@camstack/addon-admin-ui 1.2.440 → 1.2.442
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/{AddonAssetIcon-DoCqXzAv.js → AddonAssetIcon-BccuV0q0.js} +1 -1
- package/dist/assets/Addons-kSQ_LfKG.js +4 -0
- package/dist/assets/{AdminPage-KGO_m_yt.js → AdminPage-C_5SnDIL.js} +1 -1
- package/dist/assets/{AdminSectionedPage-BiMhPKOP.js → AdminSectionedPage-9KWXxykK.js} +1 -1
- package/dist/assets/AiProfiles-jgiZ-hEI.js +3 -0
- package/dist/assets/{BrokerForm-yx58WRgh.js → BrokerForm-DzQNeSxm.js} +1 -1
- package/dist/assets/Build-DCeob-yZ.js +40 -0
- package/dist/assets/{Calendars-BdN8ZQmv.js → Calendars-Cla89sbi.js} +1 -1
- package/dist/assets/Cluster-eTZjguTx.js +1 -0
- package/dist/assets/{ClusterStepModel-DPmlzTfm.js → ClusterStepModel-8aoPvS-k.js} +1 -1
- package/dist/assets/{CompositionEditor-BhL25d6e.js → CompositionEditor-CJR7m-qo.js} +1 -1
- package/dist/assets/{CompositionEditorPage-BwqVkeY-.js → CompositionEditorPage-BgQSiVo8.js} +1 -1
- package/dist/assets/Data-xUdBOATt.js +2 -0
- package/dist/assets/DeviceDetail-BxgqCzrO.js +2 -0
- package/dist/assets/{DeviceDoActionFields-C6f9gioM.js → DeviceDoActionFields-BjVWVHu7.js} +1 -1
- package/dist/assets/{Devices-CtivG8K9.js → Devices-D9zuTHOW.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-BD-Z7zz-.js → EmbedPlayerPage-MXUvBkWX.js} +1 -1
- package/dist/assets/Identity-0TfWSUca.js +1 -0
- package/dist/assets/IntegrationDetail-e-6OvQx9.js +1 -0
- package/dist/assets/IntegrationHub-CA9MM1oL.js +1 -0
- package/dist/assets/Integrations-BbsiTLtO.js +1 -0
- package/dist/assets/Integrations-BdrRZHfb.js +1 -0
- package/dist/assets/{Library-ToUHY4O3.js → Library-B9_Scpen.js} +1 -1
- package/dist/assets/Locations-DdCSAAsc.js +3 -0
- package/dist/assets/{Logs-Ds6SPC6o.js → Logs-CVR97TYT.js} +1 -1
- package/dist/assets/{MaskShapeCanvas-BoY32Qvt.js → MaskShapeCanvas-DEZFJVo5.js} +1 -1
- package/dist/assets/{MotionZonesSettings-DBW4jTEr.js → MotionZonesSettings-Bwo-3iRG.js} +1 -1
- package/dist/assets/MyAccess-oZ9l9GBy.js +2 -0
- package/dist/assets/Network-CNhaeFmn.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-CIISQuIL.js → NodeAddonsSettingsPanel-CRyxRlRb.js} +1 -1
- package/dist/assets/Notifications-2cTCf7lp.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-z8P3R0fA.js → PrivacyMaskSettings-cDl1Qu_T.js} +1 -1
- package/dist/assets/Recordings-DycF_b6H.js +1 -0
- package/dist/assets/{ScanNetworkModal-D7N2aC7y.js → ScanNetworkModal-C5RUKriq.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-CyjEekEM.js → SceneMonitorEditor-BmaWm_DT.js} +1 -1
- package/dist/assets/SessionsList-Cu3ZE31w.js +2 -0
- package/dist/assets/{Showroom-PlFtcQrL.js → Showroom-ndc_ZezE.js} +1 -1
- package/dist/assets/{System-DxszqVYV.js → System-C_RpKyaA.js} +1 -1
- package/dist/assets/{Terminal-BMG2w8DZ.js → Terminal-BdKedDZS.js} +3 -3
- package/dist/assets/{Viewer-CRLD_tt7.js → Viewer-LdYt8Q3H.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-GapjKGVe.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DId7Mdzp.js} +1 -1
- package/dist/assets/{addon-icons-context-BrgGsfoE.js → addon-icons-context-BNhm5nij.js} +1 -1
- package/dist/assets/{archive-Dx-auPAN.js → archive-Dj3rQasM.js} +1 -1
- package/dist/assets/{authed-media-MhMmWNH3.js → authed-media-CRKmATDJ.js} +1 -1
- package/dist/assets/{bell-off-BQQTURVF.js → bell-off-BxB4ohQe.js} +1 -1
- package/dist/assets/{board-model-Bdetmchn.js → board-model-Bx9i2Ikh.js} +1 -1
- package/dist/assets/{boxes-BIK98bHo.js → boxes-Cyb74Sc2.js} +1 -1
- package/dist/assets/circle-slash-CJ8sDXES.js +1 -0
- package/dist/assets/client-CqoBi3ym.js +358 -0
- package/dist/assets/{cloud-upload-FvK6xW2I.js → cloud-upload-STkEa8On.js} +1 -1
- package/dist/assets/crop-Cvf_bPJF.js +1 -0
- package/dist/assets/{device-integration-icon-ClmWzwM_.js → device-integration-icon-NmvFHcoT.js} +1 -1
- package/dist/assets/device-picker-model-2g0u_pQE.js +1 -0
- package/dist/assets/{dist-CEnfZ10I.js → dist-CboU_aT5.js} +1 -1
- package/dist/assets/dist-yylqec5a.js +358 -0
- package/dist/assets/{eraser-CUAqtnBD.js → eraser-MfKJ-xHy.js} +1 -1
- package/dist/assets/{hard-drive-download-XGtks2vE.js → hard-drive-download-DNMTqY2h.js} +1 -1
- package/dist/assets/{history-DqvhlzWX.js → history-ohLSkO2A.js} +1 -1
- package/dist/assets/{hostInit-DzBGXsvZ.js → hostInit-LP6ARUYA.js} +1 -1
- package/dist/assets/i18n-Bldp2nug.js +1 -0
- package/dist/assets/{icons-DNRi-jSy.js → icons-Bft8hsua.js} +1 -1
- package/dist/assets/{index-yoPG03d0.js → index-WxoBkjSL.js} +3 -3
- package/dist/assets/{key-bw9xhRgT.js → key-LDVs0Hda.js} +1 -1
- package/dist/assets/{key-round-BngMS2dZ.js → key-round-ufq1OhZE.js} +1 -1
- package/dist/assets/{layers-CIl8QXpN.js → layers-DMR3HPTk.js} +1 -1
- package/dist/assets/{linked-devices-model-CclOXMLj.js → linked-devices-model-BhIH5Kho.js} +1 -1
- package/dist/assets/{list-ordered-_52_xrQ7.js → list-ordered-iFgP3FdK.js} +1 -1
- package/dist/assets/{location-owned-usage-5eb6nny3.js → location-owned-usage-ChRB3Z7a.js} +1 -1
- package/dist/assets/{log-in-DH9Lu6bJ.js → log-in-4wTdM9C2.js} +1 -1
- package/dist/assets/{memory-stick-CzaP6KiN.js → memory-stick-BVZbZTDE.js} +1 -1
- package/dist/assets/{message-square-plus-vMywres_.js → message-square-plus-DTEXt10L.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-54468006.js → mf-entry-bootstrap-0-6f3bb22b.js} +2 -2
- package/dist/assets/{mic-off-Da09u2hl.js → mic-off-BOvuLxyG.js} +1 -1
- package/dist/assets/{monitor-off-jOOWdiSg.js → monitor-off-BJJUHiNu.js} +1 -1
- package/dist/assets/{monitor-smartphone-D_W4zyWO.js → monitor-smartphone-BaRjkvN9.js} +1 -1
- package/dist/assets/mount-2g0u_pQE.js +1 -0
- package/dist/assets/{notification-schedule-field-LytDFkpQ.js → notification-schedule-field-BHhbg0a-.js} +1 -1
- package/dist/assets/{player-overlays-CCZE3o8q.js → player-overlays-CpALjVtS.js} +1 -1
- package/dist/assets/{recycle-BVcCaHVd.js → recycle-CjrRLz-b.js} +1 -1
- package/dist/assets/remoteEntry-CgICLtvC.js +1 -0
- package/dist/assets/{scan-eye-CHwWv39K.js → scan-eye-D35EojCj.js} +1 -1
- package/dist/assets/{scissors-BrUBwnKn.js → scissors-DreuVKed.js} +1 -1
- package/dist/assets/{search-x-BcR2pidC.js → search-x-DQHP4OCR.js} +1 -1
- package/dist/assets/{send-8R5TbxHN.js → send-Dta9lxhX.js} +1 -1
- package/dist/assets/{settings-2-C4PaSGfb.js → settings-2-DPZ8CKFD.js} +1 -1
- package/dist/assets/{speaker-CBRM7GNH.js → speaker-D95jrOt6.js} +1 -1
- package/dist/assets/src-CsHgYIi2.js +67 -0
- package/dist/assets/{timer-reset-DlfKkTg_.js → timer-reset-EEmenpu7.js} +1 -1
- package/dist/assets/{ungroup-BzlNECzG.js → ungroup-Db4urNO1.js} +1 -1
- package/dist/assets/{unlink-HIuzqEig.js → unlink-6J-SREPz.js} +1 -1
- package/dist/assets/{usb-DqboQtO8.js → usb-UiuX4lHP.js} +1 -1
- package/dist/assets/{use-scenes-feed-Cnl4Is6T.js → use-scenes-feed-xAvk3mdK.js} +1 -1
- package/dist/assets/{use-stationary-objects-DmFWTPK0.js → use-stationary-objects-BSuACN9l.js} +1 -1
- package/dist/assets/useEventInvalidation-2g0u_pQE.js +1 -0
- package/dist/assets/{useNodeUrlSelection-CSh6gqLc.js → useNodeUrlSelection-itsA69-a.js} +1 -1
- package/dist/assets/user-round-t1eXjuPz.js +1 -0
- package/dist/assets/{user-x-ciro8k7Z.js → user-x-BiLr1XcR.js} +1 -1
- package/dist/assets/{video-BJUj4GaK.js → video-DSVienqW.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CwjeQPZx.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BzdoZPn9.js} +2 -2
- package/dist/index.html +10 -10
- package/dist/server/addon.js +391 -295
- package/package.json +1 -1
- package/dist/assets/Addons-CrSVEbe3.js +0 -4
- package/dist/assets/AiProfiles-D8mKo1K9.js +0 -3
- package/dist/assets/Build-BArewEF3.js +0 -40
- package/dist/assets/Cluster-Bn5YZafT.js +0 -1
- package/dist/assets/Data-BvY-zVHv.js +0 -2
- package/dist/assets/DeviceDetail-g2esa6u-.js +0 -2
- package/dist/assets/Identity-BQNP0wku.js +0 -1
- package/dist/assets/IntegrationDetail-CzEG-I4B.js +0 -1
- package/dist/assets/IntegrationHub-tqxee2Rm.js +0 -1
- package/dist/assets/Integrations-C7Ptcn3c.js +0 -1
- package/dist/assets/Integrations-GZm_SrQK.js +0 -1
- package/dist/assets/Locations-CPFCvUKd.js +0 -3
- package/dist/assets/MyAccess-2mSUBp14.js +0 -2
- package/dist/assets/Network-BddKO6B1.js +0 -1
- package/dist/assets/Notifications-DWJcnXvV.js +0 -1
- package/dist/assets/Recordings-g1Jxg_Lr.js +0 -1
- package/dist/assets/SessionsList-bmTxxIOE.js +0 -2
- package/dist/assets/circle-slash-DKE4hxbW.js +0 -1
- package/dist/assets/client-Cy6wyTLQ.js +0 -358
- package/dist/assets/crop-7vsE3Qcd.js +0 -1
- package/dist/assets/device-picker-model-DVvq9nYp.js +0 -1
- package/dist/assets/dist-BPMeH1J4.js +0 -358
- package/dist/assets/i18n-B1bxeya5.js +0 -1
- package/dist/assets/mount-DVvq9nYp.js +0 -1
- package/dist/assets/remoteEntry-BOaeaEWk.js +0 -1
- package/dist/assets/src-Cw4W7OtK.js +0 -67
- package/dist/assets/useEventInvalidation-DVvq9nYp.js +0 -1
- package/dist/assets/user-round-C4K7vDWN.js +0 -1
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,L as i,S as a,a as o,b as s,o as c,q as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Bi as f,Br as p,D as m,Ei as h,En as g,G as _,Gn as v,Ii as y,It as b,J as x,Jn as S,Jr as C,K as w,Kn as T,Li as E,O as D,Rn as O,Si as k,Sr as A,St as j,T as M,V as ee,W as N,Xn as P,Xr as F,Z as te,Zt as I,_t as L,bn as R,cr as ne,dn as z,dt as re,ea as B,en as V,ht as ie,li as ae,lr as oe,m as se,oa as H,or as ce,ot as U,pi as le,pn as ue,r as de,t as fe,vn as pe,xn as W,yn as me,z as he,zn as ge,zr as _e}from"./player-overlays-CCZE3o8q.js";import{Dr as ve,Fn as ye,Hr as be,In as xe,Mr as G,Nr as K,Or as q,Pn as J,Tr as Se,Vr as Ce,Zn as we,_ as Te,_i as Ee,an as De,br as Oe,d as ke,dn as Ae,h as je,in as Me,jn as Ne,jr as Pe,m as Fe,mr as Ie,nn as Le,p as Re,pn as ze,rn as Be,tn as Ve,un as He,ur as Ue,v as We,vi as Ge,vr as Ke,x as qe}from"./client-Cy6wyTLQ.js";import{t as Je}from"./archive-Dx-auPAN.js";import{i as Ye,n as Xe,r as Ze,t as Qe}from"./scan-eye-CHwWv39K.js";import{t as $e}from"./bell-off-BQQTURVF.js";import{t as et}from"./boxes-BIK98bHo.js";import{n as tt}from"./video-BJUj4GaK.js";import{t as nt}from"./circle-slash-DKE4hxbW.js";import{t as rt}from"./layers-CIl8QXpN.js";import{$n as it,$o as at,$t as ot,A as st,Bs as ct,Ca as lt,Ct as ut,Di as dt,Dn as ft,Dt as pt,Ea as mt,En as ht,Et as gt,Fn as _t,Fs as vt,Ga as yt,Gi as bt,Gs as xt,Gt as St,Ha as Ct,Hi as wt,Hn as Y,Is as Tt,J as Et,Jn as Dt,Jt as Ot,K as kt,Ki as At,Ln as jt,M as Mt,Ma as Nt,Mi as Pt,Mn as Ft,Ms as It,Ni as Lt,Nn as Rt,Ns as zt,Oi as Bt,On as Vt,Pn as Ht,Pr as Ut,Pt as Wt,Ri as Gt,Rn as Kt,S as qt,St as Jt,Su as Yt,T as Xt,Tt as Zt,Un as Qt,Ut as $t,Vi as en,Vt as tn,Wi as nn,Xr as rn,Y as an,Zl as on,_a as sn,_n as cn,_o as ln,_t as un,_u as dn,a as fn,ac as pn,an as mn,au as hn,c as gn,cr as _n,ct as vn,d as yn,dn as bn,do as xn,dt as Sn,ea as Cn,en as wn,fn as Tn,ga as En,go as Dn,gr as On,gu as kn,ho as An,i as jn,ia as Mn,ic as Nn,in as Pn,it as Fn,j as In,jn as Ln,js as Rn,k as zn,kc as Bn,kn as Vn,l as Hn,la as Un,ln as Wn,lr as Gn,ls as Kn,lu as qn,ma as Jn,mc as Yn,mt as Xn,mu as Zn,nc as Qn,nn as $n,nt as er,nu as tr,o as nr,oc as rr,on as ir,ot as ar,ou as or,pa as sr,pn as cr,pt as lr,r as ur,rc as dr,rn as fr,ru as pr,s as mr,sn as hr,sr as gr,ss as _r,st as vr,su as yr,tc as br,ua as xr,un as Sr,ut as Cr,va as wr,vt as Tr,w as Er,x as Dr,xt as Or,yt as kr,za as Ar,zn as jr}from"./src-Cw4W7OtK.js";import{t as X}from"./i18n-B1bxeya5.js";import{t as Z}from"./useTranslation-D3Is_4B6.js";import"./mount-DVvq9nYp.js";import{A as Mr,F as Nr,H as Pr,I as Fr,J as Ir,K as Lr,M as Rr,N as zr,P as Br,Q as Vr,U as Hr,V as Ur,W as Wr,X as Gr,Y as Kr,Z as qr,et as Jr,g as Yr,h as Xr,j as Zr,nt as Qr,p as $r,q as ei,tt as ti}from"./index-yoPG03d0.js";import{C as ni,D as ri,E as ii,S as ai,_ as oi,a as si,b as ci,c as li,d as ui,f as di,g as fi,h as pi,i as mi,l as hi,m as gi,n as _i,o as vi,p as yi,r as bi,s as xi,t as Si,u as Ci,v as wi,x as Ti,y as Ei}from"./CompositionEditor-BhL25d6e.js";import{_ as Di,a as Oi,c as ki,d as Ai,f as ji,g as Mi,h as Ni,i as Pi,l as Fi,m as Ii,n as Li,o as Ri,p as zi,s as Bi,t as Vi,u as Hi,v as Ui,y as Wi}from"./ClusterStepModel-DPmlzTfm.js";import"./useEventInvalidation-DVvq9nYp.js";import{t as Gi}from"./use-stationary-objects-DmFWTPK0.js";import{a as Ki,c as qi,d as Ji,f as Yi,i as Xi,l as Zi,n as Qi,o as $i,p as ea,r as ta,s as na,t as ra,u as ia}from"./linked-devices-model-CclOXMLj.js";import{t as aa}from"./authed-media-MhMmWNH3.js";e();function oa(e){if(typeof e!=`object`||!e)return null;let t=e,n=t.id,r=t.label;if(typeof n!=`string`||typeof r!=`string`)return null;let i=t.available===!0,a=t.enabled,o=t.unavailableReason;return{id:n,label:r,costWhenOff:typeof t.costWhenOff==`string`?t.costWhenOff:``,on:i&&typeof a==`boolean`?a:null,available:i,unavailableReason:typeof o==`string`?o:null}}function sa(e){if(typeof e!=`object`||!e)return null;let t=e.switches;if(!Array.isArray(t))return null;let n=t.map(oa).filter(e=>e!==null);return n.length===0?null:n}var ca=[[/privacy|mask/i,`privacy`],[/microphone|mic\b/i,`microphone`],[/speaker|broker audio|stream audio/i,`speaker`],[/audio/i,`listening`],[/object|detect/i,`detection`],[/event/i,`archive`],[/record/i,`recording`],[/notif/i,`notifications`],[/stream|broker/i,`stream`]];function la(e){for(let[t,n]of ca)if(t.test(e))return n;return`generic`}function ua(e){let t=e.filter(e=>e.on===!1).map(e=>e.id),n=e.filter(e=>e.on===null).map(e=>e.id),r=t=>t.map(t=>e.find(e=>e.id===t)?.label??t).join(`, `),i=[];return t.length>0&&i.push(X.t(`helpers.cameraSwitchRows.off`,{list:r(t)})),n.length>0&&i.push(X.t(`helpers.cameraSwitchRows.unknown`,{list:r(n)})),{offIds:t,unknownIds:n,summary:i.length===0?X.t(`helpers.cameraSwitchRows.allOn`):i.join(` · `)}}var da={stream:W,detection:Qe,privacy:_e,microphone:P,speaker:j,listening:Xe,archive:Je,recording:Ze,notifications:y,generic:V};function fa({deviceId:e}){let{t}=Z(),n=c(),o=Number.isFinite(e),[s,l]=r(null),[u,f]=r(!1),p=Tt({deviceId:e},{enabled:o});ur([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let m=sa(p.data),h=rr({onError:(t,r)=>{console.error(`[CameraFunctionSwitches] switch write failed — reverting`,{tags:{deviceId:e},meta:{switchId:r.switchId,error:t instanceof Error?t.message:String(t)}}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSwitches`]]}),l({id:r.switchId,message:t instanceof Error?t.message:String(t)})},onSuccess:()=>{l(null),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),n.invalidateQueries({queryKey:[[`deviceManager`]]}),n.invalidateQueries({queryKey:[[`recording`]]})}}),g=i(t=>{!t.available||t.on===null||h.mutate({deviceId:e,switchId:t.id,enabled:!t.on})},[e,h]);if(m===null)return null;let _=ua(m),v=e=>s?.id===e.id?s.message:null;return a(hn,{open:u,onOpenChange:f,children:[a(yr,{"aria-label":t(`device.cameraFunctionSwitches.cameraFunctions`,`Camera functions`),title:_.summary,className:`inline-flex items-center gap-1 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors ${s===null?_.offIds.length>0?`border-warning/40 text-warning hover:bg-warning/10`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`:`border-danger/50 text-danger bg-danger/5`}`,children:[d(V,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden lg:inline`,children:t(`device.cameraFunctionSwitches.functions`,`Functions`)}),_.offIds.length>0&&d(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:t(`device.cameraFunctionSwitches.offCount`,{count:_.offIds.length})})]}),a(or,{align:`end`,className:`min-w-[240px] max-h-[60vh] overflow-y-auto p-1`,children:[d(`div`,{className:`px-2 py-1 text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t(`device.cameraFunctionSwitches.cameraFunctions`,`Camera functions`)}),d(`ul`,{className:`space-y-0.5`,children:m.map(e=>d(`li`,{children:d(pa,{row:e,failure:v(e),onToggle:()=>g(e)})},e.id))})]})]})}function pa({row:e,failure:t,onToggle:n}){let{t:r}=Z(),i=da[la(e.label)],o=e.on===null,s=e.on===!1,c=t===null?o?e.unavailableReason??`The source that owns this did not answer.`:e.costWhenOff:`Write failed: ${t}`,l=t===null?o?e.unavailableReason??`unknown`:null:`write failed`;return a(`button`,{type:`button`,role:`switch`,"aria-label":e.label,"aria-checked":e.on===!0,disabled:!e.available,onClick:n,title:c,className:`flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-[12px] text-foreground transition-colors hover:bg-surface-hover disabled:opacity-40 disabled:cursor-not-allowed`,children:[d(i,{className:`h-3.5 w-3.5 shrink-0 ${t===null?o?`text-foreground-subtle/50`:s?`text-warning`:`text-success`:`text-danger`}`}),a(`span`,{className:`flex-1 min-w-0 truncate`,children:[e.label,l!==null&&a(`span`,{className:`ml-1 text-[10px] text-foreground-subtle`,children:[`· `,l]})]}),d(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[9px] font-semibold uppercase tracking-wide ${o?`bg-surface-hover text-foreground-subtle/60`:s?`bg-warning/20 text-warning`:`bg-success/20 text-success`}`,children:o?`—`:r(s?`common.off`:`common.on`)})]})}function ma({deviceId:e}){let t=lr(U().trpcClient,e);return t===null?null:a(`a`,{href:t.url,target:`_blank`,rel:`noopener noreferrer`,title:`${t.label} — ${t.host}`,className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[d(p,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden sm:inline`,children:t.label})]})}function ha({parentDeviceId:e}){let{t}=Z(),n=Jr(),r=U(),{data:i,isLoading:o,isError:s}=Wr(e),{data:c}=sr({deviceId:e},{enabled:Number.isFinite(e)});if(o)return d(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:d(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(s)return d(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:d(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let l=(i??[]).filter(e=>e.display?.hidden!==!0);if(l.length===0)return null;let u=vn(c?.stableId??``,l,c?.childLayout),f=u.ungrouped,p=e=>n(`/devices/${String(e)}`),m=c?.name??``,h=(e,t)=>d(ar,{trpc:r.trpcClient,device:{...t,name:Xn(t,m)},variant:`minimal`,onNavigate:p},e),g=f.some(e=>!!e.role),_=f.some(e=>!e.role),v=g&&!_?t(`device.accessories`,{defaultValue:`Accessories`}):!g&&_?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),y=f.length>0?a(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[d(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:v}),d(`div`,{className:`space-y-1`,children:f.map(e=>h(e.id,e))})]}):null,b=u.disabledSection===void 0?null:d(vr,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:u.disabledSection.children.length,defaultOpen:!1,children:d(`div`,{className:`opacity-60 space-y-1`,children:u.disabledSection.children.map(e=>h(e.id,e))})},u.disabledSection.title);if(u.sections.length===0)return b===null?y:a(`div`,{className:`space-y-2`,children:[y,b]});let x=_&&!g;return a(`div`,{className:`space-y-2`,children:[x?y:null,u.sections.map(e=>d(vr,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>h(e.id,e))},e.title)),x?null:y,b]})}function ga({deviceId:e}){let t=U(),{data:n,isLoading:r}=Hr(e),{data:i,isLoading:a}=Wr(e),o=r||a,s=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),c=typeof n?.linkDeviceId==`number`?n.linkDeviceId:null,l=typeof n?.primaryChildEntityId==`string`?n.primaryChildEntityId:null;return o?d(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):d(`div`,{className:`flex h-full w-full flex-col`,children:d(un,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}e();function _a({dev:e,busy:t,setBusy:n}){let{t:i}=Z(),o=e?.motionTrigger,s=x(e?.state.motionTrigger),[c,l]=r(!1);if(!o)return null;let u=s?.enabled===!0,f=s!==void 0,p=async()=>{if(t||!f)return;let e=!u;n(!0),l(!0);try{await o.setMotionTrigger({enabled:e})}finally{n(!1),l(!1)}},m=c?u?`Disabling…`:`Enabling…`:f?u?`On motion: on`:`On motion: off`:`On motion: …`;return a(`button`,{type:`button`,onClick:()=>{p()},disabled:t||!f,title:f?u?i(`hero.motionTriggerToggle.disableTriggerOnMotion`,`Disable trigger on motion`):i(`hero.motionTriggerToggle.enableTriggerOnMotion`,`Enable trigger on motion`):i(`hero.motionTriggerToggle.awaitingState`,`Awaiting state…`),"aria-pressed":u,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${u?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[d(B,{className:`h-3 w-3`}),d(`span`,{children:m})]})}e();function Q({deviceId:e,deviceType:t,features:n}){let i=U(),o=Or(t)?.HeroCard??Jt,s=w(i.trpcClient,e),c=x(s?.state.deviceStatus),[l,u]=r(!1),f=c!==void 0&&c.online===!1,p=f?c.lastChangedAt:null;return a(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[f?d(`div`,{className:`flex justify-center`,children:d(kr,{lastChangedAt:p})}):null,d(o,{trpc:i.trpcClient,deviceId:e,features:n}),d(`div`,{className:`flex justify-center`,children:d(_a,{dev:s,busy:l,setBusy:u})})]})}function va({deviceId:e,features:t}){return d(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:d(ut,{trpc:U().trpcClient,deviceId:e,features:t})})}function ya({deviceId:e,features:t}){return d(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:d(Jt,{trpc:U().trpcClient,deviceId:e,features:t})})}function ba(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function xa(e){if(!e)return null;let t=ba(e.data);return t===null?e.eventType:X.t(`helpers.eventEmitterFormat.buttonHeadline`,{channel:String(t),eventType:e.eventType})}var Sa=1e3,Ca=60*Sa,wa=60*Ca,Ta=24*wa;function Ea(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<Sa?X.t(`helpers.relativeTime.justNow`):n<Ca?X.t(`helpers.relativeTime.secondsAgo`,{count:Math.floor(n/Sa)}):n<wa?X.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(n/Ca)}):n<Ta?X.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(n/wa)}):X.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(n/Ta)})}e();var Da=1500,Oa=15e3,ka=1e3;function Aa({deviceId:e}){let{t:n}=Z(),i=w(U().trpcClient,e)?.state.eventEmitter,o=x(i);t(()=>{if(!i)return;i.refresh();let e=setInterval(()=>{i.refresh()},Oa);return()=>{clearInterval(e)}},[i]);let s=o?.lastEvent??null,c=s?.seq??null,u=l(null),[f,p]=r(!1);t(()=>{if(c===null)return;let e=u.current;if(u.current=c,e===null||e===c)return;p(!0);let t=setTimeout(()=>{p(!1)},Da);return()=>{clearTimeout(t)}},[c]);let[m,h]=r(()=>Date.now());t(()=>{let e=setInterval(()=>{h(Date.now())},ka);return()=>{clearInterval(e)}},[]);let g=xa(s),_=o?.eventTypes??[],y=o?.eventCountSinceStart??0,b=o!==void 0,S=ba(s?.data);return a(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[d(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(f),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${f?`border-primary bg-primary/20 text-primary shadow-lg shadow-primary/30 scale-105`:`border-border bg-surface text-foreground-subtle`}`,"aria-live":`polite`,title:g??n(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`),children:d(f?v:A,{className:`h-10 w-10`})}),a(`div`,{className:`text-center`,children:[S!==null&&d(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:n(`hero.eventEmitterHero.button`,`Button {{value1}}`,{value1:String(S)})}),d(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${g?`text-foreground`:`text-foreground-subtle`}`,children:g??(b?n(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`):n(`hero.eventEmitterHero.awaitingState`,`Awaiting state…`))}),d(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:s?Ea(s.timestamp,m):n(`hero.eventEmitterHero.waitingForTheFirstEvent`,`Waiting for the first event`)})]}),_.length>0&&d(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:_.map(e=>d(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===s?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:n(`hero.eventEmitterHero.sinceStart`,{count:y})})]})}function ja({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){let{t:o}=Z();return a(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[d(Kr,{type:n,size:`lg`}),a(`div`,{children:[d(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),d(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),a(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[d(Mt,{status:r?`online`:`offline`}),i.length>0&&d(Gr,{capabilities:i})]}),d(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:o(`hero.genericHero.noLiveViewForThis`,`No live view for this device type. Use the Config tab or the shortcut row to interact.`)})]})}e();function Ma({deviceId:e}){let{t}=Z(),r=c(),i=en({deviceId:e},{refetchInterval:1e4,retry:!1}),o=wt({onSuccess:()=>{r.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),r.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),s=n(()=>Na(i.data??[]),[i.data]);return a(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[a(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[d(Pa,{label:t(`hero.hubHero.discovered`,`Discovered`),value:s.total,icon:d(ge,{className:`h-3.5 w-3.5`})}),d(Pa,{label:t(`hero.hubHero.adopted`,`Adopted`),value:s.adopted,accent:`success`}),d(Pa,{label:t(`hero.hubHero.available`,`Available`),value:s.available,accent:s.available>0?`primary`:void 0}),a(`button`,{type:`button`,onClick:()=>{o.mutateAsync({deviceId:e}).catch(()=>{})},disabled:o.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[o.isPending?d(ce,{className:`h-3.5 w-3.5 animate-spin`}):d(R,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden sm:inline`,children:t(`hero.hubHero.discover`,`Discover`)})]})]}),a(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[d(Fa,{icon:d(ie,{className:`h-3 w-3 text-emerald-500`}),label:t(`hero.hubHero.online`,`{{online}} online`,{online:s.online})}),d(Fa,{icon:d(T,{className:`h-3 w-3 text-amber-500`}),label:t(`hero.hubHero.sleeping`,`{{sleeping}} sleeping`,{sleeping:s.sleeping})}),d(Fa,{icon:d(L,{className:`h-3 w-3 text-destructive`}),label:t(`hero.hubHero.offline`,`{{offline}} offline`,{offline:s.offline})}),s.unknown>0?d(Fa,{icon:d(ae,{className:`h-3 w-3 text-foreground-subtle`}),label:t(`hero.hubHero.unknown`,`{{unknown}} unknown`,{unknown:s.unknown})}):null]})]})}function Na(e){let t={total:e.length,adopted:0,available:0,online:0,sleeping:0,offline:0,unknown:0};for(let n of e)n.alreadyAdopted?t.adopted+=1:t.available+=1,t[n.status]+=1;return t}function Pa({label:e,value:t,icon:n,accent:r}){return a(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${r===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:r===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[a(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,d(`span`,{className:`truncate`,children:e})]}),d(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function Fa({icon:e,label:t}){return a(`span`,{className:`inline-flex items-center gap-1`,children:[e,d(`span`,{children:t})]})}var Ia={[K.Switch]:Q,[K.Siren]:Q,[K.Light]:Q,[K.Sensor]:Q,[K.Button]:Q,[K.Hub]:Ma,[K.Cover]:va,[K.Valve]:Q,[K.Humidifier]:Q,[K.WaterHeater]:Q,[K.Container]:ga,[K.Lock]:Q,[K.Fan]:Q,[K.Thermostat]:Q,[K.Climate]:Q,[K.MediaPlayer]:Q,[K.Control]:Q,[K.AlarmPanel]:Q,[K.EventEmitter]:Aa,[K.Notifier]:ya,[K.Script]:Q,[K.Automation]:Q,[K.Presence]:Q,[K.Update]:Q,[K.Vacuum]:Q,[K.LawnMower]:Q,[K.Weather]:Q,[K.Image]:Q,[K.PetFeeder]:Q,[K.Dishwasher]:Q};function La(e){return Ia[e]??ja}function Ra(e){return d(La(e.deviceType),{...e})}function za(e){return nr(U().trpcClient,e)}e();function Ba(e){let[n,a]=r(`idle`),[o,s]=r(null),c=l(null),u=l(null),d=l(null),f=l(!0),p=Dn(),m=An(),h=ln(),g=i(()=>{if(c.current){try{c.current.close()}catch{}c.current=null}if(u.current){for(let e of u.current.getTracks())try{e.stop()}catch{}u.current=null}d.current=null},[]),_=i(async()=>{if(n===`idle`)return;a(`stopping`);let t=d.current;if(t&&e!==null)try{await Promise.race([h.mutateAsync({deviceId:e,sessionId:t}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}g(),f.current&&(a(`idle`),s(null))},[n,e,h,g]),v=i(async()=>{if(e===null||n!==`idle`&&n!==`error`)return;s(null);let t=null,r=null,i=null;try{a(`requesting-mic`),t=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),u.current=t,a(`starting`);let n=await p.mutateAsync({deviceId:e});i=n.sessionId,d.current=i,a(`connecting`),r=new RTCPeerConnection,c.current=r,r.oniceconnectionstatechange=()=>{if(!f.current)return;let e=r.iceConnectionState;e===`connected`||e===`completed`?a(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&f.current&&(s(e===`failed`?`WebRTC connection failed`:null),_())};for(let e of t.getAudioTracks())r.addTrack(e,t);await r.setRemoteDescription({type:`offer`,sdp:n.sdpOffer});let o=await r.createAnswer();await r.setLocalDescription(o);let l=r.localDescription?.sdp??o.sdp??``;await m.mutateAsync({deviceId:e,sessionId:i,sdpAnswer:l})}catch(n){let o=n instanceof Error?n.message:String(n);if(console.warn(`[intercom] start failed`,n),r)try{r.close()}catch{}if(t)for(let e of t.getTracks())try{e.stop()}catch{}if(c.current=null,u.current=null,i!==null)try{await h.mutateAsync({deviceId:e,sessionId:i})}catch{}d.current=null,f.current&&(s(o),a(`error`))}},[e,n,p,m,h,_]);return t(()=>(f.current=!0,()=>{f.current=!1;let t=d.current;if(t!==null&&e!==null&&h.mutate({deviceId:e,sessionId:t}),c.current){try{c.current.close()}catch{}c.current=null}if(u.current){for(let e of u.current.getTracks())try{e.stop()}catch{}u.current=null}d.current=null}),[e]),{state:n,error:o,start:v,stop:_,isTalking:n===`talking`}}e();var Va=0;function $(){return++Va}function Ha(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Ua(e){return[``,`Commands`,` help Show this help`,` examples Show usage examples for the current scope`,` context Show every available variable + full API surface`,` clear Clear terminal (also Ctrl+L)`,``,`Shortcuts`,` Enter Execute expression`,` Arrow Up/Down Navigate command history`,` Ctrl+L Clear terminal`,``,`Try: ${{system:` sm.summary() // fleet overview`,device:` device.state.battery.value?.sleeping // sync read`,provider:` devices.map(d => d.name)`,addon:` manifest.version`}[e.type]}`,``,`Top-level objects: sm (SystemMirror), DeviceType, Math, JSON, Date, …`]}function Wa(e){switch(e.type){case`device`:return[``,`── State (sync, zero round-trip) ─────────────────────────`,` device.state.battery.value`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,``,`── Actions (async, through wrapper chain) ────────────────`,` await device.snapshot.getSnapshot({})`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.switch.setState({ on: true })`,``,`── Wait for condition ───────────────────────────────────`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`── Subscribe to changes ─────────────────────────────────`,` const off = device.state.battery.subscribe(s => console.log(s))`,``,`── Quick info ───────────────────────────────────────────`,` info.name device name`,` info.addonId owning addon`,` sm.dump(deviceId) full debug dump`];case`system`:return[``,`── Lookups ──────────────────────────────────────────────`,` sm.getDeviceById(8)`,` sm.getDeviceByName('Sala da pranzo')`,` sm.getDevicesByAddon('reolink')`,` sm.getDevicesByType(DeviceType.Camera)`,``,`── Filters (typed query) ────────────────────────────────`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] })`,` sm.query({ name: /^Cam-/ })`,``,`── Cross-device ─────────────────────────────────────────`,` sm.whereState('battery', s => s.percentage < 20).length`,` sm.mapState('battery', s => s.percentage)`,` sm.countByCap('snapshot')`,``,`── Batch action ─────────────────────────────────────────`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,``,`── Listen ───────────────────────────────────────────────`,` sm.listenCap('motion', (id, s) => console.log(id, s))`,` sm.onDeviceAdded((id, info) => console.log('+', info.name))`,``,`── Diagnostics ──────────────────────────────────────────`,` sm.summary()`,` sm.dump(8)`];case`provider`:return[``,` devices.map(d => d.name)`,` await getIntegration()`,` sm.getDevicesByAddon('<this-addon-id>').length`];case`addon`:return[``,` manifest.name`,` manifest.version`,` declaration`]}}function Ga(e){let t=[``,`Scope: ${e.type}`,``];switch(e.type){case`system`:return[...t,`Primary API — sm (SystemMirror):`,` sm.getDeviceById(id) DeviceProxy | null (sync)`,` sm.getDeviceByName(name) DeviceProxy | null`,` sm.getDeviceByStableId(sid) DeviceProxy | null`,` sm.getAllDevices() readonly DeviceProxy[]`,` sm.getDeviceInfo(id) DeviceInfo | null`,` sm.summary() fleet stats`,``,`Filters — sm.query({...}):`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] }) // ALL caps required`,` sm.query({ anyCap: ['ptz', 'motion'] }) // ANY cap`,` sm.query({ name: { contains: 'sala' } }) // case-insensitive`,` sm.query({ name: /^Cam-\\d+$/ })`,` sm.query({ type: DeviceType.Camera })`,` sm.query({ parentDeviceId: 8 }) // accessories of cam 8`,` sm.query({ where: (info, dev) => dev.state.battery.value?.sleeping })`,``,`State queries:`,` sm.whereState('battery', s => s.percentage < 20)`,` sm.mapState('battery', s => s.percentage)`,` sm.findState('motion', s => s.detected)`,` sm.countByCap('snapshot')`,``,`Listeners (return unsubscribe fn):`,` sm.listen((id, cap, slice) => …) // every state change`,` sm.listenCap('motion', (id, slice) => …)`,` sm.listenDevice(8, (id, cap, slice) => …)`,` sm.onDeviceAdded((id, info) => …)`,` sm.onDeviceRemoved((id, info) => …)`,``,`Wait primitives:`,` await sm.waitForState(8, 'battery', s => !s.sleeping, 30_000)`,` await sm.waitForDevice(99, 30_000)`,``,`Batch:`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,` await sm.forEachCap('reboot', d => d.reboot.reboot({}))`,``,`Diagnostics:`,` sm.dump(8) debug dump (one device)`,` sm.dump() full fleet dump`,` sm.summary() breakdown by cap/addon/type`,``,`Legacy: deviceRegistry, addonRegistry, eventBus, devices(), addons()`];case`device`:return[...t,`Pre-bound variables:`,` device DeviceProxy for this device (sync state + async methods)`,` deviceId number`,` info DeviceInfo metadata (name, addonId, type, online, …)`,` sm SystemMirror (full cluster view)`,` rawDevice legacy IDevice instance (escape hatch)`,``,`Reactive state (sync, zero round-trip):`,` device.state.battery.value BatteryStatus | undefined`,` device.state.battery.value?.sleeping`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,` device.state.switch.value?.on`,` device.state.brightness.value?.percentage`,` device.state.doorbell.value?.lastPressedAt`,``,`Cap actions (async, through wrapper chain):`,` await device.snapshot.getSnapshot({})`,` await device.snapshot.getSnapshot({ streamId: 'high' })`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.ptz.goToPreset({ presetId: 'home' })`,` await device.switch.setState({ on: true })`,` await device.brightness.setBrightness({ percentage: 60 })`,` await device.reboot.reboot({})`,``,`Subscribe to slice changes:`,` const off = device.state.battery.subscribe(s => console.log(s))`,` // off() to unsubscribe`,``,`Wait for a state condition:`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`Diagnostics:`,` info.name device name`,` info.addonId which addon owns it`,` info.online transport health`,` sm.dump(deviceId) full debug dump (binding + state + info)`];case`provider`:return[...t,`Pre-bound variables:`,` devices Devices belonging to this provider (raw IDevice[])`,` getIntegration() Integration metadata`,``,`For typed device access use the SystemMirror:`,` await getSystemMirror()`,` sm.getDevicesByAddon('this-addon-id')`];case`addon`:return[...t,`Pre-bound variables:`,` manifest { name, version, ... }`,` declaration addon declaration`,` source addon source location`,``,`Examples:`,` manifest.name`,` manifest.version`]}}function Ka({scope:e,greeting:n,className:o}){let{t:s}=Z(),c=U(),[f,p]=r(()=>{let t=[];return n&&t.push({id:$(),kind:`info`,text:n}),t.push({id:$(),kind:`info`,text:`scope: ${Ha(e)} — type help or context for available commands`}),t}),[m,h]=r(``),[g,_]=r([]),[v,y]=r(-1),b=l(null),x=l(null);t(()=>{let e=x.current;e&&(e.scrollTop=e.scrollHeight)},[f]);let S=i(()=>{b.current?.focus()},[]),C=u({mutationFn:t=>c.trpcClient.repl.execute.mutate({code:t,scope:e}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;p(e=>[...e,{id:$(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);p(e=>[...e,{id:$(),kind:`error`,text:t}])}});function w(t){let n=t.trim();if(n){if(n===`clear`){p([{id:$(),kind:`info`,text:`scope: ${Ha(e)}`}]),h(``);return}if(n===`help`){p(t=>[...t,{id:$(),kind:`input`,text:`> ${n}`},...Ua(e).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}if(n===`context`){p(t=>[...t,{id:$(),kind:`input`,text:`> ${n}`},...Ga(e).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}if(n===`examples`){p(t=>[...t,{id:$(),kind:`input`,text:`> ${n}`},...Wa(e).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}_(e=>[...e,n]),y(-1),p(e=>[...e,{id:$(),kind:`input`,text:`> ${n}`}]),h(``),C.mutate(n)}}function T(t){if(t.key===`Enter`){t.preventDefault(),w(m);return}if(t.key===`ArrowUp`){if(t.preventDefault(),g.length===0)return;let e=v===-1?g.length-1:Math.max(0,v-1);y(e),h(g[e]??``);return}if(t.key===`ArrowDown`){if(t.preventDefault(),v===-1)return;let e=v+1;e>=g.length?(y(-1),h(``)):(y(e),h(g[e]??``));return}t.ctrlKey&&t.key===`l`&&(t.preventDefault(),p([{id:$(),kind:`info`,text:`scope: ${Ha(e)}`}]))}let E={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return a(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${o??``}`,onClick:S,children:[a(`div`,{ref:x,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[f.map(e=>d(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${E[e.kind]}`,children:e.text},e.id)),C.isPending&&d(`span`,{className:`text-zinc-500 animate-pulse`,children:s(`shared.replTerminal.thinking`,`…thinking`)})]}),a(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[d(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:s(`shared.replTerminal.text`,`>`)}),d(`input`,{ref:b,value:m,onChange:e=>h(e.target.value),onKeyDown:T,disabled:C.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function qa(e,t){return e===null?null:{playbackUrl:e.url,...e.format===void 0?{}:{playbackFormat:e.format},playbackAuthToken:t,...e.label===void 0?{}:{playbackLabel:e.label}}}e();function Ja({deviceId:e,intercomAvailable:t=!1}){let r=U(),i=typeof window<`u`?te():``,a=Number.isFinite(e),o=za(a?e:null),c=Gi(a?[e]:[]),l=n(()=>{if(!a)return;let e=[];for(let t of c.rows){let n=fn(t);n!==null&&e.push(n)}return e},[a,c.rows]),{streams:u,pipelineMetrics:f,createSession:p,sendAnswer:m,handleOffer:h,getIceServers:g,addIceCandidate:v,getIceCandidates:y,closeSession:b,getSessionState:x,applyDownlinkProbe:S}=tn(r.trpcClient,a?e:null),C=_(a?e:null,{width:$a}),w=Ba(a&&t?e:null),T=w.state===`requesting-mic`||w.state===`starting`||w.state===`connecting`||w.state===`stopping`,E=w.isTalking||T,D=()=>{w.state===`idle`||w.state===`error`?w.start():w.state!==`stopping`&&w.stop()},O=de(),k=Kt(),A=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,j=qa(k.request,A),M=O.length>0?d(s,{children:O.map(e=>d(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return d(Dr,{serverUrl:i,createSession:p,sendAnswer:m,handleOffer:h,getIceServers:g,addIceCandidate:v,getIceCandidates:y,closeSession:b,getSessionState:x,applyDownlinkProbe:S,...j===null?{}:{...j,onExitPlayback:()=>k.clear()},streams:u,pipelineMetrics:f,phase:o.phase,detections:o,...l===void 0?{}:{stationaryObjects:l},defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:C.src,...C.src?{posterUrl:C.src}:{},snapshotLoading:C.loading,onRefreshSnapshot:C.refresh,intercomAvailable:t,intercomShown:E,onIntercomToggle:D,extraOverlay:M,chromeless:!0,className:`h-full`})}function Ya({deviceId:e,containerDeviceId:t}){let{t:n}=Z();return Number.isFinite(e)?d(`div`,{className:`flex flex-col h-full`,children:d(pt,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):d(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:n(`device.panelContent.notLoaded`,{id:e})})}function Xa({deviceId:e}){let{t}=Z();if(!Number.isFinite(e))return d(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:t(`device.panelContent.notLoaded`,{id:e})});let n=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
|
|
2
|
-
`);return d(Ka,{scope:{type:`device`,deviceId:e},greeting:n,className:`h-full border-0 rounded-none`})}function Za({deviceId:e}){let{t}=Z();return Number.isFinite(e)?d(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:d(gt,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):d(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:t(`device.panelContent.notLoaded`,{id:e})})}function Qa({deviceId:e}){let{t}=Z();return Number.isFinite(e)?d(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:d(Zt,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):d(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:t(`device.panelContent.notLoaded`,{id:e})})}var $a=960;function eo(e){return new Set(e.filter(e=>{let t=e.nativeAddonId?.trim()??``;return t!==``&&t!==`composer`}).map(e=>e.capName))}function to(e){return e.kind===`known`?null:e}function no(e,t){return e.composable.kind===`known`?e.composable.value.has(t)?{kind:`present`,mode:`add`}:{kind:`absent`}:e.composable}function ro(e){if(e.deviceType!==K.Camera)return{kind:`absent`};switch(e.cameraSensors){case`pending`:return{kind:`pending`};case`unknown`:return{kind:`unknown`,reason:X.t(`helpers.assignmentAvailability.sensorsUnchecked`)};case`absent`:return{kind:`absent`};case`present`:return{kind:`present`,mode:`add`}}}function io(e,t){if(e===`motion`)return ro(t);let n=to(t.nativeCaps);if(n!==null)return n;let r=t.nativeCaps.kind===`known`?t.nativeCaps.value:new Set;switch(e){case`doorbell`:return r.has(`doorbell`)?{kind:`absent`}:no(t,`doorbell`);case`battery`:return r.has(`battery`)?{kind:`present`,mode:`replace`}:no(t,`battery`);case`consumables`:return r.has(`consumables`)?{kind:`absent`}:no(t,`consumables`)}}function ao({onAdvanced:e}){let{t}=Z();return e===void 0?null:d(`button`,{type:`button`,className:`rounded text-left text-[11px] text-primary hover:underline focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary`,onClick:e,children:t(`customize.advancedLink`)})}function oo(e){if(e.status===`pending`)return{kind:`pending`};if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??X.t(`helpers.customize.requestFailed`)};let t=e.data;if(t===void 0)return{kind:`pending`};if(t.state===`not-loaded`)return{kind:`not-loaded`,reason:t.reason};if(t.view===null)return{kind:`none`};let n=Ie(t.view.block);return n===null?{kind:`unknown`,reason:X.t(`helpers.customizationRead.notAComposition`,{id:t.view.block.id})}:{kind:`present`,view:t.view,composition:n}}function so(e){return e.kind===`present`?e.composition:null}function co(e,t){let{hidden:n,...r}=e??{},i=t?{...r,hidden:!0}:r;return Object.keys(i).length===0?null:i}function lo(e){return typeof e.linkDeviceId==`number`}var uo=new Set(Object.values(G));function fo(e){return uo.has(e)}var po={[K.Switch]:[G.Siren,G.Floodlight,G.Spotlight,G.PirSensor,G.Chime,G.Autotrack,G.Nightvision,G.PrivacyMask,G.BinaryHelper],[K.Light]:[G.Floodlight,G.Spotlight,G.Nightvision],[K.Siren]:[G.Siren],[K.Button]:[G.Doorbell],[K.Sensor]:[G.MotionSensor,G.ContactSensor,G.LeakSensor,G.SmokeSensor,G.COSensor,G.GasSensor,G.TamperSensor,G.VibrationSensor,G.ConnectivitySensor,G.SoundSensor,G.BinarySensor,G.TemperatureSensor,G.HumiditySensor,G.AmbientLightSensor,G.PressureSensor,G.WindSensor,G.RainSensor,G.UvSensor,G.SolarRadiationSensor,G.SoilMoistureSensor,G.PowerSensor,G.EnergySensor,G.VoltageSensor,G.CurrentSensor,G.AirQualitySensor,G.BatterySensor,G.NumericSensor,G.EnumSensor,G.DateTimeSensor,G.GenericSensor],[K.Control]:[G.NumericControl,G.SelectControl,G.TextControl,G.DateTimeControl],[K.Notifier]:[G.MobilePushNotifier,G.MessagingNotifier,G.EmailNotifier,G.GenericNotifier]};function mo(e){for(let t of Object.values(K))if(t===e)return!0;return!1}function ho(e){return mo(e)?po[e]??[]:[]}function go(e,t){let n=ho(t);return e==null||e===``||n.includes(e)?n:[...n,e]}e();function _o({device:e}){let{t}=Z(),n=H(),i=c(),[o,s]=r(null),l=()=>s(null),u={onSuccess:()=>{l(),i.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>s(e.message)},f=Ar(),p=Nt(),h=e.display?.hidden===!0;return a(`section`,{"aria-label":t(`customize.identity.title`),className:`${D} ${m}`,children:[a(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[d(ei,{deviceId:e.id,initialName:e.name,label:t(`customize.identity.name`),layout:`stacked`,onError:s,onSaved:l,onCancel:l}),d(Lr,{deviceId:e.id,initialLocation:e.location,label:t(`customize.identity.room`),layout:`stacked`,onError:s,onSaved:l,onCancel:l}),d(Ir,{label:t(`customize.identity.hidden`),layout:`stacked`,value:d(hr,{"aria-label":t(`deviceDisplay.hideFromLists`),checked:h,disabled:p.isPending,onChange:t=>p.mutate({deviceId:e.id,display:co(e.display,t.target.checked)},u)})}),d(Ir,{label:t(`customize.identity.role`),layout:`stacked`,value:lo(e)?d(`span`,{children:vo(e.role,t(`customize.identity.noRole`),n)}):d(on,{"aria-label":t(`customize.identity.role`),value:e.role??``,disabled:f.isPending,options:[{value:``,label:t(`customize.identity.noRole`)},...go(e.role,e.type).map(e=>({value:e,label:vo(e,t(`customize.identity.noRole`),n)}))],onChange:t=>f.mutate({deviceId:e.id,role:t.target.value===``?null:t.target.value},u)})})]}),o!==null&&d(`p`,{role:`alert`,className:`mt-2 text-xs text-danger break-words`,children:o})]})}function vo(e,t,n){return e==null||e===``?t:fo(e)?Zn(e,n).label:e}e();function yo(e){return e===`pending`?`pending`:e===`error`?`failed`:`answered`}function bo({excludeDeviceIds:e,onSelect:t}){let{t:r}=Z(),i=sn({projection:`slim`}),a=i.status===`success`?i.data:null,o=n(()=>{if(a===null)return[];let t=new Set(e);return li(a).filter(e=>!t.has(e.id))},[a,e]),s=n(()=>new Map(o.map(e=>[e.id,e])),[o]),c=n(()=>o.map(e=>({id:e.id,name:e.name,type:e.type,...e.location===null?{}:{location:e.location}})),[o]);if(i.status===`error`)return d(jr,{title:r(`customize.picker.devicesFailed`),message:i.error?.message??``});let l=e=>{let n=s.get(e);n!==void 0&&t(n)};return d(yn,{devices:c,listState:yo(i.status),value:[],onChange:e=>{let t=e.at(-1);t!==void 0&&l(t)},noun:`device`,emptyLabel:r(`customize.assign.none`),showAll:!0,testId:`customize-field-device-picker`})}function xo({open:e,title:t,targetKind:n,excludeDeviceIds:i,confirmLabel:o,extra:c,extraComplete:l=!0,onConfirm:u,onClose:f}){let{t:p}=Z(),[m,h]=r(null),[g,_]=r(null),v=()=>{h(null),_(null),f()};return d(ft,{open:e,onOpenChange:e=>e?void 0:v(),children:a(Vn,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":t,children:[d(Ft,{children:d(Rt,{children:t})}),d(Vt,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:e&&a(s,{children:[a(`section`,{"aria-label":p(`customize.assign.stepDevice`),className:`flex flex-col gap-1`,children:[d(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:p(`customize.assign.stepDevice`)}),m===null?d(bo,{excludeDeviceIds:i,onSelect:h}):a(`p`,{className:`flex items-center gap-2 text-xs text-foreground`,children:[m.name,d(Y,{variant:`ghost`,size:`sm`,onClick:()=>{h(null),_(null)},children:p(`customize.assign.change`)})]})]}),m!==null&&a(`section`,{"aria-label":p(`customize.assign.stepField`),className:`flex flex-col gap-1`,children:[d(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:p(`customize.assign.stepField`)}),d(si,{device:m,targetKind:n,selected:g===null?null:{cap:g.cap,path:g.path},onPick:_,onBack:()=>{h(null),_(null)}})]}),m!==null&&c!==void 0&&a(`section`,{"aria-label":p(`customize.assign.stepDetails`),className:`flex flex-col gap-1`,children:[d(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:p(`customize.assign.stepDetails`)}),c]})]})}),a(Ln,{children:[d(Y,{variant:`ghost`,onClick:v,children:p(`customize.assign.cancel`)}),d(Y,{disabled:g===null||!l,onClick:()=>{g!==null&&(u(g),h(null),_(null))},children:o})]})]})})}function So(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Co(e,t){let n=xi(e,t);return n===void 0?{kind:`absent`}:{kind:`value`,value:n}}function wo(e,t,n){return So(t)?Co(t,n):e.status===`error`?{kind:`unknown`,reason:e.error?.message??X.t(`helpers.liveValue.unreadable`)}:e.status===`pending`||e.data===void 0?{kind:`pending`}:e.data===null?{kind:`absent`}:Co(e.data,n)}function To(e,t,n){let r=e?`active`:`muted`;return t.cap===`contact`&&t.path===`entryOpen`?{text:e?n.open:n.closed,tone:r}:be[t.cap]===t.path?{text:e?n.active:n.inactive,tone:r}:{text:String(e),tone:`normal`}}function Eo(e,t,n){switch(e.kind){case`pending`:return{text:`…`,tone:`muted`};case`unknown`:return{text:`?`,title:e.reason,tone:`warning`};case`absent`:return{text:`—`,tone:`muted`};case`value`:{let r=e.value;return r===null?{text:`—`,tone:`muted`}:typeof r==`boolean`?To(r,t,n):typeof r==`number`?{text:t.path===`percentage`?`${Math.round(r)} %`:String(r),tone:`normal`}:typeof r==`string`?{text:r,tone:`normal`}:{text:JSON.stringify(r),tone:`normal`}}}}var Do=0;function Oo(e){let t=U(),n=yt({deviceId:e?.deviceId??Do,capName:e?.cap??``},{enabled:e!==null}),r=mr(t.trpcClient,e?.deviceId??null,e?.cap??``);return e===null?{kind:`absent`}:wo({status:n.status,data:n.data,error:n.error===null||n.error===void 0?null:{message:n.error.message}},r,e.path)}var ko={muted:`text-foreground-subtle`,active:`text-success`,normal:`text-foreground`,warning:`text-warning`};function Ao({target:e}){let{t}=Z(),n=Oo(e);return e===null?null:d(jo,{display:Eo(n,e,{active:t(`customize.assign.value.active`),inactive:t(`customize.assign.value.inactive`),open:t(`customize.assign.value.open`),closed:t(`customize.assign.value.closed`)})})}function jo({display:e}){return d(`span`,{className:`text-xs ${ko[e.tone]}`,title:e.title,children:e.text})}function Mo({name:e,detail:t,meta:n,value:r,shown:i,problem:o,onRemove:s,removeLabel:c,busy:l=!1}){return a(`li`,{className:`${M} grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-1 sm:grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,1fr)_1.75rem]`,children:[a(`div`,{className:`min-w-0`,children:[d(`div`,{className:`text-xs text-foreground break-words`,children:e}),t!==null&&d(`div`,{className:`text-[11px] text-foreground-subtle break-words`,children:t}),o!==void 0&&d(`div`,{role:`alert`,className:`text-[11px] text-warning break-words`,children:o})]}),d(`div`,{className:`row-start-2 col-start-1 text-[11px] text-foreground-subtle empty:hidden sm:row-start-auto sm:col-start-auto sm:empty:block`,children:n}),d(`div`,{className:`row-start-3 col-start-1 empty:hidden sm:row-start-auto sm:col-start-auto sm:empty:block`,children:i===void 0?d(Ao,{target:r}):i!==null&&d(jo,{display:i})}),d(`div`,{className:`row-start-1 col-start-2 flex justify-end sm:row-start-auto sm:col-start-auto`,children:s!==void 0&&d(pr,{icon:re,variant:`ghost`,size:`sm`,"aria-label":c,disabled:l,onClick:s})})]})}function No({id:e,...t}){return d($t,{headingId:`customize-${e}`,...t})}function Po({id:e,icon:t,title:n,headerControl:r,addLabel:i,onAdd:o,addDisabled:c=!1,notices:l,suggestion:u,children:f}){let{t:p}=Z(),m=o!==void 0&&i!==void 0;return a(No,{id:e,icon:t,title:n,actions:a(s,{children:[r,m&&!c&&u!==void 0&&u.count>0&&a(Y,{variant:`ghost`,size:`sm`,onClick:u.onOpen,children:[d(I,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),p(`customize.suggest.hint`,{count:u.count,location:u.location})]}),m&&d(Y,{variant:`outline`,size:`sm`,disabled:c,onClick:o,children:i})]}),children:[l!==void 0&&d(`div`,{className:`flex flex-col gap-1 px-3 pt-2 empty:hidden sm:px-4`,children:l}),d(`ul`,{className:`flex flex-col divide-y divide-border`,children:f})]})}function Fo({availability:e}){let{t}=Z();return e.kind===`pending`?d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.assign.checking`)}):e.kind===`unknown`?d(`p`,{role:`alert`,className:`text-xs text-warning`,children:t(`customize.assign.unknown`,{reason:e.reason})}):null}function Io(e,t){if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??X.t(`helpers.customize.requestFailed`)};let n=e.data;return e.status===`pending`||n===void 0?{kind:`pending`}:{kind:`known`,value:t(n)}}function Lo(e,t){let n=Yt.useQueries(n=>e.map(e=>n.deviceManager.listDeviceIdsByCaps({capNames:[e]},{enabled:t})));return ia(e.map((e,t)=>{let r=n[t];return{cap:e,query:r===void 0?{status:`pending`}:{status:r.status,data:r.data,error:r.error===null?null:{message:r.error.message}}}}))}e();function Ro(e,t){let n=Fn(e,t);return n.kind===`resolved`?n.integration.name:null}function zo(e){let t=sn({projection:`slim`},{enabled:e}),{data:r}=xn(void 0,{enabled:e}),i=t.error===null||t.error===void 0?null:t.error.message;return n(()=>Io({status:t.status,data:t.data,error:i===null?null:{message:i}},e=>e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,type:e.type,location:e.location,isCamera:e.isCamera,integration:Ro(e,r),parentDeviceId:e.parentDeviceId,primaryChildEntityId:e.primaryChildEntityId??null,role:e.role??null}))),[t.status,t.data,i,r])}function Bo(e){let t=zo(e.enabled),n=Lo(Ce,e.enabled);return t.kind===`unknown`?t:n.kind===`unknown`?n:t.kind===`pending`||n.kind===`pending`?{kind:`pending`}:{kind:`known`,value:ea({devices:t.value,capIndex:n.value,hostId:e.hostId,excludeCameras:e.excludeCameras,assigned:e.assigned,preferredCap:e.preferredCap})}}function Vo(){let{t:e}=Z(),t=it();return(n,r)=>t({title:e(`customize.assign.removeConfirm.title`),message:r?`${e(`customize.assign.removeConfirm.message`,{what:n})} ${e(`customize.assign.removeConfirm.last`)}`:e(`customize.assign.removeConfirm.message`,{what:n}),confirmLabel:e(`customize.assign.removeConfirm.confirm`),variant:`danger`})}e();function Ho(e){return e===null?null:pi(e,`replace`)?`replace`:pi(e,`add`)?`add`:null}function Uo({device:e,handle:t,availability:n,onAdvanced:i}){let{t:o}=Z(),c=Vo(),[l,u]=r(!1),[p,m]=r(null),h=so(t.state),g=Ei(h,`battery`),_=Ho(g),v=_===null?null:oi(g?.fields.percentage),y=zo(v!==null);if(n.kind===`absent`)return null;let b=n.kind===`present`?n.mode:null,x=t.state.kind===`none`||t.state.kind===`present`,S=v===null||y.kind!==`known`?null:y.value.find(e=>q({addonId:e.addonId,stableId:e.stableId})===q(v.source))??null,C=v===null?``:S?.name??q(v.source),w=async e=>{let n=await t.save(e);m(n.kind===`refused`?n.reason:null)},T=async()=>{if(h===null)return;let e=ni(h,`battery`);await c(o(`customize.battery.removeWhat`,{name:C}),e===null)&&await w(e)},E=b!==null&&x&&g===null&&!t.saving;return a(s,{children:[a(Po,{id:`battery`,icon:f,title:o(`customize.battery.title`),addLabel:o(b===`replace`?`customize.battery.replace`:`customize.battery.add`),onAdd:E?()=>u(!0):void 0,notices:a(s,{children:[d(Fo,{availability:n}),v!==null&&y.kind===`unknown`&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:o(`customize.assign.devicesUnreadable`,{reason:y.reason})}),p!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:p})]}),children:[b===`replace`&&x&&d(Mo,{name:o(`customize.battery.native`),detail:null,meta:o(g===null?`customize.assign.native`:`customize.battery.nativeReplaced`),value:g===null?{deviceId:e.id,cap:`battery`,path:`percentage`}:null,removeLabel:``}),g===null&&b===`add`&&x&&d(`li`,{className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:o(`customize.assign.none`)}),v!==null&&d(Mo,{name:C,detail:`${v.cap}.${v.fieldPath}`,meta:o(_===`replace`?`customize.assign.replaces`:`customize.assign.adds`),value:S===null?null:{deviceId:S.id,cap:v.cap,path:v.fieldPath},problem:S===null&&y.kind===`known`?o(`customize.assign.missingKept`):void 0,onRemove:x?()=>void T():void 0,removeLabel:o(`customize.assign.removeNamed`,{name:C}),busy:t.saving}),g!==null&&v===null&&d(Mo,{name:o(`customize.battery.otherFormula`),detail:null,meta:d(ao,{onAdvanced:i}),value:{deviceId:e.id,cap:`battery`,path:`percentage`},removeLabel:``})]}),d(xo,{open:l,title:o(b===`replace`?`customize.battery.replace`:`customize.battery.add`),targetKind:`number`,excludeDeviceIds:[e.id],confirmLabel:o(`customize.assign.add`),onConfirm:e=>{u(!1);let n=b===null?null:Ci({percentage:{source:e.ref,cap:e.cap,fieldPath:e.path,kind:e.kind},mode:b});n===null?m(o(`customize.assign.pickUnusable`)):w(ai(h,t.target,n))},onClose:()=>u(!1)})]})}e();function Wo(e,t){let n=e.source;if(n===null||t.kind!==`known`)return null;let r=q(n.source);return t.value.find(e=>q({addonId:e.addonId,stableId:e.stableId})===r)??null}function Go(e){let t=typeof e==`number`?e:typeof e==`string`?Number(e):NaN;return Number.isFinite(t)?t:null}function Ko({device:e,handle:t,availability:n,onAdvanced:i}){let{t:o}=Z(),c=Vo(),[l,u]=r(!1),[f,p]=r(``),[m,h]=r(`percent`),[g,_]=r(null),v=so(t.state),y=Ei(v,`consumables`),b=di(y),x=zo(b.some(e=>e.source!==null));if(n.kind===`absent`)return null;let S=t.state.kind===`none`||t.state.kind===`present`,C=n.kind===`present`&&S&&!t.saving,w=fi(f),T=b.find(e=>e.key===w)??null,E=T!==null,D=f.trim()!==``&&w===``,k=async e=>{let n=await t.save(e);_(n.kind===`refused`?n.reason:null)},A=()=>{u(!1),p(``),h(`percent`)},j=async e=>{if(y===null||v===null)return;let n=wi(y,e.key),r=n===null?ni(v,`consumables`):ai(v,t.target,n);await c(o(`customize.consumables.removeWhat`,{name:e.label}),r===null)&&await k(r)},M=a(`div`,{className:`flex flex-wrap items-end gap-2`,children:[a(`label`,{className:`flex w-full flex-col gap-1 text-[11px] text-foreground-subtle sm:w-56`,children:[o(`customize.consumables.name`),d(tr,{"aria-label":o(`customize.consumables.name`),value:f,onChange:e=>p(e.target.value)})]}),a(`label`,{className:`flex w-full flex-col gap-1 text-[11px] text-foreground-subtle sm:w-40`,children:[o(`customize.consumables.unit`),d(on,{"aria-label":o(`customize.consumables.unit`),value:m,options:hi.map(e=>({value:e,label:o(`customize.consumables.units.${e}`)})),onChange:e=>{let t=hi.find(t=>t===e.target.value);t!==void 0&&h(t)}})]}),E&&d(`p`,{role:`alert`,className:`basis-full text-xs text-warning`,children:o(`customize.consumables.takenBy`,{name:T.label})}),D&&d(`p`,{role:`alert`,className:`basis-full text-xs text-warning`,children:o(`customize.consumables.keyless`)})]});return a(s,{children:[a(Po,{id:`consumables`,icon:O,title:o(`customize.consumables.title`),addLabel:o(`customize.consumables.add`),onAdd:C?()=>u(!0):void 0,notices:a(s,{children:[d(Fo,{availability:n}),x.kind===`unknown`&&b.some(e=>e.source!==null)&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:o(`customize.assign.devicesUnreadable`,{reason:x.reason})}),g!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:g})]}),children:[b.map(e=>{let n=e.source;if(e.unit===null||n===null)return d(Mo,{name:e.label,detail:o(`customize.consumables.otherFormula`),meta:d(ao,{onAdvanced:i}),value:null,removeLabel:``},e.key);let r=Wo(e,x),a=r?.name??q(n.source);return d(Mo,{name:e.label,detail:`${o(`customize.consumables.units.${e.unit}`)} · ${a}`,meta:`${n.cap}.${n.fieldPath}`,value:r===null?null:{deviceId:r.id,cap:n.cap,path:n.fieldPath},problem:r===null&&x.kind===`known`?o(`customize.assign.missingKept`):void 0,onRemove:S?()=>void j(e):void 0,removeLabel:o(`customize.assign.removeNamed`,{name:e.label}),busy:t.saving},e.key)}),b.length===0&&n.kind===`present`&&S&&d(`li`,{className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:o(`customize.assign.none`)})]}),d(xo,{open:l,title:o(`customize.consumables.pickTitle`),targetKind:`number`,excludeDeviceIds:[e.id],confirmLabel:o(`customize.assign.add`),extra:M,extraComplete:w!==``&&!E,onConfirm:e=>{let n=Go(e.value);if(n!==null&&(n<0||m===`percent`&&n>100)){A(),_(o(`customize.consumables.outOfRange`,{value:n}));return}let r=ui(y,{key:w,label:f,remaining:{source:e.ref,cap:e.cap,fieldPath:e.path,kind:e.kind},unit:m});A(),r===null?_(o(`customize.assign.pickUnusable`)):k(ai(v,t.target,r))},onClose:A})]})}function qo(e,t){if(e.kind!==`known`||typeof t!=`string`||t.length===0)return null;let n=Gn(e.value,t),r=new Map(e.value.map(e=>[e.id,e])),i=new Map;for(let e of n){let t=r.get(e)?.parentDeviceId,n=t==null?void 0:r.get(t);n!==void 0&&n.type===`container`&&i.set(e,n.name)}return{location:t,ids:n,containers:i}}function Jo(e,t,n){return _n(e,t?.ids??new Set,n)}function Yo(e,t){return e?.containers.get(t)??null}function Xo(e,t,n){return e.kind===`known`?Jo(e.value,t,n).suggested.length:0}function Zo(e,t){let n=[t,e.detail].filter(e=>e!==null&&e!==``);return n.length===0?null:n.join(` · `)}function Qo({location:e,devices:t,action:n,onPick:r,onPickAll:i}){let{t:o}=Z();if(t.length===0)return null;let s=o(`customize.suggest.heading`,{location:e});return a(`section`,{"aria-label":s,className:`flex flex-col gap-1`,children:[a(`div`,{className:`flex min-h-7 items-center gap-2`,children:[d(`h3`,{className:`${ee} min-w-0 flex-1`,children:s}),i!==void 0&&t.length>1&&d(Y,{variant:`ghost`,size:`sm`,onClick:i,children:o(`customize.suggest.addAll`,{count:t.length})})]}),d(`ul`,{className:`flex flex-col divide-y divide-border rounded-md border border-border`,children:t.map(e=>{let t=Zo(e,e.container===null||e.name.includes(e.container)?null:o(`customize.suggest.in`,{container:e.container}));return a(`li`,{className:`${M} flex items-center gap-3`,children:[a(`div`,{className:`min-w-0 flex-1`,children:[d(`div`,{className:`text-xs text-foreground break-words`,children:e.name}),t!==null&&d(`div`,{className:`text-[11px] text-foreground-subtle break-words`,children:t})]}),d(Y,{variant:`outline`,size:`sm`,"aria-label":o(n===`add`?`customize.suggest.addNamed`:`customize.suggest.useNamed`,{name:e.name}),onClick:()=>r(e.id),children:o(n===`add`?`customize.suggest.add`:`customize.suggest.use`)})]},e.id)})})]})}e();function $o(e){return e.kind===`pending`?`pending`:e.kind===`unknown`?`failed`:`answered`}function es(e){return e.map(e=>({id:e.deviceId,name:e.name,...e.meta===null?{}:{type:e.meta},...e.detail===null?{}:{location:e.detail.includes(` · `)?e.detail.split(` · `).at(-1)??null:e.detail},...e.detail===null?{}:{detail:e.detail}}))}function ts({open:e,title:i,selection:o,candidates:s,filters:c,room:l=null,confirmLabel:u,onConfirm:f,onClose:p}){let{t:m}=Z(),[h,g]=r(null),[_,v]=r([]),y=c?.find(e=>e.id===h)??c?.[0]??null,b=s.kind===`known`?s.value:[],x=s.kind===`known`?Ji(s.value,``,y):[],S=Jo(b,l,e=>e.deviceId).suggested,C=Jo(x,l,e=>e.deviceId).others,w=n(()=>es(C),[C]),T=$o(s),E=b.filter(e=>_.includes(e.deviceId));t(()=>{e||(v([]),g(null))},[e]);let D=()=>{v([]),g(null),p()},O=e=>{e.length!==0&&(f(e),v([]),g(null))},k=()=>O(E);return d(ft,{open:e,onOpenChange:e=>e?void 0:D(),children:a(Vn,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":i,children:[d(Ft,{children:d(Rt,{children:i})}),a(Vt,{className:`flex flex-col gap-2 p-2 sm:p-4`,children:[c!==void 0&&c.length>0&&d(`div`,{className:`flex flex-wrap gap-1`,role:`tablist`,"aria-label":m(`customize.assign.filtersLabel`),children:c.map(e=>d(`button`,{type:`button`,role:`tab`,"aria-selected":(y?.id??null)===e.id,className:`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${(y?.id??null)===e.id?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover`}`,onClick:()=>g(e.id),children:m(e.labelKey)},e.id))}),l!==null&&d(Qo,{location:l.location,devices:S.map(e=>({id:e.deviceId,name:e.name,container:Yo(l,e.deviceId),detail:e.detail})),action:`add`,onPick:e=>O(S.filter(t=>t.deviceId===e)),...o===`multi`?{onPickAll:()=>O(S)}:{}}),s.kind===`unknown`?d(`p`,{role:`alert`,className:`text-xs text-warning`,children:m(`customize.assign.unknown`,{reason:s.reason})}):w.length===0&&S.length>0?null:d(yn,{devices:w,listState:T,value:_,onChange:e=>v(o===`single`?e.length>0?[e[e.length-1]]:[]:e),noun:`device`,emptyLabel:m(`customize.assign.none`),showAll:!0,testId:`customize-device-picker`})]}),a(Ln,{children:[d(Y,{variant:`ghost`,onClick:D,children:m(`customize.picker.cancel`)}),d(Y,{disabled:E.length===0,onClick:k,children:u(E.length)})]})]})})}function ns(e){if(e===null)return[];let t=gi(e);return yi(e).map(e=>{let n=q(e);return{key:n,ref:e,caps:t.filter(e=>q(e.source)===n).map(e=>e.cap)}})}function rs(e,t){let n=gi(e);if(n.length===0)return!1;let{enabled:r,...i}=e,{enabled:a,...o}=Me({camera:t,sources:n,enabled:!0});return Ti(i,o)}function is(e){return e?.enabled!==!1}function as(e,t,n){let r=[...e===null?[]:gi(e),...n.flatMap(e=>De(e.ref,e.caps))];return r.length===0?null:Me({camera:t,sources:r,enabled:is(e)})}function os(e,t,n){let r=gi(e).filter(e=>q(e.source)!==n);return r.length===0?null:Me({camera:t,sources:r,enabled:is(e)})}function ss(e,t){return{...e,enabled:t}}e();function cs({device:e,handle:t,availability:n,onAdvanced:i}){let{t:o}=Z(),c=Vo(),[l,u]=r(!1),[f,p]=r(null),m=so(t.state),h=Ei(m,`doorbell`),g=h===null||rs(h,t.target),_=g?ns(h):[],v=zo(_.length>0),y=Bo({hostId:e.id,excludeCameras:!1,assigned:new Set(_.map(e=>e.key)),preferredCap:null,enabled:l});if(n.kind===`absent`)return null;let b=t.state.kind===`none`||t.state.kind===`present`,x=b&&!t.saving,S=n.kind===`present`&&x&&g,C=async e=>{let n=e===null?m===null?null:ni(m,`doorbell`):ai(m,t.target,e),r=await t.save(n);p(r.kind===`refused`?r.reason:null)},w=async(e,n)=>{if(h===null||m===null)return;let r=os(h,t.target,e.key),i=r===null&&ni(m,`doorbell`)===null;await c(o(`customize.doorbell.removeWhat`,{name:n}),i)&&await C(r)},T=e=>v.kind===`known`?v.value.find(t=>q({addonId:t.addonId,stableId:t.stableId})===e.key)??null:null;return a(s,{children:[a(Po,{id:`doorbell`,icon:E,title:o(`customize.doorbell.title`),headerControl:h===null?void 0:a(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground`,children:[d(hr,{"aria-label":o(`customize.doorbell.active`),checked:h.enabled!==!1,disabled:!x,onChange:e=>void C(ss(h,e.target.checked))}),o(`customize.doorbell.active`)]}),addLabel:o(`customize.doorbell.add`),onAdd:S?()=>u(!0):void 0,notices:a(s,{children:[d(Fo,{availability:n}),v.kind===`unknown`&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:o(`customize.assign.devicesUnreadable`,{reason:v.reason})}),f!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:f})]}),children:[_.map(e=>{let n=T(e),r=n?.name??e.key,i=Yi(e.caps,null),a=i===null?void 0:be[i];return d(Mo,{name:r,detail:n===null?null:Zi(n.integration,n.location),meta:e.caps.join(`, `),value:n!==null&&i!==null&&a!==void 0?{deviceId:n.id,cap:i,path:a}:null,problem:n===null&&v.kind===`known`?o(`customize.assign.missingKept`):void 0,onRemove:b?()=>void w(e,r):void 0,removeLabel:o(`customize.assign.removeNamed`,{name:r}),busy:t.saving},e.key)}),!g&&d(Mo,{name:o(`customize.doorbell.otherFormula`),detail:null,meta:d(ao,{onAdvanced:i}),value:null,removeLabel:``}),h===null&&n.kind===`present`&&b&&d(`li`,{className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:o(`customize.assign.none`)})]}),d(ts,{open:l,title:o(`customize.doorbell.pickTitle`),selection:`multi`,candidates:y,confirmLabel:e=>o(`customize.assign.addCount`,{count:e}),onConfirm:e=>{u(!1),C(as(h,t.target,e.map(e=>({ref:e.ref,caps:e.caps}))))},onClose:()=>u(!1)})]})}e();function ls(e,t){let r=typeof e==`string`&&e.length>0,i=zo(t&&r);return n(()=>t?qo(i,e):null,[t,i,e])}e();function us(e){return e==null?null:e.message}function ds({device:e}){let t=H(),{t:n}=Z(),i=c(),o=Vo(),l=we.includes(e.type),[u,f]=r(!1),[p,m]=r(!1),[h,g]=r(null),_=bt({deviceId:e.id},{enabled:l}),v=ta({status:_.status,data:_.data,error:us(_.error)===null?null:{message:us(_.error)??``}}),y=v.kind===`present`?v.slot.slotRef:``,b=v.kind===`present`?[...Qi(v.slot,v.value).map(e=>e.deviceId),...Xi(v.slot,v.value)]:[],x=At(),S=zo(l&&v.kind===`present`&&(u||b.length>0)),C=ls(e.location,l&&v.kind===`present`),w=nn({deviceId:e.id,slotRef:y},{enabled:(u||C!==null)&&v.kind===`present`});if(!l||v.kind===`absent`)return null;if(v.kind!==`present`)return d(Po,{id:`linked`,icon:oe,title:n(`customize.linked.title`),notices:v.kind===`pending`?d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:n(`customize.assign.checking`)}):d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:n(`customize.assign.unknown`,{reason:v.reason})}),children:null});let T=v.value,E=new Map(S.kind===`known`?S.value.map(e=>[e.id,e]):[]),D=T.trackedDeviceIds!==void 0,O=(e,t)=>{let n=E.get(e.deviceId);return{...e,name:e.name??n?.name??null,type:n?.type??null,detail:n===void 0?null:Zi(n.integration,n.location),orphan:t}},k=[...Qi(v.slot,T).map(e=>O(e,!1)),...Xi(v.slot,T).map(e=>O({deviceId:e,name:null,health:`ok`,implied:!1,tracked:!0},!0))],A=new Set(b),j=S.kind===`unknown`?S:w.status===`error`?{kind:`unknown`,reason:us(w.error)??n(`helpers.customize.requestFailed`)}:S.kind===`pending`||w.status===`pending`||w.data===void 0?{kind:`pending`}:{kind:`known`,value:ra(w.data.candidates,E,A)},M=async t=>{if(p){g(n(`customize.saveInFlight`));return}m(!0),g(null);try{await x.mutateAsync({deviceId:e.id,slotRef:v.slot.slotRef,value:t}),await _.refetch(),await i.invalidateQueries({queryKey:[[`deviceManager`]]})}catch(e){g(e instanceof Error?e.message:String(e))}finally{m(!1)}},ee=async e=>{await o(n(`customize.linked.removeWhat`,{name:e.name??`#${e.deviceId}`}),!1)&&await M(na(T,e.deviceId))},N=[{key:`device`,header:n(`customize.linked.device`),cell:e=>a(`div`,{className:`flex flex-col min-w-0`,children:[d(`span`,{className:`truncate text-xs text-foreground`,children:e.name??`#${e.deviceId}`}),e.detail!==null&&d(`span`,{className:`truncate text-[11px] text-foreground-subtle`,children:e.detail}),e.orphan&&d(`span`,{className:`text-[11px] text-foreground-subtle`,children:n(`customize.linked.notLinked`)}),e.health!==`ok`&&d(`span`,{role:`alert`,className:`text-[11px] text-warning`,children:n(`customize.linked.health.${e.health}`)})]})},{key:`type`,header:n(`customize.linked.type`),headerClassName:`hidden sm:table-cell`,cellClassName:`hidden sm:table-cell text-xs text-foreground-subtle`,cell:e=>e.type===null?`—`:kn(e.type,t).label},{key:`controls`,header:n(`customize.linked.controls`),headerClassName:`hidden md:table-cell`,cellClassName:`hidden md:table-cell text-xs text-foreground-subtle`,cell:e=>e.orphan?`—`:n(`customize.linked.yes`)},...D?[{key:`tracked`,header:n(`customize.linked.tracked`),cellClassName:`text-right`,headerClassName:`text-right`,cell:e=>d(ir,{checked:e.tracked,disabled:p,"aria-label":n(`customize.linked.trackFor`,{name:e.name??e.deviceId}),onCheckedChange:t=>void M($i(T,e.deviceId,t))})}]:[],{key:`remove`,header:``,cellClassName:`text-right w-10`,cell:e=>e.implied||e.orphan?null:d(pr,{icon:re,variant:`ghost`,size:`sm`,"aria-label":n(`customize.assign.removeNamed`,{name:e.name??e.deviceId}),disabled:p,onClick:t=>{t.stopPropagation(),ee(e)}})}];return a(s,{children:[d(Po,{id:`linked`,icon:oe,title:n(`customize.linked.title`),addLabel:n(`customize.linked.add`),onAdd:p?void 0:()=>f(!0),...C===null?{}:{suggestion:{count:Xo(j,C,e=>e.deviceId),location:C.location,onOpen:()=>f(!0)}},notices:a(s,{children:[S.kind===`unknown`&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:n(`customize.assign.devicesUnreadable`,{reason:S.reason})}),h!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:h})]}),children:a(`li`,{className:`list-none px-3 py-2 sm:px-4`,children:[k.length===0?d(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`customize.assign.none`)}):d(er,{mode:`generic`,items:k,getKey:e=>String(e.deviceId),getSearchText:e=>[e.name??``,e.detail??``,e.type??``,String(e.deviceId)].join(` `),getFilterType:e=>e.type===null?null:kn(e.type,t).label,columns:N,searchPlaceholder:n(`customize.assign.search`),emptyLabel:n(`customize.assign.none`)}),k.some(e=>!e.orphan)&&d(`p`,{className:`mt-2 text-[10px] text-foreground-subtle`,children:n(`customize.linked.controlsAlways`)}),D&&d(`p`,{className:`mt-0.5 text-[10px] text-foreground-subtle`,children:n(`customize.linked.trackedHint`)})]})}),d(ts,{open:u,title:n(`customize.linked.pickTitle`),selection:`multi`,candidates:j,room:C,confirmLabel:e=>n(`customize.assign.addCount`,{count:e}),onConfirm:e=>{f(!1),M(Ki(T,e.map(e=>e.deviceId)))},onClose:()=>f(!1)})]})}function fs(e){return e===null||e.state===`unreadable`?null:e.state===`configured`?e.sensors:[]}function ps(e){return{addonId:e.addonId,stableId:e.stableId,mode:e.mode}}function ms(e){return e.length===0?null:{sensors:[...e]}}function hs(e,t){let n=new Set(e.map(xe));return ms([...e.map(ps),...t.filter(e=>!n.has(xe(e))).map(e=>({...e,mode:ye}))])}function gs(e,t,n){return ms(e.map(e=>xe(e)===t?{...ps(e),mode:n}:ps(e)))}function _s(e,t){return ms(e.filter(e=>xe(e)!==t).map(ps))}function vs(e){return e?.state===`configured`&&e.cameraMotion!==void 0}function ys(e){return e===null||e.state===`unreadable`?null:e.state===`configured`?e.cameraMotion??`always`:`always`}function bs(e){return e===null||e.state===`unreadable`?!1:e.state===`not-configured`||vs(e)}function xs(e){return e?.state===`configured`&&(e.notForwarded!==void 0||e.notEnforced!==void 0)}function Ss(e,t,n){if(e!==`present`||t===null||n)return{kind:`none`};let r=t.cameraLevel;return r===void 0?{kind:`unknown`}:{kind:`level`,detected:r.detected,atMs:r.atMs}}e();var Cs=5e3;function ws(e){return e.state===`missing`||e.state===`unreadable`?e.stableId:e.name}function Ts({device:e,availability:n,sensors:i}){let{t:o}=Z(),c=Vo(),u=Qn(),[f,p]=r(!1),[m,h]=r(null),g=l(!1),[_,v]=r(!1),[y,b]=r(!1),x=i.status,S=l(i.refetch);S.current=i.refetch,t(()=>{let e=setInterval(()=>{g.current||S.current()},Cs);return()=>clearInterval(e)},[]);let C=fs(x);t(()=>{x!==null&&b(!1)},[x]);let w=i.presence===`present`&&bs(x)&&!y?C:null,T=zo(C!==null&&C.length>0),E=Bo({hostId:e.id,excludeCameras:!0,assigned:new Set((C??[]).map(xe)),preferredCap:`motion`,enabled:f});if(n.kind===`absent`)return null;let D=vs(x),O=xs(x)?`passes`:ys(x),k=Ss(i.presence,x,y),A=k.kind===`none`?null:k.kind===`unknown`?{text:`?`,tone:`warning`,title:o(`customize.motion.cameraLevelUnknown`)}:{text:o(k.detected?`customize.assign.value.active`:`customize.assign.value.inactive`),tone:k.detected?`active`:`muted`,title:o(`customize.motion.cameraLevelOwn`,{at:new Date(k.atMs).toLocaleTimeString()})},j=_||u.isPending,M=async t=>{if(g.current){h(o(`customize.saveInFlight`));return}g.current=!0,v(!0);try{await u.mutateAsync({deviceId:e.id,config:t}),h(null),await i.refetch()===`failed`&&b(!0)}catch(e){h(e instanceof Error?e.message:String(e))}finally{g.current=!1,v(!1)}},ee=async e=>{w!==null&&await c(o(`customize.motion.removeWhat`,{name:ws(e)}),!1)&&await M(_s(w,xe(e)))},N=e=>{if(T.kind!==`known`||!(`deviceId`in e))return null;let t=T.value.find(t=>t.id===e.deviceId);return t===void 0?null:Zi(t.integration,t.location)};return a(s,{children:[a(Po,{id:`motion`,icon:B,title:o(`customize.motion.title`),addLabel:o(`customize.motion.add`),onAdd:w!==null&&n.kind===`present`?()=>p(!0):void 0,addDisabled:j,notices:a(s,{children:[d(Fo,{availability:n}),i.presence===`pending`&&n.kind!==`pending`&&d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:o(`customize.motion.reading`)}),x?.state===`unreadable`&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:o(`customize.motion.unreadable`,{reason:x.reason})}),x?.state===`configured`&&!bs(x)&&d(`p`,{role:`alert`,className:`text-xs text-warning`,children:o(`customize.motion.olderOrchestrator`)}),y&&d(`p`,{role:`alert`,className:`text-xs text-warning`,children:o(`customize.motion.refetchFailed`)}),x?.state===`configured`&&x.notForwarded!==void 0&&d(`p`,{role:`alert`,className:`text-xs text-warning`,children:o(`customize.motion.notForwarded.${x.notForwarded}`)}),x?.state===`configured`&&x.notEnforced!==void 0&&d(`p`,{role:`alert`,className:`text-xs text-warning`,children:o(`customize.motion.notEnforced`)}),T.kind===`unknown`&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:o(`customize.assign.devicesUnreadable`,{reason:T.reason})}),m!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:m})]}),children:[d(Mo,{name:o(`customize.motion.camera`),detail:null,meta:O===null?o(`customize.assign.native`):`${o(`customize.motion.cameraState.${O}`)} · ${o(`customize.assign.native`)}`,value:null,shown:A,removeLabel:``}),(C??[]).map(e=>{let t=xe(e),n=ws(e),r=e.state===`ready`?Yi(e.caps,`motion`):null,i=r===null?void 0:be[r];return d(Mo,{name:n,detail:N(e),meta:D&&w!==null?d(on,{"aria-label":o(`customize.motion.modeFor`,{name:n}),value:e.mode,disabled:j,options:J.options.map(e=>({value:e,label:o(`customize.motion.mode.${e}`)})),onChange:e=>{let n=J.safeParse(e.target.value);n.success&&w!==null&&M(gs(w,t,n.data))}}):o(`customize.motion.mode.${e.mode}`),value:r!==null&&i!==void 0&&`deviceId`in e?{deviceId:e.deviceId,cap:r,path:i}:null,problem:e.state===`ready`?void 0:e.reason===e.state?o(`customize.motion.state.${e.state}`):`${o(`customize.motion.state.${e.state}`)}: ${e.reason}`,onRemove:w===null?void 0:()=>void ee(e),removeLabel:o(`customize.assign.removeNamed`,{name:n}),busy:j},t)})]}),d(ts,{open:f,title:o(`customize.motion.pickTitle`),selection:`multi`,candidates:E,filters:qi,confirmLabel:e=>o(`customize.assign.addCount`,{count:e}),onConfirm:e=>{if(p(!1),w===null)return;let t=hs(w,e.map(e=>e.ref));if(t!==null&&t.sensors.length>8){h(o(`customize.motion.tooMany`,{max:8}));return}M(t)},onClose:()=>p(!1)})]})}var Es={"numeric-sensor":{fieldPath:`value`,unitField:`unit`},"temperature-sensor":{fieldPath:`celsius`,unitField:`unit`},"humidity-sensor":{fieldPath:`percent`,unitField:`unit`},"pressure-sensor":{fieldPath:`hpa`,unitField:`unit`},"ambient-light-sensor":{fieldPath:`lux`,unitField:`unit`}},Ds=new Set([K.Camera]);function Os(e){return e.unitField===null?[e.fieldPath]:[e.fieldPath,e.unitField]}function ks(e,t){if(Ds.has(e))return{kind:`absent`};let n=null;for(let[e,r]of Object.entries(Es))if(t.has(e)){n={cap:e,fieldPath:r.fieldPath,unitField:r.unitField};break}let r=null;for(let e of Ve)if(t.has(e)){let t=be[e];if(t!==void 0){r={cap:e,fieldPath:t};break}}return n===null&&r===null?{kind:`absent`}:{kind:`present`,convert:n,invert:r}}function As(e){return Ae(e.from,e.to)?Le(e):null}function js(e){return Be(e)}var Ms=/^convert\(v,\s*"[^"]*",\s*"[^"]*"\)$/;function Ns(e){return e!==void 0&&Ms.test(e.expr)}function Ps(e){return e===void 0||e.expr===`!v`||Ms.test(e.expr)?!1:e.bindings.v!==void 0}function Fs(e){let t=e.expr.trim();if(t===``)return{kind:`refused`,reason:X.t(`helpers.numericTransforms.emptyExpression`)};let n={kind:`expression`,expr:t,bindings:{v:{kind:`from`,source:e.self,cap:e.cap,fieldPath:e.fieldPath}}},r=He({source:n,now:Date.now(),read:()=>({state:`fresh`,value:e.probe})});return r.state===`unavailable`?{kind:`refused`,reason:r.reason}:{kind:`ok`,feature:{kind:`fields`,cap:e.cap,fields:{[e.fieldPath]:n}}}}function Is(e,t,n){if(e===null)return null;let r=Ei(e,n.cap);if(r===null)return e;let i=new Set(Os(n)),a=Object.fromEntries(Object.entries(r.fields).filter(([e])=>!i.has(e)));return Object.keys(a).length===0?ni(e,n.cap):ai(e,t,{kind:`fields`,cap:n.cap,...r.enabled===void 0?{}:{enabled:r.enabled},fields:a,...r.items===void 0?{}:{items:r.items}})}e();function Ls(e){if(typeof e!=`object`||!e)return;let t=Reflect.get(e,`unit`);return typeof t==`string`?t:void 0}function Rs(e,t){if(typeof e!=`object`||!e)return;let n=Reflect.get(e,t);return typeof n==`number`&&Number.isFinite(n)?n:void 0}function zs(e,t){let n=Ei(e,t.cap);if(n===null)return;let r=n.fields[t.fieldPath];return r!==void 0&&r.kind===`expression`?r:void 0}function Bs(e,t){let n=zs(e,t);return n===void 0||!Ns(n)?null:/^convert\(v,\s*"[^"]*",\s*"([^"]*)"\)$/.exec(n.expr)?.[1]??null}function Vs(e,t){let n=zs(e,t);return n===void 0||!Ps(n)?null:n.expr}function Hs(e,t,n){let r=Ei(e,t);if(r===null)return!1;let i=r.fields[n];return i!==void 0&&i.kind===`expression`&&i.expr===`!v`}function Us(e){return typeof e==`number`||typeof e==`boolean`||typeof e==`string`?String(e):e===null?`null`:JSON.stringify(e)}function Ws({device:e,target:t,handle:n,facts:i}){let{t:o}=Z(),s=U(),[c,l]=r(null),[u,f]=r(``),[p,h]=r(null),g=i.nativeCaps.kind===`known`?i.nativeCaps.value:null,_=g===null?null:ks(e.type,g),v=_?.kind===`present`?_.convert?.cap??``:``,y=mr(s.trpcClient,e.id,v);if(i.nativeCaps.kind===`pending`)return d(`section`,{className:`${D} ${m}`,children:d(Fo,{availability:{kind:`pending`}})});if(i.nativeCaps.kind===`unknown`)return d(`section`,{className:`${D} ${m}`,children:d(Fo,{availability:{kind:`unknown`,reason:i.nativeCaps.reason}})});if(_===null||_.kind===`absent`)return null;let b=so(n.state),x=_.convert,S=_.invert,C=x===null?void 0:Ls(y),w=C===void 0?void 0:Ue(C)??C,T=w===void 0?void 0:ze(w),E=x===null?null:Bs(b,x),O=x===null?null:Vs(b,x),k=p??O??``,A=S===null?!1:Hs(b,S.cap,S.fieldPath),j=n.state.kind===`none`||n.state.kind===`present`,M=x===null?0:Rs(y,x.fieldPath)??0,ee=x!==null&&k.trim()!==``?{kind:`expression`,expr:k.trim(),bindings:{v:{kind:`from`,source:t,cap:x.cap,fieldPath:x.fieldPath}}}:null,N=ee===null||x===null?null:_i(ee,new Map([[ve(t,x.cap),y===void 0?{kind:`pending`}:{kind:`value`,slice:y}]]),Date.now()),P=async e=>{let t=await n.save(e);l(t.kind===`refused`?t.reason:null)},F=async()=>{if(x===null||w===void 0||u===``)return;let e=As({self:t,cap:x.cap,fieldPath:x.fieldPath,from:w,to:u,unitField:x.unitField});if(e===null){l(o(`customize.numericTransforms.convertRefused`));return}h(null),await P(ai(b,t,e))},te=async()=>{x!==null&&(await P(Is(b,t,x)),f(``))},I=async()=>{if(x===null)return;let e=Fs({self:t,cap:x.cap,fieldPath:x.fieldPath,expr:k,probe:M});if(e.kind===`refused`){l(e.reason);return}f(``),await P(ai(b,t,e.feature))},L=async()=>{x!==null&&(await P(Is(b,t,x)),h(``))},R=async()=>{if(S===null)return;let e=js({self:t,cap:S.cap});if(e===null){l(o(`customize.numericTransforms.invertRefused`));return}await P(ai(b,t,e))},ne=async()=>{S===null||b===null||await P(ni(b,S.cap))};return d(No,{id:`numeric-transforms`,icon:Ye,title:o(`customize.numericTransforms.title`),testId:`numeric-transforms-card`,children:a(`div`,{className:`${m} flex flex-col gap-3`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`customize.numericTransforms.blurb`)}),c!==null&&d(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:c}),x!==null&&a(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-convert`,children:[d(`label`,{className:`text-[11px] font-medium text-foreground`,children:o(`customize.numericTransforms.publishUnit`)}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:w===void 0?o(`customize.numericTransforms.fromUnknown`):o(`customize.numericTransforms.fromUnit`,{unit:w})}),d(`div`,{className:`w-full sm:max-w-xs`,children:d(Hn,{dimension:T,value:u===``?E??``:u,onChange:e=>{f(e),e!==``&&h(``)},disabled:!j||n.saving||w===void 0,"aria-label":o(`customize.numericTransforms.toUnit`),inheritLabel:o(`customize.numericTransforms.pickUnit`),emptyReason:o(`customize.numericTransforms.fromUnknown`)})}),a(`div`,{className:`flex flex-wrap gap-2`,children:[d(Y,{size:`sm`,disabled:!j||n.saving||w===void 0||u===``||u===w,onClick:()=>void F(),children:o(`customize.numericTransforms.applyConvert`)}),E!==null&&d(Y,{size:`sm`,variant:`outline`,disabled:!j||n.saving,onClick:()=>void te(),children:o(`customize.numericTransforms.clearConvert`)})]})]}),x!==null&&a(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-script`,children:[d(bi,{label:o(`customize.numericTransforms.script`),value:k,bindings:[`v`],onChange:e=>{h(e),e.trim()!==``&&f(``)}}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`customize.numericTransforms.scriptBlurb`)}),N!==null&&d(`p`,{role:`status`,className:`text-[11px] font-mono text-foreground`,"data-testid":`numeric-script-preview`,children:N.kind===`value`?o(`customize.numericTransforms.preview`,{source:Us(M),result:Us(N.value)}):N.kind===`waiting`?o(`customize.numericTransforms.previewWaiting`):N.kind===`unavailable`?o(`customize.numericTransforms.previewError`,{reason:N.reason}):o(`customize.numericTransforms.previewRuntimeOnly`)}),a(`div`,{className:`flex flex-wrap gap-2`,children:[d(Y,{size:`sm`,disabled:!j||n.saving||k.trim()===``,onClick:()=>void I(),children:o(`customize.numericTransforms.applyScript`)}),O!==null&&d(Y,{size:`sm`,variant:`outline`,disabled:!j||n.saving,onClick:()=>void L(),children:o(`customize.numericTransforms.clearScript`)})]})]}),S!==null&&a(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-invert`,children:[d(`label`,{className:`text-[11px] font-medium text-foreground`,children:o(`customize.numericTransforms.invert`)}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`customize.numericTransforms.invertBlurb`)}),d(`div`,{className:`flex flex-wrap gap-2`,children:A?d(Y,{size:`sm`,variant:`outline`,disabled:!j||n.saving,onClick:()=>void ne(),children:o(`customize.numericTransforms.clearInvert`)}):d(Y,{size:`sm`,disabled:!j||n.saving,onClick:()=>void R(),children:o(`customize.numericTransforms.applyInvert`)})})]})]})})}e();function Gs(e){return e instanceof Error?e.message:String(e)}function Ks(e){let t=Pt({addonId:e.addonId,stableId:e.stableId}),n=dt(),i=Gt(),a=Bt(),o=oo({status:t.status,data:t.data,error:t.error===null||t.error===void 0?null:{message:t.error.message}}),{t:s}=Z(),c=l(!1),[u,d]=r(!1),f=async e=>{let r=ci(o,e);try{switch(r.kind){case`refused`:return{kind:`refused`,reason:r.reason};case`noop`:return{kind:`saved`};case`create`:await n.mutateAsync({block:r.input});break;case`update`:await i.mutateAsync({blockId:r.blockId,expectedUpdatedAt:r.expectedUpdatedAt,block:{composition:r.composition}});break;case`delete`:await a.mutateAsync({blockId:r.blockId});break}return await t.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:Gs(e)}}};return{target:e,state:o,saving:u||n.isPending||i.isPending||a.isPending,save:async e=>{if(c.current)return{kind:`refused`,reason:s(`customize.saveInFlight`)};c.current=!0,d(!0);try{return await f(e)}finally{c.current=!1,d(!1)}}}}var qs=`pipeline-orchestrator`;function Js(e){return e.status===`pending`?`pending`:e.status===`error`?`unknown`:e.data===void 0?`pending`:e.data.cameraSensors===void 0?`absent`:`present`}function Ys(e,t){return e===`absent`?`absent`:Js(t)}async function Xs(e){try{return(await e()).isError?`failed`:`answered`}catch{return`failed`}}function Zs(e,t){let n=Qt(qs),r=zt({deviceId:e},{enabled:t&&n!==`absent`}),i=()=>Xs(r.refetch);return t?{presence:Ys(n,{status:r.status,data:r.data}),status:r.data?.cameraSensors??null,refetch:i}:{presence:`absent`,status:null,refetch:i}}function Qs(e,t){let n=Lt({deviceType:e.type}),r=xr({deviceId:e.id}),i=En({deviceId:e.id}),a=Io(n,e=>new Set(e.caps.map(e=>e.cap))),o=Io(r,e=>eo(e.entries)),s=Io(i,e=>e);return{deviceType:e.type,composable:a,nativeCaps:o,wireable:s,composed:new Set((t?.features??[]).map(e=>e.cap))}}function $s(){return{kind:`unknown`,reason:X.t(`helpers.fieldsTableRows.noValue`)}}function ec(e,t){let n=q(e);return t.get(n)??n}function tc(e,t,n){let r=n.nativeCaps.has(e.cap)?`replaced`:`added`,i=t.filter(t=>t.cap===e.cap&&t.origin===`composed`);if(e.cap===`doorbell`){let t=yi(e).map(e=>ec(e,n.sourceNames)).join(` + `),a=i.find(e=>e.field===`lastPressedAt`);return[{key:`doorbell`,label:X.t(`helpers.whatChangesRows.doorbell`),origin:{kind:r,from:t},value:a?.value??$s()}]}return e.cap===`consumables`?di(e).map(e=>{let t=t=>Se(Oe,e.key,t),a=i.find(e=>e.field===t(`level`)||e.field===t(`remaining.value`)),o=e.source===null?``:ec(e.source.source,n.sourceNames);return{key:`consumables.${e.key}`,label:X.t(`helpers.whatChangesRows.consumable`,{name:e.label}),origin:{kind:r,from:o},value:a?.value??$s()}}):i.map(e=>({key:e.key,label:`${e.cap}.${e.field}`,origin:{kind:r,from:e.from},value:e.value}))}function nc(e){let t=mi({composition:e.composition,nativeCaps:e.nativeCaps,state:e.state,nativeFields:new Map,snapshot:null,sourceNames:e.sourceNames});return e.composition.features.flatMap(n=>n.kind===`fields`?tc(n,t,e):[])}function rc(e,t){if(e?.state!==`configured`||e.sensors.length===0)return null;let n=e.cameraMotion===`never`?[]:[t.camera],r=e.sensors.map(e=>t.sensor(e.state===`missing`||e.state===`unreadable`?e.stableId:e.name,e.mode));return[...n,...r].join(` + `)}var ic=`${M} grid grid-cols-1 gap-x-3 gap-y-0.5 items-baseline sm:grid-cols-[minmax(0,1fr)_minmax(0,2fr)_minmax(0,1.5fr)]`,ac=`font-mono text-[11px] text-foreground break-words`,oc=`text-[11px] text-foreground-subtle break-words`,sc=`text-[11px] break-words sm:text-right`;function cc({device:e,composition:t,state:n,nativeCaps:r,cameraSensors:i}){let{t:o}=Z(),s=t!==null&&n!==null,c=zo(s),l=new Map(c.kind===`known`?c.value.map(e=>[q({addonId:e.addonId,stableId:e.stableId}),e.name]):[]),u=s&&r.kind===`known`?nc({composition:t,nativeCaps:r.value,state:n,sourceNames:l}):[],f=s&&r.kind===`known`&&u.length===0&&t.features.length>0,p=rc(i,{camera:o(`customize.changes.motion.camera`),sensor:(e,t)=>o(`customize.changes.motion.${t}`,{name:e})}),m=s&&r.kind!==`known`;return u.length===0&&p===null&&!m&&!f?null:a(No,{id:`changes`,icon:ne,title:o(`customize.changes.title`),children:[m&&d(`p`,{role:r.kind===`unknown`?`alert`:`status`,className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:r.kind===`unknown`?o(`customize.changes.unknown`,{reason:r.reason}):o(`customize.changes.reading`)}),f&&d(`p`,{className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:o(`customize.changes.noRows`)}),a(`ul`,{className:`divide-y divide-border`,children:[u.map(e=>a(`li`,{className:ic,children:[d(`span`,{className:ac,children:e.label}),d(`span`,{className:oc,children:c.kind===`known`?o(`customize.changes.origin.${e.origin.kind}`,{from:e.origin.from}):o(`customize.changes.originUnread.${c.kind}`,{kind:o(`customize.changes.kind.${e.origin.kind}`),reason:c.kind===`unknown`?c.reason:``})}),d(`span`,{className:sc,children:d(lc,{value:e.value})})]},e.key)),p!==null&&a(`li`,{className:ic,children:[d(`span`,{className:ac,children:o(`common.motionWord`)}),d(`span`,{className:oc,children:p}),d(`span`,{className:sc,children:d(Ao,{target:{deviceId:e.id,cap:`motion`,path:`detected`}})})]})]})]})}function lc({value:e}){let{t}=Z();switch(e.kind){case`value`:return a(`span`,{children:[vi(e.value,!0),e.staleReason!==null&&a(`span`,{className:`text-warning`,children:[` `,`·`,` `,t(`customize.changes.value.stale`,{reason:e.staleReason})]})]});case`unavailable`:return d(`span`,{className:`text-warning`,children:t(`customize.changes.value.unavailable`,{reason:e.reason})});case`unknown`:return d(`span`,{className:`text-foreground-subtle`,children:t(`customize.changes.value.unknown`,{reason:e.reason})});case`off`:return d(`span`,{className:`text-foreground-subtle`,children:t(`customize.status.off`)})}}e();function uc({deviceId:e,activeSubTab:t,onSubTabChange:n}){let{t:r}=Z(),i=sr({deviceId:e}),a=i.data;return a==null?i.status===`error`?d(jr,{title:r(`customize.deviceUnreadable`),message:i.error?.message??``,onRetry:()=>void i.refetch()}):a===null?d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.noSuchDevice`,{deviceId:e})}):d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.loadingDevice`)}):a.addonId===`composer`?d(dc,{device:a}):d(fc,{device:a,target:{addonId:a.addonId,stableId:a.stableId},activeSubTab:t,onSubTabChange:n})}function dc({device:e}){let{t}=Z(),n=e.stableId.startsWith(`composed-`)?e.stableId.slice(Ke.length):null;return a(`section`,{className:`${D} ${m} flex flex-col gap-2`,children:[d(`p`,{className:`text-xs text-foreground`,children:t(`customize.composed.body`)}),n!==null&&d(Vr,{className:`text-[11px] text-primary hover:underline`,to:Yr(n),children:t(`customize.composed.edit`)})]})}function fc({device:e,target:t,activeSubTab:n,onSubTabChange:r}){let i=Ks(t),o=Qt(`composer`),{t:s}=Z(),c=Zs(e.id,e.type===K.Camera),l=Qs(e,so(i.state)),u={deviceType:e.type,composable:l.composable,nativeCaps:l.nativeCaps,cameraSensors:c.presence},f=()=>r($r),p=i.state.kind===`none`||i.state.kind===`present`;return n===`advanced`?a(`div`,{className:`flex flex-col gap-3`,children:[d(mc,{state:i.state}),p&&d(pc,{device:e,target:t,handle:i,facts:l,onDone:()=>r(`main`)})]}):a(`div`,{className:`flex flex-col gap-3`,children:[d(_o,{device:e}),o===`absent`&&d(`p`,{role:`alert`,className:`text-xs text-warning`,children:s(`customize.composerAbsent`)}),i.state.kind!==`none`&&d(mc,{state:i.state}),d(cs,{device:e,handle:i,availability:io(`doorbell`,u),onAdvanced:f}),d(Ts,{device:e,handle:i,availability:io(`motion`,u),sensors:c}),d(Uo,{device:e,handle:i,availability:io(`battery`,u),onAdvanced:f}),d(Ko,{device:e,handle:i,availability:io(`consumables`,u),onAdvanced:f}),d(Ws,{device:e,target:t,handle:i,facts:l}),d(ds,{device:e}),d(cc,{device:e,composition:so(i.state),state:i.state.kind===`present`?i.state.view.state:null,nativeCaps:l.nativeCaps,cameraSensors:c.status}),a(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[p?d(ao,{onAdvanced:f}):d(`span`,{}),d(hc,{handle:i})]})]})}function pc({device:e,target:t,handle:n,facts:r,onDone:i}){let a=n.state.kind===`present`?n.state:null;return d(Si,{initial:a===null?ri(t):ii(a.composition,``),blockId:a===null?null:a.view.block.id,deviceType:e.type,targetName:e.name,nativeCaps:r.nativeCaps,targetFields:r.wireable,onCancel:i,save:async e=>{let t=await n.save(e);return t.kind===`saved`&&i(),t}})}function mc({state:e}){let{t}=Z();switch(e.kind){case`pending`:return d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.status.pending`)});case`unknown`:return d(jr,{title:t(`customize.status.unknownTitle`),message:e.reason});case`not-loaded`:return d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.status.notLoaded`,{reason:e.reason})});case`none`:return null;case`present`:{let n=e.view.block;return a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(gr,{variant:n.status===`running`?`success`:n.status===`failed`?`danger`:`warning`,children:t(`customize.blockStatus.${n.status}`)}),!n.enabled&&d(gr,{variant:`default`,children:t(`customize.status.off`)}),n.lastError!==void 0&&d(`span`,{className:`text-[11px] text-foreground-muted break-words`,children:n.lastError}),e.view.state.kind===`unreachable`&&d(`span`,{className:`text-[11px] text-warning`,children:t(`customize.status.composerUnreachable`,{reason:e.view.state.error})})]})}}}function hc({handle:e}){let{t}=Z(),n=it(),[i,o]=r(null);if(e.state.kind!==`present`)return null;let s=async()=>{if(!await n({title:t(`customize.remove.title`),message:t(`customize.remove.message`),confirmLabel:t(`customize.remove.confirm`),variant:`danger`}))return;let r=await e.save(null);o(r.kind===`refused`?r.reason:null)};return a(`div`,{className:`flex flex-col items-start gap-1`,children:[d(Y,{variant:`danger`,size:`sm`,disabled:e.saving,onClick:()=>void s(),children:t(`customize.remove.button`)}),i!==null&&d(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:i})]})}var gc=`overview`;function _c(e,t){return e.some(e=>e.id===t)?t:gc}function vc({deviceId:e}){let{t}=Z(),n=c(),r=Number.isFinite(e),{data:i}=sr({deviceId:e},{enabled:r}),o=typeof i?.type==`string`?i.type:`camera`;ur([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:s,isLoading:l,isError:u,error:f}=xr({deviceId:e},{enabled:r}),{data:p}=wr({deviceType:o},{enabled:!!o}),m=Ct({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(l)return d(`div`,{className:`p-4`,children:d(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(u)return a(`div`,{className:`p-4 text-xs text-red-400`,children:[t(`device.bindingsTab.failedToLoadBindings`,`Failed to load bindings:`),` `,f instanceof Error?f.message:String(f)]});let h=new Map,g={};for(let e of p??[])g[e.capName]=e.wrappers;for(let e of s?.entries??[])h.set(e.capName,{...e,wrappers:g[e.capName]??[]});for(let e of p??[])h.has(e.capName)||h.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let _=[...h.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(_.length===0)return a(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[d(et,{className:`h-8 w-8 opacity-40`}),d(`p`,{className:`text-xs`,children:t(`device.bindingsTab.noCapabilityProvidersApplicableTo`,`No capability providers applicable to this device yet.`)}),d(`p`,{className:`text-[10px] opacity-60`,children:t(`device.bindingsTab.nativeProvidersShowUpHere`,`Native providers show up here as soon as the owning addon registers them.`)})]});let v=_.filter(e=>e.kind!==`unbound`).length,y=[{key:`capability`,header:t(`device.bindingsTab.capability`,`Capability`),render:e=>d(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:t(`device.bindingsTab.kind`,`Kind`),render:e=>d(yc,{kind:e.kind})},{key:`provider`,header:t(`device.bindingsTab.activeProvider`,`Active Provider`),render:e=>d(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||d(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:t(`device.bindingsTab.node`,`Node`),render:e=>e.providerNodeId?d(bc,{nodeId:e.providerNodeId}):d(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:t(`device.bindingsTab.kindNative`,`Native`),render:e=>d(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||d(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:t(`device.bindingsTab.wrapper`,`Wrapper`),render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return d(xc,{wrappers:t.wrappers,activeWrapperId:n,disabled:m.isPending,onPick:r=>{let i=n===r;m.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}];return a(`div`,{className:`flex flex-col gap-3 p-1`,children:[d(`div`,{className:`text-[11px] text-foreground-subtle`,children:d(qr,{i18nKey:`device.bindingsTab.boundSummary`,count:_.length,values:{bound:v},components:{b:d(`span`,{className:`font-medium text-foreground`}),em:d(`em`,{})}})}),d(St,{columns:y,rows:_,rowKey:e=>e.capName,minWidthPx:720})]})}function yc({kind:e}){let{t}=Z();return e===`native`?a(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[d(z,{className:`h-3 w-3`}),t(`device.bindingsTab.kindNative`)]}):e===`wrapped`?a(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[d(rt,{className:`h-3 w-3`}),t(`device.bindingsTab.wrapped`)]}):e===`linked`?a(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-warning/30 text-warning bg-warning/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[d(oe,{className:`h-3 w-3`}),t(`device.bindingsTab.linked`)]}):a(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[d(S,{className:`h-3 w-3`}),t(`common.unbound`)]})}function bc({nodeId:e}){return d(`span`,{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e===`hub`?`text-foreground-subtle`:`text-foreground`}`,children:e})}function xc({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){let{t:i}=Z();return e.length===0?d(`span`,{className:`text-[10px] opacity-40`,children:i(`device.bindingsTab.noneAvailable`,`none available`)}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let o=e===t;return a(`button`,{disabled:n,onClick:()=>r(e),title:o?i(`device.bindingsTab.clickToDeactivateRevertTo`,`Click to deactivate (revert to native)`):i(`device.bindingsTab.activateWrapper`,`Activate wrapper {{wrapperId}}`,{wrapperId:e}),className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${o?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[d(o?k:me,{className:`h-3 w-3`}),e]},e)})})}function Sc({deviceId:e,activeSubTab:t,onSubTabChange:n,deviceType:r,isAdmin:i}){return a(`div`,{className:`flex flex-col gap-3`,children:[zr(r,i)&&d(_t,{deviceId:e,readOnly:!0}),d(Zr,{deviceId:e,activeSubTab:t,onSubTabChange:n})]})}e();var Cc=[[`pipelineOrchestrator`,`getCameraDetectionSource`]];function wc(e){let t=c(),n=Rn({deviceId:e},{refetchOnMount:`always`}),a=br(),[o,s]=r(null),[l,u]=r(null),d=i(async n=>{u(null),s(n);try{await a.mutateAsync({deviceId:e,source:n}),await t.invalidateQueries({queryKey:Cc})}catch(e){u(e instanceof Error?e.message:`Could not change the root detector`),await t.invalidateQueries({queryKey:Cc})}finally{s(null)}},[e,a,t]),f=n.data??null;return{view:f,isLoading:n.isLoading,source:o??f?.source??null,saving:o!==null,error:l,pick:d}}var Tc=`object-detection`;function Ec(e){return[e.addonId,...e.children.flatMap(Ec)]}function Dc(e,t){if(e===`pipeline`)return new Set;let n=Oc(t,Tc);return n===void 0?new Set:new Set(e===`onboard`?[n.addonId]:Ec(n))}function Oc(e,t){for(let n of e){if(n.addonId===t)return n;let e=Oc(n.children,t);if(e!==void 0)return e}}function kc(e,t){return e===`onboard`?X.t(`helpers.detectionSourceModel.badgeCameraAi`):t===`object-detection`?X.t(`helpers.detectionSourceModel.badgeNoRoot`):X.t(`helpers.detectionSourceModel.badgeIdle`)}function Ac(e){switch(e){case`pipeline`:return X.t(`helpers.detectionSourceModel.explainPipeline`);case`onboard`:return X.t(`helpers.detectionSourceModel.explainOnboard`);case`none`:return X.t(`helpers.detectionSourceModel.explainNone`)}}function jc(e){switch(e){case`boxed`:return``;case`while-streaming`:return X.t(`helpers.detectionSourceModel.geometryWhileStreaming`);case`flag-only`:return X.t(`helpers.detectionSourceModel.geometryFlagOnly`);case`unknown`:return X.t(`helpers.detectionSourceModel.geometryUnknown`)}}function Mc(e,t){return e===`onboard`?X.t(`helpers.detectionSourceModel.noticeOnboard`):t===`object-detection`?X.t(`helpers.detectionSourceModel.noticeNoRoot`):X.t(`helpers.detectionSourceModel.noticeIdle`)}function Nc({source:e,geometry:t,saving:n,error:r,onPick:i}){let{t:o}=Z(),s=t===`flag-only`,c=jc(t);return a(`section`,{"aria-label":o(`device.detectionSourceControl.rootDetector`,`Root detector`),"aria-busy":n,className:`space-y-1.5 rounded-md border border-border bg-surface px-3 py-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1.5`,children:[d(`h3`,{className:ee,children:o(`device.detectionSourceControl.rootDetector`,`Root detector`)}),d(zn,{label:o(`device.detectionSourceControl.rootDetector`,`Root detector`),value:e,onChange:t=>{!n&&t!==e&&i(t)},options:[{value:`pipeline`,label:o(`device.detectionSourceControl.thisNode`,`This node`)},{value:`onboard`,label:o(`device.detectionSourceControl.cameraOnboardAi`,`Camera onboard AI`),disabled:s&&e!==`onboard`,reason:c},{value:`none`,label:o(`device.detectionSourceControl.none`,`None`)}]}),n&&d(`span`,{className:`text-[10px] text-foreground-subtle`,children:o(`device.detectionSourceControl.saving`,`Saving…`)})]}),a(`p`,{className:he,children:[Ac(e),` `,o(`device.detectionSourceControl.oneRoot`)]}),c!==``&&d(`p`,{className:`text-[10px] text-foreground-subtle`,children:c}),r!==null&&d(`p`,{role:`alert`,className:`text-[11px] text-danger`,children:r})]})}e();var Pc=new Set([`package-detection`]);function Fc(e){return e?.settings!==void 0&&Object.keys(e.settings).length>0?`accelerator`:`camera`}function Ic(e){return e===`camera`?X.t(`device.cameraStepInspector.modelSource.camera`):e===`node`?X.t(`device.cameraStepInspector.modelSource.node`):X.t(`device.cameraStepInspector.modelSource.default`)}function Lc(e){let{stored:t,draft:n,below:r,boundKeys:i}=e,a=n?.modelId===void 0?t?.modelId:n.modelId??void 0,o=ke(n?.settings??t?.settings,r,i),s={...a===void 0?{}:{modelId:a},...o===void 0?{}:{settings:o}};return Object.keys(s).length>0?s:null}function Rc(e,t){return(e?.modelId??null)===(t?.modelId??null)&&je(e?.settings??{},t?.settings??{})}function zc({deviceId:e}){let{t}=Z(),i=c(),l=U().trpcClient,u=It({deviceId:e},{refetchOnMount:`always`}),f=vt({deviceId:e},{refetchOnMount:`always`}),p=xt(void 0,{refetchOnMount:`always`}),m=Ne(On({addonId:`pipeline-orchestrator`}).data??null);ur([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let{nodes:h}=dn(),g=n(()=>{let e=new Set((p.data??[]).map(e=>e.nodeId));return h.filter(t=>t.isOnline&&e.has(t.id)).map(e=>({id:e.id,name:e.name}))},[p.data,h]),_=g.map(e=>e.id).join(`,`),v=o({enabled:g.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`camera-step-schemas`,_],queryFn:async()=>{let e={};for(let t of g)try{e[t.id]=await l.pipelineExecutor.getSchema.query({nodeId:t.id})}catch{}return e}}),y=o({enabled:g.length>0,queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`],`camera-step`,_],queryFn:async()=>{let e={};for(let t of g)try{e[t.id]=(await l.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:t.id})).devices}catch{e[t.id]=[]}return e}}),b=()=>{i.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),i.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]})},x=pn({onSuccess:b}),S=dr(),C=Nn(),[w,T]=r(null),[E,D]=r(null),[O,k]=r(null),[A,j]=r(!1),[M,N]=r(null),P=v.data??{},F=y.data??{},te=f.data??{},I=u.data??null,L=g.map(e=>P[e.id]).find(e=>e!==void 0)??null,R=n(()=>L?qt(L):[],[L]),ne=n(()=>Fi(R),[R]),z=wc(e),re=n(()=>z.source===null?new Set:Dc(z.source,R),[z.source,R]),[B,V]=r(!1),ie=n(()=>Ri(g,F,B),[g,F,B]),ae=n(()=>Ri(g,F,!0),[g,F]),oe=n(()=>Ri(g,F).length,[g,F]),se=(e,t)=>ki(P[e.nodeId],t),H=(e,t)=>te[e.nodeId]?.[e.deviceKey]?.[t],ce=(e,t)=>Ui(F[e.nodeId]??[],e.deviceKey,t)??{},le=e=>{if(Pc.has(e))return{kind:`zone-driven`};let t=ki(L,e)?.enabledByDefault??!0,n=I?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},ue=(e,t,n)=>{let r=n?.stepId===t?n:null;return{node:ce(e,t),camera:r?.camera??I?.stepSettings?.[t],accelerator:r?.perAccelerator[e.id]?.settings??H(e,t)?.settings}},de=(e,t,n)=>{let r=n?.stepId===t?n.perAccelerator[e.id]?.modelId:void 0;return r===void 0?H(e,t)?.modelId:r??void 0},fe=(e,t)=>{if(re.has(e))return{kind:`disabled`};let n=se(t,e),r=le(e),i=Li(e),a=Ai(P[t.nodeId],t,H(t,`object-detection`)?.modelId),o=ue(t,e,null),s=Fe(o.node,o.camera,o.accelerator);return Bi({addon:n,acc:t,gatedOn:r.kind===`gate`?r.effectiveOn:!0,model:n?Ii(n,t,{nodePin:t.device.steps?.[e]?.modelId,cameraPin:H(t,e)?.modelId}):{modelId:void 0,source:`default`},...Ni(e,s,a)&&a?{rootName:a.name}:{},...i?{clusterModelId:m[e]??i.defaultModelId}:{}})},pe=ne.map(({node:e})=>({addonId:e.addonId,name:e.addonName,fieldLabels:zi(ki(L,e.addonId))}));return p.isLoading||g.length>0&&(v.isLoading||y.isLoading)?d(`div`,{className:`animate-pulse p-4 text-xs text-foreground-subtle`,children:t(`device.cameraStepInspector.loadingPipeline`,`Loading pipeline…`)}):g.length===0?d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:t(`device.cameraStepInspector.noPipelineNodeIsOnline`,`No pipeline node is online.`)}):L===null?d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:t(`device.cameraStepInspector.catalogUnavailable`,`Catalog unavailable.`)}):a(`div`,{className:`space-y-2`,children:[z.view?.onboard.available===!0&&z.source!==null&&d(Nc,{source:z.source,geometry:z.view.onboard.geometry,saving:z.saving,error:z.error,onPick:e=>void z.pick(e)}),d(Oi,{tree:R,searchRows:pe,accelerators:ie,cellState:fe,stepBadge:e=>re.has(e)&&z.source!==null?d(gr,{variant:`warning`,title:Mc(z.source,e),children:kc(z.source,e)}):d(st,{gate:le(e)}),disabledCount:Hi(Object.fromEntries(g.map(e=>[e.id,F[e.id]??[]]))),showDisabled:B,onShowDisabledChange:V,dirty:w!==null,onDiscard:()=>T(null),summary:d(`span`,{className:he,children:t(`device.cameraStepInspector.balancedAcross`,{count:oe})}),label:t(`device.cameraStepInspector.detectionStepsOfThisCamera`,`Detection steps of this camera`),renderDetail:({stepId:n,accelerator:r,matchedField:i,closeButton:o,onEscape:c,headingRef:l})=>{let u=r??ie[0],f=u?se(u,n)??ki(L,n):null;if(f===null||u===void 0)return d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:t(`device.cameraStepInspector.noStepSelected`,`No step selected.`)});let p=w?.stepId===n?w:null,m=bn(f),h=qe(m),g=ue(u,n,p),_=Fe(g.node,g.camera,g.accelerator),v=Ai(P[u.nodeId],u,H(u,`object-detection`)?.modelId),y=Ii(f,u,{nodePin:u.device.steps?.[n]?.modelId,cameraPin:de(u,n,p)}).modelId,F=Fe(g.node,g.camera),te=Re(g.accelerator,F,h),R=Li(n),ne=le(n),B=m.find(e=>`label`in e&&e.label===i)?.key??null,V=r===null?null:`${n}|${r.id}`,oe=r===null?`camera`:E?.key===V?E.scope:Fc(H(r,n)),U=e=>{N(null),T(t=>e(t?.stepId===n?t:{stepId:n,perAccelerator:{}}))},fe=(e,t)=>U(n=>({...n,perAccelerator:{...n.perAccelerator,[e.id]:{...n.perAccelerator[e.id],...t}}})),pe=e=>U(t=>{let r=g.accelerator??{},i=Te(t.camera??I?.stepSettings?.[n],e,r,h),a={...t.perAccelerator};for(let r of ae){let i=t.perAccelerator[r.id]?.settings??H(r,n)?.settings;i!==void 0&&(a[r.id]={...a[r.id],settings:We(i,e,h)})}return{...t,camera:i,perAccelerator:a}}),W=async()=>{if(p!==null){j(!0);try{let t=I?.stepSettings?.[n];p.camera!==void 0&&!je(p.camera,t??{})&&await C.mutateAsync({deviceId:e,addonId:n,settings:Object.keys(p.camera).length>0?{...p.camera}:null});let r=p.camera??t;for(let t of ae){let i=p.perAccelerator[t.id];if(i===void 0)continue;let a=H(t,n),o=Lc({stored:a,draft:i,below:Fe(ce(t,n),r),boundKeys:h});Rc(o,a)||await S.mutateAsync({deviceId:e,agentNodeId:t.nodeId,deviceKey:t.deviceKey,addonId:n,patch:o})}T(null),N({kind:`saved`})}catch(e){N({kind:`error`,error:e instanceof Error?e.message:t(`device.cameraStepInspector.saveFailed`)})}finally{j(!1),b()}}},me=p===null?0:+(p.camera!==void 0&&!je(p.camera,I?.stepSettings?.[n]??{}))+Object.values(p.perAccelerator).length,ge=e=>{let r=se(e,n)??f,i=de(e,n,p),a=e.device.steps?.[n]?.modelId,o=Ii(r,e,{nodePin:a,cameraPin:i}),c=ue(e,n,p),l=Ai(P[e.nodeId],e,H(e,`object-detection`)?.modelId),u=Ni(n,Fe(c.node,c.camera,c.accelerator),l),m=ji(r,e)?u&&l?d(Wn,{rootModel:l,stepModelId:o.modelId}):void 0:d(s,{children:t(`device.cameraStepInspector.noBuild`,{format:e.device.format})});return{label:e.label,format:e.device.format,modelId:o.modelId,source:o.source,sourceLabel:Ic(o.source),models:cn(r.models??[],e.device.format),defaultModelId:r.defaultModelIdByFormat?.[e.device.format]??r.defaultModelId,expanded:O===e.id,onToggle:()=>k(t=>t===e.id?null:e.id),onChangeModel:t=>fe(e,{modelId:t}),...i===void 0?{}:{onReset:()=>fe(e,{modelId:null}),resetLabel:a===void 0?`Reset to hardware default`:`Reset to node pin`},...m===void 0?{}:{note:m},changed:p?.perAccelerator[e.id]?.modelId!==void 0}},_e=R===null&&m.length>0?r===null?d(`p`,{className:he,children:t(`device.cameraStepInspector.appliesToAllAcceleratorsOf`,`Applies to: all accelerators of this camera.`)}):a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`span`,{className:`text-[11px] font-medium text-foreground`,children:t(`device.cameraStepInspector.appliesTo`,`Applies to`)}),d(zn,{label:t(`device.cameraStepInspector.settingsApplyTo`,`Settings apply to`),options:[{value:`accelerator`,label:t(`device.cameraStepInspector.thisAccelerator`,`This accelerator`)},{value:`camera`,label:t(`device.cameraStepInspector.allAcceleratorsOfThisCamera`,`All accelerators of this camera`)}],value:oe,onChange:e=>V!==null&&D({key:V,scope:e})})]}):void 0;return d(Xt,{ref:l,title:r===null?t(`device.cameraStepInspector.thisCamera`,`{{name}} · this camera`,{name:f.name}):`${f.name} · ${r.label}`,subtitle:r===null?t(`device.cameraStepInspector.everyAcceleratorThisCameraRuns`,`{{slot}} · every accelerator this camera runs on`,{slot:f.slot}):`${f.slot} · ${r.device.format}`,leading:o,onEscape:c,headerActions:d(In,{gate:ne,busy:x.isPending,onSet:t=>x.mutate({deviceId:e,addonId:n,enabled:t})}),saveBar:{dirtyCount:me,saving:A,status:M?.kind??null,...M?.error===void 0?{}:{error:M.error},onSave:()=>void W(),onDiscard:()=>T(null),..._e===void 0?{}:{scope:_e}},children:a(`div`,{className:`space-y-3`,children:[re.has(n)&&z.source!==null&&d(`p`,{role:`note`,className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-1.5 text-[11px] text-warning`,children:Mc(z.source,n)}),a(`section`,{className:`space-y-2`,"aria-label":t(`device.cameraStepInspector.model`,`Model`),children:[d(`h3`,{className:ee,children:t(`device.cameraStepInspector.model`,`Model`)}),R===null?r===null?d(Mi,{rows:ie.map(e=>{let t=Ii(se(e,n)??f,e,{nodePin:e.device.steps?.[n]?.modelId,cameraPin:de(e,n,p)});return{id:e.id,label:e.label,modelId:t.modelId,sourceLabel:Ic(t.source)}})}):d(Er,{...ge(r)},r.id):d(Vi,{step:R,engineFormat:u.device.format,runnableModelIds:cn(f.models??[],u.device.format).map(e=>e.id)})]}),R===null&&(m.length>0||v!==void 0)&&d(`section`,{"aria-label":t(`device.cameraStepInspector.settings`,`Settings`),className:`border-t border-border/60 pt-2`,children:d(Bc,{addon:f,fields:m,layers:g,scope:oe,viewed:r,modelId:Sr(f,y,_,v),root:v,pinned:r===null?[]:te,highlightKey:B,onChangeCamera:e=>U(t=>({...t,camera:e})),onChangeAccelerator:e=>fe(u,{settings:e}),onApplyToAll:pe,onFollowNode:()=>fe(u,{settings:te.reduce((e,t)=>We(e,t,h),{...g.accelerator})})})}),d(Di,{addonId:n,highlightLabel:i})]})})}})]})}function Bc({addon:e,fields:t,layers:n,scope:r,viewed:i,modelId:a,root:o,pinned:s,highlightKey:c,onChangeCamera:l,onChangeAccelerator:u,onApplyToAll:f,onFollowNode:p}){let{t:m}=Z();Pi(c===null?null:cr(c));let h=i!==null&&n.accelerator!==void 0;return d(Tn,{addon:e,fields:t,layers:{node:n.node,...n.camera===void 0?{}:{camera:n.camera},...h?{accelerator:n.accelerator}:{}},target:r,labels:{...i===null?{}:{accelerator:`This accelerator`},camera:`All accelerators`,node:`Node`},modelId:a,...o===void 0?{}:{rootModel:o},pinnedKeys:s,highlightKey:c,onChangeLayer:r===`camera`?l:u,...s.length>0?{headerActions:d(`button`,{type:`button`,className:se,onClick:p,children:m(`device.cameraStepInspector.followNode`,{count:s.length})})}:{},fieldActions:(e,t)=>i!==null&&t===`accelerator`?d(`button`,{type:`button`,className:se,onClick:()=>f(e),children:m(`device.cameraStepInspector.applyToAllAccelerators`,`Apply to all accelerators`)}):null})}function Vc(e,t,n){return{id:e,get label(){return X.t(t)},icon:n}}var Hc=[Vc(`object-detection`,`helpers.detectionSettingsGroups.objectDetection`,`scan-search`),Vc(`tracking`,`helpers.detectionSettingsGroups.tracking`,`route`),Vc(`motion`,`helpers.detectionSettingsGroups.motion`,`activity`),Vc(`stationary`,`helpers.detectionSettingsGroups.stationary`,`square-parking`),Vc(`zones`,`helpers.detectionSettingsGroups.zones`,`shapes`),Vc(`audio`,`helpers.detectionSettingsGroups.audio`,`volume-2`),Vc(`cluster`,`helpers.detectionSettingsGroups.cluster`,`server`)],Uc={"pipeline-object-detection":`object-detection`,"detection-sensitivity":`object-detection`,"onboard-object-detection":`object-detection`,tracking:`tracking`,"tracking-core":`tracking`,"motion-tuning":`motion`,"stationary-objects":`stationary`,occupancy:`stationary`,zones:`zones`,"pipeline-audio":`audio`,"cluster-assignment":`cluster`,"orchestrator-live":`cluster`};function Wc(e){return Uc[e]??`object-detection`}e();var Gc=`steps`,Kc=`settings`,qc=new Set([Gc,Kc]);function Jc(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function Yc({deviceId:e,activeSubTab:t,onSubTabChange:n}){let{t:r}=Z();return a($n,{value:t&&qc.has(t)?t:Gc,onValueChange:i(e=>{n?.(e)},[n]),className:`flex flex-col`,children:[a(Pn,{className:`flex-shrink-0`,children:[d(mn,{value:Gc,children:r(`device.detectionPipelineTab.steps`,`Steps`)}),d(mn,{value:Kc,children:r(`device.detectionPipelineTab.settings`,`Settings`)})]}),d(fr,{value:Gc,children:d(zc,{deviceId:e})}),d(fr,{value:Kc,children:d(Zr,{deviceId:e,sectionFilter:Jc,subTabGrouping:{groupOf:e=>Wc(e.id),tabs:Hc}})})]})}var Xc=`Notifications`,Zc=`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`;function Qc(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:Xc,on:r===null?null:i??r,available:r!==null,costWhenOff:Zc}}function $c(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}e();function el(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function tl({deviceId:e}){let{t}=Z(),n=c(),o=Number.isFinite(e),[s,l]=r(null),[u,f]=r(null),p=Qc({mutedDeviceIds:el(_r({},{enabled:o}).data),deviceId:e,pendingOn:u}),m=Kn({onError:t=>{console.error(`[DeviceNotificationMute] mute write failed — reverting`,{tags:{deviceId:e},meta:{error:t instanceof Error?t.message:String(t)}}),f(null),l(t instanceof Error?t.message:String(t)),n.invalidateQueries({queryKey:[[`notificationRules`,`listDeviceMutes`]]})},onSuccess:()=>{l(null),f(null),n.invalidateQueries({queryKey:[[`notificationRules`]]})}}),h=i(()=>{let t=$c(p,e);t!==null&&(f(!t.muted),m.mutate(t))},[e,m,p]),g=p.on===null,_=p.on===!1,v=_?$e:E;return a(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[a(`div`,{className:`border-b border-border px-4 py-2 flex items-center justify-between gap-2`,children:[d(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:t(`device.deviceNotificationMute.notifications`,`Notifications`)}),_&&d(`span`,{className:`rounded bg-warning/20 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide text-warning`,children:t(`common.muted`)})]}),a(`div`,{className:`px-4 py-3 flex items-start gap-3`,children:[a(`button`,{type:`button`,role:`switch`,"aria-label":p.label,"aria-checked":p.on===!0,disabled:!p.available||m.isPending,onClick:h,title:g?t(`device.deviceNotificationMute.notificationMuteStateUnknownThe`,`Notification mute — state unknown; the notification centre did not answer.`):_?t(`device.deviceNotificationMute.muted`,`Muted. {{costWhenOff}}`,{costWhenOff:p.costWhenOff}):t(`device.deviceNotificationMute.notifyingMutingIt`,`Notifying. Muting it: {{costWhenOff}}`,{costWhenOff:p.costWhenOff}),className:`inline-flex items-center gap-1.5 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors disabled:cursor-not-allowed ${s===null?g?`border-dashed border-border text-foreground-subtle/50`:_?`border-warning/40 text-warning hover:bg-warning/10`:`border-success/30 text-success hover:bg-success/10`:`border-danger/50 text-danger bg-danger/5`}`,children:[d(v,{className:`h-3.5 w-3.5`}),d(`span`,{children:g?t(`device.deviceNotificationMute.unknown`,`Unknown`):_?t(`device.deviceNotificationMute.muted2`,`Muted`):t(`device.deviceNotificationMute.notifying`,`Notifying`)})]}),d(`p`,{className:`flex-1 text-[11px] leading-relaxed text-foreground-subtle`,children:s===null?g?t(`device.deviceNotificationMute.theNotificationCentreDidNot`,`The notification centre did not answer, so this device’s mute state is unknown.`):p.costWhenOff:t(`device.deviceNotificationMute.writeFailed`,`Write failed: {{failure}}`,{failure:s})})]})]})}function nl(e,t){return{switchId:e,label:Ee[e].label,detail:t===void 0||t.length===0?null:t}}function rl(e){let t=new Map;for(let n of e.switches)n.deviceId===e.sourceId&&(t.has(n.switchId)||t.set(n.switchId,n));return t}function il(e){let t=rl(e),n=new Set(e.sourceStillLive),r=e.sourceStillLive.map(e=>nl(e,t.get(e)?.detail)),i=[...t.values()].filter(e=>e.outcome===`not-offered`&&!n.has(e.switchId)).map(e=>nl(e.switchId,e.detail));return{inheritedId:e.sourceId,retiredId:e.targetId,swapped:e.swapped,verdict:r.length===0?`quiet`:`still-live`,stillLive:r,neverOffered:i}}e();function al(e,t){return e.filter(e=>e.isCamera&&e.id!==t).map(e=>({id:e.id,name:e.name})).toSorted((e,t)=>e.name.localeCompare(t.name))}function ol({deviceId:e,deviceName:t}){let{t:i}=Z(),o=it(),[s,c]=r(null),l=sn({isCamera:!0,projection:`slim`}),u=lt(),f=l.data!==void 0,p=n(()=>l.data===void 0?[]:al(l.data,e),[l.data,e]),m=p.find(e=>e.id===s)??null,h=u.data===void 0?null:il(u.data),g=u.error===null?null:u.error.message,_=async()=>{m===null||m.id===e||await o({title:i(`deviceMigrate.confirmTitle`,`Replace “{{source}}” with “{{target}}”?`,{source:t,target:m.name}),message:i(`deviceMigrate.confirmMessage`,`“{{target}}” takes over number {{sourceId}}. That number is what every recording, event, rule, zone and home-automation export of “{{source}}” is filed under, so all of it follows the number to the new hardware and keeps working. “{{source}}” is switched off and handed number {{targetId}} in exchange. This swaps two device identities and cannot be undone from here.`,{source:t,target:m.name,sourceId:e,targetId:m.id}),confirmLabel:i(`deviceMigrate.confirmAction`,`Migrate`),variant:`danger`})&&u.mutate({sourceId:e,targetId:m.id})};return a(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[a(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[a(`div`,{className:`min-w-0`,children:[d(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:i(`deviceMigrate.title`,`Migrate to…`)}),d(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:i(`deviceMigrate.subtitle`,`Replace this camera with other hardware you have already adopted. The new camera inherits number {{deviceId}}, so recordings, rules and integrations follow it.`,{deviceId:e})})]}),a(`div`,{className:`flex shrink-0 items-center gap-2`,children:[a(`select`,{"aria-label":i(`deviceMigrate.pickerLabel`,`Replacement camera`),className:`rounded-md border border-border bg-background px-2 py-1.5 text-xs text-foreground disabled:opacity-50`,disabled:!f||p.length===0||u.isPending,value:s===null?``:String(s),onChange:e=>{let t=e.target.value;c(t===``?null:Number(t))},children:[d(`option`,{value:``,children:f?i(`deviceMigrate.pickerPlaceholder`,`Select a camera…`):i(`deviceMigrate.pickerPending`,`Reading the fleet…`)}),p.map(e=>a(`option`,{value:String(e.id),children:[e.name,` (#`,e.id,`)`]},e.id))]}),a(`button`,{type:`button`,disabled:m===null||u.isPending,onClick:()=>{_()},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[d(Ye,{className:`h-3 w-3`}),u.isPending?i(`deviceMigrate.running`,`Migrating…`):i(`deviceMigrate.action`,`Migrate`)]})]})]}),f&&p.length===0&&d(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:i(`deviceMigrate.noTargets`,`No other camera is adopted, so there is nothing to migrate to.`)}),g!==null&&d(`p`,{className:`mt-2 text-[11px] text-danger`,children:i(`deviceMigrate.failed`,`Migration failed: {{error}}`,{error:g})}),h!==null&&d(sl,{report:h})]})}function sl({report:e}){let{t}=Z(),n=e.verdict===`quiet`;return a(`div`,{className:`mt-3 space-y-2 border-t border-border pt-3`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`deviceMigrate.swapped`,`The replacement now answers on number {{inheritedId}}; the old camera was handed number {{retiredId}}.`,{inheritedId:e.inheritedId,retiredId:e.retiredId})}),n?a(`div`,{className:`flex items-start gap-2 rounded-md border border-success/30 bg-success/5 px-3 py-2`,children:[d(le,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-success`}),d(`p`,{className:`text-[11px] leading-relaxed text-foreground`,children:t(`deviceMigrate.quiet`,`Every function on the replaced camera was switched off — the old hardware is quiet.`)})]}):a(`div`,{className:`rounded-md border border-warning/40 bg-warning/5 px-3 py-2`,children:[a(`div`,{className:`flex items-start gap-2`,children:[d(W,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),d(`p`,{className:`text-[11px] leading-relaxed text-foreground`,children:t(`deviceMigrate.stillLive`,`The replaced camera could not be reached, so these functions are STILL RUNNING on the old hardware. Nothing here failed to migrate — but until you unplug it or reach it physically, it can still produce data.`)})]}),d(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.stillLive.map(e=>a(`li`,{className:`text-[11px] text-foreground`,children:[d(`span`,{className:`font-medium`,children:e.label}),e.detail!==null&&a(`span`,{className:`text-foreground-subtle`,children:[` — `,e.detail]})]},e.switchId))})]}),e.neverOffered.length>0&&a(`div`,{className:`rounded-md border border-border px-3 py-2`,children:[a(`div`,{className:`flex items-start gap-2`,children:[d(nt,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),d(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`deviceMigrate.neverOffered`,`The replaced camera never offered these, so there was nothing to switch off. They are not running.`)})]}),d(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.neverOffered.map(e=>d(`li`,{className:`text-[11px] text-foreground-subtle`,children:e.label},e.switchId))})]})]})}e();function cl({deviceId:e}){let{t}=Z(),[n,i]=r(null),o=Cn({onSuccess:e=>{i(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>i(`Re-sync failed: ${e.message}`)});return a(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[a(`div`,{className:`flex items-center justify-between gap-3`,children:[a(`div`,{children:[d(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:t(`device.resyncButton.reSync`,`Re-sync`)}),d(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:t(`device.resyncButton.reAlignThisDeviceS`,`Re-align this device's type, role, capabilities and units with its source.`)})]}),a(`button`,{type:`button`,disabled:o.isPending,onClick:()=>{i(null),o.mutate({camDeviceId:e})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[d(R,{className:`h-3 w-3 ${o.isPending?`animate-spin`:``}`}),o.isPending?t(`device.resyncButton.reSyncing`,`Re-syncing…`):t(`device.resyncButton.reSync`,`Re-sync`)]})]}),n!==null&&d(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:n})]})}function ll(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function ul({device:e}){let{t}=Z(),n=Jr(),r=typeof e.id==`number`?e.id:null,i=String(e.type??``),o=i===K.Camera,s=i===K.Hub,c=e.features??[],l=c.includes(Pe.Resyncable),{data:u}=at({deviceId:r??0},{enabled:r!==null&&o,refetchInterval:5e3}),f=u?.streams??{},p=Object.entries(f),m=c.includes(Pe.DoorbellButton),h=jn(m?{deviceId:r??void 0,historyLimit:10}:void 0),g=h.latest?Date.now()-h.latest.timestamp<3e4:!1;return a(`div`,{className:`space-y-5`,children:[s&&r!==null&&d(an,{deviceId:r,onOpenChild:e=>n(`/devices/${e}`)}),l&&r!==null&&d(cl,{deviceId:r}),o&&r!==null&&d(ol,{deviceId:r,deviceName:String(e.name??``)}),r!==null&&d(tl,{deviceId:r}),o&&r!==null&&d(ht,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:r}),m&&d(Et,{history:h.history,latestIsFresh:g}),o&&r!==null&&d(ht,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:r}),o&&p.length>0&&a(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[d(`div`,{className:`border-b border-border px-4 py-2`,children:d(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:t(`device.overviewTab.streamNetwork`,`Stream Network`)})}),d(`div`,{className:`divide-y divide-border`,children:p.map(([e,n])=>a(`div`,{className:`px-4 py-2.5`,children:[a(`div`,{className:`flex items-center gap-2 mb-2`,children:[d(ie,{className:`h-3 w-3 text-foreground-subtle`}),d(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),a(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[d(dl,{label:t(`device.overviewTab.nominal`,`Nominal`),value:ll(n.nominalBitrateKbps??0)}),d(dl,{label:t(`device.overviewTab.observed`,`Observed`),value:ll(n.observedBitrateKbps??0)}),d(dl,{label:t(`device.overviewTab.peak`,`Peak`),value:ll(n.peakBitrateKbps??0)}),d(dl,{label:t(`device.overviewTab.packetLoss`,`Packet Loss`),value:`${(n.packetLossPercent??0).toFixed(2)}%`,warning:(n.packetLossPercent??0)>1})]})]},e))})]}),d(Pr,{}),r!==null&&d(Mr,{deviceId:r})]})}function dl({label:e,value:t,warning:n}){return a(`div`,{children:[d(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),d(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}var fl=[{id:`overview`,labelKey:`helpers.structuralTabs.overview`,cameraOnly:!1,adminOnly:!1},{id:`config`,labelKey:`helpers.structuralTabs.config`,cameraOnly:!1,adminOnly:!1},{id:Xr,labelKey:`helpers.structuralTabs.customize`,cameraOnly:!1,adminOnly:!0},{id:`detection-pipeline`,labelKey:`helpers.structuralTabs.detectionPipeline`,cameraOnly:!0,adminOnly:!1},{id:`bindings`,labelKey:`helpers.structuralTabs.bindings`,cameraOnly:!0,adminOnly:!1}];function pl(e,t){let n=e===K.Camera;return fl.filter(e=>(n||!e.cameraOnly)&&(t||!e.adminOnly)).map(({id:e,labelKey:t})=>({id:e,label:X.t(t)}))}function ml({provider:e,integrationId:t,name:n}){let r=Jr(),i=t===null?`/integrations`:`/integrations/${t}`,a=n===null?`Open integrations`:`Open integration ${n}`;return d(`button`,{type:`button`,onClick:()=>r(i),className:`shrink-0 rounded-md transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-1 focus-visible:ring-primary/50`,title:a,"aria-label":a,children:d(Kr,{type:e,size:`lg`})})}e();var hl=[{id:`logs`,icon:ue,labelKey:`common.logs`},{id:`repl`,icon:tt,labelKey:`deviceDetail.repl`},{id:`events`,icon:y,labelKey:`common.events`},{id:`state`,icon:C,labelKey:`common.state`}];function gl(){let{t:e}=Z(),t=ti(),o=Number(t.deviceId),u=Number.isFinite(o),f=Jr(),p=c(),m=it(),_=U(),{user:v}=Ur(),y=v?.isAdmin===!0,[x,S]=Qr(),C=x.get(`tab`)??`overview`,w=x.get(`sub`),[T,E]=r(`logs`),D=`device-detail.left-col-width-px`,[O,k]=r(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(D),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),A=l(O);A.current=O;function j(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??O??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{k(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=A.current;if(e!==null)try{window.localStorage.setItem(D,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:M,isLoading:ee,isError:P}=sr({deviceId:o},{enabled:u,refetchInterval:5e3,retry:1}),{data:F}=Jn({deviceId:o},{enabled:u}),te=n(()=>{let e=F?.settings?.sections??[],t=F?.live?.sections??[],n=[...e,...t],r=new Set;for(let e of n)e.location===`top-tab`&&e.tab&&r.add(e.tab===`zones`?`detection-pipeline`:e.tab);return n.some(Fr)&&r.add(Br),[...r].map(e=>e===`export`?{id:e,label:Nr,isAddonContrib:!0}:{id:e,label:Ge[e]?.label??e,isAddonContrib:!0})},[F]),I=M,L=String(I?.name??t.deviceId??`Device`),ne=I?.online===!0,z=ne?`online`:`offline`,re=String(I?.addonId??`rtsp`),B=I?.features??[],V=I?.type,ie=V===K.Camera,{data:ae}=Wr(u?o:0),oe=V===K.Container,se=n(()=>(ae??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[ae]),H=n(()=>oe?Tr(se,typeof I?.linkDeviceId==`number`?I.linkDeviceId:null,typeof I?.primaryChildEntityId==`string`?I.primaryChildEntityId:null)?.id??null:null,[oe,se,I?.linkDeviceId,I?.primaryChildEntityId]),{data:ce}=Jn({deviceId:H??0},{enabled:H!==null}),le=n(()=>{if(H===null)return[];let e=ce?.settings?.sections??[],t=ce?.live?.sections??[],n=new Set;for(let r of[...e,...t])r.location===`top-tab`&&r.tab&&n.add(r.tab);return[...n].map(e=>({id:e,label:Ge[e]?.label??e,isAddonContrib:!0,childDeviceId:H}))},[H,ce]),ue=typeof I?.parentDeviceId==`number`?I.parentDeviceId:null,{data:de}=sr({deviceId:ue??0},{enabled:ue!==null}),W=qn(),me=I?.disabled!==!0,he=n(()=>{let e=F?.settings?.sections??[],t=F?.live?.sections??[];return Rr([...e,...t],V,y,F!==void 0)},[F,V,y]),ge=n(()=>{let e=new Set,t=[];for(let n of[...pl(V,y),...te,...le])n.id===`config`&&!he||e.has(n.id)||(e.add(n.id),t.push(n));return t},[V,y,te,le,he]),_e=n(()=>_c(ge,C),[ge,C]),ve=i(e=>{S(t=>{let n=new URLSearchParams(t);e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`);for(let e of Wi)n.delete(e);return n},{replace:!0})},[S]),ye=i(e=>{S(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[S]),be=(ae??[]).length>0,xe=n(()=>hl.filter(({featureGate:e})=>!e||B.includes(e)),[B]),{data:G}=xn(void 0),q=n(()=>I?Fn(I,G):null,[I,G]),J=q?.kind===`resolved`?q.integration:null,Se=J===null?q?.kind===`unknown`?e(`deviceDetail.loadingIntegration`):q?.kind===`orphan`?e(`deviceDetail.missingIntegration`):e(`deviceDetail.noIntegration`):J.name,Ce=J!==null&&J.addonId===re?J.name:re,we=mt({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]}),f(J?.id?`/integrations/${J.id}`:`/integrations`)}}),Te=Un({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ee=Mn({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),De=Bn(),Oe=Ut({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=B.includes(Pe.Rebootable),Ae=B.includes(Pe.BatteryOperated),je=Sn(_.trpcClient,Ae&&u?o:null),Me=Cr(_.trpcClient,u?o:null),[Ne,Fe]=r(!1),Ie=async()=>{if(!Ne){Fe(!0);try{let e=L.replace(/[^a-zA-Z0-9_.-]+/g,`_`),t=new Date().toISOString().replace(/[:.]/g,`-`);await aa(`${N}/${String(o)}.jpg?force=1`,`${e}-${t}.jpg`)}finally{Fe(!1)}}},Le=Te.isPending||Ee.isPending,{data:Re}=ct({deviceId:o},{enabled:u&&ie,refetchInterval:1e4}),ze=Re?.agentNodeId??null,Be=typeof ze==`string`&&ze.length>0&&!ze.startsWith(`addon:`)?ze:void 0,{data:Ve}=Yn({deviceId:o,...Be?{nodeId:Be}:{}},{enabled:u&&ie,refetchInterval:3e3,retry:!1}),{data:He}=rn({deviceId:o},{enabled:u&&ie,refetchInterval:3e3,retry:!1}),Ue=He?.level?.dbfs??null;function We(){if(!u)return null;switch(_e){case`overview`:return d(ul,{device:I??{}});case`config`:return d(Sc,{deviceId:o,activeSubTab:w,onSubTabChange:ye,deviceType:V,isAdmin:y});case`detection-pipeline`:return d(Yc,{deviceId:o,activeSubTab:w,onSubTabChange:ye});case`bindings`:return d(vc,{deviceId:o});case Xr:return d(uc,{deviceId:o,activeSubTab:w,onSubTabChange:ye});default:{let e=_e,t=te.some(t=>t.id===e),n=le.find(t=>t.id===e);if(!t&&n===void 0)return null;let r=n?.childDeviceId??o;if(e===`export`)return d(Zr,{deviceId:o,sectionFilter:Fr,activeSubTab:w,onSubTabChange:ye});let i=d(Zr,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:w,onSubTabChange:ye});return n!==void 0&&r!==o?d(Dt,{deviceId:r,children:i}):i}}}return u?ee?a(`div`,{className:`flex flex-col h-full`,children:[a(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[d(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),d(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),d(`div`,{className:`flex-1 p-6`,children:d(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):P||!M?a(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[d(`p`,{className:`text-lg font-semibold text-foreground`,children:e(`deviceDetail.deviceNotFound`,`Device not found`)}),d(`p`,{className:`text-xs`,children:d(qr,{i18nKey:`deviceDetail.noDeviceWithId`,values:{id:o},components:{code:d(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`})}})}),d(`button`,{onClick:()=>f(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:e(`deviceDetail.backToIntegrations`,`Back to Integrations`)})]}):a(`div`,{className:`absolute inset-0 flex flex-col overflow-clip`,children:[a(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[d(`div`,{className:`mb-2`,children:d(Ot,{items:[{label:e(`deviceDetail.integrations`,`Integrations`),onClick:()=>f(`/integrations`)},J===null?{label:Se}:{label:Se,onClick:()=>f(`/integrations/${J.id}`)},{label:L}]})}),a(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[J!==null&&d(ml,{provider:J.addonId,integrationId:J.id,name:J.name}),a(`div`,{className:`min-w-0 flex-1`,children:[a(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[d(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:L}),d(Mt,{status:z}),Ae&&d(wn,{status:je,variant:`full`}),d(ot,{status:Me})]}),ue!==null&&de&&a(`button`,{type:`button`,onClick:()=>f(`/devices/${ue}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:e(`deviceDetail.openParentDevice`,`Open parent device {{name}}`,{name:de.name}),children:[d(`span`,{children:`↑`}),d(`span`,{className:`truncate`,children:String(de.name??`Device #${ue}`)})]}),d(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:B.length>0&&d(Gr,{capabilities:B})})]}),Ve&&d(`div`,{className:`hidden lg:flex`,children:d(_l,{metrics:Ve,dbfs:Ue})}),a(`div`,{className:`flex items-center gap-1 shrink-0`,children:[a(`button`,{onClick:async()=>{me?await m({title:e(`deviceDetail.disable`,`Disable "{{name}}"?`,{name:L}),message:e(`deviceDetail.theDeviceWillStopProcessing`,`The device will stop processing streams and events. You can re-enable it later.`),confirmLabel:e(`common.disable`,`Disable`),variant:`danger`})&&Ee.mutate({deviceId:o}):Te.mutate({deviceId:o})},disabled:Le,title:me?e(`deviceDetail.disableDevice`,`Disable device`):e(`deviceDetail.enableDevice`,`Enable device`),className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border transition-colors disabled:opacity-50 ${me?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[d(g,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden sm:inline`,children:Le?e(`deviceDetail.updating`,`Updating…`):me?e(`deviceDetail.enabled`,`Enabled`):e(`deviceDetail.disabled`,`Disabled`)})]}),d(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),ie&&a(s,{children:[d(fa,{deviceId:o}),d(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),d(ma,{deviceId:o}),d(kt,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:e(`deviceDetail.takeSnapshot`,`Take snapshot`),description:e(`deviceDetail.fetchAFreshFrameAnd`,`Fetch a fresh frame and download it.`),icon:h,disabled:Ne,onClick:()=>{Ie()}},{id:`reboot`,label:e(`deviceDetail.rebootDevice`,`Reboot device`),description:e(`deviceDetail.cameraGoesOfflineFor30`,`Camera goes offline for ~30 seconds.`),icon:pe,hidden:!ke,disabled:De.isPending,danger:!0,onClick:async()=>{await m({title:e(`deviceDetail.reboot`,`Reboot "{{name}}"?`,{name:L}),message:e(`deviceDetail.theCameraWillGoOffline`,`The camera will go offline for around 30 seconds while the firmware reboots.`),confirmLabel:e(`deviceDetail.reboot2`,`Reboot`),variant:`danger`})&&De.mutate({deviceId:o})}},{id:`restart-addon`,label:e(`deviceDetail.restartAddon`,`Restart addon`),description:e(`deviceDetail.bouncesEveryDeviceServedBy`,`Bounces every device served by {{servingAddonLabel}}.`,{servingAddonLabel:Ce}),icon:R,disabled:Oe.isPending,danger:!0,onClick:async()=>{await m({title:e(`deviceDetail.restart`,`Restart "{{servingAddonLabel}}"?`,{servingAddonLabel:Ce}),message:e(`deviceDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device served by it (not just "{{name}}"). Streams will reconnect automatically.`,{name:L}),confirmLabel:e(`deviceDetail.restart2`,`Restart`),variant:`danger`})&&Oe.mutate({addonId:re})}},{id:`delete`,label:e(`deviceDetail.deleteDevice`,`Delete device`),description:e(`deviceDetail.removeTheDeviceAndAll`,`Remove the device and all its settings.`),icon:b,separatorBefore:!0,disabled:we.isPending,danger:!0,onClick:async()=>{await m({title:e(`deviceDetail.delete`,`Delete "{{name}}"?`,{name:L}),message:e(`deviceDetail.thisWillRemoveTheDevice`,`This will remove the device and all its settings. This action cannot be undone.`),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&we.mutate({deviceId:o})}}]})]})]})]}),d(Dt,{deviceId:o,device:I??void 0,children:d(jt,{children:d(Ht,{children:d(fe,{children:d(gn,{children:a(`main`,{className:W?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[a(`div`,{className:W?`flex flex-col bg-surface`:`${O===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!W&&O!==null?{width:`${String(O)}px`}:void 0,children:[d(`div`,{className:ie?`flex-shrink-0 border-b border-border-subtle bg-black`:W?`flex-shrink-0 border-b border-border-subtle bg-surface`:`max-h-[55%] shrink-0 overflow-y-auto border-b border-border-subtle bg-surface`,children:ie?d(Ja,{deviceId:o,intercomAvailable:B.includes(Pe.TwoWayAudio)}):d(Ra,{deviceId:o,deviceName:L,deviceType:V??`unknown`,provider:re,isOnline:ne,features:B})}),a(`div`,{className:W?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[d(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:d(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:xe.map(({id:t,labelKey:n,icon:r})=>{let i=T===t;return a(`button`,{onClick:()=>E(t),title:e(n),className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${i?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[d(r,{className:`h-3 w-3`}),e(n)]},t)})})}),a(`div`,{className:W?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[T===`logs`&&d(Ya,{deviceId:o,containerDeviceId:V===`container`?o:void 0}),T===`repl`&&d(Xa,{deviceId:o}),T===`events`&&d(Za,{deviceId:o}),T===`state`&&d(Qa,{deviceId:o})]})]})]}),!W&&d(`div`,{role:`separator`,"aria-orientation":`vertical`,title:e(`deviceDetail.dragToResize`,`Drag to resize`),onMouseDown:j,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:d(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),a(`div`,{className:W?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[d(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:d(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:ge.map(e=>{let t=_e===e.id;return a(`button`,{onClick:()=>ve(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&d(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),a(`div`,{className:W?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[_e===`overview`&&be&&d(ha,{parentDeviceId:o}),We()]})]})]})})})})})})]}):a(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[d(`p`,{className:`text-lg font-semibold text-foreground`,children:e(`deviceDetail.invalidDeviceId`,`Invalid device id`)}),d(`p`,{className:`text-xs`,children:d(qr,{i18nKey:`deviceDetail.invalidSegment`,values:{segment:t.deviceId},components:{code:d(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`})}})}),d(`button`,{onClick:()=>f(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:e(`deviceDetail.backToIntegrations`,`Back to Integrations`)})]})}function _l({metrics:e,dbfs:t}){let n=H(),{t:r}=Z(),i=Wt(e.phase??`idle`,n);return a(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[a(`div`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`h-1.5 w-1.5 rounded-full ${i.dotClass}`}),d(`span`,{className:`text-[10px] font-medium ${i.textColor}`,children:i.label})]}),d(`div`,{className:`h-3 w-px bg-border`}),a(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[d(B,{className:`h-3 w-3`}),d(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),d(`span`,{children:r(`common.fpsWord`)})]}),a(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[d(F,{className:`h-3 w-3`}),d(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),d(`span`,{children:`ms`})]}),a(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:r(`deviceDetail.currentAudioLevelDbfs`,`Current audio level (dBFS)`),children:[d(j,{className:`h-3 w-3`}),d(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),d(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&a(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{gl as DeviceDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,L as i,S as a,a as o,b as s,o as c,q as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{$t as f,D as p,Fn as m,It as h,Nt as g,Rr as _,Tt as v,Wi as y,Wr as b,an as x,bn as S,cn as C,dn as w,dt as T,kn as E,ln as D,lr as O,mi as k,mr as A,oa as j,or as M,ot as N,pn as P,rr as F,sn as I,xi as L,yi as R}from"./player-overlays-CCZE3o8q.js";import{Ci as z,Si as ee,a as B,c as V,o as te,s as ne,wi as re}from"./client-Cy6wyTLQ.js";import{i as ie,n as ae,r as oe,t as se}from"./key-bw9xhRgT.js";import{d as H,l as ce,s as le}from"./video-BJUj4GaK.js";import{t as ue}from"./history-DqvhlzWX.js";import{t as de}from"./key-round-BngMS2dZ.js";import{t as fe}from"./monitor-smartphone-D_W4zyWO.js";import{t as pe}from"./unlink-HIuzqEig.js";import{$ as me,$l as he,$n as U,Bl as ge,Bn as _e,Dn as W,Fl as ve,Fo as ye,Gl as be,Gt as xe,Hl as Se,Hn as G,Ho as Ce,Il as we,Kl as Te,Kt as Ee,Ll as De,Lt as Oe,Ml as ke,Mn as Ae,N as je,Nl as Me,Nn as Ne,No as Pe,On as Fe,Or as Ie,P as Le,Pl as Re,Q as ze,Ql as Be,Rl as Ve,Ro as He,Rt as Ue,Sn as We,Su as K,Tn as Ge,Ul as Ke,Ut as qe,V as Je,Vl as Ye,Vn as Xe,Vo as Ze,Wl as Qe,Wt as q,Zl as $e,_a as et,an as tt,cn as nt,er as rt,eu as it,in as at,jl as ot,jn as st,kn as ct,kr as lt,nn as ut,nu as dt,on as ft,q as pt,sr as J,tu as mt,z as ht,zl as gt,zn as _t}from"./src-Cw4W7OtK.js";import{t as Y}from"./i18n-B1bxeya5.js";import{t as X}from"./useTranslation-D3Is_4B6.js";import{$ as vt,Q as yt,T as bt,V as xt,Z as St,a as Ct,d as wt,et as Tt,i as Et,l as Dt,nt as Ot}from"./index-yoPG03d0.js";import{t as kt}from"./AdminSectionedPage-BiMhPKOP.js";import{t as At}from"./AdminPage-KGO_m_yt.js";import{A as jt,C as Mt,D as Nt,E as Pt,F as Ft,M as It,N as Z,O as Lt,P as Rt,S as zt,T as Bt,_ as Vt,a as Ht,b as Ut,c as Wt,d as Gt,f as Kt,h as qt,i as Jt,j as Yt,k as Xt,l as Zt,m as Qt,n as $t,o as en,p as tn,s as nn,t as rn,u as an,v as on,w as sn,x as cn,y as ln}from"./SessionsList-bmTxxIOE.js";import{i as un,n as dn,r as fn,t as pn}from"./IntegrationHub-tqxee2Rm.js";import{n as mn,t as hn}from"./addon-display-names-BkwMrExv.js";e();function gn(){let{t:e}=X(),t=U(),i=K.useUtils(),a=Ft(),{data:o,isLoading:s}=gt(),c=n(()=>o??[],[o]),l=K.useQueries(e=>c.map(t=>e.userManagement.listExternalIdentities({userId:t.id}))),u=K.auth.listLoginMethods.useQuery(),[f,p]=r(null),m=be({onSuccess:()=>void i.userManagement.listExternalIdentities.invalidate(),onError:e=>p(`Remove failed: ${e.message}`)}),h=n(()=>new Map((u.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),[u.data]),g=c.flatMap((e,t)=>l[t]?.data??[]),_=g.map(e=>({...Bt(e,a),kind:h.get(e.provider)??e.provider})),v=async n=>{let r=g.find(e=>sn(e)===n.id);r!==void 0&&await t({title:e(`access.externalIdentitiesSection.removeSignInLink`,`Remove sign-in link`),message:e(`access.externalIdentitiesSection.willNoLongerBeAble`,`"{{ownerName}}" will no longer be able to sign in with this {{kind}} account.`,{ownerName:n.ownerName,kind:n.kind}),confirmLabel:e(`common.remove`,`Remove`),variant:`danger`})&&(p(null),m.mutate({userId:r.userId,provider:r.provider,subject:r.subject}))};return d(Z,{notice:Rt(f),onDismissNotice:()=>{p(null)},id:`external-identities`,title:e(`access.externalIdentitiesSection.signInLinks`,`Sign-in links`),icon:H,description:e(`access.externalIdentitiesSection.externalAccountsSingleSignOn`,`External accounts (single sign-on) each user linked to their CamStack account. Only the owner can link one, from their profile; an admin can remove it.`),children:d(Xt,{rows:_,label:`sign-in links`,isLoading:s||l.some(e=>e.isLoading),loadError:l.find(e=>e.isError)?.error?.message??null,emptyText:`No user has linked a sign-in account.`,expiresNone:`—`,action:{label:e(`common.remove`,`Remove`),icon:pe,isAvailable:()=>!0,onRun:e=>void v(e),busyId:null,disabled:m.isPending}})})}e();function _n(){let{t:e}=X(),t=U(),i=c(),a=Ft(),o=we(),[s,l]=r(null),u=Ye({onSuccess:()=>void i.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),onError:e=>l(`Revoke failed: ${e.message}`)}),f=n(()=>(o.data??[]).map(e=>Mt(e,a)),[o.data,a]),p=async n=>{await t({title:e(`access.legacyApiKeysSection.revoke`,`Revoke "{{name}}"?`,{name:n.name}),message:e(`access.legacyApiKeysSection.anyClientUsingThisKey`,`Any client using this key loses access immediately. This cannot be undone.`),confirmLabel:e(`access.legacyApiKeysSection.revoke2`,`Revoke`),variant:`danger`})&&(l(null),u.mutate({id:n.id}))};return d(Z,{notice:Rt(s),onDismissNotice:()=>{l(null)},id:`legacy-api-keys`,title:e(`access.legacyApiKeysSection.legacyApiKeys`,`Legacy API keys`),icon:ue,description:e(`access.legacyApiKeysSection.keysFromBeforeScopedTokens`,`Keys from before scoped tokens. Nothing creates them any more; revoke them and issue a scoped token instead.`),children:d(Xt,{rows:f,label:e(`access.legacyApiKeysSection.legacyApiKeys2`,`legacy API keys`),isLoading:o.isLoading,loadError:o.isError?o.error?.message??`Request failed`:null,emptyText:`No legacy API keys.`,action:{label:e(`access.legacyApiKeysSection.revoke2`,`Revoke`),icon:h,isAvailable:()=>!0,onRun:e=>void p(e),busyId:u.isPending?u.variables?.id??null:null,disabled:u.isPending}})})}e();var vn={key:`access.nouns.linkedApp`};function yn(e){if(e.type===`category`){let t=e.target??``;return t===`device`?Y.t(`access.linkedAppsSection.allDevices`):Y.t(`access.linkedAppsSection.allTarget`,{target:t})}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function bn(){let{t:e}=X(),t=U(),i=c(),a=Ve(),[o,s]=r(null),l=()=>void i.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),u=Se({onSuccess:l,onError:e=>s(`Revoke failed: ${e.message}`)}),f=jt(`oauth-session`,vn,l),p=n(()=>(a.data??[]).map(e=>Pt(e,e.scopes.map(yn).join(`, `))),[a.data]),m=async n=>{await t({title:e(`access.linkedAppsSection.revokeTheLink`,`Revoke the "{{name}}" link?`,{name:n.name}),message:e(`access.linkedAppsSection.losesAccessForOnIts`,`{{name}} loses access for {{ownerName}} on its next call. Linking it again needs the account-link flow from the start.`,{name:n.name,ownerName:n.ownerName}),confirmLabel:e(`access.linkedAppsSection.revoke`,`Revoke`),variant:`danger`})&&(s(null),u.mutate({id:n.id}))},g=u.isPending?u.variables?.id??null:null;return d(Z,{notice:Rt(o,f.outcome),onDismissNotice:()=>{s(null),f.dismiss()},id:`linked-apps`,title:e(`access.linkedAppsSection.linkedApps`,`Linked apps`),icon:O,description:e(`access.linkedAppsSection.externalIntegrationsAlexaLinkedTo`,`External integrations (Alexa, …) linked to this hub through OAuth. Revoking one stops that integration on its next call. Already-revoked rows can be selected and removed from the list.`),children:d(Xt,{rows:p,label:e(`access.linkedAppsSection.linkedApps2`,`linked apps`),isLoading:a.isLoading,loadError:a.isError?a.error?.message??`Request failed`:null,emptyText:`No linked apps — an integration appears here once it completes the account-link flow.`,expiresNone:`—`,action:{label:e(`access.linkedAppsSection.revoke`,`Revoke`),icon:h,isAvailable:e=>e.status===`active`||e.status===`revoked`,onRun:e=>void m(e),busyId:g,disabled:u.isPending||f.busy},bulk:{revoke:f,noun:vn,isSelectable:e=>e.status===`active`||e.status===`revoked`,quickSelect:[{label:e(`access.linkedAppsSection.selectRevoked`,`Select revoked`),match:e=>e.status===`revoked`}]}})})}e();var xn={key:`access.nouns.session`};function Sn(){let{t:e}=X(),t=U(),i=K.useUtils(),a=Ft(),o=K.auth.listSessions.useQuery(),[s,c]=r(null),l=()=>void i.auth.listSessions.invalidate(),u=K.auth.revokeSessions.useMutation({onSuccess:l,onError:e=>c(`Sign out failed: ${e.message}`)}),f=jt(`login-session`,xn,l),p=n(()=>(o.data??[]).map(e=>Nt(e,a,{client:e=>on(e).label,method:ln})),[o.data,a]),m=async n=>{await t({title:e(`access.loginSessionsSection.signOutThisSession`,`Sign out this session`),message:e(`access.loginSessionsSection.onWillHaveToSign`,`{{ownerName}} on {{name}} will have to sign in again.`,{ownerName:n.ownerName,name:n.name}),confirmLabel:e(`access.loginSessionsSection.signOut`,`Sign out`),variant:`danger`})&&(c(null),u.mutate({id:n.id}))};return d(Z,{notice:Rt(s,f.outcome),onDismissNotice:()=>{c(null),f.dismiss()},id:`login-sessions`,title:e(`access.loginSessionsSection.loginSessions`,`Login sessions`),icon:fe,description:e(`access.loginSessionsSection.everyBrowserAndAppSigned`,`Every browser and app signed in to this hub, for every user. Signing one out ends it at once; it has to sign in again. Your own current session is marked and never included in a bulk sign-out.`),children:d(Xt,{rows:p,label:e(`common.sessionsLabel`),isLoading:o.isLoading,loadError:o.isError?o.error?.message??`Request failed`:null,emptyText:`No active sessions.`,action:{label:e(`access.loginSessionsSection.signOut`,`Sign out`),icon:le,isAvailable:e=>e.status===`active`,onRun:e=>void m(e),busyId:u.isPending&&u.variables!==void 0&&`id`in u.variables?u.variables.id:null,disabled:u.isPending||f.busy},bulk:{revoke:f,noun:xn,isSelectable:e=>e.status===`active`}})})}function Cn({token:e,label:t,onClose:n}){let{t:r}=X();return d(W,{open:!0,onOpenChange:e=>!e&&n(),children:a(ct,{width:`md`,scroll:`body`,children:[d(Ae,{children:d(Ne,{children:r(`auth.tokenModals.token`,`Token: {{label}}`,{label:t})})}),a(Fe,{className:`space-y-3`,children:[d(`div`,{className:`rounded-md border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:r(`auth.tokenModals.copyThisTokenNowOnce`,`Copy this token now. Once you close this dialog the secret cannot be displayed again.`)}),d(`div`,{className:`select-all break-all rounded-md border border-border bg-background p-2 font-mono text-[11px] text-foreground`,children:e})]}),a(st,{children:[d(Oe,{value:e,label:r(`common.copy`,`Copy`),srLabel:`token`}),d(G,{type:`button`,variant:`primary`,size:`sm`,onClick:n,children:r(`auth.tokenModals.done`,`Done`)})]})]})})}var wn={token:`newToken`,scoped:`newScoped`,admin:`newAdmin`};e();var Tn=7,En=90,Dn=80;function On(e){let t=Number(e);return Number.isInteger(t)&&t>=1&&t<=En?t:null}function kn({open:e,users:n,onClose:i,onSubmitScoped:o,onSubmitAdmin:c,submitting:l,formError:u,awaitingProof:f}){let{t:p}=X(),m=j(),{user:h}=xt(),g=h?.isAdmin===!0,_=g?null:h?.scopes??[],[v,y]=r(!1),[b,x]=r(n[0]?.id??``),[S,w]=r(``),[T,E]=r([{type:`capability`,target:``,access:[`view`,`create`]}]),[D,O]=r(``),[k,A]=r(String(Tn));t(()=>{e||(y(!1),x(n[0]?.id??``),w(``),E([{type:`capability`,target:``,access:[`view`,`create`]}]),O(``),A(String(Tn)))},[e,n]);let N=S.trim(),P=Le(T,m),F=On(k),L=!v&&b!==``&&N.length>0&&T.length>0&&P===null&&!l,R=v&&g&&N.length>0&&N.length<=Dn&&F!==null&&!l&&!f,z=()=>{if(v){if(!R||F===null)return;c({name:N,expiresInDays:F});return}if(!L)return;let e=parseInt(D,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;o({userId:b,name:N,scopes:T,...t===void 0?{}:{expiresAt:t}})},ee=v,B=v?C:I;return d(Je,{open:e,onClose:i,title:v?p(`access.createTokenModal.createAdminToken`,`Create admin token`):p(`access.createTokenModal.createToken`,`Create token`),icon:v?C:de,error:u,width:`md`,testId:`create-token-dialog`,footer:a(G,{type:`button`,variant:ee?`danger`:`primary`,size:`sm`,onClick:z,disabled:v?!R:!L,children:[l||f?d(M,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}):d(B,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),v?p(`access.createTokenModal.createAdminToken`,`Create admin token`):p(`access.createTokenModal.issueToken`,`Issue token`)]}),children:a(`div`,{className:`space-y-3`,children:[g?a(`label`,{className:`flex items-start gap-2 text-sm text-foreground`,children:[d(`input`,{type:`checkbox`,className:`mt-0.5`,checked:v,onChange:e=>y(e.target.checked),"data-testid":`token-as-admin`}),a(`span`,{children:[d(`span`,{className:`font-medium`,children:p(`access.createTokenModal.administrator`,`Administrator`)}),d(`span`,{className:`block text-[11px] text-foreground-subtle`,children:p(`access.createTokenModal.offScopedToASurface`,`Off = scoped to a surface. On = full admin for scripts (audited, max 90 days).`)})]})]}):null,v?d(`div`,{className:`space-y-1 rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] leading-relaxed text-foreground`,"data-testid":`admin-token-warning`,children:d(`p`,{children:d(St,{i18nKey:`auth.adminTokenNoticeShort`,components:{strong:d(`strong`,{})}})})}):null,v?null:a(`div`,{className:`space-y-1`,children:[d(nt,{htmlFor:`token-user`,children:p(`access.createTokenModal.onBehalfOfUser`,`On behalf of user`)}),d($e,{id:`token-user`,value:b,onChange:e=>x(e.target.value),options:n.map(e=>({value:e.id,label:e.username}))})]}),d(pt,{label:p(`access.createTokenModal.name`,`Name`),required:!0,children:d(dt,{id:`token-name`,value:S,maxLength:Dn,onChange:e=>w(e.target.value),placeholder:v?`nightly-backup`:`cloudflare-tunnel-route`,autoFocus:!0})}),v?a(`div`,{className:`space-y-1`,children:[d(nt,{htmlFor:`token-admin-days`,children:p(`access.createTokenModal.expiresInDays`,`Expires in (days)`)}),d(dt,{id:`token-admin-days`,type:`number`,min:1,max:En,value:k,onChange:e=>A(e.target.value),state:F===null?`error`:`default`}),F===null?d(`p`,{className:`text-[11px] text-danger`,children:p(`auth.expiryInvalid`,{max:En})}):d(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`auth.expiryHint`,{max:En})})]}):a(s,{children:[a(`div`,{className:`space-y-1`,children:[d(nt,{children:p(`access.createTokenModal.scopes`,`Scopes`)}),d(je,{value:T,onChange:E,clampToParent:_}),P&&d(`p`,{className:`text-[10px] text-danger`,children:P}),d(`p`,{className:`text-[10px] text-foreground-subtle`,children:p(`access.createTokenModal.eachScopePicksACap`,`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`)})]}),a(`div`,{className:`space-y-1`,children:[d(nt,{htmlFor:`token-scoped-days`,children:p(`access.createTokenModal.expiresInDays`,`Expires in (days)`)}),d(dt,{id:`token-scoped-days`,type:`number`,min:1,value:D,onChange:e=>O(e.target.value),placeholder:`30`}),d(`p`,{className:`text-[10px] text-foreground-subtle`,children:p(`access.createTokenModal.leaveBlankForNonExpiring`,`Leave blank for non-expiring.`)})]})]})]})})}e();var An={key:`access.nouns.token`};function jn(e,t){return e.type===`device`?`device:[${me(e.selector,t)}]`:`${e.type}:${e.target??``}`}function Mn({createRequested:e=!1,onCreateConsumed:i}){let{t:o}=X(),s=j(),{user:l}=xt(),u=U(),f=c(),p=K.useUtils(),m=Ft(),{data:g,isLoading:_}=gt(),v=n(()=>g??[],[g]),y=K.useQueries(e=>v.map(t=>e.userManagement.listScopedTokens({userId:t.id}))),b=K.auth.listAdminTokens.useQuery(void 0,{enabled:l?.isAdmin===!0}),{requestProof:x,dialog:S}=Vt(`Creating an admin token`),{state:C,openNew:w,close:T}=ht({newKey:wn.token}),[E,D]=r(null),[O,k]=r(null),[A,M]=r(!1),[N,P]=r(null),[F,I]=r(null);t(()=>{e&&(w(),i?.())},[e,w,i]);let L=()=>{f.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),p.auth.listAdminTokens.invalidate(),p.auth.listAuthAudit.invalidate()},R=ot({onSuccess:({token:e,record:t})=>{L(),T(),k(null),P({token:e,label:t.name})},onError:e=>{D(`Create failed: ${e.message}`),k(`Create failed: ${e.message}`)}}),z=K.auth.createAdminToken.useMutation({onSuccess:({token:e,record:t})=>{L(),T(),k(null),M(!1),P({token:e,label:t.name})},onError:e=>{D(`Create failed: ${e.message}`),k(`Create failed: ${e.message}`),M(!1)}}),ee=Ke({onSuccess:()=>{I(null),L()},onError:e=>{I(null),D(`Revoke failed: ${e.message}`)}}),B=K.auth.revokeAdminToken.useMutation({onSuccess:()=>{I(null),L()},onError:e=>{I(null),D(`Revoke failed: ${e.message}`)}}),V=It(An,L),te=Date.now(),ne=v.flatMap((e,t)=>(y[t]?.data??[]).map(t=>Lt(t,e.id,m,t.scopes.map(e=>jn(e,s)).join(`, `),te))),re=l?.isAdmin===!0?(b.data??[]).map(e=>zt(e,m,te)):[],ie=[...ne,...re],ae=y.find(e=>e.isError)?.error?.message??(b.isError?b.error?.message??`Request failed`:null),oe=async e=>{let t=e.kind===cn;await u({title:o(`access.tokensSection.revoke`,`Revoke "{{name}}"?`,{name:e.name}),message:t?o(`access.tokensSection.everyScriptUsingItLoses`,`Every script using it loses access immediately. This cannot be undone.`):o(`access.tokensSection.sScopedTokenStopsWorking`,`{{ownerName}}'s scoped token stops working on its next use. This cannot be undone.`,{ownerName:e.ownerName}),confirmLabel:o(`access.tokensSection.revoke2`,`Revoke`),variant:`danger`})&&(D(null),I(e.id),t?B.mutate({id:e.id}):ee.mutate({id:e.id}))},se=R.isPending||z.isPending;return a(`div`,{"data-testid":`tokens`,children:[S,d(Z,{notice:Rt(E,V.outcome),onDismissNotice:()=>{D(null),V.dismiss()},id:`tokens`,title:o(`access.tokensSection.tokens`,`Tokens`),icon:de,description:o(`access.tokensSection.scopedTokensForANarrow`,`Scoped tokens for a narrow surface, and admin tokens for full-administrator scripts. Revoking one stops it on its next use.`),children:d(Xt,{rows:ie,label:o(`common.tokensLabel`),isLoading:_||y.some(e=>e.isLoading)||l?.isAdmin===!0&&b.isLoading,loadError:ae,emptyText:`No tokens.`,action:{label:o(`access.tokensSection.revoke2`,`Revoke`),icon:h,isAvailable:e=>e.status===`active`,onRun:e=>void oe(e),busyId:F,disabled:V.busy||F!==null},bulk:{revoke:V,noun:An,isSelectable:e=>e.status===`active`}})}),d(kn,{open:C.mode===`new`,users:v.map(e=>({id:e.id,username:e.username})),onClose:()=>{T(),k(null),M(!1)},submitting:se,formError:O,awaitingProof:A,onSubmitScoped:e=>R.mutate({userId:e.userId,name:e.name,scopes:e.scopes,expiresAt:e.expiresAt}),onSubmitAdmin:e=>{(async()=>{D(null),k(null),M(!0);let t=await x();M(!1),t!==null&&z.mutate({...e,reauthToken:t})})()}}),N&&d(Cn,{token:N.token,label:N.label,onClose:()=>P(null)})]})}var Nn={"share-link":`helpers.authAuditWording.bulkNoun.shareLink`,"admin-token":`helpers.authAuditWording.bulkNoun.adminToken`,"login-session":`helpers.authAuditWording.bulkNoun.loginSession`};function Q(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Pn(e,t){let n=Q(e,`tokenId`);return Q(e,`name`)??(n===null?void 0:t.get(n))??n??`?`}function Fn(e){return e.filter(e=>e!==null)}function In(e){let t=Q(e,`prefix`);return t===null?null:Y.t(`helpers.authAuditWording.prefix`,{prefix:t})}function Ln(e,t){let n=e.detail??{};switch(e.action){case`admin-token-created`:{let e=n.expiresAt;return{title:Y.t(`helpers.authAuditWording.tokenCreated`,{name:Pn(n,t)}),details:Fn([In(n),typeof e==`number`?Y.t(`helpers.authAuditWording.expires`,{at:Ut(e)}):null])}}case`admin-token-used`:{let e=Q(n,`path`);return{title:Y.t(`helpers.authAuditWording.tokenUsed`,{name:Pn(n,t)}),details:Fn([In(n),e===null?null:Y.t(`helpers.authAuditWording.call`,{path:e})])}}case`admin-token-revoked`:return{title:Y.t(`helpers.authAuditWording.tokenRevoked`,{name:Pn(n,t)}),details:Fn([In(n)])};case`credentials-revoked`:{let e=Q(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=Nn[e],a=i===void 0?`${e}s`:Y.t(i);return{title:Y.t(`helpers.authAuditWording.bulkRevoked`,{n:typeof t==`number`?String(t):`?`,noun:a}),details:Fn([typeof r==`number`&&r>0?Y.t(`helpers.authAuditWording.skipped`,{count:r}):null,Q(n,`ids`)===null?null:Y.t(`helpers.authAuditWording.ids`,{ids:Q(n,`ids`)??``})])}}case`second-factor-skipped`:{let e=Q(n,`method`),t=Q(n,`factors`);return{title:Y.t(`helpers.authAuditWording.secondFactorSkipped`),details:Fn([e===null?null:Y.t(`helpers.authAuditWording.signedInWith`,{method:ln(e)}),t===null?null:Y.t(`helpers.authAuditWording.skippedFactors`,{factors:t.split(`,`).join(`, `)})])}}default:return{title:e.action,details:Object.entries(n).map(([e,t])=>`${e}: ${String(t)}`)}}}e();var Rn=100;function zn(){let{user:e}=xt();return e?.isAdmin?d(Vn,{}):null}function Bn(){let{data:e}=gt(),{data:t}=K.auth.listAdminTokens.useQuery();return n(()=>{let n=new Map;for(let t of e??[])n.set(t.id,t.username);let r=new Map;for(let e of t??[])r.set(e.id,e.name);return{userNameById:n,tokenNameById:r}},[e,t])}function Vn(){let{t:e}=X(),t=K.auth.listAuthAudit.useQuery({limit:Rn}),{userNameById:n,tokenNameById:r}=Bn(),i=t.data??[];return a(`div`,{"data-testid":`auth-audit`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[a(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[d(P,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`auth.authAuditSection.authenticationAudit`,`Authentication audit`)}),d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:e(`auth.authAuditSection.latest`,{count:Rn})})]}),d(`div`,{className:`p-4`,children:t.isLoading?a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(M,{className:`h-3.5 w-3.5 animate-spin`}),e(`auth.authAuditSection.loadingAuditTrail`,`Loading audit trail…`)]}):t.isError?a(`div`,{className:`text-[11px] text-danger`,children:[e(`auth.authAuditSection.couldNotLoadTheAudit`,`Could not load the audit trail:`),` `,t.error?.message??e(`auth.authAuditSection.requestFailed`,`Request failed`)]}):i.length===0?a(`div`,{className:`rounded border border-dashed border-border px-3 py-4 text-xs text-foreground-subtle text-center space-y-1`,children:[d(`div`,{children:e(`auth.authAuditSection.noAuthenticationEventsRecordedYet`,`No authentication events recorded yet.`)}),d(`div`,{className:`text-[11px] text-foreground-subtle/90`,children:e(`auth.authAuditSection.thisTrailRecordsAdminToken`,`This trail records admin-token create/use/revoke, trusted-network 2FA skips, and credential revokes (including single share-link revoke). Browser password logins are not listed here.`)})]}):d(`ul`,{className:`divide-y divide-border rounded-md border border-border max-h-[420px] overflow-y-auto`,children:i.map(e=>d(Hn,{record:e,userName:e.userId===void 0?null:n.get(e.userId)??e.userId,tokenNameById:r},e.id))})})]})}function Hn({record:e,userName:t,tokenNameById:n}){let r=Ln(e,n);return a(`li`,{"data-testid":`auth-audit-row`,className:`px-3 py-2 text-xs space-y-0.5`,children:[a(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[d(`span`,{className:`font-medium text-foreground`,children:r.title}),d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ut(e.at)})]}),a(`div`,{className:`flex flex-wrap gap-x-3 text-[11px] text-foreground-subtle`,children:[t!==null&&d(`span`,{className:`text-foreground`,children:t}),e.ip!==void 0&&d(`span`,{className:`font-mono`,children:e.ip}),r.details.map(e=>d(`span`,{className:`font-mono`,children:e},e))]})]})}e();var $={loginSessions:`login-sessions`,linkedApps:`linked-apps`,tokens:`tokens`,scopedTokens:`scoped-tokens`,adminTokens:`admin-tokens`,shareLinks:`share-links`,legacyApiKeys:`legacy-api-keys`,externalIdentities:`external-identities`,audit:`auth-audit`},Un={[$.scopedTokens]:$.tokens,[$.adminTokens]:$.tokens};function Wn(e){return[{id:$.loginSessions,label:Y.t(`system.access.loginSessions`,`Login sessions`),icon:fe,render:()=>d(Sn,{})},{id:$.linkedApps,label:Y.t(`system.access.linkedApps`,`Linked apps`),icon:O,render:()=>d(bn,{})},{id:$.tokens,label:Y.t(`system.access.tokens`,`Tokens`),icon:de,render:({createRequested:e,onCreateConsumed:t})=>d(Mn,{headerOwnsCreate:!0,createRequested:e,onCreateConsumed:t})},{id:$.shareLinks,label:Y.t(`system.access.shareLinks`,`Share links`),icon:D,render:()=>d(qt,{})},...e?[{id:$.legacyApiKeys,label:Y.t(`system.access.legacyApiKeys`,`Legacy API keys`),icon:ue,render:()=>d(_n,{})}]:[],{id:$.externalIdentities,label:Y.t(`system.access.signInLinks`,`Sign-in links`),icon:H,render:()=>d(gn,{})},{id:$.audit,label:Y.t(`system.access.audit`,`Audit`),icon:P,render:()=>d(zn,{})}]}function Gn({createRequested:e=!1,onCreateConsumed:t}){let{t:r}=X(),i=we(),o=(i.data??[]).length>0,s=n(()=>Wn(o),[o]),c=un({ids:n(()=>s.map(e=>e.id),[s]),answered:!i.isLoading}),l=Tt(),[u]=Ot(),f=u.get(`integration`),p=f===null?void 0:Un[f];if(p!==void 0){let e=new URLSearchParams(u);return e.set(`integration`,p),d(vt,{to:`?${e.toString()}`,replace:!0})}let m=s.find(e=>e.id===c.selectedId)??s[0],h=m?.id??$.loginSessions;return i.isLoading?d(`div`,{className:`text-sm text-foreground-subtle`,"data-testid":`access-page`,children:r(`common.loading`,`Loading…`)}):a(`div`,{className:`flex flex-col gap-3`,"data-testid":`access-page`,children:[d(ut,{appearance:`pills`,value:h,onValueChange:e=>{l(`?${wt(u,e,null,null).toString()}`)},children:d(at,{"aria-label":r(`system.access.credentialKinds`,`Credential kinds`),children:s.map(e=>a(tt,{value:e.id,"data-testid":`access-kind-${e.id}`,children:[d(e.icon,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),e.label]},e.id))})}),m===void 0?null:d(`div`,{role:`region`,"aria-label":m.label,"data-testid":`access-kind-body`,children:m.render({createRequested:e&&m.id===$.tokens,onCreateConsumed:t??(()=>void 0)})},m.id)]})}function Kn(e,t){if(e===$.tokens)return a(G,{size:`sm`,type:`button`,"data-testid":`access-new-token`,onClick:t,children:[d(de,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),Y.t(`system.access.newToken`,`New token`)]})}function qn(){let[e,t]=r(!1);return{createRequested:e,requestCreate:()=>t(!0),clearCreate:()=>t(!1)}}e();var Jn=[`oidcConnections`,`listConnections`],Yn=[`oidcConnections`,`connectionFormSchema`],Xn={displayName:`OpenID Connect`,icon:`shield-check`,issuerUrl:``,clientId:``,clientSecret:``,redirectUri:``,scopes:`openid profile email`,usernameClaim:`preferred_username`},Zn=/^[a-z0-9][a-z0-9-]{0,63}$/;function Qn(e){return e instanceof Error?e.message:String(e)}function $n(e,t){if(t)return typeof e==`string`&&e.length>0?e:void 0;if(z(e))return ee;if(typeof e==`string`&&e.length>0)return e;re(e)}function er(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function tr({addonId:e}){let{t:f}=X(),p=N(),m=c(),g=U(),_=ht({editKey:`oidcEdit`,newKey:`oidcNew`}),[v,y]=r(!1),[b,x]=r(null),[S,C]=r(``),[w,T]=r({...Xn}),D=l(null),O=o({queryKey:[...Jn,e],queryFn:async()=>p.trpcClient.oidcConnections.listConnections.query({})}),k=o({queryKey:Yn,queryFn:async()=>p.trpcClient.oidcConnections.connectionFormSchema.query({})}),A=O.data??[],j=er(k.data)?k.data:void 0,M=_.state,P=M.mode===`edit`?A.find(e=>e.id===M.id)??null:null;t(()=>{if(_.state.mode===`edit`&&P!==null){let e=`edit:${P.id}`;if(D.current===e)return;D.current=e,x(null),C(P.id),T(P.formValues===void 0?{...Xn}:{...P.formValues});return}if(_.state.mode===`new`){if(D.current===`new`)return;D.current=`new`,x(null),C(``),T({...Xn})}},[P,_.state]);let F=i(async()=>{await m.invalidateQueries({queryKey:Jn})},[m]),L=u({mutationFn:async e=>p.trpcClient.oidcConnections.deleteConnection.mutate({id:e}),onSuccess:async()=>F()}),R=i(async e=>{await g({title:f(`system.oidcSettingsConnections.deleteOidcConnection`,`Delete OIDC connection?`),message:f(`system.oidcSettingsConnections.removeTheLoginButtonAnd`,`Remove “{{displayName}}” ({{id}}). The login button and IdP credentials for this id are dropped.`,{displayName:e.displayName,id:e.id}),confirmLabel:f(`common.delete`,`Delete`),cancelLabel:f(`common.cancel`,`Cancel`),variant:`danger`})&&(await L.mutateAsync(e.id),_.state.mode===`edit`&&_.state.id===e.id&&(_.close(),D.current=null))},[g,L,_,f]),z=i(async()=>{let e=w.displayName,t=typeof e==`string`&&e.trim()!==``?e.trim():``;if(t===``){x(`Display name is required.`);return}let n=_.state.mode===`new`,r=n?S.trim():P?.id??``;if(n&&!Zn.test(r)){x(`Instance id must be a lowercase slug (e.g. authentik, google).`);return}if(r===``){x(`That connection is no longer available.`);return}let i=$n(w.clientSecret,n),a=w.icon,o=w.issuerUrl,s=w.clientId,c=w.redirectUri,l=w.scopes,u=w.usernameClaim,d=u===`email`||u===`sub`?u:`preferred_username`;y(!0),x(null);try{n&&await p.trpcClient.oidcConnections.createConnection.mutate({id:r,displayName:t}),await p.trpcClient.oidcConnections.updateConnection.mutate({id:r,displayName:t,icon:typeof a==`string`?a:`shield-check`,issuerUrl:typeof o==`string`?o:``,clientId:typeof s==`string`?s:``,...i===void 0?{}:{clientSecret:i},redirectUri:typeof c==`string`?c:``,scopes:typeof l==`string`?l:`openid profile email`,usernameClaim:d}),await F(),_.close(),D.current=null}catch(e){x(Qn(e))}finally{y(!1)}},[S,P?.id,_,w,F,p]),ee=n(()=>[{key:`id`,header:f(`system.oidcSettingsConnections.id`,`Id`),sortValue:e=>e.id,render:e=>d(`span`,{className:`font-mono text-xs text-foreground`,children:e.id})},{key:`name`,header:f(`system.oidcSettingsConnections.name`,`Name`),sortValue:e=>e.displayName,render:e=>d(`span`,{className:`truncate font-medium text-foreground`,children:e.displayName})},{key:`issuer`,header:f(`system.oidcSettingsConnections.issuer`,`Issuer`),sortValue:e=>e.issuerUrl,render:e=>d(`span`,{className:`truncate text-xs text-foreground-muted`,children:e.issuerUrl===``?`—`:e.issuerUrl})},{key:`status`,header:f(`system.oidcSettingsConnections.status`,`Status`),notSortableReason:`Badge`,render:e=>d(J,{variant:e.configured?`success`:`warning`,children:e.configured?f(`system.oidcSettingsConnections.configured`,`Configured`):f(`system.oidcSettingsConnections.notConfigured`,`Not configured`)})},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,nowrap:!0,render:e=>a(`div`,{className:`flex justify-end gap-1`,children:[d(G,{type:`button`,size:`sm`,variant:`secondary`,onClick:t=>{t.stopPropagation(),_.openEdit(e.id)},children:f(`common.edit`,`Edit`)}),d(G,{type:`button`,size:`sm`,variant:`ghost`,"aria-label":f(`system.oidcSettingsConnections.delete`,`Delete {{displayName}}`,{displayName:e.displayName}),title:f(`common.delete`,`Delete`),onClick:t=>{t.stopPropagation(),R(e)},children:d(h,{className:`h-3.5 w-3.5 text-danger`})})]})}],[_,R,f]),B=_.state.mode===`new`,V=B||P!==null,te=B?`new`:P===null?`closed`:`edit:${P.id}:${P.configured?`cfg`:`empty`}`;return a(`div`,{className:`flex min-h-0 flex-col gap-3`,"data-testid":`oidc-settings-connections`,children:[a(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[a(`p`,{className:`text-sm text-foreground-muted`,children:[f(`system.oidcSettingsConnections.eachRowIsOneIdp`,`Each row is one IdP. Redirect URI:`),` `,d(`span`,{className:`font-mono text-xs`,children:`/addon/${e}/<id>/callback`})]}),a(G,{type:`button`,size:`sm`,"data-testid":`oidc-connections-add`,onClick:()=>_.openNew(),children:[d(E,{className:`h-3.5 w-3.5`}),f(`system.oidcSettingsConnections.addConnection`,`Add connection`)]})]}),O.isError?d(`p`,{className:`text-sm text-danger`,children:f(`system.oidcSettingsConnections.couldNotLoadConnections`,`Could not load connections.`)}):null,O.isPending?d(Xe,{className:`h-32 w-full`}):d(xe,{columns:ee,rows:A,rowKey:e=>e.id,pageSize:25,emptyMessage:f(`system.oidcSettingsConnections.noOidcConnectionsYetAdd`,`No OIDC connections yet. Add one to register an IdP.`),onRowClick:e=>_.openEdit(e.id),defaultSort:{columnKey:`name`,dir:`asc`}}),d(Je,{open:V,onClose:()=>{_.close(),x(null),D.current=null},title:B?f(`system.oidcSettingsConnections.addOidcConnection`,`Add OIDC connection`):f(`system.oidcSettingsConnections.edit`,`Edit {{value1}}`,{value1:P?.displayName??`connection`}),icon:I,width:`xl`,testId:`oidc-connection-editor`,error:b,footer:d(G,{type:`button`,size:`sm`,disabled:v||B&&S.trim()===``,onClick:()=>void z(),children:v?f(`system.oidcSettingsConnections.saving`,`Saving…`):f(`common.save`,`Save`)}),children:V?a(s,{children:[B?a(`div`,{children:[d(nt,{htmlFor:`oidc-connection-id`,children:f(`system.oidcSettingsConnections.instanceId`,`Instance id`)}),d(dt,{id:`oidc-connection-id`,value:S,onChange:e=>C(e.target.value),placeholder:`authentik`,autoComplete:`off`}),d(`p`,{className:`mt-1 text-xs text-foreground-muted`,children:f(`system.oidcSettingsConnections.urlSlugAppearsInAddon`,`URL slug — appears in /addon/{{addonId}}/<id>/callback. Stable; renaming is not supported after save.`,{addonId:e})})]}):a(`p`,{className:`text-sm text-foreground-muted`,children:[f(`system.oidcSettingsConnections.instanceId2`,`Instance id:`),` `,d(`span`,{className:`font-mono`,children:P?.id})]}),j===void 0?d(`p`,{className:`text-sm text-foreground-muted`,children:f(`system.oidcSettingsConnections.loadingForm`,`Loading form…`)}):d(We,{schema:j,values:w,onChange:T,bare:!0},te)]}):null})]})}e();var nr=3e4,rr=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],ir={titleKey:`system.authentication.sectionTitle`,subtitleKey:`system.authentication.sectionSubtitle`,emptyTitleKey:`system.authentication.sectionEmptyTitle`,emptyDescriptionKey:`system.authentication.sectionEmptyDescription`,installLabelKey:`system.authentication.sectionInstall`};function ar(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:ae,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).`,`Scoped tokens, admin tokens and sessions are managed from Identity → Tokens & sessions.`],setupSteps:[`A fresh hub has one account, admin / changeme — the first sign-in asks for a new password. Add users from Users → New user.`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:ce,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`Explicit linking only: an IdP account signs in only the CamStack user who linked it from their profile (My access → Linked sign-in accounts). No auto-created users, no email matching.`,`The linked user’s role, scopes and two-factor authentication apply.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Choose a stable instance id (slug). Set the IdP redirect URI to `https://<this-hub>/addon/auth-oidc/<id>/callback`.",`In Settings below, Add connection — enter the id, issuer, and credentials; Save.`,`Each user then links their IdP account from My access → Linked sign-in accounts.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:ce,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:f,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`)?{headline:`TOTP — second factor.`,icon:f,bullets:[`Time-based codes from an authenticator app (RFC 6238).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:I,bullets:[`Generic authentication provider. No additional hints registered.`]}}function or(){let{t:e}=X(),t=lt({capName:rr[0].capName},{refetchInterval:nr}),r=lt({capName:rr[1].capName},{refetchInterval:nr}),i=Ie(void 0,{refetchInterval:nr}),a=n(()=>hn(i.data??[]),[i.data]),o=n(()=>{let e=[],n=[t.data??[],r.data??[]];for(let[t,r]of rr.entries())for(let i of n[t]??[])e.push({addonId:i.addonId,displayName:a.get(i.addonId)??i.addonId,isActive:i.isActive,capName:r.capName,stageBadge:r.stageBadge});return e},[t.data,r.data,a]),s=[{id:`authentication`,label:e(`system.authentication.authenticationProviders`,`Authentication providers`),install:{capability:rr[0].capName,label:e(ir.installLabelKey)},entries:o.map(t=>({id:t.addonId,name:t.displayName,fallbackIcon:I,...mn(t.isActive),render:()=>d(dn,{addonId:t.addonId,displayName:t.displayName,capName:t.capName,isActive:t.isActive,badges:t.stageBadge===null?null:d(J,{variant:`info`,className:fn,children:t.stageBadge}),settingsContent:t.addonId.startsWith(`auth-oidc`)?d(tr,{addonId:t.addonId}):void 0,panels:[{id:`about`,title:e(`system.authentication.about`,`About`),icon:ar(t.addonId).icon,content:d(sr,{addonId:t.addonId})}]})}))}];return d(pn,{embedded:!0,icon:I,title:e(ir.titleKey),subtitle:e(ir.subtitleKey),groups:s,isLoading:t.isLoading||r.isLoading,emptyTitle:e(ir.emptyTitleKey),emptyDescription:e(ir.emptyDescriptionKey)})}function sr({addonId:e}){let{t}=X(),n=ar(e),r=n.icon;return a(`div`,{className:`space-y-3 rounded-lg border border-border bg-surface p-2 sm:p-4`,children:[a(`div`,{className:`flex items-start gap-2.5`,children:[d(r,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),d(`div`,{className:`text-xs text-foreground font-medium`,children:n.headline})]}),d(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:n.bullets.map((e,t)=>d(`li`,{children:e},t))}),n.setupSteps&&n.setupSteps.length>0&&a(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[a(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[d(ie,{className:`h-3 w-3`}),t(`system.authentication.setupSteps`,`Setup steps`)]}),d(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:n.setupSteps.map((e,t)=>d(`li`,{children:e},t))})]}),e===`local-auth`&&a(`div`,{className:`rounded-md border border-info/30 bg-info/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[d(A,{className:`h-3.5 w-3.5 mt-0.5 text-info shrink-0`}),d(`span`,{children:d(St,{i18nKey:`system.authentication.totpNote`,components:{access:d(yt,{to:`/system/my-access`,className:`underline text-primary`}),users:d(yt,{to:`/system/identity?tab=users`,className:`underline text-primary`})}})})]})]})}function cr({isPending:e,error:t,what:n,onRetry:r,children:i}){let{t:o}=X();return e?a(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,role:`status`,"data-testid":`query-pending`,children:[d(M,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),o(`certificates.queryBody.reading`,{what:n})]}):t===null?i:d(_t,{title:o(`certificates.queryBody.couldNotRead`,`Could not read {{what}}`,{what:n}),message:t.message.length>0?t.message:o(`certificates.queryBody.requestFailed`,`Request failed`),onRetry:r})}function lr(){let{t:e}=X(),t=K.deviceCredentials.getDeviceCaStatus.useQuery({}),n=t.data;return d(Z,{id:`device-ca`,title:e(`certificates.deviceCaCard.deviceCertificateAuthority`,`Device certificate authority`),icon:I,description:e(`certificates.deviceCaCard.signsTheCertificateEachPaired`,`Signs the certificate each paired device holds. It is created the first time a device is paired.`),children:d(cr,{isPending:t.isPending,error:t.error,what:`the device CA`,onRetry:()=>void t.refetch(),children:n!==void 0&&a(`div`,{className:`space-y-1`,"data-testid":`device-ca-status`,children:[a(q,{label:e(`certificates.deviceCaCard.state`,`State`),children:[n.state===`ready`&&d(J,{variant:`success`,children:e(`certificates.deviceCaCard.ready`,`Ready`)}),n.state===`absent`&&d(J,{variant:`default`,children:e(`certificates.deviceCaCard.notCreatedYet`,`Not created yet`)}),n.state===`unavailable`&&d(J,{variant:`danger`,children:e(`certificates.deviceCaCard.unavailable`,`Unavailable`)})]}),n.state===`ready`&&a(s,{children:[d(q,{label:e(`certificates.deviceCaCard.subject`,`Subject`),valueClassName:`font-mono`,children:n.subject}),d(q,{label:e(`certificates.deviceCaCard.fingerprintSha256`,`Fingerprint (SHA-256)`),valueClassName:`font-mono`,children:n.fingerprintSha256}),d(q,{label:e(`certificates.deviceCaCard.validUntil`,`Valid until`),children:n.validTo})]}),n.state===`unavailable`&&d(q,{label:e(`certificates.deviceCaCard.reason`,`Reason`),children:d(`span`,{className:`text-danger`,children:n.reason})})]})})})}e();function ur(){let{t:e}=X(),t=K.useUtils(),n=K.deviceCredentials.getDeviceCertificateSettings.useQuery({}),[i,o]=r(null),s=K.deviceCredentials.setDeviceCertificateSettings.useMutation({onSuccess:()=>{o(null),t.deviceCredentials.getDeviceCertificateSettings.invalidate()},onError:e=>o(`Could not save: ${e.message}`)});return d(cr,{isPending:n.isPending,error:n.error,what:`the enrollment setting`,onRetry:()=>void n.refetch(),children:n.data!==void 0&&a(q,{label:e(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),actions:d(ft,{checked:n.data.selfEnrollment===`allowed`,disabled:s.isPending,"aria-label":e(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),onCheckedChange:e=>s.mutate({selfEnrollment:e?`allowed`:`disabled`})}),children:[d(`span`,{className:`text-[11px] text-foreground-subtle`,children:n.data.selfEnrollment===`allowed`?e(`certificates.deviceSettingsRow.allowedAUserSignedIn`,`Allowed - a user signed in on a phone can keep it signed in. Pairing by QR works either way.`):e(`certificates.deviceSettingsRow.disabledOnlyAnAdminCan`,`Disabled - only an admin can pair a device, with a QR code.`)}),i!==null&&d(`span`,{className:`block text-[11px] text-danger`,children:i})]})})}e();function dr(e){let[n,i]=r(()=>Date.now());return t(()=>{let t=setInterval(()=>i(Date.now()),e);return()=>clearInterval(t)},[e]),n}e();var fr=80,pr=208;function mr({open:e,users:t,onClose:n,onPaired:i}){let{t:o}=X(),s=K.deviceCredentials.startEnrollment.useMutation({onSuccess:i}),[c,l]=r(``),[u,p]=r(``),m=c===``?t[0]?.id??``:c,h=s.data,g=()=>{s.reset(),p(``),n()};return d(Je,{open:e,onClose:g,title:o(`certificates.pairDeviceDialog.pairADevice`,`Pair a device`),icon:f,width:`md`,testId:`pair-device-dialog`,error:s.isError?s.error.message:null,footer:h===void 0?a(G,{type:`button`,onClick:()=>{let e=u.trim();m===``||e===``||s.mutate({userId:m,deviceName:e})},disabled:s.isPending||m===``||u.trim()===``,children:[s.isPending&&d(M,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),o(`certificates.pairDeviceDialog.createPairingCode`,`Create pairing code`)]}):d(G,{type:`button`,variant:`outline`,onClick:g,children:o(`certificates.pairDeviceDialog.done`,`Done`)}),children:h===void 0?a(`div`,{className:`space-y-3`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`certificates.pairDeviceDialog.createsAOneTimeCode`,`Creates a one-time code for a phone you hold. Scan it with the CamStack app on that phone; the phone then stays signed in as the chosen user until you revoke it.`)}),d(pt,{label:o(`certificates.pairDeviceDialog.user`,`User`),required:!0,children:d($e,{value:m,onChange:e=>l(e.target.value),options:t.map(e=>({value:e.id,label:e.username}))})}),d(pt,{label:o(`certificates.pairDeviceDialog.deviceName`,`Device name`),required:!0,description:o(`certificates.pairDeviceDialog.howThisPhoneIsListed`,`How this phone is listed, e.g. Anna's iPhone.`),children:d(dt,{value:u,maxLength:fr,onChange:e=>p(e.target.value),placeholder:o(`certificates.pairDeviceDialog.annaSIphone`,`Anna's iPhone`),autoFocus:!0})})]}):d(hr,{enrollUrl:h.enrollUrl,expiresAt:h.expiresAt,hubKnown:h.hubOrigin!==null,onRestart:()=>s.reset()})})}function hr({enrollUrl:e,expiresAt:t,hubKnown:n,onRestart:r}){let{t:i}=X(),o=en(t,dr(1e3));return d(`div`,{className:`space-y-3`,"data-testid":`pair-issued`,children:a(`div`,{className:`flex flex-col items-center gap-3 sm:flex-row sm:items-start`,children:[d(`div`,{className:o.expired?`opacity-30`:void 0,children:d(Ge,{value:e,size:pr,alt:i(`certificates.pairDeviceDialog.enrollmentQrCode`,`Enrollment QR code`)})}),a(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:i(`certificates.pairDeviceDialog.openTheCamstackAppOn`,`Open the CamStack app on the phone and scan this code. It works once.`)}),d(`div`,{className:`text-sm font-semibold tabular-nums text-foreground`,role:`timer`,"data-testid":`pair-countdown`,children:o.expired?i(`certificates.pairDeviceDialog.expiredCreateANewCode`,`Expired - create a new code`):i(`certificates.pairDeviceDialog.expiresIn`,`Expires in {{label}}`,{label:o.label})}),a(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[d(`code`,{className:`min-w-0 flex-1 select-all break-all font-mono text-[11px] text-foreground`,children:e}),d(Oe,{value:e,srLabel:`Enrollment link`})]}),!n&&a(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[d(g,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),d(`span`,{children:i(`certificates.pairDeviceDialog.theHubCouldNotName`,`The hub could not name an address for this link, so the app must already know it.`)})]}),o.expired&&d(G,{type:`button`,variant:`outline`,size:`sm`,onClick:r,children:i(`certificates.pairDeviceDialog.newCode`,`New code`)})]})]})})}e();var gr={key:`access.nouns.device`};function _r({pairOpen:e,onPairClose:t}){let{t:i}=X(),o=U(),s=rt(),c=K.useUtils(),l=K.deviceCredentials.listDeviceCredentials.useQuery({includeRevoked:!0}),u=gt(),[p,g]=r(null),[_,v]=r(null),b=()=>void c.deviceCredentials.listDeviceCredentials.invalidate(),x=e=>t=>{v(null),g(`${e} failed: ${t.message}`)},S=()=>{v(null),b()},C=K.deviceCredentials.revokeDeviceCredential.useMutation({onSuccess:S,onError:x(`Revoke`)}),w=K.deviceCredentials.deleteDeviceCredential.useMutation({onSuccess:e=>{e.result!==`deleted`&&g(e.result===`live`?`Only a revoked device can be deleted: revoke it first.`:`That device no longer exists.`),S()},onError:x(`Delete`)}),T=K.deviceCredentials.renameDeviceCredential.useMutation({onSuccess:S,onError:x(`Rename`)}),E=Yt(gr,e=>C.mutateAsync({id:e}),b),D=E.busy||_!==null,O=n(()=>(l.data??[]).map($t),[l.data]),k=async e=>{await o({title:i(`certificates.devicesCard.revoke`,`Revoke "{{name}}"?`,{name:e.name}),message:i(`certificates.devicesCard.sDeviceStopsSigningIn`,`{{ownerName}}'s device stops signing in at once and its open sessions end. To use it again it has to be paired anew. This cannot be undone.`,{ownerName:e.ownerName}),confirmLabel:i(`certificates.devicesCard.revoke2`,`Revoke`),variant:`danger`})&&(g(null),v(e.id),C.mutate({id:e.id}))},A=async e=>{await o({title:i(`certificates.devicesCard.delete`,`Delete "{{name}}"?`,{name:e.name}),message:i(`certificates.devicesCard.isRemovedFromTheList`,`{{name}} is removed from the list. The audit trail keeps the revocation.`,{name:e.name}),confirmLabel:i(`common.delete`,`Delete`),variant:`danger`})&&(g(null),v(e.id),w.mutate({id:e.id}))},j=async e=>{let t=(await s({title:i(`certificates.devicesCard.renameDevice`,`Rename device`),label:i(`certificates.devicesCard.deviceName`,`Device name`),defaultValue:e.name,confirmLabel:i(`certificates.devicesCard.rename`,`Rename`)}))?.trim()??``;t===``||t===e.name||(g(null),v(e.id),T.mutate({id:e.id,deviceName:t}))},M={label:i(`certificates.devicesCard.revoke2`,`Revoke`),icon:y,isAvailable:Ht,onRun:e=>void k(e),busyId:C.isPending?_:null,disabled:D},N=[{label:i(`certificates.devicesCard.rename`,`Rename`),icon:m,tone:`neutral`,isAvailable:()=>!0,onRun:e=>void j(e),busyId:T.isPending?_:null,disabled:D},{label:i(`common.delete`,`Delete`),icon:h,isAvailable:Jt,onRun:e=>void A(e),busyId:w.isPending?_:null,disabled:D}];return a(Z,{id:`devices`,title:i(`certificates.devicesCard.devices`,`Devices`),icon:f,description:i(`certificates.devicesCard.phonesThatStaySignedIn`,`Phones that stay signed in with a certificate instead of a login. Revoking one signs it out at once; it has to be paired again.`),notice:Rt(p,E.outcome),onDismissNotice:()=>{g(null),E.dismiss()},children:[d(ur,{}),d(Xt,{rows:O,label:i(`certificates.devicesCard.label`),isLoading:l.isPending,loadError:l.error===null?null:l.error.message||`Request failed`,emptyText:`No devices paired yet.`,expiresNone:`—`,action:M,extraActions:N,bulk:{revoke:E,noun:gr,isSelectable:Ht}}),d(mr,{open:e,users:u.data??[],onClose:t,onPaired:b})]})}var vr=/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/,yr=/-----BEGIN ((?:RSA |EC |ENCRYPTED )?PRIVATE KEY)-----[\s\S]+?-----END \1-----/,br={certificate:`.pem,.crt,.cer`,privateKey:`.pem,.key`,ca:`.pem,.crt,.cer`};function xr(e,t){if(t.trim()===``)return null;if(e===`privateKey`){let e=yr.exec(t);return e===null?vr.test(t)?Y.t(`helpers.pemFile.isCert`):Y.t(`helpers.pemFile.notKey`):e[1]===`ENCRYPTED PRIVATE KEY`?Y.t(`helpers.pemFile.encrypted`):null}return vr.test(t)?e===`certificate`&&yr.test(t)?Y.t(`helpers.pemFile.certHasKey`):null:yr.test(t)?Y.t(`helpers.pemFile.isKey`):Y.t(`helpers.pemFile.notCert`)}function Sr(e){return e.text()}e();function Cr({kind:e,label:t,value:n,onChange:i,rows:o=6}){let{t:s}=X(),c=l(null),[u,f]=r(null),[p,m]=r(null),h=p??xr(e,n),g=`pem-${e}`,_=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t!==void 0){f(t.name);try{let e=await Sr(t);m(null),i(e)}catch(e){m(`Could not read ${t.name}: ${e instanceof Error?e.message:String(e)}`)}}};return a(`div`,{className:`space-y-1`,children:[a(`div`,{className:`flex items-center justify-between gap-2`,children:[d(`label`,{htmlFor:g,className:`text-[11px] text-foreground-subtle`,children:t}),a(`div`,{className:`flex min-w-0 items-center gap-2`,children:[u!==null&&d(`span`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,"data-testid":`${g}-file-name`,children:u}),d(`input`,{ref:c,type:`file`,accept:br[e],onChange:e=>void _(e),className:`hidden`,"data-testid":`${g}-file`}),a(G,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>c.current?.click(),children:[d(oe,{className:`mr-1 h-3 w-3`}),s(`system.pemField.chooseFile`,`Choose file`)]})]})]}),d(`textarea`,{id:g,value:n,onChange:e=>{f(null),m(null),i(e.target.value)},rows:o,"aria-invalid":h!==null,className:`w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`}),h!==null&&d(`p`,{className:`text-[11px] text-danger`,role:`alert`,children:h})]})}e();var wr=30;function Tr(e){let t=Date.parse(e);return!Number.isNaN(t)&&Date.now()-t<wr*864e5}function Er(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function Dr(){let{t:e}=X(),t=c(),n=Pe(void 0,{refetchInterval:15e3}),i=ye({onSuccess:()=>void t.invalidateQueries({queryKey:[[`localNetwork`]]})}),o=He({onSuccess:()=>void t.invalidateQueries({queryKey:[[`localNetwork`]]})}),s=Ce({onSuccess:()=>void t.invalidateQueries({queryKey:[[`localNetwork`]]})}),l=Ze({onSuccess:()=>{m(!1),g(``),v(``),b(``),t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),u=n.data,[f,m]=r(!1),[h,g]=r(``),[_,v]=r(``),[y,b]=r(``),S=()=>{if(!u?.caCertPem)return;let e=new Blob([u.caCertPem],{type:`application/x-pem-file`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`camstack-ca.crt`,n.click(),URL.revokeObjectURL(t)},C=u?.mode===`uploaded`?`Uploaded`:u?.mode===`generated`?`Generated local CA`:`TLS disabled`;return d(qe,{headingId:`local-access-certificate`,title:e(`system.localAccess.certificate`,`Certificate`),icon:x,children:a(`div`,{className:`${p} space-y-3`,children:[n.isError&&d(`p`,{className:`text-xs text-danger`,children:e(`system.localAccess.couldNotReadTlsStatus`,`Could not read TLS status.`)}),u?.reissueError&&d(_t,{variant:`warning`,title:e(`system.localAccess.certificateReissue`,`Certificate reissue`),message:u.reissueError}),u?.restartRequired&&d(_t,{variant:`warning`,title:e(`system.localAccess.restartRequired`,`Restart required`),message:e(`system.localAccess.theHttpsListenerStillServes`,`The HTTPS listener still serves the previous certificate. Restart the hub to apply it.`)}),u?.caMissing===!0&&d(_t,{variant:`warning`,title:e(`system.localAccess.caMissingTitle`,`CA missing - devices cannot trust this hub`),message:e(`system.localAccess.caMissingBody`,"The uploaded certificate was not issued by a public CA and no CA was stored with it, so Download CA has nothing to hand out. Upload the certificate again together with its CA (for mkcert, the rootCA.pem in the folder `mkcert -CAROOT` prints).")}),u?.caReplacedAt!=null&&Tr(u.caReplacedAt)&&d(_t,{variant:`warning`,title:e(`system.localAccess.caReplacedTitle`,`The local CA was replaced - re-install it on your devices`),message:e(`system.localAccess.caReplacedBody`,`The previous local CA had no name constraints: if its key ever leaked it could vouch for any website. The hub now uses a CA limited to private addresses and local names. Download it again and trust it on every phone and computer that used the old one (replaced {{when}}).`,{when:new Date(u.caReplacedAt).toLocaleString()})}),a(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.mode`,`Mode`)}),d(`dd`,{className:`font-medium`,children:C})]}),a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.validTo`,`Valid to`)}),d(`dd`,{className:`font-mono`,children:u?.validTo?new Date(u.validTo).toLocaleString():`—`})]}),a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.leafSha256`,`Leaf SHA-256`)}),d(`dd`,{className:`font-mono`,title:u?.leafFingerprintSha256??void 0,children:Er(u?.leafFingerprintSha256??null)})]}),u?.storedUpload!=null&&a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.storedUpload`,`Stored upload`)}),d(`dd`,{className:`font-medium`,children:e(`system.localAccess.storedUploadValue`,`valid to {{validTo}}, {{ca}}`,{validTo:new Date(u.storedUpload.validTo).toLocaleDateString(),ca:u.storedUpload.hasCa?e(`system.localAccess.storedUploadWithCa`,`with its CA`):e(`system.localAccess.storedUploadNoCa`,`no CA`)})})]}),a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.caSha256`,`CA SHA-256`)}),d(`dd`,{className:`font-mono`,title:u?.caFingerprintSha256??void 0,children:u?.mode===`uploaded`&&u.caFingerprintSha256===null?d(`span`,{className:`font-sans text-foreground-subtle`,children:e(`system.localAccess.issuerNotIncludedInThe`,`Issuer not included in the upload (not the local CA)`)}):Er(u?.caFingerprintSha256??null)})]})]}),u&&u.sans.length>0&&d(`div`,{className:`flex flex-wrap gap-1`,children:u.sans.map(e=>d(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 font-mono text-[10px] text-foreground-subtle`,children:e},e))}),a(`div`,{className:`flex flex-wrap gap-2`,children:[d(Ue,{label:e(`system.localAccess.regenerate`,`Regenerate`),title:e(`system.localAccess.issueANewLeaf`,`Issue a new leaf?`),description:e(`system.localAccess.issuesANewLeafUnder`,`Issues a new leaf under the current local CA. Clients that trust the CA keep working. The HTTPS listener reloads.`),confirmLabel:e(`system.localAccess.regenerate`,`Regenerate`),disabled:u?.mode===`uploaded`||i.isPending,action:()=>i.mutateAsync({})}),d(G,{size:`sm`,variant:`outline`,onClick:()=>m(e=>!e),children:e(`system.localAccess.upload`,`Upload`)}),u?.caCertPem&&d(G,{size:`sm`,variant:`outline`,onClick:S,children:e(`system.localAccess.downloadCa`,`Download CA`)}),u?.mode===`uploaded`&&d(Ue,{label:e(`system.localAccess.revertToGenerated`,`Revert to generated`),title:e(`system.localAccess.revertTitle`,`Switch back to the generated certificate?`),description:e(`system.localAccess.keepsTheUploadedPair`,`Returns to the generated local CA. The uploaded certificate and its CA stay stored here; you can select them again.`),confirmLabel:e(`system.localAccess.revert`,`Revert`),disabled:o.isPending,action:()=>o.mutateAsync({})}),u?.mode===`generated`&&u.storedUpload!=null&&d(Ue,{label:e(`system.localAccess.useUploaded`,`Use uploaded certificate`),title:e(`system.localAccess.useUploadedTitle`,`Serve the stored upload again?`),description:e(`system.localAccess.useUploadedDescription`,`The stored uploaded certificate replaces the generated one on the HTTPS listener. The generated certificate stays stored.`),confirmLabel:e(`system.localAccess.useUploaded`,`Use uploaded certificate`),disabled:s.isPending,action:()=>s.mutateAsync(void 0)})]}),f&&a(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[d(Cr,{kind:`certificate`,label:e(`system.localAccess.certificateOrFullChainPem`,`Certificate or full chain (PEM)`),value:h,onChange:g}),d(Cr,{kind:`privateKey`,label:e(`system.localAccess.privateKeyPem`,`Private key (PEM)`),value:_,onChange:v}),d(Cr,{kind:`ca`,label:e(`system.localAccess.caPemRequired`,`CA (PEM) - required unless the certificate comes from a public CA`),value:y,onChange:b,rows:4}),d(G,{size:`sm`,disabled:!h.trim()||!_.trim()||xr(`certificate`,h)!==null||xr(`privateKey`,_)!==null||xr(`ca`,y)!==null||l.isPending,onClick:()=>l.mutate({certPem:h,keyPem:_,...y.trim()?{caPem:y}:{}}),children:e(`system.localAccess.saveCertificate`,`Save certificate`)}),l.isError&&d(`p`,{className:`text-xs text-danger`,children:l.error instanceof Error?l.error.message:e(`system.localAccess.uploadFailed`,`Upload failed`)})]})]})})}var Or={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`};function kr(e){let t=e.find(e=>e.isHub);return t?.https.kind===`served`?t.https.status.caFingerprintSha256:null}function Ar({https:e,mesh:t,now:n}){let{t:r}=X(),i=Pe().data?.caCertPem??``,o=()=>{if(i===``)return;let e=URL.createObjectURL(new Blob([i],{type:`application/x-pem-file`})),t=document.createElement(`a`);t.href=e,t.download=`camstack-ca.crt`,t.click(),URL.revokeObjectURL(e)},s=t?.ca,c=s?.state===`ready`?Date.parse(s.validTo):null,l=t?.listener;return a(`div`,{className:`space-y-1`,"data-testid":`ca-strip`,children:[d(q,{label:r(`certificates.caStrip.localHttpsCaSha256`,`Local HTTPS CA (SHA-256)`),valueClassName:`font-mono`,children:a(`span`,{className:`flex flex-wrap items-center gap-2`,children:[kr(e)??`—`,i!==``&&a(G,{type:`button`,variant:`ghost`,size:`sm`,onClick:o,children:[d(b,{className:`h-3 w-3`,"aria-hidden":!0}),r(`certificates.caStrip.downloadCa`,`Download CA`)]})]})}),d(q,{label:r(`certificates.caStrip.clusterCaSha256`,`Cluster CA (SHA-256)`),valueClassName:`font-mono`,children:s===void 0?`—`:s.state===`ready`?s.fingerprintSha256:d(`span`,{className:`text-danger`,children:r(`certificates.caStrip.unavailable`,{reason:s.reason})})}),s?.state===`ready`&&a(q,{label:r(`certificates.caStrip.clusterCaValidUntil`,`Cluster CA valid until`),children:[s.validTo,c!==null&&!Number.isNaN(c)&&a(`span`,{className:`ml-2 text-[10px] ${Or[an(c,n)]}`,children:[`(`,Wt(c,n),`)`]})]}),l!==void 0&&a(q,{label:r(`certificates.caStrip.nodeListener`,`Node listener`),children:[l.state===`open`&&d(J,{variant:`success`,children:r(`certificates.caStrip.open`,`Open`)}),l.state===`not-started`&&d(J,{variant:`default`,children:r(`certificates.caStrip.notStarted`,`Not started`)}),l.state===`closed`&&a(`span`,{className:`text-danger`,children:[r(`certificates.caStrip.closedSince`,{when:Gt(l.since)}),` `,l.reason]})]}),t!==void 0&&!t.registryAvailable&&a(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[d(g,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),d(`span`,{children:r(`certificates.caStrip.theCertificateRegistryIsNot`,`The certificate registry is not up, so the node list below is incomplete.`)})]})]})}function jr(e,t){let n=new Set;for(let t of e)n.add(t.nodeId);for(let e of t?.nodes??[])n.add(e.nodeId);return[...n].map(n=>{let r=e.find(e=>e.nodeId===n)??null,i=t?.nodes.find(e=>e.nodeId===n)??null;return{nodeId:n,isHub:r?.isHub??n===`hub`,online:r?.online??i?.online??!1,https:r,mesh:i}}).toSorted((e,t)=>Number(t.isHub)-Number(e.isHub)||e.nodeId.localeCompare(t.nodeId))}function Mr(e){return e.isHub?Y.t(`helpers.nodesModel.hubReissued`):e.mesh===null?Y.t(`helpers.nodesModel.noCertRecorded`):e.online?null:Y.t(`helpers.certificateModel.nodeOffline`)}function Nr(e){return e.isHub||e.mesh===null?Mr(e):null}var Pr={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`},Fr={enroll:`Issued at enrollment`,renewal:`Issued by a renewal`,boot:`Issued at boot`,pairing:`Issued at pairing`,observed:`Observed on its connection`},Ir={uploaded:`Uploaded`,generated:`Generated`,disabled:`Disabled`};function Lr(e){let t=e.https?.https;return t?.kind===`served`?nn(t.status.validTo):null}function Rr({ms:e,now:t}){return e===null?d(`span`,{className:`text-foreground-subtle`,children:`—`}):a(`div`,{children:[d(`div`,{children:Gt(e)}),d(`div`,{className:`text-[10px] ${Pr[an(e,t)]}`,children:Wt(e,t)})]})}function zr({row:e}){let{t}=X(),n=e.https?.https;return n===void 0?d(`span`,{className:`text-foreground-subtle`,children:`—`}):n.kind===`served`?a(`div`,{title:n.status.leafFingerprintSha256??``,children:[d(J,{variant:`success`,className:`text-[10px]`,children:t(`certificates.nodesColumns.served`,`Served`)}),d(`span`,{className:`ml-1.5 text-[10px] text-foreground-subtle`,children:Ir[n.status.mode]}),d(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:tn(n.status.leafFingerprintSha256)}),n.status.sans.length>0&&d(`div`,{className:`mt-0.5 max-w-[14rem] truncate font-mono text-[10px] text-foreground-subtle`,title:n.status.sans.join(`, `),children:n.status.sans.join(`, `)})]}):a(`div`,{className:`max-w-[16rem]`,children:[d(J,{variant:n.kind===`unreadable`?`danger`:`warning`,className:`text-[10px]`,children:n.kind===`unreadable`?t(`certificates.nodesColumns.unreadable`,`Unreadable`):t(`certificates.nodesColumns.notServed`,`Not served`)}),d(`div`,{className:`mt-1 whitespace-normal text-[10px] text-foreground-subtle`,children:n.reason})]})}function Br({row:e}){let{t}=X(),n=e.mesh?.current??null;if(n===null)return d(`span`,{className:`text-foreground-subtle`,children:t(`certificates.nodesColumns.noneRecorded`,`None recorded`)});let r=e.mesh?.history.length??0;return a(`div`,{children:[d(`div`,{className:`font-mono text-[11px]`,title:n.serial,children:Qt(n.serial)}),d(`div`,{className:`font-mono text-[10px] text-foreground-subtle`,title:n.fingerprintSha256,children:tn(n.fingerprintSha256)}),a(`div`,{className:`text-[10px] text-foreground-subtle`,children:[Fr[n.issuedVia],r>0?` · ${t(`certificates.nodesColumns.earlier`,{count:r})}`:``]})]})}function Vr({row:e}){let{t}=X(),n=e.mesh?.presentingCurrent??null;return n===null?d(`span`,{className:`text-foreground-subtle`,children:e.online?`—`:t(`certificates.nodesColumns.offline`,`Offline`)}):n?d(J,{variant:`success`,className:`text-[10px]`,children:t(`common.yes`,`Yes`)}):d(J,{variant:`warning`,className:`text-[10px]`,children:t(`certificates.nodesColumns.noPresentsAnother`,`No - presents another`)})}function Hr(e){let t=e.icon;return a(G,{type:`button`,variant:`ghost`,size:`sm`,className:e.danger?`text-danger hover:bg-danger/10`:void 0,disabled:e.reason!==null||e.busy,title:e.reason??void 0,"aria-label":e.ariaLabel,onClick:e.onClick,children:[e.spinning?d(M,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):d(t,{className:`h-3 w-3`,"aria-hidden":!0}),e.label]})}function Ur({reasons:e}){let{t}=X();return a(he,{className:`inline-block`,children:[d(mt,{children:d(`span`,{className:`cursor-help text-[11px] text-foreground-subtle`,"data-testid":`hub-managed-note`,children:t(`certificates.nodesColumns.managedByTheHub`,`Managed by the hub`)})}),d(it,{children:d(`ul`,{className:`max-w-xs space-y-1 whitespace-normal text-left text-[11px]`,children:e.map(e=>d(`li`,{children:e},e))})})]})}function Wr({row:e,o:t}){let{t:n}=X(),r=e.https===null?`No HTTPS inventory for this node.`:Kt(e.https).reason,i=Mr(e),o=Nr(e),s=n=>t.running?.nodeId===e.nodeId&&t.running.action===n,c=t=>!e.isHub||t===null,l=[r,i,o].filter((e,t,n)=>e!==null&&n.indexOf(e)===t);return a(`div`,{className:`flex w-44 flex-col items-end gap-1`,children:[a(`div`,{className:`flex flex-col items-end gap-0.5`,children:[c(r)&&d(Hr,{label:n(`certificates.nodesColumns.renewHttps`,`Renew HTTPS`),ariaLabel:n(`certificates.nodesColumns.renewTheCertificateOn`,`Renew the certificate on {{nodeId}}`,{nodeId:e.nodeId}),icon:S,reason:r,busy:t.busy,spinning:s(`renew-https`),danger:!1,onClick:()=>t.onRenewHttps(e)}),c(i)&&d(Hr,{label:s(`renew-identity`)?n(`certificates.nodesColumns.renewing`,`Renewing…`):n(`certificates.nodesColumns.renewIdentity`,`Renew identity`),ariaLabel:n(`certificates.nodesColumns.renewTheClusterCertificateOf`,`Renew the cluster certificate of {{nodeId}}`,{nodeId:e.nodeId}),icon:S,reason:i,busy:t.busy,spinning:s(`renew-identity`),danger:!1,onClick:()=>t.onRenewIdentity(e)}),c(o)&&d(Hr,{label:n(`certificates.nodesColumns.revokeIdentity`,`Revoke identity`),ariaLabel:n(`certificates.nodesColumns.revokeTheClusterCertificateOf`,`Revoke the cluster certificate of {{nodeId}}`,{nodeId:e.nodeId}),icon:y,reason:o,busy:t.busy,spinning:s(`revoke-identity`),danger:!0,onClick:()=>t.onRevokeIdentity(e)})]}),e.isHub&&l.length>0&&d(Ur,{reasons:l}),!e.isHub&&r!==null&&e.https!==null&&d(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`renew-reason-${e.nodeId}`,children:r}),!e.isHub&&i!==null&&d(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`mesh-reason-${e.nodeId}`,children:i})]})}function Gr(e){return[{key:`node`,header:Y.t(`certificates.nodesColumns.node`,`Node`),sortValue:e=>e.isHub?``:e.nodeId.toLowerCase(),render:e=>a(`div`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`font-medium text-foreground`,children:e.nodeId}),e.nodeId===`hub`&&d(J,{variant:`info`,className:`text-[10px]`,children:Y.t(`common.hubWord`)}),!e.online&&d(J,{variant:`default`,className:`text-[10px]`,children:Y.t(`common.offline`)})]})},{key:`https-state`,header:`HTTPS`,notSortableReason:`A state with a reason has no single order.`,render:e=>d(zr,{row:e})},{key:`https-expires`,header:Y.t(`certificates.nodesColumns.httpsExpires`,`HTTPS expires`),sortValue:e=>Lr(e),render:t=>d(Rr,{ms:Lr(t),now:e.now})},{key:`identity`,header:Y.t(`certificates.nodesColumns.identity`,`Identity`),sortValue:e=>e.mesh?.current?.serial??null,render:e=>d(Br,{row:e})},{key:`identity-expires`,header:Y.t(`certificates.nodesColumns.identityExpires`,`Identity expires`),sortValue:e=>e.mesh?.current?.notAfter??null,render:t=>d(Rr,{ms:t.mesh?.current?.notAfter??null,now:e.now})},{key:`presenting`,header:Y.t(`certificates.nodesColumns.inUse`,`In use`),notSortableReason:`Offline nodes have no answer to order by.`,render:e=>d(Vr,{row:e})},{key:`actions`,header:Y.t(`certificates.nodesColumns.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order.`,render:t=>d(Wr,{row:t,o:e})}]}e();function Kr(){let{t:e}=X(),t=U(),i=K.useUtils(),o=dr(6e4),s=K.certificates.listHttpsCertificates.useQuery(),c=K.certificates.getMeshCertificates.useQuery(),[l,u]=r(null),[f,p]=r(null),[m,h]=r(null),g=()=>{h(null),i.certificates.listHttpsCertificates.invalidate(),i.certificates.getMeshCertificates.invalidate()},_=e=>(t,n)=>{h(null),u(`${n.nodeId}: ${e} - ${t.message}`)},v=K.certificates.renewHttpsOnNode.useMutation({onSuccess:(t,n)=>{p({tone:`success`,message:t.restartRequired?e(`certificates.nodesCard.newCertificateIssuedRestartThe`,`{{nodeId}}: new certificate issued. Restart the node to serve it.`,{nodeId:n.nodeId}):e(`certificates.nodesCard.newCertificateIssuedAndServed`,`{{nodeId}}: new certificate issued and served.`,{nodeId:n.nodeId})}),g()},onError:_(`renewal failed`)}),y=K.certificates.renewMeshOnNode.useMutation({onSuccess:e=>{p(Zt(e)),g()},onError:_(`renewal could not start`)}),b=K.certificates.revokeMeshOnNode.useMutation({onSuccess:e=>{p({tone:`success`,message:`${e.nodeId}: ${e.next}`}),g()},onError:_(`revoke failed`)}),x=v.isPending||y.isPending||b.isPending,S=(e,t)=>{u(null),p(null),h({nodeId:e,action:t})},C=async n=>{await t({title:e(`certificates.nodesCard.renewHttpsOn`,`Renew HTTPS on "{{nodeId}}"?`,{nodeId:n.nodeId}),message:n.isHub?e(`certificates.nodesCard.aNewCertificateIsIssued`,`A new certificate is issued from the local CA. Clients that trust the CA keep working.`):e(`certificates.nodesCard.theNodeMakesANew`,`The node makes a new key, the hub signs it and the node switches over without a restart. It keeps serving what it had if anything fails.`),confirmLabel:e(`certificates.nodesCard.renew`,`Renew`)})&&(S(n.nodeId,`renew-https`),v.mutate({nodeId:n.nodeId}))},T=e=>{S(e.nodeId,`renew-identity`),y.mutate({nodeId:e.nodeId})},E=async n=>{await t({title:e(`certificates.nodesCard.revokeTheIdentityOf`,`Revoke the identity of "{{nodeId}}"?`,{nodeId:n.nodeId}),message:e(`certificates.nodesCard.isDisconnectedAtOnceAnd`,`{{nodeId}} is disconnected at once and can no longer connect. To bring it back it must be paired again from System → Cluster → Agents. It stays in the node list until you forget it on the Cluster page. This cannot be undone.`,{nodeId:n.nodeId}),confirmLabel:e(`certificates.nodesCard.revokeAndDisconnect`,`Revoke and disconnect`),variant:`danger`})&&(S(n.nodeId,`revoke-identity`),b.mutate({nodeId:n.nodeId}))},D=Gr({now:o,busy:x,running:m,onRenewHttps:e=>void C(e),onRenewIdentity:T,onRevokeIdentity:e=>void E(e)}),O=n(()=>jr(s.data??[],c.data),[s.data,c.data]),k=c.data?.registryAvailable??!0;return d(Z,{id:`nodes`,title:e(`certificates.nodesCard.nodes`,`Nodes`),icon:w,description:e(`certificates.nodesCard.eachNodeHoldsTwoCertificates`,`Each node holds two certificates: one it serves over HTTPS, one that proves its identity to the hub. Renewing replaces a certificate without a gap; revoking an identity cuts the node off until it re-joins.`),notice:Rt(l,f),onDismissNotice:()=>{u(null),p(null)},children:d(cr,{isPending:s.isPending||c.isPending,error:s.error??c.error,what:`node certificates`,onRetry:()=>{s.refetch(),c.refetch()},children:a(`div`,{className:`space-y-3`,children:[d(Ar,{https:s.data??[],mesh:c.data,now:o}),d(xe,{columns:D,rows:O,rowKey:e=>e.nodeId,minWidthPx:960,maxBodyHeight:Ee,defaultSort:{columnKey:`node`,dir:`asc`},emptyMessage:k?e(`certificates.nodesCard.noNodesReported`,`No nodes reported.`):e(`certificates.nodesCard.theCertificateRegistryIsNot`,`The certificate registry is not available yet, so nodes cannot be listed.`)})]})})})}function qr({pairOpen:e,onPairClose:t}){return a(`div`,{className:`space-y-4`,"data-testid":`certificates-page`,children:[d(_r,{pairOpen:e,onPairClose:t}),d(lr,{}),d(Dr,{}),d(Kr,{})]})}function Jr({userId:e,username:t,onClose:n}){let{t:r}=X(),i=U(),o=K.useUtils(),s=De({userId:e}),c=K.auth.listLoginMethods.useQuery(),l=be({onSuccess:()=>void o.userManagement.listExternalIdentities.invalidate()}),u=new Map((c.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),f=s.data??[],p=async(n,a)=>{await i({title:r(`users.externalIdentitiesModal.removeSignInLink`,`Remove sign-in link`),message:r(`users.externalIdentitiesModal.willNoLongerBeAble`,`"{{username}}" will no longer be able to sign in with this {{label}} account.`,{username:t,label:a}),confirmLabel:r(`common.remove`,`Remove`),variant:`danger`})&&l.mutate({userId:e,provider:n.provider,subject:n.subject})};return d(W,{open:!0,onOpenChange:e=>!e&&n(),children:a(ct,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[d(Ae,{children:a(Ne,{className:`flex items-center gap-2`,children:[d(O,{className:`h-4 w-4 text-primary`}),a(`span`,{children:[r(`users.externalIdentitiesModal.linkedSignInAccounts`,`Linked sign-in accounts`),a(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[r(`users.externalIdentitiesModal.user`,`User:`),` `,d(`span`,{className:`font-mono`,children:t})]})]})]})}),d(Fe,{className:`space-y-3`,children:s.isLoading?a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(M,{className:`h-3.5 w-3.5 animate-spin`}),r(`common.loading`,`Loading…`)]}):f.length===0?d(`p`,{className:`text-xs text-foreground-subtle`,children:r(`users.externalIdentitiesModal.noLinkedAccountsOnlyThe`,`No linked accounts. Only the user can link one, from their own profile page.`)}):d(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:f.map(e=>{let t=u.get(e.provider),n=t??e.provider;return a(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[a(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`font-medium text-foreground truncate`,children:[n,t===void 0&&d(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:r(`users.externalIdentitiesModal.providerUnavailable`,`provider unavailable`)})]}),a(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:[e.label??e.subject,` ·`,` `,new Date(e.linkedAt).toLocaleDateString()]})]}),a(`button`,{onClick:()=>void p(e,n),disabled:l.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[d(pe,{className:`h-3 w-3`}),r(`common.remove`,`Remove`)]})]},`${e.provider}|${e.subject}`)})})}),d(st,{children:d(G,{onClick:n,variant:`secondary`,children:r(`common.close`,`Close`)})})]})})}function Yr({userId:e,username:t,onClose:n}){let{t:r}=X(),i=c(),o=U(),l=ve({userId:e}),u=l.data,p=()=>i.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),m=Re({onSuccess:()=>{p(),n()}}),h=l.isLoading?`loading`:u?.enabled?`enrolled`:`not_enrolled`;return d(W,{open:!0,onOpenChange:e=>!e&&n(),children:a(ct,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[d(Ae,{children:a(Ne,{className:`flex items-center gap-2`,children:[d(f,{className:`h-4 w-4 text-primary`}),a(`span`,{children:[r(`users.totpModal.twoFactorAuthentication`,`Two-factor authentication`),a(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[r(`users.totpModal.user`,`User:`),` `,d(`span`,{className:`font-mono`,children:t})]})]})]})}),a(Fe,{className:`space-y-4`,children:[h===`loading`&&a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(M,{className:`h-3.5 w-3.5 animate-spin`}),r(`users.totpModal.checkingStatus`,`Checking status…`)]}),h===`not_enrolled`&&a(`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:[d(A,{className:`h-4 w-4 mt-0.5 shrink-0`}),a(`div`,{children:[d(`div`,{className:`font-medium text-foreground`,children:r(`users.totpModal.2faNotEnrolled`,`2FA not enrolled`)}),d(`p`,{className:`mt-0.5`,children:r(`users.totpModal.onlyTheUserThemselvesCan`,`Only the user themselves can enable 2FA, from their own profile page.`)})]})]}),h===`enrolled`&&u&&a(s,{children:[a(`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:[d(k,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),a(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[d(`div`,{className:`font-medium`,children:r(`users.totpModal.2faIsActive`,`2FA is active`)}),d(`div`,{className:`text-foreground-subtle`,children:r(`common.enrolledOn`,{when:u.confirmedAt?new Date(u.confirmedAt).toLocaleString():`—`})})]})]}),d(`div`,{className:`text-[11px] text-foreground-subtle`,children:r(`users.totpModal.removingHereClearsTheServer`,`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.`)}),a(`div`,{className:`flex justify-end gap-2`,children:[d(G,{onClick:n,variant:`secondary`,children:r(`common.close`,`Close`)}),a(`button`,{onClick:async()=>{await o({title:r(`users.totpModal.remove2fa`,`Remove 2FA`),message:r(`users.totpModal.removeTwoFactorAuthenticationFor`,`Remove two-factor authentication for "{{username}}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,{username:t}),confirmLabel:r(`common.remove`,`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?d(M,{className:`h-3 w-3 animate-spin`}):d(T,{className:`h-3 w-3`}),r(`users.totpModal.remove2fa`,`Remove 2FA`)]})]})]})]})]})})}e();function Xr({userId:e,username:t,onClose:n}){let{t:i}=X(),{user:o,logout:s}=xt(),c=o?.id===e,l=U(),u=K.useUtils(),f=K.auth.listSessions.useQuery({userId:e}),[p,m]=r(null),h=K.auth.revokeSessions.useMutation({onSuccess:(e,t)=>{if(c&&`userId`in t){s();return}u.auth.listSessions.invalidate()},onError:e=>m(`Sign out failed: ${e.message}`)}),g=async e=>{await l({title:i(`users.userSessionsModal.signOutThisSession`,`Sign out this session`),message:i(`users.userSessionsModal.onWillHaveToSign`,`"{{username}}" on {{label}} will have to sign in again.`,{username:t,label:on(e.client).label}),confirmLabel:i(`users.userSessionsModal.signOut`,`Sign out`),variant:`danger`})&&(m(null),h.mutate({id:e.id}))},_=async()=>{await l({title:i(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),message:c?i(`users.userSessionsModal.everySessionOfYourOwn`,`Every session of your own account ends, this browser included: you will be signed out here too.`):i(`users.userSessionsModal.everySessionOfEndsAt`,`Every session of "{{username}}" ends at once; each device has to sign in again.`,{username:t}),confirmLabel:i(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),variant:`danger`})&&(m(null),h.mutate({userId:e}))},v=h.isPending&&h.variables!==void 0&&`id`in h.variables?h.variables.id:null;return d(W,{open:!0,onOpenChange:e=>!e&&n(),children:a(ct,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[d(Ae,{children:a(Ne,{className:`flex items-center gap-2`,children:[d(fe,{className:`h-4 w-4 text-primary`}),a(`span`,{children:[i(`users.userSessionsModal.activeSessions`,`Active sessions`),a(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[i(`users.userSessionsModal.user`,`User:`),` `,d(`span`,{className:`font-mono`,children:t})]})]})]})}),a(Fe,{className:`space-y-3`,children:[p!==null&&d(`div`,{className:`text-[11px] text-danger`,children:p}),d(rn,{sessions:f.data??[],isLoading:f.isLoading,loadError:f.isError?f.error?.message??`Request failed`:null,emptyText:`No active sessions.`,onRevoke:e=>void g(e),revokingId:v})]}),a(st,{className:`justify-between`,children:[a(`button`,{onClick:()=>void _(),disabled:h.isPending||(f.data??[]).length===0,className:`inline-flex items-center gap-1.5 rounded border border-danger/40 px-2.5 py-1 text-[11px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,children:[h.isPending&&v===null?d(M,{className:`h-3 w-3 animate-spin`}):d(le,{className:`h-3 w-3`}),i(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`)]}),d(G,{onClick:n,variant:`secondary`,children:i(`common.close`,`Close`)})]})]})})}function Zr({icon:e,label:t,count:n,all:r,total:i}){let{t:o}=X();return a(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[d(e,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),d(`span`,{className:`min-w-0 flex-1 text-foreground-subtle`,children:t}),d(`span`,{className:n===0?`text-foreground-subtle`:`font-medium text-foreground`,children:n===0?o(`common.none`):r?o(`users.scopePreview.all`,`all {{total}}`,{total:i}):o(`users.scopePreview.of`,`{{count}} of {{total}}`,{count:n,total:i})})]})}function Qr({scopes:e,isAdmin:t,invalidReason:n}){let{t:r}=X(),i=N(),c=o({queryKey:[`auth`,`previewScope`,e,t],enabled:n===null,queryFn:()=>i.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:t})}),{data:l}=et({projection:`slim`}),u=l?.length??0;if(n!==null)return d(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:a(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,children:[d(C,{className:`h-3 w-3 shrink-0`}),n]})});if(c.isLoading)return a(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface p-3 text-[11px] text-foreground-subtle`,children:[d(M,{className:`h-3 w-3 animate-spin`}),r(`users.scopePreview.resolving`,`Resolving…`)]});if(c.isError||!c.data)return d(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:d(`p`,{className:`text-[11px] text-danger`,children:r(`users.scopePreview.couldNotResolveThisGrant`,`Could not resolve this grant set. Saving is still allowed — the server enforces the same rules either way.`)})});let f=c.data;return d(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:f.isAdmin?a(`p`,{className:`text-[11px] text-foreground`,children:[d(`span`,{className:`font-medium`,children:r(`users.scopePreview.administrator`,`Administrator`)}),` `,r(`users.scopePreview.unrestricted`)]}):a(s,{children:[d(Zr,{icon:_,label:r(`users.scopePreview.devicesTheyCanSee`,`Devices they can see`),count:f.device.view.deviceCount,all:f.device.view.all,total:u}),d(Zr,{icon:m,label:r(`users.scopePreview.devicesTheyCanOperate`,`Devices they can operate`),count:f.device.create.deviceCount,all:f.device.create.all,total:u}),d(Zr,{icon:h,label:r(`users.scopePreview.devicesTheyCanDelete`,`Devices they can delete`),count:f.device.delete.deviceCount,all:f.device.delete.all,total:u}),a(`div`,{className:`border-t border-border pt-2 text-[10px] text-foreground-subtle`,children:[r(`users.scopePreview.systemAccess`,`System access:`),` `,f.system.length===0?r(`common.none`):f.system.join(`, `),f.capabilities.length>0&&a(s,{children:[` `,r(`users.scopePreview.extraCapabilities`,`· Extra capabilities:`),` `,f.capabilities.map(e=>e.name).join(`, `)]}),f.addons.length>0&&a(s,{children:[` `,r(`users.scopePreview.addons`,`· Addons:`),` `,f.addons.map(e=>e.name).join(`, `)]})]}),f.device.view.deviceCount===0&&d(`p`,{className:`text-[10px] text-warning`,children:r(`users.scopePreview.thisUserWillNotBe`,`This user will not be able to see any device.`)})]})})}e();function $r(e){let t=ne(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 ei(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:te({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function ti({user:e,onClose:t,onSubmit:i,submitting:o,callerScopes:c}){let{t:l}=X(),u=j(),f=n(()=>$r(e.scopes??[]),[e.scopes]),[p,m]=r(f),[h,g]=r(f.mode===`advanced`),_=n(()=>ei(p),[p]),v=!e.isAdmin&&p.mode===`role`&&p.roleId===null,y=n(()=>e.isAdmin?null:p.mode===`role`&&p.roleId===null?l(`users.userAccessModal.pickAccess`):Le(_,u),[e.isAdmin,p.mode,p.roleId,_]),b=e=>m({...p,...e});return d(W,{open:!0,onOpenChange:e=>!e&&t(),children:a(ct,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[a(Ae,{children:[d(Ne,{children:l(`users.userAccessModal.title`,{name:e.username})}),d(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?l(`users.userAccessModal.thisUserIsAnAdministrator`,`This user is an administrator — they can do everything, and the settings below are ignored.`):l(`users.userAccessModal.chooseWhatTheyCanDo`,`Choose what they can do, then which devices it applies to.`)})]}),a(Fe,{className:`space-y-4`,children:[v&&a(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[d(C,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),a(`p`,{className:`text-[11px] text-foreground`,children:[d(`span`,{className:`font-medium`,children:l(`users.userAccessModal.noAccess`,`No access.`)}),` `,d(`span`,{className:`text-foreground-subtle`,children:l(`users.userAccessModal.cannotSeeAnything`,{name:e.username})})]})]}),a(`section`,{className:`space-y-2`,children:[d(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:l(`users.userAccessModal.1WhatCanTheyDo`,`1 · What can they do`)}),d(`div`,{className:`space-y-1.5`,children:B.map(e=>{let t=p.mode===`role`&&p.roleId===e.id;return a(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-lg border p-2.5 transition-colors ${t?`border-primary bg-primary/5`:`border-border hover:bg-foreground-subtle/5`}`,children:[d(`input`,{type:`radio`,name:`access-role`,checked:t,onChange:()=>b({mode:`role`,roleId:e.id}),className:`mt-0.5 border-border focus:ring-primary`}),a(`span`,{className:`min-w-0`,children:[d(`span`,{className:`block text-[12px] font-medium text-foreground`,children:e.label}),d(`span`,{className:`mt-0.5 block text-[10px] text-foreground-subtle`,children:e.description})]})]},e.id)})}),a(`button`,{type:`button`,onClick:()=>{if(!h){m({...p,mode:`advanced`,advancedScopes:_}),g(!0);return}g(!1),m($r(p.advancedScopes))},className:`inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] text-foreground-subtle transition-colors hover:bg-foreground-subtle/10 hover:text-foreground`,children:[d(h?L:R,{className:`h-3 w-3`}),l(`users.userAccessModal.advancedEditRawGrants`,`Advanced — edit raw grants`)]}),h&&a(`div`,{className:`rounded-lg border border-border p-2`,children:[d(`p`,{className:`mb-2 text-[10px] text-foreground-subtle`,children:l(`users.userAccessModal.oneRowPerGrantAnything`,`One row per grant. Anything expressible here overrides the three roles above; close this section to go back to them.`)}),d(je,{value:p.advancedScopes,onChange:e=>b({mode:`advanced`,advancedScopes:e}),clampToParent:c,emptyHint:d(s,{children:d(St,{i18nKey:`users.userAccessModal.noGrants`,values:{name:e.username},components:{b:d(`span`,{className:`font-medium text-foreground`})}})})})]})]}),p.mode===`role`&&a(`section`,{className:`space-y-2`,children:[d(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:l(`users.userAccessModal.2OnWhichDevices`,`2 · On which devices`)}),d(ze,{value:p.selector,onChange:e=>b({selector:e}),includeLinked:p.includeLinked,onIncludeLinkedChange:e=>b({includeLinked:e}),clampToDeviceIds:null})]}),a(`section`,{className:`space-y-2`,children:[d(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:p.mode===`role`?l(`users.userAccessModal.3Result`,`3 · Result`):l(`users.userAccessModal.2Result`,`2 · Result`)}),d(Qr,{scopes:_,isAdmin:e.isAdmin,invalidReason:y})]})]}),a(st,{children:[d(G,{variant:`outline`,size:`sm`,onClick:t,children:l(`common.cancel`,`Cancel`)}),d(G,{size:`sm`,onClick:()=>i([..._]),disabled:o||y!==null,children:o?d(M,{className:`h-3 w-3 animate-spin`}):l(`users.userAccessModal.saveAccess`,`Save access`)})]})]})})}e();var ni=8;function ri(){return{username:``,password:``,isAdmin:!1}}function ii(e){return{id:e.id,username:e.username,password:``,isAdmin:e.isAdmin}}function ai(e){return e instanceof Error?e.message:Y.t(`admin.system.users.genericError`)}function oi(){let{t:e}=X(),n=c(),{user:i}=xt(),{state:o,openNew:l,openEdit:u,close:p}=ht(),[g,_]=r(null),[y,b]=r(null),[x,S]=r(!1),{data:C,isLoading:w,isError:T,error:D,refetch:k}=gt(),A=U(),j=rt(),N=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),P=ke(),F=Me({onSuccess:N}),L=Te({onSuccess:N}),R=ge({onSuccess:N}),z=Qe({onSuccess:()=>{N(),B(null)}}),[ee,B]=r(null),[V,te]=r(null),[ne,re]=r(null),[ie,ae]=r(null),oe=C??[],H=o.mode===`edit`?oe.find(e=>e.id===o.id)??null:null,ce=()=>{_(null),b(null),S(!1),P.reset(),L.reset(),p()};t(()=>{if(o.mode===`closed`){_(null),b(null),S(!1);return}if(o.mode===`new`){_(e=>e!==null&&e.id===void 0?e:ri());return}if(H===null){w||p();return}_(e=>e?.id===H.id?e:ii(H))},[o,H,w,p]);let le=o.mode===`new`&&g!==null&&g.id===void 0||o.mode===`edit`&&g!==null&&H!==null;async function ue(t){await A({title:e(`admin.system.users.deleteUser`,`Delete user`),message:e(`admin.system.users.permanentlyDeleteUserThisCannot`,`Permanently delete user "{{username}}"? This cannot be undone — any active sessions will be revoked on next request.`,{username:t.username}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&(F.mutate({id:t.id}),o.mode===`edit`&&o.id===t.id&&ce())}async function de(t){let n=await j({title:e(`admin.system.users.resetPassword`,`Reset password`),message:e(`admin.system.users.setANewPasswordFor`,`Set a new password for "{{username}}".`,{username:t.username}),label:e(`admin.system.users.newPassword`,`New password`),inputType:`password`,placeholder:e(`admin.system.users.atLeast8Characters`,`At least 8 characters`),confirmLabel:e(`admin.system.users.continue`,`Continue`),validate:e=>e.length<ni?Y.t(`admin.system.users.passwordTooShort`,{min:ni}):null});n===null||n.length===0||await A({title:e(`admin.system.users.resetPassword`,`Reset password`),message:e(`admin.system.users.resetThePasswordForThey`,`Reset the password for "{{username}}"? They will need to use the new password on their next login.`,{username:t.username}),confirmLabel:e(`common.reset`,`Reset`)})&&R.mutate({id:t.id,newPassword:n})}function pe(e,t){t!==e.isAdmin&&L.mutate({id:e.id,isAdmin:t})}async function me(){if(g!==null){b(null);try{if(g.id===void 0){let e=g.username.trim();if(e===``||g.password.length<ni)return;await P.mutateAsync({username:e,password:g.password,isAdmin:g.isAdmin})}else await L.mutateAsync({id:g.id,isAdmin:g.isAdmin});N(),ce()}catch(e){b(ai(e))}}}function he(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}let W=P.isPending||L.isPending,ve=g!==null&&g.id===void 0&&g.username.trim()!==``&&g.password.length>=ni,ye=g!==null&&g.id!==void 0,be=W||(g?.id===void 0?!ve:!ye),Se=e=>F.isPending&&F.variables?.id===e.id||L.isPending&&L.variables?.id===e.id||R.isPending&&R.variables?.id===e.id,Ce=[{key:`username`,header:e(`admin.system.users.username`,`Username`),sortValue:e=>e.username,render:e=>d(`span`,{className:`font-medium text-foreground`,"data-testid":`user-open-${e.id}`,children:e.username})},{key:`isAdmin`,header:e(`admin.system.users.admin`,`Admin`),nowrap:!0,sortValue:e=>+!!e.isAdmin,render:t=>d(`span`,{onClick:e=>e.stopPropagation(),children:a(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[d(`input`,{type:`checkbox`,checked:t.isAdmin,onChange:e=>pe(t,e.target.checked),disabled:Se(t),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),d(`span`,{className:t.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:t.isAdmin?e(`admin.system.users.admin`,`Admin`):e(`admin.system.users.regular`,`Regular`)})]})})},{key:`scopes`,header:e(`admin.system.users.access`,`Access`),render:t=>t.isAdmin?d(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:e(`admin.system.users.everythingAdmin`,`everything (admin)`)}):d(`span`,{onClick:e=>e.stopPropagation(),children:a(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>B(t),title:e(`admin.system.users.configureAccess`,`Configure access`),children:[d(I,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),d(si,{scopes:t.scopes??[]})]})})},{key:`createdAt`,header:e(`admin.system.users.created`,`Created`),nowrap:!0,sortValue:e=>e.createdAt,render:e=>d(`span`,{className:`text-foreground-subtle`,children:he(e.createdAt)})},{key:`actions`,header:e(`admin.system.users.actions`,`Actions`),align:`right`,nowrap:!0,notSortableReason:`Row actions`,render:t=>{let n=Se(t),r=t.id!==i?.id&&t.totpEnabled;return a(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[a(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>u(t.id),disabled:n,title:e(`admin.system.users.editUser`,`Edit user`),children:[d(m,{className:`h-3 w-3`}),e(`common.edit`,`Edit`)]}),r&&a(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>te(t),disabled:n,title:e(`admin.system.users.removeTwoFactorAuthentication`,`Remove two-factor authentication`),children:[d(f,{className:`h-3 w-3`}),e(`admin.system.users.remove2fa`,`Remove 2FA`)]}),a(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>re(t),disabled:n,title:e(`admin.system.users.linkedSignInAccounts`,`Linked sign-in accounts`),children:[d(O,{className:`h-3 w-3`}),e(`admin.system.users.signInLinks`,`Sign-in links`)]}),a(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>ae(t),disabled:n,title:e(`admin.system.users.activeSessions`,`Active sessions`),children:[d(fe,{className:`h-3 w-3`}),e(`admin.system.users.sessions`,`Sessions`)]}),a(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void de(t),disabled:n,title:e(`admin.system.users.resetPassword`,`Reset password`),children:[d(se,{className:`h-3 w-3`}),e(`admin.system.users.resetPassword`,`Reset password`)]}),a(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void ue(t),disabled:n,title:e(`admin.system.users.deleteUser`,`Delete user`),className:`text-danger hover:bg-danger/10`,children:[n?d(M,{className:`h-3 w-3 animate-spin`}):d(h,{className:`h-3 w-3`}),e(`common.delete`,`Delete`)]})]})}}];return a(At,{embedded:!0,icon:v,title:e(`admin.system.users.users`,`Users`),subtitle:e(`admin.system.users.hubAccountsAdminFlagAccess`,`Hub accounts, admin flag, access scopes, sessions and sign-in links.`),actions:a(G,{size:`sm`,type:`button`,onClick:()=>{b(null),l()},children:[d(E,{className:`h-3.5 w-3.5`}),e(`admin.system.users.createUser`,`Create User`)]}),children:[T&&d(_t,{title:e(`admin.system.users.couldNotLoadUsers`,`Could not load users`),message:ai(D),onRetry:()=>void k()}),w&&a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(M,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}),!w&&!T&&oe.length===0&&d(_e,{icon:v,title:e(`admin.system.users.noUsersYet`,`No users yet`),description:e(`admin.system.users.createAUserToGrant`,`Create a user to grant hub access.`)}),!w&&!T&&oe.length>0&&d(xe,{columns:Ce,rows:oe,rowKey:e=>e.id,minWidthPx:560,maxBodyHeight:`max-h-[60vh]`,onRowClick:e=>u(e.id)}),d(Je,{open:le,onClose:ce,title:g?.id===void 0?e(`admin.system.users.createUser`,`Create User`):e(`admin.system.users.edit`,`Edit {{value1}}`,{value1:g.username||`user`}),icon:v,error:y,testId:`user-form-dialog`,footer:d(G,{size:`sm`,type:`button`,disabled:be,onClick:()=>void me(),children:W?a(s,{children:[d(M,{className:`h-3.5 w-3.5 animate-spin`}),e(`admin.system.users.saving`,`Saving…`)]}):g?.id===void 0?e(`admin.system.users.create`,`Create`):e(`common.save`,`Save`)}),children:g!==null&&a(`div`,{className:`space-y-3`,children:[d(pt,{label:e(`admin.system.users.username`,`Username`),required:g.id===void 0,children:d(dt,{value:g.username,onChange:e=>_({...g,username:e.target.value}),placeholder:`john`,autoFocus:g.id===void 0,disabled:g.id!==void 0,"data-testid":`user-form-username`})}),g.id===void 0&&d(pt,{label:e(`admin.system.users.password`,`Password`),required:!0,description:e(`admin.system.users.atLeastCharacters`,`At least {{value1}} characters.`,{value1:String(ni)}),children:d(Be,{value:g.password,onValueChange:e=>_({...g,password:e}),shown:x,onToggleShown:()=>S(e=>!e),placeholder:`••••••••`,"data-testid":`user-form-password`})}),d(pt,{label:e(`admin.system.users.admin`,`Admin`),description:e(`admin.system.users.unrestrictedAccessToEveryCapability`,`Unrestricted access to every capability and device.`),children:a(`label`,{className:`inline-flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[d(`input`,{type:`checkbox`,checked:g.isAdmin,onChange:e=>_({...g,isAdmin:e.target.checked}),className:`rounded border-border focus:ring-primary`,"data-testid":`user-form-admin`}),d(`span`,{children:e(`admin.system.users.admin`,`Admin`)})]})}),g.id!==void 0&&d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`admin.system.users.toChangeThePasswordUse`,`To change the password, use Reset password on the user's row. Access scopes are configured from the Access column.`)})]})}),V&&d(Yr,{userId:V.id,username:V.username,onClose:()=>te(null)}),ne&&d(Jr,{userId:ne.id,username:ne.username,onClose:()=>re(null)}),ie&&d(Xr,{userId:ie.id,username:ie.username,onClose:()=>ae(null)}),ee&&d(ci,{user:ee,onClose:()=>B(null),onSubmit:e=>z.mutate({userId:ee.id,scopes:e}),submitting:z.isPending})]})}function si({scopes:e}){let{t}=X(),n=j();if(e.length===0)return d(`span`,{className:`font-medium text-warning`,children:t(`admin.system.users.noAccess`,`No access`)});let r=ne(e);return r===null?d(`span`,{className:`text-foreground-subtle`,children:t(`users.customGrants`,{count:e.length})}):a(`span`,{className:`text-foreground-subtle`,children:[d(`span`,{className:`font-medium text-foreground`,children:V(r.roleId).label}),` ·`,` `,me(r.selector,n)]})}function ci(e){let{user:t}=xt(),n=t?.isAdmin===!0;return d(ti,{...e,callerScopes:n?null:t?.scopes??[]})}e();var li={"api-keys":$.tokens,"linked-sessions":$.linkedApps},ui=`certificates`;function di(e){return a(G,{size:`sm`,type:`button`,"data-testid":`certificates-pair-device`,onClick:e,children:[d(f,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),Y.t(`systemPage.identity.pairADevice`,`Pair a device`)]})}function fi(){let{t:e}=X(),[t]=Ot(),n=qn(),[i,a]=r(!1),o=li[t.get(`tab`)??``];if(o!==void 0)return d(vt,{to:Dt(`access`,{integration:o}),replace:!0});let s=bt(`/system/identity`,{t:e,isAdmin:!0})??{icon:F,title:e(`system.identity`,`Identity & Access`)},c=t.get(`tab`)??`users`,l=t.get(`integration`),u=c===Ct.access.tab?Kn(l,n.requestCreate):c===`certificates`?di(()=>a(!0)):void 0;return d(kt,{icon:s.icon,title:s.title,defaultSection:`users`,sectionsLabel:`${s.title} sections`,actions:u,sections:[{id:`users`,label:e(`systemPage.identity.users`,`Users`),content:d(oi,{})},{id:Ct.access.tab,label:e(`systemPage.identity.tokensSessions`,`Tokens & sessions`),content:d(Gn,{createRequested:n.createRequested,onCreateConsumed:n.clearCreate}),ownedParams:Et.concat([wn.token,wn.scoped,wn.admin])},{id:ui,label:e(`systemPage.identity.certificates`,`Certificates`),content:d(qr,{pairOpen:i,onPairClose:()=>a(!1)})},{id:Ct.authentication.tab,label:e(`systemPage.identity.authentication`,`Authentication`),content:d(or,{}),ownedParams:Et}]})}export{fi as IdentityPage};
|