@camstack/addon-admin-ui 1.2.315 → 1.2.317

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.
Files changed (106) hide show
  1. package/dist/assets/{AddonCollectionPage-pS-uTKIv.js → AddonCollectionPage-Bz3KyJNf.js} +1 -1
  2. package/dist/assets/Addons-K7ojIo10.js +1 -0
  3. package/dist/assets/{AdminTabs-jHFlbFwy.js → AdminTabs-BE0YQcz6.js} +1 -1
  4. package/dist/assets/AiProfiles-D7sHeBH4.js +3 -0
  5. package/dist/assets/{BrokerForm-DgGM0_0c.js → BrokerForm-bxpKmM7o.js} +1 -1
  6. package/dist/assets/Build-DVOvAgQF.js +32 -0
  7. package/dist/assets/Calendars-CswUDHQu.js +1 -0
  8. package/dist/assets/{Capabilities-C3B2Cg8b.js → Capabilities-Do3wDlZD.js} +1 -1
  9. package/dist/assets/{CapabilityBadges-B4tAQqGd.js → CapabilityBadges-CgeMnJ7C.js} +1 -1
  10. package/dist/assets/Cluster-Dp9iAJfh.js +11 -0
  11. package/dist/assets/CompositionEditor-DylZiGDl.js +1 -0
  12. package/dist/assets/{CompositionEditorPage-VsLdAptk.js → CompositionEditorPage-NjfF0yvh.js} +1 -1
  13. package/dist/assets/{Data-jiTwAkwz.js → Data-CkdRah8J.js} +1 -1
  14. package/dist/assets/DetectionIntelligence-Cpy4JvtP.js +1 -0
  15. package/dist/assets/{DeviceAggregateSection-CbiGOvpd.js → DeviceAggregateSection-DfFPdtb8.js} +1 -1
  16. package/dist/assets/DeviceDetail-D0GETqvV.js +2 -0
  17. package/dist/assets/{Devices-BUSj9XZS.js → Devices-DQ0ArzQE.js} +1 -1
  18. package/dist/assets/{EmbedPlayerPage-HBoWc3RB.js → EmbedPlayerPage-mC85OtwI.js} +1 -1
  19. package/dist/assets/Events-C61zhgxI.js +1 -0
  20. package/dist/assets/{FormBuilder-Bsir_-sl.js → FormBuilder-CUKZeqaR.js} +1 -1
  21. package/dist/assets/Identity-DP6Ckj2p.js +1 -0
  22. package/dist/assets/IntegrationDetail-CQMNd52V.js +1 -0
  23. package/dist/assets/Integrations-CkSMOc_i.js +1 -0
  24. package/dist/assets/{Integrations-CM0m1Zef.js → Integrations-Dck3p4vk.js} +1 -1
  25. package/dist/assets/Locations-BfuqW8R4.js +3 -0
  26. package/dist/assets/{Logs-D0IImY2Y.js → Logs-xDxr9Gtg.js} +1 -1
  27. package/dist/assets/{ModelLicenses-q_i_PA1X.js → ModelLicenses-B-yPcnv9.js} +1 -1
  28. package/dist/assets/{MotionZonesSettings-CVxyo9hA.js → MotionZonesSettings-BXuS3yQG.js} +1 -1
  29. package/dist/assets/{MyAccess-FbdsZp4I.js → MyAccess-B2t0iEac.js} +1 -1
  30. package/dist/assets/Network-DWGAw_ny.js +1 -0
  31. package/dist/assets/{NodeAddonsSettingsPanel-DssU1eLJ.js → NodeAddonsSettingsPanel-Cvi-yx7B.js} +1 -1
  32. package/dist/assets/{NodeInferenceDevices-4JgJwMA2.js → NodeInferenceDevices-BW2KYGcO.js} +1 -1
  33. package/dist/assets/Notifications-BNb2HjOi.js +1 -0
  34. package/dist/assets/Pipeline-BSCqhhXf.js +1 -0
  35. package/dist/assets/Plates-DqiV1ewT.js +1 -0
  36. package/dist/assets/{PrivacyMaskSettings-CLxBzwVu.js → PrivacyMaskSettings-BWSWKsNC.js} +1 -1
  37. package/dist/assets/{ProviderIcon-dscfq54_.js → ProviderIcon-fddHc0k4.js} +1 -1
  38. package/dist/assets/Recordings-EaVg76H3.js +1 -0
  39. package/dist/assets/{ScanNetworkModal-D8yxRM0Z.js → ScanNetworkModal-BNgDBkJM.js} +1 -1
  40. package/dist/assets/{SceneMonitorEditor-Cv2vE8HC.js → SceneMonitorEditor-9Q6zewXr.js} +1 -1
  41. package/dist/assets/{Scenes-BQ4CPMKw.js → Scenes-C5kxcDpB.js} +1 -1
  42. package/dist/assets/{Settings-Dfcait6k.js → Settings-onYehQTZ.js} +1 -1
  43. package/dist/assets/{Showroom-_zi_fQzx.js → Showroom-SqmtzsWp.js} +1 -1
  44. package/dist/assets/{StorageLocationsPanel-DNV_ZgVx.js → StorageLocationsPanel-9SEbSCda.js} +1 -1
  45. package/dist/assets/{Terminal-BC9ErnQ1.js → Terminal-6-ZxMSqu.js} +3 -3
  46. package/dist/assets/{Viewer-6Aij0p3V.js → Viewer-9-eAVNyE.js} +1 -1
  47. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-_ywvVYKV.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-D4WwCW56.js} +1 -1
  48. package/dist/assets/{archive-DnwqLvnq.js → archive-DFnrUg_n.js} +1 -1
  49. package/dist/assets/{authed-media-BAASKB_9.js → authed-media-CcoUkS09.js} +1 -1
  50. package/dist/assets/{boxes-kF6UH6-_.js → boxes-Yw-udPBi.js} +1 -1
  51. package/dist/assets/circle-slash-gMJOW6fS.js +1 -0
  52. package/dist/assets/{debounced-invalidate-2ngeH0FB.js → debounced-invalidate-DRxN7AgI.js} +1 -1
  53. package/dist/assets/{device-integration-icon-bqqGCRov.js → device-integration-icon-DhrVTlMx.js} +1 -1
  54. package/dist/assets/device-picker-model-CWtuhmnD.js +1 -0
  55. package/dist/assets/{dist-BXhzcrtM.js → dist-CIufP1FF.js} +3 -3
  56. package/dist/assets/{dist-iiQuRL6W.js → dist-CwW7owcd.js} +1 -1
  57. package/dist/assets/{face-bbox-zGQvxT6q.js → face-bbox-0DetgpsJ.js} +1 -1
  58. package/dist/assets/{hard-drive-download-CoG1t86A.js → hard-drive-download-DaSRdIcz.js} +1 -1
  59. package/dist/assets/{hostInit-ClFPaQoK.js → hostInit-B4V8T3EL.js} +1 -1
  60. package/dist/assets/index-Bleh56hg.js +4 -0
  61. package/dist/assets/index-DZYv56ZC.css +2 -0
  62. package/dist/assets/{layers-9n_eO6gY.js → layers-BUhaBMGm.js} +1 -1
  63. package/dist/assets/{location-owned-usage-XFA4zrIz.js → location-owned-usage-BoDYtcBv.js} +1 -1
  64. package/dist/assets/{mf-entry-bootstrap-0-aa4bc7ed.js → mf-entry-bootstrap-0-4d3f6da6.js} +2 -2
  65. package/dist/assets/{player-overlays-BPnLENh-.js → player-overlays-cfiayLzw.js} +1 -1
  66. package/dist/assets/remoteEntry-CgiotXE_.js +1 -0
  67. package/dist/assets/{send-EIywGEfF.js → send-DxfUIMIW.js} +1 -1
  68. package/dist/assets/{settings-2-C2jb3QFd.js → settings-2-zfrKsU7z.js} +1 -1
  69. package/dist/assets/{square-check-big-7kDS8B6S.js → square-check-big-BGFB97B2.js} +1 -1
  70. package/dist/assets/src-CYSHGOVz.js +349 -0
  71. package/dist/assets/src-FuqzctFV.js +67 -0
  72. package/dist/assets/{use-scenes-feed-Dl7dI39g.js → use-scenes-feed-CFkmhw5l.js} +1 -1
  73. package/dist/assets/{use-stationary-objects-BHIRg4zV.js → use-stationary-objects-Bb-XKIyw.js} +1 -1
  74. package/dist/assets/{useDevice-BuSELuIc.js → useDevice-DRs5RxiU.js} +1 -1
  75. package/dist/assets/useEventInvalidation-CWtuhmnD.js +1 -0
  76. package/dist/assets/{useNodeUrlSelection-hGEaySeu.js → useNodeUrlSelection-CVp0XLPd.js} +1 -1
  77. package/dist/assets/user-round-rTUAQ-iI.js +1 -0
  78. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DHst_gbg.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BRzNhP8n.js} +2 -2
  79. package/dist/index.html +6 -6
  80. package/dist/server/addon.js +90 -1
  81. package/package.json +1 -1
  82. package/dist/assets/Addons-9ZIvUT1K.js +0 -1
  83. package/dist/assets/AiProfiles-BhbohiJt.js +0 -3
  84. package/dist/assets/Build-CUET0Iyz.js +0 -32
  85. package/dist/assets/Cluster-4QQw-L5J.js +0 -11
  86. package/dist/assets/CompositionEditor-BPm2kx9Q.js +0 -1
  87. package/dist/assets/DetectionIntelligence-z8Wi34J2.js +0 -1
  88. package/dist/assets/DeviceDetail-XZGgHSZ7.js +0 -2
  89. package/dist/assets/Events-CwwN-Ai4.js +0 -1
  90. package/dist/assets/Identity-Dybyl5R-.js +0 -1
  91. package/dist/assets/IntegrationDetail-BKdQfHsS.js +0 -1
  92. package/dist/assets/Integrations-B3j9mUgh.js +0 -1
  93. package/dist/assets/Locations-CyY2UiFp.js +0 -3
  94. package/dist/assets/Network-Ba7GJPhZ.js +0 -1
  95. package/dist/assets/Notifications-DOZJMvSa.js +0 -1
  96. package/dist/assets/Pipeline-CSVrOhDb.js +0 -1
  97. package/dist/assets/Plates-D3-W026o.js +0 -1
  98. package/dist/assets/Recordings-Ccu6iaCk.js +0 -1
  99. package/dist/assets/circle-slash-BbFEc4PR.js +0 -1
  100. package/dist/assets/index-BKfjeM9L.js +0 -4
  101. package/dist/assets/index-egLHRpbu.css +0 -2
  102. package/dist/assets/remoteEntry-Dc4is_2X.js +0 -1
  103. package/dist/assets/src-Ch2D4L9J.js +0 -67
  104. package/dist/assets/src-DXUFbK1_.js +0 -349
  105. package/dist/assets/useEventInvalidation-C-bG2gYe.js +0 -1
  106. package/dist/assets/user-round-DIcryj9b.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,_t as m,at as h,ct as g,ft as _,gt as v,st as y,yt as b}from"./player-overlays-cfiayLzw.js";import{$c as x,$l as S,$u as C,Ao as w,Bu as T,Co as E,Dd as D,Do as O,Eo as k,Et as A,Fi as j,Fo as M,Gt as N,Gu as P,In as F,Io as I,Ju as ee,Kl as te,Ln as ne,Ml as re,Mn as L,Mo as R,Nn as ie,No as z,Nu as ae,Ol as B,Oo as oe,Pn as V,Po as se,Q as ce,Sn as H,So as le,Wu as ue,Zo as de,al as fe,ar as pe,bo as me,cl as he,el as ge,en as U,gn as _e,go as ve,hn as W,ho as ye,id as be,jl as xe,ko as Se,no as Ce,po as we,qo as Te,qt as Ee,rn as De,sd as Oe,sn as ke,ss as Ae,vo as je,vu as Me,wo as Ne,xl as Pe,xn as Fe,xo as Ie,yn as G,yo as Le,yu as K}from"./src-FuqzctFV.js";import{t as Re}from"./square-check-big-BGFB97B2.js";import{fn as ze,xr as Be}from"./src-CYSHGOVz.js";import{l as Ve}from"./index-Bleh56hg.js";import{t as He}from"./AdminPage-CiKtOLQm.js";import{a as Ue,i as We,r as Ge,t as Ke}from"./authed-media-CcoUkS09.js";import{a as qe,c as Je,d as Ye,f as Xe,i as Ze,n as Qe,o as $e,p as et,r as tt,s as nt,t as rt}from"./debounced-invalidate-DRxN7AgI.js";import{t as it}from"./use-stationary-objects-Bb-XKIyw.js";import{t as at}from"./AdminTabs-BE0YQcz6.js";import{t as ot}from"./format-size-DIxKXxtj.js";var st=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`}]]),ct=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`}]]),lt=b(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),ut=b(`graduation-cap`,[[`path`,{d:`M21.42 10.922a1 1 0 0 0-.019-1.838L12.83 5.18a2 2 0 0 0-1.66 0L2.6 9.08a1 1 0 0 0 0 1.832l8.57 3.908a2 2 0 0 0 1.66 0z`,key:`j76jl0`}],[`path`,{d:`M22 10v6`,key:`1lu8f3`}],[`path`,{d:`M6 12.5V16a6 3 0 0 0 12 0v-3.5`,key:`1r8lef`}]]),dt=b(`square-parking`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 17V7h4a3 3 0 0 1 0 6H9`,key:`1dfk2c`}]]);n();function ft(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 pt=720*60*60*1e3;function mt(e){let t=[];for(let n of e)t.push(...n);return t}function ht(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function gt(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 vt(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 yt(e,t){return{since:e.fromMs??t-pt,until:e.toMs??t}}var bt=[`native`,`raster`,`standin`];function xt(e){return bt.some(t=>t===e)}var St={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 Ct(e){return e===`standin`?St.standin:e===`raster`?St.raster:null}var wt={"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 Tt(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:wt[r]??r,detail:i,raw:t}}function Et(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 Dt({row:e,cameraName:t,nowMs:n,onOpenDetail:i,selected:a=!1,onToggleSelect:o,score:s,provenance:c,footer:l}){let d=Ue(e.mediaId===void 0?We(`track`,e.trackId):Ge(e.mediaId)),f=Math.round(e.importance*100),p=s===void 0?void 0:Math.round(s*100),m=Et(e.windowMs),h=()=>i(e),v=Ct(c);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${a?`border-primary ring-1 ring-primary`:`border-border`}`,children:[r(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[d.src?u(`img`,{src:d.src,alt:`Event from ${t}`,onClick:h,className:`h-full w-full cursor-zoom-in object-cover`}):u(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:d.failed?`Key-event media unavailable`:`No key-event media`,children:u(_,{className:`h-6 w-6 opacity-60`})}),o&&u(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(_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(Re,{className:`h-4 w-4 text-primary`}):u(g,{className:`h-4 w-4`})}),p!==void 0&&r(`span`,{className:`absolute left-1 top-1 z-10 rounded bg-primary/85 px-1.5 py-0.5 text-[10px] font-semibold text-white tabular-nums`,title:`CLIP semantic-match score`,children:[String(p),`%`]}),f>0&&u(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(f)}),v!==null&&u(`span`,{className:`absolute bottom-1 right-1 z-10 rounded px-1.5 py-0.5 text-[10px] font-semibold text-white ${v.tone===`warning`?`bg-warning/90`:`bg-black/70`}`,title:v.title,children:v.label}),(e.markForTrain===!0||e.debug===!0||e.favourited===!0)&&r(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[e.markForTrain===!0&&u(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Marked for training`,"aria-label":`Marked for training`,children:u(ut,{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(Oe,{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(xe,{className:`h-3 w-3`})})]})]}),r(`button`,{type:`button`,onClick:h,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[r(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,ft(e)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,ft(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:Xe(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 Ot=1400,kt=`Admin-gated URL — opens only inside an authenticated session`;function At({label:t,value:n,title:i}){let[a,o]=l(!1),s=V();return d(()=>{if(!a)return;let e=setTimeout(()=>o(!1),Ot);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?be:ue,{className:`h-2.5 w-2.5 shrink-0`}),u(`span`,{className:`truncate`,children:a?`Copied`:t})]})}function jt({localUrl:e,publicUrl:t}){return r(`div`,{className:`flex flex-wrap gap-1`,children:[u(At,{label:`Local`,value:e,title:`Copy LAN URL — ${kt}`}),t&&u(At,{label:`Public`,value:t,title:`Copy public URL — ${kt}`})]})}var Mt={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 Nt(e){return e in Mt}function Pt(e){return Nt(e)?Mt[e]:e}function Ft(e,t){return`${e}${t}`}n();var It=3e4;function Lt(t){let[n,r]=l(null),i=e(e=>{r(t=>t??e)},[]);return d(()=>{t||r(null)},[t]),{publicOrigin:n,probes:t?u(Rt,{onOrigin:i}):null}}function Rt({onOrigin:e}){let{data:t}=pe({capName:`network-access`});return u(s,{children:(t??[]).map(t=>u(zt,{addonId:t.addonId,onOrigin:e},t.addonId))})}function zt({addonId:e,onOrigin:t}){let{data:n}=Ce({addonId:e},{refetchInterval:It,retry:!1});return d(()=>{let e=n?ze.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 Bt=typeof M==`function`,Vt=`Track flags arrive with the next server update`;function Ht(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var Ut=Bt?M:Ht;function Wt(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 Gt({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 Kt({deviceId:e,trackId:t,markForTrain:n,debug:i,favourited:a,onChange:o}){let s=Ut(),c=L(),[d,f]=l(null),p=d?.markForTrain??n===!0,m=d?.debug??i===!0,h=d?.favourited??a===!0,g=!Bt||s.isPending,_=Bt?void 0:Vt,v=n=>{g||(async()=>{try{let r=Wt(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(Gt,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:p,disabled:g,..._===void 0?{}:{title:_},icon:u(ut,{className:`h-4 w-4`}),onToggle:()=>v({markForTrain:!p})}),u(Gt,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:m,disabled:g,..._===void 0?{}:{title:_},icon:u(Oe,{className:`h-4 w-4`}),onToggle:()=>v({debug:!m})}),u(Gt,{label:`Favourited`,hint:`Keeps this track and its media past retention`,checked:h,disabled:g,..._===void 0?{}:{title:_},icon:u(xe,{className:`h-4 w-4`}),onToggle:()=>v({favourited:!h})})]})}var q=100,qt=120,Jt={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},J=e=>e<0?0:e>1?1:e,Yt=e=>Math.round(e*100)/100;function Xt(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 Zt(e,t,n){if(e.length===0||t===null)return Jt;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return Jt;let a=Xt(e,n?.maxPoints??qt).map(e=>({x:Yt(J(e.x/r)*q),y:Yt(J(e.y/i)*q)})),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:Yt(J(e.x/r)*q),y:Yt(J(e.y/i)*q),mediaId:e.mediaId})),u=null,d=-1;for(let t of e){let e=J(t.bbox.w/r)*J(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Yt(J(u.bbox.x/r)*q),y:Yt(J(u.bbox.y/i)*q),w:Yt(J(u.bbox.w/r)*q),h:Yt(J(u.bbox.h/i)*q)}:null}}var Qt=typeof ye==`function`,$t=`Track deletion arrives with the next server update`;function en(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var tn=Qt?ye:en;n();var nn=15e3,rn=f();function an({url:e,label:t}){let{src:n,failed:r}=Ue(e);return n===null?u(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?u(_,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):u(K,{className:`h-4 w-4 animate-spin text-foreground-subtle opacity-70`})}):u(`img`,{src:n,alt:t,className:`h-full w-full object-cover`})}var on=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),sn=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`,`sceneFrame`,`lastSceneFrame`]);function cn(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 ln({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 Y({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 un({row:t,cameraName:n,deleteAvailable:i,onClose:o,onDeleted:c,onFlagsChanged:f}){let p=h(),m=L(),g=ie(),v=tn(),b=t!==null,S=t?.deviceId??0,C=t?.trackId??``,w=t?.timestamp??0,T=t?.windowMs??0,{data:E}=me({deviceId:S,trackId:C},{enabled:b}),{data:D}=Se({trackId:C,deviceId:S},{enabled:b}),O=E?.bestEventId===void 0?void 0:Number(E.bestEventId),{data:k}=Ne({ownerType:`object`,eventId:O??0,deviceId:S},{enabled:b&&O!==void 0&&Number.isFinite(O)}),{data:A}=ge({deviceId:S},{enabled:b}),j=(A??[]).find(e=>e.addonId!==void 0)?.addonId,{data:M}=x({deviceId:S,since:w-nn,until:w+T+nn,provider:j??``},{enabled:b&&j!==void 0}),[P,F]=l(null),[I,ee]=l(!1),{publicOrigin:te,probes:ne}=Lt(b);d(()=>{F(null)},[S,C]);let re=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]),R=P??re,z=Ue(R?R.url:void 0),B=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]),oe=a(()=>B.find(e=>on.has(e.kind))??null,[B]),V=cn(Ue(oe?oe.url:void 0).src),se=a(()=>Zt(E?.positions??[],V,{snapshots:(E?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaId:e.mediaId}))}),[E?.positions,E?.snapshots,V]),ce=e(e=>{let t=B.find(t=>t.mediaId===e);t&&F(t)},[B]);if(t===null)return null;let le=z.src,ue=R?.kind,de=ue!==void 0&&sn.has(ue)&&V!==null&&(E?.positions.length??0)>=2,fe=M&&M.length>0?M[0]:null,pe=()=>{fe&&(ee(!0),(async()=>{try{let e=await p.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:fe.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{m({title:`Clip unavailable`,message:`Could not resolve clip playback. Check the server logs.`,variant:`warning`})}finally{ee(!1)}})())},U=()=>{!i||v.isPending||(async()=>{if(await g({title:`Delete track`,message:`Delete this track and every image and clip captured for it? This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`}))try{await v.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),c()}catch{await m({title:`Delete failed`,message:`Failed to delete this track. Check the server logs.`,variant:`danger`})}})()},_e=Math.round(t.importance*100),ve=E?.importanceReason?`${String(_e)}% · ${E.importanceReason}`:`${String(_e)}%`,W=E?.zonesVisited&&E.zonesVisited.length>0?E.zonesVisited.join(`, `):`—`,ye=E?.audioLabels&&E.audioLabels.length>0?E.audioLabels:t.audioLabels&&t.audioLabels.length>0?t.audioLabels:void 0,be=ye===void 0?`—`:ye.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `),xe=E?E.totalDistance.toFixed(2):`—`,Ce=Tt(E?.previewMissReason),we=et(E?E.firstSeen:w),Te=E?et(E.lastSeen):`—`;return u(N,{open:!0,onOpenChange:e=>!e&&o(),children:r(Ee,{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,ft(t)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,ft(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(he,{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:[le?u(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:u(Qe,{src:le,alt:`Key frame from ${n}`,fit:`natural`,className:`w-full`,overlay:de?u(ln,{overlay:se,onPickSnapshot:ce}):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:z.failed?r(s,{children:[u(_,{className:`h-8 w-8 opacity-60`}),u(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):u(K,{className:`h-6 w-6 animate-spin opacity-70`})}),B.length>0&&u(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:B.map(e=>{let t=Pt(e.kind),n=Ft(rn,e.url),i=te?Ft(te,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} · ${et(e.timestamp)}`,children:u(an,{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:et(e.timestamp),children:Ye(e.timestamp)})]}),u(jt,{localUrl:n,publicUrl:i})]},e.mediaId)})}),ne,fe&&r(H,{variant:`secondary`,onClick:pe,disabled:I,children:[I?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(ae,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),u(Kt,{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}),Ce!==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:Ce.sentence}),u(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:Ce.raw})]}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[u(Y,{label:`Camera`,value:n}),u(Y,{label:`Class`,value:t.className}),u(Y,{label:`Label`,value:t.label??`—`}),u(Y,{label:`Sub-label`,value:t.subLabel??`—`}),u(Y,{label:`Importance`,value:ve}),u(Y,{label:`Zones visited`,value:W}),u(Y,{label:`Audio heard`,value:be}),u(Y,{label:`Total distance`,value:xe}),u(Y,{label:`First seen`,value:we}),u(Y,{label:`Last seen`,value:Te}),u(Y,{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:$t,children:r(H,{variant:`secondary`,onClick:U,disabled:!i||v.isPending,children:[v.isPending?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(y,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}var dn={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`},fn={setRelation:`debug.gt.setRelation`,setPurity:`debug.gt.setPurity`,list:`debug.gt.list`},pn=p(`/addon/pipeline-analytics/tape-export`),mn=10*6e4;function hn(e){return`${pn}?tapeId=${encodeURIComponent(e)}`}var gn=`The server answered in a shape this build does not understand.`;function _n(e){return e instanceof Error?e.message:`The action failed.`}function X(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Z(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function vn(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 Q(e,t){let n=e[t];return typeof n==`string`?n:null}function yn(e,t){let n=e[t];return typeof n==`boolean`?n:null}function bn(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 xn(e){return e===`off`||e===`recording`||e===`refused`||e===`failing`||e===`unknown`}function Sn(e){if(!X(e))return null;let t=Z(e,`deviceId`),n=e.state,r=Z(e,`gapsSinceArmed`),i=vn(e,`segmentsHeld`),a=vn(e,`bytesLastHour`),o=vn(e,`bytesHeld`);if(t===null||!xn(n)||r===null||i===void 0||a===void 0||o===void 0)return null;let s=Q(e,`reason`),c=Z(e,`segmentOriginMs`),l=Z(e,`framesPerMin`),u=Z(e,`heldFromMs`),d=Z(e,`heldToMs`),f=Q(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 Cn(e){return X(e)?bn(e.cameras,Sn):null}function wn(e){if(!X(e))return null;let t=Q(e,`id`),n=Z(e,`deviceId`),r=Q(e,`scenario`),i=e.lighting,a=Z(e,`fromMs`),o=Z(e,`toMs`),s=e.state,c=Z(e,`frames`),l=Z(e,`gaps`),u=Z(e,`bytes`),d=yn(e,`reviewed`),f=yn(e,`released`),p=bn(e.tracks,e=>typeof e==`string`?e:null),m=Z(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:Q(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 Tn(e){return X(e)?bn(e.tapes,wn):null}function En(e){if(!X(e))return null;let t=Q(e,`trackId`),n=Z(e,`firstT`),r=Z(e,`lastT`),i=Z(e,`boundFrames`),a=Q(e,`cls`),o=yn(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 Dn(e){if(!X(e))return null;let t=Q(e,`tapeId`),n=Z(e,`deviceId`),r=Z(e,`fromMs`),i=Z(e,`toMs`),a=yn(e,`reviewed`),o=bn(e.lanes,En);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 On(e){if(!X(e))return null;if(e.ok===!1){let t=Q(e,`reason`),n=Q(e,`detail`);return t===null||n===null?null:{ok:!1,reason:t,detail:n}}if(e.ok!==!0)return null;let t=Q(e,`tapeId`),n=e.state,r=Z(e,`frames`),i=Z(e,`gaps`),a=Z(e,`pinnedTracks`),o=Z(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 kn(e){if(!X(e))return null;let t=e.status;if(t===`released`){let n=Z(e,`unpinned`),r=yn(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=Q(e,`reason`);return n===null?null:{status:t,reason:n}}return null}function An(e){if(!X(e))return null;let t=e.status;if(t===`deleted`||t===`pins-owed`||t===`not-found`)return{status:t};if(t===`unavailable`){let n=Q(e,`reason`);return n===null?null:{status:t,reason:n}}return null}function jn(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 Mn(e){if(!X(e))return null;let t=Q(e,`leftTrackId`),n=Q(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 Nn(e){if(!X(e))return null;let t=Q(e,`sourceTrackId`),n=e.purity;return t===null||n!==`mixed`&&n!==`not-a-subject`?null:{sourceTrackId:t,purity:n,switchAtMs:Z(e,`switchAtMs`)}}function Pn(e){if(!X(e))return null;let t=bn(e.relations,Mn),n=bn(e.purities,Nn),r=yn(e,`truncated`);return t===null||n===null||r===null?null:{relations:t,purities:n,truncated:r}}function Fn(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 In(e){return e.filter(e=>e.segmentsHeld===null||e.segmentsHeld>0).map(e=>({deviceId:e.deviceId,segmentsUnknown:e.segmentsHeld===null}))}function Ln(e){return e.slice(1).map((t,n)=>({trackId:e[n]??t,otherTrackId:t}))}function Rn(e){return e.flatMap((t,n)=>e.slice(n+1).map(e=>({trackId:t,otherTrackId:e})))}function zn(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 Bn(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 Vn={"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 Hn(e,t){let n=Vn[e]??`Refused (${e}).`;return t.length>0?`${n} ${t}`:n}function Un(e){if(e.length===0)return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null}function Wn(e){return e<1024*1024?`${(e/1024).toFixed(0)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function Gn(e){return e===null?`unknown`:Wn(e)}function Kn(e){return e===null?`unknown`:String(e)}function qn(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 Jn({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=Un(o),s=Un(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=On(await t(dn.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(gn):e.ok?(x(`Promoted ${e.tapeId}: ${String(e.frames)} frames, ${Wn(e.bytes)}, ${String(e.pinnedTracks)} tracks pinned`+(e.state===`incomplete`?` — incomplete (it has gaps) and cannot become a case.`:`.`)),n()):x(Hn(e.reason,e.detail))}catch(e){x(_n(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(Fe,{value:i,options:[...e],onChange:e=>a(e.target.value),"aria-label":`Camera`})}),u(U,{type:`datetime-local`,"aria-label":`From`,value:o,onChange:e=>s(e.target.value),className:`w-48`}),u(U,{type:`datetime-local`,"aria-label":`To`,value:c,onChange:e=>d(e.target.value),className:`w-48`}),u(U,{"aria-label":`Scenario`,placeholder:`615-door-groups`,value:f,onChange:e=>p(e.target.value),className:`w-44`}),u(U,{"aria-label":`Note`,placeholder:`optional note`,value:m,onChange:e=>h(e.target.value),className:`w-52`}),u(`div`,{className:`w-28`,children:u(Fe,{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(K,{className:`h-3.5 w-3.5 animate-spin`}):null,` Promote window`]}),u(`p`,{className:`w-full text-xs text-foreground-subtle`,children:`A promoted tape may be shared as a test case — keep the scenario slug and note free of names or other personal data.`}),b!==null&&u(`p`,{className:`w-full text-xs text-foreground`,children:b})]})}var Yn=`pipeline-analytics`,Xn=`debug.listTracks`,Zn=`debug.analyze`,Qn=p(`/addon/pipeline-analytics/debug-export`);function $n(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function er(e,t){let n=e[t];return typeof n==`string`?n:null}function $(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function tr(e,t){let n=e[t];return typeof n==`boolean`?n:null}function nr(e){return e===`error`||e===`warn`||e===`info`}function rr(e){if(!$n(e))return null;let t=er(e,`code`),n=er(e,`detail`),r=e.severity;return t===null||n===null||!nr(r)?null:{code:t,severity:r,detail:n}}function ir(e){if(!$n(e))return null;let t=er(e,`trackId`),n=$(e,`deviceId`),r=er(e,`className`),i=$(e,`firstSeen`),a=$(e,`lastSeen`),o=$(e,`durationMs`),s=tr(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=er(e,`label`),l=er(e,`subLabel`),u=er(e,`previewMissReason`),d=tr(e,`markForTrain`),f=tr(e,`favourited`);return{trackId:t,deviceId:n,className:r,...c===null?{}:{label:c},...l===null?{}:{subLabel:l},firstSeen:i,lastSeen:a,durationMs:o,active:s,timestamp:i,windowMs:o,importance:$(e,`importance`)??0,bestEventId:er(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function ar(e){let t=ir(e);if(t===null||!$n(e))return null;let n=$(e,`mediaCount`),r=$(e,`eventCount`),i=$(e,`positionCount`);if(n===null||r===null||i===null)return null;let a=e.mediaKinds,o=e.findings;if(!Array.isArray(a)||!Array.isArray(o))return null;let s=a.filter(e=>typeof e==`string`),c=[];for(let e of o){let t=rr(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...xt(l)?{thumbnailProvenance:l}:{}}}function or(e){if(!$n(e))return null;let t=tr(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=ir(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function sr(e){if(!$n(e))return null;let t=e.reports,n=e.vanished;if(!Array.isArray(t)||!Array.isArray(n))return null;let r=[];for(let e of t){let t=ar(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var cr={MEDIA_EVICTED_OR_NEVER:`no media`,MISSING_KEYFRAME:`no keyframe`,MISSING_FIRSTFRAME:`no first frame`,MISSING_LASTFRAME:`no last frame`,MISSING_THUMBNAIL:`no thumbnail`,MISSING_BEST_CROP:`no crop`,SHORT_TRACK:`very short`,ZERO_EVENTS:`no events`,ZERO_POSITIONS:`no trajectory`,NO_PERIODIC_SNAPSHOTS:`no snapshots`,LASTFRAME_STALE:`stale last frame`,MEDIA_STOPPED_EARLY:`media stopped early`,NO_BEST_EVENT:`no best event`,LOW_BEST_SCORE:`low score`,UNSCORED_LABEL:`unscored label`,BEST_SHOT_STANDIN:`stand-in best shot`,BEST_SHOT_RASTER:`low-res best shot`};function lr(e){return cr[e]??e}var ur={error:0,warn:1,info:2};function dr(e){return e.toSorted((e,t)=>ur[e.severity]-ur[t.severity]||e.code.localeCompare(t.code))}function fr(e){return e.length===0?Qn:`${Qn}?deviceIds=${e.join(`,`)}`}function pr(e){if(e<1e4)return`${(e/1e3).toFixed(1)}s`;let t=Math.round(e/1e3);if(t<60)return`${String(t)}s`;let n=Math.floor(t/60);return`${String(n)}m ${String(t%60).padStart(2,`0`)}s`}function mr(e,t){return`${String(e)}:${t}`}function hr(e,t){let n=[],r=new Set;for(let i of e){let e=mr(i.deviceId,i.trackId);!t.has(e)||r.has(e)||(r.add(e),n.push({deviceId:i.deviceId,trackId:i.trackId}))}return n}n();function gr({tapeId:e,call:t,onClose:n,onChanged:i}){let a=o({queryKey:[`events-debug`,`tapes`,`tracks`,e],queryFn:async()=>Dn(await t(dn.tracks,{tapeId:e}))}),s=a.data??null,c=o({queryKey:[`events-debug`,`tapes`,`marks`,e],enabled:s!==null,queryFn:async()=>s===null?null:Pn(await t(fn.list,{deviceId:s.deviceId,since:s.fromMs-mn,until:s.toMs+mn,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(_n(e))}};if(s===null)return a.isLoading?u(`p`,{className:`text-xs`,children:`Loading the tape…`}):u(G,{message:gn});let y=s.deviceId,b=(e,t)=>v(e.map(e=>[fn.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=>[fn.setPurity,{deviceId:y,trackId:t,purity:e,...n===void 0?{}:{switchAtMs:Math.round(n)}}]))},S=c.data==null?null:Fn(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(Ln(d),`same-subject`),children:`Same subject`}),u(H,{variant:`secondary`,disabled:d.length<2,onClick:()=>void b(Rn(d),`different-subjects`),children:`Different subjects`}),u(U,{"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([[dn.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(G,{message:h}),S!==null&&u(G,{variant:`warning`,message:S}),u(`ul`,{className:`space-y-1`,children:s.lanes.toSorted((e,t)=>e.firstT-t.firstT).map(e=>u(_r,{lane:e,marks:c.data===null||c.data===void 0?[]:zn(e.trackId,c.data),selected:d.includes(e.trackId),onToggle:()=>_(e.trackId)},e.trackId))})]})}function _r({lane:e,marks:t,selected:n,onToggle:i}){let{src:a}=Ue(e.stillStored?We(`track`,e.trackId):void 0);return r(`li`,{className:`flex items-center gap-2 text-xs`,children:[u(`input`,{type:`checkbox`,"aria-label":`select ${e.trackId}`,checked:n,onChange:i}),a===null?u(`div`,{className:`h-10 w-10 rounded bg-surface-hover`}):u(`img`,{src:a,alt:e.trackId,className:`h-10 w-10 rounded object-cover`}),u(`span`,{className:`font-mono`,children:e.trackId}),u(`span`,{children:e.cls}),r(`span`,{className:`text-foreground-subtle`,children:[pr(e.firstT),` → `,pr(e.lastT),` · `,String(e.boundFrames),` `,`frames`]}),!e.stillStored&&u(`span`,{className:`text-foreground-subtle`,children:`not stored — marked through the tape`}),t.map(e=>u(W,{variant:`info`,children:e},e))]})}n();var vr=`camstack_admin_token`;function yr(){let e=h();return(t,n)=>e.trpcClient.addons.custom.mutate({addonId:Yn,action:t,input:n})}async function br(e,t){let n=localStorage.getItem(vr),r={};n!==null&&(r.Authorization=`Bearer ${n}`);let i=await fetch(hn(e),{headers:r});if(!i.ok){let e=await i.text().catch(()=>``);throw Error(qn(i.status,e))}let a=await i.blob(),o=i.headers.get(`content-disposition`),s=(o===null?null:/filename="?([^";]+)"?/i.exec(o))?.[1]?.trim()??t,c=URL.createObjectURL(a),l=document.createElement(`a`);l.href=c,l.download=s,l.click(),setTimeout(()=>URL.revokeObjectURL(c),6e4)}function xr(){let[e,t]=l(!1);return u(ke,{expanded:e,onExpandedChange:t,header:u(`span`,{className:`text-sm font-medium text-foreground`,children:`Tracking tapes`}),children:u(Sr,{})})}function Sr(){let e=yr(),t=j({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()=>Cn(await e(dn.status,{}))}),s=o({queryKey:[`events-debug`,`tapes`,`list`],queryFn:async()=>Tn(await e(dn.list,{}))}),[c,d]=l(null),[f,p]=l(null),m=async e=>{p(null);try{await br(e.id,`${e.scenario}.tape-bundle.json.gz`)}catch(e){p(_n(e))}},h=async t=>{let n=kn(await e(dn.release,{tapeId:t.id}));if(n===null)throw Error(gn);let r=jn(n);if(r!==null)throw Error(r);await s.refetch()},g=async t=>{let n=An(await e(dn.remove,{tapeId:t.id}));if(n===null)throw Error(gn);let r=jn(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(G,{message:f}),i.isLoading&&u(`p`,{className:`text-xs text-foreground-subtle`,children:`Loading camera status…`}),i.data===null&&u(G,{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(W,{variant:e.state===`recording`?`success`:e.state===`off`?`default`:e.state===`unknown`?`warning`:`danger`,children:Bn(e)})}),u(`td`,{children:e.framesPerMin===void 0?`—`:String(Math.round(e.framesPerMin))}),u(`td`,{title:e.shelfError,children:Gn(e.bytesLastHour)}),r(`td`,{title:e.shelfError,children:[Kn(e.segmentsHeld),` seg · `,Gn(e.bytesHeld)]}),u(`td`,{children:String(e.gapsSinceArmed)})]},e.deviceId))})]}),u(Jn,{cameras:In(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(G,{message:`The server answered in a shape this build does not understand.`}),r(`table`,{className:`w-full text-xs`,children:[u(`thead`,{children:r(`tr`,{className:`text-left text-foreground-subtle`,children:[u(`th`,{children:`Scenario`}),u(`th`,{children:`Camera`}),u(`th`,{children:`Window`}),u(`th`,{children:`State`}),u(`th`,{children:`Tracks`}),u(`th`,{})]})}),u(`tbody`,{children:(s.data??[]).map(e=>r(`tr`,{children:[u(`td`,{children:e.scenario}),u(`td`,{children:n(e.deviceId)}),r(`td`,{children:[new Date(e.fromMs).toLocaleString(),` · `,pr(e.toMs-e.fromMs),` `,`· `,e.lighting]}),r(`td`,{children:[u(W,{variant:e.state===`complete`?`success`:`warning`,children:e.state}),` `,e.reviewed&&u(W,{variant:`info`,children:`reviewed`}),` `,e.released&&u(W,{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(T,{className:`h-3.5 w-3.5`})}),u(A,{label:`Release`,icon:Me,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(A,{label:`Delete`,icon:y,title:`Delete ${e.scenario}?`,description:`Deleting removes the promoted bundle and its index row for good. Its tracks' pins are released first — this cannot be undone.`,confirmLabel:`Delete`,triggerVariant:`ghost`,confirmVariant:`danger`,action:()=>g(e)})]})]},e.id))})]}),c!==null&&u(gr,{tapeId:c,call:e,onClose:()=>d(null),onChanged:()=>void s.refetch()})]})}n();var Cr=`all`,wr=`The server answered in a shape this build does not understand.`,Tr={error:`danger`,warn:`warning`,info:`info`};function Er({findings:e}){return e.length===0?u(W,{variant:`success`,children:`no anomaly found`}):u(`div`,{className:`flex flex-wrap gap-1`,children:dr(e).map(e=>u(W,{variant:Tr[e.severity],title:e.detail,children:lr(e.code)},e.code))})}function Dr({track:e,report:t,analyzing:n}){let i=Tt(t?.previewMissReason??e.previewMissReason);return r(`div`,{className:`space-y-1 border-t border-border pt-1.5`,children:[t===void 0?u(`span`,{className:`text-[10px] text-foreground-subtle`,children:n?`analysing…`:`not analysed`}):r(s,{children:[u(Er,{findings:t.findings}),r(`p`,{className:`text-[10px] text-foreground-subtle`,title:t.mediaKinds.length>0?t.mediaKinds.join(`, `):`no media of any kind`,children:[String(t.mediaCount),` media · `,String(t.eventCount),` events ·`,` `,String(t.positionCount),` positions`]})]}),i!==null&&u(`p`,{className:`text-[10px] text-foreground-subtle`,title:i.raw,children:i.sentence})]})}function Or(){let e=h(),[t,n]=l(Cr),[i,s]=l(!1),[c,d]=l(null),[f,p]=l(new Set),[m,g]=l(null),[_,v]=l(null),[y,b]=l(null),[x,C]=l([]),w=Ut(),E=j({isCamera:!0,projection:`slim`}),D=a(()=>[{value:Cr,label:`All cameras`},...(E.data??[]).map(e=>({value:String(e.id),label:e.name}))],[E.data]),O=a(()=>{let e=new Map;for(let t of E.data??[])e.set(t.id,t.name);return e},[E.data]),k=e=>O.get(e)??`Camera ${String(e)}`,A=a(()=>t===Cr?[]:[Number.parseInt(t,10)],[t]),M=o({queryKey:[`events-debug`,`list`,A],queryFn:async()=>or(await e.trpcClient.addons.custom.mutate({addonId:Yn,action:Xn,input:A.length===0?{}:{deviceIds:A}}))}),N=a(()=>(M.data?.tracks??[]).map(e=>e.trackId),[M.data]),P=o({queryKey:[`events-debug`,`analyze`,N],enabled:N.length>0,queryFn:async()=>sr(await e.trpcClient.addons.custom.mutate({addonId:Yn,action:Zn,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]),I=M.data?.tracks??[],ee=M.data===null||P.data===null,te=()=>{M.refetch(),P.refetch()},ne=e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},re=()=>{p(new Set(I.map(e=>mr(e.deviceId,e.trackId))))},L=()=>p(new Set),R=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}},ie=e=>{if(!Bt||_!==null)return;let t=hr(I,f);t.length!==0&&(v(e),b(null),(async()=>{let n=await R(e,t);v(null);let r=new Set(n.refused);p(new Set(t.filter(e=>r.has(e.trackId)).map(e=>mr(e.deviceId,e.trackId)))),e===`analyzed`&&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()})())},z=()=>{let e=x;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()})())},ae=async()=>{s(!0),d(null);try{await Ke(fr(A),`camstack-debug.zip`)}catch(e){d(e instanceof Error?e.message:`Export failed.`)}finally{s(!1)}},B=_!==null;return u(He,{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(Fe,{value:t,options:D,onChange:e=>n(e.target.value)})}),r(H,{variant:`secondary`,onClick:te,disabled:M.isFetching,children:[M.isFetching?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(S,{className:`h-3.5 w-3.5`}),`Refresh`]}),r(H,{onClick:()=>void ae(),disabled:i||I.length===0,children:[i?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(T,{className:`h-3.5 w-3.5`}),`Export all (`,String(I.length),`)`]}),I.length>0&&f.size<I.length&&u(H,{variant:`ghost`,onClick:re,children:`Select all`})]}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`A `,u(`code`,{children:`debug`}),` mark does not pin retention — this lists the marked tracks that still exist. A track whose media was evicted shows as missing media. Use `,u(`strong`,{children:`Keep`}),` `,`to hold a selection against pruning while you investigate, and `,u(`strong`,{children:`Analyzed`}),` `,`to un-mark the ones you are finished with.`]}),u(xr,{}),M.isError&&u(G,{message:`Could not load the marked tracks.`}),ee&&!M.isError&&u(G,{message:wr}),c!==null&&u(G,{message:c}),y!==null&&u(G,{message:y}),M.data?.truncated===!0&&u(G,{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:Bt?void 0:`Track flags arrive with the next server update`,children:r(H,{variant:`secondary`,onClick:()=>ie(`keep`),disabled:!Bt||B,children:[_===`keep`?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(xe,{className:`h-3.5 w-3.5`}),` `,`Keep`]})}),u(`span`,{title:Bt?void 0:`Track flags arrive with the next server update`,children:r(H,{onClick:()=>ie(`analyzed`),disabled:!Bt||B,children:[_===`analyzed`?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(be,{className:`h-3.5 w-3.5`}),` `,`Analyzed`]})}),u(H,{variant:`ghost`,onClick:L,disabled:B,children:u(he,{className:`h-3.5 w-3.5`})})]})]}),x.length>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-border bg-surface px-3 py-2`,children:[r(`span`,{className:`text-xs text-foreground`,children:[String(x.length),` track(s) marked analyzed and removed from this list.`]}),r(H,{variant:`ghost`,onClick:z,disabled:B,children:[u(Pe,{className:`h-3.5 w-3.5`}),` Undo`]}),u(H,{variant:`ghost`,onClick:()=>C([]),disabled:B,children:u(he,{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…`})}):I.length===0?u(_e,{children:r(`div`,{className:`flex flex-col items-center gap-2 px-3 py-8 text-center`,children:[u(Oe,{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:I.map(e=>{let t=F.get(e.trackId);return u(Dt,{row:e,cameraName:k(e.deviceId),nowMs:e.lastSeen,selected:f.has(mr(e.deviceId,e.trackId)),onToggleSelect:ne,onOpenDetail:g,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:u(Dr,{track:e,report:t,analyzing:P.isFetching})},mr(e.deviceId,e.trackId))})}),m&&u(un,{row:m,cameraName:k(m.deviceId),deleteAvailable:Qt,onClose:()=>g(null),onDeleted:()=>{g(null),M.refetch()},onFlagsChanged:e=>{e.debug||(g(null),M.refetch())}})]})})}var kr=200,Ar=3e4,jr=[];function Mr(e){let t=h(),n=e.deviceIds.length>0,r=[...e.deviceIds].sort((e,t)=>e-t),{data:i,isLoading:a}=o({queryKey:[`events-feed`,r,e.since,e.until,e.minImportance??null,e.classFilter??null],enabled:n,staleTime:Ar,refetchInterval:Ar,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEventsBatch.query({deviceIds:r,since:e.since,until:e.until,limit:kr,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>e.events.map(t=>({...t,deviceId:e.deviceId})))});return{rows:ht(mt(i??jr),`importance`),isLoading:n&&a}}n();var Nr=[`events-feed`],Pr=2e3;function Fr(n){let r=c(),i=n?.paused===!0,a=t(r);a.current=r;let o=t(i);o.current=i;let[s,u]=l(!1),f=e(()=>{a.current.invalidateQueries({queryKey:Nr})},[]),p=t(void 0);p.current||=rt({delayMs:Pr,invalidate:()=>{o.current?u(!0):f()}}),d(()=>()=>p.current?.cancel(),[]),d(()=>{i||!s||(u(!1),f())},[i,s,f]);let m=e(()=>{u(!1),f()},[f]);return fe(Be.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),fe(Be.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:s,refreshNow:m}}n();function Ir({groups:e,selected:t,onChange:n,loading:i=!1}){let{t:o}=Ve(),[s,c]=l(!1),[d,f]=l(``),[p,h]=l(new Set),g=d.trim().toLowerCase(),_=e=>g.length===0||F(e,o).toLowerCase().includes(g),y=a(()=>e.map(e=>({macro:e.macro,subs:e.subs.filter(t=>_(t)||_(e.macro))})).filter(e=>_(e.macro)||e.subs.length>0),[e,g]),b=e=>h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),x=e=>{let r=new Set(t),i=t.has(e.macro.kind)&&e.subs.every(e=>t.has(e.kind)),a=[e.macro.kind,...e.subs.map(e=>e.kind)];if(i)for(let e of a)r.delete(e);else for(let e of a)r.add(e);n(r)},S=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},C=()=>n(new Set),w=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 ${w>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(B,{className:`h-3.5 w-3.5`}),w>0?`Kinds (${String(w)})`:`Kinds`,u(m,{className:`h-3 w-3`})]}),s&&r(`div`,{className:`absolute z-20 mt-1 max-h-80 w-64 overflow-auto rounded-md border border-border bg-surface p-2 shadow-lg`,children:[r(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[u(te,{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`}),w>0&&u(`button`,{type:`button`,onClick:C,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),y.length===0&&u(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:i?`Loading kinds…`:g.length>0?`No kind matches that search.`:`These cameras advertise no event kinds.`}),y.map(e=>{let n=ne(e.macro.iconId),i=p.has(e.macro.kind)||g.length>0,a=t.has(e.macro.kind);return r(`div`,{className:`mb-0.5`,children:[r(`div`,{className:`flex items-center gap-1`,children:[e.subs.length>0?u(`button`,{type:`button`,onClick:()=>b(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:u(i?m:v,{className:`h-3 w-3`})}):u(`span`,{className:`w-3`}),r(`label`,{className:`flex flex-1 cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[u(`input`,{type:`checkbox`,checked:a,onChange:()=>x(e),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),u(`span`,{className:`font-medium`,children:F(e.macro,o)})]})]}),i&&e.subs.map(e=>{let n=ne(e.iconId);return r(`label`,{className:`ml-5 flex cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[u(`input`,{type:`checkbox`,checked:t.has(e.kind),onChange:()=>S(e.kind),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),u(`span`,{children:F(e,o)})]},e.kind)})]},e.macro.kind)})]})]})}function Lr(e,t){let n=new Map;for(let r of e)if(!(t.size>0&&!t.has(r.deviceId)))for(let e of r.kinds)n.has(e.kind)||n.set(e.kind,e);return n}function Rr(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var zr=new Set([`detection`,`package`]);function Br(e,t){return[...Lr(e,t).values()].filter(e=>e.parentKind===null&&zr.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function Vr(e,t){let n=Lr(e,t),r=new Map,i=new Map;for(let e of n.values()){if(e.parentKind===null){i.set(e.kind,e);continue}let t=r.get(e.parentKind);t===void 0?r.set(e.parentKind,[e]):t.push(e)}for(let[e,t]of r){if(i.has(e))continue;let n=t[0];n!==void 0&&i.set(e,Rr(e,n))}return[...i.values()].map(e=>({macro:e,subs:[...r.get(e.kind)??[]].sort((e,t)=>e.label.localeCompare(t.label))})).sort((e,t)=>e.macro.label.localeCompare(t.macro.label))}n();function Hr(){let[n,r]=l(!1),i=t(null),[a,o]=l(0),s=e(e=>{i.current!==e&&(i.current=e,o(e=>e+1))},[]);return d(()=>{let e=i.current;if(!e||typeof IntersectionObserver>`u`){r(!1);return}let t=new IntersectionObserver(e=>{let t=e[e.length-1];t&&r(!t.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return t.observe(e),()=>t.disconnect()},[a]),{ref:s,scrolledPast:n}}n();var Ur=[`events-feed`],Wr=60,Gr=[{value:`importance`,label:`Importance`,icon:st},{value:`time`,label:`Recent`,icon:ee}];function Kr(){let e=c(),t=L(),n=ie(),[i,o]=l(nt),[f,p]=l(new Set),[m,h]=l(new Set),[g,_]=l(0),[v,b]=l(`time`),[x,S]=l(new Set),[C,w]=l(null),[T,D]=l(()=>Date.now());d(()=>{let e=setInterval(()=>D(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:O,until:k}=a(()=>yt({fromMs:i.fromMs,toMs:i.toMs},T),[i.fromMs,i.toMs,T]),A=Hr(),{pending:M,refreshNow:N}=Fr({paused:C!==null||x.size>0||A.scrolledPast}),{data:P=[]}=j({isCamera:!0,projection:`slim`}),F=a(()=>P.map(e=>e.id),[P]),{data:I,isLoading:ee}=E({deviceIds:F},{enabled:F.length>0,staleTime:5*6e4}),te=a(()=>Vr(I??[],f),[I,f]),ne=tn(),re=ne.isPending,{rows:R,isLoading:z}=Mr({deviceIds:F,since:O,until:k,minImportance:g>0?g:void 0,classFilter:m.size===1?[...m][0]:void 0}),ae=a(()=>{let e=new Map;for(let t of P??[])e.set(t.id,t.name);return e},[P]),B=e=>ae.get(e)??`Camera #${String(e)}`,oe=a(()=>Je(R).map(e=>({id:e,name:B(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[R,ae]),V=a(()=>ht(gt(R,{cameras:f,classes:m,minImportance:g}),v),[R,f,m,g,v]),se=$e(V,Wr,a(()=>JSON.stringify([[...f].sort((e,t)=>e-t),[...m].sort(),g,v,O,k]),[f,m,g,v,O,k])),ce=()=>{e.invalidateQueries({queryKey:Ur})},le=()=>S(new Set);function ue(e){S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function de(){if(x.size===0||!Qt)return;let e=vt(R,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`})&&fe(e)})()}function fe(e){let n=[...e];Promise.allSettled(n.map(([e,t])=>ne.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{ce();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=>B(e)).join(`, `)}. They remain selected — retry, or check the server logs.`,variant:`danger`})})}let pe=V.length!==R.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(tt,{onChange:o}),u(Ze,{cameras:oe,selected:f,onChange:p}),u(Ir,{groups:te,selected:m,onChange:h,loading:ee}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(`span`,{children:`Min score`}),u(`input`,{type:`range`,min:0,max:1,step:.05,value:g,onChange:e=>_(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":`Minimum importance`}),u(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(g*100)})]}),u(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Gr.map(e=>{let t=e.icon;return r(`button`,{type:`button`,onClick:()=>b(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${v===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!z&&u(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:pe?`${String(V.length)} of ${String(R.length)} events`:`${String(V.length)} event${V.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:Qt?void 0:`Track deletion arrives with the next server update`,children:r(H,{variant:`secondary`,onClick:de,disabled:!Qt||re,children:[re?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(y,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),u(H,{variant:`ghost`,onClick:le,disabled:re,children:u(he,{className:`h-3.5 w-3.5`})})]})]}),z&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(K,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!z&&V.length===0&&u(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),M&&u(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:u(`button`,{type:`button`,onClick:N,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`})}),!z&&V.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:se.pageItems.map(e=>u(Dt,{row:e,cameraName:B(e.deviceId),nowMs:T,selected:x.has(_t(e.deviceId,e.trackId)),onToggleSelect:ue,onOpenDetail:w},_t(e.deviceId,e.trackId)))}),u(qe,{currentPage:se.page,totalItems:se.totalItems,pageSize:se.pageSize,onPageChange:se.setPage,itemNoun:`events`})]}),C&&u(un,{row:C,cameraName:B(C.deviceId),deleteAvailable:Qt,onClose:()=>w(null),onDeleted:()=>{ce(),w(null)},onFlagsChanged:e=>{w(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}n();var qr=50,Jr=350,Yr=[{value:`loose`,label:`Loose`,title:`The search model's own floor`},{value:`balanced`,label:`Balanced`,title:`1.25× the search model's floor`},{value:`strict`,label:`Strict`,title:`1.5× the search model's floor`}];function Xr(e){let t=String(e.id);return{id:t,trackId:e.trackId??t,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,subLabel:e.subLabel,importance:e.importance??0,bestEventId:t,mediaId:e.keyFrameMediaId??e.mediaId,windowMs:void 0}}function Zr({onActiveChange:e}){let[t,n]=l(``),[i,o]=l(`loose`),[s,c]=l(null),[f,p]=l(null),[m,h]=l(null),g=ce(t,Jr).trim(),_=g.length>0;d(()=>{e(_)},[_,e]);let[v,y]=l(()=>Date.now());d(()=>{let e=setInterval(()=>y(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:b=[]}=j({isCamera:!0,projection:`slim`}),x=a(()=>{let e=new Map;for(let t of b)e.set(t.id,t.name);return e},[b]),S=e=>x.get(e)??`Camera #${String(e)}`,C=a(()=>b.map(e=>e.id),[b]),{data:w}=E({deviceIds:C},{enabled:C.length>0,staleTime:5*6e4}),T=a(()=>Br(w??[],new Set(f===null?[]:[f])),[w,f]);d(()=>{s!==null&&(T.some(e=>e.kind===s)||c(null))},[T,s]);let{data:D,isFetching:O,isError:k,error:A}=z({text:g,strictness:i,limit:qr,classFilter:s??void 0,deviceId:f??void 0},{enabled:_}),M=a(()=>[...D??[]].sort((e,t)=>t.score-e.score).map(e=>({...Xr(e),score:e.score})),[D]);function N(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(te,{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(he,{className:`h-3.5 w-3.5`})})]}),O&&_&&u(K,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[u(`div`,{className:`flex items-center gap-1`,children:T.map(e=>u(`button`,{type:`button`,onClick:()=>N(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:F(e)},e.kind))}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(`span`,{children:`Camera`}),r(`select`,{value:f===null?``:String(f),onChange:e=>p(e.target.value===``?null:Number(e.target.value)),className:`h-7 rounded-md border border-border bg-background px-1.5 text-xs text-foreground focus:border-primary focus:outline-none`,"aria-label":`Filter by camera`,children:[u(`option`,{value:``,children:`All`}),b.map(e=>u(`option`,{value:String(e.id),children:e.name},e.id))]})]}),r(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(`span`,{children:`Match`}),u(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Yr.map(e=>u(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:e.title,children:e.label},e.value))})]}),_&&!O&&!k&&r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[M.length,` match`,M.length===1?``:`es`]})]})]}),_&&r(`div`,{className:`space-y-3`,children:[k&&r(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,A instanceof Error?A.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!k&&O&&M.length===0&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(K,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!k&&!O&&M.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.`]}),!k&&M.length>0&&u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:M.map(e=>u(Dt,{row:e,cameraName:S(e.deviceId),nowMs:v,score:e.score,onOpenDetail:h},e.id))})]}),m&&u(un,{row:m,cameraName:S(m.deviceId),deleteAvailable:Qt,onClose:()=>h(null),onDeleted:()=>h(null)})]})}n();function Qr(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return`just now`;if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function $r({row:e,cameraName:t,nowMs:n}){let i=Ue(e.keyFrameMediaId===void 0?void 0:Ge(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(dt,{className:`h-6 w-6`})}),u(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:e.label??e.className})]}),r(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[u(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,Qr(n,e.becameStationaryAt)]})]})]})}function ei(){let[e,t]=l(!1),n=Date.now(),{data:i=[]}=j({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}=it(o);return c.length===0&&d===0?null:r(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[r(`button`,{type:`button`,onClick:()=>t(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[u(e?m:v,{className:`h-4 w-4 text-foreground-subtle`}),u(dt,{className:`h-4 w-4 text-foreground-subtle`}),u(`span`,{className:`text-sm font-semibold text-foreground`,children:`Stationary`}),u(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:c.length}),u(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:`Parked objects — kept out of the event feed`}),d>0?r(`span`,{className:`ml-2 text-[11px] text-warning`,children:[d,` camera`,d===1?``:`s`,` could not be read`]}):null]}),e&&u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:c.map(e=>u($r,{row:e,cameraName:s.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}n();function ti(){let[e,t]=l(!1);return u(He,{children:r(`section`,{className:`space-y-3`,children:[u(Zr,{onActiveChange:t}),!e&&u(ei,{}),!e&&u(Kr,{})]})})}var ni=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],ri=new Set(ni);function ii(e){let t=e?.trim().toLowerCase();return t===void 0||t===``?null:ri.has(t)?`"${t}" is a macro class, not a label — person / postman / Marco are three different tiers`:null}function ai({annotations:e,selectedIndex:t,onSelect:n,onChange:i,onDelete:a}){return e.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle p-3`,children:[`No subject on this frame yet. Drag on the image to draw one, or ask the pipeline for a proposal. Annotate `,u(`strong`,{children:`every`}),` subject — a frame with one box and three unlabelled people teaches the model that two thirds of the people in it are background.`]}):u(`ul`,{className:`divide-y divide-border`,children:e.map((e,o)=>{let s=o===t,c=ii(e.label),l=ii(e.subLabel);return r(`li`,{className:`p-2.5 space-y-1.5 ${s?`bg-surface-hover`:``}`,onFocus:()=>{n(o)},children:[r(`div`,{className:`flex items-center gap-2`,children:[u(Fe,{className:`w-28`,value:e.macroClass,options:ni.map(e=>({value:e,label:e})),onChange:e=>{let t=ni.find(t=>t===e.target.value);t!==void 0&&i(o,{macroClass:t})}}),u(Fe,{className:`w-32`,value:e.kind,options:[{value:`subject`,label:`subject`},{value:`model_error`,label:`model error`}],onChange:e=>{i(o,{kind:e.target.value===`model_error`?`model_error`:`subject`})}}),e.source===`assist`&&r(W,{variant:`info`,children:[e.assistModelId??`assist`,e.assistScore===void 0?``:` ${e.assistScore.toFixed(2)}`]}),u(H,{variant:`ghost`,size:`sm`,"aria-label":`Delete this subject`,onClick:()=>{a(o)},children:u(y,{className:`h-3 w-3`})})]}),r(`div`,{className:`flex items-center gap-2`,children:[u(U,{className:`flex-1`,placeholder:`label (postman, van, cat…)`,value:e.label??``,onChange:e=>{i(o,{label:e.target.value})}}),u(U,{className:`flex-1`,placeholder:`sub-label (a name, a plate…)`,value:e.subLabel??``,onChange:e=>{i(o,{subLabel:e.target.value})}})]}),c!==null&&u(`p`,{className:`text-[11px] text-danger`,children:c}),l!==null&&u(`p`,{className:`text-[11px] text-danger`,children:l})]},`${String(o)}-${String(e.bbox.x)}`)})})}function oi(e){return e.every(e=>ii(e.label)===null&&ii(e.subLabel)===null&&ri.has(e.macroClass))}function si(e){return e<0?0:e>1?1:e}function ci(e,t,n,r){if(!(e>0)||!(t>0)||!(n>0)||!(r>0))return null;let i=Math.min(e/n,t/r),a=n*i,o=r*i;return{left:(e-a)/2,top:(t-o)/2,width:a,height:o}}function li(e,t,n){return{x:si((e-n.left)/n.width),y:si((t-n.top)/n.height)}}function ui(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),w:Math.abs(t.x-e.x),h:Math.abs(t.y-e.y)}}function di(e){return e.w>=.01&&e.h>=.01}function fi(e,t){return{left:t.left+e.x*t.width,top:t.top+e.y*t.height,width:e.w*t.width,height:e.h*t.height}}function pi(e,t){let n=-1,r=1/0;return e.forEach((e,i)=>{if(!(t.x>=e.x&&t.x<=e.x+e.w&&t.y>=e.y&&t.y<=e.y+e.h))return;let a=e.w*e.h;a<r&&(n=i,r=a)}),n}n();function mi({imageSrc:n,imageWidth:a,imageHeight:o,boxes:s,selectedIndex:c,onSelect:d,onDraw:f}){let p=t(null),[m,h]=l({w:0,h:0}),[g,_]=l(null);i(()=>{let e=p.current;if(e===null)return;let t=new ResizeObserver(()=>{h({w:e.clientWidth,h:e.clientHeight})});return t.observe(e),h({w:e.clientWidth,h:e.clientHeight}),()=>{t.disconnect()}},[]);let v=ci(m.w,m.h,a,o),y=e(e=>{let t=p.current;if(t===null||v===null)return null;let n=t.getBoundingClientRect();return li(e.clientX-n.left,e.clientY-n.top,v)},[v]);return r(`div`,{ref:p,className:`relative w-full h-full min-h-[280px] bg-surface-sunken select-none touch-none`,onPointerDown:e=>{let t=y(e);t!==null&&(e.currentTarget.setPointerCapture(e.pointerId),_({start:t,current:ui(t,t)}))},onPointerMove:e=>{if(g===null)return;let t=y(e);t!==null&&_({start:g.start,current:ui(g.start,t)})},onPointerUp:()=>{if(g===null)return;let e=g.current;_(null),di(e)?f(e):d(pi(s.map(e=>e.bbox),g.start))},children:[u(`img`,{src:n,alt:`Frame being annotated`,className:`absolute inset-0 w-full h-full object-contain pointer-events-none`}),v!==null&&s.map((e,t)=>{let n=fi(e.bbox,v),i=e.kind===`model_error`,a=t===c,o=i?`#ef4444`:a?`#22c55e`:`#3b82f6`;return u(`div`,{className:`absolute pointer-events-none`,style:{left:n.left,top:n.top,width:n.width,height:n.height,border:`${a?`2px`:`1px`} ${i?`dashed`:`solid`} ${o}`,opacity:e.source===`assist`&&!a?.65:1},children:r(`span`,{className:`absolute -top-4 left-0 text-[10px] px-1 rounded`,style:{background:o,color:`#08121f`},children:[e.label??e.macroClass,i?` ✕`:``]})},`${String(t)}-${String(e.bbox.x)}-${String(e.bbox.y)}`)}),g!==null&&v!==null&&u(`div`,{className:`absolute border border-dashed border-primary pointer-events-none`,style:fi(g.current,v)})]})}n();function hi(){let e=Ie({}),t=je({}),n=le({}),[i,a]=l(null),[o,s]=l(null),c=async(e,t,n)=>{a(e),s(null);try{await Ke(p(t),n)}catch(e){s(e instanceof Error?e.message:String(e))}finally{a(null)}},d=e.data,f=d!==void 0&&d.trackCount===0;return r(`div`,{className:`rounded-md border border-border bg-surface p-3 space-y-2`,children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Export dataset`}),r(H,{variant:`secondary`,size:`sm`,disabled:t.data===void 0||i!==null,onClick:()=>{t.data!==void 0&&c(`annotated`,t.data.url,`camstack-retrain-export.tar`)},children:[i===`annotated`?u(K,{className:`h-3 w-3 animate-spin`}):u(T,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Annotated dataset`})]}),r(H,{variant:`secondary`,size:`sm`,disabled:n.data===void 0||f||i!==null,onClick:()=>{n.data!==void 0&&c(`marked`,n.data.url,`camstack-training-export.tar`)},children:[i===`marked`?u(K,{className:`h-3 w-3 animate-spin`}):u(T,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Marked media`})]})]}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.isError?`The export summary could not be read, so the size of the marked set is unknown — not zero.`:d===void 0?`Measuring the marked set…`:f?`No track is marked for training: the marked-media archive would be empty. The annotated dataset can still hold frames from tracks already completed — this count does not measure those.`:`${String(d.trackCount)} marked track${d.trackCount===1?``:`s`} · ${String(d.fileCount)} file${d.fileCount===1?``:`s`} · ${ot(d.byteCount)}${d.truncated?` · more marked tracks exist than one pass carries`:``}`}),(t.isError||n.isError)&&u(`p`,{className:`text-[11px] text-danger`,children:`An export data plane is not available on the node that answered — no archive can be streamed from here.`}),o!==null&&r(`p`,{className:`text-[11px] text-danger`,children:[`Download failed: `,o]})]})}function gi(e){return e>=1e6?`${(e/1e6).toFixed(1)} MB`:`${Math.round(e/1e3)} KB`}function _i({candidates:e,copies:t,activeFrameId:n,refusals:i,isSelecting:a,onSelectCandidate:o,onOpenCopy:s,onRemoveCopy:c}){let l=new Set(t.map(e=>e.sourceMediaId)),d=e.filter(e=>!l.has(e.mediaId));return r(`div`,{className:`space-y-3`,children:[r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`In the dataset (`,t.length,`)`]}),t.length===0?u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No frame copied yet. Selecting a frame copies it into retrain storage immediately — the dataset stops depending on the track's own media from that moment.`}):u(`ul`,{className:`flex flex-wrap gap-2`,children:t.map(e=>u(`li`,{children:r(`div`,{className:`rounded-md border px-2 py-1.5 text-[11px] ${e.frameId===n?`border-primary bg-surface-hover`:`border-border`}`,children:[r(`button`,{type:`button`,className:`flex items-center gap-1.5 text-left`,onClick:()=>{s(e.frameId)},children:[u(be,{className:`h-3 w-3 text-success`}),u(`span`,{className:`font-medium text-foreground`,children:e.sourceKind}),r(`span`,{className:`text-foreground-subtle`,children:[e.width,`×`,e.height,` · `,gi(e.sizeBytes)]})]}),r(`button`,{type:`button`,"aria-label":`Remove this frame from the dataset`,className:`mt-1 flex items-center gap-1 text-foreground-muted hover:text-danger`,onClick:()=>{c(e.frameId)},children:[u(y,{className:`h-3 w-3`}),`remove`]})]})},e.frameId))})]}),r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`Available frames (`,d.length,`)`]}),d.length===0?u(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.length===0?`This track has no whole, unannotated frame left — its media aged out before it was marked. Anything already copied above is still usable.`:`Every available frame is already in the dataset.`}):u(`ul`,{className:`flex flex-wrap gap-2`,children:d.map(e=>{let t=i.get(e.mediaId);return r(`li`,{children:[r(H,{variant:`secondary`,size:`sm`,disabled:a||t!==void 0,onClick:()=>{o(e.mediaId)},children:[a?u(K,{className:`h-3 w-3 animate-spin`}):u(t===void 0?P:_,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:e.kind}),u(`span`,{className:`ml-1 text-foreground-subtle`,children:gi(e.sizeBytes)})]}),t!==void 0&&u(W,{variant:`danger`,className:`ml-1`,children:t})]},e.mediaId)})})]})]})}function vi(e){return e.frameCount===0?`untouched`:e.annotationCount===0?`started`:`ready`}var yi={untouched:{icon:lt,label:`to do`,variant:`default`},started:{icon:ct,label:`frames only`,variant:`info`},ready:{icon:C,label:`annotated`,variant:`success`}};function bi(e){return new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function xi({tracks:e,isLoading:t,selectedTrackId:n,deviceNames:i,onSelect:a}){return t?r(`div`,{className:`flex items-center gap-2 p-4 text-xs text-foreground-subtle`,children:[u(K,{className:`h-3.5 w-3.5 animate-spin`}),`Loading staging tracks…`]}):e.length===0?u(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`Nothing in staging. Mark a track for training from the viewer or the Events grid and it appears here.`}):u(`ul`,{className:`divide-y divide-border`,children:e.map(e=>{let t=yi[vi(e)],o=t.icon;return u(`li`,{children:r(`button`,{type:`button`,onClick:()=>{a(e)},className:`w-full text-left px-3 py-2 flex items-start gap-2 hover:bg-surface-hover ${e.trackId===n?`bg-surface-hover`:``}`,children:[u(o,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 text-foreground-subtle`}),r(`span`,{className:`min-w-0 flex-1`,children:[r(`span`,{className:`flex items-center gap-2`,children:[u(`span`,{className:`text-xs font-medium text-foreground truncate`,children:e.label??e.className}),u(W,{variant:t.variant,children:t.label})]}),r(`span`,{className:`block text-[11px] text-foreground-subtle truncate`,children:[i.get(e.deviceId)??`Camera ${String(e.deviceId)}`,` ·`,` `,bi(e.lastSeen)]}),r(`span`,{className:`block text-[11px] text-foreground-muted`,children:[e.frameCount,` frame`,e.frameCount===1?``:`s`,` ·`,` `,e.annotationCount,` subject`,e.annotationCount===1?``:`s`]})]})]})},e.trackId)})})}var Si=`object-detection`;function Ci(e,t){for(let n of e){if(n.addonId===t)return n;let e=n.children===void 0?void 0:Ci(n.children,t);if(e!==void 0)return e}}function wi(e,t){for(let n of e.slots){let e=n.addons.find(e=>e.id===t);if(e!==void 0)return e}}function Ti(e){let{status:t,nodeDevices:n,schema:r,resolvedSteps:i}=e;if(t===void 0)return{kind:`unknown`,gap:`pending`};if(t.detection===null)return{kind:`unknown`,gap:t.degraded.some(e=>e.stage===`detection`)?`placement-unreadable`:`detection-off`};let a=t.detection;if(n===void 0||r===void 0||i===void 0)return{kind:`unknown`,gap:`pending`};if(!n.reachable)return{kind:`unknown`,gap:`node-unreachable`};let o=n.devices.find(e=>e.backend===a.engine.backend&&e.device===a.engine.device);if(o===void 0)return{kind:`unknown`,gap:`device-unknown`};let s=wi(r,Si);if(s===void 0)return{kind:`unknown`,gap:`step-unknown`};let c=De({catalog:s,device:o,override:Ci(i,Si)?.modelId,base:o.steps?.[Si]?.modelId});return c===void 0?{kind:`unknown`,gap:`no-model`}:{kind:`resolved`,nodeId:a.nodeId,modelId:c,minScore:s.models.find(e=>e.id===c)?.defaultConfidence??s.defaultConfidence}}n();var Ei=`person`,Di={pending:`Reading which detector this camera runs…`,"placement-unreadable":`The detection stage of this camera could not be read, so the model it runs is unknown — not absent.`,"detection-off":`This camera runs no object detector, so there is no proposal to mirror.`,"node-unreachable":`The node that detects for this camera did not answer about its accelerators.`,"device-unknown":`The node does not list the accelerator this camera detects on — asking another one would propose with a different model.`,"step-unknown":`That node carries no object-detection step in its catalog.`,"no-model":`No object-detection model on that accelerator can be resolved for this camera.`};function Oi(){let[t,n]=l(null),[i,o]=l(null),[c,f]=l([]),[p,m]=l(-1),[h,g]=l(new Map),[_,v]=l(null),y=j({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=oe({}),S=O({trackId:t?.trackId??``},{enabled:t!==null}),C=k({trackId:t?.trackId??``},{enabled:t!==null}),T=Le({frameId:i??``},{enabled:i!==null}),E=se(),D=ve(),A=w(),M=R(),N=we(),P=Te({deviceIds:t===null?[]:[t.deviceId]},{enabled:t!==null,staleTime:3e4}),F=P.data?.[0]?.detection?.nodeId??null,ee=de({nodeId:F??``},{enabled:F!==null,staleTime:3e4}),te=I({nodeId:F??``},{enabled:F!==null,staleTime:3e4}),ne=Ae({deviceId:t?.deviceId??0},{enabled:t!==null,staleTime:3e4}),L=a(()=>Ti({status:P.data?.[0],nodeDevices:ee.data,schema:te.data,resolvedSteps:ne.data?.steps}),[P.data,ee.data,te.data,ne.data]);d(()=>{if(i===null){f([]);return}f((C.data??[]).filter(e=>e.mediaKey===i).map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},...e.subLabel===void 0?{}:{subLabel:e.subLabel},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))),m(-1)},[i,C.data]),d(()=>{let e=S.data?.copies??[];i===null&&e.length>0&&o(e[0].frameId)},[S.data,i]);let ie=e(e=>{n(e),o(null),f([]),g(new Map),v(null)},[]),z=e(async e=>{if(t===null)return;let n=await E.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,mediaIds:[e]});if(n.refused.length>0){let e=new Map(h);for(let t of n.refused)e.set(t.sourceMediaId,t.reason);g(e)}n.copied.length>0&&o(n.copied[0].frameId),await S.refetch(),await x.refetch()},[t,E,h,S,x]),ae=e(async e=>{t!==null&&(await D.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:e}),i===e&&o(null),await S.refetch(),await C.refetch(),await x.refetch())},[t,D,i,S,C,x]),B=e(async e=>{if(t===null||i===null)return;if(v(null),L.kind!==`resolved`){v(Di[L.gap]);return}let n=await A.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:i,subject:e===`package`?{kind:`package`}:{kind:`objects`,modelId:L.modelId,minScore:L.minScore},nodeId:L.nodeId});if(n.kind===`refused`){v(n.reason===`no-zone`?`A package proposal runs on the zone crop only — this camera has no zone, and running the detector on the whole frame at 0.35 proposes furniture.`:`The pipeline refused: ${n.reason}${n.detail===void 0?``:` — ${n.detail}`}`);return}f(e=>[...e,...n.proposals.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))]),v(`${n.proposals.length} proposal${n.proposals.length===1?``:`s`} from ${n.modelId}`+(n.belowThreshold>0?` — ${n.belowThreshold} more were below ${n.minScore.toFixed(2)}`:``))},[t,i,A,L]),V=e(e=>{f(t=>[...t,{bbox:e,macroClass:Ei,kind:`subject`,source:`operator`}]),m(c.length)},[c.length]),ce=e((e,t)=>{f(n=>n.map((n,r)=>r===e?{...n,...t}:n))},[]),le=e(e=>{f(t=>t.filter((t,n)=>n!==e)),m(-1)},[]),ue=e(async()=>{t===null||i===null||(await M.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:i,annotations:c.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label!==void 0&&e.label!==``?{label:e.label}:{},...e.subLabel!==void 0&&e.subLabel!==``?{subLabel:e.subLabel}:{},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))}),await C.refetch(),await x.refetch(),v(`Annotations saved.`))},[t,i,c,M,C,x]),fe=e(async()=>{if(t===null)return;let e=await N.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});v(e.changed?`Track completed — it is now trained, and its own media is evictable again.`:e.reason===`no-frames-copied`?`Refused: no frame was ever copied into the dataset. Completing would let retention delete material nothing was extracted from.`:`Refused: ${e.reason??`unknown`}`),await x.refetch(),e.changed&&n(null)},[t,N,x]),pe=T.data,me=oi(c)&&i!==null;return r(He,{subtitle:`Turn the tracks you marked for training into an annotated dataset. Selecting a frame copies it — the dataset never depends on media that can be swept.`,actions:t===null?null:r(H,{size:`sm`,onClick:()=>void fe(),children:[u(ut,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Complete track`})]}),children:[_!==null&&u(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-xs text-foreground`,children:_}),u(hi,{}),r(`div`,{className:`grid grid-cols-1 lg:grid-cols-[minmax(0,260px)_minmax(0,1fr)] gap-4`,children:[r(`aside`,{className:`rounded-md border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-3 py-2 border-b border-border flex items-center justify-between`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Staging`}),u(W,{children:x.data?.length??0})]}),u(xi,{tracks:x.data??[],isLoading:x.isLoading,selectedTrackId:t?.trackId??null,deviceNames:b,onSelect:ie})]}),u(`section`,{className:`space-y-3 min-w-0`,children:t===null?u(`p`,{className:`text-xs text-foreground-subtle`,children:`Pick a track from the staging list to start annotating it.`}):r(s,{children:[u(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:u(_i,{candidates:S.data?.candidates??[],copies:S.data?.copies??[],activeFrameId:i,refusals:h,isSelecting:E.isPending,onSelectCandidate:e=>void z(e),onOpenCopy:o,onRemoveCopy:e=>void ae(e)})}),i!==null&&r(`div`,{className:`grid grid-cols-1 xl:grid-cols-[minmax(0,1fr)_minmax(0,380px)] gap-3`,children:[u(`div`,{className:`rounded-md border border-border overflow-hidden`,children:pe===void 0?r(`div`,{className:`flex items-center gap-2 p-6 text-xs text-foreground-subtle`,children:[u(K,{className:`h-3.5 w-3.5 animate-spin`}),`Loading the frame…`]}):u(mi,{imageSrc:`data:image/jpeg;base64,${pe.base64}`,imageWidth:pe.width,imageHeight:pe.height,boxes:c,selectedIndex:p,onSelect:m,onDraw:V})}),r(`div`,{className:`rounded-md border border-border bg-surface flex flex-col min-h-0`,children:[r(`div`,{className:`px-3 py-2 border-b border-border flex items-center gap-2`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Subjects`}),r(H,{variant:`secondary`,size:`sm`,disabled:A.isPending||L.kind!==`resolved`,onClick:()=>void B(`objects`),children:[u(re,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Propose`})]}),r(H,{variant:`secondary`,size:`sm`,disabled:A.isPending||L.kind!==`resolved`,onClick:()=>void B(`package`),children:[u(re,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Packages`})]})]}),u(`div`,{className:`px-3 py-1 border-b border-border text-[11px] text-foreground-subtle`,children:L.kind===`resolved`?`Proposals come from ${L.modelId} at ${L.minScore.toFixed(2)}, on ${L.nodeId} — what this camera really runs.`:Di[L.gap]}),u(`div`,{className:`flex-1 overflow-y-auto`,children:u(ai,{annotations:c,selectedIndex:p,onSelect:m,onChange:ce,onDelete:le})}),r(`div`,{className:`px-3 py-2 border-t border-border flex items-center justify-between`,children:[r(`span`,{className:`text-[11px] text-foreground-subtle`,children:[c.filter(e=>e.kind===`model_error`).length,` marked as model errors`]}),u(H,{size:`sm`,disabled:!me||M.isPending,onClick:()=>void ue(),children:`Save frame`})]})]})]})]})})]})]})}function ki(){return u(`div`,{className:`flex flex-col p-4`,children:u(at,{tabs:[{id:`feed`,label:`Feed`,icon:D,content:u(ti,{})},{id:`retrain`,label:`Retrain`,icon:ut,content:u(Oi,{})},{id:`debug`,label:`Debug`,icon:Oe,content:u(Or,{})}]})})}export{ki as EventsPage};
@@ -1 +1 @@
1
- import{K as e,Q as t,S as n,W as r,b 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{_t as s}from"./player-overlays-BPnLENh-.js";import{Hl as c,Pn as l,b as u,ed as d,ln as f,un as p,x as m}from"./src-Ch2D4L9J.js";function h(e){return[e.value,e.label,e.description].filter(e=>typeof e==`string`&&e.length>0).join(` `).toLowerCase()}function g(e,t){let n=t.trim().toLowerCase().split(/\s+/).filter(Boolean);return n.length===0?e:e.filter(e=>{let t=h(e);return n.every(e=>t.includes(e))})}function _(e,t){let n=new Map(e.map(e=>[e.value,e])),r=new Set(t);return{selectedOptions:t.map(e=>n.get(e)??{value:e,label:e}),unselected:e.filter(e=>!r.has(e.value))}}function v(e){return e>=8}t();var y=`block text-[11px] font-medium text-foreground mb-1 break-words`,b=`text-[10px] text-foreground-subtle mt-0.5 break-words`;function x({field:t,value:i,onChange:f,disabled:p,translationFn:h}){let v=Array.isArray(i)?i:[],x=p===!0||t.disabled===!0,S=t.maxItems!==void 0&&v.length>=t.maxItems,[C,w]=a(``),[E,D]=a(!1),[O,k]=a(0),A=e(null),j=e(null),{selectedOptions:M}=r(()=>_(t.options,v),[t.options,v]),N=r(()=>g(t.options,C),[t.options,C]),P=e=>{if(!x)if(v.includes(e))f(v.filter(t=>t!==e));else{if(t.maxItems!==void 0&&v.length>=t.maxItems)return;f([...v,e])}},F=e=>{if(e.key===`ArrowDown`)e.preventDefault(),D(!0),k(e=>N.length===0?0:(e+1)%N.length);else if(e.key===`ArrowUp`)e.preventDefault(),D(!0),k(e=>N.length===0?0:(e-1+N.length)%N.length);else if(e.key===`Enter`){e.preventDefault();let t=N[O];t&&P(t.value)}else e.key===`Escape`?D(!1):e.key===`Backspace`&&C===``&&v.length>0&&f(v.slice(0,-1))},I=T(t.label,h),L=T(t.description,h);return n(`div`,{className:`min-w-0`,children:[I!==void 0&&I!==``&&o(`label`,{className:y,children:I}),M.length>0&&o(`div`,{className:`flex flex-wrap gap-1 mb-1.5`,children:M.map(e=>o(m,{label:e.label,...e.iconId===void 0?{}:{iconId:e.iconId},...x?{}:{onRemove:()=>P(e.value)}},e.value))}),n(`div`,{className:u+(x?` opacity-50`:``),children:[o(c,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),o(`input`,{ref:A,type:`text`,role:`combobox`,"aria-expanded":E,"aria-controls":`msel-${t.key}`,className:`min-w-0 flex-1 bg-transparent text-xs text-foreground outline-none placeholder:text-foreground-disabled`,value:C,placeholder:S?`Max ${t.maxItems} selected`:t.placeholder??`Search to add…`,disabled:x,onChange:e=>{w(e.target.value),D(!0),k(0)},onFocus:()=>D(!0),onBlur:()=>{j.current=setTimeout(()=>D(!1),120)},onKeyDown:F}),o(s,{className:`h-3.5 w-3.5 shrink-0 cursor-pointer text-foreground-subtle`,onMouseDown:e=>{e.preventDefault(),j.current&&clearTimeout(j.current),D(e=>!e),A.current?.focus()}})]}),E&&!x&&o(`div`,{id:`msel-${t.key}`,role:`listbox`,className:`mt-1 max-h-56 overflow-y-auto rounded-md border border-border bg-surface shadow-lg`,onMouseDown:e=>{e.preventDefault()},children:N.length===0?n(`div`,{className:`px-2.5 py-2 text-[11px] text-foreground-subtle italic`,children:[`No matches for “`,C,`”`]}):N.map((e,t)=>{let r=v.includes(e.value),i=!r&&S;return n(`button`,{type:`button`,role:`option`,"aria-selected":r,disabled:i,className:[`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-xs transition-colors`,t===O?`bg-primary/10`:`hover:bg-surface-hover`,i?`opacity-40 cursor-not-allowed`:`cursor-pointer`].join(` `),onMouseEnter:()=>k(t),onClick:()=>P(e.value),children:[o(`span`,{className:[`flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded border`,r?`border-primary bg-primary text-white`:`border-border`].join(` `),children:r&&o(d,{className:`h-2.5 w-2.5`})}),e.iconId!==void 0&&o(l,{iconId:e.iconId,size:13}),o(`span`,{className:`truncate text-foreground`,children:e.label})]},e.value)})}),L&&o(`p`,{className:b,children:L})]})}t();function S(e){return e.type===`multiselect`}function C({field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,externalProbe:s,allFields:c,onAction:l}){return S(e)&&v(e.options.length)?p(e,t,c)?o(x,{field:e,value:t[e.key],onChange:t=>n(e.key,t),disabled:r,translationFn:i}):null:o(f,{field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,externalProbe:s,allFields:c,onAction:l})}function w(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function T(e,t){if(e!==void 0)return t&&w(e)?t(e):e}function E({section:e,values:t,onChange:r,disabled:s,translationFn:c,onTestField:l,probeResults:u,onAction:d}){let[m,h]=a(e.defaultCollapsed??!1),g=e.style===`accordion`;if(e.fields.reduce((n,r)=>n+ +!!p(r,t,e.fields),0)===0)return null;let _=e.fields,v=e.columns??2,y=v===1?`grid-cols-1`:v===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:v===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`,b=e.fields.length===1&&e.fields[0]?.type===`widget`?e.fields[0]:void 0;return n(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},children:[!(b!==void 0||!e.title&&!e.description)&&n(`div`,{className:[`flex items-center justify-between mb-2`,g?`cursor-pointer`:``].join(` `),onClick:g?()=>h(e=>!e):void 0,children:[n(`div`,{children:[e.title&&o(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:T(e.title,c)}),e.description&&o(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:T(e.description,c)})]}),g&&o(`span`,{className:`text-foreground-subtle text-xs ml-2`,children:m?`▸`:`▾`})]}),!m&&(b===void 0?o(i,{children:o(`div`,{className:`grid ${y} gap-x-3 gap-y-2.5`,children:_.map(n=>o(C,{field:n,values:t,onChange:r,disabled:s,translationFn:c,onTestField:l,externalProbe:u?.[n.key],allFields:e.fields,onAction:d},n.key))})}):o(f,{field:b,values:t,onChange:r,disabled:s,translationFn:c,onTestField:l,externalProbe:u?.[b.key],allFields:e.fields,onAction:d},b.key))]})}function D({schema:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,probeResults:s,onClearProbe:c,onAction:l}){let u=(e,r)=>{n({...t,[e]:r}),c?.(e)};return o(`div`,{className:`space-y-4`,children:e.sections.map((e,n)=>o(E,{section:e,values:t,onChange:u,disabled:r,translationFn:i,onTestField:a,probeResults:s,onAction:l},`${e.id}-${n}`))})}export{D as t};
1
+ import{K as e,Q as t,S as n,W as r,b 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{_t as s}from"./player-overlays-cfiayLzw.js";import{Fn as c,Kl as l,S as u,dn as d,id as f,un as p,x as m}from"./src-FuqzctFV.js";function h(e){return[e.value,e.label,e.description].filter(e=>typeof e==`string`&&e.length>0).join(` `).toLowerCase()}function g(e,t){let n=t.trim().toLowerCase().split(/\s+/).filter(Boolean);return n.length===0?e:e.filter(e=>{let t=h(e);return n.every(e=>t.includes(e))})}function _(e,t){let n=new Map(e.map(e=>[e.value,e])),r=new Set(t);return{selectedOptions:t.map(e=>n.get(e)??{value:e,label:e}),unselected:e.filter(e=>!r.has(e.value))}}function v(e){return e>=8}t();var y=`block text-[11px] font-medium text-foreground mb-1 break-words`,b=`text-[10px] text-foreground-subtle mt-0.5 break-words`;function x({field:t,value:i,onChange:d,disabled:p,translationFn:h}){let v=Array.isArray(i)?i:[],x=p===!0||t.disabled===!0,S=t.maxItems!==void 0&&v.length>=t.maxItems,[C,w]=a(``),[E,D]=a(!1),[O,k]=a(0),A=e(null),j=e(null),{selectedOptions:M}=r(()=>_(t.options,v),[t.options,v]),N=r(()=>g(t.options,C),[t.options,C]),P=e=>{if(!x)if(v.includes(e))d(v.filter(t=>t!==e));else{if(t.maxItems!==void 0&&v.length>=t.maxItems)return;d([...v,e])}},F=e=>{if(e.key===`ArrowDown`)e.preventDefault(),D(!0),k(e=>N.length===0?0:(e+1)%N.length);else if(e.key===`ArrowUp`)e.preventDefault(),D(!0),k(e=>N.length===0?0:(e-1+N.length)%N.length);else if(e.key===`Enter`){e.preventDefault();let t=N[O];t&&P(t.value)}else e.key===`Escape`?D(!1):e.key===`Backspace`&&C===``&&v.length>0&&d(v.slice(0,-1))},I=T(t.label,h),L=T(t.description,h);return n(`div`,{className:`min-w-0`,children:[I!==void 0&&I!==``&&o(`label`,{className:y,children:I}),M.length>0&&o(`div`,{className:`flex flex-wrap gap-1 mb-1.5`,children:M.map(e=>o(u,{label:e.label,...e.iconId===void 0?{}:{iconId:e.iconId},...x?{}:{onRemove:()=>P(e.value)}},e.value))}),n(`div`,{className:m+(x?` opacity-50`:``),children:[o(l,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),o(`input`,{ref:A,type:`text`,role:`combobox`,"aria-expanded":E,"aria-controls":`msel-${t.key}`,className:`min-w-0 flex-1 bg-transparent text-xs text-foreground outline-none placeholder:text-foreground-disabled`,value:C,placeholder:S?`Max ${t.maxItems} selected`:t.placeholder??`Search to add…`,disabled:x,onChange:e=>{w(e.target.value),D(!0),k(0)},onFocus:()=>D(!0),onBlur:()=>{j.current=setTimeout(()=>D(!1),120)},onKeyDown:F}),o(s,{className:`h-3.5 w-3.5 shrink-0 cursor-pointer text-foreground-subtle`,onMouseDown:e=>{e.preventDefault(),j.current&&clearTimeout(j.current),D(e=>!e),A.current?.focus()}})]}),E&&!x&&o(`div`,{id:`msel-${t.key}`,role:`listbox`,className:`mt-1 max-h-56 overflow-y-auto rounded-md border border-border bg-surface shadow-lg`,onMouseDown:e=>{e.preventDefault()},children:N.length===0?n(`div`,{className:`px-2.5 py-2 text-[11px] text-foreground-subtle italic`,children:[`No matches for “`,C,`”`]}):N.map((e,t)=>{let r=v.includes(e.value),i=!r&&S;return n(`button`,{type:`button`,role:`option`,"aria-selected":r,disabled:i,className:[`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-xs transition-colors`,t===O?`bg-primary/10`:`hover:bg-surface-hover`,i?`opacity-40 cursor-not-allowed`:`cursor-pointer`].join(` `),onMouseEnter:()=>k(t),onClick:()=>P(e.value),children:[o(`span`,{className:[`flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded border`,r?`border-primary bg-primary text-white`:`border-border`].join(` `),children:r&&o(f,{className:`h-2.5 w-2.5`})}),e.iconId!==void 0&&o(c,{iconId:e.iconId,size:13}),o(`span`,{className:`truncate text-foreground`,children:e.label})]},e.value)})}),L&&o(`p`,{className:b,children:L})]})}t();function S(e){return e.type===`multiselect`}function C({field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,externalProbe:s,allFields:c,onAction:l}){return S(e)&&v(e.options.length)?d(e,t,c)?o(x,{field:e,value:t[e.key],onChange:t=>n(e.key,t),disabled:r,translationFn:i}):null:o(p,{field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,externalProbe:s,allFields:c,onAction:l})}function w(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function T(e,t){if(e!==void 0)return t&&w(e)?t(e):e}function E({section:e,values:t,onChange:r,disabled:s,translationFn:c,onTestField:l,probeResults:u,onAction:f}){let[m,h]=a(e.defaultCollapsed??!1),g=e.style===`accordion`;if(e.fields.reduce((n,r)=>n+ +!!d(r,t,e.fields),0)===0)return null;let _=e.fields,v=e.columns??2,y=v===1?`grid-cols-1`:v===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:v===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`,b=e.fields.length===1&&e.fields[0]?.type===`widget`?e.fields[0]:void 0;return n(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},children:[!(b!==void 0||!e.title&&!e.description)&&n(`div`,{className:[`flex items-center justify-between mb-2`,g?`cursor-pointer`:``].join(` `),onClick:g?()=>h(e=>!e):void 0,children:[n(`div`,{children:[e.title&&o(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:T(e.title,c)}),e.description&&o(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:T(e.description,c)})]}),g&&o(`span`,{className:`text-foreground-subtle text-xs ml-2`,children:m?`▸`:`▾`})]}),!m&&(b===void 0?o(i,{children:o(`div`,{className:`grid ${y} gap-x-3 gap-y-2.5`,children:_.map(n=>o(C,{field:n,values:t,onChange:r,disabled:s,translationFn:c,onTestField:l,externalProbe:u?.[n.key],allFields:e.fields,onAction:f},n.key))})}):o(p,{field:b,values:t,onChange:r,disabled:s,translationFn:c,onTestField:l,externalProbe:u?.[b.key],allFields:e.fields,onAction:f},b.key))]})}function D({schema:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,probeResults:s,onClearProbe:c,onAction:l}){let u=(e,r)=>{n({...t,[e]:r}),c?.(e)};return o(`div`,{className:`space-y-4`,children:e.sections.map((e,n)=>o(E,{section:e,values:t,onChange:u,disabled:r,translationFn:i,onTestField:a,probeResults:s,onAction:l},`${e.id}-${n}`))})}export{D as t};
@@ -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{_t as c,at as l,gt as u,st as d,yt as f}from"./player-overlays-cfiayLzw.js";import{Bc as p,Cu as m,D as h,E as g,Fi as _,Fl as v,Gc as y,Hc as b,Hl as x,I as S,Iu as C,Jc as w,Kc as T,L as E,Nn as D,Pn as ee,Qc as te,Rc as O,Sn as k,Su as ne,Uc as A,Vc as j,Vl as M,Wc as N,Wu as P,Xc as F,Yc as I,Zc as re,ar as L,au as ie,cl as R,ed as z,id as B,ir as V,qc as ae,su as H,vl as oe,wt as se,wu as U,yu as W,zc as ce}from"./src-FuqzctFV.js";import{a as le,i as ue,o as de,s as fe}from"./src-CYSHGOVz.js";import{b as pe,u as G}from"./index-Bleh56hg.js";import{t as K}from"./AdminPage-CiKtOLQm.js";import{t as me}from"./AdminTabs-BE0YQcz6.js";import{t as he}from"./AddonCollectionPage-Bz3KyJNf.js";import{t as ge}from"./addon-display-names-DvSEQty-.js";var _e=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`}]]),ve=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`}]]),ye=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 be({userId:e,username:n,onClose:r}){let o=a(),c=D(),l=b({userId:e}),u=l.data,d=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),f=j({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(v,{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(R,{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(W,{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(U,{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(z,{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(k,{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(W,{className:`h-3 w-3 animate-spin`}):s(R,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function q({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 xe({scopes:e,isAdmin:n,invalidReason:a}){let o=l(),c=r({queryKey:[`auth`,`previewScope`,e,n],enabled:a===null,queryFn:()=>o.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:n})}),{data:u}=_({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(x,{className:`h-3 w-3 shrink-0`}),a]})});if(c.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(W,{className:`h-3 w-3 animate-spin`}),`Resolving…`]});if(c.isError||!c.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=c.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(q,{icon:C,label:`Devices they can see`,count:p.device.view.deviceCount,all:p.device.view.all,total:f}),s(q,{icon:H,label:`Devices they can operate`,count:p.device.create.deviceCount,all:p.device.create.all,total:f}),s(q,{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 Se(e){let t=de(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 Ce(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:le({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function we({user:e,onClose:r,onSubmit:a,submitting:l,callerScopes:d}){let f=n(()=>Se(e.scopes??[]),[e.scopes]),[p,m]=o(f),[_,v]=o(f.mode===`advanced`),y=n(()=>Ce(p),[p]),b=!e.isAdmin&&p.mode===`role`&&p.roleId===null,C=n(()=>e.isAdmin?null:p.mode===`role`&&p.roleId===null?`Pick what this user can do to see the result.`:h(y),[e.isAdmin,p.mode,p.roleId,y]),w=e=>m({...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(R,{className:`h-4 w-4`})})]}),t(`div`,{className:`min-h-0 flex-1 space-y-4 overflow-y-auto px-4 py-4`,children:[b&&t(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[s(x,{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:ue.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:()=>w({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(!_){m({...p,mode:`advanced`,advancedScopes:y}),v(!0);return}v(!1),m(Se(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(_?c: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(g,{value:p.advancedScopes,onChange:e=>w({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(S,{value:p.selector,onChange:e=>w({selector:e}),includeLinked:p.includeLinked,onIncludeLinkedChange:e=>w({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(xe,{scopes:y,isAdmin:e.isAdmin,invalidReason:C})]})]}),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:l||C!==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:l?s(W,{className:`h-3 w-3 animate-spin`}):`Save access`})]})]})})}e();var Te=8;function Ee(){let e=a(),{user:n}=G(),[r,i]=o(!1),[c,l]=o(``),[u,f]=o(``),[m,h]=o(!1),[g,_]=o(null),{data:y,isLoading:b,isError:x}=T(),S=D(),C=ee(),w=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),E=ce({onSuccess:()=>{w(),i(!1),l(``),f(``),h(!1),_(null)},onError:e=>{_(e instanceof Error?e.message:`Failed to create user`)}}),O=p({onSuccess:w}),k=te({onSuccess:w}),A=ae({onSuccess:w}),j=re({onSuccess:()=>{w(),P(null)}}),[N,P]=o(null),[F,I]=o(null),L=y??[];async function z(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`})&&O.mutate({id:e.id})}async function B(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<Te?`Password must be at least ${String(Te)} 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`})&&A.mutate({id:e.id,newPassword:t})}function V(e,t){t!==e.isAdmin&&k.mutate({id:e.id,isAdmin:t})}function H(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return t(K,{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(ie,{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(R,{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=>h(e.target.checked),className:`rounded border-border focus:ring-primary`}),s(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),g&&s(`p`,{className:`text-[10px] text-danger`,children:g}),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&&L.length===0&&s(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>O.isPending&&O.variables?.id===e.id||k.isPending&&k.variables?.id===e.id||A.isPending&&A.variables?.id===e.id;return s(se,{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=>V(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:()=>P(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(M,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(De,{scopes:e.scopes??[]})]})},{key:`createdAt`,header:`Created`,render:e=>s(`span`,{className:`text-foreground-subtle`,children:H(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:()=>I(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(v,{className:`h-3 w-3`}),`Remove 2FA`]}),t(`button`,{onClick:()=>B(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(ne,{className:`h-3 w-3`}),`Reset password`]}),t(`button`,{onClick:()=>z(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(W,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:L,rowKey:e=>e.id,minWidthPx:560})})(),F&&s(be,{userId:F.id,username:F.username,onClose:()=>I(null)}),N&&s(Oe,{user:N,onClose:()=>P(null),onSubmit:e=>j.mutate({userId:N.id,scopes:e}),submitting:j.isPending})]})}function De({scopes:e}){if(e.length===0)return s(`span`,{className:`font-medium text-warning`,children:`No access`});let n=de(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:fe(n.roleId).label}),` ·`,` `,E(n.selector)]})}function Oe(e){let{user:t}=G(),n=t?.isAdmin===!0;return s(we,{...e,callerScopes:n?null:t?.scopes??[]})}e();var ke=`bg-primary/10 text-primary`,Ae=`bg-foreground-subtle/10 text-foreground-subtle`;function J(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function je(e){return e?e===`*`?`*`:e.join(`, `):``}function Me(){let e=a(),r=D(),{data:i,isLoading:c}=A(),{data:l}=T(),u=n(()=>i??[],[i]),f=n(()=>l??[],[l]),p=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),m=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[h,g]=o(!1),[_,v]=o(null),y=w({onSuccess:p}),b=O({onSuccess:({token:e,record:t})=>{m(),g(!1),v({token:e,label:t.name})}}),x=F({onSuccess:m}),S=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`})&&y.mutate({id:e})},C=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&x.mutate({id:e})};return t(K,{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:()=>g(!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(M,{className:`h-3.5 w-3.5`}),`New token`]})]}),t(Ne,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[f.length===0&&s(Fe,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),f.map(e=>s(Le,{userId:e.id,username:e.username,onRevoke:(e,t)=>{C(e,t)},revokePending:x.isPending,revokeId:x.variables?.id},e.id))]}),u.length>0&&s(Ne,{title:`Legacy API keys`,subtitle:`${u.length} pre-existing — revoke only`,children:s(Ie,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:u.map(e=>{let n=!!e.isAdmin,r=y.isPending&&y.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?ke:Ae}`,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:je(e.allowedProviders)||`all`}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.createdAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:t(`button`,{onClick:()=>{S(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(W,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),c&&s(Pe,{}),h&&s(Re,{users:f.map(e=>({id:e.id,username:e.username})),onClose:()=>g(!1),onSubmit:e=>b.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:b.isPending}),_&&s(ze,{token:_.token,label:_.label,onClose:()=>v(null)})]})}function Ne({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 Pe(){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 Fe({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 Ie({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 Le({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(Ie,{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`?`[${E(e.selector)}]`:e.target]},n))})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.expiresAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(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(W,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function Re({users:e,onClose:n,onSubmit:r,submitting:i}){let{user:a}=G(),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`]}]),[_,v]=o(``),y=h(p),b=l!==``&&d.trim().length>0&&p.length>0&&y===null&&!i;return t(Be,{title:`Create scoped token`,onClose:n,children:[t(`div`,{className:`space-y-3`,children:[s(Y,{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(Y,{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(Y,{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(g,{value:p,onChange:m,clampToParent:c}),y&&s(`p`,{className:`mt-1 text-[10px] text-danger`,children:y})]}),s(Y,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:s(`input`,{type:`number`,min:1,value:_,onChange:e=>v(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(Ve,{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(_,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;r({userId:l,name:d.trim(),scopes:p,expiresAt:t})},disabled:!b,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(W,{className:`h-3.5 w-3.5 animate-spin`}):s(M,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function ze({token:e,label:n,onClose:r}){let[i,a]=o(!1),c=async()=>{try{await navigator.clipboard.writeText(e),a(!0)}catch{}};return t(Be,{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(Ve,{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(B,{className:`h-3.5 w-3.5 text-primary`}):s(P,{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 Be({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(R,{className:`h-4 w-4`})})]}),s(`div`,{className:`p-4`,children:r})]})})}function Ve({children:e}){return s(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Y({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 X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function He(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 Ue(){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 We({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 Ge({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 Ke(){let e=a(),r=D(),{data:i,isLoading:o}=N(),c=n(()=>i??[],[i]),l=I({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(K,{icon:ye,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(Ue,{}),!o&&c.length===0&&s(We,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!o&&c.length>0&&s(Ge,{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:He(e)},t))})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(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 `,X(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(W,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}e();var Z=3e4,Q=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],$={title:`Authentication providers`,subtitle:`Every registered authentication surface in one list: login providers (local password, OIDC, SAML, magic-link) and second-factor providers (passkeys / WebAuthn — configure the relying-party RP ID + origin inline; users enroll from My access → Passkeys). Multiple providers run in parallel — enable/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 qe(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:ve,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:pe,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`First-time sign-ins are auto-provisioned with the configured Default Role.`],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.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:pe,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:v,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:v,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:M,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Je(){let e=L({capName:Q[0].capName},{refetchInterval:Z}),t=L({capName:Q[1].capName},{refetchInterval:Z}),r=V(void 0,{refetchInterval:Z}),i=n(()=>ge(r.data??[]),[r.data]),a=n(()=>{let n=[],r=[e.data??[],t.data??[]];for(let[e,t]of Q.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]);return s(he,{title:$.title,subtitle:$.subtitle,pageIcon:M,itemIcon:M,capability:Q[0].capName,installButtonLabel:$.installLabel,items:a,isLoading:e.isLoading||t.isLoading,emptyTitle:$.emptyTitle,emptyDescription:$.emptyDescription,renderStatusBadges:e=>e.stageBadge===null?null:s(`span`,{className:`inline-flex items-center rounded-full border border-primary/30 bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary`,children:e.stageBadge}),renderExpandedPanel:e=>s(Ye,{addonId:e.addonId})})}function Ye({addonId:e}){let n=qe(e),r=n.icon;return t(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,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(_e,{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(U,{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(`a`,{href:`/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(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function Xe(){return s(`div`,{className:`flex flex-col p-4`,children:s(me,{tabs:[{id:`users`,label:`Users`,icon:oe,content:s(Ee,{})},{id:`api-keys`,label:`Tokens`,icon:m,content:s(Me,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:ye,content:s(Ke,{})},{id:`authentication`,label:`Authentication`,icon:M,content:s(Je,{})}]})})}export{Xe 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,_t as d,at as f,gt as p,mt as m,st as h,yt as g}from"./player-overlays-cfiayLzw.js";import{$ as _,$l as v,$u as y,Aa as b,Ai as x,B as S,Cl as C,Da as w,Di as T,Ea as E,Ei as D,Et as O,Fi as k,Hi as A,Iu as ee,Kn as j,Ma as M,Oa as N,Ql as te,Qt as P,Sd as ne,Si as F,Ta as I,U as L,V as R,Wi as z,Wl as re,Yu as B,_i as V,au as H,bi as ie,cl as ae,cn as U,dl as oe,gi as se,hi as W,ht as ce,id as G,ka as le,kt as ue,lr as de,mi as K,nt as fe,ql as pe,qn as me,sa as q,tu as he,vi as ge,xi as _e,yu as J}from"./src-FuqzctFV.js";import{Vn as ve}from"./src-CYSHGOVz.js";import{f as ye,l as be,m as xe,p as Se}from"./index-Bleh56hg.js";import{t as Ce}from"./FormBuilder-CUKZeqaR.js";import{t as we}from"./device-integration-icon-DhrVTlMx.js";import{n as Te,r as Y,t as Ee}from"./ScanNetworkModal-BNgDBkJM.js";import{t as De}from"./NodeAddonsSettingsPanel-Cvi-yx7B.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:f}=be(),p=o(),[m,h]=s({}),[g,_]=s(!1),[v,y]=s(null),[b,S]=s(X),w=A({addonId:a},{enabled:t}),T=w.data?.deviceType??null,E=x({addonId:a,type:T??ve.Camera},{enabled:t&&w.isSuccess&&T!==null}),D=E.data??null;l(()=>{t&&(h(D?Ne(D.sections.flatMap(e=>e.fields)):{}),S(X()),_(!1),y(null))},[t,n,D]);let O=i(()=>({...m,_probeRequestId:b}),[m,b]),k=_e({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ee=q(),j=e(async(e,t)=>{_(!0);let n=await ee.mutateAsync({addonId:a,type:T??ve.Camera,key:e,value:t,formValues:O});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},[ee,a,O,T]),{testAllStatus:M,hasProbeFields:N,probeResults:te,handleTestAll:P,clearProbeResult:ne}=Ae(D??{sections:[]},m,j);async function F(e){y(null);try{await k.mutateAsync({addonId:a,type:T??ve.Camera,config:m,integrationId:n}),e?h(D?Ne(D.sections.flatMap(e=>e.fields)):{}):u()}catch(e){y(e instanceof Error?e.message:String(e))}}if(!t)return null;let I=je((D?.sections??[]).flatMap(e=>e.fields)).filter(e=>Me(m[e])),L=I.length===0,R=w.isLoading||T!==null&&E.isLoading,z=w.isError||w.isSuccess&&T===null||E.isError||E.isSuccess&&D===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:f(`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(ae,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:R?c(`div`,{className:`flex items-center justify-center py-8`,children:c(J,{className:`h-5 w-5 animate-spin text-primary`})}):z?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[c(C,{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(Ce,{schema:D,values:m,onChange:h,onTestField:j,probeResults:te,onClearProbe:ne})}),!z&&!R&&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(pe,{className:`h-3.5 w-3.5`}),`Test logs`,c(`span`,{className:`font-mono text-[9px] opacity-60`,children:b.slice(0,14)})]}),c(d,{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(ce,{addonId:a,requestId:b,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!z&&!R&&(v||I.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(C,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:v||`Required: ${I.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:f(`integrations.cancel`)}),!z&&N&&r(`button`,{type:`button`,onClick:P,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(J,{className:`h-3.5 w-3.5 animate-spin`}):c(oe,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:()=>F(!0),disabled:z||!L||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:f(`integrations.saveAndNew`)}),c(`button`,{onClick:()=>F(!1),disabled:z||!L||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?f(`integrations.saving`):f(`integrations.save`)})]})]})]})]})}var Fe=1500;function Z({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=be(),o=K(),s=(V({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(J,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):s.failed>0?c(C,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):s.state===`cancelled`?c(B,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):c(y,{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}=be(),d=o(),[f,p]=s(new Set),[m,h]=s(new Set),[g,v]=s(new Map),[y,b]=s(null),{data:x}=w(),T=(x??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[E,D]=s(!0),O=W({addonId:n,integrationId:i}).data?.filters,k=O&&O.length>0?O:[Le],[A,ee]=s(k.find(e=>e.isDefault)?.id??(k.some(e=>e.id===Q)?Q:k[0].id)),j=A!==Q,M=ge(),N=se({addonId:n,integrationId:i,page:1,pageSize:Re,filter:A}),P=N.refetch,ne=M.mutate,F=e(()=>{ne({addonId:n,integrationId:i},{onSettled:()=>{P()}})},[ne,n,i,P]),I=t(null);l(()=>{let e=`${n}::${i}`;I.current===e||N.isLoading||(I.current=e,(N.data?.candidates.length??0)===0&&F())},[n,i,N.isLoading,N.data,F]);let L=M.isPending,R=M.isError?M.error instanceof Error?M.error.message:String(M.error):null,z=typeof M.data?.lastError==`string`&&M.data.lastError.length>0?M.data.lastError:null,re=N.data?.candidates??[],B=N.isError?N.error instanceof Error?N.error.message:String(N.error):null,V=ie(),[H,U]=s(null),oe=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})},[]),ce=e(e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),le=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})},[]),ue=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]),de=e(async()=>{b(null);let e=[...f];if(e.length!==0)try{let t=ue(e),{jobId:r}=await V.mutateAsync({addonId:n,integrationId:i,filter:A,childNativeIds:e,...t?{perCandidate:t}:{},...T?{importLocations:E}:{}});U(r),p(new Set),v(new Map)}catch(e){b(e instanceof Error?e.message:String(e))}},[f,ue,V,n,i,A,T,E]),K=t(null),pe=e(()=>{H===null||K.current===H||(K.current=H,P(),d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}))},[H,P,d]),me=e(e=>{ee(e),p(new Set),h(new Set),v(new Map),b(null)},[]),q=f.size,he=H!==null&&q===0&&!V.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:[T&&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:E,onChange:e=>D(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(ae,{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:[(R??B??z)&&re.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(C,{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:R??B??z})]})]})}),k.length>1&&c(Be,{filters:k,activeFilter:A,onSelect:me}),c(`div`,{className:`flex-1 min-h-0`,children:c(S,{mode:`generic`,items:re,pageSize:$,getKey:e=>e.childNativeId,getSearchText:Ie,getFilterType:e=>e.type,filterOptions:_(),filterLabel:u(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:N.isLoading||L&&re.length===0,searchPlaceholder:u(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(R??B??z)&&re.length===0?``:u(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:F,disabled:L,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(te,{className:`h-3.5 w-3.5 ${L?`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:!j,expanded:m.has(e.childNativeId),onToggleExpand:()=>ce(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=fe(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:()=>oe(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(G,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!j&&m.has(e.childNativeId),renderExpanded:j?void 0:e=>c(He,{candidate:e,hiddenChildIds:g.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>le(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:f.has(e.childNativeId)?`bg-primary/5`:``})})]}),y&&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(C,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:y})]})}),H!==null&&c(Z,{addonId:n,integrationId:i,jobId:H,onFinished:pe}),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:he?a:de,disabled:!he&&(q===0||V.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:[V.isPending&&c(J,{className:`h-3.5 w-3.5 animate-spin`}),he?u(`integrations.close`,{defaultValue:`Close`}):u(`integrations.addSelected`,{defaultValue:`Add selected`}),!he&&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?d: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:ee,{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}=be(),m=o(),{data:h,isLoading:g}=N({id:e},{enabled:s===`account`||s===`broker`}),_=i(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:v,isLoading:y}=j({addonId:t,nodeId:`hub`},{enabled:s===`account`}),x=i(()=>v?Ge(v):null,[v]),S=b(),C=t=>{S.mutate({id:e,settings:t},{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(ae,{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(J,{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||y?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(J,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):c(Te,{addonId:t,configSchema:x,canTest:u,initialName:n,initialConfig:We(x,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e})=>C(e),onBack:f}):c(U,{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}=be(),{integrationId:n}=Se(),d=o(),p=ye(),[m,g]=xe(),_=f(),[y,b]=s(!1),[x,A]=s(!1),[ee,N]=s(!1),[te,B]=s(!1),[V,ie]=s(!1),{data:U,isLoading:oe}=E({id:n??``},{enabled:!!n}),{data:se}=j({addonId:U?.addonId??``,nodeId:`hub`},{enabled:!!U?.addonId}),{data:W,isSuccess:G}=w(),K=i(()=>{let e=U?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[W,U?.addonId,G]),{data:fe}=D({}),q=i(()=>(fe?.providers??[]).some(e=>e.addonId===U?.addonId),[fe,U?.addonId]),ge=K!==null,_e=U?.info?.fixed===!0,ve=ge?K===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),Ce=i(()=>{let e=U?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.brokerKind??null},[W,U?.addonId,G]),Te=i(()=>{let e=U?.addonId;return!e||!G?!1:(W??[]).find(t=>t.addonId===e)?.canTest===!0},[W,U?.addonId,G]),Y=i(()=>{let e=U?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.mode??null},[W,U?.addonId,G]);l(()=>{m.get(`add`)===`1`&&ge&&(b(!0),g(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[m,ge,g]);let ke=se!=null&&Array.isArray(se.sections)&&se.sections.some(e=>e.fields.length>0),{data:Ae}=me({addonId:U?.addonId??``,nodeId:`hub`},{enabled:!!U?.addonId&&Y!==`account`}),je=Y!==null&&Y!==`account`&&qe(Ae),Me=i(()=>U?.addonId?[U.addonId]:[],[U?.addonId]),{data:Ne}=k({projection:`slim`},{refetchInterval:3e4}),X=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Fe=M({onMutate:async e=>{await d.cancelQueries({queryKey:X});let t=d.getQueryData(X);return t!=null&&d.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&d.setQueryData(X,r.previous)},onSettled:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Z=I({onSuccess:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}),B(!1),p(`/integrations`)}}),Ie=de({onSuccess:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=z({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=F({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Re=T({onSuccess:()=>{d.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}=le(void 0),Ue=i(()=>R(He),[He]),We=e(e=>p(`/devices/${String(e)}`),[p]),Ge=i(()=>{let e=U?.id;return e?$.filter(t=>{let n=Ue(t);return n.kind===`resolved`&&n.integration.id===e}):[]},[$,U?.id,Ue]),Je=i(()=>He===void 0?null:L(Ge).length,[He,Ge])??`…`;return oe?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`})]}):U?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[c(ue,{items:[{label:`Integrations`,onClick:()=>p(`/integrations`)},{label:U.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/${U.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:U.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[U.addonId,` · `,Je,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[q&&r(`button`,{onClick:()=>A(!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(he,{className:`h-3.5 w-3.5`}),`Scan network`]}),!_e&&r(`button`,{onClick:()=>b(!0),disabled:!ge,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(H,{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`:``} ${U.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[c(P,{checked:U.enabled,onCheckedChange:e=>Fe.mutate({id:n,enabled:e}),disabled:Fe.isPending,"aria-label":U.enabled?`Disable integration`:`Enable integration`}),c(`span`,{className:`text-[11px] font-medium ${U.enabled?`text-success`:`text-foreground-subtle`}`,children:U.enabled?`Enabled`:`Disabled`}),Fe.isPending&&c(J,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Y!==`standalone`&&(ke||K===`device-adoption`)&&r(`button`,{onClick:()=>N(!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(re,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>ie(!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(pe,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),c(O,{label:`Restart`,icon:v,title:`Restart "${U.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:U.addonId})}),!_e&&r(`button`,{onClick:()=>B(!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(De,{nodeId:null,addonIds:Me,level:`global`,surface:`integration`,title:t(`integrations.settings`,{defaultValue:`Settings`})}),c(S,{context:`integration-detail`,devices:$,trpc:_.trpcClient,integrationOf:Ue,forceIntegrationId:U.id,urlScope:`root`,lsKey:`integration-detail:${U.addonId}`,resolveIntegrationIcon:we,resolveParent:Ve,onNavigate:We,batchActions:{remove:Q.mutate,disable:Le.mutate,enable:Re.mutate},..._e?{}:{onDeleteDevice:e=>Q.mutate({deviceId:e.id})}}),y&&n&&K===`device-adoption`&&c(ze,{addonId:U.addonId,integrationId:n,onClose:()=>b(!1)}),y&&n&&K===`device-provider`&&c(Pe,{open:y,integrationId:n,addonId:U.addonId,onClose:()=>b(!1)}),x&&U&&c(Ee,{open:x,scope:{addonId:U.addonId,label:U.name},onClose:()=>A(!1)}),ee&&n&&K!==null&&Y!==null&&c(Ke,{integrationId:n,addonId:U.addonId,name:U.name,kind:K,mode:Y,brokerKind:Ce,canTest:Te,trpc:_.trpcClient,onClose:()=>N(!1)}),V&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>ie(!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(pe,{className:`h-4 w-4 text-primary shrink-0`}),c(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:U.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[U.addonId,n?` · ${n}`:``]})]}),c(`button`,{onClick:()=>ie(!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(ae,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:c(ce,{addonId:U.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),te&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Z.isPending&&B(!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(C,{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:U.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:()=>B(!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(J,{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(ne,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{Je as IntegrationDetailPage};
@@ -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,vt as f}from"./player-overlays-cfiayLzw.js";import{$l as p,B as m,Da as h,Fi as g,Kn as ee,U as _,Un as v,V as te,Wl as y,au as ne,cl as b,id as x,iu as S,ka as C,pi as re,r as w,tu as T,wa as E,wi as ie,yu as D}from"./src-FuqzctFV.js";import{t as O}from"./ProviderIcon-fddHc0k4.js";import{f as k,l as A,m as ae}from"./index-Bleh56hg.js";import{t as j}from"./AdminPage-CiKtOLQm.js";import"./useEventInvalidation-CWtuhmnD.js";import{t as M}from"./StatusBadge-CeptlsPG.js";import{t as oe}from"./device-integration-icon-DhrVTlMx.js";import{n as N,r as P,t as F}from"./ScanNetworkModal-BNgDBkJM.js";import{t as I}from"./useBodyScrollLock-BDocajQE.js";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}=A(),[a,l]=o(new Set),u=ie(),d=u.data,p=u.isPending||!u.data&&!u.isError;c(()=>{e&&(u.isPending||u.data||u.mutate({addonId:e}))},[e,u]);function m(e){l(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=d??[];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(f,{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}=A(),a=k(),{data:o,isLoading:c}=h();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,f=l;return n(`button`,{disabled:f,onClick:()=>{if(!f)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(D,{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(y,{className:`h-3 w-3`}),i(`integrations.manage`)]}):s(d,{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}=A(),u=k(),d=a(),[f,p]=o(`picker`),[m,h]=o(null),[g,_]=o(null),[v,te]=o(`manual`),[y,ne]=o(null),[x,S]=o(``),[C,w]=o(null),[T,O]=o(null),[ae,j]=o(!1),{data:M}=ee({addonId:m??``,nodeId:`hub`},{enabled:m!=null}),oe=r(()=>M?se(M):null,[M]),F=E({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),V=ie(),H=V.data;c(()=>{f!==`discovery`||!g||!m||V.isPending||V.data||V.mutate({addonId:m})},[f,g,m,V]);let ce=re({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function le(e,t,n,r,i,a,o,s){if(!F.isPending){if(h(e),j(s),te(n),S(r),O(null),o===`broker`){if(!a){O(`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(m)try{let t=await F.mutateAsync({addonId:m,name:e.name,settings:e.config});_(t.id),v===`auto`||v===`both`?p(`discovery`):q(t.id)}catch{}}async function G(e){if(m)try{let t=await F.mutateAsync({addonId:m,name:x,settings:{brokerId:e}});w(t.id),_(t.id),q(t.id)}catch{}}async function K(e){if(m){for(let t of e){let e=H?.find(e=>e.stableId===t);e&&await ce.mutateAsync({addonId:m,candidate:e,...C===null?{}:{integrationId:C}})}q()}}function q(e){let n=e??g??m;t(),J(),n&&u(`/integrations/${n}`)}function J(){p(`picker`),h(null),_(null),te(`manual`),ne(null),S(``),w(null),O(null),j(!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?m: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(b,{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:[T&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:T}),s(z,{onSelect:le,onClose:Y,pendingAddonId:Q})]}),f===`config`&&m&&s(N,{addonId:m,configSchema:oe??null,canTest:ae,onSave:W,onBack:()=>p(`picker`)}),f===`broker`&&y&&s(P,{kind:y,onResolved:e=>{G(e)},onBack:()=>p(`picker`)}),f===`discovery`&&g&&s(R,{providerId:g,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(D,{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?l:d,{className:`h-3.5 w-3.5`})}),s(O,{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}=A(),a=k(),c=u(),[l]=ae(),[d,f]=o(!1),h=e(()=>f(!0),[]),ee=e(()=>f(!1),[]),[y,b]=o(!1),x=e(()=>b(!0),[]),re=e(()=>b(!1),[]);w([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),w([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:E,isLoading:ie,refetch:D}=C(void 0),{data:O,isLoading:M,refetch:N}=g({projection:`slim`}),P=r(()=>O??[],[O]),I=r(()=>E??[],[E]),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(()=>te(E),[E]),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(m,{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(j,{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(p,{className:v(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),n(`button`,{onClick:x,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(T,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick:h,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(ne,{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(m,{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:ee}),s(F,{open:y,onClose:re})]})}export{W as IntegrationsPage};
@@ -1 +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}from"./player-overlays-BPnLENh-.js";import{Br as c,Gr as l,Hr as u,Lr as d,Mn as f,R as p,Rr as m,Ur as h,Vr as g,Wr as _,Xl as v,eu as y,fu as b,hu as x,ii as S,il as C,rr as w,ru as T,sl as E,tu as D,zl as O}from"./src-Ch2D4L9J.js";import{Rn as ee,bn as k,mt as A}from"./src-DXUFbK1_.js";import{f as j}from"./index-BKfjeM9L.js";import{t as M}from"./AdminPage-CiKtOLQm.js";import{t as N}from"./AdminTabs-jHFlbFwy.js";import{t as P}from"./BrokerForm-DgGM0_0c.js";import{t as F}from"./useBodyScrollLock-BDocajQE.js";import{t as I}from"./AddonCollectionPage-pS-uTKIv.js";e();var L={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function R(e){return L[e]??e}function z(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var B={connected:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,connecting:`bg-amber-500/15 text-amber-700 dark:text-amber-300`,disconnected:`bg-foreground-subtle/15 text-foreground-subtle`,"auth-failed":`bg-danger/15 text-danger`,unreachable:`bg-danger/15 text-danger`,error:`bg-danger/15 text-danger`};function V({status:e}){return o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${B[e]}`,children:e})}function H(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function U({title:e,subtitle:n,onClose:r,children:i}){return F(),o(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,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:[t(`div`,{className:`space-y-0.5`,children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&o(`p`,{className:`text-xs text-foreground-subtle`,children:n})]}),o(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,children:o(C,{className:`h-4 w-4`})})]}),o(`div`,{className:`p-4 max-h-[70vh] overflow-y-auto overscroll-contain`,children:i})]})})}function W({kinds:e,onClose:n,onDone:s}){let c=i(),l=e=>`${e.addonId??``}::${e.kind}`,[u,f]=a(e[0]?l(e[0]):``),[p,m]=a(``),[h,g]=a(!1),[_,v]=a(``),y=e.find(e=>l(e)===u)??e[0],b=y?.kind??``,x=y?.addonId,S=d({onSuccess:()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]}),s()}}),C=e=>{if(!b||p.trim().length===0)return;let t=h?_.trim():``;h&&t===``||S.mutate({kind:b,name:p.trim(),settings:e,...t===``?{}:{id:t},...x===void 0?{}:{addonId:x}})};return o(U,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:S.isPending?()=>{}:n,children:t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Kind`}),o(`select`,{value:u,onChange:e=>f(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>o(`option`,{value:l(e),children:e.label},l(e)))})]}),t(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),o(`input`,{type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:`My Home Assistant`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1 rounded border border-border px-3 py-2`,children:[t(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground`,children:[o(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked)}),`Restore a broker that was removed, under its original id`]}),h&&t(r,{children:[o(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),placeholder:`ha_004`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`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.`})]})]}),S.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:S.error instanceof Error?S.error.message:String(S.error)}),b&&o(P,{kind:b,...x===void 0?{}:{addonId:x},onSubmit:C,onCancel:n,submitLabel:S.isPending?`Adding…`:`Add broker`,disabled:S.isPending}),p.trim().length===0&&o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before saving.`}),h&&_.trim().length===0&&o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter the original id, or clear the checkbox to create a new broker.`})]})})}function G({broker:e,onClose:r,onDone:a}){let s=i(),c=m({id:e.id,addonId:e.addonId}),l=_({onSuccess:()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]}),s.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),a()}}),u=n(()=>{let e=c.data;return e&&typeof e==`object`?{...e}:{}},[c.data]);return o(U,{title:`Edit ${e.name}`,subtitle:`${R(e.kind)} · ${e.id}`,onClose:l.isPending?()=>{}:r,children:c.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(x,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):c.isError?t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load settings:`,` `,c.error instanceof Error?c.error.message:`Unknown error`]}),o(`div`,{className:`flex justify-end`,children:o(`button`,{type:`button`,onClick:r,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Close`})})]}):t(`div`,{className:`space-y-3`,children:[l.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:l.error instanceof Error?l.error.message:String(l.error)}),o(P,{kind:e.kind,addonId:e.addonId,initialValues:u,onSubmit:t=>{l.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:r,submitLabel:l.isPending?`Saving…`:`Save`,disabled:l.isPending})]})})}function K({broker:e,onEdit:n}){let r=i(),c=f(),[u,d]=a(null),p=l({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)})}),m=h({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),g=async()=>{await c({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&m.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:R(e.kind)}),t(`td`,{className:`px-3 py-2`,children:[o(V,{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(`button`,{type:`button`,onClick:()=>p.mutate({id:e.id,addonId:e.addonId}),disabled:p.isPending,title:`Test connection`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10 disabled:opacity-50`,children:[p.isPending?o(x,{className:`h-3 w-3 animate-spin`}):o(E,{className:`h-3 w-3`}),`Test`]}),t(`button`,{type:`button`,onClick:()=>n(e),title:`Edit`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10`,children:[o(T,{className:`h-3 w-3`}),` Edit`]}),t(`button`,{type:`button`,onClick:()=>{g()},disabled:m.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded border border-danger/40 px-2 py-1 text-[11px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[m.isPending?o(x,{className:`h-3 w-3 animate-spin`}):o(s,{className:`h-3 w-3`}),`Delete`]})]})})]})}function q(){let e=g({}),r=u(),i=n(()=>H(e.data),[e.data]),[s,c]=a(!1),[l,d]=a(null),f=n(()=>{let e=new Map;for(let t of z(r.data))for(let n of t.kinds)e.set(`${t.addonId}::${n.kind}`,{addonId:t.addonId,kind:n.kind,label:n.label});for(let t of i)[...e.values()].some(e=>e.kind===t.kind)||e.set(`::${t.kind}`,{kind:t.kind,label:R(t.kind)});return[...e.values()]},[i,r.data]);return t(`div`,{className:`space-y-3`,children:[o(`div`,{className:`flex items-center justify-end`,children:t(`button`,{type:`button`,onClick:()=>c(!0),disabled:f.length===0,title:f.length===0?`No broker providers available`:void 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:cursor-not-allowed`,children:[o(D,{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:[e.isLoading&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[o(x,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),e.isError&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,e.error instanceof Error?e.error.message:`Unknown error`]})}),!e.isLoading&&!e.isError&&i.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.`})}),i.map(e=>o(K,{broker:e,onEdit:d},e.id))]})]})}),s&&o(W,{kinds:f,onClose:()=>c(!1),onDone:()=>c(!1)}),l&&o(G,{broker:l,onClose:()=>d(null),onDone:()=>d(null)})]})}var J=[{kind:`device-export`,tabId:`device-export`,title:`Device export`,subtitle:`Outbound exporters that publish CamStack devices to other ecosystems (HomeAssistant, HomeKit, Alexa, …).`,icon:O,emptyTitle:`No device-export providers installed`,emptyDescription:`Install an export addon (e.g. @camstack/addon-export-ha-mqtt) to surface your CamStack devices in HomeAssistant, HomeKit, …`,addLabel:`Add export`},{kind:`email`,tabId:`email`,title:`Email providers`,subtitle:`Outbound email relays used for magic-link login, notifications, and alerts (SMTP today, future SendGrid, …).`,icon:b,emptyTitle:`No email providers installed`,emptyDescription:`Install an email-provider addon (e.g. @camstack/addon-smtp) so the hub can deliver magic-link logins and notifications.`,addLabel:`Add email provider`},{kind:`broker`,tabId:`broker`,title:`Brokers`,subtitle:`Message brokers consumed by exporters and downstream automations (MQTT today, future Kafka, …).`,icon:v,emptyTitle:`No brokers installed`,emptyDescription:`Install a broker addon (e.g. @camstack/addon-mqtt-broker) to publish device events for downstream automations.`,addLabel:`Add broker`}];function Y(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e.name;if(typeof t==`string`)return t}return null}function X(e){let t=e,n=t?.manifest;if(!n?.id)return null;let r=[];for(let e of n.capabilities??[]){let t=Y(e);t!==null&&r.push(t)}let i=n.packageDisplayName??n.name??n.id,a=t?.process?.state??null;return{addonId:n.id,displayName:i,isActive:a===`running`,packageName:n.packageName??`@camstack/addon-${n.id}`,capNames:r,processState:a}}function Z(e,t){let n=new Set(t);return e.filter(e=>e.capNames.some(e=>n.has(e)))}function Q(e){for(let[t,n]of Object.entries(A))if(n===e)return t;return null}function te(e){return e===`running`?{label:`Running`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`}:e===`crashed`||e===`failed`?{label:e===`failed`?`Failed`:`Crashed`,className:`bg-danger/15 text-danger`}:e===`stopped`||e===`disabled`?{label:`Stopped`,className:`bg-foreground-subtle/15 text-foreground-subtle`}:{label:e??`Unknown`,className:`bg-foreground-subtle/15 text-foreground-subtle`}}function $({label:e,className:t}){return o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t}`,children:e})}function ne({addonId:e}){let{data:t,isLoading:n}=c({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=ee.safeParse(t);if(!r.success)return null;let i=r.data;return o($,{label:`${i.brokerCount} broker${i.brokerCount===1?``:`s`}${i.connectedCount>0?` • ${i.connectedCount} connected`:``}`,className:`bg-primary/10 text-primary`})}function re({addonId:e}){let{data:t,isLoading:n}=S({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=k.safeParse(t);if(!r.success)return null;let i=r.data,a=i.linkState===`linked`?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:i.linkState===`error`?`bg-danger/15 text-danger`:`bg-foreground-subtle/15 text-foreground-subtle`;return o($,{label:`${i.linkState} • ${i.exposedDeviceCount} exposed`,className:a})}function ie({kind:e,addonId:t}){return e===`broker`?o(ne,{addonId:t}):e===`device-export`?o(re,{addonId:t}):null}function ae({descriptor:e,rows:n,isLoading:i}){let a=Q(e.kind),s=e.kind===`device-export`,c=j();return o(I,{title:e.title,subtitle:e.subtitle,pageIcon:e.icon,itemIcon:e.icon,capability:a??e.kind,installButtonLabel:e.addLabel,items:n,isLoading:i,emptyTitle:e.emptyTitle,emptyDescription:e.emptyDescription,renderStatusBadges:n=>{let i=te(n.processState);return t(r,{children:[o($,{label:i.label,className:i.className}),o(ie,{kind:e.kind,addonId:n.addonId})]})},renderExpandedPanel:s?e=>o(p,{addonId:e.addonId,onOpenDevice:e=>c(`/devices/${e}`)}):void 0,showChrome:!0})}function oe(){let e=w(void 0,{refetchInterval:1e4}),t=(e.data??[]).map(X).filter(e=>e!==null);return o(M,{icon:y,title:`External systems`,subtitle:`External systems this hub talks to — device exporters, email relays, and message brokers. Settings, Logs and Events are docked under every provider.`,children:o(N,{tabs:J.map(n=>{let r=Object.entries(A).filter(([,e])=>e===n.kind).map(([e])=>e),i=n.kind===`broker`?o(q,{}):o(ae,{descriptor:n,rows:Z(t,r),isLoading:e.isLoading});return{id:n.tabId,label:n.title,icon:n.icon,content:i}})})})}export{oe as IntegrationsPage};
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}from"./player-overlays-cfiayLzw.js";import{Gr as c,Hr as l,Kr as u,Nn as d,Rr as f,Ul as p,Ur as m,Vr as h,Wr as g,au as _,ci as v,cl as y,dl as b,eu as x,gu as S,ir as C,iu as w,su as T,yu as E,z as D,zr as O}from"./src-FuqzctFV.js";import{Rn as k,bn as ee,mt as A}from"./src-CYSHGOVz.js";import{f as j}from"./index-Bleh56hg.js";import{t as M}from"./AdminPage-CiKtOLQm.js";import{t as N}from"./AdminTabs-BE0YQcz6.js";import{t as P}from"./BrokerForm-bxpKmM7o.js";import{t as F}from"./useBodyScrollLock-BDocajQE.js";import{t as I}from"./AddonCollectionPage-Bz3KyJNf.js";e();var L={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function R(e){return L[e]??e}function z(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var B={connected:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,connecting:`bg-amber-500/15 text-amber-700 dark:text-amber-300`,disconnected:`bg-foreground-subtle/15 text-foreground-subtle`,"auth-failed":`bg-danger/15 text-danger`,unreachable:`bg-danger/15 text-danger`,error:`bg-danger/15 text-danger`};function V({status:e}){return o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${B[e]}`,children:e})}function H(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function U({title:e,subtitle:n,onClose:r,children:i}){return F(),o(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,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:[t(`div`,{className:`space-y-0.5`,children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&o(`p`,{className:`text-xs text-foreground-subtle`,children:n})]}),o(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,children:o(y,{className:`h-4 w-4`})})]}),o(`div`,{className:`p-4 max-h-[70vh] overflow-y-auto overscroll-contain`,children:i})]})})}function W({kinds:e,onClose:n,onDone:s}){let c=i(),l=e=>`${e.addonId??``}::${e.kind}`,[u,d]=a(e[0]?l(e[0]):``),[p,m]=a(``),[h,g]=a(!1),[_,v]=a(``),y=e.find(e=>l(e)===u)??e[0],b=y?.kind??``,x=y?.addonId,S=f({onSuccess:()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]}),s()}}),C=e=>{if(!b||p.trim().length===0)return;let t=h?_.trim():``;h&&t===``||S.mutate({kind:b,name:p.trim(),settings:e,...t===``?{}:{id:t},...x===void 0?{}:{addonId:x}})};return o(U,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:S.isPending?()=>{}:n,children:t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Kind`}),o(`select`,{value:u,onChange:e=>d(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>o(`option`,{value:l(e),children:e.label},l(e)))})]}),t(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),o(`input`,{type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:`My Home Assistant`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1 rounded border border-border px-3 py-2`,children:[t(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground`,children:[o(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked)}),`Restore a broker that was removed, under its original id`]}),h&&t(r,{children:[o(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),placeholder:`ha_004`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`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.`})]})]}),S.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:S.error instanceof Error?S.error.message:String(S.error)}),b&&o(P,{kind:b,...x===void 0?{}:{addonId:x},onSubmit:C,onCancel:n,submitLabel:S.isPending?`Adding…`:`Add broker`,disabled:S.isPending}),p.trim().length===0&&o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before saving.`}),h&&_.trim().length===0&&o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter the original id, or clear the checkbox to create a new broker.`})]})})}function G({broker:e,onClose:r,onDone:a}){let s=i(),l=O({id:e.id,addonId:e.addonId}),u=c({onSuccess:()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]}),s.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),a()}}),d=n(()=>{let e=l.data;return e&&typeof e==`object`?{...e}:{}},[l.data]);return o(U,{title:`Edit ${e.name}`,subtitle:`${R(e.kind)} · ${e.id}`,onClose:u.isPending?()=>{}:r,children:l.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(E,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):l.isError?t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load settings:`,` `,l.error instanceof Error?l.error.message:`Unknown error`]}),o(`div`,{className:`flex justify-end`,children:o(`button`,{type:`button`,onClick:r,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Close`})})]}):t(`div`,{className:`space-y-3`,children:[u.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:u.error instanceof Error?u.error.message:String(u.error)}),o(P,{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 K({broker:e,onEdit:n}){let r=i(),c=d(),[l,f]=a(null),p=u({onSuccess:e=>f(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>f({ok:!1,error:e instanceof Error?e.message:String(e)})}),m=g({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),h=async()=>{await c({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&m.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:R(e.kind)}),t(`td`,{className:`px-3 py-2`,children:[o(V,{status:e.status}),l&&o(`span`,{className:`ml-2 text-[10px] ${l.ok?`text-success`:`text-danger`}`,children:l.ok?`OK`:l.error??`failed`})]}),o(`td`,{className:`px-3 py-2`,children:t(`div`,{className:`flex items-center justify-end gap-1.5`,children:[t(`button`,{type:`button`,onClick:()=>p.mutate({id:e.id,addonId:e.addonId}),disabled:p.isPending,title:`Test connection`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10 disabled:opacity-50`,children:[p.isPending?o(E,{className:`h-3 w-3 animate-spin`}):o(b,{className:`h-3 w-3`}),`Test`]}),t(`button`,{type:`button`,onClick:()=>n(e),title:`Edit`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10`,children:[o(T,{className:`h-3 w-3`}),` Edit`]}),t(`button`,{type:`button`,onClick:()=>{h()},disabled:m.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded border border-danger/40 px-2 py-1 text-[11px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[m.isPending?o(E,{className:`h-3 w-3 animate-spin`}):o(s,{className:`h-3 w-3`}),`Delete`]})]})})]})}function q(){let e=l({}),r=m(),i=n(()=>H(e.data),[e.data]),[s,c]=a(!1),[u,d]=a(null),f=n(()=>{let e=new Map;for(let t of z(r.data))for(let n of t.kinds)e.set(`${t.addonId}::${n.kind}`,{addonId:t.addonId,kind:n.kind,label:n.label});for(let t of i)[...e.values()].some(e=>e.kind===t.kind)||e.set(`::${t.kind}`,{kind:t.kind,label:R(t.kind)});return[...e.values()]},[i,r.data]);return t(`div`,{className:`space-y-3`,children:[o(`div`,{className:`flex items-center justify-end`,children:t(`button`,{type:`button`,onClick:()=>c(!0),disabled:f.length===0,title:f.length===0?`No broker providers available`:void 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:cursor-not-allowed`,children:[o(_,{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:[e.isLoading&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[o(E,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),e.isError&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,e.error instanceof Error?e.error.message:`Unknown error`]})}),!e.isLoading&&!e.isError&&i.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.`})}),i.map(e=>o(K,{broker:e,onEdit:d},e.id))]})]})}),s&&o(W,{kinds:f,onClose:()=>c(!1),onDone:()=>c(!1)}),u&&o(G,{broker:u,onClose:()=>d(null),onDone:()=>d(null)})]})}var J=[{kind:`device-export`,tabId:`device-export`,title:`Device export`,subtitle:`Outbound exporters that publish CamStack devices to other ecosystems (HomeAssistant, HomeKit, Alexa, …).`,icon:p,emptyTitle:`No device-export providers installed`,emptyDescription:`Install an export addon (e.g. @camstack/addon-export-ha-mqtt) to surface your CamStack devices in HomeAssistant, HomeKit, …`,addLabel:`Add export`},{kind:`email`,tabId:`email`,title:`Email providers`,subtitle:`Outbound email relays used for magic-link login, notifications, and alerts (SMTP today, future SendGrid, …).`,icon:S,emptyTitle:`No email providers installed`,emptyDescription:`Install an email-provider addon (e.g. @camstack/addon-smtp) so the hub can deliver magic-link logins and notifications.`,addLabel:`Add email provider`},{kind:`broker`,tabId:`broker`,title:`Brokers`,subtitle:`Message brokers consumed by exporters and downstream automations (MQTT today, future Kafka, …).`,icon:x,emptyTitle:`No brokers installed`,emptyDescription:`Install a broker addon (e.g. @camstack/addon-mqtt-broker) to publish device events for downstream automations.`,addLabel:`Add broker`}];function Y(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e.name;if(typeof t==`string`)return t}return null}function X(e){let t=e,n=t?.manifest;if(!n?.id)return null;let r=[];for(let e of n.capabilities??[]){let t=Y(e);t!==null&&r.push(t)}let i=n.packageDisplayName??n.name??n.id,a=t?.process?.state??null;return{addonId:n.id,displayName:i,isActive:a===`running`,packageName:n.packageName??`@camstack/addon-${n.id}`,capNames:r,processState:a}}function Z(e,t){let n=new Set(t);return e.filter(e=>e.capNames.some(e=>n.has(e)))}function Q(e){for(let[t,n]of Object.entries(A))if(n===e)return t;return null}function te(e){return e===`running`?{label:`Running`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`}:e===`crashed`||e===`failed`?{label:e===`failed`?`Failed`:`Crashed`,className:`bg-danger/15 text-danger`}:e===`stopped`||e===`disabled`?{label:`Stopped`,className:`bg-foreground-subtle/15 text-foreground-subtle`}:{label:e??`Unknown`,className:`bg-foreground-subtle/15 text-foreground-subtle`}}function $({label:e,className:t}){return o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t}`,children:e})}function ne({addonId:e}){let{data:t,isLoading:n}=h({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=k.safeParse(t);if(!r.success)return null;let i=r.data;return o($,{label:`${i.brokerCount} broker${i.brokerCount===1?``:`s`}${i.connectedCount>0?` • ${i.connectedCount} connected`:``}`,className:`bg-primary/10 text-primary`})}function re({addonId:e}){let{data:t,isLoading:n}=v({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=ee.safeParse(t);if(!r.success)return null;let i=r.data,a=i.linkState===`linked`?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:i.linkState===`error`?`bg-danger/15 text-danger`:`bg-foreground-subtle/15 text-foreground-subtle`;return o($,{label:`${i.linkState} • ${i.exposedDeviceCount} exposed`,className:a})}function ie({kind:e,addonId:t}){return e===`broker`?o(ne,{addonId:t}):e===`device-export`?o(re,{addonId:t}):null}function ae({descriptor:e,rows:n,isLoading:i}){let a=Q(e.kind),s=e.kind===`device-export`,c=j();return o(I,{title:e.title,subtitle:e.subtitle,pageIcon:e.icon,itemIcon:e.icon,capability:a??e.kind,installButtonLabel:e.addLabel,items:n,isLoading:i,emptyTitle:e.emptyTitle,emptyDescription:e.emptyDescription,renderStatusBadges:n=>{let i=te(n.processState);return t(r,{children:[o($,{label:i.label,className:i.className}),o(ie,{kind:e.kind,addonId:n.addonId})]})},renderExpandedPanel:s?e=>o(D,{addonId:e.addonId,onOpenDevice:e=>c(`/devices/${e}`)}):void 0,showChrome:!0})}function oe(){let e=C(void 0,{refetchInterval:1e4}),t=(e.data??[]).map(X).filter(e=>e!==null);return o(M,{icon:w,title:`External systems`,subtitle:`External systems this hub talks to — device exporters, email relays, and message brokers. Settings, Logs and Events are docked under every provider.`,children:o(N,{tabs:J.map(n=>{let r=Object.entries(A).filter(([,e])=>e===n.kind).map(([e])=>e),i=n.kind===`broker`?o(q,{}):o(ae,{descriptor:n,rows:Z(t,r),isLoading:e.isLoading});return{id:n.tabId,label:n.title,icon:n.icon,content:i}})})})}export{oe as IntegrationsPage};