@camstack/addon-admin-ui 1.0.5 → 1.0.7

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 (82) hide show
  1. package/dist/assets/{AddLocationWizard-B5dkIoQ2.js → AddLocationWizard-BPXjVkoq.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-DVB69ClF.js → AddonCollectionPage-BHk_82L1.js} +1 -1
  3. package/dist/assets/{Addons-Bfvs6-g0.js → Addons-Bu6k7qrw.js} +1 -1
  4. package/dist/assets/{AdminTabs-BWNsXXy4.js → AdminTabs-C5BWg3Pz.js} +1 -1
  5. package/dist/assets/{BrokerForm-DYIjeusD.js → BrokerForm-CwBhT_Zu.js} +1 -1
  6. package/dist/assets/{BrokerStep-DjzuHh1z.js → BrokerStep-kInoZsZ8.js} +1 -1
  7. package/dist/assets/{Capabilities-hicnOVum.js → Capabilities-DazohgP2.js} +1 -1
  8. package/dist/assets/{CapabilityBadges-CSyidKVA.js → CapabilityBadges-CqlDFU27.js} +1 -1
  9. package/dist/assets/Cluster-vA3G3Xt-.js +1 -0
  10. package/dist/assets/{Dashboard-BkLuDhPq.js → Dashboard-CIarzGjr.js} +1 -1
  11. package/dist/assets/{Data-Beh_0Rmk.js → Data-CBUx81MG.js} +1 -1
  12. package/dist/assets/{DetectionIntelligence-BfxtDLUn.js → DetectionIntelligence-DmE8QQvK.js} +1 -1
  13. package/dist/assets/DeviceDetail-DqTWl3Kz.js +2 -0
  14. package/dist/assets/{Devices-DzX3RWXL.js → Devices-KDtIE02J.js} +1 -1
  15. package/dist/assets/{EmbedPlayerPage-WJHXt2K5.js → EmbedPlayerPage-BcG6bilu.js} +1 -1
  16. package/dist/assets/{FormBuilder-C_FGp6fK.js → FormBuilder-DBTf1H_B.js} +1 -1
  17. package/dist/assets/Identity-CYHFXu1M.js +1 -0
  18. package/dist/assets/IntegrationDetail-DqViKcp6.js +1 -0
  19. package/dist/assets/{Integrations-DMJL2wGt.js → Integrations-BXICd-JI.js} +1 -1
  20. package/dist/assets/{Integrations-DdxCeVlW.js → Integrations-Cyg_bOkD.js} +1 -1
  21. package/dist/assets/{Logs-Czo2ju6R.js → Logs-kzrdYdPu.js} +1 -1
  22. package/dist/assets/{MotionZonesSettings-DSz0ZQ3J.js → MotionZonesSettings-C1INb9Ec.js} +1 -1
  23. package/dist/assets/{MyAccess-CiRVe6o4.js → MyAccess-DvxBmUhb.js} +1 -1
  24. package/dist/assets/{Network-2_yW2eMz.js → Network-BEet8LbP.js} +1 -1
  25. package/dist/assets/{NodeAddonsSettingsPanel-CWOXJvnI.js → NodeAddonsSettingsPanel-BU3fsQhW.js} +1 -1
  26. package/dist/assets/Pipeline-C460Q1dM.js +1 -0
  27. package/dist/assets/{PrivacyMaskSettings-CrWASNzq.js → PrivacyMaskSettings-Isrt2Rzc.js} +1 -1
  28. package/dist/assets/{ProviderIcon-DU7EkOsQ.js → ProviderIcon-BS00rCO4.js} +1 -1
  29. package/dist/assets/{Settings-Ba4e7VPd.js → Settings-BPtVhsDv.js} +1 -1
  30. package/dist/assets/{Showroom-fzNXeqzs.js → Showroom-qtUMm-lj.js} +1 -1
  31. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-OIn_kS_J.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BCWO2hJt.js} +1 -1
  32. package/dist/assets/{bell-PpkN_TgJ.js → bell-CRa7XWAs.js} +1 -1
  33. package/dist/assets/circle-check-big-Ca1L631f.js +1 -0
  34. package/dist/assets/{copy-D3XNVDYo.js → copy-Bi-BgxBp.js} +1 -1
  35. package/dist/assets/{dist-DyYmhGqc.js → dist-B82tlPWR.js} +1 -1
  36. package/dist/assets/dist-B8KtyWbO.js +1 -0
  37. package/dist/assets/{download-BHYjG90K.js → download-Bq_ArgRU.js} +1 -1
  38. package/dist/assets/esm-C6_--ziT.js +7 -0
  39. package/dist/assets/{hostInit-BykkFKC1.js → hostInit-B8ISRO-X.js} +1 -1
  40. package/dist/assets/{index-DpTstpp_.js → index-D5OTguVm.js} +3 -3
  41. package/dist/assets/index-D5fms8eH.css +2 -0
  42. package/dist/assets/{key-round-Dn1oOWgV.js → key-round-DdK6mTCz.js} +1 -1
  43. package/dist/assets/{mf-entry-bootstrap-0-04dcd8db.js → mf-entry-bootstrap-0-ebe1e057.js} +2 -2
  44. package/dist/assets/{pencil-Kbj4_JBR.js → pencil-WwVUhRC9.js} +1 -1
  45. package/dist/assets/{player-overlays-zGqQhGgE.js → player-overlays-ZG1nYuYj.js} +1 -1
  46. package/dist/assets/plus-D2fCWFPc.js +1 -0
  47. package/dist/assets/{radio-CTfNJnG5.js → radio-B8E0UhzS.js} +1 -1
  48. package/dist/assets/{refresh-cw-BnmOdHXx.js → refresh-cw-DewUBhjl.js} +1 -1
  49. package/dist/assets/remoteEntry-vWrz4ebK.js +1 -0
  50. package/dist/assets/{rotate-ccw-UF_FErzF.js → rotate-ccw-CZ8RwUso.js} +1 -1
  51. package/dist/assets/rotate-cw-DiyghCam.js +1 -0
  52. package/dist/assets/search-DZ8Fw9-F.js +1 -0
  53. package/dist/assets/{server-DK5PS_QF.js → server-DnaOYw5t.js} +1 -1
  54. package/dist/assets/{sparkles-B5Duaxbv.js → sparkles-D9CcRRON.js} +1 -1
  55. package/dist/assets/square-CO0xPDBD.js +1 -0
  56. package/dist/assets/{square-check-big-qiutr_Ci.js → square-check-big-9Ki4zQ6C.js} +1 -1
  57. package/dist/assets/src-BB1LG2-C.js +34 -0
  58. package/dist/assets/src-Cno9Ci3x.js +1 -0
  59. package/dist/assets/{upload-Btk1HMIN.js → upload-DHwenRyJ.js} +1 -1
  60. package/dist/assets/{useDevice-uoMH2oPD.js → useDevice-BuSIXBXp.js} +1 -1
  61. package/dist/assets/{useEventInvalidation-DDUSWISR.js → useEventInvalidation-wNGhDdi_.js} +1 -1
  62. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-s1j_uW8u.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-OHA5nJNY.js} +2 -2
  63. package/dist/assets/{wifi-DH-9OMrB.js → wifi-BJgMgcFe.js} +1 -1
  64. package/dist/assets/{zap-Cpoh2hjh.js → zap-BAH9oFRn.js} +1 -1
  65. package/dist/index.html +6 -6
  66. package/dist/server/addon.js +1299 -1074
  67. package/package.json +1 -1
  68. package/dist/assets/Cluster-AyC6G6sS.js +0 -7
  69. package/dist/assets/DeviceDetail-DGlm0ka0.js +0 -2
  70. package/dist/assets/Identity-oMA7lRlr.js +0 -1
  71. package/dist/assets/IntegrationDetail-DUzh5vXL.js +0 -1
  72. package/dist/assets/Pipeline-MNGNVhOO.js +0 -1
  73. package/dist/assets/circle-check-big-BzSkZiMj.js +0 -1
  74. package/dist/assets/dist-CyLsBIs8.js +0 -1
  75. package/dist/assets/index-COZOEwaJ.css +0 -2
  76. package/dist/assets/plus-CPqVcqUV.js +0 -1
  77. package/dist/assets/remoteEntry-BKwb226y.js +0 -1
  78. package/dist/assets/rotate-cw-B4szmAxG.js +0 -1
  79. package/dist/assets/search-C07n9Z2S.js +0 -1
  80. package/dist/assets/square-Bex0hnGW.js +0 -1
  81. package/dist/assets/src-DqOo0bwK.js +0 -1
  82. package/dist/assets/src-Dxc7AUYA.js +0 -34
