@camstack/addon-admin-ui 1.2.181 → 1.2.183
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddonCollectionPage-DJd0G561.js → AddonCollectionPage-DwDJOFcL.js} +1 -1
- package/dist/assets/{Addons-B9oEehiz.js → Addons-DDgC9FD-.js} +1 -1
- package/dist/assets/{AdminTabs-DUSbhirs.js → AdminTabs-B4GGMxRz.js} +1 -1
- package/dist/assets/{AiProfiles-DS_qCfyh.js → AiProfiles-CR9oxC8h.js} +1 -1
- package/dist/assets/{BrokerForm-B_J_UL0W.js → BrokerForm-BHUwTLLB.js} +1 -1
- package/dist/assets/{Build-Co3eNCT4.js → Build-f_1u4WFv.js} +4 -4
- package/dist/assets/{Capabilities-C48-krU8.js → Capabilities-RvtHAT_T.js} +1 -1
- package/dist/assets/{CapabilityBadges-Bl8JQUQr.js → CapabilityBadges-IB_h9qda.js} +1 -1
- package/dist/assets/{Cluster-BJ8jpAsh.js → Cluster-C9BEXmwP.js} +1 -1
- package/dist/assets/{Data-CTgs0K6f.js → Data-BpDCDX6A.js} +1 -1
- package/dist/assets/{DetectionIntelligence-4UTyckKL.js → DetectionIntelligence-zPhopJKC.js} +1 -1
- package/dist/assets/{DeviceAggregateSection-DXU4IgUx.js → DeviceAggregateSection-BRusipZp.js} +1 -1
- package/dist/assets/{DeviceDetail-jV91edQI.js → DeviceDetail-DHUjDgDI.js} +2 -2
- package/dist/assets/{Devices-TuM5Y4CA.js → Devices-Kt8t-U1T.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-CacpkWdR.js → EmbedPlayerPage-yMkiMevj.js} +1 -1
- package/dist/assets/Events-BWJj26yH.js +1 -0
- package/dist/assets/{FormBuilder-CpdMn4hO.js → FormBuilder-j23rGTmj.js} +1 -1
- package/dist/assets/{Identity-DccPstNt.js → Identity-BbH4N3ls.js} +1 -1
- package/dist/assets/{IntegrationDetail-DqQ46kTk.js → IntegrationDetail-C-2iPJLh.js} +1 -1
- package/dist/assets/{Integrations-BpC_0Ori.js → Integrations-36RwnM2W.js} +1 -1
- package/dist/assets/{Integrations-bqPp2Asv.js → Integrations-B2ODlpqX.js} +1 -1
- package/dist/assets/{Locations-_V2xUV_m.js → Locations-D4Xsj5LF.js} +1 -1
- package/dist/assets/{Logs-qRgWArT0.js → Logs-D2WiTgJp.js} +1 -1
- package/dist/assets/{MotionZonesSettings-D8VKOXWT.js → MotionZonesSettings-MuTTyBWY.js} +1 -1
- package/dist/assets/{MyAccess-C_Lqhtp6.js → MyAccess-Cnee6p_G.js} +1 -1
- package/dist/assets/{Network-CLU9pz2F.js → Network-Cd2ZePrQ.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-BGnTKNTC.js → NodeAddonsSettingsPanel-BlZbeN2Z.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-COEEBYQZ.js → NodeInferenceDevices-I1_uPt2b.js} +1 -1
- package/dist/assets/Notifications-DwEtDT_l.js +1 -0
- package/dist/assets/{Pipeline-VwlltOl_.js → Pipeline-WWlQuB3Q.js} +1 -1
- package/dist/assets/{Plates-DqQqsqek.js → Plates-BS6TmAmt.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-DJOVa6ie.js → PrivacyMaskSettings-BpCcBGIH.js} +1 -1
- package/dist/assets/{ProviderIcon-C8_JXI4r.js → ProviderIcon-CNufGvWr.js} +1 -1
- package/dist/assets/{Recordings-ChT5HLhb.js → Recordings-CBqVhZii.js} +1 -1
- package/dist/assets/{ScanNetworkModal-Ds9Ujyss.js → ScanNetworkModal-DRcWDlfZ.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-Nj4V9mEW.js → SceneMonitorEditor-B_T951ld.js} +1 -1
- package/dist/assets/{Scenes-Czo8-9HJ.js → Scenes-DMIvg_xr.js} +1 -1
- package/dist/assets/{Settings-Bt8qWgaY.js → Settings-B0G6mumO.js} +1 -1
- package/dist/assets/{Showroom-DbzjAJ5K.js → Showroom-CUnnK9jp.js} +1 -1
- package/dist/assets/{StorageLocationsPanel-Gli46LO3.js → StorageLocationsPanel-gyN2eOAh.js} +1 -1
- package/dist/assets/{Terminal-C2znJyh5.js → Terminal-DL0pk1Yh.js} +1 -1
- package/dist/assets/{Viewer-BTIHvb5g.js → Viewer-p7bHegjM.js} +1 -1
- package/dist/assets/_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CytyhLaf.js +1 -0
- package/dist/assets/{authed-media-JFPl7HRk.js → authed-media-DK9gXwSO.js} +1 -1
- package/dist/assets/{bell-off-BzqSLdYZ.js → bell-off-DvjhA5yz.js} +1 -1
- package/dist/assets/{bell-ring-D6RgrV33.js → bell-ring-C7bMrYRU.js} +1 -1
- package/dist/assets/{boxes-Di4H7szx.js → boxes-DUWmFsrP.js} +1 -1
- package/dist/assets/circle-check-big-UUTDxFnK.js +1 -0
- package/dist/assets/circle-dot-CzW0cNTB.js +1 -0
- package/dist/assets/circle-slash-CaR9akZn.js +1 -0
- package/dist/assets/{circle-x-DFeAzRym.js → circle-x-BVeWtyWa.js} +1 -1
- package/dist/assets/clock-BcJxzq7C.js +1 -0
- package/dist/assets/{copy-HKHON4wK.js → copy-Clr1lTje.js} +1 -1
- package/dist/assets/{debounced-invalidate-DEob-KJB.js → debounced-invalidate-BaUUaOIe.js} +1 -1
- package/dist/assets/{dist-Cjqh0Wan.js → dist-B5mS_AVj.js} +1 -1
- package/dist/assets/dist-Cd33cSZb.js +349 -0
- package/dist/assets/{download-BjcTAzIe.js → download-B6F7in4f.js} +1 -1
- package/dist/assets/{face-bbox-GrU8Bm42.js → face-bbox-BHQ2kPlZ.js} +1 -1
- package/dist/assets/{flame-COul3umE.js → flame-WU7l8HOV.js} +1 -1
- package/dist/assets/{format-size-C9Wam9GG.js → format-size-BmviP3wi.js} +1 -1
- package/dist/assets/{hard-drive-DPc0W5g5.js → hard-drive-XE3emw6S.js} +1 -1
- package/dist/assets/hostInit-upQrb-ke.js +1 -0
- package/dist/assets/{index-YqMXmKC_.js → index-DL2yqdrc.js} +3 -3
- package/dist/assets/{key-round-D15z3uvv.js → key-round-DsG9cNQv.js} +1 -1
- package/dist/assets/{layers-DZ5ZWJK2.js → layers-CWHzy2IP.js} +1 -1
- package/dist/assets/{location-owned-usage-Cmw1H2ky.js → location-owned-usage-BdIJhCaK.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-94c8e721.js → mf-entry-bootstrap-0-a8ba3fb3.js} +2 -2
- package/dist/assets/{pencil-DRBv7Lne.js → pencil-DICsE4Gy.js} +1 -1
- package/dist/assets/play-Bc0Mbg1N.js +1 -0
- package/dist/assets/{player-overlays-CoerrptV.js → player-overlays-DVo2KR_t.js} +1 -1
- package/dist/assets/plus-BhEMDQtU.js +1 -0
- package/dist/assets/power-B3EaHOez.js +1 -0
- package/dist/assets/{radio-DRQV-atC.js → radio-Dlzurs1x.js} +1 -1
- package/dist/assets/{refresh-cw-DUVLNAWK.js → refresh-cw-Bk9SNV20.js} +1 -1
- package/dist/assets/remoteEntry-CtfxvtyJ.js +1 -0
- package/dist/assets/rotate-ccw-C4cPfNFW.js +1 -0
- package/dist/assets/rotate-cw-B1uedsyY.js +1 -0
- package/dist/assets/{send-BbpuXZ3P.js → send-CITynaYq.js} +1 -1
- package/dist/assets/{server-K4C9yQfR.js → server-C4WwnByv.js} +1 -1
- package/dist/assets/{shield-Dw3zZIWI.js → shield-BF2zMD3h.js} +1 -1
- package/dist/assets/{shield-alert-4RXP2qu7.js → shield-alert-DvcWv6qf.js} +1 -1
- package/dist/assets/square-C8DJ0ohY.js +1 -0
- package/dist/assets/{square-check-big-Bu8N6Tcy.js → square-check-big-Bm7xPVTE.js} +1 -1
- package/dist/assets/src-CLAf92SY.js +67 -0
- package/dist/assets/src-e8CzBBHU.js +349 -0
- package/dist/assets/{undo-2-VDdKzlFl.js → undo-2-B94PbyBv.js} +1 -1
- package/dist/assets/{use-scenes-feed-GLnt3J9R.js → use-scenes-feed-BaWfN-lO.js} +1 -1
- package/dist/assets/useEventInvalidation-Bqc9UKUF.js +1 -0
- package/dist/assets/{useNodeUrlSelection-Py2d-E1q.js → useNodeUrlSelection-QH8LW_MZ.js} +1 -1
- package/dist/assets/user-round-CssMH_tg.js +1 -0
- package/dist/assets/{video-D8YrEcPQ.js → video-BQp9auCL.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BUYfVBry.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BkrkrKOR.js} +2 -2
- package/dist/assets/{wifi-CEFpiBjp.js → wifi-DKocxMvb.js} +1 -1
- package/dist/assets/{zap-DmoickfW.js → zap-D5PZRv07.js} +1 -1
- package/dist/index.html +5 -5
- package/dist/server/addon.js +248 -6
- package/package.json +1 -1
- package/dist/assets/Events-Vhs6Ka45.js +0 -1
- package/dist/assets/Notifications-CrJJ3noY.js +0 -1
- package/dist/assets/_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Ba6ePIt-.js +0 -1
- package/dist/assets/circle-check-big-Ckfr2nS1.js +0 -1
- package/dist/assets/circle-dot-Bynvvq-p.js +0 -1
- package/dist/assets/circle-slash-Bq9YB7rl.js +0 -1
- package/dist/assets/clock-DOdZD0B9.js +0 -1
- package/dist/assets/dist-BPfNrxiG.js +0 -349
- package/dist/assets/hostInit-1argaRxT.js +0 -1
- package/dist/assets/play-DJ__jbgT.js +0 -1
- package/dist/assets/plus-Bn6mAUY6.js +0 -1
- package/dist/assets/power-ZJUNhMVg.js +0 -1
- package/dist/assets/remoteEntry-Dpe5ejW8.js +0 -1
- package/dist/assets/rotate-ccw-BaeY9e6c.js +0 -1
- package/dist/assets/rotate-cw-CQFP4L_-.js +0 -1
- package/dist/assets/square-CURysUVy.js +0 -1
- package/dist/assets/src-71h6VhtY.js +0 -349
- package/dist/assets/src-BLs3JnCT.js +0 -67
- package/dist/assets/useEventInvalidation-XSNpux9c.js +0 -1
- package/dist/assets/user-round-DhK29-A9.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,U as i,W as a,a as o,b as s,o as c,q as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{X as f,Z as p,at as m}from"./player-overlays-DVo2KR_t.js";import{Ca as h,Ct as g,Da as _,Ea as v,Fa as y,Ft as b,It as x,Jr as S,Jt as C,M as w,Ma as T,Mn as E,Mt as D,Na as O,Nt as k,Oa as A,Pa as j,Pt as M,Sa as N,Ta as P,Tt as F,Zs as I,_a as L,ba as R,ha as z,ia as B,ja as V,ka as H,ln as U,nc as W,un as G,va as ee,xa as te}from"./src-CLAf92SY.js";import{lt as K,qt as ne}from"./src-e8CzBBHU.js";import{t as re}from"./clock-BcJxzq7C.js";import{t as ie}from"./copy-Clr1lTje.js";import{t as ae}from"./download-B6F7in4f.js";import{a as oe,c as se,d as ce,f as le,i as ue,m as de,n as fe,o as pe,p as me,r as he,s as ge,t as _e}from"./debounced-invalidate-BaUUaOIe.js";import{t as ve}from"./refresh-cw-Bk9SNV20.js";import{t as ye}from"./square-check-big-Bm7xPVTE.js";import{t as be}from"./square-C8DJ0ohY.js";import{t as xe}from"./undo-2-B94PbyBv.js";import{B as Se,F as Ce,J as q,L as we,c as Te,k as Ee,o as De,p as Oe,q as ke,r as Ae,t as je,w as J,z as Me}from"./index-DL2yqdrc.js";import{t as Ne}from"./AdminPage-CiKtOLQm.js";import{a as Pe,n as Fe,r as Ie,t as Le}from"./authed-media-DK9gXwSO.js";import{t as Re}from"./AdminTabs-B4GGMxRz.js";var ze=q(`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`}]]),Be=q(`bug`,[[`path`,{d:`m8 2 1.88 1.88`,key:`fmnt4t`}],[`path`,{d:`M14.12 3.88 16 2`,key:`qol33r`}],[`path`,{d:`M9 7.13v-1a3.003 3.003 0 1 1 6 0v1`,key:`d7y7pr`}],[`path`,{d:`M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6`,key:`xs1cw7`}],[`path`,{d:`M12 20v-9`,key:`1qisl0`}],[`path`,{d:`M6.53 9C4.6 8.8 3 7.1 3 5`,key:`32zzws`}],[`path`,{d:`M6 13H2`,key:`82j7cp`}],[`path`,{d:`M3 21c0-2.1 1.7-3.9 3.8-4`,key:`4p0ekp`}],[`path`,{d:`M20.97 5c0 2.1-1.6 3.8-3.5 4`,key:`18gb23`}],[`path`,{d:`M22 13h-4`,key:`1jl80f`}],[`path`,{d:`M17.2 17c2.1.1 3.8 1.9 3.8 4`,key:`k3fwyw`}]]),Ve=q(`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`}]]),He=q(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),Ue=q(`copy-plus`,[[`line`,{x1:`15`,x2:`15`,y1:`12`,y2:`18`,key:`1p7wdc`}],[`line`,{x1:`12`,x2:`18`,y1:`15`,y2:`15`,key:`1nscbv`}],[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),We=q(`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`}]]),Ge=q(`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`}]]),Ke=q(`star`,[[`path`,{d:`M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z`,key:`r04s7s`}]]),qe=q(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]);n();function Je(e){return e.subLabel??e.label}var Ye=720*60*60*1e3;function Xe(e){let t=[];for(let n of e)t.push(...n);return t}function Ze(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function Qe(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 $e(e,t){return`${String(e)}:${t}`}function et(e,t){let n=new Map,r=new Set;for(let i of e){let e=$e(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 tt(e,t){return{since:e.fromMs??t-Ye,until:e.toMs??t}}var nt=[`native`,`raster`,`standin`];function rt(e){return nt.some(t=>t===e)}var it={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 at(e){return e===`standin`?it.standin:e===`raster`?it.raster:null}var ot={"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 st(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:ot[r]??r,detail:i,raw:t}}function ct(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 lt({row:e,cameraName:t,nowMs:n,onOpenDetail:i,selected:a=!1,onToggleSelect:o,score:s,provenance:c,footer:l}){let d=Pe(e.bestEventId?`${Le}/${e.bestEventId}`:void 0),f=Math.round(e.importance*100),p=s===void 0?void 0:Math.round(s*100),m=ct(e.windowMs),h=()=>i(e),g=at(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(de,{className:`h-6 w-6 opacity-60`})}),o&&u(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o($e(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(ye,{className:`h-4 w-4 text-primary`}):u(be,{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)}),g!==null&&u(`span`,{className:`absolute bottom-1 right-1 z-10 rounded px-1.5 py-0.5 text-[10px] font-semibold text-white ${g.tone===`warning`?`bg-warning/90`:`bg-black/70`}`,title:g.title,children:g.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(We,{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(Be,{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(Ke,{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,Je(e)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,Je(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:le(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 ut=1400,dt=`Admin-gated URL — opens only inside an authenticated session`;function ft({label:t,value:n,title:i}){let[a,o]=l(!1);return d(()=>{if(!a)return;let e=setTimeout(()=>o(!1),ut);return()=>clearTimeout(e)},[a]),r(`button`,{type:`button`,onClick:e(()=>{(async()=>{try{await navigator.clipboard.writeText(n),o(!0)}catch{window.prompt(`Copy the media URL:`,n)}})()},[n]),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?Se:ie,{className:`h-2.5 w-2.5 shrink-0`}),u(`span`,{className:`truncate`,children:a?`Copied`:t})]})}function pt({localUrl:e,publicUrl:t}){return r(`div`,{className:`flex flex-wrap gap-1`,children:[u(ft,{label:`Local`,value:e,title:`Copy LAN URL — ${dt}`}),t&&u(ft,{label:`Public`,value:t,title:`Copy public URL — ${dt}`})]})}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`,sceneFrame:`Scene frame (clean, retired)`};function ht(e){return e in mt}function gt(e){return ht(e)?mt[e]:e}function _t(e,t){return`${e}${Fe}/${encodeURIComponent(t)}`}n();var vt=3e4;function yt(t){let[n,r]=l(null),i=e(e=>{r(t=>t??e)},[]);return d(()=>{t||r(null)},[t]),{publicOrigin:n,probes:t?u(bt,{onOrigin:i}):null}}function bt({onOrigin:e}){let{data:t}=E({capName:`network-access`});return u(s,{children:(t??[]).map(t=>u(xt,{addonId:t.addonId,onOrigin:e},t.addonId))})}function xt({addonId:e,onOrigin:t}){let{data:n}=B({addonId:e},{refetchInterval:vt,retry:!1});return d(()=>{let e=n?K.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 Y=typeof y==`function`,St=`Track flags arrive with the next server update`;function Ct(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var wt=Y?y:Ct;function Tt(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 Et({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 Dt({deviceId:e,trackId:t,markForTrain:n,debug:i,favourited:a,onChange:o}){let s=wt(),[c,d]=l(null),f=c?.markForTrain??n===!0,p=c?.debug??i===!0,m=c?.favourited??a===!0,h=!Y||s.isPending,g=Y?void 0:St,_=n=>{h||(async()=>{try{let r=Tt(await s.mutateAsync({deviceId:e,trackId:t,flags:n}));if(!r)return;d(r),o?.(r)}catch(e){let t=e instanceof Error?e.message:``;window.alert(t===``?`Could not update this track. Check the server logs.`:`Could not update this track — ${t}`)}})()};return r(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[u(Et,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:f,disabled:h,...g===void 0?{}:{title:g},icon:u(We,{className:`h-4 w-4`}),onToggle:()=>_({markForTrain:!f})}),u(Et,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:p,disabled:h,...g===void 0?{}:{title:g},icon:u(Be,{className:`h-4 w-4`}),onToggle:()=>_({debug:!p})}),u(Et,{label:`Favourited`,hint:`Keeps this track and its media past retention`,checked:m,disabled:h,...g===void 0?{}:{title:g},icon:u(Ke,{className:`h-4 w-4`}),onToggle:()=>_({favourited:!m})})]})}var X=100,Ot=120,kt={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Z=e=>e<0?0:e>1?1:e,Q=e=>Math.round(e*100)/100;function At(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 jt(e,t,n){if(e.length===0||t===null)return kt;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return kt;let a=At(e,n?.maxPoints??Ot).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X)})),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:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X),mediaKey:e.mediaKey})),u=null,d=-1;for(let t of e){let e=Z(t.bbox.w/r)*Z(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Q(Z(u.bbox.x/r)*X),y:Q(Z(u.bbox.y/i)*X),w:Q(Z(u.bbox.w/r)*X),h:Q(Z(u.bbox.h/i)*X)}:null}}var Mt=typeof L==`function`,Nt=`Track deletion arrives with the next server update`;function Pt(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Ft=Mt?L:Pt;n();var It=15e3;function Lt(e){return`${Le}/${encodeURIComponent(e)}`}var Rt=f();function zt({mediaKey:e,label:t}){let{src:n,failed:r}=Pe(Lt(e));return n===null?u(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?u(de,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):u(J,{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 Bt=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),Vt=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]);function Ht(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 Ut({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.mediaKey)}:void 0,children:u(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${e.mediaKey}-${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 $({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 Wt({row:t,cameraName:n,deleteAvailable:i,onClose:o,onDeleted:c,onFlagsChanged:f}){let p=m(),_=Ft(),v=t!==null,y=t?.deviceId??0,b=t?.trackId??``,S=t?.bestEventId??``,C=t?.timestamp??0,w=t?.windowMs??0,{data:T}=te({deviceId:y,trackId:b},{enabled:v}),{data:E}=A({trackId:b,deviceId:y},{enabled:v}),{data:D}=h({eventId:S,deviceId:y},{enabled:v&&S!==``}),{data:O}=I({deviceId:y,since:C-It,until:C+w+It},{enabled:v}),[k,j]=l(null),[M,N]=l(!1),{publicOrigin:P,probes:L}=yt(v);d(()=>{j(null)},[y,b]);let R=a(()=>{let e=E??[],t=D??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[E,D]),z=k??R,B=Pe(z?Lt(z.key):void 0),V=a(()=>{let e=new Set,t=[];for(let n of[...D??[],...E??[]])n.key===``||e.has(n.key)||(e.add(n.key),t.push(n));return t},[D,E]),H=a(()=>V.find(e=>Bt.has(e.kind))??null,[V]),U=Ht(Pe(H?Lt(H.key):void 0).src),W=a(()=>jt(T?.positions??[],U,{snapshots:(T?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaKey:e.mediaKey}))}),[T?.positions,T?.snapshots,U]),G=e(e=>{let t=V.find(t=>t.key===e);t&&j(t)},[V]);if(t===null)return null;let ee=B.src,K=z?.kind,ne=K!==void 0&&Vt.has(K)&&U!==null&&(T?.positions.length??0)>=2,re=O&&O.length>0?O[0]:null,ie=()=>{re&&(N(!0),(async()=>{try{let e=await p.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:re.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{window.alert(`Could not resolve clip playback. Check the server logs.`)}finally{N(!1)}})())},ae=()=>{!i||_.isPending||window.confirm(`Delete this track and all its media? This cannot be undone.`)&&(async()=>{try{await _.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),c()}catch{window.alert(`Failed to delete this track. Check the server logs.`)}})()},oe=Math.round(t.importance*100),se=T?.importanceReason?`${String(oe)}% · ${T.importanceReason}`:`${String(oe)}%`,le=T?.zonesVisited&&T.zonesVisited.length>0?T.zonesVisited.join(`, `):`—`,ue=T?.audioLabels&&T.audioLabels.length>0?T.audioLabels.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `):`—`,pe=T?T.totalDistance.toFixed(2):`—`,he=st(T?.previewMissReason),ge=me(T?T.firstSeen:C),_e=T?me(T.lastSeen):`—`;return u(g,{open:!0,onOpenChange:e=>!e&&o(),children:r(F,{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,Je(t)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,Je(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(Ae,{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:[ee?u(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:u(fe,{src:ee,alt:`Key frame from ${n}`,fit:`natural`,className:`w-full`,overlay:ne?u(Ut,{overlay:W,onPickSnapshot:G}):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:B.failed?r(s,{children:[u(de,{className:`h-8 w-8 opacity-60`}),u(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):u(J,{className:`h-6 w-6 animate-spin opacity-70`})}),V.length>0&&u(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:V.map(e=>{let t=gt(e.kind),n=_t(Rt,e.key),i=P?_t(P,e.key):null;return r(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[u(`button`,{type:`button`,onClick:()=>j(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${t} · ${me(e.timestamp)}`,children:u(zt,{mediaKey:e.key,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:me(e.timestamp),children:ce(e.timestamp)})]}),u(pt,{localUrl:n,publicUrl:i})]},e.key)})}),L,re&&r(x,{variant:`secondary`,onClick:ie,disabled:M,children:[M?u(J,{className:`h-3.5 w-3.5 animate-spin`}):u(Ee,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),u(Dt,{deviceId:t.deviceId,trackId:t.trackId,...(T?.markForTrain??t.markForTrain)===void 0?{}:{markForTrain:T?.markForTrain??t.markForTrain},...(T?.debug??t.debug)===void 0?{}:{debug:T?.debug??t.debug},...(T?.favourited??t.favourited)===void 0?{}:{favourited:T?.favourited??t.favourited},onChange:f}),he!==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:he.sentence}),u(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:he.raw})]}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[u($,{label:`Camera`,value:n}),u($,{label:`Class`,value:t.className}),u($,{label:`Label`,value:t.label??`—`}),u($,{label:`Sub-label`,value:t.subLabel??`—`}),u($,{label:`Importance`,value:se}),u($,{label:`Zones visited`,value:le}),u($,{label:`Audio heard`,value:ue}),u($,{label:`Total distance`,value:pe}),u($,{label:`First seen`,value:ge}),u($,{label:`Last seen`,value:_e}),u($,{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:Nt,children:r(x,{variant:`secondary`,onClick:ae,disabled:!i||_.isPending,children:[_.isPending?u(J,{className:`h-3.5 w-3.5 animate-spin`}):u(De,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}var Gt=`pipeline-analytics`,Kt=`debug.listTracks`,qt=`debug.analyze`,Jt=p(`/addon/pipeline-analytics/debug-export`);function Yt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Xt(e,t){let n=e[t];return typeof n==`string`?n:null}function Zt(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Qt(e,t){let n=e[t];return typeof n==`boolean`?n:null}function $t(e){return e===`error`||e===`warn`||e===`info`}function en(e){if(!Yt(e))return null;let t=Xt(e,`code`),n=Xt(e,`detail`),r=e.severity;return t===null||n===null||!$t(r)?null:{code:t,severity:r,detail:n}}function tn(e){if(!Yt(e))return null;let t=Xt(e,`trackId`),n=Zt(e,`deviceId`),r=Xt(e,`className`),i=Zt(e,`firstSeen`),a=Zt(e,`lastSeen`),o=Zt(e,`durationMs`),s=Qt(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=Xt(e,`label`),l=Xt(e,`subLabel`),u=Xt(e,`previewMissReason`),d=Qt(e,`markForTrain`),f=Qt(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:Zt(e,`importance`)??0,bestEventId:Xt(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function nn(e){let t=tn(e);if(t===null||!Yt(e))return null;let n=Zt(e,`mediaCount`),r=Zt(e,`eventCount`),i=Zt(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=en(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...rt(l)?{thumbnailProvenance:l}:{}}}function rn(e){if(!Yt(e))return null;let t=Qt(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=tn(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function an(e){if(!Yt(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=nn(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var on={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`,BEST_SHOT_STANDIN:`stand-in best shot`,BEST_SHOT_RASTER:`low-res best shot`};function sn(e){return on[e]??e}var cn={error:0,warn:1,info:2};function ln(e){return e.toSorted((e,t)=>cn[e.severity]-cn[t.severity]||e.code.localeCompare(t.code))}function un(e){return e.length===0?Jt:`${Jt}?deviceIds=${e.join(`,`)}`}function dn(e,t){return`${String(e)}:${t}`}function fn(e,t){let n=[],r=new Set;for(let i of e){let e=dn(i.deviceId,i.trackId);!t.has(e)||r.has(e)||(r.add(e),n.push({deviceId:i.deviceId,trackId:i.trackId}))}return n}n();var pn=`all`,mn=`The server answered in a shape this build does not understand.`,hn={error:`danger`,warn:`warning`,info:`info`};function gn({findings:e}){return e.length===0?u(b,{variant:`success`,children:`no anomaly found`}):u(`div`,{className:`flex flex-wrap gap-1`,children:ln(e).map(e=>u(b,{variant:hn[e.severity],title:e.detail,children:sn(e.code)},e.code))})}function _n({track:e,report:t,analyzing:n}){let i=st(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(gn,{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 vn(){let e=m(),[t,n]=l(pn),[i,s]=l(!1),[c,d]=l(null),[f,p]=l(new Set),[h,g]=l(null),[_,v]=l(null),[y,b]=l(null),[w,T]=l([]),E=wt(),O=S({isCamera:!0,projection:`slim`}),k=a(()=>[{value:pn,label:`All cameras`},...(O.data??[]).map(e=>({value:String(e.id),label:e.name}))],[O.data]),A=a(()=>{let e=new Map;for(let t of O.data??[])e.set(t.id,t.name);return e},[O.data]),j=e=>A.get(e)??`Camera ${String(e)}`,N=a(()=>t===pn?[]:[Number.parseInt(t,10)],[t]),P=o({queryKey:[`events-debug`,`list`,N],queryFn:async()=>rn(await e.trpcClient.addons.custom.mutate({addonId:Gt,action:Kt,input:N.length===0?{}:{deviceIds:N}}))}),F=a(()=>(P.data?.tracks??[]).map(e=>e.trackId),[P.data]),I=o({queryKey:[`events-debug`,`analyze`,F],enabled:F.length>0,queryFn:async()=>an(await e.trpcClient.addons.custom.mutate({addonId:Gt,action:qt,input:{trackIds:F}}))}),L=a(()=>{let e=new Map;for(let t of I.data?.reports??[])e.set(t.trackId,t);return e},[I.data]),R=P.data?.tracks??[],z=P.data===null||I.data===null,B=()=>{P.refetch(),I.refetch()},V=e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},H=()=>{p(new Set(R.map(e=>dn(e.deviceId,e.trackId))))},U=()=>p(new Set),W=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await E.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},G=e=>{if(!Y||_!==null)return;let t=fn(R,f);t.length!==0&&(v(e),b(null),(async()=>{let n=await W(e,t);v(null);let r=new Set(n.refused);p(new Set(t.filter(e=>r.has(e.trackId)).map(e=>dn(e.deviceId,e.trackId)))),e===`analyzed`&&T(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.`),P.refetch()})())},ee=()=>{let e=w;e.length===0||_!==null||(v(`analyzed`),b(null),(async()=>{for(let t of e)try{await E.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),T([]),P.refetch()})())},te=async()=>{s(!0),d(null);try{await Ie(un(N),`camstack-debug.zip`)}catch(e){d(e instanceof Error?e.message:`Export failed.`)}finally{s(!1)}},K=_!==null;return u(Ne,{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(D,{value:t,options:k,onChange:e=>n(e.target.value)})}),r(x,{variant:`secondary`,onClick:B,disabled:P.isFetching,children:[P.isFetching?u(J,{className:`h-3.5 w-3.5 animate-spin`}):u(ve,{className:`h-3.5 w-3.5`}),`Refresh`]}),r(x,{onClick:()=>void te(),disabled:i||R.length===0,children:[i?u(J,{className:`h-3.5 w-3.5 animate-spin`}):u(ae,{className:`h-3.5 w-3.5`}),`Export all (`,String(R.length),`)`]}),R.length>0&&f.size<R.length&&u(x,{variant:`ghost`,onClick:H,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.`]}),P.isError&&u(C,{message:`Could not load the marked tracks.`}),z&&!P.isError&&u(C,{message:mn}),c!==null&&u(C,{message:c}),y!==null&&u(C,{message:y}),P.data?.truncated===!0&&u(C,{message:`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`}),(I.data?.vanished.length??0)>0&&r(`p`,{className:`text-xs text-foreground-subtle`,children:[String(I.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:Y?void 0:`Track flags arrive with the next server update`,children:r(x,{variant:`secondary`,onClick:()=>G(`keep`),disabled:!Y||K,children:[_===`keep`?u(J,{className:`h-3.5 w-3.5 animate-spin`}):u(Ke,{className:`h-3.5 w-3.5`}),` `,`Keep`]})}),u(`span`,{title:Y?void 0:`Track flags arrive with the next server update`,children:r(x,{onClick:()=>G(`analyzed`),disabled:!Y||K,children:[_===`analyzed`?u(J,{className:`h-3.5 w-3.5 animate-spin`}):u(Se,{className:`h-3.5 w-3.5`}),` `,`Analyzed`]})}),u(x,{variant:`ghost`,onClick:U,disabled:K,children:u(Ae,{className:`h-3.5 w-3.5`})})]})]}),w.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(w.length),` track(s) marked analyzed and removed from this list.`]}),r(x,{variant:`ghost`,onClick:ee,disabled:K,children:[u(xe,{className:`h-3.5 w-3.5`}),` Undo`]}),u(x,{variant:`ghost`,onClick:()=>T([]),disabled:K,children:u(Ae,{className:`h-3.5 w-3.5`})})]}),P.isLoading?u(M,{children:u(`div`,{className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`Loading…`})}):R.length===0?u(M,{children:r(`div`,{className:`flex flex-col items-center gap-2 px-3 py-8 text-center`,children:[u(Be,{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:R.map(e=>{let t=L.get(e.trackId);return u(lt,{row:e,cameraName:j(e.deviceId),nowMs:e.lastSeen,selected:f.has(dn(e.deviceId,e.trackId)),onToggleSelect:V,onOpenDetail:g,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:u(_n,{track:e,report:t,analyzing:I.isFetching})},dn(e.deviceId,e.trackId))})}),h&&u(Wt,{row:h,cameraName:j(h.deviceId),deleteAvailable:Mt,onClose:()=>g(null),onDeleted:()=>{g(null),P.refetch()},onFlagsChanged:e=>{e.debug||(g(null),P.refetch())}})]})})}var yn=200,bn=3e4,xn=[];function Sn(e){let t=m(),n=e.deviceIds.length>0,r=[...e.deviceIds].sort((e,t)=>e-t),{data:i,isLoading:a}=o({queryKey:[`events-feed`,r,e.since,e.until,e.minImportance??null,e.classFilter??null],enabled:n,staleTime:bn,refetchInterval:bn,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEventsBatch.query({deviceIds:r,since:e.since,until:e.until,limit:yn,...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:Ze(Xe(i??xn),`importance`),isLoading:n&&a}}n();var Cn=[`events-feed`],wn=2e3;function Tn(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:Cn})},[]),p=t(void 0);p.current||=_e({delayMs:wn,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 W(ne.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),W(ne.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:s,refreshNow:m}}n();function En({groups:e,selected:t,onChange:n,loading:i=!1}){let{t:o}=je(),[s,c]=l(!1),[d,f]=l(``),[p,m]=l(new Set),h=d.trim().toLowerCase(),g=e=>h.length===0||U(e,o).toLowerCase().includes(h),_=a(()=>e.map(e=>({macro:e.macro,subs:e.subs.filter(t=>g(t)||g(e.macro))})).filter(e=>g(e.macro)||e.subs.length>0),[e,h]),v=e=>m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),y=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)},b=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},x=()=>n(new Set),S=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 ${S>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(qe,{className:`h-3.5 w-3.5`}),S>0?`Kinds (${String(S)})`:`Kinds`,u(Me,{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(Oe,{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`}),S>0&&u(`button`,{type:`button`,onClick:x,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),_.length===0&&u(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:i?`Loading kinds…`:h.length>0?`No kind matches that search.`:`These cameras advertise no event kinds.`}),_.map(e=>{let n=G(e.macro.iconId),i=p.has(e.macro.kind)||h.length>0,a=t.has(e.macro.kind);return r(`div`,{className:`mb-0.5`,children:[r(`div`,{className:`flex items-center gap-1`,children:[e.subs.length>0?u(`button`,{type:`button`,onClick:()=>v(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:u(i?Me:we,{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:()=>y(e),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),u(`span`,{className:`font-medium`,children:U(e.macro,o)})]})]}),i&&e.subs.map(e=>{let n=G(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:()=>b(e.kind),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),u(`span`,{children:U(e,o)})]},e.kind)})]},e.macro.kind)})]})]})}function Dn(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 On(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var kn=new Set([`detection`,`package`]);function An(e,t){return[...Dn(e,t).values()].filter(e=>e.parentKind===null&&kn.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function jn(e,t){let n=Dn(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,On(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 Mn(){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 Nn=[`events-feed`],Pn=60,Fn=[{value:`importance`,label:`Importance`,icon:ze},{value:`time`,label:`Recent`,icon:re}];function In(){let e=c(),[t,n]=l(ge),[i,o]=l(new Set),[f,p]=l(new Set),[m,h]=l(0),[g,_]=l(`time`),[v,y]=l(new Set),[b,C]=l(null),[w,T]=l(()=>Date.now());d(()=>{let e=setInterval(()=>T(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:E,until:D}=a(()=>tt({fromMs:t.fromMs,toMs:t.toMs},w),[t.fromMs,t.toMs,w]),O=Mn(),{pending:k,refreshNow:A}=Tn({paused:b!==null||v.size>0||O.scrolledPast}),{data:j=[]}=S({isCamera:!0,projection:`slim`}),M=a(()=>j.map(e=>e.id),[j]),{data:P,isLoading:F}=N({deviceIds:M},{enabled:M.length>0,staleTime:5*6e4}),I=a(()=>jn(P??[],i),[P,i]),L=Ft(),R=L.isPending,{rows:z,isLoading:B}=Sn({deviceIds:M,since:E,until:D,minImportance:m>0?m:void 0,classFilter:f.size===1?[...f][0]:void 0}),V=a(()=>{let e=new Map;for(let t of j??[])e.set(t.id,t.name);return e},[j]),H=e=>V.get(e)??`Camera #${String(e)}`,U=a(()=>se(z).map(e=>({id:e,name:H(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[z,V]),W=a(()=>Ze(Qe(z,{cameras:i,classes:f,minImportance:m}),g),[z,i,f,m,g]),G=pe(W,Pn,a(()=>JSON.stringify([[...i].sort((e,t)=>e-t),[...f].sort(),m,g,E,D]),[i,f,m,g,E,D])),ee=()=>{e.invalidateQueries({queryKey:Nn})},te=()=>y(new Set);function K(e){y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function ne(){if(v.size===0||!Mt)return;let e=et(z,v),t=[...e.values()].reduce((e,t)=>e+t.length,0);if(t===0||!window.confirm(`Delete ${String(t)} track${t===1?``:`s`} and all their media? This cannot be undone.`))return;let n=[...e];Promise.allSettled(n.map(([e,t])=>L.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{ee();let t=[],r=new Set;if(e.forEach((e,i)=>{let a=n[i];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)r.add($e(o,e));else t.push(o)}),y(e=>{let t=new Set(e);for(let e of r)t.delete(e);return t}),t.length>0){let e=t.map(e=>H(e)).join(`, `);window.alert(`Failed to delete tracks on: ${e}. They remain selected — retry, or check the server logs.`)}})}let re=W.length!==z.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(he,{onChange:n}),u(ue,{cameras:U,selected:i,onChange:o}),u(En,{groups:I,selected:f,onChange:p,loading:F}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(`span`,{children:`Min score`}),u(`input`,{type:`range`,min:0,max:1,step:.05,value:m,onChange:e=>h(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(m*100)})]}),u(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Fn.map(e=>{let t=e.icon;return r(`button`,{type:`button`,onClick:()=>_(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${g===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!B&&u(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:re?`${String(W.length)} of ${String(z.length)} events`:`${String(W.length)} event${W.length===1?``:`s`}`})]}),v.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:[v.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[u(`span`,{title:Mt?void 0:`Track deletion arrives with the next server update`,children:r(x,{variant:`secondary`,onClick:ne,disabled:!Mt||R,children:[R?u(J,{className:`h-3.5 w-3.5 animate-spin`}):u(De,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),u(x,{variant:`ghost`,onClick:te,disabled:R,children:u(Ae,{className:`h-3.5 w-3.5`})})]})]}),B&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(J,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!B&&W.length===0&&u(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),k&&u(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:u(`button`,{type:`button`,onClick:A,className:`rounded-full border border-primary/40 bg-surface px-3 py-1 text-[11px] font-medium text-primary shadow-sm hover:bg-primary/10`,children:`New events — refresh`})}),!B&&W.length>0&&r(s,{children:[u(`div`,{ref:O.ref,"aria-hidden":!0,className:`h-0`}),u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:G.pageItems.map(e=>u(lt,{row:e,cameraName:H(e.deviceId),nowMs:w,selected:v.has($e(e.deviceId,e.trackId)),onToggleSelect:K,onOpenDetail:C},$e(e.deviceId,e.trackId)))}),u(oe,{currentPage:G.page,totalItems:G.totalItems,pageSize:G.pageSize,onPageChange:G.setPage,itemNoun:`events`})]}),b&&u(Wt,{row:b,cameraName:H(b.deviceId),deleteAvailable:Mt,onClose:()=>C(null),onDeleted:()=>{ee(),C(null)},onFlagsChanged:e=>{C(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}n();var Ln=50,Rn=350,zn=[{value:.2,label:`Loose`},{value:.25,label:`Balanced`},{value:.3,label:`Strict`}];function Bn(e){return{id:e.id,trackId:e.trackId??e.id,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,subLabel:e.subLabel,importance:e.importance??0,bestEventId:e.mediaKey??e.trackId??e.id,windowMs:void 0}}function Vn({onActiveChange:e}){let[t,n]=l(``),[i,o]=l(.2),[s,c]=l(null),[f,p]=l(null),[m,h]=l(null),g=w(t,Rn).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=[]}=S({isCamera:!0,projection:`slim`}),x=a(()=>{let e=new Map;for(let t of b)e.set(t.id,t.name);return e},[b]),C=e=>x.get(e)??`Camera #${String(e)}`,T=a(()=>b.map(e=>e.id),[b]),{data:E}=N({deviceIds:T},{enabled:T.length>0,staleTime:5*6e4}),D=a(()=>An(E??[],new Set(f===null?[]:[f])),[E,f]);d(()=>{s!==null&&(D.some(e=>e.kind===s)||c(null))},[D,s]);let{data:k,isFetching:A,isError:j,error:M}=O({text:g,minScore:i,limit:Ln,classFilter:s??void 0,deviceId:f??void 0},{enabled:_}),P=a(()=>[...k??[]].sort((e,t)=>t.score-e.score).map(e=>({...Bn(e),score:e.score})),[k]);function F(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(Oe,{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(Ae,{className:`h-3.5 w-3.5`})})]}),A&&_&&u(J,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[u(`div`,{className:`flex items-center gap-1`,children:D.map(e=>u(`button`,{type:`button`,onClick:()=>F(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:U(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:zn.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:`Minimum CLIP score ${e.value.toFixed(2)}`,children:e.label},e.value))})]}),_&&!A&&!j&&r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[P.length,` match`,P.length===1?``:`es`]})]})]}),_&&r(`div`,{className:`space-y-3`,children:[j&&r(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,M instanceof Error?M.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!j&&A&&P.length===0&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(J,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!j&&!A&&P.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.`]}),!j&&P.length>0&&u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:P.map(e=>u(lt,{row:e,cameraName:C(e.deviceId),nowMs:v,score:e.score,onOpenDetail:h},e.id))})]}),m&&u(Wt,{row:m,cameraName:C(m.deviceId),deleteAvailable:Mt,onClose:()=>h(null),onDeleted:()=>h(null)})]})}var Hn=15e3,Un={rows:[],unreadableCount:0};function Wn(e){let t=m(),n=e.length>0,r=[...e].sort((e,t)=>e-t),{data:i,isLoading:a}=o({queryKey:[`stationary-objects`,r],enabled:n,staleTime:Hn,refetchInterval:Hn,queryFn:async()=>{let e=await t.trpcClient.zoneAnalytics.getCurrentSnapshotBatch.query({deviceIds:r}),n=[],i=0;for(let t of e){if(t.read===`unreadable`){i++;continue}for(let e of t.snapshot?.stationaryObjects??[])n.push({...e,deviceId:t.deviceId})}return{rows:n,unreadableCount:i}}}),s=i??Un;return{rows:s.rows.toSorted((e,t)=>t.becameStationaryAt-e.becameStationaryAt),isLoading:n&&a,unreadableCount:s.unreadableCount}}n();function Gn(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 Kn({row:e,cameraName:t,nowMs:n}){let i=e.keyFrameMediaKey?.startsWith(`track:`)?e.keyFrameMediaKey.split(`:`)[1]:e.keyFrameMediaKey,a=Pe(i?`${Le}/${i}`:void 0);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:[a.src?u(`img`,{src:a.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(Ge,{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 `,Gn(n,e.becameStationaryAt)]})]})]})}function qn(){let[e,t]=l(!1),n=Date.now(),{data:i=[]}=S({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}=Wn(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?Me:we,{className:`h-4 w-4 text-foreground-subtle`}),u(Ge,{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(Kn,{row:e,cameraName:s.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}n();function Jn(){let[e,t]=l(!1);return u(Ne,{children:r(`section`,{className:`space-y-3`,children:[u(Vn,{onActiveChange:t}),!e&&u(qn,{}),!e&&u(In,{})]})})}var Yn=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],Xn=new Set(Yn);function Zn(e){let t=e?.trim().toLowerCase();return t===void 0||t===``?null:Xn.has(t)?`"${t}" is a macro class, not a label — person / postman / Marco are three different tiers`:null}function Qn({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=Zn(e.label),l=Zn(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(D,{className:`w-28`,value:e.macroClass,options:Yn.map(e=>({value:e,label:e})),onChange:e=>{let t=Yn.find(t=>t===e.target.value);t!==void 0&&i(o,{macroClass:t})}}),u(D,{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(b,{variant:`info`,children:[e.assistModelId??`assist`,e.assistScore===void 0?``:` ${e.assistScore.toFixed(2)}`]}),u(x,{variant:`ghost`,size:`sm`,"aria-label":`Delete this subject`,onClick:()=>{a(o)},children:u(De,{className:`h-3 w-3`})})]}),r(`div`,{className:`flex items-center gap-2`,children:[u(k,{className:`flex-1`,placeholder:`label (postman, van, cat…)`,value:e.label??``,onChange:e=>{i(o,{label:e.target.value})}}),u(k,{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 $n(e){return e.every(e=>Zn(e.label)===null&&Zn(e.subLabel)===null&&Xn.has(e.macroClass))}function er(e){return e<0?0:e>1?1:e}function tr(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 nr(e,t,n){return{x:er((e-n.left)/n.width),y:er((t-n.top)/n.height)}}function rr(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 ir(e){return e.w>=.01&&e.h>=.01}function ar(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 or(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 sr({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=tr(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 nr(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:rr(t,t)}))},onPointerMove:e=>{if(g===null)return;let t=y(e);t!==null&&_({start:g.start,current:rr(g.start,t)})},onPointerUp:()=>{if(g===null)return;let e=g.current;_(null),ir(e)?f(e):d(or(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=ar(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:ar(g.current,v)})]})}function cr(e){return e>=1e6?`${(e/1e6).toFixed(1)} MB`:`${Math.round(e/1e3)} KB`}function lr({candidates:e,copies:t,activeFrameId:n,refusals:i,isSelecting:a,onSelectCandidate:o,onOpenCopy:s,onRemoveCopy:c}){let l=new Set(t.map(e=>e.sourceMediaKey)),d=e.filter(e=>!l.has(e.mediaKey));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(Se,{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,` · `,cr(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(De,{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.mediaKey);return r(`li`,{children:[r(x,{variant:`secondary`,size:`sm`,disabled:a||t!==void 0,onClick:()=>{o(e.mediaKey)},children:[a?u(J,{className:`h-3 w-3 animate-spin`}):u(t===void 0?Ue:de,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:e.kind}),u(`span`,{className:`ml-1 text-foreground-subtle`,children:cr(e.sizeBytes)})]}),t!==void 0&&u(b,{variant:`danger`,className:`ml-1`,children:t})]},e.mediaKey)})})]})]})}function ur(e){return e.frameCount===0?`untouched`:e.annotationCount===0?`started`:`ready`}var dr={untouched:{icon:He,label:`to do`,variant:`default`},started:{icon:Ve,label:`frames only`,variant:`info`},ready:{icon:Ce,label:`annotated`,variant:`success`}};function fr(e){return new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function pr({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(J,{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=dr[ur(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(b,{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)}`,` ·`,` `,fr(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)})})}n();var mr=`person`;function hr(){let[t,n]=l(null),[i,o]=l(null),[c,f]=l([]),[p,m]=l(-1),[h,g]=l(new Map),[y,C]=l(null),w=S({projection:`slim`,isCamera:!0}),E=a(()=>{let e=new Map;for(let t of w.data??[])e.set(t.id,t.name);return e},[w.data]),D=_({}),O=v({trackId:t?.trackId??``},{enabled:t!==null}),k=P({trackId:t?.trackId??``},{enabled:t!==null}),A=R({frameId:i??``},{enabled:i!==null}),M=j(),N=ee(),F=H(),I=T(),L=z(),B=V();d(()=>{if(i===null){f([]);return}f((k.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,k.data]),d(()=>{let e=O.data?.copies??[];i===null&&e.length>0&&o(e[0].frameId)},[O.data,i]);let U=e(e=>{n(e),o(null),f([]),g(new Map),C(null)},[]),W=e(async e=>{if(t===null)return;let n=await M.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,mediaKeys:[e]});if(n.refused.length>0){let e=new Map(h);for(let t of n.refused)e.set(t.sourceMediaKey,t.reason);g(e)}n.copied.length>0&&o(n.copied[0].frameId),await O.refetch(),await D.refetch()},[t,M,h,O,D]),G=e(async e=>{t!==null&&(await N.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:e}),i===e&&o(null),await O.refetch(),await k.refetch(),await D.refetch())},[t,N,i,O,k,D]),te=e(async e=>{if(t===null||i===null)return;C(null);let n=await F.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:i,subject:e===`package`?{kind:`package`}:{kind:`objects`,modelId:`yolo26n`,minScore:.3}});if(n.kind===`refused`){C(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}}))]),C(`${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,F]),K=e(e=>{f(t=>[...t,{bbox:e,macroClass:mr,kind:`subject`,source:`operator`}]),m(c.length)},[c.length]),ne=e((e,t)=>{f(n=>n.map((n,r)=>r===e?{...n,...t}:n))},[]),re=e(e=>{f(t=>t.filter((t,n)=>n!==e)),m(-1)},[]),ie=e(async()=>{t===null||i===null||(await I.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 k.refetch(),await D.refetch(),C(`Annotations saved.`))},[t,i,c,I,k,D]),ae=e(async()=>{if(t===null)return;let e=await L.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});C(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 D.refetch(),e.changed&&n(null)},[t,L,D]),oe=e(async()=>{if(t===null)return;let e=await B.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});C(e.changed?`Track returned to staging. Its copies and annotations were left alone.`:`Refused: ${e.reason??`unknown`}`),await D.refetch()},[t,B,D]),se=A.data,ce=$n(c)&&i!==null;return r(Ne,{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(`div`,{className:`flex items-center gap-2`,children:[r(x,{variant:`secondary`,size:`sm`,onClick:()=>void oe(),children:[u(xe,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Back to staging`})]}),r(x,{size:`sm`,onClick:()=>void ae(),children:[u(We,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Complete track`})]})]}),children:[y!==null&&u(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-xs text-foreground`,children:y}),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(b,{children:D.data?.length??0})]}),u(pr,{tracks:D.data??[],isLoading:D.isLoading,selectedTrackId:t?.trackId??null,deviceNames:E,onSelect:U})]}),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(lr,{candidates:O.data?.candidates??[],copies:O.data?.copies??[],activeFrameId:i,refusals:h,isSelecting:M.isPending,onSelectCandidate:e=>void W(e),onOpenCopy:o,onRemoveCopy:e=>void G(e)})}),i!==null&&r(`div`,{className:`grid grid-cols-1 xl:grid-cols-[minmax(0,1fr)_minmax(0,380px)] gap-3`,children:[u(`div`,{className:`rounded-md border border-border overflow-hidden`,children:se===void 0?r(`div`,{className:`flex items-center gap-2 p-6 text-xs text-foreground-subtle`,children:[u(J,{className:`h-3.5 w-3.5 animate-spin`}),`Loading the frame…`]}):u(sr,{imageSrc:`data:image/jpeg;base64,${se.base64}`,imageWidth:se.width,imageHeight:se.height,boxes:c,selectedIndex:p,onSelect:m,onDraw:K})}),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(x,{variant:`secondary`,size:`sm`,disabled:F.isPending,onClick:()=>void te(`objects`),children:[u(Te,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Propose`})]}),r(x,{variant:`secondary`,size:`sm`,disabled:F.isPending,onClick:()=>void te(`package`),children:[u(Te,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Packages`})]})]}),u(`div`,{className:`flex-1 overflow-y-auto`,children:u(Qn,{annotations:c,selectedIndex:p,onSelect:m,onChange:ne,onDelete:re})}),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(x,{size:`sm`,disabled:!ce||I.isPending,onClick:()=>void ie(),children:`Save frame`})]})]})]})]})})]})]})}function gr(){return u(`div`,{className:`flex flex-col p-4`,children:u(Re,{tabs:[{id:`feed`,label:`Feed`,icon:ke,content:u(Jn,{})},{id:`retrain`,label:`Retrain`,icon:We,content:u(hr,{})},{id:`debug`,label:`Debug`,icon:Be,content:u(vn,{})}]})})}export{gr 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{Gt as s,Kr as c,Kt as l,cn as u}from"./src-
|
|
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{Gt as s,Kr as c,Kt as l,cn as u}from"./src-CLAf92SY.js";import{t as d}from"./refresh-cw-Bk9SNV20.js";import{B as f,X as p,p as m,r as h,w as g,x as _,z as v}from"./index-DL2yqdrc.js";function y({deviceId:e}){let t=p(),{data:r,isLoading:i,isFetching:a,isError:s,refetch:l}=c({deviceId:e},{enabled:Number.isFinite(e)}),u=r?.devices??[];return n(`div`,{className:`mt-3 rounded-md border border-border bg-background p-2.5`,children:[n(`div`,{className:`flex items-center justify-between mb-1.5`,children:[n(`span`,{className:`text-[11px] font-medium text-foreground`,children:[`Resolved links`,o(`span`,{className:`ml-1.5 text-[10px] font-normal text-foreground-subtle`,children:`children + your picks`})]}),n(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-50`,disabled:a,onClick:()=>void l(),title:`Re-run the resolver`,children:[o(d,{className:`h-3 w-3 ${a?`animate-spin`:``}`}),`Refresh`]})]}),i?n(`div`,{className:`flex items-center gap-1.5 py-1 text-[11px] text-foreground-subtle`,children:[o(g,{className:`h-3 w-3 animate-spin`}),`Resolving…`]}):s?o(`p`,{className:`py-1 text-[11px] text-danger`,children:`Failed to resolve linked devices.`}):u.length===0?o(`p`,{className:`py-1 text-[11px] text-foreground-subtle italic`,children:`No linked devices resolved.`}):o(`div`,{className:`flex flex-wrap gap-1`,children:u.map(e=>n(`button`,{type:`button`,onClick:()=>t(`/devices/${e.deviceId}`),className:`inline-flex cursor-pointer items-center gap-1 rounded-md border border-border bg-surface px-1.5 py-0.5 text-[11px] text-foreground max-w-full hover:bg-surface-hover hover:border-primary/50 focus:outline-none focus-visible:ring-1 focus-visible:ring-primary/50`,title:e.location??void 0,children:[o(`span`,{className:`truncate`,children:e.name}),e.location!==null&&e.location.length>0&&n(`span`,{className:`inline-flex items-center gap-0.5 shrink-0 text-[10px] text-foreground-subtle`,children:[o(_,{className:`h-2.5 w-2.5`}),e.location]})]},e.deviceId))})]})}function b(e){return[e.value,e.label,e.description].filter(e=>typeof e==`string`&&e.length>0).join(` `).toLowerCase()}function x(e,t){let n=t.trim().toLowerCase().split(/\s+/).filter(Boolean);return n.length===0?e:e.filter(e=>{let t=b(e);return n.every(e=>t.includes(e))})}function S(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 C(e){return e>=8}t();var w=`flex items-center gap-1.5 rounded-md border border-border bg-background px-2 py-1.5 focus-within:border-primary focus-within:ring-1 focus-within:ring-primary/30`,T=`block text-[11px] font-medium text-foreground mb-1 break-words`,E=`text-[10px] text-foreground-subtle mt-0.5 break-words`;function D({field:t,value:i,onChange:s,disabled:c,translationFn:l}){let d=Array.isArray(i)?i:[],p=c===!0||t.disabled===!0,g=t.maxItems!==void 0&&d.length>=t.maxItems,[_,y]=a(``),[b,C]=a(!1),[D,O]=a(0),k=e(null),A=e(null),{selectedOptions:j}=r(()=>S(t.options,d),[t.options,d]),N=r(()=>x(t.options,_),[t.options,_]),P=e=>{if(!p)if(d.includes(e))s(d.filter(t=>t!==e));else{if(t.maxItems!==void 0&&d.length>=t.maxItems)return;s([...d,e])}},F=e=>{if(e.key===`ArrowDown`)e.preventDefault(),C(!0),O(e=>N.length===0?0:(e+1)%N.length);else if(e.key===`ArrowUp`)e.preventDefault(),C(!0),O(e=>N.length===0?0:(e-1+N.length)%N.length);else if(e.key===`Enter`){e.preventDefault();let t=N[D];t&&P(t.value)}else e.key===`Escape`?C(!1):e.key===`Backspace`&&_===``&&d.length>0&&s(d.slice(0,-1))},I=M(t.label,l),L=M(t.description,l);return n(`div`,{className:`min-w-0`,children:[I!==void 0&&I!==``&&o(`label`,{className:T,children:I}),j.length>0&&o(`div`,{className:`flex flex-wrap gap-1 mb-1.5`,children:j.map(e=>n(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-primary/10 px-1.5 py-0.5 text-[11px] text-primary max-w-full`,children:[e.iconId!==void 0&&o(u,{iconId:e.iconId,size:12}),o(`span`,{className:`truncate`,children:e.label}),!p&&o(`button`,{type:`button`,className:`shrink-0 hover:text-danger`,"aria-label":`Remove ${e.label}`,onClick:()=>P(e.value),children:o(h,{className:`h-2.5 w-2.5`})})]},e.value))}),n(`div`,{className:w+(p?` opacity-50`:``),children:[o(m,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),o(`input`,{ref:k,type:`text`,role:`combobox`,"aria-expanded":b,"aria-controls":`msel-${t.key}`,className:`min-w-0 flex-1 bg-transparent text-xs text-foreground outline-none placeholder:text-foreground-disabled`,value:_,placeholder:g?`Max ${t.maxItems} selected`:t.placeholder??`Search to add…`,disabled:p,onChange:e=>{y(e.target.value),C(!0),O(0)},onFocus:()=>C(!0),onBlur:()=>{A.current=setTimeout(()=>C(!1),120)},onKeyDown:F}),o(v,{className:`h-3.5 w-3.5 shrink-0 cursor-pointer text-foreground-subtle`,onMouseDown:e=>{e.preventDefault(),A.current&&clearTimeout(A.current),C(e=>!e),k.current?.focus()}})]}),b&&!p&&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 “`,_,`”`]}):N.map((e,t)=>{let r=d.includes(e.value),i=!r&&g;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===D?`bg-primary/10`:`hover:bg-surface-hover`,i?`opacity-40 cursor-not-allowed`:`cursor-pointer`].join(` `),onMouseEnter:()=>O(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(u,{iconId:e.iconId,size:13}),o(`span`,{className:`truncate text-foreground`,children:e.label})]},e.value)})}),L&&o(`p`,{className:E,children:L})]})}t();var O=`_linkedDeviceIds`;function k(e){return e.type===`multiselect`}function A({field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,externalProbe:c,allFields:u,onAction:d}){return k(e)&&C(e.options.length)?l(e,t,u)?o(D,{field:e,value:t[e.key],onChange:t=>n(e.key,t),disabled:r,translationFn:i}):null:o(s,{field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,externalProbe:c,allFields:u,onAction:d})}function j(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function M(e,t){if(e!==void 0)return t&&j(e)?t(e):e}function N({section:e,values:t,onChange:r,disabled:c,translationFn:u,onTestField:d,probeResults:f,onAction:p,deviceId:m}){let[h,g]=a(e.defaultCollapsed??!1),_=e.style===`accordion`;if(e.fields.reduce((n,r)=>n+ +!!l(r,t,e.fields),0)===0)return null;let v=e.fields.some(e=>`key`in e&&e.key===O),b=e.fields,x=v?1:e.columns??2,S=x===1?`grid-cols-1`:x===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:x===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`,C=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:[!(C!==void 0||!e.title&&!e.description)&&n(`div`,{className:[`flex items-center justify-between mb-2`,_?`cursor-pointer`:``].join(` `),onClick:_?()=>g(e=>!e):void 0,children:[n(`div`,{children:[e.title&&o(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:M(e.title,u)}),e.description&&o(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:M(e.description,u)})]}),_&&o(`span`,{className:`text-foreground-subtle text-xs ml-2`,children:h?`▸`:`▾`})]}),!h&&(C===void 0?n(i,{children:[o(`div`,{className:`grid ${S} gap-x-3 gap-y-2.5`,children:b.map(n=>o(A,{field:n,values:t,onChange:r,disabled:c,translationFn:u,onTestField:d,externalProbe:f?.[n.key],allFields:e.fields,onAction:p},n.key))}),v&&m!==void 0&&o(y,{deviceId:m})]}):o(s,{field:C,values:t,onChange:r,disabled:c,translationFn:u,onTestField:d,externalProbe:f?.[C.key],allFields:e.fields,onAction:p},C.key))]})}function P({schema:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,probeResults:s,onClearProbe:c,onAction:l,deviceId:u}){let d=(e,r)=>{n({...t,[e]:r}),c?.(e)};return o(`div`,{className:`space-y-4`,children:e.sections.map((e,n)=>o(N,{section:e,values:t,onChange:d,disabled:r,translationFn:i,onTestField:a,probeResults:s,onAction:l,deviceId:u},`${e.id}-${n}`))})}export{P as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Q as e,S as t,W as n,a as r,b as i,o as a,q as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as c}from"./player-overlays-CoerrptV.js";import{Bs as l,Gs as u,Hs as d,Is as f,It as p,Jr as m,Js as h,Ks as g,Ls as _,Mn as v,Rs as y,S as b,Us as x,Vs as S,Ws as ee,Xs as C,Ys as w,f as T,jn as E,nt as te,p as D,qs as O,sn as k,x as A,zs as j}from"./src-BLs3JnCT.js";import{c as M,d as N,l as P,u as F}from"./src-71h6VhtY.js";import{t as I}from"./circle-check-big-Ckfr2nS1.js";import{t as ne}from"./copy-HKHON4wK.js";import{t as re}from"./key-round-D15z3uvv.js";import{t as ie}from"./pencil-DRBv7Lne.js";import{t as ae}from"./plus-Bn6mAUY6.js";import{t as L}from"./shield-alert-4RXP2qu7.js";import{A as oe,B as se,D as R,J as z,L as ce,T as le,d as B,l as V,n as H,o as U,r as W,w as G,z as ue}from"./index-YqMXmKC_.js";import{t as K}from"./AdminPage-CiKtOLQm.js";import{t as de}from"./AdminTabs-DUSbhirs.js";import{t as fe}from"./AddonCollectionPage-DJd0G561.js";import{t as pe}from"./addon-display-names-DvSEQty-.js";var me=z(`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`}]]),he=z(`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`}]]),ge=z(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),_e=z(`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`}]]),ve=z(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]);e();function ye({userId:e,username:n,onClose:r}){let o=a(),c=k(),u=l({userId:e}),d=u.data,f=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),m=j({onSuccess:()=>{f(),r()}}),h=u.isLoading?`loading`:d?.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(W,{className:`h-4 w-4`})})]}),t(`div`,{className:`p-4 space-y-4`,children:[h===`loading`&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(G,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),h===`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(le,{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.`})]})]}),h===`enrolled`&&d&&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(I,{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`,` `,d.confirmedAt?new Date(d.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(p,{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`})&&m.mutate({userId:e})},disabled:m.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:[m.isPending?s(G,{className:`h-3 w-3 animate-spin`}):s(W,{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 be({scopes:e,isAdmin:n,invalidReason:a}){let o=c(),l=r({queryKey:[`auth`,`previewScope`,e,n],enabled:a===null,queryFn:()=>o.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:n})}),{data:u}=m({projection:`slim`}),d=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(L,{className:`h-3 w-3 shrink-0`}),a]})});if(l.isLoading)return t(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface p-3 text-[11px] text-foreground-subtle`,children:[s(G,{className:`h-3 w-3 animate-spin`}),`Resolving…`]});if(l.isError||!l.data)return s(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:s(`p`,{className:`text-[11px] text-danger`,children:`Could not resolve this grant set. Saving is still allowed — the server enforces the same rules either way.`})});let f=l.data;return s(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:f.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:oe,label:`Devices they can see`,count:f.device.view.deviceCount,all:f.device.view.all,total:d}),s(q,{icon:ie,label:`Devices they can operate`,count:f.device.create.deviceCount,all:f.device.create.all,total:d}),s(q,{icon:U,label:`Devices they can delete`,count:f.device.delete.deviceCount,all:f.device.delete.all,total:d}),t(`div`,{className:`border-t border-border pt-2 text-[10px] text-foreground-subtle`,children:[`System access: `,f.system.length===0?`none`:f.system.join(`, `),f.capabilities.length>0&&t(i,{children:[` · Extra capabilities: `,f.capabilities.map(e=>e.name).join(`, `)]}),f.addons.length>0&&t(i,{children:[` · Addons: `,f.addons.map(e=>e.name).join(`, `)]})]}),f.device.view.deviceCount===0&&s(`p`,{className:`text-[10px] text-warning`,children:`This user will not be able to see any device.`})]})})}function xe(e){let t=F(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 Se(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:P({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function Ce({user:e,onClose:r,onSubmit:a,submitting:c,callerScopes:l}){let u=n(()=>xe(e.scopes??[]),[e.scopes]),[d,f]=o(u),[p,m]=o(u.mode===`advanced`),h=n(()=>Se(d),[d]),g=!e.isAdmin&&d.mode===`role`&&d.roleId===null,_=n(()=>e.isAdmin?null:d.mode===`role`&&d.roleId===null?`Pick what this user can do to see the result.`:D(h),[e.isAdmin,d.mode,d.roleId,h]),v=e=>f({...d,...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(W,{className:`h-4 w-4`})})]}),t(`div`,{className:`min-h-0 flex-1 space-y-4 overflow-y-auto px-4 py-4`,children:[g&&t(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[s(L,{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:M.map(e=>{let n=d.mode===`role`&&d.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:()=>v({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(!p){f({...d,mode:`advanced`,advancedScopes:h}),m(!0);return}m(!1),f(xe(d.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(p?ue:ce,{className:`h-3 w-3`}),`Advanced — edit raw grants`]}),p&&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(T,{value:d.advancedScopes,onChange:e=>v({mode:`advanced`,advancedScopes:e}),clampToParent:l,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.`]})})]})]}),d.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(A,{value:d.selector,onChange:e=>v({selector:e}),includeLinked:d.includeLinked,onIncludeLinkedChange:e=>v({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:d.mode===`role`?`3 · Result`:`2 · Result`}),s(be,{scopes:h,isAdmin:e.isAdmin,invalidReason:_})]})]}),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([...h]),disabled: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:c?s(G,{className:`h-3 w-3 animate-spin`}):`Save access`})]})]})})}e();function we(){let e=a(),{user:n}=H(),[r,i]=o(!1),[c,l]=o(``),[d,f]=o(``),[p,m]=o(!1),[h,g]=o(null),{data:v,isLoading:b,isError:x}=ee(),S=k(),T=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),E=_({onSuccess:()=>{T(),i(!1),l(``),f(``),m(!1),g(null)},onError:e=>{g(e instanceof Error?e.message:`Failed to create user`)}}),D=y({onSuccess:T}),O=C({onSuccess:T}),A=u({onSuccess:T}),j=w({onSuccess:()=>{T(),N(null)}}),[M,N]=o(null),[P,F]=o(null),I=v??[];async function ne(e){await S({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&D.mutate({id:e.id})}async function re(e){let t=window.prompt(`New password for "${e.username}":`);if(t){if(t.length<8){window.alert(`Password must be at least 8 characters.`);return}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 ie(e,t){t!==e.isAdmin&&O.mutate({id:e.id,isAdmin:t})}function L(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(ae,{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(W,{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:d,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:p,onChange:e=>m(e.target.checked),className:`rounded border-border focus:ring-primary`}),s(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),h&&s(`p`,{className:`text-[10px] text-danger`,children:h}),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:d,isAdmin:p}),disabled:E.isPending||!c||!d,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&&I.length===0&&s(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>D.isPending&&D.variables?.id===e.id||O.isPending&&O.variables?.id===e.id||A.isPending&&A.variables?.id===e.id;return s(te,{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=>ie(n,e.target.checked),disabled:e(n),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),s(`span`,{className:n.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:n.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Access`,render:e=>e.isAdmin?s(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`everything (admin)`}):t(`button`,{onClick:()=>N(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] hover:bg-foreground-subtle/10`,title:`Configure access`,children:[s(B,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(Te,{scopes:e.scopes??[]})]})},{key:`createdAt`,header:`Created`,render:e=>s(`span`,{className:`text-foreground-subtle`,children:L(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:r=>{let i=e(r);return t(`div`,{className:`flex items-center justify-end gap-1`,children:[r.id!==n?.id&&r.totpEnabled&&t(`button`,{onClick:()=>F(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[s(V,{className:`h-3 w-3`}),`Remove 2FA`]}),t(`button`,{onClick:()=>re(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(ge,{className:`h-3 w-3`}),`Reset password`]}),t(`button`,{onClick:()=>ne(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(G,{className:`h-3 w-3 animate-spin`}):s(U,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:I,rowKey:e=>e.id,minWidthPx:560})})(),P&&s(ye,{userId:P.id,username:P.username,onClose:()=>F(null)}),M&&s(Ee,{user:M,onClose:()=>N(null),onSubmit:e=>j.mutate({userId:M.id,scopes:e}),submitting:j.isPending})]})}function Te({scopes:e}){if(e.length===0)return s(`span`,{className:`font-medium text-warning`,children:`No access`});let n=F(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:N(n.roleId).label}),` ·`,` `,b(n.selector)]})}function Ee(e){let{user:t}=H(),n=t?.isAdmin===!0;return s(Ce,{...e,callerScopes:n?null:t?.scopes??[]})}e();var De=`bg-primary/10 text-primary`,Oe=`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 ke(e){return e?e===`*`?`*`:e.join(`, `):``}function Ae(){let e=a(),r=k(),{data:i,isLoading:c}=S(),{data:l}=ee(),u=n(()=>i??[],[i]),d=n(()=>l??[],[l]),p=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),m=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[_,v]=o(!1),[y,b]=o(null),x=g({onSuccess:p}),C=f({onSuccess:({token:e,record:t})=>{m(),v(!1),b({token:e,label:t.name})}}),w=h({onSuccess:m}),T=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`})&&x.mutate({id:e})},E=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&w.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:()=>v(!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:d.length===0,title:d.length===0?`Create a user first`:`Issue a scoped token`,children:[s(B,{className:`h-3.5 w-3.5`}),`New token`]})]}),t(je,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[d.length===0&&s(Ne,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),d.map(e=>s(Fe,{userId:e.id,username:e.username,onRevoke:(e,t)=>{E(e,t)},revokePending:w.isPending,revokeId:w.variables?.id},e.id))]}),u.length>0&&s(je,{title:`Legacy API keys`,subtitle:`${u.length} pre-existing — revoke only`,children:s(Pe,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:u.map(e=>{let n=!!e.isAdmin,r=x.isPending&&x.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?De:Oe}`,children:n?`admin`:`regular`})}),t(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:ke(e.allowedProviders)||`all`}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children: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:()=>{T(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(G,{className:`h-3 w-3 animate-spin`}):s(U,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),c&&s(Me,{}),_&&s(Ie,{users:d.map(e=>({id:e.id,username:e.username})),onClose:()=>v(!1),onSubmit:e=>C.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:C.isPending}),y&&s(Le,{token:y.token,label:y.label,onClose:()=>b(null)})]})}function je({title:e,subtitle:n,children:r}){return t(`div`,{className:`space-y-2`,children:[t(`div`,{className:`flex items-baseline justify-between`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&s(`span`,{className:`text-[10px] text-foreground-subtle`,children:n})]}),r]})}function Me(){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 Ne({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 Pe({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 Fe({userId:e,username:n,onRevoke:r,revokePending:i,revokeId:a}){let{data:o,isLoading:c}=x({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(Pe,{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`?`[${b(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(G,{className:`h-3 w-3 animate-spin`}):s(U,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function Ie({users:e,onClose:n,onSubmit:r,submitting:i}){let{user:a}=H(),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`]}]),[h,g]=o(``),_=D(p),v=l!==``&&d.trim().length>0&&p.length>0&&_===null&&!i;return t(Re,{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(T,{value:p,onChange:m,clampToParent:c}),_&&s(`p`,{className:`mt-1 text-[10px] text-danger`,children:_})]}),s(Y,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:s(`input`,{type:`number`,min:1,value:h,onChange:e=>g(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(ze,{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(h,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;r({userId:l,name:d.trim(),scopes:p,expiresAt:t})},disabled:!v,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(G,{className:`h-3.5 w-3.5 animate-spin`}):s(B,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function Le({token:e,label:n,onClose:r}){let[i,a]=o(!1),c=async()=>{try{await navigator.clipboard.writeText(e),a(!0)}catch{}};return t(Re,{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(ze,{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(se,{className:`h-3.5 w-3.5 text-primary`}):s(ne,{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 Re({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(W,{className:`h-4 w-4`})})]}),s(`div`,{className:`p-4`,children:r})]})})}function ze({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 Be(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 Ve(){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 He({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 Ue({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 We(){let e=a(),r=k(),{data:i,isLoading:o}=d(),c=n(()=>i??[],[i]),l=O({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:_e,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(Ve,{}),!o&&c.length===0&&s(He,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!o&&c.length>0&&s(Ue,{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:Be(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(G,{className:`h-3 w-3 animate-spin`}):s(U,{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 Ge(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:he,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:R,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:R,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:B,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Ke(){let e=v({capName:Q[0].capName},{refetchInterval:Z}),t=v({capName:Q[1].capName},{refetchInterval:Z}),r=E(void 0,{refetchInterval:Z}),i=n(()=>pe(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(fe,{title:$.title,subtitle:$.subtitle,pageIcon:B,itemIcon:B,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(qe,{addonId:e.addonId})})}function qe({addonId:e}){let n=Ge(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(me,{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(le,{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 Je(){return s(`div`,{className:`flex flex-col p-4`,children:s(de,{tabs:[{id:`users`,label:`Users`,icon:ve,content:s(we,{})},{id:`api-keys`,label:`Tokens`,icon:re,content:s(Ae,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:_e,content:s(We,{})},{id:`authentication`,label:`Authentication`,icon:B,content:s(Ke,{})}]})})}export{Je as IdentityPage};
|
|
1
|
+
import{Q as e,S as t,W as n,a as r,b as i,o as a,q as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as c}from"./player-overlays-DVo2KR_t.js";import{Bs as l,Gs as u,Hs as d,Is as f,It as p,Jr as m,Js as h,Ks as g,Ls as _,Mn as v,Rs as y,S as b,Us as x,Vs as S,Ws as ee,Xs as C,Ys as w,f as T,jn as E,nt as te,p as D,qs as O,sn as k,x as A,zs as j}from"./src-CLAf92SY.js";import{c as M,d as N,l as P,u as F}from"./src-e8CzBBHU.js";import{t as I}from"./circle-check-big-UUTDxFnK.js";import{t as ne}from"./copy-Clr1lTje.js";import{t as re}from"./key-round-DsG9cNQv.js";import{t as ie}from"./pencil-DICsE4Gy.js";import{t as ae}from"./plus-BhEMDQtU.js";import{t as L}from"./shield-alert-DvcWv6qf.js";import{A as oe,B as se,D as R,J as z,L as ce,T as le,d as B,l as V,n as H,o as U,r as W,w as G,z as ue}from"./index-DL2yqdrc.js";import{t as K}from"./AdminPage-CiKtOLQm.js";import{t as de}from"./AdminTabs-B4GGMxRz.js";import{t as fe}from"./AddonCollectionPage-DwDJOFcL.js";import{t as pe}from"./addon-display-names-DvSEQty-.js";var me=z(`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`}]]),he=z(`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`}]]),ge=z(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),_e=z(`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`}]]),ve=z(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]);e();function ye({userId:e,username:n,onClose:r}){let o=a(),c=k(),u=l({userId:e}),d=u.data,f=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),m=j({onSuccess:()=>{f(),r()}}),h=u.isLoading?`loading`:d?.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(W,{className:`h-4 w-4`})})]}),t(`div`,{className:`p-4 space-y-4`,children:[h===`loading`&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(G,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),h===`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(le,{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.`})]})]}),h===`enrolled`&&d&&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(I,{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`,` `,d.confirmedAt?new Date(d.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(p,{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`})&&m.mutate({userId:e})},disabled:m.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:[m.isPending?s(G,{className:`h-3 w-3 animate-spin`}):s(W,{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 be({scopes:e,isAdmin:n,invalidReason:a}){let o=c(),l=r({queryKey:[`auth`,`previewScope`,e,n],enabled:a===null,queryFn:()=>o.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:n})}),{data:u}=m({projection:`slim`}),d=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(L,{className:`h-3 w-3 shrink-0`}),a]})});if(l.isLoading)return t(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface p-3 text-[11px] text-foreground-subtle`,children:[s(G,{className:`h-3 w-3 animate-spin`}),`Resolving…`]});if(l.isError||!l.data)return s(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:s(`p`,{className:`text-[11px] text-danger`,children:`Could not resolve this grant set. Saving is still allowed — the server enforces the same rules either way.`})});let f=l.data;return s(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:f.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:oe,label:`Devices they can see`,count:f.device.view.deviceCount,all:f.device.view.all,total:d}),s(q,{icon:ie,label:`Devices they can operate`,count:f.device.create.deviceCount,all:f.device.create.all,total:d}),s(q,{icon:U,label:`Devices they can delete`,count:f.device.delete.deviceCount,all:f.device.delete.all,total:d}),t(`div`,{className:`border-t border-border pt-2 text-[10px] text-foreground-subtle`,children:[`System access: `,f.system.length===0?`none`:f.system.join(`, `),f.capabilities.length>0&&t(i,{children:[` · Extra capabilities: `,f.capabilities.map(e=>e.name).join(`, `)]}),f.addons.length>0&&t(i,{children:[` · Addons: `,f.addons.map(e=>e.name).join(`, `)]})]}),f.device.view.deviceCount===0&&s(`p`,{className:`text-[10px] text-warning`,children:`This user will not be able to see any device.`})]})})}function xe(e){let t=F(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 Se(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:P({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function Ce({user:e,onClose:r,onSubmit:a,submitting:c,callerScopes:l}){let u=n(()=>xe(e.scopes??[]),[e.scopes]),[d,f]=o(u),[p,m]=o(u.mode===`advanced`),h=n(()=>Se(d),[d]),g=!e.isAdmin&&d.mode===`role`&&d.roleId===null,_=n(()=>e.isAdmin?null:d.mode===`role`&&d.roleId===null?`Pick what this user can do to see the result.`:D(h),[e.isAdmin,d.mode,d.roleId,h]),v=e=>f({...d,...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(W,{className:`h-4 w-4`})})]}),t(`div`,{className:`min-h-0 flex-1 space-y-4 overflow-y-auto px-4 py-4`,children:[g&&t(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[s(L,{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:M.map(e=>{let n=d.mode===`role`&&d.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:()=>v({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(!p){f({...d,mode:`advanced`,advancedScopes:h}),m(!0);return}m(!1),f(xe(d.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(p?ue:ce,{className:`h-3 w-3`}),`Advanced — edit raw grants`]}),p&&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(T,{value:d.advancedScopes,onChange:e=>v({mode:`advanced`,advancedScopes:e}),clampToParent:l,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.`]})})]})]}),d.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(A,{value:d.selector,onChange:e=>v({selector:e}),includeLinked:d.includeLinked,onIncludeLinkedChange:e=>v({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:d.mode===`role`?`3 · Result`:`2 · Result`}),s(be,{scopes:h,isAdmin:e.isAdmin,invalidReason:_})]})]}),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([...h]),disabled: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:c?s(G,{className:`h-3 w-3 animate-spin`}):`Save access`})]})]})})}e();function we(){let e=a(),{user:n}=H(),[r,i]=o(!1),[c,l]=o(``),[d,f]=o(``),[p,m]=o(!1),[h,g]=o(null),{data:v,isLoading:b,isError:x}=ee(),S=k(),T=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),E=_({onSuccess:()=>{T(),i(!1),l(``),f(``),m(!1),g(null)},onError:e=>{g(e instanceof Error?e.message:`Failed to create user`)}}),D=y({onSuccess:T}),O=C({onSuccess:T}),A=u({onSuccess:T}),j=w({onSuccess:()=>{T(),N(null)}}),[M,N]=o(null),[P,F]=o(null),I=v??[];async function ne(e){await S({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&D.mutate({id:e.id})}async function re(e){let t=window.prompt(`New password for "${e.username}":`);if(t){if(t.length<8){window.alert(`Password must be at least 8 characters.`);return}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 ie(e,t){t!==e.isAdmin&&O.mutate({id:e.id,isAdmin:t})}function L(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(ae,{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(W,{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:d,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:p,onChange:e=>m(e.target.checked),className:`rounded border-border focus:ring-primary`}),s(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),h&&s(`p`,{className:`text-[10px] text-danger`,children:h}),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:d,isAdmin:p}),disabled:E.isPending||!c||!d,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&&I.length===0&&s(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>D.isPending&&D.variables?.id===e.id||O.isPending&&O.variables?.id===e.id||A.isPending&&A.variables?.id===e.id;return s(te,{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=>ie(n,e.target.checked),disabled:e(n),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),s(`span`,{className:n.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:n.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Access`,render:e=>e.isAdmin?s(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`everything (admin)`}):t(`button`,{onClick:()=>N(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] hover:bg-foreground-subtle/10`,title:`Configure access`,children:[s(B,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(Te,{scopes:e.scopes??[]})]})},{key:`createdAt`,header:`Created`,render:e=>s(`span`,{className:`text-foreground-subtle`,children:L(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:r=>{let i=e(r);return t(`div`,{className:`flex items-center justify-end gap-1`,children:[r.id!==n?.id&&r.totpEnabled&&t(`button`,{onClick:()=>F(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[s(V,{className:`h-3 w-3`}),`Remove 2FA`]}),t(`button`,{onClick:()=>re(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(ge,{className:`h-3 w-3`}),`Reset password`]}),t(`button`,{onClick:()=>ne(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(G,{className:`h-3 w-3 animate-spin`}):s(U,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:I,rowKey:e=>e.id,minWidthPx:560})})(),P&&s(ye,{userId:P.id,username:P.username,onClose:()=>F(null)}),M&&s(Ee,{user:M,onClose:()=>N(null),onSubmit:e=>j.mutate({userId:M.id,scopes:e}),submitting:j.isPending})]})}function Te({scopes:e}){if(e.length===0)return s(`span`,{className:`font-medium text-warning`,children:`No access`});let n=F(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:N(n.roleId).label}),` ·`,` `,b(n.selector)]})}function Ee(e){let{user:t}=H(),n=t?.isAdmin===!0;return s(Ce,{...e,callerScopes:n?null:t?.scopes??[]})}e();var De=`bg-primary/10 text-primary`,Oe=`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 ke(e){return e?e===`*`?`*`:e.join(`, `):``}function Ae(){let e=a(),r=k(),{data:i,isLoading:c}=S(),{data:l}=ee(),u=n(()=>i??[],[i]),d=n(()=>l??[],[l]),p=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),m=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[_,v]=o(!1),[y,b]=o(null),x=g({onSuccess:p}),C=f({onSuccess:({token:e,record:t})=>{m(),v(!1),b({token:e,label:t.name})}}),w=h({onSuccess:m}),T=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`})&&x.mutate({id:e})},E=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&w.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:()=>v(!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:d.length===0,title:d.length===0?`Create a user first`:`Issue a scoped token`,children:[s(B,{className:`h-3.5 w-3.5`}),`New token`]})]}),t(je,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[d.length===0&&s(Ne,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),d.map(e=>s(Fe,{userId:e.id,username:e.username,onRevoke:(e,t)=>{E(e,t)},revokePending:w.isPending,revokeId:w.variables?.id},e.id))]}),u.length>0&&s(je,{title:`Legacy API keys`,subtitle:`${u.length} pre-existing — revoke only`,children:s(Pe,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:u.map(e=>{let n=!!e.isAdmin,r=x.isPending&&x.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?De:Oe}`,children:n?`admin`:`regular`})}),t(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:ke(e.allowedProviders)||`all`}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children: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:()=>{T(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(G,{className:`h-3 w-3 animate-spin`}):s(U,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),c&&s(Me,{}),_&&s(Ie,{users:d.map(e=>({id:e.id,username:e.username})),onClose:()=>v(!1),onSubmit:e=>C.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:C.isPending}),y&&s(Le,{token:y.token,label:y.label,onClose:()=>b(null)})]})}function je({title:e,subtitle:n,children:r}){return t(`div`,{className:`space-y-2`,children:[t(`div`,{className:`flex items-baseline justify-between`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&s(`span`,{className:`text-[10px] text-foreground-subtle`,children:n})]}),r]})}function Me(){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 Ne({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 Pe({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 Fe({userId:e,username:n,onRevoke:r,revokePending:i,revokeId:a}){let{data:o,isLoading:c}=x({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(Pe,{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`?`[${b(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(G,{className:`h-3 w-3 animate-spin`}):s(U,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function Ie({users:e,onClose:n,onSubmit:r,submitting:i}){let{user:a}=H(),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`]}]),[h,g]=o(``),_=D(p),v=l!==``&&d.trim().length>0&&p.length>0&&_===null&&!i;return t(Re,{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(T,{value:p,onChange:m,clampToParent:c}),_&&s(`p`,{className:`mt-1 text-[10px] text-danger`,children:_})]}),s(Y,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:s(`input`,{type:`number`,min:1,value:h,onChange:e=>g(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(ze,{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(h,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;r({userId:l,name:d.trim(),scopes:p,expiresAt:t})},disabled:!v,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(G,{className:`h-3.5 w-3.5 animate-spin`}):s(B,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function Le({token:e,label:n,onClose:r}){let[i,a]=o(!1),c=async()=>{try{await navigator.clipboard.writeText(e),a(!0)}catch{}};return t(Re,{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(ze,{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(se,{className:`h-3.5 w-3.5 text-primary`}):s(ne,{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 Re({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(W,{className:`h-4 w-4`})})]}),s(`div`,{className:`p-4`,children:r})]})})}function ze({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 Be(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 Ve(){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 He({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 Ue({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 We(){let e=a(),r=k(),{data:i,isLoading:o}=d(),c=n(()=>i??[],[i]),l=O({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:_e,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(Ve,{}),!o&&c.length===0&&s(He,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!o&&c.length>0&&s(Ue,{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:Be(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(G,{className:`h-3 w-3 animate-spin`}):s(U,{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 Ge(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:he,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:R,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:R,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:B,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Ke(){let e=v({capName:Q[0].capName},{refetchInterval:Z}),t=v({capName:Q[1].capName},{refetchInterval:Z}),r=E(void 0,{refetchInterval:Z}),i=n(()=>pe(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(fe,{title:$.title,subtitle:$.subtitle,pageIcon:B,itemIcon:B,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(qe,{addonId:e.addonId})})}function qe({addonId:e}){let n=Ge(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(me,{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(le,{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 Je(){return s(`div`,{className:`flex flex-col p-4`,children:s(de,{tabs:[{id:`users`,label:`Users`,icon:ve,content:s(we,{})},{id:`api-keys`,label:`Tokens`,icon:re,content:s(Ae,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:_e,content:s(We,{})},{id:`authentication`,label:`Authentication`,icon:B,content:s(Ke,{})}]})})}export{Je as IdentityPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,b as a,o,q as s,x as c,z as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as u,at as d}from"./player-overlays-CoerrptV.js";import{Ai as f,Ar as p,At as m,Br as h,Di as g,Dr as _,Ei as v,Fr as y,In as b,Jr as x,L as S,Mi as C,Nr as w,Oi as ee,Or as T,P as E,Pi as D,Pr as O,Qr as te,T as k,Ur as A,Ut as j,Y as M,bn as ne,ei as re,it as ie,jr as N,kr as P,st as F,ui as I,w as L,yn as R,zr as z}from"./src-BLs3JnCT.js";import{gt as B}from"./src-71h6VhtY.js";import{t as ae}from"./ProviderIcon-C8_JXI4r.js";import{t as V}from"./circle-x-DFeAzRym.js";import{t as oe}from"./plus-Bn6mAUY6.js";import{i as se,n as ce,r as H,t as le}from"./ScanNetworkModal-Ds9Ujyss.js";import{t as ue}from"./refresh-cw-DUVLNAWK.js";import{t as U}from"./rotate-cw-CQFP4L_-.js";import{t as W}from"./wifi-CEFpiBjp.js";import{A as de,B as fe,F as G,J as K,K as pe,L as me,Q as he,X as ge,Z as _e,a as q,f as ve,j as ye,m as be,o as xe,r as Se,t as Ce,w as J,z as we}from"./index-YqMXmKC_.js";import{t as Y}from"./FormBuilder-CpdMn4hO.js";import{t as Te}from"./NodeAddonsSettingsPanel-BGnTKNTC.js";var Ee=K(`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 De(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...De(n.fields));return t}function Oe(t,n,r){let[a,o]=s(`idle`),[c,l]=s({}),u=i(()=>{let e=[];for(let n of t.sections)e.push(...De(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 ke(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(...ke(n.fields));return t}function Ae(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function je(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){je(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 Me({open:t,integrationId:n,addonId:a,onClose:u}){let{t:d}=Ce(),f=o(),[p,m]=s({}),[h,g]=s(!1),[_,v]=s(null),[y,b]=s(X),x=te({addonId:a},{enabled:t}),S=x.data?.deviceType??null,C=A({addonId:a,type:S??B.Camera},{enabled:t&&x.isSuccess&&S!==null}),w=C.data??null;l(()=>{t&&(m(w?je(w.sections.flatMap(e=>e.fields)):{}),b(X()),g(!1),v(null))},[t,n,w]);let ee=i(()=>({...p,_probeRequestId:y}),[p,y]),T=O({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),E=I(),D=e(async(e,t)=>{g(!0);let n=await E.mutateAsync({addonId:a,type:S??B.Camera,key:e,value:t,formValues:ee});return n.status===`ok`&&n.suggestedValues&&m(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Ae(e[i])&&!Ae(a)&&(r[i]=a,t=!0);return t?r:e}),n},[E,a,ee,S]),{testAllStatus:k,hasProbeFields:j,probeResults:ne,handleTestAll:re,clearProbeResult:ie}=Oe(w??{sections:[]},p,D);async function N(e){v(null);try{await T.mutateAsync({addonId:a,type:S??B.Camera,config:p,integrationId:n}),e?m(w?je(w.sections.flatMap(e=>e.fields)):{}):u()}catch(e){v(e instanceof Error?e.message:String(e))}}if(!t)return null;let P=ke((w?.sections??[]).flatMap(e=>e.fields)).filter(e=>Ae(p[e])),F=P.length===0,L=x.isLoading||S!==null&&C.isLoading,R=x.isError||x.isSuccess&&S===null||C.isError||C.isSuccess&&w===null;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),r(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:d(`integrations.addDevice`)}),c(`button`,{onClick:u,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:c(Se,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:L?c(`div`,{className:`flex items-center justify-center py-8`,children:c(J,{className:`h-5 w-5 animate-spin text-primary`})}):R?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[c(q,{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(Y,{schema:w,values:p,onChange:m,onTestField:D,probeResults:ne,onClearProbe:ie})}),!R&&!L&&r(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[r(`button`,{type:`button`,onClick:()=>g(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(be,{className:`h-3.5 w-3.5`}),`Test logs`,c(`span`,{className:`font-mono text-[9px] opacity-60`,children:y.slice(0,14)})]}),c(we,{className:`h-3.5 w-3.5 transition-transform ${h?`rotate-180`:``}`})]}),h&&c(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:c(M,{addonId:a,requestId:y,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!R&&!L&&(_||P.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(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:_||`Required: ${P.join(`, `)}`})]})}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:u,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:d(`integrations.cancel`)}),!R&&j&&r(`button`,{type:`button`,onClick:re,disabled:k===`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:[k===`testing`?c(J,{className:`h-3.5 w-3.5 animate-spin`}):c(W,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:()=>N(!0),disabled:R||!F||T.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:d(`integrations.saveAndNew`)}),c(`button`,{onClick:()=>N(!1),disabled:R||!F||T.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:T.isPending?d(`integrations.saving`):d(`integrations.save`)})]})]})]})]})}var Ne=1500;function Z({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=Ce(),o=_(),s=(p({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Ne:!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 m=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(q,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):s.state===`cancelled`?c(V,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):c(G,{className:`h-3.5 w-3.5 text-primary shrink-0`}),c(`p`,{className:`text-[11px] text-foreground`,children:m}),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 Pe(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`,Fe={id:Q,label:`Devices`,isDefault:!0},Ie=2e4,$=100;function Le({addonId:n,integrationId:i,onClose:a}){let{t:o}=Ce(),[u,d]=s(new Set),[f,p]=s(new Set),[m,h]=s(new Map),[g,_]=s(null),{data:v}=ee(),y=(v??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[b,x]=s(!0),C=T({addonId:n,integrationId:i}).data?.filters,D=C&&C.length>0?C:[Fe],[O,te]=s(D.find(e=>e.isDefault)?.id??(D.some(e=>e.id===Q)?Q:D[0].id)),k=O!==Q,A=N(),j=P({addonId:n,integrationId:i,page:1,pageSize:Ie,filter:O}),M=j.refetch,ne=A.mutate,re=e(()=>{ne({addonId:n,integrationId:i},{onSettled:()=>{M()}})},[ne,n,i,M]),ie=t(null);l(()=>{let e=`${n}::${i}`;ie.current===e||j.isLoading||(ie.current=e,(j.data?.candidates.length??0)===0&&re())},[n,i,j.isLoading,j.data,re]);let F=A.isPending,I=A.isError?A.error instanceof Error?A.error.message:String(A.error):null,R=typeof A.data?.lastError==`string`&&A.data.lastError.length>0?A.data.lastError:null,z=j.data?.candidates??[],B=j.isError?j.error instanceof Error?j.error.message:String(j.error):null,ae=w(),[V,oe]=s(null),se=e(e=>{e.alreadyAdopted||d(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),ce=e(e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),H=e((e,t)=>{h(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})},[]),le=e(e=>{let t={};for(let n of e){let e=m.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[m]),ue=e(async()=>{_(null);let e=[...u];if(e.length!==0)try{let t=le(e),{jobId:r}=await ae.mutateAsync({addonId:n,integrationId:i,filter:O,childNativeIds:e,...t?{perCandidate:t}:{},...y?{importLocations:b}:{}});oe(r),d(new Set),h(new Map)}catch(e){_(e instanceof Error?e.message:String(e))}},[u,le,ae,n,i,O,y,b]),W=t(null),de=e(()=>{V===null||W.current===V||(W.current=V,M())},[V,M]),G=e(e=>{te(e),d(new Set),p(new Set),h(new Map),_(null)},[]),K=u.size;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:o(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),c(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:o(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),r(`div`,{className:`flex items-center gap-3 shrink-0`,children:[y&&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:b,onChange:e=>x(e.target.checked),className:`accent-primary`}),o(`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(Se,{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:[(I??B??R)&&z.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(q,{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:o(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),c(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:I??B??R})]})]})}),D.length>1&&c(Re,{filters:D,activeFilter:O,onSelect:G}),c(`div`,{className:`flex-1 min-h-0`,children:c(L,{mode:`generic`,items:z,pageSize:$,getKey:e=>e.childNativeId,getSearchText:Pe,getFilterType:e=>e.type,filterOptions:E(),filterLabel:o(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:j.isLoading||F&&z.length===0,searchPlaceholder:o(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(I??B??R)&&z.length===0?``:o(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:re,disabled:F,title:o(`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(U,{className:`h-3.5 w-3.5 ${F?`animate-spin`:``}`}),o(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:o(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>c(ze,{candidate:e,expandable:!k,expanded:f.has(e.childNativeId),onToggleExpand:()=>ce(e.childNativeId),adoptedLabel:o(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:o(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=S(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:()=>se(e),disabled:e.alreadyAdopted,"aria-label":u.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${u.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:u.has(e.childNativeId)&&c(fe,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!k&&f.has(e.childNativeId),renderExpanded:k?void 0:e=>c(Be,{candidate:e,hiddenChildIds:m.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>H(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:u.has(e.childNativeId)?`bg-primary/5`:``})})]}),g&&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(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:g})]})}),V!==null&&c(Z,{addonId:n,integrationId:i,jobId:V,onFinished:de}),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:o(`integrations.cancel`,{defaultValue:`Cancel`})}),r(`button`,{onClick:ue,disabled:K===0||ae.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:[ae.isPending&&c(J,{className:`h-3.5 w-3.5 animate-spin`}),o(`integrations.addSelected`,{defaultValue:`Add selected`}),K>0?` (${K})`:``]})]})]})]})]})}function Re({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 ze({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?we:me,{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 Be({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?ye:de,{className:`h-3 w-3`})})]},e.childNativeId)})})}n();function Ve(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...Ve(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function He(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>Ve(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Ue(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 We({integrationId:e,addonId:t,name:n,kind:a,mode:s,brokerKind:l,canTest:u=!1,trpc:d,onClose:p}){let{t:m}=Ce(),h=o(),{data:g,isLoading:_}=f({id:e},{enabled:s===`account`||s===`broker`}),v=i(()=>{let e=g?.brokerId;return typeof e==`string`?e:null},[g]),{data:y,isLoading:b}=R({addonId:t,nodeId:`hub`},{enabled:s===`account`}),x=i(()=>y?Ue(y):null,[y]),S=C(),w=t=>{S.mutate({id:e,settings:t},{onSuccess:()=>{h.invalidateQueries(),p()}})};return c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:p,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:[m(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),c(`button`,{onClick:p,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":m(`common.close`,{defaultValue:`Close`}),children:c(Se,{className:`h-4 w-4`})})]}),s===`broker`?l?r(`div`,{className:`space-y-3`,children:[c(`p`,{className:`text-[11px] text-foreground-subtle`,children:m(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),v&&r(`p`,{className:`text-[11px] text-foreground`,children:[m(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,c(`span`,{className:`font-mono text-foreground-subtle`,children:v})]}),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`}),m(`integrations.saving`,{defaultValue:`Saving…`})]}):c(H,{kind:l,onResolved:e=>{w({brokerId:e})},onBack:p}),S.isError&&c(`p`,{className:`text-[11px] text-danger`,children:m(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):c(`p`,{className:`text-[11px] text-danger`,children:m(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):s===`account`?_||b?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(J,{className:`h-3 w-3 animate-spin`}),m(`integrations.loading`,{defaultValue:`Loading…`})]}):c(ce,{addonId:t,configSchema:x,canTest:u,initialName:n,initialConfig:He(x,g??{}),submitLabel:m(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e})=>w(e),onBack:p}):c(j,{trpc:d,addonId:t,nodeId:`hub`,title:n})]})})}function Ge(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}n();function Ke(){let{t}=Ce(),{integrationId:n}=_e(),f=o(),p=ge(),[_,S]=he(),C=d(),[w,T]=s(!1),[E,O]=s(!1),[te,A]=s(!1),[j,N]=s(!1),[P,I]=s(!1),{data:B,isLoading:V}=g({id:n??``},{enabled:!!n}),{data:ce}=R({addonId:B?.addonId??``,nodeId:`hub`},{enabled:!!B?.addonId}),{data:H,isSuccess:U}=ee(),W=i(()=>{let e=B?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[H,B?.addonId,U]),{data:de}=z({}),fe=i(()=>(de?.providers??[]).some(e=>e.addonId===B?.addonId),[de,B?.addonId]),G=W!==null,K=B?.info?.fixed===!0,me=G?W===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),ye=i(()=>{let e=B?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.brokerKind??null},[H,B?.addonId,U]),we=i(()=>{let e=B?.addonId;return!e||!U?!1:(H??[]).find(t=>t.addonId===e)?.canTest===!0},[H,B?.addonId,U]),Y=i(()=>{let e=B?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.mode??null},[H,B?.addonId,U]);l(()=>{_.get(`add`)===`1`&&G&&(T(!0),S(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[_,G,S]);let De=ce!=null&&Array.isArray(ce.sections)&&ce.sections.some(e=>e.fields.length>0),{data:Oe}=ne({addonId:B?.addonId??``,nodeId:`hub`},{enabled:!!B?.addonId&&Y!==`account`}),ke=Y!==null&&Y!==`account`&&Ge(Oe),Ae=i(()=>B?.addonId?[B.addonId]:[],[B?.addonId]),{data:je}=x({projection:`slim`},{refetchInterval:3e4}),X=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Ne=D({onMutate:async e=>{await f.cancelQueries({queryKey:X});let t=f.getQueryData(X);return t!=null&&f.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&f.setQueryData(X,r.previous)},onSettled:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Z=v({onSuccess:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]}),N(!1),p(`/integrations`)}}),Pe=b({onSuccess:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=re({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=y({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ie=h({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=i(()=>je??[],[je]),Re=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},[$]),ze=e(e=>Re.get(e)??null,[Re]),Be=e(e=>c(ae,{type:e,size:`sm`}),[]),Ve=e(e=>p(`/devices/${String(e)}`),[p]),He=i(()=>{let e=B?.addonId;return e?$.filter(t=>t.addonId===e):[]},[$,B?.addonId]),Ue=i(()=>k(He).length,[He]);return V?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`})]}):B?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[c(F,{items:[{label:`Integrations`,onClick:()=>p(`/integrations`)},{label:B.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/${B.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:B.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[B.addonId,` · `,Ue,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[fe&&r(`button`,{onClick:()=>O(!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(se,{className:`h-3.5 w-3.5`}),`Scan network`]}),!K&&r(`button`,{onClick:()=>T(!0),disabled:!G,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:me,children:[c(oe,{className:`h-3.5 w-3.5`}),me]}),r(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Ne.isPending?`opacity-60`:``} ${B.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[c(m,{checked:B.enabled,onCheckedChange:e=>Ne.mutate({id:n,enabled:e}),disabled:Ne.isPending,"aria-label":B.enabled?`Disable integration`:`Enable integration`}),c(`span`,{className:`text-[11px] font-medium ${B.enabled?`text-success`:`text-foreground-subtle`}`,children:B.enabled?`Enabled`:`Disabled`}),Ne.isPending&&c(J,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Y!==`standalone`&&(De||W===`device-adoption`)&&r(`button`,{onClick:()=>A(!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(ve,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>I(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrations.logs`,{defaultValue:`View logs`}),children:[c(be,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),c(ie,{label:`Restart`,icon:ue,title:`Restart "${B.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Ue} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Pe.isPending,action:()=>Pe.mutateAsync({addonId:B.addonId})}),!K&&r(`button`,{onClick:()=>N(!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(xe,{className:`h-3 w-3`}),t(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),ke&&c(Te,{nodeId:null,addonIds:Ae,level:`global`,surface:`integration`,title:t(`integrations.settings`,{defaultValue:`Settings`})}),c(L,{context:`integration-detail`,devices:$,trpc:C.trpcClient,forceAddon:B.addonId,urlScope:`root`,lsKey:`integration-detail:${B.addonId}`,resolveIntegrationIcon:Be,resolveParent:ze,onNavigate:Ve,batchActions:{remove:Q.mutate,disable:Fe.mutate,enable:Ie.mutate},...K?{}:{onDeleteDevice:e=>Q.mutate({deviceId:e.id})}}),w&&n&&W===`device-adoption`&&c(Le,{addonId:B.addonId,integrationId:n,onClose:()=>T(!1)}),w&&n&&W===`device-provider`&&c(Me,{open:w,integrationId:n,addonId:B.addonId,onClose:()=>T(!1)}),E&&B&&c(le,{open:E,scope:{addonId:B.addonId,label:B.name},onClose:()=>O(!1)}),te&&n&&W!==null&&Y!==null&&c(We,{integrationId:n,addonId:B.addonId,name:B.name,kind:W,mode:Y,brokerKind:ye,canTest:we,trpc:C.trpcClient,onClose:()=>A(!1)}),P&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>I(!1),children:r(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 min-w-0`,children:[c(be,{className:`h-4 w-4 text-primary shrink-0`}),c(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:B.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[B.addonId,n?` · ${n}`:``]})]}),c(`button`,{onClick:()=>I(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:c(Se,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:c(M,{addonId:B.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),j&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Z.isPending&&N(!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(q,{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:B.name,count:Ue})})]})]}),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:()=>N(!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(xe,{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(Ee,{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(pe,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{Ke as IntegrationDetailPage};
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,W as i,b as a,o,q as s,x as c,z as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as u,at as d}from"./player-overlays-DVo2KR_t.js";import{Ai as f,Ar as p,At as m,Br as h,Di as g,Dr as _,Ei as v,Fr as y,In as b,Jr as x,L as S,Mi as C,Nr as w,Oi as ee,Or as T,P as E,Pi as D,Pr as O,Qr as te,T as k,Ur as A,Ut as j,Y as M,bn as ne,ei as re,it as ie,jr as N,kr as P,st as F,ui as I,w as L,yn as R,zr as z}from"./src-CLAf92SY.js";import{_t as B}from"./src-e8CzBBHU.js";import{t as ae}from"./ProviderIcon-CNufGvWr.js";import{t as V}from"./circle-x-BVeWtyWa.js";import{t as oe}from"./plus-BhEMDQtU.js";import{i as se,n as ce,r as H,t as le}from"./ScanNetworkModal-DRcWDlfZ.js";import{t as ue}from"./refresh-cw-Bk9SNV20.js";import{t as U}from"./rotate-cw-B1uedsyY.js";import{t as W}from"./wifi-DKocxMvb.js";import{A as de,B as fe,F as G,J as K,K as pe,L as me,Q as he,X as ge,Z as _e,a as q,f as ve,j as ye,m as be,o as xe,r as Se,t as Ce,w as J,z as we}from"./index-DL2yqdrc.js";import{t as Y}from"./FormBuilder-j23rGTmj.js";import{t as Te}from"./NodeAddonsSettingsPanel-BlZbeN2Z.js";var Ee=K(`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 De(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...De(n.fields));return t}function Oe(t,n,r){let[a,o]=s(`idle`),[c,l]=s({}),u=i(()=>{let e=[];for(let n of t.sections)e.push(...De(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 ke(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(...ke(n.fields));return t}function Ae(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function je(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){je(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 Me({open:t,integrationId:n,addonId:a,onClose:u}){let{t:d}=Ce(),f=o(),[p,m]=s({}),[h,g]=s(!1),[_,v]=s(null),[y,b]=s(X),x=te({addonId:a},{enabled:t}),S=x.data?.deviceType??null,C=A({addonId:a,type:S??B.Camera},{enabled:t&&x.isSuccess&&S!==null}),w=C.data??null;l(()=>{t&&(m(w?je(w.sections.flatMap(e=>e.fields)):{}),b(X()),g(!1),v(null))},[t,n,w]);let ee=i(()=>({...p,_probeRequestId:y}),[p,y]),T=O({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),E=I(),D=e(async(e,t)=>{g(!0);let n=await E.mutateAsync({addonId:a,type:S??B.Camera,key:e,value:t,formValues:ee});return n.status===`ok`&&n.suggestedValues&&m(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Ae(e[i])&&!Ae(a)&&(r[i]=a,t=!0);return t?r:e}),n},[E,a,ee,S]),{testAllStatus:k,hasProbeFields:j,probeResults:ne,handleTestAll:re,clearProbeResult:ie}=Oe(w??{sections:[]},p,D);async function N(e){v(null);try{await T.mutateAsync({addonId:a,type:S??B.Camera,config:p,integrationId:n}),e?m(w?je(w.sections.flatMap(e=>e.fields)):{}):u()}catch(e){v(e instanceof Error?e.message:String(e))}}if(!t)return null;let P=ke((w?.sections??[]).flatMap(e=>e.fields)).filter(e=>Ae(p[e])),F=P.length===0,L=x.isLoading||S!==null&&C.isLoading,R=x.isError||x.isSuccess&&S===null||C.isError||C.isSuccess&&w===null;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),r(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:d(`integrations.addDevice`)}),c(`button`,{onClick:u,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:c(Se,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:L?c(`div`,{className:`flex items-center justify-center py-8`,children:c(J,{className:`h-5 w-5 animate-spin text-primary`})}):R?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[c(q,{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(Y,{schema:w,values:p,onChange:m,onTestField:D,probeResults:ne,onClearProbe:ie})}),!R&&!L&&r(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[r(`button`,{type:`button`,onClick:()=>g(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(be,{className:`h-3.5 w-3.5`}),`Test logs`,c(`span`,{className:`font-mono text-[9px] opacity-60`,children:y.slice(0,14)})]}),c(we,{className:`h-3.5 w-3.5 transition-transform ${h?`rotate-180`:``}`})]}),h&&c(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:c(M,{addonId:a,requestId:y,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!R&&!L&&(_||P.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(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:_||`Required: ${P.join(`, `)}`})]})}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:u,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:d(`integrations.cancel`)}),!R&&j&&r(`button`,{type:`button`,onClick:re,disabled:k===`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:[k===`testing`?c(J,{className:`h-3.5 w-3.5 animate-spin`}):c(W,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:()=>N(!0),disabled:R||!F||T.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:d(`integrations.saveAndNew`)}),c(`button`,{onClick:()=>N(!1),disabled:R||!F||T.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:T.isPending?d(`integrations.saving`):d(`integrations.save`)})]})]})]})]})}var Ne=1500;function Z({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=Ce(),o=_(),s=(p({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Ne:!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 m=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(q,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):s.state===`cancelled`?c(V,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):c(G,{className:`h-3.5 w-3.5 text-primary shrink-0`}),c(`p`,{className:`text-[11px] text-foreground`,children:m}),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 Pe(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`,Fe={id:Q,label:`Devices`,isDefault:!0},Ie=2e4,$=100;function Le({addonId:n,integrationId:i,onClose:a}){let{t:o}=Ce(),[u,d]=s(new Set),[f,p]=s(new Set),[m,h]=s(new Map),[g,_]=s(null),{data:v}=ee(),y=(v??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[b,x]=s(!0),C=T({addonId:n,integrationId:i}).data?.filters,D=C&&C.length>0?C:[Fe],[O,te]=s(D.find(e=>e.isDefault)?.id??(D.some(e=>e.id===Q)?Q:D[0].id)),k=O!==Q,A=N(),j=P({addonId:n,integrationId:i,page:1,pageSize:Ie,filter:O}),M=j.refetch,ne=A.mutate,re=e(()=>{ne({addonId:n,integrationId:i},{onSettled:()=>{M()}})},[ne,n,i,M]),ie=t(null);l(()=>{let e=`${n}::${i}`;ie.current===e||j.isLoading||(ie.current=e,(j.data?.candidates.length??0)===0&&re())},[n,i,j.isLoading,j.data,re]);let F=A.isPending,I=A.isError?A.error instanceof Error?A.error.message:String(A.error):null,R=typeof A.data?.lastError==`string`&&A.data.lastError.length>0?A.data.lastError:null,z=j.data?.candidates??[],B=j.isError?j.error instanceof Error?j.error.message:String(j.error):null,ae=w(),[V,oe]=s(null),se=e(e=>{e.alreadyAdopted||d(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),ce=e(e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),H=e((e,t)=>{h(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})},[]),le=e(e=>{let t={};for(let n of e){let e=m.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[m]),ue=e(async()=>{_(null);let e=[...u];if(e.length!==0)try{let t=le(e),{jobId:r}=await ae.mutateAsync({addonId:n,integrationId:i,filter:O,childNativeIds:e,...t?{perCandidate:t}:{},...y?{importLocations:b}:{}});oe(r),d(new Set),h(new Map)}catch(e){_(e instanceof Error?e.message:String(e))}},[u,le,ae,n,i,O,y,b]),W=t(null),de=e(()=>{V===null||W.current===V||(W.current=V,M())},[V,M]),G=e(e=>{te(e),d(new Set),p(new Set),h(new Map),_(null)},[]),K=u.size;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:o(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),c(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:o(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),r(`div`,{className:`flex items-center gap-3 shrink-0`,children:[y&&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:b,onChange:e=>x(e.target.checked),className:`accent-primary`}),o(`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(Se,{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:[(I??B??R)&&z.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(q,{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:o(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),c(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:I??B??R})]})]})}),D.length>1&&c(Re,{filters:D,activeFilter:O,onSelect:G}),c(`div`,{className:`flex-1 min-h-0`,children:c(L,{mode:`generic`,items:z,pageSize:$,getKey:e=>e.childNativeId,getSearchText:Pe,getFilterType:e=>e.type,filterOptions:E(),filterLabel:o(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:j.isLoading||F&&z.length===0,searchPlaceholder:o(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(I??B??R)&&z.length===0?``:o(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:re,disabled:F,title:o(`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(U,{className:`h-3.5 w-3.5 ${F?`animate-spin`:``}`}),o(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:o(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>c(ze,{candidate:e,expandable:!k,expanded:f.has(e.childNativeId),onToggleExpand:()=>ce(e.childNativeId),adoptedLabel:o(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:o(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=S(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:()=>se(e),disabled:e.alreadyAdopted,"aria-label":u.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${u.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:u.has(e.childNativeId)&&c(fe,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!k&&f.has(e.childNativeId),renderExpanded:k?void 0:e=>c(Be,{candidate:e,hiddenChildIds:m.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>H(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:u.has(e.childNativeId)?`bg-primary/5`:``})})]}),g&&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(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:g})]})}),V!==null&&c(Z,{addonId:n,integrationId:i,jobId:V,onFinished:de}),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:o(`integrations.cancel`,{defaultValue:`Cancel`})}),r(`button`,{onClick:ue,disabled:K===0||ae.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:[ae.isPending&&c(J,{className:`h-3.5 w-3.5 animate-spin`}),o(`integrations.addSelected`,{defaultValue:`Add selected`}),K>0?` (${K})`:``]})]})]})]})]})}function Re({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 ze({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?we:me,{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 Be({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?ye:de,{className:`h-3 w-3`})})]},e.childNativeId)})})}n();function Ve(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...Ve(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function He(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>Ve(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Ue(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 We({integrationId:e,addonId:t,name:n,kind:a,mode:s,brokerKind:l,canTest:u=!1,trpc:d,onClose:p}){let{t:m}=Ce(),h=o(),{data:g,isLoading:_}=f({id:e},{enabled:s===`account`||s===`broker`}),v=i(()=>{let e=g?.brokerId;return typeof e==`string`?e:null},[g]),{data:y,isLoading:b}=R({addonId:t,nodeId:`hub`},{enabled:s===`account`}),x=i(()=>y?Ue(y):null,[y]),S=C(),w=t=>{S.mutate({id:e,settings:t},{onSuccess:()=>{h.invalidateQueries(),p()}})};return c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:p,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:[m(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),c(`button`,{onClick:p,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":m(`common.close`,{defaultValue:`Close`}),children:c(Se,{className:`h-4 w-4`})})]}),s===`broker`?l?r(`div`,{className:`space-y-3`,children:[c(`p`,{className:`text-[11px] text-foreground-subtle`,children:m(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),v&&r(`p`,{className:`text-[11px] text-foreground`,children:[m(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,c(`span`,{className:`font-mono text-foreground-subtle`,children:v})]}),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`}),m(`integrations.saving`,{defaultValue:`Saving…`})]}):c(H,{kind:l,onResolved:e=>{w({brokerId:e})},onBack:p}),S.isError&&c(`p`,{className:`text-[11px] text-danger`,children:m(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):c(`p`,{className:`text-[11px] text-danger`,children:m(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):s===`account`?_||b?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(J,{className:`h-3 w-3 animate-spin`}),m(`integrations.loading`,{defaultValue:`Loading…`})]}):c(ce,{addonId:t,configSchema:x,canTest:u,initialName:n,initialConfig:He(x,g??{}),submitLabel:m(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e})=>w(e),onBack:p}):c(j,{trpc:d,addonId:t,nodeId:`hub`,title:n})]})})}function Ge(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}n();function Ke(){let{t}=Ce(),{integrationId:n}=_e(),f=o(),p=ge(),[_,S]=he(),C=d(),[w,T]=s(!1),[E,O]=s(!1),[te,A]=s(!1),[j,N]=s(!1),[P,I]=s(!1),{data:B,isLoading:V}=g({id:n??``},{enabled:!!n}),{data:ce}=R({addonId:B?.addonId??``,nodeId:`hub`},{enabled:!!B?.addonId}),{data:H,isSuccess:U}=ee(),W=i(()=>{let e=B?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[H,B?.addonId,U]),{data:de}=z({}),fe=i(()=>(de?.providers??[]).some(e=>e.addonId===B?.addonId),[de,B?.addonId]),G=W!==null,K=B?.info?.fixed===!0,me=G?W===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),ye=i(()=>{let e=B?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.brokerKind??null},[H,B?.addonId,U]),we=i(()=>{let e=B?.addonId;return!e||!U?!1:(H??[]).find(t=>t.addonId===e)?.canTest===!0},[H,B?.addonId,U]),Y=i(()=>{let e=B?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.mode??null},[H,B?.addonId,U]);l(()=>{_.get(`add`)===`1`&&G&&(T(!0),S(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[_,G,S]);let De=ce!=null&&Array.isArray(ce.sections)&&ce.sections.some(e=>e.fields.length>0),{data:Oe}=ne({addonId:B?.addonId??``,nodeId:`hub`},{enabled:!!B?.addonId&&Y!==`account`}),ke=Y!==null&&Y!==`account`&&Ge(Oe),Ae=i(()=>B?.addonId?[B.addonId]:[],[B?.addonId]),{data:je}=x({projection:`slim`},{refetchInterval:3e4}),X=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Ne=D({onMutate:async e=>{await f.cancelQueries({queryKey:X});let t=f.getQueryData(X);return t!=null&&f.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&f.setQueryData(X,r.previous)},onSettled:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Z=v({onSuccess:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]}),N(!1),p(`/integrations`)}}),Pe=b({onSuccess:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=re({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=y({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ie=h({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=i(()=>je??[],[je]),Re=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},[$]),ze=e(e=>Re.get(e)??null,[Re]),Be=e(e=>c(ae,{type:e,size:`sm`}),[]),Ve=e(e=>p(`/devices/${String(e)}`),[p]),He=i(()=>{let e=B?.addonId;return e?$.filter(t=>t.addonId===e):[]},[$,B?.addonId]),Ue=i(()=>k(He).length,[He]);return V?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`})]}):B?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[c(F,{items:[{label:`Integrations`,onClick:()=>p(`/integrations`)},{label:B.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/${B.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:B.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[B.addonId,` · `,Ue,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[fe&&r(`button`,{onClick:()=>O(!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(se,{className:`h-3.5 w-3.5`}),`Scan network`]}),!K&&r(`button`,{onClick:()=>T(!0),disabled:!G,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:me,children:[c(oe,{className:`h-3.5 w-3.5`}),me]}),r(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Ne.isPending?`opacity-60`:``} ${B.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[c(m,{checked:B.enabled,onCheckedChange:e=>Ne.mutate({id:n,enabled:e}),disabled:Ne.isPending,"aria-label":B.enabled?`Disable integration`:`Enable integration`}),c(`span`,{className:`text-[11px] font-medium ${B.enabled?`text-success`:`text-foreground-subtle`}`,children:B.enabled?`Enabled`:`Disabled`}),Ne.isPending&&c(J,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Y!==`standalone`&&(De||W===`device-adoption`)&&r(`button`,{onClick:()=>A(!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(ve,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>I(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrations.logs`,{defaultValue:`View logs`}),children:[c(be,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),c(ie,{label:`Restart`,icon:ue,title:`Restart "${B.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Ue} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Pe.isPending,action:()=>Pe.mutateAsync({addonId:B.addonId})}),!K&&r(`button`,{onClick:()=>N(!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(xe,{className:`h-3 w-3`}),t(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),ke&&c(Te,{nodeId:null,addonIds:Ae,level:`global`,surface:`integration`,title:t(`integrations.settings`,{defaultValue:`Settings`})}),c(L,{context:`integration-detail`,devices:$,trpc:C.trpcClient,forceAddon:B.addonId,urlScope:`root`,lsKey:`integration-detail:${B.addonId}`,resolveIntegrationIcon:Be,resolveParent:ze,onNavigate:Ve,batchActions:{remove:Q.mutate,disable:Fe.mutate,enable:Ie.mutate},...K?{}:{onDeleteDevice:e=>Q.mutate({deviceId:e.id})}}),w&&n&&W===`device-adoption`&&c(Le,{addonId:B.addonId,integrationId:n,onClose:()=>T(!1)}),w&&n&&W===`device-provider`&&c(Me,{open:w,integrationId:n,addonId:B.addonId,onClose:()=>T(!1)}),E&&B&&c(le,{open:E,scope:{addonId:B.addonId,label:B.name},onClose:()=>O(!1)}),te&&n&&W!==null&&Y!==null&&c(We,{integrationId:n,addonId:B.addonId,name:B.name,kind:W,mode:Y,brokerKind:ye,canTest:we,trpc:C.trpcClient,onClose:()=>A(!1)}),P&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>I(!1),children:r(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 min-w-0`,children:[c(be,{className:`h-4 w-4 text-primary shrink-0`}),c(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:B.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[B.addonId,n?` · ${n}`:``]})]}),c(`button`,{onClick:()=>I(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:c(Se,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:c(M,{addonId:B.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),j&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Z.isPending&&N(!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(q,{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:B.name,count:Ue})})]})]}),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:()=>N(!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(xe,{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(Ee,{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(pe,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{Ke as IntegrationDetailPage};
|