@camstack/addon-admin-ui 1.1.26 → 1.1.28

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 (86) hide show
  1. package/dist/assets/{AddLocationWizard-BLLOWMqU.js → AddLocationWizard-BqqTpair.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-DkFc3EyC.js → AddonCollectionPage-CHJrQbxS.js} +1 -1
  3. package/dist/assets/Addons-PDcFB41o.js +1 -0
  4. package/dist/assets/{AdminTabs-CdgYb0ow.js → AdminTabs-Dcn_NnRS.js} +1 -1
  5. package/dist/assets/{BrokerForm-DUfRi9ps.js → BrokerForm-DhpuU5tk.js} +1 -1
  6. package/dist/assets/{Capabilities-DFnvlplf.js → Capabilities-DNFfJgC4.js} +1 -1
  7. package/dist/assets/{CapabilityBadges-9yltt4Fp.js → CapabilityBadges-BPp4spWK.js} +1 -1
  8. package/dist/assets/Cluster-BaaYsixN.js +1 -0
  9. package/dist/assets/{Dashboard-BnShjVgK.js → Dashboard-CM2iQw9a.js} +1 -1
  10. package/dist/assets/{Data-CoQK3ysi.js → Data-Cm_DTQc3.js} +1 -1
  11. package/dist/assets/{DetectionIntelligence-DsnrlJl7.js → DetectionIntelligence-BUvN-5c-.js} +1 -1
  12. package/dist/assets/DeviceDetail-PPL3d07c.js +2 -0
  13. package/dist/assets/{Devices-CS42SuEX.js → Devices-BFQvObda.js} +1 -1
  14. package/dist/assets/{EmbedPlayerPage-CanuO_TA.js → EmbedPlayerPage-D7ziDRCE.js} +1 -1
  15. package/dist/assets/{FormBuilder-BYpwuMQM.js → FormBuilder-BtCunYUK.js} +1 -1
  16. package/dist/assets/Identity-DShDOLzy.js +1 -0
  17. package/dist/assets/IntegrationDetail-Dn2Q55u8.js +1 -0
  18. package/dist/assets/{Integrations-DoZeK5Ie.js → Integrations-DLAx15Dx.js} +1 -1
  19. package/dist/assets/{Integrations-UyRVYFuF.js → Integrations-DMQWpYfB.js} +1 -1
  20. package/dist/assets/{Logs-t2ZIKJm-.js → Logs-BZ22Tof8.js} +1 -1
  21. package/dist/assets/{MotionZonesSettings-Cr5A0bd3.js → MotionZonesSettings-Cb04qdzk.js} +1 -1
  22. package/dist/assets/{MyAccess-BkfQKq0X.js → MyAccess-BSGRdNLj.js} +1 -1
  23. package/dist/assets/Network-p8KkZ0a2.js +1 -0
  24. package/dist/assets/{NodeAddonsSettingsPanel-2bieWYkX.js → NodeAddonsSettingsPanel-u4V1iTbJ.js} +1 -1
  25. package/dist/assets/{NotificationTargets-vsJ_Dnl4.js → NotificationTargets-CCNlJEh8.js} +1 -1
  26. package/dist/assets/Pipeline-BlhdDHB0.js +1 -0
  27. package/dist/assets/{PrivacyMaskSettings-DYFTw_Gn.js → PrivacyMaskSettings-uImjMvtB.js} +1 -1
  28. package/dist/assets/{ProviderIcon-BHDS5Z0G.js → ProviderIcon-X1LLmqTA.js} +1 -1
  29. package/dist/assets/{ScanNetworkModal-BMkqK2zC.js → ScanNetworkModal-DNl-uXYZ.js} +1 -1
  30. package/dist/assets/{SchemaTabBar-Lx0lVN3x.js → SchemaTabBar-DhsmEGyn.js} +1 -1
  31. package/dist/assets/{Settings-BBFPupkN.js → Settings-CkWgIblv.js} +1 -1
  32. package/dist/assets/{Showroom-CkG5E4ny.js → Showroom-BjxzO7Xe.js} +1 -1
  33. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DTfChhSB.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BW32eA4e.js} +1 -1
  34. package/dist/assets/build-cluster-graph-BBzichfL.js +7 -0
  35. package/dist/assets/circle-check-big-Blvkp2hJ.js +1 -0
  36. package/dist/assets/{copy-BmhRdhEP.js → copy-BzVBaBlO.js} +1 -1
  37. package/dist/assets/{dist-DBwmv4oI.js → dist-B6nrtI9D.js} +1 -1
  38. package/dist/assets/dist-ipJu8FwS.js +7 -0
  39. package/dist/assets/{download-BBBdRPko.js → download-Bg3fxTwd.js} +1 -1
  40. package/dist/assets/{hostInit-BGdKqsfs.js → hostInit-AVzON_Ql.js} +1 -1
  41. package/dist/assets/index-7ucUNPxm.css +2 -0
  42. package/dist/assets/index-cObQUDCu.js +4 -0
  43. package/dist/assets/{key-round-C6sHSGAY.js → key-round-BeNuMjW0.js} +1 -1
  44. package/dist/assets/{mf-entry-bootstrap-0-0a971570.js → mf-entry-bootstrap-0-75a8d503.js} +2 -2
  45. package/dist/assets/{pencil-CTMhFkjD.js → pencil-BxhnkUV_.js} +1 -1
  46. package/dist/assets/{player-overlays-CpxC1ZVd.js → player-overlays-Bhh-T-qH.js} +1 -1
  47. package/dist/assets/plus-BR0mGk3r.js +1 -0
  48. package/dist/assets/{radio-DhJBlJcG.js → radio-CP28eXrH.js} +1 -1
  49. package/dist/assets/{refresh-cw-4PFnjcCn.js → refresh-cw-hKUYl1HT.js} +1 -1
  50. package/dist/assets/remoteEntry-CaZXIGdX.js +1 -0
  51. package/dist/assets/{rotate-ccw-V8i9NHCh.js → rotate-ccw-B1y8E4DF.js} +1 -1
  52. package/dist/assets/rotate-cw-ChSqQNtp.js +1 -0
  53. package/dist/assets/search-qPHxMz5I.js +1 -0
  54. package/dist/assets/{server-DIdemqSW.js → server-BD-hEzuI.js} +1 -1
  55. package/dist/assets/{sparkles-CyW8l4Z-.js → sparkles-C8w2oZIa.js} +1 -1
  56. package/dist/assets/square-D5fMq7WQ.js +1 -0
  57. package/dist/assets/{square-check-big-DknZIVfm.js → square-check-big-BquN3GaR.js} +1 -1
  58. package/dist/assets/{src-ypI5eXyJ.js → src-BvxPxXyx.js} +10 -10
  59. package/dist/assets/src-Ce30zKhx.js +7 -0
  60. package/dist/assets/{upload-ChN3wzau.js → upload-ChX0t6dA.js} +1 -1
  61. package/dist/assets/{useDevice-CAFOrYD_.js → useDevice-BRRdLKBn.js} +1 -1
  62. package/dist/assets/{useEventInvalidation-CJ7VfCpl.js → useEventInvalidation-OVOcl54D.js} +1 -1
  63. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-D--9iyFd.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BKo-bthY.js} +2 -2
  64. package/dist/assets/{wifi-C1TF0nps.js → wifi-Cl7ptz-k.js} +1 -1
  65. package/dist/assets/{zap-B3Ch0kb4.js → zap-Bis62gF5.js} +1 -1
  66. package/dist/index.html +6 -6
  67. package/dist/server/addon.js +39 -2
  68. package/package.json +1 -1
  69. package/dist/assets/Addons-DDSoi3Du.js +0 -1
  70. package/dist/assets/Cluster-aXNH3Hn_.js +0 -1
  71. package/dist/assets/DeviceDetail-BE0DmclC.js +0 -2
  72. package/dist/assets/Identity-BjbacBt4.js +0 -1
  73. package/dist/assets/IntegrationDetail-DT8sJvMf.js +0 -1
  74. package/dist/assets/Network-DB7Bb_49.js +0 -1
  75. package/dist/assets/Pipeline-D3Zh7_DC.js +0 -1
  76. package/dist/assets/circle-check-big-CFZgrxz8.js +0 -1
  77. package/dist/assets/dist-BBSYPQfM.js +0 -7
  78. package/dist/assets/index-CB8rHudv.js +0 -4
  79. package/dist/assets/index-DgnLfnMW.css +0 -2
  80. package/dist/assets/plus-B6B4NTpl.js +0 -1
  81. package/dist/assets/remoteEntry-DWYulF9l.js +0 -1
  82. package/dist/assets/rotate-cw-Ds_lhjJG.js +0 -1
  83. package/dist/assets/search-lmDzeAc6.js +0 -1
  84. package/dist/assets/square-BzGlGJec.js +0 -1
  85. package/dist/assets/src-BB7sQJiE.js +0 -7
  86. package/dist/assets/use-persisted-flow-layout-CuTJbVd3.js +0 -7
