@camstack/addon-admin-ui 1.1.55 → 1.1.56

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 (99) hide show
  1. package/dist/assets/{AddLocationWizard-DKMFqTvZ.js → AddLocationWizard-BS_sw-yb.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-B7r7RnCS.js → AddonCollectionPage-B83rtm_P.js} +1 -1
  3. package/dist/assets/Addons-CVIk8bKA.js +1 -0
  4. package/dist/assets/{AdminTabs-DsU1olLw.js → AdminTabs-CGgxIyjn.js} +1 -1
  5. package/dist/assets/{AiProfiles-DbcBYG7x.js → AiProfiles-BiwHduY5.js} +1 -1
  6. package/dist/assets/{BrokerForm-Bof3-RsO.js → BrokerForm-Ce54Djz4.js} +1 -1
  7. package/dist/assets/{Capabilities-CpM6R2iG.js → Capabilities-B5IxdwuN.js} +1 -1
  8. package/dist/assets/{CapabilityBadges-CrG_Gpq2.js → CapabilityBadges-3XeZhtSI.js} +1 -1
  9. package/dist/assets/Cluster-D8rUWJST.js +1 -0
  10. package/dist/assets/ClusterRecordingTab-DX9aLngj.js +1 -0
  11. package/dist/assets/{Dashboard-BLwnF4KK.js → Dashboard-BblDjLKn.js} +1 -1
  12. package/dist/assets/Data-CdLaMkIJ.js +1 -0
  13. package/dist/assets/DetectionIntelligence-D6i0W6kk.js +1 -0
  14. package/dist/assets/DeviceDetail-BYfQe_30.js +2 -0
  15. package/dist/assets/{Devices-1MpXBj6n.js → Devices-x_UPdIGK.js} +1 -1
  16. package/dist/assets/EmbedPlayerPage-Buxyv9Ar.js +1 -0
  17. package/dist/assets/Events-CDDnJ01Z.js +1 -0
  18. package/dist/assets/{FormBuilder-1_hLh6UD.js → FormBuilder-iTpxBqBc.js} +1 -1
  19. package/dist/assets/{Identity-DIIHY4_I.js → Identity-DH41lSfX.js} +1 -1
  20. package/dist/assets/IntegrationDetail-CR5AD5vO.js +1 -0
  21. package/dist/assets/{Integrations-uUU6I8AA.js → Integrations-BDJ1xxLY.js} +1 -1
  22. package/dist/assets/{Integrations-D2UQlymQ.js → Integrations-CV1KBLOI.js} +1 -1
  23. package/dist/assets/{Logs-DklB9pQr.js → Logs-ErbjBqie.js} +1 -1
  24. package/dist/assets/{MotionZonesSettings-Cv4ArwMh.js → MotionZonesSettings-BMPiTO3l.js} +1 -1
  25. package/dist/assets/{MyAccess-DreWB3nL.js → MyAccess-DTt40JO0.js} +1 -1
  26. package/dist/assets/Network-CyPbysr8.js +1 -0
  27. package/dist/assets/{NodeAddonsSettingsPanel-adQJWpFA.js → NodeAddonsSettingsPanel-CFXh9ESA.js} +1 -1
  28. package/dist/assets/{NotificationTargets-BqY-ixcT.js → NotificationTargets-Dgs05HjS.js} +1 -1
  29. package/dist/assets/Pipeline-Dsx-nB1p.js +1 -0
  30. package/dist/assets/{Plates-BDN77UjR.js → Plates-B_BVouJR.js} +1 -1
  31. package/dist/assets/{PrivacyMaskSettings-DtvQVzUm.js → PrivacyMaskSettings-DSSEqXHi.js} +1 -1
  32. package/dist/assets/{ProviderIcon-BvqTmUAe.js → ProviderIcon-BeZnXEB7.js} +1 -1
  33. package/dist/assets/Recordings-H8TXnxuf.js +1 -0
  34. package/dist/assets/ScanNetworkModal-C_pd8W_5.js +1 -0
  35. package/dist/assets/{Settings-Bal6O--f.js → Settings-Cg4clEYW.js} +1 -1
  36. package/dist/assets/{Showroom-CRdx2BE1.js → Showroom-DQuD1mwE.js} +1 -1
  37. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-ByenDxWa.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DqSIGxiA.js} +1 -1
  38. package/dist/assets/{build-cluster-graph-DGTSGb1I.js → build-cluster-graph-D36_rlRB.js} +1 -1
  39. package/dist/assets/circle-check-big-DOCODmhZ.js +1 -0
  40. package/dist/assets/clock-D2H-Andr.js +1 -0
  41. package/dist/assets/{schemas-DSTjX9zr.js → compat-CbwIzIXq.js} +1 -1
  42. package/dist/assets/{copy-BFZ5D4BJ.js → copy-DAnlpNmN.js} +1 -1
  43. package/dist/assets/{debounced-invalidate-B_KsAVGD.js → debounced-invalidate-DkqNPsSh.js} +1 -1
  44. package/dist/assets/{dist-CqgNHN-E.js → dist-Ck-SkmF_.js} +1 -1
  45. package/dist/assets/dist-DZmXEoJH.js +7 -0
  46. package/dist/assets/{download-5vnInJfp.js → download-CTO2YqfN.js} +1 -1
  47. package/dist/assets/{face-bbox-VcgOLkvN.js → face-bbox-Ctmu8UoI.js} +1 -1
  48. package/dist/assets/{hostInit-BKkxJ9TG.js → hostInit-DRnXHdHY.js} +1 -1
  49. package/dist/assets/{index-Cmln2hC6.css → index-9438rY3p.css} +1 -1
  50. package/dist/assets/index-BVO5AjpN.js +4 -0
  51. package/dist/assets/{key-round-76xRX3g6.js → key-round-DY-W0ctm.js} +1 -1
  52. package/dist/assets/{mf-entry-bootstrap-0-4ee9f7b7.js → mf-entry-bootstrap-0-64545043.js} +2 -2
  53. package/dist/assets/{pencil-Gs6QSg5F.js → pencil-fohpLhWe.js} +1 -1
  54. package/dist/assets/{player-overlays-DArwlTAt.js → player-overlays-CDSEY_-X.js} +1 -1
  55. package/dist/assets/plus-CWmuK222.js +1 -0
  56. package/dist/assets/{radio-B4tiKZeo.js → radio-CCbXLtig.js} +1 -1
  57. package/dist/assets/{refresh-cw-dvjeQnSv.js → refresh-cw-7j7eJ_7S.js} +1 -1
  58. package/dist/assets/remoteEntry-BB2jugOV.js +1 -0
  59. package/dist/assets/{rotate-ccw-CdvaSzic.js → rotate-ccw-DVTmMtl2.js} +1 -1
  60. package/dist/assets/rotate-cw-Dl9N7lTh.js +1 -0
  61. package/dist/assets/search-DvkKd5B0.js +1 -0
  62. package/dist/assets/{send-Cn2E54X0.js → send-CyaRM2HU.js} +1 -1
  63. package/dist/assets/{server-Cgdp4E__.js → server-BxecI2el.js} +1 -1
  64. package/dist/assets/square-CzYy8xOt.js +1 -0
  65. package/dist/assets/{square-check-big-j_FMW3NH.js → square-check-big-BsYa2Tzh.js} +1 -1
  66. package/dist/assets/src-DNVzx9ag.js +7 -0
  67. package/dist/assets/src-P2A2VEVG.js +67 -0
  68. package/dist/assets/{upload-BkHF_KcS.js → upload-CYB5H427.js} +1 -1
  69. package/dist/assets/{useDevice-CNEnCHst.js → useDevice-BskeVR-e.js} +1 -1
  70. package/dist/assets/{useEventInvalidation-zuVyeFVc.js → useEventInvalidation-DtNYz-2H.js} +1 -1
  71. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BktxCRjD.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DtiKhSUE.js} +2 -2
  72. package/dist/assets/{wifi-CaslRhpX.js → wifi-D9-_VL0_.js} +1 -1
  73. package/dist/assets/{zap-1sJN7Bvb.js → zap-WiUYl_aC.js} +1 -1
  74. package/dist/index.html +7 -7
  75. package/dist/server/addon.js +193 -5
  76. package/package.json +1 -1
  77. package/dist/assets/Addons-DjQMioo-.js +0 -1
  78. package/dist/assets/Cluster-DGYFlvd-.js +0 -1
  79. package/dist/assets/Data-mjlU3tOI.js +0 -1
  80. package/dist/assets/DetectionIntelligence-BF7VOXIn.js +0 -1
  81. package/dist/assets/DeviceDetail-DHxFHQzX.js +0 -2
  82. package/dist/assets/EmbedPlayerPage-BG2XDJsy.js +0 -1
  83. package/dist/assets/Events-cycfxpUn.js +0 -1
  84. package/dist/assets/IntegrationDetail-ByT41Y57.js +0 -1
  85. package/dist/assets/Network-WAC7AOhT.js +0 -1
  86. package/dist/assets/Pipeline-8ill1YGg.js +0 -1
  87. package/dist/assets/ScanNetworkModal-7FD7LPU3.js +0 -1
  88. package/dist/assets/circle-check-big-CxoqUJ4a.js +0 -1
  89. package/dist/assets/clock-ByHlQpk3.js +0 -1
  90. package/dist/assets/dist-DcJZn370.js +0 -7
  91. package/dist/assets/film-FBIr-9R4.js +0 -1
  92. package/dist/assets/index-B0VBnS5H.js +0 -4
  93. package/dist/assets/plus-ByGzrFiA.js +0 -1
  94. package/dist/assets/remoteEntry-BOwRpCPu.js +0 -1
  95. package/dist/assets/rotate-cw-QbVLxhT1.js +0 -1
  96. package/dist/assets/search-BWa4jUVz.js +0 -1
  97. package/dist/assets/square-B8uQd9s9.js +0 -1
  98. package/dist/assets/src-7HDrFEPH.js +0 -7
  99. package/dist/assets/src-BhRH3dxa.js +0 -67
