@camstack/addon-admin-ui 1.2.353 → 1.2.355
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/Addons-Bzf-UqEw.js +4 -0
- package/dist/assets/{AdminTabs-D2EUE5A0.js → AdminTabs-jmzYA4Gj.js} +1 -1
- package/dist/assets/AiProfiles-DDUitYj8.js +3 -0
- package/dist/assets/{BrokerForm-jvEIkwfE.js → BrokerForm-Cv_WPhvt.js} +1 -1
- package/dist/assets/Build-3A9gyeeL.js +40 -0
- package/dist/assets/{Calendars-BCpPE1jT.js → Calendars-MFMnXqjT.js} +1 -1
- package/dist/assets/{Capabilities-WsxtQm6G.js → Capabilities-BzcFdoxe.js} +1 -1
- package/dist/assets/Cluster-B8MOp6Pr.js +11 -0
- package/dist/assets/ClusterStepModel-DCIodYpM.js +1 -0
- package/dist/assets/CompositionEditor-C9f51ycE.js +1 -0
- package/dist/assets/{CompositionEditorPage-DN1jwFte.js → CompositionEditorPage-GhqEH8fu.js} +1 -1
- package/dist/assets/Data-DW-C0JmT.js +1 -0
- package/dist/assets/DetectionIntelligence-CrH_kLX1.js +1 -0
- package/dist/assets/DeviceDetail-CDOw1qyD.js +2 -0
- package/dist/assets/{DeviceDoActionFields-C9efvuLy.js → DeviceDoActionFields-DTRBrGeQ.js} +1 -1
- package/dist/assets/{Devices-uRSR1KF9.js → Devices-urEV4IEL.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-B0M5LCl6.js → EmbedPlayerPage-RP6PYmQ3.js} +1 -1
- package/dist/assets/Events-zS0-6Rd3.js +1 -0
- package/dist/assets/Identity-Dqul-DNR.js +1 -0
- package/dist/assets/IntegrationDetail-wBX3nT_i.js +1 -0
- package/dist/assets/IntegrationHub-3NtGsJ8f.js +1 -0
- package/dist/assets/Integrations-BAPCCTL_.js +1 -0
- package/dist/assets/Integrations-EkMwKxz0.js +1 -0
- package/dist/assets/Locations-CLBXHuE9.js +3 -0
- package/dist/assets/{Logs-BdD9ktZ1.js → Logs-BwMwasxy.js} +1 -1
- package/dist/assets/{MotionZonesSettings-BMZDT9aS.js → MotionZonesSettings--ZP6wq8p.js} +1 -1
- package/dist/assets/MyAccess-DRVHIYEW.js +2 -0
- package/dist/assets/Network-vx7gg32u.js +1 -0
- package/dist/assets/NodeAddonsSettingsPanel-BbRT6OqB.js +1 -0
- package/dist/assets/Notifications-DlINBoX1.js +1 -0
- package/dist/assets/Plates-D82UR8AW.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-e1shTFq0.js → PrivacyMaskSettings-UJpZQuWF.js} +1 -1
- package/dist/assets/Recordings-C9JJ_i3X.js +1 -0
- package/dist/assets/ScanNetworkModal-Dq6vPLgX.js +1 -0
- package/dist/assets/{SceneMonitorEditor-B8SaYaRg.js → SceneMonitorEditor-CwTxeG1H.js} +1 -1
- package/dist/assets/{Scenes-UX3CQiSD.js → Scenes-BxWxF9RG.js} +1 -1
- package/dist/assets/Secrets-B1Py-XlE.js +1 -0
- package/dist/assets/{Settings-hvJAx444.js → Settings-D3l2szna.js} +1 -1
- package/dist/assets/{Showroom-DGF0GI0t.js → Showroom-DCK8-7b8.js} +1 -1
- package/dist/assets/{Terminal-CnAgipZG.js → Terminal-C2SFvaOH.js} +3 -3
- package/dist/assets/{Viewer-u429VTlj.js → Viewer-qJaACnXs.js} +1 -1
- package/dist/assets/{__vite-browser-external-Cc3gW-QT.js → __vite-browser-external-DF8Eb0aa.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Dmoq9iz_.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-4FAaqbgl.js} +1 -1
- package/dist/assets/{archive-DEGN5b-2.js → archive-C9jrGy5Q.js} +1 -1
- package/dist/assets/{authed-media-zoQQL-DU.js → authed-media-DQAkskU5.js} +1 -1
- package/dist/assets/{boxes-D53xb3mF.js → boxes-BNIPhLCT.js} +1 -1
- package/dist/assets/circle-slash-BYpk_wjd.js +1 -0
- package/dist/assets/client-HDm3z1QL.js +357 -0
- package/dist/assets/crop-9g1Z5sFT.js +1 -0
- package/dist/assets/{debounced-invalidate-Di49k3Ur.js → debounced-invalidate-COhAlfWE.js} +1 -1
- package/dist/assets/{device-integration-icon-C44r3pOz.js → device-integration-icon-KaXkp2LK.js} +1 -1
- package/dist/assets/device-picker-model-D_5ynS9o.js +1 -0
- package/dist/assets/dist-DPdG1Rf2.js +357 -0
- package/dist/assets/{dist-CupCPVu2.js → dist-YROsaxnC.js} +1 -1
- package/dist/assets/{face-bbox-BekWkYM8.js → face-bbox-CFdWEIAo.js} +1 -1
- package/dist/assets/{hard-drive-download-CaBI4JJt.js → hard-drive-download-D11tb7sM.js} +1 -1
- package/dist/assets/{hostInit-LeZtjcV4.js → hostInit-C1Zchdpp.js} +1 -1
- package/dist/assets/index-B-nNtYMr.css +2 -0
- package/dist/assets/index-d2QAhmc-.js +4 -0
- package/dist/assets/{layers-Bl4GXnaV.js → layers-DYdFVal1.js} +1 -1
- package/dist/assets/{location-owned-usage-B2EH12kQ.js → location-owned-usage-DJjVpEH8.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-f71236c8.js → mf-entry-bootstrap-0-164529ae.js} +2 -2
- package/dist/assets/mount-D_5ynS9o.js +1 -0
- package/dist/assets/notification-schedule-field-C3V8Yo1S.js +1 -0
- package/dist/assets/{player-overlays-CHWCYkGf.js → player-overlays-tKtUzh3g.js} +1 -1
- package/dist/assets/remoteEntry-8SJYH9n-.js +1 -0
- package/dist/assets/{send-BxCvGnMf.js → send-C3mZ85mq.js} +1 -1
- package/dist/assets/{settings-2-CWTgzyTw.js → settings-2-CCI879zJ.js} +1 -1
- package/dist/assets/src-Y4G_LfLc.js +67 -0
- package/dist/assets/unlink-m4c0iz87.js +1 -0
- package/dist/assets/{use-scenes-feed-CsZwOmyp.js → use-scenes-feed-DyIyOk7m.js} +1 -1
- package/dist/assets/{use-stationary-objects-DTKCTzni.js → use-stationary-objects-DqQJT1ff.js} +1 -1
- package/dist/assets/useEventInvalidation-D_5ynS9o.js +1 -0
- package/dist/assets/{useNodeUrlSelection-BSYJnQKG.js → useNodeUrlSelection-CEK0v_3k.js} +1 -1
- package/dist/assets/user-round-BGmDt-wq.js +1 -0
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-mzuJ2veF.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-B0TfzpP_.js} +2 -2
- package/dist/index.html +9 -9
- package/dist/server/addon.js +1963 -60
- package/package.json +1 -1
- package/dist/assets/Addons-CSSlxmKX.js +0 -4
- package/dist/assets/AiProfiles-ZTs3hQfG.js +0 -3
- package/dist/assets/Build-D-cQZg2g.js +0 -40
- package/dist/assets/Cluster-BZpFTXoQ.js +0 -11
- package/dist/assets/ClusterStepModel-Hz5Uy3Lc.js +0 -1
- package/dist/assets/CompositionEditor-DlXjZmuS.js +0 -1
- package/dist/assets/Data-BiwkrKto.js +0 -1
- package/dist/assets/DetectionIntelligence-C_6PVnNp.js +0 -1
- package/dist/assets/DeviceDetail-Dd16eq5_.js +0 -2
- package/dist/assets/Events-BqYGW97U.js +0 -1
- package/dist/assets/Identity-CwF15mWM.js +0 -1
- package/dist/assets/IntegrationDetail-KiizjQky.js +0 -1
- package/dist/assets/IntegrationHub-CtZ9pFUl.js +0 -1
- package/dist/assets/Integrations-5D0W0NO_.js +0 -1
- package/dist/assets/Integrations-8JethkBu.js +0 -1
- package/dist/assets/Locations-C0VGgBDh.js +0 -3
- package/dist/assets/MyAccess-VT-IYS_0.js +0 -2
- package/dist/assets/Network-DAS4ofeO.js +0 -1
- package/dist/assets/NodeAddonsSettingsPanel-2ImNi4l_.js +0 -1
- package/dist/assets/Notifications-CtpsBCVg.js +0 -1
- package/dist/assets/Plates-DRYDfqhl.js +0 -1
- package/dist/assets/Recordings-Cp1t8Lsr.js +0 -1
- package/dist/assets/ScanNetworkModal-CtcUY86A.js +0 -1
- package/dist/assets/circle-slash-g5R19IPN.js +0 -1
- package/dist/assets/client-CxHFB-xR.js +0 -357
- package/dist/assets/crop-DTBzwOc0.js +0 -1
- package/dist/assets/device-picker-model-Y21yLCDr.js +0 -1
- package/dist/assets/dist-B_y7Xf3Y.js +0 -357
- package/dist/assets/index-BdYsVZMw.js +0 -4
- package/dist/assets/index-CFkS00_M.css +0 -2
- package/dist/assets/mount-Y21yLCDr.js +0 -1
- package/dist/assets/notification-schedule-field-CX_ISfhK.js +0 -1
- package/dist/assets/remoteEntry-D2L5CI92.js +0 -1
- package/dist/assets/src-Crb8RLzq.js +0 -67
- package/dist/assets/useEventInvalidation-Y21yLCDr.js +0 -1
- package/dist/assets/user-round-BR8uDCSh.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
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,at as m,ct as h,ft as g,gt as _,ht as v,st as y,vt as b}from"./player-overlays-tKtUzh3g.js";import{$d as x,$n as S,$o as C,$t as w,Ad as T,An as E,As as D,Bd as O,Bt as k,Cn as A,Dn as j,Ds as M,Dt as N,En as P,Es as F,Fn as I,Gt as L,Hd as R,Hs as ee,Ht as z,Hu as B,Id as V,In as H,Jn as U,Kd as te,Kn as ne,Kt as W,Lo as G,Mu as re,Nn as K,Os as ie,Qo as ae,Ss as oe,Tn as se,Ts as ce,Ut as le,Uu as ue,Wt as de,Xt as fe,Yt as pe,Zt as me,_s as he,_u as ge,at as _e,bn as q,bs as ve,cs as ye,df as be,ds as xe,er as Se,es as Ce,eu as we,fs as Te,gf as Ee,gs as De,gu as Oe,hs as ke,ic as Ae,is as je,jf as Me,js as Ne,kd as Pe,ks as Fe,ls as Ie,ms as Le,mu as Re,ns as ze,of as Be,on as Ve,os as He,qn as Ue,qs as We,rd as Ge,rf as Ke,rs as qe,sa as Je,sn as Ye,ss as Xe,tr as J,tu as Ze,ud as Qe,us as $e,vd as et,vs as tt,wn as nt,wr as rt,ws as it,xn as at,xs as ot,yf as st,yn as ct,ys as lt,yu as ut,zf as dt,zu as ft}from"./src-Y4G_LfLc.js";import{a as pt,c as mt,d as ht,f as gt,i as _t,m as vt,n as yt,o as bt,p as xt,r as St,s as Ct,t as wt}from"./debounced-invalidate-COhAlfWE.js";import{Un as Tt,pi as Et}from"./client-HDm3z1QL.js";import{t as Dt}from"./useTranslation-Bc5yH9V9.js";import"./mount-D_5ynS9o.js";import{et as Ot}from"./index-d2QAhmc-.js";import{t as kt}from"./AdminPage-BSFohA3i.js";import{a as At,i as jt,r as Mt,t as Nt}from"./authed-media-DQAkskU5.js";import{t as Pt}from"./use-stationary-objects-DqQJT1ff.js";import{t as Ft}from"./AdminTabs-jmzYA4Gj.js";import{t as It}from"./format-size-DIxKXxtj.js";var Lt=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`}]]),Rt=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`}]]),zt=b(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),Bt=b(`copy-plus`,[[`line`,{x1:`15`,x2:`15`,y1:`12`,y2:`18`,key:`1p7wdc`}],[`line`,{x1:`12`,x2:`18`,y1:`15`,y2:`15`,key:`1nscbv`}],[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),Vt=b(`folder-plus`,[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),Ht=b(`keyboard`,[[`path`,{d:`M10 8h.01`,key:`1r9ogq`}],[`path`,{d:`M12 12h.01`,key:`1mp3jc`}],[`path`,{d:`M14 8h.01`,key:`1primd`}],[`path`,{d:`M16 12h.01`,key:`1l6xoz`}],[`path`,{d:`M18 8h.01`,key:`emo2bl`}],[`path`,{d:`M6 8h.01`,key:`x9i8wu`}],[`path`,{d:`M7 16h10`,key:`wp8him`}],[`path`,{d:`M8 12h.01`,key:`czm47f`}],[`rect`,{width:`20`,height:`16`,x:`2`,y:`4`,rx:`2`,key:`18n3k1`}]]),Ut=b(`list-video`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M10 12H3`,key:`1ulcyk`}],[`path`,{d:`M10 19H3`,key:`108z41`}],[`path`,{d:`M15 12.003a1 1 0 0 1 1.517-.859l4.997 2.997a1 1 0 0 1 0 1.718l-4.997 2.997a1 1 0 0 1-1.517-.86z`,key:`ms4nik`}]]),Wt=b(`maximize`,[[`path`,{d:`M8 3H5a2 2 0 0 0-2 2v3`,key:`1dcmit`}],[`path`,{d:`M21 8V5a2 2 0 0 0-2-2h-3`,key:`1e4gt3`}],[`path`,{d:`M3 16v3a2 2 0 0 0 2 2h3`,key:`wsl5sc`}],[`path`,{d:`M16 21h3a2 2 0 0 0 2-2v-3`,key:`18trek`}]]),Gt=b(`redo-2`,[[`path`,{d:`m15 14 5-5-5-5`,key:`12vg1m`}],[`path`,{d:`M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13`,key:`6uklza`}]]),Kt=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`}]]),qt=b(`wand-sparkles`,[[`path`,{d:`m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72`,key:`ul74o6`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`M5 6v4`,key:`ilb8ba`}],[`path`,{d:`M19 14v4`,key:`blhpug`}],[`path`,{d:`M10 2v2`,key:`7u0qdc`}],[`path`,{d:`M7 8H3`,key:`zfb6yr`}],[`path`,{d:`M21 16h-4`,key:`1cnmox`}],[`path`,{d:`M11 3H9`,key:`1obp7u`}]]);n();function Jt(e){let t=e.subLabel??e.label;if(t!==void 0)return t;let n=e.audioLabels?.[0]?.label;return n!==void 0&&n.length>0?n:void 0}var Yt=720*60*60*1e3;function Xt(e){let t=[];for(let n of e)t.push(...n);return t}function Zt(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function Qt(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 $t(e,t){return`${String(e)}:${t}`}function en(e,t){let n=new Map,r=new Set;for(let i of e){let e=$t(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 tn(e,t){return{since:e.fromMs??t-Yt,until:e.toMs??t}}var nn=[`native`,`raster`,`standin`];function rn(e){return nn.some(t=>t===e)}var an={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 on(e){return e===`standin`?an.standin:e===`raster`?an.raster:null}var sn={"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 cn(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:sn[r]??r,detail:i,raw:t}}function ln(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 un({row:e,cameraName:t,nowMs:n,onOpenDetail:i,selected:a=!1,onToggleSelect:o,score:s,provenance:c,footer:l}){let d=At(e.mediaId===void 0?jt(`track`,e.trackId):Mt(e.mediaId)),f=Math.round(e.importance*100),p=s===void 0?void 0:Math.round(s*100),m=ln(e.windowMs),_=()=>i(e),v=on(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:_,className:`h-full w-full cursor-zoom-in object-cover`}):u(`button`,{type:`button`,onClick:_,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(g,{className:`h-6 w-6 opacity-60`})}),o&&u(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o($t(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(vt,{className:`h-4 w-4 text-primary`}):u(h,{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(R,{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(st,{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(B,{className:`h-3 w-3`})})]})]}),r(`button`,{type:`button`,onClick:_,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,Jt(e)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,Jt(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:gt(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 dn=1400,fn=`Admin-gated URL — opens only inside an authenticated session`;function pn({label:t,value:n,title:i}){let[a,o]=l(!1),s=U();return d(()=>{if(!a)return;let e=setTimeout(()=>o(!1),dn);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?Ee:Ke,{className:`h-2.5 w-2.5 shrink-0`}),u(`span`,{className:`truncate`,children:a?`Copied`:t})]})}function mn({localUrl:e,publicUrl:t}){return r(`div`,{className:`flex flex-wrap gap-1`,children:[u(pn,{label:`Local`,value:e,title:`Copy LAN URL — ${fn}`}),t&&u(pn,{label:`Public`,value:t,title:`Copy public URL — ${fn}`})]})}var hn={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 gn(e){return e in hn}function _n(e){return gn(e)?hn[e]:e}function vn(e,t){return`${e}${t}`}n();var yn=3e4;function bn(t){let[n,r]=l(null),i=e(e=>{r(t=>t??e)},[]);return d(()=>{t||r(null)},[t]),{publicOrigin:n,probes:t?u(xn,{onOrigin:i}):null}}function xn({onOrigin:e}){let{data:t}=rt({capName:`network-access`});return u(s,{children:(t??[]).map(t=>u(Sn,{addonId:t.addonId,onOrigin:e},t.addonId))})}function Sn({addonId:e,onOrigin:t}){let{data:n}=G({addonId:e},{refetchInterval:yn,retry:!1});return d(()=>{let e=n?Tt.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 Cn=typeof D==`function`,wn=`Track flags arrive with the next server update`;function Tn(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var En=Cn?D:Tn;function Dn(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 On({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 kn({deviceId:e,trackId:t,markForTrain:n,debug:i,favourited:a,onChange:o}){let s=En(),c=ne(),[d,f]=l(null),p=d?.markForTrain??n===!0,m=d?.debug??i===!0,h=d?.favourited??a===!0,g=!Cn||s.isPending,_=Cn?void 0:wn,v=n=>{g||(async()=>{try{let r=Dn(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(On,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:p,disabled:g,..._===void 0?{}:{title:_},icon:u(R,{className:`h-4 w-4`}),onToggle:()=>v({markForTrain:!p})}),u(On,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:m,disabled:g,..._===void 0?{}:{title:_},icon:u(st,{className:`h-4 w-4`}),onToggle:()=>v({debug:!m})}),u(On,{label:`Favourited`,hint:`Keeps this track and its media past retention`,checked:h,disabled:g,..._===void 0?{}:{title:_},icon:u(B,{className:`h-4 w-4`}),onToggle:()=>v({favourited:!h})})]})}var An=100,jn=120,Mn={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Y=e=>e<0?0:e>1?1:e,Nn=e=>Math.round(e*100)/100;function Pn(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 Fn(e,t,n){if(e.length===0||t===null)return Mn;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return Mn;let a=Pn(e,n?.maxPoints??jn).map(e=>({x:Nn(Y(e.x/r)*An),y:Nn(Y(e.y/i)*An)})),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:Nn(Y(e.x/r)*An),y:Nn(Y(e.y/i)*An),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:Nn(Y(u.bbox.x/r)*An),y:Nn(Y(u.bbox.y/i)*An),w:Nn(Y(u.bbox.w/r)*An),h:Nn(Y(u.bbox.h/i)*An)}:null}}var In=typeof qe==`function`,Ln=`Track deletion arrives with the next server update`;function Rn(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var zn=In?qe:Rn;n();var Bn=15e3,Vn=f();function Hn({url:e,label:t}){let{src:n,failed:r}=At(e);return n===null?u(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?u(g,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):u(T,{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 Un=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),Wn=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`,`sceneFrame`,`lastSceneFrame`]);function Gn(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 Kn({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 qn({row:t,cameraName:n,deleteAvailable:i,onClose:o,onDeleted:c,onFlagsChanged:f}){let p=m(),h=ne(),_=Ue(),v=zn(),b=t!==null,x=t?.deviceId??0,S=t?.trackId??``,C=t?.timestamp??0,w=t?.windowMs??0,{data:E}=ye({deviceId:x,trackId:S},{enabled:b}),{data:D}=ve({trackId:S,deviceId:x},{enabled:b}),O=E?.bestEventId===void 0?void 0:Number(E.bestEventId),{data:k}=Te({ownerType:`object`,eventId:O??0,deviceId:x},{enabled:b&&O!==void 0&&Number.isFinite(O)}),{data:j}=Ze({deviceId:x},{enabled:b}),M=(j??[]).find(e=>e.addonId!==void 0)?.addonId,{data:N}=we({deviceId:x,since:C-Bn,until:C+w+Bn,provider:M??``},{enabled:b&&M!==void 0}),[P,F]=l(null),[I,L]=l(!1),{publicOrigin:R,probes:ee}=bn(b);d(()=>{F(null)},[x,S]);let z=a(()=>{let e=D??[],t=k??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[D,k]),B=P??z,V=At(B?B.url:void 0),U=a(()=>{let e=new Set,t=[];for(let n of[...k??[],...D??[]])e.has(n.mediaId)||(e.add(n.mediaId),t.push(n));return t},[k,D]),W=a(()=>U.find(e=>Un.has(e.kind))??null,[U]),G=Gn(At(W?W.url:void 0).src),re=a(()=>Fn(E?.positions??[],G,{snapshots:(E?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaId:e.mediaId}))}),[E?.positions,E?.snapshots,G]),K=e(e=>{let t=U.find(t=>t.mediaId===e);t&&F(t)},[U]);if(t===null)return null;let ie=V.src,ae=B?.kind,oe=ae!==void 0&&Wn.has(ae)&&G!==null&&(E?.positions.length??0)>=2,se=N&&N.length>0?N[0]:null,ce=()=>{se&&(L(!0),(async()=>{try{let e=await p.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:se.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{h({title:`Clip unavailable`,message:`Could not resolve clip playback. Check the server logs.`,variant:`warning`})}finally{L(!1)}})())},le=()=>{!i||v.isPending||(async()=>{if(await _({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 h({title:`Delete failed`,message:`Failed to delete this track. Check the server logs.`,variant:`danger`})}})()},ue=Math.round(t.importance*100),de=E?.importanceReason?`${String(ue)}% · ${E.importanceReason}`:`${String(ue)}%`,fe=E?.zonesVisited&&E.zonesVisited.length>0?E.zonesVisited.join(`, `):`—`,pe=E?.audioLabels&&E.audioLabels.length>0?E.audioLabels:t.audioLabels&&t.audioLabels.length>0?t.audioLabels:void 0,me=pe===void 0?`—`:pe.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `),he=E?E.totalDistance.toFixed(2):`—`,ge=cn(E?.previewMissReason),_e=xt(E?E.firstSeen:C),q=E?xt(E.lastSeen):`—`;return u(at,{open:!0,onOpenChange:e=>!e&&o(),children:r(A,{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,Jt(t)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,Jt(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(ut,{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:[ie?u(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:u(yt,{src:ie,alt:`Key frame from ${n}`,fit:`natural`,className:`w-full`,overlay:oe?u(Kn,{overlay:re,onPickSnapshot:K}):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:V.failed?r(s,{children:[u(g,{className:`h-8 w-8 opacity-60`}),u(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):u(T,{className:`h-6 w-6 animate-spin opacity-70`})}),U.length>0&&u(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:U.map(e=>{let t=_n(e.kind),n=vn(Vn,e.url),i=R?vn(R,e.url):null;return r(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[u(`button`,{type:`button`,onClick:()=>F(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${t} · ${xt(e.timestamp)}`,children:u(Hn,{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:xt(e.timestamp),children:ht(e.timestamp)})]}),u(mn,{localUrl:n,publicUrl:i})]},e.mediaId)})}),ee,se&&r(H,{variant:`secondary`,onClick:ce,disabled:I,children:[I?u(T,{className:`h-3.5 w-3.5 animate-spin`}):u(te,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),u(kn,{deviceId:t.deviceId,trackId:t.trackId,...(E?.markForTrain??t.markForTrain)===void 0?{}:{markForTrain:E?.markForTrain??t.markForTrain},...(E?.debug??t.debug)===void 0?{}:{debug:E?.debug??t.debug},...(E?.favourited??t.favourited)===void 0?{}:{favourited:E?.favourited??t.favourited},onChange:f}),ge!==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:ge.sentence}),u(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:ge.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:de}),u(X,{label:`Zones visited`,value:fe}),u(X,{label:`Audio heard`,value:me}),u(X,{label:`Total distance`,value:he}),u(X,{label:`First seen`,value:_e}),u(X,{label:`Last seen`,value:q}),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:Ln,children:r(H,{variant:`secondary`,onClick:le,disabled:!i||v.isPending,children:[v.isPending?u(T,{className:`h-3.5 w-3.5 animate-spin`}):u(y,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}var Jn={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`},Yn={setRelation:`debug.gt.setRelation`,setPurity:`debug.gt.setPurity`,list:`debug.gt.list`},Xn=p(`/addon/pipeline-analytics/tape-export`),Zn=10*6e4;function Qn(e){return`${Xn}?tapeId=${encodeURIComponent(e)}`}var $n=`The server answered in a shape this build does not understand.`;function er(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 tr(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 nr(e,t){let n=e[t];return typeof n==`boolean`?n:null}function rr(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 ir(e){return e===`off`||e===`recording`||e===`refused`||e===`failing`||e===`unknown`}function ar(e){if(!Z(e))return null;let t=Q(e,`deviceId`),n=e.state,r=Q(e,`gapsSinceArmed`),i=tr(e,`segmentsHeld`),a=tr(e,`bytesLastHour`),o=tr(e,`bytesHeld`);if(t===null||!ir(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 or(e){return Z(e)?rr(e.cameras,ar):null}function sr(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=nr(e,`reviewed`),f=nr(e,`released`),p=rr(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 cr(e){return Z(e)?rr(e.tapes,sr):null}function lr(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=nr(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 ur(e){if(!Z(e))return null;let t=$(e,`tapeId`),n=Q(e,`deviceId`),r=Q(e,`fromMs`),i=Q(e,`toMs`),a=nr(e,`reviewed`),o=rr(e.lanes,lr);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 dr(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 fr(e){if(!Z(e))return null;let t=e.status;if(t===`released`){let n=Q(e,`unpinned`),r=nr(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 pr(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 mr(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 hr(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 gr(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 _r(e){if(!Z(e))return null;let t=rr(e.relations,hr),n=rr(e.purities,gr),r=nr(e,`truncated`);return t===null||n===null||r===null?null:{relations:t,purities:n,truncated:r}}function vr(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 yr(e){return e.filter(e=>e.segmentsHeld===null||e.segmentsHeld>0).map(e=>({deviceId:e.deviceId,segmentsUnknown:e.segmentsHeld===null}))}function br(e){return e.slice(1).map((t,n)=>({trackId:e[n]??t,otherTrackId:t}))}function xr(e){return e.flatMap((t,n)=>e.slice(n+1).map(e=>({trackId:t,otherTrackId:e})))}function Sr(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 Cr(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 wr={"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 Tr(e,t){let n=wr[e]??`Refused (${e}).`;return t.length>0?`${n} ${t}`:n}function Er(e){if(e.length===0)return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null}function Dr(e){return e<1024*1024?`${(e/1024).toFixed(0)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function Or(e){return e===null?`unknown`:Dr(e)}function kr(e){return e===null?`unknown`:String(e)}function Ar(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 jr({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=Er(o),s=Er(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=dr(await t(Jn.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($n):e.ok?(x(`Promoted ${e.tapeId}: ${String(e.frames)} frames, ${Dr(e.bytes)}, ${String(e.pinnedTracks)} tracks pinned`+(e.state===`incomplete`?` — incomplete (it has gaps) and cannot become a case.`:`.`)),n()):x(Tr(e.reason,e.detail))}catch(e){x(er(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(I,{value:i,options:[...e],onChange:e=>a(e.target.value),"aria-label":`Camera`})}),u(q,{type:`datetime-local`,"aria-label":`From`,value:o,onChange:e=>s(e.target.value),className:`w-48`}),u(q,{type:`datetime-local`,"aria-label":`To`,value:c,onChange:e=>d(e.target.value),className:`w-48`}),u(q,{"aria-label":`Scenario`,placeholder:`615-door-groups`,value:f,onChange:e=>p(e.target.value),className:`w-44`}),u(q,{"aria-label":`Note`,placeholder:`optional note`,value:m,onChange:e=>h(e.target.value),className:`w-52`}),u(`div`,{className:`w-28`,children:u(I,{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(H,{onClick:()=>void S(),disabled:v||e.length===0,children:[v?u(T,{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 Mr=`pipeline-analytics`,Nr=`debug.listTracks`,Pr=`debug.analyze`,Fr=p(`/addon/pipeline-analytics/debug-export`);function Ir(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Lr(e,t){let n=e[t];return typeof n==`string`?n:null}function Rr(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function zr(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Br(e){return e===`error`||e===`warn`||e===`info`}function Vr(e){if(!Ir(e))return null;let t=Lr(e,`code`),n=Lr(e,`detail`),r=e.severity;return t===null||n===null||!Br(r)?null:{code:t,severity:r,detail:n}}function Hr(e){if(!Ir(e))return null;let t=Lr(e,`trackId`),n=Rr(e,`deviceId`),r=Lr(e,`className`),i=Rr(e,`firstSeen`),a=Rr(e,`lastSeen`),o=Rr(e,`durationMs`),s=zr(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=Lr(e,`label`),l=Lr(e,`subLabel`),u=Lr(e,`previewMissReason`),d=zr(e,`markForTrain`),f=zr(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:Rr(e,`importance`)??0,bestEventId:Lr(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function Ur(e){let t=Hr(e);if(t===null||!Ir(e))return null;let n=Rr(e,`mediaCount`),r=Rr(e,`eventCount`),i=Rr(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=Vr(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...rn(l)?{thumbnailProvenance:l}:{}}}function Wr(e){if(!Ir(e))return null;let t=zr(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=Hr(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function Gr(e){if(!Ir(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=Ur(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var Kr={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 qr(e){return Kr[e]??e}var Jr={error:0,warn:1,info:2};function Yr(e){return e.toSorted((e,t)=>Jr[e.severity]-Jr[t.severity]||e.code.localeCompare(t.code))}function Xr(e){return e.length===0?Fr:`${Fr}?deviceIds=${e.join(`,`)}`}function Zr(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 Qr(e,t){return`${String(e)}:${t}`}function $r(e,t){let n=[],r=new Set;for(let i of e){let e=Qr(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 ei({tapeId:e,call:t,onClose:n,onChanged:i}){let a=o({queryKey:[`events-debug`,`tapes`,`tracks`,e],queryFn:async()=>ur(await t(Jn.tracks,{tapeId:e}))}),s=a.data??null,c=o({queryKey:[`events-debug`,`tapes`,`marks`,e],enabled:s!==null,queryFn:async()=>s===null?null:_r(await t(Yn.list,{deviceId:s.deviceId,since:s.fromMs-Zn,until:s.toMs+Zn,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(er(e))}};if(s===null)return a.isLoading?u(`p`,{className:`text-xs`,children:`Loading the tape…`}):u(K,{message:$n});let y=s.deviceId,b=(e,t)=>v(e.map(e=>[Yn.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=>[Yn.setPurity,{deviceId:y,trackId:t,purity:e,...n===void 0?{}:{switchAtMs:Math.round(n)}}]))},S=c.data==null?null:vr(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(H,{disabled:d.length<2,onClick:()=>void b(br(d),`same-subject`),children:`Same subject`}),u(H,{variant:`secondary`,disabled:d.length<2,onClick:()=>void b(xr(d),`different-subjects`),children:`Different subjects`}),u(q,{"aria-label":`Changed at (s from tape start)`,placeholder:`changed at s`,value:p,onChange:e=>m(e.target.value),className:`w-28`}),u(H,{variant:`secondary`,disabled:d.length!==1,onClick:()=>void x(`mixed`),children:`Mixed`}),u(H,{variant:`secondary`,disabled:d.length===0,onClick:()=>void x(`not-a-subject`),children:`Not a subject`}),u(H,{variant:s.reviewed?`secondary`:`primary`,onClick:()=>void v([[Jn.review,{tapeId:s.tapeId,reviewed:!s.reviewed}]]).then(()=>a.refetch()),children:s.reviewed?`Mark not reviewed`:`Mark reviewed`}),u(H,{variant:`ghost`,onClick:n,children:`Close`})]}),h!==null&&u(K,{message:h}),S!==null&&u(K,{variant:`warning`,message:S}),u(`ul`,{className:`space-y-1`,children:s.lanes.toSorted((e,t)=>e.firstT-t.firstT).map(e=>u(ti,{lane:e,marks:c.data===null||c.data===void 0?[]:Sr(e.trackId,c.data),selected:d.includes(e.trackId),onToggle:()=>_(e.trackId)},e.trackId))})]})}function ti({lane:e,marks:t,selected:n,onToggle:i}){let{src:a}=At(e.stillStored?jt(`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:[Zr(e.firstT),` → `,Zr(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(J,{variant:`info`,children:e},e))]})}n();var ni=`camstack_admin_token`;function ri(){let e=m();return(t,n)=>e.trpcClient.addons.custom.mutate({addonId:Mr,action:t,input:n})}async function ii(e,t){let n=localStorage.getItem(ni),r={};n!==null&&(r.Authorization=`Bearer ${n}`);let i=await fetch(Qn(e),{headers:r});if(!i.ok){let e=await i.text().catch(()=>``);throw Error(Ar(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 ai(){let[e,t]=l(!1);return u(Ve,{expanded:e,onExpandedChange:t,header:u(`span`,{className:`text-sm font-medium text-foreground`,children:`Tracking tapes`}),children:u(oi,{})})}function oi(){let e=ri(),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()=>or(await e(Jn.status,{}))}),s=o({queryKey:[`events-debug`,`tapes`,`list`],queryFn:async()=>cr(await e(Jn.list,{}))}),[c,d]=l(null),[f,p]=l(null),m=async e=>{p(null);try{await ii(e.id,`${e.scenario}.tape-bundle.json.gz`)}catch(e){p(er(e))}},h=async t=>{let n=fr(await e(Jn.release,{tapeId:t.id}));if(n===null)throw Error($n);let r=mr(n);if(r!==null)throw Error(r);await s.refetch()},g=async t=>{let n=pr(await e(Jn.remove,{tapeId:t.id}));if(n===null)throw Error($n);let r=mr(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(K,{message:f}),i.isLoading&&u(`p`,{className:`text-xs text-foreground-subtle`,children:`Loading camera status…`}),i.data===null&&u(K,{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(J,{variant:e.state===`recording`?`success`:e.state===`off`?`default`:e.state===`unknown`?`warning`:`danger`,children:Cr(e)})}),u(`td`,{children:e.framesPerMin===void 0?`—`:String(Math.round(e.framesPerMin))}),u(`td`,{title:e.shelfError,children:Or(e.bytesLastHour)}),r(`td`,{title:e.shelfError,children:[kr(e.segmentsHeld),` seg · `,Or(e.bytesHeld)]}),u(`td`,{children:String(e.gapsSinceArmed)})]},e.deviceId))})]}),u(jr,{cameras:yr(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(K,{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(),` · `,Zr(e.toMs-e.fromMs),` `,`· `,e.lighting]}),r(`td`,{children:[u(J,{variant:e.state===`complete`?`success`:`warning`,children:e.state}),` `,e.reviewed&&u(J,{variant:`info`,children:`reviewed`}),` `,e.released&&u(J,{children:`released`})]}),r(`td`,{children:[String(e.tracksStillStored),`/`,String(e.tracks.length),` stored`]}),r(`td`,{className:`space-x-1 text-right`,children:[u(H,{variant:`secondary`,"aria-label":`Review ${e.scenario}`,onClick:()=>d(e.id),children:`Review`}),u(H,{variant:`ghost`,"aria-label":`Download ${e.scenario}`,onClick:()=>void m(e),children:u(x,{className:`h-3.5 w-3.5`})}),u(N,{label:`Release`,icon:Pe,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(N,{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(ei,{tapeId:c,call:e,onClose:()=>d(null),onChanged:()=>void s.refetch()})]})}n();var si=`all`,ci=`The server answered in a shape this build does not understand.`,li={error:`danger`,warn:`warning`,info:`info`};function ui({findings:e}){return e.length===0?u(J,{variant:`success`,children:`no anomaly found`}):u(`div`,{className:`flex flex-wrap gap-1`,children:Yr(e).map(e=>u(J,{variant:li[e.severity],title:e.detail,children:qr(e.code)},e.code))})}function di({track:e,report:t,analyzing:n}){let i=cn(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(ui,{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 fi(){let e=m(),[t,n]=l(si),[i,s]=l(!1),[c,d]=l(null),[f,p]=l(new Set),[h,g]=l(null),[_,v]=l(null),[y,b]=l(null),[S,C]=l([]),w=En(),D=Je({isCamera:!0,projection:`slim`}),O=a(()=>[{value:si,label:`All cameras`},...(D.data??[]).map(e=>({value:String(e.id),label:e.name}))],[D.data]),k=a(()=>{let e=new Map;for(let t of D.data??[])e.set(t.id,t.name);return e},[D.data]),A=e=>k.get(e)??`Camera ${String(e)}`,j=a(()=>t===si?[]:[Number.parseInt(t,10)],[t]),M=o({queryKey:[`events-debug`,`list`,j],queryFn:async()=>Wr(await e.trpcClient.addons.custom.mutate({addonId:Mr,action:Nr,input:j.length===0?{}:{deviceIds:j}}))}),N=a(()=>(M.data?.tracks??[]).map(e=>e.trackId),[M.data]),P=o({queryKey:[`events-debug`,`analyze`,N],enabled:N.length>0,queryFn:async()=>Gr(await e.trpcClient.addons.custom.mutate({addonId:Mr,action:Pr,input:{trackIds:N}}))}),F=a(()=>{let e=new Map;for(let t of P.data?.reports??[])e.set(t.trackId,t);return e},[P.data]),L=M.data?.tracks??[],R=M.data===null||P.data===null,ee=()=>{M.refetch(),P.refetch()},z=e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},V=()=>{p(new Set(L.map(e=>Qr(e.deviceId,e.trackId))))},U=()=>p(new Set),te=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await w.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},ne=e=>{if(!Cn||_!==null)return;let t=$r(L,f);t.length!==0&&(v(e),b(null),(async()=>{let n=await te(e,t);v(null);let r=new Set(n.refused);p(new Set(t.filter(e=>r.has(e.trackId)).map(e=>Qr(e.deviceId,e.trackId)))),e===`analyzed`&&C(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.`),M.refetch()})())},W=()=>{let e=S;e.length===0||_!==null||(v(`analyzed`),b(null),(async()=>{for(let t of e)try{await w.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),C([]),M.refetch()})())},G=async()=>{s(!0),d(null);try{await Nt(Xr(j),`camstack-debug.zip`)}catch(e){d(e instanceof Error?e.message:`Export failed.`)}finally{s(!1)}},ie=_!==null;return u(kt,{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(I,{value:t,options:O,onChange:e=>n(e.target.value)})}),r(H,{variant:`secondary`,onClick:ee,disabled:M.isFetching,children:[M.isFetching?u(T,{className:`h-3.5 w-3.5 animate-spin`}):u(Qe,{className:`h-3.5 w-3.5`}),`Refresh`]}),r(H,{onClick:()=>void G(),disabled:i||L.length===0,children:[i?u(T,{className:`h-3.5 w-3.5 animate-spin`}):u(x,{className:`h-3.5 w-3.5`}),`Export all (`,String(L.length),`)`]}),L.length>0&&f.size<L.length&&u(H,{variant:`ghost`,onClick:V,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(ai,{}),M.isError&&u(K,{message:`Could not load the marked tracks.`}),R&&!M.isError&&u(K,{message:ci}),c!==null&&u(K,{message:c}),y!==null&&u(K,{message:y}),M.data?.truncated===!0&&u(K,{message:`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`}),(P.data?.vanished.length??0)>0&&r(`p`,{className:`text-xs text-foreground-subtle`,children:[String(P.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:Cn?void 0:`Track flags arrive with the next server update`,children:r(H,{variant:`secondary`,onClick:()=>ne(`keep`),disabled:!Cn||ie,children:[_===`keep`?u(T,{className:`h-3.5 w-3.5 animate-spin`}):u(B,{className:`h-3.5 w-3.5`}),` `,`Keep`]})}),u(`span`,{title:Cn?void 0:`Track flags arrive with the next server update`,children:r(H,{onClick:()=>ne(`analyzed`),disabled:!Cn||ie,children:[_===`analyzed`?u(T,{className:`h-3.5 w-3.5 animate-spin`}):u(Ee,{className:`h-3.5 w-3.5`}),` `,`Analyzed`]})}),u(H,{variant:`ghost`,onClick:U,disabled:ie,children:u(ut,{className:`h-3.5 w-3.5`})})]})]}),S.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(S.length),` track(s) marked analyzed and removed from this list.`]}),r(H,{variant:`ghost`,onClick:W,disabled:ie,children:[u(re,{className:`h-3.5 w-3.5`}),` Undo`]}),u(H,{variant:`ghost`,onClick:()=>C([]),disabled:ie,children:u(ut,{className:`h-3.5 w-3.5`})})]}),M.isLoading?u(E,{children:u(`div`,{className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`Loading…`})}):L.length===0?u(E,{children:r(`div`,{className:`flex flex-col items-center gap-2 px-3 py-8 text-center`,children:[u(st,{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:L.map(e=>{let t=F.get(e.trackId);return u(un,{row:e,cameraName:A(e.deviceId),nowMs:e.lastSeen,selected:f.has(Qr(e.deviceId,e.trackId)),onToggleSelect:z,onOpenDetail:g,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:u(di,{track:e,report:t,analyzing:P.isFetching})},Qr(e.deviceId,e.trackId))})}),h&&u(qn,{row:h,cameraName:A(h.deviceId),deleteAvailable:In,onClose:()=>g(null),onDeleted:()=>{g(null),M.refetch()},onFlagsChanged:e=>{e.debug||(g(null),M.refetch())}})]})})}var pi=200,mi=3e4,hi=[];function gi(e){let t=m(),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:mi,refetchInterval:mi,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEventsBatch.query({deviceIds:r,since:e.since,until:e.until,limit:pi,...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:Zt(Xt(i??hi),`importance`),isLoading:n&&a}}n();var _i=[`events-feed`],vi=2e3;function yi(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:_i})},[]),p=t(void 0);p.current||=wt({delayMs:vi,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 Re(Et.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),Re(Et.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:s,refreshNow:m}}n();function bi({groups:e,selected:t,onChange:n,loading:i=!1}){let{t:o}=Dt(),[s,c]=l(!1),[d,f]=l(``),[p,m]=l(new Set),h=d.trim().toLowerCase(),g=e=>h.length===0||S(e,o).toLowerCase().includes(h),y=a(()=>e.map(e=>({macro:e.macro,subs:e.subs.filter(t=>g(t)||g(e.macro))})).filter(e=>g(e.macro)||e.subs.length>0),[e,h]),b=e=>m(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)},C=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},w=()=>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(ft,{className:`h-3.5 w-3.5`}),T>0?`Kinds (${String(T)})`:`Kinds`,u(_,{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(Ge,{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:w,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…`:h.length>0?`No kind matches that search.`:`These cameras advertise no event kinds.`}),y.map(e=>{let n=Se(e.macro.iconId),i=p.has(e.macro.kind)||h.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?_: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:S(e.macro,o)})]})]}),i&&e.subs.map(e=>{let n=Se(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:()=>C(e.kind),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),u(`span`,{children:S(e,o)})]},e.kind)})]},e.macro.kind)})]})]})}function xi(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 Si(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var Ci=new Set([`detection`,`package`]);function wi(e,t){return[...xi(e,t).values()].filter(e=>e.parentKind===null&&Ci.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function Ti(e,t){let n=xi(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,Si(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 Ei(){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 Di=[`events-feed`],Oi=60,ki=[{value:`importance`,label:`Importance`,icon:Lt},{value:`time`,label:`Recent`,icon:Be}];function Ai(){let e=c(),t=ne(),n=Ue(),[i,o]=l(Ct),[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),[E,D]=l(()=>Date.now());d(()=>{let e=setInterval(()=>D(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:O,until:k}=a(()=>tn({fromMs:i.fromMs,toMs:i.toMs},E),[i.fromMs,i.toMs,E]),A=Ei(),{pending:j,refreshNow:M}=yi({paused:C!==null||x.size>0||A.scrolledPast}),{data:N=[]}=Je({isCamera:!0,projection:`slim`}),P=a(()=>N.map(e=>e.id),[N]),{data:F,isLoading:I}=xe({deviceIds:P},{enabled:P.length>0,staleTime:5*6e4}),L=a(()=>Ti(F??[],f),[F,f]),R=zn(),ee=R.isPending,{rows:z,isLoading:B}=gi({deviceIds:P,since:O,until:k,minImportance:g>0?g:void 0,classFilter:m.size===1?[...m][0]:void 0}),V=a(()=>{let e=new Map;for(let t of N??[])e.set(t.id,t.name);return e},[N]),U=e=>V.get(e)??`Camera #${String(e)}`,te=a(()=>mt(z).map(e=>({id:e,name:U(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[z,V]),W=a(()=>Zt(Qt(z,{cameras:f,classes:m,minImportance:g}),v),[z,f,m,g,v]),G=bt(W,Oi,a(()=>JSON.stringify([[...f].sort((e,t)=>e-t),[...m].sort(),g,v,O,k]),[f,m,g,v,O,k])),re=()=>{e.invalidateQueries({queryKey:Di})},K=()=>S(new Set);function ie(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||!In)return;let e=en(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])=>R.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($t(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=>U(e)).join(`, `)}. They remain selected — retry, or check the server logs.`,variant:`danger`})})}let se=W.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(St,{onChange:o}),u(_t,{cameras:te,selected:f,onChange:p}),u(bi,{groups:L,selected:m,onChange:h,loading:I}),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:ki.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(W.length)} of ${String(z.length)} events`:`${String(W.length)} event${W.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:In?void 0:`Track deletion arrives with the next server update`,children:r(H,{variant:`secondary`,onClick:ae,disabled:!In||ee,children:[ee?u(T,{className:`h-3.5 w-3.5 animate-spin`}):u(y,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),u(H,{variant:`ghost`,onClick:K,disabled:ee,children:u(ut,{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(T,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!B&&W.length===0&&u(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),j&&u(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:u(`button`,{type:`button`,onClick:M,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&&W.length>0&&r(s,{children:[u(`div`,{ref:A.ref,"aria-hidden":!0,className:`h-0`}),u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:G.pageItems.map(e=>u(un,{row:e,cameraName:U(e.deviceId),nowMs:E,selected:x.has($t(e.deviceId,e.trackId)),onToggleSelect:ie,onOpenDetail:w},$t(e.deviceId,e.trackId)))}),u(pt,{currentPage:G.page,totalItems:G.totalItems,pageSize:G.pageSize,onPageChange:G.setPage,itemNoun:`events`})]}),C&&u(qn,{row:C,cameraName:U(C.deviceId),deleteAvailable:In,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 ji=50,Mi=350,Ni=[{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 Pi(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 Fi({onActiveChange:e}){let[t,n]=l(``),[i,o]=l(`loose`),[s,c]=l(null),[f,p]=l(null),[m,h]=l(null),g=_e(t,Mi).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]),C=e=>x.get(e)??`Camera #${String(e)}`,w=a(()=>b.map(e=>e.id),[b]),{data:E}=xe({deviceIds:w},{enabled:w.length>0,staleTime:5*6e4}),D=a(()=>wi(E??[],new Set(f===null?[]:[f])),[E,f]);d(()=>{s!==null&&(D.some(e=>e.kind===s)||c(null))},[D,s]);let{data:O,isFetching:k,isError:A,error:j}=M({text:g,strictness:i,limit:ji,classFilter:s??void 0,deviceId:f??void 0},{enabled:_}),N=a(()=>[...O??[]].sort((e,t)=>t.score-e.score).map(e=>({...Pi(e),score:e.score})),[O]);function P(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(Ge,{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(ut,{className:`h-3.5 w-3.5`})})]}),k&&_&&u(T,{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:D.map(e=>u(`button`,{type:`button`,onClick:()=>P(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:S(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:Ni.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))})]}),_&&!k&&!A&&r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[N.length,` match`,N.length===1?``:`es`]})]})]}),_&&r(`div`,{className:`space-y-3`,children:[A&&r(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,j instanceof Error?j.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!A&&k&&N.length===0&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(T,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!A&&!k&&N.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.`]}),!A&&N.length>0&&u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:N.map(e=>u(un,{row:e,cameraName:C(e.deviceId),nowMs:v,score:e.score,onOpenDetail:h},e.id))})]}),m&&u(qn,{row:m,cameraName:C(m.deviceId),deleteAvailable:In,onClose:()=>h(null),onDeleted:()=>h(null)})]})}n();function Ii(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 Li({row:e,cameraName:t,nowMs:n}){let i=At(e.keyFrameMediaId===void 0?void 0:Mt(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(Kt,{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 `,Ii(n,e.becameStationaryAt)]})]})]})}function Ri(){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}=Pt(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?_:v,{className:`h-4 w-4 text-foreground-subtle`}),u(Kt,{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(Li,{row:e,cameraName:s.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}n();function zi(){let[e,t]=l(!1);return u(kt,{children:r(`section`,{className:`space-y-3`,children:[u(Fi,{onActiveChange:t}),!e&&u(Ri,{}),!e&&u(Ai,{})]})})}n();function Bi({frameId:e,onAdded:t}){let n=ae(),[i,a]=l(null),[o,s]=l(null),c=async()=>{if(i===null)return;let r=await n.mutateAsync({collectionId:i,frameIds:[e]});s(r.added>0?`Added.`:r.alreadyMember>0?`Already in that collection.`:`That frame or collection no longer exists.`),await t()};return r(de,{children:[r(W,{className:`mt-1 flex items-center gap-1 text-foreground-muted hover:text-foreground`,"aria-label":`Add this frame to a collection`,children:[u(Vt,{className:`h-3 w-3`}),`collection`]}),r(L,{className:`w-72 space-y-2 p-3`,children:[u(ct,{value:i,onChange:a}),r(`div`,{className:`flex items-center justify-between gap-2`,children:[u(`span`,{className:`text-[11px] text-foreground-subtle`,children:o}),u(H,{size:`sm`,disabled:i===null||n.isPending,onClick:()=>void c(),children:`Add`})]})]})]})}function Vi(e){let t=e.capturedAt??e.copiedAt;return new Date(t).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function Hi({frames:e,isLoading:t,activeFrameId:n,deviceNames:i,onOpen:a,onRemove:o}){return e.length===0?u(`p`,{className:`text-[11px] text-foreground-subtle`,children:t?`Reading the collection…`:`This collection is empty. Add frames with "Send frame to training" on a camera’s recording timeline, or "Add to collection" on a track’s copied frame.`}):u(`ul`,{className:`flex flex-wrap gap-2`,children:e.map(e=>u(`li`,{children:r(`div`,{className:`rounded-md border px-2 py-1.5 text-[11px] flex items-start gap-1.5 ${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:()=>{a(e.frameId)},children:[e.origin===`recording`?u(te,{className:`h-3 w-3 text-info`,"aria-label":`From the recording`}):u(Ut,{className:`h-3 w-3 text-success`,"aria-label":`From a track`}),u(`span`,{className:`font-medium text-foreground`,children:i.get(e.deviceId)??`Camera ${String(e.deviceId)}`}),u(`span`,{className:`text-foreground-subtle`,children:Vi(e)}),e.complete&&u(J,{variant:`success`,children:`complete`})]}),u(`button`,{type:`button`,"aria-label":`Remove from this collection`,title:e.origin===`recording`?`Remove from this collection. If no other collection holds it, the frame and its boxes leave the dataset.`:`Remove from this collection. The frame stays in the dataset with its track.`,className:`text-foreground-muted hover:text-danger`,onClick:()=>{o(e)},children:u(ut,{className:`h-3 w-3`})})]})},e.frameId))})}n();function Ui({collections:e,isLoading:t,selectedId:n,onSelect:i,onCreate:a,onRename:o,onDelete:c}){let[d,f]=l(``),[p,m]=l(null),[h,g]=l(null),_=async()=>{let e=await a(d);m(e),e===null&&f(``)},v=async()=>{if(h===null)return;let e=await o(h.id,h.name);m(e),e===null&&g(null)};return r(`div`,{className:`divide-y divide-border`,children:[r(`div`,{className:`p-2 space-y-1.5`,children:[r(`div`,{className:`flex items-center gap-1.5`,children:[u(q,{className:`flex-1`,"aria-label":`New collection name`,placeholder:`New collection`,value:d,onChange:e=>{f(e.target.value)}}),u(H,{size:`sm`,disabled:d.trim()===``,onClick:()=>void _(),children:`Create`})]}),p!==null&&u(`p`,{className:`text-[11px] text-danger`,children:p})]}),e.length===0?u(`p`,{className:`p-3 text-[11px] text-foreground-subtle`,children:t?`Reading the collections…`:`No collection yet. Create one here, or use "Send frame to training" on a camera’s recording timeline.`}):u(`ul`,{className:`divide-y divide-border`,children:e.map(e=>u(`li`,{className:`px-3 py-2 flex items-center gap-2 text-xs ${e.id===n?`bg-surface-hover`:``}`,children:h?.id===e.id?r(s,{children:[u(q,{className:`flex-1`,"aria-label":`Collection name`,value:h.name,onChange:t=>{g({id:e.id,name:t.target.value})}}),u(H,{variant:`ghost`,size:`sm`,"aria-label":`Save the name`,onClick:()=>void v(),children:u(Ee,{className:`h-3 w-3`})}),u(H,{variant:`ghost`,size:`sm`,"aria-label":`Cancel renaming`,onClick:()=>{g(null)},children:u(ut,{className:`h-3 w-3`})})]}):r(s,{children:[u(`button`,{type:`button`,className:`flex-1 min-w-0 text-left truncate text-foreground`,onClick:()=>{i(e)},children:e.name}),u(J,{children:e.frameCount}),u(H,{variant:`ghost`,size:`sm`,"aria-label":`Rename ${e.name}`,onClick:()=>{g({id:e.id,name:e.name})},children:u(et,{className:`h-3 w-3`})}),u(N,{label:`Delete`,icon:y,triggerVariant:`ghost`,size:`sm`,title:`Delete "${e.name}"?`,description:`Frames taken from the recording that are in no other collection are deleted with their boxes. Frames copied from tracks stay in the dataset.`,confirmLabel:`Delete`,confirmVariant:`danger`,action:()=>c(e.id)})]})},e.id))})]})}n();function Wi(){let e=Ie({}),t=he({}),[n,i]=l([]),a=He(n.length>0?{collectionIds:[...n]}:{}),o=$e({}),[s,c]=l(null),[d,f]=l(null),m=async(e,t,n)=>{c(e),f(null);try{await Nt(p(t),n)}catch(e){f(e instanceof Error?e.message:String(e))}finally{c(null)}},h=e.data,g=h!==void 0&&h.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(H,{variant:`secondary`,size:`sm`,disabled:a.data===void 0||s!==null,onClick:()=>{a.data!==void 0&&m(`annotated`,a.data.url,`camstack-retrain-export.tar`)},children:[s===`annotated`?u(T,{className:`h-3 w-3 animate-spin`}):u(x,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Annotated dataset`})]}),r(H,{variant:`secondary`,size:`sm`,disabled:o.data===void 0||g||s!==null,onClick:()=>{o.data!==void 0&&m(`marked`,o.data.url,`camstack-training-export.tar`)},children:[s===`marked`?u(T,{className:`h-3 w-3 animate-spin`}):u(x,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Marked media`})]})]}),(t.data??[]).length>0&&r(`div`,{className:`flex items-center gap-1.5 flex-wrap text-[11px]`,children:[u(`span`,{className:`text-foreground-subtle`,children:`Annotated dataset from:`}),n.length===0&&u(J,{children:`every collection and track`}),(t.data??[]).map(e=>{let t=n.includes(e.id);return r(`button`,{type:`button`,"aria-pressed":t,className:`rounded-full border px-2 py-0.5 ${t?`border-primary text-primary`:`border-border text-foreground-muted hover:text-foreground`}`,onClick:()=>{i(n=>t?n.filter(t=>t!==e.id):[...n,e.id])},children:[e.name,` · `,e.frameCount]},e.id)})]}),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.`:h===void 0?`Measuring the marked set…`:g?`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(h.trackCount)} marked track${h.trackCount===1?``:`s`} · ${String(h.fileCount)} file${h.fileCount===1?``:`s`} · ${It(h.byteCount)}${h.truncated?` · more marked tracks exist than one pass carries`:``}`}),(a.isError||o.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.`}),d!==null&&r(`p`,{className:`text-[11px] text-danger`,children:[`Download failed: `,d]})]})}function Gi(e){return e>=1e6?`${(e/1e6).toFixed(1)} MB`:`${Math.round(e/1e3)} KB`}function Ki({candidates:e,copies:t,activeFrameId:n,refusals:i,isSelecting:a,onSelectCandidate:o,onOpenCopy:s,onRemoveCopy:c,renderCopyActions:l}){let d=new Set(t.map(e=>e.sourceMediaId)),f=e.filter(e=>!d.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(Ee,{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)]}),e.complete&&u(J,{variant:`success`,children:`complete`})]}),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`]}),l?.(e)]})},e.frameId))})]}),r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`Available frames (`,f.length,`)`]}),f.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:f.map(e=>{let t=i.get(e.mediaId);return r(`li`,{children:[r(H,{variant:`secondary`,size:`sm`,disabled:a||t!==void 0,onClick:()=>{o(e.mediaId)},children:[a?u(T,{className:`h-3 w-3 animate-spin`}):u(t===void 0?Bt:g,{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(J,{variant:`danger`,className:`ml-1`,children:t})]},e.mediaId)})})]})]})}function qi(e){return e.frameCount===0?`untouched`:e.annotationCount===0?`started`:`ready`}var Ji={untouched:{icon:zt,label:`to do`,variant:`default`},started:{icon:Rt,label:`frames only`,variant:`info`},ready:{icon:be,label:`annotated`,variant:`success`}};function Yi(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(T,{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=Ji[qi(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(J,{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)}`,` ·`,` `,Yi(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)})})}function Zi(e){return{deviceId:e.deviceId,...e.trackId===void 0?{}:{trackId:e.trackId},frameId:e.frameId}}var Qi=`object-detection`;function $i(e,t){for(let n of e){if(n.addonId===t)return n;let e=n.children===void 0?void 0:$i(n.children,t);if(e!==void 0)return e}}function ea(e,t){for(let n of e.slots){let e=n.addons.find(e=>e.id===t);if(e!==void 0)return e}}function ta(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=ea(r,Qi);if(s===void 0)return{kind:`unknown`,gap:`step-unknown`};let c=Ye({catalog:s,device:o,override:$i(i,Qi)?.modelId,base:o.steps?.[Qi]?.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}}function na(e,t){let n=Math.max(0,Math.min(e.x+e.w,t.x+t.w)-Math.max(e.x,t.x))*Math.max(0,Math.min(e.y+e.h,t.y+t.h)-Math.max(e.y,t.y)),r=e.w*e.h+t.w*t.h-n;return r>0?n/r:0}function ra(e,t){let n=e.nextKey;return{boxes:t.map(e=>{let t=`b${String(n)}`;return n+=1,{...e,key:t}}),nextKey:n}}function ia(e){return{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},draft:!1}}function aa(e){return e.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},...e.subLabel===void 0?{}:{subLabel:e.subLabel},kind:`subject`,source:`pipeline`,...e.modelId===void 0?{}:{assistModelId:e.modelId},...e.score===void 0?{}:{assistScore:e.score},draft:!0,note:e.basis===`subject-box`?`The box the pipeline recorded on this very frame.`:`The pipeline's track position ${String(Math.round(e.deltaMs))} ms from this frame.`}))}var oa={boxes:[],selectedKey:null,nextKey:0};function sa(e,t){let n=ra(oa,e.map(ia));return ca({boxes:n.boxes,selectedKey:null,nextKey:n.nextKey},aa(t)).state}function ca(e,t){let n=[],r=0;for(let i of t){if([...e.boxes,...n].some(e=>na(e.bbox,i.bbox)>=.8)){r+=1;continue}n.push({...i,draft:!0})}let i=ra(e,n);return{state:{...e,boxes:[...e.boxes,...i.boxes],nextKey:i.nextKey},skipped:r}}function la(e,t,n){let r=ra(e,[{bbox:t,macroClass:n,kind:`subject`,source:`operator`,draft:!1}]),i=r.boxes[0];return i===void 0?e:{boxes:[...e.boxes,i],selectedKey:i.key,nextKey:r.nextKey}}function ua(e,t,n){return{...e,boxes:e.boxes.map(e=>e.key===t?n(e):e)}}function da(e,t,n){return ua(e,t,e=>({...e,...n,draft:!1}))}function fa(e,t){return ua(e,t,e=>({...e,draft:!1}))}function pa(e){return{...e,boxes:e.boxes.map(e=>e.draft?{...e,draft:!1}:e)}}function ma(e,t){return ua(e,t,e=>({...e,kind:e.kind===`model_error`?`subject`:`model_error`,draft:!1}))}function ha(e,t){return{...e,boxes:e.boxes.filter(e=>e.key!==t),selectedKey:e.selectedKey===t?null:e.selectedKey}}function ga(e,t){return{...e,selectedKey:t}}function _a(e,t){return{...e,boxes:e.boxes.map(e=>{let n=t.get(e.key);return n===void 0?e:{...e,flag:n}})}}function va(e,t){return new Map(e.map(e=>[e.ref,{verdict:e.verdict,reason:e.reason,by:t,...e.suggestedClass===void 0?{}:{suggestedClass:e.suggestedClass}}]))}function ya(e){return e.boxes.filter(e=>e.draft).length}function ba(e){let t=e?.trim();return t===void 0||t===``?void 0:t}function xa(e){return e.boxes.filter(e=>!e.draft).map(e=>{let t=ba(e.label),n=ba(e.subLabel);return{bbox:e.bbox,macroClass:e.macroClass,...t===void 0?{}:{label:t},...n===void 0?{}:{subLabel:n},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}})}var Sa=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],Ca=new Set(Sa),wa={operator:`drawn`,pipeline:`pipeline`,assist:`detector`,llm:`AI vision`};function Ta(e){let t=e?.trim().toLowerCase();return t===void 0||t===``?null:Ca.has(t)?`"${t}" is a macro class, not a label — person / postman / Marco are three different tiers`:null}function Ea(e){if(e.source===`operator`)return null;let t=[wa[e.source]];return e.assistModelId!==void 0&&t.push(e.assistModelId),e.assistScore!==void 0&&t.push(e.assistScore.toFixed(2)),t.join(` · `)}function Da({boxes:e,selectedKey:t,onSelect:n,onChange:i,onAccept:a,onToggleModelError:o,onDelete:s}){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 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=>{let c=e.key===t,l=Ta(e.label),d=Ta(e.subLabel),f=Ea(e);return r(`li`,{"data-testid":`retrain-row-${e.key}`,className:`p-2.5 space-y-1.5 ${c?`bg-surface-hover`:``}`,onFocus:()=>{n(e.key)},onClick:()=>{n(e.key)},children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(I,{className:`w-28`,"aria-label":`Class`,value:e.macroClass,options:Sa.map(e=>({value:e,label:e})),onChange:t=>{let n=Sa.find(e=>e===t.target.value);n!==void 0&&i(e.key,{macroClass:n})}}),e.draft&&u(J,{variant:`warning`,children:`draft`}),e.kind===`model_error`&&u(J,{variant:`danger`,children:`model error`}),f!==null&&u(J,{variant:`info`,children:f}),(e.note!==void 0||e.flag!==void 0)&&r(pe,{children:[u(me,{children:u(V,{className:`h-3.5 w-3.5 ${e.flag!==void 0&&e.flag.verdict!==`confirmed`?`text-warning`:`text-foreground-subtle`}`,"aria-label":`Why this box is here`})}),r(fe,{className:`whitespace-normal w-64 text-left`,children:[e.note!==void 0&&u(`p`,{children:e.note}),e.flag!==void 0&&r(`p`,{children:[e.flag.by,`: `,e.flag.verdict,e.flag.suggestedClass===void 0?``:` (suggests ${e.flag.suggestedClass})`,` `,`— `,e.flag.reason]})]})]}),u(`span`,{className:`flex-1`}),e.draft&&u(H,{variant:`secondary`,size:`sm`,"aria-label":`Accept this proposal`,onClick:()=>{a(e.key)},children:u(Ee,{className:`h-3 w-3`})}),u(H,{variant:`ghost`,size:`sm`,"aria-label":e.kind===`model_error`?`This is a real subject`:`Mark as model error`,onClick:()=>{o(e.key)},children:u(Me,{className:`h-3 w-3`})}),u(H,{variant:`ghost`,size:`sm`,"aria-label":`Delete this subject`,onClick:()=>{s(e.key)},children:u(y,{className:`h-3 w-3`})})]}),r(`div`,{className:`flex items-center gap-2`,children:[u(q,{className:`flex-1`,placeholder:`label (postman, van, cat…)`,value:e.label??``,onChange:t=>{i(e.key,{label:t.target.value})}}),u(q,{className:`flex-1`,placeholder:`sub-label (a name, a plate…)`,value:e.subLabel??``,onChange:t=>{i(e.key,{subLabel:t.target.value})}})]}),l!==null&&u(`p`,{className:`text-[11px] text-danger`,children:l}),d!==null&&u(`p`,{className:`text-[11px] text-danger`,children:d})]},e.key)})})}function Oa(e){return e.filter(e=>!e.draft).every(e=>Ta(e.label)===null&&Ta(e.subLabel)===null&&Ca.has(e.macroClass))}var ka=.25;function Aa(e,t){if(e===void 0)return[];let n=e.selectedEngine.format,r=e.slots.flatMap(e=>e.addons).find(e=>e.id===Qi);if(r===void 0)return[];let i=r.models.filter(e=>e.legacy!==!0&&e.provider===void 0).flatMap(e=>{let t=e.formats[n];return t===void 0?[]:[{modelId:e.id,name:e.name,sizeMB:t.sizeMB??0}]}),a=i.find(e=>e.modelId===t);return i.filter(e=>e.modelId!==t&&(a===void 0||e.sizeMB>a.sizeMB)).toSorted((e,t)=>t.sizeMB-e.sizeMB)}n();var ja=[{value:`teacher`,label:`Bigger detector`},{value:`llm`,label:`AI vision`},{value:`both`,label:`Both`}],Ma=[`person`,`vehicle`,`animal`,`package`],Na=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],Pa={"unknown-frame":`The frame is no longer in the dataset.`,"unreadable-frame":`The frame copy could not be read.`,"unknown-profile":`That AI profile no longer exists.`,"profile-disabled":`That AI profile is disabled.`,"no-vision":`That AI profile cannot read images.`,"cloud-not-confirmed":`The frame was not sent: sending it outside the house needs your confirmation.`,"llm-error":`The AI model call failed.`,"malformed-answer":`The AI answered in a shape that cannot be trusted, so nothing was drawn.`};function Fa({frame:e,history:n,detector:i,schema:o,setNotice:s}){let c=ke({},{retry:!1}),d=ot(),f=oe(),[p,m]=l(`teacher`),h=a(()=>Aa(o,i.kind===`resolved`?i.modelId:void 0),[o,i]),[g,_]=l(null),v=h.find(e=>e.modelId===g)??h[0],[y,b]=l(ka),[x,S]=l(null),C=(c.data??[]).find(e=>e.id===x)??c.data?.[0],[w,E]=l(Ma),[D,O]=l(!1),[k,M]=l(!1),N=t(n.editor);N.current=n.editor;let F=p!==`llm`,L=p!==`teacher`,R=i.kind===`resolved`&&v!==void 0,ee=C!==void 0&&w.length>0,z=(!F||R)&&(!L||ee),B=async()=>{if(i.kind!==`resolved`||v===void 0)return``;let t=await d.mutateAsync({...Zi(e),subject:{kind:`objects`,modelId:v.modelId,minScore:y},nodeId:i.nodeId});if(t.kind===`refused`)return`${v.name} refused: ${t.reason}${t.detail===void 0?``:` — ${t.detail}`}.`;let r=ca(N.current,t.proposals.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},kind:e.kind,source:`assist`,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore},draft:!0,note:`Proposed by the larger detector ${t.modelId} on ${i.nodeId}.`})));N.current=r.state,n.setEditor(r.state);let a=t.proposals.length-r.skipped;return`${v.name}: ${String(a)} new draft${a===1?``:`s`}${r.skipped>0?`, ${String(r.skipped)} already on the frame`:``}.`},V=async t=>{if(C===void 0)return``;let r=N.current,i=await f.mutateAsync({...Zi(e),profileId:C.id,classes:[...w],boxes:r.boxes.slice(0,50).map(e=>({ref:e.key,bbox:e.bbox,macroClass:e.macroClass,...e.label!==void 0&&e.label!==``?{label:e.label}:{}})),allowCloud:t});if(i.kind===`refused`)return`${Pa[i.reason]??i.reason}${i.detail===void 0?``:` (${i.detail})`}`;let a=i.proposals.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},kind:`subject`,source:`llm`,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore},draft:!0,note:`${i.model}: ${e.reason}`})),o=va(i.reviews,i.model),s=ca(N.current,a);n.setEditor(e=>_a(ca(e,a).state,o));let c=i.proposals.length-s.skipped,l=i.reviews.filter(e=>e.verdict!==`confirmed`).length;return`${C.name}: ${String(c)} new draft${c===1?``:`s`}, ${String(l)} box${l===1?``:`es`} questioned${i.rejected>0?`, ${String(i.rejected)} unusable item${i.rejected===1?``:`s`} dropped`:``}.`},U=async e=>{O(!1),M(!0),s(null);try{let t=[];F&&t.push(await B()),L&&t.push(await V(e)),s(`${t.filter(e=>e!==``).join(` `)} Drafts are not saved until you accept or correct them.`)}catch(e){s(`The assist failed: ${e instanceof Error?e.message:String(e)}`)}finally{M(!1)}};return r(`div`,{className:`px-3 py-2 border-b border-border space-y-2 text-[11px]`,"data-testid":`retrain-assist`,children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(`span`,{className:`font-semibold text-foreground`,children:`Assist`}),u(I,{className:`w-36`,"aria-label":`Assist engine`,value:p,options:ja.map(e=>({value:e.value,label:e.label})),onChange:e=>{let t=ja.find(t=>t.value===e.target.value);t!==void 0&&m(t.value)}}),u(`span`,{className:`flex-1`}),r(H,{size:`sm`,variant:`secondary`,disabled:!z||k,onClick:()=>{if(L&&C?.leavesHouse===!0){O(!0);return}U(!1)},children:[k?u(T,{className:`h-3 w-3 animate-spin`}):u(qt,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Run`})]})]}),F&&(h.length===0||i.kind!==`resolved`?u(`p`,{className:`text-foreground-subtle`,children:i.kind===`resolved`?`The detection node’s catalog has no detector larger than this camera’s for its format.`:`The camera’s detection node is not known, so no larger detector can be run there.`}):r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(I,{className:`flex-1 min-w-40`,"aria-label":`Larger detector`,value:v?.modelId??``,options:h.map(e=>({value:e.modelId,label:`${e.name} (${String(Math.round(e.sizeMB))} MB)`})),onChange:e=>{_(e.target.value)}}),u(q,{className:`w-20`,"aria-label":`Minimum score`,type:`number`,min:.05,max:.95,step:.05,value:y,onChange:e=>{let t=Number.parseFloat(e.target.value);Number.isFinite(t)&&b(Math.min(.95,Math.max(.05,t)))}}),r(`span`,{className:`text-foreground-subtle`,children:[`on `,i.nodeId]})]})),L&&((c.data??[]).length===0?u(`p`,{className:`text-foreground-subtle`,children:c.isError?`The AI profiles could not be read.`:`No enabled AI profile can read images. Add one under AI settings.`}):r(`div`,{className:`space-y-1.5`,children:[u(I,{"aria-label":`AI profile`,value:C?.id??``,options:(c.data??[]).map(e=>({value:e.id,label:`${e.name} · ${e.model}${e.leavesHouse?` · cloud`:` · local`}`})),onChange:e=>{S(e.target.value)}}),C?.leavesHouse===!0&&u(`p`,{className:`text-warning`,children:`This profile sends the frame outside your home, to a cloud service. Each run asks first.`}),r(`div`,{className:`flex items-center gap-1 flex-wrap`,children:[u(`span`,{className:`text-foreground-subtle`,children:`Look for:`}),Na.map(e=>{let t=w.includes(e);return u(`button`,{type:`button`,"aria-pressed":t,className:`rounded-full border px-2 py-0.5 ${t?`border-primary text-primary`:`border-border text-foreground-muted`}`,onClick:()=>{E(n=>t?n.filter(t=>t!==e):[...n,e])},children:e},e)})]})]})),u(at,{open:D,onOpenChange:O,children:r(A,{children:[r(P,{children:[u(j,{children:`Send this frame outside your home?`}),u(nt,{children:`The frame from ${e.origin===`recording`?`the recording`:`this track`} will be sent to ${C?.name??`the AI profile`} (${C?.kind??`cloud`}, model ${C?.model??``}), a service outside your network, to be analysed. Only this frame, for this run.`})]}),r(se,{children:[u(H,{variant:`ghost`,size:`sm`,onClick:()=>{O(!1)},children:`Cancel`}),u(H,{size:`sm`,onClick:()=>void U(!0),children:`Send this frame`})]})]})})]})}function Ia(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 La(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)}}var Ra=.01;function za(e){return e.w>=.01&&e.h>=.01}function Ba(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}var Va=[`nw`,`n`,`ne`,`e`,`se`,`s`,`sw`,`w`];function Ha(e,t,n){return{x:Math.min(Math.max(0,e.x+t),Math.max(0,1-e.w)),y:Math.min(Math.max(0,e.y+n),Math.max(0,1-e.h)),w:e.w,h:e.h}}function Ua(e,t,n,r){if(n){let e=Math.min(Math.max(0,r),t-Ra);return{start:e,size:t-e}}return{start:e,size:Math.max(Math.min(1,r),e+Ra)-e}}function Wa(e,t,n){let r=t.includes(`w`)||t.includes(`e`)?Ua(e.x,e.x+e.w,t.includes(`w`),n.x):{start:e.x,size:e.w},i=t.includes(`n`)||t.includes(`s`)?Ua(e.y,e.y+e.h,t.includes(`n`),n.y):{start:e.y,size:e.h};return{x:r.start,y:i.start,w:r.size,h:i.size}}function Ga(e,t){return{x:t.includes(`w`)?e.x:t.includes(`e`)?e.x+e.w:e.x+e.w/2,y:t.includes(`n`)?e.y:t.includes(`s`)?e.y+e.h:e.y+e.h/2}}function Ka(e,t,n){let r=(e,t,n)=>Math.abs(e-t)<=n,i=r(t.x,e.x,n.x),a=r(t.x,e.x+e.w,n.x),o=r(t.y,e.y,n.y),s=r(t.y,e.y+e.h,n.y),c=t.x>=e.x-n.x&&t.x<=e.x+e.w+n.x,l=t.y>=e.y-n.y&&t.y<=e.y+e.h+n.y;return!c||!l?null:o&&i?`nw`:o&&a?`ne`:s&&i?`sw`:s&&a?`se`:o?`n`:s?`s`:i?`w`:a?`e`:t.x>=e.x&&t.x<=e.x+e.w&&t.y>=e.y&&t.y<=e.y+e.h?`body`:null}var qa={x:0,y:0,w:1,h:1},Ja=1.5;function Ya(e,t,n){return e<t?t:e>n?n:e}function Xa(e){return 1/e.w}function Za(e,t,n,r){return{x:Ya(r.x+(e-n.left)/n.width*r.w,0,1),y:Ya(r.y+(t-n.top)/n.height*r.h,0,1)}}function Qa(e,t,n){return{x:t.left+(e.x-n.x)/n.w*t.width,y:t.top+(e.y-n.y)/n.h*t.height}}function $a(e,t,n){let r=Qa(e,t,n);return{left:r.x,top:r.y,width:e.w/n.w*t.width,height:e.h/n.h*t.height}}function eo(e,t){return{left:e.left-t.x/t.w*e.width,top:e.top-t.y/t.h*e.height,width:e.width/t.w,height:e.height/t.h}}function to(e,t,n){let r=Ya(e.w/n,1/16,1),i=r/e.w;return{x:Ya(t.x-(t.x-e.x)*i,0,1-r),y:Ya(t.y-(t.y-e.y)*i,0,1-r),w:r,h:r}}function no(e,t,n){return{x:Ya(e.x+t,0,1-e.w),y:Ya(e.y+n,0,1-e.h),w:e.w,h:e.h}}function ro(e){return{x:e.x+e.w/2,y:e.y+e.h/2}}var io=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`];function ao(e){if(typeof e!=`object`||!e||!(`tagName`in e))return!1;let t=String(e.tagName).toUpperCase();return t===`INPUT`||t===`TEXTAREA`||t===`SELECT`?!0:`isContentEditable`in e&&e.isContentEditable===!0}function oo(e){let t=e.ctrlKey||e.metaKey,n=e.key.toLowerCase();if(t&&!e.altKey)return n===`s`&&!e.shiftKey?{kind:`save`}:e.typing?null:n===`z`?e.shiftKey?{kind:`redo`}:{kind:`undo`}:n===`y`&&!e.shiftKey?{kind:`redo`}:null;if(e.typing||t||e.altKey)return null;switch(e.key){case`ArrowRight`:return{kind:`next-frame`};case`ArrowLeft`:return{kind:`prev-frame`};case`Delete`:case`Backspace`:return{kind:`delete`};case`Escape`:return{kind:`deselect`};case`Tab`:return e.shiftKey?{kind:`select-prev`}:{kind:`select-next`};case`+`:case`=`:return{kind:`zoom-in`};case`-`:case`_`:return{kind:`zoom-out`};case`0`:return{kind:`zoom-fit`};default:break}let r=Number.parseInt(e.key,10);if(Number.isInteger(r)&&r>=1&&r<=io.length){let e=io[r-1];return e===void 0?null:{kind:`set-class`,macroClass:e}}return n===`a`?e.shiftKey?{kind:`accept-all`}:{kind:`accept`}:n===`e`&&!e.shiftKey?{kind:`toggle-model-error`}:n===`c`&&!e.shiftKey?{kind:`toggle-complete`}:null}var so=[{keys:`← / →`,does:`Previous / next frame`},{keys:`Drag on empty frame`,does:`Draw a box`},{keys:`Drag a box / its handles`,does:`Move / resize it`},{keys:`Delete, Backspace`,does:`Delete the selected box`},{keys:`1 – 6`,does:`Class: person, vehicle, animal, package, face, plate`},{keys:`A`,does:`Accept the selected draft`},{keys:`Shift + A`,does:`Accept every draft`},{keys:`E`,does:`Mark / unmark the selected box as a model error`},{keys:`C`,does:`Toggle "all subjects boxed"`},{keys:`Tab / Shift + Tab`,does:`Select the next / previous box`},{keys:`Esc`,does:`Deselect`},{keys:`Ctrl/⌘ + Z`,does:`Undo`},{keys:`Ctrl/⌘ + Shift + Z, Ctrl/⌘ + Y`,does:`Redo`},{keys:`Ctrl/⌘ + S`,does:`Save the frame`},{keys:`+ / − / 0, wheel, pinch`,does:`Zoom in / out / fit`},{keys:`Space + drag, middle drag, two fingers`,does:`Pan`}];n();var co=.0015,lo={pipeline:`var(--color-foreground-muted)`,assist:`var(--color-info)`,llm:`var(--color-warning)`,operator:`var(--color-success)`};function uo(e,t){return e.kind===`model_error`?{color:`var(--color-danger)`,dashed:!0,opacity:1}:t?{color:`var(--color-primary)`,dashed:e.draft,opacity:1}:e.draft?{color:lo[e.source],dashed:!0,opacity:.8}:{color:`var(--color-success)`,dashed:!1,opacity:1}}function fo(e,t){return Math.hypot(e.x-t.x,e.y-t.y)}function po(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}function mo({imageSrc:n,imageWidth:a,imageHeight:o,boxes:s,selectedKey:c,viewport:f,onViewportChange:p,panMode:m,onSelect:h,onDraw:g,onGestureStart:_,onGestureBox:v,onGestureEnd:y}){let b=t(null),[x,S]=l({w:0,h:0}),[C,w]=l(null),[T,E]=l(!1),D=t(new Map),O=t({mode:`none`});i(()=>{let e=b.current;if(e===null)return;let t=()=>S({w:e.clientWidth,h:e.clientHeight});if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},[]);let k=Ia(x.w,x.h,a,o);d(()=>{let e=e=>{e.key!==` `||ao(e.target)||(e.preventDefault(),E(!0))},t=e=>{e.key===` `&&E(!1)};return window.addEventListener(`keydown`,e),window.addEventListener(`keyup`,t),()=>{window.removeEventListener(`keydown`,e),window.removeEventListener(`keyup`,t)}},[]);let A=t({image:k,viewport:f,onViewportChange:p});A.current={image:k,viewport:f,onViewportChange:p},d(()=>{let e=b.current;if(e===null)return;let t=t=>{let{image:n,viewport:r,onViewportChange:i}=A.current;if(n===null)return;t.preventDefault();let a=e.getBoundingClientRect();i(to(r,Za(t.clientX-a.left,t.clientY-a.top,n,r),Math.exp(-t.deltaY*co)))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>{e.removeEventListener(`wheel`,t)}},[]);let j=e(e=>{let t=b.current?.getBoundingClientRect();return{x:e.clientX-(t?.left??0),y:e.clientY-(t?.top??0)}},[]),M=e(e=>k===null?null:Za(e.x,e.y,k,f),[k,f]),N=e(()=>{let e=O.current;(e.mode===`move`||e.mode===`resize`)&&y(),e.mode===`draw`&&w(null),O.current={mode:`none`}},[y]),P=e=>{if(k===null)return;let t=j(e);if(D.current.set(e.pointerId,t),e.currentTarget.setPointerCapture?.(e.pointerId),D.current.size===2){N();let[e,t]=[...D.current.values()];if(e===void 0||t===void 0)return;let n=po(e,t);O.current={mode:`pinch`,startDistance:Math.max(1,fo(e,t)),anchor:Za(n.x,n.y,k,f),from:f};return}if(D.current.size>2)return;if(e.button===1||T||m){e.preventDefault(),O.current={mode:`pan`,startPx:t,from:f};return}if(e.button!==0)return;let n=Za(t.x,t.y,k,f),r={x:12/k.width*f.w,y:12/k.height*f.h},i=s.find(e=>e.key===c);if(i!==void 0){let e=Ka(i.bbox,n,r);if(e!==null&&e!==`body`){_(),O.current={mode:`resize`,key:i.key,handle:e,from:i.bbox};return}}let a=s[Ba(s.map(e=>e.bbox),n)];if(a!==void 0){a.key!==c&&h(a.key),_(),O.current={mode:`move`,key:a.key,start:n,from:a.bbox};return}O.current={mode:`draw`,start:n},w(La(n,n))},F=e=>{if(!D.current.has(e.pointerId)||k===null)return;let t=j(e);D.current.set(e.pointerId,t);let n=O.current;switch(n.mode){case`pinch`:{let[e,t]=[...D.current.values()];if(e===void 0||t===void 0)return;let r=to(n.from,n.anchor,fo(e,t)/n.startDistance),i=po(e,t),a=Za(i.x,i.y,k,r);p(no(r,n.anchor.x-a.x,n.anchor.y-a.y));return}case`pan`:{let e=(t.x-n.startPx.x)/k.width*n.from.w,r=(t.y-n.startPx.y)/k.height*n.from.h;p(no(n.from,-e,-r));return}case`move`:{let e=Za(t.x,t.y,k,f);v(n.key,Ha(n.from,e.x-n.start.x,e.y-n.start.y));return}case`resize`:{let e=Za(t.x,t.y,k,f);v(n.key,Wa(n.from,n.handle,e));return}case`draw`:{let e=Za(t.x,t.y,k,f);w(La(n.start,e));return}default:return}},I=e=>{if(!D.current.has(e.pointerId))return;D.current.delete(e.pointerId);let t=O.current;if(t.mode===`pinch`){D.current.size<2&&(O.current={mode:`none`});return}if(t.mode===`draw`){let n=M(j(e)),r=n===null?null:La(t.start,n);w(null),O.current={mode:`none`},r!==null&&za(r)?g(r):h(null);return}N()},L=s.find(e=>e.key===c),R=T||m,ee=k===null?null:eo(k,f);return r(`div`,{ref:b,"data-testid":`retrain-canvas`,className:`relative w-full h-full min-h-[280px] bg-surface-sunken select-none touch-none overflow-hidden`,style:{cursor:R?`grab`:`crosshair`},onPointerDown:P,onPointerMove:F,onPointerUp:I,onPointerCancel:I,children:[ee!==null&&u(`img`,{src:n,alt:`Frame being annotated`,draggable:!1,className:`absolute max-w-none pointer-events-none`,style:ee}),k!==null&&s.map(e=>{let t=$a(e.bbox,k,f),n=e.key===c,i=uo(e,n);return u(`div`,{"data-testid":`retrain-box-${e.key}`,"data-draft":e.draft?`true`:`false`,"data-source":e.source,className:`absolute pointer-events-none`,style:{left:t.left,top:t.top,width:t.width,height:t.height,border:`${n?`2px`:`1px`} ${i.dashed?`dashed`:`solid`} ${i.color}`,opacity:i.opacity},children:r(`span`,{className:`absolute -top-4 left-0 text-[10px] px-1 rounded whitespace-nowrap text-background`,style:{background:i.color},children:[e.label??e.macroClass,e.kind===`model_error`?` ✕`:``,e.draft?` ?`:``,e.flag!==void 0&&e.flag.verdict!==`confirmed`?` !`:``]})},e.key)}),k!==null&&L!==void 0&&Va.map(e=>{let t=Qa(Ga(L.bbox,e),k,f);return u(`div`,{"data-testid":`retrain-handle-${e}`,className:`absolute h-2.5 w-2.5 -translate-x-1/2 -translate-y-1/2 rounded-sm border border-background bg-primary pointer-events-none`,style:{left:t.x,top:t.y}},e)}),C!==null&&k!==null&&u(`div`,{className:`absolute border border-dashed border-primary pointer-events-none`,style:$a(C,k,f)})]})}n();function ho(){let[t,n]=l(qa),[r,i]=l(!1);return{viewport:t,setViewport:n,zoomIn:e(()=>{n(e=>to(e,ro(e),Ja))},[]),zoomOut:e(()=>{n(e=>to(e,ro(e),1/Ja))},[]),fit:e(()=>{n(qa)},[]),panMode:r,togglePan:e(()=>{i(e=>!e)},[])}}function go({view:e,canUndo:t,canRedo:n,onUndo:i,onRedo:a}){let o=Xa(e.viewport);return r(`div`,{className:`flex items-center gap-1 px-2 py-1 border-b border-border bg-surface`,children:[u(H,{variant:`ghost`,size:`sm`,"aria-label":`Zoom out`,onClick:e.zoomOut,children:u(Oe,{className:`h-3.5 w-3.5`})}),r(`span`,{className:`w-12 text-center text-[11px] tabular-nums text-foreground-subtle`,children:[Math.round(o*100),`%`]}),u(H,{variant:`ghost`,size:`sm`,"aria-label":`Zoom in`,onClick:e.zoomIn,children:u(ge,{className:`h-3.5 w-3.5`})}),u(H,{variant:`ghost`,size:`sm`,"aria-label":`Fit the whole frame`,disabled:o<=1,onClick:e.fit,children:u(Wt,{className:`h-3.5 w-3.5`})}),u(H,{variant:e.panMode?`secondary`:`ghost`,size:`sm`,"aria-label":`Pan tool`,"aria-pressed":e.panMode,onClick:e.togglePan,children:u(O,{className:`h-3.5 w-3.5`})}),u(`span`,{className:`flex-1`}),u(H,{variant:`ghost`,size:`sm`,"aria-label":`Undo`,disabled:!t,onClick:i,children:u(re,{className:`h-3.5 w-3.5`})}),u(H,{variant:`ghost`,size:`sm`,"aria-label":`Redo`,disabled:!n,onClick:a,children:u(Gt,{className:`h-3.5 w-3.5`})}),r(de,{children:[u(W,{"aria-label":`Keyboard shortcuts`,className:`inline-flex h-7 items-center rounded-md px-2 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:u(Ht,{className:`h-3.5 w-3.5`})}),r(L,{className:`w-80`,children:[u(`h3`,{className:`mb-2 text-xs font-semibold text-foreground`,children:`Keyboard and gestures`}),u(`table`,{className:`w-full text-[11px]`,children:u(`tbody`,{children:so.map(e=>r(`tr`,{className:`align-top`,children:[u(`td`,{className:`py-0.5 pr-2 font-mono whitespace-nowrap text-foreground`,children:e.keys}),u(`td`,{className:`py-0.5 text-foreground-subtle`,children:e.does})]},e.keys))})})]})]})]})}function _o(e){return{past:[],present:e,future:[],gestureBase:null}}function vo(e,t){let n=[...e,t];return n.length>100?n.slice(n.length-100):n}function yo(e,t){return t===e.present?e:{past:vo(e.past,e.present),present:t,future:[],gestureBase:null}}function bo(e,t){return{...e,present:t}}function xo(e){let t=e.past[e.past.length-1];return t===void 0?e:{past:e.past.slice(0,-1),present:t,future:[e.present,...e.future],gestureBase:null}}function So(e){let[t,...n]=e.future;return t===void 0?e:{past:vo(e.past,e.present),present:t,future:n,gestureBase:null}}function Co(e){return{...e,gestureBase:e.present}}function wo(e,t){return{...e,present:t}}function To(e){let t=e.gestureBase;return t===null?e:t===e.present?{...e,gestureBase:null}:{past:vo(e.past,t),present:e.present,future:[],gestureBase:null}}function Eo(e){return e.past.length>0}function Do(e){return e.future.length>0}n();function Oo(e,t){return typeof e==`function`?e(t):e}function ko(t){let[n,r]=l(()=>_o(t())),i=e(e=>{r(t=>yo(t,Oo(e,t.present)))},[]),a=e(e=>{r(_o(e))},[]),o=e(e=>{r(t=>bo(t,Oo(e,t.present)))},[]),s=e(()=>{r(e=>Co(e))},[]),c=e(e=>{r(t=>wo(t,Oo(e,t.present)))},[]),u=e(()=>{r(e=>To(e))},[]),d=e(()=>{r(e=>xo(e))},[]),f=e(()=>{r(e=>So(e))},[]);return{editor:n.present,setEditor:i,resetEditor:a,selectOnly:o,beginGesture:s,updateGesture:c,endGesture:u,undo:d,redo:f,canUndo:Eo(n),canRedo:Do(n)}}n();function Ao(e,t){let n=e.boxes.length;if(n===0)return null;let r=e.boxes.findIndex(t=>t.key===e.selectedKey),i=r<0?t===1?0:n-1:(r+t+n)%n;return e.boxes[i]?.key??null}function jo(e,t){let{history:n}=t,r=n.editor.selectedKey;switch(e.kind){case`next-frame`:return t.onNextFrame();case`prev-frame`:return t.onPrevFrame();case`toggle-complete`:return t.onToggleComplete();case`save`:return t.onSave();case`undo`:return n.canUndo?(n.undo(),!0):!1;case`redo`:return n.canRedo?(n.redo(),!0):!1;case`zoom-in`:return t.onZoomIn(),!0;case`zoom-out`:return t.onZoomOut(),!0;case`zoom-fit`:return t.onZoomFit(),!0;case`accept-all`:return n.setEditor(e=>pa(e)),!0;case`select-next`:case`select-prev`:{let t=Ao(n.editor,e.kind===`select-next`?1:-1);return t===null?!1:(n.selectOnly(e=>ga(e,t)),!0)}case`deselect`:return r===null?!1:(n.selectOnly(e=>ga(e,null)),!0);default:break}if(r===null)return!1;switch(e.kind){case`delete`:return n.setEditor(e=>ha(e,r)),!0;case`set-class`:return n.setEditor(t=>da(t,r,{macroClass:e.macroClass})),!0;case`accept`:return n.setEditor(e=>fa(e,r)),!0;case`toggle-model-error`:return n.setEditor(e=>ma(e,r)),!0;default:return!1}}function Mo(e,n){let r=t(n);r.current=n,d(()=>{if(!e)return;let t=e=>{if(e.defaultPrevented||e.isComposing)return;let t=oo({key:e.key,ctrlKey:e.ctrlKey,metaKey:e.metaKey,shiftKey:e.shiftKey,altKey:e.altKey,typing:ao(e.target)});t!==null&&jo(t,r.current)&&e.preventDefault()};return window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`keydown`,t)}},[e])}n();var No=`person`,Po={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 Fo({frames:n,activeFrameId:i,onActiveFrame:o,onFramesChanged:s,onSaved:c,setNotice:l}){let f=n.find(e=>e.frameId===i),p=f?.deviceId??null,m=ko(()=>sa([],[])),{editor:h,setEditor:g,resetEditor:_,selectOnly:v}=m,y=ho(),b=Le({frameIds:[i]}),x=Xe({frameId:i}),S=ot(),C=F(),E=Fe(),D=ee({deviceIds:p===null?[]:[p]},{enabled:p!==null,staleTime:3e4}),O=D.data?.[0]?.detection?.nodeId??null,k=We({nodeId:O??``},{enabled:O!==null,staleTime:3e4}),A=Ne({nodeId:O??``},{enabled:O!==null,staleTime:3e4}),j=Ae({deviceId:p??0},{enabled:p!==null,staleTime:3e4}),M=a(()=>ta({status:D.data?.[0],nodeDevices:k.data,schema:A.data,resolvedSteps:j.data?.steps}),[D.data,k.data,A.data,j.data]),N=t({stored:b.data,copy:f});N.current={stored:b.data,copy:f};let P=f!==void 0;d(()=>{y.fit();let{stored:e,copy:t}=N.current;_(sa((e??[]).filter(e=>e.mediaKey===i),t?.pipelineBoxes??[]))},[i,b.dataUpdatedAt,P,_,y.fit]);let I=e(async e=>{f!==void 0&&(await E.mutateAsync({...Zi(f),complete:e}),await s())},[f,E,s]),L=e(async e=>{if(f===void 0)return;if(l(null),M.kind!==`resolved`){l(Po[M.gap]);return}let t=await S.mutateAsync({...Zi(f),subject:e===`package`?{kind:`package`}:{kind:`objects`,modelId:M.modelId,minScore:M.minScore},nodeId:M.nodeId});if(t.kind===`refused`){l(t.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: ${t.reason}${t.detail===void 0?``:` — ${t.detail}`}`);return}let n=ca(h,t.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},draft:!0})));g(n.state),l(`${t.proposals.length} proposal${t.proposals.length===1?``:`s`} from ${t.modelId}`+(n.skipped>0?` — ${n.skipped} already on the frame`:``)+(t.belowThreshold>0?` — ${t.belowThreshold} more were below ${t.minScore.toFixed(2)}`:``)+`. Accept or correct each one; drafts are not saved.`)},[f,S,M,h,g,l]),R=e(e=>{g(t=>la(t,e,No))},[g]),z=e(async()=>{if(f===void 0)return;let e=ya(h);await C.mutateAsync({...Zi(f),annotations:[...xa(h)]}),await b.refetch(),await c?.(),l(e>0?`Annotations saved. ${String(e)} unconfirmed draft${e===1?` was`:`s were`} not saved.`:`Annotations saved.`)},[f,h,C,b,c,l]),B=x.data,V=Oa(h.boxes)&&f!==void 0,U=ya(h),te=n.map(e=>e.frameId),ne=e=>{let t=te.indexOf(i),n=te[t+e];return t<0||n===void 0?!1:(o(n),!0)};return Mo(!0,{history:m,onNextFrame:()=>ne(1),onPrevFrame:()=>ne(-1),onToggleComplete:()=>f===void 0||E.isPending?!1:(I(!f.complete),!0),onSave:()=>!V||C.isPending?!1:(z(),!0),onZoomIn:y.zoomIn,onZoomOut:y.zoomOut,onZoomFit:y.fit}),r(`div`,{className:`grid grid-cols-1 xl:grid-cols-[minmax(0,1fr)_minmax(0,380px)] gap-3`,children:[r(`div`,{className:`rounded-md border border-border overflow-hidden flex flex-col`,children:[u(go,{view:y,canUndo:m.canUndo,canRedo:m.canRedo,onUndo:m.undo,onRedo:m.redo}),B===void 0?r(`div`,{className:`flex items-center gap-2 p-6 text-xs text-foreground-subtle`,children:[u(T,{className:`h-3.5 w-3.5 animate-spin`}),`Loading the frame…`]}):u(mo,{imageSrc:`data:image/jpeg;base64,${B.base64}`,imageWidth:B.width,imageHeight:B.height,boxes:h.boxes,selectedKey:h.selectedKey,viewport:y.viewport,onViewportChange:y.setViewport,panMode:y.panMode,onSelect:e=>{v(t=>ga(t,e))},onDraw:R,onGestureStart:m.beginGesture,onGestureBox:(e,t)=>{m.updateGesture(n=>da(n,e,{bbox:t}))},onGestureEnd:m.endGesture})]}),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 flex-wrap`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Subjects`}),f?.origin===`recording`&&u(J,{variant:`info`,children:`from the recording`}),r(H,{variant:`secondary`,size:`sm`,disabled:S.isPending||M.kind!==`resolved`,onClick:()=>void L(`objects`),children:[u(ue,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Propose`})]}),r(H,{variant:`secondary`,size:`sm`,disabled:S.isPending||M.kind!==`resolved`,onClick:()=>void L(`package`),children:[u(ue,{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:M.kind===`resolved`?`Proposals come from ${M.modelId} at ${M.minScore.toFixed(2)}, on ${M.nodeId} — what this camera really runs.`:Po[M.gap]}),f!==void 0&&u(Fa,{frame:f,history:m,detector:M,schema:A.data,setNotice:l}),u(`div`,{className:`flex-1 overflow-y-auto`,children:u(Da,{boxes:h.boxes,selectedKey:h.selectedKey,onSelect:e=>{v(t=>ga(t,e))},onChange:(e,t)=>{g(n=>da(n,e,t))},onAccept:e=>{g(t=>fa(t,e))},onToggleModelError:e=>{g(t=>ma(t,e))},onDelete:e=>{g(t=>ha(t,e))}})}),r(`label`,{className:`px-3 py-2 border-t border-border flex items-center gap-2 text-[11px] text-foreground`,children:[u(w,{"aria-label":`All subjects in this frame are boxed`,checked:f?.complete===!0,disabled:f===void 0||E.isPending,onChange:e=>void I(e.target.checked)}),r(`span`,{className:`flex-1`,children:[`All subjects boxed`,u(`span`,{className:`block text-foreground-subtle`,children:`Detector evaluation uses only these frames — an unboxed person counts as a false alarm. A frame with nothing in it, ticked, is a negative example.`})]})]}),U>0&&r(`div`,{className:`px-3 py-2 border-t border-border flex items-center gap-2 text-[11px] text-warning`,children:[r(`span`,{className:`flex-1`,children:[U,` draft`,U===1?``:`s`,` not confirmed — a draft is never saved. Accept, correct or delete each one.`]}),r(H,{variant:`secondary`,size:`sm`,onClick:()=>{g(e=>pa(e))},children:[u(Ot,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Accept all`})]})]}),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:[h.boxes.filter(e=>e.kind===`model_error`).length,` marked as model errors`]}),u(H,{size:`sm`,disabled:!V||C.isPending,onClick:()=>void z(),children:`Save frame`})]})]})]})}n();var Io={"empty-name":`Give the collection a name.`,"duplicate-name":`A collection with that name already exists.`,"unknown-collection":`That collection no longer exists.`};function Lo(){let[t,n]=l(`tracks`),[i,o]=l(null),[c,f]=l(null),[p,m]=l(null),[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]),x=lt({}),S=tt({trackId:i?.trackId??``},{enabled:t===`tracks`&&i!==null}),w=ie(),T=je(),E=C(),D=he({}),O=De({collectionId:c?.id??``},{enabled:t===`collections`&&c!==null}),A=Ce(),j=ce(),M=ze(),N=it(),P=t===`tracks`?S.data?.copies??[]:O.data??[],F=e(()=>t===`tracks`?S.refetch():O.refetch(),[t,S,O]);d(()=>{p===null&&P.length>0&&m(P[0].frameId)},[P,p]);let I=e(()=>{m(null),g(new Map),v(null)},[]),L=e(e=>{o(e),I()},[I]),ee=e(e=>{f(e),I()},[I]),B=e(async e=>{if(i===null)return;let t=await w.mutateAsync({deviceId:i.deviceId,trackId:i.trackId,mediaIds:[e]});if(t.refused.length>0){let e=new Map(h);for(let n of t.refused)e.set(n.sourceMediaId,n.reason);g(e)}t.copied.length>0&&m(t.copied[0].frameId),await S.refetch(),await x.refetch()},[i,w,h,S,x]),V=e(async e=>{let t=(S.data?.copies??[]).find(t=>t.frameId===e);t!==void 0&&(await T.mutateAsync(Zi(t)),p===e&&m(null),await S.refetch(),await x.refetch(),await D.refetch())},[S,T,p,x,D]),U=e(async()=>{if(i===null)return;let e=await E.mutateAsync({deviceId:i.deviceId,trackId:i.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 x.refetch(),e.changed&&o(null)},[i,E,x]),te=e(async e=>{let t=await A.mutateAsync({name:e});return await D.refetch(),t.kind===`refused`?Io[t.reason]??t.reason:(f(t.collection),I(),null)},[A,D,I]),ne=e(async(e,t)=>{let n=await j.mutateAsync({id:e,name:t});return await D.refetch(),n.kind===`refused`?Io[n.reason]??n.reason:(c?.id===e&&f(n.collection),null)},[j,D,c]),W=e(async e=>{let t=await M.mutateAsync({id:e});c?.id===e&&(f(null),I()),await D.refetch(),v(t.deleted?`Collection deleted${t.removedFrames>0?` — ${String(t.removedFrames)} recording frame${t.removedFrames===1?``:`s`} no other collection held left the dataset`:``}.`:`That collection no longer existed.`)},[M,c,D,I]),G=e(async e=>{if(c===null)return;let t=await N.mutateAsync({collectionId:c.id,frameId:e.frameId});p===e.frameId&&m(null),await O.refetch(),await D.refetch(),v(t.deletedFrame?`Removed — it was a recording frame no other collection held, so it left the dataset with its boxes.`:`Removed from the collection.`)},[c,N,p,O,D]),re=e(async()=>{await x.refetch()},[x]),K=t===`tracks`?i!==null:c!==null,ae=P.some(e=>e.frameId===p);return r(kt,{subtitle:`Turn marked tracks and frames sent from recordings into an annotated dataset. Every frame is a copy the dataset owns — it never depends on media that can be swept.`,actions:t===`tracks`&&i!==null?r(H,{size:`sm`,onClick:()=>void U(),children:[u(R,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Complete track`})]}):null,children:[_!==null&&u(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-xs text-foreground`,children:_}),u(Wi,{}),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:[u(k,{value:t,onValueChange:e=>{n(e===`collections`?`collections`:`tracks`),I()},children:r(z,{className:`px-2 pt-2`,children:[r(le,{value:`tracks`,children:[`Tracks `,u(J,{className:`ml-1`,children:x.data?.length??0})]}),r(le,{value:`collections`,children:[`Collections `,u(J,{className:`ml-1`,children:D.data?.length??0})]})]})}),t===`tracks`?u(Xi,{tracks:x.data??[],isLoading:x.isLoading,selectedTrackId:i?.trackId??null,deviceNames:b,onSelect:L}):u(Ui,{collections:D.data??[],isLoading:D.isLoading,selectedId:c?.id??null,onSelect:ee,onCreate:te,onRename:ne,onDelete:W})]}),u(`section`,{className:`space-y-3 min-w-0`,children:K?r(s,{children:[u(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:t===`tracks`?u(Ki,{candidates:S.data?.candidates??[],copies:S.data?.copies??[],activeFrameId:p,refusals:h,isSelecting:w.isPending,onSelectCandidate:e=>void B(e),onOpenCopy:m,onRemoveCopy:e=>void V(e),renderCopyActions:e=>u(Bi,{frameId:e.frameId,onAdded:()=>D.refetch()})}):u(Hi,{frames:O.data??[],isLoading:O.isLoading,activeFrameId:p,deviceNames:b,onOpen:m,onRemove:e=>void G(e)})}),p!==null&&ae&&u(Fo,{frames:P,activeFrameId:p,onActiveFrame:m,onFramesChanged:F,onSaved:re,setNotice:v})]}):u(`p`,{className:`text-xs text-foreground-subtle`,children:t===`tracks`?`Pick a track from the staging list to start annotating it.`:`Pick or create a collection.`})})]})]})}function Ro(){return u(`div`,{className:`flex flex-col p-4`,children:u(Ft,{tabs:[{id:`feed`,label:`Feed`,icon:dt,content:u(zi,{})},{id:`retrain`,label:`Retrain`,icon:R,content:u(Lo,{})},{id:`debug`,label:`Debug`,icon:st,content:u(fi,{})}]})})}export{Ro as EventsPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Q as e,S as t,W as n,a as r,b as i,o as a,q as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as c,gt as l,ht as u,st as d,vt as f}from"./player-overlays-tKtUzh3g.js";import{$l as p,$u as m,Ad as h,Bl as g,Cr as _,Fd as v,Gl as y,H as b,Hl as x,Id as S,In as C,Jl as w,Jn as ee,Kl as te,Ku as T,Ll as E,M as D,Md as ne,N as O,Nt as re,Pd as ie,Ql as k,Qu as A,Rl as ae,U as j,Ul as M,Vl as N,Wl as P,Xl as F,Yd as I,Yl as L,Zl as oe,ff as R,gd as se,gf as ce,hu as z,ku as le,ql as ue,qn as B,rf as de,sa as fe,tr as pe,vd as me,wr as V,yu as H,zl as he}from"./src-Y4G_LfLc.js";import{t as ge}from"./unlink-m4c0iz87.js";import{a as _e,i as ve,o as ye,s as be}from"./client-HDm3z1QL.js";import{$ as xe,F as U,G as Se,o as Ce,s as we}from"./index-d2QAhmc-.js";import{t as W}from"./AdminPage-BSFohA3i.js";import{t as Te}from"./AdminTabs-jmzYA4Gj.js";import{n as Ee,r as De,t as Oe}from"./IntegrationHub-3NtGsJ8f.js";import{n as ke,t as Ae}from"./addon-display-names-BkwMrExv.js";var je=f(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),Me=f(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]),Ne=f(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]);e();function Pe({userId:e,username:n,onClose:r}){let i=B(),a=z.useUtils(),o=M({userId:e}),c=z.auth.listLoginMethods.useQuery(),l=k({onSuccess:()=>void a.userManagement.listExternalIdentities.invalidate()}),u=new Map((c.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),d=o.data??[],f=async(t,r)=>{await i({title:`Remove sign-in link`,message:`"${n}" will no longer be able to sign in with this ${r} account.`,confirmLabel:`Remove`,variant:`danger`})&&l.mutate({userId:e,provider:t.provider,subject:t.subject})};return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:t(`div`,{"data-testid":`external-identities-modal`,className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[t(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[t(`div`,{className:`flex items-center gap-2`,children:[s(ne,{className:`h-4 w-4 text-primary`}),t(`div`,{children:[s(`div`,{className:`text-sm font-medium text-foreground`,children:`Linked sign-in accounts`}),t(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,s(`span`,{className:`font-mono`,children:n})]})]})]}),s(`button`,{onClick:r,"aria-label":`Close`,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:s(H,{className:`h-4 w-4`})})]}),t(`div`,{className:`p-4 space-y-3`,children:[o.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(h,{className:`h-3.5 w-3.5 animate-spin`}),`Loading…`]}):d.length===0?s(`p`,{className:`text-xs text-foreground-subtle`,children:`No linked accounts. Only the user can link one, from their own profile page.`}):s(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:d.map(e=>{let n=u.get(e.provider),r=n??e.provider;return t(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[t(`div`,{className:`flex-1 min-w-0`,children:[t(`div`,{className:`font-medium text-foreground truncate`,children:[r,n===void 0&&s(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:`provider unavailable`})]}),t(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:[e.label??e.subject,` ·`,` `,new Date(e.linkedAt).toLocaleDateString()]})]}),t(`button`,{onClick:()=>void f(e,r),disabled:l.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[s(ge,{className:`h-3 w-3`}),`Remove`]})]},`${e.provider}|${e.subject}`)})}),s(`div`,{className:`flex justify-end`,children:s(C,{onClick:r,variant:`secondary`,children:`Close`})})]})]})})}function Fe({userId:e,username:n,onClose:r}){let o=a(),c=B(),l=N({userId:e}),u=l.data,d=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),f=g({onSuccess:()=>{d(),r()}}),p=l.isLoading?`loading`:u?.enabled?`enrolled`:`not_enrolled`;return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[t(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[t(`div`,{className:`flex items-center gap-2`,children:[s(T,{className:`h-4 w-4 text-primary`}),t(`div`,{children:[s(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),t(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,s(`span`,{className:`font-mono`,children:n})]})]})]}),s(`button`,{onClick:r,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:s(H,{className:`h-4 w-4`})})]}),t(`div`,{className:`p-4 space-y-4`,children:[p===`loading`&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(h,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),p===`not_enrolled`&&t(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[s(S,{className:`h-4 w-4 mt-0.5 shrink-0`}),t(`div`,{children:[s(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),s(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),p===`enrolled`&&u&&t(i,{children:[t(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[s(R,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),t(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[s(`div`,{className:`font-medium`,children:`2FA is active`}),t(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,u.confirmedAt?new Date(u.confirmedAt).toLocaleString():`—`]})]})]}),s(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),t(`div`,{className:`flex justify-end gap-2`,children:[s(C,{onClick:r,variant:`secondary`,children:`Close`}),t(`button`,{onClick:async()=>{await c({title:`Remove 2FA`,message:`Remove two-factor authentication for "${n}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&f.mutate({userId:e})},disabled:f.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[f.isPending?s(h,{className:`h-3 w-3 animate-spin`}):s(H,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function G({icon:e,label:n,count:r,all:i,total:a}){return t(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[s(e,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(`span`,{className:`min-w-0 flex-1 text-foreground-subtle`,children:n}),s(`span`,{className:r===0?`text-foreground-subtle`:`font-medium text-foreground`,children:r===0?`none`:i?`all ${a}`:`${r} of ${a}`})]})}function Ie({scopes:e,isAdmin:n,invalidReason:a}){let o=c(),l=r({queryKey:[`auth`,`previewScope`,e,n],enabled:a===null,queryFn:()=>o.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:n})}),{data:u}=fe({projection:`slim`}),f=u?.length??0;if(a!==null)return s(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:t(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,children:[s(m,{className:`h-3 w-3 shrink-0`}),a]})});if(l.isLoading)return t(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface p-3 text-[11px] text-foreground-subtle`,children:[s(h,{className:`h-3 w-3 animate-spin`}),`Resolving…`]});if(l.isError||!l.data)return s(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:s(`p`,{className:`text-[11px] text-danger`,children:`Could not resolve this grant set. Saving is still allowed — the server enforces the same rules either way.`})});let p=l.data;return s(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:p.isAdmin?t(`p`,{className:`text-[11px] text-foreground`,children:[s(`span`,{className:`font-medium`,children:`Administrator`}),` — unrestricted. Grants are ignored for an admin.`]}):t(i,{children:[s(G,{icon:I,label:`Devices they can see`,count:p.device.view.deviceCount,all:p.device.view.all,total:f}),s(G,{icon:me,label:`Devices they can operate`,count:p.device.create.deviceCount,all:p.device.create.all,total:f}),s(G,{icon:d,label:`Devices they can delete`,count:p.device.delete.deviceCount,all:p.device.delete.all,total:f}),t(`div`,{className:`border-t border-border pt-2 text-[10px] text-foreground-subtle`,children:[`System access: `,p.system.length===0?`none`:p.system.join(`, `),p.capabilities.length>0&&t(i,{children:[` · Extra capabilities: `,p.capabilities.map(e=>e.name).join(`, `)]}),p.addons.length>0&&t(i,{children:[` · Addons: `,p.addons.map(e=>e.name).join(`, `)]})]}),p.device.view.deviceCount===0&&s(`p`,{className:`text-[10px] text-warning`,children:`This user will not be able to see any device.`})]})})}function Le(e){let t=ye(e);return t===null?{mode:e.length===0?`role`:`advanced`,roleId:null,selector:{kind:`all`},includeLinked:!0,advancedScopes:e}:{mode:`role`,roleId:t.roleId,selector:t.selector,includeLinked:t.includeLinked,advancedScopes:e}}function Re(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:_e({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function ze({user:e,onClose:r,onSubmit:a,submitting:c,callerScopes:d}){let f=n(()=>Le(e.scopes??[]),[e.scopes]),[p,g]=o(f),[_,v]=o(f.mode===`advanced`),y=n(()=>Re(p),[p]),x=!e.isAdmin&&p.mode===`role`&&p.roleId===null,S=n(()=>e.isAdmin?null:p.mode===`role`&&p.roleId===null?`Pick what this user can do to see the result.`:O(y),[e.isAdmin,p.mode,p.roleId,y]),C=e=>g({...p,...e});return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4 pt-[calc(1rem+env(safe-area-inset-top))] pb-[calc(1rem+env(safe-area-inset-bottom))]`,children:t(`div`,{className:`flex max-h-full w-full max-w-2xl flex-col rounded-lg border border-border bg-surface shadow-xl`,children:[t(`div`,{className:`flex shrink-0 items-start justify-between border-b border-border px-4 py-3`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Access — `,e.username]}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`This user is an administrator — they can do everything, and the settings below are ignored.`:`Choose what they can do, then which devices it applies to.`})]}),s(`button`,{onClick:r,className:`shrink-0 text-foreground-subtle hover:text-foreground`,title:`Close`,children:s(H,{className:`h-4 w-4`})})]}),t(`div`,{className:`min-h-0 flex-1 space-y-4 overflow-y-auto px-4 py-4`,children:[x&&t(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[s(m,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),t(`p`,{className:`text-[11px] text-foreground`,children:[s(`span`,{className:`font-medium`,children:`No access.`}),` `,t(`span`,{className:`text-foreground-subtle`,children:[e.username,` cannot see or do anything yet. Configure it below.`]})]})]}),t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`1 · What can they do`}),s(`div`,{className:`space-y-1.5`,children:ve.map(e=>{let n=p.mode===`role`&&p.roleId===e.id;return t(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-lg border p-2.5 transition-colors ${n?`border-primary bg-primary/5`:`border-border hover:bg-foreground-subtle/5`}`,children:[s(`input`,{type:`radio`,name:`access-role`,checked:n,onChange:()=>C({mode:`role`,roleId:e.id}),className:`mt-0.5 border-border focus:ring-primary`}),t(`span`,{className:`min-w-0`,children:[s(`span`,{className:`block text-[12px] font-medium text-foreground`,children:e.label}),s(`span`,{className:`mt-0.5 block text-[10px] text-foreground-subtle`,children:e.description})]})]},e.id)})}),t(`button`,{type:`button`,onClick:()=>{if(!_){g({...p,mode:`advanced`,advancedScopes:y}),v(!0);return}v(!1),g(Le(p.advancedScopes))},className:`inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] text-foreground-subtle transition-colors hover:bg-foreground-subtle/10 hover:text-foreground`,children:[s(_?l:u,{className:`h-3 w-3`}),`Advanced — edit raw grants`]}),_&&t(`div`,{className:`rounded-lg border border-border p-2`,children:[s(`p`,{className:`mb-2 text-[10px] text-foreground-subtle`,children:`One row per grant. Anything expressible here overrides the three roles above; close this section to go back to them.`}),s(D,{value:p.advancedScopes,onChange:e=>C({mode:`advanced`,advancedScopes:e}),clampToParent:d,emptyHint:t(i,{children:[`No grants.`,` `,s(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until one is added.`]})})]})]}),p.mode===`role`&&t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`2 · On which devices`}),s(b,{value:p.selector,onChange:e=>C({selector:e}),includeLinked:p.includeLinked,onIncludeLinkedChange:e=>C({includeLinked:e}),clampToDeviceIds:null})]}),t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:p.mode===`role`?`3 · Result`:`2 · Result`}),s(Ie,{scopes:y,isAdmin:e.isAdmin,invalidReason:S})]})]}),t(`div`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[s(`button`,{onClick:r,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>a([...y]),disabled:c||S!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:c?s(h,{className:`h-3 w-3 animate-spin`}):`Save access`})]})]})})}e();var Be=8;function Ve(){let e=a(),{user:n}=U(),[r,i]=o(!1),[c,l]=o(``),[u,f]=o(``),[m,g]=o(!1),[_,v]=o(null),{data:y,isLoading:b,isError:x}=te(),S=B(),C=ee(),w=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),E=ae({onSuccess:()=>{w(),i(!1),l(``),f(``),g(!1),v(null)},onError:e=>{v(e instanceof Error?e.message:`Failed to create user`)}}),D=he({onSuccess:w}),O=p({onSuccess:w}),k=ue({onSuccess:w}),j=oe({onSuccess:()=>{w(),N(null)}}),[M,N]=o(null),[P,F]=o(null),[I,L]=o(null),R=y??[];async function ce(e){await S({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&D.mutate({id:e.id})}async function z(e){let t=await C({title:`Reset password`,message:`Set a new password for "${e.username}".`,label:`New password`,inputType:`password`,placeholder:`At least 8 characters`,confirmLabel:`Continue`,validate:e=>e.length<Be?`Password must be at least ${String(Be)} characters.`:null});t===null||t.length===0||await S({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&k.mutate({id:e.id,newPassword:t})}function le(e,t){t!==e.isAdmin&&O.mutate({id:e.id,isAdmin:t})}function de(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return t(W,{children:[s(`div`,{className:`flex items-center justify-end`,children:t(`button`,{onClick:()=>i(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm hover:bg-primary/90`,children:[s(se,{className:`h-3.5 w-3.5`}),`Create User`]})}),r&&t(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[t(`div`,{className:`flex items-center justify-between`,children:[s(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),s(`button`,{onClick:()=>i(!1),className:`text-foreground-subtle hover:text-foreground`,children:s(H,{className:`h-4 w-4`})})]}),t(`div`,{className:`grid grid-cols-3 gap-3`,children:[t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),s(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`john`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),s(`input`,{type:`password`,value:u,onChange:e=>f(e.target.value),placeholder:`••••••••`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),t(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:m,onChange:e=>g(e.target.checked),className:`rounded border-border focus:ring-primary`}),s(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),_&&s(`p`,{className:`text-[10px] text-danger`,children:_}),t(`div`,{className:`flex justify-end gap-2`,children:[s(`button`,{onClick:()=>i(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>E.mutate({username:c,password:u,isAdmin:m}),disabled:E.isPending||!c||!u,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:E.isPending?`Creating...`:`Create`})]})]}),b&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),x&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!b&&!x&&R.length===0&&s(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>D.isPending&&D.variables?.id===e.id||O.isPending&&O.variables?.id===e.id||k.isPending&&k.variables?.id===e.id;return s(re,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:n=>t(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:n.isAdmin,onChange:e=>le(n,e.target.checked),disabled:e(n),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),s(`span`,{className:n.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:n.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Access`,render:e=>e.isAdmin?s(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`everything (admin)`}):t(`button`,{onClick:()=>N(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] hover:bg-foreground-subtle/10`,title:`Configure access`,children:[s(A,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(He,{scopes:e.scopes??[]})]})},{key:`createdAt`,header:`Created`,render:e=>s(`span`,{className:`text-foreground-subtle`,children:de(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:r=>{let i=e(r);return t(`div`,{className:`flex items-center justify-end gap-1`,children:[r.id!==n?.id&&r.totpEnabled&&t(`button`,{onClick:()=>F(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[s(T,{className:`h-3 w-3`}),`Remove 2FA`]}),t(`button`,{onClick:()=>L(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Linked sign-in accounts`,children:[s(ne,{className:`h-3 w-3`}),`Sign-in links`]}),t(`button`,{onClick:()=>z(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[s(ie,{className:`h-3 w-3`}),`Reset password`]}),t(`button`,{onClick:()=>ce(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete user`,children:[i?s(h,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:R,rowKey:e=>e.id,minWidthPx:560})})(),P&&s(Fe,{userId:P.id,username:P.username,onClose:()=>F(null)}),I&&s(Pe,{userId:I.id,username:I.username,onClose:()=>L(null)}),M&&s(Ue,{user:M,onClose:()=>N(null),onSubmit:e=>j.mutate({userId:M.id,scopes:e}),submitting:j.isPending})]})}function He({scopes:e}){if(e.length===0)return s(`span`,{className:`font-medium text-warning`,children:`No access`});let n=ye(e);return n===null?t(`span`,{className:`text-foreground-subtle`,children:[`Custom · `,e.length,` grant`,e.length===1?``:`s`]}):t(`span`,{className:`text-foreground-subtle`,children:[s(`span`,{className:`font-medium text-foreground`,children:be(n.roleId).label}),` ·`,` `,j(n.selector)]})}function Ue(e){let{user:t}=U(),n=t?.isAdmin===!0;return s(ze,{...e,callerScopes:n?null:t?.scopes??[]})}e();var We=`bg-primary/10 text-primary`,Ge=`bg-foreground-subtle/10 text-foreground-subtle`;function K(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function Ke(e){return e?e===`*`?`*`:e.join(`, `):``}function qe(){let e=a(),r=B(),{data:i,isLoading:c}=x(),{data:l}=te(),u=n(()=>i??[],[i]),f=n(()=>l??[],[l]),p=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),m=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[g,_]=o(!1),[v,y]=o(null),b=w({onSuccess:p}),S=E({onSuccess:({token:e,record:t})=>{m(),_(!1),y({token:e,label:t.name})}}),C=F({onSuccess:m}),ee=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&b.mutate({id:e})},T=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&C.mutate({id:e})};return t(W,{children:[t(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[s(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius.`}),t(`button`,{onClick:()=>_(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,disabled:f.length===0,title:f.length===0?`Create a user first`:`Issue a scoped token`,children:[s(A,{className:`h-3.5 w-3.5`}),`New token`]})]}),t(Je,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[f.length===0&&s(Xe,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),f.map(e=>s(Qe,{userId:e.id,username:e.username,onRevoke:(e,t)=>{T(e,t)},revokePending:C.isPending,revokeId:C.variables?.id},e.id))]}),u.length>0&&s(Je,{title:`Legacy API keys`,subtitle:`${u.length} pre-existing — revoke only`,children:s(Ze,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:u.map(e=>{let n=!!e.isAdmin,r=b.isPending&&b.variables?.id===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${n?We:Ge}`,children:n?`admin`:`regular`})}),t(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:Ke(e.allowedProviders)||`all`}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:K(e.createdAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:K(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:t(`button`,{onClick:()=>{ee(e.id,e.label)},disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[r?s(h,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),c&&s(Ye,{}),g&&s($e,{users:f.map(e=>({id:e.id,username:e.username})),onClose:()=>_(!1),onSubmit:e=>S.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:S.isPending}),v&&s(et,{token:v.token,label:v.label,onClose:()=>y(null)})]})}function Je({title:e,subtitle:n,children:r}){return t(`div`,{className:`space-y-2`,children:[t(`div`,{className:`flex items-baseline justify-between`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&s(`span`,{className:`text-[10px] text-foreground-subtle`,children:n})]}),r]})}function Ye(){return s(`div`,{className:`space-y-2`,children:[1,2].map(e=>s(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function Xe({text:e}){return s(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function Ze({headers:e,rows:n}){return s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:s(`tr`,{children:e.map((t,n)=>s(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),s(`tbody`,{children:n})]})})}function Qe({userId:e,username:n,onRevoke:r,revokePending:i,revokeId:a}){let{data:o,isLoading:c}=y({userId:e}),l=o??[];return c||l.length===0?null:t(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-medium text-foreground`,children:n}),s(Ze,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:l.map(e=>{let n=i&&a===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),t(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,n)=>t(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:[e.type,`:`,e.type===`device`?`[${j(e.selector)}]`:e.target]},n))})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:K(e.expiresAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:K(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:K(e.createdAt)}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:t(`button`,{onClick:()=>r(e.id,e.name),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[n?s(h,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function $e({users:e,onClose:n,onSubmit:r,submitting:i}){let{user:a}=U(),c=a?.isAdmin===!0?null:a?.scopes??[],[l,u]=o(e[0]?.id??``),[d,f]=o(``),[p,m]=o([{type:`capability`,target:``,access:[`view`,`create`]}]),[g,_]=o(``),v=O(p),y=l!==``&&d.trim().length>0&&p.length>0&&v===null&&!i;return t(q,{title:`Create scoped token`,onClose:n,children:[t(`div`,{className:`space-y-3`,children:[s(J,{label:`On behalf of user`,children:s(`select`,{value:l,onChange:e=>u(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>s(`option`,{value:e.id,children:e.username},e.id))})}),s(J,{label:`Name`,children:s(`input`,{value:d,onChange:e=>f(e.target.value),placeholder:`cloudflare-tunnel-route`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})}),t(J,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[s(D,{value:p,onChange:m,clampToParent:c}),v&&s(`p`,{className:`mt-1 text-[10px] text-danger`,children:v})]}),s(J,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:s(`input`,{type:`number`,min:1,value:g,onChange:e=>_(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),t(tt,{children:[s(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),t(`button`,{onClick:()=>{let e=parseInt(g,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;r({userId:l,name:d.trim(),scopes:p,expiresAt:t})},disabled:!y,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[i?s(h,{className:`h-3.5 w-3.5 animate-spin`}):s(A,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function et({token:e,label:n,onClose:r}){let[i,a]=o(!1),c=async()=>{try{await navigator.clipboard.writeText(e),a(!0)}catch{}};return t(q,{title:`Token: ${n}`,onClose:r,children:[t(`div`,{className:`space-y-3`,children:[s(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),s(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),t(tt,{children:[t(`button`,{onClick:()=>{c()},className:`inline-flex items-center gap-1.5 rounded bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[i?s(ce,{className:`h-3.5 w-3.5 text-primary`}):s(de,{className:`h-3.5 w-3.5`}),i?`Copied`:`Copy`]}),s(`button`,{onClick:r,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function q({title:e,onClose:n,children:r}){return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[t(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),s(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:s(H,{className:`h-4 w-4`})})]}),s(`div`,{className:`p-4`,children:r})]})})}function tt({children:e}){return s(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function J({label:e,hint:n,children:r}){return t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),r,n&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:n})]})}e();function Y(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function nt(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function rt(){return s(`div`,{className:`space-y-2`,children:[1,2].map(e=>s(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function it({text:e}){return s(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function at({headers:e,rows:n}){return s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:s(`tr`,{children:e.map((t,n)=>s(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),s(`tbody`,{children:n})]})})}function ot(){let e=a(),r=B(),{data:i,isLoading:o}=P(),c=n(()=>i??[],[i]),l=L({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),u=async(e,t)=>{await r({title:`Revoke "${t}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&l.mutate({id:e})};return t(W,{icon:Ne,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[o&&s(rt,{}),!o&&c.length===0&&s(it,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!o&&c.length>0&&s(at,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:c.map(e=>{let n=e.revokedAt!==null,r=(l.isPending?l.variables?.id:void 0)===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>s(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:nt(e)},t))})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:Y(e.createdAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:Y(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 border-b border-border`,children:n?t(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,Y(e.revokedAt)]}):s(`span`,{className:`inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300`,children:`Active`})}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!n&&t(`button`,{onClick:()=>{u(e.id,e.integrationId)},disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[r?s(h,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}e();var X=3e4,Z=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],Q={title:`Authentication`,subtitle:`Login providers (local password, OIDC, SAML, magic-link) and second-factor providers (passkeys / WebAuthn). They run in parallel — enable or disable each independently; disabling one only removes that method, local password login is unaffected.`,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,installLabel:`Add provider`};function $(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:Me,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA is self-enrolled: each user enables it from their own profile page (My access → Two-factor authentication).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:xe,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`Explicit linking only: an IdP account signs in only the CamStack user who linked it from their profile (My access → Linked sign-in accounts). No auto-created users, no email matching.`,`The linked user’s role, scopes and two-factor authentication apply.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.",`Paste issuer + credentials in the Settings panel below — saves on every change.`,`Each user then links their IdP account from My access → Linked sign-in accounts.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:xe,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:T,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:T,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:A,bullets:[`Generic authentication provider. No additional hints registered.`]}}function st(){let e=V({capName:Z[0].capName},{refetchInterval:X}),t=V({capName:Z[1].capName},{refetchInterval:X}),r=_(void 0,{refetchInterval:X}),i=n(()=>Ae(r.data??[]),[r.data]),a=n(()=>{let n=[],r=[e.data??[],t.data??[]];for(let[e,t]of Z.entries())for(let a of r[e]??[])n.push({addonId:a.addonId,displayName:i.get(a.addonId)??a.addonId,isActive:a.isActive,capName:t.capName,stageBadge:t.stageBadge});return n},[e.data,t.data,i]),o=[{id:`authentication`,label:`Authentication providers`,install:{capability:Z[0].capName,label:Q.installLabel},entries:a.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:A,...ke(e.isActive),render:()=>s(Ee,{addonId:e.addonId,displayName:e.displayName,capName:e.capName,isActive:e.isActive,badges:e.stageBadge===null?null:s(pe,{variant:`info`,className:De,children:e.stageBadge}),panels:[{id:`about`,title:`About`,icon:$(e.addonId).icon,content:s(ct,{addonId:e.addonId})}]})}))}];return s(Oe,{icon:A,title:Q.title,subtitle:Q.subtitle,groups:o,isLoading:e.isLoading||t.isLoading,emptyTitle:Q.emptyTitle,emptyDescription:Q.emptyDescription})}function ct({addonId:e}){let n=$(e),r=n.icon;return t(`div`,{className:`space-y-3 rounded-lg border border-border bg-surface p-2 sm:p-4`,children:[t(`div`,{className:`flex items-start gap-2.5`,children:[s(r,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),s(`div`,{className:`text-xs text-foreground font-medium`,children:n.headline})]}),s(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:n.bullets.map((e,t)=>s(`li`,{children:e},t))}),n.setupSteps&&n.setupSteps.length>0&&t(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[t(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[s(je,{className:`h-3 w-3`}),`Setup steps`]}),s(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:n.setupSteps.map((e,t)=>s(`li`,{children:e},t))})]}),e===`local-auth`&&t(`div`,{className:`rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[s(S,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),t(`span`,{children:[`TOTP / 2FA is self-service: each user enrols from their own profile page —`,` `,s(Se,{to:`/system/my-access`,className:`underline text-primary`,children:`My access`}),` `,`→ “Two-factor authentication” → Enable 2FA. Admins can only remove a user’s active enrollment (lost device) from the`,` `,s(Se,{to:`/system/identity?tab=users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function lt(){return s(`div`,{className:`flex flex-col p-4`,children:s(Te,{tabs:[{id:`users`,label:`Users`,icon:le,content:s(Ve,{})},{id:`api-keys`,label:`Tokens`,icon:v,content:s(qe,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:Ne,content:s(ot,{})},{id:we.authentication.tab,label:`Authentication`,icon:A,content:s(st,{}),ownedParams:Ce}]})})}export{lt as IdentityPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,W as i,b as a,o,q as s,x as c,z as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as u,at as d,gt as f,ht as p,mt as m,st as h,vt as g}from"./player-overlays-tKtUzh3g.js";import{$a as _,$i as v,Ad as y,Bi as b,Dt as x,Hi as S,It as C,Ji as w,K as T,Ki as E,Na as D,Pf as ee,Pu as O,Qa as k,Qi as A,Qt as j,Su as te,Ui as M,Vi as ne,Wi as re,Y as N,Yd as P,Za as F,_t as ie,au as ae,cu as I,df as L,dr as R,eo as z,fd as oe,fr as se,ga as ce,gd as le,gf as ue,id as B,io as V,kr as de,ld as H,ma as U,na as W,no as fe,pn as pe,q as me,qi as G,sa as he,sf as K,td as q,to as J,ud as ge,yu as _e}from"./src-Y4G_LfLc.js";import{Tr as ve}from"./client-HDm3z1QL.js";import{t as ye}from"./useTranslation-Bc5yH9V9.js";import"./mount-D_5ynS9o.js";import{J as be,K as xe,N as Se,q as Ce}from"./index-d2QAhmc-.js";import{t as we}from"./NodeAddonsSettingsPanel-BbRT6OqB.js";import{t as Te}from"./device-integration-icon-KaXkp2LK.js";import{n as Ee,r as Y,t as De}from"./ScanNetworkModal-Dq6vPLgX.js";var Oe=g(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);n();function ke(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...ke(n.fields));return t}function Ae(t,n,r){let[a,o]=s(`idle`),[c,l]=s({}),u=i(()=>{let e=[];for(let n of t.sections)e.push(...ke(n.fields));return e},[t]),d=u.length>0&&r!==void 0,f=e(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:e(async()=>{if(!r)return;let e=u.filter(e=>{let t=n[e];return t!=null&&String(t).trim()!==``});if(e.length===0)return;o(`testing`);let t={};for(let n of e)t[n]={status:`probing`};l(t);let i=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await r(e,n[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of i)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),o(`idle`)},[r,u,n]),clearProbeResult:f}}n();function je(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...je(n.fields));return t}function Me(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Ne(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Ne(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function X(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Pe({open:t,integrationId:n,addonId:a,onClose:u}){let{t:d}=ye(),p=o(),[m,h]=s({}),[g,_]=s(!1),[v,b]=s(null),[x,S]=s(X),C=U({addonId:a},{enabled:t}),w=C.data?.deviceType??null,T=W({addonId:a,type:w??ve.Camera},{enabled:t&&C.isSuccess&&w!==null}),E=T.data??null;l(()=>{t&&(h(E?Ne(E.sections.flatMap(e=>e.fields)):{}),S(X()),_(!1),b(null))},[t,n,E]);let ee=i(()=>({...m,_probeRequestId:x}),[m,x]),k=G({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),A=D(),j=e(async(e,t)=>{_(!0);let n=await A.mutateAsync({addonId:a,type:w??ve.Camera,key:e,value:t,formValues:ee});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Me(e[i])&&!Me(a)&&(r[i]=a,t=!0);return t?r:e}),n},[A,a,ee,w]),{testAllStatus:M,hasProbeFields:ne,probeResults:re,handleTestAll:N,clearProbeResult:P}=Ae(E??{sections:[]},m,j);async function F(e){b(null);try{await k.mutateAsync({addonId:a,type:w??ve.Camera,config:m,integrationId:n}),e?h(E?Ne(E.sections.flatMap(e=>e.fields)):{}):u()}catch(e){b(e instanceof Error?e.message:String(e))}}if(!t)return null;let ae=je((E?.sections??[]).flatMap(e=>e.fields)).filter(e=>Me(m[e])),I=ae.length===0,L=C.isLoading||w!==null&&T.isLoading,R=C.isError||C.isSuccess&&w===null||T.isError||T.isSuccess&&E===null;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),r(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:d(`integrations.addDevice`)}),c(`button`,{onClick:u,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:c(_e,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:L?c(`div`,{className:`flex items-center justify-center py-8`,children:c(y,{className:`h-5 w-5 animate-spin text-primary`})}):R?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[c(O,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`space-y-1`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,c(`span`,{className:`font-mono`,children:a}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):c(Se,{schema:E,values:m,onChange:h,onTestField:j,probeResults:re,onClearProbe:P})}),!R&&!L&&r(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[r(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[r(`span`,{className:`flex items-center gap-2`,children:[c(B,{className:`h-3.5 w-3.5`}),`Test logs`,c(`span`,{className:`font-mono text-[9px] opacity-60`,children:x.slice(0,14)})]}),c(f,{className:`h-3.5 w-3.5 transition-transform ${g?`rotate-180`:``}`})]}),g&&c(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:c(ie,{addonId:a,requestId:x,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!R&&!L&&(v||ae.length>0)&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(O,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:v||`Required: ${ae.join(`, `)}`})]})}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:u,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:d(`integrations.cancel`)}),!R&&ne&&r(`button`,{type:`button`,onClick:N,disabled:M===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[M===`testing`?c(y,{className:`h-3.5 w-3.5 animate-spin`}):c(te,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:()=>F(!0),disabled:R||!I||k.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:d(`integrations.saveAndNew`)}),c(`button`,{onClick:()=>F(!1),disabled:R||!I||k.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:k.isPending?d(`integrations.saving`):d(`integrations.save`)})]})]})]})]})}var Fe=1500;function Z({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=ye(),o=b(),s=(M({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Fe:!1}).data??[]).find(e=>e.jobId===n);if(!s)return null;let l=s.state===`running`,u=s.processed,d=s.total>0?Math.round(u/s.total*100):0;!l&&s.finishedAt!==null&&i();let f=[`${u}/${s.total} ${a(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];s.adopted>0&&f.push(`${s.adopted} ${a(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),s.alreadyAdopted>0&&f.push(`${s.alreadyAdopted} ${a(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),s.failed>0&&f.push(`${s.failed} ${a(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let p=f.join(` · `);return r(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[r(`div`,{className:`flex items-center gap-2`,children:[l?c(y,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):s.failed>0?c(O,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):s.state===`cancelled`?c(K,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):c(L,{className:`h-3.5 w-3.5 text-primary shrink-0`}),c(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&c(`button`,{onClick:()=>o.mutate({jobId:n}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),c(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:c(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),s.results.filter(e=>e.outcome===`failed`).slice(0,5).map(e=>r(`p`,{className:`text-[11px] text-destructive`,children:[e.childNativeId,`: `,e.error]},e.childNativeId))]})}function Ie(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}n();var Q=`devices`,Le={id:Q,label:`Devices`,isDefault:!0},Re=2e4,$=100;function ze({addonId:n,integrationId:i,onClose:a}){let{t:u}=ye(),d=o(),[f,p]=s(new Set),[m,h]=s(new Set),[g,v]=s(new Map),[b,x]=s(null),{data:C}=_(),w=(C??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[D,ee]=s(!0),k=ne({addonId:n,integrationId:i}).data?.filters,A=k&&k.length>0?k:[Le],[j,te]=s(A.find(e=>e.isDefault)?.id??(A.some(e=>e.id===Q)?Q:A[0].id)),M=j!==Q,N=re(),P=S({addonId:n,integrationId:i,page:1,pageSize:Re,filter:j}),F=P.refetch,ie=N.mutate,L=e(()=>{ie({addonId:n,integrationId:i},{onSettled:()=>{F()}})},[ie,n,i,F]),R=t(null);l(()=>{let e=`${n}::${i}`;R.current===e||P.isLoading||(R.current=e,(P.data?.candidates.length??0)===0&&L())},[n,i,P.isLoading,P.data,L]);let z=N.isPending,oe=N.isError?N.error instanceof Error?N.error.message:String(N.error):null,se=typeof N.data?.lastError==`string`&&N.data.lastError.length>0?N.data.lastError:null,ce=P.data?.candidates??[],le=P.isError?P.error instanceof Error?P.error.message:String(P.error):null,B=E(),[V,de]=s(null),U=e(e=>{e.alreadyAdopted||p(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),W=e(e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),fe=e((e,t)=>{v(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),pe=e(e=>{let t={};for(let n of e){let e=g.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[g]),me=e(async()=>{x(null);let e=[...f];if(e.length!==0)try{let t=pe(e),{jobId:r}=await B.mutateAsync({addonId:n,integrationId:i,filter:j,childNativeIds:e,...t?{perCandidate:t}:{},...w?{importLocations:D}:{}});de(r),p(new Set),v(new Map)}catch(e){x(e instanceof Error?e.message:String(e))}},[f,pe,B,n,i,j,w,D]),G=t(null),he=e(()=>{V===null||G.current===V||(G.current=V,F(),d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}))},[V,F,d]),K=e(e=>{te(e),p(new Set),h(new Set),v(new Map),x(null)},[]),q=f.size,J=V!==null&&q===0&&!B.isPending;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:a}),r(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[r(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:u(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),c(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:u(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),r(`div`,{className:`flex items-center gap-3 shrink-0`,children:[w&&r(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[c(`input`,{type:`checkbox`,checked:D,onChange:e=>ee(e.target.checked),className:`accent-primary`}),u(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),c(`button`,{onClick:a,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:c(_e,{className:`h-4 w-4`})})]})]}),r(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(oe??le??se)&&ce.length===0&&c(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(O,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`min-w-0`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:u(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),c(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:oe??le??se})]})]})}),A.length>1&&c(Be,{filters:A,activeFilter:j,onSelect:K}),c(`div`,{className:`flex-1 min-h-0`,children:c(T,{mode:`generic`,items:ce,pageSize:$,getKey:e=>e.childNativeId,getSearchText:Ie,getFilterType:e=>e.type,filterOptions:ae(),filterLabel:u(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:P.isLoading||z&&ce.length===0,searchPlaceholder:u(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(oe??le??se)&&ce.length===0?``:u(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:L,disabled:z,title:u(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[c(H,{className:`h-3.5 w-3.5 ${z?`animate-spin`:``}`}),u(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:u(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>c(Ve,{candidate:e,expandable:!M,expanded:m.has(e.childNativeId),onToggleExpand:()=>W(e.childNativeId),adoptedLabel:u(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:u(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=I(e.type),n=t.icon;return r(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[c(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>c(`div`,{className:`flex items-center justify-end`,children:c(`button`,{onClick:()=>U(e),disabled:e.alreadyAdopted,"aria-label":f.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${f.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:f.has(e.childNativeId)&&c(ue,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!M&&m.has(e.childNativeId),renderExpanded:M?void 0:e=>c(He,{candidate:e,hiddenChildIds:g.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>fe(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:f.has(e.childNativeId)?`bg-primary/5`:``})})]}),b&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(O,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:b})]})}),V!==null&&c(Z,{addonId:n,integrationId:i,jobId:V,onFinished:he}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[c(`div`,{}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:a,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:u(`integrations.cancel`,{defaultValue:`Cancel`})}),r(`button`,{onClick:J?a:me,disabled:!J&&(q===0||B.isPending),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[B.isPending&&c(y,{className:`h-3.5 w-3.5 animate-spin`}),J?u(`integrations.close`,{defaultValue:`Close`}):u(`integrations.addSelected`,{defaultValue:`Add selected`}),!J&&q>0?` (${q})`:``]})]})]})]})]})}function Be({filters:e,activeFilter:t,onSelect:n}){return c(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return c(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function Ve({candidate:e,expandable:t,expanded:n,onToggleExpand:i,adoptedLabel:a}){let o=(e.children??[]).length;return r(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&o>0?r(`button`,{type:`button`,onClick:i,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[c(n?f:p,{className:`h-3.5 w-3.5`}),o]}):c(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),c(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&c(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:a})]})}function He({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let i=e.children??[];return i.length===0?null:c(`div`,{className:`space-y-1 py-1`,children:i.map(e=>{let i=t.has(e.childNativeId),a=e.capabilities??[];return r(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${i?`opacity-50`:``}`,children:[c(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),a.length>0&&c(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:a.join(`, `)}),c(`button`,{onClick:()=>n(e.childNativeId),"aria-label":i?`Show child`:`Hide child`,title:i?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:c(i?m:P,{className:`h-3 w-3`})})]},e.childNativeId)})})}n();function Ue(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...Ue(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function We(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>Ue(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Ge(e){return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{if(`value`in e){let{value:t,...n}=e;return n}return e})}))}}function Ke({integrationId:e,addonId:t,name:n,kind:a,mode:s,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=ye(),m=o(),{data:h,isLoading:g}=z({id:e},{enabled:s===`account`||s===`broker`}),_=i(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:v,isLoading:b}=R({addonId:t,nodeId:`hub`},{enabled:s===`account`}),x=i(()=>v?Ge(v):null,[v]),S=fe(),C=(t,n)=>{S.mutate({id:e,settings:t,...n?{secretKeys:[...n]}:{}},{onSuccess:()=>{m.invalidateQueries(),f()}})};return c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:f,children:r(`div`,{className:`max-h-[85vh] w-full max-w-lg overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`mb-3 flex items-center justify-between`,children:[r(`h2`,{className:`text-sm font-semibold text-foreground`,children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),c(`button`,{onClick:f,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":p(`common.close`,{defaultValue:`Close`}),children:c(_e,{className:`h-4 w-4`})})]}),s===`broker`?l?r(`div`,{className:`space-y-3`,children:[c(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),_&&r(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,c(`span`,{className:`font-mono text-foreground-subtle`,children:_})]}),S.isPending?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(y,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):c(Y,{kind:l,onResolved:e=>{C({brokerId:e})},onBack:f}),S.isError&&c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):s===`account`?g||b?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(y,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):c(Ee,{addonId:t,configSchema:x,canTest:u,initialName:n,initialConfig:We(x,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e,secretKeys:t})=>C(e,t),onBack:f}):c(pe,{trpc:d,addonId:t,nodeId:`hub`,title:n})]})})}function qe(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}n();function Je(){let{t}=ye(),{integrationId:n}=Ce(),f=o(),p=xe(),[m,g]=be(),b=d(),[S,E]=s(!1),[D,te]=s(!1),[M,ne]=s(!1),[re,P]=s(!1),[ae,I]=s(!1),{data:L,isLoading:z}=k({id:n??``},{enabled:!!n}),{data:ue}=R({addonId:L?.addonId??``,nodeId:`hub`},{enabled:!!L?.addonId}),{data:H,isSuccess:U}=_(),W=i(()=>{let e=L?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[H,L?.addonId,U]),{data:fe}=A({}),pe=i(()=>(fe?.providers??[]).some(e=>e.addonId===L?.addonId),[fe,L?.addonId]),G=W!==null,K=L?.info?.fixed===!0,ve=G?W===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),Se=i(()=>{let e=L?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.brokerKind??null},[H,L?.addonId,U]),Ee=i(()=>{let e=L?.addonId;return!e||!U?!1:(H??[]).find(t=>t.addonId===e)?.canTest===!0},[H,L?.addonId,U]),Y=i(()=>{let e=L?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.mode??null},[H,L?.addonId,U]);l(()=>{m.get(`add`)===`1`&&G&&(E(!0),g(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[m,G,g]);let ke=ue!=null&&Array.isArray(ue.sections)&&ue.sections.some(e=>e.fields.length>0),{data:Ae}=se({addonId:L?.addonId??``,nodeId:`hub`},{enabled:!!L?.addonId&&Y!==`account`}),je=Y!==null&&Y!==`account`&&qe(Ae),Me=i(()=>L?.addonId?[L.addonId]:[],[L?.addonId]),{data:Ne}=he({projection:`slim`},{refetchInterval:3e4}),X=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Fe=V({onMutate:async e=>{await f.cancelQueries({queryKey:X});let t=f.getQueryData(X);return t!=null&&f.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&f.setQueryData(X,r.previous)},onSettled:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Z=F({onSuccess:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]}),P(!1),p(`/integrations`)}}),Ie=de({onSuccess:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=ce({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=w({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Re=v({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=i(()=>Ne??[],[Ne]),Be=i(()=>{let e=new Map;for(let t of $)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[$]),Ve=e(e=>Be.get(e)??null,[Be]),{data:He}=J(void 0),Ue=i(()=>me(He),[He]),We=e(e=>p(`/devices/${String(e)}`),[p]),Ge=i(()=>{let e=L?.id;return e?$.filter(t=>{let n=Ue(t);return n.kind===`resolved`&&n.integration.id===e}):[]},[$,L?.id,Ue]),Je=i(()=>He===void 0?null:N(Ge).length,[He,Ge])??`…`;return z?r(`div`,{className:`p-4`,children:[c(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),c(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):L?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[c(C,{items:[{label:`Integrations`,onClick:()=>p(`/integrations`)},{label:L.name}]}),r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`flex items-center gap-3 min-w-0`,children:[c(`img`,{src:u(`/api/addon-assets/${L.addonId}/assets/icon.svg`),alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),r(`div`,{className:`min-w-0`,children:[c(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:L.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[L.addonId,` · `,Je,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[pe&&r(`button`,{onClick:()=>te(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the network for devices (incl. a different subnet)`,children:[c(oe,{className:`h-3.5 w-3.5`}),`Scan network`]}),!K&&r(`button`,{onClick:()=>E(!0),disabled:!G,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:ve,children:[c(le,{className:`h-3.5 w-3.5`}),ve]}),r(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Fe.isPending?`opacity-60`:``} ${L.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[c(j,{checked:L.enabled,onCheckedChange:e=>Fe.mutate({id:n,enabled:e}),disabled:Fe.isPending,"aria-label":L.enabled?`Disable integration`:`Enable integration`}),c(`span`,{className:`text-[11px] font-medium ${L.enabled?`text-success`:`text-foreground-subtle`}`,children:L.enabled?`Enabled`:`Disabled`}),Fe.isPending&&c(y,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Y!==`standalone`&&(ke||W===`device-adoption`)&&r(`button`,{onClick:()=>ne(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[c(q,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>I(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrations.logs`,{defaultValue:`View logs`}),children:[c(B,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),c(x,{label:`Restart`,icon:ge,title:`Restart "${L.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Je} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Ie.isPending,action:()=>Ie.mutateAsync({addonId:L.addonId})}),!K&&r(`button`,{onClick:()=>P(!0),className:`flex items-center gap-1.5 rounded-lg border border-danger bg-danger/10 px-3 py-1.5 text-[11px] font-medium text-danger hover:bg-danger hover:text-background transition-colors`,title:t(`integrations.delete`,{defaultValue:`Delete integration`}),children:[c(h,{className:`h-3 w-3`}),t(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),je&&c(we,{nodeId:null,addonIds:Me,level:`global`,surface:`integration`,title:t(`integrations.settings`,{defaultValue:`Settings`})}),c(T,{context:`integration-detail`,devices:$,trpc:b.trpcClient,integrationOf:Ue,forceIntegrationId:L.id,urlScope:`root`,lsKey:`integration-detail:${L.addonId}`,resolveIntegrationIcon:Te,resolveParent:Ve,onNavigate:We,batchActions:{remove:Q.mutate,disable:Le.mutate,enable:Re.mutate},...K?{}:{onDeleteDevice:e=>Q.mutate({deviceId:e.id})}}),S&&n&&W===`device-adoption`&&c(ze,{addonId:L.addonId,integrationId:n,onClose:()=>E(!1)}),S&&n&&W===`device-provider`&&c(Pe,{open:S,integrationId:n,addonId:L.addonId,onClose:()=>E(!1)}),D&&L&&c(De,{open:D,scope:{addonId:L.addonId,label:L.name},onClose:()=>te(!1)}),M&&n&&W!==null&&Y!==null&&c(Ke,{integrationId:n,addonId:L.addonId,name:L.name,kind:W,mode:Y,brokerKind:Se,canTest:Ee,trpc:b.trpcClient,onClose:()=>ne(!1)}),ae&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>I(!1),children:r(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 min-w-0`,children:[c(B,{className:`h-4 w-4 text-primary shrink-0`}),c(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:L.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[L.addonId,n?` · ${n}`:``]})]}),c(`button`,{onClick:()=>I(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:c(_e,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:c(ie,{addonId:L.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),re&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Z.isPending&&P(!1),children:r(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`flex items-start gap-3`,children:[c(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:c(O,{className:`h-4 w-4 text-danger`})}),r(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),c(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:L.name,count:Je})})]})]}),Z.error&&c(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:Z.error instanceof Error?Z.error.message:String(Z.error)}),r(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[c(`button`,{onClick:()=>P(!1),disabled:Z.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:t(`integrations.cancel`,{defaultValue:`Cancel`})}),c(`button`,{onClick:()=>Z.mutate({id:n}),disabled:Z.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-danger px-3 py-1.5 text-[11px] font-medium text-background hover:bg-danger/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed`,children:Z.isPending?r(a,{children:[c(y,{className:`h-3 w-3 animate-spin`}),t(`integrations.deleting`,{defaultValue:`Deleting…`})]}):r(a,{children:[c(h,{className:`h-3 w-3`}),t(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):r(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[c(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:c(Oe,{className:`h-6 w-6 text-foreground-subtle`})}),r(`div`,{className:`space-y-1 max-w-sm`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),c(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:n??``})})]}),r(`button`,{onClick:()=>p(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[c(ee,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{Je as IntegrationDetailPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{D as e,K as t,L as n,Q as r,S as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{B as d,Z as f,ct as p}from"./player-overlays-tKtUzh3g.js";import{Ad as m,An as h,Dt as g,Fr as _,In as v,Md as y,Mt as b,Nn as x,Pn as S,Pu as C,_d as w,_t as ee,gd as T,gt as E,id as te,kr as ne,tr as re,ud as D,wf as O}from"./src-Y4G_LfLc.js";import{t as k}from"./settings-2-CCI879zJ.js";import"./mount-D_5ynS9o.js";import{G as A,J as j,a as M,c as N,d as P,f as F,l as I,p as L,u as R}from"./index-d2QAhmc-.js";import{t as z}from"./AdminPage-BSFohA3i.js";import{t as B}from"./NodeAddonsSettingsPanel-BbRT6OqB.js";r();var V=[[[`addons`,`listCapabilityProviders`]],[[`addons`,`list`]]],H=`text-[10px]`;function U({isActive:e}){return l(re,{variant:e?`success`:`default`,className:H,children:e?`Enabled`:`Disabled`})}function W({capName:e,addonId:t,isActive:n}){let r=s(),a=_({onSuccess:()=>{for(let e of V)r.invalidateQueries({queryKey:e})}}),o=a.isPending;return i(v,{size:`sm`,variant:n?`secondary`:`primary`,disabled:o,onClick:()=>a.mutate({capName:e,addonId:t,enabled:!n}),children:[o?l(m,{className:`h-3 w-3 animate-spin`}):l(n?p:w,{className:`h-3 w-3`}),n?`Disable`:`Enable`]})}function G({addonId:e,displayName:t}){let n=s(),r=ne({onSuccess:()=>{for(let e of V)n.invalidateQueries({queryKey:e})}});return l(g,{label:`Restart`,icon:D,size:`sm`,title:`Restart "${t}"?`,description:`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`ghost`,confirmVariant:`danger`,disabled:r.isPending,action:()=>r.mutateAsync({addonId:e})})}var K=600,q=e(null);function J({id:e,title:r,icon:a,actions:s,framed:c=!1,children:u}){let f=n(q),p=t(null),m=`integration-section-${e}`;Y(p,f,e);let h=i(o,{children:[f===null?null:l(A,{to:f.sectionHref(e),"aria-label":`Link to ${r}`,title:`Link to ${r}`,className:`rounded p-0.5 text-foreground-subtle/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,children:l(y,{className:`h-3 w-3`,"aria-hidden":!0})}),s]});return c?l(`div`,{ref:p,className:`scroll-mt-4`,children:l(b,{headingId:m,title:r,icon:a,actions:h,children:u})}):i(`section`,{ref:p,"aria-labelledby":m,className:`scroll-mt-4 space-y-2`,children:[i(`header`,{className:`flex min-h-7 flex-wrap items-center gap-2 px-0.5`,children:[a!==void 0&&l(a,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),l(`h2`,{id:m,className:`${d} min-w-0 flex-1`,children:r}),h]}),u]})}function Y(e,t,n){let r=t?.requestedSection===n,i=t?.integrationId;u(()=>{if(!r)return;let t=()=>e.current?.scrollIntoView?.({block:`start`});t();let n=!1,i=()=>{n=!0},a=[`wheel`,`touchmove`,`keydown`];for(let e of a)window.addEventListener(e,i,{once:!0,passive:!0});let o=window.setTimeout(()=>{n||t()},K);return()=>{window.clearTimeout(o);for(let e of a)window.removeEventListener(e,i)}},[r,i,e])}r();var X=`max-h-72`;function ie({addonId:e,displayName:t,capName:n,isActive:r,badges:a,primaryAction:o,error:s=null,lead:c,panels:u=[]}){let d=u.filter(e=>e.placement!==`end`),f=u.filter(e=>e.placement===`end`);return i(`div`,{className:`flex flex-col gap-4`,children:[l(ae,{addonId:e,displayName:t,capName:n,isActive:r,badges:a,primaryAction:o}),s!==null&&l(x,{message:s}),c,l(Z,{panels:d}),l(J,{id:R,title:`Settings`,icon:k,children:l(B,{nodeId:`hub`,addonIds:[e],level:`global`,capability:n})}),l(se,{addonId:e}),l(Z,{panels:f})]})}function Z({panels:e}){return l(o,{children:e.map(e=>l(J,{id:e.id,title:e.title,icon:e.icon,children:e.content},e.id))})}function ae({addonId:e,displayName:t,capName:n,isActive:r,badges:a,primaryAction:o}){return i(`div`,{className:`flex flex-wrap items-center justify-between gap-2 rounded-lg border border-border bg-surface px-2 py-1.5 sm:px-3`,"data-testid":`integration-status-strip`,children:[i(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[l(U,{isActive:r}),a,l(`span`,{className:`break-all font-mono text-[11px] text-foreground-subtle`,children:e})]}),i(`div`,{className:`flex flex-wrap items-center justify-end gap-1`,children:[o,l(W,{capName:n,addonId:e,isActive:r}),l(G,{addonId:e,displayName:t})]})]})}var oe=[{kind:`logs`,label:`Logs`,icon:te},{kind:`events`,label:`Events`,icon:O}];function se({addonId:e}){let[t,n]=c(`logs`);return l(J,{id:M,title:`Activity`,framed:!0,actions:l(`div`,{role:`group`,"aria-label":`Activity stream`,className:`flex items-center gap-1`,children:oe.map(({kind:e,label:r,icon:a})=>i(`button`,{type:`button`,"aria-pressed":t===e,onClick:()=>n(e),className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${t===e?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[l(a,{className:`h-3 w-3`,"aria-hidden":!0}),r]},e))}),children:t===`logs`?l(ee,{addonId:e,maxHeight:X,showFilters:!1}):l(E,{addonId:e,category:`addon.*`,maxHeight:X})})}r();function ce(e){let{ids:t,answered:n,legacyGroupParam:r=null,groupFirst:i}=e,[o]=j(),s=o.get(N),c=r===null?null:o.get(r),l=o.get(I),u=a(()=>F({ids:t,requested:s,answered:n,legacyGroup:c,...i===void 0?{}:{groupFirst:i}}),[t,s,n,c,i]),d=a(()=>(e,t)=>`?${L(o,e,r,t??null).toString()}`,[o,r]);return{...u,requestedSection:l,hrefFor:d}}r();var le={md:{tile:`h-10 w-10 rounded-lg`,img:`h-7 w-7 rounded-md p-1`,fallback:`h-5 w-5`},sm:{tile:`h-5 w-5 rounded`,img:`h-5 w-5 rounded p-0.5`,fallback:`h-3.5 w-3.5`}};function ue({addonId:e,fallback:t,tileClassName:n,iconPath:r=`assets/icon.svg`,size:i=`md`}){let[a,o]=c(!1),s=f(`/api/addon-assets/${e}/${r}`),u=le[i];return l(`div`,{className:`${u.tile} flex items-center justify-center shrink-0 ${n}`,children:a?l(t,{className:u.fallback,"aria-hidden":!0}):l(`img`,{src:s,alt:``,className:`${u.img} bg-white ring-1 ring-black/5`,onError:()=>o(!0)})})}var Q=`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,de=`border-primary bg-primary/10 text-primary font-medium`,fe=`border-border bg-surface text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,pe={ok:`bg-success`,off:`bg-foreground-subtle/60`,error:`bg-danger`,unknown:`border border-foreground-subtle bg-transparent`};function me({label:e,groups:t,selectedId:n,hrefFor:r}){let a=t.length>1;return l(`nav`,{"aria-label":e,className:a?`flex flex-col gap-2 sm:grid sm:grid-cols-[max-content_minmax(0,1fr)] sm:items-start sm:gap-x-3`:`flex flex-col`,children:t.map(e=>i(`div`,{role:`group`,"aria-label":e.label,className:a?`flex min-w-0 flex-col gap-1 sm:col-span-2 sm:grid sm:grid-cols-subgrid sm:items-start`:`min-w-0`,children:[a&&l(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle sm:pt-2`,children:e.label}),i(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[e.entries.map(e=>l(he,{entry:e,current:e.id===n,href:r(e.id)},e.id)),e.install&&i(A,{to:P(e.install.capability),className:`${Q} border-dashed border-border pl-2 text-foreground-subtle hover:border-primary/50 hover:text-foreground`,children:[l(T,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),l(`span`,{className:`truncate`,children:e.install.label})]})]})]},e.id))})}function he({entry:e,current:t,href:n}){let r=e.state===`ok`;return i(A,{to:n,"aria-current":t?`true`:void 0,className:`${Q} ${t?de:fe}`,"data-testid":`integration-pill-${e.id}`,children:[l(ue,{addonId:e.id,fallback:e.fallbackIcon,tileClassName:``,size:`sm`}),l(`span`,{className:`truncate`,children:e.name}),l(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${pe[e.state]}`,"aria-hidden":!0}),l(`span`,{className:r?`sr-only`:`shrink-0 text-[10px] font-normal text-foreground-subtle`,children:e.stateLabel})]})}r();function ge({icon:e,title:t,subtitle:n,groups:r,isLoading:s,emptyTitle:c,emptyDescription:u,legacyGroupParam:d,trailing:f}){let p=a(()=>r.flatMap(e=>e.entries),[r]),m=a(()=>p.map(e=>e.id),[p]),g=a(()=>{let e={};for(let t of r){let n=t.entries[0];n!==void 0&&(e[t.id]=n.id)}return e},[r]),_=ce({ids:m,answered:!s,legacyGroupParam:d??null,groupFirst:g}),v=p.find(e=>e.id===_.selectedId)??null,y=a(()=>v===null?null:{integrationId:v.id,requestedSection:_.requestedSection,sectionHref:e=>_.hrefFor(v.id,e)},[v,_]);return l(z,{icon:e,title:t,subtitle:n,nav:s?null:l(me,{label:`${t} integrations`,groups:r,selectedId:_.selectedId,hrefFor:e=>_.hrefFor(e)}),children:s?l(h,{children:l(`div`,{className:`p-6 text-sm text-foreground-subtle`,children:`Loading…`})}):i(o,{children:[_.staleId!==null&&l(_e,{staleId:_.staleId,shownName:v?.name??null}),v!==null&&y!==null?l(q.Provider,{value:y,children:l(`div`,{role:`region`,"aria-label":v.name,"data-testid":`integration-body`,children:v.render()},v.id)}):l($,{groups:r,title:c,description:u}),f]})})}function $({groups:e,title:t,description:n}){let r=e.find(e=>e.install!==void 0)?.install;return l(h,{children:l(S,{title:t,description:n,action:r?l(A,{to:P(r.capability),children:i(v,{variant:`primary`,size:`sm`,children:[l(T,{className:`mr-1 h-3.5 w-3.5`}),r.label]})}):void 0})})}function _e({staleId:e,shownName:t}){return i(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-[11px] text-foreground-subtle`,children:[l(C,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),i(`span`,{children:[`This link named `,l(`span`,{className:`font-mono text-foreground`,children:e}),`, which is not installed here.`,t!==null&&i(o,{children:[` `,`Showing `,l(`span`,{className:`font-medium text-foreground`,children:t}),` instead.`]})]})]})}export{ie as n,H as r,ge as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Q as e,S as t,W as n,b as r,o as i,q as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{st as s,vt as c}from"./player-overlays-tKtUzh3g.js";import{Ad as l,Cn as u,Cr as d,Dd as f,Dn as p,En as m,G as h,In as g,Nn as _,Pi as v,Sn as y,Su as b,W as x,ai as S,ci as C,dd as w,di as T,ed as E,fi as D,gd as ee,hd as te,ii as ne,li as re,qn as ie,si as ae,tr as O,ui as k,vd as A,wn as j,xn as M}from"./src-Y4G_LfLc.js";import{Nt as N,Sr as P,tr as F}from"./client-HDm3z1QL.js";import{K as I,N as L}from"./index-d2QAhmc-.js";import{t as R}from"./BrokerForm-Cv_WPhvt.js";import{n as z,r as B,t as V}from"./IntegrationHub-3NtGsJ8f.js";var H=c(`monitor-smartphone`,[[`path`,{d:`M18 8V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h8`,key:`10dyio`}],[`path`,{d:`M10 19v-3.96 3.15`,key:`1irgej`}],[`path`,{d:`M7 19h5`,key:`qswx4l`}],[`rect`,{width:`6`,height:`10`,x:`16`,y:`12`,rx:`2`,key:`1egngj`}]]);e();var U=`kind`,W=`name`,G=`restore`,K=`restoreId`;function q(e){return{sections:[{id:`broker-identity`,title:`Broker`,columns:1,fields:[{type:`select`,key:U,label:`Kind`,options:e.map(e=>({value:e.key,label:e.label})),disabled:e.length<=1},{type:`text`,key:W,label:`Name`,placeholder:`My Home Assistant`,required:!0},{type:`boolean`,key:G,label:`Restore a broker that was removed, under its original id`,description:`Devices remember the broker id they were discovered under, so restoring the original id reconnects them instead of needing re-discovery. An id that is still in use is refused.`},{type:`text`,key:K,label:`Original broker id`,placeholder:`ha_004`,required:!0,showWhen:{field:G,equals:!0}}]}]}}function oe(e){let t=t=>{let n=e[t];return typeof n==`string`?n.trim():``},n=t(U);if(n===``)return{ok:!1,problem:`Pick a kind.`};let r=t(W);if(r===``)return{ok:!1,problem:`Enter a name before saving.`};if(e.restore!==!0)return{ok:!0,identity:{kindKey:n,name:r,restoreId:null}};let i=t(K);return i===``?{ok:!1,problem:`Enter the original id, or turn restore off to create a new broker.`}:{ok:!0,identity:{kindKey:n,name:r,restoreId:i}}}var se={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function J(e){return se[e]??e}function ce(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var le={connected:`success`,connecting:`warning`,disconnected:`default`,"auth-failed":`danger`,unreachable:`danger`,error:`danger`};function ue({status:e}){return o(O,{variant:le[e],className:`text-[10px]`,children:e})}function de(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function Y({title:e,subtitle:n,onClose:r,children:i}){return o(M,{open:!0,onOpenChange:e=>!e&&r(),children:t(u,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[t(m,{children:[o(p,{children:e}),n&&o(j,{children:n})]}),o(y,{className:`space-y-3 pr-1`,children:i})]})})}function fe({kinds:e,onClose:r,onDone:s}){let c=i(),l=n(()=>q(e.map(e=>({key:X(e),label:e.label}))),[e]),[u,d]=a(()=>({[U]:X(e[0]),[W]:``,[G]:!1,[K]:``})),[f,p]=a(null),m=e.find(e=>X(e)===u.kind)??e[0],h=m?.kind??``,g=m?.addonId,v=ne({onSuccess:()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]}),s()}}),y=e=>{let t=oe(u);if(!t.ok){p(t.problem);return}p(null);let{name:n,restoreId:r}=t.identity;v.mutate({kind:h,name:n,settings:e,...r===null?{}:{id:r},...g===void 0?{}:{addonId:g}})};return t(Y,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:v.isPending?()=>{}:r,children:[o(L,{schema:l,values:u,onChange:d}),f!==null&&o(_,{message:f}),v.isError&&o(_,{message:v.error instanceof Error?v.error.message:String(v.error)}),h&&o(R,{kind:h,...g===void 0?{}:{addonId:g},onSubmit:y,onCancel:r,submitLabel:v.isPending?`Adding…`:`Add broker`,disabled:v.isPending},X(m))]})}function X(e){return e===void 0?``:`${e.addonId??``}::${e.kind}`}function pe({broker:e,onClose:r,onDone:a}){let s=i(),c=S({id:e.id,addonId:e.addonId}),u=T({onSuccess:()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]}),s.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),a()}}),d=n(()=>{let e=c.data;return e&&typeof e==`object`?{...e}:{}},[c.data]);return o(Y,{title:`Edit ${e.name}`,subtitle:`${J(e.kind)} · ${e.id}`,onClose:u.isPending?()=>{}:r,children:c.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(l,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):c.isError?t(`div`,{className:`space-y-3`,children:[o(_,{message:`Failed to load settings: ${c.error instanceof Error?c.error.message:`Unknown error`}`}),o(`div`,{className:`flex justify-end`,children:o(g,{variant:`outline`,size:`sm`,onClick:r,children:`Close`})})]}):t(`div`,{className:`space-y-3`,children:[u.isError&&o(_,{message:u.error instanceof Error?u.error.message:String(u.error)}),o(R,{kind:e.kind,addonId:e.addonId,initialValues:d,onSubmit:t=>{u.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:r,submitLabel:u.isPending?`Saving…`:`Save`,disabled:u.isPending})]})})}function me({broker:e,onEdit:n}){let r=i(),c=ie(),[u,d]=a(null),f=D({onSuccess:e=>d(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>d({ok:!1,error:e instanceof Error?e.message:String(e)})}),p=k({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),m=async()=>{await c({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&p.mutate({id:e.id,addonId:e.addonId})};return t(`tr`,{className:`border-b border-border last:border-0`,children:[o(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),o(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:J(e.kind)}),t(`td`,{className:`px-3 py-2`,children:[o(ue,{status:e.status}),u&&o(`span`,{className:`ml-2 text-[10px] ${u.ok?`text-success`:`text-danger`}`,children:u.ok?`OK`:u.error??`failed`})]}),o(`td`,{className:`px-3 py-2`,children:t(`div`,{className:`flex items-center justify-end gap-1.5`,children:[t(g,{variant:`outline`,size:`sm`,onClick:()=>f.mutate({id:e.id,addonId:e.addonId}),disabled:f.isPending,title:`Test connection`,children:[f.isPending?o(l,{className:`h-3 w-3 animate-spin`}):o(b,{className:`h-3 w-3`}),`Test`]}),t(g,{variant:`outline`,size:`sm`,onClick:()=>n(e),title:`Edit`,children:[o(A,{className:`h-3 w-3`}),` Edit`]}),t(g,{variant:`outline`,size:`sm`,className:`border-danger/40 text-danger hover:bg-danger/10`,onClick:()=>{m()},disabled:p.isPending,title:`Delete`,children:[p.isPending?o(l,{className:`h-3 w-3 animate-spin`}):o(s,{className:`h-3 w-3`}),`Delete`]})]})})]})}function he({addonId:e}={}){let r=C({}),i=re(),s=n(()=>de(r.data).filter(t=>e===void 0||t.addonId===e),[r.data,e]),[c,u]=a(!1),[d,f]=a(null),p=n(()=>{let t=new Map;for(let n of ce(i.data))if(!(e!==void 0&&n.addonId!==e))for(let e of n.kinds)t.set(`${n.addonId}::${e.kind}`,{addonId:n.addonId,kind:e.kind,label:e.label});for(let e of s)[...t.values()].some(t=>t.kind===e.kind)||t.set(`::${e.kind}`,{kind:e.kind,label:J(e.kind)});return[...t.values()]},[s,i.data,e]);return t(`div`,{className:`space-y-3`,children:[o(`div`,{className:`flex items-center justify-end`,children:t(g,{variant:`primary`,size:`sm`,onClick:()=>u(!0),disabled:p.length===0,title:p.length===0?`No broker providers available`:void 0,children:[o(ee,{className:`h-3.5 w-3.5`}),` Add broker`]})}),o(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[o(`thead`,{children:t(`tr`,{className:`border-b border-border bg-background/50`,children:[o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Name`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Kind`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Status`}),o(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Actions`})]})}),t(`tbody`,{children:[r.isLoading&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[o(l,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),r.isError&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,r.error instanceof Error?r.error.message:`Unknown error`]})}),!r.isLoading&&!r.isError&&s.length===0&&o(`tr`,{children:o(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`No brokers registered yet. Add one to publish device events for downstream automations.`})}),s.map(e=>o(me,{broker:e,onEdit:f},e.id))]})]})}),c&&o(fe,{kinds:p,onClose:()=>u(!1),onDone:()=>u(!1)}),d&&o(pe,{broker:d,onClose:()=>f(null),onDone:()=>f(null)})]})}function ge(e){if(typeof e==`string`)return e;if(typeof e==`object`&&e){let t=e.name;if(typeof t==`string`)return t}return null}function _e(e){let t=e,n=t?.manifest;if(n?.id===void 0)return null;let r=(n.capabilities??[]).map(ge).filter(e=>e!==null);return{addonId:n.id,displayName:n.packageDisplayName??n.name??n.id,capNames:r,processState:t?.process?.state??null}}function ve(e,t){return Object.entries(e).filter(([,e])=>e===t).map(([e])=>e)}function ye(e,t){return t.find(t=>e.capNames.includes(t))??null}function Z(e){switch(e){case`running`:return{state:`ok`,label:`running`};case`crashed`:case`failed`:return{state:`error`,label:e};case`stopped`:case`disabled`:return{state:`off`,label:`stopped`};default:return{state:`unknown`,label:e??`unknown`}}}e();var Q=1e4,be=[{kind:`device-export`,label:`Device export`,icon:E,installLabel:`Add export`},{kind:`email`,label:`Email`,icon:f,installLabel:`Add email provider`},{kind:`broker`,label:`Message brokers`,icon:w,installLabel:`Add broker addon`}];function $(){let e=d(void 0,{refetchInterval:Q}),i=I();return o(V,{icon:te,title:`Connectivity`,subtitle:`External systems this hub talks to — device exporters, email relays and message brokers.`,groups:n(()=>{let n=(e.data??[]).map(_e).filter(e=>e!==null);return be.map(e=>{let a=ve(N,e.kind),s=n.flatMap(n=>{let s=ye(n,a);if(s===null)return[];let c=Z(n.processState);return[{id:n.addonId,name:n.displayName,fallbackIcon:e.icon,state:c.state,stateLabel:c.label,render:()=>o(z,{addonId:n.addonId,displayName:n.displayName,capName:s,isActive:n.processState===`running`,badges:t(r,{children:[o(Se,{processState:n.processState}),o(Ce,{kind:e.kind,addonId:n.addonId})]}),lead:e.kind===`device-export`?o(h,{addonId:n.addonId}):void 0,panels:xe(e.kind,n.addonId,e=>i(`/devices/${e}`))})}]});return{id:e.kind,label:e.label,entries:s,install:{capability:a[0]??e.kind,label:e.installLabel}}})},[e.data,i]),isLoading:e.isLoading,emptyTitle:`No external systems installed`,emptyDescription:`Install an export, email or broker addon to connect this hub to another system.`,legacyGroupParam:`tab`})}function xe(e,t,n){return e===`device-export`?[{id:`devices`,title:`Devices`,icon:H,placement:`end`,content:o(x,{addonId:t,onOpenDevice:n,showSetup:!1})}]:e===`broker`?[{id:`connections`,title:`Connections`,icon:w,content:o(he,{addonId:t})}]:[]}function Se({processState:e}){let{state:t,label:n}=Z(e);return o(O,{variant:t===`ok`?`success`:t===`error`?`danger`:`default`,className:`${B} capitalize`,children:n})}function Ce({kind:e,addonId:t}){return e===`broker`?o(we,{addonId:t}):e===`device-export`?o(Te,{addonId:t}):null}function we({addonId:e}){let{data:t}=ae({addonId:e},{refetchInterval:Q,retry:!1}),n=P.safeParse(t);if(!n.success)return null;let{brokerCount:r,connectedCount:i}=n.data;return o(O,{variant:`info`,className:B,children:`${r} connection${r===1?``:`s`}${i>0?` · ${i} connected`:``}`})}function Te({addonId:e}){let{data:t}=v({addonId:e},{refetchInterval:Q,retry:!1}),n=F.safeParse(t);if(!n.success)return null;let{linkState:r,exposedDeviceCount:i}=n.data;return o(O,{variant:r===`linked`?`success`:r===`error`?`danger`:`default`,className:B,children:`${r} · ${i} exposed`})}export{$ as IntegrationsPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as l,at as u,gt as d,ht as f}from"./player-overlays-tKtUzh3g.js";import{$a as p,Ad as m,K as h,Xa as ee,Xi as g,Y as _,cr as v,dr as te,fd as y,gd as b,gf as x,hd as S,q as ne,r as re,sa as C,td as w,to as T,ud as E,yu as ie,zi as D}from"./src-Y4G_LfLc.js";import{t as O}from"./useTranslation-Bc5yH9V9.js";import{J as k,K as A,U as j}from"./index-d2QAhmc-.js";import{t as ae}from"./AdminPage-BSFohA3i.js";import"./useEventInvalidation-D_5ynS9o.js";import{t as M}from"./StatusBadge-CeptlsPG.js";import{t as oe}from"./device-integration-icon-KaXkp2LK.js";import{n as N,r as P,t as F}from"./ScanNetworkModal-Dq6vPLgX.js";t();function I(e=!0){c(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e])}t();function L(e,t){let[n,r]=o(!1);return c(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}t();function R({providerId:e,onImport:t,onSkip:r}){let{t:i}=O(),[a,u]=o(new Set),d=g(),f=d.data,p=d.isPending||!d.data&&!d.isError;c(()=>{e&&(d.isPending||d.data||d.mutate({addonId:e}))},[e,d]);function m(e){u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(p)return n(`div`,{className:`flex flex-col items-center py-12`,children:[s(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),s(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:i(`integrations.searchingDevices`)})]});let h=f??[];return n(`div`,{className:`space-y-4`,children:[s(`p`,{className:`text-xs text-foreground-subtle`,children:h.length>0?i(`integrations.foundDevices`,{count:h.length}):i(`integrations.noDevicesFound`)}),h.length>0&&s(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:h.map(e=>{let t=e.stableId,r=e.suggestedName??t,o=a.has(t),c=e.alreadyOnboarded===!0;return n(`button`,{onClick:()=>{c||m(t)},disabled:c,title:c?i(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:e.onboardedName??r}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${c?`border-border bg-surface opacity-60 cursor-not-allowed`:o?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[s(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${o&&!c?`border-primary bg-primary`:`border-border`}`,children:o&&!c&&s(x,{className:`h-3 w-3 text-primary-foreground`})}),s(l,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),s(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r}),c&&s(`span`,{className:`ml-auto flex-shrink-0 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:i(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},t)})}),n(`div`,{className:`flex items-center justify-between pt-2`,children:[s(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.skip`)}),h.length>0&&n(`button`,{onClick:()=>t(Array.from(a)),disabled:a.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[i(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}function z({onSelect:e,onClose:t,pendingAddonId:r=null}){let{t:i}=O(),a=A(),{data:o,isLoading:c}=p();if(c)return s(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let l=r!==null;return n(`div`,{className:`space-y-2`,children:[(o??[]).map(o=>{let c=o.instanceMode===`unique`&&o.existingInstances.length>0,u=r===o.addonId,d=l;return n(`button`,{disabled:d,onClick:()=>{if(!d)if(c){let e=o.existingInstances[0].id;t(),a(`/integrations/${e}`)}else e(o.addonId,o.instanceMode,o.discoveryMode,o.name,o.kind,o.brokerKind,o.mode,o.canTest)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[o.iconUrl?s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`img`,{src:o.iconUrl,alt:``,className:`h-5 w-5`})}):s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`span`,{className:`text-sm`,style:{color:o.color},children:`◉`})}),n(`div`,{className:`flex-1 min-w-0`,children:[s(`p`,{className:`text-xs font-semibold text-foreground`,children:o.name}),o.description&&s(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:o.description})]}),u?s(m,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):c?n(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[s(w,{className:`h-3 w-3`}),i(`integrations.manage`)]}):s(f,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},o.addonId)}),(o??[]).length===0&&s(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:i(`integrations.noProviders`)})]})}t();function se(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var B=2e4;function V({open:e,onClose:t}){let{t:l}=O(),u=A(),d=a(),[f,p]=o(`picker`),[h,_]=o(null),[v,y]=o(null),[b,x]=o(`manual`),[S,ne]=o(null),[re,C]=o(``),[w,T]=o(null),[E,k]=o(null),[j,ae]=o(!1),{data:M}=te({addonId:h??``,nodeId:`hub`},{enabled:h!=null}),oe=r(()=>M?se(M):null,[M]),F=ee({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),V=g(),H=V.data;c(()=>{f!==`discovery`||!v||!h||V.isPending||V.data||V.mutate({addonId:h})},[f,v,h,V]);let ce=D({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function le(e,t,n,r,i,a,o,s){if(!F.isPending){if(_(e),ae(s),x(n),C(r),k(null),o===`broker`){if(!a){k(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}ne(a),p(`broker`);return}if(o===`account`){p(`config`);return}U(e,r)}}async function U(e,n){try{let r=await F.mutateAsync({addonId:e,name:n,settings:{}});t(),J(),u(`/integrations/${r.id}?add=1`)}catch{}}async function W(e){if(h)try{let t=await F.mutateAsync({addonId:h,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});y(t.id),b===`auto`||b===`both`?p(`discovery`):q(t.id)}catch{}}async function G(e){if(h)try{let t=await F.mutateAsync({addonId:h,name:re,settings:{brokerId:e}});T(t.id),y(t.id),q(t.id)}catch{}}async function K(e){if(h){for(let t of e){let e=H?.find(e=>e.stableId===t);e&&await ce.mutateAsync({addonId:h,candidate:e,...w===null?{}:{integrationId:w}})}q()}}function q(e){let n=e??v??h;t(),J(),n&&u(`/integrations/${n}`)}function J(){p(`picker`),_(null),y(null),x(`manual`),ne(null),C(``),T(null),k(null),ae(!1)}function Y(){t(),J()}I(e);let X=F.isPending,Z=L(X,B);if(!e)return null;let ue={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Q=X?h:null,$=F.error,de=X&&!Z;return n(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:Y}),n(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:ue[f]}),s(`button`,{onClick:Y,disabled:de,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:s(ie,{className:`h-4 w-4`})})]}),n(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!X&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),f===`picker`&&n(i,{children:[E&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:E}),s(z,{onSelect:le,onClose:Y,pendingAddonId:Q})]}),f===`config`&&h&&s(N,{addonId:h,configSchema:oe??null,canTest:j,onSave:W,onBack:()=>p(`picker`)}),f===`broker`&&S&&s(P,{kind:S,onResolved:e=>{G(e)},onBack:()=>p(`picker`)}),f===`discovery`&&v&&s(R,{providerId:v,onImport:K,onSkip:q})]}),X&&n(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[s(m,{className:`h-6 w-6 animate-spin text-primary`}),s(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&n(i,{children:[s(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:l(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),s(`button`,{onClick:Y,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:l(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function H({integration:e,expanded:t,onToggleExpand:r}){return n(`div`,{className:`flex items-center gap-2.5`,children:[s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:s(t?d:f,{className:`h-3.5 w-3.5`})}),s(j,{type:e.addonId,size:`sm`}),n(`div`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),s(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function ce(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>s(H,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>s(M,{status:e.status})}]}t();function le(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var U=`expand`;function W(){let{t}=O(),a=A(),c=u(),[l]=k(),[d,f]=o(!1),p=e(()=>f(!0),[]),m=e(()=>f(!1),[]),[ee,g]=o(!1),te=e(()=>g(!0),[]),x=e(()=>g(!1),[]);re([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),re([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:w,isLoading:ie,refetch:D}=T(void 0),{data:j,isLoading:M,refetch:N}=C({projection:`slim`}),P=r(()=>j??[],[j]),I=r(()=>w??[],[w]),L=r(()=>{let e=new Map;for(let t of P)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[P]),R=r(()=>ne(w),[w]),z=r(()=>{let e=new Map;for(let t of _(P)){let n=R(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[P,R]),se=r(()=>I.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:le(e),deviceCount:z.get(e.id)??0})),[I,z]),B=l.get(U),H=e(e=>{let t=new URLSearchParams(window.location.search);t.get(U)===e?t.delete(U):t.set(U,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),W=e(e=>a(`/integrations/${e.id}`),[a]),G=e(e=>L.get(e)??null,[L]),K=e(e=>a(`/devices/${String(e)}`),[a]),q=e(e=>s(h,{context:`integration-detail`,devices:P,trpc:c.trpcClient,integrationOf:R,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:oe,resolveParent:G,onNavigate:K}),[P,c.trpcClient,R,G,K]),J=e(e=>B===e.addonId,[B]),Y=r(()=>ce({isExpanded:J,onToggleExpand:H}),[J,H]),X=e(e=>`${e.name} ${e.addonId}`,[]),Z=e(e=>e.addonId,[]),ue=e(()=>{D(),N()},[D,N]),Q=ie||M,$=I.length>0;return n(ae,{icon:S,title:t(`nav.integrations`,`Integrations`),actions:n(i,{children:[s(`button`,{onClick:ue,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:s(E,{className:v(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),n(`button`,{onClick:te,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[s(y,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick:p,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[s(b,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&s(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&n(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[s(`p`,{className:`text-sm`,children:`No integrations configured.`}),s(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&$&&s(h,{mode:`generic`,items:se,getKey:Z,getSearchText:X,columns:Y,onRowClick:W,isExpanded:J,renderExpanded:q,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),s(V,{open:d,onClose:m}),s(F,{open:ee,onClose:x})]})}export{W as IntegrationsPage};
|