@@ -1 +1 @@
1
- import{Bt as e,Ci as t,Di as n,Gt as r,Ht as i,Lt as a,Rt as o,Ti as s,Ut as c,Vt as l,Wt as u,Xi as d,na as f,wi as p,xt as m,zt as h}from"./src-ypI5eXyJ.js";import{I as g,Q as _,S as v,W as y,b,o as x,q as S,x as C,z as w}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{L as T}from"./src-BB7sQJiE.js";import{t as E}from"./download-BBBdRPko.js";import{i as D,n as O,r as k,t as A}from"./AddLocationWizard-BLLOWMqU.js";import{t as j}from"./plus-B6B4NTpl.js";import{t as M}from"./rotate-cw-Ds_lhjJG.js";import{M as N,P,V as F,i as I,s as L,x as R,z as ee}from"./index-CB8rHudv.js";import{t as z}from"./AdminPage-BwmGKnRf.js";import{t as B}from"./format-size-CO9d3C3-.js";import{t as V}from"./AdminTabs-CdgYb0ow.js";var H=F(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),te=F(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),ne=F(`calendar-clock`,[[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M17.5 17.5 16 16.3V14`,key:`akvzfd`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]);_();function U(){let e=x(),r=d(),{data:i,isLoading:a,isError:o}=s({}),c=p(),l=y(()=>c.data??[],[c.data]),[u,f]=S(null),[m,h]=S(null),g=t({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),_=n({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),b=e=>{e.isDefault||_.mutate({id:e.id,type:e.type,providerId:e.providerId,displayName:e.displayName,config:e.config,isDefault:!0})},w=async e=>{if(e.isDefault){await r({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 r({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 i??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[i]),E=a||c.isLoading,D=o||c.isError;return v(z,{children:[E&&C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),D&&C(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!E&&!D&&v(`div`,{className:`space-y-3`,children:[l.length===0&&C(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:`No storage locations declared by any installed addon.`}),l.map(e=>C(k,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:T.get(e.id)??[],onAdd:e=>f(e),onEdit:e=>h(e),onDelete:e=>{w(e)},onSetDefault:e=>b(e)},e.id))]}),u!==null&&C(A,{initialType:u,onClose:()=>f(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),f(null)}}),m!==null&&C(O,{location:m,onClose:()=>h(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),h(null)}})]})}_();var W=[[`backup`,`listDestinations`]],G=[`backup`,`listArchives`];function K({destinationId:e,restoreSupported:t,onOpenRestoreWizard:n}){let r=x(),i=d(),{data:o,isLoading:s,isError:c}=h({destinationId:e}),l=o??[],u=a({onSuccess:()=>{r.invalidateQueries({queryKey:[[...G]]}),r.invalidateQueries({queryKey:W})}}),f=g(async t=>{await i({title:`Delete this archive?`,message:`Permanently deletes "${t.label??t.id}" and frees ${B(t.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&u.mutate({destinationId:e,backupId:t.id})},[i,e,u]),[p,m]=S(null),_=g(async t=>{m(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{m(null)}},[e]),b=y(()=>[...l].toSorted((e,t)=>t.createdAt-e.createdAt),[l]);return s?C(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):c?C(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):b.length===0?C(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):C(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:v(`table`,{className:`w-full text-xs min-w-[640px]`,children:[C(`thead`,{children:v(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[C(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),C(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),C(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),C(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),C(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),C(`tbody`,{children:b.map(r=>v(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[C(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:J(r.createdAt)}),C(`td`,{className:`px-3 py-1.5 text-foreground`,children:r.label??C(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),C(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:r.locations.join(`, `)}),C(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:B(r.sizeBytes)}),C(`td`,{className:`px-3 py-1.5`,children:v(`div`,{className:`flex items-center justify-end gap-1`,children:[v(`button`,{onClick:()=>{_(r)},disabled:p===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:[p===r.id?C(R,{className:`h-3 w-3 animate-spin`}):C(E,{className:`h-3 w-3`}),`Download`]}),t&&n&&v(`button`,{onClick:()=>n({destinationId:e,archiveId:r.id}),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-primary hover:bg-primary/10`,title:`Restore from this archive`,children:[C(M,{className:`h-3 w-3`}),`Restore`]}),C(`button`,{onClick:()=>{f(r)},disabled:u.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete archive`,children:u.isPending?C(R,{className:`h-3 w-3 animate-spin`}):C(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`})}_();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 a=X(e),[o,s]=S(a===`custom`);w(()=>{a!==`custom`&&s(!1)},[a]);let c=ae(e,250),l=i({cron:c,count:n},{enabled:c.trim().length>0}),u=l.data??null,d=e=>{s(!1),t(e.cron)},f=o||a===`custom`;return v(`div`,{className:`space-y-3`,children:[v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),v(`div`,{className:`flex flex-wrap gap-1.5`,children:[Y.map(e=>C(`button`,{type:`button`,onClick:()=>d(e),disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!o&&a===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.description??e.label,children:e.label},e.id)),C(`button`,{type:`button`,onClick:()=>{s(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(f?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),f&&v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),C(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:r,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),v(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,C(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),C(re,{cron:c,preview:u,loading:l.isFetching})]})}function re({cron:e,preview:t,loading:n}){return n&&t===null?v(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[C(R,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?C(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:`No future runs match this expression.`}):v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),C(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>v(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[C(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),C(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:ie(e)})]},`${e}-${t}`))})]}):C(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??`Invalid cron expression`})}function 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]=S(e),i=y(()=>e,[e]);return w(()=>{let e=setTimeout(()=>r(i),t);return()=>clearTimeout(e)},[i,t]),n}_();var oe=[[`backup`,`listDestinations`]];function se({onCreateAt:t,onOpenRestoreWizard:n}){let{data:r,isLoading:i,isError:a}=e(),o=r??[],[s,c]=S(null),l=e=>{c(t=>t===e?null:e)},u=fe();return i?C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading destinations…`}):a?C(`div`,{className:`text-xs text-danger`,children:`Failed to load destinations`}):o.length===0?C(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:C(`p`,{className:`text-xs text-foreground-subtle`,children:"No `backups`-typed storage locations registered. Add one in Settings → Storage to begin."})}):C(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:v(`table`,{className:`w-full text-xs min-w-[720px]`,children:[C(`thead`,{children:v(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[C(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),C(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Destination`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-28`,children:`Retention`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-56`,children:`Schedule`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-44`,children:`Last success`}),C(`th`,{className:`text-right px-3 py-2 font-medium w-44`,children:`Actions`})]})}),C(`tbody`,{children:o.map(e=>{let r=u.get(e.id);return C(ce,{row:e,isOpen:s===e.id,onToggle:()=>l(e.id),onCreateAt:t,liveLastSuccessAt:r?.at,liveLastSuccessSizeBytes:r?.sizeBytes,...n?{onOpenRestoreWizard:n}:{}},e.id)})})]})})}function ce({row:e,isOpen:t,onToggle:n,onCreateAt:i,onOpenRestoreWizard:a,liveLastSuccessAt:o,liveLastSuccessSizeBytes:s}){let c=x(),l=r({onSuccess:()=>{c.invalidateQueries({queryKey:oe})}}),[u,d]=S(String(e.retentionCount));w(()=>{d(String(e.retentionCount))},[e.retentionCount]);let[f,p]=S(!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]),_=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 v(b,{children:[v(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[C(`td`,{className:`px-2 py-2`,children:C(`button`,{onClick:n,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:t?`Hide archives`:`Show archives`,children:C(t?P:N,{className:`h-3.5 w-3.5`})})}),C(`td`,{className:`px-3 py-2`,children:v(`button`,{onClick:n,className:`text-left hover:underline focus:outline-none`,title:`View archives`,children:[C(`div`,{className:`text-foreground font-medium`,children:e.displayName}),v(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[C(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5`,children:e.kind}),C(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]})}),C(`td`,{className:`px-3 py-2`,children:C(`label`,{className:`inline-flex items-center cursor-pointer`,children:C(`input`,{type:`checkbox`,className:`accent-primary`,checked:e.enabled,disabled:l.isPending,onChange:e=>m(e.target.checked)})})}),C(`td`,{className:`px-3 py-2`,children:C(`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`})}),C(`td`,{className:`px-3 py-2`,children:C(le,{cron:e.cron,nextRunAt:e.nextRunAt,onEdit:()=>p(!0),disabled:l.isPending})}),C(`td`,{className:`px-3 py-2 text-foreground-subtle`,children:(()=>{let t=pe(o,e.lastSuccessAt),n=t===o?s:e.lastSuccessSizeBytes;return t===void 0?C(`span`,{className:`italic`,children:`Never`}):C(me,{at:t,sizeBytes:n})})()}),C(`td`,{className:`px-3 py-2`,children:C(`div`,{className:`flex items-center justify-end gap-1.5`,children:e.triggerSupported&&v(`button`,{onClick:()=>i(e),className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90`,children:[C(j,{className:`h-3 w-3`}),`Create here`]})})})]}),t&&C(`tr`,{className:`border-t border-border bg-background/30`,children:C(`td`,{colSpan:7,className:`px-4 py-3`,children:C(K,{destinationId:e.id,restoreSupported:e.restoreSupported,...a?{onOpenRestoreWizard:a}:{}})})}),f&&C(de,{destinationName:e.displayName,currentCron:e.cron??``,onSave:_,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 v(`button`,{type:`button`,onClick:n,disabled:r,className:`group flex flex-col items-start gap-0.5 text-left rounded px-1.5 py-1 -mx-1.5 hover:bg-primary/5 disabled:opacity-50`,title:`Edit schedule`,children:[v(`div`,{className:`flex items-center gap-1.5`,children:[C(ne,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),C(`span`,{className:i?`font-mono text-foreground`:`italic text-foreground-subtle`,children:i?e:`Manual`})]}),i&&t!==void 0&&v(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[`next `,ue(t)]})]})}function ue(e){let t=e-Date.now();if(t<=0)return`imminent`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function de({destinationName:e,currentCron:t,onSave:n,onClose:r,saving:i,saveError:a}){let[o,s]=S(t);return C(`tr`,{children:C(`td`,{colSpan:7,className:`p-0`,children:C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:v(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Schedule`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e]})]}),C(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,title:`Close`,children:C(I,{className:`h-4 w-4`})})]}),v(`div`,{className:`p-4`,children:[C(Z,{value:o,onChange:s,disabled:i}),a!==null&&C(`div`,{className:`mt-3 rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:a})]}),v(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[C(`button`,{onClick:r,disabled:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground disabled:opacity-50`,children:`Cancel`}),C(`button`,{onClick:()=>n(o.trim()),disabled:i||o.trim()===t.trim(),className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:i?`Saving…`:`Save`})]})]})})})})}function fe(){let{map:e}=f(T.BackupCompleted,e=>e.destinationId);return y(()=>{let t=new Map;for(let[n,r]of e)t.set(n,{at:Date.now(),sizeBytes:r.sizeMB*1024*1024});return t},[e])}function pe(e,t){return e===void 0?t:t===void 0||e>t?e:t}function me({at:e,sizeBytes:t}){let n=he(e);return v(`span`,{title:y(()=>new Date(e).toLocaleString(),[e]),className:`text-foreground tabular-nums`,children:[n,t!==void 0&&v(`span`,{className:`ml-1 text-foreground-subtle`,children:[`· `,B(t)]})]})}function he(e){let[,t]=S(0);return w(()=>{let e=setInterval(()=>t(e=>e+1),3e4);return()=>clearInterval(e)},[]),ge(e)}function ge(e){let t=Math.max(0,Date.now()-e),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=Math.floor(a/30);return o<12?`${o}mo ago`:`${Math.floor(a/365)}y ago`}_();var _e=[[`backup`,`list`]];function ve({initialDestinationId:t,initialArchiveId:n,onClose:r,onScheduled:i}){let a=x(),[s,l]=S(t&&n?2:1),[u,d]=S(t),[f,p]=S(n),[m,g]=S(new Set),{data:_}=e(),b=_??[],{data:T,isLoading:E}=h({destinationId:u??``},{enabled:!!u}),D=T??[];w(()=>{if(u!==void 0)return;let e=b.filter(e=>e.restoreSupported);e.length===1&&d(e[0].id)},[u,b]);let{data:O}=o({destinationId:u??``,backupId:f??``},{enabled:!!u&&!!f}),k=y(()=>O?.locations??[],[O]);w(()=>{k.length!==0&&g(e=>e.size===0?new Set(k):e)},[k]);let A=c({onSuccess:()=>{a.invalidateQueries({queryKey:_e}),i(),r()}}),j=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},N=!!u&&!!f,P=m.size>0,F=N&&P&&!A.isPending,L=()=>{!u||!f||A.mutate({destinationId:u,backupId:f,locations:[...m]})};return C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:v(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,s,` of 3 —`,` `,s===1?`pick source`:s===2?`pick locations`:`confirm`]})]}),C(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,children:C(I,{className:`h-4 w-4`})})]}),s===1&&C(ye,{destinations:b,destinationId:u,onPickDestination:e=>{d(e),p(void 0),g(new Set)},archives:D,archivesLoading:E,archiveId:f,onPickArchive:p}),s===2&&C(be,{locations:k,picked:m,onToggle:j}),s===3&&C(xe,{destinationName:b.find(e=>e.id===u)?.displayName??u??``,archive:D.find(e=>e.id===f),picked:[...m]}),v(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[C(`div`,{children:s>1&&v(`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:[C(ee,{className:`h-3 w-3`}),`Back`]})}),v(`div`,{className:`flex items-center gap-2`,children:[C(`button`,{onClick:r,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),s<3?v(`button`,{disabled:s===1&&!N||s===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`,C(te,{className:`h-3 w-3`})]}):v(`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?C(R,{className:`h-3.5 w-3.5 animate-spin`}):C(M,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function ye({destinations:e,destinationId:t,onPickDestination:n,archives:r,archivesLoading:i,archiveId:a,onPickArchive:o}){let s=e.filter(e=>e.restoreSupported);return v(`div`,{className:`p-4 space-y-3`,children:[v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),v(`select`,{value:t??``,onChange:e=>n(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:[C(`option`,{value:``,disabled:!0,children:`Select destination…`}),s.map(e=>v(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&C(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&i&&C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!i&&r.length===0&&C(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&r.length>0&&C(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:r.map(e=>{let t=a===e.id;return v(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>o(e.id),className:`accent-primary`}),v(`div`,{children:[C(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),C(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),C(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:B(e.sizeBytes)})]},e.id)})})]})]})}function be({locations:e,picked:t,onToggle:n}){return e.length===0?C(`div`,{className:`p-4`,children:C(`div`,{className:`text-xs text-foreground-subtle`,children:`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`})}):v(`div`,{className:`p-4 space-y-3`,children:[C(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),C(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>v(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[C(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>n(e),className:`accent-primary`}),C(`span`,{className:`font-mono text-foreground`,children:e}),C(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ce(e)})]},e))})]})]})}function xe({destinationName:e,archive:t,picked:n}){return v(`div`,{className:`p-4 space-y-3 text-xs`,children:[C(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-300`,children:`Restore is applied at next server boot. Active connections will drop when you restart.`}),v(`dl`,{className:`space-y-1.5`,children:[C(Q,{term:`Destination`,value:e}),C(Q,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&C(Q,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${B(t.sizeBytes)}`}),C(Q,{term:`Locations`,value:n.length>0?n.join(`, `):`— (full archive)`})]})]})}function Q({term:e,value:t}){return v(`div`,{className:`flex justify-between gap-3`,children:[C(`dt`,{className:`text-foreground-subtle`,children:e}),C(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Se={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function Ce(e){return Se[e]??``}_();var $=[[`backup`,`list`]],we=[[`backup`,`listLocations`]];function Te(){let e=x(),t=d(),{data:n}=l(),r=u({onSuccess:()=>{e.invalidateQueries({queryKey:$}),e.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),e.invalidateQueries({queryKey:[[`backup`,`listArchives`]]})}}),i=m(),[a,o]=S(null),[s,c]=S(null),[f,p]=S(!1),[h,g]=S(!1),[_,y]=S(!1),b=async()=>{await t({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&i.mutate({confirm:!0})};return v(z,{children:[v(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[v(`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:[C(M,{className:`h-3.5 w-3.5`}),`Restore…`]}),v(`button`,{onClick:()=>y(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[C(j,{className:`h-3.5 w-3.5`}),`Add destination`]})]}),h&&C(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2.5 text-xs text-amber-700 dark:text-amber-300`,children:v(`div`,{className:`flex items-center justify-between gap-3`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(M,{className:`h-3.5 w-3.5`}),C(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),v(`button`,{onClick:()=>{b()},disabled:i.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:[i.isPending?C(R,{className:`h-3.5 w-3.5 animate-spin`}):C(M,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),C(se,{onCreateAt:e=>o(e),onOpenRestoreWizard:e=>c(e)}),a&&C(Ee,{destination:a,locations:n??[],onClose:()=>o(null),onSubmit:(t,n)=>{r.mutate({destinations:[a.id],locations:t,label:n||void 0},{onSuccess:()=>{o(null),e.invalidateQueries({queryKey:we})}})},submitting:r.isPending}),(s||f)&&C(ve,{...s?{initialDestinationId:s.destinationId,initialArchiveId:s.archiveId}:{},onClose:()=>{c(null),p(!1)},onScheduled:()=>g(!0)}),_&&C(A,{initialType:`backups`,onClose:()=>y(!1),onCreated:()=>{y(!1),e.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]=S(``),[c,l]=S(()=>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 C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:v(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Create Backup`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e.displayName]})]}),C(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:C(I,{className:`h-4 w-4`})})]}),v(`div`,{className:`p-4 space-y-3`,children:[v(`div`,{className:`space-y-1`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Label (optional)`}),C(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`pre-upgrade`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Include`}),v(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:[a.length===0&&C(`div`,{className:`px-3 py-2 text-xs text-foreground-subtle italic`,children:`Nothing to back up.`}),a.map(e=>v(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(`input`,{type:`checkbox`,checked:c.has(e.name),onChange:()=>u(e.name),className:`accent-primary`}),C(`span`,{className:`font-mono text-foreground`,children:e.name})]}),v(`div`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[B(e.sizeBytes),` · `,e.fileCount,` files`]})]},e.name))]})]})]}),v(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[C(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),v(`button`,{onClick:()=>r(Array.from(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?C(R,{className:`h-3.5 w-3.5 animate-spin`}):C(H,{className:`h-3.5 w-3.5`}),i?`Creating…`:`Create`]})]})]})})}function De(){return C(`div`,{className:`flex flex-col p-4`,children:C(V,{tabs:[{id:`storage`,label:`Storage`,icon:D,content:C(U,{})},{id:`backup`,label:`Backup`,icon:H,content:C(Te,{})}]})})}export{De as DataPage};
1
+ import{Bt as e,Di as t,Ei as n,Gt as r,Ht as i,Lt as a,Qi as o,Rt as s,Ti as c,Ut as l,Vt as u,Wt as d,ia as f,ki as p,xt as m,zt as h}from"./src-BvxPxXyx.js";import{I as g,Q as _,S as v,W as y,b,o as x,q as S,x as C,z as w}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{L as T}from"./src-Ce30zKhx.js";import{t as E}from"./download-Bg3fxTwd.js";import{i as D,n as O,r as k,t as A}from"./AddLocationWizard-BqqTpair.js";import{t as j}from"./plus-BR0mGk3r.js";import{t as M}from"./rotate-cw-ChSqQNtp.js";import{M as N,P,V as F,i as I,s as L,x as R,z as ee}from"./index-cObQUDCu.js";import{t as z}from"./AdminPage-BwmGKnRf.js";import{t as B}from"./format-size-CO9d3C3-.js";import{t as V}from"./AdminTabs-Dcn_NnRS.js";var H=F(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),te=F(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),ne=F(`calendar-clock`,[[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M17.5 17.5 16 16.3V14`,key:`akvzfd`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]);_();function U(){let e=x(),r=o(),{data:i,isLoading:a,isError:s}=t({}),l=n(),u=y(()=>l.data??[],[l.data]),[d,f]=S(null),[m,h]=S(null),g=c({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),_=p({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),b=e=>{e.isDefault||_.mutate({id:e.id,type:e.type,providerId:e.providerId,displayName:e.displayName,config:e.config,isDefault:!0})},w=async e=>{if(e.isDefault){await r({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 r({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 i??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[i]),E=a||l.isLoading,D=s||l.isError;return v(z,{children:[E&&C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),D&&C(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!E&&!D&&v(`div`,{className:`space-y-3`,children:[u.length===0&&C(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:`No storage locations declared by any installed addon.`}),u.map(e=>C(k,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:T.get(e.id)??[],onAdd:e=>f(e),onEdit:e=>h(e),onDelete:e=>{w(e)},onSetDefault:e=>b(e)},e.id))]}),d!==null&&C(A,{initialType:d,onClose:()=>f(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),f(null)}}),m!==null&&C(O,{location:m,onClose:()=>h(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),h(null)}})]})}_();var W=[[`backup`,`listDestinations`]],G=[`backup`,`listArchives`];function K({destinationId:e,restoreSupported:t,onOpenRestoreWizard:n}){let r=x(),i=o(),{data:s,isLoading:c,isError:l}=h({destinationId:e}),u=s??[],d=a({onSuccess:()=>{r.invalidateQueries({queryKey:[[...G]]}),r.invalidateQueries({queryKey:W})}}),f=g(async t=>{await i({title:`Delete this archive?`,message:`Permanently deletes "${t.label??t.id}" and frees ${B(t.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&d.mutate({destinationId:e,backupId:t.id})},[i,e,d]),[p,m]=S(null),_=g(async t=>{m(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{m(null)}},[e]),b=y(()=>[...u].toSorted((e,t)=>t.createdAt-e.createdAt),[u]);return c?C(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):l?C(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):b.length===0?C(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):C(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:v(`table`,{className:`w-full text-xs min-w-[640px]`,children:[C(`thead`,{children:v(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[C(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),C(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),C(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),C(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),C(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),C(`tbody`,{children:b.map(r=>v(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[C(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:J(r.createdAt)}),C(`td`,{className:`px-3 py-1.5 text-foreground`,children:r.label??C(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),C(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:r.locations.join(`, `)}),C(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:B(r.sizeBytes)}),C(`td`,{className:`px-3 py-1.5`,children:v(`div`,{className:`flex items-center justify-end gap-1`,children:[v(`button`,{onClick:()=>{_(r)},disabled:p===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:[p===r.id?C(R,{className:`h-3 w-3 animate-spin`}):C(E,{className:`h-3 w-3`}),`Download`]}),t&&n&&v(`button`,{onClick:()=>n({destinationId:e,archiveId:r.id}),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-primary hover:bg-primary/10`,title:`Restore from this archive`,children:[C(M,{className:`h-3 w-3`}),`Restore`]}),C(`button`,{onClick:()=>{f(r)},disabled:d.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:d.isPending?C(R,{className:`h-3 w-3 animate-spin`}):C(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`})}_();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 a=X(e),[o,s]=S(a===`custom`);w(()=>{a!==`custom`&&s(!1)},[a]);let c=ae(e,250),l=i({cron:c,count:n},{enabled:c.trim().length>0}),u=l.data??null,d=e=>{s(!1),t(e.cron)},f=o||a===`custom`;return v(`div`,{className:`space-y-3`,children:[v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),v(`div`,{className:`flex flex-wrap gap-1.5`,children:[Y.map(e=>C(`button`,{type:`button`,onClick:()=>d(e),disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!o&&a===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.description??e.label,children:e.label},e.id)),C(`button`,{type:`button`,onClick:()=>{s(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(f?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),f&&v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),C(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:r,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),v(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,C(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),C(re,{cron:c,preview:u,loading:l.isFetching})]})}function re({cron:e,preview:t,loading:n}){return n&&t===null?v(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[C(R,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?C(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:`No future runs match this expression.`}):v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),C(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>v(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[C(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),C(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:ie(e)})]},`${e}-${t}`))})]}):C(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??`Invalid cron expression`})}function 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]=S(e),i=y(()=>e,[e]);return w(()=>{let e=setTimeout(()=>r(i),t);return()=>clearTimeout(e)},[i,t]),n}_();var oe=[[`backup`,`listDestinations`]];function se({onCreateAt:t,onOpenRestoreWizard:n}){let{data:r,isLoading:i,isError:a}=e(),o=r??[],[s,c]=S(null),l=e=>{c(t=>t===e?null:e)},u=fe();return i?C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading destinations…`}):a?C(`div`,{className:`text-xs text-danger`,children:`Failed to load destinations`}):o.length===0?C(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:C(`p`,{className:`text-xs text-foreground-subtle`,children:"No `backups`-typed storage locations registered. Add one in Settings → Storage to begin."})}):C(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:v(`table`,{className:`w-full text-xs min-w-[720px]`,children:[C(`thead`,{children:v(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[C(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),C(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Destination`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-28`,children:`Retention`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-56`,children:`Schedule`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-44`,children:`Last success`}),C(`th`,{className:`text-right px-3 py-2 font-medium w-44`,children:`Actions`})]})}),C(`tbody`,{children:o.map(e=>{let r=u.get(e.id);return C(ce,{row:e,isOpen:s===e.id,onToggle:()=>l(e.id),onCreateAt:t,liveLastSuccessAt:r?.at,liveLastSuccessSizeBytes:r?.sizeBytes,...n?{onOpenRestoreWizard:n}:{}},e.id)})})]})})}function ce({row:e,isOpen:t,onToggle:n,onCreateAt:i,onOpenRestoreWizard:a,liveLastSuccessAt:o,liveLastSuccessSizeBytes:s}){let c=x(),l=r({onSuccess:()=>{c.invalidateQueries({queryKey:oe})}}),[u,d]=S(String(e.retentionCount));w(()=>{d(String(e.retentionCount))},[e.retentionCount]);let[f,p]=S(!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]),_=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 v(b,{children:[v(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[C(`td`,{className:`px-2 py-2`,children:C(`button`,{onClick:n,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:t?`Hide archives`:`Show archives`,children:C(t?P:N,{className:`h-3.5 w-3.5`})})}),C(`td`,{className:`px-3 py-2`,children:v(`button`,{onClick:n,className:`text-left hover:underline focus:outline-none`,title:`View archives`,children:[C(`div`,{className:`text-foreground font-medium`,children:e.displayName}),v(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[C(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5`,children:e.kind}),C(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]})}),C(`td`,{className:`px-3 py-2`,children:C(`label`,{className:`inline-flex items-center cursor-pointer`,children:C(`input`,{type:`checkbox`,className:`accent-primary`,checked:e.enabled,disabled:l.isPending,onChange:e=>m(e.target.checked)})})}),C(`td`,{className:`px-3 py-2`,children:C(`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`})}),C(`td`,{className:`px-3 py-2`,children:C(le,{cron:e.cron,nextRunAt:e.nextRunAt,onEdit:()=>p(!0),disabled:l.isPending})}),C(`td`,{className:`px-3 py-2 text-foreground-subtle`,children:(()=>{let t=pe(o,e.lastSuccessAt),n=t===o?s:e.lastSuccessSizeBytes;return t===void 0?C(`span`,{className:`italic`,children:`Never`}):C(me,{at:t,sizeBytes:n})})()}),C(`td`,{className:`px-3 py-2`,children:C(`div`,{className:`flex items-center justify-end gap-1.5`,children:e.triggerSupported&&v(`button`,{onClick:()=>i(e),className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90`,children:[C(j,{className:`h-3 w-3`}),`Create here`]})})})]}),t&&C(`tr`,{className:`border-t border-border bg-background/30`,children:C(`td`,{colSpan:7,className:`px-4 py-3`,children:C(K,{destinationId:e.id,restoreSupported:e.restoreSupported,...a?{onOpenRestoreWizard:a}:{}})})}),f&&C(de,{destinationName:e.displayName,currentCron:e.cron??``,onSave:_,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 v(`button`,{type:`button`,onClick:n,disabled:r,className:`group flex flex-col items-start gap-0.5 text-left rounded px-1.5 py-1 -mx-1.5 hover:bg-primary/5 disabled:opacity-50`,title:`Edit schedule`,children:[v(`div`,{className:`flex items-center gap-1.5`,children:[C(ne,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),C(`span`,{className:i?`font-mono text-foreground`:`italic text-foreground-subtle`,children:i?e:`Manual`})]}),i&&t!==void 0&&v(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[`next `,ue(t)]})]})}function ue(e){let t=e-Date.now();if(t<=0)return`imminent`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function de({destinationName:e,currentCron:t,onSave:n,onClose:r,saving:i,saveError:a}){let[o,s]=S(t);return C(`tr`,{children:C(`td`,{colSpan:7,className:`p-0`,children:C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:v(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Schedule`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e]})]}),C(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,title:`Close`,children:C(I,{className:`h-4 w-4`})})]}),v(`div`,{className:`p-4`,children:[C(Z,{value:o,onChange:s,disabled:i}),a!==null&&C(`div`,{className:`mt-3 rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:a})]}),v(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[C(`button`,{onClick:r,disabled:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground disabled:opacity-50`,children:`Cancel`}),C(`button`,{onClick:()=>n(o.trim()),disabled:i||o.trim()===t.trim(),className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:i?`Saving…`:`Save`})]})]})})})})}function fe(){let{map:e}=f(T.BackupCompleted,e=>e.destinationId);return y(()=>{let t=new Map;for(let[n,r]of e)t.set(n,{at:Date.now(),sizeBytes:r.sizeMB*1024*1024});return t},[e])}function pe(e,t){return e===void 0?t:t===void 0||e>t?e:t}function me({at:e,sizeBytes:t}){let n=he(e);return v(`span`,{title:y(()=>new Date(e).toLocaleString(),[e]),className:`text-foreground tabular-nums`,children:[n,t!==void 0&&v(`span`,{className:`ml-1 text-foreground-subtle`,children:[`· `,B(t)]})]})}function he(e){let[,t]=S(0);return w(()=>{let e=setInterval(()=>t(e=>e+1),3e4);return()=>clearInterval(e)},[]),ge(e)}function ge(e){let t=Math.max(0,Date.now()-e),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=Math.floor(a/30);return o<12?`${o}mo ago`:`${Math.floor(a/365)}y ago`}_();var _e=[[`backup`,`list`]];function ve({initialDestinationId:t,initialArchiveId:n,onClose:r,onScheduled:i}){let a=x(),[o,c]=S(t&&n?2:1),[u,d]=S(t),[f,p]=S(n),[m,g]=S(new Set),{data:_}=e(),b=_??[],{data:T,isLoading:E}=h({destinationId:u??``},{enabled:!!u}),D=T??[];w(()=>{if(u!==void 0)return;let e=b.filter(e=>e.restoreSupported);e.length===1&&d(e[0].id)},[u,b]);let{data:O}=s({destinationId:u??``,backupId:f??``},{enabled:!!u&&!!f}),k=y(()=>O?.locations??[],[O]);w(()=>{k.length!==0&&g(e=>e.size===0?new Set(k):e)},[k]);let A=l({onSuccess:()=>{a.invalidateQueries({queryKey:_e}),i(),r()}}),j=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},N=!!u&&!!f,P=m.size>0,F=N&&P&&!A.isPending,L=()=>{!u||!f||A.mutate({destinationId:u,backupId:f,locations:[...m]})};return C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:v(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,o,` of 3 —`,` `,o===1?`pick source`:o===2?`pick locations`:`confirm`]})]}),C(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,children:C(I,{className:`h-4 w-4`})})]}),o===1&&C(ye,{destinations:b,destinationId:u,onPickDestination:e=>{d(e),p(void 0),g(new Set)},archives:D,archivesLoading:E,archiveId:f,onPickArchive:p}),o===2&&C(be,{locations:k,picked:m,onToggle:j}),o===3&&C(xe,{destinationName:b.find(e=>e.id===u)?.displayName??u??``,archive:D.find(e=>e.id===f),picked:[...m]}),v(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[C(`div`,{children:o>1&&v(`button`,{onClick:()=>c(e=>e===3?2:1),className:`inline-flex items-center gap-1 rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:[C(ee,{className:`h-3 w-3`}),`Back`]})}),v(`div`,{className:`flex items-center gap-2`,children:[C(`button`,{onClick:r,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),o<3?v(`button`,{disabled:o===1&&!N||o===2&&!P,onClick:()=>c(e=>e===1?2:3),className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[`Next`,C(te,{className:`h-3 w-3`})]}):v(`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?C(R,{className:`h-3.5 w-3.5 animate-spin`}):C(M,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function ye({destinations:e,destinationId:t,onPickDestination:n,archives:r,archivesLoading:i,archiveId:a,onPickArchive:o}){let s=e.filter(e=>e.restoreSupported);return v(`div`,{className:`p-4 space-y-3`,children:[v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),v(`select`,{value:t??``,onChange:e=>n(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:[C(`option`,{value:``,disabled:!0,children:`Select destination…`}),s.map(e=>v(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&C(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&i&&C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!i&&r.length===0&&C(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&r.length>0&&C(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:r.map(e=>{let t=a===e.id;return v(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>o(e.id),className:`accent-primary`}),v(`div`,{children:[C(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),C(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),C(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:B(e.sizeBytes)})]},e.id)})})]})]})}function be({locations:e,picked:t,onToggle:n}){return e.length===0?C(`div`,{className:`p-4`,children:C(`div`,{className:`text-xs text-foreground-subtle`,children:`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`})}):v(`div`,{className:`p-4 space-y-3`,children:[C(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),C(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>v(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[C(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>n(e),className:`accent-primary`}),C(`span`,{className:`font-mono text-foreground`,children:e}),C(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ce(e)})]},e))})]})]})}function xe({destinationName:e,archive:t,picked:n}){return v(`div`,{className:`p-4 space-y-3 text-xs`,children:[C(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-300`,children:`Restore is applied at next server boot. Active connections will drop when you restart.`}),v(`dl`,{className:`space-y-1.5`,children:[C(Q,{term:`Destination`,value:e}),C(Q,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&C(Q,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${B(t.sizeBytes)}`}),C(Q,{term:`Locations`,value:n.length>0?n.join(`, `):`— (full archive)`})]})]})}function Q({term:e,value:t}){return v(`div`,{className:`flex justify-between gap-3`,children:[C(`dt`,{className:`text-foreground-subtle`,children:e}),C(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Se={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function Ce(e){return Se[e]??``}_();var $=[[`backup`,`list`]],we=[[`backup`,`listLocations`]];function Te(){let e=x(),t=o(),{data:n}=u(),r=d({onSuccess:()=>{e.invalidateQueries({queryKey:$}),e.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),e.invalidateQueries({queryKey:[[`backup`,`listArchives`]]})}}),i=m(),[a,s]=S(null),[c,l]=S(null),[f,p]=S(!1),[h,g]=S(!1),[_,y]=S(!1),b=async()=>{await t({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&i.mutate({confirm:!0})};return v(z,{children:[v(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[v(`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:[C(M,{className:`h-3.5 w-3.5`}),`Restore…`]}),v(`button`,{onClick:()=>y(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[C(j,{className:`h-3.5 w-3.5`}),`Add destination`]})]}),h&&C(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2.5 text-xs text-amber-700 dark:text-amber-300`,children:v(`div`,{className:`flex items-center justify-between gap-3`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(M,{className:`h-3.5 w-3.5`}),C(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),v(`button`,{onClick:()=>{b()},disabled:i.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:[i.isPending?C(R,{className:`h-3.5 w-3.5 animate-spin`}):C(M,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),C(se,{onCreateAt:e=>s(e),onOpenRestoreWizard:e=>l(e)}),a&&C(Ee,{destination:a,locations:n??[],onClose:()=>s(null),onSubmit:(t,n)=>{r.mutate({destinations:[a.id],locations:t,label:n||void 0},{onSuccess:()=>{s(null),e.invalidateQueries({queryKey:we})}})},submitting:r.isPending}),(c||f)&&C(ve,{...c?{initialDestinationId:c.destinationId,initialArchiveId:c.archiveId}:{},onClose:()=>{l(null),p(!1)},onScheduled:()=>g(!0)}),_&&C(A,{initialType:`backups`,onClose:()=>y(!1),onCreated:()=>{y(!1),e.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]=S(``),[c,l]=S(()=>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 C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:v(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Create Backup`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e.displayName]})]}),C(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:C(I,{className:`h-4 w-4`})})]}),v(`div`,{className:`p-4 space-y-3`,children:[v(`div`,{className:`space-y-1`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Label (optional)`}),C(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`pre-upgrade`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Include`}),v(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:[a.length===0&&C(`div`,{className:`px-3 py-2 text-xs text-foreground-subtle italic`,children:`Nothing to back up.`}),a.map(e=>v(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(`input`,{type:`checkbox`,checked:c.has(e.name),onChange:()=>u(e.name),className:`accent-primary`}),C(`span`,{className:`font-mono text-foreground`,children:e.name})]}),v(`div`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[B(e.sizeBytes),` · `,e.fileCount,` files`]})]},e.name))]})]})]}),v(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[C(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),v(`button`,{onClick:()=>r(Array.from(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?C(R,{className:`h-3.5 w-3.5 animate-spin`}):C(H,{className:`h-3.5 w-3.5`}),i?`Creating…`:`Create`]})]})]})})}function De(){return C(`div`,{className:`flex flex-col p-4`,children:C(V,{tabs:[{id:`storage`,label:`Storage`,icon:D,content:C(U,{})},{id:`backup`,label:`Backup`,icon:H,content:C(Te,{})}]})})}export{De as DataPage};
@@ -1 +1 @@
1
- import{$n as e,Ca as t,Ea as n,Gn as r,Hn as i,Jn as a,Kn as o,Oa as s,Qn as c,Sa as l,Un as u,Wn as d,Xn as f,Yn as p,Zn as m,ba as h,ka as g,qn as _,wa as v,xa as y,ya as b}from"./src-ypI5eXyJ.js";import{Q as x,S,W as C,b as w,o as T,q as E,x as D}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as O}from"./pencil-CTMhFkjD.js";import{t as k}from"./plus-B6B4NTpl.js";import{t as A}from"./sparkles-CyW8l4Z-.js";import{t as j}from"./square-check-big-DknZIVfm.js";import{t as M}from"./square-BzGlGJec.js";import{F as N,M as P,P as F,V as I,i as L,m as R,s as z,x as B}from"./index-CB8rHudv.js";import{t as V}from"./AdminPage-BwmGKnRf.js";var H=I(`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=I(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]),W=I(`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`}]]);x();var G=[[`faceGallery`]];function K({identityId:e}){let t=T(),{data:n,isLoading:r}=_({identityId:e}),i=p();function a(n){i.mutate({identityId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:G})}})}return r?S(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[D(B,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!n||n.length===0?D(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):D(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:n.map(e=>S(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?D(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):D(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:D(U,{className:`h-6 w-6`})}),D(`button`,{type:`button`,onClick:()=>a(e),disabled:i.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove sample`,children:D(L,{className:`h-4 w-4 text-white`})})]},e.id))})}function q({identity:e,expanded:i,onToggle:a}){let o=T(),[c,u]=E(``),[d,p]=E(!1),[m,_]=E(!1),x=f(),C=r();function k(){u(e.name),p(!0)}function A(){p(!1),u(``)}function j(){let t=c.trim();if(!t||t===e.name){A();return}x.mutate({id:e.id,name:t},{onSettled:()=>{o.invalidateQueries({queryKey:G}),A()}})}function M(){C.mutate({id:e.id},{onSettled:()=>{o.invalidateQueries({queryKey:G}),_(!1)}})}return S(`div`,{className:`rounded-md border border-border bg-surface`,children:[S(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[D(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:e.coverBase64?D(`img`,{src:`data:image/jpeg;base64,${e.coverBase64}`,alt:e.name,className:`h-full w-full object-cover`}):D(`div`,{className:`flex h-full w-full items-center justify-center`,children:D(U,{className:`h-4 w-4 text-foreground-subtle`})})}),D(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:d?S(w,{children:[D(n,{value:c,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&j(),e.key===`Escape`&&A()},className:`h-6 text-xs`,autoFocus:!0}),D(`button`,{type:`button`,onClick:j,disabled:x.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:D(N,{className:`h-3.5 w-3.5`})}),D(`button`,{type:`button`,onClick:A,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:D(L,{className:`h-3.5 w-3.5`})})]}):D(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),D(s,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!d&&S(`div`,{className:`flex items-center gap-1`,children:[D(`button`,{type:`button`,onClick:k,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:D(O,{className:`h-3.5 w-3.5`})}),D(`button`,{type:`button`,onClick:()=>_(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:D(z,{className:`h-3.5 w-3.5`})})]}),D(`button`,{type:`button`,onClick:a,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":i?`Collapse`:`Expand`,children:D(i?F:P,{className:`h-3.5 w-3.5`})})]}),i&&D(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:D(K,{identityId:e.id})}),D(b,{open:m,onOpenChange:e=>!e&&_(!1),children:S(h,{children:[S(t,{children:[D(v,{children:`Delete person`}),S(y,{children:[`Delete `,D(`strong`,{children:e.name}),` and all their samples? This cannot be undone.`]})]}),S(l,{children:[D(g,{variant:`secondary`,onClick:()=>_(!1),children:`Cancel`}),S(g,{variant:`danger`,onClick:M,disabled:C.isPending,children:[C.isPending?D(B,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function J(){let e=T(),[t,r]=E(``),i=u();function a(){let n=t.trim();n&&i.mutate({name:n},{onSettled:()=>{e.invalidateQueries({queryKey:G}),r(``)}})}return S(`div`,{className:`flex items-center gap-2 pt-2`,children:[D(n,{placeholder:`New person name…`,value:t,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&a()},className:`h-7 text-xs flex-1`}),S(g,{variant:`primary`,size:`sm`,onClick:a,disabled:i.isPending||!t.trim(),children:[i.isPending?D(B,{className:`h-3.5 w-3.5 animate-spin`}):D(k,{className:`h-3.5 w-3.5`}),`Add`]})]})}function Y(){let{data:e,isLoading:t}=o(),[n,r]=E(null);function i(e){r(t=>t===e?null:e)}return t?S(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[D(B,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):S(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&D(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),e?.map(e=>D(q,{identity:e,expanded:n===e.id,onToggle:()=>i(e.id)},e.id)),D(J,{})]})}x();var X=[[`faceGallery`]];function Z({faceIds:e,identities:r,onDone:a}){let o=T(),s=i(),c=u(),[d,f]=E(``),[p,m]=E(!1),[_,x]=E(null),C=e!==null&&e.length>0,w=e?.length??0;function O(){m(!1),f(``),x(null)}function k(){O(),a()}function A(t){!e||e.length===0||s.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{o.invalidateQueries({queryKey:X}),k()}})}function j(){!e||!d.trim()||c.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&A(e.id)},onError:()=>{o.invalidateQueries({queryKey:X}),k()}})}let M=s.isPending||c.isPending;return D(b,{open:C,onOpenChange:e=>!e&&k(),children:S(h,{children:[S(t,{children:[D(v,{children:w>1?`Assign ${w} faces to person`:`Assign face to person`}),D(y,{children:`Select an existing person or create a new one.`})]}),D(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:r.map(e=>S(`button`,{type:`button`,onClick:()=>x(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${_===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[D(`span`,{className:`font-medium`,children:e.name}),S(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),p?D(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:D(n,{placeholder:`New person name…`,value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&j()},autoFocus:!0,className:`flex-1`})}):D(`button`,{type:`button`,onClick:()=>{x(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…`}),S(l,{children:[D(g,{variant:`secondary`,onClick:k,disabled:M,children:`Cancel`}),p?S(g,{variant:`primary`,onClick:j,disabled:M||!d.trim(),children:[M&&D(B,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):S(g,{variant:`primary`,onClick:()=>_&&A(_),disabled:M||!_,children:[M&&D(B,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,w>1?` ${w}`:``]})]})]})})}function Q({face:e,selected:t,onToggleSelect:n,onAssign:r}){let i=T(),a=c(),o=d(),s=()=>{i.invalidateQueries({queryKey:X})};return S(`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:[S(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[e.base64?D(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Face`,className:`h-full w-full object-cover`}):D(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:D(U,{className:`h-8 w-8`})}),D(`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?D(j,{className:`h-3.5 w-3.5 text-primary`}):D(M,{className:`h-3.5 w-3.5`})}),S(`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?D(`button`,{type:`button`,onClick:()=>a.mutate({faceId:e.faceId},{onSettled:s}),disabled:a.isPending,className:`rounded-full bg-warning/80 p-1.5 text-white hover:bg-warning disabled:opacity-50`,title:`Detach`,children:a.isPending?D(B,{className:`h-3.5 w-3.5 animate-spin`}):D(W,{className:`h-3.5 w-3.5`})}):D(`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:D(H,{className:`h-3.5 w-3.5`})}),D(`button`,{type:`button`,onClick:()=>o.mutate({faceId:e.faceId},{onSettled:s}),disabled:o.isPending,className:`rounded-full bg-danger/80 p-1.5 text-white hover:bg-danger disabled:opacity-50`,title:`Delete face`,children:o.isPending?D(B,{className:`h-3.5 w-3.5 animate-spin`}):D(z,{className:`h-3.5 w-3.5`})})]})]}),S(`div`,{className:`px-2 pb-2 space-y-0.5`,children:[D(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.deviceId}),e.identityName&&D(`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 t=T(),[n,r]=E(`all`),[s,c]=E(new Set),[l,u]=E(null),[f,p]=E(!1),{data:h,isLoading:_}=a({limit:100,filter:n}),{data:v=[]}=o(),{data:y,isFetching:b}=m({threshold:.5,minClusterSize:2,limit:20},{enabled:f}),x=i(),w=e(),O=d(),k=h??[],j=C(()=>new Map(k.map(e=>[e.faceId,e])),[k]),M=()=>{t.invalidateQueries({queryKey:X})},N=()=>c(new Set);function P(e){c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function F(e){c(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}let I=[...s],R=x.isPending||w.isPending||O.isPending;function V(){I.length!==0&&w.mutate({faceIds:I},{onSettled:()=>{M(),N()}})}function G(){I.length!==0&&Promise.allSettled(I.map(e=>O.mutateAsync({faceId:e}))).then(()=>{M(),N()})}return S(`div`,{className:`space-y-3`,children:[S(`div`,{className:`flex items-center gap-1`,children:[$.map(e=>D(`button`,{type:`button`,onClick:()=>r(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${n===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value)),S(`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:[D(A,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!_&&S(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[k.length,` face`,k.length===1?``:`s`]})]}),s.size>0&&S(`div`,{className:`flex items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[S(`span`,{className:`text-xs font-medium text-foreground`,children:[s.size,` selected`]}),S(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[S(g,{variant:`primary`,onClick:()=>u(I),disabled:R,children:[D(H,{className:`h-3.5 w-3.5`}),` Assign`]}),S(g,{variant:`secondary`,onClick:V,disabled:R,children:[w.isPending?D(B,{className:`h-3.5 w-3.5 animate-spin`}):D(W,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),S(g,{variant:`secondary`,onClick:G,disabled:R,children:[D(z,{className:`h-3.5 w-3.5`}),` Delete`]}),D(g,{variant:`ghost`,onClick:N,disabled:R,children:D(L,{className:`h-3.5 w-3.5`})})]})]}),f&&S(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:[D(`p`,{className:`mb-2 text-xs font-medium text-foreground`,children:`Look-alike groups`}),b?S(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[D(B,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):!y||y.length===0?D(`p`,{className:`text-xs text-foreground-subtle`,children:`No look-alike groups found among unassigned faces.`}):D(`div`,{className:`space-y-2`,children:y.map(e=>S(`div`,{className:`flex items-center gap-2 rounded-md bg-surface-hover/50 p-2`,children:[D(`div`,{className:`flex -space-x-1.5`,children:e.faceIds.slice(0,6).map(e=>{let t=j.get(e);return D(`div`,{className:`h-8 w-8 overflow-hidden rounded border border-border bg-surface`,children:t?.base64?D(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:``,className:`h-full w-full object-cover`}):D(U,{className:`h-full w-full p-1.5 text-foreground-subtle`})},e)})}),S(`span`,{className:`text-xs text-foreground-subtle`,children:[e.size,` faces · `,Math.round(e.cohesion*100),`% alike`]}),S(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[D(g,{variant:`secondary`,onClick:()=>F(e.faceIds),children:`Select group`}),S(g,{variant:`primary`,onClick:()=>u(e.faceIds),children:[D(H,{className:`h-3.5 w-3.5`}),` Assign all`]})]})]},e.representativeFaceId))})]}),_&&S(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[D(B,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!_&&k.length===0&&D(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No faces found for this filter.`}),!_&&k.length>0&&D(`div`,{className:`grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8 lg:grid-cols-10`,children:k.map(e=>D(Q,{face:e,selected:s.has(e.faceId),onToggleSelect:P,onAssign:e=>u([e])},e.faceId))}),D(Z,{faceIds:l,identities:v,onDone:()=>{u(null),N()}})]})}function te(){return D(V,{icon:R,title:`Detection Intelligence`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:S(`section`,{className:`space-y-3`,children:[S(`div`,{children:[D(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),D(`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.`}),D(Y,{})]}),S(`div`,{className:`pt-4 border-t border-border`,children:[D(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),D(`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.`}),D(ee,{})]})]})})}export{te as DetectionIntelligencePage};
1
+ import{$n as e,Aa as t,Ca as n,Ea as r,Gn as i,Hn as a,Jn as o,Kn as s,Oa as c,Qn as l,Sa as u,Ta as d,Un as f,Wn as p,Xn as m,Yn as h,Zn as g,ja as _,qn as v,wa as y,xa as b}from"./src-BvxPxXyx.js";import{Q as x,S,W as C,b as w,o as T,q as E,x as D}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as O}from"./pencil-BxhnkUV_.js";import{t as k}from"./plus-BR0mGk3r.js";import{t as A}from"./sparkles-C8w2oZIa.js";import{t as j}from"./square-check-big-BquN3GaR.js";import{t as M}from"./square-D5fMq7WQ.js";import{F as N,M as P,P as F,V as I,i as L,m as R,s as z,x as B}from"./index-cObQUDCu.js";import{t as V}from"./AdminPage-BwmGKnRf.js";var H=I(`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=I(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]),W=I(`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`}]]);x();var G=[[`faceGallery`]];function K({identityId:e}){let t=T(),{data:n,isLoading:r}=v({identityId:e}),i=h();function a(n){i.mutate({identityId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:G})}})}return r?S(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[D(B,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!n||n.length===0?D(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):D(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:n.map(e=>S(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?D(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):D(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:D(U,{className:`h-6 w-6`})}),D(`button`,{type:`button`,onClick:()=>a(e),disabled:i.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove sample`,children:D(L,{className:`h-4 w-4 text-white`})})]},e.id))})}function q({identity:e,expanded:a,onToggle:o}){let s=T(),[l,f]=E(``),[p,h]=E(!1),[g,v]=E(!1),x=m(),C=i();function k(){f(e.name),h(!0)}function A(){h(!1),f(``)}function j(){let t=l.trim();if(!t||t===e.name){A();return}x.mutate({id:e.id,name:t},{onSettled:()=>{s.invalidateQueries({queryKey:G}),A()}})}function M(){C.mutate({id:e.id},{onSettled:()=>{s.invalidateQueries({queryKey:G}),v(!1)}})}return S(`div`,{className:`rounded-md border border-border bg-surface`,children:[S(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[D(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:e.coverBase64?D(`img`,{src:`data:image/jpeg;base64,${e.coverBase64}`,alt:e.name,className:`h-full w-full object-cover`}):D(`div`,{className:`flex h-full w-full items-center justify-center`,children:D(U,{className:`h-4 w-4 text-foreground-subtle`})})}),D(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:p?S(w,{children:[D(c,{value:l,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&j(),e.key===`Escape`&&A()},className:`h-6 text-xs`,autoFocus:!0}),D(`button`,{type:`button`,onClick:j,disabled:x.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:D(N,{className:`h-3.5 w-3.5`})}),D(`button`,{type:`button`,onClick:A,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:D(L,{className:`h-3.5 w-3.5`})})]}):D(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),D(t,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!p&&S(`div`,{className:`flex items-center gap-1`,children:[D(`button`,{type:`button`,onClick:k,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:D(O,{className:`h-3.5 w-3.5`})}),D(`button`,{type:`button`,onClick:()=>v(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:D(z,{className:`h-3.5 w-3.5`})})]}),D(`button`,{type:`button`,onClick:o,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":a?`Collapse`:`Expand`,children:D(a?F:P,{className:`h-3.5 w-3.5`})})]}),a&&D(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:D(K,{identityId:e.id})}),D(b,{open:g,onOpenChange:e=>!e&&v(!1),children:S(u,{children:[S(d,{children:[D(r,{children:`Delete person`}),S(n,{children:[`Delete `,D(`strong`,{children:e.name}),` and all their samples? This cannot be undone.`]})]}),S(y,{children:[D(_,{variant:`secondary`,onClick:()=>v(!1),children:`Cancel`}),S(_,{variant:`danger`,onClick:M,disabled:C.isPending,children:[C.isPending?D(B,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function J(){let e=T(),[t,n]=E(``),r=f();function i(){let i=t.trim();i&&r.mutate({name:i},{onSettled:()=>{e.invalidateQueries({queryKey:G}),n(``)}})}return S(`div`,{className:`flex items-center gap-2 pt-2`,children:[D(c,{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`}),S(_,{variant:`primary`,size:`sm`,onClick:i,disabled:r.isPending||!t.trim(),children:[r.isPending?D(B,{className:`h-3.5 w-3.5 animate-spin`}):D(k,{className:`h-3.5 w-3.5`}),`Add`]})]})}function Y(){let{data:e,isLoading:t}=s(),[n,r]=E(null);function i(e){r(t=>t===e?null:e)}return t?S(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[D(B,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):S(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&D(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),e?.map(e=>D(q,{identity:e,expanded:n===e.id,onToggle:()=>i(e.id)},e.id)),D(J,{})]})}x();var X=[[`faceGallery`]];function Z({faceIds:e,identities:t,onDone:i}){let o=T(),s=a(),l=f(),[p,m]=E(``),[h,g]=E(!1),[v,x]=E(null),C=e!==null&&e.length>0,w=e?.length??0;function O(){g(!1),m(``),x(null)}function k(){O(),i()}function A(t){!e||e.length===0||s.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{o.invalidateQueries({queryKey:X}),k()}})}function j(){!e||!p.trim()||l.mutate({name:p.trim()},{onSuccess:e=>{e?.id&&A(e.id)},onError:()=>{o.invalidateQueries({queryKey:X}),k()}})}let M=s.isPending||l.isPending;return D(b,{open:C,onOpenChange:e=>!e&&k(),children:S(u,{children:[S(d,{children:[D(r,{children:w>1?`Assign ${w} faces to person`:`Assign face to person`}),D(n,{children:`Select an existing person or create a new one.`})]}),D(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>S(`button`,{type:`button`,onClick:()=>x(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${v===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[D(`span`,{className:`font-medium`,children:e.name}),S(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),h?D(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:D(c,{placeholder:`New person name…`,value:p,onChange:e=>m(e.target.value),onKeyDown:e=>{e.key===`Enter`&&j()},autoFocus:!0,className:`flex-1`})}):D(`button`,{type:`button`,onClick:()=>{x(null),g(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:`+ New person…`}),S(y,{children:[D(_,{variant:`secondary`,onClick:k,disabled:M,children:`Cancel`}),h?S(_,{variant:`primary`,onClick:j,disabled:M||!p.trim(),children:[M&&D(B,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):S(_,{variant:`primary`,onClick:()=>v&&A(v),disabled:M||!v,children:[M&&D(B,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,w>1?` ${w}`:``]})]})]})})}function Q({face:e,selected:t,onToggleSelect:n,onAssign:r}){let i=T(),a=l(),o=p(),s=()=>{i.invalidateQueries({queryKey:X})};return S(`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:[S(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[e.base64?D(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Face`,className:`h-full w-full object-cover`}):D(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:D(U,{className:`h-8 w-8`})}),D(`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?D(j,{className:`h-3.5 w-3.5 text-primary`}):D(M,{className:`h-3.5 w-3.5`})}),S(`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?D(`button`,{type:`button`,onClick:()=>a.mutate({faceId:e.faceId},{onSettled:s}),disabled:a.isPending,className:`rounded-full bg-warning/80 p-1.5 text-white hover:bg-warning disabled:opacity-50`,title:`Detach`,children:a.isPending?D(B,{className:`h-3.5 w-3.5 animate-spin`}):D(W,{className:`h-3.5 w-3.5`})}):D(`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:D(H,{className:`h-3.5 w-3.5`})}),D(`button`,{type:`button`,onClick:()=>o.mutate({faceId:e.faceId},{onSettled:s}),disabled:o.isPending,className:`rounded-full bg-danger/80 p-1.5 text-white hover:bg-danger disabled:opacity-50`,title:`Delete face`,children:o.isPending?D(B,{className:`h-3.5 w-3.5 animate-spin`}):D(z,{className:`h-3.5 w-3.5`})})]})]}),S(`div`,{className:`px-2 pb-2 space-y-0.5`,children:[D(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.deviceId}),e.identityName&&D(`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 t=T(),[n,r]=E(`all`),[i,c]=E(new Set),[l,u]=E(null),[d,f]=E(!1),{data:m,isLoading:h}=o({limit:100,filter:n}),{data:v=[]}=s(),{data:y,isFetching:b}=g({threshold:.5,minClusterSize:2,limit:20},{enabled:d}),x=a(),w=e(),O=p(),k=m??[],j=C(()=>new Map(k.map(e=>[e.faceId,e])),[k]),M=()=>{t.invalidateQueries({queryKey:X})},N=()=>c(new Set);function P(e){c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function F(e){c(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}let I=[...i],R=x.isPending||w.isPending||O.isPending;function V(){I.length!==0&&w.mutate({faceIds:I},{onSettled:()=>{M(),N()}})}function G(){I.length!==0&&Promise.allSettled(I.map(e=>O.mutateAsync({faceId:e}))).then(()=>{M(),N()})}return S(`div`,{className:`space-y-3`,children:[S(`div`,{className:`flex items-center gap-1`,children:[$.map(e=>D(`button`,{type:`button`,onClick:()=>r(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${n===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value)),S(`button`,{type:`button`,onClick:()=>f(e=>!e),className:`ml-2 flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${d?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[D(A,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!h&&S(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[k.length,` face`,k.length===1?``:`s`]})]}),i.size>0&&S(`div`,{className:`flex items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[S(`span`,{className:`text-xs font-medium text-foreground`,children:[i.size,` selected`]}),S(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[S(_,{variant:`primary`,onClick:()=>u(I),disabled:R,children:[D(H,{className:`h-3.5 w-3.5`}),` Assign`]}),S(_,{variant:`secondary`,onClick:V,disabled:R,children:[w.isPending?D(B,{className:`h-3.5 w-3.5 animate-spin`}):D(W,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),S(_,{variant:`secondary`,onClick:G,disabled:R,children:[D(z,{className:`h-3.5 w-3.5`}),` Delete`]}),D(_,{variant:`ghost`,onClick:N,disabled:R,children:D(L,{className:`h-3.5 w-3.5`})})]})]}),d&&S(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:[D(`p`,{className:`mb-2 text-xs font-medium text-foreground`,children:`Look-alike groups`}),b?S(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[D(B,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):!y||y.length===0?D(`p`,{className:`text-xs text-foreground-subtle`,children:`No look-alike groups found among unassigned faces.`}):D(`div`,{className:`space-y-2`,children:y.map(e=>S(`div`,{className:`flex items-center gap-2 rounded-md bg-surface-hover/50 p-2`,children:[D(`div`,{className:`flex -space-x-1.5`,children:e.faceIds.slice(0,6).map(e=>{let t=j.get(e);return D(`div`,{className:`h-8 w-8 overflow-hidden rounded border border-border bg-surface`,children:t?.base64?D(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:``,className:`h-full w-full object-cover`}):D(U,{className:`h-full w-full p-1.5 text-foreground-subtle`})},e)})}),S(`span`,{className:`text-xs text-foreground-subtle`,children:[e.size,` faces · `,Math.round(e.cohesion*100),`% alike`]}),S(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[D(_,{variant:`secondary`,onClick:()=>F(e.faceIds),children:`Select group`}),S(_,{variant:`primary`,onClick:()=>u(e.faceIds),children:[D(H,{className:`h-3.5 w-3.5`}),` Assign all`]})]})]},e.representativeFaceId))})]}),h&&S(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[D(B,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!h&&k.length===0&&D(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No faces found for this filter.`}),!h&&k.length>0&&D(`div`,{className:`grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8 lg:grid-cols-10`,children:k.map(e=>D(Q,{face:e,selected:i.has(e.faceId),onToggleSelect:P,onAssign:e=>u([e])},e.faceId))}),D(Z,{faceIds:l,identities:v,onDone:()=>{u(null),N()}})]})}function te(){return D(V,{icon:R,title:`Detection Intelligence`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:S(`section`,{className:`space-y-3`,children:[S(`div`,{children:[D(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),D(`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.`}),D(Y,{})]}),S(`div`,{className:`pt-4 border-t border-border`,children:[D(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),D(`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.`}),D(ee,{})]})]})})}export{te as DetectionIntelligencePage};
@@ -0,0 +1,2 @@
1
+ import{$r as e,Ai as t,B as n,Bn as r,Br as i,Cn as a,D as o,Dn as s,E as c,En as l,Fn as u,G as d,Ia as f,In as p,It as m,J as h,K as g,La as _,Ln as v,M as y,Mn as b,N as x,Nn as S,O as C,On as w,Or as T,Pn as E,Q as D,Qi as ee,R as O,Rn as k,Si as te,Sn as A,T as j,Tn as ne,U as re,Vn as ie,W as M,X as N,Xi as P,Y as ae,Yi as oe,Yr as se,a as ce,bt as le,ca as F,dn as ue,dr as de,et as fe,f as pe,fa as me,fr as I,g as he,ga as ge,hi as _e,i as ve,ii as ye,in as L,ir as be,j as xe,ji as Se,jn as Ce,l as we,la as Te,m as Ee,n as De,nt as Oe,o as ke,oi as R,p as Ae,pa as je,pn as Me,q as Ne,r as Pe,rn as Fe,tt as Ie,u as Le,ua as Re,ur as ze,vn as Be,wi as Ve,wn as He,y as Ue,yn as We,z as Ge,zn as Ke}from"./src-BvxPxXyx.js";import{I as z,K as B,Q as V,S as H,W as U,b as W,o as G,q as K,t as qe,x as q,z as J}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{A as Je,D as Ye,E as Xe,I as Ze,N as Qe,O as $e,S as et,T as tt,b as nt,g as rt,k as it,w as Y,y as at}from"./src-Ce30zKhx.js";import{c as ot,k as st,p as X,r as ct,t as lt,u as ut}from"./player-overlays-Bhh-T-qH.js";import{t as dt}from"./CapabilityBadges-BPp4spWK.js";import{n as ft,t as pt}from"./rotate-ccw-B1y8E4DF.js";import{t as mt}from"./ProviderIcon-X1LLmqTA.js";import{t as ht}from"./pencil-BxhnkUV_.js";import{t as gt}from"./plus-BR0mGk3r.js";import{t as _t}from"./refresh-cw-hKUYl1HT.js";import{t as vt}from"./rotate-cw-ChSqQNtp.js";import{t as yt}from"./server-BD-hEzuI.js";import{t as bt}from"./wifi-Cl7ptz-k.js";import{B as xt,F as St,G as Ct,I as wt,O as Tt,R as Et,U as Dt,V as Ot,W as kt,_ as At,a as jt,c as Mt,i as Nt,k as Pt,p as Ft,r as It,s as Lt,t as Rt,v as zt,x as Bt}from"./index-cObQUDCu.js";import{n as Vt,t as Ht}from"./useDevice-BRRdLKBn.js";import{t as Ut}from"./StatusBadge-Dcr2bw58.js";import{t as Wt}from"./useEventInvalidation-OVOcl54D.js";import{n as Gt,r as Kt,t as qt}from"./SchemaTabBar-DhsmEGyn.js";import{t as Jt}from"./FormBuilder-BtCunYUK.js";var Yt=Ot(`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`}]]),Xt=Ot(`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`}]]),Zt=Ot(`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`}]]),Qt=Ot(`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`}]]),$t=Ot(`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`}]]),en=Ot(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),tn=Ot(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),nn=Ot(`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`}]]);V();function rn({parentDeviceId:e}){let{t}=Rt(),n=Dt(),r=X(),{data:i,isLoading:a,isError:o}=Vt(e),{data:s}=A({deviceId:e},{enabled:Number.isFinite(e)});if(a)return q(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:q(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(o)return q(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:q(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let c=(i??[]).filter(e=>e.display?.hidden!==!0);if(c.length===0)return null;let l=d(s?.stableId??``,c,s?.childLayout),u=l.ungrouped,f=e=>n(`/devices/${String(e)}`),p=s?.name??``,m=(e,t)=>q(re,{trpc:r.trpcClient,device:{...t,name:ae(t,p)},variant:`minimal`,onNavigate:f},e),h=u.some(e=>!!e.role),g=u.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=u.length>0?H(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[q(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:_}),q(`div`,{className:`space-y-1`,children:u.map(e=>m(e.id,e))})]}):null,y=l.disabledSection===void 0?null:q(M,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:l.disabledSection.children.length,defaultOpen:!1,children:q(`div`,{className:`opacity-60 space-y-1`,children:l.disabledSection.children.map(e=>m(e.id,e))})},l.disabledSection.title);return l.sections.length===0?y===null?v:H(`div`,{className:`space-y-2`,children:[v,y]}):H(`div`,{className:`space-y-2`,children:[l.sections.map(e=>q(M,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>m(e.id,e))},e.title)),v,y]})}function an({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){return H(`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:[q(mt,{type:n,size:`lg`}),H(`div`,{children:[q(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),q(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),H(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[q(Ut,{status:r?`online`:`offline`}),i.length>0&&q(dt,{capabilities:i})]}),q(`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.`})]})}function on({deviceId:e}){let t=G(),n=Fe({deviceId:e},{refetchInterval:1e4,retry:!1}),r=L({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=U(()=>sn(n.data??[]),[n.data]);return H(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[H(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[q(cn,{label:`Discovered`,value:i.total,icon:q(At,{className:`h-3.5 w-3.5`})}),q(cn,{label:`Adopted`,value:i.adopted,accent:`success`}),q(cn,{label:`Available`,value:i.available,accent:i.available>0?`primary`:void 0}),H(`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?q(Bt,{className:`h-3.5 w-3.5 animate-spin`}):q(_t,{className:`h-3.5 w-3.5`}),q(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),H(`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:[q(ln,{icon:q(bt,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),q(ln,{icon:q(zt,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),q(ln,{icon:q(jt,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?q(ln,{icon:q(Yt,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.unknown} unknown`}):null]})]})}function sn(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 cn({label:e,value:t,icon:n,accent:r}){return H(`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:[H(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,q(`span`,{className:`truncate`,children:e})]}),q(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function ln({icon:e,label:t}){return H(`span`,{className:`inline-flex items-center gap-1`,children:[e,q(`span`,{children:t})]})}function un({deviceId:e,features:t}){return q(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:q(P,{trpc:X().trpcClient,deviceId:e,features:t})})}function dn({deviceId:e,features:t}){return q(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:q(oe,{trpc:X().trpcClient,deviceId:e,features:t})})}function Z({deviceId:e,deviceType:t,features:r}){let i=X(),a=Ie(t)?.HeroCard??oe,o=ut(ot(i.trpcClient,e)?.state.deviceStatus),s=o!==void 0&&o.online===!1,c=s?o.lastChangedAt:null;return H(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[s?q(`div`,{className:`flex justify-center`,children:q(n,{lastChangedAt:c})}):null,q(a,{trpc:i.trpcClient,deviceId:e,features:r})]})}function fn({deviceId:e}){let t=X(),{data:n,isLoading:r}=Ht(e),{data:i,isLoading:a}=Vt(e),o=r||a,s=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),c=typeof n?.linkDeviceId==`number`?n.linkDeviceId:null,l=typeof n?.primaryChildEntityId==`string`?n.primaryChildEntityId:null;return o?q(`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:q(Ge,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}var pn={[Y.Switch]:Z,[Y.Siren]:Z,[Y.Light]:Z,[Y.Sensor]:Z,[Y.Button]:Z,[Y.Hub]:on,[Y.Cover]:un,[Y.Valve]:Z,[Y.Humidifier]:Z,[Y.WaterHeater]:Z,[Y.Container]:fn,[Y.Lock]:Z,[Y.Fan]:Z,[Y.Thermostat]:Z,[Y.Climate]:Z,[Y.MediaPlayer]:Z,[Y.Control]:Z,[Y.AlarmPanel]:dn,[Y.EventEmitter]:dn,[Y.Notifier]:dn,[Y.Script]:dn,[Y.Automation]:dn,[Y.Presence]:Z,[Y.Update]:Z,[Y.Vacuum]:Z,[Y.LawnMower]:Z,[Y.Weather]:Z,[Y.Image]:Z,[Y.PetFeeder]:Z};function mn(e){return q(pn[e.deviceType]??an,{...e})}function hn(e){return ce(X().trpcClient,e)}V();function gn(e){let[t,n]=K(`idle`),[r,i]=K(null),a=B(null),o=B(null),s=B(null),c=B(!0),l=de(),u=ze(),d=I(),f=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}s.current=null},[]),p=z(async()=>{if(t===`idle`)return;n(`stopping`);let r=s.current;if(r&&e!==null)try{await Promise.race([d.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)}f(),c.current&&(n(`idle`),i(null))},[t,e,d,f]),m=z(async()=>{if(e===null||t!==`idle`&&t!==`error`)return;i(null);let r=null,f=null,m=null;try{n(`requesting-mic`),r=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),o.current=r,n(`starting`);let t=await l.mutateAsync({deviceId:e});m=t.sessionId,s.current=m,n(`connecting`),f=new RTCPeerConnection,a.current=f,f.oniceconnectionstatechange=()=>{if(!c.current)return;let e=f.iceConnectionState;e===`connected`||e===`completed`?n(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&c.current&&(i(e===`failed`?`WebRTC connection failed`:null),p())};for(let e of r.getAudioTracks())f.addTrack(e,r);await f.setRemoteDescription({type:`offer`,sdp:t.sdpOffer});let d=await f.createAnswer();await f.setLocalDescription(d);let h=f.localDescription?.sdp??d.sdp??``;await u.mutateAsync({deviceId:e,sessionId:m,sdpAnswer:h})}catch(t){let l=t instanceof Error?t.message:String(t);if(console.warn(`[intercom] start failed`,t),f)try{f.close()}catch{}if(r)for(let e of r.getTracks())try{e.stop()}catch{}if(a.current=null,o.current=null,m!==null)try{await d.mutateAsync({deviceId:e,sessionId:m})}catch{}s.current=null,c.current&&(i(l),n(`error`))}},[e,t,l,u,d,p]);return J(()=>(c.current=!0,()=>{c.current=!1;let t=s.current;if(t!==null&&e!==null&&d.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}s.current=null}),[e]),{state:t,error:r,start:m,stop:p,isTalking:t===`talking`}}V();var _n=0;function Q(){return++_n}function vn(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function yn(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 bn(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 xn(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 Sn({scope:e,greeting:t,className:n}){let r=X(),[i,a]=K(()=>{let n=[];return t&&n.push({id:Q(),kind:`info`,text:t}),n.push({id:Q(),kind:`info`,text:`scope: ${vn(e)} — type help or context for available commands`}),n}),[o,s]=K(``),[c,l]=K([]),[u,d]=K(-1),f=B(null),p=B(null);J(()=>{let e=p.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let m=z(()=>{f.current?.focus()},[]),h=qe({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:Q(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);a(e=>[...e,{id:Q(),kind:`error`,text:t}])}});function g(t){let n=t.trim();if(n){if(n===`clear`){a([{id:Q(),kind:`info`,text:`scope: ${vn(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...yn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...xn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...bn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}l(e=>[...e,n]),d(-1),a(e=>[...e,{id:Q(),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:Q(),kind:`info`,text:`scope: ${vn(e)}`}]))}let v={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return H(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??``}`,onClick:m,children:[H(`div`,{ref:p,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[i.map(e=>q(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${v[e.kind]}`,children:e.text},e.id)),h.isPending&&q(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),H(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[q(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),q(`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 Cn({deviceId:e,intercomAvailable:t=!1}){let n=X(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),a=hn(i?e:null),{streams:o,pipelineMetrics:s,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h}=ve(n.trpcClient,i?e:null),g=Ne(n.trpcClient,i?e:null),_=gn(i&&t?e:null),v=_.state===`requesting-mic`||_.state===`starting`||_.state===`connecting`||_.state===`stopping`,y=_.isTalking||v,b=()=>{_.state===`idle`||_.state===`error`?_.start():_.state!==`stopping`&&_.stop()},x=ct(),S=C(),w=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,T=x.length>0?q(W,{children:x.map(e=>q(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return q(Ue,{serverUrl:r,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h,...S.request?{playbackUrl:S.request.url,playbackAuthToken:w,...S.request.label?{playbackLabel:S.request.label}:{},onExitPlayback:()=>S.clear()}:{},streams:o,pipelineMetrics:s,phase:a.phase,detections:a,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:g.src,...g.src?{posterUrl:g.src}:{},snapshotLoading:g.loading,onRefreshSnapshot:g.refresh,intercomAvailable:t,intercomShown:y,onIntercomToggle:b,extraOverlay:T,chromeless:!0,className:`h-full`})}function wn({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full`,children:q(he,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Tn({deviceId:e}){if(!Number.isFinite(e))return H(`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 q(Sn,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function En({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(Ee,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Dn({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(pe,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function On({deviceId:e}){let t=G(),n=Number.isFinite(e),{data:r}=A({deviceId:e},{enabled:n}),i=typeof r?.type==`string`?r.type:`camera`;Wt([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:a,isLoading:o,isError:c,error:l}=We({deviceId:e},{enabled:n}),{data:u}=s({deviceType:i},{enabled:!!i}),d=Ke({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(o)return q(`div`,{className:`p-4`,children:q(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(c)return H(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,l instanceof Error?l.message:String(l)]});let f=new Map,p={};for(let e of u??[])p[e.capName]=e.wrappers;for(let e of a?.entries??[])f.set(e.capName,{...e,wrappers:p[e.capName]??[]});for(let e of u??[])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 H(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[q(ft,{className:`h-8 w-8 opacity-40`}),q(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),q(`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 H(`div`,{className:`flex flex-col gap-3 p-1`,children:[H(`div`,{className:`text-[11px] text-foreground-subtle`,children:[q(`span`,{className:`font-medium text-foreground`,children:h}),` of `,m.length,` capabilit`,m.length===1?`y`:`ies`,` bound — rows marked `,q(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),q(me,{columns:[{key:`capability`,header:`Capability`,render:e=>q(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>q(kn,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>q(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||q(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?q(An,{nodeId:e.providerNodeId}):q(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>q(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||q(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return q(jn,{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 kn({kind:e}){return e===`native`?H(`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:[q(yt,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?H(`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:[q(Xt,{className:`h-3 w-3`}),`wrapped`]}):e===`linked`?H(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-warning/30 text-warning bg-warning/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[q(Qt,{className:`h-3 w-3`}),`linked`]}):H(`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:[q(en,{className:`h-3 w-3`}),`unbound`]})}function An({nodeId:e}){return q(`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 jn({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){return e.length===0?q(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):q(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let i=e===t;return H(`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:[q(i?St:pt,{className:`h-3 w-3`}),e]},e)})})}V();function Mn({schema:e,values:t,pendingKeys:n,onChange:r,onAction:i,onSave:a,onDiscard:o,disabled:s,activeSubTab:c,onSubTabChange:l,flattenTabs:u=!1}){let d=e.tabs??[],f=U(()=>{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]),p=new Set(d.map(e=>e.id)),m=[...d,...[...f.keys()].filter(e=>!p.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],h=m[0]?.id??`general`,[g,_]=K(h),v=l!==void 0,y=new Set(m.map(e=>e.id)),b=v?c&&y.has(c)?c:h:y.has(g)?g:h,x=e=>{v?l(e):_(e)},S=f.get(b)??[],C={sections:S.length<=1?S.length===1?[{...S[0],title:``}]:S:S.every(e=>!e.title)?[{...S[0],title:``,fields:S.flatMap(e=>e.fields)}]:S},w=q(Gt,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>o(n),saving:s});if(u||m.length<=1)return H(`div`,{className:`flex flex-col gap-3`,children:[q(Jt,{schema:e,values:t,onChange:r,onAction:i,disabled:s}),w]});let T=new Map,E=new Map;for(let[e,t]of f){T.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&&E.set(e,a)}return H(`div`,{className:`flex flex-col gap-3`,children:[q(qt,{tabs:m.map(e=>({id:e.id,label:e.label})),activeId:b,onChange:x,countByTab:T,pendingByTab:E}),q(Jt,{schema:C,values:t,onChange:r,onAction:i,disabled:s}),w]})}var Nn=`device-export`,Pn=`export`,Fn=`Export`;function In(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(In):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(In)):e.writerCapName===Nn}function Ln(e){return e.fields.some(In)}V();function Rn(e,t){return t&&t===`admin`?e:!0}function zn(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?Ln(e)&&Ln(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 Vn(e){return e.key}function Hn(e){if(!Bn(e))return e.value}function Un(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 Gn(e){if(!e)return{};let t={};for(let n of e.sections)Wn(n.fields,e=>{let n=Vn(e);n!==null&&(t[n]=Hn(e))});return t}function Kn(e,t){if(!e)return null;let n=null;for(let r of e.sections)if(Wn(r.fields,e=>{if(n!==null||Vn(e)!==t)return;let r=Un(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function qn(e){return{...e,fields:e.fields.map(Jn)}}function Jn(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function Yn(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=Un(e);return n?Rn(t,n.minRole)?e:Jn(e):e})}))}}function Xn({deviceId:e,sectionFilter:n,activeSubTab:i,onSubTabChange:o,flattenSubTabs:s}){let c=G(),{user:l}=It(),u=l?.isAdmin===!0,d=B(!1),{data:f,isLoading:p}=a({deviceId:e},{refetchInterval:()=>d.current?!1:2500,enabled:Number.isFinite(e)}),{data:m}=A({deviceId:e},{enabled:Number.isFinite(e)}),h=f?.settings??null,g=f?.live??null,_=U(()=>{if(!h&&!g)return null;let e=h?.sections??[],t=(g?.sections??[]).map(qn),r=[...e,...t],i=n?r.filter(n):r.filter(e=>e.location!==`top-tab`&&!Ln(e));if(i.length===0)return null;let a=new Set;for(let e of i)a.add(e.tab??`general`);let o=[...h?.tabs??[],...(g?.tabs??[]).filter(e=>!(h?.tabs??[]).some(t=>t.id===e.id))].filter(e=>a.has(e.id));return o.length>0?{tabs:o,sections:i}:{sections:i}},[h,g,n]),v=U(()=>zn(_),[_]),y=U(()=>Yn(v,u),[v,u]),x=U(()=>Gn(y),[y]),S=Se(),C=t(),w=r(),T=b(),E=ie({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),D={isPending:E.isPending,mutate:t=>{E.mutate({deviceId:e,changes:[...t]})}},ee=Kt({schema:y,serverValues:x,onImmediateSave:z(e=>{let t=Object.entries(e).map(([e,t])=>{let n=Kn(y,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&D.mutate(t)},[y,D]),onDeferredSave:z(e=>{let t=Object.entries(e).map(([e,t])=>{let n=Kn(y,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&D.mutate(t)},[y,D])}),{values:O,pendingKeys:k,handleChange:te,handleSave:j,handleDiscard:ne}=ee;if(d.current=ee.editingPaused,p)return H(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[q(Bt,{className:`h-4 w-4 animate-spin mr-2`}),q(`span`,{className:`text-xs`,children:`Loading device aggregate…`})]});if(!y||y.sections.length===0)return q(`div`,{className:`text-xs text-foreground-subtle italic py-4 text-center`,children:`No aggregate contributions for this device.`});async function re(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 i=Qe(e,r);await S.mutateAsync({brokerId:i}),c.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(t===`test-probe`){if(!m)return{status:`error`,error:`Device metadata not loaded yet`};try{return await w.mutateAsync({addonId:m.addonId,type:m.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=Qe(e,t),i=await C.mutateAsync({brokerId:r});return c.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),i}if(t===`device-custom-action`){let t=await T.mutateAsync({deviceId:e,action:n,input:r});return c.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),t}throw Error(`[device-aggregate] unknown action "${t}"`)}return q(Mn,{schema:y,values:O,pendingKeys:k,onChange:te,onAction:re,onSave:j,onDiscard:ne,disabled:D.isPending,activeSubTab:i,onSubTabChange:o,flattenTabs:s})}function Zn({deviceId:e,activeSubTab:t,onSubTabChange:n}){return q(`div`,{className:`flex flex-col gap-3`,children:q(Xn,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}V();function Qn(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 $n(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 er({agents:e,currentAgent:t,onPick:n}){let[r,i]=K(!1);return H(`div`,{className:`relative`,children:[q(`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&&q(`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=>q(`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 tr({deviceId:t,refreshToken:n}){let r=G(),[a,o]=K(null),[s,c]=K(null),[l,u]=K(null),[d,f]=K(null),p=e({deviceId:t}),m=R(),h=ye({deviceId:t}),g=se(),v=U(()=>h.data?.agentNodeId||g.data?.find(e=>e.online)?.nodeId||`hub`,[h.data?.agentNodeId,g.data]),y=s??v,b=i({nodeId:y??``},{enabled:!!y}),x=_e({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),u(null)}}),S=U(()=>b.data?Re(b.data):[],[b.data]),C=U(()=>{let e=p.data??null,t={};for(let n of m.data??[])for(let r of Object.keys(n.settings.addonDefaults)){let i=t[r]??[];i.push({agentNodeId:n.nodeId,state:$n(e,n.nodeId,r)}),t[r]=i}return t},[p.data,m.data]),w=a?Qn(b.data??null,a):null,T=y?m.data?.find(e=>e.nodeId===y)??null:null,E=a&&T?T.settings.addonDefaults[a]??null:null,D=a&&y?p.data?.stepOverridesByAgent?.[y]?.[a]??null:null,ee=b.data?.selectedEngine.format??`coreml`,O=e=>{c(e),u(null),f(null)};return m.isLoading||b.isLoading?q(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`}):b.data?q(`div`,{className:`@container h-full`,style:{containerType:`inline-size`},children:H(`div`,{className:`flex flex-col @[720px]:flex-row h-full`,children:[q(`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:q(Te,{tree:S,selectedAddonId:a,onSelect:e=>{o(e),u(null),f(null)},agentDots:C})}),q(`section`,{className:`flex-1 min-w-0 p-4 overflow-y-auto`,children:!a||!w?q(`div`,{className:`text-sm text-foreground-subtle`,children:`Select a step on the left to configure it for this camera.`}):H(`div`,{className:`space-y-4`,children:[H(`div`,{children:[q(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle`,children:`Selected step`}),q(`div`,{className:`text-base font-semibold`,children:w.name})]}),H(`div`,{className:`flex items-end gap-3 flex-wrap`,children:[H(`div`,{children:[q(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle mb-1`,children:`Agent`}),q(`div`,{className:`flex rounded border border-border overflow-hidden`,children:(m.data??[]).map(e=>q(`button`,{type:`button`,onClick:()=>O(e.nodeId),className:`px-3 py-1 text-xs ${y===e.nodeId?`bg-primary text-primary-foreground`:`bg-surface hover:bg-muted`}`,children:e.nodeId},e.nodeId))})]}),q(er,{agents:(m.data??[]).map(e=>e.nodeId),currentAgent:y,onPick:e=>{if(!y||!a||!b.data||!m.data)return;let t=m.data.find(t=>t.nodeId===e),n=m.data.find(e=>e.nodeId===y);if(!t||!n)return;let[r]=_({source:{nodeId:t.nodeId,engine:{format:ee},defaults:t.settings.addonDefaults},target:{nodeId:n.nodeId,engine:{format:ee},defaults:n.settings.addonDefaults},catalog:b.data,addonIds:[a]});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&&q(`div`,{className:`text-[10px] text-foreground-subtle`,children:d})]}),E&&q(F,{mode:`device`,addon:w,agentDefault:E,agentNodeId:y??``,currentPatch:l??D,engineFormat:ee,onChangePatch:u}),H(`div`,{className:`flex items-center justify-between gap-2 pt-4 border-t border-border`,children:[q(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle`,disabled:!D||x.isPending,onClick:()=>{!y||!a||x.mutate({deviceId:t,agentNodeId:y,addonId:a,patch:null})},children:`Clear override`}),H(`div`,{className:`flex items-center gap-2`,children:[q(`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`}),q(`button`,{type:`button`,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,disabled:!y||!a||x.isPending,onClick:()=>{!y||!a||x.mutate({deviceId:t,agentNodeId:y,addonId:a,patch:l})},children:x.isPending?`Saving…`:`Save`})]})]})]})})]})}):q(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`})}function $({label:e,value:t}){return H(`div`,{className:`${st} flex items-start gap-2 sm:gap-3`,children:[q(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),q(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}V();function nr({deviceId:e,initialName:t}){let n=G(),[r,i]=K(!1),[a,o]=K(t),[s,c]=K(!1),l=B(null);J(()=>{r||o(t)},[t,r]),J(()=>{r&&l.current?.focus()},[r]);let u=p({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?q($,{label:`Name`,value:H(`div`,{className:`flex items-center gap-1`,children:[q(`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`}),q(`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:q(St,{className:`h-3 w-3`})}),q(`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:q(Nt,{className:`h-3 w-3`})})]})}):q($,{label:`Name`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[q(`span`,{className:`truncate`,children:t}),q(`button`,{type:`button`,onClick:()=>i(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit name`,children:q(ht,{className:`h-3.5 w-3.5`})})]})})}V();function rr({deviceId:e,initialLocation:t}){let n=G(),[r,i]=K(!1),[a,o]=K(t??``),[s,c]=K(!1),l=B(null),{data:d}=w(void 0,{enabled:r}),f=d??[];J(()=>{r||o(t??``)},[t,r]),J(()=>{r&&l.current?.focus()},[r]);let p=u({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),m=U(()=>{let e=a.trim().toLowerCase();return e.length===0?f:f.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[f,a]),h=a.trim().length>0&&!f.some(e=>e.toLowerCase()===a.trim().toLowerCase()),g=async n=>{let r=(n??a).trim(),o=r.length===0?null:r;if(o===(t??null)){i(!1);return}c(!0);try{await p.mutateAsync({deviceId:e,location:o}),i(!1)}catch{}finally{c(!1)}},_=()=>{o(t??``),i(!1)};return r?q($,{label:`Location`,value:H(`div`,{className:`relative`,children:[H(`div`,{className:`flex items-center gap-1`,children:[q(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?g():e.key===`Escape`&&_()},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`}),q(`button`,{type:`button`,onClick:()=>void g(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:q(St,{className:`h-3 w-3`})}),q(`button`,{type:`button`,onClick:_,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:q(Nt,{className:`h-3 w-3`})})]}),(m.length>0||h)&&H(`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:[m.map(e=>H(`button`,{type:`button`,onClick:()=>{o(e),g(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[q($t,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),q(`span`,{className:`truncate`,children:e})]},e)),h&&H(`button`,{type:`button`,onClick:()=>void g(),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:[q(`span`,{className:`text-foreground-subtle`,children:`Create`}),H(`span`,{className:`font-medium truncate`,children:[`"`,a.trim(),`"`]})]})]})]})}):q($,{label:`Location`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[t?q(`span`,{className:`truncate`,children:t}):q(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),q(`button`,{type:`button`,onClick:()=>i(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit location`,children:q(ht,{className:`h-3.5 w-3.5`})})]})})}V();function ir({deviceId:e}){let t=G(),{data:n}=Ht(e),{data:r}=Vt(e),[i,a]=K(null),o=v({onSuccess:()=>{a(null),t.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{a(`Could not change primary child: ${e.message}`)}});if(n==null||String(n.type??``)!==Y.Container)return null;let s=(r??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}}));if(s.length<=1)return null;let c=fe(s,typeof n.linkDeviceId==`number`?n.linkDeviceId:null,typeof n.primaryChildEntityId==`string`?n.primaryChildEntityId:null);return H(W,{children:[q($,{label:`Primary child`,value:q(O,{childrenList:s,selectedId:c===null?s[0].id:c.id,onSetPrimary:t=>o.mutate({deviceId:e,primaryChildEntityId:t}),disabled:o.isPending})}),i!==null&&q(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:i})]})}V();var ar=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function or(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function sr(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function cr(){let e=y(),t=x(),{data:n}=A({deviceId:e??0},{enabled:e!==null}),{data:r}=We({deviceId:e??0},{enabled:e!==null}),i=n??t??null,[a,o]=K(`identity`);if(e===null||!i)return null;let s=String(i.stableId??``),c=String(i.name??``),l=String(i.type??``),u=String(i.addonId??``),d=i.features??[],f=new Set([`device-status`,`feature-probe`,`device-ops`]),p=(r?.entries??[]).filter(e=>e.kind===`native`&&!f.has(e.capName)).map(e=>e.capName),m=d.length>0?d:p,h=i.location??null,g=i.metadata??null,_=g!==null&&Object.keys(g).length>0;return H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[H(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[q(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),_&&H(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[q(lr,{active:a===`identity`,onClick:()=>o(`identity`),label:`Identity`}),q(lr,{active:a===`hardware`,onClick:()=>o(`hardware`),label:`Hardware`})]})]}),(!_||a===`identity`)&&H(`div`,{className:`divide-y divide-border`,children:[q($,{label:`ID`,value:H(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${e}`,H(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,s,`)`]})]})}),q(nr,{deviceId:e,initialName:c}),q(rr,{deviceId:e,initialLocation:h}),q(ir,{deviceId:e}),q($,{label:`Type`,value:l}),q($,{label:`Provider`,value:q(mt,{type:u,size:`sm`,showLabel:!0})}),q($,{label:`Capabilities`,value:m.length>0?q(dt,{capabilities:m,showLabels:!0}):q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),_&&a===`hardware`&&q(ur,{metadata:g})]})}function lr({active:e,onClick:t,label:n}){return q(`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 ur({metadata:e}){let t=ar.filter(t=>t in e),n=Object.keys(e).filter(e=>!ar.includes(e)).toSorted(),r=[...t,...n];return H(`div`,{children:[q(`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.`}),q(`div`,{className:`divide-y divide-border`,children:r.map(t=>q($,{label:or(t),value:q(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:sr(e[t])})},t))})]})}V();function dr({deviceId:e}){let[t,n]=K(null),r=ue({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 H(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[H(`div`,{className:`flex items-center justify-between gap-3`,children:[H(`div`,{children:[q(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),q(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),H(`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:[q(_t,{className:`h-3 w-3 ${r.isPending?`animate-spin`:``}`}),r.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&q(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}V();var fr={icon:``,label:``,unit:``,precision:``,hidden:!1};function pr(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function mr(e){if(typeof e!=`object`||!e)return;let t=e.unit;return typeof t==`string`?t:void 0}function hr(e){let t=e.precision.trim()===``?void 0:Number.parseInt(e.precision,10),n={...e.icon===``?{}:{icon:e.icon},...e.label.trim()===``?{}:{label:e.label.trim()},...e.unit===``?{}:{unit:e.unit},...t!==void 0&&Number.isFinite(t)?{precision:t}:{},...e.hidden?{hidden:!0}:{}};return Object.keys(n).length===0?null:n}function gr({deviceId:e}){let t=X(),n=G(),{data:r}=A({deviceId:e},{enabled:e>0}),i=typeof r?.role==`string`?r.role:null,a=i===null?void 0:Oe[i],o=a?.kind===`numeric`,s=De(t.trpcClient,e,i??``),c=a?.kind===`numeric`?a.canonicalUnit:void 0,l=mr(s)??c,u=l===void 0?void 0:at(l),d=U(()=>u===void 0?[]:nt(u),[u]),[f,p]=K(null),m=f??pr(r?.display),h=E({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:g}=He({},{staleTime:6e4}),_=k({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(r===void 0||i===null)return null;let v=e=>{p({...m,...e})},y=()=>{h.mutate({deviceId:e,display:hr(m)})},b=()=>{p(fr),h.mutate({deviceId:e,display:null})},x=()=>{let e={...m.icon===``?{}:{icon:m.icon},...m.unit===``?{}:{unit:m.unit},...m.precision.trim()!==``&&Number.isFinite(Number.parseInt(m.precision,10))?{precision:Number.parseInt(m.precision,10)}:{}},t={...g?.defaults??{},[i]:e};_.mutate({defaults:t})},S=D(i).label,C=Object.keys(N);return H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[q(`div`,{className:`border-b border-border px-4 py-2`,children:q(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Display`})}),H(`div`,{className:`p-4 space-y-3`,children:[H(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Icon`}),H(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:m.icon,onChange:e=>v({icon:e.target.value}),children:[H(`option`,{value:``,children:[`Default (`,S,`)`]}),C.map(e=>q(`option`,{value:e,children:e},e))]})]}),H(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Label`}),q(`input`,{type:`text`,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:S,value:m.label,onChange:e=>v({label:e.target.value})})]}),o&&H(`div`,{className:`grid grid-cols-2 gap-3`,children:[H(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Unit`}),H(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:m.unit,onChange:e=>v({unit:e.target.value}),disabled:d.length===0,children:[H(`option`,{value:``,children:[`Source`,l?` (${l})`:``]}),d.map(e=>q(`option`,{value:e,children:e},e))]})]}),H(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Precision`}),q(`input`,{type:`number`,min:0,max:10,step:1,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:`inherit`,value:m.precision,onChange:e=>v({precision:e.target.value})})]})]}),H(`label`,{className:`flex items-center gap-2`,children:[q(`input`,{type:`checkbox`,checked:m.hidden,onChange:e=>v({hidden:e.target.checked})}),q(`span`,{className:`text-sm text-foreground`,children:`Hide from device lists`})]}),H(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[q(`button`,{type:`button`,className:`rounded bg-primary px-3 py-1 text-sm font-medium text-primary-foreground disabled:opacity-50`,onClick:y,disabled:h.isPending,children:`Save`}),q(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:b,disabled:h.isPending,children:`Reset`}),H(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:x,disabled:_.isPending,title:`Apply this unit / precision / icon as the default for every ${S} sensor`,children:[`Set as default for all `,S,` sensors`]})]})]})]})}function _r(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function vr({device:e}){let t=Dt(),n=typeof e.id==`number`?e.id:null,r=String(e.type??``),i=r===Y.Camera,a=r===Y.Hub,o=typeof e.role==`string`&&e.role.length>0,s=e.features??[],c=s.includes(et.Resyncable),{data:l}=T({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),u=l?.streams??{},d=Object.entries(u),f=s.includes(et.DoorbellButton),p=Pe(f?{deviceId:n??void 0,historyLimit:10}:void 0),m=p.latest?Date.now()-p.latest.timestamp<3e4:!1;return H(`div`,{className:`space-y-5`,children:[a&&n!==null&&q(Ae,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),c&&n!==null&&q(dr,{deviceId:n}),i&&n!==null&&q(j,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),f&&q(Le,{history:p.history,latestIsFresh:m}),i&&n!==null&&q(j,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),i&&d.length>0&&H(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[q(`div`,{className:`border-b border-border px-4 py-2`,children:q(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),q(`div`,{className:`divide-y divide-border`,children:d.map(([e,t])=>H(`div`,{className:`px-4 py-2.5`,children:[H(`div`,{className:`flex items-center gap-2 mb-2`,children:[q(bt,{className:`h-3 w-3 text-foreground-subtle`}),q(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),H(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[q(yr,{label:`Nominal`,value:_r(t.nominalBitrateKbps??0)}),q(yr,{label:`Observed`,value:_r(t.observedBitrateKbps??0)}),q(yr,{label:`Peak`,value:_r(t.peakBitrateKbps??0)}),q(yr,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),q(cr,{}),o&&n!==null&&q(gr,{deviceId:n})]})}function yr({label:e,value:t,warning:n}){return H(`div`,{children:[q(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),q(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}V();function br(e,t){if(t===`number`){let t=Number(e);return Number.isNaN(t)?e:t}return t===`boolean`?e===`true`:e}function xr(e,t){let n={};for(let r of e)r.key!==``&&r.value!==``&&(n[r.key]=br(r.value,t));return n}function Sr(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 Cr(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 wr(e){return e==null?`identity`:e.kind}function Tr({value:e,onChange:t,sourceField:n,targetKind:r}){let[i,a]=K(()=>wr(e)),[o,s]=K(()=>Sr(e,n)),[c,l]=K(()=>e?.kind===`enum-map`&&e.fallback!=null?String(e.fallback):``),[u,d]=K(()=>Cr(e));J(()=>{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]),J(()=>{if(i===`identity`){t(void 0);return}if(i===`enum-map`){let e=xr(o,r),n=c===``?void 0:br(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(Sr(void 0,n)),e===`linear`&&d(Cr(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 H(`div`,{className:`flex flex-col gap-3`,children:[H(`div`,{children:[q(`p`,{className:`text-[11px] font-medium text-foreground-subtle mb-1.5`,children:`Transform`}),q(`div`,{className:`flex items-center gap-4`,children:[`identity`,`enum-map`,`linear`].map(e=>H(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[q(`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`&&H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[q(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Key → Value mapping`}),o.map((e,t)=>H(`div`,{className:`flex items-center gap-1.5`,children:[q(`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`}),q(`span`,{className:`text-foreground-subtle/50 text-xs`,children:`→`}),r===`boolean`?H(`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:[q(`option`,{value:``,children:`—`}),q(`option`,{value:`true`,children:`true`}),q(`option`,{value:`false`,children:`false`})]}):q(`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`&&q(`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`&&q(`button`,{type:`button`,onClick:m,className:`self-start text-[10px] text-primary/70 hover:text-primary transition-colors`,children:`+ Add row`}),H(`div`,{className:`flex items-center gap-2 pt-1 border-t border-border/50`,children:[q(`label`,{className:`text-[10px] text-foreground-subtle/70 whitespace-nowrap`,children:`Fallback:`}),q(`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`&&H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[q(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Linear: value × scale + offset`}),H(`div`,{className:`grid grid-cols-2 gap-2`,children:[H(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Scale`}),q(`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`})]}),H(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Offset`}),q(`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`})]})]}),H(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[q(`input`,{type:`checkbox`,checked:u.useClamp,onChange:e=>d(t=>({...t,useClamp:e.target.checked})),className:`accent-primary`}),q(`span`,{className:`text-foreground-subtle`,children:`Clamp output`})]}),u.useClamp&&H(`div`,{className:`grid grid-cols-2 gap-2`,children:[H(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Min`}),q(`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`})]}),H(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Max`}),q(`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`})]})]})]})]})}var Er=`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`;function Dr({mode:e,idPrefix:t,labelPrefix:n,pickerDevices:r,value:i,onChange:a,search:o,onSearchChange:s}){let{data:c}=ne({deviceId:i.sourceId??0},{enabled:i.sourceId!=null}),l=c?.caps??[],u=l.find(e=>e.cap===i.cap)?.fields??[],d=e=>{a(e,(l.find(t=>t.cap===e.cap)?.fields??[]).find(t=>t.path===e.fieldPath))},f=e=>{d({sourceId:e===``?null:Number(e),cap:``,fieldPath:``})},p=e=>{d({sourceId:i.sourceId,cap:e,fieldPath:``})},m=e=>{d({sourceId:i.sourceId,cap:i.cap,fieldPath:e})};return H(W,{children:[e===`global`&&s&&H(`div`,{children:[q(`label`,{htmlFor:`${t}-search`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Search devices`}),q(`input`,{id:`${t}-search`,type:`text`,value:o??``,placeholder:`Filter by name, stable id or #id`,onChange:e=>s(e.target.value),className:Er})]}),H(`div`,{children:[H(`label`,{htmlFor:`${t}-device`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[n,` device`]}),H(`select`,{id:`${t}-device`,value:i.sourceId??``,onChange:e=>f(e.target.value),className:Er,children:[q(`option`,{value:``,children:`— select a device —`}),r.map(e=>H(`option`,{value:e.id,children:[e.name??e.stableId,` (#`,e.id,`)`]},e.id))]})]}),H(`div`,{children:[H(`label`,{htmlFor:`${t}-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[n,` cap`]}),H(`select`,{id:`${t}-cap`,value:i.cap,disabled:i.sourceId==null,onChange:e=>p(e.target.value),className:Er,children:[q(`option`,{value:``,children:`— select a cap —`}),l.map(e=>q(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),H(`div`,{children:[H(`label`,{htmlFor:`${t}-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[n,` field`]}),H(`select`,{id:`${t}-field`,value:i.fieldPath,disabled:i.cap===``,onChange:e=>m(e.target.value),className:Er,children:[q(`option`,{value:``,children:`— select a field —`}),u.map(e=>H(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]})}function Or(e,t){switch(e){case`null`:return{value:null};case`string`:return t===``?null:{value:t};case`number`:{if(t.trim()===``)return null;let e=Number(t);return Number.isFinite(e)?{value:e}:null}case`boolean`:return t===`true`?{value:!0}:t===`false`?{value:!1}:null}}function kr(e){return e===null?`null`:typeof e==`number`?`number`:typeof e==`boolean`?`boolean`:`string`}function Ar(e){return e===null?``:String(e)}V();var jr=`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`,Mr=`min, max, abs, round, floor, ceil, sqrt, pow, clamp, avg, sum, coalesce, age, convert`,Nr=0;function Pr(){return Nr+=1,`b${Nr}`}function Fr(e){return{key:Pr(),name:e,mode:`sibling`,sourceId:null,cap:``,fieldPath:``,search:``,literalType:`number`,literalText:``,sampleText:``}}function Ir(e,t,n){if(e===null)return[Fr(`a`)];let r=[];for(let[i,a]of Object.entries(e.bindings)){if(a.kind===`literal`){r.push({...Fr(i),mode:`literal`,literalType:kr(a.value),literalText:Ar(a.value)});continue}if(a.kind===`global`){r.push({...Fr(i),mode:`global`,sourceId:t.find(e=>e.stableId===a.sourceStableId)?.id??null,cap:a.cap,fieldPath:a.fieldPath});continue}r.push({...Fr(i),mode:`sibling`,sourceId:t.find(e=>e.stableId===`${n}-${a.sourceKey}`)?.id??null,cap:a.cap,fieldPath:a.fieldPath})}return r.length>0?r:[Fr(`a`)]}function Lr(e,t,n){if(e.mode===`literal`){let t=Or(e.literalType,e.literalText);return t===null?null:{kind:`literal`,value:t.value}}let r=t.find(t=>t.id===e.sourceId);if(!r||e.cap===``||e.fieldPath===``)return null;if(e.mode===`global`)return{kind:`global`,sourceStableId:r.stableId,cap:e.cap,fieldPath:e.fieldPath};let i=`${n}-`,a=r.stableId.startsWith(i)?r.stableId.slice(i.length):``;return a===``?null:{kind:`field`,sourceKey:a,cap:e.cap,fieldPath:e.fieldPath}}function Rr(e){if(e.mode===`literal`)return Or(e.literalType,e.literalText)?.value??null;let t=e.sampleText.trim();if(t===``)return null;let n=Number(t);return Number.isFinite(n)?n:e.sampleText}function zr({devices:e,siblings:t,targetDeviceId:n,containerStableId:r,initial:i,onChange:a}){let[o,s]=K(i?.expr??``),[c,l]=K(()=>Ir(i,e,r)),u=U(()=>{let t={},n=c.length>0,i=new Set;for(let a of c){let o=a.name.trim();if(o===``||i.has(o)){n=!1;continue}i.add(o);let s=Lr(a,e,r);if(s===null){n=!1;continue}t[o]=s}return{source:{kind:`expression`,expr:o,bindings:t},complete:n}},[c,o,e,r]),d=U(()=>Xe({expr:u.source.expr,bindings:u.source.bindings}),[u.source]),f=U(()=>{if(o.trim()===``)return null;let e=Ye(o);return e.ok?null:e.error},[o]),p=U(()=>{if(u.source.expr.trim()===``)return null;let e={};for(let t of c){let n=t.name.trim();n!==``&&(e[n]=Rr(t))}return tt(u.source.expr,e,Date.now())},[u.source.expr,c]),m=u.complete&&d===null&&o.trim()!==``;J(()=>{a(m?u.source:null)},[m?JSON.stringify(u.source):`null`]);let h=e=>{let t=e.name.trim();return t===``?`required`:it.test(t)?Je.has(t)?`reserved`:$e.has(t)?`shadows builtin`:c.filter(e=>e.name.trim()===t).length>1?`duplicate`:null:`invalid name`},g=(e,t)=>{l(n=>n.map(n=>n.key===e?{...n,...t}:n))},_=()=>{c.length>=32||l(e=>[...e,Fr(Br(e))])},v=e=>{l(t=>t.length<=1?t:t.filter(t=>t.key!==e))};return H(`div`,{className:`flex flex-col gap-3`,children:[H(`div`,{className:`flex flex-col gap-2`,children:[q(`span`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Bindings`}),c.map((r,i)=>q(Vr,{row:r,ordinal:i+1,devices:e,siblings:t,targetDeviceId:n,nameError:h(r),onPatch:e=>g(r.key,e),onRemove:()=>v(r.key),canRemove:c.length>1},r.key)),q(`button`,{type:`button`,onClick:_,disabled:c.length>=32,className:`self-start px-2 py-1 rounded-md text-[11px] font-medium border border-border text-foreground-subtle hover:bg-surface-hover disabled:opacity-50`,children:`+ Add binding`})]}),H(`div`,{children:[q(`label`,{htmlFor:`link-expr-input`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Expression`}),q(`textarea`,{id:`link-expr-input`,value:o,rows:2,spellCheck:!1,placeholder:`e.g. clamp(avg(a, b) + 5, 0, 100)`,onChange:e=>s(e.target.value),className:`${jr} font-mono resize-y`}),H(`p`,{className:`mt-1 text-[10px] text-foreground-subtle/60`,children:[`Functions: `,Mr]}),f&&q(`p`,{className:`mt-1 text-[10px] text-danger`,children:f}),f===null&&d&&q(`p`,{className:`mt-1 text-[10px] text-danger`,children:d})]}),H(`div`,{className:`rounded-md border border-border bg-surface/50 px-2 py-1.5`,children:[q(`span`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle/60`,children:`Preview`}),` `,p===null?q(`span`,{className:`text-[11px] text-foreground-subtle/60`,children:`enter an expression`}):p.ok?q(`span`,{className:`font-mono text-[11px] text-foreground`,children:JSON.stringify(p.value)}):q(`span`,{className:`font-mono text-[11px] text-danger`,children:p.error})]})]})}function Br(e){let t=new Set(e.map(e=>e.name.trim()));for(let e=0;e<26;e++){let n=String.fromCharCode(97+e);if(!t.has(n))return n}return`b${e.length+1}`}function Vr({row:e,ordinal:t,devices:n,siblings:r,targetDeviceId:i,nameError:a,onPatch:o,onRemove:s,canRemove:c}){let l=e.search.trim().toLowerCase(),u=n.filter(e=>e.id===i?!1:l===``?!0:e.name.toLowerCase().includes(l)||e.stableId.toLowerCase().includes(l)||String(e.id).includes(l)),d=e.mode===`global`?u:r;return H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border/60 p-2`,children:[H(`div`,{className:`flex items-center gap-2`,children:[q(`input`,{type:`text`,"aria-label":`binding ${t} name`,value:e.name,placeholder:`name`,onChange:e=>o({name:e.target.value}),className:`${jr} max-w-[8rem] font-mono`}),H(`select`,{"aria-label":`binding ${t} mode`,value:e.mode,onChange:e=>{let t=e.target.value;(t===`sibling`||t===`global`||t===`literal`)&&o({mode:t,sourceId:null,cap:``,fieldPath:``,search:``})},className:`${jr} max-w-[9rem]`,children:[q(`option`,{value:`sibling`,children:`Sibling`}),q(`option`,{value:`global`,children:`Any device`}),q(`option`,{value:`literal`,children:`Literal`})]}),c&&q(`button`,{type:`button`,"aria-label":`remove binding ${t}`,onClick:s,className:`px-2 py-1 rounded-md text-[11px] text-danger hover:bg-surface-hover`,children:`✕`})]}),a&&H(`span`,{className:`text-[10px] text-danger`,children:[`name: `,a]}),e.mode===`literal`?H(`div`,{className:`flex items-center gap-2`,children:[H(`select`,{"aria-label":`binding ${t} literal type`,value:e.literalType,onChange:e=>{let t=e.target.value;(t===`string`||t===`number`||t===`boolean`||t===`null`)&&o({literalType:t,literalText:t===`boolean`?`true`:``})},className:`${jr} max-w-[7rem]`,children:[q(`option`,{value:`string`,children:`string`}),q(`option`,{value:`number`,children:`number`}),q(`option`,{value:`boolean`,children:`boolean`}),q(`option`,{value:`null`,children:`null`})]}),e.literalType!==`null`&&q(`input`,{type:`text`,"aria-label":`binding ${t} literal value`,value:e.literalText,placeholder:e.literalType===`number`?`e.g. 42`:`value`,onChange:e=>o({literalText:e.target.value}),className:jr})]}):H(W,{children:[q(Dr,{mode:e.mode,idPrefix:`binding-${t}`,labelPrefix:`Binding`,pickerDevices:d,value:{sourceId:e.sourceId,cap:e.cap,fieldPath:e.fieldPath},onChange:e=>o({sourceId:e.sourceId,cap:e.cap,fieldPath:e.fieldPath}),search:e.search,onSearchChange:e=>o({search:e})}),q(`input`,{type:`text`,"aria-label":`binding ${t} sample`,value:e.sampleText,placeholder:`sample value (preview only)`,onChange:e=>o({sampleText:e.target.value}),className:`${jr} text-[10px]`})]})]})}V();function Hr(e,t,n){return(n===void 0?[e,t]:[e,n,t]).map(e=>e.replace(/[^a-z0-9]/gi,`-`)).join(`-`)}function Ur(e,t,n){let r=`${t}-${e}`;return n.find(e=>e.stableId===r)?.id??null}function Wr(e,t){return t.find(t=>t.stableId===e)?.id??null}function Gr(e){return e==null?`sibling`:e.source.kind===`literal`?`literal`:e.source.kind===`global`?`global`:e.source.kind===`expression`?`expression`:`sibling`}function Kr(e){return e==null||e.source.kind!==`literal`?`string`:kr(e.source.value)}function qr(e){return e==null||e.source.kind!==`literal`?``:Ar(e.source.value)}function Jr({deviceId:e,parentDeviceId:t,deviceStableId:n,initial:r,onSave:i,onCancel:a}){let{data:o}=l({}),s=o??[],c=t==null?n:s.find(e=>e.id===t)?.stableId??n,u=s.filter(n=>n.parentDeviceId===t&&n.id!==e),{data:d}=ne({deviceId:e,includeSynthesizable:!0}),f=d?.caps??[],p=r!=null&&(r.source.kind===void 0||r.source.kind===`field`)?r.source:null,m=r!=null&&r.source.kind===`global`?r.source:null,h=r!=null&&r.source.kind===`expression`?r.source:null,g=p==null?m==null?null:Wr(m.sourceStableId,s):Ur(p.sourceKey,c,s),[_,v]=K(Gr(r)),[y,b]=K(r?.target.cap??``),[x,S]=K(r?.target.fieldPath??``),[C,w]=K(r?.target.itemKey??``),[T,E]=K(g),[D,ee]=K((p??m)?.cap??``),[O,k]=K((p??m)?.fieldPath??``),[te,A]=K(void 0),[j,re]=K(``),[ie,M]=K(Kr(r)),[N,P]=K(qr(r)),[ae,oe]=K(h),[se,ce]=K(r?.transform);J(()=>{if((p??m)==null||T!==null||s.length===0)return;let e=p==null?m==null?null:Wr(m.sourceStableId,s):Ur(p.sourceKey,c,s);e!==null&&E(e)},[p,m,T,s,c]);let le=f.find(e=>e.cap===y)?.fields??[],F=le.find(e=>e.path===x),ue=F?.item===!0,de=j.trim().toLowerCase(),fe=s.filter(t=>t.id===e?!1:de===``?!0:t.name.toLowerCase().includes(de)||t.stableId.toLowerCase().includes(de)||String(t.id).includes(de)),pe=_===`global`?fe:u,me=e=>{b(e),S(``),w(``)},I=e=>{e!==`sibling`&&e!==`global`&&e!==`literal`&&e!==`expression`||(v(e),E(null),ee(``),k(``),A(void 0),re(``))},he=Or(ie,N),ge=_===`literal`?he!==null:_===`expression`?ae!==null:T!=null&&D!==``&&O!==``,_e=y!==``&&x!==``&&(!ue||C.trim()!==``)&&ge,ve=()=>{if(_===`literal`)return he===null?null:{kind:`literal`,value:he.value};if(_===`expression`)return ae;let e=s.find(e=>e.id===T);if(!e||D===``||O===``)return null;if(_===`global`)return{kind:`global`,sourceStableId:e.stableId,cap:D,fieldPath:O};let t=`${c}-`;return{sourceKey:e.stableId.startsWith(t)?e.stableId.slice(t.length):``,cap:D,fieldPath:O}},ye=()=>{if(!_e)return;let e=ve();if(e===null)return;let t=ue?C.trim():void 0;i({id:r?.id??Hr(y,x,t),source:e,target:{cap:y,fieldPath:x,...t===void 0?{}:{itemKey:t}},...se==null?{}:{transform:se}})},L=`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 H(`div`,{className:`flex flex-col gap-4 p-3`,children:[H(`fieldset`,{className:`flex flex-col gap-3`,children:[q(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Target (this device)`}),H(`div`,{children:[q(`label`,{htmlFor:`link-target-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target cap`}),H(`select`,{id:`link-target-cap`,value:y,onChange:e=>me(e.target.value),className:L,children:[q(`option`,{value:``,children:`— select a cap —`}),f.map(e=>q(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),H(`div`,{children:[q(`label`,{htmlFor:`link-target-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target field`}),H(`select`,{id:`link-target-field`,value:x,disabled:y===``,onChange:e=>S(e.target.value),className:L,children:[q(`option`,{value:``,children:`— select a field —`}),le.map(e=>q(`option`,{value:e.path,children:e.item===!0?`${e.path} (per item, ${e.kind})`:`${e.path} (${e.kind})`},e.path))]})]}),ue&&H(`div`,{children:[q(`label`,{htmlFor:`link-target-item-key`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Item key`}),q(`input`,{id:`link-target-item-key`,type:`text`,value:C,placeholder:`e.g. main-brush`,onChange:e=>w(e.target.value),className:L}),q(`p`,{className:`mt-1 text-[10px] text-foreground-subtle/60`,children:`Links sharing the same item key build one item (e.g. one consumable).`})]})]}),H(`fieldset`,{className:`flex flex-col gap-3`,children:[q(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Source`}),H(`div`,{children:[q(`label`,{htmlFor:`link-source-mode`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source mode`}),H(`select`,{id:`link-source-mode`,value:_,onChange:e=>I(e.target.value),className:L,children:[q(`option`,{value:`sibling`,children:`Sibling device (same container)`}),q(`option`,{value:`global`,children:`Any device`}),q(`option`,{value:`literal`,children:`Literal constant`}),q(`option`,{value:`expression`,children:`Expression (computed)`})]})]}),_===`literal`&&H(W,{children:[H(`div`,{children:[q(`label`,{htmlFor:`link-literal-type`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal type`}),H(`select`,{id:`link-literal-type`,value:ie,onChange:e=>{let t=e.target.value;(t===`string`||t===`number`||t===`boolean`||t===`null`)&&(M(t),t===`boolean`&&P(`true`),t===`null`&&P(``))},className:L,children:[q(`option`,{value:`string`,children:`string`}),q(`option`,{value:`number`,children:`number`}),q(`option`,{value:`boolean`,children:`boolean`}),q(`option`,{value:`null`,children:`null`})]})]}),ie!==`null`&&(ie===`boolean`?H(`div`,{children:[q(`label`,{htmlFor:`link-literal-value`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal value`}),H(`select`,{id:`link-literal-value`,value:N,onChange:e=>P(e.target.value),className:L,children:[q(`option`,{value:`true`,children:`true`}),q(`option`,{value:`false`,children:`false`})]})]}):H(`div`,{children:[q(`label`,{htmlFor:`link-literal-value`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal value`}),q(`input`,{id:`link-literal-value`,type:`text`,value:N,placeholder:ie===`number`?`e.g. 42`:`e.g. main-brush`,onChange:e=>P(e.target.value),className:L})]}))]}),_===`expression`&&q(zr,{devices:s,siblings:u,targetDeviceId:e,containerStableId:c,initial:h,onChange:oe}),(_===`sibling`||_===`global`)&&q(Dr,{mode:_,idPrefix:`link-source`,labelPrefix:`Source`,pickerDevices:pe,value:{sourceId:T,cap:D,fieldPath:O},onChange:(e,t)=>{E(e.sourceId),ee(e.cap),k(e.fieldPath),A(t)},search:j,onSearchChange:re})]}),q(Tr,{value:se,onChange:ce,sourceField:_===`literal`||_===`expression`?void 0:te,targetKind:F?.kind}),H(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-border`,children:[q(`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`}),q(`button`,{type:`button`,disabled:!_e,onClick:ye,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`})]})]})}V();function Yr({deviceId:e}){let t=X(),n=G(),r=Number.isFinite(e),{data:i,isLoading:a}=A({deviceId:e},{enabled:r,refetchInterval:1e4}),{data:o}=ne({deviceId:e,includeSynthesizable:!0},{enabled:r}),s=new Map;for(let e of o?.caps??[])e.itemArray&&s.set(e.cap,e.itemArray);let c=S({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),l=i?.deviceLinks??[],u=typeof i?.parentDeviceId==`number`?i.parentDeviceId:null,d=typeof i?.stableId==`string`?i.stableId:``,[f,p]=K(null),m=t=>{c.mutate({deviceId:e,deviceLinks:l.filter(e=>e.id!==t)})};return a?q(`div`,{className:`p-4`,children:q(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})}):f===null?H(`div`,{className:`flex flex-col gap-3 p-1`,children:[H(`div`,{className:`flex items-center justify-between`,children:[q(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Wiring`}),H(`button`,{type:`button`,onClick:()=>p(`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:[q(gt,{className:`h-3 w-3`}),`Add link`]})]}),l.length===0?H(`div`,{className:`flex flex-col items-center justify-center gap-2 py-8 text-foreground-subtle`,children:[q(Zt,{className:`h-8 w-8 opacity-30`}),q(`p`,{className:`text-xs`,children:`No links yet.`}),q(`p`,{className:`text-[10px] opacity-60`,children:`Cross-device field wirings will appear here once authored.`})]}):q(`div`,{className:`flex flex-col divide-y divide-border rounded-lg border border-border overflow-hidden`,children:l.map(n=>q(Zr,{deviceId:e,link:n,itemArray:s.get(n.target.cap),trpcClient:t.trpcClient,onDelete:()=>m(n.id),onEdit:()=>p(n),isPending:c.isPending},n.id))})]}):H(`div`,{className:`flex flex-col gap-3 p-1`,children:[q(`div`,{className:`flex items-center justify-between`,children:q(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:f===`new`?`Add link`:`Edit link`})}),q(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:q(Jr,{deviceId:e,parentDeviceId:u,deviceStableId:d,initial:f===`new`?null:f,onSave:t=>{let n=l.some(e=>e.id===t.id)?l.map(e=>e.id===t.id?t:e):[...l,t];c.mutate({deviceId:e,deviceLinks:n}),p(null)},onCancel:()=>{p(null)}})})]})}function Xr(e,t,n,r){let i=rt(e,t.path);if(!Array.isArray(i))return;let a=i.find(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Reflect.get(e,t.keyField)===n);return a===void 0?void 0:rt(a,r)}function Zr({deviceId:e,link:t,itemArray:n,trpcClient:r,onDelete:i,onEdit:a,isPending:o}){let s=De(r,e,t.target.cap),c=t.target.itemKey,l=s===void 0?void 0:c!==void 0&&n!==void 0?Xr(s,n,c,t.target.fieldPath):c===void 0?rt(s,t.target.fieldPath):void 0,u=l==null?`—`:String(l);return H(`div`,{className:`flex items-center gap-3 px-3 py-2.5 bg-surface hover:bg-surface-hover transition-colors`,children:[q(Qt,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle/40`}),H(`div`,{className:`min-w-0 flex-1 flex flex-col gap-0.5`,children:[H(`div`,{className:`flex items-baseline gap-1 flex-wrap`,children:[q(`span`,{className:`font-mono text-[11px] font-medium text-foreground`,children:t.target.cap}),q(`span`,{className:`text-[10px] text-foreground-subtle/60`,children:`.`}),q(`span`,{className:`font-mono text-[11px] text-foreground-subtle`,children:t.target.fieldPath}),c!==void 0&&q(`span`,{className:`rounded bg-surface-hover px-1 py-px font-mono text-[9px] text-foreground-subtle`,title:`Item key — links sharing it build one array item`,children:c})]}),H(`div`,{className:`flex items-baseline gap-1 flex-wrap text-[10px] text-foreground-subtle/70`,children:[q(`span`,{children:`←`}),t.source.kind===`literal`?H(`span`,{className:`font-mono`,children:[`literal: `,String(t.source.value)]}):t.source.kind===`expression`?H(W,{children:[H(`span`,{className:`font-mono`,title:t.source.expr,children:[`ƒ`,` `,t.source.expr.length>40?`${t.source.expr.slice(0,40)}…`:t.source.expr]}),H(`span`,{className:`rounded bg-surface-hover px-1 py-px font-mono text-[9px] text-foreground-subtle`,title:`Number of source bindings`,children:[Object.keys(t.source.bindings).length,` bindings`]})]}):H(W,{children:[q(`span`,{className:`font-mono`,children:t.source.kind===`global`?t.source.sourceStableId:t.source.sourceKey}),q(`span`,{className:`opacity-60`,children:`/`}),q(`span`,{className:`font-mono`,children:t.source.cap}),q(`span`,{className:`opacity-60`,children:`.`}),q(`span`,{className:`font-mono`,children:t.source.fieldPath})]})]})]}),t.transform&&q(Qr,{kind:t.transform.kind}),q(`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:u}),q(`button`,{type:`button`,"aria-label":`Edit link`,title:`Edit this link`,disabled:o,onClick:a,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`}),q(`button`,{type:`button`,"aria-label":`Delete link`,title:`Remove this link`,disabled:o,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-danger hover:border-danger/50 hover:bg-danger/5 transition-colors disabled:opacity-50`,children:`Delete`})]})}function Qr({kind:e}){return q(`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})}V();var $r=[{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 ei(e){let t=e===Y.Camera;return $r.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var ti=[{id:`logs`,icon:Ft,label:`Logs`},{id:`repl`,icon:Mt,label:`REPL`},{id:`events`,icon:Et,label:`Events`},{id:`state`,icon:Tt,label:`State`}];function ni(){let e=kt(),t=Number(e.deviceId),n=Number.isFinite(t),r=Dt(),i=G(),s=ee(),l=X(),[u,d]=Ct(),f=u.get(`tab`)??`overview`,p=u.get(`sub`),[_,v]=K(`logs`),y=`device-detail.left-col-width-px`,[b,x]=K(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(y),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),S=B(b);S.current=b;function C(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??b??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{x(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=S.current;if(e!==null)try{window.localStorage.setItem(y,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}=A({deviceId:t},{enabled:n,refetchInterval:5e3,retry:1}),{data:D}=a({deviceId:t},{enabled:n}),O=U(()=>{let e=D?.settings?.sections??[],t=D?.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(Ln)&&r.add(Pn),[...r].map(e=>e===`export`?{id:e,label:Fn,isAddonContrib:!0}:{id:e,label:Ze[e]?.label??e,isAddonContrib:!0})},[D]),k=w,j=String(k?.name??e.deviceId??`Device`),re=k?.online===!0,ie=re?`online`:`offline`,M=String(k?.addonId??`rtsp`),N=k?.features??[],P=k?.type,ae=P===Y.Camera,{data:oe}=Vt(n?t:0),se=P===Y.Container,ce=U(()=>(oe??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[oe]),F=U(()=>se?fe(ce,typeof k?.linkDeviceId==`number`?k.linkDeviceId:null,typeof k?.primaryChildEntityId==`string`?k.primaryChildEntityId:null)?.id??null:null,[se,ce,k?.linkDeviceId,k?.primaryChildEntityId]),{data:ue}=a({deviceId:F??0},{enabled:F!==null}),de=U(()=>{if(F===null)return[];let e=ue?.settings?.sections??[],t=ue?.live?.sections??[],n=new Set;for(let r of[...e,...t])r.location===`top-tab`&&r.tab&&n.add(r.tab);return[...n].map(e=>({id:e,label:Ze[e]?.label??e,isAddonContrib:!0,childDeviceId:F}))},[F,ue]),pe=typeof k?.parentDeviceId==`number`?k.parentDeviceId:null,{data:me}=A({deviceId:pe??0},{enabled:pe!==null}),I=ge(),he=k?.disabled!==!0,{data:_e}=ne({deviceId:t},{enabled:n}),ve=(_e?.caps.length??0)>0,L=U(()=>{let e=new Set,t=[];for(let n of[...ei(P),...O,...de])e.has(n.id)||(e.add(n.id),!(n.id===`wiring`&&!ve)&&t.push(n));return t},[P,O,de,ve]),Se=U(()=>L.some(e=>e.id===f)?f:`overview`,[L,f]),Te=z(e=>{d(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[d]),Ee=z(e=>{d(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[d]),De=(oe??[]).length>0,Oe=U(()=>ti.filter(({featureGate:e})=>!e||N.includes(e)),[N]),{data:R}=be({addonId:M},{enabled:!!M&&M!==`rtsp`}),Ae=Ce({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]}),r(R?.id?`/integrations/${R.id}`:`/integrations`)}}),Ne=Be({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Pe=Me({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=Ve(),Ie=le({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=N.includes(et.Rebootable),Re=N.includes(et.BatteryOperated),ze=h(l.trpcClient,Re&&n?t:null),[He,Ue]=K(!1),We=ot(l.trpcClient,n?t:null),Ge=async()=>{if(!(He||!We)){Ue(!0);try{await We.snapshot?.invalidateCache({});let e=await We.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{Ue(!1)}}},Ke=Ne.isPending||Pe.isPending,{data:V}=ye({deviceId:t},{enabled:n,refetchInterval:1e4}),W=V?.agentNodeId??null,qe=typeof W==`string`&&W.length>0&&!W.startsWith(`addon:`)?W:void 0,{data:J}=te({deviceId:t,...qe?{nodeId:qe}:{}},{enabled:n,refetchInterval:3e3,retry:!1}),{data:Je}=m({deviceId:t},{enabled:n,refetchInterval:3e3,retry:!1}),Ye=Je?.level?.dbfs??null;function Xe(){if(!n)return null;switch(Se){case`overview`:return q(vr,{device:k??{}});case`config`:return q(Zn,{deviceId:t,activeSubTab:p,onSubTabChange:Ee});case`pipeline`:return q(tr,{deviceId:t,refreshToken:0});case`bindings`:return q(On,{deviceId:t});case`wiring`:return q(Yr,{deviceId:t});default:{let e=Se,n=O.some(t=>t.id===e),r=de.find(t=>t.id===e);if(!n&&r===void 0)return null;let i=r?.childDeviceId??t;if(e===`export`)return q(Xn,{deviceId:t,sectionFilter:Ln,activeSubTab:p,onSubTabChange:Ee});let a=q(Xn,{deviceId:i,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:p,onSubTabChange:Ee});return r!==void 0&&i!==t?q(xe,{deviceId:i,children:a}):a}}}return n?T?H(`div`,{className:`flex flex-col h-full`,children:[H(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[q(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),q(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),q(`div`,{className:`flex-1 p-6`,children:q(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):E||!w?H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[q(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),H(`p`,{className:`text-xs`,children:[`No device with ID`,` `,H(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,t]})]}),q(`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`})]}):H(`div`,{className:`absolute inset-0 flex flex-col overflow-hidden`,children:[H(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[q(`div`,{className:`mb-2`,children:q(je,{items:[{label:`Integrations`,onClick:()=>r(`/integrations`)},{label:R?.name??M,onClick:()=>R?.id&&r(`/integrations/${R.id}`)},{label:j}]})}),H(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[q(mt,{type:M,size:`lg`}),H(`div`,{className:`min-w-0 flex-1`,children:[H(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[q(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:j}),q(Ut,{status:ie}),Re&&q(g,{status:ze,variant:`full`})]}),pe!==null&&me&&H(`button`,{type:`button`,onClick:()=>r(`/devices/${pe}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${me.name}`,children:[q(`span`,{children:`↑`}),q(`span`,{className:`truncate`,children:String(me.name??`Device #${pe}`)})]}),q(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:N.length>0&&q(dt,{capabilities:N})})]}),J&&q(`div`,{className:`hidden lg:flex`,children:q(ri,{metrics:J,dbfs:Ye})}),H(`div`,{className:`flex items-center gap-1 shrink-0`,children:[H(`button`,{onClick:async()=>{he?await s({title:`Disable "${j}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Pe.mutate({deviceId:t}):Ne.mutate({deviceId:t})},disabled:Ke,title:he?`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 ${he?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[q(tn,{className:`h-3.5 w-3.5`}),q(`span`,{className:`hidden sm:inline`,children:Ke?`Updating…`:he?`Enabled`:`Disabled`})]}),q(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),q(we,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:wt,disabled:He,onClick:()=>{Ge()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:vt,hidden:!Le,disabled:Fe.isPending,danger:!0,onClick:async()=>{await s({title:`Reboot "${j}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Fe.mutate({deviceId:t})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${R?.name??M}.`,icon:_t,disabled:Ie.isPending,danger:!0,onClick:async()=>{await s({title:`Restart "${R?.name??M}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${j}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&Ie.mutate({addonId:M})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:Lt,separatorBefore:!0,disabled:Ae.isPending,danger:!0,onClick:async()=>{await s({title:`Delete "${j}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Ae.mutate({deviceId:t})}}]})]})]})]}),q(xe,{deviceId:t,device:k??void 0,children:q(o,{children:q(c,{children:q(lt,{children:q(ke,{children:H(`main`,{className:I?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[H(`div`,{className:I?`flex flex-col bg-surface`:`${b===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!I&&b!==null?{width:`${String(b)}px`}:void 0,children:[q(`div`,{className:ae?`flex-shrink-0 border-b border-border-subtle bg-black`:I?`flex-shrink-0 border-b border-border-subtle bg-surface`:`max-h-[55%] shrink-0 overflow-y-auto border-b border-border-subtle bg-surface`,children:ae?q(Cn,{deviceId:t,intercomAvailable:N.includes(et.TwoWayAudio)}):q(mn,{deviceId:t,deviceName:j,deviceType:P??`unknown`,provider:M,isOnline:re,features:N})}),H(`div`,{className:I?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[q(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:q(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:Oe.map(({id:e,label:t,icon:n})=>H(`button`,{onClick:()=>v(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${_===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[q(n,{className:`h-3 w-3`}),t]},e))})}),H(`div`,{className:I?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[_===`logs`&&q(wn,{deviceId:t,containerDeviceId:P===`container`?t:void 0}),_===`repl`&&q(Tn,{deviceId:t}),_===`events`&&q(En,{deviceId:t}),_===`state`&&q(Dn,{deviceId:t})]})]})]}),!I&&q(`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:q(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),H(`div`,{className:I?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[q(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:q(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:L.map(e=>{let t=Se===e.id;return H(`button`,{onClick:()=>Te(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&&q(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),H(`div`,{className:I?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[Se===`overview`&&De&&q(rn,{parentDeviceId:t}),Xe()]})]})]})})})})})})]}):H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[q(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),H(`p`,{className:`text-xs`,children:[`The URL segment`,` `,q(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:e.deviceId}),` `,`is not a number.`]}),q(`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 ri({metrics:e,dbfs:t}){let n=f(e.phase??`idle`);return H(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[H(`div`,{className:`flex items-center gap-1.5`,children:[q(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),q(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),q(`div`,{className:`h-3 w-px bg-border`}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[q(xt,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),q(`span`,{children:`fps`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[q(Pt,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),q(`span`,{children:`ms`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[q(nn,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),q(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&H(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{ni as DeviceDetailPage};
@@ -1 +1 @@
1
- import{En as e,V as t,jn as n,or as r,pn as i,vn as a}from"./src-ypI5eXyJ.js";import{I as o,Q as s,S as c,W 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-DTufy7Ue.js";import{p as f}from"./player-overlays-CpxC1ZVd.js";import{t as p}from"./ProviderIcon-BHDS5Z0G.js";import{I as m,U as h,o as g,t as _}from"./index-CB8rHudv.js";import{t as v}from"./AdminPage-BwmGKnRf.js";import{t as y}from"./useEventInvalidation-CJ7VfCpl.js";s();function b(){let{t:s}=_(),b=h(),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}=e({}),{data:w}=r(void 0),T=n({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),E=i({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),D=a({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),O=l(()=>C??[],[C]),{activeDevices:k,orphanDevices:A}=l(()=>{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=l(()=>{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=l(()=>(w??[]).map(e=>({id:e.addonId,name:e.name??e.addonId,icon:d(p,{type:e.addonId,size:`sm`})})),[w]),P=o(e=>d(p,{type:e,size:`sm`}),[]),F=o(e=>b(`/devices/${String(e)}`),[b]);return c(v,{icon:m,title:s(`nav.devices`,`Devices`),children:[d(t,{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&&c(`div`,{className:`mt-6 space-y-2`,children:[c(`div`,{className:`flex items-baseline gap-2`,children:[d(g,{className:`h-3.5 w-3.5 text-warning shrink-0`}),d(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Orphan devices`}),c(`span`,{className:`text-[10px] text-foreground-subtle`,children:[A.length,` device`,A.length===1?``:`s`,` pointing at integrations no longer registered`]})]}),c(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 p-2`,children:[d(`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."}),d(t,{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{En as e,V as t,jn as n,or as r,pn as i,vn as a}from"./src-BvxPxXyx.js";import{I as o,Q as s,S as c,W 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-DTufy7Ue.js";import{p as f}from"./player-overlays-Bhh-T-qH.js";import{t as p}from"./ProviderIcon-X1LLmqTA.js";import{I as m,U as h,o as g,t as _}from"./index-cObQUDCu.js";import{t as v}from"./AdminPage-BwmGKnRf.js";import{t as y}from"./useEventInvalidation-OVOcl54D.js";s();function b(){let{t:s}=_(),b=h(),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}=e({}),{data:w}=r(void 0),T=n({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),E=i({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),D=a({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),O=l(()=>C??[],[C]),{activeDevices:k,orphanDevices:A}=l(()=>{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=l(()=>{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=l(()=>(w??[]).map(e=>({id:e.addonId,name:e.name??e.addonId,icon:d(p,{type:e.addonId,size:`sm`})})),[w]),P=o(e=>d(p,{type:e,size:`sm`}),[]),F=o(e=>b(`/devices/${String(e)}`),[b]);return c(v,{icon:m,title:s(`nav.devices`,`Devices`),children:[d(t,{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&&c(`div`,{className:`mt-6 space-y-2`,children:[c(`div`,{className:`flex items-baseline gap-2`,children:[d(g,{className:`h-3.5 w-3.5 text-warning shrink-0`}),d(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Orphan devices`}),c(`span`,{className:`text-[10px] text-foreground-subtle`,children:[A.length,` device`,A.length===1?``:`s`,` pointing at integrations no longer registered`]})]}),c(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 p-2`,children:[d(`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."}),d(t,{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{I as e,b as t,i as n,ia as r}from"./src-ypI5eXyJ.js";import{Q as i,S as a,W as o,d as s,q as c,u as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{C as f,D as p,S as m,g as h,k as g,w as _}from"./schemas-CuE8EXQ7.js";import{M as v}from"./src-BB7sQJiE.js";import{d as y}from"./player-overlays-CpxC1ZVd.js";i();var b=g([_({kind:m(`adaptive`)}),_({kind:m(`profile`),profile:v})]),x=_({serverUrl:p().min(1),token:p().min(1),deviceId:f().int().nonnegative(),target:b,muted:h()});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 d(()=>{S(`error`,e)},[e]),a(`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:r,initialTarget:i,initialMuted:a}){let[s,l]=c(i),[f,p]=c(a),{handleOffer:m,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,getSessionState:y}=n(e.trpcClient,r),x=o(()=>w(s),[s]),E=o(()=>(e,t)=>m(x,e,t),[m,x]),D=o(()=>(e,t,n)=>m(n,t,e),[m]);d(()=>(window.__camstackEmbed={setMuted:e=>p(e),setTarget:e=>{let t=b.safeParse(e);t.success&&l(t.data)}},()=>{window.__camstackEmbed&&delete window.__camstackEmbed}),[]);let O=T(s);return u(`div`,{style:{position:`fixed`,inset:0,width:`100vw`,height:`100vh`,background:`#000`},children:u(t,{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 t=o(()=>E(),[]),n=o(()=>t.ok?{system:e({serverUrl:t.config.serverUrl,token:t.config.token}),queryClient:new s({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1}}})}:null,[t]);return d(()=>{if(n)return()=>{n.system.close()}},[n]),t.ok?n?u(y,{system:n.system,children:u(l,{client:n.queryClient,children:u(r.Provider,{client:n.system.trpcClient,queryClient:n.queryClient,children:u(O,{system:n.system,deviceId:t.config.deviceId,initialTarget:t.config.target,initialMuted:t.config.muted})})})}):u(D,{message:`Failed to initialise the embed player`}):u(D,{message:t.error})}export{k as EmbedPlayerPage};
1
+ import{I as e,b as t,i as n,oa as r}from"./src-BvxPxXyx.js";import{Q as i,S as a,W as o,d as s,q as c,u as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{C as f,D as p,S as m,g as h,k as g,w as _}from"./schemas-CuE8EXQ7.js";import{M as v}from"./src-Ce30zKhx.js";import{d as y}from"./player-overlays-Bhh-T-qH.js";i();var b=g([_({kind:m(`adaptive`)}),_({kind:m(`profile`),profile:v})]),x=_({serverUrl:p().min(1),token:p().min(1),deviceId:f().int().nonnegative(),target:b,muted:h()});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 d(()=>{S(`error`,e)},[e]),a(`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:r,initialTarget:i,initialMuted:a}){let[s,l]=c(i),[f,p]=c(a),{handleOffer:m,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,getSessionState:y}=n(e.trpcClient,r),x=o(()=>w(s),[s]),E=o(()=>(e,t)=>m(x,e,t),[m,x]),D=o(()=>(e,t,n)=>m(n,t,e),[m]);d(()=>(window.__camstackEmbed={setMuted:e=>p(e),setTarget:e=>{let t=b.safeParse(e);t.success&&l(t.data)}},()=>{window.__camstackEmbed&&delete window.__camstackEmbed}),[]);let O=T(s);return u(`div`,{style:{position:`fixed`,inset:0,width:`100vw`,height:`100vh`,background:`#000`},children:u(t,{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 t=o(()=>E(),[]),n=o(()=>t.ok?{system:e({serverUrl:t.config.serverUrl,token:t.config.token}),queryClient:new s({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1}}})}:null,[t]);return d(()=>{if(n)return()=>{n.system.close()}},[n]),t.ok?n?u(y,{system:n.system,children:u(l,{client:n.queryClient,children:u(r.Provider,{client:n.system.trpcClient,queryClient:n.queryClient,children:u(O,{system:n.system,deviceId:t.config.deviceId,initialTarget:t.config.target,initialMuted:t.config.muted})})})}):u(D,{message:`Failed to initialise the embed player`}):u(D,{message:t.error})}export{k as EmbedPlayerPage};
@@ -1 +1 @@
1
- import{C as e,w as t}from"./src-ypI5eXyJ.js";import{Q as n,S as r,q 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-DTufy7Ue.js";n();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:n,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,probeResults:f,onAction:p}){let[m,h]=i(n.defaultCollapsed??!1),g=n.style===`accordion`;if(n.fields.reduce((e,r)=>e+ +!!t(r,o,n.fields),0)===0)return null;let _=n.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=n.fields.length===1&&n.fields[0]?.type===`widget`?n.fields[0]:void 0;return r(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},children:[!(y!==void 0||!n.title&&!n.description)&&r(`div`,{className:[`flex items-center justify-between mb-2`,g?`cursor-pointer`:``].join(` `),onClick:g?()=>h(e=>!e):void 0,children:[r(`div`,{children:[n.title&&a(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:s(n.title,u)}),n.description&&a(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:s(n.description,u)})]}),g&&a(`span`,{className:`text-foreground-subtle text-xs ml-2`,children:m?`▸`:`▾`})]}),!m&&(y===void 0?a(`div`,{className:`grid ${v} gap-x-3 gap-y-2.5`,children:n.fields.map(t=>a(e,{field:t,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,externalProbe:f?.[t.key],allFields:n.fields,onAction:p},t.key))}):a(e,{field:y,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,externalProbe:f?.[y.key],allFields:n.fields,onAction:p},y.key))]})}function l({schema:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:o,probeResults:s,onClearProbe:l,onAction:u}){let d=(e,r)=>{n({...t,[e]:r}),l?.(e)};return a(`div`,{className:`space-y-4`,children:e.sections.map((e,n)=>a(c,{section:e,values:t,onChange:d,disabled:r,translationFn:i,onTestField:o,probeResults:s,onAction:u},`${e.id}-${n}`))})}export{l as t};
1
+ import{C as e,w as t}from"./src-BvxPxXyx.js";import{Q as n,S as r,q 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-DTufy7Ue.js";n();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:n,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,probeResults:f,onAction:p}){let[m,h]=i(n.defaultCollapsed??!1),g=n.style===`accordion`;if(n.fields.reduce((e,r)=>e+ +!!t(r,o,n.fields),0)===0)return null;let _=n.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=n.fields.length===1&&n.fields[0]?.type===`widget`?n.fields[0]:void 0;return r(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},children:[!(y!==void 0||!n.title&&!n.description)&&r(`div`,{className:[`flex items-center justify-between mb-2`,g?`cursor-pointer`:``].join(` `),onClick:g?()=>h(e=>!e):void 0,children:[r(`div`,{children:[n.title&&a(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:s(n.title,u)}),n.description&&a(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:s(n.description,u)})]}),g&&a(`span`,{className:`text-foreground-subtle text-xs ml-2`,children:m?`▸`:`▾`})]}),!m&&(y===void 0?a(`div`,{className:`grid ${v} gap-x-3 gap-y-2.5`,children:n.fields.map(t=>a(e,{field:t,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,externalProbe:f?.[t.key],allFields:n.fields,onAction:p},t.key))}):a(e,{field:y,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,externalProbe:f?.[y.key],allFields:n.fields,onAction:p},y.key))]})}function l({schema:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:o,probeResults:s,onClearProbe:l,onAction:u}){let d=(e,r)=>{n({...t,[e]:r}),l?.(e)};return a(`div`,{className:`space-y-4`,children:e.sections.map((e,n)=>a(c,{section:e,values:t,onChange:d,disabled:r,translationFn:i,onTestField:o,probeResults:s,onAction:u},`${e.id}-${n}`))})}export{l as t};