@camstack/addon-admin-ui 1.2.16 → 1.2.18
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/AddLocationWizard-BowIG3iq.js +1 -0
- package/dist/assets/{AddonCollectionPage-BM908g2f.js → AddonCollectionPage-DzUEOYUV.js} +1 -1
- package/dist/assets/Addons-B5DucodR.js +1 -0
- package/dist/assets/{AdminTabs-6yXsZXxy.js → AdminTabs-C-SMNF-6.js} +1 -1
- package/dist/assets/{AiProfiles-BD68Zj9J.js → AiProfiles-D65CezzL.js} +1 -1
- package/dist/assets/{BrokerForm-DdIHaTEB.js → BrokerForm-ENHOk64X.js} +1 -1
- package/dist/assets/{Capabilities-Bqn-RV72.js → Capabilities-dtlaxRnV.js} +1 -1
- package/dist/assets/{CapabilityBadges-DzvvSaPs.js → CapabilityBadges-QVudw7lC.js} +1 -1
- package/dist/assets/Cluster-9-Ysfuh5.js +1 -0
- package/dist/assets/{ClusterRecordingTab-z1xB2po9.js → ClusterRecordingTab-CvimJgTY.js} +1 -1
- package/dist/assets/{Dashboard-CADMRCrw.js → Dashboard-CXFEM2IR.js} +1 -1
- package/dist/assets/Data-DPmsq4Rb.js +1 -0
- package/dist/assets/DetectionIntelligence-CsY0BCKS.js +1 -0
- package/dist/assets/DeviceAggregateSection-CzThj0Vt.js +1 -0
- package/dist/assets/DeviceDetail-BWX7NeMm.js +2 -0
- package/dist/assets/{Devices-OO1Obho0.js → Devices-CdMd1Rxe.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-Dj5RZE6X.js → EmbedPlayerPage-BPMSAjgX.js} +1 -1
- package/dist/assets/Events-DlSc5xWS.js +1 -0
- package/dist/assets/{FormBuilder-D6rV90RE.js → FormBuilder-BTBth7Mm.js} +1 -1
- package/dist/assets/{Identity-CyhpFEp5.js → Identity-BkJfHHax.js} +1 -1
- package/dist/assets/IntegrationDetail-DjcVm32z.js +1 -0
- package/dist/assets/{Integrations-Cf-P7zbM.js → Integrations-BstWDI9y.js} +1 -1
- package/dist/assets/{Integrations-uId-1G3x.js → Integrations-CCkqm_Su.js} +1 -1
- package/dist/assets/{Logs-BsuRve34.js → Logs-BKvPV_wj.js} +1 -1
- package/dist/assets/{MotionZonesSettings-CDt7HiBk.js → MotionZonesSettings-C3F5tNrn.js} +1 -1
- package/dist/assets/{MyAccess-nr6vCJQp.js → MyAccess-D94hQDyr.js} +1 -1
- package/dist/assets/Network-DRjrjeQG.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-DQhn50qD.js → NodeAddonsSettingsPanel-CL75zTHK.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-DreXBx4e.js → NodeInferenceDevices-gVLIWG74.js} +1 -1
- package/dist/assets/Notifications-7spoN22j.js +1 -0
- package/dist/assets/Pipeline-Dmgt7OdK.js +1 -0
- package/dist/assets/{Plates-D93zGL-b.js → Plates-0nXxdKJX.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-CeRPYNws.js → PrivacyMaskSettings-BC6o9lqJ.js} +1 -1
- package/dist/assets/{ProviderIcon-DXM0Cs6A.js → ProviderIcon-tK6tKDtF.js} +1 -1
- package/dist/assets/Recordings-BtjWTugI.js +1 -0
- package/dist/assets/{ScanNetworkModal-DtqM9hw3.js → ScanNetworkModal-CwPUWLnW.js} +1 -1
- package/dist/assets/{Settings-DcxnlT5r.js → Settings-CmklSlYL.js} +1 -1
- package/dist/assets/{Showroom-DiNuN2DK.js → Showroom-fSzPo12F.js} +1 -1
- package/dist/assets/{Terminal-Yn1yb5UR.js → Terminal-DLULQ5yw.js} +2 -2
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DHOV12JB.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C8V797Ba.js} +1 -1
- package/dist/assets/{build-cluster-graph--dRyE6jp.js → build-cluster-graph-DIGI0NJ3.js} +2 -2
- package/dist/assets/circle-check-big-DifLR11P.js +1 -0
- package/dist/assets/clock-BXw5TTp6.js +1 -0
- package/dist/assets/{copy-BBaHyGT3.js → copy-D4StuZzs.js} +1 -1
- package/dist/assets/{debounced-invalidate-oJQtaYsH.js → debounced-invalidate-CXo5TVm0.js} +1 -1
- package/dist/assets/{dist-BfuZVKjE.js → dist-B1ZcDDOx.js} +1 -1
- package/dist/assets/dist-BqHHqLgd.js +7 -0
- package/dist/assets/{download-BARV2Xt2.js → download-Dq6V-5xf.js} +1 -1
- package/dist/assets/{face-bbox-CB0AdRxV.js → face-bbox-CnD55hf6.js} +1 -1
- package/dist/assets/{hostInit-D1YIG8Xp.js → hostInit-DyHdo8Gk.js} +1 -1
- package/dist/assets/index-BsmimqzB.js +4 -0
- package/dist/assets/index-D_09pXCE.css +2 -0
- package/dist/assets/{key-round-Cu-m43BY.js → key-round-BC8uv06u.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-7505e378.js → mf-entry-bootstrap-0-278ef480.js} +2 -2
- package/dist/assets/{pencil-C3NxLuzk.js → pencil-BuY8CueB.js} +1 -1
- package/dist/assets/{player-overlays-5vIS4o_W.js → player-overlays-CNHQKrHd.js} +1 -1
- package/dist/assets/plus-DyBHOfPx.js +1 -0
- package/dist/assets/{radio-IH3FZ-ad.js → radio-CQ2Qddgd.js} +1 -1
- package/dist/assets/{refresh-cw-DXzAUpGT.js → refresh-cw-BwbLLVV6.js} +1 -1
- package/dist/assets/remoteEntry-BQiHtOSG.js +1 -0
- package/dist/assets/{rotate-ccw-mo9YtqUE.js → rotate-ccw-D9ag3NNh.js} +1 -1
- package/dist/assets/rotate-cw-J5QBXynE.js +1 -0
- package/dist/assets/search-BLl1nrAm.js +1 -0
- package/dist/assets/{send-DUT5ZyQM.js → send-CrQGjBpn.js} +1 -1
- package/dist/assets/{server-B2_ttQ96.js → server-C-ApRIN8.js} +1 -1
- package/dist/assets/square-D5oi0WlG.js +1 -0
- package/dist/assets/{square-check-big-D5MMfdqS.js → square-check-big-D0Ns-qwF.js} +1 -1
- package/dist/assets/src-BDNLbHXL.js +67 -0
- package/dist/assets/src-SFNx0Juf.js +7 -0
- package/dist/assets/{upload-DfBkWUj-.js → upload-OKC5mQ8W.js} +1 -1
- package/dist/assets/{useEventInvalidation-tttDHu6H.js → useEventInvalidation-BHTo3YFv.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CcewkvoR.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CkMK9IKI.js} +2 -2
- package/dist/assets/{wifi-jwlQfCJ5.js → wifi-xQgrxKer.js} +1 -1
- package/dist/assets/{zap-CUnbY527.js → zap-B6f_Rmgy.js} +1 -1
- package/dist/index.html +6 -6
- package/dist/server/addon.js +452 -77
- package/package.json +1 -1
- package/dist/assets/AddLocationWizard-B_z3eUPS.js +0 -1
- package/dist/assets/Addons-D8SC8yBw.js +0 -1
- package/dist/assets/Cluster-CQhoefyJ.js +0 -1
- package/dist/assets/Data-Dk7iSdmP.js +0 -1
- package/dist/assets/DetectionIntelligence-CxKHKx0p.js +0 -1
- package/dist/assets/DeviceDetail-KFtEf0dr.js +0 -2
- package/dist/assets/Events-xEfJUDrb.js +0 -1
- package/dist/assets/IntegrationDetail-CkhuZF-B.js +0 -1
- package/dist/assets/Network-Cc-kPHj4.js +0 -1
- package/dist/assets/Notifications-BSPhogBa.js +0 -1
- package/dist/assets/Pipeline-CNL8qV10.js +0 -1
- package/dist/assets/Recordings-C5GO3GeS.js +0 -1
- package/dist/assets/circle-check-big-BUonJKZG.js +0 -1
- package/dist/assets/clock-CDpOjQuj.js +0 -1
- package/dist/assets/dist-BINwBvR-.js +0 -7
- package/dist/assets/index-B2Lt4mEF.css +0 -2
- package/dist/assets/index-DcoBSPD8.js +0 -4
- package/dist/assets/plus-zsIhHGHK.js +0 -1
- package/dist/assets/remoteEntry-CqqHuqZU.js +0 -1
- package/dist/assets/rotate-cw-RF_Q6dlG.js +0 -1
- package/dist/assets/search-BU0QQbas.js +0 -1
- package/dist/assets/square-CCYHDGJh.js +0 -1
- package/dist/assets/src-D49drDQI.js +0 -67
- package/dist/assets/src-PXZvyYDe.js +0 -7
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{$ as e,$a as t,Ai as n,An as r,Ba as i,Bn as a,Bt as o,Cn as s,D as c,Dn as l,E as u,F as d,Fr as f,Gn as p,H as m,Ha as h,Hn as g,Hr as _,Ii as v,J as y,Kn as b,Ln as x,Mn as S,Mo as C,N as w,Nn as T,O as E,On as D,P as ee,Pn as O,Q as te,Qa as ne,Rn as re,T as k,Tt as A,U as j,Un as M,Vn as ie,W as ae,Wn as N,X as P,Y as F,Z as oe,Za as se,Zi as ce,_r as le,a as I,at as ue,cn as de,co as fe,di as pe,do as me,dr as he,et as ge,f as _e,g as ve,gi as L,gn as R,ha as ye,i as be,io as xe,jn as Se,ki as Ce,l as we,ln as Te,lo as Ee,m as De,ma as Oe,n as ke,ni as Ae,no as z,o as je,oo as Me,ot as Ne,p as Pe,pi as Fe,qn as Ie,r as Le,ro as Re,rt as ze,so as Be,st as Ve,to as He,tt as Ue,u as We,vn as Ge,vr as Ke,wn as qe,y as Je,yi as Ye,yr as Xe,za as Ze,zn as Qe}from"./src-D49drDQI.js";import{I as B,K as V,Q as H,S as U,W,a as $e,b as et,o as G,q as K,t as tt,x as q,z as J}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{A as nt,D as rt,E as Y,M as it,O as at,S as ot,V as st,W as ct,j as lt,k as ut,v as dt,w as ft,x as pt}from"./src-PXZvyYDe.js";import{c as mt,k as ht,p as X,r as gt,t as _t,u as vt}from"./player-overlays-5vIS4o_W.js";import{t as yt}from"./CapabilityBadges-DzvvSaPs.js";import{n as bt,t as xt}from"./rotate-ccw-mo9YtqUE.js";import{t as St}from"./ProviderIcon-DXM0Cs6A.js";import{a as Ct,c as wt,i as Tt,n as Et,s as Dt}from"./NodeInferenceDevices-DreXBx4e.js";import{n as Ot,t as kt}from"./FormBuilder-D6rV90RE.js";import{t as At}from"./pencil-C3NxLuzk.js";import{t as jt}from"./plus-zsIhHGHK.js";import{t as Mt}from"./refresh-cw-DXzAUpGT.js";import{t as Nt}from"./rotate-cw-RF_Q6dlG.js";import{t as Pt}from"./server-B2_ttQ96.js";import{t as Ft}from"./wifi-jwlQfCJ5.js";import{A as It,J as Lt,K as Rt,L as zt,S as Bt,U as Vt,V as Ht,W as Ut,a as Wt,c as Gt,i as Kt,j as qt,m as Jt,q as Yt,r as Xt,s as Zt,t as Qt,v as $t,y as en,z as tn}from"./index-DcoBSPD8.js";import{t as nn}from"./StatusBadge-Dcr2bw58.js";import{t as rn}from"./useEventInvalidation-tttDHu6H.js";import{n as an,r as on,t as sn}from"./SchemaTabBar-BrF8ZUiR.js";import{t as cn}from"./StableTabPanel-p16epZGa.js";var ln=Ut(`circle-help`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),un=Ut(`link-2-off`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7`,key:`10o201`}],[`path`,{d:`M15 7h2a5 5 0 0 1 4 8`,key:`1d3206`}],[`line`,{x1:`8`,x2:`12`,y1:`12`,y2:`12`,key:`rvw6j4`}],[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`,key:`a6p6uj`}]]),dn=Ut(`link-2`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]),fn=Ut(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),pn=Ut(`volume-2`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]);H();function mn({parentDeviceId:e}){let{t}=Qt(),n=Rt(),r=X(),{data:i,isLoading:a,isError:o}=Ct(e),{data:s}=l({deviceId:e},{enabled:Number.isFinite(e)});if(a)return q(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:q(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(o)return q(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:q(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let c=(i??[]).filter(e=>e.display?.hidden!==!0);if(c.length===0)return null;let u=P(s?.stableId??``,c,s?.childLayout),d=u.ungrouped,f=e=>n(`/devices/${String(e)}`),p=s?.name??``,m=(e,t)=>q(y,{trpc:r.trpcClient,device:{...t,name:ge(t,p)},variant:`minimal`,onNavigate:f},e),h=d.some(e=>!!e.role),g=d.some(e=>!e.role),_=h&&!g?t(`device.accessories`,{defaultValue:`Accessories`}):!h&&g?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),v=d.length>0?U(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[q(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:_}),q(`div`,{className:`space-y-1`,children:d.map(e=>m(e.id,e))})]}):null,b=u.disabledSection===void 0?null:q(F,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:u.disabledSection.children.length,defaultOpen:!1,children:q(`div`,{className:`opacity-60 space-y-1`,children:u.disabledSection.children.map(e=>m(e.id,e))})},u.disabledSection.title);return u.sections.length===0?b===null?v:U(`div`,{className:`space-y-2`,children:[v,b]}):U(`div`,{className:`space-y-2`,children:[u.sections.map(e=>q(F,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>m(e.id,e))},e.title)),v,b]})}function hn({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){return U(`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:[q(St,{type:n,size:`lg`}),U(`div`,{children:[q(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),q(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),U(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[q(nn,{status:r?`online`:`offline`}),i.length>0&&q(yt,{capabilities:i})]}),q(`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.`})]})}function gn({deviceId:e}){let t=G(),n=de({deviceId:e},{refetchInterval:1e4,retry:!1}),r=Te({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=W(()=>_n(n.data??[]),[n.data]);return U(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[U(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[q(vn,{label:`Discovered`,value:i.total,icon:q($t,{className:`h-3.5 w-3.5`})}),q(vn,{label:`Adopted`,value:i.adopted,accent:`success`}),q(vn,{label:`Available`,value:i.available,accent:i.available>0?`primary`:void 0}),U(`button`,{type:`button`,onClick:()=>{r.mutateAsync({deviceId:e}).catch(()=>{})},disabled:r.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:[r.isPending?q(Bt,{className:`h-3.5 w-3.5 animate-spin`}):q(Mt,{className:`h-3.5 w-3.5`}),q(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),U(`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:[q(yn,{icon:q(Ft,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),q(yn,{icon:q(en,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),q(yn,{icon:q(Wt,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?q(yn,{icon:q(ln,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.unknown} unknown`}):null]})]})}function _n(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 vn({label:e,value:t,icon:n,accent:r}){return U(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${r===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:r===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[U(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,q(`span`,{className:`truncate`,children:e})]}),q(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function yn({icon:e,label:t}){return U(`span`,{className:`inline-flex items-center gap-1`,children:[e,q(`span`,{children:t})]})}function bn({deviceId:e,features:t}){return q(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:q(i,{trpc:X().trpcClient,deviceId:e,features:t})})}function xn({deviceId:e,features:t}){return q(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:q(Ze,{trpc:X().trpcClient,deviceId:e,features:t})})}H();function Sn({dev:e,busy:t,setBusy:n}){let r=e?.motionTrigger,i=vt(e?.state.motionTrigger),[a,o]=K(!1);if(!r)return null;let s=i?.enabled===!0,c=i!==void 0,l=async()=>{if(t||!c)return;let e=!s;n(!0),o(!0);try{await r.setMotionTrigger({enabled:e})}finally{n(!1),o(!1)}};return U(`button`,{type:`button`,onClick:()=>{l()},disabled:t||!c,title:c?s?`Disable trigger on motion`:`Enable trigger on motion`:`Awaiting state…`,"aria-pressed":s,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 ${s?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[q(Vt,{className:`h-3 w-3`}),q(`span`,{children:a?s?`Disabling…`:`Enabling…`:c?s?`On motion: on`:`On motion: off`:`On motion: …`})]})}H();function Z({deviceId:e,deviceType:t,features:n}){let r=X(),i=Ne(t)?.HeroCard??Ze,a=mt(r.trpcClient,e),o=vt(a?.state.deviceStatus),[s,c]=K(!1),l=o!==void 0&&o.online===!1,u=l?o.lastChangedAt:null;return U(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[l?q(`div`,{className:`flex justify-center`,children:q(ae,{lastChangedAt:u})}):null,q(i,{trpc:r.trpcClient,deviceId:e,features:n}),q(`div`,{className:`flex justify-center`,children:q(Sn,{dev:a,busy:s,setBusy:c})})]})}function Cn({deviceId:e}){let t=X(),{data:n,isLoading:r}=Tt(e),{data:i,isLoading:a}=Ct(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?q(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):q(`div`,{className:`flex h-full w-full flex-col`,children:q(j,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}var wn={[Y.Switch]:Z,[Y.Siren]:Z,[Y.Light]:Z,[Y.Sensor]:Z,[Y.Button]:Z,[Y.Hub]:gn,[Y.Cover]:bn,[Y.Valve]:Z,[Y.Humidifier]:Z,[Y.WaterHeater]:Z,[Y.Container]:Cn,[Y.Lock]:Z,[Y.Fan]:Z,[Y.Thermostat]:Z,[Y.Climate]:Z,[Y.MediaPlayer]:Z,[Y.Control]:Z,[Y.AlarmPanel]:xn,[Y.EventEmitter]:xn,[Y.Notifier]:xn,[Y.Script]:xn,[Y.Automation]:xn,[Y.Presence]:Z,[Y.Update]:Z,[Y.Vacuum]:Z,[Y.LawnMower]:Z,[Y.Weather]:Z,[Y.Image]:Z,[Y.PetFeeder]:Z};function Tn(e){return q(wn[e.deviceType]??hn,{...e})}function En(e){return I(X().trpcClient,e)}H();function Dn(e){let[t,n]=K(`idle`),[r,i]=K(null),a=V(null),o=V(null),s=V(null),c=V(!0),l=Ke(),u=le(),d=Xe(),f=B(()=>{if(a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}s.current=null},[]),p=B(async()=>{if(t===`idle`)return;n(`stopping`);let r=s.current;if(r&&e!==null)try{await Promise.race([d.mutateAsync({deviceId:e,sessionId:r}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}f(),c.current&&(n(`idle`),i(null))},[t,e,d,f]),m=B(async()=>{if(e===null||t!==`idle`&&t!==`error`)return;i(null);let r=null,f=null,m=null;try{n(`requesting-mic`),r=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),o.current=r,n(`starting`);let t=await l.mutateAsync({deviceId:e});m=t.sessionId,s.current=m,n(`connecting`),f=new RTCPeerConnection,a.current=f,f.oniceconnectionstatechange=()=>{if(!c.current)return;let e=f.iceConnectionState;e===`connected`||e===`completed`?n(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&c.current&&(i(e===`failed`?`WebRTC connection failed`:null),p())};for(let e of r.getAudioTracks())f.addTrack(e,r);await f.setRemoteDescription({type:`offer`,sdp:t.sdpOffer});let d=await f.createAnswer();await f.setLocalDescription(d);let h=f.localDescription?.sdp??d.sdp??``;await u.mutateAsync({deviceId:e,sessionId:m,sdpAnswer:h})}catch(t){let l=t instanceof Error?t.message:String(t);if(console.warn(`[intercom] start failed`,t),f)try{f.close()}catch{}if(r)for(let e of r.getTracks())try{e.stop()}catch{}if(a.current=null,o.current=null,m!==null)try{await d.mutateAsync({deviceId:e,sessionId:m})}catch{}s.current=null,c.current&&(i(l),n(`error`))}},[e,t,l,u,d,p]);return J(()=>(c.current=!0,()=>{c.current=!1;let t=s.current;if(t!==null&&e!==null&&d.mutate({deviceId:e,sessionId:t}),a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}s.current=null}),[e]),{state:t,error:r,start:m,stop:p,isTalking:t===`talking`}}H();var On=0;function Q(){return++On}function kn(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function An(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 jn(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 Mn(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 Nn({scope:e,greeting:t,className:n}){let r=X(),[i,a]=K(()=>{let n=[];return t&&n.push({id:Q(),kind:`info`,text:t}),n.push({id:Q(),kind:`info`,text:`scope: ${kn(e)} — type help or context for available commands`}),n}),[o,s]=K(``),[c,l]=K([]),[u,d]=K(-1),f=V(null),p=V(null);J(()=>{let e=p.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let m=B(()=>{f.current?.focus()},[]),h=tt({mutationFn:t=>r.trpcClient.repl.execute.mutate({code:t,scope:e}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;a(e=>[...e,{id:Q(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);a(e=>[...e,{id:Q(),kind:`error`,text:t}])}});function g(t){let n=t.trim();if(n){if(n===`clear`){a([{id:Q(),kind:`info`,text:`scope: ${kn(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...An(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...Mn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...jn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}l(e=>[...e,n]),d(-1),a(e=>[...e,{id:Q(),kind:`input`,text:`> ${n}`}]),s(``),h.mutate(n)}}function _(t){if(t.key===`Enter`){t.preventDefault(),g(o);return}if(t.key===`ArrowUp`){if(t.preventDefault(),c.length===0)return;let e=u===-1?c.length-1:Math.max(0,u-1);d(e),s(c[e]??``);return}if(t.key===`ArrowDown`){if(t.preventDefault(),u===-1)return;let e=u+1;e>=c.length?(d(-1),s(``)):(d(e),s(c[e]??``));return}t.ctrlKey&&t.key===`l`&&(t.preventDefault(),a([{id:Q(),kind:`info`,text:`scope: ${kn(e)}`}]))}let v={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return U(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??``}`,onClick:m,children:[U(`div`,{ref:p,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[i.map(e=>q(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${v[e.kind]}`,children:e.text},e.id)),h.isPending&&q(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),U(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[q(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),q(`input`,{ref:f,value:o,onChange:e=>s(e.target.value),onKeyDown:_,disabled:h.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 Pn({deviceId:e,intercomAvailable:t=!1}){let n=X(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),a=En(i?e:null),{streams:o,pipelineMetrics:s,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h}=be(n.trpcClient,i?e:null),g=te(n.trpcClient,i?e:null),_=Dn(i&&t?e:null),v=_.state===`requesting-mic`||_.state===`starting`||_.state===`connecting`||_.state===`stopping`,y=_.isTalking||v,b=()=>{_.state===`idle`||_.state===`error`?_.start():_.state!==`stopping`&&_.stop()},x=gt(),S=E(),C=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,w=x.length>0?q(et,{children:x.map(e=>q(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return q(Je,{serverUrl:r,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h,...S.request?{playbackUrl:S.request.url,playbackAuthToken:C,...S.request.label?{playbackLabel:S.request.label}:{},onExitPlayback:()=>S.clear()}:{},streams:o,pipelineMetrics:s,phase:a.phase,detections:a,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:g.src,...g.src?{posterUrl:g.src}:{},snapshotLoading:g.loading,onRefreshSnapshot:g.refresh,intercomAvailable:t,intercomShown:y,onIntercomToggle:b,extraOverlay:w,chromeless:!0,className:`h-full`})}function Fn({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full`,children:q(ve,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):U(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function In({deviceId:e}){if(!Number.isFinite(e))return U(`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 q(Nn,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function Ln({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(De,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):U(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Rn({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(_e,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):U(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function zn({deviceId:e}){let t=G(),n=Number.isFinite(e),{data:r}=l({deviceId:e},{enabled:n}),i=typeof r?.type==`string`?r.type:`camera`;rn([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:a,isLoading:o,isError:s,error:c}=qe({deviceId:e},{enabled:n}),{data:u}=T({deviceType:i},{enabled:!!i}),d=p({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(o)return q(`div`,{className:`p-4`,children:q(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(s)return U(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,c instanceof Error?c.message:String(c)]});let f=new Map,m={};for(let e of u??[])m[e.capName]=e.wrappers;for(let e of a?.entries??[])f.set(e.capName,{...e,wrappers:m[e.capName]??[]});for(let e of u??[])f.has(e.capName)||f.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let h=[...f.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(h.length===0)return U(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[q(bt,{className:`h-8 w-8 opacity-40`}),q(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),q(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let g=h.filter(e=>e.kind!==`unbound`).length;return U(`div`,{className:`flex flex-col gap-3 p-1`,children:[U(`div`,{className:`text-[11px] text-foreground-subtle`,children:[q(`span`,{className:`font-medium text-foreground`,children:g}),` of `,h.length,` capabilit`,h.length===1?`y`:`ies`,` bound — rows marked `,q(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),q(Re,{columns:[{key:`capability`,header:`Capability`,render:e=>q(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>q(Bn,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>q(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||q(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?q(Vn,{nodeId:e.providerNodeId}):q(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>q(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||q(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return q(Hn,{wrappers:t.wrappers,activeWrapperId:n,disabled:d.isPending,onPick:r=>{let i=n===r;d.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:h,rowKey:e=>e.capName,minWidthPx:720})]})}function Bn({kind:e}){return e===`native`?U(`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:[q(Pt,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?U(`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:[q(wt,{className:`h-3 w-3`}),`wrapped`]}):e===`linked`?U(`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:[q(dn,{className:`h-3 w-3`}),`linked`]}):U(`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:[q(Dt,{className:`h-3 w-3`}),`unbound`]})}function Vn({nodeId:e}){return q(`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 Hn({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){return e.length===0?q(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):q(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let i=e===t;return U(`button`,{disabled:n,onClick:()=>r(e),title:i?`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 ${i?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[q(i?zt:xt,{className:`h-3 w-3`}),e]},e)})})}H();function Un({schema:e,values:t,pendingKeys:n,onChange:r,onAction:i,onSave:a,onDiscard:o,disabled:s,activeSubTab:c,onSubTabChange:l,flattenTabs:u=!1,deviceId:d}){let f=e.tabs??[],p=W(()=>{let t=new Map;for(let n of e.sections){let e=n.tab??`general`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t},[e.sections]),m=new Set(f.map(e=>e.id)),h=[...f,...[...p.keys()].filter(e=>!m.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],g=h[0]?.id??`general`,[_,v]=K(g),y=l!==void 0,b=new Set(h.map(e=>e.id)),x=y?c&&b.has(c)?c:g:b.has(_)?_:g,S=e=>{y?l(e):v(e)},C=p.get(x)??[],w={sections:C.length<=1?C.length===1?[{...C[0],title:``}]:C:C.every(e=>!e.title)?[{...C[0],title:``,fields:C.flatMap(e=>e.fields)}]:C},T=q(an,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>o(n),saving:s});if(u||h.length<=1)return U(`div`,{className:`flex flex-col gap-3`,children:[q(kt,{schema:e,values:t,onChange:r,onAction:i,disabled:s,deviceId:d}),T]});let E=new Map,D=new Map;for(let[e,t]of p){E.set(e,t.length);let r=new Set,i=e=>{for(let t of e)if(`key`in t&&typeof t.key==`string`&&r.add(t.key),t.type===`group`)i(t.fields);else if(t.type===`sub-tabs`)for(let e of t.tabs)i(e.fields)};for(let e of t)i(e.fields);let a=n.filter(e=>r.has(e)).length;a>0&&D.set(e,a)}return U(`div`,{className:`flex flex-col gap-3`,children:[q(sn,{tabs:h.map(e=>({id:e.id,label:e.label})),activeId:x,onChange:S,countByTab:E,pendingByTab:D}),q(cn,{tabKey:x,children:q(kt,{schema:w,values:t,onChange:r,onAction:i,disabled:s,deviceId:d})}),T]})}var Wn=`device-export`,Gn=`export`,Kn=`Export`;function qn(e){return e.type===`separator`||e.type===`info`||e.type===`object-array`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`?!1:e.type===`group`?e.fields.some(qn):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(qn)):e.writerCapName===Wn}function Jn(e){return e.fields.some(qn)}H();function Yn(e,t){return t&&t===`admin`?e:!0}function Xn(e){if(!e)return null;let t={sections:[...e.sections].toSorted((e,t)=>{let n=e.tab??`general`,r=t.tab??`general`;return n===r?Jn(e)&&Jn(t)?e.id.localeCompare(t.id):(e.order??0)-(t.order??0):n.localeCompare(r)})};return e.tabs?{...t,tabs:e.tabs}:t}function Zn(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`}function Qn(e){return e.key}function $n(e){if(!Zn(e))return e.value}function er(e){return Zn(e)?null:e}function tr(e,t){for(let n of e)if(t(n),n.type===`group`)tr(n.fields,t);else if(n.type===`sub-tabs`)for(let e of n.tabs)tr(e.fields,t)}function nr(e){if(!e)return{};let t={};for(let n of e.sections)tr(n.fields,e=>{let n=Qn(e);n!==null&&(t[n]=$n(e))});return t}function rr(e,t){if(!e)return null;let n=null;for(let r of e.sections)if(tr(r.fields,e=>{if(n!==null||Qn(e)!==t)return;let r=er(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function ir(e){return{...e,fields:e.fields.map(ar)}}function ar(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function or(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=er(e);return n?Yn(t,n.minRole)?e:ar(e):e})}))}}function sr({deviceId:e,sectionFilter:t,activeSubTab:n,onSubTabChange:r,flattenSubTabs:i,subTabGrouping:a}){let o=G(),{user:s}=Xt(),c=s?.isAdmin===!0,u=V(!1),{data:d,isLoading:f}=D({deviceId:e},{refetchInterval:()=>u.current?!1:2500,enabled:Number.isFinite(e)}),{data:p}=l({deviceId:e},{enabled:Number.isFinite(e)}),m=d?.settings??null,h=d?.live??null,g=W(()=>{if(!m&&!h)return null;let e=m?.sections??[],n=(h?.sections??[]).map(ir),r=[...e,...n],i=t?r.filter(t):r.filter(e=>e.location!==`top-tab`&&!Jn(e));if(i.length===0)return null;if(a){let e=i.map(e=>({...e,tab:a.groupOf(e)})),t=new Set(e.map(e=>e.tab)),n=a.tabs.filter(e=>t.has(e.id));return n.length>0?{tabs:n,sections:e}:{sections:e}}let o=new Set;for(let e of i)o.add(e.tab??`general`);let s=[...m?.tabs??[],...(h?.tabs??[]).filter(e=>!(m?.tabs??[]).some(t=>t.id===e.id))].filter(e=>o.has(e.id));return s.length>0?{tabs:s,sections:i}:{sections:i}},[m,h,t,a]),_=W(()=>Xn(g),[g]),v=W(()=>or(_,c),[_,c]),y=W(()=>nr(v),[v]),x=ye(),S=Oe(),C=b(),w=re(),T=Ie({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),E={isPending:T.isPending,mutate:t=>{T.mutate({deviceId:e,changes:[...t]})}},ee=on({schema:v,serverValues:y,onImmediateSave:B(e=>{let t=Object.entries(e).map(([e,t])=>{let n=rr(v,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&E.mutate(t)},[v,E]),onDeferredSave:B(e=>{let t=Object.entries(e).map(([e,t])=>{let n=rr(v,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&E.mutate(t)},[v,E])}),{values:O,pendingKeys:te,handleChange:ne,handleSave:k,handleDiscard:A}=ee;if(u.current=ee.editingPaused,f)return U(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[q(Bt,{className:`h-4 w-4 animate-spin mr-2`}),q(`span`,{className:`text-xs`,children:`Loading device aggregate…`})]});if(!v||v.sections.length===0)return q(`div`,{className:`text-xs text-foreground-subtle italic py-4 text-center`,children:`No aggregate contributions for this device.`});async function j(t,n,r){if(t===`regenerate-rtsp-token`){let t=[`rtspUrl:`,`regenerateToken:`].find(e=>n.startsWith(e));if(!t)throw Error(`regenerate-rtsp-token: unrecognised key "${n}" (expected "rtspUrl:<streamId>" or "regenerateToken:<streamId>")`);let r=n.slice(t.length);if(!r)throw Error(`regenerate-rtsp-token: key "${n}" has no streamId after prefix`);let i=st(e,r);await x.mutateAsync({brokerId:i}),o.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(t===`test-probe`){if(!p)return{status:`error`,error:`Device metadata not loaded yet`};try{return await C.mutateAsync({addonId:p.addonId,type:p.type,key:n,value:r})}catch(e){return{status:`error`,error:e instanceof Error?e.message:String(e)}}}if(t===`refresh-probe`){if(!n.startsWith(`probedInfo:`))throw Error(`refresh-probe: unrecognised key "${n}" (expected "probedInfo:<streamId>")`);let t=n.slice(11);if(!t)throw Error(`refresh-probe: key "${n}" has no streamId after prefix`);let r=st(e,t),i=await S.mutateAsync({brokerId:r});return o.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),i}if(t===`device-custom-action`){let t=await w.mutateAsync({deviceId:e,action:n,input:r});return o.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),t}throw Error(`[device-aggregate] unknown action "${t}"`)}return q(Un,{schema:v,values:O,pendingKeys:te,onChange:ne,onAction:j,onSave:k,onDiscard:A,disabled:E.isPending,activeSubTab:n,onSubTabChange:r,flattenTabs:i,deviceId:e})}function cr({deviceId:e,activeSubTab:t,onSubTabChange:n}){return q(`div`,{className:`flex flex-col gap-3`,children:q(sr,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}H();var lr=new Set([`package-detection`]);function ur(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 dr(e){return e?e.modelId!==void 0||e.settings!==void 0:!1}function fr({deviceId:e,refreshToken:r}){let i=G(),a=X().trpcClient,[o,s]=K(null),[c,l]=K(null),[u,d]=K(null),f=pe({deviceId:e},{refetchOnMount:`always`}),p=Fe({deviceId:e},{refetchOnMount:`always`}),m=Ye(void 0,{refetchOnMount:`always`});rn([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let h=_(void 0,{refetchOnMount:`always`}),g=W(()=>{let e=new Set;for(let t of h.data??[])t.isOnline&&e.add(t.id);return e},[h.data]),v=W(()=>(m.data??[]).filter(e=>g.has(e.nodeId)).map(e=>e.nodeId),[m.data,g]),y=v[0]??``,b=Ae({nodeId:y},{enabled:y!==``,refetchOnMount:`always`}),x=$e({enabled:v.length>0,queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`],`device-step`,v.join(`,`),r],queryFn:async()=>{let e={};for(let t of v)try{e[t]=(await a.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:t})).devices}catch{e[t]=[]}return e}}),S=()=>{i.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),i.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]})},C=Ce({onSuccess:S}),w=n({onSuccess:S}),T=W(()=>b.data?He(b.data):[],[b.data]),E=W(()=>{let e=m.data??[],t=g.size===0?[]:e.filter(e=>g.has(e.nodeId)),n=[];for(let e of t){let t=(x.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:Et(r).label});else n.push({agentNodeId:e.nodeId,engineLabel:t[0]?.format??`(engine unknown)`})}return n},[m.data,x.data,g]),D=(e,t)=>x.data?.[e]?.find(e=>e.key===t)??null,ee=e=>{if(e.deviceKey!==void 0)return e.deviceKey;let t=x.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},O=(e,t,n)=>p.data?.[e]?.[t]?.[n]??null,te=e=>{if(lr.has(e))return{kind:`zone-driven`};let t=ur(b.data??null,e)?.enabledByDefault??!0,n=f.data?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},re=(e,t)=>{let n=ur(b.data??null,e),r=t?.format;if(!(!n||r===void 0))return(n.slot===`detector`?t?.defaultModelId:void 0)??se(n,r)},k=(e,t)=>{let n=te(e),r=n.kind===`gate`?n.effectiveOn:!1,i=ur(b.data??null,e),a=ee(t),o=a===null?null:D(t.agentNodeId,a),s=o?.format;if(!(i?.models.some(e=>s!==void 0&&!!e.formats[s])??!1))return r?{kind:`skip`}:{kind:`na`};let c=a===null?null:O(t.agentNodeId,a,e),l=o?.steps?.[e];return{kind:`enabled`,modelId:c?.modelId??l?.modelId??re(e,o)??`Auto`,overridden:dr(c)}},A=o&&b.data?ur(b.data,o.addonId):null,j=o?D(o.agentNodeId,o.deviceKey):null,M=j?.format??`coreml`,ie=o?dr(O(o.agentNodeId,o.deviceKey,o.addonId)):!1,ae=o?re(o.addonId,j):void 0,N=W(()=>{if(!o||!j)return null;let e=j.steps?.[o.addonId];return{enabled:!0,...e?.modelId===void 0?{}:{modelId:e.modelId},settings:e?.settings??{}}},[o,j]),P=()=>{s(null),l(null)},F=(e,t)=>{let n=ee(t);n!==null&&(s({addonId:e,agentNodeId:t.agentNodeId,deviceKey:n}),l(O(t.agentNodeId,n,e)))},oe=(t,n)=>{w.mutate({deviceId:e,addonId:t,enabled:n})},ce=()=>{o&&C.mutate({deviceId:e,agentNodeId:o.agentNodeId,deviceKey:o.deviceKey,addonId:o.addonId,patch:c},{onSuccess:P})},le=()=>{o&&C.mutate({deviceId:e,agentNodeId:o.agentNodeId,deviceKey:o.deviceKey,addonId:o.addonId,patch:null},{onSuccess:P})};if(m.isLoading||y!==``&&b.isLoading)return q(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(E.length===0)return q(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`No online agents.`});if(!b.data)return q(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let I=o!==null&&A!==null&&j!==null;return U(`div`,{className:`relative h-full w-full space-y-3`,children:[U(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[q(`span`,{className:`font-medium text-foreground`,children:`Gate`}),` (col 1) decides whether this camera runs a step — independent of nodes. Each`,` `,q(`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 `,q(`span`,{className:`text-amber-500`,children:`⚠ skip`}),` `,`and won't run there.`]}),U(`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:[q(`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.`]}),q(`div`,{className:I?`md:pr-[360px]`:``,children:T.length>0?q(ne,{tree:T,agents:E,gateFor:te,getCellState:k,onCellClick:F,selectedCell:o,onSetGate:oe,gateBusy:w.isPending,fallbackNodeId:u,onFallbackNodeChange:d}):q(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),q(z,{open:I,onClose:P,title:A?.name??``,subtitle:o&&j?`${o.agentNodeId} · ${Et(j).label} · ${j.format}`:``,footer:U(et,{children:[q(`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:!ie||C.isPending,onClick:le,children:`Clear override`}),q(`div`,{className:`flex-1`}),q(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:P,children:`Cancel`}),q(`button`,{type:`button`,disabled:!o||!N||C.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:ce,children:C.isPending?`Saving…`:`Save`})]}),children:A&&o&&N?q(t,{mode:`device`,addon:A,agentDefault:N,agentNodeId:o.agentNodeId,currentPatch:c,engineFormat:M,effectiveModelId:ae,onChangePatch:l}):q(`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 pr=[{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`}],mr={"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 hr(e){return mr[e]??`object-detection`}H();var gr=`steps`,_r=`settings`,vr=new Set([gr,_r]);function yr(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function br({deviceId:e,activeSubTab:t,onSubTabChange:n}){return U(Me,{value:t&&vr.has(t)?t:gr,onValueChange:B(e=>{n?.(e)},[n]),className:`flex flex-col`,children:[U(fe,{className:`flex-shrink-0`,children:[q(Ee,{value:gr,children:`Steps`}),q(Ee,{value:_r,children:`Settings`})]}),q(Be,{value:gr,children:q(fr,{deviceId:e,refreshToken:0})}),q(Be,{value:_r,children:q(sr,{deviceId:e,sectionFilter:yr,subTabGrouping:{groupOf:e=>hr(e.id),tabs:pr}})})]})}function $({label:e,value:t}){return U(`div`,{className:`${ht} flex items-start gap-2 sm:gap-3`,children:[q(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),q(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}H();function xr({deviceId:e,initialName:t}){let n=G(),[r,i]=K(!1),[a,o]=K(t),[s,c]=K(!1),l=V(null);J(()=>{r||o(t)},[t,r]),J(()=>{r&&l.current?.focus()},[r]);let u=g({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),d=async()=>{let n=a.trim();if(n.length===0||n===t){i(!1),o(t);return}c(!0);try{await u.mutateAsync({deviceId:e,name:n}),i(!1)}catch{}finally{c(!1)}},f=()=>{o(t),i(!1)};return r?q($,{label:`Name`,value:U(`div`,{className:`flex items-center gap-1`,children:[q(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?d():e.key===`Escape`&&f()},disabled:s,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),q(`button`,{type:`button`,onClick:()=>void d(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:q(zt,{className:`h-3 w-3`})}),q(`button`,{type:`button`,onClick:f,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:q(Kt,{className:`h-3 w-3`})})]})}):q($,{label:`Name`,value:U(`div`,{className:`flex items-center gap-2 group`,children:[q(`span`,{className:`truncate`,children:t}),q(`button`,{type:`button`,onClick:()=>i(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit name`,children:q(At,{className:`h-3.5 w-3.5`})})]})})}H();function Sr({deviceId:e,initialLocation:t}){let n=G(),[r,i]=K(!1),[a,o]=K(t??``),[s,c]=K(!1),l=V(null),{data:u}=O(void 0,{enabled:r}),d=u??[];J(()=>{r||o(t??``)},[t,r]),J(()=>{r&&l.current?.focus()},[r]);let f=ie({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),p=W(()=>{let e=a.trim().toLowerCase();return e.length===0?d:d.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[d,a]),m=a.trim().length>0&&!d.some(e=>e.toLowerCase()===a.trim().toLowerCase()),h=async n=>{let r=(n??a).trim(),o=r.length===0?null:r;if(o===(t??null)){i(!1);return}c(!0);try{await f.mutateAsync({deviceId:e,location:o}),i(!1)}catch{}finally{c(!1)}},g=()=>{o(t??``),i(!1)};return r?q($,{label:`Location`,value:U(`div`,{className:`relative`,children:[U(`div`,{className:`flex items-center gap-1`,children:[q(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?h():e.key===`Escape`&&g()},disabled:s,placeholder:`Room / area (or leave empty to clear)`,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),q(`button`,{type:`button`,onClick:()=>void h(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:q(zt,{className:`h-3 w-3`})}),q(`button`,{type:`button`,onClick:g,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:q(Kt,{className:`h-3 w-3`})})]}),(p.length>0||m)&&U(`div`,{className:`absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md`,children:[p.map(e=>U(`button`,{type:`button`,onClick:()=>{o(e),h(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[q(Ot,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),q(`span`,{className:`truncate`,children:e})]},e)),m&&U(`button`,{type:`button`,onClick:()=>void h(),className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover border-t border-border`,children:[q(`span`,{className:`text-foreground-subtle`,children:`Create`}),U(`span`,{className:`font-medium truncate`,children:[`"`,a.trim(),`"`]})]})]})]})}):q($,{label:`Location`,value:U(`div`,{className:`flex items-center gap-2 group`,children:[t?q(`span`,{className:`truncate`,children:t}):q(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),q(`button`,{type:`button`,onClick:()=>i(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit location`,children:q(At,{className:`h-3.5 w-3.5`})})]})})}H();function Cr({deviceId:e}){let t=G(),{data:n}=Tt(e),{data:r}=Ct(e),[i,a]=K(null),o=M({onSuccess:()=>{a(null),t.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{a(`Could not change primary child: ${e.message}`)}});if(n==null||String(n.type??``)!==Y.Container)return null;let s=(r??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}}));if(s.length<=1)return null;let c=ue(s,typeof n.linkDeviceId==`number`?n.linkDeviceId:null,typeof n.primaryChildEntityId==`string`?n.primaryChildEntityId:null);return U(et,{children:[q($,{label:`Primary child`,value:q(m,{childrenList:s,selectedId:c===null?s[0].id:c.id,onSetPrimary:t=>o.mutate({deviceId:e,primaryChildEntityId:t}),disabled:o.isPending})}),i!==null&&q(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:i})]})}H();var wr=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function Tr(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function Er(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function Dr(){let e=ee(),t=d(),{data:n}=l({deviceId:e??0},{enabled:e!==null}),{data:r}=qe({deviceId:e??0},{enabled:e!==null}),i=n??t??null,[a,o]=K(`identity`);if(e===null||!i)return null;let s=String(i.stableId??``),c=String(i.name??``),u=String(i.type??``),f=String(i.addonId??``),p=i.features??[],m=new Set([`device-status`,`feature-probe`,`device-ops`]),h=(r?.entries??[]).filter(e=>e.kind===`native`&&!m.has(e.capName)).map(e=>e.capName),g=p.length>0?p:h,_=i.location??null,v=i.metadata??null,y=v!==null&&Object.keys(v).length>0;return U(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[U(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[q(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),y&&U(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[q(Or,{active:a===`identity`,onClick:()=>o(`identity`),label:`Identity`}),q(Or,{active:a===`hardware`,onClick:()=>o(`hardware`),label:`Hardware`})]})]}),(!y||a===`identity`)&&U(`div`,{className:`divide-y divide-border`,children:[q($,{label:`ID`,value:U(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${e}`,U(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,s,`)`]})]})}),q(xr,{deviceId:e,initialName:c}),q(Sr,{deviceId:e,initialLocation:_}),q(Cr,{deviceId:e}),q($,{label:`Type`,value:u}),q($,{label:`Provider`,value:q(St,{type:f,size:`sm`,showLabel:!0})}),q($,{label:`Capabilities`,value:g.length>0?q(yt,{capabilities:g,showLabels:!0}):q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),y&&a===`hardware`&&q(kr,{metadata:v})]})}function Or({active:e,onClick:t,label:n}){return q(`button`,{type:`button`,onClick:t,className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${e?`bg-surface text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`}`,children:n})}function kr({metadata:e}){let t=wr.filter(t=>t in e),n=Object.keys(e).filter(e=>!wr.includes(e)).toSorted(),r=[...t,...n];return U(`div`,{children:[q(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-b border-border bg-surface-subtle/40`,children:`Auto-populated by the driver on every connect. Read-only.`}),q(`div`,{className:`divide-y divide-border`,children:r.map(t=>q($,{label:Tr(t),value:q(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:Er(e[t])})},t))})]})}H();function Ar({deviceId:e}){let[t,n]=K(null),r=R({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 U(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[U(`div`,{className:`flex items-center justify-between gap-3`,children:[U(`div`,{children:[q(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),q(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),U(`button`,{type:`button`,disabled:r.isPending,onClick:()=>{n(null),r.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:[q(Mt,{className:`h-3 w-3 ${r.isPending?`animate-spin`:``}`}),r.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&q(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}H();var jr={icon:``,label:``,unit:``,precision:``,hidden:!1};function Mr(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function Nr(e){if(typeof e!=`object`||!e)return;let t=e.unit;return typeof t==`string`?t:void 0}function Pr(e){let t=e.precision.trim()===``?void 0:Number.parseInt(e.precision,10),n={...e.icon===``?{}:{icon:e.icon},...e.label.trim()===``?{}:{label:e.label.trim()},...e.unit===``?{}:{unit:e.unit},...t!==void 0&&Number.isFinite(t)?{precision:t}:{},...e.hidden?{hidden:!0}:{}};return Object.keys(n).length===0?null:n}function Fr({deviceId:e}){let t=X(),n=G(),{data:i}=l({deviceId:e},{enabled:e>0}),o=typeof i?.role==`string`?i.role:null,s=o===null?void 0:Ve[o],c=s?.kind===`numeric`,u=ke(t.trpcClient,e,o??``),d=s?.kind===`numeric`?s.canonicalUnit:void 0,f=Nr(u)??d,p=f===void 0?void 0:pt(f),m=W(()=>p===void 0?[]:ot(p),[p]),[h,g]=K(null),_=h??Mr(i?.display),v=a({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:y}=r({},{staleTime:6e4}),b=N({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(i===void 0||o===null)return null;let x=e=>{g({..._,...e})},S=()=>{v.mutate({deviceId:e,display:Pr(_)})},C=()=>{g(jr),v.mutate({deviceId:e,display:null})},w=()=>{let e={..._.icon===``?{}:{icon:_.icon},..._.unit===``?{}:{unit:_.unit},..._.precision.trim()!==``&&Number.isFinite(Number.parseInt(_.precision,10))?{precision:Number.parseInt(_.precision,10)}:{}},t={...y?.defaults??{},[o]:e};b.mutate({defaults:t})},T=ze(o).label,E=Object.keys(Ue);return U(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[q(`div`,{className:`border-b border-border px-4 py-2`,children:q(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Display`})}),U(`div`,{className:`p-4 space-y-3`,children:[U(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Icon`}),U(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:_.icon,onChange:e=>x({icon:e.target.value}),children:[U(`option`,{value:``,children:[`Default (`,T,`)`]}),E.map(e=>q(`option`,{value:e,children:e},e))]})]}),U(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Label`}),q(`input`,{type:`text`,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:T,value:_.label,onChange:e=>x({label:e.target.value})})]}),c&&U(`div`,{className:`grid grid-cols-2 gap-3`,children:[U(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Unit`}),U(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:_.unit,onChange:e=>x({unit:e.target.value}),disabled:m.length===0,children:[U(`option`,{value:``,children:[`Source`,f?` (${f})`:``]}),m.map(e=>q(`option`,{value:e,children:e},e))]})]}),U(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Precision`}),q(`input`,{type:`number`,min:0,max:10,step:1,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:`inherit`,value:_.precision,onChange:e=>x({precision:e.target.value})})]})]}),U(`label`,{className:`flex items-center gap-2`,children:[q(`input`,{type:`checkbox`,checked:_.hidden,onChange:e=>x({hidden:e.target.checked})}),q(`span`,{className:`text-sm text-foreground`,children:`Hide from device lists`})]}),U(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[q(`button`,{type:`button`,className:`rounded bg-primary px-3 py-1 text-sm font-medium text-primary-foreground disabled:opacity-50`,onClick:S,disabled:v.isPending,children:`Save`}),q(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:C,disabled:v.isPending,children:`Reset`}),U(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:w,disabled:b.isPending,title:`Apply this unit / precision / icon as the default for every ${T} sensor`,children:[`Set as default for all `,T,` sensors`]})]})]})]})}function Ir(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function Lr({device:e}){let t=Rt(),n=typeof e.id==`number`?e.id:null,r=String(e.type??``),i=r===Y.Camera,a=r===Y.Hub,o=typeof e.role==`string`&&e.role.length>0,s=e.features??[],c=s.includes(ft.Resyncable),{data:l}=f({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),u=l?.streams??{},d=Object.entries(u),p=s.includes(ft.DoorbellButton),m=Le(p?{deviceId:n??void 0,historyLimit:10}:void 0),h=m.latest?Date.now()-m.latest.timestamp<3e4:!1;return U(`div`,{className:`space-y-5`,children:[a&&n!==null&&q(Pe,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),c&&n!==null&&q(Ar,{deviceId:n}),i&&n!==null&&q(k,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),p&&q(We,{history:m.history,latestIsFresh:h}),i&&n!==null&&q(k,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),i&&d.length>0&&U(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[q(`div`,{className:`border-b border-border px-4 py-2`,children:q(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),q(`div`,{className:`divide-y divide-border`,children:d.map(([e,t])=>U(`div`,{className:`px-4 py-2.5`,children:[U(`div`,{className:`flex items-center gap-2 mb-2`,children:[q(Ft,{className:`h-3 w-3 text-foreground-subtle`}),q(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),U(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[q(Rr,{label:`Nominal`,value:Ir(t.nominalBitrateKbps??0)}),q(Rr,{label:`Observed`,value:Ir(t.observedBitrateKbps??0)}),q(Rr,{label:`Peak`,value:Ir(t.peakBitrateKbps??0)}),q(Rr,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),q(Dr,{}),o&&n!==null&&q(Fr,{deviceId:n})]})}function Rr({label:e,value:t,warning:n}){return U(`div`,{children:[q(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),q(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}H();function zr(e,t){if(t===`number`){let t=Number(e);return Number.isNaN(t)?e:t}return t===`boolean`?e===`true`:e}function Br(e,t){let n={};for(let r of e)r.key!==``&&r.value!==``&&(n[r.key]=zr(r.value,t));return n}function Vr(e,t){return e?.kind===`enum-map`?Object.entries(e.mapping).map(([e,t])=>({key:e,value:String(t)})):t?.kind===`enum`&&t.enumValues?t.enumValues.map(e=>({key:e,value:``})):[{key:``,value:``}]}function Hr(e){return e?.kind===`linear`?{scale:String(e.scale),offset:String(e.offset),clampMin:e.clamp?String(e.clamp[0]):``,clampMax:e.clamp?String(e.clamp[1]):``,useClamp:e.clamp!=null}:{scale:`1`,offset:`0`,clampMin:``,clampMax:``,useClamp:!1}}function Ur(e){return e==null?`identity`:e.kind}function Wr({value:e,onChange:t,sourceField:n,targetKind:r}){let[i,a]=K(()=>Ur(e)),[o,s]=K(()=>Vr(e,n)),[c,l]=K(()=>e?.kind===`enum-map`&&e.fallback!=null?String(e.fallback):``),[u,d]=K(()=>Hr(e));J(()=>{if(i===`enum-map`&&n?.kind===`enum`&&n.enumValues){let e=n.enumValues;s(t=>e.map(e=>({key:e,value:t.find(t=>t.key===e)?.value??``})))}},[n,i]),J(()=>{if(i===`identity`){t(void 0);return}if(i===`enum-map`){let e=Br(o,r),n=c===``?void 0:zr(c,r);t({kind:`enum-map`,mapping:e,...n===void 0?{}:{fallback:n}});return}if(i===`linear`){let e=Number(u.scale),n=Number(u.offset);if(Number.isNaN(e)||Number.isNaN(n))return;let r=Number(u.clampMin),i=Number(u.clampMax),a=u.useClamp&&!Number.isNaN(r)&&!Number.isNaN(i)?[r,i]:void 0;t({kind:`linear`,scale:e,offset:n,...a?{clamp:a}:{}})}},[i,o,c,u,r,t]);let f=e=>{a(e),e===`enum-map`&&s(Vr(void 0,n)),e===`linear`&&d(Hr(void 0))},p=(e,t,n)=>{s(r=>r.map((r,i)=>i===e?{...r,[t]:n}:r))},m=()=>s(e=>[...e,{key:``,value:``}]),h=e=>s(t=>t.filter((t,n)=>n!==e));return U(`div`,{className:`flex flex-col gap-3`,children:[U(`div`,{children:[q(`p`,{className:`text-[11px] font-medium text-foreground-subtle mb-1.5`,children:`Transform`}),q(`div`,{className:`flex items-center gap-4`,children:[`identity`,`enum-map`,`linear`].map(e=>U(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[q(`input`,{type:`radio`,name:`transform-kind`,value:e,checked:i===e,onChange:()=>f(e),className:`accent-primary`}),e===`identity`?`None`:e]},e))})]}),i===`enum-map`&&U(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[q(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Key → Value mapping`}),o.map((e,t)=>U(`div`,{className:`flex items-center gap-1.5`,children:[q(`input`,{"aria-label":`enum key ${t}`,type:`text`,value:e.key,readOnly:n?.kind===`enum`,onChange:e=>p(t,`key`,e.target.value),placeholder:`source value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none read-only:opacity-70`}),q(`span`,{className:`text-foreground-subtle/50 text-xs`,children:`→`}),r===`boolean`?U(`select`,{"aria-label":`enum value ${t}`,value:e.value,onChange:e=>p(t,`value`,e.target.value),className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`,children:[q(`option`,{value:``,children:`—`}),q(`option`,{value:`true`,children:`true`}),q(`option`,{value:`false`,children:`false`})]}):q(`input`,{"aria-label":`enum value ${t}`,type:r===`number`?`number`:`text`,value:e.value,onChange:e=>p(t,`value`,e.target.value),placeholder:`target value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none`}),n?.kind!==`enum`&&q(`button`,{type:`button`,onClick:()=>h(t),className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] border border-border/80 text-foreground-subtle hover:text-danger hover:border-danger/50 transition-colors`,children:`✕`})]},t)),n?.kind!==`enum`&&q(`button`,{type:`button`,onClick:m,className:`self-start text-[10px] text-primary/70 hover:text-primary transition-colors`,children:`+ Add row`}),U(`div`,{className:`flex items-center gap-2 pt-1 border-t border-border/50`,children:[q(`label`,{className:`text-[10px] text-foreground-subtle/70 whitespace-nowrap`,children:`Fallback:`}),q(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`(leave empty for none)`,className:`flex-1 rounded border border-border bg-background px-2 py-0.5 text-xs font-mono text-foreground focus:border-primary outline-none`})]})]}),i===`linear`&&U(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[q(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Linear: value × scale + offset`}),U(`div`,{className:`grid grid-cols-2 gap-2`,children:[U(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Scale`}),q(`input`,{type:`number`,value:u.scale,onChange:e=>d(t=>({...t,scale:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),U(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Offset`}),q(`input`,{type:`number`,value:u.offset,onChange:e=>d(t=>({...t,offset:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]}),U(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[q(`input`,{type:`checkbox`,checked:u.useClamp,onChange:e=>d(t=>({...t,useClamp:e.target.checked})),className:`accent-primary`}),q(`span`,{className:`text-foreground-subtle`,children:`Clamp output`})]}),u.useClamp&&U(`div`,{className:`grid grid-cols-2 gap-2`,children:[U(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Min`}),q(`input`,{type:`number`,value:u.clampMin,onChange:e=>d(t=>({...t,clampMin:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),U(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Max`}),q(`input`,{type:`number`,value:u.clampMax,onChange:e=>d(t=>({...t,clampMax:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]})]})]})}var Gr=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`;function Kr({mode:e,idPrefix:t,labelPrefix:n,pickerDevices:r,value:i,onChange:a,search:o,onSearchChange:s}){let{data:c}=Se({deviceId:i.sourceId??0},{enabled:i.sourceId!=null}),l=c?.caps??[],u=l.find(e=>e.cap===i.cap)?.fields??[],d=e=>{a(e,(l.find(t=>t.cap===e.cap)?.fields??[]).find(t=>t.path===e.fieldPath))},f=e=>{d({sourceId:e===``?null:Number(e),cap:``,fieldPath:``})},p=e=>{d({sourceId:i.sourceId,cap:e,fieldPath:``})},m=e=>{d({sourceId:i.sourceId,cap:i.cap,fieldPath:e})};return U(et,{children:[e===`global`&&s&&U(`div`,{children:[q(`label`,{htmlFor:`${t}-search`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Search devices`}),q(`input`,{id:`${t}-search`,type:`text`,value:o??``,placeholder:`Filter by name, stable id or #id`,onChange:e=>s(e.target.value),className:Gr})]}),U(`div`,{children:[U(`label`,{htmlFor:`${t}-device`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[n,` device`]}),U(`select`,{id:`${t}-device`,value:i.sourceId??``,onChange:e=>f(e.target.value),className:Gr,children:[q(`option`,{value:``,children:`— select a device —`}),r.map(e=>U(`option`,{value:e.id,children:[e.name??e.stableId,` (#`,e.id,`)`]},e.id))]})]}),U(`div`,{children:[U(`label`,{htmlFor:`${t}-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[n,` cap`]}),U(`select`,{id:`${t}-cap`,value:i.cap,disabled:i.sourceId==null,onChange:e=>p(e.target.value),className:Gr,children:[q(`option`,{value:``,children:`— select a cap —`}),l.map(e=>q(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),U(`div`,{children:[U(`label`,{htmlFor:`${t}-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[n,` field`]}),U(`select`,{id:`${t}-field`,value:i.fieldPath,disabled:i.cap===``,onChange:e=>m(e.target.value),className:Gr,children:[q(`option`,{value:``,children:`— select a field —`}),u.map(e=>U(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]})}function qr(e,t){switch(e){case`null`:return{value:null};case`string`:return t===``?null:{value:t};case`number`:{if(t.trim()===``)return null;let e=Number(t);return Number.isFinite(e)?{value:e}:null}case`boolean`:return t===`true`?{value:!0}:t===`false`?{value:!1}:null}}function Jr(e){return e===null?`null`:typeof e==`number`?`number`:typeof e==`boolean`?`boolean`:`string`}function Yr(e){return e===null?``:String(e)}H();var Xr=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`,Zr=`min, max, abs, round, floor, ceil, sqrt, pow, clamp, avg, sum, coalesce, age, convert`,Qr=0;function $r(){return Qr+=1,`b${Qr}`}function ei(e){return{key:$r(),name:e,mode:`sibling`,sourceId:null,cap:``,fieldPath:``,search:``,literalType:`number`,literalText:``,sampleText:``}}function ti(e,t,n){if(e===null)return[ei(`a`)];let r=[];for(let[i,a]of Object.entries(e.bindings)){if(a.kind===`literal`){r.push({...ei(i),mode:`literal`,literalType:Jr(a.value),literalText:Yr(a.value)});continue}if(a.kind===`global`){r.push({...ei(i),mode:`global`,sourceId:t.find(e=>e.stableId===a.sourceStableId)?.id??null,cap:a.cap,fieldPath:a.fieldPath});continue}r.push({...ei(i),mode:`sibling`,sourceId:t.find(e=>e.stableId===`${n}-${a.sourceKey}`)?.id??null,cap:a.cap,fieldPath:a.fieldPath})}return r.length>0?r:[ei(`a`)]}function ni(e,t,n){if(e.mode===`literal`){let t=qr(e.literalType,e.literalText);return t===null?null:{kind:`literal`,value:t.value}}let r=t.find(t=>t.id===e.sourceId);if(!r||e.cap===``||e.fieldPath===``)return null;if(e.mode===`global`)return{kind:`global`,sourceStableId:r.stableId,cap:e.cap,fieldPath:e.fieldPath};let i=`${n}-`,a=r.stableId.startsWith(i)?r.stableId.slice(i.length):``;return a===``?null:{kind:`field`,sourceKey:a,cap:e.cap,fieldPath:e.fieldPath}}function ri(e){if(e.mode===`literal`)return qr(e.literalType,e.literalText)?.value??null;let t=e.sampleText.trim();if(t===``)return null;let n=Number(t);return Number.isFinite(n)?n:e.sampleText}function ii({devices:e,siblings:t,targetDeviceId:n,containerStableId:r,initial:i,onChange:a}){let[o,s]=K(i?.expr??``),[c,l]=K(()=>ti(i,e,r)),u=W(()=>{let t={},n=c.length>0,i=new Set;for(let a of c){let o=a.name.trim();if(o===``||i.has(o)){n=!1;continue}i.add(o);let s=ni(a,e,r);if(s===null){n=!1;continue}t[o]=s}return{source:{kind:`expression`,expr:o,bindings:t},complete:n}},[c,o,e,r]),d=W(()=>at({expr:u.source.expr,bindings:u.source.bindings}),[u.source]),f=W(()=>{if(o.trim()===``)return null;let e=ut(o);return e.ok?null:e.error},[o]),p=W(()=>{if(u.source.expr.trim()===``)return null;let e={};for(let t of c){let n=t.name.trim();n!==``&&(e[n]=ri(t))}return rt(u.source.expr,e,Date.now())},[u.source.expr,c]),m=u.complete&&d===null&&o.trim()!==``;J(()=>{a(m?u.source:null)},[m?JSON.stringify(u.source):`null`]);let h=e=>{let t=e.name.trim();return t===``?`required`:lt.test(t)?it.has(t)?`reserved`:nt.has(t)?`shadows builtin`:c.filter(e=>e.name.trim()===t).length>1?`duplicate`:null:`invalid name`},g=(e,t)=>{l(n=>n.map(n=>n.key===e?{...n,...t}:n))},_=()=>{c.length>=32||l(e=>[...e,ei(ai(e))])},v=e=>{l(t=>t.length<=1?t:t.filter(t=>t.key!==e))};return U(`div`,{className:`flex flex-col gap-3`,children:[U(`div`,{className:`flex flex-col gap-2`,children:[q(`span`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Bindings`}),c.map((r,i)=>q(oi,{row:r,ordinal:i+1,devices:e,siblings:t,targetDeviceId:n,nameError:h(r),onPatch:e=>g(r.key,e),onRemove:()=>v(r.key),canRemove:c.length>1},r.key)),q(`button`,{type:`button`,onClick:_,disabled:c.length>=32,className:`self-start px-2 py-1 rounded-md text-[11px] font-medium border border-border text-foreground-subtle hover:bg-surface-hover disabled:opacity-50`,children:`+ Add binding`})]}),U(`div`,{children:[q(`label`,{htmlFor:`link-expr-input`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Expression`}),q(`textarea`,{id:`link-expr-input`,value:o,rows:2,spellCheck:!1,placeholder:`e.g. clamp(avg(a, b) + 5, 0, 100)`,onChange:e=>s(e.target.value),className:`${Xr} font-mono resize-y`}),U(`p`,{className:`mt-1 text-[10px] text-foreground-subtle/60`,children:[`Functions: `,Zr]}),f&&q(`p`,{className:`mt-1 text-[10px] text-danger`,children:f}),f===null&&d&&q(`p`,{className:`mt-1 text-[10px] text-danger`,children:d})]}),U(`div`,{className:`rounded-md border border-border bg-surface/50 px-2 py-1.5`,children:[q(`span`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle/60`,children:`Preview`}),` `,p===null?q(`span`,{className:`text-[11px] text-foreground-subtle/60`,children:`enter an expression`}):p.ok?q(`span`,{className:`font-mono text-[11px] text-foreground`,children:JSON.stringify(p.value)}):q(`span`,{className:`font-mono text-[11px] text-danger`,children:p.error})]})]})}function ai(e){let t=new Set(e.map(e=>e.name.trim()));for(let e=0;e<26;e++){let n=String.fromCharCode(97+e);if(!t.has(n))return n}return`b${e.length+1}`}function oi({row:e,ordinal:t,devices:n,siblings:r,targetDeviceId:i,nameError:a,onPatch:o,onRemove:s,canRemove:c}){let l=e.search.trim().toLowerCase(),u=n.filter(e=>e.id===i?!1:l===``?!0:e.name.toLowerCase().includes(l)||e.stableId.toLowerCase().includes(l)||String(e.id).includes(l)),d=e.mode===`global`?u:r;return U(`div`,{className:`flex flex-col gap-2 rounded-md border border-border/60 p-2`,children:[U(`div`,{className:`flex items-center gap-2`,children:[q(`input`,{type:`text`,"aria-label":`binding ${t} name`,value:e.name,placeholder:`name`,onChange:e=>o({name:e.target.value}),className:`${Xr} max-w-[8rem] font-mono`}),U(`select`,{"aria-label":`binding ${t} mode`,value:e.mode,onChange:e=>{let t=e.target.value;(t===`sibling`||t===`global`||t===`literal`)&&o({mode:t,sourceId:null,cap:``,fieldPath:``,search:``})},className:`${Xr} max-w-[9rem]`,children:[q(`option`,{value:`sibling`,children:`Sibling`}),q(`option`,{value:`global`,children:`Any device`}),q(`option`,{value:`literal`,children:`Literal`})]}),c&&q(`button`,{type:`button`,"aria-label":`remove binding ${t}`,onClick:s,className:`px-2 py-1 rounded-md text-[11px] text-danger hover:bg-surface-hover`,children:`✕`})]}),a&&U(`span`,{className:`text-[10px] text-danger`,children:[`name: `,a]}),e.mode===`literal`?U(`div`,{className:`flex items-center gap-2`,children:[U(`select`,{"aria-label":`binding ${t} literal type`,value:e.literalType,onChange:e=>{let t=e.target.value;(t===`string`||t===`number`||t===`boolean`||t===`null`)&&o({literalType:t,literalText:t===`boolean`?`true`:``})},className:`${Xr} max-w-[7rem]`,children:[q(`option`,{value:`string`,children:`string`}),q(`option`,{value:`number`,children:`number`}),q(`option`,{value:`boolean`,children:`boolean`}),q(`option`,{value:`null`,children:`null`})]}),e.literalType!==`null`&&q(`input`,{type:`text`,"aria-label":`binding ${t} literal value`,value:e.literalText,placeholder:e.literalType===`number`?`e.g. 42`:`value`,onChange:e=>o({literalText:e.target.value}),className:Xr})]}):U(et,{children:[q(Kr,{mode:e.mode,idPrefix:`binding-${t}`,labelPrefix:`Binding`,pickerDevices:d,value:{sourceId:e.sourceId,cap:e.cap,fieldPath:e.fieldPath},onChange:e=>o({sourceId:e.sourceId,cap:e.cap,fieldPath:e.fieldPath}),search:e.search,onSearchChange:e=>o({search:e})}),q(`input`,{type:`text`,"aria-label":`binding ${t} sample`,value:e.sampleText,placeholder:`sample value (preview only)`,onChange:e=>o({sampleText:e.target.value}),className:`${Xr} text-[10px]`})]})]})}H();function si(e,t,n){return(n===void 0?[e,t]:[e,n,t]).map(e=>e.replace(/[^a-z0-9]/gi,`-`)).join(`-`)}function ci(e,t,n){let r=`${t}-${e}`;return n.find(e=>e.stableId===r)?.id??null}function li(e,t){return t.find(t=>t.stableId===e)?.id??null}function ui(e){return e==null?`sibling`:e.source.kind===`literal`?`literal`:e.source.kind===`global`?`global`:e.source.kind===`expression`?`expression`:`sibling`}function di(e){return e==null||e.source.kind!==`literal`?`string`:Jr(e.source.value)}function fi(e){return e==null||e.source.kind!==`literal`?``:Yr(e.source.value)}function pi({deviceId:e,parentDeviceId:t,deviceStableId:n,initial:r,onSave:i,onCancel:a}){let{data:o}=S({}),s=o??[],c=t==null?n:s.find(e=>e.id===t)?.stableId??n,l=s.filter(n=>n.parentDeviceId===t&&n.id!==e),{data:u}=Se({deviceId:e,includeSynthesizable:!0}),d=u?.caps??[],f=r!=null&&(r.source.kind===void 0||r.source.kind===`field`)?r.source:null,p=r!=null&&r.source.kind===`global`?r.source:null,m=r!=null&&r.source.kind===`expression`?r.source:null,h=f==null?p==null?null:li(p.sourceStableId,s):ci(f.sourceKey,c,s),[g,_]=K(ui(r)),[v,y]=K(r?.target.cap??``),[b,x]=K(r?.target.fieldPath??``),[C,w]=K(r?.target.itemKey??``),[T,E]=K(h),[D,ee]=K((f??p)?.cap??``),[O,te]=K((f??p)?.fieldPath??``),[ne,re]=K(void 0),[k,A]=K(``),[j,M]=K(di(r)),[ie,ae]=K(fi(r)),[N,P]=K(m),[F,oe]=K(r?.transform);J(()=>{if((f??p)==null||T!==null||s.length===0)return;let e=f==null?p==null?null:li(p.sourceStableId,s):ci(f.sourceKey,c,s);e!==null&&E(e)},[f,p,T,s,c]);let se=d.find(e=>e.cap===v)?.fields??[],ce=se.find(e=>e.path===b),le=ce?.item===!0,I=k.trim().toLowerCase(),ue=s.filter(t=>t.id===e?!1:I===``?!0:t.name.toLowerCase().includes(I)||t.stableId.toLowerCase().includes(I)||String(t.id).includes(I)),de=g===`global`?ue:l,fe=e=>{y(e),x(``),w(``)},pe=e=>{e!==`sibling`&&e!==`global`&&e!==`literal`&&e!==`expression`||(_(e),E(null),ee(``),te(``),re(void 0),A(``))},me=qr(j,ie),he=g===`literal`?me!==null:g===`expression`?N!==null:T!=null&&D!==``&&O!==``,ge=v!==``&&b!==``&&(!le||C.trim()!==``)&&he,_e=()=>{if(g===`literal`)return me===null?null:{kind:`literal`,value:me.value};if(g===`expression`)return N;let e=s.find(e=>e.id===T);if(!e||D===``||O===``)return null;if(g===`global`)return{kind:`global`,sourceStableId:e.stableId,cap:D,fieldPath:O};let t=`${c}-`;return{sourceKey:e.stableId.startsWith(t)?e.stableId.slice(t.length):``,cap:D,fieldPath:O}},ve=()=>{if(!ge)return;let e=_e();if(e===null)return;let t=le?C.trim():void 0;i({id:r?.id??si(v,b,t),source:e,target:{cap:v,fieldPath:b,...t===void 0?{}:{itemKey:t}},...F==null?{}:{transform:F}})},L=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`;return U(`div`,{className:`flex flex-col gap-4 p-3`,children:[U(`fieldset`,{className:`flex flex-col gap-3`,children:[q(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Target (this device)`}),U(`div`,{children:[q(`label`,{htmlFor:`link-target-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target cap`}),U(`select`,{id:`link-target-cap`,value:v,onChange:e=>fe(e.target.value),className:L,children:[q(`option`,{value:``,children:`— select a cap —`}),d.map(e=>q(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),U(`div`,{children:[q(`label`,{htmlFor:`link-target-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target field`}),U(`select`,{id:`link-target-field`,value:b,disabled:v===``,onChange:e=>x(e.target.value),className:L,children:[q(`option`,{value:``,children:`— select a field —`}),se.map(e=>q(`option`,{value:e.path,children:e.item===!0?`${e.path} (per item, ${e.kind})`:`${e.path} (${e.kind})`},e.path))]})]}),le&&U(`div`,{children:[q(`label`,{htmlFor:`link-target-item-key`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Item key`}),q(`input`,{id:`link-target-item-key`,type:`text`,value:C,placeholder:`e.g. main-brush`,onChange:e=>w(e.target.value),className:L}),q(`p`,{className:`mt-1 text-[10px] text-foreground-subtle/60`,children:`Links sharing the same item key build one item (e.g. one consumable).`})]})]}),U(`fieldset`,{className:`flex flex-col gap-3`,children:[q(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Source`}),U(`div`,{children:[q(`label`,{htmlFor:`link-source-mode`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source mode`}),U(`select`,{id:`link-source-mode`,value:g,onChange:e=>pe(e.target.value),className:L,children:[q(`option`,{value:`sibling`,children:`Sibling device (same container)`}),q(`option`,{value:`global`,children:`Any device`}),q(`option`,{value:`literal`,children:`Literal constant`}),q(`option`,{value:`expression`,children:`Expression (computed)`})]})]}),g===`literal`&&U(et,{children:[U(`div`,{children:[q(`label`,{htmlFor:`link-literal-type`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal type`}),U(`select`,{id:`link-literal-type`,value:j,onChange:e=>{let t=e.target.value;(t===`string`||t===`number`||t===`boolean`||t===`null`)&&(M(t),t===`boolean`&&ae(`true`),t===`null`&&ae(``))},className:L,children:[q(`option`,{value:`string`,children:`string`}),q(`option`,{value:`number`,children:`number`}),q(`option`,{value:`boolean`,children:`boolean`}),q(`option`,{value:`null`,children:`null`})]})]}),j!==`null`&&(j===`boolean`?U(`div`,{children:[q(`label`,{htmlFor:`link-literal-value`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal value`}),U(`select`,{id:`link-literal-value`,value:ie,onChange:e=>ae(e.target.value),className:L,children:[q(`option`,{value:`true`,children:`true`}),q(`option`,{value:`false`,children:`false`})]})]}):U(`div`,{children:[q(`label`,{htmlFor:`link-literal-value`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal value`}),q(`input`,{id:`link-literal-value`,type:`text`,value:ie,placeholder:j===`number`?`e.g. 42`:`e.g. main-brush`,onChange:e=>ae(e.target.value),className:L})]}))]}),g===`expression`&&q(ii,{devices:s,siblings:l,targetDeviceId:e,containerStableId:c,initial:m,onChange:P}),(g===`sibling`||g===`global`)&&q(Kr,{mode:g,idPrefix:`link-source`,labelPrefix:`Source`,pickerDevices:de,value:{sourceId:T,cap:D,fieldPath:O},onChange:(e,t)=>{E(e.sourceId),ee(e.cap),te(e.fieldPath),re(t)},search:k,onSearchChange:A})]}),q(Wr,{value:F,onChange:oe,sourceField:g===`literal`||g===`expression`?void 0:ne,targetKind:ce?.kind}),U(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-border`,children:[q(`button`,{type:`button`,onClick:a,className:`px-3 py-1.5 rounded-md text-xs font-medium border border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,children:`Cancel`}),q(`button`,{type:`button`,disabled:!ge,onClick:ve,className:`px-3 py-1.5 rounded-md text-xs font-medium bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:`Save`})]})]})}H();function mi({deviceId:e}){let t=X(),n=G(),r=Number.isFinite(e),{data:i,isLoading:a}=l({deviceId:e},{enabled:r,refetchInterval:1e4}),{data:o}=Se({deviceId:e,includeSynthesizable:!0},{enabled:r}),s=new Map;for(let e of o?.caps??[])e.itemArray&&s.set(e.cap,e.itemArray);let c=Qe({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),u=i?.deviceLinks??[],d=typeof i?.parentDeviceId==`number`?i.parentDeviceId:null,f=typeof i?.stableId==`string`?i.stableId:``,[p,m]=K(null),h=t=>{c.mutate({deviceId:e,deviceLinks:u.filter(e=>e.id!==t)})};return a?q(`div`,{className:`p-4`,children:q(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})}):p===null?U(`div`,{className:`flex flex-col gap-3 p-1`,children:[U(`div`,{className:`flex items-center justify-between`,children:[q(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Wiring`}),U(`button`,{type:`button`,onClick:()=>m(`new`),title:`Add a cross-device link`,className:`inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[q(jt,{className:`h-3 w-3`}),`Add link`]})]}),u.length===0?U(`div`,{className:`flex flex-col items-center justify-center gap-2 py-8 text-foreground-subtle`,children:[q(un,{className:`h-8 w-8 opacity-30`}),q(`p`,{className:`text-xs`,children:`No links yet.`}),q(`p`,{className:`text-[10px] opacity-60`,children:`Cross-device field wirings will appear here once authored.`})]}):q(`div`,{className:`flex flex-col divide-y divide-border rounded-lg border border-border overflow-hidden`,children:u.map(n=>q(gi,{deviceId:e,link:n,itemArray:s.get(n.target.cap),trpcClient:t.trpcClient,onDelete:()=>h(n.id),onEdit:()=>m(n),isPending:c.isPending},n.id))})]}):U(`div`,{className:`flex flex-col gap-3 p-1`,children:[q(`div`,{className:`flex items-center justify-between`,children:q(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:p===`new`?`Add link`:`Edit link`})}),q(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:q(pi,{deviceId:e,parentDeviceId:d,deviceStableId:f,initial:p===`new`?null:p,onSave:t=>{let n=u.some(e=>e.id===t.id)?u.map(e=>e.id===t.id?t:e):[...u,t];c.mutate({deviceId:e,deviceLinks:n}),m(null)},onCancel:()=>{m(null)}})})]})}function hi(e,t,n,r){let i=dt(e,t.path);if(!Array.isArray(i))return;let a=i.find(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Reflect.get(e,t.keyField)===n);return a===void 0?void 0:dt(a,r)}function gi({deviceId:e,link:t,itemArray:n,trpcClient:r,onDelete:i,onEdit:a,isPending:o}){let s=ke(r,e,t.target.cap),c=t.target.itemKey,l=s===void 0?void 0:c!==void 0&&n!==void 0?hi(s,n,c,t.target.fieldPath):c===void 0?dt(s,t.target.fieldPath):void 0,u=l==null?`—`:String(l);return U(`div`,{className:`flex items-center gap-3 px-3 py-2.5 bg-surface hover:bg-surface-hover transition-colors`,children:[q(dn,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle/40`}),U(`div`,{className:`min-w-0 flex-1 flex flex-col gap-0.5`,children:[U(`div`,{className:`flex items-baseline gap-1 flex-wrap`,children:[q(`span`,{className:`font-mono text-[11px] font-medium text-foreground`,children:t.target.cap}),q(`span`,{className:`text-[10px] text-foreground-subtle/60`,children:`.`}),q(`span`,{className:`font-mono text-[11px] text-foreground-subtle`,children:t.target.fieldPath}),c!==void 0&&q(`span`,{className:`rounded bg-surface-hover px-1 py-px font-mono text-[9px] text-foreground-subtle`,title:`Item key — links sharing it build one array item`,children:c})]}),U(`div`,{className:`flex items-baseline gap-1 flex-wrap text-[10px] text-foreground-subtle/70`,children:[q(`span`,{children:`←`}),t.source.kind===`literal`?U(`span`,{className:`font-mono`,children:[`literal: `,String(t.source.value)]}):t.source.kind===`expression`?U(et,{children:[U(`span`,{className:`font-mono`,title:t.source.expr,children:[`ƒ`,` `,t.source.expr.length>40?`${t.source.expr.slice(0,40)}…`:t.source.expr]}),U(`span`,{className:`rounded bg-surface-hover px-1 py-px font-mono text-[9px] text-foreground-subtle`,title:`Number of source bindings`,children:[Object.keys(t.source.bindings).length,` bindings`]})]}):U(et,{children:[q(`span`,{className:`font-mono`,children:t.source.kind===`global`?t.source.sourceStableId:t.source.sourceKey}),q(`span`,{className:`opacity-60`,children:`/`}),q(`span`,{className:`font-mono`,children:t.source.cap}),q(`span`,{className:`opacity-60`,children:`.`}),q(`span`,{className:`font-mono`,children:t.source.fieldPath})]})]})]}),t.transform&&q(_i,{kind:t.transform.kind}),q(`span`,{className:`font-mono text-[11px] tabular-nums min-w-[2.5rem] text-right text-foreground-subtle`,title:`Live resolved value (from this device's runtime-state slice)`,children:u}),q(`button`,{type:`button`,"aria-label":`Edit link`,title:`Edit this link`,disabled:o,onClick:a,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:`Edit`}),q(`button`,{type:`button`,"aria-label":`Delete link`,title:`Remove this link`,disabled:o,onClick:i,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-danger hover:border-danger/50 hover:bg-danger/5 transition-colors disabled:opacity-50`,children:`Delete`})]})}function _i({kind:e}){return q(`span`,{className:`inline-flex items-center rounded-md border border-primary/20 bg-primary/5 px-1.5 py-0.5 font-mono text-[10px] text-primary/80 shrink-0`,children:e})}H();var vi=[{id:`overview`,label:`Overview`,cameraOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1},{id:`detection-pipeline`,label:`Detection pipeline`,cameraOnly:!0},{id:`bindings`,label:`Bindings`,cameraOnly:!0},{id:`wiring`,label:`Wiring`,cameraOnly:!1}];function yi(e){let t=e===Y.Camera;return vi.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var bi=[{id:`logs`,icon:Jt,label:`Logs`},{id:`repl`,icon:Gt,label:`REPL`},{id:`events`,icon:Ht,label:`Events`},{id:`state`,icon:It,label:`State`}];function xi(){let t=Yt(),n=Number(t.deviceId),r=Number.isFinite(n),i=Rt(),a=G(),d=h(),f=X(),[p,m]=Lt(),g=p.get(`tab`)??`overview`,_=p.get(`sub`),[y,b]=K(`logs`),S=`device-detail.left-col-width-px`,[C,T]=K(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(S),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),E=V(C);E.current=C;function ee(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??C??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{T(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=E.current;if(e!==null)try{window.localStorage.setItem(S,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:O,isLoading:te,isError:ne}=l({deviceId:n},{enabled:r,refetchInterval:5e3,retry:1}),{data:re}=D({deviceId:n},{enabled:r}),k=W(()=>{let e=re?.settings?.sections??[],t=re?.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(Jn)&&r.add(Gn),[...r].map(e=>e===`export`?{id:e,label:Kn,isAddonContrib:!0}:{id:e,label:ct[e]?.label??e,isAddonContrib:!0})},[re]),j=O,M=String(j?.name??t.deviceId??`Device`),ie=j?.online===!0,ae=ie?`online`:`offline`,N=String(j?.addonId??`rtsp`),P=j?.features??[],F=j?.type,se=F===Y.Camera,{data:le}=Ct(r?n:0),I=F===Y.Container,de=W(()=>(le??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[le]),fe=W(()=>I?ue(de,typeof j?.linkDeviceId==`number`?j.linkDeviceId:null,typeof j?.primaryChildEntityId==`string`?j.primaryChildEntityId:null)?.id??null:null,[I,de,j?.linkDeviceId,j?.primaryChildEntityId]),{data:pe}=D({deviceId:fe??0},{enabled:fe!==null}),ge=W(()=>{if(fe===null)return[];let e=pe?.settings?.sections??[],t=pe?.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:ct[e]?.label??e,isAddonContrib:!0,childDeviceId:fe}))},[fe,pe]),_e=typeof j?.parentDeviceId==`number`?j.parentDeviceId:null,{data:ve}=l({deviceId:_e??0},{enabled:_e!==null}),R=me(),ye=j?.disabled!==!0,{data:be}=Se({deviceId:n},{enabled:r}),Ce=(be?.caps.length??0)>0,Te=W(()=>{let e=new Set,t=[];for(let n of[...yi(F),...k,...ge])e.has(n.id)||(e.add(n.id),!(n.id===`wiring`&&!Ce)&&t.push(n));return t},[F,k,ge,Ce]),Ee=W(()=>Te.some(e=>e.id===g)?g:`overview`,[Te,g]),De=B(e=>{m(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[m]),Oe=B(e=>{m(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[m]),ke=(le??[]).length>0,Ae=W(()=>bi.filter(({featureGate:e})=>!e||P.includes(e)),[P]),{data:z}=he({addonId:N},{enabled:!!N&&N!==`rtsp`}),Me=x({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]}),i(z?.id?`/integrations/${z.id}`:`/integrations`)}}),Ne=s({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Pe=Ge({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=ce(),Ie=A({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=P.includes(ft.Rebootable),Re=P.includes(ft.BatteryOperated),ze=e(f.trpcClient,Re&&r?n:null),[Be,Ve]=K(!1),He=mt(f.trpcClient,r?n:null),Ue=async()=>{if(!(Be||!He)){Ve(!0);try{await He.snapshot?.invalidateCache({});let e=await He.snapshot?.getSnapshot({});if(!e)return;let t=`data:${e.contentType};base64,${e.base64}`,n=e.contentType.includes(`png`)?`png`:`jpg`,r=M.replace(/[^a-zA-Z0-9_.-]+/g,`_`),i=new Date().toISOString().replace(/[:.]/g,`-`),a=document.createElement(`a`);a.href=t,a.download=`${r}-${i}.${n}`,document.body.appendChild(a),a.click(),document.body.removeChild(a)}finally{Ve(!1)}}},We=Ne.isPending||Pe.isPending,{data:Ke}=L({deviceId:n},{enabled:r,refetchInterval:1e4}),qe=Ke?.agentNodeId??null,Je=typeof qe==`string`&&qe.length>0&&!qe.startsWith(`addon:`)?qe:void 0,{data:Ye}=v({deviceId:n,...Je?{nodeId:Je}:{}},{enabled:r,refetchInterval:3e3,retry:!1}),{data:Xe}=o({deviceId:n},{enabled:r,refetchInterval:3e3,retry:!1}),Ze=Xe?.level?.dbfs??null;function Qe(){if(!r)return null;switch(Ee){case`overview`:return q(Lr,{device:j??{}});case`config`:return q(cr,{deviceId:n,activeSubTab:_,onSubTabChange:Oe});case`detection-pipeline`:return q(br,{deviceId:n,activeSubTab:_,onSubTabChange:Oe});case`bindings`:return q(zn,{deviceId:n});case`wiring`:return q(mi,{deviceId:n});default:{let e=Ee,t=k.some(t=>t.id===e),r=ge.find(t=>t.id===e);if(!t&&r===void 0)return null;let i=r?.childDeviceId??n;if(e===`export`)return q(sr,{deviceId:n,sectionFilter:Jn,activeSubTab:_,onSubTabChange:Oe});let a=q(sr,{deviceId:i,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:_,onSubTabChange:Oe});return r!==void 0&&i!==n?q(w,{deviceId:i,children:a}):a}}}return r?te?U(`div`,{className:`flex flex-col h-full`,children:[U(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[q(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),q(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),q(`div`,{className:`flex-1 p-6`,children:q(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):ne||!O?U(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[q(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),U(`p`,{className:`text-xs`,children:[`No device with ID`,` `,U(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,n]})]}),q(`button`,{onClick:()=>i(`/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`})]}):U(`div`,{className:`absolute inset-0 flex flex-col overflow-hidden`,children:[U(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[q(`div`,{className:`mb-2`,children:q(xe,{items:[{label:`Integrations`,onClick:()=>i(`/integrations`)},{label:z?.name??N,onClick:()=>z?.id&&i(`/integrations/${z.id}`)},{label:M}]})}),U(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[q(St,{type:N,size:`lg`}),U(`div`,{className:`min-w-0 flex-1`,children:[U(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[q(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:M}),q(nn,{status:ae}),Re&&q(oe,{status:ze,variant:`full`})]}),_e!==null&&ve&&U(`button`,{type:`button`,onClick:()=>i(`/devices/${_e}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${ve.name}`,children:[q(`span`,{children:`↑`}),q(`span`,{className:`truncate`,children:String(ve.name??`Device #${_e}`)})]}),q(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:P.length>0&&q(yt,{capabilities:P})})]}),Ye&&q(`div`,{className:`hidden lg:flex`,children:q(Si,{metrics:Ye,dbfs:Ze})}),U(`div`,{className:`flex items-center gap-1 shrink-0`,children:[U(`button`,{onClick:async()=>{ye?await d({title:`Disable "${M}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Pe.mutate({deviceId:n}):Ne.mutate({deviceId:n})},disabled:We,title:ye?`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 ${ye?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[q(fn,{className:`h-3.5 w-3.5`}),q(`span`,{className:`hidden sm:inline`,children:We?`Updating…`:ye?`Enabled`:`Disabled`})]}),q(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),q(we,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:tn,disabled:Be,onClick:()=>{Ue()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:Nt,hidden:!Le,disabled:Fe.isPending,danger:!0,onClick:async()=>{await d({title:`Reboot "${M}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Fe.mutate({deviceId:n})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${z?.name??N}.`,icon:Mt,disabled:Ie.isPending,danger:!0,onClick:async()=>{await d({title:`Restart "${z?.name??N}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${M}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&Ie.mutate({addonId:N})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:Zt,separatorBefore:!0,disabled:Me.isPending,danger:!0,onClick:async()=>{await d({title:`Delete "${M}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Me.mutate({deviceId:n})}}]})]})]})]}),q(w,{deviceId:n,device:j??void 0,children:q(c,{children:q(u,{children:q(_t,{children:q(je,{children:U(`main`,{className:R?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[U(`div`,{className:R?`flex flex-col bg-surface`:`${C===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!R&&C!==null?{width:`${String(C)}px`}:void 0,children:[q(`div`,{className:se?`flex-shrink-0 border-b border-border-subtle bg-black`:R?`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?q(Pn,{deviceId:n,intercomAvailable:P.includes(ft.TwoWayAudio)}):q(Tn,{deviceId:n,deviceName:M,deviceType:F??`unknown`,provider:N,isOnline:ie,features:P})}),U(`div`,{className:R?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[q(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:q(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:Ae.map(({id:e,label:t,icon:n})=>U(`button`,{onClick:()=>b(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${y===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[q(n,{className:`h-3 w-3`}),t]},e))})}),U(`div`,{className:R?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[y===`logs`&&q(Fn,{deviceId:n,containerDeviceId:F===`container`?n:void 0}),y===`repl`&&q(In,{deviceId:n}),y===`events`&&q(Ln,{deviceId:n}),y===`state`&&q(Rn,{deviceId:n})]})]})]}),!R&&q(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:ee,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:q(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),U(`div`,{className:R?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[q(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:q(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:Te.map(e=>{let t=Ee===e.id;return U(`button`,{onClick:()=>De(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&&q(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),U(`div`,{className:R?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[Ee===`overview`&&ke&&q(mn,{parentDeviceId:n}),Qe()]})]})]})})})})})})]}):U(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[q(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),U(`p`,{className:`text-xs`,children:[`The URL segment`,` `,q(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:t.deviceId}),` `,`is not a number.`]}),q(`button`,{onClick:()=>i(`/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 Si({metrics:e,dbfs:t}){let n=C(e.phase??`idle`);return U(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[U(`div`,{className:`flex items-center gap-1.5`,children:[q(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),q(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),q(`div`,{className:`h-3 w-px bg-border`}),U(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[q(Vt,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),q(`span`,{children:`fps`})]}),U(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[q(qt,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),q(`span`,{children:`ms`})]}),U(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[q(pn,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),q(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&U(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{xi as DeviceDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{B as e,Do as t,Gr as n,Jr as r,Kr as i,Mn as a,Mr as o,Qr as s,Ra as c,Ya as l,Yr as u,_o as d,go as f,q as p,xt as m,z as h}from"./src-D49drDQI.js";import{I as g,K as _,Q as v,S as y,W as b,b as x,i as S,o as C,q as w,x as T,z as E}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{E as D,K as O,P as k,s as A}from"./src-PXZvyYDe.js";import{p as j}from"./player-overlays-5vIS4o_W.js";import{t as M}from"./clock-CDpOjQuj.js";import{t as N}from"./copy-BBaHyGT3.js";import{a as ee,c as te,d as ne,f as P,i as F,m as I,n as re,o as L,p as R,r as ie,s as z,t as B}from"./debounced-invalidate-oJQtaYsH.js";import{t as V}from"./search-BU0QQbas.js";import{t as ae}from"./square-check-big-D5MMfdqS.js";import{t as H}from"./square-CCYHDGJh.js";import{E as U,I as W,L as oe,P as se,S as G,U as K,W as q,i as ce,s as le,t as ue}from"./index-DcoBSPD8.js";import{t as de}from"./AdminPage-Dq33XE9j.js";import{r as fe,t as pe}from"./authed-media-XfBD4Ma-.js";var me=q(`arrow-down-wide-narrow`,[[`path`,{d:`m3 16 4 4 4-4`,key:`1co6wj`}],[`path`,{d:`M7 20V4`,key:`1yoxec`}],[`path`,{d:`M11 4h10`,key:`1w87gc`}],[`path`,{d:`M11 8h7`,key:`djye34`}],[`path`,{d:`M11 12h4`,key:`q8tih4`}]]),he=q(`square-parking`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 17V7h4a3 3 0 0 1 0 6H9`,key:`1dfk2c`}]]),ge=q(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]);v();var _e=720*60*60*1e3;function ve(e){let t=[];for(let n of e)t.push(...n);return t}function ye(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function be(e,t){return e.filter(e=>!(e.importance<t.minImportance||t.cameras.size>0&&!t.cameras.has(e.deviceId)||t.classes.size>0&&!t.classes.has(e.className)))}function J(e,t){return`${String(e)}:${t}`}function xe(e,t){let n=new Map,r=new Set;for(let i of e){let e=J(i.deviceId,i.trackId);if(!t.has(e)||r.has(e))continue;r.add(e);let a=n.get(i.deviceId);a?a.push(i.trackId):n.set(i.deviceId,[i.trackId])}return n}function Se(e,t){return{since:e.fromMs??t-_e,until:e.toMs??t}}var Y=typeof n==`function`,Ce=`Track deletion arrives with the next server update`;function we(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Te=Y?n:we,Ee=200,De=3e4;function Oe(e){let t=j(),n=S({queries:e.deviceIds.map(n=>({queryKey:[`events-feed`,n,e.since,e.until,e.minImportance??null,e.classFilter??null],staleTime:De,refetchInterval:De,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEvents.query({deviceId:n,since:e.since,until:e.until,limit:Ee,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>({...e,deviceId:n}))}))});return{rows:ye(ve(n.map(e=>e.data??[])),`importance`),isLoading:n.some(e=>e.isLoading)}}var ke=[`events-feed`],Ae=2e3;function je(e){let t=C(),n=e?.paused===!0,r=_(t);r.current=t;let i=_(n);i.current=n;let[a,o]=w(!1),s=g(()=>{r.current.invalidateQueries({queryKey:ke})},[]),c=_(void 0);c.current||=B({delayMs:Ae,invalidate:()=>{i.current?o(!0):s()}}),E(()=>()=>c.current?.cancel(),[]),E(()=>{n||!a||(o(!1),s())},[n,a,s]);let u=g(()=>{o(!1),s()},[s]);return l(O.PipelineAnalyticsDetectionEvent,()=>{c.current?.trigger()}),l(O.PipelineAnalyticsTrackEnded,()=>{c.current?.trigger()}),{pending:a,refreshNow:u}}v();function Me(){return Object.values(k).filter(e=>e.level===`macro`).map(e=>({macro:e,subs:Object.values(k).filter(t=>t.parentKind===e.kind).sort((e,t)=>e.label.localeCompare(t.label))})).sort((e,t)=>e.macro.label.localeCompare(t.macro.label))}function Ne({selected:t,onChange:n}){let{t:r}=ue(),[i,a]=w(!1),[o,s]=w(``),[c,l]=w(new Set),u=b(Me,[]),d=o.trim().toLowerCase(),f=e=>d.length===0||h(e,r).toLowerCase().includes(d),p=b(()=>u.map(e=>({macro:e.macro,subs:e.subs.filter(t=>f(t)||f(e.macro))})).filter(e=>f(e.macro)||e.subs.length>0),[u,d]),m=e=>l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),g=e=>{let r=new Set(t),i=t.has(e.macro.kind)&&e.subs.every(e=>t.has(e.kind)),a=[e.macro.kind,...e.subs.map(e=>e.kind)];if(i)for(let e of a)r.delete(e);else for(let e of a)r.add(e);n(r)},_=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},v=()=>n(new Set),x=t.size;return y(`div`,{className:`relative`,children:[y(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${x>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[T(ge,{className:`h-3.5 w-3.5`}),x>0?`Kinds (${String(x)})`:`Kinds`,T(W,{className:`h-3 w-3`})]}),i&&y(`div`,{className:`absolute z-20 mt-1 max-h-80 w-64 overflow-auto rounded-md border border-border bg-surface p-2 shadow-lg`,children:[y(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[T(V,{className:`h-3.5 w-3.5 text-foreground-subtle`}),T(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`Search kinds…`,className:`w-full bg-transparent py-1 text-xs outline-none`}),x>0&&T(`button`,{type:`button`,onClick:v,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),p.map(n=>{let i=e(n.macro.iconId),a=c.has(n.macro.kind)||d.length>0,o=t.has(n.macro.kind);return y(`div`,{className:`mb-0.5`,children:[y(`div`,{className:`flex items-center gap-1`,children:[n.subs.length>0?T(`button`,{type:`button`,onClick:()=>m(n.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:T(a?W:se,{className:`h-3 w-3`})}):T(`span`,{className:`w-3`}),y(`label`,{className:`flex flex-1 cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[T(`input`,{type:`checkbox`,checked:o,onChange:()=>g(n),className:`accent-primary`}),T(i,{className:`h-3.5 w-3.5`,style:{color:n.macro.color}}),T(`span`,{className:`font-medium`,children:h(n.macro,r)})]})]}),a&&n.subs.map(n=>{let i=e(n.iconId);return y(`label`,{className:`ml-5 flex cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[T(`input`,{type:`checkbox`,checked:t.has(n.kind),onChange:()=>_(n.kind),className:`accent-primary`}),T(i,{className:`h-3.5 w-3.5`,style:{color:n.color}}),T(`span`,{children:h(n,r)})]},n.kind)})]},n.macro.kind)})]})]})}var X=100,Pe=120,Fe={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Z=e=>e<0?0:e>1?1:e,Q=e=>Math.round(e*100)/100;function Ie(e,t){if(e.length<=t)return[...e];let n=(e.length-1)/(t-1),r=[];for(let i=0;i<t;i++)r.push(e[Math.round(i*n)]);return r[r.length-1]=e[e.length-1],r}function Le(e,t,n){if(e.length===0||t===null)return Fe;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return Fe;let a=Ie(e,n?.maxPoints??Pe).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X)})),o=a[0]??null,s=a[a.length-1]??null,c=a.length>=2?a.map(e=>`${e.x},${e.y}`).join(` `):``,l=(n?.snapshots??[]).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X),mediaKey:e.mediaKey})),u=null,d=-1;for(let t of e){let e=Z(t.bbox.w/r)*Z(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Q(Z(u.bbox.x/r)*X),y:Q(Z(u.bbox.y/i)*X),w:Q(Z(u.bbox.w/r)*X),h:Q(Z(u.bbox.h/i)*X)}:null}}var Re={firstFrame:`First frame (track start)`,lastFrame:`Last frame (track end)`,thumbnail:`Best detection`,thumbnailSmall:`Best detection (480)`,snapshot:`Snapshot`,keyFrame:`Key frame (native-res)`,keyFrameSmall:`Key frame (960)`,crop:`Object crop`,fullFrame:`Full frame`,fullFrameBoxed:`Full frame (boxed)`,faceCrop:`Face crop`,plateCrop:`Plate crop`};function ze(e){return e in Re}function Be(e){return ze(e)?Re[e]:e}function Ve(e,t){return`${e}${pe}/${encodeURIComponent(t)}`}v();var He=1400,Ue=`Admin-gated URL — opens only inside an authenticated session`;function We({label:e,value:t,title:n}){let[r,i]=w(!1);return E(()=>{if(!r)return;let e=setTimeout(()=>i(!1),He);return()=>clearTimeout(e)},[r]),y(`button`,{type:`button`,onClick:g(()=>{(async()=>{try{await navigator.clipboard.writeText(t),i(!0)}catch{window.prompt(`Copy the media URL:`,t)}})()},[t]),title:n,"aria-label":`Copy ${e} URL`,className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${r?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[T(r?oe:N,{className:`h-2.5 w-2.5 shrink-0`}),T(`span`,{className:`truncate`,children:r?`Copied`:e})]})}function Ge({localUrl:e,publicUrl:t}){return y(`div`,{className:`flex flex-wrap gap-1`,children:[T(We,{label:`Local`,value:e,title:`Copy LAN URL — ${Ue}`}),t&&T(We,{label:`Public`,value:t,title:`Copy public URL — ${Ue}`})]})}v();var Ke=3e4;function qe(e){let[t,n]=w(null),r=g(e=>{n(t=>t??e)},[]);return E(()=>{e||n(null)},[e]),{publicOrigin:t,probes:e?T(Je,{onOrigin:r}):null}}function Je({onOrigin:e}){let{data:t}=m({capName:`network-access`});return T(x,{children:(t??[]).map(t=>T(Ye,{addonId:t.addonId,onOrigin:e},t.addonId))})}function Ye({addonId:e,onOrigin:t}){let{data:n}=o({addonId:e},{refetchInterval:Ke,retry:!1});return E(()=>{let e=n?A.safeParse(n):null,r=e?.success?e.data.endpoint?.url:void 0;if(r)try{t(new URL(r).origin)}catch{}},[n,t]),null}v();var Xe=15e3,Ze=window.location.origin,Qe=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),$e=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]);function et(e){let[t,n]=w(null);return E(()=>{if(n(null),!e)return;let t=!1,r=new Image;return r.onload=()=>{t||n({width:r.naturalWidth,height:r.naturalHeight})},r.src=e,()=>{t=!0,r.onload=null}},[e]),t}function tt({overlay:e,onPickSnapshot:t}){return!e.polyline&&!e.peakBox&&e.snapshots.length===0?null:y(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[e.peakBox&&T(`rect`,{x:e.peakBox.x,y:e.peakBox.y,width:e.peakBox.w,height:e.peakBox.h,fill:`none`,stroke:`#f59e0b`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),e.polyline&&T(`polyline`,{points:e.polyline,fill:`none`,stroke:`#38bdf8`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),e.points.map((e,t)=>T(`circle`,{cx:e.x,cy:e.y,r:1,fill:`#38bdf8`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),e.snapshots.map((e,n)=>T(`circle`,{cx:e.x,cy:e.y,r:1.9,fill:`#0ea5e9`,fillOpacity:.95,stroke:`#082f49`,strokeWidth:.7,vectorEffect:`non-scaling-stroke`,className:t?`pointer-events-auto cursor-pointer`:void 0,onClick:t?n=>{n.stopPropagation(),t(e.mediaKey)}:void 0,children:T(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${e.mediaKey}-${String(n)}`)),e.start&&T(`circle`,{cx:e.start.x,cy:e.start.y,r:2.4,fill:`#22c55e`,stroke:`#052e16`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),e.end&&T(`circle`,{cx:e.end.x,cy:e.end.y,r:2.4,fill:`#ef4444`,stroke:`#450a0a`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function $({label:e,value:t,mono:n}){return y(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[T(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),T(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function nt({row:e,cameraName:n,deleteAvailable:a,onClose:o,onDeleted:s}){let l=j(),p=Te(),m=e!==null,h=e?.deviceId??0,_=e?.trackId??``,v=e?.bestEventId??``,S=e?.timestamp??0,C=e?.windowMs??0,{data:D}=r({deviceId:h,trackId:_},{enabled:m}),{data:O}=u({trackId:_},{enabled:m}),{data:k}=i({eventId:v},{enabled:m&&v!==``}),{data:A}=c({deviceId:h,since:S-Xe,until:S+C+Xe},{enabled:m}),[M,N]=w(null),[ee,te]=w(!1),{publicOrigin:P,probes:re}=qe(m);E(()=>{N(null)},[h,_]);let L=b(()=>{let e=O??[],t=k??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[O,k]),ie=fe(L?`${pe}/${encodeURIComponent(L.key)}`:void 0),z=b(()=>{let e=new Set,t=[];for(let n of[...k??[],...O??[]])!n.base64||e.has(n.key)||(e.add(n.key),t.push(n));return t},[k,O]),B=b(()=>z.find(e=>Qe.has(e.kind))??null,[z]),V=et(B?`data:image/jpeg;base64,${B.base64}`:null),ae=b(()=>Le(D?.positions??[],V,{snapshots:(D?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaKey:e.mediaKey}))}),[D?.positions,D?.snapshots,V]),H=g(e=>{let t=z.find(t=>t.key===e);t&&N(t)},[z]);if(e===null)return null;let W=M?`data:image/jpeg;base64,${M.base64}`:ie.src,oe=M?.kind??L?.kind,se=oe!==void 0&&$e.has(oe)&&V!==null&&(D?.positions.length??0)>=2,K=A&&A.length>0?A[0]:null,q=()=>{K&&(te(!0),(async()=>{try{let t=await l.trpcClient.videoclips.getClipPlayback.query({deviceId:e.deviceId,clipId:K.id});window.open(t.playbackUrl,`_blank`,`noopener`)}catch{window.alert(`Could not resolve clip playback. Check the server logs.`)}finally{te(!1)}})())},ue=()=>{!a||p.isPending||window.confirm(`Delete this track and all its media? This cannot be undone.`)&&(async()=>{try{await p.mutateAsync({deviceId:e.deviceId,trackIds:[e.trackId]}),s()}catch{window.alert(`Failed to delete this track. Check the server logs.`)}})()},de=Math.round(e.importance*100),me=D?.importanceReason?`${String(de)}% · ${D.importanceReason}`:`${String(de)}%`,he=D?.zonesVisited&&D.zonesVisited.length>0?D.zonesVisited.join(`, `):`—`,ge=D?.audioLabels&&D.audioLabels.length>0?D.audioLabels.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `):`—`,_e=D?D.totalDistance.toFixed(2):`—`,ve=R(D?D.firstSeen:S),ye=D?R(D.lastSeen):`—`;return T(f,{open:!0,onOpenChange:e=>!e&&o(),children:y(d,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Event detail`,className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[y(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[y(`div`,{className:`min-w-0`,children:[y(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[e.className,e.label?y(`span`,{className:`text-foreground-subtle`,children:[` · `,e.label]}):null]}),T(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:n})]}),T(`button`,{type:`button`,onClick:o,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:T(ce,{className:`h-4 w-4`})})]}),y(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[W?T(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:T(F,{src:W,alt:`Key frame from ${n}`,fit:`natural`,className:`w-full`,overlay:se?T(tt,{overlay:ae,onPickSnapshot:H}):void 0})}):T(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:ie.failed?y(x,{children:[T(I,{className:`h-8 w-8 opacity-60`}),T(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):T(G,{className:`h-6 w-6 animate-spin opacity-70`})}),z.length>0&&T(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:z.map(e=>{let t=`data:image/jpeg;base64,${e.base64}`,n=Be(e.kind),r=Ve(Ze,e.key),i=P?Ve(P,e.key):null;return y(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[T(`button`,{type:`button`,onClick:()=>N(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${n} · ${R(e.timestamp)}`,children:T(`img`,{src:t,alt:n,className:`h-full w-full object-cover`})}),y(`figcaption`,{className:`min-w-0 px-0.5`,children:[T(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:n,children:n}),T(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:R(e.timestamp),children:ne(e.timestamp)})]}),T(Ge,{localUrl:r,publicUrl:i})]},e.key)})}),re,K&&y(t,{variant:`secondary`,onClick:q,disabled:ee,children:[ee?T(G,{className:`h-3.5 w-3.5 animate-spin`}):T(U,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),y(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[T($,{label:`Camera`,value:n}),T($,{label:`Class`,value:e.className}),T($,{label:`Label`,value:e.label??`—`}),T($,{label:`Importance`,value:me}),T($,{label:`Zones visited`,value:he}),T($,{label:`Audio heard`,value:ge}),T($,{label:`Total distance`,value:_e}),T($,{label:`First seen`,value:ve}),T($,{label:`Last seen`,value:ye}),T($,{label:`Track`,value:e.trackId,mono:!0})]})]}),T(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:T(`span`,{title:a?void 0:Ce,children:y(t,{variant:`secondary`,onClick:ue,disabled:!a||p.isPending,children:[p.isPending?T(G,{className:`h-3.5 w-3.5 animate-spin`}):T(le,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}function rt(e){if(e===void 0||!Number.isFinite(e)||e<=0)return``;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`${String(n)}m ${String(r).padStart(2,`0`)}s`}function it({row:e,cameraName:t,nowMs:n,onOpenDetail:r,selected:i=!1,onToggleSelect:a,score:o}){let s=fe(e.bestEventId?`${pe}/${e.bestEventId}`:void 0),c=Math.round(e.importance*100),l=o===void 0?void 0:Math.round(o*100),u=rt(e.windowMs),d=()=>r(e);return y(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[y(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[s.src?T(`img`,{src:s.src,alt:`Event from ${t}`,onClick:d,className:`h-full w-full cursor-zoom-in object-cover`}):T(`button`,{type:`button`,onClick:d,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:s.failed?`Key-event media unavailable`:`No key-event media`,children:T(I,{className:`h-6 w-6 opacity-60`})}),a&&T(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(J(e.deviceId,e.trackId))},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Deselect`:`Select`,children:i?T(ae,{className:`h-4 w-4 text-primary`}):T(H,{className:`h-4 w-4`})}),l!==void 0&&y(`span`,{className:`absolute left-1 top-1 z-10 rounded bg-primary/85 px-1.5 py-0.5 text-[10px] font-semibold text-white tabular-nums`,title:`CLIP semantic-match score`,children:[String(l),`%`]}),c>0&&T(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(c)})]}),y(`button`,{type:`button`,onClick:d,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[y(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,e.label?y(`span`,{className:`text-foreground-subtle`,children:[` · `,e.label]}):null]}),T(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),y(`div`,{className:`flex items-center justify-between gap-2`,children:[T(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:P(e.timestamp,n)}),u&&T(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:u})]})]})]})}v();function at(){let[e,t]=w(!1),n=_(null),[r,i]=w(0),a=g(e=>{n.current!==e&&(n.current=e,i(e=>e+1))},[]);return E(()=>{let e=n.current;if(!e||typeof IntersectionObserver>`u`){t(!1);return}let r=new IntersectionObserver(e=>{let n=e[e.length-1];n&&t(!n.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return r.observe(e),()=>r.disconnect()},[r]),{ref:a,scrolledPast:e}}v();var ot=[`events-feed`],st=60,ct=[{value:`importance`,label:`Importance`,icon:me},{value:`time`,label:`Recent`,icon:M}];function lt(){let e=C(),[n,r]=w(z),[i,o]=w(new Set),[s,c]=w(new Set),[l,u]=w(0),[d,f]=w(`time`),[p,m]=w(new Set),[h,g]=w(null),[_,v]=w(()=>Date.now());E(()=>{let e=setInterval(()=>v(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:S,until:O}=b(()=>Se({fromMs:n.fromMs,toMs:n.toMs},_),[n.fromMs,n.toMs,_]),k=at(),{pending:A,refreshNow:j}=je({paused:h!==null||p.size>0||k.scrolledPast}),{data:M}=a({}),N=b(()=>(M??[]).filter(e=>e.type===D.Camera),[M]),ne=b(()=>N.map(e=>e.id),[N]),P=Te(),F=P.isPending,{rows:I,isLoading:R}=Oe({deviceIds:ne,since:S,until:O,minImportance:l>0?l:void 0,classFilter:s.size===1?[...s][0]:void 0}),B=b(()=>{let e=new Map;for(let t of N??[])e.set(t.id,t.name);return e},[N]),V=e=>B.get(e)??`Camera #${String(e)}`,ae=b(()=>te(I).map(e=>({id:e,name:V(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[I,B]),H=b(()=>ye(be(I,{cameras:i,classes:s,minImportance:l}),d),[I,i,s,l,d]),U=re(H,st,b(()=>JSON.stringify([[...i].sort((e,t)=>e-t),[...s].sort(),l,d,S,O]),[i,s,l,d,S,O])),W=()=>{e.invalidateQueries({queryKey:ot})},oe=()=>m(new Set);function se(e){m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function K(){if(p.size===0||!Y)return;let e=xe(I,p),t=[...e.values()].reduce((e,t)=>e+t.length,0);if(t===0||!window.confirm(`Delete ${String(t)} track${t===1?``:`s`} and all their media? This cannot be undone.`))return;let n=[...e];Promise.allSettled(n.map(([e,t])=>P.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{W();let t=[],r=new Set;if(e.forEach((e,i)=>{let a=n[i];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)r.add(J(o,e));else t.push(o)}),m(e=>{let t=new Set(e);for(let e of r)t.delete(e);return t}),t.length>0){let e=t.map(e=>V(e)).join(`, `);window.alert(`Failed to delete tracks on: ${e}. They remain selected — retry, or check the server logs.`)}})}let q=H.length!==I.length;return y(`div`,{className:`relative space-y-3`,children:[y(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[T(ee,{onChange:r}),T(L,{cameras:ae,selected:i,onChange:o}),T(Ne,{selected:s,onChange:c}),y(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[T(`span`,{children:`Min score`}),T(`input`,{type:`range`,min:0,max:1,step:.05,value:l,onChange:e=>u(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":`Minimum importance`}),T(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(l*100)})]}),T(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:ct.map(e=>{let t=e.icon;return y(`button`,{type:`button`,onClick:()=>f(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${d===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[T(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!R&&T(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:q?`${String(H.length)} of ${String(I.length)} events`:`${String(H.length)} event${H.length===1?``:`s`}`})]}),p.size>0&&y(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[y(`span`,{className:`text-xs font-medium text-foreground`,children:[p.size,` selected`]}),y(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[T(`span`,{title:Y?void 0:`Track deletion arrives with the next server update`,children:y(t,{variant:`secondary`,onClick:K,disabled:!Y||F,children:[F?T(G,{className:`h-3.5 w-3.5 animate-spin`}):T(le,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),T(t,{variant:`ghost`,onClick:oe,disabled:F,children:T(ce,{className:`h-3.5 w-3.5`})})]})]}),R&&y(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[T(G,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!R&&H.length===0&&T(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),A&&T(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:T(`button`,{type:`button`,onClick:j,className:`rounded-full border border-primary/40 bg-surface px-3 py-1 text-[11px] font-medium text-primary shadow-sm hover:bg-primary/10`,children:`New events — refresh`})}),!R&&H.length>0&&y(x,{children:[T(`div`,{ref:k.ref,"aria-hidden":!0,className:`h-0`}),T(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:U.pageItems.map(e=>T(it,{row:e,cameraName:V(e.deviceId),nowMs:_,selected:p.has(J(e.deviceId,e.trackId)),onToggleSelect:se,onOpenDetail:g},J(e.deviceId,e.trackId)))}),T(ie,{currentPage:U.page,totalItems:U.totalItems,pageSize:U.pageSize,onPageChange:U.setPage,itemNoun:`events`})]}),h&&T(nt,{row:h,cameraName:V(h.deviceId),deleteAvailable:Y,onClose:()=>g(null),onDeleted:()=>{W(),g(null)}})]})}v();var ut=50,dt=350,ft=[`person`,`vehicle`,`animal`],pt=[{value:.2,label:`Loose`},{value:.25,label:`Balanced`},{value:.3,label:`Strict`}];function mt(e){return{id:e.id,trackId:e.trackId??e.id,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,importance:e.importance??0,bestEventId:e.mediaKey??e.trackId??e.id,windowMs:void 0}}function ht({onActiveChange:e}){let[t,n]=w(``),[r,i]=w(.2),[o,c]=w(null),[l,u]=w(null),[d,f]=w(null),m=p(t,dt).trim(),h=m.length>0;E(()=>{e(h)},[h,e]);let[g,_]=w(()=>Date.now());E(()=>{let e=setInterval(()=>_(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:v}=a({}),x=b(()=>(v??[]).filter(e=>e.type===D.Camera),[v]),S=b(()=>{let e=new Map;for(let t of v??[])e.set(t.id,t.name);return e},[v]),C=e=>S.get(e)??`Camera #${String(e)}`,{data:O,isFetching:k,isError:A,error:j}=s({text:m,minScore:r,limit:ut,classFilter:o??void 0,deviceId:l??void 0},{enabled:h}),M=b(()=>[...O??[]].sort((e,t)=>t.score-e.score).map(e=>({...mt(e),score:e.score})),[O]);function N(e){c(t=>t===e?null:e)}return y(`div`,{className:`space-y-3`,children:[y(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[y(`div`,{className:`flex flex-wrap items-center gap-2`,children:[y(`div`,{className:`relative min-w-[16rem] flex-1`,children:[T(V,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),T(`input`,{type:`text`,value:t,onChange:e=>n(e.target.value),placeholder:`Semantic search — describe what you're looking for…`,className:`h-9 w-full rounded-md border border-border bg-background pl-8 pr-8 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":`Semantic event search`}),t&&T(`button`,{type:`button`,onClick:()=>n(``),className:`absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Clear search`,children:T(ce,{className:`h-3.5 w-3.5`})})]}),k&&h&&T(G,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),y(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[T(`div`,{className:`flex items-center gap-1`,children:ft.map(e=>T(`button`,{type:`button`,onClick:()=>N(e),className:`rounded-md px-2.5 py-1 text-xs capitalize transition-colors ${o===e?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e},e))}),y(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[T(`span`,{children:`Camera`}),y(`select`,{value:l===null?``:String(l),onChange:e=>u(e.target.value===``?null:Number(e.target.value)),className:`h-7 rounded-md border border-border bg-background px-1.5 text-xs text-foreground focus:border-primary focus:outline-none`,"aria-label":`Filter by camera`,children:[T(`option`,{value:``,children:`All`}),x.map(e=>T(`option`,{value:String(e.id),children:e.name},e.id))]})]}),y(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[T(`span`,{children:`Match`}),T(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:pt.map(e=>T(`button`,{type:`button`,onClick:()=>i(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${r===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:`Minimum CLIP score ${e.value.toFixed(2)}`,children:e.label},e.value))})]}),h&&!k&&!A&&y(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[M.length,` match`,M.length===1?``:`es`]})]})]}),h&&y(`div`,{className:`space-y-3`,children:[A&&y(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,j instanceof Error?j.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!A&&k&&M.length===0&&y(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[T(G,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!A&&!k&&M.length===0&&y(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:[`No semantic matches for “`,m,`”. Try a looser match threshold or a different phrasing.`]}),!A&&M.length>0&&T(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:M.map(e=>T(it,{row:e,cameraName:C(e.deviceId),nowMs:g,score:e.score,onOpenDetail:f},e.id))})]}),d&&T(nt,{row:d,cameraName:C(d.deviceId),deleteAvailable:Y,onClose:()=>f(null),onDeleted:()=>f(null)})]})}var gt=15e3;function _t(e){let t=j(),n=S({queries:e.map(e=>({queryKey:[`stationary-objects`,e],staleTime:gt,refetchInterval:gt,queryFn:async()=>((await t.trpcClient.zoneAnalytics.getCurrentSnapshot.query({deviceId:e}))?.stationaryObjects??[]).map(t=>({...t,deviceId:e}))}))});return{rows:n.flatMap(e=>e.data??[]).toSorted((e,t)=>t.becameStationaryAt-e.becameStationaryAt),isLoading:n.some(e=>e.isLoading)}}v();function vt(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return`just now`;if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function yt({row:e,cameraName:t,nowMs:n}){let r=e.keyFrameMediaKey?.startsWith(`track:`)?e.keyFrameMediaKey.split(`:`)[1]:e.keyFrameMediaKey,i=fe(r?`${pe}/${r}`:void 0);return y(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[y(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[i.src?T(`img`,{src:i.src,alt:`Parked ${e.className} on ${t}`,className:`h-full w-full object-cover`}):T(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:T(he,{className:`h-6 w-6`})}),T(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:e.label??e.className})]}),y(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[T(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),y(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,vt(n,e.becameStationaryAt)]})]})]})}function bt(){let[e,t]=w(!1),n=Date.now(),{data:r}=a({}),i=b(()=>(r??[]).filter(e=>e.type===D.Camera),[r]),o=b(()=>i.map(e=>e.id),[i]),s=b(()=>{let e=new Map;for(let t of i)e.set(t.id,t.name);return e},[i]),{rows:c}=_t(o);return c.length===0?null:y(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[y(`button`,{type:`button`,onClick:()=>t(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[T(e?W:se,{className:`h-4 w-4 text-foreground-subtle`}),T(he,{className:`h-4 w-4 text-foreground-subtle`}),T(`span`,{className:`text-sm font-semibold text-foreground`,children:`Stationary`}),T(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:c.length}),T(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:`Parked objects — kept out of the event feed`})]}),e&&T(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:c.map(e=>T(yt,{row:e,cameraName:s.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}v();function xt(){let[e,t]=w(!1);return T(de,{icon:K,title:`Events`,subtitle:`Every captured key event across all cameras — trajectory, media, and clips.`,children:y(`section`,{className:`space-y-3`,children:[T(ht,{onActiveChange:t}),!e&&T(bt,{}),!e&&T(lt,{})]})})}export{xt as EventsPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Cn as e,En as t,Fn as n,G as r,K as i,Kn as a,Ln as o,Mn as s,Sn as c,So as l,Tt as u,_n as d,cr as f,d as p,fn as m,fr as h,g,gr as _,hn as ee,io as v,it as y,lr as b,mn as x,mr as S,nt as C,pn as te,ur as ne,ut as w,vn as T,x as E}from"./src-D49drDQI.js";import{I as D,K as re,Q as O,S as k,W as A,b as j,o as M,q as N,x as P,z as ie}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{E as F}from"./src-PXZvyYDe.js";import{p as I}from"./player-overlays-5vIS4o_W.js";import{t as L}from"./ProviderIcon-DXM0Cs6A.js";import{t as R}from"./FormBuilder-D6rV90RE.js";import{t as z}from"./plus-zsIhHGHK.js";import{n as B,r as ae,t as oe}from"./ScanNetworkModal-DtqM9hw3.js";import{t as se}from"./refresh-cw-DXzAUpGT.js";import{t as ce}from"./rotate-cw-RF_Q6dlG.js";import{t as V}from"./wifi-jwlQfCJ5.js";import{D as H,H as le,I as U,J as ue,K as de,L as W,O as fe,P as pe,S as G,W as K,i as q,m as me,o as J,p as he,q as ge,s as _e,t as ve}from"./index-DcoBSPD8.js";var ye=K(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);O();function be(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...be(n.fields));return t}function xe(e,t,n){let[r,i]=N(`idle`),[a,o]=N({}),s=A(()=>{let t=[];for(let n of e.sections)t.push(...be(n.fields));return t},[e]),c=s.length>0&&n!==void 0,l=D(e=>{o(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:r,hasProbeFields:c,probeResults:a,handleTestAll:D(async()=>{if(!n)return;let e=s.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;i(`testing`);let r={};for(let t of e)r[t]={status:`probing`};o(r);let a=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await n(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),c={};for(let e of a)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;c[t]={status:n.status===`ok`?`ok`:`error`,result:n}}o(c),i(`idle`)},[n,s,t]),clearProbeResult:l}}O();function Se(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Se(n.fields));return t}function Ce(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Y(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Y(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function X(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function we({open:e,integrationId:r,addonId:i,onClose:o}){let{t:s}=ve(),c=M(),[l,u]=N({}),[f,p]=N(!1),[m,h]=N(null),[_,ee]=N(X),v=n({addonId:i},{enabled:e}),y=v.data?.deviceType??null,b=t({addonId:i,type:y??F.Camera},{enabled:e&&v.isSuccess&&y!==null}),x=b.data??null;ie(()=>{e&&(u(x?Y(x.sections.flatMap(e=>e.fields)):{}),ee(X()),p(!1),h(null))},[e,r,x]);let S=A(()=>({...l,_probeRequestId:_}),[l,_]),C=d({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),te=a(),ne=D(async(e,t)=>{p(!0);let n=await te.mutateAsync({addonId:i,type:y??F.Camera,key:e,value:t,formValues:S});return n.status===`ok`&&n.suggestedValues&&u(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Ce(e[i])&&!Ce(a)&&(r[i]=a,t=!0);return t?r:e}),n},[te,i,S,y]),{testAllStatus:w,hasProbeFields:T,probeResults:E,handleTestAll:re,clearProbeResult:O}=xe(x??{sections:[]},l,ne);async function j(e){h(null);try{await C.mutateAsync({addonId:i,type:y??F.Camera,config:l,integrationId:r}),e?u(x?Y(x.sections.flatMap(e=>e.fields)):{}):o()}catch(e){h(e instanceof Error?e.message:String(e))}}if(!e)return null;let I=Se((x?.sections??[]).flatMap(e=>e.fields)).filter(e=>Ce(l[e])),L=I.length===0,z=v.isLoading||y!==null&&b.isLoading,B=v.isError||v.isSuccess&&y===null||b.isError||b.isSuccess&&x===null;return k(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[P(`div`,{className:`absolute inset-0 bg-black/60`,onClick:o}),k(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[90vh] rounded-xl border border-border bg-background shadow-2xl`,children:[k(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:s(`integrations.addDevice`)}),P(`button`,{onClick:o,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:P(q,{className:`h-4 w-4`})})]}),P(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:z?P(`div`,{className:`flex items-center justify-center py-8`,children:P(G,{className:`h-5 w-5 animate-spin text-primary`})}):B?k(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[P(J,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),k(`div`,{className:`space-y-1`,children:[P(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),k(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,P(`span`,{className:`font-mono`,children:i}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):P(R,{schema:x,values:l,onChange:u,onTestField:ne,probeResults:E,onClearProbe:O})}),!B&&!z&&k(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[k(`button`,{type:`button`,onClick:()=>p(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[k(`span`,{className:`flex items-center gap-2`,children:[P(me,{className:`h-3.5 w-3.5`}),`Test logs`,P(`span`,{className:`font-mono text-[9px] opacity-60`,children:_.slice(0,14)})]}),P(U,{className:`h-3.5 w-3.5 transition-transform ${f?`rotate-180`:``}`})]}),f&&P(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:P(g,{addonId:i,requestId:_,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!B&&!z&&(m||I.length>0)&&P(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:k(`div`,{className:`flex items-start gap-2`,children:[P(J,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),P(`p`,{className:`text-[11px] text-destructive`,children:m||`Required: ${I.join(`, `)}`})]})}),k(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[k(`div`,{className:`flex items-center gap-2`,children:[P(`button`,{onClick:o,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:s(`integrations.cancel`)}),!B&&T&&k(`button`,{type:`button`,onClick:re,disabled:w===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[w===`testing`?P(G,{className:`h-3.5 w-3.5 animate-spin`}):P(V,{className:`h-3.5 w-3.5`}),`Test All`]})]}),k(`div`,{className:`flex items-center gap-2`,children:[P(`button`,{onClick:()=>j(!0),disabled:B||!L||C.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:s(`integrations.saveAndNew`)}),P(`button`,{onClick:()=>j(!1),disabled:B||!L||C.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:C.isPending?s(`integrations.saving`):s(`integrations.save`)})]})]})]})]})}function Z(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}O();var Q=`devices`,Te={id:Q,label:`Devices`,isDefault:!0},Ee=2e4,De=100;function Oe({addonId:e,integrationId:t,onClose:n}){let{t:i}=ve(),[a,o]=N(new Set),[s,c]=N(new Set),[l,u]=N(new Map),[d,f]=N(null),{data:p}=ne(),h=(p??[]).find(t=>t.addonId===e)?.supportsLocationImport??!1,[g,_]=N(!0),v=te({addonId:e,integrationId:t}).data?.filters,b=v&&v.length>0?v:[Te],[S,w]=N(b.find(e=>e.isDefault)?.id??(b.some(e=>e.id===Q)?Q:b[0].id)),T=S!==Q,E=ee(),O=x({addonId:e,integrationId:t,page:1,pageSize:Ee,filter:S}),A=O.refetch,j=E.mutate,M=D(()=>{j({addonId:e,integrationId:t},{onSettled:()=>{A()}})},[j,e,t,A]),F=re(null);ie(()=>{let n=`${e}::${t}`;F.current===n||O.isLoading||(F.current=n,(O.data?.candidates.length??0)===0&&M())},[e,t,O.isLoading,O.data,M]);let I=E.isPending,L=E.isError?E.error instanceof Error?E.error.message:String(E.error):null,R=O.data?.candidates??[],z=O.isError?O.error instanceof Error?O.error.message:String(O.error):null,B=m(),ae=D(e=>{e.alreadyAdopted||o(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),oe=D(e=>{c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),se=D((e,t)=>{u(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),V=D(e=>{let t={};for(let n of e){let e=l.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[l]),H=D(async()=>{f(null);let r=[...a];if(r.length!==0)try{let i=V(r);await B.mutateAsync({addonId:e,integrationId:t,filter:S,childNativeIds:r,...i?{perCandidate:i}:{},...h?{importLocations:g}:{}}),o(new Set),u(new Map),await A(),n()}catch(e){f(e instanceof Error?e.message:String(e))}},[a,V,B,e,t,S,A,h,g]),le=D(e=>{w(e),o(new Set),c(new Set),u(new Map),f(null)},[]),U=a.size;return k(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[P(`div`,{className:`absolute inset-0 bg-black/60`,onClick:n}),k(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[k(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[k(`div`,{className:`min-w-0`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:i(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),P(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:i(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),k(`div`,{className:`flex items-center gap-3 shrink-0`,children:[h&&k(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[P(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`accent-primary`}),i(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),P(`button`,{onClick:n,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:P(q,{className:`h-4 w-4`})})]})]}),k(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(L??z)&&R.length===0&&P(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:k(`div`,{className:`flex items-start gap-2`,children:[P(J,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),k(`div`,{className:`min-w-0`,children:[P(`p`,{className:`text-xs font-medium text-destructive`,children:i(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),P(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:L??z})]})]})}),b.length>1&&P(ke,{filters:b,activeFilter:S,onSelect:le}),P(`div`,{className:`flex-1 min-h-0`,children:P(r,{mode:`generic`,items:R,pageSize:De,getKey:e=>e.childNativeId,getSearchText:Z,getFilterType:e=>e.type,filterOptions:C(),filterLabel:i(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:O.isLoading||I&&R.length===0,searchPlaceholder:i(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(L??z)&&R.length===0?``:i(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:k(`button`,{type:`button`,onClick:M,disabled:I,title:i(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[P(ce,{className:`h-3.5 w-3.5 ${I?`animate-spin`:``}`}),i(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:i(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>P($,{candidate:e,expandable:!T,expanded:s.has(e.childNativeId),onToggleExpand:()=>oe(e.childNativeId),adoptedLabel:i(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:i(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=y(e.type),n=t.icon;return k(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[P(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>P(`div`,{className:`flex items-center justify-end`,children:P(`button`,{onClick:()=>ae(e),disabled:e.alreadyAdopted,"aria-label":a.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${a.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:a.has(e.childNativeId)&&P(W,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!T&&s.has(e.childNativeId),renderExpanded:T?void 0:e=>P(Ae,{candidate:e,hiddenChildIds:l.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>se(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:a.has(e.childNativeId)?`bg-primary/5`:``})})]}),d&&P(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:k(`div`,{className:`flex items-start gap-2`,children:[P(J,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),P(`p`,{className:`text-[11px] text-destructive`,children:d})]})}),k(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[P(`div`,{}),k(`div`,{className:`flex items-center gap-2`,children:[P(`button`,{onClick:n,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.cancel`,{defaultValue:`Cancel`})}),k(`button`,{onClick:H,disabled:U===0||B.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[B.isPending&&P(G,{className:`h-3.5 w-3.5 animate-spin`}),i(`integrations.addSelected`,{defaultValue:`Add selected`}),U>0?` (${U})`:``]})]})]})]})]})}function ke({filters:e,activeFilter:t,onSelect:n}){return P(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return P(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function $({candidate:e,expandable:t,expanded:n,onToggleExpand:r,adoptedLabel:i}){let a=(e.children??[]).length;return k(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&a>0?k(`button`,{type:`button`,onClick:r,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[P(n?U:pe,{className:`h-3.5 w-3.5`}),a]}):P(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),P(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&P(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:i})]})}function Ae({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let r=e.children??[];return r.length===0?null:P(`div`,{className:`space-y-1 py-1`,children:r.map(e=>{let r=t.has(e.childNativeId),i=e.capabilities??[];return k(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${r?`opacity-50`:``}`,children:[P(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),i.length>0&&P(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:i.join(`, `)}),P(`button`,{onClick:()=>n(e.childNativeId),"aria-label":r?`Show child`:`Hide child`,title:r?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:P(r?fe:H,{className:`h-3 w-3`})})]},e.childNativeId)})})}O();function je({integrationId:e,addonId:t,name:n,kind:r,brokerKind:i,trpc:a,onClose:o}){let{t:s}=ve(),c=M(),l=r===`device-adoption`,{data:u}=h({id:e},{enabled:l}),d=A(()=>{let e=u?.brokerId;return typeof e==`string`?e:null},[u]),f=S();return P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:o,children:k(`div`,{className:`max-h-[85vh] w-full max-w-md overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[k(`div`,{className:`mb-3 flex items-center justify-between`,children:[k(`h2`,{className:`text-sm font-semibold text-foreground`,children:[s(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),P(`button`,{onClick:o,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":s(`common.close`,{defaultValue:`Close`}),children:P(q,{className:`h-4 w-4`})})]}),l?i?k(`div`,{className:`space-y-3`,children:[P(`p`,{className:`text-[11px] text-foreground-subtle`,children:s(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),d&&k(`p`,{className:`text-[11px] text-foreground`,children:[s(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,P(`span`,{className:`font-mono text-foreground-subtle`,children:d})]}),f.isPending?k(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[P(G,{className:`h-3 w-3 animate-spin`}),s(`integrations.saving`,{defaultValue:`Saving…`})]}):P(B,{kind:i,onResolved:t=>{f.mutate({id:e,settings:{brokerId:t}},{onSuccess:()=>{c.invalidateQueries(),o()}})},onBack:o}),f.isError&&P(`p`,{className:`text-[11px] text-danger`,children:s(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):P(`p`,{className:`text-[11px] text-danger`,children:s(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):P(E,{trpc:a,addonId:t,nodeId:`hub`,title:n})]})})}O();function Me(){let{t}=ve(),{integrationId:n}=ge(),a=M(),d=de(),[m,h]=ue(),ee=I(),[y,x]=N(!1),[S,C]=N(!1),[te,E]=N(!1),[re,O]=N(!1),[F,R]=N(!1),{data:B,isLoading:ce}=b({id:n??``},{enabled:!!n}),{data:V}=w({addonId:B?.addonId??``,nodeId:`hub`},{enabled:!!B?.addonId}),{data:H,isSuccess:U}=ne(),W=A(()=>{let e=B?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[H,B?.addonId,U]),{data:fe}=c({}),pe=A(()=>(fe?.providers??[]).some(e=>e.addonId===B?.addonId),[fe,B?.addonId]),K=W!==null,be=K?W===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),xe=A(()=>{let e=B?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.brokerKind??null},[H,B?.addonId,U]),Se=A(()=>{let e=B?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.mode??null},[H,B?.addonId,U]);ie(()=>{m.get(`add`)===`1`&&K&&(x(!0),h(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[m,K,h]);let Ce=V!=null&&Array.isArray(V.sections)&&V.sections.some(e=>e.fields.length>0),{data:Y}=s({},{refetchInterval:5e3}),X=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Z=_({onMutate:async e=>{await a.cancelQueries({queryKey:X});let t=a.getQueryData(X);return t!=null&&a.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&a.setQueryData(X,r.previous)},onSettled:()=>{a.invalidateQueries({queryKey:[[`integrations`]]}),a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=f({onSuccess:()=>{a.invalidateQueries({queryKey:[[`integrations`]]}),a.invalidateQueries({queryKey:[[`deviceManager`]]}),O(!1),d(`/integrations`)}}),Te=u({onSuccess:()=>{a.invalidateQueries({queryKey:[[`integrations`]]}),a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ee=o({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),De=T({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=e({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=A(()=>Y??[],[Y]),Ae=A(()=>{let e=new Map;for(let t of $)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[$]),Me=D(e=>Ae.get(e)??null,[Ae]),Ne=D(e=>P(L,{type:e,size:`sm`}),[]),Pe=D(e=>d(`/devices/${String(e)}`),[d]),Fe=A(()=>{let e=B?.addonId;return e?$.filter(t=>t.addonId===e):[]},[$,B?.addonId]),Ie=A(()=>i(Fe).length,[Fe]);return ce?k(`div`,{className:`p-4`,children:[P(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),P(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):B?k(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[P(v,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},{label:B.name}]}),k(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[k(`div`,{className:`flex items-center gap-3 min-w-0`,children:[P(`img`,{src:`/api/addon-assets/${B.addonId}/assets/icon.svg`,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),k(`div`,{className:`min-w-0`,children:[P(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:B.name}),k(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[B.addonId,` · `,Ie,` `,t(`integrations.devices`)]})]})]}),k(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[pe&&k(`button`,{onClick:()=>C(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the network for devices (incl. a different subnet)`,children:[P(ae,{className:`h-3.5 w-3.5`}),`Scan network`]}),k(`button`,{onClick:()=>x(!0),disabled:!K,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:be,children:[P(z,{className:`h-3.5 w-3.5`}),be]}),k(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Z.isPending?`opacity-60`:``} ${B.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[P(l,{checked:B.enabled,onCheckedChange:e=>Z.mutate({id:n,enabled:e}),disabled:Z.isPending,"aria-label":B.enabled?`Disable integration`:`Enable integration`}),P(`span`,{className:`text-[11px] font-medium ${B.enabled?`text-success`:`text-foreground-subtle`}`,children:B.enabled?`Enabled`:`Disabled`}),Z.isPending&&P(G,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Se!==`standalone`&&(Ce||W===`device-adoption`)&&k(`button`,{onClick:()=>E(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[P(he,{className:`h-3 w-3`}),t(`integrations.config`)]}),k(`button`,{onClick:()=>R(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrations.logs`,{defaultValue:`View logs`}),children:[P(me,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),P(p,{label:`Restart`,icon:se,title:`Restart "${B.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Ie} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Te.isPending,action:()=>Te.mutateAsync({addonId:B.addonId})}),k(`button`,{onClick:()=>O(!0),className:`flex items-center gap-1.5 rounded-lg border border-danger bg-danger/10 px-3 py-1.5 text-[11px] font-medium text-danger hover:bg-danger hover:text-background transition-colors`,title:t(`integrations.delete`,{defaultValue:`Delete integration`}),children:[P(_e,{className:`h-3 w-3`}),t(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),P(r,{context:`integration-detail`,devices:$,trpc:ee.trpcClient,defaultView:`cards`,forceAddon:B.addonId,urlScope:`root`,lsKey:`integration-detail:${B.addonId}`,resolveIntegrationIcon:Ne,resolveParent:Me,onNavigate:Pe,batchActions:{remove:Ee.mutate,disable:De.mutate,enable:ke.mutate},onDeleteDevice:e=>Ee.mutate({deviceId:e.id})}),y&&n&&W===`device-adoption`&&P(Oe,{addonId:B.addonId,integrationId:n,onClose:()=>x(!1)}),y&&n&&W===`device-provider`&&P(we,{open:y,integrationId:n,addonId:B.addonId,onClose:()=>x(!1)}),S&&B&&P(oe,{open:S,scope:{addonId:B.addonId,label:B.name},onClose:()=>C(!1)}),te&&n&&W!==null&&P(je,{integrationId:n,addonId:B.addonId,name:B.name,kind:W,brokerKind:xe,trpc:ee.trpcClient,onClose:()=>E(!1)}),F&&P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>R(!1),children:k(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[k(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[k(`div`,{className:`flex items-center gap-2 min-w-0`,children:[P(me,{className:`h-4 w-4 text-primary shrink-0`}),P(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:B.name}),k(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[B.addonId,n?` · ${n}`:``]})]}),P(`button`,{onClick:()=>R(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:P(q,{className:`h-4 w-4`})})]}),P(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:P(g,{addonId:B.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),re&&P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Q.isPending&&O(!1),children:k(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[k(`div`,{className:`flex items-start gap-3`,children:[P(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:P(J,{className:`h-4 w-4 text-danger`})}),k(`div`,{className:`min-w-0`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),P(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:B.name,count:Ie})})]})]}),Q.error&&P(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:Q.error instanceof Error?Q.error.message:String(Q.error)}),k(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[P(`button`,{onClick:()=>O(!1),disabled:Q.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:t(`integrations.cancel`,{defaultValue:`Cancel`})}),P(`button`,{onClick:()=>Q.mutate({id:n}),disabled:Q.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-danger px-3 py-1.5 text-[11px] font-medium text-background hover:bg-danger/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed`,children:Q.isPending?k(j,{children:[P(G,{className:`h-3 w-3 animate-spin`}),t(`integrations.deleting`,{defaultValue:`Deleting…`})]}):k(j,{children:[P(_e,{className:`h-3 w-3`}),t(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):k(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[P(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:P(ye,{className:`h-6 w-6 text-foreground-subtle`})}),k(`div`,{className:`space-y-1 max-w-sm`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),P(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:n??``})})]}),k(`button`,{onClick:()=>d(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[P(le,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{Me as IntegrationDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Cr as e,Do as t,Dr as n,Eo as r,Er as i,Mr as a,Nr as o,Or as s,Pr as c,Sa as l,Sr as u,To as d,Tr as f,Ua as p,br as m,bt as h,kr as g,ro as _,wr as ee,xr as te,xt as v}from"./src-D49drDQI.js";import{I as y,Q as b,S as x,W as S,b as C,o as w,q as T,x as E,z as ne}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{o as D,s as O}from"./src-PXZvyYDe.js";import{p as k}from"./player-overlays-5vIS4o_W.js";import{n as A,t as re}from"./rotate-ccw-mo9YtqUE.js";import{t as j}from"./copy-BBaHyGT3.js";import{n as ie,t as M}from"./AddonCollectionPage-BM908g2f.js";import{t as ae}from"./refresh-cw-DXzAUpGT.js";import{t as N}from"./server-B2_ttQ96.js";import{t as oe}from"./square-CCYHDGJh.js";import{t as se}from"./wifi-jwlQfCJ5.js";import{L as ce,S as P,T as F,W as I,b as le,i as ue,k as L,l as de,o as R,v as z,x as B}from"./index-DcoBSPD8.js";import{t as V}from"./AdminPage-Dq33XE9j.js";import{t as H}from"./AdminTabs-6yXsZXxy.js";import{t as U}from"./addon-display-names-DvSEQty-.js";var fe=I(`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`}]]),pe=I(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),W=I(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]);b();var G=5e3,me={connected:!1,endpoint:null};function he(){let e=w(),t=v({capName:`network-access`},{refetchInterval:G}),n=h(void 0,{refetchInterval:G}),r=S(()=>U(n.data??[]),[n.data]),i=S(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,r]),[a,s]=T(null),[l,u]=T({}),d=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),s(null),u(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},f=(e,t)=>{s(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);u(e=>({...e,[n]:r}))},p=o({onSuccess:d,onError:f}),m=c({onSuccess:d,onError:f});return E(M,{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:F,itemIcon:F,capability:`network-access`,installButtonLabel:`Add tunnel`,items:i,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=>E(ge,{addonId:e.addonId}),itemError:e=>l[e.addonId]??null,renderPrimaryAction:e=>E(_e,{addonId:e.addonId,busyId:a,onStart:e=>{s(e),p.mutate({addonId:e})},onStop:e=>{s(e),m.mutate({addonId:e})}})})}function K(e){let{data:t}=a({addonId:e},{refetchInterval:G,retry:!1}),n=t?O.safeParse(t):null;return n?.success?n.data:me}function ge({addonId:e}){let t=K(e);return x(C,{children:[E(`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&&x(`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:[E(L,{className:`h-3 w-3`}),t.endpoint.url]})]})}function _e({addonId:e,busyId:n,onStart:r,onStop:i}){let a=K(e),o=n===e;return a.connected?x(t,{size:`sm`,variant:`secondary`,disabled:o,onClick:()=>i(e),children:[o?E(P,{className:`h-3 w-3 animate-spin`}):E(oe,{className:`h-3 w-3`}),`Stop`]}):x(t,{size:`sm`,variant:`primary`,disabled:o,onClick:()=>r(e),children:[o?E(P,{className:`h-3 w-3 animate-spin`}):E(ie,{className:`h-3 w-3`}),`Start`]})}b();var q=3e4;function ve(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function ye(){let e=v({capName:`turn-provider`},{refetchInterval:q}),n=h(void 0,{refetchInterval:q}),r=l(),i=r.data??[],a=S(()=>U(n.data??[]),[n.data]);return E(M,{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:z,itemIcon:z,capability:`turn-provider`,installButtonLabel:`Add provider`,items:S(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:a.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,a]),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=>E(be,{addonId:e.addonId,enabled:e.isActive}),trailing:x(d,{children:[x(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[x(`div`,{children:[E(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),E(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),E(t,{size:`sm`,variant:`secondary`,onClick:()=>r.refetch(),disabled:r.isFetching,children:`Refresh`})]}),E(`div`,{className:`p-4`,children:i.length===0?E(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):E(`div`,{className:`flex flex-col gap-3`,children:i.map((e,t)=>{let n=Array.isArray(e.urls)?e.urls:[e.urls];return x(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&x(`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&&x(`span`,{children:[E(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,E(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&x(`span`,{children:[E(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,E(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),E(`ul`,{className:`divide-y divide-border`,children:n.map(e=>E(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function be({addonId:e,enabled:t}){let n=l({addonId:e},{enabled:t,retry:!1}),r=S(()=>ve(n.data??[]),[n.data]);return!t||r.length===0?null:x(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[x(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,r.length,`)`]}),E(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>E(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}b();var xe={lan:z,wifi:se,docker:A,vpn:B,loopback:N,other:N},Se={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Ce=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function we(e){let{interfaces:t,disabled:n,hideLoopback:r,ipv4Only:i,emptyMessage:a}=e,o=S(()=>t.filter(e=>!(r&&e.kind===`loopback`||i&&e.family!==`IPv4`)),[t,r,i]),s=S(()=>{let e=new Map;for(let t of o){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Ce.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[o]),c=t=>e.mode===`single`?e.value===t:e.value.includes(t),l=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 o.length===0?E(`div`,{className:`text-xs text-foreground-subtle italic`,children:a??`No addresses available.`}):E(`div`,{className:`flex flex-col gap-3`,children:s.map(({kind:t,items:r})=>x(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[x(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[E(xe[t]??N,{className:`h-3.5 w-3.5 text-foreground-subtle`}),E(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:Se[t]??t}),x(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),E(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=c(t.address),i=t.kind===`loopback`,a=!t.plausible&&!i;return x(`li`,{className:`flex items-center gap-3 px-3 py-2 ${i?`opacity-60 cursor-not-allowed`:n?`opacity-60`:a?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>l(t),children:[E(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${e.mode===`single`?`rounded-full`:`rounded`} border ${r?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:r&&E(ce,{className:`h-3 w-3`})}),x(`div`,{className:`flex-1 min-w-0 ${a?`text-foreground-subtle`:``}`,children:[x(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[E(`span`,{className:`font-mono text-xs font-semibold ${a?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),E(`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&&E(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),i&&E(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),a&&x(`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:[E(R,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),x(`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))})}b();var J={"lan-ipv4":`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,"lan-ipv6":`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`,loopback:`bg-foreground-subtle/15 text-foreground-subtle`};function Te(){let n=w(),r=k(),i=u(void 0,{refetchInterval:3e4}),a=m(void 0),o=ee({onSuccess:()=>{n.invalidateQueries({queryKey:[[`localNetwork`]]})}}),s=e({onSuccess:e=>{p(e.addresses),n.invalidateQueries({queryKey:[[`localNetwork`]]})}}),c=S(()=>i.data?.interfaces??[],[i.data]),l=te({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`},{refetchInterval:3e4}),[f,p]=T([]),[h,g]=T(!1);ne(()=>{!h&&a.data&&(p(a.data.addresses),g(!0))},[a.data,h]);let _=a.data?.addresses??[],v=S(()=>{if(f.length!==_.length)return!0;let e=[...f].toSorted(),t=[..._].toSorted();return e.some((e,n)=>e!==t[n])},[f,_]),y=()=>{o.mutate({addresses:[...f]})},b=()=>{p(_)},C=()=>{p([])},D=()=>{i.refetch(),l.refetch(),a.refetch()},O=async()=>{try{let e=await r.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},A=l.data?.endpoints??[];return x(V,{children:[x(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[E(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Pick the local addresses SDK clients should race for the fastest path to this hub. Empty selection (auto) lets every non-loopback / non-link-local interface participate.`}),x(`div`,{className:`flex items-center gap-2 shrink-0`,children:[x(t,{size:`sm`,variant:`secondary`,onClick:D,disabled:i.isLoading,children:[E(ae,{className:`h-3 w-3 ${i.isLoading?`animate-spin`:``}`}),`Refresh`]}),E(t,{size:`sm`,variant:`secondary`,onClick:O,children:`Probe race`})]})]}),x(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[x(d,{children:[x(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[x(`div`,{children:[E(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),E(`div`,{className:`text-xs text-foreground-subtle`,children:f.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${f.length} pinned`})]}),x(`div`,{className:`flex items-center gap-1`,children:[x(t,{size:`sm`,variant:`secondary`,onClick:()=>s.mutate(void 0),disabled:s.isPending||o.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[E(de,{className:`h-3 w-3`}),s.isPending?`Detecting…`:`Best match`]}),x(t,{size:`sm`,variant:`secondary`,onClick:C,disabled:f.length===0||o.isPending,children:[E(re,{className:`h-3 w-3`}),`Clear`]}),v&&E(t,{size:`sm`,variant:`secondary`,onClick:b,disabled:o.isPending,children:`Discard`}),x(t,{size:`sm`,variant:`primary`,onClick:y,disabled:!v||o.isPending,children:[E(pe,{className:`h-3 w-3`}),o.isPending?`Saving…`:`Save`]})]})]}),E(`div`,{className:`p-4`,children:E(we,{mode:`multiple`,interfaces:c,value:f,onChange:p,disabled:o.isPending,emptyMessage:i.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),x(d,{children:[x(`div`,{className:`px-4 py-3 border-b border-border`,children:[E(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints — priority order`}),E(`div`,{className:`text-xs text-foreground-subtle`,children:`Live preview of the ranked candidate list the SDK would race against. Updates with each Save.`})]}),E(`div`,{className:`p-4`,children:A.length===0?E(`div`,{className:`text-xs text-foreground-subtle italic`,children:l.isLoading?`Loading…`:`No endpoints available.`}):E(`ul`,{className:`space-y-1 text-xs`,children:A.map(e=>x(`li`,{className:`flex items-center gap-2 flex-wrap ${e.plausible?``:`opacity-80`}`,children:[E(`span`,{className:`font-mono text-[10px] w-10 text-foreground-subtle`,children:String(e.priority).padStart(4,`0`)}),E(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${J[e.kind]??J.loopback}`,children:e.kind}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&E(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-medium uppercase`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&x(`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:e.plausibleReason||void 0,children:[E(R,{className:`h-2.5 w-2.5`}),`Unlikely usable`]}),E(`span`,{className:`font-mono break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),x(`span`,{className:`text-foreground-subtle`,children:[`— `,e.label]})]},`${e.priority}-${e.baseUrl}`))})})]})]})]})}b();var Ee={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,De=3e4,Oe={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function ke(){let e=v({capName:`mesh-network`},{refetchInterval:Y}),t=h(void 0,{refetchInterval:Y}),n=S(()=>U(t.data??[]),[t.data]);return E(M,{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:A,itemIcon:z,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:S(()=>(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=>E(Ae,{addonId:e.addonId}),renderPrimaryAction:e=>E(je,{addonId:e.addonId}),renderExpandedPanel:e=>E(Me,{addonId:e.addonId})})}function X(e){let{data:t,isLoading:n}=f({addonId:e},{refetchInterval:Y,retry:!1}),r=t?D.safeParse(t):null;return{status:r?.success?r.data:Oe,isLoading:n}}function Ae({addonId:e}){let{status:t}=X(e);return x(C,{children:[E(`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&&x(`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 je({addonId:e}){let n=w(),[r,a]=T(!1),[o,c]=T(null),l=k(),{status:u}=X(e),d=y(()=>{n.invalidateQueries({queryKey:[[`meshNetwork`]]})},[n]),f=g(),p=i({onSuccess:d}),m=s({onSuccess:d}),h=y(async()=>{a(!0);let t={cancelled:!1};c(t);try{let n=await f.mutateAsync({addonId:e});if(t.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!t.cancelled&&(await Le(2e3),!t.cancelled);){let t=await l.trpcClient.meshNetwork.getStatus.query({addonId:e}).catch(()=>null),n=t?D.safeParse(t):null;if(n?.success&&n.data.joined){d();break}if(Date.now()-r>6e5)break}}finally{a(!1),c(null)}},[e,d,f,l]),_=y(()=>{o&&(o.cancelled=!0),a(!1),c(null)},[o]);return E(C,{children:u.joined?x(C,{children:[x(t,{size:`sm`,variant:`secondary`,disabled:p.isPending,onClick:()=>p.mutate({addonId:e}),children:[p.isPending?E(P,{className:`h-3 w-3 animate-spin`}):E(le,{className:`h-3 w-3`}),`Disconnect`]}),x(t,{size:`sm`,variant:`ghost`,disabled:m.isPending,onClick:()=>m.mutate({addonId:e}),children:[m.isPending?E(P,{className:`h-3 w-3 animate-spin`}):E(W,{className:`h-3 w-3`}),`Log out`]})]}):r?x(t,{size:`sm`,variant:`ghost`,onClick:_,children:[E(ue,{className:`h-3 w-3 mr-1`}),` Cancel`]}):x(C,{children:[x(t,{size:`sm`,variant:`primary`,onClick:()=>void h(),children:[E(fe,{className:`h-3 w-3`}),`Connect`]}),x(t,{size:`sm`,variant:`ghost`,disabled:m.isPending,onClick:()=>m.mutate({addonId:e}),children:[m.isPending?E(P,{className:`h-3 w-3 animate-spin`}):E(W,{className:`h-3 w-3`}),`Log out`]})]})})}function Me({addonId:e}){let{status:t}=X(e),r=n({addonId:e},{refetchInterval:De,retry:!1});return x(`div`,{className:`rounded-lg border border-border bg-surface`,children:[x(`div`,{className:`p-4 space-y-4`,children:[t.error&&E(p,{message:t.error}),E(Ne,{status:t}),t.endpoints.length>0&&x(`div`,{className:`space-y-1.5`,children:[E(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>x(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[x(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Ee[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?E(F,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),x(`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:[E(L,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),E(`div`,{className:`border-t border-border`,children:E(Fe,{peers:r.data?.peers??[],loading:r.isLoading})})]})}function Ne({status:e}){return E(`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?Pe(e.keyExpiry):`—`}].map(e=>x(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[E(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),E(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Pe(e){let t=e-Date.now();if(t<0)return`Expired ${Q(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 Fe({peers:e,loading:t}){let n=S(()=>e.map(e=>({...e,_id:e.id})),[e]),i=y(e=>{e&&navigator.clipboard?.writeText(e)},[]),a=S(()=>[{key:`hostname`,header:`Hostname`,render:e=>x(`div`,{className:`flex flex-col`,children:[x(`div`,{className:`flex items-center gap-1.5`,children:[E(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&E(r,{variant:`info`,children:`self`}),e.exitNodeOption&&E(r,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&E(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?x(`div`,{className:`flex items-center gap-1`,children:[E(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),E(`button`,{onClick:()=>i(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:E(j,{className:`h-3 w-3 text-foreground-subtle`})})]}):E(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?x(`div`,{className:`flex items-center gap-1`,children:[E(`span`,{className:`font-mono text-xs`,children:t}),E(`button`,{onClick:()=>i(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:E(j,{className:`h-3 w-3 text-foreground-subtle`})})]}):E(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>x(`div`,{className:`flex items-center gap-1.5`,children:[E(r,{variant:Ie(e.connection),children:e.connection}),e.relay&&E(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?E(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):E(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>x(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Z(e.txBytes),` · ↓ `,Z(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>E(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?Q(e.lastSeenMs):`—`})}],[i]);return t&&e.length===0?x(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[E(P,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):e.length===0?E(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):E(`div`,{className:`p-4`,children:E(_,{columns:a,rows:n,rowKey:e=>e._id,minWidthPx:820})})}function Ie(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function Z(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 Q(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 Le(e){return new Promise(t=>setTimeout(t,e))}function $(){return E(`div`,{className:`flex flex-col p-4`,children:E(H,{tabs:[{id:`addresses`,label:`Network Addresses`,icon:N,content:E(Te,{})},{id:`remote-access`,label:`Remote Access`,icon:F,content:E(he,{})},{id:`mesh`,label:`Mesh Networks`,icon:A,content:E(ke,{})},{id:`turn`,label:`TURN Servers`,icon:z,content:E(ye,{})}]})})}export{$ as NetworkPage};
|