@camstack/addon-admin-ui 1.2.15 → 1.2.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/AddLocationWizard-KwzmlSoV.js +1 -0
- package/dist/assets/{AddonCollectionPage-D4dNkjD9.js → AddonCollectionPage-Dn32SNWM.js} +1 -1
- package/dist/assets/Addons-EyEW4D4A.js +1 -0
- package/dist/assets/{AdminTabs-B6qnIaak.js → AdminTabs-57hhQmVl.js} +1 -1
- package/dist/assets/{AiProfiles-DnuLTZqB.js → AiProfiles-uNlhciHT.js} +1 -1
- package/dist/assets/{BrokerForm-C99fSuRo.js → BrokerForm-DyoPjxXz.js} +1 -1
- package/dist/assets/{Capabilities-B8SGK49R.js → Capabilities-cVsIOc2t.js} +1 -1
- package/dist/assets/{CapabilityBadges-BTZKlfM2.js → CapabilityBadges-s1q6EazS.js} +1 -1
- package/dist/assets/Cluster-BkmB4wXT.js +1 -0
- package/dist/assets/{ClusterRecordingTab-BPSdzcK3.js → ClusterRecordingTab-BH11-IbA.js} +1 -1
- package/dist/assets/{Dashboard-DCFIPV11.js → Dashboard-CwGNZIik.js} +1 -1
- package/dist/assets/Data-DU6dKN0-.js +1 -0
- package/dist/assets/DetectionIntelligence-DgBcQaJ7.js +1 -0
- package/dist/assets/DeviceAggregateSection-DDZxpHxU.js +1 -0
- package/dist/assets/DeviceDetail-Z501iVY2.js +2 -0
- package/dist/assets/{Devices-Dzpvq_f7.js → Devices-BUppgEis.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-CNBEeRdP.js → EmbedPlayerPage-DyKLMuTg.js} +1 -1
- package/dist/assets/Events-DRMEOb-1.js +1 -0
- package/dist/assets/{FormBuilder-CMFZXwvq.js → FormBuilder-V9-ZYyfi.js} +1 -1
- package/dist/assets/Identity-BOlAVEHc.js +1 -0
- package/dist/assets/IntegrationDetail-xhGos6_v.js +1 -0
- package/dist/assets/{Integrations-B1Ld1HH1.js → Integrations-CXfoHU1-.js} +1 -1
- package/dist/assets/{Integrations-B3rD6hIo.js → Integrations-Dp5hPLpw.js} +1 -1
- package/dist/assets/{Logs-CYpS3BpR.js → Logs-kyji_5ss.js} +1 -1
- package/dist/assets/{MotionZonesSettings-2auRIiQ1.js → MotionZonesSettings-M7Q0c7HT.js} +1 -1
- package/dist/assets/{MyAccess-D3_q9-33.js → MyAccess-BP00gmMz.js} +1 -1
- package/dist/assets/Network-BupOQchv.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-CgGvimGW.js → NodeAddonsSettingsPanel-BHYPuuzP.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-COSPUL-L.js → NodeInferenceDevices-CYZafvHq.js} +1 -1
- package/dist/assets/Notifications-C7yz_fFq.js +1 -0
- package/dist/assets/Pipeline-Cc89loIx.js +1 -0
- package/dist/assets/{Plates-C96Mahmu.js → Plates-CaHuT1aj.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-C2PIvv63.js → PrivacyMaskSettings-C8tsyRZP.js} +1 -1
- package/dist/assets/{ProviderIcon-DQ9yuo_L.js → ProviderIcon-CD80TWfL.js} +1 -1
- package/dist/assets/Recordings-Ds0k0Oit.js +1 -0
- package/dist/assets/{ScanNetworkModal-Cl1Mdjki.js → ScanNetworkModal-C1fdwcgx.js} +1 -1
- package/dist/assets/{Settings-CvCaq_zC.js → Settings-D9xYfuNz.js} +1 -1
- package/dist/assets/{Showroom-BCsIYYwv.js → Showroom-DfupwGEQ.js} +1 -1
- package/dist/assets/{Terminal-BpPIZ0or.js → Terminal-QIfVJ57m.js} +2 -2
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BALp_9qY.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DTU5DNxA.js} +1 -1
- package/dist/assets/{build-cluster-graph-cp3KQH-1.js → build-cluster-graph-DryWXcym.js} +1 -1
- package/dist/assets/circle-check-big-Cz1WD2g9.js +1 -0
- package/dist/assets/clock-D9iqCSCa.js +1 -0
- package/dist/assets/{copy-UBfFgSz-.js → copy-xvYnf3mn.js} +1 -1
- package/dist/assets/{debounced-invalidate-BsGZbF6v.js → debounced-invalidate-CT06Xct6.js} +1 -1
- package/dist/assets/dist-9AilmwYu.js +7 -0
- package/dist/assets/{dist-CvIYYU5j.js → dist-kk5V4ONk.js} +1 -1
- package/dist/assets/{download-BpNiVwyM.js → download-4PdCPJIH.js} +1 -1
- package/dist/assets/{face-bbox-BScALk_z.js → face-bbox-BOfEr6-A.js} +1 -1
- package/dist/assets/{hostInit-DFZvs0Jw.js → hostInit-BbElAo79.js} +1 -1
- package/dist/assets/index-DUFmNDGR.js +4 -0
- package/dist/assets/index-D_09pXCE.css +2 -0
- package/dist/assets/{key-round-BPb5gRuL.js → key-round-BluylYau.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-1f1c06da.js → mf-entry-bootstrap-0-d0572cd2.js} +2 -2
- package/dist/assets/{pencil-Bcfk7YmX.js → pencil-upvlHQDr.js} +1 -1
- package/dist/assets/{player-overlays-CpNYQPHP.js → player-overlays-DFxnnQ5-.js} +1 -1
- package/dist/assets/plus-pXafUidG.js +1 -0
- package/dist/assets/{radio-BH-ZU1HE.js → radio-CNyLw5GQ.js} +1 -1
- package/dist/assets/{refresh-cw-hhKexEfo.js → refresh-cw-Brd1nmbC.js} +1 -1
- package/dist/assets/remoteEntry-CNHP9pn9.js +1 -0
- package/dist/assets/{rotate-ccw-CbpUNSqs.js → rotate-ccw-CrfFxSL1.js} +1 -1
- package/dist/assets/rotate-cw-BvJwWYA6.js +1 -0
- package/dist/assets/search-DHWQ7t3y.js +1 -0
- package/dist/assets/{send-Cyy_G5i9.js → send-DcQrPOWq.js} +1 -1
- package/dist/assets/{server-BxRe5xIW.js → server-s54U0Xav.js} +1 -1
- package/dist/assets/square-CqUnowVe.js +1 -0
- package/dist/assets/{square-check-big-hPLl5NdC.js → square-check-big-CkGVGfz1.js} +1 -1
- package/dist/assets/src-Btp5jZp0.js +67 -0
- package/dist/assets/src-DlGmnrz9.js +7 -0
- package/dist/assets/{upload-C6Q1-uQx.js → upload-ZqMKZ88x.js} +1 -1
- package/dist/assets/{useEventInvalidation-Bh_CgFlD.js → useEventInvalidation-ByOUWkAr.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-C9LrTlPE.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CsWv8uI6.js} +2 -2
- package/dist/assets/{wifi-CL8vr9lV.js → wifi-C008K8Xa.js} +1 -1
- package/dist/assets/{zap-DZXxY1Hy.js → zap-VYSIuI1A.js} +1 -1
- package/dist/index.html +6 -6
- package/dist/server/addon.js +432 -78
- package/package.json +1 -1
- package/dist/assets/AddLocationWizard-BzfZuUFE.js +0 -1
- package/dist/assets/Addons-KlOfEhx8.js +0 -1
- package/dist/assets/Cluster-COcBiWpg.js +0 -1
- package/dist/assets/Data-_pY_q5xu.js +0 -1
- package/dist/assets/DetectionIntelligence-B6Dj5dVX.js +0 -1
- package/dist/assets/DeviceDetail-N6WvCekZ.js +0 -2
- package/dist/assets/Events-B5T59IPR.js +0 -1
- package/dist/assets/Identity-BbNZdgPf.js +0 -1
- package/dist/assets/IntegrationDetail-DEPSilP_.js +0 -1
- package/dist/assets/Network-DIVAg_f5.js +0 -1
- package/dist/assets/Notifications-Bv4whDil.js +0 -1
- package/dist/assets/Pipeline-l_vZ2VML.js +0 -1
- package/dist/assets/Recordings-C2R7zGta.js +0 -1
- package/dist/assets/circle-check-big-4_1SeqzL.js +0 -1
- package/dist/assets/clock-CmbYDH1e.js +0 -1
- package/dist/assets/dist-CphRM5WA.js +0 -7
- package/dist/assets/index-0YJ-haW4.css +0 -2
- package/dist/assets/index-Cl-M8KBA.js +0 -4
- package/dist/assets/plus-z-WZstU2.js +0 -1
- package/dist/assets/remoteEntry-C6sBv4xP.js +0 -1
- package/dist/assets/rotate-cw-CQj7EyBl.js +0 -1
- package/dist/assets/search-DqoMv21b.js +0 -1
- package/dist/assets/square-CEBWDX93.js +0 -1
- package/dist/assets/src-Cv9CvT8c.js +0 -7
- package/dist/assets/src-DHFCkQHW.js +0 -67
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Et as e,Ga as t,Gt as n,Ht as r,Jt as i,Kt as a,Ut as o,Vt as s,Wt as c,Xt as l,Yt as u,bt as d,fa as f,ga as p,ma as m,pa as h,qt as g,xt as _}from"./src-Btp5jZp0.js";import{I as v,Q as y,S as b,W as x,a as S,b as C,o as w,q as T,x as E,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{p as O}from"./player-overlays-DFxnnQ5-.js";import{a as k,i as A,n as j,r as M,t as N}from"./AddLocationWizard-KwzmlSoV.js";import{t as P}from"./download-4PdCPJIH.js";import{t as F}from"./pencil-upvlHQDr.js";import{n as I,t as ee}from"./AddonCollectionPage-Dn32SNWM.js";import{t as te}from"./plus-pXafUidG.js";import{t as L}from"./rotate-cw-BvJwWYA6.js";import{H as ne,I as re,P as ie,S as R,W as z,i as B,m as V,s as H}from"./index-DUFmNDGR.js";import{t as U}from"./AdminPage-Dq33XE9j.js";import{n as ae}from"./authed-media-XfBD4Ma-.js";import{t as W}from"./format-size-CO9d3C3-.js";import{t as G}from"./AdminTabs-57hhQmVl.js";import{t as K}from"./addon-display-names-DvSEQty-.js";var q=z(`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`}]]),J=z(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),oe=z(`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`}]]),se=z(`file-text`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]);y();var ce=new Set([`recordings`,`recordingsLow`]);function le(e){let t=e.filesTotal===null?``:`/${e.filesTotal}`,n=Math.round(e.bytesMoved/(1024*1024)),r=`${e.entities.join(`+`)}: ${e.filesMoved}${t} files, ${n} MB — ${e.state}`;return e.error?`${r} (${e.error})`:r}function ue({location:e,onClose:t}){let n=O().trpcClient,[r,i]=T(``),[a,o]=T(!0),[s,c]=T(!0),[l,u]=T(null),[d,f]=T(!1),p=S({queryKey:[`storage`,`listLocations`,`relocate`],queryFn:()=>n.storage.listLocations.query({})}),m=x(()=>(p.data??[]).filter(t=>t.id!==e.id&&ce.has(t.type)&&t.config.readOnly!==!0&&t.config.basePath!==e.config.basePath),[p.data,e]),h=S({queryKey:[`relocate`,`jobs`],queryFn:async()=>{let[e,t]=await Promise.all([n.recording.getRelocateStatus.query({}).catch(()=>[]),n.pipelineAnalytics.getMediaRelocateStatus.query({}).catch(()=>[])]);return[...e,...t].sort((e,t)=>t.startedAt-e.startedAt)},refetchInterval:2e3}),g=h.data??[],_=g.some(e=>e.state===`running`);D(()=>{r===``&&m.length>0&&i(m[0].id)},[m,r]);let v=async()=>{if(r!==``){u(null),f(!0);try{a&&await n.recording.relocateFootage.mutate({fromLocationId:e.id,toLocationId:r}),s&&await n.pipelineAnalytics.relocateMedia.mutate({toLocationId:r}),await h.refetch()}catch(e){u(e instanceof Error?e.message:String(e))}finally{f(!1)}}},y=async e=>{try{e.entities.includes(`media`)?await n.pipelineAnalytics.cancelMediaRelocate.mutate({jobId:e.jobId}):await n.recording.cancelRelocate.mutate({jobId:e.jobId}),await h.refetch()}catch{}};return E(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:b(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[b(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[b(`div`,{className:`space-y-0.5`,children:[b(`h2`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[E(k,{className:`h-3.5 w-3.5`}),`Relocate from `,e.displayName]}),E(`p`,{className:`text-xs text-foreground-subtle`,children:`Throttled background move; safe to re-run — it resumes where it stopped. Mark this location read-only first so nothing new lands here.`})]}),E(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:E(B,{className:`h-4 w-4`})})]}),b(`div`,{className:`p-4 space-y-3`,children:[b(`div`,{className:`space-y-1`,children:[E(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Target location`}),m.length===0?E(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No writable recordings location on a different root to move to.`}):E(`select`,{value:r,onChange:e=>i(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:m.map(e=>b(`option`,{value:e.id,children:[e.displayName,` (`,String(e.config.basePath??e.id),`)`]},e.id))})]}),b(`div`,{className:`space-y-1`,children:[b(`label`,{className:`flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[E(`input`,{type:`checkbox`,checked:a,onChange:e=>o(e.target.checked),className:`accent-primary`}),`Footage (segments + strips)`]}),b(`label`,{className:`flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[E(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked),className:`accent-primary`}),`Event media (crops, thumbnails, snapshots)`]})]}),l&&E(`p`,{className:`text-[11px] text-danger`,children:l}),g.length>0&&E(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:g.slice(0,4).map(e=>b(`div`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[E(`span`,{className:`flex-1 truncate text-[11px] text-foreground`,children:le(e)}),e.state===`running`&&E(`button`,{onClick:()=>void y(e),className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground`,children:`Cancel`})]},e.jobId))})]}),b(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[E(`button`,{onClick:t,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground`,children:`Close`}),E(`button`,{onClick:()=>void v(),disabled:r===``||d||_||!a&&!s,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:_?`Running…`:`Start relocation`})]})]})})}y();function de(){let e=w(),n=t(),{data:r,isLoading:i,isError:a}=m({}),o=h(),s=x(()=>o.data??[],[o.data]),[c,l]=T(null),[u,d]=T(null),[g,_]=T(null),v=f({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),y=p({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),S=e=>{e.isDefault||y.mutate({id:e.id,type:e.type,providerId:e.providerId,displayName:e.displayName,config:e.config,isDefault:!0})},C=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`})&&v.mutate({id:e.id})},D=x(()=>{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]),O=i||o.isLoading,k=a||o.isError;return b(U,{children:[O&&E(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),k&&E(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!O&&!k&&b(`div`,{className:`space-y-3`,children:[s.length===0&&E(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:`No storage locations declared by any installed addon.`}),s.map(e=>E(M,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:D.get(e.id)??[],onAdd:e=>l(e),onEdit:e=>d(e),onDelete:e=>{C(e)},onSetDefault:e=>S(e),...e.id===`recordings`||e.id===`recordingsLow`?{onRelocate:e=>_(e)}:{}},e.id))]}),c!==null&&E(N,{initialType:c,onClose:()=>l(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),l(null)}}),u!==null&&E(j,{location:u,onClose:()=>d(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),d(null)}}),g&&E(ue,{location:g,onClose:()=>_(null)})]})}y();var fe=[[`backup`,`listDestinations`]],pe=[`backup`,`listArchives`];function me({destinationId:e,restoreSupported:n,onOpenRestoreWizard:r}){let i=w(),a=t(),{data:o,isLoading:l,isError:u}=c({destinationId:e}),d=o??[],f=s({onSuccess:()=>{i.invalidateQueries({queryKey:[[...pe]]}),i.invalidateQueries({queryKey:fe})}}),p=v(async t=>{await a({title:`Delete this archive?`,message:`Permanently deletes "${t.label??t.id}" and frees ${W(t.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&f.mutate({destinationId:e,backupId:t.id})},[a,e,f]),[m,h]=T(null),g=v(async t=>{h(t.id);try{let n=await ae(he(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{h(null)}},[e]),_=x(()=>[...d].toSorted((e,t)=>t.createdAt-e.createdAt),[d]);return l?E(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):u?E(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):_.length===0?E(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):E(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:b(`table`,{className:`w-full text-xs min-w-[640px]`,children:[E(`thead`,{children:b(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[E(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),E(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),E(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),E(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),E(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),E(`tbody`,{children:_.map(t=>b(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[E(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:Y(t.createdAt)}),E(`td`,{className:`px-3 py-1.5 text-foreground`,children:t.label??E(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),E(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:t.locations.join(`, `)}),E(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:W(t.sizeBytes)}),E(`td`,{className:`px-3 py-1.5`,children:b(`div`,{className:`flex items-center justify-end gap-1`,children:[b(`button`,{onClick:()=>{g(t)},disabled:m===t.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 disabled:opacity-50`,title:`Download archive`,children:[m===t.id?E(R,{className:`h-3 w-3 animate-spin`}):E(P,{className:`h-3 w-3`}),`Download`]}),n&&r&&b(`button`,{onClick:()=>r({destinationId:e,archiveId:t.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:[E(L,{className:`h-3 w-3`}),`Restore`]}),E(`button`,{onClick:()=>{p(t)},disabled:f.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete archive`,children:f.isPending?E(R,{className:`h-3 w-3 animate-spin`}):E(H,{className:`h-3 w-3`})})]})})]},t.id))})]})})}function he(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`})}y();var X=[[`backup`,`listSchedules`]];function ge({onEdit:e,onOpenRestoreWizard:t}){let{data:r,isLoading:i,isError:o}=a(),s=r??[],c=n().data??[],l=x(()=>{let e=new Map;for(let t of c)e.set(t.id,t);return e},[c]),[u,d]=T(null),f=e=>{d(t=>t===e?null:e)};return i?E(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading backup entries…`}):o?E(`div`,{className:`text-xs text-danger`,children:`Failed to load backup entries`}):s.length===0?E(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:E(`p`,{className:`text-xs text-foreground-subtle`,children:`No backup entries yet. Create one to schedule backups across one or more storage locations.`})}):E(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:b(`table`,{className:`w-full text-xs min-w-[820px]`,children:[E(`thead`,{children:b(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[E(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),E(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Entry`}),E(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),E(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Locations`}),E(`th`,{className:`text-left px-3 py-2 font-medium w-24`,children:`Retention`}),E(`th`,{className:`text-left px-3 py-2 font-medium w-48`,children:`Schedule`}),E(`th`,{className:`text-right px-3 py-2 font-medium w-52`,children:`Actions`})]})}),E(`tbody`,{children:s.map(n=>E(_e,{row:n,destById:l,isOpen:u===n.id,onToggle:()=>f(n.id),onEdit:()=>e(n),...t?{onOpenRestoreWizard:t}:{}},n.id))})]})})}function _e({row:e,destById:n,isOpen:i,onToggle:a,onEdit:o,onOpenRestoreWizard:s}){let c=w(),d=t(),f=l({onSuccess:()=>{c.invalidateQueries({queryKey:X})}}),p=r({onSuccess:()=>{c.invalidateQueries({queryKey:X})}}),m=u({onSuccess:()=>{c.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),c.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]})}}),[h,g]=T(String(e.retentionCount));D(()=>{g(String(e.retentionCount))},[e.retentionCount]);let _=x(()=>({id:e.id,label:e.label,cron:e.cron,locationIds:[...e.locationIds],retentionCount:e.retentionCount,...e.dataSources?{dataSources:[...e.dataSources]}:{}}),[e]),y=v(e=>{f.mutate({..._,enabled:e})},[f,_]),S=v(()=>{let t=Number.parseInt(h,10);if(Number.isNaN(t)||t<1){g(String(e.retentionCount));return}t!==e.retentionCount&&f.mutate({..._,enabled:e.enabled,retentionCount:t})},[f,_,h,e.retentionCount,e.enabled]),O=v(()=>{e.locationIds.length!==0&&m.mutate({destinations:[...e.locationIds],...e.dataSources&&e.dataSources.length>0?{locations:[...e.dataSources]}:{},label:e.label,retentionCount:e.retentionCount})},[m,e]),k=v(async()=>{await d({title:`Delete backup entry?`,message:`"${e.label||e.id}" will stop running. Existing archives are kept.`,confirmLabel:`Delete`,variant:`warning`})&&p.mutate({id:e.id})},[d,p,e.id,e.label]),A=e.cron.trim().length>0,j=f.isPending||p.isPending;return b(C,{children:[b(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[E(`td`,{className:`px-2 py-2`,children:E(`button`,{onClick:a,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:i?`Hide archives`:`Show archives`,children:E(i?re:ie,{className:`h-3.5 w-3.5`})})}),E(`td`,{className:`px-3 py-2`,children:b(`button`,{onClick:o,className:`text-left hover:underline focus:outline-none`,children:[E(`div`,{className:`text-foreground font-medium`,children:e.label||`(unnamed)`}),e.lastRunAt!==void 0&&b(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:[`last run `,new Date(e.lastRunAt).toLocaleString()]})]})}),E(`td`,{className:`px-3 py-2`,children:E(`label`,{className:`inline-flex items-center cursor-pointer`,children:E(`input`,{type:`checkbox`,className:`accent-primary`,checked:e.enabled,disabled:j,onChange:e=>y(e.target.checked)})})}),E(`td`,{className:`px-3 py-2`,children:b(`div`,{className:`flex flex-wrap gap-1`,children:[e.locationIds.length===0&&E(`span`,{className:`text-[11px] text-danger italic`,children:`No locations`}),e.locationIds.map(e=>E(`span`,{className:`inline-flex items-center rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-foreground`,title:e,children:n.get(e)?.displayName??e},e))]})}),E(`td`,{className:`px-3 py-2`,children:E(`input`,{type:`number`,min:1,max:1e3,value:h,disabled:j,onChange:e=>g(e.target.value),onBlur:S,onKeyDown:t=>{t.key===`Enter`&&t.target.blur(),t.key===`Escape`&&g(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`})}),E(`td`,{className:`px-3 py-2`,children:b(`button`,{onClick:o,className:`group flex flex-col items-start gap-0.5 text-left`,title:`Edit schedule`,children:[b(`span`,{className:`inline-flex items-center gap-1`,children:[E(oe,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),E(`span`,{className:`font-mono text-[11px] text-foreground`,children:A?e.cron:`Manual`})]}),A&&e.nextRunAt!==void 0&&b(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`next `,new Date(e.nextRunAt).toLocaleString()]})]})}),E(`td`,{className:`px-3 py-2`,children:b(`div`,{className:`flex items-center justify-end gap-1.5`,children:[b(`button`,{onClick:O,disabled:m.isPending||e.locationIds.length===0,className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,title:`Run this entry now`,children:[m.isPending?E(R,{className:`h-3 w-3 animate-spin`}):E(I,{className:`h-3 w-3`}),`Run now`]}),E(`button`,{onClick:o,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-foreground hover:bg-primary/5`,title:`Edit entry`,children:E(F,{className:`h-3 w-3`})}),E(`button`,{onClick:()=>{k()},disabled:j,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-danger hover:border-danger/40 disabled:opacity-50`,title:`Delete entry`,children:E(H,{className:`h-3 w-3`})})]})})]}),i&&E(`tr`,{className:`border-t border-border bg-background/30`,children:b(`td`,{colSpan:7,className:`px-4 py-3 space-y-4`,children:[e.locationIds.length===0&&E(`p`,{className:`text-xs text-foreground-subtle italic`,children:`This entry has no locations selected.`}),e.locationIds.map(e=>b(`div`,{className:`space-y-1.5`,children:[E(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:n.get(e)?.displayName??e}),E(me,{destinationId:e,restoreSupported:n.get(e)?.restoreSupported??!0,...s?{onOpenRestoreWizard:s}:{}})]},e))]})})]})}y();var Z=[{id:`manual`,label:`Manual only`,cron:``},{id:`hourly`,label:`Every hour`,cron:`0 * * * *`,description:`On the hour`},{id:`every-3h`,label:`Every 3 hours`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,label:`Every 6 hours`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,label:`Daily at 03:00`,cron:`0 3 * * *`,description:`Every night at 3 AM`},{id:`weekly-sun`,label:`Weekly Sunday 03:00`,cron:`0 3 * * 0`,description:`Sunday morning at 3 AM`}];function ve(e){let t=e.trim();for(let e of Z)if(e.cron===t)return e.id;return`custom`}function ye({value:e,onChange:t,previewCount:n=5,disabled:r=!1}){let i=ve(e),[a,o]=T(i===`custom`);D(()=>{i!==`custom`&&o(!1)},[i]);let s=Se(e,250),c=g({cron:s,count:n},{enabled:s.trim().length>0}),l=c.data??null,u=e=>{o(!1),t(e.cron)},d=a||i===`custom`;return b(`div`,{className:`space-y-3`,children:[b(`div`,{className:`space-y-1`,children:[E(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),b(`div`,{className:`flex flex-wrap gap-1.5`,children:[Z.map(e=>E(`button`,{type:`button`,onClick:()=>u(e),disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!a&&i===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.description??e.label,children:e.label},e.id)),E(`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 `+(d?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),d&&b(`div`,{className:`space-y-1`,children:[E(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),E(`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`}),b(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,E(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),E(be,{cron:s,preview:l,loading:c.isFetching})]})}function be({cron:e,preview:t,loading:n}){return n&&t===null?b(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[E(R,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?E(`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.`}):b(`div`,{className:`space-y-1`,children:[E(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),E(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>b(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[E(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),E(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:xe(e)})]},`${e}-${t}`))})]}):E(`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 xe(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 Se(e,t){let[n,r]=T(e),i=x(()=>e,[e]);return D(()=>{let e=setTimeout(()=>r(i),t);return()=>clearTimeout(e)},[i,t]),n}y();var Ce=[[`backup`,`listSchedules`]];function we({entry:e,onClose:t,onSaved:r}){let i=w(),a=n(),o=a.data??[],[s,c]=T(e?.label??``),[u,d]=T(e?.cron??`0 3 * * *`),[f,p]=T(e?.enabled??!0),[m,h]=T(String(e?.retentionCount??7)),[g,_]=T(new Set(e?.locationIds??[])),v=l({onSuccess:()=>{i.invalidateQueries({queryKey:Ce}),r()}}),y=e=>{_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},S=Number.parseInt(m,10),C=x(()=>s.trim().length>0&&g.size>0&&!Number.isNaN(S)&&S>=1&&S<=1e3,[s,g,S]),D=()=>{C&&v.mutate({...e?{id:e.id}:{},label:s.trim(),cron:u.trim(),enabled:f,locationIds:Array.from(g),retentionCount:S})},O=v.error instanceof Error?v.error.message:null;return E(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:b(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[b(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3 sticky top-0 bg-surface`,children:[E(`h2`,{className:`text-sm font-semibold text-foreground`,children:e?`Edit backup entry`:`New backup entry`}),E(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:E(B,{className:`h-4 w-4`})})]}),b(`div`,{className:`p-4 space-y-4`,children:[b(`div`,{className:`space-y-1`,children:[E(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Name`}),E(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`Nightly offsite`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),b(`div`,{className:`space-y-1.5`,children:[b(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:[`Locations (`,g.size,` selected)`]}),a.isLoading&&b(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[E(R,{className:`h-3.5 w-3.5 animate-spin`}),`Loading locations…`]}),!a.isLoading&&o.length===0&&E(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:"No `backups` storage locations configured. Add one in Settings → Storage first."}),o.length>0&&E(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-52 overflow-y-auto`,children:o.map(e=>b(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[b(`div`,{className:`flex items-center gap-2`,children:[E(`input`,{type:`checkbox`,checked:g.has(e.id),onChange:()=>y(e.id),className:`accent-primary`}),E(`span`,{className:`text-foreground`,children:e.displayName})]}),b(`div`,{className:`flex items-center gap-1.5`,children:[E(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-surface border border-border rounded px-1.5 py-0.5`,children:e.kind}),E(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]},e.id))})]}),b(`div`,{className:`grid grid-cols-2 gap-3`,children:[b(`div`,{className:`space-y-1`,children:[E(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Retention (archives kept)`}),E(`input`,{type:`number`,min:1,max:1e3,value:m,onChange:e=>h(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`})]}),b(`div`,{className:`space-y-1`,children:[E(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Enabled`}),b(`label`,{className:`inline-flex items-center gap-2 py-1.5 cursor-pointer`,children:[E(`input`,{type:`checkbox`,checked:f,onChange:e=>p(e.target.checked),className:`accent-primary`}),E(`span`,{className:`text-xs text-foreground-subtle`,children:`Run on schedule`})]})]})]}),b(`div`,{className:`space-y-1.5 border-t border-border pt-3`,children:[E(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Schedule`}),E(ye,{value:u,onChange:d,disabled:v.isPending})]}),O&&E(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:O})]}),b(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3 sticky bottom-0 bg-surface`,children:[E(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),b(`button`,{onClick:D,disabled:!C||v.isPending,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[v.isPending&&E(R,{className:`h-3.5 w-3.5 animate-spin`}),e?`Save`:`Create entry`]})]})]})})}y();var Te=[[`backup`,`list`]];function Ee({initialDestinationId:e,initialArchiveId:t,onClose:r,onScheduled:a}){let s=w(),[l,u]=T(e&&t?2:1),[d,f]=T(e),[p,m]=T(t),[h,g]=T(new Set),{data:_}=n(),v=_??[],{data:y,isLoading:S}=c({destinationId:d??``},{enabled:!!d}),C=y??[];D(()=>{if(d!==void 0)return;let e=v.filter(e=>e.restoreSupported);e.length===1&&f(e[0].id)},[d,v]);let{data:O}=o({destinationId:d??``,backupId:p??``},{enabled:!!d&&!!p}),k=x(()=>O?.locations??[],[O]);D(()=>{k.length!==0&&g(e=>e.size===0?new Set(k):e)},[k]);let A=i({onSuccess:()=>{s.invalidateQueries({queryKey:Te}),a(),r()}}),j=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},M=!!d&&!!p,N=h.size>0,P=M&&N&&!A.isPending,F=()=>{!d||!p||A.mutate({destinationId:d,backupId:p,locations:[...h]})};return E(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:b(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[b(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[b(`div`,{className:`space-y-0.5`,children:[E(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),b(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,l,` of 3 —`,` `,l===1?`pick source`:l===2?`pick locations`:`confirm`]})]}),E(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,children:E(B,{className:`h-4 w-4`})})]}),l===1&&E(De,{destinations:v,destinationId:d,onPickDestination:e=>{f(e),m(void 0),g(new Set)},archives:C,archivesLoading:S,archiveId:p,onPickArchive:m}),l===2&&E(Oe,{locations:k,picked:h,onToggle:j}),l===3&&E(ke,{destinationName:v.find(e=>e.id===d)?.displayName??d??``,archive:C.find(e=>e.id===p),picked:[...h]}),b(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[E(`div`,{children:l>1&&b(`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:[E(ne,{className:`h-3 w-3`}),`Back`]})}),b(`div`,{className:`flex items-center gap-2`,children:[E(`button`,{onClick:r,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),l<3?b(`button`,{disabled:l===1&&!M||l===2&&!N,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`,E(J,{className:`h-3 w-3`})]}):b(`button`,{onClick:F,disabled:!P,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?E(R,{className:`h-3.5 w-3.5 animate-spin`}):E(L,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function De({destinations:e,destinationId:t,onPickDestination:n,archives:r,archivesLoading:i,archiveId:a,onPickArchive:o}){let s=e.filter(e=>e.restoreSupported);return b(`div`,{className:`p-4 space-y-3`,children:[b(`div`,{className:`space-y-1.5`,children:[E(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),b(`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:[E(`option`,{value:``,disabled:!0,children:`Select destination…`}),s.map(e=>b(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),b(`div`,{className:`space-y-1.5`,children:[E(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&E(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&i&&E(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!i&&r.length===0&&E(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&r.length>0&&E(`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 b(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[b(`div`,{className:`flex items-center gap-2`,children:[E(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>o(e.id),className:`accent-primary`}),b(`div`,{children:[E(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),E(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),E(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:W(e.sizeBytes)})]},e.id)})})]})]})}function Oe({locations:e,picked:t,onToggle:n}){return e.length===0?E(`div`,{className:`p-4`,children:E(`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.`})}):b(`div`,{className:`p-4 space-y-3`,children:[E(`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.`}),b(`div`,{className:`space-y-1.5`,children:[E(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),E(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>b(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[E(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>n(e),className:`accent-primary`}),E(`span`,{className:`font-mono text-foreground`,children:e}),E(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:je(e)})]},e))})]})]})}function ke({destinationName:e,archive:t,picked:n}){return b(`div`,{className:`p-4 space-y-3 text-xs`,children:[E(`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.`}),b(`dl`,{className:`space-y-1.5`,children:[E(Q,{term:`Destination`,value:e}),E(Q,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&E(Q,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${W(t.sizeBytes)}`}),E(Q,{term:`Locations`,value:n.length>0?n.join(`, `):`— (full archive)`})]})]})}function Q({term:e,value:t}){return b(`div`,{className:`flex justify-between gap-3`,children:[E(`dt`,{className:`text-foreground-subtle`,children:e}),E(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Ae={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function je(e){return Ae[e]??``}y();function Me(){let n=t(),r=e(),[i,a]=T(null),[o,s]=T(!1),[c,l]=T(!1),[u,d]=T(void 0),f=async()=>{await n({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&r.mutate({confirm:!0})};return b(U,{children:[b(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[b(`button`,{onClick:()=>s(!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:[E(L,{className:`h-3.5 w-3.5`}),`Restore…`]}),b(`button`,{onClick:()=>d(null),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[E(te,{className:`h-3.5 w-3.5`}),`New entry`]})]}),c&&E(`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:b(`div`,{className:`flex items-center justify-between gap-3`,children:[b(`div`,{className:`flex items-center gap-2`,children:[E(L,{className:`h-3.5 w-3.5`}),E(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),b(`button`,{onClick:()=>{f()},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?E(R,{className:`h-3.5 w-3.5 animate-spin`}):E(L,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),E(ge,{onEdit:e=>d(e),onOpenRestoreWizard:e=>a(e)}),u!==void 0&&E(we,{entry:u,onClose:()=>d(void 0),onSaved:()=>d(void 0)}),(i||o)&&E(Ee,{...i?{initialDestinationId:i.destinationId,initialArchiveId:i.archiveId}:{},onClose:()=>{a(null),s(!1)},onScheduled:()=>l(!0)})]})}y();var $=5e3,Ne={"winston-logging":`Rotated log files on this node’s disk.`,"console-logging":`stdout / stderr of the node process.`,"loki-logging":`Pushes to a Grafana Loki instance. Off until enabled with a URL.`,"hub-forwarder":`Agent-only — forwards this node’s entries to the hub.`};function Pe(){let e=_({capName:`log-destination`},{refetchInterval:$}),t=d(void 0,{refetchInterval:$}),n=x(()=>K(t.data??[]),[t.data]),r=x(()=>{let e=new Map;for(let n of t.data??[]){let t=n.description,r=n.id;typeof r==`string`&&typeof t==`string`&&t.length>0&&e.set(r,t)}return e},[t.data]);return E(ee,{title:`Logging`,subtitle:`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another. Each destination's own configuration is docked under it.`,pageIcon:V,itemIcon:se,capability:`log-destination`,installButtonLabel:`Add destination`,items:x(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive,caption:r.get(e.addonId)??Ne[e.addonId]??``})),[e.data,n,r]),isLoading:e.isLoading,emptyTitle:`No log destinations registered`,emptyDescription:`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`,renderStatusBadges:e=>e.caption.length>0?E(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.caption}):null})}function Fe(){return E(`div`,{className:`flex flex-col p-4`,children:E(G,{tabs:[{id:`storage`,label:`Storage`,icon:A,content:E(de,{})},{id:`backup`,label:`Backup`,icon:q,content:E(Me,{})},{id:`logging`,label:`Logging`,icon:V,content:E(Pe,{})}]})})}export{Fe as DataPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{$n as e,Ao as t,Co as n,Do as r,Ga as i,Jn as a,Mn as o,Qa as s,Qn as c,So as l,Xn as u,Yn as d,Zn as f,ar as p,bo as m,er as h,ir as g,ko as _,nr as v,or as y,rr as b,tr as x,wo as S,xo as ee,yo as C}from"./src-Btp5jZp0.js";import{K as w,Q as T,S as E,W as D,b as O,o as k,q as A,x as j,z as M}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{K as N}from"./src-DlGmnrz9.js";import{a as P,i as F,n as I,r as te,t as L}from"./face-bbox-BOfEr6-A.js";import{a as R,c as ne,f as z,i as B,l as re,m as V,n as H,o as ie,p as U,r as ae,s as oe,t as se,u as ce}from"./debounced-invalidate-CT06Xct6.js";import{t as W}from"./pencil-upvlHQDr.js";import{t as G}from"./plus-pXafUidG.js";import{t as le}from"./refresh-cw-Brd1nmbC.js";import{t as ue}from"./square-check-big-CkGVGfz1.js";import{t as de}from"./square-CqUnowVe.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-DUFmNDGR.js";import{t as Z}from"./AdminPage-Dq33XE9j.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`}]]);T();var $=[[`faceGallery`]];function ye({identityId:e}){let t=k(),{data:n,isLoading:r}=h({identityId:e}),i=v();function a(n){i.mutate({identityId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:$})}})}return r?E(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[j(J,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!n||n.length===0?j(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):j(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:n.map(e=>E(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?j(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):j(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:j(ve,{className:`h-6 w-6`})}),j(`button`,{type:`button`,onClick:()=>a(e),disabled:i.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove sample`,children:j(Y,{className:`h-4 w-4 text-white`})})]},e.id))})}function be({identity:e,expanded:i,onToggle:a}){let o=k(),[s,c]=A(``),[u,d]=A(!1),[p,h]=A(!1),g=b(),v=f();function y(){c(e.name),d(!0)}function x(){d(!1),c(``)}function w(){let t=s.trim();if(!t||t===e.name){x();return}g.mutate({id:e.id,name:t},{onSettled:()=>{o.invalidateQueries({queryKey:$}),x()}})}function T(){v.mutate({id:e.id},{onSettled:()=>{o.invalidateQueries({queryKey:$}),h(!1)}})}return E(`div`,{className:`rounded-md border border-border bg-surface`,children:[E(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[j(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:e.coverBase64?j(`img`,{src:`data:image/jpeg;base64,${e.coverBase64}`,alt:e.name,className:`h-full w-full object-cover`}):j(`div`,{className:`flex h-full w-full items-center justify-center`,children:j(ve,{className:`h-4 w-4 text-foreground-subtle`})})}),j(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:u?E(O,{children:[j(r,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&w(),e.key===`Escape`&&x()},className:`h-6 text-xs`,autoFocus:!0}),j(`button`,{type:`button`,onClick:w,disabled:g.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:j(q,{className:`h-3.5 w-3.5`})}),j(`button`,{type:`button`,onClick:x,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:j(Y,{className:`h-3.5 w-3.5`})})]}):j(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),j(_,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!u&&E(`div`,{className:`flex items-center gap-1`,children:[j(`button`,{type:`button`,onClick:y,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:j(W,{className:`h-3.5 w-3.5`})}),j(`button`,{type:`button`,onClick:()=>h(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:j(X,{className:`h-3.5 w-3.5`})})]}),j(`button`,{type:`button`,onClick:a,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":i?`Collapse`:`Expand`,children:j(i?K:fe,{className:`h-3.5 w-3.5`})})]}),i&&j(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:j(ye,{identityId:e.id})}),j(C,{open:p,onOpenChange:e=>!e&&h(!1),children:E(m,{children:[E(n,{children:[j(S,{children:`Delete person`}),E(ee,{children:[`Delete `,j(`strong`,{children:e.name}),` and all their samples? This cannot be undone.`]})]}),E(l,{children:[j(t,{variant:`secondary`,onClick:()=>h(!1),children:`Cancel`}),E(t,{variant:`danger`,onClick:T,disabled:v.isPending,children:[v.isPending?j(J,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function xe(){let e=k(),[n,i]=A(``),a=d();function o(){let t=n.trim();t&&a.mutate({name:t},{onSettled:()=>{e.invalidateQueries({queryKey:$}),i(``)}})}return E(`div`,{className:`flex items-center gap-2 pt-2`,children:[j(r,{placeholder:`New person name…`,value:n,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&o()},className:`h-7 text-xs flex-1`}),E(t,{variant:`primary`,size:`sm`,onClick:o,disabled:a.isPending||!n.trim(),children:[a.isPending?j(J,{className:`h-3.5 w-3.5 animate-spin`}):j(G,{className:`h-3.5 w-3.5`}),`Add`]})]})}function Se(){let{data:t,isLoading:n}=e(),[r,i]=A(null);function a(e){i(t=>t===e?null:e)}return n?E(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[j(J,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):E(`div`,{className:`space-y-2`,children:[(!t||t.length===0)&&j(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),t?.map(e=>j(be,{identity:e,expanded:r===e.id,onToggle:()=>a(e.id)},e.id)),j(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}T();function Ee(e){let[t,n]=A(null),[r,i]=A(null),[a,o]=A(!1);return M(()=>{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]),M(()=>{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 E(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[j(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),j(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:t})]})}function ke({box:e}){return j(`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:j(`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:n,onClose:r,onAssign:i,onUnassign:a,onDelete:o,actionsPending:s}){let{data:l,isFetching:u}=c({faceId:e?.faceId??``},{enabled:e!==null}),[d,f]=A(`frame`),{frameSrc:p,naturalWidth:h,naturalHeight:g,failed:_}=Ee(e?.keyFrameMediaKey),v=D(()=>{let t=De(l??[]);return t?`data:image/jpeg;base64,${t.base64}`:e?.base64?`data:image/jpeg;base64,${e.base64}`:null},[l,e]),y=D(()=>!e?.faceBbox||h===null||g===null?null:L(e.faceBbox,h,g),[e?.faceBbox,h,g]);if(e===null)return null;let b=typeof e.keyFrameMediaKey==`string`&&e.keyFrameMediaKey.length>0&&!_,x=b&&d===`frame`,S=e.assigned?e.identityName??`Assigned`:e.recognizedIdentityId?`${e.identityName??`Recognized`} (suggested)`:`Unassigned`;return j(C,{open:!0,onOpenChange:e=>!e&&r(),children:E(m,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Face detail`,className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[E(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[E(`div`,{className:`min-w-0`,children:[j(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:`Face detail`}),j(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:n})]}),j(`button`,{type:`button`,onClick:r,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:j(Y,{className:`h-4 w-4`})})]}),E(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[b&&E(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[E(`button`,{type:`button`,onClick:()=>f(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${d===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[j(F,{className:`h-3.5 w-3.5`}),` Full frame`]}),E(`button`,{type:`button`,onClick:()=>f(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${d===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[j(P,{className:`h-3.5 w-3.5`}),` Crop`]})]}),x&&p?j(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:j(B,{src:p,alt:`Full frame with detected face`,fit:`natural`,className:`w-full`,overlay:y?j(ke,{box:y}):void 0})}):v?E(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[j(B,{src:v,alt:`Detected face`,className:`h-full w-full`}),u&&j(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:j(J,{className:`h-3.5 w-3.5 animate-spin`})})]}):E(`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:[j(V,{className:`h-8 w-8 text-warning/70`}),j(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),j(`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.`})]}),E(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[j(Oe,{label:`Camera`,value:n}),j(Oe,{label:`Captured`,value:U(e.timestamp)}),j(Oe,{label:`Track`,value:e.trackId}),j(Oe,{label:`Identity`,value:S})]})]}),E(`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?E(t,{variant:`secondary`,onClick:()=>a(e.faceId),disabled:s,children:[j(I,{className:`h-3.5 w-3.5`}),` Detach`]}):E(t,{variant:`primary`,onClick:()=>i(e.faceId),disabled:s,children:[j(te,{className:`h-3.5 w-3.5`}),` Assign`]}),E(t,{variant:`secondary`,onClick:()=>o(e.faceId),disabled:s,children:[j(X,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}T();var je=[[`faceGallery`]];function Me({faceIds:e,identities:i,onDone:o}){let s=k(),c=a(),u=d(),[f,p]=A(``),[h,g]=A(!1),[_,v]=A(null),y=e!==null&&e.length>0,b=e?.length??0;function x(){g(!1),p(``),v(null)}function w(){x(),o()}function T(t){!e||e.length===0||c.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{s.invalidateQueries({queryKey:je}),w()}})}function D(){!e||!f.trim()||u.mutate({name:f.trim()},{onSuccess:e=>{e?.id&&T(e.id)},onError:()=>{s.invalidateQueries({queryKey:je}),w()}})}let O=c.isPending||u.isPending;return j(C,{open:y,onOpenChange:e=>!e&&w(),children:E(m,{children:[E(n,{children:[j(S,{children:b>1?`Assign ${String(b)} faces to person`:`Assign face to person`}),j(ee,{children:`Select an existing person or create a new one.`})]}),j(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:i.map(e=>E(`button`,{type:`button`,onClick:()=>v(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${_===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[j(`span`,{className:`font-medium`,children:e.name}),E(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),h?j(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:j(r,{placeholder:`New person name…`,value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&D()},autoFocus:!0,className:`flex-1`})}):j(`button`,{type:`button`,onClick:()=>{v(null),g(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:`+ New person…`}),E(l,{children:[j(t,{variant:`secondary`,onClick:w,disabled:O,children:`Cancel`}),h?E(t,{variant:`primary`,onClick:D,disabled:O||!f.trim(),children:[O&&j(J,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):E(t,{variant:`primary`,onClick:()=>_&&T(_),disabled:O||!_,children:[O&&j(J,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,b>1?` ${String(b)}`:``]})]})]})})}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))}T();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 E(`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:[j(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:t?.base64?j(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:``,className:`h-24 w-24 object-cover`}):j(V,{className:`h-24 w-24 p-6 text-foreground-subtle`})}),E(`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 E(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${r?`border-border opacity-40 grayscale`:`border-border`}`,children:[E(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[e.base64?j(B,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Face from ${t}`,className:`h-full w-full`}):E(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[j(V,{className:`h-7 w-7 text-warning/70`}),j(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}),j(`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:j(r?_e:Y,{className:`h-3.5 w-3.5`})})]}),E(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[j(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),j(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:z(e.timestamp,n)})]}),j(`div`,{className:`mt-1 flex items-center justify-end border-t border-border/60 px-1 py-0.5`,children:j(`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?j(J,{className:`h-4 w-4 animate-spin`}):j(X,{className:`h-4 w-4`})})})]})}function qe({open:e,onClose:n,byId:r,cameraName:a,nowMs:o,identities:s,selectMany:c}){let l=k(),d=i(),f=u(),[p,h]=A(Ve),[_,v]=A(We),[y,b]=A(null),[x,S]=A({}),[ee,w]=A(null),{data:T,isFetching:N,refetch:P}=g({threshold:p,minClusterSize:_,limit:Le},{enabled:e}),F=T??[];M(()=>{S({})},[p,_]),M(()=>{if(F.length===0){b(null);return}F.some(e=>e.representativeFaceId===y)||b(F[0]?.representativeFaceId??null)},[F]);let I=D(()=>F.find(e=>e.representativeFaceId===y)??null,[F,y]),L=I?x[I.representativeFaceId]??new Set:new Set,R=D(()=>I?Fe(I,e=>r.has(e)):[],[I,r]),ne=I?I.faceIds.length-R.length:0,z=I?Pe({...I,faceIds:R},L):[];function B(e){if(!I)return;let t=I.representativeFaceId;S(n=>({...n,[t]:Ne(n[t]??new Set,e)}))}function re(){l.invalidateQueries({queryKey:Ie})}async function V(e){await d({title:`Delete face`,message:`Permanently deletes this face crop. This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&f.mutate({faceId:e},{onSettled:re})}function H(){w(null),n()}function ie(){z.length!==0&&(c(z),H())}return E(C,{open:e,onOpenChange:e=>!e&&H(),children:[E(m,{placement:`sheet-on-mobile`,width:`lg`,"aria-label":`Look-alike groups`,className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 md:max-w-4xl`,children:[E(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border px-4 py-3`,children:[E(`div`,{className:`flex items-center justify-between gap-2`,children:[E(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[j(he,{className:`h-4 w-4 text-primary`}),` Look-alike groups`]}),j(`button`,{type:`button`,onClick:H,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:j(Y,{className:`h-4 w-4`})})]}),E(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[E(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Threshold`,j(`input`,{type:`range`,min:Re,max:ze,step:Be,value:p,onChange:e=>h(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),j(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:p.toFixed(2)})]}),E(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Min size`,j(`input`,{type:`number`,min:He,max:Ue,step:1,value:_,onChange:e=>v(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`})]}),E(t,{variant:`secondary`,onClick:()=>{S({}),P()},disabled:N,children:[N?j(J,{className:`h-3.5 w-3.5 animate-spin`}):j(le,{className:`h-3.5 w-3.5`}),`Re-analyze`]})]})]}),j(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:N&&F.length===0?E(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[j(J,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):F.length===0?j(`div`,{className:`flex flex-1 items-center justify-center py-8 text-xs text-foreground-subtle`,children:`No look-alike groups at this threshold.`}):E(O,{children:[j(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:F.map(e=>j(Ge,{cluster:e,face:r.get(e.representativeFaceId),active:e.representativeFaceId===y,onSelect:()=>b(e.representativeFaceId)},e.representativeFaceId))}),j(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:F.map(e=>j(Ge,{cluster:e,face:r.get(e.representativeFaceId),active:e.representativeFaceId===y,onSelect:()=>b(e.representativeFaceId)},e.representativeFaceId))}),j(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:I&&E(O,{children:[ne>0&&E(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:[ne,` not loaded — excluded from actions`]}),j(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,1fr))] gap-2`,children:R.map(e=>{let t=r.get(e);return t?j(Ke,{face:t,cameraName:a(t.deviceId),nowMs:o,excluded:L.has(e),onToggleExclude:()=>B(e),onDelete:()=>void V(e),deletePending:f.isPending&&f.variables?.faceId===e},e):null})})]})})]})}),E(`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:[j(t,{variant:`secondary`,onClick:ie,disabled:z.length===0,children:`Select in gallery`}),E(t,{variant:`primary`,onClick:()=>w(z),disabled:z.length===0,children:[j(te,{className:`h-3.5 w-3.5`}),` Adopt (`,z.length,`)`]})]})]}),j(Me,{faceIds:ee,identities:s,onDone:()=>w(null)})]})}T();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=k(),c=p(),l=u(),d=()=>{s.invalidateQueries({queryKey:Je})},f=()=>o(e.faceId);return E(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${r?`border-primary ring-1 ring-primary`:`border-border`}`,children:[E(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[e.base64?j(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Face from ${t}`,onClick:f,className:`h-full w-full cursor-zoom-in object-cover`}):E(`button`,{type:`button`,onClick:f,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:`No crop image — the face's crop media is missing (a pre-fix orphan). Safe to delete.`,children:[j(V,{className:`h-7 w-7 text-warning/70`}),j(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}),j(`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?j(ue,{className:`h-4 w-4 text-primary`}):j(de,{className:`h-4 w-4`})})]}),E(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[j(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),j(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:z(e.timestamp,n)}),e.identityName&&j(`p`,{className:`text-[10px] font-medium text-primary truncate`,title:e.identityName,children:e.identityName})]}),E(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?j(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),c.mutate({faceId:e.faceId},{onSettled:d})},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?j(J,{className:`h-4 w-4 animate-spin`}):j(I,{className:`h-4 w-4`})}):j(`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:j(te,{className:`h-4 w-4`})}),j(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),l.mutate({faceId:e.faceId},{onSettled:d})},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?j(J,{className:`h-4 w-4 animate-spin`}):j(X,{className:`h-4 w-4`})})]})]})}var Qe=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function $e(){let n=k(),[r,i]=A(`all`),[s,c]=A(oe),[l,d]=A(new Set),[f,m]=A(new Set),[h,g]=A(null),[_,v]=A(!1),[b,S]=A(null),{data:ee,isLoading:C}=x({limit:Ye,filter:r},{refetchInterval:3e4}),{data:w=[]}=e(),{data:T}=o({}),M=a(),N=p(),P=y(),F=u(),L=Date.now(),z=ee??[],B=D(()=>{let e=new Map;for(let t of T??[])e.set(t.id,t.name);return e},[T]),U=e=>B.get(e)??`Camera #${String(e)}`,se=D(()=>ne(z).map(e=>({id:e,name:U(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[z,B]),W=D(()=>re(ce(z,s),l),[z,s,l]),G=H(W,Xe,D(()=>JSON.stringify([r,s.fromMs,s.toMs,[...l].sort((e,t)=>e-t)]),[r,s.fromMs,s.toMs,l])),le=D(()=>new Map(z.map(e=>[e.faceId,e])),[z]),ue=D(()=>Te(W),[W]),de=b===null?null:le.get(b)??null,K=()=>{n.invalidateQueries({queryKey:Je})},q=()=>m(new Set);function fe(e){m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function pe(e){m(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function me(){pe(we(W))}let Z=[...f],Q=M.isPending||P.isPending||F.isPending,ge=N.isPending||F.isPending;function _e(){Z.length!==0&&P.mutate({faceIds:Z},{onSettled:()=>{K(),q()}})}function ve(){Z.length!==0&&Promise.allSettled(Z.map(e=>F.mutateAsync({faceId:e}))).then(()=>{K(),q()})}function $(e){S(null),g([e])}function ye(e){N.mutate({faceId:e},{onSettled:K}),S(null)}function be(e){F.mutate({faceId:e},{onSettled:K}),S(null)}let xe=W.length!==z.length;return E(`div`,{className:`relative space-y-3`,children:[E(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[j(`div`,{className:`flex items-center gap-1`,children:Qe.map(e=>j(`button`,{type:`button`,onClick:()=>i(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${r===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value))}),j(R,{onChange:c}),j(ie,{cameras:se,selected:l,onChange:d}),E(`button`,{type:`button`,onClick:()=>v(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${_?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[j(he,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!C&&ue>0&&E(`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:[j(V,{className:`h-3.5 w-3.5`}),` Select `,ue,` crop-less`]}),!C&&j(`span`,{className:`text-[10px] text-foreground-subtle ${ue>0?`ml-2`:`ml-auto`}`,children:xe?`${String(W.length)} of ${String(z.length)} faces`:`${String(W.length)} face${W.length===1?``:`s`}`})]}),f.size>0&&E(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[E(`span`,{className:`text-xs font-medium text-foreground`,children:[f.size,` selected`]}),E(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[E(t,{variant:`primary`,onClick:()=>g(Z),disabled:Q,children:[j(te,{className:`h-3.5 w-3.5`}),` Assign`]}),E(t,{variant:`secondary`,onClick:_e,disabled:Q,children:[P.isPending?j(J,{className:`h-3.5 w-3.5 animate-spin`}):j(I,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),E(t,{variant:`secondary`,onClick:ve,disabled:Q,children:[j(X,{className:`h-3.5 w-3.5`}),` Delete`]}),j(t,{variant:`ghost`,onClick:q,disabled:Q,children:j(Y,{className:`h-3.5 w-3.5`})})]})]}),C&&E(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[j(J,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!C&&W.length===0&&j(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:z.length>0?`No faces match the current date / camera filters.`:`No faces found for this filter.`}),!C&&W.length>0&&E(O,{children:[j(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(6.5rem,1fr))] gap-2`,children:G.pageItems.map(e=>j(Ze,{face:e,cameraName:U(e.deviceId),nowMs:L,selected:f.has(e.faceId),onToggleSelect:fe,onAssign:e=>g([e]),onOpenDetail:S},e.faceId))}),j(ae,{currentPage:G.page,totalItems:G.totalItems,pageSize:G.pageSize,onPageChange:G.setPage,itemNoun:`faces`})]}),j(Ae,{face:de,cameraName:de?U(de.deviceId):``,onClose:()=>S(null),onAssign:$,onUnassign:ye,onDelete:be,actionsPending:ge}),j(Me,{faceIds:h,identities:w,onDone:()=>{g(null),q()}}),j(qe,{open:_,onClose:()=>v(!1),byId:le,cameraName:U,nowMs:L,identities:w,selectMany:pe})]})}T();var et=[[`faceGallery`]],tt=2e3;function nt(){let e=k(),t=w(e);t.current=e;let n=w(void 0);n.current||=se({delayMs:tt,invalidate:()=>{t.current.invalidateQueries({queryKey:et})}}),M(()=>()=>n.current?.cancel(),[]),s(N.PipelineAnalyticsFaceGalleryChanged,()=>{n.current?.trigger()})}function rt(){return nt(),j(Z,{icon:me,title:`Faces`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:E(`section`,{className:`space-y-3`,children:[E(`div`,{children:[j(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),j(`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.`}),j(Se,{})]}),E(`div`,{className:`pt-4 border-t border-border`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),j(`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.`}),j($e,{})]})]})})}export{rt as DetectionIntelligencePage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Dn as e,Kn as t,On as n,Rn as r,_a as i,qn as a,va as o}from"./src-Btp5jZp0.js";import{I as s,K as c,Q as l,S as u,W as d,o as f,q as p,x as m}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{V as h}from"./src-DlGmnrz9.js";import{t as g}from"./FormBuilder-V9-ZYyfi.js";import{S as _,r as v}from"./index-DUFmNDGR.js";import{n as y,r as b,t as x}from"./SchemaTabBar-BrF8ZUiR.js";import{t as S}from"./StableTabPanel-p16epZGa.js";l();function C({schema:e,values:t,pendingKeys:n,onChange:r,onAction:i,onSave:a,onDiscard:o,disabled:s,activeSubTab:c,onSubTabChange:l,flattenTabs:f=!1,deviceId:h}){let _=e.tabs??[],v=d(()=>{let t=new Map;for(let n of e.sections){let e=n.tab??`general`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t},[e.sections]),b=new Set(_.map(e=>e.id)),C=[..._,...[...v.keys()].filter(e=>!b.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],w=C[0]?.id??`general`,[T,E]=p(w),D=l!==void 0,O=new Set(C.map(e=>e.id)),k=D?c&&O.has(c)?c:w:O.has(T)?T:w,A=e=>{D?l(e):E(e)},j=v.get(k)??[],M={sections:j.length<=1?j.length===1?[{...j[0],title:``}]:j:j.every(e=>!e.title)?[{...j[0],title:``,fields:j.flatMap(e=>e.fields)}]:j},N=m(y,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>o(n),saving:s});if(f||C.length<=1)return u(`div`,{className:`flex flex-col gap-3`,children:[m(g,{schema:e,values:t,onChange:r,onAction:i,disabled:s,deviceId:h}),N]});let P=new Map,F=new Map;for(let[e,t]of v){P.set(e,t.length);let r=new Set,i=e=>{for(let t of e)if(`key`in t&&typeof t.key==`string`&&r.add(t.key),t.type===`group`)i(t.fields);else if(t.type===`sub-tabs`)for(let e of t.tabs)i(e.fields)};for(let e of t)i(e.fields);let a=n.filter(e=>r.has(e)).length;a>0&&F.set(e,a)}return u(`div`,{className:`flex flex-col gap-3`,children:[m(x,{tabs:C.map(e=>({id:e.id,label:e.label})),activeId:k,onChange:A,countByTab:P,pendingByTab:F}),m(S,{tabKey:k,children:m(g,{schema:M,values:t,onChange:r,onAction:i,disabled:s,deviceId:h})}),N]})}var w=`device-export`,T=`export`,E=`Export`;function D(e){return e.type===`separator`||e.type===`info`||e.type===`object-array`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`?!1:e.type===`group`?e.fields.some(D):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(D)):e.writerCapName===w}function O(e){return e.fields.some(D)}l();function k(e,t){return t&&t===`admin`?e:!0}function A(e){if(!e)return null;let t={sections:[...e.sections].toSorted((e,t)=>{let n=e.tab??`general`,r=t.tab??`general`;return n===r?O(e)&&O(t)?e.id.localeCompare(t.id):(e.order??0)-(t.order??0):n.localeCompare(r)})};return e.tabs?{...t,tabs:e.tabs}:t}function j(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`}function M(e){return e.key}function N(e){if(!j(e))return e.value}function P(e){return j(e)?null:e}function F(e,t){for(let n of e)if(t(n),n.type===`group`)F(n.fields,t);else if(n.type===`sub-tabs`)for(let e of n.tabs)F(e.fields,t)}function I(e){if(!e)return{};let t={};for(let n of e.sections)F(n.fields,e=>{let n=M(e);n!==null&&(t[n]=N(e))});return t}function L(e,t){if(!e)return null;let n=null;for(let r of e.sections)if(F(r.fields,e=>{if(n!==null||M(e)!==t)return;let r=P(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function R(e){return{...e,fields:e.fields.map(z)}}function z(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function B(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=P(e);return n?k(t,n.minRole)?e:z(e):e})}))}}function V({deviceId:l,sectionFilter:p,activeSubTab:g,onSubTabChange:y,flattenSubTabs:x,subTabGrouping:S}){let w=f(),{user:T}=v(),E=T?.isAdmin===!0,D=c(!1),{data:k,isLoading:j}=n({deviceId:l},{refetchInterval:()=>D.current?!1:2500,enabled:Number.isFinite(l)}),{data:M}=e({deviceId:l},{enabled:Number.isFinite(l)}),N=k?.settings??null,P=k?.live??null,F=d(()=>{if(!N&&!P)return null;let e=N?.sections??[],t=(P?.sections??[]).map(R),n=[...e,...t],r=p?n.filter(p):n.filter(e=>e.location!==`top-tab`&&!O(e));if(r.length===0)return null;if(S){let e=r.map(e=>({...e,tab:S.groupOf(e)})),t=new Set(e.map(e=>e.tab)),n=S.tabs.filter(e=>t.has(e.id));return n.length>0?{tabs:n,sections:e}:{sections:e}}let i=new Set;for(let e of r)i.add(e.tab??`general`);let a=[...N?.tabs??[],...(P?.tabs??[]).filter(e=>!(N?.tabs??[]).some(t=>t.id===e.id))].filter(e=>i.has(e.id));return a.length>0?{tabs:a,sections:r}:{sections:r}},[N,P,p,S]),z=d(()=>A(F),[F]),V=d(()=>B(z,E),[z,E]),H=d(()=>I(V),[V]),U=o(),W=i(),G=t(),K=r(),q=a({onSuccess:()=>{w.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),J={isPending:q.isPending,mutate:e=>{q.mutate({deviceId:l,changes:[...e]})}},Y=b({schema:V,serverValues:H,onImmediateSave:s(e=>{let t=Object.entries(e).map(([e,t])=>{let n=L(V,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&J.mutate(t)},[V,J]),onDeferredSave:s(e=>{let t=Object.entries(e).map(([e,t])=>{let n=L(V,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&J.mutate(t)},[V,J])}),{values:X,pendingKeys:Z,handleChange:Q,handleSave:$,handleDiscard:ee}=Y;if(D.current=Y.editingPaused,j)return u(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[m(_,{className:`h-4 w-4 animate-spin mr-2`}),m(`span`,{className:`text-xs`,children:`Loading device aggregate…`})]});if(!V||V.sections.length===0)return m(`div`,{className:`text-xs text-foreground-subtle italic py-4 text-center`,children:`No aggregate contributions for this device.`});async function te(e,t,n){if(e===`regenerate-rtsp-token`){let e=[`rtspUrl:`,`regenerateToken:`].find(e=>t.startsWith(e));if(!e)throw Error(`regenerate-rtsp-token: unrecognised key "${t}" (expected "rtspUrl:<streamId>" or "regenerateToken:<streamId>")`);let n=t.slice(e.length);if(!n)throw Error(`regenerate-rtsp-token: key "${t}" has no streamId after prefix`);let r=h(l,n);await U.mutateAsync({brokerId:r}),w.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(e===`test-probe`){if(!M)return{status:`error`,error:`Device metadata not loaded yet`};try{return await G.mutateAsync({addonId:M.addonId,type:M.type,key:t,value:n})}catch(e){return{status:`error`,error:e instanceof Error?e.message:String(e)}}}if(e===`refresh-probe`){if(!t.startsWith(`probedInfo:`))throw Error(`refresh-probe: unrecognised key "${t}" (expected "probedInfo:<streamId>")`);let e=t.slice(11);if(!e)throw Error(`refresh-probe: key "${t}" has no streamId after prefix`);let n=h(l,e),r=await W.mutateAsync({brokerId:n});return w.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),r}if(e===`device-custom-action`){let e=await K.mutateAsync({deviceId:l,action:t,input:n});return w.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),e}throw Error(`[device-aggregate] unknown action "${e}"`)}return m(C,{schema:V,values:X,pendingKeys:Z,onChange:Q,onAction:te,onSave:$,onDiscard:ee,disabled:J.isPending,activeSubTab:g,onSubTabChange:y,flattenTabs:x,deviceId:l})}export{O as i,T as n,E as r,V as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{$ as e,$i as t,An as n,Bn as r,Bt as i,Cn as a,D as o,Dn as s,E as c,F as l,Fo as u,Ga as d,Gn as f,H as p,Ha as m,Hn as h,J as g,Ln as _,Lr as v,Mi as y,Mn as b,N as x,Nn as S,O as C,On as ee,P as w,Pn as te,Q as T,Ri as ne,T as E,Tt as re,U as ie,Ua as D,Un as ae,Vn as oe,W as O,Wn as k,Wr as A,X as j,Y as se,Z as ce,_r as M,a as N,ao as P,at as le,cn as ue,do as F,dr as de,eo as fe,et as pe,f as me,fo as I,g as he,gn as L,hi as ge,i as R,ii as z,io as _e,ji as ve,jn as ye,l as be,ln as xe,lo as Se,m as Ce,mo as we,n as Te,no as Ee,o as De,oo as Oe,ot as ke,p as Ae,pi as je,r as Me,rt as Ne,so as Pe,st as Fe,to as Ie,tt as Le,u as Re,uo as ze,vi as Be,vn as Ve,vr as He,wn as Ue,xi as We,y as Ge,yr as Ke,zn as qe}from"./src-Btp5jZp0.js";import{I as Je,K as B,Q as V,S as H,W as U,a as Ye,b as W,o as G,q as K,t as Xe,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 Ze,D as Qe,F as $e,M as et,N as tt,P as nt,S as rt,W as it,j as at,k as Y,v as ot,x as st}from"./src-DlGmnrz9.js";import{c as ct,k as lt,p as X,r as ut,t as dt,u as ft}from"./player-overlays-DFxnnQ5-.js";import{t as pt}from"./CapabilityBadges-s1q6EazS.js";import{n as mt,t as ht}from"./rotate-ccw-CrfFxSL1.js";import{t as gt}from"./ProviderIcon-CD80TWfL.js";import{a as _t,c as vt,i as yt,n as bt,s as xt}from"./NodeInferenceDevices-CYZafvHq.js";import{n as St}from"./FormBuilder-V9-ZYyfi.js";import{t as Ct}from"./pencil-upvlHQDr.js";import{t as wt}from"./plus-pXafUidG.js";import{t as Tt}from"./refresh-cw-Brd1nmbC.js";import{t as Et}from"./rotate-cw-BvJwWYA6.js";import{t as Dt}from"./server-s54U0Xav.js";import{t as Ot}from"./wifi-C008K8Xa.js";import{A as kt,J as At,K as jt,L as Mt,S as Nt,U as Pt,V as Ft,W as It,a as Lt,c as Rt,i as zt,j as Bt,m as Vt,q as Ht,s as Ut,t as Wt,v as Gt,y as Kt,z as qt}from"./index-DUFmNDGR.js";import{t as Jt}from"./StatusBadge-Dcr2bw58.js";import{t as Yt}from"./useEventInvalidation-ByOUWkAr.js";import{i as Xt,n as Zt,r as Qt,t as $t}from"./DeviceAggregateSection-DDZxpHxU.js";var en=It(`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`}]]),tn=It(`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=It(`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=It(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),an=It(`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=jt(),r=X(),{data:i,isLoading:a,isError:o}=_t(e),{data:c}=s({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 l=(i??[]).filter(e=>e.display?.hidden!==!0);if(l.length===0)return null;let u=j(c?.stableId??``,l,c?.childLayout),d=u.ungrouped,f=e=>n(`/devices/${String(e)}`),p=c?.name??``,m=(e,t)=>q(g,{trpc:r.trpcClient,device:{...t,name:pe(t,p)},variant:`minimal`,onNavigate:f},e),h=d.some(e=>!!e.role),_=d.some(e=>!e.role),v=h&&!_?t(`device.accessories`,{defaultValue:`Accessories`}):!h&&_?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),y=d.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:v}),q(`div`,{className:`space-y-1`,children:d.map(e=>m(e.id,e))})]}):null,b=u.disabledSection===void 0?null:q(se,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:u.disabledSection.children.length,defaultOpen:!1,children:q(`div`,{className:`opacity-60 space-y-1`,children:u.disabledSection.children.map(e=>m(e.id,e))})},u.disabledSection.title);return u.sections.length===0?b===null?y:H(`div`,{className:`space-y-2`,children:[y,b]}):H(`div`,{className:`space-y-2`,children:[u.sections.map(e=>q(se,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>m(e.id,e))},e.title)),y,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=ue({deviceId:e},{refetchInterval:1e4,retry:!1}),r=xe({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(Nt,{className:`h-3.5 w-3.5 animate-spin`}):q(Tt,{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(Ot,{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(Lt,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?q(dn,{icon:q(en,{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(D,{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(m,{trpc:X().trpcClient,deviceId:e,features:t})})}V();function mn({dev:e,busy:t,setBusy:n}){let r=e?.motionTrigger,i=ft(e?.state.motionTrigger),[a,o]=K(!1);if(!r)return null;let s=i?.enabled===!0,c=i!==void 0,l=async()=>{if(t||!c)return;let e=!s;n(!0),o(!0);try{await r.setMotionTrigger({enabled:e})}finally{n(!1),o(!1)}};return H(`button`,{type:`button`,onClick:()=>{l()},disabled:t||!c,title:c?s?`Disable trigger on motion`:`Enable trigger on motion`:`Awaiting state…`,"aria-pressed":s,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${s?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[q(Pt,{className:`h-3 w-3`}),q(`span`,{children:a?s?`Disabling…`:`Enabling…`:c?s?`On motion: on`:`On motion: off`:`On motion: …`})]})}V();function Z({deviceId:e,deviceType:t,features:n}){let r=X(),i=ke(t)?.HeroCard??m,a=ct(r.trpcClient,e),o=ft(a?.state.deviceStatus),[s,c]=K(!1),l=o!==void 0&&o.online===!1,u=l?o.lastChangedAt:null;return H(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[l?q(`div`,{className:`flex justify-center`,children:q(O,{lastChangedAt:u})}):null,q(i,{trpc:r.trpcClient,deviceId:e,features:n}),q(`div`,{className:`flex justify-center`,children:q(mn,{dev:a,busy:s,setBusy:c})})]})}function hn({deviceId:e}){let t=X(),{data:n,isLoading:r}=yt(e),{data:i,isLoading:a}=_t(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(ie,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}var gn={[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]:hn,[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 _n(e){return q(gn[e.deviceType]??sn,{...e})}function vn(e){return N(X().trpcClient,e)}V();function yn(e){let[t,n]=K(`idle`),[r,i]=K(null),a=B(null),o=B(null),s=B(null),c=B(!0),l=He(),u=M(),d=Ke(),f=Je(()=>{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=Je(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=Je(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 bn=0;function Q(){return++bn}function xn(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Sn(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 Cn(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 wn(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 Tn({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: ${xn(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=Je(()=>{f.current?.focus()},[]),h=Xe({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: ${xn(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...Sn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...wn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...Cn(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: ${xn(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 En({deviceId:e,intercomAvailable:t=!1}){let n=X(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),a=vn(i?e:null),{streams:o,pipelineMetrics:s,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h}=R(n.trpcClient,i?e:null),g=T(n.trpcClient,i?e:null),_=yn(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=C(),ee=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,w=x.length>0?q(W,{children:x.map(e=>q(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return q(Ge,{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:ee,...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:w,chromeless:!0,className:`h-full`})}function Dn({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full`,children:q(he,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function On({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(Tn,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function kn({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(Ce,{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}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(me,{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 jn({deviceId:e}){let t=G(),n=Number.isFinite(e),{data:r}=s({deviceId:e},{enabled:n}),i=typeof r?.type==`string`?r.type:`camera`;Yt([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:a,isLoading:o,isError:c,error:l}=Ue({deviceId:e},{enabled:n}),{data:u}=S({deviceType:i},{enabled:!!i}),d=f({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(o)return q(`div`,{className:`p-4`,children:q(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(c)return H(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,l instanceof Error?l.message:String(l)]});let p=new Map,m={};for(let e of u??[])m[e.capName]=e.wrappers;for(let e of a?.entries??[])p.set(e.capName,{...e,wrappers:m[e.capName]??[]});for(let e of u??[])p.has(e.capName)||p.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let h=[...p.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(h.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 g=h.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:g}),` of `,h.length,` capabilit`,h.length===1?`y`:`ies`,` bound — rows marked `,q(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),q(Oe,{columns:[{key:`capability`,header:`Capability`,render:e=>q(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>q(Mn,{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(Nn,{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(Pn,{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:h,rowKey:e=>e.capName,minWidthPx:720})]})}function Mn({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(Dt,{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(vt,{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(xt,{className:`h-3 w-3`}),`unbound`]})}function Nn({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 Pn({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?Mt:ht,{className:`h-3 w-3`}),e]},e)})})}function Fn({deviceId:e,activeSubTab:t,onSubTabChange:n}){return q(`div`,{className:`flex flex-col gap-3`,children:q($t,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}V();var In=new Set([`package-detection`]);function Ln(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 Rn(e){return e?e.modelId!==void 0||e.settings!==void 0:!1}function zn({deviceId:e,refreshToken:t}){let n=G(),r=X().trpcClient,[i,a]=K(null),[o,s]=K(null),[c,l]=K(null),u=je({deviceId:e},{refetchOnMount:`always`}),d=ge({deviceId:e},{refetchOnMount:`always`}),f=We(void 0,{refetchOnMount:`always`});Yt([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let p=A(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(()=>(f.data??[]).filter(e=>m.has(e.nodeId)).map(e=>e.nodeId),[f.data,m]),g=h[0]??``,_=z({nodeId:g},{enabled:g!==``,refetchOnMount:`always`}),v=Ye({enabled:h.length>0,queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`],`device-step`,h.join(`,`),t],queryFn:async()=>{let e={};for(let t of h)try{e[t]=(await r.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:t})).devices}catch{e[t]=[]}return e}}),b=()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]})},x=ve({onSuccess:b}),S=y({onSuccess:b}),C=U(()=>_.data?_e(_.data):[],[_.data]),ee=U(()=>{let e=f.data??[],t=m.size===0?[]:e.filter(e=>m.has(e.nodeId)),n=[];for(let e of t){let t=(v.data?.[e.nodeId]??[]).filter(e=>e.enabled&&e.available);if(t.length>=2)for(let r of t)n.push({agentNodeId:e.nodeId,engineLabel:r.format,deviceKey:r.key,deviceLabel:bt(r).label});else n.push({agentNodeId:e.nodeId,engineLabel:t[0]?.format??`(engine unknown)`})}return n},[f.data,v.data,m]),w=(e,t)=>v.data?.[e]?.find(e=>e.key===t)??null,te=e=>{if(e.deviceKey!==void 0)return e.deviceKey;let t=v.data?.[e.agentNodeId]??[],n=t.filter(e=>e.enabled&&e.available);return n.length>=1?n[0].key:t.find(e=>e.available)?.key??t[0]?.key??null},T=(e,t,n)=>d.data?.[e]?.[t]?.[n]??null,ne=e=>{if(In.has(e))return{kind:`zone-driven`};let t=Ln(_.data??null,e)?.enabledByDefault??!0,n=u.data?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},E=(e,t)=>{let n=Ln(_.data??null,e),r=t?.format;if(!(!n||r===void 0))return(n.slot===`detector`?t?.defaultModelId:void 0)??fe(n,r)},re=(e,t)=>{let n=ne(e),r=n.kind===`gate`?n.effectiveOn:!1,i=Ln(_.data??null,e),a=te(t),o=a===null?null:w(t.agentNodeId,a),s=o?.format;if(!(i?.models.some(e=>s!==void 0&&!!e.formats[s])??!1))return r?{kind:`skip`}:{kind:`na`};let c=a===null?null:T(t.agentNodeId,a,e),l=o?.steps?.[e];return{kind:`enabled`,modelId:c?.modelId??l?.modelId??E(e,o)??`Auto`,overridden:Rn(c)}},ie=i&&_.data?Ln(_.data,i.addonId):null,D=i?w(i.agentNodeId,i.deviceKey):null,ae=D?.format??`coreml`,oe=i?Rn(T(i.agentNodeId,i.deviceKey,i.addonId)):!1,O=i?E(i.addonId,D):void 0,k=U(()=>{if(!i||!D)return null;let e=D.steps?.[i.addonId];return{enabled:!0,...e?.modelId===void 0?{}:{modelId:e.modelId},settings:e?.settings??{}}},[i,D]),j=()=>{a(null),s(null)},se=(e,t)=>{let n=te(t);n!==null&&(a({addonId:e,agentNodeId:t.agentNodeId,deviceKey:n}),s(T(t.agentNodeId,n,e)))},ce=(t,n)=>{S.mutate({deviceId:e,addonId:t,enabled:n})},M=()=>{i&&x.mutate({deviceId:e,agentNodeId:i.agentNodeId,deviceKey:i.deviceKey,addonId:i.addonId,patch:o},{onSuccess:j})},N=()=>{i&&x.mutate({deviceId:e,agentNodeId:i.agentNodeId,deviceKey:i.deviceKey,addonId:i.addonId,patch:null},{onSuccess:j})};if(f.isLoading||g!==``&&_.isLoading)return q(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(ee.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 le=i!==null&&ie!==null&&D!==null;return H(`div`,{className:`relative h-full w-full space-y-3`,children:[H(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[q(`span`,{className:`font-medium text-foreground`,children:`Gate`}),` (col 1) decides whether this camera runs a step — independent of nodes. Each`,` `,q(`span`,{className:`font-medium text-foreground`,children:`node column`}),` shows the model that node runs; click a cell to pin a per-camera model override for that accelerator. A gated-on step with no model on a device shows a clickable `,q(`span`,{className:`text-amber-500`,children:`⚠ skip`}),` `,`and won't run there.`]}),H(`div`,{className:`rounded-md border border-sky-500/25 bg-sky-500/[0.06] px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[q(`span`,{className:`font-medium text-sky-400`,children:`Placement is dynamic.`}),` When a node has multiple inference accelerators, each session is balanced across them per-session at dispatch time — these device columns show each accelerator's effective model (override ?? device default), not a fixed assignment.`]}),q(`div`,{className:le?`md:pr-[360px]`:``,children:C.length>0?q(Ie,{tree:C,agents:ee,gateFor:ne,getCellState:re,onCellClick:se,selectedCell:i,onSetGate:ce,gateBusy:S.isPending,fallbackNodeId:c,onFallbackNodeChange:l}):q(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),q(P,{open:le,onClose:j,title:ie?.name??``,subtitle:i&&D?`${i.agentNodeId} · ${bt(D).label} · ${D.format}`:``,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:!oe||x.isPending,onClick:N,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:j,children:`Cancel`}),q(`button`,{type:`button`,disabled:!i||!k||x.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:M,children:x.isPending?`Saving…`:`Save`})]}),children:ie&&i&&k?q(Ee,{mode:`device`,addon:ie,agentDefault:k,agentNodeId:i.agentNodeId,currentPatch:o,engineFormat:ae,effectiveModelId:O,onChangePatch:s}):q(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-300`,children:`This accelerator is no longer reported by the node, so there is nothing to provision here.`})})]})}var Bn=[{id:`object-detection`,label:`Object detection`,icon:`scan-search`},{id:`tracking`,label:`Tracking`,icon:`route`},{id:`motion`,label:`Motion`,icon:`activity`},{id:`stationary`,label:`Stationary`,icon:`square-parking`},{id:`zones`,label:`Zones`,icon:`shapes`},{id:`audio`,label:`Audio`,icon:`volume-2`},{id:`cluster`,label:`Cluster`,icon:`server`}],Vn={"pipeline-object-detection":`object-detection`,"detection-sensitivity":`object-detection`,"onboard-object-detection":`object-detection`,tracking:`tracking`,"tracking-core":`tracking`,"motion-tuning":`motion`,"stationary-objects":`stationary`,occupancy:`stationary`,zones:`zones`,"pipeline-audio":`audio`,"cluster-assignment":`cluster`,"orchestrator-live":`cluster`};function Hn(e){return Vn[e]??`object-detection`}V();var Un=`steps`,Wn=`settings`,Gn=new Set([Un,Wn]);function Kn(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function qn({deviceId:e,activeSubTab:t,onSubTabChange:n}){return H(Se,{value:t&&Gn.has(t)?t:Un,onValueChange:Je(e=>{n?.(e)},[n]),className:`flex flex-col`,children:[H(F,{className:`flex-shrink-0`,children:[q(I,{value:Un,children:`Steps`}),q(I,{value:Wn,children:`Settings`})]}),q(ze,{value:Un,children:q(zn,{deviceId:e,refreshToken:0})}),q(ze,{value:Wn,children:q($t,{deviceId:e,sectionFilter:Kn,subTabGrouping:{groupOf:e=>Hn(e.id),tabs:Bn}})})]})}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 Jn({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=h({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(Mt,{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(zt,{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(Ct,{className:`h-3.5 w-3.5`})})]})})}V();function Yn({deviceId:e,initialLocation:t}){let n=G(),[r,i]=K(!1),[a,o]=K(t??``),[s,c]=K(!1),l=B(null),{data:u}=te(void 0,{enabled:r}),d=u??[];J(()=>{r||o(t??``)},[t,r]),J(()=>{r&&l.current?.focus()},[r]);let f=oe({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(Mt,{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(zt,{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(St,{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(Ct,{className:`h-3.5 w-3.5`})})]})})}V();function Xn({deviceId:e}){let t=G(),{data:n}=yt(e),{data:r}=_t(e),[i,a]=K(null),o=ae({onSuccess:()=>{a(null),t.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{a(`Could not change primary child: ${e.message}`)}});if(n==null||String(n.type??``)!==Y.Container)return null;let s=(r??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}}));if(s.length<=1)return null;let c=le(s,typeof n.linkDeviceId==`number`?n.linkDeviceId:null,typeof n.primaryChildEntityId==`string`?n.primaryChildEntityId:null);return H(W,{children:[q($,{label:`Primary child`,value:q(p,{childrenList:s,selectedId:c===null?s[0].id:c.id,onSetPrimary:t=>o.mutate({deviceId:e,primaryChildEntityId:t}),disabled:o.isPending})}),i!==null&&q(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:i})]})}V();var Zn=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function Qn(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function $n(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function er(){let e=w(),t=l(),{data:n}=s({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 c=String(i.stableId??``),u=String(i.name??``),d=String(i.type??``),f=String(i.addonId??``),p=i.features??[],m=new Set([`device-status`,`feature-probe`,`device-ops`]),h=(r?.entries??[]).filter(e=>e.kind===`native`&&!m.has(e.capName)).map(e=>e.capName),g=p.length>0?p:h,_=i.location??null,v=i.metadata??null,y=v!==null&&Object.keys(v).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`}),y&&H(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[q(tr,{active:a===`identity`,onClick:()=>o(`identity`),label:`Identity`}),q(tr,{active:a===`hardware`,onClick:()=>o(`hardware`),label:`Hardware`})]})]}),(!y||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:[`(`,c,`)`]})]})}),q(Jn,{deviceId:e,initialName:u}),q(Yn,{deviceId:e,initialLocation:_}),q(Xn,{deviceId:e}),q($,{label:`Type`,value:d}),q($,{label:`Provider`,value:q(gt,{type:f,size:`sm`,showLabel:!0})}),q($,{label:`Capabilities`,value:g.length>0?q(pt,{capabilities:g,showLabels:!0}):q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),y&&a===`hardware`&&q(nr,{metadata:v})]})}function tr({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 nr({metadata:e}){let t=Zn.filter(t=>t in e),n=Object.keys(e).filter(e=>!Zn.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:Qn(t),value:q(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:$n(e[t])})},t))})]})}V();function rr({deviceId:e}){let[t,n]=K(null),r=L({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(Tt,{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 ir={icon:``,label:``,unit:``,precision:``,hidden:!1};function ar(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function or(e){if(typeof e!=`object`||!e)return;let t=e.unit;return typeof t==`string`?t:void 0}function sr(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 cr({deviceId:e}){let t=X(),i=G(),{data:a}=s({deviceId:e},{enabled:e>0}),o=typeof a?.role==`string`?a.role:null,c=o===null?void 0:Fe[o],l=c?.kind===`numeric`,u=Te(t.trpcClient,e,o??``),d=c?.kind===`numeric`?c.canonicalUnit:void 0,f=or(u)??d,p=f===void 0?void 0:st(f),m=U(()=>p===void 0?[]:rt(p),[p]),[h,g]=K(null),_=h??ar(a?.display),v=r({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:y}=n({},{staleTime:6e4}),b=k({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(a===void 0||o===null)return null;let x=e=>{g({..._,...e})},S=()=>{v.mutate({deviceId:e,display:sr(_)})},C=()=>{g(ir),v.mutate({deviceId:e,display:null})},ee=()=>{let e={..._.icon===``?{}:{icon:_.icon},..._.unit===``?{}:{unit:_.unit},..._.precision.trim()!==``&&Number.isFinite(Number.parseInt(_.precision,10))?{precision:Number.parseInt(_.precision,10)}:{}},t={...y?.defaults??{},[o]:e};b.mutate({defaults:t})},w=Ne(o).label,te=Object.keys(Le);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:_.icon,onChange:e=>x({icon:e.target.value}),children:[H(`option`,{value:``,children:[`Default (`,w,`)`]}),te.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:w,value:_.label,onChange:e=>x({label:e.target.value})})]}),l&&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:_.unit,onChange:e=>x({unit:e.target.value}),disabled:m.length===0,children:[H(`option`,{value:``,children:[`Source`,f?` (${f})`:``]}),m.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:_.precision,onChange:e=>x({precision:e.target.value})})]})]}),H(`label`,{className:`flex items-center gap-2`,children:[q(`input`,{type:`checkbox`,checked:_.hidden,onChange:e=>x({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:v.isPending,children:`Save`}),q(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:C,disabled:v.isPending,children:`Reset`}),H(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:ee,disabled:b.isPending,title:`Apply this unit / precision / icon as the default for every ${w} sensor`,children:[`Set as default for all `,w,` sensors`]})]})]})]})}function lr(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function ur({device:e}){let t=jt(),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(Qe.Resyncable),{data:l}=v({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),u=l?.streams??{},d=Object.entries(u),f=s.includes(Qe.DoorbellButton),p=Me(f?{deviceId:n??void 0,historyLimit:10}:void 0),m=p.latest?Date.now()-p.latest.timestamp<3e4:!1;return H(`div`,{className:`space-y-5`,children:[a&&n!==null&&q(Ae,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),c&&n!==null&&q(rr,{deviceId:n}),i&&n!==null&&q(E,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),f&&q(Re,{history:p.history,latestIsFresh:m}),i&&n!==null&&q(E,{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(Ot,{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(dr,{label:`Nominal`,value:lr(t.nominalBitrateKbps??0)}),q(dr,{label:`Observed`,value:lr(t.observedBitrateKbps??0)}),q(dr,{label:`Peak`,value:lr(t.peakBitrateKbps??0)}),q(dr,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),q(er,{}),o&&n!==null&&q(cr,{deviceId:n})]})}function dr({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 fr(e,t){if(t===`number`){let t=Number(e);return Number.isNaN(t)?e:t}return t===`boolean`?e===`true`:e}function pr(e,t){let n={};for(let r of e)r.key!==``&&r.value!==``&&(n[r.key]=fr(r.value,t));return n}function mr(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 hr(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 gr(e){return e==null?`identity`:e.kind}function _r({value:e,onChange:t,sourceField:n,targetKind:r}){let[i,a]=K(()=>gr(e)),[o,s]=K(()=>mr(e,n)),[c,l]=K(()=>e?.kind===`enum-map`&&e.fallback!=null?String(e.fallback):``),[u,d]=K(()=>hr(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=pr(o,r),n=c===``?void 0:fr(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(mr(void 0,n)),e===`linear`&&d(hr(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 vr=`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 yr({mode:e,idPrefix:t,labelPrefix:n,pickerDevices:r,value:i,onChange:a,search:o,onSearchChange:s}){let{data:c}=ye({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:vr})]}),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:vr,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:vr,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:vr,children:[q(`option`,{value:``,children:`— select a field —`}),u.map(e=>H(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]})}function br(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 xr(e){return e===null?`null`:typeof e==`number`?`number`:typeof e==`boolean`?`boolean`:`string`}function Sr(e){return e===null?``:String(e)}V();var Cr=`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`,wr=`min, max, abs, round, floor, ceil, sqrt, pow, clamp, avg, sum, coalesce, age, convert`,Tr=0;function Er(){return Tr+=1,`b${Tr}`}function Dr(e){return{key:Er(),name:e,mode:`sibling`,sourceId:null,cap:``,fieldPath:``,search:``,literalType:`number`,literalText:``,sampleText:``}}function Or(e,t,n){if(e===null)return[Dr(`a`)];let r=[];for(let[i,a]of Object.entries(e.bindings)){if(a.kind===`literal`){r.push({...Dr(i),mode:`literal`,literalType:xr(a.value),literalText:Sr(a.value)});continue}if(a.kind===`global`){r.push({...Dr(i),mode:`global`,sourceId:t.find(e=>e.stableId===a.sourceStableId)?.id??null,cap:a.cap,fieldPath:a.fieldPath});continue}r.push({...Dr(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:[Dr(`a`)]}function kr(e,t,n){if(e.mode===`literal`){let t=br(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 Ar(e){if(e.mode===`literal`)return br(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 jr({devices:e,siblings:t,targetDeviceId:n,containerStableId:r,initial:i,onChange:a}){let[o,s]=K(i?.expr??``),[c,l]=K(()=>Or(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=kr(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(()=>at({expr:u.source.expr,bindings:u.source.bindings}),[u.source]),f=U(()=>{if(o.trim()===``)return null;let e=et(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]=Ar(t))}return Ze(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`:nt.test(t)?$e.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,Dr(Mr(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(Nr,{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:`${Cr} font-mono resize-y`}),H(`p`,{className:`mt-1 text-[10px] text-foreground-subtle/60`,children:[`Functions: `,wr]}),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 Mr(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 Nr({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:`${Cr} 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:`${Cr} 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:`${Cr} 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:Cr})]}):H(W,{children:[q(yr,{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:`${Cr} text-[10px]`})]})]})}V();function Pr(e,t,n){return(n===void 0?[e,t]:[e,n,t]).map(e=>e.replace(/[^a-z0-9]/gi,`-`)).join(`-`)}function Fr(e,t,n){let r=`${t}-${e}`;return n.find(e=>e.stableId===r)?.id??null}function Ir(e,t){return t.find(t=>t.stableId===e)?.id??null}function Lr(e){return e==null?`sibling`:e.source.kind===`literal`?`literal`:e.source.kind===`global`?`global`:e.source.kind===`expression`?`expression`:`sibling`}function Rr(e){return e==null||e.source.kind!==`literal`?`string`:xr(e.source.value)}function zr(e){return e==null||e.source.kind!==`literal`?``:Sr(e.source.value)}function Br({deviceId:e,parentDeviceId:t,deviceStableId:n,initial:r,onSave:i,onCancel:a}){let{data:o}=b({}),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}=ye({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:Ir(p.sourceStableId,s):Fr(f.sourceKey,c,s),[g,_]=K(Lr(r)),[v,y]=K(r?.target.cap??``),[x,S]=K(r?.target.fieldPath??``),[C,ee]=K(r?.target.itemKey??``),[w,te]=K(h),[T,ne]=K((f??p)?.cap??``),[E,re]=K((f??p)?.fieldPath??``),[ie,D]=K(void 0),[ae,oe]=K(``),[O,k]=K(Rr(r)),[A,j]=K(zr(r)),[se,ce]=K(m),[M,N]=K(r?.transform);J(()=>{if((f??p)==null||w!==null||s.length===0)return;let e=f==null?p==null?null:Ir(p.sourceStableId,s):Fr(f.sourceKey,c,s);e!==null&&te(e)},[f,p,w,s,c]);let P=d.find(e=>e.cap===v)?.fields??[],le=P.find(e=>e.path===x),ue=le?.item===!0,F=ae.trim().toLowerCase(),de=s.filter(t=>t.id===e?!1:F===``?!0:t.name.toLowerCase().includes(F)||t.stableId.toLowerCase().includes(F)||String(t.id).includes(F)),fe=g===`global`?de:l,pe=e=>{y(e),S(``),ee(``)},me=e=>{e!==`sibling`&&e!==`global`&&e!==`literal`&&e!==`expression`||(_(e),te(null),ne(``),re(``),D(void 0),oe(``))},I=br(O,A),he=g===`literal`?I!==null:g===`expression`?se!==null:w!=null&&T!==``&&E!==``,L=v!==``&&x!==``&&(!ue||C.trim()!==``)&&he,ge=()=>{if(g===`literal`)return I===null?null:{kind:`literal`,value:I.value};if(g===`expression`)return se;let e=s.find(e=>e.id===w);if(!e||T===``||E===``)return null;if(g===`global`)return{kind:`global`,sourceStableId:e.stableId,cap:T,fieldPath:E};let t=`${c}-`;return{sourceKey:e.stableId.startsWith(t)?e.stableId.slice(t.length):``,cap:T,fieldPath:E}},R=()=>{if(!L)return;let e=ge();if(e===null)return;let t=ue?C.trim():void 0;i({id:r?.id??Pr(v,x,t),source:e,target:{cap:v,fieldPath:x,...t===void 0?{}:{itemKey:t}},...M==null?{}:{transform:M}})},z=`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=>pe(e.target.value),className:z,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:x,disabled:v===``,onChange:e=>S(e.target.value),className:z,children:[q(`option`,{value:``,children:`— select a field —`}),P.map(e=>q(`option`,{value:e.path,children:e.item===!0?`${e.path} (per item, ${e.kind})`:`${e.path} (${e.kind})`},e.path))]})]}),ue&&H(`div`,{children:[q(`label`,{htmlFor:`link-target-item-key`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Item key`}),q(`input`,{id:`link-target-item-key`,type:`text`,value:C,placeholder:`e.g. main-brush`,onChange:e=>ee(e.target.value),className:z}),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=>me(e.target.value),className:z,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:O,onChange:e=>{let t=e.target.value;(t===`string`||t===`number`||t===`boolean`||t===`null`)&&(k(t),t===`boolean`&&j(`true`),t===`null`&&j(``))},className:z,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`})]})]}),O!==`null`&&(O===`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:A,onChange:e=>j(e.target.value),className:z,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:A,placeholder:O===`number`?`e.g. 42`:`e.g. main-brush`,onChange:e=>j(e.target.value),className:z})]}))]}),g===`expression`&&q(jr,{devices:s,siblings:l,targetDeviceId:e,containerStableId:c,initial:m,onChange:ce}),(g===`sibling`||g===`global`)&&q(yr,{mode:g,idPrefix:`link-source`,labelPrefix:`Source`,pickerDevices:fe,value:{sourceId:w,cap:T,fieldPath:E},onChange:(e,t)=>{te(e.sourceId),ne(e.cap),re(e.fieldPath),D(t)},search:ae,onSearchChange:oe})]}),q(_r,{value:M,onChange:N,sourceField:g===`literal`||g===`expression`?void 0:ie,targetKind:le?.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:!L,onClick:R,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 Vr({deviceId:e}){let t=X(),n=G(),r=Number.isFinite(e),{data:i,isLoading:a}=s({deviceId:e},{enabled:r,refetchInterval:1e4}),{data:o}=ye({deviceId:e,includeSynthesizable:!0},{enabled:r}),c=new Map;for(let e of o?.caps??[])e.itemArray&&c.set(e.cap,e.itemArray);let l=qe({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),u=i?.deviceLinks??[],d=typeof i?.parentDeviceId==`number`?i.parentDeviceId:null,f=typeof i?.stableId==`string`?i.stableId:``,[p,m]=K(null),h=t=>{l.mutate({deviceId:e,deviceLinks:u.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`})}):p===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:()=>m(`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(wt,{className:`h-3 w-3`}),`Add link`]})]}),u.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:u.map(n=>q(Ur,{deviceId:e,link:n,itemArray:c.get(n.target.cap),trpcClient:t.trpcClient,onDelete:()=>h(n.id),onEdit:()=>m(n),isPending:l.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:p===`new`?`Add link`:`Edit link`})}),q(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:q(Br,{deviceId:e,parentDeviceId:d,deviceStableId:f,initial:p===`new`?null:p,onSave:t=>{let n=u.some(e=>e.id===t.id)?u.map(e=>e.id===t.id?t:e):[...u,t];l.mutate({deviceId:e,deviceLinks:n}),m(null)},onCancel:()=>{m(null)}})})]})}function Hr(e,t,n,r){let i=ot(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:ot(a,r)}function Ur({deviceId:e,link:t,itemArray:n,trpcClient:r,onDelete:i,onEdit:a,isPending:o}){let s=Te(r,e,t.target.cap),c=t.target.itemKey,l=s===void 0?void 0:c!==void 0&&n!==void 0?Hr(s,n,c,t.target.fieldPath):c===void 0?ot(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(Wr,{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 Wr({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 Gr=[{id:`overview`,label:`Overview`,cameraOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1},{id:`detection-pipeline`,label:`Detection pipeline`,cameraOnly:!0},{id:`bindings`,label:`Bindings`,cameraOnly:!0},{id:`wiring`,label:`Wiring`,cameraOnly:!1}];function Kr(e){let t=e===Y.Camera;return Gr.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var qr=[{id:`logs`,icon:Vt,label:`Logs`},{id:`repl`,icon:Rt,label:`REPL`},{id:`events`,icon:Ft,label:`Events`},{id:`state`,icon:kt,label:`State`}];function Jr(){let n=Ht(),r=Number(n.deviceId),l=Number.isFinite(r),u=jt(),f=G(),p=d(),m=X(),[h,g]=At(),v=h.get(`tab`)??`overview`,y=h.get(`sub`),[b,S]=K(`logs`),C=`device-detail.left-col-width-px`,[w,te]=K(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(C),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),T=B(w);T.current=w;function E(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??w??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{te(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=T.current;if(e!==null)try{window.localStorage.setItem(C,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:ie,isLoading:D,isError:ae}=s({deviceId:r},{enabled:l,refetchInterval:5e3,retry:1}),{data:oe}=ee({deviceId:r},{enabled:l}),O=U(()=>{let e=oe?.settings?.sections??[],t=oe?.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(Xt)&&r.add(Zt),[...r].map(e=>e===`export`?{id:e,label:Qt,isAddonContrib:!0}:{id:e,label:it[e]?.label??e,isAddonContrib:!0})},[oe]),k=ie,A=String(k?.name??n.deviceId??`Device`),j=k?.online===!0,se=j?`online`:`offline`,M=String(k?.addonId??`rtsp`),N=k?.features??[],P=k?.type,ue=P===Y.Camera,{data:F}=_t(l?r:0),fe=P===Y.Container,pe=U(()=>(F??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[F]),me=U(()=>fe?le(pe,typeof k?.linkDeviceId==`number`?k.linkDeviceId:null,typeof k?.primaryChildEntityId==`string`?k.primaryChildEntityId:null)?.id??null:null,[fe,pe,k?.linkDeviceId,k?.primaryChildEntityId]),{data:I}=ee({deviceId:me??0},{enabled:me!==null}),he=U(()=>{if(me===null)return[];let e=I?.settings?.sections??[],t=I?.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:it[e]?.label??e,isAddonContrib:!0,childDeviceId:me}))},[me,I]),L=typeof k?.parentDeviceId==`number`?k.parentDeviceId:null,{data:ge}=s({deviceId:L??0},{enabled:L!==null}),R=we(),z=k?.disabled!==!0,{data:_e}=ye({deviceId:r},{enabled:l}),ve=(_e?.caps.length??0)>0,xe=U(()=>{let e=new Set,t=[];for(let n of[...Kr(P),...O,...he])e.has(n.id)||(e.add(n.id),!(n.id===`wiring`&&!ve)&&t.push(n));return t},[P,O,he,ve]),Se=U(()=>xe.some(e=>e.id===v)?v:`overview`,[xe,v]),Ce=Je(e=>{g(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[g]),Te=Je(e=>{g(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[g]),Ee=(F??[]).length>0,Oe=U(()=>qr.filter(({featureGate:e})=>!e||N.includes(e)),[N]),{data:ke}=de({addonId:M},{enabled:!!M&&M!==`rtsp`}),Ae=_({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]}),u(ke?.id?`/integrations/${ke.id}`:`/integrations`)}}),je=a({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Me=Ve({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ne=t(),Fe=re({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ie=N.includes(Qe.Rebootable),Le=N.includes(Qe.BatteryOperated),Re=e(m.trpcClient,Le&&l?r:null),[ze,He]=K(!1),Ue=ct(m.trpcClient,l?r:null),We=async()=>{if(!(ze||!Ue)){He(!0);try{await Ue.snapshot?.invalidateCache({});let e=await Ue.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{He(!1)}}},Ge=je.isPending||Me.isPending,{data:Ke}=Be({deviceId:r},{enabled:l,refetchInterval:1e4}),qe=Ke?.agentNodeId??null,V=typeof qe==`string`&&qe.length>0&&!qe.startsWith(`addon:`)?qe:void 0,{data:Ye}=ne({deviceId:r,...V?{nodeId:V}:{}},{enabled:l,refetchInterval:3e3,retry:!1}),{data:W}=i({deviceId:r},{enabled:l,refetchInterval:3e3,retry:!1}),Xe=W?.level?.dbfs??null;function J(){if(!l)return null;switch(Se){case`overview`:return q(ur,{device:k??{}});case`config`:return q(Fn,{deviceId:r,activeSubTab:y,onSubTabChange:Te});case`detection-pipeline`:return q(qn,{deviceId:r,activeSubTab:y,onSubTabChange:Te});case`bindings`:return q(jn,{deviceId:r});case`wiring`:return q(Vr,{deviceId:r});default:{let e=Se,t=O.some(t=>t.id===e),n=he.find(t=>t.id===e);if(!t&&n===void 0)return null;let i=n?.childDeviceId??r;if(e===`export`)return q($t,{deviceId:r,sectionFilter:Xt,activeSubTab:y,onSubTabChange:Te});let a=q($t,{deviceId:i,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:y,onSubTabChange:Te});return n!==void 0&&i!==r?q(x,{deviceId:i,children:a}):a}}}return l?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`})})]}):ae||!ie?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:[`#`,r]})]}),q(`button`,{onClick:()=>u(`/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(Pe,{items:[{label:`Integrations`,onClick:()=>u(`/integrations`)},{label:ke?.name??M,onClick:()=>ke?.id&&u(`/integrations/${ke.id}`)},{label:A}]})}),H(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[q(gt,{type:M,size:`lg`}),H(`div`,{className:`min-w-0 flex-1`,children:[H(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[q(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:A}),q(Jt,{status:se}),Le&&q(ce,{status:Re,variant:`full`})]}),L!==null&&ge&&H(`button`,{type:`button`,onClick:()=>u(`/devices/${L}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${ge.name}`,children:[q(`span`,{children:`↑`}),q(`span`,{className:`truncate`,children:String(ge.name??`Device #${L}`)})]}),q(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:N.length>0&&q(pt,{capabilities:N})})]}),Ye&&q(`div`,{className:`hidden lg:flex`,children:q(Yr,{metrics:Ye,dbfs:Xe})}),H(`div`,{className:`flex items-center gap-1 shrink-0`,children:[H(`button`,{onClick:async()=>{z?await p({title:`Disable "${A}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Me.mutate({deviceId:r}):je.mutate({deviceId:r})},disabled:Ge,title:z?`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 ${z?`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:Ge?`Updating…`:z?`Enabled`:`Disabled`})]}),q(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),q(be,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:qt,disabled:ze,onClick:()=>{We()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:Et,hidden:!Ie,disabled:Ne.isPending,danger:!0,onClick:async()=>{await p({title:`Reboot "${A}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Ne.mutate({deviceId:r})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${ke?.name??M}.`,icon:Tt,disabled:Fe.isPending,danger:!0,onClick:async()=>{await p({title:`Restart "${ke?.name??M}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${A}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&Fe.mutate({addonId:M})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:Ut,separatorBefore:!0,disabled:Ae.isPending,danger:!0,onClick:async()=>{await p({title:`Delete "${A}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Ae.mutate({deviceId:r})}}]})]})]})]}),q(x,{deviceId:r,device:k??void 0,children:q(o,{children:q(c,{children:q(dt,{children:q(De,{children:H(`main`,{className:R?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[H(`div`,{className:R?`flex flex-col bg-surface`:`${w===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!R&&w!==null?{width:`${String(w)}px`}:void 0,children:[q(`div`,{className:ue?`flex-shrink-0 border-b border-border-subtle bg-black`:R?`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:ue?q(En,{deviceId:r,intercomAvailable:N.includes(Qe.TwoWayAudio)}):q(_n,{deviceId:r,deviceName:A,deviceType:P??`unknown`,provider:M,isOnline:j,features:N})}),H(`div`,{className:R?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[q(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:q(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:Oe.map(({id:e,label:t,icon:n})=>H(`button`,{onClick:()=>S(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${b===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:R?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[b===`logs`&&q(Dn,{deviceId:r,containerDeviceId:P===`container`?r:void 0}),b===`repl`&&q(On,{deviceId:r}),b===`events`&&q(kn,{deviceId:r}),b===`state`&&q(An,{deviceId:r})]})]})]}),!R&&q(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:E,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:R?`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:xe.map(e=>{let t=Se===e.id;return H(`button`,{onClick:()=>Ce(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:R?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[Se===`overview`&&Ee&&q(on,{parentDeviceId:r}),J()]})]})]})})})})})})]}):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:n.deviceId}),` `,`is not a number.`]}),q(`button`,{onClick:()=>u(`/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 Yr({metrics:e,dbfs:t}){let n=u(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(Pt,{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(Bt,{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{Jr as DeviceDetailPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Cn as e,G as t,Ln as n,Mn as r,pr as i,vn as a}from"./src-Btp5jZp0.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-DFxnnQ5-.js";import{t as p}from"./ProviderIcon-CD80TWfL.js";import{K as m,o as h,t as g,z as _}from"./index-DUFmNDGR.js";import{t as v}from"./AdminPage-Dq33XE9j.js";import{t as y}from"./useEventInvalidation-ByOUWkAr.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}=r({}),{data:w}=i(void 0),T=n({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),E=a({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),D=e({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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{$a as e,R as t,b as n,i as r}from"./src-Btp5jZp0.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{B as v}from"./src-DlGmnrz9.js";import{d as y}from"./player-overlays-DFxnnQ5-.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{Ao as e,B as t,Jr as n,Mn as r,Pr as i,Qa as a,Va as o,Xr as s,Zr as c,bo as l,ei as u,q as d,qr as f,xt as p,yo as m,z as h}from"./src-Btp5jZp0.js";import{I as g,K as _,Q as v,S as y,W as b,b as x,i as S,o as C,q as w,x as T,z as E}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{K as D,L as O,k,s as A}from"./src-DlGmnrz9.js";import{p as j}from"./player-overlays-DFxnnQ5-.js";import{t as M}from"./clock-D9iqCSCa.js";import{t as N}from"./copy-xvYnf3mn.js";import{a as ee,c as te,d as ne,f as P,i as F,m as I,n as re,o as L,p as R,r as ie,s as z,t as B}from"./debounced-invalidate-CT06Xct6.js";import{t as V}from"./search-DHWQ7t3y.js";import{t as ae}from"./square-check-big-CkGVGfz1.js";import{t as H}from"./square-CqUnowVe.js";import{E as U,I as W,L as oe,P as se,S as G,U as K,W as q,i as ce,s as le,t as ue}from"./index-DUFmNDGR.js";import{t as de}from"./AdminPage-Dq33XE9j.js";import{r as fe,t as pe}from"./authed-media-XfBD4Ma-.js";var me=q(`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`}]]),he=q(`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`}]]),ge=q(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]);v();var _e=720*60*60*1e3;function ve(e){let t=[];for(let n of e)t.push(...n);return t}function ye(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function be(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 xe(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 Se(e,t){return{since:e.fromMs??t-_e,until:e.toMs??t}}var Y=typeof f==`function`,Ce=`Track deletion arrives with the next server update`;function we(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Te=Y?f:we,Ee=200,De=3e4;function Oe(e){let t=j(),n=S({queries:e.deviceIds.map(n=>({queryKey:[`events-feed`,n,e.since,e.until,e.minImportance??null,e.classFilter??null],staleTime:De,refetchInterval:De,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEvents.query({deviceId:n,since:e.since,until:e.until,limit:Ee,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>({...e,deviceId:n}))}))});return{rows:ye(ve(n.map(e=>e.data??[])),`importance`),isLoading:n.some(e=>e.isLoading)}}var ke=[`events-feed`],Ae=2e3;function je(e){let t=C(),n=e?.paused===!0,r=_(t);r.current=t;let i=_(n);i.current=n;let[o,s]=w(!1),c=g(()=>{r.current.invalidateQueries({queryKey:ke})},[]),l=_(void 0);l.current||=B({delayMs:Ae,invalidate:()=>{i.current?s(!0):c()}}),E(()=>()=>l.current?.cancel(),[]),E(()=>{n||!o||(s(!1),c())},[n,o,c]);let u=g(()=>{s(!1),c()},[c]);return a(D.PipelineAnalyticsDetectionEvent,()=>{l.current?.trigger()}),a(D.PipelineAnalyticsTrackEnded,()=>{l.current?.trigger()}),{pending:o,refreshNow:u}}v();function Me(){return Object.values(O).filter(e=>e.level===`macro`).map(e=>({macro:e,subs:Object.values(O).filter(t=>t.parentKind===e.kind).sort((e,t)=>e.label.localeCompare(t.label))})).sort((e,t)=>e.macro.label.localeCompare(t.macro.label))}function Ne({selected:e,onChange:n}){let{t:r}=ue(),[i,a]=w(!1),[o,s]=w(``),[c,l]=w(new Set),u=b(Me,[]),d=o.trim().toLowerCase(),f=e=>d.length===0||h(e,r).toLowerCase().includes(d),p=b(()=>u.map(e=>({macro:e.macro,subs:e.subs.filter(t=>f(t)||f(e.macro))})).filter(e=>f(e.macro)||e.subs.length>0),[u,d]),m=e=>l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),g=t=>{let r=new Set(e),i=e.has(t.macro.kind)&&t.subs.every(t=>e.has(t.kind)),a=[t.macro.kind,...t.subs.map(e=>e.kind)];if(i)for(let e of a)r.delete(e);else for(let e of a)r.add(e);n(r)},_=t=>{let r=new Set(e);r.has(t)?r.delete(t):r.add(t),n(r)},v=()=>n(new Set),x=e.size;return y(`div`,{className:`relative`,children:[y(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${x>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[T(ge,{className:`h-3.5 w-3.5`}),x>0?`Kinds (${String(x)})`:`Kinds`,T(W,{className:`h-3 w-3`})]}),i&&y(`div`,{className:`absolute z-20 mt-1 max-h-80 w-64 overflow-auto rounded-md border border-border bg-surface p-2 shadow-lg`,children:[y(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[T(V,{className:`h-3.5 w-3.5 text-foreground-subtle`}),T(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`Search kinds…`,className:`w-full bg-transparent py-1 text-xs outline-none`}),x>0&&T(`button`,{type:`button`,onClick:v,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),p.map(n=>{let i=t(n.macro.iconId),a=c.has(n.macro.kind)||d.length>0,o=e.has(n.macro.kind);return y(`div`,{className:`mb-0.5`,children:[y(`div`,{className:`flex items-center gap-1`,children:[n.subs.length>0?T(`button`,{type:`button`,onClick:()=>m(n.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:T(a?W:se,{className:`h-3 w-3`})}):T(`span`,{className:`w-3`}),y(`label`,{className:`flex flex-1 cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[T(`input`,{type:`checkbox`,checked:o,onChange:()=>g(n),className:`accent-primary`}),T(i,{className:`h-3.5 w-3.5`,style:{color:n.macro.color}}),T(`span`,{className:`font-medium`,children:h(n.macro,r)})]})]}),a&&n.subs.map(n=>{let i=t(n.iconId);return y(`label`,{className:`ml-5 flex cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[T(`input`,{type:`checkbox`,checked:e.has(n.kind),onChange:()=>_(n.kind),className:`accent-primary`}),T(i,{className:`h-3.5 w-3.5`,style:{color:n.color}}),T(`span`,{children:h(n,r)})]},n.kind)})]},n.macro.kind)})]})]})}var X=100,Pe=120,Fe={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 Ie(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 Le(e,t,n){if(e.length===0||t===null)return Fe;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return Fe;let a=Ie(e,n?.maxPoints??Pe).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 Re={firstFrame:`First frame (track start)`,lastFrame:`Last frame (track end)`,thumbnail:`Best detection`,thumbnailSmall:`Best detection (480)`,snapshot:`Snapshot`,keyFrame:`Key frame (native-res)`,keyFrameSmall:`Key frame (960)`,crop:`Object crop`,fullFrame:`Full frame`,fullFrameBoxed:`Full frame (boxed)`,faceCrop:`Face crop`,plateCrop:`Plate crop`};function ze(e){return e in Re}function Be(e){return ze(e)?Re[e]:e}function Ve(e,t){return`${e}${pe}/${encodeURIComponent(t)}`}v();var He=1400,Ue=`Admin-gated URL — opens only inside an authenticated session`;function We({label:e,value:t,title:n}){let[r,i]=w(!1);return E(()=>{if(!r)return;let e=setTimeout(()=>i(!1),He);return()=>clearTimeout(e)},[r]),y(`button`,{type:`button`,onClick:g(()=>{(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:[T(r?oe:N,{className:`h-2.5 w-2.5 shrink-0`}),T(`span`,{className:`truncate`,children:r?`Copied`:e})]})}function Ge({localUrl:e,publicUrl:t}){return y(`div`,{className:`flex flex-wrap gap-1`,children:[T(We,{label:`Local`,value:e,title:`Copy LAN URL — ${Ue}`}),t&&T(We,{label:`Public`,value:t,title:`Copy public URL — ${Ue}`})]})}v();var Ke=3e4;function qe(e){let[t,n]=w(null),r=g(e=>{n(t=>t??e)},[]);return E(()=>{e||n(null)},[e]),{publicOrigin:t,probes:e?T(Je,{onOrigin:r}):null}}function Je({onOrigin:e}){let{data:t}=p({capName:`network-access`});return T(x,{children:(t??[]).map(t=>T(Ye,{addonId:t.addonId,onOrigin:e},t.addonId))})}function Ye({addonId:e,onOrigin:t}){let{data:n}=i({addonId:e},{refetchInterval:Ke,retry:!1});return E(()=>{let e=n?A.safeParse(n):null,r=e?.success?e.data.endpoint?.url:void 0;if(r)try{t(new URL(r).origin)}catch{}},[n,t]),null}v();var Xe=15e3,Ze=window.location.origin,Qe=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),$e=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]);function et(e){let[t,n]=w(null);return E(()=>{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 tt({overlay:e,onPickSnapshot:t}){return!e.polyline&&!e.peakBox&&e.snapshots.length===0?null:y(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[e.peakBox&&T(`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&&T(`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)=>T(`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)=>T(`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:T(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${e.mediaKey}-${String(n)}`)),e.start&&T(`circle`,{cx:e.start.x,cy:e.start.y,r:2.4,fill:`#22c55e`,stroke:`#052e16`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),e.end&&T(`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 y(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[T(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),T(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function nt({row:t,cameraName:r,deleteAvailable:i,onClose:a,onDeleted:u}){let d=j(),f=Te(),p=t!==null,h=t?.deviceId??0,_=t?.trackId??``,v=t?.bestEventId??``,S=t?.timestamp??0,C=t?.windowMs??0,{data:D}=s({deviceId:h,trackId:_},{enabled:p}),{data:O}=c({trackId:_},{enabled:p}),{data:k}=n({eventId:v},{enabled:p&&v!==``}),{data:A}=o({deviceId:h,since:S-Xe,until:S+C+Xe},{enabled:p}),[M,N]=w(null),[ee,te]=w(!1),{publicOrigin:P,probes:re}=qe(p);E(()=>{N(null)},[h,_]);let L=b(()=>{let e=O??[],t=k??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[O,k]),ie=fe(L?`${pe}/${encodeURIComponent(L.key)}`:void 0),z=b(()=>{let e=new Set,t=[];for(let n of[...k??[],...O??[]])!n.base64||e.has(n.key)||(e.add(n.key),t.push(n));return t},[k,O]),B=b(()=>z.find(e=>Qe.has(e.kind))??null,[z]),V=et(B?`data:image/jpeg;base64,${B.base64}`:null),ae=b(()=>Le(D?.positions??[],V,{snapshots:(D?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaKey:e.mediaKey}))}),[D?.positions,D?.snapshots,V]),H=g(e=>{let t=z.find(t=>t.key===e);t&&N(t)},[z]);if(t===null)return null;let W=M?`data:image/jpeg;base64,${M.base64}`:ie.src,oe=M?.kind??L?.kind,se=oe!==void 0&&$e.has(oe)&&V!==null&&(D?.positions.length??0)>=2,K=A&&A.length>0?A[0]:null,q=()=>{K&&(te(!0),(async()=>{try{let e=await d.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:K.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{window.alert(`Could not resolve clip playback. Check the server logs.`)}finally{te(!1)}})())},ue=()=>{!i||f.isPending||window.confirm(`Delete this track and all its media? This cannot be undone.`)&&(async()=>{try{await f.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),u()}catch{window.alert(`Failed to delete this track. Check the server logs.`)}})()},de=Math.round(t.importance*100),me=D?.importanceReason?`${String(de)}% · ${D.importanceReason}`:`${String(de)}%`,he=D?.zonesVisited&&D.zonesVisited.length>0?D.zonesVisited.join(`, `):`—`,ge=D?.audioLabels&&D.audioLabels.length>0?D.audioLabels.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `):`—`,_e=D?D.totalDistance.toFixed(2):`—`,ve=R(D?D.firstSeen:S),ye=D?R(D.lastSeen):`—`;return T(m,{open:!0,onOpenChange:e=>!e&&a(),children:y(l,{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:[y(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[y(`div`,{className:`min-w-0`,children:[y(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[t.className,t.label?y(`span`,{className:`text-foreground-subtle`,children:[` · `,t.label]}):null]}),T(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:r})]}),T(`button`,{type:`button`,onClick:a,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:T(ce,{className:`h-4 w-4`})})]}),y(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[W?T(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:T(F,{src:W,alt:`Key frame from ${r}`,fit:`natural`,className:`w-full`,overlay:se?T(tt,{overlay:ae,onPickSnapshot:H}):void 0})}):T(`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:ie.failed?y(x,{children:[T(I,{className:`h-8 w-8 opacity-60`}),T(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):T(G,{className:`h-6 w-6 animate-spin opacity-70`})}),z.length>0&&T(`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=Be(e.kind),r=Ve(Ze,e.key),i=P?Ve(P,e.key):null;return y(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[T(`button`,{type:`button`,onClick:()=>N(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${n} · ${R(e.timestamp)}`,children:T(`img`,{src:t,alt:n,className:`h-full w-full object-cover`})}),y(`figcaption`,{className:`min-w-0 px-0.5`,children:[T(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:n,children:n}),T(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:R(e.timestamp),children:ne(e.timestamp)})]}),T(Ge,{localUrl:r,publicUrl:i})]},e.key)})}),re,K&&y(e,{variant:`secondary`,onClick:q,disabled:ee,children:[ee?T(G,{className:`h-3.5 w-3.5 animate-spin`}):T(U,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),y(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[T($,{label:`Camera`,value:r}),T($,{label:`Class`,value:t.className}),T($,{label:`Label`,value:t.label??`—`}),T($,{label:`Importance`,value:me}),T($,{label:`Zones visited`,value:he}),T($,{label:`Audio heard`,value:ge}),T($,{label:`Total distance`,value:_e}),T($,{label:`First seen`,value:ve}),T($,{label:`Last seen`,value:ye}),T($,{label:`Track`,value:t.trackId,mono:!0})]})]}),T(`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:T(`span`,{title:i?void 0:Ce,children:y(e,{variant:`secondary`,onClick:ue,disabled:!i||f.isPending,children:[f.isPending?T(G,{className:`h-3.5 w-3.5 animate-spin`}):T(le,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}function rt(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 it({row:e,cameraName:t,nowMs:n,onOpenDetail:r,selected:i=!1,onToggleSelect:a,score:o}){let s=fe(e.bestEventId?`${pe}/${e.bestEventId}`:void 0),c=Math.round(e.importance*100),l=o===void 0?void 0:Math.round(o*100),u=rt(e.windowMs),d=()=>r(e);return y(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[y(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[s.src?T(`img`,{src:s.src,alt:`Event from ${t}`,onClick:d,className:`h-full w-full cursor-zoom-in object-cover`}):T(`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:T(I,{className:`h-6 w-6 opacity-60`})}),a&&T(`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?T(ae,{className:`h-4 w-4 text-primary`}):T(H,{className:`h-4 w-4`})}),l!==void 0&&y(`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&&T(`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)})]}),y(`button`,{type:`button`,onClick:d,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[y(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,e.label?y(`span`,{className:`text-foreground-subtle`,children:[` · `,e.label]}):null]}),T(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),y(`div`,{className:`flex items-center justify-between gap-2`,children:[T(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:P(e.timestamp,n)}),u&&T(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:u})]})]})]})}v();function at(){let[e,t]=w(!1),n=_(null),[r,i]=w(0),a=g(e=>{n.current!==e&&(n.current=e,i(e=>e+1))},[]);return E(()=>{let e=n.current;if(!e||typeof IntersectionObserver>`u`){t(!1);return}let r=new IntersectionObserver(e=>{let n=e[e.length-1];n&&t(!n.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return r.observe(e),()=>r.disconnect()},[r]),{ref:a,scrolledPast:e}}v();var ot=[`events-feed`],st=60,ct=[{value:`importance`,label:`Importance`,icon:me},{value:`time`,label:`Recent`,icon:M}];function lt(){let t=C(),[n,i]=w(z),[a,o]=w(new Set),[s,c]=w(new Set),[l,u]=w(0),[d,f]=w(`time`),[p,m]=w(new Set),[h,g]=w(null),[_,v]=w(()=>Date.now());E(()=>{let e=setInterval(()=>v(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:S,until:D}=b(()=>Se({fromMs:n.fromMs,toMs:n.toMs},_),[n.fromMs,n.toMs,_]),O=at(),{pending:A,refreshNow:j}=je({paused:h!==null||p.size>0||O.scrolledPast}),{data:M}=r({}),N=b(()=>(M??[]).filter(e=>e.type===k.Camera),[M]),ne=b(()=>N.map(e=>e.id),[N]),P=Te(),F=P.isPending,{rows:I,isLoading:R}=Oe({deviceIds:ne,since:S,until:D,minImportance:l>0?l:void 0,classFilter:s.size===1?[...s][0]:void 0}),B=b(()=>{let e=new Map;for(let t of N??[])e.set(t.id,t.name);return e},[N]),V=e=>B.get(e)??`Camera #${String(e)}`,ae=b(()=>te(I).map(e=>({id:e,name:V(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[I,B]),H=b(()=>ye(be(I,{cameras:a,classes:s,minImportance:l}),d),[I,a,s,l,d]),U=re(H,st,b(()=>JSON.stringify([[...a].sort((e,t)=>e-t),[...s].sort(),l,d,S,D]),[a,s,l,d,S,D])),W=()=>{t.invalidateQueries({queryKey:ot})},oe=()=>m(new Set);function se(e){m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function K(){if(p.size===0||!Y)return;let e=xe(I,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])=>P.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{W();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=>V(e)).join(`, `);window.alert(`Failed to delete tracks on: ${e}. They remain selected — retry, or check the server logs.`)}})}let q=H.length!==I.length;return y(`div`,{className:`relative space-y-3`,children:[y(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[T(ee,{onChange:i}),T(L,{cameras:ae,selected:a,onChange:o}),T(Ne,{selected:s,onChange:c}),y(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[T(`span`,{children:`Min score`}),T(`input`,{type:`range`,min:0,max:1,step:.05,value:l,onChange:e=>u(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":`Minimum importance`}),T(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(l*100)})]}),T(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:ct.map(e=>{let t=e.icon;return y(`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:[T(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!R&&T(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:q?`${String(H.length)} of ${String(I.length)} events`:`${String(H.length)} event${H.length===1?``:`s`}`})]}),p.size>0&&y(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[y(`span`,{className:`text-xs font-medium text-foreground`,children:[p.size,` selected`]}),y(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[T(`span`,{title:Y?void 0:`Track deletion arrives with the next server update`,children:y(e,{variant:`secondary`,onClick:K,disabled:!Y||F,children:[F?T(G,{className:`h-3.5 w-3.5 animate-spin`}):T(le,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),T(e,{variant:`ghost`,onClick:oe,disabled:F,children:T(ce,{className:`h-3.5 w-3.5`})})]})]}),R&&y(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[T(G,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!R&&H.length===0&&T(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),A&&T(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:T(`button`,{type:`button`,onClick:j,className:`rounded-full border border-primary/40 bg-surface px-3 py-1 text-[11px] font-medium text-primary shadow-sm hover:bg-primary/10`,children:`New events — refresh`})}),!R&&H.length>0&&y(x,{children:[T(`div`,{ref:O.ref,"aria-hidden":!0,className:`h-0`}),T(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:U.pageItems.map(e=>T(it,{row:e,cameraName:V(e.deviceId),nowMs:_,selected:p.has(J(e.deviceId,e.trackId)),onToggleSelect:se,onOpenDetail:g},J(e.deviceId,e.trackId)))}),T(ie,{currentPage:U.page,totalItems:U.totalItems,pageSize:U.pageSize,onPageChange:U.setPage,itemNoun:`events`})]}),h&&T(nt,{row:h,cameraName:V(h.deviceId),deleteAvailable:Y,onClose:()=>g(null),onDeleted:()=>{W(),g(null)}})]})}v();var ut=50,dt=350,ft=[`person`,`vehicle`,`animal`],pt=[{value:.2,label:`Loose`},{value:.25,label:`Balanced`},{value:.3,label:`Strict`}];function mt(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 ht({onActiveChange:e}){let[t,n]=w(``),[i,a]=w(.2),[o,s]=w(null),[c,l]=w(null),[f,p]=w(null),m=d(t,dt).trim(),h=m.length>0;E(()=>{e(h)},[h,e]);let[g,_]=w(()=>Date.now());E(()=>{let e=setInterval(()=>_(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:v}=r({}),x=b(()=>(v??[]).filter(e=>e.type===k.Camera),[v]),S=b(()=>{let e=new Map;for(let t of v??[])e.set(t.id,t.name);return e},[v]),C=e=>S.get(e)??`Camera #${String(e)}`,{data:D,isFetching:O,isError:A,error:j}=u({text:m,minScore:i,limit:ut,classFilter:o??void 0,deviceId:c??void 0},{enabled:h}),M=b(()=>[...D??[]].sort((e,t)=>t.score-e.score).map(e=>({...mt(e),score:e.score})),[D]);function N(e){s(t=>t===e?null:e)}return y(`div`,{className:`space-y-3`,children:[y(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[y(`div`,{className:`flex flex-wrap items-center gap-2`,children:[y(`div`,{className:`relative min-w-[16rem] flex-1`,children:[T(V,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),T(`input`,{type:`text`,value:t,onChange:e=>n(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`}),t&&T(`button`,{type:`button`,onClick:()=>n(``),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:T(ce,{className:`h-3.5 w-3.5`})})]}),O&&h&&T(G,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),y(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[T(`div`,{className:`flex items-center gap-1`,children:ft.map(e=>T(`button`,{type:`button`,onClick:()=>N(e),className:`rounded-md px-2.5 py-1 text-xs capitalize transition-colors ${o===e?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e},e))}),y(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[T(`span`,{children:`Camera`}),y(`select`,{value:c===null?``:String(c),onChange:e=>l(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:[T(`option`,{value:``,children:`All`}),x.map(e=>T(`option`,{value:String(e.id),children:e.name},e.id))]})]}),y(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[T(`span`,{children:`Match`}),T(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:pt.map(e=>T(`button`,{type:`button`,onClick:()=>a(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${i===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&&!O&&!A&&y(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[M.length,` match`,M.length===1?``:`es`]})]})]}),h&&y(`div`,{className:`space-y-3`,children:[A&&y(`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&&O&&M.length===0&&y(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[T(G,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!A&&!O&&M.length===0&&y(`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&&T(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:M.map(e=>T(it,{row:e,cameraName:C(e.deviceId),nowMs:g,score:e.score,onOpenDetail:p},e.id))})]}),f&&T(nt,{row:f,cameraName:C(f.deviceId),deleteAvailable:Y,onClose:()=>p(null),onDeleted:()=>p(null)})]})}var gt=15e3;function _t(e){let t=j(),n=S({queries:e.map(e=>({queryKey:[`stationary-objects`,e],staleTime:gt,refetchInterval:gt,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)}}v();function vt(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 yt({row:e,cameraName:t,nowMs:n}){let r=e.keyFrameMediaKey?.startsWith(`track:`)?e.keyFrameMediaKey.split(`:`)[1]:e.keyFrameMediaKey,i=fe(r?`${pe}/${r}`:void 0);return y(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[y(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[i.src?T(`img`,{src:i.src,alt:`Parked ${e.className} on ${t}`,className:`h-full w-full object-cover`}):T(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:T(he,{className:`h-6 w-6`})}),T(`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})]}),y(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[T(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),y(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,vt(n,e.becameStationaryAt)]})]})]})}function bt(){let[e,t]=w(!1),n=Date.now(),{data:i}=r({}),a=b(()=>(i??[]).filter(e=>e.type===k.Camera),[i]),o=b(()=>a.map(e=>e.id),[a]),s=b(()=>{let e=new Map;for(let t of a)e.set(t.id,t.name);return e},[a]),{rows:c}=_t(o);return c.length===0?null:y(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[y(`button`,{type:`button`,onClick:()=>t(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[T(e?W:se,{className:`h-4 w-4 text-foreground-subtle`}),T(he,{className:`h-4 w-4 text-foreground-subtle`}),T(`span`,{className:`text-sm font-semibold text-foreground`,children:`Stationary`}),T(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:c.length}),T(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:`Parked objects — kept out of the event feed`})]}),e&&T(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:c.map(e=>T(yt,{row:e,cameraName:s.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}v();function xt(){let[e,t]=w(!1);return T(de,{icon:K,title:`Events`,subtitle:`Every captured key event across all cameras — trajectory, media, and clips.`,children:y(`section`,{className:`space-y-3`,children:[T(ht,{onActiveChange:t}),!e&&T(bt,{}),!e&&T(lt,{})]})})}export{xt as EventsPage};
|