@camstack/addon-admin-ui 1.1.52 → 1.1.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/dist/assets/{AddLocationWizard-Uf0yJnjR.js → AddLocationWizard-B2-uyYmP.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-DqaY4er4.js → AddonCollectionPage-FU3E6QGz.js} +1 -1
  3. package/dist/assets/Addons-DU5z1ZvU.js +1 -0
  4. package/dist/assets/{AdminTabs-BbJVdoRX.js → AdminTabs-CICieyaN.js} +1 -1
  5. package/dist/assets/AiProfiles-BRTUYeoH.js +1 -0
  6. package/dist/assets/{BrokerForm-u3y0YqZe.js → BrokerForm-CuIg_iOf.js} +1 -1
  7. package/dist/assets/{Capabilities-CMfsYieK.js → Capabilities-CEZc9Dcc.js} +1 -1
  8. package/dist/assets/{CapabilityBadges-Ribk0vnA.js → CapabilityBadges-DDSnGBgk.js} +1 -1
  9. package/dist/assets/Cluster-DjZVaBCZ.js +1 -0
  10. package/dist/assets/{Dashboard-qRfzfjPv.js → Dashboard-CLWVhKF4.js} +1 -1
  11. package/dist/assets/{Data-DHhlstKQ.js → Data-aqRyEVJp.js} +1 -1
  12. package/dist/assets/{DetectionIntelligence-DV-yQXDw.js → DetectionIntelligence-Bvw_e-lH.js} +1 -1
  13. package/dist/assets/{DeviceDetail-DHrSmXXI.js → DeviceDetail-Bt08IJis.js} +2 -2
  14. package/dist/assets/{Devices-SsSi-4nJ.js → Devices-CZ_Moh5w.js} +1 -1
  15. package/dist/assets/{EmbedPlayerPage-CzcNBQ3L.js → EmbedPlayerPage-DAeQe0Bf.js} +1 -1
  16. package/dist/assets/{Events-C0-Ts8gr.js → Events-OajEJc_n.js} +1 -1
  17. package/dist/assets/{FormBuilder-BsMr0Lyl.js → FormBuilder-B69YBaq9.js} +1 -1
  18. package/dist/assets/Identity-DWgcf-tI.js +1 -0
  19. package/dist/assets/IntegrationDetail-BOTeJU5I.js +1 -0
  20. package/dist/assets/{Integrations-Cab4Dh8j.js → Integrations-CMT2Jroo.js} +1 -1
  21. package/dist/assets/{Integrations-DZAnOMWG.js → Integrations-nY6HlQUf.js} +1 -1
  22. package/dist/assets/{Logs-DxdTei3J.js → Logs-BTWVO572.js} +1 -1
  23. package/dist/assets/{MotionZonesSettings-Dk5S6Yey.js → MotionZonesSettings-BWhNWsPJ.js} +1 -1
  24. package/dist/assets/{MyAccess-DnZwl6il.js → MyAccess-CJLeYWfN.js} +1 -1
  25. package/dist/assets/Network-DTQVXNuu.js +1 -0
  26. package/dist/assets/{NodeAddonsSettingsPanel-CJbUr7pj.js → NodeAddonsSettingsPanel-BQWXa7vq.js} +1 -1
  27. package/dist/assets/{NotificationTargets-ZY0oUqQy.js → NotificationTargets-DqrqQvJN.js} +1 -1
  28. package/dist/assets/Pipeline-BZPrco_d.js +1 -0
  29. package/dist/assets/{Plates-CpuUTsMF.js → Plates-Cy7kPDK4.js} +1 -1
  30. package/dist/assets/{PrivacyMaskSettings-CsjSf0ui.js → PrivacyMaskSettings-DTEI02Vz.js} +1 -1
  31. package/dist/assets/ProviderIcon-Ba4DQXPs.js +1 -0
  32. package/dist/assets/ScanNetworkModal-CbDd4Bl9.js +1 -0
  33. package/dist/assets/{Settings-Cg40p72B.js → Settings-BxK0kuED.js} +1 -1
  34. package/dist/assets/{Showroom-WqyHrFZ8.js → Showroom-BLBcs7XJ.js} +1 -1
  35. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-mb1uqJnX.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-jFLPXlhw.js} +1 -1
  36. package/dist/assets/{build-cluster-graph-CWEgvPHm.js → build-cluster-graph-CIiqGgZL.js} +1 -1
  37. package/dist/assets/circle-check-big-B-tT2CHM.js +1 -0
  38. package/dist/assets/clock-cwKSxYZs.js +1 -0
  39. package/dist/assets/{copy-uF3P0mCb.js → copy-CTAQpm07.js} +1 -1
  40. package/dist/assets/{debounced-invalidate-CmrI3MX6.js → debounced-invalidate-DZ3oxQDl.js} +1 -1
  41. package/dist/assets/{dist-BIF_0i8X.js → dist-BMrXztkM.js} +1 -1
  42. package/dist/assets/{dist-B39mAyWB.js → dist-tu4iBgMD.js} +2 -2
  43. package/dist/assets/{download-C6gtaH_N.js → download-DjYX33pK.js} +1 -1
  44. package/dist/assets/{face-bbox-C6BZci_u.js → face-bbox-vlSxiLet.js} +1 -1
  45. package/dist/assets/{film-Ce3Puhhw.js → film-lIXZ0TIf.js} +1 -1
  46. package/dist/assets/{hostInit-fNwBYqHp.js → hostInit-BhKkSxQn.js} +1 -1
  47. package/dist/assets/index-Cdp6OaKK.js +4 -0
  48. package/dist/assets/{index-CQGeAf4R.css → index-Cmln2hC6.css} +1 -1
  49. package/dist/assets/{key-round-CTt4GMO-.js → key-round-D6koQlXg.js} +1 -1
  50. package/dist/assets/{mf-entry-bootstrap-0-13957685.js → mf-entry-bootstrap-0-1af432ca.js} +2 -2
  51. package/dist/assets/{pencil-B2rRCbs4.js → pencil-CUVzuL3L.js} +1 -1
  52. package/dist/assets/{player-overlays-G3UGtBzC.js → player-overlays-BrjDKJA9.js} +1 -1
  53. package/dist/assets/plus-CTLCXGgQ.js +1 -0
  54. package/dist/assets/{radio-D3U_70dZ.js → radio-_KFBV9h-.js} +1 -1
  55. package/dist/assets/{refresh-cw-NUBl_9F6.js → refresh-cw-BM18Lfvw.js} +1 -1
  56. package/dist/assets/remoteEntry-xwnWPwER.js +1 -0
  57. package/dist/assets/{rotate-ccw-C9aSKyTE.js → rotate-ccw-EdLXWeWN.js} +1 -1
  58. package/dist/assets/rotate-cw-CE0Ns6Fz.js +1 -0
  59. package/dist/assets/search-mDjJzMoX.js +1 -0
  60. package/dist/assets/{send-Cjr4zHvT.js → send-C5a5_8YJ.js} +1 -1
  61. package/dist/assets/server-CTi1sPfP.js +1 -0
  62. package/dist/assets/square-CfQwX-85.js +1 -0
  63. package/dist/assets/{square-check-big-CSjE0FM_.js → square-check-big-DqE0lyuf.js} +1 -1
  64. package/dist/assets/{src-DJCxIXmd.js → src-BIAY4cjr.js} +1 -1
  65. package/dist/assets/src-Bx1PCCWV.js +67 -0
  66. package/dist/assets/{upload-DY7S1CIX.js → upload-CBvWlRd4.js} +1 -1
  67. package/dist/assets/{useDevice-Ch_9qauD.js → useDevice-CRWDjGkB.js} +1 -1
  68. package/dist/assets/{useEventInvalidation-h9LIsvjv.js → useEventInvalidation-BgQYjLEl.js} +1 -1
  69. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CPN4r1AG.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BzCJlGIx.js} +2 -2
  70. package/dist/assets/{wifi-0f3nqfEf.js → wifi-D9LNVG6Y.js} +1 -1
  71. package/dist/assets/{zap-BZHvm4pV.js → zap-CjGIHi-s.js} +1 -1
  72. package/dist/index.html +6 -6
  73. package/dist/server/addon.js +4648 -4640
  74. package/package.json +1 -1
  75. package/dist/assets/Addons-an5qhtPG.js +0 -1
  76. package/dist/assets/AiProfiles-DdWPLcwR.js +0 -1
  77. package/dist/assets/Cluster-CYnROh4T.js +0 -1
  78. package/dist/assets/Identity-eIowJSpV.js +0 -1
  79. package/dist/assets/IntegrationDetail-B8wj47uz.js +0 -1
  80. package/dist/assets/Network-dhnXr-jY.js +0 -1
  81. package/dist/assets/Pipeline-DaPp8qeN.js +0 -1
  82. package/dist/assets/ProviderIcon-BSvVPouG.js +0 -1
  83. package/dist/assets/ScanNetworkModal-ByX1qWEM.js +0 -1
  84. package/dist/assets/ServerManagement-BtFGaYJa.js +0 -1
  85. package/dist/assets/circle-check-big-DVa9F7JF.js +0 -1
  86. package/dist/assets/clock-CuFB6vbo.js +0 -1
  87. package/dist/assets/index-BXAOUGFx.js +0 -4
  88. package/dist/assets/plus-DIHRelRK.js +0 -1
  89. package/dist/assets/remoteEntry-tIxTqhi3.js +0 -1
  90. package/dist/assets/rotate-cw-CWQEKQOp.js +0 -1
  91. package/dist/assets/search-CNcDC4RH.js +0 -1
  92. package/dist/assets/square-DCFTa1lw.js +0 -1
  93. package/dist/assets/src-C9tUE6VN.js +0 -67
