@camstack/addon-admin-ui 1.2.86 → 1.2.88
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/{AddLocationWizard-CVvsaNYx.js → AddLocationWizard-BntkKU2V.js} +1 -1
- package/dist/assets/{AddonCollectionPage-JA8tzL7q.js → AddonCollectionPage-DfZQjIPJ.js} +1 -1
- package/dist/assets/Addons-Cof7W-Ym.js +1 -0
- package/dist/assets/{AdminTabs-B-UL_iuP.js → AdminTabs-FswV6m19.js} +1 -1
- package/dist/assets/{AiProfiles-DI31JvyZ.js → AiProfiles-Bol2xzPZ.js} +1 -1
- package/dist/assets/{BrokerForm-CFTyH54D.js → BrokerForm-rlgpgB9M.js} +1 -1
- package/dist/assets/{Build-BP0Mx9FT.js → Build--P11mU0s.js} +3 -3
- package/dist/assets/{Capabilities-BvxWbN6u.js → Capabilities-Di_wIznW.js} +1 -1
- package/dist/assets/CapabilityBadges-BOwdQNDH.js +1 -0
- package/dist/assets/{Cluster-CsEHMgVp.js → Cluster-B58mM4Kr.js} +1 -1
- package/dist/assets/{Data-Bt2o6J7H.js → Data-uwnl2ZR0.js} +1 -1
- package/dist/assets/{DetectionIntelligence-CeunXPtW.js → DetectionIntelligence-wpF45dZl.js} +1 -1
- package/dist/assets/{DeviceAggregateSection-DLNzCtMs.js → DeviceAggregateSection-r5_ljoI1.js} +1 -1
- package/dist/assets/DeviceDetail-Bf3FJFNv.js +2 -0
- package/dist/assets/{Devices-fMM-N9UK.js → Devices-D3k50BRl.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-D8LRITOt.js → EmbedPlayerPage-C2EWx5XY.js} +1 -1
- package/dist/assets/Events-DuXVjBmB.js +1 -0
- package/dist/assets/{FormBuilder-ChyOUw_O.js → FormBuilder-QY4tah4S.js} +1 -1
- package/dist/assets/{Identity-kjnupMGz.js → Identity-BV8WXb2H.js} +1 -1
- package/dist/assets/{IntegrationDetail-683FxnPV.js → IntegrationDetail-ClwD7H7W.js} +1 -1
- package/dist/assets/{Integrations-BAa7Hx8I.js → Integrations-BGbVMFT4.js} +1 -1
- package/dist/assets/{Integrations-Bvz5KiZt.js → Integrations-Dy_WWWKK.js} +1 -1
- package/dist/assets/{Logs-CPMTc4WW.js → Logs-Dr2j0QZR.js} +1 -1
- package/dist/assets/{MotionZonesSettings-DhO5kuER.js → MotionZonesSettings-Ds8nYWoN.js} +1 -1
- package/dist/assets/{MyAccess-C5kfikXk.js → MyAccess-Bsf24wbg.js} +1 -1
- package/dist/assets/Network-D_OMCOsR.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-BdP5wGIu.js → NodeAddonsSettingsPanel-B3-jgI6Y.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-CubcmlvI.js → NodeInferenceDevices-vixWXUkV.js} +1 -1
- package/dist/assets/Notifications-DbYpUqwt.js +1 -0
- package/dist/assets/Pipeline-m823fIKM.js +1 -0
- package/dist/assets/{Plates-DiVTWUKg.js → Plates-BIkYeFJp.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-zKU6VZ4G.js → PrivacyMaskSettings-C2nmPqsf.js} +1 -1
- package/dist/assets/{ProviderIcon-JxmOoO_O.js → ProviderIcon-yuhuUjyO.js} +1 -1
- package/dist/assets/Recordings-ChPRJj_w.js +1 -0
- package/dist/assets/{ScanNetworkModal-DkqUu2Xc.js → ScanNetworkModal-B6Dhtqhv.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-DZucoVrl.js → SceneMonitorEditor-CpU_-6iK.js} +1 -1
- package/dist/assets/{Scenes-DMSYbhd1.js → Scenes-Bp-HU3HC.js} +1 -1
- package/dist/assets/{Settings-olnTIAze.js → Settings-CxNCTStH.js} +1 -1
- package/dist/assets/{Showroom-CdPGD4R4.js → Showroom-BfQj_ruk.js} +1 -1
- package/dist/assets/{Terminal-Ck0I64eZ.js → Terminal-COkGK9Eu.js} +5 -3
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BpY1fOVD.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CtfWG-B0.js} +1 -1
- package/dist/assets/{bell-ring-BgQsFN7F.js → bell-ring-BIkgL1EI.js} +1 -1
- package/dist/assets/{boxes-BnOBLNz5.js → boxes-EqdcdFpg.js} +1 -1
- package/dist/assets/{build-cluster-graph-BwHdP82z.js → build-cluster-graph-C0MeCzJZ.js} +1 -1
- package/dist/assets/circle-check-big-DGl1OsLR.js +1 -0
- package/dist/assets/{circle-x-DAqnOyA6.js → circle-x-CBZPec7u.js} +1 -1
- package/dist/assets/clock-M4NiOyl_.js +1 -0
- package/dist/assets/{copy-Dl5E5of_.js → copy-BPgY4Eey.js} +1 -1
- package/dist/assets/{debounced-invalidate-BIRVvqvY.js → debounced-invalidate-B1bc5kFD.js} +1 -1
- package/dist/assets/{dist-CUfLXJC3.js → dist-DjbCvztb.js} +1 -1
- package/dist/assets/dist-IEXliP3K.js +349 -0
- package/dist/assets/{download-AfoMEWCf.js → download-Dq2bfdRX.js} +1 -1
- package/dist/assets/{face-bbox-BFT7iMc1.js → face-bbox-DUGyLE43.js} +1 -1
- package/dist/assets/{hard-drive-C9zTEogy.js → hard-drive-COdkuHqf.js} +1 -1
- package/dist/assets/{hostInit-Cw_l9Xfz.js → hostInit-BSakAGif.js} +1 -1
- package/dist/assets/index-LPwis6Rq.js +4 -0
- package/dist/assets/{key-round-sF-8oSo7.js → key-round-CfAFZkMw.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-8f39d7c2.js → mf-entry-bootstrap-0-e9ffa7b9.js} +2 -2
- package/dist/assets/{pencil-DsWgW1cM.js → pencil-CfoKCBNv.js} +1 -1
- package/dist/assets/play-CqrjGyv7.js +1 -0
- package/dist/assets/{player-overlays-BGbLKvcn.js → player-overlays-CBKaIBph.js} +1 -1
- package/dist/assets/plus-DHRgxEWi.js +1 -0
- package/dist/assets/power-DGhEdOiQ.js +1 -0
- package/dist/assets/{radio-CWn4dw9L.js → radio-BOUTlTbE.js} +1 -1
- package/dist/assets/{refresh-cw-Cly4MRhi.js → refresh-cw-CllqntzE.js} +1 -1
- package/dist/assets/remoteEntry-BsYVmvk8.js +1 -0
- package/dist/assets/rotate-ccw-CdTrnBTI.js +1 -0
- package/dist/assets/rotate-cw-Dre2EA6E.js +1 -0
- package/dist/assets/search-Dx_k5G37.js +1 -0
- package/dist/assets/{send-yaKZ1tHd.js → send-DcXtHjaz.js} +1 -1
- package/dist/assets/{server-CLOtA1S4.js → server-DbU7BgZv.js} +1 -1
- package/dist/assets/shield-BojVNBVL.js +1 -0
- package/dist/assets/square-DynbJcCj.js +1 -0
- package/dist/assets/{square-check-big-DsiPGDCA.js → square-check-big-Ch-X3CcM.js} +1 -1
- package/dist/assets/src-0pbBUmTo.js +349 -0
- package/dist/assets/src-BLHY9yig.js +67 -0
- package/dist/assets/{star-fUCw1hyi.js → star-BotqSaGv.js} +1 -1
- package/dist/assets/{undo-2-DXcExZt9.js → undo-2-CXIWJrgH.js} +1 -1
- package/dist/assets/{upload-CLT-rIe6.js → upload-CafOTsXz.js} +1 -1
- package/dist/assets/{use-scenes-feed-CvesyXw2.js → use-scenes-feed-DTuzztEP.js} +1 -1
- package/dist/assets/useEventInvalidation-BDOhX3vo.js +1 -0
- package/dist/assets/{video-CFtTGKiz.js → video-GQHe9bLG.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BwIIU_83.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-7s6IgvIP.js} +2 -2
- package/dist/assets/{wifi-Glpx3AkR.js → wifi-MOwlhPpo.js} +1 -1
- package/dist/assets/{zap-aTn3GS-l.js → zap-BiojyRpM.js} +1 -1
- package/dist/index.html +5 -5
- package/dist/server/addon.js +135 -7
- package/package.json +1 -1
- package/dist/assets/Addons-BOYMP0uf.js +0 -1
- package/dist/assets/CapabilityBadges-DjOvNnpp.js +0 -1
- package/dist/assets/DeviceDetail-DCh8ydpY.js +0 -2
- package/dist/assets/Events-Drj6ybP0.js +0 -1
- package/dist/assets/Network-DBtVDYGt.js +0 -1
- package/dist/assets/Notifications-DBH3QGle.js +0 -1
- package/dist/assets/Pipeline-DgZbCwcO.js +0 -1
- package/dist/assets/Recordings-DTGdM6Ip.js +0 -1
- package/dist/assets/circle-check-big-FvfSWrhR.js +0 -1
- package/dist/assets/clock-BpmU9WHJ.js +0 -1
- package/dist/assets/dist-C2l22cSJ.js +0 -349
- package/dist/assets/index-vZPXzSPK.js +0 -4
- package/dist/assets/play-BkPr3HPj.js +0 -1
- package/dist/assets/plus-zSkh3oEn.js +0 -1
- package/dist/assets/power-C4yi0usE.js +0 -1
- package/dist/assets/remoteEntry-BwhR6qpk.js +0 -1
- package/dist/assets/rotate-ccw-D0bM0VXI.js +0 -1
- package/dist/assets/rotate-cw-CNTEn7nJ.js +0 -1
- package/dist/assets/search-Bq3ZLayo.js +0 -1
- package/dist/assets/square-BlSn3fsr.js +0 -1
- package/dist/assets/src-Buv5KpAz.js +0 -67
- package/dist/assets/src-CQVcBp6b.js +0 -349
- package/dist/assets/useEventInvalidation-B-Cb5-ry.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{$n as l,Bo as u,Dn as d,En as f,Jn as p,Ko as m,Mn as h,Qn as g,Ro as _,Xn as v,Yn as y,Zn as b,er as x,ln as S,nr as C,rr as w,tr as T,zo as E}from"./src-Buv5KpAz.js";import{t as D}from"./download-AfoMEWCf.js";import{t as O}from"./hard-drive-C9zTEogy.js";import{t as k}from"./pencil-DsWgW1cM.js";import{t as A}from"./play-BkPr3HPj.js";import{t as j}from"./plus-zSkh3oEn.js";import{t as M}from"./rotate-cw-CNTEn7nJ.js";import{C as N,I as P,K as F,R as I,W as ee,i as L,m as R,s as z}from"./index-vZPXzSPK.js";import{t as B}from"./AdminPage-CCD07UMs.js";import{r as te}from"./authed-media-BPd_L9jr.js";import{t as ne}from"./AdminTabs-B-UL_iuP.js";import{t as V}from"./format-size-CO9d3C3-.js";import{i as H,n as re,r as ie,t as ae}from"./AddLocationWizard-CVvsaNYx.js";import{t as U}from"./AddonCollectionPage-JA8tzL7q.js";import{t as W}from"./addon-display-names-DvSEQty-.js";var G=F(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),K=F(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),q=F(`calendar-clock`,[[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M17.5 17.5 16 16.3V14`,key:`akvzfd`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]),J=F(`file-text`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]);t();function oe(){let e=a(),t=S(),{data:i,isLoading:c,isError:l}=u({}),d=E(),f=r(()=>d.data??[],[d.data]),[p,h]=o(null),[g,v]=o(null),y=_({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),b=m({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),x=e=>{e.isDefault||b.mutate(H(e,{isDefault:!0}))},C=(e,t)=>{b.mutate(H(e,{enabled:t}))},w=async e=>{if(e.isDefault){await t({title:`Cannot delete default location`,message:`"${e.displayName}" is the default for type "${e.type}". Mark another location as default first, then delete this one.`,confirmLabel:`OK`,variant:`warning`});return}await t({title:`Delete location "${e.displayName}"?`,message:`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`,confirmLabel:`Delete`,variant:`danger`})&&y.mutate({id:e.id})},T=r(()=>{let e=new Map;for(let t of i??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[i]),D=c||d.isLoading,O=l||d.isError;return n(B,{children:[D&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),O&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!D&&!O&&n(`div`,{className:`space-y-3`,children:[f.length===0&&s(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:`No storage locations declared by any installed addon.`}),f.map(e=>s(ie,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:T.get(e.id)??[],onAdd:e=>h(e),onEdit:e=>v(e),onDelete:e=>{w(e)},onSetDefault:e=>x(e),onToggleEnabled:(e,t)=>C(e,t)},e.id))]}),p!==null&&s(ae,{initialType:p,onClose:()=>h(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),h(null)}}),g!==null&&s(re,{location:g,onClose:()=>v(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),v(null)}})]})}t();var se=[[`backup`,`listDestinations`]],ce=[`backup`,`listArchives`];function le({destinationId:t,restoreSupported:i,onOpenRestoreWizard:c}){let l=a(),u=S(),{data:d,isLoading:f,isError:m}=b({destinationId:t}),h=d??[],g=p({onSuccess:()=>{l.invalidateQueries({queryKey:[[...ce]]}),l.invalidateQueries({queryKey:se})}}),_=e(async e=>{await u({title:`Delete this archive?`,message:`Permanently deletes "${e.label??e.id}" and frees ${V(e.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&g.mutate({destinationId:t,backupId:e.id})},[u,t,g]),[v,y]=o(null),x=e(async e=>{y(e.id);try{let n=await te(ue(t,e.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.label??e.id}.tar.gz`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{y(null)}},[t]),C=r(()=>[...h].toSorted((e,t)=>t.createdAt-e.createdAt),[h]);return f?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):m?s(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):C.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):s(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),s(`tbody`,{children:C.map(e=>n(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:Y(e.createdAt)}),s(`td`,{className:`px-3 py-1.5 text-foreground`,children:e.label??s(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),s(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:e.locations.join(`, `)}),s(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:V(e.sizeBytes)}),s(`td`,{className:`px-3 py-1.5`,children:n(`div`,{className:`flex items-center justify-end gap-1`,children:[n(`button`,{onClick:()=>{x(e)},disabled:v===e.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 disabled:opacity-50`,title:`Download archive`,children:[v===e.id?s(N,{className:`h-3 w-3 animate-spin`}):s(D,{className:`h-3 w-3`}),`Download`]}),i&&c&&n(`button`,{onClick:()=>c({destinationId:t,archiveId:e.id}),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-primary hover:bg-primary/10`,title:`Restore from this archive`,children:[s(M,{className:`h-3 w-3`}),`Restore`]}),s(`button`,{onClick:()=>{_(e)},disabled:g.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete archive`,children:g.isPending?s(N,{className:`h-3 w-3 animate-spin`}):s(z,{className:`h-3 w-3`})})]})})]},e.id))})]})})}function ue(e,t){return`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function Y(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}t();var X=[[`backup`,`listSchedules`]];function de({onEdit:e,onOpenRestoreWizard:t}){let{data:i,isLoading:a,isError:c}=l(),u=i??[],d=g().data??[],f=r(()=>{let e=new Map;for(let t of d)e.set(t.id,t);return e},[d]),[p,m]=o(null),h=e=>{m(t=>t===e?null:e)};return a?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading backup entries…`}):c?s(`div`,{className:`text-xs text-danger`,children:`Failed to load backup entries`}):u.length===0?s(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:s(`p`,{className:`text-xs text-foreground-subtle`,children:`No backup entries yet. Create one to schedule backups across one or more storage locations.`})}):s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[820px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[s(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),s(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Entry`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),s(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Locations`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-24`,children:`Retention`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-48`,children:`Schedule`}),s(`th`,{className:`text-right px-3 py-2 font-medium w-52`,children:`Actions`})]})}),s(`tbody`,{children:u.map(n=>s(fe,{row:n,destById:f,isOpen:p===n.id,onToggle:()=>h(n.id),onEdit:()=>e(n),...t?{onOpenRestoreWizard:t}:{}},n.id))})]})})}function fe({row:t,destById:l,isOpen:u,onToggle:d,onEdit:f,onOpenRestoreWizard:p}){let m=a(),h=S(),g=w({onSuccess:()=>{m.invalidateQueries({queryKey:X})}}),_=y({onSuccess:()=>{m.invalidateQueries({queryKey:X})}}),v=C({onSuccess:()=>{m.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),m.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]})}}),[b,x]=o(String(t.retentionCount));c(()=>{x(String(t.retentionCount))},[t.retentionCount]);let T=r(()=>({id:t.id,label:t.label,cron:t.cron,locationIds:[...t.locationIds],retentionCount:t.retentionCount,...t.dataSources?{dataSources:[...t.dataSources]}:{}}),[t]),E=e(e=>{g.mutate({...T,enabled:e})},[g,T]),D=e(()=>{let e=Number.parseInt(b,10);if(Number.isNaN(e)||e<1){x(String(t.retentionCount));return}e!==t.retentionCount&&g.mutate({...T,enabled:t.enabled,retentionCount:e})},[g,T,b,t.retentionCount,t.enabled]),O=e(()=>{t.locationIds.length!==0&&v.mutate({destinations:[...t.locationIds],...t.dataSources&&t.dataSources.length>0?{locations:[...t.dataSources]}:{},label:t.label,retentionCount:t.retentionCount})},[v,t]),j=e(async()=>{await h({title:`Delete backup entry?`,message:`"${t.label||t.id}" will stop running. Existing archives are kept.`,confirmLabel:`Delete`,variant:`warning`})&&_.mutate({id:t.id})},[h,_,t.id,t.label]),M=t.cron.trim().length>0,F=g.isPending||_.isPending;return n(i,{children:[n(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[s(`td`,{className:`px-2 py-2`,children:s(`button`,{onClick:d,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:u?`Hide archives`:`Show archives`,children:s(u?I:P,{className:`h-3.5 w-3.5`})})}),s(`td`,{className:`px-3 py-2`,children:n(`button`,{onClick:f,className:`text-left hover:underline focus:outline-none`,children:[s(`div`,{className:`text-foreground font-medium`,children:t.label||`(unnamed)`}),t.lastRunAt!==void 0&&n(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:[`last run `,new Date(t.lastRunAt).toLocaleString()]})]})}),s(`td`,{className:`px-3 py-2`,children:s(`label`,{className:`inline-flex items-center cursor-pointer`,children:s(`input`,{type:`checkbox`,className:`accent-primary`,checked:t.enabled,disabled:F,onChange:e=>E(e.target.checked)})})}),s(`td`,{className:`px-3 py-2`,children:n(`div`,{className:`flex flex-wrap gap-1`,children:[t.locationIds.length===0&&s(`span`,{className:`text-[11px] text-danger italic`,children:`No locations`}),t.locationIds.map(e=>s(`span`,{className:`inline-flex items-center rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-foreground`,title:e,children:l.get(e)?.displayName??e},e))]})}),s(`td`,{className:`px-3 py-2`,children:s(`input`,{type:`number`,min:1,max:1e3,value:b,disabled:F,onChange:e=>x(e.target.value),onBlur:D,onKeyDown:e=>{e.key===`Enter`&&e.target.blur(),e.key===`Escape`&&x(String(t.retentionCount))},className:`w-16 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})}),s(`td`,{className:`px-3 py-2`,children:n(`button`,{onClick:f,className:`group flex flex-col items-start gap-0.5 text-left`,title:`Edit schedule`,children:[n(`span`,{className:`inline-flex items-center gap-1`,children:[s(q,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),s(`span`,{className:`font-mono text-[11px] text-foreground`,children:M?t.cron:`Manual`})]}),M&&t.nextRunAt!==void 0&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`next `,new Date(t.nextRunAt).toLocaleString()]})]})}),s(`td`,{className:`px-3 py-2`,children:n(`div`,{className:`flex items-center justify-end gap-1.5`,children:[n(`button`,{onClick:O,disabled:v.isPending||t.locationIds.length===0,className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,title:`Run this entry now`,children:[v.isPending?s(N,{className:`h-3 w-3 animate-spin`}):s(A,{className:`h-3 w-3`}),`Run now`]}),s(`button`,{onClick:f,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-foreground hover:bg-primary/5`,title:`Edit entry`,children:s(k,{className:`h-3 w-3`})}),s(`button`,{onClick:()=>{j()},disabled:F,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-danger hover:border-danger/40 disabled:opacity-50`,title:`Delete entry`,children:s(z,{className:`h-3 w-3`})})]})})]}),u&&s(`tr`,{className:`border-t border-border bg-background/30`,children:n(`td`,{colSpan:7,className:`px-4 py-3 space-y-4`,children:[t.locationIds.length===0&&s(`p`,{className:`text-xs text-foreground-subtle italic`,children:`This entry has no locations selected.`}),t.locationIds.map(e=>n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:l.get(e)?.displayName??e}),s(le,{destinationId:e,restoreSupported:l.get(e)?.restoreSupported??!0,...p?{onOpenRestoreWizard:p}:{}})]},e))]})})]})}t();var Z=[{id:`manual`,label:`Manual only`,cron:``},{id:`hourly`,label:`Every hour`,cron:`0 * * * *`,description:`On the hour`},{id:`every-3h`,label:`Every 3 hours`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,label:`Every 6 hours`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,label:`Daily at 03:00`,cron:`0 3 * * *`,description:`Every night at 3 AM`},{id:`weekly-sun`,label:`Weekly Sunday 03:00`,cron:`0 3 * * 0`,description:`Sunday morning at 3 AM`}];function pe(e){let t=e.trim();for(let e of Z)if(e.cron===t)return e.id;return`custom`}function me({value:e,onChange:t,previewCount:r=5,disabled:i=!1}){let a=pe(e),[l,u]=o(a===`custom`);c(()=>{a!==`custom`&&u(!1)},[a]);let d=_e(e,250),f=x({cron:d,count:r},{enabled:d.trim().length>0}),p=f.data??null,m=e=>{u(!1),t(e.cron)},h=l||a===`custom`;return n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),n(`div`,{className:`flex flex-wrap gap-1.5`,children:[Z.map(e=>s(`button`,{type:`button`,onClick:()=>m(e),disabled:i,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!l&&a===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.description??e.label,children:e.label},e.id)),s(`button`,{type:`button`,onClick:()=>{u(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:i,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(h?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),h&&n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),s(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:i,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),n(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,s(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),s(he,{cron:d,preview:p,loading:f.isFetching})]})}function he({cron:e,preview:t,loading:r}){return r&&t===null?n(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[s(N,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?s(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:`No future runs match this expression.`}):n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),s(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>n(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[s(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),s(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:ge(e)})]},`${e}-${t}`))})]}):s(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??`Invalid cron expression`})}function ge(e){let t=e-Date.now();if(t<=0)return`now`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function _e(e,t){let[n,i]=o(e),a=r(()=>e,[e]);return c(()=>{let e=setTimeout(()=>i(a),t);return()=>clearTimeout(e)},[a,t]),n}t();var ve=[[`backup`,`listSchedules`]];function ye({entry:e,onClose:t,onSaved:i}){let c=a(),l=g(),u=l.data??[],[d,f]=o(e?.label??``),[p,m]=o(e?.cron??`0 3 * * *`),[h,_]=o(e?.enabled??!0),[v,y]=o(String(e?.retentionCount??7)),[b,x]=o(new Set(e?.locationIds??[])),S=w({onSuccess:()=>{c.invalidateQueries({queryKey:ve}),i()}}),C=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},T=Number.parseInt(v,10),E=r(()=>d.trim().length>0&&b.size>0&&!Number.isNaN(T)&&T>=1&&T<=1e3,[d,b,T]),D=()=>{E&&S.mutate({...e?{id:e.id}:{},label:d.trim(),cron:p.trim(),enabled:h,locationIds:Array.from(b),retentionCount:T})},O=S.error instanceof Error?S.error.message:null;return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:n(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3 sticky top-0 bg-surface`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e?`Edit backup entry`:`New backup entry`}),s(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:s(L,{className:`h-4 w-4`})})]}),n(`div`,{className:`p-4 space-y-4`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Name`}),s(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`Nightly offsite`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),n(`div`,{className:`space-y-1.5`,children:[n(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:[`Locations (`,b.size,` selected)`]}),l.isLoading&&n(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[s(N,{className:`h-3.5 w-3.5 animate-spin`}),`Loading locations…`]}),!l.isLoading&&u.length===0&&s(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:"No `backups` storage locations configured. Add one in Settings → Storage first."}),u.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-52 overflow-y-auto`,children:u.map(e=>n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`checkbox`,checked:b.has(e.id),onChange:()=>C(e.id),className:`accent-primary`}),s(`span`,{className:`text-foreground`,children:e.displayName})]}),n(`div`,{className:`flex items-center gap-1.5`,children:[s(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-surface border border-border rounded px-1.5 py-0.5`,children:e.kind}),s(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]},e.id))})]}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Retention (archives kept)`}),s(`input`,{type:`number`,min:1,max:1e3,value:v,onChange:e=>y(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Enabled`}),n(`label`,{className:`inline-flex items-center gap-2 py-1.5 cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:h,onChange:e=>_(e.target.checked),className:`accent-primary`}),s(`span`,{className:`text-xs text-foreground-subtle`,children:`Run on schedule`})]})]})]}),n(`div`,{className:`space-y-1.5 border-t border-border pt-3`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Schedule`}),s(me,{value:p,onChange:m,disabled:S.isPending})]}),O&&s(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:O})]}),n(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3 sticky bottom-0 bg-surface`,children:[s(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),n(`button`,{onClick:D,disabled:!E||S.isPending,className:`inline-flex items-center gap-1.5 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&&s(N,{className:`h-3.5 w-3.5 animate-spin`}),e?`Save`:`Create entry`]})]})]})})}t();var be=[[`backup`,`list`]];function xe({initialDestinationId:e,initialArchiveId:t,onClose:i,onScheduled:l}){let u=a(),[d,f]=o(e&&t?2:1),[p,m]=o(e),[h,_]=o(t),[y,x]=o(new Set),{data:S}=g(),C=S??[],{data:w,isLoading:E}=b({destinationId:p??``},{enabled:!!p}),D=w??[];c(()=>{if(p!==void 0)return;let e=C.filter(e=>e.restoreSupported);e.length===1&&m(e[0].id)},[p,C]);let{data:O}=v({destinationId:p??``,backupId:h??``},{enabled:!!p&&!!h}),k=r(()=>O?.locations??[],[O]);c(()=>{k.length!==0&&x(e=>e.size===0?new Set(k):e)},[k]);let A=T({onSuccess:()=>{u.invalidateQueries({queryKey:be}),l(),i()}}),j=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},P=!!p&&!!h,F=y.size>0,I=P&&F&&!A.isPending,R=()=>{!p||!h||A.mutate({destinationId:p,backupId:h,locations:[...y]})};return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:i,children:n(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[n(`div`,{className:`space-y-0.5`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),n(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,d,` of 3 —`,` `,d===1?`pick source`:d===2?`pick locations`:`confirm`]})]}),s(`button`,{onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:s(L,{className:`h-4 w-4`})})]}),d===1&&s(Se,{destinations:C,destinationId:p,onPickDestination:e=>{m(e),_(void 0),x(new Set)},archives:D,archivesLoading:E,archiveId:h,onPickArchive:_}),d===2&&s(Ce,{locations:k,picked:y,onToggle:j}),d===3&&s(we,{destinationName:C.find(e=>e.id===p)?.displayName??p??``,archive:D.find(e=>e.id===h),picked:[...y]}),n(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[s(`div`,{children:d>1&&n(`button`,{onClick:()=>f(e=>e===3?2:1),className:`inline-flex items-center gap-1 rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:[s(ee,{className:`h-3 w-3`}),`Back`]})}),n(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),d<3?n(`button`,{disabled:d===1&&!P||d===2&&!F,onClick:()=>f(e=>e===1?2:3),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:[`Next`,s(K,{className:`h-3 w-3`})]}):n(`button`,{onClick:R,disabled:!I,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[A.isPending?s(N,{className:`h-3.5 w-3.5 animate-spin`}):s(M,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function Se({destinations:e,destinationId:t,onPickDestination:r,archives:i,archivesLoading:a,archiveId:o,onPickArchive:c}){let l=e.filter(e=>e.restoreSupported);return n(`div`,{className:`p-4 space-y-3`,children:[n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),n(`select`,{value:t??``,onChange:e=>r(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:[s(`option`,{value:``,disabled:!0,children:`Select destination…`}),l.map(e=>n(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&a&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!a&&i.length===0&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&i.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:i.map(e=>{let t=o===e.id;return n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>c(e.id),className:`accent-primary`}),n(`div`,{children:[s(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),s(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:V(e.sizeBytes)})]},e.id)})})]})]})}function Ce({locations:e,picked:t,onToggle:r}){return e.length===0?s(`div`,{className:`p-4`,children:s(`div`,{className:`text-xs text-foreground-subtle`,children:`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`})}):n(`div`,{className:`p-4 space-y-3`,children:[s(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>n(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>r(e),className:`accent-primary`}),s(`span`,{className:`font-mono text-foreground`,children:e}),s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ee(e)})]},e))})]})]})}function we({destinationName:e,archive:t,picked:r}){return n(`div`,{className:`p-4 space-y-3 text-xs`,children:[s(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-300`,children:`Restore is applied at next server boot. Active connections will drop when you restart.`}),n(`dl`,{className:`space-y-1.5`,children:[s(Q,{term:`Destination`,value:e}),s(Q,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&s(Q,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${V(t.sizeBytes)}`}),s(Q,{term:`Locations`,value:r.length>0?r.join(`, `):`— (full archive)`})]})]})}function Q({term:e,value:t}){return n(`div`,{className:`flex justify-between gap-3`,children:[s(`dt`,{className:`text-foreground-subtle`,children:e}),s(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Te={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function Ee(e){return Te[e]??``}t();function De(){let e=S(),t=h(),[r,i]=o(null),[a,c]=o(!1),[l,u]=o(!1),[d,f]=o(void 0),p=async()=>{await e({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&t.mutate({confirm:!0})};return n(B,{children:[n(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[n(`button`,{onClick:()=>c(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[s(M,{className:`h-3.5 w-3.5`}),`Restore…`]}),n(`button`,{onClick:()=>f(null),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[s(j,{className:`h-3.5 w-3.5`}),`New entry`]})]}),l&&s(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2.5 text-xs text-amber-700 dark:text-amber-300`,children:n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(M,{className:`h-3.5 w-3.5`}),s(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),n(`button`,{onClick:()=>{p()},disabled:t.isPending,className:`inline-flex items-center gap-1.5 rounded bg-amber-500/20 px-2 py-1 font-medium text-amber-800 dark:text-amber-200 hover:bg-amber-500/30 disabled:opacity-50`,children:[t.isPending?s(N,{className:`h-3.5 w-3.5 animate-spin`}):s(M,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),s(de,{onEdit:e=>f(e),onOpenRestoreWizard:e=>i(e)}),d!==void 0&&s(ye,{entry:d,onClose:()=>f(void 0),onSaved:()=>f(void 0)}),(r||a)&&s(xe,{...r?{initialDestinationId:r.destinationId,initialArchiveId:r.archiveId}:{},onClose:()=>{i(null),c(!1)},onScheduled:()=>u(!0)})]})}t();var $=5e3,Oe={"winston-logging":`Rotated log files on this node’s disk.`,"console-logging":`stdout / stderr of the node process.`,"loki-logging":`Pushes to a Grafana Loki instance. Off until enabled with a URL.`,"hub-forwarder":`Agent-only — forwards this node’s entries to the hub.`};function ke(){let e=d({capName:`log-destination`},{refetchInterval:$}),t=f(void 0,{refetchInterval:$}),n=r(()=>W(t.data??[]),[t.data]),i=r(()=>{let e=new Map;for(let n of t.data??[]){let t=n.description,r=n.id;typeof r==`string`&&typeof t==`string`&&t.length>0&&e.set(r,t)}return e},[t.data]);return s(U,{title:`Logging`,subtitle:`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another. Each destination's own configuration is docked under it.`,pageIcon:R,itemIcon:J,capability:`log-destination`,installButtonLabel:`Add destination`,items:r(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive,caption:i.get(e.addonId)??Oe[e.addonId]??``})),[e.data,n,i]),isLoading:e.isLoading,emptyTitle:`No log destinations registered`,emptyDescription:`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`,renderStatusBadges:e=>e.caption.length>0?s(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.caption}):null})}function Ae(){return s(`div`,{className:`flex flex-col p-4`,children:s(ne,{tabs:[{id:`storage`,label:`Storage`,icon:O,content:s(oe,{})},{id:`backup`,label:`Backup`,icon:G,content:s(De,{})},{id:`logging`,label:`Logging`,icon:R,content:s(ke,{})}]})})}export{Ae as DataPage};
|
|
1
|
+
import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{$n as l,Dn as u,En as d,Ho as f,Jn as p,Mn as m,Qn as h,Uo as g,Wo as _,Xn as v,Xo as y,Yn as b,Zn as x,er as S,ln as C,nr as w,rr as T,tr as E}from"./src-BLHY9yig.js";import{t as D}from"./download-Dq2bfdRX.js";import{t as O}from"./hard-drive-COdkuHqf.js";import{t as k}from"./pencil-CfoKCBNv.js";import{t as A}from"./play-CqrjGyv7.js";import{t as j}from"./plus-DHRgxEWi.js";import{t as M}from"./rotate-cw-Dre2EA6E.js";import{C as N,I as P,K as F,R as I,W as ee,i as L,m as R,s as z}from"./index-LPwis6Rq.js";import{t as B}from"./AdminPage-CCD07UMs.js";import{r as te}from"./authed-media-BPd_L9jr.js";import{t as ne}from"./AdminTabs-FswV6m19.js";import{t as V}from"./format-size-CO9d3C3-.js";import{i as H,n as re,r as ie,t as ae}from"./AddLocationWizard-BntkKU2V.js";import{t as U}from"./AddonCollectionPage-DfZQjIPJ.js";import{t as W}from"./addon-display-names-DvSEQty-.js";var G=F(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),K=F(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),q=F(`calendar-clock`,[[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M17.5 17.5 16 16.3V14`,key:`akvzfd`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]),J=F(`file-text`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]);t();function oe(){let e=a(),t=C(),{data:i,isLoading:c,isError:l}=_({}),u=g(),d=r(()=>u.data??[],[u.data]),[p,m]=o(null),[h,v]=o(null),b=f({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),x=y({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),S=e=>{e.isDefault||x.mutate(H(e,{isDefault:!0}))},w=(e,t)=>{x.mutate(H(e,{enabled:t}))},T=async e=>{if(e.isDefault){await t({title:`Cannot delete default location`,message:`"${e.displayName}" is the default for type "${e.type}". Mark another location as default first, then delete this one.`,confirmLabel:`OK`,variant:`warning`});return}await t({title:`Delete location "${e.displayName}"?`,message:`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`,confirmLabel:`Delete`,variant:`danger`})&&b.mutate({id:e.id})},E=r(()=>{let e=new Map;for(let t of i??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[i]),D=c||u.isLoading,O=l||u.isError;return n(B,{children:[D&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),O&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!D&&!O&&n(`div`,{className:`space-y-3`,children:[d.length===0&&s(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:`No storage locations declared by any installed addon.`}),d.map(e=>s(ie,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:E.get(e.id)??[],onAdd:e=>m(e),onEdit:e=>v(e),onDelete:e=>{T(e)},onSetDefault:e=>S(e),onToggleEnabled:(e,t)=>w(e,t)},e.id))]}),p!==null&&s(ae,{initialType:p,onClose:()=>m(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),m(null)}}),h!==null&&s(re,{location:h,onClose:()=>v(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),v(null)}})]})}t();var se=[[`backup`,`listDestinations`]],ce=[`backup`,`listArchives`];function le({destinationId:t,restoreSupported:i,onOpenRestoreWizard:c}){let l=a(),u=C(),{data:d,isLoading:f,isError:m}=x({destinationId:t}),h=d??[],g=p({onSuccess:()=>{l.invalidateQueries({queryKey:[[...ce]]}),l.invalidateQueries({queryKey:se})}}),_=e(async e=>{await u({title:`Delete this archive?`,message:`Permanently deletes "${e.label??e.id}" and frees ${V(e.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&g.mutate({destinationId:t,backupId:e.id})},[u,t,g]),[v,y]=o(null),b=e(async e=>{y(e.id);try{let n=await te(ue(t,e.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.label??e.id}.tar.gz`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{y(null)}},[t]),S=r(()=>[...h].toSorted((e,t)=>t.createdAt-e.createdAt),[h]);return f?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):m?s(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):S.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):s(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),s(`tbody`,{children:S.map(e=>n(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:Y(e.createdAt)}),s(`td`,{className:`px-3 py-1.5 text-foreground`,children:e.label??s(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),s(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:e.locations.join(`, `)}),s(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:V(e.sizeBytes)}),s(`td`,{className:`px-3 py-1.5`,children:n(`div`,{className:`flex items-center justify-end gap-1`,children:[n(`button`,{onClick:()=>{b(e)},disabled:v===e.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 disabled:opacity-50`,title:`Download archive`,children:[v===e.id?s(N,{className:`h-3 w-3 animate-spin`}):s(D,{className:`h-3 w-3`}),`Download`]}),i&&c&&n(`button`,{onClick:()=>c({destinationId:t,archiveId:e.id}),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-primary hover:bg-primary/10`,title:`Restore from this archive`,children:[s(M,{className:`h-3 w-3`}),`Restore`]}),s(`button`,{onClick:()=>{_(e)},disabled:g.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete archive`,children:g.isPending?s(N,{className:`h-3 w-3 animate-spin`}):s(z,{className:`h-3 w-3`})})]})})]},e.id))})]})})}function ue(e,t){return`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function Y(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}t();var X=[[`backup`,`listSchedules`]];function de({onEdit:e,onOpenRestoreWizard:t}){let{data:i,isLoading:a,isError:c}=l(),u=i??[],d=h().data??[],f=r(()=>{let e=new Map;for(let t of d)e.set(t.id,t);return e},[d]),[p,m]=o(null),g=e=>{m(t=>t===e?null:e)};return a?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading backup entries…`}):c?s(`div`,{className:`text-xs text-danger`,children:`Failed to load backup entries`}):u.length===0?s(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:s(`p`,{className:`text-xs text-foreground-subtle`,children:`No backup entries yet. Create one to schedule backups across one or more storage locations.`})}):s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[820px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[s(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),s(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Entry`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),s(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Locations`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-24`,children:`Retention`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-48`,children:`Schedule`}),s(`th`,{className:`text-right px-3 py-2 font-medium w-52`,children:`Actions`})]})}),s(`tbody`,{children:u.map(n=>s(fe,{row:n,destById:f,isOpen:p===n.id,onToggle:()=>g(n.id),onEdit:()=>e(n),...t?{onOpenRestoreWizard:t}:{}},n.id))})]})})}function fe({row:t,destById:l,isOpen:u,onToggle:d,onEdit:f,onOpenRestoreWizard:p}){let m=a(),h=C(),g=T({onSuccess:()=>{m.invalidateQueries({queryKey:X})}}),_=b({onSuccess:()=>{m.invalidateQueries({queryKey:X})}}),v=w({onSuccess:()=>{m.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),m.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]})}}),[y,x]=o(String(t.retentionCount));c(()=>{x(String(t.retentionCount))},[t.retentionCount]);let S=r(()=>({id:t.id,label:t.label,cron:t.cron,locationIds:[...t.locationIds],retentionCount:t.retentionCount,...t.dataSources?{dataSources:[...t.dataSources]}:{}}),[t]),E=e(e=>{g.mutate({...S,enabled:e})},[g,S]),D=e(()=>{let e=Number.parseInt(y,10);if(Number.isNaN(e)||e<1){x(String(t.retentionCount));return}e!==t.retentionCount&&g.mutate({...S,enabled:t.enabled,retentionCount:e})},[g,S,y,t.retentionCount,t.enabled]),O=e(()=>{t.locationIds.length!==0&&v.mutate({destinations:[...t.locationIds],...t.dataSources&&t.dataSources.length>0?{locations:[...t.dataSources]}:{},label:t.label,retentionCount:t.retentionCount})},[v,t]),j=e(async()=>{await h({title:`Delete backup entry?`,message:`"${t.label||t.id}" will stop running. Existing archives are kept.`,confirmLabel:`Delete`,variant:`warning`})&&_.mutate({id:t.id})},[h,_,t.id,t.label]),M=t.cron.trim().length>0,F=g.isPending||_.isPending;return n(i,{children:[n(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[s(`td`,{className:`px-2 py-2`,children:s(`button`,{onClick:d,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:u?`Hide archives`:`Show archives`,children:s(u?I:P,{className:`h-3.5 w-3.5`})})}),s(`td`,{className:`px-3 py-2`,children:n(`button`,{onClick:f,className:`text-left hover:underline focus:outline-none`,children:[s(`div`,{className:`text-foreground font-medium`,children:t.label||`(unnamed)`}),t.lastRunAt!==void 0&&n(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:[`last run `,new Date(t.lastRunAt).toLocaleString()]})]})}),s(`td`,{className:`px-3 py-2`,children:s(`label`,{className:`inline-flex items-center cursor-pointer`,children:s(`input`,{type:`checkbox`,className:`accent-primary`,checked:t.enabled,disabled:F,onChange:e=>E(e.target.checked)})})}),s(`td`,{className:`px-3 py-2`,children:n(`div`,{className:`flex flex-wrap gap-1`,children:[t.locationIds.length===0&&s(`span`,{className:`text-[11px] text-danger italic`,children:`No locations`}),t.locationIds.map(e=>s(`span`,{className:`inline-flex items-center rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-foreground`,title:e,children:l.get(e)?.displayName??e},e))]})}),s(`td`,{className:`px-3 py-2`,children:s(`input`,{type:`number`,min:1,max:1e3,value:y,disabled:F,onChange:e=>x(e.target.value),onBlur:D,onKeyDown:e=>{e.key===`Enter`&&e.target.blur(),e.key===`Escape`&&x(String(t.retentionCount))},className:`w-16 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})}),s(`td`,{className:`px-3 py-2`,children:n(`button`,{onClick:f,className:`group flex flex-col items-start gap-0.5 text-left`,title:`Edit schedule`,children:[n(`span`,{className:`inline-flex items-center gap-1`,children:[s(q,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),s(`span`,{className:`font-mono text-[11px] text-foreground`,children:M?t.cron:`Manual`})]}),M&&t.nextRunAt!==void 0&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`next `,new Date(t.nextRunAt).toLocaleString()]})]})}),s(`td`,{className:`px-3 py-2`,children:n(`div`,{className:`flex items-center justify-end gap-1.5`,children:[n(`button`,{onClick:O,disabled:v.isPending||t.locationIds.length===0,className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,title:`Run this entry now`,children:[v.isPending?s(N,{className:`h-3 w-3 animate-spin`}):s(A,{className:`h-3 w-3`}),`Run now`]}),s(`button`,{onClick:f,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-foreground hover:bg-primary/5`,title:`Edit entry`,children:s(k,{className:`h-3 w-3`})}),s(`button`,{onClick:()=>{j()},disabled:F,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-danger hover:border-danger/40 disabled:opacity-50`,title:`Delete entry`,children:s(z,{className:`h-3 w-3`})})]})})]}),u&&s(`tr`,{className:`border-t border-border bg-background/30`,children:n(`td`,{colSpan:7,className:`px-4 py-3 space-y-4`,children:[t.locationIds.length===0&&s(`p`,{className:`text-xs text-foreground-subtle italic`,children:`This entry has no locations selected.`}),t.locationIds.map(e=>n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:l.get(e)?.displayName??e}),s(le,{destinationId:e,restoreSupported:l.get(e)?.restoreSupported??!0,...p?{onOpenRestoreWizard:p}:{}})]},e))]})})]})}t();var Z=[{id:`manual`,label:`Manual only`,cron:``},{id:`hourly`,label:`Every hour`,cron:`0 * * * *`,description:`On the hour`},{id:`every-3h`,label:`Every 3 hours`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,label:`Every 6 hours`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,label:`Daily at 03:00`,cron:`0 3 * * *`,description:`Every night at 3 AM`},{id:`weekly-sun`,label:`Weekly Sunday 03:00`,cron:`0 3 * * 0`,description:`Sunday morning at 3 AM`}];function pe(e){let t=e.trim();for(let e of Z)if(e.cron===t)return e.id;return`custom`}function me({value:e,onChange:t,previewCount:r=5,disabled:i=!1}){let a=pe(e),[l,u]=o(a===`custom`);c(()=>{a!==`custom`&&u(!1)},[a]);let d=_e(e,250),f=S({cron:d,count:r},{enabled:d.trim().length>0}),p=f.data??null,m=e=>{u(!1),t(e.cron)},h=l||a===`custom`;return n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),n(`div`,{className:`flex flex-wrap gap-1.5`,children:[Z.map(e=>s(`button`,{type:`button`,onClick:()=>m(e),disabled:i,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!l&&a===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.description??e.label,children:e.label},e.id)),s(`button`,{type:`button`,onClick:()=>{u(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:i,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(h?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),h&&n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),s(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:i,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),n(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,s(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),s(he,{cron:d,preview:p,loading:f.isFetching})]})}function he({cron:e,preview:t,loading:r}){return r&&t===null?n(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[s(N,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?s(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:`No future runs match this expression.`}):n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),s(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>n(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[s(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),s(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:ge(e)})]},`${e}-${t}`))})]}):s(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??`Invalid cron expression`})}function ge(e){let t=e-Date.now();if(t<=0)return`now`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function _e(e,t){let[n,i]=o(e),a=r(()=>e,[e]);return c(()=>{let e=setTimeout(()=>i(a),t);return()=>clearTimeout(e)},[a,t]),n}t();var ve=[[`backup`,`listSchedules`]];function ye({entry:e,onClose:t,onSaved:i}){let c=a(),l=h(),u=l.data??[],[d,f]=o(e?.label??``),[p,m]=o(e?.cron??`0 3 * * *`),[g,_]=o(e?.enabled??!0),[v,y]=o(String(e?.retentionCount??7)),[b,x]=o(new Set(e?.locationIds??[])),S=T({onSuccess:()=>{c.invalidateQueries({queryKey:ve}),i()}}),C=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},w=Number.parseInt(v,10),E=r(()=>d.trim().length>0&&b.size>0&&!Number.isNaN(w)&&w>=1&&w<=1e3,[d,b,w]),D=()=>{E&&S.mutate({...e?{id:e.id}:{},label:d.trim(),cron:p.trim(),enabled:g,locationIds:Array.from(b),retentionCount:w})},O=S.error instanceof Error?S.error.message:null;return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:n(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3 sticky top-0 bg-surface`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e?`Edit backup entry`:`New backup entry`}),s(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:s(L,{className:`h-4 w-4`})})]}),n(`div`,{className:`p-4 space-y-4`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Name`}),s(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`Nightly offsite`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),n(`div`,{className:`space-y-1.5`,children:[n(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:[`Locations (`,b.size,` selected)`]}),l.isLoading&&n(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[s(N,{className:`h-3.5 w-3.5 animate-spin`}),`Loading locations…`]}),!l.isLoading&&u.length===0&&s(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:"No `backups` storage locations configured. Add one in Settings → Storage first."}),u.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-52 overflow-y-auto`,children:u.map(e=>n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`checkbox`,checked:b.has(e.id),onChange:()=>C(e.id),className:`accent-primary`}),s(`span`,{className:`text-foreground`,children:e.displayName})]}),n(`div`,{className:`flex items-center gap-1.5`,children:[s(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-surface border border-border rounded px-1.5 py-0.5`,children:e.kind}),s(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]},e.id))})]}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Retention (archives kept)`}),s(`input`,{type:`number`,min:1,max:1e3,value:v,onChange:e=>y(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Enabled`}),n(`label`,{className:`inline-flex items-center gap-2 py-1.5 cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`accent-primary`}),s(`span`,{className:`text-xs text-foreground-subtle`,children:`Run on schedule`})]})]})]}),n(`div`,{className:`space-y-1.5 border-t border-border pt-3`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Schedule`}),s(me,{value:p,onChange:m,disabled:S.isPending})]}),O&&s(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:O})]}),n(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3 sticky bottom-0 bg-surface`,children:[s(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),n(`button`,{onClick:D,disabled:!E||S.isPending,className:`inline-flex items-center gap-1.5 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&&s(N,{className:`h-3.5 w-3.5 animate-spin`}),e?`Save`:`Create entry`]})]})]})})}t();var be=[[`backup`,`list`]];function xe({initialDestinationId:e,initialArchiveId:t,onClose:i,onScheduled:l}){let u=a(),[d,f]=o(e&&t?2:1),[p,m]=o(e),[g,_]=o(t),[y,b]=o(new Set),{data:S}=h(),C=S??[],{data:w,isLoading:T}=x({destinationId:p??``},{enabled:!!p}),D=w??[];c(()=>{if(p!==void 0)return;let e=C.filter(e=>e.restoreSupported);e.length===1&&m(e[0].id)},[p,C]);let{data:O}=v({destinationId:p??``,backupId:g??``},{enabled:!!p&&!!g}),k=r(()=>O?.locations??[],[O]);c(()=>{k.length!==0&&b(e=>e.size===0?new Set(k):e)},[k]);let A=E({onSuccess:()=>{u.invalidateQueries({queryKey:be}),l(),i()}}),j=e=>{b(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},P=!!p&&!!g,F=y.size>0,I=P&&F&&!A.isPending,R=()=>{!p||!g||A.mutate({destinationId:p,backupId:g,locations:[...y]})};return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:i,children:n(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[n(`div`,{className:`space-y-0.5`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),n(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,d,` of 3 —`,` `,d===1?`pick source`:d===2?`pick locations`:`confirm`]})]}),s(`button`,{onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:s(L,{className:`h-4 w-4`})})]}),d===1&&s(Se,{destinations:C,destinationId:p,onPickDestination:e=>{m(e),_(void 0),b(new Set)},archives:D,archivesLoading:T,archiveId:g,onPickArchive:_}),d===2&&s(Ce,{locations:k,picked:y,onToggle:j}),d===3&&s(we,{destinationName:C.find(e=>e.id===p)?.displayName??p??``,archive:D.find(e=>e.id===g),picked:[...y]}),n(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[s(`div`,{children:d>1&&n(`button`,{onClick:()=>f(e=>e===3?2:1),className:`inline-flex items-center gap-1 rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:[s(ee,{className:`h-3 w-3`}),`Back`]})}),n(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),d<3?n(`button`,{disabled:d===1&&!P||d===2&&!F,onClick:()=>f(e=>e===1?2:3),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:[`Next`,s(K,{className:`h-3 w-3`})]}):n(`button`,{onClick:R,disabled:!I,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[A.isPending?s(N,{className:`h-3.5 w-3.5 animate-spin`}):s(M,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function Se({destinations:e,destinationId:t,onPickDestination:r,archives:i,archivesLoading:a,archiveId:o,onPickArchive:c}){let l=e.filter(e=>e.restoreSupported);return n(`div`,{className:`p-4 space-y-3`,children:[n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),n(`select`,{value:t??``,onChange:e=>r(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:[s(`option`,{value:``,disabled:!0,children:`Select destination…`}),l.map(e=>n(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&a&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!a&&i.length===0&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&i.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:i.map(e=>{let t=o===e.id;return n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>c(e.id),className:`accent-primary`}),n(`div`,{children:[s(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),s(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:V(e.sizeBytes)})]},e.id)})})]})]})}function Ce({locations:e,picked:t,onToggle:r}){return e.length===0?s(`div`,{className:`p-4`,children:s(`div`,{className:`text-xs text-foreground-subtle`,children:`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`})}):n(`div`,{className:`p-4 space-y-3`,children:[s(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>n(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>r(e),className:`accent-primary`}),s(`span`,{className:`font-mono text-foreground`,children:e}),s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ee(e)})]},e))})]})]})}function we({destinationName:e,archive:t,picked:r}){return n(`div`,{className:`p-4 space-y-3 text-xs`,children:[s(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-300`,children:`Restore is applied at next server boot. Active connections will drop when you restart.`}),n(`dl`,{className:`space-y-1.5`,children:[s(Q,{term:`Destination`,value:e}),s(Q,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&s(Q,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${V(t.sizeBytes)}`}),s(Q,{term:`Locations`,value:r.length>0?r.join(`, `):`— (full archive)`})]})]})}function Q({term:e,value:t}){return n(`div`,{className:`flex justify-between gap-3`,children:[s(`dt`,{className:`text-foreground-subtle`,children:e}),s(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Te={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function Ee(e){return Te[e]??``}t();function De(){let e=C(),t=m(),[r,i]=o(null),[a,c]=o(!1),[l,u]=o(!1),[d,f]=o(void 0),p=async()=>{await e({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&t.mutate({confirm:!0})};return n(B,{children:[n(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[n(`button`,{onClick:()=>c(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[s(M,{className:`h-3.5 w-3.5`}),`Restore…`]}),n(`button`,{onClick:()=>f(null),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[s(j,{className:`h-3.5 w-3.5`}),`New entry`]})]}),l&&s(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2.5 text-xs text-amber-700 dark:text-amber-300`,children:n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(M,{className:`h-3.5 w-3.5`}),s(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),n(`button`,{onClick:()=>{p()},disabled:t.isPending,className:`inline-flex items-center gap-1.5 rounded bg-amber-500/20 px-2 py-1 font-medium text-amber-800 dark:text-amber-200 hover:bg-amber-500/30 disabled:opacity-50`,children:[t.isPending?s(N,{className:`h-3.5 w-3.5 animate-spin`}):s(M,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),s(de,{onEdit:e=>f(e),onOpenRestoreWizard:e=>i(e)}),d!==void 0&&s(ye,{entry:d,onClose:()=>f(void 0),onSaved:()=>f(void 0)}),(r||a)&&s(xe,{...r?{initialDestinationId:r.destinationId,initialArchiveId:r.archiveId}:{},onClose:()=>{i(null),c(!1)},onScheduled:()=>u(!0)})]})}t();var $=5e3,Oe={"winston-logging":`Rotated log files on this node’s disk.`,"console-logging":`stdout / stderr of the node process.`,"loki-logging":`Pushes to a Grafana Loki instance. Off until enabled with a URL.`,"hub-forwarder":`Agent-only — forwards this node’s entries to the hub.`};function ke(){let e=u({capName:`log-destination`},{refetchInterval:$}),t=d(void 0,{refetchInterval:$}),n=r(()=>W(t.data??[]),[t.data]),i=r(()=>{let e=new Map;for(let n of t.data??[]){let t=n.description,r=n.id;typeof r==`string`&&typeof t==`string`&&t.length>0&&e.set(r,t)}return e},[t.data]);return s(U,{title:`Logging`,subtitle:`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another. Each destination's own configuration is docked under it.`,pageIcon:R,itemIcon:J,capability:`log-destination`,installButtonLabel:`Add destination`,items:r(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive,caption:i.get(e.addonId)??Oe[e.addonId]??``})),[e.data,n,i]),isLoading:e.isLoading,emptyTitle:`No log destinations registered`,emptyDescription:`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`,renderStatusBadges:e=>e.caption.length>0?s(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.caption}):null})}function Ae(){return s(`div`,{className:`flex flex-col p-4`,children:s(ne,{tabs:[{id:`storage`,label:`Storage`,icon:O,content:s(oe,{})},{id:`backup`,label:`Backup`,icon:G,content:s(De,{})},{id:`logging`,label:`Logging`,icon:R,content:s(ke,{})}]})})}export{Ae as DataPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,b as a,o,q as s,x as c,z as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as u}from"./player-overlays-BGbLKvcn.js";import{At as d,Br as f,Dt as p,Et as m,It as h,Lt as g,Ms as _,Nt as v,Ot as y,Pt as b,ai as x,ci as S,di as C,fi as w,ii as T,kt as E,li as D,ln as O,ni as k,oi as A,pi as j,ri as M,si as N,ti as P,ui as F,wt as I}from"./src-Buv5KpAz.js";import{Lt as L}from"./src-CQVcBp6b.js";import{a as R,i as z,n as B,r as V,t as H}from"./face-bbox-BFT7iMc1.js";import{a as U,c as ee,f as W,i as G,l as te,m as ne,n as K,o as re,p as q,r as ie,s as ae,t as oe,u as se}from"./debounced-invalidate-BIRVvqvY.js";import{t as ce}from"./pencil-DsWgW1cM.js";import{t as le}from"./plus-zSkh3oEn.js";import{t as ue}from"./refresh-cw-Cly4MRhi.js";import{t as de}from"./rotate-cw-CNTEn7nJ.js";import{t as fe}from"./square-check-big-DsiPGDCA.js";import{t as pe}from"./square-BlSn3fsr.js";import{t as me}from"./undo-2-DXcExZt9.js";import{C as J,I as Y,K as X,R as he,h as ge,i as Z,l as _e,o as ve,s as ye,z as be}from"./index-vZPXzSPK.js";import{t as xe}from"./AdminPage-CCD07UMs.js";import{r as Se,t as Ce}from"./authed-media-BPd_L9jr.js";var we=X(`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`}]]),Te=X(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]);n();var Ee=`pipeline-analytics`,De=`photo.analyze`,Oe=`photo.enroll`,ke=`photo.discard`,Ae=18*1024*1024;function je(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function $(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Me(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Ne(e){if(!je(e))return null;let t=$(e,`x`),n=$(e,`y`),r=$(e,`width`),i=$(e,`height`);return t===null||n===null||r===null||i===null?null:{x:t,y:n,width:r,height:i}}function Pe(e){if(!je(e))return null;let t=$(e,`detectionShortSidePx`),n=$(e,`score`);if(t===null||n===null)return null;let r=$(e,`magnitude`);return{detectionShortSidePx:t,score:n,...r===null?{}:{magnitude:r}}}function Fe(e){if(!je(e))return null;let t=$(e,`faceIndex`),n=$(e,`score`),r=Me(e,`enrollable`),i=Ne(e.bbox),a=Pe(e.quality);if(t===null||n===null||r===null||i===null||a===null)return null;let o=Q(e,`refusedReason`),s=Q(e,`alignedCropBase64`),c=Q(e,`modelId`);return{faceIndex:t,bbox:i,score:n,enrollable:r,quality:a,...o===null?{}:{refusedReason:o},...s===null?{}:{alignedCropBase64:s},...c===null?{}:{modelId:c}}}function Ie(e){if(!je(e))return null;let t=Q(e,`sessionId`),n=Q(e,`ranOnNodeId`),r=e.faces;if(t===null||n===null||!Array.isArray(r))return null;let i=[];for(let e of r){let t=Fe(e);t!==null&&i.push(t)}return{sessionId:t,ranOnNodeId:n,faces:i}}function Le(e){if(!je(e))return null;let t=Q(e,`sampleId`),n=Q(e,`identityId`),r=Q(e,`modelId`);return t===null||n===null||r===null?null:{sampleId:t,identityId:n,modelId:r}}function Re(e,t,n){let r={...e};return n===null||n===``?delete r[t]:r[t]=n,r}function ze(e,t){return e.filter(e=>e.enrollable&&t[e.faceIndex]!==void 0).length}function Be(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 Ve(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 He(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 Ue(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 We(e,t,n){return e.map(e=>e.photoIndex===t?{...e,...n}:e)}function Ge(e,t){return`${e}:${t}`}function Ke(e,t,n,r){let i=Re(e[t]??{},n,r),a={...e};return Object.keys(i).length===0?delete a[t]:a[t]=i,a}function qe(e,t){let n=0;for(let r of e)r.analysis!==void 0&&(n+=ze(r.analysis.faces,t[r.photoIndex]??{}));return n}var Je=`__new__`;function Ye(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[Ge(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 Xe(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[Ge(e,a)]??``).trim()];s!==void 0&&(o[a]=s)}r[e]=o}return r}function Ze(e,t){let n=[];for(let r of e){if(r.analysis===void 0)continue;let e=Be(r.analysis.sessionId,r.analysis.faces,t[r.photoIndex]??{});for(let t of e)n.push({photoIndex:r.photoIndex,request:t})}return n}function Qe(e){return/expired/i.test(e)}function $e(e){return e instanceof Error?e.message:String(e)}async function et(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 Ze(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=$e(t);if(!Qe(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 (${$e(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)}: ${$e(e)}`)}}}return{enrolled:o,stampedModelId:s,failures:a,refreshedAnalyses:i}}var tt=[[`faceGallery`]],nt=``;function rt(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 it(e){return e instanceof Error?e.message:String(e)}function at({face:e,identities:t,value:n,onChange:o,disabled:s}){let l=i(()=>[{value:nt,label:`Ignore this face`},...t.map(e=>({value:e.id,label:e.name})),{value:Je,label:`+ New person…`}],[t]);return r(`div`,{className:`rounded-md border border-border bg-surface p-2`,children:[c(`div`,{className:`mb-2 aspect-square w-full overflow-hidden rounded border border-border bg-surface-hover`,children:e.alignedCropBase64?c(`img`,{src:`data:image/jpeg;base64,${e.alignedCropBase64}`,alt:`Face ${e.faceIndex+1}`,className:`h-full w-full object-cover`}):c(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:c(Te,{className:`h-8 w-8`})})}),e.enrollable?r(a,{children:[c(v,{options:l,value:n,disabled:s,onChange:e=>o(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:[c(h,{variant:`warning`,className:`text-[10px]`,children:`Not usable`}),c(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:Ve(e.refusedReason)})]})]})}function ot({photo:e,identities:t,draft:n,newNames:i,disabled:a,onAssign:o,onNameChange:s,onRetry:l}){let u=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:[c(`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:[c(J,{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:[u.length,` face`,u.length===1?``:`s`,` · analysed on`,` `,e.analysis.ranOnNodeId]}),e.status===`failed`&&r(g,{variant:`secondary`,size:`sm`,disabled:a,onClick:l,children:[c(de,{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:[c(ve,{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`&&u.length===0&&c(`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.`}),u.length>0&&c(`div`,{className:`grid grid-cols-3 gap-3 sm:grid-cols-4 md:grid-cols-5`,children:u.map(e=>c(at,{face:e,identities:t,value:d[e.faceIndex]??nt,disabled:a,onChange:t=>o(e.faceIndex,t)},e.faceIndex))}),u.filter(e=>d[e.faceIndex]===Je).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]}),c(`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[Ge(e.photoIndex,t.faceIndex)]??``,onChange:e=>s(t.faceIndex,e.target.value)})]},t.faceIndex))]})}function st({open:n,onOpenChange:a}){let l=u(),f=o(),h=t(null),{data:_}=A(),v=k(),[b,x]=s([]),[S,C]=s(!1),[w,T]=s(null),[D,O]=s({}),[j,M]=s({}),[N,P]=s(null),F=i(()=>(_??[]).map(e=>({id:e.id,name:e.name})),[_]),L=b.some(e=>e.status===`queued`||e.status===`analyzing`),R=L||S,z=e(e=>{for(let t of e){let e=t.analysis?.sessionId;e!==void 0&&l.trpcClient.addons.custom.mutate({addonId:Ee,action:ke,input:{sessionId:e}}).catch(()=>void 0)}},[l]),B=e(()=>{x([]),O({}),M({}),T(null),P(null),h.current&&(h.current.value=``)},[]),V=e(()=>{z(b),B(),a(!1)},[z,a,b,B]),H=e(async e=>{let t=Ie(await l.trpcClient.addons.custom.mutate({addonId:Ee,action:De,input:{photoBase64:e.photoBase64,filename:e.filename}}));if(t===null)throw Error(`the server replied with something this page could not read`);return t},[l]),U=e(async e=>{x(t=>We(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await H(e);x(n=>We(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){x(n=>We(n,e.photoIndex,{status:`failed`,error:it(t)}))}},[H]),ee=e(async e=>{if(e.length===0)return;z(b),B();let t=He(e,{maxCount:12,maxBytes:Ae}),n=[];t.oversize.length>0&&n.push(`Over the ${Math.round(Ae/(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&&T(n.join(` `));let r;try{r=await Promise.all(t.accepted.map(async(e,t)=>({photoIndex:t,filename:e.name,photoBase64:await rt(e),status:`queued`})))}catch(e){T(it(e));return}x(r),await Ue(r,2,e=>U(e))},[z,b,B,U]),W=qe(b,D),G=e(async()=>{C(!0),T(null),P(null);try{let e=Ye(b,D,j);if(e.kind===`error`){T(e.message);return}let t={};for(let n of e.names)t[n]=(await v.mutateAsync({name:n})).id;let n=await et(b,Xe(D,j,t),{enroll:async e=>{let t=Le(await l.trpcClient.addons.custom.mutate({addonId:Ee,action:Oe,input:e}));if(t===null)throw Error(`unreadable reply`);return t},reanalyze:e=>H(e)});Object.keys(n.refreshedAnalyses).length>0&&x(e=>e.map(e=>{let t=n.refreshedAnalyses[e.photoIndex];return t===void 0?e:{...e,status:`analyzed`,analysis:t}})),f.invalidateQueries({queryKey:tt}),n.failures.length>0&&T(n.failures.join(` · `)),P(n.enrolled===0?`Nothing was enrolled.`:`Enrolled ${n.enrolled} sample${n.enrolled===1?``:`s`}${n.stampedModelId===null?``:` with ${n.stampedModelId}`}.`)}catch(e){T(it(e))}finally{C(!1)}},[H,v,D,j,b,f,l]),te=b.filter(e=>e.status===`analyzed`).length;return c(I,{open:n,onOpenChange:e=>e?a(!0):V(),children:r(m,{className:`max-w-3xl`,children:[r(E,{children:[c(d,{children:`Enrol from photos`}),c(p,{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 `,c(`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:[c(`input`,{ref:h,type:`file`,accept:`image/jpeg,image/png,image/webp`,multiple:!0,className:`hidden`,onChange:e=>void ee(Array.from(e.target.files??[]))}),r(g,{variant:`secondary`,size:`sm`,disabled:R,onClick:()=>h.current?.click(),children:[L?c(J,{className:`h-3.5 w-3.5 animate-spin`}):c(we,{className:`h-3.5 w-3.5`}),`Choose photos`]}),b.length>0&&r(`span`,{className:`text-xs text-foreground-subtle`,children:[te,`/`,b.length,` photo`,b.length===1?``:`s`,` analysed`]})]}),w!==null&&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:[c(ve,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),c(`span`,{children:w})]}),N!==null&&c(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:N}),b.length>0&&c(`div`,{className:`max-h-[50vh] space-y-4 overflow-y-auto pr-1`,children:b.map(e=>c(ot,{photo:e,identities:F,draft:D,newNames:j,disabled:R,onAssign:(t,n)=>O(r=>Ke(r,e.photoIndex,t,n===nt?null:n)),onNameChange:(t,n)=>M(r=>({...r,[Ge(e.photoIndex,t)]:n})),onRetry:()=>void U(e)},e.photoIndex))}),r(y,{children:[c(g,{variant:`secondary`,onClick:V,disabled:S,children:`Close`}),r(g,{variant:`primary`,onClick:()=>void G(),disabled:R||W===0,children:[S?c(J,{className:`h-3.5 w-3.5 animate-spin`}):null,`Enrol `,W,` face`,W===1?``:`s`]})]})]})})}n();var ct=[[`faceGallery`]];function lt({identityId:e}){let t=o(),{data:n,isLoading:i}=N({identityId:e}),a=D();function s(n){a.mutate({identityId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:ct})}})}return i?r(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[c(J,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!n||n.length===0?c(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):c(`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?c(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):c(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:c(Te,{className:`h-6 w-6`})}),e.source===`photo`&&c(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 p-0.5 text-white`,title:`Enrolled from an uploaded photo`,children:c(we,{className:`h-3 w-3`})}),c(`button`,{type:`button`,onClick:()=>s(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:c(Z,{className:`h-4 w-4 text-white`})})]},e.id))})}function ut({identity:e,expanded:t,onToggle:n}){let i=o(),[l,u]=s(``),[f,_]=s(!1),[v,x]=s(!1),S=F(),C=T();function w(){u(e.name),_(!0)}function D(){_(!1),u(``)}function O(){let t=l.trim();if(!t||t===e.name){D();return}S.mutate({id:e.id,name:t},{onSettled:()=>{i.invalidateQueries({queryKey:ct}),D()}})}function k(){C.mutate({id:e.id},{onSettled:()=>{i.invalidateQueries({queryKey:ct}),x(!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:[c(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:e.coverBase64?c(`img`,{src:`data:image/jpeg;base64,${e.coverBase64}`,alt:e.name,className:`h-full w-full object-cover`}):c(`div`,{className:`flex h-full w-full items-center justify-center`,children:c(Te,{className:`h-4 w-4 text-foreground-subtle`})})}),c(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:f?r(a,{children:[c(b,{value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&O(),e.key===`Escape`&&D()},className:`h-6 text-xs`,autoFocus:!0}),c(`button`,{type:`button`,onClick:O,disabled:S.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:c(be,{className:`h-3.5 w-3.5`})}),c(`button`,{type:`button`,onClick:D,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:c(Z,{className:`h-3.5 w-3.5`})})]}):c(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),c(h,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!f&&r(`div`,{className:`flex items-center gap-1`,children:[c(`button`,{type:`button`,onClick:w,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:c(ce,{className:`h-3.5 w-3.5`})}),c(`button`,{type:`button`,onClick:()=>x(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:c(ye,{className:`h-3.5 w-3.5`})})]}),c(`button`,{type:`button`,onClick:n,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:c(t?he:Y,{className:`h-3.5 w-3.5`})})]}),t&&c(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:c(lt,{identityId:e.id})}),c(I,{open:v,onOpenChange:e=>!e&&x(!1),children:r(m,{children:[r(E,{children:[c(d,{children:`Delete person`}),r(p,{children:[`Delete `,c(`strong`,{children:e.name}),` and all their samples? This cannot be undone.`]})]}),r(y,{children:[c(g,{variant:`secondary`,onClick:()=>x(!1),children:`Cancel`}),r(g,{variant:`danger`,onClick:k,disabled:C.isPending,children:[C.isPending?c(J,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function dt(){let e=o(),[t,n]=s(``),i=k();function a(){let r=t.trim();r&&i.mutate({name:r},{onSettled:()=>{e.invalidateQueries({queryKey:ct}),n(``)}})}return r(`div`,{className:`flex items-center gap-2 pt-2`,children:[c(b,{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(g,{variant:`primary`,size:`sm`,onClick:a,disabled:i.isPending||!t.trim(),children:[i.isPending?c(J,{className:`h-3.5 w-3.5 animate-spin`}):c(le,{className:`h-3.5 w-3.5`}),`Add`]})]})}function ft(){let{data:e,isLoading:t}=A(),[n,i]=s(null),[a,o]=s(!1);function l(e){i(t=>t===e?null:e)}return t?r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[c(J,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):r(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&c(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),e?.map(e=>c(ut,{identity:e,expanded:n===e.id,onToggle:()=>l(e.id)},e.id)),c(dt,{}),c(`div`,{className:`pt-1`,children:r(g,{variant:`secondary`,size:`sm`,onClick:()=>o(!0),children:[c(we,{className:`h-3.5 w-3.5`}),`Enrol from a photo`]})}),c(st,{open:a,onOpenChange:o})]})}function pt(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function mt(e){return e.filter(pt).map(e=>e.faceId)}function ht(e){let t=0;for(let n of e)pt(n)&&(t+=1);return t}function gt(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 _t=[[`faceGallery`]];function vt({faceIds:e,identities:t,onDone:n}){let i=o(),a=P(),l=k(),[u,f]=s(``),[h,_]=s(!1),[v,x]=s(null),S=e!==null&&e.length>0,C=e?.length??0;function w(){_(!1),f(``),x(null)}function T(){w(),n()}function D(t){!e||e.length===0||a.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{i.invalidateQueries({queryKey:_t}),T()}})}function O(){!e||!u.trim()||l.mutate({name:u.trim()},{onSuccess:e=>{e?.id&&D(e.id)},onError:()=>{i.invalidateQueries({queryKey:_t}),T()}})}let A=a.isPending||l.isPending;return c(I,{open:S,onOpenChange:e=>!e&&T(),children:r(m,{children:[r(E,{children:[c(d,{children:C>1?`Assign ${String(C)} faces to person`:`Assign face to person`}),c(p,{children:`Select an existing person or create a new one.`})]}),c(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>r(`button`,{type:`button`,onClick:()=>x(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${v===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[c(`span`,{className:`font-medium`,children:e.name}),r(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),h?c(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:c(b,{placeholder:`New person name…`,value:u,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&O()},autoFocus:!0,className:`flex-1`})}):c(`button`,{type:`button`,onClick:()=>{x(null),_(!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 person…`}),r(y,{children:[c(g,{variant:`secondary`,onClick:T,disabled:A,children:`Cancel`}),h?r(g,{variant:`primary`,onClick:O,disabled:A||!u.trim(),children:[A&&c(J,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):r(g,{variant:`primary`,onClick:()=>v&&D(v),disabled:A||!v,children:[A&&c(J,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,C>1?` ${String(C)}`:``]})]})]})})}n();function yt(e){let[t,n]=s(null),[r,i]=s(null),[a,o]=s(!1);return l(()=>{if(n(null),i(null),o(!1),!e)return;let t=!1,r=null;return(async()=>{try{let i=await Se(`${Ce}/${encodeURIComponent(e)}`);if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),l(()=>{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 bt(e){let t=e.filter(e=>e.base64.length>0);return t.length===0?null:t.find(e=>/crop|face/i.test(e.kind))??t[0]}function xt({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:[c(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),c(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:t})]})}function St({box:e}){return c(`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:c(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Face`})})}function Ct({face:e,cameraName:t,onClose:n,onAssign:a,onUnassign:o,onDelete:l,actionsPending:u}){let{data:d,isFetching:f}=x({faceId:e?.faceId??``},{enabled:e!==null}),[p,h]=s(`frame`),{frameSrc:_,naturalWidth:v,naturalHeight:y,failed:b}=yt(e?.keyFrameMediaKey),S=i(()=>{let t=bt(d??[]);return t?`data:image/jpeg;base64,${t.base64}`:gt(e)},[d,e]),C=i(()=>!e?.faceBbox||v===null||y===null?null:H(e.faceBbox,v,y),[e?.faceBbox,v,y]);if(e===null)return null;let w=typeof e.keyFrameMediaKey==`string`&&e.keyFrameMediaKey.length>0&&!b,T=w&&p===`frame`,E=e.assigned?e.identityName??`Assigned`:e.recognizedIdentityId?`${e.identityName??`Recognized`} (suggested)`:`Unassigned`;return c(I,{open:!0,onOpenChange:e=>!e&&n(),children:r(m,{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:[r(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`min-w-0`,children:[c(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:`Face detail`}),c(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),c(`button`,{type:`button`,onClick:n,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:c(Z,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[w&&r(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[r(`button`,{type:`button`,onClick:()=>h(`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:[c(z,{className:`h-3.5 w-3.5`}),` Full frame`]}),r(`button`,{type:`button`,onClick:()=>h(`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:[c(R,{className:`h-3.5 w-3.5`}),` Crop`]})]}),T&&_?c(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:c(K,{src:_,alt:`Full frame with detected face`,fit:`natural`,className:`w-full`,overlay:C?c(St,{box:C}):void 0})}):S?r(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[c(K,{src:S,alt:`Detected face`,className:`h-full w-full`}),f&&c(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:c(J,{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:[c(ne,{className:`h-8 w-8 text-warning/70`}),c(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),c(`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:[c(xt,{label:`Camera`,value:t}),c(xt,{label:`Captured`,value:q(e.timestamp)}),c(xt,{label:`Track`,value:e.trackId}),c(xt,{label:`Identity`,value:E})]})]}),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(g,{variant:`secondary`,onClick:()=>o(e.faceId),disabled:u,children:[c(B,{className:`h-3.5 w-3.5`}),` Detach`]}):r(g,{variant:`primary`,onClick:()=>a(e.faceId),disabled:u,children:[c(V,{className:`h-3.5 w-3.5`}),` Assign`]}),r(g,{variant:`secondary`,onClick:()=>l(e.faceId),disabled:u,children:[c(ye,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}function wt(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function Tt(e,t){return e.faceIds.filter(e=>!t.has(e))}function Et(e,t){return e.faceIds.filter(e=>t(e))}n();var Dt=[[`faceGallery`]],Ot=20,kt=.3,At=.9,jt=.05,Mt=.5,Nt=2,Pt=10,Ft=2;function It({cluster:e,face:t,active:n,onSelect:i}){let a=gt(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:[c(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:a===null?c(ne,{className:`h-24 w-24 p-6 text-foreground-subtle`}):c(`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 Lt({face:e,cameraName:t,nowMs:n,excluded:i,onToggleExclude:a,onDelete:o,deletePending:s}){let l=gt(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:[l===null?r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[c(ne,{className:`h-7 w-7 text-warning/70`}),c(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):c(K,{src:l,alt:`Face from ${t}`,className:`h-full w-full`}),c(`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:c(i?me:Z,{className:`h-3.5 w-3.5`})})]}),r(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[c(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),c(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:W(e.timestamp,n)})]}),c(`div`,{className:`mt-1 flex items-center justify-end border-t border-border/60 px-1 py-0.5`,children:c(`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?c(J,{className:`h-4 w-4 animate-spin`}):c(ye,{className:`h-4 w-4`})})})]})}function Rt({open:e,onClose:t,byId:n,cameraName:u,nowMs:d,identities:f,selectMany:p}){let h=o(),_=O(),v=M(),[y,b]=s(Mt),[x,S]=s(Ft),[w,T]=s(null),[E,D]=s({}),[k,A]=s(null),{data:j,isFetching:N,refetch:P}=C({threshold:y,minClusterSize:x,limit:Ot},{enabled:e}),F=j??[];l(()=>{D({})},[y,x]),l(()=>{if(F.length===0){T(null);return}F.some(e=>e.representativeFaceId===w)||T(F[0]?.representativeFaceId??null)},[F]);let L=i(()=>F.find(e=>e.representativeFaceId===w)??null,[F,w]),R=L?E[L.representativeFaceId]??new Set:new Set,z=i(()=>L?Et(L,e=>n.has(e)):[],[L,n]),B=L?L.faceIds.length-z.length:0,H=L?Tt({...L,faceIds:z},R):[];function U(e){if(!L)return;let t=L.representativeFaceId;D(n=>({...n,[t]:wt(n[t]??new Set,e)}))}function ee(){h.invalidateQueries({queryKey:Dt})}async function W(e){await _({title:`Delete face`,message:`Permanently deletes this face crop. This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&v.mutate({faceId:e},{onSettled:ee})}function G(){A(null),t()}function te(){H.length!==0&&(p(H),G())}return r(I,{open:e,onOpenChange:e=>!e&&G(),children:[r(m,{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 px-4 py-3`,children:[r(`div`,{className:`flex items-center justify-between gap-2`,children:[r(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[c(_e,{className:`h-4 w-4 text-primary`}),` Look-alike groups`]}),c(`button`,{type:`button`,onClick:G,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:c(Z,{className:`h-4 w-4`})})]}),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`,c(`input`,{type:`range`,min:kt,max:At,step:jt,value:y,onChange:e=>b(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),c(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:y.toFixed(2)})]}),r(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Min size`,c(`input`,{type:`number`,min:Nt,max:Pt,step:1,value:x,onChange:e=>S(Math.min(Pt,Math.max(Nt,Number(e.target.value)||Nt))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),r(g,{variant:`secondary`,onClick:()=>{D({}),P()},disabled:N,children:[N?c(J,{className:`h-3.5 w-3.5 animate-spin`}):c(ue,{className:`h-3.5 w-3.5`}),`Re-analyze`]})]})]}),c(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:N&&F.length===0?r(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[c(J,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):F.length===0?c(`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(a,{children:[c(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:F.map(e=>c(It,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===w,onSelect:()=>T(e.representativeFaceId)},e.representativeFaceId))}),c(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:F.map(e=>c(It,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===w,onSelect:()=>T(e.representativeFaceId)},e.representativeFaceId))}),c(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:L&&r(a,{children:[B>0&&r(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:[B,` not loaded — excluded from actions`]}),c(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,1fr))] gap-2`,children:z.map(e=>{let t=n.get(e);return t?c(Lt,{face:t,cameraName:u(t.deviceId),nowMs:d,excluded:R.has(e),onToggleExclude:()=>U(e),onDelete:()=>void W(e),deletePending:v.isPending&&v.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:[c(g,{variant:`secondary`,onClick:te,disabled:H.length===0,children:`Select in gallery`}),r(g,{variant:`primary`,onClick:()=>A(H),disabled:H.length===0,children:[c(V,{className:`h-3.5 w-3.5`}),` Adopt (`,H.length,`)`]})]})]}),c(vt,{faceIds:k,identities:f,onDone:()=>A(null)})]})}n();var zt=[[`faceGallery`]],Bt=500,Vt=120;function Ht({face:e,cameraName:t,nowMs:n,selected:i,onToggleSelect:a,onAssign:s,onOpenDetail:l}){let u=o(),d=w(),f=M(),p=()=>{u.invalidateQueries({queryKey:zt})},m=()=>l(e.faceId),h=gt(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:[c(ne,{className:`h-7 w-7 text-warning/70`}),c(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):c(`img`,{src:h,alt:`Face from ${t}`,onClick:m,loading:`lazy`,decoding:`async`,className:`h-full w-full cursor-zoom-in object-cover`}),c(`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?c(fe,{className:`h-4 w-4 text-primary`}):c(pe,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[c(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),c(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:W(e.timestamp,n)}),e.identityName&&c(`p`,{className:`text-[10px] font-medium text-primary truncate`,title:e.identityName,children:e.identityName})]}),r(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?c(`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?c(J,{className:`h-4 w-4 animate-spin`}):c(B,{className:`h-4 w-4`})}):c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(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:c(V,{className:`h-4 w-4`})}),c(`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?c(J,{className:`h-4 w-4 animate-spin`}):c(ye,{className:`h-4 w-4`})})]})]})}var Ut=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function Wt(){let e=o(),[t,n]=s(`all`),[l,u]=s(ae),[d,p]=s(new Set),[m,h]=s(new Set),[_,v]=s(null),[y,b]=s(!1),[x,C]=s(null),{data:T,isLoading:E}=S({limit:Bt,filter:t,includeCrops:!1},{refetchInterval:3e4}),{data:D=[]}=A(),{data:O}=f({}),k=P(),N=w(),F=j(),I=M(),L=Date.now(),R=T??[],z=i(()=>{let e=new Map;for(let t of O??[])e.set(t.id,t.name);return e},[O]),H=e=>z.get(e)??`Camera #${String(e)}`,W=i(()=>ee(R).map(e=>({id:e,name:H(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[R,z]),K=i(()=>te(se(R,l),d),[R,l,d]),q=re(K,Vt,i(()=>JSON.stringify([t,l.fromMs,l.toMs,[...d].sort((e,t)=>e-t)]),[t,l.fromMs,l.toMs,d])),oe=i(()=>new Map(R.map(e=>[e.faceId,e])),[R]),ce=i(()=>ht(K),[K]),le=x===null?null:oe.get(x)??null,ue=()=>{e.invalidateQueries({queryKey:zt})},de=()=>h(new Set);function fe(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function pe(e){h(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function me(){pe(mt(K))}let Y=[...m],X=k.isPending||F.isPending||I.isPending,he=N.isPending||I.isPending;function ge(){Y.length!==0&&F.mutate({faceIds:Y},{onSettled:()=>{ue(),de()}})}function ve(){Y.length!==0&&Promise.allSettled(Y.map(e=>I.mutateAsync({faceId:e}))).then(()=>{ue(),de()})}function be(e){C(null),v([e])}function xe(e){N.mutate({faceId:e},{onSettled:ue}),C(null)}function Se(e){I.mutate({faceId:e},{onSettled:ue}),C(null)}let Ce=K.length!==R.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[c(`div`,{className:`flex items-center gap-1`,children:Ut.map(e=>c(`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))}),c(ie,{onChange:u}),c(G,{cameras:W,selected:d,onChange:p}),r(`button`,{type:`button`,onClick:()=>b(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${y?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[c(_e,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!E&&ce>0&&r(`button`,{type:`button`,onClick:me,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:[c(ne,{className:`h-3.5 w-3.5`}),` Select `,ce,` crop-less`]}),!E&&c(`span`,{className:`text-[10px] text-foreground-subtle ${ce>0?`ml-2`:`ml-auto`}`,children:Ce?`${String(K.length)} of ${String(R.length)} faces`:`${String(K.length)} face${K.length===1?``:`s`}`})]}),m.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:[m.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[r(g,{variant:`primary`,onClick:()=>v(Y),disabled:X,children:[c(V,{className:`h-3.5 w-3.5`}),` Assign`]}),r(g,{variant:`secondary`,onClick:ge,disabled:X,children:[F.isPending?c(J,{className:`h-3.5 w-3.5 animate-spin`}):c(B,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),r(g,{variant:`secondary`,onClick:ve,disabled:X,children:[c(ye,{className:`h-3.5 w-3.5`}),` Delete`]}),c(g,{variant:`ghost`,onClick:de,disabled:X,children:c(Z,{className:`h-3.5 w-3.5`})})]})]}),E&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[c(J,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!E&&K.length===0&&c(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:R.length>0?`No faces match the current date / camera filters.`:`No faces found for this filter.`}),!E&&K.length>0&&r(a,{children:[c(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(6.5rem,1fr))] gap-2`,children:q.pageItems.map(e=>c(Ht,{face:e,cameraName:H(e.deviceId),nowMs:L,selected:m.has(e.faceId),onToggleSelect:fe,onAssign:e=>v([e]),onOpenDetail:C},e.faceId))}),c(U,{currentPage:q.page,totalItems:q.totalItems,pageSize:q.pageSize,onPageChange:q.setPage,itemNoun:`faces`})]}),c(Ct,{face:le,cameraName:le?H(le.deviceId):``,onClose:()=>C(null),onAssign:be,onUnassign:xe,onDelete:Se,actionsPending:he}),c(vt,{faceIds:_,identities:D,onDone:()=>{v(null),de()}}),c(Rt,{open:y,onClose:()=>b(!1),byId:oe,cameraName:H,nowMs:L,identities:D,selectMany:pe})]})}n();var Gt=[[`faceGallery`]],Kt=2e3;function qt(){let e=o(),n=t(e);n.current=e;let r=t(void 0);r.current||=oe({delayMs:Kt,invalidate:()=>{n.current.invalidateQueries({queryKey:Gt})}}),l(()=>()=>r.current?.cancel(),[]),_(L.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function Jt(){return qt(),c(xe,{icon:ge,title:`Faces`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:r(`section`,{className:`space-y-3`,children:[r(`div`,{children:[c(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),c(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Enrolled identities used for face recognition. Expand a row to view or remove training samples.`}),c(ft,{})]}),r(`div`,{className:`pt-4 border-t border-border`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),c(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Face crops captured by the detection pipeline. Assign them to a person to build recognition training data.`}),c(Wt,{})]})]})})}export{Jt as DetectionIntelligencePage};
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,W as i,b as a,o,q as s,x as c,z as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as u}from"./player-overlays-CBKaIBph.js";import{At as d,Br as f,Dt as p,Et as m,It as h,Ls as g,Lt as _,Nt as v,Ot as y,Pt as b,ai as x,ci as S,di as C,fi as w,ii as T,kt as E,li as D,ln as O,ni as k,oi as A,pi as j,ri as M,si as N,ti as P,ui as F,wt as I}from"./src-BLHY9yig.js";import{Rt as L}from"./src-0pbBUmTo.js";import{a as R,i as z,n as B,r as V,t as H}from"./face-bbox-DUGyLE43.js";import{a as U,c as ee,f as W,i as G,l as te,m as ne,n as K,o as re,p as q,r as ie,s as ae,t as oe,u as se}from"./debounced-invalidate-B1bc5kFD.js";import{t as ce}from"./pencil-CfoKCBNv.js";import{t as le}from"./plus-DHRgxEWi.js";import{t as ue}from"./refresh-cw-CllqntzE.js";import{t as de}from"./rotate-cw-Dre2EA6E.js";import{t as fe}from"./square-check-big-Ch-X3CcM.js";import{t as pe}from"./square-DynbJcCj.js";import{t as me}from"./undo-2-CXIWJrgH.js";import{C as J,I as Y,K as X,R as he,h as ge,i as Z,l as _e,o as ve,s as ye,z as be}from"./index-LPwis6Rq.js";import{t as xe}from"./AdminPage-CCD07UMs.js";import{r as Se,t as Ce}from"./authed-media-BPd_L9jr.js";var we=X(`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`}]]),Te=X(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]);n();var Ee=`pipeline-analytics`,De=`photo.analyze`,Oe=`photo.enroll`,ke=`photo.discard`,Ae=18*1024*1024;function je(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function $(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Me(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Ne(e){if(!je(e))return null;let t=$(e,`x`),n=$(e,`y`),r=$(e,`width`),i=$(e,`height`);return t===null||n===null||r===null||i===null?null:{x:t,y:n,width:r,height:i}}function Pe(e){if(!je(e))return null;let t=$(e,`detectionShortSidePx`),n=$(e,`score`);if(t===null||n===null)return null;let r=$(e,`magnitude`);return{detectionShortSidePx:t,score:n,...r===null?{}:{magnitude:r}}}function Fe(e){if(!je(e))return null;let t=$(e,`faceIndex`),n=$(e,`score`),r=Me(e,`enrollable`),i=Ne(e.bbox),a=Pe(e.quality);if(t===null||n===null||r===null||i===null||a===null)return null;let o=Q(e,`refusedReason`),s=Q(e,`alignedCropBase64`),c=Q(e,`modelId`);return{faceIndex:t,bbox:i,score:n,enrollable:r,quality:a,...o===null?{}:{refusedReason:o},...s===null?{}:{alignedCropBase64:s},...c===null?{}:{modelId:c}}}function Ie(e){if(!je(e))return null;let t=Q(e,`sessionId`),n=Q(e,`ranOnNodeId`),r=e.faces;if(t===null||n===null||!Array.isArray(r))return null;let i=[];for(let e of r){let t=Fe(e);t!==null&&i.push(t)}return{sessionId:t,ranOnNodeId:n,faces:i}}function Le(e){if(!je(e))return null;let t=Q(e,`sampleId`),n=Q(e,`identityId`),r=Q(e,`modelId`);return t===null||n===null||r===null?null:{sampleId:t,identityId:n,modelId:r}}function Re(e,t,n){let r={...e};return n===null||n===``?delete r[t]:r[t]=n,r}function ze(e,t){return e.filter(e=>e.enrollable&&t[e.faceIndex]!==void 0).length}function Be(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 Ve(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 He(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 Ue(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 We(e,t,n){return e.map(e=>e.photoIndex===t?{...e,...n}:e)}function Ge(e,t){return`${e}:${t}`}function Ke(e,t,n,r){let i=Re(e[t]??{},n,r),a={...e};return Object.keys(i).length===0?delete a[t]:a[t]=i,a}function qe(e,t){let n=0;for(let r of e)r.analysis!==void 0&&(n+=ze(r.analysis.faces,t[r.photoIndex]??{}));return n}var Je=`__new__`;function Ye(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[Ge(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 Xe(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[Ge(e,a)]??``).trim()];s!==void 0&&(o[a]=s)}r[e]=o}return r}function Ze(e,t){let n=[];for(let r of e){if(r.analysis===void 0)continue;let e=Be(r.analysis.sessionId,r.analysis.faces,t[r.photoIndex]??{});for(let t of e)n.push({photoIndex:r.photoIndex,request:t})}return n}function Qe(e){return/expired/i.test(e)}function $e(e){return e instanceof Error?e.message:String(e)}async function et(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 Ze(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=$e(t);if(!Qe(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 (${$e(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)}: ${$e(e)}`)}}}return{enrolled:o,stampedModelId:s,failures:a,refreshedAnalyses:i}}var tt=[[`faceGallery`]],nt=``;function rt(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 it(e){return e instanceof Error?e.message:String(e)}function at({face:e,identities:t,value:n,onChange:o,disabled:s}){let l=i(()=>[{value:nt,label:`Ignore this face`},...t.map(e=>({value:e.id,label:e.name})),{value:Je,label:`+ New person…`}],[t]);return r(`div`,{className:`rounded-md border border-border bg-surface p-2`,children:[c(`div`,{className:`mb-2 aspect-square w-full overflow-hidden rounded border border-border bg-surface-hover`,children:e.alignedCropBase64?c(`img`,{src:`data:image/jpeg;base64,${e.alignedCropBase64}`,alt:`Face ${e.faceIndex+1}`,className:`h-full w-full object-cover`}):c(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:c(Te,{className:`h-8 w-8`})})}),e.enrollable?r(a,{children:[c(v,{options:l,value:n,disabled:s,onChange:e=>o(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:[c(h,{variant:`warning`,className:`text-[10px]`,children:`Not usable`}),c(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:Ve(e.refusedReason)})]})]})}function ot({photo:e,identities:t,draft:n,newNames:i,disabled:a,onAssign:o,onNameChange:s,onRetry:l}){let u=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:[c(`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:[c(J,{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:[u.length,` face`,u.length===1?``:`s`,` · analysed on`,` `,e.analysis.ranOnNodeId]}),e.status===`failed`&&r(_,{variant:`secondary`,size:`sm`,disabled:a,onClick:l,children:[c(de,{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:[c(ve,{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`&&u.length===0&&c(`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.`}),u.length>0&&c(`div`,{className:`grid grid-cols-3 gap-3 sm:grid-cols-4 md:grid-cols-5`,children:u.map(e=>c(at,{face:e,identities:t,value:d[e.faceIndex]??nt,disabled:a,onChange:t=>o(e.faceIndex,t)},e.faceIndex))}),u.filter(e=>d[e.faceIndex]===Je).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]}),c(`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[Ge(e.photoIndex,t.faceIndex)]??``,onChange:e=>s(t.faceIndex,e.target.value)})]},t.faceIndex))]})}function st({open:n,onOpenChange:a}){let l=u(),f=o(),h=t(null),{data:g}=A(),v=k(),[b,x]=s([]),[S,C]=s(!1),[w,T]=s(null),[D,O]=s({}),[j,M]=s({}),[N,P]=s(null),F=i(()=>(g??[]).map(e=>({id:e.id,name:e.name})),[g]),L=b.some(e=>e.status===`queued`||e.status===`analyzing`),R=L||S,z=e(e=>{for(let t of e){let e=t.analysis?.sessionId;e!==void 0&&l.trpcClient.addons.custom.mutate({addonId:Ee,action:ke,input:{sessionId:e}}).catch(()=>void 0)}},[l]),B=e(()=>{x([]),O({}),M({}),T(null),P(null),h.current&&(h.current.value=``)},[]),V=e(()=>{z(b),B(),a(!1)},[z,a,b,B]),H=e(async e=>{let t=Ie(await l.trpcClient.addons.custom.mutate({addonId:Ee,action:De,input:{photoBase64:e.photoBase64,filename:e.filename}}));if(t===null)throw Error(`the server replied with something this page could not read`);return t},[l]),U=e(async e=>{x(t=>We(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await H(e);x(n=>We(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){x(n=>We(n,e.photoIndex,{status:`failed`,error:it(t)}))}},[H]),ee=e(async e=>{if(e.length===0)return;z(b),B();let t=He(e,{maxCount:12,maxBytes:Ae}),n=[];t.oversize.length>0&&n.push(`Over the ${Math.round(Ae/(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&&T(n.join(` `));let r;try{r=await Promise.all(t.accepted.map(async(e,t)=>({photoIndex:t,filename:e.name,photoBase64:await rt(e),status:`queued`})))}catch(e){T(it(e));return}x(r),await Ue(r,2,e=>U(e))},[z,b,B,U]),W=qe(b,D),G=e(async()=>{C(!0),T(null),P(null);try{let e=Ye(b,D,j);if(e.kind===`error`){T(e.message);return}let t={};for(let n of e.names)t[n]=(await v.mutateAsync({name:n})).id;let n=await et(b,Xe(D,j,t),{enroll:async e=>{let t=Le(await l.trpcClient.addons.custom.mutate({addonId:Ee,action:Oe,input:e}));if(t===null)throw Error(`unreadable reply`);return t},reanalyze:e=>H(e)});Object.keys(n.refreshedAnalyses).length>0&&x(e=>e.map(e=>{let t=n.refreshedAnalyses[e.photoIndex];return t===void 0?e:{...e,status:`analyzed`,analysis:t}})),f.invalidateQueries({queryKey:tt}),n.failures.length>0&&T(n.failures.join(` · `)),P(n.enrolled===0?`Nothing was enrolled.`:`Enrolled ${n.enrolled} sample${n.enrolled===1?``:`s`}${n.stampedModelId===null?``:` with ${n.stampedModelId}`}.`)}catch(e){T(it(e))}finally{C(!1)}},[H,v,D,j,b,f,l]),te=b.filter(e=>e.status===`analyzed`).length;return c(I,{open:n,onOpenChange:e=>e?a(!0):V(),children:r(m,{className:`max-w-3xl`,children:[r(E,{children:[c(d,{children:`Enrol from photos`}),c(p,{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 `,c(`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:[c(`input`,{ref:h,type:`file`,accept:`image/jpeg,image/png,image/webp`,multiple:!0,className:`hidden`,onChange:e=>void ee(Array.from(e.target.files??[]))}),r(_,{variant:`secondary`,size:`sm`,disabled:R,onClick:()=>h.current?.click(),children:[L?c(J,{className:`h-3.5 w-3.5 animate-spin`}):c(we,{className:`h-3.5 w-3.5`}),`Choose photos`]}),b.length>0&&r(`span`,{className:`text-xs text-foreground-subtle`,children:[te,`/`,b.length,` photo`,b.length===1?``:`s`,` analysed`]})]}),w!==null&&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:[c(ve,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),c(`span`,{children:w})]}),N!==null&&c(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:N}),b.length>0&&c(`div`,{className:`max-h-[50vh] space-y-4 overflow-y-auto pr-1`,children:b.map(e=>c(ot,{photo:e,identities:F,draft:D,newNames:j,disabled:R,onAssign:(t,n)=>O(r=>Ke(r,e.photoIndex,t,n===nt?null:n)),onNameChange:(t,n)=>M(r=>({...r,[Ge(e.photoIndex,t)]:n})),onRetry:()=>void U(e)},e.photoIndex))}),r(y,{children:[c(_,{variant:`secondary`,onClick:V,disabled:S,children:`Close`}),r(_,{variant:`primary`,onClick:()=>void G(),disabled:R||W===0,children:[S?c(J,{className:`h-3.5 w-3.5 animate-spin`}):null,`Enrol `,W,` face`,W===1?``:`s`]})]})]})})}n();var ct=[[`faceGallery`]];function lt({identityId:e}){let t=o(),{data:n,isLoading:i}=N({identityId:e}),a=D();function s(n){a.mutate({identityId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:ct})}})}return i?r(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[c(J,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!n||n.length===0?c(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):c(`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?c(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):c(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:c(Te,{className:`h-6 w-6`})}),e.source===`photo`&&c(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 p-0.5 text-white`,title:`Enrolled from an uploaded photo`,children:c(we,{className:`h-3 w-3`})}),c(`button`,{type:`button`,onClick:()=>s(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:c(Z,{className:`h-4 w-4 text-white`})})]},e.id))})}function ut({identity:e,expanded:t,onToggle:n}){let i=o(),[l,u]=s(``),[f,g]=s(!1),[v,x]=s(!1),S=F(),C=T();function w(){u(e.name),g(!0)}function D(){g(!1),u(``)}function O(){let t=l.trim();if(!t||t===e.name){D();return}S.mutate({id:e.id,name:t},{onSettled:()=>{i.invalidateQueries({queryKey:ct}),D()}})}function k(){C.mutate({id:e.id},{onSettled:()=>{i.invalidateQueries({queryKey:ct}),x(!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:[c(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:e.coverBase64?c(`img`,{src:`data:image/jpeg;base64,${e.coverBase64}`,alt:e.name,className:`h-full w-full object-cover`}):c(`div`,{className:`flex h-full w-full items-center justify-center`,children:c(Te,{className:`h-4 w-4 text-foreground-subtle`})})}),c(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:f?r(a,{children:[c(b,{value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&O(),e.key===`Escape`&&D()},className:`h-6 text-xs`,autoFocus:!0}),c(`button`,{type:`button`,onClick:O,disabled:S.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:c(be,{className:`h-3.5 w-3.5`})}),c(`button`,{type:`button`,onClick:D,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:c(Z,{className:`h-3.5 w-3.5`})})]}):c(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),c(h,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!f&&r(`div`,{className:`flex items-center gap-1`,children:[c(`button`,{type:`button`,onClick:w,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:c(ce,{className:`h-3.5 w-3.5`})}),c(`button`,{type:`button`,onClick:()=>x(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:c(ye,{className:`h-3.5 w-3.5`})})]}),c(`button`,{type:`button`,onClick:n,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:c(t?he:Y,{className:`h-3.5 w-3.5`})})]}),t&&c(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:c(lt,{identityId:e.id})}),c(I,{open:v,onOpenChange:e=>!e&&x(!1),children:r(m,{children:[r(E,{children:[c(d,{children:`Delete person`}),r(p,{children:[`Delete `,c(`strong`,{children:e.name}),` and all their samples? This cannot be undone.`]})]}),r(y,{children:[c(_,{variant:`secondary`,onClick:()=>x(!1),children:`Cancel`}),r(_,{variant:`danger`,onClick:k,disabled:C.isPending,children:[C.isPending?c(J,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function dt(){let e=o(),[t,n]=s(``),i=k();function a(){let r=t.trim();r&&i.mutate({name:r},{onSettled:()=>{e.invalidateQueries({queryKey:ct}),n(``)}})}return r(`div`,{className:`flex items-center gap-2 pt-2`,children:[c(b,{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(_,{variant:`primary`,size:`sm`,onClick:a,disabled:i.isPending||!t.trim(),children:[i.isPending?c(J,{className:`h-3.5 w-3.5 animate-spin`}):c(le,{className:`h-3.5 w-3.5`}),`Add`]})]})}function ft(){let{data:e,isLoading:t}=A(),[n,i]=s(null),[a,o]=s(!1);function l(e){i(t=>t===e?null:e)}return t?r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[c(J,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):r(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&c(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),e?.map(e=>c(ut,{identity:e,expanded:n===e.id,onToggle:()=>l(e.id)},e.id)),c(dt,{}),c(`div`,{className:`pt-1`,children:r(_,{variant:`secondary`,size:`sm`,onClick:()=>o(!0),children:[c(we,{className:`h-3.5 w-3.5`}),`Enrol from a photo`]})}),c(st,{open:a,onOpenChange:o})]})}function pt(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function mt(e){return e.filter(pt).map(e=>e.faceId)}function ht(e){let t=0;for(let n of e)pt(n)&&(t+=1);return t}function gt(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 _t=[[`faceGallery`]];function vt({faceIds:e,identities:t,onDone:n}){let i=o(),a=P(),l=k(),[u,f]=s(``),[h,g]=s(!1),[v,x]=s(null),S=e!==null&&e.length>0,C=e?.length??0;function w(){g(!1),f(``),x(null)}function T(){w(),n()}function D(t){!e||e.length===0||a.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{i.invalidateQueries({queryKey:_t}),T()}})}function O(){!e||!u.trim()||l.mutate({name:u.trim()},{onSuccess:e=>{e?.id&&D(e.id)},onError:()=>{i.invalidateQueries({queryKey:_t}),T()}})}let A=a.isPending||l.isPending;return c(I,{open:S,onOpenChange:e=>!e&&T(),children:r(m,{children:[r(E,{children:[c(d,{children:C>1?`Assign ${String(C)} faces to person`:`Assign face to person`}),c(p,{children:`Select an existing person or create a new one.`})]}),c(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>r(`button`,{type:`button`,onClick:()=>x(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${v===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[c(`span`,{className:`font-medium`,children:e.name}),r(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),h?c(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:c(b,{placeholder:`New person name…`,value:u,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&O()},autoFocus:!0,className:`flex-1`})}):c(`button`,{type:`button`,onClick:()=>{x(null),g(!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 person…`}),r(y,{children:[c(_,{variant:`secondary`,onClick:T,disabled:A,children:`Cancel`}),h?r(_,{variant:`primary`,onClick:O,disabled:A||!u.trim(),children:[A&&c(J,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):r(_,{variant:`primary`,onClick:()=>v&&D(v),disabled:A||!v,children:[A&&c(J,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,C>1?` ${String(C)}`:``]})]})]})})}n();function yt(e){let[t,n]=s(null),[r,i]=s(null),[a,o]=s(!1);return l(()=>{if(n(null),i(null),o(!1),!e)return;let t=!1,r=null;return(async()=>{try{let i=await Se(`${Ce}/${encodeURIComponent(e)}`);if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),l(()=>{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 bt(e){let t=e.filter(e=>e.base64.length>0);return t.length===0?null:t.find(e=>/crop|face/i.test(e.kind))??t[0]}function xt({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:[c(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),c(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:t})]})}function St({box:e}){return c(`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:c(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Face`})})}function Ct({face:e,cameraName:t,onClose:n,onAssign:a,onUnassign:o,onDelete:l,actionsPending:u}){let{data:d,isFetching:f}=x({faceId:e?.faceId??``},{enabled:e!==null}),[p,h]=s(`frame`),{frameSrc:g,naturalWidth:v,naturalHeight:y,failed:b}=yt(e?.keyFrameMediaKey),S=i(()=>{let t=bt(d??[]);return t?`data:image/jpeg;base64,${t.base64}`:gt(e)},[d,e]),C=i(()=>!e?.faceBbox||v===null||y===null?null:H(e.faceBbox,v,y),[e?.faceBbox,v,y]);if(e===null)return null;let w=typeof e.keyFrameMediaKey==`string`&&e.keyFrameMediaKey.length>0&&!b,T=w&&p===`frame`,E=e.assigned?e.identityName??`Assigned`:e.recognizedIdentityId?`${e.identityName??`Recognized`} (suggested)`:`Unassigned`;return c(I,{open:!0,onOpenChange:e=>!e&&n(),children:r(m,{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:[r(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`min-w-0`,children:[c(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:`Face detail`}),c(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),c(`button`,{type:`button`,onClick:n,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:c(Z,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[w&&r(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[r(`button`,{type:`button`,onClick:()=>h(`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:[c(z,{className:`h-3.5 w-3.5`}),` Full frame`]}),r(`button`,{type:`button`,onClick:()=>h(`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:[c(R,{className:`h-3.5 w-3.5`}),` Crop`]})]}),T&&g?c(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:c(K,{src:g,alt:`Full frame with detected face`,fit:`natural`,className:`w-full`,overlay:C?c(St,{box:C}):void 0})}):S?r(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[c(K,{src:S,alt:`Detected face`,className:`h-full w-full`}),f&&c(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:c(J,{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:[c(ne,{className:`h-8 w-8 text-warning/70`}),c(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),c(`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:[c(xt,{label:`Camera`,value:t}),c(xt,{label:`Captured`,value:q(e.timestamp)}),c(xt,{label:`Track`,value:e.trackId}),c(xt,{label:`Identity`,value:E})]})]}),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(_,{variant:`secondary`,onClick:()=>o(e.faceId),disabled:u,children:[c(B,{className:`h-3.5 w-3.5`}),` Detach`]}):r(_,{variant:`primary`,onClick:()=>a(e.faceId),disabled:u,children:[c(V,{className:`h-3.5 w-3.5`}),` Assign`]}),r(_,{variant:`secondary`,onClick:()=>l(e.faceId),disabled:u,children:[c(ye,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}function wt(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function Tt(e,t){return e.faceIds.filter(e=>!t.has(e))}function Et(e,t){return e.faceIds.filter(e=>t(e))}n();var Dt=[[`faceGallery`]],Ot=20,kt=.3,At=.9,jt=.05,Mt=.5,Nt=2,Pt=10,Ft=2;function It({cluster:e,face:t,active:n,onSelect:i}){let a=gt(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:[c(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:a===null?c(ne,{className:`h-24 w-24 p-6 text-foreground-subtle`}):c(`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 Lt({face:e,cameraName:t,nowMs:n,excluded:i,onToggleExclude:a,onDelete:o,deletePending:s}){let l=gt(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:[l===null?r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[c(ne,{className:`h-7 w-7 text-warning/70`}),c(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):c(K,{src:l,alt:`Face from ${t}`,className:`h-full w-full`}),c(`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:c(i?me:Z,{className:`h-3.5 w-3.5`})})]}),r(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[c(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),c(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:W(e.timestamp,n)})]}),c(`div`,{className:`mt-1 flex items-center justify-end border-t border-border/60 px-1 py-0.5`,children:c(`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?c(J,{className:`h-4 w-4 animate-spin`}):c(ye,{className:`h-4 w-4`})})})]})}function Rt({open:e,onClose:t,byId:n,cameraName:u,nowMs:d,identities:f,selectMany:p}){let h=o(),g=O(),v=M(),[y,b]=s(Mt),[x,S]=s(Ft),[w,T]=s(null),[E,D]=s({}),[k,A]=s(null),{data:j,isFetching:N,refetch:P}=C({threshold:y,minClusterSize:x,limit:Ot},{enabled:e}),F=j??[];l(()=>{D({})},[y,x]),l(()=>{if(F.length===0){T(null);return}F.some(e=>e.representativeFaceId===w)||T(F[0]?.representativeFaceId??null)},[F]);let L=i(()=>F.find(e=>e.representativeFaceId===w)??null,[F,w]),R=L?E[L.representativeFaceId]??new Set:new Set,z=i(()=>L?Et(L,e=>n.has(e)):[],[L,n]),B=L?L.faceIds.length-z.length:0,H=L?Tt({...L,faceIds:z},R):[];function U(e){if(!L)return;let t=L.representativeFaceId;D(n=>({...n,[t]:wt(n[t]??new Set,e)}))}function ee(){h.invalidateQueries({queryKey:Dt})}async function W(e){await g({title:`Delete face`,message:`Permanently deletes this face crop. This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&v.mutate({faceId:e},{onSettled:ee})}function G(){A(null),t()}function te(){H.length!==0&&(p(H),G())}return r(I,{open:e,onOpenChange:e=>!e&&G(),children:[r(m,{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 px-4 py-3`,children:[r(`div`,{className:`flex items-center justify-between gap-2`,children:[r(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[c(_e,{className:`h-4 w-4 text-primary`}),` Look-alike groups`]}),c(`button`,{type:`button`,onClick:G,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:c(Z,{className:`h-4 w-4`})})]}),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`,c(`input`,{type:`range`,min:kt,max:At,step:jt,value:y,onChange:e=>b(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),c(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:y.toFixed(2)})]}),r(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Min size`,c(`input`,{type:`number`,min:Nt,max:Pt,step:1,value:x,onChange:e=>S(Math.min(Pt,Math.max(Nt,Number(e.target.value)||Nt))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),r(_,{variant:`secondary`,onClick:()=>{D({}),P()},disabled:N,children:[N?c(J,{className:`h-3.5 w-3.5 animate-spin`}):c(ue,{className:`h-3.5 w-3.5`}),`Re-analyze`]})]})]}),c(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:N&&F.length===0?r(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[c(J,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):F.length===0?c(`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(a,{children:[c(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:F.map(e=>c(It,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===w,onSelect:()=>T(e.representativeFaceId)},e.representativeFaceId))}),c(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:F.map(e=>c(It,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===w,onSelect:()=>T(e.representativeFaceId)},e.representativeFaceId))}),c(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:L&&r(a,{children:[B>0&&r(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:[B,` not loaded — excluded from actions`]}),c(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,1fr))] gap-2`,children:z.map(e=>{let t=n.get(e);return t?c(Lt,{face:t,cameraName:u(t.deviceId),nowMs:d,excluded:R.has(e),onToggleExclude:()=>U(e),onDelete:()=>void W(e),deletePending:v.isPending&&v.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:[c(_,{variant:`secondary`,onClick:te,disabled:H.length===0,children:`Select in gallery`}),r(_,{variant:`primary`,onClick:()=>A(H),disabled:H.length===0,children:[c(V,{className:`h-3.5 w-3.5`}),` Adopt (`,H.length,`)`]})]})]}),c(vt,{faceIds:k,identities:f,onDone:()=>A(null)})]})}n();var zt=[[`faceGallery`]],Bt=500,Vt=120;function Ht({face:e,cameraName:t,nowMs:n,selected:i,onToggleSelect:a,onAssign:s,onOpenDetail:l}){let u=o(),d=w(),f=M(),p=()=>{u.invalidateQueries({queryKey:zt})},m=()=>l(e.faceId),h=gt(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:[c(ne,{className:`h-7 w-7 text-warning/70`}),c(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):c(`img`,{src:h,alt:`Face from ${t}`,onClick:m,loading:`lazy`,decoding:`async`,className:`h-full w-full cursor-zoom-in object-cover`}),c(`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?c(fe,{className:`h-4 w-4 text-primary`}):c(pe,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[c(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),c(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:W(e.timestamp,n)}),e.identityName&&c(`p`,{className:`text-[10px] font-medium text-primary truncate`,title:e.identityName,children:e.identityName})]}),r(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?c(`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?c(J,{className:`h-4 w-4 animate-spin`}):c(B,{className:`h-4 w-4`})}):c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(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:c(V,{className:`h-4 w-4`})}),c(`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?c(J,{className:`h-4 w-4 animate-spin`}):c(ye,{className:`h-4 w-4`})})]})]})}var Ut=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function Wt(){let e=o(),[t,n]=s(`all`),[l,u]=s(ae),[d,p]=s(new Set),[m,h]=s(new Set),[g,v]=s(null),[y,b]=s(!1),[x,C]=s(null),{data:T,isLoading:E}=S({limit:Bt,filter:t,includeCrops:!1},{refetchInterval:3e4}),{data:D=[]}=A(),{data:O}=f({}),k=P(),N=w(),F=j(),I=M(),L=Date.now(),R=T??[],z=i(()=>{let e=new Map;for(let t of O??[])e.set(t.id,t.name);return e},[O]),H=e=>z.get(e)??`Camera #${String(e)}`,W=i(()=>ee(R).map(e=>({id:e,name:H(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[R,z]),K=i(()=>te(se(R,l),d),[R,l,d]),q=re(K,Vt,i(()=>JSON.stringify([t,l.fromMs,l.toMs,[...d].sort((e,t)=>e-t)]),[t,l.fromMs,l.toMs,d])),oe=i(()=>new Map(R.map(e=>[e.faceId,e])),[R]),ce=i(()=>ht(K),[K]),le=x===null?null:oe.get(x)??null,ue=()=>{e.invalidateQueries({queryKey:zt})},de=()=>h(new Set);function fe(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function pe(e){h(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function me(){pe(mt(K))}let Y=[...m],X=k.isPending||F.isPending||I.isPending,he=N.isPending||I.isPending;function ge(){Y.length!==0&&F.mutate({faceIds:Y},{onSettled:()=>{ue(),de()}})}function ve(){Y.length!==0&&Promise.allSettled(Y.map(e=>I.mutateAsync({faceId:e}))).then(()=>{ue(),de()})}function be(e){C(null),v([e])}function xe(e){N.mutate({faceId:e},{onSettled:ue}),C(null)}function Se(e){I.mutate({faceId:e},{onSettled:ue}),C(null)}let Ce=K.length!==R.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[c(`div`,{className:`flex items-center gap-1`,children:Ut.map(e=>c(`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))}),c(ie,{onChange:u}),c(G,{cameras:W,selected:d,onChange:p}),r(`button`,{type:`button`,onClick:()=>b(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${y?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[c(_e,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!E&&ce>0&&r(`button`,{type:`button`,onClick:me,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:[c(ne,{className:`h-3.5 w-3.5`}),` Select `,ce,` crop-less`]}),!E&&c(`span`,{className:`text-[10px] text-foreground-subtle ${ce>0?`ml-2`:`ml-auto`}`,children:Ce?`${String(K.length)} of ${String(R.length)} faces`:`${String(K.length)} face${K.length===1?``:`s`}`})]}),m.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:[m.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[r(_,{variant:`primary`,onClick:()=>v(Y),disabled:X,children:[c(V,{className:`h-3.5 w-3.5`}),` Assign`]}),r(_,{variant:`secondary`,onClick:ge,disabled:X,children:[F.isPending?c(J,{className:`h-3.5 w-3.5 animate-spin`}):c(B,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),r(_,{variant:`secondary`,onClick:ve,disabled:X,children:[c(ye,{className:`h-3.5 w-3.5`}),` Delete`]}),c(_,{variant:`ghost`,onClick:de,disabled:X,children:c(Z,{className:`h-3.5 w-3.5`})})]})]}),E&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[c(J,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!E&&K.length===0&&c(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:R.length>0?`No faces match the current date / camera filters.`:`No faces found for this filter.`}),!E&&K.length>0&&r(a,{children:[c(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(6.5rem,1fr))] gap-2`,children:q.pageItems.map(e=>c(Ht,{face:e,cameraName:H(e.deviceId),nowMs:L,selected:m.has(e.faceId),onToggleSelect:fe,onAssign:e=>v([e]),onOpenDetail:C},e.faceId))}),c(U,{currentPage:q.page,totalItems:q.totalItems,pageSize:q.pageSize,onPageChange:q.setPage,itemNoun:`faces`})]}),c(Ct,{face:le,cameraName:le?H(le.deviceId):``,onClose:()=>C(null),onAssign:be,onUnassign:xe,onDelete:Se,actionsPending:he}),c(vt,{faceIds:g,identities:D,onDone:()=>{v(null),de()}}),c(Rt,{open:y,onClose:()=>b(!1),byId:oe,cameraName:H,nowMs:L,identities:D,selectMany:pe})]})}n();var Gt=[[`faceGallery`]],Kt=2e3;function qt(){let e=o(),n=t(e);n.current=e;let r=t(void 0);r.current||=oe({delayMs:Kt,invalidate:()=>{n.current.invalidateQueries({queryKey:Gt})}}),l(()=>()=>r.current?.cancel(),[]),g(L.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function Jt(){return qt(),c(xe,{icon:ge,title:`Faces`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:r(`section`,{className:`space-y-3`,children:[r(`div`,{children:[c(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),c(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Enrolled identities used for face recognition. Expand a row to view or remove training samples.`}),c(ft,{})]}),r(`div`,{className:`pt-4 border-t border-border`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),c(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Face crops captured by the detection pipeline. Assign them to a person to build recognition training data.`}),c(Wt,{})]})]})})}export{Jt as DetectionIntelligencePage};
|
package/dist/assets/{DeviceAggregateSection-DLNzCtMs.js → DeviceAggregateSection-r5_ljoI1.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,o as a,q as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{$r as c,Ir as l,
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,W as i,o as a,q as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{$r as c,Ir as l,Kr as u,Lr as d,Qo as f,Zo as p,ei as m}from"./src-BLHY9yig.js";import{Mt as h}from"./src-0pbBUmTo.js";import{t as g}from"./FormBuilder-QY4tah4S.js";import{C as _,r as v}from"./index-LPwis6Rq.js";import{n as y,r as b,t as x}from"./SchemaTabBar-DC28nb9j.js";import{t as S}from"./StableTabPanel-Dc954AQl.js";n();function C({schema:e,values:t,pendingKeys:n,onChange:a,onAction:c,onSave:l,onDiscard:u,disabled:d,activeSubTab:f,onSubTabChange:p,flattenTabs:m=!1,deviceId:h}){let _=e.tabs??[],v=i(()=>{let t=new Map;for(let n of e.sections){let e=n.tab??`general`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t},[e.sections]),b=new Set(_.map(e=>e.id)),C=[..._,...[...v.keys()].filter(e=>!b.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],w=C[0]?.id??`general`,[T,E]=o(w),D=p!==void 0,O=new Set(C.map(e=>e.id)),k=D?f&&O.has(f)?f:w:O.has(T)?T:w,A=e=>{D?p(e):E(e)},j=v.get(k)??[],M={sections:j.length<=1?j.length===1?[{...j[0],title:``}]:j:j.every(e=>!e.title)?[{...j[0],title:``,fields:j.flatMap(e=>e.fields)}]:j},N=s(y,{pendingCount:n.length,onSave:()=>l(n),onDiscard:()=>u(n),saving:d});if(m||C.length<=1)return r(`div`,{className:`flex flex-col gap-3`,children:[s(g,{schema:e,values:t,onChange:a,onAction:c,disabled:d,deviceId:h}),N]});let P=new Map,F=new Map;for(let[e,t]of v){P.set(e,t.length);let r=new Set,i=e=>{for(let t of e)if(`key`in t&&typeof t.key==`string`&&r.add(t.key),t.type===`group`)i(t.fields);else if(t.type===`sub-tabs`)for(let e of t.tabs)i(e.fields)};for(let e of t)i(e.fields);let a=n.filter(e=>r.has(e)).length;a>0&&F.set(e,a)}return r(`div`,{className:`flex flex-col gap-3`,children:[s(x,{tabs:C.map(e=>({id:e.id,label:e.label})),activeId:k,onChange:A,countByTab:P,pendingByTab:F}),s(S,{tabKey:k,children:s(g,{schema:M,values:t,onChange:a,onAction:c,disabled:d,deviceId:h})}),N]})}var w=`device-export`,T=`export`,E=`Export`;function D(e){return e.type===`separator`||e.type===`info`||e.type===`object-array`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`?!1:e.type===`group`?e.fields.some(D):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(D)):e.writerCapName===w}function O(e){return e.tab===`export`?!0:e.fields.some(D)}n();function k(e,t){return t&&t===`admin`?e:!0}function A(e){if(!e)return null;let t={sections:[...e.sections].toSorted((e,t)=>{let n=e.tab??`general`,r=t.tab??`general`;return n===r?O(e)&&O(t)?e.id.localeCompare(t.id):(e.order??0)-(t.order??0):n.localeCompare(r)})};return e.tabs?{...t,tabs:e.tabs}:t}function j(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`}function M(e){return e.key}function N(e){if(!j(e))return e.value}function P(e){return j(e)?null:e}function F(e,t){for(let n of e)if(t(n),n.type===`group`)F(n.fields,t);else if(n.type===`sub-tabs`)for(let e of n.tabs)F(e.fields,t)}function I(e){if(!e)return{};let t={};for(let n of e.sections)F(n.fields,e=>{let n=M(e);n!==null&&(t[n]=N(e))});return t}function L(e,t){if(!e)return null;let n=null;for(let r of e.sections)if(F(r.fields,e=>{if(n!==null||M(e)!==t)return;let r=P(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function R(e){return{...e,fields:e.fields.map(z)}}function z(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function B(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=P(e);return n?k(t,n.minRole)?e:z(e):e})}))}}function V({deviceId:n,sectionFilter:o,activeSubTab:g,onSubTabChange:y,flattenSubTabs:x,subTabGrouping:S}){let w=a(),{user:T}=v(),E=T?.isAdmin===!0,D=t(!1),{data:k,isLoading:j}=d({deviceId:n},{refetchInterval:()=>D.current?!1:2500,enabled:Number.isFinite(n)}),{data:M}=l({deviceId:n},{enabled:Number.isFinite(n)}),N=k?.settings??null,P=k?.live??null,F=i(()=>{if(!N&&!P)return null;let e=N?.sections??[],t=(P?.sections??[]).map(R),n=[...e,...t],r=o?n.filter(o):n.filter(e=>e.location!==`top-tab`&&!O(e));if(r.length===0)return null;if(S){let e=r.map(e=>({...e,tab:S.groupOf(e)})),t=new Set(e.map(e=>e.tab)),n=S.tabs.filter(e=>t.has(e.id));return n.length>0?{tabs:n,sections:e}:{sections:e}}let i=new Set;for(let e of r)i.add(e.tab??`general`);let a=[...N?.tabs??[],...(P?.tabs??[]).filter(e=>!(N?.tabs??[]).some(t=>t.id===e.id))].filter(e=>i.has(e.id));return a.length>0?{tabs:a,sections:r}:{sections:r}},[N,P,o,S]),z=i(()=>A(F),[F]),V=i(()=>B(z,E),[z,E]),H=i(()=>I(V),[V]),U=f(),W=p(),G=c(),K=u(),q=m({onSuccess:()=>{w.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),J={isPending:q.isPending,mutate:e=>{q.mutate({deviceId:n,changes:[...e]})}},Y=b({schema:V,serverValues:H,onImmediateSave:e(e=>{let t=Object.entries(e).map(([e,t])=>{let n=L(V,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&J.mutate(t)},[V,J]),onDeferredSave:e(e=>{let t=Object.entries(e).map(([e,t])=>{let n=L(V,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&J.mutate(t)},[V,J])}),{values:X,pendingKeys:Z,handleChange:Q,handleSave:$,handleDiscard:ee}=Y;if(D.current=Y.editingPaused,j)return r(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[s(_,{className:`h-4 w-4 animate-spin mr-2`}),s(`span`,{className:`text-xs`,children:`Loading device aggregate…`})]});if(!V||V.sections.length===0)return s(`div`,{className:`text-xs text-foreground-subtle italic py-4 text-center`,children:`No aggregate contributions for this device.`});async function te(e,t,r){if(e===`regenerate-rtsp-token`){let e=[`rtspUrl:`,`regenerateToken:`].find(e=>t.startsWith(e));if(!e)throw Error(`regenerate-rtsp-token: unrecognised key "${t}" (expected "rtspUrl:<streamId>" or "regenerateToken:<streamId>")`);let r=t.slice(e.length);if(!r)throw Error(`regenerate-rtsp-token: key "${t}" has no streamId after prefix`);let i=h(n,r);await U.mutateAsync({brokerId:i}),w.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(e===`test-probe`){if(!M)return{status:`error`,error:`Device metadata not loaded yet`};try{return await G.mutateAsync({addonId:M.addonId,type:M.type,key:t,value:r})}catch(e){return{status:`error`,error:e instanceof Error?e.message:String(e)}}}if(e===`refresh-probe`){if(!t.startsWith(`probedInfo:`))throw Error(`refresh-probe: unrecognised key "${t}" (expected "probedInfo:<streamId>")`);let e=t.slice(11);if(!e)throw Error(`refresh-probe: key "${t}" has no streamId after prefix`);let r=h(n,e),i=await W.mutateAsync({brokerId:r});return w.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),i}if(e===`device-custom-action`){let e=await K.mutateAsync({deviceId:n,action:t,input:r});return w.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),e}throw Error(`[device-aggregate] unknown action "${e}"`)}return s(C,{schema:V,values:X,pendingKeys:Z,onChange:Q,onAction:te,onSave:$,onDiscard:ee,disabled:J.isPending,activeSubTab:g,onSubTabChange:y,flattenTabs:x,deviceId:n})}export{O as i,T as n,E as r,V as t};
|