@@ -1 +1 @@
1
- import{At as e,Dt as t,Et as n,Mi as r,Mt as i,Nt as a,Ot as o,Pt as s,Ri as c,ai as l,ii as u,jt as d,kt as f,ri as p,si as m,ut as h}from"./src-Dxc7AUYA.js";import{F as g,G as _,R as v,U as y,X as b,b as x,o as S,x as C,y as w}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{D as T}from"./src-DqOo0bwK.js";import{t as E}from"./download-BHYjG90K.js";import{i as D,n as O,r as k,t as A}from"./AddLocationWizard-B5dkIoQ2.js";import{t as j}from"./plus-CPqVcqUV.js";import{t as M}from"./rotate-cw-B4szmAxG.js";import{B as N,M as P,P as F,R as ee,i as I,s as L,x as R}from"./index-DpTstpp_.js";import{t as z}from"./AdminPage-CN6ZMhf0.js";import{t as B}from"./format-size-CO9d3C3-.js";import{t as V}from"./AdminTabs-BWNsXXy4.js";var H=N(`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`}]]),te=N(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),ne=N(`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`}]]);b();function U(){let e=S(),t=r(),{data:n,isLoading:i,isError:a}=l({}),o=u(),s=y(()=>o.data??[],[o.data]),[c,d]=_(null),[f,h]=_(null),g=p({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),v=m({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),b=e=>{e.isDefault||v.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=i||o.isLoading,D=a||o.isError;return C(z,{children:[E&&x(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),D&&x(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!E&&!D&&C(`div`,{className:`space-y-3`,children:[s.length===0&&x(`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=>x(k,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:T.get(e.id)??[],onAdd:e=>d(e),onEdit:e=>h(e),onDelete:e=>{w(e)},onSetDefault:e=>b(e)},e.id))]}),c!==null&&x(A,{initialType:c,onClose:()=>d(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),d(null)}}),f!==null&&x(O,{location:f,onClose:()=>h(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),h(null)}})]})}b();var W=[[`backup`,`listDestinations`]],G=[`backup`,`listArchives`];function K({destinationId:e,restoreSupported:t,onOpenRestoreWizard:i}){let a=S(),s=r(),{data:c,isLoading:l,isError:u}=o({destinationId:e}),d=c??[],f=n({onSuccess:()=>{a.invalidateQueries({queryKey:[[...G]]}),a.invalidateQueries({queryKey:W})}}),p=g(async t=>{await s({title:`Delete this archive?`,message:`Permanently deletes "${t.label??t.id}" and frees ${B(t.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&f.mutate({destinationId:e,backupId:t.id})},[s,e,f]),[m,h]=_(null),v=g(async t=>{h(t.id);try{let n=localStorage.getItem(`camstack_admin_token`),r={};n&&(r.Authorization=`Bearer ${n}`);let i=await fetch(q(e,t.id),{headers:r});if(!i.ok)throw Error(`download failed: ${i.status} ${i.statusText}`);let a=await i.blob(),o=URL.createObjectURL(a),s=document.createElement(`a`);s.href=o,s.download=`${t.label??t.id}.tar.gz`,document.body.appendChild(s),s.click(),s.remove(),URL.revokeObjectURL(o)}finally{h(null)}},[e]),b=y(()=>[...d].toSorted((e,t)=>t.createdAt-e.createdAt),[d]);return l?x(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):u?x(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):b.length===0?x(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):x(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[640px]`,children:[x(`thead`,{children:C(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[x(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),x(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),x(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),x(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),x(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),x(`tbody`,{children:b.map(n=>C(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[x(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:J(n.createdAt)}),x(`td`,{className:`px-3 py-1.5 text-foreground`,children:n.label??x(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),x(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:n.locations.join(`, `)}),x(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:B(n.sizeBytes)}),x(`td`,{className:`px-3 py-1.5`,children:C(`div`,{className:`flex items-center justify-end gap-1`,children:[C(`button`,{onClick:()=>{v(n)},disabled:m===n.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:[m===n.id?x(R,{className:`h-3 w-3 animate-spin`}):x(E,{className:`h-3 w-3`}),`Download`]}),t&&i&&C(`button`,{onClick:()=>i({destinationId:e,archiveId:n.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:[x(M,{className:`h-3 w-3`}),`Restore`]}),x(`button`,{onClick:()=>{p(n)},disabled:f.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:f.isPending?x(R,{className:`h-3 w-3 animate-spin`}):x(L,{className:`h-3 w-3`})})]})})]},n.id))})]})})}function q(e,t){return`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function J(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}b();var Y=[{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 X(e){let t=e.trim();for(let e of Y)if(e.cron===t)return e.id;return`custom`}function Z({value:e,onChange:t,previewCount:n=5,disabled:r=!1}){let i=X(e),[a,o]=_(i===`custom`);v(()=>{i!==`custom`&&o(!1)},[i]);let s=ae(e,250),c=d({cron:s,count:n},{enabled:s.trim().length>0}),l=c.data??null,u=e=>{o(!1),t(e.cron)},f=a||i===`custom`;return C(`div`,{className:`space-y-3`,children:[C(`div`,{className:`space-y-1`,children:[x(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),C(`div`,{className:`flex flex-wrap gap-1.5`,children:[Y.map(e=>x(`button`,{type:`button`,onClick:()=>u(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)),x(`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&&C(`div`,{className:`space-y-1`,children:[x(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),x(`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`}),C(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,x(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),x(re,{cron:s,preview:l,loading:c.isFetching})]})}function re({cron:e,preview:t,loading:n}){return n&&t===null?C(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[x(R,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?x(`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.`}):C(`div`,{className:`space-y-1`,children:[x(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),x(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>C(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[x(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),x(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:ie(e)})]},`${e}-${t}`))})]}):x(`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 ie(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 ae(e,t){let[n,r]=_(e),i=y(()=>e,[e]);return v(()=>{let e=setTimeout(()=>r(i),t);return()=>clearTimeout(e)},[i,t]),n}b();var oe=[[`backup`,`listDestinations`]];function se({onCreateAt:e,onOpenRestoreWizard:t}){let{data:n,isLoading:r,isError:i}=f(),a=n??[],[o,s]=_(null),c=e=>{s(t=>t===e?null:e)},l=fe();return r?x(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading destinations…`}):i?x(`div`,{className:`text-xs text-danger`,children:`Failed to load destinations`}):a.length===0?x(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:x(`p`,{className:`text-xs text-foreground-subtle`,children:"No `backups`-typed storage locations registered. Add one in Settings → Storage to begin."})}):x(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[720px]`,children:[x(`thead`,{children:C(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[x(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),x(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Destination`}),x(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),x(`th`,{className:`text-left px-3 py-2 font-medium w-28`,children:`Retention`}),x(`th`,{className:`text-left px-3 py-2 font-medium w-56`,children:`Schedule`}),x(`th`,{className:`text-left px-3 py-2 font-medium w-44`,children:`Last success`}),x(`th`,{className:`text-right px-3 py-2 font-medium w-44`,children:`Actions`})]})}),x(`tbody`,{children:a.map(n=>{let r=l.get(n.id);return x(ce,{row:n,isOpen:o===n.id,onToggle:()=>c(n.id),onCreateAt:e,liveLastSuccessAt:r?.at,liveLastSuccessSizeBytes:r?.sizeBytes,...t?{onOpenRestoreWizard:t}:{}},n.id)})})]})})}function ce({row:e,isOpen:t,onToggle:n,onCreateAt:r,onOpenRestoreWizard:i,liveLastSuccessAt:a,liveLastSuccessSizeBytes:o}){let c=S(),l=s({onSuccess:()=>{c.invalidateQueries({queryKey:oe})}}),[u,d]=_(String(e.retentionCount));v(()=>{d(String(e.retentionCount))},[e.retentionCount]);let[f,p]=_(!1),m=g(t=>{l.mutate({locationId:e.id,enabled:t,retentionCount:e.retentionCount,...e.label===void 0?{}:{label:e.label},...e.cron===void 0?{}:{cron:e.cron}})},[l,e.id,e.retentionCount,e.label,e.cron]),h=g(()=>{let t=Number.parseInt(u,10);if(Number.isNaN(t)||t<1){d(String(e.retentionCount));return}t!==e.retentionCount&&l.mutate({locationId:e.id,enabled:e.enabled,retentionCount:t,...e.label===void 0?{}:{label:e.label},...e.cron===void 0?{}:{cron:e.cron}})},[l,u,e.id,e.enabled,e.retentionCount,e.label,e.cron]),y=g(t=>{l.mutate({locationId:e.id,enabled:e.enabled,retentionCount:e.retentionCount,...e.label===void 0?{}:{label:e.label},cron:t},{onSuccess:()=>{p(!1)}})},[l,e.id,e.enabled,e.retentionCount,e.label]);return C(w,{children:[C(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[x(`td`,{className:`px-2 py-2`,children:x(`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:x(t?F:P,{className:`h-3.5 w-3.5`})})}),x(`td`,{className:`px-3 py-2`,children:C(`button`,{onClick:n,className:`text-left hover:underline focus:outline-none`,title:`View archives`,children:[x(`div`,{className:`text-foreground font-medium`,children:e.displayName}),C(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[x(`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}),x(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]})}),x(`td`,{className:`px-3 py-2`,children:x(`label`,{className:`inline-flex items-center cursor-pointer`,children:x(`input`,{type:`checkbox`,className:`accent-primary`,checked:e.enabled,disabled:l.isPending,onChange:e=>m(e.target.checked)})})}),x(`td`,{className:`px-3 py-2`,children:x(`input`,{type:`number`,min:1,max:1e3,value:u,disabled:l.isPending,onChange:e=>d(e.target.value),onBlur:h,onKeyDown:t=>{t.key===`Enter`&&t.target.blur(),t.key===`Escape`&&d(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`})}),x(`td`,{className:`px-3 py-2`,children:x(le,{cron:e.cron,nextRunAt:e.nextRunAt,onEdit:()=>p(!0),disabled:l.isPending})}),x(`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?x(`span`,{className:`italic`,children:`Never`}):x(me,{at:t,sizeBytes:n})})()}),x(`td`,{className:`px-3 py-2`,children:x(`div`,{className:`flex items-center justify-end gap-1.5`,children:e.triggerSupported&&C(`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:[x(j,{className:`h-3 w-3`}),`Create here`]})})})]}),t&&x(`tr`,{className:`border-t border-border bg-background/30`,children:x(`td`,{colSpan:7,className:`px-4 py-3`,children:x(K,{destinationId:e.id,restoreSupported:e.restoreSupported,...i?{onOpenRestoreWizard:i}:{}})})}),f&&x(de,{destinationName:e.displayName,currentCron:e.cron??``,onSave:y,onClose:()=>p(!1),saving:l.isPending,saveError:l.error instanceof Error?l.error.message:null})]})}function le({cron:e,nextRunAt:t,onEdit:n,disabled:r}){let i=typeof e==`string`&&e.trim().length>0;return C(`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:[C(`div`,{className:`flex items-center gap-1.5`,children:[x(ne,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),x(`span`,{className:i?`font-mono text-foreground`:`italic text-foreground-subtle`,children:i?e:`Manual`})]}),i&&t!==void 0&&C(`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]=_(t);return x(`tr`,{children:x(`td`,{colSpan:7,className:`p-0`,children:x(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:C(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[C(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[C(`div`,{className:`space-y-0.5`,children:[x(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Schedule`}),C(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e]})]}),x(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,title:`Close`,children:x(I,{className:`h-4 w-4`})})]}),C(`div`,{className:`p-4`,children:[x(Z,{value:o,onChange:s,disabled:i}),a!==null&&x(`div`,{className:`mt-3 rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:a})]}),C(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[x(`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`}),x(`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}=c(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 C(`span`,{title:y(()=>new Date(e).toLocaleString(),[e]),className:`text-foreground tabular-nums`,children:[n,t!==void 0&&C(`span`,{className:`ml-1 text-foreground-subtle`,children:[`· `,B(t)]})]})}function he(e){let[,t]=_(0);return v(()=>{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`}b();var _e=[[`backup`,`list`]];function ve({initialDestinationId:e,initialArchiveId:n,onClose:r,onScheduled:a}){let s=S(),[c,l]=_(e&&n?2:1),[u,d]=_(e),[p,m]=_(n),[h,g]=_(new Set),{data:b}=f(),w=b??[],{data:T,isLoading:E}=o({destinationId:u??``},{enabled:!!u}),D=T??[];v(()=>{if(u!==void 0)return;let e=w.filter(e=>e.restoreSupported);e.length===1&&d(e[0].id)},[u,w]);let{data:O}=t({destinationId:u??``,backupId:p??``},{enabled:!!u&&!!p}),k=y(()=>O?.locations??[],[O]);v(()=>{k.length!==0&&g(e=>e.size===0?new Set(k):e)},[k]);let A=i({onSuccess:()=>{s.invalidateQueries({queryKey:_e}),a(),r()}}),j=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},N=!!u&&!!p,P=h.size>0,F=N&&P&&!A.isPending,L=()=>{!u||!p||A.mutate({destinationId:u,backupId:p,locations:[...h]})};return x(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[C(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[C(`div`,{className:`space-y-0.5`,children:[x(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),C(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,c,` of 3 —`,` `,c===1?`pick source`:c===2?`pick locations`:`confirm`]})]}),x(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,children:x(I,{className:`h-4 w-4`})})]}),c===1&&x(ye,{destinations:w,destinationId:u,onPickDestination:e=>{d(e),m(void 0),g(new Set)},archives:D,archivesLoading:E,archiveId:p,onPickArchive:m}),c===2&&x(be,{locations:k,picked:h,onToggle:j}),c===3&&x(xe,{destinationName:w.find(e=>e.id===u)?.displayName??u??``,archive:D.find(e=>e.id===p),picked:[...h]}),C(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[x(`div`,{children:c>1&&C(`button`,{onClick:()=>l(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:[x(ee,{className:`h-3 w-3`}),`Back`]})}),C(`div`,{className:`flex items-center gap-2`,children:[x(`button`,{onClick:r,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),c<3?C(`button`,{disabled:c===1&&!N||c===2&&!P,onClick:()=>l(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`,x(te,{className:`h-3 w-3`})]}):C(`button`,{onClick:L,disabled:!F,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?x(R,{className:`h-3.5 w-3.5 animate-spin`}):x(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 C(`div`,{className:`p-4 space-y-3`,children:[C(`div`,{className:`space-y-1.5`,children:[x(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),C(`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:[x(`option`,{value:``,disabled:!0,children:`Select destination…`}),s.map(e=>C(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),C(`div`,{className:`space-y-1.5`,children:[x(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&x(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&i&&x(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!i&&r.length===0&&x(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&r.length>0&&x(`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 C(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[C(`div`,{className:`flex items-center gap-2`,children:[x(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>o(e.id),className:`accent-primary`}),C(`div`,{children:[x(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),x(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),x(`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?x(`div`,{className:`p-4`,children:x(`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.`})}):C(`div`,{className:`p-4 space-y-3`,children:[x(`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.`}),C(`div`,{className:`space-y-1.5`,children:[x(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),x(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>C(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[x(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>n(e),className:`accent-primary`}),x(`span`,{className:`font-mono text-foreground`,children:e}),x(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ce(e)})]},e))})]})]})}function xe({destinationName:e,archive:t,picked:n}){return C(`div`,{className:`p-4 space-y-3 text-xs`,children:[x(`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.`}),C(`dl`,{className:`space-y-1.5`,children:[x(Q,{term:`Destination`,value:e}),x(Q,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&x(Q,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${B(t.sizeBytes)}`}),x(Q,{term:`Locations`,value:n.length>0?n.join(`, `):`— (full archive)`})]})]})}function Q({term:e,value:t}){return C(`div`,{className:`flex justify-between gap-3`,children:[x(`dt`,{className:`text-foreground-subtle`,children:e}),x(`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]??``}b();var $=[[`backup`,`list`]],we=[[`backup`,`listLocations`]];function Te(){let t=S(),n=r(),{data:i}=e(),o=a({onSuccess:()=>{t.invalidateQueries({queryKey:$}),t.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),t.invalidateQueries({queryKey:[[`backup`,`listArchives`]]})}}),s=h(),[c,l]=_(null),[u,d]=_(null),[f,p]=_(!1),[m,g]=_(!1),[v,y]=_(!1),b=async()=>{await n({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&s.mutate({confirm:!0})};return C(z,{children:[C(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[C(`button`,{onClick:()=>p(!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:[x(M,{className:`h-3.5 w-3.5`}),`Restore…`]}),C(`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:[x(j,{className:`h-3.5 w-3.5`}),`Add destination`]})]}),m&&x(`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:C(`div`,{className:`flex items-center justify-between gap-3`,children:[C(`div`,{className:`flex items-center gap-2`,children:[x(M,{className:`h-3.5 w-3.5`}),x(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),C(`button`,{onClick:()=>{b()},disabled:s.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:[s.isPending?x(R,{className:`h-3.5 w-3.5 animate-spin`}):x(M,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),x(se,{onCreateAt:e=>l(e),onOpenRestoreWizard:e=>d(e)}),c&&x(Ee,{destination:c,locations:i??[],onClose:()=>l(null),onSubmit:(e,n)=>{o.mutate({destinations:[c.id],locations:e,label:n||void 0},{onSuccess:()=>{l(null),t.invalidateQueries({queryKey:we})}})},submitting:o.isPending}),(u||f)&&x(ve,{...u?{initialDestinationId:u.destinationId,initialArchiveId:u.archiveId}:{},onClose:()=>{d(null),p(!1)},onScheduled:()=>g(!0)}),v&&x(A,{initialType:`backups`,onClose:()=>y(!1),onCreated:()=>{y(!1),t.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]})}})]})}function Ee({destination:e,locations:t,onClose:n,onSubmit:r,submitting:i}){let a=t.filter(e=>e.present),[o,s]=_(``),[c,l]=_(()=>new Set(a.map(e=>e.name))),u=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return x(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[C(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[C(`div`,{className:`space-y-0.5`,children:[x(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Create Backup`}),C(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e.displayName]})]}),x(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:x(I,{className:`h-4 w-4`})})]}),C(`div`,{className:`p-4 space-y-3`,children:[C(`div`,{className:`space-y-1`,children:[x(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Label (optional)`}),x(`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`})]}),C(`div`,{className:`space-y-1.5`,children:[x(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Include`}),C(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:[a.length===0&&x(`div`,{className:`px-3 py-2 text-xs text-foreground-subtle italic`,children:`Nothing to back up.`}),a.map(e=>C(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[C(`div`,{className:`flex items-center gap-2`,children:[x(`input`,{type:`checkbox`,checked:c.has(e.name),onChange:()=>u(e.name),className:`accent-primary`}),x(`span`,{className:`font-mono text-foreground`,children:e.name})]}),C(`div`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[B(e.sizeBytes),` · `,e.fileCount,` files`]})]},e.name))]})]})]}),C(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[x(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),C(`button`,{onClick:()=>r(Array.from(c),o.trim()),disabled:i||c.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?x(R,{className:`h-3.5 w-3.5 animate-spin`}):x(H,{className:`h-3.5 w-3.5`}),i?`Creating…`:`Create`]})]})]})})}function De(){return x(`div`,{className:`flex flex-col p-4`,children:x(V,{tabs:[{id:`storage`,label:`Storage`,icon:D,content:x(U,{})},{id:`backup`,label:`Backup`,icon:H,content:x(Te,{})}]})})}export{De as DataPage};
1
+ import{At as e,Bi as t,Dt as n,Et as r,Mt as i,Nt as a,Ot as o,Pi as s,Pt as c,ai as l,jt as u,kt as d,li as f,oi as p,si as m,ut as h}from"./src-BB1LG2-C.js";import{F as g,G as _,R as v,U as y,X as b,b as x,o as S,x as C,y as w}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{D as T}from"./src-Cno9Ci3x.js";import{t as E}from"./download-Bq_ArgRU.js";import{i as D,n as O,r as k,t as A}from"./AddLocationWizard-BPXjVkoq.js";import{t as j}from"./plus-D2fCWFPc.js";import{t as M}from"./rotate-cw-DiyghCam.js";import{B as N,M as P,P as F,R as ee,i as I,s as L,x as R}from"./index-D5OTguVm.js";import{t as z}from"./AdminPage-CN6ZMhf0.js";import{t as B}from"./format-size-CO9d3C3-.js";import{t as V}from"./AdminTabs-C5BWg3Pz.js";var H=N(`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`}]]),te=N(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),ne=N(`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`}]]);b();function U(){let e=S(),t=s(),{data:n,isLoading:r,isError:i}=m({}),a=p(),o=y(()=>a.data??[],[a.data]),[c,u]=_(null),[d,h]=_(null),g=l({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),v=f({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),b=e=>{e.isDefault||v.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||a.isLoading,D=i||a.isError;return C(z,{children:[E&&x(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),D&&x(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!E&&!D&&C(`div`,{className:`space-y-3`,children:[o.length===0&&x(`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.`}),o.map(e=>x(k,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:T.get(e.id)??[],onAdd:e=>u(e),onEdit:e=>h(e),onDelete:e=>{w(e)},onSetDefault:e=>b(e)},e.id))]}),c!==null&&x(A,{initialType:c,onClose:()=>u(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),u(null)}}),d!==null&&x(O,{location:d,onClose:()=>h(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),h(null)}})]})}b();var W=[[`backup`,`listDestinations`]],G=[`backup`,`listArchives`];function K({destinationId:e,restoreSupported:t,onOpenRestoreWizard:n}){let i=S(),a=s(),{data:c,isLoading:l,isError:u}=o({destinationId:e}),d=c??[],f=r({onSuccess:()=>{i.invalidateQueries({queryKey:[[...G]]}),i.invalidateQueries({queryKey:W})}}),p=g(async t=>{await a({title:`Delete this archive?`,message:`Permanently deletes "${t.label??t.id}" and frees ${B(t.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&f.mutate({destinationId:e,backupId:t.id})},[a,e,f]),[m,h]=_(null),v=g(async t=>{h(t.id);try{let n=localStorage.getItem(`camstack_admin_token`),r={};n&&(r.Authorization=`Bearer ${n}`);let i=await fetch(q(e,t.id),{headers:r});if(!i.ok)throw Error(`download failed: ${i.status} ${i.statusText}`);let a=await i.blob(),o=URL.createObjectURL(a),s=document.createElement(`a`);s.href=o,s.download=`${t.label??t.id}.tar.gz`,document.body.appendChild(s),s.click(),s.remove(),URL.revokeObjectURL(o)}finally{h(null)}},[e]),b=y(()=>[...d].toSorted((e,t)=>t.createdAt-e.createdAt),[d]);return l?x(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):u?x(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):b.length===0?x(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):x(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[640px]`,children:[x(`thead`,{children:C(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[x(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),x(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),x(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),x(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),x(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),x(`tbody`,{children:b.map(r=>C(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[x(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:J(r.createdAt)}),x(`td`,{className:`px-3 py-1.5 text-foreground`,children:r.label??x(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),x(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:r.locations.join(`, `)}),x(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:B(r.sizeBytes)}),x(`td`,{className:`px-3 py-1.5`,children:C(`div`,{className:`flex items-center justify-end gap-1`,children:[C(`button`,{onClick:()=>{v(r)},disabled:m===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:[m===r.id?x(R,{className:`h-3 w-3 animate-spin`}):x(E,{className:`h-3 w-3`}),`Download`]}),t&&n&&C(`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:[x(M,{className:`h-3 w-3`}),`Restore`]}),x(`button`,{onClick:()=>{p(r)},disabled:f.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:f.isPending?x(R,{className:`h-3 w-3 animate-spin`}):x(L,{className:`h-3 w-3`})})]})})]},r.id))})]})})}function q(e,t){return`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function J(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}b();var Y=[{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 X(e){let t=e.trim();for(let e of Y)if(e.cron===t)return e.id;return`custom`}function Z({value:e,onChange:t,previewCount:n=5,disabled:r=!1}){let i=X(e),[a,o]=_(i===`custom`);v(()=>{i!==`custom`&&o(!1)},[i]);let s=ae(e,250),c=u({cron:s,count:n},{enabled:s.trim().length>0}),l=c.data??null,d=e=>{o(!1),t(e.cron)},f=a||i===`custom`;return C(`div`,{className:`space-y-3`,children:[C(`div`,{className:`space-y-1`,children:[x(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),C(`div`,{className:`flex flex-wrap gap-1.5`,children:[Y.map(e=>x(`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)),x(`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&&C(`div`,{className:`space-y-1`,children:[x(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),x(`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`}),C(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,x(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),x(re,{cron:s,preview:l,loading:c.isFetching})]})}function re({cron:e,preview:t,loading:n}){return n&&t===null?C(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[x(R,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?x(`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.`}):C(`div`,{className:`space-y-1`,children:[x(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),x(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>C(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[x(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),x(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:ie(e)})]},`${e}-${t}`))})]}):x(`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 ie(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 ae(e,t){let[n,r]=_(e),i=y(()=>e,[e]);return v(()=>{let e=setTimeout(()=>r(i),t);return()=>clearTimeout(e)},[i,t]),n}b();var oe=[[`backup`,`listDestinations`]];function se({onCreateAt:e,onOpenRestoreWizard:t}){let{data:n,isLoading:r,isError:i}=d(),a=n??[],[o,s]=_(null),c=e=>{s(t=>t===e?null:e)},l=fe();return r?x(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading destinations…`}):i?x(`div`,{className:`text-xs text-danger`,children:`Failed to load destinations`}):a.length===0?x(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:x(`p`,{className:`text-xs text-foreground-subtle`,children:"No `backups`-typed storage locations registered. Add one in Settings → Storage to begin."})}):x(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[720px]`,children:[x(`thead`,{children:C(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[x(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),x(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Destination`}),x(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),x(`th`,{className:`text-left px-3 py-2 font-medium w-28`,children:`Retention`}),x(`th`,{className:`text-left px-3 py-2 font-medium w-56`,children:`Schedule`}),x(`th`,{className:`text-left px-3 py-2 font-medium w-44`,children:`Last success`}),x(`th`,{className:`text-right px-3 py-2 font-medium w-44`,children:`Actions`})]})}),x(`tbody`,{children:a.map(n=>{let r=l.get(n.id);return x(ce,{row:n,isOpen:o===n.id,onToggle:()=>c(n.id),onCreateAt:e,liveLastSuccessAt:r?.at,liveLastSuccessSizeBytes:r?.sizeBytes,...t?{onOpenRestoreWizard:t}:{}},n.id)})})]})})}function ce({row:e,isOpen:t,onToggle:n,onCreateAt:r,onOpenRestoreWizard:i,liveLastSuccessAt:a,liveLastSuccessSizeBytes:o}){let s=S(),l=c({onSuccess:()=>{s.invalidateQueries({queryKey:oe})}}),[u,d]=_(String(e.retentionCount));v(()=>{d(String(e.retentionCount))},[e.retentionCount]);let[f,p]=_(!1),m=g(t=>{l.mutate({locationId:e.id,enabled:t,retentionCount:e.retentionCount,...e.label===void 0?{}:{label:e.label},...e.cron===void 0?{}:{cron:e.cron}})},[l,e.id,e.retentionCount,e.label,e.cron]),h=g(()=>{let t=Number.parseInt(u,10);if(Number.isNaN(t)||t<1){d(String(e.retentionCount));return}t!==e.retentionCount&&l.mutate({locationId:e.id,enabled:e.enabled,retentionCount:t,...e.label===void 0?{}:{label:e.label},...e.cron===void 0?{}:{cron:e.cron}})},[l,u,e.id,e.enabled,e.retentionCount,e.label,e.cron]),y=g(t=>{l.mutate({locationId:e.id,enabled:e.enabled,retentionCount:e.retentionCount,...e.label===void 0?{}:{label:e.label},cron:t},{onSuccess:()=>{p(!1)}})},[l,e.id,e.enabled,e.retentionCount,e.label]);return C(w,{children:[C(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[x(`td`,{className:`px-2 py-2`,children:x(`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:x(t?F:P,{className:`h-3.5 w-3.5`})})}),x(`td`,{className:`px-3 py-2`,children:C(`button`,{onClick:n,className:`text-left hover:underline focus:outline-none`,title:`View archives`,children:[x(`div`,{className:`text-foreground font-medium`,children:e.displayName}),C(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[x(`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}),x(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]})}),x(`td`,{className:`px-3 py-2`,children:x(`label`,{className:`inline-flex items-center cursor-pointer`,children:x(`input`,{type:`checkbox`,className:`accent-primary`,checked:e.enabled,disabled:l.isPending,onChange:e=>m(e.target.checked)})})}),x(`td`,{className:`px-3 py-2`,children:x(`input`,{type:`number`,min:1,max:1e3,value:u,disabled:l.isPending,onChange:e=>d(e.target.value),onBlur:h,onKeyDown:t=>{t.key===`Enter`&&t.target.blur(),t.key===`Escape`&&d(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`})}),x(`td`,{className:`px-3 py-2`,children:x(le,{cron:e.cron,nextRunAt:e.nextRunAt,onEdit:()=>p(!0),disabled:l.isPending})}),x(`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?x(`span`,{className:`italic`,children:`Never`}):x(me,{at:t,sizeBytes:n})})()}),x(`td`,{className:`px-3 py-2`,children:x(`div`,{className:`flex items-center justify-end gap-1.5`,children:e.triggerSupported&&C(`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:[x(j,{className:`h-3 w-3`}),`Create here`]})})})]}),t&&x(`tr`,{className:`border-t border-border bg-background/30`,children:x(`td`,{colSpan:7,className:`px-4 py-3`,children:x(K,{destinationId:e.id,restoreSupported:e.restoreSupported,...i?{onOpenRestoreWizard:i}:{}})})}),f&&x(de,{destinationName:e.displayName,currentCron:e.cron??``,onSave:y,onClose:()=>p(!1),saving:l.isPending,saveError:l.error instanceof Error?l.error.message:null})]})}function le({cron:e,nextRunAt:t,onEdit:n,disabled:r}){let i=typeof e==`string`&&e.trim().length>0;return C(`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:[C(`div`,{className:`flex items-center gap-1.5`,children:[x(ne,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),x(`span`,{className:i?`font-mono text-foreground`:`italic text-foreground-subtle`,children:i?e:`Manual`})]}),i&&t!==void 0&&C(`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]=_(t);return x(`tr`,{children:x(`td`,{colSpan:7,className:`p-0`,children:x(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:C(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[C(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[C(`div`,{className:`space-y-0.5`,children:[x(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Schedule`}),C(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e]})]}),x(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,title:`Close`,children:x(I,{className:`h-4 w-4`})})]}),C(`div`,{className:`p-4`,children:[x(Z,{value:o,onChange:s,disabled:i}),a!==null&&x(`div`,{className:`mt-3 rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:a})]}),C(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[x(`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`}),x(`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 C(`span`,{title:y(()=>new Date(e).toLocaleString(),[e]),className:`text-foreground tabular-nums`,children:[n,t!==void 0&&C(`span`,{className:`ml-1 text-foreground-subtle`,children:[`· `,B(t)]})]})}function he(e){let[,t]=_(0);return v(()=>{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`}b();var _e=[[`backup`,`list`]];function ve({initialDestinationId:e,initialArchiveId:t,onClose:r,onScheduled:a}){let s=S(),[c,l]=_(e&&t?2:1),[u,f]=_(e),[p,m]=_(t),[h,g]=_(new Set),{data:b}=d(),w=b??[],{data:T,isLoading:E}=o({destinationId:u??``},{enabled:!!u}),D=T??[];v(()=>{if(u!==void 0)return;let e=w.filter(e=>e.restoreSupported);e.length===1&&f(e[0].id)},[u,w]);let{data:O}=n({destinationId:u??``,backupId:p??``},{enabled:!!u&&!!p}),k=y(()=>O?.locations??[],[O]);v(()=>{k.length!==0&&g(e=>e.size===0?new Set(k):e)},[k]);let A=i({onSuccess:()=>{s.invalidateQueries({queryKey:_e}),a(),r()}}),j=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},N=!!u&&!!p,P=h.size>0,F=N&&P&&!A.isPending,L=()=>{!u||!p||A.mutate({destinationId:u,backupId:p,locations:[...h]})};return x(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[C(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[C(`div`,{className:`space-y-0.5`,children:[x(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),C(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,c,` of 3 —`,` `,c===1?`pick source`:c===2?`pick locations`:`confirm`]})]}),x(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,children:x(I,{className:`h-4 w-4`})})]}),c===1&&x(ye,{destinations:w,destinationId:u,onPickDestination:e=>{f(e),m(void 0),g(new Set)},archives:D,archivesLoading:E,archiveId:p,onPickArchive:m}),c===2&&x(be,{locations:k,picked:h,onToggle:j}),c===3&&x(xe,{destinationName:w.find(e=>e.id===u)?.displayName??u??``,archive:D.find(e=>e.id===p),picked:[...h]}),C(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[x(`div`,{children:c>1&&C(`button`,{onClick:()=>l(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:[x(ee,{className:`h-3 w-3`}),`Back`]})}),C(`div`,{className:`flex items-center gap-2`,children:[x(`button`,{onClick:r,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),c<3?C(`button`,{disabled:c===1&&!N||c===2&&!P,onClick:()=>l(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`,x(te,{className:`h-3 w-3`})]}):C(`button`,{onClick:L,disabled:!F,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?x(R,{className:`h-3.5 w-3.5 animate-spin`}):x(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 C(`div`,{className:`p-4 space-y-3`,children:[C(`div`,{className:`space-y-1.5`,children:[x(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),C(`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:[x(`option`,{value:``,disabled:!0,children:`Select destination…`}),s.map(e=>C(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),C(`div`,{className:`space-y-1.5`,children:[x(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&x(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&i&&x(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!i&&r.length===0&&x(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&r.length>0&&x(`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 C(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[C(`div`,{className:`flex items-center gap-2`,children:[x(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>o(e.id),className:`accent-primary`}),C(`div`,{children:[x(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),x(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),x(`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?x(`div`,{className:`p-4`,children:x(`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.`})}):C(`div`,{className:`p-4 space-y-3`,children:[x(`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.`}),C(`div`,{className:`space-y-1.5`,children:[x(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),x(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>C(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[x(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>n(e),className:`accent-primary`}),x(`span`,{className:`font-mono text-foreground`,children:e}),x(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ce(e)})]},e))})]})]})}function xe({destinationName:e,archive:t,picked:n}){return C(`div`,{className:`p-4 space-y-3 text-xs`,children:[x(`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.`}),C(`dl`,{className:`space-y-1.5`,children:[x(Q,{term:`Destination`,value:e}),x(Q,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&x(Q,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${B(t.sizeBytes)}`}),x(Q,{term:`Locations`,value:n.length>0?n.join(`, `):`— (full archive)`})]})]})}function Q({term:e,value:t}){return C(`div`,{className:`flex justify-between gap-3`,children:[x(`dt`,{className:`text-foreground-subtle`,children:e}),x(`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]??``}b();var $=[[`backup`,`list`]],we=[[`backup`,`listLocations`]];function Te(){let t=S(),n=s(),{data:r}=e(),i=a({onSuccess:()=>{t.invalidateQueries({queryKey:$}),t.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),t.invalidateQueries({queryKey:[[`backup`,`listArchives`]]})}}),o=h(),[c,l]=_(null),[u,d]=_(null),[f,p]=_(!1),[m,g]=_(!1),[v,y]=_(!1),b=async()=>{await n({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&o.mutate({confirm:!0})};return C(z,{children:[C(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[C(`button`,{onClick:()=>p(!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:[x(M,{className:`h-3.5 w-3.5`}),`Restore…`]}),C(`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:[x(j,{className:`h-3.5 w-3.5`}),`Add destination`]})]}),m&&x(`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:C(`div`,{className:`flex items-center justify-between gap-3`,children:[C(`div`,{className:`flex items-center gap-2`,children:[x(M,{className:`h-3.5 w-3.5`}),x(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),C(`button`,{onClick:()=>{b()},disabled:o.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:[o.isPending?x(R,{className:`h-3.5 w-3.5 animate-spin`}):x(M,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),x(se,{onCreateAt:e=>l(e),onOpenRestoreWizard:e=>d(e)}),c&&x(Ee,{destination:c,locations:r??[],onClose:()=>l(null),onSubmit:(e,n)=>{i.mutate({destinations:[c.id],locations:e,label:n||void 0},{onSuccess:()=>{l(null),t.invalidateQueries({queryKey:we})}})},submitting:i.isPending}),(u||f)&&x(ve,{...u?{initialDestinationId:u.destinationId,initialArchiveId:u.archiveId}:{},onClose:()=>{d(null),p(!1)},onScheduled:()=>g(!0)}),v&&x(A,{initialType:`backups`,onClose:()=>y(!1),onCreated:()=>{y(!1),t.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]})}})]})}function Ee({destination:e,locations:t,onClose:n,onSubmit:r,submitting:i}){let a=t.filter(e=>e.present),[o,s]=_(``),[c,l]=_(()=>new Set(a.map(e=>e.name))),u=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return x(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[C(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[C(`div`,{className:`space-y-0.5`,children:[x(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Create Backup`}),C(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e.displayName]})]}),x(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:x(I,{className:`h-4 w-4`})})]}),C(`div`,{className:`p-4 space-y-3`,children:[C(`div`,{className:`space-y-1`,children:[x(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Label (optional)`}),x(`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`})]}),C(`div`,{className:`space-y-1.5`,children:[x(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Include`}),C(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:[a.length===0&&x(`div`,{className:`px-3 py-2 text-xs text-foreground-subtle italic`,children:`Nothing to back up.`}),a.map(e=>C(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[C(`div`,{className:`flex items-center gap-2`,children:[x(`input`,{type:`checkbox`,checked:c.has(e.name),onChange:()=>u(e.name),className:`accent-primary`}),x(`span`,{className:`font-mono text-foreground`,children:e.name})]}),C(`div`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[B(e.sizeBytes),` · `,e.fileCount,` files`]})]},e.name))]})]})]}),C(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[x(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),C(`button`,{onClick:()=>r(Array.from(c),o.trim()),disabled:i||c.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?x(R,{className:`h-3.5 w-3.5 animate-spin`}):x(H,{className:`h-3.5 w-3.5`}),i?`Creating…`:`Create`]})]})]})})}function De(){return x(`div`,{className:`flex flex-col p-4`,children:x(V,{tabs:[{id:`storage`,label:`Storage`,icon:D,content:x(U,{})},{id:`backup`,label:`Backup`,icon:H,content:x(Te,{})}]})})}export{De as DataPage};
@@ -1 +1 @@
1
- import{An as e,Cn as t,Dn as n,En as r,Mn as i,Nn as a,On as o,Pn as s,Tn as c,aa as l,ca as u,da as d,ia as f,jn as p,kn as m,na as h,oa as g,ra as _,ta as v,ua as y,wn as b}from"./src-Dxc7AUYA.js";import{G as x,U as S,X as C,b as w,o as T,x as E,y as D}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{t as O}from"./pencil-Kbj4_JBR.js";import{t as k}from"./plus-CPqVcqUV.js";import{t as A}from"./sparkles-B5Duaxbv.js";import{t as j}from"./square-check-big-qiutr_Ci.js";import{t as M}from"./square-Bex0hnGW.js";import{B as N,F as P,M as F,P as I,i as L,m as R,s as z,x as B}from"./index-DpTstpp_.js";import{t as V}from"./AdminPage-CN6ZMhf0.js";var H=N(`user-check`,[[`path`,{d:`m16 11 2 2 4-4`,key:`9rsbq5`}],[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),U=N(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]),W=N(`user-x`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`17`,x2:`22`,y1:`8`,y2:`13`,key:`3nzzx3`}],[`line`,{x1:`22`,x2:`17`,y1:`8`,y2:`13`,key:`1swrse`}]]);C();var G=[[`faceGallery`]];function K({identityId:t}){let n=T(),{data:r,isLoading:i}=o({identityId:t}),a=e();function s(e){a.mutate({identityId:t,sampleId:e.id},{onSettled:()=>{n.invalidateQueries({queryKey:G})}})}return i?E(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[w(B,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!r||r.length===0?w(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):w(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:r.map(e=>E(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?w(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):w(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:w(U,{className:`h-6 w-6`})}),w(`button`,{type:`button`,onClick:()=>s(e),disabled:a.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove sample`,children:w(L,{className:`h-4 w-4 text-white`})})]},e.id))})}function q({identity:e,expanded:t,onToggle:n}){let i=T(),[a,o]=x(``),[s,c]=x(!1),[m,b]=x(!1),S=p(),C=r();function k(){o(e.name),c(!0)}function A(){c(!1),o(``)}function j(){let t=a.trim();if(!t||t===e.name){A();return}S.mutate({id:e.id,name:t},{onSettled:()=>{i.invalidateQueries({queryKey:G}),A()}})}function M(){C.mutate({id:e.id},{onSettled:()=>{i.invalidateQueries({queryKey:G}),b(!1)}})}return E(`div`,{className:`rounded-md border border-border bg-surface`,children:[E(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[w(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:e.coverBase64?w(`img`,{src:`data:image/jpeg;base64,${e.coverBase64}`,alt:e.name,className:`h-full w-full object-cover`}):w(`div`,{className:`flex h-full w-full items-center justify-center`,children:w(U,{className:`h-4 w-4 text-foreground-subtle`})})}),w(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:s?E(D,{children:[w(u,{value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&j(),e.key===`Escape`&&A()},className:`h-6 text-xs`,autoFocus:!0}),w(`button`,{type:`button`,onClick:j,disabled:S.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:w(P,{className:`h-3.5 w-3.5`})}),w(`button`,{type:`button`,onClick:A,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:w(L,{className:`h-3.5 w-3.5`})})]}):w(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),w(y,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!s&&E(`div`,{className:`flex items-center gap-1`,children:[w(`button`,{type:`button`,onClick:k,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:w(O,{className:`h-3.5 w-3.5`})}),w(`button`,{type:`button`,onClick:()=>b(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:w(z,{className:`h-3.5 w-3.5`})})]}),w(`button`,{type:`button`,onClick:n,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:w(t?I:F,{className:`h-3.5 w-3.5`})})]}),t&&w(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:w(K,{identityId:e.id})}),w(v,{open:m,onOpenChange:e=>!e&&b(!1),children:E(h,{children:[E(l,{children:[w(g,{children:`Delete person`}),E(_,{children:[`Delete `,w(`strong`,{children:e.name}),` and all their samples? This cannot be undone.`]})]}),E(f,{children:[w(d,{variant:`secondary`,onClick:()=>b(!1),children:`Cancel`}),E(d,{variant:`danger`,onClick:M,disabled:C.isPending,children:[C.isPending?w(B,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function J(){let e=T(),[t,n]=x(``),r=b();function i(){let i=t.trim();i&&r.mutate({name:i},{onSettled:()=>{e.invalidateQueries({queryKey:G}),n(``)}})}return E(`div`,{className:`flex items-center gap-2 pt-2`,children:[w(u,{placeholder:`New person name…`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&i()},className:`h-7 text-xs flex-1`}),E(d,{variant:`primary`,size:`sm`,onClick:i,disabled:r.isPending||!t.trim(),children:[r.isPending?w(B,{className:`h-3.5 w-3.5 animate-spin`}):w(k,{className:`h-3.5 w-3.5`}),`Add`]})]})}function Y(){let{data:e,isLoading:t}=n(),[r,i]=x(null);function a(e){i(t=>t===e?null:e)}return t?E(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[w(B,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):E(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&w(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),e?.map(e=>w(q,{identity:e,expanded:r===e.id,onToggle:()=>a(e.id)},e.id)),w(J,{})]})}C();var X=[[`faceGallery`]];function Z({faceIds:e,identities:n,onDone:r}){let i=T(),a=t(),o=b(),[s,c]=x(``),[p,m]=x(!1),[y,S]=x(null),C=e!==null&&e.length>0,D=e?.length??0;function O(){m(!1),c(``),S(null)}function k(){O(),r()}function A(t){!e||e.length===0||a.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{i.invalidateQueries({queryKey:X}),k()}})}function j(){!e||!s.trim()||o.mutate({name:s.trim()},{onSuccess:e=>{e?.id&&A(e.id)},onError:()=>{i.invalidateQueries({queryKey:X}),k()}})}let M=a.isPending||o.isPending;return w(v,{open:C,onOpenChange:e=>!e&&k(),children:E(h,{children:[E(l,{children:[w(g,{children:D>1?`Assign ${D} faces to person`:`Assign face to person`}),w(_,{children:`Select an existing person or create a new one.`})]}),w(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:n.map(e=>E(`button`,{type:`button`,onClick:()=>S(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:[w(`span`,{className:`font-medium`,children:e.name}),E(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),p?w(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:w(u,{placeholder:`New person name…`,value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&j()},autoFocus:!0,className:`flex-1`})}):w(`button`,{type:`button`,onClick:()=>{S(null),m(!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…`}),E(f,{children:[w(d,{variant:`secondary`,onClick:k,disabled:M,children:`Cancel`}),p?E(d,{variant:`primary`,onClick:j,disabled:M||!s.trim(),children:[M&&w(B,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):E(d,{variant:`primary`,onClick:()=>y&&A(y),disabled:M||!y,children:[M&&w(B,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,D>1?` ${D}`:``]})]})]})})}function Q({face:e,selected:t,onToggleSelect:n,onAssign:r}){let i=T(),o=a(),s=c(),l=()=>{i.invalidateQueries({queryKey:X})};return E(`div`,{className:`group relative flex flex-col gap-1 rounded-md border bg-surface overflow-hidden ${t?`border-primary ring-1 ring-primary`:`border-border`}`,children:[E(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[e.base64?w(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Face`,className:`h-full w-full object-cover`}):w(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:w(U,{className:`h-8 w-8`})}),w(`button`,{type:`button`,onClick:()=>n(e.faceId),className:`absolute left-1 top-1 rounded bg-black/40 p-0.5 text-white hover:bg-black/60`,"aria-label":t?`Deselect`:`Select`,children:t?w(j,{className:`h-3.5 w-3.5 text-primary`}):w(M,{className:`h-3.5 w-3.5`})}),E(`div`,{className:`absolute inset-0 flex items-center justify-center gap-2 bg-black/50 opacity-0 transition-opacity group-hover:opacity-100`,children:[e.assigned?w(`button`,{type:`button`,onClick:()=>o.mutate({faceId:e.faceId},{onSettled:l}),disabled:o.isPending,className:`rounded-full bg-warning/80 p-1.5 text-white hover:bg-warning disabled:opacity-50`,title:`Detach`,children:o.isPending?w(B,{className:`h-3.5 w-3.5 animate-spin`}):w(W,{className:`h-3.5 w-3.5`})}):w(`button`,{type:`button`,onClick:()=>r(e.faceId),className:`rounded-full bg-primary/80 p-1.5 text-white hover:bg-primary`,title:`Assign to person`,children:w(H,{className:`h-3.5 w-3.5`})}),w(`button`,{type:`button`,onClick:()=>s.mutate({faceId:e.faceId},{onSettled:l}),disabled:s.isPending,className:`rounded-full bg-danger/80 p-1.5 text-white hover:bg-danger disabled:opacity-50`,title:`Delete face`,children:s.isPending?w(B,{className:`h-3.5 w-3.5 animate-spin`}):w(z,{className:`h-3.5 w-3.5`})})]})]}),E(`div`,{className:`px-2 pb-2 space-y-0.5`,children:[w(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.deviceId}),e.identityName&&w(`p`,{className:`text-[10px] font-medium text-primary truncate`,title:e.identityName,children:e.identityName})]})]})}var $=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function ee(){let e=T(),[r,a]=x(`all`),[o,l]=x(new Set),[u,f]=x(null),[p,h]=x(!1),{data:g,isLoading:_}=m({limit:100,filter:r}),{data:v=[]}=n(),{data:y,isFetching:b}=i({threshold:.5,minClusterSize:2,limit:20},{enabled:p}),C=t(),D=s(),O=c(),k=g??[],j=S(()=>new Map(k.map(e=>[e.faceId,e])),[k]),M=()=>{e.invalidateQueries({queryKey:X})},N=()=>l(new Set);function P(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function F(e){l(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}let I=[...o],R=C.isPending||D.isPending||O.isPending;function V(){I.length!==0&&D.mutate({faceIds:I},{onSettled:()=>{M(),N()}})}function G(){I.length!==0&&Promise.allSettled(I.map(e=>O.mutateAsync({faceId:e}))).then(()=>{M(),N()})}return E(`div`,{className:`space-y-3`,children:[E(`div`,{className:`flex items-center gap-1`,children:[$.map(e=>w(`button`,{type:`button`,onClick:()=>a(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${r===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value)),E(`button`,{type:`button`,onClick:()=>h(e=>!e),className:`ml-2 flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${p?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[w(A,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!_&&E(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[k.length,` face`,k.length===1?``:`s`]})]}),o.size>0&&E(`div`,{className:`flex items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[E(`span`,{className:`text-xs font-medium text-foreground`,children:[o.size,` selected`]}),E(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[E(d,{variant:`primary`,onClick:()=>f(I),disabled:R,children:[w(H,{className:`h-3.5 w-3.5`}),` Assign`]}),E(d,{variant:`secondary`,onClick:V,disabled:R,children:[D.isPending?w(B,{className:`h-3.5 w-3.5 animate-spin`}):w(W,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),E(d,{variant:`secondary`,onClick:G,disabled:R,children:[w(z,{className:`h-3.5 w-3.5`}),` Delete`]}),w(d,{variant:`ghost`,onClick:N,disabled:R,children:w(L,{className:`h-3.5 w-3.5`})})]})]}),p&&E(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:[w(`p`,{className:`mb-2 text-xs font-medium text-foreground`,children:`Look-alike groups`}),b?E(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[w(B,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):!y||y.length===0?w(`p`,{className:`text-xs text-foreground-subtle`,children:`No look-alike groups found among unassigned faces.`}):w(`div`,{className:`space-y-2`,children:y.map(e=>E(`div`,{className:`flex items-center gap-2 rounded-md bg-surface-hover/50 p-2`,children:[w(`div`,{className:`flex -space-x-1.5`,children:e.faceIds.slice(0,6).map(e=>{let t=j.get(e);return w(`div`,{className:`h-8 w-8 overflow-hidden rounded border border-border bg-surface`,children:t?.base64?w(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:``,className:`h-full w-full object-cover`}):w(U,{className:`h-full w-full p-1.5 text-foreground-subtle`})},e)})}),E(`span`,{className:`text-xs text-foreground-subtle`,children:[e.size,` faces · `,Math.round(e.cohesion*100),`% alike`]}),E(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[w(d,{variant:`secondary`,onClick:()=>F(e.faceIds),children:`Select group`}),E(d,{variant:`primary`,onClick:()=>f(e.faceIds),children:[w(H,{className:`h-3.5 w-3.5`}),` Assign all`]})]})]},e.representativeFaceId))})]}),_&&E(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[w(B,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!_&&k.length===0&&w(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No faces found for this filter.`}),!_&&k.length>0&&w(`div`,{className:`grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8 lg:grid-cols-10`,children:k.map(e=>w(Q,{face:e,selected:o.has(e.faceId),onToggleSelect:P,onAssign:e=>f([e])},e.faceId))}),w(Z,{faceIds:u,identities:v,onDone:()=>{f(null),N()}})]})}function te(){return w(V,{icon:R,title:`Detection Intelligence`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:E(`section`,{className:`space-y-3`,children:[E(`div`,{children:[w(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),w(`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.`}),w(Y,{})]}),E(`div`,{className:`pt-4 border-t border-border`,children:[w(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),w(`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.`}),w(ee,{})]})]})})}export{te as DetectionIntelligencePage};
1
+ import{An as e,Cn as t,Dn as n,En as r,Mn as i,Nn as a,On as o,Pn as s,Tn as c,aa as l,ca as u,fa as d,ia as f,jn as p,kn as m,oa as h,pa as g,ra as _,sa as v,ua as y,wn as b}from"./src-BB1LG2-C.js";import{G as x,U as S,X as C,b as w,o as T,x as E,y as D}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{t as O}from"./pencil-WwVUhRC9.js";import{t as k}from"./plus-D2fCWFPc.js";import{t as A}from"./sparkles-D9CcRRON.js";import{t as j}from"./square-check-big-9Ki4zQ6C.js";import{t as M}from"./square-CO0xPDBD.js";import{B as N,F as P,M as F,P as I,i as L,m as R,s as z,x as B}from"./index-D5OTguVm.js";import{t as V}from"./AdminPage-CN6ZMhf0.js";var H=N(`user-check`,[[`path`,{d:`m16 11 2 2 4-4`,key:`9rsbq5`}],[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),U=N(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]),W=N(`user-x`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`17`,x2:`22`,y1:`8`,y2:`13`,key:`3nzzx3`}],[`line`,{x1:`22`,x2:`17`,y1:`8`,y2:`13`,key:`1swrse`}]]);C();var G=[[`faceGallery`]];function K({identityId:t}){let n=T(),{data:r,isLoading:i}=o({identityId:t}),a=e();function s(e){a.mutate({identityId:t,sampleId:e.id},{onSettled:()=>{n.invalidateQueries({queryKey:G})}})}return i?E(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[w(B,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!r||r.length===0?w(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):w(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:r.map(e=>E(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?w(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):w(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:w(U,{className:`h-6 w-6`})}),w(`button`,{type:`button`,onClick:()=>s(e),disabled:a.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove sample`,children:w(L,{className:`h-4 w-4 text-white`})})]},e.id))})}function q({identity:e,expanded:t,onToggle:n}){let i=T(),[a,o]=x(``),[s,c]=x(!1),[m,b]=x(!1),S=p(),C=r();function k(){o(e.name),c(!0)}function A(){c(!1),o(``)}function j(){let t=a.trim();if(!t||t===e.name){A();return}S.mutate({id:e.id,name:t},{onSettled:()=>{i.invalidateQueries({queryKey:G}),A()}})}function M(){C.mutate({id:e.id},{onSettled:()=>{i.invalidateQueries({queryKey:G}),b(!1)}})}return E(`div`,{className:`rounded-md border border-border bg-surface`,children:[E(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[w(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:e.coverBase64?w(`img`,{src:`data:image/jpeg;base64,${e.coverBase64}`,alt:e.name,className:`h-full w-full object-cover`}):w(`div`,{className:`flex h-full w-full items-center justify-center`,children:w(U,{className:`h-4 w-4 text-foreground-subtle`})})}),w(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:s?E(D,{children:[w(y,{value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&j(),e.key===`Escape`&&A()},className:`h-6 text-xs`,autoFocus:!0}),w(`button`,{type:`button`,onClick:j,disabled:S.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:w(P,{className:`h-3.5 w-3.5`})}),w(`button`,{type:`button`,onClick:A,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:w(L,{className:`h-3.5 w-3.5`})})]}):w(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),w(d,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!s&&E(`div`,{className:`flex items-center gap-1`,children:[w(`button`,{type:`button`,onClick:k,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:w(O,{className:`h-3.5 w-3.5`})}),w(`button`,{type:`button`,onClick:()=>b(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:w(z,{className:`h-3.5 w-3.5`})})]}),w(`button`,{type:`button`,onClick:n,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:w(t?I:F,{className:`h-3.5 w-3.5`})})]}),t&&w(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:w(K,{identityId:e.id})}),w(_,{open:m,onOpenChange:e=>!e&&b(!1),children:E(f,{children:[E(v,{children:[w(u,{children:`Delete person`}),E(l,{children:[`Delete `,w(`strong`,{children:e.name}),` and all their samples? This cannot be undone.`]})]}),E(h,{children:[w(g,{variant:`secondary`,onClick:()=>b(!1),children:`Cancel`}),E(g,{variant:`danger`,onClick:M,disabled:C.isPending,children:[C.isPending?w(B,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function J(){let e=T(),[t,n]=x(``),r=b();function i(){let i=t.trim();i&&r.mutate({name:i},{onSettled:()=>{e.invalidateQueries({queryKey:G}),n(``)}})}return E(`div`,{className:`flex items-center gap-2 pt-2`,children:[w(y,{placeholder:`New person name…`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&i()},className:`h-7 text-xs flex-1`}),E(g,{variant:`primary`,size:`sm`,onClick:i,disabled:r.isPending||!t.trim(),children:[r.isPending?w(B,{className:`h-3.5 w-3.5 animate-spin`}):w(k,{className:`h-3.5 w-3.5`}),`Add`]})]})}function Y(){let{data:e,isLoading:t}=n(),[r,i]=x(null);function a(e){i(t=>t===e?null:e)}return t?E(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[w(B,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):E(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&w(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),e?.map(e=>w(q,{identity:e,expanded:r===e.id,onToggle:()=>a(e.id)},e.id)),w(J,{})]})}C();var X=[[`faceGallery`]];function Z({faceIds:e,identities:n,onDone:r}){let i=T(),a=t(),o=b(),[s,c]=x(``),[d,p]=x(!1),[m,S]=x(null),C=e!==null&&e.length>0,D=e?.length??0;function O(){p(!1),c(``),S(null)}function k(){O(),r()}function A(t){!e||e.length===0||a.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{i.invalidateQueries({queryKey:X}),k()}})}function j(){!e||!s.trim()||o.mutate({name:s.trim()},{onSuccess:e=>{e?.id&&A(e.id)},onError:()=>{i.invalidateQueries({queryKey:X}),k()}})}let M=a.isPending||o.isPending;return w(_,{open:C,onOpenChange:e=>!e&&k(),children:E(f,{children:[E(v,{children:[w(u,{children:D>1?`Assign ${D} faces to person`:`Assign face to person`}),w(l,{children:`Select an existing person or create a new one.`})]}),w(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:n.map(e=>E(`button`,{type:`button`,onClick:()=>S(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${m===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[w(`span`,{className:`font-medium`,children:e.name}),E(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),d?w(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:w(y,{placeholder:`New person name…`,value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&j()},autoFocus:!0,className:`flex-1`})}):w(`button`,{type:`button`,onClick:()=>{S(null),p(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:`+ New person…`}),E(h,{children:[w(g,{variant:`secondary`,onClick:k,disabled:M,children:`Cancel`}),d?E(g,{variant:`primary`,onClick:j,disabled:M||!s.trim(),children:[M&&w(B,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):E(g,{variant:`primary`,onClick:()=>m&&A(m),disabled:M||!m,children:[M&&w(B,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,D>1?` ${D}`:``]})]})]})})}function Q({face:e,selected:t,onToggleSelect:n,onAssign:r}){let i=T(),o=a(),s=c(),l=()=>{i.invalidateQueries({queryKey:X})};return E(`div`,{className:`group relative flex flex-col gap-1 rounded-md border bg-surface overflow-hidden ${t?`border-primary ring-1 ring-primary`:`border-border`}`,children:[E(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[e.base64?w(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Face`,className:`h-full w-full object-cover`}):w(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:w(U,{className:`h-8 w-8`})}),w(`button`,{type:`button`,onClick:()=>n(e.faceId),className:`absolute left-1 top-1 rounded bg-black/40 p-0.5 text-white hover:bg-black/60`,"aria-label":t?`Deselect`:`Select`,children:t?w(j,{className:`h-3.5 w-3.5 text-primary`}):w(M,{className:`h-3.5 w-3.5`})}),E(`div`,{className:`absolute inset-0 flex items-center justify-center gap-2 bg-black/50 opacity-0 transition-opacity group-hover:opacity-100`,children:[e.assigned?w(`button`,{type:`button`,onClick:()=>o.mutate({faceId:e.faceId},{onSettled:l}),disabled:o.isPending,className:`rounded-full bg-warning/80 p-1.5 text-white hover:bg-warning disabled:opacity-50`,title:`Detach`,children:o.isPending?w(B,{className:`h-3.5 w-3.5 animate-spin`}):w(W,{className:`h-3.5 w-3.5`})}):w(`button`,{type:`button`,onClick:()=>r(e.faceId),className:`rounded-full bg-primary/80 p-1.5 text-white hover:bg-primary`,title:`Assign to person`,children:w(H,{className:`h-3.5 w-3.5`})}),w(`button`,{type:`button`,onClick:()=>s.mutate({faceId:e.faceId},{onSettled:l}),disabled:s.isPending,className:`rounded-full bg-danger/80 p-1.5 text-white hover:bg-danger disabled:opacity-50`,title:`Delete face`,children:s.isPending?w(B,{className:`h-3.5 w-3.5 animate-spin`}):w(z,{className:`h-3.5 w-3.5`})})]})]}),E(`div`,{className:`px-2 pb-2 space-y-0.5`,children:[w(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.deviceId}),e.identityName&&w(`p`,{className:`text-[10px] font-medium text-primary truncate`,title:e.identityName,children:e.identityName})]})]})}var $=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function ee(){let e=T(),[r,a]=x(`all`),[o,l]=x(new Set),[u,d]=x(null),[f,p]=x(!1),{data:h,isLoading:_}=m({limit:100,filter:r}),{data:v=[]}=n(),{data:y,isFetching:b}=i({threshold:.5,minClusterSize:2,limit:20},{enabled:f}),C=t(),D=s(),O=c(),k=h??[],j=S(()=>new Map(k.map(e=>[e.faceId,e])),[k]),M=()=>{e.invalidateQueries({queryKey:X})},N=()=>l(new Set);function P(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function F(e){l(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}let I=[...o],R=C.isPending||D.isPending||O.isPending;function V(){I.length!==0&&D.mutate({faceIds:I},{onSettled:()=>{M(),N()}})}function G(){I.length!==0&&Promise.allSettled(I.map(e=>O.mutateAsync({faceId:e}))).then(()=>{M(),N()})}return E(`div`,{className:`space-y-3`,children:[E(`div`,{className:`flex items-center gap-1`,children:[$.map(e=>w(`button`,{type:`button`,onClick:()=>a(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${r===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value)),E(`button`,{type:`button`,onClick:()=>p(e=>!e),className:`ml-2 flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${f?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[w(A,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!_&&E(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[k.length,` face`,k.length===1?``:`s`]})]}),o.size>0&&E(`div`,{className:`flex items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[E(`span`,{className:`text-xs font-medium text-foreground`,children:[o.size,` selected`]}),E(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[E(g,{variant:`primary`,onClick:()=>d(I),disabled:R,children:[w(H,{className:`h-3.5 w-3.5`}),` Assign`]}),E(g,{variant:`secondary`,onClick:V,disabled:R,children:[D.isPending?w(B,{className:`h-3.5 w-3.5 animate-spin`}):w(W,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),E(g,{variant:`secondary`,onClick:G,disabled:R,children:[w(z,{className:`h-3.5 w-3.5`}),` Delete`]}),w(g,{variant:`ghost`,onClick:N,disabled:R,children:w(L,{className:`h-3.5 w-3.5`})})]})]}),f&&E(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:[w(`p`,{className:`mb-2 text-xs font-medium text-foreground`,children:`Look-alike groups`}),b?E(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[w(B,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):!y||y.length===0?w(`p`,{className:`text-xs text-foreground-subtle`,children:`No look-alike groups found among unassigned faces.`}):w(`div`,{className:`space-y-2`,children:y.map(e=>E(`div`,{className:`flex items-center gap-2 rounded-md bg-surface-hover/50 p-2`,children:[w(`div`,{className:`flex -space-x-1.5`,children:e.faceIds.slice(0,6).map(e=>{let t=j.get(e);return w(`div`,{className:`h-8 w-8 overflow-hidden rounded border border-border bg-surface`,children:t?.base64?w(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:``,className:`h-full w-full object-cover`}):w(U,{className:`h-full w-full p-1.5 text-foreground-subtle`})},e)})}),E(`span`,{className:`text-xs text-foreground-subtle`,children:[e.size,` faces · `,Math.round(e.cohesion*100),`% alike`]}),E(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[w(g,{variant:`secondary`,onClick:()=>F(e.faceIds),children:`Select group`}),E(g,{variant:`primary`,onClick:()=>d(e.faceIds),children:[w(H,{className:`h-3.5 w-3.5`}),` Assign all`]})]})]},e.representativeFaceId))})]}),_&&E(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[w(B,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!_&&k.length===0&&w(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No faces found for this filter.`}),!_&&k.length>0&&w(`div`,{className:`grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8 lg:grid-cols-10`,children:k.map(e=>w(Q,{face:e,selected:o.has(e.faceId),onToggleSelect:P,onAssign:e=>d([e])},e.faceId))}),w(Z,{faceIds:u,identities:v,onDone:()=>{d(null),N()}})]})}function te(){return w(V,{icon:R,title:`Detection Intelligence`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:E(`section`,{className:`space-y-3`,children:[E(`div`,{children:[w(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),w(`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.`}),w(Y,{})]}),E(`div`,{className:`pt-4 border-t border-border`,children:[w(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),w(`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.`}),w(ee,{})]})]})})}export{te as DetectionIntelligencePage};
@@ -0,0 +1,2 @@
1
+ import{A as e,Ai as t,Ar as n,B as r,E as i,G as a,Gi as o,Gn as s,H as c,I as l,Ji as u,Jt as d,K as f,Ki as p,Kn as m,L as h,Pi as g,Pr as _,Qi as v,Sn as y,T as b,Tt as x,U as S,V as C,Vr as w,W as T,Wi as E,Yi as D,Yr as O,Yt as k,_n as A,a as j,an as M,bn as ee,cn as N,di as P,dn as F,f as I,fn as te,g as ne,gn as re,hn as L,i as ie,ii as ae,in as oe,j as se,k as ce,ki as le,l as ue,ln as de,lr as fe,lt as pe,m as me,mn as he,n as ge,ni as _e,nn as ve,o as ye,p as be,pn as xe,qn as Se,qt as Ce,r as R,u as we,ui as Te,un as Ee,va as De,vn as Oe,w as ke,xn as Ae,xr as je,y as Me,ya as Ne,yn as Pe,zn as Fe,zr as Ie}from"./src-BB1LG2-C.js";import{F as z,G as B,R as V,U as H,W as U,X as W,b as G,o as K,t as Le,x as q,y as Re}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{c as ze,k as Be,p as J,r as Ve,t as He,u as Ue}from"./player-overlays-ZG1nYuYj.js";import{C as We,E as Ge,b as Y,g as Ke,v as qe}from"./src-Cno9Ci3x.js";import{t as Je}from"./CapabilityBadges-CqlDFU27.js";import{t as Ye}from"./bell-CRa7XWAs.js";import{n as Xe,t as Ze}from"./rotate-ccw-CZ8RwUso.js";import{t as Qe}from"./ProviderIcon-BS00rCO4.js";import{t as $e}from"./pencil-WwVUhRC9.js";import{t as et}from"./plus-D2fCWFPc.js";import{t as tt}from"./refresh-cw-DewUBhjl.js";import{t as nt}from"./rotate-cw-DiyghCam.js";import{t as rt}from"./server-DnaOYw5t.js";import{t as it}from"./wifi-BJgMgcFe.js";import{B as X,F as at,H as ot,I as st,O as ct,U as lt,W as ut,_ as dt,a as ft,c as pt,i as mt,k as ht,p as gt,r as _t,s as vt,t as yt,v as bt,x as xt,z as St}from"./index-D5OTguVm.js";import{t as Ct}from"./StatusBadge-CkYubfRG.js";import{n as wt,t as Tt}from"./useDevice-BuSIXBXp.js";import{n as Et,r as Dt,t as Ot}from"./SchemaTabBar-ByWwzBUZ.js";import{t as kt}from"./FormBuilder-DBTf1H_B.js";import{t as At}from"./useEventInvalidation-wNGhDdi_.js";var jt=X(`circle-help`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),Mt=X(`layers`,[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]]),Nt=X(`link-2-off`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7`,key:`10o201`}],[`path`,{d:`M15 7h2a5 5 0 0 1 4 8`,key:`1d3206`}],[`line`,{x1:`8`,x2:`12`,y1:`12`,y2:`12`,key:`rvw6j4`}],[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`,key:`a6p6uj`}]]),Pt=X(`link-2`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]),Ft=X(`map-pin`,[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]),It=X(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),Lt=X(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),Rt=X(`volume-2`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]);W();var zt=`device-export`,Bt=`export`,Vt=`Export`;function Ht(e){return e.type===`separator`||e.type===`info`||e.type===`object-array`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`?!1:e.type===`group`?e.fields.some(Ht):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(Ht)):e.writerCapName===zt}function Ut(e){return e.fields.some(Ht)}function Wt(e){return j(J().trpcClient,e)}function Gt(e){let[t,n]=B(`idle`),[r,i]=B(null),a=U(null),o=U(null),c=U(null),l=U(!0),u=m(),d=s(),f=Se(),p=z(()=>{if(a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}c.current=null},[]),h=z(async()=>{if(t===`idle`)return;n(`stopping`);let r=c.current;if(r&&e!==null)try{await Promise.race([f.mutateAsync({deviceId:e,sessionId:r}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}p(),l.current&&(n(`idle`),i(null))},[t,e,f,p]),g=z(async()=>{if(e===null||t!==`idle`&&t!==`error`)return;i(null);let r=null,s=null,p=null;try{n(`requesting-mic`),r=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),o.current=r,n(`starting`);let t=await u.mutateAsync({deviceId:e});p=t.sessionId,c.current=p,n(`connecting`),s=new RTCPeerConnection,a.current=s,s.oniceconnectionstatechange=()=>{if(!l.current)return;let e=s.iceConnectionState;e===`connected`||e===`completed`?n(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&l.current&&(i(e===`failed`?`WebRTC connection failed`:null),h())};for(let e of r.getAudioTracks())s.addTrack(e,r);await s.setRemoteDescription({type:`offer`,sdp:t.sdpOffer});let f=await s.createAnswer();await s.setLocalDescription(f);let m=s.localDescription?.sdp??f.sdp??``;await d.mutateAsync({deviceId:e,sessionId:p,sdpAnswer:m})}catch(t){let u=t instanceof Error?t.message:String(t);if(console.warn(`[intercom] start failed`,t),s)try{s.close()}catch{}if(r)for(let e of r.getTracks())try{e.stop()}catch{}if(a.current=null,o.current=null,p!==null)try{await f.mutateAsync({deviceId:e,sessionId:p})}catch{}c.current=null,l.current&&(i(u),n(`error`))}},[e,t,u,d,f,h]);return V(()=>(l.current=!0,()=>{l.current=!1;let t=c.current;if(t!==null&&e!==null&&f.mutate({deviceId:e,sessionId:t}),a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}c.current=null}),[e]),{state:t,error:r,start:g,stop:h,isTalking:t===`talking`}}W();var Kt=0;function Z(){return++Kt}function qt(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Jt(e){return[``,`Commands`,` help Show this help`,` examples Show usage examples for the current scope`,` context Show every available variable + full API surface`,` clear Clear terminal (also Ctrl+L)`,``,`Shortcuts`,` Enter Execute expression`,` Arrow Up/Down Navigate command history`,` Ctrl+L Clear terminal`,``,`Try: ${{system:` sm.summary() // fleet overview`,device:` device.state.battery.value?.sleeping // sync read`,provider:` devices.map(d => d.name)`,addon:` manifest.version`}[e.type]}`,``,`Top-level objects: sm (SystemMirror), DeviceType, Math, JSON, Date, …`]}function Yt(e){switch(e.type){case`device`:return[``,`── State (sync, zero round-trip) ─────────────────────────`,` device.state.battery.value`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,``,`── Actions (async, through wrapper chain) ────────────────`,` await device.snapshot.getSnapshot({})`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.switch.setState({ on: true })`,``,`── Wait for condition ───────────────────────────────────`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`── Subscribe to changes ─────────────────────────────────`,` const off = device.state.battery.subscribe(s => console.log(s))`,``,`── Quick info ───────────────────────────────────────────`,` info.name device name`,` info.addonId owning addon`,` sm.dump(deviceId) full debug dump`];case`system`:return[``,`── Lookups ──────────────────────────────────────────────`,` sm.getDeviceById(8)`,` sm.getDeviceByName('Sala da pranzo')`,` sm.getDevicesByAddon('reolink')`,` sm.getDevicesByType(DeviceType.Camera)`,``,`── Filters (typed query) ────────────────────────────────`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] })`,` sm.query({ name: /^Cam-/ })`,``,`── Cross-device ─────────────────────────────────────────`,` sm.whereState('battery', s => s.percentage < 20).length`,` sm.mapState('battery', s => s.percentage)`,` sm.countByCap('snapshot')`,``,`── Batch action ─────────────────────────────────────────`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,``,`── Listen ───────────────────────────────────────────────`,` sm.listenCap('motion', (id, s) => console.log(id, s))`,` sm.onDeviceAdded((id, info) => console.log('+', info.name))`,``,`── Diagnostics ──────────────────────────────────────────`,` sm.summary()`,` sm.dump(8)`];case`provider`:return[``,` devices.map(d => d.name)`,` await getIntegration()`,` sm.getDevicesByAddon('<this-addon-id>').length`];case`addon`:return[``,` manifest.name`,` manifest.version`,` declaration`]}}function Xt(e){let t=[``,`Scope: ${e.type}`,``];switch(e.type){case`system`:return[...t,`Primary API — sm (SystemMirror):`,` sm.getDeviceById(id) DeviceProxy | null (sync)`,` sm.getDeviceByName(name) DeviceProxy | null`,` sm.getDeviceByStableId(sid) DeviceProxy | null`,` sm.getAllDevices() readonly DeviceProxy[]`,` sm.getDeviceInfo(id) DeviceInfo | null`,` sm.summary() fleet stats`,``,`Filters — sm.query({...}):`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] }) // ALL caps required`,` sm.query({ anyCap: ['ptz', 'motion'] }) // ANY cap`,` sm.query({ name: { contains: 'sala' } }) // case-insensitive`,` sm.query({ name: /^Cam-\\d+$/ })`,` sm.query({ type: DeviceType.Camera })`,` sm.query({ parentDeviceId: 8 }) // accessories of cam 8`,` sm.query({ where: (info, dev) => dev.state.battery.value?.sleeping })`,``,`State queries:`,` sm.whereState('battery', s => s.percentage < 20)`,` sm.mapState('battery', s => s.percentage)`,` sm.findState('motion', s => s.detected)`,` sm.countByCap('snapshot')`,``,`Listeners (return unsubscribe fn):`,` sm.listen((id, cap, slice) => …) // every state change`,` sm.listenCap('motion', (id, slice) => …)`,` sm.listenDevice(8, (id, cap, slice) => …)`,` sm.onDeviceAdded((id, info) => …)`,` sm.onDeviceRemoved((id, info) => …)`,``,`Wait primitives:`,` await sm.waitForState(8, 'battery', s => !s.sleeping, 30_000)`,` await sm.waitForDevice(99, 30_000)`,``,`Batch:`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,` await sm.forEachCap('reboot', d => d.reboot.reboot({}))`,``,`Diagnostics:`,` sm.dump(8) debug dump (one device)`,` sm.dump() full fleet dump`,` sm.summary() breakdown by cap/addon/type`,``,`Legacy: deviceRegistry, addonRegistry, eventBus, devices(), addons()`];case`device`:return[...t,`Pre-bound variables:`,` device DeviceProxy for this device (sync state + async methods)`,` deviceId number`,` info DeviceInfo metadata (name, addonId, type, online, …)`,` sm SystemMirror (full cluster view)`,` rawDevice legacy IDevice instance (escape hatch)`,``,`Reactive state (sync, zero round-trip):`,` device.state.battery.value BatteryStatus | undefined`,` device.state.battery.value?.sleeping`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,` device.state.switch.value?.on`,` device.state.brightness.value?.percentage`,` device.state.doorbell.value?.lastPressedAt`,``,`Cap actions (async, through wrapper chain):`,` await device.snapshot.getSnapshot({})`,` await device.snapshot.getSnapshot({ streamId: 'high' })`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.ptz.goToPreset({ presetId: 'home' })`,` await device.switch.setState({ on: true })`,` await device.brightness.setBrightness({ percentage: 60 })`,` await device.reboot.reboot({})`,``,`Subscribe to slice changes:`,` const off = device.state.battery.subscribe(s => console.log(s))`,` // off() to unsubscribe`,``,`Wait for a state condition:`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`Diagnostics:`,` info.name device name`,` info.addonId which addon owns it`,` info.online transport health`,` sm.dump(deviceId) full debug dump (binding + state + info)`];case`provider`:return[...t,`Pre-bound variables:`,` devices Devices belonging to this provider (raw IDevice[])`,` getIntegration() Integration metadata`,``,`For typed device access use the SystemMirror:`,` await getSystemMirror()`,` sm.getDevicesByAddon('this-addon-id')`];case`addon`:return[...t,`Pre-bound variables:`,` manifest { name, version, ... }`,` declaration addon declaration`,` source addon source location`,``,`Examples:`,` manifest.name`,` manifest.version`]}}function Zt({scope:e,greeting:t,className:n}){let r=J(),[i,a]=B(()=>{let n=[];return t&&n.push({id:Z(),kind:`info`,text:t}),n.push({id:Z(),kind:`info`,text:`scope: ${qt(e)} — type help or context for available commands`}),n}),[o,s]=B(``),[c,l]=B([]),[u,d]=B(-1),f=U(null),p=U(null);V(()=>{let e=p.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let m=z(()=>{f.current?.focus()},[]),h=Le({mutationFn:t=>r.trpcClient.repl.execute.mutate({code:t,scope:e}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;a(e=>[...e,{id:Z(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);a(e=>[...e,{id:Z(),kind:`error`,text:t}])}});function g(t){let n=t.trim();if(n){if(n===`clear`){a([{id:Z(),kind:`info`,text:`scope: ${qt(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Z(),kind:`input`,text:`> ${n}`},...Jt(e).map(e=>({id:Z(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Z(),kind:`input`,text:`> ${n}`},...Xt(e).map(e=>({id:Z(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Z(),kind:`input`,text:`> ${n}`},...Yt(e).map(e=>({id:Z(),kind:`info`,text:e}))]),s(``);return}l(e=>[...e,n]),d(-1),a(e=>[...e,{id:Z(),kind:`input`,text:`> ${n}`}]),s(``),h.mutate(n)}}function _(t){if(t.key===`Enter`){t.preventDefault(),g(o);return}if(t.key===`ArrowUp`){if(t.preventDefault(),c.length===0)return;let e=u===-1?c.length-1:Math.max(0,u-1);d(e),s(c[e]??``);return}if(t.key===`ArrowDown`){if(t.preventDefault(),u===-1)return;let e=u+1;e>=c.length?(d(-1),s(``)):(d(e),s(c[e]??``));return}t.ctrlKey&&t.key===`l`&&(t.preventDefault(),a([{id:Z(),kind:`info`,text:`scope: ${qt(e)}`}]))}let v={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return q(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??``}`,onClick:m,children:[q(`div`,{ref:p,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[i.map(e=>G(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${v[e.kind]}`,children:e.text},e.id)),h.isPending&&G(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),q(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[G(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),G(`input`,{ref:f,value:o,onChange:e=>s(e.target.value),onKeyDown:_,disabled:h.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function Qt({deviceId:e,intercomAvailable:t=!1}){let n=J(),r=typeof window<`u`?window.location.origin:``,a=Number.isFinite(e),o=Wt(a?e:null),{streams:s,pipelineMetrics:c,createSession:l,sendAnswer:u,handleOffer:d,getIceServers:f,addIceCandidate:p,getIceCandidates:m,closeSession:h,getSessionState:g}=ie(n.trpcClient,a?e:null),_=T(n.trpcClient,a?e:null),v=Gt(a&&t?e:null),y=v.state===`requesting-mic`||v.state===`starting`||v.state===`connecting`||v.state===`stopping`,b=v.isTalking||y,x=()=>{v.state===`idle`||v.state===`error`?v.start():v.state!==`stopping`&&v.stop()},S=Ve(),C=i(),w=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,E=S.length>0?G(Re,{children:S.map(e=>G(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return G(Me,{serverUrl:r,createSession:l,sendAnswer:u,handleOffer:d,getIceServers:f,addIceCandidate:p,getIceCandidates:m,closeSession:h,getSessionState:g,...C.request?{playbackUrl:C.request.url,playbackAuthToken:w,...C.request.label?{playbackLabel:C.request.label}:{},onExitPlayback:()=>C.clear()}:{},streams:s,pipelineMetrics:c,phase:o.phase,detections:o,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:_.src,..._.src?{posterUrl:_.src}:{},snapshotLoading:_.loading,onRefreshSnapshot:_.refresh,intercomAvailable:t,intercomShown:b,onIntercomToggle:x,extraOverlay:E,chromeless:!0,className:`h-full`})}function $t({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?G(`div`,{className:`flex flex-col h-full`,children:G(ne,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):q(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function en({deviceId:e}){if(!Number.isFinite(e))return q(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let t=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
2
+ `);return G(Zt,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function tn({deviceId:e}){return Number.isFinite(e)?G(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:G(me,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):q(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function nn({deviceId:e}){return Number.isFinite(e)?G(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:G(I,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):q(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function rn({parentDeviceId:e}){let{t}=yt(),n=ot(),i=J(),{data:a,isLoading:o,isError:s}=wt(e),{data:l}=N({deviceId:e},{enabled:Number.isFinite(e)});if(o)return G(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:G(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(s)return G(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:G(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let u=a??[];if(u.length===0)return null;let d=C(l?.stableId??``,u,l?.childLayout),f=d.ungrouped,p=e=>n(`/devices/${String(e)}`),m=(e,t)=>G(r,{trpc:i.trpcClient,device:t,variant:`minimal`,onNavigate:p},e),h=f.some(e=>!!e.role),g=f.some(e=>!e.role),_=h&&!g?t(`device.accessories`,{defaultValue:`Accessories`}):!h&&g?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),v=f.length>0?q(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[G(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:_}),G(`div`,{className:`space-y-1`,children:f.map(e=>m(e.id,e))})]}):null,y=d.disabledSection===void 0?null:G(c,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:d.disabledSection.children.length,defaultOpen:!1,children:G(`div`,{className:`opacity-60 space-y-1`,children:d.disabledSection.children.map(e=>m(e.id,e))})},d.disabledSection.title);return d.sections.length===0?y===null?v:q(`div`,{className:`space-y-2`,children:[v,y]}):q(`div`,{className:`space-y-2`,children:[d.sections.map(e=>G(c,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>m(e.id,e))},e.title)),v,y]})}function Q({label:e,value:t}){return q(`div`,{className:`${Be} flex items-start gap-2 sm:gap-3`,children:[G(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),G(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}W();function an({deviceId:e,initialName:t}){let n=K(),[r,i]=B(!1),[a,o]=B(t),[s,c]=B(!1),l=U(null);V(()=>{r||o(t)},[t,r]),V(()=>{r&&l.current?.focus()},[r]);let u=Oe({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),d=async()=>{let n=a.trim();if(n.length===0||n===t){i(!1),o(t);return}c(!0);try{await u.mutateAsync({deviceId:e,name:n}),i(!1)}catch{}finally{c(!1)}},f=()=>{o(t),i(!1)};return r?G(Q,{label:`Name`,value:q(`div`,{className:`flex items-center gap-1`,children:[G(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?d():e.key===`Escape`&&f()},disabled:s,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),G(`button`,{type:`button`,onClick:()=>void d(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:G(at,{className:`h-3 w-3`})}),G(`button`,{type:`button`,onClick:f,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:G(mt,{className:`h-3 w-3`})})]})}):G(Q,{label:`Name`,value:q(`div`,{className:`flex items-center gap-2 group`,children:[G(`span`,{className:`truncate`,children:t}),G(`button`,{type:`button`,onClick:()=>i(!0),className:`opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-surface-hover`,"aria-label":`Edit name`,children:G($e,{className:`h-3 w-3 text-foreground-subtle`})})]})})}W();function on({deviceId:e,initialLocation:t}){let n=K(),[r,i]=B(!1),[a,o]=B(t??``),[s,c]=B(!1),l=U(null),{data:u}=xe(void 0,{enabled:r}),d=u??[];V(()=>{r||o(t??``)},[t,r]),V(()=>{r&&l.current?.focus()},[r]);let f=A({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),p=H(()=>{let e=a.trim().toLowerCase();return e.length===0?d:d.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[d,a]),m=a.trim().length>0&&!d.some(e=>e.toLowerCase()===a.trim().toLowerCase()),h=async n=>{let r=(n??a).trim(),o=r.length===0?null:r;if(o===(t??null)){i(!1);return}c(!0);try{await f.mutateAsync({deviceId:e,location:o}),i(!1)}catch{}finally{c(!1)}},g=()=>{o(t??``),i(!1)};return r?G(Q,{label:`Location`,value:q(`div`,{className:`relative`,children:[q(`div`,{className:`flex items-center gap-1`,children:[G(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?h():e.key===`Escape`&&g()},disabled:s,placeholder:`Room / area (or leave empty to clear)`,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),G(`button`,{type:`button`,onClick:()=>void h(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:G(at,{className:`h-3 w-3`})}),G(`button`,{type:`button`,onClick:g,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:G(mt,{className:`h-3 w-3`})})]}),(p.length>0||m)&&q(`div`,{className:`absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md`,children:[p.map(e=>q(`button`,{type:`button`,onClick:()=>{o(e),h(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[G(Ft,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),G(`span`,{className:`truncate`,children:e})]},e)),m&&q(`button`,{type:`button`,onClick:()=>void h(),className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover border-t border-border`,children:[G(`span`,{className:`text-foreground-subtle`,children:`Create`}),q(`span`,{className:`font-medium truncate`,children:[`"`,a.trim(),`"`]})]})]})]})}):G(Q,{label:`Location`,value:q(`div`,{className:`flex items-center gap-2 group`,children:[t?G(`span`,{className:`truncate`,children:t}):G(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),G(`button`,{type:`button`,onClick:()=>i(!0),className:`opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-surface-hover`,"aria-label":`Edit location`,children:G($e,{className:`h-3 w-3 text-foreground-subtle`})})]})})}W();var sn=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function cn(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function ln(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function un(){let t=e(),n=se(),{data:r}=N({deviceId:t??0},{enabled:t!==null}),{data:i}=M({deviceId:t??0},{enabled:t!==null}),a=r??n??null,[o,s]=B(`identity`);if(t===null||!a)return null;let c=String(a.stableId??``),l=String(a.name??``),u=String(a.type??``),d=String(a.addonId??``),f=a.features??[],p=new Set([`device-status`,`feature-probe`,`device-ops`]),m=(i?.entries??[]).filter(e=>e.kind===`native`&&!p.has(e.capName)).map(e=>e.capName),h=f.length>0?f:m,g=a.location??null,_=a.metadata??null,v=_!==null&&Object.keys(_).length>0;return q(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[q(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[G(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),v&&q(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[G(dn,{active:o===`identity`,onClick:()=>s(`identity`),label:`Identity`}),G(dn,{active:o===`hardware`,onClick:()=>s(`hardware`),label:`Hardware`})]})]}),(!v||o===`identity`)&&q(`div`,{className:`divide-y divide-border`,children:[G(Q,{label:`ID`,value:q(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${t}`,q(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,c,`)`]})]})}),G(an,{deviceId:t,initialName:l}),G(on,{deviceId:t,initialLocation:g}),G(Q,{label:`Type`,value:u}),G(Q,{label:`Provider`,value:G(Qe,{type:d,size:`sm`,showLabel:!0})}),G(Q,{label:`Capabilities`,value:h.length>0?G(Je,{capabilities:h,showLabels:!0}):G(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),v&&o===`hardware`&&G(fn,{metadata:_})]})}function dn({active:e,onClick:t,label:n}){return G(`button`,{type:`button`,onClick:t,className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${e?`bg-surface text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`}`,children:n})}function fn({metadata:e}){let t=sn.filter(t=>t in e),n=Object.keys(e).filter(e=>!sn.includes(e)).toSorted(),r=[...t,...n];return q(`div`,{children:[G(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-b border-border bg-surface-subtle/40`,children:`Auto-populated by the driver on every connect. Read-only.`}),G(`div`,{className:`divide-y divide-border`,children:r.map(t=>G(Q,{label:cn(t),value:G(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:ln(e[t])})},t))})]})}W();function pn({deviceId:e}){let[t,n]=B(null),r=Ce({onSuccess:e=>{n(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>n(`Re-sync failed: ${e.message}`)});return q(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[q(`div`,{className:`flex items-center justify-between gap-3`,children:[q(`div`,{children:[G(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),G(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),q(`button`,{type:`button`,disabled:r.isPending,onClick:()=>{n(null),r.mutate({camDeviceId:e})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[G(tt,{className:`h-3 w-3 ${r.isPending?`animate-spin`:``}`}),r.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&G(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}function mn(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function hn({device:e}){let t=ot(),n=typeof e.id==`number`?e.id:null,r=String(e.type??``),i=r===Y.Camera,a=r===Y.Hub,o=e.features??[],s=o.includes(qe.Resyncable),{data:c}=fe({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),l=c?.streams??{},u=Object.entries(l),d=o.includes(qe.DoorbellButton),f=R(d?{deviceId:n??void 0,historyLimit:10}:void 0),p=f.latest?Date.now()-f.latest.timestamp<3e4:!1;return q(`div`,{className:`space-y-5`,children:[a&&n!==null&&G(be,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),s&&n!==null&&G(pn,{deviceId:n}),i&&n!==null&&G(ke,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),d&&G(we,{history:f.history,latestIsFresh:p}),i&&n!==null&&G(ke,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),i&&u.length>0&&q(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[G(`div`,{className:`border-b border-border px-4 py-2`,children:G(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),G(`div`,{className:`divide-y divide-border`,children:u.map(([e,t])=>q(`div`,{className:`px-4 py-2.5`,children:[q(`div`,{className:`flex items-center gap-2 mb-2`,children:[G(it,{className:`h-3 w-3 text-foreground-subtle`}),G(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),q(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[G(gn,{label:`Nominal`,value:mn(t.nominalBitrateKbps??0)}),G(gn,{label:`Observed`,value:mn(t.observedBitrateKbps??0)}),G(gn,{label:`Peak`,value:mn(t.peakBitrateKbps??0)}),G(gn,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),G(un,{})]})}function gn({label:e,value:t,warning:n}){return q(`div`,{children:[G(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),G(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}W();function _n({schema:e,values:t,pendingKeys:n,onChange:r,onAction:i,onSave:a,onDiscard:o,disabled:s,activeSubTab:c,onSubTabChange:l}){let u=e.tabs??[],d=H(()=>{let t=new Map;for(let n of e.sections){let e=n.tab??`general`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t},[e.sections]),f=new Set(u.map(e=>e.id)),p=[...u,...[...d.keys()].filter(e=>!f.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],m=p[0]?.id??`general`,[h,g]=B(m),_=l!==void 0,v=new Set(p.map(e=>e.id)),y=_?c&&v.has(c)?c:m:v.has(h)?h:m,b=e=>{_?l(e):g(e)},x=d.get(y)??[],S={sections:x.length<=1?x.length===1?[{...x[0],title:``}]:x:x.every(e=>!e.title)?[{...x[0],title:``,fields:x.flatMap(e=>e.fields)}]:x},C=G(Et,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>o(n),saving:s});if(p.length<=1)return q(`div`,{className:`flex flex-col gap-3`,children:[G(kt,{schema:e,values:t,onChange:r,onAction:i,disabled:s}),C]});let w=new Map,T=new Map;for(let[e,t]of d){w.set(e,t.length);let r=new Set,i=e=>{for(let t of e)if(`key`in t&&typeof t.key==`string`&&r.add(t.key),t.type===`group`)i(t.fields);else if(t.type===`sub-tabs`)for(let e of t.tabs)i(e.fields)};for(let e of t)i(e.fields);let a=n.filter(e=>r.has(e)).length;a>0&&T.set(e,a)}return q(`div`,{className:`flex flex-col gap-3`,children:[G(Ot,{tabs:p.map(e=>({id:e.id,label:e.label})),activeId:y,onChange:b,countByTab:w,pendingByTab:T}),G(kt,{schema:S,values:t,onChange:r,onAction:i,disabled:s}),C]})}W();function vn(e,t){return t&&t===`admin`?e:!0}function yn(e){if(!e)return null;let t={sections:[...e.sections].toSorted((e,t)=>{let n=e.tab??`general`,r=t.tab??`general`;return n===r?Ut(e)&&Ut(t)?e.id.localeCompare(t.id):(e.order??0)-(t.order??0):n.localeCompare(r)})};return e.tabs?{...t,tabs:e.tabs}:t}function bn(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`}function xn(e){return e.key}function Sn(e){if(!bn(e))return e.value}function Cn(e){return bn(e)?null:e}function wn(e,t){for(let n of e)if(t(n),n.type===`group`)wn(n.fields,t);else if(n.type===`sub-tabs`)for(let e of n.tabs)wn(e.fields,t)}function Tn(e){if(!e)return{};let t={};for(let n of e.sections)wn(n.fields,e=>{let n=xn(e);n!==null&&(t[n]=Sn(e))});return t}function En(e,t){if(!e)return null;let n=null;for(let r of e.sections)if(wn(r.fields,e=>{if(n!==null||xn(e)!==t)return;let r=Cn(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function Dn(e){return{...e,fields:e.fields.map(On)}}function On(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function kn(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=Cn(e);return n?vn(t,n.minRole)?e:On(e):e})}))}}function An({deviceId:e,sectionFilter:t,activeSubTab:n,onSubTabChange:r}){let i=K(),{user:a}=_t(),o=a?.isAdmin===!0,s=U(!1),{data:c,isLoading:l}=de({deviceId:e},{refetchInterval:()=>s.current?!1:2500,enabled:Number.isFinite(e)}),{data:u}=N({deviceId:e},{enabled:Number.isFinite(e)}),d=c?.settings??null,f=c?.live??null,p=H(()=>{if(!d&&!f)return null;let e=d?.sections??[],n=(f?.sections??[]).map(Dn),r=[...e,...n],i=t?r.filter(t):r.filter(e=>e.location!==`top-tab`&&!Ut(e));if(i.length===0)return null;let a=new Set;for(let e of i)a.add(e.tab??`general`);let o=[...d?.tabs??[],...(f?.tabs??[]).filter(e=>!(d?.tabs??[]).some(t=>t.id===e.id))].filter(e=>a.has(e.id));return o.length>0?{tabs:o,sections:i}:{sections:i}},[d,f,t]),m=H(()=>yn(p),[p]),h=H(()=>kn(m,o),[m,o]),g=H(()=>Tn(h),[h]),_=P(),v=Te(),b=Ae(),x=L(),S=y({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),C={isPending:S.isPending,mutate:t=>{S.mutate({deviceId:e,changes:[...t]})}},w=Dt({schema:h,serverValues:g,onImmediateSave:z(e=>{let t=Object.entries(e).map(([e,t])=>{let n=En(h,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&C.mutate(t)},[h,C]),onDeferredSave:z(e=>{let t=Object.entries(e).map(([e,t])=>{let n=En(h,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&C.mutate(t)},[h,C])}),{values:T,pendingKeys:E,handleChange:D,handleSave:O,handleDiscard:k}=w;if(s.current=w.editingPaused,l)return q(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[G(xt,{className:`h-4 w-4 animate-spin mr-2`}),G(`span`,{className:`text-xs`,children:`Loading device aggregate…`})]});if(!h||h.sections.length===0)return G(`div`,{className:`text-xs text-foreground-subtle italic py-4 text-center`,children:`No aggregate contributions for this device.`});async function A(t,n,r){if(t===`regenerate-rtsp-token`){let t=[`rtspUrl:`,`regenerateToken:`].find(e=>n.startsWith(e));if(!t)throw Error(`regenerate-rtsp-token: unrecognised key "${n}" (expected "rtspUrl:<streamId>" or "regenerateToken:<streamId>")`);let r=n.slice(t.length);if(!r)throw Error(`regenerate-rtsp-token: key "${n}" has no streamId after prefix`);let a=We(e,r);await _.mutateAsync({brokerId:a}),i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(t===`test-probe`){if(!u)return{status:`error`,error:`Device metadata not loaded yet`};try{return await b.mutateAsync({addonId:u.addonId,type:u.type,key:n,value:r})}catch(e){return{status:`error`,error:e instanceof Error?e.message:String(e)}}}if(t===`refresh-probe`){if(!n.startsWith(`probedInfo:`))throw Error(`refresh-probe: unrecognised key "${n}" (expected "probedInfo:<streamId>")`);let t=n.slice(11);if(!t)throw Error(`refresh-probe: key "${n}" has no streamId after prefix`);let r=We(e,t),a=await v.mutateAsync({brokerId:r});return i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),a}if(t===`device-custom-action`){let t=await x.mutateAsync({deviceId:e,action:n,input:r});return i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),t}throw Error(`[device-aggregate] unknown action "${t}"`)}return G(_n,{schema:h,values:T,pendingKeys:E,onChange:D,onAction:A,onSave:O,onDiscard:k,disabled:C.isPending,activeSubTab:n,onSubTabChange:r})}function jn({deviceId:e,activeSubTab:t,onSubTabChange:n}){return G(`div`,{className:`flex flex-col gap-3`,children:G(An,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}W(),W();function Mn({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){return q(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[G(Qe,{type:n,size:`lg`}),q(`div`,{children:[G(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),G(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),q(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[G(Ct,{status:r?`online`:`offline`}),i.length>0&&G(Je,{capabilities:i})]}),G(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:`No live view for this device type. Use the Config tab or the shortcut row to interact.`})]})}W();function Nn({deviceId:e}){let t=K(),n=d({deviceId:e},{refetchInterval:1e4,retry:!1}),r=k({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=H(()=>Pn(n.data??[]),[n.data]);return q(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[q(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[G(Fn,{label:`Discovered`,value:i.total,icon:G(dt,{className:`h-3.5 w-3.5`})}),G(Fn,{label:`Adopted`,value:i.adopted,accent:`success`}),G(Fn,{label:`Available`,value:i.available,accent:i.available>0?`primary`:void 0}),q(`button`,{type:`button`,onClick:()=>{r.mutateAsync({deviceId:e}).catch(()=>{})},disabled:r.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[r.isPending?G(xt,{className:`h-3.5 w-3.5 animate-spin`}):G(tt,{className:`h-3.5 w-3.5`}),G(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),q(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[G(In,{icon:G(it,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),G(In,{icon:G(bt,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),G(In,{icon:G(ft,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?G(In,{icon:G(jt,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.unknown} unknown`}):null]})]})}function Pn(e){let t={total:e.length,adopted:0,available:0,online:0,sleeping:0,offline:0,unknown:0};for(let n of e)n.alreadyAdopted?t.adopted+=1:t.available+=1,t[n.status]+=1;return t}function Fn({label:e,value:t,icon:n,accent:r}){return q(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${r===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:r===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[q(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,G(`span`,{className:`truncate`,children:e})]}),G(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function In({icon:e,label:t}){return q(`span`,{className:`inline-flex items-center gap-1`,children:[e,G(`span`,{children:t})]})}function Ln({deviceId:e,features:n}){return G(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:G(t,{trpc:J().trpcClient,deviceId:e,features:n})})}function Rn({deviceId:e,features:t}){return G(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:G(le,{trpc:J().trpcClient,deviceId:e,features:t})})}function $({deviceId:e,deviceType:t,features:n}){let r=J(),i=f(t)?.HeroCard??le,a=Ue(ze(r.trpcClient,e)?.state.deviceStatus),o=a!==void 0&&a.online===!1,s=o?a.lastChangedAt:null;return q(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[o?G(`div`,{className:`flex justify-center`,children:G(h,{lastChangedAt:s})}):null,G(i,{trpc:r.trpcClient,deviceId:e,features:n})]})}W();function zn({deviceId:e}){let t=J(),n=K(),{data:r,isLoading:i}=Tt(e),{data:a,isLoading:o}=wt(e),s=i||o,[c,u]=B(null),d=Pe({onSuccess:()=>{u(null),n.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{u(`Could not change primary child: ${e.message}`)}}),f=(a??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),p=typeof r?.linkDeviceId==`number`?r.linkDeviceId:null,m=typeof r?.primaryChildEntityId==`string`?r.primaryChildEntityId:null;return s?G(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):q(`div`,{className:`flex h-full w-full flex-col`,children:[G(l,{trpc:t.trpcClient,children:f,linkDeviceId:p,primaryChildEntityId:m,onSetPrimary:t=>d.mutate({deviceId:e,primaryChildEntityId:t})}),c!==null&&G(`p`,{role:`alert`,className:`px-3 pb-2 text-[11px] text-danger sm:px-4`,children:c})]})}var Bn={[Y.Switch]:$,[Y.Siren]:$,[Y.Light]:$,[Y.Sensor]:$,[Y.Button]:$,[Y.Hub]:Nn,[Y.Cover]:Ln,[Y.Valve]:$,[Y.Humidifier]:$,[Y.WaterHeater]:$,[Y.Container]:zn,[Y.Lock]:$,[Y.Fan]:$,[Y.Thermostat]:$,[Y.MediaPlayer]:$,[Y.Control]:$,[Y.AlarmPanel]:Rn,[Y.EventEmitter]:Rn,[Y.Notifier]:Rn,[Y.Script]:Rn,[Y.Automation]:Rn,[Y.Presence]:$,[Y.Update]:$,[Y.Vacuum]:$,[Y.LawnMower]:$,[Y.Weather]:$,[Y.Image]:$};function Vn(e){return G(Bn[e.deviceType]??Mn,{...e})}function Hn({deviceId:e}){let t=K(),n=Number.isFinite(e),{data:r}=N({deviceId:e},{enabled:n}),i=typeof r?.type==`string`?r.type:`camera`;At([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:a,isLoading:o,isError:s,error:c}=M({deviceId:e},{enabled:n}),{data:l}=te({deviceType:i},{enabled:!!i}),d=ee({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(o)return G(`div`,{className:`p-4`,children:G(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(s)return q(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,c instanceof Error?c.message:String(c)]});let f=new Map,p={};for(let e of l??[])p[e.capName]=e.wrappers;for(let e of a?.entries??[])f.set(e.capName,{...e,wrappers:p[e.capName]??[]});for(let e of l??[])f.has(e.capName)||f.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let m=[...f.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(m.length===0)return q(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[G(Xe,{className:`h-8 w-8 opacity-40`}),G(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),G(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let h=m.filter(e=>e.kind!==`unbound`).length;return q(`div`,{className:`flex flex-col gap-3 p-1`,children:[q(`div`,{className:`text-[11px] text-foreground-subtle`,children:[G(`span`,{className:`font-medium text-foreground`,children:h}),` of `,m.length,` capabilit`,m.length===1?`y`:`ies`,` bound — rows marked `,G(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),G(u,{columns:[{key:`capability`,header:`Capability`,render:e=>G(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>G(Un,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>G(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||G(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?G(Wn,{nodeId:e.providerNodeId}):G(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>G(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||G(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return G(Gn,{wrappers:t.wrappers,activeWrapperId:n,disabled:d.isPending,onPick:r=>{let i=n===r;d.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:m,rowKey:e=>e.capName,minWidthPx:720})]})}function Un({kind:e}){return e===`native`?q(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[G(rt,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?q(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[G(Mt,{className:`h-3 w-3`}),`wrapped`]}):q(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[G(It,{className:`h-3 w-3`}),`unbound`]})}function Wn({nodeId:e}){return G(`span`,{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e===`hub`?`text-foreground-subtle`:`text-foreground`}`,children:e})}function Gn({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){return e.length===0?G(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):G(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let i=e===t;return q(`button`,{disabled:n,onClick:()=>r(e),title:i?`Click to deactivate (revert to native)`:`Activate wrapper ${e}`,className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${i?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[G(i?at:Ze,{className:`h-3 w-3`}),e]},e)})})}W();function Kn(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function qn(e,t,n){let r=e?.stepOverridesByAgent?.[t]?.[n];if(r)return r.enabled===!1?`off`:(r.enabled,`on`);let i=e?.stepToggles?.[n];return i===!1?`off`:i===!0?`on`:`inherit`}function Jn({agents:e,currentAgent:t,onPick:n}){let[r,i]=B(!1);return q(`div`,{className:`relative`,children:[G(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>i(e=>!e),children:`Mirror from ▾`}),r&&G(`div`,{className:`absolute top-full left-0 mt-1 min-w-[140px] bg-surface border border-border rounded shadow-lg z-10`,children:e.filter(e=>e!==t).map(e=>G(`button`,{type:`button`,className:`w-full text-left px-3 py-1.5 text-xs hover:bg-muted`,onClick:()=>{i(!1),n(e)},children:e},e))})]})}function Yn({deviceId:e,refreshToken:t}){let r=K(),[i,a]=B(null),[s,c]=B(null),[l,u]=B(null),[d,f]=B(null),m=_({deviceId:e}),h=w(),g=Ie({deviceId:e}),v=n(),y=H(()=>g.data?.agentNodeId||v.data?.find(e=>e.online)?.nodeId||`hub`,[g.data?.agentNodeId,v.data]),b=s??y,x=je({nodeId:b??``},{enabled:!!b}),S=O({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),u(null)}}),C=H(()=>x.data?p(x.data):[],[x.data]),T=H(()=>{let e=m.data??null,t={};for(let n of h.data??[])for(let r of Object.keys(n.settings.addonDefaults)){let i=t[r]??[];i.push({agentNodeId:n.nodeId,state:qn(e,n.nodeId,r)}),t[r]=i}return t},[m.data,h.data]),D=i?Kn(x.data??null,i):null,k=b?h.data?.find(e=>e.nodeId===b)??null:null,A=i&&k?k.settings.addonDefaults[i]??null:null,j=i&&b?m.data?.stepOverridesByAgent?.[b]?.[i]??null:null,M=x.data?.selectedEngine.format??`coreml`,ee=e=>{c(e),u(null),f(null)};return h.isLoading||x.isLoading?G(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`}):x.data?G(`div`,{className:`@container h-full`,style:{containerType:`inline-size`},children:q(`div`,{className:`flex flex-col @[720px]:flex-row h-full`,children:[G(`aside`,{className:`w-full @[720px]:w-[300px] @[720px]:flex-shrink-0 border-b @[720px]:border-b-0 @[720px]:border-r border-border overflow-y-auto max-h-[40vh] @[720px]:max-h-none`,children:G(o,{tree:C,selectedAddonId:i,onSelect:e=>{a(e),u(null),f(null)},agentDots:T})}),G(`section`,{className:`flex-1 min-w-0 p-4 overflow-y-auto`,children:!i||!D?G(`div`,{className:`text-sm text-foreground-subtle`,children:`Select a step on the left to configure it for this camera.`}):q(`div`,{className:`space-y-4`,children:[q(`div`,{children:[G(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle`,children:`Selected step`}),G(`div`,{className:`text-base font-semibold`,children:D.name})]}),q(`div`,{className:`flex items-end gap-3 flex-wrap`,children:[q(`div`,{children:[G(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle mb-1`,children:`Agent`}),G(`div`,{className:`flex rounded border border-border overflow-hidden`,children:(h.data??[]).map(e=>G(`button`,{type:`button`,onClick:()=>ee(e.nodeId),className:`px-3 py-1 text-xs ${b===e.nodeId?`bg-primary text-primary-foreground`:`bg-surface hover:bg-muted`}`,children:e.nodeId},e.nodeId))})]}),G(Jn,{agents:(h.data??[]).map(e=>e.nodeId),currentAgent:b,onPick:e=>{if(!b||!i||!x.data||!h.data)return;let t=h.data.find(t=>t.nodeId===e),n=h.data.find(e=>e.nodeId===b);if(!t||!n)return;let[r]=Ne({source:{nodeId:t.nodeId,engine:{format:M},defaults:t.settings.addonDefaults},target:{nodeId:n.nodeId,engine:{format:M},defaults:n.settings.addonDefaults},catalog:x.data,addonIds:[i]});if(!r){f(`no mirror result`);return}if(r.outcome===`skip`){f(`skipped: ${r.reason??`no candidate`}`);return}u(r.patch),f(`${r.outcome} from ${e}`)}}),d&&G(`div`,{className:`text-[10px] text-foreground-subtle`,children:d})]}),A&&G(E,{mode:`device`,addon:D,agentDefault:A,agentNodeId:b??``,currentPatch:l??j,engineFormat:M,onChangePatch:u}),q(`div`,{className:`flex items-center justify-between gap-2 pt-4 border-t border-border`,children:[G(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle`,disabled:!j||S.isPending,onClick:()=>{!b||!i||S.mutate({deviceId:e,agentNodeId:b,addonId:i,patch:null})},children:`Clear override`}),q(`div`,{className:`flex items-center gap-2`,children:[G(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>u(null),children:`Reset draft`}),G(`button`,{type:`button`,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,disabled:!b||!i||S.isPending,onClick:()=>{!b||!i||S.mutate({deviceId:e,agentNodeId:b,addonId:i,patch:l})},children:S.isPending?`Saving…`:`Save`})]})]})]})})]})}):G(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`})}W();function Xn(e,t){if(t===`number`){let t=Number(e);return Number.isNaN(t)?e:t}return t===`boolean`?e===`true`:e}function Zn(e,t){let n={};for(let r of e)r.key!==``&&r.value!==``&&(n[r.key]=Xn(r.value,t));return n}function Qn(e,t){return e?.kind===`enum-map`?Object.entries(e.mapping).map(([e,t])=>({key:e,value:String(t)})):t?.kind===`enum`&&t.enumValues?t.enumValues.map(e=>({key:e,value:``})):[{key:``,value:``}]}function $n(e){return e?.kind===`linear`?{scale:String(e.scale),offset:String(e.offset),clampMin:e.clamp?String(e.clamp[0]):``,clampMax:e.clamp?String(e.clamp[1]):``,useClamp:e.clamp!=null}:{scale:`1`,offset:`0`,clampMin:``,clampMax:``,useClamp:!1}}function er(e){return e==null?`identity`:e.kind}function tr({value:e,onChange:t,sourceField:n,targetKind:r}){let[i,a]=B(()=>er(e)),[o,s]=B(()=>Qn(e,n)),[c,l]=B(()=>e?.kind===`enum-map`&&e.fallback!=null?String(e.fallback):``),[u,d]=B(()=>$n(e));V(()=>{if(i===`enum-map`&&n?.kind===`enum`&&n.enumValues){let e=n.enumValues;s(t=>e.map(e=>({key:e,value:t.find(t=>t.key===e)?.value??``})))}},[n,i]),V(()=>{if(i===`identity`){t(void 0);return}if(i===`enum-map`){let e=Zn(o,r),n=c===``?void 0:Xn(c,r);t({kind:`enum-map`,mapping:e,...n===void 0?{}:{fallback:n}});return}if(i===`linear`){let e=Number(u.scale),n=Number(u.offset);if(Number.isNaN(e)||Number.isNaN(n))return;let r=Number(u.clampMin),i=Number(u.clampMax),a=u.useClamp&&!Number.isNaN(r)&&!Number.isNaN(i)?[r,i]:void 0;t({kind:`linear`,scale:e,offset:n,...a?{clamp:a}:{}})}},[i,o,c,u,r,t]);let f=e=>{a(e),e===`enum-map`&&s(Qn(void 0,n)),e===`linear`&&d($n(void 0))},p=(e,t,n)=>{s(r=>r.map((r,i)=>i===e?{...r,[t]:n}:r))},m=()=>s(e=>[...e,{key:``,value:``}]),h=e=>s(t=>t.filter((t,n)=>n!==e));return q(`div`,{className:`flex flex-col gap-3`,children:[q(`div`,{children:[G(`p`,{className:`text-[11px] font-medium text-foreground-subtle mb-1.5`,children:`Transform`}),G(`div`,{className:`flex items-center gap-4`,children:[`identity`,`enum-map`,`linear`].map(e=>q(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[G(`input`,{type:`radio`,name:`transform-kind`,value:e,checked:i===e,onChange:()=>f(e),className:`accent-primary`}),e===`identity`?`None`:e]},e))})]}),i===`enum-map`&&q(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[G(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Key → Value mapping`}),o.map((e,t)=>q(`div`,{className:`flex items-center gap-1.5`,children:[G(`input`,{"aria-label":`enum key ${t}`,type:`text`,value:e.key,readOnly:n?.kind===`enum`,onChange:e=>p(t,`key`,e.target.value),placeholder:`source value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none read-only:opacity-70`}),G(`span`,{className:`text-foreground-subtle/50 text-xs`,children:`→`}),r===`boolean`?q(`select`,{"aria-label":`enum value ${t}`,value:e.value,onChange:e=>p(t,`value`,e.target.value),className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`,children:[G(`option`,{value:``,children:`—`}),G(`option`,{value:`true`,children:`true`}),G(`option`,{value:`false`,children:`false`})]}):G(`input`,{"aria-label":`enum value ${t}`,type:r===`number`?`number`:`text`,value:e.value,onChange:e=>p(t,`value`,e.target.value),placeholder:`target value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none`}),n?.kind!==`enum`&&G(`button`,{type:`button`,onClick:()=>h(t),className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] border border-border/80 text-foreground-subtle hover:text-danger hover:border-danger/50 transition-colors`,children:`✕`})]},t)),n?.kind!==`enum`&&G(`button`,{type:`button`,onClick:m,className:`self-start text-[10px] text-primary/70 hover:text-primary transition-colors`,children:`+ Add row`}),q(`div`,{className:`flex items-center gap-2 pt-1 border-t border-border/50`,children:[G(`label`,{className:`text-[10px] text-foreground-subtle/70 whitespace-nowrap`,children:`Fallback:`}),G(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`(leave empty for none)`,className:`flex-1 rounded border border-border bg-background px-2 py-0.5 text-xs font-mono text-foreground focus:border-primary outline-none`})]})]}),i===`linear`&&q(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[G(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Linear: value × scale + offset`}),q(`div`,{className:`grid grid-cols-2 gap-2`,children:[q(`label`,{className:`flex flex-col gap-0.5`,children:[G(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Scale`}),G(`input`,{type:`number`,value:u.scale,onChange:e=>d(t=>({...t,scale:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),q(`label`,{className:`flex flex-col gap-0.5`,children:[G(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Offset`}),G(`input`,{type:`number`,value:u.offset,onChange:e=>d(t=>({...t,offset:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]}),q(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[G(`input`,{type:`checkbox`,checked:u.useClamp,onChange:e=>d(t=>({...t,useClamp:e.target.checked})),className:`accent-primary`}),G(`span`,{className:`text-foreground-subtle`,children:`Clamp output`})]}),u.useClamp&&q(`div`,{className:`grid grid-cols-2 gap-2`,children:[q(`label`,{className:`flex flex-col gap-0.5`,children:[G(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Min`}),G(`input`,{type:`number`,value:u.clampMin,onChange:e=>d(t=>({...t,clampMin:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),q(`label`,{className:`flex flex-col gap-0.5`,children:[G(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Max`}),G(`input`,{type:`number`,value:u.clampMax,onChange:e=>d(t=>({...t,clampMax:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]})]})]})}W();function nr(e,t){return`${e.replace(/[^a-z0-9]/gi,`-`)}-${t.replace(/[^a-z0-9]/gi,`-`)}`}function rr(e,t,n){let r=`${t}-${e}`;return n.find(e=>e.stableId===r)?.id??null}function ir({deviceId:e,parentDeviceId:t,deviceStableId:n,initial:r,onSave:i,onCancel:a}){let{data:o}=F({}),s=o??[],c=t==null?n:s.find(e=>e.id===t)?.stableId??n,l=s.filter(n=>n.parentDeviceId===t&&n.id!==e),{data:u}=Ee({deviceId:e}),d=u?.caps??[],f=r==null?null:rr(r.source.sourceKey,c,s),[p,m]=B(r?.target.cap??``),[h,g]=B(r?.target.fieldPath??``),[_,v]=B(f),[y,b]=B(r?.source.cap??``),[x,S]=B(r?.source.fieldPath??``),[C,w]=B(r?.transform);V(()=>{if(r!=null&&_===null&&s.length>0){let e=rr(r.source.sourceKey,c,s);e!==null&&v(e)}},[r,_,s,c]);let{data:T}=Ee({deviceId:_??0},{enabled:_!=null}),E=T?.caps??[],D=d.find(e=>e.cap===p)?.fields??[],O=D.find(e=>e.path===h),k=E.find(e=>e.cap===y)?.fields??[],A=k.find(e=>e.path===x),j=e=>{m(e),g(``)},M=e=>{v(e===``?null:Number(e)),b(``),S(``)},ee=e=>{b(e),S(``)},N=p!==``&&h!==``&&_!=null&&y!==``&&x!==``,P=()=>{if(!N)return;let e=s.find(e=>e.id===_),t=`${c}-`,n=e&&e.stableId.startsWith(t)?e.stableId.slice(t.length):``;i({id:r?.id??nr(p,h),source:{sourceKey:n,cap:y,fieldPath:x},target:{cap:p,fieldPath:h},...C==null?{}:{transform:C}})},I=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`;return q(`div`,{className:`flex flex-col gap-4 p-3`,children:[q(`fieldset`,{className:`flex flex-col gap-3`,children:[G(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Target (this device)`}),q(`div`,{children:[G(`label`,{htmlFor:`link-target-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target cap`}),q(`select`,{id:`link-target-cap`,value:p,onChange:e=>j(e.target.value),className:I,children:[G(`option`,{value:``,children:`— select a cap —`}),d.map(e=>G(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),q(`div`,{children:[G(`label`,{htmlFor:`link-target-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target field`}),q(`select`,{id:`link-target-field`,value:h,disabled:p===``,onChange:e=>g(e.target.value),className:I,children:[G(`option`,{value:``,children:`— select a field —`}),D.map(e=>q(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]}),q(`fieldset`,{className:`flex flex-col gap-3`,children:[G(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Source (sibling device)`}),q(`div`,{children:[G(`label`,{htmlFor:`link-source-device`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source device`}),q(`select`,{id:`link-source-device`,value:_??``,onChange:e=>M(e.target.value),className:I,children:[G(`option`,{value:``,children:`— select a device —`}),l.map(e=>q(`option`,{value:e.id,children:[e.name??e.stableId,` (#`,e.id,`)`]},e.id))]})]}),q(`div`,{children:[G(`label`,{htmlFor:`link-source-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source cap`}),q(`select`,{id:`link-source-cap`,value:y,disabled:_==null,onChange:e=>ee(e.target.value),className:I,children:[G(`option`,{value:``,children:`— select a cap —`}),E.map(e=>G(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),q(`div`,{children:[G(`label`,{htmlFor:`link-source-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source field`}),q(`select`,{id:`link-source-field`,value:x,disabled:y===``,onChange:e=>S(e.target.value),className:I,children:[G(`option`,{value:``,children:`— select a field —`}),k.map(e=>q(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]}),G(tr,{value:C,onChange:w,sourceField:A,targetKind:O?.kind}),q(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-border`,children:[G(`button`,{type:`button`,onClick:a,className:`px-3 py-1.5 rounded-md text-xs font-medium border border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,children:`Cancel`}),G(`button`,{type:`button`,disabled:!N,onClick:P,className:`px-3 py-1.5 rounded-md text-xs font-medium bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:`Save`})]})]})}W();function ar({deviceId:e}){let t=J(),n=K(),{data:r,isLoading:i}=N({deviceId:e},{enabled:Number.isFinite(e),refetchInterval:1e4}),a=re({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),o=r?.deviceLinks??[],s=typeof r?.parentDeviceId==`number`?r.parentDeviceId:null,c=typeof r?.stableId==`string`?r.stableId:``,[l,u]=B(null),d=t=>{a.mutate({deviceId:e,deviceLinks:o.filter(e=>e.id!==t)})};return i?G(`div`,{className:`p-4`,children:G(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})}):l===null?q(`div`,{className:`flex flex-col gap-3 p-1`,children:[q(`div`,{className:`flex items-center justify-between`,children:[G(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Wiring`}),q(`button`,{type:`button`,onClick:()=>u(`new`),title:`Add a cross-device link`,className:`inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[G(et,{className:`h-3 w-3`}),`Add link`]})]}),o.length===0?q(`div`,{className:`flex flex-col items-center justify-center gap-2 py-8 text-foreground-subtle`,children:[G(Nt,{className:`h-8 w-8 opacity-30`}),G(`p`,{className:`text-xs`,children:`No links yet.`}),G(`p`,{className:`text-[10px] opacity-60`,children:`Cross-device field wirings will appear here once authored.`})]}):G(`div`,{className:`flex flex-col divide-y divide-border rounded-lg border border-border overflow-hidden`,children:o.map(n=>G(or,{deviceId:e,link:n,trpcClient:t.trpcClient,onDelete:()=>d(n.id),onEdit:()=>u(n),isPending:a.isPending},n.id))})]}):q(`div`,{className:`flex flex-col gap-3 p-1`,children:[G(`div`,{className:`flex items-center justify-between`,children:G(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:l===`new`?`Add link`:`Edit link`})}),G(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:G(ir,{deviceId:e,parentDeviceId:s,deviceStableId:c,initial:l===`new`?null:l,onSave:t=>{let n=o.some(e=>e.id===t.id)?o.map(e=>e.id===t.id?t:e):[...o,t];a.mutate({deviceId:e,deviceLinks:n}),u(null)},onCancel:()=>{u(null)}})})]})}function or({deviceId:e,link:t,trpcClient:n,onDelete:r,onEdit:i,isPending:a}){let o=ge(n,e,t.target.cap),s=o===void 0?void 0:Ke(o,t.target.fieldPath),c=s==null?`—`:String(s);return q(`div`,{className:`flex items-center gap-3 px-3 py-2.5 bg-surface hover:bg-surface-hover transition-colors`,children:[G(Pt,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle/40`}),q(`div`,{className:`min-w-0 flex-1 flex flex-col gap-0.5`,children:[q(`div`,{className:`flex items-baseline gap-1 flex-wrap`,children:[G(`span`,{className:`font-mono text-[11px] font-medium text-foreground`,children:t.target.cap}),G(`span`,{className:`text-[10px] text-foreground-subtle/60`,children:`.`}),G(`span`,{className:`font-mono text-[11px] text-foreground-subtle`,children:t.target.fieldPath})]}),q(`div`,{className:`flex items-baseline gap-1 flex-wrap text-[10px] text-foreground-subtle/70`,children:[G(`span`,{children:`←`}),G(`span`,{className:`font-mono`,children:t.source.sourceKey}),G(`span`,{className:`opacity-60`,children:`/`}),G(`span`,{className:`font-mono`,children:t.source.cap}),G(`span`,{className:`opacity-60`,children:`.`}),G(`span`,{className:`font-mono`,children:t.source.fieldPath})]})]}),t.transform&&G(sr,{kind:t.transform.kind}),G(`span`,{className:`font-mono text-[11px] tabular-nums min-w-[2.5rem] text-right text-foreground-subtle`,title:`Live resolved value (from this device's runtime-state slice)`,children:c}),G(`button`,{type:`button`,"aria-label":`Edit link`,title:`Edit this link`,disabled:a,onClick:i,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:`Edit`}),G(`button`,{type:`button`,"aria-label":`Delete link`,title:`Remove this link`,disabled:a,onClick:r,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-danger hover:border-danger/50 hover:bg-danger/5 transition-colors disabled:opacity-50`,children:`Delete`})]})}function sr({kind:e}){return G(`span`,{className:`inline-flex items-center rounded-md border border-primary/20 bg-primary/5 px-1.5 py-0.5 font-mono text-[10px] text-primary/80 shrink-0`,children:e})}W();var cr=[{id:`overview`,label:`Overview`,cameraOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1},{id:`pipeline`,label:`Pipeline steps`,cameraOnly:!0},{id:`bindings`,label:`Bindings`,cameraOnly:!0},{id:`wiring`,label:`Wiring`,cameraOnly:!1}];function lr(e){let t=e===Y.Camera;return cr.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var ur=[{id:`logs`,icon:gt,label:`Logs`},{id:`repl`,icon:pt,label:`REPL`},{id:`events`,icon:Ye,label:`Events`},{id:`state`,icon:ct,label:`State`}];function dr(){let e=lt(),t=Number(e.deviceId),n=Number.isFinite(t),r=ot(),i=K(),o=g(),s=J(),[c,l]=ut(),u=c.get(`tab`)??`overview`,d=c.get(`sub`),[f,p]=B(`logs`),m=`device-detail.left-col-width-px`,[h,_]=B(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(m),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),y=U(h);y.current=h;function C(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??h??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{_(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=y.current;if(e!==null)try{window.localStorage.setItem(m,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:w,isLoading:T,isError:E}=N({deviceId:t},{enabled:n,refetchInterval:5e3,retry:1}),{data:O}=de({deviceId:t},{enabled:n}),k=H(()=>{let e=O?.settings?.sections??[],t=O?.live?.sections??[],n=[...e,...t],r=new Set;for(let e of n)e.location===`top-tab`&&e.tab&&r.add(e.tab===`zones`?`detection-pipeline`:e.tab);return n.some(Ut)&&r.add(Bt),[...r].map(e=>e===`export`?{id:e,label:Vt,isAddonContrib:!0}:{id:e,label:Ge[e]?.label??e,isAddonContrib:!0})},[O]),A=w,j=String(A?.name??e.deviceId??`Device`),M=A?.online===!0,ee=M?`online`:`offline`,P=String(A?.addonId??`rtsp`),F=A?.features??[],I=A?.type,te=I===Y.Camera,ne=typeof A?.parentDeviceId==`number`?A.parentDeviceId:null,{data:re}=N({deviceId:ne??0},{enabled:ne!==null}),L=v(),ie=A?.disabled!==!0,{data:se}=Ee({deviceId:t},{enabled:n}),le=(se?.caps.length??0)>0,fe=H(()=>{let e=new Set,t=[];for(let n of[...lr(I),...k])e.has(n.id)||(e.add(n.id),!(n.id===`wiring`&&!le)&&t.push(n));return t},[I,k,le]),me=H(()=>fe.some(e=>e.id===u)?u:`overview`,[fe,u]),ge=z(e=>{l(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[l]),be=z(e=>{l(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[l]),{data:xe}=wt(n?t:0),Se=(xe??[]).length>0,Ce=H(()=>ur.filter(({featureGate:e})=>!e||F.includes(e)),[F]),{data:R}=Fe({addonId:P},{enabled:!!P&&P!==`rtsp`}),we=he({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]}),r(R?.id?`/integrations/${R.id}`:`/integrations`)}}),Te=oe({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),De=ve({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Oe=ae(),ke=pe({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ae=F.includes(qe.Rebootable),je=F.includes(qe.BatteryOperated),Me=a(s.trpcClient,je&&n?t:null),[Ne,Pe]=B(!1),V=ze(s.trpcClient,n?t:null),W=async()=>{if(!(Ne||!V)){Pe(!0);try{await V.snapshot?.invalidateCache({});let e=await V.snapshot?.getSnapshot({});if(!e)return;let t=`data:${e.contentType};base64,${e.base64}`,n=e.contentType.includes(`png`)?`png`:`jpg`,r=j.replace(/[^a-zA-Z0-9_.-]+/g,`_`),i=new Date().toISOString().replace(/[:.]/g,`-`),a=document.createElement(`a`);a.href=t,a.download=`${r}-${i}.${n}`,document.body.appendChild(a),a.click(),document.body.removeChild(a)}finally{Pe(!1)}}},Le=Te.isPending||De.isPending,{data:Re}=Ie({deviceId:t},{enabled:n,refetchInterval:1e4}),Be=Re?.agentNodeId??null,Ve=typeof Be==`string`&&Be.length>0&&!Be.startsWith(`addon:`)?Be:void 0,{data:Ue}=_e({deviceId:t,...Ve?{nodeId:Ve}:{}},{enabled:n,refetchInterval:3e3,retry:!1}),{data:We}=x({deviceId:t},{enabled:n,refetchInterval:3e3,retry:!1}),Ke=We?.level?.dbfs??null;function Ye(){if(!n)return null;switch(me){case`overview`:return G(hn,{device:A??{}});case`config`:return G(jn,{deviceId:t,activeSubTab:d,onSubTabChange:be});case`pipeline`:return G(Yn,{deviceId:t,refreshToken:0});case`bindings`:return G(Hn,{deviceId:t});case`wiring`:return G(ar,{deviceId:t});default:{let e=me;return k.some(t=>t.id===e)?e===`export`?G(An,{deviceId:t,sectionFilter:Ut,activeSubTab:d,onSubTabChange:be}):G(An,{deviceId:t,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),activeSubTab:d,onSubTabChange:be}):null}}}return n?T?q(`div`,{className:`flex flex-col h-full`,children:[q(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[G(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),G(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),G(`div`,{className:`flex-1 p-6`,children:G(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):E||!w?q(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[G(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),q(`p`,{className:`text-xs`,children:[`No device with ID`,` `,q(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,t]})]}),G(`button`,{onClick:()=>r(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]}):q(`div`,{className:`absolute inset-0 flex flex-col overflow-hidden`,children:[q(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[G(`div`,{className:`mb-2`,children:G(D,{items:[{label:`Integrations`,onClick:()=>r(`/integrations`)},{label:R?.name??P,onClick:()=>R?.id&&r(`/integrations/${R.id}`)},{label:j}]})}),q(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[G(Qe,{type:P,size:`lg`}),q(`div`,{className:`min-w-0 flex-1`,children:[q(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[G(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:j}),G(Ct,{status:ee}),je&&G(S,{status:Me,variant:`full`})]}),ne!==null&&re&&q(`button`,{type:`button`,onClick:()=>r(`/devices/${ne}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${re.name}`,children:[G(`span`,{children:`↑`}),G(`span`,{className:`truncate`,children:String(re.name??`Device #${ne}`)})]}),G(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:F.length>0&&G(Je,{capabilities:F})})]}),Ue&&G(`div`,{className:`hidden lg:flex`,children:G(fr,{metrics:Ue,dbfs:Ke})}),q(`div`,{className:`flex items-center gap-1 shrink-0`,children:[q(`button`,{onClick:async()=>{ie?await o({title:`Disable "${j}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&De.mutate({deviceId:t}):Te.mutate({deviceId:t})},disabled:Le,title:ie?`Disable device`:`Enable device`,className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border transition-colors disabled:opacity-50 ${ie?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[G(Lt,{className:`h-3.5 w-3.5`}),G(`span`,{className:`hidden sm:inline`,children:Le?`Updating…`:ie?`Enabled`:`Disabled`})]}),G(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),G(ue,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:st,disabled:Ne,onClick:()=>{W()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:nt,hidden:!Ae,disabled:Oe.isPending,danger:!0,onClick:async()=>{await o({title:`Reboot "${j}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Oe.mutate({deviceId:t})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${R?.name??P}.`,icon:tt,disabled:ke.isPending,danger:!0,onClick:async()=>{await o({title:`Restart "${R?.name??P}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${j}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&ke.mutate({addonId:P})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:vt,separatorBefore:!0,disabled:we.isPending,danger:!0,onClick:async()=>{await o({title:`Delete "${j}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&we.mutate({deviceId:t})}}]})]})]})]}),G(ce,{deviceId:t,device:A??void 0,children:G(b,{children:G(He,{children:G(ye,{children:q(`main`,{className:L?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[q(`div`,{className:L?`flex flex-col bg-surface`:`${h===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!L&&h!==null?{width:`${String(h)}px`}:void 0,children:[G(`div`,{className:`flex-shrink-0 border-b border-border-subtle ${te?`bg-black`:`bg-surface`}`,children:te?G(Qt,{deviceId:t,intercomAvailable:F.includes(qe.TwoWayAudio)}):G(Vn,{deviceId:t,deviceName:j,deviceType:I??`unknown`,provider:P,isOnline:M,features:F})}),q(`div`,{className:L?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[G(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:G(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:Ce.map(({id:e,label:t,icon:n})=>q(`button`,{onClick:()=>p(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${f===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[G(n,{className:`h-3 w-3`}),t]},e))})}),q(`div`,{className:L?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[f===`logs`&&G($t,{deviceId:t,containerDeviceId:I===`container`?t:void 0}),f===`repl`&&G(en,{deviceId:t}),f===`events`&&G(tn,{deviceId:t}),f===`state`&&G(nn,{deviceId:t})]})]})]}),!L&&G(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:C,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:G(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),q(`div`,{className:L?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[G(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:G(`div`,{className:`flex flex-wrap items-center gap-0`,children:fe.map(e=>{let t=me===e.id;return q(`button`,{onClick:()=>ge(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&G(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),q(`div`,{className:L?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[me===`overview`&&Se&&G(rn,{parentDeviceId:t}),Ye()]})]})]})})})})})]}):q(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[G(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),q(`p`,{className:`text-xs`,children:[`The URL segment`,` `,G(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:e.deviceId}),` `,`is not a number.`]}),G(`button`,{onClick:()=>r(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]})}function fr({metrics:e,dbfs:t}){let n=De(e.phase??`idle`);return q(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[q(`div`,{className:`flex items-center gap-1.5`,children:[G(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),G(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),G(`div`,{className:`h-3 w-px bg-border`}),q(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[G(St,{className:`h-3 w-3`}),G(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),G(`span`,{children:`fps`})]}),q(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[G(ht,{className:`h-3 w-3`}),G(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),G(`span`,{children:`ms`})]}),q(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[G(Rt,{className:`h-3 w-3`}),G(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),G(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&q(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{dr as DeviceDetailPage};
@@ -1 +1 @@
1
- import{R as e,Vn as t,dn as n,in as r,mn as i,nn as a}from"./src-Dxc7AUYA.js";import{F as o,U as s,X as c,b as l,o as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{p as f}from"./player-overlays-zGqQhGgE.js";import{t as p}from"./ProviderIcon-DU7EkOsQ.js";import{H as m,I as h,o as g,t as _}from"./index-DpTstpp_.js";import{t as v}from"./AdminPage-CN6ZMhf0.js";import{t as y}from"./useEventInvalidation-DDUSWISR.js";c();function b(){let{t:c}=_(),b=m(),x=f(),S=u();y([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]),y([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`]);let{data:C}=n({}),{data:w}=t(void 0),T=i({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),E=a({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),D=r({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),O=s(()=>C??[],[C]),{activeDevices:k,orphanDevices:A}=s(()=>{let e=new Set((w??[]).map(e=>e.addonId)),t=t=>typeof t.addonId==`string`&&t.addonId.length>0&&!e.has(t.addonId),n=new Set;for(let e of O)t(e)&&n.add(e.id);let r=new Set(n),i=new Map;for(let e of O)i.set(e.id,e);let a=(e,t=0)=>{if(t>32)return!1;if(n.has(e.id))return!0;if(e.parentDeviceId==null)return!1;let r=i.get(e.parentDeviceId);return r?a(r,t+1):!1};for(let e of O)a(e)&&r.add(e.id);let o=[],s=[];for(let e of O)r.has(e.id)?s.push(e):o.push(e);return{activeDevices:o,orphanDevices:s}},[O,w]),j=s(()=>{let e=new Map;for(let t of O)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[O]),M=o(e=>j.get(e)??null,[j]),N=s(()=>(w??[]).map(e=>({id:e.addonId,name:e.name??e.addonId,icon:l(p,{type:e.addonId,size:`sm`})})),[w]),P=o(e=>l(p,{type:e,size:`sm`}),[]),F=o(e=>b(`/devices/${String(e)}`),[b]);return d(v,{icon:h,title:c(`nav.devices`,`Devices`),children:[l(e,{context:`devices`,devices:k,trpc:x.trpcClient,filters:{addons:N},resolveIntegrationIcon:P,resolveParent:M,onNavigate:F,batchActions:{remove:T.mutate,disable:E.mutate,enable:D.mutate}}),A.length>0&&d(`div`,{className:`mt-6 space-y-2`,children:[d(`div`,{className:`flex items-baseline gap-2`,children:[l(g,{className:`h-3.5 w-3.5 text-warning shrink-0`}),l(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Orphan devices`}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:[A.length,` device`,A.length===1?``:`s`,` pointing at integrations no longer registered`]})]}),d(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 p-2`,children:[l(`p`,{className:`text-[11px] text-foreground-subtle px-2 pb-2`,children:"These devices reference an addonId that has no matching integration. Delete them, or re-install the missing integration to bring them back online. The provider scope (`addonId`) shown beside each row is what's failing to resolve."}),l(e,{context:`devices`,devices:A,trpc:x.trpcClient,filters:{addons:N},urlScope:`nested`,lsKey:`devices:orphan`,resolveIntegrationIcon:P,resolveParent:M,onNavigate:F})]})]})]})}export{b as DevicesPage};
1
+ import{R as e,Vn as t,dn as n,in as r,mn as i,nn as a}from"./src-BB1LG2-C.js";import{F as o,U as s,X as c,b as l,o as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{p as f}from"./player-overlays-ZG1nYuYj.js";import{t as p}from"./ProviderIcon-BS00rCO4.js";import{H as m,I as h,o as g,t as _}from"./index-D5OTguVm.js";import{t as v}from"./AdminPage-CN6ZMhf0.js";import{t as y}from"./useEventInvalidation-wNGhDdi_.js";c();function b(){let{t:c}=_(),b=m(),x=f(),S=u();y([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]),y([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`]);let{data:C}=n({}),{data:w}=t(void 0),T=i({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),E=a({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),D=r({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),O=s(()=>C??[],[C]),{activeDevices:k,orphanDevices:A}=s(()=>{let e=new Set((w??[]).map(e=>e.addonId)),t=t=>typeof t.addonId==`string`&&t.addonId.length>0&&!e.has(t.addonId),n=new Set;for(let e of O)t(e)&&n.add(e.id);let r=new Set(n),i=new Map;for(let e of O)i.set(e.id,e);let a=(e,t=0)=>{if(t>32)return!1;if(n.has(e.id))return!0;if(e.parentDeviceId==null)return!1;let r=i.get(e.parentDeviceId);return r?a(r,t+1):!1};for(let e of O)a(e)&&r.add(e.id);let o=[],s=[];for(let e of O)r.has(e.id)?s.push(e):o.push(e);return{activeDevices:o,orphanDevices:s}},[O,w]),j=s(()=>{let e=new Map;for(let t of O)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[O]),M=o(e=>j.get(e)??null,[j]),N=s(()=>(w??[]).map(e=>({id:e.addonId,name:e.name??e.addonId,icon:l(p,{type:e.addonId,size:`sm`})})),[w]),P=o(e=>l(p,{type:e,size:`sm`}),[]),F=o(e=>b(`/devices/${String(e)}`),[b]);return d(v,{icon:h,title:c(`nav.devices`,`Devices`),children:[l(e,{context:`devices`,devices:k,trpc:x.trpcClient,filters:{addons:N},resolveIntegrationIcon:P,resolveParent:M,onNavigate:F,batchActions:{remove:T.mutate,disable:E.mutate,enable:D.mutate}}),A.length>0&&d(`div`,{className:`mt-6 space-y-2`,children:[d(`div`,{className:`flex items-baseline gap-2`,children:[l(g,{className:`h-3.5 w-3.5 text-warning shrink-0`}),l(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Orphan devices`}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:[A.length,` device`,A.length===1?``:`s`,` pointing at integrations no longer registered`]})]}),d(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 p-2`,children:[l(`p`,{className:`text-[11px] text-foreground-subtle px-2 pb-2`,children:"These devices reference an addonId that has no matching integration. Delete them, or re-install the missing integration to bring them back online. The provider scope (`addonId`) shown beside each row is what's failing to resolve."}),l(e,{context:`devices`,devices:A,trpc:x.trpcClient,filters:{addons:N},urlScope:`nested`,lsKey:`devices:orphan`,resolveIntegrationIcon:P,resolveParent:M,onNavigate:F})]})]})]})}export{b as DevicesPage};
@@ -1 +1 @@
1
- import{Bi as e,P as t,b as n,i as r}from"./src-Dxc7AUYA.js";import{G as i,R as a,U as o,X as s,b as c,d as l,u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{d as f}from"./player-overlays-zGqQhGgE.js";import{C as p,D as m,S as h,g,k as _,w as v}from"./schemas-CuE8EXQ7.js";import{S as y}from"./src-DqOo0bwK.js";s();var b=_([v({kind:h(`adaptive`)}),v({kind:h(`profile`),profile:y})]),x=v({serverUrl:m().min(1),token:m().min(1),deviceId:p().int().nonnegative(),target:b,muted:g()});function S(e,t){let n=t===void 0?{type:`state`,state:e}:{type:`state`,state:e,message:t};window.ReactNativeWebView?.postMessage(JSON.stringify(n))}function C(e){switch(e){case`playing`:return`playing`;case`error`:return`error`;case`connecting`:case`disconnected`:case`idle`:return`connecting`}}function w(e){return e.kind===`adaptive`?{kind:`adaptive`}:{kind:`profile`,profile:e.profile}}function T(e){return e.kind===`adaptive`?`embed:adaptive`:`embed:profile:${e.profile}`}function E(){let e=window.__CAMSTACK_EMBED__;if(e==null)return{ok:!1,error:`window.__CAMSTACK_EMBED__ is not set`};let t=x.safeParse(e);return t.success?{ok:!0,config:t.data}:{ok:!1,error:t.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).join(`; `)}}function D({message:e}){return a(()=>{S(`error`,e)},[e]),d(`div`,{style:{position:`fixed`,inset:0,display:`flex`,alignItems:`center`,justifyContent:`center`,background:`#000`,color:`#f87171`,fontFamily:`system-ui, sans-serif`,fontSize:13,padding:16,textAlign:`center`},children:[`Embed config error: `,e]})}function O({system:e,deviceId:t,initialTarget:s,initialMuted:l}){let[u,d]=i(s),[f,p]=i(l),{handleOffer:m,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,getSessionState:y}=r(e.trpcClient,t),x=o(()=>w(u),[u]),E=o(()=>(e,t)=>m(x,e,t),[m,x]),D=o(()=>(e,t,n)=>m(n,t,e),[m]);a(()=>(window.__camstackEmbed={setMuted:e=>p(e),setTarget:e=>{let t=b.safeParse(e);t.success&&d(t.data)}},()=>{window.__camstackEmbed&&delete window.__camstackEmbed}),[]);let O=T(u);return c(`div`,{style:{position:`fixed`,inset:0,width:`100vw`,height:`100vh`,background:`#000`},children:c(n,{serverUrl:e.serverUrl,streamKey:O,autoPlay:!0,muted:f,showControls:!1,className:`w-full h-full`,handleOffer:E,reoffer:D,getSessionState:y,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,onStateChange:e=>S(C(e)),onError:e=>S(`error`,e)},O)})}function k(){let n=o(()=>E(),[]),r=o(()=>n.ok?{system:t({serverUrl:n.config.serverUrl,token:n.config.token}),queryClient:new l({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1}}})}:null,[n]);return a(()=>{if(r)return()=>{r.system.close()}},[r]),n.ok?r?c(f,{system:r.system,children:c(u,{client:r.queryClient,children:c(e.Provider,{client:r.system.trpcClient,queryClient:r.queryClient,children:c(O,{system:r.system,deviceId:n.config.deviceId,initialTarget:n.config.target,initialMuted:n.config.muted})})})}):c(D,{message:`Failed to initialise the embed player`}):c(D,{message:n.error})}export{k as EmbedPlayerPage};
1
+ import{Hi as e,P as t,b as n,i as r}from"./src-BB1LG2-C.js";import{G as i,R as a,U as o,X as s,b as c,d as l,u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{d as f}from"./player-overlays-ZG1nYuYj.js";import{C as p,D as m,S as h,g,k as _,w as v}from"./schemas-CuE8EXQ7.js";import{S as y}from"./src-Cno9Ci3x.js";s();var b=_([v({kind:h(`adaptive`)}),v({kind:h(`profile`),profile:y})]),x=v({serverUrl:m().min(1),token:m().min(1),deviceId:p().int().nonnegative(),target:b,muted:g()});function S(e,t){let n=t===void 0?{type:`state`,state:e}:{type:`state`,state:e,message:t};window.ReactNativeWebView?.postMessage(JSON.stringify(n))}function C(e){switch(e){case`playing`:return`playing`;case`error`:return`error`;case`connecting`:case`disconnected`:case`idle`:return`connecting`}}function w(e){return e.kind===`adaptive`?{kind:`adaptive`}:{kind:`profile`,profile:e.profile}}function T(e){return e.kind===`adaptive`?`embed:adaptive`:`embed:profile:${e.profile}`}function E(){let e=window.__CAMSTACK_EMBED__;if(e==null)return{ok:!1,error:`window.__CAMSTACK_EMBED__ is not set`};let t=x.safeParse(e);return t.success?{ok:!0,config:t.data}:{ok:!1,error:t.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).join(`; `)}}function D({message:e}){return a(()=>{S(`error`,e)},[e]),d(`div`,{style:{position:`fixed`,inset:0,display:`flex`,alignItems:`center`,justifyContent:`center`,background:`#000`,color:`#f87171`,fontFamily:`system-ui, sans-serif`,fontSize:13,padding:16,textAlign:`center`},children:[`Embed config error: `,e]})}function O({system:e,deviceId:t,initialTarget:s,initialMuted:l}){let[u,d]=i(s),[f,p]=i(l),{handleOffer:m,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,getSessionState:y}=r(e.trpcClient,t),x=o(()=>w(u),[u]),E=o(()=>(e,t)=>m(x,e,t),[m,x]),D=o(()=>(e,t,n)=>m(n,t,e),[m]);a(()=>(window.__camstackEmbed={setMuted:e=>p(e),setTarget:e=>{let t=b.safeParse(e);t.success&&d(t.data)}},()=>{window.__camstackEmbed&&delete window.__camstackEmbed}),[]);let O=T(u);return c(`div`,{style:{position:`fixed`,inset:0,width:`100vw`,height:`100vh`,background:`#000`},children:c(n,{serverUrl:e.serverUrl,streamKey:O,autoPlay:!0,muted:f,showControls:!1,className:`w-full h-full`,handleOffer:E,reoffer:D,getSessionState:y,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,onStateChange:e=>S(C(e)),onError:e=>S(`error`,e)},O)})}function k(){let n=o(()=>E(),[]),r=o(()=>n.ok?{system:t({serverUrl:n.config.serverUrl,token:n.config.token}),queryClient:new l({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1}}})}:null,[n]);return a(()=>{if(r)return()=>{r.system.close()}},[r]),n.ok?r?c(f,{system:r.system,children:c(u,{client:r.queryClient,children:c(e.Provider,{client:r.system.trpcClient,queryClient:r.queryClient,children:c(O,{system:r.system,deviceId:n.config.deviceId,initialTarget:n.config.target,initialMuted:n.config.muted})})})}):c(D,{message:`Failed to initialise the embed player`}):c(D,{message:n.error})}export{k as EmbedPlayerPage};
@@ -1 +1 @@
1
- import{C as e,S as t}from"./src-Dxc7AUYA.js";import{G as n,X as r,b as i,x as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";r();function o(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function s(e,t){if(e!==void 0)return t&&o(e)?t(e):e}function c({section:r,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,probeResults:f,onAction:p}){let[m,h]=n(r.defaultCollapsed??!1),g=r.style===`accordion`;if(r.fields.reduce((t,n)=>t+ +!!e(n,o,r.fields),0)===0)return null;let _=r.columns??2,v=_===1?`grid-cols-1`:_===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:_===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`,y=r.fields.length===1&&r.fields[0]?.type===`widget`?r.fields[0]:void 0;return a(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},children:[!(y!==void 0||!r.title&&!r.description)&&a(`div`,{className:[`flex items-center justify-between mb-2`,g?`cursor-pointer`:``].join(` `),onClick:g?()=>h(e=>!e):void 0,children:[a(`div`,{children:[r.title&&i(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:s(r.title,u)}),r.description&&i(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:s(r.description,u)})]}),g&&i(`span`,{className:`text-foreground-subtle text-xs ml-2`,children:m?`▸`:`▾`})]}),!m&&(y===void 0?i(`div`,{className:`grid ${v} gap-x-3 gap-y-2.5`,children:r.fields.map(e=>i(t,{field:e,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,externalProbe:f?.[e.key],allFields:r.fields,onAction:p},e.key))}):i(t,{field:y,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,externalProbe:f?.[y.key],allFields:r.fields,onAction:p},y.key))]})}function l({schema:e,values:t,onChange:n,disabled:r,translationFn:a,onTestField:o,probeResults:s,onClearProbe:l,onAction:u}){let d=(e,r)=>{n({...t,[e]:r}),l?.(e)};return i(`div`,{className:`space-y-4`,children:e.sections.map((e,n)=>i(c,{section:e,values:t,onChange:d,disabled:r,translationFn:a,onTestField:o,probeResults:s,onAction:u},`${e.id}-${n}`))})}export{l as t};
1
+ import{C as e,S as t}from"./src-BB1LG2-C.js";import{G as n,X as r,b as i,x as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";r();function o(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function s(e,t){if(e!==void 0)return t&&o(e)?t(e):e}function c({section:r,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,probeResults:f,onAction:p}){let[m,h]=n(r.defaultCollapsed??!1),g=r.style===`accordion`;if(r.fields.reduce((t,n)=>t+ +!!e(n,o,r.fields),0)===0)return null;let _=r.columns??2,v=_===1?`grid-cols-1`:_===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:_===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`,y=r.fields.length===1&&r.fields[0]?.type===`widget`?r.fields[0]:void 0;return a(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},children:[!(y!==void 0||!r.title&&!r.description)&&a(`div`,{className:[`flex items-center justify-between mb-2`,g?`cursor-pointer`:``].join(` `),onClick:g?()=>h(e=>!e):void 0,children:[a(`div`,{children:[r.title&&i(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:s(r.title,u)}),r.description&&i(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:s(r.description,u)})]}),g&&i(`span`,{className:`text-foreground-subtle text-xs ml-2`,children:m?`▸`:`▾`})]}),!m&&(y===void 0?i(`div`,{className:`grid ${v} gap-x-3 gap-y-2.5`,children:r.fields.map(e=>i(t,{field:e,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,externalProbe:f?.[e.key],allFields:r.fields,onAction:p},e.key))}):i(t,{field:y,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,externalProbe:f?.[y.key],allFields:r.fields,onAction:p},y.key))]})}function l({schema:e,values:t,onChange:n,disabled:r,translationFn:a,onTestField:o,probeResults:s,onClearProbe:l,onAction:u}){let d=(e,r)=>{n({...t,[e]:r}),l?.(e)};return i(`div`,{className:`space-y-4`,children:e.sections.map((e,n)=>i(c,{section:e,values:t,onChange:d,disabled:r,translationFn:a,onTestField:o,probeResults:s,onAction:u},`${e.id}-${n}`))})}export{l as t};
@@ -0,0 +1 @@
1
+ import{Ci as e,Di as t,Ei as n,Ji as r,Oi as i,Pi as a,Si as o,Ti as s,_i as c,at as l,bi as u,c as d,gi as f,hi as p,it as m,mi as h,pa as g,s as _,vi as v,wi as y,xi as b,yi as x}from"./src-BB1LG2-C.js";import{G as S,U as C,X as w,b as T,o as E,x as D,y as O}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{t as k}from"./circle-check-big-Ca1L631f.js";import{t as A}from"./copy-Bi-BgxBp.js";import{t as j}from"./key-round-DdK6mTCz.js";import{t as M}from"./AddonCollectionPage-BHk_82L1.js";import{t as ee}from"./plus-D2fCWFPc.js";import{B as N,C as P,F,d as I,i as L,l as R,r as z,s as B,w as V,x as H}from"./index-D5OTguVm.js";import{t as U}from"./AdminPage-CN6ZMhf0.js";import{t as W}from"./AdminTabs-C5BWg3Pz.js";var G=N(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),K=N(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]),te=N(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),q=N(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]),J=N(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]);w();function ne({userId:e,username:t,onClose:n}){let r=E(),i=a(),o=v({userId:e}),s=o.data,l=()=>r.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),u=c({onSuccess:()=>{l(),n()}}),d=o.isLoading?`loading`:s?.enabled?`enrolled`:`not_enrolled`;return T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:D(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[D(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[D(`div`,{className:`flex items-center gap-2`,children:[T(R,{className:`h-4 w-4 text-primary`}),D(`div`,{children:[T(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),D(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,T(`span`,{className:`font-mono`,children:t})]})]})]}),T(`button`,{onClick:n,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:T(L,{className:`h-4 w-4`})})]}),D(`div`,{className:`p-4 space-y-4`,children:[d===`loading`&&D(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[T(H,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),d===`not_enrolled`&&D(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[T(P,{className:`h-4 w-4 mt-0.5 shrink-0`}),D(`div`,{children:[T(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),T(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),d===`enrolled`&&s&&D(O,{children:[D(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[T(k,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),D(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[T(`div`,{className:`font-medium`,children:`2FA is active`}),D(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,s.confirmedAt?new Date(s.confirmedAt).toLocaleString():`—`]})]})]}),T(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),D(`div`,{className:`flex justify-end gap-2`,children:[T(g,{onClick:n,variant:`secondary`,children:`Close`}),D(`button`,{onClick:async()=>{await i({title:`Remove 2FA`,message:`Remove two-factor authentication for "${t}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&u.mutate({userId:e})},disabled:u.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[u.isPending?T(H,{className:`h-3 w-3 animate-spin`}):T(L,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function Y(){let n=E(),{user:s}=z(),[c,l]=S(!1),[u,d]=S(``),[m,h]=S(``),[g,_]=S(!1),[v,y]=S(null),{data:b,isLoading:x,isError:C}=o(),w=a(),O=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),k=p({onSuccess:()=>{O(),l(!1),d(``),h(``),_(!1),y(null)},onError:e=>{y(e instanceof Error?e.message:`Failed to create user`)}}),A=f({onSuccess:O}),j=i({onSuccess:O}),M=e({onSuccess:O}),N=t({onSuccess:()=>{O(),F(null)}}),[P,F]=S(null),[V,W]=S(null),G=b??[];async function K(e){await w({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&A.mutate({id:e.id})}async function q(e){let t=window.prompt(`New password for "${e.username}":`);if(t){if(t.length<8){window.alert(`Password must be at least 8 characters.`);return}await w({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&M.mutate({id:e.id,newPassword:t})}}function J(e,t){t!==e.isAdmin&&j.mutate({id:e.id,isAdmin:t})}function Y(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return D(U,{children:[T(`div`,{className:`flex items-center justify-end`,children:D(`button`,{onClick:()=>l(!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 shadow-sm hover:bg-primary/90`,children:[T(ee,{className:`h-3.5 w-3.5`}),`Create User`]})}),c&&D(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[D(`div`,{className:`flex items-center justify-between`,children:[T(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),T(`button`,{onClick:()=>l(!1),className:`text-foreground-subtle hover:text-foreground`,children:T(L,{className:`h-4 w-4`})})]}),D(`div`,{className:`grid grid-cols-3 gap-3`,children:[D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),T(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:`john`,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`})]}),D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),T(`input`,{type:`password`,value:m,onChange:e=>h(e.target.value),placeholder:`••••••••`,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`})]}),D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),D(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[T(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`rounded border-border focus:ring-primary`}),T(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),v&&T(`p`,{className:`text-[10px] text-danger`,children:v}),D(`div`,{className:`flex justify-end gap-2`,children:[T(`button`,{onClick:()=>l(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),T(`button`,{onClick:()=>k.mutate({username:u,password:m,isAdmin:g}),disabled:k.isPending||!u||!m,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:k.isPending?`Creating...`:`Create`})]})]}),x&&T(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),C&&T(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!x&&!C&&G.length===0&&T(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>A.isPending&&A.variables?.id===e.id||j.isPending&&j.variables?.id===e.id||M.isPending&&M.variables?.id===e.id;return T(r,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:t=>D(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[T(`input`,{type:`checkbox`,checked:t.isAdmin,onChange:e=>J(t,e.target.checked),disabled:e(t),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),T(`span`,{className:t.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:t.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Scopes`,render:e=>{if(e.isAdmin)return T(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`unscoped`});let t=e.scopes??[];return D(`button`,{onClick:()=>F(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground`,title:`Edit scope grants`,children:[T(I,{className:`h-3 w-3`}),t.length===0?`no access`:`${t.length} grant${t.length===1?``:`s`}`]})}},{key:`createdAt`,header:`Created`,render:e=>T(`span`,{className:`text-foreground-subtle`,children:Y(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:t=>{let n=e(t);return D(`div`,{className:`flex items-center justify-end gap-1`,children:[t.id!==s?.id&&t.totpEnabled&&D(`button`,{onClick:()=>W(t),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[T(R,{className:`h-3 w-3`}),`Remove 2FA`]}),D(`button`,{onClick:()=>q(t),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[T(te,{className:`h-3 w-3`}),`Reset password`]}),D(`button`,{onClick:()=>K(t),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete user`,children:[n?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:G,rowKey:e=>e.id,minWidthPx:560})})(),V&&T(ne,{userId:V.id,username:V.username,onClose:()=>W(null)}),P&&T(re,{user:P,onClose:()=>F(null),onSubmit:e=>N.mutate({userId:P.id,scopes:e}),submitting:N.isPending})]})}function re(e){let{user:t}=z(),n=t?.isAdmin===!0;return T(ie,{...e,callerScopes:n?null:t?.scopes??[]})}function ie({user:e,onClose:t,onSubmit:n,submitting:r,callerScopes:i}){let[a,o]=S(C(()=>(e.scopes??[]).map(e=>({...e,access:[...e.access]})),[e.scopes])),s=d(a);return T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,children:D(`div`,{className:`w-full max-w-2xl rounded-lg border border-border bg-surface shadow-xl`,children:[D(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-3`,children:[D(`div`,{children:[D(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Edit scopes — `,e.username]}),T(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`Admin users bypass the scope check; this list is ignored.`:`Pick which capabilities this user can call, and which access flavours within each.`})]}),T(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:T(L,{className:`h-4 w-4`})})]}),D(`div`,{className:`px-4 py-4`,children:[T(_,{value:a,onChange:o,clampToParent:i,emptyHint:D(O,{children:[`No scopes granted.`,` `,T(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until a scope is added.`]})}),s&&T(`p`,{className:`mt-2 text-[10px] text-danger`,children:s})]}),D(`div`,{className:`flex items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[T(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),T(`button`,{onClick:()=>n(a),disabled:r||s!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:r?T(H,{className:`h-3 w-3 animate-spin`}):`Save scopes`})]})]})})}w();var ae=`bg-primary/10 text-primary`,oe=`bg-foreground-subtle/10 text-foreground-subtle`;function X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function se(e){return e?e===`*`?`*`:e.join(`, `):``}function ce(){let e=E(),t=a(),{data:r,isLoading:i}=x(),{data:s}=o(),c=C(()=>r??[],[r]),l=C(()=>s??[],[s]),u=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),d=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[f,p]=S(!1),[m,g]=S(null),_=y({onSuccess:u}),v=h({onSuccess:({token:e,record:t})=>{d(),p(!1),g({token:e,label:t.name})}}),b=n({onSuccess:d}),w=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&_.mutate({id:e})},O=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&b.mutate({id:e})};return D(U,{children:[D(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[T(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius.`}),D(`button`,{onClick:()=>p(!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 disabled:opacity-50`,disabled:l.length===0,title:l.length===0?`Create a user first`:`Issue a scoped token`,children:[T(I,{className:`h-3.5 w-3.5`}),`New token`]})]}),D(Z,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[l.length===0&&T(ue,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),l.map(e=>T(fe,{userId:e.id,username:e.username,onRevoke:(e,t)=>{O(e,t)},revokePending:b.isPending,revokeId:b.variables?.id},e.id))]}),c.length>0&&T(Z,{title:`Legacy API keys`,subtitle:`${c.length} pre-existing — revoke only`,children:T(de,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:c.map(e=>{let t=!!e.isAdmin,n=_.isPending&&_.variables?.id===e.id;return D(`tr`,{className:`hover:bg-primary/5`,children:[T(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:T(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${t?ae:oe}`,children:t?`admin`:`regular`})}),D(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:se(e.allowedProviders)||`all`}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),T(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:D(`button`,{onClick:()=>{w(e.id,e.label)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),i&&T(le,{}),f&&T(pe,{users:l.map(e=>({id:e.id,username:e.username})),onClose:()=>p(!1),onSubmit:e=>v.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:v.isPending}),m&&T(me,{token:m.token,label:m.label,onClose:()=>g(null)})]})}function Z({title:e,subtitle:t,children:n}){return D(`div`,{className:`space-y-2`,children:[D(`div`,{className:`flex items-baseline justify-between`,children:[T(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&T(`span`,{className:`text-[10px] text-foreground-subtle`,children:t})]}),n]})}function le(){return T(`div`,{className:`space-y-2`,children:[1,2].map(e=>T(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function ue({text:e}){return T(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function de({headers:e,rows:t}){return T(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:D(`table`,{className:`w-full text-xs min-w-[640px]`,children:[T(`thead`,{children:T(`tr`,{children:e.map((t,n)=>T(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),T(`tbody`,{children:t})]})})}function fe({userId:e,username:t,onRevoke:n,revokePending:r,revokeId:i}){let{data:a,isLoading:o}=b({userId:e}),s=a??[];return o||s.length===0?null:D(`div`,{className:`space-y-1.5`,children:[T(`div`,{className:`text-[11px] font-medium text-foreground`,children:t}),T(de,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:s.map(e=>{let t=r&&i===e.id;return D(`tr`,{className:`hover:bg-primary/5`,children:[T(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),D(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:T(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>D(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:[e.type,`:`,e.type===`device`?`[${e.targets.join(`,`)}]`:e.target]},t))})}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.expiresAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),T(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:D(`button`,{onClick:()=>n(e.id,e.name),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[t?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function pe({users:e,onClose:t,onSubmit:n,submitting:r}){let{user:i}=z(),a=i?.isAdmin===!0?null:i?.scopes??[],[o,s]=S(e[0]?.id??``),[c,l]=S(``),[u,f]=S([{type:`capability`,target:``,access:[`view`,`create`]}]),[p,m]=S(``),h=d(u),g=o!==``&&c.trim().length>0&&u.length>0&&h===null&&!r;return D(he,{title:`Create scoped token`,onClose:t,children:[D(`div`,{className:`space-y-3`,children:[T(Q,{label:`On behalf of user`,children:T(`select`,{value:o,onChange:e=>s(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>T(`option`,{value:e.id,children:e.username},e.id))})}),T(Q,{label:`Name`,children:T(`input`,{value:c,onChange:e=>l(e.target.value),placeholder:`cloudflare-tunnel-route`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})}),D(Q,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[T(_,{value:u,onChange:f,clampToParent:a}),h&&T(`p`,{className:`mt-1 text-[10px] text-danger`,children:h})]}),T(Q,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:T(`input`,{type:`number`,min:1,value:p,onChange:e=>m(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),D(ge,{children:[T(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),D(`button`,{onClick:()=>{let e=parseInt(p,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;n({userId:o,name:c.trim(),scopes:u,expiresAt:t})},disabled:!g,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:[r?T(H,{className:`h-3.5 w-3.5 animate-spin`}):T(I,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function me({token:e,label:t,onClose:n}){let[r,i]=S(!1),a=async()=>{try{await navigator.clipboard.writeText(e),i(!0)}catch{}};return D(he,{title:`Token: ${t}`,onClose:n,children:[D(`div`,{className:`space-y-3`,children:[T(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),T(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),D(ge,{children:[D(`button`,{onClick:()=>{a()},className:`inline-flex items-center gap-1.5 rounded 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:[r?T(F,{className:`h-3.5 w-3.5 text-primary`}):T(A,{className:`h-3.5 w-3.5`}),r?`Copied`:`Copy`]}),T(`button`,{onClick:n,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function he({title:e,onClose:t,children:n}){return T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:D(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[D(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[T(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),T(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:T(L,{className:`h-4 w-4`})})]}),T(`div`,{className:`p-4`,children:n})]})})}function ge({children:e}){return T(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Q({label:e,hint:t,children:n}){return D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),n,t&&T(`p`,{className:`text-[10px] text-foreground-subtle`,children:t})]})}w();function $(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function _e(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function ve(){return T(`div`,{className:`space-y-2`,children:[1,2].map(e=>T(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function ye({text:e}){return T(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function be({headers:e,rows:t}){return T(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:D(`table`,{className:`w-full text-xs min-w-[640px]`,children:[T(`thead`,{children:T(`tr`,{children:e.map((t,n)=>T(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),T(`tbody`,{children:t})]})})}function xe(){let e=E(),t=a(),{data:n,isLoading:r}=u(),i=C(()=>n??[],[n]),o=s({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),c=async(e,n)=>{await t({title:`Revoke "${n}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&o.mutate({id:e})};return D(U,{icon:q,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[r&&T(ve,{}),!r&&i.length===0&&T(ye,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!r&&i.length>0&&T(be,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:i.map(e=>{let t=e.revokedAt!==null,n=(o.isPending?o.variables?.id:void 0)===e.id;return D(`tr`,{className:`hover:bg-primary/5`,children:[T(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:T(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>T(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:_e(e)},t))})}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.createdAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.lastUsedAt)}),T(`td`,{className:`px-3 py-2 border-b border-border`,children:t?D(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,$(e.revokedAt)]}):T(`span`,{className:`inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300`,children:`Active`})}),T(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!t&&D(`button`,{onClick:()=>{c(e.id,e.integrationId)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}w();var Se=3e4;function Ce(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function we(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:K,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA can be enrolled per-user from the Users page (added in v0.4).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:V,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`First-time sign-ins are auto-provisioned with the configured Default Role.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.",`Paste issuer + credentials in the Settings panel below — saves on every change.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:V,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:R,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:R,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:I,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Te(){let e=l({capName:`auth-provider`},{refetchInterval:Se}),t=m(void 0,{refetchInterval:Se}),n=C(()=>Ce(t.data??[]),[t.data]);return T(M,{title:`Authentication`,subtitle:`Identity providers exposed to the admin UI. Multiple providers can run in parallel — operators pick which to enable. Disabling a provider only removes that external login method; local password login is unaffected. Each provider’s settings + live logs are inline below.`,pageIcon:I,itemIcon:I,capability:`auth-provider`,installButtonLabel:`Add provider`,items:C(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,renderExpandedPanel:e=>T(Ee,{addonId:e.addonId})})}function Ee({addonId:e}){let t=we(e),n=t.icon;return D(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[D(`div`,{className:`flex items-start gap-2.5`,children:[T(n,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),T(`div`,{className:`text-xs text-foreground font-medium`,children:t.headline})]}),T(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:t.bullets.map((e,t)=>T(`li`,{children:e},t))}),t.setupSteps&&t.setupSteps.length>0&&D(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[D(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[T(G,{className:`h-3 w-3`}),`Setup steps`]}),T(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:t.setupSteps.map((e,t)=>T(`li`,{children:e},t))})]}),e===`local-auth`&&D(`div`,{className:`rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[T(P,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),D(`span`,{children:[`TOTP / 2FA settings are exposed per-user from the`,` `,T(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page (added in v0.4). Enable for each user via the Actions column → “Enable TOTP”.`]})]})]})}function De(){return T(`div`,{className:`flex flex-col p-4`,children:T(W,{tabs:[{id:`users`,label:`Users`,icon:J,content:T(Y,{})},{id:`api-keys`,label:`Tokens`,icon:j,content:T(ce,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:q,content:T(xe,{})},{id:`authentication`,label:`Authentication`,icon:I,content:T(Te,{})}]})})}export{De as IdentityPage};