@@ -1 +1 @@
1
- import{Bt as e,Da as t,Gt as n,Ht as r,Ji as i,Kt as a,Ut as o,Vt as s,Wt as c,Yi as l,Zi as u,qi as d,qt as f,wt as p,xa as m,zt as h}from"./src-C9tUE6VN.js";import{I as g,Q as _,S as v,W as y,b,o as x,q as S,x as C,z as w}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{R as T}from"./src-DJCxIXmd.js";import{t as E}from"./download-C6gtaH_N.js";import{i as D,n as O,r as k,t as A}from"./AddLocationWizard-Uf0yJnjR.js";import{t as j}from"./plus-DIHRelRK.js";import{t as M}from"./rotate-cw-CWQEKQOp.js";import{C as N,H as ee,I as P,P as F,W as I,i as L,s as R}from"./index-BXAOUGFx.js";import{t as z}from"./AdminPage-BwmGKnRf.js";import{n as te}from"./authed-media-XfBD4Ma-.js";import{t as B}from"./format-size-CO9d3C3-.js";import{t as V}from"./AdminTabs-BbJVdoRX.js";var H=I(`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`}]]),ne=I(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),U=I(`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`}]]);_();function W(){let e=x(),t=m(),{data:n,isLoading:r,isError:a}=l({}),o=i(),s=y(()=>o.data??[],[o.data]),[c,f]=S(null),[p,h]=S(null),g=d({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),_=u({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),b=e=>{e.isDefault||_.mutate({id:e.id,type:e.type,providerId:e.providerId,displayName:e.displayName,config:e.config,isDefault:!0})},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`})&&g.mutate({id:e.id})},T=y(()=>{let e=new Map;for(let t of n??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[n]),E=r||o.isLoading,D=a||o.isError;return v(z,{children:[E&&C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),D&&C(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!E&&!D&&v(`div`,{className:`space-y-3`,children:[s.length===0&&C(`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.`}),s.map(e=>C(k,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:T.get(e.id)??[],onAdd:e=>f(e),onEdit:e=>h(e),onDelete:e=>{w(e)},onSetDefault:e=>b(e)},e.id))]}),c!==null&&C(A,{initialType:c,onClose:()=>f(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),f(null)}}),p!==null&&C(O,{location:p,onClose:()=>h(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),h(null)}})]})}_();var G=[[`backup`,`listDestinations`]],K=[`backup`,`listArchives`];function q({destinationId:e,restoreSupported:t,onOpenRestoreWizard:n}){let r=x(),i=m(),{data:a,isLoading:o,isError:c}=s({destinationId:e}),l=a??[],u=h({onSuccess:()=>{r.invalidateQueries({queryKey:[[...K]]}),r.invalidateQueries({queryKey:G})}}),d=g(async t=>{await i({title:`Delete this archive?`,message:`Permanently deletes "${t.label??t.id}" and frees ${B(t.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&u.mutate({destinationId:e,backupId:t.id})},[i,e,u]),[f,p]=S(null),_=g(async t=>{p(t.id);try{let n=await te(J(e,t.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${t.label??t.id}.tar.gz`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{p(null)}},[e]),b=y(()=>[...l].toSorted((e,t)=>t.createdAt-e.createdAt),[l]);return o?C(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):c?C(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):b.length===0?C(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):C(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:v(`table`,{className:`w-full text-xs min-w-[640px]`,children:[C(`thead`,{children:v(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[C(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),C(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),C(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),C(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),C(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),C(`tbody`,{children:b.map(r=>v(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[C(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:Y(r.createdAt)}),C(`td`,{className:`px-3 py-1.5 text-foreground`,children:r.label??C(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),C(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:r.locations.join(`, `)}),C(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:B(r.sizeBytes)}),C(`td`,{className:`px-3 py-1.5`,children:v(`div`,{className:`flex items-center justify-end gap-1`,children:[v(`button`,{onClick:()=>{_(r)},disabled:f===r.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:[f===r.id?C(N,{className:`h-3 w-3 animate-spin`}):C(E,{className:`h-3 w-3`}),`Download`]}),t&&n&&v(`button`,{onClick:()=>n({destinationId:e,archiveId:r.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:[C(M,{className:`h-3 w-3`}),`Restore`]}),C(`button`,{onClick:()=>{d(r)},disabled:u.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:u.isPending?C(N,{className:`h-3 w-3 animate-spin`}):C(R,{className:`h-3 w-3`})})]})})]},r.id))})]})})}function J(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`})}_();var X=[{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 Z(e){let t=e.trim();for(let e of X)if(e.cron===t)return e.id;return`custom`}function re({value:e,onChange:t,previewCount:n=5,disabled:r=!1}){let i=Z(e),[a,o]=S(i===`custom`);w(()=>{i!==`custom`&&o(!1)},[i]);let s=oe(e,250),l=c({cron:s,count:n},{enabled:s.trim().length>0}),u=l.data??null,d=e=>{o(!1),t(e.cron)},f=a||i===`custom`;return v(`div`,{className:`space-y-3`,children:[v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),v(`div`,{className:`flex flex-wrap gap-1.5`,children:[X.map(e=>C(`button`,{type:`button`,onClick:()=>d(e),disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!a&&i===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)),C(`button`,{type:`button`,onClick:()=>{o(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(f?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),f&&v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),C(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:r,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`}),v(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,C(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),C(ie,{cron:s,preview:u,loading:l.isFetching})]})}function ie({cron:e,preview:t,loading:n}){return n&&t===null?v(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[C(N,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?C(`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.`}):v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),C(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>v(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[C(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),C(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:ae(e)})]},`${e}-${t}`))})]}):C(`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 ae(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 oe(e,t){let[n,r]=S(e),i=y(()=>e,[e]);return w(()=>{let e=setTimeout(()=>r(i),t);return()=>clearTimeout(e)},[i,t]),n}_();var se=[[`backup`,`listDestinations`]];function ce({onCreateAt:e,onOpenRestoreWizard:t}){let{data:n,isLoading:i,isError:a}=r(),o=n??[],[s,c]=S(null),l=e=>{c(t=>t===e?null:e)},u=fe();return i?C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading destinations…`}):a?C(`div`,{className:`text-xs text-danger`,children:`Failed to load destinations`}):o.length===0?C(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:C(`p`,{className:`text-xs text-foreground-subtle`,children:"No `backups`-typed storage locations registered. Add one in Settings → Storage to begin."})}):C(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:v(`table`,{className:`w-full text-xs min-w-[720px]`,children:[C(`thead`,{children:v(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[C(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),C(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Destination`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-28`,children:`Retention`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-56`,children:`Schedule`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-44`,children:`Last success`}),C(`th`,{className:`text-right px-3 py-2 font-medium w-44`,children:`Actions`})]})}),C(`tbody`,{children:o.map(n=>{let r=u.get(n.id);return C(Q,{row:n,isOpen:s===n.id,onToggle:()=>l(n.id),onCreateAt:e,liveLastSuccessAt:r?.at,liveLastSuccessSizeBytes:r?.sizeBytes,...t?{onOpenRestoreWizard:t}:{}},n.id)})})]})})}function Q({row:e,isOpen:t,onToggle:n,onCreateAt:r,onOpenRestoreWizard:i,liveLastSuccessAt:a,liveLastSuccessSizeBytes:o}){let s=x(),c=f({onSuccess:()=>{s.invalidateQueries({queryKey:se})}}),[l,u]=S(String(e.retentionCount));w(()=>{u(String(e.retentionCount))},[e.retentionCount]);let[d,p]=S(!1),m=g(t=>{c.mutate({locationId:e.id,enabled:t,retentionCount:e.retentionCount,...e.label===void 0?{}:{label:e.label},...e.cron===void 0?{}:{cron:e.cron}})},[c,e.id,e.retentionCount,e.label,e.cron]),h=g(()=>{let t=Number.parseInt(l,10);if(Number.isNaN(t)||t<1){u(String(e.retentionCount));return}t!==e.retentionCount&&c.mutate({locationId:e.id,enabled:e.enabled,retentionCount:t,...e.label===void 0?{}:{label:e.label},...e.cron===void 0?{}:{cron:e.cron}})},[c,l,e.id,e.enabled,e.retentionCount,e.label,e.cron]),_=g(t=>{c.mutate({locationId:e.id,enabled:e.enabled,retentionCount:e.retentionCount,...e.label===void 0?{}:{label:e.label},cron:t},{onSuccess:()=>{p(!1)}})},[c,e.id,e.enabled,e.retentionCount,e.label]);return v(b,{children:[v(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[C(`td`,{className:`px-2 py-2`,children:C(`button`,{onClick:n,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:t?`Hide archives`:`Show archives`,children:C(t?P:F,{className:`h-3.5 w-3.5`})})}),C(`td`,{className:`px-3 py-2`,children:v(`button`,{onClick:n,className:`text-left hover:underline focus:outline-none`,title:`View archives`,children:[C(`div`,{className:`text-foreground font-medium`,children:e.displayName}),v(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[C(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5`,children:e.kind}),C(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]})}),C(`td`,{className:`px-3 py-2`,children:C(`label`,{className:`inline-flex items-center cursor-pointer`,children:C(`input`,{type:`checkbox`,className:`accent-primary`,checked:e.enabled,disabled:c.isPending,onChange:e=>m(e.target.checked)})})}),C(`td`,{className:`px-3 py-2`,children:C(`input`,{type:`number`,min:1,max:1e3,value:l,disabled:c.isPending,onChange:e=>u(e.target.value),onBlur:h,onKeyDown:t=>{t.key===`Enter`&&t.target.blur(),t.key===`Escape`&&u(String(e.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`})}),C(`td`,{className:`px-3 py-2`,children:C(le,{cron:e.cron,nextRunAt:e.nextRunAt,onEdit:()=>p(!0),disabled:c.isPending})}),C(`td`,{className:`px-3 py-2 text-foreground-subtle`,children:(()=>{let t=pe(a,e.lastSuccessAt),n=t===a?o:e.lastSuccessSizeBytes;return t===void 0?C(`span`,{className:`italic`,children:`Never`}):C(me,{at:t,sizeBytes:n})})()}),C(`td`,{className:`px-3 py-2`,children:C(`div`,{className:`flex items-center justify-end gap-1.5`,children:e.triggerSupported&&v(`button`,{onClick:()=>r(e),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`,children:[C(j,{className:`h-3 w-3`}),`Create here`]})})})]}),t&&C(`tr`,{className:`border-t border-border bg-background/30`,children:C(`td`,{colSpan:7,className:`px-4 py-3`,children:C(q,{destinationId:e.id,restoreSupported:e.restoreSupported,...i?{onOpenRestoreWizard:i}:{}})})}),d&&C(de,{destinationName:e.displayName,currentCron:e.cron??``,onSave:_,onClose:()=>p(!1),saving:c.isPending,saveError:c.error instanceof Error?c.error.message:null})]})}function le({cron:e,nextRunAt:t,onEdit:n,disabled:r}){let i=typeof e==`string`&&e.trim().length>0;return v(`button`,{type:`button`,onClick:n,disabled:r,className:`group flex flex-col items-start gap-0.5 text-left rounded px-1.5 py-1 -mx-1.5 hover:bg-primary/5 disabled:opacity-50`,title:`Edit schedule`,children:[v(`div`,{className:`flex items-center gap-1.5`,children:[C(U,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),C(`span`,{className:i?`font-mono text-foreground`:`italic text-foreground-subtle`,children:i?e:`Manual`})]}),i&&t!==void 0&&v(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[`next `,ue(t)]})]})}function ue(e){let t=e-Date.now();if(t<=0)return`imminent`;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 de({destinationName:e,currentCron:t,onSave:n,onClose:r,saving:i,saveError:a}){let[o,s]=S(t);return C(`tr`,{children:C(`td`,{colSpan:7,className:`p-0`,children:C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:v(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Schedule`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e]})]}),C(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,title:`Close`,children:C(L,{className:`h-4 w-4`})})]}),v(`div`,{className:`p-4`,children:[C(re,{value:o,onChange:s,disabled:i}),a!==null&&C(`div`,{className:`mt-3 rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:a})]}),v(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[C(`button`,{onClick:r,disabled:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground disabled:opacity-50`,children:`Cancel`}),C(`button`,{onClick:()=>n(o.trim()),disabled:i||o.trim()===t.trim(),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:i?`Saving…`:`Save`})]})]})})})})}function fe(){let{map:e}=t(T.BackupCompleted,e=>e.destinationId);return y(()=>{let t=new Map;for(let[n,r]of e)t.set(n,{at:Date.now(),sizeBytes:r.sizeMB*1024*1024});return t},[e])}function pe(e,t){return e===void 0?t:t===void 0||e>t?e:t}function me({at:e,sizeBytes:t}){let n=he(e);return v(`span`,{title:y(()=>new Date(e).toLocaleString(),[e]),className:`text-foreground tabular-nums`,children:[n,t!==void 0&&v(`span`,{className:`ml-1 text-foreground-subtle`,children:[`· `,B(t)]})]})}function he(e){let[,t]=S(0);return w(()=>{let e=setInterval(()=>t(e=>e+1),3e4);return()=>clearInterval(e)},[]),ge(e)}function ge(e){let t=Math.max(0,Date.now()-e),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=Math.floor(a/30);return o<12?`${o}mo ago`:`${Math.floor(a/365)}y ago`}_();var _e=[[`backup`,`list`]];function ve({initialDestinationId:t,initialArchiveId:i,onClose:a,onScheduled:o}){let c=x(),[l,u]=S(t&&i?2:1),[d,f]=S(t),[p,m]=S(i),[h,g]=S(new Set),{data:_}=r(),b=_??[],{data:T,isLoading:E}=s({destinationId:d??``},{enabled:!!d}),D=T??[];w(()=>{if(d!==void 0)return;let e=b.filter(e=>e.restoreSupported);e.length===1&&f(e[0].id)},[d,b]);let{data:O}=e({destinationId:d??``,backupId:p??``},{enabled:!!d&&!!p}),k=y(()=>O?.locations??[],[O]);w(()=>{k.length!==0&&g(e=>e.size===0?new Set(k):e)},[k]);let A=n({onSuccess:()=>{c.invalidateQueries({queryKey:_e}),o(),a()}}),j=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},P=!!d&&!!p,F=h.size>0,I=P&&F&&!A.isPending,R=()=>{!d||!p||A.mutate({destinationId:d,backupId:p,locations:[...h]})};return C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:a,children:v(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,l,` of 3 —`,` `,l===1?`pick source`:l===2?`pick locations`:`confirm`]})]}),C(`button`,{onClick:a,className:`text-foreground-subtle hover:text-foreground`,children:C(L,{className:`h-4 w-4`})})]}),l===1&&C(ye,{destinations:b,destinationId:d,onPickDestination:e=>{f(e),m(void 0),g(new Set)},archives:D,archivesLoading:E,archiveId:p,onPickArchive:m}),l===2&&C(be,{locations:k,picked:h,onToggle:j}),l===3&&C(xe,{destinationName:b.find(e=>e.id===d)?.displayName??d??``,archive:D.find(e=>e.id===p),picked:[...h]}),v(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[C(`div`,{children:l>1&&v(`button`,{onClick:()=>u(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:[C(ee,{className:`h-3 w-3`}),`Back`]})}),v(`div`,{className:`flex items-center gap-2`,children:[C(`button`,{onClick:a,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),l<3?v(`button`,{disabled:l===1&&!P||l===2&&!F,onClick:()=>u(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`,C(ne,{className:`h-3 w-3`})]}):v(`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?C(N,{className:`h-3.5 w-3.5 animate-spin`}):C(M,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function ye({destinations:e,destinationId:t,onPickDestination:n,archives:r,archivesLoading:i,archiveId:a,onPickArchive:o}){let s=e.filter(e=>e.restoreSupported);return v(`div`,{className:`p-4 space-y-3`,children:[v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),v(`select`,{value:t??``,onChange:e=>n(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:[C(`option`,{value:``,disabled:!0,children:`Select destination…`}),s.map(e=>v(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&C(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&i&&C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!i&&r.length===0&&C(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&r.length>0&&C(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:r.map(e=>{let t=a===e.id;return v(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>o(e.id),className:`accent-primary`}),v(`div`,{children:[C(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),C(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),C(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:B(e.sizeBytes)})]},e.id)})})]})]})}function be({locations:e,picked:t,onToggle:n}){return e.length===0?C(`div`,{className:`p-4`,children:C(`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.`})}):v(`div`,{className:`p-4 space-y-3`,children:[C(`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.`}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),C(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>v(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[C(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>n(e),className:`accent-primary`}),C(`span`,{className:`font-mono text-foreground`,children:e}),C(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ce(e)})]},e))})]})]})}function xe({destinationName:e,archive:t,picked:n}){return v(`div`,{className:`p-4 space-y-3 text-xs`,children:[C(`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.`}),v(`dl`,{className:`space-y-1.5`,children:[C($,{term:`Destination`,value:e}),C($,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&C($,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${B(t.sizeBytes)}`}),C($,{term:`Locations`,value:n.length>0?n.join(`, `):`— (full archive)`})]})]})}function $({term:e,value:t}){return v(`div`,{className:`flex justify-between gap-3`,children:[C(`dt`,{className:`text-foreground-subtle`,children:e}),C(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Se={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function Ce(e){return Se[e]??``}_();var we=[[`backup`,`list`]],Te=[[`backup`,`listLocations`]];function Ee(){let e=x(),t=m(),n=a({onSuccess:()=>{e.invalidateQueries({queryKey:we}),e.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),e.invalidateQueries({queryKey:[[`backup`,`listArchives`]]})}}),r=p(),[i,s]=S(null),{data:c}=o(void 0,{enabled:i!==null,retry:1}),[l,u]=S(null),[d,f]=S(!1),[h,g]=S(!1),[_,y]=S(!1),b=async()=>{await t({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&r.mutate({confirm:!0})};return v(z,{children:[v(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[v(`button`,{onClick:()=>f(!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:[C(M,{className:`h-3.5 w-3.5`}),`Restore…`]}),v(`button`,{onClick:()=>y(!0),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:[C(j,{className:`h-3.5 w-3.5`}),`Add destination`]})]}),h&&C(`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:v(`div`,{className:`flex items-center justify-between gap-3`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(M,{className:`h-3.5 w-3.5`}),C(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),v(`button`,{onClick:()=>{b()},disabled:r.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:[r.isPending?C(N,{className:`h-3.5 w-3.5 animate-spin`}):C(M,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),C(ce,{onCreateAt:e=>s(e),onOpenRestoreWizard:e=>u(e)}),i&&C(De,{destination:i,locations:c,onClose:()=>s(null),onSubmit:(t,r)=>{n.mutate({destinations:[i.id],locations:t,label:r||void 0},{onSuccess:()=>{s(null),e.invalidateQueries({queryKey:Te})}})},submitting:n.isPending}),(l||d)&&C(ve,{...l?{initialDestinationId:l.destinationId,initialArchiveId:l.archiveId}:{},onClose:()=>{u(null),f(!1)},onScheduled:()=>g(!0)}),_&&C(A,{initialType:`backups`,onClose:()=>y(!1),onCreated:()=>{y(!1),e.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]})}})]})}function De({destination:e,locations:t,onClose:n,onSubmit:r,submitting:i}){let a=(t??[]).filter(e=>e.present),[o,s]=S(``),[c,l]=S(null),u=c??new Set(a.map(e=>e.name)),d=e=>{l(t=>{let n=new Set(t??a.map(e=>e.name));return n.has(e)?n.delete(e):n.add(e),n})};return C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:v(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Create Backup`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e.displayName]})]}),C(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:C(L,{className:`h-4 w-4`})})]}),v(`div`,{className:`p-4 space-y-3`,children:[v(`div`,{className:`space-y-1`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Label (optional)`}),C(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`pre-upgrade`,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`})]}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Include`}),v(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:[t===void 0&&v(`div`,{className:`flex items-center gap-2 px-3 py-2 text-xs text-foreground-subtle`,children:[C(N,{className:`h-3.5 w-3.5 animate-spin`}),`Calculating sizes…`]}),t!==void 0&&a.length===0&&C(`div`,{className:`px-3 py-2 text-xs text-foreground-subtle italic`,children:`Nothing to back up.`}),a.map(e=>v(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(`input`,{type:`checkbox`,checked:u.has(e.name),onChange:()=>d(e.name),className:`accent-primary`}),C(`span`,{className:`font-mono text-foreground`,children:e.name})]}),v(`div`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[B(e.sizeBytes),` · `,e.fileCount,` files`]})]},e.name))]})]})]}),v(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[C(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),v(`button`,{onClick:()=>r(Array.from(u),o.trim()),disabled:i||t===void 0||u.size===0,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:[i?C(N,{className:`h-3.5 w-3.5 animate-spin`}):C(H,{className:`h-3.5 w-3.5`}),i?`Creating…`:`Create`]})]})]})})}function Oe(){return C(`div`,{className:`flex flex-col p-4`,children:C(V,{tabs:[{id:`storage`,label:`Storage`,icon:D,content:C(W,{})},{id:`backup`,label:`Backup`,icon:H,content:C(Ee,{})}]})})}export{Oe as DataPage};
1
+ import{Bt as e,Da as t,Gt as n,Ht as r,Ji as i,Kt as a,Ut as o,Vt as s,Wt as c,Yi as l,Zi as u,qi as d,qt as f,wt as p,xa as m,zt as h}from"./src-Bx1PCCWV.js";import{I as g,Q as _,S as v,W as y,b,o as x,q as S,x as C,z as w}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{R as T}from"./src-BIAY4cjr.js";import{t as E}from"./download-DjYX33pK.js";import{i as D,n as O,r as k,t as A}from"./AddLocationWizard-B2-uyYmP.js";import{t as j}from"./plus-CTLCXGgQ.js";import{t as M}from"./rotate-cw-CE0Ns6Fz.js";import{F as N,N as P,S as F,U as I,V as ee,i as L,s as R}from"./index-Cdp6OaKK.js";import{t as z}from"./AdminPage-BwmGKnRf.js";import{n as te}from"./authed-media-XfBD4Ma-.js";import{t as B}from"./format-size-CO9d3C3-.js";import{t as V}from"./AdminTabs-CICieyaN.js";var H=I(`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`}]]),ne=I(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),U=I(`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`}]]);_();function W(){let e=x(),t=m(),{data:n,isLoading:r,isError:a}=l({}),o=i(),s=y(()=>o.data??[],[o.data]),[c,f]=S(null),[p,h]=S(null),g=d({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),_=u({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),b=e=>{e.isDefault||_.mutate({id:e.id,type:e.type,providerId:e.providerId,displayName:e.displayName,config:e.config,isDefault:!0})},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`})&&g.mutate({id:e.id})},T=y(()=>{let e=new Map;for(let t of n??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[n]),E=r||o.isLoading,D=a||o.isError;return v(z,{children:[E&&C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),D&&C(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!E&&!D&&v(`div`,{className:`space-y-3`,children:[s.length===0&&C(`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.`}),s.map(e=>C(k,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:T.get(e.id)??[],onAdd:e=>f(e),onEdit:e=>h(e),onDelete:e=>{w(e)},onSetDefault:e=>b(e)},e.id))]}),c!==null&&C(A,{initialType:c,onClose:()=>f(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),f(null)}}),p!==null&&C(O,{location:p,onClose:()=>h(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),h(null)}})]})}_();var G=[[`backup`,`listDestinations`]],K=[`backup`,`listArchives`];function q({destinationId:e,restoreSupported:t,onOpenRestoreWizard:n}){let r=x(),i=m(),{data:a,isLoading:o,isError:c}=s({destinationId:e}),l=a??[],u=h({onSuccess:()=>{r.invalidateQueries({queryKey:[[...K]]}),r.invalidateQueries({queryKey:G})}}),d=g(async t=>{await i({title:`Delete this archive?`,message:`Permanently deletes "${t.label??t.id}" and frees ${B(t.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&u.mutate({destinationId:e,backupId:t.id})},[i,e,u]),[f,p]=S(null),_=g(async t=>{p(t.id);try{let n=await te(J(e,t.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${t.label??t.id}.tar.gz`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{p(null)}},[e]),b=y(()=>[...l].toSorted((e,t)=>t.createdAt-e.createdAt),[l]);return o?C(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):c?C(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):b.length===0?C(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):C(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:v(`table`,{className:`w-full text-xs min-w-[640px]`,children:[C(`thead`,{children:v(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[C(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),C(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),C(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),C(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),C(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),C(`tbody`,{children:b.map(r=>v(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[C(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:Y(r.createdAt)}),C(`td`,{className:`px-3 py-1.5 text-foreground`,children:r.label??C(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),C(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:r.locations.join(`, `)}),C(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:B(r.sizeBytes)}),C(`td`,{className:`px-3 py-1.5`,children:v(`div`,{className:`flex items-center justify-end gap-1`,children:[v(`button`,{onClick:()=>{_(r)},disabled:f===r.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:[f===r.id?C(F,{className:`h-3 w-3 animate-spin`}):C(E,{className:`h-3 w-3`}),`Download`]}),t&&n&&v(`button`,{onClick:()=>n({destinationId:e,archiveId:r.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:[C(M,{className:`h-3 w-3`}),`Restore`]}),C(`button`,{onClick:()=>{d(r)},disabled:u.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:u.isPending?C(F,{className:`h-3 w-3 animate-spin`}):C(R,{className:`h-3 w-3`})})]})})]},r.id))})]})})}function J(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`})}_();var X=[{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 Z(e){let t=e.trim();for(let e of X)if(e.cron===t)return e.id;return`custom`}function re({value:e,onChange:t,previewCount:n=5,disabled:r=!1}){let i=Z(e),[a,o]=S(i===`custom`);w(()=>{i!==`custom`&&o(!1)},[i]);let s=oe(e,250),l=c({cron:s,count:n},{enabled:s.trim().length>0}),u=l.data??null,d=e=>{o(!1),t(e.cron)},f=a||i===`custom`;return v(`div`,{className:`space-y-3`,children:[v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),v(`div`,{className:`flex flex-wrap gap-1.5`,children:[X.map(e=>C(`button`,{type:`button`,onClick:()=>d(e),disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!a&&i===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)),C(`button`,{type:`button`,onClick:()=>{o(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(f?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),f&&v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),C(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:r,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`}),v(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,C(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),C(ie,{cron:s,preview:u,loading:l.isFetching})]})}function ie({cron:e,preview:t,loading:n}){return n&&t===null?v(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[C(F,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?C(`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.`}):v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),C(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>v(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[C(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),C(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:ae(e)})]},`${e}-${t}`))})]}):C(`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 ae(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 oe(e,t){let[n,r]=S(e),i=y(()=>e,[e]);return w(()=>{let e=setTimeout(()=>r(i),t);return()=>clearTimeout(e)},[i,t]),n}_();var se=[[`backup`,`listDestinations`]];function ce({onCreateAt:e,onOpenRestoreWizard:t}){let{data:n,isLoading:i,isError:a}=r(),o=n??[],[s,c]=S(null),l=e=>{c(t=>t===e?null:e)},u=fe();return i?C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading destinations…`}):a?C(`div`,{className:`text-xs text-danger`,children:`Failed to load destinations`}):o.length===0?C(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:C(`p`,{className:`text-xs text-foreground-subtle`,children:"No `backups`-typed storage locations registered. Add one in Settings → Storage to begin."})}):C(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:v(`table`,{className:`w-full text-xs min-w-[720px]`,children:[C(`thead`,{children:v(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[C(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),C(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Destination`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-28`,children:`Retention`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-56`,children:`Schedule`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-44`,children:`Last success`}),C(`th`,{className:`text-right px-3 py-2 font-medium w-44`,children:`Actions`})]})}),C(`tbody`,{children:o.map(n=>{let r=u.get(n.id);return C(Q,{row:n,isOpen:s===n.id,onToggle:()=>l(n.id),onCreateAt:e,liveLastSuccessAt:r?.at,liveLastSuccessSizeBytes:r?.sizeBytes,...t?{onOpenRestoreWizard:t}:{}},n.id)})})]})})}function Q({row:e,isOpen:t,onToggle:n,onCreateAt:r,onOpenRestoreWizard:i,liveLastSuccessAt:a,liveLastSuccessSizeBytes:o}){let s=x(),c=f({onSuccess:()=>{s.invalidateQueries({queryKey:se})}}),[l,u]=S(String(e.retentionCount));w(()=>{u(String(e.retentionCount))},[e.retentionCount]);let[d,p]=S(!1),m=g(t=>{c.mutate({locationId:e.id,enabled:t,retentionCount:e.retentionCount,...e.label===void 0?{}:{label:e.label},...e.cron===void 0?{}:{cron:e.cron}})},[c,e.id,e.retentionCount,e.label,e.cron]),h=g(()=>{let t=Number.parseInt(l,10);if(Number.isNaN(t)||t<1){u(String(e.retentionCount));return}t!==e.retentionCount&&c.mutate({locationId:e.id,enabled:e.enabled,retentionCount:t,...e.label===void 0?{}:{label:e.label},...e.cron===void 0?{}:{cron:e.cron}})},[c,l,e.id,e.enabled,e.retentionCount,e.label,e.cron]),_=g(t=>{c.mutate({locationId:e.id,enabled:e.enabled,retentionCount:e.retentionCount,...e.label===void 0?{}:{label:e.label},cron:t},{onSuccess:()=>{p(!1)}})},[c,e.id,e.enabled,e.retentionCount,e.label]);return v(b,{children:[v(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[C(`td`,{className:`px-2 py-2`,children:C(`button`,{onClick:n,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:t?`Hide archives`:`Show archives`,children:C(t?N:P,{className:`h-3.5 w-3.5`})})}),C(`td`,{className:`px-3 py-2`,children:v(`button`,{onClick:n,className:`text-left hover:underline focus:outline-none`,title:`View archives`,children:[C(`div`,{className:`text-foreground font-medium`,children:e.displayName}),v(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[C(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5`,children:e.kind}),C(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]})}),C(`td`,{className:`px-3 py-2`,children:C(`label`,{className:`inline-flex items-center cursor-pointer`,children:C(`input`,{type:`checkbox`,className:`accent-primary`,checked:e.enabled,disabled:c.isPending,onChange:e=>m(e.target.checked)})})}),C(`td`,{className:`px-3 py-2`,children:C(`input`,{type:`number`,min:1,max:1e3,value:l,disabled:c.isPending,onChange:e=>u(e.target.value),onBlur:h,onKeyDown:t=>{t.key===`Enter`&&t.target.blur(),t.key===`Escape`&&u(String(e.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`})}),C(`td`,{className:`px-3 py-2`,children:C(le,{cron:e.cron,nextRunAt:e.nextRunAt,onEdit:()=>p(!0),disabled:c.isPending})}),C(`td`,{className:`px-3 py-2 text-foreground-subtle`,children:(()=>{let t=pe(a,e.lastSuccessAt),n=t===a?o:e.lastSuccessSizeBytes;return t===void 0?C(`span`,{className:`italic`,children:`Never`}):C(me,{at:t,sizeBytes:n})})()}),C(`td`,{className:`px-3 py-2`,children:C(`div`,{className:`flex items-center justify-end gap-1.5`,children:e.triggerSupported&&v(`button`,{onClick:()=>r(e),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`,children:[C(j,{className:`h-3 w-3`}),`Create here`]})})})]}),t&&C(`tr`,{className:`border-t border-border bg-background/30`,children:C(`td`,{colSpan:7,className:`px-4 py-3`,children:C(q,{destinationId:e.id,restoreSupported:e.restoreSupported,...i?{onOpenRestoreWizard:i}:{}})})}),d&&C(de,{destinationName:e.displayName,currentCron:e.cron??``,onSave:_,onClose:()=>p(!1),saving:c.isPending,saveError:c.error instanceof Error?c.error.message:null})]})}function le({cron:e,nextRunAt:t,onEdit:n,disabled:r}){let i=typeof e==`string`&&e.trim().length>0;return v(`button`,{type:`button`,onClick:n,disabled:r,className:`group flex flex-col items-start gap-0.5 text-left rounded px-1.5 py-1 -mx-1.5 hover:bg-primary/5 disabled:opacity-50`,title:`Edit schedule`,children:[v(`div`,{className:`flex items-center gap-1.5`,children:[C(U,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),C(`span`,{className:i?`font-mono text-foreground`:`italic text-foreground-subtle`,children:i?e:`Manual`})]}),i&&t!==void 0&&v(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[`next `,ue(t)]})]})}function ue(e){let t=e-Date.now();if(t<=0)return`imminent`;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 de({destinationName:e,currentCron:t,onSave:n,onClose:r,saving:i,saveError:a}){let[o,s]=S(t);return C(`tr`,{children:C(`td`,{colSpan:7,className:`p-0`,children:C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:v(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Schedule`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e]})]}),C(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,title:`Close`,children:C(L,{className:`h-4 w-4`})})]}),v(`div`,{className:`p-4`,children:[C(re,{value:o,onChange:s,disabled:i}),a!==null&&C(`div`,{className:`mt-3 rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:a})]}),v(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[C(`button`,{onClick:r,disabled:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground disabled:opacity-50`,children:`Cancel`}),C(`button`,{onClick:()=>n(o.trim()),disabled:i||o.trim()===t.trim(),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:i?`Saving…`:`Save`})]})]})})})})}function fe(){let{map:e}=t(T.BackupCompleted,e=>e.destinationId);return y(()=>{let t=new Map;for(let[n,r]of e)t.set(n,{at:Date.now(),sizeBytes:r.sizeMB*1024*1024});return t},[e])}function pe(e,t){return e===void 0?t:t===void 0||e>t?e:t}function me({at:e,sizeBytes:t}){let n=he(e);return v(`span`,{title:y(()=>new Date(e).toLocaleString(),[e]),className:`text-foreground tabular-nums`,children:[n,t!==void 0&&v(`span`,{className:`ml-1 text-foreground-subtle`,children:[`· `,B(t)]})]})}function he(e){let[,t]=S(0);return w(()=>{let e=setInterval(()=>t(e=>e+1),3e4);return()=>clearInterval(e)},[]),ge(e)}function ge(e){let t=Math.max(0,Date.now()-e),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=Math.floor(a/30);return o<12?`${o}mo ago`:`${Math.floor(a/365)}y ago`}_();var _e=[[`backup`,`list`]];function ve({initialDestinationId:t,initialArchiveId:i,onClose:a,onScheduled:o}){let c=x(),[l,u]=S(t&&i?2:1),[d,f]=S(t),[p,m]=S(i),[h,g]=S(new Set),{data:_}=r(),b=_??[],{data:T,isLoading:E}=s({destinationId:d??``},{enabled:!!d}),D=T??[];w(()=>{if(d!==void 0)return;let e=b.filter(e=>e.restoreSupported);e.length===1&&f(e[0].id)},[d,b]);let{data:O}=e({destinationId:d??``,backupId:p??``},{enabled:!!d&&!!p}),k=y(()=>O?.locations??[],[O]);w(()=>{k.length!==0&&g(e=>e.size===0?new Set(k):e)},[k]);let A=n({onSuccess:()=>{c.invalidateQueries({queryKey:_e}),o(),a()}}),j=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},N=!!d&&!!p,P=h.size>0,I=N&&P&&!A.isPending,R=()=>{!d||!p||A.mutate({destinationId:d,backupId:p,locations:[...h]})};return C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:a,children:v(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,l,` of 3 —`,` `,l===1?`pick source`:l===2?`pick locations`:`confirm`]})]}),C(`button`,{onClick:a,className:`text-foreground-subtle hover:text-foreground`,children:C(L,{className:`h-4 w-4`})})]}),l===1&&C(ye,{destinations:b,destinationId:d,onPickDestination:e=>{f(e),m(void 0),g(new Set)},archives:D,archivesLoading:E,archiveId:p,onPickArchive:m}),l===2&&C(be,{locations:k,picked:h,onToggle:j}),l===3&&C(xe,{destinationName:b.find(e=>e.id===d)?.displayName??d??``,archive:D.find(e=>e.id===p),picked:[...h]}),v(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[C(`div`,{children:l>1&&v(`button`,{onClick:()=>u(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:[C(ee,{className:`h-3 w-3`}),`Back`]})}),v(`div`,{className:`flex items-center gap-2`,children:[C(`button`,{onClick:a,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),l<3?v(`button`,{disabled:l===1&&!N||l===2&&!P,onClick:()=>u(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`,C(ne,{className:`h-3 w-3`})]}):v(`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?C(F,{className:`h-3.5 w-3.5 animate-spin`}):C(M,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function ye({destinations:e,destinationId:t,onPickDestination:n,archives:r,archivesLoading:i,archiveId:a,onPickArchive:o}){let s=e.filter(e=>e.restoreSupported);return v(`div`,{className:`p-4 space-y-3`,children:[v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),v(`select`,{value:t??``,onChange:e=>n(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:[C(`option`,{value:``,disabled:!0,children:`Select destination…`}),s.map(e=>v(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&C(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&i&&C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!i&&r.length===0&&C(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&r.length>0&&C(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:r.map(e=>{let t=a===e.id;return v(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>o(e.id),className:`accent-primary`}),v(`div`,{children:[C(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),C(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),C(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:B(e.sizeBytes)})]},e.id)})})]})]})}function be({locations:e,picked:t,onToggle:n}){return e.length===0?C(`div`,{className:`p-4`,children:C(`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.`})}):v(`div`,{className:`p-4 space-y-3`,children:[C(`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.`}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),C(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>v(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[C(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>n(e),className:`accent-primary`}),C(`span`,{className:`font-mono text-foreground`,children:e}),C(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ce(e)})]},e))})]})]})}function xe({destinationName:e,archive:t,picked:n}){return v(`div`,{className:`p-4 space-y-3 text-xs`,children:[C(`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.`}),v(`dl`,{className:`space-y-1.5`,children:[C($,{term:`Destination`,value:e}),C($,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&C($,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${B(t.sizeBytes)}`}),C($,{term:`Locations`,value:n.length>0?n.join(`, `):`— (full archive)`})]})]})}function $({term:e,value:t}){return v(`div`,{className:`flex justify-between gap-3`,children:[C(`dt`,{className:`text-foreground-subtle`,children:e}),C(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Se={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function Ce(e){return Se[e]??``}_();var we=[[`backup`,`list`]],Te=[[`backup`,`listLocations`]];function Ee(){let e=x(),t=m(),n=a({onSuccess:()=>{e.invalidateQueries({queryKey:we}),e.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),e.invalidateQueries({queryKey:[[`backup`,`listArchives`]]})}}),r=p(),[i,s]=S(null),{data:c}=o(void 0,{enabled:i!==null,retry:1}),[l,u]=S(null),[d,f]=S(!1),[h,g]=S(!1),[_,y]=S(!1),b=async()=>{await t({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&r.mutate({confirm:!0})};return v(z,{children:[v(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[v(`button`,{onClick:()=>f(!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:[C(M,{className:`h-3.5 w-3.5`}),`Restore…`]}),v(`button`,{onClick:()=>y(!0),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:[C(j,{className:`h-3.5 w-3.5`}),`Add destination`]})]}),h&&C(`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:v(`div`,{className:`flex items-center justify-between gap-3`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(M,{className:`h-3.5 w-3.5`}),C(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),v(`button`,{onClick:()=>{b()},disabled:r.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:[r.isPending?C(F,{className:`h-3.5 w-3.5 animate-spin`}):C(M,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),C(ce,{onCreateAt:e=>s(e),onOpenRestoreWizard:e=>u(e)}),i&&C(De,{destination:i,locations:c,onClose:()=>s(null),onSubmit:(t,r)=>{n.mutate({destinations:[i.id],locations:t,label:r||void 0},{onSuccess:()=>{s(null),e.invalidateQueries({queryKey:Te})}})},submitting:n.isPending}),(l||d)&&C(ve,{...l?{initialDestinationId:l.destinationId,initialArchiveId:l.archiveId}:{},onClose:()=>{u(null),f(!1)},onScheduled:()=>g(!0)}),_&&C(A,{initialType:`backups`,onClose:()=>y(!1),onCreated:()=>{y(!1),e.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]})}})]})}function De({destination:e,locations:t,onClose:n,onSubmit:r,submitting:i}){let a=(t??[]).filter(e=>e.present),[o,s]=S(``),[c,l]=S(null),u=c??new Set(a.map(e=>e.name)),d=e=>{l(t=>{let n=new Set(t??a.map(e=>e.name));return n.has(e)?n.delete(e):n.add(e),n})};return C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:v(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Create Backup`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e.displayName]})]}),C(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:C(L,{className:`h-4 w-4`})})]}),v(`div`,{className:`p-4 space-y-3`,children:[v(`div`,{className:`space-y-1`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Label (optional)`}),C(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`pre-upgrade`,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`})]}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Include`}),v(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:[t===void 0&&v(`div`,{className:`flex items-center gap-2 px-3 py-2 text-xs text-foreground-subtle`,children:[C(F,{className:`h-3.5 w-3.5 animate-spin`}),`Calculating sizes…`]}),t!==void 0&&a.length===0&&C(`div`,{className:`px-3 py-2 text-xs text-foreground-subtle italic`,children:`Nothing to back up.`}),a.map(e=>v(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(`input`,{type:`checkbox`,checked:u.has(e.name),onChange:()=>d(e.name),className:`accent-primary`}),C(`span`,{className:`font-mono text-foreground`,children:e.name})]}),v(`div`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[B(e.sizeBytes),` · `,e.fileCount,` files`]})]},e.name))]})]})]}),v(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[C(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),v(`button`,{onClick:()=>r(Array.from(u),o.trim()),disabled:i||t===void 0||u.size===0,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:[i?C(F,{className:`h-3.5 w-3.5 animate-spin`}):C(H,{className:`h-3.5 w-3.5`}),i?`Creating…`:`Create`]})]})]})})}function Oe(){return C(`div`,{className:`flex flex-col p-4`,children:C(V,{tabs:[{id:`storage`,label:`Storage`,icon:D,content:C(W,{})},{id:`backup`,label:`Backup`,icon:H,content:C(Ee,{})}]})})}export{Oe as DataPage};
@@ -1 +1 @@
1
- import{$a as e,$n as t,Ga as n,Gn as r,Ja as i,Jn as a,Ka as o,Kn as s,Oa as c,On as l,Qn as u,Wa as d,Wn as f,Xn as p,Ya as m,Yn as h,Za as g,Zn as _,eo as v,er as y,nr as b,qa as x,qn as S,tr as C,xa as w}from"./src-C9tUE6VN.js";import{K as T,Q as E,S as D,W as O,b as k,o as A,q as j,x as M,z as N}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{R as P}from"./src-DJCxIXmd.js";import{a as F,i as I,n as L,r as ee,t as R}from"./face-bbox-C6BZci_u.js";import{a as te,c as ne,f as z,i as B,l as re,m as V,n as ie,o as ae,p as H,r as oe,s as se,t as ce,u as le}from"./debounced-invalidate-CmrI3MX6.js";import{t as U}from"./pencil-B2rRCbs4.js";import{t as W}from"./plus-DIHRelRK.js";import{t as ue}from"./refresh-cw-NUBl_9F6.js";import{t as G}from"./square-check-big-CSjE0FM_.js";import{t as de}from"./square-DCFTa1lw.js";import{C as K,I as q,L as J,P as fe,W as pe,g as me,i as Y,l as he,s as X}from"./index-BXAOUGFx.js";import{t as Z}from"./AdminPage-BwmGKnRf.js";import{n as Q,t as ge}from"./authed-media-XfBD4Ma-.js";var _e=pe(`undo-2`,[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]),ve=pe(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]);E();var $=[[`faceGallery`]];function ye({identityId:e}){let t=A(),{data:n,isLoading:r}=p({identityId:e}),i=u();function a(n){i.mutate({identityId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:$})}})}return r?D(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[M(K,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!n||n.length===0?M(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):M(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:n.map(e=>D(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?M(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):M(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:M(ve,{className:`h-6 w-6`})}),M(`button`,{type:`button`,onClick:()=>a(e),disabled:i.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:M(Y,{className:`h-4 w-4 text-white`})})]},e.id))})}function be({identity:r,expanded:a,onToggle:s}){let c=A(),[l,u]=j(``),[f,p]=j(!1),[h,_]=j(!1),y=t(),b=S();function C(){u(r.name),p(!0)}function w(){p(!1),u(``)}function T(){let e=l.trim();if(!e||e===r.name){w();return}y.mutate({id:r.id,name:e},{onSettled:()=>{c.invalidateQueries({queryKey:$}),w()}})}function E(){b.mutate({id:r.id},{onSettled:()=>{c.invalidateQueries({queryKey:$}),_(!1)}})}return D(`div`,{className:`rounded-md border border-border bg-surface`,children:[D(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[M(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:r.coverBase64?M(`img`,{src:`data:image/jpeg;base64,${r.coverBase64}`,alt:r.name,className:`h-full w-full object-cover`}):M(`div`,{className:`flex h-full w-full items-center justify-center`,children:M(ve,{className:`h-4 w-4 text-foreground-subtle`})})}),M(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:f?D(k,{children:[M(g,{value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T(),e.key===`Escape`&&w()},className:`h-6 text-xs`,autoFocus:!0}),M(`button`,{type:`button`,onClick:T,disabled:y.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:M(J,{className:`h-3.5 w-3.5`})}),M(`button`,{type:`button`,onClick:w,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:M(Y,{className:`h-3.5 w-3.5`})})]}):M(`span`,{className:`truncate text-sm font-medium text-foreground`,children:r.name})}),M(e,{variant:`default`,className:`text-[10px]`,children:r.sampleCount}),!f&&D(`div`,{className:`flex items-center gap-1`,children:[M(`button`,{type:`button`,onClick:C,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:M(U,{className:`h-3.5 w-3.5`})}),M(`button`,{type:`button`,onClick:()=>_(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:M(X,{className:`h-3.5 w-3.5`})})]}),M(`button`,{type:`button`,onClick:s,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":a?`Collapse`:`Expand`,children:M(a?q:fe,{className:`h-3.5 w-3.5`})})]}),a&&M(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:M(ye,{identityId:r.id})}),M(d,{open:h,onOpenChange:e=>!e&&_(!1),children:D(n,{children:[D(i,{children:[M(m,{children:`Delete person`}),D(o,{children:[`Delete `,M(`strong`,{children:r.name}),` and all their samples? This cannot be undone.`]})]}),D(x,{children:[M(v,{variant:`secondary`,onClick:()=>_(!1),children:`Cancel`}),D(v,{variant:`danger`,onClick:E,disabled:b.isPending,children:[b.isPending?M(K,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function xe(){let e=A(),[t,n]=j(``),i=r();function a(){let r=t.trim();r&&i.mutate({name:r},{onSettled:()=>{e.invalidateQueries({queryKey:$}),n(``)}})}return D(`div`,{className:`flex items-center gap-2 pt-2`,children:[M(g,{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`}),D(v,{variant:`primary`,size:`sm`,onClick:a,disabled:i.isPending||!t.trim(),children:[i.isPending?M(K,{className:`h-3.5 w-3.5 animate-spin`}):M(W,{className:`h-3.5 w-3.5`}),`Add`]})]})}function Se(){let{data:e,isLoading:t}=h(),[n,r]=j(null);function i(e){r(t=>t===e?null:e)}return t?D(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[M(K,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):D(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&M(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),e?.map(e=>M(be,{identity:e,expanded:n===e.id,onToggle:()=>i(e.id)},e.id)),M(xe,{})]})}function Ce(e){return e.base64===void 0||e.base64.length===0}function we(e){return e.filter(Ce).map(e=>e.faceId)}function Te(e){let t=0;for(let n of e)Ce(n)&&(t+=1);return t}E();function Ee(e){let[t,n]=j(null),[r,i]=j(null),[a,o]=j(!1);return N(()=>{if(n(null),i(null),o(!1),!e)return;let t=!1,r=null;return(async()=>{try{let i=await Q(`${ge}/${encodeURIComponent(e)}`);if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),N(()=>{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 De(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 Oe({label:e,value:t}){return D(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[M(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),M(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:t})]})}function ke({box:e}){return M(`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:M(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Face`})})}function Ae({face:e,cameraName:t,onClose:r,onAssign:i,onUnassign:o,onDelete:s,actionsPending:c}){let{data:l,isFetching:u}=a({faceId:e?.faceId??``},{enabled:e!==null}),[f,p]=j(`frame`),{frameSrc:m,naturalWidth:h,naturalHeight:g,failed:_}=Ee(e?.keyFrameMediaKey),y=O(()=>{let t=De(l??[]);return t?`data:image/jpeg;base64,${t.base64}`:e?.base64?`data:image/jpeg;base64,${e.base64}`:null},[l,e]),b=O(()=>!e?.faceBbox||h===null||g===null?null:R(e.faceBbox,h,g),[e?.faceBbox,h,g]);if(e===null)return null;let x=typeof e.keyFrameMediaKey==`string`&&e.keyFrameMediaKey.length>0&&!_,S=x&&f===`frame`,C=e.assigned?e.identityName??`Assigned`:e.recognizedIdentityId?`${e.identityName??`Recognized`} (suggested)`:`Unassigned`;return M(d,{open:!0,onOpenChange:e=>!e&&r(),children:D(n,{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:[D(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[D(`div`,{className:`min-w-0`,children:[M(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:`Face detail`}),M(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),M(`button`,{type:`button`,onClick:r,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:M(Y,{className:`h-4 w-4`})})]}),D(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[x&&D(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[D(`button`,{type:`button`,onClick:()=>p(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${f===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[M(I,{className:`h-3.5 w-3.5`}),` Full frame`]}),D(`button`,{type:`button`,onClick:()=>p(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${f===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[M(F,{className:`h-3.5 w-3.5`}),` Crop`]})]}),S&&m?M(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:M(B,{src:m,alt:`Full frame with detected face`,fit:`natural`,className:`w-full`,overlay:b?M(ke,{box:b}):void 0})}):y?D(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[M(B,{src:y,alt:`Detected face`,className:`h-full w-full`}),u&&M(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:M(K,{className:`h-3.5 w-3.5 animate-spin`})})]}):D(`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:[M(V,{className:`h-8 w-8 text-warning/70`}),M(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),M(`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.`})]}),D(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[M(Oe,{label:`Camera`,value:t}),M(Oe,{label:`Captured`,value:H(e.timestamp)}),M(Oe,{label:`Track`,value:e.trackId}),M(Oe,{label:`Identity`,value:C})]})]}),D(`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?D(v,{variant:`secondary`,onClick:()=>o(e.faceId),disabled:c,children:[M(L,{className:`h-3.5 w-3.5`}),` Detach`]}):D(v,{variant:`primary`,onClick:()=>i(e.faceId),disabled:c,children:[M(ee,{className:`h-3.5 w-3.5`}),` Assign`]}),D(v,{variant:`secondary`,onClick:()=>s(e.faceId),disabled:c,children:[M(X,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}E();var je=[[`faceGallery`]];function Me({faceIds:e,identities:t,onDone:a}){let s=A(),c=f(),l=r(),[u,p]=j(``),[h,_]=j(!1),[y,b]=j(null),S=e!==null&&e.length>0,C=e?.length??0;function w(){_(!1),p(``),b(null)}function T(){w(),a()}function E(t){!e||e.length===0||c.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{s.invalidateQueries({queryKey:je}),T()}})}function O(){!e||!u.trim()||l.mutate({name:u.trim()},{onSuccess:e=>{e?.id&&E(e.id)},onError:()=>{s.invalidateQueries({queryKey:je}),T()}})}let k=c.isPending||l.isPending;return M(d,{open:S,onOpenChange:e=>!e&&T(),children:D(n,{children:[D(i,{children:[M(m,{children:C>1?`Assign ${String(C)} faces to person`:`Assign face to person`}),M(o,{children:`Select an existing person or create a new one.`})]}),M(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>D(`button`,{type:`button`,onClick:()=>b(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${y===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[M(`span`,{className:`font-medium`,children:e.name}),D(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),h?M(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:M(g,{placeholder:`New person name…`,value:u,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&O()},autoFocus:!0,className:`flex-1`})}):M(`button`,{type:`button`,onClick:()=>{b(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…`}),D(x,{children:[M(v,{variant:`secondary`,onClick:T,disabled:k,children:`Cancel`}),h?D(v,{variant:`primary`,onClick:O,disabled:k||!u.trim(),children:[k&&M(K,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):D(v,{variant:`primary`,onClick:()=>y&&E(y),disabled:k||!y,children:[k&&M(K,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,C>1?` ${String(C)}`:``]})]})]})})}function Ne(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function Pe(e,t){return e.faceIds.filter(e=>!t.has(e))}function Fe(e,t){return e.faceIds.filter(e=>t(e))}E();var Ie=[[`faceGallery`]],Le=20,Re=.3,ze=.9,Be=.05,Ve=.5,He=2,Ue=10,We=2;function Ge({cluster:e,face:t,active:n,onSelect:r}){return D(`button`,{type:`button`,onClick:r,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:[M(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:t?.base64?M(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:``,className:`h-24 w-24 object-cover`}):M(V,{className:`h-24 w-24 p-6 text-foreground-subtle`})}),D(`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 Ke({face:e,cameraName:t,nowMs:n,excluded:r,onToggleExclude:i,onDelete:a,deletePending:o}){return D(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${r?`border-border opacity-40 grayscale`:`border-border`}`,children:[D(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[e.base64?M(B,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Face from ${t}`,className:`h-full w-full`}):D(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[M(V,{className:`h-7 w-7 text-warning/70`}),M(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}),M(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i()},className:`absolute right-1 top-1 z-10 rounded-full bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":r?`Include face`:`Exclude face`,title:r?`Include`:`Exclude`,children:M(r?_e:Y,{className:`h-3.5 w-3.5`})})]}),D(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[M(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),M(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:z(e.timestamp,n)})]}),M(`div`,{className:`mt-1 flex items-center justify-end border-t border-border/60 px-1 py-0.5`,children:M(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},disabled:o,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:o?M(K,{className:`h-4 w-4 animate-spin`}):M(X,{className:`h-4 w-4`})})})]})}function qe({open:e,onClose:t,byId:r,cameraName:i,nowMs:a,identities:o,selectMany:c}){let l=A(),u=w(),f=s(),[p,m]=j(Ve),[h,g]=j(We),[_,b]=j(null),[x,S]=j({}),[C,T]=j(null),{data:E,isFetching:P,refetch:F}=y({threshold:p,minClusterSize:h,limit:Le},{enabled:e}),I=E??[];N(()=>{S({})},[p,h]),N(()=>{if(I.length===0){b(null);return}I.some(e=>e.representativeFaceId===_)||b(I[0]?.representativeFaceId??null)},[I]);let L=O(()=>I.find(e=>e.representativeFaceId===_)??null,[I,_]),R=L?x[L.representativeFaceId]??new Set:new Set,te=O(()=>L?Fe(L,e=>r.has(e)):[],[L,r]),ne=L?L.faceIds.length-te.length:0,z=L?Pe({...L,faceIds:te},R):[];function B(e){if(!L)return;let t=L.representativeFaceId;S(n=>({...n,[t]:Ne(n[t]??new Set,e)}))}function re(){l.invalidateQueries({queryKey:Ie})}async function V(e){await u({title:`Delete face`,message:`Permanently deletes this face crop. This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&f.mutate({faceId:e},{onSettled:re})}function ie(){T(null),t()}function ae(){z.length!==0&&(c(z),ie())}return D(d,{open:e,onOpenChange:e=>!e&&ie(),children:[D(n,{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:[D(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border px-4 py-3`,children:[D(`div`,{className:`flex items-center justify-between gap-2`,children:[D(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[M(he,{className:`h-4 w-4 text-primary`}),` Look-alike groups`]}),M(`button`,{type:`button`,onClick:ie,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:M(Y,{className:`h-4 w-4`})})]}),D(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[D(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Threshold`,M(`input`,{type:`range`,min:Re,max:ze,step:Be,value:p,onChange:e=>m(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),M(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:p.toFixed(2)})]}),D(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Min size`,M(`input`,{type:`number`,min:He,max:Ue,step:1,value:h,onChange:e=>g(Math.min(Ue,Math.max(He,Number(e.target.value)||He))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),D(v,{variant:`secondary`,onClick:()=>{S({}),F()},disabled:P,children:[P?M(K,{className:`h-3.5 w-3.5 animate-spin`}):M(ue,{className:`h-3.5 w-3.5`}),`Re-analyze`]})]})]}),M(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:P&&I.length===0?D(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[M(K,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):I.length===0?M(`div`,{className:`flex flex-1 items-center justify-center py-8 text-xs text-foreground-subtle`,children:`No look-alike groups at this threshold.`}):D(k,{children:[M(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:I.map(e=>M(Ge,{cluster:e,face:r.get(e.representativeFaceId),active:e.representativeFaceId===_,onSelect:()=>b(e.representativeFaceId)},e.representativeFaceId))}),M(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:I.map(e=>M(Ge,{cluster:e,face:r.get(e.representativeFaceId),active:e.representativeFaceId===_,onSelect:()=>b(e.representativeFaceId)},e.representativeFaceId))}),M(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:L&&D(k,{children:[ne>0&&D(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:[ne,` not loaded — excluded from actions`]}),M(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,1fr))] gap-2`,children:te.map(e=>{let t=r.get(e);return t?M(Ke,{face:t,cameraName:i(t.deviceId),nowMs:a,excluded:R.has(e),onToggleExclude:()=>B(e),onDelete:()=>void V(e),deletePending:f.isPending&&f.variables?.faceId===e},e):null})})]})})]})}),D(`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:[M(v,{variant:`secondary`,onClick:ae,disabled:z.length===0,children:`Select in gallery`}),D(v,{variant:`primary`,onClick:()=>T(z),disabled:z.length===0,children:[M(ee,{className:`h-3.5 w-3.5`}),` Adopt (`,z.length,`)`]})]})]}),M(Me,{faceIds:C,identities:o,onDone:()=>T(null)})]})}E();var Je=[[`faceGallery`]],Ye=500,Xe=120;function Ze({face:e,cameraName:t,nowMs:n,selected:r,onToggleSelect:i,onAssign:a,onOpenDetail:o}){let c=A(),l=C(),u=s(),d=()=>{c.invalidateQueries({queryKey:Je})},f=()=>o(e.faceId);return D(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${r?`border-primary ring-1 ring-primary`:`border-border`}`,children:[D(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[e.base64?M(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Face from ${t}`,onClick:f,className:`h-full w-full cursor-zoom-in object-cover`}):D(`button`,{type:`button`,onClick:f,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:[M(V,{className:`h-7 w-7 text-warning/70`}),M(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}),M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),i(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":r?`Deselect`:`Select`,children:r?M(G,{className:`h-4 w-4 text-primary`}):M(de,{className:`h-4 w-4`})})]}),D(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[M(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),M(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:z(e.timestamp,n)}),e.identityName&&M(`p`,{className:`text-[10px] font-medium text-primary truncate`,title:e.identityName,children:e.identityName})]}),D(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),l.mutate({faceId:e.faceId},{onSettled:d})},disabled:l.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:l.isPending?M(K,{className:`h-4 w-4 animate-spin`}):M(L,{className:`h-4 w-4`})}):M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(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:M(ee,{className:`h-4 w-4`})}),M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),u.mutate({faceId:e.faceId},{onSettled:d})},disabled:u.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:u.isPending?M(K,{className:`h-4 w-4 animate-spin`}):M(X,{className:`h-4 w-4`})})]})]})}var Qe=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function $e(){let e=A(),[t,n]=j(`all`),[r,i]=j(se),[a,o]=j(new Set),[c,u]=j(new Set),[d,p]=j(null),[m,g]=j(!1),[y,x]=j(null),{data:S,isLoading:w}=_({limit:Ye,filter:t},{refetchInterval:3e4}),{data:T=[]}=h(),{data:E}=l({}),N=f(),P=C(),F=b(),I=s(),R=Date.now(),z=S??[],B=O(()=>{let e=new Map;for(let t of E??[])e.set(t.id,t.name);return e},[E]),H=e=>B.get(e)??`Camera #${String(e)}`,ce=O(()=>ne(z).map(e=>({id:e,name:H(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[z,B]),U=O(()=>re(le(z,r),a),[z,r,a]),W=ie(U,Xe,O(()=>JSON.stringify([t,r.fromMs,r.toMs,[...a].sort((e,t)=>e-t)]),[t,r.fromMs,r.toMs,a])),ue=O(()=>new Map(z.map(e=>[e.faceId,e])),[z]),G=O(()=>Te(U),[U]),de=y===null?null:ue.get(y)??null,q=()=>{e.invalidateQueries({queryKey:Je})},J=()=>u(new Set);function fe(e){u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function pe(e){u(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function me(){pe(we(U))}let Z=[...c],Q=N.isPending||F.isPending||I.isPending,ge=P.isPending||I.isPending;function _e(){Z.length!==0&&F.mutate({faceIds:Z},{onSettled:()=>{q(),J()}})}function ve(){Z.length!==0&&Promise.allSettled(Z.map(e=>I.mutateAsync({faceId:e}))).then(()=>{q(),J()})}function $(e){x(null),p([e])}function ye(e){P.mutate({faceId:e},{onSettled:q}),x(null)}function be(e){I.mutate({faceId:e},{onSettled:q}),x(null)}let xe=U.length!==z.length;return D(`div`,{className:`relative space-y-3`,children:[D(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[M(`div`,{className:`flex items-center gap-1`,children:Qe.map(e=>M(`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))}),M(te,{onChange:i}),M(ae,{cameras:ce,selected:a,onChange:o}),D(`button`,{type:`button`,onClick:()=>g(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${m?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[M(he,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!w&&G>0&&D(`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:[M(V,{className:`h-3.5 w-3.5`}),` Select `,G,` crop-less`]}),!w&&M(`span`,{className:`text-[10px] text-foreground-subtle ${G>0?`ml-2`:`ml-auto`}`,children:xe?`${String(U.length)} of ${String(z.length)} faces`:`${String(U.length)} face${U.length===1?``:`s`}`})]}),c.size>0&&D(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[D(`span`,{className:`text-xs font-medium text-foreground`,children:[c.size,` selected`]}),D(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[D(v,{variant:`primary`,onClick:()=>p(Z),disabled:Q,children:[M(ee,{className:`h-3.5 w-3.5`}),` Assign`]}),D(v,{variant:`secondary`,onClick:_e,disabled:Q,children:[F.isPending?M(K,{className:`h-3.5 w-3.5 animate-spin`}):M(L,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),D(v,{variant:`secondary`,onClick:ve,disabled:Q,children:[M(X,{className:`h-3.5 w-3.5`}),` Delete`]}),M(v,{variant:`ghost`,onClick:J,disabled:Q,children:M(Y,{className:`h-3.5 w-3.5`})})]})]}),w&&D(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[M(K,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!w&&U.length===0&&M(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:z.length>0?`No faces match the current date / camera filters.`:`No faces found for this filter.`}),!w&&U.length>0&&D(k,{children:[M(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(6.5rem,1fr))] gap-2`,children:W.pageItems.map(e=>M(Ze,{face:e,cameraName:H(e.deviceId),nowMs:R,selected:c.has(e.faceId),onToggleSelect:fe,onAssign:e=>p([e]),onOpenDetail:x},e.faceId))}),M(oe,{currentPage:W.page,totalItems:W.totalItems,pageSize:W.pageSize,onPageChange:W.setPage,itemNoun:`faces`})]}),M(Ae,{face:de,cameraName:de?H(de.deviceId):``,onClose:()=>x(null),onAssign:$,onUnassign:ye,onDelete:be,actionsPending:ge}),M(Me,{faceIds:d,identities:T,onDone:()=>{p(null),J()}}),M(qe,{open:m,onClose:()=>g(!1),byId:ue,cameraName:H,nowMs:R,identities:T,selectMany:pe})]})}E();var et=[[`faceGallery`]],tt=2e3;function nt(){let e=A(),t=T(e);t.current=e;let n=T(void 0);n.current||=ce({delayMs:tt,invalidate:()=>{t.current.invalidateQueries({queryKey:et})}}),N(()=>()=>n.current?.cancel(),[]),c(P.PipelineAnalyticsFaceGalleryChanged,()=>{n.current?.trigger()})}function rt(){return nt(),M(Z,{icon:me,title:`Faces`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:D(`section`,{className:`space-y-3`,children:[D(`div`,{children:[M(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),M(`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.`}),M(Se,{})]}),D(`div`,{className:`pt-4 border-t border-border`,children:[M(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),M(`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.`}),M($e,{})]})]})})}export{rt as DetectionIntelligencePage};
1
+ import{$a as e,$n as t,Ga as n,Gn as r,Ja as i,Jn as a,Ka as o,Kn as s,Oa as c,On as l,Qn as u,Wa as d,Wn as f,Xn as p,Ya as m,Yn as h,Za as g,Zn as _,eo as v,er as y,nr as b,qa as x,qn as S,tr as C,xa as w}from"./src-Bx1PCCWV.js";import{K as T,Q as E,S as D,W as O,b as k,o as A,q as j,x as M,z as N}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{R as P}from"./src-BIAY4cjr.js";import{a as F,i as I,n as L,r as ee,t as R}from"./face-bbox-vlSxiLet.js";import{a as z,c as te,f as B,i as V,l as ne,m as H,n as re,o as ie,p as U,r as ae,s as oe,t as se,u as ce}from"./debounced-invalidate-DZ3oxQDl.js";import{t as W}from"./pencil-CUVzuL3L.js";import{t as G}from"./plus-CTLCXGgQ.js";import{t as le}from"./refresh-cw-BM18Lfvw.js";import{t as ue}from"./square-check-big-DqE0lyuf.js";import{t as de}from"./square-CfQwX-85.js";import{F as K,I as q,N as fe,S as J,U as pe,h as me,i as Y,l as he,s as X}from"./index-Cdp6OaKK.js";import{t as Z}from"./AdminPage-BwmGKnRf.js";import{n as Q,t as ge}from"./authed-media-XfBD4Ma-.js";var _e=pe(`undo-2`,[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]),ve=pe(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]);E();var $=[[`faceGallery`]];function ye({identityId:e}){let t=A(),{data:n,isLoading:r}=p({identityId:e}),i=u();function a(n){i.mutate({identityId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:$})}})}return r?D(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[M(J,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!n||n.length===0?M(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):M(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:n.map(e=>D(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?M(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):M(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:M(ve,{className:`h-6 w-6`})}),M(`button`,{type:`button`,onClick:()=>a(e),disabled:i.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:M(Y,{className:`h-4 w-4 text-white`})})]},e.id))})}function be({identity:r,expanded:a,onToggle:s}){let c=A(),[l,u]=j(``),[f,p]=j(!1),[h,_]=j(!1),y=t(),b=S();function C(){u(r.name),p(!0)}function w(){p(!1),u(``)}function T(){let e=l.trim();if(!e||e===r.name){w();return}y.mutate({id:r.id,name:e},{onSettled:()=>{c.invalidateQueries({queryKey:$}),w()}})}function E(){b.mutate({id:r.id},{onSettled:()=>{c.invalidateQueries({queryKey:$}),_(!1)}})}return D(`div`,{className:`rounded-md border border-border bg-surface`,children:[D(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[M(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:r.coverBase64?M(`img`,{src:`data:image/jpeg;base64,${r.coverBase64}`,alt:r.name,className:`h-full w-full object-cover`}):M(`div`,{className:`flex h-full w-full items-center justify-center`,children:M(ve,{className:`h-4 w-4 text-foreground-subtle`})})}),M(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:f?D(k,{children:[M(g,{value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T(),e.key===`Escape`&&w()},className:`h-6 text-xs`,autoFocus:!0}),M(`button`,{type:`button`,onClick:T,disabled:y.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:M(q,{className:`h-3.5 w-3.5`})}),M(`button`,{type:`button`,onClick:w,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:M(Y,{className:`h-3.5 w-3.5`})})]}):M(`span`,{className:`truncate text-sm font-medium text-foreground`,children:r.name})}),M(e,{variant:`default`,className:`text-[10px]`,children:r.sampleCount}),!f&&D(`div`,{className:`flex items-center gap-1`,children:[M(`button`,{type:`button`,onClick:C,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:M(W,{className:`h-3.5 w-3.5`})}),M(`button`,{type:`button`,onClick:()=>_(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:M(X,{className:`h-3.5 w-3.5`})})]}),M(`button`,{type:`button`,onClick:s,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":a?`Collapse`:`Expand`,children:M(a?K:fe,{className:`h-3.5 w-3.5`})})]}),a&&M(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:M(ye,{identityId:r.id})}),M(d,{open:h,onOpenChange:e=>!e&&_(!1),children:D(n,{children:[D(i,{children:[M(m,{children:`Delete person`}),D(o,{children:[`Delete `,M(`strong`,{children:r.name}),` and all their samples? This cannot be undone.`]})]}),D(x,{children:[M(v,{variant:`secondary`,onClick:()=>_(!1),children:`Cancel`}),D(v,{variant:`danger`,onClick:E,disabled:b.isPending,children:[b.isPending?M(J,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function xe(){let e=A(),[t,n]=j(``),i=r();function a(){let r=t.trim();r&&i.mutate({name:r},{onSettled:()=>{e.invalidateQueries({queryKey:$}),n(``)}})}return D(`div`,{className:`flex items-center gap-2 pt-2`,children:[M(g,{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`}),D(v,{variant:`primary`,size:`sm`,onClick:a,disabled:i.isPending||!t.trim(),children:[i.isPending?M(J,{className:`h-3.5 w-3.5 animate-spin`}):M(G,{className:`h-3.5 w-3.5`}),`Add`]})]})}function Se(){let{data:e,isLoading:t}=h(),[n,r]=j(null);function i(e){r(t=>t===e?null:e)}return t?D(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[M(J,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):D(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&M(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),e?.map(e=>M(be,{identity:e,expanded:n===e.id,onToggle:()=>i(e.id)},e.id)),M(xe,{})]})}function Ce(e){return e.base64===void 0||e.base64.length===0}function we(e){return e.filter(Ce).map(e=>e.faceId)}function Te(e){let t=0;for(let n of e)Ce(n)&&(t+=1);return t}E();function Ee(e){let[t,n]=j(null),[r,i]=j(null),[a,o]=j(!1);return N(()=>{if(n(null),i(null),o(!1),!e)return;let t=!1,r=null;return(async()=>{try{let i=await Q(`${ge}/${encodeURIComponent(e)}`);if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),N(()=>{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 De(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 Oe({label:e,value:t}){return D(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[M(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),M(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:t})]})}function ke({box:e}){return M(`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:M(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Face`})})}function Ae({face:e,cameraName:t,onClose:r,onAssign:i,onUnassign:o,onDelete:s,actionsPending:c}){let{data:l,isFetching:u}=a({faceId:e?.faceId??``},{enabled:e!==null}),[f,p]=j(`frame`),{frameSrc:m,naturalWidth:h,naturalHeight:g,failed:_}=Ee(e?.keyFrameMediaKey),y=O(()=>{let t=De(l??[]);return t?`data:image/jpeg;base64,${t.base64}`:e?.base64?`data:image/jpeg;base64,${e.base64}`:null},[l,e]),b=O(()=>!e?.faceBbox||h===null||g===null?null:R(e.faceBbox,h,g),[e?.faceBbox,h,g]);if(e===null)return null;let x=typeof e.keyFrameMediaKey==`string`&&e.keyFrameMediaKey.length>0&&!_,S=x&&f===`frame`,C=e.assigned?e.identityName??`Assigned`:e.recognizedIdentityId?`${e.identityName??`Recognized`} (suggested)`:`Unassigned`;return M(d,{open:!0,onOpenChange:e=>!e&&r(),children:D(n,{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:[D(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[D(`div`,{className:`min-w-0`,children:[M(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:`Face detail`}),M(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),M(`button`,{type:`button`,onClick:r,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:M(Y,{className:`h-4 w-4`})})]}),D(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[x&&D(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[D(`button`,{type:`button`,onClick:()=>p(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${f===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[M(I,{className:`h-3.5 w-3.5`}),` Full frame`]}),D(`button`,{type:`button`,onClick:()=>p(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${f===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[M(F,{className:`h-3.5 w-3.5`}),` Crop`]})]}),S&&m?M(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:M(V,{src:m,alt:`Full frame with detected face`,fit:`natural`,className:`w-full`,overlay:b?M(ke,{box:b}):void 0})}):y?D(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[M(V,{src:y,alt:`Detected face`,className:`h-full w-full`}),u&&M(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:M(J,{className:`h-3.5 w-3.5 animate-spin`})})]}):D(`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:[M(H,{className:`h-8 w-8 text-warning/70`}),M(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),M(`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.`})]}),D(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[M(Oe,{label:`Camera`,value:t}),M(Oe,{label:`Captured`,value:U(e.timestamp)}),M(Oe,{label:`Track`,value:e.trackId}),M(Oe,{label:`Identity`,value:C})]})]}),D(`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?D(v,{variant:`secondary`,onClick:()=>o(e.faceId),disabled:c,children:[M(L,{className:`h-3.5 w-3.5`}),` Detach`]}):D(v,{variant:`primary`,onClick:()=>i(e.faceId),disabled:c,children:[M(ee,{className:`h-3.5 w-3.5`}),` Assign`]}),D(v,{variant:`secondary`,onClick:()=>s(e.faceId),disabled:c,children:[M(X,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}E();var je=[[`faceGallery`]];function Me({faceIds:e,identities:t,onDone:a}){let s=A(),c=f(),l=r(),[u,p]=j(``),[h,_]=j(!1),[y,b]=j(null),S=e!==null&&e.length>0,C=e?.length??0;function w(){_(!1),p(``),b(null)}function T(){w(),a()}function E(t){!e||e.length===0||c.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{s.invalidateQueries({queryKey:je}),T()}})}function O(){!e||!u.trim()||l.mutate({name:u.trim()},{onSuccess:e=>{e?.id&&E(e.id)},onError:()=>{s.invalidateQueries({queryKey:je}),T()}})}let k=c.isPending||l.isPending;return M(d,{open:S,onOpenChange:e=>!e&&T(),children:D(n,{children:[D(i,{children:[M(m,{children:C>1?`Assign ${String(C)} faces to person`:`Assign face to person`}),M(o,{children:`Select an existing person or create a new one.`})]}),M(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>D(`button`,{type:`button`,onClick:()=>b(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${y===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[M(`span`,{className:`font-medium`,children:e.name}),D(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),h?M(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:M(g,{placeholder:`New person name…`,value:u,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&O()},autoFocus:!0,className:`flex-1`})}):M(`button`,{type:`button`,onClick:()=>{b(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…`}),D(x,{children:[M(v,{variant:`secondary`,onClick:T,disabled:k,children:`Cancel`}),h?D(v,{variant:`primary`,onClick:O,disabled:k||!u.trim(),children:[k&&M(J,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):D(v,{variant:`primary`,onClick:()=>y&&E(y),disabled:k||!y,children:[k&&M(J,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,C>1?` ${String(C)}`:``]})]})]})})}function Ne(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function Pe(e,t){return e.faceIds.filter(e=>!t.has(e))}function Fe(e,t){return e.faceIds.filter(e=>t(e))}E();var Ie=[[`faceGallery`]],Le=20,Re=.3,ze=.9,Be=.05,Ve=.5,He=2,Ue=10,We=2;function Ge({cluster:e,face:t,active:n,onSelect:r}){return D(`button`,{type:`button`,onClick:r,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:[M(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:t?.base64?M(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:``,className:`h-24 w-24 object-cover`}):M(H,{className:`h-24 w-24 p-6 text-foreground-subtle`})}),D(`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 Ke({face:e,cameraName:t,nowMs:n,excluded:r,onToggleExclude:i,onDelete:a,deletePending:o}){return D(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${r?`border-border opacity-40 grayscale`:`border-border`}`,children:[D(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[e.base64?M(V,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Face from ${t}`,className:`h-full w-full`}):D(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[M(H,{className:`h-7 w-7 text-warning/70`}),M(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}),M(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i()},className:`absolute right-1 top-1 z-10 rounded-full bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":r?`Include face`:`Exclude face`,title:r?`Include`:`Exclude`,children:M(r?_e:Y,{className:`h-3.5 w-3.5`})})]}),D(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[M(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),M(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:B(e.timestamp,n)})]}),M(`div`,{className:`mt-1 flex items-center justify-end border-t border-border/60 px-1 py-0.5`,children:M(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},disabled:o,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:o?M(J,{className:`h-4 w-4 animate-spin`}):M(X,{className:`h-4 w-4`})})})]})}function qe({open:e,onClose:t,byId:r,cameraName:i,nowMs:a,identities:o,selectMany:c}){let l=A(),u=w(),f=s(),[p,m]=j(Ve),[h,g]=j(We),[_,b]=j(null),[x,S]=j({}),[C,T]=j(null),{data:E,isFetching:P,refetch:F}=y({threshold:p,minClusterSize:h,limit:Le},{enabled:e}),I=E??[];N(()=>{S({})},[p,h]),N(()=>{if(I.length===0){b(null);return}I.some(e=>e.representativeFaceId===_)||b(I[0]?.representativeFaceId??null)},[I]);let L=O(()=>I.find(e=>e.representativeFaceId===_)??null,[I,_]),R=L?x[L.representativeFaceId]??new Set:new Set,z=O(()=>L?Fe(L,e=>r.has(e)):[],[L,r]),te=L?L.faceIds.length-z.length:0,B=L?Pe({...L,faceIds:z},R):[];function V(e){if(!L)return;let t=L.representativeFaceId;S(n=>({...n,[t]:Ne(n[t]??new Set,e)}))}function ne(){l.invalidateQueries({queryKey:Ie})}async function H(e){await u({title:`Delete face`,message:`Permanently deletes this face crop. This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&f.mutate({faceId:e},{onSettled:ne})}function re(){T(null),t()}function ie(){B.length!==0&&(c(B),re())}return D(d,{open:e,onOpenChange:e=>!e&&re(),children:[D(n,{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:[D(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border px-4 py-3`,children:[D(`div`,{className:`flex items-center justify-between gap-2`,children:[D(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[M(he,{className:`h-4 w-4 text-primary`}),` Look-alike groups`]}),M(`button`,{type:`button`,onClick:re,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:M(Y,{className:`h-4 w-4`})})]}),D(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[D(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Threshold`,M(`input`,{type:`range`,min:Re,max:ze,step:Be,value:p,onChange:e=>m(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),M(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:p.toFixed(2)})]}),D(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Min size`,M(`input`,{type:`number`,min:He,max:Ue,step:1,value:h,onChange:e=>g(Math.min(Ue,Math.max(He,Number(e.target.value)||He))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),D(v,{variant:`secondary`,onClick:()=>{S({}),F()},disabled:P,children:[P?M(J,{className:`h-3.5 w-3.5 animate-spin`}):M(le,{className:`h-3.5 w-3.5`}),`Re-analyze`]})]})]}),M(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:P&&I.length===0?D(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[M(J,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):I.length===0?M(`div`,{className:`flex flex-1 items-center justify-center py-8 text-xs text-foreground-subtle`,children:`No look-alike groups at this threshold.`}):D(k,{children:[M(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:I.map(e=>M(Ge,{cluster:e,face:r.get(e.representativeFaceId),active:e.representativeFaceId===_,onSelect:()=>b(e.representativeFaceId)},e.representativeFaceId))}),M(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:I.map(e=>M(Ge,{cluster:e,face:r.get(e.representativeFaceId),active:e.representativeFaceId===_,onSelect:()=>b(e.representativeFaceId)},e.representativeFaceId))}),M(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:L&&D(k,{children:[te>0&&D(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:[te,` not loaded — excluded from actions`]}),M(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,1fr))] gap-2`,children:z.map(e=>{let t=r.get(e);return t?M(Ke,{face:t,cameraName:i(t.deviceId),nowMs:a,excluded:R.has(e),onToggleExclude:()=>V(e),onDelete:()=>void H(e),deletePending:f.isPending&&f.variables?.faceId===e},e):null})})]})})]})}),D(`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:[M(v,{variant:`secondary`,onClick:ie,disabled:B.length===0,children:`Select in gallery`}),D(v,{variant:`primary`,onClick:()=>T(B),disabled:B.length===0,children:[M(ee,{className:`h-3.5 w-3.5`}),` Adopt (`,B.length,`)`]})]})]}),M(Me,{faceIds:C,identities:o,onDone:()=>T(null)})]})}E();var Je=[[`faceGallery`]],Ye=500,Xe=120;function Ze({face:e,cameraName:t,nowMs:n,selected:r,onToggleSelect:i,onAssign:a,onOpenDetail:o}){let c=A(),l=C(),u=s(),d=()=>{c.invalidateQueries({queryKey:Je})},f=()=>o(e.faceId);return D(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${r?`border-primary ring-1 ring-primary`:`border-border`}`,children:[D(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[e.base64?M(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Face from ${t}`,onClick:f,className:`h-full w-full cursor-zoom-in object-cover`}):D(`button`,{type:`button`,onClick:f,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:[M(H,{className:`h-7 w-7 text-warning/70`}),M(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}),M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),i(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":r?`Deselect`:`Select`,children:r?M(ue,{className:`h-4 w-4 text-primary`}):M(de,{className:`h-4 w-4`})})]}),D(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[M(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),M(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:B(e.timestamp,n)}),e.identityName&&M(`p`,{className:`text-[10px] font-medium text-primary truncate`,title:e.identityName,children:e.identityName})]}),D(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),l.mutate({faceId:e.faceId},{onSettled:d})},disabled:l.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:l.isPending?M(J,{className:`h-4 w-4 animate-spin`}):M(L,{className:`h-4 w-4`})}):M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(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:M(ee,{className:`h-4 w-4`})}),M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),u.mutate({faceId:e.faceId},{onSettled:d})},disabled:u.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:u.isPending?M(J,{className:`h-4 w-4 animate-spin`}):M(X,{className:`h-4 w-4`})})]})]})}var Qe=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function $e(){let e=A(),[t,n]=j(`all`),[r,i]=j(oe),[a,o]=j(new Set),[c,u]=j(new Set),[d,p]=j(null),[m,g]=j(!1),[y,x]=j(null),{data:S,isLoading:w}=_({limit:Ye,filter:t},{refetchInterval:3e4}),{data:T=[]}=h(),{data:E}=l({}),N=f(),P=C(),F=b(),I=s(),R=Date.now(),B=S??[],V=O(()=>{let e=new Map;for(let t of E??[])e.set(t.id,t.name);return e},[E]),U=e=>V.get(e)??`Camera #${String(e)}`,se=O(()=>te(B).map(e=>({id:e,name:U(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[B,V]),W=O(()=>ne(ce(B,r),a),[B,r,a]),G=re(W,Xe,O(()=>JSON.stringify([t,r.fromMs,r.toMs,[...a].sort((e,t)=>e-t)]),[t,r.fromMs,r.toMs,a])),le=O(()=>new Map(B.map(e=>[e.faceId,e])),[B]),ue=O(()=>Te(W),[W]),de=y===null?null:le.get(y)??null,K=()=>{e.invalidateQueries({queryKey:Je})},q=()=>u(new Set);function fe(e){u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function pe(e){u(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function me(){pe(we(W))}let Z=[...c],Q=N.isPending||F.isPending||I.isPending,ge=P.isPending||I.isPending;function _e(){Z.length!==0&&F.mutate({faceIds:Z},{onSettled:()=>{K(),q()}})}function ve(){Z.length!==0&&Promise.allSettled(Z.map(e=>I.mutateAsync({faceId:e}))).then(()=>{K(),q()})}function $(e){x(null),p([e])}function ye(e){P.mutate({faceId:e},{onSettled:K}),x(null)}function be(e){I.mutate({faceId:e},{onSettled:K}),x(null)}let xe=W.length!==B.length;return D(`div`,{className:`relative space-y-3`,children:[D(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[M(`div`,{className:`flex items-center gap-1`,children:Qe.map(e=>M(`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))}),M(z,{onChange:i}),M(ie,{cameras:se,selected:a,onChange:o}),D(`button`,{type:`button`,onClick:()=>g(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${m?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[M(he,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!w&&ue>0&&D(`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:[M(H,{className:`h-3.5 w-3.5`}),` Select `,ue,` crop-less`]}),!w&&M(`span`,{className:`text-[10px] text-foreground-subtle ${ue>0?`ml-2`:`ml-auto`}`,children:xe?`${String(W.length)} of ${String(B.length)} faces`:`${String(W.length)} face${W.length===1?``:`s`}`})]}),c.size>0&&D(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[D(`span`,{className:`text-xs font-medium text-foreground`,children:[c.size,` selected`]}),D(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[D(v,{variant:`primary`,onClick:()=>p(Z),disabled:Q,children:[M(ee,{className:`h-3.5 w-3.5`}),` Assign`]}),D(v,{variant:`secondary`,onClick:_e,disabled:Q,children:[F.isPending?M(J,{className:`h-3.5 w-3.5 animate-spin`}):M(L,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),D(v,{variant:`secondary`,onClick:ve,disabled:Q,children:[M(X,{className:`h-3.5 w-3.5`}),` Delete`]}),M(v,{variant:`ghost`,onClick:q,disabled:Q,children:M(Y,{className:`h-3.5 w-3.5`})})]})]}),w&&D(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[M(J,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!w&&W.length===0&&M(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:B.length>0?`No faces match the current date / camera filters.`:`No faces found for this filter.`}),!w&&W.length>0&&D(k,{children:[M(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(6.5rem,1fr))] gap-2`,children:G.pageItems.map(e=>M(Ze,{face:e,cameraName:U(e.deviceId),nowMs:R,selected:c.has(e.faceId),onToggleSelect:fe,onAssign:e=>p([e]),onOpenDetail:x},e.faceId))}),M(ae,{currentPage:G.page,totalItems:G.totalItems,pageSize:G.pageSize,onPageChange:G.setPage,itemNoun:`faces`})]}),M(Ae,{face:de,cameraName:de?U(de.deviceId):``,onClose:()=>x(null),onAssign:$,onUnassign:ye,onDelete:be,actionsPending:ge}),M(Me,{faceIds:d,identities:T,onDone:()=>{p(null),q()}}),M(qe,{open:m,onClose:()=>g(!1),byId:le,cameraName:U,nowMs:R,identities:T,selectMany:pe})]})}E();var et=[[`faceGallery`]],tt=2e3;function nt(){let e=A(),t=T(e);t.current=e;let n=T(void 0);n.current||=se({delayMs:tt,invalidate:()=>{t.current.invalidateQueries({queryKey:et})}}),N(()=>()=>n.current?.cancel(),[]),c(P.PipelineAnalyticsFaceGalleryChanged,()=>{n.current?.trigger()})}function rt(){return nt(),M(Z,{icon:me,title:`Faces`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:D(`section`,{className:`space-y-3`,children:[D(`div`,{children:[M(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),M(`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.`}),M(Se,{})]}),D(`div`,{className:`pt-4 border-t border-border`,children:[M(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),M(`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.`}),M($e,{})]})]})})}export{rt as DetectionIntelligencePage};