@camstack/addon-admin-ui 1.2.379 → 1.2.380
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-02uy1lo7.js → AddonAssetIcon-Bb7Ct500.js} +1 -1
- package/dist/assets/AddonIntegrationBody-CrdlKSnw.js +1 -0
- package/dist/assets/Addons-D4PXlVuv.js +4 -0
- package/dist/assets/{AdminPage-C1SqQSAP.js → AdminPage-C4KFXhpL.js} +1 -1
- package/dist/assets/{AdminTabs-D_amP_Ho.js → AdminTabs-Xojn4om3.js} +1 -1
- package/dist/assets/AiProfiles-DfEnDqpl.js +3 -0
- package/dist/assets/{BrokerForm-DWNdijlI.js → BrokerForm-xfFhJuwh.js} +1 -1
- package/dist/assets/Build-DI9dJ9g7.js +40 -0
- package/dist/assets/{Calendars-BRWb4l_h.js → Calendars-Bnf06BwE.js} +1 -1
- package/dist/assets/Cluster-BEN0Ywsy.js +1 -0
- package/dist/assets/ClusterStepModel-CCQfGKgr.js +1 -0
- package/dist/assets/{CompositionEditor-D2Mdanul.js → CompositionEditor-xfXmzLmy.js} +1 -1
- package/dist/assets/{CompositionEditorPage-ClvOpgEi.js → CompositionEditorPage-NiAGLAMP.js} +1 -1
- package/dist/assets/Data-BXsjqrpr.js +1 -0
- package/dist/assets/DeviceDetail-C6IJ8aPy.js +2 -0
- package/dist/assets/{DeviceDoActionFields-CLSOxEiv.js → DeviceDoActionFields-DrDGsYb9.js} +1 -1
- package/dist/assets/{Devices-D0yIu4CH.js → Devices-CbgpUN0n.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-D_h14JKk.js → EmbedPlayerPage-Chpa6jH3.js} +1 -1
- package/dist/assets/{HeaderPills-DvZSXIv5.js → HeaderPills-C_d5E3KJ.js} +1 -1
- package/dist/assets/Identity-BZRGZUJ4.js +1 -0
- package/dist/assets/IntegrationDetail-C0oNiuVo.js +1 -0
- package/dist/assets/Integrations-Bwsanjq9.js +1 -0
- package/dist/assets/Integrations-Cd2bBUEg.js +1 -0
- package/dist/assets/Library-u8upsMgy.js +1 -0
- package/dist/assets/Locations-EXGomHtI.js +3 -0
- package/dist/assets/{Logs-BmTVkon0.js → Logs-CiMG3usl.js} +1 -1
- package/dist/assets/MyAccess-D4Q373c8.js +2 -0
- package/dist/assets/Network-BDQLQavo.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-BH_xJge-.js → NodeAddonsSettingsPanel-BCBiWsXF.js} +1 -1
- package/dist/assets/Notifications-CJkHJwU9.js +1 -0
- package/dist/assets/Recordings-CY8GuLFY.js +1 -0
- package/dist/assets/{ScanNetworkModal-N-j2iMnZ.js → ScanNetworkModal--HB0iAkv.js} +1 -1
- package/dist/assets/SessionsList-BKq4tUzz.js +2 -0
- package/dist/assets/{Showroom-fId0hCWU.js → Showroom-BJ4Ky1Zs.js} +1 -1
- package/dist/assets/System-DD5PSmPJ.js +1 -0
- package/dist/assets/{Terminal-FY6VVyeT.js → Terminal-OuHg6Cs9.js} +5 -5
- package/dist/assets/{Viewer-Db9V3y4R.js → Viewer-DGVbUCuf.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DgrbCMdK.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-mlNToqXX.js} +1 -1
- package/dist/assets/{authed-media-CA36_TYL.js → authed-media-CYbdebtY.js} +1 -1
- package/dist/assets/{device-integration-icon-DcTMLxPi.js → device-integration-icon-BeY56xYd.js} +1 -1
- package/dist/assets/device-picker-model-iv0LjZ9A.js +1 -0
- package/dist/assets/{hostInit-CompbdN8.js → hostInit-CA8QWnWz.js} +1 -1
- package/dist/assets/index-BG5-7hV8.js +4 -0
- package/dist/assets/index-spclGdc-.css +2 -0
- package/dist/assets/location-owned-usage-Ynolakjx.js +1 -0
- package/dist/assets/{mf-entry-bootstrap-0-e75731db.js → mf-entry-bootstrap-0-5ba87861.js} +2 -2
- package/dist/assets/mount-iv0LjZ9A.js +1 -0
- package/dist/assets/{notification-schedule-field-ql1Dzx_N.js → notification-schedule-field-DSZYumUK.js} +1 -1
- package/dist/assets/remoteEntry-P_tn-U-H.js +1 -0
- package/dist/assets/{src-CmnrQw1X.js → src-wd4uG4SU.js} +3 -3
- package/dist/assets/{use-scenes-feed-CLHMDiWX.js → use-scenes-feed-DEo1hSFU.js} +1 -1
- package/dist/assets/{use-stationary-objects-Ba8qX5nf.js → use-stationary-objects-RHZniR-r.js} +1 -1
- package/dist/assets/useEventInvalidation-iv0LjZ9A.js +1 -0
- package/dist/assets/{useNodeUrlSelection-CjzoYyR_.js → useNodeUrlSelection-BHkizaWO.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DX2QtUlA.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CB7lihwK.js} +2 -2
- package/dist/index.html +6 -6
- package/dist/server/addon.js +1 -1
- package/package.json +1 -1
- package/dist/assets/AddonIntegrationBody-oV8coptw.js +0 -1
- package/dist/assets/Addons-BBMJbtIk.js +0 -4
- package/dist/assets/AiProfiles-C_MUiJTn.js +0 -3
- package/dist/assets/Build-BmR1cbDt.js +0 -40
- package/dist/assets/Cluster-DEbpxrVi.js +0 -1
- package/dist/assets/ClusterStepModel-D-XsmHIE.js +0 -1
- package/dist/assets/Data-DzzC8p_q.js +0 -1
- package/dist/assets/DeviceDetail-CJduuTAv.js +0 -2
- package/dist/assets/Identity-feKhsBbU.js +0 -1
- package/dist/assets/IntegrationDetail-CP2OcwRx.js +0 -1
- package/dist/assets/Integrations-BcNYo6tG.js +0 -1
- package/dist/assets/Integrations-iBbhRDLT.js +0 -1
- package/dist/assets/Library-BqAUXKdv.js +0 -1
- package/dist/assets/Locations-B9gGlGQS.js +0 -3
- package/dist/assets/MyAccess-DDYlOEbm.js +0 -2
- package/dist/assets/Network-BtT9FApe.js +0 -1
- package/dist/assets/Notifications-DxjFdLCC.js +0 -1
- package/dist/assets/Recordings-Cx8-bDgI.js +0 -1
- package/dist/assets/SessionsList-542JIoxX.js +0 -2
- package/dist/assets/System-rx1MvWgE.js +0 -1
- package/dist/assets/device-picker-model-BwPih3Va.js +0 -1
- package/dist/assets/index-BlUdDWLp.js +0 -4
- package/dist/assets/index-vq6byeQ3.css +0 -2
- package/dist/assets/location-owned-usage-yNYTa3yG.js +0 -1
- package/dist/assets/mount-BwPih3Va.js +0 -1
- package/dist/assets/remoteEntry-CoqQRRUJ.js +0 -1
- package/dist/assets/useEventInvalidation-BwPih3Va.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Q as e,S as t,W as n,b as r,o as i,q as a,x as o}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 s}from"./player-overlays-Sm-ivm_8.js";import{$n as c,An as l,Dn as u,Hi as d,Hn as f,Mn as p,Nn as m,On as h,Or as g,Wu as _,X as v,Y as ee,_i as te,ad as ne,bi as y,fi as b,fu as x,gi as S,hi as C,kn as w,ld as T,od as re,pi as ie,sr as E,td as D,vd as ae,vi as oe,xd as O,yi as k,zn as A}from"./src-CmnrQw1X.js";import{t as j}from"./monitor-smartphone-5lHVpcLH.js";import{Cr as M,Nt as N,tr as P}from"./client-B2uiK_6q.js";import{I as F,Z as I}from"./index-BlUdDWLp.js";import{t as L}from"./BrokerForm-DWNdijlI.js";import{n as R,r as z,t as B}from"./AddonIntegrationBody-oV8coptw.js";e();var V=`kind`,H=`name`,U=`restore`,W=`restoreId`;function G(e){return{sections:[{id:`broker-identity`,title:`Broker`,columns:1,fields:[{type:`select`,key:V,label:`Kind`,options:e.map(e=>({value:e.key,label:e.label})),disabled:e.length<=1},{type:`text`,key:H,label:`Name`,placeholder:`My Home Assistant`,required:!0},{type:`boolean`,key:U,label:`Restore a broker that was removed, under its original id`,description:`Devices remember the broker id they were discovered under, so restoring the original id reconnects them instead of needing re-discovery. An id that is still in use is refused.`},{type:`text`,key:W,label:`Original broker id`,placeholder:`ha_004`,required:!0,showWhen:{field:U,equals:!0}}]}]}}function K(e){let t=t=>{let n=e[t];return typeof n==`string`?n.trim():``},n=t(V);if(n===``)return{ok:!1,problem:`Pick a kind.`};let r=t(H);if(r===``)return{ok:!1,problem:`Enter a name before saving.`};if(e.restore!==!0)return{ok:!0,identity:{kindKey:n,name:r,restoreId:null}};let i=t(W);return i===``?{ok:!1,problem:`Enter the original id, or turn restore off to create a new broker.`}:{ok:!0,identity:{kindKey:n,name:r,restoreId:i}}}var q={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function J(e){return q[e]??e}function se(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var ce={connected:`success`,connecting:`warning`,disconnected:`default`,"auth-failed":`danger`,unreachable:`danger`,error:`danger`};function le({status:e}){return o(E,{variant:ce[e],className:`text-[10px]`,children:e})}function ue(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function Y({title:e,subtitle:n,onClose:r,children:i}){return o(u,{open:!0,onOpenChange:e=>!e&&r(),children:t(w,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[t(p,{children:[o(m,{children:e}),n&&o(l,{children:n})]}),o(h,{className:`space-y-3 pr-1`,children:i})]})})}function de({kinds:e,onClose:r,onDone:s}){let c=i(),l=n(()=>G(e.map(e=>({key:X(e),label:e.label}))),[e]),[u,d]=a(()=>({[V]:X(e[0]),[H]:``,[U]:!1,[W]:``})),[f,p]=a(null),m=e.find(e=>X(e)===u.kind)??e[0],h=m?.kind??``,g=m?.addonId,_=b({onSuccess:()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]}),s()}}),v=e=>{let t=K(u);if(!t.ok){p(t.problem);return}p(null);let{name:n,restoreId:r}=t.identity;_.mutate({kind:h,name:n,settings:e,...r===null?{}:{id:r},...g===void 0?{}:{addonId:g}})};return t(Y,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:_.isPending?()=>{}:r,children:[o(F,{schema:l,values:u,onChange:d}),f!==null&&o(A,{message:f}),_.isError&&o(A,{message:_.error instanceof Error?_.error.message:String(_.error)}),h&&o(L,{kind:h,...g===void 0?{}:{addonId:g},onSubmit:v,onCancel:r,submitLabel:_.isPending?`Adding…`:`Add broker`,disabled:_.isPending},X(m))]})}function X(e){return e===void 0?``:`${e.addonId??``}::${e.kind}`}function fe({broker:e,onClose:r,onDone:a}){let s=i(),c=ie({id:e.id,addonId:e.addonId}),l=k({onSuccess:()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]}),s.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),a()}}),u=n(()=>{let e=c.data;return e&&typeof e==`object`?{...e}:{}},[c.data]);return o(Y,{title:`Edit ${e.name}`,subtitle:`${J(e.kind)} · ${e.id}`,onClose:l.isPending?()=>{}:r,children:c.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(O,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):c.isError?t(`div`,{className:`space-y-3`,children:[o(A,{message:`Failed to load settings: ${c.error instanceof Error?c.error.message:`Unknown error`}`}),o(`div`,{className:`flex justify-end`,children:o(f,{variant:`outline`,size:`sm`,onClick:r,children:`Close`})})]}):t(`div`,{className:`space-y-3`,children:[l.isError&&o(A,{message:l.error instanceof Error?l.error.message:String(l.error)}),o(L,{kind:e.kind,addonId:e.addonId,initialValues:u,onSubmit:t=>{l.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:r,submitLabel:l.isPending?`Saving…`:`Save`,disabled:l.isPending})]})})}function pe({broker:e,onEdit:n}){let r=i(),l=c(),[u,d]=a(null),p=y({onSuccess:e=>d(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>d({ok:!1,error:e instanceof Error?e.message:String(e)})}),m=oe({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),h=async()=>{await l({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&m.mutate({id:e.id,addonId:e.addonId})};return t(`tr`,{className:`border-b border-border last:border-0`,children:[o(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),o(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:J(e.kind)}),t(`td`,{className:`px-3 py-2`,children:[o(le,{status:e.status}),u&&o(`span`,{className:`ml-2 text-[10px] ${u.ok?`text-success`:`text-danger`}`,children:u.ok?`OK`:u.error??`failed`})]}),o(`td`,{className:`px-3 py-2`,children:t(`div`,{className:`flex items-center justify-end gap-1.5`,children:[t(f,{variant:`outline`,size:`sm`,onClick:()=>p.mutate({id:e.id,addonId:e.addonId}),disabled:p.isPending,title:`Test connection`,children:[p.isPending?o(O,{className:`h-3 w-3 animate-spin`}):o(x,{className:`h-3 w-3`}),`Test`]}),t(f,{variant:`outline`,size:`sm`,onClick:()=>n(e),title:`Edit`,children:[o(T,{className:`h-3 w-3`}),` Edit`]}),t(f,{variant:`outline`,size:`sm`,className:`border-danger/40 text-danger hover:bg-danger/10`,onClick:()=>{h()},disabled:m.isPending,title:`Delete`,children:[m.isPending?o(O,{className:`h-3 w-3 animate-spin`}):o(s,{className:`h-3 w-3`}),`Delete`]})]})})]})}function me({addonId:e}={}){let r=S({}),i=te(),s=n(()=>ue(r.data).filter(t=>e===void 0||t.addonId===e),[r.data,e]),[c,l]=a(!1),[u,d]=a(null),p=n(()=>{let t=new Map;for(let n of se(i.data))if(!(e!==void 0&&n.addonId!==e))for(let e of n.kinds)t.set(`${n.addonId}::${e.kind}`,{addonId:n.addonId,kind:e.kind,label:e.label});for(let e of s)[...t.values()].some(t=>t.kind===e.kind)||t.set(`::${e.kind}`,{kind:e.kind,label:J(e.kind)});return[...t.values()]},[s,i.data,e]);return t(`div`,{className:`space-y-3`,children:[o(`div`,{className:`flex items-center justify-end`,children:t(f,{variant:`primary`,size:`sm`,onClick:()=>l(!0),disabled:p.length===0,title:p.length===0?`No broker providers available`:void 0,children:[o(re,{className:`h-3.5 w-3.5`}),` Add broker`]})}),o(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[o(`thead`,{children:t(`tr`,{className:`border-b border-border bg-background/50`,children:[o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Name`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Kind`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Status`}),o(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Actions`})]})}),t(`tbody`,{children:[r.isLoading&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[o(O,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),r.isError&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,r.error instanceof Error?r.error.message:`Unknown error`]})}),!r.isLoading&&!r.isError&&s.length===0&&o(`tr`,{children:o(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`No brokers registered yet. Add one to publish device events for downstream automations.`})}),s.map(e=>o(pe,{broker:e,onEdit:d},e.id))]})]})}),c&&o(de,{kinds:p,onClose:()=>l(!1),onDone:()=>l(!1)}),u&&o(fe,{broker:u,onClose:()=>d(null),onDone:()=>d(null)})]})}function he(e){if(typeof e==`string`)return e;if(typeof e==`object`&&e){let t=e.name;if(typeof t==`string`)return t}return null}function Z(e){let t=e,n=t?.manifest;if(n?.id===void 0)return null;let r=(n.capabilities??[]).map(he).filter(e=>e!==null);return{addonId:n.id,displayName:n.packageDisplayName??n.name??n.id,capNames:r,processState:t?.process?.state??null}}function ge(e,t){return Object.entries(e).filter(([,e])=>e===t).map(([e])=>e)}function _e(e,t){return t.find(t=>e.capNames.includes(t))??null}function Q(e){switch(e){case`running`:return{state:`ok`,label:`running`};case`crashed`:case`failed`:return{state:`error`,label:e};case`stopped`:case`disabled`:return{state:`off`,label:`stopped`};default:return{state:`unknown`,label:e??`unknown`}}}e();var $=1e4,ve=[{kind:`device-export`,label:`Device export`,icon:_,installLabel:`Add export`},{kind:`email`,label:`Email`,icon:ae,installLabel:`Add email provider`},{kind:`broker`,label:`Message brokers`,icon:D,installLabel:`Add broker addon`}];function ye(){let e=g(void 0,{refetchInterval:$}),i=I();return o(z,{icon:ne,title:`Connectivity`,subtitle:`External systems this hub talks to — device exporters, email relays and message brokers.`,groups:n(()=>{let n=(e.data??[]).map(Z).filter(e=>e!==null);return ve.map(e=>{let a=ge(N,e.kind),s=n.flatMap(n=>{let s=_e(n,a);if(s===null)return[];let c=Q(n.processState);return[{id:n.addonId,name:n.displayName,fallbackIcon:e.icon,state:c.state,stateLabel:c.label,render:()=>o(B,{addonId:n.addonId,displayName:n.displayName,capName:s,isActive:n.processState===`running`,badges:t(r,{children:[o(xe,{processState:n.processState}),o(Se,{kind:e.kind,addonId:n.addonId})]}),lead:e.kind===`device-export`?o(v,{addonId:n.addonId}):void 0,panels:be(e.kind,n.addonId,e=>i(`/devices/${e}`))})}]});return{id:e.kind,label:e.label,entries:s,install:{capability:a[0]??e.kind,label:e.installLabel}}})},[e.data,i]),isLoading:e.isLoading,emptyTitle:`No external systems installed`,emptyDescription:`Install an export, email or broker addon to connect this hub to another system.`,legacyGroupParam:`tab`})}function be(e,t,n){return e===`device-export`?[{id:`devices`,title:`Devices`,icon:j,placement:`end`,content:o(ee,{addonId:t,onOpenDevice:n,showSetup:!1})}]:e===`broker`?[{id:`connections`,title:`Connections`,icon:D,content:o(me,{addonId:t})}]:[]}function xe({processState:e}){let{state:t,label:n}=Q(e);return o(E,{variant:t===`ok`?`success`:t===`error`?`danger`:`default`,className:`${R} capitalize`,children:n})}function Se({kind:e,addonId:t}){return e===`broker`?o(Ce,{addonId:t}):e===`device-export`?o(we,{addonId:t}):null}function Ce({addonId:e}){let{data:t}=C({addonId:e},{refetchInterval:$,retry:!1}),n=M.safeParse(t);if(!n.success)return null;let{brokerCount:r,connectedCount:i}=n.data;return o(E,{variant:`info`,className:R,children:`${r} connection${r===1?``:`s`}${i>0?` · ${i} connected`:``}`})}function we({addonId:e}){let{data:t}=d({addonId:e},{refetchInterval:$,retry:!1}),n=P.safeParse(t);if(!n.success)return null;let{linkState:r,exposedDeviceCount:i}=n.data;return o(E,{variant:r===`linked`?`success`:r===`error`?`danger`:`default`,className:R,children:`${r} · ${i} exposed`})}export{ye as IntegrationsPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,X as a,a as o,b as s,o as c,q as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{D as f,Q as p,Z as m,_t as h,c as g,ct as _,f as v,gt as y,l as b,lt as x,ot as S,pt as C,u as w,vt as T,yt as E,z as D}from"./player-overlays-Sm-ivm_8.js";import{$a as O,$n as k,$u as A,Af as j,An as M,At as N,Bl as P,Bn as F,Bt as I,Cc as L,Dn as R,Ga as ee,Hn as z,I as B,In as V,Ja as H,Jd as U,Ka as W,Ld as G,Mn as K,Mu as te,Nd as q,Nn as J,Nt as ne,Nu as re,On as ie,Qa as ae,Qn as oe,Rt as se,Sc as ce,Su as le,Vl as ue,Vn as de,Wd as fe,Xa as pe,Ya as me,Yu as he,Za as ge,Zd as _e,_c as ve,_s as ye,ar as be,bc as xe,bd as Se,bu as Ce,cf as we,dc as Te,ds as Ee,ed as De,eo as Oe,er as ke,fc as Ae,fs as je,gc as Me,ha as Ne,hc as Pe,hs as Fe,jn as Ie,jt as Le,kn as Re,kr as ze,ku as Be,ld as Ve,ls as He,lu as Y,mc as Ue,mn as We,no as Ge,od as Ke,of as qe,or as Je,ou as Ye,pc as Xe,ps as Ze,qa as Qe,ql as X,qo as $e,qu as et,ro as tt,sf as nt,sr as rt,t as it,to as at,uf as ot,ut as st,vc as ct,vs as lt,wu as ut,xc as dt,xd as Z,yc as ft,zn as pt,zt as mt}from"./src-CmnrQw1X.js";import{t as ht}from"./crop-o1ZnayCW.js";import{t as gt}from"./user-round-BLTQwaog.js";import{Un as _t,vi as vt}from"./client-B2uiK_6q.js";import{t as yt}from"./useTranslation-Bc5yH9V9.js";import"./mount-BwPih3Va.js";import{$ as bt,X as xt,Z as St,nt as Ct}from"./index-BlUdDWLp.js";import{t as wt}from"./AdminPage-C1SqQSAP.js";import{t as Tt}from"./HeaderPills-DvZSXIv5.js";import{t as Et}from"./use-stationary-objects-Ba8qX5nf.js";import{a as Dt,i as Ot,n as kt,r as At,t as jt}from"./authed-media-CA36_TYL.js";import{t as Mt}from"./AdminTabs-D_amP_Ho.js";import{t as Nt}from"./use-scenes-feed-CLHMDiWX.js";var Pt=E(`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`}]]),Ft=E(`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`}]]),It=E(`image-plus`,[[`path`,{d:`M16 5h6`,key:`1vod17`}],[`path`,{d:`M19 2v6`,key:`4bpg5p`}],[`path`,{d:`M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5`,key:`1ue2ih`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}]]),Lt=E(`scan-face`,[[`path`,{d:`M3 7V5a2 2 0 0 1 2-2h2`,key:`aa7l1z`}],[`path`,{d:`M17 3h2a2 2 0 0 1 2 2v2`,key:`4qcy5o`}],[`path`,{d:`M21 17v2a2 2 0 0 1-2 2h-2`,key:`6vwrx8`}],[`path`,{d:`M7 21H5a2 2 0 0 1-2-2v-2`,key:`ioqczr`}],[`path`,{d:`M8 14s1.5 2 4 2 4-2 4-2`,key:`1y1vjs`}],[`path`,{d:`M9 9h.01`,key:`1q5me6`}],[`path`,{d:`M15 9h.01`,key:`x1ddxp`}]]),Rt=E(`scan-line`,[[`path`,{d:`M3 7V5a2 2 0 0 1 2-2h2`,key:`aa7l1z`}],[`path`,{d:`M17 3h2a2 2 0 0 1 2 2v2`,key:`4qcy5o`}],[`path`,{d:`M21 17v2a2 2 0 0 1-2 2h-2`,key:`6vwrx8`}],[`path`,{d:`M7 21H5a2 2 0 0 1-2-2v-2`,key:`ioqczr`}],[`path`,{d:`M7 12h10`,key:`b7w52i`}]]),zt=E(`square-check-big`,[[`path`,{d:`M21 10.656V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h12.344`,key:`2acyp4`}],[`path`,{d:`m9 11 3 3L22 4`,key:`1pflzl`}]]),Bt=E(`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`}]]),Vt=E(`user-x`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`17`,x2:`22`,y1:`8`,y2:`13`,key:`3nzzx3`}],[`line`,{x1:`22`,x2:`17`,y1:`8`,y2:`13`,key:`1swrse`}]]);n();function Ht({mediaId:e,base64:t,alt:n,className:r,placeholder:i}){let{src:a,failed:o}=Dt(e===void 0?void 0:At(e));return a===null?(e===void 0||o)&&t!==void 0&&t!==``?u(`img`,{src:`data:image/jpeg;base64,${t}`,alt:n,className:r}):i:u(`img`,{src:a,alt:n,className:r})}var Ut=`pipeline-analytics`,Wt=`photo.analyze`,Gt=`photo.enroll`,Kt=`photo.discard`,qt=18*1024*1024;function Jt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Yt(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Xt(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Zt(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Qt(e){if(!Jt(e))return null;let t=Xt(e,`x`),n=Xt(e,`y`),r=Xt(e,`width`),i=Xt(e,`height`);return t===null||n===null||r===null||i===null?null:{x:t,y:n,width:r,height:i}}function $t(e){if(!Jt(e))return null;let t=Xt(e,`detectionShortSidePx`),n=Xt(e,`score`);if(t===null||n===null)return null;let r=Xt(e,`magnitude`);return{detectionShortSidePx:t,score:n,...r===null?{}:{magnitude:r}}}function en(e){if(!Jt(e))return null;let t=Xt(e,`faceIndex`),n=Xt(e,`score`),r=Zt(e,`enrollable`),i=Qt(e.bbox),a=$t(e.quality);if(t===null||n===null||r===null||i===null||a===null)return null;let o=Yt(e,`refusedReason`),s=Yt(e,`alignedCropBase64`),c=Yt(e,`modelId`);return{faceIndex:t,bbox:i,score:n,enrollable:r,quality:a,...o===null?{}:{refusedReason:o},...s===null?{}:{alignedCropBase64:s},...c===null?{}:{modelId:c}}}function tn(e){if(!Jt(e))return null;let t=Yt(e,`sessionId`),n=Yt(e,`ranOnNodeId`),r=e.faces;if(t===null||n===null||!Array.isArray(r))return null;let i=[];for(let e of r){let t=en(e);t!==null&&i.push(t)}return{sessionId:t,ranOnNodeId:n,faces:i}}function nn(e){if(!Jt(e))return null;let t=Yt(e,`sampleId`),n=Yt(e,`identityId`),r=Yt(e,`modelId`);return t===null||n===null||r===null?null:{sampleId:t,identityId:n,modelId:r}}function rn(e,t,n){let r={...e};return n===null||n===``?delete r[t]:r[t]=n,r}function an(e,t){return e.filter(e=>e.enrollable&&t[e.faceIndex]!==void 0).length}function on(e,t,n){let r=[];for(let i of t){if(!i.enrollable)continue;let t=n[i.faceIndex];t!==void 0&&r.push({sessionId:e,faceIndex:i.faceIndex,identityId:t})}return r}function sn(e){switch(e){case`no-embedding`:return`Too small or too indistinct for the recognizer to measure — try a photo where this face is larger.`;case`no-model-id`:return`The recognizer did not report which model it used, so this face cannot be enrolled safely.`;case`no-aligned-crop`:return`The recognizer produced no aligned crop for this face, so there is nothing to store.`;case`magnitude`:return`Refused by the quality gate: the features look degenerate, and a sample like this matches everybody.`;default:return`This face is not usable as a sample.`}}function cn(e,t){let n=[],r=[];for(let i of e)i.size>t.maxBytes?n.push(i.name):r.push(i);return{accepted:r.slice(0,t.maxCount),oversize:n,overflow:r.slice(t.maxCount).map(e=>e.name)}}async function ln(e,t,n){let r=Array(e.length),i=e.map((e,t)=>({item:e,index:t})),a=0,o=async()=>{for(;;){let e=i[a];if(a+=1,e===void 0)return;r[e.index]=await n(e.item,e.index)}},s=Array.from({length:Math.max(1,Math.min(t,e.length))},()=>o());return await Promise.all(s),r}function un(e,t,n){return e.map(e=>e.photoIndex===t?{...e,...n}:e)}function dn(e,t){return`${e}:${t}`}function fn(e,t,n,r){let i=rn(e[t]??{},n,r),a={...e};return Object.keys(i).length===0?delete a[t]:a[t]=i,a}function pn(e,t){let n=0;for(let r of e)r.analysis!==void 0&&(n+=an(r.analysis.faces,t[r.photoIndex]??{}));return n}var mn=`__new__`;function hn(e,t,n){let r=[];for(let i of e){if(i.analysis===void 0)continue;let e=t[i.photoIndex]??{};for(let t of i.analysis.faces){if(!t.enrollable||e[t.faceIndex]!==`__new__`)continue;let a=(n[dn(i.photoIndex,t.faceIndex)]??``).trim();if(a===``)return{kind:`error`,message:`${i.filename}: face ${t.faceIndex+1} is set to a new person but has no name.`};r.includes(a)||r.push(a)}}return{kind:`ok`,names:r}}function gn(e,t,n){let r={};for(let[i,a]of Object.entries(e)){let e=Number(i),o={};for(let[r,i]of Object.entries(a)){let a=Number(r);if(i!==`__new__`){o[a]=i;continue}let s=n[(t[dn(e,a)]??``).trim()];s!==void 0&&(o[a]=s)}r[e]=o}return r}function _n(e,t){let n=[];for(let r of e){if(r.analysis===void 0)continue;let e=on(r.analysis.sessionId,r.analysis.faces,t[r.photoIndex]??{});for(let t of e)n.push({photoIndex:r.photoIndex,request:t})}return n}function vn(e){return/expired/i.test(e)}function yn(e){return e instanceof Error?e.message:String(e)}async function bn(e,t,n){let r=new Map(e.map(e=>[e.photoIndex,e])),i={},a=[],o=0,s=null,c=(e,t)=>`${r.get(e)?.filename??`photo ${e+1}`}, face ${t+1}`;for(let l of _n(e,t)){let e=i[l.photoIndex],t=e===void 0?l.request:{...l.request,sessionId:e.sessionId};try{let e=await n.enroll(t);o+=1,s=e.modelId}catch(t){let u=yn(t);if(!vn(u)||e!==void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${u}`);continue}let d=r.get(l.photoIndex);if(d===void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${u}`);continue}let f;try{f=await n.reanalyze(d)}catch(e){a.push(`${c(l.photoIndex,l.request.faceIndex)}: the analysis expired and re-analysing failed (${yn(e)})`);continue}if(i[l.photoIndex]=f,f.faces.find(e=>e.faceIndex===l.request.faceIndex&&e.enrollable)===void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: the analysis expired, and re-analysing no longer finds this face — assign it again from the fresh result`);continue}try{let e=await n.enroll({...l.request,sessionId:f.sessionId});o+=1,s=e.modelId}catch(e){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${yn(e)}`)}}}return{enrolled:o,stampedModelId:s,failures:a,refreshedAnalyses:i}}var xn=[[`faceGallery`]],Sn=``;function Cn(e){return new Promise((t,n)=>{let r=new FileReader;r.addEventListener(`error`,()=>n(Error(`the file could not be read`)),{once:!0}),r.addEventListener(`load`,()=>{let e=r.result;if(typeof e!=`string`){n(Error(`the file could not be read`));return}let i=e.indexOf(`,`);t(i>=0?e.slice(i+1):e)},{once:!0}),r.readAsDataURL(e)})}function wn(e){return e instanceof Error?e.message:String(e)}function Tn({face:e,identities:t,value:n,onChange:a,disabled:o}){let c=i(()=>[{value:Sn,label:`Ignore this face`},...t.map(e=>({value:e.id,label:e.name})),{value:mn,label:`+ New person…`}],[t]);return r(`div`,{className:`rounded-md border border-border bg-surface p-2`,children:[u(`div`,{className:`mb-2 aspect-square w-full overflow-hidden rounded border border-border bg-surface-hover`,children:e.alignedCropBase64?u(`img`,{src:`data:image/jpeg;base64,${e.alignedCropBase64}`,alt:`Face ${e.faceIndex+1}`,className:`h-full w-full object-cover`}):u(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:u(gt,{className:`h-8 w-8`})})}),u(`div`,{className:`min-h-[4.75rem]`,children:e.enrollable?r(s,{children:[u(de,{options:c,value:n,disabled:o,onChange:e=>a(e.target.value),"aria-label":`Assign face ${e.faceIndex+1}`}),r(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:[Math.round(e.quality.detectionShortSidePx),` px`,e.modelId?` · ${e.modelId}`:``]})]}):r(`div`,{className:`space-y-1`,children:[u(rt,{variant:`warning`,className:`text-[10px]`,children:`Not usable`}),u(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:sn(e.refusedReason)})]})})]})}function En({photo:e,identities:t,draft:n,newNames:i,disabled:a,onAssign:o,onNameChange:s,onRetry:c}){let l=e.analysis?.faces??[],d=n[e.photoIndex]??{};return r(`div`,{className:`space-y-2`,children:[r(`div`,{className:`flex items-center gap-2 border-b border-border pb-1`,children:[u(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.filename}),e.status===`analyzing`||e.status===`queued`?r(`span`,{className:`flex items-center gap-1 text-xs text-foreground-subtle`,children:[u(Z,{className:`h-3 w-3 animate-spin`}),` analysing…`]}):null,e.status===`analyzed`&&e.analysis!==void 0&&r(`span`,{className:`text-xs text-foreground-subtle`,children:[l.length,` face`,l.length===1?``:`s`,` · analysed on`,` `,e.analysis.ranOnNodeId]}),e.status===`failed`&&r(z,{variant:`secondary`,size:`sm`,disabled:a,onClick:c,children:[u(A,{className:`h-3 w-3`}),` Retry`]})]}),e.status===`failed`&&r(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[u(ut,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),r(`span`,{children:[`This photo could not be analysed: `,e.error??`unknown error`,`. The other photos are unaffected.`]})]}),e.status===`analyzed`&&l.length===0&&u(`p`,{className:`text-xs text-foreground-subtle`,children:`No faces were found in this photo. A face has to be reasonably large and facing the camera for the detector to measure it.`}),l.length>0&&u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(7rem,7rem))] justify-start gap-3`,children:l.map(e=>u(Tn,{face:e,identities:t,value:d[e.faceIndex]??Sn,disabled:a,onChange:t=>o(e.faceIndex,t)},e.faceIndex))}),l.filter(e=>d[e.faceIndex]===mn).map(t=>r(`div`,{className:`flex items-center gap-2`,children:[r(`span`,{className:`w-28 shrink-0 truncate text-xs text-foreground-subtle`,children:[`Face `,t.faceIndex+1]}),u(`input`,{className:`h-7 flex-1 rounded-md border border-border bg-surface px-2.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,placeholder:`New person name… (type the same name under another face to reuse it)`,value:i[dn(e.photoIndex,t.faceIndex)]??``,onChange:e=>s(t.faceIndex,e.target.value)})]},t.faceIndex))]})}function Dn({open:n,onOpenChange:a}){let o=S(),s=c(),d=t(null),{data:f}=pe(),p=W(),[m,h]=l([]),[g,_]=l(!1),[v,y]=l(null),[b,x]=l({}),[C,w]=l({}),[T,E]=l(null),D=i(()=>(f??[]).map(e=>({id:e.id,name:e.name})),[f]),O=m.some(e=>e.status===`queued`||e.status===`analyzing`),k=O||g,A=e(e=>{for(let t of e){let e=t.analysis?.sessionId;e!==void 0&&o.trpcClient.addons.custom.mutate({addonId:Ut,action:Kt,input:{sessionId:e}}).catch(()=>void 0)}},[o]),j=e(()=>{h([]),x({}),w({}),y(null),E(null),d.current&&(d.current.value=``)},[]),N=e(()=>{A(m),j(),a(!1)},[A,a,m,j]),P=e(async e=>{let t=tn(await o.trpcClient.addons.custom.mutate({addonId:Ut,action:Wt,input:{photoBase64:e.photoBase64,filename:e.filename}}));if(t===null)throw Error(`the server replied with something this page could not read`);return t},[o]),F=e(async e=>{h(t=>un(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await P(e);h(n=>un(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){h(n=>un(n,e.photoIndex,{status:`failed`,error:wn(t)}))}},[P]),I=e(async e=>{if(e.length===0)return;A(m),j();let t=cn(e,{maxCount:12,maxBytes:qt}),n=[];t.oversize.length>0&&n.push(`Over the ${Math.round(qt/(1024*1024))} MB limit and skipped: ${t.oversize.join(`, `)}.`),t.overflow.length>0&&n.push(`A batch holds at most 12 photos — not analysed: ${t.overflow.join(`, `)}. Enrol them in a second round.`),n.length>0&&y(n.join(` `));let r;try{r=await Promise.all(t.accepted.map(async(e,t)=>({photoIndex:t,filename:e.name,photoBase64:await Cn(e),status:`queued`})))}catch(e){y(wn(e));return}h(r),await ln(r,2,e=>F(e))},[A,m,j,F]),L=pn(m,b),ee=e(async()=>{_(!0),y(null),E(null);try{let e=hn(m,b,C);if(e.kind===`error`){y(e.message);return}let t={};for(let n of e.names)t[n]=(await p.mutateAsync({name:n})).id;let n=await bn(m,gn(b,C,t),{enroll:async e=>{let t=nn(await o.trpcClient.addons.custom.mutate({addonId:Ut,action:Gt,input:e}));if(t===null)throw Error(`unreadable reply`);return t},reanalyze:e=>P(e)});Object.keys(n.refreshedAnalyses).length>0&&h(e=>e.map(e=>{let t=n.refreshedAnalyses[e.photoIndex];return t===void 0?e:{...e,status:`analyzed`,analysis:t}})),s.invalidateQueries({queryKey:xn}),n.failures.length>0&&y(n.failures.join(` · `)),E(n.enrolled===0?`Nothing was enrolled.`:`Enrolled ${n.enrolled} sample${n.enrolled===1?``:`s`}${n.stampedModelId===null?``:` with ${n.stampedModelId}`}.`)}catch(e){y(wn(e))}finally{_(!1)}},[P,p,b,C,m,s,o]),B=m.filter(e=>e.status===`analyzed`).length;return u(R,{open:n,onOpenChange:e=>e?a(!0):N(),children:r(Re,{className:`max-w-3xl`,children:[r(K,{children:[u(J,{children:`Enrol from photos`}),u(M,{children:`Every photo is analysed with the same face detector the cameras use, and all the faces found are reviewed below in one pass, grouped by photo. Assign each face to a person, or leave it ignored.`})]}),r(`div`,{className:`rounded-md border border-border bg-surface-hover px-3 py-2 text-xs text-foreground-subtle`,children:[`For reliable recognition use `,u(`strong`,{children:`at least 3 photos per person`}),`, taken at different times, with different poses and lighting — you can select them all at once. Several frames from the same moment count as one — they do not add information.`]}),r(`div`,{className:`flex items-center gap-2`,children:[u(`input`,{ref:d,type:`file`,accept:`image/jpeg,image/png,image/webp`,multiple:!0,className:`hidden`,onChange:e=>void I(Array.from(e.target.files??[]))}),r(z,{variant:`secondary`,size:`sm`,disabled:k,onClick:()=>d.current?.click(),children:[O?u(Z,{className:`h-3.5 w-3.5 animate-spin`}):u(It,{className:`h-3.5 w-3.5`}),`Choose photos`]}),m.length>0&&r(`span`,{className:`text-xs text-foreground-subtle`,children:[B,`/`,m.length,` photo`,m.length===1?``:`s`,` analysed`]})]}),u(`div`,{className:`min-h-11`,"aria-live":`polite`,children:v===null?T===null?null:u(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:T}):r(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[u(ut,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),u(`span`,{children:v})]})}),m.length>0&&u(`div`,{className:`max-h-[50vh] space-y-4 overflow-y-auto pr-1`,children:m.map(e=>u(En,{photo:e,identities:D,draft:b,newNames:C,disabled:k,onAssign:(t,n)=>x(r=>fn(r,e.photoIndex,t,n===Sn?null:n)),onNameChange:(t,n)=>w(r=>({...r,[dn(e.photoIndex,t)]:n})),onRetry:()=>void F(e)},e.photoIndex))}),r(Ie,{children:[u(z,{variant:`secondary`,onClick:N,disabled:g,children:`Close`}),r(z,{variant:`primary`,onClick:()=>void ee(),disabled:k||L===0,children:[g?u(Z,{className:`h-3.5 w-3.5 animate-spin`}):null,`Enrol `,L,` face`,L===1?``:`s`]})]})]})})}n();var On=[[`faceGallery`]];function kn({identityId:e}){let t=c(),{data:n,isLoading:i}=ge({identityId:e}),a=O();function o(n){a.mutate({identityId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:On})}})}return i?r(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[u(Z,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!n||n.length===0?u(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):u(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:n.map(e=>r(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?u(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):u(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:u(gt,{className:`h-6 w-6`})}),e.source===`photo`&&u(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 p-0.5 text-white`,title:`Enrolled from an uploaded photo`,children:u(It,{className:`h-3 w-3`})}),u(`button`,{type:`button`,onClick:()=>o(e),disabled:a.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 sample`,children:u(Y,{className:`h-4 w-4 text-white`})})]},e.id))})}function An({identity:e,expanded:t,onToggle:n}){let i=c(),[a,o]=l(``),[d,f]=l(!1),[p,m]=l(!1),g=Oe(),v=H();function b(){o(e.name),f(!0)}function x(){f(!1),o(``)}function S(){let t=a.trim();if(!t||t===e.name){x();return}g.mutate({id:e.id,name:t},{onSettled:()=>{i.invalidateQueries({queryKey:On}),x()}})}function C(){v.mutate({id:e.id},{onSettled:()=>{i.invalidateQueries({queryKey:On}),m(!1)}})}return r(`div`,{className:`rounded-md border border-border bg-surface`,children:[r(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[u(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:u(Ht,{mediaId:e.coverMediaId,base64:e.coverBase64,alt:e.name,className:`h-full w-full object-cover`,placeholder:u(`div`,{className:`flex h-full w-full items-center justify-center`,children:u(gt,{className:`h-4 w-4 text-foreground-subtle`})})})}),u(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:d?r(s,{children:[u(X,{value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&S(),e.key===`Escape`&&x()},className:`h-6 text-xs`,autoFocus:!0}),u(`button`,{type:`button`,onClick:S,disabled:g.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:u(nt,{className:`h-3.5 w-3.5`})}),u(`button`,{type:`button`,onClick:x,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:u(Y,{className:`h-3.5 w-3.5`})})]}):u(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),u(rt,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!d&&r(`div`,{className:`flex items-center gap-1`,children:[u(`button`,{type:`button`,onClick:b,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:u(Ve,{className:`h-3.5 w-3.5`})}),u(`button`,{type:`button`,onClick:()=>m(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:u(_,{className:`h-3.5 w-3.5`})})]}),u(`button`,{type:`button`,onClick:n,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:u(t?h:y,{className:`h-3.5 w-3.5`})})]}),t&&u(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:u(kn,{identityId:e.id})}),u(R,{open:p,onOpenChange:e=>!e&&m(!1),children:r(Re,{children:[r(K,{children:[u(J,{children:`Delete person`}),r(M,{children:[`Delete `,u(`strong`,{children:e.name}),` and all their samples? This cannot be undone.`]})]}),r(Ie,{children:[u(z,{variant:`secondary`,onClick:()=>m(!1),children:`Cancel`}),r(z,{variant:`danger`,onClick:C,disabled:v.isPending,children:[v.isPending?u(Z,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function jn(){let e=c(),[t,n]=l(``),i=W();function a(){let r=t.trim();r&&i.mutate({name:r},{onSettled:()=>{e.invalidateQueries({queryKey:On}),n(``)}})}return r(`div`,{className:`flex items-center gap-2 pt-2`,children:[u(X,{placeholder:`New person name…`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&a()},className:`h-7 text-xs flex-1`}),r(z,{variant:`primary`,size:`sm`,onClick:a,disabled:i.isPending||!t.trim(),children:[i.isPending?u(Z,{className:`h-3.5 w-3.5 animate-spin`}):u(Ke,{className:`h-3.5 w-3.5`}),`Add`]})]})}function Mn(){let{data:e,isLoading:t}=pe(),n=e??[],i=N(n,{searchText:e=>[e.name]}),[a,o]=l(null),[s,c]=l(!1);function d(e){o(t=>t===e?null:e)}return t?r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(Z,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):r(`div`,{className:`space-y-2`,children:[(n.length>0||i.active)&&u(Le,{state:i.state,facets:i.facets,labels:{searchPlaceholder:`Search people…`,searchLabel:`Search people`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:i.setSearch,onToggleFacet:i.toggleFacet,onClear:i.clear}),i.rows.length===0?u(F,{icon:gt,title:i.active?`Nothing matches the filter`:`No people enrolled yet`,description:i.active?`Clear the search or try another name.`:`Add a person below, or enrol faces from a photo.`}):i.rows.map(e=>u(An,{identity:e,expanded:a===e.id,onToggle:()=>d(e.id)},e.id)),u(jn,{}),u(`div`,{className:`pt-1`,children:r(z,{variant:`secondary`,size:`sm`,onClick:()=>c(!0),children:[u(It,{className:`h-3.5 w-3.5`}),`Enrol from a photo`]})}),u(Dn,{open:s,onOpenChange:c})]})}var Nn={fromMs:null,toMs:null},Pn=36e5,Fn=24*Pn;function In(e,t){switch(e){case`24h`:return{fromMs:t-Fn,toMs:null};case`7d`:return{fromMs:t-7*Fn,toMs:null};case`30d`:return{fromMs:t-30*Fn,toMs:null};case`all`:return Nn}}function Ln(e){return e.fromMs!==null||e.toMs!==null}function Rn(e,t){return Ln(t)?e.filter(e=>!(t.fromMs!==null&&e.timestamp<t.fromMs||t.toMs!==null&&e.timestamp>t.toMs)):[...e]}function zn(e,t){return t.size===0?[...e]:e.filter(e=>t.has(e.deviceId))}function Bn(e){let t=new Set,n=[];for(let r of e)t.has(r.deviceId)||(t.add(r.deviceId),n.push(r.deviceId));return n}function Vn(e){if(!e)return null;let t=Date.parse(`${e}T00:00:00`);return Number.isNaN(t)?null:t}function Hn(e){if(!e)return null;let t=Date.parse(`${e}T23:59:59.999`);return Number.isNaN(t)?null:t}function Un(e,t){if(!Number.isFinite(e)||e<=0)return`—`;let n=t-e;return n<6e4?`just now`:n<Pn?`${String(Math.floor(n/6e4))}m ago`:n<Fn?`${String(Math.floor(n/Pn))}h ago`:n<7*Fn?`${String(Math.floor(n/Fn))}d ago`:new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function Wn(e){return!Number.isFinite(e)||e<=0?`—`:new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function Gn(e){return!Number.isFinite(e)||e<=0?`—`:new Date(e).toLocaleString(void 0,{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function Kn(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function qn(e){return e.filter(Kn).map(e=>e.faceId)}function Jn(e){let t=0;for(let n of e)Kn(n)&&(t+=1);return t}function Yn(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}n();function Xn(e,t,n){let[r,a]=l(1);d(()=>{a(1)},[n]);let o=e.length,s=Math.max(1,Math.ceil(o/t)),c=Math.min(r,s);return d(()=>{c!==r&&a(c)},[c,r]),{page:c,setPage:a,pageItems:i(()=>{let n=(c-1)*t;return e.slice(n,n+t)},[e,c,t]),totalPages:s,totalItems:o,pageSize:t}}var Zn=2;function Qn(e,t){if(t<=1)return[{kind:`page`,n:1}];if(t<=7){let e=[];for(let n=1;n<=t;n++)e.push({kind:`page`,n});return e}let n=[],r=Math.max(2,e-Zn),i=Math.min(t-1,e+Zn);n.push({kind:`page`,n:1}),r>2&&n.push({kind:`ellipsis`,side:`left`});for(let e=r;e<=i;e++)n.push({kind:`page`,n:e});return i<t-1&&n.push({kind:`ellipsis`,side:`right`}),n.push({kind:`page`,n:t}),n}function $n({currentPage:e,totalItems:t,pageSize:n,onPageChange:i,itemNoun:a=`items`}){if(t<=n)return null;let o=Math.ceil(t/n),s=(e-1)*n+1,c=Math.min(e*n,t),l=Qn(e,o),d=`inline-flex h-7 min-w-7 items-center justify-center rounded-md px-2 text-[11px] transition-colors disabled:opacity-40`;return r(`div`,{className:`flex items-center justify-between gap-4 flex-wrap pt-2 text-[11px] text-foreground-subtle`,children:[r(`span`,{children:[`Showing `,s,`–`,c,` of `,t,` `,a]}),r(`div`,{className:`flex items-center gap-1`,children:[u(`button`,{type:`button`,className:`${d} hover:bg-surface-hover`,onClick:()=>i(e-1),disabled:e<=1,"aria-label":`Previous page`,children:u(qe,{className:`h-3.5 w-3.5`})}),l.map(t=>t.kind===`ellipsis`?u(`span`,{className:`px-1 opacity-60`,children:`…`},`ellipsis-${t.side}`):u(`button`,{type:`button`,className:`${d} ${t.n===e?`bg-primary/12 text-primary font-medium`:`hover:bg-surface-hover hover:text-foreground`}`,onClick:()=>i(t.n),"aria-current":t.n===e?`page`:void 0,children:t.n},t.n)),u(`button`,{type:`button`,className:`${d} hover:bg-surface-hover`,onClick:()=>i(e+1),disabled:e>=o,"aria-label":`Next page`,children:u(y,{className:`h-3.5 w-3.5`})})]})]})}n();var er=[[`faceGallery`]];function tr({faceIds:e,identities:t,onDone:n}){let i=c(),a=ee(),o=W(),[s,d]=l(``),[f,p]=l(!1),[m,h]=l(null),g=e!==null&&e.length>0,_=e?.length??0;function v(){p(!1),d(``),h(null)}function y(){v(),n()}function b(t){!e||e.length===0||a.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{i.invalidateQueries({queryKey:er}),y()}})}function x(){!e||!s.trim()||o.mutate({name:s.trim()},{onSuccess:e=>{e?.id&&b(e.id)},onError:()=>{i.invalidateQueries({queryKey:er}),y()}})}let S=a.isPending||o.isPending;return u(R,{open:g,onOpenChange:e=>!e&&y(),children:r(Re,{children:[r(K,{children:[u(J,{children:_>1?`Assign ${String(_)} faces to person`:`Assign face to person`}),u(M,{children:`Select an existing person or create a new one.`})]}),u(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>r(`button`,{type:`button`,onClick:()=>h(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${m===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[u(`span`,{className:`font-medium`,children:e.name}),r(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),u(`div`,{className:`min-h-[2.75rem] border-t border-border pt-2`,children:f?u(`div`,{className:`flex items-center gap-2`,children:u(X,{placeholder:`New person name…`,value:s,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&x()},autoFocus:!0,className:`flex-1`})}):u(`button`,{type:`button`,onClick:()=>{h(null),p(!0)},className:`w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle transition-colors hover:border-primary hover:text-primary`,children:`+ New person…`})}),r(Ie,{className:`min-h-[2.75rem]`,children:[u(z,{variant:`secondary`,onClick:y,disabled:S,children:`Cancel`}),f?r(z,{variant:`primary`,onClick:x,disabled:S||!s.trim(),children:[S&&u(Z,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):r(z,{variant:`primary`,onClick:()=>m&&b(m),disabled:S||!m,children:[S&&u(Z,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,_>1?` ${String(_)}`:``]})]})]})})}n();function nr({cameras:e,selected:n,onChange:i}){let[a,o]=l(!1),s=t(null);d(()=>{if(!a)return;function e(e){s.current&&e.target instanceof Node&&!s.current.contains(e.target)&&o(!1)}function t(e){e.key===`Escape`&&o(!1)}return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[a]);function c(e){let t=new Set(n);t.has(e)?t.delete(e):t.add(e),i(t)}let f=n.size,p=f===0?`All cameras`:f===1?e.find(e=>n.has(e.id))?.name??`1 camera`:`${String(f)} cameras`;return r(`div`,{ref:s,className:`relative`,children:[r(`button`,{type:`button`,onClick:()=>o(e=>!e),disabled:e.length===0,className:`flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs transition-colors disabled:opacity-40 ${f>0?`border-primary/40 bg-primary/8 text-primary`:`border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(T,{className:`h-3.5 w-3.5`}),u(`span`,{className:`max-w-[10rem] truncate`,children:p}),u(h,{className:`h-3 w-3 opacity-70`})]}),a&&r(`div`,{className:`absolute left-0 z-30 mt-1 max-h-64 w-[min(15rem,calc(100vw-1.5rem))] overflow-y-auto rounded-md border border-border bg-surface p-1 shadow-lg shadow-black/30`,children:[f>0&&u(`button`,{type:`button`,onClick:()=>i(new Set),className:`mb-1 w-full rounded px-2 py-1 text-left text-[11px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:`Clear selection`}),e.map(e=>{let t=n.has(e.id);return r(`button`,{type:`button`,onClick:()=>c(e.id),className:`flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs transition-colors ${t?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[u(`span`,{className:`flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded-sm border ${t?`border-primary bg-primary text-white`:`border-border`}`,children:t&&u(nt,{className:`h-2.5 w-2.5`})}),u(`span`,{className:`truncate`,children:e.name})]},e.id)})]})]})}n();var rr=[{label:`24h`,value:`24h`},{label:`7d`,value:`7d`},{label:`30d`,value:`30d`},{label:`All`,value:`all`}];function ir({onChange:e}){let[t,n]=l(`all`),[i,a]=l(``),[o,s]=l(``);function c(t){n(t),a(``),s(``),e(In(t,Date.now()))}function d(t,r){n(`custom`),a(t),s(r),e({fromMs:Vn(t),toMs:Hn(r)})}let f=`rounded-md border border-border bg-surface px-2 py-1.5 text-[11px] text-foreground outline-none focus:border-primary [color-scheme:light] dark:[color-scheme:dark]`;return r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:rr.map(e=>u(`button`,{type:`button`,onClick:()=>c(e.value),className:`rounded px-2.5 py-1 text-[11px] 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))}),r(`div`,{className:`flex items-center gap-1`,children:[u(`input`,{type:`date`,"aria-label":`From date`,value:i,max:o||void 0,onChange:e=>d(e.target.value,o),className:`${f} ${t===`custom`&&i?`border-primary/50`:``}`}),u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`→`}),u(`input`,{type:`date`,"aria-label":`To date`,value:o,min:i||void 0,onChange:e=>d(i,e.target.value),className:`${f} ${t===`custom`&&o?`border-primary/50`:``}`})]})]})}function ar(e){return e<0?0:e>1?1:e}function or(e,t,n){if(!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0)return null;let r=ar(e.x/t),i=ar(e.y/n),a=ar((e.x+e.w)/t),o=ar((e.y+e.h)/n);return{x:r,y:i,width:Math.max(0,a-r),height:Math.max(0,o-i)}}n();var sr=2.6;function cr({src:e,alt:t,className:n,overlay:i,fit:a=`contain`}){let[o,s]=l(!1),[c,f]=l(`50% 50%`);d(()=>{s(!1),f(`50% 50%`)},[e]);function p(e){if(!o){let t=e.currentTarget.getBoundingClientRect(),n=(e.clientX-t.left)/t.width*100,r=(e.clientY-t.top)/t.height*100;f(`${String(n)}% ${String(r)}%`)}s(e=>!e)}let m=a===`natural`;return u(`div`,{className:`relative overflow-hidden bg-background ${n??``}`,onClick:p,children:r(`div`,{className:`relative select-none transition-transform duration-200 ease-out ${m?`w-full`:`h-full w-full`} ${o?`cursor-zoom-out`:`cursor-zoom-in`}`,style:{transformOrigin:c,transform:o?`scale(${String(sr)})`:`scale(1)`},children:[u(`img`,{src:e,alt:t,draggable:!1,className:m?`block h-auto w-full object-contain`:`h-full w-full object-contain`}),i]})})}n();function lr(e){let[t,n]=l(null),[r,i]=l(null),[a,o]=l(!1);return d(()=>{if(n(null),i(null),o(!1),e===void 0)return;let t=!1,r=null;return(async()=>{try{let i=await kt(At(e));if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),d(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>o(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function ur(e){let t=e.filter(e=>e.url.length>0);return t.length===0?null:t.find(e=>/crop|face/i.test(e.kind))??t[0]}function dr({label:e,value:t}){return r(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[u(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),u(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:t})]})}function fr({box:e}){return u(`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:u(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Face`})})}function pr({face:e,cameraName:t,onClose:n,onAssign:a,onUnassign:o,onDelete:s,actionsPending:c}){let{data:d,isFetching:f}=me({faceId:e?.faceId??``},{enabled:e!==null}),[p,m]=l(`frame`),{frameSrc:h,naturalWidth:g,naturalHeight:v,failed:y}=lr(e?.keyFrameMediaId),b=i(()=>{let t=ur(d??[]);return t?t.url:Yn(e)},[d,e]),x=i(()=>!e?.faceBbox||g===null||v===null?null:or(e.faceBbox,g,v),[e?.faceBbox,g,v]);if(e===null)return null;let S=e.keyFrameMediaId!==void 0&&!y,w=S&&p===`frame`,T=e.assigned?e.identityName??`Assigned`:e.recognizedIdentityId?`${e.identityName??`Recognized`} (suggested)`:`Unassigned`;return u(R,{open:!0,onOpenChange:e=>!e&&n(),children:r(Re,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Face detail`,className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[u(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:r(`div`,{className:`min-w-0`,children:[u(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:`Face detail`}),u(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]})}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[S&&r(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[r(`button`,{type:`button`,onClick:()=>m(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${p===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(he,{className:`h-3.5 w-3.5`}),` Full frame`]}),r(`button`,{type:`button`,onClick:()=>m(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${p===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(ht,{className:`h-3.5 w-3.5`}),` Crop`]})]}),w&&h?u(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:u(cr,{src:h,alt:`Full frame with detected face`,fit:`natural`,className:`w-full`,overlay:x?u(fr,{box:x}):void 0})}):b?r(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[u(cr,{src:b,alt:`Detected face`,className:`h-full w-full`}),f&&u(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:u(Z,{className:`h-3.5 w-3.5 animate-spin`})})]}):r(`div`,{className:`flex aspect-square w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[u(C,{className:`h-8 w-8 text-warning/70`}),u(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),u(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:`The crop media for this face could not be resolved (a pre-fix orphan). Safe to delete.`})]}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[u(dr,{label:`Camera`,value:t}),u(dr,{label:`Captured`,value:Gn(e.timestamp)}),u(dr,{label:`Track`,value:e.trackId}),u(dr,{label:`Identity`,value:T})]})]}),r(`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?r(z,{variant:`secondary`,onClick:()=>o(e.faceId),disabled:c,children:[u(Vt,{className:`h-3.5 w-3.5`}),` Detach`]}):r(z,{variant:`primary`,onClick:()=>a(e.faceId),disabled:c,children:[u(Ce,{className:`h-3.5 w-3.5`}),` Assign`]}),r(z,{variant:`secondary`,onClick:()=>s(e.faceId),disabled:c,children:[u(_,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}function mr(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function hr(e,t){return e.faceIds.filter(e=>!t.has(e))}function gr(e,t){return e.faceIds.filter(e=>t(e))}n();var _r=[[`faceGallery`]],vr=20,yr=.3,br=.9,xr=.05,Sr=.5,Cr=2,wr=10,Tr=2;function Er({cluster:e,face:t,active:n,onSelect:i}){let a=Yn(t);return r(`button`,{type:`button`,onClick:i,className:`flex shrink-0 flex-col items-center gap-1.5 rounded-md border p-2 text-center transition-colors md:w-full md:flex-row md:gap-2.5 md:text-left ${n?`border-primary bg-primary/8`:`border-border bg-surface hover:bg-surface-hover`}`,children:[u(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:a===null?u(C,{className:`h-24 w-24 p-6 text-foreground-subtle`}):u(`img`,{src:a,alt:``,loading:`lazy`,decoding:`async`,className:`h-24 w-24 object-cover`})}),r(`span`,{className:`w-24 text-[11px] leading-tight text-foreground-subtle md:w-auto`,children:[e.size,` faces · `,Math.round(e.cohesion*100),`% alike`]})]})}function Dr({face:e,cameraName:t,nowMs:n,excluded:i,onToggleExclude:a,onDelete:o,deletePending:s}){let c=Yn(e);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${i?`border-border opacity-40 grayscale`:`border-border`}`,children:[r(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[c===null?r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[u(C,{className:`h-7 w-7 text-warning/70`}),u(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):u(cr,{src:c,alt:`Face from ${t}`,className:`h-full w-full`}),u(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},className:`absolute right-1 top-1 z-10 rounded-full bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Include face`:`Exclude face`,title:i?`Include`:`Exclude`,children:u(i?le:Y,{className:`h-3.5 w-3.5`})})]}),r(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[u(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),u(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:Un(e.timestamp,n)})]}),u(`div`,{className:`mt-1 flex min-h-[2rem] items-center justify-end border-t border-border/60 px-1 py-0.5`,children:u(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},disabled:s,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete face`,title:`Delete face`,children:s?u(Z,{className:`h-4 w-4 animate-spin`}):u(_,{className:`h-4 w-4`})})})]})}function Or({open:e,onClose:t,byId:n,cameraName:a,nowMs:o,identities:f,selectMany:p}){let m=c(),h=k(),g=Qe(),[_,v]=l(Sr),[y,b]=l(Tr),[x,S]=l(null),[C,w]=l({}),[T,E]=l(null),{data:D,isFetching:O,refetch:A}=at({threshold:_,minClusterSize:y,limit:vr},{enabled:e}),j=D??[];d(()=>{w({})},[_,y]),d(()=>{if(j.length===0){S(null);return}j.some(e=>e.representativeFaceId===x)||S(j[0]?.representativeFaceId??null)},[j]);let M=i(()=>j.find(e=>e.representativeFaceId===x)??null,[j,x]),N=M?C[M.representativeFaceId]??new Set:new Set,P=i(()=>M?gr(M,e=>n.has(e)):[],[M,n]),F=M?M.faceIds.length-P.length:0,I=M?hr({...M,faceIds:P},N):[];function L(e){if(!M)return;let t=M.representativeFaceId;w(n=>({...n,[t]:mr(n[t]??new Set,e)}))}function ee(){m.invalidateQueries({queryKey:_r})}async function B(e){await h({title:`Delete face`,message:`Permanently deletes this face crop. This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&g.mutate({faceId:e},{onSettled:ee})}function V(){E(null),t()}function H(){I.length!==0&&(p(I),V())}return r(R,{open:e,onOpenChange:e=>!e&&V(),children:[r(Re,{placement:`sheet-on-mobile`,width:`lg`,"aria-label":`Look-alike groups`,className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 md:max-w-4xl`,children:[r(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border py-3 pl-4 pr-10`,children:[r(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[u(re,{className:`h-4 w-4 text-primary`}),` Look-alike groups`]}),r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[r(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Threshold`,u(`input`,{type:`range`,min:yr,max:br,step:xr,value:_,onChange:e=>v(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),u(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:_.toFixed(2)})]}),r(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Min size`,u(`input`,{type:`number`,min:Cr,max:wr,step:1,value:y,onChange:e=>b(Math.min(wr,Math.max(Cr,Number(e.target.value)||Cr))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),r(z,{variant:`secondary`,onClick:()=>{w({}),A()},disabled:O,children:[O?u(Z,{className:`h-3.5 w-3.5 animate-spin`}):u(De,{className:`h-3.5 w-3.5`}),`Re-analyze`]})]})]}),u(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:O&&j.length===0?r(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[u(Z,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):j.length===0?u(`div`,{className:`flex flex-1 items-center justify-center py-8 text-xs text-foreground-subtle`,children:`No look-alike groups at this threshold.`}):r(s,{children:[u(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:j.map(e=>u(Er,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===x,onSelect:()=>S(e.representativeFaceId)},e.representativeFaceId))}),u(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:j.map(e=>u(Er,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===x,onSelect:()=>S(e.representativeFaceId)},e.representativeFaceId))}),u(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:M&&r(s,{children:[F>0&&r(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:[F,` not loaded — excluded from actions`]}),u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,13rem))] justify-start gap-2`,children:P.map(e=>{let t=n.get(e);return t?u(Dr,{face:t,cameraName:a(t.deviceId),nowMs:o,excluded:N.has(e),onToggleExclude:()=>L(e),onDelete:()=>void B(e),deletePending:g.isPending&&g.variables?.faceId===e},e):null})})]})})]})}),r(`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:[u(z,{variant:`secondary`,onClick:H,disabled:I.length===0,children:`Select in gallery`}),r(z,{variant:`primary`,onClick:()=>E(I),disabled:I.length===0,children:[u(Ce,{className:`h-3.5 w-3.5`}),` Adopt (`,I.length,`)`]})]})]}),u(tr,{faceIds:T,identities:f,onDone:()=>E(null)})]})}n();var kr=[[`faceGallery`]],Ar=500,jr=120;function Mr({face:e,cameraName:t,nowMs:n,selected:i,onToggleSelect:a,onAssign:o,onOpenDetail:s}){let l=c(),d=Ge(),f=Qe(),p=()=>{l.invalidateQueries({queryKey:kr})},m=()=>s(e.faceId),h=Yn(e);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[r(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[h===null?r(`button`,{type:`button`,onClick:m,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 face's crop media is missing (a pre-fix orphan). Safe to delete.`,children:[u(C,{className:`h-7 w-7 text-warning/70`}),u(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):u(`img`,{src:h,alt:`Face from ${t}`,onClick:m,loading:`lazy`,decoding:`async`,className:`h-full w-full cursor-zoom-in object-cover`}),u(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(e.faceId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Deselect`:`Select`,children:i?u(zt,{className:`h-4 w-4 text-primary`}):u(x,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[u(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),u(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:Un(e.timestamp,n)}),u(`p`,{className:`min-h-[0.875rem] truncate text-[10px] font-medium leading-tight ${e.identityName?`text-primary`:`invisible`}`,title:e.identityName,children:e.identityName??`\xA0`})]}),r(`div`,{className:`mt-1 flex min-h-[2rem] items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?u(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),d.mutate({faceId:e.faceId},{onSettled:p})},disabled:d.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":`Detach face`,title:`Detach`,children:d.isPending?u(Z,{className:`h-4 w-4 animate-spin`}):u(Vt,{className:`h-4 w-4`})}):u(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(e.faceId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":`Assign face to person`,title:`Assign to person`,children:u(Ce,{className:`h-4 w-4`})}),u(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),f.mutate({faceId:e.faceId},{onSettled:p})},disabled:f.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 face`,title:`Delete face`,children:f.isPending?u(Z,{className:`h-4 w-4 animate-spin`}):u(_,{className:`h-4 w-4`})})]})]})}var Nr=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function Pr(){let e=c(),[t,n]=l(`all`),[a,o]=l(Nn),[d,f]=l(new Set),[p,m]=l(new Set),[h,g]=l(null),[v,y]=l(!1),[b,x]=l(null),{data:S,isLoading:w}=ae({limit:Ar,filter:t,includeCrops:!1},{refetchInterval:3e4}),{data:T=[]}=pe(),{data:E}=Ne({isCamera:!0,projection:`slim`}),D=ee(),O=Ge(),k=tt(),A=Qe(),j=Date.now(),M=S??[],N=i(()=>{let e=new Map;for(let t of E??[])e.set(t.id,t.name);return e},[E]),P=e=>N.get(e)??`Camera #${String(e)}`,I=i(()=>Bn(M).map(e=>({id:e,name:P(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[M,N]),L=i(()=>zn(Rn(M,a),d),[M,a,d]),R=Xn(L,jr,i(()=>JSON.stringify([t,a.fromMs,a.toMs,[...d].sort((e,t)=>e-t)]),[t,a.fromMs,a.toMs,d])),V=i(()=>new Map(M.map(e=>[e.faceId,e])),[M]),H=i(()=>Jn(L),[L]),U=b===null?null:V.get(b)??null,W=()=>{e.invalidateQueries({queryKey:kr})},G=()=>m(new Set);function K(e){m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function te(e){m(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function q(){te(qn(L))}let J=[...p],ne=D.isPending||k.isPending||A.isPending,ie=O.isPending||A.isPending;function oe(){J.length!==0&&k.mutate({faceIds:J},{onSettled:()=>{W(),G()}})}function se(){J.length!==0&&Promise.allSettled(J.map(e=>A.mutateAsync({faceId:e}))).then(()=>{W(),G()})}function ce(e){x(null),g([e])}function le(e){O.mutate({faceId:e},{onSettled:W}),x(null)}function ue(e){A.mutate({faceId:e},{onSettled:W}),x(null)}let de=L.length!==M.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(`div`,{className:`flex items-center gap-1`,children:Nr.map(e=>u(`button`,{type:`button`,onClick:()=>n(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))}),u(ir,{onChange:o}),u(nr,{cameras:I,selected:d,onChange:f}),r(`button`,{type:`button`,onClick:()=>y(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${v?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(re,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!w&&H>0&&r(`button`,{type:`button`,onClick:q,className:`ml-auto flex items-center gap-1 rounded-md px-2.5 py-1 text-xs text-warning/90 transition-colors hover:bg-warning/10`,title:`Select every visible face whose crop image is missing so you can delete the orphans in one pass`,children:[u(C,{className:`h-3.5 w-3.5`}),` Select `,H,` crop-less`]}),!w&&u(`span`,{className:`text-[10px] text-foreground-subtle ${H>0?`ml-2`:`ml-auto`}`,children:de?`${String(L.length)} of ${String(M.length)} faces`:`${String(L.length)} face${L.length===1?``:`s`}`})]}),p.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:[p.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[r(z,{variant:`primary`,onClick:()=>g(J),disabled:ne,children:[u(Ce,{className:`h-3.5 w-3.5`}),` Assign`]}),r(z,{variant:`secondary`,onClick:oe,disabled:ne,children:[k.isPending?u(Z,{className:`h-3.5 w-3.5 animate-spin`}):u(Vt,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),r(z,{variant:`secondary`,onClick:se,disabled:ne,children:[u(_,{className:`h-3.5 w-3.5`}),` Delete`]}),u(z,{variant:`ghost`,onClick:G,disabled:ne,children:u(Y,{className:`h-3.5 w-3.5`})})]})]}),w?u(B,{status:`pending`,pendingMessage:`Loading faces…`,testId:`faces-grid`}):L.length===0?u(F,{icon:C,title:M.length>0?`Nothing matches the filter`:`No faces found for this filter`,description:M.length>0?`Widen the date range or clear the camera filter.`:`Face crops appear here when the detection pipeline captures them.`}):r(s,{children:[u(B,{status:`ready`,testId:`faces-grid`,className:`grid-cols-[repeat(auto-fill,minmax(6.5rem,6.5rem))] justify-start`,children:R.pageItems.map(e=>u(Mr,{face:e,cameraName:P(e.deviceId),nowMs:j,selected:p.has(e.faceId),onToggleSelect:K,onAssign:e=>g([e]),onOpenDetail:x},e.faceId))}),u($n,{currentPage:R.page,totalItems:R.totalItems,pageSize:R.pageSize,onPageChange:R.setPage,itemNoun:`faces`})]}),u(pr,{face:U,cameraName:U?P(U.deviceId):``,onClose:()=>x(null),onAssign:ce,onUnassign:le,onDelete:ue,actionsPending:ie}),u(tr,{faceIds:h,identities:T,onDone:()=>{g(null),G()}}),u(Or,{open:v,onClose:()=>y(!1),byId:V,cameraName:P,nowMs:j,identities:T,selectMany:te})]})}function Fr(e){let{delayMs:t,invalidate:n,setTimeoutFn:r=setTimeout,clearTimeoutFn:i=clearTimeout}=e,a;function o(){a===void 0&&(a=r(()=>{a=void 0,n()},t))}function s(){a!==void 0&&(i(a),a=void 0)}return{trigger:o,cancel:s}}n();var Ir=[[`faceGallery`]],Lr=2e3;function Rr(){let e=c(),n=t(e);n.current=e;let r=t(void 0);r.current||=Fr({delayMs:Lr,invalidate:()=>{n.current.invalidateQueries({queryKey:Ir})}}),d(()=>()=>r.current?.cancel(),[]),Ye(vt.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function zr(){return Rr(),r(`div`,{className:`space-y-3`,children:[u(se,{headingId:`library-people`,title:`People`,icon:gt,testId:`library-section-people`,children:r(`div`,{className:`${f} space-y-3`,children:[u(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:`Enrolled identities used for face recognition. Expand a row to view or remove training samples.`}),u(Mn,{})]})}),u(se,{headingId:`library-recent-faces`,title:`Recent detected faces`,icon:Lt,testId:`library-section-recent-faces`,children:r(`div`,{className:`${f} space-y-3`,children:[u(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:`Face crops captured by the detection pipeline. Assign them to a person to build recognition training data.`}),u(Pr,{})]})})]})}function Br(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 Vr=720*60*60*1e3;function Hr(e){let t=[];for(let n of e)t.push(...n);return t}function Ur(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function Wr(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 Gr(e,t){return`${String(e)}:${t}`}function Kr(e,t){let n=new Map,r=new Set;for(let i of e){let e=Gr(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 qr(e,t){return{since:e.fromMs??t-Vr,until:e.toMs??t}}var Jr=[`native`,`raster`,`standin`];function Yr(e){return Jr.some(t=>t===e)}var Xr={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 Zr(e){return e===`standin`?Xr.standin:e===`raster`?Xr.raster:null}var Qr={"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 $r(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:Qr[r]??r,detail:i,raw:t}}function ei(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 ti({row:e,cameraName:t,nowMs:n,onOpenDetail:i,selected:a=!1,onToggleSelect:o,score:s,provenance:c,footer:l}){let d=Dt(e.mediaId===void 0?Ot(`track`,e.trackId):At(e.mediaId)),f=Math.round(e.importance*100),p=s===void 0?void 0:Math.round(s*100),m=ei(e.windowMs),h=()=>i(e),g=Zr(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?u(`img`,{src:d.src,alt:`Event from ${t}`,onClick:h,className:`h-full w-full cursor-zoom-in object-cover`}):u(`button`,{type:`button`,onClick:h,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:u(C,{className:`h-6 w-6 opacity-60`})}),o&&u(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(Gr(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?u(zt,{className:`h-4 w-4 text-primary`}):u(x,{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&&u(`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)}),g!==null&&u(`span`,{className:`absolute bottom-1 right-1 z-10 rounded px-1.5 py-0.5 text-[10px] font-semibold text-white ${g.tone===`warning`?`bg-warning/90`:`bg-black/70`}`,title:g.title,children:g.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&&u(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Marked for training`,"aria-label":`Marked for training`,children:u(q,{className:`h-3 w-3`})}),e.retrainStatus===`trained`&&e.markForTrain!==!0&&u(`span`,{className:`rounded bg-success/85 p-0.5 text-white`,title:`Training complete`,"aria-label":`Training complete`,"data-testid":`retrain-status-trained`,children:u(nt,{className:`h-3 w-3`})}),e.debug===!0&&u(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:`Flagged for debug`,"aria-label":`Flagged for debug`,children:u(ot,{className:`h-3 w-3`})}),e.favourited===!0&&u(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Favourited`,"aria-label":`Favourited`,children:u(te,{className:`h-3 w-3`})})]})]}),r(`button`,{type:`button`,onClick:h,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,Br(e)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,Br(e)]}):null]}),u(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),r(`div`,{className:`flex items-center justify-between gap-2`,children:[u(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:Un(e.timestamp,n)}),m&&u(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:m})]})]}),l!==void 0&&u(`div`,{className:`px-2 pb-1.5`,children:l})]})}n();var ni=1400,ri=`Admin-gated URL — opens only inside an authenticated session`;function ii({label:t,value:n,title:i}){let[a,o]=l(!1),s=ke();return d(()=>{if(!a)return;let e=setTimeout(()=>o(!1),ni);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:[u(a?nt:U,{className:`h-2.5 w-2.5 shrink-0`}),u(`span`,{className:`truncate`,children:a?`Copied`:t})]})}function ai({localUrl:e,publicUrl:t}){return r(`div`,{className:`flex flex-wrap gap-1`,children:[u(ii,{label:`Local`,value:e,title:`Copy LAN URL — ${ri}`}),t&&u(ii,{label:`Public`,value:t,title:`Copy public URL — ${ri}`})]})}var oi={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 si(e){return e in oi}function ci(e){return si(e)?oi[e]:e}function li(e,t){return`${e}${t}`}n();var ui=3e4;function di(t){let[n,r]=l(null),i=e(e=>{r(t=>t??e)},[]);return d(()=>{t||r(null)},[t]),{publicOrigin:n,probes:t?u(fi,{onOrigin:i}):null}}function fi({onOrigin:e}){let{data:t}=ze({capName:`network-access`});return u(s,{children:(t??[]).map(t=>u(pi,{addonId:t.addonId,onOrigin:e},t.addonId))})}function pi({addonId:e,onOrigin:t}){let{data:n}=$e({addonId:e},{refetchInterval:ui,retry:!1});return d(()=>{let e=n?_t.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 mi=typeof lt==`function`,hi=`Track flags arrive with the next server update`;function gi(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var _i=mi?lt:gi;function vi(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 yi({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:[u(`span`,{className:n?`text-primary`:`text-foreground-subtle`,children:o}),r(`span`,{className:`min-w-0 flex-1`,children:[u(`span`,{className:`block text-[11px] font-medium text-foreground`,children:e}),u(`span`,{className:`block text-[10px] text-foreground-subtle`,children:t})]}),u(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${n?`bg-primary`:`bg-border`}`,children:u(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${n?`translate-x-3`:``}`})})]})}function bi({deviceId:e,trackId:t,markForTrain:n,debug:i,favourited:a,onChange:o}){let s=_i(),c=oe(),[d,f]=l(null),p=d?.markForTrain??n===!0,m=d?.debug??i===!0,h=d?.favourited??a===!0,g=!mi||s.isPending,_=mi?void 0:hi,v=n=>{g||(async()=>{try{let r=vi(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 c({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:[u(yi,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:p,disabled:g,..._===void 0?{}:{title:_},icon:u(q,{className:`h-4 w-4`}),onToggle:()=>v({markForTrain:!p})}),u(yi,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:m,disabled:g,..._===void 0?{}:{title:_},icon:u(ot,{className:`h-4 w-4`}),onToggle:()=>v({debug:!m})}),u(yi,{label:`Favourited`,hint:`Keeps this track and its media past retention`,checked:h,disabled:g,..._===void 0?{}:{title:_},icon:u(te,{className:`h-4 w-4`}),onToggle:()=>v({favourited:!h})})]})}var xi=100,Si=120,Ci={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},wi=e=>e<0?0:e>1?1:e,Ti=e=>Math.round(e*100)/100;function Ei(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 Di(e,t,n){if(e.length===0||t===null)return Ci;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return Ci;let a=Ei(e,n?.maxPoints??Si).map(e=>({x:Ti(wi(e.x/r)*xi),y:Ti(wi(e.y/i)*xi)})),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:Ti(wi(e.x/r)*xi),y:Ti(wi(e.y/i)*xi),mediaId:e.mediaId})),u=null,d=-1;for(let t of e){let e=wi(t.bbox.w/r)*wi(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Ti(wi(u.bbox.x/r)*xi),y:Ti(wi(u.bbox.y/i)*xi),w:Ti(wi(u.bbox.w/r)*xi),h:Ti(wi(u.bbox.h/i)*xi)}:null}}var Oi=typeof He==`function`,ki=`Track deletion arrives with the next server update`;function Ai(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var ji=Oi?He:Ai;n();var Mi=15e3,Ni=m();function Pi({url:e,label:t}){let{src:n,failed:r}=Dt(e);return n===null?u(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?u(C,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):u(Z,{className:`h-4 w-4 animate-spin text-foreground-subtle opacity-70`})}):u(`img`,{src:n,alt:t,className:`h-full w-full object-cover`})}var Fi=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),Ii=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`,`sceneFrame`,`lastSceneFrame`]);function Li(e){let[t,n]=l(null);return d(()=>{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 Ri({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&&u(`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&&u(`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)=>u(`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)=>u(`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:u(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${String(e.mediaId)}-${String(n)}`)),e.start&&u(`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&&u(`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 zi({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:[u(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),u(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function Bi({row:t,cameraName:n,deleteAvailable:a,onClose:o,onDeleted:c,onFlagsChanged:f}){let p=S(),m=oe(),h=k(),g=ji(),v=t!==null,y=t?.deviceId??0,b=t?.trackId??``,x=t?.timestamp??0,w=t?.windowMs??0,{data:T}=Ee({deviceId:y,trackId:b},{enabled:v}),{data:E}=Fe({trackId:b,deviceId:y},{enabled:v}),D=T?.bestEventId===void 0?void 0:Number(T.bestEventId),{data:O}=Ze({ownerType:`object`,eventId:D??0,deviceId:y},{enabled:v&&D!==void 0&&Number.isFinite(D)}),{data:A}=ue({deviceId:y},{enabled:v}),j=(A??[]).find(e=>e.addonId!==void 0)?.addonId,{data:M}=P({deviceId:y,since:x-Mi,until:x+w+Mi,provider:j??``},{enabled:v&&j!==void 0}),[N,F]=l(null),[I,L]=l(!1),{publicOrigin:ee,probes:B}=di(v);d(()=>{F(null)},[y,b]);let V=i(()=>{let e=E??[],t=O??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[E,O]),H=N??V,U=Dt(H?H.url:void 0),W=i(()=>{let e=new Set,t=[];for(let n of[...O??[],...E??[]])e.has(n.mediaId)||(e.add(n.mediaId),t.push(n));return t},[O,E]),K=i(()=>W.find(e=>Fi.has(e.kind))??null,[W]),te=Li(Dt(K?K.url:void 0).src),q=i(()=>Di(T?.positions??[],te,{snapshots:(T?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaId:e.mediaId}))}),[T?.positions,T?.snapshots,te]),J=e(e=>{let t=W.find(t=>t.mediaId===e);t&&F(t)},[W]);if(t===null)return null;let ne=U.src,re=H?.kind,ie=re!==void 0&&Ii.has(re)&&te!==null&&(T?.positions.length??0)>=2,ae=M&&M.length>0?M[0]:null,se=()=>{ae&&(L(!0),(async()=>{try{let e=await p.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:ae.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{m({title:`Clip unavailable`,message:`Could not resolve clip playback. Check the server logs.`,variant:`warning`})}finally{L(!1)}})())},ce=()=>{!a||g.isPending||(async()=>{if(await h({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 g.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),c()}catch{await m({title:`Delete failed`,message:`Failed to delete this track. Check the server logs.`,variant:`danger`})}})()},le=Math.round(t.importance*100),de=T?.importanceReason?`${String(le)}% · ${T.importanceReason}`:`${String(le)}%`,fe=T?.zonesVisited&&T.zonesVisited.length>0?T.zonesVisited.join(`, `):`—`,pe=T?.audioLabels&&T.audioLabels.length>0?T.audioLabels:t.audioLabels&&t.audioLabels.length>0?t.audioLabels:void 0,me=pe===void 0?`—`:pe.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `),he=T?T.totalDistance.toFixed(2):`—`,ge=$r(T?.previewMissReason),_e=Gn(T?T.firstSeen:x),ve=T?Gn(T.lastSeen):`—`;return u(R,{open:!0,onOpenChange:e=>!e&&o(),children:r(Re,{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:[u(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[t.className,Br(t)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,Br(t)]}):null]}),u(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:n})]})}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[ne?u(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:u(cr,{src:ne,alt:`Key frame from ${n}`,fit:`natural`,className:`w-full`,overlay:ie?u(Ri,{overlay:q,onPickSnapshot:J}):void 0})}):u(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:U.failed?r(s,{children:[u(C,{className:`h-8 w-8 opacity-60`}),u(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):u(Z,{className:`h-6 w-6 animate-spin opacity-70`})}),W.length>0&&u(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:W.map(e=>{let t=ci(e.kind),n=li(Ni,e.url),i=ee?li(ee,e.url):null;return r(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[u(`button`,{type:`button`,onClick:()=>F(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${t} · ${Gn(e.timestamp)}`,children:u(Pi,{url:e.url,label:t})}),r(`figcaption`,{className:`min-w-0 px-0.5`,children:[u(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:t,children:t}),u(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:Gn(e.timestamp),children:Wn(e.timestamp)})]}),u(ai,{localUrl:n,publicUrl:i})]},e.mediaId)})}),B,ae&&r(z,{variant:`secondary`,onClick:se,disabled:I,children:[I?u(Z,{className:`h-3.5 w-3.5 animate-spin`}):u(G,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),u(bi,{deviceId:t.deviceId,trackId:t.trackId,...(T?.markForTrain??t.markForTrain)===void 0?{}:{markForTrain:T?.markForTrain??t.markForTrain},...(T?.debug??t.debug)===void 0?{}:{debug:T?.debug??t.debug},...(T?.favourited??t.favourited)===void 0?{}:{favourited:T?.favourited??t.favourited},onChange:f}),ge!==null&&r(`div`,{className:`rounded-lg border border-warning/40 bg-warning/8 px-3 py-2`,children:[u(`p`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Best shot`}),u(`p`,{className:`mt-0.5 text-xs text-foreground`,children:ge.sentence}),u(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:ge.raw})]}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[u(zi,{label:`Camera`,value:n}),u(zi,{label:`Class`,value:t.className}),u(zi,{label:`Label`,value:t.label??`—`}),u(zi,{label:`Sub-label`,value:t.subLabel??`—`}),u(zi,{label:`Importance`,value:de}),u(zi,{label:`Zones visited`,value:fe}),u(zi,{label:`Audio heard`,value:me}),u(zi,{label:`Total distance`,value:he}),u(zi,{label:`First seen`,value:_e}),u(zi,{label:`Last seen`,value:ve}),u(zi,{label:`Track`,value:t.trackId,mono:!0})]})]}),u(`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:u(`span`,{title:a?void 0:ki,children:r(z,{variant:`secondary`,onClick:ce,disabled:!a||g.isPending,children:[g.isPending?u(Z,{className:`h-3.5 w-3.5 animate-spin`}):u(_,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}var Vi={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`},Hi={setRelation:`debug.gt.setRelation`,setPurity:`debug.gt.setPurity`,list:`debug.gt.list`},Ui=p(`/addon/pipeline-analytics/tape-export`),Wi=10*6e4;function Gi(e){return`${Ui}?tapeId=${encodeURIComponent(e)}`}var Ki=`The server answered in a shape this build does not understand.`;function qi(e){return e instanceof Error?e.message:`The action failed.`}function Ji(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Yi(e,t){if(!(t in e))return;let n=e[t];return n===null?null:typeof n==`number`&&Number.isFinite(n)?n:void 0}function $(e,t){let n=e[t];return typeof n==`string`?n:null}function Xi(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Zi(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 Qi(e){return e===`off`||e===`recording`||e===`refused`||e===`failing`||e===`unknown`}function $i(e){if(!Ji(e))return null;let t=Q(e,`deviceId`),n=e.state,r=Q(e,`gapsSinceArmed`),i=Yi(e,`segmentsHeld`),a=Yi(e,`bytesLastHour`),o=Yi(e,`bytesHeld`);if(t===null||!Qi(n)||r===null||i===void 0||a===void 0||o===void 0)return null;let s=$(e,`reason`),c=Q(e,`segmentOriginMs`),l=Q(e,`framesPerMin`),u=Q(e,`heldFromMs`),d=Q(e,`heldToMs`),f=$(e,`shelfError`);return{deviceId:t,state:n,gapsSinceArmed:r,segmentsHeld:i,bytesLastHour:a,bytesHeld:o,...s===null?{}:{reason:s},...c===null?{}:{segmentOriginMs:c},...l===null?{}:{framesPerMin:l},...u===null?{}:{heldFromMs:u},...d===null?{}:{heldToMs:d},...f===null?{}:{shelfError:f}}}function ea(e){return Ji(e)?Zi(e.cameras,$i):null}function ta(e){if(!Ji(e))return null;let t=$(e,`id`),n=Q(e,`deviceId`),r=$(e,`scenario`),i=e.lighting,a=Q(e,`fromMs`),o=Q(e,`toMs`),s=e.state,c=Q(e,`frames`),l=Q(e,`gaps`),u=Q(e,`bytes`),d=Xi(e,`reviewed`),f=Xi(e,`released`),p=Zi(e.tracks,e=>typeof e==`string`?e:null),m=Q(e,`tracksStillStored`);return t===null||n===null||r===null||i!==`day`&&i!==`ir`||a===null||o===null||s!==`complete`&&s!==`incomplete`||c===null||l===null||u===null||d===null||f===null||p===null||m===null?null:{id:t,deviceId:n,scenario:r,note:$(e,`note`),lighting:i,fromMs:a,toMs:o,state:s,frames:c,gaps:l,bytes:u,reviewed:d,released:f,tracks:p,tracksStillStored:m}}function na(e){return Ji(e)?Zi(e.tapes,ta):null}function ra(e){if(!Ji(e))return null;let t=$(e,`trackId`),n=Q(e,`firstT`),r=Q(e,`lastT`),i=Q(e,`boundFrames`),a=$(e,`cls`),o=Xi(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 ia(e){if(!Ji(e))return null;let t=$(e,`tapeId`),n=Q(e,`deviceId`),r=Q(e,`fromMs`),i=Q(e,`toMs`),a=Xi(e,`reviewed`),o=Zi(e.lanes,ra);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 aa(e){if(!Ji(e))return null;if(e.ok===!1){let t=$(e,`reason`),n=$(e,`detail`);return t===null||n===null?null:{ok:!1,reason:t,detail:n}}if(e.ok!==!0)return null;let t=$(e,`tapeId`),n=e.state,r=Q(e,`frames`),i=Q(e,`gaps`),a=Q(e,`pinnedTracks`),o=Q(e,`bytes`);return t===null||n!==`complete`&&n!==`incomplete`||r===null||i===null||a===null||o===null?null:{ok:!0,tapeId:t,state:n,frames:r,gaps:i,pinnedTracks:a,bytes:o}}function oa(e){if(!Ji(e))return null;let t=e.status;if(t===`released`){let n=Q(e,`unpinned`),r=Xi(e,`pinsSettled`);return n===null||r===null?null:{status:t,unpinned:n,pinsSettled:r}}if(t===`already-released`||t===`not-found`)return{status:t};if(t===`unavailable`){let n=$(e,`reason`);return n===null?null:{status:t,reason:n}}return null}function sa(e){if(!Ji(e))return null;let t=e.status;if(t===`deleted`||t===`pins-owed`||t===`not-found`)return{status:t};if(t===`unavailable`){let n=$(e,`reason`);return n===null?null:{status:t,reason:n}}return null}function ca(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 la(e){if(!Ji(e))return null;let t=$(e,`leftTrackId`),n=$(e,`rightTrackId`),r=e.relation,i=e.presence;return t===null||n===null||r!==`same-subject`&&r!==`different-subjects`?null:{leftTrackId:t,rightTrackId:n,relation:r,presence:i===`continuous`?`continuous`:null}}function ua(e){if(!Ji(e))return null;let t=$(e,`sourceTrackId`),n=e.purity;return t===null||n!==`mixed`&&n!==`not-a-subject`?null:{sourceTrackId:t,purity:n,switchAtMs:Q(e,`switchAtMs`)}}function da(e){if(!Ji(e))return null;let t=Zi(e.relations,la),n=Zi(e.purities,ua),r=Xi(e,`truncated`);return t===null||n===null||r===null?null:{relations:t,purities:n,truncated:r}}function fa(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 pa(e){return e.filter(e=>e.segmentsHeld===null||e.segmentsHeld>0).map(e=>({deviceId:e.deviceId,segmentsUnknown:e.segmentsHeld===null}))}function ma(e){return e.slice(1).map((t,n)=>({trackId:e[n]??t,otherTrackId:t}))}function ha(e){return e.flatMap((t,n)=>e.slice(n+1).map(e=>({trackId:t,otherTrackId:e})))}function ga(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 _a(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 va={"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 ya(e,t){let n=va[e]??`Refused (${e}).`;return t.length>0?`${n} ${t}`:n}function ba(e){if(e.length===0)return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null}function xa(e){return e<1024*1024?`${(e/1024).toFixed(0)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function Sa(e){return e===null?`unknown`:xa(e)}function Ca(e){return e===null?`unknown`:String(e)}function wa(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 Ta({cameras:e,call:t,onPromoted:n}){let[i,a]=l(``),[o,s]=l(``),[c,d]=l(``),[f,p]=l(``),[m,h]=l(``),[g,_]=l(`auto`),[v,y]=l(!1),[b,x]=l(null),S=async()=>{let r=Number.parseInt(i===``?e[0]?.value??``:i,10),a=ba(o),s=ba(c);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=aa(await t(Vi.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(Ki):e.ok?(x(`Promoted ${e.tapeId}: ${String(e.frames)} frames, ${xa(e.bytes)}, ${String(e.pinnedTracks)} tracks pinned`+(e.state===`incomplete`?` — incomplete (it has gaps) and cannot become a case.`:`.`)),n()):x(ya(e.reason,e.detail))}catch(e){x(qi(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:[u(`div`,{className:`w-40`,children:u(de,{value:i,options:[...e],onChange:e=>a(e.target.value),"aria-label":`Camera`})}),u(X,{type:`datetime-local`,"aria-label":`From`,value:o,onChange:e=>s(e.target.value),className:`w-48`}),u(X,{type:`datetime-local`,"aria-label":`To`,value:c,onChange:e=>d(e.target.value),className:`w-48`}),u(X,{"aria-label":`Scenario`,placeholder:`615-door-groups`,value:f,onChange:e=>p(e.target.value),className:`w-44`}),u(X,{"aria-label":`Note`,placeholder:`optional note`,value:m,onChange:e=>h(e.target.value),className:`w-52`}),u(`div`,{className:`w-28`,children:u(de,{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(z,{onClick:()=>void S(),disabled:v||e.length===0,children:[v?u(Z,{className:`h-3.5 w-3.5 animate-spin`}):null,` Promote window`]}),u(`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&&u(`p`,{className:`w-full text-xs text-foreground`,children:b})]})}var Ea=`pipeline-analytics`,Da=`debug.listTracks`,Oa=`debug.analyze`,ka=p(`/addon/pipeline-analytics/debug-export`);function Aa(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ja(e,t){let n=e[t];return typeof n==`string`?n:null}function Ma(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Na(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Pa(e){return e===`error`||e===`warn`||e===`info`}function Fa(e){if(!Aa(e))return null;let t=ja(e,`code`),n=ja(e,`detail`),r=e.severity;return t===null||n===null||!Pa(r)?null:{code:t,severity:r,detail:n}}function Ia(e){if(!Aa(e))return null;let t=ja(e,`trackId`),n=Ma(e,`deviceId`),r=ja(e,`className`),i=Ma(e,`firstSeen`),a=Ma(e,`lastSeen`),o=Ma(e,`durationMs`),s=Na(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=ja(e,`label`),l=ja(e,`subLabel`),u=ja(e,`previewMissReason`),d=Na(e,`markForTrain`),f=Na(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:Ma(e,`importance`)??0,bestEventId:ja(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function La(e){let t=Ia(e);if(t===null||!Aa(e))return null;let n=Ma(e,`mediaCount`),r=Ma(e,`eventCount`),i=Ma(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=Fa(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...Yr(l)?{thumbnailProvenance:l}:{}}}function Ra(e){if(!Aa(e))return null;let t=Na(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=Ia(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function za(e){if(!Aa(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=La(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var Ba={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 Va(e){return Ba[e]??e}var Ha={error:0,warn:1,info:2};function Ua(e){return e.toSorted((e,t)=>Ha[e.severity]-Ha[t.severity]||e.code.localeCompare(t.code))}function Wa(e){return e.length===0?ka:`${ka}?deviceIds=${e.join(`,`)}`}function Ga(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 Ka(e,t){return`${String(e)}:${t}`}function qa(e,t){let n=[],r=new Set;for(let i of e){let e=Ka(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 Ja({tapeId:e,call:t,onClose:n,onChanged:i}){let a=o({queryKey:[`events-debug`,`tapes`,`tracks`,e],queryFn:async()=>ia(await t(Vi.tracks,{tapeId:e}))}),s=a.data??null,c=o({queryKey:[`events-debug`,`tapes`,`marks`,e],enabled:s!==null,queryFn:async()=>s===null?null:da(await t(Hi.list,{deviceId:s.deviceId,since:s.fromMs-Wi,until:s.toMs+Wi,limit:5e3}))}),[d,f]=l([]),[p,m]=l(``),[h,g]=l(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 c.refetch(),i()}catch(e){g(qi(e))}};if(s===null)return a.isLoading?u(`p`,{className:`text-xs`,children:`Loading the tape…`}):u(pt,{message:Ki});let y=s.deviceId,b=(e,t)=>v(e.map(e=>[Hi.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=>[Hi.setPurity,{deviceId:y,trackId:t,purity:e,...n===void 0?{}:{switchAtMs:Math.round(n)}}]))},S=c.data==null?null:fa(c.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`]}),u(z,{disabled:d.length<2,onClick:()=>void b(ma(d),`same-subject`),children:`Same subject`}),u(z,{variant:`secondary`,disabled:d.length<2,onClick:()=>void b(ha(d),`different-subjects`),children:`Different subjects`}),u(X,{"aria-label":`Changed at (s from tape start)`,placeholder:`changed at s`,value:p,onChange:e=>m(e.target.value),className:`w-28`}),u(z,{variant:`secondary`,disabled:d.length!==1,onClick:()=>void x(`mixed`),children:`Mixed`}),u(z,{variant:`secondary`,disabled:d.length===0,onClick:()=>void x(`not-a-subject`),children:`Not a subject`}),u(z,{variant:s.reviewed?`secondary`:`primary`,onClick:()=>void v([[Vi.review,{tapeId:s.tapeId,reviewed:!s.reviewed}]]).then(()=>a.refetch()),children:s.reviewed?`Mark not reviewed`:`Mark reviewed`}),u(z,{variant:`ghost`,onClick:n,children:`Close`})]}),h!==null&&u(pt,{message:h}),S!==null&&u(pt,{variant:`warning`,message:S}),u(`ul`,{className:`space-y-1`,children:s.lanes.toSorted((e,t)=>e.firstT-t.firstT).map(e=>u(Ya,{lane:e,marks:c.data===null||c.data===void 0?[]:ga(e.trackId,c.data),selected:d.includes(e.trackId),onToggle:()=>_(e.trackId)},e.trackId))})]})}function Ya({lane:e,marks:t,selected:n,onToggle:i}){let{src:a}=Dt(e.stillStored?Ot(`track`,e.trackId):void 0);return r(`li`,{className:`flex items-center gap-2 text-xs`,children:[u(`input`,{type:`checkbox`,"aria-label":`select ${e.trackId}`,checked:n,onChange:i}),a===null?u(`div`,{className:`h-10 w-10 rounded bg-surface-hover`}):u(`img`,{src:a,alt:e.trackId,className:`h-10 w-10 rounded object-cover`}),u(`span`,{className:`font-mono`,children:e.trackId}),u(`span`,{children:e.cls}),r(`span`,{className:`text-foreground-subtle`,children:[Ga(e.firstT),` → `,Ga(e.lastT),` · `,String(e.boundFrames),` `,`frames`]}),!e.stillStored&&u(`span`,{className:`text-foreground-subtle`,children:`not stored — marked through the tape`}),t.map(e=>u(rt,{variant:`info`,children:e},e))]})}n();var Xa=`camstack_admin_token`;function Za(){let e=S();return(t,n)=>e.trpcClient.addons.custom.mutate({addonId:Ea,action:t,input:n})}async function Qa(e,t){let n=localStorage.getItem(Xa),r={};n!==null&&(r.Authorization=`Bearer ${n}`);let i=await fetch(Gi(e),{headers:r});if(!i.ok){let e=await i.text().catch(()=>``);throw Error(wa(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 $a(){let[e,t]=l(!1);return u(We,{expanded:e,onExpandedChange:t,header:u(`span`,{className:`text-sm font-medium text-foreground`,children:`Tracking tapes`}),children:u(eo,{})})}function eo(){let e=Za(),t=Ne({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]),a=o({queryKey:[`events-debug`,`tapes`,`status`],queryFn:async()=>ea(await e(Vi.status,{}))}),s=o({queryKey:[`events-debug`,`tapes`,`list`],queryFn:async()=>na(await e(Vi.list,{}))}),[c,d]=l(null),[f,p]=l(null),m=async e=>{p(null);try{await Qa(e.id,`${e.scenario}.tape-bundle.json.gz`)}catch(e){p(qi(e))}},h=async t=>{let n=oa(await e(Vi.release,{tapeId:t.id}));if(n===null)throw Error(Ki);let r=ca(n);if(r!==null)throw Error(r);await s.refetch()},g=async t=>{let n=sa(await e(Vi.remove,{tapeId:t.id}));if(n===null)throw Error(Ki);let r=ca(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 `,u(`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`,` `,u(`code`,{children:`npm run tracking-bench -- case`}),`.`]}),f!==null&&u(pt,{message:f}),a.isLoading&&u(`p`,{className:`text-xs text-foreground-subtle`,children:`Loading camera status…`}),a.data===null&&u(pt,{message:`The server answered in a shape this build does not understand.`}),r(`table`,{className:`w-full text-xs`,children:[u(`thead`,{children:r(`tr`,{className:`text-left text-foreground-subtle`,children:[u(`th`,{children:`Camera`}),u(`th`,{children:`State`}),u(`th`,{children:`Frames/min`}),u(`th`,{children:`Last hour`}),u(`th`,{children:`Held`}),u(`th`,{children:`Gaps`})]})}),u(`tbody`,{children:(a.data??[]).map(e=>r(`tr`,{children:[u(`td`,{children:n(e.deviceId)}),u(`td`,{children:u(rt,{variant:e.state===`recording`?`success`:e.state===`off`?`default`:e.state===`unknown`?`warning`:`danger`,children:_a(e)})}),u(`td`,{children:e.framesPerMin===void 0?`—`:String(Math.round(e.framesPerMin))}),u(`td`,{title:e.shelfError,children:Sa(e.bytesLastHour)}),r(`td`,{title:e.shelfError,children:[Ca(e.segmentsHeld),` seg · `,Sa(e.bytesHeld)]}),u(`td`,{children:String(e.gapsSinceArmed)})]},e.deviceId))})]}),u(Ta,{cameras:pa(a.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&&u(`p`,{className:`text-xs text-foreground-subtle`,children:`Loading promoted tapes…`}),s.data===null&&u(pt,{message:`The server answered in a shape this build does not understand.`}),r(`table`,{className:`w-full text-xs`,children:[u(`thead`,{children:r(`tr`,{className:`text-left text-foreground-subtle`,children:[u(`th`,{children:`Scenario`}),u(`th`,{children:`Camera`}),u(`th`,{children:`Window`}),u(`th`,{children:`State`}),u(`th`,{children:`Tracks`}),u(`th`,{})]})}),u(`tbody`,{children:(s.data??[]).map(e=>r(`tr`,{children:[u(`td`,{children:e.scenario}),u(`td`,{children:n(e.deviceId)}),r(`td`,{children:[new Date(e.fromMs).toLocaleString(),` · `,Ga(e.toMs-e.fromMs),` `,`· `,e.lighting]}),r(`td`,{children:[u(rt,{variant:e.state===`complete`?`success`:`warning`,children:e.state}),` `,e.reviewed&&u(rt,{variant:`info`,children:`reviewed`}),` `,e.released&&u(rt,{children:`released`})]}),r(`td`,{children:[String(e.tracksStillStored),`/`,String(e.tracks.length),` stored`]}),r(`td`,{className:`space-x-1 text-right`,children:[u(z,{variant:`secondary`,"aria-label":`Review ${e.scenario}`,onClick:()=>d(e.id),children:`Review`}),u(z,{variant:`ghost`,"aria-label":`Download ${e.scenario}`,onClick:()=>void m(e),children:u(fe,{className:`h-3.5 w-3.5`})}),u(ne,{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)}),u(ne,{label:`Delete`,icon:_,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))})]}),c!==null&&u(Ja,{tapeId:c,call:e,onClose:()=>d(null),onChanged:()=>void s.refetch()})]})}n();var to=`all`,no=`The server answered in a shape this build does not understand.`,ro={error:`danger`,warn:`warning`,info:`info`};function io({findings:e}){return e.length===0?u(rt,{variant:`success`,children:`no anomaly found`}):u(`div`,{className:`flex flex-wrap gap-1`,children:Ua(e).map(e=>u(rt,{variant:ro[e.severity],title:e.detail,children:Va(e.code)},e.code))})}function ao({track:e,report:t,analyzing:n}){let i=$r(t?.previewMissReason??e.previewMissReason);return r(`div`,{className:`space-y-1 border-t border-border pt-1.5`,children:[t===void 0?u(`span`,{className:`text-[10px] text-foreground-subtle`,children:n?`analysing…`:`not analysed`}):r(s,{children:[u(io,{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&&u(`p`,{className:`text-[10px] text-foreground-subtle`,title:i.raw,children:i.sentence})]})}function oo(){let e=S(),[t,n]=l(to),[a,s]=l(!1),[c,d]=l(null),[f,p]=l(new Set),[m,h]=l(null),[g,_]=l(null),[v,y]=l(null),[b,x]=l([]),C=_i(),w=Ne({isCamera:!0,projection:`slim`}),T=i(()=>[{value:to,label:`All cameras`},...(w.data??[]).map(e=>({value:String(e.id),label:e.name}))],[w.data]),E=i(()=>{let e=new Map;for(let t of w.data??[])e.set(t.id,t.name);return e},[w.data]),D=e=>E.get(e)??`Camera ${String(e)}`,O=i(()=>t===to?[]:[Number.parseInt(t,10)],[t]),k=o({queryKey:[`events-debug`,`list`,O],queryFn:async()=>Ra(await e.trpcClient.addons.custom.mutate({addonId:Ea,action:Da,input:O.length===0?{}:{deviceIds:O}}))}),A=i(()=>(k.data?.tracks??[]).map(e=>e.trackId),[k.data]),j=o({queryKey:[`events-debug`,`analyze`,A],enabled:A.length>0,queryFn:async()=>za(await e.trpcClient.addons.custom.mutate({addonId:Ea,action:Oa,input:{trackIds:A}}))}),M=i(()=>{let e=new Map;for(let t of j.data?.reports??[])e.set(t.trackId,t);return e},[j.data]),N=k.data?.tracks??[],P=k.data===null||j.data===null,I=()=>{k.refetch(),j.refetch()},L=e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},R=()=>{p(new Set(N.map(e=>Ka(e.deviceId,e.trackId))))},ee=()=>p(new Set),V=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await C.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},H=e=>{if(!mi||g!==null)return;let t=qa(N,f);t.length!==0&&(_(e),y(null),(async()=>{let n=await V(e,t);_(null);let r=new Set(n.refused);p(new Set(t.filter(e=>r.has(e.trackId)).map(e=>Ka(e.deviceId,e.trackId)))),e===`analyzed`&&x(t.filter(e=>!r.has(e.trackId))),n.refused.length>0&&y(`${String(n.refused.length)} of ${String(t.length)} were refused by the server and are still selected. Check the hub log.`),k.refetch()})())},U=()=>{let e=b;e.length===0||g!==null||(_(`analyzed`),y(null),(async()=>{for(let t of e)try{await C.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,flags:{debug:!0}})}catch{y(`Some tracks could not be re-marked. Refresh and try again.`)}_(null),x([]),k.refetch()})())},W=async()=>{s(!0),d(null);try{await jt(Wa(O),`camstack-debug.zip`)}catch(e){d(e instanceof Error?e.message:`Export failed.`)}finally{s(!1)}},G=g!==null;return r(`section`,{className:`space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[u(`div`,{className:`w-44`,children:u(de,{value:t,options:T,onChange:e=>n(e.target.value)})}),r(z,{variant:`secondary`,onClick:I,disabled:k.isFetching,children:[k.isFetching?u(Z,{className:`h-3.5 w-3.5 animate-spin`}):u(De,{className:`h-3.5 w-3.5`}),`Refresh`]}),r(z,{onClick:()=>void W(),disabled:a||N.length===0,children:[a?u(Z,{className:`h-3.5 w-3.5 animate-spin`}):u(fe,{className:`h-3.5 w-3.5`}),`Export all (`,String(N.length),`)`]}),N.length>0&&f.size<N.length&&u(z,{variant:`ghost`,onClick:R,children:`Select all`})]}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`A `,u(`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 `,u(`strong`,{children:`Keep`}),` to hold a selection against pruning while you investigate, and `,u(`strong`,{children:`Analyzed`}),` to un-mark the ones you are finished with.`]}),u($a,{}),k.isError&&u(pt,{message:`Could not load the marked tracks.`}),P&&!k.isError&&u(pt,{message:no}),c!==null&&u(pt,{message:c}),v!==null&&u(pt,{message:v}),k.data?.truncated===!0&&u(pt,{message:`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`}),(j.data?.vanished.length??0)>0&&r(`p`,{className:`text-xs text-foreground-subtle`,children:[String(j.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:[u(`span`,{title:mi?void 0:`Track flags arrive with the next server update`,children:r(z,{variant:`secondary`,onClick:()=>H(`keep`),disabled:!mi||G,children:[g===`keep`?u(Z,{className:`h-3.5 w-3.5 animate-spin`}):u(te,{className:`h-3.5 w-3.5`}),` `,`Keep`]})}),u(`span`,{title:mi?void 0:`Track flags arrive with the next server update`,children:r(z,{onClick:()=>H(`analyzed`),disabled:!mi||G,children:[g===`analyzed`?u(Z,{className:`h-3.5 w-3.5 animate-spin`}):u(nt,{className:`h-3.5 w-3.5`}),` `,`Analyzed`]})}),u(z,{variant:`ghost`,onClick:ee,disabled:G,children:u(Y,{className:`h-3.5 w-3.5`})})]})]}),b.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(b.length),` track(s) marked analyzed and removed from this list.`]}),r(z,{variant:`ghost`,onClick:U,disabled:G,children:[u(le,{className:`h-3.5 w-3.5`}),` Undo`]}),u(z,{variant:`ghost`,onClick:()=>x([]),disabled:G,children:u(Y,{className:`h-3.5 w-3.5`})})]}),k.isLoading?u(B,{status:`pending`,pendingMessage:`Loading…`,testId:`debug-tracks-grid`}):N.length===0?u(F,{icon:ot,title:`No track is marked for debug`,description:`Mark one from a track's actions on the Feed to see it here.`}):u(B,{status:`ready`,testId:`debug-tracks-grid`,children:N.map(e=>{let t=M.get(e.trackId);return u(ti,{row:e,cameraName:D(e.deviceId),nowMs:e.lastSeen,selected:f.has(Ka(e.deviceId,e.trackId)),onToggleSelect:L,onOpenDetail:h,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:u(ao,{track:e,report:t,analyzing:j.isFetching})},Ka(e.deviceId,e.trackId))})}),m&&u(Bi,{row:m,cameraName:D(m.deviceId),deleteAvailable:Oi,onClose:()=>h(null),onDeleted:()=>{h(null),k.refetch()},onFlagsChanged:e=>{e.debug||(h(null),k.refetch())}})]})}var so=200,co=3e4,lo=[];function uo(e){let t=S(),n=e.deviceIds.length>0,r=[...e.deviceIds].sort((e,t)=>e-t),{data:i,isLoading:a}=o({queryKey:[`events-feed`,r,e.since,e.until,e.minImportance??null,e.classFilter??null],enabled:n,staleTime:co,refetchInterval:co,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEventsBatch.query({deviceIds:r,since:e.since,until:e.until,limit:so,...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:Ur(Hr(i??lo),`importance`),isLoading:n&&a}}n();var fo=[`events-feed`],po=2e3;function mo(n){let r=c(),i=n?.paused===!0,a=t(r);a.current=r;let o=t(i);o.current=i;let[s,u]=l(!1),f=e(()=>{a.current.invalidateQueries({queryKey:fo})},[]),p=t(void 0);p.current||=Fr({delayMs:po,invalidate:()=>{o.current?u(!0):f()}}),d(()=>()=>p.current?.cancel(),[]),d(()=>{i||!s||(u(!1),f())},[i,s,f]);let m=e(()=>{u(!1),f()},[f]);return Ye(vt.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),Ye(vt.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:s,refreshNow:m}}n();function ho({groups:e,selected:t,onChange:n,loading:a=!1}){let{t:o}=yt(),[s,c]=l(!1),[d,f]=l(``),[p,m]=l(new Set),g=d.trim().toLowerCase(),_=e=>g.length===0||be(e,o).toLowerCase().includes(g),v=i(()=>e.map(e=>({macro:e.macro,subs:e.subs.filter(t=>_(t)||_(e.macro))})).filter(e=>_(e.macro)||e.subs.length>0),[e,g]),b=e=>m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),x=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)},S=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},C=()=>n(new Set),w=t.size;return r(`div`,{className:`relative`,children:[r(`button`,{type:`button`,onClick:()=>c(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${w>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(Be,{className:`h-3.5 w-3.5`}),w>0?`Kinds (${String(w)})`:`Kinds`,u(h,{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:[u(et,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`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`}),w>0&&u(`button`,{type:`button`,onClick:C,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),v.length===0&&u(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:a?`Loading kinds…`:g.length>0?`No kind matches that search.`:`These cameras advertise no event kinds.`}),v.map(e=>{let n=Je(e.macro.iconId),i=p.has(e.macro.kind)||g.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?u(`button`,{type:`button`,onClick:()=>b(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:u(i?h:y,{className:`h-3 w-3`})}):u(`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:[u(`input`,{type:`checkbox`,checked:a,onChange:()=>x(e),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),u(`span`,{className:`font-medium`,children:be(e.macro,o)})]})]}),i&&e.subs.map(e=>{let n=Je(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:[u(`input`,{type:`checkbox`,checked:t.has(e.kind),onChange:()=>S(e.kind),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),u(`span`,{children:be(e,o)})]},e.kind)})]},e.macro.kind)})]})]})}function go(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 _o(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var vo=new Set([`detection`,`package`]);function yo(e,t){return[...go(e,t).values()].filter(e=>e.parentKind===null&&vo.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function bo(e,t){let n=go(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,_o(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 xo(){let[n,r]=l(!1),i=t(null),[a,o]=l(0),s=e(e=>{i.current!==e&&(i.current=e,o(e=>e+1))},[]);return d(()=>{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 So=[`events-feed`],Co=60,wo=[{value:`importance`,label:`Importance`,icon:Pt},{value:`time`,label:`Recent`,icon:_e}];function To(){let e=c(),t=oe(),n=k(),[a,o]=l(Nn),[f,p]=l(new Set),[m,h]=l(new Set),[g,v]=l(0),[y,b]=l(`time`),[x,S]=l(new Set),[C,w]=l(null),[T,E]=l(()=>Date.now());d(()=>{let e=setInterval(()=>E(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:D,until:O}=i(()=>qr({fromMs:a.fromMs,toMs:a.toMs},T),[a.fromMs,a.toMs,T]),A=xo(),{pending:M,refreshNow:N}=mo({paused:C!==null||x.size>0||A.scrolledPast}),{data:P=[]}=Ne({isCamera:!0,projection:`slim`}),I=i(()=>P.map(e=>e.id),[P]),{data:L,isLoading:R}=je({deviceIds:I},{enabled:I.length>0,staleTime:5*6e4}),ee=i(()=>bo(L??[],f),[L,f]),V=ji(),H=V.isPending,{rows:U,isLoading:W}=uo({deviceIds:I,since:D,until:O,minImportance:g>0?g:void 0,classFilter:m.size===1?[...m][0]:void 0}),G=i(()=>{let e=new Map;for(let t of P??[])e.set(t.id,t.name);return e},[P]),K=e=>G.get(e)??`Camera #${String(e)}`,te=i(()=>Bn(U).map(e=>({id:e,name:K(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[U,G]),q=i(()=>Ur(Wr(U,{cameras:f,classes:m,minImportance:g}),y),[U,f,m,g,y]),J=Xn(q,Co,i(()=>JSON.stringify([[...f].sort((e,t)=>e-t),[...m].sort(),g,y,D,O]),[f,m,g,y,D,O])),ne=()=>{e.invalidateQueries({queryKey:So})},re=()=>S(new Set);function ie(e){S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function ae(){if(x.size===0||!Oi)return;let e=Kr(U,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`})&&se(e)})()}function se(e){let n=[...e];Promise.allSettled(n.map(([e,t])=>V.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{ne();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(Gr(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=>K(e)).join(`, `)}. They remain selected — retry, or check the server logs.`,variant:`danger`})})}let ce=q.length!==U.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(ir,{onChange:o}),u(nr,{cameras:te,selected:f,onChange:p}),u(ho,{groups:ee,selected:m,onChange:h,loading:R}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(`span`,{children:`Min score`}),u(`input`,{type:`range`,min:0,max:1,step:.05,value:g,onChange:e=>v(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":`Minimum importance`}),u(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(g*100)})]}),u(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:wo.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 ${y===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!W&&u(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:ce?`${String(q.length)} of ${String(U.length)} events`:`${String(q.length)} event${q.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:[u(`span`,{title:Oi?void 0:`Track deletion arrives with the next server update`,children:r(z,{variant:`secondary`,onClick:ae,disabled:!Oi||H,children:[H?u(Z,{className:`h-3.5 w-3.5 animate-spin`}):u(_,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),u(z,{variant:`ghost`,onClick:re,disabled:H,children:u(Y,{className:`h-3.5 w-3.5`})})]})]}),M&&u(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:u(`button`,{type:`button`,onClick:N,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`})}),W?u(B,{status:`pending`,pendingMessage:`Loading events…`,testId:`events-grid`}):q.length===0?u(F,{icon:j,title:ce?`Nothing matches the filter`:`No key events in this window`,description:ce?`Widen the date range, clear cameras or kinds, or lower the min score.`:`Captured tracks appear here when the pipeline scores a key event.`}):r(s,{children:[u(`div`,{ref:A.ref,"aria-hidden":!0,className:`h-0`}),u(B,{status:`ready`,testId:`events-grid`,children:J.pageItems.map(e=>u(ti,{row:e,cameraName:K(e.deviceId),nowMs:T,selected:x.has(Gr(e.deviceId,e.trackId)),onToggleSelect:ie,onOpenDetail:w},Gr(e.deviceId,e.trackId)))}),u($n,{currentPage:J.page,totalItems:J.totalItems,pageSize:J.pageSize,onPageChange:J.setPage,itemNoun:`events`})]}),C&&u(Bi,{row:C,cameraName:K(C.deviceId),deleteAvailable:Oi,onClose:()=>w(null),onDeleted:()=>{ne(),w(null)},onFlagsChanged:e=>{w(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}var Eo=`/addon/training`;function Do(){let e=St();return r(V,{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:[u(q,{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:[u(`p`,{className:`text-xs font-medium text-foreground`,children:`Training from this feed`}),u(`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.`})]})]}),u(z,{variant:`outline`,size:`sm`,className:`shrink-0 self-start sm:self-center`,onClick:()=>e(Eo),children:`Open Training`})]})}n();var Oo=50,ko=350,Ao=[{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 jo(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 Mo({onActiveChange:e}){let[t,n]=l(``),[a,o]=l(`loose`),[s,c]=l(null),[f,p]=l(null),[m,h]=l(null),g=st(t,ko).trim(),_=g.length>0;d(()=>{e(_)},[_,e]);let[v,y]=l(()=>Date.now());d(()=>{let e=setInterval(()=>y(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:b=[]}=Ne({isCamera:!0,projection:`slim`}),x=i(()=>{let e=new Map;for(let t of b)e.set(t.id,t.name);return e},[b]),S=e=>x.get(e)??`Camera #${String(e)}`,C=i(()=>b.map(e=>e.id),[b]),{data:w}=je({deviceIds:C},{enabled:C.length>0,staleTime:5*6e4}),T=i(()=>yo(w??[],new Set(f===null?[]:[f])),[w,f]);d(()=>{s!==null&&(T.some(e=>e.kind===s)||c(null))},[T,s]);let{data:E,isFetching:D,isError:O,error:k}=ye({text:g,strictness:a,limit:Oo,classFilter:s??void 0,deviceId:f??void 0},{enabled:_}),A=i(()=>[...E??[]].sort((e,t)=>t.score-e.score).map(e=>({...jo(e),score:e.score})),[E]);function j(e){c(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:[u(et,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),u(`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&&u(`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:u(Y,{className:`h-3.5 w-3.5`})})]}),D&&_&&u(Z,{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:[u(`div`,{className:`flex items-center gap-1`,children:T.map(e=>u(`button`,{type:`button`,onClick:()=>j(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:be(e)},e.kind))}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(`span`,{children:`Camera`}),u(de,{value:f===null?``:String(f),onChange:e=>p(e.target.value===``?null:Number(e.target.value)),className:`h-7 text-xs`,"aria-label":`Filter by camera`,options:[{value:``,label:`All`},...b.map(e=>({value:String(e.id),label:e.name}))]})]}),r(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(`span`,{children:`Match`}),u(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Ao.map(e=>u(`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))})]}),_&&!D&&!O&&r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[A.length,` match`,A.length===1?``:`es`]})]})]}),_&&r(`div`,{className:`space-y-3`,children:[O&&r(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,k instanceof Error?k.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!O&&D&&A.length===0&&u(B,{status:`pending`,pendingMessage:`Searching…`,testId:`semantic-events-grid`}),!O&&!D&&A.length===0&&u(B,{status:`empty`,emptyMessage:`No semantic matches for “${g}”. Try a looser match threshold or a different phrasing.`,testId:`semantic-events-grid`}),!O&&A.length>0&&u(B,{status:`ready`,testId:`semantic-events-grid`,children:A.map(e=>u(ti,{row:e,cameraName:S(e.deviceId),nowMs:v,score:e.score,onOpenDetail:h},e.id))})]}),m&&u(Bi,{row:m,cameraName:S(m.deviceId),deleteAvailable:Oi,onClose:()=>h(null),onDeleted:()=>h(null)})]})}n();function No(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 Po({row:e,cameraName:t,nowMs:n}){let i=Dt(e.keyFrameMediaId===void 0?void 0:At(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?u(`img`,{src:i.src,alt:`Parked ${e.className} on ${t}`,className:`h-full w-full object-cover`}):u(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:u(Bt,{className:`h-6 w-6`})}),u(`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:[u(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,No(n,e.becameStationaryAt)]})]})]})}function Fo(){let[e,t]=l(!1),n=Date.now(),{data:a=[]}=Ne({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:c,unreadableCount:d}=Et(o);return c.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:[u(e?h:y,{className:`h-4 w-4 text-foreground-subtle`}),u(Bt,{className:`h-4 w-4 text-foreground-subtle`}),u(`span`,{className:`text-sm font-semibold text-foreground`,children:`Stationary`}),u(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:c.length}),u(`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&&u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:c.map(e=>u(Po,{row:e,cameraName:s.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}n();function Io(){let[e,t]=l(!1);return r(`section`,{className:`space-y-3`,children:[u(Do,{}),u(Mo,{onActiveChange:t}),!e&&u(Fo,{}),!e&&u(To,{})]})}function Lo(){let[e]=bt();return e.get(`section`)===`retrain`?u(xt,{to:`/addon/training`,replace:!0}):u(Mt,{paramName:`section`,tabs:[{id:`feed`,label:`Feed`,icon:j,content:u(Io,{})},{id:`debug`,label:`Debug`,icon:ot,content:u(oo,{})}]})}function Ro(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}n();var zo=[[`plateGallery`]];function Bo({plateIds:e,vehicles:t,onDone:n}){let i=c(),a=Te(),o=Xe(),[s,d]=l(``),[f,p]=l(!1),[m,h]=l(null),g=e!==null&&e.length>0,_=e?.length??0;function v(){p(!1),d(``),h(null)}function y(){v(),n()}function b(t){!e||e.length===0||a.mutate({plateIds:[...e],vehicleId:t},{onSettled:()=>{i.invalidateQueries({queryKey:zo}),y()}})}function x(){!e||!s.trim()||o.mutate({name:s.trim()},{onSuccess:e=>{e?.id&&b(e.id)},onError:()=>{i.invalidateQueries({queryKey:zo}),y()}})}let S=a.isPending||o.isPending;return u(R,{open:g,onOpenChange:e=>!e&&y(),children:r(Re,{children:[r(K,{children:[u(J,{children:_>1?`Assign ${String(_)} plates to vehicle`:`Assign plate to vehicle`}),u(M,{children:`Select an existing vehicle or create a new one.`})]}),u(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>r(`button`,{type:`button`,onClick:()=>h(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${m===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[u(`span`,{className:`font-medium`,children:e.name}),r(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` plates`]})]},e.id))}),f?u(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:u(X,{placeholder:`New vehicle name…`,value:s,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&x()},autoFocus:!0,className:`flex-1`})}):u(`button`,{type:`button`,onClick:()=>{h(null),p(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:`+ New vehicle…`}),r(Ie,{children:[u(z,{variant:`secondary`,onClick:y,disabled:S,children:`Cancel`}),f?r(z,{variant:`primary`,onClick:x,disabled:S||!s.trim(),children:[S&&u(Z,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):r(z,{variant:`primary`,onClick:()=>m&&b(m),disabled:S||!m,children:[S&&u(Z,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,_>1?` ${String(_)}`:``]})]})]})})}n();var Vo=[[`plateGallery`]];function Ho(e){let[t,n]=l(null),[r,i]=l(null),[a,o]=l(!1);return d(()=>{if(n(null),i(null),o(!1),e===void 0)return;let t=!1,r=null;return(async()=>{try{let i=await kt(At(e));if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),d(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>o(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function Uo(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 Wo({label:e,value:t,mono:n}){return r(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[u(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),u(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono`:``}`,title:t,children:t})]})}function Go({box:e}){return u(`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:u(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Plate`})})}function Ko({plate:e,cameraName:t,onClose:n,onAssign:a,onUnassign:o,onDelete:s,actionsPending:f}){let p=c(),{data:m,isFetching:h}=Me({plateId:e?.plateId??``},{enabled:e!==null}),g=Ae(),[v,y]=l(`frame`),[b,x]=l(!1),[S,w]=l(``),{frameSrc:T,naturalWidth:E,naturalHeight:D,failed:O}=Ho(e?.keyFrameMediaId);d(()=>{x(!1),w(``),y(`frame`)},[e?.plateId]);let k=i(()=>{let t=Uo(m??[]);return t?t.url:Ro(e)},[m,e]),A=i(()=>!e?.plateBbox||E===null||D===null?null:or(e.plateBbox,E,D),[e?.plateBbox,E,D]);if(e===null)return null;let j=e.keyFrameMediaId!==void 0&&!O,M=j&&v===`frame`,N=e.assigned?e.vehicleName??`Assigned`:e.recognizedVehicleId?`${e.vehicleName??`Recognized`} (suggested)`:`Unassigned`,P=`${String(Math.round(e.score*100))}%${e.corrected?` · corrected`:``}`;function F(){e&&(w(e.text),x(!0))}function I(){if(!e)return;let t=S.trim().toUpperCase();if(!t||t===e.text){x(!1);return}g.mutate({plateId:e.plateId,text:t},{onSettled:()=>{p.invalidateQueries({queryKey:Vo}),x(!1)}})}return u(R,{open:!0,onOpenChange:e=>!e&&n(),children:r(Re,{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:[u(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:r(`div`,{className:`min-w-0`,children:[u(`div`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||`Plate detail`}),u(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]})}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[j&&r(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[r(`button`,{type:`button`,onClick:()=>y(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${v===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(he,{className:`h-3.5 w-3.5`}),` Full frame`]}),r(`button`,{type:`button`,onClick:()=>y(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${v===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(ht,{className:`h-3.5 w-3.5`}),` Crop`]})]}),M&&T?u(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:u(cr,{src:T,alt:`Full frame with detected plate`,fit:`natural`,className:`w-full`,overlay:A?u(Go,{box:A}):void 0})}):k?r(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[u(cr,{src:k,alt:`Detected plate`,className:`h-full w-full`}),h&&u(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:u(Z,{className:`h-3.5 w-3.5 animate-spin`})})]}):r(`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:[u(C,{className:`h-8 w-8 text-warning/70`}),u(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),u(`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.`})]}),u(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-2`,children:r(`div`,{className:`flex items-center justify-between gap-3`,children:[u(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:`Plate text`}),b?r(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[u(X,{value:S,onChange:e=>w(e.target.value),onKeyDown:e=>{e.key===`Enter`&&I(),e.key===`Escape`&&x(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),u(`button`,{type:`button`,onClick:I,disabled:g.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Save corrected text`,children:g.isPending?u(Z,{className:`h-3.5 w-3.5 animate-spin`}):u(nt,{className:`h-3.5 w-3.5`})}),u(`button`,{type:`button`,onClick:()=>x(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel`,children:u(Y,{className:`h-3.5 w-3.5`})})]}):r(`button`,{type:`button`,onClick:F,className:`group flex min-w-0 items-center gap-1.5`,title:`Correct the OCR reading`,children:[u(`span`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||`—`}),u(Ve,{className:`h-3 w-3 shrink-0 text-foreground-subtle group-hover:text-foreground`})]})]})}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[u(Wo,{label:`Camera`,value:t}),u(Wo,{label:`Captured`,value:Gn(e.timestamp)}),u(Wo,{label:`Confidence`,value:P}),u(Wo,{label:`Vehicle`,value:N}),u(Wo,{label:`Track`,value:e.trackId,mono:!0})]})]}),r(`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?r(z,{variant:`secondary`,onClick:()=>o(e.plateId),disabled:f,children:[u(Vt,{className:`h-3.5 w-3.5`}),` Detach`]}):r(z,{variant:`primary`,onClick:()=>a(e.plateId),disabled:f,children:[u(Ce,{className:`h-3.5 w-3.5`}),` Assign`]}),r(z,{variant:`secondary`,onClick:()=>s(e.plateId),disabled:f,children:[u(_,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}n();var qo=[[`plateGallery`]],Jo=500,Yo=120;function Xo({plate:e,cameraName:t,nowMs:n,selected:i,onToggleSelect:a,onAssign:o,onOpenDetail:s}){let l=c(),d=ce(),f=Ue(),p=()=>{l.invalidateQueries({queryKey:qo})},m=()=>s(e.plateId),h=Ro(e);return r(`div`,{className:`relative flex flex-col overflow-hidden rounded-md border bg-surface ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[r(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[h===null?r(`button`,{type:`button`,onClick:m,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:[u(C,{className:`h-7 w-7 text-warning/70`}),u(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):u(`img`,{src:h,alt:`Plate ${e.text} from ${t}`,onClick:m,className:`h-full w-full cursor-zoom-in object-cover`}),u(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(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?u(zt,{className:`h-4 w-4 text-primary`}):u(x,{className:`h-4 w-4`})}),e.corrected&&r(`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:[u(Ft,{className:`h-3 w-3`}),` Fixed`]})]}),r(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[u(`p`,{className:`truncate font-mono text-xs font-bold tracking-wide text-foreground`,title:e.text,children:e.text||`—`}),u(`p`,{className:`truncate text-[10px] text-foreground-subtle`,title:t,children:t}),u(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:Un(e.timestamp,n)}),e.vehicleName&&u(`p`,{className:`truncate text-[10px] font-medium text-primary`,title:e.vehicleName,children:e.vehicleName})]}),r(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?u(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),d.mutate({plateId:e.plateId},{onSettled:p})},disabled:d.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:d.isPending?u(Z,{className:`h-4 w-4 animate-spin`}):u(Vt,{className:`h-4 w-4`})}):u(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(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:u(Ce,{className:`h-4 w-4`})}),u(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),f.mutate({plateId:e.plateId},{onSettled:p})},disabled:f.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:f.isPending?u(Z,{className:`h-4 w-4 animate-spin`}):u(_,{className:`h-4 w-4`})})]})]})}var Zo=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Assigned`,value:`assigned`}];function Qo(e,t){return t===`unassigned`?e.filter(e=>!e.assigned):t===`assigned`?e.filter(e=>e.assigned):e}function $o(){let e=c(),[t,n]=l(`all`),[a,o]=l(Nn),[d,f]=l(new Set),[p,m]=l(new Set),[h,g]=l(null),[v,y]=l(null),{data:b,isLoading:x}=ve({limit:Jo,includeCrops:!1},{refetchInterval:3e4}),{data:S=[]}=ft(),{data:w}=Ne({isCamera:!0,projection:`slim`}),T=ce(),E=L(),D=Ue(),O=Date.now(),k=b??[],A=i(()=>{let e=new Map;for(let t of w??[])e.set(t.id,t.name);return e},[w]),j=e=>A.get(e)??`Camera #${String(e)}`,M=i(()=>Bn(k).map(e=>({id:e,name:j(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[k,A]),N=i(()=>zn(Rn(Qo(k,t),a),d),[k,t,a,d]),P=Xn(N,Yo,i(()=>JSON.stringify([t,a.fromMs,a.toMs,[...d].sort((e,t)=>e-t)]),[t,a.fromMs,a.toMs,d])),I=i(()=>new Map(k.map(e=>[e.plateId,e])),[k]),R=v===null?null:I.get(v)??null,ee=()=>{e.invalidateQueries({queryKey:qo})},V=()=>m(new Set);function H(e){m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let U=[...p],W=E.isPending||D.isPending,G=T.isPending||D.isPending;function K(){U.length!==0&&E.mutate({plateIds:U},{onSettled:()=>{ee(),V()}})}function te(){U.length!==0&&Promise.allSettled(U.map(e=>D.mutateAsync({plateId:e}))).then(()=>{ee(),V()})}function q(e){y(null),g([e])}function J(e){T.mutate({plateId:e},{onSettled:ee}),y(null)}function ne(e){D.mutate({plateId:e},{onSettled:ee}),y(null)}let re=N.length!==k.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(`div`,{className:`flex items-center gap-1`,children:Zo.map(e=>u(`button`,{type:`button`,onClick:()=>n(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))}),u(ir,{onChange:o}),u(nr,{cameras:M,selected:d,onChange:f}),!x&&u(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:re?`${String(N.length)} of ${String(k.length)} plates`:`${String(N.length)} plate${N.length===1?``:`s`}`})]}),p.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:[p.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[r(z,{variant:`primary`,onClick:()=>g(U),disabled:W,children:[u(Ce,{className:`h-3.5 w-3.5`}),` Assign`]}),r(z,{variant:`secondary`,onClick:K,disabled:W,children:[E.isPending?u(Z,{className:`h-3.5 w-3.5 animate-spin`}):u(Vt,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),r(z,{variant:`secondary`,onClick:te,disabled:W,children:[u(_,{className:`h-3.5 w-3.5`}),` Delete`]}),u(z,{variant:`ghost`,onClick:V,disabled:W,children:u(Y,{className:`h-3.5 w-3.5`})})]})]}),x?u(B,{status:`pending`,pendingMessage:`Loading plates…`,testId:`plates-grid`}):N.length===0?u(F,{icon:C,title:k.length>0?`Nothing matches the filter`:`No plates recognized yet`,description:k.length>0?`Widen the date range or clear the camera filter.`:`Plate reads appear here when the detection pipeline OCRs a vehicle.`}):r(s,{children:[u(B,{status:`ready`,testId:`plates-grid`,children:P.pageItems.map(e=>u(Xo,{plate:e,cameraName:j(e.deviceId),nowMs:O,selected:p.has(e.plateId),onToggleSelect:H,onAssign:e=>g([e]),onOpenDetail:y},e.plateId))}),u($n,{currentPage:P.page,totalItems:P.totalItems,pageSize:P.pageSize,onPageChange:P.setPage,itemNoun:`plates`})]}),u(Ko,{plate:R,cameraName:R?j(R.deviceId):``,onClose:()=>y(null),onAssign:q,onUnassign:J,onDelete:ne,actionsPending:G}),u(Bo,{plateIds:h,vehicles:S,onDone:()=>{g(null),V()}})]})}n();var es=[[`plateGallery`]];function ts({vehicleId:e}){let t=c(),{data:n,isLoading:i}=ct({vehicleId:e}),a=xe();function o(n){a.mutate({vehicleId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:es})}})}return i?r(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[u(Z,{className:`h-3.5 w-3.5 animate-spin`}),`Loading plates…`]}):!n||n.length===0?u(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No plates yet.`}):u(`div`,{className:`mt-2 grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-6`,children:n.map(e=>r(`div`,{className:`group relative overflow-hidden rounded-md border border-border bg-surface`,children:[r(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[e.base64?u(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:e.text,className:`h-full w-full object-cover`}):u(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:u(we,{className:`h-6 w-6`})}),u(`button`,{type:`button`,onClick:()=>o(e),disabled:a.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:u(Y,{className:`h-4 w-4 text-white`})})]}),u(`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 ns({vehicle:e,expanded:t,onToggle:n}){let i=c(),[a,o]=l(``),[d,f]=l(!1),[p,m]=l(!1),g=dt(),v=Pe();function b(){o(e.name),f(!0)}function x(){f(!1),o(``)}function S(){let t=a.trim();if(!t||t===e.name){x();return}g.mutate({id:e.id,name:t},{onSettled:()=>{i.invalidateQueries({queryKey:es}),x()}})}function C(){v.mutate({id:e.id},{onSettled:()=>{i.invalidateQueries({queryKey:es}),m(!1)}})}return r(`div`,{className:`rounded-md border border-border bg-surface`,children:[r(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[u(`div`,{className:`h-8 w-12 shrink-0 overflow-hidden rounded border border-border bg-surface-hover`,children:u(Ht,{mediaId:e.coverMediaId,base64:e.coverBase64,alt:e.name,className:`h-full w-full object-cover`,placeholder:u(`div`,{className:`flex h-full w-full items-center justify-center`,children:u(we,{className:`h-4 w-4 text-foreground-subtle`})})})}),u(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:d?r(s,{children:[u(X,{value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&S(),e.key===`Escape`&&x()},className:`h-6 text-xs`,autoFocus:!0}),u(`button`,{type:`button`,onClick:S,disabled:g.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:u(nt,{className:`h-3.5 w-3.5`})}),u(`button`,{type:`button`,onClick:x,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:u(Y,{className:`h-3.5 w-3.5`})})]}):u(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),u(rt,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!d&&r(`div`,{className:`flex items-center gap-1`,children:[u(`button`,{type:`button`,onClick:b,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:u(Ve,{className:`h-3.5 w-3.5`})}),u(`button`,{type:`button`,onClick:()=>m(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:u(_,{className:`h-3.5 w-3.5`})})]}),u(`button`,{type:`button`,onClick:n,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:u(t?h:y,{className:`h-3.5 w-3.5`})})]}),t&&u(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:u(ts,{vehicleId:e.id})}),u(R,{open:p,onOpenChange:e=>!e&&m(!1),children:r(Re,{children:[r(K,{children:[u(J,{children:`Delete vehicle`}),r(M,{children:[`Delete `,u(`strong`,{children:e.name}),` and all its plate samples? This cannot be undone.`]})]}),r(Ie,{children:[u(z,{variant:`secondary`,onClick:()=>m(!1),children:`Cancel`}),r(z,{variant:`danger`,onClick:C,disabled:v.isPending,children:[v.isPending?u(Z,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function rs(){let e=c(),[t,n]=l(``),i=Xe();function a(){let r=t.trim();r&&i.mutate({name:r},{onSettled:()=>{e.invalidateQueries({queryKey:es}),n(``)}})}return r(`div`,{className:`flex items-center gap-2 pt-2`,children:[u(X,{placeholder:`New vehicle name…`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&a()},className:`h-7 text-xs flex-1`}),r(z,{variant:`primary`,size:`sm`,onClick:a,disabled:i.isPending||!t.trim(),children:[i.isPending?u(Z,{className:`h-3.5 w-3.5 animate-spin`}):u(Ke,{className:`h-3.5 w-3.5`}),`Add`]})]})}function is(){let{data:e,isLoading:t}=ft(),n=e??[],i=N(n,{searchText:e=>[e.name]}),[a,o]=l(null);function s(e){o(t=>t===e?null:e)}return t?r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(Z,{className:`h-4 w-4 animate-spin`}),`Loading vehicles…`]}):r(`div`,{className:`space-y-2`,children:[(n.length>0||i.active)&&u(Le,{state:i.state,facets:i.facets,labels:{searchPlaceholder:`Search vehicles…`,searchLabel:`Search vehicles`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:i.setSearch,onToggleFacet:i.toggleFacet,onClear:i.clear}),i.rows.length===0?u(F,{icon:we,title:i.active?`Nothing matches the filter`:`No vehicles enrolled yet`,description:i.active?`Clear the search or try another name.`:`Add a vehicle below, then assign plate crops from Recent recognized plates.`}):i.rows.map(e=>u(ns,{vehicle:e,expanded:a===e.id,onToggle:()=>s(e.id)},e.id)),u(rs,{})]})}n();var as=[[`plateGallery`]],os=2e3;function ss(){let e=c(),n=t(e);n.current=e;let r=t(void 0);r.current||=Fr({delayMs:os,invalidate:()=>{n.current.invalidateQueries({queryKey:as})}}),d(()=>()=>r.current?.cancel(),[]),Ye(vt.PipelineAnalyticsPlateGalleryChanged,()=>{r.current?.trigger()})}function cs(){return ss(),r(`div`,{className:`space-y-3`,children:[u(se,{headingId:`library-vehicles`,title:`Vehicles`,icon:we,testId:`library-section-vehicles`,children:r(`div`,{className:`${f} space-y-3`,children:[u(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:`Enrolled vehicle identities used for plate recognition. Expand a row to view or remove plate samples.`}),u(is,{})]})}),u(se,{headingId:`library-recent-plates`,title:`Recent recognized plates`,icon:Rt,testId:`library-section-recent-plates`,children:r(`div`,{className:`${f} space-y-3`,children:[u(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:`License plates read by the detection pipeline. Assign them to a vehicle, correct the OCR text, or delete.`}),u($o,{})]})})]})}function ls(e){return e.states.length===0?3:e.latched?0:e.verdict===`diverged`?1:e.verdict===`unknown`?2:4}function us(e){let t=[e.divergedAt,e.restoredAt].filter(e=>typeof e==`number`);return t.length===0?null:Math.max(...t)}function ds(e,t){let n=new Map(e.map(e=>[e.deviceId,e.deviceName])),r=[];for(let e of t)for(let t of e.monitors)r.push({deviceId:e.deviceId,deviceName:n.get(e.deviceId)??`Camera ${e.deviceId}`,monitor:t});return r.toSorted((e,t)=>{let n=ls(e.monitor)-ls(t.monitor);if(n!==0)return n;let r=us(e.monitor)??-1,i=us(t.monitor)??-1;if(r!==i)return i-r;let a=e.deviceName.localeCompare(t.deviceName);return a===0?e.monitor.label.localeCompare(t.monitor.label):a})}n();var fs={alarm:`danger`,ok:`success`,unknown:`default`},ps={alarm:`Alarm`,ok:`OK`,unknown:`Unknown`};function ms(e,t){let n=us(e);return n===null?`—`:`${w(Math.max(0,t-n))} ago`}function hs(e){return g(e.monitor).tone}function gs(){let e=Ne({isCamera:!0,projection:`slim`}),t=i(()=>(e.data??[]).map(e=>({deviceId:e.id,deviceName:e.name})).sort((e,t)=>e.deviceName.localeCompare(t.deviceName)),[e.data]),n=i(()=>t.map(e=>e.deviceId),[t]),o=Nt(n),s=i(()=>ds(t,o.results),[t,o.results]),c=N(s,{searchText:e=>[e.monitor.label,e.deviceName],facetValue:hs}),[d,f]=l(null),[p,m]=l(null),h=Date.now(),_=t.find(e=>e.deviceId===d)?.deviceName??``;return r(`section`,{className:`space-y-3`,children:[r(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-4`,children:[u(`p`,{className:`text-xs text-foreground-subtle`,children:`A scene watches one region of one camera and tells you when it stops looking like the picture you captured — a wheelie bin, a gate, a parking space.`}),r(z,{onClick:()=>m(n[0]??null),disabled:t.length===0,className:`shrink-0`,children:[u(Ke,{className:`mr-1 h-3.5 w-3.5`}),`New scene`]})]}),o.unreachableCount>0?r(`p`,{className:`text-xs text-warning`,children:[o.unreachableCount,` camera`,o.unreachableCount===1?``:`s`,` could not be asked about scenes. Those cameras are missing from this list — this is not the same as having no scenes.`]}):null,(s.length>0||c.active)&&u(Le,{state:c.state,facets:c.facets,labels:{searchPlaceholder:`Search scenes…`,searchLabel:`Search scenes`,facetsLabel:`State`,clearLabel:`Clear`},facetLabel:e=>ps[e]??e,onSearch:c.setSearch,onToggleFacet:c.toggleFacet,onClear:c.clear}),u(V,{variant:`flat`,className:`p-0`,children:u(mt,{columns:[{key:`label`,header:`Scene`,sortValue:e=>e.monitor.label,render:e=>u(`span`,{className:`font-medium`,children:e.monitor.label})},{key:`camera`,header:`Camera`,nowrap:!0,sortValue:e=>e.deviceName,render:e=>e.deviceName},{key:`state`,header:`State`,nowrap:!0,sortValue:e=>hs(e),render:e=>{let t=g(e.monitor);return u(rt,{variant:fs[t.tone],children:t.text})}},{key:`status`,header:`What it says`,notSortableReason:`Status is a live sentence, not a comparable value`,render:e=>u(`span`,{className:`text-xs text-foreground-muted`,children:v(e.monitor,h)})},{key:`coverage`,header:`Variants`,notSortableReason:`Coverage is a summary string`,render:e=>u(`span`,{className:`text-xs text-foreground-muted`,children:b(e.monitor)})},{key:`transition`,header:`Last change`,align:`right`,nowrap:!0,sortValue:e=>us(e.monitor)??0,render:e=>u(`span`,{className:`text-xs tabular-nums text-foreground-muted`,children:ms(e.monitor,h)})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:e=>u(z,{variant:`ghost`,onClick:()=>f(e.deviceId),children:`Open`})}],rows:c.rows,rowKey:e=>`${e.deviceId}:${e.monitor.id}`,minWidthPx:880,bordered:!1,mobileMode:`scroll`,maxBodyHeight:I,emptyMessage:o.isLoading?`Loading scenes…`:c.active?`Nothing matches the filter`:`No scenes yet. Press “New scene”, pick a camera, then draw a box around the thing you want watched.`})}),u(R,{open:p!==null,onOpenChange:e=>!e&&m(null),children:r(Re,{width:`sm`,children:[r(K,{children:[u(J,{children:`Which camera?`}),u(M,{children:`A scene lives on one camera. Pick the one that can see the thing.`})]}),r(`div`,{className:`mt-3 flex items-center gap-2`,children:[u(de,{value:p===null?``:String(p),onChange:e=>m(Number(e.target.value)),"aria-label":`Camera`,options:t.map(e=>({value:String(e.deviceId),label:e.deviceName}))}),u(z,{onClick:()=>{f(p),m(null)},disabled:p===null,children:`Continue`})]})]})}),u(R,{open:d!==null,onOpenChange:e=>!e&&f(null),children:r(Re,{width:`lg`,scroll:`body`,children:[r(K,{children:[r(J,{children:[`Scenes — `,_]}),u(M,{children:`Draw a box, name it, then capture what “normal” looks like. Daylight is enough — the night reference is optional, and “Settings” on each scene tunes how fussy and how often it checks.`})]}),u(ie,{className:`mt-3`,children:d===null?null:u(a,{fallback:u(`p`,{className:`text-xs text-foreground-muted`,children:`Loading the editor…`}),children:u(it,{deviceId:d})})})]})})]})}var _s=[`people`,`vehicles`,`events`,`scenes`];function vs(e){return e!==null&&_s.some(t=>t===e)}function ys(e,t){let n=new URLSearchParams(e);return n.set(`tab`,t),t!==`events`&&n.delete(`section`),`?${n.toString()}`}function bs(){let[e]=bt(),t=e.get(`tab`),n=vs(t)?t:`people`;return r(wt,{icon:Ct,title:`Library`,subtitle:`People, vehicles, captured events and scenes — what detection has recognised.`,nav:u(Tt,{label:`Library sections`,items:[{id:`people`,label:`People`,href:ys(e,`people`),current:n===`people`,testId:`library-pill-people`},{id:`vehicles`,label:`Vehicles`,href:ys(e,`vehicles`),current:n===`vehicles`,testId:`library-pill-vehicles`},{id:`events`,label:`Events`,href:ys(e,`events`),current:n===`events`,testId:`library-pill-events`},{id:`scenes`,label:`Scenes`,href:ys(e,`scenes`),current:n===`scenes`,testId:`library-pill-scenes`}],replace:!0}),children:[n===`people`?u(zr,{}):null,n===`vehicles`?u(cs,{}):null,n===`events`?u(Lo,{}):null,n===`scenes`?u(gs,{}):null]})}export{bs as LibraryPage};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{Q as e,S as t,W as n,b as r,o as i,q as a,x as o,z as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as c,ct as l,gt as u,vt as d,yt as f}from"./player-overlays-Sm-ivm_8.js";import{$n as p,Af as m,At as h,Au as g,Cu as _,Da as v,Du as y,Ea as b,Eu as x,Fu as S,Gd as C,Gi as w,Hd as T,Id as E,Ju as D,Ki as ee,Lu as O,Ma as te,Na as k,Oa as A,Od as j,Of as M,Ou as N,Pa as ne,Pu as re,Qu as ie,Rd as P,Sf as F,Ta as ae,Tu as I,Ud as oe,Uu as se,V as L,Xd as R,Xl as ce,Zu as le,_a as ue,_d as z,ba as de,cf as fe,cu as pe,df as me,du as B,ed as V,ef as H,gf as he,ha as ge,hu as _e,ja as ve,jt as U,ju as ye,kd as be,kf as xe,ld as Se,lu as W,mf as Ce,mu as we,nd as Te,od as G,pf as Ee,sn as De,tf as Oe,ud as ke,va as Ae,vf as je,vu as Me,wd as Ne,xf as Pe,ya as Fe,yd as Ie,za as Le,zd as Re,zt as ze,zu as Be}from"./src-CmnrQw1X.js";import{t as Ve}from"./boxes-X_rDWdou.js";import{t as He}from"./user-round-BLTQwaog.js";import{$n as K,$t as Ue,Qn as q,er as J}from"./client-B2uiK_6q.js";import{t as We}from"./useTranslation-Bc5yH9V9.js";import{$ as Ge,Y}from"./index-BlUdDWLp.js";import{t as Ke}from"./AdminPage-C1SqQSAP.js";var qe=f(`circle-arrow-up`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 12-4-4-4 4`,key:`177agl`}],[`path`,{d:`M12 16V8`,key:`1sbj14`}]]);e();var Je={camera:d,hub:le,container:Ve,light:Ne,siren:Be,switch:y,sensor:m,thermostat:N,climate:xe,button:Oe,"event-emitter":pe,update:qe,notifier:he,script:D,automation:B,lock:Ie,cover:Ce,valve:oe,humidifier:T,"water-heater":E,fan:Re,"media-player":re,"alarm-panel":se,control:O,presence:He,weather:R,vacuum:Ee,"lawn-mower":x,image:j,smoke:M};function X({type:e,className:t}){return o(Je[e]??Oe,{"aria-hidden":`true`,className:t??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function Ye({online:e,deviceName:t}){return o(`span`,{className:e?`inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-emerald-500`:`inline-block h-1.5 w-1.5 shrink-0 rounded-full border border-foreground-subtle`,role:`img`,"aria-label":`${t}: ${e?`online`:`offline`}`,title:e?`online`:`offline`})}function Xe({name:e,description:n,busy:r,onSave:i}){let[c,l]=a(n??``);return s(()=>{l(n??``)},[n]),t(`div`,{className:`border-t border-border px-3 py-2`,children:[o(`label`,{htmlFor:`location-description-${e}`,className:`block text-[10px] font-medium uppercase tracking-wide text-foreground-subtle`,children:`What is there`}),o(`textarea`,{id:`location-description-${e}`,value:c,onChange:e=>l(e.target.value),onBlur:()=>{let e=c.trim();e!==(n??``)&&i(e.length===0?null:e)},disabled:r,rows:2,maxLength:400,placeholder:`Surfaces, boundaries, what is normally parked or stored here.`,className:`mt-1 w-full resize-y rounded border border-border bg-background px-1.5 py-1 text-[11px] text-foreground placeholder:text-foreground-subtle disabled:opacity-50`}),o(`p`,{className:`mt-0.5 text-[10px] text-foreground-subtle`,children:`Given to the AI with the pictures, so it knows what it is looking at. Describe the PLACE, not what happens in it — events change, the ground does not.`})]})}function Ze(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0||n.description.length===0?null:n.description}var Z=` none`;function Qe({name:e,zones:n,zoneKey:r,busy:i,onChange:a}){return n.length===0?null:t(`div`,{className:`flex items-center gap-2 border-t border-border px-3 py-1.5`,children:[o(`label`,{htmlFor:`location-zone-${e}`,className:`text-[10px] font-medium uppercase tracking-wide text-foreground-subtle`,children:`Zone`}),t(`select`,{id:`location-zone-${e}`,value:r??Z,disabled:i,onChange:e=>{let t=e.target.value;if(t===Z){a(null);return}let r=n.find(e=>e.zoneKey===t);r!==void 0&&a(r.label)},className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-foreground disabled:opacity-50`,children:[o(`option`,{value:Z,children:`— none —`}),n.map(e=>o(`option`,{value:e.zoneKey,children:e.label},e.zoneKey))]})]})}function $e(e,t){return e.find(e=>e.locationKeys.includes(t))?.zoneKey??null}var et={"map-pin":{icon:z,label:`Pin`},house:{icon:be,label:`Home`},"door-open":{icon:C,label:`Entrance`},sofa:{icon:S,label:`Living room`},utensils:{icon:Me,label:`Kitchen`},"bed-double":{icon:je,label:`Bedroom`},bath:{icon:Pe,label:`Bathroom`},briefcase:{icon:me,label:`Office`},car:{icon:fe,label:`Garage`},"circle-parking":{icon:H,label:`Parking`},route:{icon:ie,label:`Street`},trees:{icon:I,label:`Garden`},umbrella:{icon:_,label:`Terrace`},"waves-ladder":{icon:we,label:`Pool`},fence:{icon:P,label:`Gate`},package:{icon:ke,label:`Storage`},warehouse:{icon:_e,label:`Warehouse`},store:{icon:ye,label:`Shop`},sun:{icon:g,label:`Outdoor`},radar:{icon:Te,label:`Perimeter`}},tt=q.map(e=>({id:e,...et[e]}));function nt(e){return et[J(e)].icon}var rt=new Map(tt.map(e=>[e.id,[e.label]])),it=new Map(tt.map(e=>[e.id,e.label])),at=new Set(q);function ot(e){return at.has(e)?nt(e):void 0}function Q({name:e,icon:t,busy:n,onPick:r}){return o(ce,{value:t,onPick:e=>r(e===null?null:J(e)),resolveGlyph:ot,fallbackGlyph:z,clearGlyph:F,labelFor:e=>it.get(e),labels:{trigger:`Change the icon of ${e}`,panel:`Icon for ${e}`,close:`Close icon picker`,searchPlaceholder:`Search icons`,clear:`No icon`,noMatches:`No icon matches that`,groups:{device:`Devices`,lighting:`Lights and climate`,sensing:`Sensors and weather`,place:`Rooms and places`,life:`Vehicles, animals and people`}},only:q,extraWords:rt,disabled:n})}function st(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0?null:J(n.icon)}function $(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function ct(e,t){let n=$(t);return n===null?[]:e.filter(e=>$(e.location)===n)}function lt(e,t){let n=ct(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function ut(e,t){let n=$(e.location);return n===null||new Set(t.map(e=>$(e))).has(n)?null:e.location?.trim()??null}function dt(e,t){let n=$(e.location);return n!==null&&t.has(n)}function ft(e,t){let n=new Set(t.map(e=>$(e))),r=new Set(e.filter(e=>dt(e,n)).map(e=>e.id));return e.filter(e=>!(dt(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function pt(e,t){return ft(e,t).filter(e=>e.parentDeviceId===null)}function mt(e,t){let n=new Map;for(let t of e){if(t.parentDeviceId===null)continue;let e=n.get(t.parentDeviceId);e?e.push(t):n.set(t.parentDeviceId,[t])}let r=[],i=new Set([t]),a=[t];for(;a.length>0;){let e=[];for(let t of a)for(let a of n.get(t)??[])i.has(a.id)||(i.add(a.id),r.push(a),e.push(a.id));a=e}return r}function ht(e,t){return mt(e,t).length}function gt(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function _t(e,t){return t.map(t=>({name:t,members:lt(e,t)}))}function vt(e){return`${e.kind}:${String(e.device.id)}`}function yt(e,t,n){return e.flatMap(e=>{let r=gt(t,e.id),i=n.has(e.id),a={kind:`member`,device:e,accessories:r,open:i};return!i||r.length===0?[a]:[a,...r.map(t=>({kind:`accessory`,device:t,parent:e}))]})}e();function bt({name:e,members:i,devices:s,busy:c,icon:u,description:d,onRename:f,onDelete:p,onRebuildLinks:m,onPickIcon:g,onSaveDescription:_,zones:v,zoneKey:y,onChangeZone:b}){let{t:x}=We(),[S,C]=a(!1),[w,T]=a(e),E=h(i,n(()=>({searchText:e=>[e.name,...gt(s,e.id).map(e=>e.name)],facetValue:e=>e.type}),[s])),[D,ee]=a(()=>new Set),O=e=>ee(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),te=n(()=>yt(E.rows,s,D),[E.rows,s,D]),k=[{key:`name`,header:x(`locations.columns.device`),notSortableReason:x(`locations.columns.noSort`),render:e=>e.kind===`member`?o(xt,{row:e,onToggle:()=>O(e.device.id)}):o(St,{row:e})},{key:`type`,header:x(`locations.columns.type`),notSortableReason:x(`locations.columns.noSort`),render:e=>o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.device.type})},{key:`status`,header:x(`locations.columns.status`),notSortableReason:x(`locations.columns.noSort`),render:e=>t(`span`,{className:`flex items-center gap-1.5`,children:[o(Ye,{online:e.device.online,deviceName:e.device.name}),o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.device.online?`online`:`offline`})]})}],A=()=>{T(e),C(!1)},j=async()=>{let t=w.trim();if(t.length===0||t===e){A();return}await f(t),C(!1)};return t(`section`,{className:`min-w-0 rounded-md border border-border bg-surface`,children:[t(`header`,{className:`flex items-center gap-1.5 border-b border-border px-3 py-1.5`,children:[o(Q,{name:e,icon:u,busy:c,onPick:g}),S?t(r,{children:[o(`input`,{value:w,onChange:e=>T(e.target.value),onKeyDown:e=>{e.key===`Enter`&&j(),e.key===`Escape`&&A()},"aria-label":`Rename ${e}`,className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-sm font-semibold text-foreground`,autoFocus:!0}),o(`button`,{type:`button`,onClick:()=>void j(),className:`text-[11px] text-foreground-subtle hover:text-foreground`,children:`Save`}),o(`button`,{type:`button`,onClick:A,"aria-label":`Cancel rename`,className:`p-0.5 text-foreground-subtle hover:text-foreground`,children:o(W,{className:`h-3.5 w-3.5`})})]}):t(r,{children:[o(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:e}),o(L,{items:[{id:`rename`,label:`Rename`,icon:Se,disabled:c,onClick:()=>{T(e),C(!0)}},{id:`rebuild-links`,label:`Rebuild linked devices`,icon:V,separatorBefore:!0,disabled:c,onClick:()=>void m()},{id:`delete`,label:`Delete`,icon:l,danger:!0,separatorBefore:!0,disabled:c,onClick:()=>void p()}],title:`Actions for ${e}`,triggerClassName:`p-1`})]})]}),o(Qe,{name:e,zones:v,zoneKey:y,busy:c,onChange:b}),o(Xe,{name:e,description:d,busy:c,onSave:_}),i.length>0&&o(`div`,{className:`border-b border-border px-3 py-1.5`,children:o(U,{state:E.state,facets:E.facets,labels:{searchPlaceholder:x(`locations.filter.searchPlaceholder`),searchLabel:x(`locations.room.searchLabel`,{room:e}),facetsLabel:x(`locations.filter.typesLabel`),clearLabel:x(`locations.filter.clear`)},onSearch:E.setSearch,onToggleFacet:E.toggleFacet,onClear:E.clear})}),i.length===0?o(`p`,{className:`px-3 py-3 text-[11px] text-foreground-subtle`,children:`Nothing here yet — assign a device from the table below.`}):o(ze,{columns:k,rows:te,rowKey:vt,bordered:!1,minWidthPx:360,mobileMode:`scroll`,emptyMessage:x(`locations.filter.noMatch`)})]})}function xt({row:e,onToggle:n}){let{device:r,accessories:i,open:a}=e,s=a?c:u;return t(`span`,{className:`flex items-center gap-1.5`,children:[i.length>0?t(`button`,{type:`button`,onClick:n,"aria-expanded":a,"aria-label":`${a?`Collapse`:`Expand`} ${String(i.length)} companion device(s) of ${r.name}`,className:`flex shrink-0 items-center gap-0.5 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:[o(s,{className:`h-3 w-3`}),o(`span`,{className:`text-[10px] tabular-nums`,children:i.length})]}):o(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),o(X,{type:r.type}),o(Y,{to:`/devices/${String(r.id)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:r.name})]})}function St({row:e}){let{device:n}=e;return t(`span`,{className:`flex items-center gap-1.5 pl-6`,children:[o(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),o(X,{type:n.type,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),o(Y,{to:`/devices/${String(n.id)}`,className:`min-w-0 truncate text-[11px] text-foreground-muted hover:underline`,children:n.name})]})}e();function Ct({zones:e,busy:n,onCreate:r,onRename:i,onDelete:s,onPickIcon:c}){let[u,d]=a(!1),[f,p]=a(``),[m,h]=a(null),[g,_]=a(``),v=async()=>{let e=f.trim();e.length!==0&&(await r(e),p(``),d(!1))},y=async e=>{let t=g.trim();h(null),!(t.length===0||t===e)&&await i(e,t)};return t(`section`,{className:`rounded-md border border-border bg-surface`,children:[t(`header`,{className:`flex items-center gap-2 border-b border-border px-3 py-1.5`,children:[o(`h2`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Zones`}),u?null:t(`button`,{type:`button`,onClick:()=>d(!0),disabled:n,className:`flex items-center gap-1 text-[11px] text-foreground-muted hover:text-foreground disabled:opacity-50`,children:[o(G,{className:`h-3 w-3`}),` New zone`]})]}),u&&t(`div`,{className:`flex items-center gap-1.5 border-b border-border px-3 py-1.5`,children:[o(`input`,{value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&v(),e.key===`Escape`&&(p(``),d(!1))},placeholder:`Zona notte`,"aria-label":`New zone name`,autoFocus:!0,className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`}),o(`button`,{type:`button`,onClick:()=>void v(),className:`text-[11px] text-foreground-subtle hover:text-foreground`,children:`Add`}),o(`button`,{type:`button`,onClick:()=>{p(``),d(!1)},"aria-label":`Cancel new zone`,className:`p-0.5 text-foreground-subtle hover:text-foreground`,children:o(W,{className:`h-3.5 w-3.5`})})]}),e.length===0?o(`p`,{className:`px-3 py-2 text-[11px] text-foreground-subtle`,children:`No zones yet. A zone groups rooms — “Zona notte” for the bedrooms — and shows up before them in the app’s camera filter.`}):o(`ul`,{className:`py-0.5`,children:e.map(e=>t(`li`,{className:`flex items-center gap-1.5 px-3 py-1`,children:[o(Q,{name:e.label,icon:e.icon,busy:n,onPick:t=>c(e.label,t)}),m===e.label?o(`input`,{value:g,onChange:e=>_(e.target.value),onKeyDown:t=>{t.key===`Enter`&&y(e.label),t.key===`Escape`&&h(null)},onBlur:()=>void y(e.label),"aria-label":`Rename ${e.label}`,autoFocus:!0,className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`}):o(`button`,{type:`button`,onClick:()=>{_(e.label),h(e.label)},disabled:n,className:`min-w-0 flex-1 truncate text-left text-xs text-foreground hover:underline disabled:opacity-50`,children:e.label}),o(`span`,{className:`shrink-0 text-[10px] tabular-nums text-foreground-subtle`,children:e.locationKeys.length===0?`empty`:`${String(e.locationKeys.length)} rooms`}),o(`button`,{type:`button`,onClick:()=>void s(e.label),disabled:n,"aria-label":`Delete ${e.label}`,title:`Delete the zone — the rooms in it are kept`,className:`shrink-0 p-0.5 text-foreground-subtle hover:text-danger disabled:opacity-50`,children:o(l,{className:`h-3.5 w-3.5`})})]},e.zoneKey))})]})}e();function wt({busy:e,onCreate:n}){let[r,i]=a(!1),[s,c]=a(``),l=()=>{c(``),i(!1)},u=async()=>{let e=s.trim();e.length!==0&&(await n(e),l())};return r?t(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),u()},children:[o(`input`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Escape`&&l()},placeholder:`Ingresso, Salone, Cucina…`,"aria-label":`New location name`,className:`min-w-[16rem] flex-1 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,autoFocus:!0}),t(`button`,{type:`submit`,disabled:s.trim().length===0||e,className:`inline-flex items-center gap-1 rounded border border-border bg-surface px-2 py-1.5 text-xs font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[o(G,{className:`h-3.5 w-3.5`}),`Add`]}),o(`button`,{type:`button`,onClick:l,"aria-label":`Cancel new location`,className:`p-1 text-foreground-subtle hover:text-foreground`,children:o(W,{className:`h-3.5 w-3.5`})})]}):t(`button`,{type:`button`,onClick:()=>i(!0),className:`inline-flex w-fit items-center gap-1 rounded border border-border bg-surface px-2 py-1.5 text-xs font-medium text-foreground hover:bg-surface-hover`,children:[o(G,{className:`h-3.5 w-3.5`}),`New location`]})}e();var Tt={searchText:e=>[e.name],facetValue:e=>e.type};function Et({rows:e,fleet:r,locations:i,busy:s,emptyMessage:c,onAssign:l}){let{t:u}=We(),[d,f]=a([]),[p,m]=a(``),g=h(e,Tt),_=g.rows,v=n(()=>_.map(e=>e.id),[_]),y=n(()=>d.filter(e=>v.includes(e)),[d,v]),b=_.length>0&&y.length===_.length,x=n(()=>{let t=new Map;for(let n of e)t.set(n.id,ht(r,n.id));return t},[e,r]),S=y.reduce((e,t)=>e+(x.get(t)??0),0),C=e=>f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),w=()=>f(b?[]:v);return t(`section`,{className:`space-y-2`,children:[t(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Not in a room`}),o(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Top-level devices only — accessories move with their parent.`})]}),e.length>0&&o(U,{state:g.state,facets:g.facets,labels:{searchPlaceholder:u(`locations.filter.searchPlaceholder`),searchLabel:u(`locations.unassigned.searchLabel`),facetsLabel:u(`locations.filter.typesLabel`),clearLabel:u(`locations.filter.clear`)},onSearch:g.setSearch,onToggleFacet:g.toggleFacet,onClear:g.clear}),y.length>0&&t(`div`,{role:`group`,"aria-label":`Bulk assignment`,className:`flex flex-wrap items-center gap-2 rounded border border-primary/40 bg-primary/5 px-2 py-1.5`,children:[t(`span`,{className:`text-[11px] text-foreground`,children:[y.length,` selected`,S>0&&` · ${String(S)} accessories in tow`]}),t(`select`,{"aria-label":`Assign selected devices to`,value:p,onChange:e=>m(e.target.value),className:`rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-foreground`,children:[o(`option`,{value:``,children:`Assign to…`}),i.map(e=>o(`option`,{value:e,children:e},e))]}),o(`button`,{type:`button`,onClick:()=>{p.length===0||y.length===0||(l(y,p),f([]),m(``))},disabled:s||p.length===0,className:`rounded border border-border bg-surface px-2 py-0.5 text-[11px] font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:`Assign`}),o(`button`,{type:`button`,onClick:()=>f([]),className:`text-[11px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),o(ze,{columns:[{key:`select`,width:`w-8`,headerRender:()=>o(De,{checked:b,onChange:w,"aria-label":b?`Clear selection`:`Select all unassigned devices`}),render:e=>o(De,{checked:y.includes(e.id),onChange:()=>C(e.id),"aria-label":`Select ${e.name}`})},{key:`name`,header:`Device`,sortValue:e=>e.name.toLowerCase(),render:e=>{let n=ut(e,i);return t(`span`,{className:`flex items-center gap-1.5`,children:[o(X,{type:e.type}),o(Y,{to:`/devices/${String(e.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:e.name}),n!==null&&t(`span`,{className:`rounded-full border border-warning/40 px-1.5 py-px text-[10px] text-warning`,children:[`unknown room “`,n,`”`]})]})}},{key:`type`,header:`Type`,sortValue:e=>e.type,render:e=>o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.type})},{key:`status`,header:`Status`,sortValue:e=>+!!e.online,render:e=>t(`span`,{className:`flex items-center gap-1.5`,children:[o(Ye,{online:e.online,deviceName:e.name}),o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.online?`online`:`offline`})]})},{key:`followers`,header:`Accessories in tow`,align:`right`,sortValue:e=>x.get(e.id)??0,render:e=>o(`span`,{className:`tabular-nums text-[11px] text-foreground-muted`,children:x.get(e.id)??0})},{key:`assign`,header:`Assign to`,align:`right`,notSortableReason:`This column is a control, not a value.`,render:e=>t(`select`,{"aria-label":`Location for ${e.name}`,value:``,disabled:s||i.length===0,onChange:t=>{let n=t.target.value;n.length!==0&&l([e.id],n)},className:`max-w-[11rem] rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-foreground disabled:opacity-50`,children:[o(`option`,{value:``,children:`—`}),i.map(e=>o(`option`,{value:e,children:e},e))]})}],rows:_,rowKey:e=>e.id,minWidthPx:720,mobileMode:`scroll`,emptyMessage:g.active?u(`locations.filter.noMatch`):c})]})}function Dt(e){return{id:e.id,parentDeviceId:e.parentDeviceId,location:e.location,type:e.type,stableId:e.stableId??``,...e.primaryChildEntityId===void 0?{}:{primaryChildEntityId:e.primaryChildEntityId},...e.role!==void 0&&e.role!==null?{role:e.role}:{},name:e.name}}function Ot(e,t){let n=t.map(Dt),r=[];for(let i of t)i.isCamera&&i.location===e&&r.push({deviceId:i.id,name:i.name,ids:Ue({selfId:i.id,selfLocation:i.location,candidates:n})});return{entries:r}}var kt=`device-manager:linked-devices`;function At(e){return{deviceId:e.deviceId,slotRef:kt,value:{slot:`linked-devices`,deviceIds:[...e.ids]}}}e();function jt(){let e=i(),r=p(),{data:a,isLoading:s}=Fe(),{data:c}=Ae(),{data:l}=ue(),{data:u}=de(),{data:d,isLoading:f}=ge({projection:`slim`}),m=()=>{e.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listLocationIcons`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listLocationDescriptions`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listSiteZones`]]})},h=ee({onSuccess:m}),g=ae({onSuccess:m}),_=ve({onSuccess:m}),y=v({onSuccess:m}),x=k({onSuccess:m}),S=te({onSuccess:m}),C=Le({onSuccess:m}),T=b({onSuccess:m}),E=A({onSuccess:m}),D=ne({onSuccess:m}),O=w(),j=n(()=>(d??[]).map(e=>({id:e.id,name:e.name,location:e.location??null,type:String(e.type),isCamera:e.isCamera,parentDeviceId:e.parentDeviceId,online:e.online,role:e.role??null,stableId:e.stableId,primaryChildEntityId:e.primaryChildEntityId??null})),[d]),M=a??[],N=n(()=>_t(j,M),[j,M]),[re,ie]=Ge(),P=re.get(`room`),F=P!==null&&N.some(e=>e.name===P)?P:N[0]?.name??null,I=N.find(e=>e.name===F)??null,oe=e=>{ie(t=>{let n=new URLSearchParams(t);return n.set(`room`,e),n},{replace:!0})},se=n(()=>pt(j,M),[j,M]),L=s||f,R=_.isPending||g.isPending||h.isPending||x.isPending,ce=async e=>{await h.mutateAsync({name:e})},le=async(e,t)=>{let n=t.trim();n.length===0||n===e||await y.mutateAsync({from:e,to:n})},fe=async e=>{let t=Ot(e,j);if(t.entries.length===0){await r({title:`Rebuild linked devices`,message:`No camera is assigned to “${e}”.`,confirmLabel:`OK`});return}if(!await r({title:`Rebuild linked devices`,message:`Replace the linked-device list of every camera in “${e}” with what the room contains?\n\n${t.entries.map(e=>`• ${e.name}: ${String(e.ids.length)} device(s)`).join(`
|
|
2
|
-
`)}\n\nAnything linked by hand that is not in this room is lost.`,confirmLabel:`Rebuild`,variant:`danger`}))return;let n=[];for(let e of t.entries)try{await O.mutateAsync(At(e))}catch(t){n.push(`• ${e.name}: ${t instanceof Error?t.message:String(t)}`)}m(),n.length>0&&await r({title:`Rebuild linked devices`,message:`Not rebuilt:\n\n${n.join(`
|
|
3
|
-
`)}`,confirmLabel:`OK`})},pe=async(e,t)=>{await r({title:`Delete location`,message:`Delete the location “${e}”?${t>0?` ${String(t)} device(s) will become unassigned.`:``}`,confirmLabel:`Delete`,variant:`danger`})&&await g.mutateAsync({name:e,cascade:!0})},me=async(e,t)=>{await x.mutateAsync({location:e,icon:t})},B=async(e,t)=>{await S.mutateAsync({location:e,description:t})},V=u??[],H=async(e,t)=>{await D.mutateAsync({location:e,zone:t})};return t(Ke,{icon:z,title:`Locations`,subtitle:`Rooms and areas of the site. Assign any device here — storage disks are under Data → Storage.`,children:[o(wt,{busy:h.isPending,onCreate:ce}),o(Ct,{zones:V,busy:R,onCreate:e=>C.mutateAsync({name:e}),onRename:(e,t)=>E.mutateAsync({from:e,to:t}),onDelete:e=>T.mutateAsync({name:e}),onPickIcon:(e,t)=>C.mutateAsync({name:e,icon:t})}),L&&o(`p`,{className:`text-xs text-foreground-subtle`,children:`Loading locations and devices…`}),N.length>0&&o(`div`,{role:`tablist`,"aria-label":`Locations`,className:`-mx-1 flex gap-1 overflow-x-auto px-1 pb-1`,children:N.map(e=>{let n=e.name===F,r=nt(st(c,K(e.name)));return t(`button`,{type:`button`,role:`tab`,"aria-selected":n,onClick:()=>oe(e.name),className:n?`shrink-0 whitespace-nowrap rounded-full border border-primary bg-primary/10 px-3 py-1 text-xs text-foreground`:`shrink-0 whitespace-nowrap rounded-full border border-border px-3 py-1 text-xs text-foreground-muted hover:bg-surface-hover`,children:[o(r,{className:`mr-1 inline h-3.5 w-3.5 align-text-bottom`}),e.name,` `,o(`span`,{className:`text-foreground-subtle tabular-nums`,children:e.members.length})]},e.name)})}),I!==null&&o(bt,{name:I.name,members:I.members,devices:j,busy:R,icon:st(c,K(I.name)),onPickIcon:e=>me(I.name,e),description:Ze(l,K(I.name)),onSaveDescription:e=>B(I.name,e),zones:V,zoneKey:$e(V,K(I.name)),onChangeZone:e=>H(I.name,e),onRename:e=>le(I.name,e),onDelete:()=>pe(I.name,ct(j,I.name).length),onRebuildLinks:()=>fe(I.name)},I.name),M.length===0&&!L&&o(`p`,{className:`text-xs text-foreground-subtle`,children:`No locations yet. Add Ingresso, Salone, Cucina…`}),o(Et,{rows:se,fleet:j,locations:M,busy:R,emptyMessage:L?`Loading…`:`Every top-level device has a room.`,onAssign:(e,t)=>{for(let n of e)_.mutate({deviceId:n,location:t})}})]})}export{jt as LocationsPage};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./browser-BHo8W_uH.js","./rolldown-runtime-Cyuzqnbw.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{t}from"./vite-preload-helper-kNaey6uv.js";import{K as n,Q as r,S as i,W as a,a as o,b as s,q as c,t as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Q as f,ct as p,ot as m}from"./player-overlays-Sm-ivm_8.js";import{$n as h,Ao as g,Bd as _,Cd as v,Dd as y,Ed as b,En as x,Hn as S,Iu as C,J as w,Jd as T,Kn as E,Mt as D,Oo as O,Tn as ee,Vn as te,if as k,ld as ne,rf as A,su as j,wu as M,xd as N,yd as P}from"./src-CmnrQw1X.js";import{t as re}from"./monitor-smartphone-5lHVpcLH.js";import{a as F,b as I,i as L,r as R,t as ie}from"./SessionsList-542JIoxX.js";import{Jn as ae,qn as oe}from"./client-B2uiK_6q.js";import{t as z}from"./useTranslation-Bc5yH9V9.js";import"./mount-BwPih3Va.js";import{R as B,i as V,n as H,r as U,t as W,tt as G}from"./index-BlUdDWLp.js";import{t as K}from"./AdminPage-C1SqQSAP.js";r();function q({value:n,size:r=192}){let[a,o]=c(null),[s,l]=c(null);if(d(()=>{let r=!1;return t(()=>import(`./browser-BHo8W_uH.js`).then(t=>e(t.default,1)).then(async e=>{if(r)return;let t=e.create;if(typeof t!=`function`){l(`qrcode.create() unavailable in installed version`);return}try{let e=t(n,{errorCorrectionLevel:`M`});r||o(e)}catch(e){r||l(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1]),import.meta.url).catch(()=>{r||l(`qrcode library not installed`)}),()=>{r=!0}},[n]),s)return u(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:r,height:r},children:`QR rendering unavailable — use the secret below.`});if(!a)return u(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:r,height:r},children:`Generating…`});let f=a.modules.size,p=r/f,m=[];for(let e=0;e<f;e++)for(let t=0;t<f;t++)a.modules.data[e*f+t]&&m.push(u(`rect`,{x:t*p,y:e*p,width:p,height:p,fill:`currentColor`},`${t}-${e}`));return i(`svg`,{width:r,height:r,viewBox:`0 0 ${r} ${r}`,className:`text-black`,children:[u(`rect`,{x:0,y:0,width:r,height:r,fill:`white`}),m]})}var se=`${oe}/connect`,J={public:0,mesh:1,lan:2,"lan-ipv6":3};function ce(e){switch(e.kind){case`public`:return e.interfaceKind===`vpn`?`mesh`:`public`;case`lan-ipv4`:return`lan`;case`lan-ipv6`:return`lan-ipv6`;case`custom`:return`public`;case`loopback`:case`app-link`:return null}}function Y(e){return ae(e)}function le(e){return e.startsWith(`https://`)}function ue(e){let t=e.flatMap(e=>{let t=ce(e),n=Y(e.baseUrl);return t===null||n===null?[]:[{endpoint:e,tier:t,origin:n}]}).toSorted((e,t)=>J[e.tier]-J[t.tier]||Number(t.endpoint.plausible)-Number(e.endpoint.plausible)||e.endpoint.priority-t.endpoint.priority),n=new Set;return t.flatMap(({endpoint:e,tier:t,origin:r})=>n.has(r)?[]:(n.add(r),[{origin:r,label:e.label,tier:t,secure:le(r),plausible:e.plausible}]))}function de(e,t,n=null){for(let r of[t,n]){if(r===null)continue;let t=Y(r),n=e.find(e=>e.origin===t);if(n!==void 0)return n}return e[0]??null}function fe(e){let t=new URL(se);return t.searchParams.set(`hub`,e),t.toString()}r();var pe=176,X={scheme:`https`};function me(){let{t:e}=z(),t=g(X),n=O(X).data?.roles.publicEndpoint.resolved??null;return i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[i(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[u(C,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`connectPhone.title`)})]}),i(`div`,{className:`p-4 space-y-3`,children:[u(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`connectPhone.description`)}),t.isPending?i(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[u(N,{className:`h-3.5 w-3.5 animate-spin`}),e(`connectPhone.loading`)]}):t.isError?i(`div`,{className:`flex items-start gap-2 text-[11px] text-danger`,children:[u(M,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),i(`div`,{className:`flex-1 min-w-0 space-y-1.5`,children:[u(`div`,{className:`break-words`,children:e(`connectPhone.error`,{message:t.error.message})}),u(S,{size:`sm`,variant:`ghost`,onClick:()=>void t.refetch(),children:e(`connectPhone.retry`)})]})]}):u(he,{candidates:ue(t.data.endpoints),preferredOrigin:n})]})]})}function he({candidates:e,preferredOrigin:t}){let{t:n}=z(),[r,o]=c(null),s=de(e,r,t),l=a(()=>s?fe(s.origin):null,[s]);if(s===null||l===null)return u(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`connectPhone.empty`)});let d=e=>n(`connectPhone.tier.${e}`),f=e.map(e=>({value:e.origin,label:`${d(e.tier)} — ${e.origin}`}));return i(`div`,{className:`flex flex-col sm:flex-row gap-4`,children:[u(ee,{value:l,size:pe,alt:n(`connectPhone.qrAlt`),className:`self-start`}),i(`div`,{className:`flex-1 min-w-0 space-y-3`,children:[i(`label`,{className:`block space-y-1`,children:[u(`span`,{className:`text-[11px] font-medium text-foreground`,children:n(`connectPhone.addressLabel`)}),u(te,{value:s.origin,options:f,onChange:e=>o(e.target.value)}),i(`span`,{className:`block text-[10px] text-foreground-subtle`,children:[d(s.tier),` · `,s.label]})]}),!s.secure&&u(Z,{text:n(`connectPhone.insecure`)}),!s.plausible&&u(Z,{text:n(`connectPhone.implausible`)}),i(`div`,{className:`space-y-1`,children:[u(`span`,{className:`text-[11px] font-medium text-foreground`,children:n(`connectPhone.linkLabel`)}),i(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[u(`code`,{className:`flex-1 min-w-0 font-mono text-[11px] text-foreground break-all select-all`,children:l}),u(D,{value:l,srLabel:n(`connectPhone.linkLabel`)})]})]}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`connectPhone.signInHint`)})]})]})}function Z({text:e}){return i(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[u(M,{className:`h-3.5 w-3.5 text-warning mt-0.5 shrink-0`}),u(`span`,{children:e})]})}r();function ge(e){return new Date(e).toLocaleDateString()}function _e(){let e=h(),t=j.useUtils(),r=j.auth.listLinkableProviders.useQuery(),a=j.auth.listOwnExternalIdentities.useQuery(),[o,s]=c(null),[l,p]=c(()=>V(window.location.search)),m=n(null),g=L(`Linking a sign-in account`),_=n(null);d(()=>()=>_.current?.(),[]);let[y,b]=c(null);d(()=>{if(l===null)return;let e=new URL(window.location.href);e.searchParams.delete(`linked`),e.searchParams.delete(`linkError`),window.history.replaceState({},``,e.pathname+e.search+e.hash)},[l]);let x=j.auth.beginExternalLink.useMutation({onSuccess:({url:e})=>{let n=m.current;if(m.current=null,n===null||n.closed){window.location.assign(e);return}let r=e=>{b(null),p(V(`?${e}`)),t.auth.listOwnExternalIdentities.invalidate()};_.current?.(),_.current=H(n,{onReturn:e=>{e.target===`profile`&&r(e.query)},onDone:e=>{e.target===`profile`&&r(e.query)},onClosed:()=>{_.current?.(),_.current=null,t.auth.listOwnExternalIdentities.invalidate()}}),n.location.href=f(U(e))},onError:e=>{m.current?.close(),m.current=null,b(null),s(e.message)}}),S=j.auth.unlinkOwnExternalIdentity.useMutation({onSuccess:()=>void t.auth.listOwnExternalIdentities.invalidate(),onError:e=>s(e.message)}),C=r.data??[],w=a.data??[],T=y!==null&&w.some(e=>e.provider===y);if(d(()=>{!T||y===null||(b(null),p({kind:`linked`,provider:y}))},[T,y]),C.length===0&&w.length===0)return null;let E=new Set(w.map(e=>e.provider)),D=e=>C.find(t=>t.provider===e)?.label??e,O=async(t,n)=>{await e({title:`Unlink sign-in account`,message:`Stop signing in with this ${n} account?`,confirmLabel:`Unlink`,variant:`danger`})&&(s(null),S.mutate({provider:t.provider,subject:t.subject}))};return i(`div`,{"data-testid":`linked-sign-ins`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[g.dialog,i(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[u(v,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`div`,{className:`text-xs font-semibold text-foreground`,children:`Linked sign-in accounts`})]}),i(`div`,{className:`p-4 space-y-3`,children:[u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Sign in with an external account instead of your password. Only accounts you link here can sign you in; your two-factor authentication still applies.`}),l?.kind===`linked`&&i(`div`,{className:`flex items-center gap-2 rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2 text-xs text-foreground`,children:[u(A,{className:`h-3.5 w-3.5 text-emerald-500 shrink-0`}),`Linked your `,D(l.provider),` account.`]}),(l?.kind===`error`||o)&&i(`div`,{className:`flex items-center gap-2 rounded-md border border-danger/20 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[u(k,{className:`h-3.5 w-3.5 shrink-0`}),o??(l?.kind===`error`?l.message:``)]}),w.length>0&&u(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:w.map(e=>{let t=e.providerLabel??e.provider;return i(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[i(`div`,{className:`flex-1 min-w-0`,children:[i(`div`,{className:`font-medium text-foreground truncate`,children:[t,!e.available&&u(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:`provider unavailable`})]}),i(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:[e.label??e.subject,` · linked `,ge(e.linkedAt)]})]}),i(`button`,{onClick:()=>void O(e,t),disabled:S.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[u(I,{className:`h-3 w-3`}),`Unlink`]})]},`${e.provider}|${e.subject}`)})}),u(`div`,{className:`flex flex-wrap gap-2`,children:C.filter(e=>!E.has(e.provider)).map(e=>i(`button`,{onClick:()=>{s(null),p(null),g.requestProof().then(t=>{t!==null&&(m.current=W(null),b(m.current===null?null:e.provider),x.mutate({provider:e.provider,reauthToken:t}))})},disabled:x.isPending,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[x.isPending&&x.variables?.provider===e.provider?u(N,{className:`h-3 w-3 animate-spin`}):u(v,{className:`h-3 w-3`}),`Link `,e.label]},e.provider))})]})]})}r();function Q(e){return e.message.length>0?e.message:`Request failed`}function ve(){let{logout:e}=B(),t=h(),n=j.useUtils(),r=j.auth.listOwnSessions.useQuery(),[a,o]=c(null),s=j.auth.revokeOwnSession.useMutation({onSuccess:()=>void n.auth.listOwnSessions.invalidate(),onError:e=>o(`Sign out failed: ${Q(e)}`)}),l=j.auth.logout.useMutation({onSuccess:()=>e(),onError:e=>o(`Sign out failed: ${Q(e)}`)}),d=async e=>{await t({title:`Sign out this session`,message:`${F(e.client).label} will have to sign in again.`,confirmLabel:`Sign out`,variant:`danger`})&&(o(null),s.mutate({id:e.id}))},f=async()=>{await t({title:`Sign out everywhere`,message:`Every session of your account ends, this browser included: you will be signed out here too and every device has to sign in again.`,confirmLabel:`Sign out everywhere`,variant:`danger`})&&(o(null),l.mutate({everywhere:!0}))};return i(`div`,{"data-testid":`my-sessions`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[i(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[u(re,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`div`,{className:`text-xs font-semibold text-foreground`,children:`Active sessions`})]}),i(`div`,{className:`p-4 space-y-3`,children:[u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`The browsers and apps signed in to your account. Signing one out ends it at once.`}),a!==null&&u(`div`,{className:`text-[11px] text-danger`,children:a}),u(ie,{sessions:r.data??[],isLoading:r.isLoading,loadError:r.isError?r.error?.message??`Request failed`:null,emptyText:`No active sessions.`,onRevoke:e=>void d(e),revokingId:s.isPending?s.variables?.id??null:null}),u(`div`,{className:`flex justify-end`,children:i(`button`,{onClick:()=>void f(),disabled:l.isPending,className:`inline-flex items-center gap-1.5 rounded border border-danger/40 px-2.5 py-1 text-[11px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,children:[l.isPending?u(N,{className:`h-3 w-3 animate-spin`}):u(G,{className:`h-3 w-3`}),`Sign out everywhere`]})})]})]})}r();var ye={view:{icon:_,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:ne,cls:`bg-primary/15 text-primary`},delete:{icon:p,cls:`bg-danger/15 text-danger`}};function be(){let{user:e,logout:t}=B();if(!e)return u(K,{children:u(`div`,{className:`text-xs text-foreground-subtle`,children:`Not signed in.`})});let n=e.isAdmin,r=e.scopes??[];return i(K,{children:[i(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[u(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-primary font-semibold text-base`,children:e.username.slice(0,1).toUpperCase()}),i(`div`,{className:`flex-1 min-w-0`,children:[u(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:e.username}),i(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n?`Administrator`:`User`,` · session id`,` `,i(`span`,{className:`font-mono`,children:[e.id.slice(0,8),`…`]})]})]})]}),n&&i(`div`,{className:`rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5`,children:[u(y,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),i(`div`,{children:[u(`div`,{className:`font-semibold text-foreground`,children:`Unrestricted access`}),u(`p`,{className:`text-foreground-subtle mt-0.5`,children:`Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below.`})]})]}),u(xe,{}),u(Se,{username:e.username}),u(Ce,{}),u(_e,{}),u(R,{}),u(ve,{}),u(me,{}),r.length>0&&i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[i(`div`,{className:`px-4 py-2 border-b border-border`,children:[u(`div`,{className:`text-xs font-semibold text-foreground`,children:`Granted scopes`}),u(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Baked into your session token at login; sign out + back in to refresh after changes.`})]}),i(`div`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[u(`div`,{children:`Type`}),u(`div`,{children:`Target`}),u(`div`,{children:`Access`})]}),u(`ul`,{className:`divide-y divide-border`,children:r.map((e,t)=>i(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[u(`span`,{className:`font-mono text-foreground-subtle`,children:e.type}),u(`span`,{className:`font-mono text-foreground`,children:e.type===`device`?w(e.selector):e.target}),u(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(t=>{let n=e.access.includes(t),{icon:r,cls:a}=ye[t];return i(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${n?a:`bg-transparent text-foreground-subtle/40 line-through`}`,title:n?`Can ${t}`:`Cannot ${t}`,children:[u(r,{className:`h-3 w-3`}),t]},t)})})]},t))})]}),u(`div`,{className:`flex justify-end`,children:i(`button`,{onClick:t,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground transition-colors`,children:[u(G,{className:`h-3 w-3`}),`Sign out`]})})]})}function xe(){let e=m(),[t,n]=c(``),[r,a]=c(``),[o,s]=c(``),[d,f]=c(null),p=l({mutationFn:t=>e.changeOwnPassword(t),onSuccess:()=>{f({kind:`success`,msg:`Password updated.`}),n(``),a(``),s(``)},onError:e=>{f({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),h=r.length>0&&o.length>0&&r!==o,g=r.length>0&&r.length<8,_=t.length>=1&&r.length>=8&&r===o;return i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[i(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[u(b,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`div`,{className:`text-xs font-semibold text-foreground`,children:`Change password`})]}),i(`div`,{className:`p-4 space-y-3`,children:[u($,{label:`Current password`,value:t,onChange:n,autoComplete:`current-password`}),u($,{label:`New password`,value:r,onChange:a,autoComplete:`new-password`,hint:`At least 8 characters.`}),u($,{label:`Confirm new password`,value:o,onChange:s,autoComplete:`new-password`}),(h||g)&&u(`div`,{className:`text-[11px] text-danger`,children:h?`Passwords do not match.`:`New password must be at least 8 characters.`}),d&&i(`div`,{className:`text-[11px] flex items-center gap-1 ${d.kind===`success`?`text-emerald-500`:`text-danger`}`,children:[d.kind===`success`?u(A,{className:`h-3 w-3`}):u(k,{className:`h-3 w-3`}),d.msg]}),u(`div`,{className:`flex justify-end`,children:i(`button`,{onClick:()=>{f(null),p.mutate({currentPassword:t,newPassword:r})},disabled:!_||p.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[p.isPending?u(N,{className:`h-3 w-3 animate-spin`}):u(P,{className:`h-3 w-3`}),`Update password`]})})]})]})}function $({label:e,value:t,onChange:n,autoComplete:r,hint:a}){return i(`div`,{className:`space-y-1`,children:[u(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),u(`input`,{type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:r,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),a&&u(`div`,{className:`text-[10px] text-foreground-subtle`,children:a})]})}function Se({username:e}){let t=m(),n=o({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>t.getOwnTotpStatus()}),r=n.data,[f,p]=c(null),[h,g]=c(``),[_,v]=c(null),[y,b]=c(!1),x=l({mutationFn:()=>t.setupOwnTotp(),onSuccess:e=>{p({secret:e.secret,otpauthUrl:e.otpauthUrl}),g(``),v(null)},onError:e=>v(e instanceof Error?e.message:`Setup failed`)}),S=l({mutationFn:e=>t.confirmOwnTotp(e),onSuccess:()=>{p(null),g(``),v(null),n.refetch()},onError:e=>v(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),w=L(`Turning off two-factor authentication`),E=l({mutationFn:async()=>{let e=await w.requestProof();return e===null?null:t.disableOwnTotp({reauthToken:e})},onSuccess:()=>{v(null),n.refetch()},onError:e=>v(e instanceof Error?e.message:`Disable failed`)});d(()=>{if(!y)return;let e=setTimeout(()=>b(!1),1500);return()=>clearTimeout(e)},[y]);let D=a(()=>n.isLoading?`loading`:f?`setup_in_progress`:r?.enabled?`enrolled`:`not_enrolled`,[n.isLoading,r?.enabled,f]);return i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[w.dialog,i(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[u(C,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`div`,{className:`text-xs font-semibold text-foreground`,children:`Two-factor authentication`})]}),i(`div`,{className:`p-4 space-y-3`,children:[D===`loading`&&i(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[u(N,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),D===`not_enrolled`&&i(s,{children:[u(`div`,{className:`text-xs text-foreground-subtle`,children:`2FA isn't active on your account. Enable it to require a 6-digit code from your authenticator app at every login.`}),u(`div`,{className:`flex justify-end`,children:i(`button`,{onClick:()=>{v(null),x.mutate()},disabled:x.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[x.isPending?u(N,{className:`h-3 w-3 animate-spin`}):u(C,{className:`h-3 w-3`}),`Enable 2FA`]})})]}),D===`setup_in_progress`&&f&&i(s,{children:[i(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`Scan the QR code (or enter the secret manually) into your authenticator app for`,` `,u(`span`,{className:`font-mono`,children:e}),`, then enter the 6-digit code below to confirm.`]}),i(`div`,{className:`flex flex-col items-center gap-3`,children:[u(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:u(q,{value:f.otpauthUrl,size:180})}),i(`div`,{className:`w-full`,children:[u(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:`Secret (manual entry)`}),i(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[u(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:f.secret}),i(`button`,{onClick:()=>{f&&navigator.clipboard.writeText(f.secret).then(()=>b(!0))},className:`inline-flex items-center gap-1 text-[10px] text-foreground-subtle hover:text-foreground`,children:[y?u(A,{className:`h-3 w-3 text-emerald-500`}):u(T,{className:`h-3 w-3`}),y?`Copied`:`Copy`]})]})]})]}),i(`div`,{className:`space-y-1`,children:[u(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),u(`input`,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:h,onChange:e=>g(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary`})]}),_&&i(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[u(k,{className:`h-3 w-3`}),_]}),i(`div`,{className:`flex justify-end gap-2`,children:[u(`button`,{onClick:()=>{p(null),v(null),g(``)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),i(`button`,{onClick:()=>{v(null),S.mutate({code:h})},disabled:S.isPending||h.length!==6,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[S.isPending?u(N,{className:`h-3 w-3 animate-spin`}):u(A,{className:`h-3 w-3`}),`Confirm`]})]})]}),D===`enrolled`&&r&&i(s,{children:[i(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[u(A,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),i(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[u(`div`,{className:`font-medium`,children:`2FA is active`}),i(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,r.confirmedAt?new Date(r.confirmedAt).toLocaleString():`—`]})]})]}),_&&i(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[u(k,{className:`h-3 w-3`}),_]}),u(`div`,{className:`flex justify-end`,children:i(`button`,{onClick:()=>{v(null),E.mutate()},disabled:E.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[E.isPending?u(N,{className:`h-3 w-3 animate-spin`}):u(C,{className:`h-3 w-3`}),`Disable 2FA`]})})]})]})]})}function Ce(){return E(`auth-webauthn/passkey-enrollment`)?u(x,{widgetId:`auth-webauthn/passkey-enrollment`,host:`dashboard`}):null}export{be as MyAccessPage};
|