@@ -0,0 +1 @@
1
+ import{$i as e,Bt as t,Gt as n,Ht as r,Kt as i,Qi as a,Ta as o,Ut as s,Vt as c,Wt as l,Zi as u,ja as d,qt as f,ta as p,wt as m,zt as h}from"./src-P2A2VEVG.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{H as T}from"./src-DNVzx9ag.js";import{t as E}from"./download-CTO2YqfN.js";import{i as D,n as O,r as k,t as A}from"./AddLocationWizard-BS_sw-yb.js";import{t as j}from"./plus-CWmuK222.js";import{t as M}from"./rotate-cw-Dl9N7lTh.js";import{H as ee,I as N,P,S as F,W as I,i as L,s as R}from"./index-BVO5AjpN.js";import{t as z}from"./AdminPage-BwmGKnRf.js";import{n as te}from"./authed-media-XfBD4Ma-.js";import{t as B}from"./format-size-CO9d3C3-.js";import{t as V}from"./AdminTabs-CGgxIyjn.js";var H=I(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),ne=I(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),U=I(`calendar-clock`,[[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M17.5 17.5 16 16.3V14`,key:`akvzfd`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]);_();function W(){let t=x(),n=o(),{data:r,isLoading:i,isError:s}=e({}),c=a(),l=y(()=>c.data??[],[c.data]),[d,f]=S(null),[m,h]=S(null),g=u({onSuccess:()=>{t.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),_=p({onSuccess:()=>{t.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 n({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 n({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 r??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[r]),E=i||c.isLoading,D=s||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))]}),d!==null&&C(A,{initialType:d,onClose:()=>f(null),onCreated:()=>{t.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),f(null)}}),m!==null&&C(O,{location:m,onClose:()=>h(null),onSaved:()=>{t.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),h(null)}})]})}_();var G=[[`backup`,`listDestinations`]],K=[`backup`,`listArchives`];function q({destinationId:e,restoreSupported:t,onOpenRestoreWizard:n}){let r=x(),i=o(),{data:a,isLoading:s,isError:l}=c({destinationId:e}),u=a??[],d=h({onSuccess:()=>{r.invalidateQueries({queryKey:[[...K]]}),r.invalidateQueries({queryKey:G})}}),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=await te(J(e,t.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${t.label??t.id}.tar.gz`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{m(null)}},[e]),b=y(()=>[...u].toSorted((e,t)=>t.createdAt-e.createdAt),[u]);return s?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:Y(r.createdAt)}),C(`td`,{className:`px-3 py-1.5 text-foreground`,children:r.label??C(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),C(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:r.locations.join(`, `)}),C(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:B(r.sizeBytes)}),C(`td`,{className:`px-3 py-1.5`,children:v(`div`,{className:`flex items-center justify-end gap-1`,children:[v(`button`,{onClick:()=>{_(r)},disabled: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(F,{className:`h-3 w-3 animate-spin`}):C(E,{className:`h-3 w-3`}),`Download`]}),t&&n&&v(`button`,{onClick:()=>n({destinationId:e,archiveId:r.id}),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-primary hover:bg-primary/10`,title:`Restore from this archive`,children:[C(M,{className:`h-3 w-3`}),`Restore`]}),C(`button`,{onClick:()=>{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(F,{className:`h-3 w-3 animate-spin`}):C(R,{className:`h-3 w-3`})})]})})]},r.id))})]})})}function J(e,t){return`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function Y(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}_();var X=[{id:`manual`,label:`Manual only`,cron:``},{id:`hourly`,label:`Every hour`,cron:`0 * * * *`,description:`On the hour`},{id:`every-3h`,label:`Every 3 hours`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,label:`Every 6 hours`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,label:`Daily at 03:00`,cron:`0 3 * * *`,description:`Every night at 3 AM`},{id:`weekly-sun`,label:`Weekly Sunday 03:00`,cron:`0 3 * * 0`,description:`Sunday morning at 3 AM`}];function Z(e){let t=e.trim();for(let e of X)if(e.cron===t)return e.id;return`custom`}function re({value:e,onChange:t,previewCount:n=5,disabled:r=!1}){let i=Z(e),[a,o]=S(i===`custom`);w(()=>{i!==`custom`&&o(!1)},[i]);let s=oe(e,250),c=l({cron:s,count:n},{enabled:s.trim().length>0}),u=c.data??null,d=e=>{o(!1),t(e.cron)},f=a||i===`custom`;return v(`div`,{className:`space-y-3`,children:[v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),v(`div`,{className:`flex flex-wrap gap-1.5`,children:[X.map(e=>C(`button`,{type:`button`,onClick:()=>d(e),disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!a&&i===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.description??e.label,children:e.label},e.id)),C(`button`,{type:`button`,onClick:()=>{o(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(f?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),f&&v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),C(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:r,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),v(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,C(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),C(ie,{cron:s,preview:u,loading:c.isFetching})]})}function ie({cron:e,preview:t,loading:n}){return n&&t===null?v(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[C(F,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?C(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:`No future runs match this expression.`}):v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),C(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>v(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[C(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),C(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:ae(e)})]},`${e}-${t}`))})]}):C(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??`Invalid cron expression`})}function ae(e){let t=e-Date.now();if(t<=0)return`now`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function oe(e,t){let[n,r]=S(e),i=y(()=>e,[e]);return w(()=>{let e=setTimeout(()=>r(i),t);return()=>clearTimeout(e)},[i,t]),n}_();var se=[[`backup`,`listDestinations`]];function ce({onCreateAt:e,onOpenRestoreWizard:t}){let{data:n,isLoading:i,isError:a}=r(),o=n??[],[s,c]=S(null),l=e=>{c(t=>t===e?null:e)},u=fe();return i?C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading destinations…`}):a?C(`div`,{className:`text-xs text-danger`,children:`Failed to load destinations`}):o.length===0?C(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:C(`p`,{className:`text-xs text-foreground-subtle`,children:"No `backups`-typed storage locations registered. Add one in Settings → Storage to begin."})}):C(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:v(`table`,{className:`w-full text-xs min-w-[720px]`,children:[C(`thead`,{children:v(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[C(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),C(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Destination`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-28`,children:`Retention`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-56`,children:`Schedule`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-44`,children:`Last success`}),C(`th`,{className:`text-right px-3 py-2 font-medium w-44`,children:`Actions`})]})}),C(`tbody`,{children:o.map(n=>{let r=u.get(n.id);return C(Q,{row:n,isOpen:s===n.id,onToggle:()=>l(n.id),onCreateAt:e,liveLastSuccessAt:r?.at,liveLastSuccessSizeBytes:r?.sizeBytes,...t?{onOpenRestoreWizard:t}:{}},n.id)})})]})})}function Q({row:e,isOpen:t,onToggle:n,onCreateAt:r,onOpenRestoreWizard:i,liveLastSuccessAt:a,liveLastSuccessSizeBytes:o}){let s=x(),c=f({onSuccess:()=>{s.invalidateQueries({queryKey:se})}}),[l,u]=S(String(e.retentionCount));w(()=>{u(String(e.retentionCount))},[e.retentionCount]);let[d,p]=S(!1),m=g(t=>{c.mutate({locationId:e.id,enabled:t,retentionCount:e.retentionCount,...e.label===void 0?{}:{label:e.label},...e.cron===void 0?{}:{cron:e.cron}})},[c,e.id,e.retentionCount,e.label,e.cron]),h=g(()=>{let t=Number.parseInt(l,10);if(Number.isNaN(t)||t<1){u(String(e.retentionCount));return}t!==e.retentionCount&&c.mutate({locationId:e.id,enabled:e.enabled,retentionCount:t,...e.label===void 0?{}:{label:e.label},...e.cron===void 0?{}:{cron:e.cron}})},[c,l,e.id,e.enabled,e.retentionCount,e.label,e.cron]),_=g(t=>{c.mutate({locationId:e.id,enabled:e.enabled,retentionCount:e.retentionCount,...e.label===void 0?{}:{label:e.label},cron:t},{onSuccess:()=>{p(!1)}})},[c,e.id,e.enabled,e.retentionCount,e.label]);return v(b,{children:[v(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[C(`td`,{className:`px-2 py-2`,children:C(`button`,{onClick:n,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:t?`Hide archives`:`Show archives`,children:C(t?N:P,{className:`h-3.5 w-3.5`})})}),C(`td`,{className:`px-3 py-2`,children:v(`button`,{onClick:n,className:`text-left hover:underline focus:outline-none`,title:`View archives`,children:[C(`div`,{className:`text-foreground font-medium`,children:e.displayName}),v(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[C(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5`,children:e.kind}),C(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]})}),C(`td`,{className:`px-3 py-2`,children:C(`label`,{className:`inline-flex items-center cursor-pointer`,children:C(`input`,{type:`checkbox`,className:`accent-primary`,checked:e.enabled,disabled:c.isPending,onChange:e=>m(e.target.checked)})})}),C(`td`,{className:`px-3 py-2`,children:C(`input`,{type:`number`,min:1,max:1e3,value:l,disabled:c.isPending,onChange:e=>u(e.target.value),onBlur:h,onKeyDown:t=>{t.key===`Enter`&&t.target.blur(),t.key===`Escape`&&u(String(e.retentionCount))},className:`w-16 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})}),C(`td`,{className:`px-3 py-2`,children:C(le,{cron:e.cron,nextRunAt:e.nextRunAt,onEdit:()=>p(!0),disabled:c.isPending})}),C(`td`,{className:`px-3 py-2 text-foreground-subtle`,children:(()=>{let t=pe(a,e.lastSuccessAt),n=t===a?o:e.lastSuccessSizeBytes;return t===void 0?C(`span`,{className:`italic`,children:`Never`}):C(me,{at:t,sizeBytes:n})})()}),C(`td`,{className:`px-3 py-2`,children:C(`div`,{className:`flex items-center justify-end gap-1.5`,children:e.triggerSupported&&v(`button`,{onClick:()=>r(e),className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90`,children:[C(j,{className:`h-3 w-3`}),`Create here`]})})})]}),t&&C(`tr`,{className:`border-t border-border bg-background/30`,children:C(`td`,{colSpan:7,className:`px-4 py-3`,children:C(q,{destinationId:e.id,restoreSupported:e.restoreSupported,...i?{onOpenRestoreWizard:i}:{}})})}),d&&C(de,{destinationName:e.displayName,currentCron:e.cron??``,onSave:_,onClose:()=>p(!1),saving:c.isPending,saveError:c.error instanceof Error?c.error.message:null})]})}function le({cron:e,nextRunAt:t,onEdit:n,disabled:r}){let i=typeof e==`string`&&e.trim().length>0;return v(`button`,{type:`button`,onClick:n,disabled:r,className:`group flex flex-col items-start gap-0.5 text-left rounded px-1.5 py-1 -mx-1.5 hover:bg-primary/5 disabled:opacity-50`,title:`Edit schedule`,children:[v(`div`,{className:`flex items-center gap-1.5`,children:[C(U,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),C(`span`,{className:i?`font-mono text-foreground`:`italic text-foreground-subtle`,children:i?e:`Manual`})]}),i&&t!==void 0&&v(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[`next `,ue(t)]})]})}function ue(e){let t=e-Date.now();if(t<=0)return`imminent`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function de({destinationName:e,currentCron:t,onSave:n,onClose:r,saving:i,saveError:a}){let[o,s]=S(t);return C(`tr`,{children:C(`td`,{colSpan:7,className:`p-0`,children:C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:v(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Schedule`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e]})]}),C(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,title:`Close`,children:C(L,{className:`h-4 w-4`})})]}),v(`div`,{className:`p-4`,children:[C(re,{value:o,onChange:s,disabled:i}),a!==null&&C(`div`,{className:`mt-3 rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:a})]}),v(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[C(`button`,{onClick:r,disabled:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground disabled:opacity-50`,children:`Cancel`}),C(`button`,{onClick:()=>n(o.trim()),disabled:i||o.trim()===t.trim(),className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:i?`Saving…`:`Save`})]})]})})})})}function fe(){let{map:e}=d(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:e,initialArchiveId:i,onClose:a,onScheduled:o}){let s=x(),[l,u]=S(e&&i?2:1),[d,f]=S(e),[p,m]=S(i),[h,g]=S(new Set),{data:_}=r(),b=_??[],{data:T,isLoading:E}=c({destinationId:d??``},{enabled:!!d}),D=T??[];w(()=>{if(d!==void 0)return;let e=b.filter(e=>e.restoreSupported);e.length===1&&f(e[0].id)},[d,b]);let{data:O}=t({destinationId:d??``,backupId:p??``},{enabled:!!d&&!!p}),k=y(()=>O?.locations??[],[O]);w(()=>{k.length!==0&&g(e=>e.size===0?new Set(k):e)},[k]);let A=n({onSuccess:()=>{s.invalidateQueries({queryKey:_e}),o(),a()}}),j=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},N=!!d&&!!p,P=h.size>0,I=N&&P&&!A.isPending,R=()=>{!d||!p||A.mutate({destinationId:d,backupId:p,locations:[...h]})};return C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:a,children:v(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,l,` of 3 —`,` `,l===1?`pick source`:l===2?`pick locations`:`confirm`]})]}),C(`button`,{onClick:a,className:`text-foreground-subtle hover:text-foreground`,children:C(L,{className:`h-4 w-4`})})]}),l===1&&C(ye,{destinations:b,destinationId:d,onPickDestination:e=>{f(e),m(void 0),g(new Set)},archives:D,archivesLoading:E,archiveId:p,onPickArchive:m}),l===2&&C(be,{locations:k,picked:h,onToggle:j}),l===3&&C(xe,{destinationName:b.find(e=>e.id===d)?.displayName??d??``,archive:D.find(e=>e.id===p),picked:[...h]}),v(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[C(`div`,{children:l>1&&v(`button`,{onClick:()=>u(e=>e===3?2:1),className:`inline-flex items-center gap-1 rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:[C(ee,{className:`h-3 w-3`}),`Back`]})}),v(`div`,{className:`flex items-center gap-2`,children:[C(`button`,{onClick:a,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),l<3?v(`button`,{disabled:l===1&&!N||l===2&&!P,onClick:()=>u(e=>e===1?2:3),className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[`Next`,C(ne,{className:`h-3 w-3`})]}):v(`button`,{onClick:R,disabled:!I,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[A.isPending?C(F,{className:`h-3.5 w-3.5 animate-spin`}):C(M,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function ye({destinations:e,destinationId:t,onPickDestination:n,archives:r,archivesLoading:i,archiveId:a,onPickArchive:o}){let s=e.filter(e=>e.restoreSupported);return v(`div`,{className:`p-4 space-y-3`,children:[v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),v(`select`,{value:t??``,onChange:e=>n(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:[C(`option`,{value:``,disabled:!0,children:`Select destination…`}),s.map(e=>v(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&C(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&i&&C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!i&&r.length===0&&C(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&r.length>0&&C(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:r.map(e=>{let t=a===e.id;return v(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>o(e.id),className:`accent-primary`}),v(`div`,{children:[C(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),C(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),C(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:B(e.sizeBytes)})]},e.id)})})]})]})}function be({locations:e,picked:t,onToggle:n}){return e.length===0?C(`div`,{className:`p-4`,children:C(`div`,{className:`text-xs text-foreground-subtle`,children:`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`})}):v(`div`,{className:`p-4 space-y-3`,children:[C(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),C(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>v(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[C(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>n(e),className:`accent-primary`}),C(`span`,{className:`font-mono text-foreground`,children:e}),C(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ce(e)})]},e))})]})]})}function xe({destinationName:e,archive:t,picked:n}){return v(`div`,{className:`p-4 space-y-3 text-xs`,children:[C(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-300`,children:`Restore is applied at next server boot. Active connections will drop when you restart.`}),v(`dl`,{className:`space-y-1.5`,children:[C($,{term:`Destination`,value:e}),C($,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&C($,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${B(t.sizeBytes)}`}),C($,{term:`Locations`,value:n.length>0?n.join(`, `):`— (full archive)`})]})]})}function $({term:e,value:t}){return v(`div`,{className:`flex justify-between gap-3`,children:[C(`dt`,{className:`text-foreground-subtle`,children:e}),C(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Se={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function Ce(e){return Se[e]??``}_();var we=[[`backup`,`list`]],Te=[[`backup`,`listLocations`]];function Ee(){let e=x(),t=o(),n=i({onSuccess:()=>{e.invalidateQueries({queryKey:we}),e.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),e.invalidateQueries({queryKey:[[`backup`,`listArchives`]]})}}),r=m(),[a,c]=S(null),{data:l}=s(void 0,{enabled:a!==null,retry:1}),[u,d]=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`})&&r.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:r.isPending,className:`inline-flex items-center gap-1.5 rounded bg-amber-500/20 px-2 py-1 font-medium text-amber-800 dark:text-amber-200 hover:bg-amber-500/30 disabled:opacity-50`,children:[r.isPending?C(F,{className:`h-3.5 w-3.5 animate-spin`}):C(M,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),C(ce,{onCreateAt:e=>c(e),onOpenRestoreWizard:e=>d(e)}),a&&C(De,{destination:a,locations:l,onClose:()=>c(null),onSubmit:(t,r)=>{n.mutate({destinations:[a.id],locations:t,label:r||void 0},{onSuccess:()=>{c(null),e.invalidateQueries({queryKey:Te})}})},submitting:n.isPending}),(u||f)&&C(ve,{...u?{initialDestinationId:u.destinationId,initialArchiveId:u.archiveId}:{},onClose:()=>{d(null),p(!1)},onScheduled:()=>g(!0)}),_&&C(A,{initialType:`backups`,onClose:()=>y(!1),onCreated:()=>{y(!1),e.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]})}})]})}function De({destination:e,locations:t,onClose:n,onSubmit:r,submitting:i}){let a=(t??[]).filter(e=>e.present),[o,s]=S(``),[c,l]=S(null),u=c??new Set(a.map(e=>e.name)),d=e=>{l(t=>{let n=new Set(t??a.map(e=>e.name));return n.has(e)?n.delete(e):n.add(e),n})};return C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:v(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Create Backup`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e.displayName]})]}),C(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:C(L,{className:`h-4 w-4`})})]}),v(`div`,{className:`p-4 space-y-3`,children:[v(`div`,{className:`space-y-1`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Label (optional)`}),C(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`pre-upgrade`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Include`}),v(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:[t===void 0&&v(`div`,{className:`flex items-center gap-2 px-3 py-2 text-xs text-foreground-subtle`,children:[C(F,{className:`h-3.5 w-3.5 animate-spin`}),`Calculating sizes…`]}),t!==void 0&&a.length===0&&C(`div`,{className:`px-3 py-2 text-xs text-foreground-subtle italic`,children:`Nothing to back up.`}),a.map(e=>v(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(`input`,{type:`checkbox`,checked:u.has(e.name),onChange:()=>d(e.name),className:`accent-primary`}),C(`span`,{className:`font-mono text-foreground`,children:e.name})]}),v(`div`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[B(e.sizeBytes),` · `,e.fileCount,` files`]})]},e.name))]})]})]}),v(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[C(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),v(`button`,{onClick:()=>r(Array.from(u),o.trim()),disabled:i||t===void 0||u.size===0,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[i?C(F,{className:`h-3.5 w-3.5 animate-spin`}):C(H,{className:`h-3.5 w-3.5`}),i?`Creating…`:`Create`]})]})]})})}function Oe(){return C(`div`,{className:`flex flex-col p-4`,children:C(V,{tabs:[{id:`storage`,label:`Storage`,icon:D,content:C(W,{})},{id:`backup`,label:`Backup`,icon:H,content:C(Ee,{})}]})})}export{Oe as DataPage};
@@ -0,0 +1 @@
1
+ import{$a as e,$n as t,Gn as n,Ja as r,Jn as i,Kn as a,Ma as o,Qa as s,Qn as c,Ta as l,Xa as u,Xn as d,Ya as f,Yn as p,Za as m,Zn as h,er as g,io as _,kn as v,nr as y,qn as b,ro as x,rr as S,to as C,tr as w}from"./src-P2A2VEVG.js";import{K as T,Q as E,S as D,W as O,b as k,o as A,q as j,x as M,z as N}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{H as P}from"./src-DNVzx9ag.js";import{a as F,i as I,n as L,r as R,t as z}from"./face-bbox-Ctmu8UoI.js";import{a as ee,c as te,f as B,i as V,l as ne,m as H,n as re,o as ie,p as U,r as ae,s as oe,t as se,u as ce}from"./debounced-invalidate-DkqNPsSh.js";import{t as W}from"./pencil-fohpLhWe.js";import{t as G}from"./plus-CWmuK222.js";import{t as le}from"./refresh-cw-7j7eJ_7S.js";import{t as ue}from"./square-check-big-BsYa2Tzh.js";import{t as de}from"./square-CzYy8xOt.js";import{I as K,L as q,P as fe,S as J,W as pe,h as me,i as Y,l as he,s as X}from"./index-BVO5AjpN.js";import{t as Z}from"./AdminPage-BwmGKnRf.js";import{n as Q,t as ge}from"./authed-media-XfBD4Ma-.js";var _e=pe(`undo-2`,[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]),ve=pe(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]);E();var $=[[`faceGallery`]];function ye({identityId:e}){let n=A(),{data:r,isLoading:i}=h({identityId:e}),a=t();function o(t){a.mutate({identityId:e,sampleId:t.id},{onSettled:()=>{n.invalidateQueries({queryKey:$})}})}return i?D(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[M(J,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!r||r.length===0?M(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):M(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:r.map(e=>D(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?M(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):M(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:M(ve,{className:`h-6 w-6`})}),M(`button`,{type:`button`,onClick:()=>o(e),disabled:a.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove sample`,children:M(Y,{className:`h-4 w-4 text-white`})})]},e.id))})}function be({identity:t,expanded:n,onToggle:a}){let o=A(),[c,l]=j(``),[d,p]=j(!1),[h,v]=j(!1),y=g(),b=i();function S(){l(t.name),p(!0)}function w(){p(!1),l(``)}function T(){let e=c.trim();if(!e||e===t.name){w();return}y.mutate({id:t.id,name:e},{onSettled:()=>{o.invalidateQueries({queryKey:$}),w()}})}function E(){b.mutate({id:t.id},{onSettled:()=>{o.invalidateQueries({queryKey:$}),v(!1)}})}return D(`div`,{className:`rounded-md border border-border bg-surface`,children:[D(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[M(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:t.coverBase64?M(`img`,{src:`data:image/jpeg;base64,${t.coverBase64}`,alt:t.name,className:`h-full w-full object-cover`}):M(`div`,{className:`flex h-full w-full items-center justify-center`,children:M(ve,{className:`h-4 w-4 text-foreground-subtle`})})}),M(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:d?D(k,{children:[M(C,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T(),e.key===`Escape`&&w()},className:`h-6 text-xs`,autoFocus:!0}),M(`button`,{type:`button`,onClick:T,disabled:y.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:M(q,{className:`h-3.5 w-3.5`})}),M(`button`,{type:`button`,onClick:w,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:M(Y,{className:`h-3.5 w-3.5`})})]}):M(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name})}),M(x,{variant:`default`,className:`text-[10px]`,children:t.sampleCount}),!d&&D(`div`,{className:`flex items-center gap-1`,children:[M(`button`,{type:`button`,onClick:S,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:M(W,{className:`h-3.5 w-3.5`})}),M(`button`,{type:`button`,onClick:()=>v(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:M(X,{className:`h-3.5 w-3.5`})})]}),M(`button`,{type:`button`,onClick:a,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":n?`Collapse`:`Expand`,children:M(n?K:fe,{className:`h-3.5 w-3.5`})})]}),n&&M(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:M(ye,{identityId:t.id})}),M(r,{open:h,onOpenChange:e=>!e&&v(!1),children:D(f,{children:[D(s,{children:[M(e,{children:`Delete person`}),D(u,{children:[`Delete `,M(`strong`,{children:t.name}),` and all their samples? This cannot be undone.`]})]}),D(m,{children:[M(_,{variant:`secondary`,onClick:()=>v(!1),children:`Cancel`}),D(_,{variant:`danger`,onClick:E,disabled:b.isPending,children:[b.isPending?M(J,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function xe(){let e=A(),[t,n]=j(``),r=a();function i(){let i=t.trim();i&&r.mutate({name:i},{onSettled:()=>{e.invalidateQueries({queryKey:$}),n(``)}})}return D(`div`,{className:`flex items-center gap-2 pt-2`,children:[M(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`}),D(_,{variant:`primary`,size:`sm`,onClick:i,disabled:r.isPending||!t.trim(),children:[r.isPending?M(J,{className:`h-3.5 w-3.5 animate-spin`}):M(G,{className:`h-3.5 w-3.5`}),`Add`]})]})}function Se(){let{data:e,isLoading:t}=d(),[n,r]=j(null);function i(e){r(t=>t===e?null:e)}return t?D(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[M(J,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):D(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&M(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),e?.map(e=>M(be,{identity:e,expanded:n===e.id,onToggle:()=>i(e.id)},e.id)),M(xe,{})]})}function Ce(e){return e.base64===void 0||e.base64.length===0}function we(e){return e.filter(Ce).map(e=>e.faceId)}function Te(e){let t=0;for(let n of e)Ce(n)&&(t+=1);return t}E();function Ee(e){let[t,n]=j(null),[r,i]=j(null),[a,o]=j(!1);return N(()=>{if(n(null),i(null),o(!1),!e)return;let t=!1,r=null;return(async()=>{try{let i=await Q(`${ge}/${encodeURIComponent(e)}`);if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),N(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>o(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function De(e){let t=e.filter(e=>e.base64.length>0);return t.length===0?null:t.find(e=>/crop|face/i.test(e.kind))??t[0]}function Oe({label:e,value:t}){return D(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[M(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),M(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:t})]})}function ke({box:e}){return M(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:M(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Face`})})}function Ae({face:e,cameraName:t,onClose:n,onAssign:i,onUnassign:a,onDelete:o,actionsPending:s}){let{data:c,isFetching:l}=p({faceId:e?.faceId??``},{enabled:e!==null}),[u,d]=j(`frame`),{frameSrc:m,naturalWidth:h,naturalHeight:g,failed:v}=Ee(e?.keyFrameMediaKey),y=O(()=>{let t=De(c??[]);return t?`data:image/jpeg;base64,${t.base64}`:e?.base64?`data:image/jpeg;base64,${e.base64}`:null},[c,e]),b=O(()=>!e?.faceBbox||h===null||g===null?null:z(e.faceBbox,h,g),[e?.faceBbox,h,g]);if(e===null)return null;let x=typeof e.keyFrameMediaKey==`string`&&e.keyFrameMediaKey.length>0&&!v,S=x&&u===`frame`,C=e.assigned?e.identityName??`Assigned`:e.recognizedIdentityId?`${e.identityName??`Recognized`} (suggested)`:`Unassigned`;return M(r,{open:!0,onOpenChange:e=>!e&&n(),children:D(f,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Face detail`,className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[D(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[D(`div`,{className:`min-w-0`,children:[M(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:`Face detail`}),M(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),M(`button`,{type:`button`,onClick:n,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:M(Y,{className:`h-4 w-4`})})]}),D(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[x&&D(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[D(`button`,{type:`button`,onClick:()=>d(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${u===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[M(I,{className:`h-3.5 w-3.5`}),` Full frame`]}),D(`button`,{type:`button`,onClick:()=>d(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${u===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[M(F,{className:`h-3.5 w-3.5`}),` Crop`]})]}),S&&m?M(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:M(V,{src:m,alt:`Full frame with detected face`,fit:`natural`,className:`w-full`,overlay:b?M(ke,{box:b}):void 0})}):y?D(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[M(V,{src:y,alt:`Detected face`,className:`h-full w-full`}),l&&M(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:M(J,{className:`h-3.5 w-3.5 animate-spin`})})]}):D(`div`,{className:`flex aspect-square w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[M(H,{className:`h-8 w-8 text-warning/70`}),M(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),M(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:`The crop media for this face could not be resolved (a pre-fix orphan). Safe to delete.`})]}),D(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[M(Oe,{label:`Camera`,value:t}),M(Oe,{label:`Captured`,value:U(e.timestamp)}),M(Oe,{label:`Track`,value:e.trackId}),M(Oe,{label:`Identity`,value:C})]})]}),D(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[e.assigned?D(_,{variant:`secondary`,onClick:()=>a(e.faceId),disabled:s,children:[M(L,{className:`h-3.5 w-3.5`}),` Detach`]}):D(_,{variant:`primary`,onClick:()=>i(e.faceId),disabled:s,children:[M(R,{className:`h-3.5 w-3.5`}),` Assign`]}),D(_,{variant:`secondary`,onClick:()=>o(e.faceId),disabled:s,children:[M(X,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}E();var je=[[`faceGallery`]];function Me({faceIds:t,identities:i,onDone:o}){let c=A(),l=n(),d=a(),[p,h]=j(``),[g,v]=j(!1),[y,b]=j(null),x=t!==null&&t.length>0,S=t?.length??0;function w(){v(!1),h(``),b(null)}function T(){w(),o()}function E(e){!t||t.length===0||l.mutate({faceIds:[...t],identityId:e},{onSettled:()=>{c.invalidateQueries({queryKey:je}),T()}})}function O(){!t||!p.trim()||d.mutate({name:p.trim()},{onSuccess:e=>{e?.id&&E(e.id)},onError:()=>{c.invalidateQueries({queryKey:je}),T()}})}let k=l.isPending||d.isPending;return M(r,{open:x,onOpenChange:e=>!e&&T(),children:D(f,{children:[D(s,{children:[M(e,{children:S>1?`Assign ${String(S)} faces to person`:`Assign face to person`}),M(u,{children:`Select an existing person or create a new one.`})]}),M(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:i.map(e=>D(`button`,{type:`button`,onClick:()=>b(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${y===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[M(`span`,{className:`font-medium`,children:e.name}),D(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),g?M(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:M(C,{placeholder:`New person name…`,value:p,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&O()},autoFocus:!0,className:`flex-1`})}):M(`button`,{type:`button`,onClick:()=>{b(null),v(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:`+ New person…`}),D(m,{children:[M(_,{variant:`secondary`,onClick:T,disabled:k,children:`Cancel`}),g?D(_,{variant:`primary`,onClick:O,disabled:k||!p.trim(),children:[k&&M(J,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):D(_,{variant:`primary`,onClick:()=>y&&E(y),disabled:k||!y,children:[k&&M(J,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,S>1?` ${String(S)}`:``]})]})]})})}function Ne(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function Pe(e,t){return e.faceIds.filter(e=>!t.has(e))}function Fe(e,t){return e.faceIds.filter(e=>t(e))}E();var Ie=[[`faceGallery`]],Le=20,Re=.3,ze=.9,Be=.05,Ve=.5,He=2,Ue=10,We=2;function Ge({cluster:e,face:t,active:n,onSelect:r}){return D(`button`,{type:`button`,onClick:r,className:`flex shrink-0 flex-col items-center gap-1.5 rounded-md border p-2 text-center transition-colors md:w-full md:flex-row md:gap-2.5 md:text-left ${n?`border-primary bg-primary/8`:`border-border bg-surface hover:bg-surface-hover`}`,children:[M(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:t?.base64?M(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:``,className:`h-24 w-24 object-cover`}):M(H,{className:`h-24 w-24 p-6 text-foreground-subtle`})}),D(`span`,{className:`w-24 text-[11px] leading-tight text-foreground-subtle md:w-auto`,children:[e.size,` faces · `,Math.round(e.cohesion*100),`% alike`]})]})}function Ke({face:e,cameraName:t,nowMs:n,excluded:r,onToggleExclude:i,onDelete:a,deletePending:o}){return D(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${r?`border-border opacity-40 grayscale`:`border-border`}`,children:[D(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[e.base64?M(V,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Face from ${t}`,className:`h-full w-full`}):D(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[M(H,{className:`h-7 w-7 text-warning/70`}),M(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}),M(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i()},className:`absolute right-1 top-1 z-10 rounded-full bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":r?`Include face`:`Exclude face`,title:r?`Include`:`Exclude`,children:M(r?_e:Y,{className:`h-3.5 w-3.5`})})]}),D(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[M(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),M(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:B(e.timestamp,n)})]}),M(`div`,{className:`mt-1 flex items-center justify-end border-t border-border/60 px-1 py-0.5`,children:M(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},disabled:o,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete face`,title:`Delete face`,children:o?M(J,{className:`h-4 w-4 animate-spin`}):M(X,{className:`h-4 w-4`})})})]})}function qe({open:e,onClose:t,byId:n,cameraName:i,nowMs:a,identities:o,selectMany:s}){let c=A(),u=l(),d=b(),[p,m]=j(Ve),[h,g]=j(We),[v,y]=j(null),[x,S]=j({}),[C,T]=j(null),{data:E,isFetching:P,refetch:F}=w({threshold:p,minClusterSize:h,limit:Le},{enabled:e}),I=E??[];N(()=>{S({})},[p,h]),N(()=>{if(I.length===0){y(null);return}I.some(e=>e.representativeFaceId===v)||y(I[0]?.representativeFaceId??null)},[I]);let L=O(()=>I.find(e=>e.representativeFaceId===v)??null,[I,v]),z=L?x[L.representativeFaceId]??new Set:new Set,ee=O(()=>L?Fe(L,e=>n.has(e)):[],[L,n]),te=L?L.faceIds.length-ee.length:0,B=L?Pe({...L,faceIds:ee},z):[];function V(e){if(!L)return;let t=L.representativeFaceId;S(n=>({...n,[t]:Ne(n[t]??new Set,e)}))}function ne(){c.invalidateQueries({queryKey:Ie})}async function H(e){await u({title:`Delete face`,message:`Permanently deletes this face crop. This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&d.mutate({faceId:e},{onSettled:ne})}function re(){T(null),t()}function ie(){B.length!==0&&(s(B),re())}return D(r,{open:e,onOpenChange:e=>!e&&re(),children:[D(f,{placement:`sheet-on-mobile`,width:`lg`,"aria-label":`Look-alike groups`,className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 md:max-w-4xl`,children:[D(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border px-4 py-3`,children:[D(`div`,{className:`flex items-center justify-between gap-2`,children:[D(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[M(he,{className:`h-4 w-4 text-primary`}),` Look-alike groups`]}),M(`button`,{type:`button`,onClick:re,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:M(Y,{className:`h-4 w-4`})})]}),D(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[D(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Threshold`,M(`input`,{type:`range`,min:Re,max:ze,step:Be,value:p,onChange:e=>m(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),M(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:p.toFixed(2)})]}),D(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Min size`,M(`input`,{type:`number`,min:He,max:Ue,step:1,value:h,onChange:e=>g(Math.min(Ue,Math.max(He,Number(e.target.value)||He))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),D(_,{variant:`secondary`,onClick:()=>{S({}),F()},disabled:P,children:[P?M(J,{className:`h-3.5 w-3.5 animate-spin`}):M(le,{className:`h-3.5 w-3.5`}),`Re-analyze`]})]})]}),M(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:P&&I.length===0?D(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[M(J,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):I.length===0?M(`div`,{className:`flex flex-1 items-center justify-center py-8 text-xs text-foreground-subtle`,children:`No look-alike groups at this threshold.`}):D(k,{children:[M(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:I.map(e=>M(Ge,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===v,onSelect:()=>y(e.representativeFaceId)},e.representativeFaceId))}),M(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:I.map(e=>M(Ge,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===v,onSelect:()=>y(e.representativeFaceId)},e.representativeFaceId))}),M(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:L&&D(k,{children:[te>0&&D(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:[te,` not loaded — excluded from actions`]}),M(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,1fr))] gap-2`,children:ee.map(e=>{let t=n.get(e);return t?M(Ke,{face:t,cameraName:i(t.deviceId),nowMs:a,excluded:z.has(e),onToggleExclude:()=>V(e),onDelete:()=>void H(e),deletePending:d.isPending&&d.variables?.faceId===e},e):null})})]})})]})}),D(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[M(_,{variant:`secondary`,onClick:ie,disabled:B.length===0,children:`Select in gallery`}),D(_,{variant:`primary`,onClick:()=>T(B),disabled:B.length===0,children:[M(R,{className:`h-3.5 w-3.5`}),` Adopt (`,B.length,`)`]})]})]}),M(Me,{faceIds:C,identities:o,onDone:()=>T(null)})]})}E();var Je=[[`faceGallery`]],Ye=500,Xe=120;function Ze({face:e,cameraName:t,nowMs:n,selected:r,onToggleSelect:i,onAssign:a,onOpenDetail:o}){let s=A(),c=y(),l=b(),u=()=>{s.invalidateQueries({queryKey:Je})},d=()=>o(e.faceId);return D(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${r?`border-primary ring-1 ring-primary`:`border-border`}`,children:[D(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[e.base64?M(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Face from ${t}`,onClick:d,className:`h-full w-full cursor-zoom-in object-cover`}):D(`button`,{type:`button`,onClick:d,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:`No crop image — the face's crop media is missing (a pre-fix orphan). Safe to delete.`,children:[M(H,{className:`h-7 w-7 text-warning/70`}),M(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}),M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),i(e.faceId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":r?`Deselect`:`Select`,children:r?M(ue,{className:`h-4 w-4 text-primary`}):M(de,{className:`h-4 w-4`})})]}),D(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[M(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),M(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:B(e.timestamp,n)}),e.identityName&&M(`p`,{className:`text-[10px] font-medium text-primary truncate`,title:e.identityName,children:e.identityName})]}),D(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),c.mutate({faceId:e.faceId},{onSettled:u})},disabled:c.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":`Detach face`,title:`Detach`,children:c.isPending?M(J,{className:`h-4 w-4 animate-spin`}):M(L,{className:`h-4 w-4`})}):M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(e.faceId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":`Assign face to person`,title:`Assign to person`,children:M(R,{className:`h-4 w-4`})}),M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),l.mutate({faceId:e.faceId},{onSettled:u})},disabled:l.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete face`,title:`Delete face`,children:l.isPending?M(J,{className:`h-4 w-4 animate-spin`}):M(X,{className:`h-4 w-4`})})]})]})}var Qe=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function $e(){let e=A(),[t,r]=j(`all`),[i,a]=j(oe),[o,s]=j(new Set),[l,u]=j(new Set),[f,p]=j(null),[m,h]=j(!1),[g,x]=j(null),{data:C,isLoading:w}=c({limit:Ye,filter:t},{refetchInterval:3e4}),{data:T=[]}=d(),{data:E}=v({}),N=n(),P=y(),F=S(),I=b(),z=Date.now(),B=C??[],V=O(()=>{let e=new Map;for(let t of E??[])e.set(t.id,t.name);return e},[E]),U=e=>V.get(e)??`Camera #${String(e)}`,se=O(()=>te(B).map(e=>({id:e,name:U(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[B,V]),W=O(()=>ne(ce(B,i),o),[B,i,o]),G=re(W,Xe,O(()=>JSON.stringify([t,i.fromMs,i.toMs,[...o].sort((e,t)=>e-t)]),[t,i.fromMs,i.toMs,o])),le=O(()=>new Map(B.map(e=>[e.faceId,e])),[B]),ue=O(()=>Te(W),[W]),de=g===null?null:le.get(g)??null,K=()=>{e.invalidateQueries({queryKey:Je})},q=()=>u(new Set);function fe(e){u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function pe(e){u(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function me(){pe(we(W))}let Z=[...l],Q=N.isPending||F.isPending||I.isPending,ge=P.isPending||I.isPending;function _e(){Z.length!==0&&F.mutate({faceIds:Z},{onSettled:()=>{K(),q()}})}function ve(){Z.length!==0&&Promise.allSettled(Z.map(e=>I.mutateAsync({faceId:e}))).then(()=>{K(),q()})}function $(e){x(null),p([e])}function ye(e){P.mutate({faceId:e},{onSettled:K}),x(null)}function be(e){I.mutate({faceId:e},{onSettled:K}),x(null)}let xe=W.length!==B.length;return D(`div`,{className:`relative space-y-3`,children:[D(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[M(`div`,{className:`flex items-center gap-1`,children:Qe.map(e=>M(`button`,{type:`button`,onClick:()=>r(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${t===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value))}),M(ee,{onChange:a}),M(ie,{cameras:se,selected:o,onChange:s}),D(`button`,{type:`button`,onClick:()=>h(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${m?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[M(he,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!w&&ue>0&&D(`button`,{type:`button`,onClick:me,className:`ml-auto flex items-center gap-1 rounded-md px-2.5 py-1 text-xs text-warning/90 transition-colors hover:bg-warning/10`,title:`Select every visible face whose crop image is missing so you can delete the orphans in one pass`,children:[M(H,{className:`h-3.5 w-3.5`}),` Select `,ue,` crop-less`]}),!w&&M(`span`,{className:`text-[10px] text-foreground-subtle ${ue>0?`ml-2`:`ml-auto`}`,children:xe?`${String(W.length)} of ${String(B.length)} faces`:`${String(W.length)} face${W.length===1?``:`s`}`})]}),l.size>0&&D(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[D(`span`,{className:`text-xs font-medium text-foreground`,children:[l.size,` selected`]}),D(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[D(_,{variant:`primary`,onClick:()=>p(Z),disabled:Q,children:[M(R,{className:`h-3.5 w-3.5`}),` Assign`]}),D(_,{variant:`secondary`,onClick:_e,disabled:Q,children:[F.isPending?M(J,{className:`h-3.5 w-3.5 animate-spin`}):M(L,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),D(_,{variant:`secondary`,onClick:ve,disabled:Q,children:[M(X,{className:`h-3.5 w-3.5`}),` Delete`]}),M(_,{variant:`ghost`,onClick:q,disabled:Q,children:M(Y,{className:`h-3.5 w-3.5`})})]})]}),w&&D(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[M(J,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!w&&W.length===0&&M(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:B.length>0?`No faces match the current date / camera filters.`:`No faces found for this filter.`}),!w&&W.length>0&&D(k,{children:[M(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(6.5rem,1fr))] gap-2`,children:G.pageItems.map(e=>M(Ze,{face:e,cameraName:U(e.deviceId),nowMs:z,selected:l.has(e.faceId),onToggleSelect:fe,onAssign:e=>p([e]),onOpenDetail:x},e.faceId))}),M(ae,{currentPage:G.page,totalItems:G.totalItems,pageSize:G.pageSize,onPageChange:G.setPage,itemNoun:`faces`})]}),M(Ae,{face:de,cameraName:de?U(de.deviceId):``,onClose:()=>x(null),onAssign:$,onUnassign:ye,onDelete:be,actionsPending:ge}),M(Me,{faceIds:f,identities:T,onDone:()=>{p(null),q()}}),M(qe,{open:m,onClose:()=>h(!1),byId:le,cameraName:U,nowMs:z,identities:T,selectMany:pe})]})}E();var et=[[`faceGallery`]],tt=2e3;function nt(){let e=A(),t=T(e);t.current=e;let n=T(void 0);n.current||=se({delayMs:tt,invalidate:()=>{t.current.invalidateQueries({queryKey:et})}}),N(()=>()=>n.current?.cancel(),[]),o(P.PipelineAnalyticsFaceGalleryChanged,()=>{n.current?.trigger()})}function rt(){return nt(),M(Z,{icon:me,title:`Faces`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:D(`section`,{className:`space-y-3`,children:[D(`div`,{children:[M(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),M(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Enrolled identities used for face recognition. Expand a row to view or remove training samples.`}),M(Se,{})]}),D(`div`,{className:`pt-4 border-t border-border`,children:[M(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),M(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Face crops captured by the detection pipeline. Assign them to a person to build recognition training data.`}),M($e,{})]})]})})}export{rt as DetectionIntelligencePage};
@@ -0,0 +1,2 @@
1
+ import{$ as e,An as t,B as n,Ba as r,Bn as i,Ca as a,Ct as o,D as s,Di as c,Dn as l,E as u,F as d,Fa as f,Fn as p,H as m,Hi as h,Hn as g,In as _,J as v,K as y,La as b,Ln as x,Mr as S,N as C,O as w,On as T,P as E,Pa as D,Pn as ee,Q as O,Ra as te,Rn as ne,Rt as re,Sa as k,T as A,Ta as ie,Tn as ae,Ua as oe,Un as se,V as ce,Vn as j,Wn as M,X as le,Y as ue,Yr as de,Z as fe,a as N,an as pe,at as me,bn as he,cr as ge,di as P,f as _e,g as ve,gr as ye,hn as be,hr as F,i as I,it as xe,jn as Se,kn as Ce,l as we,li as Te,lo as Ee,m as De,mr as Oe,n as ke,na as Ae,o as je,oi as Me,on as L,p as Ne,pn as Pe,q as Fe,r as Ie,ra as Le,rt as Re,tt as ze,u as Be,uo as Ve,wn as R,xi as He,xn as Ue,y as We,za as Ge,zn as Ke,zr as qe}from"./src-P2A2VEVG.js";import{I as z,K as B,Q as V,S as H,W as U,a as Je,b as W,o as G,q as K,t as Ye,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 Xe,B as Ze,D as Qe,E as $e,L as et,O as tt,S as nt,T as rt,b as it,g as at,k as ot,w as Y,y as st}from"./src-DNVzx9ag.js";import{c as ct,k as lt,p as X,r as ut,t as dt,u as ft}from"./player-overlays-CDSEY_-X.js";import{t as pt}from"./CapabilityBadges-3XeZhtSI.js";import{n as mt,t as ht}from"./rotate-ccw-DVTmMtl2.js";import{t as gt}from"./ProviderIcon-BeZnXEB7.js";import{n as _t,t as vt}from"./FormBuilder-iTpxBqBc.js";import{i as yt,n as bt,t as xt}from"./useDevice-BskeVR-e.js";import{t as St}from"./pencil-fohpLhWe.js";import{t as Ct}from"./plus-CWmuK222.js";import{t as wt}from"./refresh-cw-7j7eJ_7S.js";import{t as Tt}from"./rotate-cw-Dl9N7lTh.js";import{t as Et}from"./server-BxecI2el.js";import{t as Dt}from"./wifi-D9-_VL0_.js";import{A as Ot,J as kt,K as At,L as jt,S as Mt,U as Nt,V as Pt,W as Ft,a as It,c as Lt,i as Rt,j as zt,m as Bt,q as Vt,r as Ht,s as Ut,t as Wt,v as Gt,y as Kt,z as qt}from"./index-BVO5AjpN.js";import{t as Jt}from"./StatusBadge-Dcr2bw58.js";import{t as Yt}from"./useEventInvalidation-DtNYz-2H.js";import{n as Xt,r as Zt,t as Qt}from"./SchemaTabBar-DhsmEGyn.js";var $t=Ft(`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`}]]),en=Ft(`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`}]]),tn=Ft(`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`}]]),nn=Ft(`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`}]]),rn=Ft(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),an=Ft(`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 on({parentDeviceId:e}){let{t}=Wt(),n=At(),r=X(),{data:i,isLoading:a,isError:o}=bt(e),{data:s}=R({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=v(s?.stableId??``,c,s?.childLayout),u=l.ungrouped,d=e=>n(`/devices/${String(e)}`),f=s?.name??``,p=(e,t)=>q(y,{trpc:r.trpcClient,device:{...t,name:O(t,f)},variant:`minimal`,onNavigate:d},e),m=u.some(e=>!!e.role),h=u.some(e=>!e.role),g=m&&!h?t(`device.accessories`,{defaultValue:`Accessories`}):!m&&h?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),_=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:g}),q(`div`,{className:`space-y-1`,children:u.map(e=>p(e.id,e))})]}):null,b=l.disabledSection===void 0?null:q(Fe,{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=>p(e.id,e))})},l.disabledSection.title);return l.sections.length===0?b===null?_:H(`div`,{className:`space-y-2`,children:[_,b]}):H(`div`,{className:`space-y-2`,children:[l.sections.map(e=>q(Fe,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>p(e.id,e))},e.title)),_,b]})}function sn({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(gt,{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(Jt,{status:r?`online`:`offline`}),i.length>0&&q(pt,{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 cn({deviceId:e}){let t=G(),n=pe({deviceId:e},{refetchInterval:1e4,retry:!1}),r=L({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=U(()=>ln(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(un,{label:`Discovered`,value:i.total,icon:q(Gt,{className:`h-3.5 w-3.5`})}),q(un,{label:`Adopted`,value:i.adopted,accent:`success`}),q(un,{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(Mt,{className:`h-3.5 w-3.5 animate-spin`}):q(wt,{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(dn,{icon:q(Dt,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),q(dn,{icon:q(Kt,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),q(dn,{icon:q(It,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?q(dn,{icon:q($t,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.unknown} unknown`}):null]})]})}function ln(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 un({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 dn({icon:e,label:t}){return H(`span`,{className:`inline-flex items-center gap-1`,children:[e,q(`span`,{children:t})]})}function fn({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(a,{trpc:X().trpcClient,deviceId:e,features:t})})}function pn({deviceId:e,features:t}){return q(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:q(k,{trpc:X().trpcClient,deviceId:e,features:t})})}function Z({deviceId:e,deviceType:t,features:n}){let r=X(),i=xe(t)?.HeroCard??k,a=ft(ct(r.trpcClient,e)?.state.deviceStatus),o=a!==void 0&&a.online===!1,s=o?a.lastChangedAt:null;return H(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[o?q(`div`,{className:`flex justify-center`,children:q(m,{lastChangedAt:s})}):null,q(i,{trpc:r.trpcClient,deviceId:e,features:n})]})}function mn({deviceId:e}){let t=X(),{data:n,isLoading:r}=xt(e),{data:i,isLoading:a}=bt(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(ce,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}var hn={[Y.Switch]:Z,[Y.Siren]:Z,[Y.Light]:Z,[Y.Sensor]:Z,[Y.Button]:Z,[Y.Hub]:cn,[Y.Cover]:fn,[Y.Valve]:Z,[Y.Humidifier]:Z,[Y.WaterHeater]:Z,[Y.Container]:mn,[Y.Lock]:Z,[Y.Fan]:Z,[Y.Thermostat]:Z,[Y.Climate]:Z,[Y.MediaPlayer]:Z,[Y.Control]:Z,[Y.AlarmPanel]:pn,[Y.EventEmitter]:pn,[Y.Notifier]:pn,[Y.Script]:pn,[Y.Automation]:pn,[Y.Presence]:Z,[Y.Update]:Z,[Y.Vacuum]:Z,[Y.LawnMower]:Z,[Y.Weather]:Z,[Y.Image]:Z,[Y.PetFeeder]:Z};function gn(e){return q(hn[e.deviceType]??sn,{...e})}function _n(e){return N(X().trpcClient,e)}V();function vn(e){let[t,n]=K(`idle`),[r,i]=K(null),a=B(null),o=B(null),s=B(null),c=B(!0),l=F(),u=Oe(),d=ye(),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 yn=0;function Q(){return++yn}function bn(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function xn(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 Sn(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 Cn(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 wn({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: ${bn(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=Ye({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: ${bn(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...xn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...Cn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...Sn(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: ${bn(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 Tn({deviceId:e,intercomAvailable:t=!1}){let n=X(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),a=_n(i?e:null),{streams:o,pipelineMetrics:s,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h}=I(n.trpcClient,i?e:null),g=le(n.trpcClient,i?e:null),_=vn(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=ut(),S=w(),C=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(We,{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:C,...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 En({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full`,children:q(ve,{...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 Dn({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(wn,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function On({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(De,{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 kn({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(_e,{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 An({deviceId:e}){let n=G(),r=Number.isFinite(e),{data:i}=R({deviceId:e},{enabled:r}),a=typeof i?.type==`string`?i.type:`camera`;Yt([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:o,isLoading:s,isError:c,error:l}=Ue({deviceId:e},{enabled:r}),{data:u}=t({deviceType:a},{enabled:!!a}),d=g({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(s)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 o?.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(mt,{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(Ge,{columns:[{key:`capability`,header:`Capability`,render:e=>q(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>q(jn,{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(Mn,{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(Nn,{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 jn({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(Et,{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(en,{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(nn,{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(yt,{className:`h-3 w-3`}),`unbound`]})}function Mn({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 Nn({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?jt:ht,{className:`h-3 w-3`}),e]},e)})})}V();function Pn({schema:e,values:t,pendingKeys:n,onChange:r,onAction:i,onSave:a,onDiscard:o,disabled:s,activeSubTab:c,onSubTabChange:l,flattenTabs:u=!1,deviceId:d}){let f=e.tabs??[],p=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]),m=new Set(f.map(e=>e.id)),h=[...f,...[...p.keys()].filter(e=>!m.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],g=h[0]?.id??`general`,[_,v]=K(g),y=l!==void 0,b=new Set(h.map(e=>e.id)),x=y?c&&b.has(c)?c:g:b.has(_)?_:g,S=e=>{y?l(e):v(e)},C=p.get(x)??[],w={sections:C.length<=1?C.length===1?[{...C[0],title:``}]:C:C.every(e=>!e.title)?[{...C[0],title:``,fields:C.flatMap(e=>e.fields)}]:C},T=q(Xt,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>o(n),saving:s});if(u||h.length<=1)return H(`div`,{className:`flex flex-col gap-3`,children:[q(vt,{schema:e,values:t,onChange:r,onAction:i,disabled:s,deviceId:d}),T]});let E=new Map,D=new Map;for(let[e,t]of p){E.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&&D.set(e,a)}return H(`div`,{className:`flex flex-col gap-3`,children:[q(Qt,{tabs:h.map(e=>({id:e.id,label:e.label})),activeId:x,onChange:S,countByTab:E,pendingByTab:D}),q(vt,{schema:w,values:t,onChange:r,onAction:i,disabled:s,deviceId:d}),T]})}var Fn=`device-export`,In=`export`,Ln=`Export`;function Rn(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(Rn):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(Rn)):e.writerCapName===Fn}function zn(e){return e.fields.some(Rn)}V();function Bn(e,t){return t&&t===`admin`?e:!0}function Vn(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?zn(e)&&zn(t)?e.id.localeCompare(t.id):(e.order??0)-(t.order??0):n.localeCompare(r)})};return e.tabs?{...t,tabs:e.tabs}:t}function Hn(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 Un(e){return e.key}function Wn(e){if(!Hn(e))return e.value}function Gn(e){return Hn(e)?null:e}function Kn(e,t){for(let n of e)if(t(n),n.type===`group`)Kn(n.fields,t);else if(n.type===`sub-tabs`)for(let e of n.tabs)Kn(e.fields,t)}function qn(e){if(!e)return{};let t={};for(let n of e.sections)Kn(n.fields,e=>{let n=Un(e);n!==null&&(t[n]=Wn(e))});return t}function Jn(e,t){if(!e)return null;let n=null;for(let r of e.sections)if(Kn(r.fields,e=>{if(n!==null||Un(e)!==t)return;let r=Gn(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function Yn(e){return{...e,fields:e.fields.map(Xn)}}function Xn(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function Zn(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=Gn(e);return n?Bn(t,n.minRole)?e:Xn(e):e})}))}}function Qn({deviceId:e,sectionFilter:t,activeSubTab:n,onSubTabChange:r,flattenSubTabs:i}){let a=G(),{user:o}=Ht(),s=o?.isAdmin===!0,c=B(!1),{data:l,isLoading:u}=ae({deviceId:e},{refetchInterval:()=>c.current?!1:2500,enabled:Number.isFinite(e)}),{data:d}=R({deviceId:e},{enabled:Number.isFinite(e)}),f=l?.settings??null,m=l?.live??null,h=U(()=>{if(!f&&!m)return null;let e=f?.sections??[],n=(m?.sections??[]).map(Yn),r=[...e,...n],i=t?r.filter(t):r.filter(e=>e.location!==`top-tab`&&!zn(e));if(i.length===0)return null;let a=new Set;for(let e of i)a.add(e.tab??`general`);let o=[...f?.tabs??[],...(m?.tabs??[]).filter(e=>!(f?.tabs??[]).some(t=>t.id===e.id))].filter(e=>a.has(e.id));return o.length>0?{tabs:o,sections:i}:{sections:i}},[f,m,t]),g=U(()=>Vn(h),[h]),_=U(()=>Zn(g,s),[g,s]),v=U(()=>qn(_),[_]),y=Le(),b=Ae(),x=se(),S=p(),C=M({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),w={isPending:C.isPending,mutate:t=>{C.mutate({deviceId:e,changes:[...t]})}},T=Zt({schema:_,serverValues:v,onImmediateSave:z(e=>{let t=Object.entries(e).map(([e,t])=>{let n=Jn(_,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&w.mutate(t)},[_,w]),onDeferredSave:z(e=>{let t=Object.entries(e).map(([e,t])=>{let n=Jn(_,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&w.mutate(t)},[_,w])}),{values:E,pendingKeys:D,handleChange:ee,handleSave:O,handleDiscard:te}=T;if(c.current=T.editingPaused,u)return H(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[q(Mt,{className:`h-4 w-4 animate-spin mr-2`}),q(`span`,{className:`text-xs`,children:`Loading device aggregate…`})]});if(!_||_.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 ne(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=et(e,r);await y.mutateAsync({brokerId:i}),a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(t===`test-probe`){if(!d)return{status:`error`,error:`Device metadata not loaded yet`};try{return await x.mutateAsync({addonId:d.addonId,type:d.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=et(e,t),i=await b.mutateAsync({brokerId:r});return a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),i}if(t===`device-custom-action`){let t=await S.mutateAsync({deviceId:e,action:n,input:r});return a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),t}throw Error(`[device-aggregate] unknown action "${t}"`)}return q(Pn,{schema:_,values:E,pendingKeys:D,onChange:ee,onAction:ne,onSave:O,onDiscard:te,disabled:w.isPending,activeSubTab:n,onSubTabChange:r,flattenTabs:i,deviceId:e})}function $n({deviceId:e,activeSubTab:t,onSubTabChange:n}){return q(`div`,{className:`flex flex-col gap-3`,children:q(Qn,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}V();function er(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 tr(e){return e?e.enabled!==void 0||e.modelId!==void 0||e.settings!==void 0:!1}function nr(e,t){return t?{enabled:t.enabled??e.enabled,modelId:t.modelId??e.modelId,settings:t.settings??e.settings}:e}function rr({agents:e,currentAgent:t,onPick:n,hint:r}){let[i,a]=K(!1),o=e.filter(e=>e!==t);return o.length===0?null: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:()=>a(e=>!e),children:`Mirror from ▾`}),r&&q(`div`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:r}),i&&q(`div`,{className:`absolute top-full left-0 mt-1 min-w-[140px] bg-surface border border-border rounded shadow-lg z-10`,children:o.map(e=>q(`button`,{type:`button`,className:`w-full text-left px-3 py-1.5 text-xs hover:bg-muted`,onClick:()=>{a(!1),n(e)},children:e},e))})]})}function ir({deviceId:e,refreshToken:t}){let n=G(),r=X().trpcClient,[i,a]=K(null),[o,s]=K(null),[c,l]=K(null),u=Me({deviceId:e},{refetchOnMount:`always`}),d=P(void 0,{refetchOnMount:`always`});Yt([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let p=qe(void 0,{refetchOnMount:`always`}),m=U(()=>{let e=new Set;for(let t of p.data??[])t.isOnline&&e.add(t.id);return e},[p.data]),h=U(()=>(d.data??[]).filter(e=>m.has(e.nodeId)).map(e=>e.nodeId),[d.data,m]),g=h[0]??``,_=de({nodeId:g},{enabled:g!==``,refetchOnMount:`always`}),v=Je({enabled:h.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`device-step-formats`,h.join(`,`),t],queryFn:async()=>{let e={};for(let t of h)try{e[t]=(await r.pipelineExecutor.getSchema.query({nodeId:t})).selectedEngine.format}catch{e[t]=`coreml`}return e}}),y=He({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]})}}),x=U(()=>_.data?b(_.data):[],[_.data]),S=U(()=>{let e=d.data??[];return(m.size===0?[]:e.filter(e=>m.has(e.nodeId))).map(e=>({agentNodeId:e.nodeId,engineLabel:v.data?.[e.nodeId]??`(engine unknown)`}))},[d.data,v.data,m]),C=(e,t)=>(d.data?.find(t=>t.nodeId===e))?.settings.addonDefaults[t]??null,w=(e,t,n)=>e?.stepOverridesByAgent?.[t]?.[n]??null,T=(e,t)=>{let n=v.data?.[t];if(!er(_.data??null,e)?.models.some(e=>n!==void 0&&!!e.formats[n]))return{kind:`na`};let r=C(t,e);if(!r)return{kind:`na`};let i=w(u.data??null,t,e),a=tr(i),o=nr(r,i);return o.enabled?{kind:`enabled`,modelId:o.modelId??`Auto`,overridden:a}:{kind:`disabled`,overridden:a}},E=i&&_.data?er(_.data,i.addonId):null,ee=i?C(i.agentNodeId,i.addonId):null,O=i?v.data?.[i.agentNodeId]??`coreml`:`coreml`,ne=i?tr(w(u.data??null,i.agentNodeId,i.addonId)):!1,re=()=>{a(null),s(null),l(null)},k=(e,t)=>{a({addonId:e,agentNodeId:t}),s(w(u.data??null,t,e)),l(null)},A=e=>{if(!i||!_.data||!d.data)return;let t=d.data.find(t=>t.nodeId===e),n=d.data.find(e=>e.nodeId===i.agentNodeId);if(!t||!n)return;let[r]=Ve({source:{nodeId:t.nodeId,engine:{format:O},defaults:t.settings.addonDefaults},target:{nodeId:n.nodeId,engine:{format:O},defaults:n.settings.addonDefaults},catalog:_.data,addonIds:[i.addonId]});if(!r){l(`no mirror result`);return}if(r.outcome===`skip`){l(`skipped: ${r.reason??`no candidate`}`);return}s(r.patch),l(`${r.outcome} from ${e}`)},ie=()=>{i&&y.mutate({deviceId:e,agentNodeId:i.agentNodeId,addonId:i.addonId,patch:o},{onSuccess:re})},ae=()=>{i&&y.mutate({deviceId:e,agentNodeId:i.agentNodeId,addonId:i.addonId,patch:null},{onSuccess:re})};if(d.isLoading||g!==``&&_.isLoading)return q(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(S.length===0)return q(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`No online agents.`});if(!_.data)return q(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let oe=i!==null&&E!==null&&ee!==null,se=(d.data??[]).map(e=>e.nodeId);return H(`div`,{className:`relative h-full w-full space-y-3`,children:[H(`div`,{className:`flex items-center gap-3 text-[10px] text-foreground-subtle`,children:[H(`span`,{className:`inline-flex items-center gap-1`,children:[q(`span`,{className:`h-1.5 w-1.5 rounded-full bg-emerald-500`}),` inherited`]}),H(`span`,{className:`inline-flex items-center gap-1`,children:[q(`span`,{className:`h-1.5 w-1.5 rounded-full bg-amber-500`}),` override`]}),q(`span`,{children:`Click a cell to override this camera's step for that agent.`})]}),q(`div`,{className:oe?`md:pr-[360px]`:``,children:x.length>0?q(D,{tree:x,agents:S,getCellState:T,onCellClick:k,selectedCell:i}):q(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),q(te,{open:oe,onClose:re,title:E?.name??``,subtitle:i?`${i.agentNodeId} · ${O}`:``,footer:H(W,{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:opacity-50`,disabled:!ne||y.isPending,onClick:ae,children:`Clear override`}),q(`div`,{className:`flex-1`}),q(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:re,children:`Cancel`}),q(`button`,{type:`button`,disabled:!i||y.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:ie,children:y.isPending?`Saving…`:`Save`})]}),children:E&&ee&&i&&H(`div`,{className:`space-y-4`,children:[q(rr,{agents:se,currentAgent:i.agentNodeId,onPick:A,hint:c}),q(f,{mode:`device`,addon:E,agentDefault:ee,agentNodeId:i.agentNodeId,currentPatch:o,engineFormat:O,onChangePatch:s})]})})]})}function $({label:e,value:t}){return H(`div`,{className:`${lt} 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 ar({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=Ke({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(jt,{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(Rt,{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(St,{className:`h-3.5 w-3.5`})})]})})}V();function or({deviceId:e,initialLocation:t}){let n=G(),[r,i]=K(!1),[a,o]=K(t??``),[s,c]=K(!1),l=B(null),{data:u}=Se(void 0,{enabled:r}),d=u??[];J(()=>{r||o(t??``)},[t,r]),J(()=>{r&&l.current?.focus()},[r]);let f=ne({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),p=U(()=>{let e=a.trim().toLowerCase();return e.length===0?d:d.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[d,a]),m=a.trim().length>0&&!d.some(e=>e.toLowerCase()===a.trim().toLowerCase()),h=async n=>{let r=(n??a).trim(),o=r.length===0?null:r;if(o===(t??null)){i(!1);return}c(!0);try{await f.mutateAsync({deviceId:e,location:o}),i(!1)}catch{}finally{c(!1)}},g=()=>{o(t??``),i(!1)};return r?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`?h():e.key===`Escape`&&g()},disabled:s,placeholder:`Room / area (or leave empty to clear)`,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),q(`button`,{type:`button`,onClick:()=>void h(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:q(jt,{className:`h-3 w-3`})}),q(`button`,{type:`button`,onClick:g,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:q(Rt,{className:`h-3 w-3`})})]}),(p.length>0||m)&&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:[p.map(e=>H(`button`,{type:`button`,onClick:()=>{o(e),h(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[q(_t,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),q(`span`,{className:`truncate`,children:e})]},e)),m&&H(`button`,{type:`button`,onClick:()=>void h(),className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover border-t border-border`,children:[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(St,{className:`h-3.5 w-3.5`})})]})})}V();function sr({deviceId:e}){let t=G(),{data:r}=xt(e),{data:a}=bt(e),[o,s]=K(null),c=i({onSuccess:()=>{s(null),t.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{s(`Could not change primary child: ${e.message}`)}});if(r==null||String(r.type??``)!==Y.Container)return null;let l=(a??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}}));if(l.length<=1)return null;let u=Re(l,typeof r.linkDeviceId==`number`?r.linkDeviceId:null,typeof r.primaryChildEntityId==`string`?r.primaryChildEntityId:null);return H(W,{children:[q($,{label:`Primary child`,value:q(n,{childrenList:l,selectedId:u===null?l[0].id:u.id,onSetPrimary:t=>c.mutate({deviceId:e,primaryChildEntityId:t}),disabled:c.isPending})}),o!==null&&q(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:o})]})}V();var cr=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function lr(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function ur(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function dr(){let e=E(),t=d(),{data:n}=R({deviceId:e??0},{enabled:e!==null}),{data:r}=Ue({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??``),f=i.features??[],p=new Set([`device-status`,`feature-probe`,`device-ops`]),m=(r?.entries??[]).filter(e=>e.kind===`native`&&!p.has(e.capName)).map(e=>e.capName),h=f.length>0?f:m,g=i.location??null,_=i.metadata??null,v=_!==null&&Object.keys(_).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`}),v&&H(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[q(fr,{active:a===`identity`,onClick:()=>o(`identity`),label:`Identity`}),q(fr,{active:a===`hardware`,onClick:()=>o(`hardware`),label:`Hardware`})]})]}),(!v||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(ar,{deviceId:e,initialName:c}),q(or,{deviceId:e,initialLocation:g}),q(sr,{deviceId:e}),q($,{label:`Type`,value:l}),q($,{label:`Provider`,value:q(gt,{type:u,size:`sm`,showLabel:!0})}),q($,{label:`Capabilities`,value:h.length>0?q(pt,{capabilities:h,showLabels:!0}):q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),v&&a===`hardware`&&q(pr,{metadata:_})]})}function fr({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 pr({metadata:e}){let t=cr.filter(t=>t in e),n=Object.keys(e).filter(e=>!cr.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:lr(t),value:q(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:ur(e[t])})},t))})]})}V();function mr({deviceId:e}){let[t,n]=K(null),r=Pe({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(wt,{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 hr={icon:``,label:``,unit:``,precision:``,hidden:!1};function gr(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function _r(e){if(typeof e!=`object`||!e)return;let t=e.unit;return typeof t==`string`?t:void 0}function vr(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 yr({deviceId:t}){let n=X(),r=G(),{data:i}=R({deviceId:t},{enabled:t>0}),a=typeof i?.role==`string`?i.role:null,o=a===null?void 0:me[a],s=o?.kind===`numeric`,c=ke(n.trpcClient,t,a??``),u=o?.kind===`numeric`?o.canonicalUnit:void 0,d=_r(c)??u,f=d===void 0?void 0:st(d),p=U(()=>f===void 0?[]:it(f),[f]),[m,h]=K(null),g=m??gr(i?.display),_=x({onSuccess:()=>{r.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:v}=l({},{staleTime:6e4}),y=j({onSuccess:()=>{r.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(i===void 0||a===null)return null;let b=e=>{h({...g,...e})},S=()=>{_.mutate({deviceId:t,display:vr(g)})},C=()=>{h(hr),_.mutate({deviceId:t,display:null})},w=()=>{let e={...g.icon===``?{}:{icon:g.icon},...g.unit===``?{}:{unit:g.unit},...g.precision.trim()!==``&&Number.isFinite(Number.parseInt(g.precision,10))?{precision:Number.parseInt(g.precision,10)}:{}},t={...v?.defaults??{},[a]:e};y.mutate({defaults:t})},T=ze(a).label,E=Object.keys(e);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:g.icon,onChange:e=>b({icon:e.target.value}),children:[H(`option`,{value:``,children:[`Default (`,T,`)`]}),E.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:T,value:g.label,onChange:e=>b({label:e.target.value})})]}),s&&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:g.unit,onChange:e=>b({unit:e.target.value}),disabled:p.length===0,children:[H(`option`,{value:``,children:[`Source`,d?` (${d})`:``]}),p.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:g.precision,onChange:e=>b({precision:e.target.value})})]})]}),H(`label`,{className:`flex items-center gap-2`,children:[q(`input`,{type:`checkbox`,checked:g.hidden,onChange:e=>b({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:S,disabled:_.isPending,children:`Save`}),q(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:C,disabled:_.isPending,children:`Reset`}),H(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:w,disabled:y.isPending,title:`Apply this unit / precision / icon as the default for every ${T} sensor`,children:[`Set as default for all `,T,` sensors`]})]})]})]})}function br(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function xr({device:e}){let t=At(),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(nt.Resyncable),{data:l}=S({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),u=l?.streams??{},d=Object.entries(u),f=s.includes(nt.DoorbellButton),p=Ie(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(Ne,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),c&&n!==null&&q(mr,{deviceId:n}),i&&n!==null&&q(A,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),f&&q(Be,{history:p.history,latestIsFresh:m}),i&&n!==null&&q(A,{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(Dt,{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(Sr,{label:`Nominal`,value:br(t.nominalBitrateKbps??0)}),q(Sr,{label:`Observed`,value:br(t.observedBitrateKbps??0)}),q(Sr,{label:`Peak`,value:br(t.peakBitrateKbps??0)}),q(Sr,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),q(dr,{}),o&&n!==null&&q(yr,{deviceId:n})]})}function Sr({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 Cr(e,t){if(t===`number`){let t=Number(e);return Number.isNaN(t)?e:t}return t===`boolean`?e===`true`:e}function wr(e,t){let n={};for(let r of e)r.key!==``&&r.value!==``&&(n[r.key]=Cr(r.value,t));return n}function Tr(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 Er(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 Dr(e){return e==null?`identity`:e.kind}function Or({value:e,onChange:t,sourceField:n,targetKind:r}){let[i,a]=K(()=>Dr(e)),[o,s]=K(()=>Tr(e,n)),[c,l]=K(()=>e?.kind===`enum-map`&&e.fallback!=null?String(e.fallback):``),[u,d]=K(()=>Er(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=wr(o,r),n=c===``?void 0:Cr(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(Tr(void 0,n)),e===`linear`&&d(Er(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 kr=`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 Ar({mode:e,idPrefix:t,labelPrefix:n,pickerDevices:r,value:i,onChange:a,search:o,onSearchChange:s}){let{data:c}=T({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:kr})]}),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:kr,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:kr,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:kr,children:[q(`option`,{value:``,children:`— select a field —`}),u.map(e=>H(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]})}function jr(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 Mr(e){return e===null?`null`:typeof e==`number`?`number`:typeof e==`boolean`?`boolean`:`string`}function Nr(e){return e===null?``:String(e)}V();var Pr=`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`,Fr=`min, max, abs, round, floor, ceil, sqrt, pow, clamp, avg, sum, coalesce, age, convert`,Ir=0;function Lr(){return Ir+=1,`b${Ir}`}function Rr(e){return{key:Lr(),name:e,mode:`sibling`,sourceId:null,cap:``,fieldPath:``,search:``,literalType:`number`,literalText:``,sampleText:``}}function zr(e,t,n){if(e===null)return[Rr(`a`)];let r=[];for(let[i,a]of Object.entries(e.bindings)){if(a.kind===`literal`){r.push({...Rr(i),mode:`literal`,literalType:Mr(a.value),literalText:Nr(a.value)});continue}if(a.kind===`global`){r.push({...Rr(i),mode:`global`,sourceId:t.find(e=>e.stableId===a.sourceStableId)?.id??null,cap:a.cap,fieldPath:a.fieldPath});continue}r.push({...Rr(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:[Rr(`a`)]}function Br(e,t,n){if(e.mode===`literal`){let t=jr(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 Vr(e){if(e.mode===`literal`)return jr(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 Hr({devices:e,siblings:t,targetDeviceId:n,containerStableId:r,initial:i,onChange:a}){let[o,s]=K(i?.expr??``),[c,l]=K(()=>zr(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=Br(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(()=>$e({expr:u.source.expr,bindings:u.source.bindings}),[u.source]),f=U(()=>{if(o.trim()===``)return null;let e=Qe(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]=Vr(t))}return rt(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`:ot.test(t)?Xe.has(t)?`reserved`:tt.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,Rr(Ur(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(Wr,{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:`${Pr} font-mono resize-y`}),H(`p`,{className:`mt-1 text-[10px] text-foreground-subtle/60`,children:[`Functions: `,Fr]}),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 Ur(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 Wr({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:`${Pr} 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:`${Pr} 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:`${Pr} 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:Pr})]}):H(W,{children:[q(Ar,{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:`${Pr} text-[10px]`})]})]})}V();function Gr(e,t,n){return(n===void 0?[e,t]:[e,n,t]).map(e=>e.replace(/[^a-z0-9]/gi,`-`)).join(`-`)}function Kr(e,t,n){let r=`${t}-${e}`;return n.find(e=>e.stableId===r)?.id??null}function qr(e,t){return t.find(t=>t.stableId===e)?.id??null}function Jr(e){return e==null?`sibling`:e.source.kind===`literal`?`literal`:e.source.kind===`global`?`global`:e.source.kind===`expression`?`expression`:`sibling`}function Yr(e){return e==null||e.source.kind!==`literal`?`string`:Mr(e.source.value)}function Xr(e){return e==null||e.source.kind!==`literal`?``:Nr(e.source.value)}function Zr({deviceId:e,parentDeviceId:t,deviceStableId:n,initial:r,onSave:i,onCancel:a}){let{data:o}=Ce({}),s=o??[],c=t==null?n:s.find(e=>e.id===t)?.stableId??n,l=s.filter(n=>n.parentDeviceId===t&&n.id!==e),{data:u}=T({deviceId:e,includeSynthesizable:!0}),d=u?.caps??[],f=r!=null&&(r.source.kind===void 0||r.source.kind===`field`)?r.source:null,p=r!=null&&r.source.kind===`global`?r.source:null,m=r!=null&&r.source.kind===`expression`?r.source:null,h=f==null?p==null?null:qr(p.sourceStableId,s):Kr(f.sourceKey,c,s),[g,_]=K(Jr(r)),[v,y]=K(r?.target.cap??``),[b,x]=K(r?.target.fieldPath??``),[S,C]=K(r?.target.itemKey??``),[w,E]=K(h),[D,ee]=K((f??p)?.cap??``),[O,te]=K((f??p)?.fieldPath??``),[ne,re]=K(void 0),[k,A]=K(``),[ie,ae]=K(Yr(r)),[oe,se]=K(Xr(r)),[ce,j]=K(m),[M,le]=K(r?.transform);J(()=>{if((f??p)==null||w!==null||s.length===0)return;let e=f==null?p==null?null:qr(p.sourceStableId,s):Kr(f.sourceKey,c,s);e!==null&&E(e)},[f,p,w,s,c]);let ue=d.find(e=>e.cap===v)?.fields??[],de=ue.find(e=>e.path===b),fe=de?.item===!0,N=k.trim().toLowerCase(),pe=s.filter(t=>t.id===e?!1:N===``?!0:t.name.toLowerCase().includes(N)||t.stableId.toLowerCase().includes(N)||String(t.id).includes(N)),me=g===`global`?pe:l,he=e=>{y(e),x(``),C(``)},ge=e=>{e!==`sibling`&&e!==`global`&&e!==`literal`&&e!==`expression`||(_(e),E(null),ee(``),te(``),re(void 0),A(``))},P=jr(ie,oe),_e=g===`literal`?P!==null:g===`expression`?ce!==null:w!=null&&D!==``&&O!==``,ve=v!==``&&b!==``&&(!fe||S.trim()!==``)&&_e,ye=()=>{if(g===`literal`)return P===null?null:{kind:`literal`,value:P.value};if(g===`expression`)return ce;let e=s.find(e=>e.id===w);if(!e||D===``||O===``)return null;if(g===`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}},be=()=>{if(!ve)return;let e=ye();if(e===null)return;let t=fe?S.trim():void 0;i({id:r?.id??Gr(v,b,t),source:e,target:{cap:v,fieldPath:b,...t===void 0?{}:{itemKey:t}},...M==null?{}:{transform:M}})},F=`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:v,onChange:e=>he(e.target.value),className:F,children:[q(`option`,{value:``,children:`— select a cap —`}),d.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:b,disabled:v===``,onChange:e=>x(e.target.value),className:F,children:[q(`option`,{value:``,children:`— select a field —`}),ue.map(e=>q(`option`,{value:e.path,children:e.item===!0?`${e.path} (per item, ${e.kind})`:`${e.path} (${e.kind})`},e.path))]})]}),fe&&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:S,placeholder:`e.g. main-brush`,onChange:e=>C(e.target.value),className:F}),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:g,onChange:e=>ge(e.target.value),className:F,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)`})]})]}),g===`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`)&&(ae(t),t===`boolean`&&se(`true`),t===`null`&&se(``))},className:F,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:oe,onChange:e=>se(e.target.value),className:F,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:oe,placeholder:ie===`number`?`e.g. 42`:`e.g. main-brush`,onChange:e=>se(e.target.value),className:F})]}))]}),g===`expression`&&q(Hr,{devices:s,siblings:l,targetDeviceId:e,containerStableId:c,initial:m,onChange:j}),(g===`sibling`||g===`global`)&&q(Ar,{mode:g,idPrefix:`link-source`,labelPrefix:`Source`,pickerDevices:me,value:{sourceId:w,cap:D,fieldPath:O},onChange:(e,t)=>{E(e.sourceId),ee(e.cap),te(e.fieldPath),re(t)},search:k,onSearchChange:A})]}),q(Or,{value:M,onChange:le,sourceField:g===`literal`||g===`expression`?void 0:ne,targetKind:de?.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:!ve,onClick:be,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 Qr({deviceId:e}){let t=X(),n=G(),r=Number.isFinite(e),{data:i,isLoading:a}=R({deviceId:e},{enabled:r,refetchInterval:1e4}),{data:o}=T({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=_({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(Ct,{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(tn,{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(ei,{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(Zr,{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 $r(e,t,n,r){let i=at(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:at(a,r)}function ei({deviceId:e,link:t,itemArray:n,trpcClient:r,onDelete:i,onEdit:a,isPending:o}){let s=ke(r,e,t.target.cap),c=t.target.itemKey,l=s===void 0?void 0:c!==void 0&&n!==void 0?$r(s,n,c,t.target.fieldPath):c===void 0?at(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(nn,{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(ti,{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 ti({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 ni=[{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 ri(e){let t=e===Y.Camera;return ni.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var ii=[{id:`logs`,icon:Bt,label:`Logs`},{id:`repl`,icon:Lt,label:`REPL`},{id:`events`,icon:Pt,label:`Events`},{id:`state`,icon:Ot,label:`State`}];function ai(){let e=Vt(),t=Number(e.deviceId),n=Number.isFinite(t),i=At(),a=G(),l=ie(),d=X(),[f,p]=kt(),m=f.get(`tab`)??`overview`,g=f.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 w(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:E,isLoading:D,isError:O}=R({deviceId:t},{enabled:n,refetchInterval:5e3,retry:1}),{data:te}=ae({deviceId:t},{enabled:n}),ne=U(()=>{let e=te?.settings?.sections??[],t=te?.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(zn)&&r.add(In),[...r].map(e=>e===`export`?{id:e,label:Ln,isAddonContrib:!0}:{id:e,label:Ze[e]?.label??e,isAddonContrib:!0})},[te]),k=E,A=String(k?.name??e.deviceId??`Device`),se=k?.online===!0,ce=se?`online`:`offline`,j=String(k?.addonId??`rtsp`),M=k?.features??[],le=k?.type,de=le===Y.Camera,{data:N}=bt(n?t:0),pe=le===Y.Container,me=U(()=>(N??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[N]),P=U(()=>pe?Re(me,typeof k?.linkDeviceId==`number`?k.linkDeviceId:null,typeof k?.primaryChildEntityId==`string`?k.primaryChildEntityId:null)?.id??null:null,[pe,me,k?.linkDeviceId,k?.primaryChildEntityId]),{data:_e}=ae({deviceId:P??0},{enabled:P!==null}),ve=U(()=>{if(P===null)return[];let e=_e?.settings?.sections??[],t=_e?.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:P}))},[P,_e]),ye=typeof k?.parentDeviceId==`number`?k.parentDeviceId:null,{data:F}=R({deviceId:ye??0},{enabled:ye!==null}),I=oe(),xe=k?.disabled!==!0,{data:Se}=T({deviceId:t},{enabled:n}),Ce=(Se?.caps.length??0)>0,Ee=U(()=>{let e=new Set,t=[];for(let n of[...ri(le),...ne,...ve])e.has(n.id)||(e.add(n.id),!(n.id===`wiring`&&!Ce)&&t.push(n));return t},[le,ne,ve,Ce]),De=U(()=>Ee.some(e=>e.id===m)?m:`overview`,[Ee,m]),Oe=z(e=>{p(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[p]),ke=z(e=>{p(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[p]),Ae=(N??[]).length>0,Me=U(()=>ii.filter(({featureGate:e})=>!e||M.includes(e)),[M]),{data:L}=ge({addonId:j},{enabled:!!j&&j!==`rtsp`}),Ne=ee({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]}),i(L?.id?`/integrations/${L.id}`:`/integrations`)}}),Pe=he({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=be({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ie=h(),Le=o({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ze=M.includes(nt.Rebootable),Be=M.includes(nt.BatteryOperated),Ve=fe(d.trpcClient,Be&&n?t:null),[He,Ue]=K(!1),We=ct(d.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=A.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=Pe.isPending||Fe.isPending,{data:qe}=Te({deviceId:t},{enabled:n,refetchInterval:1e4}),V=qe?.agentNodeId??null,Je=typeof V==`string`&&V.length>0&&!V.startsWith(`addon:`)?V:void 0,{data:W}=c({deviceId:t,...Je?{nodeId:Je}:{}},{enabled:n,refetchInterval:3e3,retry:!1}),{data:Ye}=re({deviceId:t},{enabled:n,refetchInterval:3e3,retry:!1}),J=Ye?.level?.dbfs??null;function Xe(){if(!n)return null;switch(De){case`overview`:return q(xr,{device:k??{}});case`config`:return q($n,{deviceId:t,activeSubTab:g,onSubTabChange:ke});case`pipeline`:return q(ir,{deviceId:t,refreshToken:0});case`bindings`:return q(An,{deviceId:t});case`wiring`:return q(Qr,{deviceId:t});default:{let e=De,n=ne.some(t=>t.id===e),r=ve.find(t=>t.id===e);if(!n&&r===void 0)return null;let i=r?.childDeviceId??t;if(e===`export`)return q(Qn,{deviceId:t,sectionFilter:zn,activeSubTab:g,onSubTabChange:ke});let a=q(Qn,{deviceId:i,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:g,onSubTabChange:ke});return r!==void 0&&i!==t?q(C,{deviceId:i,children:a}):a}}}return n?D?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`})})]}):O||!E?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:()=>i(`/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(r,{items:[{label:`Integrations`,onClick:()=>i(`/integrations`)},{label:L?.name??j,onClick:()=>L?.id&&i(`/integrations/${L.id}`)},{label:A}]})}),H(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[q(gt,{type:j,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:A}),q(Jt,{status:ce}),Be&&q(ue,{status:Ve,variant:`full`})]}),ye!==null&&F&&H(`button`,{type:`button`,onClick:()=>i(`/devices/${ye}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${F.name}`,children:[q(`span`,{children:`↑`}),q(`span`,{className:`truncate`,children:String(F.name??`Device #${ye}`)})]}),q(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:M.length>0&&q(pt,{capabilities:M})})]}),W&&q(`div`,{className:`hidden lg:flex`,children:q(oi,{metrics:W,dbfs:J})}),H(`div`,{className:`flex items-center gap-1 shrink-0`,children:[H(`button`,{onClick:async()=>{xe?await l({title:`Disable "${A}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Fe.mutate({deviceId:t}):Pe.mutate({deviceId:t})},disabled:Ke,title:xe?`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 ${xe?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[q(rn,{className:`h-3.5 w-3.5`}),q(`span`,{className:`hidden sm:inline`,children:Ke?`Updating…`:xe?`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:qt,disabled:He,onClick:()=>{Ge()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:Tt,hidden:!ze,disabled:Ie.isPending,danger:!0,onClick:async()=>{await l({title:`Reboot "${A}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Ie.mutate({deviceId:t})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${L?.name??j}.`,icon:wt,disabled:Le.isPending,danger:!0,onClick:async()=>{await l({title:`Restart "${L?.name??j}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${A}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&Le.mutate({addonId:j})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:Ut,separatorBefore:!0,disabled:Ne.isPending,danger:!0,onClick:async()=>{await l({title:`Delete "${A}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Ne.mutate({deviceId:t})}}]})]})]})]}),q(C,{deviceId:t,device:k??void 0,children:q(s,{children:q(u,{children:q(dt,{children:q(je,{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:de?`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:de?q(Tn,{deviceId:t,intercomAvailable:M.includes(nt.TwoWayAudio)}):q(gn,{deviceId:t,deviceName:A,deviceType:le??`unknown`,provider:j,isOnline:se,features:M})}),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:Me.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(En,{deviceId:t,containerDeviceId:le===`container`?t:void 0}),_===`repl`&&q(Dn,{deviceId:t}),_===`events`&&q(On,{deviceId:t}),_===`state`&&q(kn,{deviceId:t})]})]})]}),!I&&q(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:w,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:Ee.map(e=>{let t=De===e.id;return H(`button`,{onClick:()=>Oe(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:[De===`overview`&&Ae&&q(on,{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:()=>i(`/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 oi({metrics:e,dbfs:t}){let n=Ee(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(Nt,{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(zt,{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(an,{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{ai as DeviceDetailPage};
@@ -1 +1 @@
1
- import{Pn as e,U as t,bn as n,hn as r,kn as i,ur as a}from"./src-BhRH3dxa.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-DArwlTAt.js";import{t as p}from"./ProviderIcon-BvqTmUAe.js";import{G as m,R as h,o as g,t as _}from"./index-B0VBnS5H.js";import{t as v}from"./AdminPage-BwmGKnRf.js";import{t as y}from"./useEventInvalidation-zuVyeFVc.js";s();function b(){let{t:s}=_(),b=m(),x=f(),S=u();y([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]),y([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`]);let{data:C}=i({}),{data:w}=a(void 0),T=e({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),E=r({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),D=n({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:h,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{Pn as e,U as t,bn as n,hn as r,kn as i,ur as a}from"./src-P2A2VEVG.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-CDSEY_-X.js";import{t as p}from"./ProviderIcon-BeZnXEB7.js";import{K as m,o as h,t as g,z as _}from"./index-BVO5AjpN.js";import{t as v}from"./AdminPage-BwmGKnRf.js";import{t as y}from"./useEventInvalidation-DtNYz-2H.js";s();function b(){let{t:s}=g(),b=m(),x=f(),S=u();y([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]),y([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`]);let{data:C}=i({}),{data:w}=a(void 0),T=e({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),E=r({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),D=n({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:_,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(h,{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};
@@ -0,0 +1 @@
1
+ import{Na as e,R as t,b as n,i as r}from"./src-P2A2VEVG.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,E as p,T as m,_ as h,j as g,k as _}from"./compat-CbwIzIXq.js";import{I as v}from"./src-DNVzx9ag.js";import{d as y}from"./player-overlays-CDSEY_-X.js";i();var b=g([p({kind:f(`adaptive`)}),p({kind:f(`profile`),profile:v})]),x=p({serverUrl:_().min(1),token:_().min(1),deviceId:m().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:t,initialTarget:i,initialMuted:a}){let[s,l]=c(i),[f,p]=c(a),{handleOffer:m,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,getSessionState:y}=r(e.trpcClient,t),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(n,{serverUrl:e.serverUrl,streamKey:O,autoPlay:!0,muted:f,showControls:!1,className:`w-full h-full`,handleOffer:E,reoffer:D,getSessionState:y,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,onStateChange:e=>S(C(e)),onError:e=>S(`error`,e)},O)})}function k(){let n=o(()=>E(),[]),r=o(()=>n.ok?{system:t({serverUrl:n.config.serverUrl,token:n.config.token}),queryClient:new s({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1}}})}:null,[n]);return d(()=>{if(r)return()=>{r.system.close()}},[r]),n.ok?r?u(y,{system:r.system,children:u(l,{client:r.queryClient,children:u(e.Provider,{client:r.system.trpcClient,queryClient:r.queryClient,children:u(O,{system:r.system,deviceId:n.config.deviceId,initialTarget:n.config.target,initialMuted:n.config.muted})})})}):u(D,{message:`Failed to initialise the embed player`}):u(D,{message:n.error})}export{k as EmbedPlayerPage};
@@ -0,0 +1 @@
1
+ import{G as e,Gr as t,Hr as n,Ja as r,Ma as i,Ur as a,Vr as o,Wr as s,Ya as c,io as l,kn as u,kr as d,xa as f,yt as p}from"./src-P2A2VEVG.js";import{I as m,K as h,Q as g,S as _,W as v,b as y,i as 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{H as T,s as E,w as D}from"./src-DNVzx9ag.js";import{p as O}from"./player-overlays-CDSEY_-X.js";import{t as k}from"./clock-D2H-Andr.js";import{t as A}from"./copy-DAnlpNmN.js";import{a as j,c as M,d as ee,f as N,i as P,m as F,n as te,o as ne,p as I,r as re,s as ie,t as L}from"./debounced-invalidate-DkqNPsSh.js";import{t as R}from"./search-DvkKd5B0.js";import{t as z}from"./square-check-big-BsYa2Tzh.js";import{t as B}from"./square-CzYy8xOt.js";import{E as V,I as H,L as ae,P as oe,S as U,U as W,W as G,i as se,s as ce}from"./index-BVO5AjpN.js";import{t as le}from"./AdminPage-BwmGKnRf.js";import{r as ue,t as K}from"./authed-media-XfBD4Ma-.js";var q=G(`arrow-down-wide-narrow`,[[`path`,{d:`m3 16 4 4 4-4`,key:`1co6wj`}],[`path`,{d:`M7 20V4`,key:`1yoxec`}],[`path`,{d:`M11 4h10`,key:`1w87gc`}],[`path`,{d:`M11 8h7`,key:`djye34`}],[`path`,{d:`M11 12h4`,key:`q8tih4`}]]),de=G(`square-parking`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 17V7h4a3 3 0 0 1 0 6H9`,key:`1dfk2c`}]]);g();var fe=720*60*60*1e3;function pe(e){let t=[];for(let n of e)t.push(...n);return t}function me(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function he(e,t){return e.filter(e=>!(e.importance<t.minImportance||t.cameras.size>0&&!t.cameras.has(e.deviceId)||t.classes.size>0&&!t.classes.has(e.className)))}function J(e,t){return`${String(e)}:${t}`}function ge(e,t){let n=new Map,r=new Set;for(let i of e){let e=J(i.deviceId,i.trackId);if(!t.has(e)||r.has(e))continue;r.add(e);let a=n.get(i.deviceId);a?a.push(i.trackId):n.set(i.deviceId,[i.trackId])}return n}function _e(e,t){return{since:e.fromMs??t-fe,until:e.toMs??t}}var Y=typeof o==`function`,ve=`Track deletion arrives with the next server update`;function ye(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var be=Y?o:ye,xe=200,Se=3e4;function Ce(e){let t=O(),n=b({queries:e.deviceIds.map(n=>({queryKey:[`events-feed`,n,e.since,e.until,e.minImportance??null,e.classFilter??null],staleTime:Se,refetchInterval:Se,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEvents.query({deviceId:n,since:e.since,until:e.until,limit:xe,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>({...e,deviceId:n}))}))});return{rows:me(pe(n.map(e=>e.data??[])),`importance`),isLoading:n.some(e=>e.isLoading)}}var we=[`events-feed`],Te=2e3;function Ee(){let e=x(),t=h(e);t.current=e;let n=h(void 0);n.current||=L({delayMs:Te,invalidate:()=>{t.current.invalidateQueries({queryKey:we})}}),w(()=>()=>n.current?.cancel(),[]),i(T.PipelineAnalyticsDetectionEvent,()=>{n.current?.trigger()}),i(T.PipelineAnalyticsTrackEnded,()=>{n.current?.trigger()})}var X=100,De=120,Oe={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Z=e=>e<0?0:e>1?1:e,Q=e=>Math.round(e*100)/100;function ke(e,t){if(e.length<=t)return[...e];let n=(e.length-1)/(t-1),r=[];for(let i=0;i<t;i++)r.push(e[Math.round(i*n)]);return r[r.length-1]=e[e.length-1],r}function Ae(e,t,n){if(e.length===0||t===null)return Oe;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return Oe;let a=ke(e,n?.maxPoints??De).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X)})),o=a[0]??null,s=a[a.length-1]??null,c=a.length>=2?a.map(e=>`${e.x},${e.y}`).join(` `):``,l=(n?.snapshots??[]).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X),mediaKey:e.mediaKey})),u=null,d=-1;for(let t of e){let e=Z(t.bbox.w/r)*Z(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Q(Z(u.bbox.x/r)*X),y:Q(Z(u.bbox.y/i)*X),w:Q(Z(u.bbox.w/r)*X),h:Q(Z(u.bbox.h/i)*X)}:null}}var je={firstFrame:`First frame (track start)`,lastFrame:`Last frame (track end)`,thumbnail:`Best detection`,snapshot:`Snapshot`,keyFrame:`Key frame (native-res)`,crop:`Object crop`,fullFrame:`Full frame`,fullFrameBoxed:`Full frame (boxed)`,faceCrop:`Face crop`,plateCrop:`Plate crop`};function Me(e){return e in je}function Ne(e){return Me(e)?je[e]:e}function Pe(e,t){return`${e}${K}/${encodeURIComponent(t)}`}g();var Fe=1400,Ie=`Admin-gated URL — opens only inside an authenticated session`;function Le({label:e,value:t,title:n}){let[r,i]=S(!1);return w(()=>{if(!r)return;let e=setTimeout(()=>i(!1),Fe);return()=>clearTimeout(e)},[r]),_(`button`,{type:`button`,onClick:m(()=>{(async()=>{try{await navigator.clipboard.writeText(t),i(!0)}catch{window.prompt(`Copy the media URL:`,t)}})()},[t]),title:n,"aria-label":`Copy ${e} URL`,className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${r?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[C(r?ae:A,{className:`h-2.5 w-2.5 shrink-0`}),C(`span`,{className:`truncate`,children:r?`Copied`:e})]})}function Re({localUrl:e,publicUrl:t}){return _(`div`,{className:`flex flex-wrap gap-1`,children:[C(Le,{label:`Local`,value:e,title:`Copy LAN URL — ${Ie}`}),t&&C(Le,{label:`Public`,value:t,title:`Copy public URL — ${Ie}`})]})}g();var ze=3e4;function Be(e){let[t,n]=S(null),r=m(e=>{n(t=>t??e)},[]);return w(()=>{e||n(null)},[e]),{publicOrigin:t,probes:e?C(Ve,{onOrigin:r}):null}}function Ve({onOrigin:e}){let{data:t}=p({capName:`network-access`});return C(y,{children:(t??[]).map(t=>C(He,{addonId:t.addonId,onOrigin:e},t.addonId))})}function He({addonId:e,onOrigin:t}){let{data:n}=d({addonId:e},{refetchInterval:ze,retry:!1});return w(()=>{let e=n?E.safeParse(n):null,r=e?.success?e.data.endpoint?.url:void 0;if(r)try{t(new URL(r).origin)}catch{}},[n,t]),null}g();var Ue=15e3,We=window.location.origin,Ge=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),Ke=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]);function qe(e){let[t,n]=S(null);return w(()=>{if(n(null),!e)return;let t=!1,r=new Image;return r.onload=()=>{t||n({width:r.naturalWidth,height:r.naturalHeight})},r.src=e,()=>{t=!0,r.onload=null}},[e]),t}function Je({overlay:e,onPickSnapshot:t}){return!e.polyline&&!e.peakBox&&e.snapshots.length===0?null:_(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[e.peakBox&&C(`rect`,{x:e.peakBox.x,y:e.peakBox.y,width:e.peakBox.w,height:e.peakBox.h,fill:`none`,stroke:`#f59e0b`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),e.polyline&&C(`polyline`,{points:e.polyline,fill:`none`,stroke:`#38bdf8`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),e.points.map((e,t)=>C(`circle`,{cx:e.x,cy:e.y,r:1,fill:`#38bdf8`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),e.snapshots.map((e,n)=>C(`circle`,{cx:e.x,cy:e.y,r:1.9,fill:`#0ea5e9`,fillOpacity:.95,stroke:`#082f49`,strokeWidth:.7,vectorEffect:`non-scaling-stroke`,className:t?`pointer-events-auto cursor-pointer`:void 0,onClick:t?n=>{n.stopPropagation(),t(e.mediaKey)}:void 0,children:C(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${e.mediaKey}-${String(n)}`)),e.start&&C(`circle`,{cx:e.start.x,cy:e.start.y,r:2.4,fill:`#22c55e`,stroke:`#052e16`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),e.end&&C(`circle`,{cx:e.end.x,cy:e.end.y,r:2.4,fill:`#ef4444`,stroke:`#450a0a`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function $({label:e,value:t,mono:n}){return _(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[C(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),C(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function Ye({row:e,cameraName:t,deleteAvailable:i,onClose:o,onDeleted:u}){let d=O(),p=be(),h=e!==null,g=e?.deviceId??0,b=e?.trackId??``,x=e?.bestEventId??``,T=e?.timestamp??0,E=e?.windowMs??0,{data:D}=a({deviceId:g,trackId:b},{enabled:h}),{data:k}=s({trackId:b},{enabled:h}),{data:A}=n({eventId:x},{enabled:h&&x!==``}),{data:j}=f({deviceId:g,since:T-Ue,until:T+E+Ue},{enabled:h}),[M,N]=S(null),[te,ne]=S(!1),{publicOrigin:re,probes:ie}=Be(h);w(()=>{N(null)},[g,b]);let L=v(()=>{let e=k??[],t=A??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[k,A]),R=ue(L?`${K}/${encodeURIComponent(L.key)}`:void 0),z=v(()=>{let e=new Set,t=[];for(let n of[...A??[],...k??[]])!n.base64||e.has(n.key)||(e.add(n.key),t.push(n));return t},[A,k]),B=v(()=>z.find(e=>Ge.has(e.kind))??null,[z]),H=qe(B?`data:image/jpeg;base64,${B.base64}`:null),ae=v(()=>Ae(D?.positions??[],H,{snapshots:(D?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaKey:e.mediaKey}))}),[D?.positions,D?.snapshots,H]),oe=m(e=>{let t=z.find(t=>t.key===e);t&&N(t)},[z]);if(e===null)return null;let W=M?`data:image/jpeg;base64,${M.base64}`:R.src,G=M?.kind??L?.kind,le=G!==void 0&&Ke.has(G)&&H!==null&&(D?.positions.length??0)>=2,q=j&&j.length>0?j[0]:null,de=()=>{q&&(ne(!0),(async()=>{try{let t=await d.trpcClient.videoclips.getClipPlayback.query({deviceId:e.deviceId,clipId:q.id});window.open(t.playbackUrl,`_blank`,`noopener`)}catch{window.alert(`Could not resolve clip playback. Check the server logs.`)}finally{ne(!1)}})())},fe=()=>{!i||p.isPending||window.confirm(`Delete this track and all its media? This cannot be undone.`)&&(async()=>{try{await p.mutateAsync({deviceId:e.deviceId,trackIds:[e.trackId]}),u()}catch{window.alert(`Failed to delete this track. Check the server logs.`)}})()},pe=Math.round(e.importance*100),me=D?.importanceReason?`${String(pe)}% · ${D.importanceReason}`:`${String(pe)}%`,he=D?.zonesVisited&&D.zonesVisited.length>0?D.zonesVisited.join(`, `):`—`,J=D?.audioLabels&&D.audioLabels.length>0?D.audioLabels.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `):`—`,ge=D?D.totalDistance.toFixed(2):`—`,_e=I(D?D.firstSeen:T),Y=D?I(D.lastSeen):`—`;return C(r,{open:!0,onOpenChange:e=>!e&&o(),children:_(c,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Event detail`,className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[_(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[_(`div`,{className:`min-w-0`,children:[_(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[e.className,e.label?_(`span`,{className:`text-foreground-subtle`,children:[` · `,e.label]}):null]}),C(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),C(`button`,{type:`button`,onClick:o,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:C(se,{className:`h-4 w-4`})})]}),_(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[W?C(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:C(P,{src:W,alt:`Key frame from ${t}`,fit:`natural`,className:`w-full`,overlay:le?C(Je,{overlay:ae,onPickSnapshot:oe}):void 0})}):C(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:R.failed?_(y,{children:[C(F,{className:`h-8 w-8 opacity-60`}),C(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):C(U,{className:`h-6 w-6 animate-spin opacity-70`})}),z.length>0&&C(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:z.map(e=>{let t=`data:image/jpeg;base64,${e.base64}`,n=Ne(e.kind),r=Pe(We,e.key),i=re?Pe(re,e.key):null;return _(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[C(`button`,{type:`button`,onClick:()=>N(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${n} · ${I(e.timestamp)}`,children:C(`img`,{src:t,alt:n,className:`h-full w-full object-cover`})}),_(`figcaption`,{className:`min-w-0 px-0.5`,children:[C(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:n,children:n}),C(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:I(e.timestamp),children:ee(e.timestamp)})]}),C(Re,{localUrl:r,publicUrl:i})]},e.key)})}),ie,q&&_(l,{variant:`secondary`,onClick:de,disabled:te,children:[te?C(U,{className:`h-3.5 w-3.5 animate-spin`}):C(V,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),_(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[C($,{label:`Camera`,value:t}),C($,{label:`Class`,value:e.className}),C($,{label:`Label`,value:e.label??`—`}),C($,{label:`Importance`,value:me}),C($,{label:`Zones visited`,value:he}),C($,{label:`Audio heard`,value:J}),C($,{label:`Total distance`,value:ge}),C($,{label:`First seen`,value:_e}),C($,{label:`Last seen`,value:Y}),C($,{label:`Track`,value:e.trackId,mono:!0})]})]}),C(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:C(`span`,{title:i?void 0:ve,children:_(l,{variant:`secondary`,onClick:fe,disabled:!i||p.isPending,children:[p.isPending?C(U,{className:`h-3.5 w-3.5 animate-spin`}):C(ce,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}function Xe(e){if(e===void 0||!Number.isFinite(e)||e<=0)return``;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`${String(n)}m ${String(r).padStart(2,`0`)}s`}function Ze({row:e,cameraName:t,nowMs:n,onOpenDetail:r,selected:i=!1,onToggleSelect:a,score:o}){let s=ue(e.bestEventId?`${K}/${e.bestEventId}`:void 0),c=Math.round(e.importance*100),l=o===void 0?void 0:Math.round(o*100),u=Xe(e.windowMs),d=()=>r(e);return _(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[_(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[s.src?C(`img`,{src:s.src,alt:`Event from ${t}`,onClick:d,className:`h-full w-full cursor-zoom-in object-cover`}):C(`button`,{type:`button`,onClick:d,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:s.failed?`Key-event media unavailable`:`No key-event media`,children:C(F,{className:`h-6 w-6 opacity-60`})}),a&&C(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(J(e.deviceId,e.trackId))},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Deselect`:`Select`,children:i?C(z,{className:`h-4 w-4 text-primary`}):C(B,{className:`h-4 w-4`})}),l!==void 0&&_(`span`,{className:`absolute left-1 top-1 z-10 rounded bg-primary/85 px-1.5 py-0.5 text-[10px] font-semibold text-white tabular-nums`,title:`CLIP semantic-match score`,children:[String(l),`%`]}),c>0&&C(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(c)})]}),_(`button`,{type:`button`,onClick:d,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[_(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,e.label?_(`span`,{className:`text-foreground-subtle`,children:[` · `,e.label]}):null]}),C(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),_(`div`,{className:`flex items-center justify-between gap-2`,children:[C(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:N(e.timestamp,n)}),u&&C(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:u})]})]})]})}g();var Qe=[`events-feed`],$e=60,et=[`person`,`vehicle`,`animal`],tt=[{value:`importance`,label:`Importance`,icon:q},{value:`time`,label:`Recent`,icon:k}];function nt(){let e=x(),[t,n]=S(ie),[r,i]=S(new Set),[a,o]=S(new Set),[s,c]=S(0),[d,f]=S(`time`),[p,m]=S(new Set),[h,g]=S(null),[b,T]=S(()=>Date.now());w(()=>{let e=setInterval(()=>T(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:E,until:O}=v(()=>_e({fromMs:t.fromMs,toMs:t.toMs},b),[t.fromMs,t.toMs,b]);Ee();let{data:k}=u({}),A=v(()=>(k??[]).filter(e=>e.type===D.Camera),[k]),ee=v(()=>A.map(e=>e.id),[A]),N=be(),P=N.isPending,{rows:F,isLoading:I}=Ce({deviceIds:ee,since:E,until:O,minImportance:s>0?s:void 0,classFilter:a.size===1?[...a][0]:void 0}),L=v(()=>{let e=new Map;for(let t of A??[])e.set(t.id,t.name);return e},[A]),R=e=>L.get(e)??`Camera #${String(e)}`,z=v(()=>M(F).map(e=>({id:e,name:R(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[F,L]),B=v(()=>me(he(F,{cameras:r,classes:a,minImportance:s}),d),[F,r,a,s,d]),V=te(B,$e,v(()=>JSON.stringify([[...r].sort((e,t)=>e-t),[...a].sort(),s,d,E,O]),[r,a,s,d,E,O])),H=()=>{e.invalidateQueries({queryKey:Qe})},ae=()=>m(new Set);function oe(e){m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function W(e){o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function G(){if(p.size===0||!Y)return;let e=ge(F,p),t=[...e.values()].reduce((e,t)=>e+t.length,0);if(t===0||!window.confirm(`Delete ${String(t)} track${t===1?``:`s`} and all their media? This cannot be undone.`))return;let n=[...e];Promise.allSettled(n.map(([e,t])=>N.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{H();let t=[],r=new Set;if(e.forEach((e,i)=>{let a=n[i];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)r.add(J(o,e));else t.push(o)}),m(e=>{let t=new Set(e);for(let e of r)t.delete(e);return t}),t.length>0){let e=t.map(e=>R(e)).join(`, `);window.alert(`Failed to delete tracks on: ${e}. They remain selected — retry, or check the server logs.`)}})}let le=B.length!==F.length;return _(`div`,{className:`relative space-y-3`,children:[_(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[C(j,{onChange:n}),C(ne,{cameras:z,selected:r,onChange:i}),C(`div`,{className:`flex items-center gap-1`,children:et.map(e=>C(`button`,{type:`button`,onClick:()=>W(e),className:`rounded-md px-2.5 py-1 text-xs capitalize transition-colors ${a.has(e)?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e},e))}),_(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[C(`span`,{children:`Min score`}),C(`input`,{type:`range`,min:0,max:1,step:.05,value:s,onChange:e=>c(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":`Minimum importance`}),C(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(s*100)})]}),C(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:tt.map(e=>{let t=e.icon;return _(`button`,{type:`button`,onClick:()=>f(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${d===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[C(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!I&&C(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:le?`${String(B.length)} of ${String(F.length)} events`:`${String(B.length)} event${B.length===1?``:`s`}`})]}),p.size>0&&_(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[_(`span`,{className:`text-xs font-medium text-foreground`,children:[p.size,` selected`]}),_(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[C(`span`,{title:Y?void 0:`Track deletion arrives with the next server update`,children:_(l,{variant:`secondary`,onClick:G,disabled:!Y||P,children:[P?C(U,{className:`h-3.5 w-3.5 animate-spin`}):C(ce,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),C(l,{variant:`ghost`,onClick:ae,disabled:P,children:C(se,{className:`h-3.5 w-3.5`})})]})]}),I&&_(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[C(U,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!I&&B.length===0&&C(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),!I&&B.length>0&&_(y,{children:[C(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:V.pageItems.map(e=>C(Ze,{row:e,cameraName:R(e.deviceId),nowMs:b,selected:p.has(J(e.deviceId,e.trackId)),onToggleSelect:oe,onOpenDetail:g},J(e.deviceId,e.trackId)))}),C(re,{currentPage:V.page,totalItems:V.totalItems,pageSize:V.pageSize,onPageChange:V.setPage,itemNoun:`events`})]}),h&&C(Ye,{row:h,cameraName:R(h.deviceId),deleteAvailable:Y,onClose:()=>g(null),onDeleted:()=>{H(),g(null)}})]})}g();var rt=50,it=350,at=[`person`,`vehicle`,`animal`],ot=[{value:.2,label:`Loose`},{value:.25,label:`Balanced`},{value:.3,label:`Strict`}];function st(e){return{id:e.id,trackId:e.trackId??e.id,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,importance:e.importance??0,bestEventId:e.mediaKey??e.trackId??e.id,windowMs:void 0}}function ct({onActiveChange:n}){let[r,i]=S(``),[a,o]=S(.2),[s,c]=S(null),[l,d]=S(null),[f,p]=S(null),m=e(r,it).trim(),h=m.length>0;w(()=>{n(h)},[h,n]);let[g,y]=S(()=>Date.now());w(()=>{let e=setInterval(()=>y(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:b}=u({}),x=v(()=>(b??[]).filter(e=>e.type===D.Camera),[b]),T=v(()=>{let e=new Map;for(let t of b??[])e.set(t.id,t.name);return e},[b]),E=e=>T.get(e)??`Camera #${String(e)}`,{data:O,isFetching:k,isError:A,error:j}=t({text:m,minScore:a,limit:rt,classFilter:s??void 0,deviceId:l??void 0},{enabled:h}),M=v(()=>[...O??[]].sort((e,t)=>t.score-e.score).map(e=>({...st(e),score:e.score})),[O]);function ee(e){c(t=>t===e?null:e)}return _(`div`,{className:`space-y-3`,children:[_(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[_(`div`,{className:`flex flex-wrap items-center gap-2`,children:[_(`div`,{className:`relative min-w-[16rem] flex-1`,children:[C(R,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),C(`input`,{type:`text`,value:r,onChange:e=>i(e.target.value),placeholder:`Semantic search — describe what you're looking for…`,className:`h-9 w-full rounded-md border border-border bg-background pl-8 pr-8 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":`Semantic event search`}),r&&C(`button`,{type:`button`,onClick:()=>i(``),className:`absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Clear search`,children:C(se,{className:`h-3.5 w-3.5`})})]}),k&&h&&C(U,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),_(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[C(`div`,{className:`flex items-center gap-1`,children:at.map(e=>C(`button`,{type:`button`,onClick:()=>ee(e),className:`rounded-md px-2.5 py-1 text-xs capitalize transition-colors ${s===e?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e},e))}),_(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[C(`span`,{children:`Camera`}),_(`select`,{value:l===null?``:String(l),onChange:e=>d(e.target.value===``?null:Number(e.target.value)),className:`h-7 rounded-md border border-border bg-background px-1.5 text-xs text-foreground focus:border-primary focus:outline-none`,"aria-label":`Filter by camera`,children:[C(`option`,{value:``,children:`All`}),x.map(e=>C(`option`,{value:String(e.id),children:e.name},e.id))]})]}),_(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[C(`span`,{children:`Match`}),C(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:ot.map(e=>C(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${a===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:`Minimum CLIP score ${e.value.toFixed(2)}`,children:e.label},e.value))})]}),h&&!k&&!A&&_(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[M.length,` match`,M.length===1?``:`es`]})]})]}),h&&_(`div`,{className:`space-y-3`,children:[A&&_(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,j instanceof Error?j.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!A&&k&&M.length===0&&_(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[C(U,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!A&&!k&&M.length===0&&_(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:[`No semantic matches for “`,m,`”. Try a looser match threshold or a different phrasing.`]}),!A&&M.length>0&&C(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:M.map(e=>C(Ze,{row:e,cameraName:E(e.deviceId),nowMs:g,score:e.score,onOpenDetail:p},e.id))})]}),f&&C(Ye,{row:f,cameraName:E(f.deviceId),deleteAvailable:Y,onClose:()=>p(null),onDeleted:()=>p(null)})]})}var lt=15e3;function ut(e){let t=O(),n=b({queries:e.map(e=>({queryKey:[`stationary-objects`,e],staleTime:lt,refetchInterval:lt,queryFn:async()=>((await t.trpcClient.zoneAnalytics.getCurrentSnapshot.query({deviceId:e}))?.stationaryObjects??[]).map(t=>({...t,deviceId:e}))}))});return{rows:n.flatMap(e=>e.data??[]).toSorted((e,t)=>t.becameStationaryAt-e.becameStationaryAt),isLoading:n.some(e=>e.isLoading)}}g();function dt(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return`just now`;if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function ft({row:e,cameraName:t,nowMs:n}){let r=e.keyFrameMediaKey?.startsWith(`track:`)?e.keyFrameMediaKey.split(`:`)[1]:e.keyFrameMediaKey,i=ue(r?`${K}/${r}`:void 0);return _(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[_(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[i.src?C(`img`,{src:i.src,alt:`Parked ${e.className} on ${t}`,className:`h-full w-full object-cover`}):C(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:C(de,{className:`h-6 w-6`})}),C(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:e.label??e.className})]}),_(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[C(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),_(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,dt(n,e.becameStationaryAt)]})]})]})}function pt(){let[e,t]=S(!1),n=Date.now(),{data:r}=u({}),i=v(()=>(r??[]).filter(e=>e.type===D.Camera),[r]),a=v(()=>i.map(e=>e.id),[i]),o=v(()=>{let e=new Map;for(let t of i)e.set(t.id,t.name);return e},[i]),{rows:s}=ut(a);return s.length===0?null:_(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[_(`button`,{type:`button`,onClick:()=>t(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[C(e?H:oe,{className:`h-4 w-4 text-foreground-subtle`}),C(de,{className:`h-4 w-4 text-foreground-subtle`}),C(`span`,{className:`text-sm font-semibold text-foreground`,children:`Stationary`}),C(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:s.length}),C(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:`Parked objects — kept out of the event feed`})]}),e&&C(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:s.map(e=>C(ft,{row:e,cameraName:o.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}g();function mt(){Ee();let[e,t]=S(!1);return C(le,{icon:W,title:`Events`,subtitle:`Every captured key event across all cameras — trajectory, media, and clips.`,children:_(`section`,{className:`space-y-3`,children:[C(ct,{onActiveChange:t}),!e&&C(pt,{}),!e&&C(nt,{})]})})}export{mt as EventsPage};
@@ -1 +1 @@
1
- import{C as e,En as t,w as n}from"./src-BhRH3dxa.js";import{K as r,Q as i,S as a,W as o,b as s,q as c,x as l}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 u}from"./refresh-cw-dvjeQnSv.js";import{t as d}from"./search-BWa4jUVz.js";import{F as f,I as p,S as m,U as h,i as g}from"./index-B0VBnS5H.js";var _=h(`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`}]]);function v(e){return[e.value,e.label,e.description].filter(e=>typeof e==`string`&&e.length>0).join(` `).toLowerCase()}function y(e,t){let n=t.trim().toLowerCase().split(/\s+/).filter(Boolean);return n.length===0?e:e.filter(e=>{let t=v(e);return n.every(e=>t.includes(e))})}function b(e,t){let n=new Map(e.map(e=>[e.value,e])),r=new Set(t);return{selectedOptions:t.map(e=>n.get(e)??{value:e,label:e}),unselected:e.filter(e=>!r.has(e.value))}}function x(e){return e>=8}i();var S=`flex items-center gap-1.5 rounded-md border border-border bg-background px-2 py-1.5 focus-within:border-primary focus-within:ring-1 focus-within:ring-primary/30`,C=`block text-[11px] font-medium text-foreground mb-1 break-words`,w=`text-[10px] text-foreground-subtle mt-0.5 break-words`;function T({field:e,value:t,onChange:n,disabled:i,translationFn:s}){let u=Array.isArray(t)?t:[],m=i===!0||e.disabled===!0,h=e.maxItems!==void 0&&u.length>=e.maxItems,[_,v]=c(``),[x,T]=c(!1),[E,D]=c(0),O=r(null),k=r(null),{selectedOptions:A}=o(()=>b(e.options,u),[e.options,u]),j=o(()=>y(e.options,_),[e.options,_]),N=t=>{if(!m)if(u.includes(t))n(u.filter(e=>e!==t));else{if(e.maxItems!==void 0&&u.length>=e.maxItems)return;n([...u,t])}},P=e=>{if(e.key===`ArrowDown`)e.preventDefault(),T(!0),D(e=>j.length===0?0:(e+1)%j.length);else if(e.key===`ArrowUp`)e.preventDefault(),T(!0),D(e=>j.length===0?0:(e-1+j.length)%j.length);else if(e.key===`Enter`){e.preventDefault();let t=j[E];t&&N(t.value)}else e.key===`Escape`?T(!1):e.key===`Backspace`&&_===``&&u.length>0&&n(u.slice(0,-1))},F=M(e.label,s),I=M(e.description,s);return a(`div`,{className:`min-w-0`,children:[F!==void 0&&F!==``&&l(`label`,{className:C,children:F}),A.length>0&&l(`div`,{className:`flex flex-wrap gap-1 mb-1.5`,children:A.map(e=>a(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-primary/10 px-1.5 py-0.5 text-[11px] text-primary max-w-full`,children:[l(`span`,{className:`truncate`,children:e.label}),!m&&l(`button`,{type:`button`,className:`shrink-0 hover:text-danger`,"aria-label":`Remove ${e.label}`,onClick:()=>N(e.value),children:l(g,{className:`h-2.5 w-2.5`})})]},e.value))}),a(`div`,{className:S+(m?` opacity-50`:``),children:[l(d,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),l(`input`,{ref:O,type:`text`,role:`combobox`,"aria-expanded":x,"aria-controls":`msel-${e.key}`,className:`min-w-0 flex-1 bg-transparent text-xs text-foreground outline-none placeholder:text-foreground-disabled`,value:_,placeholder:h?`Max ${e.maxItems} selected`:e.placeholder??`Search to add…`,disabled:m,onChange:e=>{v(e.target.value),T(!0),D(0)},onFocus:()=>T(!0),onBlur:()=>{k.current=setTimeout(()=>T(!1),120)},onKeyDown:P}),l(f,{className:`h-3.5 w-3.5 shrink-0 cursor-pointer text-foreground-subtle`,onMouseDown:e=>{e.preventDefault(),k.current&&clearTimeout(k.current),T(e=>!e),O.current?.focus()}})]}),x&&!m&&l(`div`,{id:`msel-${e.key}`,role:`listbox`,className:`mt-1 max-h-56 overflow-y-auto rounded-md border border-border bg-surface shadow-lg`,onMouseDown:e=>{e.preventDefault()},children:j.length===0?a(`div`,{className:`px-2.5 py-2 text-[11px] text-foreground-subtle italic`,children:[`No matches for “`,_,`”`]}):j.map((e,t)=>{let n=u.includes(e.value),r=!n&&h;return a(`button`,{type:`button`,role:`option`,"aria-selected":n,disabled:r,className:[`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-xs transition-colors`,t===E?`bg-primary/10`:`hover:bg-surface-hover`,r?`opacity-40 cursor-not-allowed`:`cursor-pointer`].join(` `),onMouseEnter:()=>D(t),onClick:()=>N(e.value),children:[l(`span`,{className:[`flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded border`,n?`border-primary bg-primary text-white`:`border-border`].join(` `),children:n&&l(p,{className:`h-2.5 w-2.5`})}),l(`span`,{className:`truncate text-foreground`,children:e.label})]},e.value)})}),I&&l(`p`,{className:w,children:I})]})}function E({deviceId:e,mode:n}){let{data:r,isLoading:i,isFetching:o,isError:s,refetch:c}=t({deviceId:e},{enabled:Number.isFinite(e)}),d=r?.devices??[];return a(`div`,{className:`mt-3 rounded-md border border-border bg-background p-2.5`,children:[a(`div`,{className:`flex items-center justify-between mb-1.5`,children:[a(`span`,{className:`text-[11px] font-medium text-foreground`,children:[`Resolved links`,l(`span`,{className:`ml-1.5 text-[10px] font-normal text-foreground-subtle`,children:(r?.mode??n)===`auto`?`children + same location`:`children + manual list`})]}),a(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-50`,disabled:o,onClick:()=>void c(),title:`Re-run the resolver`,children:[l(u,{className:`h-3 w-3 ${o?`animate-spin`:``}`}),`Refresh`]})]}),i?a(`div`,{className:`flex items-center gap-1.5 py-1 text-[11px] text-foreground-subtle`,children:[l(m,{className:`h-3 w-3 animate-spin`}),`Resolving…`]}):s?l(`p`,{className:`py-1 text-[11px] text-danger`,children:`Failed to resolve linked devices.`}):d.length===0?l(`p`,{className:`py-1 text-[11px] text-foreground-subtle italic`,children:`No linked devices resolved.`}):l(`div`,{className:`flex flex-wrap gap-1`,children:d.map(e=>a(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border bg-surface px-1.5 py-0.5 text-[11px] text-foreground max-w-full`,title:e.location??void 0,children:[l(`span`,{className:`truncate`,children:e.name}),e.location!==null&&e.location.length>0&&a(`span`,{className:`inline-flex items-center gap-0.5 shrink-0 text-[10px] text-foreground-subtle`,children:[l(_,{className:`h-2.5 w-2.5`}),e.location]})]},e.deviceId))})]})}i();var D=`_linkedDevicesMode`,O=`_linkedDeviceIds`;function k(e){return e.type===`multiselect`}function A({field:t,values:r,onChange:i,disabled:a,translationFn:o,onTestField:s,externalProbe:c,allFields:u,onAction:d}){return k(t)&&x(t.options.length)?n(t,r,u)?l(T,{field:t,value:r[t.key],onChange:e=>i(t.key,e),disabled:a,translationFn:o}):null:l(e,{field:t,values:r,onChange:i,disabled:a,translationFn:o,onTestField:s,externalProbe:c,allFields:u,onAction:d})}function j(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function M(e,t){if(e!==void 0)return t&&j(e)?t(e):e}function N({section:t,values:r,onChange:i,disabled:o,translationFn:u,onTestField:d,probeResults:f,onAction:p,deviceId:m}){let[h,g]=c(t.defaultCollapsed??!1),_=t.style===`accordion`;if(t.fields.reduce((e,i)=>e+ +!!n(i,r,t.fields),0)===0)return null;let v=t.fields.some(e=>`key`in e&&e.key===D),y=r[D]===`manual`?`manual`:`auto`,b=v&&y!==`manual`?t.fields.filter(e=>!(`key`in e&&e.key===O)):t.fields,x=v?1:t.columns??2,S=x===1?`grid-cols-1`:x===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:x===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`,C=t.fields.length===1&&t.fields[0]?.type===`widget`?t.fields[0]:void 0;return a(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},children:[!(C!==void 0||!t.title&&!t.description)&&a(`div`,{className:[`flex items-center justify-between mb-2`,_?`cursor-pointer`:``].join(` `),onClick:_?()=>g(e=>!e):void 0,children:[a(`div`,{children:[t.title&&l(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:M(t.title,u)}),t.description&&l(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:M(t.description,u)})]}),_&&l(`span`,{className:`text-foreground-subtle text-xs ml-2`,children:h?`▸`:`▾`})]}),!h&&(C===void 0?a(s,{children:[l(`div`,{className:`grid ${S} gap-x-3 gap-y-2.5`,children:b.map(e=>l(A,{field:e,values:r,onChange:i,disabled:o,translationFn:u,onTestField:d,externalProbe:f?.[e.key],allFields:t.fields,onAction:p},e.key))}),v&&m!==void 0&&l(E,{deviceId:m,mode:y})]}):l(e,{field:C,values:r,onChange:i,disabled:o,translationFn:u,onTestField:d,externalProbe:f?.[C.key],allFields:t.fields,onAction:p},C.key))]})}function P({schema:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,probeResults:o,onClearProbe:s,onAction:c,deviceId:u}){let d=(e,r)=>{n({...t,[e]:r}),s?.(e)};return l(`div`,{className:`space-y-4`,children:e.sections.map((e,n)=>l(N,{section:e,values:t,onChange:d,disabled:r,translationFn:i,onTestField:a,probeResults:o,onAction:c,deviceId:u},`${e.id}-${n}`))})}export{_ as n,P as t};
1
+ import{C as e,En as t,w as n}from"./src-P2A2VEVG.js";import{K as r,Q as i,S as a,W as o,b as s,q as c,x as l}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 u}from"./refresh-cw-7j7eJ_7S.js";import{t as d}from"./search-DvkKd5B0.js";import{I as f,L as p,S as m,W as h,i as g}from"./index-BVO5AjpN.js";var _=h(`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`}]]);function v(e){return[e.value,e.label,e.description].filter(e=>typeof e==`string`&&e.length>0).join(` `).toLowerCase()}function y(e,t){let n=t.trim().toLowerCase().split(/\s+/).filter(Boolean);return n.length===0?e:e.filter(e=>{let t=v(e);return n.every(e=>t.includes(e))})}function b(e,t){let n=new Map(e.map(e=>[e.value,e])),r=new Set(t);return{selectedOptions:t.map(e=>n.get(e)??{value:e,label:e}),unselected:e.filter(e=>!r.has(e.value))}}function x(e){return e>=8}i();var S=`flex items-center gap-1.5 rounded-md border border-border bg-background px-2 py-1.5 focus-within:border-primary focus-within:ring-1 focus-within:ring-primary/30`,C=`block text-[11px] font-medium text-foreground mb-1 break-words`,w=`text-[10px] text-foreground-subtle mt-0.5 break-words`;function T({field:e,value:t,onChange:n,disabled:i,translationFn:s}){let u=Array.isArray(t)?t:[],m=i===!0||e.disabled===!0,h=e.maxItems!==void 0&&u.length>=e.maxItems,[_,v]=c(``),[x,T]=c(!1),[E,D]=c(0),O=r(null),k=r(null),{selectedOptions:A}=o(()=>b(e.options,u),[e.options,u]),j=o(()=>y(e.options,_),[e.options,_]),N=t=>{if(!m)if(u.includes(t))n(u.filter(e=>e!==t));else{if(e.maxItems!==void 0&&u.length>=e.maxItems)return;n([...u,t])}},P=e=>{if(e.key===`ArrowDown`)e.preventDefault(),T(!0),D(e=>j.length===0?0:(e+1)%j.length);else if(e.key===`ArrowUp`)e.preventDefault(),T(!0),D(e=>j.length===0?0:(e-1+j.length)%j.length);else if(e.key===`Enter`){e.preventDefault();let t=j[E];t&&N(t.value)}else e.key===`Escape`?T(!1):e.key===`Backspace`&&_===``&&u.length>0&&n(u.slice(0,-1))},F=M(e.label,s),I=M(e.description,s);return a(`div`,{className:`min-w-0`,children:[F!==void 0&&F!==``&&l(`label`,{className:C,children:F}),A.length>0&&l(`div`,{className:`flex flex-wrap gap-1 mb-1.5`,children:A.map(e=>a(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-primary/10 px-1.5 py-0.5 text-[11px] text-primary max-w-full`,children:[l(`span`,{className:`truncate`,children:e.label}),!m&&l(`button`,{type:`button`,className:`shrink-0 hover:text-danger`,"aria-label":`Remove ${e.label}`,onClick:()=>N(e.value),children:l(g,{className:`h-2.5 w-2.5`})})]},e.value))}),a(`div`,{className:S+(m?` opacity-50`:``),children:[l(d,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),l(`input`,{ref:O,type:`text`,role:`combobox`,"aria-expanded":x,"aria-controls":`msel-${e.key}`,className:`min-w-0 flex-1 bg-transparent text-xs text-foreground outline-none placeholder:text-foreground-disabled`,value:_,placeholder:h?`Max ${e.maxItems} selected`:e.placeholder??`Search to add…`,disabled:m,onChange:e=>{v(e.target.value),T(!0),D(0)},onFocus:()=>T(!0),onBlur:()=>{k.current=setTimeout(()=>T(!1),120)},onKeyDown:P}),l(f,{className:`h-3.5 w-3.5 shrink-0 cursor-pointer text-foreground-subtle`,onMouseDown:e=>{e.preventDefault(),k.current&&clearTimeout(k.current),T(e=>!e),O.current?.focus()}})]}),x&&!m&&l(`div`,{id:`msel-${e.key}`,role:`listbox`,className:`mt-1 max-h-56 overflow-y-auto rounded-md border border-border bg-surface shadow-lg`,onMouseDown:e=>{e.preventDefault()},children:j.length===0?a(`div`,{className:`px-2.5 py-2 text-[11px] text-foreground-subtle italic`,children:[`No matches for “`,_,`”`]}):j.map((e,t)=>{let n=u.includes(e.value),r=!n&&h;return a(`button`,{type:`button`,role:`option`,"aria-selected":n,disabled:r,className:[`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-xs transition-colors`,t===E?`bg-primary/10`:`hover:bg-surface-hover`,r?`opacity-40 cursor-not-allowed`:`cursor-pointer`].join(` `),onMouseEnter:()=>D(t),onClick:()=>N(e.value),children:[l(`span`,{className:[`flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded border`,n?`border-primary bg-primary text-white`:`border-border`].join(` `),children:n&&l(p,{className:`h-2.5 w-2.5`})}),l(`span`,{className:`truncate text-foreground`,children:e.label})]},e.value)})}),I&&l(`p`,{className:w,children:I})]})}function E({deviceId:e,mode:n}){let{data:r,isLoading:i,isFetching:o,isError:s,refetch:c}=t({deviceId:e},{enabled:Number.isFinite(e)}),d=r?.devices??[];return a(`div`,{className:`mt-3 rounded-md border border-border bg-background p-2.5`,children:[a(`div`,{className:`flex items-center justify-between mb-1.5`,children:[a(`span`,{className:`text-[11px] font-medium text-foreground`,children:[`Resolved links`,l(`span`,{className:`ml-1.5 text-[10px] font-normal text-foreground-subtle`,children:(r?.mode??n)===`auto`?`children + same location`:`children + manual list`})]}),a(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-50`,disabled:o,onClick:()=>void c(),title:`Re-run the resolver`,children:[l(u,{className:`h-3 w-3 ${o?`animate-spin`:``}`}),`Refresh`]})]}),i?a(`div`,{className:`flex items-center gap-1.5 py-1 text-[11px] text-foreground-subtle`,children:[l(m,{className:`h-3 w-3 animate-spin`}),`Resolving…`]}):s?l(`p`,{className:`py-1 text-[11px] text-danger`,children:`Failed to resolve linked devices.`}):d.length===0?l(`p`,{className:`py-1 text-[11px] text-foreground-subtle italic`,children:`No linked devices resolved.`}):l(`div`,{className:`flex flex-wrap gap-1`,children:d.map(e=>a(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border bg-surface px-1.5 py-0.5 text-[11px] text-foreground max-w-full`,title:e.location??void 0,children:[l(`span`,{className:`truncate`,children:e.name}),e.location!==null&&e.location.length>0&&a(`span`,{className:`inline-flex items-center gap-0.5 shrink-0 text-[10px] text-foreground-subtle`,children:[l(_,{className:`h-2.5 w-2.5`}),e.location]})]},e.deviceId))})]})}i();var D=`_linkedDevicesMode`,O=`_linkedDeviceIds`;function k(e){return e.type===`multiselect`}function A({field:t,values:r,onChange:i,disabled:a,translationFn:o,onTestField:s,externalProbe:c,allFields:u,onAction:d}){return k(t)&&x(t.options.length)?n(t,r,u)?l(T,{field:t,value:r[t.key],onChange:e=>i(t.key,e),disabled:a,translationFn:o}):null:l(e,{field:t,values:r,onChange:i,disabled:a,translationFn:o,onTestField:s,externalProbe:c,allFields:u,onAction:d})}function j(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function M(e,t){if(e!==void 0)return t&&j(e)?t(e):e}function N({section:t,values:r,onChange:i,disabled:o,translationFn:u,onTestField:d,probeResults:f,onAction:p,deviceId:m}){let[h,g]=c(t.defaultCollapsed??!1),_=t.style===`accordion`;if(t.fields.reduce((e,i)=>e+ +!!n(i,r,t.fields),0)===0)return null;let v=t.fields.some(e=>`key`in e&&e.key===D),y=r[D]===`manual`?`manual`:`auto`,b=v&&y!==`manual`?t.fields.filter(e=>!(`key`in e&&e.key===O)):t.fields,x=v?1:t.columns??2,S=x===1?`grid-cols-1`:x===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:x===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`,C=t.fields.length===1&&t.fields[0]?.type===`widget`?t.fields[0]:void 0;return a(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},children:[!(C!==void 0||!t.title&&!t.description)&&a(`div`,{className:[`flex items-center justify-between mb-2`,_?`cursor-pointer`:``].join(` `),onClick:_?()=>g(e=>!e):void 0,children:[a(`div`,{children:[t.title&&l(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:M(t.title,u)}),t.description&&l(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:M(t.description,u)})]}),_&&l(`span`,{className:`text-foreground-subtle text-xs ml-2`,children:h?`▸`:`▾`})]}),!h&&(C===void 0?a(s,{children:[l(`div`,{className:`grid ${S} gap-x-3 gap-y-2.5`,children:b.map(e=>l(A,{field:e,values:r,onChange:i,disabled:o,translationFn:u,onTestField:d,externalProbe:f?.[e.key],allFields:t.fields,onAction:p},e.key))}),v&&m!==void 0&&l(E,{deviceId:m,mode:y})]}):l(e,{field:C,values:r,onChange:i,disabled:o,translationFn:u,onTestField:d,externalProbe:f?.[C.key],allFields:t.fields,onAction:p},C.key))]})}function P({schema:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,probeResults:o,onClearProbe:s,onAction:c,deviceId:u}){let d=(e,r)=>{n({...t,[e]:r}),s?.(e)};return l(`div`,{className:`space-y-4`,children:e.sections.map((e,n)=>l(N,{section:e,values:t,onChange:d,disabled:r,translationFn:i,onTestField:a,probeResults:o,onAction:c,deviceId:u},`${e.id}-${n}`))})}export{_ as n,P as t};