@camstack/addon-admin-ui 1.2.334 → 1.2.336
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddonCollectionPage-DkGiGxFC.js → AddonCollectionPage-1QxWaBAg.js} +1 -1
- package/dist/assets/{Addons-CypCkppm.js → Addons-C0z0FTW_.js} +1 -1
- package/dist/assets/{AdminTabs-C-9638Z4.js → AdminTabs-B28HJpqg.js} +1 -1
- package/dist/assets/{AiProfiles-DkpVWrOo.js → AiProfiles-BHiJ7Z2k.js} +1 -1
- package/dist/assets/{BrokerForm-BoqJv1y6.js → BrokerForm-DgejI2Qa.js} +1 -1
- package/dist/assets/{Build-BKZMT62f.js → Build-mdS2HDEe.js} +2 -2
- package/dist/assets/{Calendars-CJVnOCH_.js → Calendars-C6KksCu5.js} +1 -1
- package/dist/assets/{Capabilities-BZJAqIuD.js → Capabilities-3zyHWzsA.js} +1 -1
- package/dist/assets/{Cluster-BGSXOpQy.js → Cluster-dqPC_lKO.js} +1 -1
- package/dist/assets/{CompositionEditor-BTXI8CyL.js → CompositionEditor-C6YAp1cL.js} +1 -1
- package/dist/assets/{CompositionEditorPage-DGHrMSg4.js → CompositionEditorPage-BvorJdIb.js} +1 -1
- package/dist/assets/{Data-ButIQAfx.js → Data-B730h1Lv.js} +1 -1
- package/dist/assets/{DetectionIntelligence-BympJspD.js → DetectionIntelligence-Bxr9XTJ9.js} +1 -1
- package/dist/assets/DeviceDetail-C__OpABx.js +2 -0
- package/dist/assets/{DeviceDoActionFields-CL-Luh8D.js → DeviceDoActionFields-AO-X1s3A.js} +1 -1
- package/dist/assets/{Devices-o5JY5ofE.js → Devices-CqnQYB4l.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-2-YMD083.js → EmbedPlayerPage-CjqZIPN8.js} +1 -1
- package/dist/assets/{Events-DhEga6oU.js → Events-CXoJvlC-.js} +1 -1
- package/dist/assets/{Identity-C95oOYFv.js → Identity-Cu-TKZnF.js} +1 -1
- package/dist/assets/{IntegrationDetail-DeIElUcJ.js → IntegrationDetail-CyYjXCIL.js} +1 -1
- package/dist/assets/{Integrations-BazAzEMd.js → Integrations-9Nt_CRq8.js} +1 -1
- package/dist/assets/{Integrations-DVEpMOw5.js → Integrations-BSL3L3mF.js} +1 -1
- package/dist/assets/{Locations-zWb53nNH.js → Locations-fKiMVGX9.js} +1 -1
- package/dist/assets/{Logs-BYpt5JFC.js → Logs-CE2ciJEI.js} +1 -1
- package/dist/assets/{MotionZonesSettings-bKzkWJjQ.js → MotionZonesSettings-BOaTtXGm.js} +1 -1
- package/dist/assets/MyAccess-BSHUSXJ3.js +2 -0
- package/dist/assets/Network-wvfQT9sr.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-CAP-fBly.js → NodeAddonsSettingsPanel-CIwkfZQo.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-BOd1WFKM.js → NodeInferenceDevices-DFgnwBv0.js} +1 -1
- package/dist/assets/{Notifications-CWbXNwe2.js → Notifications-C0uNPyDk.js} +1 -1
- package/dist/assets/Pipeline-CtA82GPL.js +1 -0
- package/dist/assets/{Plates-C-KOXIHU.js → Plates-X3QWxhA6.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-XhoJopqN.js → PrivacyMaskSettings-68QMJWHD.js} +1 -1
- package/dist/assets/{Recordings-CT4fc1Sq.js → Recordings-DchQ0RYv.js} +1 -1
- package/dist/assets/{ScanNetworkModal-DfKFx4sF.js → ScanNetworkModal-D1V2Rp7Y.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-DC6wXmBZ.js → SceneMonitorEditor-BkF3tk4M.js} +1 -1
- package/dist/assets/{Scenes-Dg5VtqBs.js → Scenes-yWfAKebB.js} +1 -1
- package/dist/assets/{Settings-DKMsokq7.js → Settings-x5M0II2x.js} +1 -1
- package/dist/assets/{Showroom-Deofs3m7.js → Showroom-BOkxxrdq.js} +1 -1
- package/dist/assets/{StorageLocationsPanel-B9rC8lZZ.js → StorageLocationsPanel-C3dfi8nt.js} +1 -1
- package/dist/assets/{Terminal-UfI_P5VX.js → Terminal-B7-62lli.js} +1 -1
- package/dist/assets/{Viewer-afn842p3.js → Viewer-CzeSuRUq.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DXtigMeT.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BUlL5xVC.js} +1 -1
- package/dist/assets/{archive-CgE_tiDE.js → archive-BfF7PMxI.js} +1 -1
- package/dist/assets/{authed-media-BDiLsx7P.js → authed-media-L9ILUxK6.js} +1 -1
- package/dist/assets/{boxes-Djrey7Kg.js → boxes-Dk_xC_zO.js} +1 -1
- package/dist/assets/circle-slash-QT0n35L8.js +1 -0
- package/dist/assets/client-DC5W16F8.js +357 -0
- package/dist/assets/{debounced-invalidate-BBMxbAO8.js → debounced-invalidate-BRmbT6BB.js} +1 -1
- package/dist/assets/{device-integration-icon-CUB_TUPi.js → device-integration-icon-DCgYDpoY.js} +1 -1
- package/dist/assets/device-picker-model-BuMSrvSC.js +1 -0
- package/dist/assets/{dist-C9j-Z3IC.js → dist-CVsiieiA.js} +1 -1
- package/dist/assets/dist-Cy29mGod.js +357 -0
- package/dist/assets/{face-bbox-BEqNiQQm.js → face-bbox-BGfJDOso.js} +1 -1
- package/dist/assets/{hard-drive-download-D5JUf3nQ.js → hard-drive-download-COP5VoMl.js} +1 -1
- package/dist/assets/{hostInit-DDZ7WAlQ.js → hostInit-DO64mck5.js} +1 -1
- package/dist/assets/{index-CoHcNeUl.js → index-Bni8OpYr.js} +3 -3
- package/dist/assets/index-SMDlV0HD.css +2 -0
- package/dist/assets/{layers-C3hsGCP9.js → layers-CPGvg6bD.js} +1 -1
- package/dist/assets/{location-owned-usage-IYI9fhtY.js → location-owned-usage-DWOhOROb.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-a9aeeea6.js → mf-entry-bootstrap-0-777c113d.js} +2 -2
- package/dist/assets/mount-BuMSrvSC.js +1 -0
- package/dist/assets/{notification-schedule-field-CyIr-I5n.js → notification-schedule-field-k0bnvNSK.js} +1 -1
- package/dist/assets/{player-overlays-B-iWFodj.js → player-overlays-BUDKTivc.js} +1 -1
- package/dist/assets/remoteEntry-BH9J8bBJ.js +1 -0
- package/dist/assets/{send-CcrlY-kL.js → send-DRuTpqEK.js} +1 -1
- package/dist/assets/{settings-2-DTTOE57Z.js → settings-2-CMX40AAa.js} +1 -1
- package/dist/assets/{square-check-big-Be2zuYRA.js → square-check-big-MqxD69UD.js} +1 -1
- package/dist/assets/src-mM-MIpJ5.js +67 -0
- package/dist/assets/{use-scenes-feed-D3Ym3rpZ.js → use-scenes-feed-DedcyS9k.js} +1 -1
- package/dist/assets/{use-stationary-objects-DU3fanWH.js → use-stationary-objects-DSkTtwR5.js} +1 -1
- package/dist/assets/useEventInvalidation-BuMSrvSC.js +1 -0
- package/dist/assets/{useNodeUrlSelection-CHHUJ1Xd.js → useNodeUrlSelection-DGXiagMl.js} +1 -1
- package/dist/assets/user-round-CTo5V9Lf.js +1 -0
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-D8iKHaJ9.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DHYvAlzF.js} +2 -2
- package/dist/index.html +8 -8
- package/dist/server/addon.js +282 -67
- package/package.json +1 -1
- package/dist/assets/DeviceDetail--ETe_7bv.js +0 -2
- package/dist/assets/MyAccess-NJqkim7o.js +0 -2
- package/dist/assets/Network-Cx0uFr46.js +0 -1
- package/dist/assets/Pipeline-DGhwoZa0.js +0 -1
- package/dist/assets/circle-slash-DC-FdH7L.js +0 -1
- package/dist/assets/client-BomCPWqx.js +0 -357
- package/dist/assets/device-picker-model-CIAVHmGN.js +0 -1
- package/dist/assets/dist-D3d-qpdz.js +0 -357
- package/dist/assets/index-DQbnU8cj.css +0 -2
- package/dist/assets/mount-CIAVHmGN.js +0 -1
- package/dist/assets/remoteEntry-Dfah9M5_.js +0 -1
- package/dist/assets/src-D3Zan8Or.js +0 -67
- package/dist/assets/useEventInvalidation-CIAVHmGN.js +0 -1
- package/dist/assets/user-round-t202JDZh.js +0 -1
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,a,b as o,o as s,q as c,t as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{G as f,U as p,W as m,X as h,_t as g,at as _,lt as v,mt as y,q as b,r as x,st as S,t as C,ut as w,vt as T}from"./player-overlays-B-iWFodj.js";import{$t as E,A as D,As as O,At as k,Bt as A,C as j,Cn as M,Co as N,Cu as P,Dd as F,Du as ee,El as I,Ft as L,G as te,Ga as R,Gi as z,Hd as ne,Hi as re,Hn as B,Ht as ie,Hu as ae,It as V,J as oe,Jt as H,Ki as se,Kt as ce,Li as le,Ls as ue,Lt as de,M as fe,Mi as pe,Mt as me,N as he,Nu as ge,Od as _e,Os as ve,P as ye,Pn as be,Pt as U,Pu as W,Qs as xe,Qt as Se,Ri as Ce,Rt as we,S as Te,Sl as Ee,Su as De,Tl as Oe,To as ke,Tu as Ae,U as G,Ua as je,V as Me,Vi as Ne,W as Pe,Wa as Fe,Wi as Ie,X as Le,Xl as Re,Xt as ze,Z as Be,Zi as Ve,Zt as He,Zu as Ue,_i as We,_u as Ge,a as Ke,an as qe,as as Je,at as Ye,au as Xe,b as Ze,bi as Qe,bl as $e,bn as et,c as tt,ci as nt,cs as rt,dd as it,dt as at,ea as ot,et as st,f as ct,fs as lt,fu as ut,ga as dt,gi as ft,gn as pt,gs as mt,hl as ht,hn as gt,ho as _t,ht as vt,i as yt,id as bt,in as xt,jd as St,js as Ct,jt as wt,kd as Tt,ki as Et,kl as Dt,kn as Ot,kr as kt,ks as At,l as jt,ls as Mt,lt as Nt,md as Pt,mn as Ft,mt as It,mu as Lt,ni as Rt,nn as zt,nt as Bt,o as Vt,oa as Ht,os as Ut,ot as Wt,pa as Gt,pi as Kt,pr as qt,pt as Jt,pu as Yt,q as Xt,qt as Zt,r as Qt,rd as $t,ri as en,rn as tn,s as nn,si as rn,st as an,su as on,u as sn,ut as cn,vn as ln,w as un,wn as dn,wt as fn,wu as pn,x as mn,xi as hn,xt as gn,ya as _n,yd as vn,yi as yn,yn as bn,z as xn,za as Sn,zt as Cn}from"./src-D3Zan8Or.js";import{t as wn}from"./archive-CgE_tiDE.js";import{t as Tn}from"./boxes-Djrey7Kg.js";import{t as En}from"./circle-slash-DC-FdH7L.js";import{n as Dn}from"./NodeInferenceDevices-BOd1WFKM.js";import{t as On}from"./layers-C3hsGCP9.js";import{Bt as kn,Hn as An,Ht as jn,In as Mn,Jt as Nn,Lr as Pn,On as Fn,Qn as K,Rn as In,Rr as Ln,Ut as Rn,Vt as zn,Wn as Bn,Yn as Vn,Yt as Hn,Zn as Un,Zt as Wn,_n as Gn,dr as Kn,fr as qn,gn as Jn,gr as Yn,hr as Xn,mr as Zn,nr as q,rr as J,tr as Qn,vn as $n,zt as er}from"./client-BomCPWqx.js";import{t as Y}from"./useTranslation-Bc5yH9V9.js";import"./mount-CIAVHmGN.js";import{A as tr,C as nr,D as rr,F as ir,I as ar,M as or,N as sr,O as cr,P as lr,R as ur,S as dr,T as fr,d as pr,f as mr,g as hr,h as gr,i as _r,j as vr,k as yr,m as br,n as xr,o as Sr,p as Cr,u as wr,w as Tr}from"./index-CoHcNeUl.js";import{C as Er,D as Dr,E as Or,S as X,_ as kr,a as Ar,b as jr,c as Mr,d as Nr,f as Pr,g as Fr,h as Ir,i as Lr,l as Rr,m as zr,n as Br,o as Vr,p as Hr,r as Ur,s as Wr,t as Gr,u as Kr,v as qr,x as Jr,y as Yr}from"./CompositionEditor-BTXI8CyL.js";import{t as Xr}from"./authed-media-BDiLsx7P.js";import"./useEventInvalidation-CIAVHmGN.js";import{t as Zr}from"./StatusBadge-CeptlsPG.js";import{t as Qr}from"./use-stationary-objects-DU3fanWH.js";import"./device-picker-model-CIAVHmGN.js";var $r=T(`arrow-left-right`,[[`path`,{d:`M8 3 4 7l4 4`,key:`9rb6wj`}],[`path`,{d:`M4 7h16`,key:`6tx8e3`}],[`path`,{d:`m16 21 4-4-4-4`,key:`siv7j2`}],[`path`,{d:`M20 17H4`,key:`h6l3hr`}]]),ei=T(`disc`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]),ti=T(`ear`,[[`path`,{d:`M6 8.5a6.5 6.5 0 1 1 13 0c0 6-6 6-6 10a3.5 3.5 0 1 1-7 0`,key:`1dfaln`}],[`path`,{d:`M15 8.5a2.5 2.5 0 0 0-5 0v1a2 2 0 1 1 0 4`,key:`1qnva7`}]]);n();function ni(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 ri(e){if(typeof e!=`object`||!e)return null;let t=e.switches;if(!Array.isArray(t))return null;let n=t.map(ni).filter(e=>e!==null);return n.length===0?null:n}var ii=[[/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 ai(e){for(let[t,n]of ii)if(t.test(e))return n;return`generic`}function oi(e){let t=e.filter(e=>e.on===!1).map(e=>e.id),n=e.filter(e=>e.on===null).map(e=>e.id),r=t=>t.map(t=>e.find(e=>e.id===t)?.label??t).join(`, `),i=[];return t.length>0&&i.push(`Off: ${r(t)}`),n.length>0&&i.push(`Unknown: ${r(n)}`),{offIds:t,unknownIds:n,summary:i.length===0?`All camera functions on`:i.join(` · `)}}var si={stream:Lt,detection:ur,privacy:y,microphone:w,speaker:Dt,listening:ti,archive:wn,recording:ei,notifications:F,generic:Re};function ci({deviceId:t}){let n=s(),i=Number.isFinite(t),[a,o]=c(null),[l,d]=c(!1),f=Mt({deviceId:t},{enabled:i});Qt([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let p=ri(f.data),m=Ct({onError:(e,r)=>{console.error(`[CameraFunctionSwitches] switch write failed — reverting`,{tags:{deviceId:t},meta:{switchId:r.switchId,error:e instanceof Error?e.message:String(e)}}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSwitches`]]}),o({id:r.switchId,message:e instanceof Error?e.message:String(e)})},onSuccess:()=>{o(null),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),n.invalidateQueries({queryKey:[[`deviceManager`]]}),n.invalidateQueries({queryKey:[[`recording`]]})}}),h=e(e=>{!e.available||e.on===null||m.mutate({deviceId:t,switchId:e.id,enabled:!e.on})},[t,m]);if(p===null)return null;let g=oi(p),_=e=>a?.id===e.id?a.message:null;return r(we,{open:l,onOpenChange:d,children:[r(A,{"aria-label":`Camera functions`,title:g.summary,className:`inline-flex items-center gap-1 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors ${a===null?g.offIds.length>0?`border-warning/40 text-warning hover:bg-warning/10`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`:`border-danger/50 text-danger bg-danger/5`}`,children:[u(Re,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden lg:inline`,children:`Functions`}),g.offIds.length>0&&r(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:[g.offIds.length,` off`]})]}),r(Cn,{className:`left-auto right-0 mt-1 min-w-[240px] max-h-[60vh] overflow-y-auto p-1`,children:[u(`div`,{className:`px-2 py-1 text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Camera functions`}),u(`ul`,{className:`space-y-0.5`,children:p.map(e=>u(`li`,{children:u(li,{row:e,failure:_(e),onToggle:()=>h(e)})},e.id))})]})]})}function li({row:e,failure:t,onToggle:n}){let i=si[ai(e.label)],a=e.on===null,o=e.on===!1,s=t===null?a?e.unavailableReason??`The source that owns this did not answer.`:e.costWhenOff:`Write failed: ${t}`,c=t===null?a?e.unavailableReason??`unknown`:null:`write failed`;return r(`button`,{type:`button`,role:`switch`,"aria-label":e.label,"aria-checked":e.on===!0,disabled:!e.available,onClick:n,title:s,className:`flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-[12px] text-foreground transition-colors hover:bg-surface-hover disabled:opacity-40 disabled:cursor-not-allowed`,children:[u(i,{className:`h-3.5 w-3.5 shrink-0 ${t===null?a?`text-foreground-subtle/50`:o?`text-warning`:`text-success`:`text-danger`}`}),r(`span`,{className:`flex-1 min-w-0 truncate`,children:[e.label,c!==null&&r(`span`,{className:`ml-1 text-[10px] text-foreground-subtle`,children:[`· `,c]})]}),u(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[9px] font-semibold uppercase tracking-wide ${a?`bg-surface-hover text-foreground-subtle/60`:o?`bg-warning/20 text-warning`:`bg-success/20 text-success`}`,children:a?`—`:o?`off`:`on`})]})}function ui({deviceId:e}){let t=Le(_().trpcClient,e);return t===null?null:r(`a`,{href:t.url,target:`_blank`,rel:`noopener noreferrer`,title:`${t.label} — ${t.host}`,className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[u(Ue,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:t.label})]})}function di({parentDeviceId:e}){let{t}=Y(),n=sr(),i=_(),{data:a,isLoading:o,isError:s}=fr(e),{data:c}=Ne({deviceId:e},{enabled:Number.isFinite(e)});if(o)return u(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(s)return u(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let l=(a??[]).filter(e=>e.display?.hidden!==!0);if(l.length===0)return null;let d=te(c?.stableId??``,l,c?.childLayout),f=d.ungrouped,p=e=>n(`/devices/${String(e)}`),m=c?.name??``,h=(e,t)=>u(G,{trpc:i.trpcClient,device:{...t,name:Be(t,m)},variant:`minimal`,onNavigate:p},e),g=f.some(e=>!!e.role),v=f.some(e=>!e.role),y=g&&!v?t(`device.accessories`,{defaultValue:`Accessories`}):!g&&v?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),b=f.length>0?r(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[u(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:y}),u(`div`,{className:`space-y-1`,children:f.map(e=>h(e.id,e))})]}):null,x=d.disabledSection===void 0?null:u(Pe,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:d.disabledSection.children.length,defaultOpen:!1,children:u(`div`,{className:`opacity-60 space-y-1`,children:d.disabledSection.children.map(e=>h(e.id,e))})},d.disabledSection.title);if(d.sections.length===0)return x===null?b:r(`div`,{className:`space-y-2`,children:[b,x]});let S=v&&!g;return r(`div`,{className:`space-y-2`,children:[S?b:null,d.sections.map(e=>u(Pe,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>h(e.id,e))},e.title)),S?null:b,x]})}function fi({deviceId:e}){let t=_(),{data:n,isLoading:r}=Tr(e),{data:i,isLoading:a}=fr(e),o=r||a,s=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),c=typeof n?.linkDeviceId==`number`?n.linkDeviceId:null,l=typeof n?.primaryChildEntityId==`string`?n.primaryChildEntityId:null;return o?u(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):u(`div`,{className:`flex h-full w-full flex-col`,children:u(Ye,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}n();function pi({dev:e,busy:t,setBusy:n}){let i=e?.motionTrigger,a=b(e?.state.motionTrigger),[o,s]=c(!1);if(!i)return null;let l=a?.enabled===!0,d=a!==void 0,f=async()=>{if(t||!d)return;let e=!l;n(!0),s(!0);try{await i.setMotionTrigger({enabled:e})}finally{n(!1),s(!1)}};return r(`button`,{type:`button`,onClick:()=>{f()},disabled:t||!d,title:d?l?`Disable trigger on motion`:`Enable trigger on motion`:`Awaiting state…`,"aria-pressed":l,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${l?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[u(ne,{className:`h-3 w-3`}),u(`span`,{children:o?l?`Disabling…`:`Enabling…`:d?l?`On motion: on`:`On motion: off`:`On motion: …`})]})}n();function Z({deviceId:e,deviceType:t,features:n}){let i=_(),a=Nt(t)?.HeroCard??cn,o=f(i.trpcClient,e),s=b(o?.state.deviceStatus),[l,d]=c(!1),p=s!==void 0&&s.online===!1,m=p?s.lastChangedAt:null;return r(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[p?u(`div`,{className:`flex justify-center`,children:u(an,{lastChangedAt:m})}):null,u(a,{trpc:i.trpcClient,deviceId:e,features:n}),u(`div`,{className:`flex justify-center`,children:u(pi,{dev:o,busy:l,setBusy:d})})]})}function mi({deviceId:e,features:t}){return u(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:u(at,{trpc:_().trpcClient,deviceId:e,features:t})})}function hi({deviceId:e,features:t}){return u(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:u(cn,{trpc:_().trpcClient,deviceId:e,features:t})})}function gi(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function _i(e){if(!e)return null;let t=gi(e.data);return t===null?e.eventType:`Button ${String(t)} · ${e.eventType}`}var vi=1e3,yi=60*vi,bi=60*yi,xi=24*bi;function Si(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<vi?`just now`:n<yi?`${String(Math.floor(n/vi))}s ago`:n<bi?`${String(Math.floor(n/yi))}m ago`:n<xi?`${String(Math.floor(n/bi))}h ago`:`${String(Math.floor(n/xi))}d ago`}n();var Ci=1500,wi=15e3,Ti=1e3;function Ei({deviceId:e}){let n=f(_().trpcClient,e)?.state.eventEmitter,i=b(n);d(()=>{if(!n)return;n.refresh();let e=setInterval(()=>{n.refresh()},wi);return()=>{clearInterval(e)}},[n]);let a=i?.lastEvent??null,o=a?.seq??null,s=t(null),[l,p]=c(!1);d(()=>{if(o===null)return;let e=s.current;if(s.current=o,e===null||e===o)return;p(!0);let t=setTimeout(()=>{p(!1)},Ci);return()=>{clearTimeout(t)}},[o]);let[m,h]=c(()=>Date.now());d(()=>{let e=setInterval(()=>{h(Date.now())},Ti);return()=>{clearInterval(e)}},[]);let g=_i(a),v=i?.eventTypes??[],y=i?.eventCountSinceStart??0,x=i!==void 0,S=gi(a?.data);return r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[u(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(l),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${l?`border-primary bg-primary/20 text-primary shadow-lg shadow-primary/30 scale-105`:`border-border bg-surface text-foreground-subtle`}`,"aria-live":`polite`,title:g??`No press recorded`,children:u(l?pn:ae,{className:`h-10 w-10`})}),r(`div`,{className:`text-center`,children:[S!==null&&u(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:`Button ${String(S)}`}),u(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${g?`text-foreground`:`text-foreground-subtle`}`,children:g??(x?`No press recorded`:`Awaiting state…`)}),u(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:a?Si(a.timestamp,m):`Waiting for the first event`})]}),v.length>0&&u(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:v.map(e=>u(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===a?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),u(`div`,{className:`text-[10px] text-foreground-subtle`,children:`${String(y)} ${y===1?`event`:`events`} since start`})]})}function Di({deviceName:e,deviceType:t,provider:n,isOnline:i,features:a}){return r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[u(tr,{type:n,size:`lg`}),r(`div`,{children:[u(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),u(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),r(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[u(Zr,{status:i?`online`:`offline`}),a.length>0&&u(vr,{capabilities:a})]}),u(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:`No live view for this device type. Use the Config tab or the shortcut row to interact.`})]})}n();function Oi({deviceId:e}){let t=s(),n=ft({deviceId:e},{refetchInterval:1e4,retry:!1}),a=We({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),o=i(()=>ki(n.data??[]),[n.data]);return r(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[r(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[u(Ai,{label:`Discovered`,value:o.total,icon:u(P,{className:`h-3.5 w-3.5`})}),u(Ai,{label:`Adopted`,value:o.adopted,accent:`success`}),u(Ai,{label:`Available`,value:o.available,accent:o.available>0?`primary`:void 0}),r(`button`,{type:`button`,onClick:()=>{a.mutateAsync({deviceId:e}).catch(()=>{})},disabled:a.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[a.isPending?u(ge,{className:`h-3.5 w-3.5 animate-spin`}):u(Yt,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[u(ji,{icon:u(Oe,{className:`h-3 w-3 text-emerald-500`}),label:`${o.online} online`}),u(ji,{icon:u(Ae,{className:`h-3 w-3 text-amber-500`}),label:`${o.sleeping} sleeping`}),u(ji,{icon:u(I,{className:`h-3 w-3 text-destructive`}),label:`${o.offline} offline`}),o.unknown>0?u(ji,{icon:u(it,{className:`h-3 w-3 text-foreground-subtle`}),label:`${o.unknown} unknown`}):null]})]})}function ki(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 Ai({label:e,value:t,icon:n,accent:i}){return r(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${i===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:i===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[r(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,u(`span`,{className:`truncate`,children:e})]}),u(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function ji({icon:e,label:t}){return r(`span`,{className:`inline-flex items-center gap-1`,children:[e,u(`span`,{children:t})]})}var Mi={[J.Switch]:Z,[J.Siren]:Z,[J.Light]:Z,[J.Sensor]:Z,[J.Button]:Z,[J.Hub]:Oi,[J.Cover]:mi,[J.Valve]:Z,[J.Humidifier]:Z,[J.WaterHeater]:Z,[J.Container]:fi,[J.Lock]:Z,[J.Fan]:Z,[J.Thermostat]:Z,[J.Climate]:Z,[J.MediaPlayer]:Z,[J.Control]:Z,[J.AlarmPanel]:Z,[J.EventEmitter]:Ei,[J.Notifier]:hi,[J.Script]:Z,[J.Automation]:Z,[J.Presence]:Z,[J.Update]:Z,[J.Vacuum]:Z,[J.LawnMower]:Z,[J.Weather]:Z,[J.Image]:Z,[J.PetFeeder]:Z};function Ni(e){return Mi[e]??Di}function Pi(e){return u(Ni(e.deviceType),{...e})}function Fi(e){return nn(_().trpcClient,e)}n();function Ii(n){let[r,i]=c(`idle`),[a,o]=c(null),s=t(null),l=t(null),u=t(null),f=t(!0),p=Fe(),m=je(),h=R(),g=e(()=>{if(s.current){try{s.current.close()}catch{}s.current=null}if(l.current){for(let e of l.current.getTracks())try{e.stop()}catch{}l.current=null}u.current=null},[]),_=e(async()=>{if(r===`idle`)return;i(`stopping`);let e=u.current;if(e&&n!==null)try{await Promise.race([h.mutateAsync({deviceId:n,sessionId:e}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}g(),f.current&&(i(`idle`),o(null))},[r,n,h,g]),v=e(async()=>{if(n===null||r!==`idle`&&r!==`error`)return;o(null);let e=null,t=null,a=null;try{i(`requesting-mic`),e=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),l.current=e,i(`starting`);let r=await p.mutateAsync({deviceId:n});a=r.sessionId,u.current=a,i(`connecting`),t=new RTCPeerConnection,s.current=t,t.oniceconnectionstatechange=()=>{if(!f.current)return;let e=t.iceConnectionState;e===`connected`||e===`completed`?i(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&f.current&&(o(e===`failed`?`WebRTC connection failed`:null),_())};for(let n of e.getAudioTracks())t.addTrack(n,e);await t.setRemoteDescription({type:`offer`,sdp:r.sdpOffer});let c=await t.createAnswer();await t.setLocalDescription(c);let d=t.localDescription?.sdp??c.sdp??``;await m.mutateAsync({deviceId:n,sessionId:a,sdpAnswer:d})}catch(r){let c=r instanceof Error?r.message:String(r);if(console.warn(`[intercom] start failed`,r),t)try{t.close()}catch{}if(e)for(let t of e.getTracks())try{t.stop()}catch{}if(s.current=null,l.current=null,a!==null)try{await h.mutateAsync({deviceId:n,sessionId:a})}catch{}u.current=null,f.current&&(o(c),i(`error`))}},[n,r,p,m,h,_]);return d(()=>(f.current=!0,()=>{f.current=!1;let e=u.current;if(e!==null&&n!==null&&h.mutate({deviceId:n,sessionId:e}),s.current){try{s.current.close()}catch{}s.current=null}if(l.current){for(let e of l.current.getTracks())try{e.stop()}catch{}l.current=null}u.current=null}),[n]),{state:r,error:a,start:v,stop:_,isTalking:r===`talking`}}n();var Li=0;function Q(){return++Li}function Ri(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function zi(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 Bi(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 Vi(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 Hi({scope:n,greeting:i,className:a}){let o=_(),[s,f]=c(()=>{let e=[];return i&&e.push({id:Q(),kind:`info`,text:i}),e.push({id:Q(),kind:`info`,text:`scope: ${Ri(n)} — type help or context for available commands`}),e}),[p,m]=c(``),[h,g]=c([]),[v,y]=c(-1),b=t(null),x=t(null);d(()=>{let e=x.current;e&&(e.scrollTop=e.scrollHeight)},[s]);let S=e(()=>{b.current?.focus()},[]),C=l({mutationFn:e=>o.trpcClient.repl.execute.mutate({code:e,scope:n}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;f(e=>[...e,{id:Q(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);f(e=>[...e,{id:Q(),kind:`error`,text:t}])}});function w(e){let t=e.trim();if(t){if(t===`clear`){f([{id:Q(),kind:`info`,text:`scope: ${Ri(n)}`}]),m(``);return}if(t===`help`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...zi(n).map(e=>({id:Q(),kind:`info`,text:e}))]),m(``);return}if(t===`context`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...Vi(n).map(e=>({id:Q(),kind:`info`,text:e}))]),m(``);return}if(t===`examples`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...Bi(n).map(e=>({id:Q(),kind:`info`,text:e}))]),m(``);return}g(e=>[...e,t]),y(-1),f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`}]),m(``),C.mutate(t)}}function T(e){if(e.key===`Enter`){e.preventDefault(),w(p);return}if(e.key===`ArrowUp`){if(e.preventDefault(),h.length===0)return;let t=v===-1?h.length-1:Math.max(0,v-1);y(t),m(h[t]??``);return}if(e.key===`ArrowDown`){if(e.preventDefault(),v===-1)return;let t=v+1;t>=h.length?(y(-1),m(``)):(y(t),m(h[t]??``));return}e.ctrlKey&&e.key===`l`&&(e.preventDefault(),f([{id:Q(),kind:`info`,text:`scope: ${Ri(n)}`}]))}let E={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return r(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${a??``}`,onClick:S,children:[r(`div`,{ref:x,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[s.map(e=>u(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${E[e.kind]}`,children:e.text},e.id)),C.isPending&&u(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),r(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[u(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),u(`input`,{ref:b,value:p,onChange:e=>m(e.target.value),onKeyDown:T,disabled:C.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function Ui(e,t){return e===null?null:{playbackUrl:e.url,...e.format===void 0?{}:{playbackFormat:e.format},playbackAuthToken:t,...e.label===void 0?{}:{playbackLabel:e.label}}}n();function Wi({deviceId:e,intercomAvailable:t=!1}){let n=_(),r=typeof window<`u`?h():``,a=Number.isFinite(e),s=Fi(a?e:null),c=Qr(a?[e]:[]),l=i(()=>{if(!a)return;let e=[];for(let t of c.rows){let n=Vt(t);n!==null&&e.push(n)}return e},[a,c.rows]),{streams:d,pipelineMetrics:f,createSession:p,sendAnswer:g,handleOffer:v,getIceServers:y,addIceCandidate:b,getIceCandidates:S,closeSession:C,getSessionState:w}=Ke(n.trpcClient,a?e:null),T=m(a?e:null,{width:Yi}),E=Ii(a&&t?e:null),D=E.state===`requesting-mic`||E.state===`starting`||E.state===`connecting`||E.state===`stopping`,O=E.isTalking||D,k=()=>{E.state===`idle`||E.state===`error`?E.start():E.state!==`stopping`&&E.stop()},A=x(),j=bn(),M=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,N=Ui(j.request,M),P=A.length>0?u(o,{children:A.map(e=>u(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return u(Te,{serverUrl:r,createSession:p,sendAnswer:g,handleOffer:v,getIceServers:y,addIceCandidate:b,getIceCandidates:S,closeSession:C,getSessionState:w,...N===null?{}:{...N,onExitPlayback:()=>j.clear()},streams:d,pipelineMetrics:f,phase:s.phase,detections:s,...l===void 0?{}:{stationaryObjects:l},defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:T.src,...T.src?{posterUrl:T.src}:{},snapshotLoading:T.loading,onRefreshSnapshot:T.refresh,intercomAvailable:t,intercomShown:O,onIntercomToggle:k,extraOverlay:P,chromeless:!0,className:`h-full`})}function Gi({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full`,children:u(vt,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Ki({deviceId:e}){if(!Number.isFinite(e))return r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let t=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
|
|
2
|
-
`);return u(Hi,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function qi({deviceId:e}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:u(It,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Ji({deviceId:e}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:u(Jt,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}var Yi=960;function Xi(e){return new Set(e.filter(e=>{let t=e.nativeAddonId?.trim()??``;return t!==``&&t!==`composer`}).map(e=>e.capName))}function Zi(e){return e.kind===`known`?null:e}function Qi(e,t){return e.composable.kind===`known`?e.composable.value.has(t)?{kind:`present`,mode:`add`}:{kind:`absent`}:e.composable}function $i(e){if(e.deviceType!==J.Camera)return{kind:`absent`};switch(e.cameraSensors){case`pending`:return{kind:`pending`};case`unknown`:return{kind:`unknown`,reason:`camera sensors could not be checked`};case`absent`:return{kind:`absent`};case`present`:return{kind:`present`,mode:`add`}}}function ea(e,t){if(e===`motion`)return $i(t);let n=Zi(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`}:Qi(t,`doorbell`);case`battery`:return r.has(`battery`)?{kind:`present`,mode:`replace`}:Qi(t,`battery`);case`consumables`:return r.has(`consumables`)?{kind:`absent`}:Qi(t,`consumables`)}}function ta(e){if(e.status===`pending`)return{kind:`pending`};if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??`the request failed`};let t=e.data;if(t===void 0)return{kind:`pending`};if(t.state===`not-loaded`)return{kind:`not-loaded`,reason:t.reason};if(t.view===null)return{kind:`none`};let n=In(t.view.block);return n===null?{kind:`unknown`,reason:`block ${t.view.block.id} is not a composition`}:{kind:`present`,view:t.view,composition:n}}function na(e){return e.kind===`present`?e.composition:null}function ra(e,t){let{hidden:n,...r}=e??{},i=t?{...r,hidden:!0}:r;return Object.keys(i).length===0?null:i}function ia(e){return typeof e.linkDeviceId==`number`}var aa=new Set(Object.values(q));function oa(e){return aa.has(e)}var sa={[J.Switch]:[q.Siren,q.Floodlight,q.Spotlight,q.PirSensor,q.Chime,q.Autotrack,q.Nightvision,q.PrivacyMask,q.BinaryHelper],[J.Light]:[q.Floodlight,q.Spotlight,q.Nightvision],[J.Siren]:[q.Siren],[J.Button]:[q.Doorbell],[J.Sensor]:[q.MotionSensor,q.ContactSensor,q.LeakSensor,q.SmokeSensor,q.COSensor,q.GasSensor,q.TamperSensor,q.VibrationSensor,q.ConnectivitySensor,q.SoundSensor,q.BinarySensor,q.TemperatureSensor,q.HumiditySensor,q.AmbientLightSensor,q.PressureSensor,q.WindSensor,q.RainSensor,q.UvSensor,q.SolarRadiationSensor,q.SoilMoistureSensor,q.PowerSensor,q.EnergySensor,q.VoltageSensor,q.CurrentSensor,q.AirQualitySensor,q.BatterySensor,q.NumericSensor,q.EnumSensor,q.DateTimeSensor,q.GenericSensor],[J.Control]:[q.NumericControl,q.SelectControl,q.TextControl,q.DateTimeControl],[J.Notifier]:[q.MobilePushNotifier,q.MessagingNotifier,q.EmailNotifier,q.GenericNotifier]};function ca(e){for(let t of Object.values(J))if(t===e)return!0;return!1}function la(e){return ca(e)?sa[e]??[]:[]}function ua(e,t){let n=la(t);return e==null||e===``||n.includes(e)?n:[...n,e]}n();var da=`w-full min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`;function fa({device:e}){let{t}=Y(),n=s(),[i,a]=c(null),o=()=>a(null),l={onSuccess:()=>{o(),n.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>a(e.message)},d=Gt(),f=Ht(),p=e.display?.hidden===!0;return r(`section`,{"aria-label":t(`customize.identity.title`),className:`rounded-lg border border-border bg-surface p-2 sm:p-4`,children:[r(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[u(cr,{deviceId:e.id,initialName:e.name,label:t(`customize.identity.name`),layout:`stacked`,onError:a,onSaved:o,onCancel:o}),u(rr,{deviceId:e.id,initialLocation:e.location,label:t(`customize.identity.room`),layout:`stacked`,onError:a,onSaved:o,onCancel:o}),u(yr,{label:t(`customize.identity.hidden`),layout:`stacked`,value:u(`input`,{type:`checkbox`,"aria-label":t(`deviceDisplay.hideFromLists`),checked:p,disabled:f.isPending,onChange:t=>f.mutate({deviceId:e.id,display:ra(e.display,t.target.checked)},l)})}),u(yr,{label:t(`customize.identity.role`),layout:`stacked`,value:ia(e)?u(`span`,{children:pa(e.role,t(`customize.identity.noRole`))}):r(`select`,{"aria-label":t(`customize.identity.role`),className:da,value:e.role??``,disabled:d.isPending,onChange:t=>d.mutate({deviceId:e.id,role:t.target.value===``?null:t.target.value},l),children:[u(`option`,{value:``,children:t(`customize.identity.noRole`)}),ua(e.role,e.type).map(e=>u(`option`,{value:e,children:pa(e,t(`customize.identity.noRole`))},e))]})})]}),i!==null&&u(`p`,{role:`alert`,className:`mt-2 text-xs text-danger break-words`,children:i})]})}function pa(e,t){return e==null||e===``?t:oa(e)?st(e).label:e}function ma({onAdvanced:e}){let{t}=Y();return e===void 0?null:u(`button`,{type:`button`,className:`min-h-11 text-left text-primary underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,onClick:e,children:t(`customize.advancedLink`)})}n();function ha(e){return e===`pending`?`pending`:e===`error`?`failed`:`answered`}function ga({excludeDeviceIds:e,onSelect:t}){let{t:n}=Y(),r=z({projection:`slim`}),a=r.status===`success`?r.data:null,o=i(()=>{if(a===null)return[];let t=new Set(e);return Mr(a).filter(e=>!t.has(e.id))},[a,e]),s=i(()=>new Map(o.map(e=>[e.id,e])),[o]),c=i(()=>o.map(e=>({id:e.id,name:e.name,type:e.type,...e.location===null?{}:{location:e.location}})),[o]);return r.status===`error`?u(et,{title:n(`customize.picker.devicesFailed`),message:r.error?.message??``}):u(ct,{devices:c,listState:ha(r.status),value:[],onChange:e=>{let n=e.at(-1);if(n===void 0)return;let r=s.get(n);r!==void 0&&t(r)},noun:`device`,emptyLabel:n(`customize.assign.none`),showAll:!0,testId:`customize-field-device-picker`})}function _a({open:e,title:t,targetKind:n,excludeDeviceIds:i,confirmLabel:a,extra:s,extraComplete:l=!0,onConfirm:d,onClose:f}){let{t:p}=Y(),[m,h]=c(null),[g,_]=c(null),v=()=>{h(null),_(null),f()};return u(ce,{open:e,onOpenChange:e=>e?void 0:v(),children:r(H,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":t,children:[u(He,{children:u(Se,{children:t})}),u(Zt,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:e&&r(o,{children:[r(`section`,{"aria-label":p(`customize.assign.stepDevice`),className:`flex flex-col gap-1`,children:[u(`h3`,{className:`text-xs font-semibold`,children:p(`customize.assign.stepDevice`)}),m===null?u(ga,{excludeDeviceIds:i,onSelect:h}):r(`p`,{className:`flex items-center gap-2 text-sm`,children:[m.name,u(M,{variant:`ghost`,size:`sm`,onClick:()=>{h(null),_(null)},children:p(`customize.assign.change`)})]})]}),m!==null&&r(`section`,{"aria-label":p(`customize.assign.stepField`),className:`flex flex-col gap-1`,children:[u(`h3`,{className:`text-xs font-semibold`,children:p(`customize.assign.stepField`)}),u(Ar,{device:m,targetKind:n,selected:g===null?null:{cap:g.cap,path:g.path},onPick:_,onBack:()=>{h(null),_(null)}})]}),m!==null&&s!==void 0&&r(`section`,{"aria-label":p(`customize.assign.stepDetails`),className:`flex flex-col gap-1`,children:[u(`h3`,{className:`text-xs font-semibold`,children:p(`customize.assign.stepDetails`)}),s]})]})}),r(ze,{children:[u(M,{variant:`ghost`,onClick:v,children:p(`customize.assign.cancel`)}),u(M,{disabled:g===null||!l,onClick:()=>{g!==null&&(d(g),h(null),_(null))},children:a})]})]})})}function va(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ya(e,t){let n=Wr(e,t);return n===void 0?{kind:`absent`}:{kind:`value`,value:n}}function ba(e,t,n){return va(t)?ya(t,n):e.status===`error`?{kind:`unknown`,reason:e.error?.message??`the value could not be read`}:e.status===`pending`||e.data===void 0?{kind:`pending`}:e.data===null?{kind:`absent`}:ya(e.data,n)}function xa(e,t,n){let r=e?`active`:`muted`;return t.cap===`contact`&&t.path===`entryOpen`?{text:e?n.open:n.closed,tone:r}:qn[t.cap]===t.path?{text:e?n.active:n.inactive,tone:r}:{text:String(e),tone:`normal`}}function Sa(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`?xa(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 Ca=0;function wa(e){let t=_(),n=_n({deviceId:e?.deviceId??Ca,capName:e?.cap??``},{enabled:e!==null}),r=tt(t.trpcClient,e?.deviceId??null,e?.cap??``);return e===null?{kind:`absent`}:ba({status:n.status,data:n.data,error:n.error===null||n.error===void 0?null:{message:n.error.message}},r,e.path)}var Ta={muted:`text-foreground-subtle`,active:`text-success`,normal:`text-foreground`,warning:`text-warning`};function Ea({target:e}){let{t}=Y(),n=wa(e);return e===null?null:u(Da,{display:Sa(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 Da({display:e}){return u(`span`,{className:`text-xs ${Ta[e.tone]}`,title:e.title,children:e.text})}function $({name:e,detail:t,meta:n,value:i,shown:a,problem:o,onRemove:s,removeLabel:c,busy:l=!1}){return r(`li`,{className:`grid grid-cols-[minmax(0,1fr)_44px] gap-x-3 gap-y-1 items-center px-2 py-2 sm:px-4 sm:grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,1fr)_44px]`,children:[r(`div`,{className:`min-w-0`,children:[u(`div`,{className:`text-sm break-words`,children:e}),t!==null&&u(`div`,{className:`text-xs text-foreground-subtle break-words`,children:t}),o!==void 0&&u(`div`,{role:`alert`,className:`text-xs text-warning break-words`,children:o})]}),u(`div`,{className:`row-start-2 col-start-1 text-xs text-foreground-subtle empty:hidden sm:row-start-auto sm:col-start-auto sm:empty:block`,children:n}),u(`div`,{className:`row-start-3 col-start-1 empty:hidden sm:row-start-auto sm:col-start-auto sm:empty:block`,children:a===void 0?u(Ea,{target:i}):a!==null&&u(Da,{display:a})}),u(`div`,{className:`row-start-1 col-start-2 sm:row-start-auto sm:col-start-auto`,children:s!==void 0&&u(`button`,{type:`button`,"aria-label":c,disabled:l,className:`h-11 w-11 flex items-center justify-center rounded text-foreground-subtle hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:opacity-50 disabled:cursor-not-allowed`,onClick:s,children:u(Ee,{className:`h-4 w-4`})})})]})}function Oa({id:e,icon:t,title:n,headerControl:i,addLabel:a,onAdd:o,addDisabled:s=!1,notices:c,children:l}){return r(`section`,{"aria-labelledby":`customize-${e}`,className:`rounded-lg border border-border bg-surface`,children:[r(`header`,{className:`flex flex-wrap items-center gap-2 border-b border-border px-2 py-2 sm:px-4`,children:[t,u(`h2`,{id:`customize-${e}`,className:`flex-1 text-sm font-semibold`,children:n}),i,o!==void 0&&a!==void 0&&u(M,{variant:`outline`,size:`sm`,disabled:s,onClick:o,children:a})]}),c!==void 0&&u(`div`,{className:`flex flex-col gap-1 px-2 pt-2 empty:hidden sm:px-4`,children:c}),u(`ul`,{className:`flex flex-col divide-y divide-border`,children:l})]})}function ka({availability:e}){let{t}=Y();return e.kind===`pending`?u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.assign.checking`)}):e.kind===`unknown`?u(`p`,{role:`alert`,className:`text-xs text-warning`,children:t(`customize.assign.unknown`,{reason:e.reason})}):null}function Aa(e,t){if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??`the request failed`};let n=e.data;return e.status===`pending`||n===void 0?{kind:`pending`}:{kind:`known`,value:t(n)}}var ja=[{id:`motion`,labelKey:`customize.assign.filters.motion`,caps:[`motion`]},{id:`contact`,labelKey:`customize.assign.filters.contact`,caps:[`contact`]},{id:`all`,labelKey:`customize.assign.filters.all`,caps:Kn}];function Ma(e,t){return t!==null&&e.includes(t)?t:Kn.find(t=>e.includes(t))??null}function Na(e,t){let n=[e,t].filter(e=>e!==null&&e!==``);return n.length===0?null:n.join(` · `)}function Pa(e,t){if(e.id===t.hostId||e.type===J.Container||t.excludeCameras&&e.isCamera)return!1;let n=K({addonId:e.addonId,stableId:e.stableId});return!t.assigned.has(n)}function Fa(e){return e.devices.flatMap(t=>{if(!Pa(t,e))return[];let n=e.capIndex.get(t.id)??[],r=Ma(n,e.preferredCap);if(r===null)return[];let i=qn[r];return[{deviceId:t.id,ref:{addonId:t.addonId,stableId:t.stableId},name:t.name,detail:Na(t.integration,t.location),meta:r,caps:n,value:i===void 0?null:{deviceId:t.id,cap:r,path:i}}]}).toSorted((e,t)=>e.name.localeCompare(t.name))}function Ia(e,t,n){let r=Ze(t);return e.filter(e=>{if(n!==null&&!e.caps.some(e=>n.caps.includes(e)))return!1;if(r.length===0)return!0;let t=mn({id:e.deviceId,name:e.name,...e.detail===null?{}:{detail:e.detail},...e.meta===null?{}:{type:e.meta}});return r.every(e=>t.includes(e))})}function La(e){let t=e.find(e=>e.query.status===`error`);if(t!==void 0)return{kind:`unknown`,reason:t.query.error?.message??`the request failed`};if(e.some(e=>e.query.status!==`success`||e.query.data===void 0))return{kind:`pending`};let n=new Map;for(let t of e)for(let e of t.query.data??[])n.set(e,[...n.get(e)??[],t.cap]);return{kind:`known`,value:n}}function Ra(e,t){let n=$e.useQueries(n=>e.map(e=>n.deviceManager.listDeviceIdsByCaps({capNames:[e]},{enabled:t})));return La(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}}}}))}n();function za(e,t){let n=Me(e,t);return n.kind===`resolved`?n.integration.name:null}function Ba(e){let t=z({projection:`slim`},{enabled:e}),{data:n}=Sn(void 0,{enabled:e}),r=t.error===null||t.error===void 0?null:t.error.message;return i(()=>Aa({status:t.status,data:t.data,error:r===null?null:{message:r}},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:za(e,n)}))),[t.status,t.data,r,n])}function Va(e){let t=Ba(e.enabled),n=Ra(Kn,e.enabled);return t.kind===`unknown`?t:n.kind===`unknown`?n:t.kind===`pending`||n.kind===`pending`?{kind:`pending`}:{kind:`known`,value:Fa({devices:t.value,capIndex:n.value,hostId:e.hostId,excludeCameras:e.excludeCameras,assigned:e.assigned,preferredCap:e.preferredCap})}}function Ha(){let{t:e}=Y(),t=be();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`})}n();function Ua(e){return e===null?null:Ir(e,`replace`)?`replace`:Ir(e,`add`)?`add`:null}function Wa({device:e,handle:t,availability:n,onAdvanced:i}){let{t:a}=Y(),s=Ha(),[l,d]=c(!1),[f,p]=c(null),m=na(t.state),h=Yr(m,`battery`),g=Ua(h),_=g===null?null:kr(h?.fields.percentage),v=Ba(_!==null);if(n.kind===`absent`)return null;let y=n.kind===`present`?n.mode:null,b=t.state.kind===`none`||t.state.kind===`present`,x=_===null||v.kind!==`known`?null:v.value.find(e=>K({addonId:e.addonId,stableId:e.stableId})===K(_.source))??null,S=_===null?``:x?.name??K(_.source),C=async e=>{let n=await t.save(e);p(n.kind===`refused`?n.reason:null)},w=async()=>{if(m===null)return;let e=Er(m,`battery`);await s(a(`customize.battery.removeWhat`,{name:S}),e===null)&&await C(e)},T=y!==null&&b&&h===null&&!t.saving;return r(o,{children:[r(Oa,{id:`battery`,icon:u(St,{className:`h-4 w-4 text-foreground-subtle`}),title:a(`customize.battery.title`),addLabel:a(y===`replace`?`customize.battery.replace`:`customize.battery.add`),onAdd:T?()=>d(!0):void 0,notices:r(o,{children:[u(ka,{availability:n}),_!==null&&v.kind===`unknown`&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.assign.devicesUnreadable`,{reason:v.reason})}),f!==null&&u(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:f})]}),children:[y===`replace`&&b&&u($,{name:a(`customize.battery.native`),detail:null,meta:a(h===null?`customize.assign.native`:`customize.battery.nativeReplaced`),value:h===null?{deviceId:e.id,cap:`battery`,path:`percentage`}:null,removeLabel:``}),h===null&&y===`add`&&b&&u(`li`,{className:`px-2 py-2 text-xs text-foreground-subtle sm:px-4`,children:a(`customize.assign.none`)}),_!==null&&u($,{name:S,detail:`${_.cap}.${_.fieldPath}`,meta:a(g===`replace`?`customize.assign.replaces`:`customize.assign.adds`),value:x===null?null:{deviceId:x.id,cap:_.cap,path:_.fieldPath},problem:x===null&&v.kind===`known`?a(`customize.assign.missingKept`):void 0,onRemove:b?()=>void w():void 0,removeLabel:a(`customize.assign.removeNamed`,{name:S}),busy:t.saving}),h!==null&&_===null&&u($,{name:a(`customize.battery.otherFormula`),detail:null,meta:u(ma,{onAdvanced:i}),value:{deviceId:e.id,cap:`battery`,path:`percentage`},removeLabel:``})]}),u(_a,{open:l,title:a(y===`replace`?`customize.battery.replace`:`customize.battery.add`),targetKind:`number`,excludeDeviceIds:[e.id],confirmLabel:a(`customize.assign.add`),onConfirm:e=>{d(!1);let n=y===null?null:Kr({percentage:{source:e.ref,cap:e.cap,fieldPath:e.path,kind:e.kind},mode:y});n===null?p(a(`customize.assign.pickUnusable`)):C(X(m,t.target,n))},onClose:()=>d(!1)})]})}n();function Ga(e,t){let n=e.source;if(n===null||t.kind!==`known`)return null;let r=K(n.source);return t.value.find(e=>K({addonId:e.addonId,stableId:e.stableId})===r)??null}function Ka(e){let t=typeof e==`number`?e:typeof e==`string`?Number(e):NaN;return Number.isFinite(t)?t:null}function qa({device:e,handle:t,availability:n,onAdvanced:i}){let{t:a}=Y(),s=Ha(),[l,d]=c(!1),[f,p]=c(``),[m,h]=c(`percent`),[g,_]=c(null),v=na(t.state),y=Yr(v,`consumables`),b=Pr(y),x=Ba(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=Fr(f),T=b.find(e=>e.key===w)??null,E=T!==null,D=f.trim()!==``&&w===``,O=async e=>{let n=await t.save(e);_(n.kind===`refused`?n.reason:null)},k=()=>{d(!1),p(``),h(`percent`)},A=async e=>{if(y===null||v===null)return;let n=qr(y,e.key),r=n===null?Er(v,`consumables`):X(v,t.target,n);await s(a(`customize.consumables.removeWhat`,{name:e.label}),r===null)&&await O(r)},j=r(`div`,{className:`flex flex-wrap items-end gap-2`,children:[r(`label`,{className:`flex w-full flex-col gap-1 text-xs sm:w-56`,children:[a(`customize.consumables.name`),u(`input`,{"aria-label":a(`customize.consumables.name`),className:`px-2 py-1 text-sm bg-background border border-border rounded`,value:f,onChange:e=>p(e.target.value)})]}),r(`label`,{className:`flex flex-col gap-1 text-xs`,children:[a(`customize.consumables.unit`),u(`select`,{"aria-label":a(`customize.consumables.unit`),className:`px-2 py-1 text-sm bg-background border border-border rounded`,value:m,onChange:e=>{let t=Rr.find(t=>t===e.target.value);t!==void 0&&h(t)},children:Rr.map(e=>u(`option`,{value:e,children:a(`customize.consumables.units.${e}`)},e))})]}),E&&u(`p`,{role:`alert`,className:`basis-full text-xs text-warning`,children:a(`customize.consumables.takenBy`,{name:T.label})}),D&&u(`p`,{role:`alert`,className:`basis-full text-xs text-warning`,children:a(`customize.consumables.keyless`)})]});return r(o,{children:[r(Oa,{id:`consumables`,icon:u(De,{className:`h-4 w-4 text-foreground-subtle`}),title:a(`customize.consumables.title`),addLabel:a(`customize.consumables.add`),onAdd:C?()=>d(!0):void 0,notices:r(o,{children:[u(ka,{availability:n}),x.kind===`unknown`&&b.some(e=>e.source!==null)&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.assign.devicesUnreadable`,{reason:x.reason})}),g!==null&&u(`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 u($,{name:e.label,detail:a(`customize.consumables.otherFormula`),meta:u(ma,{onAdvanced:i}),value:null,removeLabel:``},e.key);let r=Ga(e,x),o=r?.name??K(n.source);return u($,{name:e.label,detail:`${a(`customize.consumables.units.${e.unit}`)} · ${o}`,meta:`${n.cap}.${n.fieldPath}`,value:r===null?null:{deviceId:r.id,cap:n.cap,path:n.fieldPath},problem:r===null&&x.kind===`known`?a(`customize.assign.missingKept`):void 0,onRemove:S?()=>void A(e):void 0,removeLabel:a(`customize.assign.removeNamed`,{name:e.label}),busy:t.saving},e.key)}),b.length===0&&n.kind===`present`&&S&&u(`li`,{className:`px-2 py-2 text-xs text-foreground-subtle sm:px-4`,children:a(`customize.assign.none`)})]}),u(_a,{open:l,title:a(`customize.consumables.pickTitle`),targetKind:`number`,excludeDeviceIds:[e.id],confirmLabel:a(`customize.assign.add`),extra:j,extraComplete:w!==``&&!E,onConfirm:e=>{let n=Ka(e.value);if(n!==null&&(n<0||m===`percent`&&n>100)){k(),_(a(`customize.consumables.outOfRange`,{value:n}));return}let r=Nr(y,{key:w,label:f,remaining:{source:e.ref,cap:e.cap,fieldPath:e.path,kind:e.kind},unit:m});k(),r===null?_(a(`customize.assign.pickUnusable`)):O(X(v,t.target,r))},onClose:k})]})}n();function Ja(e){return e.kind===`pending`?`pending`:e.kind===`unknown`?`failed`:`answered`}function Ya(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 Xa({open:e,title:t,selection:n,candidates:a,filters:o,confirmLabel:s,onConfirm:l,onClose:f}){let{t:p}=Y(),[m,h]=c(null),[g,_]=c([]),v=o?.find(e=>e.id===m)??o?.[0]??null,y=a.kind===`known`?a.value:[],b=a.kind===`known`?Ia(a.value,``,v):[],x=i(()=>Ya(b),[b]),S=Ja(a),C=y.filter(e=>g.includes(e.deviceId));d(()=>{e||(_([]),h(null))},[e]);let w=()=>{_([]),h(null),f()};return u(ce,{open:e,onOpenChange:e=>e?void 0:w(),children:r(H,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":t,children:[u(He,{children:u(Se,{children:t})}),r(Zt,{className:`flex flex-col gap-2 p-2 sm:p-4`,children:[o!==void 0&&o.length>0&&u(`div`,{className:`flex flex-wrap gap-1`,role:`tablist`,"aria-label":p(`customize.assign.filtersLabel`),children:o.map(e=>u(`button`,{type:`button`,role:`tab`,"aria-selected":(v?.id??null)===e.id,className:`rounded-md border px-2 py-1 text-xs ${(v?.id??null)===e.id?`border-foreground bg-surface-hover`:`border-border text-foreground-subtle`}`,onClick:()=>h(e.id),children:p(e.labelKey)},e.id))}),a.kind===`unknown`?u(`p`,{role:`alert`,className:`text-xs text-warning`,children:p(`customize.assign.unknown`,{reason:a.reason})}):u(ct,{devices:x,listState:S,value:g,onChange:e=>_(n===`single`?e.length>0?[e[e.length-1]]:[]:e),noun:`device`,emptyLabel:p(`customize.assign.none`),showAll:!0,testId:`customize-device-picker`})]}),r(ze,{children:[u(M,{variant:`ghost`,onClick:w,children:p(`customize.picker.cancel`)}),u(M,{disabled:C.length===0,onClick:()=>{C.length!==0&&(l(C),_([]),h(null))},children:s(C.length)})]})]})})}function Za(e){if(e===null)return[];let t=zr(e);return Hr(e).map(e=>{let n=K(e);return{key:n,ref:e,caps:t.filter(e=>K(e.source)===n).map(e=>e.cap)}})}function Qa(e,t){let n=zr(e);if(n.length===0)return!1;let{enabled:r,...i}=e,{enabled:a,...o}=jn({camera:t,sources:n,enabled:!0});return Jr(i,o)}function $a(e){return e?.enabled!==!1}function eo(e,t,n){let r=[...e===null?[]:zr(e),...n.flatMap(e=>Rn(e.ref,e.caps))];return r.length===0?null:jn({camera:t,sources:r,enabled:$a(e)})}function to(e,t,n){let r=zr(e).filter(e=>K(e.source)!==n);return r.length===0?null:jn({camera:t,sources:r,enabled:$a(e)})}function no(e,t){return{...e,enabled:t}}n();function ro({device:e,handle:t,availability:n,onAdvanced:i}){let{t:a}=Y(),s=Ha(),[l,d]=c(!1),[f,p]=c(null),m=na(t.state),h=Yr(m,`doorbell`),g=h===null||Qa(h,t.target),_=g?Za(h):[],v=Ba(_.length>0),y=Va({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:Er(m,`doorbell`):X(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=to(h,t.target,e.key),i=r===null&&Er(m,`doorbell`)===null;await s(a(`customize.doorbell.removeWhat`,{name:n}),i)&&await C(r)},T=e=>v.kind===`known`?v.value.find(t=>K({addonId:t.addonId,stableId:t.stableId})===e.key)??null:null;return r(o,{children:[r(Oa,{id:`doorbell`,icon:u(_e,{className:`h-4 w-4 text-foreground-subtle`}),title:a(`customize.doorbell.title`),headerControl:h===null?void 0:r(`label`,{className:`flex min-h-11 items-center gap-1 text-xs`,children:[u(`input`,{type:`checkbox`,"aria-label":a(`customize.doorbell.active`),checked:h.enabled!==!1,disabled:!x,onChange:e=>void C(no(h,e.target.checked))}),a(`customize.doorbell.active`)]}),addLabel:a(`customize.doorbell.add`),onAdd:S?()=>d(!0):void 0,notices:r(o,{children:[u(ka,{availability:n}),v.kind===`unknown`&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.assign.devicesUnreadable`,{reason:v.reason})}),f!==null&&u(`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=Ma(e.caps,null),o=i===null?void 0:qn[i];return u($,{name:r,detail:n===null?null:Na(n.integration,n.location),meta:e.caps.join(`, `),value:n!==null&&i!==null&&o!==void 0?{deviceId:n.id,cap:i,path:o}:null,problem:n===null&&v.kind===`known`?a(`customize.assign.missingKept`):void 0,onRemove:b?()=>void w(e,r):void 0,removeLabel:a(`customize.assign.removeNamed`,{name:r}),busy:t.saving},e.key)}),!g&&u($,{name:a(`customize.doorbell.otherFormula`),detail:null,meta:u(ma,{onAdvanced:i}),value:null,removeLabel:``}),h===null&&n.kind===`present`&&b&&u(`li`,{className:`px-2 py-2 text-xs text-foreground-subtle sm:px-4`,children:a(`customize.assign.none`)})]}),u(Xa,{open:l,title:a(`customize.doorbell.pickTitle`),selection:`multi`,candidates:y,confirmLabel:e=>a(`customize.assign.addCount`,{count:e}),onConfirm:e=>{d(!1),C(eo(h,t.target,e.map(e=>({ref:e.ref,caps:e.caps}))))},onClose:()=>d(!1)})]})}function io(e){return e.slot===`linked-devices`}function ao(e){if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??`the request failed`};if(e.status===`pending`||e.data===void 0)return{kind:`pending`};for(let t of e.data)if(t.state===`ok`&&t.slot===`linked-devices`&&io(t.value))return{kind:`present`,slot:t,value:t.value};let t=e.data.find(e=>e.state===`unreachable`);return t!==void 0&&t.state===`unreachable`?{kind:`unknown`,reason:t.reason}:{kind:`absent`}}function oo(e,t){let n=t.trackedDeviceIds??[],r=e=>t=>({deviceId:t.deviceId,name:t.name,health:t.health,implied:e,tracked:n.includes(t.deviceId)});return[...e.sources.map(r(!1)),...(e.impliedSources??[]).map(r(!0))]}function so(e,t){let n=new Set([...e.sources,...e.impliedSources??[]].map(e=>e.deviceId));return(t.trackedDeviceIds??[]).filter(e=>!n.has(e))}function co(e,t){return{...e,deviceIds:[...e.deviceIds,...t.filter(t=>!e.deviceIds.includes(t))]}}function lo(e,t){return{...e,deviceIds:e.deviceIds.filter(e=>e!==t),...e.trackedDeviceIds===void 0?{}:{trackedDeviceIds:e.trackedDeviceIds.filter(e=>e!==t)}}}function uo(e,t,n){let r=e.trackedDeviceIds??[],i=n?[...r.filter(e=>e!==t),t]:r.filter(e=>e!==t);return{...e,trackedDeviceIds:i}}function fo(e,t,n){return e.flatMap(e=>{let r=t.get(e.deviceId);return n.has(e.deviceId)||r===void 0?[]:[{deviceId:e.deviceId,ref:{addonId:r.addonId,stableId:r.stableId},name:e.parentName===null?e.name:`${e.parentName} · ${e.name}`,detail:Na(r.integration,e.location),meta:e.type,caps:[],value:null}]})}n();function po(e){return e==null?null:e.message}function mo({device:e}){let{t}=Y(),n=s(),i=Ha(),a=Fn.includes(e.type),[l,d]=c(!1),[f,p]=c(!1),[m,h]=c(null),g=Qe({deviceId:e.id},{enabled:a}),_=ao({status:g.status,data:g.data,error:po(g.error)===null?null:{message:po(g.error)??``}}),v=_.kind===`present`?_.slot.slotRef:``,y=_.kind===`present`?[...oo(_.slot,_.value).map(e=>e.deviceId),...so(_.slot,_.value)]:[],b=hn(),x=Ba(a&&_.kind===`present`&&(l||y.length>0)),S=yn({deviceId:e.id,slotRef:v},{enabled:l&&_.kind===`present`});if(!a||_.kind===`absent`)return null;if(_.kind!==`present`)return u(Oa,{id:`linked`,icon:u(W,{className:`h-4 w-4 text-foreground-subtle`}),title:t(`customize.linked.title`),notices:_.kind===`pending`?u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.assign.checking`)}):u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:t(`customize.assign.unknown`,{reason:_.reason})}),children:null});let C=_.value,w=new Map(x.kind===`known`?x.value.map(e=>[e.id,e]):[]),T=C.trackedDeviceIds!==void 0,D=(e,t)=>{let n=w.get(e.deviceId);return{...e,name:e.name??n?.name??null,type:n?.type??null,detail:n===void 0?null:Na(n.integration,n.location),orphan:t}},O=[...oo(_.slot,C).map(e=>D(e,!1)),...so(_.slot,C).map(e=>D({deviceId:e,name:null,health:`ok`,implied:!1,tracked:!0},!0))],k=new Set(y),A=x.kind===`unknown`?x:S.status===`error`?{kind:`unknown`,reason:po(S.error)??`the request failed`}:x.kind===`pending`||S.status===`pending`||S.data===void 0?{kind:`pending`}:{kind:`known`,value:fo(S.data.candidates,w,k)},j=async r=>{if(f){h(t(`customize.saveInFlight`));return}p(!0),h(null);try{await b.mutateAsync({deviceId:e.id,slotRef:_.slot.slotRef,value:r}),await g.refetch(),await n.invalidateQueries({queryKey:[[`deviceManager`]]})}catch(e){h(e instanceof Error?e.message:String(e))}finally{p(!1)}},M=async e=>{await i(t(`customize.linked.removeWhat`,{name:e.name??`#${e.deviceId}`}),!1)&&await j(lo(C,e.deviceId))},N=[{key:`device`,header:t(`customize.linked.device`),cell:e=>r(`div`,{className:`flex flex-col min-w-0`,children:[u(`span`,{className:`truncate text-sm`,children:e.name??`#${e.deviceId}`}),e.detail!==null&&u(`span`,{className:`truncate text-xs text-foreground-subtle`,children:e.detail}),e.orphan&&u(`span`,{className:`text-xs text-foreground-subtle`,children:t(`customize.linked.notLinked`)}),e.health!==`ok`&&u(`span`,{role:`alert`,className:`text-xs text-warning`,children:t(`customize.linked.health.${e.health}`)})]})},{key:`type`,header:t(`customize.linked.type`),headerClassName:`hidden sm:table-cell`,cellClassName:`hidden sm:table-cell text-xs text-foreground-subtle`,cell:e=>e.type===null?`—`:Bt(e.type).label},{key:`controls`,header:t(`customize.linked.controls`),headerClassName:`hidden md:table-cell`,cellClassName:`hidden md:table-cell text-xs text-foreground-subtle`,cell:e=>e.orphan?`—`:t(`customize.linked.yes`)},...T?[{key:`tracked`,header:t(`customize.linked.tracked`),cellClassName:`text-right`,headerClassName:`text-right`,cell:e=>u(E,{checked:e.tracked,disabled:f,"aria-label":t(`customize.linked.trackFor`,{name:e.name??e.deviceId}),onCheckedChange:t=>void j(uo(C,e.deviceId,t))})}]:[],{key:`remove`,header:``,cellClassName:`text-right w-12`,cell:e=>e.implied||e.orphan?null:u(`button`,{type:`button`,"aria-label":t(`customize.assign.removeNamed`,{name:e.name??e.deviceId}),className:`h-11 w-11 inline-flex items-center justify-center text-foreground-subtle hover:text-foreground disabled:opacity-50`,disabled:f,onClick:t=>{t.stopPropagation(),M(e)},children:u(Ee,{className:`h-4 w-4`})})}];return r(o,{children:[u(Oa,{id:`linked`,icon:u(W,{className:`h-4 w-4 text-foreground-subtle`}),title:t(`customize.linked.title`),addLabel:t(`customize.linked.add`),onAdd:f?void 0:()=>d(!0),notices:r(o,{children:[x.kind===`unknown`&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:t(`customize.assign.devicesUnreadable`,{reason:x.reason})}),m!==null&&u(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:m})]}),children:r(`li`,{className:`list-none px-2 sm:px-4`,children:[O.length===0?u(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:t(`customize.assign.none`)}):u(xn,{mode:`generic`,items:O,getKey:e=>String(e.deviceId),getSearchText:e=>[e.name??``,e.detail??``,e.type??``,String(e.deviceId)].join(` `),getFilterType:e=>e.type===null?null:Bt(e.type).label,columns:N,searchPlaceholder:t(`customize.assign.search`),emptyLabel:t(`customize.assign.none`)}),O.some(e=>!e.orphan)&&u(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:t(`customize.linked.controlsAlways`)}),T&&u(`p`,{className:`pb-2 text-xs text-foreground-subtle`,children:t(`customize.linked.trackedHint`)})]})}),u(Xa,{open:l,title:t(`customize.linked.pickTitle`),selection:`multi`,candidates:A,confirmLabel:e=>t(`customize.assign.addCount`,{count:e}),onConfirm:e=>{d(!1),j(co(C,e.map(e=>e.deviceId)))},onClose:()=>d(!1)})]})}function ho(e){return e===null||e.state===`unreadable`?null:e.state===`configured`?e.sensors:[]}function go(e){return{addonId:e.addonId,stableId:e.stableId,mode:e.mode}}function _o(e){return e.length===0?null:{sensors:[...e]}}function vo(e,t){let n=new Set(e.map($n));return _o([...e.map(go),...t.filter(e=>!n.has($n(e))).map(e=>({...e,mode:Gn}))])}function yo(e,t,n){return _o(e.map(e=>$n(e)===t?{...go(e),mode:n}:go(e)))}function bo(e,t){return _o(e.filter(e=>$n(e)!==t).map(go))}function xo(e){return e?.state===`configured`&&e.cameraMotion!==void 0}function So(e){return e===null||e.state===`unreadable`?null:e.state===`configured`?e.cameraMotion??`always`:`always`}function Co(e){return e===null||e.state===`unreadable`?!1:e.state===`not-configured`||xo(e)}function wo(e){return e?.state===`configured`&&(e.notForwarded!==void 0||e.notEnforced!==void 0)}function To(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}}n();var Eo=5e3;function Do(e){return e.state===`missing`||e.state===`unreadable`?e.stableId:e.name}function Oo({device:e,availability:n,sensors:i}){let{t:a}=Y(),s=Ha(),l=ve(),[f,p]=c(!1),[m,h]=c(null),g=t(!1),[_,v]=c(!1),[y,b]=c(!1),x=i.status,S=t(i.refetch);S.current=i.refetch,d(()=>{let e=setInterval(()=>{g.current||S.current()},Eo);return()=>clearInterval(e)},[]);let C=ho(x);d(()=>{x!==null&&b(!1)},[x]);let w=i.presence===`present`&&Co(x)&&!y?C:null,T=Ba(C!==null&&C.length>0),E=Va({hostId:e.id,excludeCameras:!0,assigned:new Set((C??[]).map($n)),preferredCap:`motion`,enabled:f});if(n.kind===`absent`)return null;let D=xo(x),O=wo(x)?`passes`:So(x),k=To(i.presence,x,y),A=k.kind===`none`?null:k.kind===`unknown`?{text:`?`,tone:`warning`,title:a(`customize.motion.cameraLevelUnknown`)}:{text:a(k.detected?`customize.assign.value.active`:`customize.assign.value.inactive`),tone:k.detected?`active`:`muted`,title:a(`customize.motion.cameraLevelOwn`,{at:new Date(k.atMs).toLocaleTimeString()})},j=_||l.isPending,M=async t=>{if(g.current){h(a(`customize.saveInFlight`));return}g.current=!0,v(!0);try{await l.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)}},N=async e=>{w!==null&&await s(a(`customize.motion.removeWhat`,{name:Do(e)}),!1)&&await M(bo(w,$n(e)))},P=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:Na(t.integration,t.location)};return r(o,{children:[r(Oa,{id:`motion`,icon:u(ne,{className:`h-4 w-4 text-foreground-subtle`}),title:a(`customize.motion.title`),addLabel:a(`customize.motion.add`),onAdd:w!==null&&n.kind===`present`?()=>p(!0):void 0,addDisabled:j,notices:r(o,{children:[u(ka,{availability:n}),i.presence===`pending`&&n.kind!==`pending`&&u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:a(`customize.motion.reading`)}),x?.state===`unreadable`&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.motion.unreadable`,{reason:x.reason})}),x?.state===`configured`&&!Co(x)&&u(`p`,{role:`alert`,className:`text-xs text-warning`,children:a(`customize.motion.olderOrchestrator`)}),y&&u(`p`,{role:`alert`,className:`text-xs text-warning`,children:a(`customize.motion.refetchFailed`)}),x?.state===`configured`&&x.notForwarded!==void 0&&u(`p`,{role:`alert`,className:`text-xs text-warning`,children:a(`customize.motion.notForwarded.${x.notForwarded}`)}),x?.state===`configured`&&x.notEnforced!==void 0&&u(`p`,{role:`alert`,className:`text-xs text-warning`,children:a(`customize.motion.notEnforced`)}),T.kind===`unknown`&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.assign.devicesUnreadable`,{reason:T.reason})}),m!==null&&u(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:m})]}),children:[u($,{name:a(`customize.motion.camera`),detail:null,meta:O===null?a(`customize.assign.native`):`${a(`customize.motion.cameraState.${O}`)} · ${a(`customize.assign.native`)}`,value:null,shown:A,removeLabel:``}),(C??[]).map(e=>{let t=$n(e),n=Do(e),r=e.state===`ready`?Ma(e.caps,`motion`):null,i=r===null?void 0:qn[r];return u($,{name:n,detail:P(e),meta:D&&w!==null?u(`select`,{"aria-label":a(`customize.motion.modeFor`,{name:n}),className:`h-11 rounded border border-border bg-surface px-1 text-xs`,value:e.mode,disabled:j,onChange:e=>{let n=Jn.safeParse(e.target.value);n.success&&w!==null&&M(yo(w,t,n.data))},children:Jn.options.map(e=>u(`option`,{value:e,children:a(`customize.motion.mode.${e}`)},e))}):a(`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?a(`customize.motion.state.${e.state}`):`${a(`customize.motion.state.${e.state}`)}: ${e.reason}`,onRemove:w===null?void 0:()=>void N(e),removeLabel:a(`customize.assign.removeNamed`,{name:n}),busy:j},t)})]}),u(Xa,{open:f,title:a(`customize.motion.pickTitle`),selection:`multi`,candidates:E,filters:ja,confirmLabel:e=>a(`customize.assign.addCount`,{count:e}),onConfirm:e=>{if(p(!1),w===null)return;let t=vo(w,e.map(e=>e.ref));if(t!==null&&t.sensors.length>8){h(a(`customize.motion.tooMany`,{max:8}));return}M(t)},onClose:()=>p(!1)})]})}var ko={"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`}},Ao=new Set([J.Camera]);function jo(e){return e.unitField===null?[e.fieldPath]:[e.fieldPath,e.unitField]}function Mo(e,t){if(Ao.has(e))return{kind:`absent`};let n=null;for(let[e,r]of Object.entries(ko))if(t.has(e)){n={cap:e,fieldPath:r.fieldPath,unitField:r.unitField};break}let r=null;for(let e of er)if(t.has(e)){let t=qn[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 No(e){return Hn(e.from,e.to)?kn(e):null}function Po(e){return zn(e)}var Fo=/^convert\(v,\s*"[^"]*",\s*"[^"]*"\)$/;function Io(e){return e!==void 0&&Fo.test(e.expr)}function Lo(e){return e===void 0||e.expr===`!v`||Fo.test(e.expr)?!1:e.bindings.v!==void 0}function Ro(e){let t=e.expr.trim();if(t===``)return{kind:`refused`,reason:`expression is empty`};let n={kind:`expression`,expr:t,bindings:{v:{kind:`from`,source:e.self,cap:e.cap,fieldPath:e.fieldPath}}},r=Nn({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 zo(e,t,n){if(e===null)return null;let r=Yr(e,n.cap);if(r===null)return e;let i=new Set(jo(n)),a=Object.fromEntries(Object.entries(r.fields).filter(([e])=>!i.has(e)));return Object.keys(a).length===0?Er(e,n.cap):X(e,t,{kind:`fields`,cap:n.cap,...r.enabled===void 0?{}:{enabled:r.enabled},fields:a,...r.items===void 0?{}:{items:r.items}})}n();function Bo(e){if(typeof e!=`object`||!e)return;let t=Reflect.get(e,`unit`);return typeof t==`string`?t:void 0}function Vo(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 Ho(e,t){let n=Yr(e,t.cap);if(n===null)return;let r=n.fields[t.fieldPath];return r!==void 0&&r.kind===`expression`?r:void 0}function Uo(e,t){let n=Ho(e,t);return n===void 0||!Io(n)?null:/^convert\(v,\s*"[^"]*",\s*"([^"]*)"\)$/.exec(n.expr)?.[1]??null}function Wo(e,t){let n=Ho(e,t);return n===void 0||!Lo(n)?null:n.expr}function Go(e,t,n){let r=Yr(e,t);if(r===null)return!1;let i=r.fields[n];return i!==void 0&&i.kind===`expression`&&i.expr===`!v`}function Ko(e){return typeof e==`number`||typeof e==`boolean`||typeof e==`string`?String(e):e===null?`null`:JSON.stringify(e)}function qo({device:e,target:t,handle:n,facts:i}){let{t:a}=Y(),o=_(),[s,l]=c(null),[d,f]=c(``),[p,m]=c(null),h=i.nativeCaps.kind===`known`?i.nativeCaps.value:null,g=h===null?null:Mo(e.type,h),v=g?.kind===`present`?g.convert?.cap??``:``,y=tt(o.trpcClient,e.id,v);if(i.nativeCaps.kind===`pending`)return u(`section`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(ka,{availability:{kind:`pending`}})});if(i.nativeCaps.kind===`unknown`)return u(`section`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(ka,{availability:{kind:`unknown`,reason:i.nativeCaps.reason}})});if(g===null||g.kind===`absent`)return null;let b=na(n.state),x=g.convert,S=g.invert,C=x===null?void 0:Bo(y),w=C===void 0?void 0:Mn(C)??C,T=w===void 0?void 0:Wn(w),E=x===null?null:Uo(b,x),D=x===null?null:Wo(b,x),O=p??D??``,k=S===null?!1:Go(b,S.cap,S.fieldPath),A=n.state.kind===`none`||n.state.kind===`present`,j=x===null?0:Vo(y,x.fieldPath)??0,N=x!==null&&O.trim()!==``?{kind:`expression`,expr:O.trim(),bindings:{v:{kind:`from`,source:t,cap:x.cap,fieldPath:x.fieldPath}}}:null,P=N===null||x===null?null:Br(N,new Map([[Un(t,x.cap),y===void 0?{kind:`pending`}:{kind:`value`,slice:y}]]),Date.now()),F=async e=>{let t=await n.save(e);l(t.kind===`refused`?t.reason:null)},ee=async()=>{if(x===null||w===void 0||d===``)return;let e=No({self:t,cap:x.cap,fieldPath:x.fieldPath,from:w,to:d,unitField:x.unitField});if(e===null){l(a(`customize.numericTransforms.convertRefused`));return}m(null),await F(X(b,t,e))},I=async()=>{x!==null&&(await F(zo(b,t,x)),f(``))},L=async()=>{if(x===null)return;let e=Ro({self:t,cap:x.cap,fieldPath:x.fieldPath,expr:O,probe:j});if(e.kind===`refused`){l(e.reason);return}f(``),await F(X(b,t,e.feature))},te=async()=>{x!==null&&(await F(zo(b,t,x)),m(``))},R=async()=>{if(S===null)return;let e=Po({self:t,cap:S.cap});if(e===null){l(a(`customize.numericTransforms.invertRefused`));return}await F(X(b,t,e))},z=async()=>{S===null||b===null||await F(Er(b,S.cap))};return r(`section`,{"aria-labelledby":`customize-numeric-transforms`,className:`rounded-lg border border-border bg-surface`,"data-testid":`numeric-transforms-card`,children:[r(`header`,{className:`flex flex-wrap items-center gap-2 border-b border-border px-2 py-2 sm:px-4`,children:[u($r,{className:`h-4 w-4 text-foreground-subtle`,"aria-hidden":!0}),u(`h2`,{id:`customize-numeric-transforms`,className:`flex-1 text-sm font-semibold`,children:a(`customize.numericTransforms.title`)})]}),r(`div`,{className:`flex flex-col gap-3 px-2 py-3 sm:px-4`,children:[u(`p`,{className:`text-xs text-foreground-subtle`,children:a(`customize.numericTransforms.blurb`)}),s!==null&&u(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:s}),x!==null&&r(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-convert`,children:[u(`label`,{className:`text-[11px] font-medium text-foreground`,children:a(`customize.numericTransforms.publishUnit`)}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:w===void 0?a(`customize.numericTransforms.fromUnknown`):a(`customize.numericTransforms.fromUnit`,{unit:w})}),u(sn,{dimension:T,value:d===``?E??``:d,onChange:e=>{f(e),e!==``&&m(``)},disabled:!A||n.saving||w===void 0,"aria-label":a(`customize.numericTransforms.toUnit`),inheritLabel:a(`customize.numericTransforms.pickUnit`),emptyReason:a(`customize.numericTransforms.fromUnknown`)}),r(`div`,{className:`flex flex-wrap gap-2`,children:[u(M,{size:`sm`,disabled:!A||n.saving||w===void 0||d===``||d===w,onClick:()=>void ee(),children:a(`customize.numericTransforms.applyConvert`)}),E!==null&&u(M,{size:`sm`,variant:`outline`,disabled:!A||n.saving,onClick:()=>void I(),children:a(`customize.numericTransforms.clearConvert`)})]})]}),x!==null&&r(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-script`,children:[u(Ur,{label:a(`customize.numericTransforms.script`),value:O,bindings:[`v`],onChange:e=>{m(e),e.trim()!==``&&f(``)}}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`customize.numericTransforms.scriptBlurb`)}),P!==null&&u(`p`,{role:`status`,className:`text-[11px] font-mono text-foreground`,"data-testid":`numeric-script-preview`,children:P.kind===`value`?a(`customize.numericTransforms.preview`,{source:Ko(j),result:Ko(P.value)}):P.kind===`waiting`?a(`customize.numericTransforms.previewWaiting`):P.kind===`unavailable`?a(`customize.numericTransforms.previewError`,{reason:P.reason}):a(`customize.numericTransforms.previewRuntimeOnly`)}),r(`div`,{className:`flex flex-wrap gap-2`,children:[u(M,{size:`sm`,disabled:!A||n.saving||O.trim()===``,onClick:()=>void L(),children:a(`customize.numericTransforms.applyScript`)}),D!==null&&u(M,{size:`sm`,variant:`outline`,disabled:!A||n.saving,onClick:()=>void te(),children:a(`customize.numericTransforms.clearScript`)})]})]}),S!==null&&r(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-invert`,children:[u(`label`,{className:`text-[11px] font-medium text-foreground`,children:a(`customize.numericTransforms.invert`)}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`customize.numericTransforms.invertBlurb`)}),u(`div`,{className:`flex flex-wrap gap-2`,children:k?u(M,{size:`sm`,variant:`outline`,disabled:!A||n.saving,onClick:()=>void z(),children:a(`customize.numericTransforms.clearInvert`)}):u(M,{size:`sm`,disabled:!A||n.saving,onClick:()=>void R(),children:a(`customize.numericTransforms.applyInvert`)})})]})]})]})}n();function Jo(e){return e instanceof Error?e.message:String(e)}function Yo(e){let n=rn({addonId:e.addonId,stableId:e.stableId}),r=Rt(),i=Kt(),a=en(),o=ta({status:n.status,data:n.data,error:n.error===null||n.error===void 0?null:{message:n.error.message}}),{t:s}=Y(),l=t(!1),[u,d]=c(!1),f=async e=>{let t=jr(o,e);try{switch(t.kind){case`refused`:return{kind:`refused`,reason:t.reason};case`noop`:return{kind:`saved`};case`create`:await r.mutateAsync({block:t.input});break;case`update`:await i.mutateAsync({blockId:t.blockId,expectedUpdatedAt:t.expectedUpdatedAt,block:{composition:t.composition}});break;case`delete`:await a.mutateAsync({blockId:t.blockId});break}return await n.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:Jo(e)}}};return{target:e,state:o,saving:u||r.isPending||i.isPending||a.isPending,save:async e=>{if(l.current)return{kind:`refused`,reason:s(`customize.saveInFlight`)};l.current=!0,d(!0);try{return await f(e)}finally{l.current=!1,d(!1)}}}}var Xo=`pipeline-orchestrator`;function Zo(e){return e.status===`pending`?`pending`:e.status===`error`?`unknown`:e.data===void 0?`pending`:e.data.cameraSensors===void 0?`absent`:`present`}function Qo(e,t){return e===`absent`?`absent`:Zo(t)}async function $o(e){try{return(await e()).isError?`failed`:`answered`}catch{return`failed`}}function es(e,t){let n=dn(Xo),r=Ut({deviceId:e},{enabled:t&&n!==`absent`}),i=()=>$o(r.refetch);return t?{presence:Qo(n,{status:r.status,data:r.data}),status:r.data?.cameraSensors??null,refetch:i}:{presence:`absent`,status:null,refetch:i}}function ts(e,t){let n=nt({deviceType:e.type}),r=Ce({deviceId:e.id}),i=Ie({deviceId:e.id}),a=Aa(n,e=>new Set(e.caps.map(e=>e.cap))),o=Aa(r,e=>Xi(e.entries)),s=Aa(i,e=>e);return{deviceType:e.type,composable:a,nativeCaps:o,wireable:s,composed:new Set((t?.features??[]).map(e=>e.cap))}}var ns={kind:`unknown`,reason:`the composer reports no value for this field`};function rs(e,t){let n=K(e);return t.get(n)??n}function is(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=Hr(e).map(e=>rs(e,n.sourceNames)).join(` + `),a=i.find(e=>e.field===`lastPressedAt`);return[{key:`doorbell`,label:`doorbell`,origin:{kind:r,from:t},value:a?.value??ns}]}return e.cap===`consumables`?Pr(e).map(e=>{let t=t=>Vn(Bn,e.key,t),a=i.find(e=>e.field===t(`level`)||e.field===t(`remaining.value`)),o=e.source===null?``:rs(e.source.source,n.sourceNames);return{key:`consumables.${e.key}`,label:`consumables · ${e.label}`,origin:{kind:r,from:o},value:a?.value??ns}}):i.map(e=>({key:e.key,label:`${e.cap}.${e.field}`,origin:{kind:r,from:e.from},value:e.value}))}function as(e){let t=Lr({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`?is(n,t,e):[])}function os(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 ss=`grid grid-cols-[minmax(0,1fr)_auto] gap-x-3 gap-y-1 items-baseline px-2 py-2 sm:px-4 sm:grid-cols-[minmax(0,1fr)_minmax(0,2fr)_auto]`;function cs({device:e,composition:t,state:n,nativeCaps:i,cameraSensors:a}){let{t:o}=Y(),s=t!==null&&n!==null,c=Ba(s),l=new Map(c.kind===`known`?c.value.map(e=>[K({addonId:e.addonId,stableId:e.stableId}),e.name]):[]),d=s&&i.kind===`known`?as({composition:t,nativeCaps:i.value,state:n,sourceNames:l}):[],f=s&&i.kind===`known`&&d.length===0&&t.features.length>0,p=os(a,{camera:o(`customize.changes.motion.camera`),sensor:(e,t)=>o(`customize.changes.motion.${t}`,{name:e})}),m=s&&i.kind!==`known`;return d.length===0&&p===null&&!m&&!f?null:r(`section`,{"aria-labelledby":`customize-changes`,className:`rounded-lg border border-border bg-surface`,children:[u(`h2`,{id:`customize-changes`,className:`px-3 py-2 text-[11px] font-semibold uppercase tracking-wider border-b border-border`,children:o(`customize.changes.title`)}),m&&u(`p`,{role:i.kind===`unknown`?`alert`:`status`,className:`px-2 py-2 text-xs text-foreground-subtle sm:px-4`,children:i.kind===`unknown`?o(`customize.changes.unknown`,{reason:i.reason}):o(`customize.changes.reading`)}),f&&u(`p`,{className:`px-2 py-2 text-xs text-foreground-subtle sm:px-4`,children:o(`customize.changes.noRows`)}),r(`ul`,{className:`divide-y divide-border`,children:[d.map(e=>r(`li`,{className:ss,children:[u(`span`,{className:`font-mono text-xs break-words`,children:e.label}),u(`span`,{className:`col-span-2 row-start-2 text-xs text-foreground-subtle break-words sm:col-span-1 sm:row-start-auto`,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:``})}),u(`span`,{className:`row-start-1 col-start-2 text-xs sm:row-start-auto sm:col-start-auto`,children:u(ls,{value:e.value})})]},e.key)),p!==null&&r(`li`,{className:ss,children:[u(`span`,{className:`font-mono text-xs`,children:`motion`}),u(`span`,{className:`col-span-2 row-start-2 text-xs text-foreground-subtle break-words sm:col-span-1 sm:row-start-auto`,children:p}),u(`span`,{className:`row-start-1 col-start-2 sm:row-start-auto sm:col-start-auto`,children:u(Ea,{target:{deviceId:e.id,cap:`motion`,path:`detected`}})})]})]})]})}function ls({value:e}){let{t}=Y();switch(e.kind){case`value`:return r(`span`,{children:[Vr(e.value,!0),e.staleReason!==null&&r(`span`,{className:`text-warning`,children:[` `,`· `,t(`customize.changes.value.stale`,{reason:e.staleReason})]})]});case`unavailable`:return u(`span`,{className:`text-warning`,children:t(`customize.changes.value.unavailable`,{reason:e.reason})});case`unknown`:return u(`span`,{className:`text-foreground-subtle`,children:t(`customize.changes.value.unknown`,{reason:e.reason})});case`off`:return u(`span`,{className:`text-foreground-subtle`,children:t(`customize.status.off`)})}}n();function us({deviceId:e,activeSubTab:t,onSubTabChange:n}){let{t:r}=Y(),i=Ne({deviceId:e}),a=i.data;return a==null?i.status===`error`?u(et,{title:r(`customize.deviceUnreadable`),message:i.error?.message??``,onRetry:()=>void i.refetch()}):a===null?u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.noSuchDevice`,{deviceId:e})}):u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.loadingDevice`)}):a.addonId===`composer`?u(ds,{device:a}):u(fs,{device:a,target:{addonId:a.addonId,stableId:a.stableId},activeSubTab:t,onSubTabChange:n})}function ds({device:e}){let{t}=Y(),n=e.stableId.startsWith(`composed-`)?e.stableId.slice(An.length):null;return r(`section`,{className:`rounded-lg border border-border bg-surface p-4 flex flex-col gap-2`,children:[u(`p`,{className:`text-sm text-foreground`,children:t(`customize.composed.body`)}),n!==null&&u(or,{className:`text-sm text-primary`,to:Sr(n),children:t(`customize.composed.edit`)})]})}function fs({device:e,target:t,activeSubTab:n,onSubTabChange:i}){let a=Yo(t),o=dn(`composer`),{t:s}=Y(),c=es(e.id,e.type===J.Camera),l=ts(e,na(a.state)),d={deviceType:e.type,composable:l.composable,nativeCaps:l.nativeCaps,cameraSensors:c.presence},f=()=>i(xr),p=a.state.kind===`none`||a.state.kind===`present`;return n===`advanced`?r(`div`,{className:`flex flex-col gap-4`,children:[u(ms,{state:a.state}),p&&u(ps,{device:e,target:t,handle:a,facts:l,onDone:()=>i(`main`)})]}):r(`div`,{className:`flex flex-col gap-4`,children:[u(fa,{device:e}),o===`absent`&&u(`p`,{role:`alert`,className:`text-xs text-warning`,children:s(`customize.composerAbsent`)}),a.state.kind!==`none`&&u(ms,{state:a.state}),u(ro,{device:e,handle:a,availability:ea(`doorbell`,d),onAdvanced:f}),u(Oo,{device:e,handle:a,availability:ea(`motion`,d),sensors:c}),u(Wa,{device:e,handle:a,availability:ea(`battery`,d),onAdvanced:f}),u(qa,{device:e,handle:a,availability:ea(`consumables`,d),onAdvanced:f}),u(qo,{device:e,target:t,handle:a,facts:l}),u(mo,{device:e}),u(cs,{device:e,composition:na(a.state),state:a.state.kind===`present`?a.state.view.state:null,nativeCaps:l.nativeCaps,cameraSensors:c.status}),r(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[p?u(M,{variant:`ghost`,className:`text-primary underline`,onClick:f,children:s(`customize.advancedLink`)}):u(`span`,{}),u(hs,{handle:a})]})]})}function ps({device:e,target:t,handle:n,facts:r,onDone:i}){let a=n.state.kind===`present`?n.state:null;return u(Gr,{initial:a===null?Dr(t):Or(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 ms({state:e}){let{t}=Y();switch(e.kind){case`pending`:return u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.status.pending`)});case`unknown`:return u(et,{title:t(`customize.status.unknownTitle`),message:e.reason});case`not-loaded`:return u(`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 r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[u(B,{variant:n.status===`running`?`success`:n.status===`failed`?`danger`:`warning`,children:t(`customize.blockStatus.${n.status}`)}),!n.enabled&&u(B,{variant:`default`,children:t(`customize.status.off`)}),n.lastError!==void 0&&u(`span`,{className:`text-[11px] text-foreground-muted break-words`,children:n.lastError}),e.view.state.kind===`unreachable`&&u(`span`,{className:`text-[11px] text-warning`,children:t(`customize.status.composerUnreachable`,{reason:e.view.state.error})})]})}}}function hs({handle:e}){let{t}=Y(),n=be(),[i,a]=c(null);if(e.state.kind!==`present`)return null;let o=async()=>{if(!await n({title:t(`customize.remove.title`),message:t(`customize.remove.message`),confirmLabel:t(`customize.remove.confirm`),variant:`danger`}))return;let r=await e.save(null);a(r.kind===`refused`?r.reason:null)};return r(`div`,{className:`flex flex-col items-start gap-1`,children:[u(M,{variant:`danger`,disabled:e.saving,onClick:()=>void o(),children:t(`customize.remove.button`)}),i!==null&&u(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:i})]})}var gs=`overview`;function _s(e,t){return e.some(e=>e.id===t)?t:gs}function vs({deviceId:e}){let t=s(),n=Number.isFinite(e),{data:i}=Ne({deviceId:e},{enabled:n}),a=typeof i?.type==`string`?i.type:`camera`;Qt([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:o,isLoading:c,isError:l,error:d}=Ce({deviceId:e},{enabled:n}),{data:f}=se({deviceType:a},{enabled:!!a}),p=dt({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(c)return u(`div`,{className:`p-4`,children:u(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(l)return r(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,d instanceof Error?d.message:String(d)]});let m=new Map,h={};for(let e of f??[])h[e.capName]=e.wrappers;for(let e of o?.entries??[])m.set(e.capName,{...e,wrappers:h[e.capName]??[]});for(let e of f??[])m.has(e.capName)||m.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let g=[...m.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(g.length===0)return r(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[u(Tn,{className:`h-8 w-8 opacity-40`}),u(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),u(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let _=g.filter(e=>e.kind!==`unbound`).length;return r(`div`,{className:`flex flex-col gap-3 p-1`,children:[r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-foreground`,children:_}),` of `,g.length,` capabilit`,g.length===1?`y`:`ies`,` bound — rows marked `,u(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),u(fn,{columns:[{key:`capability`,header:`Capability`,render:e=>u(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>u(ys,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>u(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||u(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?u(bs,{nodeId:e.providerNodeId}):u(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>u(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||u(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return u(xs,{wrappers:t.wrappers,activeWrapperId:n,disabled:p.isPending,onPick:r=>{let i=n===r;p.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:g,rowKey:e=>e.capName,minWidthPx:720})]})}function ys({kind:e}){return e===`native`?r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(Xe,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(On,{className:`h-3 w-3`}),`wrapped`]}):e===`linked`?r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-warning/30 text-warning bg-warning/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(W,{className:`h-3 w-3`}),`linked`]}):r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(ee,{className:`h-3 w-3`}),`unbound`]})}function bs({nodeId:e}){return u(`span`,{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e===`hub`?`text-foreground-subtle`:`text-foreground`}`,children:e})}function xs({wrappers:e,activeWrapperId:t,disabled:n,onPick:i}){return e.length===0?u(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):u(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let a=e===t;return r(`button`,{disabled:n,onClick:()=>i(e),title:a?`Click to deactivate (revert to native)`:`Activate wrapper ${e}`,className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${a?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[u(a?vn:v,{className:`h-3 w-3`}),e]},e)})})}function Ss({deviceId:e,activeSubTab:t,onSubTabChange:n,deviceType:i,isAdmin:a}){return r(`div`,{className:`flex flex-col gap-3`,children:[Cr(i,a)&&u(pt,{deviceId:e,readOnly:!0}),u(pr,{deviceId:e,activeSubTab:t,onSubTabChange:n})]})}n();var Cs=new Set([`package-detection`]);function ws(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function Ts(e){return e?e.modelId!==void 0||e.settings!==void 0:!1}function Es({deviceId:e,refreshToken:t}){let n=s(),l=_().trpcClient,[d,f]=c(null),[p,m]=c(null),[h,g]=c(null),v=Je({deviceId:e},{refetchOnMount:`always`}),y=rt({deviceId:e},{refetchOnMount:`always`}),b=mt(void 0,{refetchOnMount:`always`});Qt([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let{nodes:x}=ht(),S=i(()=>{let e=new Set;for(let t of x)t.isOnline&&e.add(t.id);return e},[x]),C=i(()=>(b.data??[]).filter(e=>S.has(e.nodeId)).map(e=>e.nodeId),[b.data,S]),w=a({enabled:C.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`device-step-schemas`,C.join(`,`),t],queryFn:async()=>{let e={};for(let t of C)try{e[t]=await l.pipelineExecutor.getSchema.query({nodeId:t})}catch{}return e}}),T=e=>w.data?.[e]??null,E=i(()=>{let e=C[0];if(e!==void 0){let t=w.data?.[e];if(t)return t}return Object.values(w.data??{})[0]??null},[C,w.data]),D=a({enabled:C.length>0,queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`],`device-step`,C.join(`,`),t],queryFn:async()=>{let e={};for(let t of C)try{e[t]=(await l.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:t})).devices}catch{e[t]=[]}return e}}),k=()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]})},A=At({onSuccess:k}),M=O({onSuccess:k}),N=i(()=>E?j(E):[],[E]),P=i(()=>{let e=b.data??[],t=S.size===0?[]:e.filter(e=>S.has(e.nodeId)),n=[];for(let e of t){let t=(D.data?.[e.nodeId]??[]).filter(e=>e.enabled&&e.available);if(t.length>=2)for(let r of t)n.push({agentNodeId:e.nodeId,engineLabel:r.format,deviceKey:r.key,deviceLabel:Dn(r).label});else n.push({agentNodeId:e.nodeId,engineLabel:t[0]?.format??`(engine unknown)`})}return n},[b.data,D.data,S]),F=(e,t)=>D.data?.[e]?.find(e=>e.key===t)??null,ee=e=>{if(e.deviceKey!==void 0)return e.deviceKey;let t=D.data?.[e.agentNodeId]??[],n=t.filter(e=>e.enabled&&e.available);return n.length>=1?n[0].key:t.find(e=>e.available)?.key??t[0]?.key??null},I=(e,t,n)=>y.data?.[e]?.[t]?.[n]??null,L=e=>{if(Cs.has(e))return{kind:`zone-driven`};let t=ws(E,e)?.enabledByDefault??!0,n=v.data?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},te=(e,t,n)=>{let r=ws(T(n),e);if(r)return tn(r,t)},R=(e,t)=>{let n=ws(T(t.agentNodeId),e);if(!n)return;let r=ee(t),i=r===null?null:F(t.agentNodeId,r);return xt({catalog:n,device:i,override:(r===null?null:I(t.agentNodeId,r,e))?.modelId,base:i?.steps?.[e]?.modelId})},z=(e,t)=>{if(!Xn(e))return;let n=R(`object-detection`,t);if(n===void 0)return;let r=ws(T(t.agentNodeId),`object-detection`)?.models.find(e=>e.id===n),i=Zn(r,e);if(i===void 0)return;let a=L(e),o=ee(t),s=o===null?null:F(t.agentNodeId,o),c=o===null?null:I(t.agentNodeId,o,e);return Yn(i,{enabled:a.kind===`zone-driven`||a.effectiveOn,settings:{...s?.steps?.[e]?.settings,...c?.settings}}).skip?n:void 0},ne=(e,t)=>{let n=L(e),r=n.kind===`gate`?n.effectiveOn:!1,i=ws(T(t.agentNodeId),e),a=ee(t),o=a===null?null:F(t.agentNodeId,a);if(!qe(i?.models??[],o?.format))return r?{kind:`skip`}:{kind:`na`};let s=a===null?null:I(t.agentNodeId,a,e),c=z(e,t);return{kind:`enabled`,modelId:R(e,t)??`Auto`,overridden:Ts(s),...c===void 0?{}:{filledBy:c}}},re=d===null?null:ws(T(d.agentNodeId),d.addonId),B=d?F(d.agentNodeId,d.deviceKey):null,ie=B?.format??`coreml`,ae=d?Ts(I(d.agentNodeId,d.deviceKey,d.addonId)):!1,V=d?te(d.addonId,B,d.agentNodeId):void 0,oe=i(()=>{if(!d||!B)return null;let e=B.steps?.[d.addonId];return{enabled:!0,...e?.modelId===void 0?{}:{modelId:e.modelId},settings:e?.settings??{}}},[d,B]),H=()=>{f(null),m(null)},se=(e,t)=>{let n=ee(t);n!==null&&(f({addonId:e,agentNodeId:t.agentNodeId,deviceKey:n}),m(I(t.agentNodeId,n,e)))},ce=(t,n)=>{M.mutate({deviceId:e,addonId:t,enabled:n})},le=()=>{d&&A.mutate({deviceId:e,agentNodeId:d.agentNodeId,deviceKey:d.deviceKey,addonId:d.addonId,patch:p},{onSuccess:H})},ue=()=>{d&&A.mutate({deviceId:e,agentNodeId:d.agentNodeId,deviceKey:d.deviceKey,addonId:d.addonId,patch:null},{onSuccess:H})};if(b.isLoading||C.length>0&&w.isLoading)return u(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(P.length===0)return u(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`No online agents.`});if(!E)return u(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let de=d!==null&&re!==null&&B!==null;return r(`div`,{className:`relative h-full w-full space-y-3`,children:[r(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-foreground`,children:`Gate`}),` (col 1) decides whether this camera runs a step — independent of nodes. Each`,` `,u(`span`,{className:`font-medium text-foreground`,children:`node column`}),` shows the model that node runs; click a cell to pin a per-camera model override for that accelerator. A gated-on step with no model on a device shows a clickable `,u(`span`,{className:`text-amber-500`,children:`⚠ skip`}),` `,`and won't run there.`]}),r(`div`,{className:`rounded-md border border-sky-500/25 bg-sky-500/[0.06] px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-sky-400`,children:`Placement is dynamic.`}),` When a node has multiple inference accelerators, each session is balanced across them per-session at dispatch time — these device columns show each accelerator's effective model (override ?? device default), not a fixed assignment.`]}),u(`div`,{className:de?`md:pr-[360px]`:``,children:N.length>0?u(ye,{tree:N,agents:P,gateFor:L,getCellState:ne,onCellClick:se,selectedCell:d,onSetGate:ce,gateBusy:M.isPending,fallbackNodeId:h,onFallbackNodeChange:g}):u(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),u(un,{open:de,onClose:H,title:re?.name??``,subtitle:d&&B?`${d.agentNodeId} · ${Dn(B).label} · ${B.format}`:``,footer:r(o,{children:[u(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle disabled:opacity-50`,disabled:!ae||A.isPending,onClick:ue,children:`Clear override`}),u(`div`,{className:`flex-1`}),u(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:H,children:`Cancel`}),u(`button`,{type:`button`,disabled:!d||!oe||A.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:le,children:A.isPending?`Saving…`:`Save`})]}),children:re&&d&&oe?u(zt,{mode:`device`,addon:re,agentDefault:oe,agentNodeId:d.agentNodeId,currentPatch:p,engineFormat:ie,effectiveModelId:V,onChangePatch:m}):u(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-300`,children:`This accelerator is no longer reported by the node, so there is nothing to provision here.`})})]})}var Ds=[{id:`object-detection`,label:`Object detection`,icon:`scan-search`},{id:`tracking`,label:`Tracking`,icon:`route`},{id:`motion`,label:`Motion`,icon:`activity`},{id:`stationary`,label:`Stationary`,icon:`square-parking`},{id:`zones`,label:`Zones`,icon:`shapes`},{id:`audio`,label:`Audio`,icon:`volume-2`},{id:`cluster`,label:`Cluster`,icon:`server`}],Os={"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 ks(e){return Os[e]??`object-detection`}n();var As=`steps`,js=`settings`,Ms=new Set([As,js]);function Ns(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function Ps({deviceId:t,activeSubTab:n,onSubTabChange:i}){return r(U,{value:n&&Ms.has(n)?n:As,onValueChange:e(e=>{i?.(e)},[i]),className:`flex flex-col`,children:[r(V,{className:`flex-shrink-0`,children:[u(de,{value:As,children:`Steps`}),u(de,{value:js,children:`Settings`})]}),u(L,{value:As,children:u(Es,{deviceId:t,refreshToken:0})}),u(L,{value:js,children:u(pr,{deviceId:t,sectionFilter:Ns,subTabGrouping:{groupOf:e=>ks(e.id),tabs:Ds}})})]})}var Fs=`Notifications`,Is=`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`;function Ls(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:Fs,on:r===null?null:i??r,available:r!==null,costWhenOff:Is}}function Rs(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}n();function zs(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function Bs({deviceId:t}){let n=s(),i=Number.isFinite(t),[a,o]=c(null),[l,d]=c(null),f=Ls({mutedDeviceIds:zs(N({},{enabled:i}).data),deviceId:t,pendingOn:l}),p=ke({onError:e=>{console.error(`[DeviceNotificationMute] mute write failed — reverting`,{tags:{deviceId:t},meta:{error:e instanceof Error?e.message:String(e)}}),d(null),o(e instanceof Error?e.message:String(e)),n.invalidateQueries({queryKey:[[`notificationRules`,`listDeviceMutes`]]})},onSuccess:()=>{o(null),d(null),n.invalidateQueries({queryKey:[[`notificationRules`]]})}}),m=e(()=>{let e=Rs(f,t);e!==null&&(d(!e.muted),p.mutate(e))},[t,p,f]),h=f.on===null,g=f.on===!1,_=g?Tt:_e;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`border-b border-border px-4 py-2 flex items-center justify-between gap-2`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Notifications`}),g&&u(`span`,{className:`rounded bg-warning/20 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide text-warning`,children:`muted`})]}),r(`div`,{className:`px-4 py-3 flex items-start gap-3`,children:[r(`button`,{type:`button`,role:`switch`,"aria-label":f.label,"aria-checked":f.on===!0,disabled:!f.available||p.isPending,onClick:m,title:h?`Notification mute — state unknown; the notification centre did not answer.`:g?`Muted. ${f.costWhenOff}`:`Notifying. Muting it: ${f.costWhenOff}`,className:`inline-flex items-center gap-1.5 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors disabled:cursor-not-allowed ${a===null?h?`border-dashed border-border text-foreground-subtle/50`:g?`border-warning/40 text-warning hover:bg-warning/10`:`border-success/30 text-success hover:bg-success/10`:`border-danger/50 text-danger bg-danger/5`}`,children:[u(_,{className:`h-3.5 w-3.5`}),u(`span`,{children:h?`Unknown`:g?`Muted`:`Notifying`})]}),u(`p`,{className:`flex-1 text-[11px] leading-relaxed text-foreground-subtle`,children:a===null?h?`The notification centre did not answer, so this device’s mute state is unknown.`:f.costWhenOff:`Write failed: ${a}`})]})]})}function Vs(e,t){return{switchId:e,label:Pn[e].label,detail:t===void 0||t.length===0?null:t}}function Hs(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 Us(e){let t=Hs(e),n=new Set(e.sourceStillLive),r=e.sourceStillLive.map(e=>Vs(e,t.get(e)?.detail)),i=[...t.values()].filter(e=>e.outcome===`not-offered`&&!n.has(e.switchId)).map(e=>Vs(e.switchId,e.detail));return{inheritedId:e.sourceId,retiredId:e.targetId,swapped:e.swapped,verdict:r.length===0?`quiet`:`still-live`,stillLive:r,neverOffered:i}}n();function Ws(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 Gs({deviceId:e,deviceName:t}){let{t:n}=Y(),a=be(),[o,s]=c(null),l=z({isCamera:!0,projection:`slim`}),d=Ve(),f=l.data!==void 0,p=i(()=>l.data===void 0?[]:Ws(l.data,e),[l.data,e]),m=p.find(e=>e.id===o)??null,h=d.data===void 0?null:Us(d.data),g=d.error===null?null:d.error.message,_=async()=>{m===null||m.id===e||await a({title:n(`deviceMigrate.confirmTitle`,`Replace “{{source}}” with “{{target}}”?`,{source:t,target:m.name}),message:n(`deviceMigrate.confirmMessage`,`“{{target}}” takes over number {{sourceId}}. That number is what every recording, event, rule, zone and home-automation export of “{{source}}” is filed under, so all of it follows the number to the new hardware and keeps working. “{{source}}” is switched off and handed number {{targetId}} in exchange. This swaps two device identities and cannot be undone from here.`,{source:t,target:m.name,sourceId:e,targetId:m.id}),confirmLabel:n(`deviceMigrate.confirmAction`,`Migrate`),variant:`danger`})&&d.mutate({sourceId:e,targetId:m.id})};return r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`min-w-0`,children:[u(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:n(`deviceMigrate.title`,`Migrate to…`)}),u(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:n(`deviceMigrate.subtitle`,`Replace this camera with other hardware you have already adopted. The new camera inherits number {{deviceId}}, so recordings, rules and integrations follow it.`,{deviceId:e})})]}),r(`div`,{className:`flex shrink-0 items-center gap-2`,children:[r(`select`,{"aria-label":n(`deviceMigrate.pickerLabel`,`Replacement camera`),className:`rounded-md border border-border bg-background px-2 py-1.5 text-xs text-foreground disabled:opacity-50`,disabled:!f||p.length===0||d.isPending,value:o===null?``:String(o),onChange:e=>{let t=e.target.value;s(t===``?null:Number(t))},children:[u(`option`,{value:``,children:f?n(`deviceMigrate.pickerPlaceholder`,`Select a camera…`):n(`deviceMigrate.pickerPending`,`Reading the fleet…`)}),p.map(e=>r(`option`,{value:String(e.id),children:[e.name,` (#`,e.id,`)`]},e.id))]}),r(`button`,{type:`button`,disabled:m===null||d.isPending,onClick:()=>{_()},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[u($r,{className:`h-3 w-3`}),d.isPending?n(`deviceMigrate.running`,`Migrating…`):n(`deviceMigrate.action`,`Migrate`)]})]})]}),f&&p.length===0&&u(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:n(`deviceMigrate.noTargets`,`No other camera is adopted, so there is nothing to migrate to.`)}),g!==null&&u(`p`,{className:`mt-2 text-[11px] text-danger`,children:n(`deviceMigrate.failed`,`Migration failed: {{error}}`,{error:g})}),h!==null&&u(Ks,{report:h})]})}function Ks({report:e}){let{t}=Y(),n=e.verdict===`quiet`;return r(`div`,{className:`mt-3 space-y-2 border-t border-border pt-3`,children:[u(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`deviceMigrate.swapped`,`The replacement now answers on number {{inheritedId}}; the old camera was handed number {{retiredId}}.`,{inheritedId:e.inheritedId,retiredId:e.retiredId})}),n?r(`div`,{className:`flex items-start gap-2 rounded-md border border-success/30 bg-success/5 px-3 py-2`,children:[u(Pt,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-success`}),u(`p`,{className:`text-[11px] leading-relaxed text-foreground`,children:t(`deviceMigrate.quiet`,`Every function on the replaced camera was switched off — the old hardware is quiet.`)})]}):r(`div`,{className:`rounded-md border border-warning/40 bg-warning/5 px-3 py-2`,children:[r(`div`,{className:`flex items-start gap-2`,children:[u(Lt,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),u(`p`,{className:`text-[11px] leading-relaxed text-foreground`,children:t(`deviceMigrate.stillLive`,`The replaced camera could not be reached, so these functions are STILL RUNNING on the old hardware. Nothing here failed to migrate — but until you unplug it or reach it physically, it can still produce data.`)})]}),u(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.stillLive.map(e=>r(`li`,{className:`text-[11px] text-foreground`,children:[u(`span`,{className:`font-medium`,children:e.label}),e.detail!==null&&r(`span`,{className:`text-foreground-subtle`,children:[` — `,e.detail]})]},e.switchId))})]}),e.neverOffered.length>0&&r(`div`,{className:`rounded-md border border-border px-3 py-2`,children:[r(`div`,{className:`flex items-start gap-2`,children:[u(En,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),u(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`deviceMigrate.neverOffered`,`The replaced camera never offered these, so there was nothing to switch off. They are not running.`)})]}),u(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.neverOffered.map(e=>u(`li`,{className:`text-[11px] text-foreground-subtle`,children:e.label},e.switchId))})]})]})}n();function qs({deviceId:e}){let[t,n]=c(null),i=Et({onSuccess:e=>{n(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>n(`Re-sync failed: ${e.message}`)});return r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[r(`div`,{className:`flex items-center justify-between gap-3`,children:[r(`div`,{children:[u(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),u(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),r(`button`,{type:`button`,disabled:i.isPending,onClick:()=>{n(null),i.mutate({camDeviceId:e})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[u(Yt,{className:`h-3 w-3 ${i.isPending?`animate-spin`:``}`}),i.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&u(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}function Js(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function Ys({device:e}){let t=sr(),n=typeof e.id==`number`?e.id:null,i=String(e.type??``),a=i===J.Camera,o=i===J.Hub,s=e.features??[],c=s.includes(Qn.Resyncable),{data:l}=_t({deviceId:n??0},{enabled:n!==null&&a,refetchInterval:5e3}),d=l?.streams??{},f=Object.entries(d),p=s.includes(Qn.DoorbellButton),m=yt(p?{deviceId:n??void 0,historyLimit:10}:void 0),h=m.latest?Date.now()-m.latest.timestamp<3e4:!1;return r(`div`,{className:`space-y-5`,children:[o&&n!==null&&u(he,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),c&&n!==null&&u(qs,{deviceId:n}),a&&n!==null&&u(Gs,{deviceId:n,deviceName:String(e.name??``)}),n!==null&&u(Bs,{deviceId:n}),a&&n!==null&&u(Ft,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),p&&u(fe,{history:m.history,latestIsFresh:h}),a&&n!==null&&u(Ft,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),a&&f.length>0&&r(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[u(`div`,{className:`border-b border-border px-4 py-2`,children:u(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),u(`div`,{className:`divide-y divide-border`,children:f.map(([e,t])=>r(`div`,{className:`px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 mb-2`,children:[u(Oe,{className:`h-3 w-3 text-foreground-subtle`}),u(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),r(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[u(Xs,{label:`Nominal`,value:Js(t.nominalBitrateKbps??0)}),u(Xs,{label:`Observed`,value:Js(t.observedBitrateKbps??0)}),u(Xs,{label:`Peak`,value:Js(t.peakBitrateKbps??0)}),u(Xs,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),u(nr,{}),n!==null&&u(wr,{deviceId:n})]})}function Xs({label:e,value:t,warning:n}){return r(`div`,{children:[u(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),u(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}var Zs=[{id:`overview`,label:`Overview`,cameraOnly:!1,adminOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1,adminOnly:!1},{id:_r,label:`Customize`,cameraOnly:!1,adminOnly:!0},{id:`detection-pipeline`,label:`Detection pipeline`,cameraOnly:!0,adminOnly:!1},{id:`bindings`,label:`Bindings`,cameraOnly:!0,adminOnly:!1}];function Qs(e,t){let n=e===J.Camera;return Zs.filter(e=>(n||!e.cameraOnly)&&(t||!e.adminOnly)).map(({id:e,label:t})=>({id:e,label:t}))}function $s({provider:e,integrationId:t,name:n}){let r=sr(),i=t===null?`/integrations`:`/integrations/${t}`,a=n===null?`Open integrations`:`Open integration ${n}`;return u(`button`,{type:`button`,onClick:()=>r(i),className:`shrink-0 rounded-md transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-1 focus-visible:ring-primary/50`,title:a,"aria-label":a,children:u(tr,{type:e,size:`lg`})})}n();var ec=[{id:`logs`,icon:on,label:`Logs`},{id:`repl`,icon:ar,label:`REPL`},{id:`events`,icon:F,label:`Events`},{id:`state`,icon:$t,label:`State`}];function tc(){let n=lr(),a=Number(n.deviceId),l=Number.isFinite(a),d=sr(),f=s(),m=be(),h=_(),{user:v}=dr(),y=v?.isAdmin===!0,[b,x]=ir(),w=b.get(`tab`)??`overview`,T=b.get(`sub`),[E,O]=c(`logs`),A=`device-detail.left-col-width-px`,[j,M]=c(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(A),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),N=t(j);N.current=j;function P(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??j??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{M(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=N.current;if(e!==null)try{window.localStorage.setItem(A,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:F,isLoading:ee,isError:I}=Ne({deviceId:a},{enabled:l,refetchInterval:5e3,retry:1}),{data:L}=re({deviceId:a},{enabled:l}),te=i(()=>{let e=L?.settings?.sections??[],t=L?.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(hr)&&r.add(br),[...r].map(e=>e===`export`?{id:e,label:gr,isAddonContrib:!0}:{id:e,label:Ln[e]?.label??e,isAddonContrib:!0})},[L]),R=F,z=String(R?.name??n.deviceId??`Device`),ne=R?.online===!0,B=ne?`online`:`offline`,ae=String(R?.addonId??`rtsp`),V=R?.features??[],H=R?.type,se=H===J.Camera,{data:ce}=fr(l?a:0),de=H===J.Container,fe=i(()=>(ce??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[ce]),he=i(()=>de?Wt(fe,typeof R?.linkDeviceId==`number`?R.linkDeviceId:null,typeof R?.primaryChildEntityId==`string`?R.primaryChildEntityId:null)?.id??null:null,[de,fe,R?.linkDeviceId,R?.primaryChildEntityId]),{data:ge}=re({deviceId:he??0},{enabled:he!==null}),_e=i(()=>{if(he===null)return[];let e=ge?.settings?.sections??[],t=ge?.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:Ln[e]?.label??e,isAddonContrib:!0,childDeviceId:he}))},[he,ge]),ve=typeof R?.parentDeviceId==`number`?R.parentDeviceId:null,{data:ye}=Ne({deviceId:ve??0},{enabled:ve!==null}),U=ie(),W=R?.disabled!==!0,Se=i(()=>{let e=L?.settings?.sections??[],t=L?.live?.sections??[];return mr([...e,...t],H,y,L!==void 0)},[L,H,y]),Ce=i(()=>{let e=new Set,t=[];for(let n of[...Qs(H,y),...te,..._e])n.id===`config`&&!Se||e.has(n.id)||(e.add(n.id),t.push(n));return t},[H,y,te,_e,Se]),we=i(()=>_s(Ce,w),[Ce,w]),Te=e(e=>{x(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[x]),Ee=e(e=>{x(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[x]),De=(ce??[]).length>0,Oe=i(()=>ec.filter(({featureGate:e})=>!e||V.includes(e)),[V]),{data:ke}=Sn(void 0),Ae=i(()=>R?Me(R,ke):null,[R,ke]),G=Ae?.kind===`resolved`?Ae.integration:null,je=G===null?Ae?.kind===`unknown`?`Loading integration…`:Ae?.kind===`orphan`?`Missing integration`:`No integration`:G.name,Pe=G!==null&&G.addonId===ae?G.name:ae,Fe=ot({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]}),d(G?.id?`/integrations/${G.id}`:`/integrations`)}}),Ie=le({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=pe({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Re=xe(),ze=qt({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Be=V.includes(Qn.Rebootable),Ve=V.includes(Qn.BatteryOperated),He=oe(h.trpcClient,Ve&&l?a:null),Ue=Xt(h.trpcClient,l?a:null),[We,Ke]=c(!1),qe=async()=>{if(!We){Ke(!0);try{let e=z.replace(/[^a-zA-Z0-9_.-]+/g,`_`),t=new Date().toISOString().replace(/[:.]/g,`-`);await Xr(`${p}/${String(a)}.jpg?force=1`,`${e}-${t}.jpg`)}finally{Ke(!1)}}},Je=Ie.isPending||Le.isPending,{data:Ye}=lt({deviceId:a},{enabled:l,refetchInterval:1e4}),Xe=Ye?.agentNodeId??null,Ze=typeof Xe==`string`&&Xe.length>0&&!Xe.startsWith(`addon:`)?Xe:void 0,{data:Qe}=ue({deviceId:a,...Ze?{nodeId:Ze}:{}},{enabled:l,refetchInterval:3e3,retry:!1}),{data:$e}=kt({deviceId:a},{enabled:l,refetchInterval:3e3,retry:!1}),et=$e?.level?.dbfs??null;function tt(){if(!l)return null;switch(we){case`overview`:return u(Ys,{device:R??{}});case`config`:return u(Ss,{deviceId:a,activeSubTab:T,onSubTabChange:Ee,deviceType:H,isAdmin:y});case`detection-pipeline`:return u(Ps,{deviceId:a,activeSubTab:T,onSubTabChange:Ee});case`bindings`:return u(vs,{deviceId:a});case _r:return u(us,{deviceId:a,activeSubTab:T,onSubTabChange:Ee});default:{let e=we,t=te.some(t=>t.id===e),n=_e.find(t=>t.id===e);if(!t&&n===void 0)return null;let r=n?.childDeviceId??a;if(e===`export`)return u(pr,{deviceId:a,sectionFilter:hr,activeSubTab:T,onSubTabChange:Ee});let i=u(pr,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:T,onSubTabChange:Ee});return n!==void 0&&r!==a?u(Ot,{deviceId:r,children:i}):i}}}return l?ee?r(`div`,{className:`flex flex-col h-full`,children:[r(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[u(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),u(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),u(`div`,{className:`flex-1 p-6`,children:u(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):I||!F?r(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[u(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),r(`p`,{className:`text-xs`,children:[`No device with ID`,` `,r(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,a]})]}),u(`button`,{onClick:()=>d(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]}):r(`div`,{className:`absolute inset-0 flex flex-col overflow-clip`,children:[r(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[u(`div`,{className:`mb-2`,children:u(k,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},G===null?{label:je}:{label:je,onClick:()=>d(`/integrations/${G.id}`)},{label:z}]})}),r(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[G!==null&&u($s,{provider:G.addonId,integrationId:G.id,name:G.name}),r(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:z}),u(Zr,{status:B}),Ve&&u(me,{status:He,variant:`full`}),u(wt,{status:Ue})]}),ve!==null&&ye&&r(`button`,{type:`button`,onClick:()=>d(`/devices/${ve}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${ye.name}`,children:[u(`span`,{children:`↑`}),u(`span`,{className:`truncate`,children:String(ye.name??`Device #${ve}`)})]}),u(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:V.length>0&&u(vr,{capabilities:V})})]}),Qe&&u(`div`,{className:`hidden lg:flex`,children:u(nc,{metrics:Qe,dbfs:et})}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[r(`button`,{onClick:async()=>{W?await m({title:`Disable "${z}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Le.mutate({deviceId:a}):Ie.mutate({deviceId:a})},disabled:Je,title:W?`Disable device`:`Enable device`,className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border transition-colors disabled:opacity-50 ${W?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[u(Ge,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:Je?`Updating…`:W?`Enabled`:`Disabled`})]}),u(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),se&&r(o,{children:[u(ci,{deviceId:a}),u(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),u(ui,{deviceId:a}),u(D,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:g,disabled:We,onClick:()=>{qe()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:ut,hidden:!Be,disabled:Re.isPending,danger:!0,onClick:async()=>{await m({title:`Reboot "${z}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Re.mutate({deviceId:a})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${Pe}.`,icon:Yt,disabled:ze.isPending,danger:!0,onClick:async()=>{await m({title:`Restart "${Pe}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${z}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&ze.mutate({addonId:ae})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:S,separatorBefore:!0,disabled:Fe.isPending,danger:!0,onClick:async()=>{await m({title:`Delete "${z}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Fe.mutate({deviceId:a})}}]})]})]})]}),u(Ot,{deviceId:a,device:R??void 0,children:u(ln,{children:u(gt,{children:u(C,{children:u(jt,{children:r(`main`,{className:U?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[r(`div`,{className:U?`flex flex-col bg-surface`:`${j===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!U&&j!==null?{width:`${String(j)}px`}:void 0,children:[u(`div`,{className:se?`flex-shrink-0 border-b border-border-subtle bg-black`:U?`flex-shrink-0 border-b border-border-subtle bg-surface`:`max-h-[55%] shrink-0 overflow-y-auto border-b border-border-subtle bg-surface`,children:se?u(Wi,{deviceId:a,intercomAvailable:V.includes(Qn.TwoWayAudio)}):u(Pi,{deviceId:a,deviceName:z,deviceType:H??`unknown`,provider:ae,isOnline:ne,features:V})}),r(`div`,{className:U?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[u(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:u(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:Oe.map(({id:e,label:t,icon:n})=>r(`button`,{onClick:()=>O(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${E===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[u(n,{className:`h-3 w-3`}),t]},e))})}),r(`div`,{className:U?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[E===`logs`&&u(Gi,{deviceId:a,containerDeviceId:H===`container`?a:void 0}),E===`repl`&&u(Ki,{deviceId:a}),E===`events`&&u(qi,{deviceId:a}),E===`state`&&u(Ji,{deviceId:a})]})]})]}),!U&&u(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:P,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:u(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),r(`div`,{className:U?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[u(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:u(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:Ce.map(e=>{let t=we===e.id;return r(`button`,{onClick:()=>Te(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&u(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),r(`div`,{className:U?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[we===`overview`&&De&&u(di,{parentDeviceId:a}),tt()]})]})]})})})})})})]}):r(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[u(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),r(`p`,{className:`text-xs`,children:[`The URL segment`,` `,u(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:n.deviceId}),` `,`is not a number.`]}),u(`button`,{onClick:()=>d(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]})}function nc({metrics:e,dbfs:t}){let n=gn(e.phase??`idle`);return r(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[r(`div`,{className:`flex items-center gap-1.5`,children:[u(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),u(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),u(`div`,{className:`h-3 w-px bg-border`}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[u(ne,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),u(`span`,{children:`fps`})]}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[u(bt,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),u(`span`,{children:`ms`})]}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[u(Dt,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),u(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&r(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{tc as DeviceDetailPage};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./browser-BHo8W_uH.js","./rolldown-runtime-Cyuzqnbw.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{t}from"./vite-preload-helper-kNaey6uv.js";import{Q as n,S as r,W as i,a,b as o,q as s,t as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as d,st as f}from"./player-overlays-B-iWFodj.js";import{Cn as p,Dn as m,Et as h,I as g,Ll as _,Lu as v,Nu as y,Ru as b,Sn as x,Xu as S,Yl as C,ad as w,gd as T,hd as E,ju as D,mn as O,pn as k,qa as A,xu as ee}from"./src-D3Zan8Or.js";import{an as j,rn as M}from"./client-BomCPWqx.js";import{t as N}from"./useTranslation-Bc5yH9V9.js";import{S as P,z as F}from"./index-CoHcNeUl.js";import{t as I}from"./AdminPage-CiKtOLQm.js";n();function L({value:n,size:i=192}){let[a,o]=s(null),[c,d]=s(null);if(u(()=>{let r=!1;return t(()=>import(`./browser-BHo8W_uH.js`).then(t=>e(t.default,1)).then(async e=>{if(r)return;let t=e.create;if(typeof t!=`function`){d(`qrcode.create() unavailable in installed version`);return}try{let e=t(n,{errorCorrectionLevel:`M`});r||o(e)}catch(e){r||d(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1]),import.meta.url).catch(()=>{r||d(`qrcode library not installed`)}),()=>{r=!0}},[n]),c)return l(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:i,height:i},children:`QR rendering unavailable — use the secret below.`});if(!a)return l(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:i,height:i},children:`Generating…`});let f=a.modules.size,p=i/f,m=[];for(let e=0;e<f;e++)for(let t=0;t<f;t++)a.modules.data[e*f+t]&&m.push(l(`rect`,{x:t*p,y:e*p,width:p,height:p,fill:`currentColor`},`${t}-${e}`));return r(`svg`,{width:i,height:i,viewBox:`0 0 ${i} ${i}`,className:`text-black`,children:[l(`rect`,{x:0,y:0,width:i,height:i,fill:`white`}),m]})}var R=`${M}/connect`,z={public:0,mesh:1,lan:2,"lan-ipv6":3};function B(e){switch(e.kind){case`public`:return e.interfaceKind===`vpn`?`mesh`:`public`;case`lan-ipv4`:return`lan`;case`lan-ipv6`:return`lan-ipv6`;case`loopback`:case`app-link`:return null}}function V(e){return j(e)}function H(e){return e.startsWith(`https://`)}function U(e){let t=e.flatMap(e=>{let t=B(e),n=V(e.baseUrl);return t===null||n===null?[]:[{endpoint:e,tier:t,origin:n}]}).toSorted((e,t)=>z[e.tier]-z[t.tier]||Number(t.endpoint.plausible)-Number(e.endpoint.plausible)||e.endpoint.priority-t.endpoint.priority),n=new Set;return t.flatMap(({endpoint:e,tier:t,origin:r})=>n.has(r)?[]:(n.add(r),[{origin:r,label:e.label,tier:t,secure:H(r),plausible:e.plausible}]))}function W(e,t){if(t!==null){let n=e.find(e=>e.origin===t);if(n!==void 0)return n}return e[0]??null}function G(e){let t=new URL(R);return t.searchParams.set(`hub`,e),t.toString()}n();var K=176,q={scheme:`https`};function J(){let{t:e}=N(),t=A(q);return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[l(C,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`connectPhone.title`)})]}),r(`div`,{className:`p-4 space-y-3`,children:[l(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`connectPhone.description`)}),t.isPending?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[l(y,{className:`h-3.5 w-3.5 animate-spin`}),e(`connectPhone.loading`)]}):t.isError?r(`div`,{className:`flex items-start gap-2 text-[11px] text-danger`,children:[l(_,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),r(`div`,{className:`flex-1 min-w-0 space-y-1.5`,children:[l(`div`,{className:`break-words`,children:e(`connectPhone.error`,{message:t.error.message})}),l(p,{size:`sm`,variant:`ghost`,onClick:()=>void t.refetch(),children:e(`connectPhone.retry`)})]})]}):l(Y,{candidates:U(t.data.endpoints)})]})]})}function Y({candidates:e}){let{t}=N(),[n,a]=s(null),o=W(e,n),c=i(()=>o?G(o.origin):null,[o]);if(o===null||c===null)return l(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`connectPhone.empty`)});let u=e=>t(`connectPhone.tier.${e}`),d=e.map(e=>({value:e.origin,label:`${u(e.tier)} — ${e.origin}`}));return r(`div`,{className:`flex flex-col sm:flex-row gap-4`,children:[l(k,{value:c,size:K,alt:t(`connectPhone.qrAlt`),className:`self-start`}),r(`div`,{className:`flex-1 min-w-0 space-y-3`,children:[r(`label`,{className:`block space-y-1`,children:[l(`span`,{className:`text-[11px] font-medium text-foreground`,children:t(`connectPhone.addressLabel`)}),l(x,{value:o.origin,options:d,onChange:e=>a(e.target.value)}),r(`span`,{className:`block text-[10px] text-foreground-subtle`,children:[u(o.tier),` · `,o.label]})]}),!o.secure&&l(X,{text:t(`connectPhone.insecure`)}),!o.plausible&&l(X,{text:t(`connectPhone.implausible`)}),r(`div`,{className:`space-y-1`,children:[l(`span`,{className:`text-[11px] font-medium text-foreground`,children:t(`connectPhone.linkLabel`)}),r(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[l(`code`,{className:`flex-1 min-w-0 font-mono text-[11px] text-foreground break-all select-all`,children:c}),l(h,{value:c,srLabel:t(`connectPhone.linkLabel`)})]})]}),l(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`connectPhone.signInHint`)})]})]})}function X({text:e}){return r(`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:[l(_,{className:`h-3.5 w-3.5 text-warning mt-0.5 shrink-0`}),l(`span`,{children:e})]})}n();var Z={view:{icon:S,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:ee,cls:`bg-primary/15 text-primary`},delete:{icon:f,cls:`bg-danger/15 text-danger`}};function Q(){let{user:e,logout:t}=P();if(!e)return l(I,{children:l(`div`,{className:`text-xs text-foreground-subtle`,children:`Not signed in.`})});let n=e.isAdmin,i=e.scopes??[];return r(I,{children:[r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[l(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-primary font-semibold text-base`,children:e.username.slice(0,1).toUpperCase()}),r(`div`,{className:`flex-1 min-w-0`,children:[l(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:e.username}),r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n?`Administrator`:`User`,` · session id`,` `,r(`span`,{className:`font-mono`,children:[e.id.slice(0,8),`…`]})]})]})]}),n&&r(`div`,{className:`rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5`,children:[l(b,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),r(`div`,{children:[l(`div`,{className:`font-semibold text-foreground`,children:`Unrestricted access`}),l(`p`,{className:`text-foreground-subtle mt-0.5`,children:`Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below.`})]})]}),l(te,{}),l(ne,{username:e.username}),l(re,{}),l(J,{}),i.length>0&&r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-4 py-2 border-b border-border`,children:[l(`div`,{className:`text-xs font-semibold text-foreground`,children:`Granted scopes`}),l(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Baked into your session token at login; sign out + back in to refresh after changes.`})]}),r(`div`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[l(`div`,{children:`Type`}),l(`div`,{children:`Target`}),l(`div`,{children:`Access`})]}),l(`ul`,{className:`divide-y divide-border`,children:i.map((e,t)=>r(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[l(`span`,{className:`font-mono text-foreground-subtle`,children:e.type}),l(`span`,{className:`font-mono text-foreground`,children:e.type===`device`?g(e.selector):e.target}),l(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(t=>{let n=e.access.includes(t),{icon:i,cls:a}=Z[t];return r(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${n?a:`bg-transparent text-foreground-subtle/40 line-through`}`,title:n?`Can ${t}`:`Cannot ${t}`,children:[l(i,{className:`h-3 w-3`}),t]},t)})})]},t))})]}),l(`div`,{className:`flex justify-end`,children:r(`button`,{onClick:t,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground transition-colors`,children:[l(F,{className:`h-3 w-3`}),`Sign out`]})})]})}function te(){let e=d(),[t,n]=s(``),[i,a]=s(``),[o,u]=s(``),[f,p]=s(null),m=c({mutationFn:t=>e.changeOwnPassword(t),onSuccess:()=>{p({kind:`success`,msg:`Password updated.`}),n(``),a(``),u(``)},onError:e=>{p({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),h=i.length>0&&o.length>0&&i!==o,g=i.length>0&&i.length<8,_=t.length>=1&&i.length>=8&&i===o;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[l(v,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`div`,{className:`text-xs font-semibold text-foreground`,children:`Change password`})]}),r(`div`,{className:`p-4 space-y-3`,children:[l($,{label:`Current password`,value:t,onChange:n,autoComplete:`current-password`}),l($,{label:`New password`,value:i,onChange:a,autoComplete:`new-password`,hint:`At least 8 characters.`}),l($,{label:`Confirm new password`,value:o,onChange:u,autoComplete:`new-password`}),(h||g)&&l(`div`,{className:`text-[11px] text-danger`,children:h?`Passwords do not match.`:`New password must be at least 8 characters.`}),f&&r(`div`,{className:`text-[11px] flex items-center gap-1 ${f.kind===`success`?`text-emerald-500`:`text-danger`}`,children:[f.kind===`success`?l(E,{className:`h-3 w-3`}):l(T,{className:`h-3 w-3`}),f.msg]}),l(`div`,{className:`flex justify-end`,children:r(`button`,{onClick:()=>{p(null),m.mutate({currentPassword:t,newPassword:i})},disabled:!_||m.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[m.isPending?l(y,{className:`h-3 w-3 animate-spin`}):l(D,{className:`h-3 w-3`}),`Update password`]})})]})]})}function $({label:e,value:t,onChange:n,autoComplete:i,hint:a}){return r(`div`,{className:`space-y-1`,children:[l(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),l(`input`,{type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:i,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),a&&l(`div`,{className:`text-[10px] text-foreground-subtle`,children:a})]})}function ne({username:e}){let t=d(),n=a({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>t.getOwnTotpStatus()}),f=n.data,[p,m]=s(null),[h,g]=s(``),[_,v]=s(null),[b,x]=s(!1),S=c({mutationFn:()=>t.setupOwnTotp(),onSuccess:e=>{m({secret:e.secret,otpauthUrl:e.otpauthUrl}),g(``),v(null)},onError:e=>v(e instanceof Error?e.message:`Setup failed`)}),D=c({mutationFn:e=>t.confirmOwnTotp(e),onSuccess:()=>{m(null),g(``),v(null),n.refetch()},onError:e=>v(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),O=c({mutationFn:()=>t.disableOwnTotp(),onSuccess:()=>{v(null),n.refetch()},onError:e=>v(e instanceof Error?e.message:`Disable failed`)});u(()=>{if(!b)return;let e=setTimeout(()=>x(!1),1500);return()=>clearTimeout(e)},[b]);let k=i(()=>n.isLoading?`loading`:p?`setup_in_progress`:f?.enabled?`enrolled`:`not_enrolled`,[n.isLoading,f?.enabled,p]);return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[l(C,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`div`,{className:`text-xs font-semibold text-foreground`,children:`Two-factor authentication`})]}),r(`div`,{className:`p-4 space-y-3`,children:[k===`loading`&&r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[l(y,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),k===`not_enrolled`&&r(o,{children:[l(`div`,{className:`text-xs text-foreground-subtle`,children:`2FA isn't active on your account. Enable it to require a 6-digit code from your authenticator app at every login.`}),l(`div`,{className:`flex justify-end`,children:r(`button`,{onClick:()=>{v(null),S.mutate()},disabled:S.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[S.isPending?l(y,{className:`h-3 w-3 animate-spin`}):l(C,{className:`h-3 w-3`}),`Enable 2FA`]})})]}),k===`setup_in_progress`&&p&&r(o,{children:[r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`Scan the QR code (or enter the secret manually) into your authenticator app for`,` `,l(`span`,{className:`font-mono`,children:e}),`, then enter the 6-digit code below to confirm.`]}),r(`div`,{className:`flex flex-col items-center gap-3`,children:[l(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:l(L,{value:p.otpauthUrl,size:180})}),r(`div`,{className:`w-full`,children:[l(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:`Secret (manual entry)`}),r(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[l(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:p.secret}),r(`button`,{onClick:()=>{p&&navigator.clipboard.writeText(p.secret).then(()=>x(!0))},className:`inline-flex items-center gap-1 text-[10px] text-foreground-subtle hover:text-foreground`,children:[b?l(E,{className:`h-3 w-3 text-emerald-500`}):l(w,{className:`h-3 w-3`}),b?`Copied`:`Copy`]})]})]})]}),r(`div`,{className:`space-y-1`,children:[l(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),l(`input`,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:h,onChange:e=>g(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary`})]}),_&&r(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[l(T,{className:`h-3 w-3`}),_]}),r(`div`,{className:`flex justify-end gap-2`,children:[l(`button`,{onClick:()=>{m(null),v(null),g(``)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),r(`button`,{onClick:()=>{v(null),D.mutate({code:h})},disabled:D.isPending||h.length!==6,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[D.isPending?l(y,{className:`h-3 w-3 animate-spin`}):l(E,{className:`h-3 w-3`}),`Confirm`]})]})]}),k===`enrolled`&&f&&r(o,{children:[r(`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:[l(E,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),r(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[l(`div`,{className:`font-medium`,children:`2FA is active`}),r(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,f.confirmedAt?new Date(f.confirmedAt).toLocaleString():`—`]})]})]}),_&&r(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[l(T,{className:`h-3 w-3`}),_]}),l(`div`,{className:`flex justify-end`,children:r(`button`,{onClick:()=>{v(null),O.mutate()},disabled:O.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:[O.isPending?l(y,{className:`h-3 w-3 animate-spin`}):l(C,{className:`h-3 w-3`}),`Disable 2FA`]})})]})]})]})}function re(){return m(`auth-webauthn/passkey-enrollment`)?l(O,{widgetId:`auth-webauthn/passkey-enrollment`,host:`dashboard`}):null}export{Q as MyAccessPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,b as a,o,q as s,x as c,z as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as u,ct as d,lt as f,vt as p}from"./player-overlays-B-iWFodj.js";import{$a as m,$l as h,Cn as g,Cu as _,Dt as v,Hn as y,Ja as b,Ka as x,Kl as ee,Ll as te,Nu as S,Pu as ne,Qa as C,Sl as w,Tl as T,Xa as re,Ya as ie,Za as ae,Zc as E,Zu as D,_n as O,ad as k,ao as A,au as j,bn as M,bu as N,co as P,cr as F,en as oe,eo as I,eu as L,fo as R,io as z,ju as B,lo as V,lr as H,lu as se,mo as ce,no as le,oo as ue,po as de,pu as fe,qa as pe,ro as me,so as he,tn as ge,to as _e,wt as ve,yd as ye}from"./src-D3Zan8Or.js";import{t as U}from"./boxes-Djrey7Kg.js";import{En as be,in as xe,on as Se,tn as Ce}from"./client-BomCPWqx.js";import{B as W,z as we}from"./index-CoHcNeUl.js";import{t as Te}from"./AdminPage-CiKtOLQm.js";import{t as Ee}from"./AdminTabs-C-9638Z4.js";import{t as De}from"./NodeAddonsSettingsPanel-CAP-fBly.js";import{t as G}from"./AddonCollectionPage-DkGiGxFC.js";import{t as K}from"./addon-display-names-DvSEQty-.js";var Oe=p(`file-up`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 12v6`,key:`3ahymv`}],[`path`,{d:`m15 15-3-3-3 3`,key:`15xj92`}]]),ke=p(`log-in`,[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]);n();var q=5e3,Ae={connected:!1,endpoint:null};function je(){let e=o(),t=H({capName:`network-access`},{refetchInterval:q}),n=F(void 0,{refetchInterval:q}),r=i(()=>K(n.data??[]),[n.data]),a=i(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,r]),[l,u]=s(null),[d,f]=s({}),p=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),u(null),f(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},m=(e,t)=>{u(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);f(e=>({...e,[n]:r}))},h=de({onSuccess:p,onError:m}),g=ce({onSuccess:p,onError:m});return c(G,{title:`Remote Access`,subtitle:`Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …). Settings, Logs and Events are docked under every provider.`,pageIcon:W,itemIcon:W,capability:`network-access`,installButtonLabel:`Add tunnel`,items:a,isLoading:t.isLoading,emptyTitle:`No remote-access providers installed`,emptyDescription:`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`,renderStatusBadges:e=>c(Ne,{addonId:e.addonId}),itemError:e=>d[e.addonId]??null,renderPrimaryAction:e=>c(Pe,{addonId:e.addonId,busyId:l,onStart:e=>{u(e),h.mutate({addonId:e})},onStop:e=>{u(e),g.mutate({addonId:e})}})})}function Me(e){let{data:t}=R({addonId:e},{refetchInterval:q,retry:!1}),n=t?be.safeParse(t):null;return n?.success?n.data:Ae}function Ne({addonId:e}){let t=Me(e);return r(a,{children:[c(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.connected?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.connected?`Connected`:`Disconnected`}),t.endpoint&&r(`a`,{href:t.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-[10px] text-emerald-700 dark:text-emerald-300 hover:underline flex items-center gap-1`,children:[c(D,{className:`h-3 w-3`}),t.endpoint.url]})]})}function Pe({addonId:e,busyId:t,onStart:n,onStop:i}){let a=Me(e),o=t===e;return a.connected?r(g,{size:`sm`,variant:`secondary`,disabled:o,onClick:()=>i(e),children:[o?c(S,{className:`h-3 w-3 animate-spin`}):c(d,{className:`h-3 w-3`}),`Stop`]}):r(g,{size:`sm`,variant:`primary`,disabled:o,onClick:()=>n(e),children:[o?c(S,{className:`h-3 w-3 animate-spin`}):c(N,{className:`h-3 w-3`}),`Start`]})}n();var Fe=3e4;function Ie(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function Le(){let e=H({capName:`turn-provider`},{refetchInterval:Fe}),t=F(void 0,{refetchInterval:Fe}),n=E(),a=n.data??[],o=i(()=>K(t.data??[]),[t.data]);return c(G,{title:`TURN Servers`,subtitle:`ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.`,pageIcon:_,itemIcon:_,capability:`turn-provider`,installButtonLabel:`Add provider`,items:i(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:o.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,o]),isLoading:e.isLoading,emptyTitle:`No TURN providers installed`,emptyDescription:`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`,renderExpandedPanel:e=>c(Re,{addonId:e.addonId,enabled:e.isActive}),trailing:r(O,{children:[r(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[r(`div`,{children:[c(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),c(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),c(g,{size:`sm`,variant:`secondary`,onClick:()=>n.refetch(),disabled:n.isFetching,children:`Refresh`})]}),c(`div`,{className:`p-4`,children:a.length===0?c(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):c(`div`,{className:`flex flex-col gap-3`,children:a.map((e,t)=>{let n=Array.isArray(e.urls)?e.urls:[e.urls];return r(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&r(`div`,{className:`px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3`,children:[e.username&&r(`span`,{children:[c(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,c(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&r(`span`,{children:[c(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,c(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),c(`ul`,{className:`divide-y divide-border`,children:n.map(e=>c(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function Re({addonId:e,enabled:t}){let n=E({addonId:e},{enabled:t,retry:!1}),a=i(()=>Ie(n.data??[]),[n.data]);return!t||a.length===0?null:r(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[r(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,a.length,`)`]}),c(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>c(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}n();var ze={lan:_,wifi:T,docker:U,vpn:B,loopback:j,other:j},Be={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Ve=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function He(e){let{interfaces:t,disabled:n,hideLoopback:a,ipv4Only:o,emptyMessage:s}=e,l=i(()=>t.filter(e=>!(a&&e.kind===`loopback`||o&&e.family!==`IPv4`)),[t,a,o]),u=i(()=>{let e=new Map;for(let t of l){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Ve.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[l]),d=t=>e.mode===`single`?e.value===t:e.value.includes(t),f=t=>{if(n||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let r=new Set(e.value);r.has(t.address)?r.delete(t.address):r.add(t.address),e.onChange([...r])};return l.length===0?c(`div`,{className:`text-xs text-foreground-subtle italic`,children:s??`No addresses available.`}):c(`div`,{className:`flex flex-col gap-3`,children:u.map(({kind:t,items:i})=>r(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[r(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[c(ze[t]??j,{className:`h-3.5 w-3.5 text-foreground-subtle`}),c(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:Be[t]??t}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,i.length]})]}),c(`ul`,{className:`divide-y divide-border`,children:i.map(t=>{let i=d(t.address),a=t.kind===`loopback`,o=!t.plausible&&!a;return r(`li`,{className:`flex items-center gap-3 px-3 py-2 ${a?`opacity-60 cursor-not-allowed`:n?`opacity-60`:o?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>f(t),children:[c(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${e.mode===`single`?`rounded-full`:`rounded`} border ${i?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:i&&c(ye,{className:`h-3 w-3`})}),r(`div`,{className:`flex-1 min-w-0 ${o?`text-foreground-subtle`:``}`,children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[c(`span`,{className:`font-mono text-xs font-semibold ${o?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),c(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:t.family}),t.preferred&&c(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),a&&c(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),o&&r(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[c(te,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),r(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:[t.address,t.cidr&&t.cidr!==t.address?` (${t.cidr})`:``]})]})]},`${t.name}-${t.family}-${t.address}`)})})]},t))})}function Ue(e,t){if(e===void 0)return null;let n=e.baseUrl??e.resolved,r=Se(e),i=r.form===`app`;return{flagged:n,appLink:i,appLinkHub:i?r.hubBaseUrl:null,preview:xe({base:r,destination:{kind:`camera`,deviceId:12,atMs:t}}),warning:We(r,n)}}function We(e,t){return e.form===`app`&&e.hubBaseUrl===null?`No public HTTPS address (tunnel or Tailscale) is up, so app links carry no hub address. The app still opens on a phone that already knows this hub; a new browser asks for the address once.`:e.form===`hub`&&t===null?`No reachable address is flagged, so notifications carry no tap link.`:e.form===`hub`&&t!==null&&t.startsWith(`http://`)?`This address is plain HTTP and usually only works on your own network — a notification opened away from home will not load.`:null}function Ge(e){let t=e.trim();if(t===``)return{ok:!1,error:`Enter an address.`};let n;try{n=new URL(t)}catch{return{ok:!1,error:`Not a URL — include https://.`}}return n.protocol!==`https:`&&n.protocol!==`http:`?{ok:!1,error:`Use an http:// or https:// address.`}:n.username!==``||n.password!==``?{ok:!1,error:`An address must not carry a user name or password.`}:{ok:!0,origin:n.origin}}n();function Ke({endpoint:e,saving:t,onFlag:n,nowMs:i}){let[o,l]=s(``),[u,d]=s(null),f=Ue(e,i??Date.now());return r(O,{children:[r(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between gap-3 flex-wrap`,children:[r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`text-sm font-semibold inline-flex items-center gap-1.5`,children:[c(ne,{className:`h-3.5 w-3.5`}),`Notification links`]}),r(`div`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:[`Where tapping a notification takes you. The default, `,c(`b`,{children:`CamStack app link`}),`, opens the CamStack app on the phone when it is installed and the web viewer otherwise, and carries this hub's public address so it connects to the right hub. Flag one of this hub's own addresses in the table below to link straight to it instead. Attachments, action buttons and admin pages (such as addon updates) always use this hub's own address.`]})]}),e!==void 0&&e.baseUrl!==null&&c(g,{size:`sm`,variant:`secondary`,disabled:t,onClick:()=>n(null),children:`Use default (app link)`})]}),r(`div`,{className:`p-4 flex flex-col gap-3 text-xs`,children:[f===null?c(`div`,{className:`text-foreground-subtle`,children:`Loading…`}):r(a,{children:[r(`div`,{className:`grid grid-cols-[auto_1fr] gap-x-3 gap-y-1.5 items-baseline`,children:[c(`span`,{className:`text-foreground-subtle`,children:`Links point to`}),r(`span`,{className:`font-mono break-all`,"data-testid":`notification-link-flagged`,children:[f.appLink?`CamStack app link`:f.flagged??`nothing reachable`,e?.baseUrl===null?c(`span`,{className:`ml-1.5 font-sans text-foreground-subtle`,children:`(default)`}):null]}),f.appLink&&r(a,{children:[c(`span`,{className:`text-foreground-subtle`,children:`Hub address in the link`}),c(`span`,{className:`font-mono break-all`,"data-testid":`notification-link-hub`,children:f.appLinkHub??`none — no tunnel or Tailscale address is up`})]}),c(`span`,{className:`text-foreground-subtle`,children:`Example camera tap`}),c(`span`,{className:`font-mono break-all text-foreground`,"data-testid":`notification-link-preview`,children:f.preview??`— no link —`})]}),f.warning!==null&&c(`p`,{className:`text-[11px] text-amber-600 dark:text-amber-400`,children:f.warning})]}),r(`div`,{className:`flex flex-wrap items-start gap-2 pt-1`,children:[r(`div`,{className:`flex-1 min-w-[220px]`,children:[c(ge,{value:o,onChange:e=>{l(e.target.value),d(null)},placeholder:`Custom address, e.g. https://cams.example.com`,"aria-label":`Custom notification address`,disabled:t}),u!==null&&c(`div`,{className:`mt-1 text-[11px] text-red-600 dark:text-red-400`,children:u})]}),c(g,{size:`sm`,variant:`secondary`,disabled:t||o.trim()===``,onClick:()=>{let e=Ge(o);if(!e.ok){d(e.error);return}d(null),l(``),n(e.origin)},children:`Use custom address`})]})]})]})}n();var qe={"lan-ipv4":{label:`IPv4`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`},"lan-ipv6":{label:`IPv6`,className:`bg-violet-500/15 text-violet-700 dark:text-violet-300`},public:{label:`Public`,className:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},"app-link":{label:`App link`,className:`bg-amber-500/15 text-amber-700 dark:text-amber-300`},loopback:{label:`Loopback`,className:`bg-foreground-subtle/15 text-foreground-subtle`}};function J(e){return e.kind!==`loopback`&&e.kind!==`app-link`}function Je(e){return e.kind!==`loopback`}function Ye(){let e=o(),t=u(),n=ae(void 0,{refetchInterval:3e4}),a=x(void 0),d=_e({onSuccess:()=>{e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),p=m({onSuccess:t=>{y(t.addresses),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),h=i(()=>n.data?.interfaces??[],[n.data]),_=pe({port:typeof window<`u`?Number(window.location.port)||(window.location.protocol===`https:`?443:80):4e3,scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`,includeAppLink:!0},{refetchInterval:3e4}),[v,y]=s([]),[S,ne]=s(!1);l(()=>{!S&&a.data&&(y(a.data.addresses),ne(!0))},[a.data,S]);let C=a.data?.addresses??[],w=i(()=>{if(v.length!==C.length)return!0;let e=[...v].toSorted(),t=[...C].toSorted();return e.some((e,n)=>e!==t[n])},[v,C]),T=()=>{d.mutate({addresses:[...v]})},ie=()=>{y(C)},E=()=>{y([])},D=()=>{n.refetch(),_.refetch(),a.refetch(),A.refetch(),M.refetch()},k=async()=>{try{let e=await t.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},A=b(),j=le({onSuccess:()=>void A.refetch()}),M=re(),N=me({onSuccess:()=>void M.refetch()}),P=_.data?.endpoints??[],F=A.data?.baseUrl??null,I=A.data?.resolved??null,L=A.data?.appLinkHub??null,R=M.data?.baseUrls??[],z=R.length===0,B=F===null,V=e=>z?e.kind===`lan-ipv4`||e.kind===`public`&&e.interfaceKind===`public`:R.includes(e.baseUrl),H=e=>F===null?I===e.baseUrl:F===e.baseUrl,ce=e=>{if(!J(e))return;let t=z?P.filter(e=>J(e)&&V(e)).map(e=>e.baseUrl):[...R],n=t.includes(e.baseUrl)?t.filter(t=>t!==e.baseUrl):[...t,e.baseUrl];N.mutate({baseUrls:n})},ue=e=>{if(Je(e)){if(H(e)){B||j.mutate({baseUrl:null});return}j.mutate({baseUrl:e.kind===`app-link`?null:e.baseUrl})}},de=i(()=>[{key:`url`,header:`Endpoint`,render:e=>r(`div`,{className:`min-w-0 py-0.5`,children:[c(`div`,{className:`font-mono text-[12px] break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),r(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[c(`span`,{children:e.label}),e.kind===`app-link`&&r(`span`,{className:`font-mono`,children:[`hub= `,L??`none (no tunnel or Tailscale)`]}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&c(`span`,{className:`uppercase tracking-wide`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&r(`span`,{className:`inline-flex items-center gap-1 text-amber-700 dark:text-amber-300`,title:e.plausibleReason||void 0,children:[c(te,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]})]})},{key:`kind`,header:`Kind`,nowrap:!0,render:e=>{let t=qe[e.kind]??qe.loopback;return c(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.className}`,children:t.label})}},{key:`viewer`,headerRender:()=>r(`span`,{className:`inline-flex items-center gap-1`,children:[`Viewer`,z?c(`span`,{className:`text-[10px] font-normal normal-case text-foreground-subtle`,children:`auto`}):null]}),align:`center`,nowrap:!0,width:`w-24`,render:e=>{let t=J(e);return c(`label`,{className:`inline-flex justify-center ${t?`cursor-pointer`:`cursor-not-allowed opacity-40`}`,title:e.kind===`loopback`?`Loopback is not a client route.`:e.kind===`app-link`?`The app link is not a hub address — it is only a notification link target.`:`Use this URL in the API / viewer race.`,children:c(oe,{checked:t&&V(e),disabled:!t||N.isPending,onChange:()=>ce(e),"aria-label":`Viewer: ${e.baseUrl}`})})}},{key:`notifications`,headerRender:()=>r(`span`,{className:`inline-flex items-center gap-1`,children:[`Notifications`,B?c(`span`,{className:`text-[10px] font-normal normal-case text-foreground-subtle`,children:`auto`}):null]}),align:`center`,nowrap:!0,width:`w-28`,render:e=>{let t=Je(e);return c(`label`,{className:`inline-flex justify-center ${t?`cursor-pointer`:`cursor-not-allowed opacity-40`}`,title:t?`Notification links and deep links use this address.`:`Loopback is not a client route.`,children:c(oe,{checked:t&&H(e),disabled:!t||j.isPending,onChange:()=>ue(e),"aria-label":`Notifications: ${e.baseUrl}`})})}}],[z,B,R,F,I,L,N.isPending,j.isPending,P]);return r(Te,{children:[r(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[c(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Pin which host addresses exist, then tick the destinations each URL should serve. Viewer auto is IPv4 + public; every other row (including IPv6) can be ticked on.`}),r(`div`,{className:`flex items-center gap-2 shrink-0`,children:[r(g,{size:`sm`,variant:`secondary`,onClick:D,disabled:n.isLoading,children:[c(fe,{className:`h-3 w-3 ${n.isLoading?`animate-spin`:``}`}),`Refresh`]}),c(g,{size:`sm`,variant:`secondary`,onClick:k,children:`Probe race`})]})]}),r(O,{children:[r(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between gap-3 flex-wrap`,children:[r(`div`,{children:[c(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),c(`div`,{className:`text-xs text-foreground-subtle`,children:v.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${v.length} pinned`})]}),r(`div`,{className:`flex items-center gap-1`,children:[r(g,{size:`sm`,variant:`secondary`,onClick:()=>p.mutate(void 0),disabled:p.isPending||d.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[c(ee,{className:`h-3 w-3`}),p.isPending?`Detecting…`:`Best match`]}),r(g,{size:`sm`,variant:`secondary`,onClick:E,disabled:v.length===0||d.isPending,children:[c(f,{className:`h-3 w-3`}),`Clear`]}),w&&c(g,{size:`sm`,variant:`secondary`,onClick:ie,disabled:d.isPending,children:`Discard`}),r(g,{size:`sm`,variant:`primary`,onClick:T,disabled:!w||d.isPending,children:[c(se,{className:`h-3 w-3`}),d.isPending?`Saving…`:`Save`]})]})]}),c(`div`,{className:`p-4`,children:c(He,{mode:`multiple`,interfaces:h,value:v,onChange:y,disabled:d.isPending,emptyMessage:n.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),c(Ke,{endpoint:A.data,saving:j.isPending,onFlag:e=>j.mutate({baseUrl:e})}),r(O,{children:[r(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between gap-3 flex-wrap`,children:[r(`div`,{children:[c(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints`}),c(`div`,{className:`text-xs text-foreground-subtle`,children:`Ranked URLs this hub advertises, plus the CamStack app link. Tick Viewer (many) and Notifications (one — the address notification taps open).`})]}),r(`div`,{className:`flex items-center gap-1`,children:[!z&&c(g,{size:`sm`,variant:`secondary`,disabled:N.isPending,onClick:()=>N.mutate({baseUrls:[]}),children:`Viewer → auto`}),!B&&c(g,{size:`sm`,variant:`secondary`,disabled:j.isPending,onClick:()=>j.mutate({baseUrl:null}),children:`Notifications → default`})]})]}),c(ve,{columns:de,rows:P,rowKey:e=>`${e.priority}-${e.baseUrl}`,minWidthPx:640,bordered:!1,mobileMode:`scroll`,emptyMessage:_.isLoading?`Loading…`:`No endpoints available.`,rowClassName:e=>e.plausible?void 0:`opacity-80`})]})]})}n();var Xe={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Y=5e3,Ze=3e4,Qe={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function $e(){let e=H({capName:`mesh-network`},{refetchInterval:Y}),t=F(void 0,{refetchInterval:Y}),n=i(()=>K(t.data??[]),[t.data]);return c(G,{title:`Mesh Networks`,subtitle:`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`,pageIcon:U,itemIcon:_,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:i(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No mesh-network providers installed`,emptyDescription:`Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.`,renderStatusBadges:e=>c(et,{addonId:e.addonId}),renderPrimaryAction:e=>c(tt,{addonId:e.addonId}),renderExpandedPanel:e=>c(nt,{addonId:e.addonId})})}function X(e){let{data:t,isLoading:n}=A({addonId:e},{refetchInterval:Y,retry:!1}),r=t?Ce.safeParse(t):null;return{status:r?.success?r.data:Qe,isLoading:n}}function et({addonId:e}){let{status:t}=X(e);return r(a,{children:[c(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.joined?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.joined?`Joined`:`Not joined`}),t.joined&&r(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:[t.peerCount,` peer`,t.peerCount===1?``:`s`]})]})}function tt({addonId:t}){let n=o(),[i,l]=s(!1),[d,f]=s(null),p=u(),{status:m}=X(t),h=e(()=>{n.invalidateQueries({queryKey:[[`meshNetwork`]]})},[n]),_=V(),v=ue({onSuccess:h}),y=P({onSuccess:h}),b=e(async()=>{l(!0);let e={cancelled:!1};f(e);try{let n=await _.mutateAsync({addonId:t});if(e.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!e.cancelled&&(await lt(2e3),!e.cancelled);){let e=await p.trpcClient.meshNetwork.getStatus.query({addonId:t}).catch(()=>null),n=e?Ce.safeParse(e):null;if(n?.success&&n.data.joined){h();break}if(Date.now()-r>6e5)break}}finally{l(!1),f(null)}},[t,h,_,p]),x=e(()=>{d&&(d.cancelled=!0),l(!1),f(null)},[d]);return c(a,{children:m.joined?r(a,{children:[r(g,{size:`sm`,variant:`secondary`,disabled:v.isPending,onClick:()=>v.mutate({addonId:t}),children:[v.isPending?c(S,{className:`h-3 w-3 animate-spin`}):c(we,{className:`h-3 w-3`}),`Disconnect`]}),r(g,{size:`sm`,variant:`ghost`,disabled:y.isPending,onClick:()=>y.mutate({addonId:t}),children:[y.isPending?c(S,{className:`h-3 w-3 animate-spin`}):c(L,{className:`h-3 w-3`}),`Log out`]})]}):i?r(g,{size:`sm`,variant:`ghost`,onClick:x,children:[c(w,{className:`h-3 w-3 mr-1`}),` Cancel`]}):r(a,{children:[r(g,{size:`sm`,variant:`primary`,onClick:()=>void b(),children:[c(ke,{className:`h-3 w-3`}),`Connect`]}),r(g,{size:`sm`,variant:`ghost`,disabled:y.isPending,onClick:()=>y.mutate({addonId:t}),children:[y.isPending?c(S,{className:`h-3 w-3 animate-spin`}):c(L,{className:`h-3 w-3`}),`Log out`]})]})})}function nt({addonId:e}){let{status:t}=X(e),n=he({addonId:e},{refetchInterval:Ze,retry:!1});return r(`div`,{className:`rounded-lg border border-border bg-surface`,children:[r(`div`,{className:`p-4 space-y-4`,children:[t.error&&c(M,{message:t.error}),c(rt,{status:t}),t.endpoints.length>0&&r(`div`,{className:`space-y-1.5`,children:[c(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>r(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[r(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Xe[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?c(W,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),r(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[c(D,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),c(`div`,{className:`border-t border-border`,children:c(at,{peers:n.data?.peers??[],loading:n.isLoading})})]})}function rt({status:e}){return c(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5`,children:[{label:`Tenant`,value:e.tenantName||`—`},{label:`User`,value:e.userLogin??`—`},{label:`Control plane`,value:e.controlPlaneUrl||`—`},{label:`Mesh IP`,value:e.meshIp||`—`,mono:!0},{label:`MagicDNS`,value:e.magicDnsHostname||`—`,mono:!0},{label:`DNS suffix`,value:e.magicDnsSuffix||`—`,mono:!0},{label:`Peers`,value:String(e.peerCount)},{label:`Key expiry`,value:e.keyExpiry?it(e.keyExpiry):`—`}].map(e=>r(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[c(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),c(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function it(e){let t=e-Date.now();if(t<0)return`Expired ${ct(e)}`;let n=Math.floor(t/864e5);if(n>60)return new Date(e).toLocaleDateString();if(n>1)return`in ${n} days`;let r=Math.floor(t/36e5);return r>1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))} min`}function at({peers:t,loading:n}){let a=i(()=>t.map(e=>({...e,_id:e.id})),[t]),o=e(e=>{e&&navigator.clipboard?.writeText(e)},[]),s=i(()=>[{key:`hostname`,header:`Hostname`,render:e=>r(`div`,{className:`flex flex-col`,children:[r(`div`,{className:`flex items-center gap-1.5`,children:[c(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&c(y,{variant:`info`,children:`self`}),e.exitNodeOption&&c(y,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&c(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?r(`div`,{className:`flex items-center gap-1`,children:[c(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),c(`button`,{onClick:()=>o(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:c(k,{className:`h-3 w-3 text-foreground-subtle`})})]}):c(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?r(`div`,{className:`flex items-center gap-1`,children:[c(`span`,{className:`font-mono text-xs`,children:t}),c(`button`,{onClick:()=>o(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:c(k,{className:`h-3 w-3 text-foreground-subtle`})})]}):c(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>r(`div`,{className:`flex items-center gap-1.5`,children:[c(y,{variant:ot(e.connection),children:e.connection}),e.relay&&c(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?c(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):c(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>r(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,st(e.txBytes),` · ↓ `,st(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>c(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?ct(e.lastSeenMs):`—`})}],[o]);return n&&t.length===0?r(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[c(S,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):t.length===0?c(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):c(`div`,{className:`p-4`,children:c(ve,{columns:s,rows:a,rowKey:e=>e._id,minWidthPx:820})})}function ot(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function st(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${(e/1024/1024/1024).toFixed(2)}GB`}function ct(e){let t=Date.now()-e;return t<6e4?`just now`:t<36e5?`${Math.round(t/6e4)}m ago`:t<864e5?`${Math.round(t/36e5)}h ago`:`${Math.round(t/864e5)}d ago`}function lt(e){return new Promise(t=>setTimeout(t,e))}var ut=/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/,Z=/-----BEGIN ((?:RSA |EC |ENCRYPTED )?PRIVATE KEY)-----[\s\S]+?-----END \1-----/,dt={certificate:`.pem,.crt,.cer`,privateKey:`.pem,.key`,ca:`.pem,.crt,.cer`};function Q(e,t){if(t.trim()===``)return null;if(e===`privateKey`){let e=Z.exec(t);return e===null?ut.test(t)?`This is a certificate, not a private key.`:`Not a PEM private key — expected -----BEGIN … PRIVATE KEY-----.`:e[1]===`ENCRYPTED PRIVATE KEY`?`The private key is password-protected. Export it without a passphrase.`:null}return ut.test(t)?e===`certificate`&&Z.test(t)?`This file also contains a private key. Pick the certificate file, and the key in its own field.`:null:Z.test(t)?`This is a private key, not a certificate.`:`Not a PEM certificate — expected -----BEGIN CERTIFICATE-----.`}function ft(e){return e.text()}n();function $({kind:e,label:n,value:i,onChange:a,rows:o=6}){let l=t(null),[u,d]=s(null),[f,p]=s(null),m=f??Q(e,i),h=`pem-${e}`,_=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t!==void 0){d(t.name);try{let e=await ft(t);p(null),a(e)}catch(e){p(`Could not read ${t.name}: ${e instanceof Error?e.message:String(e)}`)}}};return r(`div`,{className:`space-y-1`,children:[r(`div`,{className:`flex items-center justify-between gap-2`,children:[c(`label`,{htmlFor:h,className:`text-[11px] text-foreground-subtle`,children:n}),r(`div`,{className:`flex min-w-0 items-center gap-2`,children:[u!==null&&c(`span`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,"data-testid":`${h}-file-name`,children:u}),c(`input`,{ref:l,type:`file`,accept:dt[e],onChange:e=>void _(e),className:`hidden`,"data-testid":`${h}-file`}),r(g,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>l.current?.click(),children:[c(Oe,{className:`mr-1 h-3 w-3`}),`Choose file`]})]})]}),c(`textarea`,{id:h,value:i,onChange:e=>{d(null),p(null),a(e.target.value)},rows:o,"aria-invalid":m!==null,className:`w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`}),m!==null&&c(`p`,{className:`text-[11px] text-danger`,role:`alert`,children:m})]})}n();function pt(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function mt(){let e=o(),t=ie(void 0,{refetchInterval:15e3}),n=C({onSuccess:()=>void e.invalidateQueries({queryKey:[[`localNetwork`]]})}),i=I({onSuccess:()=>void e.invalidateQueries({queryKey:[[`localNetwork`]]})}),a=z({onSuccess:()=>{d(!1),p(``),_(``),b(``),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),l=t.data,[u,d]=s(!1),[f,p]=s(``),[m,_]=s(``),[y,b]=s(``),x=()=>{if(!l?.caCertPem)return;let e=new Blob([l.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)},ee=l?.mode===`uploaded`?`Uploaded`:l?.mode===`generated`?`Generated local CA`:`TLS disabled`;return r(`div`,{className:`flex flex-col gap-4`,children:[c(De,{nodeId:`hub`,addonIds:[`local-network`],level:`global`,title:`LAN HTTP`,description:`Native apps on this Wi-Fi use http:// and skip the private certificate. The tunnel and this admin UI stay on HTTPS.`}),r(O,{className:`p-4 space-y-3`,children:[r(`div`,{className:`flex items-center gap-2`,children:[c(h,{className:`h-4 w-4 text-foreground-subtle`}),c(`h3`,{className:`text-sm font-semibold`,children:`Certificate`})]}),t.isError&&c(`p`,{className:`text-xs text-danger`,children:`Could not read TLS status.`}),l?.reissueError&&c(`p`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:l.reissueError}),l?.restartRequired&&c(`p`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`The HTTPS listener still serves the previous certificate. Restart the hub to apply it.`}),r(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[r(`div`,{children:[c(`dt`,{className:`text-foreground-subtle`,children:`Mode`}),c(`dd`,{className:`font-medium`,children:ee})]}),r(`div`,{children:[c(`dt`,{className:`text-foreground-subtle`,children:`Valid to`}),c(`dd`,{className:`font-mono`,children:l?.validTo?new Date(l.validTo).toLocaleString():`—`})]}),r(`div`,{children:[c(`dt`,{className:`text-foreground-subtle`,children:`Leaf SHA-256`}),c(`dd`,{className:`font-mono`,title:l?.leafFingerprintSha256??void 0,children:pt(l?.leafFingerprintSha256??null)})]}),r(`div`,{children:[c(`dt`,{className:`text-foreground-subtle`,children:`CA SHA-256`}),c(`dd`,{className:`font-mono`,title:l?.caFingerprintSha256??void 0,children:l?.mode===`uploaded`&&l.caFingerprintSha256===null?c(`span`,{className:`font-sans text-foreground-subtle`,children:`Issuer not included in the upload (not the local CA)`}):pt(l?.caFingerprintSha256??null)})]})]}),l&&l.sans.length>0&&c(`div`,{className:`flex flex-wrap gap-1`,children:l.sans.map(e=>c(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 font-mono text-[10px] text-foreground-subtle`,children:e},e))}),r(`div`,{className:`flex flex-wrap gap-2`,children:[c(v,{label:`Regenerate`,title:`Issue a new leaf?`,description:`Issues a new leaf under the current local CA. Clients that trust the CA keep working. The HTTPS listener reloads.`,confirmLabel:`Regenerate`,disabled:l?.mode===`uploaded`||n.isPending,action:()=>n.mutateAsync({})}),c(g,{size:`sm`,variant:`outline`,onClick:()=>d(e=>!e),children:`Upload`}),l?.caCertPem&&c(g,{size:`sm`,variant:`outline`,onClick:x,children:`Download CA`}),l?.mode===`uploaded`&&c(v,{label:`Revert to generated`,title:`Drop the uploaded certificate?`,description:`Deletes the uploaded pair and returns to the generated local CA.`,confirmLabel:`Revert`,confirmVariant:`danger`,disabled:i.isPending,action:()=>i.mutateAsync({})})]}),u&&r(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[c($,{kind:`certificate`,label:`Certificate or full chain (PEM)`,value:f,onChange:p}),c($,{kind:`privateKey`,label:`Private key (PEM)`,value:m,onChange:_}),c($,{kind:`ca`,label:`CA (PEM, optional)`,value:y,onChange:b,rows:4}),c(g,{size:`sm`,disabled:!f.trim()||!m.trim()||Q(`certificate`,f)!==null||Q(`privateKey`,m)!==null||Q(`ca`,y)!==null||a.isPending,onClick:()=>a.mutate({certPem:f,keyPem:m,...y.trim()?{caPem:y}:{}}),children:`Save certificate`}),a.isError&&c(`p`,{className:`text-xs text-danger`,children:a.error instanceof Error?a.error.message:`Upload failed`})]})]})]})}function ht(){return c(`div`,{className:`flex flex-col p-4`,children:c(Ee,{defaultTab:`addresses`,tabs:[{id:`local-access`,label:`Local access`,icon:T,content:c(mt,{})},{id:`addresses`,label:`Network Addresses`,icon:j,content:c(Ye,{})},{id:`remote-access`,label:`Remote Access`,icon:W,content:c(je,{})},{id:`mesh`,label:`Mesh Networks`,icon:U,content:c($e,{})},{id:`turn`,label:`TURN Servers`,icon:_,content:c(Le,{})}]})})}export{ht as NetworkPage};
|