@camstack/addon-admin-ui 1.2.368 → 1.2.369
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.
- package/dist/assets/{AddonAssetIcon-DFj-ju1T.js → AddonAssetIcon-rRcZQtEA.js} +1 -1
- package/dist/assets/AddonIntegrationBody-EbUl8tUN.js +1 -0
- package/dist/assets/Addons-DGr0dCVs.js +4 -0
- package/dist/assets/{AdminTabs-DTp_qwRF.js → AdminTabs-wu-aryGN.js} +1 -1
- package/dist/assets/AiProfiles-BeoeH8Zu.js +3 -0
- package/dist/assets/{BrokerForm-C1gCAO_i.js → BrokerForm-BKrrZCZh.js} +1 -1
- package/dist/assets/Build-B6IaaCld.js +40 -0
- package/dist/assets/{Calendars-CgpSaf57.js → Calendars-Cu9XHV92.js} +1 -1
- package/dist/assets/Cluster-Cy5X6Uvg.js +1 -0
- package/dist/assets/ClusterStepModel-naRCh9Gl.js +1 -0
- package/dist/assets/{CompositionEditor-B72RWTAg.js → CompositionEditor-IHtDmqNg.js} +1 -1
- package/dist/assets/{CompositionEditorPage-Czh4hLXm.js → CompositionEditorPage-DC8vTjNi.js} +1 -1
- package/dist/assets/Data-DYW0abTi.js +1 -0
- package/dist/assets/DetectionIntelligence-Dql2v1Z-.js +1 -0
- package/dist/assets/DeviceDetail-DnI-UCZh.js +2 -0
- package/dist/assets/{DeviceDoActionFields-CgcW2y34.js → DeviceDoActionFields-CDcT9AGH.js} +1 -1
- package/dist/assets/{Devices-Dxdfsu2U.js → Devices-BQlncmWJ.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-DBDO4iGl.js → EmbedPlayerPage-tOXvPyWI.js} +1 -1
- package/dist/assets/Events-BHrs4V4o.js +1 -0
- package/dist/assets/Identity-B0o5qgSj.js +1 -0
- package/dist/assets/IntegrationDetail-C5FRSBKl.js +1 -0
- package/dist/assets/Integrations-Y_7v1rC_.js +1 -0
- package/dist/assets/Integrations-kpJ44y4z.js +1 -0
- package/dist/assets/Locations-CcEjNLL3.js +3 -0
- package/dist/assets/{Logs-CEo_ltyB.js → Logs-CwotbBSR.js} +1 -1
- package/dist/assets/{MotionZonesSettings-CEgwXQs4.js → MotionZonesSettings-DWw3QpEU.js} +1 -1
- package/dist/assets/MyAccess-FYgj8K8r.js +2 -0
- package/dist/assets/Network-CAm0gAZJ.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-ud5IAMLM.js → NodeAddonsSettingsPanel-Bb9dwuSU.js} +1 -1
- package/dist/assets/Notifications--kHXBEqD.js +1 -0
- package/dist/assets/{Plates-DY7gAqtN.js → Plates-BiXyRHLs.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-3Qj6iJyr.js → PrivacyMaskSettings-DCTAX66L.js} +1 -1
- package/dist/assets/Recordings-DrcwnpEB.js +1 -0
- package/dist/assets/Retrain-BrINvPPp.js +1 -0
- package/dist/assets/{ScanNetworkModal-DeQVAhiv.js → ScanNetworkModal-C4IaFGug.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-DLTybD7E.js → SceneMonitorEditor-CQ2pi_Hj.js} +1 -1
- package/dist/assets/{Scenes-yXnX2BEQ.js → Scenes-BLFLAgHy.js} +1 -1
- package/dist/assets/SessionsList-Yg5gVfMg.js +2 -0
- package/dist/assets/{Showroom-DWPBOwhC.js → Showroom-I56ibw6k.js} +1 -1
- package/dist/assets/System-BVjDuAwr.js +1 -0
- package/dist/assets/{Terminal-Dw2mDFS9.js → Terminal-5SL5NSD1.js} +5 -5
- package/dist/assets/{Viewer-BOmPgDRl.js → Viewer-C9zzDTPh.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DtaIXYDp.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C2fbuZJL.js} +1 -1
- package/dist/assets/{archive-6pzbE4zL.js → archive-Dkte8Y8a.js} +1 -1
- package/dist/assets/{authed-media-dlxPHLGt.js → authed-media-Bi2u1rSm.js} +1 -1
- package/dist/assets/{boxes-B9mRSNXT.js → boxes-CG60qRZo.js} +1 -1
- package/dist/assets/circle-slash-C3W4jvTj.js +1 -0
- package/dist/assets/{client-DdTCFotl.js → client-DX0rAC3X.js} +1 -1
- package/dist/assets/crop-BBN3JEL7.js +1 -0
- package/dist/assets/{debounced-invalidate-CjvnQ6zt.js → debounced-invalidate-CxaRFTpC.js} +1 -1
- package/dist/assets/{device-integration-icon-BRBO6DaZ.js → device-integration-icon-JFsHsv7_.js} +1 -1
- package/dist/assets/device-picker-model-BTxjd_Y8.js +1 -0
- package/dist/assets/{dist-CJxcey0N.js → dist-DK6qWoSo.js} +1 -1
- package/dist/assets/{dist-BPTn9PvV.js → dist-DflVZo7O.js} +1 -1
- package/dist/assets/{face-bbox-CPsQ49nP.js → face-bbox-zC_kw0CX.js} +1 -1
- package/dist/assets/{hard-drive-download-CUKF7GIe.js → hard-drive-download-C9ll-Tud.js} +1 -1
- package/dist/assets/{history-BR0cgtxK.js → history-Bsb3o8Ph.js} +1 -1
- package/dist/assets/{hostInit-D7PExcI5.js → hostInit-D-dSFNov.js} +1 -1
- package/dist/assets/index-BfUAV0Tt.css +2 -0
- package/dist/assets/index-D7yeH_53.js +4 -0
- package/dist/assets/{layers-BEphtFOD.js → layers-BiHKkPFk.js} +1 -1
- package/dist/assets/location-owned-usage-DQxXKxXh.js +1 -0
- package/dist/assets/{mf-entry-bootstrap-0-f35db814.js → mf-entry-bootstrap-0-76e50126.js} +2 -2
- package/dist/assets/{monitor-smartphone-DbkPiYT_.js → monitor-smartphone-DCj4MFCV.js} +1 -1
- package/dist/assets/mount-BTxjd_Y8.js +1 -0
- package/dist/assets/notification-schedule-field-B3G1sjYy.js +1 -0
- package/dist/assets/{octagon-alert-DI2r29y1.js → octagon-alert-uq_xpLNT.js} +1 -1
- package/dist/assets/{player-overlays-CVsVEZkx.js → player-overlays-D9aoM64J.js} +1 -1
- package/dist/assets/remoteEntry-CKbF9NAW.js +1 -0
- package/dist/assets/{send-CsS0XJlB.js → send-BoWu8sC3.js} +1 -1
- package/dist/assets/{settings-2-CyVUMXY7.js → settings-2-vAZgfnrs.js} +1 -1
- package/dist/assets/{src-DBOD88Il.js → src-B-IRCQFw.js} +4 -4
- package/dist/assets/{use-scenes-feed-B3khNWlP.js → use-scenes-feed-B67D8SNJ.js} +1 -1
- package/dist/assets/{use-stationary-objects-DONRHYCH.js → use-stationary-objects-B5PewW7U.js} +1 -1
- package/dist/assets/useEventInvalidation-BTxjd_Y8.js +1 -0
- package/dist/assets/{useNodeUrlSelection-CqbePEmt.js → useNodeUrlSelection-DyMwFYyx.js} +1 -1
- package/dist/assets/user-round-bqX4ogd_.js +1 -0
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Cns_eCdr.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DDHU33sX.js} +2 -2
- package/dist/index.html +8 -8
- package/dist/server/addon.js +1 -1
- package/package.json +1 -1
- package/dist/assets/AddonIntegrationBody-FGAYdPUA.js +0 -1
- package/dist/assets/Addons-WwpkTbDd.js +0 -4
- package/dist/assets/AiProfiles-CBco5ewR.js +0 -3
- package/dist/assets/Build-DurNKP8T.js +0 -40
- package/dist/assets/Cluster-DvhjeS7K.js +0 -1
- package/dist/assets/ClusterStepModel-B6r5CyPs.js +0 -1
- package/dist/assets/Data-DXof6DOP.js +0 -1
- package/dist/assets/DetectionIntelligence-DOHtIjr_.js +0 -1
- package/dist/assets/DeviceDetail-DJTOlefk.js +0 -2
- package/dist/assets/Events-BfvAxlZU.js +0 -1
- package/dist/assets/Identity-CdNS5Nbo.js +0 -1
- package/dist/assets/IntegrationDetail-v37t7dlu.js +0 -1
- package/dist/assets/Integrations-B46b2Fdt.js +0 -1
- package/dist/assets/Integrations-BhXxxG3u.js +0 -1
- package/dist/assets/Locations-DS7U1LC0.js +0 -3
- package/dist/assets/MyAccess-BPfDF0OL.js +0 -2
- package/dist/assets/Network-CsE6aS-2.js +0 -1
- package/dist/assets/Notifications-Dq9lhOuh.js +0 -1
- package/dist/assets/Recordings-Cu6I48Ge.js +0 -1
- package/dist/assets/SessionsList-DTYAg11v.js +0 -2
- package/dist/assets/System-B2dJPzzY.js +0 -1
- package/dist/assets/circle-slash-D3OU4sq-.js +0 -1
- package/dist/assets/crop-C4_qNtVc.js +0 -1
- package/dist/assets/device-picker-model-DOwpVM5h.js +0 -1
- package/dist/assets/index-BhXNFlQG.js +0 -4
- package/dist/assets/index-BrFFHBMJ.css +0 -2
- package/dist/assets/location-owned-usage-BHS4BUrZ.js +0 -1
- package/dist/assets/mount-DOwpVM5h.js +0 -1
- package/dist/assets/notification-schedule-field-DQOVzLdk.js +0 -1
- package/dist/assets/remoteEntry-8sPAjus8.js +0 -1
- package/dist/assets/useEventInvalidation-DOwpVM5h.js +0 -1
- package/dist/assets/user-round-DIYdKGlH.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{K as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{ct as l,ft as u,gt as d,ht as f,st as p,vt as m}from"./player-overlays-CVsVEZkx.js";import{$n as h,Ad as g,Bc as _,Cn as v,Eu as y,Fc as b,Hc as x,Hd as S,Hu as C,Ic as w,Lc as T,Mc as E,Nc as D,Od as O,Of as k,Pc as A,Pn as j,Rc as M,Sn as N,Tn as P,Uc as F,Vc as I,_d as L,jc as R,ju as z,kf as B,pu as V,sa as ee,wn as H,xn as U,yn as W,zc as G}from"./src-DBOD88Il.js";import{t as K}from"./crop-C4_qNtVc.js";import{a as q,c as J,f as te,i as ne,l as re,m as Y,n as X,o as ie,p as ae,r as oe,s as se,t as ce,u as le}from"./debounced-invalidate-CjvnQ6zt.js";import{n as ue,r as Z,t as de}from"./face-bbox-CPsQ49nP.js";import{hi as fe}from"./client-DdTCFotl.js";import{t as pe}from"./AdminPage-BSFohA3i.js";import{n as me,r as he}from"./authed-media-dlxPHLGt.js";var ge=m(`badge-check`,[[`path`,{d:`M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z`,key:`3c2336`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]);t();var Q=[[`plateGallery`]];function _e({vehicleId:e}){let t=a(),{data:r,isLoading:i}=M({vehicleId:e}),o=_();function c(n){o.mutate({vehicleId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:Q})}})}return i?n(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[s(S,{className:`h-3.5 w-3.5 animate-spin`}),`Loading plates…`]}):!r||r.length===0?s(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No plates yet.`}):s(`div`,{className:`mt-2 grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-6`,children:r.map(e=>n(`div`,{className:`group relative overflow-hidden rounded-md border border-border bg-surface`,children:[n(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[e.base64?s(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:e.text,className:`h-full w-full object-cover`}):s(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:s(B,{className:`h-6 w-6`})}),s(`button`,{type:`button`,onClick:()=>c(e),disabled:o.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove plate sample`,children:s(z,{className:`h-4 w-4 text-white`})})]}),s(`p`,{className:`truncate px-1.5 py-1 text-center font-mono text-[11px] font-semibold tracking-wide text-foreground`,title:e.text,children:e.text})]},e.id))})}function ve({vehicle:e,expanded:t,onToggle:r}){let c=a(),[l,u]=o(``),[m,_]=o(!1),[y,x]=o(!1),C=I(),w=b();function T(){u(e.name),_(!0)}function E(){_(!1),u(``)}function D(){let t=l.trim();if(!t||t===e.name){E();return}C.mutate({id:e.id,name:t},{onSettled:()=>{c.invalidateQueries({queryKey:Q}),E()}})}function O(){w.mutate({id:e.id},{onSettled:()=>{c.invalidateQueries({queryKey:Q}),x(!1)}})}return n(`div`,{className:`rounded-md border border-border bg-surface`,children:[n(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[s(`div`,{className:`h-8 w-12 shrink-0 overflow-hidden rounded border border-border bg-surface-hover`,children:s(ue,{mediaId:e.coverMediaId,base64:e.coverBase64,alt:e.name,className:`h-full w-full object-cover`,placeholder:s(`div`,{className:`flex h-full w-full items-center justify-center`,children:s(B,{className:`h-4 w-4 text-foreground-subtle`})})})}),s(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:m?n(i,{children:[s(V,{value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&D(),e.key===`Escape`&&E()},className:`h-6 text-xs`,autoFocus:!0}),s(`button`,{type:`button`,onClick:D,disabled:C.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:s(k,{className:`h-3.5 w-3.5`})}),s(`button`,{type:`button`,onClick:E,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:s(z,{className:`h-3.5 w-3.5`})})]}):s(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),s(h,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!m&&n(`div`,{className:`flex items-center gap-1`,children:[s(`button`,{type:`button`,onClick:T,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:s(g,{className:`h-3.5 w-3.5`})}),s(`button`,{type:`button`,onClick:()=>x(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:s(p,{className:`h-3.5 w-3.5`})})]}),s(`button`,{type:`button`,onClick:r,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:s(t?d:f,{className:`h-3.5 w-3.5`})})]}),t&&s(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:s(_e,{vehicleId:e.id})}),s(W,{open:y,onOpenChange:e=>!e&&x(!1),children:n(U,{children:[n(H,{children:[s(P,{children:`Delete vehicle`}),n(N,{children:[`Delete `,s(`strong`,{children:e.name}),` and all its plate samples? This cannot be undone.`]})]}),n(v,{children:[s(j,{variant:`secondary`,onClick:()=>x(!1),children:`Cancel`}),n(j,{variant:`danger`,onClick:O,disabled:w.isPending,children:[w.isPending?s(S,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function ye(){let e=a(),[t,r]=o(``),i=D();function c(){let n=t.trim();n&&i.mutate({name:n},{onSettled:()=>{e.invalidateQueries({queryKey:Q}),r(``)}})}return n(`div`,{className:`flex items-center gap-2 pt-2`,children:[s(V,{placeholder:`New vehicle name…`,value:t,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&c()},className:`h-7 text-xs flex-1`}),n(j,{variant:`primary`,size:`sm`,onClick:c,disabled:i.isPending||!t.trim(),children:[i.isPending?s(S,{className:`h-3.5 w-3.5 animate-spin`}):s(O,{className:`h-3.5 w-3.5`}),`Add`]})]})}function be(){let{data:e,isLoading:t}=G(),[r,i]=o(null);function a(e){i(t=>t===e?null:e)}return t?n(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[s(S,{className:`h-4 w-4 animate-spin`}),`Loading vehicles…`]}):n(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&s(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No vehicles enrolled yet. Add one below.`}),e?.map(e=>s(ve,{vehicle:e,expanded:r===e.id,onToggle:()=>a(e.id)},e.id)),s(ye,{})]})}function xe(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}t();var Se=[[`plateGallery`]];function Ce({plateIds:e,vehicles:t,onDone:r}){let i=a(),c=R(),l=D(),[u,d]=o(``),[f,p]=o(!1),[m,h]=o(null),g=e!==null&&e.length>0,_=e?.length??0;function y(){p(!1),d(``),h(null)}function b(){y(),r()}function x(t){!e||e.length===0||c.mutate({plateIds:[...e],vehicleId:t},{onSettled:()=>{i.invalidateQueries({queryKey:Se}),b()}})}function C(){!e||!u.trim()||l.mutate({name:u.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{i.invalidateQueries({queryKey:Se}),b()}})}let w=c.isPending||l.isPending;return s(W,{open:g,onOpenChange:e=>!e&&b(),children:n(U,{children:[n(H,{children:[s(P,{children:_>1?`Assign ${String(_)} plates to vehicle`:`Assign plate to vehicle`}),s(N,{children:`Select an existing vehicle or create a new one.`})]}),s(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>n(`button`,{type:`button`,onClick:()=>h(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${m===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[s(`span`,{className:`font-medium`,children:e.name}),n(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` plates`]})]},e.id))}),f?s(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:s(V,{placeholder:`New vehicle name…`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&C()},autoFocus:!0,className:`flex-1`})}):s(`button`,{type:`button`,onClick:()=>{h(null),p(!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:`+ New vehicle…`}),n(v,{children:[s(j,{variant:`secondary`,onClick:b,disabled:w,children:`Cancel`}),f?n(j,{variant:`primary`,onClick:C,disabled:w||!u.trim(),children:[w&&s(S,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):n(j,{variant:`primary`,onClick:()=>m&&x(m),disabled:w||!m,children:[w&&s(S,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,_>1?` ${String(_)}`:``]})]})]})})}t();var we=[[`plateGallery`]];function Te(e){let[t,n]=o(null),[r,i]=o(null),[a,s]=o(!1);return c(()=>{if(n(null),i(null),s(!1),e===void 0)return;let t=!1,r=null;return(async()=>{try{let i=await me(he(e));if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||s(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),c(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>s(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function Ee(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 $({label:e,value:t,mono:r}){return n(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[s(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),s(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${r?`font-mono`:``}`,title:t,children:t})]})}function De({box:e}){return s(`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:s(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Plate`})})}function Oe({plate:e,cameraName:t,onClose:i,onAssign:l,onUnassign:d,onDelete:f,actionsPending:m}){let h=a(),{data:_,isFetching:v}=w({plateId:e?.plateId??``},{enabled:e!==null}),y=E(),[b,x]=o(`frame`),[T,D]=o(!1),[O,A]=o(``),{frameSrc:M,naturalWidth:N,naturalHeight:P,failed:F}=Te(e?.keyFrameMediaId);c(()=>{D(!1),A(``),x(`frame`)},[e?.plateId]);let I=r(()=>{let t=Ee(_??[]);return t?t.url:xe(e)},[_,e]),R=r(()=>!e?.plateBbox||N===null||P===null?null:de(e.plateBbox,N,P),[e?.plateBbox,N,P]);if(e===null)return null;let B=e.keyFrameMediaId!==void 0&&!F,ee=B&&b===`frame`,H=e.assigned?e.vehicleName??`Assigned`:e.recognizedVehicleId?`${e.vehicleName??`Recognized`} (suggested)`:`Unassigned`,G=`${String(Math.round(e.score*100))}%${e.corrected?` · corrected`:``}`;function q(){e&&(A(e.text),D(!0))}function J(){if(!e)return;let t=O.trim().toUpperCase();if(!t||t===e.text){D(!1);return}y.mutate({plateId:e.plateId,text:t},{onSettled:()=>{h.invalidateQueries({queryKey:we}),D(!1)}})}return s(W,{open:!0,onOpenChange:e=>!e&&i(),children:n(U,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`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:[n(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[n(`div`,{className:`min-w-0`,children:[s(`div`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||`Plate detail`}),s(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),s(`button`,{type:`button`,onClick:i,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:s(z,{className:`h-4 w-4`})})]}),n(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[B&&n(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[n(`button`,{type:`button`,onClick:()=>x(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${b===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[s(L,{className:`h-3.5 w-3.5`}),` Full frame`]}),n(`button`,{type:`button`,onClick:()=>x(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${b===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[s(K,{className:`h-3.5 w-3.5`}),` Crop`]})]}),ee&&M?s(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:s(X,{src:M,alt:`Full frame with detected plate`,fit:`natural`,className:`w-full`,overlay:R?s(De,{box:R}):void 0})}):I?n(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[s(X,{src:I,alt:`Detected plate`,className:`h-full w-full`}),v&&s(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:s(S,{className:`h-3.5 w-3.5 animate-spin`})})]}):n(`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:[s(u,{className:`h-8 w-8 text-warning/70`}),s(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),s(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:`The crop media for this plate could not be resolved. Safe to delete.`})]}),s(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-2`,children:n(`div`,{className:`flex items-center justify-between gap-3`,children:[s(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:`Plate text`}),T?n(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[s(V,{value:O,onChange:e=>A(e.target.value),onKeyDown:e=>{e.key===`Enter`&&J(),e.key===`Escape`&&D(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),s(`button`,{type:`button`,onClick:J,disabled:y.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Save corrected text`,children:y.isPending?s(S,{className:`h-3.5 w-3.5 animate-spin`}):s(k,{className:`h-3.5 w-3.5`})}),s(`button`,{type:`button`,onClick:()=>D(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel`,children:s(z,{className:`h-3.5 w-3.5`})})]}):n(`button`,{type:`button`,onClick:q,className:`group flex min-w-0 items-center gap-1.5`,title:`Correct the OCR reading`,children:[s(`span`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||`—`}),s(g,{className:`h-3 w-3 shrink-0 text-foreground-subtle group-hover:text-foreground`})]})]})}),n(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[s($,{label:`Camera`,value:t}),s($,{label:`Captured`,value:ae(e.timestamp)}),s($,{label:`Confidence`,value:G}),s($,{label:`Vehicle`,value:H}),s($,{label:`Track`,value:e.trackId,mono:!0})]})]}),n(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[e.assigned?n(j,{variant:`secondary`,onClick:()=>d(e.plateId),disabled:m,children:[s(Z,{className:`h-3.5 w-3.5`}),` Detach`]}):n(j,{variant:`primary`,onClick:()=>l(e.plateId),disabled:m,children:[s(C,{className:`h-3.5 w-3.5`}),` Assign`]}),n(j,{variant:`secondary`,onClick:()=>f(e.plateId),disabled:m,children:[s(p,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}t();var ke=[[`plateGallery`]],Ae=500,je=120;function Me({plate:e,cameraName:t,nowMs:r,selected:i,onToggleSelect:o,onAssign:c,onOpenDetail:d}){let f=a(),m=x(),h=A(),g=()=>{f.invalidateQueries({queryKey:ke})},_=()=>d(e.plateId),v=xe(e);return n(`div`,{className:`relative flex flex-col overflow-hidden rounded-md border bg-surface ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[n(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[v===null?n(`button`,{type:`button`,onClick:_,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:`No crop image — the plate's crop media is missing. Safe to delete.`,children:[s(u,{className:`h-7 w-7 text-warning/70`}),s(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):s(`img`,{src:v,alt:`Plate ${e.text} from ${t}`,onClick:_,className:`h-full w-full cursor-zoom-in object-cover`}),s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(e.plateId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Deselect`:`Select`,children:i?s(Y,{className:`h-4 w-4 text-primary`}):s(l,{className:`h-4 w-4`})}),e.corrected&&n(`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:`Manually corrected`,children:[s(ge,{className:`h-3 w-3`}),` Fixed`]})]}),n(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[s(`p`,{className:`truncate font-mono text-xs font-bold tracking-wide text-foreground`,title:e.text,children:e.text||`—`}),s(`p`,{className:`truncate text-[10px] text-foreground-subtle`,title:t,children:t}),s(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:te(e.timestamp,r)}),e.vehicleName&&s(`p`,{className:`truncate text-[10px] font-medium text-primary`,title:e.vehicleName,children:e.vehicleName})]}),n(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),m.mutate({plateId:e.plateId},{onSettled:g})},disabled:m.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":`Detach plate`,title:`Detach`,children:m.isPending?s(S,{className:`h-4 w-4 animate-spin`}):s(Z,{className:`h-4 w-4`})}):s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),c(e.plateId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":`Assign plate to vehicle`,title:`Assign to vehicle`,children:s(C,{className:`h-4 w-4`})}),s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),h.mutate({plateId:e.plateId},{onSettled:g})},disabled:h.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":`Delete plate`,title:`Delete plate`,children:h.isPending?s(S,{className:`h-4 w-4 animate-spin`}):s(p,{className:`h-4 w-4`})})]})]})}var Ne=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Assigned`,value:`assigned`}];function Pe(e,t){return t===`unassigned`?e.filter(e=>!e.assigned):t===`assigned`?e.filter(e=>e.assigned):e}function Fe(){let e=a(),[t,c]=o(`all`),[l,u]=o(se),[d,f]=o(new Set),[m,h]=o(new Set),[g,_]=o(null),[v,y]=o(null),{data:b,isLoading:w}=T({limit:Ae,includeCrops:!1},{refetchInterval:3e4}),{data:E=[]}=G(),{data:D}=ee({isCamera:!0,projection:`slim`}),O=x(),k=F(),M=A(),N=Date.now(),P=b??[],I=r(()=>{let e=new Map;for(let t of D??[])e.set(t.id,t.name);return e},[D]),L=e=>I.get(e)??`Camera #${String(e)}`,R=r(()=>J(P).map(e=>({id:e,name:L(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[P,I]),B=r(()=>re(le(Pe(P,t),l),d),[P,t,l,d]),V=ie(B,je,r(()=>JSON.stringify([t,l.fromMs,l.toMs,[...d].sort((e,t)=>e-t)]),[t,l.fromMs,l.toMs,d])),H=r(()=>new Map(P.map(e=>[e.plateId,e])),[P]),U=v===null?null:H.get(v)??null,W=()=>{e.invalidateQueries({queryKey:ke})},K=()=>h(new Set);function te(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let Y=[...m],X=k.isPending||M.isPending,ae=O.isPending||M.isPending;function ce(){Y.length!==0&&k.mutate({plateIds:Y},{onSettled:()=>{W(),K()}})}function ue(){Y.length!==0&&Promise.allSettled(Y.map(e=>M.mutateAsync({plateId:e}))).then(()=>{W(),K()})}function de(e){y(null),_([e])}function fe(e){O.mutate({plateId:e},{onSettled:W}),y(null)}function pe(e){M.mutate({plateId:e},{onSettled:W}),y(null)}let me=B.length!==P.length;return n(`div`,{className:`relative space-y-3`,children:[n(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[s(`div`,{className:`flex items-center gap-1`,children:Ne.map(e=>s(`button`,{type:`button`,onClick:()=>c(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${t===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value))}),s(oe,{onChange:u}),s(ne,{cameras:R,selected:d,onChange:f}),!w&&s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:me?`${String(B.length)} of ${String(P.length)} plates`:`${String(B.length)} plate${B.length===1?``:`s`}`})]}),m.size>0&&n(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[n(`span`,{className:`text-xs font-medium text-foreground`,children:[m.size,` selected`]}),n(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[n(j,{variant:`primary`,onClick:()=>_(Y),disabled:X,children:[s(C,{className:`h-3.5 w-3.5`}),` Assign`]}),n(j,{variant:`secondary`,onClick:ce,disabled:X,children:[k.isPending?s(S,{className:`h-3.5 w-3.5 animate-spin`}):s(Z,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),n(j,{variant:`secondary`,onClick:ue,disabled:X,children:[s(p,{className:`h-3.5 w-3.5`}),` Delete`]}),s(j,{variant:`ghost`,onClick:K,disabled:X,children:s(z,{className:`h-3.5 w-3.5`})})]})]}),w&&n(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[s(S,{className:`h-4 w-4 animate-spin`}),` Loading plates…`]}),!w&&B.length===0&&s(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:P.length>0?`No plates match the current filters.`:`No plates recognized yet.`}),!w&&B.length>0&&n(i,{children:[s(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2`,children:V.pageItems.map(e=>s(Me,{plate:e,cameraName:L(e.deviceId),nowMs:N,selected:m.has(e.plateId),onToggleSelect:te,onAssign:e=>_([e]),onOpenDetail:y},e.plateId))}),s(q,{currentPage:V.page,totalItems:V.totalItems,pageSize:V.pageSize,onPageChange:V.setPage,itemNoun:`plates`})]}),s(Oe,{plate:U,cameraName:U?L(U.deviceId):``,onClose:()=>y(null),onAssign:de,onUnassign:fe,onDelete:pe,actionsPending:ae}),s(Ce,{plateIds:g,vehicles:E,onDone:()=>{_(null),K()}})]})}t();var Ie=[[`plateGallery`]],Le=2e3;function Re(){let t=a(),n=e(t);n.current=t;let r=e(void 0);r.current||=ce({delayMs:Le,invalidate:()=>{n.current.invalidateQueries({queryKey:Ie})}}),c(()=>()=>r.current?.cancel(),[]),y(fe.PipelineAnalyticsPlateGalleryChanged,()=>{r.current?.trigger()})}function ze(){return Re(),s(pe,{icon:B,title:`Plates`,subtitle:`Manage enrolled vehicles and assign recognized license plates to them.`,children:n(`section`,{className:`space-y-3`,children:[n(`div`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Vehicles`}),s(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Enrolled vehicle identities used for plate recognition. Expand a row to view or remove plate samples.`}),s(be,{})]}),n(`div`,{className:`pt-4 border-t border-border`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent recognized plates`}),s(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`License plates read by the detection pipeline. Assign them to a vehicle, correct the OCR text, or delete.`}),s(Fe,{})]})]})})}export{ze as PlatesPage};
|
|
1
|
+
import{K as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{ct as l,ft as u,gt as d,ht as f,st as p,vt as m}from"./player-overlays-D9aoM64J.js";import{Af as h,Bc as g,Cn as _,Du as v,En as y,Fc as b,Fn as x,Hc as S,Ic as C,Lc as w,Mc as T,Mu as E,Nc as D,Pc as O,Rc as k,Sn as A,Tn as j,Uc as M,Ud as N,Uu as P,Vc as F,Wc as I,bn as L,ca as R,er as z,jd as B,kd as V,kf as H,mu as U,vd as W,wn as G,zc as K}from"./src-B-IRCQFw.js";import{t as q}from"./crop-BBN3JEL7.js";import{a as ee,c as J,f as te,i as ne,l as re,m as Y,n as X,o as ie,p as ae,r as oe,s as se,t as ce,u as le}from"./debounced-invalidate-CxaRFTpC.js";import{n as ue,r as Z,t as de}from"./face-bbox-zC_kw0CX.js";import{hi as fe}from"./client-DX0rAC3X.js";import{t as pe}from"./AdminPage-BSFohA3i.js";import{n as me,r as he}from"./authed-media-Bi2u1rSm.js";var ge=m(`badge-check`,[[`path`,{d:`M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z`,key:`3c2336`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]);t();var Q=[[`plateGallery`]];function _e({vehicleId:e}){let t=a(),{data:r,isLoading:i}=K({vehicleId:e}),o=F();function c(n){o.mutate({vehicleId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:Q})}})}return i?n(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[s(N,{className:`h-3.5 w-3.5 animate-spin`}),`Loading plates…`]}):!r||r.length===0?s(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No plates yet.`}):s(`div`,{className:`mt-2 grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-6`,children:r.map(e=>n(`div`,{className:`group relative overflow-hidden rounded-md border border-border bg-surface`,children:[n(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[e.base64?s(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:e.text,className:`h-full w-full object-cover`}):s(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:s(h,{className:`h-6 w-6`})}),s(`button`,{type:`button`,onClick:()=>c(e),disabled:o.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove plate sample`,children:s(E,{className:`h-4 w-4 text-white`})})]}),s(`p`,{className:`truncate px-1.5 py-1 text-center font-mono text-[11px] font-semibold tracking-wide text-foreground`,title:e.text,children:e.text})]},e.id))})}function ve({vehicle:e,expanded:t,onToggle:r}){let c=a(),[l,u]=o(``),[m,g]=o(!1),[v,b]=o(!1),w=S(),T=C();function D(){u(e.name),g(!0)}function O(){g(!1),u(``)}function k(){let t=l.trim();if(!t||t===e.name){O();return}w.mutate({id:e.id,name:t},{onSettled:()=>{c.invalidateQueries({queryKey:Q}),O()}})}function M(){T.mutate({id:e.id},{onSettled:()=>{c.invalidateQueries({queryKey:Q}),b(!1)}})}return n(`div`,{className:`rounded-md border border-border bg-surface`,children:[n(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[s(`div`,{className:`h-8 w-12 shrink-0 overflow-hidden rounded border border-border bg-surface-hover`,children:s(ue,{mediaId:e.coverMediaId,base64:e.coverBase64,alt:e.name,className:`h-full w-full object-cover`,placeholder:s(`div`,{className:`flex h-full w-full items-center justify-center`,children:s(h,{className:`h-4 w-4 text-foreground-subtle`})})})}),s(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:m?n(i,{children:[s(U,{value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&k(),e.key===`Escape`&&O()},className:`h-6 text-xs`,autoFocus:!0}),s(`button`,{type:`button`,onClick:k,disabled:w.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:s(H,{className:`h-3.5 w-3.5`})}),s(`button`,{type:`button`,onClick:O,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:s(E,{className:`h-3.5 w-3.5`})})]}):s(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),s(z,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!m&&n(`div`,{className:`flex items-center gap-1`,children:[s(`button`,{type:`button`,onClick:D,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:s(B,{className:`h-3.5 w-3.5`})}),s(`button`,{type:`button`,onClick:()=>b(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:s(p,{className:`h-3.5 w-3.5`})})]}),s(`button`,{type:`button`,onClick:r,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:s(t?d:f,{className:`h-3.5 w-3.5`})})]}),t&&s(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:s(_e,{vehicleId:e.id})}),s(L,{open:v,onOpenChange:e=>!e&&b(!1),children:n(A,{children:[n(j,{children:[s(y,{children:`Delete vehicle`}),n(_,{children:[`Delete `,s(`strong`,{children:e.name}),` and all its plate samples? This cannot be undone.`]})]}),n(G,{children:[s(x,{variant:`secondary`,onClick:()=>b(!1),children:`Cancel`}),n(x,{variant:`danger`,onClick:M,disabled:T.isPending,children:[T.isPending?s(N,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function ye(){let e=a(),[t,r]=o(``),i=O();function c(){let n=t.trim();n&&i.mutate({name:n},{onSettled:()=>{e.invalidateQueries({queryKey:Q}),r(``)}})}return n(`div`,{className:`flex items-center gap-2 pt-2`,children:[s(U,{placeholder:`New vehicle name…`,value:t,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&c()},className:`h-7 text-xs flex-1`}),n(x,{variant:`primary`,size:`sm`,onClick:c,disabled:i.isPending||!t.trim(),children:[i.isPending?s(N,{className:`h-3.5 w-3.5 animate-spin`}):s(V,{className:`h-3.5 w-3.5`}),`Add`]})]})}function be(){let{data:e,isLoading:t}=g(),[r,i]=o(null);function a(e){i(t=>t===e?null:e)}return t?n(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[s(N,{className:`h-4 w-4 animate-spin`}),`Loading vehicles…`]}):n(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&s(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No vehicles enrolled yet. Add one below.`}),e?.map(e=>s(ve,{vehicle:e,expanded:r===e.id,onToggle:()=>a(e.id)},e.id)),s(ye,{})]})}function xe(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}t();var Se=[[`plateGallery`]];function Ce({plateIds:e,vehicles:t,onDone:r}){let i=a(),c=T(),l=O(),[u,d]=o(``),[f,p]=o(!1),[m,h]=o(null),g=e!==null&&e.length>0,v=e?.length??0;function b(){p(!1),d(``),h(null)}function S(){b(),r()}function C(t){!e||e.length===0||c.mutate({plateIds:[...e],vehicleId:t},{onSettled:()=>{i.invalidateQueries({queryKey:Se}),S()}})}function w(){!e||!u.trim()||l.mutate({name:u.trim()},{onSuccess:e=>{e?.id&&C(e.id)},onError:()=>{i.invalidateQueries({queryKey:Se}),S()}})}let E=c.isPending||l.isPending;return s(L,{open:g,onOpenChange:e=>!e&&S(),children:n(A,{children:[n(j,{children:[s(y,{children:v>1?`Assign ${String(v)} plates to vehicle`:`Assign plate to vehicle`}),s(_,{children:`Select an existing vehicle or create a new one.`})]}),s(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>n(`button`,{type:`button`,onClick:()=>h(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${m===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[s(`span`,{className:`font-medium`,children:e.name}),n(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` plates`]})]},e.id))}),f?s(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:s(U,{placeholder:`New vehicle name…`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&w()},autoFocus:!0,className:`flex-1`})}):s(`button`,{type:`button`,onClick:()=>{h(null),p(!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:`+ New vehicle…`}),n(G,{children:[s(x,{variant:`secondary`,onClick:S,disabled:E,children:`Cancel`}),f?n(x,{variant:`primary`,onClick:w,disabled:E||!u.trim(),children:[E&&s(N,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):n(x,{variant:`primary`,onClick:()=>m&&C(m),disabled:E||!m,children:[E&&s(N,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,v>1?` ${String(v)}`:``]})]})]})})}t();var we=[[`plateGallery`]];function Te(e){let[t,n]=o(null),[r,i]=o(null),[a,s]=o(!1);return c(()=>{if(n(null),i(null),s(!1),e===void 0)return;let t=!1,r=null;return(async()=>{try{let i=await me(he(e));if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||s(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),c(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>s(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function Ee(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 $({label:e,value:t,mono:r}){return n(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[s(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),s(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${r?`font-mono`:``}`,title:t,children:t})]})}function De({box:e}){return s(`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:s(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Plate`})})}function Oe({plate:e,cameraName:t,onClose:i,onAssign:l,onUnassign:d,onDelete:f,actionsPending:m}){let h=a(),{data:g,isFetching:_}=w({plateId:e?.plateId??``},{enabled:e!==null}),v=D(),[y,b]=o(`frame`),[S,C]=o(!1),[T,O]=o(``),{frameSrc:k,naturalWidth:j,naturalHeight:M,failed:F}=Te(e?.keyFrameMediaId);c(()=>{C(!1),O(``),b(`frame`)},[e?.plateId]);let I=r(()=>{let t=Ee(g??[]);return t?t.url:xe(e)},[g,e]),R=r(()=>!e?.plateBbox||j===null||M===null?null:de(e.plateBbox,j,M),[e?.plateBbox,j,M]);if(e===null)return null;let z=e.keyFrameMediaId!==void 0&&!F,V=z&&y===`frame`,G=e.assigned?e.vehicleName??`Assigned`:e.recognizedVehicleId?`${e.vehicleName??`Recognized`} (suggested)`:`Unassigned`,K=`${String(Math.round(e.score*100))}%${e.corrected?` · corrected`:``}`;function ee(){e&&(O(e.text),C(!0))}function J(){if(!e)return;let t=T.trim().toUpperCase();if(!t||t===e.text){C(!1);return}v.mutate({plateId:e.plateId,text:t},{onSettled:()=>{h.invalidateQueries({queryKey:we}),C(!1)}})}return s(L,{open:!0,onOpenChange:e=>!e&&i(),children:n(A,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`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:[n(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[n(`div`,{className:`min-w-0`,children:[s(`div`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||`Plate detail`}),s(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),s(`button`,{type:`button`,onClick:i,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:s(E,{className:`h-4 w-4`})})]}),n(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[z&&n(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[n(`button`,{type:`button`,onClick:()=>b(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${y===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[s(W,{className:`h-3.5 w-3.5`}),` Full frame`]}),n(`button`,{type:`button`,onClick:()=>b(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${y===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[s(q,{className:`h-3.5 w-3.5`}),` Crop`]})]}),V&&k?s(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:s(X,{src:k,alt:`Full frame with detected plate`,fit:`natural`,className:`w-full`,overlay:R?s(De,{box:R}):void 0})}):I?n(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[s(X,{src:I,alt:`Detected plate`,className:`h-full w-full`}),_&&s(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:s(N,{className:`h-3.5 w-3.5 animate-spin`})})]}):n(`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:[s(u,{className:`h-8 w-8 text-warning/70`}),s(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),s(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:`The crop media for this plate could not be resolved. Safe to delete.`})]}),s(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-2`,children:n(`div`,{className:`flex items-center justify-between gap-3`,children:[s(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:`Plate text`}),S?n(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[s(U,{value:T,onChange:e=>O(e.target.value),onKeyDown:e=>{e.key===`Enter`&&J(),e.key===`Escape`&&C(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),s(`button`,{type:`button`,onClick:J,disabled:v.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Save corrected text`,children:v.isPending?s(N,{className:`h-3.5 w-3.5 animate-spin`}):s(H,{className:`h-3.5 w-3.5`})}),s(`button`,{type:`button`,onClick:()=>C(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel`,children:s(E,{className:`h-3.5 w-3.5`})})]}):n(`button`,{type:`button`,onClick:ee,className:`group flex min-w-0 items-center gap-1.5`,title:`Correct the OCR reading`,children:[s(`span`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||`—`}),s(B,{className:`h-3 w-3 shrink-0 text-foreground-subtle group-hover:text-foreground`})]})]})}),n(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[s($,{label:`Camera`,value:t}),s($,{label:`Captured`,value:ae(e.timestamp)}),s($,{label:`Confidence`,value:K}),s($,{label:`Vehicle`,value:G}),s($,{label:`Track`,value:e.trackId,mono:!0})]})]}),n(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[e.assigned?n(x,{variant:`secondary`,onClick:()=>d(e.plateId),disabled:m,children:[s(Z,{className:`h-3.5 w-3.5`}),` Detach`]}):n(x,{variant:`primary`,onClick:()=>l(e.plateId),disabled:m,children:[s(P,{className:`h-3.5 w-3.5`}),` Assign`]}),n(x,{variant:`secondary`,onClick:()=>f(e.plateId),disabled:m,children:[s(p,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}t();var ke=[[`plateGallery`]],Ae=500,je=120;function Me({plate:e,cameraName:t,nowMs:r,selected:i,onToggleSelect:o,onAssign:c,onOpenDetail:d}){let f=a(),m=M(),h=b(),g=()=>{f.invalidateQueries({queryKey:ke})},_=()=>d(e.plateId),v=xe(e);return n(`div`,{className:`relative flex flex-col overflow-hidden rounded-md border bg-surface ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[n(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[v===null?n(`button`,{type:`button`,onClick:_,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:`No crop image — the plate's crop media is missing. Safe to delete.`,children:[s(u,{className:`h-7 w-7 text-warning/70`}),s(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):s(`img`,{src:v,alt:`Plate ${e.text} from ${t}`,onClick:_,className:`h-full w-full cursor-zoom-in object-cover`}),s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(e.plateId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Deselect`:`Select`,children:i?s(Y,{className:`h-4 w-4 text-primary`}):s(l,{className:`h-4 w-4`})}),e.corrected&&n(`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:`Manually corrected`,children:[s(ge,{className:`h-3 w-3`}),` Fixed`]})]}),n(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[s(`p`,{className:`truncate font-mono text-xs font-bold tracking-wide text-foreground`,title:e.text,children:e.text||`—`}),s(`p`,{className:`truncate text-[10px] text-foreground-subtle`,title:t,children:t}),s(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:te(e.timestamp,r)}),e.vehicleName&&s(`p`,{className:`truncate text-[10px] font-medium text-primary`,title:e.vehicleName,children:e.vehicleName})]}),n(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),m.mutate({plateId:e.plateId},{onSettled:g})},disabled:m.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":`Detach plate`,title:`Detach`,children:m.isPending?s(N,{className:`h-4 w-4 animate-spin`}):s(Z,{className:`h-4 w-4`})}):s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),c(e.plateId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":`Assign plate to vehicle`,title:`Assign to vehicle`,children:s(P,{className:`h-4 w-4`})}),s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),h.mutate({plateId:e.plateId},{onSettled:g})},disabled:h.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":`Delete plate`,title:`Delete plate`,children:h.isPending?s(N,{className:`h-4 w-4 animate-spin`}):s(p,{className:`h-4 w-4`})})]})]})}var Ne=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Assigned`,value:`assigned`}];function Pe(e,t){return t===`unassigned`?e.filter(e=>!e.assigned):t===`assigned`?e.filter(e=>e.assigned):e}function Fe(){let e=a(),[t,c]=o(`all`),[l,u]=o(se),[d,f]=o(new Set),[m,h]=o(new Set),[_,v]=o(null),[y,S]=o(null),{data:C,isLoading:w}=k({limit:Ae,includeCrops:!1},{refetchInterval:3e4}),{data:T=[]}=g(),{data:D}=R({isCamera:!0,projection:`slim`}),O=M(),A=I(),j=b(),F=Date.now(),L=C??[],z=r(()=>{let e=new Map;for(let t of D??[])e.set(t.id,t.name);return e},[D]),B=e=>z.get(e)??`Camera #${String(e)}`,V=r(()=>J(L).map(e=>({id:e,name:B(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[L,z]),H=r(()=>re(le(Pe(L,t),l),d),[L,t,l,d]),U=ie(H,je,r(()=>JSON.stringify([t,l.fromMs,l.toMs,[...d].sort((e,t)=>e-t)]),[t,l.fromMs,l.toMs,d])),W=r(()=>new Map(L.map(e=>[e.plateId,e])),[L]),G=y===null?null:W.get(y)??null,K=()=>{e.invalidateQueries({queryKey:ke})},q=()=>h(new Set);function te(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let Y=[...m],X=A.isPending||j.isPending,ae=O.isPending||j.isPending;function ce(){Y.length!==0&&A.mutate({plateIds:Y},{onSettled:()=>{K(),q()}})}function ue(){Y.length!==0&&Promise.allSettled(Y.map(e=>j.mutateAsync({plateId:e}))).then(()=>{K(),q()})}function de(e){S(null),v([e])}function fe(e){O.mutate({plateId:e},{onSettled:K}),S(null)}function pe(e){j.mutate({plateId:e},{onSettled:K}),S(null)}let me=H.length!==L.length;return n(`div`,{className:`relative space-y-3`,children:[n(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[s(`div`,{className:`flex items-center gap-1`,children:Ne.map(e=>s(`button`,{type:`button`,onClick:()=>c(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${t===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value))}),s(oe,{onChange:u}),s(ne,{cameras:V,selected:d,onChange:f}),!w&&s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:me?`${String(H.length)} of ${String(L.length)} plates`:`${String(H.length)} plate${H.length===1?``:`s`}`})]}),m.size>0&&n(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[n(`span`,{className:`text-xs font-medium text-foreground`,children:[m.size,` selected`]}),n(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[n(x,{variant:`primary`,onClick:()=>v(Y),disabled:X,children:[s(P,{className:`h-3.5 w-3.5`}),` Assign`]}),n(x,{variant:`secondary`,onClick:ce,disabled:X,children:[A.isPending?s(N,{className:`h-3.5 w-3.5 animate-spin`}):s(Z,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),n(x,{variant:`secondary`,onClick:ue,disabled:X,children:[s(p,{className:`h-3.5 w-3.5`}),` Delete`]}),s(x,{variant:`ghost`,onClick:q,disabled:X,children:s(E,{className:`h-3.5 w-3.5`})})]})]}),w&&n(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[s(N,{className:`h-4 w-4 animate-spin`}),` Loading plates…`]}),!w&&H.length===0&&s(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:L.length>0?`No plates match the current filters.`:`No plates recognized yet.`}),!w&&H.length>0&&n(i,{children:[s(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2`,children:U.pageItems.map(e=>s(Me,{plate:e,cameraName:B(e.deviceId),nowMs:F,selected:m.has(e.plateId),onToggleSelect:te,onAssign:e=>v([e]),onOpenDetail:S},e.plateId))}),s(ee,{currentPage:U.page,totalItems:U.totalItems,pageSize:U.pageSize,onPageChange:U.setPage,itemNoun:`plates`})]}),s(Oe,{plate:G,cameraName:G?B(G.deviceId):``,onClose:()=>S(null),onAssign:de,onUnassign:fe,onDelete:pe,actionsPending:ae}),s(Ce,{plateIds:_,vehicles:T,onDone:()=>{v(null),q()}})]})}t();var Ie=[[`plateGallery`]],Le=2e3;function Re(){let t=a(),n=e(t);n.current=t;let r=e(void 0);r.current||=ce({delayMs:Le,invalidate:()=>{n.current.invalidateQueries({queryKey:Ie})}}),c(()=>()=>r.current?.cancel(),[]),v(fe.PipelineAnalyticsPlateGalleryChanged,()=>{r.current?.trigger()})}function ze(){return Re(),s(pe,{icon:h,title:`Plates`,subtitle:`Manage enrolled vehicles and assign recognized license plates to them.`,children:n(`section`,{className:`space-y-3`,children:[n(`div`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Vehicles`}),s(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Enrolled vehicle identities used for plate recognition. Expand a row to view or remove plate samples.`}),s(be,{})]}),n(`div`,{className:`pt-4 border-t border-border`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent recognized plates`}),s(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`License plates read by the detection pipeline. Assign them to a vehicle, correct the OCR text, or delete.`}),s(Fe,{})]})]})})}export{ze as PlatesPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,b as ee,q as a,x as o,z as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{G as te,H as ne,R as c,Y as re,at as ie,ct as ae,dt as oe,mt as l,n as se,st as ce,ut as le,vt as u}from"./player-overlays-
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,W as i,b as ee,q as a,x as o,z as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{G as te,H as ne,R as c,Y as re,at as ie,ct as ae,dt as oe,mt as l,n as se,st as ce,ut as le,vt as u}from"./player-overlays-D9aoM64J.js";import{MaskShapeCanvas as ue}from"./MaskShapeCanvas-Dcpby34M.js";var de=u(`hexagon`,[[`path`,{d:`M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z`,key:`yt0hxn`}]]);n();var d=`Microphone`,f=`The camera encodes no audio at all — live view, recordings, exports and the audio analyzer are all silent.`;function p(e){let t=e.supportsAudioMute===!0,n=t?e.audioEnabled:null,r=e.pendingOn??null;return{label:d,supported:t,on:n===null?null:r??n,available:t&&n!==null,costWhenOff:f}}function m(e){return!e.available||e.on===null?null:{enabled:!e.on}}var fe=120,pe=`privacy-mask`,h=`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`,g=`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 _(e){return e.kind===`rect`||e.kind===`polygon`?e:null}function me(e){let t=new Set(e.map(e=>e.id)),n=0;for(;t.has(n);)n+=1;return n}function he(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(JSON.stringify(e[n])!==JSON.stringify(t[n]))return!1;return!0}function v({deviceId:n}){let u=te(ie().trpcClient,n),[d,f]=a(null),[v,y]=a(!1),[b,x]=a(!1),[S,C]=a(null),[w,T]=a(null),[E,D]=a(!1),[O,k]=a(!1),[A,j]=a(null),[M,N]=a(null),[ge,P]=a(null),[F,I]=a(null),[L,R]=a(null),z=t(!1);s(()=>{if(!u)return;let e=!1;return z.current=!1,f(null),y(!1),x(!1),C(null),T(null),k(!1),j(null),N(null),P(null),I(null),R(null),(async()=>{try{let t=await u.privacyMask?.getOptions({});if(e)return;if(!t)throw Error(`device proxy not ready`);if(f(t),z.current)return;let n=await u.privacyMask?.getStatus({});if(e)return;if(!n)throw Error(`device proxy not ready`);if(n.regions===null){x(!0),P(n.audioEnabled);return}z.current=!0;let r={enabled:n.enabled,regions:n.regions};T(r),C(r),P(n.audioEnabled)}catch(t){if(e)return;ne(t)?y(!0):console.error(`Privacy Mask load failed`,t)}})(),()=>{e=!0}},[u]);let B=i(()=>S!==null&&w!==null&&(S.enabled!==w.enabled||!he(S.regions,w.regions)),[S,w]),V=S?S.regions.length:0,H=d?d.maxRegions:0,U=t(0);s(()=>{U.current=H},[H]);let W=H>0&&V>=H,_e=e(()=>{C(e=>e&&{...e,enabled:!e.enabled})},[]),G=e(e=>{j(typeof e==`number`?e:null)},[]),K=i(()=>S?S.regions.map(e=>({id:e.id,shape:e.shape,enabled:e.enabled,label:`Zone ${String(e.id)}`})):[],[S]),q=e((e,t)=>{let n=_(t);n&&C(t=>t&&{...t,regions:t.regions.map(t=>t.id===e?{...t,shape:n}:t)})},[]),J=e(e=>{let t=_(e);t&&(N(null),C(e=>{if(!e)return e;let n=U.current;if(n>0&&e.regions.length>=n)return e;let r=me(e.regions),i={id:r,enabled:!0,shape:t};return j(r),{...e,regions:[...e.regions,i]}}))},[]),Y=e(e=>{k(!0),j(null),N(e)},[]),ve=e(e=>{k(!0),N(null),j(e)},[]),X=e(e=>{j(t=>t===e?null:t),C(t=>t&&{...t,regions:t.regions.filter(t=>t.id!==e)})},[]),ye=e(()=>{N(null),j(null),w&&C({enabled:w.enabled,regions:w.regions})},[w]),be=e(async()=>{if(!(!u||!S)){D(!0);try{await u.privacyMask?.setMask({patch:{enabled:S.enabled,regions:[...S.regions]}});let e=await u.privacyMask?.getStatus({});if(e&&e.regions!==null){let t={enabled:e.enabled,regions:e.regions};T(t),C(t)}}catch(e){console.error(`Privacy Mask save failed`,e)}finally{D(!1)}}},[u,S]),Z=p({supportsAudioMute:d===null?null:d.supportsAudioMute,audioEnabled:ge,pendingOn:F}),xe=e(async()=>{let e=m(Z);if(!(!u||e===null)){I(e.enabled),R(null);try{await u.privacyMask?.setAudioEnabled(e);let t=await u.privacyMask?.getStatus({});t&&P(t.audioEnabled)}catch(e){console.error(`Privacy microphone write failed — reverting`,e),R(e instanceof Error?e.message:String(e))}finally{I(null)}}},[u,Z]),Se=e(()=>{k(e=>(e&&(N(null),j(null)),!e))},[]),Q=d?.supportedShapes??[];se(i(()=>O&&!v&&d&&S?{id:pe,order:fe,node:o(ue,{transparent:!0,items:K,supportedShapes:Q,polygonVertices:d.polygonVertices,selectedId:A,onSelect:G,onShapeChange:q,onDrawComplete:J,drawingKind:M})}:null,[O,v,d,S,K,Q,A,G,q,J,M]));let Ce=d?.supportedShapes.includes(`rect`)??!1,we=d?.supportedShapes.includes(`polygon`)??!1,$=d!==null&&(d.maxRegions<=0||d.supportedShapes.length===0);return u?o(re,{title:`Privacy Mask`,icon:o(l,{className:`h-3.5 w-3.5 text-foreground-subtle`}),children:r(`div`,{className:`flex flex-col gap-3`,children:[v||$?o(`p`,{className:`${c} leading-relaxed`,children:`This camera doesn't support an on-board privacy mask.`}):b?o(`p`,{className:`${c} leading-relaxed`,children:`This camera hasn't answered, so what it currently masks is unknown — the editor stays closed rather than showing an empty frame you could save over. A battery camera answers once it wakes; otherwise check that it is reachable.`}):!v&&!$&&!b&&d!==null&&S!==null?r(ee,{children:[r(`p`,{className:`${c} leading-relaxed`,children:[`Toggle `,o(`strong`,{className:`text-foreground`,children:`Edit mask`}),` to draw blanked-out zones on the live frame, then `,o(`strong`,{className:`text-foreground`,children:`Save`}),` to push them to the camera. Drag a rectangle to move, its corner to resize; drag polygon vertices, click an edge midpoint to add one, or right-click a vertex to remove it.`]}),r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[o(`button`,{type:`button`,onClick:Se,disabled:E,"aria-pressed":O,className:O?g:h,children:O?`Done editing`:`Edit mask`}),o(`button`,{type:`button`,onClick:_e,disabled:E,"aria-pressed":S.enabled,className:S.enabled?g:h,children:S.enabled?`Mask on`:`Mask off`}),Ce&&o(`button`,{type:`button`,onClick:()=>Y(`rect`),disabled:E||W,"aria-pressed":M===`rect`,className:M===`rect`?g:h,title:W?`Maximum zones reached`:`Add a rectangle zone`,children:`+ Rect`}),we&&o(`button`,{type:`button`,onClick:()=>Y(`polygon`),disabled:E||W,"aria-pressed":M===`polygon`,className:M===`polygon`?g:h,title:W?`Maximum zones reached`:`Add a polygon zone`,children:`+ Polygon`}),r(`span`,{className:`${c} ml-1 tabular-nums`,children:[V,` / `,H,` zones`]}),o(`span`,{className:`flex-1`}),o(`button`,{type:`button`,onClick:ye,disabled:E||!B,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:`Revert`}),o(`button`,{type:`button`,onClick:()=>void be(),disabled:E||!B,className:g,children:E?`Saving…`:`Save`})]}),V>0?o(`div`,{className:`flex flex-col gap-1`,children:S.regions.map(e=>{let t=A===e.id,n=e.shape.kind===`polygon`?de:ae;return r(`div`,{className:`flex items-center gap-2 rounded-md border px-2 py-1 transition-colors ${t?`border-primary/50 bg-primary/10`:`border-border bg-surface`}`,children:[r(`button`,{type:`button`,onClick:()=>ve(e.id),disabled:E,className:`flex flex-1 items-center gap-2 text-left text-[11px] font-medium text-foreground-subtle hover:text-foreground disabled:opacity-40 transition-colors`,children:[o(n,{className:`h-3.5 w-3.5 shrink-0`}),r(`span`,{children:[`Zone `,e.id]}),o(`span`,{className:`text-foreground-faint capitalize`,children:e.shape.kind})]}),o(`button`,{type:`button`,onClick:()=>X(e.id),disabled:E,"aria-label":`Delete zone ${String(e.id)}`,title:`Delete zone`,className:`inline-flex h-6 w-6 items-center justify-center rounded border border-border bg-surface text-foreground-subtle hover:border-red-400/40 hover:bg-red-500/10 hover:text-red-400 disabled:opacity-40 transition-colors`,children:o(ce,{className:`h-3.5 w-3.5`})})]},e.id)})}):null]}):o(`p`,{className:`${c} leading-relaxed`,children:`Loading the camera's privacy mask…`}),Z.supported&&r(`div`,{className:`flex items-start gap-3 rounded-md border border-border bg-surface px-2 py-2`,children:[o(`button`,{type:`button`,role:`switch`,"aria-label":Z.label,"aria-checked":Z.on===!0,disabled:!Z.available||F!==null,onClick:()=>void xe(),title:Z.on===null?`Microphone — state unknown; the camera did not answer.`:Z.on?`The camera is capturing sound. Turning it off: ${Z.costWhenOff}`:`The camera is silent. ${Z.costWhenOff}`,className:Z.on===!1||Z.on===null?h:g,children:r(`span`,{className:`inline-flex items-center gap-1.5`,children:[Z.on===!1?o(oe,{className:`h-3.5 w-3.5`}):o(le,{className:`h-3.5 w-3.5`}),Z.on===null?`Microphone unknown`:Z.on?`Microphone on`:`Microphone off`]})}),o(`p`,{className:`text-[10px] text-foreground-subtle flex-1 leading-relaxed`,children:L===null?Z.on===null?`The camera did not report its microphone, so this state is unknown.`:Z.costWhenOff:`Write failed: ${L}`})]})]})}):null}export{v as PrivacyMaskSettings};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{J as l,_t as u,at as d,st as f,vt as p}from"./player-overlays-D9aoM64J.js";import{$c as m,As as h,Cu as g,En as _,Eu as v,Fn as y,In as b,It as x,Jc as S,Kc as C,Kn as w,Lt as T,Mu as E,Nn as D,Qc as O,Qd as k,Qf as A,Sn as j,Tn as M,Ud as N,Vn as P,Xc as ee,Yc as te,Zc as ne,_l as re,af as F,as as ie,bf as ae,bl as oe,bn as se,ca as I,dl as ce,ff as le,fl as ue,fr as de,gl as fe,hl as pe,il as me,ll as he,lr as L,mf as R,ml as ge,oc as _e,ol as ve,pl as ye,qc as z,qu as B,sl as V,uc as be,ul as xe,us as Se,vl as Ce,vs as we,wn as Te,xn as Ee,yl as De}from"./src-B-IRCQFw.js";import{c as Oe,i as ke,l as Ae,n as je,o as Me,r as Ne,s as Pe,t as Fe,u as Ie}from"./location-owned-usage-DQxXKxXh.js";import{t as Le}from"./settings-2-vAZgfnrs.js";import{hi as H}from"./client-DX0rAC3X.js";import{D as Re}from"./index-D7yeH_53.js";import{t as ze}from"./AdminPage-BSFohA3i.js";import{n as Be}from"./authed-media-Bi2u1rSm.js";import{t as Ve}from"./AdminTabs-wu-aryGN.js";import{t as U}from"./format-size-DIxKXxtj.js";var W=p(`arrow-right-left`,[[`path`,{d:`m16 3 4 4-4 4`,key:`1x1c3m`}],[`path`,{d:`M20 7H4`,key:`zbl0bi`}],[`path`,{d:`m8 21-4-4 4-4`,key:`h9nckh`}],[`path`,{d:`M4 17h16`,key:`g4d7ey`}]]),G=p(`scissors`,[[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M8.12 8.12 12 12`,key:`1alkpv`}],[`path`,{d:`M20 4 8.12 15.88`,key:`xgtan2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M14.8 14.8 20 20`,key:`ptml3r`}]]);t();var He=[{value:`all`,label:`All`},{value:`recording`,label:`Recordings`},{value:`events`,label:`Events`}],Ue={recording:`bg-primary/10 text-primary`,events:`bg-violet-500/10 text-violet-400`},We={columnKey:`at`,dir:`desc`};function Ge(e){return new Date(e).toLocaleString()}function Ke(){let[e,t]=o(`all`),{data:a,isLoading:c,isError:l}=S({},{refetchOnWindowFocus:!1}),{data:u,isLoading:d,isError:f}=we({},{refetchOnWindowFocus:!1}),{data:p}=I({isCamera:!0,projection:`slim`}),m=r(()=>{let e=new Map;for(let t of p??[])e.set(t.id,t.name);return e},[p]),h=r(()=>{let t=[...a??[],...u??[]];return(e===`all`?t:t.filter(t=>t.domain===e)).toSorted((e,t)=>t.at-e.at)},[a,u,e]),g=r(()=>{let t=[];return l&&e!==`events`&&t.push(`Recordings`),f&&e!==`recording`&&t.push(`Events`),t},[l,f,e]),_=r(()=>[{key:`at`,header:`When`,nowrap:!0,sortValue:e=>e.at,render:e=>s(`span`,{className:`text-foreground-subtle tabular-nums`,children:Ge(e.at)})},{key:`domain`,header:`Domain`,sortValue:e=>e.domain,render:e=>s(`span`,{className:`inline-flex rounded px-1.5 py-0.5 text-[10px] font-medium ${Ue[e.domain]}`,children:e.domain})},{key:`op`,header:`Operation`,sortValue:e=>e.op,render:e=>s(`span`,{className:`text-foreground`,children:e.op})},{key:`reason`,header:`Reason`,sortValue:e=>e.reason,render:e=>s(`span`,{className:`text-foreground-subtle`,children:e.reason})},{key:`device`,header:`Camera`,sortValue:e=>e.deviceId===null?`cluster`:m.get(e.deviceId)??`#${String(e.deviceId)}`,render:e=>e.deviceId===null?s(`span`,{className:`text-foreground-subtle`,children:`cluster`}):s(`span`,{className:`text-foreground`,children:m.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`items`,header:`Items`,align:`right`,nowrap:!0,sortValue:e=>e.itemsAffected,render:e=>s(`span`,{className:`tabular-nums`,children:e.itemsAffected.toLocaleString()})},{key:`bytes`,header:`Reclaimed`,align:`right`,nowrap:!0,sortValue:e=>e.bytesReclaimed,render:e=>s(`span`,{className:`tabular-nums`,children:e.bytesReclaimed>0?U(e.bytesReclaimed):`—`})}],[m]),v=c||d;return n(`div`,{className:`flex flex-col gap-4`,children:[s(`div`,{className:`flex items-center gap-1`,children:He.map(n=>s(`button`,{onClick:()=>t(n.value),className:`rounded px-2 py-1 text-xs font-medium ${e===n.value?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-muted`}`,children:n.label},n.value))}),v&&h.length===0?n(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[s(N,{className:`h-4 w-4 animate-spin`}),`Loading activity…`]}):h.length===0?g.length>0?s(D,{icon:B,title:`Activity could not be read`,description:`The ${g.join(` and `)} ops log did not answer. This is not "nothing happened" — retry, or check the node that owns it.`}):s(D,{icon:A,title:`No activity yet`,description:`Prune, delete and rescan operations across recordings and events show up here.`}):n(i,{children:[g.length>0&&n(`p`,{className:`flex items-center gap-1.5 text-[11px] text-amber-500`,children:[s(B,{className:`h-3 w-3 shrink-0`}),g.join(` and `),` did not answer — rows from`,` `,g.length===1?`that domain`:`those domains`,` are missing below.`]}),s(x,{columns:_,rows:h,rowKey:e=>e.id,minWidthPx:720,mobileMode:`scroll`,maxBodyHeight:T,defaultSort:We})]})]})}t();function qe(){let e=I({isCamera:!0,projection:`slim`}),t=r(()=>(e.data??[]).toSorted((e,t)=>e.name.localeCompare(t.name)),[e.data]),[i,a]=o(null),c=i??t[0]?.id??null;return!e.isLoading&&t.length===0?s(D,{icon:u,title:`No cameras`,description:`Add a camera first.`}):n(`div`,{className:`space-y-3`,children:[n(`div`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Per-camera recording & retention`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`Recording mode, schedule bands and the retention policy for one camera — the same controls as the camera's own Recording tab. Retention is one policy over footage and analytics; per-camera event deletion lives on the Events tab.`})]}),n(`div`,{className:`flex items-center gap-2`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Camera`}),s(`select`,{value:c??``,onChange:e=>a(Number(e.target.value)),className:`rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:t.map(e=>s(`option`,{value:e.id,children:e.name},e.id))})]}),c!==null&&s(P,{deviceId:c,children:s(Re,{deviceId:c,sectionFilter:e=>e.location===`top-tab`&&e.tab===`recording`})},c)]})}t();function Je({types:e}){let t=a(),i=w(),{data:c}=V({}),l=ve(),u=r(()=>l.data??[],[l.data]),{data:d}=z({},{refetchOnWindowFocus:!1}),f=r(()=>Fe(c??[],d?.locations),[c,d?.locations]),[p,m]=o(null),[h,g]=o(null),_=()=>{t.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})},v=oe({onSuccess:_}),y=me({onSuccess:_}),b=r(()=>{let e=new Map;for(let t of c??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[c]),x=async(e,t)=>{Ae(t)&&!await i({title:`Disable "${e.displayName}"?`,message:`${Oe(t).consequence}\n\nNothing is deleted — set the location back to Read-only or Active to bring its footage back.`,confirmLabel:`Disable`,variant:`danger`})||v.mutate(Pe(e,{mode:t}))},S=async e=>{if(await i({title:`Delete location "${e.displayName}"?`,message:`Removes the record; files on disk are untouched.`,confirmLabel:`Delete`,variant:`danger`}))try{await y.mutateAsync({id:e.id})}catch(t){await i({title:`Delete anyway?`,message:`${t instanceof Error?t.message:String(t)}\n\nForcing removes the record only. Anything still on that location becomes unreachable.`,confirmLabel:`Force delete`,variant:`danger`})&&y.mutate({id:e.id,force:!0})}},C=e.map(e=>u.find(t=>t.id===e)).filter(e=>e!==void 0);return n(`div`,{className:`space-y-3`,children:[C.length===0?s(`p`,{className:`text-[11px] text-foreground-subtle italic`,children:`No storage locations declared for this purpose.`}):C.map(e=>s(je,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:b.get(e.id)??[],onAdd:e=>m(e),onEdit:e=>g(e),onDelete:e=>{S(e)},ownedBytesById:f,onSetMode:(e,t)=>{x(e,t)}},e.id)),p!==null&&s(Ie,{initialType:p,onClose:()=>m(null),onCreated:()=>{_(),m(null)}}),h!==null&&s(Me,{location:h,onClose:()=>g(null),onSaved:()=>{_(),g(null)}})]})}t();var Ye=`pipeline-analytics`;function Xe(e){for(let t of e?.sections??[])for(let e of t.fields??[])if(e.key===`postProcessingNodeId`&&typeof e.value==`string`)return e.value;return`hub`}function Ze(){let e=a(),{nodes:t}=g(),{data:i,isLoading:o}=L({addonId:Ye}),c=Xe(i),l=de({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),u=r(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,c,...e])].filter(Boolean)},[t,c]);return n(`div`,{className:`flex flex-col gap-6`,children:[n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[s(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Post-processing node`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that runs detection post-processing (events, media, audio & motion). Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),n(`div`,{className:`mt-3 flex items-center gap-2`,children:[o?s(N,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):s(`select`,{value:c,onChange:e=>{e.target.value!==c&&l.mutate({addonId:Ye,patch:{postProcessingNodeId:e.target.value}})},disabled:l.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:u.map(e=>s(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),l.isPending&&s(N,{className:`h-4 w-4 animate-spin text-primary`})]})]}),n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[s(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Events folder`}),s(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),s(Je,{types:[`eventMedia`]})]})]})}t();var Qe=[[`pipelineAnalytics`]],$e=1440*60*1e3;function et(e,t){return t.get(e)??`Removed camera #${String(e)}`}var tt=[{days:1,label:`1 day`},{days:7,label:`7 days`},{days:30,label:`30 days`},{days:90,label:`90 days`}];function nt(){let t=a(),i=w(),[c,u]=o(30),[d,p]=o(null),{data:m,isLoading:g}=Se({},{refetchOnWindowFocus:!1}),{data:_}=I({isCamera:!0,projection:`slim`}),v=r(()=>{let e=new Map;for(let t of _??[])e.set(t.id,t.name);return e},[_]),y=e(()=>{t.invalidateQueries({queryKey:Qe})},[t]),b=h({onSuccess:y}),S=ie(),C=e(async()=>{await i({title:`Prune events older than ${String(c)} day${c===1?``:`s`}?`,message:`Permanently deletes every event (motion / object / audio) older than the cutoff across all cameras, and their media. This cannot be undone.`,confirmLabel:`Prune events`,variant:`danger`})&&b.mutate({olderThanMs:Date.now()-c*$e,reason:`retention`})},[i,b,c]),T=e(async e=>{let t=et(e.deviceId,v);if(await i({title:`Delete all events for ${t}?`,message:`Permanently deletes ${String(e.rows)} event${e.rows===1?``:`s`} (${U(e.bytes)} of media) for this camera. This cannot be undone.`,confirmLabel:`Delete events`,variant:`danger`})){p(null);try{let n=await S.mutateAsync({deviceId:e.deviceId});y();let r=n.motion+n.object+n.audio;if(r===0&&e.bytes>0){p(`0 events deleted for ${t}. Media still listed (${U(e.bytes)}) — those blobs are not event rows; use Management → Count leftovers or Disk reconcile.`);return}p(`Deleted ${String(r)} event${r===1?``:`s`} for ${t}.`)}catch(e){p(e instanceof Error?e.message:String(e))}}},[i,S,v,y]),E=r(()=>[{key:`camera`,header:`Camera`,render:e=>s(`span`,{className:`text-foreground`,children:et(e.deviceId,v)})},{key:`rows`,header:`Events`,align:`right`,nowrap:!0,render:e=>s(`span`,{className:`tabular-nums`,children:e.rows.toLocaleString()})},{key:`bytes`,header:`Media`,align:`right`,nowrap:!0,render:e=>s(`span`,{className:`tabular-nums`,children:U(e.bytes)})},{key:`actions`,header:``,align:`right`,render:e=>n(`button`,{onClick:()=>{T(e)},disabled:S.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:`Delete all events for this camera`,children:[s(f,{className:`h-3 w-3`}),`Delete`]})}],[v,T,S.isPending]);return g&&!m?n(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[s(N,{className:`h-4 w-4 animate-spin`}),`Loading event-store footprint…`]}):m?n(`div`,{className:`flex flex-col gap-6`,children:[n(`section`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[s(l,{label:`Total events`,icon:s(R,{className:`h-3 w-3`}),footer:`across ${String(m.devices.length)} camera${m.devices.length===1?``:`s`}`,children:m.totalRows.toLocaleString()}),s(l,{label:`Event media on disk`,children:U(m.totalBytes)})]}),n(`section`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[s(`span`,{className:`text-foreground-subtle`,children:`Prune events older than`}),s(`select`,{value:c,onChange:e=>u(Number(e.target.value)),className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:tt.map(e=>s(`option`,{value:e.days,children:e.label},e.days))}),n(`button`,{onClick:()=>{C()},disabled:b.isPending,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-xs font-medium text-foreground-subtle hover:bg-warning/10 hover:text-warning disabled:opacity-50`,children:[b.isPending?s(N,{className:`h-3 w-3 animate-spin`}):s(G,{className:`h-3 w-3`}),`Prune now`]})]}),m.devices.length===0?s(D,{icon:R,title:`No stored events`,description:`No camera has persisted events yet.`}):s(x,{columns:E,rows:[...m.devices],rowKey:e=>e.deviceId,minWidthPx:480}),d===null?null:s(`p`,{className:d.startsWith(`Deleted `)?`text-[11px] text-foreground-subtle`:`text-[11px] text-destructive`,children:d})]}):s(D,{icon:R,title:`No event data`,description:`Pipeline analytics has not reported any event-store footprint yet.`})}function rt(){return n(`div`,{className:`flex flex-col gap-8`,children:[n(`div`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Event store`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`What the durable event store occupies, per camera, with fleet-wide prune-by-age and delete-all-events.`}),s(`div`,{className:`mt-3`,children:s(nt,{})})]}),n(`div`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Post-processing node & folders`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that writes event crops, and the storage location they land in.`}),s(`div`,{className:`mt-3`,children:s(Ze,{})})]})]})}function it(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 at(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}function ot(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`${at(e)} · ${o}`}function st(e,t){let n=e-t;if(n<=0)return`expired`;let r=Math.floor(n/6e4);if(r<60)return`in ${String(r)}m`;let i=Math.floor(r/60);return i<24?`in ${String(i)}h`:`in ${String(Math.floor(i/24))}d`}function ct(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})}t();var lt=[`high`,`mid`,`low`],ut=[{value:1,label:`Real time (1×)`},{value:2,label:`2×`},{value:4,label:`4×`},{value:8,label:`8×`},{value:16,label:`16×`}],dt=10080*60*1e3;function ft(e){let t=new Date(Date.now()-e*6e4),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function pt({onClose:e,onCreated:t}){let i=I({isCamera:!0,projection:`slim`}),a=r(()=>(i.data??[]).toSorted((e,t)=>e.name.localeCompare(t.name)),[i.data]),[c,l]=o(``),[u,d]=o(`high`),[f,p]=o(ft(60)),[m,h]=o(ft(0)),[g,v]=o(1),[b,x]=o(!0),[S,C]=o(``),[w,T]=o(null),E=c===``?a[0]?.id??null:c,D=new Date(f).getTime(),O=new Date(m).getTime(),k=Number.isFinite(D)&&Number.isFinite(O)&&D<O,A=ne({onSuccess:()=>{t(),e()},onError:e=>T(e instanceof Error?e.message:String(e))});return s(se,{open:!0,onOpenChange:t=>!t&&e(),children:n(j,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[s(M,{children:n(_,{className:`flex items-center gap-1.5`,children:[s(F,{className:`h-3.5 w-3.5`}),`New export`]})}),n(Ee,{className:`space-y-3`,children:[n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Camera`}),s(`select`,{value:E??``,onChange:e=>l(Number(e.target.value)),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:a.map(e=>s(`option`,{value:e.id,children:e.name},e.id))})]}),n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Profile`}),s(`select`,{value:u,onChange:e=>d(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:lt.map(e=>s(`option`,{value:e,children:e},e))})]})]}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`From`}),s(`input`,{type:`datetime-local`,value:f,onChange:e=>p(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`})]}),n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`To`}),s(`input`,{type:`datetime-local`,value:m,onChange:e=>h(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`})]})]}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Speed`}),s(`select`,{value:g,onChange:e=>v(Number(e.target.value)),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:ut.map(e=>s(`option`,{value:e.value,children:e.label},e.value))})]}),n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Title (optional)`}),s(`input`,{type:`text`,value:S,onChange:e=>C(e.target.value),placeholder:`e.g. courier at the gate`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle`})]})]}),n(`label`,{className:`flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:b,disabled:g!==1,onChange:e=>x(e.target.checked),className:`accent-primary`}),`Include audio`,g===1?``:` (real-time only)`]}),!k&&s(`p`,{className:`text-[11px] text-danger`,children:`"From" must be before "To".`}),w&&s(`p`,{className:`text-[11px] text-danger`,children:w})]}),n(Te,{children:[s(y,{variant:`outline`,size:`sm`,onClick:e,children:`Cancel`}),s(y,{size:`sm`,onClick:()=>{if(E===null||!k)return;T(null);let e=S.trim();A.mutate({deviceId:E,profile:u,fromMs:D,toMs:O,options:{includeAudio:b,maxLifeMs:dt,deleteAfterDownload:!1,...g===1?{}:{speed:g},...e.length>0?{title:e}:{}}})},disabled:E===null||!k||A.isPending,children:A.isPending?`Queuing…`:`Create export`})]})]})})}t();var mt=[[`recordingExport`]],ht={queued:{cls:`bg-muted text-foreground-subtle`,label:`queued`},rendering:{cls:`bg-primary/10 text-primary`,label:`rendering`,spin:!0},ready:{cls:`bg-success/10 text-success`,label:`ready`},failed:{cls:`bg-danger/10 text-danger`,label:`failed`},expired:{cls:`bg-muted text-foreground-subtle`,label:`expired`},deleted:{cls:`bg-muted text-foreground-subtle`,label:`deleted`}};function gt(){let{data:e,isLoading:t}=m({},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`queued`||e.state===`rendering`)?3e3:!1}),{map:n}=v(H.RecordingExportProgress,e=>e.exportId),{map:i}=v(H.RecordingExportCompleted,e=>e.exportId),{map:a}=v(H.RecordingExportFailed,e=>e.exportId);return{rows:r(()=>ct(e??[],n,i,a),[e,n,i,a]),isLoading:t}}function _t(e){let[t,n]=o(()=>Date.now());return c(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function vt(){let t=a(),[i,c]=o(!1),l=()=>{t.invalidateQueries({queryKey:[[`recordingExport`,`listExports`]]})},u=w(),p=d().trpcClient,m=_t(6e4),{rows:h,isLoading:g}=gt(),{data:_}=I({isCamera:!0,projection:`slim`}),v=r(()=>{let e=new Map;for(let t of _??[])e.set(t.id,t.name);return e},[_]),y=e(()=>{t.invalidateQueries({queryKey:mt})},[t]),b=ee({onSuccess:y}),S=O({onSuccess:y}),[C,T]=o(null),E=e(async e=>{T(e.id);try{let{url:t}=await p.recordingExport.getDownloadUrl.query({exportId:e.id}),n=await Be(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),y()}finally{T(null)}},[p,y]),k=e(async e=>{await u({title:`Cancel this export?`,message:`Stops the render. The partial file is discarded.`,confirmLabel:`Cancel export`,variant:`danger`})&&b.mutate({exportId:e.id})},[u,b]),A=e(async e=>{await u({title:`Delete this export?`,message:`Permanently removes the rendered file and its history row.`,confirmLabel:`Delete`,variant:`danger`})&&S.mutate({exportId:e.id})},[u,S]),j=r(()=>[{key:`camera`,header:`Camera`,render:e=>s(`span`,{className:`text-foreground`,children:v.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`range`,header:`Range`,nowrap:!0,render:e=>s(`span`,{className:`tabular-nums`,children:ot(e.fromMs,e.toMs)})},{key:`variant`,header:`Variant`,render:e=>s(`span`,{className:`text-foreground-subtle`,children:it(e.options)})},{key:`state`,header:`State`,render:e=>{let t=ht[e.state];return n(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${t.cls}`,children:[t.spin&&s(N,{className:`h-2.5 w-2.5 animate-spin`}),t.label,e.state===`rendering`&&e.progressPct!==null&&n(`span`,{className:`tabular-nums`,children:[e.progressPct,`%`]})]})}},{key:`expiry`,header:`Expires`,nowrap:!0,render:e=>e.state===`deleted`?s(`span`,{className:`text-foreground-subtle`,children:`—`}):s(`span`,{className:`text-foreground-subtle tabular-nums`,children:st(e.expiresAt,m)})},{key:`size`,header:`Size`,align:`right`,nowrap:!0,render:e=>s(`span`,{className:`tabular-nums`,children:e.fileBytes===null?`—`:U(e.fileBytes)})},{key:`actions`,header:``,align:`right`,render:e=>{let t=e.state===`ready`,r=e.state===`queued`||e.state===`rendering`,i=e.state!==`deleted`;return n(`div`,{className:`flex items-center justify-end gap-1`,children:[t&&n(`button`,{onClick:()=>{E(e)},disabled:C===e.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:`Download MP4`,children:[C===e.id?s(N,{className:`h-3 w-3 animate-spin`}):s(le,{className:`h-3 w-3`}),`Download`]}),r&&n(`button`,{onClick:()=>{k(e)},disabled:b.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-amber-500/10 hover:text-amber-500 disabled:opacity-50`,title:`Cancel render`,children:[s(ae,{className:`h-3 w-3`}),`Cancel`]}),i&&s(`button`,{onClick:()=>{A(e)},disabled:S.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:`Delete export`,children:s(f,{className:`h-3 w-3`})})]})}}],[v,m,C,b.isPending,S.isPending,E,k,A]);return g&&h.length===0?n(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[s(N,{className:`h-4 w-4 animate-spin`}),`Loading exports…`]}):n(`div`,{className:`space-y-3`,children:[s(`div`,{className:`flex justify-end`,children:n(`button`,{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:[s(F,{className:`h-3.5 w-3.5`}),`New export`]})}),h.length===0?s(D,{icon:F,title:`No exports yet`,description:`Create one here (New export) or from a camera's timeline in the viewer. Rendered clips show up here to download or manage.`}):s(x,{columns:j,rows:h,rowKey:e=>e.id,minWidthPx:720}),i&&s(pt,{onClose:()=>c(!1),onCreated:l})]})}var yt=`inline-flex w-fit items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`;t();var bt=`storage-migration`,xt=new Set([`orphans`,`debug-media`,`ghost-ledger`]);function St(e){return[`${e.orphansReclaimed} orphan rows (${U(e.orphanBytesReclaimed)})`,e.includeDebugMedia?`${e.debugMediaReclaimed} debug files (${U(e.debugMediaBytesReclaimed)})`:null,`${e.ghostsForgotten} ghost rows (${U(e.ghostBytesForgotten)})`].filter(e=>e!==null).join(` · `)}function Ct(){let e=b(bt);return e===`pending`?null:e===`unknown`?s(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`Could not check whether storage cleanup is installed on this hub.`}):e===`present`?s(wt,{}):null}function wt(){let e=w(),[t,r]=o(!1),[i,a]=o(null),c=ue({},{refetchInterval:2e3}),l=c.data??null,u=l!==null&&xt.has(l.phase),d=ce(),p=xe(),m=async()=>{if(await e({title:`Run storage cleanup?`,message:t?`Reclaims leftover analytics rows and files, debug stills/filmstrips, and ghost footage rows on frozen locations. Safe to re-run.`:`Reclaims leftover analytics rows and files, and ghost footage rows on frozen locations. Debug stills are left alone. Safe to re-run.`,confirmLabel:`Run cleanup`,variant:`danger`})){a(null);try{await d.mutateAsync({includeDebugMedia:t}),await c.refetch()}catch(e){a(e instanceof Error?e.message:String(e))}}},h=async()=>{if(l&&await e({title:`Cancel cleanup?`,message:`Stops after the current step. Work already done stays done.`,confirmLabel:`Cancel cleanup`,variant:`danger`}))try{await p.mutateAsync({jobId:l.jobId}),await c.refetch()}catch{}};return n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Cleanup`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`One pass over leftover analytics (database + files) and ghost footage rows on frozen locations. Does not time out — progress updates here until it finishes.`}),n(`label`,{className:`mt-3 flex items-start gap-2 text-[11px] text-foreground`,children:[s(`input`,{type:`checkbox`,checked:t,disabled:u,onChange:e=>{r(e.target.checked)},className:`mt-0.5 h-3.5 w-3.5 accent-primary`}),s(`span`,{children:`Also remove debug media (motion stills and track filmstrips)`})]}),n(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[n(`button`,{type:`button`,disabled:u||d.isPending,onClick:()=>{m()},className:yt,children:[(u||d.isPending)&&s(N,{className:`h-3 w-3 animate-spin`}),s(f,{className:`h-3 w-3`}),`Run cleanup`]}),u&&s(`button`,{type:`button`,onClick:()=>{h()},className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10`,children:`Cancel`})]}),i&&s(`p`,{className:`mt-2 text-[11px] text-danger`,children:i}),l&&n(`div`,{className:`mt-3 space-y-1 rounded-md border border-border px-2.5 py-2`,children:[n(`p`,{className:`text-xs text-foreground`,children:[`Phase: `,s(`span`,{className:`font-medium`,children:l.phase}),u&&s(N,{className:`ml-2 inline h-3 w-3 animate-spin text-primary`})]}),l.detail&&s(`p`,{className:`text-[11px] text-foreground-subtle`,children:l.detail}),s(`p`,{className:`text-[11px] text-foreground-subtle`,children:St(l)}),l.error&&s(`p`,{className:`text-[11px] text-danger`,children:l.error})]})]})}t();var Tt=2e3;function Et(){let e=w(),t=a(),r=be(),i=_e(void 0,{refetchInterval:e=>e.state.data?.state===`running`?Tt:!1}),o=i.data,l=o?.state===`running`,u=l||r.isPending;c(()=>{o?.state!==`done`||o.finishedAtMs===null||(t.invalidateQueries({queryKey:[[`recording`]]}),t.invalidateQueries({queryKey:[[`pipelineAnalytics`]]}))},[o?.state,o?.finishedAtMs,t]);let d=async()=>{await e({title:`Reconcile storage from disk?`,message:`Makes the database match the filesystem: recordings index, tracks, events and media whose files are gone. Favourited tracks without files are deleted. Snapshot-less motion/audio events are deleted. Enrolled identities stay. This cannot be undone.`,confirmLabel:`Reconcile`,variant:`warning`})&&(await r.mutateAsync(),await i.refetch())},f=l?o.total>0?`Reconciling ${String(o.completed)}/${String(o.total)}…`:`Reconciling…`:r.isPending?`Reconciling…`:`Reconcile from disk`;return n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[s(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Disk reconcile`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`Deletes database rows whose files are gone. Enrolled identities stay.`}),n(`div`,{className:`mt-3 flex flex-col gap-2`,children:[n(`button`,{type:`button`,onClick:()=>void d(),disabled:u,className:`inline-flex w-fit items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[u?s(N,{className:`h-3.5 w-3.5 animate-spin`}):s(k,{className:`h-3.5 w-3.5`}),f]}),o?.state===`done`?n(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Last run: `,String(o.completed),` camera(s) — dropped `,String(o.tracks),` tracks,`,` `,String(o.events),` events, `,String(o.mediaDropped),` media`,o.failed.length>0?`, ${String(o.failed.length)} failed (${o.failed.join(`, `)})`:``,`.`]}):null,o?.state===`error`&&o.error!==null?n(`p`,{className:`text-[11px] text-destructive`,children:[`Reconcile failed: `,o.error]}):null]})]})}var K=1e3,q=60*K,J=60*q;function Y(e){return e.toLocaleString(`en-US`)}function Dt(e){if(!Number.isFinite(e)||e<0)return`—`;if(e>=J){let t=Math.floor(e/J),n=Math.round(e%J/q);return`${t.toString()}h ${n.toString()}m`}if(e>=q){let t=Math.floor(e/q),n=Math.round(e%q/K);return`${t.toString()}m ${n.toString()}s`}return`${Math.max(0,Math.round(e/K)).toString()}s`}function Ot(e){let t=Math.max(0,e.observedAt-e.startedAt),n=e.filesTotal===null?`${Y(e.filesMoved)} files`:`${Y(e.filesMoved)} / ${Y(e.filesTotal)} files`,r=e.filesTotal===null||e.filesTotal===0?null:Math.min(1,e.filesMoved/e.filesTotal),i=t>0&&e.filesMoved>0,a=i?`${U(e.bytesMoved/t*K)}/s`:null,o=e.filesTotal===null?null:e.filesTotal-e.filesMoved,s=!i||o===null||o<=0?null:`~${Dt(o*t/e.filesMoved)} left`;return{counted:n,fraction:r,moved:`${U(e.bytesMoved)} moved`,rate:a,eta:s}}function kt(e){let t=Ot(e);return[t.counted,t.moved,t.rate,t.eta].filter(e=>e!==null).join(` · `)}t();var At=`storage-migration`,X=[{id:`recordings`,label:`Recordings`,locationType:`recordings`},{id:`recordingsLow`,label:`Low-res recordings`,locationType:`recordingsLow`},{id:`eventMedia`,label:`Event media`,locationType:`eventMedia`}],jt=new Set([`planning`,`sealing`,`pausing`,`moving`,`draining`,`verifying`,`repointing`,`refreshing`,`resuming`]);function Mt(){let e=b(At);return e===`pending`?n(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[s(N,{className:`h-4 w-4 animate-spin`}),`Checking whether storage migration is installed…`]}):e===`unknown`?s(D,{icon:B,title:`Couldn't check whether storage migration is installed`,description:`The capability registry did not answer, so this panel has nothing to report either way — it is not a statement that the capability is missing. Reload to ask again.`}):e===`absent`?s(D,{icon:W,title:`Storage migration not installed`,description:`The capability registry answered: no addon in this cluster provides storage-migration. Once one is deployed, this panel moves recordings, low-res recordings and event media to new storage locations in one coordinated, verified operation.`}):s(Nt,{})}function Nt(){let e=w(),{data:t}=V({}),[i,a]=o({}),[c,l]=o({}),[u,d]=o(null),[f,p]=o(null),m=r(()=>{let e=new Map;for(let n of t??[]){let t=e.get(n.type);t?t.push(n):e.set(n.type,[n])}return e},[t]),h=r(()=>{let e=new Map;for(let n of t??[]){if(n.enabled===!1)continue;let t=e.get(n.type);t?t.push(n.id):e.set(n.type,[n.id])}let n=new Map;for(let[t,r]of e)r.length===1&&n.set(t,r[0]);return n},[t]),g=De({},{refetchInterval:2e3}),_=g.data??null,v=_!==null&&jt.has(_.phase),y=r(()=>{let e={};for(let t of X){let n=i[t.id];n&&(e[t.id]=n)}return Object.keys(e).length>0?e:void 0},[i]),b=r(()=>{let e={};for(let t of X){if(!i[t.id])continue;let n=c[t.id]??h.get(t.locationType);n&&(e[t.id]=n)}return Object.keys(e).length>0?e:void 0},[i,c,h]),x=r(()=>({destinations:y??{},...b?{sources:b}:{}}),[y,b]),S=fe(x,{enabled:!1,retry:!1}),C=Ce(),T=he(),D=async()=>{if(!y)return;p(null);let e=await S.refetch();if(e.error){p(e.error instanceof Error?e.error.message:String(e.error));return}d(e.data??null)},O=async()=>{if(y&&await e({title:`Start storage migration?`,message:`Copies the selected classes from the chosen source to the destination, verifies, then either makes the destination the default (if the source was) or disables the source. Safe to re-run if interrupted.`,confirmLabel:`Start migration`,variant:`danger`})){p(null);try{await C.mutateAsync(x),d(null),await g.refetch()}catch(e){p(e instanceof Error?e.message:String(e))}}},k=async()=>{if(_&&await e({title:`Cancel migration?`,message:`Stops the in-progress migration. Data already moved and verified stays at the destination; anything already repointed is not reverted.`,confirmLabel:`Cancel migration`,variant:`danger`}))try{await T.mutateAsync({jobId:_.jobId}),await g.refetch()}catch{}};return n(`div`,{className:`flex flex-col gap-6`,children:[n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[n(`h3`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[s(W,{className:`h-3.5 w-3.5`}),`Storage migration`]}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`Move recordings, low-res recordings and/or event media from one location to another: copies via the recorder / pipeline-analytics movers, verifies, then either repoints the default (when the source was the default) or disables the source (when it was not). Skip a class with an empty destination.`}),s(`div`,{className:`mt-3 grid grid-cols-1 gap-3 sm:grid-cols-3`,children:X.map(e=>{let t=m.get(e.locationType)??[],r=h.get(e.locationType)??``;return n(`div`,{className:`space-y-2`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e.label}),n(`div`,{className:`space-y-1`,children:[n(`label`,{htmlFor:`migration-from-${e.id}`,className:`text-[10px] text-foreground-subtle`,children:[e.label,` from`]}),s(`select`,{id:`migration-from-${e.id}`,value:c[e.id]??r,onChange:t=>{let n=t.target.value;l(t=>({...t,[e.id]:n}))},disabled:v,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground disabled:opacity-50`,children:t.map(e=>n(`option`,{value:e.id,children:[e.displayName,e.enabled===!1?` (read-only)`:``]},e.id))})]}),n(`div`,{className:`space-y-1`,children:[n(`label`,{htmlFor:`migration-dest-${e.id}`,className:`text-[10px] text-foreground-subtle`,children:[e.label,` to`]}),n(`select`,{id:`migration-dest-${e.id}`,value:i[e.id]??``,onChange:t=>{let n=t.target.value;a(t=>({...t,[e.id]:n}))},disabled:v,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground disabled:opacity-50`,children:[s(`option`,{value:``,children:`— skip —`}),t.map(e=>s(`option`,{value:e.id,children:e.displayName},e.id))]})]})]},e.id)})}),f&&s(`p`,{className:`mt-2 text-[11px] text-danger`,children:f}),n(`div`,{className:`mt-3 flex items-center gap-2`,children:[n(`button`,{type:`button`,onClick:()=>{D()},disabled:!y||S.isFetching||v,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[S.isFetching&&s(N,{className:`h-3 w-3 animate-spin`}),`Plan`]}),n(`button`,{type:`button`,onClick:()=>{O()},disabled:!y||C.isPending||v,className:`inline-flex items-center gap-1.5 rounded bg-primary px-2.5 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:[C.isPending&&s(N,{className:`h-3 w-3 animate-spin`}),`Start migration`]})]}),u&&s(`div`,{className:`mt-3 divide-y divide-border rounded-md border border-border`,children:u.moves.length===0?s(`p`,{className:`px-2.5 py-1.5 text-[11px] text-foreground-subtle`,children:`Nothing to move — selected destinations match the current defaults.`}):u.moves.map(e=>n(`div`,{className:`px-2.5 py-1.5 text-[11px] text-foreground`,children:[e.storageClass,`: `,e.fromLocationId,` → `,e.toLocationId]},`${e.storageClass}-${e.toLocationId}`))}),_&&n(`div`,{className:`mt-4 border-t border-border pt-3`,children:[n(`div`,{className:`flex items-center justify-between`,children:[s(`h4`,{className:`text-xs font-semibold text-foreground`,children:`Migration status`}),v&&n(`button`,{type:`button`,onClick:()=>{k()},className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10`,children:[s(E,{className:`h-3 w-3`}),`Cancel`]})]}),n(`p`,{className:`mt-1 text-xs text-foreground`,children:[`Phase: `,s(`span`,{className:`font-medium`,children:_.phase}),v&&s(N,{className:`ml-2 inline h-3 w-3 animate-spin text-primary`})]}),_.error&&s(`p`,{className:`mt-1 text-[11px] text-danger`,children:_.error}),_.pausedParticipants.length>0&&n(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:[`Paused: `,_.pausedParticipants.join(`, `)]}),s(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:_.moves.map(e=>s(Pt,{move:e},`${e.storageClass}-${e.fromLocationId}`))})]}),s(Ft,{})]}),s(It,{running:v}),s(Rt,{})]})}function Pt({move:e}){let t=e.progress===null?null:Ot(e.progress);return n(`div`,{className:`px-2.5 py-1.5 text-[11px]`,children:[n(`div`,{className:`flex items-center justify-between`,children:[n(`span`,{className:`text-foreground`,children:[e.storageClass,`: `,e.fromLocationId,` → `,e.toLocationId]}),n(`span`,{className:`text-foreground-subtle`,children:[e.state??`pending`,e.error?` (${e.error})`:``]})]}),e.progress!==null&&n(`div`,{className:`mt-1 space-y-1`,children:[t!==null&&t.fraction!==null&&s(`div`,{className:`h-1 w-full overflow-hidden rounded bg-border`,children:s(`div`,{className:`h-full bg-primary`,style:{width:`${(t.fraction*100).toFixed(1)}%`}})}),s(`p`,{className:`text-[10px] text-foreground-subtle`,children:kt(e.progress)})]})]})}function Ft(){let{data:e}=ge({});return!e||e.length===0?null:n(`div`,{className:`mt-4 border-t border-border pt-3`,children:[s(`h4`,{className:`text-xs font-semibold text-foreground`,children:`Migration history`}),s(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:e.map(e=>n(`div`,{className:`px-2.5 py-1.5 text-[11px] text-foreground-subtle`,children:[s(`span`,{className:`font-medium text-foreground`,children:e.phase}),` · `,Object.entries(e.destinations).filter(e=>typeof e[1]==`string`).map(([e,t])=>`${e} → ${t}`).join(`, `),` · `,new Date(e.startedAt).toLocaleString()]},e.jobId))})]})}function It({running:e}){let t=w(),r=re({},{staleTime:1/0,refetchOnWindowFocus:!1}),i=ye(),[a,c]=o(null),l=r.data??[];if(l.length===0)return null;let u=async e=>{if(await t({title:`Drain remaining ${e.storageClass}?`,message:`Moves what is still on ${e.fromLocationId} to ${e.toLocationId}. Nothing is paused and no default is changed — this is the second half of a migration, run on its own. It is resumable: cancelling leaves everything readable from both locations.`,confirmLabel:`Drain remaining`,variant:`danger`})){c(null);try{await i.mutateAsync({classes:[e.storageClass]}),await r.refetch()}catch(e){c(e instanceof Error?e.message:String(e))}}};return n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[n(`div`,{className:`flex items-start justify-between gap-2`,children:[s(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Left on the old location`}),n(`div`,{className:`flex shrink-0 items-center gap-2`,children:[s(`span`,{className:`text-[10px] text-foreground-subtle`,children:r.dataUpdatedAt>0?`Measured ${new Date(r.dataUpdatedAt).toLocaleTimeString()}`:`Measured — never`}),s(`button`,{type:`button`,onClick:()=>{r.refetch()},disabled:r.isFetching,className:`rounded border border-border px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`,children:r.isFetching?`Counting…`:`Refresh`})]})]}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`A migration repoints first and drains behind. If the drain was cancelled, failed, or was interrupted by a restart, the data below is still on the source — readable, but not where the defaults now point. Draining moves it; it changes no default and pauses nothing.`}),s(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:`This count is taken on demand: measuring it walks the whole media collection, so it is not refreshed on a timer. Press Refresh after a drain finishes.`}),a&&s(`p`,{className:`mt-2 text-[11px] text-danger`,children:a}),s(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:l.map(t=>n(`div`,{className:`flex items-center justify-between gap-2 px-2.5 py-1.5 text-[11px]`,children:[n(`span`,{className:`text-foreground`,children:[t.storageClass,`: `,t.fromLocationId,` → `,t.toLocationId,s(`span`,{className:`ml-2 text-foreground-subtle`,children:Lt(t)})]}),s(`button`,{type:`button`,onClick:()=>{u(t)},disabled:e||i.isPending,className:`shrink-0 rounded border border-border px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`,children:`Drain remaining`})]},`${t.storageClass}-${t.fromLocationId}`))})]})}function Lt(e){if(e.items===null)return`amount unknown — the archive could not be read`;let t=e.items.toLocaleString(`en-US`);return e.bytes===null?`${t} rows`:`${t} segments · ${U(e.bytes)}`}function Rt(){let{data:e}=pe({},{refetchInterval:2e3}),t=(e??[]).filter(e=>e.migrationJobId===null&&e.job.state===`running`);return t.length===0?null:n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[s(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Movers running outside a migration`}),s(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:t.map(e=>n(`div`,{className:`px-2.5 py-1.5 text-[11px]`,children:[n(`div`,{className:`text-foreground`,children:[e.lane,`: `,e.job.fromLocationId,` → `,e.job.toLocationId]}),s(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:kt({filesMoved:e.job.filesMoved,filesTotal:e.job.filesTotal,bytesMoved:e.job.bytesMoved,startedAt:e.job.startedAt,observedAt:e.observedAt})})]},e.job.jobId))})]})}function zt(){return n(`div`,{className:`flex flex-col gap-4`,children:[s(Ct,{}),s(Et,{}),n(`section`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Move storage`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`Copy recordings, low-res recordings or event media to a new location, verify, then repoint the default. Applies to every camera.`}),s(`div`,{className:`mt-3`,children:s(Mt,{})})]})]})}t();var Bt=`recorder`;function Vt(e,t,n){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t&&typeof e.value==`string`)return e.value;return n}function Ht(){let e=a(),{nodes:t}=g(),{data:i,isLoading:o}=L({addonId:Bt}),c=Vt(i,`recordingNodeId`,`hub`),l=de({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),u=r(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,c,...e])].filter(Boolean)},[t,c]);return n(`div`,{className:`flex flex-col gap-6`,children:[n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[s(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Recording node`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that records (continuous & events) and serves playback. Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),n(`div`,{className:`mt-3 flex items-center gap-2`,children:[o?s(N,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):s(`select`,{value:c,onChange:e=>{e.target.value!==c&&l.mutate({addonId:Bt,patch:{recordingNodeId:e.target.value}})},disabled:l.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:u.map(e=>s(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),l.isPending&&s(N,{className:`h-4 w-4 animate-spin text-primary`})]}),c!==`hub`&&n(`p`,{className:`mt-2 text-[11px] text-amber-500`,children:[`The stream-broker is hub-only — an agent recorder pulls streams from the hub over the network. The hub's RTSP restream port must be reachable from`,` `,s(`span`,{className:`font-medium`,children:c}),`. If the auto-derived host doesn't work, set the recorder's`,s(`span`,{className:`font-medium`,children:` recordingHubHostname`}),` global setting.`]})]}),n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[s(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Recordings folders`}),s(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where recordings are stored. Multi-location collections — segments are split across the locations of a type. Add a location to grow capacity; mark one default per type.`}),s(Je,{types:[`recordings`,`recordingsLow`]})]})]})}function Z(e){return e.locationIds!==void 0&&e.locationIds.length>0?e.locationIds:e.locationId===null?[]:[e.locationId]}function Ut(e,t){let n=Z(e);return n.length===0?`default root`:n.map(e=>t.get(e)??e).join(` + `)}function Wt(e,t,n){if(e.length===0)return null;let r=e[0];if(e.length===1&&r!==void 0)return{label:Ut(r,t),exact:!0};if(n===null)return null;let i=e.find(e=>Z(e).includes(n));return i===void 0?null:{label:Ut(i,t),exact:!1}}t();var Gt=[[`recording`]],Kt=[{value:`retention`,label:`Retention policy`},{value:`quota`,label:`Quota / disk pressure`},{value:`operator`,label:`Operator`}],qt={ok:`bg-primary`,warn:`bg-amber-500`,critical:`bg-danger`},Q={ok:`text-foreground-subtle`,warn:`text-amber-500`,critical:`text-danger`};function $(e){return`${String(Math.round(e*100))}%`}function Jt(e){return e==null?`—`:new Date(e).toLocaleString()}function Yt(e,t){let n=e.locationIds??(e.locationId===null?[]:[e.locationId]),r=n.map(e=>t.get(e)).filter(e=>e!==void 0);return r.length>0?r.join(` + `):e.root===void 0?n.length>0?n.join(` + `):`default root`:e.root}function Xt(){let t=a(),i=w(),[c,u]=o(`retention`),{data:d,isLoading:p}=z({},{refetchOnWindowFocus:!1}),{data:m}=I({isCamera:!0,projection:`slim`}),{data:h}=V({}),g=r(()=>{let e=new Map;for(let t of m??[])e.set(t.id,t.name);return e},[m]),_=r(()=>{let e=new Map;for(let t of h??[])e.set(t.id,t.displayName);return e},[h]),v=r(()=>{let e=h??[];return e.find(e=>e.type===`recordings`&&e.enabled!==!1)?.id??e.find(e=>e.type===`recordings`)?.id??null},[h]),y=r(()=>d?.locations??[],[d?.locations]),b=r(()=>Wt(y,_,v),[y,_,v]),S=r(()=>ke(y),[y]),T=e(()=>{t.invalidateQueries({queryKey:Gt})},[t]),E=te({onSuccess:T}),O=C({onSuccess:T}),A=e(async e=>{await i({title:`Prune ${g.get(e.deviceId)??`#${String(e.deviceId)}`}?`,message:`Applies the retention policy now (reason: ${c}). Footage beyond the policy is permanently deleted.`,confirmLabel:`Prune now`,variant:`danger`})&&E.mutate({deviceId:e.deviceId,reason:c})},[i,E,c,g]),j=e(async e=>{await i({title:`Delete all footage for ${g.get(e.deviceId)??`#${String(e.deviceId)}`}?`,message:`Permanently deletes ${U(e.usedBytes)} of recorded footage for this camera. This cannot be undone.`,confirmLabel:`Delete ${U(e.usedBytes)}`,variant:`danger`})&&O.mutate({deviceId:e.deviceId})},[i,O,g]),M=r(()=>[{key:`camera`,header:`Camera`,render:e=>s(`span`,{className:`text-foreground`,children:g.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`disk`,header:`Disk`,nowrap:!0,render:()=>b===null?s(`span`,{className:`text-foreground-subtle`,children:`—`}):n(`span`,{className:b.exact?`text-foreground`:`text-foreground-subtle`,title:b.exact?`The only recordings volume on this node — this camera can only be here.`:`The recordings DEFAULT. This node has several recordings volumes and the per-camera placement is not reported by recording.getStorageUsage, so this is where footage lands by default rather than a per-camera fact.`,children:[b.label,!b.exact&&s(`span`,{className:`ml-1 text-foreground-subtle`,children:`(default)`})]})},{key:`used`,header:`Used`,align:`right`,nowrap:!0,render:e=>s(`span`,{className:`tabular-nums`,children:U(e.usedBytes)})},{key:`oldest`,header:`Oldest footage`,align:`right`,nowrap:!0,render:e=>s(`span`,{className:`tabular-nums text-foreground-subtle`,title:`The oldest segment the ARCHIVE holds for this camera — the per-camera answer to 'is retention actually holding?'.`,children:Jt(e.oldestMs)})},{key:`actions`,header:``,align:`right`,render:e=>n(`div`,{className:`flex items-center justify-end gap-1`,children:[n(`button`,{onClick:()=>{A(e)},disabled:E.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-amber-500/10 hover:text-amber-500 disabled:opacity-50`,title:`Apply retention policy now`,children:[s(G,{className:`h-3 w-3`}),`Prune`]}),n(`button`,{onClick:()=>{j(e)},disabled:O.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:`Delete all footage`,children:[s(f,{className:`h-3 w-3`}),`Delete`]})]})}],[g,b,A,j,E.isPending,O.isPending]);if(p&&!d)return n(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[s(N,{className:`h-4 w-4 animate-spin`}),`Loading storage usage…`]});if(!d)return s(D,{icon:k,title:`No storage data`,description:`The recording node has not reported any storage usage yet.`});let P=d.devices.length;return n(`div`,{className:`flex flex-col gap-6`,children:[n(`section`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:[s(l,{label:`Total used`,icon:s(k,{className:`h-3 w-3`}),footer:`${String(P)} camera${P===1?``:`s`} on ${d.nodeId}`,children:U(d.totalUsedBytes)}),S!==null&&S.severity!==null&&s(l,{label:`Free on recordings volumes`,icon:s(k,{className:`h-3 w-3`}),footer:`across ${String(S.knownVolumes)} volume${S.knownVolumes===1?``:`s`} of ${U(S.totalBytes)}`+(S.unknownVolumes>0?` · ${String(S.unknownVolumes)} did not report capacity`:``),children:s(`span`,{className:`tabular-nums ${Q[S.severity]}`,children:U(S.freeBytes)})}),y.map(e=>{let t=Ne(e),r=e.locationId??e.root??`default`;return s(l,{label:`Disk: ${Yt(e,_)}`,footer:t===null?`${U(e.usedBytes)} of recordings · volume capacity unknown`:`${U(t.freeBytes)} free of ${U(t.totalBytes)} · ${U(e.usedBytes)} recordings (${$(t.recordingsFraction)})`,children:t===null?s(`span`,{className:`tabular-nums`,children:U(e.usedBytes)}):n(`div`,{className:`flex items-center gap-2`,title:`Volume fill — everything on the disk, not only recordings. Warn at 85%, critical at 95%.`,children:[s(`div`,{className:`h-2 flex-1 overflow-hidden rounded bg-muted`,children:s(`div`,{className:`h-full rounded ${qt[t.severity]}`,style:{width:$(t.fraction)}})}),s(`span`,{className:`tabular-nums text-xs ${Q[t.severity]}`,children:$(t.fraction)})]})},r)})]}),n(`section`,{className:`flex items-center gap-2 text-xs`,children:[s(`label`,{htmlFor:`prune-reason`,className:`text-foreground-subtle`,children:`Prune reason`}),s(`select`,{id:`prune-reason`,value:c,onChange:e=>{let t=Kt.find(t=>t.value===e.target.value);t&&u(t.value)},className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:Kt.map(e=>s(`option`,{value:e.value,children:e.label},e.value))})]}),P===0?s(D,{icon:k,title:d.devicesRead===`unavailable`?`Per-camera usage unavailable`:`No recorded footage`,description:d.devicesRead===`unavailable`?`This recording node has no footage ledger, so it refused to answer the per-camera table rather than report what it happens to hold in memory. The disk totals above are unaffected.`:`No camera has recorded footage on this node yet.`}):s(x,{columns:M,rows:[...d.devices],rowKey:e=>e.deviceId,minWidthPx:480})]})}function Zt(){return n(`div`,{className:`flex flex-col gap-8`,children:[n(`div`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Footage on disk`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`What recorded footage occupies, per camera and per volume, with prune-by-policy and delete-all-footage.`}),s(`div`,{className:`mt-3`,children:s(Xt,{})})]}),n(`div`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Recording node & folders`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that records and serves playback, and the storage locations footage is written to.`}),s(`div`,{className:`mt-3`,children:s(Ht,{})})]})]})}function Qt(){return s(ze,{icon:F,title:`Recordings`,subtitle:`Recorded footage and the durable event store — what each occupies, where it is written, and the operations that move or reconcile both.`,children:s(Ve,{tabs:[{id:`storage`,label:`Recordings`,icon:k,content:s(Zt,{})},{id:`events`,label:`Events`,icon:R,content:s(rt,{})},{id:`cameras`,label:`Cameras`,icon:u,content:s(qe,{})},{id:`exports`,label:`Export`,icon:F,content:s(vt,{})},{id:`activity`,label:`Activity`,icon:A,content:s(Ke,{})},{id:`management`,label:`Management`,icon:Le,content:s(zt,{})}]})})}export{Qt as RecordingsPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,U as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as d,_t as f,at as p,ft as m,st as h,vt as g}from"./player-overlays-D9aoM64J.js";import{$d as _,$t as v,At as y,Au as b,Cn as x,Cs as S,Ds as C,En as w,Fn as T,Fs as E,Gt as D,Gu as O,Is as k,It as A,Jt as j,Kt as M,Ms as N,Mu as P,N as F,Ns as I,Os as L,Pn as R,Rs as z,Sn as ee,Ss as B,Tn as V,Ts as te,Ud as H,Ut as U,Wf as W,Xd as G,Xs as ne,Yd as K,Yt as re,af as ie,bn as ae,bs as oe,ca as se,dd as ce,ds as le,du as ue,er as q,fc as de,ff as fe,fs as pe,fu as me,hs as he,is as J,jd as Y,js as ge,kf as _e,ks as ve,ku as ye,ls as be,ms as xe,mu as X,nd as Se,ns as Ce,os as we,pu as Te,qt as Ee,rs as De,sn as Oe,ss as ke,tc as Ae,tf as je,ts as Me,wf as Ne,wn as Pe,ws as Fe,xs as Ie,yn as Le,ys as Re,zs as ze}from"./src-B-IRCQFw.js";import{t as Be}from"./layers-BiHKkPFk.js";import"./mount-BTxjd_Y8.js";import{$ as Ve,ot as He}from"./index-D7yeH_53.js";import{t as Ue}from"./AdminPage-BSFohA3i.js";import{t as We}from"./authed-media-Bi2u1rSm.js";import{t as Ge}from"./format-size-DIxKXxtj.js";var Ke=g(`circle-dashed`,[[`path`,{d:`M10.1 2.182a10 10 0 0 1 3.8 0`,key:`5ilxe3`}],[`path`,{d:`M13.9 21.818a10 10 0 0 1-3.8 0`,key:`11zvb9`}],[`path`,{d:`M17.609 3.721a10 10 0 0 1 2.69 2.7`,key:`1iw5b2`}],[`path`,{d:`M2.182 13.9a10 10 0 0 1 0-3.8`,key:`c0bmvh`}],[`path`,{d:`M20.279 17.609a10 10 0 0 1-2.7 2.69`,key:`1ruxm7`}],[`path`,{d:`M21.818 10.1a10 10 0 0 1 0 3.8`,key:`qkgqxc`}],[`path`,{d:`M3.721 6.391a10 10 0 0 1 2.7-2.69`,key:`1mcia2`}],[`path`,{d:`M6.391 20.279a10 10 0 0 1-2.69-2.7`,key:`1fvljs`}]]),qe=g(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),Je=g(`copy-plus`,[[`line`,{x1:`15`,x2:`15`,y1:`12`,y2:`18`,key:`1p7wdc`}],[`line`,{x1:`12`,x2:`18`,y1:`15`,y2:`15`,key:`1nscbv`}],[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),Ye=g(`folder-plus`,[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),Xe=g(`keyboard`,[[`path`,{d:`M10 8h.01`,key:`1r9ogq`}],[`path`,{d:`M12 12h.01`,key:`1mp3jc`}],[`path`,{d:`M14 8h.01`,key:`1primd`}],[`path`,{d:`M16 12h.01`,key:`1l6xoz`}],[`path`,{d:`M18 8h.01`,key:`emo2bl`}],[`path`,{d:`M6 8h.01`,key:`x9i8wu`}],[`path`,{d:`M7 16h10`,key:`wp8him`}],[`path`,{d:`M8 12h.01`,key:`czm47f`}],[`rect`,{width:`20`,height:`16`,x:`2`,y:`4`,rx:`2`,key:`18n3k1`}]]),Ze=g(`list-video`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M10 12H3`,key:`1ulcyk`}],[`path`,{d:`M10 19H3`,key:`108z41`}],[`path`,{d:`M15 12.003a1 1 0 0 1 1.517-.859l4.997 2.997a1 1 0 0 1 0 1.718l-4.997 2.997a1 1 0 0 1-1.517-.86z`,key:`ms4nik`}]]),Qe=g(`maximize`,[[`path`,{d:`M8 3H5a2 2 0 0 0-2 2v3`,key:`1dcmit`}],[`path`,{d:`M21 8V5a2 2 0 0 0-2-2h-3`,key:`1e4gt3`}],[`path`,{d:`M3 16v3a2 2 0 0 0 2 2h3`,key:`wsl5sc`}],[`path`,{d:`M16 21h3a2 2 0 0 0 2-2v-3`,key:`18trek`}]]),$e=g(`package-plus`,[[`path`,{d:`M12 22V12`,key:`d0xqtd`}],[`path`,{d:`M16 17h6`,key:`1ook5g`}],[`path`,{d:`M19 14v6`,key:`1ckrd5`}],[`path`,{d:`M21 10.535V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.729l7 4a2 2 0 0 0 2 .001l1.675-.955`,key:`28k6lz`}],[`path`,{d:`M3.29 7 12 12l8.71-5`,key:`19ckod`}],[`path`,{d:`m7.5 4.27 8.997 5.148`,key:`9yrvtv`}]]),et=g(`redo-2`,[[`path`,{d:`m15 14 5-5-5-5`,key:`12vg1m`}],[`path`,{d:`M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13`,key:`6uklza`}]]),tt=g(`wand-sparkles`,[[`path`,{d:`m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72`,key:`ul74o6`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`M5 6v4`,key:`ilb8ba`}],[`path`,{d:`M19 14v4`,key:`blhpug`}],[`path`,{d:`M10 2v2`,key:`7u0qdc`}],[`path`,{d:`M7 8H3`,key:`zfb6yr`}],[`path`,{d:`M21 16h-4`,key:`1cnmox`}],[`path`,{d:`M11 3H9`,key:`1obp7u`}]]);n();function nt({frameId:e,onAdded:t}){let n=Me(),[i,a]=c(null),[o,s]=c(null),u=async()=>{if(i===null)return;let r=await n.mutateAsync({collectionId:i,frameIds:[e]});s(r.added>0?`Added.`:r.alreadyMember>0?`Already in that collection.`:`That frame or collection no longer exists.`),await t()};return r(Ee,{children:[r(re,{className:`mt-1 flex items-center gap-1 text-foreground-muted hover:text-foreground`,"aria-label":`Add this frame to a collection`,children:[l(Ye,{className:`h-3 w-3`}),`collection`]}),r(j,{className:`w-72 space-y-2 p-3`,children:[l(Le,{value:i,onChange:a}),r(`div`,{className:`flex items-center justify-between gap-2`,children:[l(`span`,{className:`text-[11px] text-foreground-subtle`,children:o}),l(T,{size:`sm`,disabled:i===null||n.isPending,onClick:()=>void u(),children:`Add`})]})]})]})}function rt(e){let t=e.capturedAt??e.copiedAt;return new Date(t).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function it({frames:e,isLoading:t,activeFrameId:n,deviceNames:i,onOpen:a,onRemove:o}){return e.length===0?l(`p`,{className:`text-[11px] text-foreground-subtle`,children:t?`Reading the collection…`:`This collection is empty. Add frames with "Send frame to training" on a camera’s recording timeline, or "Add to collection" on a track’s copied frame.`}):l(`ul`,{className:`flex flex-wrap gap-2`,children:e.map(e=>l(`li`,{children:r(`div`,{className:`rounded-md border px-2 py-1.5 text-[11px] flex items-start gap-1.5 ${e.frameId===n?`border-primary bg-surface-hover`:`border-border`}`,children:[r(`button`,{type:`button`,className:`flex items-center gap-1.5 text-left`,onClick:()=>{a(e.frameId)},children:[e.origin===`recording`?l(ie,{className:`h-3 w-3 text-info`,"aria-label":`From the recording`}):l(Ze,{className:`h-3 w-3 text-success`,"aria-label":`From a track`}),l(`span`,{className:`font-medium text-foreground`,children:i.get(e.deviceId)??`Camera ${String(e.deviceId)}`}),l(`span`,{className:`text-foreground-subtle`,children:rt(e)}),e.complete&&l(q,{variant:`success`,children:`complete`})]}),l(`button`,{type:`button`,"aria-label":`Remove from this collection`,title:e.origin===`recording`?`Remove from this collection. If no other collection holds it, the frame and its boxes leave the dataset.`:`Remove from this collection. The frame stays in the dataset with its track.`,className:`text-foreground-muted hover:text-danger`,onClick:()=>{o(e)},children:l(P,{className:`h-3 w-3`})})]})},e.frameId))})}n();function at({collections:e,isLoading:t,selectedId:n,onSelect:i,onCreate:a,onRename:s,onDelete:u}){let[d,f]=c(``),[p,m]=c(null),[g,_]=c(null),v=async()=>{let e=await a(d);m(e),e===null&&f(``)},b=async()=>{if(g===null)return;let e=await s(g.id,g.name);m(e),e===null&&_(null)};return r(`div`,{className:`divide-y divide-border`,children:[r(`div`,{className:`p-2 space-y-1.5`,children:[r(`div`,{className:`flex items-center gap-1.5`,children:[l(X,{className:`flex-1`,"aria-label":`New collection name`,placeholder:`New collection`,value:d,onChange:e=>{f(e.target.value)}}),l(T,{size:`sm`,disabled:d.trim()===``,onClick:()=>void v(),children:`Create`})]}),p!==null&&l(`p`,{className:`text-[11px] text-danger`,children:p})]}),e.length===0?l(`p`,{className:`p-3 text-[11px] text-foreground-subtle`,children:t?`Reading the collections…`:`No collection yet. Create one here, or use "Send frame to training" on a camera’s recording timeline.`}):l(`ul`,{className:`divide-y divide-border`,children:e.map(e=>l(`li`,{className:`px-3 py-2 flex items-center gap-2 text-xs ${e.id===n?`bg-surface-hover`:``}`,children:g?.id===e.id?r(o,{children:[l(X,{className:`flex-1`,"aria-label":`Collection name`,value:g.name,onChange:t=>{_({id:e.id,name:t.target.value})}}),l(T,{variant:`ghost`,size:`sm`,"aria-label":`Save the name`,onClick:()=>void b(),children:l(_e,{className:`h-3 w-3`})}),l(T,{variant:`ghost`,size:`sm`,"aria-label":`Cancel renaming`,onClick:()=>{_(null)},children:l(P,{className:`h-3 w-3`})})]}):r(o,{children:[l(`button`,{type:`button`,className:`flex-1 min-w-0 text-left truncate text-foreground`,onClick:()=>{i(e)},children:e.name}),l(q,{children:e.frameCount}),l(T,{variant:`ghost`,size:`sm`,"aria-label":`Rename ${e.name}`,onClick:()=>{_({id:e.id,name:e.name})},children:l(Y,{className:`h-3 w-3`})}),l(y,{label:`Delete`,icon:h,triggerVariant:`ghost`,size:`sm`,title:`Delete "${e.name}"?`,description:`Frames taken from the recording that are in no other collection are deleted with their boxes. Frames copied from tracks stay in the dataset.`,confirmLabel:`Delete`,confirmVariant:`danger`,action:()=>u(e.id)})]})},e.id))})]})}function ot(e,t){let n=0,r=0,i=0;for(let t of e)n+=t.frameCount,r+=t.annotationCount,t.frameCount>0&&t.annotationCount>0&&(i+=1);let a=0;for(let e of t)a+=e.frameCount;return{tracks:e.length,frames:n,annotations:r,ready:i,collectionFrames:a}}function st(e,t){return t===null?e:e.filter(e=>e.deviceId===t)}function ct(e,t){let n=new Map;for(let t of e)n.set(t.deviceId,(n.get(t.deviceId)??0)+1);return[...n.entries()].map(([e,n])=>({deviceId:e,name:t.get(e)??`Camera ${String(e)}`,trackCount:n})).sort((e,t)=>e.name.localeCompare(t.name))}function lt({counts:e,cameras:t,selectedDeviceId:n,onSelectDevice:i}){return r(`div`,{className:`space-y-3`,"data-testid":`retrain-corpus-bar`,children:[e!==null&&r(`div`,{className:`grid grid-cols-2 sm:grid-cols-2 lg:grid-cols-4`,children:[l(F,{icon:Be,label:`Staging tracks`,value:e.tracks,subtext:`${String(e.ready)} ready to complete`}),l(F,{icon:G,label:`Copied frames`,value:e.frames,subtext:`in the dataset from tracks`}),l(F,{icon:Ne,label:`Subjects annotated`,value:e.annotations,subtext:`across staging copies`}),l(F,{icon:f,label:`Collection frames`,value:e.collectionFrames,subtext:`recording stills + track copies`})]}),t.length>1&&r(`div`,{className:`flex flex-wrap items-center gap-1.5`,role:`group`,"aria-label":`Filter by camera`,children:[l(ut,{on:n===null,label:`All cameras`,onClick:()=>{i(null)}}),t.map(e=>l(ut,{on:n===e.deviceId,label:`${e.name} (${String(e.trackCount)})`,onClick:()=>{i(e.deviceId)}},e.deviceId))]})]})}function ut({on:e,label:t,onClick:n}){return l(T,{type:`button`,size:`sm`,variant:e?`secondary`:`ghost`,"aria-pressed":e,className:`h-auto rounded-full px-2 py-0.5 text-[11px] ${e?`border border-primary text-primary`:`border border-border text-foreground-muted`}`,onClick:n,children:t})}n();var dt={"empty-name":`Give the version a name.`,"duplicate-name":`A version with that name already exists.`,"no-frames":`This selection holds no annotated or complete frame — nothing to freeze.`},ft=e=>`${String(Math.round(e*100))}%`;function pt(e,t){return e.includes(t)?e.filter(e=>e!==t):[...e,t]}function mt({on:e,label:t,onClick:n}){return l(`button`,{type:`button`,"aria-pressed":e,className:`rounded-full border px-2 py-0.5 text-[11px] ${e?`border-primary text-primary`:`border-border text-foreground-muted hover:text-foreground`}`,onClick:n,children:t})}function ht({stats:e,deviceNames:t}){let n=e=>t.get(e)??`Camera ${String(e)}`;return r(`div`,{className:`space-y-2`,"data-testid":`retrain-dataset-stats`,children:[r(`div`,{className:`flex flex-wrap gap-1.5 text-[11px]`,children:[r(q,{children:[e.frames,` frames`]}),r(q,{variant:e.completeness>=.9?`success`:`warning`,children:[ft(e.completeness),` complete (`,e.completeFrames,`)`]}),r(q,{children:[e.subjects,` boxes`]}),r(q,{variant:`danger`,children:[e.modelErrors,` model errors`]}),r(q,{variant:`info`,children:[e.hardNegatives,` hard negatives`]}),e.cameras.map(e=>r(q,{children:[n(e.deviceId),`: `,e.frames,` ·`,` `,ft(e.frames>0?e.completeFrames/e.frames:0),` complete`]},e.deviceId))]}),l(A,{columns:[{key:`class`,header:`Class`,render:e=>e.macroClass,sortValue:e=>e.macroClass},{key:`camera`,header:`Camera`,render:e=>n(e.deviceId),sortValue:e=>n(e.deviceId)},{key:`light`,header:`Light`,render:e=>e.lighting,sortValue:e=>e.lighting},{key:`subjects`,header:`Boxes`,align:`right`,render:e=>e.subjects,sortValue:e=>e.subjects},{key:`frames`,header:`Frames`,align:`right`,render:e=>e.frames,sortValue:e=>e.frames}],rows:e.cells,rowKey:e=>`${e.macroClass}-${String(e.deviceId)}-${e.lighting}`,emptyMessage:`No box in this selection.`,minWidthPx:360})]})}function gt({id:e}){let[t,n]=c(!1),i=z({id:e},{enabled:t});return t?i.data===void 0?l(H,{className:`h-3 w-3 animate-spin`}):i.data.matches?l(q,{variant:`success`,children:`unchanged`}):r(q,{variant:`warning`,children:[`changed`,i.data.missingFrames>0?` · ${String(i.data.missingFrames)} missing`:``]}):r(T,{variant:`ghost`,size:`sm`,onClick:()=>n(!0),children:[l(ce,{className:`h-3 w-3`}),l(`span`,{className:`ml-1`,children:`Verify`})]})}function _t({deviceNames:e,collections:t,pickedFrameIds:n,onClearPicked:i}){let a=s(),o=p(),[u,f]=c([]),[m,g]=c([]),[_,b]=c(!1),[x,w]=c(!1),[E,D]=c(`frames`),[O,k]=c(``),[j,M]=c(null),[N,P]=c(null),F={...u.length>0?{deviceIds:[...u]}:{},...m.length>0?{collectionIds:[...m]}:{},..._&&n.length>0?{frameIds:[...n]}:{}},I=C({selection:F,completeOnly:x}),L=S({}),z=J(),ee=ke(),B=async()=>{M(null);let e=await z.mutateAsync({name:O,selection:F,layout:E,completeOnly:x});if(e.kind===`refused`){M(dt[e.reason]??e.reason);return}k(``),M(`Version "${e.version.name}" frozen: ${String(e.version.frameCount)} frames.`),await L.refetch()},V=async e=>{P(e.id);try{let{url:t}=await o.trpcClient.pipelineAnalytics.getRetrainExportUrl.query({datasetVersionId:e.id,layout:e.layout});await We(d(t),`camstack-dataset-${e.name.replace(/[^a-z0-9_-]+/gi,`-`)}.tar`)}catch(e){M(`Download failed: ${e instanceof Error?e.message:String(e)}`)}finally{P(null)}},te=[...e.keys()].toSorted((e,t)=>e-t);return r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`rounded-md border border-border bg-surface p-3 space-y-2`,children:[l(`h2`,{className:`text-xs font-semibold text-foreground`,children:`New dataset version`}),r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[l(`span`,{className:`text-[11px] text-foreground-subtle w-20`,children:`Cameras`}),u.length===0&&l(q,{children:`all`}),te.map(t=>l(mt,{on:u.includes(t),label:e.get(t)??String(t),onClick:()=>f(e=>pt(e,t))},t))]}),r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[l(`span`,{className:`text-[11px] text-foreground-subtle w-20`,children:`Collections`}),m.length===0&&l(q,{children:`any frame`}),t.map(e=>l(mt,{on:m.includes(e.id),label:`${e.name} · ${String(e.frameCount)}`,onClick:()=>g(t=>pt(t,e.id))},e.id))]}),r(`div`,{className:`flex flex-wrap items-center gap-3 text-[11px]`,children:[r(`label`,{className:`flex items-center gap-1.5`,children:[l(v,{"aria-label":`Only the frames picked in the workbench`,checked:_,disabled:n.length===0,onChange:e=>b(e.target.checked)}),`Only the `,n.length,` picked frame`,n.length===1?``:`s`]}),n.length>0&&l(T,{variant:`ghost`,size:`sm`,onClick:i,children:`Clear picks`}),r(`label`,{className:`flex items-center gap-1.5`,children:[l(v,{"aria-label":`Only complete frames`,checked:x,onChange:e=>w(e.target.checked)}),`Only frames marked "all subjects boxed"`]}),l(R,{className:`w-36`,"aria-label":`Layout`,value:E,options:[{value:`frames`,label:`Frames (detector)`},{value:`crops`,label:`Frames + crops (classifier)`}],onChange:e=>D(e.target.value===`crops`?`crops`:`frames`)})]}),I.data===void 0?l(`p`,{className:`text-[11px] text-foreground-subtle`,children:I.isError?`The selection could not be counted.`:`Counting the selection…`}):l(ht,{stats:I.data,deviceNames:e}),r(`div`,{className:`flex items-center gap-2`,children:[l(X,{className:`flex-1`,"aria-label":`Version name`,placeholder:`Version name (e.g. night person v1)`,value:O,onChange:e=>k(e.target.value)}),l(T,{size:`sm`,disabled:O.trim()===``||z.isPending||(I.data?.frames??0)===0,onClick:()=>void B(),children:`Freeze version`})]}),j!==null&&l(`p`,{className:`text-[11px] text-foreground`,children:j})]}),r(`div`,{className:`rounded-md border border-border bg-surface p-3 space-y-2`,children:[l(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Versions`}),l(A,{columns:[{key:`name`,header:`Version`,render:e=>e.name,sortValue:e=>e.name},{key:`created`,header:`Frozen`,render:e=>new Date(e.createdAt).toLocaleString(),sortValue:e=>e.createdAt},{key:`frames`,header:`Frames`,align:`right`,render:e=>e.frameCount,sortValue:e=>e.frameCount},{key:`boxes`,header:`Boxes`,align:`right`,render:e=>e.stats.subjects,sortValue:e=>e.stats.subjects},{key:`complete`,header:`Complete`,align:`right`,render:e=>ft(e.stats.completeness),sortValue:e=>e.stats.completeness},{key:`layout`,header:`Layout`,render:e=>e.layout},{key:`hash`,header:`Hash`,render:e=>l(`code`,{title:e.annotationHash,children:e.annotationHash.slice(0,10)})},{key:`actions`,header:``,render:e=>r(`div`,{className:`flex items-center gap-1 justify-end`,children:[l(gt,{id:e.id}),l(T,{variant:`ghost`,size:`sm`,"aria-label":`Download ${e.name}`,disabled:N!==null,onClick:()=>void V(e),children:N===e.id?l(H,{className:`h-3 w-3 animate-spin`}):l(fe,{className:`h-3 w-3`})}),l(y,{label:`Delete`,icon:h,triggerVariant:`ghost`,size:`sm`,title:`Delete version "${e.name}"?`,description:`The version's record goes. Its frames stay in the dataset.`,confirmLabel:`Delete`,action:async()=>{await ee.mutateAsync({id:e.id}),await a.invalidateQueries()}})]})}],rows:L.data??[],rowKey:e=>e.id,emptyMessage:L.isLoading?`Reading the versions…`:`No version frozen yet.`,minWidthPx:640})]})]})}n();function vt(){let e=xe({}),t=B({}),[n,i]=c([]),a=le(n.length>0?{collectionIds:[...n]}:{}),o=he({}),[s,u]=c(null),[f,p]=c(null),m=async(e,t,n)=>{u(e),p(null);try{await We(d(t),n)}catch(e){p(e instanceof Error?e.message:String(e))}finally{u(null)}},h=e.data,g=h!==void 0&&h.trackCount===0;return r(`div`,{className:`rounded-md border border-border bg-surface p-3 space-y-2`,children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[l(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Export dataset`}),r(T,{variant:`secondary`,size:`sm`,disabled:a.data===void 0||s!==null,onClick:()=>{a.data!==void 0&&m(`annotated`,a.data.url,`camstack-retrain-export.tar`)},children:[s===`annotated`?l(H,{className:`h-3 w-3 animate-spin`}):l(fe,{className:`h-3 w-3`}),l(`span`,{className:`ml-1`,children:`Annotated dataset`})]}),r(T,{variant:`secondary`,size:`sm`,disabled:o.data===void 0||g||s!==null,onClick:()=>{o.data!==void 0&&m(`marked`,o.data.url,`camstack-training-export.tar`)},children:[s===`marked`?l(H,{className:`h-3 w-3 animate-spin`}):l(fe,{className:`h-3 w-3`}),l(`span`,{className:`ml-1`,children:`Marked media`})]})]}),(t.data??[]).length>0&&r(`div`,{className:`flex items-center gap-1.5 flex-wrap text-[11px]`,children:[l(`span`,{className:`text-foreground-subtle`,children:`Annotated dataset from:`}),n.length===0&&l(q,{children:`every collection and track`}),(t.data??[]).map(e=>{let t=n.includes(e.id);return r(`button`,{type:`button`,"aria-pressed":t,className:`rounded-full border px-2 py-0.5 ${t?`border-primary text-primary`:`border-border text-foreground-muted hover:text-foreground`}`,onClick:()=>{i(n=>t?n.filter(t=>t!==e.id):[...n,e.id])},children:[e.name,` · `,e.frameCount]},e.id)})]}),l(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.isError?`The export summary could not be read, so the size of the marked set is unknown — not zero.`:h===void 0?`Measuring the marked set…`:g?`No track is marked for training: the marked-media archive would be empty. The annotated dataset can still hold frames from tracks already completed — this count does not measure those.`:`${String(h.trackCount)} marked track${h.trackCount===1?``:`s`} · ${String(h.fileCount)} file${h.fileCount===1?``:`s`} · ${Ge(h.byteCount)}${h.truncated?` · more marked tracks exist than one pass carries`:``}`}),(a.isError||o.isError)&&l(`p`,{className:`text-[11px] text-danger`,children:`An export data plane is not available on the node that answered — no archive can be streamed from here.`}),f!==null&&r(`p`,{className:`text-[11px] text-danger`,children:[`Download failed: `,f]})]})}function yt(e){return e>=1e6?`${(e/1e6).toFixed(1)} MB`:`${Math.round(e/1e3)} KB`}function bt({candidates:e,copies:t,activeFrameId:n,refusals:i,isSelecting:a,onSelectCandidate:o,onOpenCopy:s,onRemoveCopy:c,renderCopyActions:u}){let d=new Set(t.map(e=>e.sourceMediaId)),f=e.filter(e=>!d.has(e.mediaId));return r(`div`,{className:`space-y-3`,children:[r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`In the dataset (`,t.length,`)`]}),t.length===0?l(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No frame copied yet. Selecting a frame copies it into retrain storage immediately — the dataset stops depending on the track's own media from that moment.`}):l(`ul`,{className:`flex flex-wrap gap-2`,children:t.map(e=>l(`li`,{children:r(`div`,{className:`rounded-md border px-2 py-1.5 text-[11px] ${e.frameId===n?`border-primary bg-surface-hover`:`border-border`}`,children:[r(`button`,{type:`button`,className:`flex items-center gap-1.5 text-left`,onClick:()=>{s(e.frameId)},children:[l(_e,{className:`h-3 w-3 text-success`}),l(`span`,{className:`font-medium text-foreground`,children:e.sourceKind}),r(`span`,{className:`text-foreground-subtle`,children:[e.width,`×`,e.height,` · `,yt(e.sizeBytes)]}),e.complete&&l(q,{variant:`success`,children:`complete`})]}),r(`button`,{type:`button`,"aria-label":`Remove this frame from the dataset`,className:`mt-1 flex items-center gap-1 text-foreground-muted hover:text-danger`,onClick:()=>{c(e.frameId)},children:[l(h,{className:`h-3 w-3`}),`remove`]}),u?.(e)]})},e.frameId))})]}),r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`Available frames (`,f.length,`)`]}),f.length===0?l(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.length===0?`This track has no whole, unannotated frame left — its media aged out before it was marked. Anything already copied above is still usable.`:`Every available frame is already in the dataset.`}):l(`ul`,{className:`flex flex-wrap gap-2`,children:f.map(e=>{let t=i.get(e.mediaId);return r(`li`,{children:[r(T,{variant:`secondary`,size:`sm`,disabled:a||t!==void 0,onClick:()=>{o(e.mediaId)},children:[a?l(H,{className:`h-3 w-3 animate-spin`}):l(t===void 0?Je:m,{className:`h-3 w-3`}),l(`span`,{className:`ml-1`,children:e.kind}),l(`span`,{className:`ml-1 text-foreground-subtle`,children:yt(e.sizeBytes)})]}),t!==void 0&&l(q,{variant:`danger`,className:`ml-1`,children:t})]},e.mediaId)})})]})]})}function xt(e){return e.frameCount===0?`untouched`:e.annotationCount===0?`started`:`ready`}var St={untouched:{icon:qe,label:`to do`,variant:`default`},started:{icon:Ke,label:`frames only`,variant:`info`},ready:{icon:Ne,label:`annotated`,variant:`success`}};function Ct(e){return new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function wt({tracks:e,isLoading:t,selectedTrackId:n,deviceNames:i,onSelect:a}){return t?r(`div`,{className:`flex items-center gap-2 p-4 text-xs text-foreground-subtle`,children:[l(H,{className:`h-3.5 w-3.5 animate-spin`}),`Loading staging tracks…`]}):e.length===0?l(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`Nothing in staging. Mark a track for training from the viewer or the Library feed and it appears here.`}):l(`ul`,{className:`divide-y divide-border`,children:e.map(e=>{let t=St[xt(e)],o=t.icon;return l(`li`,{children:r(`button`,{type:`button`,onClick:()=>{a(e)},className:`w-full text-left px-3 py-2 flex items-start gap-2 hover:bg-surface-hover ${e.trackId===n?`bg-surface-hover`:``}`,children:[l(o,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 text-foreground-subtle`}),r(`span`,{className:`min-w-0 flex-1`,children:[r(`span`,{className:`flex items-center gap-2`,children:[l(`span`,{className:`text-xs font-medium text-foreground truncate`,children:e.label??e.className}),l(q,{variant:t.variant,children:t.label})]}),r(`span`,{className:`block text-[11px] text-foreground-subtle truncate`,children:[i.get(e.deviceId)??`Camera ${String(e.deviceId)}`,` ·`,` `,Ct(e.lastSeen)]}),r(`span`,{className:`block text-[11px] text-foreground-muted`,children:[e.frameCount,` frame`,e.frameCount===1?``:`s`,` ·`,` `,e.annotationCount,` subject`,e.annotationCount===1?``:`s`]})]})]})},e.trackId)})})}function Z(e){return{deviceId:e.deviceId,...e.trackId===void 0?{}:{trackId:e.trackId},frameId:e.frameId}}var Tt=`object-detection`;function Et(e,t){for(let n of e){if(n.addonId===t)return n;let e=n.children===void 0?void 0:Et(n.children,t);if(e!==void 0)return e}}function Dt(e,t){for(let n of e.slots){let e=n.addons.find(e=>e.id===t);if(e!==void 0)return e}}function Ot(e){let{status:t,nodeDevices:n,schema:r,resolvedSteps:i}=e;if(t===void 0)return{kind:`unknown`,gap:`pending`};if(t.detection===null)return{kind:`unknown`,gap:t.degraded.some(e=>e.stage===`detection`)?`placement-unreadable`:`detection-off`};let a=t.detection;if(n===void 0||r===void 0||i===void 0)return{kind:`unknown`,gap:`pending`};if(!n.reachable)return{kind:`unknown`,gap:`node-unreachable`};let o=n.devices.find(e=>e.backend===a.engine.backend&&e.device===a.engine.device);if(o===void 0)return{kind:`unknown`,gap:`device-unknown`};let s=Dt(r,Tt);if(s===void 0)return{kind:`unknown`,gap:`step-unknown`};let c=Oe({catalog:s,device:o,override:Et(i,Tt)?.modelId,base:o.steps?.[Tt]?.modelId});return c===void 0?{kind:`unknown`,gap:`no-model`}:{kind:`resolved`,nodeId:a.nodeId,modelId:c,minScore:s.models.find(e=>e.id===c)?.defaultConfidence??s.defaultConfidence}}function kt(e,t){let n=Math.max(0,Math.min(e.x+e.w,t.x+t.w)-Math.max(e.x,t.x))*Math.max(0,Math.min(e.y+e.h,t.y+t.h)-Math.max(e.y,t.y)),r=e.w*e.h+t.w*t.h-n;return r>0?n/r:0}function At(e,t){let n=e.nextKey;return{boxes:t.map(e=>{let t=`b${String(n)}`;return n+=1,{...e,key:t}}),nextKey:n}}function jt(e){return{bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},...e.subLabel===void 0?{}:{subLabel:e.subLabel},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore},draft:!1}}function Mt(e){return e.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},...e.subLabel===void 0?{}:{subLabel:e.subLabel},kind:`subject`,source:`pipeline`,...e.modelId===void 0?{}:{assistModelId:e.modelId},...e.score===void 0?{}:{assistScore:e.score},draft:!0,note:e.basis===`subject-box`?`The box the pipeline recorded on this very frame.`:`The pipeline's track position ${String(Math.round(e.deltaMs))} ms from this frame.`}))}var Nt={boxes:[],selectedKey:null,nextKey:0};function Pt(e,t){let n=At(Nt,e.map(jt));return Ft({boxes:n.boxes,selectedKey:null,nextKey:n.nextKey},Mt(t)).state}function Ft(e,t){let n=[],r=0;for(let i of t){if([...e.boxes,...n].some(e=>kt(e.bbox,i.bbox)>=.8)){r+=1;continue}n.push({...i,draft:!0})}let i=At(e,n);return{state:{...e,boxes:[...e.boxes,...i.boxes],nextKey:i.nextKey},skipped:r}}function It(e,t,n){let r=At(e,[{bbox:t,macroClass:n,kind:`subject`,source:`operator`,draft:!1}]),i=r.boxes[0];return i===void 0?e:{boxes:[...e.boxes,i],selectedKey:i.key,nextKey:r.nextKey}}function Lt(e,t,n){return{...e,boxes:e.boxes.map(e=>e.key===t?n(e):e)}}function Rt(e,t,n){return Lt(e,t,e=>({...e,...n,draft:!1}))}function zt(e,t){return Lt(e,t,e=>({...e,draft:!1}))}function Bt(e){return{...e,boxes:e.boxes.map(e=>e.draft?{...e,draft:!1}:e)}}function Vt(e,t){return Lt(e,t,e=>({...e,kind:e.kind===`model_error`?`subject`:`model_error`,draft:!1}))}function Ht(e,t){return{...e,boxes:e.boxes.filter(e=>e.key!==t),selectedKey:e.selectedKey===t?null:e.selectedKey}}function Ut(e,t){return{...e,selectedKey:t}}function Wt(e,t){return{...e,boxes:e.boxes.map(e=>{let n=t.get(e.key);return n===void 0?e:{...e,flag:n}})}}function Gt(e,t){return new Map(e.map(e=>[e.ref,{verdict:e.verdict,reason:e.reason,by:t,...e.suggestedClass===void 0?{}:{suggestedClass:e.suggestedClass}}]))}function Kt(e){return e.boxes.filter(e=>e.draft).length}function qt(e){let t=e?.trim();return t===void 0||t===``?void 0:t}function Jt(e){return e.boxes.filter(e=>!e.draft).map(e=>{let t=qt(e.label),n=qt(e.subLabel);return{bbox:e.bbox,macroClass:e.macroClass,...t===void 0?{}:{label:t},...n===void 0?{}:{subLabel:n},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}})}var Yt=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],Xt=new Set(Yt),Zt={operator:`drawn`,pipeline:`pipeline`,assist:`detector`,llm:`AI vision`};function Qt(e){let t=e?.trim().toLowerCase();return t===void 0||t===``?null:Xt.has(t)?`"${t}" is a macro class, not a label — person / postman / Marco are three different tiers`:null}function $t(e){if(e.source===`operator`)return null;let t=[Zt[e.source]];return e.assistModelId!==void 0&&t.push(e.assistModelId),e.assistScore!==void 0&&t.push(e.assistScore.toFixed(2)),t.join(` · `)}function en({boxes:e,selectedKey:t,onSelect:n,onChange:i,onAccept:a,onToggleModelError:o,onDelete:s}){return e.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle p-3`,children:[`No subject on this frame yet. Drag on the image to draw one, or ask for a proposal. Annotate`,` `,l(`strong`,{children:`every`}),` subject — a frame with one box and three unlabelled people teaches the model that two thirds of the people in it are background.`]}):l(`ul`,{className:`divide-y divide-border`,children:e.map(e=>{let c=e.key===t,u=Qt(e.label),d=Qt(e.subLabel),f=$t(e);return r(`li`,{"data-testid":`retrain-row-${e.key}`,className:`p-2.5 space-y-1.5 ${c?`bg-surface-hover`:``}`,onFocus:()=>{n(e.key)},onClick:()=>{n(e.key)},children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[l(R,{className:`w-28`,"aria-label":`Class`,value:e.macroClass,options:Yt.map(e=>({value:e,label:e})),onChange:t=>{let n=Yt.find(e=>e===t.target.value);n!==void 0&&i(e.key,{macroClass:n})}}),e.draft&&l(q,{variant:`warning`,children:`draft`}),e.kind===`model_error`&&l(q,{variant:`danger`,children:`model error`}),f!==null&&l(q,{variant:`info`,children:f}),(e.note!==void 0||e.flag!==void 0)&&r(ue,{children:[l(Te,{children:l(K,{className:`h-3.5 w-3.5 ${e.flag!==void 0&&e.flag.verdict!==`confirmed`?`text-warning`:`text-foreground-subtle`}`,"aria-label":`Why this box is here`})}),r(me,{className:`whitespace-normal w-64 text-left`,children:[e.note!==void 0&&l(`p`,{children:e.note}),e.flag!==void 0&&r(`p`,{children:[e.flag.by,`: `,e.flag.verdict,e.flag.suggestedClass===void 0?``:` (suggests ${e.flag.suggestedClass})`,` `,`— `,e.flag.reason]})]})]}),l(`span`,{className:`flex-1`}),e.draft&&l(T,{variant:`secondary`,size:`sm`,"aria-label":`Accept this proposal`,onClick:()=>{a(e.key)},children:l(_e,{className:`h-3 w-3`})}),l(T,{variant:`ghost`,size:`sm`,"aria-label":e.kind===`model_error`?`This is a real subject`:`Mark as model error`,onClick:()=>{o(e.key)},children:l(W,{className:`h-3 w-3`})}),l(T,{variant:`ghost`,size:`sm`,"aria-label":`Delete this subject`,onClick:()=>{s(e.key)},children:l(h,{className:`h-3 w-3`})})]}),r(`div`,{className:`flex items-center gap-2`,children:[l(X,{className:`flex-1`,placeholder:`label (postman, van, cat…)`,value:e.label??``,onChange:t=>{i(e.key,{label:t.target.value})}}),l(X,{className:`flex-1`,placeholder:`sub-label (a name, a plate…)`,value:e.subLabel??``,onChange:t=>{i(e.key,{subLabel:t.target.value})}})]}),u!==null&&l(`p`,{className:`text-[11px] text-danger`,children:u}),d!==null&&l(`p`,{className:`text-[11px] text-danger`,children:d})]},e.key)})})}function tn(e){return e.filter(e=>!e.draft).every(e=>Qt(e.label)===null&&Qt(e.subLabel)===null&&Xt.has(e.macroClass))}var nn=.25;function rn(e,t){if(e===void 0)return[];let n=e.selectedEngine.format,r=e.slots.flatMap(e=>e.addons).find(e=>e.id===Tt);if(r===void 0)return[];let i=r.models.filter(e=>e.legacy!==!0&&e.provider===void 0).flatMap(e=>{let t=e.formats[n];return t===void 0?[]:[{modelId:e.id,name:e.name,sizeMB:t.sizeMB??0}]}),a=i.find(e=>e.modelId===t);return i.filter(e=>e.modelId!==t&&(a===void 0||e.sizeMB>a.sizeMB)).toSorted((e,t)=>t.sizeMB-e.sizeMB)}n();var an=[{value:`teacher`,label:`Bigger detector`},{value:`llm`,label:`AI vision`},{value:`both`,label:`Both`}],on=[`person`,`vehicle`,`animal`,`package`],sn=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],cn={"unknown-frame":`The frame is no longer in the dataset.`,"unreadable-frame":`The frame copy could not be read.`,"unknown-profile":`That AI profile no longer exists.`,"profile-disabled":`That AI profile is disabled.`,"no-vision":`That AI profile cannot read images.`,"cloud-not-confirmed":`The frame was not sent: sending it outside the house needs your confirmation.`,"llm-error":`The AI model call failed.`,"malformed-answer":`The AI answered in a shape that cannot be trusted, so nothing was drawn.`};function ln({frame:e,history:n,detector:i,schema:o,setNotice:s}){let u=oe({},{retry:!1}),d=L(),f=ve(),[p,m]=c(`teacher`),h=a(()=>rn(o,i.kind===`resolved`?i.modelId:void 0),[o,i]),[g,_]=c(null),v=h.find(e=>e.modelId===g)??h[0],[y,b]=c(nn),[S,C]=c(null),E=(u.data??[]).find(e=>e.id===S)??u.data?.[0],[D,O]=c(on),[k,A]=c(!1),[j,M]=c(!1),N=t(n.editor);N.current=n.editor;let P=p!==`llm`,F=p!==`teacher`,I=i.kind===`resolved`&&v!==void 0,z=E!==void 0&&D.length>0,B=(!P||I)&&(!F||z),te=async()=>{if(i.kind!==`resolved`||v===void 0)return``;let t=await d.mutateAsync({...Z(e),subject:{kind:`objects`,modelId:v.modelId,minScore:y},nodeId:i.nodeId});if(t.kind===`refused`)return`${v.name} refused: ${t.reason}${t.detail===void 0?``:` — ${t.detail}`}.`;let r=Ft(N.current,t.proposals.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},kind:e.kind,source:`assist`,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore},draft:!0,note:`Proposed by the larger detector ${t.modelId} on ${i.nodeId}.`})));N.current=r.state,n.setEditor(r.state);let a=t.proposals.length-r.skipped;return`${v.name}: ${String(a)} new draft${a===1?``:`s`}${r.skipped>0?`, ${String(r.skipped)} already on the frame`:``}.`},U=async t=>{if(E===void 0)return``;let r=N.current,i=await f.mutateAsync({...Z(e),profileId:E.id,classes:[...D],boxes:r.boxes.slice(0,50).map(e=>({ref:e.key,bbox:e.bbox,macroClass:e.macroClass,...e.label!==void 0&&e.label!==``?{label:e.label}:{}})),allowCloud:t});if(i.kind===`refused`)return`${cn[i.reason]??i.reason}${i.detail===void 0?``:` (${i.detail})`}`;let a=i.proposals.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},kind:`subject`,source:`llm`,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore},draft:!0,note:`${i.model}: ${e.reason}`})),o=Gt(i.reviews,i.model),s=Ft(N.current,a);n.setEditor(e=>Wt(Ft(e,a).state,o));let c=i.proposals.length-s.skipped,l=i.reviews.filter(e=>e.verdict!==`confirmed`).length;return`${E.name}: ${String(c)} new draft${c===1?``:`s`}, ${String(l)} box${l===1?``:`es`} questioned${i.rejected>0?`, ${String(i.rejected)} unusable item${i.rejected===1?``:`s`} dropped`:``}.`},W=async e=>{A(!1),M(!0),s(null);try{let t=[];P&&t.push(await te()),F&&t.push(await U(e)),s(`${t.filter(e=>e!==``).join(` `)} Drafts are not saved until you accept or correct them.`)}catch(e){s(`The assist failed: ${e instanceof Error?e.message:String(e)}`)}finally{M(!1)}};return r(`div`,{className:`px-3 py-2 border-b border-border space-y-2 text-[11px]`,"data-testid":`retrain-assist`,children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[l(`span`,{className:`font-semibold text-foreground`,children:`Assist`}),l(R,{className:`w-36`,"aria-label":`Assist engine`,value:p,options:an.map(e=>({value:e.value,label:e.label})),onChange:e=>{let t=an.find(t=>t.value===e.target.value);t!==void 0&&m(t.value)}}),l(`span`,{className:`flex-1`}),r(T,{size:`sm`,variant:`secondary`,disabled:!B||j,onClick:()=>{if(F&&E?.leavesHouse===!0){A(!0);return}W(!1)},children:[j?l(H,{className:`h-3 w-3 animate-spin`}):l(tt,{className:`h-3 w-3`}),l(`span`,{className:`ml-1`,children:`Run`})]})]}),P&&(h.length===0||i.kind!==`resolved`?l(`p`,{className:`text-foreground-subtle`,children:i.kind===`resolved`?`The detection node’s catalog has no detector larger than this camera’s for its format.`:`The camera’s detection node is not known, so no larger detector can be run there.`}):r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[l(R,{className:`flex-1 min-w-40`,"aria-label":`Larger detector`,value:v?.modelId??``,options:h.map(e=>({value:e.modelId,label:`${e.name} (${String(Math.round(e.sizeMB))} MB)`})),onChange:e=>{_(e.target.value)}}),l(X,{className:`w-20`,"aria-label":`Minimum score`,type:`number`,min:.05,max:.95,step:.05,value:y,onChange:e=>{let t=Number.parseFloat(e.target.value);Number.isFinite(t)&&b(Math.min(.95,Math.max(.05,t)))}}),r(`span`,{className:`text-foreground-subtle`,children:[`on `,i.nodeId]})]})),F&&((u.data??[]).length===0?l(`p`,{className:`text-foreground-subtle`,children:u.isError?`The AI profiles could not be read.`:`No enabled AI profile can read images. Add one under AI settings.`}):r(`div`,{className:`space-y-1.5`,children:[l(R,{"aria-label":`AI profile`,value:E?.id??``,options:(u.data??[]).map(e=>({value:e.id,label:`${e.name} · ${e.model}${e.leavesHouse?` · cloud`:` · local`}`})),onChange:e=>{C(e.target.value)}}),E?.leavesHouse===!0&&l(`p`,{className:`text-warning`,children:`This profile sends the frame outside your home, to a cloud service. Each run asks first.`}),r(`div`,{className:`flex items-center gap-1 flex-wrap`,children:[l(`span`,{className:`text-foreground-subtle`,children:`Look for:`}),sn.map(e=>{let t=D.includes(e);return l(`button`,{type:`button`,"aria-pressed":t,className:`rounded-full border px-2 py-0.5 ${t?`border-primary text-primary`:`border-border text-foreground-muted`}`,onClick:()=>{O(n=>t?n.filter(t=>t!==e):[...n,e])},children:e},e)})]})]})),l(ae,{open:k,onOpenChange:A,children:r(ee,{children:[r(V,{children:[l(w,{children:`Send this frame outside your home?`}),l(x,{children:`The frame from ${e.origin===`recording`?`the recording`:`this track`} will be sent to ${E?.name??`the AI profile`} (${E?.kind??`cloud`}, model ${E?.model??``}), a service outside your network, to be analysed. Only this frame, for this run.`})]}),r(Pe,{children:[l(T,{variant:`ghost`,size:`sm`,onClick:()=>{A(!1)},children:`Cancel`}),l(T,{size:`sm`,onClick:()=>void W(!0),children:`Send this frame`})]})]})})]})}function un(e,t,n,r){if(!(e>0)||!(t>0)||!(n>0)||!(r>0))return null;let i=Math.min(e/n,t/r),a=n*i,o=r*i;return{left:(e-a)/2,top:(t-o)/2,width:a,height:o}}function dn(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),w:Math.abs(t.x-e.x),h:Math.abs(t.y-e.y)}}var fn=.01;function pn(e){return e.w>=.01&&e.h>=.01}function mn(e,t){let n=-1,r=1/0;return e.forEach((e,i)=>{if(!(t.x>=e.x&&t.x<=e.x+e.w&&t.y>=e.y&&t.y<=e.y+e.h))return;let a=e.w*e.h;a<r&&(n=i,r=a)}),n}var hn=[`nw`,`n`,`ne`,`e`,`se`,`s`,`sw`,`w`];function gn(e,t,n){return{x:Math.min(Math.max(0,e.x+t),Math.max(0,1-e.w)),y:Math.min(Math.max(0,e.y+n),Math.max(0,1-e.h)),w:e.w,h:e.h}}function _n(e,t,n,r){if(n){let e=Math.min(Math.max(0,r),t-fn);return{start:e,size:t-e}}return{start:e,size:Math.max(Math.min(1,r),e+fn)-e}}function vn(e,t,n){let r=t.includes(`w`)||t.includes(`e`)?_n(e.x,e.x+e.w,t.includes(`w`),n.x):{start:e.x,size:e.w},i=t.includes(`n`)||t.includes(`s`)?_n(e.y,e.y+e.h,t.includes(`n`),n.y):{start:e.y,size:e.h};return{x:r.start,y:i.start,w:r.size,h:i.size}}function yn(e,t){return{x:t.includes(`w`)?e.x:t.includes(`e`)?e.x+e.w:e.x+e.w/2,y:t.includes(`n`)?e.y:t.includes(`s`)?e.y+e.h:e.y+e.h/2}}function bn(e,t,n){let r=(e,t,n)=>Math.abs(e-t)<=n,i=r(t.x,e.x,n.x),a=r(t.x,e.x+e.w,n.x),o=r(t.y,e.y,n.y),s=r(t.y,e.y+e.h,n.y),c=t.x>=e.x-n.x&&t.x<=e.x+e.w+n.x,l=t.y>=e.y-n.y&&t.y<=e.y+e.h+n.y;return!c||!l?null:o&&i?`nw`:o&&a?`ne`:s&&i?`sw`:s&&a?`se`:o?`n`:s?`s`:i?`w`:a?`e`:t.x>=e.x&&t.x<=e.x+e.w&&t.y>=e.y&&t.y<=e.y+e.h?`body`:null}var xn={x:0,y:0,w:1,h:1},Sn=1.5;function Q(e,t,n){return e<t?t:e>n?n:e}function Cn(e){return 1/e.w}function $(e,t,n,r){return{x:Q(r.x+(e-n.left)/n.width*r.w,0,1),y:Q(r.y+(t-n.top)/n.height*r.h,0,1)}}function wn(e,t,n){return{x:t.left+(e.x-n.x)/n.w*t.width,y:t.top+(e.y-n.y)/n.h*t.height}}function Tn(e,t,n){let r=wn(e,t,n);return{left:r.x,top:r.y,width:e.w/n.w*t.width,height:e.h/n.h*t.height}}function En(e,t){return{left:e.left-t.x/t.w*e.width,top:e.top-t.y/t.h*e.height,width:e.width/t.w,height:e.height/t.h}}function Dn(e,t,n){let r=Q(e.w/n,1/16,1),i=r/e.w;return{x:Q(t.x-(t.x-e.x)*i,0,1-r),y:Q(t.y-(t.y-e.y)*i,0,1-r),w:r,h:r}}function On(e,t,n){return{x:Q(e.x+t,0,1-e.w),y:Q(e.y+n,0,1-e.h),w:e.w,h:e.h}}function kn(e){return{x:e.x+e.w/2,y:e.y+e.h/2}}var An=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`];function jn(e){if(typeof e!=`object`||!e||!(`tagName`in e))return!1;let t=String(e.tagName).toUpperCase();return t===`INPUT`||t===`TEXTAREA`||t===`SELECT`?!0:`isContentEditable`in e&&e.isContentEditable===!0}function Mn(e){let t=e.ctrlKey||e.metaKey,n=e.key.toLowerCase();if(t&&!e.altKey)return n===`s`&&!e.shiftKey?{kind:`save`}:e.typing?null:n===`z`?e.shiftKey?{kind:`redo`}:{kind:`undo`}:n===`y`&&!e.shiftKey?{kind:`redo`}:null;if(e.typing||t||e.altKey)return null;switch(e.key){case`ArrowRight`:return{kind:`next-frame`};case`ArrowLeft`:return{kind:`prev-frame`};case`Delete`:case`Backspace`:return{kind:`delete`};case`Escape`:return{kind:`deselect`};case`Tab`:return e.shiftKey?{kind:`select-prev`}:{kind:`select-next`};case`+`:case`=`:return{kind:`zoom-in`};case`-`:case`_`:return{kind:`zoom-out`};case`0`:return{kind:`zoom-fit`};default:break}let r=Number.parseInt(e.key,10);if(Number.isInteger(r)&&r>=1&&r<=An.length){let e=An[r-1];return e===void 0?null:{kind:`set-class`,macroClass:e}}return n===`a`?e.shiftKey?{kind:`accept-all`}:{kind:`accept`}:n===`e`&&!e.shiftKey?{kind:`toggle-model-error`}:n===`c`&&!e.shiftKey?{kind:`toggle-complete`}:null}var Nn=[{keys:`← / →`,does:`Previous / next frame`},{keys:`Drag on empty frame`,does:`Draw a box`},{keys:`Drag a box / its handles`,does:`Move / resize it`},{keys:`Delete, Backspace`,does:`Delete the selected box`},{keys:`1 – 6`,does:`Class: person, vehicle, animal, package, face, plate`},{keys:`A`,does:`Accept the selected draft`},{keys:`Shift + A`,does:`Accept every draft`},{keys:`E`,does:`Mark / unmark the selected box as a model error`},{keys:`C`,does:`Toggle "all subjects boxed"`},{keys:`Tab / Shift + Tab`,does:`Select the next / previous box`},{keys:`Esc`,does:`Deselect`},{keys:`Ctrl/⌘ + Z`,does:`Undo`},{keys:`Ctrl/⌘ + Shift + Z, Ctrl/⌘ + Y`,does:`Redo`},{keys:`Ctrl/⌘ + S`,does:`Save the frame`},{keys:`+ / − / 0, wheel, pinch`,does:`Zoom in / out / fit`},{keys:`Space + drag, middle drag, two fingers`,does:`Pan`}];n();var Pn=.0015,Fn={pipeline:`var(--color-foreground-muted)`,assist:`var(--color-info)`,llm:`var(--color-warning)`,operator:`var(--color-success)`};function In(e,t){return e.kind===`model_error`?{color:`var(--color-danger)`,dashed:!0,opacity:1}:t?{color:`var(--color-primary)`,dashed:e.draft,opacity:1}:e.draft?{color:Fn[e.source],dashed:!0,opacity:.8}:{color:`var(--color-success)`,dashed:!1,opacity:1}}function Ln(e,t){return Math.hypot(e.x-t.x,e.y-t.y)}function Rn(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}function zn({imageSrc:n,imageWidth:a,imageHeight:o,boxes:s,selectedKey:d,viewport:f,onViewportChange:p,panMode:m,onSelect:h,onDraw:g,onGestureStart:_,onGestureBox:v,onGestureEnd:y}){let b=t(null),[x,S]=c({w:0,h:0}),[C,w]=c(null),[T,E]=c(!1),D=t(new Map),O=t({mode:`none`});i(()=>{let e=b.current;if(e===null)return;let t=()=>S({w:e.clientWidth,h:e.clientHeight});if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},[]);let k=un(x.w,x.h,a,o);u(()=>{let e=e=>{e.key!==` `||jn(e.target)||(e.preventDefault(),E(!0))},t=e=>{e.key===` `&&E(!1)};return window.addEventListener(`keydown`,e),window.addEventListener(`keyup`,t),()=>{window.removeEventListener(`keydown`,e),window.removeEventListener(`keyup`,t)}},[]);let A=t({image:k,viewport:f,onViewportChange:p});A.current={image:k,viewport:f,onViewportChange:p},u(()=>{let e=b.current;if(e===null)return;let t=t=>{let{image:n,viewport:r,onViewportChange:i}=A.current;if(n===null)return;t.preventDefault();let a=e.getBoundingClientRect();i(Dn(r,$(t.clientX-a.left,t.clientY-a.top,n,r),Math.exp(-t.deltaY*Pn)))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>{e.removeEventListener(`wheel`,t)}},[]);let j=e(e=>{let t=b.current?.getBoundingClientRect();return{x:e.clientX-(t?.left??0),y:e.clientY-(t?.top??0)}},[]),M=e(e=>k===null?null:$(e.x,e.y,k,f),[k,f]),N=e(()=>{let e=O.current;(e.mode===`move`||e.mode===`resize`)&&y(),e.mode===`draw`&&w(null),O.current={mode:`none`}},[y]),P=e=>{if(k===null)return;let t=j(e);if(D.current.set(e.pointerId,t),e.currentTarget.setPointerCapture?.(e.pointerId),D.current.size===2){N();let[e,t]=[...D.current.values()];if(e===void 0||t===void 0)return;let n=Rn(e,t);O.current={mode:`pinch`,startDistance:Math.max(1,Ln(e,t)),anchor:$(n.x,n.y,k,f),from:f};return}if(D.current.size>2)return;if(e.button===1||T||m){e.preventDefault(),O.current={mode:`pan`,startPx:t,from:f};return}if(e.button!==0)return;let n=$(t.x,t.y,k,f),r={x:12/k.width*f.w,y:12/k.height*f.h},i=s.find(e=>e.key===d);if(i!==void 0){let e=bn(i.bbox,n,r);if(e!==null&&e!==`body`){_(),O.current={mode:`resize`,key:i.key,handle:e,from:i.bbox};return}}let a=s[mn(s.map(e=>e.bbox),n)];if(a!==void 0){a.key!==d&&h(a.key),_(),O.current={mode:`move`,key:a.key,start:n,from:a.bbox};return}O.current={mode:`draw`,start:n},w(dn(n,n))},F=e=>{if(!D.current.has(e.pointerId)||k===null)return;let t=j(e);D.current.set(e.pointerId,t);let n=O.current;switch(n.mode){case`pinch`:{let[e,t]=[...D.current.values()];if(e===void 0||t===void 0)return;let r=Dn(n.from,n.anchor,Ln(e,t)/n.startDistance),i=Rn(e,t),a=$(i.x,i.y,k,r);p(On(r,n.anchor.x-a.x,n.anchor.y-a.y));return}case`pan`:{let e=(t.x-n.startPx.x)/k.width*n.from.w,r=(t.y-n.startPx.y)/k.height*n.from.h;p(On(n.from,-e,-r));return}case`move`:{let e=$(t.x,t.y,k,f);v(n.key,gn(n.from,e.x-n.start.x,e.y-n.start.y));return}case`resize`:{let e=$(t.x,t.y,k,f);v(n.key,vn(n.from,n.handle,e));return}case`draw`:{let e=$(t.x,t.y,k,f);w(dn(n.start,e));return}default:return}},I=e=>{if(!D.current.has(e.pointerId))return;D.current.delete(e.pointerId);let t=O.current;if(t.mode===`pinch`){D.current.size<2&&(O.current={mode:`none`});return}if(t.mode===`draw`){let n=M(j(e)),r=n===null?null:dn(t.start,n);w(null),O.current={mode:`none`},r!==null&&pn(r)?g(r):h(null);return}N()},L=s.find(e=>e.key===d),R=T||m,z=k===null?null:En(k,f);return r(`div`,{ref:b,"data-testid":`retrain-canvas`,className:`relative w-full h-full min-h-[280px] bg-surface-sunken select-none touch-none overflow-hidden`,style:{cursor:R?`grab`:`crosshair`},onPointerDown:P,onPointerMove:F,onPointerUp:I,onPointerCancel:I,children:[z!==null&&l(`img`,{src:n,alt:`Frame being annotated`,draggable:!1,className:`absolute max-w-none pointer-events-none`,style:z}),k!==null&&s.map(e=>{let t=Tn(e.bbox,k,f),n=e.key===d,i=In(e,n);return l(`div`,{"data-testid":`retrain-box-${e.key}`,"data-draft":e.draft?`true`:`false`,"data-source":e.source,className:`absolute pointer-events-none`,style:{left:t.left,top:t.top,width:t.width,height:t.height,border:`${n?`2px`:`1px`} ${i.dashed?`dashed`:`solid`} ${i.color}`,opacity:i.opacity},children:r(`span`,{className:`absolute -top-4 left-0 text-[10px] px-1 rounded whitespace-nowrap text-background`,style:{background:i.color},children:[e.label??e.macroClass,e.kind===`model_error`?` ✕`:``,e.draft?` ?`:``,e.flag!==void 0&&e.flag.verdict!==`confirmed`?` !`:``]})},e.key)}),k!==null&&L!==void 0&&hn.map(e=>{let t=wn(yn(L.bbox,e),k,f);return l(`div`,{"data-testid":`retrain-handle-${e}`,className:`absolute h-2.5 w-2.5 -translate-x-1/2 -translate-y-1/2 rounded-sm border border-background bg-primary pointer-events-none`,style:{left:t.x,top:t.y}},e)}),C!==null&&k!==null&&l(`div`,{className:`absolute border border-dashed border-primary pointer-events-none`,style:Tn(C,k,f)})]})}n();function Bn(){let[t,n]=c(xn),[r,i]=c(!1);return{viewport:t,setViewport:n,zoomIn:e(()=>{n(e=>Dn(e,kn(e),Sn))},[]),zoomOut:e(()=>{n(e=>Dn(e,kn(e),1/Sn))},[]),fit:e(()=>{n(xn)},[]),panMode:r,togglePan:e(()=>{i(e=>!e)},[])}}function Vn({view:e,canUndo:t,canRedo:n,onUndo:i,onRedo:a}){let o=Cn(e.viewport);return r(`div`,{className:`flex items-center gap-1 px-2 py-1 border-b border-border bg-surface`,children:[l(T,{variant:`ghost`,size:`sm`,"aria-label":`Zoom out`,onClick:e.zoomOut,children:l(ye,{className:`h-3.5 w-3.5`})}),r(`span`,{className:`w-12 text-center text-[11px] tabular-nums text-foreground-subtle`,children:[Math.round(o*100),`%`]}),l(T,{variant:`ghost`,size:`sm`,"aria-label":`Zoom in`,onClick:e.zoomIn,children:l(b,{className:`h-3.5 w-3.5`})}),l(T,{variant:`ghost`,size:`sm`,"aria-label":`Fit the whole frame`,disabled:o<=1,onClick:e.fit,children:l(Qe,{className:`h-3.5 w-3.5`})}),l(T,{variant:e.panMode?`secondary`:`ghost`,size:`sm`,"aria-label":`Pan tool`,"aria-pressed":e.panMode,onClick:e.togglePan,children:l(_,{className:`h-3.5 w-3.5`})}),l(`span`,{className:`flex-1`}),l(T,{variant:`ghost`,size:`sm`,"aria-label":`Undo`,disabled:!t,onClick:i,children:l(O,{className:`h-3.5 w-3.5`})}),l(T,{variant:`ghost`,size:`sm`,"aria-label":`Redo`,disabled:!n,onClick:a,children:l(et,{className:`h-3.5 w-3.5`})}),r(Ee,{children:[l(re,{"aria-label":`Keyboard shortcuts`,className:`inline-flex h-7 items-center rounded-md px-2 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:l(Xe,{className:`h-3.5 w-3.5`})}),r(j,{className:`w-80`,children:[l(`h3`,{className:`mb-2 text-xs font-semibold text-foreground`,children:`Keyboard and gestures`}),l(`table`,{className:`w-full text-[11px]`,children:l(`tbody`,{children:Nn.map(e=>r(`tr`,{className:`align-top`,children:[l(`td`,{className:`py-0.5 pr-2 font-mono whitespace-nowrap text-foreground`,children:e.keys}),l(`td`,{className:`py-0.5 text-foreground-subtle`,children:e.does})]},e.keys))})})]})]})]})}function Hn(e){return{past:[],present:e,future:[],gestureBase:null}}function Un(e,t){let n=[...e,t];return n.length>100?n.slice(n.length-100):n}function Wn(e,t){return t===e.present?e:{past:Un(e.past,e.present),present:t,future:[],gestureBase:null}}function Gn(e,t){return{...e,present:t}}function Kn(e){let t=e.past[e.past.length-1];return t===void 0?e:{past:e.past.slice(0,-1),present:t,future:[e.present,...e.future],gestureBase:null}}function qn(e){let[t,...n]=e.future;return t===void 0?e:{past:Un(e.past,e.present),present:t,future:n,gestureBase:null}}function Jn(e){return{...e,gestureBase:e.present}}function Yn(e,t){return{...e,present:t}}function Xn(e){let t=e.gestureBase;return t===null?e:t===e.present?{...e,gestureBase:null}:{past:Un(e.past,t),present:e.present,future:[],gestureBase:null}}function Zn(e){return e.past.length>0}function Qn(e){return e.future.length>0}n();function $n(e,t){return typeof e==`function`?e(t):e}function er(t){let[n,r]=c(()=>Hn(t())),i=e(e=>{r(t=>Wn(t,$n(e,t.present)))},[]),a=e(e=>{r(Hn(e))},[]),o=e(e=>{r(t=>Gn(t,$n(e,t.present)))},[]),s=e(()=>{r(e=>Jn(e))},[]),l=e(e=>{r(t=>Yn(t,$n(e,t.present)))},[]),u=e(()=>{r(e=>Xn(e))},[]),d=e(()=>{r(e=>Kn(e))},[]),f=e(()=>{r(e=>qn(e))},[]);return{editor:n.present,setEditor:i,resetEditor:a,selectOnly:o,beginGesture:s,updateGesture:l,endGesture:u,undo:d,redo:f,canUndo:Zn(n),canRedo:Qn(n)}}n();function tr(e,t){let n=e.boxes.length;if(n===0)return null;let r=e.boxes.findIndex(t=>t.key===e.selectedKey),i=r<0?t===1?0:n-1:(r+t+n)%n;return e.boxes[i]?.key??null}function nr(e,t){let{history:n}=t,r=n.editor.selectedKey;switch(e.kind){case`next-frame`:return t.onNextFrame();case`prev-frame`:return t.onPrevFrame();case`toggle-complete`:return t.onToggleComplete();case`save`:return t.onSave();case`undo`:return n.canUndo?(n.undo(),!0):!1;case`redo`:return n.canRedo?(n.redo(),!0):!1;case`zoom-in`:return t.onZoomIn(),!0;case`zoom-out`:return t.onZoomOut(),!0;case`zoom-fit`:return t.onZoomFit(),!0;case`accept-all`:return n.setEditor(e=>Bt(e)),!0;case`select-next`:case`select-prev`:{let t=tr(n.editor,e.kind===`select-next`?1:-1);return t===null?!1:(n.selectOnly(e=>Ut(e,t)),!0)}case`deselect`:return r===null?!1:(n.selectOnly(e=>Ut(e,null)),!0);default:break}if(r===null)return!1;switch(e.kind){case`delete`:return n.setEditor(e=>Ht(e,r)),!0;case`set-class`:return n.setEditor(t=>Rt(t,r,{macroClass:e.macroClass})),!0;case`accept`:return n.setEditor(e=>zt(e,r)),!0;case`toggle-model-error`:return n.setEditor(e=>Vt(e,r)),!0;default:return!1}}function rr(e,n){let r=t(n);r.current=n,u(()=>{if(!e)return;let t=e=>{if(e.defaultPrevented||e.isComposing)return;let t=Mn({key:e.key,ctrlKey:e.ctrlKey,metaKey:e.metaKey,shiftKey:e.shiftKey,altKey:e.altKey,typing:jn(e.target)});t!==null&&nr(t,r.current)&&e.preventDefault()};return window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`keydown`,t)}},[e])}n();var ir=`person`,ar={pending:`Reading which detector this camera runs…`,"placement-unreadable":`The detection stage of this camera could not be read, so the model it runs is unknown — not absent.`,"detection-off":`This camera runs no object detector, so there is no proposal to mirror.`,"node-unreachable":`The node that detects for this camera did not answer about its accelerators.`,"device-unknown":`The node does not list the accelerator this camera detects on — asking another one would propose with a different model.`,"step-unknown":`That node carries no object-detection step in its catalog.`,"no-model":`No object-detection model on that accelerator can be resolved for this camera.`};function or({frames:n,activeFrameId:i,onActiveFrame:o,onFramesChanged:s,onSaved:d,setNotice:f,picked:p=!1,onTogglePick:m}){let h=n.find(e=>e.frameId===i),g=h?.deviceId??null,_=er(()=>Pt([],[])),{editor:y,setEditor:b,resetEditor:x,selectOnly:S}=_,C=Bn(),w=Re({frameIds:[i]}),E=pe({frameId:i}),D=L(),O=I(),A=k(),j=ne({deviceIds:g===null?[]:[g]},{enabled:g!==null,staleTime:3e4}),M=j.data?.[0]?.detection?.nodeId??null,N=Ae({nodeId:M??``},{enabled:M!==null,staleTime:3e4}),P=ze({nodeId:M??``},{enabled:M!==null,staleTime:3e4}),F=de({deviceId:g??0},{enabled:g!==null,staleTime:3e4}),R=a(()=>Ot({status:j.data?.[0],nodeDevices:N.data,schema:P.data,resolvedSteps:F.data?.steps}),[j.data,N.data,P.data,F.data]),z=t({stored:w.data,copy:h});z.current={stored:w.data,copy:h};let ee=h!==void 0;u(()=>{C.fit();let{stored:e,copy:t}=z.current;x(Pt((e??[]).filter(e=>e.mediaKey===i),t?.pipelineBoxes??[]))},[i,w.dataUpdatedAt,ee,x,C.fit]);let B=e(async e=>{h!==void 0&&(await A.mutateAsync({...Z(h),complete:e}),await s())},[h,A,s]),V=e(async e=>{if(h===void 0)return;if(f(null),R.kind!==`resolved`){f(ar[R.gap]);return}let t=await D.mutateAsync({...Z(h),subject:e===`package`?{kind:`package`}:{kind:`objects`,modelId:R.modelId,minScore:R.minScore},nodeId:R.nodeId});if(t.kind===`refused`){f(t.reason===`no-zone`?`A package proposal runs on the zone crop only — this camera has no zone, and running the detector on the whole frame at 0.35 proposes furniture.`:`The pipeline refused: ${t.reason}${t.detail===void 0?``:` — ${t.detail}`}`);return}let n=Ft(y,t.proposals.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore},draft:!0})));b(n.state),f(`${t.proposals.length} proposal${t.proposals.length===1?``:`s`} from ${t.modelId}`+(n.skipped>0?` — ${n.skipped} already on the frame`:``)+(t.belowThreshold>0?` — ${t.belowThreshold} more were below ${t.minScore.toFixed(2)}`:``)+`. Accept or correct each one; drafts are not saved.`)},[h,D,R,y,b,f]),te=e(e=>{b(t=>It(t,e,ir))},[b]),[U,W]=c(!1),G=e(async()=>{if(h===void 0)return;let e=Kt(y);W(!0);try{await O.mutateAsync({...Z(h),annotations:[...Jt(y)]}),await w.refetch()}finally{W(!1)}await d?.(),f(e>0?`Annotations saved. ${String(e)} unconfirmed draft${e===1?` was`:`s were`} not saved.`:`Annotations saved.`)},[h,y,O,w,d,f]),K=E.data,re=tn(y.boxes)&&h!==void 0,ie=Kt(y),ae=n.map(e=>e.frameId),oe=e=>{let t=ae.indexOf(i),n=ae[t+e];return t<0||n===void 0?!1:(o(n),!0)};return rr(!U,{history:_,onNextFrame:()=>oe(1),onPrevFrame:()=>oe(-1),onToggleComplete:()=>h===void 0||A.isPending?!1:(B(!h.complete),!0),onSave:()=>!re||U?!1:(G(),!0),onZoomIn:C.zoomIn,onZoomOut:C.zoomOut,onZoomFit:C.fit}),r(`div`,{className:`grid grid-cols-1 xl:grid-cols-[minmax(0,1fr)_minmax(0,380px)] gap-3 ${U?`pointer-events-none opacity-70`:``}`,"aria-busy":U,children:[r(`div`,{className:`rounded-md border border-border overflow-hidden flex flex-col`,children:[l(Vn,{view:C,canUndo:_.canUndo,canRedo:_.canRedo,onUndo:_.undo,onRedo:_.redo}),K===void 0?r(`div`,{className:`flex items-center gap-2 p-6 text-xs text-foreground-subtle`,children:[l(H,{className:`h-3.5 w-3.5 animate-spin`}),`Loading the frame…`]}):l(zn,{imageSrc:`data:image/jpeg;base64,${K.base64}`,imageWidth:K.width,imageHeight:K.height,boxes:y.boxes,selectedKey:y.selectedKey,viewport:C.viewport,onViewportChange:C.setViewport,panMode:C.panMode,onSelect:e=>{S(t=>Ut(t,e))},onDraw:te,onGestureStart:_.beginGesture,onGestureBox:(e,t)=>{_.updateGesture(n=>Rt(n,e,{bbox:t}))},onGestureEnd:_.endGesture})]}),r(`div`,{className:`rounded-md border border-border bg-surface flex flex-col min-h-0`,children:[r(`div`,{className:`px-3 py-2 border-b border-border flex items-center gap-2 flex-wrap`,children:[l(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Subjects`}),h?.origin===`recording`&&l(q,{variant:`info`,children:`from the recording`}),m!==void 0&&r(T,{variant:p?`primary`:`ghost`,size:`sm`,"aria-pressed":p,title:`Pick this frame for a dataset version (Datasets tab)`,onClick:m,children:[l($e,{className:`h-3 w-3`}),l(`span`,{className:`ml-1`,children:p?`Picked`:`Pick for dataset`})]}),r(T,{variant:`secondary`,size:`sm`,disabled:D.isPending||R.kind!==`resolved`,onClick:()=>void V(`objects`),children:[l(Se,{className:`h-3 w-3`}),l(`span`,{className:`ml-1`,children:`Propose`})]}),r(T,{variant:`secondary`,size:`sm`,disabled:D.isPending||R.kind!==`resolved`,onClick:()=>void V(`package`),children:[l(Se,{className:`h-3 w-3`}),l(`span`,{className:`ml-1`,children:`Packages`})]})]}),l(`div`,{className:`px-3 py-1 border-b border-border text-[11px] text-foreground-subtle`,children:R.kind===`resolved`?`Proposals come from ${R.modelId} at ${R.minScore.toFixed(2)}, on ${R.nodeId} — what this camera really runs.`:ar[R.gap]}),h!==void 0&&l(ln,{frame:h,history:_,detector:R,schema:P.data,setNotice:f}),l(`div`,{className:`flex-1 overflow-y-auto`,children:l(en,{boxes:y.boxes,selectedKey:y.selectedKey,onSelect:e=>{S(t=>Ut(t,e))},onChange:(e,t)=>{b(n=>Rt(n,e,t))},onAccept:e=>{b(t=>zt(t,e))},onToggleModelError:e=>{b(t=>Vt(t,e))},onDelete:e=>{b(t=>Ht(t,e))}})}),r(`label`,{className:`px-3 py-2 border-t border-border flex items-center gap-2 text-[11px] text-foreground`,children:[l(v,{"aria-label":`All subjects in this frame are boxed`,checked:h?.complete===!0,disabled:h===void 0||A.isPending,onChange:e=>void B(e.target.checked)}),r(`span`,{className:`flex-1`,children:[`All subjects boxed`,l(`span`,{className:`block text-foreground-subtle`,children:`Detector evaluation uses only these frames — an unboxed person counts as a false alarm. A frame with nothing in it, ticked, is a negative example.`})]})]}),ie>0&&r(`div`,{className:`px-3 py-2 border-t border-border flex items-center gap-2 text-[11px] text-warning`,children:[r(`span`,{className:`flex-1`,children:[ie,` draft`,ie===1?``:`s`,` not confirmed — a draft is never saved. Accept, correct or delete each one.`]}),r(T,{variant:`secondary`,size:`sm`,onClick:()=>{b(e=>Bt(e))},children:[l(He,{className:`h-3 w-3`}),l(`span`,{className:`ml-1`,children:`Accept all`})]})]}),r(`div`,{className:`px-3 py-2 border-t border-border flex items-center justify-between`,children:[r(`span`,{className:`text-[11px] text-foreground-subtle`,children:[y.boxes.filter(e=>e.kind===`model_error`).length,` marked as model errors`]}),l(T,{size:`sm`,disabled:!re||U,onClick:()=>void G(),children:`Save frame`})]})]})]})}n();var sr={"empty-name":`Give the collection a name.`,"duplicate-name":`A collection with that name already exists.`,"unknown-collection":`That collection no longer exists.`};function cr(){let[t,n]=Ve(),[i,s]=c(`tracks`),[d,f]=c(null),[p,m]=c(null),[h,g]=c(null),[_,v]=c(new Map),[y,b]=c(null),[x,S]=c([]),C=t.get(`camera`),w=a(()=>{if(C===null||C===``)return null;let e=Number(C);return Number.isFinite(e)?e:null},[C]),O=e(e=>{n(t=>{let n=new URLSearchParams(t);return e===null?n.delete(`camera`):n.set(`camera`,String(e)),n},{replace:!0})},[n]),k=se({projection:`slim`,isCamera:!0}),A=a(()=>{let e=new Map;for(let t of k.data??[])e.set(t.id,t.name);return e},[k.data]),j=te({}),P=Fe({trackId:d?.trackId??``},{enabled:i===`tracks`&&d!==null}),F=E(),I=be(),L=Ce(),R=B({}),z=Ie({collectionId:p?.id??``},{enabled:i===`collections`&&p!==null}),ee=De(),V=N(),H=we(),W=ge(),G=i===`tracks`?P.data?.copies??[]:z.data??[],ne=e(()=>i===`tracks`?P.refetch():z.refetch(),[i,P,z]);u(()=>{h===null&&G.length>0&&g(G[0].frameId)},[G,h]);let K=e(()=>{g(null),v(new Map),b(null)},[]),re=e(e=>{f(e),K()},[K]),ie=e(e=>{m(e),K()},[K]),ae=e(async e=>{if(d===null)return;let t=await F.mutateAsync({deviceId:d.deviceId,trackId:d.trackId,mediaIds:[e]});if(t.refused.length>0){let e=new Map(_);for(let n of t.refused)e.set(n.sourceMediaId,n.reason);v(e)}t.copied.length>0&&g(t.copied[0].frameId),await P.refetch(),await j.refetch()},[d,F,_,P,j]),oe=e(async e=>{let t=(P.data?.copies??[]).find(t=>t.frameId===e);t!==void 0&&(await I.mutateAsync(Z(t)),h===e&&g(null),await P.refetch(),await j.refetch(),await R.refetch())},[P,I,h,j,R]),ce=e(async()=>{if(d===null)return;let e=await L.mutateAsync({deviceId:d.deviceId,trackId:d.trackId});b(e.changed?`Track completed — it is now trained, and its own media is evictable again.`:e.reason===`no-frames-copied`?`Refused: no frame was ever copied into the dataset. Completing would let retention delete material nothing was extracted from.`:`Refused: ${e.reason??`unknown`}`),await j.refetch(),e.changed&&f(null)},[d,L,j]),le=e(async e=>{let t=await ee.mutateAsync({name:e});return await R.refetch(),t.kind===`refused`?sr[t.reason]??t.reason:(m(t.collection),K(),null)},[ee,R,K]),ue=e(async(e,t)=>{let n=await V.mutateAsync({id:e,name:t});return await R.refetch(),n.kind===`refused`?sr[n.reason]??n.reason:(p?.id===e&&m(n.collection),null)},[V,R,p]),de=e(async e=>{let t=await H.mutateAsync({id:e});p?.id===e&&(m(null),K()),await R.refetch(),b(t.deleted?`Collection deleted${t.removedFrames>0?` — ${String(t.removedFrames)} recording frame${t.removedFrames===1?``:`s`} no other collection held left the dataset`:``}.`:`That collection no longer existed.`)},[H,p,R,K]),fe=e(async e=>{if(p===null)return;let t=await W.mutateAsync({collectionId:p.id,frameId:e.frameId});h===e.frameId&&g(null),await z.refetch(),await R.refetch(),b(t.deletedFrame?`Removed — it was a recording frame no other collection held, so it left the dataset with its boxes.`:`Removed from the collection.`)},[p,W,h,z,R]),pe=e(async()=>{await j.refetch()},[j]),me=i===`tracks`?d!==null:p!==null,he=G.some(e=>e.frameId===h),J=j.data,Y=R.data,_e=a(()=>J===void 0||Y===void 0?null:ot(J,Y),[J,Y]),ve=a(()=>J===void 0?[]:ct(J,A),[J,A]),ye=a(()=>J===void 0?[]:st(J,w),[J,w]);return u(()=>{d!==null&&(ye.some(e=>e.trackId===d.trackId)||(f(null),K()))},[ye,d,K]),r(Ue,{icon:je,title:`Retrain`,subtitle:`Turn marked tracks and frames sent from recordings into an annotated dataset. Every frame is a copy the dataset owns — it never depends on media that can be swept.`,actions:i===`tracks`&&d!==null?r(T,{size:`sm`,onClick:()=>void ce(),children:[l(je,{className:`h-3 w-3`}),l(`span`,{className:`ml-1`,children:`Complete track`})]}):null,children:[y!==null&&l(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-xs text-foreground`,children:y}),l(lt,{counts:_e,cameras:ve,selectedDeviceId:w,onSelectDevice:O}),l(vt,{}),r(`div`,{className:`grid grid-cols-1 lg:grid-cols-[minmax(0,260px)_minmax(0,1fr)] gap-4`,children:[r(`aside`,{className:`rounded-md border border-border bg-surface overflow-hidden`,children:[l(U,{value:i,onValueChange:e=>{s(e===`collections`||e===`datasets`?e:`tracks`),K()},children:r(D,{className:`px-2 pt-2`,children:[r(M,{value:`tracks`,children:[`Tracks `,l(q,{className:`ml-1`,children:ye.length})]}),r(M,{value:`collections`,children:[`Collections `,l(q,{className:`ml-1`,children:Y?.length??0})]}),l(M,{value:`datasets`,children:`Datasets`})]})}),i===`tracks`?l(wt,{tracks:ye,isLoading:j.isLoading,selectedTrackId:d?.trackId??null,deviceNames:A,onSelect:re}):i===`datasets`?l(`p`,{className:`p-3 text-[11px] text-foreground-subtle`,children:`A dataset version freezes the frames a selection of cameras, collections and picked frames yields, with the hash of their boxes, so a training run can name exactly what it learned from. Pick frames with "Pick for dataset" in the frame workbench.`}):l(at,{collections:R.data??[],isLoading:R.isLoading,selectedId:p?.id??null,onSelect:ie,onCreate:le,onRename:ue,onDelete:de})]}),l(`section`,{className:`space-y-3 min-w-0`,children:i===`datasets`?l(_t,{deviceNames:A,collections:R.data??[],pickedFrameIds:x,onClearPicked:()=>{S([])}}):me?r(o,{children:[l(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:i===`tracks`?l(bt,{candidates:P.data?.candidates??[],copies:P.data?.copies??[],activeFrameId:h,refusals:_,isSelecting:F.isPending,onSelectCandidate:e=>void ae(e),onOpenCopy:g,onRemoveCopy:e=>void oe(e),renderCopyActions:e=>l(nt,{frameId:e.frameId,onAdded:()=>R.refetch()})}):l(it,{frames:z.data??[],isLoading:z.isLoading,activeFrameId:h,deviceNames:A,onOpen:g,onRemove:e=>void fe(e)})}),h!==null&&he&&l(or,{frames:G,activeFrameId:h,onActiveFrame:g,onFramesChanged:ne,onSaved:pe,setNotice:b,picked:x.includes(h),onTogglePick:()=>{S(e=>e.includes(h)?e.filter(e=>e!==h):[...e,h])}})]}):l(`p`,{className:`text-xs text-foreground-subtle`,children:i===`tracks`?`Pick a track from the staging list to start annotating it.`:`Pick or create a collection.`})})]})]})}export{cr as RetrainPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,b as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as l}from"./player-overlays-CVsVEZkx.js";import{Df as u,Hd as d,Ku as f,Of as p,Sd as m,Yi as h,Zi as g,cf as _,ci as v,df as y,ha as b,ii as x,ju as S,li as C,ro as w,sa as T,wd as E,zi as D}from"./src-DBOD88Il.js";import{pi as O}from"./client-DdTCFotl.js";import{t as k}from"./useTranslation-Bc5yH9V9.js";import"./mount-DOwpVM5h.js";import{I as A}from"./index-BhXNFlQG.js";import{t as j}from"./BrokerForm-C1gCAO_i.js";n();var M=[`amazon.com`,`amazon.it`,`amazon.de`,`amazon.co.uk`,`amazon.fr`,`amazon.es`,`amazon.ca`,`amazon.com.au`,`amazon.co.jp`,`amazon.in`,`amazon.com.br`,`amazon.com.mx`],N=l(`/addon/import-alexa`),P=2e3;function F(e){return typeof e==`object`&&!!e&&typeof e.sessionId==`string`&&typeof e.loginUrl==`string`}function I(e){return typeof e==`object`&&!!e&&typeof e.phase==`string`&&typeof e.sessionId==`string`}function L(e){return typeof e==`object`&&!!e&&typeof e.brokerId==`string`}function R(e){return{"Content-Type":`application/json`,Authorization:`Bearer ${localStorage.getItem(`camstack_admin_token`)??``}`,...e}}async function z(e,t,n){let r=await fetch(`${N}${e}`,{method:`POST`,headers:R(),body:JSON.stringify(t)}),i=await r.json();if(!r.ok){let e=typeof i==`object`&&i?i.error??`Unknown error`:`Unknown error`;throw Error(String(e))}if(!n(i))throw Error(`Unexpected response from server`);return i}async function B(e){let t=new URLSearchParams({sessionId:e}),n=localStorage.getItem(`camstack_admin_token`)??``,r=await fetch(`${N}/login/status?${t.toString()}`,{headers:{Authorization:`Bearer ${n}`}}),i=await r.json();if(!r.ok){let e=typeof i==`object`&&i?i.error??`Unknown error`:`Unknown error`;throw Error(String(e))}if(!I(i))throw Error(`Unexpected status response from server`);return i}async function V(e){try{await fetch(`${N}/login/cancel`,{method:`POST`,headers:R(),body:JSON.stringify({sessionId:e})})}catch{}}function H({brokerId:n,onResolved:i,onCancel:a}){let[l,u]=o(`amazon.it`),[p,h]=o(`Alexa account`),[g,v]=o({kind:`idle`}),y=t(!0);c(()=>(y.current=!0,()=>{y.current=!1}),[]);let b=t(null),x=t(null),S=e(()=>{x.current!==null&&(clearInterval(x.current),x.current=null)},[]),C=e(async e=>{S(),y.current&&v({kind:`committing`,sessionId:e});try{let t=await z(`/login/commit`,{sessionId:e,name:p.trim().length>0?p.trim():`Alexa account`,...n===void 0?{}:{brokerId:n}},L);b.current=null,i(t.brokerId)}catch(t){let n=t instanceof Error?t.message:String(t);y.current&&v({kind:`error`,message:n,sessionId:e})}},[n,p,i,S]),w=e((e,t)=>{S();let n=async()=>{try{let n=await B(e);if(n.phase===`captured`){S(),C(e);return}if(n.phase===`error`){S(),y.current&&v({kind:`error`,message:n.error??`Login proxy returned an error`,sessionId:e});return}if(n.phase===`cancelled`){S(),y.current&&v({kind:`idle`});return}y.current&&v({kind:`polling`,sessionId:e,loginUrl:n.loginUrl||t,phase:n.phase})}catch(e){let t=e instanceof Error?e.message:String(e);y.current&&v(e=>e.kind===`polling`?{...e}:{kind:`error`,message:t,sessionId:null})}};x.current=setInterval(()=>{n()},P)},[S,C]);c(()=>()=>{S(),b.current!==null&&V(b.current)},[S]);let T=async()=>{S(),b.current!==null&&(V(b.current),b.current=null),v({kind:`starting`});try{let e=await z(`/login/start`,{amazonDomain:l},F);b.current=e.sessionId,v({kind:`polling`,sessionId:e.sessionId,loginUrl:e.loginUrl,phase:`starting`}),w(e.sessionId,e.loginUrl)}catch(e){v({kind:`error`,message:e instanceof Error?e.message:String(e),sessionId:null})}},E=()=>{S(),b.current!==null&&(V(b.current),b.current=null),v({kind:`idle`})},D=()=>{E()},O=g.kind===`idle`,k=g.kind===`starting`,A=g.kind===`polling`,j=g.kind===`committing`,N=g.kind===`error`,I=k||A||j,R=g.kind===`polling`?g.phase:null,H=g.kind===`polling`?g.loginUrl:null,U=A&&R===`awaiting-login`,W=A&&(R===`starting`||R===null);return r(`div`,{className:`space-y-4`,children:[(O||N)&&r(`div`,{className:`space-y-3`,children:[n===void 0&&r(`div`,{className:`space-y-1`,children:[s(`label`,{htmlFor:`alexa-account-name`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Account name`}),s(`input`,{id:`alexa-account-name`,type:`text`,value:p,onChange:e=>h(e.target.value),placeholder:`Alexa account`,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`})]}),r(`div`,{className:`space-y-1`,children:[s(`label`,{htmlFor:`alexa-amazon-region`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Amazon region`}),s(`select`,{id:`alexa-amazon-region`,value:l,onChange:e=>u(e.target.value),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`,children:M.map(e=>s(`option`,{value:e,children:e},e))})]})]}),N&&r(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px] flex items-start gap-2`,children:[s(f,{className:`h-3.5 w-3.5 mt-0.5 flex-shrink-0`}),s(`span`,{children:g.message})]}),k&&r(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[s(d,{className:`h-4 w-4 animate-spin flex-shrink-0`}),`Starting login proxy…`]}),W&&r(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[s(d,{className:`h-4 w-4 animate-spin flex-shrink-0`}),`Waiting for proxy to be ready…`]}),j&&r(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[s(d,{className:`h-4 w-4 animate-spin flex-shrink-0`}),`Saving credentials…`]}),U&&H!==null&&r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-2`,children:[s(`p`,{className:`text-xs font-semibold text-foreground`,children:`Open the link below to log in to your Amazon account`}),s(`p`,{className:`text-[10px] text-foreground-subtle`,children:`After completing the login and any 2FA steps, this wizard will continue automatically.`}),r(`a`,{href:H,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[s(_,{className:`h-3.5 w-3.5`}),`Login to Amazon`]})]}),r(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-[10px] text-warning`,children:[s(`strong`,{children:`Note:`}),` The login proxy runs directly on the hub. If the link does not open or the page does not load, make sure the hub's proxy host and port are reachable from your browser. You can configure `,s(`code`,{className:`font-mono`,children:`proxyHost`}),` in the Alexa addon settings and ensure the proxy port is published (Docker port mapping).`]}),r(`div`,{className:`flex items-center gap-2 text-[10px] text-foreground-subtle`,children:[s(d,{className:`h-3 w-3 animate-spin`}),`Waiting for Amazon login to complete…`]})]}),r(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[s(`button`,{type:`button`,onClick:I?E:a,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:I?`Cancel login`:`Back`}),r(`div`,{className:`flex items-center gap-2`,children:[N&&r(`button`,{type:`button`,onClick:D,className:`inline-flex items-center gap-1.5 rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10`,children:[s(m,{className:`h-3.5 w-3.5`}),`Retry`]}),O&&s(`button`,{type:`button`,onClick:()=>{T()},disabled:n===void 0&&p.trim().length===0,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:`Start login`})]})]})]})}n();var U=`alexa`;function W(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function G(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var K={connected:`bg-success/15 text-success`,connecting:`bg-warning/15 text-warning`,disconnected:`bg-foreground-subtle/15 text-foreground-subtle`,"auth-failed":`bg-danger/15 text-danger`,unreachable:`bg-danger/15 text-danger`,error:`bg-danger/15 text-danger`};function q({kind:e,onResolved:t,onBack:n}){let[a,c]=o(e===U?`alexa-login`:`existing`),l=v({kind:e}),f=i(()=>W(l.data).filter(t=>t.kind===e),[l.data,e]),p=C(),m=i(()=>{for(let t of G(p.data))if(t.kinds.some(t=>t.kind===e))return t.addonId},[p.data,e]),[h,g]=o(null),[_,y]=o(``),b=x({}),S=()=>{h&&t(h)},w=async n=>{_.trim().length!==0&&t((await b.mutateAsync({kind:e,name:_.trim(),settings:n,...m===void 0?{}:{addonId:m}})).id)},T=e=>{e===`new`?g(null):b.reset(),c(e)};return r(`div`,{className:`space-y-4`,children:[r(`button`,{type:`button`,onClick:n,className:`inline-flex items-center gap-1 text-[11px] text-foreground-subtle hover:text-foreground`,children:[s(u,{className:`h-3.5 w-3.5`}),` Back`]}),r(`div`,{className:`inline-flex rounded-lg border border-border p-0.5 flex-wrap gap-0.5`,children:[e===U&&s(`button`,{type:`button`,onClick:()=>T(`alexa-login`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${a===`alexa-login`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:`Login interactively`}),s(`button`,{type:`button`,onClick:()=>T(`existing`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${a===`existing`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:`Use existing`}),s(`button`,{type:`button`,onClick:()=>T(`new`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${a===`new`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:e===U?`Paste cookie`:`Create new`})]}),a===`alexa-login`&&s(H,{onResolved:t,onCancel:n}),a===`existing`&&r(`div`,{className:`space-y-3`,children:[l.isLoading&&r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(d,{className:`h-3.5 w-3.5 animate-spin`}),` Loading brokers…`]}),l.isError&&r(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load brokers:`,` `,l.error instanceof Error?l.error.message:`Unknown error`]}),!l.isLoading&&!l.isError&&f.length===0&&r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-6 text-center text-xs text-foreground-subtle`,children:[`No brokers of this kind yet. Switch to`,` `,s(`span`,{className:`font-medium text-foreground`,children:e===U?`Login interactively`:`Create new`}),` `,`to register one.`]}),s(`div`,{className:`space-y-2`,children:f.map(e=>r(`button`,{type:`button`,onClick:()=>g(e.id),className:`flex w-full items-center justify-between gap-3 rounded-lg border bg-surface p-3 text-left transition-colors ${h===e.id?`border-primary ring-1 ring-primary`:`border-border hover:border-foreground-subtle/30`}`,children:[s(`span`,{className:`text-xs font-semibold text-foreground`,children:e.name}),s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${K[e.status]}`,children:e.status})]},e.id))}),f.length>0&&s(`div`,{className:`flex justify-end pt-1`,children:s(`button`,{type:`button`,onClick:S,disabled:!h,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:`Use this broker`})})]}),a===`new`&&r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),s(`input`,{type:`text`,value:_,onChange:e=>y(e.target.value),placeholder:`My Home Assistant`,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`})]}),b.isError&&s(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:b.error instanceof Error?b.error.message:String(b.error)}),s(j,{kind:e,...m===void 0?{}:{addonId:m},onSubmit:e=>{w(e).catch(()=>{})},onCancel:n,submitLabel:b.isPending?`Creating…`:`Create broker`,disabled:b.isPending||_.trim().length===0}),_.trim().length===0&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before creating.`})]})]})}n();function J(e){return{status:e.status===`validated`||e.status===`rejected`||e.status===`inconclusive`||e.status===`unsupported`?e.status:e.success?`validated`:`rejected`,...e.error===void 0?{}:{error:e.error},...e.detail===void 0?{}:{detail:e.detail}}}var Y={validated:`border-success/30 bg-success/5 text-success`,rejected:`border-danger/30 bg-danger/5 text-danger`,inconclusive:`border-warning/30 bg-warning/5 text-warning`,unsupported:`border-border bg-surface text-foreground-subtle`};function X({addonId:e,configSchema:t,canTest:n=!0,initialName:i,initialConfig:a,submitLabel:c,hideName:l=!1,onSave:u,onBack:d}){let{t:f}=k(),[p,m]=o(i??``),[h,g]=o(a??{}),[_,v]=o(null),y=w({onSuccess:e=>v(J(e)),onError:e=>v({status:`inconclusive`,error:String(e)})});return r(`div`,{className:`space-y-4`,children:[!l&&r(`div`,{children:[s(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:f(`integrations.integrationName`)}),s(`input`,{type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:f(`integrations.integrationNamePlaceholder`),className:`w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:border-primary/50`})]}),t&&s(A,{schema:t,values:h,onChange:g}),_&&s(`div`,{className:`rounded-lg border px-3 py-2 text-xs ${Y[_.status]}`,children:(e=>{switch(e.status){case`validated`:return e.detail?`${f(`integrations.connectionSuccess`)} — ${e.detail}`:f(`integrations.connectionSuccess`);case`rejected`:return`${f(`integrations.errorPrefix`)} ${e.error??``}`;case`inconclusive`:return`${f(`integrations.connectionInconclusive`,{defaultValue:`Could not be checked:`})} ${e.error??``}`;case`unsupported`:return e.error??f(`integrations.connectionUntestable`,{defaultValue:`This integration cannot be tested before it is created.`})}})(_)}),r(`div`,{className:`flex items-center justify-between pt-2`,children:[s(`button`,{onClick:d,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.back`)}),r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:()=>y.mutate({addonId:e,settings:h}),disabled:y.isPending||!n,title:n?void 0:f(`integrations.connectionUntestable`,{defaultValue:`This integration cannot be tested before it is created.`}),className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:y.isPending?f(`integrations.testing`):f(`integrations.testConnection`)}),s(`button`,{onClick:()=>u({name:p,config:h,secretKeys:[...O(t)]}),disabled:l?!1:!p.trim(),className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:c??f(`integrations.forward`)})]})]})]})}n();function Z({open:t,onClose:n,scope:a}){let c=D(),[l,u]=o(new Set),[f,m]=o(new Set),{data:h}=T({projection:`slim`}),g=i(()=>new Set((h??[]).map(e=>e.stableId)),[h]),_=e(async(e,t)=>{m(e=>new Set(e).add(t.stableId));try{await c.mutateAsync({addonId:e,candidate:t}),u(e=>new Set(e).add(t.stableId))}catch{}finally{m(e=>{let n=new Set(e);return n.delete(t.stableId),n})}},[c]),v=e((e,t)=>{let n=typeof t.prefilledConfig.host==`string`?t.prefilledConfig.host:null,i=g.has(t.stableId),a=l.has(t.stableId)||i,o=f.has(t.stableId);return r(`div`,{className:`flex items-center justify-between rounded-lg border border-border bg-surface px-3 py-2`,children:[r(`div`,{className:`min-w-0`,children:[s(`p`,{className:`truncate text-xs font-medium text-foreground`,children:t.suggestedName}),n&&s(`p`,{className:`truncate text-[10px] font-mono text-foreground-subtle`,children:n})]}),a?r(`span`,{className:`flex items-center gap-1 text-[11px] text-foreground-subtle`,children:[s(p,{className:`h-3.5 w-3.5`}),` `,i?`Already added`:`Added`]}):r(`button`,{type:`button`,onClick:()=>void _(e,t),disabled:o,className:`flex items-center gap-1 rounded-md bg-primary px-2.5 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-50`,children:[o?s(d,{className:`h-3.5 w-3.5 animate-spin`}):s(y,{className:`h-3.5 w-3.5`}),`Add`]})]},t.stableId)},[l,f,g,_]);if(!t)return null;let b=a?`Scan network — ${a.label}`:`Scan network for devices`;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:n}),r(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[s(E,{className:`h-4 w-4 text-primary`}),s(`h2`,{className:`text-sm font-semibold text-foreground`,children:b})]}),s(`button`,{onClick:n,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:s(S,{className:`h-4 w-4`})})]}),a?s(ee,{scope:a,onAdopt:v,onReset:()=>u(new Set)}):s(Q,{onAdopt:v,onReset:()=>u(new Set)})]})]})}function Q({onAdopt:t,onReset:n}){let o=h(),l=e(()=>{n(),o.mutate({})},[o,n]);c(()=>{!o.isPending&&!o.data&&l()},[]);let u=i(()=>(o.data?.groups??[]).filter(e=>e.candidates.length>0),[o.data]),d=i(()=>u.reduce((e,t)=>e+t.candidates.length,0),[u]);return r(a,{children:[s(`div`,{className:`flex items-center justify-end gap-2 border-b border-border px-5 py-2 shrink-0`,children:r(`button`,{onClick:l,disabled:o.isPending,className:`flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[s(m,{className:`h-3.5 w-3.5 ${o.isPending?`animate-spin`:``}`}),`Re-scan`]})}),r(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-4`,children:[o.isPending&&s(te,{label:`Scanning the local network…`}),!o.isPending&&o.isError&&s($,{}),!o.isPending&&o.data&&u.length===0&&s(`p`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:`No devices responded to the scan.`}),!o.isPending&&u.length>0&&r(`p`,{className:`text-xs text-foreground-subtle`,children:[`Found `,d,` device`,d===1?``:`s`,` on the network.`]}),!o.isPending&&u.map(e=>r(`div`,{className:`space-y-1.5`,children:[r(`div`,{className:`flex items-center gap-2`,children:[s(`span`,{className:`text-[11px] font-semibold text-foreground`,children:e.label}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`(`,e.candidates.length,`)`]})]}),e.candidates.map(n=>t(e.addonId,n))]},e.addonId))]})]})}function ee({scope:t,onAdopt:n,onReset:i}){let c=b({addonId:t.addonId}).data??null,[l,u]=o({}),f=g(),p=e(()=>{i(),f.mutate({addonId:t.addonId,params:l})},[f,t.addonId,l,i]),m=f.data?.candidates??[];return s(a,{children:r(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-4`,children:[c&&s(A,{schema:c,values:l,onChange:u}),r(`button`,{onClick:p,disabled:f.isPending,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:[f.isPending?s(d,{className:`h-3.5 w-3.5 animate-spin`}):s(E,{className:`h-3.5 w-3.5`}),f.isPending?`Scanning…`:`Scan`]}),f.isError&&s($,{}),!f.isPending&&f.data&&m.length===0&&s(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:`No devices responded to the scan.`}),!f.isPending&&m.length>0&&r(`div`,{className:`space-y-1.5`,children:[r(`p`,{className:`text-xs text-foreground-subtle`,children:[`Found `,m.length,` device`,m.length===1?``:`s`,`.`]}),m.map(e=>n(t.addonId,e))]})]})})}function te({label:e}){return r(`div`,{className:`flex flex-col items-center py-12`,children:[s(d,{className:`h-6 w-6 animate-spin text-primary`}),s(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:e})]})}function $(){return r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[s(f,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),s(`p`,{className:`text-xs text-destructive`,children:`The scan failed. Try again.`})]})}export{X as n,q as r,Z as t};
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,W as i,b as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as l}from"./player-overlays-D9aoM64J.js";import{Bi as u,Cd as d,Mu as f,Of as p,Qi as m,Td as h,Ud as g,Xi as _,ai as v,ca as y,ff as b,ga as x,io as S,kf as C,lf as w,li as T,qu as E,ui as D}from"./src-B-IRCQFw.js";import{pi as O}from"./client-DX0rAC3X.js";import{t as k}from"./useTranslation-Bc5yH9V9.js";import"./mount-BTxjd_Y8.js";import{I as A}from"./index-D7yeH_53.js";import{t as j}from"./BrokerForm-BKrrZCZh.js";n();var M=[`amazon.com`,`amazon.it`,`amazon.de`,`amazon.co.uk`,`amazon.fr`,`amazon.es`,`amazon.ca`,`amazon.com.au`,`amazon.co.jp`,`amazon.in`,`amazon.com.br`,`amazon.com.mx`],N=l(`/addon/import-alexa`),P=2e3;function F(e){return typeof e==`object`&&!!e&&typeof e.sessionId==`string`&&typeof e.loginUrl==`string`}function I(e){return typeof e==`object`&&!!e&&typeof e.phase==`string`&&typeof e.sessionId==`string`}function L(e){return typeof e==`object`&&!!e&&typeof e.brokerId==`string`}function R(e){return{"Content-Type":`application/json`,Authorization:`Bearer ${localStorage.getItem(`camstack_admin_token`)??``}`,...e}}async function z(e,t,n){let r=await fetch(`${N}${e}`,{method:`POST`,headers:R(),body:JSON.stringify(t)}),i=await r.json();if(!r.ok){let e=typeof i==`object`&&i?i.error??`Unknown error`:`Unknown error`;throw Error(String(e))}if(!n(i))throw Error(`Unexpected response from server`);return i}async function B(e){let t=new URLSearchParams({sessionId:e}),n=localStorage.getItem(`camstack_admin_token`)??``,r=await fetch(`${N}/login/status?${t.toString()}`,{headers:{Authorization:`Bearer ${n}`}}),i=await r.json();if(!r.ok){let e=typeof i==`object`&&i?i.error??`Unknown error`:`Unknown error`;throw Error(String(e))}if(!I(i))throw Error(`Unexpected status response from server`);return i}async function V(e){try{await fetch(`${N}/login/cancel`,{method:`POST`,headers:R(),body:JSON.stringify({sessionId:e})})}catch{}}function H({brokerId:n,onResolved:i,onCancel:a}){let[l,u]=o(`amazon.it`),[f,p]=o(`Alexa account`),[m,h]=o({kind:`idle`}),_=t(!0);c(()=>(_.current=!0,()=>{_.current=!1}),[]);let v=t(null),y=t(null),b=e(()=>{y.current!==null&&(clearInterval(y.current),y.current=null)},[]),x=e(async e=>{b(),_.current&&h({kind:`committing`,sessionId:e});try{let t=await z(`/login/commit`,{sessionId:e,name:f.trim().length>0?f.trim():`Alexa account`,...n===void 0?{}:{brokerId:n}},L);v.current=null,i(t.brokerId)}catch(t){let n=t instanceof Error?t.message:String(t);_.current&&h({kind:`error`,message:n,sessionId:e})}},[n,f,i,b]),S=e((e,t)=>{b();let n=async()=>{try{let n=await B(e);if(n.phase===`captured`){b(),x(e);return}if(n.phase===`error`){b(),_.current&&h({kind:`error`,message:n.error??`Login proxy returned an error`,sessionId:e});return}if(n.phase===`cancelled`){b(),_.current&&h({kind:`idle`});return}_.current&&h({kind:`polling`,sessionId:e,loginUrl:n.loginUrl||t,phase:n.phase})}catch(e){let t=e instanceof Error?e.message:String(e);_.current&&h(e=>e.kind===`polling`?{...e}:{kind:`error`,message:t,sessionId:null})}};y.current=setInterval(()=>{n()},P)},[b,x]);c(()=>()=>{b(),v.current!==null&&V(v.current)},[b]);let C=async()=>{b(),v.current!==null&&(V(v.current),v.current=null),h({kind:`starting`});try{let e=await z(`/login/start`,{amazonDomain:l},F);v.current=e.sessionId,h({kind:`polling`,sessionId:e.sessionId,loginUrl:e.loginUrl,phase:`starting`}),S(e.sessionId,e.loginUrl)}catch(e){h({kind:`error`,message:e instanceof Error?e.message:String(e),sessionId:null})}},T=()=>{b(),v.current!==null&&(V(v.current),v.current=null),h({kind:`idle`})},D=()=>{T()},O=m.kind===`idle`,k=m.kind===`starting`,A=m.kind===`polling`,j=m.kind===`committing`,N=m.kind===`error`,I=k||A||j,R=m.kind===`polling`?m.phase:null,H=m.kind===`polling`?m.loginUrl:null,U=A&&R===`awaiting-login`,W=A&&(R===`starting`||R===null);return r(`div`,{className:`space-y-4`,children:[(O||N)&&r(`div`,{className:`space-y-3`,children:[n===void 0&&r(`div`,{className:`space-y-1`,children:[s(`label`,{htmlFor:`alexa-account-name`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Account name`}),s(`input`,{id:`alexa-account-name`,type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:`Alexa account`,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`})]}),r(`div`,{className:`space-y-1`,children:[s(`label`,{htmlFor:`alexa-amazon-region`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Amazon region`}),s(`select`,{id:`alexa-amazon-region`,value:l,onChange:e=>u(e.target.value),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`,children:M.map(e=>s(`option`,{value:e,children:e},e))})]})]}),N&&r(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px] flex items-start gap-2`,children:[s(E,{className:`h-3.5 w-3.5 mt-0.5 flex-shrink-0`}),s(`span`,{children:m.message})]}),k&&r(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[s(g,{className:`h-4 w-4 animate-spin flex-shrink-0`}),`Starting login proxy…`]}),W&&r(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[s(g,{className:`h-4 w-4 animate-spin flex-shrink-0`}),`Waiting for proxy to be ready…`]}),j&&r(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[s(g,{className:`h-4 w-4 animate-spin flex-shrink-0`}),`Saving credentials…`]}),U&&H!==null&&r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-2`,children:[s(`p`,{className:`text-xs font-semibold text-foreground`,children:`Open the link below to log in to your Amazon account`}),s(`p`,{className:`text-[10px] text-foreground-subtle`,children:`After completing the login and any 2FA steps, this wizard will continue automatically.`}),r(`a`,{href:H,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[s(w,{className:`h-3.5 w-3.5`}),`Login to Amazon`]})]}),r(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-[10px] text-warning`,children:[s(`strong`,{children:`Note:`}),` The login proxy runs directly on the hub. If the link does not open or the page does not load, make sure the hub's proxy host and port are reachable from your browser. You can configure `,s(`code`,{className:`font-mono`,children:`proxyHost`}),` in the Alexa addon settings and ensure the proxy port is published (Docker port mapping).`]}),r(`div`,{className:`flex items-center gap-2 text-[10px] text-foreground-subtle`,children:[s(g,{className:`h-3 w-3 animate-spin`}),`Waiting for Amazon login to complete…`]})]}),r(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[s(`button`,{type:`button`,onClick:I?T:a,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:I?`Cancel login`:`Back`}),r(`div`,{className:`flex items-center gap-2`,children:[N&&r(`button`,{type:`button`,onClick:D,className:`inline-flex items-center gap-1.5 rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10`,children:[s(d,{className:`h-3.5 w-3.5`}),`Retry`]}),O&&s(`button`,{type:`button`,onClick:()=>{C()},disabled:n===void 0&&f.trim().length===0,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:`Start login`})]})]})]})}n();var U=`alexa`;function W(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function G(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var K={connected:`bg-success/15 text-success`,connecting:`bg-warning/15 text-warning`,disconnected:`bg-foreground-subtle/15 text-foreground-subtle`,"auth-failed":`bg-danger/15 text-danger`,unreachable:`bg-danger/15 text-danger`,error:`bg-danger/15 text-danger`};function q({kind:e,onResolved:t,onBack:n}){let[a,c]=o(e===U?`alexa-login`:`existing`),l=T({kind:e}),u=i(()=>W(l.data).filter(t=>t.kind===e),[l.data,e]),d=D(),f=i(()=>{for(let t of G(d.data))if(t.kinds.some(t=>t.kind===e))return t.addonId},[d.data,e]),[m,h]=o(null),[_,y]=o(``),b=v({}),x=()=>{m&&t(m)},S=async n=>{_.trim().length!==0&&t((await b.mutateAsync({kind:e,name:_.trim(),settings:n,...f===void 0?{}:{addonId:f}})).id)},C=e=>{e===`new`?h(null):b.reset(),c(e)};return r(`div`,{className:`space-y-4`,children:[r(`button`,{type:`button`,onClick:n,className:`inline-flex items-center gap-1 text-[11px] text-foreground-subtle hover:text-foreground`,children:[s(p,{className:`h-3.5 w-3.5`}),` Back`]}),r(`div`,{className:`inline-flex rounded-lg border border-border p-0.5 flex-wrap gap-0.5`,children:[e===U&&s(`button`,{type:`button`,onClick:()=>C(`alexa-login`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${a===`alexa-login`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:`Login interactively`}),s(`button`,{type:`button`,onClick:()=>C(`existing`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${a===`existing`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:`Use existing`}),s(`button`,{type:`button`,onClick:()=>C(`new`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${a===`new`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:e===U?`Paste cookie`:`Create new`})]}),a===`alexa-login`&&s(H,{onResolved:t,onCancel:n}),a===`existing`&&r(`div`,{className:`space-y-3`,children:[l.isLoading&&r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(g,{className:`h-3.5 w-3.5 animate-spin`}),` Loading brokers…`]}),l.isError&&r(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load brokers:`,` `,l.error instanceof Error?l.error.message:`Unknown error`]}),!l.isLoading&&!l.isError&&u.length===0&&r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-6 text-center text-xs text-foreground-subtle`,children:[`No brokers of this kind yet. Switch to`,` `,s(`span`,{className:`font-medium text-foreground`,children:e===U?`Login interactively`:`Create new`}),` `,`to register one.`]}),s(`div`,{className:`space-y-2`,children:u.map(e=>r(`button`,{type:`button`,onClick:()=>h(e.id),className:`flex w-full items-center justify-between gap-3 rounded-lg border bg-surface p-3 text-left transition-colors ${m===e.id?`border-primary ring-1 ring-primary`:`border-border hover:border-foreground-subtle/30`}`,children:[s(`span`,{className:`text-xs font-semibold text-foreground`,children:e.name}),s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${K[e.status]}`,children:e.status})]},e.id))}),u.length>0&&s(`div`,{className:`flex justify-end pt-1`,children:s(`button`,{type:`button`,onClick:x,disabled:!m,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:`Use this broker`})})]}),a===`new`&&r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),s(`input`,{type:`text`,value:_,onChange:e=>y(e.target.value),placeholder:`My Home Assistant`,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`})]}),b.isError&&s(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:b.error instanceof Error?b.error.message:String(b.error)}),s(j,{kind:e,...f===void 0?{}:{addonId:f},onSubmit:e=>{S(e).catch(()=>{})},onCancel:n,submitLabel:b.isPending?`Creating…`:`Create broker`,disabled:b.isPending||_.trim().length===0}),_.trim().length===0&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before creating.`})]})]})}n();function J(e){return{status:e.status===`validated`||e.status===`rejected`||e.status===`inconclusive`||e.status===`unsupported`?e.status:e.success?`validated`:`rejected`,...e.error===void 0?{}:{error:e.error},...e.detail===void 0?{}:{detail:e.detail}}}var Y={validated:`border-success/30 bg-success/5 text-success`,rejected:`border-danger/30 bg-danger/5 text-danger`,inconclusive:`border-warning/30 bg-warning/5 text-warning`,unsupported:`border-border bg-surface text-foreground-subtle`};function X({addonId:e,configSchema:t,canTest:n=!0,initialName:i,initialConfig:a,submitLabel:c,hideName:l=!1,onSave:u,onBack:d}){let{t:f}=k(),[p,m]=o(i??``),[h,g]=o(a??{}),[_,v]=o(null),y=S({onSuccess:e=>v(J(e)),onError:e=>v({status:`inconclusive`,error:String(e)})});return r(`div`,{className:`space-y-4`,children:[!l&&r(`div`,{children:[s(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:f(`integrations.integrationName`)}),s(`input`,{type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:f(`integrations.integrationNamePlaceholder`),className:`w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:border-primary/50`})]}),t&&s(A,{schema:t,values:h,onChange:g}),_&&s(`div`,{className:`rounded-lg border px-3 py-2 text-xs ${Y[_.status]}`,children:(e=>{switch(e.status){case`validated`:return e.detail?`${f(`integrations.connectionSuccess`)} — ${e.detail}`:f(`integrations.connectionSuccess`);case`rejected`:return`${f(`integrations.errorPrefix`)} ${e.error??``}`;case`inconclusive`:return`${f(`integrations.connectionInconclusive`,{defaultValue:`Could not be checked:`})} ${e.error??``}`;case`unsupported`:return e.error??f(`integrations.connectionUntestable`,{defaultValue:`This integration cannot be tested before it is created.`})}})(_)}),r(`div`,{className:`flex items-center justify-between pt-2`,children:[s(`button`,{onClick:d,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.back`)}),r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:()=>y.mutate({addonId:e,settings:h}),disabled:y.isPending||!n,title:n?void 0:f(`integrations.connectionUntestable`,{defaultValue:`This integration cannot be tested before it is created.`}),className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:y.isPending?f(`integrations.testing`):f(`integrations.testConnection`)}),s(`button`,{onClick:()=>u({name:p,config:h,secretKeys:[...O(t)]}),disabled:l?!1:!p.trim(),className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:c??f(`integrations.forward`)})]})]})]})}n();function Z({open:t,onClose:n,scope:a}){let c=u(),[l,d]=o(new Set),[p,m]=o(new Set),{data:_}=y({projection:`slim`}),v=i(()=>new Set((_??[]).map(e=>e.stableId)),[_]),x=e(async(e,t)=>{m(e=>new Set(e).add(t.stableId));try{await c.mutateAsync({addonId:e,candidate:t}),d(e=>new Set(e).add(t.stableId))}catch{}finally{m(e=>{let n=new Set(e);return n.delete(t.stableId),n})}},[c]),S=e((e,t)=>{let n=typeof t.prefilledConfig.host==`string`?t.prefilledConfig.host:null,i=v.has(t.stableId),a=l.has(t.stableId)||i,o=p.has(t.stableId);return r(`div`,{className:`flex items-center justify-between rounded-lg border border-border bg-surface px-3 py-2`,children:[r(`div`,{className:`min-w-0`,children:[s(`p`,{className:`truncate text-xs font-medium text-foreground`,children:t.suggestedName}),n&&s(`p`,{className:`truncate text-[10px] font-mono text-foreground-subtle`,children:n})]}),a?r(`span`,{className:`flex items-center gap-1 text-[11px] text-foreground-subtle`,children:[s(C,{className:`h-3.5 w-3.5`}),` `,i?`Already added`:`Added`]}):r(`button`,{type:`button`,onClick:()=>void x(e,t),disabled:o,className:`flex items-center gap-1 rounded-md bg-primary px-2.5 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-50`,children:[o?s(g,{className:`h-3.5 w-3.5 animate-spin`}):s(b,{className:`h-3.5 w-3.5`}),`Add`]})]},t.stableId)},[l,p,v,x]);if(!t)return null;let w=a?`Scan network — ${a.label}`:`Scan network for devices`;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:n}),r(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[s(h,{className:`h-4 w-4 text-primary`}),s(`h2`,{className:`text-sm font-semibold text-foreground`,children:w})]}),s(`button`,{onClick:n,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:s(f,{className:`h-4 w-4`})})]}),a?s(ee,{scope:a,onAdopt:S,onReset:()=>d(new Set)}):s(Q,{onAdopt:S,onReset:()=>d(new Set)})]})]})}function Q({onAdopt:t,onReset:n}){let o=_(),l=e(()=>{n(),o.mutate({})},[o,n]);c(()=>{!o.isPending&&!o.data&&l()},[]);let u=i(()=>(o.data?.groups??[]).filter(e=>e.candidates.length>0),[o.data]),f=i(()=>u.reduce((e,t)=>e+t.candidates.length,0),[u]);return r(a,{children:[s(`div`,{className:`flex items-center justify-end gap-2 border-b border-border px-5 py-2 shrink-0`,children:r(`button`,{onClick:l,disabled:o.isPending,className:`flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[s(d,{className:`h-3.5 w-3.5 ${o.isPending?`animate-spin`:``}`}),`Re-scan`]})}),r(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-4`,children:[o.isPending&&s(te,{label:`Scanning the local network…`}),!o.isPending&&o.isError&&s($,{}),!o.isPending&&o.data&&u.length===0&&s(`p`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:`No devices responded to the scan.`}),!o.isPending&&u.length>0&&r(`p`,{className:`text-xs text-foreground-subtle`,children:[`Found `,f,` device`,f===1?``:`s`,` on the network.`]}),!o.isPending&&u.map(e=>r(`div`,{className:`space-y-1.5`,children:[r(`div`,{className:`flex items-center gap-2`,children:[s(`span`,{className:`text-[11px] font-semibold text-foreground`,children:e.label}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`(`,e.candidates.length,`)`]})]}),e.candidates.map(n=>t(e.addonId,n))]},e.addonId))]})]})}function ee({scope:t,onAdopt:n,onReset:i}){let c=x({addonId:t.addonId}).data??null,[l,u]=o({}),d=m(),f=e(()=>{i(),d.mutate({addonId:t.addonId,params:l})},[d,t.addonId,l,i]),p=d.data?.candidates??[];return s(a,{children:r(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-4`,children:[c&&s(A,{schema:c,values:l,onChange:u}),r(`button`,{onClick:f,disabled:d.isPending,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:[d.isPending?s(g,{className:`h-3.5 w-3.5 animate-spin`}):s(h,{className:`h-3.5 w-3.5`}),d.isPending?`Scanning…`:`Scan`]}),d.isError&&s($,{}),!d.isPending&&d.data&&p.length===0&&s(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:`No devices responded to the scan.`}),!d.isPending&&p.length>0&&r(`div`,{className:`space-y-1.5`,children:[r(`p`,{className:`text-xs text-foreground-subtle`,children:[`Found `,p.length,` device`,p.length===1?``:`s`,`.`]}),p.map(e=>n(t.addonId,e))]})]})})}function te({label:e}){return r(`div`,{className:`flex flex-col items-center py-12`,children:[s(g,{className:`h-6 w-6 animate-spin text-primary`}),s(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:e})]})}function $(){return r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[s(E,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),s(`p`,{className:`text-xs text-destructive`,children:`The scan failed. Try again.`})]})}export{X as n,q as r,Z as t};
|