@camstack/addon-admin-ui 1.2.298 → 1.2.299
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddonCollectionPage-Df7TFa8c.js → AddonCollectionPage-Bgk5av4b.js} +1 -1
- package/dist/assets/{Addons-BL0l83HX.js → Addons-BiAma6AN.js} +1 -1
- package/dist/assets/{AdminTabs-_3rYGvff.js → AdminTabs-C7QmfUqk.js} +1 -1
- package/dist/assets/{AiProfiles-Cb_Zmt2e.js → AiProfiles-B4z9wywC.js} +1 -1
- package/dist/assets/{BrokerForm-O4qx5NOl.js → BrokerForm-lP42jKPi.js} +1 -1
- package/dist/assets/Build-6D08C629.js +32 -0
- package/dist/assets/{Capabilities-BhWA9I3U.js → Capabilities-BSbtmFZi.js} +1 -1
- package/dist/assets/{CapabilityBadges-E822NR6-.js → CapabilityBadges-Ck0Zi6v3.js} +1 -1
- package/dist/assets/{Cluster-CytT6oOR.js → Cluster-D8yFB0Np.js} +2 -2
- package/dist/assets/CompositionEditor-KckU34Rc.js +1 -0
- package/dist/assets/{CompositionEditorPage-D-Pr98e9.js → CompositionEditorPage-CPRkhwhE.js} +1 -1
- package/dist/assets/{Data-C_5nuknP.js → Data-CPY-GSWR.js} +1 -1
- package/dist/assets/{DetectionIntelligence-Ddu_ubPT.js → DetectionIntelligence-Bfo6e0Fm.js} +1 -1
- package/dist/assets/{DeviceAggregateSection-kHgMnzdV.js → DeviceAggregateSection-XoINX6MC.js} +1 -1
- package/dist/assets/DeviceDetail-BkOvR0zE.js +2 -0
- package/dist/assets/{Devices-CkDDnlUY.js → Devices-CBo87XTe.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-4bKTeu-8.js → EmbedPlayerPage-nlk8WGop.js} +1 -1
- package/dist/assets/Events-BTw7o3c3.js +1 -0
- package/dist/assets/{FormBuilder-DFkvqrJD.js → FormBuilder-DCWIHY3A.js} +1 -1
- package/dist/assets/{Identity-Bs0HMUZv.js → Identity-Z0uQisms.js} +1 -1
- package/dist/assets/IntegrationDetail-CxpJItTw.js +1 -0
- package/dist/assets/Integrations-CWQ4Bmhh.js +1 -0
- package/dist/assets/Integrations-CvQ2Qsiu.js +1 -0
- package/dist/assets/Locations-D-vr4FmX.js +3 -0
- package/dist/assets/{Logs-CdSMPoxV.js → Logs-MUeTxUBL.js} +1 -1
- package/dist/assets/{ModelLicenses-GuvIn1gk.js → ModelLicenses-D4ZI-ieb.js} +1 -1
- package/dist/assets/{MotionZonesSettings-C5cymw6R.js → MotionZonesSettings-eZjxA7t2.js} +1 -1
- package/dist/assets/{MyAccess-DKvcVvYi.js → MyAccess-BLNO_4Vb.js} +1 -1
- package/dist/assets/{Network-DO7j65It.js → Network-V-sOJFE3.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-Bj_BK8BK.js → NodeAddonsSettingsPanel-DeYrqSPH.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-DEF7iUIy.js → NodeInferenceDevices-BAdCG-8q.js} +1 -1
- package/dist/assets/Notifications-CVMvqEcL.js +1 -0
- package/dist/assets/{Pipeline-C3rd2o0z.js → Pipeline-Dv9QxF4V.js} +1 -1
- package/dist/assets/{Plates-KK9Jucpy.js → Plates-BxIKSjrx.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-DLWoWKa1.js → PrivacyMaskSettings-1wQ0sX0H.js} +1 -1
- package/dist/assets/{ProviderIcon-B95H0OGs.js → ProviderIcon-BbMyhwcl.js} +1 -1
- package/dist/assets/{Recordings-BIMt47G_.js → Recordings-C7qug-1m.js} +1 -1
- package/dist/assets/{ScanNetworkModal-C745HgYN.js → ScanNetworkModal-DK_tyixc.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-DEFeKrQi.js → SceneMonitorEditor-Ds9agOvV.js} +1 -1
- package/dist/assets/{Scenes-31t1OF8h.js → Scenes-Raq-0hCd.js} +1 -1
- package/dist/assets/{Settings-rfP-ZvI0.js → Settings-Ddx30tFk.js} +1 -1
- package/dist/assets/{Showroom-Df8NV8QK.js → Showroom-B8b26pPh.js} +1 -1
- package/dist/assets/{StorageLocationsPanel-DGsk0Ute.js → StorageLocationsPanel-DfOP9cjP.js} +1 -1
- package/dist/assets/{Terminal-CDJOGeqz.js → Terminal-BQlJcagf.js} +1 -1
- package/dist/assets/{Viewer-BjRST1rI.js → Viewer-Dugm0Lyh.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C4tT4btJ.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BGlzIG7f.js} +1 -1
- package/dist/assets/{archive-TrxiLNcl.js → archive-M1NkdyX1.js} +1 -1
- package/dist/assets/{authed-media-CH1U0Z7I.js → authed-media-BbclCn8D.js} +1 -1
- package/dist/assets/{boxes-BAiYOams.js → boxes-3RvvFSDa.js} +1 -1
- package/dist/assets/circle-slash-CSI0dVHX.js +1 -0
- package/dist/assets/{debounced-invalidate-BDeU9yPQ.js → debounced-invalidate-Dg1eT_Y-.js} +1 -1
- package/dist/assets/{device-integration-icon-CHkYoY0a.js → device-integration-icon-CteXz-vc.js} +1 -1
- package/dist/assets/device-picker-model-B29vbIKa.js +1 -0
- package/dist/assets/{dist-a0ex8Xy3.js → dist--LXFk-rO.js} +1 -1
- package/dist/assets/dist-B8s4O5ek.js +349 -0
- package/dist/assets/{face-bbox-BO4f9HS4.js → face-bbox-D0yJXCw6.js} +1 -1
- package/dist/assets/{hard-drive-download-DMTgloj5.js → hard-drive-download-DWkfRg_9.js} +1 -1
- package/dist/assets/{hostInit-DImvGASf.js → hostInit-1ItCQHp9.js} +1 -1
- package/dist/assets/{index-CgXPc-AV.js → index-BZ3TdH1g.js} +3 -3
- package/dist/assets/index-egLHRpbu.css +2 -0
- package/dist/assets/{layers-eROspUmA.js → layers-DkNaQ1QP.js} +1 -1
- package/dist/assets/{location-owned-usage-sOE3xLhc.js → location-owned-usage-BQ0INIT2.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-84890b2e.js → mf-entry-bootstrap-0-e02cda07.js} +2 -2
- package/dist/assets/{player-overlays-o54P23P2.js → player-overlays-B_uiidR6.js} +1 -1
- package/dist/assets/remoteEntry-CqjS7D1o.js +1 -0
- package/dist/assets/{send-D0d5eZ61.js → send-B_CQqzXx.js} +1 -1
- package/dist/assets/{settings-2-Dqj-Whfr.js → settings-2-BYvhRrnI.js} +1 -1
- package/dist/assets/{square-check-big-CC2dU6RF.js → square-check-big-DvgdtLa5.js} +1 -1
- package/dist/assets/{src-f3OJiuN1.js → src-B3pgYpGR.js} +8 -8
- package/dist/assets/src-BH2M3zRW.js +349 -0
- package/dist/assets/{use-scenes-feed-R-GEBDBU.js → use-scenes-feed-C3EryavW.js} +1 -1
- package/dist/assets/{use-stationary-objects-CO4PdIFG.js → use-stationary-objects-BM21l4YT.js} +1 -1
- package/dist/assets/{useDevice-BU0imY9B.js → useDevice-DPvLTx63.js} +1 -1
- package/dist/assets/useEventInvalidation-B0D6f62J.js +1 -0
- package/dist/assets/{useNodeUrlSelection-Dlf0CWPU.js → useNodeUrlSelection-DPB3ldG4.js} +1 -1
- package/dist/assets/user-round-BijBSyFY.js +1 -0
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DAaE-Myc.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Bu6krwIe.js} +2 -2
- package/dist/index.html +6 -6
- package/dist/server/addon.js +153 -89
- package/package.json +1 -1
- package/dist/assets/Build-CNQhG6ma.js +0 -32
- package/dist/assets/CompositionEditor-BhWVT7RV.js +0 -1
- package/dist/assets/DeviceDetail-BZJKkllF.js +0 -2
- package/dist/assets/Events-DoN_tLnP.js +0 -1
- package/dist/assets/IntegrationDetail-Cr5-tJiw.js +0 -1
- package/dist/assets/Integrations-D5LYSgWQ.js +0 -1
- package/dist/assets/Integrations-D5hX1u4b.js +0 -1
- package/dist/assets/Locations-NysPu2nw.js +0 -3
- package/dist/assets/Notifications-R4TlE5EH.js +0 -1
- package/dist/assets/circle-slash-Di12V3ul.js +0 -1
- package/dist/assets/dist-3HV5hQQl.js +0 -349
- package/dist/assets/index-DOZUgTMC.css +0 -2
- package/dist/assets/remoteEntry-nDKnWQvr.js +0 -1
- package/dist/assets/src-C36-vO5A.js +0 -349
- package/dist/assets/useEventInvalidation-BxCnrh5u.js +0 -1
- package/dist/assets/user-round-CXdkrmGZ.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{G as e,I as t,K as n,Q as r,S as i,b as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as l}from"./player-overlays-o54P23P2.js";import{B as u,H as d,Rr as f,Vr as p,_i as m,an as h,c as g,cn as _,qi as v,tn as y,vi as b}from"./src-f3OJiuN1.js";import{Dt as x,Mn as S,Nn as C,Ot as w,Pn as ee,Tn as T,_n as te,bn as E,fn as ne,gn as re,jn as D,ln as O,mn as ie,pn as ae,vn as k,wn as A,xn as j,yn as M}from"./src-C36-vO5A.js";import{l as N}from"./index-CgXPc-AV.js";r();function oe(e){return{target:{kind:`new`,type:e},name:``,features:[]}}function se(e){return{target:{kind:`existing`,device:e},name:``,features:[]}}function ce(e,t){return{target:e.target,name:t,features:e.features.flatMap(e=>e.kind===`fields`?[e]:[])}}function P(e,t,n){return{...e,features:e.features.map(e=>e.cap===t?n(e):e)}}function le(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>e!==t))}function ue(e,t){switch(t.type){case`set-new-type`:return e.target.kind===`new`?{...e,target:{...e.target,type:t.deviceType}}:e;case`set-new-role`:{if(e.target.kind!==`new`)return e;let{role:n,...r}=e.target;return{...e,target:t.role===null?r:{...r,role:t.role}}}case`set-name`:return{...e,name:t.name};case`add-feature`:return e.features.some(e=>e.cap===t.cap)?e:{...e,features:[...e.features,{kind:`fields`,cap:t.cap,fields:{}}]};case`remove-feature`:return{...e,features:e.features.filter(e=>e.cap!==t.cap)};case`set-field`:return P(e,t.cap,e=>({...e,fields:{...e.fields,[t.path]:t.source}}));case`clear-field`:return P(e,t.cap,e=>({...e,fields:le(e.fields,t.path)}));case`copy-feature`:return P(e,t.cap,e=>({...e,fields:{...e.fields,...Object.fromEntries(t.paths.map(e=>[e,{kind:`from`,source:t.from,cap:t.sourceCap,fieldPath:e}]))}}))}}function de(e){let t=ie.safeParse({target:e.target,features:e.features});return t.success?{ok:!0,composition:t.data}:{ok:!1,problems:t.error.issues.map(e=>`${e.path.join(`.`)||`composition`}: ${e.message}`)}}function fe(e){for(let t=1;;t++){let n=`s${t}`;if(!e.includes(n))return n}}function F(e){return{addonId:e.addonId,stableId:e.stableId}}function I(e){return new Map(e.map(e=>[E(F(e)),e]))}function pe(e,t,n){return e.filter(e=>e.id!==n&&e.type!==T.Container&&t.includes(e.id)).toSorted((e,t)=>e.name.localeCompare(t.name))}function me(e,t,n){let r=e?.features??[],i=r.findIndex(e=>e.cap===n.cap);return{target:e?.target??{kind:`existing`,device:t},features:i===-1?[...r,n]:r.map((e,t)=>t===i?n:e)}}function he(e,t){let n=e.features.filter(e=>e.cap!==t);return n.length===0?null:{target:e.target,features:n}}function ge(e,t){let n=e?.features.find(e=>e.cap===t);return n!==void 0&&n.kind===`fields`?n:null}function L(e){return Array.isArray(e)?e.map(L):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,L(t)]))}function R(e){return JSON.stringify(L(e))}function z(e,t){return R(e)===R(t)}function _e(e,t){switch(e.kind){case`pending`:return{kind:`refused`,reason:`the customization has not been read yet — try again`};case`unknown`:return{kind:`refused`,reason:`the customization could not be read: ${e.reason}`};case`not-loaded`:return{kind:`refused`,reason:`the customizations are not loaded yet: ${e.reason}`};case`none`:return t===null?{kind:`noop`}:{kind:`create`,input:{enabled:!0,composition:t}};case`present`:{let n=e.view.block.id;return t===null?{kind:`delete`,blockId:n}:R(t)===R(e.composition)?{kind:`noop`}:{kind:`update`,blockId:n,expectedUpdatedAt:e.view.block.updatedAt,composition:t}}}}function B(e,t){let n=e===`enum`?`string`:e,r=t.kind===`enum`?`string`:t.kind,i={source:t.source,cap:t.cap,fieldPath:t.fieldPath};return r===n?{kind:`from`,...i}:n===`number`&&r===`string`?{kind:`expression`,expr:`number(x)`,bindings:{x:{kind:`from`,...i}}}:null}function V(e){return{kind:`expression`,expr:e,bindings:{}}}function H(e){let t=B(`number`,e.percentage);return t===null?null:{kind:`fields`,cap:`battery`,fields:e.mode===`replace`?{percentage:t}:{percentage:t,charging:V(`"unknown"`),sleeping:V(`false`),lastUpdated:V(`now`)}}}var U=C.filter(e=>e!==`switch`&&e!==`motion`);function ve(e){let t=ee[e.cap];return t===void 0||!U.includes(e.cap)?null:{kind:`fields`,cap:e.cap,fields:{[t]:{kind:`expression`,expr:`!v`,bindings:{v:{kind:`from`,source:e.self,cap:e.cap,fieldPath:t}}}}}}function ye(e){return e.from===e.to||!w(e.from,e.to)?null:{kind:`fields`,cap:e.cap,fields:{[e.fieldPath]:{kind:`expression`,expr:`convert(v, ${JSON.stringify(e.from)}, ${JSON.stringify(e.to)})`,bindings:{v:{kind:`from`,source:e.self,cap:e.cap,fieldPath:e.fieldPath}}},...e.unitField===null?{}:{[e.unitField]:V(JSON.stringify(e.to))}}}}function be(e,t){let n=B(`number`,t.remaining);if(n===null||!ae.test(t.key)||t.label.trim()===``)return null;let r={label:t.label.trim(),fields:{"remaining.value":n,"remaining.unit":V(JSON.stringify(t.unit))}};return{kind:`fields`,cap:`consumables`,...e?.enabled===void 0?{}:{enabled:e.enabled},fields:e?.fields??{lastChangedAt:V(`now`),lastFetchedAt:V(`now`)},items:{...e?.items,[t.key]:r}}}function xe(e){return e.toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,48)}function Se(e){let t=e.fields.lastPressedAt;if(t===void 0||t.kind!==`expression`)return[];let n=Object.entries(t.bindings).filter(([e])=>e.startsWith(`active`)).flatMap(([,e])=>e.kind===`from`?[e.source]:[]);return[...new Map(n.map(e=>[E(e),e])).values()]}function Ce(e){let t=e.fields.lastPressedAt;if(t===void 0||t.kind!==`expression`)return[];let n=t.bindings;return Object.entries(n).flatMap(([e,t])=>{if(!e.startsWith(`active`)||t.kind!==`from`)return[];let r=n[`changed${e.slice(6)}`];return r===void 0||r.kind!==`from`?[]:[{source:t.source,cap:t.cap,activeField:t.fieldPath,changedAtField:r.fieldPath}]})}function we(e){if(e===void 0)return null;if(e.kind===`from`){let{kind:t,...n}=e;return{...n,kind:`number`}}if(e.kind!==`expression`||e.expr!==`number(x)`)return null;let t=e.bindings.x;if(t===void 0||t.kind!==`from`||Object.keys(e.bindings).length!==1)return null;let{kind:n,...r}=t;return{...r,kind:`string`}}function Te(e,t){let n=we(e.fields.percentage);if(n===null)return!1;let r=H({percentage:n,mode:t}),{enabled:i,...a}=e;return r!==null&&z(a,r)}function W(e){return e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,location:e.location,type:e.type}))}function Ee(e,t,n){let r=t.trim().toLowerCase();return r===``?[]:e.filter(e=>!n.includes(e.id)&&[e.name,e.stableId,e.location??``].some(e=>e.toLowerCase().includes(r))).toSorted((e,t)=>e.name.localeCompare(t.name)).slice(0,20)}function G(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n||Array.isArray(n))return;n=Object.getOwnPropertyDescriptor(n,e)?.value}return n}function De(e,t,n,r){return r===null?{kind:`from`,source:e,cap:t,fieldPath:n.path}:B(r,{source:e,cap:t,fieldPath:n.path,kind:n.kind})}function Oe(e,t,n,r){let i={addonId:e.addonId,stableId:e.stableId};return t.caps.flatMap(e=>e.fields.filter(e=>e.item!==!0).map(t=>({cap:e.cap,path:t.path,kind:t.kind,value:n===null?void 0:G(n[e.cap],t.path),source:De(i,e.cap,t,r)})))}function K(e,t){return t?e===void 0?`—`:e===null?`null`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e):`…`}var ke=[];function q({title:e,targetKind:t,excludeDeviceIds:n=ke,onPick:r,onCancel:a}){let{t:c}=N(),[l,u]=o(null);return i(`aside`,{"aria-label":e,className:`rounded-lg border border-border bg-surface p-3 flex flex-col gap-2`,children:[s(`h3`,{className:`text-xs font-semibold`,children:e}),l===null?s(Ae,{excludeDeviceIds:n,onSelect:u}):s(je,{device:l,targetKind:t,onPick:r,onBack:()=>u(null)}),s(`div`,{children:s(_,{variant:`ghost`,onClick:a,children:c(`customize.picker.cancel`)})})]})}function Ae({excludeDeviceIds:e,onSelect:t}){let{t:n}=N(),[r,c]=o(``),l=b({projection:`slim`});return i(a,{children:[i(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`customize.picker.search`),s(`input`,{type:`search`,"aria-label":n(`customize.picker.search`),className:`px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`,value:r,onChange:e=>c(e.target.value)})]}),l.status===`pending`&&s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:n(`customize.picker.loadingDevices`)}),l.status===`error`&&s(h,{title:n(`customize.picker.devicesFailed`),message:l.error?.message??``}),l.status===`success`&&s(`ul`,{className:`flex flex-col gap-1`,children:Ee(W(l.data),r,e).map(e=>s(`li`,{children:i(`button`,{type:`button`,className:`text-left text-[11px] hover:underline`,onClick:()=>t(e),children:[e.name,` `,i(`span`,{className:`text-foreground-subtle`,children:[`· `,e.stableId]})]})},e.id))})]})}function je({device:e,targetKind:t,onPick:n,onBack:r}){let{t:a}=N(),o=m({deviceId:e.id}),c=v({deviceId:e.id});if(o.status===`pending`)return s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:a(`customize.picker.loadingFields`)});if(o.status===`error`)return s(h,{title:a(`customize.picker.fieldsFailed`),message:o.error?.message??``});let l=Oe(e,o.data,c.status===`success`?c.data:null,t),u=l.filter(e=>e.source===null).length,d={addonId:e.addonId,stableId:e.stableId};return i(`div`,{className:`flex flex-col gap-1`,children:[i(`button`,{type:`button`,className:`text-left text-[11px] text-primary`,onClick:r,children:[`← `,e.name]}),c.status===`error`&&s(`p`,{role:`alert`,className:`text-[10px] text-warning`,children:a(`customize.picker.valuesFailed`,{reason:c.error?.message??``})}),s(`ul`,{role:`listbox`,"aria-label":a(`customize.picker.fields`),className:`flex flex-col gap-1`,children:l.map(t=>{let r=t.source;if(r===null)return null;let a=()=>n({device:e,ref:d,cap:t.cap,path:t.path,kind:t.kind,source:r,value:t.value});return i(`li`,{role:`option`,"aria-selected":!1,tabIndex:0,className:`flex justify-between gap-2 text-[11px] cursor-pointer hover:bg-surface-hover rounded px-1`,onClick:a,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&a()},children:[i(`span`,{className:`font-mono`,children:[t.cap,`.`,t.path]}),s(`span`,{children:K(t.value,c.status===`success`)})]},`${t.cap}.${t.path}`)})}),u>0&&t!==null&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:a(`customize.picker.hidden`,{count:u,kind:a(`customize.kinds.${t}`)})})]})}var J=`integration`;function Y(e,t){switch(e.kind){case`from`:{let n=E(e.source);return`${t.get(n)??n} · ${e.cap}.${e.fieldPath}`}case`expression`:return e.expr;case`code`:return`code`}}function Me(e,t){if(e.kind===`unreachable`)return{kind:`unknown`,reason:e.error};if(e.state===null)return{kind:`unknown`,reason:`the composer has not reported this customization yet`};let n=e.state.fields.find(t);return n===void 0?{kind:`unknown`,reason:`the composer reports no value for this field`}:n.state===`unavailable`?{kind:`unavailable`,reason:n.reason??`unavailable`}:{kind:`value`,value:n.value,staleReason:n.state===`stale`?n.reason??`stale`:null}}function X(e,t,n,r){return{key:`${e.feature.cap}.${t}`,cap:e.feature.cap,field:t,origin:`composed`,mode:e.mode,from:Y(n,e.input.sourceNames),value:e.enabled?Me(e.input.state,r):{kind:`off`}}}function Ne(e){let t=e.feature.cap;return Object.entries(e.feature.fields).map(([n,r])=>X(e,n,r,e=>e.cap===t&&e.path===n&&e.item===void 0))}function Pe(e){let t=e.feature.cap;return Object.entries(e.feature.items??{}).flatMap(([n,r])=>Object.entries(r.fields).map(([r,i])=>X(e,te(ne,n,r),i,e=>e.cap===t&&e.path===r&&e.item?.arrayPath===`items`&&e.item.key===n)))}function Fe(e,t,n){if(e===null)return{kind:`unknown`,reason:`the device state could not be read`};let r=G(e[t],n),i=r===void 0?void 0:D(r);return i===void 0?{kind:`unknown`,reason:`not reported`}:{kind:`value`,value:i,staleReason:null}}function Ie(e){if(e.mode!==`replace`)return[];let t=e.feature.cap,n=new Set(Object.keys(e.feature.fields));return(e.input.nativeFields.get(t)??[]).filter(e=>!n.has(e)).map(n=>({key:`${t}.${n}`,cap:t,field:n,origin:`native`,mode:e.mode,from:J,value:Fe(e.input.snapshot,t,n)}))}function Le(e){return e.composition.features.flatMap(t=>{if(t.kind!==`fields`)return[];let n={feature:t,mode:e.nativeCaps.has(t.cap)?`replace`:`add`,enabled:re(t),input:e};return[...Ne(n),...Pe(n),...Ie(n)]})}var Re={min:`min(a, b, …)`,max:`max(a, b, …)`,abs:`abs(x)`,floor:`floor(x)`,ceil:`ceil(x)`,sqrt:`sqrt(x)`,round:`round(x, digits?)`,pow:`pow(x, y)`,clamp:`clamp(x, lo, hi)`,avg:`avg(a, b, …)`,sum:`sum(a, b, …)`,coalesce:`coalesce(a, b, …)`,age:`age(now, ts)`,convert:`convert(x, "from", "to")`,any:`any(a, b, …)`,all:`all(a, b, …)`,within:`within(ts, ms)`,number:`number(x)`,latest:`latest(ts, …)`,rose:`rose(level, changedAt, debounceMs?)`,count:`count(x)`},Z=/[A-Za-z_][A-Za-z0-9_]*$/;function ze(e,t,n){let r=Z.exec(e.slice(0,t))?.[0]??``;if(r===``)return[];let i=n.filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`binding`,label:e,insert:e,hintKey:null})),a=`now`.startsWith(r)?[{kind:`now`,label:`now`,insert:`now`,hintKey:`compositionEditor.now`}]:[],o=[...S].filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`builtin`,label:Re[e]??e,insert:`${e}(`,hintKey:`compositionEditor.builtins.${e}`}));return[...i,...a,...o].slice(0,8)}function Be(e,t,n){let r=t-(Z.exec(e.slice(0,t))?.[0]??``).length;return{text:`${e.slice(0,r)}${n.insert}${e.slice(t)}`,cursor:r+n.insert.length}}r();function Ve({label:e,value:t,bindings:r,onChange:a}){let{t:c}=N(),l=n(null),[u,d]=o(t.length),f=ze(t,u,r);return i(`div`,{className:`flex flex-col gap-1`,children:[i(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[e,s(`input`,{ref:l,className:`font-mono px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`,value:t,onChange:e=>{a(e.target.value),d(e.target.selectionStart??e.target.value.length)},onSelect:e=>d(e.currentTarget.selectionStart??t.length)})]}),f.length>0&&s(`ul`,{role:`listbox`,"aria-label":c(`compositionEditor.suggestions`),className:`rounded border border-border bg-surface text-[11px]`,children:f.map(e=>i(`li`,{role:`option`,"aria-selected":!1,tabIndex:0,className:`flex justify-between gap-2 px-1 cursor-pointer hover:bg-surface-hover`,onClick:()=>{let n=Be(t,u,e);a(n.text),d(n.cursor),l.current?.focus()},children:[s(`span`,{className:`font-mono`,children:e.label}),e.hintKey!==null&&s(`span`,{className:`text-foreground-subtle`,children:c(e.hintKey)})]},`${e.kind}:${e.label}`))})]})}function He(e,t,n){if(e.kind===`code`)return{kind:`unavailable`,reason:`code fields arrive in slice 4`};if(e.kind===`expression`&&(O(e.expr,`rose`)||O(e.expr,`count`)))return{kind:`runtime-only`};let r=j(e).filter(e=>t.get(M(e.source,e.cap))?.kind!==`value`).map(k);if(r.length>0)return{kind:`waiting`,missing:r};let i=x({source:e,now:n,read:e=>{let n=t.get(M(e.source,e.cap)),r=n?.kind===`value`?G(n.slice,e.fieldPath):void 0,i=r===void 0?void 0:D(r);return i===void 0?{state:`unavailable`,reason:`${e.cap}.${e.fieldPath} is not reported`,fatal:!1}:{state:`fresh`,value:i}}});return i.state===`unavailable`?{kind:`unavailable`,reason:i.reason}:{kind:`value`,value:i.value,stale:i.reason}}r();function Ue({sliceKey:e,deviceId:t,capName:n,onReading:r}){let i=g(l().trpcClient,t,n);return c(()=>{r(e,i===void 0?{kind:`pending`}:{kind:`value`,slice:i})},[e,i,r]),null}function We(e,t){return[...new Map(j(e).map(e=>[M(e.source,e.cap),e]))].map(([e,n])=>({key:e,read:n,device:t.get(E(n.source))}))}function Ge({source:e}){let{t:n}=N(),r=b({projection:`slim`}),[a,c]=o(new Map),l=t((e,t)=>{c(n=>new Map([...n,[e,t]]))},[]),u=We(e,I(r.status===`success`?W(r.data):[])),d=r.status===`success`?u.filter(e=>e.device===void 0).map(e=>E(e.read.source)):[];return i(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[u.map(e=>e.device===void 0?null:s(Ue,{sliceKey:e.key,deviceId:e.device.id,capName:e.read.cap,onReading:l},e.key)),s(`span`,{className:`text-foreground-subtle`,children:n(`compositionEditor.preview.label`)}),r.status===`error`?s(`span`,{className:`text-warning`,children:n(`compositionEditor.preview.devicesFailed`,{reason:r.error?.message??``})}):d.length>0?s(`span`,{className:`text-warning`,children:n(`compositionEditor.preview.unknownDevice`,{sources:d.join(`, `)})}):s(Ke,{preview:He(e,a,Date.now())})]})}function Ke({preview:e}){let{t}=N();switch(e.kind){case`value`:return i(`strong`,{children:[`→ `,K(e.value,!0),e.stale===null?``:` (${e.stale})`]});case`unavailable`:return s(`span`,{className:`text-warning`,children:e.reason});case`waiting`:return s(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.waiting`,{sources:e.missing.join(`, `)})});case`runtime-only`:return s(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.runtimeOnly`)})}}r();function qe({path:e,kind:t,required:n,source:r,onSet:c,onClear:l,sourceNames:u}){let{t:d}=N(),[f,p]=o(`idle`),m=r?.kind===`expression`?r:null;return i(`div`,{className:`flex flex-col gap-1 rounded border border-border p-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[s(`span`,{className:`font-mono text-[11px]`,children:e}),i(`span`,{className:`text-[10px] text-foreground-subtle`,children:[d(`customize.kinds.${t}`),n?` · ${d(`compositionEditor.required`)}`:``]}),s(_,{size:`sm`,variant:`outline`,onClick:()=>p(`take`),children:d(`compositionEditor.takeFrom`)}),s(_,{size:`sm`,variant:`outline`,"aria-pressed":m!==null,onClick:()=>c(m??{kind:`expression`,expr:`null`,bindings:{}}),children:d(`compositionEditor.formula`)}),r!==void 0&&s(_,{size:`sm`,variant:`ghost`,onClick:l,children:d(`compositionEditor.clear`)})]}),r?.kind===`from`&&s(`span`,{className:`text-[11px]`,children:Y(r,u)}),m!==null&&i(a,{children:[s(Ve,{label:d(`compositionEditor.formulaFor`,{path:e}),value:m.expr,bindings:Object.keys(m.bindings),onChange:e=>c({...m,expr:e})}),s(`ul`,{className:`text-[11px] flex flex-col gap-0.5`,children:Object.entries(m.bindings).map(([e,t])=>i(`li`,{className:`flex gap-2`,children:[s(`span`,{className:`font-mono`,children:e}),s(`span`,{children:t.kind===`from`?Y(t,u):JSON.stringify(t.value)})]},e))}),s(_,{size:`sm`,variant:`ghost`,onClick:()=>p(`add-binding`),children:d(`compositionEditor.addSource`)})]}),f!==`idle`&&s(q,{title:d(f===`take`?`compositionEditor.takeFrom`:`compositionEditor.addSource`),targetKind:f===`take`?t:null,onCancel:()=>p(`idle`),onPick:e=>{if(f===`take`)c(e.source);else if(m!==null){let t=fe(Object.keys(m.bindings));c({...m,bindings:{...m.bindings,[t]:{kind:`from`,source:e.ref,cap:e.cap,fieldPath:e.path}}})}p(`idle`)}}),r!==void 0&&s(Ge,{source:r})]})}r();function Q(e){return e===null||e.kind===`known`?null:e}function Je({draft:e,deviceType:t,nativeCaps:n,targetFields:r,dispatch:c}){let{t:l}=N(),u=f({deviceType:t}),d=b({projection:`slim`}),p=new Map([...I(d.status===`success`?W(d.data):[])].map(([e,t])=>[e,t.name])),[m,h]=o(null),g=Q(n)??Q(r),v=n?.kind===`known`?n.value:new Set,x=new Set(e.features.map(e=>e.cap)),S=u.status===`success`?u.data.caps.filter(e=>!x.has(e.cap)&&!v.has(e.cap)):[],C=[...v].filter(e=>!x.has(e)),w=e=>v.has(e)?((r?.kind===`known`?r.value.caps.find(t=>t.cap===e):void 0)?.fields??[]).filter(e=>e.item!==!0&&!e.path.includes(`.`)).map(e=>({path:e.path,kind:e.kind,required:!1})):((u.status===`success`?u.data.caps.find(t=>t.cap===e):void 0)?.fields??[]).map(e=>({path:e.path,kind:e.kind,required:e.required}));return g===null?i(a,{children:[i(`section`,{"aria-labelledby":`editor-features`,className:`flex flex-col gap-2`,children:[s(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),u.status===`pending`&&s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`customize.presets.checking`)}),u.status===`error`&&s(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`customize.presets.unknown`,{reason:u.error?.message??``})}),i(`div`,{className:`flex flex-wrap gap-1`,children:[e.features.map(e=>i(`span`,{className:`flex items-center gap-1 rounded border border-border px-1.5 text-[11px]`,children:[e.cap,s(y,{variant:v.has(e.cap)?`default`:`info`,children:v.has(e.cap)?l(`compositionEditor.replaces`):l(`customize.fields.added`)}),s(`button`,{type:`button`,"aria-label":l(`compositionEditor.removeFeature`,{cap:e.cap}),onClick:()=>c({type:`remove-feature`,cap:e.cap}),children:`×`})]},e.cap)),S.map(e=>i(_,{size:`sm`,variant:`outline`,onClick:()=>c({type:`add-feature`,cap:e.cap}),children:[`+ `,e.cap]},e.cap)),C.map(e=>s(_,{size:`sm`,variant:`ghost`,onClick:()=>c({type:`add-feature`,cap:e}),children:l(`compositionEditor.replaceIn`,{cap:e})},e))]})]}),e.features.map(e=>i(`section`,{"aria-label":l(`compositionEditor.steps.fieldsOf`,{cap:e.cap}),className:`flex flex-col gap-2`,children:[i(`div`,{className:`flex items-center justify-between`,children:[s(`h2`,{className:`text-sm font-semibold`,children:l(`compositionEditor.steps.fieldsOf`,{cap:e.cap})}),s(_,{size:`sm`,variant:`outline`,onClick:()=>h(e.cap),children:l(`compositionEditor.copyFeature`)})]}),m===e.cap&&s(q,{title:l(`compositionEditor.copyFeature`),targetKind:null,onCancel:()=>h(null),onPick:t=>{c({type:`copy-feature`,cap:e.cap,from:t.ref,sourceCap:t.cap,paths:w(e.cap).map(e=>e.path)}),h(null)}}),w(e.cap).map(t=>s(qe,{path:t.path,kind:t.kind,required:t.required,source:e.fields[t.path],onSet:n=>c({type:`set-field`,cap:e.cap,path:t.path,source:n}),onClear:()=>c({type:`clear-field`,cap:e.cap,path:t.path}),sourceNames:p},t.path))]},e.cap))]}):i(`section`,{"aria-labelledby":`editor-features`,className:`flex flex-col gap-2`,children:[s(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:g.kind===`unknown`?g.reason:l(`customize.fields.reading`)})]})}var $=`px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`;function Ye({draft:e,targetName:t,dispatch:n}){let{t:r}=N(),a=e.target;return i(`section`,{"aria-labelledby":`editor-target`,className:`flex flex-col gap-2`,children:[s(`h2`,{id:`editor-target`,className:`text-sm font-semibold`,children:r(`compositionEditor.steps.target`)}),a.kind===`existing`?s(`p`,{className:`text-[11px]`,children:r(`compositionEditor.existingTarget`,{name:t??`${a.device.addonId}/${a.device.stableId}`})}):i(`div`,{className:`grid grid-cols-3 gap-2`,children:[i(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[r(`customize.identity.type`),s(`select`,{className:$,value:a.type,onChange:e=>{let t=Object.values(T).find(t=>t===e.target.value);t!==void 0&&n({type:`set-new-type`,deviceType:t})},children:Object.values(T).map(e=>s(`option`,{value:e,children:d(e).label},e))})]}),i(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[r(`customize.identity.role`),i(`select`,{className:$,value:a.role??``,onChange:e=>n({type:`set-new-role`,role:Object.values(A).find(t=>t===e.target.value)??null}),children:[s(`option`,{value:``,children:r(`customize.identity.noRole`)}),Object.values(A).map(e=>s(`option`,{value:e,children:u(e).label},e))]})]}),i(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[r(`compositionEditor.name`),s(`input`,{className:$,value:e.name,onChange:e=>n({type:`set-name`,name:e.target.value})})]})]})]})}r();function Xe({draft:e,blockId:t,saving:n,onSave:r,onCancel:a}){let{t:l}=N(),u=p(),d=de(e),f=d.ok?JSON.stringify(d.composition):``,[m,h]=o({key:``,state:{kind:`checking`}});c(()=>{if(!d.ok)return;let e=d.composition,n=setTimeout(()=>{u.mutateAsync({composition:e,...t===null?{}:{blockId:t}}).then(e=>h({key:f,state:e.ok?{kind:`ok`}:{kind:`refused`,problems:e.problems}})).catch(e=>h({key:f,state:{kind:`unknown`,reason:e instanceof Error?e.message:String(e)}}))},500);return()=>clearTimeout(n)},[f,t]);let g=d.ok?m.key===f?m.state:{kind:`checking`}:{kind:`invalid-draft`,problems:d.problems};return i(`section`,{"aria-labelledby":`editor-verify`,className:`flex flex-col gap-2`,children:[s(`h2`,{id:`editor-verify`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.verify`)}),g.kind===`checking`&&s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.verify.checking`)}),g.kind===`ok`&&s(`p`,{className:`text-[11px] text-success`,children:l(`compositionEditor.verify.ok`)}),g.kind===`unknown`&&s(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.verify.unknown`,{reason:g.reason})}),(g.kind===`invalid-draft`||g.kind===`refused`)&&s(`ul`,{role:`alert`,className:`flex flex-col gap-1 text-[11px] text-danger`,children:g.kind===`invalid-draft`?g.problems.map(e=>s(`li`,{children:e},e)):g.problems.map(e=>i(`li`,{children:[s(`span`,{className:`font-mono`,children:e.path}),` — `,e.message]},`${e.path}:${e.code}`))}),i(`div`,{className:`flex gap-2`,children:[s(_,{variant:`ghost`,onClick:a,children:l(`compositionEditor.cancel`)}),s(_,{disabled:g.kind!==`ok`||n||!d.ok,onClick:()=>d.ok&&r(d.composition),children:l(`compositionEditor.save`)})]})]})}r();function Ze({initial:t,blockId:n,deviceType:r,targetName:a=null,nativeCaps:c,targetFields:l,save:u,onCancel:d}){let[f,p]=e(ue,t),[m,h]=o(!1),[g,_]=o(null),v=f.target.kind===`new`?f.target.type:r,y=async e=>{h(!0);let t=await u(e,f.name);h(!1),_(t.kind===`refused`?t.reason:null)};return i(`div`,{className:`flex flex-col gap-4`,children:[s(Ye,{draft:f,targetName:a,dispatch:p}),s(Je,{draft:f,deviceType:v,nativeCaps:c,targetFields:l,dispatch:p}),s(Xe,{draft:f,blockId:n,saving:m,onSave:e=>void y(e),onCancel:d}),g!==null&&s(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:g})]})}export{pe as C,oe as D,se as E,I as S,ce as T,ge as _,K as a,me as b,U as c,ye as d,Se as f,xe as g,Te as h,q as i,H as l,ve as m,J as n,G as o,Ce as p,Le as r,W as s,Ze as t,be as u,_e as v,F as w,he as x,z as y};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,a,b as o,o as s,q as c,t as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{G as f,U as p,W as m,X as h,_ as g,at as _,ht as v,lt as y,mt as b,q as x,r as S,st as C,t as w,ut as T,vt as E,yt as D}from"./player-overlays-o54P23P2.js";import{$ as O,$o as k,$t as A,A as j,Al as M,B as N,Bi as P,Bl as ee,Br as F,Ci as te,Ct as I,Dt as ne,Eu as L,Fi as R,Fl as re,Fo as ie,Fr as z,G as ae,Gc as oe,H as B,Ha as V,Hi as H,Ht as se,I as ce,Il as le,Iu as ue,Ja as de,Jc as U,Jl as fe,Ju as pe,K as me,Kl as he,Kr as ge,L as W,Ll as _e,Lr as ve,M as ye,Mo as be,N as xe,Nu as Se,O as Ce,Oi as we,Ol as Te,Oo as Ee,P as De,Pi as Oe,Pr as ke,Q as G,Qc as Ae,Ql as je,Qo as Me,Qt as Ne,Rc as Pe,Rr as Fe,St as Ie,Ti as Le,Tt as Re,Tu as ze,U as Be,Ur as Ve,Ut as He,Vi as Ue,Vt as We,Vu as Ge,W as Ke,Wi as qe,Wl as Je,Wr as Ye,Wt as Xe,X as Ze,Xl as Qe,Xu as $e,Y as et,Ya as tt,Yc as nt,Yn as rt,Yu as it,Z as at,Zo as ot,_a as st,_i as ct,_t as lt,a as ut,an as dt,b as ft,bi as pt,bt as mt,c as ht,cd as gt,cn as K,d as _t,di as vt,dr as yt,du as bt,en as xt,es as St,et as Ct,f as wt,fa as Tt,ga as Et,gi as Dt,gn as Ot,gt as kt,hi as At,hn as jt,ht as Mt,i as Nt,ii as Pt,in as Ft,j as It,jo as Lt,ko as Rt,l as zt,li as Bt,ln as Vt,mi as q,mn as Ht,nu as Ut,o as Wt,os as Gt,q as Kt,qi as qt,ql as Jt,r as Yt,rn as Xt,ru as Zt,s as Qt,st as $t,ti as en,tn as J,tt as tn,u as nn,ui as rn,ut as an,v as on,va as sn,vi as cn,w as ln,wt as un,x as dn,xs as fn,xt as pn,y as mn,yi as hn,yl as gn,yn as _n,yt as vn,zi as yn,zo as bn}from"./src-f3OJiuN1.js";import{t as xn}from"./archive-TrxiLNcl.js";import{t as Sn}from"./boxes-BAiYOams.js";import{t as Cn}from"./ProviderIcon-B95H0OGs.js";import{t as wn}from"./circle-slash-Di12V3ul.js";import{n as Tn}from"./NodeInferenceDevices-DEF7iUIy.js";import{t as En}from"./layers-eROspUmA.js";import{t as Dn}from"./CapabilityBadges-E822NR6-.js";import{$t as On,At as kn,Cn as An,Et as jn,Ft as Mn,Gt as Nn,Nn as Pn,Tn as Y,Tt as Fn,bn as In,cn as Ln,jt as Rn,nr as zn,rr as Bn,un as Vn,wn as Hn}from"./src-C36-vO5A.js";import{_ as Un,a as Wn,d as Gn,f as Kn,h as qn,l as X,m as Jn,p as Yn,r as Xn,t as Zn,u as Qn}from"./index-CgXPc-AV.js";import{n as $n,t as er}from"./useDevice-BU0imY9B.js";import{C as tr,E as nr,S as rr,T as ir,_ as ar,a as or,b as sr,c as cr,d as lr,f as ur,g as dr,h as fr,i as pr,l as mr,m as hr,o as gr,p as _r,r as vr,s as yr,t as br,u as xr,v as Sr,w as Cr,x as wr,y as Tr}from"./CompositionEditor-BhWVT7RV.js";import{t as Er}from"./authed-media-CH1U0Z7I.js";import"./useEventInvalidation-BxCnrh5u.js";import{t as Dr}from"./StatusBadge-CeptlsPG.js";import{t as Or}from"./use-stationary-objects-CO4PdIFG.js";import{a as kr,i as Ar,n as jr,r as Mr,t as Nr}from"./DeviceAggregateSection-kHgMnzdV.js";var Pr=D(`arrow-left-right`,[[`path`,{d:`M8 3 4 7l4 4`,key:`9rb6wj`}],[`path`,{d:`M4 7h16`,key:`6tx8e3`}],[`path`,{d:`m16 21 4-4-4-4`,key:`siv7j2`}],[`path`,{d:`M20 17H4`,key:`h6l3hr`}]]),Fr=D(`disc`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]),Ir=D(`ear`,[[`path`,{d:`M6 8.5a6.5 6.5 0 1 1 13 0c0 6-6 6-6 10a3.5 3.5 0 1 1-7 0`,key:`1dfaln`}],[`path`,{d:`M15 8.5a2.5 2.5 0 0 0-5 0v1a2 2 0 1 1 0 4`,key:`1qnva7`}]]);n();function Lr(e){if(typeof e!=`object`||!e)return null;let t=e,n=t.id,r=t.label;if(typeof n!=`string`||typeof r!=`string`)return null;let i=t.available===!0,a=t.enabled,o=t.unavailableReason;return{id:n,label:r,costWhenOff:typeof t.costWhenOff==`string`?t.costWhenOff:``,on:i&&typeof a==`boolean`?a:null,available:i,unavailableReason:typeof o==`string`?o:null}}function Rr(e){if(typeof e!=`object`||!e)return null;let t=e.switches;if(!Array.isArray(t))return null;let n=t.map(Lr).filter(e=>e!==null);return n.length===0?null:n}var zr=[[/privacy|mask/i,`privacy`],[/microphone|mic\b/i,`microphone`],[/speaker|broker audio|stream audio/i,`speaker`],[/audio/i,`listening`],[/object|detect/i,`detection`],[/event/i,`archive`],[/record/i,`recording`],[/notif/i,`notifications`],[/stream|broker/i,`stream`]];function Br(e){for(let[t,n]of zr)if(t.test(e))return n;return`generic`}function Vr(e){let t=e.filter(e=>e.on===!1).map(e=>e.id),n=e.filter(e=>e.on===null).map(e=>e.id),r=t=>t.map(t=>e.find(e=>e.id===t)?.label??t).join(`, `),i=[];return t.length>0&&i.push(`Off: ${r(t)}`),n.length>0&&i.push(`Unknown: ${r(n)}`),{offIds:t,unknownIds:n,summary:i.length===0?`All camera functions on`:i.join(` · `)}}var Hr={stream:_e,detection:Un,privacy:b,microphone:T,speaker:Ae,listening:Ir,archive:xn,recording:Fr,notifications:pe,generic:gn};function Ur({deviceId:t}){let n=s(),i=Number.isFinite(t),[a,o]=c(null),[l,d]=c(!1),f=be({deviceId:t},{enabled:i});Yt([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let p=Rr(f.data),m=St({onError:(e,r)=>{console.error(`[CameraFunctionSwitches] switch write failed — reverting`,{tags:{deviceId:t},meta:{switchId:r.switchId,error:e instanceof Error?e.message:String(e)}}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSwitches`]]}),o({id:r.switchId,message:e instanceof Error?e.message:String(e)})},onSuccess:()=>{o(null),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),n.invalidateQueries({queryKey:[[`deviceManager`]]}),n.invalidateQueries({queryKey:[[`recording`]]})}}),h=e(e=>{!e.available||e.on===null||m.mutate({deviceId:t,switchId:e.id,enabled:!e.on})},[t,m]);if(p===null)return null;let g=Vr(p),_=e=>a?.id===e.id?a.message:null;return r(I,{open:l,onOpenChange:d,children:[r(Re,{"aria-label":`Camera functions`,title:g.summary,className:`inline-flex items-center gap-1 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors ${a===null?g.offIds.length>0?`border-warning/40 text-warning hover:bg-warning/10`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`:`border-danger/50 text-danger bg-danger/5`}`,children:[u(gn,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden lg:inline`,children:`Functions`}),g.offIds.length>0&&r(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:[g.offIds.length,` off`]})]}),r(un,{className:`left-auto right-0 mt-1 min-w-[240px] max-h-[60vh] overflow-y-auto p-1`,children:[u(`div`,{className:`px-2 py-1 text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Camera functions`}),u(`ul`,{className:`space-y-0.5`,children:p.map(e=>u(`li`,{children:u(Wr,{row:e,failure:_(e),onToggle:()=>h(e)})},e.id))})]})]})}function Wr({row:e,failure:t,onToggle:n}){let i=Hr[Br(e.label)],a=e.on===null,o=e.on===!1,s=t===null?a?e.unavailableReason??`The source that owns this did not answer.`:e.costWhenOff:`Write failed: ${t}`,c=t===null?a?e.unavailableReason??`unknown`:null:`write failed`;return r(`button`,{type:`button`,role:`switch`,"aria-label":e.label,"aria-checked":e.on===!0,disabled:!e.available,onClick:n,title:s,className:`flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-[12px] text-foreground transition-colors hover:bg-surface-hover disabled:opacity-40 disabled:cursor-not-allowed`,children:[u(i,{className:`h-3.5 w-3.5 shrink-0 ${t===null?a?`text-foreground-subtle/50`:o?`text-warning`:`text-success`:`text-danger`}`}),r(`span`,{className:`flex-1 min-w-0 truncate`,children:[e.label,c!==null&&r(`span`,{className:`ml-1 text-[10px] text-foreground-subtle`,children:[`· `,c]})]}),u(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[9px] font-semibold uppercase tracking-wide ${a?`bg-surface-hover text-foreground-subtle/60`:o?`bg-warning/20 text-warning`:`bg-success/20 text-success`}`,children:a?`—`:o?`off`:`on`})]})}function Gr({deviceId:e}){let t=ce(_().trpcClient,e);return t===null?null:r(`a`,{href:t.url,target:`_blank`,rel:`noopener noreferrer`,title:`${t.label} — ${t.host}`,className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[u(v,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:t.label})]})}function Kr({parentDeviceId:e}){let{t}=X(),n=Kn(),i=_(),{data:a,isLoading:o,isError:s}=$n(e),{data:c}=q({deviceId:e},{enabled:Number.isFinite(e)});if(o)return u(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(s)return u(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let l=(a??[]).filter(e=>e.display?.hidden!==!0);if(l.length===0)return null;let d=ye(c?.stableId??``,l,c?.childLayout),f=d.ungrouped,p=e=>n(`/devices/${String(e)}`),m=c?.name??``,h=(e,t)=>u(j,{trpc:i.trpcClient,device:{...t,name:W(t,m)},variant:`minimal`,onNavigate:p},e),g=f.some(e=>!!e.role),v=f.some(e=>!e.role),y=g&&!v?t(`device.accessories`,{defaultValue:`Accessories`}):!g&&v?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),b=f.length>0?r(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[u(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:y}),u(`div`,{className:`space-y-1`,children:f.map(e=>h(e.id,e))})]}):null,x=d.disabledSection===void 0?null:u(It,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:d.disabledSection.children.length,defaultOpen:!1,children:u(`div`,{className:`opacity-60 space-y-1`,children:d.disabledSection.children.map(e=>h(e.id,e))})},d.disabledSection.title);if(d.sections.length===0)return x===null?b:r(`div`,{className:`space-y-2`,children:[b,x]});let S=v&&!g;return r(`div`,{className:`space-y-2`,children:[S?b:null,d.sections.map(e=>u(It,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>h(e.id,e))},e.title)),S?null:b,x]})}function qr({deviceId:e}){let t=_(),{data:n,isLoading:r}=er(e),{data:i,isLoading:a}=$n(e),o=r||a,s=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),c=typeof n?.linkDeviceId==`number`?n.linkDeviceId:null,l=typeof n?.primaryChildEntityId==`string`?n.primaryChildEntityId:null;return o?u(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):u(`div`,{className:`flex h-full w-full flex-col`,children:u(ae,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}n();function Jr({dev:e,busy:t,setBusy:n}){let i=e?.motionTrigger,a=x(e?.state.motionTrigger),[o,s]=c(!1);if(!i)return null;let l=a?.enabled===!0,d=a!==void 0,f=async()=>{if(t||!d)return;let e=!l;n(!0),s(!0);try{await i.setMotionTrigger({enabled:e})}finally{n(!1),s(!1)}};return r(`button`,{type:`button`,onClick:()=>{f()},disabled:t||!d,title:d?l?`Disable trigger on motion`:`Enable trigger on motion`:`Awaiting state…`,"aria-pressed":l,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${l?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[u(gt,{className:`h-3 w-3`}),u(`span`,{children:o?l?`Disabling…`:`Enabling…`:d?l?`On motion: on`:`On motion: off`:`On motion: …`})]})}n();function Z({deviceId:e,deviceType:t,features:n}){let i=_(),a=et(t)?.HeroCard??Ze,o=f(i.trpcClient,e),s=x(o?.state.deviceStatus),[l,d]=c(!1),p=s!==void 0&&s.online===!1,m=p?s.lastChangedAt:null;return r(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[p?u(`div`,{className:`flex justify-center`,children:u(Kt,{lastChangedAt:m})}):null,u(a,{trpc:i.trpcClient,deviceId:e,features:n}),u(`div`,{className:`flex justify-center`,children:u(Jr,{dev:o,busy:l,setBusy:d})})]})}function Yr({deviceId:e,features:t}){return u(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:u(at,{trpc:_().trpcClient,deviceId:e,features:t})})}function Xr({deviceId:e,features:t}){return u(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:u(Ze,{trpc:_().trpcClient,deviceId:e,features:t})})}function Zr(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function Qr(e){if(!e)return null;let t=Zr(e.data);return t===null?e.eventType:`Button ${String(t)} · ${e.eventType}`}var $r=1e3,ei=60*$r,ti=60*ei,ni=24*ti;function ri(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<$r?`just now`:n<ei?`${String(Math.floor(n/$r))}s ago`:n<ti?`${String(Math.floor(n/ei))}m ago`:n<ni?`${String(Math.floor(n/ti))}h ago`:`${String(Math.floor(n/ni))}d ago`}n();var ii=1500,ai=15e3,oi=1e3;function si({deviceId:e}){let n=f(_().trpcClient,e)?.state.eventEmitter,i=x(n);d(()=>{if(!n)return;n.refresh();let e=setInterval(()=>{n.refresh()},ai);return()=>{clearInterval(e)}},[n]);let a=i?.lastEvent??null,o=a?.seq??null,s=t(null),[l,p]=c(!1);d(()=>{if(o===null)return;let e=s.current;if(s.current=o,e===null||e===o)return;p(!0);let t=setTimeout(()=>{p(!1)},ii);return()=>{clearTimeout(t)}},[o]);let[m,h]=c(()=>Date.now());d(()=>{let e=setInterval(()=>{h(Date.now())},oi);return()=>{clearInterval(e)}},[]);let g=Qr(a),v=i?.eventTypes??[],y=i?.eventCountSinceStart??0,b=i!==void 0,S=Zr(a?.data);return r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[u(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(l),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${l?`border-primary bg-primary/20 text-primary shadow-lg shadow-primary/30 scale-105`:`border-border bg-surface text-foreground-subtle`}`,"aria-live":`polite`,title:g??`No press recorded`,children:u(l?Jt:bt,{className:`h-10 w-10`})}),r(`div`,{className:`text-center`,children:[S!==null&&u(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:`Button ${String(S)}`}),u(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${g?`text-foreground`:`text-foreground-subtle`}`,children:g??(b?`No press recorded`:`Awaiting state…`)}),u(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:a?ri(a.timestamp,m):`Waiting for the first event`})]}),v.length>0&&u(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:v.map(e=>u(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===a?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),u(`div`,{className:`text-[10px] text-foreground-subtle`,children:`${String(y)} ${y===1?`event`:`events`} since start`})]})}function ci({deviceName:e,deviceType:t,provider:n,isOnline:i,features:a}){return r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[u(Cn,{type:n,size:`lg`}),r(`div`,{children:[u(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),u(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),r(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[u(Dr,{status:i?`online`:`offline`}),a.length>0&&u(Dn,{capabilities:a})]}),u(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:`No live view for this device type. Use the Config tab or the shortcut row to interact.`})]})}n();function li({deviceId:e}){let t=s(),n=Ve({deviceId:e},{refetchInterval:1e4,retry:!1}),a=Ye({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),o=i(()=>ui(n.data??[]),[n.data]);return r(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[r(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[u(di,{label:`Discovered`,value:o.total,icon:u(he,{className:`h-3.5 w-3.5`})}),u(di,{label:`Adopted`,value:o.adopted,accent:`success`}),u(di,{label:`Available`,value:o.available,accent:o.available>0?`primary`:void 0}),r(`button`,{type:`button`,onClick:()=>{a.mutateAsync({deviceId:e}).catch(()=>{})},disabled:a.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[a.isPending?u(Ut,{className:`h-3.5 w-3.5 animate-spin`}):u(le,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[u(fi,{icon:u(U,{className:`h-3 w-3 text-emerald-500`}),label:`${o.online} online`}),u(fi,{icon:u(fe,{className:`h-3 w-3 text-amber-500`}),label:`${o.sleeping} sleeping`}),u(fi,{icon:u(nt,{className:`h-3 w-3 text-destructive`}),label:`${o.offline} offline`}),o.unknown>0?u(fi,{icon:u(Se,{className:`h-3 w-3 text-foreground-subtle`}),label:`${o.unknown} unknown`}):null]})]})}function ui(e){let t={total:e.length,adopted:0,available:0,online:0,sleeping:0,offline:0,unknown:0};for(let n of e)n.alreadyAdopted?t.adopted+=1:t.available+=1,t[n.status]+=1;return t}function di({label:e,value:t,icon:n,accent:i}){return r(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${i===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:i===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[r(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,u(`span`,{className:`truncate`,children:e})]}),u(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function fi({icon:e,label:t}){return r(`span`,{className:`inline-flex items-center gap-1`,children:[e,u(`span`,{children:t})]})}var pi={[Y.Switch]:Z,[Y.Siren]:Z,[Y.Light]:Z,[Y.Sensor]:Z,[Y.Button]:Z,[Y.Hub]:li,[Y.Cover]:Yr,[Y.Valve]:Z,[Y.Humidifier]:Z,[Y.WaterHeater]:Z,[Y.Container]:qr,[Y.Lock]:Z,[Y.Fan]:Z,[Y.Thermostat]:Z,[Y.Climate]:Z,[Y.MediaPlayer]:Z,[Y.Control]:Z,[Y.AlarmPanel]:Z,[Y.EventEmitter]:si,[Y.Notifier]:Xr,[Y.Script]:Z,[Y.Automation]:Z,[Y.Presence]:Z,[Y.Update]:Z,[Y.Vacuum]:Z,[Y.LawnMower]:Z,[Y.Weather]:Z,[Y.Image]:Z,[Y.PetFeeder]:Z};function mi(e){return pi[e]??ci}function hi(e){return u(mi(e.deviceType),{...e})}function gi(e){return Qt(_().trpcClient,e)}n();function _i(n){let[r,i]=c(`idle`),[a,o]=c(null),s=t(null),l=t(null),u=t(null),f=t(!0),p=st(),m=Et(),h=sn(),g=e(()=>{if(s.current){try{s.current.close()}catch{}s.current=null}if(l.current){for(let e of l.current.getTracks())try{e.stop()}catch{}l.current=null}u.current=null},[]),_=e(async()=>{if(r===`idle`)return;i(`stopping`);let e=u.current;if(e&&n!==null)try{await Promise.race([h.mutateAsync({deviceId:n,sessionId:e}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}g(),f.current&&(i(`idle`),o(null))},[r,n,h,g]),v=e(async()=>{if(n===null||r!==`idle`&&r!==`error`)return;o(null);let e=null,t=null,a=null;try{i(`requesting-mic`),e=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),l.current=e,i(`starting`);let r=await p.mutateAsync({deviceId:n});a=r.sessionId,u.current=a,i(`connecting`),t=new RTCPeerConnection,s.current=t,t.oniceconnectionstatechange=()=>{if(!f.current)return;let e=t.iceConnectionState;e===`connected`||e===`completed`?i(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&f.current&&(o(e===`failed`?`WebRTC connection failed`:null),_())};for(let n of e.getAudioTracks())t.addTrack(n,e);await t.setRemoteDescription({type:`offer`,sdp:r.sdpOffer});let c=await t.createAnswer();await t.setLocalDescription(c);let d=t.localDescription?.sdp??c.sdp??``;await m.mutateAsync({deviceId:n,sessionId:a,sdpAnswer:d})}catch(r){let c=r instanceof Error?r.message:String(r);if(console.warn(`[intercom] start failed`,r),t)try{t.close()}catch{}if(e)for(let t of e.getTracks())try{t.stop()}catch{}if(s.current=null,l.current=null,a!==null)try{await h.mutateAsync({deviceId:n,sessionId:a})}catch{}u.current=null,f.current&&(o(c),i(`error`))}},[n,r,p,m,h,_]);return d(()=>(f.current=!0,()=>{f.current=!1;let e=u.current;if(e!==null&&n!==null&&h.mutate({deviceId:n,sessionId:e}),s.current){try{s.current.close()}catch{}s.current=null}if(l.current){for(let e of l.current.getTracks())try{e.stop()}catch{}l.current=null}u.current=null}),[n]),{state:r,error:a,start:v,stop:_,isTalking:r===`talking`}}n();var vi=0;function Q(){return++vi}function yi(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function bi(e){return[``,`Commands`,` help Show this help`,` examples Show usage examples for the current scope`,` context Show every available variable + full API surface`,` clear Clear terminal (also Ctrl+L)`,``,`Shortcuts`,` Enter Execute expression`,` Arrow Up/Down Navigate command history`,` Ctrl+L Clear terminal`,``,`Try: ${{system:` sm.summary() // fleet overview`,device:` device.state.battery.value?.sleeping // sync read`,provider:` devices.map(d => d.name)`,addon:` manifest.version`}[e.type]}`,``,`Top-level objects: sm (SystemMirror), DeviceType, Math, JSON, Date, …`]}function xi(e){switch(e.type){case`device`:return[``,`── State (sync, zero round-trip) ─────────────────────────`,` device.state.battery.value`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,``,`── Actions (async, through wrapper chain) ────────────────`,` await device.snapshot.getSnapshot({})`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.switch.setState({ on: true })`,``,`── Wait for condition ───────────────────────────────────`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`── Subscribe to changes ─────────────────────────────────`,` const off = device.state.battery.subscribe(s => console.log(s))`,``,`── Quick info ───────────────────────────────────────────`,` info.name device name`,` info.addonId owning addon`,` sm.dump(deviceId) full debug dump`];case`system`:return[``,`── Lookups ──────────────────────────────────────────────`,` sm.getDeviceById(8)`,` sm.getDeviceByName('Sala da pranzo')`,` sm.getDevicesByAddon('reolink')`,` sm.getDevicesByType(DeviceType.Camera)`,``,`── Filters (typed query) ────────────────────────────────`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] })`,` sm.query({ name: /^Cam-/ })`,``,`── Cross-device ─────────────────────────────────────────`,` sm.whereState('battery', s => s.percentage < 20).length`,` sm.mapState('battery', s => s.percentage)`,` sm.countByCap('snapshot')`,``,`── Batch action ─────────────────────────────────────────`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,``,`── Listen ───────────────────────────────────────────────`,` sm.listenCap('motion', (id, s) => console.log(id, s))`,` sm.onDeviceAdded((id, info) => console.log('+', info.name))`,``,`── Diagnostics ──────────────────────────────────────────`,` sm.summary()`,` sm.dump(8)`];case`provider`:return[``,` devices.map(d => d.name)`,` await getIntegration()`,` sm.getDevicesByAddon('<this-addon-id>').length`];case`addon`:return[``,` manifest.name`,` manifest.version`,` declaration`]}}function Si(e){let t=[``,`Scope: ${e.type}`,``];switch(e.type){case`system`:return[...t,`Primary API — sm (SystemMirror):`,` sm.getDeviceById(id) DeviceProxy | null (sync)`,` sm.getDeviceByName(name) DeviceProxy | null`,` sm.getDeviceByStableId(sid) DeviceProxy | null`,` sm.getAllDevices() readonly DeviceProxy[]`,` sm.getDeviceInfo(id) DeviceInfo | null`,` sm.summary() fleet stats`,``,`Filters — sm.query({...}):`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] }) // ALL caps required`,` sm.query({ anyCap: ['ptz', 'motion'] }) // ANY cap`,` sm.query({ name: { contains: 'sala' } }) // case-insensitive`,` sm.query({ name: /^Cam-\\d+$/ })`,` sm.query({ type: DeviceType.Camera })`,` sm.query({ parentDeviceId: 8 }) // accessories of cam 8`,` sm.query({ where: (info, dev) => dev.state.battery.value?.sleeping })`,``,`State queries:`,` sm.whereState('battery', s => s.percentage < 20)`,` sm.mapState('battery', s => s.percentage)`,` sm.findState('motion', s => s.detected)`,` sm.countByCap('snapshot')`,``,`Listeners (return unsubscribe fn):`,` sm.listen((id, cap, slice) => …) // every state change`,` sm.listenCap('motion', (id, slice) => …)`,` sm.listenDevice(8, (id, cap, slice) => …)`,` sm.onDeviceAdded((id, info) => …)`,` sm.onDeviceRemoved((id, info) => …)`,``,`Wait primitives:`,` await sm.waitForState(8, 'battery', s => !s.sleeping, 30_000)`,` await sm.waitForDevice(99, 30_000)`,``,`Batch:`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,` await sm.forEachCap('reboot', d => d.reboot.reboot({}))`,``,`Diagnostics:`,` sm.dump(8) debug dump (one device)`,` sm.dump() full fleet dump`,` sm.summary() breakdown by cap/addon/type`,``,`Legacy: deviceRegistry, addonRegistry, eventBus, devices(), addons()`];case`device`:return[...t,`Pre-bound variables:`,` device DeviceProxy for this device (sync state + async methods)`,` deviceId number`,` info DeviceInfo metadata (name, addonId, type, online, …)`,` sm SystemMirror (full cluster view)`,` rawDevice legacy IDevice instance (escape hatch)`,``,`Reactive state (sync, zero round-trip):`,` device.state.battery.value BatteryStatus | undefined`,` device.state.battery.value?.sleeping`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,` device.state.switch.value?.on`,` device.state.brightness.value?.percentage`,` device.state.doorbell.value?.lastPressedAt`,``,`Cap actions (async, through wrapper chain):`,` await device.snapshot.getSnapshot({})`,` await device.snapshot.getSnapshot({ streamId: 'high' })`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.ptz.goToPreset({ presetId: 'home' })`,` await device.switch.setState({ on: true })`,` await device.brightness.setBrightness({ percentage: 60 })`,` await device.reboot.reboot({})`,``,`Subscribe to slice changes:`,` const off = device.state.battery.subscribe(s => console.log(s))`,` // off() to unsubscribe`,``,`Wait for a state condition:`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`Diagnostics:`,` info.name device name`,` info.addonId which addon owns it`,` info.online transport health`,` sm.dump(deviceId) full debug dump (binding + state + info)`];case`provider`:return[...t,`Pre-bound variables:`,` devices Devices belonging to this provider (raw IDevice[])`,` getIntegration() Integration metadata`,``,`For typed device access use the SystemMirror:`,` await getSystemMirror()`,` sm.getDevicesByAddon('this-addon-id')`];case`addon`:return[...t,`Pre-bound variables:`,` manifest { name, version, ... }`,` declaration addon declaration`,` source addon source location`,``,`Examples:`,` manifest.name`,` manifest.version`]}}function Ci({scope:n,greeting:i,className:a}){let o=_(),[s,f]=c(()=>{let e=[];return i&&e.push({id:Q(),kind:`info`,text:i}),e.push({id:Q(),kind:`info`,text:`scope: ${yi(n)} — type help or context for available commands`}),e}),[p,m]=c(``),[h,g]=c([]),[v,y]=c(-1),b=t(null),x=t(null);d(()=>{let e=x.current;e&&(e.scrollTop=e.scrollHeight)},[s]);let S=e(()=>{b.current?.focus()},[]),C=l({mutationFn:e=>o.trpcClient.repl.execute.mutate({code:e,scope:n}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;f(e=>[...e,{id:Q(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);f(e=>[...e,{id:Q(),kind:`error`,text:t}])}});function w(e){let t=e.trim();if(t){if(t===`clear`){f([{id:Q(),kind:`info`,text:`scope: ${yi(n)}`}]),m(``);return}if(t===`help`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...bi(n).map(e=>({id:Q(),kind:`info`,text:e}))]),m(``);return}if(t===`context`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...Si(n).map(e=>({id:Q(),kind:`info`,text:e}))]),m(``);return}if(t===`examples`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...xi(n).map(e=>({id:Q(),kind:`info`,text:e}))]),m(``);return}g(e=>[...e,t]),y(-1),f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`}]),m(``),C.mutate(t)}}function T(e){if(e.key===`Enter`){e.preventDefault(),w(p);return}if(e.key===`ArrowUp`){if(e.preventDefault(),h.length===0)return;let t=v===-1?h.length-1:Math.max(0,v-1);y(t),m(h[t]??``);return}if(e.key===`ArrowDown`){if(e.preventDefault(),v===-1)return;let t=v+1;t>=h.length?(y(-1),m(``)):(y(t),m(h[t]??``));return}e.ctrlKey&&e.key===`l`&&(e.preventDefault(),f([{id:Q(),kind:`info`,text:`scope: ${yi(n)}`}]))}let E={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return r(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${a??``}`,onClick:S,children:[r(`div`,{ref:x,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[s.map(e=>u(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${E[e.kind]}`,children:e.text},e.id)),C.isPending&&u(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),r(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[u(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),u(`input`,{ref:b,value:p,onChange:e=>m(e.target.value),onKeyDown:T,disabled:C.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function wi(e,t){return e===null?null:{playbackUrl:e.url,...e.format===void 0?{}:{playbackFormat:e.format},playbackAuthToken:t,...e.label===void 0?{}:{playbackLabel:e.label}}}n();function Ti({deviceId:e,intercomAvailable:t=!1}){let n=_(),r=typeof window<`u`?h():``,a=Number.isFinite(e),s=gi(a?e:null),c=Or(a?[e]:[]),l=i(()=>{if(!a)return;let e=[];for(let t of c.rows){let n=Wt(t);n!==null&&e.push(n)}return e},[a,c.rows]),{streams:d,pipelineMetrics:f,createSession:p,sendAnswer:g,handleOffer:v,getIceServers:y,addIceCandidate:b,getIceCandidates:x,closeSession:C,getSessionState:w}=ut(n.trpcClient,a?e:null),T=m(a?e:null,{width:Ai}),E=_i(a&&t?e:null),D=E.state===`requesting-mic`||E.state===`starting`||E.state===`connecting`||E.state===`stopping`,O=E.isTalking||D,k=()=>{E.state===`idle`||E.state===`error`?E.start():E.state!==`stopping`&&E.stop()},A=S(),j=Ft(),M=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,N=wi(j.request,M),P=A.length>0?u(o,{children:A.map(e=>u(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return u(nn,{serverUrl:r,createSession:p,sendAnswer:g,handleOffer:v,getIceServers:y,addIceCandidate:b,getIceCandidates:x,closeSession:C,getSessionState:w,...N===null?{}:{...N,onExitPlayback:()=>j.clear()},streams:d,pipelineMetrics:f,phase:s.phase,detections:s,...l===void 0?{}:{stationaryObjects:l},defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:T.src,...T.src?{posterUrl:T.src}:{},snapshotLoading:T.loading,onRefreshSnapshot:T.refresh,intercomAvailable:t,intercomShown:O,onIntercomToggle:k,extraOverlay:P,chromeless:!0,className:`h-full`})}function Ei({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full`,children:u(tn,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Di({deviceId:e}){if(!Number.isFinite(e))return r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let t=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
|
|
2
|
-
`);return u(Ci,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function Oi({deviceId:e}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:u(Ct,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function ki({deviceId:e}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:u(O,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}var Ai=960;function ji(e){if(e.status===`pending`)return{kind:`pending`};if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??`the request failed`};let t=e.data;if(t===void 0)return{kind:`pending`};if(t.state===`not-loaded`)return{kind:`not-loaded`,reason:t.reason};if(t.view===null)return{kind:`none`};let n=Ln(t.view.block);return n===null?{kind:`unknown`,reason:`block ${t.view.block.id} is not a composition`}:{kind:`present`,view:t.view,composition:n}}function Mi(e){return e.kind===`present`?e.composition:null}function Ni(e){return new Map(e.caps.map(e=>[e.cap,e.fields.filter(e=>e.item!==!0&&!e.path.includes(`.`)).map(e=>e.path)]))}function Pi(...e){for(let t of e)if(t.kind===`unknown`)return t.reason;return null}function Fi({device:e,composition:t,state:n,facts:i,action:a}){let{t:o}=X(),{nativeCaps:s,wireable:c}=i;return r(`section`,{"aria-labelledby":`customize-fields`,className:`rounded-lg border border-border bg-surface p-3 flex flex-col gap-2`,children:[r(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[u(`h2`,{id:`customize-fields`,className:`text-[11px] font-semibold uppercase tracking-wider`,children:o(`customize.fields.title`)}),a]}),u(`p`,{className:`text-[10px] text-foreground-subtle`,children:o(`customize.fields.untouched`)}),s.kind===`known`&&c.kind===`known`?u(Ii,{deviceId:e.id,composition:t,state:n,nativeCaps:s.value,catalog:c.value}):u(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:Pi(s,c)??o(`customize.fields.reading`)})]})}function Ii({deviceId:e,composition:t,state:n,nativeCaps:i,catalog:a}){let{t:o}=X(),s=qt({deviceId:e}),c=cn({projection:`slim`}),l=rr(c.status===`success`?yr(c.data):[]),d=new Map([...l].map(([e,t])=>[e,t.name])),f=vr({composition:t,nativeCaps:i,state:n,nativeFields:Ni(a),snapshot:s.status===`success`?s.data:null,sourceNames:d});return r(`table`,{className:`text-[11px]`,children:[u(`thead`,{children:r(`tr`,{children:[u(`th`,{className:`text-left`,children:o(`customize.fields.function`)}),u(`th`,{className:`text-left`,children:o(`customize.fields.field`)}),u(`th`,{className:`text-left`,children:o(`customize.fields.origin`)}),u(`th`,{className:`text-left`,children:o(`customize.fields.from`)}),u(`th`,{className:`text-left`,children:o(`customize.fields.now`)})]})}),u(`tbody`,{children:f.map(e=>u(Li,{row:e},e.key))})]})}function Li({row:e}){let{t}=X();return r(`tr`,{children:[r(`td`,{children:[e.cap,` `,e.mode===`add`?u(J,{variant:`info`,children:t(`customize.fields.added`)}):null]}),u(`td`,{className:`font-mono`,children:e.field}),u(`td`,{children:u(J,{variant:e.origin===`composed`?`success`:`default`,children:t(`customize.fields.origins.${e.origin}`)})}),u(`td`,{className:`font-mono break-all`,children:e.from===`integration`?t(`customize.fields.integration`):e.from}),u(`td`,{children:u(Ri,{value:e.value})})]})}function Ri({value:e}){let{t}=X();switch(e.kind){case`value`:return r(`span`,{children:[or(e.value,!0),e.staleReason!==null&&r(`span`,{className:`text-warning`,children:[` `,`· `,t(`customize.fields.stale`,{reason:e.staleReason})]})]});case`unavailable`:return u(`span`,{className:`text-warning`,children:t(`customize.fields.unavailable`,{reason:e.reason})});case`unknown`:return u(`span`,{className:`text-foreground-subtle`,children:t(`customize.fields.unknown`,{reason:e.reason})});case`off`:return u(`span`,{className:`text-foreground-subtle`,children:t(`customize.status.off`)})}}function $({label:e,value:t}){return r(`div`,{className:`${g} flex items-start gap-2 sm:gap-3`,children:[u(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),u(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}n();function zi({deviceId:e,initialName:n}){let i=s(),[a,o]=c(!1),[l,f]=c(n),[p,m]=c(!1),h=t(null);d(()=>{a||f(n)},[n,a]),d(()=>{a&&h.current?.focus()},[a]);let g=yn({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),i.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),_=async()=>{let t=l.trim();if(t.length===0||t===n){o(!1),f(n);return}m(!0);try{await g.mutateAsync({deviceId:e,name:t}),o(!1)}catch{}finally{m(!1)}},v=()=>{f(n),o(!1)};return a?u($,{label:`Name`,value:r(`div`,{className:`flex items-center gap-1`,children:[u(`input`,{ref:h,type:`text`,value:l,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`?_():e.key===`Escape`&&v()},disabled:p,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),u(`button`,{type:`button`,onClick:()=>void _(),disabled:p,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:u(Ge,{className:`h-3 w-3`})}),u(`button`,{type:`button`,onClick:v,disabled:p,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:u(oe,{className:`h-3 w-3`})})]})}):u($,{label:`Name`,value:r(`div`,{className:`flex items-center gap-2 group`,children:[u(`span`,{className:`truncate`,children:n}),u(`button`,{type:`button`,onClick:()=>o(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit name`,children:u(Je,{className:`h-3.5 w-3.5`})})]})})}function Bi(e,t){let{hidden:n,...r}=e??{},i=t?{...r,hidden:!0}:r;return Object.keys(i).length===0?null:i}function Vi(e){return typeof e.linkDeviceId==`number`}var Hi=new Set(Object.values(Hn));function Ui(e){return Hi.has(e)}function Wi(e){let t=Object.values(Hn);return e==null||e===``||Ui(e)?t:[...t,e]}var Gi=`w-full min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`;function Ki({device:e}){let{t}=X(),n=s(),i={onSuccess:()=>void n.invalidateQueries({queryKey:[[`deviceManager`]]})},a=Ue(),o=Oe(),c=e.display?.hidden===!0;return r(`section`,{"aria-labelledby":`customize-identity`,className:`rounded-lg border border-border bg-surface`,children:[u(`h2`,{id:`customize-identity`,className:`px-3 py-2 text-[11px] font-semibold uppercase tracking-wider border-b border-border`,children:t(`customize.identity.title`)}),r(`div`,{className:`divide-y divide-border`,children:[u($,{label:t(`customize.identity.type`),value:r(`div`,{className:`flex flex-col`,children:[u(`span`,{children:B(e.type).label}),u(`span`,{className:`text-[10px] text-foreground-subtle`,children:t(`customize.identity.typeReadOnly`)})]})}),u($,{label:t(`customize.identity.role`),value:Vi(e)?r(`div`,{className:`flex flex-col`,children:[u(`span`,{children:qi(e.role,t(`customize.identity.noRole`))}),u(`span`,{className:`text-[10px] text-foreground-subtle`,children:t(`customize.identity.roleReadOnly`)})]}):r(`select`,{"aria-label":t(`customize.identity.role`),className:Gi,value:e.role??``,disabled:a.isPending,onChange:t=>a.mutate({deviceId:e.id,role:t.target.value===``?null:t.target.value},i),children:[u(`option`,{value:``,children:t(`customize.identity.noRole`)}),Wi(e.role).map(e=>u(`option`,{value:e,children:qi(e,t(`customize.identity.noRole`))},e))]})}),u(zi,{deviceId:e.id,initialName:e.name}),u($,{label:t(`deviceDisplay.hidden`),value:r(`label`,{className:`flex items-center gap-2`,children:[u(`input`,{type:`checkbox`,"aria-label":t(`deviceDisplay.hideFromLists`),checked:c,disabled:o.isPending,onChange:t=>o.mutate({deviceId:e.id,display:Bi(e.display,t.target.checked)},i)}),u(`span`,{className:`text-[11px]`,children:t(`deviceDisplay.hideFromLists`)})]})})]}),u(`p`,{className:`px-3 py-2 text-[10px] text-foreground-subtle`,children:t(`customize.identity.noNewStore`)})]})}function qi(e,t){return e==null||e===``?t:Ui(e)?N(e).label:e}function Ji({device:e}){let{t}=X();return On.includes(e.type)?u(xt,{deviceId:e.id,slots:[`linked-devices`],title:t(`customize.links.title`)}):null}n();function Yi({title:e,targetKind:t,excludeDeviceIds:n,pick:i,onChange:a}){let{t:o}=X(),[s,l]=c(!0);return i===null?s?u(pr,{title:e,targetKind:t,excludeDeviceIds:n,onPick:e=>{a(e),l(!1)},onCancel:()=>l(!1)}):u(`div`,{children:u(K,{variant:`outline`,onClick:()=>l(!0),children:e})}):r(`p`,{className:`flex items-center gap-2 text-[11px]`,children:[r(`span`,{children:[i.device.name,` ·`,` `,r(`span`,{className:`font-mono`,children:[i.cap,`.`,i.path]})]}),u(K,{variant:`ghost`,onClick:()=>{a(null),l(!0)},children:o(`customize.presets.changeSource`)})]})}function Xi(){let{t:e}=X(),t=_n();return(n,r)=>t({title:e(`customize.presets.removeConfirm.title`),message:r?`${e(`customize.presets.removeConfirm.message`,{what:n})} ${e(`customize.presets.removeConfirm.last`)}`:e(`customize.presets.removeConfirm.message`,{what:n}),confirmLabel:e(`customize.presets.removeConfirm.confirm`),variant:`danger`})}n();function Zi({device:e,target:t,current:n,mode:i,saving:a,apply:o}){let{t:s}=X(),l=Xi(),[d,f]=c(null),p=d===null?null:mr({percentage:{source:d.ref,cap:d.cap,fieldPath:d.path,kind:d.kind},mode:i}),m=ar(n,`battery`),h=m!==null&&fr(m,i),g=async()=>{if(n===null)return;let e=wr(n,`battery`);await l(s(`customize.presets.battery.removeWhat`),e===null)&&await o(e)};return r(`div`,{className:`flex flex-col gap-2 rounded-md border border-border p-2`,children:[u(`p`,{className:`text-[11px] text-foreground-subtle`,children:s(`customize.presets.battery.help.${i}`)}),h&&u(`p`,{className:`text-[11px] text-success`,children:s(`customize.presets.battery.applied`)}),m!==null&&!h&&r(`p`,{className:`text-[11px] text-warning`,children:[s(`customize.presets.composedByOther`,{cap:`battery`}),` `,s(`customize.presets.notThisPreset`)]}),u(Yi,{title:s(`customize.presets.battery.pick`),targetKind:`number`,excludeDeviceIds:[e.id],pick:d,onChange:f}),r(`div`,{className:`flex gap-2`,children:[u(K,{disabled:p===null||a,onClick:()=>{p!==null&&o(sr(n,t,p))},children:s(`customize.presets.apply`)}),h&&u(K,{variant:`outline`,disabled:a,onClick:()=>void g(),children:s(`customize.presets.remove`)})]})]})}n();var Qi=`px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`;function $i({device:e,target:t,current:n,saving:i,apply:a}){let{t:o}=X(),[s,l]=c(``),[d,f]=c(`days`),[p,m]=c(null),h=ar(n,`consumables`),g=p===null?null:xr(h,{key:dr(s),label:s,remaining:{source:p.ref,cap:p.cap,fieldPath:p.path,kind:p.kind},unit:d});return r(`div`,{className:`flex flex-col gap-2 rounded-md border border-border p-2`,children:[u(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`customize.presets.consumables.help`)}),r(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[o(`customize.presets.consumables.label`),u(`input`,{className:Qi,value:s,onChange:e=>l(e.target.value)})]}),r(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[o(`customize.presets.consumables.unit`),u(`select`,{className:Qi,value:d,onChange:e=>{let t=Mn.safeParse(e.target.value);t.success&&f(t.data)},children:Mn.options.map(e=>u(`option`,{value:e,children:o(`customize.presets.consumables.units.${e}`)},e))})]}),u(Yi,{title:o(`customize.presets.consumables.pick`),targetKind:`number`,excludeDeviceIds:[e.id],pick:p,onChange:m}),u(`div`,{children:u(K,{disabled:g===null||i,onClick:()=>{g!==null&&a(sr(n,t,g))},children:o(`customize.presets.apply`)})})]})}n();var ea=`px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`;function ta(e){return`${e.cap}.${e.fieldPath}`}function na({device:e,target:t,current:n,facts:i,saving:a,apply:o}){let{t:s}=X(),l=_(),d=i.native.kind===`known`?[...i.native.value].flatMap(([e,t])=>t.map(t=>({cap:e,fieldPath:t}))):[],[f,p]=c(d[0]===void 0?``:ta(d[0])),m=d.find(e=>ta(e)===f)??null,h=m?.cap??``,g=gr(ht(l.trpcClient,m===null?null:e.id,h),`unit`),[v,y]=c(null),b=v??(typeof g==`string`?g:``),x=kn(b),S=x===void 0?[]:Rn(x).filter(e=>e!==b),[C,w]=c(``),T=(i.wireable.kind===`known`?i.wireable.value.caps.find(e=>e.cap===h)?.fields??[]:[]).some(e=>e.path===`unit`&&e.kind===`string`)?`unit`:null,E=m===null?null:lr({self:t,cap:h,fieldPath:m.fieldPath,from:b,to:C,unitField:T}),D=m!==null&&ar(n,h)!==null;return r(`div`,{className:`flex flex-col gap-2 rounded-md border border-border p-2`,children:[u(`p`,{className:`text-[11px] text-foreground-subtle`,children:s(`customize.presets.convert.help`)}),r(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[s(`customize.presets.convert.field`),u(`select`,{className:ea,value:f,onChange:e=>p(e.target.value),children:d.map(e=>u(`option`,{value:ta(e),children:ta(e)},ta(e)))})]}),D&&u(`p`,{className:`text-[11px] text-warning`,children:s(`customize.presets.composedByOther`,{cap:h})}),r(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[s(`customize.presets.convert.from`),u(`input`,{className:ea,value:b,onChange:e=>y(e.target.value.trim())})]}),x===void 0&&b!==``&&u(`p`,{role:`alert`,className:`text-[10px] text-warning`,children:s(`customize.presets.convert.unknownUnit`,{unit:b})}),r(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[s(`customize.presets.convert.to`),r(`select`,{className:ea,value:C,onChange:e=>w(e.target.value),children:[u(`option`,{value:``,children:`—`}),S.map(e=>u(`option`,{value:e,children:e},e))]})]}),u(`div`,{children:u(K,{disabled:E===null||a,onClick:()=>{E!==null&&o(sr(n,t,E))},children:s(`customize.presets.apply`)})})]})}n();function ra(e,t,n){return e.flatMap(e=>e.device===null?t.filter(t=>In(t.source)===e.key):jn(e.ref,n(e.device.id)))}function ia(e,t){let n=cn({projection:`slim`}),r=pt({capNames:[...Pn]}),i=n.status===`success`?yr(n.data):[],a=rr(i),[o,s]=c(null),l=(o??(t===null?[]:ur(t))).map(e=>{let t=In(e);return{key:t,ref:e,device:a.get(t)??null}}),u=l.flatMap(e=>e.device===null?[]:[e.device.id]),d=vt({deviceIds:u},{enabled:u.length>0}),f=new Set(l.map(e=>e.key)),p=r.status===`success`?tr(i,r.data,e.id).filter(e=>!f.has(In(Cr(e)))):[],m=p.filter(t=>e.location!==null&&t.location===e.location),h=n.status===`success`&&(u.length===0||d.status===`success`)?ra(l,t===null?[]:_r(t),e=>d.status===`success`?d.data.find(t=>t.deviceId===e)?.entries.map(e=>e.capName)??[]:[]):null,g=h===null?[]:l.filter(e=>e.device!==null&&!h.some(t=>In(t.source)===e.key));return{devicesStatus:n.status,devicesError:n.status===`error`?n.error?.message??``:null,entries:l,setPicks:s,candidates:p,suggestions:m,sources:h,unusable:g}}function aa({target:e,device:t,current:n,saving:i,apply:a}){let{t:o}=X(),s=Xi(),c=ar(n,`doorbell`),l=ia(t,c),d=c?.enabled!==!1,f=l.sources??[],p=l.entries.length>0&&l.sources!==null&&l.unusable.length===0&&!i,m=()=>{f.length!==0&&a(sr(n,e,Fn({camera:e,sources:f,enabled:d})))},h=async()=>{if(n===null||c===null)return;let e=wr(n,`doorbell`),t=ur(c).length;await s(o(`customize.doorbell.removeWhat`,{count:t}),e===null)&&await a(e)};return r(`div`,{className:`flex flex-col gap-2 rounded-md border border-border p-2`,children:[c!==null&&r(`label`,{className:`flex items-center gap-2 text-[11px]`,children:[u(`input`,{type:`checkbox`,"aria-label":o(`customize.doorbell.active`),checked:d,disabled:i,onChange:t=>void a(sr(n,e,{...c,enabled:t.target.checked}))}),o(`customize.doorbell.active`)]}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`customize.doorbell.rings`)}),l.devicesStatus===`pending`&&u(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:o(`customize.picker.loadingDevices`)}),l.devicesError!==null&&u(dt,{title:o(`customize.picker.devicesFailed`),message:l.devicesError}),u(oa,{draft:l}),l.unusable.length>0&&u(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:o(`customize.doorbell.noSourceCap`)}),r(`div`,{className:`flex gap-2`,children:[u(K,{disabled:!p,onClick:m,children:o(`customize.doorbell.save`)}),c!==null&&n!==null&&u(K,{variant:`outline`,disabled:i,onClick:()=>void h(),children:o(`customize.presets.remove`)})]})]})}function oa({draft:e}){let{t}=X(),n=e.entries.map(e=>e.ref);return r(o,{children:[u(`ul`,{className:`flex flex-col gap-1`,children:e.entries.map(i=>{let a=i.device?.name??(e.devicesStatus===`success`?t(`customize.doorbell.missingSource`,{id:i.key}):i.key);return r(`li`,{className:`flex items-center gap-2 text-[11px]`,children:[u(`span`,{children:a}),i.device===null&&e.devicesStatus===`success`&&u(`span`,{className:`text-warning`,children:t(`customize.doorbell.missingKept`)}),u(`button`,{type:`button`,"aria-label":t(`customize.doorbell.removeSource`,{name:a}),onClick:()=>e.setPicks(n.filter(e=>In(e)!==i.key)),children:`×`})]},i.key)})}),e.suggestions.map(e=>u(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`customize.doorbell.suggested`,{name:e.name})},e.id)),u(`div`,{className:`flex flex-wrap gap-1`,children:e.candidates.map(r=>u(K,{variant:`outline`,size:`sm`,onClick:()=>e.setPicks([...n,Cr(r)]),children:t(`customize.doorbell.add`,{name:r.name})},r.id))})]})}n();function sa({target:e,current:t,facts:n,saving:i,apply:a}){let{t:o}=X(),s=n.nativeCaps.kind===`known`?n.nativeCaps.value:new Set,l=cr.filter(e=>s.has(e)),[d,f]=c(l[0]??``),p=hr({self:e,cap:d}),m=ar(t,d),h=m!==null&&p!==null&&Tr(m,p),g=Xi(),_=async()=>{if(t===null)return;let e=wr(t,d);await g(o(`customize.presets.invert.removeWhat`,{cap:d}),e===null)&&await a(e)};return r(`div`,{className:`flex flex-col gap-2 rounded-md border border-border p-2`,children:[u(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`customize.presets.invert.help`)}),r(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[o(`customize.presets.invert.which`),u(`select`,{className:`px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`,value:d,onChange:e=>f(e.target.value),children:l.map(e=>u(`option`,{value:e,children:e},e))})]}),h&&u(`p`,{className:`text-[11px] text-success`,children:o(`customize.presets.invert.applied`,{cap:d})}),m!==null&&!h&&r(`p`,{className:`text-[11px] text-warning`,children:[o(`customize.presets.composedByOther`,{cap:d}),` `,o(`customize.presets.notThisPreset`)]}),r(`div`,{className:`flex gap-2`,children:[u(K,{disabled:p===null||h||i,onClick:()=>{p!==null&&a(sr(t,e,p))},children:o(`customize.presets.apply`)}),h&&u(K,{variant:`outline`,disabled:i,onClick:()=>void _(),children:o(`customize.presets.remove`)})]})]})}function ca(e){return e.state===`ok`&&e.slot===`doorbell-source`}function la(e){return e.state===`unreachable`}function ua({reason:e}){let{t}=X();return r(`section`,{"aria-label":t(`customize.doorbell.legacyTitle`),className:`rounded border border-warning/40 bg-warning/5 p-2 text-[11px] flex flex-col gap-1`,children:[u(`strong`,{children:t(`customize.doorbell.legacyTitle`)}),u(`span`,{role:`alert`,className:`text-danger`,children:t(`customize.doorbell.legacyReadFailed`,{reason:e})})]})}function da({deviceId:e}){let{t}=X(),n=ge({deviceId:e});if(n.status===`pending`)return null;if(n.status===`error`)return u(ua,{reason:n.error.message});let i=n.data.find(ca);if(i===void 0){let e=n.data.find(la);return e===void 0?null:u(ua,{reason:e.reason})}return i.value.deviceIds.length===0?null:r(`section`,{"aria-label":t(`customize.doorbell.legacyTitle`),className:`rounded border border-warning/40 bg-warning/5 p-2 text-[11px] flex flex-col gap-1`,children:[u(`strong`,{children:t(`customize.doorbell.legacyTitle`)}),u(`span`,{children:i.sources.map(e=>e.name??`#${e.deviceId}`).join(`, `)}),i.activation!==null&&u(`span`,{children:t(`customize.doorbell.legacyActivation`,{state:i.activation.state,authority:i.activation.authority})}),u(`span`,{className:`text-foreground-subtle`,children:t(`customize.doorbell.legacyAuthority`,{authority:i.authority})})]})}var fa=`pipeline-orchestrator`;function pa(e){return e.status===`pending`?`pending`:e.status===`error`?`unknown`:e.data===void 0?`pending`:e.data.cameraSensors===void 0?`absent`:`present`}function ma(e,t){return e===`absent`?`absent`:pa(t)}function ha(e,t){let n=Vt(fa),r=Rt({deviceId:e},{enabled:t&&n!==`absent`});return t?{presence:ma(n,{status:r.status,data:r.data}),status:r.data?.cameraSensors??null,refetch:r.refetch}:{presence:`absent`,status:null,refetch:r.refetch}}n();function ga(e){return e.state===`missing`||e.state===`unreadable`?e.stableId:e.name}function _a(e){return{addonId:e.addonId,stableId:e.stableId}}function va(e,t){let n=Nn(t);return e.some(e=>Nn(e)===n)}function ya(e){return e===null||e.state===`unreadable`?null:e.state===`configured`?e.sensors:[]}function ba(e,t){let n=Nn(t),r=e.filter(e=>Nn(e)!==n).map(_a);return r.length===0?null:{mode:`in-addition`,sensors:r}}function xa({device:e}){let{t}=X(),n=Xi(),i=ha(e.id,e.type===Y.Camera),a=cn({projection:`slim`}),s=pt({capNames:[...Pn]}),l=ot(),[d,f]=c(null),[p,m]=c([]),h=a.status===`success`?yr(a.data):[],g=i.status,_=ya(g),v=g?.state===`configured`?g.sensors:[],y=s.status===`success`&&_!==null?tr(h,s.data,e.id).filter(e=>!p.includes(e.id)&&!va(_,Cr(e))):[],b=async t=>{try{await l.mutateAsync({deviceId:e.id,config:t}),f(null),m([]),await i.refetch()}catch(e){f(e instanceof Error?e.message:String(e))}},x=async e=>{_!==null&&await n(t(`customize.motion.detachWhat`,{name:ga(e)}),!1)&&await b(ba(_,e))},S=async()=>{await n(t(`customize.motion.removeAllWhat`,{count:v.length}),!1)&&await b(null)},C=[...(_??[]).map(_a),...p.flatMap(e=>{let t=h.find(t=>t.id===e);return t===void 0?[]:[Cr(t)]})];return r(`div`,{className:`flex flex-col gap-2 rounded-md border border-border p-2`,children:[u(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`customize.motion.help`)}),u(Sa,{status:g}),u(`ul`,{className:`flex flex-col gap-1`,children:v.map(e=>r(`li`,{className:`flex items-center gap-2 text-[11px]`,children:[u(`span`,{children:ga(e)}),u(J,{variant:e.state===`ready`?`success`:`warning`,children:e.state}),e.state!==`ready`&&e.reason!==e.state&&u(`span`,{className:`text-foreground-subtle`,children:e.reason}),_!==null&&u(`button`,{type:`button`,"aria-label":t(`customize.motion.remove`,{name:ga(e)}),disabled:l.isPending,onClick:()=>void x(e),children:`×`})]},Nn(e)))}),u(Ca,{devices:h,picks:p,onChange:m}),r(`fieldset`,{className:`text-[11px]`,children:[u(`legend`,{children:t(`customize.motion.combine`)}),r(`label`,{className:`flex items-center gap-2`,children:[u(`input`,{type:`radio`,name:`camera-sensors-mode`,checked:!0,readOnly:!0}),t(`customize.motion.inAddition`)]})]}),_!==null&&r(o,{children:[u(`div`,{className:`flex flex-wrap gap-1`,children:y.map(e=>u(K,{variant:`outline`,size:`sm`,onClick:()=>m([...p,e.id]),children:t(`customize.motion.add`,{name:e.name})},e.id))}),r(`div`,{className:`flex gap-2`,children:[u(K,{disabled:p.length===0||l.isPending,onClick:()=>void b({mode:`in-addition`,sensors:C}),children:t(`customize.presets.apply`)}),v.length>0&&u(K,{variant:`outline`,disabled:l.isPending,onClick:()=>void S(),children:t(`customize.presets.remove`)})]})]}),d!==null&&u(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:d})]})}function Sa({status:e}){let{t}=X();return e===null?u(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:t(`customize.motion.reading`)}):e.state===`unreadable`?u(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:t(`customize.motion.unreadable`,{reason:e.reason})}):e.state===`configured`&&e.notForwarded!==void 0?u(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:t(`customize.motion.notForwarded.${e.notForwarded}`)}):null}function Ca({devices:e,picks:t,onChange:n}){let{t:i}=X();return t.length===0?null:u(`ul`,{"aria-label":i(`customize.motion.toAdd`),className:`flex flex-col gap-1`,children:t.map(a=>{let o=e.find(e=>e.id===a)?.name??`#${a}`;return r(`li`,{className:`flex items-center gap-2 text-[11px]`,children:[u(`span`,{children:o}),u(`button`,{type:`button`,"aria-label":i(`customize.motion.remove`,{name:o}),onClick:()=>n(t.filter(e=>e!==a)),children:`×`})]},a)})})}var wa=[`doorbell`,`battery`,`invert`,`convert`,`motion`,`consumables`];function Ta(e){return new Set(e.filter(e=>{let t=e.nativeAddonId?.trim()??``;return t!==``&&t!==`composer`}).map(e=>e.capName))}function Ea(e){return e.kind===`known`?null:e}function Da(e,t,n){let r=Ea(e.composable);return r===null?e.composable.kind===`known`&&e.composable.value.has(t)?{kind:`available`,mode:`add`,active:e.composed.has(t)}:{kind:`not-offered`,reason:n}:r}function Oa(e){if(e.deviceType!==Y.Camera)return{kind:`not-offered`,reason:`only a camera has camera sensors`};switch(e.cameraSensors){case`pending`:return{kind:`pending`};case`unknown`:return{kind:`unknown`,reason:`camera sensors could not be checked`};case`absent`:return{kind:`not-offered`,reason:`camera sensors (D672) are not installed on this hub`};case`present`:return{kind:`available`,mode:`add`,active:!1}}}function ka(e,t){if(e===`motion`)return Oa(t);let n=Ea(t.native);if(n!==null)return n;let r=t.native.kind===`known`?t.native.value:new Map;switch(e){case`doorbell`:return r.has(`doorbell`)?{kind:`not-offered`,reason:`this device has its own doorbell`}:Da(t,`doorbell`,`a doorbell is not offered on this device type`);case`battery`:return r.has(`battery`)?{kind:`available`,mode:`replace`,active:t.composed.has(`battery`)}:Da(t,`battery`,`a battery is not offered on this device type`);case`consumables`:return r.has(`consumables`)?{kind:`not-offered`,reason:`its consumables come from its integration; one composed item cannot join that list`}:Da(t,`consumables`,`consumables are not offered on this device type`);case`invert`:{let e=cr.filter(e=>r.has(e));return e.length===0?{kind:`not-offered`,reason:`this device has no state that can be inverted`}:{kind:`available`,mode:`replace`,active:e.some(e=>t.composed.has(e))}}case`convert`:return[...r.values()].some(e=>e.length>0)?{kind:`available`,mode:`replace`,active:!1}:{kind:`not-offered`,reason:`this device reports no number to convert`}}}n();var Aa={doorbell:aa,battery:Zi,invert:sa,convert:na,consumables:$i,motion:xa},ja=[`doorbell`,`motion`];function Ma(e,t){return e.flatMap(({id:e,availability:n})=>{let r=Aa[e];if(n.kind!==`available`||r===void 0)return[];let i=e===`motion`?t.attachedCameraSensors:null;return[{id:e,mode:n.mode,active:n.active,attached:i,panel:r}]})}function Na(e){return e.active||e.attached!==null&&e.attached>0}function Pa(e){return e.kind===`none`||e.kind===`present`?null:e}function Fa({device:e,handle:t,facts:n}){let{t:i}=X(),[a,o]=c(void 0),[s,l]=c(null),d=Pa(t.state),f=wa.map(e=>({id:e,availability:ka(e,n)})),p=d===null?Ma(f,n):[],m=d?.kind===`pending`||f.some(e=>e.availability.kind===`pending`),h=[...new Set(f.flatMap(e=>e.availability.kind===`unknown`?[e.availability.reason]:[]))],g=d===null&&!m?p.find(e=>Na(e)&&ja.includes(e.id))?.id??null:null,_=a===void 0?g:a,v=p.find(e=>e.id===_);return r(`section`,{"aria-labelledby":`customize-presets`,className:`rounded-lg border border-border bg-surface p-3 flex flex-col gap-2`,children:[u(`h2`,{id:`customize-presets`,className:`text-[11px] font-semibold uppercase tracking-wider`,children:i(`customize.presets.title`)}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:i(`customize.presets.intro`)}),d!==null&&d.kind!==`pending`&&u(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:i(`customize.presets.waiting`)}),m&&u(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:i(`customize.presets.checking`)}),h.map(e=>u(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:i(`customize.presets.unknown`,{reason:e})},e)),u(`div`,{className:`grid grid-cols-2 lg:grid-cols-3 gap-2`,children:p.map(e=>u(Ia,{preset:e,expanded:_===e.id,onToggle:()=>o(_===e.id?null:e.id)},e.id))}),v!==void 0&&u(v.panel,{device:e,target:t.target,current:Mi(t.state),mode:v.mode,active:v.active,facts:n,saving:t.saving,apply:async e=>{let n=await t.save(e);if(n.kind===`refused`){l(n.reason);return}l(null),o(null)}}),s!==null&&u(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:s}),On.includes(e.type)&&u(da,{deviceId:e.id})]})}function Ia({preset:e,expanded:t,onToggle:n}){let{t:i}=X();return r(`button`,{type:`button`,"aria-expanded":t,className:`flex flex-col items-start gap-0.5 rounded-md border border-border p-2 text-left hover:bg-surface-hover`,onClick:n,children:[u(`span`,{className:`text-xs font-medium`,children:i(`customize.presets.${e.id}.title`)}),u(`span`,{className:`text-[10px] text-foreground-subtle`,children:i(`customize.presets.${e.id}.hint`)}),e.active&&u(`span`,{title:i(`customize.presets.composedHint`),children:u(J,{variant:`info`,children:i(`customize.presets.composed`)})}),e.attached!==null&&e.attached>0&&u(J,{variant:`info`,children:i(`customize.motion.attached`,{count:e.attached})})]})}function La(e){return e instanceof Error?e.message:String(e)}function Ra(e){let t=ve({addonId:e.addonId,stableId:e.stableId}),n=ke(),r=F(),i=z(),a=ji({status:t.status,data:t.data,error:t.error===null||t.error===void 0?null:{message:t.error.message}});return{target:e,state:a,saving:n.isPending||r.isPending||i.isPending,save:async e=>{let o=Sr(a,e);try{switch(o.kind){case`refused`:return{kind:`refused`,reason:o.reason};case`noop`:return{kind:`saved`};case`create`:await n.mutateAsync({block:o.input});break;case`update`:await r.mutateAsync({blockId:o.blockId,expectedUpdatedAt:o.expectedUpdatedAt,block:{composition:o.composition}});break;case`delete`:await i.mutateAsync({blockId:o.blockId});break}return await t.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:La(e)}}}}}function za(e,t){if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??`the request failed`};let n=e.data;return e.status===`pending`||n===void 0?{kind:`pending`}:{kind:`known`,value:t(n)}}function Ba(e,t){return new Map([...e].map(e=>[e,(t.caps.find(t=>t.cap===e)?.fields??[]).filter(e=>e.kind===`number`&&e.item!==!0&&!e.path.includes(`.`)).map(e=>e.path)]))}function Va(e,t){return e.kind===`known`?t.kind===`known`?{kind:`known`,value:Ba(e.value,t.value)}:t:e}function Ha(e,t,n,r){let i=Fe({deviceType:e.type}),a=rn({deviceId:e.id}),o=ct({deviceId:e.id}),s=za(i,e=>new Set(e.caps.map(e=>e.cap))),c=za(a,e=>Ta(e.entries)),l=za(o,e=>e);return{deviceType:e.type,composable:s,native:Va(c,l),nativeCaps:c,wireable:l,composed:new Set((t?.features??[]).map(e=>e.cap)),cameraSensors:n,attachedCameraSensors:r}}n();function Ua({deviceId:e,activeSubTab:t,onSubTabChange:n}){let{t:r}=X(),i=q({deviceId:e}),a=i.data;return a==null?i.status===`error`?u(dt,{title:r(`customize.deviceUnreadable`),message:i.error?.message??``,onRetry:()=>void i.refetch()}):a===null?u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.noSuchDevice`,{deviceId:e})}):u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.loadingDevice`)}):a.addonId===`composer`?u(Wa,{device:a}):u(Ga,{device:a,target:{addonId:a.addonId,stableId:a.stableId},activeSubTab:t,onSubTabChange:n})}function Wa({device:e}){let{t}=X(),n=e.stableId.startsWith(`composed-`)?e.stableId.slice(Vn.length):null;return r(`section`,{className:`rounded-lg border border-border bg-surface p-4 flex flex-col gap-2`,children:[u(`p`,{className:`text-sm text-foreground`,children:t(`customize.composed.body`)}),n!==null&&u(Gn,{className:`text-sm text-primary`,to:Wn(n),children:t(`customize.composed.edit`)})]})}function Ga({device:e,target:t,activeSubTab:n,onSubTabChange:i}){let a=Ra(t),o=Vt(`composer`),{t:s}=X(),c=qa(e),l=ha(e.id,e.type===Y.Camera),d=l.status?.state===`configured`?l.status.sensors.length:null,f=Ha(e,Mi(a.state),l.presence,d),p=a.state.kind===`none`||a.state.kind===`present`,m=p?u(K,{variant:`outline`,size:`sm`,onClick:()=>i(Zn),children:s(`customize.advanced`)}):null;return n===`advanced`?r(`div`,{className:`flex flex-col gap-4`,children:[u(Ja,{state:a.state,integration:c}),p&&u(Ka,{device:e,target:t,handle:a,facts:f,onDone:()=>i(`main`)})]}):r(`div`,{className:`flex flex-col gap-4`,children:[o===`absent`&&u(`p`,{role:`alert`,className:`text-xs text-warning`,children:s(`customize.composerAbsent`)}),u(Ja,{state:a.state,integration:c}),u(Fa,{device:e,handle:a,facts:f}),u(Ki,{device:e}),u(Ji,{device:e}),a.state.kind===`present`&&u(Fi,{device:e,composition:a.state.composition,state:a.state.view.state,facts:f,action:m}),a.state.kind===`none`&&u(`div`,{children:m}),u(Ya,{handle:a})]})}function Ka({device:e,target:t,handle:n,facts:r,onDone:i}){let a=n.state.kind===`present`?n.state:null;return u(br,{initial:a===null?nr(t):ir(a.composition,``),blockId:a===null?null:a.view.block.id,deviceType:e.type,targetName:e.name,nativeCaps:r.nativeCaps,targetFields:r.wireable,onCancel:i,save:async e=>{let t=await n.save(e);return t.kind===`saved`&&i(),t}})}function qa(e){let{data:t}=Tt(void 0),n=Ce(e,t);return n.kind===`resolved`?n.integration.name:n.kind===`unknown`?null:e.integrationId??e.addonId}function Ja({state:e,integration:t}){let{t:n}=X();switch(e.kind){case`pending`:return u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:n(`customize.status.pending`)});case`unknown`:return u(dt,{title:n(`customize.status.unknownTitle`),message:e.reason});case`not-loaded`:return u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:n(`customize.status.notLoaded`,{reason:e.reason})});case`none`:return u(`p`,{className:`text-xs text-foreground-subtle`,children:t===null?n(`customize.status.noneIntegrationLoading`):n(`customize.status.none`,{integration:t})});case`present`:{let t=e.view.block;return r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[u(J,{variant:t.status===`running`?`success`:t.status===`failed`?`danger`:`warning`,children:n(`customize.blockStatus.${t.status}`)}),!t.enabled&&u(J,{variant:`default`,children:n(`customize.status.off`)}),t.lastError!==void 0&&u(`span`,{className:`text-[11px] text-foreground-muted break-words`,children:t.lastError}),e.view.state.kind===`unreachable`&&u(`span`,{className:`text-[11px] text-warning`,children:n(`customize.status.composerUnreachable`,{reason:e.view.state.error})})]})}}}function Ya({handle:e}){let{t}=X(),n=_n(),[i,a]=c(null);if(e.state.kind!==`present`)return null;let o=async()=>{if(!await n({title:t(`customize.remove.title`),message:t(`customize.remove.message`),confirmLabel:t(`customize.remove.confirm`),variant:`danger`}))return;let r=await e.save(null);a(r.kind===`refused`?r.reason:null)};return r(`div`,{className:`flex flex-col items-start gap-1`,children:[u(K,{variant:`danger`,disabled:e.saving,onClick:()=>void o(),children:t(`customize.remove.button`)}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`customize.remove.hint`)}),i!==null&&u(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:i})]})}var Xa=`overview`;function Za(e,t){return e.some(e=>e.id===t)?t:Xa}function Qa({deviceId:e}){let t=s(),n=Number.isFinite(e),{data:i}=q({deviceId:e},{enabled:n}),a=typeof i?.type==`string`?i.type:`camera`;Yt([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:o,isLoading:c,isError:l,error:d}=rn({deviceId:e},{enabled:n}),{data:f}=hn({deviceType:a},{enabled:!!a}),p=qe({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(c)return u(`div`,{className:`p-4`,children:u(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(l)return r(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,d instanceof Error?d.message:String(d)]});let m=new Map,h={};for(let e of f??[])h[e.capName]=e.wrappers;for(let e of o?.entries??[])m.set(e.capName,{...e,wrappers:h[e.capName]??[]});for(let e of f??[])m.has(e.capName)||m.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let g=[...m.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(g.length===0)return r(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[u(Sn,{className:`h-8 w-8 opacity-40`}),u(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),u(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let _=g.filter(e=>e.kind!==`unbound`).length;return r(`div`,{className:`flex flex-col gap-3 p-1`,children:[r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-foreground`,children:_}),` of `,g.length,` capabilit`,g.length===1?`y`:`ies`,` bound — rows marked `,u(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),u(an,{columns:[{key:`capability`,header:`Capability`,render:e=>u(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>u($a,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>u(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||u(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?u(eo,{nodeId:e.providerNodeId}):u(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>u(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||u(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return u(to,{wrappers:t.wrappers,activeWrapperId:n,disabled:p.isPending,onPick:r=>{let i=n===r;p.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:g,rowKey:e=>e.capName,minWidthPx:720})]})}function $a({kind:e}){return e===`native`?r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(Te,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(En,{className:`h-3 w-3`}),`wrapped`]}):e===`linked`?r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-warning/30 text-warning bg-warning/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(Zt,{className:`h-3 w-3`}),`linked`]}):r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(Qe,{className:`h-3 w-3`}),`unbound`]})}function eo({nodeId:e}){return u(`span`,{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e===`hub`?`text-foreground-subtle`:`text-foreground`}`,children:e})}function to({wrappers:e,activeWrapperId:t,disabled:n,onPick:i}){return e.length===0?u(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):u(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let a=e===t;return r(`button`,{disabled:n,onClick:()=>i(e),title:a?`Click to deactivate (revert to native)`:`Activate wrapper ${e}`,className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${a?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[u(a?Ge:y,{className:`h-3 w-3`}),e]},e)})})}function no({deviceId:e,activeSubTab:t,onSubTabChange:n,deviceType:i,isAdmin:a}){return r(`div`,{className:`flex flex-col gap-3`,children:[jr(i,a)&&u(xt,{deviceId:e,readOnly:!0}),u(Nr,{deviceId:e,activeSubTab:t,onSubTabChange:n})]})}n();var ro=new Set([`package-detection`]);function io(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function ao(e){return e?e.modelId!==void 0||e.settings!==void 0:!1}function oo({deviceId:e,refreshToken:t}){let n=s(),l=_().trpcClient,[d,f]=c(null),[p,m]=c(null),[h,g]=c(null),v=Ee({deviceId:e},{refetchOnMount:`always`}),y=Lt({deviceId:e},{refetchOnMount:`always`}),b=bn(void 0,{refetchOnMount:`always`});Yt([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let{nodes:x}=Pe(),S=i(()=>{let e=new Set;for(let t of x)t.isOnline&&e.add(t.id);return e},[x]),C=i(()=>(b.data??[]).filter(e=>S.has(e.nodeId)).map(e=>e.nodeId),[b.data,S]),w=a({enabled:C.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`device-step-schemas`,C.join(`,`),t],queryFn:async()=>{let e={};for(let t of C)try{e[t]=await l.pipelineExecutor.getSchema.query({nodeId:t})}catch{}return e}}),T=e=>w.data?.[e]??null,E=i(()=>{let e=C[0];if(e!==void 0){let t=w.data?.[e];if(t)return t}return Object.values(w.data??{})[0]??null},[C,w.data]),D=a({enabled:C.length>0,queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`],`device-step`,C.join(`,`),t],queryFn:async()=>{let e={};for(let t of C)try{e[t]=(await l.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:t})).devices}catch{e[t]=[]}return e}}),O=()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]})},A=Me({onSuccess:O}),j=k({onSuccess:O}),M=i(()=>E?_t(E):[],[E]),N=i(()=>{let e=b.data??[],t=S.size===0?[]:e.filter(e=>S.has(e.nodeId)),n=[];for(let e of t){let t=(D.data?.[e.nodeId]??[]).filter(e=>e.enabled&&e.available);if(t.length>=2)for(let r of t)n.push({agentNodeId:e.nodeId,engineLabel:r.format,deviceKey:r.key,deviceLabel:Tn(r).label});else n.push({agentNodeId:e.nodeId,engineLabel:t[0]?.format??`(engine unknown)`})}return n},[b.data,D.data,S]),P=(e,t)=>D.data?.[e]?.find(e=>e.key===t)??null,ee=e=>{if(e.deviceKey!==void 0)return e.deviceKey;let t=D.data?.[e.agentNodeId]??[],n=t.filter(e=>e.enabled&&e.available);return n.length>=1?n[0].key:t.find(e=>e.available)?.key??t[0]?.key??null},F=(e,t,n)=>y.data?.[e]?.[t]?.[n]??null,te=e=>{if(ro.has(e))return{kind:`zone-driven`};let t=io(E,e)?.enabledByDefault??!0,n=v.data?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},I=(e,t,n)=>{let r=io(T(n),e);if(r)return se(r,t)},ne=(e,t)=>{let n=te(e),r=n.kind===`gate`?n.effectiveOn:!1,i=io(T(t.agentNodeId),e),a=ee(t),o=a===null?null:P(t.agentNodeId,a);if(!Xe(i?.models??[],o?.format))return r?{kind:`skip`}:{kind:`na`};let s=a===null?null:F(t.agentNodeId,a,e),c=o?.steps?.[e];return{kind:`enabled`,modelId:(i?He({catalog:i,device:o,override:s?.modelId,base:c?.modelId}):void 0)??`Auto`,overridden:ao(s)}},L=d===null?null:io(T(d.agentNodeId),d.addonId),R=d?P(d.agentNodeId,d.deviceKey):null,re=R?.format??`coreml`,ie=d?ao(F(d.agentNodeId,d.deviceKey,d.addonId)):!1,z=d?I(d.addonId,R,d.agentNodeId):void 0,ae=i(()=>{if(!d||!R)return null;let e=R.steps?.[d.addonId];return{enabled:!0,...e?.modelId===void 0?{}:{modelId:e.modelId},settings:e?.settings??{}}},[d,R]),oe=()=>{f(null),m(null)},B=(e,t)=>{let n=ee(t);n!==null&&(f({addonId:e,agentNodeId:t.agentNodeId,deviceKey:n}),m(F(t.agentNodeId,n,e)))},V=(t,n)=>{j.mutate({deviceId:e,addonId:t,enabled:n})},H=()=>{d&&A.mutate({deviceId:e,agentNodeId:d.agentNodeId,deviceKey:d.deviceKey,addonId:d.addonId,patch:p},{onSuccess:oe})},ce=()=>{d&&A.mutate({deviceId:e,agentNodeId:d.agentNodeId,deviceKey:d.deviceKey,addonId:d.addonId,patch:null},{onSuccess:oe})};if(b.isLoading||C.length>0&&w.isLoading)return u(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(N.length===0)return u(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`No online agents.`});if(!E)return u(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let le=d!==null&&L!==null&&R!==null;return r(`div`,{className:`relative h-full w-full space-y-3`,children:[r(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-foreground`,children:`Gate`}),` (col 1) decides whether this camera runs a step — independent of nodes. Each`,` `,u(`span`,{className:`font-medium text-foreground`,children:`node column`}),` shows the model that node runs; click a cell to pin a per-camera model override for that accelerator. A gated-on step with no model on a device shows a clickable `,u(`span`,{className:`text-amber-500`,children:`⚠ skip`}),` `,`and won't run there.`]}),r(`div`,{className:`rounded-md border border-sky-500/25 bg-sky-500/[0.06] px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-sky-400`,children:`Placement is dynamic.`}),` When a node has multiple inference accelerators, each session is balanced across them per-session at dispatch time — these device columns show each accelerator's effective model (override ?? device default), not a fixed assignment.`]}),u(`div`,{className:le?`md:pr-[360px]`:``,children:M.length>0?u(dn,{tree:M,agents:N,gateFor:te,getCellState:ne,onCellClick:B,selectedCell:d,onSetGate:V,gateBusy:j.isPending,fallbackNodeId:h,onFallbackNodeChange:g}):u(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),u(wt,{open:le,onClose:oe,title:L?.name??``,subtitle:d&&R?`${d.agentNodeId} · ${Tn(R).label} · ${R.format}`:``,footer:r(o,{children:[u(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle disabled:opacity-50`,disabled:!ie||A.isPending,onClick:ce,children:`Clear override`}),u(`div`,{className:`flex-1`}),u(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:oe,children:`Cancel`}),u(`button`,{type:`button`,disabled:!d||!ae||A.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:H,children:A.isPending?`Saving…`:`Save`})]}),children:L&&d&&ae?u(We,{mode:`device`,addon:L,agentDefault:ae,agentNodeId:d.agentNodeId,currentPatch:p,engineFormat:re,effectiveModelId:z,onChangePatch:m}):u(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-300`,children:`This accelerator is no longer reported by the node, so there is nothing to provision here.`})})]})}var so=[{id:`object-detection`,label:`Object detection`,icon:`scan-search`},{id:`tracking`,label:`Tracking`,icon:`route`},{id:`motion`,label:`Motion`,icon:`activity`},{id:`stationary`,label:`Stationary`,icon:`square-parking`},{id:`zones`,label:`Zones`,icon:`shapes`},{id:`audio`,label:`Audio`,icon:`volume-2`},{id:`cluster`,label:`Cluster`,icon:`server`}],co={"pipeline-object-detection":`object-detection`,"detection-sensitivity":`object-detection`,"onboard-object-detection":`object-detection`,tracking:`tracking`,"tracking-core":`tracking`,"motion-tuning":`motion`,"stationary-objects":`stationary`,occupancy:`stationary`,zones:`zones`,"pipeline-audio":`audio`,"cluster-assignment":`cluster`,"orchestrator-live":`cluster`};function lo(e){return co[e]??`object-detection`}n();var uo=`steps`,fo=`settings`,po=new Set([uo,fo]);function mo(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function ho({deviceId:t,activeSubTab:n,onSubTabChange:i}){return r(vn,{value:n&&po.has(n)?n:uo,onValueChange:e(e=>{i?.(e)},[i]),className:`flex flex-col`,children:[r(pn,{className:`flex-shrink-0`,children:[u(Ie,{value:uo,children:`Steps`}),u(Ie,{value:fo,children:`Settings`})]}),u(mt,{value:uo,children:u(oo,{deviceId:t,refreshToken:0})}),u(mt,{value:fo,children:u(Nr,{deviceId:t,sectionFilter:mo,subTabGrouping:{groupOf:e=>lo(e.id),tabs:so}})})]})}n();function go({deviceId:e,initialLocation:n}){let a=s(),[o,l]=c(!1),[f,p]=c(n??``),[m,h]=c(!1),g=t(null),{data:_}=te(void 0,{enabled:o}),v=_??[];d(()=>{o||p(n??``)},[n,o]),d(()=>{o&&g.current?.focus()},[o]);let y=R({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),b=i(()=>{let e=f.trim().toLowerCase();return e.length===0?v:v.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[v,f]),x=f.trim().length>0&&!v.some(e=>e.toLowerCase()===f.trim().toLowerCase()),S=async t=>{let r=(t??f).trim(),i=r.length===0?null:r;if(i===(n??null)){l(!1);return}h(!0);try{await y.mutateAsync({deviceId:e,location:i}),l(!1)}catch{}finally{h(!1)}},C=()=>{p(n??``),l(!1)};return o?u($,{label:`Location`,value:r(`div`,{className:`relative`,children:[r(`div`,{className:`flex items-center gap-1`,children:[u(`input`,{ref:g,type:`text`,value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`?S():e.key===`Escape`&&C()},disabled:m,placeholder:`Room / area (or leave empty to clear)`,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),u(`button`,{type:`button`,onClick:()=>void S(),disabled:m,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:u(Ge,{className:`h-3 w-3`})}),u(`button`,{type:`button`,onClick:C,disabled:m,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:u(oe,{className:`h-3 w-3`})})]}),(b.length>0||x)&&r(`div`,{className:`absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md`,children:[b.map(e=>r(`button`,{type:`button`,onClick:()=>{p(e),S(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[u(je,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),u(`span`,{className:`truncate`,children:e})]},e)),x&&r(`button`,{type:`button`,onClick:()=>void S(),className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover border-t border-border`,children:[u(`span`,{className:`text-foreground-subtle`,children:`Create`}),r(`span`,{className:`font-medium truncate`,children:[`"`,f.trim(),`"`]})]})]})]})}):u($,{label:`Location`,value:r(`div`,{className:`flex items-center gap-2 group`,children:[n?u(`span`,{className:`truncate`,children:n}):u(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),u(`button`,{type:`button`,onClick:()=>l(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit location`,children:u(Je,{className:`h-3.5 w-3.5`})})]})})}n();function _o({deviceId:e}){let t=s(),{data:n}=er(e),{data:i}=$n(e),[a,l]=c(null),d=P({onSuccess:()=>{l(null),t.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{l(`Could not change primary child: ${e.message}`)}});if(n==null||String(n.type??``)!==Y.Container)return null;let f=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}}));if(f.length<=1)return null;let p=me(f,typeof n.linkDeviceId==`number`?n.linkDeviceId:null,typeof n.primaryChildEntityId==`string`?n.primaryChildEntityId:null);return r(o,{children:[u($,{label:`Primary child`,value:u(Ke,{childrenList:f,selectedId:p===null?f[0].id:p.id,onSetPrimary:t=>d.mutate({deviceId:e,primaryChildEntityId:t}),disabled:d.isPending})}),a!==null&&u(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:a})]})}n();var vo=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function yo(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function bo(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function xo(){let e=jt(),t=Ot(),{data:n}=q({deviceId:e??0},{enabled:e!==null}),{data:i}=rn({deviceId:e??0},{enabled:e!==null}),a=n??t??null,[o,s]=c(`identity`);if(e===null||!a)return null;let l=String(a.stableId??``),d=String(a.name??``),f=String(a.type??``),p=String(a.addonId??``),m=a.features??[],h=new Set([`device-status`,`feature-probe`,`device-ops`]),g=(i?.entries??[]).filter(e=>e.kind===`native`&&!h.has(e.capName)).map(e=>e.capName),_=m.length>0?m:g,v=a.location??null,y=a.metadata??null,b=y!==null&&Object.keys(y).length>0;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[u(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),b&&r(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[u(So,{active:o===`identity`,onClick:()=>s(`identity`),label:`Identity`}),u(So,{active:o===`hardware`,onClick:()=>s(`hardware`),label:`Hardware`})]})]}),(!b||o===`identity`)&&r(`div`,{className:`divide-y divide-border`,children:[u($,{label:`ID`,value:r(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${e}`,r(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,l,`)`]})]})}),u(zi,{deviceId:e,initialName:d}),u(go,{deviceId:e,initialLocation:v}),u(_o,{deviceId:e}),u($,{label:`Type`,value:f}),u($,{label:`Provider`,value:u(Cn,{type:p,size:`sm`,showLabel:!0})}),u($,{label:`Capabilities`,value:_.length>0?u(Dn,{capabilities:_,showLabels:!0}):u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),b&&o===`hardware`&&u(Co,{metadata:y})]})}function So({active:e,onClick:t,label:n}){return u(`button`,{type:`button`,onClick:t,className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${e?`bg-surface text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`}`,children:n})}function Co({metadata:e}){let t=vo.filter(t=>t in e),n=Object.keys(e).filter(e=>!vo.includes(e)).toSorted(),i=[...t,...n];return r(`div`,{children:[u(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-b border-border bg-surface-subtle/40`,children:`Auto-populated by the driver on every connect. Read-only.`}),u(`div`,{className:`divide-y divide-border`,children:i.map(t=>u($,{label:yo(t),value:u(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:bo(e[t])})},t))})]})}var wo=`Notifications`,To=`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`;function Eo(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:wo,on:r===null?null:i??r,available:r!==null,costWhenOff:To}}function Do(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}n();function Oo(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function ko({deviceId:t}){let n=s(),i=Number.isFinite(t),[a,o]=c(null),[l,d]=c(null),f=Eo({mutedDeviceIds:Oo(de({},{enabled:i}).data),deviceId:t,pendingOn:l}),p=tt({onError:e=>{console.error(`[DeviceNotificationMute] mute write failed — reverting`,{tags:{deviceId:t},meta:{error:e instanceof Error?e.message:String(e)}}),d(null),o(e instanceof Error?e.message:String(e)),n.invalidateQueries({queryKey:[[`notificationRules`,`listDeviceMutes`]]})},onSuccess:()=>{o(null),d(null),n.invalidateQueries({queryKey:[[`notificationRules`]]})}}),m=e(()=>{let e=Do(f,t);e!==null&&(d(!e.muted),p.mutate(e))},[t,p,f]),h=f.on===null,g=f.on===!1,_=g?$e:it;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`border-b border-border px-4 py-2 flex items-center justify-between gap-2`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Notifications`}),g&&u(`span`,{className:`rounded bg-warning/20 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide text-warning`,children:`muted`})]}),r(`div`,{className:`px-4 py-3 flex items-start gap-3`,children:[r(`button`,{type:`button`,role:`switch`,"aria-label":f.label,"aria-checked":f.on===!0,disabled:!f.available||p.isPending,onClick:m,title:h?`Notification mute — state unknown; the notification centre did not answer.`:g?`Muted. ${f.costWhenOff}`:`Notifying. Muting it: ${f.costWhenOff}`,className:`inline-flex items-center gap-1.5 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors disabled:cursor-not-allowed ${a===null?h?`border-dashed border-border text-foreground-subtle/50`:g?`border-warning/40 text-warning hover:bg-warning/10`:`border-success/30 text-success hover:bg-success/10`:`border-danger/50 text-danger bg-danger/5`}`,children:[u(_,{className:`h-3.5 w-3.5`}),u(`span`,{children:h?`Unknown`:g?`Muted`:`Notifying`})]}),u(`p`,{className:`flex-1 text-[11px] leading-relaxed text-foreground-subtle`,children:a===null?h?`The notification centre did not answer, so this device’s mute state is unknown.`:f.costWhenOff:`Write failed: ${a}`})]})]})}function Ao(e,t){return{switchId:e,label:zn[e].label,detail:t===void 0||t.length===0?null:t}}function jo(e){let t=new Map;for(let n of e.switches)n.deviceId===e.sourceId&&(t.has(n.switchId)||t.set(n.switchId,n));return t}function Mo(e){let t=jo(e),n=new Set(e.sourceStillLive),r=e.sourceStillLive.map(e=>Ao(e,t.get(e)?.detail)),i=[...t.values()].filter(e=>e.outcome===`not-offered`&&!n.has(e.switchId)).map(e=>Ao(e.switchId,e.detail));return{inheritedId:e.sourceId,retiredId:e.targetId,swapped:e.swapped,verdict:r.length===0?`quiet`:`still-live`,stillLive:r,neverOffered:i}}n();function No(e,t){return e.filter(e=>e.isCamera&&e.id!==t).map(e=>({id:e.id,name:e.name})).toSorted((e,t)=>e.name.localeCompare(t.name))}function Po({deviceId:e,deviceName:t}){let{t:n}=X(),a=_n(),[o,s]=c(null),l=cn({isCamera:!0,projection:`slim`}),d=Le(),f=l.data!==void 0,p=i(()=>l.data===void 0?[]:No(l.data,e),[l.data,e]),m=p.find(e=>e.id===o)??null,h=d.data===void 0?null:Mo(d.data),g=d.error===null?null:d.error.message,_=async()=>{m===null||m.id===e||await a({title:n(`deviceMigrate.confirmTitle`,`Replace “{{source}}” with “{{target}}”?`,{source:t,target:m.name}),message:n(`deviceMigrate.confirmMessage`,`“{{target}}” takes over number {{sourceId}}. That number is what every recording, event, rule, zone and home-automation export of “{{source}}” is filed under, so all of it follows the number to the new hardware and keeps working. “{{source}}” is switched off and handed number {{targetId}} in exchange. This swaps two device identities and cannot be undone from here.`,{source:t,target:m.name,sourceId:e,targetId:m.id}),confirmLabel:n(`deviceMigrate.confirmAction`,`Migrate`),variant:`danger`})&&d.mutate({sourceId:e,targetId:m.id})};return r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`min-w-0`,children:[u(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:n(`deviceMigrate.title`,`Migrate to…`)}),u(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:n(`deviceMigrate.subtitle`,`Replace this camera with other hardware you have already adopted. The new camera inherits number {{deviceId}}, so recordings, rules and integrations follow it.`,{deviceId:e})})]}),r(`div`,{className:`flex shrink-0 items-center gap-2`,children:[r(`select`,{"aria-label":n(`deviceMigrate.pickerLabel`,`Replacement camera`),className:`rounded-md border border-border bg-background px-2 py-1.5 text-xs text-foreground disabled:opacity-50`,disabled:!f||p.length===0||d.isPending,value:o===null?``:String(o),onChange:e=>{let t=e.target.value;s(t===``?null:Number(t))},children:[u(`option`,{value:``,children:f?n(`deviceMigrate.pickerPlaceholder`,`Select a camera…`):n(`deviceMigrate.pickerPending`,`Reading the fleet…`)}),p.map(e=>r(`option`,{value:String(e.id),children:[e.name,` (#`,e.id,`)`]},e.id))]}),r(`button`,{type:`button`,disabled:m===null||d.isPending,onClick:()=>{_()},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[u(Pr,{className:`h-3 w-3`}),d.isPending?n(`deviceMigrate.running`,`Migrating…`):n(`deviceMigrate.action`,`Migrate`)]})]})]}),f&&p.length===0&&u(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:n(`deviceMigrate.noTargets`,`No other camera is adopted, so there is nothing to migrate to.`)}),g!==null&&u(`p`,{className:`mt-2 text-[11px] text-danger`,children:n(`deviceMigrate.failed`,`Migration failed: {{error}}`,{error:g})}),h!==null&&u(Fo,{report:h})]})}function Fo({report:e}){let{t}=X(),n=e.verdict===`quiet`;return r(`div`,{className:`mt-3 space-y-2 border-t border-border pt-3`,children:[u(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`deviceMigrate.swapped`,`The replacement now answers on number {{inheritedId}}; the old camera was handed number {{retiredId}}.`,{inheritedId:e.inheritedId,retiredId:e.retiredId})}),n?r(`div`,{className:`flex items-start gap-2 rounded-md border border-success/30 bg-success/5 px-3 py-2`,children:[u(ue,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-success`}),u(`p`,{className:`text-[11px] leading-relaxed text-foreground`,children:t(`deviceMigrate.quiet`,`Every function on the replaced camera was switched off — the old hardware is quiet.`)})]}):r(`div`,{className:`rounded-md border border-warning/40 bg-warning/5 px-3 py-2`,children:[r(`div`,{className:`flex items-start gap-2`,children:[u(_e,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),u(`p`,{className:`text-[11px] leading-relaxed text-foreground`,children:t(`deviceMigrate.stillLive`,`The replaced camera could not be reached, so these functions are STILL RUNNING on the old hardware. Nothing here failed to migrate — but until you unplug it or reach it physically, it can still produce data.`)})]}),u(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.stillLive.map(e=>r(`li`,{className:`text-[11px] text-foreground`,children:[u(`span`,{className:`font-medium`,children:e.label}),e.detail!==null&&r(`span`,{className:`text-foreground-subtle`,children:[` — `,e.detail]})]},e.switchId))})]}),e.neverOffered.length>0&&r(`div`,{className:`rounded-md border border-border px-3 py-2`,children:[r(`div`,{className:`flex items-start gap-2`,children:[u(wn,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),u(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`deviceMigrate.neverOffered`,`The replaced camera never offered these, so there was nothing to switch off. They are not running.`)})]}),u(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.neverOffered.map(e=>u(`li`,{className:`text-[11px] text-foreground-subtle`,children:e.label},e.switchId))})]})]})}n();function Io({deviceId:e}){let[t,n]=c(null),i=en({onSuccess:e=>{n(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>n(`Re-sync failed: ${e.message}`)});return r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[r(`div`,{className:`flex items-center justify-between gap-3`,children:[r(`div`,{children:[u(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),u(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),r(`button`,{type:`button`,disabled:i.isPending,onClick:()=>{n(null),i.mutate({camDeviceId:e})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[u(le,{className:`h-3 w-3 ${i.isPending?`animate-spin`:``}`}),i.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&u(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}function Lo({deviceName:e,value:t,inheritedIcon:n,inheritedLabel:i,disabled:a,onChange:o}){let{t:s}=X(),c={trigger:s(`deviceDisplay.pickIcon`,{name:e}),panel:s(`deviceDisplay.iconFor`,{name:e}),close:s(`deviceDisplay.closePicker`),searchPlaceholder:s(`deviceDisplay.iconSearchPlaceholder`),clear:i,noMatches:s(`deviceDisplay.iconNoMatches`),groups:{device:s(`deviceDisplay.iconGroupDevice`),lighting:s(`deviceDisplay.iconGroupLighting`),sensing:s(`deviceDisplay.iconGroupSensing`),place:s(`deviceDisplay.iconGroupPlace`),life:s(`deviceDisplay.iconGroupLife`)}};return r(`div`,{className:`flex items-center gap-2`,children:[u(ln,{value:t===``?null:t,onPick:e=>o(e??``),resolveGlyph:Be,fallbackGlyph:n,labels:c,disabled:a}),u(`span`,{className:`text-[11px] text-foreground-subtle`,children:t===``?i:t})]})}n();var Ro=`w-full min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary disabled:opacity-50`,zo={icon:``,label:``,unit:``,precision:``,hidden:!1};function Bo(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function Vo(e){if(typeof e!=`object`||!e)return;let t=e.unit;return typeof t==`string`?t:void 0}function Ho(e){if(e.trim()===``)return;let t=Number.parseInt(e,10);return Number.isFinite(t)?t:void 0}function Uo(e,t){let n=Ho(e.precision),r={...e.icon===``?{}:{icon:e.icon},...e.label.trim()===``?{}:{label:e.label.trim()},...e.unit===``?{}:{unit:e.unit},...n===void 0?{}:{precision:n},...e.hidden?{hidden:!0}:{},...t?.perCap===void 0?{}:{perCap:t.perCap}};return Object.keys(r).length===0?null:r}function Wo({deviceId:e}){let{t}=X(),n=_(),a=s(),{data:l}=q({deviceId:e},{enabled:e>0}),d=typeof l?.role==`string`&&l.role.length>0?l.role:null,f=d===null?void 0:G[d],p=f?.kind===`numeric`,m=String(l?.type??``),h=d!==null||l?.parentDeviceId!==null&&l?.parentDeviceId!==void 0,g=ht(n.trpcClient,e,d??``),v=f?.kind===`numeric`?f.canonicalUnit:void 0,y=Vo(g)??v,b=y===void 0?void 0:kn(y),x=i(()=>b===void 0?[]:Rn(b),[b]),[S,C]=c(null),w=S??Bo(l?.display),T=Oe({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:E}=Dt({},{staleTime:6e4,enabled:d!==null}),D=H({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(l==null)return null;let O=e=>{C({...w,...e})},k=()=>{T.mutate({deviceId:e,display:Uo(w,l.display)})},A=()=>{C(zo),T.mutate({deviceId:e,display:null})},j=()=>{if(d===null)return;let e=Ho(w.precision),t={...w.icon===``?{}:{icon:w.icon},...w.unit===``?{}:{unit:w.unit},...e===void 0?{}:{precision:e}},n={...E?.defaults,[d]:t};D.mutate({defaults:n})},M=d===null?void 0:E?.defaults[d]?.icon,P=M===void 0?void 0:Be(M),ee=d===null?B(m):N(d),F={icon:P??ee.icon,label:P===void 0?ee.label:String(M)},te=d===null&&m===Y.Container?t(`deviceDisplay.inheritedContainer`):P===void 0?t(`deviceDisplay.inherited`,{name:F.label}):t(`deviceDisplay.inheritedRoleDefault`,{icon:F.label,role:ee.label}),I=typeof l.name==`string`?l.name:`#${String(e)}`,ne=d===null?``:N(d).label;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[u(`div`,{className:`border-b border-border px-3 sm:px-4 py-2`,children:u(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:t(`deviceDisplay.title`)})}),r(`div`,{className:`divide-y divide-border`,children:[u($,{label:t(`deviceDisplay.icon`),value:u(Lo,{deviceName:I,value:w.icon,inheritedIcon:F.icon,inheritedLabel:te,disabled:T.isPending,onChange:e=>O({icon:e})})}),h&&u($,{label:t(`deviceDisplay.label`),value:u(`input`,{type:`text`,className:Ro,"aria-label":t(`deviceDisplay.label`),placeholder:d===null?I:ne,value:w.label,onChange:e=>O({label:e.target.value})})}),p&&r(o,{children:[u($,{label:t(`deviceDisplay.unit`),value:r(`select`,{className:Ro,"aria-label":t(`deviceDisplay.unit`),value:w.unit,onChange:e=>O({unit:e.target.value}),disabled:x.length===0,children:[u(`option`,{value:``,children:t(`deviceDisplay.unitSource`,{unit:y===void 0?``:` (${y})`})}),x.map(e=>u(`option`,{value:e,children:e},e))]})}),u($,{label:t(`deviceDisplay.precision`),value:u(`input`,{type:`number`,min:0,max:10,step:1,className:Ro,"aria-label":t(`deviceDisplay.precision`),placeholder:t(`deviceDisplay.precisionInherit`),value:w.precision,onChange:e=>O({precision:e.target.value})})})]}),u($,{label:t(`deviceDisplay.hidden`),value:r(`label`,{className:`flex items-center gap-2`,children:[u(`input`,{type:`checkbox`,checked:w.hidden,onChange:e=>O({hidden:e.target.checked})}),u(`span`,{className:`text-[11px] text-foreground`,children:t(`deviceDisplay.hideFromLists`)})]})})]}),r(`div`,{className:`border-t border-border px-3 sm:px-4 py-2 flex flex-wrap items-center gap-2`,children:[u(`button`,{type:`button`,className:`rounded bg-primary px-3 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-50`,onClick:k,disabled:T.isPending,children:t(`common.save`)}),u(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-[11px] text-foreground-subtle`,onClick:A,disabled:T.isPending,children:t(`common.reset`)}),d!==null&&u(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-[11px] text-foreground-subtle`,onClick:j,disabled:D.isPending,title:t(`deviceDisplay.setRoleDefaultTitle`,{role:ne}),children:t(`deviceDisplay.setRoleDefault`,{role:ne})})]})]})}function Go(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function Ko({device:e}){let t=Kn(),n=typeof e.id==`number`?e.id:null,i=String(e.type??``),a=i===Y.Camera,o=i===Y.Hub,s=e.features??[],c=s.includes(An.Resyncable),{data:l}=V({deviceId:n??0},{enabled:n!==null&&a,refetchInterval:5e3}),d=l?.streams??{},f=Object.entries(d),p=s.includes(An.DoorbellButton),m=Nt(p?{deviceId:n??void 0,historyLimit:10}:void 0),h=m.latest?Date.now()-m.latest.timestamp<3e4:!1;return r(`div`,{className:`space-y-5`,children:[o&&n!==null&&u(ft,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),c&&n!==null&&u(Io,{deviceId:n}),a&&n!==null&&u(Po,{deviceId:n,deviceName:String(e.name??``)}),n!==null&&u(ko,{deviceId:n}),a&&n!==null&&u(Ne,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),p&&u(mn,{history:m.history,latestIsFresh:h}),a&&n!==null&&u(Ne,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),a&&f.length>0&&r(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[u(`div`,{className:`border-b border-border px-4 py-2`,children:u(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),u(`div`,{className:`divide-y divide-border`,children:f.map(([e,t])=>r(`div`,{className:`px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 mb-2`,children:[u(U,{className:`h-3 w-3 text-foreground-subtle`}),u(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),r(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[u(qo,{label:`Nominal`,value:Go(t.nominalBitrateKbps??0)}),u(qo,{label:`Observed`,value:Go(t.observedBitrateKbps??0)}),u(qo,{label:`Peak`,value:Go(t.peakBitrateKbps??0)}),u(qo,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),u(xo,{}),n!==null&&u(Wo,{deviceId:n})]})}function qo({label:e,value:t,warning:n}){return r(`div`,{children:[u(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),u(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}var Jo=[{id:`overview`,label:`Overview`,cameraOnly:!1,adminOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1,adminOnly:!1},{id:Xn,label:`Customize`,cameraOnly:!1,adminOnly:!0},{id:`detection-pipeline`,label:`Detection pipeline`,cameraOnly:!0,adminOnly:!1},{id:`bindings`,label:`Bindings`,cameraOnly:!0,adminOnly:!1}];function Yo(e,t){let n=e===Y.Camera;return Jo.filter(e=>(n||!e.cameraOnly)&&(t||!e.adminOnly)).map(({id:e,label:t})=>({id:e,label:t}))}function Xo({provider:e,integrationId:t,name:n}){let r=Kn(),i=t===null?`/integrations`:`/integrations/${t}`,a=n===null?`Open integrations`:`Open integration ${n}`;return u(`button`,{type:`button`,onClick:()=>r(i),className:`shrink-0 rounded-md transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-1 focus-visible:ring-primary/50`,title:a,"aria-label":a,children:u(Cn,{type:e,size:`lg`})})}n();var Zo=[{id:`logs`,icon:M,label:`Logs`},{id:`repl`,icon:qn,label:`REPL`},{id:`events`,icon:pe,label:`Events`},{id:`state`,icon:ze,label:`State`}];function Qo(){let n=Yn(),a=Number(n.deviceId),l=Number.isFinite(a),d=Kn(),f=s(),m=_n(),h=_(),{user:g}=Qn(),v=g?.isAdmin===!0,[y,b]=Jn(),x=y.get(`tab`)??`overview`,S=y.get(`sub`),[T,D]=c(`logs`),O=`device-detail.left-col-width-px`,[k,j]=c(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(O),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),M=t(k);M.current=k;function N(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??k??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{j(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=M.current;if(e!==null)try{window.localStorage.setItem(O,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:P,isLoading:F,isError:te}=q({deviceId:a},{enabled:l,refetchInterval:5e3,retry:1}),{data:I}=At({deviceId:a},{enabled:l}),L=i(()=>{let e=I?.settings?.sections??[],t=I?.live?.sections??[],n=[...e,...t],r=new Set;for(let e of n)e.location===`top-tab`&&e.tab&&r.add(e.tab===`zones`?`detection-pipeline`:e.tab);return n.some(kr)&&r.add(Mr),[...r].map(e=>e===`export`?{id:e,label:Ar,isAddonContrib:!0}:{id:e,label:Bn[e]?.label??e,isAddonContrib:!0})},[I]),R=P,z=String(R?.name??n.deviceId??`Device`),ae=R?.online===!0,oe=ae?`online`:`offline`,B=String(R?.addonId??`rtsp`),V=R?.features??[],H=R?.type,se=H===Y.Camera,{data:ce}=$n(l?a:0),ue=H===Y.Container,de=i(()=>(ce??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[ce]),U=i(()=>ue?me(de,typeof R?.linkDeviceId==`number`?R.linkDeviceId:null,typeof R?.primaryChildEntityId==`string`?R.primaryChildEntityId:null)?.id??null:null,[ue,de,R?.linkDeviceId,R?.primaryChildEntityId]),{data:fe}=At({deviceId:U??0},{enabled:U!==null}),pe=i(()=>{if(U===null)return[];let e=fe?.settings?.sections??[],t=fe?.live?.sections??[],n=new Set;for(let r of[...e,...t])r.location===`top-tab`&&r.tab&&n.add(r.tab);return[...n].map(e=>({id:e,label:Bn[e]?.label??e,isAddonContrib:!0,childDeviceId:U}))},[U,fe]),he=typeof R?.parentDeviceId==`number`?R.parentDeviceId:null,{data:ge}=q({deviceId:he??0},{enabled:he!==null}),W=ne(),_e=R?.disabled!==!0,ve=i(()=>{let e=new Set,t=[];for(let n of[...Yo(H,v),...L,...pe])e.has(n.id)||(e.add(n.id),t.push(n));return t},[H,v,L,pe]),ye=i(()=>Za(ve,x),[ve,x]),be=e(e=>{b(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[b]),Se=e(e=>{b(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[b]),Te=(ce??[]).length>0,Ee=i(()=>Zo.filter(({featureGate:e})=>!e||V.includes(e)),[V]),{data:Oe}=Tt(void 0),ke=i(()=>R?Ce(R,Oe):null,[R,Oe]),G=ke?.kind===`resolved`?ke.integration:null,Ae=G===null?ke?.kind===`unknown`?`Loading integration…`:ke?.kind===`orphan`?`Missing integration`:`No integration`:G.name,je=G!==null&&G.addonId===B?G.name:B,Me=we({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]}),d(G?.id?`/integrations/${G.id}`:`/integrations`)}}),Ne=Bt({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Pe=Pt({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=fn(),Ie=rt({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=V.includes(An.Rebootable),Re=V.includes(An.BatteryOperated),ze=De(h.trpcClient,Re&&l?a:null),Be=xe(h.trpcClient,l?a:null),[Ve,He]=c(!1),Ue=async()=>{if(!Ve){He(!0);try{let e=z.replace(/[^a-zA-Z0-9_.-]+/g,`_`),t=new Date().toISOString().replace(/[:.]/g,`-`);await Er(`${p}/${String(a)}.jpg?force=1`,`${e}-${t}.jpg`)}finally{He(!1)}}},We=Ne.isPending||Pe.isPending,{data:Ge}=ie({deviceId:a},{enabled:l,refetchInterval:1e4}),Ke=Ge?.agentNodeId??null,qe=typeof Ke==`string`&&Ke.length>0&&!Ke.startsWith(`addon:`)?Ke:void 0,{data:Je}=Gt({deviceId:a,...qe?{nodeId:qe}:{}},{enabled:l,refetchInterval:3e3,retry:!1}),{data:Ye}=yt({deviceId:a},{enabled:l,refetchInterval:3e3,retry:!1}),Xe=Ye?.level?.dbfs??null;function Ze(){if(!l)return null;switch(ye){case`overview`:return u(Ko,{device:R??{}});case`config`:return u(no,{deviceId:a,activeSubTab:S,onSubTabChange:Se,deviceType:H,isAdmin:v});case`detection-pipeline`:return u(ho,{deviceId:a,activeSubTab:S,onSubTabChange:Se});case`bindings`:return u(Qa,{deviceId:a});case Xn:return u(Ua,{deviceId:a,activeSubTab:S,onSubTabChange:Se});default:{let e=ye,t=L.some(t=>t.id===e),n=pe.find(t=>t.id===e);if(!t&&n===void 0)return null;let r=n?.childDeviceId??a;if(e===`export`)return u(Nr,{deviceId:a,sectionFilter:kr,activeSubTab:S,onSubTabChange:Se});let i=u(Nr,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:S,onSubTabChange:Se});return n!==void 0&&r!==a?u(Ht,{deviceId:r,children:i}):i}}}return l?F?r(`div`,{className:`flex flex-col h-full`,children:[r(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[u(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),u(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),u(`div`,{className:`flex-1 p-6`,children:u(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):te||!P?r(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[u(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),r(`p`,{className:`text-xs`,children:[`No device with ID`,` `,r(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,a]})]}),u(`button`,{onClick:()=>d(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]}):r(`div`,{className:`absolute inset-0 flex flex-col overflow-clip`,children:[r(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[u(`div`,{className:`mb-2`,children:u(Mt,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},G===null?{label:Ae}:{label:Ae,onClick:()=>d(`/integrations/${G.id}`)},{label:z}]})}),r(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[G!==null&&u(Xo,{provider:G.addonId,integrationId:G.id,name:G.name}),r(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:z}),u(Dr,{status:oe}),Re&&u(lt,{status:ze,variant:`full`}),u(kt,{status:Be})]}),he!==null&&ge&&r(`button`,{type:`button`,onClick:()=>d(`/devices/${he}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${ge.name}`,children:[u(`span`,{children:`↑`}),u(`span`,{className:`truncate`,children:String(ge.name??`Device #${he}`)})]}),u(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:V.length>0&&u(Dn,{capabilities:V})})]}),Je&&u(`div`,{className:`hidden lg:flex`,children:u($o,{metrics:Je,dbfs:Xe})}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[r(`button`,{onClick:async()=>{_e?await m({title:`Disable "${z}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Pe.mutate({deviceId:a}):Ne.mutate({deviceId:a})},disabled:We,title:_e?`Disable device`:`Enable device`,className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border transition-colors disabled:opacity-50 ${_e?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[u(ee,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:We?`Updating…`:_e?`Enabled`:`Disabled`})]}),u(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),se&&r(o,{children:[u(Ur,{deviceId:a}),u(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),u(Gr,{deviceId:a}),u(on,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:E,disabled:Ve,onClick:()=>{Ue()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:re,hidden:!Le,disabled:Fe.isPending,danger:!0,onClick:async()=>{await m({title:`Reboot "${z}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Fe.mutate({deviceId:a})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${je}.`,icon:le,disabled:Ie.isPending,danger:!0,onClick:async()=>{await m({title:`Restart "${je}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${z}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&Ie.mutate({addonId:B})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:C,separatorBefore:!0,disabled:Me.isPending,danger:!0,onClick:async()=>{await m({title:`Delete "${z}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Me.mutate({deviceId:a})}}]})]})]})]}),u(Ht,{deviceId:a,device:R??void 0,children:u(Xt,{children:u(A,{children:u(w,{children:u(zt,{children:r(`main`,{className:W?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[r(`div`,{className:W?`flex flex-col bg-surface`:`${k===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!W&&k!==null?{width:`${String(k)}px`}:void 0,children:[u(`div`,{className:se?`flex-shrink-0 border-b border-border-subtle bg-black`:W?`flex-shrink-0 border-b border-border-subtle bg-surface`:`max-h-[55%] shrink-0 overflow-y-auto border-b border-border-subtle bg-surface`,children:se?u(Ti,{deviceId:a,intercomAvailable:V.includes(An.TwoWayAudio)}):u(hi,{deviceId:a,deviceName:z,deviceType:H??`unknown`,provider:B,isOnline:ae,features:V})}),r(`div`,{className:W?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[u(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:u(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:Ee.map(({id:e,label:t,icon:n})=>r(`button`,{onClick:()=>D(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${T===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[u(n,{className:`h-3 w-3`}),t]},e))})}),r(`div`,{className:W?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[T===`logs`&&u(Ei,{deviceId:a,containerDeviceId:H===`container`?a:void 0}),T===`repl`&&u(Di,{deviceId:a}),T===`events`&&u(Oi,{deviceId:a}),T===`state`&&u(ki,{deviceId:a})]})]})]}),!W&&u(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:N,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:u(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),r(`div`,{className:W?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[u(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:u(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:ve.map(e=>{let t=ye===e.id;return r(`button`,{onClick:()=>be(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&u(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),r(`div`,{className:W?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[ye===`overview`&&Te&&u(Kr,{parentDeviceId:a}),Ze()]})]})]})})})})})})]}):r(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[u(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),r(`p`,{className:`text-xs`,children:[`The URL segment`,` `,u(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:n.deviceId}),` `,`is not a number.`]}),u(`button`,{onClick:()=>d(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]})}function $o({metrics:e,dbfs:t}){let n=$t(e.phase??`idle`);return r(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[r(`div`,{className:`flex items-center gap-1.5`,children:[u(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),u(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),u(`div`,{className:`h-3 w-px bg-border`}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[u(gt,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),u(`span`,{children:`fps`})]}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[u(L,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),u(`span`,{children:`ms`})]}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[u(Ae,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),u(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&r(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{Qo as DeviceDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,U as i,W as a,a as o,b as s,o 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-DhP-Lgiq.js";import{X as f,Z as p,_t as m,at as h,ct as g,ft as _,gt as v,st as y,yt as b}from"./player-overlays-o54P23P2.js";import{$a as x,Ao as S,Bt as C,Cn as w,Cu as T,Du as E,Gc as ee,Gn as D,Hc as O,Ic as k,Il as A,Iu as j,Lc as M,Nt as N,Ou as P,Po as F,Qa as I,R as L,Sn as R,Ut as z,Uu as B,Vu as te,Wo as V,Xa as ne,_o as H,an as U,ao as re,bn as ie,cd as W,cn as G,dl as ae,do as oe,fo as se,ft as ce,go as le,gu as ue,hl as de,ho as fe,il as pe,io as me,jt as he,ju as ge,kl as _e,lo as ve,ml as ye,nn as be,no as xe,nu as K,oo as Se,po as Ce,qt as we,ro as Te,sn as Ee,so as De,tn as q,to as Oe,tu as ke,uo as Ae,vi as je,vn as Me,vo as Ne,yn as Pe,yo as Fe,za as Ie}from"./src-f3OJiuN1.js";import{t as Le}from"./square-check-big-CC2dU6RF.js";import{Zt as Re,ar as ze}from"./src-C36-vO5A.js";import{l as Be}from"./index-CgXPc-AV.js";import{t as Ve}from"./AdminPage-CiKtOLQm.js";import{a as He,i as Ue,r as We,t as Ge}from"./authed-media-CH1U0Z7I.js";import{a as Ke,c as qe,d as Je,f as Ye,i as Xe,n as Ze,o as Qe,p as $e,r as et,s as tt,t as nt}from"./debounced-invalidate-BDeU9yPQ.js";import{t as rt}from"./use-stationary-objects-CO4PdIFG.js";import{t as it}from"./AdminTabs-_3rYGvff.js";import{t as at}from"./format-size-DIxKXxtj.js";var ot=b(`arrow-down-wide-narrow`,[[`path`,{d:`m3 16 4 4 4-4`,key:`1co6wj`}],[`path`,{d:`M7 20V4`,key:`1yoxec`}],[`path`,{d:`M11 4h10`,key:`1w87gc`}],[`path`,{d:`M11 8h7`,key:`djye34`}],[`path`,{d:`M11 12h4`,key:`q8tih4`}]]),st=b(`circle-dashed`,[[`path`,{d:`M10.1 2.182a10 10 0 0 1 3.8 0`,key:`5ilxe3`}],[`path`,{d:`M13.9 21.818a10 10 0 0 1-3.8 0`,key:`11zvb9`}],[`path`,{d:`M17.609 3.721a10 10 0 0 1 2.69 2.7`,key:`1iw5b2`}],[`path`,{d:`M2.182 13.9a10 10 0 0 1 0-3.8`,key:`c0bmvh`}],[`path`,{d:`M20.279 17.609a10 10 0 0 1-2.7 2.69`,key:`1ruxm7`}],[`path`,{d:`M21.818 10.1a10 10 0 0 1 0 3.8`,key:`qkgqxc`}],[`path`,{d:`M3.721 6.391a10 10 0 0 1 2.7-2.69`,key:`1mcia2`}],[`path`,{d:`M6.391 20.279a10 10 0 0 1-2.69-2.7`,key:`1fvljs`}]]),ct=b(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),lt=b(`graduation-cap`,[[`path`,{d:`M21.42 10.922a1 1 0 0 0-.019-1.838L12.83 5.18a2 2 0 0 0-1.66 0L2.6 9.08a1 1 0 0 0 0 1.832l8.57 3.908a2 2 0 0 0 1.66 0z`,key:`j76jl0`}],[`path`,{d:`M22 10v6`,key:`1lu8f3`}],[`path`,{d:`M6 12.5V16a6 3 0 0 0 12 0v-3.5`,key:`1r8lef`}]]),ut=b(`square-parking`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 17V7h4a3 3 0 0 1 0 6H9`,key:`1dfk2c`}]]);n();function dt(e){return e.subLabel??e.label}var ft=720*60*60*1e3;function pt(e){let t=[];for(let n of e)t.push(...n);return t}function mt(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function ht(e,t){return e.filter(e=>!(e.importance<t.minImportance||t.cameras.size>0&&!t.cameras.has(e.deviceId)||t.classes.size>0&&!t.classes.has(e.className)))}function gt(e,t){return`${String(e)}:${t}`}function _t(e,t){let n=new Map,r=new Set;for(let i of e){let e=gt(i.deviceId,i.trackId);if(!t.has(e)||r.has(e))continue;r.add(e);let a=n.get(i.deviceId);a?a.push(i.trackId):n.set(i.deviceId,[i.trackId])}return n}function vt(e,t){return{since:e.fromMs??t-ft,until:e.toMs??t}}var yt=[`native`,`raster`,`standin`];function bt(e){return yt.some(t=>t===e)}var xt={standin:{label:`stand-in`,title:`Stand-in: this tile is a face or plate detail crop copied in because no frame of the subject was captured. It is not a best shot.`,tone:`warning`},raster:{label:`low-res`,title:`Raster crop: a sub-native cut of the subject, not a native capture. Honest, but lower resolution than a best shot.`,tone:`info`}};function St(e){return e===`standin`?xt.standin:e===`raster`?xt.raster:null}var Ct={"no-key-frame":`No key frame existed at close, so no native tile could be cut.`,"no-best-seen-bbox":`No subject box was ever recorded, so there was nothing to cut around.`,"derive-returned-null":`The close-time crop was attempted and produced nothing.`,"derive-threw":`The close-time crop failed with an error.`,"derive-not-wired":`No close-time crop was wired on this node.`,"no-media-store":`The node was shutting down mid-close.`,"no-thumbnail":`The track closed with no tile of any kind.`,"standin-tile":`The track closed with a detail crop standing in for the subject.`,"raster-tile":`The track closed with a sub-native raster crop of the subject.`,"native-tile":`The track closed with a native tile.`};function wt(e){if(e===void 0)return null;let t=e.trim();if(t.length===0)return null;let n=t.split(/\s+/),r=n[0]??t,i=[];for(let e of n.slice(1)){let t=e.indexOf(`=`);t===-1?i.push({key:e,value:null}):i.push({key:e.slice(0,t),value:e.slice(t+1)})}return{sentence:Ct[r]??r,detail:i,raw:t}}function Tt(e){if(e===void 0||!Number.isFinite(e)||e<=0)return``;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`${String(n)}m ${String(r).padStart(2,`0`)}s`}function Et({row:e,cameraName:t,nowMs:n,onOpenDetail:i,selected:a=!1,onToggleSelect:o,score:s,provenance:c,footer:l}){let d=He(e.mediaId===void 0?Ue(`track`,e.trackId):We(e.mediaId)),f=Math.round(e.importance*100),p=s===void 0?void 0:Math.round(s*100),m=Tt(e.windowMs),h=()=>i(e),v=St(c);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${a?`border-primary ring-1 ring-primary`:`border-border`}`,children:[r(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[d.src?u(`img`,{src:d.src,alt:`Event from ${t}`,onClick:h,className:`h-full w-full cursor-zoom-in object-cover`}):u(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:d.failed?`Key-event media unavailable`:`No key-event media`,children:u(_,{className:`h-6 w-6 opacity-60`})}),o&&u(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(gt(e.deviceId,e.trackId))},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":a?`Deselect`:`Select`,children:a?u(Le,{className:`h-4 w-4 text-primary`}):u(g,{className:`h-4 w-4`})}),p!==void 0&&r(`span`,{className:`absolute left-1 top-1 z-10 rounded bg-primary/85 px-1.5 py-0.5 text-[10px] font-semibold text-white tabular-nums`,title:`CLIP semantic-match score`,children:[String(p),`%`]}),f>0&&u(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(f)}),v!==null&&u(`span`,{className:`absolute bottom-1 right-1 z-10 rounded px-1.5 py-0.5 text-[10px] font-semibold text-white ${v.tone===`warning`?`bg-warning/90`:`bg-black/70`}`,title:v.title,children:v.label}),(e.markForTrain===!0||e.debug===!0||e.favourited===!0)&&r(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[e.markForTrain===!0&&u(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Marked for training`,"aria-label":`Marked for training`,children:u(lt,{className:`h-3 w-3`})}),e.debug===!0&&u(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:`Flagged for debug`,"aria-label":`Flagged for debug`,children:u(B,{className:`h-3 w-3`})}),e.favourited===!0&&u(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Favourited`,"aria-label":`Favourited`,children:u(ye,{className:`h-3 w-3`})})]})]}),r(`button`,{type:`button`,onClick:h,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[r(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,dt(e)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,dt(e)]}):null]}),u(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),r(`div`,{className:`flex items-center justify-between gap-2`,children:[u(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:Ye(e.timestamp,n)}),m&&u(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:m})]})]}),l!==void 0&&u(`div`,{className:`px-2 pb-1.5`,children:l})]})}var Dt=1400,Ot=`Admin-gated URL — opens only inside an authenticated session`;function kt({label:t,value:n,title:i}){let[a,o]=l(!1),s=ie();return d(()=>{if(!a)return;let e=setTimeout(()=>o(!1),Dt);return()=>clearTimeout(e)},[a]),r(`button`,{type:`button`,onClick:e(()=>{(async()=>{try{await navigator.clipboard.writeText(n),o(!0)}catch{await s({title:`Copy the media URL`,message:`Clipboard access was refused. Select the URL below and copy it manually.`,label:`${t} URL`,defaultValue:n,readOnly:!0,cancelLabel:`Close`})}})()},[n,t,s]),title:i,"aria-label":`Copy ${t} URL`,className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${a?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[u(a?te:E,{className:`h-2.5 w-2.5 shrink-0`}),u(`span`,{className:`truncate`,children:a?`Copied`:t})]})}function At({localUrl:e,publicUrl:t}){return r(`div`,{className:`flex flex-wrap gap-1`,children:[u(kt,{label:`Local`,value:e,title:`Copy LAN URL — ${Ot}`}),t&&u(kt,{label:`Public`,value:t,title:`Copy public URL — ${Ot}`})]})}var jt={firstFrame:`First frame (track start)`,lastFrame:`Last frame (track end)`,thumbnail:`Best detection`,thumbnailSmall:`Best detection (480)`,snapshot:`Snapshot`,keyFrame:`Key frame (native-res)`,keyFrameSmall:`Key frame (960)`,crop:`Object crop`,fullFrame:`Full frame`,fullFrameBoxed:`Full frame (boxed)`,faceCrop:`Face crop`,plateCrop:`Plate crop`,confirmationCrop:`Confirmation crop (what the gate saw)`,debugCrop:`Debug crop (why this decision)`,sceneFrame:`Scene frame (clean)`,lastSceneFrame:`Last frame (clean)`};function Mt(e){return e in jt}function Nt(e){return Mt(e)?jt[e]:e}function Pt(e,t){return`${e}${t}`}n();var Ft=3e4;function It(t){let[n,r]=l(null),i=e(e=>{r(t=>t??e)},[]);return d(()=>{t||r(null)},[t]),{publicOrigin:n,probes:t?u(Lt,{onOrigin:i}):null}}function Lt({onOrigin:e}){let{data:t}=D({capName:`network-access`});return u(s,{children:(t??[]).map(t=>u(Rt,{addonId:t.addonId,onOrigin:e},t.addonId))})}function Rt({addonId:e,onOrigin:t}){let{data:n}=Ie({addonId:e},{refetchInterval:Ft,retry:!1});return d(()=>{let e=n?Re.safeParse(n):null,r=e?.success?e.data.endpoint?.url:void 0;if(r)try{t(new URL(r).origin)}catch{}},[n,t]),null}var zt=typeof Ne==`function`,Bt=`Track flags arrive with the next server update`;function Vt(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var Ht=zt?Ne:Vt;function Ut(e){if(typeof e!=`object`||!e||!(`trackId`in e)||!(`markForTrain`in e)||!(`debug`in e)||!(`favourited`in e))return null;let{trackId:t,markForTrain:n,debug:r,favourited:i}=e;return typeof t!=`string`||typeof n!=`boolean`||typeof r!=`boolean`||typeof i!=`boolean`?null:{trackId:t,markForTrain:n,debug:r,favourited:i}}n();function Wt({label:e,hint:t,checked:n,disabled:i,title:a,icon:o,onToggle:s}){return r(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":e,disabled:i,title:a,onClick:s,className:`flex w-full items-center gap-2 rounded-md border px-2 py-1.5 text-left transition-colors disabled:opacity-50 ${n?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[u(`span`,{className:n?`text-primary`:`text-foreground-subtle`,children:o}),r(`span`,{className:`min-w-0 flex-1`,children:[u(`span`,{className:`block text-[11px] font-medium text-foreground`,children:e}),u(`span`,{className:`block text-[10px] text-foreground-subtle`,children:t})]}),u(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${n?`bg-primary`:`bg-border`}`,children:u(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${n?`translate-x-3`:``}`})})]})}function Gt({deviceId:e,trackId:t,markForTrain:n,debug:i,favourited:a,onChange:o}){let s=Ht(),c=Me(),[d,f]=l(null),p=d?.markForTrain??n===!0,m=d?.debug??i===!0,h=d?.favourited??a===!0,g=!zt||s.isPending,_=zt?void 0:Bt,v=n=>{g||(async()=>{try{let r=Ut(await s.mutateAsync({deviceId:e,trackId:t,flags:n}));if(!r)return;f(r),o?.(r)}catch(e){let t=e instanceof Error?e.message:``;await c({title:`Could not update this track`,message:t===``?`Could not update this track. Check the server logs.`:t,variant:`danger`})}})()};return r(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[u(Wt,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:p,disabled:g,..._===void 0?{}:{title:_},icon:u(lt,{className:`h-4 w-4`}),onToggle:()=>v({markForTrain:!p})}),u(Wt,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:m,disabled:g,..._===void 0?{}:{title:_},icon:u(B,{className:`h-4 w-4`}),onToggle:()=>v({debug:!m})}),u(Wt,{label:`Favourited`,hint:`Keeps this track and its media past retention`,checked:h,disabled:g,..._===void 0?{}:{title:_},icon:u(ye,{className:`h-4 w-4`}),onToggle:()=>v({favourited:!h})})]})}var J=100,Kt=120,qt={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Y=e=>e<0?0:e>1?1:e,Jt=e=>Math.round(e*100)/100;function Yt(e,t){if(e.length<=t)return[...e];let n=(e.length-1)/(t-1),r=[];for(let i=0;i<t;i++)r.push(e[Math.round(i*n)]);return r[r.length-1]=e[e.length-1],r}function Xt(e,t,n){if(e.length===0||t===null)return qt;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return qt;let a=Yt(e,n?.maxPoints??Kt).map(e=>({x:Jt(Y(e.x/r)*J),y:Jt(Y(e.y/i)*J)})),o=a[0]??null,s=a[a.length-1]??null,c=a.length>=2?a.map(e=>`${e.x},${e.y}`).join(` `):``,l=(n?.snapshots??[]).map(e=>({x:Jt(Y(e.x/r)*J),y:Jt(Y(e.y/i)*J),mediaId:e.mediaId})),u=null,d=-1;for(let t of e){let e=Y(t.bbox.w/r)*Y(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Jt(Y(u.bbox.x/r)*J),y:Jt(Y(u.bbox.y/i)*J),w:Jt(Y(u.bbox.w/r)*J),h:Jt(Y(u.bbox.h/i)*J)}:null}}var Zt=typeof I==`function`,Qt=`Track deletion arrives with the next server update`;function $t(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var en=Zt?I:$t;n();var tn=15e3,nn=f();function rn({url:e,label:t}){let{src:n,failed:r}=He(e);return n===null?u(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?u(_,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):u(K,{className:`h-4 w-4 animate-spin text-foreground-subtle opacity-70`})}):u(`img`,{src:n,alt:t,className:`h-full w-full object-cover`})}var an=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),on=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`,`sceneFrame`,`lastSceneFrame`]);function sn(e){let[t,n]=l(null);return d(()=>{if(n(null),!e)return;let t=!1,r=new Image;return r.onload=()=>{t||n({width:r.naturalWidth,height:r.naturalHeight})},r.src=e,()=>{t=!0,r.onload=null}},[e]),t}function cn({overlay:e,onPickSnapshot:t}){return!e.polyline&&!e.peakBox&&e.snapshots.length===0?null:r(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[e.peakBox&&u(`rect`,{x:e.peakBox.x,y:e.peakBox.y,width:e.peakBox.w,height:e.peakBox.h,fill:`none`,stroke:`#f59e0b`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),e.polyline&&u(`polyline`,{points:e.polyline,fill:`none`,stroke:`#38bdf8`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),e.points.map((e,t)=>u(`circle`,{cx:e.x,cy:e.y,r:1,fill:`#38bdf8`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),e.snapshots.map((e,n)=>u(`circle`,{cx:e.x,cy:e.y,r:1.9,fill:`#0ea5e9`,fillOpacity:.95,stroke:`#082f49`,strokeWidth:.7,vectorEffect:`non-scaling-stroke`,className:t?`pointer-events-auto cursor-pointer`:void 0,onClick:t?n=>{n.stopPropagation(),t(e.mediaId)}:void 0,children:u(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${String(e.mediaId)}-${String(n)}`)),e.start&&u(`circle`,{cx:e.start.x,cy:e.start.y,r:2.4,fill:`#22c55e`,stroke:`#052e16`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),e.end&&u(`circle`,{cx:e.end.x,cy:e.end.y,r:2.4,fill:`#ef4444`,stroke:`#450a0a`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function X({label:e,value:t,mono:n}){return r(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[u(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),u(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function ln({row:t,cameraName:n,deleteAvailable:i,onClose:o,onDeleted:c,onFlagsChanged:f}){let p=h(),m=Me(),g=Pe(),v=en(),b=t!==null,x=t?.deviceId??0,S=t?.trackId??``,C=t?.timestamp??0,w=t?.windowMs??0,{data:T}=Te({deviceId:x,trackId:S},{enabled:b}),{data:E}=se({trackId:S,deviceId:x},{enabled:b}),D=T?.bestEventId===void 0?void 0:Number(T.bestEventId),{data:O}=De({ownerType:`object`,eventId:D??0,deviceId:x},{enabled:b&&D!==void 0&&Number.isFinite(D)}),{data:A}=M({deviceId:x},{enabled:b}),j=(A??[]).find(e=>e.addonId!==void 0)?.addonId,{data:P}=k({deviceId:x,since:C-tn,until:C+w+tn,provider:j??``},{enabled:b&&j!==void 0}),[F,I]=l(null),[L,R]=l(!1),{publicOrigin:z,probes:B}=It(b);d(()=>{I(null)},[x,S]);let te=a(()=>{let e=E??[],t=O??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[E,O]),V=F??te,ne=He(V?V.url:void 0),H=a(()=>{let e=new Set,t=[];for(let n of[...O??[],...E??[]])e.has(n.mediaId)||(e.add(n.mediaId),t.push(n));return t},[O,E]),U=a(()=>H.find(e=>an.has(e.kind))??null,[H]),re=sn(He(U?U.url:void 0).src),ie=a(()=>Xt(T?.positions??[],re,{snapshots:(T?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaId:e.mediaId}))}),[T?.positions,T?.snapshots,re]),W=e(e=>{let t=H.find(t=>t.mediaId===e);t&&I(t)},[H]);if(t===null)return null;let ae=ne.src,oe=V?.kind,ce=oe!==void 0&&on.has(oe)&&re!==null&&(T?.positions.length??0)>=2,le=P&&P.length>0?P[0]:null,de=()=>{le&&(R(!0),(async()=>{try{let e=await p.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:le.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{m({title:`Clip unavailable`,message:`Could not resolve clip playback. Check the server logs.`,variant:`warning`})}finally{R(!1)}})())},fe=()=>{!i||v.isPending||(async()=>{if(await g({title:`Delete track`,message:`Delete this track and every image and clip captured for it? This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`}))try{await v.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),c()}catch{await m({title:`Delete failed`,message:`Failed to delete this track. Check the server logs.`,variant:`danger`})}})()},pe=Math.round(t.importance*100),me=T?.importanceReason?`${String(pe)}% · ${T.importanceReason}`:`${String(pe)}%`,ge=T?.zonesVisited&&T.zonesVisited.length>0?T.zonesVisited.join(`, `):`—`,_e=T?.audioLabels&&T.audioLabels.length>0?T.audioLabels.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `):`—`,ve=T?T.totalDistance.toFixed(2):`—`,ye=wt(T?.previewMissReason),be=$e(T?T.firstSeen:C),xe=T?$e(T.lastSeen):`—`;return u(he,{open:!0,onOpenChange:e=>!e&&o(),children:r(N,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Event detail`,className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[r(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[t.className,dt(t)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,dt(t)]}):null]}),u(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:n})]}),u(`button`,{type:`button`,onClick:o,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:u(ee,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[ae?u(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:u(Ze,{src:ae,alt:`Key frame from ${n}`,fit:`natural`,className:`w-full`,overlay:ce?u(cn,{overlay:ie,onPickSnapshot:W}):void 0})}):u(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:ne.failed?r(s,{children:[u(_,{className:`h-8 w-8 opacity-60`}),u(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):u(K,{className:`h-6 w-6 animate-spin opacity-70`})}),H.length>0&&u(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:H.map(e=>{let t=Nt(e.kind),n=Pt(nn,e.url),i=z?Pt(z,e.url):null;return r(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[u(`button`,{type:`button`,onClick:()=>I(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${t} · ${$e(e.timestamp)}`,children:u(rn,{url:e.url,label:t})}),r(`figcaption`,{className:`min-w-0 px-0.5`,children:[u(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:t,children:t}),u(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:$e(e.timestamp),children:Je(e.timestamp)})]}),u(At,{localUrl:n,publicUrl:i})]},e.mediaId)})}),B,le&&r(G,{variant:`secondary`,onClick:de,disabled:L,children:[L?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(ue,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),u(Gt,{deviceId:t.deviceId,trackId:t.trackId,...(T?.markForTrain??t.markForTrain)===void 0?{}:{markForTrain:T?.markForTrain??t.markForTrain},...(T?.debug??t.debug)===void 0?{}:{debug:T?.debug??t.debug},...(T?.favourited??t.favourited)===void 0?{}:{favourited:T?.favourited??t.favourited},onChange:f}),ye!==null&&r(`div`,{className:`rounded-lg border border-warning/40 bg-warning/8 px-3 py-2`,children:[u(`p`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Best shot`}),u(`p`,{className:`mt-0.5 text-xs text-foreground`,children:ye.sentence}),u(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:ye.raw})]}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[u(X,{label:`Camera`,value:n}),u(X,{label:`Class`,value:t.className}),u(X,{label:`Label`,value:t.label??`—`}),u(X,{label:`Sub-label`,value:t.subLabel??`—`}),u(X,{label:`Importance`,value:me}),u(X,{label:`Zones visited`,value:ge}),u(X,{label:`Audio heard`,value:_e}),u(X,{label:`Total distance`,value:ve}),u(X,{label:`First seen`,value:be}),u(X,{label:`Last seen`,value:xe}),u(X,{label:`Track`,value:t.trackId,mono:!0})]})]}),u(`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:u(`span`,{title:i?void 0:Qt,children:r(G,{variant:`secondary`,onClick:fe,disabled:!i||v.isPending,children:[v.isPending?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(y,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}var un={status:`debug.tape.status`,promote:`debug.tape.promote`,list:`debug.tape.list`,tracks:`debug.tape.tracks`,review:`debug.tape.review`,release:`debug.tape.release`,remove:`debug.tape.delete`},dn={setRelation:`debug.gt.setRelation`,setPurity:`debug.gt.setPurity`,list:`debug.gt.list`},fn=p(`/addon/pipeline-analytics/tape-export`),pn=10*6e4;function mn(e){return`${fn}?tapeId=${encodeURIComponent(e)}`}var hn=`The server answered in a shape this build does not understand.`;function gn(e){return e instanceof Error?e.message:`The action failed.`}function Z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function _n(e,t){if(!(t in e))return;let n=e[t];return n===null?null:typeof n==`number`&&Number.isFinite(n)?n:void 0}function $(e,t){let n=e[t];return typeof n==`string`?n:null}function vn(e,t){let n=e[t];return typeof n==`boolean`?n:null}function yn(e,t){if(!Array.isArray(e))return null;let n=[];for(let r of e){let e=t(r);if(e===null)return null;n.push(e)}return n}function bn(e){return e===`off`||e===`recording`||e===`refused`||e===`failing`||e===`unknown`}function xn(e){if(!Z(e))return null;let t=Q(e,`deviceId`),n=e.state,r=Q(e,`gapsSinceArmed`),i=_n(e,`segmentsHeld`),a=_n(e,`bytesLastHour`),o=_n(e,`bytesHeld`);if(t===null||!bn(n)||r===null||i===void 0||a===void 0||o===void 0)return null;let s=$(e,`reason`),c=Q(e,`segmentOriginMs`),l=Q(e,`framesPerMin`),u=Q(e,`heldFromMs`),d=Q(e,`heldToMs`),f=$(e,`shelfError`);return{deviceId:t,state:n,gapsSinceArmed:r,segmentsHeld:i,bytesLastHour:a,bytesHeld:o,...s===null?{}:{reason:s},...c===null?{}:{segmentOriginMs:c},...l===null?{}:{framesPerMin:l},...u===null?{}:{heldFromMs:u},...d===null?{}:{heldToMs:d},...f===null?{}:{shelfError:f}}}function Sn(e){return Z(e)?yn(e.cameras,xn):null}function Cn(e){if(!Z(e))return null;let t=$(e,`id`),n=Q(e,`deviceId`),r=$(e,`scenario`),i=e.lighting,a=Q(e,`fromMs`),o=Q(e,`toMs`),s=e.state,c=Q(e,`frames`),l=Q(e,`gaps`),u=Q(e,`bytes`),d=vn(e,`reviewed`),f=vn(e,`released`),p=yn(e.tracks,e=>typeof e==`string`?e:null),m=Q(e,`tracksStillStored`);return t===null||n===null||r===null||i!==`day`&&i!==`ir`||a===null||o===null||s!==`complete`&&s!==`incomplete`||c===null||l===null||u===null||d===null||f===null||p===null||m===null?null:{id:t,deviceId:n,scenario:r,note:$(e,`note`),lighting:i,fromMs:a,toMs:o,state:s,frames:c,gaps:l,bytes:u,reviewed:d,released:f,tracks:p,tracksStillStored:m}}function wn(e){return Z(e)?yn(e.tapes,Cn):null}function Tn(e){if(!Z(e))return null;let t=$(e,`trackId`),n=Q(e,`firstT`),r=Q(e,`lastT`),i=Q(e,`boundFrames`),a=$(e,`cls`),o=vn(e,`stillStored`);return t===null||n===null||r===null||i===null||a===null||o===null?null:{trackId:t,firstT:n,lastT:r,boundFrames:i,cls:a,stillStored:o}}function En(e){if(!Z(e))return null;let t=$(e,`tapeId`),n=Q(e,`deviceId`),r=Q(e,`fromMs`),i=Q(e,`toMs`),a=vn(e,`reviewed`),o=yn(e.lanes,Tn);return t===null||n===null||r===null||i===null||a===null||o===null?null:{tapeId:t,deviceId:n,fromMs:r,toMs:i,reviewed:a,lanes:o}}function Dn(e){if(!Z(e))return null;if(e.ok===!1){let t=$(e,`reason`),n=$(e,`detail`);return t===null||n===null?null:{ok:!1,reason:t,detail:n}}if(e.ok!==!0)return null;let t=$(e,`tapeId`),n=e.state,r=Q(e,`frames`),i=Q(e,`gaps`),a=Q(e,`pinnedTracks`),o=Q(e,`bytes`);return t===null||n!==`complete`&&n!==`incomplete`||r===null||i===null||a===null||o===null?null:{ok:!0,tapeId:t,state:n,frames:r,gaps:i,pinnedTracks:a,bytes:o}}function On(e){if(!Z(e))return null;let t=e.status;if(t===`released`){let n=Q(e,`unpinned`),r=vn(e,`pinsSettled`);return n===null||r===null?null:{status:t,unpinned:n,pinsSettled:r}}if(t===`already-released`||t===`not-found`)return{status:t};if(t===`unavailable`){let n=$(e,`reason`);return n===null?null:{status:t,reason:n}}return null}function kn(e){if(!Z(e))return null;let t=e.status;if(t===`deleted`||t===`pins-owed`||t===`not-found`)return{status:t};if(t===`unavailable`){let n=$(e,`reason`);return n===null?null:{status:t,reason:n}}return null}function An(e){switch(e.status){case`released`:case`deleted`:return null;case`already-released`:return`This tape was already released.`;case`not-found`:return`That tape no longer exists — it may have been released or deleted elsewhere.`;case`pins-owed`:return`Refused: this tape still names pins not yet taken back. Try again shortly — the ledger settles them automatically.`;case`unavailable`:return`Unavailable on this node: ${e.reason}`}}function jn(e){if(!Z(e))return null;let t=$(e,`leftTrackId`),n=$(e,`rightTrackId`),r=e.relation,i=e.presence;return t===null||n===null||r!==`same-subject`&&r!==`different-subjects`?null:{leftTrackId:t,rightTrackId:n,relation:r,presence:i===`continuous`?`continuous`:null}}function Mn(e){if(!Z(e))return null;let t=$(e,`sourceTrackId`),n=e.purity;return t===null||n!==`mixed`&&n!==`not-a-subject`?null:{sourceTrackId:t,purity:n,switchAtMs:Q(e,`switchAtMs`)}}function Nn(e){if(!Z(e))return null;let t=yn(e.relations,jn),n=yn(e.purities,Mn),r=vn(e,`truncated`);return t===null||n===null||r===null?null:{relations:t,purities:n,truncated:r}}function Pn(e){if(!e.truncated)return null;let t=e.relations.length+e.purities.length;return`Showing the first ${String(t)} marks — more exist for this window.`}function Fn(e){return e.filter(e=>e.segmentsHeld===null||e.segmentsHeld>0).map(e=>({deviceId:e.deviceId,segmentsUnknown:e.segmentsHeld===null}))}function In(e){return e.slice(1).map((t,n)=>({trackId:e[n]??t,otherTrackId:t}))}function Ln(e){return e.flatMap((t,n)=>e.slice(n+1).map(e=>({trackId:t,otherTrackId:e})))}function Rn(e,t){let n=[];for(let r of t.relations){let t=r.leftTrackId===e?r.rightTrackId:r.rightTrackId===e?r.leftTrackId:null;if(t===null)continue;let i=r.relation===`same-subject`?`same as`:`different from`;n.push(`${i} ${t}${r.presence===`continuous`?` (continuous)`:``}`)}for(let r of t.purities)r.sourceTrackId===e&&n.push(r.purity===`not-a-subject`?`not a subject`:r.switchAtMs===null?`mixed`:`mixed at switch`);return n}function zn(e){switch(e.state){case`off`:return`Off`;case`recording`:return`Recording`;case`refused`:return`Refused: ${e.reason??`unknown reason`}`;case`failing`:return`Failing: ${e.reason??`unknown reason`}`;case`unknown`:return`Unknown: ${e.reason??`unknown reason`}`}}var Bn={"window-too-long":`A promoted window is at most 30 minutes.`,"window-in-future":`The window ends in the future.`,"window-not-recorded":`No segment covers that window — the camera was not recording then, or it is older than 24 h.`,"invalid-scenario":`The scenario must be a slug: lowercase letters, digits and dashes, 3–64 characters.`,"promotion-budget":`A promotion budget is full (60 tapes, 1 GiB, 3 000 pinned tracks). Release or delete a tape already committed as a case first.`,"empty-window":`No frame was recorded in that window.`,"shelf-unreadable":`The camera's recorded segments could not be listed, so the window cannot be proven whole.`,"not-post-processing-node":`This node does not post-process frames, so it records no tracking tapes.`,"artifacts-elsewhere":`The artifacts storage location is on another node; tapes are recorded only where it lives.`,"tapes-not-started":`The tape recorder has not started on this node (or failed to).`};function Vn(e,t){let n=Bn[e]??`Refused (${e}).`;return t.length>0?`${n} ${t}`:n}function Hn(e){if(e.length===0)return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null}function Un(e){return e<1024*1024?`${(e/1024).toFixed(0)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function Wn(e){return e===null?`unknown`:Un(e)}function Gn(e){return e===null?`unknown`:String(e)}function Kn(e,t){let n=t.trim();return e===404?`This tape no longer exists on this node (unknown tape).`:e===503?n.length>0?n:`Tapes are unavailable on this node.`:e===500?n.length>0?n:`The export could not be read (the tape may have just been released or deleted).`:`Download failed (${String(e)}).`}n();function qn({cameras:e,call:t,onPromoted:n}){let[i,a]=l(``),[o,s]=l(``),[c,d]=l(``),[f,p]=l(``),[m,h]=l(``),[g,_]=l(`auto`),[v,y]=l(!1),[b,x]=l(null),S=async()=>{let r=Number.parseInt(i===``?e[0]?.value??``:i,10),a=Hn(o),s=Hn(c);if(!Number.isFinite(r)||a===null||s===null){x(`Pick a camera and both ends of the window.`);return}y(!0),x(null);try{let e=Dn(await t(un.promote,{deviceId:r,fromMs:a,toMs:s,scenario:f,...m.trim().length>0?{note:m.trim()}:{},...g===`day`||g===`ir`?{lighting:g}:{}}));e===null?x(hn):e.ok?(x(`Promoted ${e.tapeId}: ${String(e.frames)} frames, ${Un(e.bytes)}, ${String(e.pinnedTracks)} tracks pinned`+(e.state===`incomplete`?` — incomplete (it has gaps) and cannot become a case.`:`.`)),n()):x(Vn(e.reason,e.detail))}catch(e){x(gn(e))}finally{y(!1)}};return r(`div`,{className:`flex flex-wrap items-end gap-2 rounded-md border border-border px-3 py-2`,children:[u(`div`,{className:`w-40`,children:u(Ee,{value:i,options:[...e],onChange:e=>a(e.target.value),"aria-label":`Camera`})}),u(C,{type:`datetime-local`,"aria-label":`From`,value:o,onChange:e=>s(e.target.value),className:`w-48`}),u(C,{type:`datetime-local`,"aria-label":`To`,value:c,onChange:e=>d(e.target.value),className:`w-48`}),u(C,{"aria-label":`Scenario`,placeholder:`615-door-groups`,value:f,onChange:e=>p(e.target.value),className:`w-44`}),u(C,{"aria-label":`Note`,placeholder:`optional note`,value:m,onChange:e=>h(e.target.value),className:`w-52`}),u(`div`,{className:`w-28`,children:u(Ee,{value:g,"aria-label":`Lighting`,options:[{value:`auto`,label:`Lighting: auto`},{value:`day`,label:`day`},{value:`ir`,label:`ir`}],onChange:e=>_(e.target.value)})}),r(G,{onClick:()=>void S(),disabled:v||e.length===0,children:[v?u(K,{className:`h-3.5 w-3.5 animate-spin`}):null,` Promote window`]}),u(`p`,{className:`w-full text-xs text-foreground-subtle`,children:`A promoted tape may be shared as a test case — keep the scenario slug and note free of names or other personal data.`}),b!==null&&u(`p`,{className:`w-full text-xs text-foreground`,children:b})]})}var Jn=`pipeline-analytics`,Yn=`debug.listTracks`,Xn=`debug.analyze`,Zn=p(`/addon/pipeline-analytics/debug-export`);function Qn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function $n(e,t){let n=e[t];return typeof n==`string`?n:null}function er(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function tr(e,t){let n=e[t];return typeof n==`boolean`?n:null}function nr(e){return e===`error`||e===`warn`||e===`info`}function rr(e){if(!Qn(e))return null;let t=$n(e,`code`),n=$n(e,`detail`),r=e.severity;return t===null||n===null||!nr(r)?null:{code:t,severity:r,detail:n}}function ir(e){if(!Qn(e))return null;let t=$n(e,`trackId`),n=er(e,`deviceId`),r=$n(e,`className`),i=er(e,`firstSeen`),a=er(e,`lastSeen`),o=er(e,`durationMs`),s=tr(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=$n(e,`label`),l=$n(e,`subLabel`),u=$n(e,`previewMissReason`),d=tr(e,`markForTrain`),f=tr(e,`favourited`);return{trackId:t,deviceId:n,className:r,...c===null?{}:{label:c},...l===null?{}:{subLabel:l},firstSeen:i,lastSeen:a,durationMs:o,active:s,timestamp:i,windowMs:o,importance:er(e,`importance`)??0,bestEventId:$n(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function ar(e){let t=ir(e);if(t===null||!Qn(e))return null;let n=er(e,`mediaCount`),r=er(e,`eventCount`),i=er(e,`positionCount`);if(n===null||r===null||i===null)return null;let a=e.mediaKinds,o=e.findings;if(!Array.isArray(a)||!Array.isArray(o))return null;let s=a.filter(e=>typeof e==`string`),c=[];for(let e of o){let t=rr(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...bt(l)?{thumbnailProvenance:l}:{}}}function or(e){if(!Qn(e))return null;let t=tr(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=ir(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function sr(e){if(!Qn(e))return null;let t=e.reports,n=e.vanished;if(!Array.isArray(t)||!Array.isArray(n))return null;let r=[];for(let e of t){let t=ar(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var cr={MEDIA_EVICTED_OR_NEVER:`no media`,MISSING_KEYFRAME:`no keyframe`,MISSING_FIRSTFRAME:`no first frame`,MISSING_LASTFRAME:`no last frame`,MISSING_THUMBNAIL:`no thumbnail`,MISSING_BEST_CROP:`no crop`,SHORT_TRACK:`very short`,ZERO_EVENTS:`no events`,ZERO_POSITIONS:`no trajectory`,NO_PERIODIC_SNAPSHOTS:`no snapshots`,LASTFRAME_STALE:`stale last frame`,MEDIA_STOPPED_EARLY:`media stopped early`,NO_BEST_EVENT:`no best event`,LOW_BEST_SCORE:`low score`,UNSCORED_LABEL:`unscored label`,BEST_SHOT_STANDIN:`stand-in best shot`,BEST_SHOT_RASTER:`low-res best shot`};function lr(e){return cr[e]??e}var ur={error:0,warn:1,info:2};function dr(e){return e.toSorted((e,t)=>ur[e.severity]-ur[t.severity]||e.code.localeCompare(t.code))}function fr(e){return e.length===0?Zn:`${Zn}?deviceIds=${e.join(`,`)}`}function pr(e){if(e<1e4)return`${(e/1e3).toFixed(1)}s`;let t=Math.round(e/1e3);if(t<60)return`${String(t)}s`;let n=Math.floor(t/60);return`${String(n)}m ${String(t%60).padStart(2,`0`)}s`}function mr(e,t){return`${String(e)}:${t}`}function hr(e,t){let n=[],r=new Set;for(let i of e){let e=mr(i.deviceId,i.trackId);!t.has(e)||r.has(e)||(r.add(e),n.push({deviceId:i.deviceId,trackId:i.trackId}))}return n}n();function gr({tapeId:e,call:t,onClose:n,onChanged:i}){let a=o({queryKey:[`events-debug`,`tapes`,`tracks`,e],queryFn:async()=>En(await t(un.tracks,{tapeId:e}))}),s=a.data??null,c=o({queryKey:[`events-debug`,`tapes`,`marks`,e],enabled:s!==null,queryFn:async()=>s===null?null:Nn(await t(dn.list,{deviceId:s.deviceId,since:s.fromMs-pn,until:s.toMs+pn,limit:5e3}))}),[d,f]=l([]),[p,m]=l(``),[h,g]=l(null),_=e=>f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),v=async e=>{g(null);try{for(let[n,r]of e)await t(n,r);f([]),await c.refetch(),i()}catch(e){g(gn(e))}};if(s===null)return a.isLoading?u(`p`,{className:`text-xs`,children:`Loading the tape…`}):u(U,{message:hn});let y=s.deviceId,b=(e,t)=>v(e.map(e=>[dn.setRelation,{deviceId:y,...e,relation:t}])),x=e=>{let t=Number.parseFloat(p),n=e===`mixed`&&Number.isFinite(t)?s.fromMs+t*1e3:void 0;return v(d.map(t=>[dn.setPurity,{deviceId:y,trackId:t,purity:e,...n===void 0?{}:{switchAtMs:Math.round(n)}}]))},S=c.data==null?null:Pn(c.data);return r(`div`,{className:`space-y-2 rounded-md border border-primary/40 px-3 py-2`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[r(`span`,{className:`text-xs font-medium`,children:[s.tapeId,` — `,String(s.lanes.length),` tracks`]}),u(G,{disabled:d.length<2,onClick:()=>void b(In(d),`same-subject`),children:`Same subject`}),u(G,{variant:`secondary`,disabled:d.length<2,onClick:()=>void b(Ln(d),`different-subjects`),children:`Different subjects`}),u(C,{"aria-label":`Changed at (s from tape start)`,placeholder:`changed at s`,value:p,onChange:e=>m(e.target.value),className:`w-28`}),u(G,{variant:`secondary`,disabled:d.length!==1,onClick:()=>void x(`mixed`),children:`Mixed`}),u(G,{variant:`secondary`,disabled:d.length===0,onClick:()=>void x(`not-a-subject`),children:`Not a subject`}),u(G,{variant:s.reviewed?`secondary`:`primary`,onClick:()=>void v([[un.review,{tapeId:s.tapeId,reviewed:!s.reviewed}]]).then(()=>a.refetch()),children:s.reviewed?`Mark not reviewed`:`Mark reviewed`}),u(G,{variant:`ghost`,onClick:n,children:`Close`})]}),h!==null&&u(U,{message:h}),S!==null&&u(U,{variant:`warning`,message:S}),u(`ul`,{className:`space-y-1`,children:s.lanes.toSorted((e,t)=>e.firstT-t.firstT).map(e=>u(_r,{lane:e,marks:c.data===null||c.data===void 0?[]:Rn(e.trackId,c.data),selected:d.includes(e.trackId),onToggle:()=>_(e.trackId)},e.trackId))})]})}function _r({lane:e,marks:t,selected:n,onToggle:i}){let{src:a}=He(e.stillStored?Ue(`track`,e.trackId):void 0);return r(`li`,{className:`flex items-center gap-2 text-xs`,children:[u(`input`,{type:`checkbox`,"aria-label":`select ${e.trackId}`,checked:n,onChange:i}),a===null?u(`div`,{className:`h-10 w-10 rounded bg-surface-hover`}):u(`img`,{src:a,alt:e.trackId,className:`h-10 w-10 rounded object-cover`}),u(`span`,{className:`font-mono`,children:e.trackId}),u(`span`,{children:e.cls}),r(`span`,{className:`text-foreground-subtle`,children:[pr(e.firstT),` → `,pr(e.lastT),` · `,String(e.boundFrames),` `,`frames`]}),!e.stillStored&&u(`span`,{className:`text-foreground-subtle`,children:`not stored — marked through the tape`}),t.map(e=>u(q,{variant:`info`,children:e},e))]})}n();var vr=`camstack_admin_token`;function yr(){let e=h();return(t,n)=>e.trpcClient.addons.custom.mutate({addonId:Jn,action:t,input:n})}async function br(e,t){let n=localStorage.getItem(vr),r={};n!==null&&(r.Authorization=`Bearer ${n}`);let i=await fetch(mn(e),{headers:r});if(!i.ok){let e=await i.text().catch(()=>``);throw Error(Kn(i.status,e))}let a=await i.blob(),o=i.headers.get(`content-disposition`),s=(o===null?null:/filename="?([^";]+)"?/i.exec(o))?.[1]?.trim()??t,c=URL.createObjectURL(a),l=document.createElement(`a`);l.href=c,l.download=s,l.click(),setTimeout(()=>URL.revokeObjectURL(c),6e4)}function xr(){let[e,t]=l(!1);return u(we,{expanded:e,onExpandedChange:t,header:u(`span`,{className:`text-sm font-medium text-foreground`,children:`Tracking tapes`}),children:u(Sr,{})})}function Sr(){let e=yr(),t=je({isCamera:!0,projection:`slim`}),n=a(()=>{let e=new Map;for(let n of t.data??[])e.set(n.id,n.name);return t=>e.get(t)??`Camera ${String(t)}`},[t.data]),i=o({queryKey:[`events-debug`,`tapes`,`status`],queryFn:async()=>Sn(await e(un.status,{}))}),s=o({queryKey:[`events-debug`,`tapes`,`list`],queryFn:async()=>wn(await e(un.list,{}))}),[c,d]=l(null),[f,p]=l(null),m=async e=>{p(null);try{await br(e.id,`${e.scenario}.tape-bundle.json.gz`)}catch(e){p(gn(e))}},h=async t=>{let n=On(await e(un.release,{tapeId:t.id}));if(n===null)throw Error(hn);let r=An(n);if(r!==null)throw Error(r);await s.refetch()},g=async t=>{let n=kn(await e(un.remove,{tapeId:t.id}));if(n===null)throw Error(hn);let r=An(n);if(r!==null)throw Error(r);await s.refetch()};return r(`div`,{className:`space-y-3`,children:[r(`p`,{className:`text-xs text-foreground-subtle`,children:[`A camera records while its `,u(`strong`,{children:`Record the track history`}),` switch (camera settings → Tracking) is on; segments are kept 24 h. Promote a window worth keeping, label it in the review, mark it reviewed, download it and turn it into a test case with`,` `,u(`code`,{children:`npm run tracking-bench -- case`}),`.`]}),f!==null&&u(U,{message:f}),i.isLoading&&u(`p`,{className:`text-xs text-foreground-subtle`,children:`Loading camera status…`}),i.data===null&&u(U,{message:`The server answered in a shape this build does not understand.`}),r(`table`,{className:`w-full text-xs`,children:[u(`thead`,{children:r(`tr`,{className:`text-left text-foreground-subtle`,children:[u(`th`,{children:`Camera`}),u(`th`,{children:`State`}),u(`th`,{children:`Frames/min`}),u(`th`,{children:`Last hour`}),u(`th`,{children:`Held`}),u(`th`,{children:`Gaps`})]})}),u(`tbody`,{children:(i.data??[]).map(e=>r(`tr`,{children:[u(`td`,{children:n(e.deviceId)}),u(`td`,{children:u(q,{variant:e.state===`recording`?`success`:e.state===`off`?`default`:e.state===`unknown`?`warning`:`danger`,children:zn(e)})}),u(`td`,{children:e.framesPerMin===void 0?`—`:String(Math.round(e.framesPerMin))}),u(`td`,{title:e.shelfError,children:Wn(e.bytesLastHour)}),r(`td`,{title:e.shelfError,children:[Gn(e.segmentsHeld),` seg · `,Wn(e.bytesHeld)]}),u(`td`,{children:String(e.gapsSinceArmed)})]},e.deviceId))})]}),u(qn,{cameras:Fn(i.data??[]).map(e=>({value:String(e.deviceId),label:e.segmentsUnknown?`${n(e.deviceId)} (segments unknown)`:n(e.deviceId)})),call:e,onPromoted:()=>void s.refetch()}),s.isLoading&&u(`p`,{className:`text-xs text-foreground-subtle`,children:`Loading promoted tapes…`}),s.data===null&&u(U,{message:`The server answered in a shape this build does not understand.`}),r(`table`,{className:`w-full text-xs`,children:[u(`thead`,{children:r(`tr`,{className:`text-left text-foreground-subtle`,children:[u(`th`,{children:`Scenario`}),u(`th`,{children:`Camera`}),u(`th`,{children:`Window`}),u(`th`,{children:`State`}),u(`th`,{children:`Tracks`}),u(`th`,{})]})}),u(`tbody`,{children:(s.data??[]).map(e=>r(`tr`,{children:[u(`td`,{children:e.scenario}),u(`td`,{children:n(e.deviceId)}),r(`td`,{children:[new Date(e.fromMs).toLocaleString(),` · `,pr(e.toMs-e.fromMs),` `,`· `,e.lighting]}),r(`td`,{children:[u(q,{variant:e.state===`complete`?`success`:`warning`,children:e.state}),` `,e.reviewed&&u(q,{variant:`info`,children:`reviewed`}),` `,e.released&&u(q,{children:`released`})]}),r(`td`,{children:[String(e.tracksStillStored),`/`,String(e.tracks.length),` stored`]}),r(`td`,{className:`space-x-1 text-right`,children:[u(G,{variant:`secondary`,"aria-label":`Review ${e.scenario}`,onClick:()=>d(e.id),children:`Review`}),u(G,{variant:`ghost`,"aria-label":`Download ${e.scenario}`,onClick:()=>void m(e),children:u(T,{className:`h-3.5 w-3.5`})}),u(ce,{label:`Release`,icon:ke,title:`Release ${e.scenario}?`,description:`Releasing returns this tape's pinned tracks to ordinary retention — they can be pruned from then on. The promoted bundle itself is kept until deleted.`,confirmLabel:`Release`,triggerVariant:`ghost`,confirmVariant:`danger`,disabled:e.released,action:()=>h(e)}),u(ce,{label:`Delete`,icon:y,title:`Delete ${e.scenario}?`,description:`Deleting removes the promoted bundle and its index row for good. Its tracks' pins are released first — this cannot be undone.`,confirmLabel:`Delete`,triggerVariant:`ghost`,confirmVariant:`danger`,action:()=>g(e)})]})]},e.id))})]}),c!==null&&u(gr,{tapeId:c,call:e,onClose:()=>d(null),onChanged:()=>void s.refetch()})]})}n();var Cr=`all`,wr=`The server answered in a shape this build does not understand.`,Tr={error:`danger`,warn:`warning`,info:`info`};function Er({findings:e}){return e.length===0?u(q,{variant:`success`,children:`no anomaly found`}):u(`div`,{className:`flex flex-wrap gap-1`,children:dr(e).map(e=>u(q,{variant:Tr[e.severity],title:e.detail,children:lr(e.code)},e.code))})}function Dr({track:e,report:t,analyzing:n}){let i=wt(t?.previewMissReason??e.previewMissReason);return r(`div`,{className:`space-y-1 border-t border-border pt-1.5`,children:[t===void 0?u(`span`,{className:`text-[10px] text-foreground-subtle`,children:n?`analysing…`:`not analysed`}):r(s,{children:[u(Er,{findings:t.findings}),r(`p`,{className:`text-[10px] text-foreground-subtle`,title:t.mediaKinds.length>0?t.mediaKinds.join(`, `):`no media of any kind`,children:[String(t.mediaCount),` media · `,String(t.eventCount),` events ·`,` `,String(t.positionCount),` positions`]})]}),i!==null&&u(`p`,{className:`text-[10px] text-foreground-subtle`,title:i.raw,children:i.sentence})]})}function Or(){let e=h(),[t,n]=l(Cr),[i,s]=l(!1),[c,d]=l(null),[f,p]=l(new Set),[m,g]=l(null),[_,v]=l(null),[y,b]=l(null),[x,S]=l([]),C=Ht(),w=je({isCamera:!0,projection:`slim`}),E=a(()=>[{value:Cr,label:`All cameras`},...(w.data??[]).map(e=>({value:String(e.id),label:e.name}))],[w.data]),D=a(()=>{let e=new Map;for(let t of w.data??[])e.set(t.id,t.name);return e},[w.data]),O=e=>D.get(e)??`Camera ${String(e)}`,k=a(()=>t===Cr?[]:[Number.parseInt(t,10)],[t]),j=o({queryKey:[`events-debug`,`list`,k],queryFn:async()=>or(await e.trpcClient.addons.custom.mutate({addonId:Jn,action:Yn,input:k.length===0?{}:{deviceIds:k}}))}),M=a(()=>(j.data?.tracks??[]).map(e=>e.trackId),[j.data]),N=o({queryKey:[`events-debug`,`analyze`,M],enabled:M.length>0,queryFn:async()=>sr(await e.trpcClient.addons.custom.mutate({addonId:Jn,action:Xn,input:{trackIds:M}}))}),P=a(()=>{let e=new Map;for(let t of N.data?.reports??[])e.set(t.trackId,t);return e},[N.data]),F=j.data?.tracks??[],I=j.data===null||N.data===null,L=()=>{j.refetch(),N.refetch()},R=e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},z=()=>{p(new Set(F.map(e=>mr(e.deviceId,e.trackId))))},V=()=>p(new Set),ne=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await C.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},H=e=>{if(!zt||_!==null)return;let t=hr(F,f);t.length!==0&&(v(e),b(null),(async()=>{let n=await ne(e,t);v(null);let r=new Set(n.refused);p(new Set(t.filter(e=>r.has(e.trackId)).map(e=>mr(e.deviceId,e.trackId)))),e===`analyzed`&&S(t.filter(e=>!r.has(e.trackId))),n.refused.length>0&&b(`${String(n.refused.length)} of ${String(t.length)} were refused by the server and are still selected. Check the hub log.`),j.refetch()})())},re=()=>{let e=x;e.length===0||_!==null||(v(`analyzed`),b(null),(async()=>{for(let t of e)try{await C.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,flags:{debug:!0}})}catch{b(`Some tracks could not be re-marked. Refresh and try again.`)}v(null),S([]),j.refetch()})())},ie=async()=>{s(!0),d(null);try{await Ge(fr(k),`camstack-debug.zip`)}catch(e){d(e instanceof Error?e.message:`Export failed.`)}finally{s(!1)}},W=_!==null;return u(Ve,{children:r(`section`,{className:`space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[u(`div`,{className:`w-44`,children:u(Ee,{value:t,options:E,onChange:e=>n(e.target.value)})}),r(G,{variant:`secondary`,onClick:L,disabled:j.isFetching,children:[j.isFetching?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(A,{className:`h-3.5 w-3.5`}),`Refresh`]}),r(G,{onClick:()=>void ie(),disabled:i||F.length===0,children:[i?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(T,{className:`h-3.5 w-3.5`}),`Export all (`,String(F.length),`)`]}),F.length>0&&f.size<F.length&&u(G,{variant:`ghost`,onClick:z,children:`Select all`})]}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`A `,u(`code`,{children:`debug`}),` mark does not pin retention — this lists the marked tracks that still exist. A track whose media was evicted shows as missing media. Use `,u(`strong`,{children:`Keep`}),` `,`to hold a selection against pruning while you investigate, and `,u(`strong`,{children:`Analyzed`}),` `,`to un-mark the ones you are finished with.`]}),u(xr,{}),j.isError&&u(U,{message:`Could not load the marked tracks.`}),I&&!j.isError&&u(U,{message:wr}),c!==null&&u(U,{message:c}),y!==null&&u(U,{message:y}),j.data?.truncated===!0&&u(U,{message:`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`}),(N.data?.vanished.length??0)>0&&r(`p`,{className:`text-xs text-foreground-subtle`,children:[String(N.data?.vanished.length),` marked track(s) were evicted between the list and the analysis.`]}),f.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[String(f.size),` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[u(`span`,{title:zt?void 0:`Track flags arrive with the next server update`,children:r(G,{variant:`secondary`,onClick:()=>H(`keep`),disabled:!zt||W,children:[_===`keep`?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(ye,{className:`h-3.5 w-3.5`}),` `,`Keep`]})}),u(`span`,{title:zt?void 0:`Track flags arrive with the next server update`,children:r(G,{onClick:()=>H(`analyzed`),disabled:!zt||W,children:[_===`analyzed`?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(te,{className:`h-3.5 w-3.5`}),` `,`Analyzed`]})}),u(G,{variant:`ghost`,onClick:V,disabled:W,children:u(ee,{className:`h-3.5 w-3.5`})})]})]}),x.length>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-border bg-surface px-3 py-2`,children:[r(`span`,{className:`text-xs text-foreground`,children:[String(x.length),` track(s) marked analyzed and removed from this list.`]}),r(G,{variant:`ghost`,onClick:re,disabled:W,children:[u(pe,{className:`h-3.5 w-3.5`}),` Undo`]}),u(G,{variant:`ghost`,onClick:()=>S([]),disabled:W,children:u(ee,{className:`h-3.5 w-3.5`})})]}),j.isLoading?u(be,{children:u(`div`,{className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`Loading…`})}):F.length===0?u(be,{children:r(`div`,{className:`flex flex-col items-center gap-2 px-3 py-8 text-center`,children:[u(B,{className:`h-5 w-5 text-foreground-subtle`}),u(`p`,{className:`text-xs text-foreground-subtle`,children:`No track is marked for debug. Mark one from a track's actions to see it here.`})]})}):u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:F.map(e=>{let t=P.get(e.trackId);return u(Et,{row:e,cameraName:O(e.deviceId),nowMs:e.lastSeen,selected:f.has(mr(e.deviceId,e.trackId)),onToggleSelect:R,onOpenDetail:g,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:u(Dr,{track:e,report:t,analyzing:N.isFetching})},mr(e.deviceId,e.trackId))})}),m&&u(ln,{row:m,cameraName:O(m.deviceId),deleteAvailable:Zt,onClose:()=>g(null),onDeleted:()=>{g(null),j.refetch()},onFlagsChanged:e=>{e.debug||(g(null),j.refetch())}})]})})}var kr=200,Ar=3e4,jr=[];function Mr(e){let t=h(),n=e.deviceIds.length>0,r=[...e.deviceIds].sort((e,t)=>e-t),{data:i,isLoading:a}=o({queryKey:[`events-feed`,r,e.since,e.until,e.minImportance??null,e.classFilter??null],enabled:n,staleTime:Ar,refetchInterval:Ar,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEventsBatch.query({deviceIds:r,since:e.since,until:e.until,limit:kr,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>e.events.map(t=>({...t,deviceId:e.deviceId})))});return{rows:mt(pt(i??jr),`importance`),isLoading:n&&a}}n();var Nr=[`events-feed`],Pr=2e3;function Fr(n){let r=c(),i=n?.paused===!0,a=t(r);a.current=r;let o=t(i);o.current=i;let[s,u]=l(!1),f=e(()=>{a.current.invalidateQueries({queryKey:Nr})},[]),p=t(void 0);p.current||=nt({delayMs:Pr,invalidate:()=>{o.current?u(!0):f()}}),d(()=>()=>p.current?.cancel(),[]),d(()=>{i||!s||(u(!1),f())},[i,s,f]);let m=e(()=>{u(!1),f()},[f]);return O(ze.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),O(ze.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:s,refreshNow:m}}n();function Ir({groups:e,selected:t,onChange:n,loading:i=!1}){let{t:o}=Be(),[s,c]=l(!1),[d,f]=l(``),[p,h]=l(new Set),g=d.trim().toLowerCase(),_=e=>g.length===0||R(e,o).toLowerCase().includes(g),y=a(()=>e.map(e=>({macro:e.macro,subs:e.subs.filter(t=>_(t)||_(e.macro))})).filter(e=>_(e.macro)||e.subs.length>0),[e,g]),b=e=>h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),x=e=>{let r=new Set(t),i=t.has(e.macro.kind)&&e.subs.every(e=>t.has(e.kind)),a=[e.macro.kind,...e.subs.map(e=>e.kind)];if(i)for(let e of a)r.delete(e);else for(let e of a)r.add(e);n(r)},S=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},C=()=>n(new Set),T=t.size;return r(`div`,{className:`relative`,children:[r(`button`,{type:`button`,onClick:()=>c(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${T>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(ae,{className:`h-3.5 w-3.5`}),T>0?`Kinds (${String(T)})`:`Kinds`,u(m,{className:`h-3 w-3`})]}),s&&r(`div`,{className:`absolute z-20 mt-1 max-h-80 w-64 overflow-auto rounded-md border border-border bg-surface p-2 shadow-lg`,children:[r(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[u(_e,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`Search kinds…`,className:`w-full bg-transparent py-1 text-xs outline-none`}),T>0&&u(`button`,{type:`button`,onClick:C,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),y.length===0&&u(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:i?`Loading kinds…`:g.length>0?`No kind matches that search.`:`These cameras advertise no event kinds.`}),y.map(e=>{let n=w(e.macro.iconId),i=p.has(e.macro.kind)||g.length>0,a=t.has(e.macro.kind);return r(`div`,{className:`mb-0.5`,children:[r(`div`,{className:`flex items-center gap-1`,children:[e.subs.length>0?u(`button`,{type:`button`,onClick:()=>b(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:u(i?m:v,{className:`h-3 w-3`})}):u(`span`,{className:`w-3`}),r(`label`,{className:`flex flex-1 cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[u(`input`,{type:`checkbox`,checked:a,onChange:()=>x(e),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),u(`span`,{className:`font-medium`,children:R(e.macro,o)})]})]}),i&&e.subs.map(e=>{let n=w(e.iconId);return r(`label`,{className:`ml-5 flex cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[u(`input`,{type:`checkbox`,checked:t.has(e.kind),onChange:()=>S(e.kind),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),u(`span`,{children:R(e,o)})]},e.kind)})]},e.macro.kind)})]})]})}function Lr(e,t){let n=new Map;for(let r of e)if(!(t.size>0&&!t.has(r.deviceId)))for(let e of r.kinds)n.has(e.kind)||n.set(e.kind,e);return n}function Rr(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var zr=new Set([`detection`,`package`]);function Br(e,t){return[...Lr(e,t).values()].filter(e=>e.parentKind===null&&zr.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function Vr(e,t){let n=Lr(e,t),r=new Map,i=new Map;for(let e of n.values()){if(e.parentKind===null){i.set(e.kind,e);continue}let t=r.get(e.parentKind);t===void 0?r.set(e.parentKind,[e]):t.push(e)}for(let[e,t]of r){if(i.has(e))continue;let n=t[0];n!==void 0&&i.set(e,Rr(e,n))}return[...i.values()].map(e=>({macro:e,subs:[...r.get(e.kind)??[]].sort((e,t)=>e.label.localeCompare(t.label))})).sort((e,t)=>e.macro.label.localeCompare(t.macro.label))}n();function Hr(){let[n,r]=l(!1),i=t(null),[a,o]=l(0),s=e(e=>{i.current!==e&&(i.current=e,o(e=>e+1))},[]);return d(()=>{let e=i.current;if(!e||typeof IntersectionObserver>`u`){r(!1);return}let t=new IntersectionObserver(e=>{let t=e[e.length-1];t&&r(!t.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return t.observe(e),()=>t.disconnect()},[a]),{ref:s,scrolledPast:n}}n();var Ur=[`events-feed`],Wr=60,Gr=[{value:`importance`,label:`Importance`,icon:ot},{value:`time`,label:`Recent`,icon:ge}];function Kr(){let e=c(),t=Me(),n=Pe(),[i,o]=l(tt),[f,p]=l(new Set),[m,h]=l(new Set),[g,_]=l(0),[v,b]=l(`time`),[x,S]=l(new Set),[C,w]=l(null),[T,E]=l(()=>Date.now());d(()=>{let e=setInterval(()=>E(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:D,until:O}=a(()=>vt({fromMs:i.fromMs,toMs:i.toMs},T),[i.fromMs,i.toMs,T]),k=Hr(),{pending:A,refreshNow:j}=Fr({paused:C!==null||x.size>0||k.scrolledPast}),{data:M=[]}=je({isCamera:!0,projection:`slim`}),N=a(()=>M.map(e=>e.id),[M]),{data:P,isLoading:F}=Se({deviceIds:N},{enabled:N.length>0,staleTime:5*6e4}),I=a(()=>Vr(P??[],f),[P,f]),L=en(),R=L.isPending,{rows:z,isLoading:B}=Mr({deviceIds:N,since:D,until:O,minImportance:g>0?g:void 0,classFilter:m.size===1?[...m][0]:void 0}),te=a(()=>{let e=new Map;for(let t of M??[])e.set(t.id,t.name);return e},[M]),V=e=>te.get(e)??`Camera #${String(e)}`,ne=a(()=>qe(z).map(e=>({id:e,name:V(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[z,te]),H=a(()=>mt(ht(z,{cameras:f,classes:m,minImportance:g}),v),[z,f,m,g,v]),U=Qe(H,Wr,a(()=>JSON.stringify([[...f].sort((e,t)=>e-t),[...m].sort(),g,v,D,O]),[f,m,g,v,D,O])),re=()=>{e.invalidateQueries({queryKey:Ur})},ie=()=>S(new Set);function W(e){S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function ae(){if(x.size===0||!Zt)return;let e=_t(z,x),t=[...e.values()].reduce((e,t)=>e+t.length,0);t!==0&&(async()=>{await n({title:`Delete ${String(t)} track${t===1?``:`s`}`,message:`Delete ${String(t)} track${t===1?``:`s`} and every image and clip captured for ${t===1?`it`:`them`}? This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&oe(e)})()}function oe(e){let n=[...e];Promise.allSettled(n.map(([e,t])=>L.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{re();let r=[],i=new Set;e.forEach((e,t)=>{let a=n[t];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)i.add(gt(o,e));else r.push(o)}),S(e=>{let t=new Set(e);for(let e of i)t.delete(e);return t}),r.length>0&&t({title:`Some tracks were not deleted`,message:`Failed to delete tracks on: ${r.map(e=>V(e)).join(`, `)}. They remain selected — retry, or check the server logs.`,variant:`danger`})})}let se=H.length!==z.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(et,{onChange:o}),u(Xe,{cameras:ne,selected:f,onChange:p}),u(Ir,{groups:I,selected:m,onChange:h,loading:F}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(`span`,{children:`Min score`}),u(`input`,{type:`range`,min:0,max:1,step:.05,value:g,onChange:e=>_(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":`Minimum importance`}),u(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(g*100)})]}),u(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Gr.map(e=>{let t=e.icon;return r(`button`,{type:`button`,onClick:()=>b(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${v===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!B&&u(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:se?`${String(H.length)} of ${String(z.length)} events`:`${String(H.length)} event${H.length===1?``:`s`}`})]}),x.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[x.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[u(`span`,{title:Zt?void 0:`Track deletion arrives with the next server update`,children:r(G,{variant:`secondary`,onClick:ae,disabled:!Zt||R,children:[R?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(y,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),u(G,{variant:`ghost`,onClick:ie,disabled:R,children:u(ee,{className:`h-3.5 w-3.5`})})]})]}),B&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(K,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!B&&H.length===0&&u(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),A&&u(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:u(`button`,{type:`button`,onClick:j,className:`rounded-full border border-primary/40 bg-surface px-3 py-1 text-[11px] font-medium text-primary shadow-sm hover:bg-primary/10`,children:`New events — refresh`})}),!B&&H.length>0&&r(s,{children:[u(`div`,{ref:k.ref,"aria-hidden":!0,className:`h-0`}),u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:U.pageItems.map(e=>u(Et,{row:e,cameraName:V(e.deviceId),nowMs:T,selected:x.has(gt(e.deviceId,e.trackId)),onToggleSelect:W,onOpenDetail:w},gt(e.deviceId,e.trackId)))}),u(Ke,{currentPage:U.page,totalItems:U.totalItems,pageSize:U.pageSize,onPageChange:U.setPage,itemNoun:`events`})]}),C&&u(ln,{row:C,cameraName:V(C.deviceId),deleteAvailable:Zt,onClose:()=>w(null),onDeleted:()=>{re(),w(null)},onFlagsChanged:e=>{w(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}n();var qr=50,Jr=350,Yr=[{value:`loose`,label:`Loose`,title:`The search model's own floor`},{value:`balanced`,label:`Balanced`,title:`1.25× the search model's floor`},{value:`strict`,label:`Strict`,title:`1.5× the search model's floor`}];function Xr(e){let t=String(e.id);return{id:t,trackId:e.trackId??t,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,subLabel:e.subLabel,importance:e.importance??0,bestEventId:t,mediaId:e.keyFrameMediaId??e.mediaId,windowMs:void 0}}function Zr({onActiveChange:e}){let[t,n]=l(``),[i,o]=l(`loose`),[s,c]=l(null),[f,p]=l(null),[m,h]=l(null),g=L(t,Jr).trim(),_=g.length>0;d(()=>{e(_)},[_,e]);let[v,y]=l(()=>Date.now());d(()=>{let e=setInterval(()=>y(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:b=[]}=je({isCamera:!0,projection:`slim`}),x=a(()=>{let e=new Map;for(let t of b)e.set(t.id,t.name);return e},[b]),S=e=>x.get(e)??`Camera #${String(e)}`,C=a(()=>b.map(e=>e.id),[b]),{data:w}=Se({deviceIds:C},{enabled:C.length>0,staleTime:5*6e4}),T=a(()=>Br(w??[],new Set(f===null?[]:[f])),[w,f]);d(()=>{s!==null&&(T.some(e=>e.kind===s)||c(null))},[T,s]);let{data:E,isFetching:D,isError:O,error:k}=le({text:g,strictness:i,limit:qr,classFilter:s??void 0,deviceId:f??void 0},{enabled:_}),A=a(()=>[...E??[]].sort((e,t)=>t.score-e.score).map(e=>({...Xr(e),score:e.score})),[E]);function j(e){c(t=>t===e?null:e)}return r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(`div`,{className:`relative min-w-[16rem] flex-1`,children:[u(_e,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),u(`input`,{type:`text`,value:t,onChange:e=>n(e.target.value),placeholder:`Semantic search — describe what you're looking for…`,className:`h-9 w-full rounded-md border border-border bg-background pl-8 pr-8 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":`Semantic event search`}),t&&u(`button`,{type:`button`,onClick:()=>n(``),className:`absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Clear search`,children:u(ee,{className:`h-3.5 w-3.5`})})]}),D&&_&&u(K,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[u(`div`,{className:`flex items-center gap-1`,children:T.map(e=>u(`button`,{type:`button`,onClick:()=>j(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${s===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:R(e)},e.kind))}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(`span`,{children:`Camera`}),r(`select`,{value:f===null?``:String(f),onChange:e=>p(e.target.value===``?null:Number(e.target.value)),className:`h-7 rounded-md border border-border bg-background px-1.5 text-xs text-foreground focus:border-primary focus:outline-none`,"aria-label":`Filter by camera`,children:[u(`option`,{value:``,children:`All`}),b.map(e=>u(`option`,{value:String(e.id),children:e.name},e.id))]})]}),r(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(`span`,{children:`Match`}),u(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Yr.map(e=>u(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:e.title,children:e.label},e.value))})]}),_&&!D&&!O&&r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[A.length,` match`,A.length===1?``:`es`]})]})]}),_&&r(`div`,{className:`space-y-3`,children:[O&&r(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,k instanceof Error?k.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!O&&D&&A.length===0&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(K,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!O&&!D&&A.length===0&&r(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:[`No semantic matches for “`,g,`”. Try a looser match threshold or a different phrasing.`]}),!O&&A.length>0&&u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:A.map(e=>u(Et,{row:e,cameraName:S(e.deviceId),nowMs:v,score:e.score,onOpenDetail:h},e.id))})]}),m&&u(ln,{row:m,cameraName:S(m.deviceId),deleteAvailable:Zt,onClose:()=>h(null),onDeleted:()=>h(null)})]})}n();function Qr(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return`just now`;if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function $r({row:e,cameraName:t,nowMs:n}){let i=He(e.keyFrameMediaId===void 0?void 0:We(e.keyFrameMediaId));return r(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[r(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[i.src?u(`img`,{src:i.src,alt:`Parked ${e.className} on ${t}`,className:`h-full w-full object-cover`}):u(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:u(ut,{className:`h-6 w-6`})}),u(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:e.label??e.className})]}),r(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[u(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,Qr(n,e.becameStationaryAt)]})]})]})}function ei(){let[e,t]=l(!1),n=Date.now(),{data:i=[]}=je({isCamera:!0,projection:`slim`}),o=a(()=>i.map(e=>e.id),[i]),s=a(()=>{let e=new Map;for(let t of i)e.set(t.id,t.name);return e},[i]),{rows:c,unreadableCount:d}=rt(o);return c.length===0&&d===0?null:r(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[r(`button`,{type:`button`,onClick:()=>t(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[u(e?m:v,{className:`h-4 w-4 text-foreground-subtle`}),u(ut,{className:`h-4 w-4 text-foreground-subtle`}),u(`span`,{className:`text-sm font-semibold text-foreground`,children:`Stationary`}),u(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:c.length}),u(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:`Parked objects — kept out of the event feed`}),d>0?r(`span`,{className:`ml-2 text-[11px] text-warning`,children:[d,` camera`,d===1?``:`s`,` could not be read`]}):null]}),e&&u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:c.map(e=>u($r,{row:e,cameraName:s.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}n();function ti(){let[e,t]=l(!1);return u(Ve,{children:r(`section`,{className:`space-y-3`,children:[u(Zr,{onActiveChange:t}),!e&&u(ei,{}),!e&&u(Kr,{})]})})}var ni=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],ri=new Set(ni);function ii(e){let t=e?.trim().toLowerCase();return t===void 0||t===``?null:ri.has(t)?`"${t}" is a macro class, not a label — person / postman / Marco are three different tiers`:null}function ai({annotations:e,selectedIndex:t,onSelect:n,onChange:i,onDelete:a}){return e.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle p-3`,children:[`No subject on this frame yet. Drag on the image to draw one, or ask the pipeline for a proposal. Annotate `,u(`strong`,{children:`every`}),` subject — a frame with one box and three unlabelled people teaches the model that two thirds of the people in it are background.`]}):u(`ul`,{className:`divide-y divide-border`,children:e.map((e,o)=>{let s=o===t,c=ii(e.label),l=ii(e.subLabel);return r(`li`,{className:`p-2.5 space-y-1.5 ${s?`bg-surface-hover`:``}`,onFocus:()=>{n(o)},children:[r(`div`,{className:`flex items-center gap-2`,children:[u(Ee,{className:`w-28`,value:e.macroClass,options:ni.map(e=>({value:e,label:e})),onChange:e=>{let t=ni.find(t=>t===e.target.value);t!==void 0&&i(o,{macroClass:t})}}),u(Ee,{className:`w-32`,value:e.kind,options:[{value:`subject`,label:`subject`},{value:`model_error`,label:`model error`}],onChange:e=>{i(o,{kind:e.target.value===`model_error`?`model_error`:`subject`})}}),e.source===`assist`&&r(q,{variant:`info`,children:[e.assistModelId??`assist`,e.assistScore===void 0?``:` ${e.assistScore.toFixed(2)}`]}),u(G,{variant:`ghost`,size:`sm`,"aria-label":`Delete this subject`,onClick:()=>{a(o)},children:u(y,{className:`h-3 w-3`})})]}),r(`div`,{className:`flex items-center gap-2`,children:[u(C,{className:`flex-1`,placeholder:`label (postman, van, cat…)`,value:e.label??``,onChange:e=>{i(o,{label:e.target.value})}}),u(C,{className:`flex-1`,placeholder:`sub-label (a name, a plate…)`,value:e.subLabel??``,onChange:e=>{i(o,{subLabel:e.target.value})}})]}),c!==null&&u(`p`,{className:`text-[11px] text-danger`,children:c}),l!==null&&u(`p`,{className:`text-[11px] text-danger`,children:l})]},`${String(o)}-${String(e.bbox.x)}`)})})}function oi(e){return e.every(e=>ii(e.label)===null&&ii(e.subLabel)===null&&ri.has(e.macroClass))}function si(e){return e<0?0:e>1?1:e}function ci(e,t,n,r){if(!(e>0)||!(t>0)||!(n>0)||!(r>0))return null;let i=Math.min(e/n,t/r),a=n*i,o=r*i;return{left:(e-a)/2,top:(t-o)/2,width:a,height:o}}function li(e,t,n){return{x:si((e-n.left)/n.width),y:si((t-n.top)/n.height)}}function ui(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),w:Math.abs(t.x-e.x),h:Math.abs(t.y-e.y)}}function di(e){return e.w>=.01&&e.h>=.01}function fi(e,t){return{left:t.left+e.x*t.width,top:t.top+e.y*t.height,width:e.w*t.width,height:e.h*t.height}}function pi(e,t){let n=-1,r=1/0;return e.forEach((e,i)=>{if(!(t.x>=e.x&&t.x<=e.x+e.w&&t.y>=e.y&&t.y<=e.y+e.h))return;let a=e.w*e.h;a<r&&(n=i,r=a)}),n}n();function mi({imageSrc:n,imageWidth:a,imageHeight:o,boxes:s,selectedIndex:c,onSelect:d,onDraw:f}){let p=t(null),[m,h]=l({w:0,h:0}),[g,_]=l(null);i(()=>{let e=p.current;if(e===null)return;let t=new ResizeObserver(()=>{h({w:e.clientWidth,h:e.clientHeight})});return t.observe(e),h({w:e.clientWidth,h:e.clientHeight}),()=>{t.disconnect()}},[]);let v=ci(m.w,m.h,a,o),y=e(e=>{let t=p.current;if(t===null||v===null)return null;let n=t.getBoundingClientRect();return li(e.clientX-n.left,e.clientY-n.top,v)},[v]);return r(`div`,{ref:p,className:`relative w-full h-full min-h-[280px] bg-surface-sunken select-none touch-none`,onPointerDown:e=>{let t=y(e);t!==null&&(e.currentTarget.setPointerCapture(e.pointerId),_({start:t,current:ui(t,t)}))},onPointerMove:e=>{if(g===null)return;let t=y(e);t!==null&&_({start:g.start,current:ui(g.start,t)})},onPointerUp:()=>{if(g===null)return;let e=g.current;_(null),di(e)?f(e):d(pi(s.map(e=>e.bbox),g.start))},children:[u(`img`,{src:n,alt:`Frame being annotated`,className:`absolute inset-0 w-full h-full object-contain pointer-events-none`}),v!==null&&s.map((e,t)=>{let n=fi(e.bbox,v),i=e.kind===`model_error`,a=t===c,o=i?`#ef4444`:a?`#22c55e`:`#3b82f6`;return u(`div`,{className:`absolute pointer-events-none`,style:{left:n.left,top:n.top,width:n.width,height:n.height,border:`${a?`2px`:`1px`} ${i?`dashed`:`solid`} ${o}`,opacity:e.source===`assist`&&!a?.65:1},children:r(`span`,{className:`absolute -top-4 left-0 text-[10px] px-1 rounded`,style:{background:o,color:`#08121f`},children:[e.label??e.macroClass,i?` ✕`:``]})},`${String(t)}-${String(e.bbox.x)}-${String(e.bbox.y)}`)}),g!==null&&v!==null&&u(`div`,{className:`absolute border border-dashed border-primary pointer-events-none`,style:fi(g.current,v)})]})}n();function hi(){let e=me({}),t=Oe({}),n=re({}),[i,a]=l(null),[o,s]=l(null),c=async(e,t,n)=>{a(e),s(null);try{await Ge(p(t),n)}catch(e){s(e instanceof Error?e.message:String(e))}finally{a(null)}},d=e.data,f=d!==void 0&&d.trackCount===0;return r(`div`,{className:`rounded-md border border-border bg-surface p-3 space-y-2`,children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Export dataset`}),r(G,{variant:`secondary`,size:`sm`,disabled:t.data===void 0||i!==null,onClick:()=>{t.data!==void 0&&c(`annotated`,t.data.url,`camstack-retrain-export.tar`)},children:[i===`annotated`?u(K,{className:`h-3 w-3 animate-spin`}):u(T,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Annotated dataset`})]}),r(G,{variant:`secondary`,size:`sm`,disabled:n.data===void 0||f||i!==null,onClick:()=>{n.data!==void 0&&c(`marked`,n.data.url,`camstack-training-export.tar`)},children:[i===`marked`?u(K,{className:`h-3 w-3 animate-spin`}):u(T,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Marked media`})]})]}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.isError?`The export summary could not be read, so the size of the marked set is unknown — not zero.`:d===void 0?`Measuring the marked set…`:f?`No track is marked for training: the marked-media archive would be empty. The annotated dataset can still hold frames from tracks already completed — this count does not measure those.`:`${String(d.trackCount)} marked track${d.trackCount===1?``:`s`} · ${String(d.fileCount)} file${d.fileCount===1?``:`s`} · ${at(d.byteCount)}${d.truncated?` · more marked tracks exist than one pass carries`:``}`}),(t.isError||n.isError)&&u(`p`,{className:`text-[11px] text-danger`,children:`An export data plane is not available on the node that answered — no archive can be streamed from here.`}),o!==null&&r(`p`,{className:`text-[11px] text-danger`,children:[`Download failed: `,o]})]})}function gi(e){return e>=1e6?`${(e/1e6).toFixed(1)} MB`:`${Math.round(e/1e3)} KB`}function _i({candidates:e,copies:t,activeFrameId:n,refusals:i,isSelecting:a,onSelectCandidate:o,onOpenCopy:s,onRemoveCopy:c}){let l=new Set(t.map(e=>e.sourceMediaId)),d=e.filter(e=>!l.has(e.mediaId));return r(`div`,{className:`space-y-3`,children:[r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`In the dataset (`,t.length,`)`]}),t.length===0?u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No frame copied yet. Selecting a frame copies it into retrain storage immediately — the dataset stops depending on the track's own media from that moment.`}):u(`ul`,{className:`flex flex-wrap gap-2`,children:t.map(e=>u(`li`,{children:r(`div`,{className:`rounded-md border px-2 py-1.5 text-[11px] ${e.frameId===n?`border-primary bg-surface-hover`:`border-border`}`,children:[r(`button`,{type:`button`,className:`flex items-center gap-1.5 text-left`,onClick:()=>{s(e.frameId)},children:[u(te,{className:`h-3 w-3 text-success`}),u(`span`,{className:`font-medium text-foreground`,children:e.sourceKind}),r(`span`,{className:`text-foreground-subtle`,children:[e.width,`×`,e.height,` · `,gi(e.sizeBytes)]})]}),r(`button`,{type:`button`,"aria-label":`Remove this frame from the dataset`,className:`mt-1 flex items-center gap-1 text-foreground-muted hover:text-danger`,onClick:()=>{c(e.frameId)},children:[u(y,{className:`h-3 w-3`}),`remove`]})]})},e.frameId))})]}),r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`Available frames (`,d.length,`)`]}),d.length===0?u(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.length===0?`This track has no whole, unannotated frame left — its media aged out before it was marked. Anything already copied above is still usable.`:`Every available frame is already in the dataset.`}):u(`ul`,{className:`flex flex-wrap gap-2`,children:d.map(e=>{let t=i.get(e.mediaId);return r(`li`,{children:[r(G,{variant:`secondary`,size:`sm`,disabled:a||t!==void 0,onClick:()=>{o(e.mediaId)},children:[a?u(K,{className:`h-3 w-3 animate-spin`}):u(t===void 0?P:_,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:e.kind}),u(`span`,{className:`ml-1 text-foreground-subtle`,children:gi(e.sizeBytes)})]}),t!==void 0&&u(q,{variant:`danger`,className:`ml-1`,children:t})]},e.mediaId)})})]})]})}function vi(e){return e.frameCount===0?`untouched`:e.annotationCount===0?`started`:`ready`}var yi={untouched:{icon:ct,label:`to do`,variant:`default`},started:{icon:st,label:`frames only`,variant:`info`},ready:{icon:j,label:`annotated`,variant:`success`}};function bi(e){return new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function xi({tracks:e,isLoading:t,selectedTrackId:n,deviceNames:i,onSelect:a}){return t?r(`div`,{className:`flex items-center gap-2 p-4 text-xs text-foreground-subtle`,children:[u(K,{className:`h-3.5 w-3.5 animate-spin`}),`Loading staging tracks…`]}):e.length===0?u(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`Nothing in staging. Mark a track for training from the viewer or the Events grid and it appears here.`}):u(`ul`,{className:`divide-y divide-border`,children:e.map(e=>{let t=yi[vi(e)],o=t.icon;return u(`li`,{children:r(`button`,{type:`button`,onClick:()=>{a(e)},className:`w-full text-left px-3 py-2 flex items-start gap-2 hover:bg-surface-hover ${e.trackId===n?`bg-surface-hover`:``}`,children:[u(o,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 text-foreground-subtle`}),r(`span`,{className:`min-w-0 flex-1`,children:[r(`span`,{className:`flex items-center gap-2`,children:[u(`span`,{className:`text-xs font-medium text-foreground truncate`,children:e.label??e.className}),u(q,{variant:t.variant,children:t.label})]}),r(`span`,{className:`block text-[11px] text-foreground-subtle truncate`,children:[i.get(e.deviceId)??`Camera ${String(e.deviceId)}`,` ·`,` `,bi(e.lastSeen)]}),r(`span`,{className:`block text-[11px] text-foreground-muted`,children:[e.frameCount,` frame`,e.frameCount===1?``:`s`,` ·`,` `,e.annotationCount,` subject`,e.annotationCount===1?``:`s`]})]})]})},e.trackId)})})}var Si=`object-detection`;function Ci(e,t){for(let n of e){if(n.addonId===t)return n;let e=n.children===void 0?void 0:Ci(n.children,t);if(e!==void 0)return e}}function wi(e,t){for(let n of e.slots){let e=n.addons.find(e=>e.id===t);if(e!==void 0)return e}}function Ti(e){let{status:t,nodeDevices:n,schema:r,resolvedSteps:i}=e;if(t===void 0)return{kind:`unknown`,gap:`pending`};if(t.detection===null)return{kind:`unknown`,gap:t.degraded.some(e=>e.stage===`detection`)?`placement-unreadable`:`detection-off`};let a=t.detection;if(n===void 0||r===void 0||i===void 0)return{kind:`unknown`,gap:`pending`};if(!n.reachable)return{kind:`unknown`,gap:`node-unreachable`};let o=n.devices.find(e=>e.backend===a.engine.backend&&e.device===a.engine.device);if(o===void 0)return{kind:`unknown`,gap:`device-unknown`};let s=wi(r,Si);if(s===void 0)return{kind:`unknown`,gap:`step-unknown`};let c=z({catalog:s,device:o,override:Ci(i,Si)?.modelId,base:o.steps?.[Si]?.modelId});return c===void 0?{kind:`unknown`,gap:`no-model`}:{kind:`resolved`,nodeId:a.nodeId,modelId:c,minScore:s.models.find(e=>e.id===c)?.defaultConfidence??s.defaultConfidence}}n();var Ei=`person`,Di={pending:`Reading which detector this camera runs…`,"placement-unreadable":`The detection stage of this camera could not be read, so the model it runs is unknown — not absent.`,"detection-off":`This camera runs no object detector, so there is no proposal to mirror.`,"node-unreachable":`The node that detects for this camera did not answer about its accelerators.`,"device-unknown":`The node does not list the accelerator this camera detects on — asking another one would propose with a different model.`,"step-unknown":`That node carries no object-detection step in its catalog.`,"no-model":`No object-detection model on that accelerator can be resolved for this camera.`};function Oi(){let[t,n]=l(null),[i,o]=l(null),[c,f]=l([]),[p,m]=l(-1),[h,g]=l(new Map),[_,v]=l(null),y=je({projection:`slim`,isCamera:!0}),b=a(()=>{let e=new Map;for(let t of y.data??[])e.set(t.id,t.name);return e},[y.data]),C=oe({}),w=Ae({trackId:t?.trackId??``},{enabled:t!==null}),T=ve({trackId:t?.trackId??``},{enabled:t!==null}),E=xe({frameId:i??``},{enabled:i!==null}),ee=H(),D=x(),O=Ce(),k=fe(),A=ne(),j=S({deviceIds:t===null?[]:[t.deviceId]},{enabled:t!==null,staleTime:3e4}),M=j.data?.[0]?.detection?.nodeId??null,N=F({nodeId:M??``},{enabled:M!==null,staleTime:3e4}),P=Fe({nodeId:M??``},{enabled:M!==null,staleTime:3e4}),I=V({deviceId:t?.deviceId??0},{enabled:t!==null,staleTime:3e4}),L=a(()=>Ti({status:j.data?.[0],nodeDevices:N.data,schema:P.data,resolvedSteps:I.data?.steps}),[j.data,N.data,P.data,I.data]);d(()=>{if(i===null){f([]);return}f((T.data??[]).filter(e=>e.mediaKey===i).map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},...e.subLabel===void 0?{}:{subLabel:e.subLabel},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))),m(-1)},[i,T.data]),d(()=>{let e=w.data?.copies??[];i===null&&e.length>0&&o(e[0].frameId)},[w.data,i]);let R=e(e=>{n(e),o(null),f([]),g(new Map),v(null)},[]),z=e(async e=>{if(t===null)return;let n=await ee.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,mediaIds:[e]});if(n.refused.length>0){let e=new Map(h);for(let t of n.refused)e.set(t.sourceMediaId,t.reason);g(e)}n.copied.length>0&&o(n.copied[0].frameId),await w.refetch(),await C.refetch()},[t,ee,h,w,C]),B=e(async e=>{t!==null&&(await D.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:e}),i===e&&o(null),await w.refetch(),await T.refetch(),await C.refetch())},[t,D,i,w,T,C]),te=e(async e=>{if(t===null||i===null)return;if(v(null),L.kind!==`resolved`){v(Di[L.gap]);return}let n=await O.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:i,subject:e===`package`?{kind:`package`}:{kind:`objects`,modelId:L.modelId,minScore:L.minScore},nodeId:L.nodeId});if(n.kind===`refused`){v(n.reason===`no-zone`?`A package proposal runs on the zone crop only — this camera has no zone, and running the detector on the whole frame at 0.35 proposes furniture.`:`The pipeline refused: ${n.reason}${n.detail===void 0?``:` — ${n.detail}`}`);return}f(e=>[...e,...n.proposals.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))]),v(`${n.proposals.length} proposal${n.proposals.length===1?``:`s`} from ${n.modelId}`+(n.belowThreshold>0?` — ${n.belowThreshold} more were below ${n.minScore.toFixed(2)}`:``))},[t,i,O,L]),U=e(e=>{f(t=>[...t,{bbox:e,macroClass:Ei,kind:`subject`,source:`operator`}]),m(c.length)},[c.length]),re=e((e,t)=>{f(n=>n.map((n,r)=>r===e?{...n,...t}:n))},[]),ie=e(e=>{f(t=>t.filter((t,n)=>n!==e)),m(-1)},[]),W=e(async()=>{t===null||i===null||(await k.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:i,annotations:c.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label!==void 0&&e.label!==``?{label:e.label}:{},...e.subLabel!==void 0&&e.subLabel!==``?{subLabel:e.subLabel}:{},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))}),await T.refetch(),await C.refetch(),v(`Annotations saved.`))},[t,i,c,k,T,C]),ae=e(async()=>{if(t===null)return;let e=await A.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});v(e.changed?`Track completed — it is now trained, and its own media is evictable again.`:e.reason===`no-frames-copied`?`Refused: no frame was ever copied into the dataset. Completing would let retention delete material nothing was extracted from.`:`Refused: ${e.reason??`unknown`}`),await C.refetch(),e.changed&&n(null)},[t,A,C]),se=E.data,ce=oi(c)&&i!==null;return r(Ve,{subtitle:`Turn the tracks you marked for training into an annotated dataset. Selecting a frame copies it — the dataset never depends on media that can be swept.`,actions:t===null?null:r(G,{size:`sm`,onClick:()=>void ae(),children:[u(lt,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Complete track`})]}),children:[_!==null&&u(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-xs text-foreground`,children:_}),u(hi,{}),r(`div`,{className:`grid grid-cols-1 lg:grid-cols-[minmax(0,260px)_minmax(0,1fr)] gap-4`,children:[r(`aside`,{className:`rounded-md border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-3 py-2 border-b border-border flex items-center justify-between`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Staging`}),u(q,{children:C.data?.length??0})]}),u(xi,{tracks:C.data??[],isLoading:C.isLoading,selectedTrackId:t?.trackId??null,deviceNames:b,onSelect:R})]}),u(`section`,{className:`space-y-3 min-w-0`,children:t===null?u(`p`,{className:`text-xs text-foreground-subtle`,children:`Pick a track from the staging list to start annotating it.`}):r(s,{children:[u(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:u(_i,{candidates:w.data?.candidates??[],copies:w.data?.copies??[],activeFrameId:i,refusals:h,isSelecting:ee.isPending,onSelectCandidate:e=>void z(e),onOpenCopy:o,onRemoveCopy:e=>void B(e)})}),i!==null&&r(`div`,{className:`grid grid-cols-1 xl:grid-cols-[minmax(0,1fr)_minmax(0,380px)] gap-3`,children:[u(`div`,{className:`rounded-md border border-border overflow-hidden`,children:se===void 0?r(`div`,{className:`flex items-center gap-2 p-6 text-xs text-foreground-subtle`,children:[u(K,{className:`h-3.5 w-3.5 animate-spin`}),`Loading the frame…`]}):u(mi,{imageSrc:`data:image/jpeg;base64,${se.base64}`,imageWidth:se.width,imageHeight:se.height,boxes:c,selectedIndex:p,onSelect:m,onDraw:U})}),r(`div`,{className:`rounded-md border border-border bg-surface flex flex-col min-h-0`,children:[r(`div`,{className:`px-3 py-2 border-b border-border flex items-center gap-2`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Subjects`}),r(G,{variant:`secondary`,size:`sm`,disabled:O.isPending||L.kind!==`resolved`,onClick:()=>void te(`objects`),children:[u(de,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Propose`})]}),r(G,{variant:`secondary`,size:`sm`,disabled:O.isPending||L.kind!==`resolved`,onClick:()=>void te(`package`),children:[u(de,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Packages`})]})]}),u(`div`,{className:`px-3 py-1 border-b border-border text-[11px] text-foreground-subtle`,children:L.kind===`resolved`?`Proposals come from ${L.modelId} at ${L.minScore.toFixed(2)}, on ${L.nodeId} — what this camera really runs.`:Di[L.gap]}),u(`div`,{className:`flex-1 overflow-y-auto`,children:u(ai,{annotations:c,selectedIndex:p,onSelect:m,onChange:re,onDelete:ie})}),r(`div`,{className:`px-3 py-2 border-t border-border flex items-center justify-between`,children:[r(`span`,{className:`text-[11px] text-foreground-subtle`,children:[c.filter(e=>e.kind===`model_error`).length,` marked as model errors`]}),u(G,{size:`sm`,disabled:!ce||k.isPending,onClick:()=>void W(),children:`Save frame`})]})]})]})]})})]})]})}function ki(){return u(`div`,{className:`flex flex-col p-4`,children:u(it,{tabs:[{id:`feed`,label:`Feed`,icon:W,content:u(ti,{})},{id:`retrain`,label:`Retrain`,icon:lt,content:u(Oi,{})},{id:`debug`,label:`Debug`,icon:B,content:u(Or,{})}]})})}export{ki as EventsPage};
|