@camstack/addon-admin-ui 1.2.289 → 1.2.290
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/{AddonCollectionPage-BKRsM_qT.js → AddonCollectionPage-D1pWGGvT.js} +1 -1
- package/dist/assets/Addons-BZ97Xzg1.js +1 -0
- package/dist/assets/{AdminTabs-Os_saxNF.js → AdminTabs-DJBff_i8.js} +1 -1
- package/dist/assets/AiProfiles-B2ZTI_l9.js +3 -0
- package/dist/assets/{BrokerForm-BhInPTAL.js → BrokerForm-qoePj2K4.js} +1 -1
- package/dist/assets/Build-C2d1cwHA.js +32 -0
- package/dist/assets/{Capabilities-CfFtLbNU.js → Capabilities-S4kRIl4K.js} +1 -1
- package/dist/assets/{CapabilityBadges-C25C3fOL.js → CapabilityBadges-DwWL_l7c.js} +1 -1
- package/dist/assets/Cluster-67TUhWLy.js +11 -0
- package/dist/assets/CompositionEditor-D1r-JisY.js +1 -0
- package/dist/assets/CompositionEditorPage-B9h3eUkU.js +1 -0
- package/dist/assets/Data-CTGdXReL.js +1 -0
- package/dist/assets/DetectionIntelligence-ClVstSbX.js +1 -0
- package/dist/assets/DeviceAggregateSection-VpXFysnh.js +1 -0
- package/dist/assets/DeviceDetail-BC1J_Uus.js +2 -0
- package/dist/assets/{Devices-Dho7Ah7I.js → Devices-ENl1rQTV.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-CZNi9Xqf.js → EmbedPlayerPage-CZv8OzxI.js} +1 -1
- package/dist/assets/Events-BAtHdRH_.js +1 -0
- package/dist/assets/{FormBuilder-BAhlMxtA.js → FormBuilder-DmVp78xs.js} +1 -1
- package/dist/assets/Identity-DBJbXwFL.js +1 -0
- package/dist/assets/IntegrationDetail-BOSgQh4k.js +1 -0
- package/dist/assets/Integrations-B9TIBbr7.js +1 -0
- package/dist/assets/Integrations-DGY8tg5o.js +1 -0
- package/dist/assets/Locations-Cb0oJLNi.js +3 -0
- package/dist/assets/{Logs-DjLrB_bz.js → Logs-BwQ51kvC.js} +1 -1
- package/dist/assets/{ModelLicenses-Ju1FDfQO.js → ModelLicenses-URNrQt1_.js} +1 -1
- package/dist/assets/{MotionZonesSettings-B68pkoTl.js → MotionZonesSettings-YQ3UaVz7.js} +1 -1
- package/dist/assets/{MyAccess-C3qL3L21.js → MyAccess-_aiNFcbi.js} +1 -1
- package/dist/assets/Network-GxxrMQ2A.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-Bdu5lrTB.js → NodeAddonsSettingsPanel-BY9z0lZa.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-BZONzZ2s.js → NodeInferenceDevices-DZ-_1qB2.js} +1 -1
- package/dist/assets/Notifications-BmxbDLAS.js +1 -0
- package/dist/assets/Pipeline-Cod6aDKO.js +1 -0
- package/dist/assets/{Plates-CQyh_1JS.js → Plates-5zDioApI.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-DyHXfkSl.js → PrivacyMaskSettings-Bo3emiuH.js} +1 -1
- package/dist/assets/{ProviderIcon-DtoRs3L2.js → ProviderIcon-CnCmdk4B.js} +1 -1
- package/dist/assets/Recordings-s4jIucSI.js +1 -0
- package/dist/assets/{ScanNetworkModal-BS1CjdFP.js → ScanNetworkModal-DWiaxsCk.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-DugNwyJ4.js → SceneMonitorEditor-CVrYjKnp.js} +1 -1
- package/dist/assets/{Scenes-DLmoTFWA.js → Scenes-CvM_wh49.js} +1 -1
- package/dist/assets/{Settings-2K2Vjg4p.js → Settings-C0t6ywVO.js} +1 -1
- package/dist/assets/{Showroom-DgbL-U1t.js → Showroom-Dr0ztns6.js} +1 -1
- package/dist/assets/{StorageLocationsPanel-DWjCqCv9.js → StorageLocationsPanel-DYu23Cr2.js} +1 -1
- package/dist/assets/{Terminal-CnRI_Gmz.js → Terminal-C3DyYl4d.js} +4 -4
- package/dist/assets/{Viewer-DHTF4S4u.js → Viewer-ig9o4_z0.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BHZ13lQR.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BXMJgpii.js} +1 -1
- package/dist/assets/{archive-BmbkFLtr.js → archive-Da1Yqakr.js} +1 -1
- package/dist/assets/{authed-media-Bhswngiz.js → authed-media-BMuC_wHZ.js} +1 -1
- package/dist/assets/{boxes-BDauq_GC.js → boxes-Baa5Ogmj.js} +1 -1
- package/dist/assets/circle-slash-BRokabFn.js +1 -0
- package/dist/assets/{debounced-invalidate-BMyWMwma.js → debounced-invalidate-BrkGpqQR.js} +1 -1
- package/dist/assets/{device-integration-icon-CowSzbMe.js → device-integration-icon-DMH1CC1W.js} +1 -1
- package/dist/assets/dist-B2jpWgNR.js +349 -0
- package/dist/assets/{dist-CEfzm_eL.js → dist-DnbX2Ts3.js} +1 -1
- package/dist/assets/{face-bbox-Bw09XNv0.js → face-bbox-CqL9Av-Z.js} +1 -1
- package/dist/assets/{hard-drive-download-D8cJmcOG.js → hard-drive-download-BLcXiD8l.js} +1 -1
- package/dist/assets/{hostInit-DawD1ezr.js → hostInit-DZGOkLOR.js} +1 -1
- package/dist/assets/index-DmZC8m5k.js +4 -0
- package/dist/assets/{index-Cz9U1hKX.css → index-Dw7R0OTh.css} +1 -1
- package/dist/assets/{layers-DRiv_qOz.js → layers-CheyENp_.js} +1 -1
- package/dist/assets/{location-owned-usage-CqCPlIDe.js → location-owned-usage-Cqkcqdng.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-a0a0ef95.js → mf-entry-bootstrap-0-f6e27852.js} +2 -2
- package/dist/assets/{player-overlays-Dpyv2MuF.js → player-overlays-COWJpSPo.js} +1 -1
- package/dist/assets/remoteEntry-4ktgOeTU.js +1 -0
- package/dist/assets/{send-DJxsQciO.js → send-WZjVf7tk.js} +1 -1
- package/dist/assets/{settings-2-DhdVszMB.js → settings-2-CHLR6iGS.js} +1 -1
- package/dist/assets/{square-check-big-CyuyrB82.js → square-check-big-x9DuWnSt.js} +1 -1
- package/dist/assets/src-CYsrYOj2.js +349 -0
- package/dist/assets/src-CxavCtUA.js +67 -0
- package/dist/assets/{use-scenes-feed-C1fOUeee.js → use-scenes-feed-C6zdrId0.js} +1 -1
- package/dist/assets/{use-stationary-objects-3iUSTAxf.js → use-stationary-objects-CgZoUHn3.js} +1 -1
- package/dist/assets/{useDevice-CEHL86RO.js → useDevice-DbxoO2nr.js} +1 -1
- package/dist/assets/useEventInvalidation-5ATLpxzV.js +1 -0
- package/dist/assets/{useNodeUrlSelection-BAKjYDmK.js → useNodeUrlSelection-CAolorcm.js} +1 -1
- package/dist/assets/user-round-5BSQ3oXA.js +1 -0
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DC2EQBm-.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Iofpk1rr.js} +2 -2
- package/dist/index.html +6 -6
- package/dist/server/addon.js +110 -45
- package/package.json +1 -1
- package/dist/assets/Addons-Dd0di_Ic.js +0 -1
- package/dist/assets/AiProfiles-DXtr0dUS.js +0 -3
- package/dist/assets/Build-DTuK1-77.js +0 -32
- package/dist/assets/Cluster-CWcQYGW_.js +0 -11
- package/dist/assets/Data-DgPd7eUU.js +0 -1
- package/dist/assets/DetectionIntelligence-C3Hrp_v2.js +0 -1
- package/dist/assets/DeviceAggregateSection-DdAM0MHQ.js +0 -1
- package/dist/assets/DeviceDetail-NT2tY24m.js +0 -2
- package/dist/assets/Events-C9dSg_g9.js +0 -1
- package/dist/assets/Identity-BYdygzct.js +0 -1
- package/dist/assets/IntegrationDetail-DblGvkgb.js +0 -1
- package/dist/assets/Integrations-qYjBg30Q.js +0 -1
- package/dist/assets/Integrations-ujAFaZz4.js +0 -1
- package/dist/assets/Locations-q3oIkzY2.js +0 -3
- package/dist/assets/Network-DrRLH46C.js +0 -1
- package/dist/assets/Notifications-BCvyB2lu.js +0 -1
- package/dist/assets/Pipeline-BfuxKrMr.js +0 -1
- package/dist/assets/Recordings-C2W6EuhQ.js +0 -1
- package/dist/assets/circle-slash-OkyAP_uM.js +0 -1
- package/dist/assets/dist-B-ttjQPE.js +0 -349
- package/dist/assets/index-SOjqIyqv.js +0 -4
- package/dist/assets/remoteEntry-ahvkDE5X.js +0 -1
- package/dist/assets/src-BjMTOeHt.js +0 -349
- package/dist/assets/src-DeANpHOz.js +0 -67
- package/dist/assets/useEventInvalidation-Bp3xnYIe.js +0 -1
- package/dist/assets/user-round-CWLSjfaj.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as l,_t as u,gt as d,st as f,yt as p}from"./player-overlays-Dpyv2MuF.js";import{Bu as m,Dl as h,El as g,Jn as _,Lu as v,Ns as y,Oc as b,Tl as x,_n as S,_r as C,_s as w,br as T,bs as E,dr as D,fr as O,gr as k,hr as A,hu as j,mr as M,mu as N,os as P,ou as F,pr as ee,ql as te,ur as ne,vl as I,vr as re,vs as ie,xr as L,yr as ae,ys as oe,yu as se,zl as R,zu as ce}from"./src-DeANpHOz.js";import{t as z}from"./archive-BmbkFLtr.js";import{t as B}from"./circle-slash-OkyAP_uM.js";import{a as V,c as H,l as U,n as W,o as G,s as le,t as ue,u as de}from"./location-owned-usage-CqCPlIDe.js";import{t as fe}from"./hard-drive-download-D8cJmcOG.js";import"./index-SOjqIyqv.js";import{t as K}from"./AdminPage-CiKtOLQm.js";import{n as pe}from"./authed-media-Bhswngiz.js";import{t as me}from"./AdminTabs-Os_saxNF.js";import{t as q}from"./format-size-DIxKXxtj.js";var he=p(`calendar-clock`,[[`path`,{d:`M16 14v2.2l1.6 1`,key:`fo4ql5`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`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:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]),ge=p(`cloud-upload`,[[`path`,{d:`M12 13v8`,key:`1l5pq0`}],[`path`,{d:`M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242`,key:`1pljnt`}],[`path`,{d:`m8 17 4-4 4 4`,key:`1quai1`}]]);t();function _e(){let e=a(),t=S(),{data:i,isLoading:c,isError:l}=E({}),u=oe(),d=r(()=>u.data??[],[u.data]),{data:f}=P({},{refetchOnWindowFocus:!1}),p=r(()=>ue(i??[],f?.locations),[i,f?.locations]),{data:m}=ie({},{refetchOnWindowFocus:!1}),h=r(()=>V(m),[m]),[g,_]=o(null),[v,b]=o(null),x=w({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),C=y({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),T=async(e,n)=>{U(n)&&!await t({title:`Disable "${e.displayName}"?`,message:`${H(n).consequence}\n\nNothing is deleted — set the location back to Read-only or Active to bring its footage back.`,confirmLabel:`Disable`,variant:`danger`})||C.mutate(le(e,{mode:n}))},D=async e=>{if(await t({title:`Delete location "${e.displayName}"?`,message:`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`,confirmLabel:`Delete`,variant:`danger`}))try{await x.mutateAsync({id:e.id})}catch(n){await t({title:`Delete anyway?`,message:`${n instanceof Error?n.message:String(n)}\n\nForcing the delete removes the record only. Anything still on that location becomes unreachable — index rows naming it stop resolving, and playback of those segments goes silently black rather than erroring.`,confirmLabel:`Force delete`,variant:`danger`})&&x.mutate({id:e.id,force:!0})}},O=r(()=>{let e=new Map;for(let t of i??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[i]),k=c||u.isLoading,A=l||u.isError;return n(K,{children:[k&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),A&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!k&&!A&&n(`div`,{className:`space-y-3`,children:[d.length===0&&s(`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.`}),d.map(e=>s(W,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:O.get(e.id)??[],onAdd:e=>_(e),onEdit:e=>b(e),onDelete:e=>{D(e)},ownedBytesById:p,drainById:h,onSetMode:(e,t)=>{T(e,t)}},e.id))]}),g!==null&&s(de,{initialType:g,onClose:()=>_(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),_(null)}}),v!==null&&s(G,{location:v,onClose:()=>b(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),b(null)}})]})}t();var ve=[[`backup`,`listDestinations`]],ye=[`backup`,`listArchives`];function be({destinationId:t,restoreSupported:i,onOpenRestoreWizard:c}){let l=a(),u=S(),{data:d,isLoading:p,isError:m}=M({destinationId:t}),h=d??[],g=D({onSuccess:()=>{l.invalidateQueries({queryKey:[[...ye]]}),l.invalidateQueries({queryKey:ve})}}),_=e(async e=>{await u({title:`Delete this archive?`,message:`Permanently deletes "${e.label??e.id}" and frees ${q(e.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&g.mutate({destinationId:t,backupId:e.id})},[u,t,g]),[v,y]=o(null),b=e(async e=>{y(e.id);try{let n=await pe(xe(t,e.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.label??e.id}.tar.gz`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{y(null)}},[t]),x=r(()=>[...h].toSorted((e,t)=>t.createdAt-e.createdAt),[h]);return p?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):m?s(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):x.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):s(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),s(`tbody`,{children:x.map(e=>n(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:Se(e.createdAt)}),s(`td`,{className:`px-3 py-1.5 text-foreground`,children:e.label??s(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),s(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:e.locations.join(`, `)}),s(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:q(e.sizeBytes)}),s(`td`,{className:`px-3 py-1.5`,children:n(`div`,{className:`flex items-center justify-end gap-1`,children:[n(`button`,{onClick:()=>{b(e)},disabled:v===e.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:[v===e.id?s(R,{className:`h-3 w-3 animate-spin`}):s(F,{className:`h-3 w-3`}),`Download`]}),i&&c&&n(`button`,{onClick:()=>c({destinationId:t,archiveId:e.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:[s(I,{className:`h-3 w-3`}),`Restore`]}),s(`button`,{onClick:()=>{_(e)},disabled:g.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:g.isPending?s(R,{className:`h-3 w-3 animate-spin`}):s(f,{className:`h-3 w-3`})})]})})]},e.id))})]})})}function xe(e,t){return l(`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}function Se(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}t();var J=[[`backup`,`listSchedules`]];function Ce({onEdit:e,onOpenRestoreWizard:t}){let{data:i,isLoading:a,isError:c}=C(),l=i??[],u=A().data??[],d=r(()=>{let e=new Map;for(let t of u)e.set(t.id,t);return e},[u]),[f,p]=o(null),m=e=>{p(t=>t===e?null:e)};return a?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading backup entries…`}):c?s(`div`,{className:`text-xs text-danger`,children:`Failed to load backup entries`}):l.length===0?s(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:s(`p`,{className:`text-xs text-foreground-subtle`,children:`No backup entries yet. Create one to schedule backups across one or more storage locations.`})}):s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[820px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[s(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),s(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Entry`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),s(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Locations`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-24`,children:`Retention`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-48`,children:`Schedule`}),s(`th`,{className:`text-right px-3 py-2 font-medium w-52`,children:`Actions`})]})}),s(`tbody`,{children:l.map(n=>s(we,{row:n,destById:d,isOpen:f===n.id,onToggle:()=>m(n.id),onEdit:()=>e(n),...t?{onOpenRestoreWizard:t}:{}},n.id))})]})})}function we({row:t,destById:l,isOpen:p,onToggle:m,onEdit:_,onOpenRestoreWizard:v}){let y=a(),b=S(),x=L({onSuccess:()=>{y.invalidateQueries({queryKey:J})}}),C=O({onSuccess:()=>{y.invalidateQueries({queryKey:J})}}),w=T({onMutate:()=>{y.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{y.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),y.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),y.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})}}),[E,D]=o(String(t.retentionCount));c(()=>{D(String(t.retentionCount))},[t.retentionCount]);let k=r(()=>({id:t.id,label:t.label,cron:t.cron,locationIds:[...t.locationIds],retentionCount:t.retentionCount,...t.dataSources?{dataSources:[...t.dataSources]}:{}}),[t]),A=e(e=>{x.mutate({...k,enabled:e})},[x,k]),j=e(()=>{let e=Number.parseInt(E,10);if(Number.isNaN(e)||e<1){D(String(t.retentionCount));return}e!==t.retentionCount&&x.mutate({...k,enabled:t.enabled,retentionCount:e})},[x,k,E,t.retentionCount,t.enabled]),M=e(()=>{t.locationIds.length!==0&&w.mutate({destinations:[...t.locationIds],...t.dataSources&&t.dataSources.length>0?{locations:[...t.dataSources]}:{},label:t.label,retentionCount:t.retentionCount})},[w,t]),N=e(async()=>{await b({title:`Delete backup entry?`,message:`"${t.label||t.id}" will stop running. Existing archives are kept.`,confirmLabel:`Delete`,variant:`warning`})&&C.mutate({id:t.id})},[b,C,t.id,t.label]),P=t.cron.trim().length>0,F=x.isPending||C.isPending;return n(i,{children:[n(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[s(`td`,{className:`px-2 py-2`,children:s(`button`,{onClick:m,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:p?`Hide archives`:`Show archives`,children:s(p?u:d,{className:`h-3.5 w-3.5`})})}),s(`td`,{className:`px-3 py-2`,children:n(`button`,{onClick:_,className:`text-left hover:underline focus:outline-none`,children:[s(`div`,{className:`text-foreground font-medium`,children:t.label||`(unnamed)`}),t.lastRunAt!==void 0&&n(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:[`last run `,new Date(t.lastRunAt).toLocaleString()]})]})}),s(`td`,{className:`px-3 py-2`,children:s(`label`,{className:`inline-flex items-center cursor-pointer`,children:s(`input`,{type:`checkbox`,className:`accent-primary`,checked:t.enabled,disabled:F,onChange:e=>A(e.target.checked)})})}),s(`td`,{className:`px-3 py-2`,children:n(`div`,{className:`flex flex-wrap gap-1`,children:[t.locationIds.length===0&&s(`span`,{className:`text-[11px] text-danger italic`,children:`No locations`}),t.locationIds.map(e=>s(`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:l.get(e)?.displayName??e},e))]})}),s(`td`,{className:`px-3 py-2`,children:s(`input`,{type:`number`,min:1,max:1e3,value:E,disabled:F,onChange:e=>D(e.target.value),onBlur:j,onKeyDown:e=>{e.key===`Enter`&&e.target.blur(),e.key===`Escape`&&D(String(t.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`})}),s(`td`,{className:`px-3 py-2`,children:n(`button`,{onClick:_,className:`group flex flex-col items-start gap-0.5 text-left`,title:`Edit schedule`,children:[n(`span`,{className:`inline-flex items-center gap-1`,children:[s(he,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),s(`span`,{className:`font-mono text-[11px] text-foreground`,children:P?t.cron:`Manual`})]}),P&&t.nextRunAt!==void 0&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`next `,new Date(t.nextRunAt).toLocaleString()]})]})}),s(`td`,{className:`px-3 py-2`,children:n(`div`,{className:`flex items-center justify-end gap-1.5`,children:[n(`button`,{onClick:M,disabled:w.isPending||t.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:[w.isPending?s(R,{className:`h-3 w-3 animate-spin`}):s(g,{className:`h-3 w-3`}),`Run now`]}),s(`button`,{onClick:_,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:s(h,{className:`h-3 w-3`})}),s(`button`,{onClick:()=>{N()},disabled:F,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:s(f,{className:`h-3 w-3`})})]})})]}),p&&s(`tr`,{className:`border-t border-border bg-background/30`,children:n(`td`,{colSpan:7,className:`px-4 py-3 space-y-4`,children:[t.locationIds.length===0&&s(`p`,{className:`text-xs text-foreground-subtle italic`,children:`This entry has no locations selected.`}),t.locationIds.map(e=>n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:l.get(e)?.displayName??e}),s(be,{destinationId:e,restoreSupported:l.get(e)?.restoreSupported??!0,...v?{onOpenRestoreWizard:v}:{}})]},e))]})})]})}t();var Y=[{id:`manual`,label:`Manual only`,cron:``},{id:`hourly`,label:`Every hour`,cron:`0 * * * *`,description:`On the hour`},{id:`every-3h`,label:`Every 3 hours`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,label:`Every 6 hours`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,label:`Daily at 03:00`,cron:`0 3 * * *`,description:`Every night at 3 AM`},{id:`weekly-sun`,label:`Weekly Sunday 03:00`,cron:`0 3 * * 0`,description:`Sunday morning at 3 AM`}];function Te(e){let t=e.trim();for(let e of Y)if(e.cron===t)return e.id;return`custom`}function Ee({value:e,onChange:t,previewCount:r=5,disabled:i=!1}){let a=Te(e),[l,u]=o(a===`custom`);c(()=>{a!==`custom`&&u(!1)},[a]);let d=ke(e,250),f=re({cron:d,count:r},{enabled:d.trim().length>0}),p=f.data??null,m=e=>{u(!1),t(e.cron)},h=l||a===`custom`;return n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),n(`div`,{className:`flex flex-wrap gap-1.5`,children:[Y.map(e=>s(`button`,{type:`button`,onClick:()=>m(e),disabled:i,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!l&&a===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.description??e.label,children:e.label},e.id)),s(`button`,{type:`button`,onClick:()=>{u(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:i,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(h?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),h&&n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),s(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:i,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`}),n(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,s(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),s(De,{cron:d,preview:p,loading:f.isFetching})]})}function De({cron:e,preview:t,loading:r}){return r&&t===null?n(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[s(R,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?s(`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.`}):n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),s(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>n(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[s(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),s(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:Oe(e)})]},`${e}-${t}`))})]}):s(`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 Oe(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 ke(e,t){let[n,i]=o(e),a=r(()=>e,[e]);return c(()=>{let e=setTimeout(()=>i(a),t);return()=>clearTimeout(e)},[a,t]),n}t();var Ae=[[`backup`,`listSchedules`]];function je({entry:e,onClose:t,onSaved:i}){let c=a(),l=A(),u=l.data??[],[d,f]=o(e?.label??``),[p,m]=o(e?.cron??`0 3 * * *`),[h,g]=o(e?.enabled??!0),[_,v]=o(String(e?.retentionCount??7)),[y,x]=o(new Set(e?.locationIds??[])),S=L({onSuccess:()=>{c.invalidateQueries({queryKey:Ae}),i()}}),C=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},w=Number.parseInt(_,10),T=r(()=>d.trim().length>0&&y.size>0&&!Number.isNaN(w)&&w>=1&&w<=1e3,[d,y,w]),E=()=>{T&&S.mutate({...e?{id:e.id}:{},label:d.trim(),cron:p.trim(),enabled:h,locationIds:Array.from(y),retentionCount:w})},D=S.error instanceof Error?S.error.message:null;return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:n(`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:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3 sticky top-0 bg-surface`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e?`Edit backup entry`:`New backup entry`}),s(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:s(b,{className:`h-4 w-4`})})]}),n(`div`,{className:`p-4 space-y-4`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Name`}),s(`input`,{type:`text`,value:d,onChange:e=>f(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`})]}),n(`div`,{className:`space-y-1.5`,children:[n(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:[`Locations (`,y.size,` selected)`]}),l.isLoading&&n(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[s(R,{className:`h-3.5 w-3.5 animate-spin`}),`Loading locations…`]}),!l.isLoading&&u.length===0&&s(`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."}),u.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-52 overflow-y-auto`,children:u.map(e=>n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`checkbox`,checked:y.has(e.id),onChange:()=>C(e.id),className:`accent-primary`}),s(`span`,{className:`text-foreground`,children:e.displayName})]}),n(`div`,{className:`flex items-center gap-1.5`,children:[s(`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}),s(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]},e.id))})]}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Retention (archives kept)`}),s(`input`,{type:`number`,min:1,max:1e3,value:_,onChange:e=>v(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`})]}),n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Enabled`}),n(`label`,{className:`inline-flex items-center gap-2 py-1.5 cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),className:`accent-primary`}),s(`span`,{className:`text-xs text-foreground-subtle`,children:`Run on schedule`})]})]})]}),n(`div`,{className:`space-y-1.5 border-t border-border pt-3`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Schedule`}),s(Ee,{value:p,onChange:m,disabled:S.isPending})]}),D&&s(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:D})]}),n(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3 sticky bottom-0 bg-surface`,children:[s(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),n(`button`,{onClick:E,disabled:!T||S.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:[S.isPending&&s(R,{className:`h-3.5 w-3.5 animate-spin`}),e?`Save`:`Create entry`]})]})]})})}t();var Me=2e3,Ne=5e3;function X(e){return e.state===`queued`||e.state===`running`}function Pe(e){if(e.state===`queued`)return{title:`Cancel queued backup run?`,message:`This run has not started. Cancelling removes it from the queue — nothing has been written, nothing is deleted.`,confirmLabel:`Cancel run`,variant:`warning`};let t=e.completedDestinationIds.length;return{title:`Stop this backup run?`,message:`The half-written staging archive is deleted and the destination currently uploading discards its partial copy. ${t>0?`${t===1?`The 1 destination`:`The ${t} destinations`} that already completed KEEP${t===1?`S`:``} the archive.`:`No destination has completed yet, so nothing will be kept.`}`,confirmLabel:`Stop run`,variant:`danger`}}function Fe(){let t=S(),[n,r]=o(null),i=k(void 0,{refetchInterval:e=>(e.state.data??[]).some(X)?Me:Ne}),a=ne({onSettled:()=>{r(null),i.refetch()}}),c=e(async e=>{await t(Pe(e))&&(r(e.id),a.mutate({runId:e.id}))},[t,a]);return s(Ie,{queryState:i.isError?`error`:i.data===void 0?`pending`:`ready`,runs:i.data??[],cancelingId:n,onCancelRequest:e=>{c(e)},now:Date.now()})}function Ie({queryState:e,runs:t,cancelingId:r,onCancelRequest:i,now:a}){let o=e===`ready`&&t.some(X),c=t.filter(e=>e.state===`running`),l=t.filter(e=>e.state===`queued`),u=t.filter(e=>!X(e)),d=[...c,...l,...u];return n(`section`,{className:`rounded-lg border border-border bg-surface`,children:[n(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border`,children:[s(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Runs`}),o&&n(`span`,{className:`inline-flex items-center gap-1 text-[10px] font-medium text-primary`,title:`A backup run is in progress`,children:[s(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary animate-pulse`}),`live`]}),s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:`One run executes at a time — queued runs wait in line.`})]}),e===`pending`&&s(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle animate-pulse`,children:`Checking for backup runs…`}),e===`error`&&s(`div`,{className:`px-3 py-2.5 text-xs text-danger`,children:`Could not read backup runs — the orchestrator did not answer.`}),e===`ready`&&t.length===0&&s(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle italic`,children:`No backup runs yet. Runs appear here the moment one starts — manual or scheduled.`}),e===`ready`&&t.length>0&&s(`div`,{className:`overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[720px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Run`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`State`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Progress`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Destinations`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Timing`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium w-28`,children:`Actions`})]})}),s(`tbody`,{children:d.map(e=>s(Le,{run:e,canceling:r===e.id,onCancelRequest:i,now:a},e.id))})]})})]})}function Le({run:e,canceling:t,onCancelRequest:r,now:i}){let a=X(e);return n(`tr`,{className:`border-t border-border hover:bg-primary/5 align-top`,children:[n(`td`,{className:`px-3 py-2`,children:[s(`div`,{className:`text-foreground`,children:e.label??s(`span`,{className:`text-foreground-subtle italic`,children:`manual`})}),s(`div`,{className:`text-[10px] text-foreground-subtle font-mono`,title:e.id,children:e.id.slice(0,8)})]}),n(`td`,{className:`px-3 py-2`,children:[s(Re,{run:e}),e.state===`failed`&&e.error!==void 0&&s(`div`,{className:`mt-1 text-[10px] text-danger max-w-56 truncate`,title:e.error,children:e.error})]}),s(`td`,{className:`px-3 py-2`,children:s(ze,{run:e})}),s(`td`,{className:`px-3 py-2`,children:s(Be,{run:e})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle tabular-nums`,children:s(Ve,{run:e,now:i})}),s(`td`,{className:`px-3 py-2`,children:s(`div`,{className:`flex justify-end`,children:a&&n(`button`,{onClick:()=>r(e),disabled:t,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:e.state===`queued`?`Remove this run from the queue before it starts`:`Stop this run — the half-written archive is discarded`,children:[t?s(R,{className:`h-3 w-3 animate-spin`}):s(v,{className:`h-3 w-3`}),e.state===`queued`?`Cancel`:`Stop`]})})})]})}function Re({run:e}){switch(e.state){case`queued`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:[s(N,{className:`h-3 w-3`}),`Queued`]});case`running`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`,children:[s(R,{className:`h-3 w-3 animate-spin`}),e.phase===`uploading`?`Uploading`:`Building archive`]});case`succeeded`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-success/10 px-1.5 py-0.5 text-[10px] font-medium text-success`,children:[s(se,{className:`h-3 w-3`}),`Succeeded`]});case`failed`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-danger/10 px-1.5 py-0.5 text-[10px] font-medium text-danger`,children:[s(j,{className:`h-3 w-3`}),`Failed`]});case`cancelled`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-amber-500/10 px-1.5 py-0.5 text-[10px] font-medium text-amber-700 dark:text-amber-300`,title:`Stopped before completing every destination — not a success`,children:[s(B,{className:`h-3 w-3`}),`Stopped`]})}}function ze({run:e}){if(e.state===`queued`)return s(`span`,{className:`text-foreground-subtle`,children:e.queuePosition===void 0?s(`span`,{className:`italic`,children:`waiting its turn`}):n(`span`,{className:`inline-flex items-center gap-1`,children:[s(`span`,{className:e.queuePosition===1?`rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`:`rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium`,children:He(e.queuePosition)}),`in line`]})});if(e.state===`running`&&e.phase===`building`)return n(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[s(fe,{className:`h-3 w-3 text-primary`}),s(`span`,{className:`tabular-nums font-medium animate-pulse`,children:q(e.stagedBytes)}),s(`span`,{className:`text-foreground-subtle`,children:`staged so far`})]});if(e.state===`running`){let t=e.archiveSizeBytes;return n(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[s(ge,{className:`h-3 w-3 text-primary`}),n(`span`,{className:`tabular-nums font-medium`,children:[q(e.uploadedBytes),t===void 0?``:` / ${q(t)}`]}),s(`span`,{className:`text-foreground-subtle`,children:`to current destination`})]})}let t=e.archiveSizeBytes??(e.stagedBytes>0?e.stagedBytes:void 0);return t===void 0?s(`span`,{className:`text-foreground-subtle italic`,children:`—`}):n(`span`,{className:`tabular-nums text-foreground`,children:[q(t),` archive`]})}function Be({run:e}){let t=e.destinationIds.length,r=e.completedDestinationIds.length,i=e.failedDestinationIds.length;return t===0?s(`span`,{className:`text-foreground-subtle italic`,children:`not resolved yet`}):n(`div`,{className:`flex flex-col gap-0.5`,children:[n(`span`,{className:`text-foreground-subtle`,title:e.destinationIds.join(`, `),children:[t,` target`,t===1?``:`s`]}),n(`span`,{className:`inline-flex items-center gap-2 text-[10px]`,children:[r>0&&n(`span`,{className:`text-success`,title:`Kept their archive: ${e.completedDestinationIds.join(`, `)}`,children:[`✓ `,r,` completed`]}),i>0&&n(`span`,{className:`text-danger`,title:`Failed: ${e.failedDestinationIds.join(`, `)}`,children:[`✗ `,i,` failed`]})]})]})}function Ve({run:e,now:t}){return e.state===`queued`?n(`span`,{children:[`queued `,Z(t-e.requestedAt),` ago`]}):e.startedAt===void 0?s(`span`,{children:`—`}):e.finishedAt===void 0?n(`span`,{children:[`running for `,Z(t-e.startedAt)]}):n(`div`,{className:`flex flex-col gap-0.5`,children:[s(`span`,{children:Q(e.finishedAt)}),n(`span`,{className:`text-[10px]`,children:[`took `,Z(e.finishedAt-e.startedAt)]})]})}function He(e){if(e<=1)return`next`;let t=e%100;if(t>=11&&t<=13)return`${e}th`;switch(e%10){case 1:return`${e}st`;case 2:return`${e}nd`;case 3:return`${e}rd`;default:return`${e}th`}}function Z(e){let t=Math.max(0,Math.floor(e/1e3));if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m ${String(t%60).padStart(2,`0`)}s`:`${Math.floor(n/60)}h ${String(n%60).padStart(2,`0`)}m`}function Q(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}t();var Ue=[[`backup`,`list`]];function We({initialDestinationId:e,initialArchiveId:t,onClose:i,onScheduled:l}){let u=a(),[d,f]=o(e&&t?2:1),[p,h]=o(e),[g,_]=o(t),[v,y]=o(new Set),{data:x}=A(),S=x??[],{data:C,isLoading:w}=M({destinationId:p??``},{enabled:!!p}),T=C??[];c(()=>{if(p!==void 0)return;let e=S.filter(e=>e.restoreSupported);e.length===1&&h(e[0].id)},[p,S]);let{data:E}=ee({destinationId:p??``,backupId:g??``},{enabled:!!p&&!!g}),D=r(()=>E?.locations??[],[E]);c(()=>{D.length!==0&&y(e=>e.size===0?new Set(D):e)},[D]);let O=ae({onSuccess:()=>{u.invalidateQueries({queryKey:Ue}),l(),i()}}),k=e=>{y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},j=!!p&&!!g,N=v.size>0,P=j&&N&&!O.isPending,F=()=>{!p||!g||O.mutate({destinationId:p,backupId:g,locations:[...v]})};return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:i,children:n(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[n(`div`,{className:`space-y-0.5`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),n(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,d,` of 3 —`,` `,d===1?`pick source`:d===2?`pick locations`:`confirm`]})]}),s(`button`,{onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:s(b,{className:`h-4 w-4`})})]}),d===1&&s(Ge,{destinations:S,destinationId:p,onPickDestination:e=>{h(e),_(void 0),y(new Set)},archives:T,archivesLoading:w,archiveId:g,onPickArchive:_}),d===2&&s(Ke,{locations:D,picked:v,onToggle:k}),d===3&&s(qe,{destinationName:S.find(e=>e.id===p)?.displayName??p??``,archive:T.find(e=>e.id===g),picked:[...v]}),n(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[s(`div`,{children:d>1&&n(`button`,{onClick:()=>f(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:[s(m,{className:`h-3 w-3`}),`Back`]})}),n(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),d<3?n(`button`,{disabled:d===1&&!j||d===2&&!N,onClick:()=>f(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`,s(ce,{className:`h-3 w-3`})]}):n(`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:[O.isPending?s(R,{className:`h-3.5 w-3.5 animate-spin`}):s(I,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function Ge({destinations:e,destinationId:t,onPickDestination:r,archives:i,archivesLoading:a,archiveId:o,onPickArchive:c}){let l=e.filter(e=>e.restoreSupported);return n(`div`,{className:`p-4 space-y-3`,children:[n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),n(`select`,{value:t??``,onChange:e=>r(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:[s(`option`,{value:``,disabled:!0,children:`Select destination…`}),l.map(e=>n(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&a&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!a&&i.length===0&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&i.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:i.map(e=>{let t=o===e.id;return n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>c(e.id),className:`accent-primary`}),n(`div`,{children:[s(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),s(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:q(e.sizeBytes)})]},e.id)})})]})]})}function Ke({locations:e,picked:t,onToggle:r}){return e.length===0?s(`div`,{className:`p-4`,children:s(`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.`})}):n(`div`,{className:`p-4 space-y-3`,children:[s(`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.`}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>n(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>r(e),className:`accent-primary`}),s(`span`,{className:`font-mono text-foreground`,children:e}),s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ye(e)})]},e))})]})]})}function qe({destinationName:e,archive:t,picked:r}){return n(`div`,{className:`p-4 space-y-3 text-xs`,children:[s(`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.`}),n(`dl`,{className:`space-y-1.5`,children:[s($,{term:`Destination`,value:e}),s($,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&s($,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${q(t.sizeBytes)}`}),s($,{term:`Locations`,value:r.length>0?r.join(`, `):`— (full archive)`})]})]})}function $({term:e,value:t}){return n(`div`,{className:`flex justify-between gap-3`,children:[s(`dt`,{className:`text-foreground-subtle`,children:e}),s(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Je={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function Ye(e){return Je[e]??``}t();function Xe(){let e=S(),t=_(),[r,i]=o(null),[a,c]=o(!1),[l,u]=o(!1),[d,f]=o(void 0),p=async()=>{await e({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&t.mutate({confirm:!0})};return n(K,{children:[n(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[n(`button`,{onClick:()=>c(!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:[s(I,{className:`h-3.5 w-3.5`}),`Restore…`]}),n(`button`,{onClick:()=>f(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:[s(x,{className:`h-3.5 w-3.5`}),`New entry`]})]}),l&&s(`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:n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(I,{className:`h-3.5 w-3.5`}),s(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),n(`button`,{onClick:()=>{p()},disabled:t.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:[t.isPending?s(R,{className:`h-3.5 w-3.5 animate-spin`}):s(I,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),s(Fe,{}),s(Ce,{onEdit:e=>f(e),onOpenRestoreWizard:e=>i(e)}),d!==void 0&&s(je,{entry:d,onClose:()=>f(void 0),onSaved:()=>f(void 0)}),(r||a)&&s(We,{...r?{initialDestinationId:r.destinationId,initialArchiveId:r.archiveId}:{},onClose:()=>{i(null),c(!1)},onScheduled:()=>u(!0)})]})}function Ze(){return s(`div`,{className:`flex flex-col p-4`,children:s(me,{tabs:[{id:`storage`,label:`Storage`,icon:te,content:s(_e,{})},{id:`backup`,label:`Backup`,icon:z,content:s(Xe,{})}]})})}export{Ze as DataPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,b as a,o,q as s,x as c,z as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as u,at as d,ct as f,ft as p,gt as m,st as h,yt as g}from"./player-overlays-Dpyv2MuF.js";import{$t as _,Bi as v,Bt as y,Dl as b,Fi as x,Ft as S,Gi as C,Hi as w,Ii as T,It as E,Li as D,Lt as O,Ni as k,Nt as A,Oc as j,Pi as M,Pt as N,Qc as P,Ri as F,Tc as I,Tl as L,Uc as R,Ui as z,Vc as B,Vi as V,Wi as H,_n as ee,an as U,jt as W,ml as G,oi as te,on as K,vl as ne,wu as re,yl as q,zc as ie,zi as J,zl as Y}from"./src-DeANpHOz.js";import{i as ae,n as oe,r as se,t as ce}from"./face-bbox-Bw09XNv0.js";import{t as X}from"./square-check-big-CyuyrB82.js";import{t as Z}from"./user-round-CWLSjfaj.js";import{In as le}from"./src-BjMTOeHt.js";import{l as ue}from"./index-SOjqIyqv.js";import{t as de}from"./AdminPage-CiKtOLQm.js";import{n as fe,r as pe}from"./authed-media-Bhswngiz.js";import{a as me,c as he,f as ge,i as _e,l as ve,n as ye,o as be,p as xe,r as Se,s as Ce,t as we,u as Te}from"./debounced-invalidate-BMyWMwma.js";var Ee=g(`image-plus`,[[`path`,{d:`M16 5h6`,key:`1vod17`}],[`path`,{d:`M19 2v6`,key:`4bpg5p`}],[`path`,{d:`M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5`,key:`1ue2ih`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}]]);n();var De=`pipeline-analytics`,Oe=`photo.analyze`,ke=`photo.enroll`,Ae=`photo.discard`,je=18*1024*1024;function Me(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function $(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Ne(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Pe(e){if(!Me(e))return null;let t=$(e,`x`),n=$(e,`y`),r=$(e,`width`),i=$(e,`height`);return t===null||n===null||r===null||i===null?null:{x:t,y:n,width:r,height:i}}function Fe(e){if(!Me(e))return null;let t=$(e,`detectionShortSidePx`),n=$(e,`score`);if(t===null||n===null)return null;let r=$(e,`magnitude`);return{detectionShortSidePx:t,score:n,...r===null?{}:{magnitude:r}}}function Ie(e){if(!Me(e))return null;let t=$(e,`faceIndex`),n=$(e,`score`),r=Ne(e,`enrollable`),i=Pe(e.bbox),a=Fe(e.quality);if(t===null||n===null||r===null||i===null||a===null)return null;let o=Q(e,`refusedReason`),s=Q(e,`alignedCropBase64`),c=Q(e,`modelId`);return{faceIndex:t,bbox:i,score:n,enrollable:r,quality:a,...o===null?{}:{refusedReason:o},...s===null?{}:{alignedCropBase64:s},...c===null?{}:{modelId:c}}}function Le(e){if(!Me(e))return null;let t=Q(e,`sessionId`),n=Q(e,`ranOnNodeId`),r=e.faces;if(t===null||n===null||!Array.isArray(r))return null;let i=[];for(let e of r){let t=Ie(e);t!==null&&i.push(t)}return{sessionId:t,ranOnNodeId:n,faces:i}}function Re(e){if(!Me(e))return null;let t=Q(e,`sampleId`),n=Q(e,`identityId`),r=Q(e,`modelId`);return t===null||n===null||r===null?null:{sampleId:t,identityId:n,modelId:r}}function ze(e,t,n){let r={...e};return n===null||n===``?delete r[t]:r[t]=n,r}function Be(e,t){return e.filter(e=>e.enrollable&&t[e.faceIndex]!==void 0).length}function Ve(e,t,n){let r=[];for(let i of t){if(!i.enrollable)continue;let t=n[i.faceIndex];t!==void 0&&r.push({sessionId:e,faceIndex:i.faceIndex,identityId:t})}return r}function He(e){switch(e){case`no-embedding`:return`Too small or too indistinct for the recognizer to measure — try a photo where this face is larger.`;case`no-model-id`:return`The recognizer did not report which model it used, so this face cannot be enrolled safely.`;case`no-aligned-crop`:return`The recognizer produced no aligned crop for this face, so there is nothing to store.`;case`magnitude`:return`Refused by the quality gate: the features look degenerate, and a sample like this matches everybody.`;default:return`This face is not usable as a sample.`}}function Ue(e,t){let n=[],r=[];for(let i of e)i.size>t.maxBytes?n.push(i.name):r.push(i);return{accepted:r.slice(0,t.maxCount),oversize:n,overflow:r.slice(t.maxCount).map(e=>e.name)}}async function We(e,t,n){let r=Array(e.length),i=e.map((e,t)=>({item:e,index:t})),a=0,o=async()=>{for(;;){let e=i[a];if(a+=1,e===void 0)return;r[e.index]=await n(e.item,e.index)}},s=Array.from({length:Math.max(1,Math.min(t,e.length))},()=>o());return await Promise.all(s),r}function Ge(e,t,n){return e.map(e=>e.photoIndex===t?{...e,...n}:e)}function Ke(e,t){return`${e}:${t}`}function qe(e,t,n,r){let i=ze(e[t]??{},n,r),a={...e};return Object.keys(i).length===0?delete a[t]:a[t]=i,a}function Je(e,t){let n=0;for(let r of e)r.analysis!==void 0&&(n+=Be(r.analysis.faces,t[r.photoIndex]??{}));return n}var Ye=`__new__`;function Xe(e,t,n){let r=[];for(let i of e){if(i.analysis===void 0)continue;let e=t[i.photoIndex]??{};for(let t of i.analysis.faces){if(!t.enrollable||e[t.faceIndex]!==`__new__`)continue;let a=(n[Ke(i.photoIndex,t.faceIndex)]??``).trim();if(a===``)return{kind:`error`,message:`${i.filename}: face ${t.faceIndex+1} is set to a new person but has no name.`};r.includes(a)||r.push(a)}}return{kind:`ok`,names:r}}function Ze(e,t,n){let r={};for(let[i,a]of Object.entries(e)){let e=Number(i),o={};for(let[r,i]of Object.entries(a)){let a=Number(r);if(i!==`__new__`){o[a]=i;continue}let s=n[(t[Ke(e,a)]??``).trim()];s!==void 0&&(o[a]=s)}r[e]=o}return r}function Qe(e,t){let n=[];for(let r of e){if(r.analysis===void 0)continue;let e=Ve(r.analysis.sessionId,r.analysis.faces,t[r.photoIndex]??{});for(let t of e)n.push({photoIndex:r.photoIndex,request:t})}return n}function $e(e){return/expired/i.test(e)}function et(e){return e instanceof Error?e.message:String(e)}async function tt(e,t,n){let r=new Map(e.map(e=>[e.photoIndex,e])),i={},a=[],o=0,s=null,c=(e,t)=>`${r.get(e)?.filename??`photo ${e+1}`}, face ${t+1}`;for(let l of Qe(e,t)){let e=i[l.photoIndex],t=e===void 0?l.request:{...l.request,sessionId:e.sessionId};try{let e=await n.enroll(t);o+=1,s=e.modelId}catch(t){let u=et(t);if(!$e(u)||e!==void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${u}`);continue}let d=r.get(l.photoIndex);if(d===void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${u}`);continue}let f;try{f=await n.reanalyze(d)}catch(e){a.push(`${c(l.photoIndex,l.request.faceIndex)}: the analysis expired and re-analysing failed (${et(e)})`);continue}if(i[l.photoIndex]=f,f.faces.find(e=>e.faceIndex===l.request.faceIndex&&e.enrollable)===void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: the analysis expired, and re-analysing no longer finds this face — assign it again from the fresh result`);continue}try{let e=await n.enroll({...l.request,sessionId:f.sessionId});o+=1,s=e.modelId}catch(e){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${et(e)}`)}}}return{enrolled:o,stampedModelId:s,failures:a,refreshedAnalyses:i}}var nt=[[`faceGallery`]],rt=``;function it(e){return new Promise((t,n)=>{let r=new FileReader;r.addEventListener(`error`,()=>n(Error(`the file could not be read`)),{once:!0}),r.addEventListener(`load`,()=>{let e=r.result;if(typeof e!=`string`){n(Error(`the file could not be read`));return}let i=e.indexOf(`,`);t(i>=0?e.slice(i+1):e)},{once:!0}),r.readAsDataURL(e)})}function at(e){return e instanceof Error?e.message:String(e)}function ot({face:e,identities:t,value:n,onChange:o,disabled:s}){let l=i(()=>[{value:rt,label:`Ignore this face`},...t.map(e=>({value:e.id,label:e.name})),{value:Ye,label:`+ New person…`}],[t]);return r(`div`,{className:`rounded-md border border-border bg-surface p-2`,children:[c(`div`,{className:`mb-2 aspect-square w-full overflow-hidden rounded border border-border bg-surface-hover`,children:e.alignedCropBase64?c(`img`,{src:`data:image/jpeg;base64,${e.alignedCropBase64}`,alt:`Face ${e.faceIndex+1}`,className:`h-full w-full object-cover`}):c(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:c(Z,{className:`h-8 w-8`})})}),e.enrollable?r(a,{children:[c(U,{options:l,value:n,disabled:s,onChange:e=>o(e.target.value),"aria-label":`Assign face ${e.faceIndex+1}`}),r(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:[Math.round(e.quality.detectionShortSidePx),` px`,e.modelId?` · ${e.modelId}`:``]})]}):r(`div`,{className:`space-y-1`,children:[c(_,{variant:`warning`,className:`text-[10px]`,children:`Not usable`}),c(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:He(e.refusedReason)})]})]})}function st({photo:e,identities:t,draft:n,newNames:i,disabled:a,onAssign:o,onNameChange:s,onRetry:l}){let u=e.analysis?.faces??[],d=n[e.photoIndex]??{};return r(`div`,{className:`space-y-2`,children:[r(`div`,{className:`flex items-center gap-2 border-b border-border pb-1`,children:[c(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.filename}),e.status===`analyzing`||e.status===`queued`?r(`span`,{className:`flex items-center gap-1 text-xs text-foreground-subtle`,children:[c(Y,{className:`h-3 w-3 animate-spin`}),` analysing…`]}):null,e.status===`analyzed`&&e.analysis!==void 0&&r(`span`,{className:`text-xs text-foreground-subtle`,children:[u.length,` face`,u.length===1?``:`s`,` · analysed on`,` `,e.analysis.ranOnNodeId]}),e.status===`failed`&&r(K,{variant:`secondary`,size:`sm`,disabled:a,onClick:l,children:[c(ne,{className:`h-3 w-3`}),` Retry`]})]}),e.status===`failed`&&r(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[c(R,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),r(`span`,{children:[`This photo could not be analysed: `,e.error??`unknown error`,`. The other photos are unaffected.`]})]}),e.status===`analyzed`&&u.length===0&&c(`p`,{className:`text-xs text-foreground-subtle`,children:`No faces were found in this photo. A face has to be reasonably large and facing the camera for the detector to measure it.`}),u.length>0&&c(`div`,{className:`grid grid-cols-3 gap-3 sm:grid-cols-4 md:grid-cols-5`,children:u.map(e=>c(ot,{face:e,identities:t,value:d[e.faceIndex]??rt,disabled:a,onChange:t=>o(e.faceIndex,t)},e.faceIndex))}),u.filter(e=>d[e.faceIndex]===Ye).map(t=>r(`div`,{className:`flex items-center gap-2`,children:[r(`span`,{className:`w-28 shrink-0 truncate text-xs text-foreground-subtle`,children:[`Face `,t.faceIndex+1]}),c(`input`,{className:`h-7 flex-1 rounded-md border border-border bg-surface px-2.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,placeholder:`New person name… (type the same name under another face to reuse it)`,value:i[Ke(e.photoIndex,t.faceIndex)]??``,onChange:e=>s(t.faceIndex,e.target.value)})]},t.faceIndex))]})}function ct({open:n,onOpenChange:a}){let l=d(),u=o(),f=t(null),{data:p}=F(),m=M(),[h,g]=s([]),[_,v]=s(!1),[y,b]=s(null),[x,C]=s({}),[w,T]=s({}),[D,k]=s(null),j=i(()=>(p??[]).map(e=>({id:e.id,name:e.name})),[p]),P=h.some(e=>e.status===`queued`||e.status===`analyzing`),I=P||_,L=e(e=>{for(let t of e){let e=t.analysis?.sessionId;e!==void 0&&l.trpcClient.addons.custom.mutate({addonId:De,action:Ae,input:{sessionId:e}}).catch(()=>void 0)}},[l]),z=e(()=>{g([]),C({}),T({}),b(null),k(null),f.current&&(f.current.value=``)},[]),B=e(()=>{L(h),z(),a(!1)},[L,a,h,z]),V=e(async e=>{let t=Le(await l.trpcClient.addons.custom.mutate({addonId:De,action:Oe,input:{photoBase64:e.photoBase64,filename:e.filename}}));if(t===null)throw Error(`the server replied with something this page could not read`);return t},[l]),H=e(async e=>{g(t=>Ge(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await V(e);g(n=>Ge(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){g(n=>Ge(n,e.photoIndex,{status:`failed`,error:at(t)}))}},[V]),ee=e(async e=>{if(e.length===0)return;L(h),z();let t=Ue(e,{maxCount:12,maxBytes:je}),n=[];t.oversize.length>0&&n.push(`Over the ${Math.round(je/(1024*1024))} MB limit and skipped: ${t.oversize.join(`, `)}.`),t.overflow.length>0&&n.push(`A batch holds at most 12 photos — not analysed: ${t.overflow.join(`, `)}. Enrol them in a second round.`),n.length>0&&b(n.join(` `));let r;try{r=await Promise.all(t.accepted.map(async(e,t)=>({photoIndex:t,filename:e.name,photoBase64:await it(e),status:`queued`})))}catch(e){b(at(e));return}g(r),await We(r,2,e=>H(e))},[L,h,z,H]),U=Je(h,x),G=e(async()=>{v(!0),b(null),k(null);try{let e=Xe(h,x,w);if(e.kind===`error`){b(e.message);return}let t={};for(let n of e.names)t[n]=(await m.mutateAsync({name:n})).id;let n=await tt(h,Ze(x,w,t),{enroll:async e=>{let t=Re(await l.trpcClient.addons.custom.mutate({addonId:De,action:ke,input:e}));if(t===null)throw Error(`unreadable reply`);return t},reanalyze:e=>V(e)});Object.keys(n.refreshedAnalyses).length>0&&g(e=>e.map(e=>{let t=n.refreshedAnalyses[e.photoIndex];return t===void 0?e:{...e,status:`analyzed`,analysis:t}})),u.invalidateQueries({queryKey:nt}),n.failures.length>0&&b(n.failures.join(` · `)),k(n.enrolled===0?`Nothing was enrolled.`:`Enrolled ${n.enrolled} sample${n.enrolled===1?``:`s`}${n.stampedModelId===null?``:` with ${n.stampedModelId}`}.`)}catch(e){b(at(e))}finally{v(!1)}},[V,m,x,w,h,u,l]),te=h.filter(e=>e.status===`analyzed`).length;return c(W,{open:n,onOpenChange:e=>e?a(!0):B(),children:r(A,{className:`max-w-3xl`,children:[r(E,{children:[c(O,{children:`Enrol from photos`}),c(N,{children:`Every photo is analysed with the same face detector the cameras use, and all the faces found are reviewed below in one pass, grouped by photo. Assign each face to a person, or leave it ignored.`})]}),r(`div`,{className:`rounded-md border border-border bg-surface-hover px-3 py-2 text-xs text-foreground-subtle`,children:[`For reliable recognition use `,c(`strong`,{children:`at least 3 photos per person`}),`, taken at different times, with different poses and lighting — you can select them all at once. Several frames from the same moment count as one — they do not add information.`]}),r(`div`,{className:`flex items-center gap-2`,children:[c(`input`,{ref:f,type:`file`,accept:`image/jpeg,image/png,image/webp`,multiple:!0,className:`hidden`,onChange:e=>void ee(Array.from(e.target.files??[]))}),r(K,{variant:`secondary`,size:`sm`,disabled:I,onClick:()=>f.current?.click(),children:[P?c(Y,{className:`h-3.5 w-3.5 animate-spin`}):c(Ee,{className:`h-3.5 w-3.5`}),`Choose photos`]}),h.length>0&&r(`span`,{className:`text-xs text-foreground-subtle`,children:[te,`/`,h.length,` photo`,h.length===1?``:`s`,` analysed`]})]}),y!==null&&r(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[c(R,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),c(`span`,{children:y})]}),D!==null&&c(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:D}),h.length>0&&c(`div`,{className:`max-h-[50vh] space-y-4 overflow-y-auto pr-1`,children:h.map(e=>c(st,{photo:e,identities:j,draft:x,newNames:w,disabled:I,onAssign:(t,n)=>C(r=>qe(r,e.photoIndex,t,n===rt?null:n)),onNameChange:(t,n)=>T(r=>({...r,[Ke(e.photoIndex,t)]:n})),onRetry:()=>void H(e)},e.photoIndex))}),r(S,{children:[c(K,{variant:`secondary`,onClick:B,disabled:_,children:`Close`}),r(K,{variant:`primary`,onClick:()=>void G(),disabled:I||U===0,children:[_?c(Y,{className:`h-3.5 w-3.5 animate-spin`}):null,`Enrol `,U,` face`,U===1?``:`s`]})]})]})})}n();var lt=[[`faceGallery`]];function ut({identityId:e}){let t=o(),{data:n,isLoading:i}=J({identityId:e}),a=V();function s(n){a.mutate({identityId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:lt})}})}return i?r(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[c(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!n||n.length===0?c(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):c(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:n.map(e=>r(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?c(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):c(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:c(Z,{className:`h-6 w-6`})}),e.source===`photo`&&c(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 p-0.5 text-white`,title:`Enrolled from an uploaded photo`,children:c(Ee,{className:`h-3 w-3`})}),c(`button`,{type:`button`,onClick:()=>s(e),disabled:a.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove sample`,children:c(j,{className:`h-4 w-4 text-white`})})]},e.id))})}function dt({identity:e,expanded:t,onToggle:n}){let i=o(),[l,d]=s(``),[f,p]=s(!1),[g,v]=s(!1),x=w(),C=T();function D(){d(e.name),p(!0)}function k(){p(!1),d(``)}function M(){let t=l.trim();if(!t||t===e.name){k();return}x.mutate({id:e.id,name:t},{onSettled:()=>{i.invalidateQueries({queryKey:lt}),k()}})}function P(){C.mutate({id:e.id},{onSettled:()=>{i.invalidateQueries({queryKey:lt}),v(!1)}})}return r(`div`,{className:`rounded-md border border-border bg-surface`,children:[r(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[c(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:c(oe,{mediaId:e.coverMediaId,base64:e.coverBase64,alt:e.name,className:`h-full w-full object-cover`,placeholder:c(`div`,{className:`flex h-full w-full items-center justify-center`,children:c(Z,{className:`h-4 w-4 text-foreground-subtle`})})})}),c(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:f?r(a,{children:[c(y,{value:l,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&M(),e.key===`Escape`&&k()},className:`h-6 text-xs`,autoFocus:!0}),c(`button`,{type:`button`,onClick:M,disabled:x.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:c(re,{className:`h-3.5 w-3.5`})}),c(`button`,{type:`button`,onClick:k,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:c(j,{className:`h-3.5 w-3.5`})})]}):c(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),c(_,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!f&&r(`div`,{className:`flex items-center gap-1`,children:[c(`button`,{type:`button`,onClick:D,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:c(b,{className:`h-3.5 w-3.5`})}),c(`button`,{type:`button`,onClick:()=>v(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:c(h,{className:`h-3.5 w-3.5`})})]}),c(`button`,{type:`button`,onClick:n,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:c(t?u:m,{className:`h-3.5 w-3.5`})})]}),t&&c(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:c(ut,{identityId:e.id})}),c(W,{open:g,onOpenChange:e=>!e&&v(!1),children:r(A,{children:[r(E,{children:[c(O,{children:`Delete person`}),r(N,{children:[`Delete `,c(`strong`,{children:e.name}),` and all their samples? This cannot be undone.`]})]}),r(S,{children:[c(K,{variant:`secondary`,onClick:()=>v(!1),children:`Cancel`}),r(K,{variant:`danger`,onClick:P,disabled:C.isPending,children:[C.isPending?c(Y,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function ft(){let e=o(),[t,n]=s(``),i=M();function a(){let r=t.trim();r&&i.mutate({name:r},{onSettled:()=>{e.invalidateQueries({queryKey:lt}),n(``)}})}return r(`div`,{className:`flex items-center gap-2 pt-2`,children:[c(y,{placeholder:`New person name…`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&a()},className:`h-7 text-xs flex-1`}),r(K,{variant:`primary`,size:`sm`,onClick:a,disabled:i.isPending||!t.trim(),children:[i.isPending?c(Y,{className:`h-3.5 w-3.5 animate-spin`}):c(L,{className:`h-3.5 w-3.5`}),`Add`]})]})}function pt(){let{data:e,isLoading:t}=F(),[n,i]=s(null),[a,o]=s(!1);function l(e){i(t=>t===e?null:e)}return t?r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[c(Y,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):r(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&c(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),e?.map(e=>c(dt,{identity:e,expanded:n===e.id,onToggle:()=>l(e.id)},e.id)),c(ft,{}),c(`div`,{className:`pt-1`,children:r(K,{variant:`secondary`,size:`sm`,onClick:()=>o(!0),children:[c(Ee,{className:`h-3.5 w-3.5`}),`Enrol from a photo`]})}),c(ct,{open:a,onOpenChange:o})]})}function mt(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function ht(e){return e.filter(mt).map(e=>e.faceId)}function gt(e){let t=0;for(let n of e)mt(n)&&(t+=1);return t}function _t(e){return e==null?null:e.cropUrl!==void 0&&e.cropUrl.length>0?e.cropUrl:e.base64!==void 0&&e.base64.length>0?`data:image/jpeg;base64,${e.base64}`:null}n();var vt=[[`faceGallery`]];function yt({faceIds:e,identities:t,onDone:n}){let i=o(),a=k(),l=M(),[u,d]=s(``),[f,p]=s(!1),[m,h]=s(null),g=e!==null&&e.length>0,_=e?.length??0;function v(){p(!1),d(``),h(null)}function b(){v(),n()}function x(t){!e||e.length===0||a.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{i.invalidateQueries({queryKey:vt}),b()}})}function C(){!e||!u.trim()||l.mutate({name:u.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{i.invalidateQueries({queryKey:vt}),b()}})}let w=a.isPending||l.isPending;return c(W,{open:g,onOpenChange:e=>!e&&b(),children:r(A,{children:[r(E,{children:[c(O,{children:_>1?`Assign ${String(_)} faces to person`:`Assign face to person`}),c(N,{children:`Select an existing person or create a new one.`})]}),c(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>r(`button`,{type:`button`,onClick:()=>h(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${m===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[c(`span`,{className:`font-medium`,children:e.name}),r(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),f?c(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:c(y,{placeholder:`New person name…`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&C()},autoFocus:!0,className:`flex-1`})}):c(`button`,{type:`button`,onClick:()=>{h(null),p(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:`+ New person…`}),r(S,{children:[c(K,{variant:`secondary`,onClick:b,disabled:w,children:`Cancel`}),f?r(K,{variant:`primary`,onClick:C,disabled:w||!u.trim(),children:[w&&c(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):r(K,{variant:`primary`,onClick:()=>m&&x(m),disabled:w||!m,children:[w&&c(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,_>1?` ${String(_)}`:``]})]})]})})}n();function bt(e){let[t,n]=s(null),[r,i]=s(null),[a,o]=s(!1);return l(()=>{if(n(null),i(null),o(!1),e===void 0)return;let t=!1,r=null;return(async()=>{try{let i=await fe(pe(e));if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),l(()=>{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 xt(e){let t=e.filter(e=>e.url.length>0);return t.length===0?null:t.find(e=>/crop|face/i.test(e.kind))??t[0]}function St({label:e,value:t}){return r(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[c(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),c(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:t})]})}function Ct({box:e}){return c(`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:c(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Face`})})}function wt({face:e,cameraName:t,onClose:n,onAssign:a,onUnassign:o,onDelete:l,actionsPending:u}){let{data:d,isFetching:f}=D({faceId:e?.faceId??``},{enabled:e!==null}),[m,g]=s(`frame`),{frameSrc:_,naturalWidth:v,naturalHeight:y,failed:b}=bt(e?.keyFrameMediaId),x=i(()=>{let t=xt(d??[]);return t?t.url:_t(e)},[d,e]),S=i(()=>!e?.faceBbox||v===null||y===null?null:ce(e.faceBbox,v,y),[e?.faceBbox,v,y]);if(e===null)return null;let C=e.keyFrameMediaId!==void 0&&!b,w=C&&m===`frame`,T=e.assigned?e.identityName??`Assigned`:e.recognizedIdentityId?`${e.identityName??`Recognized`} (suggested)`:`Unassigned`;return c(W,{open:!0,onOpenChange:e=>!e&&n(),children:r(A,{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:[r(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`min-w-0`,children:[c(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:`Face detail`}),c(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),c(`button`,{type:`button`,onClick:n,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:c(j,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[C&&r(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[r(`button`,{type:`button`,onClick:()=>g(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${m===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[c(G,{className:`h-3.5 w-3.5`}),` Full frame`]}),r(`button`,{type:`button`,onClick:()=>g(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${m===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[c(ae,{className:`h-3.5 w-3.5`}),` Crop`]})]}),w&&_?c(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:c(ye,{src:_,alt:`Full frame with detected face`,fit:`natural`,className:`w-full`,overlay:S?c(Ct,{box:S}):void 0})}):x?r(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[c(ye,{src:x,alt:`Detected face`,className:`h-full w-full`}),f&&c(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:c(Y,{className:`h-3.5 w-3.5 animate-spin`})})]}):r(`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:[c(p,{className:`h-8 w-8 text-warning/70`}),c(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),c(`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.`})]}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[c(St,{label:`Camera`,value:t}),c(St,{label:`Captured`,value:xe(e.timestamp)}),c(St,{label:`Track`,value:e.trackId}),c(St,{label:`Identity`,value:T})]})]}),r(`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?r(K,{variant:`secondary`,onClick:()=>o(e.faceId),disabled:u,children:[c(se,{className:`h-3.5 w-3.5`}),` Detach`]}):r(K,{variant:`primary`,onClick:()=>a(e.faceId),disabled:u,children:[c(ie,{className:`h-3.5 w-3.5`}),` Assign`]}),r(K,{variant:`secondary`,onClick:()=>l(e.faceId),disabled:u,children:[c(h,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}function Tt(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function Et(e,t){return e.faceIds.filter(e=>!t.has(e))}function Dt(e,t){return e.faceIds.filter(e=>t(e))}n();var Ot=[[`faceGallery`]],kt=20,At=.3,jt=.9,Mt=.05,Nt=.5,Pt=2,Ft=10,It=2;function Lt({cluster:e,face:t,active:n,onSelect:i}){let a=_t(t);return r(`button`,{type:`button`,onClick:i,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:[c(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:a===null?c(p,{className:`h-24 w-24 p-6 text-foreground-subtle`}):c(`img`,{src:a,alt:``,loading:`lazy`,decoding:`async`,className:`h-24 w-24 object-cover`})}),r(`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 Rt({face:e,cameraName:t,nowMs:n,excluded:i,onToggleExclude:a,onDelete:o,deletePending:s}){let l=_t(e);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${i?`border-border opacity-40 grayscale`:`border-border`}`,children:[r(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[l===null?r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[c(p,{className:`h-7 w-7 text-warning/70`}),c(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):c(ye,{src:l,alt:`Face from ${t}`,className:`h-full w-full`}),c(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},className:`absolute right-1 top-1 z-10 rounded-full bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Include face`:`Exclude face`,title:i?`Include`:`Exclude`,children:c(i?B:j,{className:`h-3.5 w-3.5`})})]}),r(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[c(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),c(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:ge(e.timestamp,n)})]}),c(`div`,{className:`mt-1 flex items-center justify-end border-t border-border/60 px-1 py-0.5`,children:c(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},disabled:s,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:s?c(Y,{className:`h-4 w-4 animate-spin`}):c(h,{className:`h-4 w-4`})})})]})}function zt({open:e,onClose:t,byId:n,cameraName:u,nowMs:d,identities:f,selectMany:p}){let m=o(),h=ee(),g=x(),[_,v]=s(Nt),[y,b]=s(It),[S,C]=s(null),[w,T]=s({}),[E,D]=s(null),{data:O,isFetching:k,refetch:M}=z({threshold:_,minClusterSize:y,limit:kt},{enabled:e}),N=O??[];l(()=>{T({})},[_,y]),l(()=>{if(N.length===0){C(null);return}N.some(e=>e.representativeFaceId===S)||C(N[0]?.representativeFaceId??null)},[N]);let F=i(()=>N.find(e=>e.representativeFaceId===S)??null,[N,S]),I=F?w[F.representativeFaceId]??new Set:new Set,L=i(()=>F?Dt(F,e=>n.has(e)):[],[F,n]),R=F?F.faceIds.length-L.length:0,B=F?Et({...F,faceIds:L},I):[];function V(e){if(!F)return;let t=F.representativeFaceId;T(n=>({...n,[t]:Tt(n[t]??new Set,e)}))}function H(){m.invalidateQueries({queryKey:Ot})}async function U(e){await h({title:`Delete face`,message:`Permanently deletes this face crop. This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&g.mutate({faceId:e},{onSettled:H})}function G(){D(null),t()}function te(){B.length!==0&&(p(B),G())}return r(W,{open:e,onOpenChange:e=>!e&&G(),children:[r(A,{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:[r(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`flex items-center justify-between gap-2`,children:[r(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[c(P,{className:`h-4 w-4 text-primary`}),` Look-alike groups`]}),c(`button`,{type:`button`,onClick:G,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:c(j,{className:`h-4 w-4`})})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[r(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Threshold`,c(`input`,{type:`range`,min:At,max:jt,step:Mt,value:_,onChange:e=>v(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),c(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:_.toFixed(2)})]}),r(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Min size`,c(`input`,{type:`number`,min:Pt,max:Ft,step:1,value:y,onChange:e=>b(Math.min(Ft,Math.max(Pt,Number(e.target.value)||Pt))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),r(K,{variant:`secondary`,onClick:()=>{T({}),M()},disabled:k,children:[k?c(Y,{className:`h-3.5 w-3.5 animate-spin`}):c(q,{className:`h-3.5 w-3.5`}),`Re-analyze`]})]})]}),c(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:k&&N.length===0?r(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[c(Y,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):N.length===0?c(`div`,{className:`flex flex-1 items-center justify-center py-8 text-xs text-foreground-subtle`,children:`No look-alike groups at this threshold.`}):r(a,{children:[c(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:N.map(e=>c(Lt,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===S,onSelect:()=>C(e.representativeFaceId)},e.representativeFaceId))}),c(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:N.map(e=>c(Lt,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===S,onSelect:()=>C(e.representativeFaceId)},e.representativeFaceId))}),c(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:F&&r(a,{children:[R>0&&r(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:[R,` not loaded — excluded from actions`]}),c(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,1fr))] gap-2`,children:L.map(e=>{let t=n.get(e);return t?c(Rt,{face:t,cameraName:u(t.deviceId),nowMs:d,excluded:I.has(e),onToggleExclude:()=>V(e),onDelete:()=>void U(e),deletePending:g.isPending&&g.variables?.faceId===e},e):null})})]})})]})}),r(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[c(K,{variant:`secondary`,onClick:te,disabled:B.length===0,children:`Select in gallery`}),r(K,{variant:`primary`,onClick:()=>D(B),disabled:B.length===0,children:[c(ie,{className:`h-3.5 w-3.5`}),` Adopt (`,B.length,`)`]})]})]}),c(yt,{faceIds:E,identities:f,onDone:()=>D(null)})]})}n();var Bt=[[`faceGallery`]],Vt=500,Ht=120;function Ut({face:e,cameraName:t,nowMs:n,selected:i,onToggleSelect:a,onAssign:s,onOpenDetail:l}){let u=o(),d=H(),m=x(),g=()=>{u.invalidateQueries({queryKey:Bt})},_=()=>l(e.faceId),v=_t(e);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[r(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[v===null?r(`button`,{type:`button`,onClick:_,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:[c(p,{className:`h-7 w-7 text-warning/70`}),c(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):c(`img`,{src:v,alt:`Face from ${t}`,onClick:_,loading:`lazy`,decoding:`async`,className:`h-full w-full cursor-zoom-in object-cover`}),c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(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":i?`Deselect`:`Select`,children:i?c(X,{className:`h-4 w-4 text-primary`}):c(f,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[c(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),c(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:ge(e.timestamp,n)}),e.identityName&&c(`p`,{className:`text-[10px] font-medium text-primary truncate`,title:e.identityName,children:e.identityName})]}),r(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),d.mutate({faceId:e.faceId},{onSettled:g})},disabled:d.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:d.isPending?c(Y,{className:`h-4 w-4 animate-spin`}):c(se,{className:`h-4 w-4`})}):c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(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:c(ie,{className:`h-4 w-4`})}),c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),m.mutate({faceId:e.faceId},{onSettled:g})},disabled:m.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:m.isPending?c(Y,{className:`h-4 w-4 animate-spin`}):c(h,{className:`h-4 w-4`})})]})]})}var Wt=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function Gt(){let e=o(),[t,n]=s(`all`),[l,u]=s(Ce),[d,f]=s(new Set),[m,g]=s(new Set),[_,y]=s(null),[b,S]=s(!1),[w,T]=s(null),{data:E,isLoading:D}=v({limit:Vt,filter:t,includeCrops:!1},{refetchInterval:3e4}),{data:O=[]}=F(),{data:A}=te({isCamera:!0,projection:`slim`}),M=k(),N=H(),I=C(),L=x(),R=Date.now(),z=E??[],B=i(()=>{let e=new Map;for(let t of A??[])e.set(t.id,t.name);return e},[A]),V=e=>B.get(e)??`Camera #${String(e)}`,ee=i(()=>he(z).map(e=>({id:e,name:V(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[z,B]),U=i(()=>ve(Te(z,l),d),[z,l,d]),W=be(U,Ht,i(()=>JSON.stringify([t,l.fromMs,l.toMs,[...d].sort((e,t)=>e-t)]),[t,l.fromMs,l.toMs,d])),G=i(()=>new Map(z.map(e=>[e.faceId,e])),[z]),ne=i(()=>gt(U),[U]),re=w===null?null:G.get(w)??null,q=()=>{e.invalidateQueries({queryKey:Bt})},J=()=>g(new Set);function ae(e){g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function oe(e){g(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function ce(){oe(ht(U))}let X=[...m],Z=M.isPending||I.isPending||L.isPending,le=N.isPending||L.isPending;function ue(){X.length!==0&&I.mutate({faceIds:X},{onSettled:()=>{q(),J()}})}function de(){X.length!==0&&Promise.allSettled(X.map(e=>L.mutateAsync({faceId:e}))).then(()=>{q(),J()})}function fe(e){T(null),y([e])}function pe(e){N.mutate({faceId:e},{onSettled:q}),T(null)}function ge(e){L.mutate({faceId:e},{onSettled:q}),T(null)}let ye=U.length!==z.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[c(`div`,{className:`flex items-center gap-1`,children:Wt.map(e=>c(`button`,{type:`button`,onClick:()=>n(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${t===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value))}),c(Se,{onChange:u}),c(_e,{cameras:ee,selected:d,onChange:f}),r(`button`,{type:`button`,onClick:()=>S(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${b?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[c(P,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!D&&ne>0&&r(`button`,{type:`button`,onClick:ce,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:[c(p,{className:`h-3.5 w-3.5`}),` Select `,ne,` crop-less`]}),!D&&c(`span`,{className:`text-[10px] text-foreground-subtle ${ne>0?`ml-2`:`ml-auto`}`,children:ye?`${String(U.length)} of ${String(z.length)} faces`:`${String(U.length)} face${U.length===1?``:`s`}`})]}),m.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[m.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[r(K,{variant:`primary`,onClick:()=>y(X),disabled:Z,children:[c(ie,{className:`h-3.5 w-3.5`}),` Assign`]}),r(K,{variant:`secondary`,onClick:ue,disabled:Z,children:[I.isPending?c(Y,{className:`h-3.5 w-3.5 animate-spin`}):c(se,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),r(K,{variant:`secondary`,onClick:de,disabled:Z,children:[c(h,{className:`h-3.5 w-3.5`}),` Delete`]}),c(K,{variant:`ghost`,onClick:J,disabled:Z,children:c(j,{className:`h-3.5 w-3.5`})})]})]}),D&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[c(Y,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!D&&U.length===0&&c(`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.`}),!D&&U.length>0&&r(a,{children:[c(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(6.5rem,1fr))] gap-2`,children:W.pageItems.map(e=>c(Ut,{face:e,cameraName:V(e.deviceId),nowMs:R,selected:m.has(e.faceId),onToggleSelect:ae,onAssign:e=>y([e]),onOpenDetail:T},e.faceId))}),c(me,{currentPage:W.page,totalItems:W.totalItems,pageSize:W.pageSize,onPageChange:W.setPage,itemNoun:`faces`})]}),c(wt,{face:re,cameraName:re?V(re.deviceId):``,onClose:()=>T(null),onAssign:fe,onUnassign:pe,onDelete:ge,actionsPending:le}),c(yt,{faceIds:_,identities:O,onDone:()=>{y(null),J()}}),c(zt,{open:b,onClose:()=>S(!1),byId:G,cameraName:V,nowMs:R,identities:O,selectMany:oe})]})}n();var Kt=[[`faceGallery`]],qt=2e3;function Jt(){let e=o(),n=t(e);n.current=e;let r=t(void 0);r.current||=we({delayMs:qt,invalidate:()=>{n.current.invalidateQueries({queryKey:Kt})}}),l(()=>()=>r.current?.cancel(),[]),I(le.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function Yt(){return Jt(),c(de,{icon:ue,title:`Faces`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:r(`section`,{className:`space-y-3`,children:[r(`div`,{children:[c(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),c(`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.`}),c(pt,{})]}),r(`div`,{className:`pt-4 border-t border-border`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),c(`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.`}),c(Gt,{})]})]})})}export{Yt as DetectionIntelligencePage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,o as a,q as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Fs as c,Mi as l,Ps as u,bi as d,ii as f,ji as p,ri as m,zl as h}from"./src-DeANpHOz.js";import{jn as g}from"./src-BjMTOeHt.js";import{r as _}from"./index-SOjqIyqv.js";import{n as v,r as y,t as b}from"./SchemaTabBar-Bvm8GY8a.js";import{t as x}from"./FormBuilder-BAhlMxtA.js";import{t as S}from"./StableTabPanel-Dc954AQl.js";n();function C({schema:e,values:n,pendingKeys:a,onChange:c,onAction:l,onSave:u,onDiscard:d,disabled:f,activeSubTab:p,onSubTabChange:m,flattenTabs:h=!1}){let g=e.tabs??[],_=i(()=>{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]),y=new Set(g.map(e=>e.id)),C=[...g,...[..._.keys()].filter(e=>!y.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],w=C[0]?.id??`general`,[T,E]=o(w),D=m!==void 0,O=new Set(C.map(e=>e.id)),k=t(new Set);for(let e of O)k.current.add(e);let A=k.current,j=(e=>e&&(O.has(e)||A.has(e))?e:w)(D?p:T),M=e=>{D?m(e):E(e)},N=_.get(j)??[],P={sections:N.length<=1?N.length===1?[{...N[0],title:``}]:N:N.every(e=>!e.title)?[{...N[0],title:``,fields:N.flatMap(e=>e.fields)}]:N},F=s(v,{pendingCount:a.length,onSave:()=>u(a),onDiscard:()=>d(a),saving:f});if(h||C.length<=1)return r(`div`,{className:`flex flex-col gap-3`,children:[s(x,{schema:e,values:n,onChange:c,onAction:l,disabled:f}),F]});let I=new Map,L=new Map;for(let[e,t]of _){I.set(e,t.length);let n=new Set,r=e=>{for(let t of e)if(`key`in t&&typeof t.key==`string`&&n.add(t.key),t.type===`group`)r(t.fields);else if(t.type===`sub-tabs`)for(let e of t.tabs)r(e.fields)};for(let e of t)r(e.fields);let i=a.filter(e=>n.has(e)).length;i>0&&L.set(e,i)}return r(`div`,{className:`flex flex-col gap-3`,children:[s(b,{tabs:C.map(e=>({id:e.id,label:e.label})),activeId:j,onChange:M,countByTab:I,pendingByTab:L}),s(S,{tabKey:j,children:s(x,{schema:P,values:n,onChange:c,onAction:l,disabled:f})}),F]})}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.tab===`export`?!0:e.fields.some(D)}n();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:n,sectionFilter:o,activeSubTab:v,onSubTabChange:b,flattenSubTabs:x,subTabGrouping:S}){let w=a(),{user:T}=_(),E=T?.isAdmin===!0,D=t(!1),{data:k,isLoading:j}=f({deviceId:n},{refetchInterval:()=>D.current?!1:2500,enabled:Number.isFinite(n)}),{data:M}=m({deviceId:n},{enabled:Number.isFinite(n)}),N=k?.settings??null,P=k?.live??null,F=i(()=>{if(!N&&!P)return null;let e=N?.sections??[],t=(P?.sections??[]).map(R),n=[...e,...t],r=o?n.filter(o):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,o,S]),z=i(()=>A(F),[F]),V=i(()=>B(z,E),[z,E]),H=i(()=>I(V),[V]),U=c(),W=u(),G=p(),K=d(),q=l({onSuccess:()=>{w.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),J={isPending:q.isPending,mutate:e=>{q.mutate({deviceId:n,changes:[...e]})}},Y=y({schema:V,serverValues:H,onImmediateSave:e(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:e(async 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&&(await q.mutateAsync({deviceId:n,changes:t}),await w.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}))},[V,q,n,w])}),{values:X,pendingKeys:Z,handleChange:Q,handleSave:$,handleDiscard:ee}=Y;if(D.current=Y.editingPaused,j)return r(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[s(h,{className:`h-4 w-4 animate-spin mr-2`}),s(`span`,{className:`text-xs`,children:`Loading device aggregate…`})]});if(!V||V.sections.length===0)return s(`div`,{className:`text-xs text-foreground-subtle italic py-4 text-center`,children:`No aggregate contributions for this device.`});async function te(e,t,r){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 r=t.slice(e.length);if(!r)throw Error(`regenerate-rtsp-token: key "${t}" has no streamId after prefix`);let i=g(n,r);await U.mutateAsync({brokerId:i}),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:r})}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 r=g(n,e),i=await W.mutateAsync({brokerId:r});return w.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),i}if(e===`device-custom-action`){let e=await K.mutateAsync({deviceId:n,action:t,input:r});return w.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),e}throw Error(`[device-aggregate] unknown action "${e}"`)}return s(C,{schema:V,values:X,pendingKeys:Z,onChange:Q,onAction:te,onSave:$,onDiscard:ee,disabled:J.isPending,activeSubTab:v,onSubTabChange:b,flattenTabs:x})}export{O as i,T as n,E as r,V as t};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,a,b as o,o as s,q as c,t 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-DhP-Lgiq.js";import{G as f,U as p,W as m,X as h,_ as g,at as _,ht as v,lt as y,mt as b,q as x,r as S,st as C,t as w,ut as T,vt as E,yt as D}from"./player-overlays-Dpyv2MuF.js";import{$ as O,$r as k,A,Ai as j,Al as M,B as N,Bl as P,Cl as F,Co as I,Ct as L,Da as R,Di as z,Dl as B,Dt as V,Ei as ee,Fc as H,Fl as U,Fo as W,Fr as G,G as K,Gr as te,Gu as ne,H as q,Ht as re,I as ie,Io as ae,Jl as oe,Jr as se,K as ce,L as J,Lo as le,M as ue,Mc as de,Mu as fe,N as pe,Na as me,Nl as he,Nu as ge,O as _e,Oc as ve,Oi as ye,P as be,Pa as Y,Pr as xe,Q as Se,Qt as Ce,Si as we,St as Te,Tt as Ee,U as De,Uo as Oe,Ut as ke,Vt as Ae,W as je,Wt as Me,X as Ne,Y as Pe,Z as Fe,Zi as Ie,Zt as Le,_n as Re,_t as ze,a as Be,ai as Ve,b as He,bl as Ue,bt as We,c as Ge,cu as Ke,d as qe,dl as Je,ei as Ye,et as Xe,f as Ze,fi as Qe,fn as $e,go as et,gt as tt,gu as nt,hi as rt,ho as it,ht as at,i as ot,ii as st,is as ct,j as lt,jc as ut,jl as dt,ju as ft,kl as pt,l as mt,lr as ht,lu as gt,mn as _t,na as vt,nl as yt,nn as bt,o as xt,oi as St,pl as Ct,pn as wt,po as Tt,q as Et,qn as Dt,r as Ot,ra as kt,ri as At,s as jt,si as Mt,st as Nt,ta as Pt,tn as Ft,tt as It,u as Lt,ui as Rt,ut as zt,v as Bt,vl as Vt,w as Ht,wt as Ut,wu as Wt,x as Gt,xc as Kt,xi as qt,xt as Jt,y as Yt,yl as Xt,yo as Zt,yt as Qt,yu as $t,zl as en}from"./src-DeANpHOz.js";import{t as tn}from"./archive-BmbkFLtr.js";import{t as nn}from"./boxes-BDauq_GC.js";import{t as rn}from"./ProviderIcon-DtoRs3L2.js";import{t as an}from"./circle-slash-OkyAP_uM.js";import{n as on}from"./NodeInferenceDevices-BZONzZ2s.js";import{t as sn}from"./layers-DRiv_qOz.js";import{t as cn}from"./CapabilityBadges-C25C3fOL.js";import{Nn as ln,Pn as un,a as dn,an as X,i as fn,rn as pn}from"./src-BjMTOeHt.js";import{a as mn,c as hn,n as gn,o as _n,s as vn,u as yn}from"./index-SOjqIyqv.js";import{n as bn,t as xn}from"./useDevice-CEHL86RO.js";import{t as Sn}from"./authed-media-Bhswngiz.js";import"./useEventInvalidation-Bp3xnYIe.js";import{t as Cn}from"./StatusBadge-CeptlsPG.js";import{t as wn}from"./use-stationary-objects-3iUSTAxf.js";import{i as Tn,n as En,r as Dn,t as On}from"./DeviceAggregateSection-DdAM0MHQ.js";var kn=D(`arrow-left-right`,[[`path`,{d:`M8 3 4 7l4 4`,key:`9rb6wj`}],[`path`,{d:`M4 7h16`,key:`6tx8e3`}],[`path`,{d:`m16 21 4-4-4-4`,key:`siv7j2`}],[`path`,{d:`M20 17H4`,key:`h6l3hr`}]]),An=D(`disc`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]),jn=D(`ear`,[[`path`,{d:`M6 8.5a6.5 6.5 0 1 1 13 0c0 6-6 6-6 10a3.5 3.5 0 1 1-7 0`,key:`1dfaln`}],[`path`,{d:`M15 8.5a2.5 2.5 0 0 0-5 0v1a2 2 0 1 1 0 4`,key:`1qnva7`}]]);n();function Mn(e){if(typeof e!=`object`||!e)return null;let t=e,n=t.id,r=t.label;if(typeof n!=`string`||typeof r!=`string`)return null;let i=t.available===!0,a=t.enabled,o=t.unavailableReason;return{id:n,label:r,costWhenOff:typeof t.costWhenOff==`string`?t.costWhenOff:``,on:i&&typeof a==`boolean`?a:null,available:i,unavailableReason:typeof o==`string`?o:null}}function Nn(e){if(typeof e!=`object`||!e)return null;let t=e.switches;if(!Array.isArray(t))return null;let n=t.map(Mn).filter(e=>e!==null);return n.length===0?null:n}var Pn=[[/privacy|mask/i,`privacy`],[/microphone|mic\b/i,`microphone`],[/speaker|broker audio|stream audio/i,`speaker`],[/audio/i,`listening`],[/object|detect/i,`detection`],[/event/i,`archive`],[/record/i,`recording`],[/notif/i,`notifications`],[/stream|broker/i,`stream`]];function Fn(e){for(let[t,n]of Pn)if(t.test(e))return n;return`generic`}function In(e){let t=e.filter(e=>e.on===!1).map(e=>e.id),n=e.filter(e=>e.on===null).map(e=>e.id),r=t=>t.map(t=>e.find(e=>e.id===t)?.label??t).join(`, `),i=[];return t.length>0&&i.push(`Off: ${r(t)}`),n.length>0&&i.push(`Unknown: ${r(n)}`),{offIds:t,unknownIds:n,summary:i.length===0?`All camera functions on`:i.join(` · `)}}var Ln={stream:Ue,detection:yn,privacy:b,microphone:T,speaker:H,listening:jn,archive:tn,recording:An,notifications:ft,generic:yt};function Rn({deviceId:t}){let n=s(),i=Number.isFinite(t),[a,o]=c(null),[l,d]=c(!1),f=et({deviceId:t},{enabled:i});Ot([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let p=Nn(f.data),m=le({onError:(e,r)=>{console.error(`[CameraFunctionSwitches] switch write failed — reverting`,{tags:{deviceId:t},meta:{switchId:r.switchId,error:e instanceof Error?e.message:String(e)}}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSwitches`]]}),o({id:r.switchId,message:e instanceof Error?e.message:String(e)})},onSuccess:()=>{o(null),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),n.invalidateQueries({queryKey:[[`deviceManager`]]}),n.invalidateQueries({queryKey:[[`recording`]]})}}),h=e(e=>{!e.available||e.on===null||m.mutate({deviceId:t,switchId:e.id,enabled:!e.on})},[t,m]);if(p===null)return null;let g=In(p),_=e=>a?.id===e.id?a.message:null;return r(L,{open:l,onOpenChange:d,children:[r(Ee,{"aria-label":`Camera functions`,title:g.summary,className:`inline-flex items-center gap-1 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors ${a===null?g.offIds.length>0?`border-warning/40 text-warning hover:bg-warning/10`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`:`border-danger/50 text-danger bg-danger/5`}`,children:[u(yt,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden lg:inline`,children:`Functions`}),g.offIds.length>0&&r(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:[g.offIds.length,` off`]})]}),r(Ut,{className:`left-auto right-0 mt-1 min-w-[240px] max-h-[60vh] overflow-y-auto p-1`,children:[u(`div`,{className:`px-2 py-1 text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Camera functions`}),u(`ul`,{className:`space-y-0.5`,children:p.map(e=>u(`li`,{children:u(zn,{row:e,failure:_(e),onToggle:()=>h(e)})},e.id))})]})]})}function zn({row:e,failure:t,onToggle:n}){let i=Ln[Fn(e.label)],a=e.on===null,o=e.on===!1,s=t===null?a?e.unavailableReason??`The source that owns this did not answer.`:e.costWhenOff:`Write failed: ${t}`,c=t===null?a?e.unavailableReason??`unknown`:null:`write failed`;return r(`button`,{type:`button`,role:`switch`,"aria-label":e.label,"aria-checked":e.on===!0,disabled:!e.available,onClick:n,title:s,className:`flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-[12px] text-foreground transition-colors hover:bg-surface-hover disabled:opacity-40 disabled:cursor-not-allowed`,children:[u(i,{className:`h-3.5 w-3.5 shrink-0 ${t===null?a?`text-foreground-subtle/50`:o?`text-warning`:`text-success`:`text-danger`}`}),r(`span`,{className:`flex-1 min-w-0 truncate`,children:[e.label,c!==null&&r(`span`,{className:`ml-1 text-[10px] text-foreground-subtle`,children:[`· `,c]})]}),u(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[9px] font-semibold uppercase tracking-wide ${a?`bg-surface-hover text-foreground-subtle/60`:o?`bg-warning/20 text-warning`:`bg-success/20 text-success`}`,children:a?`—`:o?`off`:`on`})]})}function Bn({deviceId:e}){let t=ie(_().trpcClient,e);return t===null?null:r(`a`,{href:t.url,target:`_blank`,rel:`noopener noreferrer`,title:`${t.label} — ${t.host}`,className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[u(v,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:t.label})]})}function Vn({parentDeviceId:e}){let{t}=gn(),n=mn(),i=_(),{data:a,isLoading:o,isError:s}=bn(e),{data:c}=At({deviceId:e},{enabled:Number.isFinite(e)});if(o)return u(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(s)return u(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let l=(a??[]).filter(e=>e.display?.hidden!==!0);if(l.length===0)return null;let d=ue(c?.stableId??``,l,c?.childLayout),f=d.ungrouped,p=e=>n(`/devices/${String(e)}`),m=c?.name??``,h=(e,t)=>u(A,{trpc:i.trpcClient,device:{...t,name:J(t,m)},variant:`minimal`,onNavigate:p},e),g=f.some(e=>!!e.role),v=f.some(e=>!e.role),y=g&&!v?t(`device.accessories`,{defaultValue:`Accessories`}):!g&&v?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),b=f.length>0?r(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[u(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:y}),u(`div`,{className:`space-y-1`,children:f.map(e=>h(e.id,e))})]}):null,x=d.disabledSection===void 0?null:u(lt,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:d.disabledSection.children.length,defaultOpen:!1,children:u(`div`,{className:`opacity-60 space-y-1`,children:d.disabledSection.children.map(e=>h(e.id,e))})},d.disabledSection.title);if(d.sections.length===0)return x===null?b:r(`div`,{className:`space-y-2`,children:[b,x]});let S=v&&!g;return r(`div`,{className:`space-y-2`,children:[S?b:null,d.sections.map(e=>u(lt,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>h(e.id,e))},e.title)),S?null:b,x]})}function Hn({deviceId:e}){let t=_(),{data:n,isLoading:r}=xn(e),{data:i,isLoading:a}=bn(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?u(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):u(`div`,{className:`flex h-full w-full flex-col`,children:u(K,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}n();function Un({dev:e,busy:t,setBusy:n}){let i=e?.motionTrigger,a=x(e?.state.motionTrigger),[o,s]=c(!1);if(!i)return null;let l=a?.enabled===!0,d=a!==void 0,f=async()=>{if(t||!d)return;let e=!l;n(!0),s(!0);try{await i.setMotionTrigger({enabled:e})}finally{n(!1),s(!1)}};return r(`button`,{type:`button`,onClick:()=>{f()},disabled:t||!d,title:d?l?`Disable trigger on motion`:`Enable trigger on motion`:`Awaiting state…`,"aria-pressed":l,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 ${l?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[u(ne,{className:`h-3 w-3`}),u(`span`,{children:o?l?`Disabling…`:`Enabling…`:d?l?`On motion: on`:`On motion: off`:`On motion: …`})]})}n();function Z({deviceId:e,deviceType:t,features:n}){let i=_(),a=Pe(t)?.HeroCard??Ne,o=f(i.trpcClient,e),s=x(o?.state.deviceStatus),[l,d]=c(!1),p=s!==void 0&&s.online===!1,m=p?s.lastChangedAt:null;return r(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[p?u(`div`,{className:`flex justify-center`,children:u(Et,{lastChangedAt:m})}):null,u(a,{trpc:i.trpcClient,deviceId:e,features:n}),u(`div`,{className:`flex justify-center`,children:u(Un,{dev:o,busy:l,setBusy:d})})]})}function Wn({deviceId:e,features:t}){return u(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:u(Fe,{trpc:_().trpcClient,deviceId:e,features:t})})}function Gn({deviceId:e,features:t}){return u(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:u(Ne,{trpc:_().trpcClient,deviceId:e,features:t})})}function Kn(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function qn(e){if(!e)return null;let t=Kn(e.data);return t===null?e.eventType:`Button ${String(t)} · ${e.eventType}`}var Jn=1e3,Yn=60*Jn,Xn=60*Yn,Zn=24*Xn;function Qn(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<Jn?`just now`:n<Yn?`${String(Math.floor(n/Jn))}s ago`:n<Xn?`${String(Math.floor(n/Yn))}m ago`:n<Zn?`${String(Math.floor(n/Xn))}h ago`:`${String(Math.floor(n/Zn))}d ago`}n();var $n=1500,er=15e3,tr=1e3;function nr({deviceId:e}){let n=f(_().trpcClient,e)?.state.eventEmitter,i=x(n);d(()=>{if(!n)return;n.refresh();let e=setInterval(()=>{n.refresh()},er);return()=>{clearInterval(e)}},[n]);let a=i?.lastEvent??null,o=a?.seq??null,s=t(null),[l,p]=c(!1);d(()=>{if(o===null)return;let e=s.current;if(s.current=o,e===null||e===o)return;p(!0);let t=setTimeout(()=>{p(!1)},$n);return()=>{clearTimeout(t)}},[o]);let[m,h]=c(()=>Date.now());d(()=>{let e=setInterval(()=>{h(Date.now())},tr);return()=>{clearInterval(e)}},[]);let g=qn(a),v=i?.eventTypes??[],y=i?.eventCountSinceStart??0,b=i!==void 0,S=Kn(a?.data);return r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[u(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(l),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${l?`border-primary bg-primary/20 text-primary shadow-lg shadow-primary/30 scale-105`:`border-border bg-surface text-foreground-subtle`}`,"aria-live":`polite`,title:g??`No press recorded`,children:u(l?M:oe,{className:`h-10 w-10`})}),r(`div`,{className:`text-center`,children:[S!==null&&u(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:`Button ${String(S)}`}),u(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${g?`text-foreground`:`text-foreground-subtle`}`,children:g??(b?`No press recorded`:`Awaiting state…`)}),u(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:a?Qn(a.timestamp,m):`Waiting for the first event`})]}),v.length>0&&u(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:v.map(e=>u(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===a?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),u(`div`,{className:`text-[10px] text-foreground-subtle`,children:`${String(y)} ${y===1?`event`:`events`} since start`})]})}function rr({deviceName:e,deviceType:t,provider:n,isOnline:i,features:a}){return r(`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:[u(rn,{type:n,size:`lg`}),r(`div`,{children:[u(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),u(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),r(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[u(Cn,{status:i?`online`:`offline`}),a.length>0&&u(cn,{capabilities:a})]}),u(`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.`})]})}n();function ir({deviceId:e}){let t=s(),n=xe({deviceId:e},{refetchInterval:1e4,retry:!1}),a=G({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),o=i(()=>ar(n.data??[]),[n.data]);return r(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[r(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[u(or,{label:`Discovered`,value:o.total,icon:u(pt,{className:`h-3.5 w-3.5`})}),u(or,{label:`Adopted`,value:o.adopted,accent:`success`}),u(or,{label:`Available`,value:o.available,accent:o.available>0?`primary`:void 0}),r(`button`,{type:`button`,onClick:()=>{a.mutateAsync({deviceId:e}).catch(()=>{})},disabled:a.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:[a.isPending?u(en,{className:`h-3.5 w-3.5 animate-spin`}):u(Xt,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),r(`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:[u(sr,{icon:u(ut,{className:`h-3 w-3 text-emerald-500`}),label:`${o.online} online`}),u(sr,{icon:u(dt,{className:`h-3 w-3 text-amber-500`}),label:`${o.sleeping} sleeping`}),u(sr,{icon:u(de,{className:`h-3 w-3 text-destructive`}),label:`${o.offline} offline`}),o.unknown>0?u(sr,{icon:u(nt,{className:`h-3 w-3 text-foreground-subtle`}),label:`${o.unknown} unknown`}):null]})]})}function ar(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 or({label:e,value:t,icon:n,accent:i}){return r(`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 ${i===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:i===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[r(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,u(`span`,{className:`truncate`,children:e})]}),u(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function sr({icon:e,label:t}){return r(`span`,{className:`inline-flex items-center gap-1`,children:[e,u(`span`,{children:t})]})}var cr={[X.Switch]:Z,[X.Siren]:Z,[X.Light]:Z,[X.Sensor]:Z,[X.Button]:Z,[X.Hub]:ir,[X.Cover]:Wn,[X.Valve]:Z,[X.Humidifier]:Z,[X.WaterHeater]:Z,[X.Container]:Hn,[X.Lock]:Z,[X.Fan]:Z,[X.Thermostat]:Z,[X.Climate]:Z,[X.MediaPlayer]:Z,[X.Control]:Z,[X.AlarmPanel]:Z,[X.EventEmitter]:nr,[X.Notifier]:Gn,[X.Script]:Z,[X.Automation]:Z,[X.Presence]:Z,[X.Update]:Z,[X.Vacuum]:Z,[X.LawnMower]:Z,[X.Weather]:Z,[X.Image]:Z,[X.PetFeeder]:Z};function lr(e){return cr[e]??rr}function ur(e){return u(lr(e.deviceType),{...e})}function dr(e){return jt(_().trpcClient,e)}n();function fr(n){let[r,i]=c(`idle`),[a,o]=c(null),s=t(null),l=t(null),u=t(null),f=t(!0),p=vt(),m=Pt(),h=kt(),g=e(()=>{if(s.current){try{s.current.close()}catch{}s.current=null}if(l.current){for(let e of l.current.getTracks())try{e.stop()}catch{}l.current=null}u.current=null},[]),_=e(async()=>{if(r===`idle`)return;i(`stopping`);let e=u.current;if(e&&n!==null)try{await Promise.race([h.mutateAsync({deviceId:n,sessionId:e}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}g(),f.current&&(i(`idle`),o(null))},[r,n,h,g]),v=e(async()=>{if(n===null||r!==`idle`&&r!==`error`)return;o(null);let e=null,t=null,a=null;try{i(`requesting-mic`),e=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),l.current=e,i(`starting`);let r=await p.mutateAsync({deviceId:n});a=r.sessionId,u.current=a,i(`connecting`),t=new RTCPeerConnection,s.current=t,t.oniceconnectionstatechange=()=>{if(!f.current)return;let e=t.iceConnectionState;e===`connected`||e===`completed`?i(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&f.current&&(o(e===`failed`?`WebRTC connection failed`:null),_())};for(let n of e.getAudioTracks())t.addTrack(n,e);await t.setRemoteDescription({type:`offer`,sdp:r.sdpOffer});let c=await t.createAnswer();await t.setLocalDescription(c);let d=t.localDescription?.sdp??c.sdp??``;await m.mutateAsync({deviceId:n,sessionId:a,sdpAnswer:d})}catch(r){let c=r instanceof Error?r.message:String(r);if(console.warn(`[intercom] start failed`,r),t)try{t.close()}catch{}if(e)for(let t of e.getTracks())try{t.stop()}catch{}if(s.current=null,l.current=null,a!==null)try{await h.mutateAsync({deviceId:n,sessionId:a})}catch{}u.current=null,f.current&&(o(c),i(`error`))}},[n,r,p,m,h,_]);return d(()=>(f.current=!0,()=>{f.current=!1;let e=u.current;if(e!==null&&n!==null&&h.mutate({deviceId:n,sessionId:e}),s.current){try{s.current.close()}catch{}s.current=null}if(l.current){for(let e of l.current.getTracks())try{e.stop()}catch{}l.current=null}u.current=null}),[n]),{state:r,error:a,start:v,stop:_,isTalking:r===`talking`}}n();var pr=0;function Q(){return++pr}function mr(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function hr(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 gr(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 _r(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 vr({scope:n,greeting:i,className:a}){let o=_(),[s,f]=c(()=>{let e=[];return i&&e.push({id:Q(),kind:`info`,text:i}),e.push({id:Q(),kind:`info`,text:`scope: ${mr(n)} — type help or context for available commands`}),e}),[p,m]=c(``),[h,g]=c([]),[v,y]=c(-1),b=t(null),x=t(null);d(()=>{let e=x.current;e&&(e.scrollTop=e.scrollHeight)},[s]);let S=e(()=>{b.current?.focus()},[]),C=l({mutationFn:e=>o.trpcClient.repl.execute.mutate({code:e,scope:n}),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`;f(e=>[...e,{id:Q(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);f(e=>[...e,{id:Q(),kind:`error`,text:t}])}});function w(e){let t=e.trim();if(t){if(t===`clear`){f([{id:Q(),kind:`info`,text:`scope: ${mr(n)}`}]),m(``);return}if(t===`help`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...hr(n).map(e=>({id:Q(),kind:`info`,text:e}))]),m(``);return}if(t===`context`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},..._r(n).map(e=>({id:Q(),kind:`info`,text:e}))]),m(``);return}if(t===`examples`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...gr(n).map(e=>({id:Q(),kind:`info`,text:e}))]),m(``);return}g(e=>[...e,t]),y(-1),f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`}]),m(``),C.mutate(t)}}function T(e){if(e.key===`Enter`){e.preventDefault(),w(p);return}if(e.key===`ArrowUp`){if(e.preventDefault(),h.length===0)return;let t=v===-1?h.length-1:Math.max(0,v-1);y(t),m(h[t]??``);return}if(e.key===`ArrowDown`){if(e.preventDefault(),v===-1)return;let t=v+1;t>=h.length?(y(-1),m(``)):(y(t),m(h[t]??``));return}e.ctrlKey&&e.key===`l`&&(e.preventDefault(),f([{id:Q(),kind:`info`,text:`scope: ${mr(n)}`}]))}let E={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return r(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${a??``}`,onClick:S,children:[r(`div`,{ref:x,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[s.map(e=>u(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${E[e.kind]}`,children:e.text},e.id)),C.isPending&&u(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),r(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[u(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),u(`input`,{ref:b,value:p,onChange:e=>m(e.target.value),onKeyDown:T,disabled:C.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 yr(e,t){return e===null?null:{playbackUrl:e.url,...e.format===void 0?{}:{playbackFormat:e.format},playbackAuthToken:t,...e.label===void 0?{}:{playbackLabel:e.label}}}n();function br({deviceId:e,intercomAvailable:t=!1}){let n=_(),r=typeof window<`u`?h():``,a=Number.isFinite(e),s=dr(a?e:null),c=wn(a?[e]:[]),l=i(()=>{if(!a)return;let e=[];for(let t of c.rows){let n=xt(t);n!==null&&e.push(n)}return e},[a,c.rows]),{streams:d,pipelineMetrics:f,createSession:p,sendAnswer:g,handleOffer:v,getIceServers:y,addIceCandidate:b,getIceCandidates:x,closeSession:C,getSessionState:w}=Be(n.trpcClient,a?e:null),T=m(a?e:null,{width:Tr}),E=fr(a&&t?e:null),D=E.state===`requesting-mic`||E.state===`starting`||E.state===`connecting`||E.state===`stopping`,O=E.isTalking||D,k=()=>{E.state===`idle`||E.state===`error`?E.start():E.state!==`stopping`&&E.stop()},A=S(),j=bt(),M=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,N=yr(j.request,M),P=A.length>0?u(o,{children:A.map(e=>u(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return u(Lt,{serverUrl:r,createSession:p,sendAnswer:g,handleOffer:v,getIceServers:y,addIceCandidate:b,getIceCandidates:x,closeSession:C,getSessionState:w,...N===null?{}:{...N,onExitPlayback:()=>j.clear()},streams:d,pipelineMetrics:f,phase:s.phase,detections:s,...l===void 0?{}:{stationaryObjects:l},defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:T.src,...T.src?{posterUrl:T.src}:{},snapshotLoading:T.loading,onRefreshSnapshot:T.refresh,intercomAvailable:t,intercomShown:O,onIntercomToggle:k,extraOverlay:P,chromeless:!0,className:`h-full`})}function xr({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full`,children:u(It,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Sr({deviceId:e}){if(!Number.isFinite(e))return r(`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 u(vr,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function Cr({deviceId:e}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:u(Xe,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function wr({deviceId:e}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:u(O,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}var Tr=960,Er=`overview`;function Dr(e,t){return e.some(e=>e.id===t)?t:Er}function Or({deviceId:e}){let t=s(),n=Number.isFinite(e),{data:i}=At({deviceId:e},{enabled:n}),a=typeof i?.type==`string`?i.type:`camera`;Ot([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:o,isLoading:c,isError:l,error:d}=Ye({deviceId:e},{enabled:n}),{data:f}=Mt({deviceType:a},{enabled:!!a}),p=j({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(c)return u(`div`,{className:`p-4`,children:u(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(l)return r(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,d instanceof Error?d.message:String(d)]});let m=new Map,h={};for(let e of f??[])h[e.capName]=e.wrappers;for(let e of o?.entries??[])m.set(e.capName,{...e,wrappers:h[e.capName]??[]});for(let e of f??[])m.has(e.capName)||m.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let g=[...m.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(g.length===0)return r(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[u(nn,{className:`h-8 w-8 opacity-40`}),u(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),u(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let _=g.filter(e=>e.kind!==`unbound`).length;return r(`div`,{className:`flex flex-col gap-3 p-1`,children:[r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-foreground`,children:_}),` of `,g.length,` capabilit`,g.length===1?`y`:`ies`,` bound — rows marked `,u(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),u(zt,{columns:[{key:`capability`,header:`Capability`,render:e=>u(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>u(kr,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>u(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||u(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?u(Ar,{nodeId:e.providerNodeId}):u(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>u(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||u(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return u(jr,{wrappers:t.wrappers,activeWrapperId:n,disabled:p.isPending,onPick:r=>{let i=n===r;p.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:g,rowKey:e=>e.capName,minWidthPx:720})]})}function kr({kind:e}){return e===`native`?r(`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:[u(Je,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?r(`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:[u(sn,{className:`h-3 w-3`}),`wrapped`]}):e===`linked`?r(`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:[u(P,{className:`h-3 w-3`}),`linked`]}):r(`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:[u(he,{className:`h-3 w-3`}),`unbound`]})}function Ar({nodeId:e}){return u(`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 jr({wrappers:e,activeWrapperId:t,disabled:n,onPick:i}){return e.length===0?u(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):u(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let a=e===t;return r(`button`,{disabled:n,onClick:()=>i(e),title:a?`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 ${a?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[u(a?Wt:y,{className:`h-3 w-3`}),e]},e)})})}function Mr({deviceId:e,activeSubTab:t,onSubTabChange:n}){return u(`div`,{className:`flex flex-col gap-3`,children:u(On,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}n();var Nr=new Set([`package-detection`]);function Pr(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 Fr(e){return e?e.modelId!==void 0||e.settings!==void 0:!1}function Ir({deviceId:e,refreshToken:t}){let n=s(),l=_().trpcClient,[d,f]=c(null),[p,m]=c(null),[h,g]=c(null),v=Tt({deviceId:e},{refetchOnMount:`always`}),y=it({deviceId:e},{refetchOnMount:`always`}),b=I(void 0,{refetchOnMount:`always`});Ot([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let{nodes:x}=Kt(),S=i(()=>{let e=new Set;for(let t of x)t.isOnline&&e.add(t.id);return e},[x]),C=i(()=>(b.data??[]).filter(e=>S.has(e.nodeId)).map(e=>e.nodeId),[b.data,S]),w=a({enabled:C.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`device-step-schemas`,C.join(`,`),t],queryFn:async()=>{let e={};for(let t of C)try{e[t]=await l.pipelineExecutor.getSchema.query({nodeId:t})}catch{}return e}}),T=e=>w.data?.[e]??null,E=i(()=>{let e=C[0];if(e!==void 0){let t=w.data?.[e];if(t)return t}return Object.values(w.data??{})[0]??null},[C,w.data]),D=a({enabled:C.length>0,queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`],`device-step`,C.join(`,`),t],queryFn:async()=>{let e={};for(let t of C)try{e[t]=(await l.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:t})).devices}catch{e[t]=[]}return e}}),O=()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]})},k=W({onSuccess:O}),A=ae({onSuccess:O}),j=i(()=>E?qe(E):[],[E]),M=i(()=>{let e=b.data??[],t=S.size===0?[]:e.filter(e=>S.has(e.nodeId)),n=[];for(let e of t){let t=(D.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:on(r).label});else n.push({agentNodeId:e.nodeId,engineLabel:t[0]?.format??`(engine unknown)`})}return n},[b.data,D.data,S]),N=(e,t)=>D.data?.[e]?.find(e=>e.key===t)??null,P=e=>{if(e.deviceKey!==void 0)return e.deviceKey;let t=D.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},F=(e,t,n)=>y.data?.[e]?.[t]?.[n]??null,L=e=>{if(Nr.has(e))return{kind:`zone-driven`};let t=Pr(E,e)?.enabledByDefault??!0,n=v.data?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},R=(e,t,n)=>{let r=Pr(T(n),e);if(r)return re(r,t)},z=(e,t)=>{let n=L(e),r=n.kind===`gate`?n.effectiveOn:!1,i=Pr(T(t.agentNodeId),e),a=P(t),o=a===null?null:N(t.agentNodeId,a);if(!Me(i?.models??[],o?.format))return r?{kind:`skip`}:{kind:`na`};let s=a===null?null:F(t.agentNodeId,a,e),c=o?.steps?.[e];return{kind:`enabled`,modelId:(i?ke({catalog:i,device:o,override:s?.modelId,base:c?.modelId}):void 0)??`Auto`,overridden:Fr(s)}},B=d===null?null:Pr(T(d.agentNodeId),d.addonId),V=d?N(d.agentNodeId,d.deviceKey):null,ee=V?.format??`coreml`,H=d?Fr(F(d.agentNodeId,d.deviceKey,d.addonId)):!1,U=d?R(d.addonId,V,d.agentNodeId):void 0,G=i(()=>{if(!d||!V)return null;let e=V.steps?.[d.addonId];return{enabled:!0,...e?.modelId===void 0?{}:{modelId:e.modelId},settings:e?.settings??{}}},[d,V]),K=()=>{f(null),m(null)},te=(e,t)=>{let n=P(t);n!==null&&(f({addonId:e,agentNodeId:t.agentNodeId,deviceKey:n}),m(F(t.agentNodeId,n,e)))},ne=(t,n)=>{A.mutate({deviceId:e,addonId:t,enabled:n})},q=()=>{d&&k.mutate({deviceId:e,agentNodeId:d.agentNodeId,deviceKey:d.deviceKey,addonId:d.addonId,patch:p},{onSuccess:K})},ie=()=>{d&&k.mutate({deviceId:e,agentNodeId:d.agentNodeId,deviceKey:d.deviceKey,addonId:d.addonId,patch:null},{onSuccess:K})};if(b.isLoading||C.length>0&&w.isLoading)return u(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(M.length===0)return u(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`No online agents.`});if(!E)return u(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let oe=d!==null&&B!==null&&V!==null;return r(`div`,{className:`relative h-full w-full space-y-3`,children:[r(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-foreground`,children:`Gate`}),` (col 1) decides whether this camera runs a step — independent of nodes. Each`,` `,u(`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 `,u(`span`,{className:`text-amber-500`,children:`⚠ skip`}),` `,`and won't run there.`]}),r(`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:[u(`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.`]}),u(`div`,{className:oe?`md:pr-[360px]`:``,children:j.length>0?u(Gt,{tree:j,agents:M,gateFor:L,getCellState:z,onCellClick:te,selectedCell:d,onSetGate:ne,gateBusy:A.isPending,fallbackNodeId:h,onFallbackNodeChange:g}):u(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),u(Ze,{open:oe,onClose:K,title:B?.name??``,subtitle:d&&V?`${d.agentNodeId} · ${on(V).label} · ${V.format}`:``,footer:r(o,{children:[u(`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:!H||k.isPending,onClick:ie,children:`Clear override`}),u(`div`,{className:`flex-1`}),u(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:K,children:`Cancel`}),u(`button`,{type:`button`,disabled:!d||!G||k.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:q,children:k.isPending?`Saving…`:`Save`})]}),children:B&&d&&G?u(Ae,{mode:`device`,addon:B,agentDefault:G,agentNodeId:d.agentNodeId,currentPatch:p,engineFormat:ee,effectiveModelId:U,onChangePatch:m}):u(`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 Lr=[{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`}],Rr={"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 zr(e){return Rr[e]??`object-detection`}n();var Br=`steps`,Vr=`settings`,Hr=new Set([Br,Vr]);function Ur(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function Wr({deviceId:t,activeSubTab:n,onSubTabChange:i}){return r(Qt,{value:n&&Hr.has(n)?n:Br,onValueChange:e(e=>{i?.(e)},[i]),className:`flex flex-col`,children:[r(Jt,{className:`flex-shrink-0`,children:[u(Te,{value:Br,children:`Steps`}),u(Te,{value:Vr,children:`Settings`})]}),u(We,{value:Br,children:u(Ir,{deviceId:t,refreshToken:0})}),u(We,{value:Vr,children:u(On,{deviceId:t,sectionFilter:Ur,subTabGrouping:{groupOf:e=>zr(e.id),tabs:Lr}})})]})}function $({label:e,value:t}){return r(`div`,{className:`${g} flex items-start gap-2 sm:gap-3`,children:[u(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),u(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}n();function Gr({deviceId:e,initialName:n}){let i=s(),[a,o]=c(!1),[l,f]=c(n),[p,m]=c(!1),h=t(null);d(()=>{a||f(n)},[n,a]),d(()=>{a&&h.current?.focus()},[a]);let g=ee({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),i.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),_=async()=>{let t=l.trim();if(t.length===0||t===n){o(!1),f(n);return}m(!0);try{await g.mutateAsync({deviceId:e,name:t}),o(!1)}catch{}finally{m(!1)}},v=()=>{f(n),o(!1)};return a?u($,{label:`Name`,value:r(`div`,{className:`flex items-center gap-1`,children:[u(`input`,{ref:h,type:`text`,value:l,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`?_():e.key===`Escape`&&v()},disabled:p,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`}),u(`button`,{type:`button`,onClick:()=>void _(),disabled:p,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:u(Wt,{className:`h-3 w-3`})}),u(`button`,{type:`button`,onClick:v,disabled:p,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:u(ve,{className:`h-3 w-3`})})]})}):u($,{label:`Name`,value:r(`div`,{className:`flex items-center gap-2 group`,children:[u(`span`,{className:`truncate`,children:n}),u(`button`,{type:`button`,onClick:()=>o(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit name`,children:u(B,{className:`h-3.5 w-3.5`})})]})})}n();function Kr({deviceId:e,initialLocation:n}){let a=s(),[o,l]=c(!1),[f,p]=c(n??``),[m,h]=c(!1),g=t(null),{data:_}=Rt(void 0,{enabled:o}),v=_??[];d(()=>{o||p(n??``)},[n,o]),d(()=>{o&&g.current?.focus()},[o]);let y=we({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),b=i(()=>{let e=f.trim().toLowerCase();return e.length===0?v:v.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[v,f]),x=f.trim().length>0&&!v.some(e=>e.toLowerCase()===f.trim().toLowerCase()),S=async t=>{let r=(t??f).trim(),i=r.length===0?null:r;if(i===(n??null)){l(!1);return}h(!0);try{await y.mutateAsync({deviceId:e,location:i}),l(!1)}catch{}finally{h(!1)}},C=()=>{p(n??``),l(!1)};return o?u($,{label:`Location`,value:r(`div`,{className:`relative`,children:[r(`div`,{className:`flex items-center gap-1`,children:[u(`input`,{ref:g,type:`text`,value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`?S():e.key===`Escape`&&C()},disabled:m,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`}),u(`button`,{type:`button`,onClick:()=>void S(),disabled:m,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:u(Wt,{className:`h-3 w-3`})}),u(`button`,{type:`button`,onClick:C,disabled:m,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:u(ve,{className:`h-3 w-3`})})]}),(b.length>0||x)&&r(`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:[b.map(e=>r(`button`,{type:`button`,onClick:()=>{p(e),S(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[u(U,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),u(`span`,{className:`truncate`,children:e})]},e)),x&&r(`button`,{type:`button`,onClick:()=>void S(),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:[u(`span`,{className:`text-foreground-subtle`,children:`Create`}),r(`span`,{className:`font-medium truncate`,children:[`"`,f.trim(),`"`]})]})]})]})}):u($,{label:`Location`,value:r(`div`,{className:`flex items-center gap-2 group`,children:[n?u(`span`,{className:`truncate`,children:n}):u(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),u(`button`,{type:`button`,onClick:()=>l(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit location`,children:u(B,{className:`h-3.5 w-3.5`})})]})})}n();function qr({deviceId:e}){let t=s(),{data:n}=xn(e),{data:i}=bn(e),[a,l]=c(null),d=z({onSuccess:()=>{l(null),t.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{l(`Could not change primary child: ${e.message}`)}});if(n==null||String(n.type??``)!==X.Container)return null;let f=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}}));if(f.length<=1)return null;let p=ce(f,typeof n.linkDeviceId==`number`?n.linkDeviceId:null,typeof n.primaryChildEntityId==`string`?n.primaryChildEntityId:null);return r(o,{children:[u($,{label:`Primary child`,value:u(je,{childrenList:f,selectedId:p===null?f[0].id:p.id,onSetPrimary:t=>d.mutate({deviceId:e,primaryChildEntityId:t}),disabled:d.isPending})}),a!==null&&u(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:a})]})}n();var Jr=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function Yr(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function Xr(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function Zr(){let e=wt(),t=_t(),{data:n}=At({deviceId:e??0},{enabled:e!==null}),{data:i}=Ye({deviceId:e??0},{enabled:e!==null}),a=n??t??null,[o,s]=c(`identity`);if(e===null||!a)return null;let l=String(a.stableId??``),d=String(a.name??``),f=String(a.type??``),p=String(a.addonId??``),m=a.features??[],h=new Set([`device-status`,`feature-probe`,`device-ops`]),g=(i?.entries??[]).filter(e=>e.kind===`native`&&!h.has(e.capName)).map(e=>e.capName),_=m.length>0?m:g,v=a.location??null,y=a.metadata??null,b=y!==null&&Object.keys(y).length>0;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[u(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),b&&r(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[u(Qr,{active:o===`identity`,onClick:()=>s(`identity`),label:`Identity`}),u(Qr,{active:o===`hardware`,onClick:()=>s(`hardware`),label:`Hardware`})]})]}),(!b||o===`identity`)&&r(`div`,{className:`divide-y divide-border`,children:[u($,{label:`ID`,value:r(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${e}`,r(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,l,`)`]})]})}),u(Gr,{deviceId:e,initialName:d}),u(Kr,{deviceId:e,initialLocation:v}),u(qr,{deviceId:e}),u($,{label:`Type`,value:f}),u($,{label:`Provider`,value:u(rn,{type:p,size:`sm`,showLabel:!0})}),u($,{label:`Capabilities`,value:_.length>0?u(cn,{capabilities:_,showLabels:!0}):u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),b&&o===`hardware`&&u($r,{metadata:y})]})}function Qr({active:e,onClick:t,label:n}){return u(`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 $r({metadata:e}){let t=Jr.filter(t=>t in e),n=Object.keys(e).filter(e=>!Jr.includes(e)).toSorted(),i=[...t,...n];return r(`div`,{children:[u(`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.`}),u(`div`,{className:`divide-y divide-border`,children:i.map(t=>u($,{label:Yr(t),value:u(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:Xr(e[t])})},t))})]})}var ei=`Notifications`,ti=`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`;function ni(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:ei,on:r===null?null:i??r,available:r!==null,costWhenOff:ti}}function ri(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}n();function ii(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function ai({deviceId:t}){let n=s(),i=Number.isFinite(t),[a,o]=c(null),[l,d]=c(null),f=ni({mutedDeviceIds:ii(me({},{enabled:i}).data),deviceId:t,pendingOn:l}),p=Y({onError:e=>{console.error(`[DeviceNotificationMute] mute write failed — reverting`,{tags:{deviceId:t},meta:{error:e instanceof Error?e.message:String(e)}}),d(null),o(e instanceof Error?e.message:String(e)),n.invalidateQueries({queryKey:[[`notificationRules`,`listDeviceMutes`]]})},onSuccess:()=>{o(null),d(null),n.invalidateQueries({queryKey:[[`notificationRules`]]})}}),m=e(()=>{let e=ri(f,t);e!==null&&(d(!e.muted),p.mutate(e))},[t,p,f]),h=f.on===null,g=f.on===!1,_=g?ge:fe;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`border-b border-border px-4 py-2 flex items-center justify-between gap-2`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Notifications`}),g&&u(`span`,{className:`rounded bg-warning/20 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide text-warning`,children:`muted`})]}),r(`div`,{className:`px-4 py-3 flex items-start gap-3`,children:[r(`button`,{type:`button`,role:`switch`,"aria-label":f.label,"aria-checked":f.on===!0,disabled:!f.available||p.isPending,onClick:m,title:h?`Notification mute — state unknown; the notification centre did not answer.`:g?`Muted. ${f.costWhenOff}`:`Notifying. Muting it: ${f.costWhenOff}`,className:`inline-flex items-center gap-1.5 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors disabled:cursor-not-allowed ${a===null?h?`border-dashed border-border text-foreground-subtle/50`:g?`border-warning/40 text-warning hover:bg-warning/10`:`border-success/30 text-success hover:bg-success/10`:`border-danger/50 text-danger bg-danger/5`}`,children:[u(_,{className:`h-3.5 w-3.5`}),u(`span`,{children:h?`Unknown`:g?`Muted`:`Notifying`})]}),u(`p`,{className:`flex-1 text-[11px] leading-relaxed text-foreground-subtle`,children:a===null?h?`The notification centre did not answer, so this device’s mute state is unknown.`:f.costWhenOff:`Write failed: ${a}`})]})]})}function oi(e,t){return{switchId:e,label:ln[e].label,detail:t===void 0||t.length===0?null:t}}function si(e){let t=new Map;for(let n of e.switches)n.deviceId===e.sourceId&&(t.has(n.switchId)||t.set(n.switchId,n));return t}function ci(e){let t=si(e),n=new Set(e.sourceStillLive),r=e.sourceStillLive.map(e=>oi(e,t.get(e)?.detail)),i=[...t.values()].filter(e=>e.outcome===`not-offered`&&!n.has(e.switchId)).map(e=>oi(e.switchId,e.detail));return{inheritedId:e.sourceId,retiredId:e.targetId,swapped:e.swapped,verdict:r.length===0?`quiet`:`still-live`,stillLive:r,neverOffered:i}}n();function li(e,t){return e.filter(e=>e.isCamera&&e.id!==t).map(e=>({id:e.id,name:e.name})).toSorted((e,t)=>e.name.localeCompare(t.name))}function ui({deviceId:e,deviceName:t}){let{t:n}=gn(),a=Re(),[o,s]=c(null),l=St({isCamera:!0,projection:`slim`}),d=Qe(),f=l.data!==void 0,p=i(()=>l.data===void 0?[]:li(l.data,e),[l.data,e]),m=p.find(e=>e.id===o)??null,h=d.data===void 0?null:ci(d.data),g=d.error===null?null:d.error.message,_=async()=>{m===null||m.id===e||await a({title:n(`deviceMigrate.confirmTitle`,`Replace “{{source}}” with “{{target}}”?`,{source:t,target:m.name}),message:n(`deviceMigrate.confirmMessage`,`“{{target}}” takes over number {{sourceId}}. That number is what every recording, event, rule, zone and home-automation export of “{{source}}” is filed under, so all of it follows the number to the new hardware and keeps working. “{{source}}” is switched off and handed number {{targetId}} in exchange. This swaps two device identities and cannot be undone from here.`,{source:t,target:m.name,sourceId:e,targetId:m.id}),confirmLabel:n(`deviceMigrate.confirmAction`,`Migrate`),variant:`danger`})&&d.mutate({sourceId:e,targetId:m.id})};return r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`min-w-0`,children:[u(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:n(`deviceMigrate.title`,`Migrate to…`)}),u(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:n(`deviceMigrate.subtitle`,`Replace this camera with other hardware you have already adopted. The new camera inherits number {{deviceId}}, so recordings, rules and integrations follow it.`,{deviceId:e})})]}),r(`div`,{className:`flex shrink-0 items-center gap-2`,children:[r(`select`,{"aria-label":n(`deviceMigrate.pickerLabel`,`Replacement camera`),className:`rounded-md border border-border bg-background px-2 py-1.5 text-xs text-foreground disabled:opacity-50`,disabled:!f||p.length===0||d.isPending,value:o===null?``:String(o),onChange:e=>{let t=e.target.value;s(t===``?null:Number(t))},children:[u(`option`,{value:``,children:f?n(`deviceMigrate.pickerPlaceholder`,`Select a camera…`):n(`deviceMigrate.pickerPending`,`Reading the fleet…`)}),p.map(e=>r(`option`,{value:String(e.id),children:[e.name,` (#`,e.id,`)`]},e.id))]}),r(`button`,{type:`button`,disabled:m===null||d.isPending,onClick:()=>{_()},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:[u(kn,{className:`h-3 w-3`}),d.isPending?n(`deviceMigrate.running`,`Migrating…`):n(`deviceMigrate.action`,`Migrate`)]})]})]}),f&&p.length===0&&u(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:n(`deviceMigrate.noTargets`,`No other camera is adopted, so there is nothing to migrate to.`)}),g!==null&&u(`p`,{className:`mt-2 text-[11px] text-danger`,children:n(`deviceMigrate.failed`,`Migration failed: {{error}}`,{error:g})}),h!==null&&u(di,{report:h})]})}function di({report:e}){let{t}=gn(),n=e.verdict===`quiet`;return r(`div`,{className:`mt-3 space-y-2 border-t border-border pt-3`,children:[u(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`deviceMigrate.swapped`,`The replacement now answers on number {{inheritedId}}; the old camera was handed number {{retiredId}}.`,{inheritedId:e.inheritedId,retiredId:e.retiredId})}),n?r(`div`,{className:`flex items-start gap-2 rounded-md border border-success/30 bg-success/5 px-3 py-2`,children:[u($t,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-success`}),u(`p`,{className:`text-[11px] leading-relaxed text-foreground`,children:t(`deviceMigrate.quiet`,`Every function on the replaced camera was switched off — the old hardware is quiet.`)})]}):r(`div`,{className:`rounded-md border border-warning/40 bg-warning/5 px-3 py-2`,children:[r(`div`,{className:`flex items-start gap-2`,children:[u(Ue,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),u(`p`,{className:`text-[11px] leading-relaxed text-foreground`,children:t(`deviceMigrate.stillLive`,`The replaced camera could not be reached, so these functions are STILL RUNNING on the old hardware. Nothing here failed to migrate — but until you unplug it or reach it physically, it can still produce data.`)})]}),u(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.stillLive.map(e=>r(`li`,{className:`text-[11px] text-foreground`,children:[u(`span`,{className:`font-medium`,children:e.label}),e.detail!==null&&r(`span`,{className:`text-foreground-subtle`,children:[` — `,e.detail]})]},e.switchId))})]}),e.neverOffered.length>0&&r(`div`,{className:`rounded-md border border-border px-3 py-2`,children:[r(`div`,{className:`flex items-start gap-2`,children:[u(an,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),u(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`deviceMigrate.neverOffered`,`The replaced camera never offered these, so there was nothing to switch off. They are not running.`)})]}),u(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.neverOffered.map(e=>u(`li`,{className:`text-[11px] text-foreground-subtle`,children:e.label},e.switchId))})]})]})}n();function fi({deviceId:e}){let[t,n]=c(null),i=te({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 r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[r(`div`,{className:`flex items-center justify-between gap-3`,children:[r(`div`,{children:[u(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),u(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),r(`button`,{type:`button`,disabled:i.isPending,onClick:()=>{n(null),i.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:[u(Xt,{className:`h-3 w-3 ${i.isPending?`animate-spin`:``}`}),i.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&u(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}function pi({deviceName:e,value:t,inheritedIcon:n,inheritedLabel:i,disabled:a,onChange:o}){let{t:s}=gn(),c={trigger:s(`deviceDisplay.pickIcon`,{name:e}),panel:s(`deviceDisplay.iconFor`,{name:e}),close:s(`deviceDisplay.closePicker`),searchPlaceholder:s(`deviceDisplay.iconSearchPlaceholder`),clear:i,noMatches:s(`deviceDisplay.iconNoMatches`),groups:{device:s(`deviceDisplay.iconGroupDevice`),lighting:s(`deviceDisplay.iconGroupLighting`),sensing:s(`deviceDisplay.iconGroupSensing`),place:s(`deviceDisplay.iconGroupPlace`),life:s(`deviceDisplay.iconGroupLife`)}};return r(`div`,{className:`flex items-center gap-2`,children:[u(Ht,{value:t===``?null:t,onPick:e=>o(e??``),resolveGlyph:De,fallbackGlyph:n,labels:c,disabled:a}),u(`span`,{className:`text-[11px] text-foreground-subtle`,children:t===``?i:t})]})}n();var mi=`w-full min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary disabled:opacity-50`,hi={icon:``,label:``,unit:``,precision:``,hidden:!1};function gi(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function _i(e){if(typeof e!=`object`||!e)return;let t=e.unit;return typeof t==`string`?t:void 0}function vi(e){if(e.trim()===``)return;let t=Number.parseInt(e,10);return Number.isFinite(t)?t:void 0}function yi(e,t){let n=vi(e.precision),r={...e.icon===``?{}:{icon:e.icon},...e.label.trim()===``?{}:{label:e.label.trim()},...e.unit===``?{}:{unit:e.unit},...n===void 0?{}:{precision:n},...e.hidden?{hidden:!0}:{},...t?.perCap===void 0?{}:{perCap:t.perCap}};return Object.keys(r).length===0?null:r}function bi({deviceId:e}){let{t}=gn(),n=_(),a=s(),{data:l}=At({deviceId:e},{enabled:e>0}),d=typeof l?.role==`string`&&l.role.length>0?l.role:null,f=d===null?void 0:Se[d],p=f?.kind===`numeric`,m=String(l?.type??``),h=d!==null||l?.parentDeviceId!==null&&l?.parentDeviceId!==void 0,g=Ge(n.trpcClient,e,d??``),v=f?.kind===`numeric`?f.canonicalUnit:void 0,y=_i(g)??v,b=y===void 0?void 0:fn(y),x=i(()=>b===void 0?[]:dn(b),[b]),[S,C]=c(null),w=S??gi(l?.display),T=qt({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:E}=Ve({},{staleTime:6e4,enabled:d!==null}),D=ye({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(l==null)return null;let O=e=>{C({...w,...e})},k=()=>{T.mutate({deviceId:e,display:yi(w,l.display)})},A=()=>{C(hi),T.mutate({deviceId:e,display:null})},j=()=>{if(d===null)return;let e=vi(w.precision),t={...w.icon===``?{}:{icon:w.icon},...w.unit===``?{}:{unit:w.unit},...e===void 0?{}:{precision:e}},n={...E?.defaults,[d]:t};D.mutate({defaults:n})},M=d===null?void 0:E?.defaults[d]?.icon,P=M===void 0?void 0:De(M),F=d===null?q(m):N(d),I={icon:P??F.icon,label:P===void 0?F.label:String(M)},L=d===null&&m===X.Container?t(`deviceDisplay.inheritedContainer`):P===void 0?t(`deviceDisplay.inherited`,{name:I.label}):t(`deviceDisplay.inheritedRoleDefault`,{icon:I.label,role:F.label}),R=typeof l.name==`string`?l.name:`#${String(e)}`,z=d===null?``:N(d).label;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[u(`div`,{className:`border-b border-border px-3 sm:px-4 py-2`,children:u(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:t(`deviceDisplay.title`)})}),r(`div`,{className:`divide-y divide-border`,children:[u($,{label:t(`deviceDisplay.icon`),value:u(pi,{deviceName:R,value:w.icon,inheritedIcon:I.icon,inheritedLabel:L,disabled:T.isPending,onChange:e=>O({icon:e})})}),h&&u($,{label:t(`deviceDisplay.label`),value:u(`input`,{type:`text`,className:mi,"aria-label":t(`deviceDisplay.label`),placeholder:d===null?R:z,value:w.label,onChange:e=>O({label:e.target.value})})}),p&&r(o,{children:[u($,{label:t(`deviceDisplay.unit`),value:r(`select`,{className:mi,"aria-label":t(`deviceDisplay.unit`),value:w.unit,onChange:e=>O({unit:e.target.value}),disabled:x.length===0,children:[u(`option`,{value:``,children:t(`deviceDisplay.unitSource`,{unit:y===void 0?``:` (${y})`})}),x.map(e=>u(`option`,{value:e,children:e},e))]})}),u($,{label:t(`deviceDisplay.precision`),value:u(`input`,{type:`number`,min:0,max:10,step:1,className:mi,"aria-label":t(`deviceDisplay.precision`),placeholder:t(`deviceDisplay.precisionInherit`),value:w.precision,onChange:e=>O({precision:e.target.value})})})]}),u($,{label:t(`deviceDisplay.hidden`),value:r(`label`,{className:`flex items-center gap-2`,children:[u(`input`,{type:`checkbox`,checked:w.hidden,onChange:e=>O({hidden:e.target.checked})}),u(`span`,{className:`text-[11px] text-foreground`,children:t(`deviceDisplay.hideFromLists`)})]})})]}),r(`div`,{className:`border-t border-border px-3 sm:px-4 py-2 flex flex-wrap items-center gap-2`,children:[u(`button`,{type:`button`,className:`rounded bg-primary px-3 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-50`,onClick:k,disabled:T.isPending,children:t(`common.save`)}),u(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-[11px] text-foreground-subtle`,onClick:A,disabled:T.isPending,children:t(`common.reset`)}),d!==null&&u(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-[11px] text-foreground-subtle`,onClick:j,disabled:D.isPending,title:t(`deviceDisplay.setRoleDefaultTitle`,{role:z}),children:t(`deviceDisplay.setRoleDefault`,{role:z})})]})]})}function xi(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function Si({device:e}){let t=mn(),n=typeof e.id==`number`?e.id:null,i=String(e.type??``),a=i===X.Camera,o=i===X.Hub,s=e.features??[],c=s.includes(pn.Resyncable),{data:l}=R({deviceId:n??0},{enabled:n!==null&&a,refetchInterval:5e3}),d=l?.streams??{},f=Object.entries(d),p=s.includes(pn.DoorbellButton),m=ot(p?{deviceId:n??void 0,historyLimit:10}:void 0),h=m.latest?Date.now()-m.latest.timestamp<3e4:!1;return r(`div`,{className:`space-y-5`,children:[o&&n!==null&&u(He,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),c&&n!==null&&u(fi,{deviceId:n}),a&&n!==null&&u(ui,{deviceId:n,deviceName:String(e.name??``)}),n!==null&&u(ai,{deviceId:n}),a&&n!==null&&u(Le,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),p&&u(Yt,{history:m.history,latestIsFresh:h}),a&&n!==null&&u(Le,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),a&&f.length>0&&r(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[u(`div`,{className:`border-b border-border px-4 py-2`,children:u(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),u(`div`,{className:`divide-y divide-border`,children:f.map(([e,t])=>r(`div`,{className:`px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 mb-2`,children:[u(ut,{className:`h-3 w-3 text-foreground-subtle`}),u(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),r(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[u(Ci,{label:`Nominal`,value:xi(t.nominalBitrateKbps??0)}),u(Ci,{label:`Observed`,value:xi(t.observedBitrateKbps??0)}),u(Ci,{label:`Peak`,value:xi(t.peakBitrateKbps??0)}),u(Ci,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),u(Zr,{}),n!==null&&u(bi,{deviceId:n})]})}function Ci({label:e,value:t,warning:n}){return r(`div`,{children:[u(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),u(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}function wi({provider:e,integrationId:t,name:n}){let r=mn(),i=t===null?`/integrations`:`/integrations/${t}`,a=n===null?`Open integrations`:`Open integration ${n}`;return u(`button`,{type:`button`,onClick:()=>r(i),className:`shrink-0 rounded-md transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-1 focus-visible:ring-primary/50`,title:a,"aria-label":a,children:u(rn,{type:e,size:`lg`})})}n();var Ti=[{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}];function Ei(e){let t=e===X.Camera;return Ti.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var Di=[{id:`logs`,icon:Ct,label:`Logs`},{id:`repl`,icon:hn,label:`REPL`},{id:`events`,icon:ft,label:`Events`},{id:`state`,icon:Ke,label:`State`}];function Oi(){let n=_n(),a=Number(n.deviceId),l=Number.isFinite(a),d=mn(),f=s(),m=Re(),h=_(),[g,v]=vn(),y=g.get(`tab`)??`overview`,b=g.get(`sub`),[x,S]=c(`logs`),T=`device-detail.left-col-width-px`,[D,O]=c(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(T),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),A=t(D);A.current=D;function j(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??D??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{O(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=A.current;if(e!==null)try{window.localStorage.setItem(T,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:M,isLoading:N,isError:P}=At({deviceId:a},{enabled:l,refetchInterval:5e3,retry:1}),{data:I}=st({deviceId:a},{enabled:l}),L=i(()=>{let e=I?.settings?.sections??[],t=I?.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(Tn)&&r.add(En),[...r].map(e=>e===`export`?{id:e,label:Dn,isAddonContrib:!0}:{id:e,label:un[e]?.label??e,isAddonContrib:!0})},[I]),R=M,z=String(R?.name??n.deviceId??`Device`),B=R?.online===!0,ee=B?`online`:`offline`,H=String(R?.addonId??`rtsp`),U=R?.features??[],W=R?.type,G=W===X.Camera,{data:K}=bn(l?a:0),te=W===X.Container,ne=i(()=>(K??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[K]),q=i(()=>te?ce(ne,typeof R?.linkDeviceId==`number`?R.linkDeviceId:null,typeof R?.primaryChildEntityId==`string`?R.primaryChildEntityId:null)?.id??null:null,[te,ne,R?.linkDeviceId,R?.primaryChildEntityId]),{data:re}=st({deviceId:q??0},{enabled:q!==null}),ie=i(()=>{if(q===null)return[];let e=re?.settings?.sections??[],t=re?.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:un[e]?.label??e,isAddonContrib:!0,childDeviceId:q}))},[q,re]),ae=typeof R?.parentDeviceId==`number`?R.parentDeviceId:null,{data:oe}=At({deviceId:ae??0},{enabled:ae!==null}),J=V(),le=R?.disabled!==!0,ue=i(()=>{let e=new Set,t=[];for(let n of[...Ei(W),...L,...ie])e.has(n.id)||(e.add(n.id),t.push(n));return t},[W,L,ie]),de=i(()=>Dr(ue,y),[ue,y]),fe=e(e=>{v(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[v]),me=e(e=>{v(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[v]),he=(K??[]).length>0,ge=i(()=>Di.filter(({featureGate:e})=>!e||U.includes(e)),[U]),{data:ve}=Ie(void 0),ye=i(()=>R?_e(R,ve):null,[R,ve]),Y=ye?.kind===`resolved`?ye.integration:null,xe=Y===null?ye?.kind===`unknown`?`Loading integration…`:ye?.kind===`orphan`?`Missing integration`:`No integration`:Y.name,Se=Y!==null&&Y.addonId===H?Y.name:H,we=rt({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]}),d(Y?.id?`/integrations/${Y.id}`:`/integrations`)}}),Te=k({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ee=se({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),De=ct(),ke=Dt({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ae=U.includes(pn.Rebootable),je=U.includes(pn.BatteryOperated),Me=be(h.trpcClient,je&&l?a:null),Ne=pe(h.trpcClient,l?a:null),[Pe,Fe]=c(!1),Le=async()=>{if(!Pe){Fe(!0);try{let e=z.replace(/[^a-zA-Z0-9_.-]+/g,`_`),t=new Date().toISOString().replace(/[:.]/g,`-`);await Sn(`${p}/${String(a)}.jpg?force=1`,`${e}-${t}.jpg`)}finally{Fe(!1)}}},Be=Te.isPending||Ee.isPending,{data:Ve}=Zt({deviceId:a},{enabled:l,refetchInterval:1e4}),He=Ve?.agentNodeId??null,Ue=typeof He==`string`&&He.length>0&&!He.startsWith(`addon:`)?He:void 0,{data:We}=Oe({deviceId:a,...Ue?{nodeId:Ue}:{}},{enabled:l,refetchInterval:3e3,retry:!1}),{data:Ge}=ht({deviceId:a},{enabled:l,refetchInterval:3e3,retry:!1}),Ke=Ge?.level?.dbfs??null;function qe(){if(!l)return null;switch(de){case`overview`:return u(Si,{device:R??{}});case`config`:return u(Mr,{deviceId:a,activeSubTab:b,onSubTabChange:me});case`detection-pipeline`:return u(Wr,{deviceId:a,activeSubTab:b,onSubTabChange:me});case`bindings`:return u(Or,{deviceId:a});default:{let e=de,t=L.some(t=>t.id===e),n=ie.find(t=>t.id===e);if(!t&&n===void 0)return null;let r=n?.childDeviceId??a;if(e===`export`)return u(On,{deviceId:a,sectionFilter:Tn,activeSubTab:b,onSubTabChange:me});let i=u(On,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:b,onSubTabChange:me});return n!==void 0&&r!==a?u($e,{deviceId:r,children:i}):i}}}return l?N?r(`div`,{className:`flex flex-col h-full`,children:[r(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[u(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),u(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),u(`div`,{className:`flex-1 p-6`,children:u(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):P||!M?r(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[u(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),r(`p`,{className:`text-xs`,children:[`No device with ID`,` `,r(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,a]})]}),u(`button`,{onClick:()=>d(`/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`})]}):r(`div`,{className:`absolute inset-0 flex flex-col overflow-clip`,children:[r(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[u(`div`,{className:`mb-2`,children:u(at,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},Y===null?{label:xe}:{label:xe,onClick:()=>d(`/integrations/${Y.id}`)},{label:z}]})}),r(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[Y!==null&&u(wi,{provider:Y.addonId,integrationId:Y.id,name:Y.name}),r(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:z}),u(Cn,{status:ee}),je&&u(ze,{status:Me,variant:`full`}),u(tt,{status:Ne})]}),ae!==null&&oe&&r(`button`,{type:`button`,onClick:()=>d(`/devices/${ae}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${oe.name}`,children:[u(`span`,{children:`↑`}),u(`span`,{className:`truncate`,children:String(oe.name??`Device #${ae}`)})]}),u(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:U.length>0&&u(cn,{capabilities:U})})]}),We&&u(`div`,{className:`hidden lg:flex`,children:u(ki,{metrics:We,dbfs:Ke})}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[r(`button`,{onClick:async()=>{le?await m({title:`Disable "${z}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Ee.mutate({deviceId:a}):Te.mutate({deviceId:a})},disabled:Be,title:le?`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 ${le?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[u(F,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:Be?`Updating…`:le?`Enabled`:`Disabled`})]}),u(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),G&&r(o,{children:[u(Rn,{deviceId:a}),u(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),u(Bn,{deviceId:a}),u(Bt,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:E,disabled:Pe,onClick:()=>{Le()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:Vt,hidden:!Ae,disabled:De.isPending,danger:!0,onClick:async()=>{await m({title:`Reboot "${z}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&De.mutate({deviceId:a})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${Se}.`,icon:Xt,disabled:ke.isPending,danger:!0,onClick:async()=>{await m({title:`Restart "${Se}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${z}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&ke.mutate({addonId:H})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:C,separatorBefore:!0,disabled:we.isPending,danger:!0,onClick:async()=>{await m({title:`Delete "${z}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&we.mutate({deviceId:a})}}]})]})]})]}),u($e,{deviceId:a,device:R??void 0,children:u(Ft,{children:u(Ce,{children:u(w,{children:u(mt,{children:r(`main`,{className:J?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[r(`div`,{className:J?`flex flex-col bg-surface`:`${D===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!J&&D!==null?{width:`${String(D)}px`}:void 0,children:[u(`div`,{className:G?`flex-shrink-0 border-b border-border-subtle bg-black`:J?`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:G?u(br,{deviceId:a,intercomAvailable:U.includes(pn.TwoWayAudio)}):u(ur,{deviceId:a,deviceName:z,deviceType:W??`unknown`,provider:H,isOnline:B,features:U})}),r(`div`,{className:J?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[u(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:u(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:ge.map(({id:e,label:t,icon:n})=>r(`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 ${x===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[u(n,{className:`h-3 w-3`}),t]},e))})}),r(`div`,{className:J?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[x===`logs`&&u(xr,{deviceId:a,containerDeviceId:W===`container`?a:void 0}),x===`repl`&&u(Sr,{deviceId:a}),x===`events`&&u(Cr,{deviceId:a}),x===`state`&&u(wr,{deviceId:a})]})]})]}),!J&&u(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:j,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:u(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),r(`div`,{className:J?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[u(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:u(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:ue.map(e=>{let t=de===e.id;return r(`button`,{onClick:()=>fe(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&&u(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),r(`div`,{className:J?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[de===`overview`&&he&&u(Vn,{parentDeviceId:a}),qe()]})]})]})})})})})})]}):r(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[u(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),r(`p`,{className:`text-xs`,children:[`The URL segment`,` `,u(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:n.deviceId}),` `,`is not a number.`]}),u(`button`,{onClick:()=>d(`/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 ki({metrics:e,dbfs:t}){let n=Nt(e.phase??`idle`);return r(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[r(`div`,{className:`flex items-center gap-1.5`,children:[u(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),u(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),u(`div`,{className:`h-3 w-px bg-border`}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[u(ne,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),u(`span`,{children:`fps`})]}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[u(gt,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),u(`span`,{children:`ms`})]}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[u(H,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),u(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&r(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{Oi as DeviceDetailPage};
|