@camstack/addon-admin-ui 1.2.370 → 1.2.371
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-rNUHK9wc.js → AddonAssetIcon-DHZhQmct.js} +1 -1
- package/dist/assets/{AddonIntegrationBody-C5wKwiTM.js → AddonIntegrationBody-CvC-ctwD.js} +1 -1
- package/dist/assets/{Addons-MDKsHDDm.js → Addons-CKywhwPt.js} +1 -1
- package/dist/assets/{AdminTabs-B7mqaGod.js → AdminTabs-8Dj_NAGy.js} +1 -1
- package/dist/assets/{AiProfiles-DaN2f1Go.js → AiProfiles-DXLk6rfB.js} +1 -1
- package/dist/assets/{BrokerForm-DjytVdo-.js → BrokerForm-Ddnt026G.js} +1 -1
- package/dist/assets/{Build-CHz1FqbZ.js → Build-DDO0D9V1.js} +1 -1
- package/dist/assets/Cluster-BuWcQoSd.js +1 -0
- package/dist/assets/{ClusterStepModel-Bg7jOAJE.js → ClusterStepModel-BkvBpCbM.js} +1 -1
- package/dist/assets/{CompositionEditorPage-CZRgABku.js → CompositionEditorPage-DwsVvapo.js} +1 -1
- package/dist/assets/{Data-CCQ5NT9z.js → Data-B61z420-.js} +1 -1
- package/dist/assets/DetectionIntelligence-DDob3sC5.js +1 -0
- package/dist/assets/{DeviceDetail-4Wa8zL39.js → DeviceDetail-1BZRldKF.js} +1 -1
- package/dist/assets/{Devices-BiwjNBIq.js → Devices-U4WBVoql.js} +1 -1
- package/dist/assets/Events-C_nFN3PH.js +1 -0
- package/dist/assets/{Identity-tue9lGgH.js → Identity-BiPNBuDe.js} +1 -1
- package/dist/assets/IntegrationDetail-DHgZuVtx.js +1 -0
- package/dist/assets/{Integrations-BfRNaP7l.js → Integrations-ChuympDa.js} +1 -1
- package/dist/assets/{Integrations-14od7JhH.js → Integrations-J88KrLOz.js} +1 -1
- package/dist/assets/{Locations-DS0EKKOB.js → Locations-_sXqNO6t.js} +1 -1
- package/dist/assets/{Logs-C_MmssVj.js → Logs-D1C5TfHE.js} +1 -1
- package/dist/assets/{MyAccess-wao27sRf.js → MyAccess-BXdjwRge.js} +1 -1
- package/dist/assets/{Network-oQcNkgTu.js → Network-B6jCW_Rn.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-BMxvR3AQ.js → NodeAddonsSettingsPanel-CaFVzCn2.js} +1 -1
- package/dist/assets/{Notifications-BB99xksI.js → Notifications-BaY0kMxA.js} +1 -1
- package/dist/assets/Plates-B4xeYvjz.js +1 -0
- package/dist/assets/{Recordings-B1ihCXnh.js → Recordings-obNohLiO.js} +1 -1
- package/dist/assets/{ScanNetworkModal-BtSkDnst.js → ScanNetworkModal-lVEZiZt7.js} +1 -1
- package/dist/assets/{Scenes-Cxsst6jH.js → Scenes-jQyGFZdk.js} +1 -1
- package/dist/assets/{SessionsList-K0gNSKrq.js → SessionsList-C3zjya_P.js} +1 -1
- package/dist/assets/{Showroom-CTGDj91m.js → Showroom-nGg1RdRU.js} +1 -1
- package/dist/assets/{System-CMAwUkxP.js → System-DEbF_6my.js} +1 -1
- package/dist/assets/{Terminal-PyG5NErD.js → Terminal-Dw0T9Poc.js} +1 -1
- package/dist/assets/{device-integration-icon-DbGFErfk.js → device-integration-icon-BPbaumq5.js} +1 -1
- package/dist/assets/{index-BsZjL5HO.js → index-BRJ2elAM.js} +2 -2
- package/dist/assets/{index-BKZRl3KT.css → index-MfQ6ok9_.css} +1 -1
- package/dist/assets/{location-owned-usage-CtdITciE.js → location-owned-usage-CYFbUEAM.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-625c8410.js → mf-entry-bootstrap-0-9c623e08.js} +1 -1
- package/dist/assets/{useNodeUrlSelection-Dcp64NLR.js → useNodeUrlSelection-DtbrNqRx.js} +1 -1
- package/dist/index.html +3 -3
- package/dist/server/addon.js +1 -1
- package/package.json +1 -1
- package/dist/assets/Cluster-Dn986Tn1.js +0 -1
- package/dist/assets/DetectionIntelligence-C6APwggP.js +0 -1
- package/dist/assets/Events-C8u59wdS.js +0 -1
- package/dist/assets/IntegrationDetail-DItHIF-n.js +0 -1
- package/dist/assets/Plates-YkdrGkW8.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,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{R as d,X as f,Z as p,at as m,ct as h,ft as g,gt as _,ht as v,st as y,vt as b}from"./player-overlays-B7T46vDu.js";import{$n as x,An as S,Cn as C,Cr as w,Du as T,Fl as E,Fn as D,Hl as O,Hu as k,Il as A,In as j,Jn as M,Kd as N,Kn as ee,Md as P,Nn as F,Od as I,Tf as L,Ud as te,Vo as ne,Yu as R,_u as re,af as ie,as as ae,cn as oe,ds as z,er as B,fs as V,gd as H,hd as se,iu as ce,kt as le,la as ue,ls as de,nf as fe,os as pe,ot as me,qn as he,rs as ge,ss as _e,tr as U,tu as ve,wu as ye,xn as be,zd as xe}from"./src-B06iwqFQ.js";import{a as Se,c as Ce,d as we,f as Te,i as Ee,m as De,n as Oe,o as ke,p as Ae,r as je,s as Me,t as Ne}from"./debounced-invalidate-CC0VQLjV.js";import{Un as Pe,vi as Fe}from"./client-BBcQuaON.js";import{t as Ie}from"./useTranslation-Bc5yH9V9.js";import"./mount-C9R5gyah.js";import{$ as Le,X as Re,Z as ze}from"./index-BsZjL5HO.js";import{t as Be}from"./AdminPage-BSFohA3i.js";import{a as Ve,i as He,r as Ue,t as We}from"./authed-media-DmDTbsLa.js";import{t as Ge}from"./use-stationary-objects-CICValw3.js";import{t as Ke}from"./AdminTabs-B7mqaGod.js";var qe=b(`arrow-down-wide-narrow`,[[`path`,{d:`m3 16 4 4 4-4`,key:`1co6wj`}],[`path`,{d:`M7 20V4`,key:`1yoxec`}],[`path`,{d:`M11 4h10`,key:`1w87gc`}],[`path`,{d:`M11 8h7`,key:`djye34`}],[`path`,{d:`M11 12h4`,key:`q8tih4`}]]),Je=b(`square-parking`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 17V7h4a3 3 0 0 1 0 6H9`,key:`1dfk2c`}]]);n();function Ye(e){let t=e.subLabel??e.label;if(t!==void 0)return t;let n=e.audioLabels?.[0]?.label;return n!==void 0&&n.length>0?n:void 0}var Xe=720*60*60*1e3;function Ze(e){let t=[];for(let n of e)t.push(...n);return t}function Qe(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function $e(e,t){return e.filter(e=>!(e.importance<t.minImportance||t.cameras.size>0&&!t.cameras.has(e.deviceId)||t.classes.size>0&&!t.classes.has(e.className)))}function et(e,t){return`${String(e)}:${t}`}function tt(e,t){let n=new Map,r=new Set;for(let i of e){let e=et(i.deviceId,i.trackId);if(!t.has(e)||r.has(e))continue;r.add(e);let a=n.get(i.deviceId);a?a.push(i.trackId):n.set(i.deviceId,[i.trackId])}return n}function nt(e,t){return{since:e.fromMs??t-Xe,until:e.toMs??t}}var rt=[`native`,`raster`,`standin`];function it(e){return rt.some(t=>t===e)}var at={standin:{label:`stand-in`,title:`Stand-in: this tile is a face or plate detail crop copied in because no frame of the subject was captured. It is not a best shot.`,tone:`warning`},raster:{label:`low-res`,title:`Raster crop: a sub-native cut of the subject, not a native capture. Honest, but lower resolution than a best shot.`,tone:`info`}};function ot(e){return e===`standin`?at.standin:e===`raster`?at.raster:null}var st={"no-key-frame":`No key frame existed at close, so no native tile could be cut.`,"no-best-seen-bbox":`No subject box was ever recorded, so there was nothing to cut around.`,"derive-returned-null":`The close-time crop was attempted and produced nothing.`,"derive-threw":`The close-time crop failed with an error.`,"derive-not-wired":`No close-time crop was wired on this node.`,"no-media-store":`The node was shutting down mid-close.`,"no-thumbnail":`The track closed with no tile of any kind.`,"standin-tile":`The track closed with a detail crop standing in for the subject.`,"raster-tile":`The track closed with a sub-native raster crop of the subject.`,"native-tile":`The track closed with a native tile.`};function ct(e){if(e===void 0)return null;let t=e.trim();if(t.length===0)return null;let n=t.split(/\s+/),r=n[0]??t,i=[];for(let e of n.slice(1)){let t=e.indexOf(`=`);t===-1?i.push({key:e,value:null}):i.push({key:e.slice(0,t),value:e.slice(t+1)})}return{sentence:st[r]??r,detail:i,raw:t}}function lt(e){if(e===void 0||!Number.isFinite(e)||e<=0)return``;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`${String(n)}m ${String(r).padStart(2,`0`)}s`}function ut({row:e,cameraName:t,nowMs:n,onOpenDetail:i,selected:a=!1,onToggleSelect:o,score:s,provenance:c,footer:u}){let d=Ve(e.mediaId===void 0?He(`track`,e.trackId):Ue(e.mediaId)),f=Math.round(e.importance*100),p=s===void 0?void 0:Math.round(s*100),m=lt(e.windowMs),_=()=>i(e),v=ot(c);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${a?`border-primary ring-1 ring-primary`:`border-border`}`,children:[r(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[d.src?l(`img`,{src:d.src,alt:`Event from ${t}`,onClick:_,className:`h-full w-full cursor-zoom-in object-cover`}):l(`button`,{type:`button`,onClick:_,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:d.failed?`Key-event media unavailable`:`No key-event media`,children:l(g,{className:`h-6 w-6 opacity-60`})}),o&&l(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(et(e.deviceId,e.trackId))},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":a?`Deselect`:`Select`,children:a?l(De,{className:`h-4 w-4 text-primary`}):l(h,{className:`h-4 w-4`})}),p!==void 0&&r(`span`,{className:`absolute left-1 top-1 z-10 rounded bg-primary/85 px-1.5 py-0.5 text-[10px] font-semibold text-white tabular-nums`,title:`CLIP semantic-match score`,children:[String(p),`%`]}),f>0&&l(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(f)}),v!==null&&l(`span`,{className:`absolute bottom-1 right-1 z-10 rounded px-1.5 py-0.5 text-[10px] font-semibold text-white ${v.tone===`warning`?`bg-warning/90`:`bg-black/70`}`,title:v.title,children:v.label}),(e.markForTrain===!0||e.retrainStatus===`trained`||e.debug===!0||e.favourited===!0)&&r(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[e.markForTrain===!0&&l(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Marked for training`,"aria-label":`Marked for training`,children:l(I,{className:`h-3 w-3`})}),e.retrainStatus===`trained`&&e.markForTrain!==!0&&l(`span`,{className:`rounded bg-success/85 p-0.5 text-white`,title:`Training complete`,"aria-label":`Training complete`,"data-testid":`retrain-status-trained`,children:l(fe,{className:`h-3 w-3`})}),e.debug===!0&&l(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:`Flagged for debug`,"aria-label":`Flagged for debug`,children:l(ie,{className:`h-3 w-3`})}),e.favourited===!0&&l(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Favourited`,"aria-label":`Favourited`,children:l(T,{className:`h-3 w-3`})})]})]}),r(`button`,{type:`button`,onClick:_,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[r(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,Ye(e)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,Ye(e)]}):null]}),l(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),r(`div`,{className:`flex items-center justify-between gap-2`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:Te(e.timestamp,n)}),m&&l(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:m})]})]}),u!==void 0&&l(`div`,{className:`px-2 pb-1.5`,children:u})]})}var dt=1400,ft=`Admin-gated URL — opens only inside an authenticated session`;function pt({label:t,value:n,title:i}){let[a,o]=c(!1),s=M();return u(()=>{if(!a)return;let e=setTimeout(()=>o(!1),dt);return()=>clearTimeout(e)},[a]),r(`button`,{type:`button`,onClick:e(()=>{(async()=>{try{await navigator.clipboard.writeText(n),o(!0)}catch{await s({title:`Copy the media URL`,message:`Clipboard access was refused. Select the URL below and copy it manually.`,label:`${t} URL`,defaultValue:n,readOnly:!0,cancelLabel:`Close`})}})()},[n,t,s]),title:i,"aria-label":`Copy ${t} URL`,className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${a?`border-success/40 bg-success/10 text-success`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[l(a?fe:te,{className:`h-2.5 w-2.5 shrink-0`}),l(`span`,{className:`truncate`,children:a?`Copied`:t})]})}function mt({localUrl:e,publicUrl:t}){return r(`div`,{className:`flex flex-wrap gap-1`,children:[l(pt,{label:`Local`,value:e,title:`Copy LAN URL — ${ft}`}),t&&l(pt,{label:`Public`,value:t,title:`Copy public URL — ${ft}`})]})}var ht={firstFrame:`First frame (track start)`,lastFrame:`Last frame (track end)`,thumbnail:`Best detection`,thumbnailSmall:`Best detection (480)`,snapshot:`Snapshot`,keyFrame:`Key frame (native-res)`,keyFrameSmall:`Key frame (960)`,crop:`Object crop`,fullFrame:`Full frame`,fullFrameBoxed:`Full frame (boxed)`,faceCrop:`Face crop`,plateCrop:`Plate crop`,confirmationCrop:`Confirmation crop (what the gate saw)`,debugCrop:`Debug crop (why this decision)`,sceneFrame:`Scene frame (clean)`,lastSceneFrame:`Last frame (clean)`};function gt(e){return e in ht}function _t(e){return gt(e)?ht[e]:e}function vt(e,t){return`${e}${t}`}n();var yt=3e4;function bt(t){let[n,r]=c(null),i=e(e=>{r(t=>t??e)},[]);return u(()=>{t||r(null)},[t]),{publicOrigin:n,probes:t?l(xt,{onOrigin:i}):null}}function xt({onOrigin:e}){let{data:t}=w({capName:`network-access`});return l(o,{children:(t??[]).map(t=>l(St,{addonId:t.addonId,onOrigin:e},t.addonId))})}function St({addonId:e,onOrigin:t}){let{data:n}=ne({addonId:e},{refetchInterval:yt,retry:!1});return u(()=>{let e=n?Pe.safeParse(n):null,r=e?.success?e.data.endpoint?.url:void 0;if(r)try{t(new URL(r).origin)}catch{}},[n,t]),null}var W=typeof V==`function`,Ct=`Track flags arrive with the next server update`;function wt(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var Tt=W?V:wt;function Et(e){if(typeof e!=`object`||!e||!(`trackId`in e)||!(`markForTrain`in e)||!(`debug`in e)||!(`favourited`in e))return null;let{trackId:t,markForTrain:n,debug:r,favourited:i}=e;return typeof t!=`string`||typeof n!=`boolean`||typeof r!=`boolean`||typeof i!=`boolean`?null:{trackId:t,markForTrain:n,debug:r,favourited:i}}n();function Dt({label:e,hint:t,checked:n,disabled:i,title:a,icon:o,onToggle:s}){return r(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":e,disabled:i,title:a,onClick:s,className:`flex w-full items-center gap-2 rounded-md border px-2 py-1.5 text-left transition-colors disabled:opacity-50 ${n?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[l(`span`,{className:n?`text-primary`:`text-foreground-subtle`,children:o}),r(`span`,{className:`min-w-0 flex-1`,children:[l(`span`,{className:`block text-[11px] font-medium text-foreground`,children:e}),l(`span`,{className:`block text-[10px] text-foreground-subtle`,children:t})]}),l(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${n?`bg-primary`:`bg-border`}`,children:l(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${n?`translate-x-3`:``}`})})]})}function Ot({deviceId:e,trackId:t,markForTrain:n,debug:i,favourited:a,onChange:o}){let s=Tt(),u=ee(),[d,f]=c(null),p=d?.markForTrain??n===!0,m=d?.debug??i===!0,h=d?.favourited??a===!0,g=!W||s.isPending,_=W?void 0:Ct,v=n=>{g||(async()=>{try{let r=Et(await s.mutateAsync({deviceId:e,trackId:t,flags:n}));if(!r)return;f(r),o?.(r)}catch(e){let t=e instanceof Error?e.message:``;await u({title:`Could not update this track`,message:t===``?`Could not update this track. Check the server logs.`:t,variant:`danger`})}})()};return r(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[l(Dt,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:p,disabled:g,..._===void 0?{}:{title:_},icon:l(I,{className:`h-4 w-4`}),onToggle:()=>v({markForTrain:!p})}),l(Dt,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:m,disabled:g,..._===void 0?{}:{title:_},icon:l(ie,{className:`h-4 w-4`}),onToggle:()=>v({debug:!m})}),l(Dt,{label:`Favourited`,hint:`Keeps this track and its media past retention`,checked:h,disabled:g,..._===void 0?{}:{title:_},icon:l(T,{className:`h-4 w-4`}),onToggle:()=>v({favourited:!h})})]})}var G=100,kt=120,At={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},K=e=>e<0?0:e>1?1:e,q=e=>Math.round(e*100)/100;function jt(e,t){if(e.length<=t)return[...e];let n=(e.length-1)/(t-1),r=[];for(let i=0;i<t;i++)r.push(e[Math.round(i*n)]);return r[r.length-1]=e[e.length-1],r}function Mt(e,t,n){if(e.length===0||t===null)return At;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return At;let a=jt(e,n?.maxPoints??kt).map(e=>({x:q(K(e.x/r)*G),y:q(K(e.y/i)*G)})),o=a[0]??null,s=a[a.length-1]??null,c=a.length>=2?a.map(e=>`${e.x},${e.y}`).join(` `):``,l=(n?.snapshots??[]).map(e=>({x:q(K(e.x/r)*G),y:q(K(e.y/i)*G),mediaId:e.mediaId})),u=null,d=-1;for(let t of e){let e=K(t.bbox.w/r)*K(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:q(K(u.bbox.x/r)*G),y:q(K(u.bbox.y/i)*G),w:q(K(u.bbox.w/r)*G),h:q(K(u.bbox.h/i)*G)}:null}}var Nt=typeof ge==`function`,Pt=`Track deletion arrives with the next server update`;function Ft(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var It=Nt?ge:Ft;n();var Lt=15e3,Rt=f();function zt({url:e,label:t}){let{src:n,failed:r}=Ve(e);return n===null?l(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?l(g,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):l(H,{className:`h-4 w-4 animate-spin text-foreground-subtle opacity-70`})}):l(`img`,{src:n,alt:t,className:`h-full w-full object-cover`})}var Bt=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),Vt=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`,`sceneFrame`,`lastSceneFrame`]);function Ht(e){let[t,n]=c(null);return u(()=>{if(n(null),!e)return;let t=!1,r=new Image;return r.onload=()=>{t||n({width:r.naturalWidth,height:r.naturalHeight})},r.src=e,()=>{t=!0,r.onload=null}},[e]),t}function Ut({overlay:e,onPickSnapshot:t}){return!e.polyline&&!e.peakBox&&e.snapshots.length===0?null:r(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[e.peakBox&&l(`rect`,{x:e.peakBox.x,y:e.peakBox.y,width:e.peakBox.w,height:e.peakBox.h,fill:`none`,stroke:`var(--color-warning)`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),e.polyline&&l(`polyline`,{points:e.polyline,fill:`none`,stroke:`var(--color-info)`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),e.points.map((e,t)=>l(`circle`,{cx:e.x,cy:e.y,r:1,fill:`var(--color-info)`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),e.snapshots.map((e,n)=>l(`circle`,{cx:e.x,cy:e.y,r:1.9,fill:`var(--color-info)`,fillOpacity:.95,stroke:`var(--color-background)`,strokeWidth:.7,vectorEffect:`non-scaling-stroke`,className:t?`pointer-events-auto cursor-pointer`:void 0,onClick:t?n=>{n.stopPropagation(),t(e.mediaId)}:void 0,children:l(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${String(e.mediaId)}-${String(n)}`)),e.start&&l(`circle`,{cx:e.start.x,cy:e.start.y,r:2.4,fill:`var(--color-success)`,stroke:`var(--color-background)`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),e.end&&l(`circle`,{cx:e.end.x,cy:e.end.y,r:2.4,fill:`var(--color-danger)`,stroke:`var(--color-background)`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function J({label:e,value:t,mono:n}){return r(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[l(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),l(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function Wt({row:t,cameraName:n,deleteAvailable:a,onClose:s,onDeleted:d,onFlagsChanged:f}){let p=m(),h=ee(),_=he(),v=It(),b=t!==null,x=t?.deviceId??0,S=t?.trackId??``,w=t?.timestamp??0,T=t?.windowMs??0,{data:D}=ae({deviceId:x,trackId:S},{enabled:b}),{data:O}=de({trackId:S,deviceId:x},{enabled:b}),k=D?.bestEventId===void 0?void 0:Number(D.bestEventId),{data:M}=_e({ownerType:`object`,eventId:k??0,deviceId:x},{enabled:b&&k!==void 0&&Number.isFinite(k)}),{data:N}=A({deviceId:x},{enabled:b}),F=(N??[]).find(e=>e.addonId!==void 0)?.addonId,{data:I}=E({deviceId:x,since:w-Lt,until:w+T+Lt,provider:F??``},{enabled:b&&F!==void 0}),[L,te]=c(null),[ne,R]=c(!1),{publicOrigin:re,probes:ie}=bt(b);u(()=>{te(null)},[x,S]);let oe=i(()=>{let e=O??[],t=M??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[O,M]),z=L??oe,B=Ve(z?z.url:void 0),V=i(()=>{let e=new Set,t=[];for(let n of[...M??[],...O??[]])e.has(n.mediaId)||(e.add(n.mediaId),t.push(n));return t},[M,O]),se=i(()=>V.find(e=>Bt.has(e.kind))??null,[V]),le=Ht(Ve(se?se.url:void 0).src),ue=i(()=>Mt(D?.positions??[],le,{snapshots:(D?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaId:e.mediaId}))}),[D?.positions,D?.snapshots,le]),fe=e(e=>{let t=V.find(t=>t.mediaId===e);t&&te(t)},[V]);if(t===null)return null;let pe=B.src,me=z?.kind,ge=me!==void 0&&Vt.has(me)&&le!==null&&(D?.positions.length??0)>=2,U=I&&I.length>0?I[0]:null,ve=()=>{U&&(R(!0),(async()=>{try{let e=await p.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:U.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{h({title:`Clip unavailable`,message:`Could not resolve clip playback. Check the server logs.`,variant:`warning`})}finally{R(!1)}})())},ye=()=>{!a||v.isPending||(async()=>{if(await _({title:`Delete track`,message:`Delete this track and every image and clip captured for it? This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`}))try{await v.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),d()}catch{await h({title:`Delete failed`,message:`Failed to delete this track. Check the server logs.`,variant:`danger`})}})()},xe=Math.round(t.importance*100),Se=D?.importanceReason?`${String(xe)}% · ${D.importanceReason}`:`${String(xe)}%`,Ce=D?.zonesVisited&&D.zonesVisited.length>0?D.zonesVisited.join(`, `):`—`,Te=D?.audioLabels&&D.audioLabels.length>0?D.audioLabels:t.audioLabels&&t.audioLabels.length>0?t.audioLabels:void 0,Ee=Te===void 0?`—`:Te.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `),De=D?D.totalDistance.toFixed(2):`—`,ke=ct(D?.previewMissReason),je=Ae(D?D.firstSeen:w),Me=D?Ae(D.lastSeen):`—`;return l(be,{open:!0,onOpenChange:e=>!e&&s(),children:r(C,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Event detail`,className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[r(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[t.className,Ye(t)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,Ye(t)]}):null]}),l(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:n})]}),l(`button`,{type:`button`,onClick:s,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:l(ce,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[pe?l(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:l(Oe,{src:pe,alt:`Key frame from ${n}`,fit:`natural`,className:`w-full`,overlay:ge?l(Ut,{overlay:ue,onPickSnapshot:fe}):void 0})}):l(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:B.failed?r(o,{children:[l(g,{className:`h-8 w-8 opacity-60`}),l(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):l(H,{className:`h-6 w-6 animate-spin opacity-70`})}),V.length>0&&l(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:V.map(e=>{let t=_t(e.kind),n=vt(Rt,e.url),i=re?vt(re,e.url):null;return r(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[l(`button`,{type:`button`,onClick:()=>te(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${t} · ${Ae(e.timestamp)}`,children:l(zt,{url:e.url,label:t})}),r(`figcaption`,{className:`min-w-0 px-0.5`,children:[l(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:t,children:t}),l(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:Ae(e.timestamp),children:we(e.timestamp)})]}),l(mt,{localUrl:n,publicUrl:i})]},e.mediaId)})}),ie,U&&r(j,{variant:`secondary`,onClick:ve,disabled:ne,children:[ne?l(H,{className:`h-3.5 w-3.5 animate-spin`}):l(P,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),l(Ot,{deviceId:t.deviceId,trackId:t.trackId,...(D?.markForTrain??t.markForTrain)===void 0?{}:{markForTrain:D?.markForTrain??t.markForTrain},...(D?.debug??t.debug)===void 0?{}:{debug:D?.debug??t.debug},...(D?.favourited??t.favourited)===void 0?{}:{favourited:D?.favourited??t.favourited},onChange:f}),ke!==null&&r(`div`,{className:`rounded-lg border border-warning/40 bg-warning/8 px-3 py-2`,children:[l(`p`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Best shot`}),l(`p`,{className:`mt-0.5 text-xs text-foreground`,children:ke.sentence}),l(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:ke.raw})]}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[l(J,{label:`Camera`,value:n}),l(J,{label:`Class`,value:t.className}),l(J,{label:`Label`,value:t.label??`—`}),l(J,{label:`Sub-label`,value:t.subLabel??`—`}),l(J,{label:`Importance`,value:Se}),l(J,{label:`Zones visited`,value:Ce}),l(J,{label:`Audio heard`,value:Ee}),l(J,{label:`Total distance`,value:De}),l(J,{label:`First seen`,value:je}),l(J,{label:`Last seen`,value:Me}),l(J,{label:`Track`,value:t.trackId,mono:!0})]})]}),l(`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:l(`span`,{title:a?void 0:Pt,children:r(j,{variant:`secondary`,onClick:ye,disabled:!a||v.isPending,children:[v.isPending?l(H,{className:`h-3.5 w-3.5 animate-spin`}):l(y,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}var Gt={status:`debug.tape.status`,promote:`debug.tape.promote`,list:`debug.tape.list`,tracks:`debug.tape.tracks`,review:`debug.tape.review`,release:`debug.tape.release`,remove:`debug.tape.delete`},Kt={setRelation:`debug.gt.setRelation`,setPurity:`debug.gt.setPurity`,list:`debug.gt.list`},qt=p(`/addon/pipeline-analytics/tape-export`),Jt=10*6e4;function Yt(e){return`${qt}?tapeId=${encodeURIComponent(e)}`}var Xt=`The server answered in a shape this build does not understand.`;function Zt(e){return e instanceof Error?e.message:`The action failed.`}function Y(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function X(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Qt(e,t){if(!(t in e))return;let n=e[t];return n===null?null:typeof n==`number`&&Number.isFinite(n)?n:void 0}function Z(e,t){let n=e[t];return typeof n==`string`?n:null}function $t(e,t){let n=e[t];return typeof n==`boolean`?n:null}function en(e,t){if(!Array.isArray(e))return null;let n=[];for(let r of e){let e=t(r);if(e===null)return null;n.push(e)}return n}function tn(e){return e===`off`||e===`recording`||e===`refused`||e===`failing`||e===`unknown`}function nn(e){if(!Y(e))return null;let t=X(e,`deviceId`),n=e.state,r=X(e,`gapsSinceArmed`),i=Qt(e,`segmentsHeld`),a=Qt(e,`bytesLastHour`),o=Qt(e,`bytesHeld`);if(t===null||!tn(n)||r===null||i===void 0||a===void 0||o===void 0)return null;let s=Z(e,`reason`),c=X(e,`segmentOriginMs`),l=X(e,`framesPerMin`),u=X(e,`heldFromMs`),d=X(e,`heldToMs`),f=Z(e,`shelfError`);return{deviceId:t,state:n,gapsSinceArmed:r,segmentsHeld:i,bytesLastHour:a,bytesHeld:o,...s===null?{}:{reason:s},...c===null?{}:{segmentOriginMs:c},...l===null?{}:{framesPerMin:l},...u===null?{}:{heldFromMs:u},...d===null?{}:{heldToMs:d},...f===null?{}:{shelfError:f}}}function rn(e){return Y(e)?en(e.cameras,nn):null}function an(e){if(!Y(e))return null;let t=Z(e,`id`),n=X(e,`deviceId`),r=Z(e,`scenario`),i=e.lighting,a=X(e,`fromMs`),o=X(e,`toMs`),s=e.state,c=X(e,`frames`),l=X(e,`gaps`),u=X(e,`bytes`),d=$t(e,`reviewed`),f=$t(e,`released`),p=en(e.tracks,e=>typeof e==`string`?e:null),m=X(e,`tracksStillStored`);return t===null||n===null||r===null||i!==`day`&&i!==`ir`||a===null||o===null||s!==`complete`&&s!==`incomplete`||c===null||l===null||u===null||d===null||f===null||p===null||m===null?null:{id:t,deviceId:n,scenario:r,note:Z(e,`note`),lighting:i,fromMs:a,toMs:o,state:s,frames:c,gaps:l,bytes:u,reviewed:d,released:f,tracks:p,tracksStillStored:m}}function on(e){return Y(e)?en(e.tapes,an):null}function sn(e){if(!Y(e))return null;let t=Z(e,`trackId`),n=X(e,`firstT`),r=X(e,`lastT`),i=X(e,`boundFrames`),a=Z(e,`cls`),o=$t(e,`stillStored`);return t===null||n===null||r===null||i===null||a===null||o===null?null:{trackId:t,firstT:n,lastT:r,boundFrames:i,cls:a,stillStored:o}}function cn(e){if(!Y(e))return null;let t=Z(e,`tapeId`),n=X(e,`deviceId`),r=X(e,`fromMs`),i=X(e,`toMs`),a=$t(e,`reviewed`),o=en(e.lanes,sn);return t===null||n===null||r===null||i===null||a===null||o===null?null:{tapeId:t,deviceId:n,fromMs:r,toMs:i,reviewed:a,lanes:o}}function ln(e){if(!Y(e))return null;if(e.ok===!1){let t=Z(e,`reason`),n=Z(e,`detail`);return t===null||n===null?null:{ok:!1,reason:t,detail:n}}if(e.ok!==!0)return null;let t=Z(e,`tapeId`),n=e.state,r=X(e,`frames`),i=X(e,`gaps`),a=X(e,`pinnedTracks`),o=X(e,`bytes`);return t===null||n!==`complete`&&n!==`incomplete`||r===null||i===null||a===null||o===null?null:{ok:!0,tapeId:t,state:n,frames:r,gaps:i,pinnedTracks:a,bytes:o}}function un(e){if(!Y(e))return null;let t=e.status;if(t===`released`){let n=X(e,`unpinned`),r=$t(e,`pinsSettled`);return n===null||r===null?null:{status:t,unpinned:n,pinsSettled:r}}if(t===`already-released`||t===`not-found`)return{status:t};if(t===`unavailable`){let n=Z(e,`reason`);return n===null?null:{status:t,reason:n}}return null}function dn(e){if(!Y(e))return null;let t=e.status;if(t===`deleted`||t===`pins-owed`||t===`not-found`)return{status:t};if(t===`unavailable`){let n=Z(e,`reason`);return n===null?null:{status:t,reason:n}}return null}function fn(e){switch(e.status){case`released`:case`deleted`:return null;case`already-released`:return`This tape was already released.`;case`not-found`:return`That tape no longer exists — it may have been released or deleted elsewhere.`;case`pins-owed`:return`Refused: this tape still names pins not yet taken back. Try again shortly — the ledger settles them automatically.`;case`unavailable`:return`Unavailable on this node: ${e.reason}`}}function pn(e){if(!Y(e))return null;let t=Z(e,`leftTrackId`),n=Z(e,`rightTrackId`),r=e.relation,i=e.presence;return t===null||n===null||r!==`same-subject`&&r!==`different-subjects`?null:{leftTrackId:t,rightTrackId:n,relation:r,presence:i===`continuous`?`continuous`:null}}function mn(e){if(!Y(e))return null;let t=Z(e,`sourceTrackId`),n=e.purity;return t===null||n!==`mixed`&&n!==`not-a-subject`?null:{sourceTrackId:t,purity:n,switchAtMs:X(e,`switchAtMs`)}}function hn(e){if(!Y(e))return null;let t=en(e.relations,pn),n=en(e.purities,mn),r=$t(e,`truncated`);return t===null||n===null||r===null?null:{relations:t,purities:n,truncated:r}}function gn(e){if(!e.truncated)return null;let t=e.relations.length+e.purities.length;return`Showing the first ${String(t)} marks — more exist for this window.`}function _n(e){return e.filter(e=>e.segmentsHeld===null||e.segmentsHeld>0).map(e=>({deviceId:e.deviceId,segmentsUnknown:e.segmentsHeld===null}))}function vn(e){return e.slice(1).map((t,n)=>({trackId:e[n]??t,otherTrackId:t}))}function yn(e){return e.flatMap((t,n)=>e.slice(n+1).map(e=>({trackId:t,otherTrackId:e})))}function bn(e,t){let n=[];for(let r of t.relations){let t=r.leftTrackId===e?r.rightTrackId:r.rightTrackId===e?r.leftTrackId:null;if(t===null)continue;let i=r.relation===`same-subject`?`same as`:`different from`;n.push(`${i} ${t}${r.presence===`continuous`?` (continuous)`:``}`)}for(let r of t.purities)r.sourceTrackId===e&&n.push(r.purity===`not-a-subject`?`not a subject`:r.switchAtMs===null?`mixed`:`mixed at switch`);return n}function xn(e){switch(e.state){case`off`:return`Off`;case`recording`:return`Recording`;case`refused`:return`Refused: ${e.reason??`unknown reason`}`;case`failing`:return`Failing: ${e.reason??`unknown reason`}`;case`unknown`:return`Unknown: ${e.reason??`unknown reason`}`}}var Sn={"window-too-long":`A promoted window is at most 30 minutes.`,"window-in-future":`The window ends in the future.`,"window-not-recorded":`No segment covers that window — the camera was not recording then, or it is older than 24 h.`,"invalid-scenario":`The scenario must be a slug: lowercase letters, digits and dashes, 3–64 characters.`,"promotion-budget":`A promotion budget is full (60 tapes, 1 GiB, 3 000 pinned tracks). Release or delete a tape already committed as a case first.`,"empty-window":`No frame was recorded in that window.`,"shelf-unreadable":`The camera's recorded segments could not be listed, so the window cannot be proven whole.`,"not-post-processing-node":`This node does not post-process frames, so it records no tracking tapes.`,"artifacts-elsewhere":`The artifacts storage location is on another node; tapes are recorded only where it lives.`,"tapes-not-started":`The tape recorder has not started on this node (or failed to).`};function Cn(e,t){let n=Sn[e]??`Refused (${e}).`;return t.length>0?`${n} ${t}`:n}function wn(e){if(e.length===0)return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null}function Tn(e){return e<1024*1024?`${(e/1024).toFixed(0)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function En(e){return e===null?`unknown`:Tn(e)}function Dn(e){return e===null?`unknown`:String(e)}function On(e,t){let n=t.trim();return e===404?`This tape no longer exists on this node (unknown tape).`:e===503?n.length>0?n:`Tapes are unavailable on this node.`:e===500?n.length>0?n:`The export could not be read (the tape may have just been released or deleted).`:`Download failed (${String(e)}).`}n();function kn({cameras:e,call:t,onPromoted:n}){let[i,a]=c(``),[o,s]=c(``),[u,d]=c(``),[f,p]=c(``),[m,h]=c(``),[g,_]=c(`auto`),[v,y]=c(!1),[b,x]=c(null),S=async()=>{let r=Number.parseInt(i===``?e[0]?.value??``:i,10),a=wn(o),s=wn(u);if(!Number.isFinite(r)||a===null||s===null){x(`Pick a camera and both ends of the window.`);return}y(!0),x(null);try{let e=ln(await t(Gt.promote,{deviceId:r,fromMs:a,toMs:s,scenario:f,...m.trim().length>0?{note:m.trim()}:{},...g===`day`||g===`ir`?{lighting:g}:{}}));e===null?x(Xt):e.ok?(x(`Promoted ${e.tapeId}: ${String(e.frames)} frames, ${Tn(e.bytes)}, ${String(e.pinnedTracks)} tracks pinned`+(e.state===`incomplete`?` — incomplete (it has gaps) and cannot become a case.`:`.`)),n()):x(Cn(e.reason,e.detail))}catch(e){x(Zt(e))}finally{y(!1)}};return r(`div`,{className:`flex flex-wrap items-end gap-2 rounded-md border border-border px-3 py-2`,children:[l(`div`,{className:`w-40`,children:l(D,{value:i,options:[...e],onChange:e=>a(e.target.value),"aria-label":`Camera`})}),l(O,{type:`datetime-local`,"aria-label":`From`,value:o,onChange:e=>s(e.target.value),className:`w-48`}),l(O,{type:`datetime-local`,"aria-label":`To`,value:u,onChange:e=>d(e.target.value),className:`w-48`}),l(O,{"aria-label":`Scenario`,placeholder:`615-door-groups`,value:f,onChange:e=>p(e.target.value),className:`w-44`}),l(O,{"aria-label":`Note`,placeholder:`optional note`,value:m,onChange:e=>h(e.target.value),className:`w-52`}),l(`div`,{className:`w-28`,children:l(D,{value:g,"aria-label":`Lighting`,options:[{value:`auto`,label:`Lighting: auto`},{value:`day`,label:`day`},{value:`ir`,label:`ir`}],onChange:e=>_(e.target.value)})}),r(j,{onClick:()=>void S(),disabled:v||e.length===0,children:[v?l(H,{className:`h-3.5 w-3.5 animate-spin`}):null,` Promote window`]}),l(`p`,{className:`w-full text-xs text-foreground-subtle`,children:`A promoted tape may be shared as a test case — keep the scenario slug and note free of names or other personal data.`}),b!==null&&l(`p`,{className:`w-full text-xs text-foreground`,children:b})]})}var An=`pipeline-analytics`,jn=`debug.listTracks`,Mn=`debug.analyze`,Nn=p(`/addon/pipeline-analytics/debug-export`);function Pn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`string`?n:null}function $(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Fn(e,t){let n=e[t];return typeof n==`boolean`?n:null}function In(e){return e===`error`||e===`warn`||e===`info`}function Ln(e){if(!Pn(e))return null;let t=Q(e,`code`),n=Q(e,`detail`),r=e.severity;return t===null||n===null||!In(r)?null:{code:t,severity:r,detail:n}}function Rn(e){if(!Pn(e))return null;let t=Q(e,`trackId`),n=$(e,`deviceId`),r=Q(e,`className`),i=$(e,`firstSeen`),a=$(e,`lastSeen`),o=$(e,`durationMs`),s=Fn(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=Q(e,`label`),l=Q(e,`subLabel`),u=Q(e,`previewMissReason`),d=Fn(e,`markForTrain`),f=Fn(e,`favourited`);return{trackId:t,deviceId:n,className:r,...c===null?{}:{label:c},...l===null?{}:{subLabel:l},firstSeen:i,lastSeen:a,durationMs:o,active:s,timestamp:i,windowMs:o,importance:$(e,`importance`)??0,bestEventId:Q(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function zn(e){let t=Rn(e);if(t===null||!Pn(e))return null;let n=$(e,`mediaCount`),r=$(e,`eventCount`),i=$(e,`positionCount`);if(n===null||r===null||i===null)return null;let a=e.mediaKinds,o=e.findings;if(!Array.isArray(a)||!Array.isArray(o))return null;let s=a.filter(e=>typeof e==`string`),c=[];for(let e of o){let t=Ln(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...it(l)?{thumbnailProvenance:l}:{}}}function Bn(e){if(!Pn(e))return null;let t=Fn(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=Rn(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function Vn(e){if(!Pn(e))return null;let t=e.reports,n=e.vanished;if(!Array.isArray(t)||!Array.isArray(n))return null;let r=[];for(let e of t){let t=zn(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var Hn={MEDIA_EVICTED_OR_NEVER:`no media`,MISSING_KEYFRAME:`no keyframe`,MISSING_FIRSTFRAME:`no first frame`,MISSING_LASTFRAME:`no last frame`,MISSING_THUMBNAIL:`no thumbnail`,MISSING_BEST_CROP:`no crop`,SHORT_TRACK:`very short`,ZERO_EVENTS:`no events`,ZERO_POSITIONS:`no trajectory`,NO_PERIODIC_SNAPSHOTS:`no snapshots`,LASTFRAME_STALE:`stale last frame`,MEDIA_STOPPED_EARLY:`media stopped early`,NO_BEST_EVENT:`no best event`,LOW_BEST_SCORE:`low score`,UNSCORED_LABEL:`unscored label`,BEST_SHOT_STANDIN:`stand-in best shot`,BEST_SHOT_RASTER:`low-res best shot`};function Un(e){return Hn[e]??e}var Wn={error:0,warn:1,info:2};function Gn(e){return e.toSorted((e,t)=>Wn[e.severity]-Wn[t.severity]||e.code.localeCompare(t.code))}function Kn(e){return e.length===0?Nn:`${Nn}?deviceIds=${e.join(`,`)}`}function qn(e){if(e<1e4)return`${(e/1e3).toFixed(1)}s`;let t=Math.round(e/1e3);if(t<60)return`${String(t)}s`;let n=Math.floor(t/60);return`${String(n)}m ${String(t%60).padStart(2,`0`)}s`}function Jn(e,t){return`${String(e)}:${t}`}function Yn(e,t){let n=[],r=new Set;for(let i of e){let e=Jn(i.deviceId,i.trackId);!t.has(e)||r.has(e)||(r.add(e),n.push({deviceId:i.deviceId,trackId:i.trackId}))}return n}n();function Xn({tapeId:e,call:t,onClose:n,onChanged:i}){let o=a({queryKey:[`events-debug`,`tapes`,`tracks`,e],queryFn:async()=>cn(await t(Gt.tracks,{tapeId:e}))}),s=o.data??null,u=a({queryKey:[`events-debug`,`tapes`,`marks`,e],enabled:s!==null,queryFn:async()=>s===null?null:hn(await t(Kt.list,{deviceId:s.deviceId,since:s.fromMs-Jt,until:s.toMs+Jt,limit:5e3}))}),[d,f]=c([]),[p,m]=c(``),[h,g]=c(null),_=e=>f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),v=async e=>{g(null);try{for(let[n,r]of e)await t(n,r);f([]),await u.refetch(),i()}catch(e){g(Zt(e))}};if(s===null)return o.isLoading?l(`p`,{className:`text-xs`,children:`Loading the tape…`}):l(F,{message:Xt});let y=s.deviceId,b=(e,t)=>v(e.map(e=>[Kt.setRelation,{deviceId:y,...e,relation:t}])),x=e=>{let t=Number.parseFloat(p),n=e===`mixed`&&Number.isFinite(t)?s.fromMs+t*1e3:void 0;return v(d.map(t=>[Kt.setPurity,{deviceId:y,trackId:t,purity:e,...n===void 0?{}:{switchAtMs:Math.round(n)}}]))},S=u.data==null?null:gn(u.data);return r(`div`,{className:`space-y-2 rounded-md border border-primary/40 px-3 py-2`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[r(`span`,{className:`text-xs font-medium`,children:[s.tapeId,` — `,String(s.lanes.length),` tracks`]}),l(j,{disabled:d.length<2,onClick:()=>void b(vn(d),`same-subject`),children:`Same subject`}),l(j,{variant:`secondary`,disabled:d.length<2,onClick:()=>void b(yn(d),`different-subjects`),children:`Different subjects`}),l(O,{"aria-label":`Changed at (s from tape start)`,placeholder:`changed at s`,value:p,onChange:e=>m(e.target.value),className:`w-28`}),l(j,{variant:`secondary`,disabled:d.length!==1,onClick:()=>void x(`mixed`),children:`Mixed`}),l(j,{variant:`secondary`,disabled:d.length===0,onClick:()=>void x(`not-a-subject`),children:`Not a subject`}),l(j,{variant:s.reviewed?`secondary`:`primary`,onClick:()=>void v([[Gt.review,{tapeId:s.tapeId,reviewed:!s.reviewed}]]).then(()=>o.refetch()),children:s.reviewed?`Mark not reviewed`:`Mark reviewed`}),l(j,{variant:`ghost`,onClick:n,children:`Close`})]}),h!==null&&l(F,{message:h}),S!==null&&l(F,{variant:`warning`,message:S}),l(`ul`,{className:`space-y-1`,children:s.lanes.toSorted((e,t)=>e.firstT-t.firstT).map(e=>l(Zn,{lane:e,marks:u.data===null||u.data===void 0?[]:bn(e.trackId,u.data),selected:d.includes(e.trackId),onToggle:()=>_(e.trackId)},e.trackId))})]})}function Zn({lane:e,marks:t,selected:n,onToggle:i}){let{src:a}=Ve(e.stillStored?He(`track`,e.trackId):void 0);return r(`li`,{className:`flex items-center gap-2 text-xs`,children:[l(`input`,{type:`checkbox`,"aria-label":`select ${e.trackId}`,checked:n,onChange:i}),a===null?l(`div`,{className:`h-10 w-10 rounded bg-surface-hover`}):l(`img`,{src:a,alt:e.trackId,className:`h-10 w-10 rounded object-cover`}),l(`span`,{className:`font-mono`,children:e.trackId}),l(`span`,{children:e.cls}),r(`span`,{className:`text-foreground-subtle`,children:[qn(e.firstT),` → `,qn(e.lastT),` · `,String(e.boundFrames),` `,`frames`]}),!e.stillStored&&l(`span`,{className:`text-foreground-subtle`,children:`not stored — marked through the tape`}),t.map(e=>l(U,{variant:`info`,children:e},e))]})}n();var Qn=`camstack_admin_token`;function $n(){let e=m();return(t,n)=>e.trpcClient.addons.custom.mutate({addonId:An,action:t,input:n})}async function er(e,t){let n=localStorage.getItem(Qn),r={};n!==null&&(r.Authorization=`Bearer ${n}`);let i=await fetch(Yt(e),{headers:r});if(!i.ok){let e=await i.text().catch(()=>``);throw Error(On(i.status,e))}let a=await i.blob(),o=i.headers.get(`content-disposition`),s=(o===null?null:/filename="?([^";]+)"?/i.exec(o))?.[1]?.trim()??t,c=URL.createObjectURL(a),l=document.createElement(`a`);l.href=c,l.download=s,l.click(),setTimeout(()=>URL.revokeObjectURL(c),6e4)}function tr(){let[e,t]=c(!1);return l(oe,{expanded:e,onExpandedChange:t,header:l(`span`,{className:`text-sm font-medium text-foreground`,children:`Tracking tapes`}),children:l(nr,{})})}function nr(){let e=$n(),t=ue({isCamera:!0,projection:`slim`}),n=i(()=>{let e=new Map;for(let n of t.data??[])e.set(n.id,n.name);return t=>e.get(t)??`Camera ${String(t)}`},[t.data]),o=a({queryKey:[`events-debug`,`tapes`,`status`],queryFn:async()=>rn(await e(Gt.status,{}))}),s=a({queryKey:[`events-debug`,`tapes`,`list`],queryFn:async()=>on(await e(Gt.list,{}))}),[u,d]=c(null),[f,p]=c(null),m=async e=>{p(null);try{await er(e.id,`${e.scenario}.tape-bundle.json.gz`)}catch(e){p(Zt(e))}},h=async t=>{let n=un(await e(Gt.release,{tapeId:t.id}));if(n===null)throw Error(Xt);let r=fn(n);if(r!==null)throw Error(r);await s.refetch()},g=async t=>{let n=dn(await e(Gt.remove,{tapeId:t.id}));if(n===null)throw Error(Xt);let r=fn(n);if(r!==null)throw Error(r);await s.refetch()};return r(`div`,{className:`space-y-3`,children:[r(`p`,{className:`text-xs text-foreground-subtle`,children:[`A camera records while its `,l(`strong`,{children:`Record the track history`}),` switch (camera settings → Tracking) is on; segments are kept 24 h. Promote a window worth keeping, label it in the review, mark it reviewed, download it and turn it into a test case with`,` `,l(`code`,{children:`npm run tracking-bench -- case`}),`.`]}),f!==null&&l(F,{message:f}),o.isLoading&&l(`p`,{className:`text-xs text-foreground-subtle`,children:`Loading camera status…`}),o.data===null&&l(F,{message:`The server answered in a shape this build does not understand.`}),r(`table`,{className:`w-full text-xs`,children:[l(`thead`,{children:r(`tr`,{className:`text-left text-foreground-subtle`,children:[l(`th`,{children:`Camera`}),l(`th`,{children:`State`}),l(`th`,{children:`Frames/min`}),l(`th`,{children:`Last hour`}),l(`th`,{children:`Held`}),l(`th`,{children:`Gaps`})]})}),l(`tbody`,{children:(o.data??[]).map(e=>r(`tr`,{children:[l(`td`,{children:n(e.deviceId)}),l(`td`,{children:l(U,{variant:e.state===`recording`?`success`:e.state===`off`?`default`:e.state===`unknown`?`warning`:`danger`,children:xn(e)})}),l(`td`,{children:e.framesPerMin===void 0?`—`:String(Math.round(e.framesPerMin))}),l(`td`,{title:e.shelfError,children:En(e.bytesLastHour)}),r(`td`,{title:e.shelfError,children:[Dn(e.segmentsHeld),` seg · `,En(e.bytesHeld)]}),l(`td`,{children:String(e.gapsSinceArmed)})]},e.deviceId))})]}),l(kn,{cameras:_n(o.data??[]).map(e=>({value:String(e.deviceId),label:e.segmentsUnknown?`${n(e.deviceId)} (segments unknown)`:n(e.deviceId)})),call:e,onPromoted:()=>void s.refetch()}),s.isLoading&&l(`p`,{className:`text-xs text-foreground-subtle`,children:`Loading promoted tapes…`}),s.data===null&&l(F,{message:`The server answered in a shape this build does not understand.`}),r(`table`,{className:`w-full text-xs`,children:[l(`thead`,{children:r(`tr`,{className:`text-left text-foreground-subtle`,children:[l(`th`,{children:`Scenario`}),l(`th`,{children:`Camera`}),l(`th`,{children:`Window`}),l(`th`,{children:`State`}),l(`th`,{children:`Tracks`}),l(`th`,{})]})}),l(`tbody`,{children:(s.data??[]).map(e=>r(`tr`,{children:[l(`td`,{children:e.scenario}),l(`td`,{children:n(e.deviceId)}),r(`td`,{children:[new Date(e.fromMs).toLocaleString(),` · `,qn(e.toMs-e.fromMs),` `,`· `,e.lighting]}),r(`td`,{children:[l(U,{variant:e.state===`complete`?`success`:`warning`,children:e.state}),` `,e.reviewed&&l(U,{variant:`info`,children:`reviewed`}),` `,e.released&&l(U,{children:`released`})]}),r(`td`,{children:[String(e.tracksStillStored),`/`,String(e.tracks.length),` stored`]}),r(`td`,{className:`space-x-1 text-right`,children:[l(j,{variant:`secondary`,"aria-label":`Review ${e.scenario}`,onClick:()=>d(e.id),children:`Review`}),l(j,{variant:`ghost`,"aria-label":`Download ${e.scenario}`,onClick:()=>void m(e),children:l(xe,{className:`h-3.5 w-3.5`})}),l(le,{label:`Release`,icon:se,title:`Release ${e.scenario}?`,description:`Releasing returns this tape's pinned tracks to ordinary retention — they can be pruned from then on. The promoted bundle itself is kept until deleted.`,confirmLabel:`Release`,triggerVariant:`ghost`,confirmVariant:`danger`,disabled:e.released,action:()=>h(e)}),l(le,{label:`Delete`,icon:y,title:`Delete ${e.scenario}?`,description:`Deleting removes the promoted bundle and its index row for good. Its tracks' pins are released first — this cannot be undone.`,confirmLabel:`Delete`,triggerVariant:`ghost`,confirmVariant:`danger`,action:()=>g(e)})]})]},e.id))})]}),u!==null&&l(Xn,{tapeId:u,call:e,onClose:()=>d(null),onChanged:()=>void s.refetch()})]})}n();var rr=`all`,ir=`The server answered in a shape this build does not understand.`,ar={error:`danger`,warn:`warning`,info:`info`};function or({findings:e}){return e.length===0?l(U,{variant:`success`,children:`no anomaly found`}):l(`div`,{className:`flex flex-wrap gap-1`,children:Gn(e).map(e=>l(U,{variant:ar[e.severity],title:e.detail,children:Un(e.code)},e.code))})}function sr({track:e,report:t,analyzing:n}){let i=ct(t?.previewMissReason??e.previewMissReason);return r(`div`,{className:`space-y-1 border-t border-border pt-1.5`,children:[t===void 0?l(`span`,{className:`text-[10px] text-foreground-subtle`,children:n?`analysing…`:`not analysed`}):r(o,{children:[l(or,{findings:t.findings}),r(`p`,{className:`text-[10px] text-foreground-subtle`,title:t.mediaKinds.length>0?t.mediaKinds.join(`, `):`no media of any kind`,children:[String(t.mediaCount),` media · `,String(t.eventCount),` events ·`,` `,String(t.positionCount),` positions`]})]}),i!==null&&l(`p`,{className:`text-[10px] text-foreground-subtle`,title:i.raw,children:i.sentence})]})}function cr(){let e=m(),[t,n]=c(rr),[o,s]=c(!1),[u,d]=c(null),[f,p]=c(new Set),[h,g]=c(null),[_,v]=c(null),[y,b]=c(null),[x,C]=c([]),w=Tt(),E=ue({isCamera:!0,projection:`slim`}),O=i(()=>[{value:rr,label:`All cameras`},...(E.data??[]).map(e=>({value:String(e.id),label:e.name}))],[E.data]),k=i(()=>{let e=new Map;for(let t of E.data??[])e.set(t.id,t.name);return e},[E.data]),A=e=>k.get(e)??`Camera ${String(e)}`,M=i(()=>t===rr?[]:[Number.parseInt(t,10)],[t]),N=a({queryKey:[`events-debug`,`list`,M],queryFn:async()=>Bn(await e.trpcClient.addons.custom.mutate({addonId:An,action:jn,input:M.length===0?{}:{deviceIds:M}}))}),ee=i(()=>(N.data?.tracks??[]).map(e=>e.trackId),[N.data]),P=a({queryKey:[`events-debug`,`analyze`,ee],enabled:ee.length>0,queryFn:async()=>Vn(await e.trpcClient.addons.custom.mutate({addonId:An,action:Mn,input:{trackIds:ee}}))}),I=i(()=>{let e=new Map;for(let t of P.data?.reports??[])e.set(t.trackId,t);return e},[P.data]),L=N.data?.tracks??[],te=N.data===null||P.data===null,ne=()=>{N.refetch(),P.refetch()},ae=e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},oe=()=>{p(new Set(L.map(e=>Jn(e.deviceId,e.trackId))))},z=()=>p(new Set),B=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await w.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},V=e=>{if(!W||_!==null)return;let t=Yn(L,f);t.length!==0&&(v(e),b(null),(async()=>{let n=await B(e,t);v(null);let r=new Set(n.refused);p(new Set(t.filter(e=>r.has(e.trackId)).map(e=>Jn(e.deviceId,e.trackId)))),e===`analyzed`&&C(t.filter(e=>!r.has(e.trackId))),n.refused.length>0&&b(`${String(n.refused.length)} of ${String(t.length)} were refused by the server and are still selected. Check the hub log.`),N.refetch()})())},se=()=>{let e=x;e.length===0||_!==null||(v(`analyzed`),b(null),(async()=>{for(let t of e)try{await w.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,flags:{debug:!0}})}catch{b(`Some tracks could not be re-marked. Refresh and try again.`)}v(null),C([]),N.refetch()})())},le=async()=>{s(!0),d(null);try{await We(Kn(M),`camstack-debug.zip`)}catch(e){d(e instanceof Error?e.message:`Export failed.`)}finally{s(!1)}},de=_!==null;return l(Be,{children:r(`section`,{className:`space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[l(`div`,{className:`w-44`,children:l(D,{value:t,options:O,onChange:e=>n(e.target.value)})}),r(j,{variant:`secondary`,onClick:ne,disabled:N.isFetching,children:[N.isFetching?l(H,{className:`h-3.5 w-3.5 animate-spin`}):l(R,{className:`h-3.5 w-3.5`}),`Refresh`]}),r(j,{onClick:()=>void le(),disabled:o||L.length===0,children:[o?l(H,{className:`h-3.5 w-3.5 animate-spin`}):l(xe,{className:`h-3.5 w-3.5`}),`Export all (`,String(L.length),`)`]}),L.length>0&&f.size<L.length&&l(j,{variant:`ghost`,onClick:oe,children:`Select all`})]}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`A `,l(`code`,{children:`debug`}),` mark does not pin retention — this lists the marked tracks that still exist. A track whose media was evicted shows as missing media. Use `,l(`strong`,{children:`Keep`}),` `,`to hold a selection against pruning while you investigate, and `,l(`strong`,{children:`Analyzed`}),` `,`to un-mark the ones you are finished with.`]}),l(tr,{}),N.isError&&l(F,{message:`Could not load the marked tracks.`}),te&&!N.isError&&l(F,{message:ir}),u!==null&&l(F,{message:u}),y!==null&&l(F,{message:y}),N.data?.truncated===!0&&l(F,{message:`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`}),(P.data?.vanished.length??0)>0&&r(`p`,{className:`text-xs text-foreground-subtle`,children:[String(P.data?.vanished.length),` marked track(s) were evicted between the list and the analysis.`]}),f.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[String(f.size),` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[l(`span`,{title:W?void 0:`Track flags arrive with the next server update`,children:r(j,{variant:`secondary`,onClick:()=>V(`keep`),disabled:!W||de,children:[_===`keep`?l(H,{className:`h-3.5 w-3.5 animate-spin`}):l(T,{className:`h-3.5 w-3.5`}),` `,`Keep`]})}),l(`span`,{title:W?void 0:`Track flags arrive with the next server update`,children:r(j,{onClick:()=>V(`analyzed`),disabled:!W||de,children:[_===`analyzed`?l(H,{className:`h-3.5 w-3.5 animate-spin`}):l(fe,{className:`h-3.5 w-3.5`}),` `,`Analyzed`]})}),l(j,{variant:`ghost`,onClick:z,disabled:de,children:l(ce,{className:`h-3.5 w-3.5`})})]})]}),x.length>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-border bg-surface px-3 py-2`,children:[r(`span`,{className:`text-xs text-foreground`,children:[String(x.length),` track(s) marked analyzed and removed from this list.`]}),r(j,{variant:`ghost`,onClick:se,disabled:de,children:[l(re,{className:`h-3.5 w-3.5`}),` Undo`]}),l(j,{variant:`ghost`,onClick:()=>C([]),disabled:de,children:l(ce,{className:`h-3.5 w-3.5`})})]}),N.isLoading?l(S,{children:l(`div`,{className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`Loading…`})}):L.length===0?l(S,{children:r(`div`,{className:`flex flex-col items-center gap-2 px-3 py-8 text-center`,children:[l(ie,{className:`h-5 w-5 text-foreground-subtle`}),l(`p`,{className:`text-xs text-foreground-subtle`,children:`No track is marked for debug. Mark one from a track's actions to see it here.`})]})}):l(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:L.map(e=>{let t=I.get(e.trackId);return l(ut,{row:e,cameraName:A(e.deviceId),nowMs:e.lastSeen,selected:f.has(Jn(e.deviceId,e.trackId)),onToggleSelect:ae,onOpenDetail:g,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:l(sr,{track:e,report:t,analyzing:P.isFetching})},Jn(e.deviceId,e.trackId))})}),h&&l(Wt,{row:h,cameraName:A(h.deviceId),deleteAvailable:Nt,onClose:()=>g(null),onDeleted:()=>{g(null),N.refetch()},onFlagsChanged:e=>{e.debug||(g(null),N.refetch())}})]})})}var lr=200,ur=3e4,dr=[];function fr(e){let t=m(),n=e.deviceIds.length>0,r=[...e.deviceIds].sort((e,t)=>e-t),{data:i,isLoading:o}=a({queryKey:[`events-feed`,r,e.since,e.until,e.minImportance??null,e.classFilter??null],enabled:n,staleTime:ur,refetchInterval:ur,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEventsBatch.query({deviceIds:r,since:e.since,until:e.until,limit:lr,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>e.events.map(t=>({...t,deviceId:e.deviceId})))});return{rows:Qe(Ze(i??dr),`importance`),isLoading:n&&o}}n();var pr=[`events-feed`],mr=2e3;function hr(n){let r=s(),i=n?.paused===!0,a=t(r);a.current=r;let o=t(i);o.current=i;let[l,d]=c(!1),f=e(()=>{a.current.invalidateQueries({queryKey:pr})},[]),p=t(void 0);p.current||=Ne({delayMs:mr,invalidate:()=>{o.current?d(!0):f()}}),u(()=>()=>p.current?.cancel(),[]),u(()=>{i||!l||(d(!1),f())},[i,l,f]);let m=e(()=>{d(!1),f()},[f]);return ve(Fe.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),ve(Fe.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:l,refreshNow:m}}n();function gr({groups:e,selected:t,onChange:n,loading:a=!1}){let{t:o}=Ie(),[s,u]=c(!1),[d,f]=c(``),[p,m]=c(new Set),h=d.trim().toLowerCase(),g=e=>h.length===0||x(e,o).toLowerCase().includes(h),y=i(()=>e.map(e=>({macro:e.macro,subs:e.subs.filter(t=>g(t)||g(e.macro))})).filter(e=>g(e.macro)||e.subs.length>0),[e,h]),b=e=>m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),S=e=>{let r=new Set(t),i=t.has(e.macro.kind)&&e.subs.every(e=>t.has(e.kind)),a=[e.macro.kind,...e.subs.map(e=>e.kind)];if(i)for(let e of a)r.delete(e);else for(let e of a)r.add(e);n(r)},C=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},w=()=>n(new Set),T=t.size;return r(`div`,{className:`relative`,children:[r(`button`,{type:`button`,onClick:()=>u(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${T>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[l(ye,{className:`h-3.5 w-3.5`}),T>0?`Kinds (${String(T)})`:`Kinds`,l(_,{className:`h-3 w-3`})]}),s&&r(`div`,{className:`absolute z-20 mt-1 max-h-80 w-64 overflow-auto rounded-md border border-border bg-surface p-2 shadow-lg`,children:[r(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[l(k,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`Search kinds…`,className:`w-full bg-transparent py-1 text-xs outline-none`}),T>0&&l(`button`,{type:`button`,onClick:w,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),y.length===0&&l(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:a?`Loading kinds…`:h.length>0?`No kind matches that search.`:`These cameras advertise no event kinds.`}),y.map(e=>{let n=B(e.macro.iconId),i=p.has(e.macro.kind)||h.length>0,a=t.has(e.macro.kind);return r(`div`,{className:`mb-0.5`,children:[r(`div`,{className:`flex items-center gap-1`,children:[e.subs.length>0?l(`button`,{type:`button`,onClick:()=>b(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:l(i?_:v,{className:`h-3 w-3`})}):l(`span`,{className:`w-3`}),r(`label`,{className:`flex flex-1 cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[l(`input`,{type:`checkbox`,checked:a,onChange:()=>S(e),className:`accent-primary`}),l(n,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),l(`span`,{className:`font-medium`,children:x(e.macro,o)})]})]}),i&&e.subs.map(e=>{let n=B(e.iconId);return r(`label`,{className:`ml-5 flex cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[l(`input`,{type:`checkbox`,checked:t.has(e.kind),onChange:()=>C(e.kind),className:`accent-primary`}),l(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),l(`span`,{children:x(e,o)})]},e.kind)})]},e.macro.kind)})]})]})}function _r(e,t){let n=new Map;for(let r of e)if(!(t.size>0&&!t.has(r.deviceId)))for(let e of r.kinds)n.has(e.kind)||n.set(e.kind,e);return n}function vr(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var yr=new Set([`detection`,`package`]);function br(e,t){return[..._r(e,t).values()].filter(e=>e.parentKind===null&&yr.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function xr(e,t){let n=_r(e,t),r=new Map,i=new Map;for(let e of n.values()){if(e.parentKind===null){i.set(e.kind,e);continue}let t=r.get(e.parentKind);t===void 0?r.set(e.parentKind,[e]):t.push(e)}for(let[e,t]of r){if(i.has(e))continue;let n=t[0];n!==void 0&&i.set(e,vr(e,n))}return[...i.values()].map(e=>({macro:e,subs:[...r.get(e.kind)??[]].sort((e,t)=>e.label.localeCompare(t.label))})).sort((e,t)=>e.macro.label.localeCompare(t.macro.label))}n();function Sr(){let[n,r]=c(!1),i=t(null),[a,o]=c(0),s=e(e=>{i.current!==e&&(i.current=e,o(e=>e+1))},[]);return u(()=>{let e=i.current;if(!e||typeof IntersectionObserver>`u`){r(!1);return}let t=new IntersectionObserver(e=>{let t=e[e.length-1];t&&r(!t.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return t.observe(e),()=>t.disconnect()},[a]),{ref:s,scrolledPast:n}}n();var Cr=[`events-feed`],wr=60,Tr=[{value:`importance`,label:`Importance`,icon:qe},{value:`time`,label:`Recent`,icon:N}];function Er(){let e=s(),t=ee(),n=he(),[a,d]=c(Me),[f,p]=c(new Set),[m,h]=c(new Set),[g,_]=c(0),[v,b]=c(`time`),[x,S]=c(new Set),[C,w]=c(null),[T,E]=c(()=>Date.now());u(()=>{let e=setInterval(()=>E(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:D,until:O}=i(()=>nt({fromMs:a.fromMs,toMs:a.toMs},T),[a.fromMs,a.toMs,T]),k=Sr(),{pending:A,refreshNow:M}=hr({paused:C!==null||x.size>0||k.scrolledPast}),{data:N=[]}=ue({isCamera:!0,projection:`slim`}),P=i(()=>N.map(e=>e.id),[N]),{data:F,isLoading:I}=pe({deviceIds:P},{enabled:P.length>0,staleTime:5*6e4}),L=i(()=>xr(F??[],f),[F,f]),te=It(),ne=te.isPending,{rows:R,isLoading:re}=fr({deviceIds:P,since:D,until:O,minImportance:g>0?g:void 0,classFilter:m.size===1?[...m][0]:void 0}),ie=i(()=>{let e=new Map;for(let t of N??[])e.set(t.id,t.name);return e},[N]),ae=e=>ie.get(e)??`Camera #${String(e)}`,oe=i(()=>Ce(R).map(e=>({id:e,name:ae(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[R,ie]),z=i(()=>Qe($e(R,{cameras:f,classes:m,minImportance:g}),v),[R,f,m,g,v]),B=ke(z,wr,i(()=>JSON.stringify([[...f].sort((e,t)=>e-t),[...m].sort(),g,v,D,O]),[f,m,g,v,D,O])),V=()=>{e.invalidateQueries({queryKey:Cr})},se=()=>S(new Set);function le(e){S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function de(){if(x.size===0||!Nt)return;let e=tt(R,x),t=[...e.values()].reduce((e,t)=>e+t.length,0);t!==0&&(async()=>{await n({title:`Delete ${String(t)} track${t===1?``:`s`}`,message:`Delete ${String(t)} track${t===1?``:`s`} and every image and clip captured for ${t===1?`it`:`them`}? This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&fe(e)})()}function fe(e){let n=[...e];Promise.allSettled(n.map(([e,t])=>te.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{V();let r=[],i=new Set;e.forEach((e,t)=>{let a=n[t];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)i.add(et(o,e));else r.push(o)}),S(e=>{let t=new Set(e);for(let e of i)t.delete(e);return t}),r.length>0&&t({title:`Some tracks were not deleted`,message:`Failed to delete tracks on: ${r.map(e=>ae(e)).join(`, `)}. They remain selected — retry, or check the server logs.`,variant:`danger`})})}let me=z.length!==R.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[l(je,{onChange:d}),l(Ee,{cameras:oe,selected:f,onChange:p}),l(gr,{groups:L,selected:m,onChange:h,loading:I}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[l(`span`,{children:`Min score`}),l(`input`,{type:`range`,min:0,max:1,step:.05,value:g,onChange:e=>_(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":`Minimum importance`}),l(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(g*100)})]}),l(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Tr.map(e=>{let t=e.icon;return r(`button`,{type:`button`,onClick:()=>b(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${v===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[l(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!re&&l(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:me?`${String(z.length)} of ${String(R.length)} events`:`${String(z.length)} event${z.length===1?``:`s`}`})]}),x.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[x.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[l(`span`,{title:Nt?void 0:`Track deletion arrives with the next server update`,children:r(j,{variant:`secondary`,onClick:de,disabled:!Nt||ne,children:[ne?l(H,{className:`h-3.5 w-3.5 animate-spin`}):l(y,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),l(j,{variant:`ghost`,onClick:se,disabled:ne,children:l(ce,{className:`h-3.5 w-3.5`})})]})]}),re&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[l(H,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!re&&z.length===0&&l(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),A&&l(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:l(`button`,{type:`button`,onClick:M,className:`rounded-full border border-primary/40 bg-surface px-3 py-1 text-[11px] font-medium text-primary shadow-sm hover:bg-primary/10`,children:`New events — refresh`})}),!re&&z.length>0&&r(o,{children:[l(`div`,{ref:k.ref,"aria-hidden":!0,className:`h-0`}),l(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:B.pageItems.map(e=>l(ut,{row:e,cameraName:ae(e.deviceId),nowMs:T,selected:x.has(et(e.deviceId,e.trackId)),onToggleSelect:le,onOpenDetail:w},et(e.deviceId,e.trackId)))}),l(Se,{currentPage:B.page,totalItems:B.totalItems,pageSize:B.pageSize,onPageChange:B.setPage,itemNoun:`events`})]}),C&&l(Wt,{row:C,cameraName:ae(C.deviceId),deleteAvailable:Nt,onClose:()=>w(null),onDeleted:()=>{V(),w(null)},onFlagsChanged:e=>{w(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}var Dr=`/addon/training`;function Or(){let e=ze();return r(S,{className:`flex flex-col gap-3 border-border bg-surface p-3 sm:flex-row sm:items-center sm:gap-4`,"data-testid":`events-feed-retrain-cta`,children:[r(`div`,{className:`flex min-w-0 flex-1 items-start gap-2.5`,children:[l(I,{className:`mt-0.5 h-4 w-4 shrink-0 text-primary`,"aria-hidden":!0}),r(`div`,{className:`min-w-0 space-y-0.5`,children:[l(`p`,{className:`text-xs font-medium text-foreground`,children:`Training from this feed`}),l(`p`,{className:`${d} leading-relaxed`,children:`Mark a track with the graduation-cap control on its card. On Training you correct frames, build collections, and start cloud fine-tunes.`})]})]}),l(j,{variant:`outline`,size:`sm`,className:`shrink-0 self-start sm:self-center`,onClick:()=>e(Dr),children:`Open Training`})]})}n();var kr=50,Ar=350,jr=[{value:`loose`,label:`Loose`,title:`The search model's own floor`},{value:`balanced`,label:`Balanced`,title:`1.25× the search model's floor`},{value:`strict`,label:`Strict`,title:`1.5× the search model's floor`}];function Mr(e){let t=String(e.id);return{id:t,trackId:e.trackId??t,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,subLabel:e.subLabel,importance:e.importance??0,bestEventId:t,mediaId:e.keyFrameMediaId??e.mediaId,windowMs:void 0}}function Nr({onActiveChange:e}){let[t,n]=c(``),[a,o]=c(`loose`),[s,d]=c(null),[f,p]=c(null),[m,h]=c(null),g=me(t,Ar).trim(),_=g.length>0;u(()=>{e(_)},[_,e]);let[v,y]=c(()=>Date.now());u(()=>{let e=setInterval(()=>y(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:b=[]}=ue({isCamera:!0,projection:`slim`}),S=i(()=>{let e=new Map;for(let t of b)e.set(t.id,t.name);return e},[b]),C=e=>S.get(e)??`Camera #${String(e)}`,w=i(()=>b.map(e=>e.id),[b]),{data:T}=pe({deviceIds:w},{enabled:w.length>0,staleTime:5*6e4}),E=i(()=>br(T??[],new Set(f===null?[]:[f])),[T,f]);u(()=>{s!==null&&(E.some(e=>e.kind===s)||d(null))},[E,s]);let{data:D,isFetching:O,isError:A,error:j}=z({text:g,strictness:a,limit:kr,classFilter:s??void 0,deviceId:f??void 0},{enabled:_}),M=i(()=>[...D??[]].sort((e,t)=>t.score-e.score).map(e=>({...Mr(e),score:e.score})),[D]);function N(e){d(t=>t===e?null:e)}return r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(`div`,{className:`relative min-w-[16rem] flex-1`,children:[l(k,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),l(`input`,{type:`text`,value:t,onChange:e=>n(e.target.value),placeholder:`Semantic search — describe what you're looking for…`,className:`h-9 w-full rounded-md border border-border bg-background pl-8 pr-8 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":`Semantic event search`}),t&&l(`button`,{type:`button`,onClick:()=>n(``),className:`absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Clear search`,children:l(ce,{className:`h-3.5 w-3.5`})})]}),O&&_&&l(H,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[l(`div`,{className:`flex items-center gap-1`,children:E.map(e=>l(`button`,{type:`button`,onClick:()=>N(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${s===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:x(e)},e.kind))}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[l(`span`,{children:`Camera`}),r(`select`,{value:f===null?``:String(f),onChange:e=>p(e.target.value===``?null:Number(e.target.value)),className:`h-7 rounded-md border border-border bg-background px-1.5 text-xs text-foreground focus:border-primary focus:outline-none`,"aria-label":`Filter by camera`,children:[l(`option`,{value:``,children:`All`}),b.map(e=>l(`option`,{value:String(e.id),children:e.name},e.id))]})]}),r(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[l(`span`,{children:`Match`}),l(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:jr.map(e=>l(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${a===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:e.title,children:e.label},e.value))})]}),_&&!O&&!A&&r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[M.length,` match`,M.length===1?``:`es`]})]})]}),_&&r(`div`,{className:`space-y-3`,children:[A&&r(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,j instanceof Error?j.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!A&&O&&M.length===0&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[l(H,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!A&&!O&&M.length===0&&r(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:[`No semantic matches for “`,g,`”. Try a looser match threshold or a different phrasing.`]}),!A&&M.length>0&&l(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:M.map(e=>l(ut,{row:e,cameraName:C(e.deviceId),nowMs:v,score:e.score,onOpenDetail:h},e.id))})]}),m&&l(Wt,{row:m,cameraName:C(m.deviceId),deleteAvailable:Nt,onClose:()=>h(null),onDeleted:()=>h(null)})]})}n();function Pr(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return`just now`;if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function Fr({row:e,cameraName:t,nowMs:n}){let i=Ve(e.keyFrameMediaId===void 0?void 0:Ue(e.keyFrameMediaId));return r(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[r(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[i.src?l(`img`,{src:i.src,alt:`Parked ${e.className} on ${t}`,className:`h-full w-full object-cover`}):l(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:l(Je,{className:`h-6 w-6`})}),l(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:e.label??e.className})]}),r(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[l(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,Pr(n,e.becameStationaryAt)]})]})]})}function Ir(){let[e,t]=c(!1),n=Date.now(),{data:a=[]}=ue({isCamera:!0,projection:`slim`}),o=i(()=>a.map(e=>e.id),[a]),s=i(()=>{let e=new Map;for(let t of a)e.set(t.id,t.name);return e},[a]),{rows:u,unreadableCount:d}=Ge(o);return u.length===0&&d===0?null:r(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[r(`button`,{type:`button`,onClick:()=>t(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[l(e?_:v,{className:`h-4 w-4 text-foreground-subtle`}),l(Je,{className:`h-4 w-4 text-foreground-subtle`}),l(`span`,{className:`text-sm font-semibold text-foreground`,children:`Stationary`}),l(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:u.length}),l(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:`Parked objects — kept out of the event feed`}),d>0?r(`span`,{className:`ml-2 text-[11px] text-warning`,children:[d,` camera`,d===1?``:`s`,` could not be read`]}):null]}),e&&l(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:u.map(e=>l(Fr,{row:e,cameraName:s.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}n();function Lr(){let[e,t]=c(!1);return l(Be,{children:r(`section`,{className:`space-y-3`,children:[l(Or,{}),l(Nr,{onActiveChange:t}),!e&&l(Ir,{}),!e&&l(Er,{})]})})}function Rr(){let[e]=Le();return e.get(`tab`)===`retrain`?l(Re,{to:`/addon/training`,replace:!0}):l(`div`,{className:`flex flex-col p-4`,children:l(Ke,{tabs:[{id:`feed`,label:`Feed`,icon:L,content:l(Lr,{})},{id:`debug`,label:`Debug`,icon:ie,content:l(cr,{})}]})})}export{Rr as EventsPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W 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{at as l,gt as u,ht as d,mt as f,st as p,vt as m}from"./player-overlays-B7T46vDu.js";import{$a as h,Bu as g,Cn as _,Dn as v,En as y,Fa as b,Fd as x,Gi as S,Hi as C,J as w,Ji as T,Ju as E,Ki as ee,Kl as D,Or as O,Sn as k,Ui as A,Ul as te,Uu as j,Wi as M,X as N,Xi as P,Yi as F,Yl as I,Yu as L,Zd as R,Zu as z,bf as B,dr as ne,ea as re,en as V,eo as ie,ga as H,gd as U,hn as W,ia as ae,io as oe,iu as se,kt as ce,la as le,nf as G,no as K,oo as ue,q as de,qd as q,ro as fe,su as pe,ta as J,td as me,to as he,ur as ge,va as _e,vt as ve,xn as ye,yu as Y,zt as be}from"./src-B06iwqFQ.js";import{Er as X}from"./client-BBcQuaON.js";import{t as xe}from"./useTranslation-Bc5yH9V9.js";import{$ as Se,I as Ce,Q as we,Z as Te,q as Ee}from"./index-BsZjL5HO.js";import{t as De}from"./NodeAddonsSettingsPanel-BMxvR3AQ.js";import{t as Oe}from"./device-integration-icon-DbGFErfk.js";import{n as ke,r as Ae,t as je}from"./ScanNetworkModal-BtSkDnst.js";var Me=m(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);n();function Ne(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Ne(n.fields));return t}function Pe(t,n,r){let[a,s]=o(`idle`),[c,l]=o({}),u=i(()=>{let e=[];for(let n of t.sections)e.push(...Ne(n.fields));return e},[t]),d=u.length>0&&r!==void 0,f=e(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:e(async()=>{if(!r)return;let e=u.filter(e=>{let t=n[e];return t!=null&&String(t).trim()!==``});if(e.length===0)return;s(`testing`);let t={};for(let n of e)t[n]={status:`probing`};l(t);let i=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await r(e,n[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of i)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),s(`idle`)},[r,u,n]),clearProbeResult:f}}n();function Z(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Z(n.fields));return t}function Fe(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Ie(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Ie(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function Le(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Re({open:t,integrationId:n,addonId:l,onClose:d}){let{t:f}=xe(),p=a(),[m,h]=o({}),[g,_]=o(!1),[v,y]=o(null),[x,S]=o(Le),C=H({addonId:l},{enabled:t}),w=C.data?.deviceType??null,T=ae({addonId:l,type:w??X.Camera},{enabled:t&&C.isSuccess&&w!==null}),E=T.data??null;c(()=>{t&&(h(E?Ie(E.sections.flatMap(e=>e.fields)):{}),S(Le()),_(!1),y(null))},[t,n,E]);let ee=i(()=>({...m,_probeRequestId:x}),[m,x]),D=F({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),O=b(),k=e(async(e,t)=>{_(!0);let n=await O.mutateAsync({addonId:l,type:w??X.Camera,key:e,value:t,formValues:ee});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Fe(e[i])&&!Fe(a)&&(r[i]=a,t=!0);return t?r:e}),n},[O,l,ee,w]),{testAllStatus:A,hasProbeFields:te,probeResults:M,handleTestAll:N,clearProbeResult:P}=Pe(E??{sections:[]},m,k);async function I(e){y(null);try{await D.mutateAsync({addonId:l,type:w??X.Camera,config:m,integrationId:n}),e?h(E?Ie(E.sections.flatMap(e=>e.fields)):{}):d()}catch(e){y(e instanceof Error?e.message:String(e))}}if(!t)return null;let L=Z((E?.sections??[]).flatMap(e=>e.fields)).filter(e=>Fe(m[e])),R=L.length===0,z=C.isLoading||w!==null&&T.isLoading,B=C.isError||C.isSuccess&&w===null||T.isError||T.isSuccess&&E===null;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:d}),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:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:f(`integrations.addDevice`)}),s(`button`,{onClick:d,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:s(se,{className:`h-4 w-4`})})]}),s(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:z?s(`div`,{className:`flex items-center justify-center py-8`,children:s(U,{className:`h-5 w-5 animate-spin text-primary`})}):B?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[s(Y,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`space-y-1`,children:[s(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,s(`span`,{className:`font-mono`,children:l}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):s(Ce,{schema:E,values:m,onChange:h,onTestField:k,probeResults:M,onClearProbe:P})}),!B&&!z&&r(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[r(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[r(`span`,{className:`flex items-center gap-2`,children:[s(j,{className:`h-3.5 w-3.5`}),`Test logs`,s(`span`,{className:`font-mono text-[9px] opacity-60`,children:x.slice(0,14)})]}),s(u,{className:`h-3.5 w-3.5 transition-transform ${g?`rotate-180`:``}`})]}),g&&s(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:s(ve,{addonId:l,requestId:x,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!B&&!z&&(v||L.length>0)&&s(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[s(Y,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),s(`p`,{className:`text-[11px] text-destructive`,children:v||`Required: ${L.join(`, `)}`})]})}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[r(`div`,{className:`flex items-center gap-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.cancel`)}),!B&&te&&r(`button`,{type:`button`,onClick:N,disabled:A===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[A===`testing`?s(U,{className:`h-3.5 w-3.5 animate-spin`}):s(pe,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:()=>I(!0),disabled:B||!R||D.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:f(`integrations.saveAndNew`)}),s(`button`,{onClick:()=>I(!1),disabled:B||!R||D.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:D.isPending?f(`integrations.saving`):f(`integrations.save`)})]})]})]})]})}var ze=1500;function Be({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=xe(),o=C(),c=(S({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?ze:!1}).data??[]).find(e=>e.jobId===n);if(!c)return null;let l=c.state===`running`,u=c.processed,d=c.total>0?Math.round(u/c.total*100):0;!l&&c.finishedAt!==null&&i();let f=[`${u}/${c.total} ${a(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];c.adopted>0&&f.push(`${c.adopted} ${a(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),c.alreadyAdopted>0&&f.push(`${c.alreadyAdopted} ${a(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),c.failed>0&&f.push(`${c.failed} ${a(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let p=f.join(` · `);return r(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[r(`div`,{className:`flex items-center gap-2`,children:[l?s(U,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?s(Y,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?s(q,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):s(R,{className:`h-3.5 w-3.5 text-primary shrink-0`}),s(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&s(`button`,{onClick:()=>o.mutate({jobId:n}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),s(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:s(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),c.results.filter(e=>e.outcome===`failed`).slice(0,5).map(e=>r(`p`,{className:`text-[11px] text-destructive`,children:[e.childNativeId,`: `,e.error]},e.childNativeId))]})}function Q(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}n();var $=`devices`,Ve={id:$,label:`Devices`,isDefault:!0},He=2e4,Ue=100;function We({addonId:n,integrationId:i,onClose:l}){let{t:u}=xe(),d=a(),[f,p]=o(new Set),[m,h]=o(new Set),[g,_]=o(new Map),[v,y]=o(null),{data:b}=he(),x=(b??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[S,C]=o(!0),w=A({addonId:n,integrationId:i}).data?.filters,O=w&&w.length>0?w:[Ve],[k,te]=o(O.find(e=>e.isDefault)?.id??(O.some(e=>e.id===$)?$:O[0].id)),j=k!==$,N=ee(),P=M({addonId:n,integrationId:i,page:1,pageSize:He,filter:k}),F=P.refetch,L=N.mutate,R=e(()=>{L({addonId:n,integrationId:i},{onSettled:()=>{F()}})},[L,n,i,F]),z=t(null);c(()=>{let e=`${n}::${i}`;z.current===e||P.isLoading||(z.current=e,(P.data?.candidates.length??0)===0&&R())},[n,i,P.isLoading,P.data,R]);let B=N.isPending,ne=N.isError?N.error instanceof Error?N.error.message:String(N.error):null,re=typeof N.data?.lastError==`string`&&N.data.lastError.length>0?N.data.lastError:null,V=P.data?.candidates??[],ie=P.isError?P.error instanceof Error?P.error.message:String(P.error):null,H=T(),[W,ae]=o(null),oe=e(e=>{e.alreadyAdopted||p(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),ce=e(e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),le=e((e,t)=>{_(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),K=e(e=>{let t={};for(let n of e){let e=g.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[g]),ue=e(async()=>{y(null);let e=[...f];if(e.length!==0)try{let t=K(e),{jobId:r}=await H.mutateAsync({addonId:n,integrationId:i,filter:k,childNativeIds:e,...t?{perCandidate:t}:{},...x?{importLocations:S}:{}});ae(r),p(new Set),_(new Map)}catch(e){y(e instanceof Error?e.message:String(e))}},[f,K,H,n,i,k,x,S]),q=t(null),fe=e(()=>{W===null||q.current===W||(q.current=W,F(),d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}))},[W,F,d]),pe=e(e=>{te(e),p(new Set),h(new Set),_(new Map),y(null)},[]),J=f.size,me=W!==null&&J===0&&!H.isPending;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:l}),r(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] 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:`min-w-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:u(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),s(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:u(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),r(`div`,{className:`flex items-center gap-3 shrink-0`,children:[x&&r(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[s(`input`,{type:`checkbox`,checked:S,onChange:e=>C(e.target.checked),className:`accent-primary`}),u(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),s(`button`,{onClick:l,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:s(se,{className:`h-4 w-4`})})]})]}),r(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(ne??ie??re)&&V.length===0&&s(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[s(Y,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`min-w-0`,children:[s(`p`,{className:`text-xs font-medium text-destructive`,children:u(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),s(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:ne??ie??re})]})]})}),O.length>1&&s(Ge,{filters:O,activeFilter:k,onSelect:pe}),s(`div`,{className:`flex-1 min-h-0`,children:s(de,{mode:`generic`,items:V,pageSize:Ue,getKey:e=>e.childNativeId,getSearchText:Q,getFilterType:e=>e.type,filterOptions:D(),filterLabel:u(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:P.isLoading||B&&V.length===0,searchPlaceholder:u(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(ne??ie??re)&&V.length===0?``:u(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:R,disabled:B,title:u(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[s(E,{className:`h-3.5 w-3.5 ${B?`animate-spin`:``}`}),u(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:u(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>s(Ke,{candidate:e,expandable:!j,expanded:m.has(e.childNativeId),onToggleExpand:()=>ce(e.childNativeId),adoptedLabel:u(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:u(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=I(e.type),n=t.icon;return r(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[s(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>s(`div`,{className:`flex items-center justify-end`,children:s(`button`,{onClick:()=>oe(e),disabled:e.alreadyAdopted,"aria-label":f.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${f.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:f.has(e.childNativeId)&&s(G,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!j&&m.has(e.childNativeId),renderExpanded:j?void 0:e=>s(qe,{candidate:e,hiddenChildIds:g.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>le(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:f.has(e.childNativeId)?`bg-primary/5`:``})})]}),v&&s(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[s(Y,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),s(`p`,{className:`text-[11px] text-destructive`,children:v})]})}),W!==null&&s(Be,{addonId:n,integrationId:i,jobId:W,onFinished:fe}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[s(`div`,{}),r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:l,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:u(`integrations.cancel`,{defaultValue:`Cancel`})}),r(`button`,{onClick:me?l:ue,disabled:!me&&(J===0||H.isPending),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[H.isPending&&s(U,{className:`h-3.5 w-3.5 animate-spin`}),me?u(`integrations.close`,{defaultValue:`Close`}):u(`integrations.addSelected`,{defaultValue:`Add selected`}),!me&&J>0?` (${J})`:``]})]})]})]})]})}function Ge({filters:e,activeFilter:t,onSelect:n}){return s(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return s(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function Ke({candidate:e,expandable:t,expanded:n,onToggleExpand:i,adoptedLabel:a}){let o=(e.children??[]).length;return r(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&o>0?r(`button`,{type:`button`,onClick:i,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[s(n?u:d,{className:`h-3.5 w-3.5`}),o]}):s(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),s(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&s(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:a})]})}function qe({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let i=e.children??[];return i.length===0?null:s(`div`,{className:`space-y-1 py-1`,children:i.map(e=>{let i=t.has(e.childNativeId),a=e.capabilities??[];return r(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${i?`opacity-50`:``}`,children:[s(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),a.length>0&&s(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:a.join(`, `)}),s(`button`,{onClick:()=>n(e.childNativeId),"aria-label":i?`Show child`:`Hide child`,title:i?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:s(i?f:x,{className:`h-3 w-3`})})]},e.childNativeId)})})}n();function Je(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...Je(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function Ye(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>Je(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Xe(e){return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{if(`value`in e){let{value:t,...n}=e;return n}return e})}))}}function Ze({integrationId:e,addonId:t,name:n,kind:o,mode:c,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=xe(),m=a(),{data:h,isLoading:g}=K({id:e},{enabled:c===`account`||c===`broker`}),b=i(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:x,isLoading:S}=ge({addonId:t,nodeId:`hub`},{enabled:c===`account`}),C=i(()=>x?Xe(x):null,[x]),w=oe(),T=(t,n)=>{w.mutate({id:e,settings:t,...n?{secretKeys:[...n]}:{}},{onSuccess:()=>{m.invalidateQueries(),f()}})};return s(ye,{open:!0,onOpenChange:e=>!e&&f(),children:r(_,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[s(y,{children:r(v,{children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]})}),s(k,{children:c===`broker`?l?r(`div`,{className:`space-y-3`,children:[s(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),b&&r(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,s(`span`,{className:`font-mono text-foreground-subtle`,children:b})]}),w.isPending?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[s(U,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):s(Ae,{kind:l,onResolved:e=>{T({brokerId:e})},onBack:f}),w.isError&&s(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):s(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):c===`account`?g||S?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[s(U,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):s(ke,{addonId:t,configSchema:C,canTest:u,initialName:n,initialConfig:Ye(C,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e,secretKeys:t})=>T(e,t),onBack:f}):s(W,{trpc:d,addonId:t,nodeId:`hub`,title:n})})]})})}function Qe(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}n();function $e(){let{t}=xe(),{integrationId:n}=we(),u=a(),d=Te(),[f,m]=Se(),b=l(),[x,S]=o(!1),[C,T]=o(!1),[E,ee]=o(!1),[D,A]=o(!1),{data:M,isLoading:F}=ie({id:n??``},{enabled:!!n}),{data:I}=ge({addonId:M?.addonId??``,nodeId:`hub`},{enabled:!!M?.addonId}),{data:R,isSuccess:H}=he(),W=i(()=>{let e=M?.addonId;return!e||!H?null:(R??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[R,M?.addonId,H]),{data:ae}=re({}),oe=i(()=>(ae?.providers??[]).some(e=>e.addonId===M?.addonId),[ae,M?.addonId]),G=W!==null,K=M?.info?.fixed===!0,q=G?W===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),pe=i(()=>{let e=M?.addonId;return!e||!H?null:(R??[]).find(t=>t.addonId===e)?.brokerKind??null},[R,M?.addonId,H]),Y=i(()=>{let e=M?.addonId;return!e||!H?!1:(R??[]).find(t=>t.addonId===e)?.canTest===!0},[R,M?.addonId,H]),X=i(()=>{let e=M?.addonId;return!e||!H?null:(R??[]).find(t=>t.addonId===e)?.mode??null},[R,M?.addonId,H]);c(()=>{f.get(`add`)===`1`&&G&&(S(!0),m(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[f,G,m]);let Ce=I!=null&&Array.isArray(I.sections)&&I.sections.some(e=>e.fields.length>0),{data:Ee}=ne({addonId:M?.addonId??``,nodeId:`hub`},{enabled:!!M?.addonId&&X!==`account`}),ke=X!==null&&X!==`account`&&Qe(Ee),Ae=i(()=>M?.addonId?[M.addonId]:[],[M?.addonId]),{data:Ne}=le({projection:`slim`},{refetchInterval:3e4}),Pe=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Z=ue({onMutate:async e=>{await u.cancelQueries({queryKey:Pe});let t=u.getQueryData(Pe);return t!=null&&u.setQueryData(Pe,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&u.setQueryData(Pe,r.previous)},onSettled:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=h({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]}),d(`/integrations`)}}),Ie=O({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=_e({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ze=P({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Be=J({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=i(()=>Ne??[],[Ne]),$=i(()=>{let e=new Map;for(let t of Q)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[Q]),Ve=e(e=>$.get(e)??null,[$]),{data:He}=fe(void 0),Ue=i(()=>w(He),[He]),Ge=e(e=>d(`/devices/${String(e)}`),[d]),Ke=i(()=>{let e=M?.id;return e?Q.filter(t=>{let n=Ue(t);return n.kind===`resolved`&&n.integration.id===e}):[]},[Q,M?.id,Ue]),qe=i(()=>He===void 0?null:N(Ke).length,[He,Ke])??`…`;return F?r(`div`,{className:`p-4`,children:[s(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),s(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):M?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[s(be,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},{label:M.name}]}),r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`flex items-center gap-3 min-w-0`,children:[s(et,{addonId:M.addonId}),r(`div`,{className:`min-w-0`,children:[s(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:M.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[M.addonId,` · `,qe,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[oe&&r(`button`,{onClick:()=>T(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the network for devices (incl. a different subnet)`,children:[s(z,{className:`h-3.5 w-3.5`}),`Scan network`]}),!K&&r(`button`,{onClick:()=>S(!0),disabled:!G,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:q,children:[s(me,{className:`h-3.5 w-3.5`}),q]}),r(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Z.isPending?`opacity-60`:``} ${M.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[s(V,{checked:M.enabled,onCheckedChange:e=>Z.mutate({id:n,enabled:e}),disabled:Z.isPending,"aria-label":M.enabled?`Disable integration`:`Enable integration`}),s(`span`,{className:`text-[11px] font-medium ${M.enabled?`text-success`:`text-foreground-subtle`}`,children:M.enabled?`Enabled`:`Disabled`}),Z.isPending&&s(U,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),X!==`standalone`&&(Ce||W===`device-adoption`)&&r(`button`,{onClick:()=>ee(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[s(g,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>A(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrations.logs`,{defaultValue:`View logs`}),children:[s(j,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),s(ce,{label:`Restart`,icon:L,title:`Restart "${M.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${qe} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Ie.isPending,action:()=>Ie.mutateAsync({addonId:M.addonId})}),!K&&n&&s(ce,{label:t(`integrations.delete`,{defaultValue:`Delete`}),icon:p,title:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`}),description:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:M.name,count:qe}),confirmLabel:t(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:Fe.isPending,action:()=>Fe.mutateAsync({id:n})})]})]}),ke&&s(De,{nodeId:null,addonIds:Ae,level:`global`,surface:`integration`,title:t(`integrations.settings`,{defaultValue:`Settings`})}),s(de,{context:`integration-detail`,devices:Q,trpc:b.trpcClient,integrationOf:Ue,forceIntegrationId:M.id,urlScope:`root`,lsKey:`integration-detail:${M.addonId}`,resolveIntegrationIcon:Oe,resolveParent:Ve,onNavigate:Ge,batchActions:{remove:Le.mutate,disable:ze.mutate,enable:Be.mutate},...K?{}:{onDeleteDevice:e=>Le.mutate({deviceId:e.id})}}),x&&n&&W===`device-adoption`&&s(We,{addonId:M.addonId,integrationId:n,onClose:()=>S(!1)}),x&&n&&W===`device-provider`&&s(Re,{open:x,integrationId:n,addonId:M.addonId,onClose:()=>S(!1)}),C&&M&&s(je,{open:C,scope:{addonId:M.addonId,label:M.name},onClose:()=>T(!1)}),E&&n&&W!==null&&X!==null&&s(Ze,{integrationId:n,addonId:M.addonId,name:M.name,kind:W,mode:X,brokerKind:pe,canTest:Y,trpc:b.trpcClient,onClose:()=>ee(!1)}),D&&s(ye,{open:!0,onOpenChange:e=>!e&&A(!1),children:r(_,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[r(y,{className:`flex-row items-center justify-between gap-2 mb-0`,children:[r(v,{className:`flex items-center gap-2 min-w-0`,children:[s(j,{className:`h-4 w-4 text-primary shrink-0`}),s(`span`,{className:`truncate`,children:M.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[M.addonId,n?` · ${n}`:``]})]}),s(te,{icon:se,variant:`ghost`,size:`sm`,"aria-label":`Close`,onClick:()=>A(!1)})]}),s(k,{className:`min-h-0 overflow-hidden p-0`,children:s(ve,{addonId:M.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})})]}):r(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[s(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:s(Me,{className:`h-6 w-6 text-foreground-subtle`})}),r(`div`,{className:`space-y-1 max-w-sm`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),s(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:n??``})})]}),r(`button`,{onClick:()=>d(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[s(B,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function et({addonId:e}){let t=Ee(e),[n,r]=o(!1);return!t||n?null:s(`img`,{src:t,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:()=>r(!0)})}export{$e as IntegrationDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
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-B7T46vDu.js";import{Cn as h,Dn as g,En as _,Hl as v,In as y,Tn as b,Wu as x,_c as S,cc as C,dc as w,fc as T,gc as E,gd as D,hc as O,hu as k,id as A,iu as j,la as M,lc as N,mc as P,nf as F,oc as I,pc as L,rf as R,sc as z,td as B,tr as V,tu as H,uc as U,vc as W,wn as G,xn as K}from"./src-B06iwqFQ.js";import{t as q}from"./crop-DEIlVeIH.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-CC0VQLjV.js";import{n as ue,r as Z,t as de}from"./face-bbox-B9dID2jY.js";import{vi as fe}from"./client-BBcQuaON.js";import{t as pe}from"./AdminPage-BSFohA3i.js";import{n as me,r as he}from"./authed-media-DmDTbsLa.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}=L({vehicleId:e}),o=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(D,{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(R,{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(j,{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,x]=o(!1),[S,C]=o(!1),w=E(),T=U();function O(){u(e.name),x(!0)}function k(){x(!1),u(``)}function M(){let t=l.trim();if(!t||t===e.name){k();return}w.mutate({id:e.id,name:t},{onSettled:()=>{c.invalidateQueries({queryKey:Q}),k()}})}function N(){T.mutate({id:e.id},{onSettled:()=>{c.invalidateQueries({queryKey:Q}),C(!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(R,{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`&&M(),e.key===`Escape`&&k()},className:`h-6 text-xs`,autoFocus:!0}),s(`button`,{type:`button`,onClick:M,disabled:w.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:s(F,{className:`h-3.5 w-3.5`})}),s(`button`,{type:`button`,onClick:k,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:s(j,{className:`h-3.5 w-3.5`})})]}):s(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),s(V,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!m&&n(`div`,{className:`flex items-center gap-1`,children:[s(`button`,{type:`button`,onClick:O,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:s(A,{className:`h-3.5 w-3.5`})}),s(`button`,{type:`button`,onClick:()=>C(!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(K,{open:S,onOpenChange:e=>!e&&C(!1),children:n(h,{children:[n(_,{children:[s(g,{children:`Delete vehicle`}),n(G,{children:[`Delete `,s(`strong`,{children:e.name}),` and all its plate samples? This cannot be undone.`]})]}),n(b,{children:[s(y,{variant:`secondary`,onClick:()=>C(!1),children:`Cancel`}),n(y,{variant:`danger`,onClick:N,disabled:T.isPending,children:[T.isPending?s(D,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function ye(){let e=a(),[t,r]=o(``),i=C();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(y,{variant:`primary`,size:`sm`,onClick:c,disabled:i.isPending||!t.trim(),children:[i.isPending?s(D,{className:`h-3.5 w-3.5 animate-spin`}):s(B,{className:`h-3.5 w-3.5`}),`Add`]})]})}function be(){let{data:e,isLoading:t}=P(),[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(D,{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=I(),l=C(),[u,d]=o(``),[f,p]=o(!1),[m,x]=o(null),S=e!==null&&e.length>0,w=e?.length??0;function T(){p(!1),d(``),x(null)}function E(){T(),r()}function O(t){!e||e.length===0||c.mutate({plateIds:[...e],vehicleId:t},{onSettled:()=>{i.invalidateQueries({queryKey:Se}),E()}})}function k(){!e||!u.trim()||l.mutate({name:u.trim()},{onSuccess:e=>{e?.id&&O(e.id)},onError:()=>{i.invalidateQueries({queryKey:Se}),E()}})}let A=c.isPending||l.isPending;return s(K,{open:S,onOpenChange:e=>!e&&E(),children:n(h,{children:[n(_,{children:[s(g,{children:w>1?`Assign ${String(w)} plates to vehicle`:`Assign plate to vehicle`}),s(G,{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:()=>x(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`&&k()},autoFocus:!0,className:`flex-1`})}):s(`button`,{type:`button`,onClick:()=>{x(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(b,{children:[s(y,{variant:`secondary`,onClick:E,disabled:A,children:`Cancel`}),f?n(y,{variant:`primary`,onClick:k,disabled:A||!u.trim(),children:[A&&s(D,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):n(y,{variant:`primary`,onClick:()=>m&&O(m),disabled:A||!m,children:[A&&s(D,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,w>1?` ${String(w)}`:``]})]})]})})}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 g=a(),{data:_,isFetching:b}=w({plateId:e?.plateId??``},{enabled:e!==null}),S=z(),[C,T]=o(`frame`),[E,O]=o(!1),[M,N]=o(``),{frameSrc:P,naturalWidth:I,naturalHeight:L,failed:R}=Te(e?.keyFrameMediaId);c(()=>{O(!1),N(``),T(`frame`)},[e?.plateId]);let B=r(()=>{let t=Ee(_??[]);return t?t.url:xe(e)},[_,e]),V=r(()=>!e?.plateBbox||I===null||L===null?null:de(e.plateBbox,I,L),[e?.plateBbox,I,L]);if(e===null)return null;let H=e.keyFrameMediaId!==void 0&&!R,U=H&&C===`frame`,W=e.assigned?e.vehicleName??`Assigned`:e.recognizedVehicleId?`${e.vehicleName??`Recognized`} (suggested)`:`Unassigned`,G=`${String(Math.round(e.score*100))}%${e.corrected?` · corrected`:``}`;function ee(){e&&(N(e.text),O(!0))}function J(){if(!e)return;let t=M.trim().toUpperCase();if(!t||t===e.text){O(!1);return}S.mutate({plateId:e.plateId,text:t},{onSettled:()=>{g.invalidateQueries({queryKey:we}),O(!1)}})}return s(K,{open:!0,onOpenChange:e=>!e&&i(),children:n(h,{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(j,{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:[H&&n(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[n(`button`,{type:`button`,onClick:()=>T(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${C===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[s(x,{className:`h-3.5 w-3.5`}),` Full frame`]}),n(`button`,{type:`button`,onClick:()=>T(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${C===`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`]})]}),U&&P?s(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:s(X,{src:P,alt:`Full frame with detected plate`,fit:`natural`,className:`w-full`,overlay:V?s(De,{box:V}):void 0})}):B?n(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[s(X,{src:B,alt:`Detected plate`,className:`h-full w-full`}),b&&s(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:s(D,{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`}),E?n(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[s(v,{value:M,onChange:e=>N(e.target.value),onKeyDown:e=>{e.key===`Enter`&&J(),e.key===`Escape`&&O(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),s(`button`,{type:`button`,onClick:J,disabled:S.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Save corrected text`,children:S.isPending?s(D,{className:`h-3.5 w-3.5 animate-spin`}):s(F,{className:`h-3.5 w-3.5`})}),s(`button`,{type:`button`,onClick:()=>O(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel`,children:s(j,{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(A,{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:W}),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(y,{variant:`secondary`,onClick:()=>d(e.plateId),disabled:m,children:[s(Z,{className:`h-3.5 w-3.5`}),` Detach`]}):n(y,{variant:`primary`,onClick:()=>l(e.plateId),disabled:m,children:[s(k,{className:`h-3.5 w-3.5`}),` Assign`]}),n(y,{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=S(),h=N(),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(D,{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(k,{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(D,{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,b]=o(null),{data:x,isLoading:C}=T({limit:Ae,includeCrops:!1},{refetchInterval:3e4}),{data:w=[]}=P(),{data:E}=M({isCamera:!0,projection:`slim`}),O=S(),A=W(),F=N(),I=Date.now(),L=x??[],R=r(()=>{let e=new Map;for(let t of E??[])e.set(t.id,t.name);return e},[E]),z=e=>R.get(e)??`Camera #${String(e)}`,B=r(()=>J(L).map(e=>({id:e,name:z(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[L,R]),V=r(()=>re(le(Pe(L,t),l),d),[L,t,l,d]),H=ie(V,je,r(()=>JSON.stringify([t,l.fromMs,l.toMs,[...d].sort((e,t)=>e-t)]),[t,l.fromMs,l.toMs,d])),U=r(()=>new Map(L.map(e=>[e.plateId,e])),[L]),G=v===null?null:U.get(v)??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||F.isPending,ae=O.isPending||F.isPending;function ce(){Y.length!==0&&A.mutate({plateIds:Y},{onSettled:()=>{K(),q()}})}function ue(){Y.length!==0&&Promise.allSettled(Y.map(e=>F.mutateAsync({plateId:e}))).then(()=>{K(),q()})}function de(e){b(null),_([e])}function fe(e){O.mutate({plateId:e},{onSettled:K}),b(null)}function pe(e){F.mutate({plateId:e},{onSettled:K}),b(null)}let me=V.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:B,selected:d,onChange:f}),!C&&s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:me?`${String(V.length)} of ${String(L.length)} plates`:`${String(V.length)} plate${V.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(y,{variant:`primary`,onClick:()=>_(Y),disabled:X,children:[s(k,{className:`h-3.5 w-3.5`}),` Assign`]}),n(y,{variant:`secondary`,onClick:ce,disabled:X,children:[A.isPending?s(D,{className:`h-3.5 w-3.5 animate-spin`}):s(Z,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),n(y,{variant:`secondary`,onClick:ue,disabled:X,children:[s(p,{className:`h-3.5 w-3.5`}),` Delete`]}),s(y,{variant:`ghost`,onClick:q,disabled:X,children:s(j,{className:`h-3.5 w-3.5`})})]})]}),C&&n(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[s(D,{className:`h-4 w-4 animate-spin`}),` Loading plates…`]}),!C&&V.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.`}),!C&&V.length>0&&n(i,{children:[s(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2`,children:H.pageItems.map(e=>s(Me,{plate:e,cameraName:z(e.deviceId),nowMs:I,selected:m.has(e.plateId),onToggleSelect:te,onAssign:e=>_([e]),onOpenDetail:b},e.plateId))}),s(ee,{currentPage:H.page,totalItems:H.totalItems,pageSize:H.pageSize,onPageChange:H.setPage,itemNoun:`plates`})]}),s(Oe,{plate:G,cameraName:G?z(G.deviceId):``,onClose:()=>b(null),onAssign:de,onUnassign:fe,onDelete:pe,actionsPending:ae}),s(Ce,{plateIds:g,vehicles:w,onDone:()=>{_(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(),[]),H(fe.PipelineAnalyticsPlateGalleryChanged,()=>{r.current?.trigger()})}function ze(){return Re(),s(pe,{icon:R,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};
|