@camstack/addon-admin-ui 1.1.62 → 1.1.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddLocationWizard-DloYiu2S.js → AddLocationWizard-VuBsssbs.js} +1 -1
- package/dist/assets/{AddonCollectionPage-C9umFG6x.js → AddonCollectionPage-rY0iw4Lx.js} +1 -1
- package/dist/assets/Addons-waDrxMrF.js +1 -0
- package/dist/assets/{AdminTabs-TF8h_0Re.js → AdminTabs-DdlxkzYF.js} +1 -1
- package/dist/assets/{AiProfiles-evBlKpAk.js → AiProfiles-CXfreEns.js} +1 -1
- package/dist/assets/{BrokerForm-CQiMr-0k.js → BrokerForm-Bi1zDzJU.js} +1 -1
- package/dist/assets/{Capabilities-CpLtxdIb.js → Capabilities-CBqnCVAQ.js} +1 -1
- package/dist/assets/{CapabilityBadges-BaPmSkOh.js → CapabilityBadges-bb3Kp76B.js} +1 -1
- package/dist/assets/{Cluster-DXC7Y0WT.js → Cluster-CkmNDo_z.js} +1 -1
- package/dist/assets/{ClusterRecordingTab-C8mgxr8n.js → ClusterRecordingTab-qj7qdRav.js} +1 -1
- package/dist/assets/{Dashboard-B8VEZ1hu.js → Dashboard-0L-WtwHw.js} +1 -1
- package/dist/assets/{Data-C4BVroUC.js → Data-B-KdcyYb.js} +1 -1
- package/dist/assets/{DetectionIntelligence-C4VkDPxu.js → DetectionIntelligence-DH2CerYz.js} +1 -1
- package/dist/assets/DeviceDetail-C0xHmlNy.js +2 -0
- package/dist/assets/{Devices-Bo3g7ayF.js → Devices-BqWTi9bF.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-ChQqe1h_.js → EmbedPlayerPage-BmllV_ir.js} +1 -1
- package/dist/assets/{Events-BEqbcBJ_.js → Events-Cg33ehHw.js} +1 -1
- package/dist/assets/{FormBuilder-CEAqDJkq.js → FormBuilder-DDOu77Pz.js} +1 -1
- package/dist/assets/Identity-DokGTNX5.js +1 -0
- package/dist/assets/{IntegrationDetail-C34UIPLB.js → IntegrationDetail-HKDhoWtW.js} +1 -1
- package/dist/assets/{Integrations-B1rfOrsh.js → Integrations-as3Ez0fd.js} +1 -1
- package/dist/assets/{Integrations-CNkb6EXJ.js → Integrations-qqFL0Gs0.js} +1 -1
- package/dist/assets/{Logs-b1hP9wnb.js → Logs-C0i-qXwM.js} +1 -1
- package/dist/assets/{MotionZonesSettings-QJdI6XiU.js → MotionZonesSettings-rxIHdY6l.js} +1 -1
- package/dist/assets/{MyAccess-Dsd8wzR-.js → MyAccess-52fP18AF.js} +1 -1
- package/dist/assets/Network-s1InxtpH.js +1 -0
- package/dist/assets/NodeAddonsSettingsPanel-PSaY411C.js +1 -0
- package/dist/assets/NodeInferenceDevices-CoLAPH96.js +1 -0
- package/dist/assets/{NotificationTargets-DCtElvUz.js → NotificationTargets-BYTjEwxL.js} +1 -1
- package/dist/assets/Pipeline-D3jI3Huf.js +1 -0
- package/dist/assets/{Plates-Bf-xBe2z.js → Plates-BwI8RHl9.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-7obyiJDJ.js → PrivacyMaskSettings-DDk6LoXQ.js} +1 -1
- package/dist/assets/{ProviderIcon-Dn5ec0PG.js → ProviderIcon-CWyyzoZB.js} +1 -1
- package/dist/assets/{Recordings-Dft02-H7.js → Recordings-D5IKi_ba.js} +1 -1
- package/dist/assets/{ScanNetworkModal-Rg9lE9vS.js → ScanNetworkModal-B2bUhuZ1.js} +1 -1
- package/dist/assets/{Settings-Wyhgkdl2.js → Settings-DKkqVGNC.js} +1 -1
- package/dist/assets/{Showroom-xc9oNpRl.js → Showroom-ablwi-TX.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BzYJJkX0.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CCcHjOIo.js} +1 -1
- package/dist/assets/{build-cluster-graph-pFpr-a1b.js → build-cluster-graph-C1vd_7m_.js} +1 -1
- package/dist/assets/circle-check-big-GmO5fdEl.js +1 -0
- package/dist/assets/clock-OUNfpFX_.js +1 -0
- package/dist/assets/{copy-D3_V1b8c.js → copy-St-1O01R.js} +1 -1
- package/dist/assets/{debounced-invalidate-B8289fFj.js → debounced-invalidate-DlIKzA73.js} +1 -1
- package/dist/assets/{dist-Bhw1R8vS.js → dist-CYW0dAGQ.js} +1 -1
- package/dist/assets/dist-D7nNU2QV.js +7 -0
- package/dist/assets/{download-DRBnzzV8.js → download-CJ-1cdDh.js} +1 -1
- package/dist/assets/{face-bbox-DMbv2bqb.js → face-bbox-CTcnAI8I.js} +1 -1
- package/dist/assets/{hostInit-DVAMD32c.js → hostInit-D4IGCyt3.js} +1 -1
- package/dist/assets/index-BKBKdGDb.css +2 -0
- package/dist/assets/index-Cjto-EXm.js +4 -0
- package/dist/assets/{key-round-Ck0BlLku.js → key-round-LcTErOxf.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-b01246c3.js → mf-entry-bootstrap-0-c57c6485.js} +2 -2
- package/dist/assets/{pencil-BtT77pEX.js → pencil-BkXeyiDf.js} +1 -1
- package/dist/assets/{player-overlays-QWBHo29P.js → player-overlays-BfnV1C0Q.js} +1 -1
- package/dist/assets/plus-DXXZ8pd7.js +1 -0
- package/dist/assets/{radio-BW05_hyT.js → radio-CGyv3voN.js} +1 -1
- package/dist/assets/{refresh-cw-CNpUNbYp.js → refresh-cw-DC4KMLsa.js} +1 -1
- package/dist/assets/remoteEntry-CXtVdVO7.js +1 -0
- package/dist/assets/{rotate-ccw-NNRCRLfM.js → rotate-ccw-DlNmHkpr.js} +1 -1
- package/dist/assets/rotate-cw-d8IjPUYX.js +1 -0
- package/dist/assets/search-DkClo4ZA.js +1 -0
- package/dist/assets/{send-Dg4BnyPy.js → send-CeJ2J9V3.js} +1 -1
- package/dist/assets/{server-DGvm2Yhg.js → server-CArIZ-KL.js} +1 -1
- package/dist/assets/square-BFjZ9GUs.js +1 -0
- package/dist/assets/{square-check-big-yVkG_6n8.js → square-check-big--y441eG8.js} +1 -1
- package/dist/assets/src-CCZM6rtM.js +7 -0
- package/dist/assets/src-CfZUxvPx.js +67 -0
- package/dist/assets/{upload-CYyYTPKF.js → upload-D6H_84gF.js} +1 -1
- package/dist/assets/{useEventInvalidation-BLqZqkUr.js → useEventInvalidation-DxjiYIcd.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-B2mPipaU.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-zgU2Aw4J.js} +2 -2
- package/dist/assets/{wifi-DnJudwD3.js → wifi-B0toFYT9.js} +1 -1
- package/dist/assets/{zap-BfS-dLf9.js → zap-d6IKZFEN.js} +1 -1
- package/dist/index.html +6 -6
- package/dist/server/addon.js +128 -33
- package/package.json +1 -1
- package/dist/assets/Addons-Cse26rBh.js +0 -1
- package/dist/assets/DeviceDetail-C8hpQWzm.js +0 -2
- package/dist/assets/Identity-CEdFWuZM.js +0 -1
- package/dist/assets/Network-CffBO4S5.js +0 -1
- package/dist/assets/NodeAddonsSettingsPanel-MlyYe60u.js +0 -1
- package/dist/assets/Pipeline-DhPbloot.js +0 -1
- package/dist/assets/circle-check-big-BZqYU7ME.js +0 -1
- package/dist/assets/clock-FEgXpSrj.js +0 -1
- package/dist/assets/dist-CGJaNSH2.js +0 -7
- package/dist/assets/index-Cmef4Jek.css +0 -2
- package/dist/assets/index-DCWyP9SY.js +0 -4
- package/dist/assets/plus-KUJYci_9.js +0 -1
- package/dist/assets/remoteEntry-C9xa2tPo.js +0 -1
- package/dist/assets/rotate-cw-XFiHXxEb.js +0 -1
- package/dist/assets/search-By_XOQoF.js +0 -1
- package/dist/assets/square-CDRKBQqh.js +0 -1
- package/dist/assets/src-Ck8eP0y_.js +0 -7
- package/dist/assets/src-aCTgvsel.js +0 -67
- package/dist/assets/useDevice-D5MwztfZ.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Ia as e,S as t,_o as n,fo as r,ho as i,lo as a,mo as o,po as s,uo as c,vo as l,yo as u}from"./src-aCTgvsel.js";import{Q as d,S as f,W as p,a as m,q as h,t as g,x as _}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as v}from"./player-overlays-QWBHo29P.js";import{t as y}from"./circle-check-big-BZqYU7ME.js";import{t as b}from"./pencil-BtT77pEX.js";import{t as x}from"./plus-KUJYci_9.js";import{t as S}from"./search-By_XOQoF.js";import{t as C}from"./send-Dg4BnyPy.js";import{N as w,S as T,V as E,s as D}from"./index-DCWyP9SY.js";import{t as O}from"./AdminPage-BwmGKnRf.js";d();var k=e=>typeof e==`string`&&e.length>0;function A(e){return{levels:e.levels,formats:e.format,bodyMaxLen:e.bodyMaxLen,attachmentSlots:e.attachments.mediaTypes,attachmentMode:e.attachments.mode,attachmentMax:e.attachments.max,attachmentMaxBytes:e.attachments.maxBytes,maxActions:e.actions,showActions:e.actions>0,showClickUrl:e.clickUrl,showSound:e.sound,showTtl:e.ttl,showTag:!0}}function j(e,t){return e.format.includes(t)?t:e.format[0]??`text`}function M(e,t){let n=[];for(let r of e.attachments.mediaTypes){if(n.length>=e.attachments.max)break;let i=t[r];k(i)&&n.push({mediaType:r,url:i})}return n}function N(e,t){if(e.actions<=0)return[];let n=[];for(let r of t){if(n.length>=e.actions)break;let t=k(r.label),i=k(r.url);!t&&!i||n.push({id:`test-${n.length+1}`,label:t?r.label:`Action ${n.length+1}`,...i?{url:r.url}:{}})}return n}function P(e,t){let n=e.levels.some(e=>e.id===t.level)?t.level:void 0,r=M(e,t.attachmentUrls),i=N(e,t.actions),a=e.ttl&&k(t.ttl)?Number(t.ttl):void 0;return{body:t.body,format:j(e,t.format),priority:F(t.priority),...k(t.title)?{title:t.title}:{},...n?{level:n}:{},...r.length>0?{attachments:r}:{},...i.length>0?{actions:i}:{},...e.clickUrl&&k(t.clickUrl)?{clickUrl:t.clickUrl}:{},...e.sound&&k(t.sound)?{sound:t.sound}:{},...a!==void 0&&Number.isFinite(a)?{ttl:a}:{},...k(t.tag)?{tag:t.tag}:{}}}function F(e){return Number.isFinite(e)?Math.min(5,Math.max(1,Math.round(e))):3}function I(e){return e.levels.find(e=>e.flags?.critical===!0)||e.levels.filter(e=>typeof e.ordinal==`number`).sort((e,t)=>t.ordinal-e.ordinal)[0]}function L(e){return{level:``,priority:3,format:e.format[0]??`text`,title:``,body:``,attachmentUrls:{},actions:[],clickUrl:``,sound:``,ttl:``,tag:``}}var R={image:`https://example.com/sample.jpg`,video:`https://example.com/sample.mp4`,gif:`https://example.com/sample.gif`,audio:`https://example.com/sample.mp3`,icon:`https://example.com/icon.png`};function z(e,t){let n=L(e);switch(t){case`minimal`:return{...n,body:`Test notification`};case`overflow`:return{...n,body:`X`.repeat(e.bodyMaxLen+50)};case`critical`:{let t=I(e);return{...n,body:`Critical test notification`,priority:5,level:t?.id??``}}case`everything`:{let t={},n=0;for(let r of e.attachments.mediaTypes){if(n>=e.attachments.max)break;t[r]=R[r],n+=1}let r=Array.from({length:e.actions},(e,t)=>({label:`Action ${t+1}`,url:`https://example.com/action/${t+1}`}));return{level:``,priority:4,format:e.format.includes(`markdown`)?`markdown`:e.format.includes(`html`)?`html`:e.format[0]??`text`,title:`Everything the kind supports`,body:`This sample fills every control the kind advertises.`,attachmentUrls:t,actions:r,clickUrl:e.clickUrl?`https://example.com/open`:``,sound:e.sound?`default`:``,ttl:e.ttl?`3600`:``,tag:`camstack-test`}}}}var B=[{id:`minimal`,label:`Minimal (body only)`},{id:`everything`,label:`Everything supported`},{id:`overflow`,label:`Overflow`},{id:`critical`,label:`Critical`}],V=`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,H=`block text-[11px] font-medium text-foreground mb-1`;function U({target:e,kind:t,open:n,onClose:i}){let d=v(),m=p(()=>A(t.caps),[t.caps]),[y,b]=h(()=>L(t.caps)),[x,S]=h(null),w=p(()=>P(t.caps,y),[t.caps,y]),E=y.body.length,D=E>m.bodyMaxLen,O=e=>b(t=>({...t,...e})),k=g({mutationFn:()=>d.trpcClient.notificationOutput.testTarget.mutate({addonId:e.addonId,targetId:e.id,sample:P(t.caps,y)}),onMutate:()=>S(null),onSuccess:e=>S(e),onError:e=>S({success:!1,error:e instanceof Error?e.message:`Test failed`})}),j=e=>{b(z(t.caps,e)),S(null)},M=(e,t,n)=>{let r=y.actions.length>0?[...y.actions]:[];for(;r.length<=e;)r.push({label:``,url:``});r[e]={...r[e],[t]:n},O({actions:r})};return _(a,{open:n,onOpenChange:e=>!e&&i(),children:f(c,{width:`lg`,className:`!max-w-2xl`,children:[_(s,{children:f(o,{children:[`Test "`,e.name,`" (`,t.label,`)`]})}),f(`div`,{className:`space-y-4 max-h-[60vh] overflow-y-auto pr-1`,children:[_(`div`,{className:`flex flex-wrap gap-1.5`,children:B.map(e=>_(u,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>j(e.id),children:e.label},e.id))}),f(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m.levels.length>0&&f(`div`,{children:[_(`label`,{className:H,children:`Level`}),f(`select`,{className:V,value:y.level,onChange:e=>O({level:e.target.value}),children:[_(`option`,{value:``,children:`— derive from priority —`}),m.levels.map(e=>f(`option`,{value:e.id,children:[e.label,e.ordinal===null?` (qualitative)`:` (p${e.ordinal})`]},e.id))]}),(()=>{let e=m.levels.find(e=>e.id===y.level);return e?f(`div`,{className:`mt-1 space-y-1`,children:[e.description&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.description}),f(`div`,{className:`flex flex-wrap gap-1`,children:[e.flags?.critical&&_(l,{variant:`danger`,"data-testid":`flag-critical`,children:`critical`}),e.flags?.silent&&_(l,{variant:`info`,children:`silent`}),e.flags?.noPush&&_(l,{variant:`warning`,children:`no-push`})]}),e.requires&&e.requires.length>0&&f(`p`,{className:`text-[10px] text-warning`,children:[`Requires target config: `,e.requires.join(`, `)]})]}):null})()]}),f(`div`,{children:[f(`label`,{className:H,children:[`Priority (ordinal): `,y.priority]}),_(`input`,{type:`range`,min:1,max:5,step:1,value:y.priority,onChange:e=>O({priority:Number(e.target.value)}),className:`w-full accent-primary`,"aria-label":`priority`})]})]}),m.formats.length>0&&f(`div`,{children:[_(`label`,{className:H,children:`Format`}),_(`div`,{className:`flex flex-wrap gap-2`,children:m.formats.map(e=>f(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[_(`input`,{type:`radio`,name:`format`,className:`accent-primary`,checked:y.format===e,onChange:()=>O({format:e})}),e]},e))})]}),f(`div`,{children:[_(`label`,{className:H,children:`Title`}),_(`input`,{className:V,value:y.title,onChange:e=>O({title:e.target.value})})]}),f(`div`,{children:[f(`label`,{className:H,children:[`Body`,` `,f(`span`,{className:D?`text-danger`:`text-foreground-subtle`,children:[`(`,E,`/`,m.bodyMaxLen,D?` — overflow`:``,`)`]})]}),_(`textarea`,{className:`${V} min-h-[80px] resize-y`,value:y.body,onChange:e=>O({body:e.target.value})})]}),m.attachmentSlots.length>0&&f(`div`,{children:[f(`label`,{className:H,children:[`Attachments`,` `,f(`span`,{className:`text-foreground-subtle`,children:[`(mode: `,m.attachmentMode,`, max `,m.attachmentMax,m.attachmentMaxBytes?`, ≤${Math.round(m.attachmentMaxBytes/1024/1024)}MB`:``,`)`]})]}),_(`div`,{className:`space-y-1.5`,children:m.attachmentSlots.map(e=>f(`div`,{className:`flex items-center gap-2`,children:[_(`span`,{className:`text-[10px] w-12 shrink-0 text-foreground-subtle`,children:e}),_(`input`,{className:V,placeholder:`${e} URL`,value:y.attachmentUrls[e]??``,onChange:t=>O({attachmentUrls:{...y.attachmentUrls,[e]:t.target.value}})})]},e))})]}),m.showActions&&f(`div`,{children:[f(`label`,{className:H,children:[`Actions (up to `,m.maxActions,`)`]}),_(`div`,{className:`space-y-1.5`,children:Array.from({length:Math.min(m.maxActions,3)},(e,t)=>f(`div`,{className:`flex items-center gap-2`,children:[_(`input`,{className:V,placeholder:`label`,value:y.actions[t]?.label??``,onChange:e=>M(t,`label`,e.target.value)}),_(`input`,{className:V,placeholder:`url`,value:y.actions[t]?.url??``,onChange:e=>M(t,`url`,e.target.value)})]},t))})]}),f(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m.showClickUrl&&f(`div`,{children:[_(`label`,{className:H,children:`Click URL`}),_(`input`,{className:V,value:y.clickUrl,onChange:e=>O({clickUrl:e.target.value})})]}),m.showSound&&f(`div`,{children:[_(`label`,{className:H,children:`Sound`}),_(`input`,{className:V,value:y.sound,onChange:e=>O({sound:e.target.value})})]}),m.showTtl&&f(`div`,{children:[_(`label`,{className:H,children:`TTL (seconds)`}),_(`input`,{className:V,type:`number`,value:y.ttl,onChange:e=>O({ttl:e.target.value})})]}),m.showTag&&f(`div`,{children:[_(`label`,{className:H,children:`Tag`}),_(`input`,{className:V,value:y.tag,onChange:e=>O({tag:e.target.value})})]})]}),x&&_(W,{result:x}),f(`details`,{className:`text-[10px]`,children:[_(`summary`,{className:`cursor-pointer text-foreground-subtle`,children:`Payload preview`}),_(`pre`,{className:`mt-1 overflow-x-auto rounded bg-surface p-2 text-foreground-subtle`,children:JSON.stringify(w,null,2)})]})]}),f(r,{children:[_(u,{variant:`secondary`,size:`sm`,type:`button`,onClick:i,children:`Close`}),f(u,{size:`sm`,type:`button`,disabled:k.isPending||y.body.length===0,onClick:()=>k.mutate(),children:[k.isPending?_(T,{className:`h-3.5 w-3.5 animate-spin`}):_(C,{className:`h-3.5 w-3.5`}),`Send test`]})]})]})})}function W({result:e}){let t=e.renderedAs;return f(`div`,{className:`rounded-md border px-3 py-2 text-xs ${e.success?`border-success/40 bg-success/10`:`border-danger/40 bg-danger/10`}`,"data-testid":`test-result`,children:[f(`div`,{className:`flex items-center gap-2 font-medium`,children:[e.success?_(y,{className:`h-3.5 w-3.5 text-success`}):_(w,{className:`h-3.5 w-3.5 text-danger`}),_(`span`,{children:e.success?`Delivered`:`Failed`})]}),e.error&&_(`p`,{className:`mt-1 text-danger`,children:e.error}),t&&f(`dl`,{className:`mt-2 grid grid-cols-2 gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[_(`dt`,{children:`Resolved level`}),_(`dd`,{className:`text-foreground`,children:t.level}),_(`dt`,{children:`Format sent`}),_(`dd`,{className:`text-foreground`,children:t.format}),_(`dt`,{children:`Attachments sent`}),_(`dd`,{className:`text-foreground`,children:t.attachmentsSent}),_(`dt`,{children:`Actions sent`}),_(`dd`,{className:`text-foreground`,children:t.actionsSent}),_(`dt`,{children:`Truncated`}),_(`dd`,{className:`text-foreground`,children:t.truncated?`yes`:`no`}),_(`dt`,{children:`Dropped`}),_(`dd`,{className:`text-foreground`,children:t.dropped.length>0?t.dropped.join(`, `):`—`})]})]})}function G(e){let t=[],n=new Map;for(let r of e){let e=n.get(r.addonId);e?e.push(r):(n.set(r.addonId,[r]),t.push(r.addonId))}return t.map(e=>({addonId:e,kinds:n.get(e)??[]}))}function K(e){let t=[],n=e=>{for(let r of e){if(r.type===`password`){t.push(r.key);continue}if(r.type===`group`){n(r.fields);continue}if(r.type===`sub-tabs`)for(let e of r.tabs)n(e.fields)}};for(let t of e.sections)n(t.fields);return t}function q(e,t,n){let r=new Set(n),i={};for(let[n,a]of Object.entries(e)){if(!r.has(n)){i[n]=a;continue}a==null||a===``||a!==t[n]&&(i[n]=a)}return i}function J(e,t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))r[t]=n.has(t)?``:i;return r}d();var Y=[`notificationOutput`,`listTargets`],X=[`notificationOutput`,`listTargetKinds`];function Z({kind:e,imgClassName:t,fallbackClassName:n}){return e?.iconUrl?_(`img`,{src:e.iconUrl,alt:e.label,className:t,loading:`lazy`,draggable:!1}):_(`span`,{className:n,children:e?.icon??`🔔`})}function Q(){let t=v(),[r,a]=h({mode:`closed`}),[o,s]=h(null),c=m({queryKey:Y,queryFn:()=>t.trpcClient.notificationOutput.listTargets.query({})}),d=m({queryKey:X,queryFn:async()=>(await t.trpcClient.notificationOutput.listTargetKinds.query({})).map(e=>{let t=e.iconUrl;return{...e,configSchema:e.configSchema,iconUrl:t}})}),y=p(()=>d.data??[],[d.data]),S=p(()=>{let e=new Map;for(let t of y)e.set(t.kind,t);return e},[y]),w=g({mutationFn:e=>t.trpcClient.notificationOutput.setTargetEnabled.mutate({addonId:e.target.addonId,targetId:e.target.id,enabled:e.enabled}),onSuccess:()=>void c.refetch()}),k=g({mutationFn:e=>t.trpcClient.notificationOutput.deleteTarget.mutate({addonId:e.addonId,targetId:e.id}),onSuccess:()=>void c.refetch()}),A=o?S.get(o.kind):void 0;return f(O,{icon:E,title:`Notification Targets`,subtitle:`Deliver notifications to ntfy, Pushover, Telegram, Home Assistant and more. Each target's kind declares its capabilities; the test panel shows exactly what a message degrades to.`,actions:f(u,{size:`sm`,type:`button`,onClick:()=>a({mode:`pick-kind`}),children:[_(x,{className:`h-3.5 w-3.5`}),`Add target`]}),children:[c.isLoading&&_(`div`,{className:`flex items-center justify-center py-16`,children:_(T,{className:`h-6 w-6 animate-spin text-primary`})}),c.isError&&!c.isLoading&&_(e,{title:`Failed to load targets`,message:c.error instanceof Error?c.error.message:`Unknown error`,onRetry:()=>void c.refetch()}),!c.isLoading&&!c.isError&&(c.data??[]).length===0&&_(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No notification targets yet. Click "Add target" to configure one.`}),(c.data??[]).length>0&&_(n,{children:_(`ul`,{className:`divide-y divide-border`,children:(c.data??[]).map(e=>{let t=S.get(e.kind);return f(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[_(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface text-xs`,title:t?.label??e.kind,children:_(Z,{kind:t,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:``})}),f(`div`,{className:`min-w-0 flex-1`,children:[_(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),_(`div`,{className:`text-[11px] text-foreground-subtle`,children:t?.label??e.kind})]}),!e.enabled&&_(l,{variant:`warning`,children:`disabled`}),_(i,{checked:e.enabled,onCheckedChange:t=>w.mutate({target:e,enabled:t}),"aria-label":`toggle ${e.name}`}),_(u,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t,onClick:()=>s(e),title:`Test`,children:_(C,{className:`h-3.5 w-3.5`})}),_(u,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t,onClick:()=>t&&a({mode:`form`,kind:t,target:e}),title:`Edit`,children:_(b,{className:`h-3.5 w-3.5`})}),_(u,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>k.mutate(e),title:`Delete`,children:_(D,{className:`h-3.5 w-3.5 text-danger`})})]},e.id)})})}),r.mode===`pick-kind`&&_($,{kinds:y,onCancel:()=>a({mode:`closed`}),onPick:e=>a({mode:`form`,kind:e,target:null})}),r.mode===`form`&&_(ee,{kind:r.kind,target:r.target,onCancel:()=>a({mode:`closed`}),onSaved:()=>{a({mode:`closed`}),c.refetch()}}),o&&A&&_(U,{target:o,kind:A,open:!0,onClose:()=>s(null)})]})}function $({kinds:e,onPick:t,onCancel:r}){let i=p(()=>G(e),[e]);return f(n,{className:`p-4 space-y-4`,children:[f(`div`,{className:`flex items-center justify-between`,children:[_(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Choose a notification kind`}),_(u,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,children:`Cancel`})]}),i.length===0&&_(`p`,{className:`text-xs text-foreground-subtle`,children:`No notification providers are installed. Install the notifiers addon (or connect Home Assistant) to add targets.`}),i.map(e=>f(`div`,{children:[_(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5`,children:e.addonId}),_(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-2`,children:e.kinds.map(n=>f(`button`,{type:`button`,onClick:()=>t(n),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors`,children:[_(Z,{kind:n,imgClassName:`h-7 w-7 object-contain`,fallbackClassName:`text-lg leading-7`}),_(`span`,{className:`font-medium text-foreground`,children:n.label}),n.supportsDiscovery&&_(l,{variant:`info`,style:`outline`,children:`discover`})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]})}function ee({kind:e,target:r,onSaved:i,onCancel:a}){let o=v(),s=p(()=>K(e.configSchema),[e.configSchema]),c=p(()=>r?.config??{},[r]),[l,d]=h(r?.name??e.label),[m,y]=h(()=>r?J(r.config,s):{}),[b,x]=h(null),[C,w]=h(null),E=g({mutationFn:()=>o.trpcClient.notificationOutput.discoverTargets.query({addonId:e.addonId,kind:e.kind,config:m}),onSuccess:e=>x(e),onError:e=>w(e instanceof Error?e.message:`Discovery failed`)}),D=g({mutationFn:()=>{let t=q(m,c,s),n={id:r?.id??`${e.kind}-${Date.now()}`,name:l,kind:e.kind,addonId:e.addonId,enabled:r?.enabled??!0,config:t};return o.trpcClient.notificationOutput.upsertTarget.mutate({addonId:e.addonId,target:n})},onSuccess:i,onError:e=>w(e instanceof Error?e.message:`Save failed`)}),O=e=>{d(e.suggestedName),y(t=>({...t,...e.config})),x(null)};return f(n,{className:`p-4 space-y-4`,children:[f(`div`,{className:`flex items-center justify-between`,children:[f(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[_(Z,{kind:e,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:`text-lg`}),r?`Edit ${r.name}`:`Add ${e.label} target`]}),_(u,{size:`sm`,variant:`ghost`,type:`button`,onClick:a,children:`Cancel`})]}),C&&_(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:C}),f(`div`,{children:[_(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Name`}),_(`input`,{className:`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,value:l,onChange:e=>d(e.target.value)})]}),e.supportsDiscovery&&f(`div`,{className:`space-y-2`,children:[f(u,{size:`sm`,variant:`outline`,type:`button`,disabled:E.isPending,onClick:()=>{w(null),E.mutate()},children:[E.isPending?_(T,{className:`h-3.5 w-3.5 animate-spin`}):_(S,{className:`h-3.5 w-3.5`}),`Discover`]}),b&&b.length===0&&_(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No candidates discovered.`}),b&&b.length>0&&_(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:b.map((e,t)=>f(`button`,{type:`button`,onClick:()=>O(e),className:`flex w-full items-center justify-between px-3 py-1.5 text-xs hover:bg-surface-hover`,children:[_(`span`,{className:`text-foreground`,children:e.suggestedName}),_(`span`,{className:`text-[10px] text-primary`,children:`use`})]},`${e.suggestedName}-${t}`))})]}),s.length>0&&r&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Secret fields are hidden. Leave them blank to keep the stored value; type a new value to replace it.`}),_(t,{schema:e.configSchema,values:m,onChange:y}),f(`div`,{className:`flex justify-end gap-2`,children:[_(u,{variant:`secondary`,size:`sm`,type:`button`,onClick:a,children:`Cancel`}),f(u,{size:`sm`,type:`button`,disabled:D.isPending||l.trim().length===0,onClick:()=>{w(null),D.mutate()},children:[D.isPending&&_(T,{className:`h-3.5 w-3.5 animate-spin`}),r?`Save changes`:`Create target`]})]})]})}export{Q as NotificationTargetsPage,Q as default};
|
|
1
|
+
import{Ra as e,S as t,bo as n,do as r,go as i,ho as a,mo as o,po as s,uo as c,vo as l,yo as u}from"./src-CfZUxvPx.js";import{Q as d,S as f,W as p,a as m,q as h,t as g,x as _}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as v}from"./player-overlays-BfnV1C0Q.js";import{t as y}from"./circle-check-big-GmO5fdEl.js";import{t as b}from"./pencil-BkXeyiDf.js";import{t as x}from"./plus-DXXZ8pd7.js";import{t as S}from"./search-DkClo4ZA.js";import{t as C}from"./send-CeJ2J9V3.js";import{N as w,S as T,V as E,s as D}from"./index-Cjto-EXm.js";import{t as O}from"./AdminPage-BwmGKnRf.js";d();var k=e=>typeof e==`string`&&e.length>0;function A(e){return{levels:e.levels,formats:e.format,bodyMaxLen:e.bodyMaxLen,attachmentSlots:e.attachments.mediaTypes,attachmentMode:e.attachments.mode,attachmentMax:e.attachments.max,attachmentMaxBytes:e.attachments.maxBytes,maxActions:e.actions,showActions:e.actions>0,showClickUrl:e.clickUrl,showSound:e.sound,showTtl:e.ttl,showTag:!0}}function j(e,t){return e.format.includes(t)?t:e.format[0]??`text`}function M(e,t){let n=[];for(let r of e.attachments.mediaTypes){if(n.length>=e.attachments.max)break;let i=t[r];k(i)&&n.push({mediaType:r,url:i})}return n}function N(e,t){if(e.actions<=0)return[];let n=[];for(let r of t){if(n.length>=e.actions)break;let t=k(r.label),i=k(r.url);!t&&!i||n.push({id:`test-${n.length+1}`,label:t?r.label:`Action ${n.length+1}`,...i?{url:r.url}:{}})}return n}function P(e,t){let n=e.levels.some(e=>e.id===t.level)?t.level:void 0,r=M(e,t.attachmentUrls),i=N(e,t.actions),a=e.ttl&&k(t.ttl)?Number(t.ttl):void 0;return{body:t.body,format:j(e,t.format),priority:F(t.priority),...k(t.title)?{title:t.title}:{},...n?{level:n}:{},...r.length>0?{attachments:r}:{},...i.length>0?{actions:i}:{},...e.clickUrl&&k(t.clickUrl)?{clickUrl:t.clickUrl}:{},...e.sound&&k(t.sound)?{sound:t.sound}:{},...a!==void 0&&Number.isFinite(a)?{ttl:a}:{},...k(t.tag)?{tag:t.tag}:{}}}function F(e){return Number.isFinite(e)?Math.min(5,Math.max(1,Math.round(e))):3}function I(e){return e.levels.find(e=>e.flags?.critical===!0)||e.levels.filter(e=>typeof e.ordinal==`number`).sort((e,t)=>t.ordinal-e.ordinal)[0]}function L(e){return{level:``,priority:3,format:e.format[0]??`text`,title:``,body:``,attachmentUrls:{},actions:[],clickUrl:``,sound:``,ttl:``,tag:``}}var R={image:`https://example.com/sample.jpg`,video:`https://example.com/sample.mp4`,gif:`https://example.com/sample.gif`,audio:`https://example.com/sample.mp3`,icon:`https://example.com/icon.png`};function z(e,t){let n=L(e);switch(t){case`minimal`:return{...n,body:`Test notification`};case`overflow`:return{...n,body:`X`.repeat(e.bodyMaxLen+50)};case`critical`:{let t=I(e);return{...n,body:`Critical test notification`,priority:5,level:t?.id??``}}case`everything`:{let t={},n=0;for(let r of e.attachments.mediaTypes){if(n>=e.attachments.max)break;t[r]=R[r],n+=1}let r=Array.from({length:e.actions},(e,t)=>({label:`Action ${t+1}`,url:`https://example.com/action/${t+1}`}));return{level:``,priority:4,format:e.format.includes(`markdown`)?`markdown`:e.format.includes(`html`)?`html`:e.format[0]??`text`,title:`Everything the kind supports`,body:`This sample fills every control the kind advertises.`,attachmentUrls:t,actions:r,clickUrl:e.clickUrl?`https://example.com/open`:``,sound:e.sound?`default`:``,ttl:e.ttl?`3600`:``,tag:`camstack-test`}}}}var B=[{id:`minimal`,label:`Minimal (body only)`},{id:`everything`,label:`Everything supported`},{id:`overflow`,label:`Overflow`},{id:`critical`,label:`Critical`}],V=`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,H=`block text-[11px] font-medium text-foreground mb-1`;function U({target:e,kind:t,open:i,onClose:l}){let d=v(),m=p(()=>A(t.caps),[t.caps]),[y,b]=h(()=>L(t.caps)),[x,S]=h(null),w=p(()=>P(t.caps,y),[t.caps,y]),E=y.body.length,D=E>m.bodyMaxLen,O=e=>b(t=>({...t,...e})),k=g({mutationFn:()=>d.trpcClient.notificationOutput.testTarget.mutate({addonId:e.addonId,targetId:e.id,sample:P(t.caps,y)}),onMutate:()=>S(null),onSuccess:e=>S(e),onError:e=>S({success:!1,error:e instanceof Error?e.message:`Test failed`})}),j=e=>{b(z(t.caps,e)),S(null)},M=(e,t,n)=>{let r=y.actions.length>0?[...y.actions]:[];for(;r.length<=e;)r.push({label:``,url:``});r[e]={...r[e],[t]:n},O({actions:r})};return _(c,{open:i,onOpenChange:e=>!e&&l(),children:f(r,{width:`lg`,className:`!max-w-2xl`,children:[_(o,{children:f(a,{children:[`Test "`,e.name,`" (`,t.label,`)`]})}),f(`div`,{className:`space-y-4 max-h-[60vh] overflow-y-auto pr-1`,children:[_(`div`,{className:`flex flex-wrap gap-1.5`,children:B.map(e=>_(n,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>j(e.id),children:e.label},e.id))}),f(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m.levels.length>0&&f(`div`,{children:[_(`label`,{className:H,children:`Level`}),f(`select`,{className:V,value:y.level,onChange:e=>O({level:e.target.value}),children:[_(`option`,{value:``,children:`— derive from priority —`}),m.levels.map(e=>f(`option`,{value:e.id,children:[e.label,e.ordinal===null?` (qualitative)`:` (p${e.ordinal})`]},e.id))]}),(()=>{let e=m.levels.find(e=>e.id===y.level);return e?f(`div`,{className:`mt-1 space-y-1`,children:[e.description&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.description}),f(`div`,{className:`flex flex-wrap gap-1`,children:[e.flags?.critical&&_(u,{variant:`danger`,"data-testid":`flag-critical`,children:`critical`}),e.flags?.silent&&_(u,{variant:`info`,children:`silent`}),e.flags?.noPush&&_(u,{variant:`warning`,children:`no-push`})]}),e.requires&&e.requires.length>0&&f(`p`,{className:`text-[10px] text-warning`,children:[`Requires target config: `,e.requires.join(`, `)]})]}):null})()]}),f(`div`,{children:[f(`label`,{className:H,children:[`Priority (ordinal): `,y.priority]}),_(`input`,{type:`range`,min:1,max:5,step:1,value:y.priority,onChange:e=>O({priority:Number(e.target.value)}),className:`w-full accent-primary`,"aria-label":`priority`})]})]}),m.formats.length>0&&f(`div`,{children:[_(`label`,{className:H,children:`Format`}),_(`div`,{className:`flex flex-wrap gap-2`,children:m.formats.map(e=>f(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[_(`input`,{type:`radio`,name:`format`,className:`accent-primary`,checked:y.format===e,onChange:()=>O({format:e})}),e]},e))})]}),f(`div`,{children:[_(`label`,{className:H,children:`Title`}),_(`input`,{className:V,value:y.title,onChange:e=>O({title:e.target.value})})]}),f(`div`,{children:[f(`label`,{className:H,children:[`Body`,` `,f(`span`,{className:D?`text-danger`:`text-foreground-subtle`,children:[`(`,E,`/`,m.bodyMaxLen,D?` — overflow`:``,`)`]})]}),_(`textarea`,{className:`${V} min-h-[80px] resize-y`,value:y.body,onChange:e=>O({body:e.target.value})})]}),m.attachmentSlots.length>0&&f(`div`,{children:[f(`label`,{className:H,children:[`Attachments`,` `,f(`span`,{className:`text-foreground-subtle`,children:[`(mode: `,m.attachmentMode,`, max `,m.attachmentMax,m.attachmentMaxBytes?`, ≤${Math.round(m.attachmentMaxBytes/1024/1024)}MB`:``,`)`]})]}),_(`div`,{className:`space-y-1.5`,children:m.attachmentSlots.map(e=>f(`div`,{className:`flex items-center gap-2`,children:[_(`span`,{className:`text-[10px] w-12 shrink-0 text-foreground-subtle`,children:e}),_(`input`,{className:V,placeholder:`${e} URL`,value:y.attachmentUrls[e]??``,onChange:t=>O({attachmentUrls:{...y.attachmentUrls,[e]:t.target.value}})})]},e))})]}),m.showActions&&f(`div`,{children:[f(`label`,{className:H,children:[`Actions (up to `,m.maxActions,`)`]}),_(`div`,{className:`space-y-1.5`,children:Array.from({length:Math.min(m.maxActions,3)},(e,t)=>f(`div`,{className:`flex items-center gap-2`,children:[_(`input`,{className:V,placeholder:`label`,value:y.actions[t]?.label??``,onChange:e=>M(t,`label`,e.target.value)}),_(`input`,{className:V,placeholder:`url`,value:y.actions[t]?.url??``,onChange:e=>M(t,`url`,e.target.value)})]},t))})]}),f(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m.showClickUrl&&f(`div`,{children:[_(`label`,{className:H,children:`Click URL`}),_(`input`,{className:V,value:y.clickUrl,onChange:e=>O({clickUrl:e.target.value})})]}),m.showSound&&f(`div`,{children:[_(`label`,{className:H,children:`Sound`}),_(`input`,{className:V,value:y.sound,onChange:e=>O({sound:e.target.value})})]}),m.showTtl&&f(`div`,{children:[_(`label`,{className:H,children:`TTL (seconds)`}),_(`input`,{className:V,type:`number`,value:y.ttl,onChange:e=>O({ttl:e.target.value})})]}),m.showTag&&f(`div`,{children:[_(`label`,{className:H,children:`Tag`}),_(`input`,{className:V,value:y.tag,onChange:e=>O({tag:e.target.value})})]})]}),x&&_(W,{result:x}),f(`details`,{className:`text-[10px]`,children:[_(`summary`,{className:`cursor-pointer text-foreground-subtle`,children:`Payload preview`}),_(`pre`,{className:`mt-1 overflow-x-auto rounded bg-surface p-2 text-foreground-subtle`,children:JSON.stringify(w,null,2)})]})]}),f(s,{children:[_(n,{variant:`secondary`,size:`sm`,type:`button`,onClick:l,children:`Close`}),f(n,{size:`sm`,type:`button`,disabled:k.isPending||y.body.length===0,onClick:()=>k.mutate(),children:[k.isPending?_(T,{className:`h-3.5 w-3.5 animate-spin`}):_(C,{className:`h-3.5 w-3.5`}),`Send test`]})]})]})})}function W({result:e}){let t=e.renderedAs;return f(`div`,{className:`rounded-md border px-3 py-2 text-xs ${e.success?`border-success/40 bg-success/10`:`border-danger/40 bg-danger/10`}`,"data-testid":`test-result`,children:[f(`div`,{className:`flex items-center gap-2 font-medium`,children:[e.success?_(y,{className:`h-3.5 w-3.5 text-success`}):_(w,{className:`h-3.5 w-3.5 text-danger`}),_(`span`,{children:e.success?`Delivered`:`Failed`})]}),e.error&&_(`p`,{className:`mt-1 text-danger`,children:e.error}),t&&f(`dl`,{className:`mt-2 grid grid-cols-2 gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[_(`dt`,{children:`Resolved level`}),_(`dd`,{className:`text-foreground`,children:t.level}),_(`dt`,{children:`Format sent`}),_(`dd`,{className:`text-foreground`,children:t.format}),_(`dt`,{children:`Attachments sent`}),_(`dd`,{className:`text-foreground`,children:t.attachmentsSent}),_(`dt`,{children:`Actions sent`}),_(`dd`,{className:`text-foreground`,children:t.actionsSent}),_(`dt`,{children:`Truncated`}),_(`dd`,{className:`text-foreground`,children:t.truncated?`yes`:`no`}),_(`dt`,{children:`Dropped`}),_(`dd`,{className:`text-foreground`,children:t.dropped.length>0?t.dropped.join(`, `):`—`})]})]})}function G(e){let t=[],n=new Map;for(let r of e){let e=n.get(r.addonId);e?e.push(r):(n.set(r.addonId,[r]),t.push(r.addonId))}return t.map(e=>({addonId:e,kinds:n.get(e)??[]}))}function K(e){let t=[],n=e=>{for(let r of e){if(r.type===`password`){t.push(r.key);continue}if(r.type===`group`){n(r.fields);continue}if(r.type===`sub-tabs`)for(let e of r.tabs)n(e.fields)}};for(let t of e.sections)n(t.fields);return t}function q(e,t,n){let r=new Set(n),i={};for(let[n,a]of Object.entries(e)){if(!r.has(n)){i[n]=a;continue}a==null||a===``||a!==t[n]&&(i[n]=a)}return i}function J(e,t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))r[t]=n.has(t)?``:i;return r}d();var Y=[`notificationOutput`,`listTargets`],X=[`notificationOutput`,`listTargetKinds`];function Z({kind:e,imgClassName:t,fallbackClassName:n}){return e?.iconUrl?_(`img`,{src:e.iconUrl,alt:e.label,className:t,loading:`lazy`,draggable:!1}):_(`span`,{className:n,children:e?.icon??`🔔`})}function Q(){let t=v(),[r,a]=h({mode:`closed`}),[o,s]=h(null),c=m({queryKey:Y,queryFn:()=>t.trpcClient.notificationOutput.listTargets.query({})}),d=m({queryKey:X,queryFn:async()=>(await t.trpcClient.notificationOutput.listTargetKinds.query({})).map(e=>{let t=e.iconUrl;return{...e,configSchema:e.configSchema,iconUrl:t}})}),y=p(()=>d.data??[],[d.data]),S=p(()=>{let e=new Map;for(let t of y)e.set(t.kind,t);return e},[y]),w=g({mutationFn:e=>t.trpcClient.notificationOutput.setTargetEnabled.mutate({addonId:e.target.addonId,targetId:e.target.id,enabled:e.enabled}),onSuccess:()=>void c.refetch()}),k=g({mutationFn:e=>t.trpcClient.notificationOutput.deleteTarget.mutate({addonId:e.addonId,targetId:e.id}),onSuccess:()=>void c.refetch()}),A=o?S.get(o.kind):void 0;return f(O,{icon:E,title:`Notification Targets`,subtitle:`Deliver notifications to ntfy, Pushover, Telegram, Home Assistant and more. Each target's kind declares its capabilities; the test panel shows exactly what a message degrades to.`,actions:f(n,{size:`sm`,type:`button`,onClick:()=>a({mode:`pick-kind`}),children:[_(x,{className:`h-3.5 w-3.5`}),`Add target`]}),children:[c.isLoading&&_(`div`,{className:`flex items-center justify-center py-16`,children:_(T,{className:`h-6 w-6 animate-spin text-primary`})}),c.isError&&!c.isLoading&&_(e,{title:`Failed to load targets`,message:c.error instanceof Error?c.error.message:`Unknown error`,onRetry:()=>void c.refetch()}),!c.isLoading&&!c.isError&&(c.data??[]).length===0&&_(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No notification targets yet. Click "Add target" to configure one.`}),(c.data??[]).length>0&&_(l,{children:_(`ul`,{className:`divide-y divide-border`,children:(c.data??[]).map(e=>{let t=S.get(e.kind);return f(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[_(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface text-xs`,title:t?.label??e.kind,children:_(Z,{kind:t,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:``})}),f(`div`,{className:`min-w-0 flex-1`,children:[_(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),_(`div`,{className:`text-[11px] text-foreground-subtle`,children:t?.label??e.kind})]}),!e.enabled&&_(u,{variant:`warning`,children:`disabled`}),_(i,{checked:e.enabled,onCheckedChange:t=>w.mutate({target:e,enabled:t}),"aria-label":`toggle ${e.name}`}),_(n,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t,onClick:()=>s(e),title:`Test`,children:_(C,{className:`h-3.5 w-3.5`})}),_(n,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t,onClick:()=>t&&a({mode:`form`,kind:t,target:e}),title:`Edit`,children:_(b,{className:`h-3.5 w-3.5`})}),_(n,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>k.mutate(e),title:`Delete`,children:_(D,{className:`h-3.5 w-3.5 text-danger`})})]},e.id)})})}),r.mode===`pick-kind`&&_($,{kinds:y,onCancel:()=>a({mode:`closed`}),onPick:e=>a({mode:`form`,kind:e,target:null})}),r.mode===`form`&&_(ee,{kind:r.kind,target:r.target,onCancel:()=>a({mode:`closed`}),onSaved:()=>{a({mode:`closed`}),c.refetch()}}),o&&A&&_(U,{target:o,kind:A,open:!0,onClose:()=>s(null)})]})}function $({kinds:e,onPick:t,onCancel:r}){let i=p(()=>G(e),[e]);return f(l,{className:`p-4 space-y-4`,children:[f(`div`,{className:`flex items-center justify-between`,children:[_(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Choose a notification kind`}),_(n,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,children:`Cancel`})]}),i.length===0&&_(`p`,{className:`text-xs text-foreground-subtle`,children:`No notification providers are installed. Install the notifiers addon (or connect Home Assistant) to add targets.`}),i.map(e=>f(`div`,{children:[_(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5`,children:e.addonId}),_(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-2`,children:e.kinds.map(n=>f(`button`,{type:`button`,onClick:()=>t(n),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors`,children:[_(Z,{kind:n,imgClassName:`h-7 w-7 object-contain`,fallbackClassName:`text-lg leading-7`}),_(`span`,{className:`font-medium text-foreground`,children:n.label}),n.supportsDiscovery&&_(u,{variant:`info`,style:`outline`,children:`discover`})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]})}function ee({kind:e,target:r,onSaved:i,onCancel:a}){let o=v(),s=p(()=>K(e.configSchema),[e.configSchema]),c=p(()=>r?.config??{},[r]),[u,d]=h(r?.name??e.label),[m,y]=h(()=>r?J(r.config,s):{}),[b,x]=h(null),[C,w]=h(null),E=g({mutationFn:()=>o.trpcClient.notificationOutput.discoverTargets.query({addonId:e.addonId,kind:e.kind,config:m}),onSuccess:e=>x(e),onError:e=>w(e instanceof Error?e.message:`Discovery failed`)}),D=g({mutationFn:()=>{let t=q(m,c,s),n={id:r?.id??`${e.kind}-${Date.now()}`,name:u,kind:e.kind,addonId:e.addonId,enabled:r?.enabled??!0,config:t};return o.trpcClient.notificationOutput.upsertTarget.mutate({addonId:e.addonId,target:n})},onSuccess:i,onError:e=>w(e instanceof Error?e.message:`Save failed`)}),O=e=>{d(e.suggestedName),y(t=>({...t,...e.config})),x(null)};return f(l,{className:`p-4 space-y-4`,children:[f(`div`,{className:`flex items-center justify-between`,children:[f(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[_(Z,{kind:e,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:`text-lg`}),r?`Edit ${r.name}`:`Add ${e.label} target`]}),_(n,{size:`sm`,variant:`ghost`,type:`button`,onClick:a,children:`Cancel`})]}),C&&_(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:C}),f(`div`,{children:[_(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Name`}),_(`input`,{className:`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,value:u,onChange:e=>d(e.target.value)})]}),e.supportsDiscovery&&f(`div`,{className:`space-y-2`,children:[f(n,{size:`sm`,variant:`outline`,type:`button`,disabled:E.isPending,onClick:()=>{w(null),E.mutate()},children:[E.isPending?_(T,{className:`h-3.5 w-3.5 animate-spin`}):_(S,{className:`h-3.5 w-3.5`}),`Discover`]}),b&&b.length===0&&_(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No candidates discovered.`}),b&&b.length>0&&_(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:b.map((e,t)=>f(`button`,{type:`button`,onClick:()=>O(e),className:`flex w-full items-center justify-between px-3 py-1.5 text-xs hover:bg-surface-hover`,children:[_(`span`,{className:`text-foreground`,children:e.suggestedName}),_(`span`,{className:`text-[10px] text-primary`,children:`use`})]},`${e.suggestedName}-${t}`))})]}),s.length>0&&r&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Secret fields are hidden. Leave them blank to keep the stored value; type a new value to replace it.`}),_(t,{schema:e.configSchema,values:m,onChange:y}),f(`div`,{className:`flex justify-end gap-2`,children:[_(n,{variant:`secondary`,size:`sm`,type:`button`,onClick:a,children:`Cancel`}),f(n,{size:`sm`,type:`button`,disabled:D.isPending||u.trim().length===0,onClick:()=>{w(null),D.mutate()},children:[D.isPending&&_(T,{className:`h-3.5 w-3.5 animate-spin`}),r?`Save changes`:`Create target`]})]})]})}export{Q as NotificationTargetsPage,Q as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{$r as e,Ci as t,Ei as n,Eo as r,Ha as i,Ii as a,La as o,Mi as s,Ni as c,Pi as l,Qr as u,Si as d,T as f,To as p,Ua as m,Va as h,Vr as g,Wa as _,_ as v,_i as y,ai as b,bi as x,ci as S,di as C,ei as w,ft as T,g as E,gi as D,ii as O,ji as k,li as A,lt as j,mi as M,ni as N,oi as ee,ri as te,si as ne,ti as re,ut as P,vi as ie,wi as ae,xi as oe,yi as se,yo as ce}from"./src-CfZUxvPx.js";import{I as le,K as ue,Q as F,S as I,T as de,W as L,b as R,o as z,q as B,x as V,z as H}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{G as fe,K as pe,X as me}from"./src-CCZM6rtM.js";import{c as he,o as ge,r as _e,s as ve,t as ye}from"./NodeInferenceDevices-CoLAPH96.js";import{t as be}from"./download-CJ-1cdDh.js";import{i as xe}from"./AddLocationWizard-VuBsssbs.js";import{n as Se,r as Ce,t as we}from"./zap-d6IKZFEN.js";import{t as Te}from"./pencil-BkXeyiDf.js";import{t as Ee}from"./plus-DXXZ8pd7.js";import{t as De}from"./radio-CGyv3voN.js";import{t as Oe}from"./refresh-cw-DC4KMLsa.js";import{t as ke}from"./search-DkClo4ZA.js";import{t as Ae}from"./server-CArIZ-KL.js";import{t as je}from"./square-check-big--y441eG8.js";import{t as Me}from"./square-BFjZ9GUs.js";import{E as Ne,I as Pe,J as Fe,L as Ie,M as Le,N as Re,P as ze,S as U,T as Be,W as Ve,i as He,j as W,o as Ue,s as We}from"./index-Cjto-EXm.js";import{t as Ge}from"./AdminPage-BwmGKnRf.js";import{t as G}from"./useEventInvalidation-DxjiYIcd.js";import{r as Ke,t as qe}from"./build-cluster-graph-C1vd_7m_.js";import{n as Je}from"./format-size-CO9d3C3-.js";import{t as Ye}from"./NodeAddonsSettingsPanel-PSaY411C.js";import{n as Xe,t as Ze}from"./ClusterRecordingTab-qj7qdRav.js";var Qe=Ve(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),$e=Ve(`flame`,[[`path`,{d:`M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z`,key:`96xj49`}]]),et=Ve(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]);F();function tt(e){return e}function nt(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function rt(e,t){return typeof e==`boolean`?e:tt(t)}function it(e,t){return{pipeline:rt(nt(e,`detect`),t),audio:rt(nt(e,`audio`),t),ingest:rt(nt(e,`ingest`),t)}}function at(e,t,n){let r=e?.find(e=>e.nodeId===t);return it(r?.settings,n)}function ot({selectedNodeId:e,onSelect:t,refreshToken:n}){let{data:i}=g(void 0),{data:a}=D(void 0),{data:o}=ie(void 0),s=new Map;for(let e of a??[])s.set(e.agentNodeId,(s.get(e.agentNodeId)??0)+1);let c=i??[],l=c.filter(e=>e.isOnline).length,u=c.filter(e=>!e.isOnline).length;return I(`div`,{className:`flex flex-col h-full`,children:[I(`button`,{type:`button`,onClick:()=>t(ur),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[V(Be,{className:`h-4 w-4 flex-shrink-0`}),I(`div`,{className:`min-w-0 flex-1`,children:[V(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),V(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),V(`div`,{className:`flex-1 overflow-y-auto`,children:c.map(n=>{let i=e===n.id,a=s.get(n.id)??0,c=n.isHub?Ae:W,l=at(o,n.id,n.isHub),u=n.isOnline?null:r(Ke(n.lastSeen));return I(`button`,{type:`button`,onClick:()=>t(n.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${i?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${n.isOnline?``:` opacity-60`}`,children:[V(c,{className:`h-4 w-4 flex-shrink-0`}),I(`div`,{className:`min-w-0 flex-1`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&V(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&V(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),n.isOnline&&V(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),I(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[I(`span`,{children:[n.cpuCores,` cores`]}),V(`span`,{children:`•`}),I(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),a>0&&I(R,{children:[V(`span`,{children:`•`}),I(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[V(Se,{className:`h-2.5 w-2.5`}),a]})]}),!n.isOnline&&I(R,{children:[V(`span`,{children:`•`}),I(`span`,{className:`text-destructive`,children:[`offline`,u===null?``:` · ${u}`]})]})]}),I(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[V(ce,{variant:l.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:l.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),V(ce,{variant:l.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:l.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},n.id)})}),I(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[I(`span`,{children:[l,` online`]}),u>0&&I(`span`,{className:`text-destructive`,children:[u,` offline`]})]})]})}function st({nodeId:e,refreshToken:t}){let{data:n}=g(void 0),r=n?.find(t=>t.id===e),a=i(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return r?I(`div`,{className:`px-6 py-4 border-b border-border`,children:[I(`div`,{className:`flex items-center gap-2 mb-1`,children:[V(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?V(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):V(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),r.isHub&&V(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),I(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[V(`span`,{children:r.cpuModel??`CPU`}),V(`span`,{children:`•`}),I(`span`,{children:[r.cpuCores,` cores`]}),V(`span`,{children:`•`}),I(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),a&&I(R,{children:[V(`span`,{children:`•`}),I(`span`,{children:[a.attachedCameras,` cameras (`,a.activeCameras,` active)`]}),V(`span`,{children:`•`}),I(`span`,{children:[a.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),V(`span`,{children:`•`}),I(`span`,{children:[`queue `,a.queueDepthTotal]}),a.hardware.hasGpu&&I(R,{children:[V(`span`,{children:`•`}),V(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):V(`div`,{className:`px-6 py-4 border-b border-border`,children:I(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}function ct({refreshToken:e,nodeId:t}){let[n,r]=B(new Map),{nodes:i}=h();_(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&r(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:a}=A(void 0),o=L(()=>{let e=new Map;for(let t of a??[])e.set(t.nodeId,t.deviceCount);return e},[a]),s=L(()=>{let e=new Map,t=Date.now()-3e4;for(let r of n.values()){if(r.timestamp<t)continue;let n=r.nodeId??`hub`,i=e.get(n)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,r.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=r.metrics.actualFps,i.totalInferenceWeighted+=r.metrics.avgInferenceTimeMs,i.queueDepth+=r.metrics.queueDepth,e.set(n,i)}return e},[n]),c=L(()=>{let e=new Map;for(let t of i)e.set(t.id,t.shortName);return e},[i]),l=L(()=>{let e=0,t=0,n=0,r=0,a=0;for(let i of s.values())e+=i.attachedCameras,t+=i.activeCameras,n+=i.totalFps,r+=i.totalInferenceWeighted,a+=i.queueDepth;let o=e>0?r/e:0;return{totalAgents:i.length,onlineAgents:i.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:o,queueDepth:a,totalFps:n}},[s,i]);if(t){let e=s.get(t);return I(`div`,{className:`@container/liveload`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),I(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[V(K,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),V(K,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),V(K,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),V(K,{label:`Queue`,value:e?String(e.queueDepth):`—`}),V(K,{label:`Audio`,value:String(o.get(t)??`—`)})]})]})}let u=[...s.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return I(`div`,{className:`@container/liveload`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),I(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[V(K,{label:`Total agents`,value:`${l.onlineAgents}/${l.totalAgents}`}),V(K,{label:`Active / Attached`,value:`${l.activeCameras}/${l.attachedCameras}`}),V(K,{label:`Total FPS`,value:l.totalFps.toFixed(1)}),V(K,{label:`Avg inference ms`,value:l.avgInferenceTimeMs.toFixed(0)}),V(K,{label:`Queue depth`,value:String(l.queueDepth)})]}),V(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:I(`table`,{className:`w-full text-xs min-w-[480px]`,children:[V(`thead`,{className:`bg-surface`,children:I(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[V(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),V(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),V(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),V(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),V(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),V(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),I(`tbody`,{children:[u.map(([e,t])=>I(`tr`,{className:`border-t border-border`,children:[V(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:c.get(e)??e}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:o.get(e)??`—`})]},e)),u.length===0&&V(`tr`,{children:V(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function K({label:e,value:t}){return I(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[V(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),V(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}F();var lt={active:!1,pinned:!1,nodeId:null,reason:``},ut=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`],dt={pipeline:W,decoder:Ne,audio:Ce},ft={pipeline:`Pipeline`,decoder:`Decoder`,audio:`Audio`};function pt({mode:e,nodeId:t,compact:n=!1}){if(e===`agent`&&!t)throw Error(`CameraAssignmentsTable: nodeId is required when mode === "agent"`);let r=z(),[i,a]=B(null),[o,l]=B(null),[u,d]=B(new Map);G([`pipelineOrchestrator`,`getPipelineAssignments`],ut),G([`pipelineOrchestrator`,`getAudioAssignments`],ut),G([`pipelineOrchestrator`,`getCameraStatuses`],ut);let{data:p}=D(void 0),{data:m}=S(void 0),{data:g}=C({},{enabled:e===`agent`}),{nodes:v}=h(),{data:y}=ge();_(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&d(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),H(()=>{if(u.size===0)return;let e=setInterval(()=>{d(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[u.size]);let x=L(()=>{let e=new Map;for(let t of y??[])e.set(t.id,t.name);return e},[y]),w=L(()=>{if(e===`agent`){let e=[];for(let n of g??[]){let r=n.assignment,i=(e,n,r)=>({active:e!==null&&e===t,pinned:n,nodeId:e,reason:r??``}),a=i(r.detectionNodeId,r.pinned.detection,r.reasons.detection),o=i(r.decoderNodeId,r.pinned.decoder,r.reasons.decoder),s=i(r.audioNodeId,r.pinned.audio,r.reasons.audio);!a.active&&!o.active&&!s.active||e.push({deviceId:n.deviceId,deviceName:x.get(n.deviceId)??`Device ${n.deviceId}`,pipeline:a,decoder:o,audio:s})}return e.sort((e,t)=>e.deviceId-t.deviceId),e}let n=new Map,r=e=>{let t=n.get(e);if(t)return t;let r={deviceId:e,deviceName:x.get(e)??`Device ${e}`,pipeline:lt,decoder:lt,audio:lt};return n.set(e,r),r};for(let i of p??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,pipeline:{active:!0,pinned:i.pinned,nodeId:i.agentNodeId,reason:i.reason??``},decoder:{active:e===`cluster`?!0:i.agentNodeId===t,pinned:!1,nodeId:i.agentNodeId,reason:`co-located`}})}for(let e of m??[]){let t=r(e.deviceId);n.set(e.deviceId,{...t,audio:{active:!0,pinned:e.pinned,nodeId:e.nodeId,reason:`capacity`}})}let i=[...n.values()];return i.sort((e,t)=>e.deviceId-t.deviceId),i},[p,m,g,x,e,t]),T=L(()=>(v??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[v]),E=()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},O=ee({onSuccess:E}),k=c({onSuccess:E}),A=b({onSuccess:E}),j=s({onSuccess:E}),M=(e,t,n)=>{t===`pipeline`?O.mutate({deviceId:e,agentNodeId:n}):A.mutate({deviceId:e,nodeId:n}),a(null)},N=(e,t)=>{t===`pipeline`?k.mutate({deviceId:e}):j.mutate({deviceId:e}),a(null)};return V(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:I(`table`,{className:`w-full text-xs min-w-[760px] table-fixed`,children:[V(`thead`,{className:`bg-surface`,children:I(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!n&&V(`th`,{className:`w-10`}),V(`th`,{className:`min-w-[200px] text-left px-3 py-2 align-middle`,children:`Camera`}),e===`cluster`?I(R,{children:[V(`th`,{className:`w-[168px] text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),V(`th`,{className:`w-[188px] text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):I(R,{children:[V(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Pipeline`}),V(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Decoder`}),V(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Audio`})]}),V(`th`,{className:`w-[132px] text-left px-3 py-2 align-middle`,children:`Status`})]})}),I(`tbody`,{children:[w.map(t=>{let r=u.get(t.deviceId),s=o===t.deviceId;return I(de.Fragment,{children:[I(`tr`,{className:`border-t border-border align-middle relative`,children:[!n&&V(`td`,{className:`px-2 py-2 align-middle`,children:V(`button`,{type:`button`,onClick:()=>l(s?null:t.deviceId),className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":s?`Collapse broker details`:`Expand broker details`,children:V(s?Pe:ze,{className:`h-3.5 w-3.5`})})}),I(`td`,{className:`px-3 py-2 align-middle min-w-0`,children:[V(`div`,{className:`text-foreground font-medium leading-tight line-clamp-2 break-words`,title:t.deviceName,children:t.deviceName}),I(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),e===`cluster`?I(R,{children:[V(`td`,{className:`px-3 py-2 align-middle`,children:V(ht,{state:t.pipeline,onlineNodes:T,pending:O.isPending||k.isPending,onChange:e=>{e===`auto`?N(t.deviceId,`pipeline`):M(t.deviceId,`pipeline`,e)}})}),V(`td`,{className:`px-3 py-2 align-middle`,children:V(gt,{state:t.pipeline})})]}):I(R,{children:[V(_t,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:T,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`pipeline`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`pipeline`?null:{deviceId:t.deviceId,role:`pipeline`}),onCloseMenu:()=>a(null),onMove:e=>M(t.deviceId,`pipeline`,e),onUnpin:()=>N(t.deviceId,`pipeline`)}),V(_t,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:T,readOnly:!0,isMenuOpen:!1,onToggleMenu:()=>void 0,onCloseMenu:()=>void 0,onMove:()=>void 0,onUnpin:()=>void 0}),V(_t,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:T,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`audio`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`audio`?null:{deviceId:t.deviceId,role:`audio`}),onCloseMenu:()=>a(null),onMove:e=>M(t.deviceId,`audio`,e),onUnpin:()=>N(t.deviceId,`audio`)})]}),V(`td`,{className:`px-3 py-2 align-middle`,children:V(xt,{snap:r})})]}),s&&!n&&I(`tr`,{className:`bg-surface/50`,children:[V(`td`,{}),I(`td`,{colSpan:e===`cluster`?4:5,className:`px-3 py-2 space-y-3`,children:[t.pipeline.nodeId&&V(mt,{deviceId:t.deviceId,nodeId:t.pipeline.nodeId}),V(f,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:t.deviceId,instanceId:`pipeline-row/${t.deviceId}`,config:{variant:`compact`,title:`Stream brokers & clients`}})]})]})]},t.deviceId)}),w.length===0&&V(`tr`,{children:V(`td`,{colSpan:n?e===`cluster`?4:5:e===`cluster`?5:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:e===`agent`?`No cameras assigned to this node`:`No cameras currently assigned`})})]})]})})}function mt({deviceId:e,nodeId:t}){let n=z(),{data:r}=M({nodeId:t}),{data:i}=y({deviceId:e}),a=k({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}}),o=r?.devices??[],s=i?.deviceKey??`auto`,c=s!==`auto`&&!o.some(e=>e.key===s);return I(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[V(`span`,{className:`shrink-0 font-medium text-foreground`,children:`Inference device`}),I(`select`,{value:s,disabled:a.isPending,"aria-label":`Inference device pin`,onChange:t=>a.mutate({deviceId:e,deviceKey:t.target.value}),className:`rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[V(`option`,{value:`auto`,children:`Auto (balanced)`}),c&&I(`option`,{value:s,children:[`Pin → `,s,` (not on this node)`]}),o.map(e=>I(`option`,{value:e.key,children:[`Pin → `,e.key,e.available?``:` (unavailable)`]},e.key))]}),a.isPending&&V(`span`,{className:`text-[10px] opacity-70`,children:`saving…`})]})}function ht({state:e,onlineNodes:t,pending:n,onChange:r}){let i=e.pinned&&e.nodeId?e.nodeId:`auto`,a=[...new Set([...e.nodeId?[e.nodeId]:[],...t.map(e=>e.id)])];return I(`select`,{value:i,disabled:n,"aria-label":`Pipeline placement pin`,onChange:e=>r(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[V(`option`,{value:`auto`,children:`Auto`}),a.map(e=>I(`option`,{value:e,children:[`Pin → `,t.find(t=>t.id===e)?.name??e]},e))]})}function gt({state:e}){if(!e.active||!e.nodeId)return V(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`});let t=e.pinned?`pinned · manual`:`auto · ${e.reason||`capacity`}`;return I(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[V(`span`,{className:`font-mono text-[11px] text-foreground truncate`,title:e.nodeId,children:e.nodeId}),V(`span`,{className:`truncate ${e.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`}`,title:t,children:t})]})}function _t({role:e,state:t,mode:n,onlineNodes:r,readOnly:i=!1,isMenuOpen:a,onToggleMenu:o,onCloseMenu:s,onMove:c,onUnpin:l}){let u=dt[e],d=r.filter(e=>e.id!==(t.nodeId??``)),f=!i&&(t.active||n===`cluster`)&&(d.length>0||t.pinned);return I(`td`,{className:`px-3 py-2 align-middle relative min-w-0`,children:[I(`div`,{className:`flex items-center gap-2 min-w-0`,children:[V(n===`agent`?vt:yt,{state:t,Icon:u}),V(`div`,{className:`ml-auto shrink-0`,children:f&&V(`button`,{type:`button`,onClick:o,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${ft[e]} actions`,children:V(Qe,{className:`h-3 w-3 text-foreground-subtle`})})})]}),a&&f&&V(St,{title:ft[e],targets:d,pinned:t.pinned,onMove:c,onUnpin:l,onClose:s})]})}function vt({state:e,Icon:t}){return I(`div`,{className:`flex items-center gap-1.5`,children:[V(e.active?je:Me,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),V(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&V(et,{className:`h-2.5 w-2.5 text-amber-400`})]})}function yt({state:e,Icon:t}){return!e.active||!e.nodeId?I(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[V(t,{className:`h-3 w-3`}),V(`span`,{className:`text-[10px] italic`,children:`—`})]}):I(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[V(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),I(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[V(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),V(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?I(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[V(et,{className:`h-2.5 w-2.5`}),` manual`]}):I(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}var bt=`min-h-[3.25rem]`;function xt({snap:e}){if(!e)return V(`div`,{className:`flex items-center ${bt}`,children:V(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`})});let{phase:t,actualFps:n,avgInferenceTimeMs:r,queueDepth:i,configuredFps:a,droppedFrames:o}=e.metrics,s=p(t);return I(`div`,{className:`flex flex-col justify-center gap-0.5 font-mono text-[10px] tabular-nums leading-tight min-w-0 ${bt}`,children:[I(`span`,{className:`inline-flex items-center gap-1 min-w-0 ${s.textColor}`,children:[V(v,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),V(`span`,{className:`font-semibold uppercase tracking-wider truncate`,children:s.label})]}),I(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[V(`span`,{className:`text-foreground`,children:n.toFixed(1)}),I(`span`,{children:[`/`,a.toFixed(0),` fps`]})]}),I(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[V(`span`,{className:`text-foreground`,children:r.toFixed(0)}),V(`span`,{children:` ms`}),i>0&&I(`span`,{className:`text-warning ml-1`,children:[`q`,i]})]}),I(`span`,{className:`whitespace-nowrap truncate ${o>0?`text-warning`:`text-foreground-subtle`}`,children:[`drops `,V(`span`,{className:`text-foreground`,children:o})]})]})}function St({title:e,targets:t,pinned:n,onMove:r,onUnpin:i,onClose:a}){let o=ue(null);return H(()=>{let e=e=>{o.current?.contains(e.target)||a()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[a]),I(`div`,{ref:o,className:`absolute right-2 top-full mt-1 w-48 rounded-lg border border-border bg-surface shadow-lg z-20 text-left`,children:[V(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:e}),t.length>0&&V(`div`,{className:`py-1`,children:t.map(e=>I(`button`,{type:`button`,onClick:()=>r(e.id),className:`block w-full text-left px-3 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[`Move to `,e.name]},e.id))}),n&&I(`button`,{type:`button`,onClick:i,className:`block w-full text-left px-3 py-1.5 text-[11px] text-destructive hover:bg-destructive/10 border-t border-border`,children:[`Unpin `,e.toLowerCase()]}),t.length===0&&!n&&V(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function Ct({nodeId:e,refreshToken:t}){return I(`div`,{className:`space-y-6`,children:[V(ct,{refreshToken:t,nodeId:e}),I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),I(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Checkboxes mark the roles currently running on `,e,`. Use the kebab to move a role to another node or unpin it; live KPIs come from the runner snapshot stream.`]})]}),V(pt,{mode:`agent`,nodeId:e,compact:!0})]})}F();function wt(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function Tt({nodeId:e,refreshToken:t}){let n=z(),r=te({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:o}=O({nodeId:e}),s=i(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??o??null,c=s===null;G([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:l}=a({nodeId:e}),{values:u}=m(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),d=L(()=>u.filter(e=>e.metrics.phase===`active`).length,[u]),f=t=>{let n=l??[];n.length>0&&!window.confirm(`${n.length} camera(s) are dispatching through this engine. Killing it forces a respawn on the next frame. Continue?`)||r.mutate({nodeId:e,engine:t,force:n.length>0})};return I(`div`,{className:`space-y-6`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),I(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(s??[]).length,` engine(s) resident in RAM. `,(l??[]).length,` `,`camera(s) attached, `,d,` actively dispatching frames. Refreshes every 5s.`]})]}),V(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:I(`table`,{className:`w-full text-xs min-w-[640px]`,children:[V(`thead`,{className:`bg-surface`,children:I(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[V(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),V(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),V(`th`,{className:`text-left px-3 py-2`,children:`Models`}),V(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),V(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),V(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),V(`th`,{className:`w-20`})]})}),I(`tbody`,{children:[c&&V(`tr`,{children:V(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!c&&(s??[]).map(e=>{let t=e.kind===`warm-override`,n=e.kind===`device-pool`;return I(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:n?`bg-primary/[0.05]`:``}`,children:[V(`td`,{className:`px-3 py-2`,children:I(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-amber-500/15 text-amber-400`:n?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[V(t?$e:n?he:W,{className:`h-3 w-3`}),t?`warm`:n?`pool`:`runtime`]})}),V(`td`,{className:`px-3 py-2`,children:I(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[V(we,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),V(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?V(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):V(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>V(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),V(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),V(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?V(`span`,{className:`text-foreground-subtle`,children:wt(e.idleMs,e.idleTtlMs)}):V(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(l??[]).length}),V(`td`,{className:`px-3 py-2 text-right`,children:n?V(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):I(`button`,{type:`button`,disabled:r.isPending,onClick:()=>f(e.engine),className:`inline-flex items-center gap-1 px-2 py-1 rounded border border-destructive/30 text-destructive text-[11px] hover:bg-destructive/10 disabled:opacity-50`,children:[V(We,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!c&&(s??[]).length===0&&V(`tr`,{children:V(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),I(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[V(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,V(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,V(`strong`,{className:`text-foreground`,children:`pool`}),`: a per-device balanced inference pool (one per enabled accelerator, running concurrently); reaper-managed on its own idle TTL.`]}),r.isError&&I(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,r.error instanceof Error?r.error.message:`unknown`]})]})}F();var Et=new Set(me);function Dt(e){return Et.has(e)}function Ot(e,t,n){return`${e}/${t}/${n}`}function kt(e){return{coreml:`CoreML`,openvino:`OpenVINO`,onnx:`ONNX`}[e.format]??e.format.toUpperCase()}function At(e){return{coreml:`Apple Neural Engine / GPU — .mlpackage`,openvino:`Intel CPU / GPU / NPU — .xml`,onnx:`CPU, CUDA, Node.js — .onnx`}[e.format]??`.${e.format}`}function q(e){return e.format}function jt(e,t){let n=0,r=0,i=0;for(let a of e)for(let e of a.addons)for(let a of e.models){let e=a.formats[t];e&&(n++,e.downloaded&&(r++,i+=e.sizeMB))}return{total:n,downloaded:r,downloadedSizeMB:i}}function Mt({addonId:e,model:t,format:n,isActive:r,progress:i,errorMsg:a,onDownload:o,onDelete:s}){let c=t.formats[n];return c?I(`div`,{className:`flex items-center gap-3 px-4 py-3 border-b border-border/50 last:border-b-0 hover:bg-surface-hover/30 transition-colors`,children:[V(`div`,{className:`h-2 w-2 rounded-full shrink-0 ${c.downloaded?`bg-success`:`bg-foreground-subtle/30`}`}),I(`div`,{className:`flex-1 min-w-0`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),I(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`(`,t.id,`)`]})]}),i&&i.progress>=0&&i.progress<100&&I(`div`,{className:`mt-1.5 flex items-center gap-2 max-w-xs`,children:[V(`div`,{className:`flex-1 h-1 bg-surface-hover rounded-full overflow-hidden`,children:V(`div`,{className:`bg-primary h-full rounded-full transition-all duration-300`,style:{width:`${i.progress}%`}})}),I(`span`,{className:`text-[9px] text-primary font-mono tabular-nums shrink-0`,children:[Math.round(i.progress),`%`]})]})]}),V(`span`,{className:`text-xs text-foreground-subtle tabular-nums shrink-0`,children:Je(c.sizeMB)}),a&&I(`span`,{className:`flex items-center gap-1 text-[10px] text-danger max-w-[160px] truncate shrink-0`,title:a,children:[V(Re,{className:`h-3 w-3 shrink-0`}),a]}),c.downloaded?I(`button`,{onClick:s,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md border border-danger/30 text-danger hover:bg-danger/10 disabled:opacity-50 transition-colors shrink-0`,children:[r?V(U,{className:`h-3 w-3 animate-spin`}):V(We,{className:`h-3 w-3`}),r?`Deleting...`:`Delete`]}):I(`button`,{onClick:o,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[r?V(U,{className:`h-3 w-3 animate-spin`}):V(be,{className:`h-3 w-3`}),r?`Downloading...`:`Download`]})]}):null}function Nt({engines:e,activeEngine:t,viewEngine:n,onSelect:r}){let[i,a]=B(!1);return I(`div`,{className:`relative`,children:[I(`button`,{type:`button`,onClick:()=>a(!i),className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-4 py-2.5 w-full text-left hover:bg-surface-hover transition-colors`,children:[V(W,{className:`h-4 w-4 text-primary shrink-0`}),I(`div`,{className:`flex-1 min-w-0`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-sm font-medium text-foreground`,children:kt(n)}),q(n)===q(t)&&V(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),V(`div`,{className:`text-[10px] text-foreground-subtle`,children:At(n)})]}),V(Pe,{className:`h-4 w-4 text-foreground-subtle transition-transform ${i?`rotate-180`:``}`})]}),i&&V(`div`,{className:`absolute top-full left-0 right-0 mt-1 rounded-lg border border-border bg-surface shadow-lg z-50 overflow-hidden`,children:e.map(e=>{let i=q(e)===q(n),o=q(e)===q(t);return I(`button`,{type:`button`,onClick:()=>{r(e),a(!1)},className:`flex items-center gap-3 px-4 py-2.5 w-full text-left transition-colors ${i?`bg-primary/5`:`hover:bg-surface-hover`}`,children:[V(W,{className:`h-4 w-4 shrink-0 ${i?`text-primary`:`text-foreground-subtle`}`}),I(`div`,{className:`flex-1`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-sm font-medium ${i?`text-primary`:`text-foreground`}`,children:kt(e)}),o&&V(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),V(`div`,{className:`text-[10px] text-foreground-subtle`,children:At(e)})]}),i&&V(Le,{className:`h-4 w-4 text-primary shrink-0`})]},q(e))})})]})}function Pt({embedded:t=!1,nodeId:n}={}){let r=z(),i=n??`hub`,[a,o]=B(null),[s,c]=B(new Set),[l,d]=B(new Map),[f,p]=B(new Map),[m,h]=B(``),{data:g=[]}=w({nodeId:i}),v=g.filter((e,t,n)=>n.findIndex(t=>t.format===e.format)===t),{data:y}=N({nodeId:i}),b=y,{data:x,isLoading:S}=re({nodeId:i}),C=e(),T=u();_(`model.download.progress`,e=>{let t=e.data,n=typeof t.modelId==`string`?t.modelId:void 0,i=typeof t.progress==`number`?t.progress:void 0,a=typeof t.totalMB==`number`?t.totalMB:0;n===void 0||i===void 0||(d(e=>{let t=new Map(e);return i===100||i===-1?t.delete(n):t.set(n,{modelId:n,progress:i,totalMB:a}),t}),i===100&&r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]}))});let E=b??{runtime:`node`,backend:`cpu`,format:`onnx`},D=v.find(e=>e.format===a)??E,O=D.format,k=x?.slots??[],A=k.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(e=>e.formats[O]!==void 0)})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0),j=jt(A,O),M=le(async(e,t,n)=>{if(!Dt(n))return;let a=Ot(e,t,n);c(e=>new Set([...e,a])),p(e=>{let t=new Map(e);return t.delete(a),t});try{await C.mutateAsync({addonId:e,modelId:t,format:n,nodeId:i}),r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){p(t=>new Map([...t,[a,e instanceof Error?e.message:`Download failed`]]))}finally{c(e=>{let t=new Set(e);return t.delete(a),t})}},[C,r,i]),ee=le(async(e,t,n)=>{if(!Dt(n))return;let a=Ot(e,t,n);c(e=>new Set([...e,a])),p(e=>{let t=new Map(e);return t.delete(a),t});try{await T.mutateAsync({addonId:e,modelId:t,format:n,nodeId:i}),r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){p(t=>new Map([...t,[a,e instanceof Error?e.message:`Delete failed`]]))}finally{c(e=>{let t=new Set(e);return t.delete(a),t})}},[T,r,i]),te=le(e=>{o(e.format)},[]),ne=m.trim()?A.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(t=>t.name.toLowerCase().includes(m.toLowerCase())||t.id.toLowerCase().includes(m.toLowerCase())||e.name.toLowerCase().includes(m.toLowerCase()))})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0):A,P=I(R,{children:[S&&V(`div`,{className:`flex items-center justify-center py-16`,children:V(U,{className:`h-5 w-5 animate-spin text-foreground-subtle`})}),!S&&k.length===0&&I(`div`,{className:`flex flex-col items-center justify-center py-16 text-foreground-subtle`,children:[V(xe,{className:`h-8 w-8 mb-3 opacity-30`}),V(`span`,{className:`text-sm`,children:`No pipeline steps available`}),V(`span`,{className:`text-xs mt-1`,children:`Configure the detection pipeline to see available models.`})]}),!S&&k.length>0&&I(R,{children:[V(Nt,{engines:v,activeEngine:E,viewEngine:D,onSelect:te}),I(`div`,{className:`flex items-center gap-4 text-xs text-foreground-subtle`,children:[I(`span`,{children:[V(`span`,{className:`font-semibold text-foreground tabular-nums`,children:j.total}),V(`span`,{className:`ml-1`,children:`compatible models`})]}),V(`span`,{className:`text-border`,children:`|`}),I(`span`,{children:[V(`span`,{className:`font-semibold text-success tabular-nums`,children:j.downloaded}),V(`span`,{className:`ml-1`,children:`downloaded`})]}),V(`span`,{className:`text-border`,children:`|`}),I(`span`,{className:`tabular-nums`,children:[Je(j.downloadedSizeMB),V(`span`,{className:`ml-1`,children:`on disk`})]})]}),j.total>5&&I(`div`,{className:`relative`,children:[V(ke,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),V(`input`,{type:`text`,value:m,onChange:e=>h(e.target.value),placeholder:`Search models...`,className:`w-full pl-9 pr-3 py-2 text-sm rounded-lg border border-border bg-surface text-foreground placeholder:text-foreground-subtle/50 focus:outline-none focus:ring-1 focus:ring-primary`})]}),ne.map(e=>{let t=e.addons.reduce((e,t)=>e+t.models.length,0),n=e.addons.reduce((e,t)=>e+t.models.filter(e=>e.formats[O]?.downloaded).length,0);return I(`div`,{children:[I(`div`,{className:`flex items-center gap-2 mb-2`,children:[V(`h2`,{className:`text-sm font-semibold text-foreground`,children:e.label}),V(`div`,{className:`flex-1 h-px bg-border`}),I(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[n,`/`,t]})]}),V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:e.addons.map(e=>e.models.map(t=>{let n=Ot(e.id,t.id,O);return V(Mt,{addonId:e.id,model:t,format:O,isActive:s.has(n),progress:l.get(t.id),errorMsg:f.get(n),onDownload:()=>M(e.id,t.id,O),onDelete:()=>ee(e.id,t.id,O)},`${e.id}/${t.id}`)}))})]},e.id)}),ne.length===0&&V(`div`,{className:`text-center py-8 text-sm text-foreground-subtle`,children:m.trim()?I(R,{children:[`No models matching “`,m,`”`]}):I(R,{children:[`No models available for `,kt(D),` format`]})})]})]});return t?V(`div`,{className:`space-y-4`,children:P}):V(Ge,{children:P})}function Ft({nodeId:e,refreshToken:t}){return V(Pt,{embedded:!0,nodeId:e})}var It=`pipeline-runner`,Lt=200;function Rt({nodeId:e}){return I(`div`,{className:`flex flex-col gap-3`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),I(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`pipeline-runner activity on `,e,` — camera attach/detach, engine phases and pipeline errors. Streaming live; the device chip on a line tells which camera it refers to.`]})]}),V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:V(E,{agentId:e,addonId:It,limit:Lt,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}F(),F();function zt({nodeId:e,title:t}){let{data:n}=ge(),{data:r}=D(void 0),i=L(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),a=L(()=>{if(!e)return null;let t=new Set;for(let n of r??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,r]),[o,s]=B(new Map);_(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||s(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),H(()=>{if(o.size===0)return;let e=setInterval(()=>{s(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[o.size]);let c=L(()=>{let e=[];for(let t of o.values())a&&!a.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[o,a]);return c.length===0?I(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic`,children:[t??`Cameras`,`: no live snapshots yet`]}):I(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[I(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[V(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),V(`span`,{className:`text-[10px] text-foreground-subtle`,children:c.length})]}),V(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map(e=>{let t=i.get(e.deviceId)??`#${e.deviceId}`,n=p(e.metrics.phase);return I(`div`,{title:`${t} · ${n.label} · ${e.metrics.actualFps.toFixed(1)} fps · ${e.metrics.avgInferenceTimeMs.toFixed(0)}ms infer · q=${e.metrics.queueDepth}`,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${n.badgeClass}`,children:[V(v,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),V(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),V(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),V(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}F();var Bt=[`pipeline-orchestrator`],Vt=[`decoder`],Ht=!1;function Ut({nodeId:e,refreshToken:t}){let n=o(),[r,i]=B(null),[a,s]=B(null),c=(g(void 0).data??[]).find(t=>t.id===e),l=c?.name??e,u=c?.isOnline??!1,d=oe({onSuccess:e=>{s(e.effectiveModelId===null?`Reset done — model config cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),f=async()=>{await n({title:`Reset ${l} to hardware-aware defaults?`,message:`This clears every per-device model default on this node (back to the format default) and every per-camera step override scoped to it. Existing per-camera customisations on this node are lost.`,confirmLabel:`Reset`,variant:`danger`})&&(s(null),d.mutate({agentNodeId:e}))};return I(`div`,{className:`relative h-full w-full space-y-3`,children:[I(`div`,{className:`flex items-center justify-end gap-2 text-xs`,children:[a&&V(`span`,{className:`text-emerald-400`,children:a}),d.isError&&V(`span`,{className:`text-red-400`,children:d.error instanceof Error?d.error.message:`Reset failed`}),V(`button`,{type:`button`,onClick:()=>{f()},disabled:d.isPending,className:`rounded border border-amber-500/40 bg-surface px-2 py-0.5 text-amber-300 hover:bg-surface-hover disabled:opacity-50`,title:`Clear this node's per-device model defaults + per-camera overrides scoped to this node`,children:d.isPending?`Resetting…`:`Reset to default`})]}),V(zt,{nodeId:e}),V(Ye,{nodeId:e,addonIds:Bt,level:`global`,sectionIds:Vt}),Ht,Ht,I(`div`,{children:[V(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices — default model per accelerator`}),V(ye,{nodeId:e,nodeName:l,isOnline:u})]})]})}var Wt=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],Gt=`decoder-nodeav`;function Kt({nodeId:e,refreshToken:t}){let{data:n}=g(void 0),r=n?.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.id??Gt,i=[...Wt,r];return I(`div`,{className:`flex flex-col h-full`,children:[V(st,{nodeId:e,refreshToken:t}),V(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:V(Ye,{nodeId:e,addonIds:i,level:`global`,extraTabs:[{id:`assignments`,label:`Assignments`,order:-10,content:V(Ct,{nodeId:e,refreshToken:t})},{id:`tree`,label:`Pipeline`,order:39,content:V(Ut,{nodeId:e,refreshToken:t})},{id:`engines`,label:`Warm instances`,order:180,content:V(Tt,{nodeId:e,refreshToken:t})},{id:`models`,label:`Models`,order:200,content:V(Ft,{nodeId:e,refreshToken:t})},{id:`logs`,label:`Logs`,order:300,content:V(Rt,{nodeId:e})}]})})]})}var qt=`pipeline-orchestrator`,Jt=`recorder`,Yt=`recordingNodeId`,Xt=[`ingestNode`,`recordingNode`,`audioNode`,`motionNode`],Zt=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline (decode + inference) for assigned cameras`}];function Qt(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function $t(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function J(e,t,n){let r=Qt(e,t);return typeof r==`string`&&r.length>0?r:n}function en(e,t,n){let r=Qt(e,t);return typeof r==`number`&&Number.isFinite(r)?r:n}function tn(e,t){let n=$t(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function nn(e,t){let n=$t(e,t);return typeof n==`string`&&n.length>0?n:null}function rn(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:e===`audioNode`?`Audio`:`Motion Node`}function an(e){return e===`ingestNode`?`Node that terminates default camera ingest`:e===`recordingNode`?`Node that owns the recorder (recording-node)`:e===`audioNode`?`Node that runs singleton audio work`:`Runs software (analyzer) motion-watch. Onboard cameras are unaffected.`}function on(e,t){switch(t){case`detect`:return e.pipeline}}function sn(e){return e instanceof Error?e.message:`Failed to save`}function cn(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}function ln({capability:e,label:t,hint:n,nodeId:r,active:i,pending:a,layout:o,onToggle:s}){let c=i?`border-success/30 bg-success/15 text-success hover:bg-success/25`:`border-border bg-surface-hover text-foreground-subtle hover:bg-surface hover:text-foreground`,l=o===`card`?`w-full justify-center px-3 py-2 text-xs`:`px-2.5 py-1 text-[11px]`,u=i?Ie:ve;return I(`button`,{type:`button`,role:`switch`,"aria-checked":i,"aria-label":`${t} capability for ${r}`,title:`${t} — ${n}`,disabled:a,onClick:()=>s(e,!i),className:`inline-flex items-center gap-1.5 rounded-full border font-medium transition-colors disabled:opacity-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 ${c} ${l}`,children:[V(u,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),V(`span`,{children:t})]})}function un({node:e,emphasis:t=!1}){let n=e.isHub?Ae:W;return I(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[V(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),V(n,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),I(`div`,{className:`min-w-0`,children:[I(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[V(`span`,{className:`truncate`,children:e.name}),e.isHub&&V(ce,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&V(ce,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),V(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}F();function dn({nodeId:e,value:t,detectedHosts:n,status:r,errorMessage:i,onCommit:a}){let[o,s]=B(t??``);H(()=>{s(t??``)},[t]);let c=n[0],l=c===void 0?`auto-detect`:`auto: ${c}`,u=r===`pending`,d=o.trim(),f=d!==(t??``),p=f&&!u,m=()=>{p&&a(e,d.length>0?d:null)};return I(`div`,{className:`flex items-center gap-1.5`,children:[V(`input`,{"aria-label":`Reachable host for ${e}`,type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:l,value:o,disabled:u,onChange:e=>s(e.target.value),onBlur:m,onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&s(t??``)},className:`w-40 rounded-md border border-border bg-background px-2.5 py-1.5 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none disabled:opacity-50`}),I(`button`,{type:`button`,onClick:m,disabled:!p,"aria-label":`Save reachable host for ${e}`,title:`Save reachable host`,className:`inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1.5 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed`,children:[u?V(U,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):V(Ie,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),!f&&!u&&r===`success`&&V(Ie,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),r===`error`&&V(`span`,{title:i??`Failed to save reachable host`,children:V(Re,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":i??`Failed to save reachable host`,role:`img`})})]})}function fn({label:e,children:t}){return I(`div`,{className:`flex items-center justify-between gap-3`,children:[V(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-subtle`,children:e}),t]})}function pn({node:e,actions:t}){return I(`div`,{className:`rounded-xl border border-border bg-background p-4 space-y-4 ${e.isOnline?``:`opacity-60`}`,children:[V(un,{node:e,emphasis:!0}),V(`div`,{className:`grid grid-cols-2 gap-2`,children:Zt.map(n=>V(ln,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:on(e.effective,n.key),pending:t.capabilityPending,layout:`card`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)},n.key))}),V(`div`,{className:`space-y-3 border-t border-border pt-3`,children:V(fn,{label:`Reachable host`,children:V(dn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})})]})}function mn(){return I(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-foreground-subtle`,children:[I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2.5 w-2.5 rounded-full border border-success/30 bg-success/15`}),`Active capability`]}),I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2.5 w-2.5 rounded-full border border-border bg-surface-hover`}),`Idle`]}),I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2 w-2 rounded-full bg-success`}),`Node online`]}),I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2 w-2 rounded-full bg-danger`}),`Node offline`]})]})}function hn({nodes:e,actions:t}){return V(`div`,{className:`overflow-x-auto rounded-lg border border-border`,children:I(`table`,{className:`w-full min-w-[720px] border-collapse text-sm`,children:[V(`thead`,{children:I(`tr`,{className:`border-b border-border bg-background text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[V(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Node`}),Zt.map(e=>V(`th`,{className:`px-3 py-3 text-center font-semibold`,children:e.label},e.key)),V(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Reachable host`})]})}),V(`tbody`,{children:e.map(e=>I(`tr`,{className:`border-b border-border last:border-b-0 transition-colors hover:bg-surface-hover/40 ${e.isOnline?``:`opacity-60`}`,children:[V(`td`,{className:`px-4 py-3 align-middle`,children:V(un,{node:e})}),Zt.map(n=>V(`td`,{className:`px-3 py-3 text-center align-middle`,children:V(ln,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:on(e.effective,n.key),pending:t.capabilityPending,layout:`cell`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)})},n.key)),V(`td`,{className:`px-4 py-3 align-middle`,children:V(dn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})]},e.id))})]})})}function gn({role:e,value:t,options:n,pending:r,onChange:i}){return I(`label`,{className:`flex flex-col gap-1.5 rounded-lg border border-border bg-background p-3`,children:[V(`span`,{className:`text-xs font-semibold text-foreground`,children:rn(e)}),V(`select`,{value:t,disabled:r,onChange:t=>i(e,t.target.value),className:`rounded-md border border-border bg-surface px-2.5 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none disabled:opacity-50`,children:n.map(e=>V(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),V(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:an(e)})]})}function _n({roleValues:e,options:t,pending:n,lowFpsEnabled:r,fpsMinThreshold:i,onRoleChange:a,onLowFpsToggle:o}){return I(`div`,{className:`grid gap-3 @lg/clustertab:grid-cols-2 @3xl/clustertab:grid-cols-4`,children:[Xt.map(r=>V(gn,{role:r,value:e[r],options:t,pending:n,onChange:a},r)),I(`label`,{className:`flex items-start gap-2.5 rounded-lg border border-border bg-background p-3 text-sm text-foreground`,children:[V(`input`,{type:`checkbox`,checked:r,disabled:n,onChange:e=>o(e.target.checked),className:`mt-0.5 h-4 w-4 shrink-0 accent-primary`}),I(`span`,{className:`flex flex-col gap-0.5`,children:[V(`span`,{className:`text-xs font-semibold`,children:`Low-fps relocate/shed`}),I(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:[`fpsMinThreshold `,r?`${i} fps`:`disabled`]})]})]})]})}F();function vn(){let e=z(),{nodes:r}=h(),i=ie(void 0),a=P({addonId:qt}),o=P({addonId:Jt}),s=()=>cn(e),c=t({onSuccess:s}),l=ae(),u=n({onSuccess:s}),d=T({onSuccess:s}),[f,p]=B(!1),m=L(()=>{let e=new Map;for(let t of i.data??[])e.set(t.nodeId,t.settings);return e},[i.data]),g=L(()=>r.map(e=>{let t=m.get(e.id),n=it(t,e.isHub),r=tn(t,`detectWeight`);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,weight:r??1,maxCameras:tn(t,`maxCameras`),reachableHost:nn(t,`reachableHost`),detectedHosts:e.localIps}}),[r,m]),_=g.filter(e=>e.effective.pipeline),v={ingestNode:J(a.data,`ingestNode`,`hub`),recordingNode:J(o.data,Yt,`hub`),audioNode:J(a.data,`audioNode`,`hub`),motionNode:J(a.data,`motionNode`,`hub`)},y=L(()=>{let e=r.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...Xt.map(e=>v[e]),...e])].filter(e=>e.length>0)},[r,v]),b=en(a.data,`fpsMinThreshold`,0),x=b>0,S=i.isLoading||a.isLoading||o.isLoading,C=(e,t,n)=>{c.mutate({agentNodeId:e,[t]:n})},w=(e,t)=>{if(e===`recordingNode`){d.mutate({addonId:Jt,patch:{[Yt]:t}});return}d.mutate({addonId:qt,patch:{[e]:t}})},E=e=>{d.mutate({addonId:qt,patch:{fpsMinThreshold:e?Math.max(1,b):0}})},D=e=>u.variables?.agentNodeId===e?u.isPending?`pending`:u.isError?`error`:u.isSuccess?`success`:`idle`:`idle`,O=e=>D(e)===`error`?sn(u.error):null,k=async e=>{p(!0);try{for(let t of e)await l.mutateAsync({agentNodeId:t.nodeId,detectWeight:t.weight})}finally{p(!1),s()}},A={capabilityPending:c.isPending,onToggleCapability:C,onCommitReachableHost:(e,t)=>u.mutate({agentNodeId:e,reachableHost:t}),reachableHostStatus:D,reachableHostErrorMessage:O};return I(`section`,{className:`rounded-xl border border-border bg-surface p-5 @3xl/clustertab:p-6 space-y-6`,children:[I(`header`,{className:`flex items-start justify-between gap-4`,children:[I(`div`,{className:`space-y-1`,children:[V(`h3`,{className:`text-base font-semibold text-foreground`,children:`Pipeline placement`}),V(`p`,{className:`max-w-prose text-xs leading-relaxed text-foreground-subtle`,children:`Toggle which node runs each pipeline capability, distribute detection weight across detect-capable nodes, and choose the singleton cluster roles.`})]}),S&&V(U,{className:`h-5 w-5 shrink-0 animate-spin text-foreground-subtle`,"aria-label":`Loading`})]}),I(`div`,{className:`space-y-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Singleton cluster roles`}),V(_n,{roleValues:v,options:y,pending:d.isPending,lowFpsEnabled:x,fpsMinThreshold:b,onRoleChange:w,onLowFpsToggle:E})]}),I(`div`,{className:`space-y-3`,children:[I(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Per-node capabilities`}),V(mn,{})]}),g.length===0?V(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No cluster nodes reporting yet.`}):I(R,{children:[V(`div`,{className:`grid gap-4 @xl/clustertab:grid-cols-2 @3xl/clustertab:hidden`,children:g.map(e=>V(pn,{node:e,actions:A},e.id))}),V(`div`,{className:`hidden @3xl/clustertab:block`,children:V(hn,{nodes:g,actions:A})})]})]}),I(`div`,{className:`space-y-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection weight`}),V(_e,{nodes:_,pending:f,onCommitWeights:e=>void k(e)})]}),I(`div`,{className:`space-y-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices`}),_.length===0?V(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No detect-capable nodes — enable detection on a node above to configure its accelerators.`}):V(`div`,{className:`space-y-2`,children:_.map(e=>V(ye,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline},e.id))})]})]})}F();var yn=!1;function bn({refreshToken:e}){let t=z(),{data:n}=g(void 0);L(()=>qe(n??[]),[n]);let r=x({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return I(`div`,{className:`space-y-6`,children:[V(zt,{title:`Cluster cameras`}),V(ct,{refreshToken:e}),V(vn,{}),yn,I(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[I(`div`,{className:`min-w-0`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),V(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pipeline · audio assignments per camera (decode always runs co-located with the pipeline). Click the kebab to pin / unpin / move a role; expand the chevron for the per-camera broker drill-down.`})]}),I(`button`,{type:`button`,onClick:()=>r.mutate(void 0),disabled:r.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-white hover:bg-primary/90 disabled:opacity-50 shrink-0 self-start @md/clustertab:self-auto whitespace-nowrap`,children:[V(we,{className:`h-3.5 w-3.5`}),r.isPending?`Rebalancing…`:`Rebalance pipelines`]})]}),V(pt,{mode:`cluster`})]})}var xn=[`pipeline-orchestrator`];function Sn({refreshToken:e}){return V(`div`,{className:`space-y-4 max-w-3xl`,children:V(Ye,{nodeId:`hub`,addonIds:xn,level:`global`,title:`Cluster settings`,description:`Cluster-wide orchestration knobs: enabled nodes, load balancer thresholds, and failover policy. Per-camera pipelines live in Device Overrides; live cluster load is on the Assignments tab.`})})}F();function Cn({refreshToken:e}){let t=z(),{data:n,isLoading:r}=se(),[i,a]=B(null),[o,s]=B(``),[c,u]=B(``),d=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},f=l({onSuccess:()=>{a(null),d()}}),p=ne({onSuccess:d}),m=e=>{a(e.id),s(e.name),u(e.description??``)},h=()=>{a(null),s(``),u(``)},g=()=>{if(!i)return;let e=c.trim();f.mutate({id:i,name:o.trim()||`Untitled`,...e?{description:e}:{}})};if(r)return V(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let _=[...n??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return V(`div`,{className:`space-y-6 max-w-4xl`,children:I(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[I(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),V(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:`Curated pipeline presets operators can apply to any camera. Apply-time is a copy — future edits to a template don't retroactively change cameras that were seeded from it. Save a template from the device Pipeline tab.`})]}),I(`div`,{className:`text-[11px] text-foreground-subtle`,children:[_.length,` template`,_.length===1?``:`s`]})]}),_.length===0?I(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[V(Ee,{className:`h-6 w-6 opacity-40`}),V(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):V(`ul`,{className:`divide-y divide-border`,children:_.map(e=>{let t=i===e.id;return V(`li`,{className:`px-4 py-3 text-xs`,children:I(`div`,{className:`flex items-start gap-3`,children:[V(`div`,{className:`flex-1 min-w-0`,children:t?I(`div`,{className:`space-y-2`,children:[V(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-xs text-foreground focus:outline-none focus:border-primary`,value:o,onChange:e=>s(e.target.value),placeholder:`Template name`,autoFocus:!0}),V(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary`,value:c,onChange:e=>u(e.target.value),placeholder:`Description (optional)`})]}):I(R,{children:[V(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&V(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),I(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,I(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),V(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?I(R,{children:[I(`button`,{type:`button`,onClick:g,disabled:f.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-50`,children:[V(Ie,{className:`h-3 w-3`}),`Save`]}),I(`button`,{type:`button`,onClick:h,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover`,children:[V(He,{className:`h-3 w-3`}),`Cancel`]})]}):I(R,{children:[V(`button`,{type:`button`,onClick:()=>m(e),title:`Rename`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,children:V(Te,{className:`h-3 w-3`})}),V(`button`,{type:`button`,onClick:()=>{confirm(`Delete template "${e.name}"?`)&&p.mutate({id:e.id})},disabled:p.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-red-400 hover:bg-surface-hover disabled:opacity-50`,children:V(We,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}F();var wn=`pipeline-analytics`;function Tn(e){for(let t of e?.sections??[])for(let e of t.fields??[])if(e.key===`postProcessingNodeId`&&typeof e.value==`string`)return e.value;return`hub`}function En(){let e=z(),{data:t}=g(void 0),{data:n,isLoading:r}=P({addonId:wn}),i=Tn(n),a=T({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),o=L(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,i,...e])].filter(Boolean)},[t,i]);return I(`div`,{className:`flex flex-col gap-6`,children:[I(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Post-processing node`}),V(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that runs detection post-processing (events, media, audio & motion). Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),I(`div`,{className:`mt-3 flex items-center gap-2`,children:[r?V(U,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):V(`select`,{value:i,onChange:e=>{e.target.value!==i&&a.mutate({addonId:wn,patch:{postProcessingNodeId:e.target.value}})},disabled:a.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:o.map(e=>V(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),a.isPending&&V(U,{className:`h-4 w-4 animate-spin text-primary`})]})]}),I(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[V(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Events folder`}),V(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),V(Xe,{types:[`eventMedia`]})]})]})}var Dn=`pipeline-orchestrator`,On=200;function kn(){return I(`div`,{className:`flex flex-col gap-3`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),V(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Dispatch decisions, balancer moves and failover events from the pipeline orchestrator. Streaming live; the device chip on a line tells which camera it refers to.`})]}),V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:V(E,{addonId:Dn,limit:On,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}F();var An=[{id:`assignments`,label:`Assignments`},{id:`events`,label:`Events`},{id:`recording`,label:`Recording`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`},{id:`logs`,label:`Logs`}];function jn({refreshToken:e}){let[t,n]=B(`assignments`);return I(`div`,{className:`flex flex-col h-full`,children:[I(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[V(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),V(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Assignments with live load, cluster-wide settings, pipeline template library, per-camera pipeline overrides.`})]}),V(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:An.map(e=>V(`button`,{type:`button`,onClick:()=>n(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),I(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&V(bn,{refreshToken:e}),t===`events`&&V(En,{}),t===`recording`&&V(Ze,{}),t===`settings`&&V(Sn,{refreshToken:e}),t===`templates`&&V(Cn,{refreshToken:e}),t===`logs`&&V(kn,{})]})]})}function Mn(e){let t=[],n=[],{assignment:r,detection:i,decoder:a,broker:o}=e;i!==null&&i.provisioning.state===`failed`&&t.push({code:`provisioning-failed`,severity:`error`,message:i.provisioning.error!==void 0&&i.provisioning.error.length>0?`Engine provisioning failed: ${i.provisioning.error}`:`Engine provisioning failed on the detection node`}),i!==null&&i.phase===`active`&&i.actualFps===0&&t.push({code:`detection-black-hole`,severity:`error`,message:`Detection phase is ACTIVE but 0 fps are being processed — frames are not reaching the detector (cross-node black-hole signature)`}),i!==null&&i.phase===`active`&&a!==null&&a.shm.framesWritten===0&&t.push({code:`decoder-black-hole`,severity:`error`,message:`Decoder on ${a.nodeId} has written 0 frames to the shared-memory plane while detection is active — the decode path is stalled`}),r.detectionNodeId===null&&i===null&&n.push({code:`unassigned`,severity:`warning`,message:`Not placed on any detection node — no pipeline is running for this camera`});for(let e of o?.profiles??[])e.status===`streaming`&&e.inFps===0&&n.push({code:`broker-stalled`,severity:`warning`,message:`Broker profile "${e.profile}" reports streaming but 0 in-fps — the source pull may be stalled`});return[...t,...n]}function Nn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function Pn(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function Fn(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function In(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var Ln={detectionMode:null,detectionStreamProfile:null,detectionFps:null,motionSources:[],motionFps:null,motionCooldownMs:null,motionStreamProfile:null,audioMode:null,pipelineNodeId:null,decoderNodeId:null,audioNodeId:null,overriddenKeys:new Set};function Rn(e){if(!Nn(e)||!Array.isArray(e.sections))return Ln;let t=fe(e),n=e=>{let n=t.get(e);if(n!==void 0)return n.value??n.default},r=new Set;for(let[e,n]of t)In(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:Pn(n(`detectionFps`)),motionSources:Fn(n(`motionSources`)),motionFps:Pn(n(`motionFps`)),motionCooldownMs:Pn(n(`motionCooldownMs`)),motionStreamProfile:Y(n(`motionStreamProfile`)),audioMode:Y(n(`audioMode`)),pipelineNodeId:Y(n(`pipelineNodeId`)),decoderNodeId:Y(n(`decoderNodeId`)),audioNodeId:Y(n(`audioNodeId`)),overriddenKeys:r}}function zn(e,t=0){let n=[];for(let r of e)n.push({addonId:r.addonId,modelId:r.modelId??null,enabled:r.enabled,depth:t}),r.children!==void 0&&r.children.length>0&&n.push(...zn(r.children,t+1));return n}function Bn(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function X({title:e,children:t}){return I(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[V(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),V(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:n=!1}){return I(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[V(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),V(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&V(Vn,{})]})}function Vn(){return V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0 self-center`,title:`Device-level override active`,"aria-label":`Device-level override active`,role:`img`})}var Hn={neutral:`border-border text-foreground-muted`,success:`border-success/40 text-success`,warning:`border-warning/40 text-warning`,danger:`border-danger/40 text-danger`,info:`border-info/40 text-info`};function Q({tone:e=`neutral`,children:t,title:n}){return V(`span`,{title:n,className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-medium leading-tight whitespace-nowrap ${Hn[e]}`,children:t})}function $({children:e}){return V(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function Un({icon:e,label:t,nodeId:n,pinned:r,reason:i,overridden:a}){return I(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[V(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),V(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?V(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):I(R,{children:[V(`span`,{className:`font-mono text-foreground truncate`,title:n,children:n}),r?I(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[V(et,{className:`h-2.5 w-2.5`}),` manual`]}):I(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,i!==void 0&&i.length>0?i:`capacity`]}),a&&V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function Wn({assignment:e,settings:t,onlineNodes:n,pinPending:r,onDetectionPinChange:i}){let a=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,o=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...n.map(e=>e.id)])];return I(X,{title:`Where it runs`,children:[V(Un,{icon:W,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),V(Un,{icon:Ne,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),V(Un,{icon:Ce,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),V(Un,{icon:De,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),V(`div`,{className:`mt-1.5`,children:I(`select`,{value:a,disabled:r,"aria-label":`Detection placement pin`,onChange:e=>i(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-[11px] text-foreground disabled:opacity-50`,children:[V(`option`,{value:`auto`,children:`Auto (load balanced)`}),o.map(e=>I(`option`,{value:e,children:[`Pin detection → `,n.find(t=>t.id===e)?.name??e]},e))]})})]})}function Gn(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function Kn(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function qn(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function Jn({streams:e,brokerProfiles:t,settings:n,motionEnabled:r,motionFpsLive:i}){let a=Kn(t,n.detectionStreamProfile),o=Kn(t,n.motionStreamProfile),s=n.motionSources.includes(`analyzer`);return I(X,{title:`Streams & motion`,children:[I(Z,{label:`Detect stream`,overridden:n.overriddenKeys.has(`detectionStreamProfile`),children:[n.detectionStreamProfile??`—`,a!==void 0&&` · ${a.width}×${a.height} ${a.codec}`]}),V(Z,{label:`Detect FPS`,overridden:n.overriddenKeys.has(`detectionFps`),children:qn(n.detectionFps)}),I(Z,{label:`Motion src`,overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.join(` + `):`none`,r===!1&&` · inactive`]}),s&&I(R,{children:[I(Z,{label:`Motion stream`,overridden:n.overriddenKeys.has(`motionStreamProfile`),children:[n.motionStreamProfile??`—`,o!==void 0&&` · ${o.width}×${o.height} ${o.codec}`]}),I(Z,{label:`Motion FPS`,overridden:n.overriddenKeys.has(`motionFps`),children:[qn(n.motionFps),i!==null&&` · live ${i.toFixed(1)}`]})]}),V(Z,{label:`Cooldown`,overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?`default`:`${n.motionCooldownMs/1e3}s`}),V(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?V($,{children:`No streams registered`}):e.map(e=>I(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[V(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,Gn(e)]},e.camStreamId))})]})}function Yn({steps:e,audioModelId:t,audioEnabled:n,audioMode:r}){return I(X,{title:`Pipeline steps`,children:[e===void 0?V($,{children:`Resolving…`}):e.length===0?V($,{children:`No steps configured`}):V(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>V(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:I(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&V(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&I(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),V(`div`,{className:`mt-1`,children:I(Z,{label:`Audio class.`,children:[r??`—`,n!==null&&(n?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var Xn={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function Zn({detection:e,live:t,detectionMode:n,modeOverridden:r}){if(e===null)return I(X,{title:`Detection runtime`,children:[V(Z,{label:`Mode`,overridden:r,children:n??`—`}),V($,{children:`Detection stage inactive or unreachable`})]});let i=t?.phase??e.phase,a=t?.actualFps??e.actualFps,o=t?.configuredFps??e.configuredFps,s=t?.avgInferenceTimeMs??e.avgInferenceMs,c=t?.queueDepth??e.queueDepth,l=p(i),u=i===`active`&&a===0;return I(X,{title:`Detection runtime`,children:[I(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[I(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${l.badgeClass}`,children:[V(v,{phase:i,className:`h-2.5 w-2.5`}),l.label]}),t!==void 0&&V(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),V(Z,{label:`Mode`,overridden:r,children:n??`—`}),I(Z,{label:`FPS`,children:[V(`span`,{className:u?`text-danger font-semibold`:``,children:a.toFixed(1)}),I(`span`,{className:`text-foreground-subtle`,children:[` / `,o.toFixed(0),` configured`]})]}),I(Z,{label:`Inference`,children:[s.toFixed(0),` ms`,c>0&&I(`span`,{className:`text-warning`,children:[` · queue `,c]}),t!==void 0&&t.droppedFrames>0&&I(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),I(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),I(Z,{label:`Provisioning`,children:[V(Q,{tone:Xn[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&I(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function Qn({broker:e}){return e===null?V(X,{title:`Stream broker`,children:V($,{children:`Broker stage inactive or unreachable`})}):I(X,{title:`Stream broker`,children:[e.profiles.length===0?V($,{children:`No broker profiles`}):V(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,n=t&&e.inFps===0;return I(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${n?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),V(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),I(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),I(`span`,{className:`ml-auto shrink-0 ${n?`text-danger`:`text-foreground`}`,children:[e.inFps.toFixed(0),`→`,e.outFps.toFixed(0),`fps`]}),I(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),I(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[I(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),I(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function $n({decoder:e,detectionActive:t}){if(e===null)return V(X,{title:`Decoder`,children:V($,{children:`Decoder stage inactive or unreachable`})});let n=t&&e.shm.framesWritten===0;return I(X,{title:`Decoder`,children:[V(Z,{label:`Node`,children:e.nodeId}),V(Z,{label:`Sessions`,children:e.sessionCount}),I(Z,{label:`SHM frames`,children:[V(`span`,{className:n?`text-danger font-semibold`:``,children:e.shm.framesWritten}),V(`span`,{className:`text-foreground-subtle`,children:` written`})]}),I(Z,{label:`SHM reads`,children:[e.shm.getFrameHits,` hits`,e.shm.getFrameMisses>0&&I(`span`,{className:`text-warning`,children:[` · `,e.shm.getFrameMisses,` misses`]})]}),I(Z,{label:`SHM budget`,children:[e.shm.budgetMb,` MB`]}),e.formats.length>0&&V(Z,{label:`Formats`,children:e.formats.join(`, `)})]})}F();var er=`pipeline-orchestrator`,tr={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},nr={healthy:`Healthy`,idle:`Idle`,error:`Error`};function rr({problems:e}){return V(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>I(`div`,{className:`flex items-start gap-2 px-4 py-1.5 text-[11px] font-medium ${e.severity===`error`?`bg-danger/10 text-danger`:`bg-warning/10 text-warning`}`,children:[V(Ue,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),V(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function ir({deviceId:e,name:t,online:n,status:r,live:i,onlineNodes:a}){let o=z(),{data:s}=j({addonId:er,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:l}=d({deviceId:e},{staleTime:3e4}),u=L(()=>Rn(s),[s]),f=L(()=>l===void 0?void 0:zn(l.steps),[l]),p=L(()=>r===void 0?[]:Mn(r),[r]),m=()=>{o.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),o.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},h=ee({onSuccess:m}),g=c({onSuccess:m}),_=t=>{t===`auto`?g.mutate({deviceId:e}):h.mutate({deviceId:e,agentNodeId:t})},v=r===void 0?`idle`:Bn(r),y=p.some(e=>e.severity===`error`),b=p.length>0,x=y?`border-danger/50`:b?`border-warning/40`:`border-border`;return I(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${x} bg-background overflow-hidden`,children:[I(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[V(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${y?`bg-danger`:tr[v]}`,title:y?`Error`:nr[v],"aria-label":y?`Error`:nr[v],role:`img`}),V(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),I(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!n&&V(Q,{tone:`danger`,children:`offline`}),I(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[u.detectionMode!==null&&V(Q,{tone:u.detectionMode===`disabled`?`warning`:u.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:u.detectionMode===`disabled`?`detection off`:u.detectionMode}),r?.recording!=null&&(r.recording.active?I(Q,{tone:`danger`,title:`Recording (${r.recording.mode})`,children:[V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):r.recording.mode!==`off`&&I(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,r.recording.mode]}))]})]}),p.length>0&&V(rr,{problems:p}),r===void 0?V(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`}):I(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[V(Wn,{assignment:r.assignment,settings:u,onlineNodes:a,pinPending:h.isPending||g.isPending,onDetectionPinChange:_}),V(Zn,{detection:r.detection,live:i,detectionMode:u.detectionMode,modeOverridden:u.overriddenKeys.has(`detectionMode`)}),V(Yn,{steps:f,audioModelId:l?.audio?.modelId??null,audioEnabled:r.audio?.enabled??l?.audio?.enabled??null,audioMode:u.audioMode}),V(Jn,{streams:r.source.streams,brokerProfiles:r.broker?.profiles,settings:u,motionEnabled:r.motion?.enabled??null,motionFpsLive:r.motion?.fps??null}),V(Qn,{broker:r.broker}),V($n,{decoder:r.decoder,detectionActive:r.detection?.phase===`active`})]})]})}F();var ar=5e3,or=1e4,sr=5e3;function cr(e){let t=z(),{data:n,isLoading:r}=ge(),{data:i,isLoading:a}=C({},{refetchInterval:ar}),{nodes:o}=h();H(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[s,c]=B(new Map);_(pe.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&c(e=>{let n=new Map(e);return n.set(t.deviceId,{phase:t.metrics.phase,configuredFps:t.metrics.configuredFps,actualFps:t.metrics.actualFps,queueDepth:t.metrics.queueDepth,avgInferenceTimeMs:t.metrics.avgInferenceTimeMs,droppedFrames:t.metrics.droppedFrames,timestamp:t.timestamp}),n})}),H(()=>{if(s.size===0)return;let e=setInterval(()=>{c(e=>{let t=Date.now()-or,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},sr);return()=>clearInterval(e)},[s.size]);let l=L(()=>{let e=new Map;for(let t of i??[])e.set(t.deviceId,t);return e},[i]);return{rows:L(()=>(n??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:l.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[n,l]),liveMetrics:s,onlineNodes:L(()=>(o??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[o]),isLoading:r||a}}F();function lr({refreshToken:e}){let{rows:t,liveMetrics:n,onlineNodes:r,isLoading:i}=cr(e),a=L(()=>[...t.map(e=>{let t=e.status===void 0?[]:Mn(e.status);return{row:e,errorCount:t.filter(e=>e.severity===`error`).length,warningCount:t.filter(e=>e.severity===`warning`).length}})].sort((e,t)=>e.errorCount===t.errorCount?e.warningCount===t.warningCount?0:t.warningCount-e.warningCount:t.errorCount-e.errorCount),[t]),o=L(()=>{let e=0,t=0;for(let r of a)(r.errorCount>0||r.warningCount>0)&&(t+=1),(n.get(r.row.deviceId)?.phase??r.row.status?.detection?.phase)===`active`&&(e+=1);return{total:a.length,active:e,issues:t}},[a,n]);return i&&t.length===0?V(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?V(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):V(`div`,{className:`h-full overflow-y-auto`,children:I(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[I(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[I(`span`,{children:[V(`span`,{className:`font-semibold text-foreground`,children:o.total}),` cameras`]}),I(`span`,{children:[V(`span`,{className:`font-semibold text-success`,children:o.active}),` actively inferring`]}),I(`span`,{children:[V(`span`,{className:`font-semibold ${o.issues>0?`text-danger`:`text-foreground`}`,children:o.issues}),` `,`with issues`]}),V(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),a.map(({row:e})=>V(ir,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:n.get(e.deviceId),onlineNodes:r},e.deviceId))]})})}F();var ur=`__cluster__`;function dr(e){return e===`cameras`?`cameras`:`nodes`}function fr(){let[e,t]=Fe(),n=dr(e.get(`view`)),r=e.get(`node`)??`__cluster__`,[i,a]=B(0),[o,s]=B(!1);return H(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:ur},{replace:!0})},[n,e,t]),I(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[I(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[I(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[V(`button`,{type:`button`,onClick:()=>{t({view:`nodes`,node:r},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),V(`button`,{type:`button`,onClick:()=>{t({view:`cameras`},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]}),I(`button`,{type:`button`,onClick:()=>a(e=>e+1),title:`Refresh`,className:`inline-flex items-center gap-1.5 rounded-lg 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:[V(Oe,{className:`h-3.5 w-3.5`}),`Refresh`]})]}),n===`nodes`&&I(`button`,{type:`button`,onClick:()=>s(e=>!e),"aria-expanded":o,className:`md:hidden flex items-center justify-between gap-2 px-4 py-2 border-b border-border shrink-0 text-[11px] font-medium text-foreground-subtle hover:text-foreground transition-colors`,children:[I(`span`,{children:[o?`Hide`:`Show`,` node list`]}),V(Pe,{className:[`h-4 w-4 transition-transform`,o?`rotate-180`:``].join(` `)})]}),V(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:n===`nodes`?I(R,{children:[V(`aside`,{className:[o?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-border`,`max-h-[60vh] md:max-h-none overflow-y-auto`].join(` `),children:V(ot,{selectedNodeId:r,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),s(!1)},refreshToken:i})}),V(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:r===`__cluster__`?V(jn,{refreshToken:i}):V(Kt,{nodeId:r,refreshToken:i})})]}):V(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:V(lr,{refreshToken:i})})})]})}export{fr as PipelinePage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Bi as e,Fi as t,Gi as n,Ha as r,Hi as i,Ii as a,Ki as o,Li as s,Ri as c,Ui as l,Vi as u,Wi as d,do as f,fo as p,go as m,jn as h,lo as g,mo as _,po as v,qi as y,uo as b,vo as x,yo as S,zi as C}from"./src-aCTgvsel.js";import{K as w,Q as T,S as E,W as D,b as O,o as k,q as A,x as j,z as M}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{K as N}from"./src-Ck8eP0y_.js";import{a as P,i as ee,n as F,r as te,t as I}from"./face-bbox-DMbv2bqb.js";import{a as L,c as R,f as z,i as B,l as ne,m as V,n as re,o as ie,p as ae,r as H,s as oe,t as U,u as se}from"./debounced-invalidate-B8289fFj.js";import{t as W}from"./pencil-BtT77pEX.js";import{t as G}from"./plus-KUJYci_9.js";import{t as ce}from"./square-check-big-yVkG_6n8.js";import{t as K}from"./square-CDRKBQqh.js";import{I as q,L as le,P as ue,R as J,S as Y,W as de,i as X,s as Z}from"./index-DCWyP9SY.js";import{t as fe}from"./AdminPage-BwmGKnRf.js";import{n as pe,t as me}from"./authed-media-XfBD4Ma-.js";var he=de(`badge-check`,[[`path`,{d:`M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z`,key:`3c2336`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]);T();var Q=[[`plateGallery`]];function ge({vehicleId:e}){let t=k(),{data:n,isLoading:r}=i({vehicleId:e}),a=d();function o(n){a.mutate({vehicleId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:Q})}})}return r?E(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[j(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Loading plates…`]}):!n||n.length===0?j(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No plates yet.`}):j(`div`,{className:`mt-2 grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-6`,children:n.map(e=>E(`div`,{className:`group relative overflow-hidden rounded-md border border-border bg-surface`,children:[E(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[e.base64?j(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:e.text,className:`h-full w-full object-cover`}):j(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:j(J,{className:`h-6 w-6`})}),j(`button`,{type:`button`,onClick:()=>o(e),disabled:a.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove plate sample`,children:j(X,{className:`h-4 w-4 text-white`})})]}),j(`p`,{className:`truncate px-1.5 py-1 text-center font-mono text-[11px] font-semibold tracking-wide text-foreground`,title:e.text,children:e.text})]},e.id))})}function _e({vehicle:e,expanded:t,onToggle:r}){let i=k(),[a,o]=A(``),[s,c]=A(!1),[l,u]=A(!1),d=n(),h=C();function y(){o(e.name),c(!0)}function w(){c(!1),o(``)}function T(){let t=a.trim();if(!t||t===e.name){w();return}d.mutate({id:e.id,name:t},{onSettled:()=>{i.invalidateQueries({queryKey:Q}),w()}})}function D(){h.mutate({id:e.id},{onSettled:()=>{i.invalidateQueries({queryKey:Q}),u(!1)}})}return E(`div`,{className:`rounded-md border border-border bg-surface`,children:[E(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[j(`div`,{className:`h-8 w-12 shrink-0 overflow-hidden rounded border border-border bg-surface-hover`,children:e.coverBase64?j(`img`,{src:`data:image/jpeg;base64,${e.coverBase64}`,alt:e.name,className:`h-full w-full object-cover`}):j(`div`,{className:`flex h-full w-full items-center justify-center`,children:j(J,{className:`h-4 w-4 text-foreground-subtle`})})}),j(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:s?E(O,{children:[j(m,{value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T(),e.key===`Escape`&&w()},className:`h-6 text-xs`,autoFocus:!0}),j(`button`,{type:`button`,onClick:T,disabled:d.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:j(le,{className:`h-3.5 w-3.5`})}),j(`button`,{type:`button`,onClick:w,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:j(X,{className:`h-3.5 w-3.5`})})]}):j(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),j(x,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!s&&E(`div`,{className:`flex items-center gap-1`,children:[j(`button`,{type:`button`,onClick:y,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:j(W,{className:`h-3.5 w-3.5`})}),j(`button`,{type:`button`,onClick:()=>u(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:j(Z,{className:`h-3.5 w-3.5`})})]}),j(`button`,{type:`button`,onClick:r,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:j(t?q:ue,{className:`h-3.5 w-3.5`})})]}),t&&j(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:j(ge,{vehicleId:e.id})}),j(g,{open:l,onOpenChange:e=>!e&&u(!1),children:E(b,{children:[E(v,{children:[j(_,{children:`Delete vehicle`}),E(f,{children:[`Delete `,j(`strong`,{children:e.name}),` and all its plate samples? This cannot be undone.`]})]}),E(p,{children:[j(S,{variant:`secondary`,onClick:()=>u(!1),children:`Cancel`}),E(S,{variant:`danger`,onClick:D,disabled:h.isPending,children:[h.isPending?j(Y,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function ve(){let e=k(),[t,n]=A(``),r=s();function i(){let i=t.trim();i&&r.mutate({name:i},{onSettled:()=>{e.invalidateQueries({queryKey:Q}),n(``)}})}return E(`div`,{className:`flex items-center gap-2 pt-2`,children:[j(m,{placeholder:`New vehicle name…`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&i()},className:`h-7 text-xs flex-1`}),E(S,{variant:`primary`,size:`sm`,onClick:i,disabled:r.isPending||!t.trim(),children:[r.isPending?j(Y,{className:`h-3.5 w-3.5 animate-spin`}):j(G,{className:`h-3.5 w-3.5`}),`Add`]})]})}function ye(){let{data:e,isLoading:t}=l(),[n,r]=A(null);function i(e){r(t=>t===e?null:e)}return t?E(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[j(Y,{className:`h-4 w-4 animate-spin`}),`Loading vehicles…`]}):E(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&j(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No vehicles enrolled yet. Add one below.`}),e?.map(e=>j(_e,{vehicle:e,expanded:n===e.id,onToggle:()=>i(e.id)},e.id)),j(ve,{})]})}T();var be=[[`plateGallery`]];function xe(e){let[t,n]=A(null),[r,i]=A(null),[a,o]=A(!1);return M(()=>{if(n(null),i(null),o(!1),!e)return;let t=!1,r=null;return(async()=>{try{let i=await pe(`${me}/${encodeURIComponent(e)}`);if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),M(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>o(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function Se(e){let t=e.filter(e=>e.base64.length>0);return t.length===0?null:t.find(e=>/crop|plate/i.test(e.kind))??t[0]}function $({label:e,value:t,mono:n}){return E(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[j(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),j(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono`:``}`,title:t,children:t})]})}function Ce({box:e}){return j(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:j(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Plate`})})}function we({plate:t,cameraName:n,onClose:r,onAssign:i,onUnassign:o,onDelete:s,actionsPending:c}){let l=k(),{data:u,isFetching:d}=e({plateId:t?.plateId??``},{enabled:t!==null}),f=a(),[p,h]=A(`frame`),[_,v]=A(!1),[y,x]=A(``),{frameSrc:C,naturalWidth:w,naturalHeight:T,failed:O}=xe(t?.keyFrameMediaKey);M(()=>{v(!1),x(``),h(`frame`)},[t?.plateId]);let N=D(()=>{let e=Se(u??[]);return e?`data:image/jpeg;base64,${e.base64}`:t?.base64?`data:image/jpeg;base64,${t.base64}`:null},[u,t]),L=D(()=>!t?.plateBbox||w===null||T===null?null:I(t.plateBbox,w,T),[t?.plateBbox,w,T]);if(t===null)return null;let R=typeof t.keyFrameMediaKey==`string`&&t.keyFrameMediaKey.length>0&&!O,z=R&&p===`frame`,ne=t.assigned?t.vehicleName??`Assigned`:t.recognizedVehicleId?`${t.vehicleName??`Recognized`} (suggested)`:`Unassigned`,re=`${String(Math.round(t.score*100))}%${t.corrected?` · corrected`:``}`;function ie(){t&&(x(t.text),v(!0))}function H(){if(!t)return;let e=y.trim().toUpperCase();if(!e||e===t.text){v(!1);return}f.mutate({plateId:t.plateId,text:e},{onSettled:()=>{l.invalidateQueries({queryKey:be}),v(!1)}})}return j(g,{open:!0,onOpenChange:e=>!e&&r(),children:E(b,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Plate detail`,className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[E(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[E(`div`,{className:`min-w-0`,children:[j(`div`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:t.text||`Plate detail`}),j(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:n})]}),j(`button`,{type:`button`,onClick:r,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:j(X,{className:`h-4 w-4`})})]}),E(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[R&&E(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[E(`button`,{type:`button`,onClick:()=>h(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${p===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[j(ee,{className:`h-3.5 w-3.5`}),` Full frame`]}),E(`button`,{type:`button`,onClick:()=>h(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${p===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[j(P,{className:`h-3.5 w-3.5`}),` Crop`]})]}),z&&C?j(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:j(B,{src:C,alt:`Full frame with detected plate`,fit:`natural`,className:`w-full`,overlay:L?j(Ce,{box:L}):void 0})}):N?E(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[j(B,{src:N,alt:`Detected plate`,className:`h-full w-full`}),d&&j(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:j(Y,{className:`h-3.5 w-3.5 animate-spin`})})]}):E(`div`,{className:`flex aspect-[2/1] w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[j(V,{className:`h-8 w-8 text-warning/70`}),j(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),j(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:`The crop media for this plate could not be resolved. Safe to delete.`})]}),j(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-2`,children:E(`div`,{className:`flex items-center justify-between gap-3`,children:[j(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:`Plate text`}),_?E(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[j(m,{value:y,onChange:e=>x(e.target.value),onKeyDown:e=>{e.key===`Enter`&&H(),e.key===`Escape`&&v(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),j(`button`,{type:`button`,onClick:H,disabled:f.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Save corrected text`,children:f.isPending?j(Y,{className:`h-3.5 w-3.5 animate-spin`}):j(le,{className:`h-3.5 w-3.5`})}),j(`button`,{type:`button`,onClick:()=>v(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel`,children:j(X,{className:`h-3.5 w-3.5`})})]}):E(`button`,{type:`button`,onClick:ie,className:`group flex min-w-0 items-center gap-1.5`,title:`Correct the OCR reading`,children:[j(`span`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:t.text||`—`}),j(W,{className:`h-3 w-3 shrink-0 text-foreground-subtle group-hover:text-foreground`})]})]})}),E(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[j($,{label:`Camera`,value:n}),j($,{label:`Captured`,value:ae(t.timestamp)}),j($,{label:`Confidence`,value:re}),j($,{label:`Vehicle`,value:ne}),j($,{label:`Track`,value:t.trackId,mono:!0})]})]}),E(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[t.assigned?E(S,{variant:`secondary`,onClick:()=>o(t.plateId),disabled:c,children:[j(F,{className:`h-3.5 w-3.5`}),` Detach`]}):E(S,{variant:`primary`,onClick:()=>i(t.plateId),disabled:c,children:[j(te,{className:`h-3.5 w-3.5`}),` Assign`]}),E(S,{variant:`secondary`,onClick:()=>s(t.plateId),disabled:c,children:[j(Z,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}T();var Te=[[`plateGallery`]];function Ee({plateIds:e,vehicles:n,onDone:r}){let i=k(),a=t(),o=s(),[c,l]=A(``),[u,d]=A(!1),[h,y]=A(null),x=e!==null&&e.length>0,C=e?.length??0;function w(){d(!1),l(``),y(null)}function T(){w(),r()}function D(t){!e||e.length===0||a.mutate({plateIds:[...e],vehicleId:t},{onSettled:()=>{i.invalidateQueries({queryKey:Te}),T()}})}function O(){!e||!c.trim()||o.mutate({name:c.trim()},{onSuccess:e=>{e?.id&&D(e.id)},onError:()=>{i.invalidateQueries({queryKey:Te}),T()}})}let M=a.isPending||o.isPending;return j(g,{open:x,onOpenChange:e=>!e&&T(),children:E(b,{children:[E(v,{children:[j(_,{children:C>1?`Assign ${String(C)} plates to vehicle`:`Assign plate to vehicle`}),j(f,{children:`Select an existing vehicle or create a new one.`})]}),j(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:n.map(e=>E(`button`,{type:`button`,onClick:()=>y(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${h===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[j(`span`,{className:`font-medium`,children:e.name}),E(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` plates`]})]},e.id))}),u?j(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:j(m,{placeholder:`New vehicle name…`,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&O()},autoFocus:!0,className:`flex-1`})}):j(`button`,{type:`button`,onClick:()=>{y(null),d(!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 vehicle…`}),E(p,{children:[j(S,{variant:`secondary`,onClick:T,disabled:M,children:`Cancel`}),u?E(S,{variant:`primary`,onClick:O,disabled:M||!c.trim(),children:[M&&j(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):E(S,{variant:`primary`,onClick:()=>h&&D(h),disabled:M||!h,children:[M&&j(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,C>1?` ${String(C)}`:``]})]})]})})}T();var De=[[`plateGallery`]],Oe=500,ke=120;function Ae({plate:e,cameraName:t,nowMs:n,selected:r,onToggleSelect:i,onAssign:a,onOpenDetail:s}){let l=k(),u=o(),d=c(),f=()=>{l.invalidateQueries({queryKey:De})},p=()=>s(e.plateId);return E(`div`,{className:`relative flex flex-col overflow-hidden rounded-md border bg-surface ${r?`border-primary ring-1 ring-primary`:`border-border`}`,children:[E(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[e.base64?j(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Plate ${e.text} from ${t}`,onClick:p,className:`h-full w-full cursor-zoom-in object-cover`}):E(`button`,{type:`button`,onClick:p,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 plate's crop media is missing. Safe to delete.`,children:[j(V,{className:`h-7 w-7 text-warning/70`}),j(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}),j(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),i(e.plateId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":r?`Deselect`:`Select`,children:r?j(ce,{className:`h-4 w-4 text-primary`}):j(K,{className:`h-4 w-4`})}),e.corrected&&E(`span`,{className:`absolute right-0 top-0 z-10 flex items-center gap-0.5 rounded-bl-md bg-primary/80 px-1 py-0.5 text-[8px] font-semibold uppercase tracking-wide text-white`,title:`Manually corrected`,children:[j(he,{className:`h-3 w-3`}),` Fixed`]})]}),E(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[j(`p`,{className:`truncate font-mono text-xs font-bold tracking-wide text-foreground`,title:e.text,children:e.text||`—`}),j(`p`,{className:`truncate text-[10px] text-foreground-subtle`,title:t,children:t}),j(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:z(e.timestamp,n)}),e.vehicleName&&j(`p`,{className:`truncate text-[10px] font-medium text-primary`,title:e.vehicleName,children:e.vehicleName})]}),E(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?j(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),u.mutate({plateId:e.plateId},{onSettled:f})},disabled:u.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":`Detach plate`,title:`Detach`,children:u.isPending?j(Y,{className:`h-4 w-4 animate-spin`}):j(F,{className:`h-4 w-4`})}):j(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(e.plateId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":`Assign plate to vehicle`,title:`Assign to vehicle`,children:j(te,{className:`h-4 w-4`})}),j(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),d.mutate({plateId:e.plateId},{onSettled:f})},disabled:d.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 plate`,title:`Delete plate`,children:d.isPending?j(Y,{className:`h-4 w-4 animate-spin`}):j(Z,{className:`h-4 w-4`})})]})]})}var je=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Assigned`,value:`assigned`}];function Me(e,t){return t===`unassigned`?e.filter(e=>!e.assigned):t===`assigned`?e.filter(e=>e.assigned):e}function Ne(){let e=k(),[t,n]=A(`all`),[r,i]=A(oe),[a,s]=A(new Set),[d,f]=A(new Set),[p,m]=A(null),[g,_]=A(null),{data:v,isLoading:b}=u({limit:Oe},{refetchInterval:3e4}),{data:x=[]}=l(),{data:C}=h({}),w=o(),T=y(),M=c(),N=Date.now(),P=v??[],ee=D(()=>{let e=new Map;for(let t of C??[])e.set(t.id,t.name);return e},[C]),I=e=>ee.get(e)??`Camera #${String(e)}`,z=D(()=>R(P).map(e=>({id:e,name:I(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[P,ee]),B=D(()=>ne(se(Me(P,t),r),a),[P,t,r,a]),V=re(B,ke,D(()=>JSON.stringify([t,r.fromMs,r.toMs,[...a].sort((e,t)=>e-t)]),[t,r.fromMs,r.toMs,a])),ae=D(()=>new Map(P.map(e=>[e.plateId,e])),[P]),U=g===null?null:ae.get(g)??null,W=()=>{e.invalidateQueries({queryKey:De})},G=()=>f(new Set);function ce(e){f(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let K=[...d],q=T.isPending||M.isPending,le=w.isPending||M.isPending;function ue(){K.length!==0&&T.mutate({plateIds:K},{onSettled:()=>{W(),G()}})}function J(){K.length!==0&&Promise.allSettled(K.map(e=>M.mutateAsync({plateId:e}))).then(()=>{W(),G()})}function de(e){_(null),m([e])}function fe(e){w.mutate({plateId:e},{onSettled:W}),_(null)}function pe(e){M.mutate({plateId:e},{onSettled:W}),_(null)}let me=B.length!==P.length;return E(`div`,{className:`relative space-y-3`,children:[E(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[j(`div`,{className:`flex items-center gap-1`,children:je.map(e=>j(`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))}),j(L,{onChange:i}),j(ie,{cameras:z,selected:a,onChange:s}),!b&&j(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:me?`${String(B.length)} of ${String(P.length)} plates`:`${String(B.length)} plate${B.length===1?``:`s`}`})]}),d.size>0&&E(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[E(`span`,{className:`text-xs font-medium text-foreground`,children:[d.size,` selected`]}),E(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[E(S,{variant:`primary`,onClick:()=>m(K),disabled:q,children:[j(te,{className:`h-3.5 w-3.5`}),` Assign`]}),E(S,{variant:`secondary`,onClick:ue,disabled:q,children:[T.isPending?j(Y,{className:`h-3.5 w-3.5 animate-spin`}):j(F,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),E(S,{variant:`secondary`,onClick:J,disabled:q,children:[j(Z,{className:`h-3.5 w-3.5`}),` Delete`]}),j(S,{variant:`ghost`,onClick:G,disabled:q,children:j(X,{className:`h-3.5 w-3.5`})})]})]}),b&&E(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[j(Y,{className:`h-4 w-4 animate-spin`}),` Loading plates…`]}),!b&&B.length===0&&j(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:P.length>0?`No plates match the current filters.`:`No plates recognized yet.`}),!b&&B.length>0&&E(O,{children:[j(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2`,children:V.pageItems.map(e=>j(Ae,{plate:e,cameraName:I(e.deviceId),nowMs:N,selected:d.has(e.plateId),onToggleSelect:ce,onAssign:e=>m([e]),onOpenDetail:_},e.plateId))}),j(H,{currentPage:V.page,totalItems:V.totalItems,pageSize:V.pageSize,onPageChange:V.setPage,itemNoun:`plates`})]}),j(we,{plate:U,cameraName:U?I(U.deviceId):``,onClose:()=>_(null),onAssign:de,onUnassign:fe,onDelete:pe,actionsPending:le}),j(Ee,{plateIds:p,vehicles:x,onDone:()=>{m(null),G()}})]})}T();var Pe=[[`plateGallery`]],Fe=2e3;function Ie(){let e=k(),t=w(e);t.current=e;let n=w(void 0);n.current||=U({delayMs:Fe,invalidate:()=>{t.current.invalidateQueries({queryKey:Pe})}}),M(()=>()=>n.current?.cancel(),[]),r(N.PipelineAnalyticsPlateGalleryChanged,()=>{n.current?.trigger()})}function Le(){return Ie(),j(fe,{icon:J,title:`Plates`,subtitle:`Manage enrolled vehicles and assign recognized license plates to them.`,children:E(`section`,{className:`space-y-3`,children:[E(`div`,{children:[j(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Vehicles`}),j(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Enrolled vehicle identities used for plate recognition. Expand a row to view or remove plate samples.`}),j(ye,{})]}),E(`div`,{className:`pt-4 border-t border-border`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent recognized plates`}),j(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`License plates read by the detection pipeline. Assign them to a vehicle, correct the OCR text, or delete.`}),j(Ne,{})]})]})})}export{Le as PlatesPage};
|
|
1
|
+
import{Bi as e,Gi as t,Hi as n,Ji as r,Ki as i,Li as a,Ri as o,Ui as s,Vi as c,Wa as l,Wi as u,Yi as d,_o as f,bo as p,do as m,fo as h,ho as g,jn as _,mo as v,po as y,qi as b,uo as x,yo as S,zi as C}from"./src-CfZUxvPx.js";import{K as w,Q as T,S as E,W as D,b as O,o as k,q as A,x as j,z as M}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{K as N}from"./src-CCZM6rtM.js";import{a as P,i as ee,n as F,r as te,t as I}from"./face-bbox-CTcnAI8I.js";import{a as L,c as R,f as z,i as B,l as ne,m as V,n as re,o as ie,p as ae,r as H,s as oe,t as U,u as se}from"./debounced-invalidate-DlIKzA73.js";import{t as W}from"./pencil-BkXeyiDf.js";import{t as G}from"./plus-DXXZ8pd7.js";import{t as ce}from"./square-check-big--y441eG8.js";import{t as K}from"./square-BFjZ9GUs.js";import{I as q,L as le,P as ue,R as J,S as Y,W as de,i as X,s as Z}from"./index-Cjto-EXm.js";import{t as fe}from"./AdminPage-BwmGKnRf.js";import{n as pe,t as me}from"./authed-media-XfBD4Ma-.js";var he=de(`badge-check`,[[`path`,{d:`M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z`,key:`3c2336`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]);T();var Q=[[`plateGallery`]];function ge({vehicleId:e}){let t=k(),{data:n,isLoading:r}=u({vehicleId:e}),a=i();function o(n){a.mutate({vehicleId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:Q})}})}return r?E(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[j(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Loading plates…`]}):!n||n.length===0?j(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No plates yet.`}):j(`div`,{className:`mt-2 grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-6`,children:n.map(e=>E(`div`,{className:`group relative overflow-hidden rounded-md border border-border bg-surface`,children:[E(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[e.base64?j(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:e.text,className:`h-full w-full object-cover`}):j(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:j(J,{className:`h-6 w-6`})}),j(`button`,{type:`button`,onClick:()=>o(e),disabled:a.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove plate sample`,children:j(X,{className:`h-4 w-4 text-white`})})]}),j(`p`,{className:`truncate px-1.5 py-1 text-center font-mono text-[11px] font-semibold tracking-wide text-foreground`,title:e.text,children:e.text})]},e.id))})}function _e({vehicle:e,expanded:t,onToggle:n}){let r=k(),[i,a]=A(``),[o,s]=A(!1),[l,u]=A(!1),d=b(),_=c();function C(){a(e.name),s(!0)}function w(){s(!1),a(``)}function T(){let t=i.trim();if(!t||t===e.name){w();return}d.mutate({id:e.id,name:t},{onSettled:()=>{r.invalidateQueries({queryKey:Q}),w()}})}function D(){_.mutate({id:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:Q}),u(!1)}})}return E(`div`,{className:`rounded-md border border-border bg-surface`,children:[E(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[j(`div`,{className:`h-8 w-12 shrink-0 overflow-hidden rounded border border-border bg-surface-hover`,children:e.coverBase64?j(`img`,{src:`data:image/jpeg;base64,${e.coverBase64}`,alt:e.name,className:`h-full w-full object-cover`}):j(`div`,{className:`flex h-full w-full items-center justify-center`,children:j(J,{className:`h-4 w-4 text-foreground-subtle`})})}),j(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:o?E(O,{children:[j(f,{value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T(),e.key===`Escape`&&w()},className:`h-6 text-xs`,autoFocus:!0}),j(`button`,{type:`button`,onClick:T,disabled:d.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:j(le,{className:`h-3.5 w-3.5`})}),j(`button`,{type:`button`,onClick:w,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:j(X,{className:`h-3.5 w-3.5`})})]}):j(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),j(S,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!o&&E(`div`,{className:`flex items-center gap-1`,children:[j(`button`,{type:`button`,onClick:C,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:j(W,{className:`h-3.5 w-3.5`})}),j(`button`,{type:`button`,onClick:()=>u(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:j(Z,{className:`h-3.5 w-3.5`})})]}),j(`button`,{type:`button`,onClick:n,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:j(t?q:ue,{className:`h-3.5 w-3.5`})})]}),t&&j(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:j(ge,{vehicleId:e.id})}),j(x,{open:l,onOpenChange:e=>!e&&u(!1),children:E(m,{children:[E(v,{children:[j(g,{children:`Delete vehicle`}),E(h,{children:[`Delete `,j(`strong`,{children:e.name}),` and all its plate samples? This cannot be undone.`]})]}),E(y,{children:[j(p,{variant:`secondary`,onClick:()=>u(!1),children:`Cancel`}),E(p,{variant:`danger`,onClick:D,disabled:_.isPending,children:[_.isPending?j(Y,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function ve(){let e=k(),[t,n]=A(``),r=C();function i(){let i=t.trim();i&&r.mutate({name:i},{onSettled:()=>{e.invalidateQueries({queryKey:Q}),n(``)}})}return E(`div`,{className:`flex items-center gap-2 pt-2`,children:[j(f,{placeholder:`New vehicle name…`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&i()},className:`h-7 text-xs flex-1`}),E(p,{variant:`primary`,size:`sm`,onClick:i,disabled:r.isPending||!t.trim(),children:[r.isPending?j(Y,{className:`h-3.5 w-3.5 animate-spin`}):j(G,{className:`h-3.5 w-3.5`}),`Add`]})]})}function ye(){let{data:e,isLoading:n}=t(),[r,i]=A(null);function a(e){i(t=>t===e?null:e)}return n?E(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[j(Y,{className:`h-4 w-4 animate-spin`}),`Loading vehicles…`]}):E(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&j(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No vehicles enrolled yet. Add one below.`}),e?.map(e=>j(_e,{vehicle:e,expanded:r===e.id,onToggle:()=>a(e.id)},e.id)),j(ve,{})]})}T();var be=[[`plateGallery`]];function xe(e){let[t,n]=A(null),[r,i]=A(null),[a,o]=A(!1);return M(()=>{if(n(null),i(null),o(!1),!e)return;let t=!1,r=null;return(async()=>{try{let i=await pe(`${me}/${encodeURIComponent(e)}`);if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),M(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>o(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function Se(e){let t=e.filter(e=>e.base64.length>0);return t.length===0?null:t.find(e=>/crop|plate/i.test(e.kind))??t[0]}function $({label:e,value:t,mono:n}){return E(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[j(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),j(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono`:``}`,title:t,children:t})]})}function Ce({box:e}){return j(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:j(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Plate`})})}function we({plate:e,cameraName:t,onClose:r,onAssign:i,onUnassign:a,onDelete:s,actionsPending:c}){let l=k(),{data:u,isFetching:d}=n({plateId:e?.plateId??``},{enabled:e!==null}),h=o(),[g,_]=A(`frame`),[v,y]=A(!1),[b,S]=A(``),{frameSrc:C,naturalWidth:w,naturalHeight:T,failed:O}=xe(e?.keyFrameMediaKey);M(()=>{y(!1),S(``),_(`frame`)},[e?.plateId]);let N=D(()=>{let t=Se(u??[]);return t?`data:image/jpeg;base64,${t.base64}`:e?.base64?`data:image/jpeg;base64,${e.base64}`:null},[u,e]),L=D(()=>!e?.plateBbox||w===null||T===null?null:I(e.plateBbox,w,T),[e?.plateBbox,w,T]);if(e===null)return null;let R=typeof e.keyFrameMediaKey==`string`&&e.keyFrameMediaKey.length>0&&!O,z=R&&g===`frame`,ne=e.assigned?e.vehicleName??`Assigned`:e.recognizedVehicleId?`${e.vehicleName??`Recognized`} (suggested)`:`Unassigned`,re=`${String(Math.round(e.score*100))}%${e.corrected?` · corrected`:``}`;function ie(){e&&(S(e.text),y(!0))}function H(){if(!e)return;let t=b.trim().toUpperCase();if(!t||t===e.text){y(!1);return}h.mutate({plateId:e.plateId,text:t},{onSettled:()=>{l.invalidateQueries({queryKey:be}),y(!1)}})}return j(x,{open:!0,onOpenChange:e=>!e&&r(),children:E(m,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Plate detail`,className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[E(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[E(`div`,{className:`min-w-0`,children:[j(`div`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||`Plate detail`}),j(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),j(`button`,{type:`button`,onClick:r,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:j(X,{className:`h-4 w-4`})})]}),E(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[R&&E(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[E(`button`,{type:`button`,onClick:()=>_(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${g===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[j(ee,{className:`h-3.5 w-3.5`}),` Full frame`]}),E(`button`,{type:`button`,onClick:()=>_(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${g===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[j(P,{className:`h-3.5 w-3.5`}),` Crop`]})]}),z&&C?j(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:j(B,{src:C,alt:`Full frame with detected plate`,fit:`natural`,className:`w-full`,overlay:L?j(Ce,{box:L}):void 0})}):N?E(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[j(B,{src:N,alt:`Detected plate`,className:`h-full w-full`}),d&&j(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:j(Y,{className:`h-3.5 w-3.5 animate-spin`})})]}):E(`div`,{className:`flex aspect-[2/1] w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[j(V,{className:`h-8 w-8 text-warning/70`}),j(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),j(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:`The crop media for this plate could not be resolved. Safe to delete.`})]}),j(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-2`,children:E(`div`,{className:`flex items-center justify-between gap-3`,children:[j(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:`Plate text`}),v?E(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[j(f,{value:b,onChange:e=>S(e.target.value),onKeyDown:e=>{e.key===`Enter`&&H(),e.key===`Escape`&&y(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),j(`button`,{type:`button`,onClick:H,disabled:h.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Save corrected text`,children:h.isPending?j(Y,{className:`h-3.5 w-3.5 animate-spin`}):j(le,{className:`h-3.5 w-3.5`})}),j(`button`,{type:`button`,onClick:()=>y(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel`,children:j(X,{className:`h-3.5 w-3.5`})})]}):E(`button`,{type:`button`,onClick:ie,className:`group flex min-w-0 items-center gap-1.5`,title:`Correct the OCR reading`,children:[j(`span`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||`—`}),j(W,{className:`h-3 w-3 shrink-0 text-foreground-subtle group-hover:text-foreground`})]})]})}),E(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[j($,{label:`Camera`,value:t}),j($,{label:`Captured`,value:ae(e.timestamp)}),j($,{label:`Confidence`,value:re}),j($,{label:`Vehicle`,value:ne}),j($,{label:`Track`,value:e.trackId,mono:!0})]})]}),E(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[e.assigned?E(p,{variant:`secondary`,onClick:()=>a(e.plateId),disabled:c,children:[j(F,{className:`h-3.5 w-3.5`}),` Detach`]}):E(p,{variant:`primary`,onClick:()=>i(e.plateId),disabled:c,children:[j(te,{className:`h-3.5 w-3.5`}),` Assign`]}),E(p,{variant:`secondary`,onClick:()=>s(e.plateId),disabled:c,children:[j(Z,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}T();var Te=[[`plateGallery`]];function Ee({plateIds:e,vehicles:t,onDone:n}){let r=k(),i=a(),o=C(),[s,c]=A(``),[l,u]=A(!1),[d,_]=A(null),b=e!==null&&e.length>0,S=e?.length??0;function w(){u(!1),c(``),_(null)}function T(){w(),n()}function D(t){!e||e.length===0||i.mutate({plateIds:[...e],vehicleId:t},{onSettled:()=>{r.invalidateQueries({queryKey:Te}),T()}})}function O(){!e||!s.trim()||o.mutate({name:s.trim()},{onSuccess:e=>{e?.id&&D(e.id)},onError:()=>{r.invalidateQueries({queryKey:Te}),T()}})}let M=i.isPending||o.isPending;return j(x,{open:b,onOpenChange:e=>!e&&T(),children:E(m,{children:[E(v,{children:[j(g,{children:S>1?`Assign ${String(S)} plates to vehicle`:`Assign plate to vehicle`}),j(h,{children:`Select an existing vehicle or create a new one.`})]}),j(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>E(`button`,{type:`button`,onClick:()=>_(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${d===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[j(`span`,{className:`font-medium`,children:e.name}),E(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` plates`]})]},e.id))}),l?j(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:j(f,{placeholder:`New vehicle name…`,value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&O()},autoFocus:!0,className:`flex-1`})}):j(`button`,{type:`button`,onClick:()=>{_(null),u(!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 vehicle…`}),E(y,{children:[j(p,{variant:`secondary`,onClick:T,disabled:M,children:`Cancel`}),l?E(p,{variant:`primary`,onClick:O,disabled:M||!s.trim(),children:[M&&j(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):E(p,{variant:`primary`,onClick:()=>d&&D(d),disabled:M||!d,children:[M&&j(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,S>1?` ${String(S)}`:``]})]})]})})}T();var De=[[`plateGallery`]],Oe=500,ke=120;function Ae({plate:t,cameraName:n,nowMs:i,selected:a,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let l=k(),u=r(),d=e(),f=()=>{l.invalidateQueries({queryKey:De})},p=()=>c(t.plateId);return E(`div`,{className:`relative flex flex-col overflow-hidden rounded-md border bg-surface ${a?`border-primary ring-1 ring-primary`:`border-border`}`,children:[E(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[t.base64?j(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:`Plate ${t.text} from ${n}`,onClick:p,className:`h-full w-full cursor-zoom-in object-cover`}):E(`button`,{type:`button`,onClick:p,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 plate's crop media is missing. Safe to delete.`,children:[j(V,{className:`h-7 w-7 text-warning/70`}),j(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}),j(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t.plateId)},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":a?`Deselect`:`Select`,children:a?j(ce,{className:`h-4 w-4 text-primary`}):j(K,{className:`h-4 w-4`})}),t.corrected&&E(`span`,{className:`absolute right-0 top-0 z-10 flex items-center gap-0.5 rounded-bl-md bg-primary/80 px-1 py-0.5 text-[8px] font-semibold uppercase tracking-wide text-white`,title:`Manually corrected`,children:[j(he,{className:`h-3 w-3`}),` Fixed`]})]}),E(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[j(`p`,{className:`truncate font-mono text-xs font-bold tracking-wide text-foreground`,title:t.text,children:t.text||`—`}),j(`p`,{className:`truncate text-[10px] text-foreground-subtle`,title:n,children:n}),j(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:z(t.timestamp,i)}),t.vehicleName&&j(`p`,{className:`truncate text-[10px] font-medium text-primary`,title:t.vehicleName,children:t.vehicleName})]}),E(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[t.assigned?j(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),u.mutate({plateId:t.plateId},{onSettled:f})},disabled:u.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":`Detach plate`,title:`Detach`,children:u.isPending?j(Y,{className:`h-4 w-4 animate-spin`}):j(F,{className:`h-4 w-4`})}):j(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(t.plateId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":`Assign plate to vehicle`,title:`Assign to vehicle`,children:j(te,{className:`h-4 w-4`})}),j(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),d.mutate({plateId:t.plateId},{onSettled:f})},disabled:d.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 plate`,title:`Delete plate`,children:d.isPending?j(Y,{className:`h-4 w-4 animate-spin`}):j(Z,{className:`h-4 w-4`})})]})]})}var je=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Assigned`,value:`assigned`}];function Me(e,t){return t===`unassigned`?e.filter(e=>!e.assigned):t===`assigned`?e.filter(e=>e.assigned):e}function Ne(){let n=k(),[i,a]=A(`all`),[o,c]=A(oe),[l,u]=A(new Set),[f,m]=A(new Set),[h,g]=A(null),[v,y]=A(null),{data:b,isLoading:x}=s({limit:Oe},{refetchInterval:3e4}),{data:S=[]}=t(),{data:C}=_({}),w=r(),T=d(),M=e(),N=Date.now(),P=b??[],ee=D(()=>{let e=new Map;for(let t of C??[])e.set(t.id,t.name);return e},[C]),I=e=>ee.get(e)??`Camera #${String(e)}`,z=D(()=>R(P).map(e=>({id:e,name:I(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[P,ee]),B=D(()=>ne(se(Me(P,i),o),l),[P,i,o,l]),V=re(B,ke,D(()=>JSON.stringify([i,o.fromMs,o.toMs,[...l].sort((e,t)=>e-t)]),[i,o.fromMs,o.toMs,l])),ae=D(()=>new Map(P.map(e=>[e.plateId,e])),[P]),U=v===null?null:ae.get(v)??null,W=()=>{n.invalidateQueries({queryKey:De})},G=()=>m(new Set);function ce(e){m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let K=[...f],q=T.isPending||M.isPending,le=w.isPending||M.isPending;function ue(){K.length!==0&&T.mutate({plateIds:K},{onSettled:()=>{W(),G()}})}function J(){K.length!==0&&Promise.allSettled(K.map(e=>M.mutateAsync({plateId:e}))).then(()=>{W(),G()})}function de(e){y(null),g([e])}function fe(e){w.mutate({plateId:e},{onSettled:W}),y(null)}function pe(e){M.mutate({plateId:e},{onSettled:W}),y(null)}let me=B.length!==P.length;return E(`div`,{className:`relative space-y-3`,children:[E(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[j(`div`,{className:`flex items-center gap-1`,children:je.map(e=>j(`button`,{type:`button`,onClick:()=>a(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value))}),j(L,{onChange:c}),j(ie,{cameras:z,selected:l,onChange:u}),!x&&j(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:me?`${String(B.length)} of ${String(P.length)} plates`:`${String(B.length)} plate${B.length===1?``:`s`}`})]}),f.size>0&&E(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[E(`span`,{className:`text-xs font-medium text-foreground`,children:[f.size,` selected`]}),E(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[E(p,{variant:`primary`,onClick:()=>g(K),disabled:q,children:[j(te,{className:`h-3.5 w-3.5`}),` Assign`]}),E(p,{variant:`secondary`,onClick:ue,disabled:q,children:[T.isPending?j(Y,{className:`h-3.5 w-3.5 animate-spin`}):j(F,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),E(p,{variant:`secondary`,onClick:J,disabled:q,children:[j(Z,{className:`h-3.5 w-3.5`}),` Delete`]}),j(p,{variant:`ghost`,onClick:G,disabled:q,children:j(X,{className:`h-3.5 w-3.5`})})]})]}),x&&E(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[j(Y,{className:`h-4 w-4 animate-spin`}),` Loading plates…`]}),!x&&B.length===0&&j(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:P.length>0?`No plates match the current filters.`:`No plates recognized yet.`}),!x&&B.length>0&&E(O,{children:[j(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2`,children:V.pageItems.map(e=>j(Ae,{plate:e,cameraName:I(e.deviceId),nowMs:N,selected:f.has(e.plateId),onToggleSelect:ce,onAssign:e=>g([e]),onOpenDetail:y},e.plateId))}),j(H,{currentPage:V.page,totalItems:V.totalItems,pageSize:V.pageSize,onPageChange:V.setPage,itemNoun:`plates`})]}),j(we,{plate:U,cameraName:U?I(U.deviceId):``,onClose:()=>y(null),onAssign:de,onUnassign:fe,onDelete:pe,actionsPending:le}),j(Ee,{plateIds:h,vehicles:S,onDone:()=>{g(null),G()}})]})}T();var Pe=[[`plateGallery`]],Fe=2e3;function Ie(){let e=k(),t=w(e);t.current=e;let n=w(void 0);n.current||=U({delayMs:Fe,invalidate:()=>{t.current.invalidateQueries({queryKey:Pe})}}),M(()=>()=>n.current?.cancel(),[]),l(N.PipelineAnalyticsPlateGalleryChanged,()=>{n.current?.trigger()})}function Le(){return Ie(),j(fe,{icon:J,title:`Plates`,subtitle:`Manage enrolled vehicles and assign recognized license plates to them.`,children:E(`section`,{className:`space-y-3`,children:[E(`div`,{children:[j(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Vehicles`}),j(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Enrolled vehicle identities used for plate recognition. Expand a row to view or remove plate samples.`}),j(ye,{})]}),E(`div`,{className:`pt-4 border-t border-border`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent recognized plates`}),j(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`License plates read by the detection pipeline. Assign them to a vehicle, correct the OCR text, or delete.`}),j(Ne,{})]})]})})}export{Le as PlatesPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Co as e,So as t,xo as n}from"./src-CfZUxvPx.js";import{I as r,K as i,Q as a,S as o,W as s,b as c,q as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{L as f,V as p,c as ee,g as m,n as h,p as g,s as te}from"./player-overlays-BfnV1C0Q.js";import{MaskShapeCanvas as _}from"./MaskShapeCanvas-pGn6MKOi.js";var ne=m(`hexagon`,[[`path`,{d:`M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z`,key:`yt0hxn`}]]);a();var v=120,y=`privacy-mask`,b=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,x=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`;function S(e){return e.kind===`rect`||e.kind===`polygon`?e:null}function re(e){let t=new Set(e.map(e=>e.id)),n=0;for(;t.has(n);)n+=1;return n}function C(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(JSON.stringify(e[n])!==JSON.stringify(t[n]))return!1;return!0}function w({deviceId:a}){let m=ee(g().trpcClient,a),[w,T]=l(null),[E,D]=l(!1),[O,k]=l(null),[A,j]=l(null),[M,N]=l(!1),[P,F]=l(!1),[I,L]=l(null),[R,z]=l(null),B=i(!1);d(()=>{if(!m)return;let e=!1;return B.current=!1,T(null),D(!1),k(null),j(null),F(!1),L(null),z(null),(async()=>{try{let t=await m.privacyMask?.getOptions({});if(e)return;if(!t)throw Error(`device proxy not ready`);if(T(t),B.current)return;let n=await m.privacyMask?.getStatus({});if(e)return;if(!n)throw Error(`device proxy not ready`);B.current=!0;let r={enabled:n.enabled,regions:n.regions};j(r),k(r)}catch(t){if(e)return;p(t)?D(!0):console.error(`Privacy Mask load failed`,t)}})(),()=>{e=!0}},[m]);let V=s(()=>O!==null&&A!==null&&(O.enabled!==A.enabled||!C(O.regions,A.regions)),[O,A]),H=O?O.regions.length:0,U=w?w.maxRegions:0,W=i(0);d(()=>{W.current=U},[U]);let G=U>0&&H>=U,K=r(()=>{k(e=>e&&{...e,enabled:!e.enabled})},[]),q=r(e=>{L(typeof e==`number`?e:null)},[]),J=s(()=>O?O.regions.map(e=>({id:e.id,shape:e.shape,enabled:e.enabled,label:`Zone ${String(e.id)}`})):[],[O]),Y=r((e,t)=>{let n=S(t);n&&k(t=>t&&{...t,regions:t.regions.map(t=>t.id===e?{...t,shape:n}:t)})},[]),X=r(e=>{let t=S(e);t&&(z(null),k(e=>{if(!e)return e;let n=W.current;if(n>0&&e.regions.length>=n)return e;let r=re(e.regions),i={id:r,enabled:!0,shape:t};return L(r),{...e,regions:[...e.regions,i]}}))},[]),Z=r(e=>{F(!0),L(null),z(e)},[]),ie=r(e=>{F(!0),z(null),L(e)},[]),ae=r(e=>{L(t=>t===e?null:t),k(t=>t&&{...t,regions:t.regions.filter(t=>t.id!==e)})},[]),oe=r(()=>{z(null),L(null),A&&k({enabled:A.enabled,regions:A.regions})},[A]),se=r(async()=>{if(!(!m||!O)){N(!0);try{await m.privacyMask?.setMask({patch:{enabled:O.enabled,regions:[...O.regions]}});let e=await m.privacyMask?.getStatus({});if(e){let t={enabled:e.enabled,regions:e.regions};j(t),k(t)}}catch(e){console.error(`Privacy Mask save failed`,e)}finally{N(!1)}}},[m,O]),ce=r(()=>{F(e=>(e&&(z(null),L(null)),!e))},[]),Q=w?.supportedShapes??[];h(s(()=>P&&!E&&w&&O?{id:y,order:v,node:u(_,{transparent:!0,items:J,supportedShapes:Q,polygonVertices:w.polygonVertices,selectedId:I,onSelect:q,onShapeChange:Y,onDrawComplete:X,drawingKind:R})}:null,[P,E,w,O,J,Q,I,q,Y,X,R]));let le=w?.supportedShapes.includes(`rect`)??!1,ue=w?.supportedShapes.includes(`polygon`)??!1,$=w!==null&&(w.maxRegions<=0||w.supportedShapes.length===0);return m?u(te,{title:`Privacy Mask`,icon:u(e,{className:`h-3.5 w-3.5 text-foreground-subtle`}),children:u(`div`,{className:`flex flex-col gap-3`,children:E||$?u(`p`,{className:`${f} leading-relaxed`,children:`This camera doesn't support an on-board privacy mask.`}):!E&&!$&&w!==null&&O!==null?o(c,{children:[o(`p`,{className:`${f} leading-relaxed`,children:[`Toggle `,u(`strong`,{className:`text-foreground`,children:`Edit mask`}),` to draw blanked-out zones on the live frame, then `,u(`strong`,{className:`text-foreground`,children:`Save`}),` to push them to the camera. Drag a rectangle to move, its corner to resize; drag polygon vertices, click an edge midpoint to add one, or right-click a vertex to remove it.`]}),o(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(`button`,{type:`button`,onClick:ce,disabled:M,"aria-pressed":P,className:P?x:b,children:P?`Done editing`:`Edit mask`}),u(`button`,{type:`button`,onClick:K,disabled:M,"aria-pressed":O.enabled,className:O.enabled?x:b,children:O.enabled?`Mask on`:`Mask off`}),le&&u(`button`,{type:`button`,onClick:()=>Z(`rect`),disabled:M||G,"aria-pressed":R===`rect`,className:R===`rect`?x:b,title:G?`Maximum zones reached`:`Add a rectangle zone`,children:`+ Rect`}),ue&&u(`button`,{type:`button`,onClick:()=>Z(`polygon`),disabled:M||G,"aria-pressed":R===`polygon`,className:R===`polygon`?x:b,title:G?`Maximum zones reached`:`Add a polygon zone`,children:`+ Polygon`}),o(`span`,{className:`${f} ml-1 tabular-nums`,children:[H,` / `,U,` zones`]}),u(`span`,{className:`flex-1`}),u(`button`,{type:`button`,onClick:oe,disabled:M||!V,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:`Revert`}),u(`button`,{type:`button`,onClick:()=>void se(),disabled:M||!V,className:x,children:M?`Saving…`:`Save`})]}),H>0?u(`div`,{className:`flex flex-col gap-1`,children:O.regions.map(e=>{let r=I===e.id,i=e.shape.kind===`polygon`?ne:t;return o(`div`,{className:`flex items-center gap-2 rounded-md border px-2 py-1 transition-colors ${r?`border-primary/50 bg-primary/10`:`border-border bg-surface`}`,children:[o(`button`,{type:`button`,onClick:()=>ie(e.id),disabled:M,className:`flex flex-1 items-center gap-2 text-left text-[11px] font-medium text-foreground-subtle hover:text-foreground disabled:opacity-40 transition-colors`,children:[u(i,{className:`h-3.5 w-3.5 shrink-0`}),o(`span`,{children:[`Zone `,e.id]}),u(`span`,{className:`text-foreground-faint capitalize`,children:e.shape.kind})]}),u(`button`,{type:`button`,onClick:()=>ae(e.id),disabled:M,"aria-label":`Delete zone ${String(e.id)}`,title:`Delete zone`,className:`inline-flex h-6 w-6 items-center justify-center rounded border border-border bg-surface text-foreground-subtle hover:border-red-400/40 hover:bg-red-500/10 hover:text-red-400 disabled:opacity-40 transition-colors`,children:u(n,{className:`h-3.5 w-3.5`})})]},e.id)})}):null]}):u(`p`,{className:`${f} leading-relaxed`,children:`Loading the camera's privacy mask…`})})}):null}export{w as PrivacyMaskSettings};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Q as e,S as t,q as n,x as r}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as i}from"./radio-
|
|
1
|
+
import{Q as e,S as t,q as n,x as r}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as i}from"./radio-CGyv3voN.js";import{t as a}from"./server-CArIZ-KL.js";import{t as o}from"./wifi-B0toFYT9.js";import{W as s}from"./index-Cjto-EXm.js";var c=s(`cctv`,[[`path`,{d:`M16.75 12h3.632a1 1 0 0 1 .894 1.447l-2.034 4.069a1 1 0 0 1-1.708.134l-2.124-2.97`,key:`ir91b5`}],[`path`,{d:`M17.106 9.053a1 1 0 0 1 .447 1.341l-3.106 6.211a1 1 0 0 1-1.342.447L3.61 12.3a2.92 2.92 0 0 1-1.3-3.91L3.69 5.6a2.92 2.92 0 0 1 3.92-1.3z`,key:`jlp8i1`}],[`path`,{d:`M2 19h3.76a2 2 0 0 0 1.8-1.1L9 15`,key:`19bib8`}],[`path`,{d:`M2 21v-4`,key:`l40lih`}],[`path`,{d:`M7 9h.01`,key:`19b3jx`}]]),l=s(`house`,[[`path`,{d:`M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8`,key:`5wwlr5`}],[`path`,{d:`M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z`,key:`1d0kgt`}]]);e();var u={frigate:{icon:c,color:`#3b82f6`,label:`Frigate`},scrypted:{icon:a,color:`#a855f7`,label:`Scrypted`},reolink:{icon:i,color:`#06b6d4`,label:`Reolink`},homeassistant:{icon:l,color:`#22d3ee`,label:`Home Assistant`},rtsp:{icon:o,color:`#78716c`,label:`RTSP`},onvif:{icon:o,color:`#78716c`,label:`ONVIF`}},d={sm:`h-4 w-4`,md:`h-5 w-5`,lg:`h-6 w-6`},f={sm:`h-7 w-7`,md:`h-8 w-8`,lg:`h-10 w-10`};function p(e){let t=e.toLowerCase();return t.startsWith(`provider-`)?t.slice(9):t}function m(e){return u[p(e)]??{icon:c,color:`#78716c`,label:e}}function h(e){let t=p(e);return`/api/addon-assets/${e.toLowerCase().startsWith(`provider-`)?e:`provider-${t}`}/assets/icon.svg`}function g({type:e,size:i=`md`,showLabel:a}){let o=m(e),s=o.icon,[c,l]=n(!1),u=h(e);return t(`div`,{className:`flex items-center gap-2`,children:[r(`div`,{className:`flex items-center justify-center rounded-lg ${f[i]}`,style:{backgroundColor:`${o.color}15`},children:c?r(s,{className:d[i],style:{color:o.color}}):r(`img`,{src:u,alt:o.label,className:d[i],onError:()=>l(!0)})}),a&&r(`span`,{className:`text-xs font-medium text-foreground-subtle`,children:o.label})]})}export{g as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{$i as e,Fa as t,Kr as n,La as r,Qi as i,Ur as a,Va as o,Xa as s,Xi as c,Xr as l,Yi as u,Yr as d,Zi as f,ea as p,jn as m,ta as h}from"./src-aCTgvsel.js";import{I as g,Q as _,S as v,W as y,o as b,q as x,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-DTufy7Ue.js";import{K as w}from"./src-Ck8eP0y_.js";import{o as T,p as E}from"./player-overlays-QWBHo29P.js";import{t as D}from"./download-DRBnzzV8.js";import{i as O}from"./AddLocationWizard-DloYiu2S.js";import{A as k,E as A,S as j,U as M,W as N,s as P}from"./index-DCWyP9SY.js";import{t as F}from"./AdminPage-BwmGKnRf.js";import{n as I}from"./authed-media-XfBD4Ma-.js";import{t as L}from"./format-size-CO9d3C3-.js";import{t as ee}from"./ClusterRecordingTab-C8mgxr8n.js";import{t as R}from"./AdminTabs-TF8h_0Re.js";var z=N(`circle-x`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),B=N(`scissors`,[[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M8.12 8.12 12 12`,key:`1alkpv`}],[`path`,{d:`M20 4 8.12 15.88`,key:`xgtan2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M14.8 14.8 20 20`,key:`ptml3r`}]]);_();function V(e){let t=[];return e.timelapse?t.push(`timelapse ${String(e.timelapse.everyMs/1e3)}s`):(t.push(`${String(e.speed??1)}×`),e.includeAudio&&t.push(`+ audio`)),t.join(` `)}function H(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}function U(e,t){let n=Math.max(0,Math.round((t-e)/1e3)),r=Math.floor(n/3600),i=Math.floor(n%3600/60),a=n%60,o=r>0?`${String(r)}:${String(i).padStart(2,`0`)}:${String(a).padStart(2,`0`)}`:`${String(i)}:${String(a).padStart(2,`0`)}`;return`${H(e)} · ${o}`}function W(e,t){let n=e-t;if(n<=0)return`expired`;let r=Math.floor(n/6e4);if(r<60)return`in ${String(r)}m`;let i=Math.floor(r/60);return i<24?`in ${String(i)}h`:`in ${String(Math.floor(i/24))}d`}function G(e,t,n,r){return e.map(e=>{if(e.state===`expired`||e.state===`deleted`)return e;let i=r.get(e.id);if(i)return{...e,state:`failed`,error:i.error,progressPct:null};let a=n.get(e.id);if(a)return{...e,state:`ready`,fileBytes:a.fileBytes,progressPct:100};let o=t.get(e.id);return o&&(e.state===`queued`||e.state===`rendering`)?{...e,state:`rendering`,progressPct:o.progressPct}:e})}var K=[[`recordingExport`]],q={queued:{cls:`bg-muted text-foreground-subtle`,label:`queued`},rendering:{cls:`bg-primary/10 text-primary`,label:`rendering`,spin:!0},ready:{cls:`bg-success/10 text-success`,label:`ready`},failed:{cls:`bg-danger/10 text-danger`,label:`failed`},expired:{cls:`bg-muted text-foreground-subtle`,label:`expired`},deleted:{cls:`bg-muted text-foreground-subtle`,label:`deleted`}};function J(){let{data:e,isLoading:t}=i({},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`queued`||e.state===`rendering`)?3e3:!1}),{map:n}=o(w.RecordingExportProgress,e=>e.exportId),{map:r}=o(w.RecordingExportCompleted,e=>e.exportId),{map:a}=o(w.RecordingExportFailed,e=>e.exportId);return{rows:y(()=>G(e??[],n,r,a),[e,n,r,a]),isLoading:t}}function Y(e){let[t,n]=x(()=>Date.now());return C(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function X(){let e=b(),n=t(),i=E().trpcClient,a=Y(6e4),{rows:o,isLoading:l}=J(),{data:u}=m({}),d=y(()=>{let e=new Map;for(let t of u??[])e.set(t.id,t.name);return e},[u]),p=g(()=>{e.invalidateQueries({queryKey:K})},[e]),h=c({onSuccess:p}),_=f({onSuccess:p}),[C,w]=x(null),T=g(async e=>{w(e.id);try{let{url:t}=await i.recordingExport.getDownloadUrl.query({exportId:e.id}),n=await I(t),r=URL.createObjectURL(n),a=document.createElement(`a`);a.href=r,a.download=`${e.options.title??e.id}.mp4`,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(r),p()}finally{w(null)}},[i,p]),O=g(async e=>{await n({title:`Cancel this export?`,message:`Stops the render. The partial file is discarded.`,confirmLabel:`Cancel export`,variant:`danger`})&&h.mutate({exportId:e.id})},[n,h]),k=g(async e=>{await n({title:`Delete this export?`,message:`Permanently removes the rendered file and its history row.`,confirmLabel:`Delete`,variant:`danger`})&&_.mutate({exportId:e.id})},[n,_]),M=y(()=>[{key:`camera`,header:`Camera`,render:e=>S(`span`,{className:`text-foreground`,children:d.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`range`,header:`Range`,nowrap:!0,render:e=>S(`span`,{className:`tabular-nums`,children:U(e.fromMs,e.toMs)})},{key:`variant`,header:`Variant`,render:e=>S(`span`,{className:`text-foreground-subtle`,children:V(e.options)})},{key:`state`,header:`State`,render:e=>{let t=q[e.state];return v(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${t.cls}`,children:[t.spin&&S(j,{className:`h-2.5 w-2.5 animate-spin`}),t.label,e.state===`rendering`&&e.progressPct!==null&&v(`span`,{className:`tabular-nums`,children:[e.progressPct,`%`]})]})}},{key:`expiry`,header:`Expires`,nowrap:!0,render:e=>e.state===`deleted`?S(`span`,{className:`text-foreground-subtle`,children:`—`}):S(`span`,{className:`text-foreground-subtle tabular-nums`,children:W(e.expiresAt,a)})},{key:`size`,header:`Size`,align:`right`,nowrap:!0,render:e=>S(`span`,{className:`tabular-nums`,children:e.fileBytes===null?`—`:L(e.fileBytes)})},{key:`actions`,header:``,align:`right`,render:e=>{let t=e.state===`ready`,n=e.state===`queued`||e.state===`rendering`,r=e.state!==`deleted`;return v(`div`,{className:`flex items-center justify-end gap-1`,children:[t&&v(`button`,{onClick:()=>{T(e)},disabled:C===e.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-primary/10 hover:text-foreground disabled:opacity-50`,title:`Download MP4`,children:[C===e.id?S(j,{className:`h-3 w-3 animate-spin`}):S(D,{className:`h-3 w-3`}),`Download`]}),n&&v(`button`,{onClick:()=>{O(e)},disabled:h.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-amber-500/10 hover:text-amber-500 disabled:opacity-50`,title:`Cancel render`,children:[S(z,{className:`h-3 w-3`}),`Cancel`]}),r&&S(`button`,{onClick:()=>{k(e)},disabled:_.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 export`,children:S(P,{className:`h-3 w-3`})})]})}}],[d,a,C,h.isPending,_.isPending,T,O,k]);return l&&o.length===0?v(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[S(j,{className:`h-4 w-4 animate-spin`}),`Loading exports…`]}):o.length===0?S(r,{icon:A,title:`No exports yet`,description:`Export a footage range from a camera's timeline in the viewer. Rendered clips show up here to download or manage.`}):S(s,{columns:M,rows:o,rowKey:e=>e.id,minWidthPx:720})}_();var Z=[[`recording`]],Q=[{value:`retention`,label:`Retention policy`},{value:`quota`,label:`Quota / disk pressure`},{value:`operator`,label:`Operator`}];function te(e){return e.totalBytes===null||e.totalBytes<=0?null:Math.min(1,Math.max(0,e.usedBytes/e.totalBytes))}function ne(){let n=b(),i=t(),[a,o]=x(`retention`),{data:c,isLoading:l}=e({},{refetchOnWindowFocus:!1}),{data:d}=m({}),f=y(()=>{let e=new Map;for(let t of d??[])e.set(t.id,t.name);return e},[d]),p=g(()=>{n.invalidateQueries({queryKey:Z})},[n]),_=h({onSuccess:p}),C=u({onSuccess:p}),w=g(async e=>{await i({title:`Prune ${f.get(e.deviceId)??`#${String(e.deviceId)}`}?`,message:`Applies the retention policy now (reason: ${a}). Footage beyond the policy is permanently deleted.`,confirmLabel:`Prune now`,variant:`danger`})&&_.mutate({deviceId:e.deviceId,reason:a})},[i,_,a,f]),E=g(async e=>{await i({title:`Delete all footage for ${f.get(e.deviceId)??`#${String(e.deviceId)}`}?`,message:`Permanently deletes ${L(e.usedBytes)} of recorded footage for this camera. This cannot be undone.`,confirmLabel:`Delete ${L(e.usedBytes)}`,variant:`danger`})&&C.mutate({deviceId:e.deviceId})},[i,C,f]),D=y(()=>[{key:`camera`,header:`Camera`,render:e=>S(`span`,{className:`text-foreground`,children:f.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`used`,header:`Used`,align:`right`,nowrap:!0,render:e=>S(`span`,{className:`tabular-nums`,children:L(e.usedBytes)})},{key:`actions`,header:``,align:`right`,render:e=>v(`div`,{className:`flex items-center justify-end gap-1`,children:[v(`button`,{onClick:()=>{w(e)},disabled:_.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-amber-500/10 hover:text-amber-500 disabled:opacity-50`,title:`Apply retention policy now`,children:[S(B,{className:`h-3 w-3`}),`Prune`]}),v(`button`,{onClick:()=>{E(e)},disabled:C.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 all footage`,children:[S(P,{className:`h-3 w-3`}),`Delete`]})]})}],[f,w,E,_.isPending,C.isPending]);if(l&&!c)return v(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[S(j,{className:`h-4 w-4 animate-spin`}),`Loading storage usage…`]});if(!c)return S(r,{icon:O,title:`No storage data`,description:`The recording node has not reported any storage usage yet.`});let k=c.devices.length;return v(`div`,{className:`flex flex-col gap-6`,children:[v(`section`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:[S(T,{label:`Total used`,icon:S(O,{className:`h-3 w-3`}),footer:`${String(k)} camera${k===1?``:`s`} on ${c.nodeId}`,children:L(c.totalUsedBytes)}),c.locations.map(e=>{let t=te(e),n=e.locationId??`default`;return S(T,{label:`Disk ${n}`,footer:e.availableBytes===null?`${L(e.usedBytes)} used (capacity unknown)`:`${L(e.availableBytes)} free${e.totalBytes===null?``:` of ${L(e.totalBytes)}`}`,children:t===null?S(`span`,{className:`tabular-nums`,children:L(e.usedBytes)}):v(`div`,{className:`flex items-center gap-2`,children:[S(`div`,{className:`h-2 flex-1 overflow-hidden rounded bg-muted`,children:S(`div`,{className:`h-full rounded ${t>.9?`bg-danger`:t>.75?`bg-amber-500`:`bg-primary`}`,style:{width:`${String(Math.round(t*100))}%`}})}),v(`span`,{className:`tabular-nums text-xs`,children:[Math.round(t*100),`%`]})]})},n)})]}),v(`section`,{className:`flex items-center gap-2 text-xs`,children:[S(`label`,{htmlFor:`prune-reason`,className:`text-foreground-subtle`,children:`Prune reason`}),S(`select`,{id:`prune-reason`,value:a,onChange:e=>{let t=Q.find(t=>t.value===e.target.value);t&&o(t.value)},className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:Q.map(e=>S(`option`,{value:e.value,children:e.label},e.value))})]}),k===0?S(r,{icon:O,title:`No recorded footage`,description:`No camera has recorded footage on this node yet.`}):S(s,{columns:D,rows:[...c.devices],rowKey:e=>e.deviceId,minWidthPx:480})]})}_();var re=[[`pipelineAnalytics`]],ie=1440*60*1e3,ae=[{days:1,label:`1 day`},{days:7,label:`7 days`},{days:30,label:`30 days`},{days:90,label:`90 days`}];function oe(){let e=b(),i=t(),[o,c]=x(30),{data:u,isLoading:d}=n({},{refetchOnWindowFocus:!1}),{data:f}=m({}),p=y(()=>{let e=new Map;for(let t of f??[])e.set(t.id,t.name);return e},[f]),h=g(()=>{e.invalidateQueries({queryKey:re})},[e]),_=l({onSuccess:h}),C=a({onSuccess:h}),w=g(async()=>{await i({title:`Prune events older than ${String(o)} day${o===1?``:`s`}?`,message:`Permanently deletes every event (motion / object / audio) older than the cutoff across all cameras, and their media. This cannot be undone.`,confirmLabel:`Prune events`,variant:`danger`})&&_.mutate({olderThanMs:Date.now()-o*ie,reason:`retention`})},[i,_,o]),E=g(async e=>{await i({title:`Delete all events for ${p.get(e.deviceId)??`#${String(e.deviceId)}`}?`,message:`Permanently deletes ${String(e.rows)} event${e.rows===1?``:`s`} (${L(e.bytes)} of media) for this camera. This cannot be undone.`,confirmLabel:`Delete events`,variant:`danger`})&&C.mutate({deviceId:e.deviceId})},[i,C,p]),D=y(()=>[{key:`camera`,header:`Camera`,render:e=>S(`span`,{className:`text-foreground`,children:p.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`rows`,header:`Events`,align:`right`,nowrap:!0,render:e=>S(`span`,{className:`tabular-nums`,children:e.rows.toLocaleString()})},{key:`bytes`,header:`Media`,align:`right`,nowrap:!0,render:e=>S(`span`,{className:`tabular-nums`,children:L(e.bytes)})},{key:`actions`,header:``,align:`right`,render:e=>v(`button`,{onClick:()=>{E(e)},disabled:C.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 all events for this camera`,children:[S(P,{className:`h-3 w-3`}),`Delete`]})}],[p,E,C.isPending]);return d&&!u?v(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[S(j,{className:`h-4 w-4 animate-spin`}),`Loading event-store footprint…`]}):u?v(`div`,{className:`flex flex-col gap-6`,children:[v(`section`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[S(T,{label:`Total events`,icon:S(k,{className:`h-3 w-3`}),footer:`across ${String(u.devices.length)} camera${u.devices.length===1?``:`s`}`,children:u.totalRows.toLocaleString()}),S(T,{label:`Event media on disk`,children:L(u.totalBytes)})]}),v(`section`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[S(`span`,{className:`text-foreground-subtle`,children:`Prune events older than`}),S(`select`,{value:o,onChange:e=>c(Number(e.target.value)),className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:ae.map(e=>S(`option`,{value:e.days,children:e.label},e.days))}),v(`button`,{onClick:()=>{w()},disabled:_.isPending,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-xs font-medium text-foreground-subtle hover:bg-amber-500/10 hover:text-amber-500 disabled:opacity-50`,children:[_.isPending?S(j,{className:`h-3 w-3 animate-spin`}):S(B,{className:`h-3 w-3`}),`Prune now`]})]}),u.devices.length===0?S(r,{icon:k,title:`No stored events`,description:`No camera has persisted events yet.`}):S(s,{columns:D,rows:[...u.devices],rowKey:e=>e.deviceId,minWidthPx:480})]}):S(r,{icon:k,title:`No event data`,description:`Pipeline analytics has not reported any event-store footprint yet.`})}_();var $=[{value:`all`,label:`All`},{value:`recording`,label:`Recordings`},{value:`events`,label:`Events`}],se={recording:`bg-primary/10 text-primary`,events:`bg-violet-500/10 text-violet-400`};function ce(e){return new Date(e).toLocaleString()}function le(){let[e,t]=x(`all`),{data:n,isLoading:i}=p({},{refetchOnWindowFocus:!1}),{data:a,isLoading:o}=d({},{refetchOnWindowFocus:!1}),{data:c}=m({}),l=y(()=>{let e=new Map;for(let t of c??[])e.set(t.id,t.name);return e},[c]),u=y(()=>{let t=[...n??[],...a??[]];return(e===`all`?t:t.filter(t=>t.domain===e)).toSorted((e,t)=>t.at-e.at)},[n,a,e]),f=y(()=>[{key:`at`,header:`When`,nowrap:!0,render:e=>S(`span`,{className:`text-foreground-subtle tabular-nums`,children:ce(e.at)})},{key:`domain`,header:`Domain`,render:e=>S(`span`,{className:`inline-flex rounded px-1.5 py-0.5 text-[10px] font-medium ${se[e.domain]}`,children:e.domain})},{key:`op`,header:`Operation`,render:e=>S(`span`,{className:`text-foreground`,children:e.op})},{key:`reason`,header:`Reason`,render:e=>S(`span`,{className:`text-foreground-subtle`,children:e.reason})},{key:`device`,header:`Camera`,render:e=>e.deviceId===null?S(`span`,{className:`text-foreground-subtle`,children:`cluster`}):S(`span`,{className:`text-foreground`,children:l.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`items`,header:`Items`,align:`right`,nowrap:!0,render:e=>S(`span`,{className:`tabular-nums`,children:e.itemsAffected.toLocaleString()})},{key:`bytes`,header:`Reclaimed`,align:`right`,nowrap:!0,render:e=>S(`span`,{className:`tabular-nums`,children:e.bytesReclaimed>0?L(e.bytesReclaimed):`—`})}],[l]),h=i||o;return v(`div`,{className:`flex flex-col gap-4`,children:[S(`div`,{className:`flex items-center gap-1`,children:$.map(n=>S(`button`,{onClick:()=>t(n.value),className:`rounded px-2 py-1 text-xs font-medium ${e===n.value?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-muted`}`,children:n.label},n.value))}),h&&u.length===0?v(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[S(j,{className:`h-4 w-4 animate-spin`}),`Loading activity…`]}):u.length===0?S(r,{icon:M,title:`No activity yet`,description:`Prune, delete and rescan operations across recordings and events show up here.`}):S(s,{columns:f,rows:u,rowKey:e=>e.id,minWidthPx:720})]})}function ue(){return S(F,{icon:A,title:`Recordings`,subtitle:`Recording node & storage, event-store management, exported clips, and an activity log.`,children:S(R,{tabs:[{id:`recordings`,label:`Recordings`,icon:O,content:S(ee,{})},{id:`storage`,label:`Storage`,icon:O,content:S(ne,{})},{id:`events`,label:`Events`,icon:k,content:S(oe,{})},{id:`exports`,label:`Exports`,icon:A,content:S(X,{})},{id:`activity`,label:`Activity`,icon:M,content:S(le,{})}]})})}export{ue as RecordingsPage};
|
|
1
|
+
import{$i as e,Kr as t,La as n,Qi as r,Ua as i,Ur as a,Xr as o,Yr as s,Za as c,Zi as l,ea as u,jn as d,na as f,ra as p,ta as m,za as h}from"./src-CfZUxvPx.js";import{I as g,Q as _,S as v,W as y,o as b,q as x,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-DTufy7Ue.js";import{K as w}from"./src-CCZM6rtM.js";import{o as T,p as E}from"./player-overlays-BfnV1C0Q.js";import{t as D}from"./download-CJ-1cdDh.js";import{i as O}from"./AddLocationWizard-VuBsssbs.js";import{A as k,E as A,S as j,U as M,W as N,s as P}from"./index-Cjto-EXm.js";import{t as F}from"./AdminPage-BwmGKnRf.js";import{n as I}from"./authed-media-XfBD4Ma-.js";import{t as L}from"./format-size-CO9d3C3-.js";import{t as ee}from"./ClusterRecordingTab-qj7qdRav.js";import{t as R}from"./AdminTabs-DdlxkzYF.js";var z=N(`circle-x`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),B=N(`scissors`,[[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M8.12 8.12 12 12`,key:`1alkpv`}],[`path`,{d:`M20 4 8.12 15.88`,key:`xgtan2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M14.8 14.8 20 20`,key:`ptml3r`}]]);_();function V(e){let t=[];return e.timelapse?t.push(`timelapse ${String(e.timelapse.everyMs/1e3)}s`):(t.push(`${String(e.speed??1)}×`),e.includeAudio&&t.push(`+ audio`)),t.join(` `)}function H(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}function U(e,t){let n=Math.max(0,Math.round((t-e)/1e3)),r=Math.floor(n/3600),i=Math.floor(n%3600/60),a=n%60,o=r>0?`${String(r)}:${String(i).padStart(2,`0`)}:${String(a).padStart(2,`0`)}`:`${String(i)}:${String(a).padStart(2,`0`)}`;return`${H(e)} · ${o}`}function W(e,t){let n=e-t;if(n<=0)return`expired`;let r=Math.floor(n/6e4);if(r<60)return`in ${String(r)}m`;let i=Math.floor(r/60);return i<24?`in ${String(i)}h`:`in ${String(Math.floor(i/24))}d`}function G(e,t,n,r){return e.map(e=>{if(e.state===`expired`||e.state===`deleted`)return e;let i=r.get(e.id);if(i)return{...e,state:`failed`,error:i.error,progressPct:null};let a=n.get(e.id);if(a)return{...e,state:`ready`,fileBytes:a.fileBytes,progressPct:100};let o=t.get(e.id);return o&&(e.state===`queued`||e.state===`rendering`)?{...e,state:`rendering`,progressPct:o.progressPct}:e})}var K=[[`recordingExport`]],q={queued:{cls:`bg-muted text-foreground-subtle`,label:`queued`},rendering:{cls:`bg-primary/10 text-primary`,label:`rendering`,spin:!0},ready:{cls:`bg-success/10 text-success`,label:`ready`},failed:{cls:`bg-danger/10 text-danger`,label:`failed`},expired:{cls:`bg-muted text-foreground-subtle`,label:`expired`},deleted:{cls:`bg-muted text-foreground-subtle`,label:`deleted`}};function J(){let{data:e,isLoading:t}=u({},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`queued`||e.state===`rendering`)?3e3:!1}),{map:n}=i(w.RecordingExportProgress,e=>e.exportId),{map:r}=i(w.RecordingExportCompleted,e=>e.exportId),{map:a}=i(w.RecordingExportFailed,e=>e.exportId);return{rows:y(()=>G(e??[],n,r,a),[e,n,r,a]),isLoading:t}}function Y(e){let[t,n]=x(()=>Date.now());return C(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function X(){let t=b(),i=n(),a=E().trpcClient,o=Y(6e4),{rows:s,isLoading:l}=J(),{data:u}=d({}),f=y(()=>{let e=new Map;for(let t of u??[])e.set(t.id,t.name);return e},[u]),p=g(()=>{t.invalidateQueries({queryKey:K})},[t]),m=r({onSuccess:p}),_=e({onSuccess:p}),[C,w]=x(null),T=g(async e=>{w(e.id);try{let{url:t}=await a.recordingExport.getDownloadUrl.query({exportId:e.id}),n=await I(t),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.options.title??e.id}.mp4`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r),p()}finally{w(null)}},[a,p]),O=g(async e=>{await i({title:`Cancel this export?`,message:`Stops the render. The partial file is discarded.`,confirmLabel:`Cancel export`,variant:`danger`})&&m.mutate({exportId:e.id})},[i,m]),k=g(async e=>{await i({title:`Delete this export?`,message:`Permanently removes the rendered file and its history row.`,confirmLabel:`Delete`,variant:`danger`})&&_.mutate({exportId:e.id})},[i,_]),M=y(()=>[{key:`camera`,header:`Camera`,render:e=>S(`span`,{className:`text-foreground`,children:f.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`range`,header:`Range`,nowrap:!0,render:e=>S(`span`,{className:`tabular-nums`,children:U(e.fromMs,e.toMs)})},{key:`variant`,header:`Variant`,render:e=>S(`span`,{className:`text-foreground-subtle`,children:V(e.options)})},{key:`state`,header:`State`,render:e=>{let t=q[e.state];return v(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${t.cls}`,children:[t.spin&&S(j,{className:`h-2.5 w-2.5 animate-spin`}),t.label,e.state===`rendering`&&e.progressPct!==null&&v(`span`,{className:`tabular-nums`,children:[e.progressPct,`%`]})]})}},{key:`expiry`,header:`Expires`,nowrap:!0,render:e=>e.state===`deleted`?S(`span`,{className:`text-foreground-subtle`,children:`—`}):S(`span`,{className:`text-foreground-subtle tabular-nums`,children:W(e.expiresAt,o)})},{key:`size`,header:`Size`,align:`right`,nowrap:!0,render:e=>S(`span`,{className:`tabular-nums`,children:e.fileBytes===null?`—`:L(e.fileBytes)})},{key:`actions`,header:``,align:`right`,render:e=>{let t=e.state===`ready`,n=e.state===`queued`||e.state===`rendering`,r=e.state!==`deleted`;return v(`div`,{className:`flex items-center justify-end gap-1`,children:[t&&v(`button`,{onClick:()=>{T(e)},disabled:C===e.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-primary/10 hover:text-foreground disabled:opacity-50`,title:`Download MP4`,children:[C===e.id?S(j,{className:`h-3 w-3 animate-spin`}):S(D,{className:`h-3 w-3`}),`Download`]}),n&&v(`button`,{onClick:()=>{O(e)},disabled:m.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-amber-500/10 hover:text-amber-500 disabled:opacity-50`,title:`Cancel render`,children:[S(z,{className:`h-3 w-3`}),`Cancel`]}),r&&S(`button`,{onClick:()=>{k(e)},disabled:_.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 export`,children:S(P,{className:`h-3 w-3`})})]})}}],[f,o,C,m.isPending,_.isPending,T,O,k]);return l&&s.length===0?v(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[S(j,{className:`h-4 w-4 animate-spin`}),`Loading exports…`]}):s.length===0?S(h,{icon:A,title:`No exports yet`,description:`Export a footage range from a camera's timeline in the viewer. Rendered clips show up here to download or manage.`}):S(c,{columns:M,rows:s,rowKey:e=>e.id,minWidthPx:720})}_();var Z=[[`recording`]],Q=[{value:`retention`,label:`Retention policy`},{value:`quota`,label:`Quota / disk pressure`},{value:`operator`,label:`Operator`}];function te(e){return e.totalBytes===null||e.totalBytes<=0?null:Math.min(1,Math.max(0,e.usedBytes/e.totalBytes))}function ne(){let e=b(),t=n(),[r,i]=x(`retention`),{data:a,isLoading:o}=m({},{refetchOnWindowFocus:!1}),{data:s}=d({}),u=y(()=>{let e=new Map;for(let t of s??[])e.set(t.id,t.name);return e},[s]),f=g(()=>{e.invalidateQueries({queryKey:Z})},[e]),_=p({onSuccess:f}),C=l({onSuccess:f}),w=g(async e=>{await t({title:`Prune ${u.get(e.deviceId)??`#${String(e.deviceId)}`}?`,message:`Applies the retention policy now (reason: ${r}). Footage beyond the policy is permanently deleted.`,confirmLabel:`Prune now`,variant:`danger`})&&_.mutate({deviceId:e.deviceId,reason:r})},[t,_,r,u]),E=g(async e=>{await t({title:`Delete all footage for ${u.get(e.deviceId)??`#${String(e.deviceId)}`}?`,message:`Permanently deletes ${L(e.usedBytes)} of recorded footage for this camera. This cannot be undone.`,confirmLabel:`Delete ${L(e.usedBytes)}`,variant:`danger`})&&C.mutate({deviceId:e.deviceId})},[t,C,u]),D=y(()=>[{key:`camera`,header:`Camera`,render:e=>S(`span`,{className:`text-foreground`,children:u.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`used`,header:`Used`,align:`right`,nowrap:!0,render:e=>S(`span`,{className:`tabular-nums`,children:L(e.usedBytes)})},{key:`actions`,header:``,align:`right`,render:e=>v(`div`,{className:`flex items-center justify-end gap-1`,children:[v(`button`,{onClick:()=>{w(e)},disabled:_.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-amber-500/10 hover:text-amber-500 disabled:opacity-50`,title:`Apply retention policy now`,children:[S(B,{className:`h-3 w-3`}),`Prune`]}),v(`button`,{onClick:()=>{E(e)},disabled:C.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 all footage`,children:[S(P,{className:`h-3 w-3`}),`Delete`]})]})}],[u,w,E,_.isPending,C.isPending]);if(o&&!a)return v(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[S(j,{className:`h-4 w-4 animate-spin`}),`Loading storage usage…`]});if(!a)return S(h,{icon:O,title:`No storage data`,description:`The recording node has not reported any storage usage yet.`});let k=a.devices.length;return v(`div`,{className:`flex flex-col gap-6`,children:[v(`section`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:[S(T,{label:`Total used`,icon:S(O,{className:`h-3 w-3`}),footer:`${String(k)} camera${k===1?``:`s`} on ${a.nodeId}`,children:L(a.totalUsedBytes)}),a.locations.map(e=>{let t=te(e),n=e.locationId??`default`;return S(T,{label:`Disk ${n}`,footer:e.availableBytes===null?`${L(e.usedBytes)} used (capacity unknown)`:`${L(e.availableBytes)} free${e.totalBytes===null?``:` of ${L(e.totalBytes)}`}`,children:t===null?S(`span`,{className:`tabular-nums`,children:L(e.usedBytes)}):v(`div`,{className:`flex items-center gap-2`,children:[S(`div`,{className:`h-2 flex-1 overflow-hidden rounded bg-muted`,children:S(`div`,{className:`h-full rounded ${t>.9?`bg-danger`:t>.75?`bg-amber-500`:`bg-primary`}`,style:{width:`${String(Math.round(t*100))}%`}})}),v(`span`,{className:`tabular-nums text-xs`,children:[Math.round(t*100),`%`]})]})},n)})]}),v(`section`,{className:`flex items-center gap-2 text-xs`,children:[S(`label`,{htmlFor:`prune-reason`,className:`text-foreground-subtle`,children:`Prune reason`}),S(`select`,{id:`prune-reason`,value:r,onChange:e=>{let t=Q.find(t=>t.value===e.target.value);t&&i(t.value)},className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:Q.map(e=>S(`option`,{value:e.value,children:e.label},e.value))})]}),k===0?S(h,{icon:O,title:`No recorded footage`,description:`No camera has recorded footage on this node yet.`}):S(c,{columns:D,rows:[...a.devices],rowKey:e=>e.deviceId,minWidthPx:480})]})}_();var re=[[`pipelineAnalytics`]],ie=1440*60*1e3,ae=[{days:1,label:`1 day`},{days:7,label:`7 days`},{days:30,label:`30 days`},{days:90,label:`90 days`}];function oe(){let e=b(),r=n(),[i,s]=x(30),{data:l,isLoading:u}=t({},{refetchOnWindowFocus:!1}),{data:f}=d({}),p=y(()=>{let e=new Map;for(let t of f??[])e.set(t.id,t.name);return e},[f]),m=g(()=>{e.invalidateQueries({queryKey:re})},[e]),_=o({onSuccess:m}),C=a({onSuccess:m}),w=g(async()=>{await r({title:`Prune events older than ${String(i)} day${i===1?``:`s`}?`,message:`Permanently deletes every event (motion / object / audio) older than the cutoff across all cameras, and their media. This cannot be undone.`,confirmLabel:`Prune events`,variant:`danger`})&&_.mutate({olderThanMs:Date.now()-i*ie,reason:`retention`})},[r,_,i]),E=g(async e=>{await r({title:`Delete all events for ${p.get(e.deviceId)??`#${String(e.deviceId)}`}?`,message:`Permanently deletes ${String(e.rows)} event${e.rows===1?``:`s`} (${L(e.bytes)} of media) for this camera. This cannot be undone.`,confirmLabel:`Delete events`,variant:`danger`})&&C.mutate({deviceId:e.deviceId})},[r,C,p]),D=y(()=>[{key:`camera`,header:`Camera`,render:e=>S(`span`,{className:`text-foreground`,children:p.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`rows`,header:`Events`,align:`right`,nowrap:!0,render:e=>S(`span`,{className:`tabular-nums`,children:e.rows.toLocaleString()})},{key:`bytes`,header:`Media`,align:`right`,nowrap:!0,render:e=>S(`span`,{className:`tabular-nums`,children:L(e.bytes)})},{key:`actions`,header:``,align:`right`,render:e=>v(`button`,{onClick:()=>{E(e)},disabled:C.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 all events for this camera`,children:[S(P,{className:`h-3 w-3`}),`Delete`]})}],[p,E,C.isPending]);return u&&!l?v(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[S(j,{className:`h-4 w-4 animate-spin`}),`Loading event-store footprint…`]}):l?v(`div`,{className:`flex flex-col gap-6`,children:[v(`section`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[S(T,{label:`Total events`,icon:S(k,{className:`h-3 w-3`}),footer:`across ${String(l.devices.length)} camera${l.devices.length===1?``:`s`}`,children:l.totalRows.toLocaleString()}),S(T,{label:`Event media on disk`,children:L(l.totalBytes)})]}),v(`section`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[S(`span`,{className:`text-foreground-subtle`,children:`Prune events older than`}),S(`select`,{value:i,onChange:e=>s(Number(e.target.value)),className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:ae.map(e=>S(`option`,{value:e.days,children:e.label},e.days))}),v(`button`,{onClick:()=>{w()},disabled:_.isPending,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-xs font-medium text-foreground-subtle hover:bg-amber-500/10 hover:text-amber-500 disabled:opacity-50`,children:[_.isPending?S(j,{className:`h-3 w-3 animate-spin`}):S(B,{className:`h-3 w-3`}),`Prune now`]})]}),l.devices.length===0?S(h,{icon:k,title:`No stored events`,description:`No camera has persisted events yet.`}):S(c,{columns:D,rows:[...l.devices],rowKey:e=>e.deviceId,minWidthPx:480})]}):S(h,{icon:k,title:`No event data`,description:`Pipeline analytics has not reported any event-store footprint yet.`})}_();var $=[{value:`all`,label:`All`},{value:`recording`,label:`Recordings`},{value:`events`,label:`Events`}],se={recording:`bg-primary/10 text-primary`,events:`bg-violet-500/10 text-violet-400`};function ce(e){return new Date(e).toLocaleString()}function le(){let[e,t]=x(`all`),{data:n,isLoading:r}=f({},{refetchOnWindowFocus:!1}),{data:i,isLoading:a}=s({},{refetchOnWindowFocus:!1}),{data:o}=d({}),l=y(()=>{let e=new Map;for(let t of o??[])e.set(t.id,t.name);return e},[o]),u=y(()=>{let t=[...n??[],...i??[]];return(e===`all`?t:t.filter(t=>t.domain===e)).toSorted((e,t)=>t.at-e.at)},[n,i,e]),p=y(()=>[{key:`at`,header:`When`,nowrap:!0,render:e=>S(`span`,{className:`text-foreground-subtle tabular-nums`,children:ce(e.at)})},{key:`domain`,header:`Domain`,render:e=>S(`span`,{className:`inline-flex rounded px-1.5 py-0.5 text-[10px] font-medium ${se[e.domain]}`,children:e.domain})},{key:`op`,header:`Operation`,render:e=>S(`span`,{className:`text-foreground`,children:e.op})},{key:`reason`,header:`Reason`,render:e=>S(`span`,{className:`text-foreground-subtle`,children:e.reason})},{key:`device`,header:`Camera`,render:e=>e.deviceId===null?S(`span`,{className:`text-foreground-subtle`,children:`cluster`}):S(`span`,{className:`text-foreground`,children:l.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`items`,header:`Items`,align:`right`,nowrap:!0,render:e=>S(`span`,{className:`tabular-nums`,children:e.itemsAffected.toLocaleString()})},{key:`bytes`,header:`Reclaimed`,align:`right`,nowrap:!0,render:e=>S(`span`,{className:`tabular-nums`,children:e.bytesReclaimed>0?L(e.bytesReclaimed):`—`})}],[l]),m=r||a;return v(`div`,{className:`flex flex-col gap-4`,children:[S(`div`,{className:`flex items-center gap-1`,children:$.map(n=>S(`button`,{onClick:()=>t(n.value),className:`rounded px-2 py-1 text-xs font-medium ${e===n.value?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-muted`}`,children:n.label},n.value))}),m&&u.length===0?v(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[S(j,{className:`h-4 w-4 animate-spin`}),`Loading activity…`]}):u.length===0?S(h,{icon:M,title:`No activity yet`,description:`Prune, delete and rescan operations across recordings and events show up here.`}):S(c,{columns:p,rows:u,rowKey:e=>e.id,minWidthPx:720})]})}function ue(){return S(F,{icon:A,title:`Recordings`,subtitle:`Recording node & storage, event-store management, exported clips, and an activity log.`,children:S(R,{tabs:[{id:`recordings`,label:`Recordings`,icon:O,content:S(ee,{})},{id:`storage`,label:`Storage`,icon:O,content:S(ne,{})},{id:`events`,label:`Events`,icon:k,content:S(oe,{})},{id:`exports`,label:`Exports`,icon:A,content:S(X,{})},{id:`activity`,label:`Activity`,icon:M,content:S(le,{})}]})})}export{ue as RecordingsPage};
|