@camstack/addon-admin-ui 1.2.707 → 1.2.708
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/CHANGELOG.md +7 -0
- package/dist/assets/{AccessSection-CdCEsvPD.js → AccessSection-CmL_Onb2.js} +1 -1
- package/dist/assets/{Addons-b61CNfYt.js → Addons-DWymb9Vl.js} +1 -1
- package/dist/assets/{AdminPage-D_ScR9To.js → AdminPage-Q8iyQ6l8.js} +1 -1
- package/dist/assets/{AdminSectionedPage-DGidDJBb.js → AdminSectionedPage-BD_fZFRe.js} +1 -1
- package/dist/assets/{AiProfiles-DabE0DP8.js → AiProfiles-BIxZ2_6q.js} +1 -1
- package/dist/assets/Archive-C6_m1wEE.js +1 -0
- package/dist/assets/{BootstrapSettingsForm-DaIg6gq5.js → BootstrapSettingsForm-CaT3bTFg.js} +1 -1
- package/dist/assets/Build-DvKE6nTb.js +40 -0
- package/dist/assets/{Calendars-CdCIOI6j.js → Calendars-DHzAhyJ7.js} +1 -1
- package/dist/assets/{Cluster-B0FV-fZt.js → Cluster-DbxqzICC.js} +1 -1
- package/dist/assets/CompositionBlockEditor-Bgx8eHTM.js +2 -0
- package/dist/assets/{CompositionEditorPage-CKvufPBG.js → CompositionEditorPage-B9gDFYDb.js} +1 -1
- package/dist/assets/{Data-C2vZTveq.js → Data-CcpaQCFA.js} +1 -1
- package/dist/assets/DeviceDetail-NBocrvbT.js +1 -0
- package/dist/assets/{Devices-VYfr6Qjh.js → Devices-D8DTAwFv.js} +1 -1
- package/dist/assets/{EmbedDevicePage-R7WS-d3D.js → EmbedDevicePage-CPQdBTEQ.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-Z2tf61w_.js → EmbedPlayerPage-B5_-KzBH.js} +1 -1
- package/dist/assets/{History-Bo9FgRVX.js → History-ft50TIgH.js} +1 -1
- package/dist/assets/{Identity-D4kdH7U7.js → Identity-D0tXeMJI.js} +1 -1
- package/dist/assets/{InstancesTable-CnwNnIGg.js → InstancesTable-BECFInNU.js} +1 -1
- package/dist/assets/{IntegrationDetail-Bz-VToH2.js → IntegrationDetail-HyHJN95v.js} +1 -1
- package/dist/assets/{Integrations-CE8kyRYx.js → Integrations-9Im6toi_.js} +1 -1
- package/dist/assets/{Integrations-BzM7SsEz.js → Integrations-CZBdHxHR.js} +1 -1
- package/dist/assets/{Library-BOlhpDfS.js → Library-_igcImHQ.js} +1 -1
- package/dist/assets/{Locations-BEURX3s_.js → Locations-BXSHCcGW.js} +1 -1
- package/dist/assets/{Logs-Do0Qz1Xm.js → Logs-BFhMej4c.js} +1 -1
- package/dist/assets/{MaskShapeCanvas-CSF5f0x4.js → MaskShapeCanvas-DJAQ2y3P.js} +1 -1
- package/dist/assets/{MotionZonesSettings-4G_zRdIV.js → MotionZonesSettings-CwHYVPtN.js} +1 -1
- package/dist/assets/{MyAccess-DRCDj6Xz.js → MyAccess-d4Dxkbs9.js} +1 -1
- package/dist/assets/{Network-ZDD_Mojs.js → Network-CZWNHZbt.js} +1 -1
- package/dist/assets/{NewExportModal-oXocqeh1.js → NewExportModal-Djoe8Y50.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-v8si7yGj.js → NodeAddonsSettingsPanel-B9ozPPw1.js} +1 -1
- package/dist/assets/Notifications-BvvHJsaT.js +1 -0
- package/dist/assets/{PanelContent-CfStlJ6y.js → PanelContent-BvMFsT5L.js} +1 -1
- package/dist/assets/{Pipeline-C5FSBQqW.js → Pipeline-BOw5x-8P.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-WoQQopZx.js → PrivacyMaskSettings-hArLTspd.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-C70XKDO3.js → SceneMonitorEditor-BQ4Ow_Zr.js} +1 -1
- package/dist/assets/{SessionsList-e1hGFA_b.js → SessionsList-Dd_M6VZ_.js} +1 -1
- package/dist/assets/{Showroom-BZ5FVUHJ.js → Showroom-BV_20igh.js} +1 -1
- package/dist/assets/{StorageLocationsTable-BdX7iiy2.js → StorageLocationsTable-BlY2ZuRD.js} +1 -1
- package/dist/assets/{System-CXy2jAEJ.js → System-kmtCUnQG.js} +1 -1
- package/dist/assets/TemplateEditorDialog-qiaEmHIC.js +1 -0
- package/dist/assets/{Terminal-BzVEx5-W.js → Terminal-CCvtDRX3.js} +1 -1
- package/dist/assets/{TrainingProviders-DcR68K6U.js → TrainingProviders-QpCAaIRs.js} +1 -1
- package/dist/assets/{Viewer-Cm8XLQl9.js → Viewer-DZ8d24s6.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-D8K0TmuG.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CU5UJUMr.js} +1 -1
- package/dist/assets/{action-draft-C0aEYbbJ.js → action-draft-B7-vMM4C.js} +1 -1
- package/dist/assets/{ai-page.helpers-CMOPYT4m.js → ai-page.helpers-CH98Xnez.js} +1 -1
- package/dist/assets/{assignment-candidates-BjQPH37S.js → assignment-candidates-CMfCAjbD.js} +1 -1
- package/dist/assets/{authed-media-CIYKXUSa.js → authed-media-mKoUB7Wx.js} +1 -1
- package/dist/assets/{board-model-B0lkkU_n.js → board-model-D0VuBTSN.js} +1 -1
- package/dist/assets/{camera-block-model-Dll1DsHk.js → camera-block-model-1_LIwub0.js} +1 -1
- package/dist/assets/{client-BDuXx1QP.js → client-BN2LRjot.js} +40 -37
- package/dist/assets/{command-vocab-BvTOW30-.js → command-vocab-CRRlGeAg.js} +1 -1
- package/dist/assets/{device-integration-icon-DM1vonRZ.js → device-integration-icon-evTdq6FJ.js} +1 -1
- package/dist/assets/device-picker-model-CZRDLeqa.js +1 -0
- package/dist/assets/{dist-UoOeKkgf.js → dist-BBOm1A6D.js} +1 -1
- package/dist/assets/{dist-i_V6azZ-.js → dist-C4JNZdd3.js} +50 -47
- package/dist/assets/divide-Bmm9r7CP.js +1 -0
- package/dist/assets/{format-DZS30uCp.js → format-B9MC39Sk.js} +1 -1
- package/dist/assets/{hostInit-BDQA3BN9.js → hostInit-B1RT7r2L.js} +1 -1
- package/dist/assets/{i18n-edIqwiB1.js → i18n-D0ym_MsQ.js} +1 -1
- package/dist/assets/icons-BIPkMWld.js +1 -0
- package/dist/assets/{index-BdZSFp7D.js → index-D3mVWYUM.js} +4 -4
- package/dist/assets/{linked-devices-model-iW46YpkQ.js → linked-devices-model-CKiEiEUw.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-d881d50d.js → mf-entry-bootstrap-0-2bdfde26.js} +2 -2
- package/dist/assets/mount-CZRDLeqa.js +1 -0
- package/dist/assets/{notification-rule-status-CMiSvQbc.js → notification-rule-status-B6U4GFtq.js} +1 -1
- package/dist/assets/{player-overlays-DIlWLHUP.js → player-overlays-D1NExXj2.js} +1 -1
- package/dist/assets/remoteEntry-B-bcpFgG.js +1 -0
- package/dist/assets/scan-eye-C862nWtV.js +1 -0
- package/dist/assets/shapes-D4IRNSXI.js +1 -0
- package/dist/assets/{src-DKJzc4UU.js → src-6lZ5_wSy.js} +10 -10
- package/dist/assets/{sso-popup-FtzI6ryL.js → sso-popup-C96ZvJqF.js} +1 -1
- package/dist/assets/{step-inspector-model-NCZ8oRWD.js → step-inspector-model-9ly-JWp5.js} +1 -1
- package/dist/assets/{use-scenes-feed-lfckxPsP.js → use-scenes-feed-czWy_ho6.js} +1 -1
- package/dist/assets/{useAdminDeviceRemoval-BqnJTWmj.js → useAdminDeviceRemoval-QjQBZ6tM.js} +1 -1
- package/dist/assets/useEventInvalidation-CZRDLeqa.js +1 -0
- package/dist/assets/{useNodeUrlSelection-D7VEc_ts.js → useNodeUrlSelection-DHio5p0q.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-VpC5Rl06.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-J9oLjMJ0.js} +2 -2
- package/dist/index.html +8 -8
- package/dist/server/addon.js +7 -2
- package/package.json +2 -2
- package/dist/assets/Archive-tvC3GS9d.js +0 -1
- package/dist/assets/Build-FmDDr5Iv.js +0 -40
- package/dist/assets/CompositionBlockEditor-CHyI7DTr.js +0 -2
- package/dist/assets/DeviceDetail-BbhNElsK.js +0 -1
- package/dist/assets/Notifications-BnLCpPnP.js +0 -1
- package/dist/assets/create-composition-_Nnzu3CV.js +0 -1
- package/dist/assets/device-picker-model-CGRy9l3T.js +0 -1
- package/dist/assets/icons-Dmo60g7m.js +0 -1
- package/dist/assets/mount-CGRy9l3T.js +0 -1
- package/dist/assets/remoteEntry-CPn9l_TV.js +0 -1
- package/dist/assets/scan-eye-C7ejeyl9.js +0 -1
- package/dist/assets/shapes-CAlvyzli.js +0 -1
- package/dist/assets/useEventInvalidation-CGRy9l3T.js +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./Devices-
|
|
2
|
-
import{a as e,t}from"./rolldown-runtime-Cyuzqnbw.js";import"./virtual_mf-exposes___mfe_internal__admin_ui_host__remoteEntry-_hash_-DnnXQRkG.js";import{a as n,o as r,r as i}from"./virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-VpC5Rl06.js";import{t as a}from"./vite-preload-helper-kNaey6uv.js";import{A as o,C as s,D as c,F as l,G as u,H as d,I as f,J as p,K as m,M as h,N as g,O as _,P as v,Q as y,R as b,S as x,V as S,X as C,Y as w,Z as T,a as E,d as D,et as O,i as k,j as A,k as j,m as M,o as N,t as ee,u as P,x as F,z as I}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$a as L,$i as te,Bn as ne,Cn as re,Cr as ie,Dr as ae,Dt as oe,Ea as se,Et as R,Hr as ce,In as le,Ir as ue,J as de,K as fe,Na as z,Nn as pe,Nr as me,Q as B,Qa as he,Qn as ge,Rn as _e,Rt as ve,Sr as ye,T as be,Tt as xe,V as Se,Vn as Ce,Vr as we,Wa as Te,Wi as Ee,Xi as De,Xn as Oe,Yi as ke,Yn as Ae,Z as je,Zr as Me,Zt as Ne,_a as Pe,_i as Fe,_r as Ie,_t as Le,aa as Re,ba as ze,ca as Be,ci as Ve,ct as He,dn as Ue,eo as We,er as Ge,fa as Ke,ft as qe,gt as Je,ir as Ye,it as Xe,ji as Ze,jn as Qe,jt as $e,ki as et,kr as tt,kt as nt,ma as rt,ni as it,oa as at,oi as ot,pa as st,q as ct,qr as lt,ri as ut,ro as dt,rr as ft,rt as pt,sa as mt,si as ht,tn as gt,to as _t,vi as vt,wi as yt,wt as bt,xa as xt,xr as St,ya as Ct,yi as wt,yn as Tt,yt as V,zr as H}from"./player-overlays-DIlWLHUP.js";import{$o as Et,At as Dt,B as Ot,Ct as kt,Dt as At,Et as jt,Ft as Mt,G as Nt,Gs as Pt,Gt as Ft,H as It,Ht as Lt,J as Rt,Jt as zt,K as Bt,Kt as Vt,L as Ht,Ls as Ut,Lt as Wt,Nt as Gt,Ot as Kt,P as qt,Pt as Jt,Qc as Yt,R as Xt,Rs as Zt,Rt as Qt,St as $t,Tt as en,U as tn,Un as nn,V as rn,Vt as an,W as on,Wo as sn,Wr as cn,Wt as ln,Xc as un,Xt as dn,Y as fn,Yt as pn,Zc as mn,Zs as U,Zt as hn,a as gn,an as _n,c as vn,ci as yn,cn as bn,d as xn,ea as Sn,en as Cn,f as wn,ft as Tn,ga as En,ic as Dn,in as On,it as kn,kt as An,ln as jn,n as Mn,nn as Nn,o as Pn,oi as Fn,on as In,q as Ln,qt as Rn,r as zn,ra as Bn,rl as Vn,rn as Hn,rt as Un,s as Wn,si as Gn,sn as Kn,t as qn,tn as Jn,ul as Yn,wt as Xn,z as Zn,zc as Qn,zt as $n}from"./client-BDuXx1QP.js";import{_ as er,a as tr,c as nr,d as rr,f as ir,g as ar,h as or,i as sr,l as cr,m as lr,n as ur,o as dr,p as fr,r as pr,s as mr,t as hr,u as gr}from"./terminal-DZ5OZpgC.js";import{$r as _r,$t as vr,Aa as yr,Ac as br,Ad as xr,Af as Sr,Ao as Cr,Ba as wr,Bl as Tr,Bs as Er,Cc as Dr,Da as Or,Do as kr,Dp as Ar,Ec as jr,Ep as W,Fa as Mr,Fi as Nr,Fn as Pr,Fp as Fr,Gi as Ir,Gs as Lr,Hf as Rr,Hp as zr,Hs as Br,Ht as Vr,Id as Hr,If as Ur,Ii as Wr,Ip as Gr,Ir as Kr,It as qr,Jd as Jr,Ji as Yr,Jn as Xr,Js as Zr,Jt as Qr,Ki as $r,La as ei,Lp as ti,Ls as ni,Lt as ri,M as ii,Mi as ai,Mp as oi,Nc as si,Ni as ci,Nn as li,Np as ui,Oc as di,Od as fi,Oi as pi,Oo as mi,Or as hi,P as gi,Pi as _i,Pn as vi,Pp as yi,Ps as bi,Pt as xi,Qc as Si,Qd as Ci,Qf as wi,Qt as Ti,Ri as Ei,Rs as Di,Rt as Oi,Sc as ki,Sr as Ai,Ts as ji,Ui as Mi,Ut as Ni,Va as Pi,Vc as Fi,Vi as Ii,Vs as Li,Vt as Ri,Wi as zi,Wp as Bi,Ws as Vi,Wt as Hi,Xp as Ui,Xt as Wi,Y as Gi,Yd as Ki,Yi as qi,Za as Ji,Zd as Yi,Zp as Xi,Zs as Zi,Zt as Qi,_a as $i,_c as ea,_r as ta,af as na,ai as ra,at as ia,bp as aa,br as oa,ci as sa,cl as ca,do as la,dr as ua,ds as da,ec as fa,el as pa,en as ma,f as ha,fa as ga,fo as _a,ga as va,gc as ya,gr as ba,ha as xa,hc as Sa,ho as Ca,hp as wa,hr as Ta,i as Ea,ii as Da,il as Oa,jl as ka,jo as Aa,jt as ja,ka as Ma,kc as Na,kf as Pa,ko as Fa,kr as Ia,la as La,lc as Ra,ll as za,ls as Ba,m as Va,ma as Ha,mp as Ua,n as Wa,nl as Ga,nm as Ka,nn as qa,on as Ja,pa as Ya,pi as Xa,qa as Za,qi as Qa,qs as $a,qt as eo,r as to,ro as no,rt as ro,si as io,so as ao,tc as oo,tm as so,ut as co,va as lo,vp as G,vr as uo,wl as fo,wr as po,xa as mo,xc as ho,xp as go,xt as _o,ya as vo,yr as yo,za as bo,zi as xo,zs as So,zt as Co}from"./src-DKJzc4UU.js";import{r as wo,t as To}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.js-BPba2g2p.js";import{t as Eo}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-ZBKFTPET.js";import{n as Do,t as K}from"./i18n-edIqwiB1.js";import{a as Oo,c as ko,i as Ao,l as jo,n as Mo,o as No,s as Po,t as q,u as Fo}from"./useTranslation-BJr-n0es.js";import"./mount-CGRy9l3T.js";import{a as Io,c as Lo,d as Ro,i as zo,n as Bo,o as Vo,r as Ho,s as Uo,t as Wo,u as Go}from"./sso-popup-FtzI6ryL.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})(),O(),wo();var Ko=`camstack.debugLayers`,qo=/(transform|opacity|filter|perspective)/;function Jo(e){return e!==``&&e!==`none`}function Yo(e,t,n=120){if(t.width<=0||t.height<=0||t.top>=n||t.bottom<=0)return null;let r=[];e.position===`fixed`&&r.push(`fixed`),e.position===`sticky`&&r.push(`sticky`),(Jo(e.backdropFilter)||Jo(e.webkitBackdropFilter))&&r.push(`backdrop-filter`),Jo(e.filter)&&r.push(`filter`);let i=Number.parseFloat(e.opacity);return Number.isFinite(i)&&i<1&&r.push(`opacity`),Jo(e.transform)&&r.push(`transform`),Jo(e.perspective)&&r.push(`perspective`),e.isolation===`isolate`&&r.push(`isolation`),e.mixBlendMode!==``&&e.mixBlendMode!==`normal`&&r.push(`mix-blend-mode`),qo.test(e.willChange)&&r.push(`will-change`),r.length===0?null:{reasons:r,zIndex:e.zIndex}}function Xo(e,t,n,r){let i=n!==null&&n!==``?`[${n}]`:t.split(/\s+/).filter(e=>e!==``).slice(0,3).map(e=>`.${e}`).join(``);return`${e.toLowerCase()}${i} z=${r.zIndex} ${r.reasons.join(`+`)}`}function Zo(e,t){let n=new URLSearchParams(e).get(`debugLayers`);return n===`1`?{on:!0,persist:`1`}:n===`0`?{on:!1,persist:null}:{on:t===`1`,persist:`keep`}}var Qo=`camstack.debugLayers.noBlur`,$o=`camstack.debugLayers.outlines`,es=`camstack.debugLayers.topLayer`,ts=`debug-no-backdrop-blur`;function ns(e,t){try{return e===null?null:e.getItem(t)}catch{return null}}function rs(e,t,n){try{if(e===null)return;n===null?e.removeItem(t):e.setItem(t,n)}catch{}}function is(e,t){let n=Zo(t,ns(e,Ko));n.persist!==`keep`&&rs(e,Ko,n.persist);let r={on:n.on,noBlur:ns(e,Qo)===`1`,outlines:ns(e,$o)!==`0`,topLayer:ns(e,es)!==`0`},i=new Set,a=e=>{r=e;for(let e of i)e()};return{getState:()=>r,subscribe:e=>(i.add(e),()=>{i.delete(e)}),setOn:t=>{if(rs(e,Ko,t?`1`:null),!t){rs(e,Qo,null),rs(e,$o,null),rs(e,es,null),a({on:t,noBlur:!1,outlines:!0,topLayer:!0});return}a({...r,on:t})},setNoBlur:t=>{rs(e,Qo,t?`1`:null),a({...r,noBlur:t})},setOutlines:t=>{rs(e,$o,t?null:`0`),a({...r,outlines:t})},setTopLayer:t=>{rs(e,es,t?null:`0`),a({...r,topLayer:t})}}}var as=[`transform`,`will-change`,`position`,`backdrop-filter`,`filter`,`opacity`];function os(e){return as.map(t=>`${t}: ${e===null?`n/a`:e(t)||`-`}`)}var ss=null;function cs(){try{return window.sessionStorage}catch{return null}}function ls(){return ss===null&&(ss=is(cs(),window.location.search)),ss}function us(){let e=ls();return{...C(e.subscribe,e.getState),setOn:e.setOn,setNoBlur:e.setNoBlur,setOutlines:e.setOutlines,setTopLayer:e.setTopLayer}}O();var ds=`data-debug-layers`,fs=250,ps=60;function ms(){let e=[],t=document.body.querySelectorAll(`*`);for(let n of Array.from(t)){if(e.length>=ps)break;if(n.closest(`[${ds}]`)!==null)continue;let t=n.getBoundingClientRect();if(t.width<=0||t.height<=0||t.top>=120||t.bottom<=0)continue;let r=getComputedStyle(n),i=Yo({position:r.position,zIndex:r.zIndex,opacity:r.opacity,filter:r.filter,backdropFilter:r.backdropFilter,webkitBackdropFilter:r.getPropertyValue(`-webkit-backdrop-filter`),transform:r.transform,perspective:r.perspective,isolation:r.isolation,mixBlendMode:r.mixBlendMode,willChange:r.willChange},t);if(i===null)continue;let a=n.getAttribute(`data-testid`);e.push({id:e.length,top:t.top,left:t.left,width:t.width,height:t.height,label:Xo(n.tagName,typeof n.className==`string`?n.className:``,a===null?null:`data-testid=${a}`,i),reasons:i.reasons})}return e}function hs(e){let t=getComputedStyle(e),n=e=>Number.parseFloat(e)||0;return{top:n(t.paddingTop),right:n(t.paddingRight),bottom:n(t.paddingBottom),left:n(t.paddingLeft)}}function gs(e){return e.includes(`backdrop-filter`)||e.includes(`filter`)?{outline:`outline-danger`,chip:`bg-danger`}:e.includes(`opacity`)||e.includes(`mix-blend-mode`)?{outline:`outline-warning`,chip:`bg-warning`}:e.includes(`fixed`)||e.includes(`sticky`)?{outline:`outline-info`,chip:`bg-info`}:{outline:`outline-primary`,chip:`bg-primary`}}function _s(){let e=Reflect.get(navigator,`standalone`);return window.matchMedia(`(display-mode: standalone)`).matches||e===!0}function vs(){return`1.2.707`}function ys(e,t){if(!(e===null||typeof e.showPopover!=`function`))try{e.matches(`:popover-open`)&&e.hidePopover(),t&&e.showPopover()}catch{}}function bs(){let e=document.querySelector(`[data-debug-header]`),t=e===null?null:e.querySelector(`img`),n=e=>os(e===null?null:t=>getComputedStyle(e).getPropertyValue(t));return{header:n(e),logo:n(t)}}function xs({noBlur:e,onNoBlurChange:t,outlines:n,onOutlinesChange:r,topLayer:i,onTopLayerChange:a}){let[o,c]=w([]),[l,u]=w({top:0,right:0,bottom:0,left:0}),d=p(null),f=p(null),m=p(null),[h,g]=w(bs),_=b(()=>{ys(f.current,i),c(n?ms():[]),g(bs()),d.current!==null&&u(hs(d.current))},[n,i]),v=b(()=>{m.current===null&&(m.current=window.setTimeout(()=>{m.current=null,_()},fs))},[_]);return S(()=>{_();let e=new MutationObserver(e=>{e.some(e=>!(e.target instanceof Element&&e.target.closest(`[${ds}]`)!==null))&&v()});return e.observe(document.body,{childList:!0,subtree:!0,attributes:!0}),window.addEventListener(`resize`,v),window.addEventListener(`orientationchange`,v),window.addEventListener(`scroll`,v,!0),()=>{e.disconnect(),window.removeEventListener(`resize`,v),window.removeEventListener(`orientationchange`,v),window.removeEventListener(`scroll`,v,!0),m.current!==null&&window.clearTimeout(m.current)}},[_,v]),To(s(`div`,{[ds]:``,ref:f,popover:`manual`,className:`pointer-events-none fixed inset-0 z-[2147483647] m-0 h-full w-full overflow-visible border-0 bg-transparent p-0`,children:[x(`div`,{ref:d,"aria-hidden":!0,className:`invisible absolute h-0 w-0`,style:{paddingTop:`env(safe-area-inset-top)`,paddingRight:`env(safe-area-inset-right)`,paddingBottom:`env(safe-area-inset-bottom)`,paddingLeft:`env(safe-area-inset-left)`}}),o.map(e=>{let t=gs(e.reasons);return x(`div`,{"data-testid":`debug-layer-box`,className:_t(`absolute outline outline-1 -outline-offset-1`,t.outline),style:{top:e.top,left:e.left,width:e.width,height:e.height},children:x(`span`,{className:_t(`absolute left-0 max-w-[90vw] truncate px-1 font-mono text-[9px] leading-3 text-primary-foreground`,t.chip),style:{top:e.id%6*12},children:e.label})},e.id)}),s(`div`,{"data-testid":`debug-layers-badge`,className:`absolute right-1 top-14 rounded-md bg-background-elevated px-2 py-1 font-mono text-[10px] leading-4 text-foreground outline outline-1 outline-border`,children:[s(`div`,{children:[`admin-ui `,vs()]}),s(`div`,{children:[`inset t`,l.top,` r`,l.right,` b`,l.bottom,` l`,l.left]}),s(`div`,{children:[`display-mode standalone:`,` `,window.matchMedia(`(display-mode: standalone)`).matches?`yes`:`no`,` · `,`navigator.standalone: `,_s()?`yes`:`no`]}),s(`div`,{children:[window.innerWidth,`x`,window.innerHeight,` · `,o.length,` layers`]}),x(Xa,{checked:e,onCheckedChange:t,label:`no backdrop blur`,className:`pointer-events-auto mt-1 text-[10px]`}),x(Xa,{checked:n,onCheckedChange:r,label:`outlines`,className:`pointer-events-auto mt-1 text-[10px]`}),x(Xa,{checked:i,onCheckedChange:a,label:`top layer`,className:`pointer-events-auto mt-1 text-[10px]`}),s(`div`,{"data-testid":`debug-header-styles`,className:`mt-1`,children:[x(`div`,{children:`header`}),h.header.map(e=>x(`div`,{children:e},e)),x(`div`,{children:`header logo`}),h.logo.map(e=>x(`div`,{children:e},e))]})]})]}),document.body)}function Ss(){let{on:e,noBlur:t,setNoBlur:n,outlines:r,setOutlines:i,topLayer:a,setTopLayer:o}=us();return S(()=>{let n=e&&t;return document.documentElement.classList.toggle(ts,n),()=>document.documentElement.classList.remove(ts)},[e,t]),e?x(xs,{noBlur:t,onNoBlurChange:n,outlines:r,onOutlinesChange:i,topLayer:a,onTopLayerChange:o}):null}var Cs=`camera`;function ws(e){return e===null||!/^\d+$/.test(e)?null:Number(e)}function Ts(e,t){return t===null?e:e.filter(e=>e.deviceId===t)}function Es(e,t){let n=new Set(e.map(e=>e.deviceId));return t!==null&&n.add(t),[...n].sort((e,t)=>e-t)}var Ds=`/archive`,Os=`/addon/training`,ks=`/library?tab=exports`,As=`section`,js=`camera`,Ms=`view`;function Ns(e,t){let n=`${Ds}?${As}=cameras&${js}=${String(e)}`;return t===void 0?n:`${n}&${Ms}=${t}`}function Ps(e){return e===void 0?ks:`${ks}&${Cs}=${String(e)}`}var Fs={settings:`settings`,space:`health`,health:`health`,events:`review`,review:`review`},Is={storage:Ds,events:Ds,cameras:Ds,exports:ks,activity:`${Ds}#activity`,management:`${Ds}#tools`},Ls=/^\/archive\/(\d+)\/?$/;function Rs(e,t){let n=new URLSearchParams(t);if(e===`/recordings`){let e=n.get(`tab`);return e===null?Ds:Is[e]??`/archive`}if(e===`/library`&&n.get(`tab`)===`events`)return n.get(`section`)===`retrain`?Os:Ds;let r=Ls.exec(e);if(r?.[1]!==void 0){let e=Number(r[1]),t=n.get(As);return t===`exports`?Ps(e):Ns(e,t===null?void 0:Fs[t])}return null}O();var zs=/^(?:[a-z][a-z0-9+.-]*:|[\\/]{2})/i,Bs=/^[\\/]{2}/;function Vs(e,t){return t+e.replace(/\\/g,`/`)}var Hs=`popstate`;function Us(e){return typeof e==`object`&&!!e&&`pathname`in e&&`search`in e&&`hash`in e&&`state`in e&&`key`in e}function Ws(e={}){function t(e,t){let n=t.state?.masked,{pathname:r,search:i,hash:a}=n||e.location;return Js(``,{pathname:r,search:i,hash:a},t.state&&t.state.usr||null,t.state&&t.state.key||`default`,n?{pathname:e.location.pathname,search:e.location.search,hash:e.location.hash}:void 0)}function n(e,t){return typeof t==`string`?t:Ys(t)}return Zs(t,n,null,e)}function J(e,t){if(e===!1||e==null)throw Error(t)}function Gs(e,t){if(!e){typeof console<`u`&&console.warn(t);try{throw Error(t)}catch{}}}function Ks(){return Math.random().toString(36).substring(2,10)}function qs(e,t){return{usr:e.state,key:e.key,idx:t,masked:e.mask?{pathname:e.pathname,search:e.search,hash:e.hash}:void 0}}function Js(e,t,n=null,r,i){return{pathname:typeof e==`string`?e:e.pathname,search:``,hash:``,...typeof t==`string`?Xs(t):t,state:n,key:t&&t.key||r||Ks(),mask:i}}function Ys({pathname:e=`/`,search:t=``,hash:n=``}){return t&&t!==`?`&&(e+=t.charAt(0)===`?`?t:`?`+t),n&&n!==`#`&&(e+=n.charAt(0)===`#`?n:`#`+n),e}function Xs(e){let t={};if(e){let n=e.indexOf(`#`);n>=0&&(t.hash=e.substring(n),e=e.substring(0,n));let r=e.indexOf(`?`);r>=0&&(t.search=e.substring(r),e=e.substring(0,r)),e&&(t.pathname=e)}return t}function Zs(e,t,n,r={}){let{window:i=document.defaultView,v5Compat:a=!1}=r,o=i.history,s=`POP`,c=null,l=u();l??(l=0,o.replaceState({...o.state,idx:l},``));function u(){return(o.state||{idx:null}).idx}function d(){s=`POP`;let e=u(),t=e==null?null:e-l;l=e,c&&c({action:s,location:h.location,delta:t})}function f(e,t){s=`PUSH`;let r=Us(e)?e:Js(h.location,e,t);n&&n(r,e),l=u()+1;let d=qs(r,l),f=h.createHref(r.mask||r);try{o.pushState(d,``,f)}catch(e){if(e instanceof DOMException&&e.name===`DataCloneError`)throw e;i.location.assign(f)}a&&c&&c({action:s,location:h.location,delta:1})}function p(e,t){s=`REPLACE`;let r=Us(e)?e:Js(h.location,e,t);n&&n(r,e),l=u();let i=qs(r,l),d=h.createHref(r.mask||r);o.replaceState(i,``,d),a&&c&&c({action:s,location:h.location,delta:0})}function m(e){return Qs(i,e)}let h={get action(){return s},get location(){return e(i,o)},listen(e){if(c)throw Error(`A history only accepts one active listener`);return i.addEventListener(Hs,d),c=e,()=>{i.removeEventListener(Hs,d),c=null}},createHref(e){return t(i,e)},createURL:m,encodeLocation(e){let t=m(e);return{pathname:t.pathname,search:t.search,hash:t.hash}},push:f,replace:p,go(e){return o.go(e)}};return h}function Qs(e,t,n=!1){let r=`http://localhost`;e&&(r=e.location.origin===`null`?e.location.href:e.location.origin),J(r,`No window.location.(origin|href) available to create URL`);let i=typeof t==`string`?t:Ys(t);return i=i.replace(/ $/,`%20`),!n&&Bs.test(i)&&(i=r+i),new URL(i,r)}function $s(e,t,n=`/`){return ec(e,t,n,!1)}function ec(e,t,n,r,i){let a=bc((typeof t==`string`?Xs(t):t).pathname||`/`,n);if(a==null)return null;let o=i??nc(e),s=null,c=yc(a);for(let e=0;s==null&&e<o.length;++e)s=hc(o[e],c,r);return s}function tc(e,t){let{route:n,pathname:r,params:i}=e;return{id:n.id,pathname:r,params:i,data:t[n.id],loaderData:t[n.id],handle:n.handle}}function nc(e){let t=rc(e);return ac(t),t}function rc(e,t=[],n=[],r=``,i=!1){let a=(e,a,o=i,s)=>{let c={relativePath:s===void 0?e.path||``:s,caseSensitive:e.caseSensitive===!0,childrenIndex:a,route:e};if(c.relativePath.startsWith(`/`)){if(!c.relativePath.startsWith(r)&&o)return;J(c.relativePath.startsWith(r),`Absolute route path "${c.relativePath}" nested under path "${r}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`),c.relativePath=c.relativePath.slice(r.length)}let l=Oc([r,c.relativePath]),u=n.concat(c);e.children&&e.children.length>0&&(J(e.index!==!0,`Index routes must not have child routes. Please remove all child routes from route path "${l}".`),rc(e.children,t,u,l,o)),!(e.path==null&&!e.index)&&t.push({path:l,score:pc(l,e.index),routesMeta:u.map((e,t)=>{let[n,r]=vc(e.relativePath,e.caseSensitive,t===u.length-1);return{...e,matcher:n,compiledParams:r}})})};return e.forEach((e,t)=>{if(e.path===``||!e.path?.includes(`?`))a(e,t);else for(let n of ic(e.path))a(e,t,!0,n)}),t}function ic(e){let t=e.split(`/`);if(t.length===0)return[];let[n,...r]=t,i=n.endsWith(`?`),a=n.replace(/\?$/,``);if(r.length===0)return i?[a,``]:[a];let o=ic(r.join(`/`)),s=[];return s.push(...o.map(e=>e===``?a:[a,e].join(`/`))),i&&s.push(...o),s.map(t=>e.startsWith(`/`)&&t===``?`/`:t)}function ac(e){e.sort((e,t)=>e.score===t.score?mc(e.routesMeta.map(e=>e.childrenIndex),t.routesMeta.map(e=>e.childrenIndex)):t.score-e.score)}var oc=/^:[\w-]+$/,sc=3,cc=2,lc=1,uc=10,dc=-2,fc=e=>e===`*`;function pc(e,t){let n=e.split(`/`),r=n.length;return n.some(fc)&&(r+=dc),t&&(r+=cc),n.filter(e=>!fc(e)).reduce((e,t)=>e+(oc.test(t)?sc:t===``?lc:uc),r)}function mc(e,t){return e.length===t.length&&e.slice(0,-1).every((e,n)=>e===t[n])?e[e.length-1]-t[t.length-1]:0}function hc(e,t,n=!1){let{routesMeta:r}=e,i={},a=`/`,o=[];for(let e=0;e<r.length;++e){let s=r[e],c=e===r.length-1,l=a===`/`?t:t.slice(a.length)||`/`,u={path:s.relativePath,caseSensitive:s.caseSensitive,end:c},d=s.matcher&&s.compiledParams?_c(u,l,s.matcher,s.compiledParams):gc(u,l),f=s.route;if(!d&&c&&n&&!r[r.length-1].route.index&&(d=gc({path:s.relativePath,caseSensitive:s.caseSensitive,end:!1},l)),!d)return null;Object.assign(i,d.params),o.push({params:i,pathname:Oc([a,d.pathname]),pathnameBase:Ac(Oc([a,d.pathnameBase])),route:f}),d.pathnameBase!==`/`&&(a=Oc([a,d.pathnameBase]))}return o}function gc(e,t){typeof e==`string`&&(e={path:e,caseSensitive:!1,end:!0});let[n,r]=vc(e.path,e.caseSensitive,e.end);return _c(e,t,n,r)}function _c(e,t,n,r){let i=t.match(n);if(!i)return null;let a=i[0],o=a.replace(/(.)\/+$/,`$1`),s=i.slice(1);return{params:r.reduce((e,{paramName:t,isOptional:n},r)=>{if(t===`*`){let e=s[r]||``;o=a.slice(0,a.length-e.length).replace(/(.)\/+$/,`$1`)}let i=s[r];return n&&!i?e[t]=void 0:e[t]=(i||``).replace(/%2F/g,`/`),e},{}),pathname:a,pathnameBase:o,pattern:e}}function vc(e,t=!1,n=!0){Gs(e===`*`||!e.endsWith(`*`)||e.endsWith(`/*`),`Route path "${e}" will be treated as if it were "${e.replace(/\*$/,`/*`)}" because the \`*\` character must always follow a \`/\` in the pattern. To get rid of this warning, please change the route path to "${e.replace(/\*$/,`/*`)}".`);let r=[],i=`^`+e.replace(/\/*\*?$/,``).replace(/^\/*/,`/`).replace(/[\\.*+^${}|()[\]]/g,`\\$&`).replace(/\/:([\w-]+)(\?)?/g,(e,t,n,i,a)=>{if(r.push({paramName:t,isOptional:n!=null}),n){let t=a.charAt(i+e.length);return t&&t!==`/`?`/([^\\/]*)`:`(?:/([^\\/]*))?`}return`/([^\\/]+)`}).replace(/\/([\w-]+)\?(\/|$)/g,`(/$1)?$2`);return e.endsWith(`*`)?(r.push({paramName:`*`}),i+=e===`*`||e===`/*`?`(.*)$`:`(?:\\/(.+)|\\/*)$`):n?i+=`\\/*$`:e!==``&&e!==`/`&&(i+=`(?:(?=\\/|$))`),[new RegExp(i,t?void 0:`i`),r]}function yc(e){try{return e.split(`/`).map(e=>decodeURIComponent(e).replace(/\//g,`%2F`)).join(`/`)}catch(t){return Gs(!1,`The URL path "${e}" could not be decoded because it is a malformed URL segment. This is probably due to a bad percent encoding (${t}).`),e}}function bc(e,t){if(t===`/`)return e;if(!e.toLowerCase().startsWith(t.toLowerCase()))return null;let n=t.endsWith(`/`)?t.length-1:t.length,r=e.charAt(n);return r&&r!==`/`?null:e.slice(n)||`/`}function xc(e,t=`/`){let{pathname:n,search:r=``,hash:i=``}=typeof e==`string`?Xs(e):e,a;return n?(n=Dc(n),a=n.startsWith(`/`)?Sc(n.substring(1),`/`):Sc(n,t)):a=t,{pathname:a,search:jc(r),hash:Mc(i)}}function Sc(e,t){let n=kc(t).split(`/`);return e.split(`/`).forEach(e=>{e===`..`?n.length>1&&n.pop():e!==`.`&&n.push(e)}),n.length>1?n.join(`/`):`/`}function Cc(e,t,n,r){return`Cannot include a '${e}' character in a manually specified \`to.${t}\` field [${JSON.stringify(r)}]. Please separate it out to the \`to.${n}\` field. Alternatively you may provide the full path as a string in <Link to="..."> and the router will parse it for you.`}function wc(e){return e.filter((e,t)=>t===0||e.route.path&&e.route.path.length>0)}function Tc(e){let t=wc(e);return t.map((e,n)=>n===t.length-1?e.pathname:e.pathnameBase)}function Ec(e,t,n,r=!1){let i;typeof e==`string`?i=Xs(e):(i={...e},J(!i.pathname||!i.pathname.includes(`?`),Cc(`?`,`pathname`,`search`,i)),J(!i.pathname||!i.pathname.includes(`#`),Cc(`#`,`pathname`,`hash`,i)),J(!i.search||!i.search.includes(`#`),Cc(`#`,`search`,`hash`,i)));let a=e===``||i.pathname===``,o=a?`/`:i.pathname,s;if(o==null)s=n;else{let e=t.length-1;if(!r&&o.startsWith(`..`)){let t=o.split(`/`);for(;t[0]===`..`;)t.shift(),--e;i.pathname=t.join(`/`)}s=e>=0?t[e]:`/`}let c=xc(i,s),l=o&&o!==`/`&&o.endsWith(`/`),u=(a||o===`.`)&&n.endsWith(`/`);return!c.pathname.endsWith(`/`)&&(l||u)&&(c.pathname+=`/`),c}var Dc=e=>e.replace(/[\\/]{2,}/g,`/`),Oc=e=>Dc(e.join(`/`)),kc=e=>e.replace(/\/+$/,``),Ac=e=>kc(e).replace(/^\/*/,`/`),jc=e=>!e||e===`?`?``:e.startsWith(`?`)?e:`?`+e,Mc=e=>!e||e===`#`?``:e.startsWith(`#`)?e:`#`+e,Nc=class{constructor(e,t,n,r=!1){this.status=e,this.statusText=t||``,this.internal=r,n instanceof Error?(this.data=n.toString(),this.error=n):this.data=n}};function Pc(e){return e!=null&&typeof e.status==`number`&&typeof e.statusText==`string`&&typeof e.internal==`boolean`&&`data`in e}function Fc(e){return Oc(e.map(e=>e.route.path).filter(Boolean))||`/`}var Ic=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;function Lc(e,t){let n=e;if(typeof n!=`string`||!zs.test(n))return{absoluteURL:void 0,isExternal:!1,to:n};let r=n,i=!1;if(Ic)try{let e=new URL(window.location.href),r=Bs.test(n)?new URL(Vs(n,e.protocol)):new URL(n),a=bc(r.pathname,t);r.origin===e.origin&&a!=null?n=a+r.search+r.hash:i=!0}catch{Gs(!1,`<Link to="${n}"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.`)}return{absoluteURL:r,isExternal:i,to:n}}Object.getOwnPropertyNames(Object.prototype).sort().join(`\0`);var Rc=[`POST`,`PUT`,`PATCH`,`DELETE`];new Set(Rc);var zc=[`GET`,...Rc];new Set(zc);var Bc=[`about:`,`blob:`,`chrome:`,`chrome-untrusted:`,`content:`,`data:`,`devtools:`,`file:`,`filesystem:`,`javascript:`];function Vc(e){try{return Bc.includes(new URL(e).protocol)}catch{return!1}}var Hc=j(null);Hc.displayName=`DataRouter`;var Uc=j(null);Uc.displayName=`DataRouterState`;var Wc=j(!1);function Gc(){return I(Wc)}var Kc=j({isTransitioning:!1});Kc.displayName=`ViewTransition`;var qc=j(new Map);qc.displayName=`Fetchers`;var Jc=j(null);Jc.displayName=`Await`;var Yc=j(null);Yc.displayName=`Navigation`;var Xc=j(null);Xc.displayName=`Location`;var Zc=j({outlet:null,matches:[],isDataRoute:!1});Zc.displayName=`Route`;var Qc=j(null);Qc.displayName=`RouteError`;var $c=`REACT_ROUTER_ERROR`,el=`REDIRECT`,tl=`ROUTE_ERROR_RESPONSE`;function nl(e){if(e.startsWith(`${$c}:${el}:{`))try{let t=JSON.parse(e.slice(28));if(typeof t==`object`&&t&&typeof t.status==`number`&&typeof t.statusText==`string`&&typeof t.location==`string`&&typeof t.reloadDocument==`boolean`&&typeof t.replace==`boolean`)return t}catch{}}function rl(e){if(e.startsWith(`${$c}:${tl}:{`))try{let t=JSON.parse(e.slice(40));if(typeof t==`object`&&t&&typeof t.status==`number`&&typeof t.statusText==`string`)return new Nc(t.status,t.statusText,t.data)}catch{}}function il(e,{relative:t}={}){J(al(),`useHref() may be used only in the context of a <Router> component.`);let{basename:n,navigator:r}=I(Yc),{hash:i,pathname:a,search:o}=ml(e,{relative:t}),s=a;return n!==`/`&&(s=a===`/`?n:Oc([n,a])),r.createHref({pathname:s,search:o,hash:i})}function al(){return I(Xc)!=null}function Y(){return J(al(),`useLocation() may be used only in the context of a <Router> component.`),I(Xc).location}function ol(){return I(Xc).navigationType}var sl=`You should call navigate() in a React.useEffect(), not when your component is first rendered.`;function cl(e){I(Yc).static||u(e)}function ll(){let{isDataRoute:e}=I(Zc);return e?Nl():ul()}function ul(){J(al(),`useNavigate() may be used only in the context of a <Router> component.`);let e=I(Hc),{basename:t,navigator:n}=I(Yc),{matches:r}=I(Zc),{pathname:i}=Y(),a=JSON.stringify(Tc(r)),o=p(!1);return cl(()=>{o.current=!0}),b((r,s={})=>{if(Gs(o.current,sl),!o.current)return;if(typeof r==`number`){n.go(r);return}let c=Ec(r,JSON.parse(a),i,s.relative===`path`);e==null&&t!==`/`&&(c.pathname=c.pathname===`/`?t:Oc([t,c.pathname])),(s.replace?n.replace:n.push)(c,s.state,s)},[t,n,a,i,e])}var dl=j(null);function fl(e){let t=I(Zc).outlet;return m(()=>t&&o(dl.Provider,{value:e},t),[t,e])}function pl(){let{matches:e}=I(Zc);return e[e.length-1]?.params??{}}function ml(e,{relative:t}={}){let{matches:n}=I(Zc),{pathname:r}=Y(),i=JSON.stringify(Tc(n));return m(()=>Ec(e,JSON.parse(i),r,t===`path`),[e,i,r,t])}function hl(e,t){return gl(e,t)}function gl(e,t,n){J(al(),`useRoutes() may be used only in the context of a <Router> component.`);let{navigator:r}=I(Yc),{matches:i}=I(Zc),a=i[i.length-1],s=a?a.params:{},c=a?a.pathname:`/`,l=a?a.pathnameBase:`/`,u=a&&a.route;{let e=u&&u.path||``;Fl(c,!u||e.endsWith(`*`)||e.endsWith(`*?`),`You rendered descendant <Routes> (or called \`useRoutes()\`) at "${c}" (under <Route path="${e}">) but the parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render.
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./Devices-D8DTAwFv.js","./src-6lZ5_wSy.js","./player-overlays-D1NExXj2.js","./chevron-down-CBb-F8DT.js","./client-BN2LRjot.js","./__vite-browser-external-DIbVKiho.js","./useTranslation-BJr-n0es.js","./AdminPage-Q8iyQ6l8.js","./device-integration-icon-evTdq6FJ.js","./useAdminDeviceRemoval-QjQBZ6tM.js","./useEventInvalidation-CZRDLeqa.js","./addon-kind-filter-CEGKkC1O.js","./Integrations-9Im6toi_.js","./i18n-D0ym_MsQ.js","./table-2-DMxm3oyu.js","./IntegrationDetail-HyHJN95v.js","./search-x-C5ra3Aft.js","./Pipeline-BOw5x-8P.js","./terminal-DZ5OZpgC.js","./usb-P4R9CjYI.js","./crop-B-t0rzRY.js","./layers-BH9u1mrE.js","./NodeAddonsSettingsPanel-B9ozPPw1.js","./settings-section-shape-DbQZZpNL.js","./step-inspector-model-9ly-JWp5.js","./board-model-D0VuBTSN.js","./DeviceDetail-NBocrvbT.js","./divide-Bmm9r7CP.js","./circle-slash-Duh934sZ.js","./scan-eye-C862nWtV.js","./shapes-D4IRNSXI.js","./file-up-2YD_M6f_.js","./CompositionBlockEditor-Bgx8eHTM.js","./camera-block-model-1_LIwub0.js","./assignment-candidates-CMfCAjbD.js","./device-picker-model-CZRDLeqa.js","./PanelContent-BvMFsT5L.js","./mount-CZRDLeqa.js","./TemplateEditorDialog-qiaEmHIC.js","./unlink-D3-IGpS8.js","./command-vocab-CRRlGeAg.js","./linked-devices-model-CKiEiEUw.js","./format-B9MC39Sk.js","./authed-media-mKoUB7Wx.js","./notification-rule-status-B6U4GFtq.js","./Showroom-BV_20igh.js","./EmbedPlayerPage-B5_-KzBH.js","./EmbedDevicePage-CPQdBTEQ.js","./Library-_igcImHQ.js","./user-x-DkWcmF99.js","./square-check-big-DAcFGNUN.js","./AdminSectionedPage-BD_fZFRe.js","./NewExportModal-Djoe8Y50.js","./use-scenes-feed-czWy_ho6.js","./format-size-DIxKXxtj.js","./Archive-C6_m1wEE.js","./scissors-DpiKUioV.js","./StorageLocationsTable-BlY2ZuRD.js","./eraser-B3lnG9yK.js","./hard-drive-download-C6N6tovA.js","./InstancesTable-BECFInNU.js","./link-2-off-DmsjRAt7.js","./Viewer-DZ8d24s6.js","./monitor-off-DnOkDa2s.js","./Build-DvKE6nTb.js","./variable-DTEpBbRf.js","./action-draft-B7-vMM4C.js","./CompositionEditorPage-B9gDFYDb.js","./Locations-BXSHCcGW.js","./Addons-DWymb9Vl.js","./useNodeUrlSelection-DHio5p0q.js","./AiProfiles-BIxZ2_6q.js","./flask-conical-D7tbJQpj.js","./message-square-plus-_aGccjyj.js","./ai-page.helpers-CH98Xnez.js","./MyAccess-d4Dxkbs9.js","./monitor-smartphone-DPI9EQus.js","./AccessSection-CmL_Onb2.js","./SessionsList-Dd_M6VZ_.js","./sso-popup-C96ZvJqF.js","./Logs-BFhMej4c.js","./timer-reset-5221y6Jb.js","./Identity-D0tXeMJI.js","./key-CH4aXNMz.js","./BootstrapSettingsForm-CaT3bTFg.js","./Network-CZWNHZbt.js","./useInvalidateAddonSettings-CyofQfBo.js","./Integrations-CZBdHxHR.js","./TrainingProviders-QpCAaIRs.js","./Data-CcpaQCFA.js","./database-zap-DHuELz_w.js","./System-kmtCUnQG.js","./ruler-Buxogset.js","./Cluster-DbxqzICC.js","./memory-stick-BQrJMbEW.js","./Terminal-CCvtDRX3.js","./Terminal-kHJ-D0s7.css","./Notifications-BvvHJsaT.js","./languages-Du_pOBpX.js","./History-ft50TIgH.js","./Calendars-DHzAhyJ7.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{a as e,t}from"./rolldown-runtime-Cyuzqnbw.js";import"./virtual_mf-exposes___mfe_internal__admin_ui_host__remoteEntry-_hash_-DnnXQRkG.js";import{a as n,o as r,r as i}from"./virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-J9oLjMJ0.js";import{t as a}from"./vite-preload-helper-kNaey6uv.js";import{A as o,C as s,D as c,F as l,G as u,H as d,I as f,J as p,K as m,M as h,N as g,O as _,P as v,Q as y,R as b,S as x,V as S,X as C,Y as w,Z as T,a as E,d as D,et as O,i as k,j as A,k as j,m as M,o as N,t as ee,u as P,x as F,z as I}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$a as L,$i as te,Bn as ne,Cn as re,Cr as ie,Dr as ae,Dt as oe,Ea as se,Et as R,Hr as ce,In as le,Ir as ue,J as de,K as fe,Na as z,Nn as pe,Nr as me,Q as B,Qa as he,Qn as ge,Rn as _e,Rt as ve,Sr as ye,T as be,Tt as xe,V as Se,Vn as Ce,Vr as we,Wa as Te,Wi as Ee,Xi as De,Xn as Oe,Yi as ke,Yn as Ae,Z as je,Zr as Me,Zt as Ne,_a as Pe,_i as Fe,_r as Ie,_t as Le,aa as Re,ba as ze,ca as Be,ci as Ve,ct as He,dn as Ue,eo as We,er as Ge,fa as Ke,ft as qe,gt as Je,ir as Ye,it as Xe,ji as Ze,jn as Qe,jt as $e,ki as et,kr as tt,kt as nt,ma as rt,ni as it,oa as at,oi as ot,pa as st,q as ct,qr as lt,ri as ut,ro as dt,rr as ft,rt as pt,sa as mt,si as ht,tn as gt,to as _t,vi as vt,wi as yt,wt as bt,xa as xt,xr as St,ya as Ct,yi as wt,yn as Tt,yt as V,zr as H}from"./player-overlays-D1NExXj2.js";import{$c as Et,At as Dt,B as Ot,Bc as kt,Ct as At,Dt as jt,Et as Mt,Ft as Nt,G as Pt,Gt as Ft,H as It,Ht as Lt,J as Rt,Jt as zt,K as Bt,Ks as Vt,Kt as Ht,L as Ut,Lt as Wt,Nt as Gt,Ot as Kt,P as qt,Pt as Jt,Qc as Yt,Qs as U,R as Xt,Rs as Zt,Rt as Qt,St as $t,Tt as en,U as tn,Un as nn,V as rn,Vt as an,W as on,Wo as sn,Wr as cn,Wt as ln,Xt as un,Y as dn,Yt as fn,Zc as pn,Zt as mn,a as hn,ac as gn,an as _n,c as vn,ci as yn,cn as bn,d as xn,dl as Sn,ea as Cn,en as wn,es as Tn,f as En,ft as Dn,ga as On,il as kn,in as An,it as jn,kt as Mn,ln as Nn,n as Pn,nn as Fn,o as In,oi as Ln,on as Rn,q as zn,qt as Bn,r as Vn,ra as Hn,rn as Un,rt as Wn,s as Gn,si as Kn,sn as qn,t as Jn,tn as Yn,wt as Xn,z as Zn,zs as Qn,zt as $n}from"./client-BN2LRjot.js";import{_ as er,a as tr,c as nr,d as rr,f as ir,g as ar,h as or,i as sr,l as cr,m as lr,n as ur,o as dr,p as fr,r as pr,s as mr,t as hr,u as gr}from"./terminal-DZ5OZpgC.js";import{$r as _r,$t as vr,Aa as yr,Ac as br,Ad as xr,Af as Sr,Ao as Cr,Ba as wr,Bl as Tr,Bs as Er,Cc as Dr,Da as Or,Do as kr,Dp as Ar,Ec as jr,Ep as W,Fa as Mr,Fi as Nr,Fn as Pr,Fp as Fr,Gi as Ir,Gs as Lr,Hf as Rr,Hp as zr,Hs as Br,Ht as Vr,Id as Hr,If as Ur,Ii as Wr,Ip as Gr,Ir as Kr,It as qr,Jd as Jr,Ji as Yr,Jn as Xr,Js as Zr,Jt as Qr,Ki as $r,La as ei,Lp as ti,Ls as ni,Lt as ri,M as ii,Mi as ai,Mp as oi,Nc as si,Ni as ci,Nn as li,Np as ui,Oc as di,Od as fi,Oi as pi,Oo as mi,Or as hi,P as gi,Pi as _i,Pn as vi,Pp as yi,Ps as bi,Pt as xi,Qc as Si,Qd as Ci,Qf as wi,Qt as Ti,Ri as Ei,Rs as Di,Rt as Oi,Sc as ki,Sr as Ai,Ts as ji,Ui as Mi,Ut as Ni,Va as Pi,Vc as Fi,Vi as Ii,Vs as Li,Vt as Ri,Wi as zi,Wp as Bi,Ws as Vi,Wt as Hi,Xp as Ui,Xt as Wi,Y as Gi,Yd as Ki,Yi as qi,Za as Ji,Zd as Yi,Zp as Xi,Zs as Zi,Zt as Qi,_a as $i,_c as ea,_r as ta,af as na,ai as ra,at as ia,bp as aa,br as oa,ci as sa,cl as ca,do as la,dr as ua,ds as da,ec as fa,el as pa,en as ma,f as ha,fa as ga,fo as _a,ga as va,gc as ya,gr as ba,ha as xa,hc as Sa,ho as Ca,hp as wa,hr as Ta,i as Ea,ii as Da,il as Oa,jl as ka,jo as Aa,jt as ja,ka as Ma,kc as Na,kf as Pa,ko as Fa,kr as Ia,la as La,lc as Ra,ll as za,ls as Ba,m as Va,ma as Ha,mp as Ua,n as Wa,nl as Ga,nm as Ka,nn as qa,on as Ja,pa as Ya,pi as Xa,qa as Za,qi as Qa,qs as $a,qt as eo,r as to,ro as no,rt as ro,si as io,so as ao,tc as oo,tm as so,ut as co,va as lo,vp as G,vr as uo,wl as fo,wr as po,xa as mo,xc as ho,xp as go,xt as _o,ya as vo,yr as yo,za as bo,zi as xo,zs as So,zt as Co}from"./src-6lZ5_wSy.js";import{r as wo,t as To}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.js-BPba2g2p.js";import{t as Eo}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-ZBKFTPET.js";import{n as Do,t as K}from"./i18n-D0ym_MsQ.js";import{a as Oo,c as ko,i as Ao,l as jo,n as Mo,o as No,s as Po,t as q,u as Fo}from"./useTranslation-BJr-n0es.js";import"./mount-CZRDLeqa.js";import{a as Io,c as Lo,d as Ro,i as zo,n as Bo,o as Vo,r as Ho,s as Uo,t as Wo,u as Go}from"./sso-popup-C96ZvJqF.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})(),O(),wo();var Ko=`camstack.debugLayers`,qo=/(transform|opacity|filter|perspective)/;function Jo(e){return e!==``&&e!==`none`}function Yo(e,t,n=120){if(t.width<=0||t.height<=0||t.top>=n||t.bottom<=0)return null;let r=[];e.position===`fixed`&&r.push(`fixed`),e.position===`sticky`&&r.push(`sticky`),(Jo(e.backdropFilter)||Jo(e.webkitBackdropFilter))&&r.push(`backdrop-filter`),Jo(e.filter)&&r.push(`filter`);let i=Number.parseFloat(e.opacity);return Number.isFinite(i)&&i<1&&r.push(`opacity`),Jo(e.transform)&&r.push(`transform`),Jo(e.perspective)&&r.push(`perspective`),e.isolation===`isolate`&&r.push(`isolation`),e.mixBlendMode!==``&&e.mixBlendMode!==`normal`&&r.push(`mix-blend-mode`),qo.test(e.willChange)&&r.push(`will-change`),r.length===0?null:{reasons:r,zIndex:e.zIndex}}function Xo(e,t,n,r){let i=n!==null&&n!==``?`[${n}]`:t.split(/\s+/).filter(e=>e!==``).slice(0,3).map(e=>`.${e}`).join(``);return`${e.toLowerCase()}${i} z=${r.zIndex} ${r.reasons.join(`+`)}`}function Zo(e,t){let n=new URLSearchParams(e).get(`debugLayers`);return n===`1`?{on:!0,persist:`1`}:n===`0`?{on:!1,persist:null}:{on:t===`1`,persist:`keep`}}var Qo=`camstack.debugLayers.noBlur`,$o=`camstack.debugLayers.outlines`,es=`camstack.debugLayers.topLayer`,ts=`debug-no-backdrop-blur`;function ns(e,t){try{return e===null?null:e.getItem(t)}catch{return null}}function rs(e,t,n){try{if(e===null)return;n===null?e.removeItem(t):e.setItem(t,n)}catch{}}function is(e,t){let n=Zo(t,ns(e,Ko));n.persist!==`keep`&&rs(e,Ko,n.persist);let r={on:n.on,noBlur:ns(e,Qo)===`1`,outlines:ns(e,$o)!==`0`,topLayer:ns(e,es)!==`0`},i=new Set,a=e=>{r=e;for(let e of i)e()};return{getState:()=>r,subscribe:e=>(i.add(e),()=>{i.delete(e)}),setOn:t=>{if(rs(e,Ko,t?`1`:null),!t){rs(e,Qo,null),rs(e,$o,null),rs(e,es,null),a({on:t,noBlur:!1,outlines:!0,topLayer:!0});return}a({...r,on:t})},setNoBlur:t=>{rs(e,Qo,t?`1`:null),a({...r,noBlur:t})},setOutlines:t=>{rs(e,$o,t?null:`0`),a({...r,outlines:t})},setTopLayer:t=>{rs(e,es,t?null:`0`),a({...r,topLayer:t})}}}var as=[`transform`,`will-change`,`position`,`backdrop-filter`,`filter`,`opacity`];function os(e){return as.map(t=>`${t}: ${e===null?`n/a`:e(t)||`-`}`)}var ss=null;function cs(){try{return window.sessionStorage}catch{return null}}function ls(){return ss===null&&(ss=is(cs(),window.location.search)),ss}function us(){let e=ls();return{...C(e.subscribe,e.getState),setOn:e.setOn,setNoBlur:e.setNoBlur,setOutlines:e.setOutlines,setTopLayer:e.setTopLayer}}O();var ds=`data-debug-layers`,fs=250,ps=60;function ms(){let e=[],t=document.body.querySelectorAll(`*`);for(let n of Array.from(t)){if(e.length>=ps)break;if(n.closest(`[${ds}]`)!==null)continue;let t=n.getBoundingClientRect();if(t.width<=0||t.height<=0||t.top>=120||t.bottom<=0)continue;let r=getComputedStyle(n),i=Yo({position:r.position,zIndex:r.zIndex,opacity:r.opacity,filter:r.filter,backdropFilter:r.backdropFilter,webkitBackdropFilter:r.getPropertyValue(`-webkit-backdrop-filter`),transform:r.transform,perspective:r.perspective,isolation:r.isolation,mixBlendMode:r.mixBlendMode,willChange:r.willChange},t);if(i===null)continue;let a=n.getAttribute(`data-testid`);e.push({id:e.length,top:t.top,left:t.left,width:t.width,height:t.height,label:Xo(n.tagName,typeof n.className==`string`?n.className:``,a===null?null:`data-testid=${a}`,i),reasons:i.reasons})}return e}function hs(e){let t=getComputedStyle(e),n=e=>Number.parseFloat(e)||0;return{top:n(t.paddingTop),right:n(t.paddingRight),bottom:n(t.paddingBottom),left:n(t.paddingLeft)}}function gs(e){return e.includes(`backdrop-filter`)||e.includes(`filter`)?{outline:`outline-danger`,chip:`bg-danger`}:e.includes(`opacity`)||e.includes(`mix-blend-mode`)?{outline:`outline-warning`,chip:`bg-warning`}:e.includes(`fixed`)||e.includes(`sticky`)?{outline:`outline-info`,chip:`bg-info`}:{outline:`outline-primary`,chip:`bg-primary`}}function _s(){let e=Reflect.get(navigator,`standalone`);return window.matchMedia(`(display-mode: standalone)`).matches||e===!0}function vs(){return`1.2.708`}function ys(e,t){if(!(e===null||typeof e.showPopover!=`function`))try{e.matches(`:popover-open`)&&e.hidePopover(),t&&e.showPopover()}catch{}}function bs(){let e=document.querySelector(`[data-debug-header]`),t=e===null?null:e.querySelector(`img`),n=e=>os(e===null?null:t=>getComputedStyle(e).getPropertyValue(t));return{header:n(e),logo:n(t)}}function xs({noBlur:e,onNoBlurChange:t,outlines:n,onOutlinesChange:r,topLayer:i,onTopLayerChange:a}){let[o,c]=w([]),[l,u]=w({top:0,right:0,bottom:0,left:0}),d=p(null),f=p(null),m=p(null),[h,g]=w(bs),_=b(()=>{ys(f.current,i),c(n?ms():[]),g(bs()),d.current!==null&&u(hs(d.current))},[n,i]),v=b(()=>{m.current===null&&(m.current=window.setTimeout(()=>{m.current=null,_()},fs))},[_]);return S(()=>{_();let e=new MutationObserver(e=>{e.some(e=>!(e.target instanceof Element&&e.target.closest(`[${ds}]`)!==null))&&v()});return e.observe(document.body,{childList:!0,subtree:!0,attributes:!0}),window.addEventListener(`resize`,v),window.addEventListener(`orientationchange`,v),window.addEventListener(`scroll`,v,!0),()=>{e.disconnect(),window.removeEventListener(`resize`,v),window.removeEventListener(`orientationchange`,v),window.removeEventListener(`scroll`,v,!0),m.current!==null&&window.clearTimeout(m.current)}},[_,v]),To(s(`div`,{[ds]:``,ref:f,popover:`manual`,className:`pointer-events-none fixed inset-0 z-[2147483647] m-0 h-full w-full overflow-visible border-0 bg-transparent p-0`,children:[x(`div`,{ref:d,"aria-hidden":!0,className:`invisible absolute h-0 w-0`,style:{paddingTop:`env(safe-area-inset-top)`,paddingRight:`env(safe-area-inset-right)`,paddingBottom:`env(safe-area-inset-bottom)`,paddingLeft:`env(safe-area-inset-left)`}}),o.map(e=>{let t=gs(e.reasons);return x(`div`,{"data-testid":`debug-layer-box`,className:_t(`absolute outline outline-1 -outline-offset-1`,t.outline),style:{top:e.top,left:e.left,width:e.width,height:e.height},children:x(`span`,{className:_t(`absolute left-0 max-w-[90vw] truncate px-1 font-mono text-[9px] leading-3 text-primary-foreground`,t.chip),style:{top:e.id%6*12},children:e.label})},e.id)}),s(`div`,{"data-testid":`debug-layers-badge`,className:`absolute right-1 top-14 rounded-md bg-background-elevated px-2 py-1 font-mono text-[10px] leading-4 text-foreground outline outline-1 outline-border`,children:[s(`div`,{children:[`admin-ui `,vs()]}),s(`div`,{children:[`inset t`,l.top,` r`,l.right,` b`,l.bottom,` l`,l.left]}),s(`div`,{children:[`display-mode standalone:`,` `,window.matchMedia(`(display-mode: standalone)`).matches?`yes`:`no`,` · `,`navigator.standalone: `,_s()?`yes`:`no`]}),s(`div`,{children:[window.innerWidth,`x`,window.innerHeight,` · `,o.length,` layers`]}),x(Xa,{checked:e,onCheckedChange:t,label:`no backdrop blur`,className:`pointer-events-auto mt-1 text-[10px]`}),x(Xa,{checked:n,onCheckedChange:r,label:`outlines`,className:`pointer-events-auto mt-1 text-[10px]`}),x(Xa,{checked:i,onCheckedChange:a,label:`top layer`,className:`pointer-events-auto mt-1 text-[10px]`}),s(`div`,{"data-testid":`debug-header-styles`,className:`mt-1`,children:[x(`div`,{children:`header`}),h.header.map(e=>x(`div`,{children:e},e)),x(`div`,{children:`header logo`}),h.logo.map(e=>x(`div`,{children:e},e))]})]})]}),document.body)}function Ss(){let{on:e,noBlur:t,setNoBlur:n,outlines:r,setOutlines:i,topLayer:a,setTopLayer:o}=us();return S(()=>{let n=e&&t;return document.documentElement.classList.toggle(ts,n),()=>document.documentElement.classList.remove(ts)},[e,t]),e?x(xs,{noBlur:t,onNoBlurChange:n,outlines:r,onOutlinesChange:i,topLayer:a,onTopLayerChange:o}):null}var Cs=`camera`;function ws(e){return e===null||!/^\d+$/.test(e)?null:Number(e)}function Ts(e,t){return t===null?e:e.filter(e=>e.deviceId===t)}function Es(e,t){let n=new Set(e.map(e=>e.deviceId));return t!==null&&n.add(t),[...n].sort((e,t)=>e-t)}var Ds=`/archive`,Os=`/addon/training`,ks=`/library?tab=exports`,As=`section`,js=`camera`,Ms=`view`;function Ns(e,t){let n=`${Ds}?${As}=cameras&${js}=${String(e)}`;return t===void 0?n:`${n}&${Ms}=${t}`}function Ps(e){return e===void 0?ks:`${ks}&${Cs}=${String(e)}`}var Fs={settings:`settings`,space:`health`,health:`health`,events:`review`,review:`review`},Is={storage:Ds,events:Ds,cameras:Ds,exports:ks,activity:`${Ds}#activity`,management:`${Ds}#tools`},Ls=/^\/archive\/(\d+)\/?$/;function Rs(e,t){let n=new URLSearchParams(t);if(e===`/recordings`){let e=n.get(`tab`);return e===null?Ds:Is[e]??`/archive`}if(e===`/library`&&n.get(`tab`)===`events`)return n.get(`section`)===`retrain`?Os:Ds;let r=Ls.exec(e);if(r?.[1]!==void 0){let e=Number(r[1]),t=n.get(As);return t===`exports`?Ps(e):Ns(e,t===null?void 0:Fs[t])}return null}O();var zs=/^(?:[a-z][a-z0-9+.-]*:|[\\/]{2})/i,Bs=/^[\\/]{2}/;function Vs(e,t){return t+e.replace(/\\/g,`/`)}var Hs=`popstate`;function Us(e){return typeof e==`object`&&!!e&&`pathname`in e&&`search`in e&&`hash`in e&&`state`in e&&`key`in e}function Ws(e={}){function t(e,t){let n=t.state?.masked,{pathname:r,search:i,hash:a}=n||e.location;return Js(``,{pathname:r,search:i,hash:a},t.state&&t.state.usr||null,t.state&&t.state.key||`default`,n?{pathname:e.location.pathname,search:e.location.search,hash:e.location.hash}:void 0)}function n(e,t){return typeof t==`string`?t:Ys(t)}return Zs(t,n,null,e)}function J(e,t){if(e===!1||e==null)throw Error(t)}function Gs(e,t){if(!e){typeof console<`u`&&console.warn(t);try{throw Error(t)}catch{}}}function Ks(){return Math.random().toString(36).substring(2,10)}function qs(e,t){return{usr:e.state,key:e.key,idx:t,masked:e.mask?{pathname:e.pathname,search:e.search,hash:e.hash}:void 0}}function Js(e,t,n=null,r,i){return{pathname:typeof e==`string`?e:e.pathname,search:``,hash:``,...typeof t==`string`?Xs(t):t,state:n,key:t&&t.key||r||Ks(),mask:i}}function Ys({pathname:e=`/`,search:t=``,hash:n=``}){return t&&t!==`?`&&(e+=t.charAt(0)===`?`?t:`?`+t),n&&n!==`#`&&(e+=n.charAt(0)===`#`?n:`#`+n),e}function Xs(e){let t={};if(e){let n=e.indexOf(`#`);n>=0&&(t.hash=e.substring(n),e=e.substring(0,n));let r=e.indexOf(`?`);r>=0&&(t.search=e.substring(r),e=e.substring(0,r)),e&&(t.pathname=e)}return t}function Zs(e,t,n,r={}){let{window:i=document.defaultView,v5Compat:a=!1}=r,o=i.history,s=`POP`,c=null,l=u();l??(l=0,o.replaceState({...o.state,idx:l},``));function u(){return(o.state||{idx:null}).idx}function d(){s=`POP`;let e=u(),t=e==null?null:e-l;l=e,c&&c({action:s,location:h.location,delta:t})}function f(e,t){s=`PUSH`;let r=Us(e)?e:Js(h.location,e,t);n&&n(r,e),l=u()+1;let d=qs(r,l),f=h.createHref(r.mask||r);try{o.pushState(d,``,f)}catch(e){if(e instanceof DOMException&&e.name===`DataCloneError`)throw e;i.location.assign(f)}a&&c&&c({action:s,location:h.location,delta:1})}function p(e,t){s=`REPLACE`;let r=Us(e)?e:Js(h.location,e,t);n&&n(r,e),l=u();let i=qs(r,l),d=h.createHref(r.mask||r);o.replaceState(i,``,d),a&&c&&c({action:s,location:h.location,delta:0})}function m(e){return Qs(i,e)}let h={get action(){return s},get location(){return e(i,o)},listen(e){if(c)throw Error(`A history only accepts one active listener`);return i.addEventListener(Hs,d),c=e,()=>{i.removeEventListener(Hs,d),c=null}},createHref(e){return t(i,e)},createURL:m,encodeLocation(e){let t=m(e);return{pathname:t.pathname,search:t.search,hash:t.hash}},push:f,replace:p,go(e){return o.go(e)}};return h}function Qs(e,t,n=!1){let r=`http://localhost`;e&&(r=e.location.origin===`null`?e.location.href:e.location.origin),J(r,`No window.location.(origin|href) available to create URL`);let i=typeof t==`string`?t:Ys(t);return i=i.replace(/ $/,`%20`),!n&&Bs.test(i)&&(i=r+i),new URL(i,r)}function $s(e,t,n=`/`){return ec(e,t,n,!1)}function ec(e,t,n,r,i){let a=bc((typeof t==`string`?Xs(t):t).pathname||`/`,n);if(a==null)return null;let o=i??nc(e),s=null,c=yc(a);for(let e=0;s==null&&e<o.length;++e)s=hc(o[e],c,r);return s}function tc(e,t){let{route:n,pathname:r,params:i}=e;return{id:n.id,pathname:r,params:i,data:t[n.id],loaderData:t[n.id],handle:n.handle}}function nc(e){let t=rc(e);return ac(t),t}function rc(e,t=[],n=[],r=``,i=!1){let a=(e,a,o=i,s)=>{let c={relativePath:s===void 0?e.path||``:s,caseSensitive:e.caseSensitive===!0,childrenIndex:a,route:e};if(c.relativePath.startsWith(`/`)){if(!c.relativePath.startsWith(r)&&o)return;J(c.relativePath.startsWith(r),`Absolute route path "${c.relativePath}" nested under path "${r}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`),c.relativePath=c.relativePath.slice(r.length)}let l=Oc([r,c.relativePath]),u=n.concat(c);e.children&&e.children.length>0&&(J(e.index!==!0,`Index routes must not have child routes. Please remove all child routes from route path "${l}".`),rc(e.children,t,u,l,o)),!(e.path==null&&!e.index)&&t.push({path:l,score:pc(l,e.index),routesMeta:u.map((e,t)=>{let[n,r]=vc(e.relativePath,e.caseSensitive,t===u.length-1);return{...e,matcher:n,compiledParams:r}})})};return e.forEach((e,t)=>{if(e.path===``||!e.path?.includes(`?`))a(e,t);else for(let n of ic(e.path))a(e,t,!0,n)}),t}function ic(e){let t=e.split(`/`);if(t.length===0)return[];let[n,...r]=t,i=n.endsWith(`?`),a=n.replace(/\?$/,``);if(r.length===0)return i?[a,``]:[a];let o=ic(r.join(`/`)),s=[];return s.push(...o.map(e=>e===``?a:[a,e].join(`/`))),i&&s.push(...o),s.map(t=>e.startsWith(`/`)&&t===``?`/`:t)}function ac(e){e.sort((e,t)=>e.score===t.score?mc(e.routesMeta.map(e=>e.childrenIndex),t.routesMeta.map(e=>e.childrenIndex)):t.score-e.score)}var oc=/^:[\w-]+$/,sc=3,cc=2,lc=1,uc=10,dc=-2,fc=e=>e===`*`;function pc(e,t){let n=e.split(`/`),r=n.length;return n.some(fc)&&(r+=dc),t&&(r+=cc),n.filter(e=>!fc(e)).reduce((e,t)=>e+(oc.test(t)?sc:t===``?lc:uc),r)}function mc(e,t){return e.length===t.length&&e.slice(0,-1).every((e,n)=>e===t[n])?e[e.length-1]-t[t.length-1]:0}function hc(e,t,n=!1){let{routesMeta:r}=e,i={},a=`/`,o=[];for(let e=0;e<r.length;++e){let s=r[e],c=e===r.length-1,l=a===`/`?t:t.slice(a.length)||`/`,u={path:s.relativePath,caseSensitive:s.caseSensitive,end:c},d=s.matcher&&s.compiledParams?_c(u,l,s.matcher,s.compiledParams):gc(u,l),f=s.route;if(!d&&c&&n&&!r[r.length-1].route.index&&(d=gc({path:s.relativePath,caseSensitive:s.caseSensitive,end:!1},l)),!d)return null;Object.assign(i,d.params),o.push({params:i,pathname:Oc([a,d.pathname]),pathnameBase:Ac(Oc([a,d.pathnameBase])),route:f}),d.pathnameBase!==`/`&&(a=Oc([a,d.pathnameBase]))}return o}function gc(e,t){typeof e==`string`&&(e={path:e,caseSensitive:!1,end:!0});let[n,r]=vc(e.path,e.caseSensitive,e.end);return _c(e,t,n,r)}function _c(e,t,n,r){let i=t.match(n);if(!i)return null;let a=i[0],o=a.replace(/(.)\/+$/,`$1`),s=i.slice(1);return{params:r.reduce((e,{paramName:t,isOptional:n},r)=>{if(t===`*`){let e=s[r]||``;o=a.slice(0,a.length-e.length).replace(/(.)\/+$/,`$1`)}let i=s[r];return n&&!i?e[t]=void 0:e[t]=(i||``).replace(/%2F/g,`/`),e},{}),pathname:a,pathnameBase:o,pattern:e}}function vc(e,t=!1,n=!0){Gs(e===`*`||!e.endsWith(`*`)||e.endsWith(`/*`),`Route path "${e}" will be treated as if it were "${e.replace(/\*$/,`/*`)}" because the \`*\` character must always follow a \`/\` in the pattern. To get rid of this warning, please change the route path to "${e.replace(/\*$/,`/*`)}".`);let r=[],i=`^`+e.replace(/\/*\*?$/,``).replace(/^\/*/,`/`).replace(/[\\.*+^${}|()[\]]/g,`\\$&`).replace(/\/:([\w-]+)(\?)?/g,(e,t,n,i,a)=>{if(r.push({paramName:t,isOptional:n!=null}),n){let t=a.charAt(i+e.length);return t&&t!==`/`?`/([^\\/]*)`:`(?:/([^\\/]*))?`}return`/([^\\/]+)`}).replace(/\/([\w-]+)\?(\/|$)/g,`(/$1)?$2`);return e.endsWith(`*`)?(r.push({paramName:`*`}),i+=e===`*`||e===`/*`?`(.*)$`:`(?:\\/(.+)|\\/*)$`):n?i+=`\\/*$`:e!==``&&e!==`/`&&(i+=`(?:(?=\\/|$))`),[new RegExp(i,t?void 0:`i`),r]}function yc(e){try{return e.split(`/`).map(e=>decodeURIComponent(e).replace(/\//g,`%2F`)).join(`/`)}catch(t){return Gs(!1,`The URL path "${e}" could not be decoded because it is a malformed URL segment. This is probably due to a bad percent encoding (${t}).`),e}}function bc(e,t){if(t===`/`)return e;if(!e.toLowerCase().startsWith(t.toLowerCase()))return null;let n=t.endsWith(`/`)?t.length-1:t.length,r=e.charAt(n);return r&&r!==`/`?null:e.slice(n)||`/`}function xc(e,t=`/`){let{pathname:n,search:r=``,hash:i=``}=typeof e==`string`?Xs(e):e,a;return n?(n=Dc(n),a=n.startsWith(`/`)?Sc(n.substring(1),`/`):Sc(n,t)):a=t,{pathname:a,search:jc(r),hash:Mc(i)}}function Sc(e,t){let n=kc(t).split(`/`);return e.split(`/`).forEach(e=>{e===`..`?n.length>1&&n.pop():e!==`.`&&n.push(e)}),n.length>1?n.join(`/`):`/`}function Cc(e,t,n,r){return`Cannot include a '${e}' character in a manually specified \`to.${t}\` field [${JSON.stringify(r)}]. Please separate it out to the \`to.${n}\` field. Alternatively you may provide the full path as a string in <Link to="..."> and the router will parse it for you.`}function wc(e){return e.filter((e,t)=>t===0||e.route.path&&e.route.path.length>0)}function Tc(e){let t=wc(e);return t.map((e,n)=>n===t.length-1?e.pathname:e.pathnameBase)}function Ec(e,t,n,r=!1){let i;typeof e==`string`?i=Xs(e):(i={...e},J(!i.pathname||!i.pathname.includes(`?`),Cc(`?`,`pathname`,`search`,i)),J(!i.pathname||!i.pathname.includes(`#`),Cc(`#`,`pathname`,`hash`,i)),J(!i.search||!i.search.includes(`#`),Cc(`#`,`search`,`hash`,i)));let a=e===``||i.pathname===``,o=a?`/`:i.pathname,s;if(o==null)s=n;else{let e=t.length-1;if(!r&&o.startsWith(`..`)){let t=o.split(`/`);for(;t[0]===`..`;)t.shift(),--e;i.pathname=t.join(`/`)}s=e>=0?t[e]:`/`}let c=xc(i,s),l=o&&o!==`/`&&o.endsWith(`/`),u=(a||o===`.`)&&n.endsWith(`/`);return!c.pathname.endsWith(`/`)&&(l||u)&&(c.pathname+=`/`),c}var Dc=e=>e.replace(/[\\/]{2,}/g,`/`),Oc=e=>Dc(e.join(`/`)),kc=e=>e.replace(/\/+$/,``),Ac=e=>kc(e).replace(/^\/*/,`/`),jc=e=>!e||e===`?`?``:e.startsWith(`?`)?e:`?`+e,Mc=e=>!e||e===`#`?``:e.startsWith(`#`)?e:`#`+e,Nc=class{constructor(e,t,n,r=!1){this.status=e,this.statusText=t||``,this.internal=r,n instanceof Error?(this.data=n.toString(),this.error=n):this.data=n}};function Pc(e){return e!=null&&typeof e.status==`number`&&typeof e.statusText==`string`&&typeof e.internal==`boolean`&&`data`in e}function Fc(e){return Oc(e.map(e=>e.route.path).filter(Boolean))||`/`}var Ic=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;function Lc(e,t){let n=e;if(typeof n!=`string`||!zs.test(n))return{absoluteURL:void 0,isExternal:!1,to:n};let r=n,i=!1;if(Ic)try{let e=new URL(window.location.href),r=Bs.test(n)?new URL(Vs(n,e.protocol)):new URL(n),a=bc(r.pathname,t);r.origin===e.origin&&a!=null?n=a+r.search+r.hash:i=!0}catch{Gs(!1,`<Link to="${n}"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.`)}return{absoluteURL:r,isExternal:i,to:n}}Object.getOwnPropertyNames(Object.prototype).sort().join(`\0`);var Rc=[`POST`,`PUT`,`PATCH`,`DELETE`];new Set(Rc);var zc=[`GET`,...Rc];new Set(zc);var Bc=[`about:`,`blob:`,`chrome:`,`chrome-untrusted:`,`content:`,`data:`,`devtools:`,`file:`,`filesystem:`,`javascript:`];function Vc(e){try{return Bc.includes(new URL(e).protocol)}catch{return!1}}var Hc=j(null);Hc.displayName=`DataRouter`;var Uc=j(null);Uc.displayName=`DataRouterState`;var Wc=j(!1);function Gc(){return I(Wc)}var Kc=j({isTransitioning:!1});Kc.displayName=`ViewTransition`;var qc=j(new Map);qc.displayName=`Fetchers`;var Jc=j(null);Jc.displayName=`Await`;var Yc=j(null);Yc.displayName=`Navigation`;var Xc=j(null);Xc.displayName=`Location`;var Zc=j({outlet:null,matches:[],isDataRoute:!1});Zc.displayName=`Route`;var Qc=j(null);Qc.displayName=`RouteError`;var $c=`REACT_ROUTER_ERROR`,el=`REDIRECT`,tl=`ROUTE_ERROR_RESPONSE`;function nl(e){if(e.startsWith(`${$c}:${el}:{`))try{let t=JSON.parse(e.slice(28));if(typeof t==`object`&&t&&typeof t.status==`number`&&typeof t.statusText==`string`&&typeof t.location==`string`&&typeof t.reloadDocument==`boolean`&&typeof t.replace==`boolean`)return t}catch{}}function rl(e){if(e.startsWith(`${$c}:${tl}:{`))try{let t=JSON.parse(e.slice(40));if(typeof t==`object`&&t&&typeof t.status==`number`&&typeof t.statusText==`string`)return new Nc(t.status,t.statusText,t.data)}catch{}}function il(e,{relative:t}={}){J(al(),`useHref() may be used only in the context of a <Router> component.`);let{basename:n,navigator:r}=I(Yc),{hash:i,pathname:a,search:o}=ml(e,{relative:t}),s=a;return n!==`/`&&(s=a===`/`?n:Oc([n,a])),r.createHref({pathname:s,search:o,hash:i})}function al(){return I(Xc)!=null}function Y(){return J(al(),`useLocation() may be used only in the context of a <Router> component.`),I(Xc).location}function ol(){return I(Xc).navigationType}var sl=`You should call navigate() in a React.useEffect(), not when your component is first rendered.`;function cl(e){I(Yc).static||u(e)}function ll(){let{isDataRoute:e}=I(Zc);return e?Nl():ul()}function ul(){J(al(),`useNavigate() may be used only in the context of a <Router> component.`);let e=I(Hc),{basename:t,navigator:n}=I(Yc),{matches:r}=I(Zc),{pathname:i}=Y(),a=JSON.stringify(Tc(r)),o=p(!1);return cl(()=>{o.current=!0}),b((r,s={})=>{if(Gs(o.current,sl),!o.current)return;if(typeof r==`number`){n.go(r);return}let c=Ec(r,JSON.parse(a),i,s.relative===`path`);e==null&&t!==`/`&&(c.pathname=c.pathname===`/`?t:Oc([t,c.pathname])),(s.replace?n.replace:n.push)(c,s.state,s)},[t,n,a,i,e])}var dl=j(null);function fl(e){let t=I(Zc).outlet;return m(()=>t&&o(dl.Provider,{value:e},t),[t,e])}function pl(){let{matches:e}=I(Zc);return e[e.length-1]?.params??{}}function ml(e,{relative:t}={}){let{matches:n}=I(Zc),{pathname:r}=Y(),i=JSON.stringify(Tc(n));return m(()=>Ec(e,JSON.parse(i),r,t===`path`),[e,i,r,t])}function hl(e,t){return gl(e,t)}function gl(e,t,n){J(al(),`useRoutes() may be used only in the context of a <Router> component.`);let{navigator:r}=I(Yc),{matches:i}=I(Zc),a=i[i.length-1],s=a?a.params:{},c=a?a.pathname:`/`,l=a?a.pathnameBase:`/`,u=a&&a.route;{let e=u&&u.path||``;Fl(c,!u||e.endsWith(`*`)||e.endsWith(`*?`),`You rendered descendant <Routes> (or called \`useRoutes()\`) at "${c}" (under <Route path="${e}">) but the parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render.
|
|
3
3
|
|
|
4
|
-
Please change the parent <Route path="${e}"> to <Route path="${e===`/`?`*`:`${e}/*`}">.`)}let d=Y(),f;if(t){let e=typeof t==`string`?Xs(t):t;J(l===`/`||e.pathname?.startsWith(l),`When overriding the location using \`<Routes location>\` or \`useRoutes(routes, location)\`, the location pathname must begin with the portion of the URL pathname that was matched by all parent routes. The current pathname base is "${l}" but pathname "${e.pathname}" was given in the \`location\` prop.`),f=e}else f=d;let p=f.pathname||`/`,m=p;if(l!==`/`){let e=l.replace(/^\//,``).split(`/`);m=`/`+p.replace(/^\//,``).split(`/`).slice(e.length).join(`/`)}let h=n&&n.state.matches.length?n.state.matches.map(e=>Object.assign(e,{route:n.manifest[e.route.id]||e.route})):$s(e,{pathname:m});Gs(u||h!=null,`No routes matched location "${f.pathname}${f.search}${f.hash}" `),Gs(h==null||h[h.length-1].route.element!==void 0||h[h.length-1].route.Component!==void 0||h[h.length-1].route.lazy!==void 0,`Matched leaf route at location "${f.pathname}${f.search}${f.hash}" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.`);let g=Cl(h&&h.map(e=>Object.assign({},e,{params:Object.assign({},s,e.params),pathname:Oc([l,r.encodeLocation?r.encodeLocation(e.pathname.replace(/%/g,`%25`).replace(/\?/g,`%3F`).replace(/#/g,`%23`)).pathname:e.pathname]),pathnameBase:e.pathnameBase===`/`?l:Oc([l,r.encodeLocation?r.encodeLocation(e.pathnameBase.replace(/%/g,`%25`).replace(/\?/g,`%3F`).replace(/#/g,`%23`)).pathname:e.pathnameBase])})),i,n);return t&&g?o(Xc.Provider,{value:{location:{pathname:`/`,search:``,hash:``,state:null,key:`default`,mask:void 0,...f},navigationType:`POP`}},g):g}function _l(){let e=Ml(),t=Pc(e)?`${e.status} ${e.statusText}`:e instanceof Error?e.message:JSON.stringify(e),n=e instanceof Error?e.stack:null,r=`rgba(200,200,200, 0.5)`,i={padding:`0.5rem`,backgroundColor:r},a={padding:`2px 4px`,backgroundColor:r},s=null;return console.error(`Error handled by React Router default ErrorBoundary:`,e),s=o(d,null,o(`p`,null,`💿 Hey developer 👋`),o(`p`,null,`You can provide a way better UX than this when your app throws errors by providing your own `,o(`code`,{style:a},`ErrorBoundary`),` or`,` `,o(`code`,{style:a},`errorElement`),` prop on your route.`)),o(d,null,o(`h2`,null,`Unexpected Application Error!`),o(`h3`,{style:{fontStyle:`italic`}},t),n?o(`pre`,{style:i},n):null,s)}var vl=o(_l,null),yl=class extends l{constructor(e){super(e),this.state={location:e.location,revalidation:e.revalidation,error:e.error}}static getDerivedStateFromError(e){return{error:e}}static getDerivedStateFromProps(e,t){return t.location!==e.location||t.revalidation!==`idle`&&e.revalidation===`idle`?{error:e.error,location:e.location,revalidation:e.revalidation}:{error:e.error===void 0?t.error:e.error,location:t.location,revalidation:e.revalidation||t.revalidation}}componentDidCatch(e,t){this.props.onError?this.props.onError(e,t):console.error(`React Router caught the following error during render`,e)}render(){let e=this.state.error;if(this.context&&typeof e==`object`&&e&&`digest`in e&&typeof e.digest==`string`){let t=rl(e.digest);t&&(e=t)}let t=e===void 0?this.props.children:o(Zc.Provider,{value:this.props.routeContext},o(Qc.Provider,{value:e,children:this.props.component}));return this.context?o(xl,{error:e},t):t}};yl.contextType=Wc;var bl=new WeakMap;function xl({children:e,error:t}){let{basename:n}=I(Yc);if(typeof t==`object`&&t&&`digest`in t&&typeof t.digest==`string`){let e=nl(t.digest);if(e){let r=bl.get(t);if(r)throw r;let i=Lc(e.location,n),a=i.absoluteURL||i.to;if(Vc(a))throw Error(`Invalid redirect location`);if(Ic&&!bl.get(t))if(i.isExternal||e.reloadDocument)window.location.href=a;else{let n=Promise.resolve().then(()=>window.__reactRouterDataRouter.navigate(i.to,{replace:e.replace}));throw bl.set(t,n),n}return o(`meta`,{httpEquiv:`refresh`,content:`0;url=${a}`})}}return e}function Sl({routeContext:e,match:t,children:n}){let r=I(Hc);return r&&r.static&&r.staticContext&&(t.route.errorElement||t.route.ErrorBoundary)&&(r.staticContext._deepestRenderedBoundaryId=t.route.id),o(Zc.Provider,{value:e},n)}function Cl(e,t=[],n){let r=n?.state;if(e==null){if(!r)return null;if(r.errors)e=r.matches;else if(t.length===0&&!r.initialized&&r.matches.length>0)e=r.matches;else return null}let i=e,a=r?.errors;if(a!=null){let e=i.findIndex(e=>e.route.id&&a?.[e.route.id]!==void 0);J(e>=0,`Could not find a matching route for errors on route IDs: ${Object.keys(a).join(`,`)}`),i=i.slice(0,Math.min(i.length,e+1))}let s=!1,c=-1;if(n&&r){s=r.renderFallback;for(let e=0;e<i.length;e++){let t=i[e];if((t.route.HydrateFallback||t.route.hydrateFallbackElement)&&(c=e),t.route.id){let{loaderData:e,errors:a}=r,o=t.route.loader&&!e.hasOwnProperty(t.route.id)&&(!a||a[t.route.id]===void 0);if(t.route.lazy||o){n.isStatic&&(s=!0),i=c>=0?i.slice(0,c+1):[i[0]];break}}}}let l=n?.onError,u=r&&l?(e,t)=>{l(e,{location:r.location,params:r.matches?.[0]?.params??{},pattern:Fc(r.matches),errorInfo:t})}:void 0;return i.reduceRight((e,n,l)=>{let d,f=!1,p=null,m=null;r&&(d=a&&n.route.id?a[n.route.id]:void 0,p=n.route.errorElement||vl,s&&(c<0&&l===0?(Fl(`route-fallback`,!1,"No `HydrateFallback` element provided to render during initial hydration"),f=!0,m=null):c===l&&(f=!0,m=n.route.hydrateFallbackElement||null)));let h=t.concat(i.slice(0,l+1)),g=()=>{let t;return t=d?p:f?m:n.route.Component?o(n.route.Component,null):n.route.element?n.route.element:e,o(Sl,{match:n,routeContext:{outlet:e,matches:h,isDataRoute:r!=null},children:t})};return r&&(n.route.ErrorBoundary||n.route.errorElement||l===0)?o(yl,{location:r.location,revalidation:r.revalidation,component:p,error:d,children:g(),routeContext:{outlet:null,matches:h,isDataRoute:!0},onError:u}):g()},null)}function wl(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function Tl(e){let t=I(Hc);return J(t,wl(e)),t}function El(e){let t=I(Uc);return J(t,wl(e)),t}function Dl(e){let t=I(Zc);return J(t,wl(e)),t}function Ol(e){let t=Dl(e),n=t.matches[t.matches.length-1];return J(n.route.id,`${e} can only be used on routes that contain a unique "id"`),n.route.id}function kl(){return Ol(`useRouteId`)}function Al(){let e=El(`useNavigation`);return m(()=>{let{matches:t,historyAction:n,...r}=e.navigation;return r},[e.navigation])}function jl(){let{matches:e,loaderData:t}=El(`useMatches`);return m(()=>e.map(e=>tc(e,t)),[e,t])}function Ml(){let e=I(Qc),t=El(`useRouteError`),n=Ol(`useRouteError`);return e===void 0?t.errors?.[n]:e}function Nl(){let{router:e}=Tl(`useNavigate`),t=Ol(`useNavigate`),n=p(!1);return cl(()=>{n.current=!0}),b(async(r,i={})=>{Gs(n.current,sl),n.current&&(typeof r==`number`?await e.navigate(r):await e.navigate(r,{fromRouteId:t,...i}))},[e,t])}var Pl={};function Fl(e,t,n){!t&&!Pl[e]&&(Pl[e]=!0,Gs(!1,n))}v(Il);function Il({routes:e,manifest:t,future:n,state:r,isStatic:i,onError:a}){return gl(e,void 0,{manifest:t,state:r,isStatic:i,onError:a,future:n})}function X({to:e,replace:t,state:n,relative:r}){J(al(),`<Navigate> may be used only in the context of a <Router> component.`);let{static:i}=I(Yc);Gs(!i,`<Navigate> must not be used on the initial render in a <StaticRouter>. This is a no-op, but you should modify your code so the <Navigate> is only ever rendered in response to some user interaction or state change.`);let{matches:a}=I(Zc),{pathname:o}=Y(),s=ll(),c=Ec(e,Tc(a),o,r===`path`),l=JSON.stringify(c);return S(()=>{s(JSON.parse(l),{replace:t,state:n,relative:r})},[s,l,r,t,n]),null}function Z(e){J(!1,`A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your <Route> in a <Routes>.`)}function Ll({basename:e=`/`,children:t=null,location:n,navigationType:r=`POP`,navigator:i,static:a=!1,useTransitions:s}){J(!al(),`You cannot render a <Router> inside another <Router>. You should never have more than one in your app.`);let c=e.replace(/^\/*/,`/`),l=m(()=>({basename:c,navigator:i,static:a,useTransitions:s,future:{}}),[c,i,a,s]);typeof n==`string`&&(n=Xs(n));let{pathname:u=`/`,search:d=``,hash:f=``,state:p=null,key:h=`default`,mask:g}=n,_=m(()=>{let e=bc(u,c);return e==null?null:{location:{pathname:e,search:d,hash:f,state:p,key:h,mask:g},navigationType:r}},[c,u,d,f,p,h,r,g]);return Gs(_!=null,`<Router basename="${c}"> is not able to match the URL "${u}${d}${f}" because it does not start with the basename, so the <Router> won't render anything.`),_==null?null:o(Yc.Provider,{value:l},o(Xc.Provider,{children:t,value:_}))}function Rl({children:e,location:t}){return hl(zl(e),t)}function zl(e,t=[]){let n=[];return c.forEach(e,(e,r)=>{if(!h(e))return;let i=[...t,r];if(e.type===d){n.push.apply(n,zl(e.props.children,i));return}J(e.type===Z,`[${typeof e.type==`string`?e.type:e.type.name}] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>`),J(!e.props.index||!e.props.children,`An index route cannot have child routes.`);let a={id:e.props.id||i.join(`-`),caseSensitive:e.props.caseSensitive,element:e.props.element,Component:e.props.Component,index:e.props.index,path:e.props.path,middleware:e.props.middleware,loader:e.props.loader,action:e.props.action,hydrateFallbackElement:e.props.hydrateFallbackElement,HydrateFallback:e.props.HydrateFallback,errorElement:e.props.errorElement,ErrorBoundary:e.props.ErrorBoundary,hasErrorBoundary:e.props.hasErrorBoundary===!0||e.props.ErrorBoundary!=null||e.props.errorElement!=null,shouldRevalidate:e.props.shouldRevalidate,handle:e.props.handle,lazy:e.props.lazy};e.props.children&&(a.children=zl(e.props.children,i)),n.push(a)}),n}var Bl=`get`,Vl=`application/x-www-form-urlencoded`;function Hl(e){return typeof HTMLElement<`u`&&e instanceof HTMLElement}function Ul(e){return Hl(e)&&e.tagName.toLowerCase()===`button`}function Wl(e){return Hl(e)&&e.tagName.toLowerCase()===`form`}function Gl(e){return Hl(e)&&e.tagName.toLowerCase()===`input`}function Kl(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function ql(e,t){return e.button===0&&(!t||t===`_self`)&&!Kl(e)}function Jl(e=``){return new URLSearchParams(typeof e==`string`||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce((t,n)=>{let r=e[n];return t.concat(Array.isArray(r)?r.map(e=>[n,e]):[[n,r]])},[]))}function Yl(e,t){let n=Jl(e);return t&&t.forEach((e,r)=>{n.has(r)||t.getAll(r).forEach(e=>{n.append(r,e)})}),n}var Xl=null;function Zl(){if(Xl===null)try{new FormData(document.createElement(`form`),0),Xl=!1}catch{Xl=!0}return Xl}var Ql=new Set([`application/x-www-form-urlencoded`,`multipart/form-data`,`text/plain`]);function $l(e){return e!=null&&!Ql.has(e)?(Gs(!1,`"${e}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${Vl}"`),null):e}function eu(e,t){let n,r,i,a,o;if(Wl(e)){let o=e.getAttribute(`action`);r=o?bc(o,t):null,n=e.getAttribute(`method`)||Bl,i=$l(e.getAttribute(`enctype`))||Vl,a=new FormData(e)}else if(Ul(e)||Gl(e)&&(e.type===`submit`||e.type===`image`)){let o=e.form;if(o==null)throw Error(`Cannot submit a <button> or <input type="submit"> without a <form>`);let s=e.getAttribute(`formaction`)||o.getAttribute(`action`);if(r=s?bc(s,t):null,n=e.getAttribute(`formmethod`)||o.getAttribute(`method`)||Bl,i=$l(e.getAttribute(`formenctype`))||$l(o.getAttribute(`enctype`))||Vl,a=new FormData(o,e),!Zl()){let{name:t,type:n,value:r}=e;if(n===`image`){let e=t?`${t}.`:``;a.append(`${e}x`,`0`),a.append(`${e}y`,`0`)}else t&&a.append(t,r)}}else if(Hl(e))throw Error(`Cannot submit element that is not <form>, <button>, or <input type="submit|image">`);else n=Bl,r=null,i=Vl,o=e;return a&&i===`text/plain`&&(o=a,a=void 0),{action:r,method:n.toLowerCase(),encType:i,formData:a,body:o}}Object.getOwnPropertyNames(Object.prototype).sort().join(`\0`);var tu={"&":`\\u0026`,">":`\\u003e`,"<":`\\u003c`,"\u2028":`\\u2028`,"\u2029":`\\u2029`},nu=/[&><\u2028\u2029]/g;function ru(e){return e.replace(nu,e=>tu[e])}function iu(e,t){if(e===!1||e==null)throw Error(t)}function au(e,t,n,r){let i=typeof e==`string`?new URL(e,typeof window>`u`?`server://singlefetch/`:window.location.origin):e;return n?i.pathname.endsWith(`/`)?i.pathname=`${i.pathname}_.${r}`:i.pathname=`${i.pathname}.${r}`:i.pathname===`/`?i.pathname=`_root.${r}`:t&&bc(i.pathname,t)===`/`?i.pathname=`${kc(t)}/_root.${r}`:i.pathname=`${kc(i.pathname)}.${r}`,i}async function ou(e,t){if(e.id in t)return t[e.id];try{let n=await a(()=>import(e.module),[],import.meta.url);return t[e.id]=n,n}catch(t){return console.error(`Error loading route module \`${e.module}\`, reloading page...`),console.error(t),window.__reactRouterContext&&window.__reactRouterContext.isSpaMode,window.location.reload(),new Promise(()=>{})}}function su(e){return e!=null&&typeof e.page==`string`}function cu(e){return e==null?!1:e.href==null?e.rel===`preload`&&typeof e.imageSrcSet==`string`&&typeof e.imageSizes==`string`:typeof e.rel==`string`&&typeof e.href==`string`}async function lu(e,t,n){return mu((await Promise.all(e.map(async e=>{let r=t.routes[e.route.id];if(r){let e=await ou(r,n);return e.links?e.links():[]}return[]}))).flat(1).filter(cu).filter(e=>e.rel===`stylesheet`||e.rel===`preload`).map(e=>e.rel===`stylesheet`?{...e,rel:`prefetch`,as:`style`}:{...e,rel:`prefetch`}))}function uu(e,t,n,r,i,a){let o=(e,t)=>n[t]?e.route.id!==n[t].route.id:!0,s=(e,t)=>n[t].pathname!==e.pathname||n[t].route.path?.endsWith(`*`)&&n[t].params[`*`]!==e.params[`*`];return a===`assets`?t.filter((e,t)=>o(e,t)||s(e,t)):a===`data`?t.filter((t,a)=>{let c=r.routes[t.route.id];if(!c||!c.hasLoader)return!1;if(o(t,a)||s(t,a))return!0;if(t.route.shouldRevalidate){let r=t.route.shouldRevalidate({currentUrl:new URL(i.pathname+i.search+i.hash,window.origin),currentParams:n[0]?.params||{},nextUrl:new URL(e,window.origin),nextParams:t.params,defaultShouldRevalidate:!0});if(typeof r==`boolean`)return r}return!0}):[]}function du(e,t,{includeHydrateFallback:n}={}){return fu(e.map(e=>{let r=t.routes[e.route.id];if(!r)return[];let i=[r.module];return r.clientActionModule&&(i=i.concat(r.clientActionModule)),r.clientLoaderModule&&(i=i.concat(r.clientLoaderModule)),n&&r.hydrateFallbackModule&&(i=i.concat(r.hydrateFallbackModule)),r.imports&&(i=i.concat(r.imports)),i}).flat(1))}function fu(e){return[...new Set(e)]}function pu(e){let t={},n=Object.keys(e).sort();for(let r of n)t[r]=e[r];return t}function mu(e,t){let n=new Set,r=new Set(t);return e.reduce((e,i)=>{if(t&&!su(i)&&i.as===`script`&&i.href&&r.has(i.href))return e;let a=JSON.stringify(pu(i));return n.has(a)||(n.add(a),e.push({key:a,link:i})),e},[])}function hu(){let e=I(Hc);return iu(e,`You must render this element inside a <DataRouterContext.Provider> element`),e}function gu(){let e=I(Uc);return iu(e,`You must render this element inside a <DataRouterStateContext.Provider> element`),e}var _u=j(void 0);_u.displayName=`FrameworkContext`;function vu(){let e=I(_u);return iu(e,`You must render this element inside a <HydratedRouter> element`),e}function yu(e,t){let n=I(_u),[r,i]=w(!1),[a,o]=w(!1),{onFocus:s,onBlur:c,onMouseEnter:l,onMouseLeave:u,onTouchStart:d}=t,f=p(null);S(()=>{if(e===`render`&&o(!0),e===`viewport`){let e=new IntersectionObserver(e=>{e.forEach(e=>{o(e.isIntersecting)})},{threshold:.5});return f.current&&e.observe(f.current),()=>{e.disconnect()}}},[e]),S(()=>{if(r){let e=setTimeout(()=>{o(!0)},100);return()=>{clearTimeout(e)}}},[r]);let m=()=>{i(!0)},h=()=>{i(!1),o(!1)};return n?e===`intent`?[a,f,{onFocus:bu(s,m),onBlur:bu(c,h),onMouseEnter:bu(l,m),onMouseLeave:bu(u,h),onTouchStart:bu(d,m)}]:[a,f,{}]:[!1,f,{}]}function bu(e,t){return n=>{e&&e(n),n.defaultPrevented||t(n)}}function xu({page:e,...t}){let n=Gc(),{nonce:r}=vu(),{router:i}=hu(),a=m(()=>$s(i.routes,e,i.basename),[i.routes,e,i.basename]);return a?(t.nonce==null&&r&&(t={...t,nonce:r}),o(n?Cu:wu,{page:e,matches:a,...t})):null}function Su(e){let{manifest:t,routeModules:n}=vu(),[r,i]=w([]);return S(()=>{let r=!1;return lu(e,t,n).then(e=>{r||i(e)}),()=>{r=!0}},[e,t,n]),r}function Cu({page:e,matches:t,...n}){let r=Y(),{future:i}=vu(),{basename:a}=hu();return o(d,null,m(()=>{if(e===r.pathname+r.search+r.hash)return[];let n=au(e,a,i.v8_trailingSlashAwareDataRequests,`rsc`),o=!1,s=[];for(let e of t)typeof e.route.shouldRevalidate==`function`?o=!0:s.push(e.route.id);return o&&s.length>0&&n.searchParams.set(`_routes`,s.join(`,`)),[n.pathname+n.search]},[a,i.v8_trailingSlashAwareDataRequests,e,r,t]).map(e=>o(`link`,{key:e,rel:`prefetch`,as:`fetch`,href:e,...n})))}function wu({page:e,matches:t,...n}){let r=Y(),{future:i,manifest:a,routeModules:s}=vu(),{basename:c}=hu(),{loaderData:l,matches:u}=gu(),f=m(()=>uu(e,t,u,a,r,`data`),[e,t,u,a,r]),p=m(()=>uu(e,t,u,a,r,`assets`),[e,t,u,a,r]),h=m(()=>{if(e===r.pathname+r.search+r.hash)return[];let n=new Set,o=!1;if(t.forEach(e=>{let t=a.routes[e.route.id];!t||!t.hasLoader||(!f.some(t=>t.route.id===e.route.id)&&e.route.id in l&&s[e.route.id]?.shouldRevalidate||t.hasClientLoader?o=!0:n.add(e.route.id))}),n.size===0)return[];let u=au(e,c,i.v8_trailingSlashAwareDataRequests,`data`);return o&&n.size>0&&u.searchParams.set(`_routes`,t.filter(e=>n.has(e.route.id)).map(e=>e.route.id).join(`,`)),[u.pathname+u.search]},[c,i.v8_trailingSlashAwareDataRequests,l,r,a,f,t,e,s]),g=m(()=>du(p,a),[p,a]),_=Su(p);return o(d,null,h.map(e=>o(`link`,{key:e,rel:`prefetch`,as:`fetch`,href:e,...n})),g.map(e=>o(`link`,{key:e,rel:`modulepreload`,href:e,...n})),_.map(({key:e,link:t})=>o(`link`,{key:e,nonce:n.nonce,...t,crossOrigin:t.crossOrigin??n.crossOrigin})))}function Tu(...e){return t=>{e.forEach(e=>{typeof e==`function`?e(t):e!=null&&(e.current=t)})}}var Eu=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;try{Eu&&(window.__reactRouterVersion=`7.18.0`)}catch{}function Du({basename:e,children:t,useTransitions:n,window:r}){let i=p();i.current??=Ws({window:r,v5Compat:!0});let a=i.current,[s,c]=w({action:a.action,location:a.location}),l=b(e=>{n===!1?c(e):f(()=>c(e))},[n]);return u(()=>a.listen(l),[a,l]),o(Ll,{basename:e,children:t,location:s.location,navigationType:s.action,navigator:a,useTransitions:n})}function Ou({basename:e,children:t,history:n,useTransitions:r}){let[i,a]=w({action:n.action,location:n.location}),s=b(e=>{r===!1?a(e):f(()=>a(e))},[r]);return u(()=>n.listen(s),[n,s]),o(Ll,{basename:e,children:t,location:i.location,navigationType:i.action,navigator:n,useTransitions:r})}Ou.displayName=`unstable_HistoryRouter`;var ku=A(function({onClick:e,discover:t=`render`,prefetch:n=`none`,relative:r,reloadDocument:i,replace:a,mask:s,state:c,target:l,to:u,preventScrollReset:f,viewTransition:p,defaultShouldRevalidate:m,...h},g){let{basename:_,navigator:v,useTransitions:y}=I(Yc),b=typeof u==`string`&&zs.test(u),x=Lc(u,_);u=x.to;let S=il(u,{relative:r}),C=Y(),w=null;if(s){let e=Ec(s,[],C.mask?C.mask.pathname:`/`,!0);_!==`/`&&(e.pathname=e.pathname===`/`?_:Oc([_,e.pathname])),w=v.createHref(e)}let[T,E,D]=yu(n,h),O=Iu(u,{replace:a,mask:s,state:c,target:l,preventScrollReset:f,relative:r,viewTransition:p,defaultShouldRevalidate:m,useTransitions:y});function k(t){e&&e(t),t.defaultPrevented||O(t)}let A=!(x.isExternal||i),j=o(`a`,{...h,...D,href:(A?w:void 0)||x.absoluteURL||S,onClick:A?k:e,ref:Tu(g,E),target:l,"data-discover":!b&&t===`render`?`true`:void 0});return T&&!b?o(d,null,j,o(xu,{page:S})):j});ku.displayName=`Link`;var Au=A(function({"aria-current":e=`page`,caseSensitive:t=!1,className:n=``,end:r=!1,style:i,to:a,viewTransition:s,children:c,...l},u){let d=ml(a,{relative:l.relative}),f=Y(),p=I(Uc),{navigator:m,basename:h}=I(Yc),g=p!=null&&qu(d)&&s===!0,_=m.encodeLocation?m.encodeLocation(d).pathname:d.pathname,v=f.pathname,y=p&&p.navigation&&p.navigation.location?p.navigation.location.pathname:null;t||(v=v.toLowerCase(),y=y?y.toLowerCase():null,_=_.toLowerCase()),y&&h&&(y=bc(y,h)||y);let b=_!==`/`&&_.endsWith(`/`)?_.length-1:_.length,x=v===_||!r&&v.startsWith(_)&&v.charAt(b)===`/`,S=y!=null&&(y===_||!r&&y.startsWith(_)&&y.charAt(_.length)===`/`),C={isActive:x,isPending:S,isTransitioning:g},w=x?e:void 0,T;T=typeof n==`function`?n(C):[n,x?`active`:null,S?`pending`:null,g?`transitioning`:null].filter(Boolean).join(` `);let E=typeof i==`function`?i(C):i;return o(ku,{...l,"aria-current":w,className:T,ref:u,style:E,to:a,viewTransition:s},typeof c==`function`?c(C):c)});Au.displayName=`NavLink`;var ju=A(({discover:e=`render`,fetcherKey:t,navigate:n,reloadDocument:r,replace:i,state:a,method:s=Bl,action:c,onSubmit:l,relative:u,preventScrollReset:d,viewTransition:p,defaultShouldRevalidate:m,...h},g)=>{let{useTransitions:_}=I(Yc),v=Bu(),y=Vu(c,{relative:u}),b=s.toLowerCase()===`get`?`get`:`post`,x=typeof c==`string`&&zs.test(c);return o(`form`,{ref:g,method:b,action:y,onSubmit:r?l:e=>{if(l&&l(e),e.defaultPrevented)return;e.preventDefault();let r=e.nativeEvent.submitter,o=r?.getAttribute(`formmethod`)||s,c=()=>v(r||e.currentTarget,{fetcherKey:t,method:o,navigate:n,replace:i,state:a,relative:u,preventScrollReset:d,viewTransition:p,defaultShouldRevalidate:m});_&&n!==!1?f(()=>c()):c()},...h,"data-discover":!x&&e===`render`?`true`:void 0})});ju.displayName=`Form`;function Mu({getKey:e,storageKey:t,...n}){let r=I(_u),{basename:i}=I(Yc),a=Y(),s=jl();Gu({getKey:e,storageKey:t});let c=m(()=>{if(!r||!e)return null;let t=Wu(a,s,i,e);return t===a.key?null:t},[]);if(!r||r.isSpaMode)return null;let l=((e,t)=>{if(!window.history.state||!window.history.state.key){let e=Math.random().toString(32).slice(2);window.history.replaceState({key:e},``)}try{let n=JSON.parse(sessionStorage.getItem(e)||`{}`)[t||window.history.state.key];typeof n==`number`&&window.scrollTo(0,n)}catch(t){console.error(t),sessionStorage.removeItem(e)}}).toString();return n.nonce==null&&r?.nonce&&(n.nonce=r.nonce),o(`script`,{...n,suppressHydrationWarning:!0,dangerouslySetInnerHTML:{__html:`(${l})(${ru(JSON.stringify(t||Hu))}, ${ru(JSON.stringify(c))})`}})}Mu.displayName=`ScrollRestoration`;function Nu(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function Pu(e){let t=I(Hc);return J(t,Nu(e)),t}function Fu(e){let t=I(Uc);return J(t,Nu(e)),t}function Iu(e,{target:t,replace:n,mask:r,state:i,preventScrollReset:a,relative:o,viewTransition:s,defaultShouldRevalidate:c,useTransitions:l}={}){let u=ll(),d=Y(),p=ml(e,{relative:o});return b(m=>{if(ql(m,t)){m.preventDefault();let t=n===void 0?Ys(d)===Ys(p):n,h=()=>u(e,{replace:t,mask:r,state:i,preventScrollReset:a,relative:o,viewTransition:s,defaultShouldRevalidate:c});l?f(()=>h()):h()}},[d,u,p,n,r,i,t,e,a,o,s,c,l])}function Lu(e){Gs(typeof URLSearchParams<`u`,"You cannot use the `useSearchParams` hook in a browser that does not support the URLSearchParams API. If you need to support Internet Explorer 11, we recommend you load a polyfill such as https://github.com/ungap/url-search-params.");let t=p(Jl(e)),n=p(!1),r=Y(),i=m(()=>Yl(r.search,n.current?null:t.current),[r.search]),a=ll();return[i,b((e,t)=>{let r=Jl(typeof e==`function`?e(new URLSearchParams(i)):e);n.current=!0,a(`?`+r,t)},[a,i])]}var Ru=0,zu=()=>`__${String(++Ru)}__`;function Bu(){let{router:e}=Pu(`useSubmit`),{basename:t}=I(Yc),n=kl(),r=e.fetch,i=e.navigate;return b(async(e,a={})=>{let{action:o,method:s,encType:c,formData:l,body:u}=eu(e,t);a.navigate===!1?await r(a.fetcherKey||zu(),n,a.action||o,{defaultShouldRevalidate:a.defaultShouldRevalidate,preventScrollReset:a.preventScrollReset,formData:l,body:u,formMethod:a.method||s,formEncType:a.encType||c,flushSync:a.flushSync}):await i(a.action||o,{defaultShouldRevalidate:a.defaultShouldRevalidate,preventScrollReset:a.preventScrollReset,formData:l,body:u,formMethod:a.method||s,formEncType:a.encType||c,replace:a.replace,state:a.state,fromRouteId:n,flushSync:a.flushSync,viewTransition:a.viewTransition})},[r,i,t,n])}function Vu(e,{relative:t}={}){let{basename:n}=I(Yc),r=I(Zc);J(r,`useFormAction must be used inside a RouteContext`);let[i]=r.matches.slice(-1),a={...ml(e||`.`,{relative:t})},o=Y();if(e==null){a.search=o.search;let e=new URLSearchParams(a.search),t=e.getAll(`index`);if(t.some(e=>e===``)){e.delete(`index`),t.filter(e=>e).forEach(t=>e.append(`index`,t));let n=e.toString();a.search=n?`?${n}`:``}}return(!e||e===`.`)&&i.route.index&&(a.search=a.search?a.search.replace(/^\?/,`?index&`):`?index`),n!==`/`&&(a.pathname=a.pathname===`/`?n:Oc([n,a.pathname])),Ys(a)}var Hu=`react-router-scroll-positions`,Uu={};function Wu(e,t,n,r){let i=null;return r&&(i=r(n===`/`?e:{...e,pathname:bc(e.pathname,n)||e.pathname},t)),i??=e.key,i}function Gu({getKey:e,storageKey:t}={}){let{router:n}=Pu(`useScrollRestoration`),{restoreScrollPosition:r,preventScrollReset:i}=Fu(`useScrollRestoration`),{basename:a}=I(Yc),o=Y(),s=jl(),c=Al();S(()=>(window.history.scrollRestoration=`manual`,()=>{window.history.scrollRestoration=`auto`}),[]),Ku(b(()=>{if(c.state===`idle`){let t=Wu(o,s,a,e);Uu[t]=window.scrollY}try{sessionStorage.setItem(t||Hu,JSON.stringify(Uu))}catch(e){Gs(!1,`Failed to save scroll positions in sessionStorage, <ScrollRestoration /> will not work properly (${e}).`)}window.history.scrollRestoration=`auto`},[c.state,e,a,o,s,t])),typeof document<`u`&&(u(()=>{try{let e=sessionStorage.getItem(t||Hu);e&&(Uu=JSON.parse(e))}catch{}},[t]),u(()=>{let t=n?.enableScrollRestoration(Uu,()=>window.scrollY,e?(t,n)=>Wu(t,n,a,e):void 0);return()=>t&&t()},[n,a,e]),u(()=>{if(r!==!1){if(typeof r==`number`){window.scrollTo(0,r);return}try{if(o.hash){let e=document.getElementById(decodeURIComponent(o.hash.slice(1)));if(e){e.scrollIntoView();return}}}catch{Gs(!1,`"${o.hash.slice(1)}" is not a decodable element ID. The view will not scroll to it.`)}i!==!0&&window.scrollTo(0,0)}},[o,r,i]))}function Ku(e,t){let{capture:n}=t||{};S(()=>{let t=n==null?void 0:{capture:n};return window.addEventListener(`pagehide`,e,t),()=>{window.removeEventListener(`pagehide`,e,t)}},[e,n])}function qu(e,{relative:t}={}){let n=I(Kc);J(n!=null,"`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?");let{basename:r}=Pu(`useViewTransitionState`),i=ml(e,{relative:t});if(!n.isTransitioning)return!1;let a=bc(n.currentLocation.pathname,r)||n.currentLocation.pathname,o=bc(n.nextLocation.pathname,r)||n.nextLocation.pathname;return gc(i.pathname,o)!=null||gc(i.pathname,a)!=null}var Ju=e(t(((e,t)=>{t.exports={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}}))()),Yu=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function Xu(e){var t={type:`tag`,name:``,voidElement:!1,attrs:{},children:[]},n=e.match(/<\/?([^\s]+?)[/\s>]/);if(n&&(t.name=n[1],(Ju.default[n[1]]||e.charAt(e.length-2)===`/`)&&(t.voidElement=!0),t.name.startsWith(`!--`))){var r=e.indexOf(`-->`);return{type:`comment`,comment:r===-1?``:e.slice(4,r)}}for(var i=new RegExp(Yu),a=null;(a=i.exec(e))!==null;)if(a[0].trim())if(a[1]){var o=a[1].trim(),s=[o,``];o.indexOf(`=`)>-1&&(s=o.split(`=`)),t.attrs[s[0]]=s[1],i.lastIndex--}else a[2]&&(t.attrs[a[2]]=a[3].trim().substring(1,a[3].length-1));return t}var Zu=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,Qu=/^\s*$/,$u=Object.create(null);function ed(e,t){switch(t.type){case`text`:return e+t.content;case`tag`:return e+=`<`+t.name+(t.attrs?function(e){var t=[];for(var n in e)t.push(n+`="`+e[n]+`"`);return t.length?` `+t.join(` `):``}(t.attrs):``)+(t.voidElement?`/>`:`>`),t.voidElement?e:e+t.children.reduce(ed,``)+`</`+t.name+`>`;case`comment`:return e+`<!--`+t.comment+`-->`}}var td={parse:function(e,t){t||={},t.components||=$u;var n,r=[],i=[],a=-1,o=!1;if(e.indexOf(`<`)!==0){var s=e.indexOf(`<`);r.push({type:`text`,content:s===-1?e:e.substring(0,s)})}return e.replace(Zu,function(s,c){if(o){if(s!==`</`+n.name+`>`)return;o=!1}var l,u=s.charAt(1)!==`/`,d=s.startsWith(`<!--`),f=c+s.length,p=e.charAt(f);if(d){var m=Xu(s);return a<0?(r.push(m),r):((l=i[a]).children.push(m),r)}if(u&&(a++,(n=Xu(s)).type===`tag`&&t.components[n.name]&&(n.type=`component`,o=!0),n.voidElement||o||!p||p===`<`||n.children.push({type:`text`,content:e.slice(f,e.indexOf(`<`,f))}),a===0&&r.push(n),(l=i[a-1])&&l.children.push(n),i[a]=n),(!u||n.voidElement)&&(a>-1&&(n.voidElement||n.name===s.slice(2,-1))&&(a--,n=a===-1?r:i[a]),!o&&p!==`<`&&p)){l=a===-1?r:i[a].children;var h=e.indexOf(`<`,f),g=e.slice(f,h===-1?void 0:h);Qu.test(g)&&(g=` `),(h>-1&&a+l.length>=0||g!==` `)&&l.push({type:`text`,content:g})}}),r},stringify:function(e){return e.reduce(function(e,t){return e+ed(``,t)},``)}};O();var nd=(e,t)=>{if(!e)return!1;let n=e.props?.children??e.children;return t?n.length>0:!!n},rd=e=>{if(!e)return[];let t=e.props?.children??e.children;return e.props?.i18nIsDynamicList?ad(t):t},id=e=>Array.isArray(e)&&e.every(h),ad=e=>Array.isArray(e)?e:[e],od=(e,t)=>{let n={...t};return n.props={...t.props,...e.props},n},sd=e=>{let t={};if(!e)return t;let n=e=>{ad(e).forEach(e=>{ko(e)||(nd(e)?n(rd(e)):Po(e)&&!h(e)&&Object.assign(t,e))})};return n(e),t},cd=(e,t,n,r)=>{if(!e)return``;let i=``,a=ad(e),o=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return a.forEach((e,a)=>{if(ko(e)){i+=`${e}`;return}if(h(e)){let{props:s,type:c}=e,l=Object.keys(s).length,u=o.indexOf(c)>-1,d=s.children;if(!d&&u&&!l){i+=`<${c}/>`;return}if(!d&&(!u||l)||s.i18nIsDynamicList){i+=`<${a}></${a}>`;return}if(u&&l<=1){let e=ko(d)?d:cd(d,t,n,r);i+=`<${c}>${e}</${c}>`;return}let f=cd(d,t,n,r);i+=`<${a}>${f}</${a}>`;return}if(e===null){jo(n,`TRANS_NULL_VALUE`,`Passed in a null value as child`,{i18nKey:r});return}if(Po(e)){let{format:t,...a}=e,o=Object.keys(a);if(o.length===1){let e=t?`${o[0]}, ${t}`:o[0];i+=`{{${e}}}`;return}jo(n,`TRANS_INVALID_OBJ`,`Invalid child - Object should only have keys {{ value, format }} (format is optional).`,{i18nKey:r,child:e});return}jo(n,`TRANS_INVALID_VAR`,`Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.`,{i18nKey:r,child:e})}),i},ld=(e,t=[],n={})=>{if(!e)return e;let r=Object.keys(n),i=[...t,...r],a=``,o=0;for(;o<e.length;)if(e[o]===`<`){let t=!1,n=e.slice(o).match(/^<\/(\d+|[a-zA-Z][a-zA-Z0-9_-]*)>/);if(n){let e=n[1];(/^\d+$/.test(e)||i.includes(e))&&(t=!0,a+=n[0],o+=n[0].length)}if(!t){let n=e.slice(o).match(/^<(\d+|[a-zA-Z][a-zA-Z0-9_-]*)(\s+[\w-]+(?:=(?:"[^"]*"|'[^']*'|[^\s>]+))?)*\s*(\/)?>/);if(n){let e=n[1];(/^\d+$/.test(e)||i.includes(e))&&(t=!0,a+=n[0],o+=n[0].length)}}t||(a+=`<`,o+=1)}else a+=e[o],o+=1;return a},ud=(e,t,n,r,i,a,s)=>{if(n===``)return[];let l=i.transKeepBasicHtmlNodesFor||[],u=n&&new RegExp(l.map(e=>`<${e}`).join(`|`)).test(n);if(!e&&!t&&!u&&!s)return[n];let f=t??{},p=e=>{ad(e).forEach(e=>{ko(e)||(nd(e)?p(rd(e)):Po(e)&&!h(e)&&Object.assign(f,e))})};p(e);let m=ld(n,l,f),g=td.parse(`<0>${m}</0>`),v={...f,...a},y=(e,t,n)=>{let r=rd(e),i=x(r,t.children,n);return id(r)&&i.length===0||e.props?.i18nIsDynamicList?r:i},b=(e,t,n,r,i)=>{e.dummy?(e.children=t,n.push(_(e,{key:r},i?void 0:t))):n.push(...c.map([e],e=>{if(e.type===d||e.props?.i18nIsDynamicList!==void 0){let n={key:r};return e&&e.props&&Object.keys(e.props).forEach(t=>{t===`children`||t===`i18nIsDynamicList`||(n[t]=e.props[t])}),o(e.type,n,i?null:t)}let n={key:r};return e&&e.props&&Object.keys(e.props).forEach(t=>{t===`ref`||t===`children`||(n[t]=e.props[t])}),_(e,n,i?null:t)}))},x=(e,n,a)=>{let c=ad(e),d=ad(n),f={};return d.reduce((e,n,d)=>{let p=n.children?.[0]?.content&&r.services.interpolator.interpolate(n.children[0].content,v,r.language);if(n.type===`tag`){let m=c[parseInt(n.name,10)];!m&&t&&(m=t[n.name]),a.length===1&&!m&&(m=a[0][n.name]),m||={};let g={...n.attrs};s&&Object.keys(g).forEach(e=>{let t=g[e];ko(t)&&(g[e]=No(t))});let _=Object.keys(g).length===0?m:od({props:g},m),S=h(_),C=S&&nd(n,!0)&&!n.voidElement,w=u&&Po(_)&&_.dummy&&!S,T=Po(t)&&Object.hasOwnProperty.call(t,n.name);if(ko(_)){let t=r.services.interpolator.interpolate(_,v,r.language);e.push(t)}else if(nd(_)||C)b(_,y(_,n,a),e,d);else if(w)b(_,x(c,n.children,a),e,d);else if(Number.isNaN(parseFloat(n.name)))if(T)b(_,y(_,n,a),e,d,n.voidElement);else if(i.transSupportBasicHtmlNodes&&l.indexOf(n.name)>-1)if(n.voidElement)e.push(o(n.name,{key:`${n.name}-${d}`}));else{let t=f[n.name]||0;f[n.name]=t+1;let r,i=0;for(let e=0;e<c.length;e+=1){let a=c[e];if(h(a)&&a.type===n.name){if(i===t){r=a;break}i+=1}}let s=x(r?ad(rd(r)):c,n.children,a);e.push(o(n.name,{key:`${n.name}-${d}`},s))}else if(n.voidElement)e.push(`<${n.name} />`);else{let t=x(c,n.children,a);e.push(`<${n.name}>${t}</${n.name}>`)}else if(Po(_)&&!S){let t=n.children[0]?p:null;t&&e.push(t)}else b(_,p,e,d,n.children.length!==1||!p)}else if(n.type===`text`){let t=i.transWrapTextNodes,a=typeof i.unescape==`function`?i.unescape:Oo().unescape,c=s?a(r.services.interpolator.interpolate(n.content,v,r.language)):r.services.interpolator.interpolate(n.content,v,r.language);t?e.push(o(t,{key:`${n.name}-${d}`},c)):e.push(c)}return e},[])};return rd(x([{dummy:!0,children:e||[]}],g,ad(e||[]))[0])},dd=(e,t,n)=>{let r=e.key||t,i=_(e,{key:r});if(!i.props||!i.props.children||n.indexOf(`${t}/>`)<0&&n.indexOf(`${t} />`)<0)return i;function a(){return o(d,null,i)}return o(a,{key:r})},fd=(e,t)=>e.map((e,n)=>dd(e,n,t)),pd=(e,t)=>{let n={};return Object.keys(e).forEach(r=>{Object.assign(n,{[r]:dd(e[r],r,t)})}),n},md=(e,t,n,r)=>e?Array.isArray(e)?fd(e,t):Po(e)?pd(e,t):(Fo(n,`TRANS_INVALID_COMPONENTS`,`<Trans /> "components" prop expects an object or array`,{i18nKey:r}),null):null,hd=e=>!Po(e)||Array.isArray(e)?!1:Object.keys(e).reduce((e,t)=>e&&Number.isNaN(Number.parseFloat(t)),!0);function gd({children:e,count:t,parent:n,i18nKey:r,context:i,tOptions:a={},values:s,defaults:c,components:l,ns:u,i18n:d,t:f,shouldUnescape:p,...m}){let h=d||Ao();if(!h)return Fo(h,`NO_I18NEXT_INSTANCE`,`Trans: You need to pass in an i18next instance using i18nextReactModule`,{i18nKey:r}),e;let g=f||h.t.bind(h)||(e=>e),_={...Oo(),...h.options?.react},v=u||g.ns||h.options?.defaultNS;v=ko(v)?[v]:v||[`translation`];let{transDefaultProps:y}=_,b=y?.tOptions?{...y.tOptions,...a}:a,x=p??y?.shouldUnescape,S=y?.values?{...y.values,...s}:s,C=y?.components?{...y.components,...l}:l,w=cd(e,_,h,r),T=c||b?.defaultValue||w||_.transEmptyNodeValue||(typeof r==`function`?Do(r):r),{hashTransKey:E}=_,D=r||(E?E(w||T):w||T);s=h.options?.interpolation?.defaultVariables?S&&Object.keys(S).length>0?{...S,...h.options.interpolation.defaultVariables}:{...h.options.interpolation.defaultVariables}:S;let O=sd(e);O&&typeof O.count==`number`&&t===void 0&&(t=O.count);let k=s||t!==void 0&&!h.options?.interpolation?.alwaysFormat||!e?b.interpolation:{interpolation:{...b.interpolation,prefix:`#$?`,suffix:`?$#`}},A={...b,context:i||b.context,count:t,...s,...k,defaultValue:T,ns:v},j=D?g(D,A):T;j===D&&T&&(j=T);let M=md(C,j,h,r),N=M||e,ee=null;hd(M)&&(ee=M,N=e);let P=ud(N,ee,j,h,_,A,x),F=n??_.defaultTransParent;return F?o(F,m,P):P}O();function _d({children:e,count:t,parent:n,i18nKey:r,context:i,tOptions:a={},values:o,defaults:s,components:c,ns:l,i18n:u,t:d,shouldUnescape:f,...p}){let{i18n:m,defaultNS:h}=I(Mo)||{},g=u||m||Ao(),_=d||g?.t.bind(g);return gd({children:e,count:t,parent:n,i18nKey:r,context:i,tOptions:a,values:o,defaults:s,components:c,ns:l||_?.ns||h||g?.options?.defaultNS,i18n:g,t:d,shouldUnescape:f,...p})}O();function vd({i18n:e,defaultNS:t,children:n}){let r=m(()=>({i18n:e,defaultNS:t}),[e,t]);return o(Mo.Provider,{value:r},n)}var yd=`camstack:broker-oauth`;function bd(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.type===`camstack:broker-oauth`&&typeof t.ok==`boolean`}function xd(e,t){return e.split(`{{brokerId}}`).join(encodeURIComponent(t))}function Sd(e,t,n=window){let r=n.location.origin,i=!1,a=e=>{i||(i=!0,n.removeEventListener(`message`,o),window.clearInterval(s),t(e))},o=t=>{t.origin!==r||t.source!==e||bd(t.data)&&a({ok:t.data.ok,...t.data.brokerId===void 0?{}:{brokerId:t.data.brokerId},...t.data.error===void 0?{}:{error:t.data.error}})};n.addEventListener(`message`,o);let s=window.setInterval(()=>{e.closed&&a({ok:!0})},500);return()=>{i=!0,n.removeEventListener(`message`,o),window.clearInterval(s)}}var Cd={open:e=>zo(e),assign:e=>window.location.assign(e),watch:(e,t)=>Sd(e,t)};function wd(e,t,n=Cd){let r=B(Lo(e)),i=n.open(r);if(i===null){n.assign(r);return}n.watch(i,e=>{t?.(e)})}var Td=[`starting`,`awaiting-login`,`captured`,`error`,`cancelled`],Ed=[`awaiting-code`,`captured`,`expired`,`error`,`cancelled`];function Dd(e){return typeof e==`object`&&!!e}function Od(e){return Dd(e)&&typeof e.sessionId==`string`&&typeof e.loginUrl==`string`}function kd(e){return Dd(e)&&typeof e.sessionId==`string`&&typeof e.phase==`string`&&Td.includes(e.phase)}function Ad(e){return Dd(e)&&typeof e.sessionId==`string`&&typeof e.userCode==`string`&&typeof e.verificationUrl==`string`&&typeof e.expiresAt==`number`}function jd(e){return Ad(e)&&Dd(e)&&typeof e.phase==`string`&&Ed.includes(e.phase)}function Md(e){return Dd(e)&&typeof e.brokerId==`string`}function Nd(){return{"Content-Type":`application/json`,Authorization:`Bearer ${localStorage.getItem(`camstack_admin_token`)??``}`}}async function Pd(e,t){try{return await e.json()}catch{throw Error(`${t} failed: HTTP ${e.status}`)}}function Fd(e){let t=Dd(e)&&typeof e.error==`string`?e.error:`Unknown error`;return Error(t)}async function Id(e,t,n){let r=await fetch(B(e),{method:`POST`,headers:Nd(),body:JSON.stringify(t)}),i=await Pd(r,`Sign-in ${e.split(`/`).pop()??`request`}`);if(!r.ok)throw Fd(i);if(!n(i))throw Error(`Unexpected response from server`);return i}function Ld(e,t){return Id(`${e}/start`,t,Od)}function Rd(e,t){return Id(`${e}/code/start`,t,Ad)}async function zd(e,t){let n=new URLSearchParams({sessionId:t}),r=await fetch(B(`${e}/status?${n.toString()}`),{headers:{Authorization:Nd().Authorization??``}}),i=await Pd(r,`Sign-in status`);if(!r.ok)throw Fd(i);if(!jd(i))throw Error(`Unexpected status response from server`);return i}async function Bd(e,t){let n=new URLSearchParams({sessionId:t}),r=await fetch(B(`${e}/status?${n.toString()}`),{headers:{Authorization:Nd().Authorization??``}}),i=await Pd(r,`Sign-in status`);if(!r.ok)throw Fd(i);if(!kd(i))throw Error(`Unexpected status response from server`);return i}function Vd(e,t){return Id(`${e}/commit`,{...t},Md)}async function Hd(e,t){try{await fetch(B(`${e}/cancel`),{method:`POST`,headers:Nd(),body:JSON.stringify({sessionId:t})})}catch{}}O();var Ud=2e3,Wd=1e3;function Gd(e){let t=Math.max(0,Math.ceil(e/1e3));return`${Math.floor(t/60)}:${(t%60).toString().padStart(2,`0`)}`}function Kd({expiresAt:e}){let{t}=q(),[n,r]=w(()=>Date.now());return S(()=>{let e=setInterval(()=>r(Date.now()),Wd);return()=>clearInterval(e)},[]),x(`span`,{className:`text-[11px] text-foreground-subtle`,children:t(`brokers.signIn.codeExpiresIn`,{time:Gd(e-n)})})}function qd({basePath:e,name:t,brokerId:n,getSettings:r,disabled:i,onSignedIn:a}){let{t:o}=q(),[c,l]=w({kind:`idle`}),u=p(!0),d=p(null),f=p(null),m=b(()=>{f.current!==null&&clearInterval(f.current),f.current=null},[]),h=b(()=>{m();let t=d.current;d.current=null,t!==null&&Hd(e,t)},[e,m]);S(()=>(u.current=!0,()=>{u.current=!1,h()}),[h]);let g=b(e=>{m(),u.current&&l({kind:`error`,message:e})},[m]),_=b(async r=>{m(),u.current&&l({kind:`committing`});try{let i=await Vd(e,{sessionId:r,name:t,...n===void 0?{}:{brokerId:n}});d.current=null,u.current&&a(i.brokerId)}catch(e){g(e instanceof Error?e.message:String(e))}},[e,n,g,t,a,m]),v=b(t=>{m(),f.current=setInterval(()=>{(async()=>{try{let n=await zd(e,t);if(n.phase===`captured`)return void await _(t);if(n.phase===`error`)return g(n.error??o(`brokers.signIn.proxyError`));if(n.phase===`expired`){m(),u.current&&l({kind:`expired`});return}n.phase===`cancelled`&&(m(),u.current&&l({kind:`idle`}))}catch{}})()},Ud)},[e,_,g,m,o]),y=async()=>{h(),l({kind:`starting`});try{let t=await Rd(e,r());d.current=t.sessionId,l({kind:`waiting`,code:t}),v(t.sessionId)}catch(e){g(e instanceof Error?e.message:String(e))}},C=()=>{h(),l({kind:`idle`})};if(c.kind===`idle`||c.kind===`error`||c.kind===`expired`)return s(`div`,{className:`space-y-2`,children:[c.kind===`error`&&x(Or,{message:c.message}),c.kind===`expired`&&x(`p`,{className:`text-xs text-warning`,children:o(`brokers.signIn.codeExpired`)}),x(`p`,{className:`text-xs text-foreground-muted`,children:o(`brokers.signIn.codeIntro`)}),s(G,{variant:`primary`,size:`sm`,disabled:i===!0||t.trim().length===0,onClick:()=>void y(),children:[c.kind===`idle`?x(dr,{className:`h-3.5 w-3.5`}):x(Ae,{className:`h-3.5 w-3.5`}),` `,c.kind===`idle`?o(`brokers.signIn.getCode`):o(`brokers.signIn.newCode`)]})]});if(c.kind===`starting`||c.kind===`committing`)return s(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[x(H,{className:`h-4 w-4 animate-spin flex-shrink-0`}),c.kind===`starting`?o(`brokers.signIn.starting`):o(`brokers.signIn.saving`)]});let{code:T}=c;return s(`div`,{className:`space-y-3 rounded-lg border border-border bg-surface p-3`,children:[x(`p`,{className:`text-xs text-foreground-muted`,children:o(`brokers.signIn.codeInstructions`)}),s(`div`,{className:`flex items-center justify-between gap-2 rounded-md border border-border-subtle bg-background px-3 py-2`,children:[x(`span`,{"data-testid":`device-code`,className:`font-mono text-2xl font-semibold tracking-widest text-foreground break-all`,children:T.userCode}),x(hi,{value:T.userCode,srLabel:o(`brokers.signIn.copyCode`)})]}),s(G,{variant:`primary`,size:`sm`,onClick:()=>window.open(T.verificationUrl,`_blank`,`noopener,noreferrer`),children:[x(wt,{className:`h-3.5 w-3.5`}),` `,o(`brokers.signIn.openCodePage`,{host:Jd(T.verificationUrl)})]}),s(`div`,{className:`flex flex-wrap items-center justify-between gap-2 pt-1`,children:[s(`span`,{className:`flex min-w-0 flex-col text-[11px] text-foreground-subtle`,children:[s(`span`,{className:`flex items-center gap-2`,children:[x(H,{className:`h-3 w-3 animate-spin flex-shrink-0`}),` `,o(`brokers.signIn.waitingForCode`)]}),x(Kd,{expiresAt:T.expiresAt})]}),x(G,{variant:`outline`,size:`sm`,className:`shrink-0 whitespace-nowrap`,onClick:C,children:o(`brokers.signIn.cancel`)})]})]})}function Jd(e){try{let t=new URL(e);return`${t.host}${t.pathname===`/`?``:t.pathname}`}catch{return e}}O();var Yd=2e3;function Xd(e){return e.startsWith(`/`)&&!e.startsWith(`//`)?new URL(e,window.location.origin).toString():e}function Zd({basePath:e,name:t,brokerId:n,getSettings:r,disabled:i,onSignedIn:a}){let{t:o}=q(),[c,l]=w({kind:`idle`}),u=p(!0),d=p(null),f=p(null),m=b(()=>{f.current!==null&&clearInterval(f.current),f.current=null},[]),h=b(()=>{m();let t=d.current;d.current=null,t!==null&&Hd(e,t)},[e,m]);S(()=>(u.current=!0,()=>{u.current=!1,h()}),[h]);let g=b(e=>{m(),u.current&&l({kind:`error`,message:e})},[m]),_=b(async r=>{m(),u.current&&l({kind:`committing`});try{let i=await Vd(e,{sessionId:r,name:t,...n===void 0?{}:{brokerId:n}});d.current=null,u.current&&a(i.brokerId)}catch(e){g(e instanceof Error?e.message:String(e))}},[e,n,g,t,a,m]),v=b(t=>{m(),f.current=setInterval(()=>{(async()=>{try{let n=await Bd(e,t);if(n.phase===`captured`)return void await _(t);if(n.phase===`error`)return g(n.error??o(`brokers.signIn.proxyError`));if(n.phase===`cancelled`){m(),u.current&&l({kind:`idle`});return}u.current&&l({kind:`waiting`,loginUrl:n.loginUrl,ready:n.phase===`awaiting-login`})}catch{}})()},Yd)},[e,_,g,m,o]),y=async()=>{h(),l({kind:`starting`});try{let t=await Ld(e,r());d.current=t.sessionId,l({kind:`waiting`,loginUrl:t.loginUrl,ready:!1}),v(t.sessionId)}catch(e){g(e instanceof Error?e.message:String(e))}};return c.kind===`idle`||c.kind===`error`?s(`div`,{className:`space-y-2`,children:[c.kind===`error`&&x(Or,{message:c.message}),x(`p`,{className:`text-xs text-foreground-muted`,children:o(`brokers.signIn.intro`)}),s(G,{variant:`primary`,size:`sm`,disabled:i===!0||t.trim().length===0,onClick:()=>void y(),children:[x(dr,{className:`h-3.5 w-3.5`}),` `,c.kind===`error`?o(`common.retry`):o(`brokers.signIn.start`)]})]}):c.kind===`starting`||c.kind===`committing`?s(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[x(H,{className:`h-4 w-4 animate-spin flex-shrink-0`}),c.kind===`starting`?o(`brokers.signIn.starting`):o(`brokers.signIn.saving`)]}):s(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:[c.ready?s(F,{children:[x(`p`,{className:`text-xs font-semibold text-foreground`,children:o(`brokers.signIn.openLink`)}),x(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`brokers.signIn.afterLogin`)}),s(G,{variant:`primary`,size:`sm`,onClick:()=>window.open(Xd(c.loginUrl),`_blank`,`noopener,noreferrer`),children:[x(wt,{className:`h-3.5 w-3.5`}),` `,o(`brokers.signIn.openLoginPage`)]})]}):s(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[x(H,{className:`h-4 w-4 animate-spin flex-shrink-0`}),o(`brokers.signIn.waitingForProxy`)]}),s(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[s(`span`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[x(H,{className:`h-3 w-3 animate-spin`}),` `,o(`brokers.signIn.waitingForLogin`)]}),x(G,{variant:`outline`,size:`sm`,onClick:()=>{h(),l({kind:`idle`})},children:o(`brokers.signIn.cancel`)})]})]})}O();var Qd=[`device-code`];function $d({methods:e,...t}){let{t:n}=q(),r=e!==void 0&&e.length>0?e:Qd,[i,a]=w(null),o=i!==null&&r.includes(i)?i:r[0]??`device-code`;return s(`div`,{className:`space-y-2`,children:[r.length>1&&x(ra,{value:o,onValueChange:e=>a(e===`device-code`?e:`proxy`),appearance:`pills`,children:x(io,{"aria-label":n(`brokers.signIn.method`),children:r.map(e=>x(sa,{value:e,children:n(e===`device-code`?`brokers.signIn.methodDeviceCode`:`brokers.signIn.methodProxy`)},e))})}),o===`device-code`?x(qd,{...t},`device-code`):x(Zd,{...t},`proxy`)]})}function ef(e){return t=>Object.prototype.hasOwnProperty.call(e,t)}var tf=ef({devices:!0}),nf=ef({classes:!0,classesExclude:!0,labelEquals:!0,identities:!0,identitiesExclude:!0,eventTypeTokens:!0,sensorKinds:!0}),rf=ef({minConfidence:!0,minImportance:!0,minLabelConfidence:!0}),af=ef({minDwellSeconds:!0}),of=ef({source:!0}),sf=ef({crossing:!0}),cf=ef({packagePhase:!0}),lf=ef({sensorTransition:!0}),uf=ef({plates:!0}),df=ef({occupancy:!0}),ff=ef({audio:!0}),pf=ef({systemEvent:!0}),mf=ef({deviceState:!0}),hf=ef({scene:!0});function gf(e,t){let n=e[t];return Array.isArray(n)?n:[]}function _f(e,t){let n=e[t];return typeof n==`number`?n:void 0}var vf=`event-emitter`;function yf(e){let t=new Map,n=[],r=!1,i=0;for(let a of e){if(a.status===`pending`){r=!0;continue}if(a.status===`error`){n.push(a.deviceName);continue}if(a.data===null||a.data===void 0)continue;let e=sn.safeParse(a.data);if(!e.success){n.push(a.deviceName);continue}i+=1;for(let n of Zt(e.data)){let e=t.get(n.id);e===void 0?t.set(n.id,{label:n.label,devices:[a.deviceName]}):e.devices.includes(a.deviceName)||t.set(n.id,{label:e.label,devices:[...e.devices,a.deviceName]})}}let a=i>1;return{options:[...t.entries()].map(([e,t])=>a?{value:e,label:t.label,hint:t.devices.join(`, `)}:{value:e,label:t.label}),pending:r,unknownDevices:n,eventDeviceCount:i}}function bf(e,t,n){let r=new Set(t.map(e=>e.id)),i=new Map((n??[]).map(e=>[e.id,e.name]));return e.filter(e=>!r.has(e)).map(e=>({deviceId:e,deviceName:i.get(e)??`#${e}`}))}O();function xf(e,t){let n=V().trpcClient,r=k({queries:e.map(e=>({queryKey:[[`nc-pickers`,`zones`],{deviceId:e}],staleTime:3e4,queryFn:async()=>({deviceId:e,zones:(await n.zones.listZones.query({deviceId:e})).map(e=>({id:e.id,name:e.name}))})}))});return m(()=>{let e=[],n=new Set;for(let i of r){if(!i.data)continue;let r=t.find(e=>e.id===i.data.deviceId)?.name;for(let t of i.data.zones)n.has(t.id)||(n.add(t.id),e.push({value:t.id,label:t.name,...r===void 0?{}:{hint:r}}))}return{options:e,loading:r.some(e=>e.isLoading),failed:r.some(e=>e.isError)}},[r,t])}function Sf(e){let t=V().trpcClient,n=k({queries:e.map(e=>({queryKey:[[`nc-pickers`,`event-kinds`],{deviceId:e}],staleTime:6e4,queryFn:async()=>(await t.pipelineAnalytics.listEventKinds.query({deviceId:e})).map(e=>({kind:e.kind,label:e.label}))}))});return m(()=>{let e=new Map;for(let t of n)for(let n of t.data??[])e.has(n.kind)||e.set(n.kind,n.label);let t=[...e.entries()].map(([e,t])=>({value:e,label:t}));return t.sort((e,t)=>e.label.localeCompare(t.label)),{options:t,loading:n.some(e=>e.isLoading)}},[n])}function Cf(e){let t=V().trpcClient,n=k({queries:e.map(({deviceId:e})=>({queryKey:[[`nc-pickers`,`declared-events`],{deviceId:e}],staleTime:3e4,queryFn:async()=>t.deviceState.getCapSlice.query({deviceId:e,capName:vf})}))});return m(()=>yf(e.map((e,t)=>({...e,status:n[t]?.status??`pending`,data:n[t]?.data}))),[e,n])}function wf(){let e=Fi();return m(()=>({options:(e.data??[]).map(e=>({value:e.id,label:e.name})),loading:e.isLoading,failed:e.isError===!0}),[e.data,e.isLoading,e.isError])}function Tf(){let e=fi({limit:200}),t=xr();return m(()=>{let n=new Set;for(let e of t.data??[])e.name.trim().length>0&&n.add(e.name);let r=new Set;for(let t of e.data??[])t.text.trim().length>0&&r.add(t.text);return[...[...n].sort(),...[...r].sort()]},[e.data,t.data])}function Ef({options:e,value:t,onChange:n,loading:r,emptyHint:i,placeholder:a,noFreeText:o=!1}){let{t:c}=q(),[l,u]=w(``),d=m(()=>new Set(e.map(e=>e.value)),[e]),f=m(()=>new Set(t),[t]),p=t.filter(e=>!d.has(e)),h=e=>{n(f.has(e)?t.filter(t=>t!==e):[...t,e])},g=()=>{let e=l.trim();e.length===0||t.includes(e)||(n([...t,e]),u(``))};return s(`div`,{className:`mt-1 space-y-1.5`,children:[p.length>0&&x(`div`,{className:`flex flex-wrap gap-1`,children:p.map(e=>s(G,{variant:`unstyled`,type:`button`,onClick:()=>n(t.filter(t=>t!==e)),className:`inline-flex items-center gap-1 rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground hover:bg-surface-hover`,title:c(`system.notificationRulePickers.customValueClickToRemove`,`Custom value — click to remove`),children:[e,` ×`]},e))}),e.length>0?x(`div`,{className:`max-h-40 overflow-y-auto rounded-md border border-border divide-y divide-border`,children:e.map(e=>s(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[x(L,{checked:f.has(e.value),onChange:()=>h(e.value),className:`accent-primary`}),x(`span`,{className:`flex-1 truncate`,children:e.label}),e.hint!==void 0&&x(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.hint})]},e.value))}):x(`p`,{className:`text-[10px] text-foreground-subtle`,children:r===!0?c(`common.loading`,`Loading…`):i}),!o&&x(W,{value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),g())},placeholder:a,className:`w-full rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground placeholder:text-foreground-subtle`})]})}var Df=[{value:`immediate`,get label(){return K.t(`helpers.ruleFormParsers.immediate`)},get hint(){return K.t(`helpers.ruleFormParsers.immediateHint`)}},{value:`track-end`,get label(){return K.t(`helpers.ruleFormParsers.trackEnd`)},get hint(){return K.t(`helpers.ruleFormParsers.trackEndHint`)}},{value:`device-event`,get label(){return K.t(`helpers.ruleFormParsers.deviceEvent`)},get hint(){return K.t(`helpers.ruleFormParsers.deviceEventHint`)}},{value:`package-event`,get label(){return K.t(`helpers.ruleFormParsers.packageEvent`)},get hint(){return K.t(`helpers.ruleFormParsers.packageEventHint`)}},{value:`system-event`,get label(){return K.t(`helpers.ruleFormParsers.systemEvent`)},get hint(){return K.t(`helpers.ruleFormParsers.systemEventHint`)}}],Of=`Immediate, grouped`,kf=Df.flatMap(e=>e.value===`immediate`?[e,{value:`immediate-grouped`,get label(){return K.t(`notificationRules.grouping.choice`)},get hint(){return K.t(`helpers.ruleFormParsers.groupedHint`)}}]:[e]);function Af(e){return e.groupingSec!==void 0&&Gt(e)?`immediate-grouped`:e.delivery}function jf(e){let t=(e.delivery===`immediate`||e.delivery===`track-end`)&&Gt({delivery:`immediate`,conditions:e.conditions});return kf.filter(e=>e.value!==`immediate-grouped`||t)}function Mf(e){return kf.find(t=>t.value===e)?.value}function Nf(e,t=Of){return Af(e)===`immediate-grouped`?`${t} · ${String(e.groupingSec)} s`:Ff(e.delivery)}function Pf(e){if(e.trim().length===0)return;let t=Number(e);return Number.isFinite(t)&&t>=0?Math.trunc(t):void 0}function Ff(e){return Df.find(t=>t.value===e)?.label??e}function If(e){return Df.some(t=>t.value===e)}var Lf=[{key:`all`,get label(){return K.t(`helpers.ruleFormParsers.sec_all_label`)},get blurb(){return K.t(`helpers.ruleFormParsers.sec_all_blurb`)},get newRuleLabel(){return K.t(`helpers.ruleFormParsers.sec_all_new`)},get emptyHint(){return K.t(`helpers.ruleFormParsers.sec_all_empty`)},creatable:!0},{key:`detection`,get label(){return K.t(`helpers.ruleFormParsers.sec_detection_label`)},get blurb(){return K.t(`helpers.ruleFormParsers.sec_detection_blurb`)},get newRuleLabel(){return K.t(`helpers.ruleFormParsers.sec_detection_new`)},get emptyHint(){return K.t(`helpers.ruleFormParsers.sec_detection_empty`)},creatable:!0},{key:`sensor`,get label(){return K.t(`helpers.ruleFormParsers.sec_sensor_label`)},get blurb(){return K.t(`helpers.ruleFormParsers.sec_sensor_blurb`)},get newRuleLabel(){return K.t(`helpers.ruleFormParsers.sec_sensor_new`)},get emptyHint(){return K.t(`helpers.ruleFormParsers.sec_sensor_empty`)},creatable:!0},{key:`audio`,get label(){return K.t(`helpers.ruleFormParsers.sec_audio_label`)},get blurb(){return K.t(`helpers.ruleFormParsers.sec_audio_blurb`)},get newRuleLabel(){return K.t(`helpers.ruleFormParsers.sec_audio_new`)},get emptyHint(){return K.t(`helpers.ruleFormParsers.sec_audio_empty`)},creatable:!0},{key:`occupancy`,get label(){return K.t(`helpers.ruleFormParsers.sec_occupancy_label`)},get blurb(){return K.t(`helpers.ruleFormParsers.sec_occupancy_blurb`)},get newRuleLabel(){return K.t(`helpers.ruleFormParsers.sec_occupancy_new`)},get emptyHint(){return K.t(`helpers.ruleFormParsers.sec_occupancy_empty`)},creatable:!0},{key:`device-events`,get label(){return K.t(`helpers.ruleFormParsers.sec_deviceEvents_label`)},get blurb(){return K.t(`helpers.ruleFormParsers.sec_deviceEvents_blurb`)},get newRuleLabel(){return K.t(`helpers.ruleFormParsers.sec_deviceEvents_new`)},get emptyHint(){return K.t(`helpers.ruleFormParsers.sec_deviceEvents_empty`)},creatable:!0},{key:`system`,get label(){return K.t(`helpers.ruleFormParsers.sec_system_label`)},get blurb(){return K.t(`helpers.ruleFormParsers.sec_system_blurb`)},get newRuleLabel(){return K.t(`helpers.ruleFormParsers.sec_system_new`)},get emptyHint(){return K.t(`helpers.ruleFormParsers.sec_system_empty`)},creatable:!0},{key:`alarm`,get label(){return K.t(`helpers.ruleFormParsers.sec_alarm_label`)},get blurb(){return K.t(`helpers.ruleFormParsers.sec_alarm_blurb`)},get newRuleLabel(){return K.t(`helpers.ruleFormParsers.sec_alarm_new`)},get emptyHint(){return K.t(`helpers.ruleFormParsers.sec_alarm_empty`)},creatable:!0},{key:`mixed`,get label(){return K.t(`helpers.ruleFormParsers.sec_mixed_label`)},get blurb(){return K.t(`helpers.ruleFormParsers.sec_mixed_blurb`)},get newRuleLabel(){return K.t(`helpers.ruleFormParsers.sec_mixed_new`)},get emptyHint(){return K.t(`helpers.ruleFormParsers.sec_mixed_empty`)},creatable:!1}];function Rf(e){return Mt(Jt(e)).editable}function zf(e){return Dt(Bf(e))}function Bf(e){switch(e){case`device-events`:case`system`:case`alarm`:case`mixed`:return e;default:return}}var Vf=new Map([[0,`helpers.ruleFormParsers.cdNone`],[60,`helpers.ruleFormParsers.cd1m`],[3600,`helpers.ruleFormParsers.cd1h`]]),Hf=86400;function Uf(e){let t=Vf.get(e);return t===void 0?e%3600==0?K.t(`helpers.ruleFormParsers.cdHours`,{count:e/3600}):e%60==0?K.t(`helpers.ruleFormParsers.cdMinutes`,{count:e/60}):K.t(`helpers.ruleFormParsers.cdSeconds`,{count:e}):K.t(t)}function Wf(e){if(e.trim().length===0)return;let t=Number(e);return Number.isFinite(t)&&t>=0?Math.trunc(t):void 0}var Gf=[{value:`rule-device`,get label(){return K.t(`helpers.ruleFormParsers.scopeDevice`)}},{value:`rule`,get label(){return K.t(`helpers.ruleFormParsers.scopeRule`)}}];function Kf(e){return Gf.find(t=>t.value===e)?.value}var qf=[{value:`per-class`,get label(){return K.t(`helpers.ruleFormParsers.granPerClass`)}},{value:`shared`,get label(){return K.t(`helpers.ruleFormParsers.granShared`)}}];function Jf(e){return qf.find(t=>t.value===e)?.value}var Yf=[{value:`scene-boxes`,get label(){return K.t(`helpers.ruleFormParsers.imageSceneBoxes`)},get description(){return K.t(`helpers.ruleFormParsers.imageSceneBoxesDesc`)}},{value:`crop`,get label(){return K.t(`helpers.ruleFormParsers.imageCrop`)},get description(){return K.t(`helpers.ruleFormParsers.imageCropDesc`)}},{value:`clean`,get label(){return K.t(`helpers.ruleFormParsers.imageClean`)},get description(){return K.t(`helpers.ruleFormParsers.imageCleanDesc`)}},{value:`none`,get label(){return K.t(`helpers.ruleFormParsers.imageNone`)},get description(){return K.t(`helpers.ruleFormParsers.imageNoneDesc`)}}];function Xf(e){return Yf.find(t=>t.value===e)?.value}var Zf=[{value:``,get label(){return K.t(`helpers.ruleFormParsers.linkedDefault`)}},{value:`mosaic`,get label(){return K.t(`helpers.ruleFormParsers.linkedMosaic`)}},{value:`each`,get label(){return K.t(`helpers.ruleFormParsers.linkedEach`)}}];function Qf(e){let t=Zf.find(t=>t.value===e)?.value;return t===``?void 0:t}var $f=[{value:``,get label(){return K.t(`helpers.ruleFormParsers.profileLowest`)}},{value:`low`,get label(){return K.t(`helpers.ruleFormParsers.profileLow`)}},{value:`mid`,get label(){return K.t(`helpers.ruleFormParsers.profileMid`)}},{value:`high`,get label(){return K.t(`helpers.ruleFormParsers.profileHigh`)}}];function ep(e){let t=$f.find(t=>t.value===e)?.value;return t===``?void 0:t}var tp=[{value:`any`,get label(){return K.t(`helpers.ruleFormParsers.srcAny`)}},{value:`pipeline`,get label(){return K.t(`helpers.ruleFormParsers.srcPipeline`)}},{value:`onboard`,get label(){return K.t(`helpers.ruleFormParsers.srcOnboard`)}},{value:`sensor`,get label(){return K.t(`helpers.ruleFormParsers.srcSensor`)}}],np=[{value:`delivered`,get label(){return K.t(`helpers.ruleFormParsers.phaseDelivered`)}},{value:`picked-up`,get label(){return K.t(`helpers.ruleFormParsers.phasePickedUp`)}},{value:`both`,get label(){return K.t(`helpers.ruleFormParsers.phaseBoth`)}}],rp=[{value:``,get label(){return K.t(`helpers.ruleFormParsers.stBoth`)}},{value:`raised`,get label(){return K.t(`helpers.ruleFormParsers.stRaised`)}},{value:`cleared`,get label(){return K.t(`helpers.ruleFormParsers.stCleared`)}}];function ip(e){return e===`raised`||e===`cleared`?e:void 0}function ap(e,t){return e===`sensorTransition`?kn(t.sensorKinds):!0}var op=[{value:`enter`,get label(){return K.t(`helpers.ruleFormParsers.crossEnter`)}},{value:`exit`,get label(){return K.t(`helpers.ruleFormParsers.crossExit`)}},{value:`any`,get label(){return K.t(`helpers.ruleFormParsers.crossAny`)}}],sp=`enter`;function cp(e){return e===`exit`||e===`any`?e:void 0}var lp=[{value:1,get label(){return K.t(`helpers.ruleFormParsers.prioMin`)}},{value:2,get label(){return K.t(`helpers.ruleFormParsers.prioLow`)}},{value:3,get label(){return K.t(`helpers.ruleFormParsers.prioDefault`)}},{value:4,get label(){return K.t(`helpers.ruleFormParsers.prioHigh`)}},{value:5,get label(){return K.t(`helpers.ruleFormParsers.prioMax`)}}];function up(e,t){return e.options&&e.options.length>0?e.options:t}var dp=[{value:``,get label(){return K.t(`helpers.ruleFormParsers.speedDefault`)}},{value:`1`,get label(){return K.t(`helpers.ruleFormParsers.speedReal`)}},{value:`2`,label:`2×`},{value:`3`,label:`3×`},{value:`4`,label:`4×`},{value:`6`,label:`6×`},{value:`8`,label:`8×`}];function fp(e){if(e===``)return;let t=Number(e);return Number.isFinite(t)&&t>=1&&t<=8?t:void 0}var pp={days:[0,1,2,3,4,5,6],minute:480},mp=[{value:1,get label(){return K.t(`helpers.notificationSystemEventDelivery.wd_mon`)}},{value:2,get label(){return K.t(`helpers.notificationSystemEventDelivery.wd_tue`)}},{value:3,get label(){return K.t(`helpers.notificationSystemEventDelivery.wd_wed`)}},{value:4,get label(){return K.t(`helpers.notificationSystemEventDelivery.wd_thu`)}},{value:5,get label(){return K.t(`helpers.notificationSystemEventDelivery.wd_fri`)}},{value:6,get label(){return K.t(`helpers.notificationSystemEventDelivery.wd_sat`)}},{value:0,get label(){return K.t(`helpers.notificationSystemEventDelivery.wd_sun`)}}];function hp(e){let t=Math.floor(e/60),n=e%60;return`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}`}function gp(e){let[t,n]=e.split(`:`),r=Number(t)*60+Number(n);return Number.isFinite(r)?Math.max(0,Math.min(1439,r)):0}var _p={mode:`modes`,onActivation:!0,onDeactivation:!1};function vp(e){return e!==void 0&&Ht.includes(e)}function yp(e,t){return Rt({conditions:t.length>0?{systemEvent:{kinds:[...t]}}:{},...e===void 0?{}:{systemEventDelivery:e}})}function bp(e){return{mode:`modes`,onActivation:e.onActivation,onDeactivation:e.onDeactivation}}function xp(e,t,n){return t===`activation`?{...e,onActivation:n}:t===`deactivation`?{...e,onDeactivation:n}:n?e.onSchedule===void 0?{...e,onSchedule:{schedule:Ot([pp]),grouping:`section`}}:e:bp(e)}function Sp(e,t){return{...e,onSchedule:{schedule:t,grouping:e.onSchedule?.grouping??`section`}}}function Cp(e,t){return e.onSchedule===void 0?e:{...e,onSchedule:{...e.onSchedule,grouping:t}}}function wp(e){let t=new Set,n=0;for(let r of e){let e=Ln(r);e===void 0?n+=1:t.add(e.label)}return{adds:[...t],without:n}}function Tp(e){if(typeof e!=`object`||!e||!(`data`in e))return;let t=e.data;if(!(typeof t!=`object`||!t||!(`code`in t)))return typeof t.code==`string`?t.code:void 0}function Ep(e){let t=Object.entries(e).map(([e,t])=>`${e} ${String(t)}`);return t.length>0?K.t(`helpers.notificationSystemEventDelivery.dropped`,{parts:t.join(`, `)}):null}function Dp(e,t,n,r=`rule`){if(e===`error`)return Tp(n)===`NOT_FOUND`?{lines:[`This hub does not serve summary rules yet — update @camstack/server first. A rule saved now would be stored without its summary, and stay instant.`]}:{lines:[`The preview could not be read: ${n instanceof Error?n.message:String(n)}`]};if(e!==`success`||t===void 0)return null;let i=[];if(r===`section`&&t.split===void 0&&i.push(`This hub does not send per-category summaries yet — update @camstack/server first. Until then it sends one message.`),t.empty)i.push(`Nothing to report right now — no notification would be sent.`);else if(t.split===`section`&&t.rows!==void 0){let e=t.rows.length;i.push(`${String(e)} notification${e===1?``:`s`} would be sent now, one per category:`);for(let e of t.rows)i.push(`${e.title}\n${e.text}`)}else i.push(`${String(t.count)} item(s) would be sent now:\n${t.text}`);let a=Ep(t.dropped);return a!==null&&i.push(a),t.excludedGroups.includes(`backups-exports`)&&i.push(`Backups and exports are completed jobs, not a state — they are not in a summary.`),{lines:i}}var Op=`notificationRules.systemEventKinds.`,kp=`notificationRules.systemEventGroups.`,Ap=`notificationRules.systemEventHints.`;function jp(e){return!yn.some(t=>t===e)}function Mp(e){let t=`${Op}${e}`;return K.exists(t)?K.t(t):e}function Np(){return Lt.map(e=>({id:e.id,family:e.family,label:K.t(`${kp}${e.id}`,e.label),hint:K.t(`${Ap}${e.id}`),kinds:e.kinds.filter(jp).map(e=>({value:e,label:Mp(e)}))}))}function Pp(e){return Np().filter(t=>t.family===e)}function Fp(e){let t=Wt(e).conditions.systemEvent;return t===void 0?{kinds:(Pp(e)[0]?.kinds??[]).map(e=>e.value)}:{...t,kinds:[...t.kinds]}}function Ip(){return Np().flatMap(e=>e.kinds)}function Lp(e){return{devices:Ft(e,`deviceIds`),deviceTypes:Ft(e,`deviceTypes`),nodes:Ft(e,`nodeIds`),packages:Ft(e,`packageNames`),consumableThreshold:Ft(e,`consumableLowPercent`),commandActions:Ft(e,`commandActions`),commandOutcomes:Ft(e,`commandOutcomes`),commandActorKinds:Ft(e,`commandActorKinds`)}}function Rp(e,t){let n=an[e],r=Lp(t);return{devices:n.includes(`deviceIds`)&&r.devices,excludeDevices:n.includes(`excludeDeviceIds`)&&r.devices,deviceTypes:n.includes(`deviceTypes`)&&r.deviceTypes,nodes:n.includes(`nodeIds`)&&r.nodes,packages:n.includes(`packageNames`)&&r.packages,consumableThreshold:n.includes(`consumableLowPercent`)&&r.consumableThreshold,commandActions:n.includes(`commandActions`)&&r.commandActions,commandOutcomes:n.includes(`commandOutcomes`)&&r.commandOutcomes,commandActorKinds:n.includes(`commandActorKinds`)&&r.commandActorKinds}}var zp=Object.values(U).map(e=>({value:e,label:Bp(e)})).toSorted((e,t)=>e.label.localeCompare(t.label));function Bp(e){let t=e.replaceAll(`-`,` `);return t.charAt(0).toUpperCase()+t.slice(1)}function Vp(e,t){let n=[],r=new Set;for(let i of e.kinds){let e=Ln(i.value);if(e===void 0){n.push({key:i.value,label:i.label,kinds:[i.value],clears:[i.value]});continue}r.has(e.id)||(r.add(e.id),n.push({key:`class:${e.id}`,label:t?e.snapshotLabel:e.label,kinds:t?[...e.bad]:Bt(e),clears:Bt(e),classId:e.id,...t&&e.snapshotSection===null?{noSnapshot:!0}:{}}))}return n}function Hp(e,t){return t.clears.some(t=>e.includes(t))}function Up(e,t,n){if(!Pp(n).some(e=>e.kinds.some(e=>t.kinds.includes(e.value))))return e;let r=e?.kinds??[];if(Hp(r,t)){let i=r.filter(e=>!t.clears.includes(e));return i.length===0?e:qp(e,i,n)}return qp(e,Ip().filter(e=>t.kinds.includes(e.value)||r.includes(e.value)).map(e=>e.value),n)}function Wp(e,t){return t===void 0?void 0:qp(t,t.kinds,e)}function Gp(e,t){let n=e?.kinds??[];if(n.length===0)return;let r=Kp(t,`deviceIds`,e?.deviceIds),i=Kp(t,`excludeDeviceIds`,e?.excludeDeviceIds),a=Kp(t,`deviceTypes`,e?.deviceTypes),o=Kp(t,`nodeIds`,e?.nodeIds),s=Kp(t,`packageNames`,e?.packageNames),c=Object.prototype.hasOwnProperty.call(t,`consumableLowPercent`)?t.consumableLowPercent:e?.consumableLowPercent;return{kinds:[...n],...r===void 0?{}:{deviceIds:[...r]},...i===void 0?{}:{excludeDeviceIds:[...i]},...a===void 0?{}:{deviceTypes:[...a]},...o===void 0?{}:{nodeIds:[...o]},...s===void 0?{}:{packageNames:[...s]},...c===void 0?{}:{consumableLowPercent:c}}}function Kp(e,t,n){let r=Object.prototype.hasOwnProperty.call(e,t)?e[t]:n;return r!==void 0&&r.length===0?void 0:r}function qp(e,t,n){let r=Rp(n,t),i=r.devices?e?.deviceIds:void 0,a=r.excludeDevices?e?.excludeDeviceIds:void 0,o=r.deviceTypes?e?.deviceTypes:void 0,s=r.nodes?e?.nodeIds:void 0,c=r.packages?e?.packageNames:void 0,l=r.consumableThreshold?e?.consumableLowPercent:void 0;return{kinds:[...t],...i&&i.length>0?{deviceIds:[...i]}:{},...a&&a.length>0?{excludeDeviceIds:[...a]}:{},...o&&o.length>0?{deviceTypes:[...o]}:{},...s&&s.length>0?{nodeIds:[...s]}:{},...c&&c.length>0?{packageNames:[...c]}:{},...l===void 0?{}:{consumableLowPercent:l}}}var Jp=95;function Yp(e){let t=e.trim();if(t===``)return{kind:`clear`};let n=Number(t);return Number.isInteger(n)&&n>=1&&n<=Jp?{kind:`set`,value:n}:{kind:`invalid`}}function Xp(e,t=2){if(e===void 0||e.length===0)return K.t(`helpers.notificationSystemEvents.noneSelected`);let n=e.slice(0,t).map(Mp).join(`, `),r=e.length-Math.min(t,e.length);return r>0?`${n} +${r}`:n}function Zp(e){if(e===void 0)return`—`;let t=[],n=e.deviceIds?.length??0,r=e.deviceTypes?.length??0,i=e.nodeIds?.length??0,a=e.packageNames?.length??0,o=e.excludeDeviceIds?.length??0;r>0&&t.push(e.deviceTypes?.map(Bp).join(`, `)??``),n>0&&t.push(`${n} device${n===1?``:`s`}`),i>0&&t.push(`${i} node${i===1?``:`s`}`),a>0&&t.push(`${a} package${a===1?``:`s`}`);let s=o>0?`except ${o} device${o===1?``:`s`}`:null,c=e.consumableLowPercent===void 0?[]:[`consumables at ${e.consumableLowPercent}%`];return t.length===0?[s===null?`Everything`:`Everything ${s}`,...c].join(` · `):[...t,...s===null?[]:[s],...c].join(` · `)}function Qp(e){return e===void 0||(e.deviceTypes?.length??0)===0?!1:e.kinds.some(e=>Fn.includes(e))}var $p=[`all`,`only`,`except`];function em(e,t){return(e??[]).length>0?`only`:(t??[]).length>0?`except`:`all`}function tm(e,t){let n=[...e??[]],r=[...t??[]];return{mode:em(n,r),include:n,exclude:r,legacyBoth:n.length>0&&r.length>0}}function nm(e,t){return{...e,mode:t}}function rm(e){switch(e.mode){case`only`:return e.include;case`except`:return e.exclude;case`all`:return[]}}function im(e,t){switch(e.mode){case`only`:return{...e,include:[...t]};case`except`:return{...e,exclude:[...t]};case`all`:return e}}function am(e){return e.mode===`only`&&e.legacyBoth?e.exclude:[]}function om(e){return{...e,exclude:[],legacyBoth:!1}}function sm(e){switch(e.mode){case`all`:return{};case`except`:return e.exclude.length>0?{exclude:[...e.exclude]}:{};case`only`:{let t=am(e);return{...e.include.length>0?{include:[...e.include]}:{},...t.length>0?{exclude:[...t]}:{}}}}}function cm(e){let t=sm(e),n=t.include??[],r=t.exclude??[];return[...e.include.filter(e=>!n.includes(e)),...e.exclude.filter(e=>!r.includes(e))]}var lm=[`onActivation`,`onDeactivation`,`onTrigger`,`onTriggerOff`],um={onActivation:{get title(){return K.t(`helpers.notificationRuleActions.onActivationTitle`)},get hint(){return K.t(`helpers.notificationRuleActions.onActivationHint`)}},onDeactivation:{get title(){return K.t(`helpers.notificationRuleActions.onDeactivationTitle`)},get hint(){return K.t(`helpers.notificationRuleActions.onDeactivationHint`)}},onTrigger:{get title(){return K.t(`helpers.notificationRuleActions.onTriggerTitle`)},get hint(){return K.t(`helpers.notificationRuleActions.onTriggerHint`)}},onTriggerOff:{get title(){return K.t(`helpers.notificationRuleActions.onTriggerOffTitle`)},get hint(){return K.t(`helpers.notificationRuleActions.onTriggerOffHint`)}}},dm={onActivation:[],onDeactivation:[],onTrigger:[],onTriggerOff:[],buttons:[]};function fm(e){return e===void 0?dm:{onActivation:[...e.onActivation??[]],onDeactivation:[...e.onDeactivation??[]],onTrigger:[...e.onTrigger??[]],onTriggerOff:[...e.onTriggerOff??[]],buttons:[...e.buttons??[]]}}function pm(e){let t=e.buttons.filter(e=>e.id.trim()!==``&&e.label.trim()!==``&&e.actionId.trim()!==``),n=e=>e.filter(e=>e.trim()!==``),r={onActivation:n(e.onActivation),onDeactivation:n(e.onDeactivation),onTrigger:n(e.onTrigger),onTriggerOff:n(e.onTriggerOff)};if(!(!lm.some(e=>r[e].length>0)&&t.length===0))return{...r.onActivation.length>0?{onActivation:[...r.onActivation]}:{},...r.onDeactivation.length>0?{onDeactivation:[...r.onDeactivation]}:{},...r.onTrigger.length>0?{onTrigger:[...r.onTrigger]}:{},...r.onTriggerOff.length>0?{onTriggerOff:[...r.onTriggerOff]}:{},...t.length>0?{buttons:t}:{}}}function mm(e,t){let n=[];for(let r of lm){let i=e[r];i.length>4&&n.push({kind:`too-many`,message:K.t(`helpers.notificationRuleActions.tooMany`,{title:um[r].title})}),i.some(e=>e.trim()!==``&&!t.has(e))&&n.push({kind:`unknown-action`,message:K.t(`helpers.notificationRuleActions.hookUnknownAction`,{title:um[r].title})})}let r=new Set;for(let i of e.buttons){let e=i.id.trim();e!==``&&(r.has(e)&&n.push({kind:`duplicate-button`,message:K.t(`helpers.notificationRuleActions.dupButton`,{id:e})}),r.add(e),t.has(i.actionId.trim())||n.push({kind:`unknown-action`,message:K.t(`helpers.notificationRuleActions.buttonUnknownAction`,{label:i.label||e})}))}return n}function hm(e,t){return{id:`action-${String(e+1)}`,label:K.t(`helpers.notificationRuleActions.newButtonLabel`),actionId:t}}var gm=[{value:`acknowledge`,get label(){return K.t(`helpers.notificationRuleActions.icon_acknowledge`)}},{value:`dismiss`,get label(){return K.t(`helpers.notificationRuleActions.icon_dismiss`)}},{value:`silence`,get label(){return K.t(`helpers.notificationRuleActions.icon_silence`)}},{value:`snooze`,get label(){return K.t(`helpers.notificationRuleActions.icon_snooze`)}},{value:`view`,get label(){return K.t(`helpers.notificationRuleActions.icon_view`)}},{value:`play`,get label(){return K.t(`helpers.notificationRuleActions.icon_play`)}},{value:`camera`,get label(){return K.t(`helpers.notificationRuleActions.icon_camera`)}},{value:`open`,get label(){return K.t(`helpers.notificationRuleActions.icon_open`)}},{value:`close`,get label(){return K.t(`helpers.notificationRuleActions.icon_close`)}},{value:`unlock`,get label(){return K.t(`helpers.notificationRuleActions.icon_unlock`)}},{value:`lock`,get label(){return K.t(`helpers.notificationRuleActions.icon_lock`)}},{value:`disarm`,get label(){return K.t(`helpers.notificationRuleActions.icon_disarm`)}},{value:`arm`,get label(){return K.t(`helpers.notificationRuleActions.icon_arm`)}},{value:`arm-home`,get label(){return K.t(`helpers.notificationRuleActions.icon_arm_home`)}},{value:`arm-away`,get label(){return K.t(`helpers.notificationRuleActions.icon_arm_away`)}},{value:`arm-night`,get label(){return K.t(`helpers.notificationRuleActions.icon_arm_night`)}},{value:`light`,get label(){return K.t(`helpers.notificationRuleActions.icon_light`)}},{value:`alert`,get label(){return K.t(`helpers.notificationRuleActions.icon_alert`)}}];function _m(e){let t=new Set;for(let n of lm)for(let r of e[n])r.trim()!==``&&t.add(r);for(let n of e.buttons)n.actionId.trim()!==``&&t.add(n.actionId);return t}function vm(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[];for(let t of _m(e))r.push(...n.get(t)?.steps??[]);return r}var ym=[10,30,60],bm=[5,10,15,30,60,120,240,480];function xm(e){return e>=60&&e%60==0?K.t(`helpers.ruleFormState.snoozeHours`,{count:e/60}):K.t(`helpers.ruleFormState.snoozeMin`,{count:e})}var Sm=new Set([`alarm-arm-refused`,`alarm-check-failed`,`alarm-arming`,`alarm-armed`,`alarm-pending`,`alarm-triggered`,`alarm-rearmed`,`alarm-sensor-bypass`,`alarm-disarmed`]);function Cm(e,t){for(let t of e.systemEvent?.kinds??[])if(Sm.has(t))return!0;for(let e of t)if(Tn(e))return!0;return!1}function wm(e,t){return vm(e,t)}function Tm(e){let{devices:t,devicesExclude:n,classes:r,classesExclude:i,...a}=e;return{conditions:a,deviceScope:tm(t,n),classScope:tm(r,i)}}function Em(e){let t=sm(e.deviceScope),n=sm(e.classScope);return{...e.conditions,...t.include===void 0?{}:{devices:[...t.include]},...t.exclude===void 0?{}:{devicesExclude:[...t.exclude]},...n.include===void 0?{}:{classes:[...n.include]},...n.exclude===void 0?{}:{classesExclude:[...n.exclude]}}}function Dm(e){return e.deviceScope.mode===`only`?e.deviceScope.include:[]}function Om(e,t,n){let r=Jt(n);return e.some(e=>e.id===t&&At(e,n.delivery,r))}function km(e=`immediate`,t={}){return{name:``,tags:[],enabled:!0,delivery:e,targetIds:[],targetUsers:[],targetParams:{},targetOverrides:{},priority:3,mediaImage:$t({},Jt({delivery:e,conditions:t})),mediaShowTriggerZone:!1,mediaShowSubjectPath:!1,mediaGif:!1,mediaClip:!1,mediaProfile:void 0,mediaClipSpeed:void 0,mediaLinkedCameras:void 0,mediaWakeSleepingCamera:void 0,templateTitle:``,templateBody:``,...Tm(t),schedule:void 0,systemEventDelivery:e===`system-event`?_p:void 0,snoozeAllowGlobal:!1,groupingSec:void 0,groupWithinSec:en({delivery:e}),snoozeOptions:void 0,askVerdict:void 0,actions:dm,cooldownSec:30,cooldownScope:`rule-device`,cooldownGranularity:void 0}}function Am(e){let t={};for(let n of e.targets)n.params&&Object.keys(n.params).length>0&&(t[n.targetId]=n.params);return{name:e.name,tags:e.tags??[],enabled:e.enabled,delivery:e.delivery,targetIds:e.targets.map(e=>e.targetId),targetUsers:e.targetUsers??[],targetParams:t,targetOverrides:e.targetOverrides??{},priority:e.priority,mediaImage:$t(e.media,Jt(e)),mediaShowTriggerZone:e.media.showTriggerZone===!0,mediaShowSubjectPath:e.media.showSubjectPath===!0,mediaGif:e.media.gif===!0,mediaClip:e.media.clip===!0,mediaProfile:e.media.profile,mediaClipSpeed:e.media.clipSpeed,mediaLinkedCameras:e.media.linkedCameras,mediaWakeSleepingCamera:e.media.wakeSleepingCamera,templateTitle:e.template?.title??``,templateBody:e.template?.body??``,...Tm(e.conditions),schedule:e.schedule,systemEventDelivery:e.systemEventDelivery,snoozeAllowGlobal:e.snoozeAllowGlobal===!0,groupingSec:e.groupingSec,groupWithinSec:en(e),snoozeOptions:e.snoozeOptions,askVerdict:e.askVerdict,actions:fm(e.actions),cooldownSec:e.throttle.cooldownSec,cooldownScope:e.throttle.scope,cooldownGranularity:e.throttle.granularity}}function jm(e,t){let n=[],r=e.groupWithinSec;if((!Number.isInteger(r)||r<0||r>300)&&n.push(`Group notifications within is a whole number of seconds between 0 and 300.`),Bm(e)){let r=e.groupingSec;r!==void 0&&(!Number.isInteger(r)||r<5||r>60)&&n.push(`The grouping window is a whole number of seconds between 5 and 60.`);let i=t?.confirm;i?.enabled===!0&&i.expect!==void 0&&!Vm(i.expect)&&n.push(`This rule’s AI confirm expects more than one subject, but a grouped message judges one picture per subject, so it would never send. Remove the confirm expectation (viewer or API), or choose Immediate.`)}if(Hn(e.conditions.audio)&&n.push(`This sound rule names neither a sound nor a level threshold, so it can never fire — every sample would count as a hit and the engine refuses it rather than notifying on silence. Pick at least one sound, or add a level.`),(!Number.isInteger(e.cooldownSec)||e.cooldownSec<0||e.cooldownSec>86400)&&n.push(`The cooldown is a whole number of seconds between 0 and ${String(Hf)} (24 hours). 0 means every match is delivered.`),An(e.delivery))for(let t of tn({delivery:e.delivery,conditions:e.conditions,...e.systemEventDelivery===void 0?{}:{systemEventDelivery:e.systemEventDelivery},...pm(e.actions)===void 0?{}:{actions:pm(e.actions)}}))n.push(Xt(t));return n}function Mm(e){let t=e.systemEventDelivery;if(t===void 0)return{};if(!An(e.delivery))return t.mode===`instant`?{}:{systemEventDelivery:{mode:`instant`}};let n=ln(e.conditions.systemEvent?.kinds??[]);if(!(n.kind===`family`&&Ht.includes(n.family)))return t.mode===`modes`?{}:{systemEventDelivery:t};let r=fn({systemEventDelivery:t}).schedule;if(r!==null&&It(r.schedule)===null){let e=rn(r.schedule);if(e!==null&&e.times.length>0){let n=Ot(e.times,r.schedule.timezone);if(t.mode===`modes`)return{systemEventDelivery:{...t,onSchedule:{...r,schedule:n}}};if(t.mode===`summary`)return{systemEventDelivery:{...t,schedule:n}}}}return{systemEventDelivery:t}}function Nm(e){if(!Pm(e))return null;if(!Nt(e.templateBody))return K.t(`helpers.ruleFormState.summaryWarnNone`,{token:`{{summaryText}}`});let t=e.templateBody;return on({...e.systemEventDelivery===void 0?{}:{systemEventDelivery:e.systemEventDelivery}})===`section`&&t.trim().length>0&&!/\{\{\s*summaryText\s*\}\}/.test(t)?K.t(`helpers.ruleFormState.summaryWarnSplit`,{token:`{{summaryText}}`}):null}function Pm(e){return Zn({delivery:e.delivery,...e.systemEventDelivery===void 0?{}:{systemEventDelivery:e.systemEventDelivery}})}function Fm(e,t,n=new Set){return jm(e,t).length===0&&If(e.delivery)&&(!An(e.delivery)||Gm(e)>0)&&Jt(e)!==`mixed`&&e.name.trim().length>0&&(e.targetIds.length>0||e.targetUsers.length>0)&&mm(e.actions,n).length===0}function Im(e,t){let n=Um(e.conditions,t),r=An(t)&&(n.systemEvent?.kinds.length??0)===0,i=An(t)&&e.systemEventDelivery===void 0?_p:e.systemEventDelivery;return r?{...e,delivery:t,systemEventDelivery:i,conditions:{...n,systemEvent:Fp(`device-events`)}}:{...e,delivery:t,conditions:n,systemEventDelivery:i}}function Lm(e,t){return t===`immediate-grouped`?Rm(e,{...Im(e,`immediate`),groupingSec:e.groupingSec??20}):Rm(e,{...Im(e,t),groupingSec:void 0})}function Rm(e,t){let n=en({delivery:e.delivery}),r=en({delivery:t.delivery}),i=e.groupWithinSec!==n;return{...t,groupWithinSec:i?e.groupWithinSec:r}}function zm(e){return e.delivery===`immediate`||e.delivery===`track-end`}function Bm(e){return e.groupingSec!==void 0&&Gt(e)}function Vm(e){switch(e.op){case`>`:return 1>e.count;case`<=`:return 1<=e.count;case`<`:return 1<e.count;case`==`:return e.count===1;default:return 1>=e.count}}var Hm=new Set([`immediate`,`track-end`,`package-event`]);function Um(e,t){if(e.source!==`pipeline`||Hm.has(t))return e;let{source:n,...r}=e;return r}function Wm(e,t){return $n(e.conditions.systemEvent)===t?e:{...e,conditions:{...e.conditions,systemEvent:Fp(t)}}}function Gm(e){return e.conditions.systemEvent?.kinds.length??0}function Km(e,t){return n=>{let r=e.find(e=>e.id===n);if(r===void 0)return;let i=t.find(e=>e.kind===r.kind&&e.addonId===r.addonId)?.caps;return i===void 0?void 0:Rn(i)}}function qm(e,t,n){let r=Km(t,n),i=zt(e.map(e=>({name:t.find(t=>t.id===e)?.name??e,fields:r(e)})));return new Map(i.map(e=>[e.field,e]))}function Jm(e,t,n){let r={};for(let i of e){let e=t[i];if(e===void 0)continue;let a=dn(e,n?.(i));a!==void 0&&(r[i]=a)}return r}function Ym(e,t,n){let{[t]:r,...i}=e;return n===void 0?i:{...i,[t]:n}}function Xm(e,t,n,r){let{[t]:i,...a}=e,{[n]:o,...s}=i??{},c=r===void 0?s:{...s,[n]:r};return Object.keys(c).length===0?a:{...a,[t]:c}}function Zm(e,t,n){let r=t.find(t=>t.id===e);if(r===void 0)return;let i=n.find(e=>e.kind===r.kind&&e.addonId===r.addonId)?.caps;if(i!==void 0)return{levels:pn(i),attachmentKinds:Vt(i)}}var Qm={rule:{fields:[`title`,`body`,`priority`,`attachments`,`actions`],attachmentKinds:[`none`,`image`,`clip`,`gif`]},summary:{fields:[`title`,`body`,`priority`,`attachments`],attachmentKinds:[`none`,`image`]},timelapse:{fields:[`title`,`body`,`priority`,`attachments`],attachmentKinds:[`none`,`image`,`clip`]},"calendar-events":{fields:[`title`,`body`,`priority`],attachmentKinds:[]}};function $m(e,t){return Qm[e].fields.includes(t)}function eh(e,t){let n=Qm[e].attachmentKinds;return t.filter(e=>n.includes(e))}function th(e){return e.map(e=>({id:e.id,name:e.name,enabled:e.enabled,kind:e.kind??``,addonId:e.addonId??``,config:{}}))}function nh(e,t){return e.appliesTo.includes(t)}var rh={source:`any`};function ih(e,t){if(t==null)return!0;if(Array.isArray(t))return t.length===0;if(typeof t==`string`)return t.length===0||rh[e]===t;if(typeof t==`number`)return!Number.isFinite(t);if(typeof t==`object`){if(`ids`in t){let e=t.ids;return!Array.isArray(e)||e.length===0}if(`values`in t){let e=t.values;return!Array.isArray(e)||e.length===0}return!1}return!1}var ah=Gn.filter(e=>e.id===`audio`);function oh(e){if(e.length===0)return e;let t=new Set(e.map(e=>e.id)),n=ah.filter(e=>!t.has(e.id));return n.length===0?e:[...e,...n]}function sh(e,t,n,r=Jt({delivery:t,conditions:e})){let i=n.length===0?null:new Set(n.filter(e=>e.id!==`schedule`&&At(e,t,r)).map(e=>e.id)),a={};for(let[t,n]of Object.entries(e))i!==null&&!i.has(t)||ap(t,e)&&(ih(t,n)||(a[t]=n));return a}function ch(e,t){if(e===void 0)return{};let n=Wp(e,t.systemEvent);return n===void 0?{}:{systemEvent:n}}function lh(e){return e!==void 0&&e.windows.length>0}function uh(e){let t={...e.clipPreRollSec===void 0?{}:{clipPreRollSec:e.clipPreRollSec},...e.clipPostRollSec===void 0?{}:{clipPostRollSec:e.clipPostRollSec}};return Object.keys(t).length>0?t:void 0}function dh(e){let t=uh(e.media);return{...e.confirm===void 0?{}:{confirm:e.confirm},...t===void 0?{}:{media:t}}}function fh(e,t,n=[],r){let i=e.templateTitle.trim(),a=e.templateBody.trim(),o=i.length>0||a.length>0?{...i.length>0?{title:i}:{},...a.length>0?{body:a}:{}}:void 0,s=pm(e.actions),c=Jt(e),l=Mt(c),u=Qt(c),d=n.length===0?!0:n.some(t=>t.id===`schedule`&&nh(t,e.delivery)),f=!Pm(e)&&d&&lh(e.schedule)?e.schedule:void 0,p=n.length===0?!0:n.some(t=>t.id===`devices`&&nh(t,e.delivery)),m=n.length===0?!0:n.some(t=>t.id===`devicesExclude`&&nh(t,e.delivery)),{devices:h,devicesExclude:g,..._}=Em(e),v=sh(_,e.delivery,n,c);return{name:e.name.trim(),tags:[...e.tags],enabled:e.enabled,delivery:e.delivery,conditions:{...v,...p&&h!==void 0?{devices:h}:{},...m&&g!==void 0?{devicesExclude:g}:{},...ch(u,e.conditions)},...f?{schedule:f}:{},...Mm(e),targets:e.targetIds.map(t=>{let n=e.targetParams[t];return n&&Object.keys(n).length>0?{targetId:t,params:n}:{targetId:t}}),...e.targetUsers.length>0?{targetUsers:[...e.targetUsers]}:{},targetOverrides:Jm(e.targetIds,e.targetOverrides,r),media:l.carriesMedia?{image:e.mediaImage,...e.mediaShowTriggerZone&&e.mediaImage!==`crop`&&e.mediaImage!==`none`&&kt(v).length>0?{showTriggerZone:!0}:{},...e.mediaShowSubjectPath&&e.mediaImage!==`none`&&Xn(c)?{showSubjectPath:!0}:{},...e.mediaGif?{gif:!0}:{},...e.mediaClip?{clip:!0}:{},...e.mediaProfile===void 0?{}:{profile:e.mediaProfile},...e.mediaClipSpeed===void 0?{}:{clipSpeed:e.mediaClipSpeed},...c===`sensor`&&e.mediaImage!==`none`&&e.mediaLinkedCameras!==void 0?{linkedCameras:e.mediaLinkedCameras}:{},...c===`sensor`&&e.mediaImage!==`none`&&e.mediaWakeSleepingCamera===!1?{wakeSleepingCamera:!1}:{},...(e.mediaGif||e.mediaClip)&&t?.media?.clipPreRollSec!==void 0?{clipPreRollSec:t.media.clipPreRollSec}:{},...(e.mediaGif||e.mediaClip)&&t?.media?.clipPostRollSec!==void 0?{clipPostRollSec:t.media.clipPostRollSec}:{}}:{image:`none`},throttle:{cooldownSec:e.cooldownSec,scope:e.cooldownScope,...e.cooldownGranularity===void 0?{}:{granularity:e.cooldownGranularity}},priority:e.priority,...o?{template:o}:{},...e.snoozeAllowGlobal?{snoozeAllowGlobal:!0}:{},...Bm(e)?{groupingSec:e.groupingSec}:{},groupWithinSec:e.groupWithinSec,...e.snoozeOptions===void 0?{}:{snoozeOptions:[...e.snoozeOptions]},...e.askVerdict!==void 0&&zm(e)?{askVerdict:e.askVerdict}:{},...t?.confirm===void 0?{}:{confirm:t.confirm},...s===void 0?{}:{actions:s}}}function ph(e,t){let n=fh(e,void 0,t);return[`template`,`schedule`,`targetUsers`,`snoozeOptions`,`snoozeAllowGlobal`,`groupingSec`,`actions`].filter(e=>n[e]===void 0)}var mh=[{key:`rule`,get label(){return K.t(`helpers.ruleFormTabs.tab_rule`)},fields:[`name`,`tags`,`enabled`,`delivery`,`groupingSec`,`groupWithinSec`,`targetIds`,`targetUsers`,`targetParams`,`targetOverrides`]},{key:`devices`,get label(){return K.t(`helpers.ruleFormTabs.tab_devices`)},fields:[`deviceScope`]},{key:`conditions`,get label(){return K.t(`helpers.ruleFormTabs.tab_conditions`)},fields:[`conditions`,`classScope`,`schedule`]},{key:`notification`,get label(){return K.t(`helpers.ruleFormTabs.tab_notification`)},fields:[`priority`,`mediaImage`,`mediaShowTriggerZone`,`mediaShowSubjectPath`,`mediaGif`,`mediaClip`,`mediaProfile`,`mediaClipSpeed`,`mediaLinkedCameras`,`mediaWakeSleepingCamera`,`templateTitle`,`templateBody`,`systemEventDelivery`]},{key:`actions`,get label(){return K.t(`helpers.ruleFormTabs.tab_actions`)},fields:[`actions`]},{key:`advanced`,get label(){return K.t(`helpers.ruleFormTabs.tab_advanced`)},fields:[`snoozeAllowGlobal`,`snoozeOptions`,`askVerdict`,`cooldownSec`,`cooldownScope`,`cooldownGranularity`]}];function hh(e,t={}){let n=Jt({delivery:e,conditions:t}),r=Mt(n),i=mh.map(e=>e.key===`conditions`?{...e,label:r.label}:e);return Dt(n)?i.filter(e=>e.key!==`devices`):i}function gh(e){if(e.audio!==void 0)return K.t(`helpers.ruleFormTabs.condSound`);if(e.occupancy!==void 0)return K.t(`helpers.ruleFormTabs.condOccupancy`)}function _h(e){let t=Jt(e),n=Kt(Em(e),t);return t===`sensor`&&e.conditions.sensorTransition!==void 0&&!ap(`sensorTransition`,e.conditions)?[...n,{conditionId:`sensorTransition`,reason:Un}]:n}var vh=`rule`;function yh(e){return mh.find(t=>t.key===e)?.key}function bh(e){return e?.toLowerCase().startsWith(`it`)===!0?`it`:`en`}function xh(){let{i18n:e}=q(),t=bh(e.language);return e=>qt(e,t)}O();var Sh=`block text-[11px] font-medium text-foreground`,Ch=`text-[10px] text-foreground-subtle mt-0.5`;function wh({cameras:e,fleet:t,value:n,onChange:r,emptyMeansAll:i=!1,savedHadDevices:a=!1}){return x(ii,{devices:e,listState:t.state,fleet:t,value:n,onChange:r,emptyMeansAll:i,savedHadDevices:a})}function Th({value:e,placeholder:t,onChange:n}){let{t:r}=q(),[i,a]=w(``),o=()=>{let t=i.trim();if(t.length===0||e.includes(t)){a(``);return}n([...e,t]),a(``)},c=t=>n(e.filter(e=>e!==t));return s(`div`,{className:`mt-1 space-y-1.5`,children:[e.length>0&&x(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>s(`span`,{className:`inline-flex items-center gap-1 rounded bg-surface-hover px-1.5 py-0.5 text-[11px] text-foreground`,children:[e,x(G,{variant:`unstyled`,type:`button`,onClick:()=>c(e),"aria-label":r(`system.notificationConditionWidgets.remove`,`remove {{v}}`,{v:e}),className:`text-foreground-subtle hover:text-danger`,children:x(xe,{className:`h-3 w-3`})})]},e))}),x(W,{value:i,placeholder:t,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),o())},onBlur:o})]})}function Eh({picker:e,value:t,onChange:n}){let{t:r}=q(),i=m(()=>hn(e),[e]),a=m(()=>new Set(t),[t]),o=t.filter(e=>!i.has(e)),c=e=>{n(a.has(e)?t.filter(t=>t!==e):[...t,e])};return s(`div`,{className:`space-y-2`,children:[o.length>0&&x(`div`,{className:`flex flex-wrap gap-1`,children:o.map(e=>s(G,{variant:`unstyled`,type:`button`,onClick:()=>n(t.filter(t=>t!==e)),className:`inline-flex items-center gap-1 rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground hover:bg-surface-hover`,title:r(`system.notificationConditionWidgets.customValueClickToRemove`,`Custom value — click to remove`),children:[e,` ×`]},e))}),e.groups.map(e=>s(`div`,{children:[x(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-muted mb-1`,children:e.fallbackLabel}),x(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map(e=>{let t=a.has(e.value);return x(G,{variant:`unstyled`,type:`button`,"aria-pressed":t,onClick:()=>c(e.value),className:t?`rounded border border-primary bg-primary/15 px-1.5 py-0.5 text-[10px] text-foreground`:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground hover:bg-surface-hover`,children:e.label},e.value)})})]},e.key))]})}function Dh({value:e,min:t,max:n,step:r,onChange:i}){let{t:a}=q();return s(`div`,{className:`mt-1 flex items-center gap-2`,children:[x(W,{type:`number`,value:e??``,min:t,max:n,step:r,className:`max-w-[8rem]`,onChange:e=>{let t=e.target.value;if(t===``){i(void 0);return}let n=Number(t);i(Number.isFinite(n)?n:void 0)}}),e!==void 0&&n!==void 0&&x(We,{min:t,max:n,step:r,value:e,onChange:e=>i(Number(e.target.value)),className:`flex-1 accent-primary`,"aria-label":a(`common.valueWord`)})]})}function Oh({value:e,onChange:t,options:n}){let{t:r}=q(),i=kh(n??[]),a=i.length>0?i:op;return s(`div`,{className:`mt-1 space-y-1`,children:[x(qe,{value:e??`enter`,options:a.map(e=>({value:e.value,label:r(`notificationRules.crossing.${e.value}`,e.label)})),onChange:e=>t(cp(e.target.value))}),x(`p`,{className:Ch,children:r(`notificationRules.crossing.hint`,`Which way the subject crosses the zone.`)})]})}function kh(e){let t=[];for(let n of e){let e=n.value===``||n.value===`enter`?sp:cp(n.value);e===void 0||t.some(t=>t.value===e)||t.push({value:e,label:n.label})}return t}function Ah({deviceIds:e,cameras:t,value:n,onChange:r}){let{options:i,loading:a}=xf(e,t);return x(Ef,{options:i,value:n,onChange:r,loading:a,noFreeText:!0,emptyHint:e.length===0?`Select cameras first — a rule can only use zones those cameras actually have.`:`The selected cameras have no zones. Draw one in the camera’s zone editor first.`,placeholder:``})}function jh({deviceIds:e,cameras:t,allDevices:n,value:r,onChange:i}){let{t:a}=q(),{options:o,loading:c}=Sf(e),l=Cf(m(()=>bf(e,t,n),[e,t,n]));return s(F,{children:[x(Ef,{options:m(()=>{let e=new Set(l.options.map(e=>e.value));return[...l.options,...o.filter(t=>!e.has(t.value))]},[l.options,o]),value:r,onChange:i,loading:c||l.pending,emptyHint:e.length===0?a(`system.notificationConditionWidgets.eventTokensSelectDevices`,`Select a device above to pick one of its events — or type a token.`):a(`system.notificationConditionWidgets.eventTokensNone`,`The selected devices declare no events — type a token.`),placeholder:a(`system.notificationConditionWidgets.eventToken`,`Event token…`)}),l.unknownDevices.length>0&&x(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:a(`system.notificationConditionWidgets.eventTokensUnknown`,`Could not read the events of: {{devices}}. They are unknown, not absent.`,{devices:l.unknownDevices.join(`, `)})})]})}var Mh=[{value:`became-occupied`,labelKey:`system.notificationConditionWidgets.opBecameOccupied`},{value:`became-free`,labelKey:`system.notificationConditionWidgets.opBecameFree`},{value:`>=`,labelKey:`system.notificationConditionWidgets.opCountAtLeast`},{value:`<=`,labelKey:`system.notificationConditionWidgets.opCountAtMost`}];function Nh(e,t){let n=e.map(e=>({value:e.value,label:e.label}));return t===void 0||t===``||n.some(e=>e.value===t)?n:[...n,{value:t,label:K.t(`system.notificationConditionWidgets.subTypeNeverCountsAlways`,`{{stored}} — sub-type, never counts (always 0)`,{stored:t})}]}function Ph({deviceIds:e,cameras:t,classOptions:n,value:r,onChange:i}){let{t:a}=q(),{options:o,loading:c}=xf(e,t),l=r??jt,u=e=>i({...l,...e}),d=l.op===`became-occupied`||l.op===`became-free`,f=Nh(n,l.className);return s(`div`,{className:`mt-1 space-y-1.5`,children:[s(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[x(`div`,{className:`min-w-[10rem]`,children:x(qe,{value:l.zoneId??``,options:[{value:``,label:c?a(`system.notificationConditionWidgets.loadingZones`,`Loading zones…`):a(`system.notificationConditionWidgets.wholeFrame`,`— whole frame —`)},...o.map(e=>({value:e.value,label:e.label}))],onChange:e=>u({zoneId:e.target.value===``?void 0:e.target.value})})}),x(`div`,{className:`min-w-[9rem]`,children:x(qe,{value:l.className??``,options:[{value:``,label:a(`system.notificationConditionWidgets.anyClass`,`— any class —`)},...f],onChange:e=>u({className:e.target.value===``?void 0:e.target.value})})}),x(`div`,{className:`min-w-[9rem]`,children:x(qe,{value:l.op,options:Mh.map(e=>({value:e.value,label:a(e.labelKey)})),onChange:e=>{let t=Mh.find(t=>t.value===e.target.value);t&&u({op:t.value})}})})]}),s(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:[s(`label`,{className:`flex items-center gap-1`,children:[d?a(`system.notificationConditionWidgets.threshold`,`Threshold`):a(`system.notificationConditionWidgets.count`,`Count`),x(W,{type:`number`,min:0,className:`w-16`,value:String(l.count),onChange:e=>u({count:Math.max(0,Number(e.target.value)||0)})})]}),s(`label`,{className:`flex items-center gap-1`,children:[a(`system.notificationConditionWidgets.holdFor`,`Hold for`),x(W,{type:`number`,min:0,max:3600,className:`w-16`,value:String(l.sustainSeconds),onChange:e=>u({sustainSeconds:Math.min(3600,Math.max(0,Number(e.target.value)||0))})}),`s`]}),r===void 0?null:x(G,{variant:`unstyled`,type:`button`,onClick:()=>i(void 0),className:`underline hover:text-foreground`,children:a(`system.notificationConditionWidgets.clear`,`Clear`)})]}),e.length===0&&x(`p`,{className:`text-[11px] text-warning`,children:a(`system.notificationConditionWidgets.noCameraPickedOnThe`,`No camera picked on the Devices tab: this watches EVERY camera's occupancy, and no zone can be offered until you choose one — a zone id belongs to a camera.`)}),x(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`system.notificationConditionWidgets.countsConfirmedTrackedObjectsFrom`,`Counts confirmed tracked objects from zone analytics. The change must hold for the sustain window before it fires; with no snapshot for the camera or zone the rule never fires.`)})]})}var Fh=[{value:`label`,labelKey:`system.notificationConditionWidgets.audioModeLabel`,Icon:ne},{value:`level`,labelKey:`system.notificationConditionWidgets.audioModeLevel`,Icon:he}];function Ih({taxonomy:e,value:t,onChange:n}){let{t:r}=q(),i=In(t),a=e=>n(bn(t,e)),{choices:o,unknownLabels:c}=On(e,i.labels),l=_n(t)??`label`;return s(`div`,{className:`mt-1 space-y-2`,children:[s(`div`,{className:`flex flex-wrap items-center gap-1`,children:[Fh.map(e=>x(G,{variant:`unstyled`,type:`button`,"aria-pressed":l===e.value,onClick:()=>a({mode:e.value}),className:`rounded border px-2 py-0.5 text-[11px] ${l===e.value?`border-primary bg-primary/15 text-foreground`:`border-border text-foreground-subtle hover:bg-surface-hover`}`,children:s(`span`,{className:`inline-flex items-center gap-1`,children:[x(e.Icon,{className:`h-3 w-3`}),r(e.labelKey)]})},e.value)),t===void 0?null:x(G,{variant:`unstyled`,type:`button`,onClick:()=>n(void 0),className:`ml-1 text-xs text-foreground-subtle underline hover:text-foreground`,children:r(`system.notificationConditionWidgets.clear`,`Clear`)})]}),l===`label`?s(F,{children:[x(`div`,{className:`flex flex-wrap gap-1`,children:o.map(e=>{let t=Kn(i.labels,e.value),n=e.unknown?`border-dashed border-warning text-warning`:t?`border-primary bg-primary/15 text-foreground`:`border-border text-foreground hover:bg-surface-hover`;return x(G,{variant:`unstyled`,type:`button`,"aria-pressed":t,title:e.unknown?r(`system.notificationConditionWidgets.storedByTheRuleNot`,`Stored by the rule — not offered by this hub`):void 0,onClick:()=>a({labels:jn(i.labels,e.value)}),className:`rounded border px-1.5 py-0.5 text-[10px] ${n}`,children:s(`span`,{className:`inline-flex items-center gap-1`,children:[x(wa,{iconId:e.iconId,size:12}),e.label]})},e.value)})}),c.length>0&&s(`p`,{className:`text-[10px] text-warning`,children:[r(`system.notificationConditionWidgets.keptFromTheRuleUnknown`,`Kept from the rule, unknown to this hub:`),` `,c.join(`, `)]}),s(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:[s(`label`,{className:`flex items-center gap-1`,children:[r(`system.notificationConditionWidgets.confirmAfter`,`Confirm after`),x(W,{type:`number`,min:1,max:20,step:1,className:`w-16`,value:String(i.confirmHits??2),onChange:e=>a({confirmHits:Number(e.target.value)})}),r(`system.notificationConditionWidgets.frames`)]}),s(`label`,{className:`flex items-center gap-1`,children:[r(`system.notificationConditionWidgets.within`),x(W,{type:`number`,min:1,max:60,step:1,className:`w-16`,value:String(i.confirmWindowSec??5),onChange:e=>a({confirmWindowSec:Number(e.target.value)})}),`s`]})]}),x(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`system.notificationConditionWidgets.audioConfirmHint`,{hits:2,window:5})})]}):s(F,{children:[x(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:s(`label`,{className:`flex items-center gap-1`,children:[r(`system.notificationConditionWidgets.louderThan`,`Louder than`),x(W,{type:`number`,min:Cn,max:0,step:3,className:`w-20`,value:String(i.dbThreshold??Jn),onChange:e=>a({dbThreshold:Number(e.target.value)})}),`dBFS`]})}),s(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:[s(`label`,{className:`flex items-center gap-1`,children:[r(`system.notificationConditionWidgets.hits`,`Hits`),x(W,{type:`number`,min:1,max:100,step:5,className:`w-16`,value:String(i.hitPercent),onChange:e=>a({hitPercent:Number(e.target.value)})}),r(`system.notificationConditionWidgets.hitsPercentDefault`,{value:Nn.hitPercent})]}),s(`label`,{className:`flex items-center gap-1`,children:[r(`system.notificationConditionWidgets.over`),x(W,{type:`number`,min:1,max:300,step:5,className:`w-16`,value:String(i.samplingSeconds),onChange:e=>a({samplingSeconds:Number(e.target.value)})}),r(`system.notificationConditionWidgets.secondsDefault`,{value:Nn.samplingSeconds})]})]}),x(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`system.notificationConditionWidgets.dbfsHint`,{min:Cn})})]}),Hn(t)?x(`p`,{className:`text-[11px] text-warning`,children:r(`system.notificationConditionWidgets.withNeitherASoundNor`,`With neither a sound nor a level threshold this can never match — every sample would be a hit, so the engine refuses it rather than notifying on silence.`)}):null]})}function Lh({value:e,onChange:t}){let{t:n}=q(),r=e?.values??[],i=e?.maxDistance??1,a=e=>t(e.length>0?{values:e,maxDistance:i}:void 0),o=e=>t(r.length>0?{values:r,maxDistance:e}:void 0),c=Tf().filter(e=>!r.includes(e));return s(`div`,{className:`mt-1 space-y-1.5`,children:[x(Th,{value:r,placeholder:n(`system.notificationConditionWidgets.plateText`,`Plate text…`),onChange:a}),c.length>0&&s(`div`,{className:`flex flex-wrap items-center gap-1`,children:[x(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`system.notificationConditionWidgets.seen`,`Seen:`)}),c.slice(0,12).map(e=>x(G,{variant:`unstyled`,type:`button`,onClick:()=>a([...r,e]),className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:e},e))]}),s(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[n(`system.notificationConditionWidgets.maxDistance`,`Max distance`),x(W,{type:`number`,min:0,max:3,step:1,value:i,className:`max-w-[5rem]`,onChange:e=>{let t=Number(e.target.value);o(Number.isFinite(t)?Math.max(0,Math.min(3,t)):1)}})]})]})}function Rh({gateable:e,value:t,onChange:n}){let{t:r}=q(),i=xh(),a=e.find(e=>e.id===t?.deviceId),o=new Set(t?.states??[]),c=e=>{let t=Number(e);if(!Number.isFinite(t)||t===0)return n(void 0);n({deviceId:t,states:[]})},l=e=>{if(t===void 0)return;let r=new Set(o);r.has(e)?r.delete(e):r.add(e),n(r.size===0?void 0:{deviceId:t.deviceId,states:[...r]})};return s(`div`,{className:`mt-1 space-y-2`,children:[x(qe,{value:t===void 0?``:String(t.deviceId),options:[{value:``,label:r(`system.notificationConditionWidgets.noDeviceGate`,`— no device gate —`)},...e.map(e=>({value:String(e.id),label:e.name}))],onChange:e=>c(e.target.value)}),a!==void 0&&x(`div`,{className:`flex flex-wrap gap-1.5`,children:a.states.map(e=>x(G,{variant:`unstyled`,type:`button`,onClick:()=>l(e),className:o.has(e)?`rounded-md border border-primary bg-primary/10 px-2 py-0.5 text-[11px] text-primary`:`rounded-md border border-border px-2 py-0.5 text-[11px] text-foreground-subtle`,children:i(e)},e))}),a!==void 0&&a.states.length===0&&x(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:r(`system.notificationConditionWidgets.thisDeviceReportsNoState`,`This device reports no state the gate can read, so it cannot arm a rule.`)}),t!==void 0&&x(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:r(`system.notificationConditionWidgets.theRuleIsSilentWhile`,`The rule is silent while the device is in any other state — including when its state cannot be read at all.`)})]})}function zh(e,t){let n=t(e.verdict);return e.latched?`${n} · ${t(`latched`)}`:n}function Bh({scenes:e,value:t,onChange:n}){let{t:r}=q(),i=xh(),a=e.find(e=>e.sceneId===t?.sceneId),o=r=>{if(r===``)return n(void 0);let i=e.find(e=>e.sceneId===r);if(i===void 0)return n(void 0);n({sceneId:r,deviceId:i.deviceId,requiredState:t?.requiredState??`diverged`,...t?.latched===void 0?{}:{latched:t.latched}})},c=e=>{t!==void 0&&n({...t,requiredState:e===`matched`?`matched`:`diverged`})},l=e=>{if(t!==void 0){if(e===``){let{latched:e,...r}=t;return n(r)}n({...t,latched:e===`latched`})}};return e.length===0?x(`p`,{className:Ch,children:r(`notificationRules.scene.none`,`No scenes yet — create one on the Scenes page.`)}):s(`div`,{className:`mt-1 space-y-2`,children:[x(qe,{value:t?.sceneId??``,options:[{value:``,label:r(`notificationRules.scene.noGate`,`— no scene gate —`)},...e.map(e=>({value:e.sceneId,label:`${e.cameraName} · ${e.label} — ${zh(e,i)}`}))],onChange:e=>o(e.target.value)}),t!==void 0&&s(`div`,{className:`flex flex-wrap items-center gap-2`,children:[s(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[r(`notificationRules.scene.onlyWhile`,`Only while it is`),x(qe,{value:t.requiredState,options:[{value:`diverged`,label:i(`diverged`)},{value:`matched`,label:i(`matched`)}],onChange:e=>c(e.target.value)})]}),s(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[r(`notificationRules.scene.read`,`Read`),x(qe,{value:t.latched===void 0?``:t.latched?`latched`:`live`,options:[{value:``,label:a===void 0?r(`notificationRules.scene.readOwn`,`The scene's own setting`):`${r(`notificationRules.scene.readOwn`,`The scene's own setting`)} (${i(a.emit)})`},{value:`latched`,label:i(`latched`)},{value:`live`,label:i(`live`)}],onChange:e=>l(e.target.value)})]})]}),a!==void 0&&s(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:[r(`notificationRules.scene.rightNow`,`Right now:`),` `,zh(a,i)]}),t!==void 0&&a===void 0&&x(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:r(`notificationRules.scene.missing`,`This scene no longer exists — pick another or remove the gate.`)})]})}function Vh(e){return hp(e)}function Hh(e){return gp(e)}function Uh(){return{days:[1,2,3,4,5],startMinute:540,endMinute:1080}}function Wh(e){return{days:[...pp.days],minute:e}}var Gh=`Always active — add a window to restrict when the rule fires.`;function Kh({value:e,onChange:t,mode:n=`windows`,defaultMinute:r=pp.minute,emptyHint:i}){return n===`times`?x(Jh,{value:e,onChange:t,defaultMinute:r}):x(qh,{value:e,onChange:t,emptyHint:i??Gh})}function qh({value:e,onChange:t,emptyHint:n}){let{t:r}=q(),i=e?.windows??[],a=e?.invert??!1,o=(n,r)=>{if(n.length===0){t(void 0);return}t({windows:n,...r?{invert:!0}:{},...e?.timezone?{timezone:e.timezone}:{}})},c=()=>o([...i,Uh()],a),l=e=>o(i.filter((t,n)=>n!==e),a),u=(e,t)=>o(i.map((n,r)=>r===e?t:n),a);return s(`div`,{className:`mt-1 space-y-2`,"data-testid":`schedule-field-windows`,children:[i.length===0?x(`p`,{className:Ch,children:n}):i.map((e,t)=>x(Yh,{window:e,onChange:e=>u(t,e),onRemove:()=>l(t)},t)),s(`div`,{className:`flex items-center gap-3`,children:[s(G,{variant:`unstyled`,type:`button`,onClick:c,className:`flex items-center gap-1 rounded-md bg-surface-hover px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground`,children:[x(Ye,{className:`h-3 w-3`}),` `,r(`system.notificationScheduleField.addWindow`)]}),i.length>0&&s(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[x(L,{checked:a,onChange:e=>o([...i],e.target.checked),className:`accent-primary`}),r(`system.notificationScheduleField.activeOutsideTheWindows`,`Active outside the windows`)]})]})]})}function Jh({value:e,onChange:t,defaultMinute:n}){let{t:r}=q(),i=e?.timezone,a=e===void 0?{times:[],approximated:!1}:rn(e);if(a===null)return s(`div`,{className:`mt-1 space-y-2`,"data-testid":`schedule-field-times-fallback`,children:[x(`p`,{className:Ch,children:r(`system.notificationScheduleField.invertedScheduleShownAsBands`,`Inverted schedule — shown as bands. Clear the invert flag (or the windows) to author punctual times.`)}),x(qh,{value:e,onChange:t,emptyHint:Gh})]});let o=a.times,c=e=>{if(e.length===0){t(void 0);return}t(Ot(e,i))};return s(`div`,{className:`mt-1 space-y-2`,"data-testid":`schedule-field-times`,children:[a.approximated&&x(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,"data-testid":`schedule-field-times-approximated`,children:r(`system.notificationScheduleField.shownAsSendAtTimes`,`Shown as send-at times from each window's end (when the summary fires). Edit or save to store them as punctual one-minute windows.`)}),o.length===0?x(`p`,{className:Ch,children:r(`system.notificationScheduleField.noTimesYetAddOne`,`No times yet — add one to send on those days at that clock time.`)}):o.map((e,t)=>x(Xh,{time:e,index:t,onChange:e=>c(o.map((n,r)=>r===t?e:n)),onRemove:o.length>1?()=>c(o.filter((e,n)=>n!==t)):void 0},t)),s(G,{variant:`unstyled`,type:`button`,onClick:()=>c([...o,Wh(n)]),className:`flex items-center gap-1 rounded-md bg-surface-hover px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground`,"data-testid":`schedule-field-add-time`,children:[x(Ye,{className:`h-3 w-3`}),` `,r(`system.notificationScheduleField.addTime`)]})]})}function Yh({window:e,onChange:t,onRemove:n}){let{t:r}=q();return s(`div`,{className:`space-y-1.5 rounded-md border border-border p-2`,children:[s(`div`,{className:`flex items-center gap-2 text-xs`,children:[x(W,{type:`time`,value:Vh(e.startMinute),onChange:n=>t({...e,startMinute:Hh(n.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),x(`span`,{className:`text-foreground-subtle`,children:`→`}),x(W,{type:`time`,value:Vh(e.endMinute),onChange:n=>t({...e,endMinute:Hh(n.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),x(`span`,{className:`flex-1`}),x(G,{variant:`unstyled`,type:`button`,onClick:n,"aria-label":r(`system.notificationScheduleField.removeWindow`,`Remove window`),className:`text-foreground-subtle hover:text-danger`,children:x(gt,{className:`h-3.5 w-3.5`})})]}),x(Zh,{days:e.days,onToggle:n=>{let r=e.days.includes(n)?e.days.filter(e=>e!==n):[...e.days,n];r.length!==0&&t({...e,days:r})}})]})}function Xh({time:e,index:t,onChange:n,onRemove:r}){let{t:i}=q();return s(`div`,{className:`space-y-1.5 rounded-md border border-border p-2`,children:[s(`div`,{className:`flex items-center gap-2 text-xs`,children:[x(`span`,{className:`text-foreground-subtle`,children:i(`system.notificationScheduleField.at`,`At`)}),x(W,{type:`time`,value:hp(e.minute),onChange:t=>n({...e,minute:gp(t.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`,"data-testid":`schedule-field-time-${String(t)}`}),x(`span`,{className:`flex-1`}),r!==void 0&&x(G,{variant:`unstyled`,type:`button`,onClick:r,"aria-label":i(`system.notificationScheduleField.removeTime`,`Remove time`),className:`text-foreground-subtle hover:text-danger`,children:x(gt,{className:`h-3.5 w-3.5`})})]}),x(Zh,{days:e.days,onToggle:t=>{let r=e.days.includes(t)?e.days.filter(e=>e!==t):[...e.days,t];r.length!==0&&n({...e,days:r})}})]})}function Zh({days:e,onToggle:t}){return x(`div`,{className:`flex flex-wrap gap-1`,children:mp.map(n=>x(G,{variant:`unstyled`,type:`button`,onClick:()=>t(n.value),className:`rounded px-1.5 py-0.5 text-[10px] ${e.includes(n.value)?`bg-primary text-primary-foreground`:`bg-surface-hover text-foreground-subtle`}`,children:n.label},n.value))})}function Qh(e){return e>=8}O();function $h(e){if(typeof e!=`object`||!e)return;let t=Reflect.get(e,`windows`);if(!(!Array.isArray(t)||t.length===0))return e}function eg(e){return e.type===`multiselect`}function tg(e){let t=e.suggestions;return t===void 0||t.length===0?[]:t.map(e=>({value:e,label:e}))}function ng(e){return e.map(e=>({value:e.value,label:e.label,...e.description===void 0?{}:{description:e.description},...e.iconId===void 0?{}:{iconId:e.iconId}}))}function rg(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function ig({field:e,values:t,onChange:n,onChangeMany:r,disabled:i,translationFn:a,onTestField:o,externalProbe:c,allFields:l,onAction:u}){let{t:d}=q();if(e.type===`tags`){if(!_i(e,t,l))return null;let r=e.creatable!==!1;return x(mo,{mode:`multi`,options:tg(e),value:rg(t[e.key]),onChange:t=>n(e.key,t),disabled:i===!0||e.disabled===!0,creatable:r,...e.createLabel===void 0?{}:{createLabel:e.createLabel},...e.maxTags===void 0?{}:{maxItems:e.maxTags},label:og(e.label,a),description:e.description===void 0?void 0:og(e.description,a),placeholder:e.placeholder??d(`formBuilder.formBuilder.searchOrAdd`,`Search or add…`),testId:`config-tags-${e.key}`})}if(e.type===`schedule`){if(!_i(e,t,l))return null;let r=og(e.label,a),i=e.description===void 0?void 0:og(e.description,a),o=e.mode===`times`?`times`:`windows`;return s(`div`,{className:`space-y-1`,"data-testid":`config-schedule-${e.key}`,children:[r!==void 0&&x(`label`,{className:`block text-[11px] font-medium text-foreground-subtle`,children:r}),i!==void 0&&x(`p`,{className:`text-[10px] text-foreground-subtle`,children:i}),x(Kh,{mode:o,value:$h(t[e.key]),onChange:t=>n(e.key,t)})]})}return eg(e)&&(Qh(e.options.length)||e.creatable===!0)?_i(e,t,l)?x(mo,{mode:`multi`,options:ng(e.options),value:rg(t[e.key]),onChange:t=>n(e.key,t),disabled:i===!0||e.disabled===!0,creatable:e.creatable===!0,...e.createLabel===void 0?{}:{createLabel:e.createLabel},...e.maxItems===void 0?{}:{maxItems:e.maxItems},label:og(e.label,a),description:e.description===void 0?void 0:og(e.description,a),placeholder:e.placeholder??d(`formBuilder.formBuilder.searchToAdd`,`Search to add…`),testId:`config-multiselect-${e.key}`,listboxId:`msel-${e.key}`}):null:x(ci,{field:e,values:t,onChange:n,onChangeMany:r,disabled:i,translationFn:a,onTestField:o,externalProbe:c,allFields:l,onAction:u})}function ag(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function og(e,t){if(e!==void 0)return t&&ag(e)?t(e):e}function sg({section:e,values:t,onChange:n,onChangeMany:r,disabled:i,translationFn:a,onTestField:o,probeResults:c,onAction:l}){let[u,d]=w(e.defaultCollapsed??!1),f=e.style===`accordion`;if(e.fields.reduce((n,r)=>n+ +!!_i(r,t,e.fields),0)===0)return null;let p=e.fields,m=e.columns??2,h=m===1?`grid-cols-1`:m===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:m===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`,g=e.fields.length===1&&e.fields[0]?.type===`widget`?e.fields[0]:void 0,_=g!==void 0||!e.title&&!e.description;return s(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},"data-settings-section":e.id,children:[!_&&(f?s(`button`,{type:`button`,"aria-expanded":!u,onClick:()=>d(e=>!e),className:`flex w-full items-center justify-between mb-2 text-left`,children:[s(`div`,{children:[e.title&&x(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:og(e.title,a)}),e.description&&x(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:og(e.description,a)})]}),x(go,{expanded:!u,className:`ml-2`})]}):x(`div`,{className:`flex items-center justify-between mb-2`,children:s(`div`,{children:[e.title&&x(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:og(e.title,a)}),e.description&&x(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:og(e.description,a)})]})})),!(u&&!_)&&(g===void 0?x(F,{children:x(`div`,{className:`grid ${h} gap-x-3 gap-y-2.5`,children:p.map(s=>x(ig,{field:s,values:t,onChange:n,onChangeMany:r,disabled:i,translationFn:a,onTestField:o,externalProbe:c?.[s.key],allFields:e.fields,onAction:l},s.key))})}):x(ci,{field:g,values:t,onChange:n,onChangeMany:r,disabled:i,translationFn:a,onTestField:o,externalProbe:c?.[g.key],allFields:e.fields,onAction:l},g.key))]})}function cg({schema:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,probeResults:o,onClearProbe:s,onAction:c,visibilityContext:l}){let u=l?{...l,...t}:t,d=(e,r)=>{n({...t,[e]:r}),s?.(e)},f=e=>{n({...t,...e});for(let t of Object.keys(e))s?.(t)};return x(`div`,{className:`space-y-4`,children:e.sections.map((e,t)=>x(sg,{section:e,values:u,onChange:d,onChangeMany:f,disabled:r,translationFn:i,onTestField:a,probeResults:o,onAction:c},`${e.id}-${t}`))})}function lg(e){return{status:e.status===`validated`||e.status===`rejected`||e.status===`inconclusive`||e.status===`unsupported`?e.status:e.success?`validated`:`rejected`,...e.error===void 0?{}:{error:e.error},...e.detail===void 0?{}:{detail:e.detail}}}var ug={validated:`border-success/30 bg-success/5 text-success`,rejected:`border-danger/30 bg-danger/5 text-danger`,inconclusive:`border-warning/30 bg-warning/5 text-warning`,unsupported:`border-border bg-surface text-foreground-subtle`};function dg({verdict:e}){let{t}=q(),n=(()=>{switch(e.status){case`validated`:return e.detail?`${t(`integrations.connectionSuccess`)} — ${e.detail}`:t(`integrations.connectionSuccess`);case`rejected`:return`${t(`integrations.errorPrefix`)} ${e.error??``}`;case`inconclusive`:return`${t(`integrations.connectionInconclusive`,{defaultValue:`Could not be checked:`})} ${e.error??``}`;case`unsupported`:return e.error??t(`integrations.connectionUntestable`,{defaultValue:`This integration cannot be tested before it is created.`})}})();return x(`div`,{className:`rounded-lg border px-3 py-2 text-xs ${ug[e.status]}`,"data-testid":`connection-test-verdict`,children:n})}var fg=new Set;function pg(e){for(let t of fg)t(e)}function mg(e){return fg.add(e),()=>{fg.delete(e)}}var hg=new Set([`proc`,`sys`,`dev`,`run`,`boot`,`lost+found`,`snap`,`bin`,`sbin`,`lib`,`lib32`,`lib64`,`libx32`,`usr`,`etc`,`var`,`opt`,`tmp`,`srv`,`root`,`System`,`Library`,`Applications`,`cores`,`private`]),gg=[`recordings`,`data`,`mnt`,`media`,`Volumes`];function _g(e){let t=gg.findIndex(t=>t===`recordings`?e.startsWith(t):e===t);return t===-1?gg.length:t}function vg(e){return e.filter(e=>!e.name.startsWith(`.`)&&!hg.has(e.name)).toSorted((e,t)=>{let n=_g(e.name)-_g(t.name);return n===0?e.name.localeCompare(t.name):n}).map(e=>e.path)}O();function yg({nodeId:e,value:t,onChange:n}){let{t:r}=q(),i=V().trpcClient,[a,o]=w([]),[c,l]=w(t),[u,d]=w(null),[f,p]=w(null),[m,h]=w(``),g=b(async(t,r)=>{p(null);try{let a=await i.filesystemBrowse.browse.query({nodeId:e,path:t});d(a),l(a.path),r&&n(a.path)}catch(e){p(e instanceof Error?e.message:`browse failed`)}},[i,e,n]);S(()=>{l(t),(async()=>{let n=await i.filesystemBrowse.browse.query({nodeId:e,path:`/`}).then(e=>e).catch(()=>null);if(n){o(vg(n.entries)),await g(t.startsWith(`/`)?t:`/`,!1);return}try{let n=await i.filesystemBrowse.listAllowedRoots.query({nodeId:e});o(n),await g(t&&n.some(e=>t.startsWith(e))?t:n[0]??``,!1)}catch(e){o([]),d(null),p(e instanceof Error&&/not available on node/i.test(e.message)?`This node can't be browsed remotely. Enter the path manually.`:e instanceof Error?e.message:`browse unavailable`)}})()},[e]);let _=async()=>{if(!(!m.trim()||!u)){p(null);try{let t=`${u.path.replace(/\/+$/,``)}/${m.trim()}`;await i.filesystemBrowse.createDir.mutate({nodeId:e,path:t}),h(``),await g(u.path,!0)}catch(e){p(e instanceof Error?e.message:`create failed`)}}},v=e=>`${(e/1e9).toFixed(1)} GB`;return s(`div`,{className:`space-y-2 rounded border border-border p-2`,children:[x(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>x(G,{variant:`unstyled`,onClick:()=>void g(e,!0),className:`rounded border border-border px-2 py-0.5 text-[10px] font-mono hover:border-primary/40`,children:e},e))}),x(W,{value:c,onChange:e=>{l(e.target.value),n(e.target.value)},placeholder:`/absolute/path`,className:`w-full rounded border border-border bg-background px-2 py-1 text-[11px] font-mono`}),u&&x(`div`,{className:`text-[10px] text-foreground-subtle`,children:r(`storage.pathBrowser.free`,{free:v(u.freeBytes),total:v(u.totalBytes)})}),x(`div`,{className:`max-h-40 space-y-0.5 overflow-y-auto`,children:u?.entries.map(e=>s(G,{variant:`unstyled`,onClick:()=>void g(e.path,!0),className:`block w-full truncate rounded px-2 py-1 text-left text-xs hover:bg-primary/5`,children:[`📁 `,e.name]},e.path))}),s(`div`,{className:`flex gap-1`,children:[x(W,{value:m,onChange:e=>h(e.target.value),placeholder:r(`storage.pathBrowser.newFolder`,`new folder`),className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs`}),x(G,{variant:`unstyled`,onClick:()=>void _(),className:`rounded border border-border px-2 py-1 text-xs hover:border-primary/40`,children:r(`storage.pathBrowser.create`,`Create`)})]}),f&&x(`div`,{className:`text-[10px] text-danger`,children:f})]})}var bg=`storage/path-browser`,xg=`nodeId`,Sg=`providerId`,Cg=`basePath`,wg=`hub`;function Tg(e,t){let n=e[t];return typeof n==`string`?n:``}function Eg(e,t){let n=e.sections.flatMap(e=>e.fields),r=n.find(e=>e.key===xg);if(r===void 0)return null;let i=Tg(t,Sg),a=`showWhen`in r?r.showWhen:void 0;return a!==void 0&&!(i!==``&&a.in?.includes(i))?null:(i===``?[Cg]:[`${i}.${Cg}`,Cg]).find(e=>n.some(t=>t.key===e))??null}function Dg(e,t){let n=Eg(e,t);return n===null?[]:[n]}function Og({schema:e,values:t,onValuesChange:n}){let{t:r}=q(),i=Eg(e,t);if(i===null)return null;let a=Tg(t,xg);return s(`div`,{className:`space-y-1`,children:[x(`p`,{className:`text-xs font-medium text-foreground-muted`,children:r(`storage.pathBrowser.label`,`Folder on the node`)}),x(yg,{nodeId:a===``?wg:a,value:Tg(t,i),onChange:e=>n({...t,[i]:e})})]})}var kg=new Map([[bg,{Component:Og,ownedKeys:Dg}]]);function Ag(e){return kg.get(e)??null}function jg(e,t){return t.length===0?e:{...e,sections:e.sections.map(e=>({...e,fields:e.fields.filter(e=>!t.includes(e.key))}))}}O();function Mg({field:e,values:t,onLabels:n}){let{t:r}=q(),{query:i,found:a}=Wr(e,t);return S(()=>{n(new Map(a.map(e=>[e.value,e.label])))},[a.map(e=>`${e.value}\u0000${e.label}`).join(``),n]),i.isError?x(`p`,{"data-testid":`create-many-labels-failed`,className:`text-xs text-warning`,children:r(`providerInstances.createManyLabelsFailed`,`The names of the choices could not be read ({{message}}); each is named after its value.`,{message:i.error?.message??``})}):null}function Ng(e){for(let t of e?.sections??[])for(let e of t.fields)if(e.type===`select`&&e.discoverOptions?.pickManyOnCreate===!0)return e;return null}function Pg(e,t){return e.type!==`select`||e.key!==t||e.discoverOptions===void 0?e:{...e,discoverOptions:{...e.discoverOptions,multiple:!0}}}function Fg(e,t){return{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>Pg(e,t))}))}}function Ig(e){let{key:t,picked:n,labels:r,typedName:i,values:a}=e;return n.map(e=>({name:n.length===1&&i.length>0?i:r.get(e)??e,values:{...a,[t]:e}}))}function Lg(e,t){let n=[];for(let r of e.links??[]){let e=t[r.field],i=Array.isArray(e)?e:[e];for(let e of i)typeof e!=`string`||e===``||n.some(t=>t.field===r.field&&t.instanceId===e)||n.push({field:r.field,cap:r.to.cap,...r.to.kind===void 0?{}:{kind:r.to.kind},instanceId:e})}return n}function Rg(e,t){return e.find(e=>e.id===t.instanceId&&(t.kind===void 0||e.kind===t.kind))}function zg(e){let t=new Map(e.holders.map(e=>[e.addonId,e])),n=[];for(let r of e.functionProviders){let i=e.displayNames.get(r.addonId)??r.addonId,a=t.get(r.addonId);if(a===void 0){n.push({kind:`fixed`,key:`fixed:${r.addonId}`,addonId:r.addonId,providerName:i,name:i,description:e.descriptions.get(r.addonId)??``,isActive:r.isActive});continue}let o=e.notRunning?.get(r.addonId);for(let e of a.instances){let t=Kg(a.description,e.kind),s=Lg(a.description,e.formValues);n.push({kind:`instance`,key:`${r.addonId}:${e.id}`,addonId:r.addonId,providerName:i,id:e.id,name:e.name,configured:e.configured,enabled:e.enabled??!0,status:e.status,canTest:t?.canTest??a.description.canTest,...e.kind===void 0?{}:{kindId:e.kind},...e.kind===void 0?{}:{kindLabel:t?.label??e.kind},...t?.iconUrl===void 0?{}:{kindIconUrl:t.iconUrl},...e.lastCheckedAt===void 0?{}:{lastCheckedAt:e.lastCheckedAt},...t?.connectPath===void 0?{}:{connectPath:t.connectPath},...t?.disconnectPath===void 0?{}:{disconnectPath:t.disconnectPath},...o===void 0?{}:{notRunning:o},...s.length>0?{links:s}:{}})}}return n}var Bg=new Set([`running`,`unknown`]);function Vg(e){return e!==void 0&&!Bg.has(e)}function Hg(e,t){return typeof e==`object`&&e?Reflect.get(e,t):void 0}function Ug(e){let t=new Map;for(let n of e){let e=Hg(Hg(n,`manifest`),`id`),r=Hg(Hg(n,`process`),`state`);typeof e!=`string`||typeof r!=`string`||Vg(r)&&t.set(e,r)}return t}function Wg(e){let t=new Map;for(let n of e){let e=Hg(n,`manifest`),r=Hg(e,`id`);if(typeof r!=`string`||r.length===0)continue;let i=Hg(e,`name`),a=Hg(e,`packageDisplayName`);t.set(r,typeof i==`string`?i:typeof a==`string`?a:r)}return t}function Gg(e){let t=new Map;for(let n of e){let e=Hg(n,`manifest`),r=Hg(e,`id`),i=Hg(e,`description`);typeof r!=`string`||typeof i!=`string`||i.length>0&&t.set(r,i)}return t}function Kg(e,t){return t===void 0?void 0:e.kinds?.find(e=>e.id===t)}function qg(e,t,n){let r=e.kinds;if(r===void 0||r.length===0)return e;let i=r.filter(e=>n===void 0?e.functionCap===t:e.id===n&&un(e,t));return i.length===0?null:{...e,kinds:i}}function Jg(e,t){let n=qg(e.description,t);if(n===null)return null;let r=n.kinds;if(e.description.kinds===void 0||r===void 0)return e;let i=new Set(r.map(e=>e.id));return{...e,description:n,instances:e.instances.filter(e=>e.kind===void 0||i.has(e.kind))}}function Yg(e){return(e.kinds?.length??0)>1}function Xg(e,t,n){return Yg(e)&&t!==void 0?t.label:n}function Zg(e){return e.label!==void 0&&e.label.length>0?e.label:e.state}function Qg(e){let t=new Set,n=[];for(let r of e)t.has(r.addonId)||(t.add(r.addonId),n.push({addonId:r.addonId,name:r.providerName}));return n}var $g={error:3,unknown:2,ok:1,off:0};function e_(e){return e.enabled?e.status===void 0?e.configured?`ok`:`unknown`:e.status.state:`off`}function t_(e){let t=null;for(let n of e){let e=e_(n);(t===null||$g[e]>$g[t])&&(t=e)}return t??`unknown`}function n_(e,t,n){return e.map(e=>{let r=n.get(e.addonId)??e.addonId,i=t.filter(t=>t.addonId===e.addonId),a=i.filter(e=>e.kind===`instance`),o=i.find(e=>e.kind===`fixed`);return o===void 0?{addonId:e.addonId,name:r,count:a.length,health:t_(a)}:{addonId:e.addonId,name:r,count:1,health:o.isActive?`ok`:`off`}})}function r_(e,t){return t===null?e:e.filter(e=>e.addonId===t)}function i_(e){return e.filter(e=>e.description.instanceMode===`multiple`||e.instances.length===0)}function a_(e,t){return e.flatMap(e=>{let n=t(e.addonId),r=e.description.kinds??[];return r.length===0?[{addonId:e.addonId,label:n,providerName:n}]:r.map(t=>({addonId:e.addonId,kind:t.id,label:t.label,providerName:n,...t.iconUrl===void 0?{}:{iconUrl:t.iconUrl}}))})}function o_(e){return e.some(e=>e.isError)?`error`:e.some(e=>e.isPending)?`pending`:`ready`}function s_(e,t){if(Object.is(e,t))return!0;if(typeof e!=`object`||typeof t!=`object`||e===null||t===null||Array.isArray(e)!==Array.isArray(t))return!1;let n=e,r=t,i=new Set([...Object.keys(n),...Object.keys(r)]);for(let e of i)if(!s_(n[e],r[e]))return!1;return!0}var c_=`enabled`;function l_(e,t){return t?.sections.some(e=>e.fields.some(e=>e.key===c_))===!0?{...e}:Object.fromEntries(Object.entries(e).filter(([e])=>e!==c_))}function u_(e,t){let n={};for(let[r,i]of Object.entries(t))i!==void 0&&(s_(e[r],i)||(n[r]=i));return n}function d_(e,t){let n={...e};for(let[e,r]of Object.entries(t))r!==void 0&&(n[e]=r);return n}function f_(e,t){return e.mintsId===!0?!1:(t?.role??e.role)!==`devices`}function p_(e,t,n){return e===`single`?t:`inst-${n()}`}function m_(){let e=crypto.getRandomValues(new Uint8Array(4));return Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``)}var h_=`+`;function g_(e,t,n){return t===void 0?e:t===null?`${e}:${h_}${n??``}`:`${e}:${t}`}function __(e){let t=e.indexOf(`:`);if(t<0)return{kind:`fixed`,addonId:e};let n=e.slice(0,t),r=e.slice(t+1);if(!r.startsWith(h_))return{kind:`instance`,addonId:n,id:r};let i=r.slice(1);return i===``?{kind:`create`,addonId:n}:{kind:`create`,addonId:n,kindId:i}}var v_=`sendWith`,y_=`smtpInstanceId`;function b_(e,t){return e.filter(e=>e.formValues[v_]===t||e.formValues[y_]===t).map(e=>e.name)}var x_=/^[a-z0-9][a-z0-9-]{0,63}$/;function S_(e,t){return t===``?`empty`:e.pattern.test(t)?`ok`:`invalid`}O();var C_=5e3,w_=`integration-instances`,T_=`provider-instances-holder`;function E_(e){let t=V(),n=_a({capName:e},{refetchInterval:C_}),r=_a({capName:w_},{refetchInterval:C_}),i=la(void 0,{refetchInterval:C_}),a=m(()=>(n.data??[]).map(e=>({addonId:e.addonId,isActive:e.isActive})),[n.data]),o=k({queries:m(()=>{let e=new Set((r.data??[]).map(e=>e.addonId));return a.map(e=>e.addonId).filter(t=>e.has(t))},[a,r.data]).map(e=>({queryKey:[T_,e],refetchInterval:C_,queryFn:async()=>{let n=t.trpcClient.integrationInstances,[r,i]=await Promise.all([n.describe.query({addonId:e}),n.listInstances.query({addonId:e})]);return{addonId:e,description:r,instances:i}}}))}),s=o_([n,r,...o]),c=m(()=>o.flatMap(t=>{let n=t.data===void 0?null:Jg(t.data,e);return n===null?[]:[n]}),[o,e]),l=m(()=>Wg(i.data??[]),[i.data]),u=m(()=>Gg(i.data??[]),[i.data]),d=m(()=>Ug(i.data??[]),[i.data]),f=m(()=>zg({functionProviders:a,holders:c,displayNames:l,descriptions:u,notRunning:d}),[a,c,l,u,d]),p=n.error??r.error??o.find(e=>e.error)?.error??null,h=b(()=>{n.refetch(),r.refetch();for(let e of o)e.refetch()},[n,r,o]);return{state:s,error:p===null?null:p.message,functionProviders:a,rows:f,holders:c,displayNames:l,descriptions:u,refetch:h}}O();var D_=`name`,O_=`kind`,k_=`restore`,A_=`restoreId`,j_=`typedId`,M_={};function N_(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function P_(e,t){let n=N_(e)?e:{};return t===null?{...n}:{...n,integrationId:t}}function F_({addonId:e,providerName:t,description:n,instance:r,onClose:i,onSaved:a,lead:o,typedId:c,testLabel:l,testHint:u}){let{t:d}=q(),f=V(),h=N(),g=r?.id??null,_=async(t,n,r)=>{let i=await f.trpcClient.addons.custom.mutate({addonId:e,action:t,input:P_(r,g)});return g!==null&&h.invalidateQueries({queryKey:[T_]}),i},v=n.kinds??[],y=Xg(n,Kg(n,r?.kind??v[0]?.id),t),[C,T]=w({[D_]:r?.name??y,[O_]:r?.kind??v[0]?.id??``,[k_]:!1,[A_]:``,[j_]:``}),D=p(y),O=C[O_];S(()=>{if(r!==null||typeof O!=`string`)return;let e=Xg(n,Kg(n,O),t),i=D.current;D.current=e,T(t=>t[D_]===i?{...t,[D_]:e}:t)},[O,n,r,t]);let k=e=>{let t=C[e];return typeof t==`string`?t.trim():``},A=k(D_),j=k(O_),M=Kg(n,j===``?void 0:j),P=C[k_]===!0,I=k(A_),L=r===null&&n.allowRestoreId===!0&&M?.signIn===void 0,te=L&&P&&I===``,ne=r===null&&M?.signIn===void 0&&!(L&&P)?c?.(j===``?void 0:j):void 0,re=k(j_),ie=ne===void 0?`ok`:S_(ne,re),[ae,oe]=w({...r?.formValues??M_}),[se,R]=w(null),le=m(()=>({sections:[{id:`instance-identity`,title:d(`providerInstances.identity`,`Identity`),columns:1,fields:[...r===null&&Yg(n)?[{type:`select`,key:O_,label:d(`providerInstances.colKind`,`Kind`),options:v.map(e=>({value:e.id,label:e.label}))}]:[],{type:`text`,key:D_,label:d(`providerInstances.colName`,`Name`),required:!0},...ne===void 0?[]:[{type:`text`,key:j_,label:d(`providerInstances.typedId`,`Id`),required:!0,description:ie===`invalid`?d(`providerInstances.typedIdInvalid`,`Lowercase letters, digits and dashes, starting with a letter or digit (up to 64).`):d(`providerInstances.typedIdHint`,`Chosen once; it cannot be changed after the record is created.`)}],...L?[{type:`boolean`,key:k_,label:d(`providerInstances.restore`,`Restore under its old id`),description:d(`providerInstances.restoreHint`,`Re-adding something that was removed under its original id keeps everything that points at it working.`)},{type:`text`,key:A_,label:d(`providerInstances.originalId`,`Original id`),required:!0,showWhen:{field:k_,equals:!0}}]:[]]}]}),[L,n,ne,r,v,d,ie]),[ue,de]=w(null),fe=g===null&&j!==``?j:void 0,z=E({queryKey:[`provider-instance-form`,e,g,fe??null],queryFn:()=>f.trpcClient.integrationInstances.instanceFormSchema.query({addonId:e,id:g,...fe===void 0?{}:{kind:fe}})}),pe=m(()=>r===null?M_:l_(r.formValues,z.data),[r,z.data]),me=m(()=>l_(ae,z.data),[ae,z.data]),B=r===null?Ng(z.data):null,he=B?.key,ge=m(()=>z.data&&he!==void 0?Fg(z.data,he):z.data,[z.data,he]),_e=B===null?[]:Nr(ae[B.key]),ve=_e.length>1,[ye,be]=w(()=>new Map),xe=b(e=>{be(e)},[]),Se=m(()=>ge?Vn(ge,{...pe}):null,[ge,pe]),Ce=z.isSuccess&&!z.data,we=(M?.widgets??[]).flatMap(e=>{let t=e.placement===`connection`?Ag(e.id):null;return t===null?[]:[{id:e.id,widget:t}]}),Te=Se===null?[]:we.flatMap(({widget:e})=>e.ownedKeys(Se,ae)),Ee=ee({mutationFn:async()=>{let t=f.trpcClient.integrationInstances,i=u_(pe,me),a=B!==null&&_e.length===1?{...i,[B.key]:_e[0]}:i;if(r===null&&B!==null&&ve){let r=Ig({key:B.key,picked:_e,labels:ye,typedName:A,values:a}),i=``;for(let[a,o]of r.entries())try{let r=await t.createInstance.mutate({addonId:e,name:o.name,...f_(n,M)?{id:p_(n.instanceMode,e,m_)}:{},...j===``?{}:{kind:j}});await t.updateInstance.mutate({addonId:e,id:r.id,values:o.values}),i=r.id}catch(e){throw h.invalidateQueries({queryKey:[T_]}),Error(d(`providerInstances.createManyStopped`,`{{done}} of {{total}} created: {{message}}`,{done:a,total:r.length,message:e instanceof Error?e.message:String(e)}))}return i}if(r===null){let r=L&&P?I:ne===void 0?f_(n,M)?p_(n.instanceMode,e,m_):void 0:re,i=await t.createInstance.mutate({addonId:e,name:A,...r===void 0?{}:{id:r},...j===``?{}:{kind:j}});return Object.keys(a).length>0&&await t.updateInstance.mutate({addonId:e,id:i.id,values:a}),i.id}return await t.updateInstance.mutate({addonId:e,id:r.id,name:A,values:a}),r.id},onSuccess:e=>{h.invalidateQueries({queryKey:[T_]}),pg({title:d(`providerInstances.saved`,`Saved`),message:ve?String(_e.length):A,severity:`info`}),a?.(e),i()},onError:e=>R(e.message)}),De=ee({mutationFn:()=>f.trpcClient.integrationInstances.testInstance.mutate({addonId:e,id:g,values:u_(pe,me),...g===null&&M!==void 0?{kind:M.id}:{}}),onSuccess:e=>de(lg(e)),onError:e=>de({status:`inconclusive`,error:e.message})});return x(ro,{open:!0,onClose:i,title:r===null?d(`providerInstances.createTitle`,`Add {{provider}}`,{provider:Xg(n,M,t)}):d(`providerInstances.editTitle`,`Edit {{name}}`,{name:r.name}),error:se??(z.isError?z.error.message:null),width:`lg`,footer:s(F,{children:[(M?.canTest??n.canTest)&&s(G,{size:`sm`,variant:`outline`,type:`button`,disabled:De.isPending||Se===null&&!Ce,onClick:()=>{de(null),De.mutate()},children:[De.isPending?x(H,{className:`h-3.5 w-3.5 animate-spin`}):null,l??d(`providerInstances.test`,`Test connection`)]}),s(G,{size:`sm`,type:`button`,disabled:Ee.isPending||Se===null&&!Ce||A.length===0&&!ve||!ve&&(te||ie!==`ok`),onClick:()=>{R(null),Ee.mutate()},children:[Ee.isPending?x(H,{className:`h-3.5 w-3.5 animate-spin`}):null,r===null&&ve?d(`providerInstances.createMany`,`Create {{count}}`,{count:_e.length}):r===null?d(`providerInstances.create`,`Create`):d(`providerInstances.saveChanges`,`Save changes`)]})]}),children:s(`div`,{className:`space-y-4`,children:[r===null?null:o,x(cg,{schema:ve?jg(le,[D_,j_,k_,A_]):le,values:C,onChange:T}),B!==null&&ve&&x(Mg,{field:B,values:ae,onLabels:xe}),M?.signIn!==void 0&&x($d,{basePath:M.signIn.basePath,...M.signIn.methods===void 0?{}:{methods:M.signIn.methods},name:A,...r===null?{}:{brokerId:r.id},getSettings:()=>d_(pe,me),disabled:A.length===0,onSignedIn:e=>{h.invalidateQueries({queryKey:[`provider-instances-holder`]}),a?.(e),i()}}),r!==null&&M?.connectPath!==void 0&&s(G,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>wd(xd(M.connectPath??``,r.id),()=>void h.invalidateQueries({queryKey:[`provider-instances-holder`]})),children:[x(ce,{className:`h-3.5 w-3.5`}),d(`providerInstances.connect`,`Connect account`)]}),Se===null?z.isError?null:Ce?x(`p`,{className:`text-xs text-foreground-muted`,children:d(`providerInstances.noForm`,`This record has no configuration form beyond its name.`)}):s(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[x(H,{className:`h-3 w-3 animate-spin`}),d(`providerInstances.loading`,`Loading…`)]}):s(F,{children:[x(ai,{schema:jg(Se,Te),values:ae,onChange:oe,onAction:_}),we.map(({id:e,widget:{Component:t}})=>x(t,{schema:Se,values:ae,onValuesChange:oe},e))]}),u!==void 0&&(M?.canTest??n.canTest)&&x(`p`,{className:`text-xs text-foreground-subtle`,children:u}),ue!==null&&x(dg,{verdict:ue})]})})}O();var I_=`integration-instances`,L_=`instance-kinds-describe`;function R_(e,t){let n=[];for(let r of e)if(!(t.addonId!==void 0&&r.addonId!==t.addonId))for(let e of r.description.kinds??[]){if(!(t.match===`link`?un(e,t.functionCap):e.functionCap===t.functionCap))continue;let i=e.brokerKind??e.id;t.kind!==void 0&&i!==t.kind&&e.id!==t.kind||n.push({addonId:r.addonId,kind:e.id,brokerKind:i,label:e.label,...e.connectPath===void 0?{}:{connectPath:e.connectPath},...e.disconnectPath===void 0?{}:{disconnectPath:e.disconnectPath},...e.signIn===void 0?{}:{signInBasePath:e.signIn.basePath},...e.iconUrl===void 0?{}:{iconUrl:e.iconUrl},canTest:e.canTest??r.description.canTest===!0})}return n}function z_(e){let t=V(),n=_a({capName:e.functionCap}),r=_a({capName:I_}),i=k({queries:m(()=>{let e=new Set((r.data??[]).map(e=>e.addonId));return(n.data??[]).map(e=>e.addonId).filter(t=>e.has(t))},[n.data,r.data]).map(e=>({queryKey:[L_,e],queryFn:async()=>({addonId:e,description:await t.trpcClient.integrationInstances.describe.query({addonId:e})})}))}),a=m(()=>i.flatMap(e=>e.data===void 0?[]:[e.data]),[i]);return{options:m(()=>R_(a,e),[a,e.functionCap,e.addonId,e.kind,e.match]),holders:a,isLoading:n.isLoading===!0||r.isLoading===!0||i.some(e=>e.isLoading)}}function B_({children:e,onClose:t}){return x(Mi,{open:!0,onOpenChange:e=>!e&&t(),children:s(Ir,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[x(Yr,{children:x(qi,{children:`\xA0`})}),x(zi,{children:e})]})})}function V_({functionCap:e,kind:t,addonId:n,onClose:r,onSaved:i,typedId:a,match:o}){let{t:s}=q(),c=V(),l=N(),u=z_({functionCap:e,...n===void 0?{}:{addonId:n},...t===void 0?{}:{kind:t},...o===void 0?{}:{match:o}}),d=u.options[0],f=n??d?.addonId,p=E({queryKey:[`instance-create-description`,f,e,d?.kind??null],enabled:f!==void 0,queryFn:async()=>qg(await c.trpcClient.integrationInstances.describe.query({addonId:f??``}),e,d?.kind)});return f===void 0||p.data===null?x(B_,{onClose:r,children:f===void 0&&u.isLoading?x(H,{className:`h-4 w-4 animate-spin`}):x(Or,{message:s(`brokers.editor.noProvider`)})}):p.isError?x(B_,{onClose:r,children:x(Or,{message:p.error.message})}):p.data===void 0?x(B_,{onClose:r,children:x(H,{className:`h-4 w-4 animate-spin`})}):x(F_,{addonId:f,providerName:d?.label??``,description:p.data,instance:null,onClose:r,...a===void 0?{}:{typedId:a},onSaved:e=>{l.invalidateQueries(),i(e)}})}O();var H_={ok:`success`,off:`default`,unknown:`default`,error:`danger`};function U_({kind:e,value:t,onChange:n,optional:r=!1,noneLabel:i,disabled:a=!1}){let{t:o}=q(),[c,l]=w(!1),u=Ea({kind:e}),d=to(u.data??[],t),f=d[0]?.id??null,p=!u.isLoading&&!u.isError&&u.data!==void 0;return S(()=>{!r&&!a&&p&&t===null&&f!==null&&n(f)},[r,a,p,t,f,n]),s(`div`,{className:`space-y-2`,children:[u.isLoading&&s(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[x(H,{className:`h-3.5 w-3.5 animate-spin`}),` `,o(`brokers.picker.loading`)]}),u.isError&&x(Or,{message:o(`brokers.picker.loadFailed`,{message:u.error?.message??o(`common.unknownError`)})}),!u.isLoading&&!u.isError&&d.length===0&&x(`p`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-xs text-foreground-subtle`,children:o(`brokers.picker.none`)}),r&&x(`button`,{type:`button`,"aria-pressed":t===null,disabled:a,onClick:()=>n(null),className:`flex w-full items-center rounded-lg border bg-surface p-3 text-left text-xs text-foreground-subtle transition-colors ${t===null?`border-primary ring-1 ring-primary`:`border-border hover:border-foreground-subtle/30`}`,children:i??o(`brokers.picker.noneChoice`)}),d.map(e=>s(`button`,{type:`button`,"aria-pressed":t===e.id,disabled:a,onClick:()=>n(e.id),className:`flex w-full items-center justify-between gap-3 rounded-lg border bg-surface p-3 text-left transition-colors ${t===e.id?`border-primary ring-1 ring-primary`:`border-border hover:border-foreground-subtle/30`}`,children:[x(`span`,{className:`text-xs font-semibold text-foreground`,children:e.name}),x(Ma,{variant:H_[e.state],className:`text-[10px]`,children:e.stateLabel??e.state})]},e.id)),s(G,{variant:`outline`,size:`sm`,disabled:a,onClick:()=>l(!0),children:[x(Ye,{className:`h-3.5 w-3.5`}),` `,o(`brokers.picker.createNew`)]}),c&&x(V_,{functionCap:`broker`,kind:e,onClose:()=>l(!1),onSaved:e=>{l(!1),n(e)}})]})}var W_=mn;function G_(e,t){let n=t[0];if(n===void 0)return null;let r=t.find(t=>t.id===e);return r===void 0?n.id:r.id}function K_(e,t){return Yt(e,t)}O();function q_(e=!0){S(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e])}O();function J_(e,t){let[n,r]=w(!1);return S(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}O();function Y_({kind:e,onResolved:t,onBack:n}){let{t:r}=q(),[i,a]=w(null);return s(`div`,{className:`space-y-4`,children:[s(G,{variant:`ghost`,size:`sm`,onClick:n,children:[x(at,{className:`h-3.5 w-3.5`}),` `,r(`common.back`)]}),x(U_,{kind:e,value:i,onChange:a}),x(`div`,{className:`flex justify-end pt-1`,children:x(G,{variant:`primary`,size:`sm`,disabled:i===null,onClick:()=>i!==null&&t(i),children:r(`integrations.brokerStep.useThisBroker`,`Use this broker`)})})]})}O();function X_({providerId:e,onImport:t,onSkip:n}){let{t:r}=q(),[i,a]=w(new Set),o=Di(),c=o.data,l=o.isPending||!o.data&&!o.isError;S(()=>{e&&(o.isPending||o.data||o.mutate({addonId:e}))},[e,o]);function u(e){a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(l)return s(`div`,{className:`flex flex-col items-center py-12`,children:[x(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),x(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:r(`integrations.searchingDevices`)})]});let d=c??[];return s(`div`,{className:`space-y-4`,children:[x(`p`,{className:`text-xs text-foreground-subtle`,children:d.length>0?r(`integrations.foundDevices`,{count:d.length}):r(`integrations.noDevicesFound`)}),d.length>0&&x(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:d.map(e=>{let t=e.stableId,n=e.suggestedName??t,a=i.has(t),o=e.alreadyOnboarded===!0;return s(G,{variant:`unstyled`,onClick:()=>{o||u(t)},disabled:o,title:o?r(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:e.onboardedName??n}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${o?`border-border bg-surface opacity-60 cursor-not-allowed`:a?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[x(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${a&&!o?`border-primary bg-primary`:`border-border`}`,children:a&&!o&&x(mt,{className:`h-3 w-3 text-primary-foreground`})}),x(Ke,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),x(`span`,{className:`text-xs font-medium text-foreground truncate`,children:n}),o&&x(`span`,{className:`ml-auto flex-shrink-0 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:r(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},t)})}),s(`div`,{className:`flex items-center justify-between pt-2`,children:[x(G,{variant:`unstyled`,onClick:n,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:r(`integrations.skip`)}),d.length>0&&s(G,{variant:`unstyled`,onClick:()=>t(Array.from(i)),disabled:i.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[r(`integrations.importSelected`),` (`,i.size,`)`]})]})]})}O();function Z_({addonId:e,configSchema:t,canTest:n=!0,instanceKind:r,initialName:i,initialConfig:a,submitLabel:o,hideName:c=!1,saving:l=!1,onScan:u,onSave:d,onBack:f}){let{t:p}=q(),[m,h]=w(i??``),[g,_]=w(a??{}),[v,y]=w(null),b=Oa({onSuccess:e=>y(lg(e)),onError:e=>y({status:`inconclusive`,error:String(e)})}),S=no(),C=!n||v?.status===`validated`,T=!c&&m.trim().length===0,E=!T&&C;return s(`div`,{className:`space-y-4`,children:[!c&&s(`div`,{children:[x(`label`,{htmlFor:`integration-name`,className:`block text-[11px] font-medium text-foreground mb-1`,children:p(`integrations.integrationName`)}),x(W,{id:`integration-name`,type:`text`,value:m,onChange:e=>h(e.target.value),placeholder:p(`integrations.integrationNamePlaceholder`),"aria-invalid":T,"aria-describedby":T?`integration-name-error`:void 0,className:`w-full rounded-lg border bg-surface px-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none ${T?`border-danger focus:border-danger`:`border-border focus:border-primary/50`}`}),T&&x(`p`,{id:`integration-name-error`,"data-testid":`integration-name-error`,className:`mt-1 text-xs text-danger`,children:p(`integrations.nameRequired`,`Name is required`)})]}),t&&x(cg,{schema:t,values:g,onChange:e=>{_(e),y(null)},onAction:async(i,a,o)=>{let s=await S.mutateAsync({addonId:e,action:i,input:o??{}});if(n&&typeof s==`object`&&s){let n=s;if(!(typeof n.token==`string`||typeof n.sslCertificate==`string`||typeof n.host==`string`))return s;let i={...g};for(let[e,t]of Object.entries(n))typeof t==`string`&&e!==`summary`&&(i[e]=t);let a=Yn(t,i);_(a),y(null),b.mutate({addonId:e,id:null,values:a,...r===void 0?{}:{kind:r}})}return s}}),v&&x(dg,{verdict:v}),s(`div`,{className:`flex items-center justify-between pt-2`,children:[x(G,{variant:`unstyled`,onClick:f,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:p(`integrations.back`)}),s(`div`,{className:`flex items-center gap-2`,children:[u&&s(G,{variant:`outline`,size:`sm`,onClick:u,"data-testid":`integration-scan`,children:[x(ge,{className:`h-3.5 w-3.5`}),p(`integrations.scanFromForm`,`Scan the network`)]}),n&&x(G,{variant:`unstyled`,onClick:()=>b.mutate({addonId:e,id:null,values:Yn(t,g),...r===void 0?{}:{kind:r}}),disabled:b.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 disabled:cursor-not-allowed`,children:b.isPending?p(`integrations.testing`):p(`integrations.testConnection`)}),s(`div`,{className:`flex flex-col items-end gap-1`,children:[T&&x(`p`,{"data-testid":`integration-name-submit-error`,className:`text-xs text-danger`,children:p(`integrations.nameRequiredSubmit`,`Enter a name before continuing.`)}),x(G,{variant:`unstyled`,onClick:()=>{T||d({name:m,config:Yn(t,g)})},disabled:!E||l,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:l?p(`integrations.saving`,{defaultValue:`Saving…`}):o??p(`integrations.forward`)})]})]})]})]})}var Q_=new Set([`@camstack/server`,`@camstack/types`,`@camstack/sdk`,`@camstack/shm-ring`,`@camstack/ui-library`]);function $_(e){return e!==void 0&&Q_.has(e)}var ev=`@camstack/addon-agent-ui`;function tv(e){return $_(e)||e===ev}function nv(e){return e.integrationSection===void 0?$_(e.packageName)?`system`:`providers`:e.integrationSection}function rv(e){let t=new Set;for(let n of e??[])nv(n.manifest)===`system`&&t.add(n.manifest.id);return t}function iv(e,t){return{providers:e.filter(e=>!t.has(e.addonId)),system:e.filter(e=>t.has(e.addonId))}}function av(e,t){return[...e].sort((e,n)=>e.name.localeCompare(n.name,t,{sensitivity:`base`}))}var ov=/\.(svg|png|jpe?g|webp)$/i,sv=`provider-`;function cv(e){return typeof e==`string`&&ov.test(e)&&!e.includes(`..`)}function lv(e){let t=[];for(let n of e??[]){let e=n,r=e?.manifest?.id;if(typeof r!=`string`||r.length===0)continue;let i=e?.declaration?.icon??e?.manifest?.icon;cv(i)&&t.push([r,i])}return new Map(t)}function uv(e,t){if(!t)return null;let n=t.startsWith(sv)?[t]:[t,`${sv}${t}`];for(let t of n){let n=e.get(t);if(n)return B(`/api/addon-assets/${encodeURIComponent(t)}/${n}`)}return null}O();var dv=5*6e4,fv=j(new Map);function pv({children:e}){let{data:t}=la(void 0,{staleTime:dv}),n=m(()=>lv(t),[t]);return x(fv.Provider,{value:n,children:e})}function mv(e){return uv(I(fv),e)}O();var hv={amcrest:{icon:ar,color:`#3b82f6`,label:`Amcrest`},hikvision:{icon:_e,color:`#a855f7`,label:`Hikvision`},reolink:{icon:Oe,color:`#06b6d4`,label:`Reolink`},homeassistant:{icon:Me,color:`#22d3ee`,label:`Home Assistant`},rtsp:{icon:nt,color:`#78716c`,label:`RTSP`},onvif:{icon:nt,color:`#78716c`,label:`ONVIF`}},gv={sm:`h-4 w-4`,md:`h-5 w-5`,lg:`h-6 w-6`,xl:`h-16 w-16`},_v={sm:`h-7 w-7`,md:`h-8 w-8`,lg:`h-10 w-10`,xl:`h-16 w-16`};function vv(e){let t=e.toLowerCase();return t.startsWith(`provider-`)?t.slice(9):t}function yv(e){return hv[vv(e)]??{icon:ar,color:`#78716c`,label:e}}function bv({type:e,size:t=`md`,showLabel:n,iconUrl:r}){let i=yv(e),a=i.icon,[o,c]=w(new Set),l=[r,mv(e)].find(e=>typeof e==`string`&&e!==``&&!o.has(e));return s(`div`,{className:`flex items-center gap-2`,children:[x(`div`,{className:`flex items-center justify-center rounded-lg ${_v[t]}`,style:{backgroundColor:`${i.color}15`},children:l===void 0?x(a,{className:gv[t],style:{color:i.color}}):x(`img`,{src:l,alt:i.label,className:gv[t],onError:()=>c(e=>new Set([...e,l]))})}),n&&x(`span`,{className:`text-xs font-medium text-foreground-subtle`,children:i.label})]})}function xv({children:e}){return x(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2 sm:gap-3 lg:grid-cols-3`,children:e})}function Sv({addonId:e,name:t,openLabel:n,onOpen:r,body:i,footer:a,disabled:o=!1,testId:c,buttonTestId:l,iconUrl:u}){return s(`article`,{"data-testid":c,className:`relative flex min-w-0 items-stretch gap-3 overflow-x-clip rounded-lg border border-border bg-surface p-3`,children:[x(G,{type:`button`,variant:`ghost`,"aria-label":n,disabled:o,"data-testid":l,onClick:r,className:`absolute inset-0 z-0 h-auto w-auto rounded-lg p-0 focus-visible:ring-2 focus-visible:ring-primary`}),x(`div`,{className:`pointer-events-none relative z-10 flex w-20 shrink-0 items-center justify-center`,children:x(bv,{type:e,size:`xl`,...u===void 0?{}:{iconUrl:u}})}),s(`div`,{className:`pointer-events-none relative z-10 grid min-w-0 flex-1 grid-rows-[1fr_auto_1fr] gap-1`,children:[x(`p`,{className:`min-w-0 self-start truncate text-sm font-semibold text-foreground`,children:t}),i,x(`div`,{className:`self-end justify-self-start`,children:a})]})]})}function Cv({kind:e,children:t}){let{t:n}=q(),r=`integrations-section-${e}`;return s(`section`,{"aria-labelledby":r,"data-testid":r,className:`min-w-0 space-y-2`,children:[x(`h2`,{id:r,className:Se,children:e===`providers`?n(`integrations.sections.providers`,`Providers`):n(`integrations.sections.system`,`System`)}),t]})}var wv=`(hover: none) and (pointer: coarse)`;function Tv(){if(typeof window>`u`||typeof window.matchMedia!=`function`)return!0;try{return!window.matchMedia(wv).matches}catch{return!0}}O();function Ev(e,t){return`${e.name} ${e.description} ${e.addonId}`.toLowerCase().includes(t)}function Dv({onSelect:e,onClose:t,pendingAddonId:n=null,source:r}){let{t:i,i18n:a}=q(),o=ll(),[c,l]=w(``),u=p(null),d=ca(void 0,{enabled:r===void 0}),f=r===void 0?d.data:void 0,h=r===void 0&&d.isLoading;S(()=>{h||!Tv()||u.current?.focus()},[h]);let{data:g}=la(void 0),_=n!==null,v=m(()=>r===void 0?(f??[]).map(n=>{let r=n.instanceMode===`unique`&&n.existingInstances.length>0;return{key:n.addonId,addonId:n.addonId,name:n.name,description:n.description??``,open:()=>{let i=n.existingInstances[0];r&&i!==void 0?(t(),o(K_(n.addonId,i.id))):e(n.addonId,n.instanceMode,n.discoveryMode,n.providerLabel??n.name,n.kind,n.brokerKind,n.mode,n.canTest)},footer:r?s(`span`,{className:`flex items-center gap-1 text-xs font-medium text-foreground-subtle`,children:[x(le,{className:`h-3 w-3`}),i(`integrations.manage`)]}):null}}):r.providers.map(e=>({...e,key:e.kind===void 0?e.addonId:`${e.addonId}-${e.kind}`,open:()=>r.onPick(e.addonId,e.kind),footer:null})),[r,f,t,e,o,i]),y=m(()=>{let e=c.trim().toLowerCase();return e.length===0?v:v.filter(t=>Ev(t,e))},[v,c]),b=m(()=>{let e=iv(y,rv(g));return{providers:av(e.providers,a.language),system:av(e.system,a.language)}},[y,g,a.language]);if(h)return x(`div`,{className:`grid grid-cols-1 gap-2 p-2 sm:grid-cols-2 lg:grid-cols-3`,children:[1,2,3,4].map(e=>x(`div`,{className:`h-24 rounded-lg bg-surface animate-pulse`},e))});let C=e=>x(xv,{children:e.map(e=>x(Sv,{testId:`provider-card-${e.key}`,buttonTestId:`provider-pick-${e.key}`,addonId:e.addonId,...e.iconUrl===void 0?{}:{iconUrl:e.iconUrl},name:e.name,openLabel:e.name,disabled:_,onOpen:e.open,body:e.description.length>0?x(`p`,{className:`line-clamp-2 text-xs text-foreground-muted`,children:e.description}):x(`span`,{}),footer:n===e.addonId?x(H,{className:`h-4 w-4 animate-spin text-primary`}):e.footer},e.key))});return s(`div`,{className:`space-y-3`,"data-testid":`provider-picker`,children:[s(`div`,{className:`relative`,children:[x(ne,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`,"aria-hidden":!0}),x(W,{ref:u,type:`search`,value:c,onChange:e=>l(e.target.value),placeholder:i(`integrations.searchProviders`,`Search integrations…`),className:`pl-8`,"data-testid":`provider-picker-search`,"data-dialog-autofocus":!0,"aria-label":i(`integrations.searchProviders`,`Search integrations…`)})]}),b.providers.length>0&&x(Cv,{kind:`providers`,children:C(b.providers)}),b.system.length>0&&x(Cv,{kind:`system`,children:C(b.system)}),y.length===0&&x(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:v.length===0?i(`integrations.noProviders`):i(`integrations.noProvidersMatch`,`No integrations match your search.`)})]})}function Ov(e){return e.setupIntegration===!0||e.prefilledConfig.setupIntegration===!0}function kv(e,t,n){let r={};for(let[e,n]of Object.entries(t.prefilledConfig))e!==`setupIntegration`&&(r[e]=typeof n==`string`&&e===`host`?n.trim():n);let i=n?.trim()??``;return{addonId:e,name:i.length>0?Wn(i):t.suggestedName,config:r,...t.stableId===void 0?{}:{originStableId:t.stableId}}}function Av(e,t,n){return Ov(t)?kv(e,t,n):null}function jv(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Mv(e){if(!jv(e)||!jv(e.integrationSeed))return null;let t=e.integrationSeed,n=t.addonId,r=t.name,i=t.config;if(typeof n!=`string`||n.length===0||typeof r!=`string`||!jv(i))return null;let a={};for(let[e,t]of Object.entries(i))a[e]=t;let o=t.originStableId;return{addonId:n,name:r,config:a,...typeof o==`string`&&o.length>0?{originStableId:o}:{}}}function Nv(e){let t=new Map;for(let n of e)t.set(n.stableId,n);let n=e=>{let n=e.parentStableId;if(n===void 0||n===e.stableId)return null;let r=t.get(n);if(r===void 0)return null;let i=new Set([e.stableId]),a=r;for(;a!==void 0;){if(i.has(a.stableId))return null;i.add(a.stableId),a=a.parentStableId===void 0?void 0:t.get(a.parentStableId)}return r},r=new Map,i=[];for(let t of e){let e=n(t);if(e===null){i.push(t);continue}let a=r.get(e.stableId)??[];a.push(t),r.set(e.stableId,a)}let a=e=>({candidate:e,children:(r.get(e.stableId)??[]).map(a)});return i.map(a)}function Pv(e){return e.flatMap(e=>[e.candidate,...Pv(e.children)])}O();var Fv=6e4;function Iv(){let e=fa({},{refetchInterval:Fv}),{refetch:t}=e,n=b(()=>void t(),[t]);return{count:e.data===void 0?null:e.data.proposals.length,refresh:n}}function Lv({count:e}){return e===null||e===0?null:x(Ma,{variant:`info`,style:`fill`,size:`sm`,"data-testid":`discovery-pill`,children:e})}function Rv({onSetupIntegration:e}){let{t}=q(),n=fa({},{refetchInterval:Fv}),r=ji(),i=Li(),[a,o]=w(new Set),{refetch:c}=n,l=b(async(e,t)=>{o(t=>new Set(t).add(e));try{await t(),c()}catch{}finally{o(t=>{let n=new Set(t);return n.delete(e),n})}},[c]),u=b(async t=>{let n=Av(t.addonId,t.candidate);if(n!==null){e(n);return}await l(t.id,()=>r.mutateAsync({addonId:t.addonId,candidate:t.candidate}))},[r,e,l]),d=b(e=>l(e.id,()=>i.mutateAsync({id:e.id})),[i,l]),f=n.data?.proposals??[];return f.length===0?null:s(`section`,{className:`space-y-2`,"data-testid":`discovery-proposals`,children:[s(`h3`,{className:`flex items-center gap-2`,children:[x(`span`,{className:Se,children:t(`integrations.discoveryProposals.title`,`Found in the background`)}),s(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`(`,f.length,`)`]})]}),x(`div`,{className:`space-y-1.5`,children:f.map(e=>s(`div`,{"data-testid":`discovery-proposal`,className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-2`,children:[s(`div`,{className:`min-w-0 flex-1`,children:[x(`p`,{className:`truncate text-sm font-medium text-foreground`,children:e.candidate.suggestedName}),x(`p`,{className:`truncate text-xs text-foreground-muted`,children:e.addonId})]}),a.has(e.id)?x(H,{className:`h-4 w-4 animate-spin text-foreground-muted`,"aria-hidden":!0}):s(F,{children:[x(G,{variant:`secondary`,size:`sm`,onClick:()=>void d(e),children:t(`integrations.discoveryProposals.dismiss`,`Dismiss`)}),s(G,{size:`sm`,onClick:()=>void u(e),children:[x(mt,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),t(`integrations.discoveryProposals.adopt`,`Adopt`)]})]})]},e.id))})]})}var zv=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\/(\d{1,2})$/;function Bv(e){let t=zv.exec(e.trim());if(t===null)return{ok:!1,reason:`format`};let n=[t[1],t[2],t[3],t[4]].map(e=>Number(e));if(n.some(e=>e>255))return{ok:!1,reason:`format`};let r=Number(t[5]);return r>32?{ok:!1,reason:`format`}:r<22?{ok:!1,reason:`prefix`}:{ok:!0,cidr:`${n.join(`.`)}/${r}`}}O();function Vv(){let{t:e}=q(),t=ka(),n=Tr({onSuccess:()=>void t.refetch()}),[r,i]=w(``),[a,o]=w(null),c=t.data?.subnets??[],l=async t=>{try{return await n.mutateAsync({subnets:[...t]}),!0}catch{return o(e(`integrations.scanNetworkModal.subnets.saveFailed`,`The network list could not be saved.`)),!1}},u=async()=>{let t=Bv(r);if(!t.ok){o(t.reason===`prefix`?e(`integrations.scanNetworkModal.subnets.errorPrefix`,`A network larger than a /22 cannot be scanned.`):e(`integrations.scanNetworkModal.subnets.errorFormat`,`Enter a network like 192.0.2.0/24.`));return}if(c.includes(t.cidr)){o(e(`integrations.scanNetworkModal.subnets.errorDuplicate`,`Already in the list.`));return}o(null),await l([...c,t.cidr])&&i(``)};return s(`section`,{className:`space-y-2`,"data-testid":`scan-subnets`,children:[x(`h3`,{className:Se,children:e(`integrations.scanNetworkModal.subnets.title`,`Extra networks to scan`)}),x(`p`,{className:`text-xs text-foreground-muted`,children:c.length===0?e(`integrations.scanNetworkModal.subnets.none`,`Only this hub's own networks are scanned.`):e(`integrations.scanNetworkModal.subnets.hint`,`Every scan covers this hub's own networks and these.`)}),c.length>0&&x(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map(e=>x(Ua,{label:e,testId:`scan-subnet-${e}`,onRemove:()=>void l(c.filter(t=>t!==e))},e))}),s(`div`,{className:`flex items-start gap-2`,children:[s(`div`,{className:`min-w-0 flex-1`,children:[x(W,{value:r,onChange:e=>{i(e.target.value),o(null)},onKeyDown:e=>{e.key===`Enter`&&u()},placeholder:`192.0.2.0/24`,state:a===null?`default`:`error`,"aria-label":e(`integrations.scanNetworkModal.subnets.title`,`Extra networks to scan`),"data-testid":`scan-subnet-input`}),a!==null&&x(`p`,{className:`mt-1 text-xs text-danger`,children:a})]}),s(G,{variant:`outline`,size:`sm`,onClick:()=>void u(),disabled:n.isPending||r.trim().length===0,"data-testid":`scan-subnet-add`,children:[x(Ye,{className:`h-3.5 w-3.5`}),e(`integrations.scanNetworkModal.subnets.add`,`Add network`)]})]})]})}O();function Hv({open:e,onClose:t,scope:n,onSetupIntegration:r,pickMode:i=`adopt`,onAdopted:a}){let{t:o}=q(),c=ji(),[l,u]=w(new Set),[d,f]=w(new Set),[p,h]=w(new Set),{data:g}=Zi({projection:`slim`}),_=m(()=>new Set((g??[]).map(e=>e.stableId)),[g]),v=b(async(e,t)=>{f(e=>new Set(e).add(t.stableId));try{await c.mutateAsync({addonId:e,candidate:t}),a?.(),u(e=>new Set(e).add(t.stableId)),h(e=>{let n=new Set(e);return n.delete(t.stableId),n})}catch{}finally{f(e=>{let n=new Set(e);return n.delete(t.stableId),n})}},[c,a]),y=b(async(e,n)=>{let a=i===`fill`?kv(e,n):Av(e,n);if(a!==null){r?.(a),t();return}await v(e,n)},[v,t,r,i]),S=b(e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),C=b(()=>{u(new Set),h(new Set)},[]),T=m(()=>({existingStableIds:_,adopted:l,adopting:d,selection:{selected:p,toggle:S},pick:y,adoptOne:v,fill:i===`fill`}),[_,l,d,p,S,y,i]),E=n?o(`integrations.scanNetworkModal.titleScoped`,`Scan network — {{label}}`,{label:n.label}):o(`integrations.scanNetworkModal.title`,`Scan network for devices`);return x(Mi,{open:e,onOpenChange:e=>!e&&t(),children:s(Ir,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[x(Yr,{children:x(qi,{children:s(`span`,{className:`flex items-center gap-2`,children:[x(ge,{className:`h-4 w-4 text-primary`}),E]})})}),s(zi,{className:`space-y-4`,children:[x(Vv,{}),!n&&i===`adopt`&&r&&x(Rv,{onSetupIntegration:e=>{t(),r(e)}}),n?x(Yv,{scope:n,row:T,onReset:C}):x(Jv,{row:T,onReset:C})]})]})})}function Uv(e,t){return!t&&e.selectable!==!1&&!Ov(e)}function Wv({addonId:e,nodes:t,row:n,depth:r}){return x(`div`,{className:r===0?`space-y-1.5`:`ml-4 space-y-1.5 border-l border-border pl-3`,"data-testid":r===0?void 0:`scan-children`,children:t.map(t=>s(`div`,{className:`space-y-1.5`,children:[x(Gv,{addonId:e,candidate:t.candidate,row:n}),t.children.length>0&&x(Wv,{addonId:e,nodes:t.children,row:n,depth:r+1})]},t.candidate.stableId))})}function Gv({addonId:e,candidate:t,row:n}){let{t:r}=q(),i=t.prefilledConfig.host,a=typeof i==`string`?i:null,o=n.existingStableIds.has(t.stableId)||t.alreadyOnboarded===!0||t.onboardedDeviceId!==void 0,c=n.adopted.has(t.stableId)||o,l=n.adopting.has(t.stableId),u=n.fill||Ov(t),d=!c&&(u||t.selectable!==!1),f=d&&Uv(t,n.fill);return s(`div`,{className:`flex items-center gap-3 rounded-lg border border-border bg-surface px-3 py-2`,"data-testid":`scan-row-${t.stableId}`,children:[f&&x(L,{checked:n.selection.selected.has(t.stableId),onChange:()=>n.selection.toggle(t.stableId),disabled:l,"aria-label":r(`integrations.scanNetworkModal.select`,`Select {{name}}`,{name:t.suggestedName})}),s(`div`,{className:`min-w-0 flex-1`,children:[x(`p`,{className:`truncate text-xs font-medium text-foreground`,children:t.suggestedName}),a&&x(`p`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,children:a}),o&&t.onboardedName!==void 0&&x(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.onboardedName})]}),c?s(`span`,{className:`flex items-center gap-1 text-[11px] text-foreground-subtle`,children:[x(mt,{className:`h-3.5 w-3.5`}),` `,o?r(`integrations.scanNetworkModal.alreadyAdded`,`Already added`):r(`integrations.scanNetworkModal.added`,`Added`)]}):d?s(G,{size:`sm`,variant:u?`outline`:`primary`,onClick:()=>void n.pick(e,t),disabled:l,children:[l?x(H,{className:`h-3.5 w-3.5 animate-spin`}):u?null:x(yt,{className:`h-3.5 w-3.5`}),u?n.fill?r(`integrations.scanNetworkModal.use`,`Use`):r(`integrations.scanNetworkModal.setUp`,`Set up`):r(`common.add`,`Add`)]}):null]})}function Kv({addonId:e,label:t,candidates:n,row:r}){let i=m(()=>Nv(n),[n]);return s(`section`,{className:`space-y-2`,"data-testid":`scan-group-${e}`,children:[s(`h3`,{className:`flex items-center gap-2`,children:[x(bv,{type:e,size:`sm`}),x(`span`,{className:Se,children:t}),s(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`(`,n.length,`)`]})]}),x(Wv,{addonId:e,nodes:i,row:r,depth:0})]})}function qv(e,t){return e.flatMap(e=>Pv(Nv(e.candidates)).filter(e=>Uv(e,t)).map(t=>({addonId:e.addonId,candidate:t})))}function Jv({row:e,onReset:t}){let{t:n}=q(),r=ni(),i=b(()=>{t(),r.mutate({})},[r,t]);S(()=>{!r.isPending&&!r.data&&i()},[]);let a=m(()=>(r.data?.groups??[]).filter(e=>e.candidates.length>0),[r.data]),o=m(()=>a.reduce((e,t)=>e+t.candidates.length,0),[a]),c=m(()=>qv(a,e.fill),[a,e.fill]);return s(`div`,{className:`space-y-4`,children:[s(`div`,{className:`flex items-center justify-between gap-2`,children:[x(`p`,{className:`text-xs text-foreground-subtle`,children:!r.isPending&&a.length>0?n(`integrations.scanNetworkModal.found`,{count:o}):null}),s(`div`,{className:`flex items-center gap-2`,children:[x(Xv,{entries:c,row:e}),s(G,{variant:`outline`,size:`sm`,onClick:i,disabled:r.isPending,children:[x(Ae,{className:`h-3.5 w-3.5 ${r.isPending?`animate-spin`:``}`}),n(`integrations.scanNetworkModal.reScan`,`Re-scan`)]})]})]}),r.isPending&&x(Qv,{label:n(`integrations.scanNetworkModal.scanningTheLocalNetwork`,`Scanning the local network…`)}),!r.isPending&&r.isError&&x($v,{}),!r.isPending&&r.data&&a.length===0&&x(Zv,{}),!r.isPending&&a.map(t=>x(Kv,{addonId:t.addonId,label:t.label,candidates:t.candidates,row:e},t.addonId))]})}function Yv({scope:e,row:t,onReset:n}){let{t:r}=q(),i=Ra({addonId:e.addonId}).data??null,[a,o]=w({}),c=So(),l=b(()=>{n(),c.mutate({addonId:e.addonId,params:a})},[c,e.addonId,a,n]),u=m(()=>c.data?.candidates??[],[c.data]),d=m(()=>qv([{addonId:e.addonId,candidates:u}],t.fill),[e.addonId,u,t.fill]);return s(`div`,{className:`space-y-4`,children:[i&&x(cg,{schema:i,values:a,onChange:o}),s(G,{onClick:l,disabled:c.isPending,children:[c.isPending?x(H,{className:`h-3.5 w-3.5 animate-spin`}):x(ge,{className:`h-3.5 w-3.5`}),c.isPending?r(`integrations.scanNetworkModal.scanning`,`Scanning…`):r(`integrations.scanNetworkModal.scan`,`Scan`)]}),x(Xv,{entries:d,row:t}),c.isError&&x($v,{}),!c.isPending&&c.data&&u.length===0&&x(Zv,{}),!c.isPending&&u.length>0&&s(`div`,{className:`space-y-2`,children:[x(`p`,{className:`text-xs text-foreground-subtle`,children:r(`integrations.scanNetworkModal.foundShort`,{count:u.length})}),x(Kv,{addonId:e.addonId,label:e.label,candidates:u,row:t})]})]})}function Xv({entries:e,row:t}){let{t:n}=q(),r=e.filter(e=>t.selection.selected.has(e.candidate.stableId));if(r.length===0)return null;let i=async()=>{for(let e of r)await t.adoptOne(e.addonId,e.candidate)};return s(G,{size:`sm`,onClick:()=>void i(),"data-testid":`scan-add-selected`,children:[x(yt,{className:`h-3.5 w-3.5`}),n(`integrations.scanNetworkModal.addSelected`,`Add selected ({{count}})`,{count:r.length})]})}function Zv(){let{t:e}=q();return x(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:e(`integrations.scanNetworkModal.noDevicesRespondedToThe`,`No devices responded to the scan.`)})}function Qv({label:e}){return s(`div`,{className:`flex flex-col items-center py-12`,children:[x(H,{className:`h-6 w-6 animate-spin text-primary`}),x(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:e})]})}function $v(){let{t:e}=q();return s(`div`,{className:`flex items-start gap-3 rounded-lg border border-danger/40 bg-danger/10 px-4 py-3`,children:[x(Ne,{className:`mt-0.5 h-4 w-4 shrink-0 text-danger`}),x(`p`,{className:`text-xs text-danger`,children:e(`integrations.scanNetworkModal.theScanFailedTryAgain`,`The scan failed. Try again.`)})]})}O();function ey(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var ty=2e4;function ny({open:e,onClose:t,seed:n=null,pickFrom:r}){let{t:i}=q(),a=ll(),o=N(),[c,l]=w(`picker`),[u,d]=w(null),[f,p]=w(null),[h,g]=w(`manual`),[_,v]=w(null),[y,b]=w(``),[C,T]=w(null),[E,D]=w(null),[O,k]=w(!1),[A,j]=w({}),[M,ee]=w(``),[P,I]=w(!1),[L,te]=w(0),[ne,re]=w(``),ie=Er({},{enabled:e&&c===`config`}),ae=(pa({addonId:u??``},{enabled:e&&c===`config`&&u!==null}).data?.kinds??[]).filter(e=>e.canTest!==!1),oe=ae.length===1?ae[0]?.id:void 0,se=u!==null&&(ie.data?.providers??[]).some(e=>e.addonId===u),R=n?.config.host,ce=n===null?``:`${n.addonId}\0${n.name}\0${typeof R==`string`?R:``}`;e&&n!==null&&M!==ce&&(ee(ce),d(n.addonId),b(n.name),j({...n.config}),l(`config`));let le=ca(void 0,{enabled:e&&n!==null}),ue=le.data?.find(e=>e.addonId===u)?.mode??`account`,{data:de}=Ga({addonId:u??``,id:null,mode:ue,...n?.originStableId===void 0?{}:{candidateStableId:n.originStableId}},{enabled:u!=null}),fe=m(()=>de?ey(de):null,[de]),z=Si({onSuccess:()=>{o.invalidateQueries({queryKey:[[`integrations`]]}),o.invalidateQueries({queryKey:[[`integrationInstances`]]})}}),pe=Di(),me=pe.data;S(()=>{if(!e||n===null)return;let t=le.data?.find(e=>e.addonId===n.addonId);if(!t)return;k(t.canTest),g(t.discoveryMode);let r=t.providerLabel??t.name;typeof r==`string`&&r.length>0&&b(vn({providerLabel:r,mode:t.mode,brokerKind:t.brokerKind}))},[e,n,le.data]),S(()=>{c!==`discovery`||!f||!u||pe.isPending||pe.data||pe.mutate({addonId:u})},[c,f,u,pe]);let B=ji({onSuccess:()=>o.invalidateQueries({queryKey:[[`deviceManager`]]})});function he(e,t,n,r,i,a,o,s){if(z.isPending)return;let c=vn({providerLabel:r,mode:o,brokerKind:a});if(d(e),k(s),g(n),b(c),D(null),z.reset(),o===`broker`){if(!a){D(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}v(a),l(`broker`);return}if(o===`account`){l(`config`);return}ge(e,c)}async function ge(e,n){try{let r=await z.mutateAsync({addonId:e,name:n,values:{}});t(),xe(),a(`${K_(e,r.id)}&add=1`)}catch{}}async function _e(e){if(u)try{let t=await z.mutateAsync({addonId:u,name:e.name,values:e.config,...oe===void 0?{}:{kind:oe},...n!==null&&n.addonId===u&&n.originStableId!==void 0?{originStableId:n.originStableId}:{}});p(t.id),T(t.id),h===`auto`||h===`both`?l(`discovery`):be(t.id,{openAdd:!0})}catch{}}async function ve(e){if(u)try{let t=await z.mutateAsync({addonId:u,name:y,values:{brokerId:e}});T(t.id),p(t.id),be(t.id)}catch{}}async function ye(e){if(u){for(let t of e){let e=me?.find(e=>e.stableId===t);e&&await B.mutateAsync({addonId:u,candidate:e,...C===null?{}:{integrationId:C}})}be()}}function be(e,n){let r=e??f??u;if(t(),xe(),r&&u){let e=K_(u,r);a(n?.openAdd===!0?`${e}&add=1`:e)}}function xe(){l(`picker`),d(null),p(null),g(`manual`),v(null),b(``),T(null),D(null),z.reset(),k(!1),j({}),ee(``)}function Se(){t(),xe()}q_(e);let Ce=z.isPending,we=J_(Ce,ty);if(!e)return null;let Te={picker:r?.title??i(`integrations.newIntegration`),config:i(`integrations.configureIntegration`),discovery:i(`integrations.importDevices`),broker:i(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Ee=Ce?u:null,De=z.error,Oe=Ce&&!we;return s(F,{children:[x(Mi,{open:!0,onOpenChange:e=>{!e&&!Oe&&Se()},children:s(Ir,{width:c===`picker`?`xl`:`lg`,scroll:`body`,onCancel:e=>{Oe&&e.preventDefault()},children:[x(Yr,{children:x(qi,{children:Te[c]})}),s(zi,{children:[De&&!Ce&&x(`div`,{className:`mb-3 rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:De instanceof Error?De.message:String(De)}),c===`picker`&&s(F,{children:[E&&x(`div`,{className:`mb-3 rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:E}),x(Dv,{onSelect:he,onClose:Se,pendingAddonId:Ee,...r===void 0?{}:{source:r}})]}),c===`config`&&u&&x(Z_,{addonId:u,configSchema:fe??null,canTest:O,...oe===void 0?{}:{instanceKind:oe},initialName:y.length>0?y:void 0,initialConfig:{...A},onScan:se?()=>{re(y.length>0?y:u),I(!0)}:void 0,onSave:_e,onBack:()=>{j({}),l(`picker`)}},`${ce.length>0?ce:u}:${y}:${L}`),c===`broker`&&_&&x(Y_,{kind:_,onResolved:e=>{ve(e)},onBack:()=>l(`picker`)}),c===`discovery`&&f&&x(X_,{providerId:f,onImport:ye,onSkip:be})]}),Ce&&s(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-lg bg-background/85 backdrop-blur-sm px-6 text-center`,children:[x(H,{className:`h-6 w-6 animate-spin text-primary`}),x(`p`,{className:`text-xs font-medium text-foreground`,children:i(`integrations.creating`,{defaultValue:`Creating integration…`})}),!we&&x(`p`,{className:`text-[10px] text-foreground-subtle`,children:i(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),we&&s(F,{children:[x(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:i(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),x(G,{variant:`unstyled`,onClick:Se,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:i(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})}),P&&u!==null&&x(Hv,{open:P,scope:{addonId:u,label:ne},pickMode:`fill`,onClose:()=>I(!1),onSetupIntegration:e=>{b(e.name),j({...e.config}),te(e=>e+1)}})]})}O();function ry({functionCap:e,disabled:t,onCreated:n}){let{t:r}=q(),{options:i}=z_({functionCap:e,match:`link`}),[a,o]=w({at:`closed`});if(i.length===0)return null;let c=()=>o({at:`closed`});return s(F,{children:[s(G,{variant:`outline`,size:`sm`,disabled:t,onClick:()=>{let e=i.length===1?i[0]:void 0;o(e===void 0?{at:`choose`}:{at:`edit`,option:e})},children:[x(Ye,{className:`h-3.5 w-3.5`}),` `,r(`brokers.picker.createNew`)]}),a.at===`choose`&&x(ny,{open:!0,onClose:c,pickFrom:{title:r(`brokers.picker.createNew`),providers:i.map(e=>({addonId:e.addonId,kind:e.kind,name:e.label,description:``,...e.iconUrl===void 0?{}:{iconUrl:e.iconUrl}})),onPick:(e,t)=>{let n=i.find(n=>n.addonId===e&&n.kind===t);o(n===void 0?{at:`closed`}:{at:`edit`,option:n})}}}),a.at===`edit`&&x(V_,{functionCap:e,addonId:a.option.addonId,kind:a.option.kind,match:`link`,onClose:c,onSaved:e=>{c(),n(e)}})]})}var iy=`broker`;function ay({functionCap:e,kind:t,noneLabel:n,required:r,disabled:i,value:a,onChange:o}){return e===iy&&t!==void 0?x(U_,{kind:t,value:a,onChange:o,optional:r===!1,disabled:i===!0,...n===void 0?{}:{noneLabel:n}}):s(`div`,{className:`space-y-2`,children:[x(Ei,{functionCap:e,...t===void 0?{}:{kind:t},...n===void 0?{}:{noneLabel:n},value:a??``,disabled:i===!0,onChange:e=>o(e===``?null:e),controlId:`instance-picker-${e}-${t??`any`}`}),t===void 0&&x(`div`,{children:x(ry,{functionCap:e,disabled:i===!0,onCreated:o})})]})}function oy({deviceId:e}){let{t}=q(),n=ma(V().trpcClient,e);return n===null?null:x(Kr,{headingId:`device-web-interface-${String(e)}`,title:t(`device.webInterface.title`,`Web interface`),icon:gr,testId:`device-web-interface-card`,children:s(`div`,{className:`flex flex-wrap items-center justify-between gap-2 px-3 py-2 sm:px-4`,children:[s(`div`,{className:`min-w-0 text-xs`,children:[x(`div`,{className:`font-medium text-foreground`,children:n.label}),x(`div`,{className:`break-all text-foreground-muted`,children:n.host})]}),s(G,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>window.open(n.url,`_blank`,`noopener,noreferrer`),children:[x(wt,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),t(`device.webInterface.open`,`Open`)]})]})})}var sy={streaming:{icon:ve,labelKey:`capabilityBadges.streaming`},detection:{icon:Fe,labelKey:`capabilityBadges.detection`},recording:{icon:ke,labelKey:`capabilityBadges.recording`},audio:{icon:ae,labelKey:`capabilityBadges.audio`},snapshot:{icon:Ke,labelKey:`capabilityBadges.snapshot`},motion:{icon:bt,labelKey:`capabilityBadges.motion`},ptz:{icon:le,labelKey:`capabilityBadges.ptz`},webrtc:{icon:Oe,labelKey:`capabilityBadges.webrtc`},onvif:{icon:Qe,labelKey:`capabilityBadges.onvif`},analytics:{icon:Ze,labelKey:`capabilityBadges.analytics`},"battery-operated":{icon:z,labelKey:`capabilityBadges.battery`},"native-snapshot":{icon:Ke,labelKey:`capabilityBadges.nativeSnapshot`},"pan-tilt-zoom":{icon:le,labelKey:`capabilityBadges.ptz`},"two-way-audio":{icon:ae,labelKey:`capabilityBadges.twoWayAudio`},"doorbell-button":{icon:se,labelKey:`capabilityBadges.doorbell`},rebootable:{icon:Ae,labelKey:`capabilityBadges.rebootable`},"vacuum-has-ai":{icon:Tt,labelKey:`capabilityBadges.aiObstacle`},"mower-has-targeted-mowing":{icon:ot,labelKey:`capabilityBadges.targetedMowing`}},cy=ze;function ly({capabilities:e,showLabels:t=!1}){let{t:n}=q();return x(`div`,{className:`flex items-center gap-1 flex-wrap`,children:e.map(e=>{let r=sy[e],i=r?.icon??cy,a=r?n(r.labelKey):e;return s(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-surface-hover px-1.5 py-0.5 text-[10px] text-foreground-subtle`,title:a,children:[x(i,{className:`h-3 w-3`}),t&&x(`span`,{children:a})]},e)})})}var uy=`customize`,dy=`/build/compositions/new`,fy=`/build/compositions/:blockId`,py=`/build?tab=custom-device`;function my(e){return`/devices/${e}`}function hy(e){return`/devices/${e}?tab=${uy}`}function gy(e){return`/build/compositions/${encodeURIComponent(e)}`}var _y=`template`,vy=`terminalId`;function yy(e){return`/build?${new URLSearchParams({tab:`custom-device`,new:`helper`,[_y]:`terminal`,[vy]:e}).toString()}`}function by({label:e,value:t,layout:n=`inline`}){return n===`stacked`?s(`div`,{className:`min-w-0 flex flex-col gap-0.5 px-0.5`,children:[x(`span`,{className:`text-[11px] text-foreground-subtle`,children:e}),x(`div`,{className:`min-w-0 text-[11px] text-foreground`,children:t})]}):s(`div`,{className:`${be} flex items-start gap-2 sm:gap-3`,children:[x(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),x(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}O();function xy(e,t){return e.kind===`same-device`?`same-device`:e.a.deviceId===t?`powers`:`powered-by`}function Sy(e){if(!e.ok)throw Error(e.message);return e.link}function Cy(e){return e.filter(e=>e.state!==`dismissed`)}function wy({deviceId:e}){let{t}=q(),n=oo({deviceId:e}),r=x(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-y border-border`,children:t(`overviewAdapters.identityLinks.header`,`Linked devices, matched on the identifiers above.`)});if(n.error)return s(F,{children:[r,x(`p`,{className:`px-3 sm:px-4 py-2 text-xs text-foreground-muted`,children:t(`overviewAdapters.identityLinks.unavailable`,`Linked devices could not be read.`)})]});if(n.data===void 0)return s(F,{children:[r,x(`div`,{className:`px-3 sm:px-4 py-2`,"data-testid":`identity-links-pending`,children:x(yr,{className:`h-4 w-1/2`})})]});if(n.data.status===`not-loaded`)return s(F,{children:[r,x(`p`,{className:`px-3 sm:px-4 py-2 text-xs text-foreground-muted`,children:t(`overviewAdapters.identityLinks.notLoaded`,`Linked devices are not read yet.`)})]});let i=Cy(n.data.links);return s(F,{children:[r,i.length===0?x(`p`,{className:`px-3 sm:px-4 py-2 text-xs text-foreground-muted`,children:t(`overviewAdapters.identityLinks.none`,`No linked devices.`)}):x(`div`,{className:`divide-y divide-border`,children:i.map(t=>x(Ty,{link:t,deviceId:e},t.id))})]})}function Ty({link:e,deviceId:t}){let{t:n}=q(),r=e.a.deviceId===t?e.b:e.a,{data:i}=$a({deviceId:r.deviceId}),a=N(),o={onSuccess:()=>void a.invalidateQueries({queryKey:[[`deviceManager`]]})},c=bi(o),l=Br(o),u=Na(o),d={"same-device":n(`overviewAdapters.identityLinks.sameDevice`,`Same device`),"powered-by":n(`overviewAdapters.identityLinks.poweredBy`,`Powered by`),powers:n(`overviewAdapters.identityLinks.powers`,`Powers`)},[f,p]=w(null),m=e=>{p(null),e.then(Sy).catch(e=>{p(e instanceof Error?e.message:String(e))})},h=i?.name??`#${r.deviceId}`,g=e.state===`proposed`;return x(by,{label:d[xy(e,t)],value:s(`div`,{className:`flex flex-wrap items-center gap-2 min-w-0`,children:[x(ku,{to:my(r.deviceId),className:`text-primary hover:underline truncate`,children:h}),g&&x(`span`,{className:`text-[11px] text-warning`,children:n(`overviewAdapters.identityLinks.proposed`,`Suggested`)}),e.evidenceGone===!0&&x(`span`,{className:`text-[11px] text-foreground-subtle`,children:n(`overviewAdapters.identityLinks.evidenceGone`,`No longer matched`)}),x(`span`,{className:`ml-auto flex gap-1.5`,children:g?s(F,{children:[x(G,{size:`sm`,disabled:c.isPending,onClick:()=>m(c.mutateAsync({linkId:e.id})),children:n(`overviewAdapters.identityLinks.confirm`,`Confirm`)}),x(G,{size:`sm`,variant:`outline`,disabled:l.isPending,onClick:()=>m(l.mutateAsync({linkId:e.id})),children:n(`overviewAdapters.identityLinks.dismiss`,`Dismiss`)})]}):x(Ia,{size:`sm`,label:n(`overviewAdapters.identityLinks.unlink`,`Unlink`),title:n(`overviewAdapters.identityLinks.unlinkTitle`,`Unlink these devices?`),description:n(`overviewAdapters.identityLinks.unlinkBody`,`The link is removed and not suggested again. Anything it added in Customize is removed with it.`),action:async()=>Sy(await u.mutateAsync({linkId:e.id}))})}),f!==null&&x(`span`,{className:`basis-full text-[11px] text-danger`,children:f})]})})}O();function Ey(e){return Zi({addonId:e,projection:`slim`})}function Dy(e){return $a({deviceId:e},{enabled:Number.isFinite(e)})}var Oy=3e4,ky=2e3;function Ay(e){let t=p(0);return t.current===0&&(t.current=Date.now()),Lr({parentDeviceId:e},{enabled:Number.isFinite(e),staleTime:0,refetchOnMount:`always`,refetchInterval:e=>{let n=e.state.data;return n&&n.length>0||Date.now()-t.current>=Oy?!1:ky}})}O();function jy({deviceId:e}){let{t}=q(),n=N(),{data:r}=Dy(e),{data:i}=Ay(e),[a,o]=w(null),c=ki({onSuccess:()=>{o(null),n.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{o(`Could not change primary child: ${e.message}`)}});if(r==null)return null;let l=String(r.type??``);if(l!==U.Container)return null;let u=String(r.name??``),d=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:ja(e,u),...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}}));if(d.length<=1)return null;let f=Co(d,typeof r.linkDeviceId==`number`?r.linkDeviceId:null,typeof r.primaryChildEntityId==`string`?r.primaryChildEntityId:null,l,nn(r)),p=f===null?d[0].id:f.id;return s(F,{children:[x(by,{label:t(`shared.primaryChildRow.primaryChild`,`Primary child`),value:x(ri,{childrenList:d,selectedId:p,onSetPrimary:t=>c.mutate({deviceId:e,primaryChildEntityId:t}),disabled:c.isPending})}),a!==null&&x(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:a})]})}O();var My=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`],Ny=[`mac`,`serial`,`vendor-uid`,`machine-uuid`,`hostname`,`ip`];function Py(e){let t=Bn.safeParse(e);if(!t.success)return[];let n=t.data;return Ny.flatMap(e=>{if(e===`mac`)return(n.mac??[]).map(t=>({key:e,value:t.value,derived:t.origin===`derived`}));let t=n[e];return t?[{key:e,value:t.value,derived:t.origin===`derived`}]:[]})}function Fy(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function Iy(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function Ly(){let{t:e}=q(),t=$i(),n=lo(),{data:r}=$a({deviceId:t??0},{enabled:t!==null}),{data:i}=Vi({deviceId:t??0},{enabled:t!==null}),{data:a}=oo({deviceId:t??0},{enabled:t!==null}),o=r??n??null,[c,l]=w(`identity`);if(t===null||!o)return null;let u=String(o.stableId??``),d=String(o.addonId??``),f=typeof o.integrationId==`string`&&o.integrationId.length>0?o.integrationId:null,p=typeof o.parentDeviceId==`number`?o.parentDeviceId:null,m=o.features??[],h=new Set([`device-status`,`feature-probe`,`device-ops`]),g=(i?.entries??[]).filter(e=>e.kind===`native`&&!h.has(e.capName)).map(e=>e.capName),_=m.length>0?m:g,v=o.metadata??null,y=Py(o.identifiers),b=a?.status===`answered`&&Cy(a.links).length>0,S=v!==null&&Object.keys(v).length>0||y.length>0||b;return s(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[s(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[x(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:e(`overviewAdapters.deviceInfoAdapter.deviceInfo`,`Device Info`)}),S&&s(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[x(Ry,{active:c===`identity`,onClick:()=>l(`identity`),label:e(`overviewAdapters.deviceInfoAdapter.identity`,`Identity`)}),x(Ry,{active:c===`hardware`,onClick:()=>l(`hardware`),label:e(`overviewAdapters.deviceInfoAdapter.hardware`,`Hardware`)})]})]}),(!S||c===`identity`)&&s(`div`,{className:`divide-y divide-border`,children:[x(by,{label:`ID`,value:s(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${t}`,s(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,u,`)`]})]})}),x(jy,{deviceId:t}),f!==null&&x(by,{label:e(`overviewAdapters.deviceInfoAdapter.integration`,`Integration`),value:x(`span`,{className:`font-mono text-[11px]`,children:f})}),p!==null&&x(by,{label:e(`overviewAdapters.deviceInfoAdapter.parent`,`Parent`),value:x(`span`,{className:`font-mono text-[11px]`,children:`#${String(p)}`})}),x(by,{label:e(`overviewAdapters.deviceInfoAdapter.provider`,`Provider`),value:x(bv,{type:d,size:`sm`,showLabel:!0})}),x(by,{label:e(`overviewAdapters.deviceInfoAdapter.capabilities`,`Capabilities`),value:_.length>0?x(ly,{capabilities:_,showLabels:!0}):x(`span`,{className:`text-[11px] text-foreground-subtle`,children:e(`overviewAdapters.deviceInfoAdapter.none`,`None`)})})]}),S&&c===`hardware`&&x(zy,{deviceId:t,metadata:v??{},identifiers:y})]})}function Ry({active:e,onClick:t,label:n}){return x(G,{variant:`unstyled`,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 zy({deviceId:e,metadata:t,identifiers:n}){let{t:r}=q(),i={mac:r(`overviewAdapters.deviceInfoAdapter.identifierMac`,`MAC address`),serial:r(`overviewAdapters.deviceInfoAdapter.identifierSerial`,`Serial number`),"vendor-uid":r(`overviewAdapters.deviceInfoAdapter.identifierVendorUid`,`Vendor ID`),"machine-uuid":r(`overviewAdapters.deviceInfoAdapter.identifierMachineUuid`,`Machine UUID`),hostname:r(`overviewAdapters.deviceInfoAdapter.identifierHostname`,`Hostname`),ip:r(`overviewAdapters.deviceInfoAdapter.identifierIp`,`IP address`)},a=My.filter(e=>e in t),o=Object.keys(t).filter(e=>!My.includes(e)).toSorted(),c=[...a,...o];return s(`div`,{children:[x(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-b border-border`,children:r(`overviewAdapters.deviceInfoAdapter.autoPopulatedByTheDriver`,`Auto-populated by the driver on every connect. Read-only.`)}),x(`div`,{className:`divide-y divide-border`,children:c.map(e=>x(by,{label:Fy(e),value:x(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:Iy(t[e])})},e))}),n.length>0&&s(F,{children:[x(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-y border-border`,children:r(`overviewAdapters.deviceInfoAdapter.identifiersDeclared`,`Identifiers declared by the provider. Read-only.`)}),x(`div`,{className:`divide-y divide-border`,children:n.map(e=>x(by,{label:i[e.key],value:s(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:[e.value,e.derived&&x(`span`,{className:`ml-1.5 text-foreground-subtle`,children:r(`overviewAdapters.deviceInfoAdapter.identifierDerived`,`(derived)`)})]})},`${e.key}:${e.value}`))})]}),x(wy,{deviceId:e})]})}function By(e){return e.hubReachable?e.authOk===!1?{kind:`auth-expired`}:{kind:`cluster-degraded`,offlineAgents:e.offlineAgents,offlineAgentIds:e.offlineAgentIds}:{kind:`hub-unreachable`}}function Vy(e){switch(e.kind){case`connected`:return null;case`reconnecting`:return{severity:`warning`,message:K.t(`connection.reconnecting`),i18nKey:`connection.reconnecting`,showSpinner:!0};case`cluster-degraded`:{let t=e.offlineAgentIds??[];return t.length>0?{severity:`warning`,message:K.t(`connection.degradedNodes`,{nodes:t.join(`, `),count:t.length}),i18nKey:`connection.degradedNodes`,i18nParams:{nodes:t.join(`, `),count:t.length},showSpinner:!0}:e.offlineAgents!==null&&e.offlineAgents>0?{severity:`warning`,message:K.t(`connection.degradedCount`,{count:e.offlineAgents}),i18nKey:`connection.degradedCount`,i18nParams:{count:e.offlineAgents},showSpinner:!0}:{severity:`warning`,message:K.t(`connection.degraded`),i18nKey:`connection.degraded`,showSpinner:!0}}case`hub-unreachable`:return{severity:`danger`,message:K.t(`connection.disconnected`),i18nKey:`connection.disconnected`,showSpinner:!0};case`auth-expired`:return{severity:`danger`,message:K.t(`connection.sessionExpired`),i18nKey:`connection.sessionExpired`,showSpinner:!1,action:`sign-in`}}}var Hy=4e3,Uy=5e3;function Wy(e){if(typeof e!=`object`||!e)return{offline:null,offlineIds:null,ok:null};let t={...e},n=typeof t.ok==`boolean`?t.ok:null,r=t.agents;if(typeof r!=`object`||!r)return{offline:null,offlineIds:null,ok:n};let i={...r},a=i.offline,o=typeof a==`number`?a:null,s=i.offlineIds;return{offline:o,offlineIds:Array.isArray(s)?s.filter(e=>typeof e==`string`):null,ok:n}}async function Gy(e,t,n,r){let i=new AbortController,a=setTimeout(()=>i.abort(),n);try{return await e(t,{method:`GET`,signal:i.signal,credentials:`omit`,...r===void 0?{}:{headers:r}})}finally{clearTimeout(a)}}async function Ky(e){let t=e.fetchFn??fetch,n=e.timeoutMs??Hy,r=e.origin.replace(/\/+$/,``),i;try{i=await Gy(t,`${r}/health`,n)}catch{return{hubReachable:!1,authOk:`unknown`,offlineAgents:null,offlineAgentIds:null}}if(!i.ok)return{hubReachable:!1,authOk:`unknown`,offlineAgents:null,offlineAgentIds:null};let a=null,o=e.getToken();if(o!==null&&o!==``)try{let e=await Gy(t,`${r}/health/details`,n,{Authorization:`Bearer ${o}`});e.ok&&(a=await e.json())}catch{}let s;try{s=Wy(a??await i.json())}catch{s={offline:null,offlineIds:null,ok:null}}if(s.ok===!1)return{hubReachable:!1,authOk:`unknown`,offlineAgents:null,offlineAgentIds:null};let c=e.getToken(),l=`unknown`;if(c!==null&&c!==``)try{let e=await Gy(t,`${r}/trpc/auth.me`,n,{Authorization:`Bearer ${c}`});e.status===401||e.status===403?l=!1:e.ok&&(l=!0)}catch{l=`unknown`}return{hubReachable:!0,authOk:l,offlineAgents:s.offline,offlineAgentIds:s.offlineIds}}var qy={kind:`connected`},Jy={kind:`reconnecting`};function Yy(e){let t=e.probeIntervalMs??Uy,n=new Set,r=qy,i=0,a=!1,o=null;function s(e){if(r!==e){r=e;for(let e of n)e()}}function c(){a=!1,o!==null&&(clearTimeout(o),o=null)}function l(){let n=i;e.probe().then(e=>{n!==i||!a||(s(By(e)),o=setTimeout(l,t))},()=>{n!==i||!a||(s({kind:`hub-unreachable`}),o=setTimeout(l,t))})}function u(e){if(i+=1,e===`connected`){c(),s(qy);return}if(e===`connecting`){c(),s(Jy);return}(r.kind===`connected`||r.kind===`reconnecting`)&&s(Jy),o!==null&&(clearTimeout(o),o=null),a=!0,l()}return{getSnapshot:()=>r,subscribe:e=>(n.add(e),()=>{n.delete(e)}),onSdkConnectionState:u,dispose:()=>{i+=1,c(),n.clear()}}}var Xy=null;function Zy(){return Xy===null&&(Xy=Yy({probe:()=>Ky({origin:je(),getToken:()=>localStorage.getItem(`camstack_admin_token`)})})),Xy}function Qy(e){Zy().onSdkConnectionState(e)}function $y(e){return e===`connected`}function eb(e){M.setOnline($y(e))}var tb=null,nb=0;function rb(){if(!tb){let e=nb;tb=yo({serverUrl:je(),token:localStorage.getItem(`camstack_admin_token`)??void 0,getLanguage:()=>K.language,refreshCredential:async e=>{e===`rejected`?await xb().refreshNow():await xb().ensureFresh()},onConnectionChange:t=>{e===nb&&(Qy(t),eb(t))}})}return tb}function ib(){let e=tb;tb=null,nb+=1,e?.close()}var ab=`camstack_admin_token`,ob=`camstack_admin_refresh`,sb=`camstack_admin_token_expires`;function cb(e){try{let t=localStorage.getItem(e);return t!==null&&t.length>0?t:null}catch{return null}}function lb(e,t){try{t===null?localStorage.removeItem(e):localStorage.setItem(e,t)}catch{}}function ub(){let e=cb(ab);if(e===null)return null;let t=cb(ob),n=Number(cb(sb));return{token:e,...t===null?{}:{refreshToken:t},...Number.isFinite(n)&&n>0?{expiresAt:n}:{}}}function db(e){lb(ab,e.token),lb(ob,e.refreshToken??null),lb(sb,e.expiresAt===void 0?null:String(e.expiresAt))}function fb(e){lb(ab,e),lb(ob,null),lb(sb,null)}function pb(){lb(ab,null),lb(ob,null),lb(sb,null)}function mb(e){let t=e.get(`token`);if(t===null||t.length===0)return null;let n=e.get(`refreshToken`),r=Number(e.get(`expiresAt`));return{token:t,...n!==null&&n.length>0?{refreshToken:n}:{},...Number.isFinite(r)&&r>0?{expiresAt:r}:{}}}async function hb(e){await fetch(B(`/api/auth/session`),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({token:e})}).catch(()=>{})}var gb=new Set;function _b(e){return gb.add(e),()=>gb.delete(e)}var vb=new Set;function yb(e){return vb.add(e),()=>vb.delete(e)}var bb=null;function xb(){return bb===null&&(bb=new oa({refresh:async e=>{let t=ub();if(t?.refreshToken!==void 0&&t.refreshToken!==e&&(t.expiresAt??0)>Date.now()+6e4)return t;let n=await rb().refreshSession(e);return{token:n.token,refreshToken:n.refreshToken,expiresAt:n.expiresAt}},onTokens:e=>{db(e),rb().setToken(e.token),hb(e.token);for(let e of vb)e()},onExpired:()=>{pb();for(let e of gb)e()}})),bb}function Sb(e){db(e),xb().adopt(e)}async function Cb(e){try{await xb().ensureFresh()}catch(e){console.warn(`[admin-session] pre-reconnect refresh failed; reconnecting anyway`,e)}e()}async function wb(){return await xb().refreshNow()!==null}var Tb=512;function Eb(e){if(!e||e.length>Tb)return null;let t=Pt(e);return t===null?!e.startsWith(`/`)||e.startsWith(`//`)||e.includes(`\\`)||e.includes(`://`)||e.includes(`..`)||e===`/login`||e.startsWith(`/login?`)||e.startsWith(`/login/`)?null:{kind:`path`,path:e}:{kind:`app-callback`,url:t}}var Db=/^[A-Za-z0-9_-]{43,128}$/,Ob=/^[A-Za-z0-9._~-]{1,256}$/;function kb(e){let{codeChallenge:t,state:n}=e;return!t||!Db.test(t)||(e.codeChallengeMethod??`S256`)!==`S256`||!n||!Ob.test(n)?null:{codeChallenge:t,state:n,purpose:e.purpose===`step-up`?`step-up`:`new-session`}}var Ab=`camstack:login-app-handoff`;function jb(e){if(!e)return null;try{let t=JSON.parse(e);if(typeof t!=`object`||!t)return null;let n=e=>{let n=Reflect.get(t,e);return typeof n==`string`?n:null};return kb({codeChallenge:n(`codeChallenge`),state:n(`state`),purpose:n(`purpose`)})}catch{return null}}function Mb(e,t=Date.now()){e!==null&&Wb(Ab,JSON.stringify(e),jb,t)}function Nb(e=Date.now()){return Gb(Ab,jb,e)}function Pb(e,t,n){return`${e}?${`code=${encodeURIComponent(t)}`}${n===void 0?``:`&state=${encodeURIComponent(n)}`}`}function Fb(e,t=Date.now()){return Jb(t)??Eb(e)}var Ib=2048;function Lb(e){return!e||e.length>Ib||!e.startsWith(`/`)||e.startsWith(`//`)||e.includes(`\\`)||e.includes(`://`)||e.includes(`..`)||e===`/login`||e.startsWith(`/login?`)||e.startsWith(`/login/`)?null:e}function Rb(e,t=Date.now()){Wb(Hb,e,Lb,t)}function zb(e=Date.now()){return Gb(Hb,Lb,e)}function Bb(e,t=Date.now()){return zb(t)??Lb(e)}var Vb=`camstack:login-redirect`,Hb=`camstack:login-next`,Ub=10*6e4;function Wb(e,t,n,r){let i=Kb();if(!i||!n(t))return;let a={raw:t??``,at:r};try{i.setItem(e,JSON.stringify(a))}catch{}}function Gb(e,t,n){let r=Kb();if(!r)return null;let i=null;try{i=r.getItem(e),r.removeItem(e)}catch{return null}if(!i)return null;try{let e=JSON.parse(i);if(typeof e!=`object`||!e)return null;let r=Reflect.get(e,`at`),a=Reflect.get(e,`raw`);return typeof r!=`number`||typeof a!=`string`||n-r>Ub?null:t(a)}catch{return null}}function Kb(){if(typeof window>`u`)return null;try{return window.sessionStorage}catch{return null}}function qb(e,t=Date.now()){Wb(Vb,e,Eb,t)}function Jb(e=Date.now()){return Gb(Vb,Eb,e)}var Yb=`changeme`;function Xb(e){try{let t=e.split(`.`);if(t.length<2||!t[1])return null;let n=JSON.parse(atob(t[1]));return{id:String(n.userId??``),username:String(n.username??`unknown`),isAdmin:!!n.isAdmin,exp:Number(n.exp??0),scopes:Zb(n.scopes)}}catch{return null}}function Zb(e){return xn(wn(e))}function Qb(e){let t=Xb(e);return t?t.exp*1e3<Date.now():!0}O();var $b=Yb;function ex(e){return{token:e.token,...e.refreshToken===void 0?{}:{refreshToken:e.refreshToken},...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}}async function tx(e,t){if(await hb(e),t.kind===`path`){window.location.replace(B(t.path));return}try{ib();let e=Nb();if(e===null)throw Error(`The app sent no PKCE challenge and state`);let{code:n}=await rb().trpcClient.auth.createHandoffCode.mutate({purpose:e.purpose,codeChallenge:e.codeChallenge,state:e.state});window.location.replace(Pb(t.url,n,e.state))}catch{window.location.replace(B(`/`))}}async function nx(e,t){await hb(e),window.location.replace(B(t))}var rx=j(null);function ix({children:e}){let[t,n]=w(null),[r,i]=w(!0),[a,o]=w(!1);S(()=>{if(typeof window<`u`&&window.location.hash.startsWith(`#token=`)){let e=new URLSearchParams(window.location.hash.slice(1)),t=mb(e),n=t?.token??null;if(t!==null&&n!==null){Sb(t);let r=Jb();if(r){tx(n,r);return}let i=zb()??Lb(e.get(`next`));if(i){nx(n,i);return}window.history.replaceState({},``,B(`/`))}}s()},[]);let s=async()=>{let e=ub();if(e===null){i(!1);return}let t=e.token;if(e.refreshToken!==void 0){let n=xb();n.adopt(e),await n.ensureFresh();let r=ub();if(r===null){console.warn(`[auth] session restore: signed out — the hub refused the refresh token`),ib(),i(!1);return}t=r.token}if(Qb(t)){console.warn(`[auth] session restore: signed out — access token expired and no refresh recovered it`),pb(),ib(),i(!1);return}let r=Xb(t);if(!r){console.warn(`[auth] session restore: signed out — the stored access token is unreadable`),pb(),ib(),i(!1);return}hb(t);let a=rb();a.trpcClient.system.info.query().then(()=>n(r)).catch(async e=>{let t=e?.data?.code;if(t===`UNAUTHORIZED`||t===`FORBIDDEN`){if(await wb()){a.reconnect();try{await rb().trpcClient.system.info.query();let e=ub();n(e&&Xb(e.token)||r);return}catch{}}console.warn(`[auth] session restore: logout, probe UNAUTHORIZED and refresh did not recover it`),xb().stop(),pb(),ib()}else n(r)}).finally(()=>i(!1))};S(()=>_b(()=>{ib(),n(null),o(!1)}),[]);let c=b(async(e,t)=>{let r=await rb().login(e,t,{refreshable:!0}),i=r.secondFactors??(r.requiresTotp===!0?[`totp`]:[]);if(i.length>0)return{kind:`second-factor`,challengeToken:r.token,factors:i};let a=r.token;return Sb(ex(r)),await hb(a),ib(),n(Xb(a)),o(t===$b),{kind:`ok`}},[]),l=b(async(e,t)=>{let r=await rb().loginVerifyTotp(e,t,{refreshable:!0}),i=r.token;Sb(ex(r)),await hb(i),ib(),n(Xb(i)),o(!1)},[]),u=b(async(e,t)=>{Sb({token:e,...t}),await hb(e),ib(),n(Xb(e)),o(!1)},[]),d=b(()=>{rb().logout().catch(()=>{}),xb().stop(),pb(),fetch(B(`/api/auth/session`),{method:`DELETE`}).catch(()=>{}),ib(),n(null),o(!1)},[]),f=b(()=>{o(!1)},[]);return x(rx.Provider,{value:{user:t,loading:r,mustChangePassword:a,login:c,verifyTotp:l,finalizePasskeyLogin:u,logout:d,clearMustChangePassword:f},children:e})}function ax(){let e=I(rx);if(!e)throw Error(`useAuth must be used within AuthProvider`);return e}function ox(e){return(t,n,r)=>e(t,{...typeof n==`string`?{defaultValue:n}:{defaultValue_one:n.one,defaultValue_other:n.other},...r})}var sx=(e,t,n)=>ox(K.t.bind(K))(e,t,n);function cx(e,t){return e===`present`&&t.status===`ok`&&(t.data?.length??0)>0}O();function lx({deviceId:e,deviceName:t}){let{t:n}=q(),r=Ui(`remote`),i=Yi({deviceId:e},{enabled:r===`present`}),[a,o]=w(!1);return r!==`present`||(i.data?.commands.length??0)===0&&(i.data?.sources.length??0)===0?null:s(`div`,{className:`flex flex-wrap items-center justify-center gap-1`,children:[s(G,{size:`sm`,variant:`outline`,onClick:()=>o(!0),"data-testid":`hero-remote`,children:[x(ua,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),n(`remote.hero.open`)]}),a&&x(ux,{deviceId:e,deviceName:t,onClose:()=>o(!1)})]})}function ux({deviceId:e,deviceName:t,onClose:n}){let{t:r}=q(),i=Ki({deviceId:e}),a=Rr({kind:`remote`}),o=Yi({deviceId:e}),c=Ci(),l=Jr({deviceId:e}),[u,d]=w(null),f=i.data?.layoutTemplateId??null,p=(a.data??[]).find(e=>e.id===f),m=p===void 0?null:Xr(p.payload),h=new Set((o.data?.commands??[]).map(e=>e.role)),g=async t=>{let n=m?.buttons.find(e=>e.id===t)?.role;if(!(n===void 0||!h.has(n))){d(null);try{let t=await c.mutateAsync({deviceId:e,role:n,repeat:1});t.status===`refused`&&d(r(`remote.test.refused.${t.reason}`,{detail:t.detail??``}))}catch(e){d(e instanceof Error?e.message:String(e))}}};return x(Mi,{open:!0,onOpenChange:e=>!e&&n(),children:s(Ir,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[x(Yr,{children:x(qi,{children:r(`remote.hero.title`,{name:t})})}),s(zi,{className:`space-y-3`,children:[i.status===`error`?x(Or,{title:r(`remote.dialog.unreadable`),message:i.error?.message??``,onRetry:()=>void i.refetch()}):m===null?x(`p`,{className:`text-xs text-foreground-muted`,children:r(`remote.hero.noLayout`)}):x(`div`,{className:`mx-auto w-full max-w-xs`,"data-testid":`remote-press`,children:x(Pr,{grid:m,label:r(`remote.hero.title`,{name:t}),boundRoles:h,onSelect:e=>void g(e),renderWidget:(t,n)=>x(vi,{deviceId:e,button:t,sources:o.data?.sources??[],current:l.data?.source??``,placement:n})})}),u!==null&&x(`p`,{role:`alert`,className:`text-xs text-danger`,children:u})]})]})})}O();var dx=j({});function fx({value:e,children:t}){return x(dx.Provider,{value:e,children:t})}O();var px={"off-while-running":{title:`Turn off while running?`,message:`The device is running. Cutting its power now interrupts what it is doing.`,confirm:`Turn off`},unlock:{title:`Unlock?`,message:`The lock will open.`,confirm:`Unlock`},install:{title:`Install the update?`,message:`The device may restart and be unavailable for a while.`,confirm:`Install`},press:{title:`Run it now?`,message:`The device acts as soon as you confirm.`,confirm:`Run`}},mx=e=>e===`off-while-running`?`deviceHero.model.confirmOff`:`deviceHero.model.confirm.${e}`;function hx(){let{t:e,i18n:t}=q(),n=t.language;return m(()=>{let t=t=>({title:e(`${mx(t)}.title`,px[t].title),message:e(`${mx(t)}.message`,px[t].message),confirm:e(`${mx(t)}.confirm`,px[t].confirm)});return{noValue:e(`deviceHero.model.noValue`,`–`),callFailed:e(`deviceHero.model.callFailed`,`The device did not accept the command`),historyTooltip:e(`deviceHero.utility.history.tooltip`,`Opens the history of this device.`),consumables:{label:e(`deviceHero.utility.consumables.label`,`Consumables`),low:t=>e(`deviceHero.utility.consumables.low`,`{{count}} low`,{count:t}),ok:e(`deviceHero.utility.consumables.ok`,`OK`),tooltip:e(`deviceHero.utility.consumables.tooltip`,`Shows the level of each consumable and which ones need attention.`)},power:{label:e(`deviceHero.utility.power.label`,`Power source`),on:e(`deviceHero.utility.power.on`,`On`),off:e(`deviceHero.utility.power.off`,`Off`),tooltip:e(`deviceHero.utility.power.tooltip`,`Opens a menu to cut or restore the power feeding this device, or to restart it.`),tooltipReadOnly:e(`deviceHero.utility.power.tooltipReadOnly`,`Whether the power source feeding this device is on. Your session cannot change it.`)},confirm:{"off-while-running":t(`off-while-running`),unlock:t(`unlock`),install:t(`install`),press:t(`press`)}}},[e,n])}O();function gx(e){let[t]=w(()=>new D({defaultOptions:{queries:{retry:!1,staleTime:5e3}}}));return e??t}function _x({deviceId:e,kind:t,canActuate:n,onDrawn:r,showName:i}){let a=yi();return S(()=>{r?.(!0)},[r]),x(`div`,{className:`flex h-full justify-center`,children:x(Qi,{kind:t,deviceId:e,canActuate:n,orientation:a?`vertical`:`horizontal`,showName:i!==!1})})}function vx(e){let t=Ti(e.deviceId);return t===`pending`?x(yr,{className:`h-72 w-full`}):t===null?x(yx,{...e}):x(_x,{deviceId:e.deviceId,kind:t,canActuate:e.canActuate,onDrawn:e.onDrawn,showName:e.showName})}function yx(e){let t=yi();return x(`div`,{className:`flex h-full justify-center`,children:x(eo,{deviceId:e.deviceId,canActuate:e.canActuate,orientation:t?`vertical`:`horizontal`,showName:e.showName!==!1,placeholder:x(yr,{className:`h-72 w-full`}),fallback:x(`div`,{className:`w-full`,children:x(bx,{...e})}),...e.onDrawn===void 0?{}:{onDrawn:e.onDrawn}})})}function bx({deviceId:e,canActuate:t,fallback:n,onDrawn:r,defaultHistoryOpen:i,showName:a}){let{t:o,i18n:c}=q(),l=hx(),[u,d]=w(i===!0),f=Ja(e),p=cx(f.presence,f.list),m=b(()=>d(!0),[]);return s(F,{children:[x(qr,{deviceId:e,canActuate:t,lang:Wi(c.language),labels:l,renderRemote:t=>x(lx,{deviceId:e,deviceName:t}),fallback:n??null,showName:a!==!1,...p?{onOpenHistory:m}:{},...r===void 0?{}:{onDrawn:r}}),u?x(Mi,{open:!0,onOpenChange:e=>!e&&d(!1),children:s(Ir,{width:`xl`,scroll:`body`,children:[x(Yr,{children:x(qi,{children:o(`deviceModule.history`,`History`)})}),x(zi,{className:`mt-3`,children:x(qa,{deviceId:e})})]})}):null]})}function xx({deviceId:e,trpcClient:t,theme:n,locale:r,canActuate:i=!1,defaultHistoryOpen:a,queryClient:o,fallback:s,onDrawn:c,onOpenDevice:l,onOpenCamera:u,onClose:d,onNavigate:f,showName:p}){let h=gx(o),g=m(()=>K.cloneInstance({lng:r}),[r]),_=m(()=>ox(g.t.bind(g)),[g]),v=m(()=>({onOpenDevice:l,onOpenCamera:u,onClose:d,onNavigate:f}),[l,u,d,f]);return x(`div`,{className:`${n} h-full`,"data-theme":n,"data-testid":`device-detail-module`,children:x(vd,{i18n:g,children:x(dt,{t:_,children:x(Le,{client:t,children:x(Ka.Provider,{client:t,queryClient:h,children:x(P,{client:h,children:x(Xe,{children:x(fx,{value:v,children:x(vx,{deviceId:e,canActuate:i,fallback:s,onDrawn:c,defaultHistoryOpen:a,showName:p})})})})})})})})})}function Sx({deviceId:e}){let t=V(),{data:n,isLoading:r}=Dy(e),{data:i,isLoading:a}=Ay(e),o=r||a,s=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...typeof e.role==`string`?{role:e.role}:{},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,u=typeof n?.type==`string`?n.type:void 0;return o?x(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):x(`div`,{className:`flex h-full w-full flex-col`,children:x(Oi,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l,containerType:u,primaryChildPreference:n?nn(n):void 0})})}O();function Cx({dev:e,busy:t,setBusy:n}){let{t:r}=q(),i=e?.motionTrigger,a=de(e?.state.motionTrigger),[o,c]=w(!1);if(!i)return null;let l=a?.enabled===!0,u=a!==void 0,d=async()=>{if(t||!u)return;let e=!l;n(!0),c(!0);try{await i.setMotionTrigger({enabled:e})}finally{n(!1),c(!1)}},f=o?l?`Disabling…`:`Enabling…`:u?l?`On motion: on`:`On motion: off`:`On motion: …`;return s(G,{variant:`unstyled`,type:`button`,onClick:()=>{d()},disabled:t||!u,title:u?l?r(`hero.motionTriggerToggle.disableTriggerOnMotion`,`Disable trigger on motion`):r(`hero.motionTriggerToggle.enableTriggerOnMotion`,`Enable trigger on motion`):r(`hero.motionTriggerToggle.awaitingState`,`Awaiting state…`),"aria-pressed":l,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${l?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[x(he,{className:`h-3 w-3`}),x(`span`,{children:f})]})}O();function Q({deviceId:e,deviceName:t,deviceType:n,deviceRole:r,features:i}){let a=V(),o=Vr(n,r)?.HeroCard??Ni,c=fe(a.trpcClient,e),l=de(c?.state.deviceStatus),[u,d]=w(!1),f=l!==void 0&&l.online===!1,p=f?l.lastChangedAt:null;return s(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[f?x(`div`,{className:`flex justify-center`,children:x(Ri,{lastChangedAt:p})}):null,x(o,{trpc:a.trpcClient,deviceId:e,features:i}),n===U.MediaPlayer?x(lx,{deviceId:e,deviceName:t}):null,x(`div`,{className:`flex justify-center`,children:x(Cx,{dev:c,busy:u,setBusy:d})})]})}function wx({deviceId:e,features:t}){return x(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:x(Hi,{trpc:V().trpcClient,deviceId:e,features:t})})}function Tx({deviceId:e}){let{t}=q(),n=Hr({deviceId:e},{staleTime:15e3}).data;if(n===void 0||n.linked!==!0||n.switchOn===null)return x(F,{});let r=n.switchOn===!0?t(`deviceHero.powerLine.on`,`Power switch on`):t(`deviceHero.powerLine.off`,`Power switch off`);return x(`p`,{className:`px-3 pt-1 text-[11px] text-foreground-muted sm:px-4`,children:n.switchName===null||n.switchName===``?r:t(`deviceHero.powerLine.withName`,`{{state}} · {{name}}`,{state:r,name:n.switchName})})}function Ex({deviceId:e,features:t}){return x(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:x(Ni,{trpc:V().trpcClient,deviceId:e,features:t})})}function Dx(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}var Ox=1e3,kx=60*Ox,Ax=60*kx,jx=24*Ax;function Mx(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<Ox?K.t(`helpers.relativeTime.justNow`):n<kx?K.t(`helpers.relativeTime.secondsAgo`,{count:Math.floor(n/Ox)}):n<Ax?K.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(n/kx)}):n<jx?K.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(n/Ax)}):K.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(n/jx)})}function Nx(e){let t=null;for(let n of e){let e=n.description;if(!(e===void 0||e.length===0)){if(t===null){t=e;continue}if(t!==e)return null}}return t}function Px(e){let t=new Map,n=[];for(let r of e){if(r.source===void 0){n.push(r);continue}let e=t.get(r.source.id);t.set(r.source.id,{source:r.source,entries:[...e?.entries??[],r]})}return[...t.values(),...n.length===0?[]:[{source:null,entries:n}]]}function Fx(e,t){if(!e)return null;let n=(Ut(t,e.eventType,e.sourceId)??Ut(t,e.eventType))?.label??e.eventType;if(e.sourceId!==void 0)return{source:t.find(t=>t.source?.id===e.sourceId)?.source?.label??null,label:n};let r=Dx(e.data);return{source:r===null?null:K.t(`hero.eventEmitterHero.button`,{value1:String(r)}),label:n}}O();var Ix=1500,Lx=15e3,Rx=1e3;function zx({deviceId:e}){let{t}=q(),n=fe(V().trpcClient,e)?.state.eventEmitter,r=de(n);S(()=>{if(!n)return;n.refresh();let e=setInterval(()=>{n.refresh()},Lx);return()=>{clearInterval(e)}},[n]);let i=r?.lastEvent??null,a=i?.seq??null,o=p(null),[c,l]=w(!1);S(()=>{if(a===null)return;let e=o.current;if(o.current=a,e===null||e===a)return;l(!0);let t=setTimeout(()=>{l(!1)},Ix);return()=>{clearTimeout(t)}},[a]);let[u,d]=w(()=>Date.now());S(()=>{let e=setInterval(()=>{d(Date.now())},Rx);return()=>{clearInterval(e)}},[]);let f=r===void 0?[]:Zt(r),m=Px(f),h=Nx(f),g=Fx(i,f),_=g===null?null:g.source===null?g.label:`${g.source} · ${g.label}`,v=i===null?void 0:Ut(f,i.eventType,i.sourceId),y=r?.eventCountSinceStart??0,b=r!==void 0;return s(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[x(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(c),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${c?`border-primary bg-primary/20 text-primary shadow-lg shadow-primary/30 scale-105`:`border-border bg-surface text-foreground-subtle`}`,"aria-live":`polite`,title:_??t(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`),children:x(c?St:it,{className:`h-10 w-10`})}),s(`div`,{className:`text-center`,children:[g!==null&&g.source!==null&&x(`div`,{"data-testid":`event-emitter-source`,className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:g.source}),x(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${_?`text-foreground`:`text-foreground-subtle`}`,children:_??(b?t(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`):t(`hero.eventEmitterHero.awaitingState`,`Awaiting state…`))}),x(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:i?Mx(i.timestamp,u):t(`hero.eventEmitterHero.waitingForTheFirstEvent`,`Waiting for the first event`)})]}),h!==null&&x(`p`,{"data-testid":`event-emitter-notice`,className:`max-w-full text-center text-xs text-foreground-subtle`,children:h}),m.length>0&&x(`div`,{className:`flex max-w-full flex-col items-center gap-1`,children:m.map(e=>s(`div`,{"data-testid":`event-emitter-source-row`,className:`flex max-w-full flex-wrap items-center justify-center gap-1`,children:[e.source!==null&&x(`span`,{className:`text-[10px] font-semibold text-foreground-subtle`,children:e.source.label}),e.entries.map(t=>x(`span`,{"data-testid":`event-emitter-chip`,title:t.description??t.id,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${t===v?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:t.label},`${e.source?.id??``}:${t.id}`))]},e.source?.id??``))}),x(`div`,{className:`text-[10px] text-foreground-subtle`,children:t(`hero.eventEmitterHero.sinceStart`,{count:y})})]})}function Bx({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){let{t:a}=q();return s(`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:[x(bv,{type:n,size:`lg`}),s(`div`,{children:[x(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),x(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),s(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[!r&&x(Gi,{status:`offline`}),i.length>0&&x(ly,{capabilities:i})]}),x(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:a(`hero.genericHero.noLiveViewForThis`,`No live view for this device type. Use the Config tab or the shortcut row to interact.`)})]})}var Vx={[U.Switch]:Q,[U.Siren]:Q,[U.Light]:Q,[U.Sensor]:Q,[U.Button]:Q,[U.Cover]:wx,[U.Valve]:Q,[U.Humidifier]:Q,[U.WaterHeater]:Q,[U.Container]:Sx,[U.Lock]:Q,[U.Fan]:Q,[U.Climate]:Q,[U.MediaPlayer]:Q,[U.Control]:Q,[U.AlarmPanel]:Q,[U.EventEmitter]:zx,[U.Notifier]:Ex,[U.Script]:Q,[U.Automation]:Q,[U.Presence]:Q,[U.Update]:Q,[U.Vacuum]:Q,[U.LawnMower]:Q,[U.Weather]:Q,[U.WeatherStation]:Q,[U.Image]:Q,[U.PetFeeder]:Q,[U.PetFountain]:Q,[U.Dishwasher]:Q,[U.Washer]:Q,[U.Dryer]:Q,[U.EnergySystem]:Q,[U.Workload]:Q};function Hx(e){return Vx[e]??Bx}function Ux({deviceId:e}){let t=ct(V().trpcClient,e,e=>e.runningState);if(t===void 0||t.running!==!0&&t.running!==!1)return x(F,{});let n=t.running;return x(_r,{running:n,since:t?.since??null,phase:t?.phase??null,className:`px-3 pt-2 sm:px-4`})}function Wx(e){let t=Hx(e.deviceType);return s(F,{children:[x(Ux,{deviceId:e.deviceId}),x(Tx,{deviceId:e.deviceId}),x(t,{...e})]})}function Gx({deviceId:e,device:t,deviceName:n,defaultHistoryOpen:r=!1,legacyFallback:i=!0,onDrawn:a,onNavigate:o}){let{i18n:s}=q(),{resolvedMode:c}=ba(),l=ll(),u=N(),d=V(),{user:f}=ax(),p=t?.features??[],m=e=>{o===void 0?l(e):o(e)};return x(xx,{deviceId:e,trpcClient:d.trpcClient,queryClient:u,theme:c,locale:Wi(s.language),canActuate:f?.isAdmin===!0,showName:!1,defaultHistoryOpen:r,...a===void 0?{}:{onDrawn:a},onOpenDevice:e=>m(`/devices/${String(e)}`),onOpenCamera:e=>m(`/devices/${String(e)}`),onNavigate:m,...i?{fallback:x(Wx,{deviceId:e,deviceName:n,deviceType:t?.type??`unknown`,deviceRole:t?.role??null,provider:String(t?.addonId??`rtsp`),isOnline:t?.online===!0,features:p})}:{}})}function Kx(e,t){return e.icon===t.icon&&e.label===t.label&&e.unit===t.unit&&e.precision===t.precision&&e.hidden===t.hidden}function qx(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function Jx(e){if(e.trim()===``)return;let t=Number.parseInt(e,10);return Number.isFinite(t)?t:void 0}function Yx(e,t){let n=Jx(e.precision),r={...e.icon===``?{}:{icon:e.icon},...e.label.trim()===``?{}:{label:e.label.trim()},...e.unit===``?{}:{unit:e.unit},...n===void 0?{}:{precision:n},...e.hidden?{hidden:!0}:{},...t?.perCap===void 0?{}:{perCap:t.perCap}};return Object.keys(r).length===0?null:r}function Xx(e){let t=qx(e.display),n=e.tags??[];return{name:e.name,location:e.location,role:e.role,display:t,tags:n,baseName:e.name,baseLocation:e.location,baseRole:e.role,baseDisplay:t,baseTags:n,persistedDisplay:e.display}}function Zx(e,t){if(e===null)return Xx(t);let n=qx(t.display),r=e.name===t.name&&e.location===t.location&&e.role===t.role&&$x(e.tags,t.tags??[])&&Kx(e.display,n);return!Qx(e)||r?Xx(t):e}function Qx(e){return e===null?!1:e.name!==e.baseName||e.location!==e.baseLocation||e.role!==e.baseRole||!$x(e.tags,e.baseTags)||!Kx(e.display,e.baseDisplay)}function $x(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function eS(e){return e.name.trim().length===0?`name`:null}function tS(e){let t=e.name.trim(),n=e.location.trim();return{...t===e.baseName?{}:{name:t},...n===e.baseLocation?{}:{location:n===``?null:n},...e.role===e.baseRole?{}:{role:e.role},...$x(e.tags,e.baseTags)?{}:{tags:[...e.tags]},...Kx(e.display,e.baseDisplay)?{}:{display:Yx(e.display,e.persistedDisplay)}}}function nS(e){let t=e.map(e=>e.error).filter(e=>e!==null&&e.length>0);return{dirty:e.some(e=>e.dirty),saving:e.some(e=>e.saving),error:t.length===0?null:t.join(`; `)}}O();var rS=j(null);function iS(){return I(rS)}function aS({deviceId:e,seed:t,onClose:n,children:r}){let[i,a]=w(null),[o,s]=w([]),{t:c}=q(),l=ll(),u=He(),d=p(new Map);if(t!==null){let e=Zx(i,t);(i===null||e.name!==i.name||e.location!==i.location||e.role!==i.role||!$x(e.tags,i.tags)||!$x(e.baseTags,i.baseTags)||!Kx(e.display,i.display)||e.baseName!==i.baseName||e.baseLocation!==i.baseLocation||e.baseRole!==i.baseRole||!Kx(e.baseDisplay,i.baseDisplay)||e.persistedDisplay!==i.persistedDisplay)&&a(e)}let f=b(e=>(d.current.set(e.id,{save:e.save,discard:e.discard}),s(t=>{let n=t.find(t=>t.id===e.id);return n!==void 0&&n.dirty===e.dirty&&n.saving===e.saving&&n.error===e.error?t:[...t.filter(t=>t.id!==e.id),{...e,save:()=>d.current.get(e.id)?.save()??Promise.resolve(),discard:()=>{d.current.get(e.id)?.discard()}}]}),()=>{d.current.delete(e.id),s(t=>t.filter(t=>t.id!==e.id))}),[]),h=nS([{dirty:Qx(i),saving:!1,error:null},...o]).dirty,g=b(e=>{(async()=>{h&&!await u({title:c(`deviceQuickDetail.leaveTitle`,`Discard unsaved changes?`),message:c(`deviceQuickDetail.leaveMessage`,`Unsaved edits on this device will be discarded.`),confirmLabel:c(`deviceQuickDetail.discard`,`Discard`),variant:`warning`})||(l(e),n?.())})()},[h,u,c,l,n]),_=b(()=>g(`/devices/${String(e)}`),[g,e]),v=m(()=>({identity:i,setIdentityName:e=>{a(t=>t===null?t:{...t,name:e})},setIdentityLocation:e=>{a(t=>t===null?t:{...t,location:e})},setIdentityRole:e=>{a(t=>t===null?t:{...t,role:e})},setIdentityTags:e=>{a(t=>t===null?t:{...t,tags:e})},setIdentityDisplay:e=>{a(t=>t===null?t:{...t,display:{...t.display,...e}})},register:f,openDevicePage:_,leaveTo:g}),[i,f,_,g]);return x(rS.Provider,{value:v,children:x(oS,{deviceId:e,identity:i,contributions:o,onIdentitySaved:e=>a(e),children:r})})}function oS({deviceId:e,identity:t,contributions:n,onIdentitySaved:r,children:i}){return s(F,{children:[i,x(cS,{deviceId:e,identity:t,contributions:n,onIdentitySaved:r})]})}function sS(e){return e instanceof Error?e.message:String(e)}function cS({deviceId:e,identity:t,contributions:n,onIdentitySaved:r}){let{t:i}=q(),a=N(),[o,c]=w(null),[l,u]=w(!1),d=ho(),f=ea(),p=Dr(),m=ya(),h=jr(),g=nS([{dirty:Qx(t),saving:l,error:o},...n]),_=()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})};return!g.dirty&&!g.saving&&g.error===null?null:s(`div`,{className:`sticky bottom-0 z-10 mt-auto flex flex-col gap-2 border-t border-border bg-background px-1 pt-3`,children:[g.error!==null&&x(`p`,{className:`text-xs text-danger`,children:g.error}),x(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:s(`div`,{className:`flex items-center gap-2`,children:[x(G,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{t!==null&&r({...t,name:t.baseName,location:t.baseLocation,role:t.baseRole,display:t.baseDisplay,tags:t.baseTags});for(let e of n)e.discard();c(null)},disabled:!g.dirty||g.saving,children:i(`deviceQuickDetail.discard`,`Discard`)}),x(G,{type:`button`,size:`sm`,onClick:()=>{if(t!==null&&Qx(t)&&eS(t)===`name`){c(i(`deviceQuickDetail.nameRequired`,`Name is required`));return}c(null),u(!0),(async()=>{try{let i=t===null?{}:tS(t);if(t!==null&&i.name!==void 0&&await d.mutateAsync({deviceId:e,name:i.name}),t!==null&&i.location!==void 0&&await f.mutateAsync({deviceId:e,location:i.location}),t!==null&&i.role!==void 0&&await p.mutateAsync({deviceId:e,role:i.role}),t!==null&&i.tags!==void 0&&await h.mutateAsync({deviceId:e,tags:i.tags}),t!==null&&i.display!==void 0&&await m.mutateAsync({deviceId:e,display:i.display}),t!==null){let e=t.name.trim(),n=t.location.trim();r({...t,name:e,location:n,baseName:e,baseLocation:n,baseRole:t.role,baseDisplay:t.display,baseTags:t.tags,persistedDisplay:i.display===void 0?t.persistedDisplay:i.display??void 0})}for(let e of n)e.dirty&&await e.save();_()}catch(e){c(sS(e))}finally{u(!1)}})()},disabled:!g.dirty||g.saving,children:g.saving?i(`deviceQuickDetail.saving`,`Saving…`):i(`deviceQuickDetail.save`,`Save`)})]})})]})}O();function lS(e,t){for(let n of e)for(let e of n.fields){if(!(`key`in e)||e.key!==t)continue;if(e.type===`button`||e.type===`separator`||e.type===`info`)return!0;let r=e.immediate;return r===!0?!0:r===!1?!1:n.immediate===!0}return!1}function uS({schema:e,serverValues:t,onImmediateSave:n,onDeferredSave:r}){let[i,a]=w({}),[o,s]=w({}),[c,l]=w(!1),u=p(null),d=e?.sections??[],f=Object.keys(i).length>0,h=m(()=>({...t,...o,...i}),[t,o,i]);S(()=>{if(f||Object.keys(o).length>0){l(!0);return}u.current&&clearTimeout(u.current),u.current=setTimeout(()=>l(!1),500)},[f,o]),S(()=>()=>{u.current&&clearTimeout(u.current)},[]);let g=b(()=>{l(!0),u.current&&clearTimeout(u.current),u.current=setTimeout(()=>l(!1),2e3)},[]),_=b(e=>{g();let r={},o={},s={...t,...i};for(let[t,n]of Object.entries(e))s[t]!==n&&(lS(d,t)?r[t]=n:o[t]=n);Object.keys(r).length>0&&n(r),a(e=>{let t={...e};for(let e of Object.keys(r))delete t[e];for(let[e,n]of Object.entries(o))t[e]=n;return t})},[g,t,i,d,n]),v=b(e=>{let t={},n={};for(let[r,a]of Object.entries(i))e.includes(r)?t[r]=a:n[r]=a;if(a(n),Object.keys(t).length===0)return;let o=Object.keys(t),c=r(t);if(c===void 0||typeof c.then!=`function`)return;s(e=>({...e,...t}));let l=()=>s(e=>{let t={...e};for(let e of o)delete t[e];return t});c.then(l,()=>{l(),a(e=>{let n={...e};for(let e of o)e in n||(n[e]=t[e]);return n})})},[i,r]),y=b(e=>{a(t=>{let n={...t};for(let t of e)delete n[t];return n})},[]),x=b(()=>{a({})},[]);return{values:h,pendingKeys:Object.keys(i),hasPendingEdits:f,editingPaused:c,handleChange:_,handleSave:v,handleDiscard:y,resetAll:x}}function dS({pendingCount:e,onSave:t,onDiscard:n,saving:r=!1,saveLabel:i=`Save`,discardLabel:a=`Discard`}){let{t:o}=q();return e<=0?null:s(`div`,{className:`sticky bottom-0 -mb-3 flex items-center justify-between gap-3 rounded-lg border border-primary/40 bg-primary/5 px-3 py-2 shadow-sm z-10`,children:[x(`span`,{className:`text-xs text-foreground`,children:o(`formBuilder.saveBar.unsavedChanges`,{count:e})}),s(`div`,{className:`flex items-center gap-2`,children:[x(G,{variant:`unstyled`,type:`button`,onClick:n,disabled:r,className:`inline-flex items-center rounded-md border border-border px-2.5 py-1 text-xs text-foreground-subtle hover:bg-surface-hover disabled:opacity-50`,children:a}),x(G,{variant:`unstyled`,type:`button`,onClick:t,disabled:r,className:`inline-flex items-center rounded-md bg-primary px-3 py-1 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:r?o(`formBuilder.formSaveBar.saving`,`Saving…`):i})]})]})}function fS({tabs:e,activeId:t,onChange:n,countByTab:r,pendingByTab:i}){return e.length===0?null:x(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border shrink-0`,children:e.map(e=>{let a=e.id===t,o=r?.get(e.id)??0,c=i?.get(e.id)??0;return s(G,{variant:`unstyled`,type:`button`,onClick:()=>n(e.id),className:`relative shrink-0 px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors -mb-px border-b-2 whitespace-nowrap ${a?`text-primary border-primary bg-primary/5`:`text-foreground-subtle border-transparent hover:text-foreground hover:bg-surface-hover`}`,children:[e.label,o>0&&s(`span`,{className:`ml-1.5 text-[10px] opacity-60`,children:[`(`,o,`)`]}),c>0&&x(`span`,{className:`ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-primary`})]},e.id)})})}O();function pS({schema:e,values:t,pendingKeys:n,onChange:r,onAction:i,onSave:a,onDiscard:o,disabled:c,activeSubTab:l,onSubTabChange:u,flattenTabs:d=!1,visibilityContext:f,hideSaveBar:h=!1,leadingTabs:g=[]}){let _=e.tabs??[],v=m(()=>{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]),y=new Set(_.map(e=>e.id)),b=[...g.map(e=>({id:e.id,label:e.label})),..._,...[...v.keys()].filter(e=>!y.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],S=b[0]?.id??`general`,[C,T]=w(S),E=u!==void 0,D=new Set(b.map(e=>e.id)),O=p(new Set);for(let e of D)O.current.add(e);let k=O.current,A=(e=>e&&(D.has(e)||k.has(e))?e:S)(E?l:C),j=e=>{E?u(e):T(e)},M=g.find(e=>e.id===A),N=v.get(A)??[],ee={sections:N.length<=1?N.length===1?[{...N[0],title:``}]:N:N.every(e=>!e.title)?[{...N[0],title:``,fields:N.flatMap(e=>e.fields)}]:N},P=h?null:x(dS,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>o(n),saving:c});if(g.length===0&&(d||b.length<=1))return s(`div`,{className:`flex flex-col gap-3`,children:[x(cg,{schema:e,values:t,onChange:r,onAction:i,disabled:c,visibilityContext:f}),P]});let F=new Map,I=new Map;for(let[e,t]of v){F.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&&I.set(e,a)}return s(`div`,{className:`flex flex-col gap-3`,children:[x(fS,{tabs:b.map(e=>({id:e.id,label:e.label})),activeId:A,onChange:j,countByTab:F,pendingByTab:I}),x(ia,{tabKey:A,children:M===void 0?x(cg,{schema:ee,values:t,onChange:r,onAction:i,disabled:c,visibilityContext:f}):M.content}),P]})}var mS=`device-export`,hS=`export`,gS=`Export`;function _S(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(_S):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(_S)):e.writerCapName===mS}function vS(e){return e.tab===`export`?!0:e.fields.some(_S)}var yS=`host/extensions-panel`;function bS(e){return e.type===`widget`?e.widgetId===yS:e.type===`group`?e.fields.some(bS):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(bS)):!1}function xS(e){return e.fields.some(bS)}function SS(e,t){return!t&&e!==void 0&&Sn.includes(e)}function CS(e){return e.location!==`top-tab`&&e.location!==`hero`&&!vS(e)&&!xS(e)}function wS(e,t,n,r){return!r||SS(t,n)?!0:(e??[]).some(CS)}function TS(e,t){for(let n of e){if(n.type===`group`){TS(n.fields,t);continue}if(n.type===`sub-tabs`){for(let e of n.tabs)TS(e.fields,t);continue}if(!(`value`in n))continue;let e=n.value===void 0?n.default:n.value;e!==void 0&&(t[n.key]=e)}}function ES(e){let t={};for(let n of e)TS(n.fields,t);return t}O();function DS(e,t){return t&&t===`admin`?e:!0}function OS(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?vS(e)&&vS(t)?e.id.localeCompare(t.id):(e.order??0)-(t.order??0):n.localeCompare(r)})};return e.tabs?{...t,tabs:e.tabs}:t}function kS(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`||e.type===`account-sign-in`||e.type===`secret-presence`}function AS(e){return e.key}function jS(e){if(!kS(e))return e.value}function MS(e){return kS(e)?null:e}function NS(e,t){for(let n of e)if(t(n),n.type===`group`)NS(n.fields,t);else if(n.type===`sub-tabs`)for(let e of n.tabs)NS(e.fields,t)}function PS(e){if(!e)return{};let t={};for(let n of e.sections)NS(n.fields,e=>{let n=AS(e);n!==null&&(t[n]=jS(e))});return t}function FS(e,t){if(!e)return null;let n=null;for(let r of e.sections)if(NS(r.fields,e=>{if(n!==null||AS(e)!==t)return;let r=MS(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function IS(e){return{...e,fields:e.fields.map(LS)}}function LS(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function RS(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=MS(e);return n?DS(t,n.minRole)?e:LS(e):e})}))}}var zS={sections:[]};function BS({deviceId:e,sectionFilter:t,activeSubTab:n,onSubTabChange:r,flattenSubTabs:i,subTabGrouping:a,leadingTabs:o}){let{t:c}=q(),l=N(),{user:u}=ax(),d=u?.isAdmin===!0,f=p(!1),{data:h,isLoading:g}=Zr({deviceId:e},{refetchInterval:()=>f.current?!1:2500,enabled:Number.isFinite(e)}),{data:_}=$a({deviceId:e},{enabled:Number.isFinite(e)}),v=h?.settings??null,y=h?.live??null,C=m(()=>{if(!v&&!y)return null;let e=v?.sections??[],n=(y?.sections??[]).map(IS),r=[...e,...n],i=t?r.filter(t):r.filter(CS);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=[...v?.tabs??[],...(y?.tabs??[]).filter(e=>!(v?.tabs??[]).some(t=>t.id===e.id))].filter(e=>o.has(e.id));return s.length>0?{tabs:s,sections:i}:{sections:i}},[v,y,t,a]),w=m(()=>ES([...v?.sections??[],...y?.sections??[]]),[v,y]),T=m(()=>OS(C),[C]),E=m(()=>RS(T,d),[T,d]),D=m(()=>PS(E),[E]),O=Sr(),k=Pa(),A=di(),j=Sa(),M=br({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),ee={isPending:M.isPending,mutate:t=>{M.mutate({deviceId:e,changes:[...t]})}},P=uS({schema:E,serverValues:D,onImmediateSave:b(e=>{let t=Object.entries(e).map(([e,t])=>{let n=FS(E,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&ee.mutate(t)},[E,ee]),onDeferredSave:b(async t=>{let n=Object.entries(t).map(([e,t])=>{let n=FS(E,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);if(n.length!==0)try{let t=await M.mutateAsync({deviceId:e,changes:n});if(t.failures.length>0)throw Error(t.failures.map(e=>e.error).join(`; `))}finally{await l.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}},[E,M,e,l])}),{values:F,pendingKeys:I,handleChange:L,handleSave:te,handleDiscard:ne}=P;f.current=P.editingPaused;let re=iS(),ie=p(te),ae=p(ne);ie.current=te,ae.current=ne;let oe=re?.register,se=M.isError?M.error instanceof Error?M.error.message:String(M.error):null,R=I.join(`\0`);S(()=>{if(oe===void 0)return;let e=R===``?[]:R.split(`\0`);return oe({id:`export`,dirty:e.length>0,saving:M.isPending,error:se,save:()=>(ie.current(e),Promise.resolve()),discard:()=>ae.current(e)})},[oe,R,M.isPending,se]);let ce=o!==void 0&&o.length>0;if(g&&!ce)return s(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[x(H,{className:`h-4 w-4 animate-spin mr-2`}),x(`span`,{className:`text-xs`,children:c(`device.deviceAggregateSection.loadingDeviceAggregate`,`Loading device aggregate…`)})]});if(!ce&&(!E||E.sections.length===0))return x(`div`,{className:`text-xs text-foreground-subtle italic py-4 text-center`,children:c(`device.deviceAggregateSection.noAggregateContributionsForThis`,`No aggregate contributions for this device.`)});async function le(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=Qn(e,r);await O.mutateAsync({brokerId:i}),l.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(t===`test-probe`){if(!_)return{status:`error`,error:c(`device.deviceAggregateSection.metadataNotLoaded`)};try{return await A.mutateAsync({addonId:_.addonId,type:_.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=Qn(e,t),i=await k.mutateAsync({brokerId:r});return l.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),i}if(t===`device-custom-action`){let t=await j.mutateAsync({deviceId:e,action:n,input:r});return l.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),t}throw Error(`[device-aggregate] unknown action "${t}"`)}return x(pS,{schema:E??zS,values:F,pendingKeys:I,onChange:L,onAction:le,onSave:te,onDiscard:ne,hideSaveBar:re!==null,disabled:ee.isPending,activeSubTab:n,onSubTabChange:r,flattenTabs:i,leadingTabs:o,visibilityContext:w})}O();function VS({deviceId:e,device:t,name:n,onDrawn:r}){let i=iS();return x(li,{frame:`bare`,fill:!0,children:x(Gx,{deviceId:e,device:t,deviceName:n,legacyFallback:!1,onDrawn:r,...i===null?{}:{onNavigate:i.leaveTo}})})}function HS(){let{t:e}=q(),t=iS();return t===null?null:x(G,{type:`button`,variant:`outline`,size:`sm`,onClick:t.openDevicePage,children:e(`deviceQuickDetail.openPage`,`Open device page`)})}function US({deviceId:e,onClose:t}){let{t:n}=q(),[r,i]=w(`detail`),[a,o]=w(null),c=a===!1,l=r===`detail`&&c?`info`:r,{data:u}=$a({deviceId:e},{enabled:e>0}),d=typeof u?.name==`string`?u.name:``,f=ei(e,`full`,d.length>0?d:`#${String(e)}`),p=typeof u?.location==`string`?u.location:``,m=[...c?[]:[[`detail`,n(`deviceQuickDetail.tabDetail`,{defaultValue:`Detail`})]],[`info`,n(`deviceQuickDetail.tabInfo`,{defaultValue:`Device info`})],[`export`,n(`deviceQuickDetail.tabExport`,{defaultValue:`Export`})]];return x(Mi,{open:!0,onOpenChange:e=>!e&&t(),children:x(Ir,{width:`lg`,scroll:`body`,className:`md:h-[85dvh]`,children:s(aS,{deviceId:e,seed:u==null?null:{name:d,location:p,role:typeof u.role==`string`?u.role:null,display:u.display,tags:u.tags},onClose:t,children:[x(Yr,{children:s(`div`,{className:`flex flex-wrap items-center justify-between gap-2 pr-8`,children:[x(qi,{children:f}),x(HS,{})]})}),x(`div`,{className:`mt-3 flex items-center gap-1 rounded-md bg-surface-hover p-0.5 w-fit`,children:m.map(([e,t])=>x(`button`,{type:`button`,onClick:()=>i(e),className:`px-2.5 py-1 rounded text-[11px] font-medium transition-colors ${l===e?`bg-surface text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`}`,children:t},e))}),x(zi,{className:l===`detail`?`mt-3 overflow-hidden`:`mt-3`,children:s(va,{deviceId:e,device:u??void 0,children:[l===`detail`?x(`div`,{className:`h-full`,children:x(VS,{deviceId:e,device:u,name:f,onDrawn:o})}):null,s(`div`,{className:l===`info`?`flex flex-col gap-3`:`hidden`,children:[x(oy,{deviceId:e}),x(Ly,{})]}),x(`div`,{className:l===`export`?void 0:`hidden`,children:x(BS,{deviceId:e,sectionFilter:vS})})]})})]})})})}function WS({children:e}){let[t,n]=w(null),r=b(e=>n(e),[]),i=b(()=>n(null),[]);return s(vr,{open:r,children:[e,t===null?null:x(US,{deviceId:t,onClose:i})]})}O();function GS({tabs:e,active:t,onChange:n}){return x(`div`,{className:`flex rounded-lg border border-border bg-surface p-0.5 gap-0.5`,children:e.map(e=>x(G,{variant:`unstyled`,type:`button`,onClick:()=>n(e.id),className:[`flex-1 rounded-md px-3 py-1.5 text-xs font-medium transition-colors`,t===e.id?`bg-primary/12 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`].join(` `),children:e.label},e.id))})}function KS(e){let t=e.formats;if(!t)return``;let n=Object.values(t).filter(e=>e!==void 0&&e.sizeMB>0).map(e=>e.sizeMB);if(n.length===0)return``;let r=Math.min(...n),i=Math.max(...n);return r===i?`${r} MB`:`${r}-${i} MB`}function qS(e){return`${e.inputSize.width}x${e.inputSize.height}`}function JS(e){return e.formats?Object.keys(e.formats).filter(t=>e.formats[t]!==void 0):[]}function YS({entry:e,selected:t,onSelect:n,disabled:r}){let{t:i}=q(),a=KS(e),o=qS(e),c=JS(e);return s(G,{variant:`unstyled`,type:`button`,onClick:n,disabled:r,className:[`w-full text-left rounded-lg border p-3 transition-all`,t?`border-primary bg-primary/5 ring-1 ring-primary/30`:`border-border bg-background hover:border-foreground-subtle/40 hover:bg-surface-hover/50`,r?`opacity-50 cursor-not-allowed`:`cursor-pointer`].join(` `),children:[x(`div`,{className:`flex items-start justify-between gap-2`,children:s(`div`,{className:`flex-1 min-w-0`,children:[s(`div`,{className:`flex items-center gap-2`,children:[x(`span`,{className:`text-xs font-semibold text-foreground truncate`,children:e.name}),t&&x(mt,{className:`h-3.5 w-3.5 text-primary shrink-0`})]}),x(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 line-clamp-2`,children:e.description})]})}),s(`div`,{className:`flex items-center gap-3 mt-2 flex-wrap`,children:[s(`span`,{className:`inline-flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[x(Ze,{className:`h-3 w-3`}),o]}),a&&x(`span`,{className:`text-[10px] text-foreground-subtle`,children:a}),c.length>0&&x(`div`,{className:`flex gap-1`,children:c.map(e=>x(`span`,{className:`text-[9px] uppercase rounded bg-surface border border-border px-1 py-0.5 text-foreground-subtle font-mono`,children:e},e))}),e.labels.length>0&&x(`span`,{className:`text-[10px] text-foreground-subtle`,children:i(`common.labels`,{count:e.labels.length})})]})]})}function XS({field:e,value:t,onChange:n,disabled:r}){let{t:i}=q(),a=e.catalog??[],o=a.length>0,c=Dn(a).length>0,l=e.allowCustomPath!==!1||e.allowCustom===!0,u=[...o?[{id:`catalog`,label:i(`formBuilder.modelSelector.models`,`Models ({{length}})`,{length:a.length})}]:[],...l?[{id:`custom`,label:i(`formBuilder.modelSelector.customPath`,`Custom Path`)}]:[]],[d,f]=w(o?`catalog`:`custom`),p=t==null?``:String(t);return s(`div`,{className:`space-y-3`,children:[u.length>1&&x(GS,{tabs:u,active:d,onChange:f}),d===`catalog`&&o&&c&&x(pi,{catalog:a,value:p,onChange:e=>n(e),disabled:r||e.disabled}),d===`catalog`&&o&&!c&&x(`div`,{className:`space-y-1.5 max-h-[320px] overflow-y-auto pr-1`,children:a.filter(e=>e.legacy!==!0).map(t=>x(YS,{entry:t,selected:p===t.id,onSelect:()=>n(t.id),disabled:r||e.disabled},t.id))}),d===`catalog`&&!o&&s(`div`,{className:`rounded-md border border-info/30 bg-info/5 px-3 py-2 flex items-start gap-2`,children:[x(lt,{className:`h-3.5 w-3.5 text-info shrink-0 mt-0.5`}),x(`p`,{className:`text-[11px] text-foreground-subtle leading-relaxed`,children:i(`formBuilder.modelSelector.noPredefinedModelsAvailableUse`,`No predefined models available. Use the Custom Path tab to specify a model file path or URL.`)})]}),d===`custom`&&l&&s(`div`,{className:`space-y-2`,children:[x(W,{type:`text`,className:`w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none disabled:opacity-50`,placeholder:i(`formBuilder.modelSelector.enterPathLikeDataModels`,`Enter path like /data/models/custom.onnx or https://...`),value:p,disabled:r||e.disabled,onChange:e=>n(e.target.value)}),e.acceptFormats&&e.acceptFormats.length>0&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:[i(`formBuilder.modelSelector.acceptedFormats`,`Accepted formats:`),` `,e.acceptFormats.join(`, `)]})]}),(e.compatibilityNote||e.conversionGuideUrl)&&s(`div`,{className:`flex items-start justify-between gap-3 pt-1`,children:[e.compatibilityNote&&s(`p`,{className:`flex items-start gap-1 text-[10px] text-foreground-subtle`,children:[x(lt,{className:`h-3 w-3 mt-0.5 shrink-0`}),e.compatibilityNote]}),e.conversionGuideUrl&&s(`a`,{href:e.conversionGuideUrl,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 text-[11px] text-primary hover:underline shrink-0`,children:[i(`formBuilder.modelSelector.howToConvertYourModel`,`How to convert your model`),x(wt,{className:`h-3 w-3`})]})]})]})}function ZS({to:e}){let{search:t}=Y();return x(X,{to:`${e}${t}`,replace:!0})}O();function QS(){return K.t(`helpers.keychainRevealHost.forbidden`)}function $S(e){if(typeof e!=`object`||!e)return null;let t=Reflect.get(e,`data`);if(typeof t!=`object`||!t)return null;let n=Reflect.get(t,`code`);return typeof n==`string`?n:null}function eC(e){let t=$S(e);if(t===`FORBIDDEN`||t===`UNAUTHORIZED`)return QS();let n=e instanceof Error?e.message:String(e);return n.length>0?K.t(`helpers.keychainRevealHost.failedWith`,{message:n}):K.t(`helpers.keychainRevealHost.failed`)}function tC({children:e}){let t=fo();return x(aa,{reveal:b(async e=>{try{return(await t.mutateAsync({ref:e})).value}catch(e){throw Error(eC(e))}},[t]),children:e})}O();function nC(){let e=V(),t=N(),[n,r]=w(()=>e.isConnected()?`connected`:`disconnected`),i=p(!1),[a,o]=w(0),[s,c]=w([]);S(()=>e.subscribeConnectionEvents(e=>{r(t=>(t!==`connected`&&e===`connected`&&i.current&&o(e=>e+1),e!==`connected`&&(i.current=!0),e))}),[e]),S(()=>{a!==0&&t.invalidateQueries({queryKey:[[`addons`,`getLastRestart`]]})},[a,t]);let{data:l}=ao(void 0,{enabled:n===`connected`&&a>0,staleTime:0,refetchOnMount:!1,refetchOnWindowFocus:!1}),u=p(null);return S(()=>{if(l==null||l.requestedAt===u.current)return;u.current=l.requestedAt;let e=iC(l);c(t=>[...t,e]);let t=window.setTimeout(()=>{c(t=>t.filter(t=>t.id!==e.id))},6e3);return()=>window.clearTimeout(t)},[l]),x(F,{children:s.length>0&&x(rC,{toasts:s})})}function rC({toasts:e}){return x(`div`,{className:`fixed top-[calc(env(safe-area-inset-top)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)] z-50 flex flex-col gap-2 max-w-sm w-full pointer-events-none`,children:e.map(e=>s(`div`,{className:`pointer-events-auto flex items-start gap-2 px-3 py-2.5 rounded-md border border-green-500/30 bg-green-500/10 shadow-lg`,children:[x(De,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),s(`div`,{children:[x(`div`,{className:`text-[11px] font-semibold text-foreground`,children:e.title}),x(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:e.message})]})]},e.id))})}function iC(e){let t=`restart-${e.requestedAt}`;if(e.kind===`framework-update`&&e.packageName!==void 0&&e.toVersion!==void 0){let n=e.fromVersion===void 0?`v${e.toVersion}`:`v${e.fromVersion} → v${e.toVersion}`;return{id:t,title:K.t(`system.reconnectOverlay.frameworkUpdated`,`Framework updated`),message:K.t(`system.reconnectOverlay.isNow`,`{{packageName}} is now {{fromTo}}.`,{packageName:e.packageName,fromTo:n})}}return{id:t,title:K.t(`system.reconnectOverlay.serverRestarted`,`Server restarted`),message:e.requestedBy===void 0?K.t(`system.reconnectOverlay.manualRestartCompleted`,`Manual restart completed.`):K.t(`system.reconnectOverlay.manualRestartByCompleted`,`Manual restart by {{requestedBy}} completed.`,{requestedBy:e.requestedBy})}}var aC=`/system/settings`,oC=[{path:`/system/capabilities`,tab:`capabilities`},{path:`/system/api-explorer`,tab:`api-explorer`}];function sC(e,t=``){let n=new URLSearchParams(t);return n.delete(`tab`),n.set(`tab`,e),`${aC}?${n.toString()}`}var cC=`/system/data`,lC=`/system/secrets`;function uC(e=``){let t=new URLSearchParams(e),n=t.get(`view`);return t.delete(`view`),t.set(`tab`,`secrets`),n===`audit`&&t.set(`secretsView`,`audit`),`${cC}?${t.toString()}`}function dC({tab:e}){let{search:t,hash:n}=Y();return x(X,{to:`${sC(e,t)}${n}`,replace:!0})}function fC(){let{search:e,hash:t}=Y();return x(X,{to:`${uC(e)}${t}`,replace:!0})}O();var pC={info:{bg:`bg-info/10`,border:`border-info/30`,icon:lt},warning:{bg:`bg-warning/10`,border:`border-warning/30`,icon:Ne},critical:{bg:`bg-danger/10`,border:`border-danger/30`,icon:te}};function mC({toast:e,onDismiss:t}){let n=pC[e.severity]??pC.info,r=n.icon;return S(()=>{let n=e.duration??5e3;if(n<=0)return;let r=setTimeout(()=>t(e.id),n);return()=>clearTimeout(r)},[e.id,e.duration,t]),x(`div`,{className:`rounded-lg bg-surface shadow-lg animate-in slide-in-from-right-5 fade-in duration-200`,children:s(`div`,{className:`flex items-start gap-3 px-4 py-3 rounded-lg border ${n.border} ${n.bg}`,children:[x(r,{className:`h-4 w-4 shrink-0 mt-0.5 text-foreground-subtle`}),s(`div`,{className:`flex-1 min-w-0`,children:[x(`div`,{className:`text-xs font-semibold text-foreground`,children:e.title}),x(`div`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:e.message})]}),x(G,{variant:`unstyled`,type:`button`,onClick:()=>t(e.id),className:`shrink-0 p-0.5 rounded hover:bg-surface-hover transition-colors`,children:x(xe,{className:`h-3.5 w-3.5 text-foreground-subtle`})})]})})}function hC(){let[e,t]=w([]),n=b(e=>{t(t=>t.filter(t=>t.id!==e))},[]),r=b(e=>{let n=`toast-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;t(t=>[...t,{...e,id:n,timestamp:Date.now()}])},[]);return wi(void 0,{onData:e=>r(e)}),S(()=>mg(r),[r]),e.length===0?null:x(`div`,{className:`fixed bottom-[calc(env(safe-area-inset-bottom)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)] z-50 flex flex-col gap-2 max-w-sm w-full pointer-events-none`,children:e.map(e=>x(`div`,{className:`pointer-events-auto`,children:x(mC,{toast:e,onDismiss:n})},e.id))})}O();function gC({children:e}){let{t}=q();return x(dt,{t:m(()=>ox(t),[t]),children:e})}O();function _C(e){if(typeof e!=`object`||!e)return;let{data:t}=e;return t?.code}function vC(e,t){let n=_C(e);return n===`UNAUTHORIZED`||n===`FORBIDDEN`?!0:/UNAUTHORIZED|FORBIDDEN/.test(t)}function yC(e,t,n,r){let[i,a]=w(!1),[o,s]=w(null);return S(()=>{if(a(!1),s(null),!t){a(!0);return}let i=!1;e.init().catch(()=>void 0);let o=t=>{e.awaitConnected().then(()=>{i||a(!0)},e=>{if(i)return;let c=e instanceof Error?e.message:String(e);if(vC(e,c)){if(t&&r!==void 0){r().then(e=>{if(!i){if(e){o(!1);return}console.warn(`[boot-gate] logout: probe UNAUTHORIZED and the refresh was refused`),n()}},()=>{i||(console.warn(`[boot-gate] logout: probe UNAUTHORIZED and recovery failed`),n())});return}console.warn(`[boot-gate] logout: probe UNAUTHORIZED after a successful refresh`,c),n();return}s(c),a(!0)})};return o(!0),()=>{i=!0}},[e,t,n,r]),{bootReady:i,bootError:o}}O();var bC=3e4;function xC(e){let t=p(e);t.current=e,S(()=>{let e=null,n=()=>{if(document.visibilityState===`hidden`){e=Date.now();return}if(document.visibilityState===`visible`&&e!==null){let n=Date.now()-e;e=null,n>=bC&&t.current()}},r=()=>{t.current()},i=e=>{e.persisted&&t.current()};return document.addEventListener(`visibilitychange`,n),window.addEventListener(`online`,r),window.addEventListener(`pageshow`,i),()=>{document.removeEventListener(`visibilitychange`,n),window.removeEventListener(`online`,r),window.removeEventListener(`pageshow`,i)}},[])}var SC=`@camstack/ui-library`;function CC(e){return typeof e==`object`&&!!e}var wC=/^>=\s*(\d+)\.(\d+)\.(\d+)/,TC=/^(\d+)\.(\d+)\.(\d+)/;function EC(e){return e===null?null:[Number(e[1]),Number(e[2]),Number(e[3])]}function DC(e,t){for(let n=0;n<3;n++){let r=e[n]??0,i=t[n]??0;if(r!==i)return r<i}return!1}function OC(e,t){let n=[];for(let r of Object.values(e)){let e=r[SC];if(!(typeof e!=`object`||!e))for(let r of Object.values(e)){if(!CC(r)||r.from!==t)continue;let e=r.shareConfig?.requiredVersion;typeof e==`string`&&n.push(e)}}return n}function kC(e,t){let n=e===null?null:EC(e.match(TC));if(n===null||e===null)return null;for(let r of t){let t=EC(r.match(wC));if(t!==null&&DC(n,t))return{required:t.join(`.`),host:e}}return null}O();function AC(){let{t:e}=q();return s(`div`,{role:`status`,"aria-busy":`true`,"aria-label":e(`layouts.addonPageLoader.loading`,`Loading page`),"data-testid":`addon-page-loading`,className:`flex flex-col gap-4 p-2 sm:p-4`,children:[x(yr,{className:`h-7 w-48`}),x(yr,{className:`h-5 w-72 max-w-full`}),x(yr,{className:`h-40`})]})}function jC({message:e}){let{t}=q();return x(`div`,{className:`p-2 sm:p-4`,"data-testid":`addon-page-error`,children:x(Or,{title:t(`layouts.addonPageLoader.failedTitle`,`This page could not be shown`),message:e})})}var MC=class extends l{state={error:null,resetKey:this.props.resetKey};static getDerivedStateFromError(e){return{error:e instanceof Error?e:Error(String(e))}}static getDerivedStateFromProps(e,t){return e.resetKey===t.resetKey?null:{error:null,resetKey:e.resetKey}}componentDidCatch(e,t){console.error(`[addon-page] ${this.props.resetKey} crashed`,e,t.componentStack)}render(){return this.state.error===null?this.props.children:x(jC,{message:this.state.error.message})}};function NC({resetKey:e,children:t}){return x(MC,{resetKey:e,children:t})}function PC({pageKey:e,children:t}){return x(MC,{resetKey:e,children:x(y,{fallback:x(AC,{}),children:t})})}O();function FC(e){let t=new Set,n=new Set,r=e=>e.page.remoteName.includes(e.addonId.replace(/[^a-zA-Z0-9]+/g,`_`)),i=[...e.filter(r),...e.filter(e=>!r(e))],a=[];for(let e of i){let r=`${e.addonId}::${e.page.id}`;t.has(r)||n.has(e.page.path)||(t.add(r),n.add(e.page.path),a.push({id:e.page.id,addonId:e.addonId,label:e.page.label,icon:e.page.icon,path:e.page.path,remoteName:e.page.remoteName,bundle:e.page.bundle,bundleUrl:e.bundleUrl,...e.page.section===void 0?{}:{section:e.page.section},...e.page.sectionLabel===void 0?{}:{sectionLabel:e.page.sectionLabel}}))}return a}var IC=2e4;function LC(e,t){let[n,r]=w(!1);return S(()=>{if(!e){r(!1);return}let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}var RC=new Map,zC=new Map,BC=new Set;function VC(e){return!e||typeof e!=`object`?!1:typeof e.default==`function`}var HC=class extends Error{problem;constructor(e){super(`ui-library ${e.host} is older than the ${e.required} this page requires`),this.problem=e}};function UC(e){let t=i()?.shareScopeMap;if(!t)return;let n=kC(Va,OC(t,e));if(n!==null)throw new HC(n)}async function WC(e,t){let i=RC.get(e);if(i)return i;let a=zC.get(e);if(a)return a;BC.has(e)||(xa(),r([{name:e,entry:B(t),type:`module`}],{force:!1}),BC.add(e));let o=n(`${e}/page`).then(n=>{if(UC(e),!VC(n))throw Error(`Addon page remote ${e} (${t}) does not expose a default React component on './page'`);return RC.set(e,n.default),zC.delete(e),n.default}).catch(t=>{throw zC.delete(e),UC(e),t});return zC.set(e,o),o}function GC(){let{t:e}=q(),{pagePath:t}=pl(),n=ll(),r=V(),{data:i,isError:a,error:o}=Ji(void 0),s=m(()=>i?FC(i):void 0,[i]),c=s?.find(e=>e.path===`/addon/${t}`),l=c?.remoteName,u=c?.bundleUrl,[d,f]=w(null),[p,h]=w(null);S(()=>{if(!l||!u)return;h(null);let t=RC.get(l);if(t){f(()=>t);return}f(null);let n=!1;return WC(l,u).then(e=>{n||f(()=>e)}).catch(t=>{n||h(t instanceof HC?e(`layouts.addonPageLoader.hostTooOld`,{defaultValue:`This page needs a newer admin UI (UI library {{required}} or later; this one has {{host}}). Update admin-ui.`,required:t.problem.required,host:t.problem.host}):t instanceof Error?t.message:String(t))}),()=>{n=!0}},[l,u]);let g=LC(!s&&!a,IC),_=LC(c!==void 0&&!d&&!p,IC);return s?c?p?x(jC,{message:p}):d?x(PC,{pageKey:c.remoteName,children:x(d,{trpc:r.trpcClient,theme:{isDark:document.documentElement.classList.contains(`dark`)},navigate:e=>{n(e.startsWith(`/`)?e:`/${e}`)}})}):_?x(jC,{message:e(`layouts.addonPageLoader.remoteStalled`,`The page did not load. Its addon may be starting or unreachable.`)}):x(AC,{}):x(`div`,{className:`flex items-center justify-center h-full text-foreground-subtle`,children:e(`layouts.addonPageLoader.addonPageNotFound`,`Addon page not found`)}):a?x(jC,{message:o?.message??e(`layouts.addonPageLoader.listFailed`,`The page list could not be loaded.`)}):g?x(jC,{message:e(`layouts.addonPageLoader.listStalled`,`The hub did not send the page list. Try again in a moment.`)}):x(AC,{})}var KC={"/system/pipeline":`pipeline-orchestrator`,"/system/history":`device-history`,"/system/ai":`llm`};function qC(e,t){return e.filter(e=>!e.adminOnly||t).map(e=>{let t=KC[e.path];return t===void 0?e:{...e,requiresCapability:t}})}function JC({t:e,isAdmin:t}){let n=qC([{label:e(`nav.devices`,`Devices`),icon:Ke,path:`/devices`},{label:e(`nav.integrations`),icon:ft,path:`/integrations`},{label:e(`nav.build`,`Build-your-self`),icon:ut,path:`/build`,adminOnly:!0},{label:e(`nav.locations`,`Locations`),icon:me,path:`/locations`,adminOnly:!0},{label:e(`nav.viewer`,`Viewer`),icon:ie,path:`/live`}],t),r=qC([{label:e(`nav.library`,`Library`),icon:mr,path:`/library`,adminOnly:!0,keywords:[`People`,`Vehicles`,`Events`,`Scenes`,`plates`,`faces`,`detection-intelligence`]},{label:e(`nav.archive`,`Archive`),icon:er,path:`/archive`,adminOnly:!0}],t),i=qC([{label:e(`nav.nodes`,`Nodes`),icon:Ie,path:`/system/nodes`,adminOnly:!0},{label:e(`nav.history`,`History`),icon:Be,path:`/system/history`,adminOnly:!0,keywords:[`charts`,`graphs`,`energy`,`temperature`,`metrics`,`trends`]},{label:e(`nav.pipeline`,`Pipeline`),icon:rr,path:`/system/pipeline`},{label:e(`system.addons`),icon:Ge,path:`/system/addons`,adminOnly:!0},{label:e(`system.ai`,`AI`),icon:Tt,path:`/system/ai`,adminOnly:!0}],t),a=qC([{label:e(`system.identity`,`Identity & Access`),icon:ue,path:`/system/identity`,adminOnly:!0},{label:e(`system.network`,`Network`),icon:gr,path:`/system/network`,adminOnly:!0},{label:e(`system.integrations`,`Connectivity`),icon:ft,path:`/system/integrations`,adminOnly:!0},{label:e(`system.data`,`Data`),icon:et,path:`/system/data`,adminOnly:!0},{label:e(`system.notifications`,`Notifications`),icon:se,path:`/system/notifications`,adminOnly:!0},{label:e(`system.calendars`,`Calendars`),icon:st,path:`/system/calendars`,adminOnly:!0},{label:e(`system.systemNav`,`System`),icon:le,path:aC,adminOnly:!0},{label:e(`system.logs`,`Logs`),icon:Ce,path:`/system/logs`,adminOnly:!0},{label:e(`system.terminal`,`Terminal`),icon:hr,path:`/system/terminal`,adminOnly:!0}],t);return[{key:`top`,label:null,items:n},{key:`detection`,label:e(`nav.detectionSection`,`Detection`),items:r},{key:`cluster`,label:e(`nav.clusterSection`,`Cluster`),items:i},{key:`administration`,label:e(`system.title`,`Administration`),items:a}]}var YC={gauge:Ve,puzzle:Ge,bot:xt,cpu:Ze,terminal:hr,box:ze,boxes:ze,monitor:ie,wrench:R,activity:he,plug:ft,"graduation-cap":ht};function XC(e){return YC[e]??Ge}function ZC(e,t){for(let n of JC(t))for(let t of n.items)if(t.path===e)return{icon:t.icon,title:t.label,path:t.path};return null}var QC=`/system/addons`;function $C({path:e,children:t}){let n=KC[e];return n===void 0?x(F,{children:t}):x(ew,{path:e,capability:n,children:t})}function ew({path:e,capability:t,children:n}){let{t:r}=q(),i=ll(),a=Ui(t);if(a===`present`)return x(F,{children:n});if(a===`pending`)return s(`div`,{className:`flex flex-col gap-4 p-2 sm:p-4`,"data-testid":`page-presence-pending`,children:[x(yr,{className:`h-7 w-48`}),x(yr,{className:`h-40`})]});if(a===`unknown`)return x(`div`,{className:`p-2 sm:p-4`,"data-testid":`page-presence-unknown`,children:x(Or,{title:r(`pageRequires.unknownTitle`,`Could not check whether this page is available`),message:r(`pageRequires.unknown`,`The hub did not answer the capability check. Reload the page to try again.`)})});let o=ZC(e,{t:r,isAdmin:!0});return x(`div`,{className:`p-2 sm:p-4`,"data-testid":`page-not-installed`,children:x(La,{icon:o?.icon??Ge,title:r(`pageRequires.absentTitle`,`{{page}} is not installed`,{page:o?.title??e}),description:r(`pageRequires.absentDescription`,`The addon that provides this page is not installed. Install it from System → Addons.`),action:x(G,{variant:`primary`,onClick:()=>i(QC),children:r(`pageRequires.openAddons`,`Open Addons`)})})})}function tw({capability:e,children:t}){return x(F,{children:t(Ui(e)===`absent`)})}function nw({children:e}){return x(Ai,{value:rw(si({})),children:e})}function rw(e){return e.data===void 0?e.isPending?{status:`pending`}:{status:`unknown`,reason:e.isError?String(e.error):`no palette`}:e.data.status===`unknown`?{status:`unknown`,reason:e.data.reason}:{status:`ready`,palette:e.data}}function iw(){let e=po(),{t}=q();return e.status===`unknown`?x(`p`,{role:`status`,className:`shrink-0 px-4 py-1 text-xs text-warning`,children:t(`pipeline.palette.unknown`,`The stored palette cannot be read ({{reason}}). Boxes use the bundled CamStack preset.`,{reason:e.reason})}):null}var aw=[`device`,`page`,`automation`,`script`,`scheduler`,`action`,`template`,`customDevice`,`integration`];function ow(e,t,n=200){if(Mn(t).length===0)return{groups:[],totalMatched:0,truncated:!1};let r=new Map;for(let n of e){let e=zn(t,{label:n.label,keywords:n.keywords,identifiers:n.identifiers});if(e===null)continue;let i=r.get(n.domain)??[];i.push({item:n,rank:e}),r.set(n.domain,i)}let i=0;for(let e of r.values())i+=e.length;let a=n,o=[];for(let e of aw){let t=r.get(e);if(!t||t.length===0||a<=0)continue;t.sort((e,t)=>e.rank-t.rank||e.item.label.localeCompare(t.item.label));let n=t.slice(0,a).map(e=>e.item);a-=n.length,o.push({domain:e,items:n})}return{groups:o,totalMatched:i,truncated:i>n}}function sw(e){return e.flatMap(e=>e.items)}var cw=` · `;function lw(e,t,n,r){let i=[`#${t}`];return r!==void 0&&i.push(r),e.stableId.length>0&&e.stableId!==n&&i.push(e.stableId),i.push(e.type),e.disabled&&i.push(`disabled`),i.join(cw)}function uw(e,t=null){let n=gi(e),r=bo(K.language.startsWith(`it`)?`it`:`en`),i=Pi(e),a=_o(t);return e.map(e=>{let t=String(e.id),o=Mr(e,`compact`,i,r),s=o.length>0?o:e.stableId||`#${t}`,c=n.get(e.id),l=c!==void 0&&(s===c||s.split(cw).includes(c)),u=a(e),d=u.kind===`resolved`?u.integration.name:``;return{key:`device:${t}`,domain:`device`,label:s,subtitle:lw(e,t,s,l?void 0:c),identifiers:[t,`#${t}`],keywords:[...e.name.length>0&&e.name!==s?[e.name]:[],e.stableId,e.addonId,e.location??``,c??``,d].filter(e=>e.length>0),path:`/devices/${t}`,icon:xi(e)}})}function dw(e){return e.map(e=>({key:`integration:${e.id}`,domain:`integration`,label:e.name||e.addonId,subtitle:e.enabled?e.addonId:K.t(`helpers.searchItems.disabled`,{addonId:e.addonId}),keywords:[e.addonId,e.processState],path:K_(e.addonId,e.id)}))}function fw(e,t,n){let r=e.section?.trim();return r?t[r]??e.sectionLabel?.trim()??r:n}function pw(e,t,n){let r=e.flatMap(e=>e.items.map(t=>({key:`page:${t.path}`,domain:`page`,label:t.label,subtitle:e.label??void 0,path:t.path,icon:t.icon,...t.keywords!==void 0&&t.keywords.length>0?{keywords:t.keywords}:{}}))),i={detection:n.detection,cluster:n.cluster,administration:n.administration},a=t.map(e=>({key:`page:addon:${e.addonId}:${e.id}`,domain:`page`,label:e.label,subtitle:fw(e,i,n.ungrouped),keywords:[e.addonId],path:e.path,icon:XC(e.icon)}));return[...r,...a]}var mw=`edit`;function hw(e){return`/build?tab=templates&${mw}=${encodeURIComponent(e)}`}var gw=`const AUTOMATION_RECIPE =`,_w=`// EJECTED from the visual automation editor — this file is now hand-owned.
|
|
4
|
+
Please change the parent <Route path="${e}"> to <Route path="${e===`/`?`*`:`${e}/*`}">.`)}let d=Y(),f;if(t){let e=typeof t==`string`?Xs(t):t;J(l===`/`||e.pathname?.startsWith(l),`When overriding the location using \`<Routes location>\` or \`useRoutes(routes, location)\`, the location pathname must begin with the portion of the URL pathname that was matched by all parent routes. The current pathname base is "${l}" but pathname "${e.pathname}" was given in the \`location\` prop.`),f=e}else f=d;let p=f.pathname||`/`,m=p;if(l!==`/`){let e=l.replace(/^\//,``).split(`/`);m=`/`+p.replace(/^\//,``).split(`/`).slice(e.length).join(`/`)}let h=n&&n.state.matches.length?n.state.matches.map(e=>Object.assign(e,{route:n.manifest[e.route.id]||e.route})):$s(e,{pathname:m});Gs(u||h!=null,`No routes matched location "${f.pathname}${f.search}${f.hash}" `),Gs(h==null||h[h.length-1].route.element!==void 0||h[h.length-1].route.Component!==void 0||h[h.length-1].route.lazy!==void 0,`Matched leaf route at location "${f.pathname}${f.search}${f.hash}" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.`);let g=Cl(h&&h.map(e=>Object.assign({},e,{params:Object.assign({},s,e.params),pathname:Oc([l,r.encodeLocation?r.encodeLocation(e.pathname.replace(/%/g,`%25`).replace(/\?/g,`%3F`).replace(/#/g,`%23`)).pathname:e.pathname]),pathnameBase:e.pathnameBase===`/`?l:Oc([l,r.encodeLocation?r.encodeLocation(e.pathnameBase.replace(/%/g,`%25`).replace(/\?/g,`%3F`).replace(/#/g,`%23`)).pathname:e.pathnameBase])})),i,n);return t&&g?o(Xc.Provider,{value:{location:{pathname:`/`,search:``,hash:``,state:null,key:`default`,mask:void 0,...f},navigationType:`POP`}},g):g}function _l(){let e=Ml(),t=Pc(e)?`${e.status} ${e.statusText}`:e instanceof Error?e.message:JSON.stringify(e),n=e instanceof Error?e.stack:null,r=`rgba(200,200,200, 0.5)`,i={padding:`0.5rem`,backgroundColor:r},a={padding:`2px 4px`,backgroundColor:r},s=null;return console.error(`Error handled by React Router default ErrorBoundary:`,e),s=o(d,null,o(`p`,null,`💿 Hey developer 👋`),o(`p`,null,`You can provide a way better UX than this when your app throws errors by providing your own `,o(`code`,{style:a},`ErrorBoundary`),` or`,` `,o(`code`,{style:a},`errorElement`),` prop on your route.`)),o(d,null,o(`h2`,null,`Unexpected Application Error!`),o(`h3`,{style:{fontStyle:`italic`}},t),n?o(`pre`,{style:i},n):null,s)}var vl=o(_l,null),yl=class extends l{constructor(e){super(e),this.state={location:e.location,revalidation:e.revalidation,error:e.error}}static getDerivedStateFromError(e){return{error:e}}static getDerivedStateFromProps(e,t){return t.location!==e.location||t.revalidation!==`idle`&&e.revalidation===`idle`?{error:e.error,location:e.location,revalidation:e.revalidation}:{error:e.error===void 0?t.error:e.error,location:t.location,revalidation:e.revalidation||t.revalidation}}componentDidCatch(e,t){this.props.onError?this.props.onError(e,t):console.error(`React Router caught the following error during render`,e)}render(){let e=this.state.error;if(this.context&&typeof e==`object`&&e&&`digest`in e&&typeof e.digest==`string`){let t=rl(e.digest);t&&(e=t)}let t=e===void 0?this.props.children:o(Zc.Provider,{value:this.props.routeContext},o(Qc.Provider,{value:e,children:this.props.component}));return this.context?o(xl,{error:e},t):t}};yl.contextType=Wc;var bl=new WeakMap;function xl({children:e,error:t}){let{basename:n}=I(Yc);if(typeof t==`object`&&t&&`digest`in t&&typeof t.digest==`string`){let e=nl(t.digest);if(e){let r=bl.get(t);if(r)throw r;let i=Lc(e.location,n),a=i.absoluteURL||i.to;if(Vc(a))throw Error(`Invalid redirect location`);if(Ic&&!bl.get(t))if(i.isExternal||e.reloadDocument)window.location.href=a;else{let n=Promise.resolve().then(()=>window.__reactRouterDataRouter.navigate(i.to,{replace:e.replace}));throw bl.set(t,n),n}return o(`meta`,{httpEquiv:`refresh`,content:`0;url=${a}`})}}return e}function Sl({routeContext:e,match:t,children:n}){let r=I(Hc);return r&&r.static&&r.staticContext&&(t.route.errorElement||t.route.ErrorBoundary)&&(r.staticContext._deepestRenderedBoundaryId=t.route.id),o(Zc.Provider,{value:e},n)}function Cl(e,t=[],n){let r=n?.state;if(e==null){if(!r)return null;if(r.errors)e=r.matches;else if(t.length===0&&!r.initialized&&r.matches.length>0)e=r.matches;else return null}let i=e,a=r?.errors;if(a!=null){let e=i.findIndex(e=>e.route.id&&a?.[e.route.id]!==void 0);J(e>=0,`Could not find a matching route for errors on route IDs: ${Object.keys(a).join(`,`)}`),i=i.slice(0,Math.min(i.length,e+1))}let s=!1,c=-1;if(n&&r){s=r.renderFallback;for(let e=0;e<i.length;e++){let t=i[e];if((t.route.HydrateFallback||t.route.hydrateFallbackElement)&&(c=e),t.route.id){let{loaderData:e,errors:a}=r,o=t.route.loader&&!e.hasOwnProperty(t.route.id)&&(!a||a[t.route.id]===void 0);if(t.route.lazy||o){n.isStatic&&(s=!0),i=c>=0?i.slice(0,c+1):[i[0]];break}}}}let l=n?.onError,u=r&&l?(e,t)=>{l(e,{location:r.location,params:r.matches?.[0]?.params??{},pattern:Fc(r.matches),errorInfo:t})}:void 0;return i.reduceRight((e,n,l)=>{let d,f=!1,p=null,m=null;r&&(d=a&&n.route.id?a[n.route.id]:void 0,p=n.route.errorElement||vl,s&&(c<0&&l===0?(Fl(`route-fallback`,!1,"No `HydrateFallback` element provided to render during initial hydration"),f=!0,m=null):c===l&&(f=!0,m=n.route.hydrateFallbackElement||null)));let h=t.concat(i.slice(0,l+1)),g=()=>{let t;return t=d?p:f?m:n.route.Component?o(n.route.Component,null):n.route.element?n.route.element:e,o(Sl,{match:n,routeContext:{outlet:e,matches:h,isDataRoute:r!=null},children:t})};return r&&(n.route.ErrorBoundary||n.route.errorElement||l===0)?o(yl,{location:r.location,revalidation:r.revalidation,component:p,error:d,children:g(),routeContext:{outlet:null,matches:h,isDataRoute:!0},onError:u}):g()},null)}function wl(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function Tl(e){let t=I(Hc);return J(t,wl(e)),t}function El(e){let t=I(Uc);return J(t,wl(e)),t}function Dl(e){let t=I(Zc);return J(t,wl(e)),t}function Ol(e){let t=Dl(e),n=t.matches[t.matches.length-1];return J(n.route.id,`${e} can only be used on routes that contain a unique "id"`),n.route.id}function kl(){return Ol(`useRouteId`)}function Al(){let e=El(`useNavigation`);return m(()=>{let{matches:t,historyAction:n,...r}=e.navigation;return r},[e.navigation])}function jl(){let{matches:e,loaderData:t}=El(`useMatches`);return m(()=>e.map(e=>tc(e,t)),[e,t])}function Ml(){let e=I(Qc),t=El(`useRouteError`),n=Ol(`useRouteError`);return e===void 0?t.errors?.[n]:e}function Nl(){let{router:e}=Tl(`useNavigate`),t=Ol(`useNavigate`),n=p(!1);return cl(()=>{n.current=!0}),b(async(r,i={})=>{Gs(n.current,sl),n.current&&(typeof r==`number`?await e.navigate(r):await e.navigate(r,{fromRouteId:t,...i}))},[e,t])}var Pl={};function Fl(e,t,n){!t&&!Pl[e]&&(Pl[e]=!0,Gs(!1,n))}v(Il);function Il({routes:e,manifest:t,future:n,state:r,isStatic:i,onError:a}){return gl(e,void 0,{manifest:t,state:r,isStatic:i,onError:a,future:n})}function X({to:e,replace:t,state:n,relative:r}){J(al(),`<Navigate> may be used only in the context of a <Router> component.`);let{static:i}=I(Yc);Gs(!i,`<Navigate> must not be used on the initial render in a <StaticRouter>. This is a no-op, but you should modify your code so the <Navigate> is only ever rendered in response to some user interaction or state change.`);let{matches:a}=I(Zc),{pathname:o}=Y(),s=ll(),c=Ec(e,Tc(a),o,r===`path`),l=JSON.stringify(c);return S(()=>{s(JSON.parse(l),{replace:t,state:n,relative:r})},[s,l,r,t,n]),null}function Z(e){J(!1,`A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your <Route> in a <Routes>.`)}function Ll({basename:e=`/`,children:t=null,location:n,navigationType:r=`POP`,navigator:i,static:a=!1,useTransitions:s}){J(!al(),`You cannot render a <Router> inside another <Router>. You should never have more than one in your app.`);let c=e.replace(/^\/*/,`/`),l=m(()=>({basename:c,navigator:i,static:a,useTransitions:s,future:{}}),[c,i,a,s]);typeof n==`string`&&(n=Xs(n));let{pathname:u=`/`,search:d=``,hash:f=``,state:p=null,key:h=`default`,mask:g}=n,_=m(()=>{let e=bc(u,c);return e==null?null:{location:{pathname:e,search:d,hash:f,state:p,key:h,mask:g},navigationType:r}},[c,u,d,f,p,h,r,g]);return Gs(_!=null,`<Router basename="${c}"> is not able to match the URL "${u}${d}${f}" because it does not start with the basename, so the <Router> won't render anything.`),_==null?null:o(Yc.Provider,{value:l},o(Xc.Provider,{children:t,value:_}))}function Rl({children:e,location:t}){return hl(zl(e),t)}function zl(e,t=[]){let n=[];return c.forEach(e,(e,r)=>{if(!h(e))return;let i=[...t,r];if(e.type===d){n.push.apply(n,zl(e.props.children,i));return}J(e.type===Z,`[${typeof e.type==`string`?e.type:e.type.name}] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>`),J(!e.props.index||!e.props.children,`An index route cannot have child routes.`);let a={id:e.props.id||i.join(`-`),caseSensitive:e.props.caseSensitive,element:e.props.element,Component:e.props.Component,index:e.props.index,path:e.props.path,middleware:e.props.middleware,loader:e.props.loader,action:e.props.action,hydrateFallbackElement:e.props.hydrateFallbackElement,HydrateFallback:e.props.HydrateFallback,errorElement:e.props.errorElement,ErrorBoundary:e.props.ErrorBoundary,hasErrorBoundary:e.props.hasErrorBoundary===!0||e.props.ErrorBoundary!=null||e.props.errorElement!=null,shouldRevalidate:e.props.shouldRevalidate,handle:e.props.handle,lazy:e.props.lazy};e.props.children&&(a.children=zl(e.props.children,i)),n.push(a)}),n}var Bl=`get`,Vl=`application/x-www-form-urlencoded`;function Hl(e){return typeof HTMLElement<`u`&&e instanceof HTMLElement}function Ul(e){return Hl(e)&&e.tagName.toLowerCase()===`button`}function Wl(e){return Hl(e)&&e.tagName.toLowerCase()===`form`}function Gl(e){return Hl(e)&&e.tagName.toLowerCase()===`input`}function Kl(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function ql(e,t){return e.button===0&&(!t||t===`_self`)&&!Kl(e)}function Jl(e=``){return new URLSearchParams(typeof e==`string`||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce((t,n)=>{let r=e[n];return t.concat(Array.isArray(r)?r.map(e=>[n,e]):[[n,r]])},[]))}function Yl(e,t){let n=Jl(e);return t&&t.forEach((e,r)=>{n.has(r)||t.getAll(r).forEach(e=>{n.append(r,e)})}),n}var Xl=null;function Zl(){if(Xl===null)try{new FormData(document.createElement(`form`),0),Xl=!1}catch{Xl=!0}return Xl}var Ql=new Set([`application/x-www-form-urlencoded`,`multipart/form-data`,`text/plain`]);function $l(e){return e!=null&&!Ql.has(e)?(Gs(!1,`"${e}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${Vl}"`),null):e}function eu(e,t){let n,r,i,a,o;if(Wl(e)){let o=e.getAttribute(`action`);r=o?bc(o,t):null,n=e.getAttribute(`method`)||Bl,i=$l(e.getAttribute(`enctype`))||Vl,a=new FormData(e)}else if(Ul(e)||Gl(e)&&(e.type===`submit`||e.type===`image`)){let o=e.form;if(o==null)throw Error(`Cannot submit a <button> or <input type="submit"> without a <form>`);let s=e.getAttribute(`formaction`)||o.getAttribute(`action`);if(r=s?bc(s,t):null,n=e.getAttribute(`formmethod`)||o.getAttribute(`method`)||Bl,i=$l(e.getAttribute(`formenctype`))||$l(o.getAttribute(`enctype`))||Vl,a=new FormData(o,e),!Zl()){let{name:t,type:n,value:r}=e;if(n===`image`){let e=t?`${t}.`:``;a.append(`${e}x`,`0`),a.append(`${e}y`,`0`)}else t&&a.append(t,r)}}else if(Hl(e))throw Error(`Cannot submit element that is not <form>, <button>, or <input type="submit|image">`);else n=Bl,r=null,i=Vl,o=e;return a&&i===`text/plain`&&(o=a,a=void 0),{action:r,method:n.toLowerCase(),encType:i,formData:a,body:o}}Object.getOwnPropertyNames(Object.prototype).sort().join(`\0`);var tu={"&":`\\u0026`,">":`\\u003e`,"<":`\\u003c`,"\u2028":`\\u2028`,"\u2029":`\\u2029`},nu=/[&><\u2028\u2029]/g;function ru(e){return e.replace(nu,e=>tu[e])}function iu(e,t){if(e===!1||e==null)throw Error(t)}function au(e,t,n,r){let i=typeof e==`string`?new URL(e,typeof window>`u`?`server://singlefetch/`:window.location.origin):e;return n?i.pathname.endsWith(`/`)?i.pathname=`${i.pathname}_.${r}`:i.pathname=`${i.pathname}.${r}`:i.pathname===`/`?i.pathname=`_root.${r}`:t&&bc(i.pathname,t)===`/`?i.pathname=`${kc(t)}/_root.${r}`:i.pathname=`${kc(i.pathname)}.${r}`,i}async function ou(e,t){if(e.id in t)return t[e.id];try{let n=await a(()=>import(e.module),[],import.meta.url);return t[e.id]=n,n}catch(t){return console.error(`Error loading route module \`${e.module}\`, reloading page...`),console.error(t),window.__reactRouterContext&&window.__reactRouterContext.isSpaMode,window.location.reload(),new Promise(()=>{})}}function su(e){return e!=null&&typeof e.page==`string`}function cu(e){return e==null?!1:e.href==null?e.rel===`preload`&&typeof e.imageSrcSet==`string`&&typeof e.imageSizes==`string`:typeof e.rel==`string`&&typeof e.href==`string`}async function lu(e,t,n){return mu((await Promise.all(e.map(async e=>{let r=t.routes[e.route.id];if(r){let e=await ou(r,n);return e.links?e.links():[]}return[]}))).flat(1).filter(cu).filter(e=>e.rel===`stylesheet`||e.rel===`preload`).map(e=>e.rel===`stylesheet`?{...e,rel:`prefetch`,as:`style`}:{...e,rel:`prefetch`}))}function uu(e,t,n,r,i,a){let o=(e,t)=>n[t]?e.route.id!==n[t].route.id:!0,s=(e,t)=>n[t].pathname!==e.pathname||n[t].route.path?.endsWith(`*`)&&n[t].params[`*`]!==e.params[`*`];return a===`assets`?t.filter((e,t)=>o(e,t)||s(e,t)):a===`data`?t.filter((t,a)=>{let c=r.routes[t.route.id];if(!c||!c.hasLoader)return!1;if(o(t,a)||s(t,a))return!0;if(t.route.shouldRevalidate){let r=t.route.shouldRevalidate({currentUrl:new URL(i.pathname+i.search+i.hash,window.origin),currentParams:n[0]?.params||{},nextUrl:new URL(e,window.origin),nextParams:t.params,defaultShouldRevalidate:!0});if(typeof r==`boolean`)return r}return!0}):[]}function du(e,t,{includeHydrateFallback:n}={}){return fu(e.map(e=>{let r=t.routes[e.route.id];if(!r)return[];let i=[r.module];return r.clientActionModule&&(i=i.concat(r.clientActionModule)),r.clientLoaderModule&&(i=i.concat(r.clientLoaderModule)),n&&r.hydrateFallbackModule&&(i=i.concat(r.hydrateFallbackModule)),r.imports&&(i=i.concat(r.imports)),i}).flat(1))}function fu(e){return[...new Set(e)]}function pu(e){let t={},n=Object.keys(e).sort();for(let r of n)t[r]=e[r];return t}function mu(e,t){let n=new Set,r=new Set(t);return e.reduce((e,i)=>{if(t&&!su(i)&&i.as===`script`&&i.href&&r.has(i.href))return e;let a=JSON.stringify(pu(i));return n.has(a)||(n.add(a),e.push({key:a,link:i})),e},[])}function hu(){let e=I(Hc);return iu(e,`You must render this element inside a <DataRouterContext.Provider> element`),e}function gu(){let e=I(Uc);return iu(e,`You must render this element inside a <DataRouterStateContext.Provider> element`),e}var _u=j(void 0);_u.displayName=`FrameworkContext`;function vu(){let e=I(_u);return iu(e,`You must render this element inside a <HydratedRouter> element`),e}function yu(e,t){let n=I(_u),[r,i]=w(!1),[a,o]=w(!1),{onFocus:s,onBlur:c,onMouseEnter:l,onMouseLeave:u,onTouchStart:d}=t,f=p(null);S(()=>{if(e===`render`&&o(!0),e===`viewport`){let e=new IntersectionObserver(e=>{e.forEach(e=>{o(e.isIntersecting)})},{threshold:.5});return f.current&&e.observe(f.current),()=>{e.disconnect()}}},[e]),S(()=>{if(r){let e=setTimeout(()=>{o(!0)},100);return()=>{clearTimeout(e)}}},[r]);let m=()=>{i(!0)},h=()=>{i(!1),o(!1)};return n?e===`intent`?[a,f,{onFocus:bu(s,m),onBlur:bu(c,h),onMouseEnter:bu(l,m),onMouseLeave:bu(u,h),onTouchStart:bu(d,m)}]:[a,f,{}]:[!1,f,{}]}function bu(e,t){return n=>{e&&e(n),n.defaultPrevented||t(n)}}function xu({page:e,...t}){let n=Gc(),{nonce:r}=vu(),{router:i}=hu(),a=m(()=>$s(i.routes,e,i.basename),[i.routes,e,i.basename]);return a?(t.nonce==null&&r&&(t={...t,nonce:r}),o(n?Cu:wu,{page:e,matches:a,...t})):null}function Su(e){let{manifest:t,routeModules:n}=vu(),[r,i]=w([]);return S(()=>{let r=!1;return lu(e,t,n).then(e=>{r||i(e)}),()=>{r=!0}},[e,t,n]),r}function Cu({page:e,matches:t,...n}){let r=Y(),{future:i}=vu(),{basename:a}=hu();return o(d,null,m(()=>{if(e===r.pathname+r.search+r.hash)return[];let n=au(e,a,i.v8_trailingSlashAwareDataRequests,`rsc`),o=!1,s=[];for(let e of t)typeof e.route.shouldRevalidate==`function`?o=!0:s.push(e.route.id);return o&&s.length>0&&n.searchParams.set(`_routes`,s.join(`,`)),[n.pathname+n.search]},[a,i.v8_trailingSlashAwareDataRequests,e,r,t]).map(e=>o(`link`,{key:e,rel:`prefetch`,as:`fetch`,href:e,...n})))}function wu({page:e,matches:t,...n}){let r=Y(),{future:i,manifest:a,routeModules:s}=vu(),{basename:c}=hu(),{loaderData:l,matches:u}=gu(),f=m(()=>uu(e,t,u,a,r,`data`),[e,t,u,a,r]),p=m(()=>uu(e,t,u,a,r,`assets`),[e,t,u,a,r]),h=m(()=>{if(e===r.pathname+r.search+r.hash)return[];let n=new Set,o=!1;if(t.forEach(e=>{let t=a.routes[e.route.id];!t||!t.hasLoader||(!f.some(t=>t.route.id===e.route.id)&&e.route.id in l&&s[e.route.id]?.shouldRevalidate||t.hasClientLoader?o=!0:n.add(e.route.id))}),n.size===0)return[];let u=au(e,c,i.v8_trailingSlashAwareDataRequests,`data`);return o&&n.size>0&&u.searchParams.set(`_routes`,t.filter(e=>n.has(e.route.id)).map(e=>e.route.id).join(`,`)),[u.pathname+u.search]},[c,i.v8_trailingSlashAwareDataRequests,l,r,a,f,t,e,s]),g=m(()=>du(p,a),[p,a]),_=Su(p);return o(d,null,h.map(e=>o(`link`,{key:e,rel:`prefetch`,as:`fetch`,href:e,...n})),g.map(e=>o(`link`,{key:e,rel:`modulepreload`,href:e,...n})),_.map(({key:e,link:t})=>o(`link`,{key:e,nonce:n.nonce,...t,crossOrigin:t.crossOrigin??n.crossOrigin})))}function Tu(...e){return t=>{e.forEach(e=>{typeof e==`function`?e(t):e!=null&&(e.current=t)})}}var Eu=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;try{Eu&&(window.__reactRouterVersion=`7.18.0`)}catch{}function Du({basename:e,children:t,useTransitions:n,window:r}){let i=p();i.current??=Ws({window:r,v5Compat:!0});let a=i.current,[s,c]=w({action:a.action,location:a.location}),l=b(e=>{n===!1?c(e):f(()=>c(e))},[n]);return u(()=>a.listen(l),[a,l]),o(Ll,{basename:e,children:t,location:s.location,navigationType:s.action,navigator:a,useTransitions:n})}function Ou({basename:e,children:t,history:n,useTransitions:r}){let[i,a]=w({action:n.action,location:n.location}),s=b(e=>{r===!1?a(e):f(()=>a(e))},[r]);return u(()=>n.listen(s),[n,s]),o(Ll,{basename:e,children:t,location:i.location,navigationType:i.action,navigator:n,useTransitions:r})}Ou.displayName=`unstable_HistoryRouter`;var ku=A(function({onClick:e,discover:t=`render`,prefetch:n=`none`,relative:r,reloadDocument:i,replace:a,mask:s,state:c,target:l,to:u,preventScrollReset:f,viewTransition:p,defaultShouldRevalidate:m,...h},g){let{basename:_,navigator:v,useTransitions:y}=I(Yc),b=typeof u==`string`&&zs.test(u),x=Lc(u,_);u=x.to;let S=il(u,{relative:r}),C=Y(),w=null;if(s){let e=Ec(s,[],C.mask?C.mask.pathname:`/`,!0);_!==`/`&&(e.pathname=e.pathname===`/`?_:Oc([_,e.pathname])),w=v.createHref(e)}let[T,E,D]=yu(n,h),O=Iu(u,{replace:a,mask:s,state:c,target:l,preventScrollReset:f,relative:r,viewTransition:p,defaultShouldRevalidate:m,useTransitions:y});function k(t){e&&e(t),t.defaultPrevented||O(t)}let A=!(x.isExternal||i),j=o(`a`,{...h,...D,href:(A?w:void 0)||x.absoluteURL||S,onClick:A?k:e,ref:Tu(g,E),target:l,"data-discover":!b&&t===`render`?`true`:void 0});return T&&!b?o(d,null,j,o(xu,{page:S})):j});ku.displayName=`Link`;var Au=A(function({"aria-current":e=`page`,caseSensitive:t=!1,className:n=``,end:r=!1,style:i,to:a,viewTransition:s,children:c,...l},u){let d=ml(a,{relative:l.relative}),f=Y(),p=I(Uc),{navigator:m,basename:h}=I(Yc),g=p!=null&&qu(d)&&s===!0,_=m.encodeLocation?m.encodeLocation(d).pathname:d.pathname,v=f.pathname,y=p&&p.navigation&&p.navigation.location?p.navigation.location.pathname:null;t||(v=v.toLowerCase(),y=y?y.toLowerCase():null,_=_.toLowerCase()),y&&h&&(y=bc(y,h)||y);let b=_!==`/`&&_.endsWith(`/`)?_.length-1:_.length,x=v===_||!r&&v.startsWith(_)&&v.charAt(b)===`/`,S=y!=null&&(y===_||!r&&y.startsWith(_)&&y.charAt(_.length)===`/`),C={isActive:x,isPending:S,isTransitioning:g},w=x?e:void 0,T;T=typeof n==`function`?n(C):[n,x?`active`:null,S?`pending`:null,g?`transitioning`:null].filter(Boolean).join(` `);let E=typeof i==`function`?i(C):i;return o(ku,{...l,"aria-current":w,className:T,ref:u,style:E,to:a,viewTransition:s},typeof c==`function`?c(C):c)});Au.displayName=`NavLink`;var ju=A(({discover:e=`render`,fetcherKey:t,navigate:n,reloadDocument:r,replace:i,state:a,method:s=Bl,action:c,onSubmit:l,relative:u,preventScrollReset:d,viewTransition:p,defaultShouldRevalidate:m,...h},g)=>{let{useTransitions:_}=I(Yc),v=Bu(),y=Vu(c,{relative:u}),b=s.toLowerCase()===`get`?`get`:`post`,x=typeof c==`string`&&zs.test(c);return o(`form`,{ref:g,method:b,action:y,onSubmit:r?l:e=>{if(l&&l(e),e.defaultPrevented)return;e.preventDefault();let r=e.nativeEvent.submitter,o=r?.getAttribute(`formmethod`)||s,c=()=>v(r||e.currentTarget,{fetcherKey:t,method:o,navigate:n,replace:i,state:a,relative:u,preventScrollReset:d,viewTransition:p,defaultShouldRevalidate:m});_&&n!==!1?f(()=>c()):c()},...h,"data-discover":!x&&e===`render`?`true`:void 0})});ju.displayName=`Form`;function Mu({getKey:e,storageKey:t,...n}){let r=I(_u),{basename:i}=I(Yc),a=Y(),s=jl();Gu({getKey:e,storageKey:t});let c=m(()=>{if(!r||!e)return null;let t=Wu(a,s,i,e);return t===a.key?null:t},[]);if(!r||r.isSpaMode)return null;let l=((e,t)=>{if(!window.history.state||!window.history.state.key){let e=Math.random().toString(32).slice(2);window.history.replaceState({key:e},``)}try{let n=JSON.parse(sessionStorage.getItem(e)||`{}`)[t||window.history.state.key];typeof n==`number`&&window.scrollTo(0,n)}catch(t){console.error(t),sessionStorage.removeItem(e)}}).toString();return n.nonce==null&&r?.nonce&&(n.nonce=r.nonce),o(`script`,{...n,suppressHydrationWarning:!0,dangerouslySetInnerHTML:{__html:`(${l})(${ru(JSON.stringify(t||Hu))}, ${ru(JSON.stringify(c))})`}})}Mu.displayName=`ScrollRestoration`;function Nu(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function Pu(e){let t=I(Hc);return J(t,Nu(e)),t}function Fu(e){let t=I(Uc);return J(t,Nu(e)),t}function Iu(e,{target:t,replace:n,mask:r,state:i,preventScrollReset:a,relative:o,viewTransition:s,defaultShouldRevalidate:c,useTransitions:l}={}){let u=ll(),d=Y(),p=ml(e,{relative:o});return b(m=>{if(ql(m,t)){m.preventDefault();let t=n===void 0?Ys(d)===Ys(p):n,h=()=>u(e,{replace:t,mask:r,state:i,preventScrollReset:a,relative:o,viewTransition:s,defaultShouldRevalidate:c});l?f(()=>h()):h()}},[d,u,p,n,r,i,t,e,a,o,s,c,l])}function Lu(e){Gs(typeof URLSearchParams<`u`,"You cannot use the `useSearchParams` hook in a browser that does not support the URLSearchParams API. If you need to support Internet Explorer 11, we recommend you load a polyfill such as https://github.com/ungap/url-search-params.");let t=p(Jl(e)),n=p(!1),r=Y(),i=m(()=>Yl(r.search,n.current?null:t.current),[r.search]),a=ll();return[i,b((e,t)=>{let r=Jl(typeof e==`function`?e(new URLSearchParams(i)):e);n.current=!0,a(`?`+r,t)},[a,i])]}var Ru=0,zu=()=>`__${String(++Ru)}__`;function Bu(){let{router:e}=Pu(`useSubmit`),{basename:t}=I(Yc),n=kl(),r=e.fetch,i=e.navigate;return b(async(e,a={})=>{let{action:o,method:s,encType:c,formData:l,body:u}=eu(e,t);a.navigate===!1?await r(a.fetcherKey||zu(),n,a.action||o,{defaultShouldRevalidate:a.defaultShouldRevalidate,preventScrollReset:a.preventScrollReset,formData:l,body:u,formMethod:a.method||s,formEncType:a.encType||c,flushSync:a.flushSync}):await i(a.action||o,{defaultShouldRevalidate:a.defaultShouldRevalidate,preventScrollReset:a.preventScrollReset,formData:l,body:u,formMethod:a.method||s,formEncType:a.encType||c,replace:a.replace,state:a.state,fromRouteId:n,flushSync:a.flushSync,viewTransition:a.viewTransition})},[r,i,t,n])}function Vu(e,{relative:t}={}){let{basename:n}=I(Yc),r=I(Zc);J(r,`useFormAction must be used inside a RouteContext`);let[i]=r.matches.slice(-1),a={...ml(e||`.`,{relative:t})},o=Y();if(e==null){a.search=o.search;let e=new URLSearchParams(a.search),t=e.getAll(`index`);if(t.some(e=>e===``)){e.delete(`index`),t.filter(e=>e).forEach(t=>e.append(`index`,t));let n=e.toString();a.search=n?`?${n}`:``}}return(!e||e===`.`)&&i.route.index&&(a.search=a.search?a.search.replace(/^\?/,`?index&`):`?index`),n!==`/`&&(a.pathname=a.pathname===`/`?n:Oc([n,a.pathname])),Ys(a)}var Hu=`react-router-scroll-positions`,Uu={};function Wu(e,t,n,r){let i=null;return r&&(i=r(n===`/`?e:{...e,pathname:bc(e.pathname,n)||e.pathname},t)),i??=e.key,i}function Gu({getKey:e,storageKey:t}={}){let{router:n}=Pu(`useScrollRestoration`),{restoreScrollPosition:r,preventScrollReset:i}=Fu(`useScrollRestoration`),{basename:a}=I(Yc),o=Y(),s=jl(),c=Al();S(()=>(window.history.scrollRestoration=`manual`,()=>{window.history.scrollRestoration=`auto`}),[]),Ku(b(()=>{if(c.state===`idle`){let t=Wu(o,s,a,e);Uu[t]=window.scrollY}try{sessionStorage.setItem(t||Hu,JSON.stringify(Uu))}catch(e){Gs(!1,`Failed to save scroll positions in sessionStorage, <ScrollRestoration /> will not work properly (${e}).`)}window.history.scrollRestoration=`auto`},[c.state,e,a,o,s,t])),typeof document<`u`&&(u(()=>{try{let e=sessionStorage.getItem(t||Hu);e&&(Uu=JSON.parse(e))}catch{}},[t]),u(()=>{let t=n?.enableScrollRestoration(Uu,()=>window.scrollY,e?(t,n)=>Wu(t,n,a,e):void 0);return()=>t&&t()},[n,a,e]),u(()=>{if(r!==!1){if(typeof r==`number`){window.scrollTo(0,r);return}try{if(o.hash){let e=document.getElementById(decodeURIComponent(o.hash.slice(1)));if(e){e.scrollIntoView();return}}}catch{Gs(!1,`"${o.hash.slice(1)}" is not a decodable element ID. The view will not scroll to it.`)}i!==!0&&window.scrollTo(0,0)}},[o,r,i]))}function Ku(e,t){let{capture:n}=t||{};S(()=>{let t=n==null?void 0:{capture:n};return window.addEventListener(`pagehide`,e,t),()=>{window.removeEventListener(`pagehide`,e,t)}},[e,n])}function qu(e,{relative:t}={}){let n=I(Kc);J(n!=null,"`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?");let{basename:r}=Pu(`useViewTransitionState`),i=ml(e,{relative:t});if(!n.isTransitioning)return!1;let a=bc(n.currentLocation.pathname,r)||n.currentLocation.pathname,o=bc(n.nextLocation.pathname,r)||n.nextLocation.pathname;return gc(i.pathname,o)!=null||gc(i.pathname,a)!=null}var Ju=e(t(((e,t)=>{t.exports={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}}))()),Yu=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function Xu(e){var t={type:`tag`,name:``,voidElement:!1,attrs:{},children:[]},n=e.match(/<\/?([^\s]+?)[/\s>]/);if(n&&(t.name=n[1],(Ju.default[n[1]]||e.charAt(e.length-2)===`/`)&&(t.voidElement=!0),t.name.startsWith(`!--`))){var r=e.indexOf(`-->`);return{type:`comment`,comment:r===-1?``:e.slice(4,r)}}for(var i=new RegExp(Yu),a=null;(a=i.exec(e))!==null;)if(a[0].trim())if(a[1]){var o=a[1].trim(),s=[o,``];o.indexOf(`=`)>-1&&(s=o.split(`=`)),t.attrs[s[0]]=s[1],i.lastIndex--}else a[2]&&(t.attrs[a[2]]=a[3].trim().substring(1,a[3].length-1));return t}var Zu=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,Qu=/^\s*$/,$u=Object.create(null);function ed(e,t){switch(t.type){case`text`:return e+t.content;case`tag`:return e+=`<`+t.name+(t.attrs?function(e){var t=[];for(var n in e)t.push(n+`="`+e[n]+`"`);return t.length?` `+t.join(` `):``}(t.attrs):``)+(t.voidElement?`/>`:`>`),t.voidElement?e:e+t.children.reduce(ed,``)+`</`+t.name+`>`;case`comment`:return e+`<!--`+t.comment+`-->`}}var td={parse:function(e,t){t||={},t.components||=$u;var n,r=[],i=[],a=-1,o=!1;if(e.indexOf(`<`)!==0){var s=e.indexOf(`<`);r.push({type:`text`,content:s===-1?e:e.substring(0,s)})}return e.replace(Zu,function(s,c){if(o){if(s!==`</`+n.name+`>`)return;o=!1}var l,u=s.charAt(1)!==`/`,d=s.startsWith(`<!--`),f=c+s.length,p=e.charAt(f);if(d){var m=Xu(s);return a<0?(r.push(m),r):((l=i[a]).children.push(m),r)}if(u&&(a++,(n=Xu(s)).type===`tag`&&t.components[n.name]&&(n.type=`component`,o=!0),n.voidElement||o||!p||p===`<`||n.children.push({type:`text`,content:e.slice(f,e.indexOf(`<`,f))}),a===0&&r.push(n),(l=i[a-1])&&l.children.push(n),i[a]=n),(!u||n.voidElement)&&(a>-1&&(n.voidElement||n.name===s.slice(2,-1))&&(a--,n=a===-1?r:i[a]),!o&&p!==`<`&&p)){l=a===-1?r:i[a].children;var h=e.indexOf(`<`,f),g=e.slice(f,h===-1?void 0:h);Qu.test(g)&&(g=` `),(h>-1&&a+l.length>=0||g!==` `)&&l.push({type:`text`,content:g})}}),r},stringify:function(e){return e.reduce(function(e,t){return e+ed(``,t)},``)}};O();var nd=(e,t)=>{if(!e)return!1;let n=e.props?.children??e.children;return t?n.length>0:!!n},rd=e=>{if(!e)return[];let t=e.props?.children??e.children;return e.props?.i18nIsDynamicList?ad(t):t},id=e=>Array.isArray(e)&&e.every(h),ad=e=>Array.isArray(e)?e:[e],od=(e,t)=>{let n={...t};return n.props={...t.props,...e.props},n},sd=e=>{let t={};if(!e)return t;let n=e=>{ad(e).forEach(e=>{ko(e)||(nd(e)?n(rd(e)):Po(e)&&!h(e)&&Object.assign(t,e))})};return n(e),t},cd=(e,t,n,r)=>{if(!e)return``;let i=``,a=ad(e),o=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return a.forEach((e,a)=>{if(ko(e)){i+=`${e}`;return}if(h(e)){let{props:s,type:c}=e,l=Object.keys(s).length,u=o.indexOf(c)>-1,d=s.children;if(!d&&u&&!l){i+=`<${c}/>`;return}if(!d&&(!u||l)||s.i18nIsDynamicList){i+=`<${a}></${a}>`;return}if(u&&l<=1){let e=ko(d)?d:cd(d,t,n,r);i+=`<${c}>${e}</${c}>`;return}let f=cd(d,t,n,r);i+=`<${a}>${f}</${a}>`;return}if(e===null){jo(n,`TRANS_NULL_VALUE`,`Passed in a null value as child`,{i18nKey:r});return}if(Po(e)){let{format:t,...a}=e,o=Object.keys(a);if(o.length===1){let e=t?`${o[0]}, ${t}`:o[0];i+=`{{${e}}}`;return}jo(n,`TRANS_INVALID_OBJ`,`Invalid child - Object should only have keys {{ value, format }} (format is optional).`,{i18nKey:r,child:e});return}jo(n,`TRANS_INVALID_VAR`,`Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.`,{i18nKey:r,child:e})}),i},ld=(e,t=[],n={})=>{if(!e)return e;let r=Object.keys(n),i=[...t,...r],a=``,o=0;for(;o<e.length;)if(e[o]===`<`){let t=!1,n=e.slice(o).match(/^<\/(\d+|[a-zA-Z][a-zA-Z0-9_-]*)>/);if(n){let e=n[1];(/^\d+$/.test(e)||i.includes(e))&&(t=!0,a+=n[0],o+=n[0].length)}if(!t){let n=e.slice(o).match(/^<(\d+|[a-zA-Z][a-zA-Z0-9_-]*)(\s+[\w-]+(?:=(?:"[^"]*"|'[^']*'|[^\s>]+))?)*\s*(\/)?>/);if(n){let e=n[1];(/^\d+$/.test(e)||i.includes(e))&&(t=!0,a+=n[0],o+=n[0].length)}}t||(a+=`<`,o+=1)}else a+=e[o],o+=1;return a},ud=(e,t,n,r,i,a,s)=>{if(n===``)return[];let l=i.transKeepBasicHtmlNodesFor||[],u=n&&new RegExp(l.map(e=>`<${e}`).join(`|`)).test(n);if(!e&&!t&&!u&&!s)return[n];let f=t??{},p=e=>{ad(e).forEach(e=>{ko(e)||(nd(e)?p(rd(e)):Po(e)&&!h(e)&&Object.assign(f,e))})};p(e);let m=ld(n,l,f),g=td.parse(`<0>${m}</0>`),v={...f,...a},y=(e,t,n)=>{let r=rd(e),i=x(r,t.children,n);return id(r)&&i.length===0||e.props?.i18nIsDynamicList?r:i},b=(e,t,n,r,i)=>{e.dummy?(e.children=t,n.push(_(e,{key:r},i?void 0:t))):n.push(...c.map([e],e=>{if(e.type===d||e.props?.i18nIsDynamicList!==void 0){let n={key:r};return e&&e.props&&Object.keys(e.props).forEach(t=>{t===`children`||t===`i18nIsDynamicList`||(n[t]=e.props[t])}),o(e.type,n,i?null:t)}let n={key:r};return e&&e.props&&Object.keys(e.props).forEach(t=>{t===`ref`||t===`children`||(n[t]=e.props[t])}),_(e,n,i?null:t)}))},x=(e,n,a)=>{let c=ad(e),d=ad(n),f={};return d.reduce((e,n,d)=>{let p=n.children?.[0]?.content&&r.services.interpolator.interpolate(n.children[0].content,v,r.language);if(n.type===`tag`){let m=c[parseInt(n.name,10)];!m&&t&&(m=t[n.name]),a.length===1&&!m&&(m=a[0][n.name]),m||={};let g={...n.attrs};s&&Object.keys(g).forEach(e=>{let t=g[e];ko(t)&&(g[e]=No(t))});let _=Object.keys(g).length===0?m:od({props:g},m),S=h(_),C=S&&nd(n,!0)&&!n.voidElement,w=u&&Po(_)&&_.dummy&&!S,T=Po(t)&&Object.hasOwnProperty.call(t,n.name);if(ko(_)){let t=r.services.interpolator.interpolate(_,v,r.language);e.push(t)}else if(nd(_)||C)b(_,y(_,n,a),e,d);else if(w)b(_,x(c,n.children,a),e,d);else if(Number.isNaN(parseFloat(n.name)))if(T)b(_,y(_,n,a),e,d,n.voidElement);else if(i.transSupportBasicHtmlNodes&&l.indexOf(n.name)>-1)if(n.voidElement)e.push(o(n.name,{key:`${n.name}-${d}`}));else{let t=f[n.name]||0;f[n.name]=t+1;let r,i=0;for(let e=0;e<c.length;e+=1){let a=c[e];if(h(a)&&a.type===n.name){if(i===t){r=a;break}i+=1}}let s=x(r?ad(rd(r)):c,n.children,a);e.push(o(n.name,{key:`${n.name}-${d}`},s))}else if(n.voidElement)e.push(`<${n.name} />`);else{let t=x(c,n.children,a);e.push(`<${n.name}>${t}</${n.name}>`)}else if(Po(_)&&!S){let t=n.children[0]?p:null;t&&e.push(t)}else b(_,p,e,d,n.children.length!==1||!p)}else if(n.type===`text`){let t=i.transWrapTextNodes,a=typeof i.unescape==`function`?i.unescape:Oo().unescape,c=s?a(r.services.interpolator.interpolate(n.content,v,r.language)):r.services.interpolator.interpolate(n.content,v,r.language);t?e.push(o(t,{key:`${n.name}-${d}`},c)):e.push(c)}return e},[])};return rd(x([{dummy:!0,children:e||[]}],g,ad(e||[]))[0])},dd=(e,t,n)=>{let r=e.key||t,i=_(e,{key:r});if(!i.props||!i.props.children||n.indexOf(`${t}/>`)<0&&n.indexOf(`${t} />`)<0)return i;function a(){return o(d,null,i)}return o(a,{key:r})},fd=(e,t)=>e.map((e,n)=>dd(e,n,t)),pd=(e,t)=>{let n={};return Object.keys(e).forEach(r=>{Object.assign(n,{[r]:dd(e[r],r,t)})}),n},md=(e,t,n,r)=>e?Array.isArray(e)?fd(e,t):Po(e)?pd(e,t):(Fo(n,`TRANS_INVALID_COMPONENTS`,`<Trans /> "components" prop expects an object or array`,{i18nKey:r}),null):null,hd=e=>!Po(e)||Array.isArray(e)?!1:Object.keys(e).reduce((e,t)=>e&&Number.isNaN(Number.parseFloat(t)),!0);function gd({children:e,count:t,parent:n,i18nKey:r,context:i,tOptions:a={},values:s,defaults:c,components:l,ns:u,i18n:d,t:f,shouldUnescape:p,...m}){let h=d||Ao();if(!h)return Fo(h,`NO_I18NEXT_INSTANCE`,`Trans: You need to pass in an i18next instance using i18nextReactModule`,{i18nKey:r}),e;let g=f||h.t.bind(h)||(e=>e),_={...Oo(),...h.options?.react},v=u||g.ns||h.options?.defaultNS;v=ko(v)?[v]:v||[`translation`];let{transDefaultProps:y}=_,b=y?.tOptions?{...y.tOptions,...a}:a,x=p??y?.shouldUnescape,S=y?.values?{...y.values,...s}:s,C=y?.components?{...y.components,...l}:l,w=cd(e,_,h,r),T=c||b?.defaultValue||w||_.transEmptyNodeValue||(typeof r==`function`?Do(r):r),{hashTransKey:E}=_,D=r||(E?E(w||T):w||T);s=h.options?.interpolation?.defaultVariables?S&&Object.keys(S).length>0?{...S,...h.options.interpolation.defaultVariables}:{...h.options.interpolation.defaultVariables}:S;let O=sd(e);O&&typeof O.count==`number`&&t===void 0&&(t=O.count);let k=s||t!==void 0&&!h.options?.interpolation?.alwaysFormat||!e?b.interpolation:{interpolation:{...b.interpolation,prefix:`#$?`,suffix:`?$#`}},A={...b,context:i||b.context,count:t,...s,...k,defaultValue:T,ns:v},j=D?g(D,A):T;j===D&&T&&(j=T);let M=md(C,j,h,r),N=M||e,ee=null;hd(M)&&(ee=M,N=e);let P=ud(N,ee,j,h,_,A,x),F=n??_.defaultTransParent;return F?o(F,m,P):P}O();function _d({children:e,count:t,parent:n,i18nKey:r,context:i,tOptions:a={},values:o,defaults:s,components:c,ns:l,i18n:u,t:d,shouldUnescape:f,...p}){let{i18n:m,defaultNS:h}=I(Mo)||{},g=u||m||Ao(),_=d||g?.t.bind(g);return gd({children:e,count:t,parent:n,i18nKey:r,context:i,tOptions:a,values:o,defaults:s,components:c,ns:l||_?.ns||h||g?.options?.defaultNS,i18n:g,t:d,shouldUnescape:f,...p})}O();function vd({i18n:e,defaultNS:t,children:n}){let r=m(()=>({i18n:e,defaultNS:t}),[e,t]);return o(Mo.Provider,{value:r},n)}var yd=`camstack:broker-oauth`;function bd(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.type===`camstack:broker-oauth`&&typeof t.ok==`boolean`}function xd(e,t){return e.split(`{{brokerId}}`).join(encodeURIComponent(t))}function Sd(e,t,n=window){let r=n.location.origin,i=!1,a=e=>{i||(i=!0,n.removeEventListener(`message`,o),window.clearInterval(s),t(e))},o=t=>{t.origin!==r||t.source!==e||bd(t.data)&&a({ok:t.data.ok,...t.data.brokerId===void 0?{}:{brokerId:t.data.brokerId},...t.data.error===void 0?{}:{error:t.data.error}})};n.addEventListener(`message`,o);let s=window.setInterval(()=>{e.closed&&a({ok:!0})},500);return()=>{i=!0,n.removeEventListener(`message`,o),window.clearInterval(s)}}var Cd={open:e=>zo(e),assign:e=>window.location.assign(e),watch:(e,t)=>Sd(e,t)};function wd(e,t,n=Cd){let r=B(Lo(e)),i=n.open(r);if(i===null){n.assign(r);return}n.watch(i,e=>{t?.(e)})}var Td=[`starting`,`awaiting-login`,`captured`,`error`,`cancelled`],Ed=[`awaiting-code`,`captured`,`expired`,`error`,`cancelled`];function Dd(e){return typeof e==`object`&&!!e}function Od(e){return Dd(e)&&typeof e.sessionId==`string`&&typeof e.loginUrl==`string`}function kd(e){return Dd(e)&&typeof e.sessionId==`string`&&typeof e.phase==`string`&&Td.includes(e.phase)}function Ad(e){return Dd(e)&&typeof e.sessionId==`string`&&typeof e.userCode==`string`&&typeof e.verificationUrl==`string`&&typeof e.expiresAt==`number`}function jd(e){return Ad(e)&&Dd(e)&&typeof e.phase==`string`&&Ed.includes(e.phase)}function Md(e){return Dd(e)&&typeof e.brokerId==`string`}function Nd(){return{"Content-Type":`application/json`,Authorization:`Bearer ${localStorage.getItem(`camstack_admin_token`)??``}`}}async function Pd(e,t){try{return await e.json()}catch{throw Error(`${t} failed: HTTP ${e.status}`)}}function Fd(e){let t=Dd(e)&&typeof e.error==`string`?e.error:`Unknown error`;return Error(t)}async function Id(e,t,n){let r=await fetch(B(e),{method:`POST`,headers:Nd(),body:JSON.stringify(t)}),i=await Pd(r,`Sign-in ${e.split(`/`).pop()??`request`}`);if(!r.ok)throw Fd(i);if(!n(i))throw Error(`Unexpected response from server`);return i}function Ld(e,t){return Id(`${e}/start`,t,Od)}function Rd(e,t){return Id(`${e}/code/start`,t,Ad)}async function zd(e,t){let n=new URLSearchParams({sessionId:t}),r=await fetch(B(`${e}/status?${n.toString()}`),{headers:{Authorization:Nd().Authorization??``}}),i=await Pd(r,`Sign-in status`);if(!r.ok)throw Fd(i);if(!jd(i))throw Error(`Unexpected status response from server`);return i}async function Bd(e,t){let n=new URLSearchParams({sessionId:t}),r=await fetch(B(`${e}/status?${n.toString()}`),{headers:{Authorization:Nd().Authorization??``}}),i=await Pd(r,`Sign-in status`);if(!r.ok)throw Fd(i);if(!kd(i))throw Error(`Unexpected status response from server`);return i}function Vd(e,t){return Id(`${e}/commit`,{...t},Md)}async function Hd(e,t){try{await fetch(B(`${e}/cancel`),{method:`POST`,headers:Nd(),body:JSON.stringify({sessionId:t})})}catch{}}O();var Ud=2e3,Wd=1e3;function Gd(e){let t=Math.max(0,Math.ceil(e/1e3));return`${Math.floor(t/60)}:${(t%60).toString().padStart(2,`0`)}`}function Kd({expiresAt:e}){let{t}=q(),[n,r]=w(()=>Date.now());return S(()=>{let e=setInterval(()=>r(Date.now()),Wd);return()=>clearInterval(e)},[]),x(`span`,{className:`text-[11px] text-foreground-subtle`,children:t(`brokers.signIn.codeExpiresIn`,{time:Gd(e-n)})})}function qd({basePath:e,name:t,brokerId:n,getSettings:r,disabled:i,onSignedIn:a}){let{t:o}=q(),[c,l]=w({kind:`idle`}),u=p(!0),d=p(null),f=p(null),m=b(()=>{f.current!==null&&clearInterval(f.current),f.current=null},[]),h=b(()=>{m();let t=d.current;d.current=null,t!==null&&Hd(e,t)},[e,m]);S(()=>(u.current=!0,()=>{u.current=!1,h()}),[h]);let g=b(e=>{m(),u.current&&l({kind:`error`,message:e})},[m]),_=b(async r=>{m(),u.current&&l({kind:`committing`});try{let i=await Vd(e,{sessionId:r,name:t,...n===void 0?{}:{brokerId:n}});d.current=null,u.current&&a(i.brokerId)}catch(e){g(e instanceof Error?e.message:String(e))}},[e,n,g,t,a,m]),v=b(t=>{m(),f.current=setInterval(()=>{(async()=>{try{let n=await zd(e,t);if(n.phase===`captured`)return void await _(t);if(n.phase===`error`)return g(n.error??o(`brokers.signIn.proxyError`));if(n.phase===`expired`){m(),u.current&&l({kind:`expired`});return}n.phase===`cancelled`&&(m(),u.current&&l({kind:`idle`}))}catch{}})()},Ud)},[e,_,g,m,o]),y=async()=>{h(),l({kind:`starting`});try{let t=await Rd(e,r());d.current=t.sessionId,l({kind:`waiting`,code:t}),v(t.sessionId)}catch(e){g(e instanceof Error?e.message:String(e))}},C=()=>{h(),l({kind:`idle`})};if(c.kind===`idle`||c.kind===`error`||c.kind===`expired`)return s(`div`,{className:`space-y-2`,children:[c.kind===`error`&&x(Or,{message:c.message}),c.kind===`expired`&&x(`p`,{className:`text-xs text-warning`,children:o(`brokers.signIn.codeExpired`)}),x(`p`,{className:`text-xs text-foreground-muted`,children:o(`brokers.signIn.codeIntro`)}),s(G,{variant:`primary`,size:`sm`,disabled:i===!0||t.trim().length===0,onClick:()=>void y(),children:[c.kind===`idle`?x(dr,{className:`h-3.5 w-3.5`}):x(Ae,{className:`h-3.5 w-3.5`}),` `,c.kind===`idle`?o(`brokers.signIn.getCode`):o(`brokers.signIn.newCode`)]})]});if(c.kind===`starting`||c.kind===`committing`)return s(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[x(H,{className:`h-4 w-4 animate-spin flex-shrink-0`}),c.kind===`starting`?o(`brokers.signIn.starting`):o(`brokers.signIn.saving`)]});let{code:T}=c;return s(`div`,{className:`space-y-3 rounded-lg border border-border bg-surface p-3`,children:[x(`p`,{className:`text-xs text-foreground-muted`,children:o(`brokers.signIn.codeInstructions`)}),s(`div`,{className:`flex items-center justify-between gap-2 rounded-md border border-border-subtle bg-background px-3 py-2`,children:[x(`span`,{"data-testid":`device-code`,className:`font-mono text-2xl font-semibold tracking-widest text-foreground break-all`,children:T.userCode}),x(hi,{value:T.userCode,srLabel:o(`brokers.signIn.copyCode`)})]}),s(G,{variant:`primary`,size:`sm`,onClick:()=>window.open(T.verificationUrl,`_blank`,`noopener,noreferrer`),children:[x(wt,{className:`h-3.5 w-3.5`}),` `,o(`brokers.signIn.openCodePage`,{host:Jd(T.verificationUrl)})]}),s(`div`,{className:`flex flex-wrap items-center justify-between gap-2 pt-1`,children:[s(`span`,{className:`flex min-w-0 flex-col text-[11px] text-foreground-subtle`,children:[s(`span`,{className:`flex items-center gap-2`,children:[x(H,{className:`h-3 w-3 animate-spin flex-shrink-0`}),` `,o(`brokers.signIn.waitingForCode`)]}),x(Kd,{expiresAt:T.expiresAt})]}),x(G,{variant:`outline`,size:`sm`,className:`shrink-0 whitespace-nowrap`,onClick:C,children:o(`brokers.signIn.cancel`)})]})]})}function Jd(e){try{let t=new URL(e);return`${t.host}${t.pathname===`/`?``:t.pathname}`}catch{return e}}O();var Yd=2e3;function Xd(e){return e.startsWith(`/`)&&!e.startsWith(`//`)?new URL(e,window.location.origin).toString():e}function Zd({basePath:e,name:t,brokerId:n,getSettings:r,disabled:i,onSignedIn:a}){let{t:o}=q(),[c,l]=w({kind:`idle`}),u=p(!0),d=p(null),f=p(null),m=b(()=>{f.current!==null&&clearInterval(f.current),f.current=null},[]),h=b(()=>{m();let t=d.current;d.current=null,t!==null&&Hd(e,t)},[e,m]);S(()=>(u.current=!0,()=>{u.current=!1,h()}),[h]);let g=b(e=>{m(),u.current&&l({kind:`error`,message:e})},[m]),_=b(async r=>{m(),u.current&&l({kind:`committing`});try{let i=await Vd(e,{sessionId:r,name:t,...n===void 0?{}:{brokerId:n}});d.current=null,u.current&&a(i.brokerId)}catch(e){g(e instanceof Error?e.message:String(e))}},[e,n,g,t,a,m]),v=b(t=>{m(),f.current=setInterval(()=>{(async()=>{try{let n=await Bd(e,t);if(n.phase===`captured`)return void await _(t);if(n.phase===`error`)return g(n.error??o(`brokers.signIn.proxyError`));if(n.phase===`cancelled`){m(),u.current&&l({kind:`idle`});return}u.current&&l({kind:`waiting`,loginUrl:n.loginUrl,ready:n.phase===`awaiting-login`})}catch{}})()},Yd)},[e,_,g,m,o]),y=async()=>{h(),l({kind:`starting`});try{let t=await Ld(e,r());d.current=t.sessionId,l({kind:`waiting`,loginUrl:t.loginUrl,ready:!1}),v(t.sessionId)}catch(e){g(e instanceof Error?e.message:String(e))}};return c.kind===`idle`||c.kind===`error`?s(`div`,{className:`space-y-2`,children:[c.kind===`error`&&x(Or,{message:c.message}),x(`p`,{className:`text-xs text-foreground-muted`,children:o(`brokers.signIn.intro`)}),s(G,{variant:`primary`,size:`sm`,disabled:i===!0||t.trim().length===0,onClick:()=>void y(),children:[x(dr,{className:`h-3.5 w-3.5`}),` `,c.kind===`error`?o(`common.retry`):o(`brokers.signIn.start`)]})]}):c.kind===`starting`||c.kind===`committing`?s(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[x(H,{className:`h-4 w-4 animate-spin flex-shrink-0`}),c.kind===`starting`?o(`brokers.signIn.starting`):o(`brokers.signIn.saving`)]}):s(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:[c.ready?s(F,{children:[x(`p`,{className:`text-xs font-semibold text-foreground`,children:o(`brokers.signIn.openLink`)}),x(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`brokers.signIn.afterLogin`)}),s(G,{variant:`primary`,size:`sm`,onClick:()=>window.open(Xd(c.loginUrl),`_blank`,`noopener,noreferrer`),children:[x(wt,{className:`h-3.5 w-3.5`}),` `,o(`brokers.signIn.openLoginPage`)]})]}):s(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[x(H,{className:`h-4 w-4 animate-spin flex-shrink-0`}),o(`brokers.signIn.waitingForProxy`)]}),s(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[s(`span`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[x(H,{className:`h-3 w-3 animate-spin`}),` `,o(`brokers.signIn.waitingForLogin`)]}),x(G,{variant:`outline`,size:`sm`,onClick:()=>{h(),l({kind:`idle`})},children:o(`brokers.signIn.cancel`)})]})]})}O();var Qd=[`device-code`];function $d({methods:e,...t}){let{t:n}=q(),r=e!==void 0&&e.length>0?e:Qd,[i,a]=w(null),o=i!==null&&r.includes(i)?i:r[0]??`device-code`;return s(`div`,{className:`space-y-2`,children:[r.length>1&&x(ra,{value:o,onValueChange:e=>a(e===`device-code`?e:`proxy`),appearance:`pills`,children:x(io,{"aria-label":n(`brokers.signIn.method`),children:r.map(e=>x(sa,{value:e,children:n(e===`device-code`?`brokers.signIn.methodDeviceCode`:`brokers.signIn.methodProxy`)},e))})}),o===`device-code`?x(qd,{...t},`device-code`):x(Zd,{...t},`proxy`)]})}function ef(e){return t=>Object.prototype.hasOwnProperty.call(e,t)}var tf=ef({devices:!0}),nf=ef({classes:!0,classesExclude:!0,labelEquals:!0,identities:!0,identitiesExclude:!0,eventTypeTokens:!0,sensorKinds:!0}),rf=ef({minConfidence:!0,minImportance:!0,minLabelConfidence:!0}),af=ef({minDwellSeconds:!0}),of=ef({source:!0}),sf=ef({crossing:!0}),cf=ef({packagePhase:!0}),lf=ef({sensorTransition:!0}),uf=ef({plates:!0}),df=ef({occupancy:!0}),ff=ef({audio:!0}),pf=ef({systemEvent:!0}),mf=ef({deviceState:!0}),hf=ef({scene:!0});function gf(e,t){let n=e[t];return Array.isArray(n)?n:[]}function _f(e,t){let n=e[t];return typeof n==`number`?n:void 0}var vf=`event-emitter`;function yf(e){let t=new Map,n=[],r=!1,i=0;for(let a of e){if(a.status===`pending`){r=!0;continue}if(a.status===`error`){n.push(a.deviceName);continue}if(a.data===null||a.data===void 0)continue;let e=sn.safeParse(a.data);if(!e.success){n.push(a.deviceName);continue}i+=1;for(let n of Qn(e.data)){let e=t.get(n.id);e===void 0?t.set(n.id,{label:n.label,devices:[a.deviceName]}):e.devices.includes(a.deviceName)||t.set(n.id,{label:e.label,devices:[...e.devices,a.deviceName]})}}let a=i>1;return{options:[...t.entries()].map(([e,t])=>a?{value:e,label:t.label,hint:t.devices.join(`, `)}:{value:e,label:t.label}),pending:r,unknownDevices:n,eventDeviceCount:i}}function bf(e,t,n){let r=new Set(t.map(e=>e.id)),i=new Map((n??[]).map(e=>[e.id,e.name]));return e.filter(e=>!r.has(e)).map(e=>({deviceId:e,deviceName:i.get(e)??`#${e}`}))}O();function xf(e,t){let n=V().trpcClient,r=k({queries:e.map(e=>({queryKey:[[`nc-pickers`,`zones`],{deviceId:e}],staleTime:3e4,queryFn:async()=>({deviceId:e,zones:(await n.zones.listZones.query({deviceId:e})).map(e=>({id:e.id,name:e.name}))})}))});return m(()=>{let e=[],n=new Set;for(let i of r){if(!i.data)continue;let r=t.find(e=>e.id===i.data.deviceId)?.name;for(let t of i.data.zones)n.has(t.id)||(n.add(t.id),e.push({value:t.id,label:t.name,...r===void 0?{}:{hint:r}}))}return{options:e,loading:r.some(e=>e.isLoading),failed:r.some(e=>e.isError)}},[r,t])}function Sf(e){let t=V().trpcClient,n=k({queries:e.map(e=>({queryKey:[[`nc-pickers`,`event-kinds`],{deviceId:e}],staleTime:6e4,queryFn:async()=>(await t.pipelineAnalytics.listEventKinds.query({deviceId:e})).map(e=>({kind:e.kind,label:e.label}))}))});return m(()=>{let e=new Map;for(let t of n)for(let n of t.data??[])e.has(n.kind)||e.set(n.kind,n.label);let t=[...e.entries()].map(([e,t])=>({value:e,label:t}));return t.sort((e,t)=>e.label.localeCompare(t.label)),{options:t,loading:n.some(e=>e.isLoading)}},[n])}function Cf(e){let t=V().trpcClient,n=k({queries:e.map(({deviceId:e})=>({queryKey:[[`nc-pickers`,`declared-events`],{deviceId:e}],staleTime:3e4,queryFn:async()=>t.deviceState.getCapSlice.query({deviceId:e,capName:vf})}))});return m(()=>yf(e.map((e,t)=>({...e,status:n[t]?.status??`pending`,data:n[t]?.data}))),[e,n])}function wf(){let e=Fi();return m(()=>({options:(e.data??[]).map(e=>({value:e.id,label:e.name})),loading:e.isLoading,failed:e.isError===!0}),[e.data,e.isLoading,e.isError])}function Tf(){let e=fi({limit:200}),t=xr();return m(()=>{let n=new Set;for(let e of t.data??[])e.name.trim().length>0&&n.add(e.name);let r=new Set;for(let t of e.data??[])t.text.trim().length>0&&r.add(t.text);return[...[...n].sort(),...[...r].sort()]},[e.data,t.data])}function Ef({options:e,value:t,onChange:n,loading:r,emptyHint:i,placeholder:a,noFreeText:o=!1}){let{t:c}=q(),[l,u]=w(``),d=m(()=>new Set(e.map(e=>e.value)),[e]),f=m(()=>new Set(t),[t]),p=t.filter(e=>!d.has(e)),h=e=>{n(f.has(e)?t.filter(t=>t!==e):[...t,e])},g=()=>{let e=l.trim();e.length===0||t.includes(e)||(n([...t,e]),u(``))};return s(`div`,{className:`mt-1 space-y-1.5`,children:[p.length>0&&x(`div`,{className:`flex flex-wrap gap-1`,children:p.map(e=>s(G,{variant:`unstyled`,type:`button`,onClick:()=>n(t.filter(t=>t!==e)),className:`inline-flex items-center gap-1 rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground hover:bg-surface-hover`,title:c(`system.notificationRulePickers.customValueClickToRemove`,`Custom value — click to remove`),children:[e,` ×`]},e))}),e.length>0?x(`div`,{className:`max-h-40 overflow-y-auto rounded-md border border-border divide-y divide-border`,children:e.map(e=>s(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[x(L,{checked:f.has(e.value),onChange:()=>h(e.value),className:`accent-primary`}),x(`span`,{className:`flex-1 truncate`,children:e.label}),e.hint!==void 0&&x(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.hint})]},e.value))}):x(`p`,{className:`text-[10px] text-foreground-subtle`,children:r===!0?c(`common.loading`,`Loading…`):i}),!o&&x(W,{value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),g())},placeholder:a,className:`w-full rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground placeholder:text-foreground-subtle`})]})}var Df=[{value:`immediate`,get label(){return K.t(`helpers.ruleFormParsers.immediate`)},get hint(){return K.t(`helpers.ruleFormParsers.immediateHint`)}},{value:`track-end`,get label(){return K.t(`helpers.ruleFormParsers.trackEnd`)},get hint(){return K.t(`helpers.ruleFormParsers.trackEndHint`)}},{value:`device-event`,get label(){return K.t(`helpers.ruleFormParsers.deviceEvent`)},get hint(){return K.t(`helpers.ruleFormParsers.deviceEventHint`)}},{value:`package-event`,get label(){return K.t(`helpers.ruleFormParsers.packageEvent`)},get hint(){return K.t(`helpers.ruleFormParsers.packageEventHint`)}},{value:`system-event`,get label(){return K.t(`helpers.ruleFormParsers.systemEvent`)},get hint(){return K.t(`helpers.ruleFormParsers.systemEventHint`)}}],Of=`Immediate, grouped`,kf=Df.flatMap(e=>e.value===`immediate`?[e,{value:`immediate-grouped`,get label(){return K.t(`notificationRules.grouping.choice`)},get hint(){return K.t(`helpers.ruleFormParsers.groupedHint`)}}]:[e]);function Af(e){return e.groupingSec!==void 0&&Gt(e)?`immediate-grouped`:e.delivery}function jf(e){let t=(e.delivery===`immediate`||e.delivery===`track-end`)&&Gt({delivery:`immediate`,conditions:e.conditions});return kf.filter(e=>e.value!==`immediate-grouped`||t)}function Mf(e){return kf.find(t=>t.value===e)?.value}function Nf(e,t=Of){return Af(e)===`immediate-grouped`?`${t} · ${String(e.groupingSec)} s`:Ff(e.delivery)}function Pf(e){if(e.trim().length===0)return;let t=Number(e);return Number.isFinite(t)&&t>=0?Math.trunc(t):void 0}function Ff(e){return Df.find(t=>t.value===e)?.label??e}function If(e){return Df.some(t=>t.value===e)}var Lf=[{key:`all`,get label(){return K.t(`helpers.ruleFormParsers.sec_all_label`)},get blurb(){return K.t(`helpers.ruleFormParsers.sec_all_blurb`)},get newRuleLabel(){return K.t(`helpers.ruleFormParsers.sec_all_new`)},get emptyHint(){return K.t(`helpers.ruleFormParsers.sec_all_empty`)},creatable:!0},{key:`detection`,get label(){return K.t(`helpers.ruleFormParsers.sec_detection_label`)},get blurb(){return K.t(`helpers.ruleFormParsers.sec_detection_blurb`)},get newRuleLabel(){return K.t(`helpers.ruleFormParsers.sec_detection_new`)},get emptyHint(){return K.t(`helpers.ruleFormParsers.sec_detection_empty`)},creatable:!0},{key:`sensor`,get label(){return K.t(`helpers.ruleFormParsers.sec_sensor_label`)},get blurb(){return K.t(`helpers.ruleFormParsers.sec_sensor_blurb`)},get newRuleLabel(){return K.t(`helpers.ruleFormParsers.sec_sensor_new`)},get emptyHint(){return K.t(`helpers.ruleFormParsers.sec_sensor_empty`)},creatable:!0},{key:`audio`,get label(){return K.t(`helpers.ruleFormParsers.sec_audio_label`)},get blurb(){return K.t(`helpers.ruleFormParsers.sec_audio_blurb`)},get newRuleLabel(){return K.t(`helpers.ruleFormParsers.sec_audio_new`)},get emptyHint(){return K.t(`helpers.ruleFormParsers.sec_audio_empty`)},creatable:!0},{key:`occupancy`,get label(){return K.t(`helpers.ruleFormParsers.sec_occupancy_label`)},get blurb(){return K.t(`helpers.ruleFormParsers.sec_occupancy_blurb`)},get newRuleLabel(){return K.t(`helpers.ruleFormParsers.sec_occupancy_new`)},get emptyHint(){return K.t(`helpers.ruleFormParsers.sec_occupancy_empty`)},creatable:!0},{key:`device-events`,get label(){return K.t(`helpers.ruleFormParsers.sec_deviceEvents_label`)},get blurb(){return K.t(`helpers.ruleFormParsers.sec_deviceEvents_blurb`)},get newRuleLabel(){return K.t(`helpers.ruleFormParsers.sec_deviceEvents_new`)},get emptyHint(){return K.t(`helpers.ruleFormParsers.sec_deviceEvents_empty`)},creatable:!0},{key:`system`,get label(){return K.t(`helpers.ruleFormParsers.sec_system_label`)},get blurb(){return K.t(`helpers.ruleFormParsers.sec_system_blurb`)},get newRuleLabel(){return K.t(`helpers.ruleFormParsers.sec_system_new`)},get emptyHint(){return K.t(`helpers.ruleFormParsers.sec_system_empty`)},creatable:!0},{key:`alarm`,get label(){return K.t(`helpers.ruleFormParsers.sec_alarm_label`)},get blurb(){return K.t(`helpers.ruleFormParsers.sec_alarm_blurb`)},get newRuleLabel(){return K.t(`helpers.ruleFormParsers.sec_alarm_new`)},get emptyHint(){return K.t(`helpers.ruleFormParsers.sec_alarm_empty`)},creatable:!0},{key:`mixed`,get label(){return K.t(`helpers.ruleFormParsers.sec_mixed_label`)},get blurb(){return K.t(`helpers.ruleFormParsers.sec_mixed_blurb`)},get newRuleLabel(){return K.t(`helpers.ruleFormParsers.sec_mixed_new`)},get emptyHint(){return K.t(`helpers.ruleFormParsers.sec_mixed_empty`)},creatable:!1}];function Rf(e){return Nt(Jt(e)).editable}function zf(e){return Dt(Bf(e))}function Bf(e){switch(e){case`device-events`:case`system`:case`alarm`:case`mixed`:return e;default:return}}var Vf=new Map([[0,`helpers.ruleFormParsers.cdNone`],[60,`helpers.ruleFormParsers.cd1m`],[3600,`helpers.ruleFormParsers.cd1h`]]),Hf=86400;function Uf(e){let t=Vf.get(e);return t===void 0?e%3600==0?K.t(`helpers.ruleFormParsers.cdHours`,{count:e/3600}):e%60==0?K.t(`helpers.ruleFormParsers.cdMinutes`,{count:e/60}):K.t(`helpers.ruleFormParsers.cdSeconds`,{count:e}):K.t(t)}function Wf(e){if(e.trim().length===0)return;let t=Number(e);return Number.isFinite(t)&&t>=0?Math.trunc(t):void 0}var Gf=[{value:`rule-device`,get label(){return K.t(`helpers.ruleFormParsers.scopeDevice`)}},{value:`rule`,get label(){return K.t(`helpers.ruleFormParsers.scopeRule`)}}];function Kf(e){return Gf.find(t=>t.value===e)?.value}var qf=[{value:`per-class`,get label(){return K.t(`helpers.ruleFormParsers.granPerClass`)}},{value:`shared`,get label(){return K.t(`helpers.ruleFormParsers.granShared`)}}];function Jf(e){return qf.find(t=>t.value===e)?.value}var Yf=[{value:`scene-boxes`,get label(){return K.t(`helpers.ruleFormParsers.imageSceneBoxes`)},get description(){return K.t(`helpers.ruleFormParsers.imageSceneBoxesDesc`)}},{value:`crop`,get label(){return K.t(`helpers.ruleFormParsers.imageCrop`)},get description(){return K.t(`helpers.ruleFormParsers.imageCropDesc`)}},{value:`clean`,get label(){return K.t(`helpers.ruleFormParsers.imageClean`)},get description(){return K.t(`helpers.ruleFormParsers.imageCleanDesc`)}},{value:`none`,get label(){return K.t(`helpers.ruleFormParsers.imageNone`)},get description(){return K.t(`helpers.ruleFormParsers.imageNoneDesc`)}}];function Xf(e){return Yf.find(t=>t.value===e)?.value}var Zf=[{value:``,get label(){return K.t(`helpers.ruleFormParsers.linkedDefault`)}},{value:`mosaic`,get label(){return K.t(`helpers.ruleFormParsers.linkedMosaic`)}},{value:`each`,get label(){return K.t(`helpers.ruleFormParsers.linkedEach`)}}];function Qf(e){let t=Zf.find(t=>t.value===e)?.value;return t===``?void 0:t}var $f=[{value:``,get label(){return K.t(`helpers.ruleFormParsers.profileLowest`)}},{value:`low`,get label(){return K.t(`helpers.ruleFormParsers.profileLow`)}},{value:`mid`,get label(){return K.t(`helpers.ruleFormParsers.profileMid`)}},{value:`high`,get label(){return K.t(`helpers.ruleFormParsers.profileHigh`)}}];function ep(e){let t=$f.find(t=>t.value===e)?.value;return t===``?void 0:t}var tp=[{value:`any`,get label(){return K.t(`helpers.ruleFormParsers.srcAny`)}},{value:`pipeline`,get label(){return K.t(`helpers.ruleFormParsers.srcPipeline`)}},{value:`onboard`,get label(){return K.t(`helpers.ruleFormParsers.srcOnboard`)}},{value:`sensor`,get label(){return K.t(`helpers.ruleFormParsers.srcSensor`)}}],np=[{value:`delivered`,get label(){return K.t(`helpers.ruleFormParsers.phaseDelivered`)}},{value:`picked-up`,get label(){return K.t(`helpers.ruleFormParsers.phasePickedUp`)}},{value:`both`,get label(){return K.t(`helpers.ruleFormParsers.phaseBoth`)}}],rp=[{value:``,get label(){return K.t(`helpers.ruleFormParsers.stBoth`)}},{value:`raised`,get label(){return K.t(`helpers.ruleFormParsers.stRaised`)}},{value:`cleared`,get label(){return K.t(`helpers.ruleFormParsers.stCleared`)}}];function ip(e){return e===`raised`||e===`cleared`?e:void 0}function ap(e,t){return e===`sensorTransition`?jn(t.sensorKinds):!0}var op=[{value:`enter`,get label(){return K.t(`helpers.ruleFormParsers.crossEnter`)}},{value:`exit`,get label(){return K.t(`helpers.ruleFormParsers.crossExit`)}},{value:`any`,get label(){return K.t(`helpers.ruleFormParsers.crossAny`)}}],sp=`enter`;function cp(e){return e===`exit`||e===`any`?e:void 0}var lp=[{value:1,get label(){return K.t(`helpers.ruleFormParsers.prioMin`)}},{value:2,get label(){return K.t(`helpers.ruleFormParsers.prioLow`)}},{value:3,get label(){return K.t(`helpers.ruleFormParsers.prioDefault`)}},{value:4,get label(){return K.t(`helpers.ruleFormParsers.prioHigh`)}},{value:5,get label(){return K.t(`helpers.ruleFormParsers.prioMax`)}}];function up(e,t){return e.options&&e.options.length>0?e.options:t}var dp=[{value:``,get label(){return K.t(`helpers.ruleFormParsers.speedDefault`)}},{value:`1`,get label(){return K.t(`helpers.ruleFormParsers.speedReal`)}},{value:`2`,label:`2×`},{value:`3`,label:`3×`},{value:`4`,label:`4×`},{value:`6`,label:`6×`},{value:`8`,label:`8×`}];function fp(e){if(e===``)return;let t=Number(e);return Number.isFinite(t)&&t>=1&&t<=8?t:void 0}var pp={days:[0,1,2,3,4,5,6],minute:480},mp=[{value:1,get label(){return K.t(`helpers.notificationSystemEventDelivery.wd_mon`)}},{value:2,get label(){return K.t(`helpers.notificationSystemEventDelivery.wd_tue`)}},{value:3,get label(){return K.t(`helpers.notificationSystemEventDelivery.wd_wed`)}},{value:4,get label(){return K.t(`helpers.notificationSystemEventDelivery.wd_thu`)}},{value:5,get label(){return K.t(`helpers.notificationSystemEventDelivery.wd_fri`)}},{value:6,get label(){return K.t(`helpers.notificationSystemEventDelivery.wd_sat`)}},{value:0,get label(){return K.t(`helpers.notificationSystemEventDelivery.wd_sun`)}}];function hp(e){let t=Math.floor(e/60),n=e%60;return`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}`}function gp(e){let[t,n]=e.split(`:`),r=Number(t)*60+Number(n);return Number.isFinite(r)?Math.max(0,Math.min(1439,r)):0}var _p={mode:`modes`,onActivation:!0,onDeactivation:!1};function vp(e){return e!==void 0&&Ut.includes(e)}function yp(e,t){return Rt({conditions:t.length>0?{systemEvent:{kinds:[...t]}}:{},...e===void 0?{}:{systemEventDelivery:e}})}function bp(e){return{mode:`modes`,onActivation:e.onActivation,onDeactivation:e.onDeactivation}}function xp(e,t,n){return t===`activation`?{...e,onActivation:n}:t===`deactivation`?{...e,onDeactivation:n}:n?e.onSchedule===void 0?{...e,onSchedule:{schedule:Ot([pp]),grouping:`section`}}:e:bp(e)}function Sp(e,t){return{...e,onSchedule:{schedule:t,grouping:e.onSchedule?.grouping??`section`}}}function Cp(e,t){return e.onSchedule===void 0?e:{...e,onSchedule:{...e.onSchedule,grouping:t}}}function wp(e){let t=new Set,n=0;for(let r of e){let e=zn(r);e===void 0?n+=1:t.add(e.label)}return{adds:[...t],without:n}}function Tp(e){if(typeof e!=`object`||!e||!(`data`in e))return;let t=e.data;if(!(typeof t!=`object`||!t||!(`code`in t)))return typeof t.code==`string`?t.code:void 0}function Ep(e){let t=Object.entries(e).map(([e,t])=>`${e} ${String(t)}`);return t.length>0?K.t(`helpers.notificationSystemEventDelivery.dropped`,{parts:t.join(`, `)}):null}function Dp(e,t,n,r=`rule`){if(e===`error`)return Tp(n)===`NOT_FOUND`?{lines:[`This hub does not serve summary rules yet — update @camstack/server first. A rule saved now would be stored without its summary, and stay instant.`]}:{lines:[`The preview could not be read: ${n instanceof Error?n.message:String(n)}`]};if(e!==`success`||t===void 0)return null;let i=[];if(r===`section`&&t.split===void 0&&i.push(`This hub does not send per-category summaries yet — update @camstack/server first. Until then it sends one message.`),t.empty)i.push(`Nothing to report right now — no notification would be sent.`);else if(t.split===`section`&&t.rows!==void 0){let e=t.rows.length;i.push(`${String(e)} notification${e===1?``:`s`} would be sent now, one per category:`);for(let e of t.rows)i.push(`${e.title}\n${e.text}`)}else i.push(`${String(t.count)} item(s) would be sent now:\n${t.text}`);let a=Ep(t.dropped);return a!==null&&i.push(a),t.excludedGroups.includes(`backups-exports`)&&i.push(`Backups and exports are completed jobs, not a state — they are not in a summary.`),{lines:i}}var Op=`notificationRules.systemEventKinds.`,kp=`notificationRules.systemEventGroups.`,Ap=`notificationRules.systemEventHints.`;function jp(e){return!yn.some(t=>t===e)}function Mp(e){let t=`${Op}${e}`;return K.exists(t)?K.t(t):e}function Np(){return Lt.map(e=>({id:e.id,family:e.family,label:K.t(`${kp}${e.id}`,e.label),hint:K.t(`${Ap}${e.id}`),kinds:e.kinds.filter(jp).map(e=>({value:e,label:Mp(e)}))}))}function Pp(e){return Np().filter(t=>t.family===e)}function Fp(e){let t=Wt(e).conditions.systemEvent;return t===void 0?{kinds:(Pp(e)[0]?.kinds??[]).map(e=>e.value)}:{...t,kinds:[...t.kinds]}}function Ip(){return Np().flatMap(e=>e.kinds)}function Lp(e){return{devices:Ft(e,`deviceIds`),deviceTypes:Ft(e,`deviceTypes`),nodes:Ft(e,`nodeIds`),packages:Ft(e,`packageNames`),consumableThreshold:Ft(e,`consumableLowPercent`),commandActions:Ft(e,`commandActions`),commandOutcomes:Ft(e,`commandOutcomes`),commandActorKinds:Ft(e,`commandActorKinds`)}}function Rp(e,t){let n=an[e],r=Lp(t);return{devices:n.includes(`deviceIds`)&&r.devices,excludeDevices:n.includes(`excludeDeviceIds`)&&r.devices,deviceTypes:n.includes(`deviceTypes`)&&r.deviceTypes,nodes:n.includes(`nodeIds`)&&r.nodes,packages:n.includes(`packageNames`)&&r.packages,consumableThreshold:n.includes(`consumableLowPercent`)&&r.consumableThreshold,commandActions:n.includes(`commandActions`)&&r.commandActions,commandOutcomes:n.includes(`commandOutcomes`)&&r.commandOutcomes,commandActorKinds:n.includes(`commandActorKinds`)&&r.commandActorKinds}}var zp=Object.values(U).map(e=>({value:e,label:Bp(e)})).toSorted((e,t)=>e.label.localeCompare(t.label));function Bp(e){let t=e.replaceAll(`-`,` `);return t.charAt(0).toUpperCase()+t.slice(1)}function Vp(e,t){let n=[],r=new Set;for(let i of e.kinds){let e=zn(i.value);if(e===void 0){n.push({key:i.value,label:i.label,kinds:[i.value],clears:[i.value]});continue}r.has(e.id)||(r.add(e.id),n.push({key:`class:${e.id}`,label:t?e.snapshotLabel:e.label,kinds:t?[...e.bad]:Bt(e),clears:Bt(e),classId:e.id,...t&&e.snapshotSection===null?{noSnapshot:!0}:{}}))}return n}function Hp(e,t){return t.clears.some(t=>e.includes(t))}function Up(e,t,n){if(!Pp(n).some(e=>e.kinds.some(e=>t.kinds.includes(e.value))))return e;let r=e?.kinds??[];if(Hp(r,t)){let i=r.filter(e=>!t.clears.includes(e));return i.length===0?e:qp(e,i,n)}return qp(e,Ip().filter(e=>t.kinds.includes(e.value)||r.includes(e.value)).map(e=>e.value),n)}function Wp(e,t){return t===void 0?void 0:qp(t,t.kinds,e)}function Gp(e,t){let n=e?.kinds??[];if(n.length===0)return;let r=Kp(t,`deviceIds`,e?.deviceIds),i=Kp(t,`excludeDeviceIds`,e?.excludeDeviceIds),a=Kp(t,`deviceTypes`,e?.deviceTypes),o=Kp(t,`nodeIds`,e?.nodeIds),s=Kp(t,`packageNames`,e?.packageNames),c=Object.prototype.hasOwnProperty.call(t,`consumableLowPercent`)?t.consumableLowPercent:e?.consumableLowPercent;return{kinds:[...n],...r===void 0?{}:{deviceIds:[...r]},...i===void 0?{}:{excludeDeviceIds:[...i]},...a===void 0?{}:{deviceTypes:[...a]},...o===void 0?{}:{nodeIds:[...o]},...s===void 0?{}:{packageNames:[...s]},...c===void 0?{}:{consumableLowPercent:c}}}function Kp(e,t,n){let r=Object.prototype.hasOwnProperty.call(e,t)?e[t]:n;return r!==void 0&&r.length===0?void 0:r}function qp(e,t,n){let r=Rp(n,t),i=r.devices?e?.deviceIds:void 0,a=r.excludeDevices?e?.excludeDeviceIds:void 0,o=r.deviceTypes?e?.deviceTypes:void 0,s=r.nodes?e?.nodeIds:void 0,c=r.packages?e?.packageNames:void 0,l=r.consumableThreshold?e?.consumableLowPercent:void 0;return{kinds:[...t],...i&&i.length>0?{deviceIds:[...i]}:{},...a&&a.length>0?{excludeDeviceIds:[...a]}:{},...o&&o.length>0?{deviceTypes:[...o]}:{},...s&&s.length>0?{nodeIds:[...s]}:{},...c&&c.length>0?{packageNames:[...c]}:{},...l===void 0?{}:{consumableLowPercent:l}}}var Jp=95;function Yp(e){let t=e.trim();if(t===``)return{kind:`clear`};let n=Number(t);return Number.isInteger(n)&&n>=1&&n<=Jp?{kind:`set`,value:n}:{kind:`invalid`}}function Xp(e,t=2){if(e===void 0||e.length===0)return K.t(`helpers.notificationSystemEvents.noneSelected`);let n=e.slice(0,t).map(Mp).join(`, `),r=e.length-Math.min(t,e.length);return r>0?`${n} +${r}`:n}function Zp(e){if(e===void 0)return`—`;let t=[],n=e.deviceIds?.length??0,r=e.deviceTypes?.length??0,i=e.nodeIds?.length??0,a=e.packageNames?.length??0,o=e.excludeDeviceIds?.length??0;r>0&&t.push(e.deviceTypes?.map(Bp).join(`, `)??``),n>0&&t.push(`${n} device${n===1?``:`s`}`),i>0&&t.push(`${i} node${i===1?``:`s`}`),a>0&&t.push(`${a} package${a===1?``:`s`}`);let s=o>0?`except ${o} device${o===1?``:`s`}`:null,c=e.consumableLowPercent===void 0?[]:[`consumables at ${e.consumableLowPercent}%`];return t.length===0?[s===null?`Everything`:`Everything ${s}`,...c].join(` · `):[...t,...s===null?[]:[s],...c].join(` · `)}function Qp(e){return e===void 0||(e.deviceTypes?.length??0)===0?!1:e.kinds.some(e=>Ln.includes(e))}var $p=[`all`,`only`,`except`];function em(e,t){return(e??[]).length>0?`only`:(t??[]).length>0?`except`:`all`}function tm(e,t){let n=[...e??[]],r=[...t??[]];return{mode:em(n,r),include:n,exclude:r,legacyBoth:n.length>0&&r.length>0}}function nm(e,t){return{...e,mode:t}}function rm(e){switch(e.mode){case`only`:return e.include;case`except`:return e.exclude;case`all`:return[]}}function im(e,t){switch(e.mode){case`only`:return{...e,include:[...t]};case`except`:return{...e,exclude:[...t]};case`all`:return e}}function am(e){return e.mode===`only`&&e.legacyBoth?e.exclude:[]}function om(e){return{...e,exclude:[],legacyBoth:!1}}function sm(e){switch(e.mode){case`all`:return{};case`except`:return e.exclude.length>0?{exclude:[...e.exclude]}:{};case`only`:{let t=am(e);return{...e.include.length>0?{include:[...e.include]}:{},...t.length>0?{exclude:[...t]}:{}}}}}function cm(e){let t=sm(e),n=t.include??[],r=t.exclude??[];return[...e.include.filter(e=>!n.includes(e)),...e.exclude.filter(e=>!r.includes(e))]}var lm=[`onActivation`,`onDeactivation`,`onTrigger`,`onTriggerOff`],um={onActivation:{get title(){return K.t(`helpers.notificationRuleActions.onActivationTitle`)},get hint(){return K.t(`helpers.notificationRuleActions.onActivationHint`)}},onDeactivation:{get title(){return K.t(`helpers.notificationRuleActions.onDeactivationTitle`)},get hint(){return K.t(`helpers.notificationRuleActions.onDeactivationHint`)}},onTrigger:{get title(){return K.t(`helpers.notificationRuleActions.onTriggerTitle`)},get hint(){return K.t(`helpers.notificationRuleActions.onTriggerHint`)}},onTriggerOff:{get title(){return K.t(`helpers.notificationRuleActions.onTriggerOffTitle`)},get hint(){return K.t(`helpers.notificationRuleActions.onTriggerOffHint`)}}},dm={onActivation:[],onDeactivation:[],onTrigger:[],onTriggerOff:[],buttons:[]};function fm(e){return e===void 0?dm:{onActivation:[...e.onActivation??[]],onDeactivation:[...e.onDeactivation??[]],onTrigger:[...e.onTrigger??[]],onTriggerOff:[...e.onTriggerOff??[]],buttons:[...e.buttons??[]]}}function pm(e){let t=e.buttons.filter(e=>e.id.trim()!==``&&e.label.trim()!==``&&e.actionId.trim()!==``),n=e=>e.filter(e=>e.trim()!==``),r={onActivation:n(e.onActivation),onDeactivation:n(e.onDeactivation),onTrigger:n(e.onTrigger),onTriggerOff:n(e.onTriggerOff)};if(!(!lm.some(e=>r[e].length>0)&&t.length===0))return{...r.onActivation.length>0?{onActivation:[...r.onActivation]}:{},...r.onDeactivation.length>0?{onDeactivation:[...r.onDeactivation]}:{},...r.onTrigger.length>0?{onTrigger:[...r.onTrigger]}:{},...r.onTriggerOff.length>0?{onTriggerOff:[...r.onTriggerOff]}:{},...t.length>0?{buttons:t}:{}}}function mm(e,t){let n=[];for(let r of lm){let i=e[r];i.length>4&&n.push({kind:`too-many`,message:K.t(`helpers.notificationRuleActions.tooMany`,{title:um[r].title})}),i.some(e=>e.trim()!==``&&!t.has(e))&&n.push({kind:`unknown-action`,message:K.t(`helpers.notificationRuleActions.hookUnknownAction`,{title:um[r].title})})}let r=new Set;for(let i of e.buttons){let e=i.id.trim();e!==``&&(r.has(e)&&n.push({kind:`duplicate-button`,message:K.t(`helpers.notificationRuleActions.dupButton`,{id:e})}),r.add(e),t.has(i.actionId.trim())||n.push({kind:`unknown-action`,message:K.t(`helpers.notificationRuleActions.buttonUnknownAction`,{label:i.label||e})}))}return n}function hm(e,t){return{id:`action-${String(e+1)}`,label:K.t(`helpers.notificationRuleActions.newButtonLabel`),actionId:t}}var gm=[{value:`acknowledge`,get label(){return K.t(`helpers.notificationRuleActions.icon_acknowledge`)}},{value:`dismiss`,get label(){return K.t(`helpers.notificationRuleActions.icon_dismiss`)}},{value:`silence`,get label(){return K.t(`helpers.notificationRuleActions.icon_silence`)}},{value:`snooze`,get label(){return K.t(`helpers.notificationRuleActions.icon_snooze`)}},{value:`view`,get label(){return K.t(`helpers.notificationRuleActions.icon_view`)}},{value:`play`,get label(){return K.t(`helpers.notificationRuleActions.icon_play`)}},{value:`camera`,get label(){return K.t(`helpers.notificationRuleActions.icon_camera`)}},{value:`open`,get label(){return K.t(`helpers.notificationRuleActions.icon_open`)}},{value:`close`,get label(){return K.t(`helpers.notificationRuleActions.icon_close`)}},{value:`unlock`,get label(){return K.t(`helpers.notificationRuleActions.icon_unlock`)}},{value:`lock`,get label(){return K.t(`helpers.notificationRuleActions.icon_lock`)}},{value:`disarm`,get label(){return K.t(`helpers.notificationRuleActions.icon_disarm`)}},{value:`arm`,get label(){return K.t(`helpers.notificationRuleActions.icon_arm`)}},{value:`arm-home`,get label(){return K.t(`helpers.notificationRuleActions.icon_arm_home`)}},{value:`arm-away`,get label(){return K.t(`helpers.notificationRuleActions.icon_arm_away`)}},{value:`arm-night`,get label(){return K.t(`helpers.notificationRuleActions.icon_arm_night`)}},{value:`light`,get label(){return K.t(`helpers.notificationRuleActions.icon_light`)}},{value:`alert`,get label(){return K.t(`helpers.notificationRuleActions.icon_alert`)}}];function _m(e){let t=new Set;for(let n of lm)for(let r of e[n])r.trim()!==``&&t.add(r);for(let n of e.buttons)n.actionId.trim()!==``&&t.add(n.actionId);return t}function vm(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[];for(let t of _m(e))r.push(...n.get(t)?.steps??[]);return r}var ym=[10,30,60],bm=[5,10,15,30,60,120,240,480];function xm(e){return e>=60&&e%60==0?K.t(`helpers.ruleFormState.snoozeHours`,{count:e/60}):K.t(`helpers.ruleFormState.snoozeMin`,{count:e})}var Sm=new Set([`alarm-arm-refused`,`alarm-check-failed`,`alarm-arming`,`alarm-armed`,`alarm-pending`,`alarm-triggered`,`alarm-rearmed`,`alarm-sensor-bypass`,`alarm-disarmed`]);function Cm(e,t){for(let t of e.systemEvent?.kinds??[])if(Sm.has(t))return!0;for(let e of t)if(Dn(e))return!0;return!1}function wm(e,t){return vm(e,t)}function Tm(e){let{devices:t,devicesExclude:n,classes:r,classesExclude:i,...a}=e;return{conditions:a,deviceScope:tm(t,n),classScope:tm(r,i)}}function Em(e){let t=sm(e.deviceScope),n=sm(e.classScope);return{...e.conditions,...t.include===void 0?{}:{devices:[...t.include]},...t.exclude===void 0?{}:{devicesExclude:[...t.exclude]},...n.include===void 0?{}:{classes:[...n.include]},...n.exclude===void 0?{}:{classesExclude:[...n.exclude]}}}function Dm(e){return e.deviceScope.mode===`only`?e.deviceScope.include:[]}function Om(e,t,n){let r=Jt(n);return e.some(e=>e.id===t&&jt(e,n.delivery,r))}function km(e=`immediate`,t={}){return{name:``,tags:[],enabled:!0,delivery:e,targetIds:[],targetUsers:[],targetParams:{},targetOverrides:{},priority:3,mediaImage:$t({},Jt({delivery:e,conditions:t})),mediaShowTriggerZone:!1,mediaShowSubjectPath:!1,mediaGif:!1,mediaClip:!1,mediaProfile:void 0,mediaClipSpeed:void 0,mediaLinkedCameras:void 0,mediaWakeSleepingCamera:void 0,templateTitle:``,templateBody:``,...Tm(t),schedule:void 0,systemEventDelivery:e===`system-event`?_p:void 0,snoozeAllowGlobal:!1,groupingSec:void 0,groupWithinSec:en({delivery:e}),snoozeOptions:void 0,askVerdict:void 0,actions:dm,cooldownSec:30,cooldownScope:`rule-device`,cooldownGranularity:void 0}}function Am(e){let t={};for(let n of e.targets)n.params&&Object.keys(n.params).length>0&&(t[n.targetId]=n.params);return{name:e.name,tags:e.tags??[],enabled:e.enabled,delivery:e.delivery,targetIds:e.targets.map(e=>e.targetId),targetUsers:e.targetUsers??[],targetParams:t,targetOverrides:e.targetOverrides??{},priority:e.priority,mediaImage:$t(e.media,Jt(e)),mediaShowTriggerZone:e.media.showTriggerZone===!0,mediaShowSubjectPath:e.media.showSubjectPath===!0,mediaGif:e.media.gif===!0,mediaClip:e.media.clip===!0,mediaProfile:e.media.profile,mediaClipSpeed:e.media.clipSpeed,mediaLinkedCameras:e.media.linkedCameras,mediaWakeSleepingCamera:e.media.wakeSleepingCamera,templateTitle:e.template?.title??``,templateBody:e.template?.body??``,...Tm(e.conditions),schedule:e.schedule,systemEventDelivery:e.systemEventDelivery,snoozeAllowGlobal:e.snoozeAllowGlobal===!0,groupingSec:e.groupingSec,groupWithinSec:en(e),snoozeOptions:e.snoozeOptions,askVerdict:e.askVerdict,actions:fm(e.actions),cooldownSec:e.throttle.cooldownSec,cooldownScope:e.throttle.scope,cooldownGranularity:e.throttle.granularity}}function jm(e,t){let n=[],r=e.groupWithinSec;if((!Number.isInteger(r)||r<0||r>300)&&n.push(`Group notifications within is a whole number of seconds between 0 and 300.`),Bm(e)){let r=e.groupingSec;r!==void 0&&(!Number.isInteger(r)||r<5||r>60)&&n.push(`The grouping window is a whole number of seconds between 5 and 60.`);let i=t?.confirm;i?.enabled===!0&&i.expect!==void 0&&!Vm(i.expect)&&n.push(`This rule’s AI confirm expects more than one subject, but a grouped message judges one picture per subject, so it would never send. Remove the confirm expectation (viewer or API), or choose Immediate.`)}if(Un(e.conditions.audio)&&n.push(`This sound rule names neither a sound nor a level threshold, so it can never fire — every sample would count as a hit and the engine refuses it rather than notifying on silence. Pick at least one sound, or add a level.`),(!Number.isInteger(e.cooldownSec)||e.cooldownSec<0||e.cooldownSec>86400)&&n.push(`The cooldown is a whole number of seconds between 0 and ${String(Hf)} (24 hours). 0 means every match is delivered.`),Mn(e.delivery))for(let t of tn({delivery:e.delivery,conditions:e.conditions,...e.systemEventDelivery===void 0?{}:{systemEventDelivery:e.systemEventDelivery},...pm(e.actions)===void 0?{}:{actions:pm(e.actions)}}))n.push(Xt(t));return n}function Mm(e){let t=e.systemEventDelivery;if(t===void 0)return{};if(!Mn(e.delivery))return t.mode===`instant`?{}:{systemEventDelivery:{mode:`instant`}};let n=ln(e.conditions.systemEvent?.kinds??[]);if(!(n.kind===`family`&&Ut.includes(n.family)))return t.mode===`modes`?{}:{systemEventDelivery:t};let r=dn({systemEventDelivery:t}).schedule;if(r!==null&&It(r.schedule)===null){let e=rn(r.schedule);if(e!==null&&e.times.length>0){let n=Ot(e.times,r.schedule.timezone);if(t.mode===`modes`)return{systemEventDelivery:{...t,onSchedule:{...r,schedule:n}}};if(t.mode===`summary`)return{systemEventDelivery:{...t,schedule:n}}}}return{systemEventDelivery:t}}function Nm(e){if(!Pm(e))return null;if(!Pt(e.templateBody))return K.t(`helpers.ruleFormState.summaryWarnNone`,{token:`{{summaryText}}`});let t=e.templateBody;return on({...e.systemEventDelivery===void 0?{}:{systemEventDelivery:e.systemEventDelivery}})===`section`&&t.trim().length>0&&!/\{\{\s*summaryText\s*\}\}/.test(t)?K.t(`helpers.ruleFormState.summaryWarnSplit`,{token:`{{summaryText}}`}):null}function Pm(e){return Zn({delivery:e.delivery,...e.systemEventDelivery===void 0?{}:{systemEventDelivery:e.systemEventDelivery}})}function Fm(e,t,n=new Set){return jm(e,t).length===0&&If(e.delivery)&&(!Mn(e.delivery)||Gm(e)>0)&&Jt(e)!==`mixed`&&e.name.trim().length>0&&(e.targetIds.length>0||e.targetUsers.length>0)&&mm(e.actions,n).length===0}function Im(e,t){let n=Um(e.conditions,t),r=Mn(t)&&(n.systemEvent?.kinds.length??0)===0,i=Mn(t)&&e.systemEventDelivery===void 0?_p:e.systemEventDelivery;return r?{...e,delivery:t,systemEventDelivery:i,conditions:{...n,systemEvent:Fp(`device-events`)}}:{...e,delivery:t,conditions:n,systemEventDelivery:i}}function Lm(e,t){return t===`immediate-grouped`?Rm(e,{...Im(e,`immediate`),groupingSec:e.groupingSec??20}):Rm(e,{...Im(e,t),groupingSec:void 0})}function Rm(e,t){let n=en({delivery:e.delivery}),r=en({delivery:t.delivery}),i=e.groupWithinSec!==n;return{...t,groupWithinSec:i?e.groupWithinSec:r}}function zm(e){return e.delivery===`immediate`||e.delivery===`track-end`}function Bm(e){return e.groupingSec!==void 0&&Gt(e)}function Vm(e){switch(e.op){case`>`:return 1>e.count;case`<=`:return 1<=e.count;case`<`:return 1<e.count;case`==`:return e.count===1;default:return 1>=e.count}}var Hm=new Set([`immediate`,`track-end`,`package-event`]);function Um(e,t){if(e.source!==`pipeline`||Hm.has(t))return e;let{source:n,...r}=e;return r}function Wm(e,t){return $n(e.conditions.systemEvent)===t?e:{...e,conditions:{...e.conditions,systemEvent:Fp(t)}}}function Gm(e){return e.conditions.systemEvent?.kinds.length??0}function Km(e,t){return n=>{let r=e.find(e=>e.id===n);if(r===void 0)return;let i=t.find(e=>e.kind===r.kind&&e.addonId===r.addonId)?.caps;return i===void 0?void 0:Bn(i)}}function qm(e,t,n){let r=Km(t,n),i=zt(e.map(e=>({name:t.find(t=>t.id===e)?.name??e,fields:r(e)})));return new Map(i.map(e=>[e.field,e]))}function Jm(e,t,n){let r={};for(let i of e){let e=t[i];if(e===void 0)continue;let a=un(e,n?.(i));a!==void 0&&(r[i]=a)}return r}function Ym(e,t,n){let{[t]:r,...i}=e;return n===void 0?i:{...i,[t]:n}}function Xm(e,t,n,r){let{[t]:i,...a}=e,{[n]:o,...s}=i??{},c=r===void 0?s:{...s,[n]:r};return Object.keys(c).length===0?a:{...a,[t]:c}}function Zm(e,t,n){let r=t.find(t=>t.id===e);if(r===void 0)return;let i=n.find(e=>e.kind===r.kind&&e.addonId===r.addonId)?.caps;if(i!==void 0)return{levels:fn(i),attachmentKinds:Ht(i)}}var Qm={rule:{fields:[`title`,`body`,`priority`,`attachments`,`actions`],attachmentKinds:[`none`,`image`,`clip`,`gif`]},summary:{fields:[`title`,`body`,`priority`,`attachments`],attachmentKinds:[`none`,`image`]},timelapse:{fields:[`title`,`body`,`priority`,`attachments`],attachmentKinds:[`none`,`image`,`clip`]},"calendar-events":{fields:[`title`,`body`,`priority`],attachmentKinds:[]}};function $m(e,t){return Qm[e].fields.includes(t)}function eh(e,t){let n=Qm[e].attachmentKinds;return t.filter(e=>n.includes(e))}function th(e){return e.map(e=>({id:e.id,name:e.name,enabled:e.enabled,kind:e.kind??``,addonId:e.addonId??``,config:{}}))}function nh(e,t){return e.appliesTo.includes(t)}var rh={source:`any`};function ih(e,t){if(t==null)return!0;if(Array.isArray(t))return t.length===0;if(typeof t==`string`)return t.length===0||rh[e]===t;if(typeof t==`number`)return!Number.isFinite(t);if(typeof t==`object`){if(`ids`in t){let e=t.ids;return!Array.isArray(e)||e.length===0}if(`values`in t){let e=t.values;return!Array.isArray(e)||e.length===0}return!1}return!1}var ah=Kn.filter(e=>e.id===`audio`);function oh(e){if(e.length===0)return e;let t=new Set(e.map(e=>e.id)),n=ah.filter(e=>!t.has(e.id));return n.length===0?e:[...e,...n]}function sh(e,t,n,r=Jt({delivery:t,conditions:e})){let i=n.length===0?null:new Set(n.filter(e=>e.id!==`schedule`&&jt(e,t,r)).map(e=>e.id)),a={};for(let[t,n]of Object.entries(e))i!==null&&!i.has(t)||ap(t,e)&&(ih(t,n)||(a[t]=n));return a}function ch(e,t){if(e===void 0)return{};let n=Wp(e,t.systemEvent);return n===void 0?{}:{systemEvent:n}}function lh(e){return e!==void 0&&e.windows.length>0}function uh(e){let t={...e.clipPreRollSec===void 0?{}:{clipPreRollSec:e.clipPreRollSec},...e.clipPostRollSec===void 0?{}:{clipPostRollSec:e.clipPostRollSec}};return Object.keys(t).length>0?t:void 0}function dh(e){let t=uh(e.media);return{...e.confirm===void 0?{}:{confirm:e.confirm},...t===void 0?{}:{media:t}}}function fh(e,t,n=[],r){let i=e.templateTitle.trim(),a=e.templateBody.trim(),o=i.length>0||a.length>0?{...i.length>0?{title:i}:{},...a.length>0?{body:a}:{}}:void 0,s=pm(e.actions),c=Jt(e),l=Nt(c),u=Qt(c),d=n.length===0?!0:n.some(t=>t.id===`schedule`&&nh(t,e.delivery)),f=!Pm(e)&&d&&lh(e.schedule)?e.schedule:void 0,p=n.length===0?!0:n.some(t=>t.id===`devices`&&nh(t,e.delivery)),m=n.length===0?!0:n.some(t=>t.id===`devicesExclude`&&nh(t,e.delivery)),{devices:h,devicesExclude:g,..._}=Em(e),v=sh(_,e.delivery,n,c);return{name:e.name.trim(),tags:[...e.tags],enabled:e.enabled,delivery:e.delivery,conditions:{...v,...p&&h!==void 0?{devices:h}:{},...m&&g!==void 0?{devicesExclude:g}:{},...ch(u,e.conditions)},...f?{schedule:f}:{},...Mm(e),targets:e.targetIds.map(t=>{let n=e.targetParams[t];return n&&Object.keys(n).length>0?{targetId:t,params:n}:{targetId:t}}),...e.targetUsers.length>0?{targetUsers:[...e.targetUsers]}:{},targetOverrides:Jm(e.targetIds,e.targetOverrides,r),media:l.carriesMedia?{image:e.mediaImage,...e.mediaShowTriggerZone&&e.mediaImage!==`crop`&&e.mediaImage!==`none`&&At(v).length>0?{showTriggerZone:!0}:{},...e.mediaShowSubjectPath&&e.mediaImage!==`none`&&Xn(c)?{showSubjectPath:!0}:{},...e.mediaGif?{gif:!0}:{},...e.mediaClip?{clip:!0}:{},...e.mediaProfile===void 0?{}:{profile:e.mediaProfile},...e.mediaClipSpeed===void 0?{}:{clipSpeed:e.mediaClipSpeed},...c===`sensor`&&e.mediaImage!==`none`&&e.mediaLinkedCameras!==void 0?{linkedCameras:e.mediaLinkedCameras}:{},...c===`sensor`&&e.mediaImage!==`none`&&e.mediaWakeSleepingCamera===!1?{wakeSleepingCamera:!1}:{},...(e.mediaGif||e.mediaClip)&&t?.media?.clipPreRollSec!==void 0?{clipPreRollSec:t.media.clipPreRollSec}:{},...(e.mediaGif||e.mediaClip)&&t?.media?.clipPostRollSec!==void 0?{clipPostRollSec:t.media.clipPostRollSec}:{}}:{image:`none`},throttle:{cooldownSec:e.cooldownSec,scope:e.cooldownScope,...e.cooldownGranularity===void 0?{}:{granularity:e.cooldownGranularity}},priority:e.priority,...o?{template:o}:{},...e.snoozeAllowGlobal?{snoozeAllowGlobal:!0}:{},...Bm(e)?{groupingSec:e.groupingSec}:{},groupWithinSec:e.groupWithinSec,...e.snoozeOptions===void 0?{}:{snoozeOptions:[...e.snoozeOptions]},...e.askVerdict!==void 0&&zm(e)?{askVerdict:e.askVerdict}:{},...t?.confirm===void 0?{}:{confirm:t.confirm},...s===void 0?{}:{actions:s}}}function ph(e,t){let n=fh(e,void 0,t);return[`template`,`schedule`,`targetUsers`,`snoozeOptions`,`snoozeAllowGlobal`,`groupingSec`,`actions`].filter(e=>n[e]===void 0)}var mh=[{key:`rule`,get label(){return K.t(`helpers.ruleFormTabs.tab_rule`)},fields:[`name`,`tags`,`enabled`,`delivery`,`groupingSec`,`groupWithinSec`,`targetIds`,`targetUsers`,`targetParams`,`targetOverrides`]},{key:`devices`,get label(){return K.t(`helpers.ruleFormTabs.tab_devices`)},fields:[`deviceScope`]},{key:`conditions`,get label(){return K.t(`helpers.ruleFormTabs.tab_conditions`)},fields:[`conditions`,`classScope`,`schedule`]},{key:`notification`,get label(){return K.t(`helpers.ruleFormTabs.tab_notification`)},fields:[`priority`,`mediaImage`,`mediaShowTriggerZone`,`mediaShowSubjectPath`,`mediaGif`,`mediaClip`,`mediaProfile`,`mediaClipSpeed`,`mediaLinkedCameras`,`mediaWakeSleepingCamera`,`templateTitle`,`templateBody`,`systemEventDelivery`]},{key:`actions`,get label(){return K.t(`helpers.ruleFormTabs.tab_actions`)},fields:[`actions`]},{key:`advanced`,get label(){return K.t(`helpers.ruleFormTabs.tab_advanced`)},fields:[`snoozeAllowGlobal`,`snoozeOptions`,`askVerdict`,`cooldownSec`,`cooldownScope`,`cooldownGranularity`]}];function hh(e,t={}){let n=Jt({delivery:e,conditions:t}),r=Nt(n),i=mh.map(e=>e.key===`conditions`?{...e,label:r.label}:e);return Dt(n)?i.filter(e=>e.key!==`devices`):i}function gh(e){if(e.audio!==void 0)return K.t(`helpers.ruleFormTabs.condSound`);if(e.occupancy!==void 0)return K.t(`helpers.ruleFormTabs.condOccupancy`)}function _h(e){let t=Jt(e),n=Kt(Em(e),t);return t===`sensor`&&e.conditions.sensorTransition!==void 0&&!ap(`sensorTransition`,e.conditions)?[...n,{conditionId:`sensorTransition`,reason:Wn}]:n}var vh=`rule`;function yh(e){return mh.find(t=>t.key===e)?.key}function bh(e){return e?.toLowerCase().startsWith(`it`)===!0?`it`:`en`}function xh(){let{i18n:e}=q(),t=bh(e.language);return e=>qt(e,t)}O();var Sh=`block text-[11px] font-medium text-foreground`,Ch=`text-[10px] text-foreground-subtle mt-0.5`;function wh({cameras:e,fleet:t,value:n,onChange:r,emptyMeansAll:i=!1,savedHadDevices:a=!1}){return x(ii,{devices:e,listState:t.state,fleet:t,value:n,onChange:r,emptyMeansAll:i,savedHadDevices:a})}function Th({value:e,placeholder:t,onChange:n}){let{t:r}=q(),[i,a]=w(``),o=()=>{let t=i.trim();if(t.length===0||e.includes(t)){a(``);return}n([...e,t]),a(``)},c=t=>n(e.filter(e=>e!==t));return s(`div`,{className:`mt-1 space-y-1.5`,children:[e.length>0&&x(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>s(`span`,{className:`inline-flex items-center gap-1 rounded bg-surface-hover px-1.5 py-0.5 text-[11px] text-foreground`,children:[e,x(G,{variant:`unstyled`,type:`button`,onClick:()=>c(e),"aria-label":r(`system.notificationConditionWidgets.remove`,`remove {{v}}`,{v:e}),className:`text-foreground-subtle hover:text-danger`,children:x(xe,{className:`h-3 w-3`})})]},e))}),x(W,{value:i,placeholder:t,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),o())},onBlur:o})]})}function Eh({picker:e,value:t,onChange:n}){let{t:r}=q(),i=m(()=>mn(e),[e]),a=m(()=>new Set(t),[t]),o=t.filter(e=>!i.has(e)),c=e=>{n(a.has(e)?t.filter(t=>t!==e):[...t,e])};return s(`div`,{className:`space-y-2`,children:[o.length>0&&x(`div`,{className:`flex flex-wrap gap-1`,children:o.map(e=>s(G,{variant:`unstyled`,type:`button`,onClick:()=>n(t.filter(t=>t!==e)),className:`inline-flex items-center gap-1 rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground hover:bg-surface-hover`,title:r(`system.notificationConditionWidgets.customValueClickToRemove`,`Custom value — click to remove`),children:[e,` ×`]},e))}),e.groups.map(e=>s(`div`,{children:[x(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-muted mb-1`,children:e.fallbackLabel}),x(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map(e=>{let t=a.has(e.value);return x(G,{variant:`unstyled`,type:`button`,"aria-pressed":t,onClick:()=>c(e.value),className:t?`rounded border border-primary bg-primary/15 px-1.5 py-0.5 text-[10px] text-foreground`:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground hover:bg-surface-hover`,children:e.label},e.value)})})]},e.key))]})}function Dh({value:e,min:t,max:n,step:r,onChange:i}){let{t:a}=q();return s(`div`,{className:`mt-1 flex items-center gap-2`,children:[x(W,{type:`number`,value:e??``,min:t,max:n,step:r,className:`max-w-[8rem]`,onChange:e=>{let t=e.target.value;if(t===``){i(void 0);return}let n=Number(t);i(Number.isFinite(n)?n:void 0)}}),e!==void 0&&n!==void 0&&x(We,{min:t,max:n,step:r,value:e,onChange:e=>i(Number(e.target.value)),className:`flex-1 accent-primary`,"aria-label":a(`common.valueWord`)})]})}function Oh({value:e,onChange:t,options:n}){let{t:r}=q(),i=kh(n??[]),a=i.length>0?i:op;return s(`div`,{className:`mt-1 space-y-1`,children:[x(qe,{value:e??`enter`,options:a.map(e=>({value:e.value,label:r(`notificationRules.crossing.${e.value}`,e.label)})),onChange:e=>t(cp(e.target.value))}),x(`p`,{className:Ch,children:r(`notificationRules.crossing.hint`,`Which way the subject crosses the zone.`)})]})}function kh(e){let t=[];for(let n of e){let e=n.value===``||n.value===`enter`?sp:cp(n.value);e===void 0||t.some(t=>t.value===e)||t.push({value:e,label:n.label})}return t}function Ah({deviceIds:e,cameras:t,value:n,onChange:r}){let{options:i,loading:a}=xf(e,t);return x(Ef,{options:i,value:n,onChange:r,loading:a,noFreeText:!0,emptyHint:e.length===0?`Select cameras first — a rule can only use zones those cameras actually have.`:`The selected cameras have no zones. Draw one in the camera’s zone editor first.`,placeholder:``})}function jh({deviceIds:e,cameras:t,allDevices:n,value:r,onChange:i}){let{t:a}=q(),{options:o,loading:c}=Sf(e),l=Cf(m(()=>bf(e,t,n),[e,t,n]));return s(F,{children:[x(Ef,{options:m(()=>{let e=new Set(l.options.map(e=>e.value));return[...l.options,...o.filter(t=>!e.has(t.value))]},[l.options,o]),value:r,onChange:i,loading:c||l.pending,emptyHint:e.length===0?a(`system.notificationConditionWidgets.eventTokensSelectDevices`,`Select a device above to pick one of its events — or type a token.`):a(`system.notificationConditionWidgets.eventTokensNone`,`The selected devices declare no events — type a token.`),placeholder:a(`system.notificationConditionWidgets.eventToken`,`Event token…`)}),l.unknownDevices.length>0&&x(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:a(`system.notificationConditionWidgets.eventTokensUnknown`,`Could not read the events of: {{devices}}. They are unknown, not absent.`,{devices:l.unknownDevices.join(`, `)})})]})}var Mh=[{value:`became-occupied`,labelKey:`system.notificationConditionWidgets.opBecameOccupied`},{value:`became-free`,labelKey:`system.notificationConditionWidgets.opBecameFree`},{value:`>=`,labelKey:`system.notificationConditionWidgets.opCountAtLeast`},{value:`<=`,labelKey:`system.notificationConditionWidgets.opCountAtMost`}];function Nh(e,t){let n=e.map(e=>({value:e.value,label:e.label}));return t===void 0||t===``||n.some(e=>e.value===t)?n:[...n,{value:t,label:K.t(`system.notificationConditionWidgets.subTypeNeverCountsAlways`,`{{stored}} — sub-type, never counts (always 0)`,{stored:t})}]}function Ph({deviceIds:e,cameras:t,classOptions:n,value:r,onChange:i}){let{t:a}=q(),{options:o,loading:c}=xf(e,t),l=r??Mt,u=e=>i({...l,...e}),d=l.op===`became-occupied`||l.op===`became-free`,f=Nh(n,l.className);return s(`div`,{className:`mt-1 space-y-1.5`,children:[s(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[x(`div`,{className:`min-w-[10rem]`,children:x(qe,{value:l.zoneId??``,options:[{value:``,label:c?a(`system.notificationConditionWidgets.loadingZones`,`Loading zones…`):a(`system.notificationConditionWidgets.wholeFrame`,`— whole frame —`)},...o.map(e=>({value:e.value,label:e.label}))],onChange:e=>u({zoneId:e.target.value===``?void 0:e.target.value})})}),x(`div`,{className:`min-w-[9rem]`,children:x(qe,{value:l.className??``,options:[{value:``,label:a(`system.notificationConditionWidgets.anyClass`,`— any class —`)},...f],onChange:e=>u({className:e.target.value===``?void 0:e.target.value})})}),x(`div`,{className:`min-w-[9rem]`,children:x(qe,{value:l.op,options:Mh.map(e=>({value:e.value,label:a(e.labelKey)})),onChange:e=>{let t=Mh.find(t=>t.value===e.target.value);t&&u({op:t.value})}})})]}),s(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:[s(`label`,{className:`flex items-center gap-1`,children:[d?a(`system.notificationConditionWidgets.threshold`,`Threshold`):a(`system.notificationConditionWidgets.count`,`Count`),x(W,{type:`number`,min:0,className:`w-16`,value:String(l.count),onChange:e=>u({count:Math.max(0,Number(e.target.value)||0)})})]}),s(`label`,{className:`flex items-center gap-1`,children:[a(`system.notificationConditionWidgets.holdFor`,`Hold for`),x(W,{type:`number`,min:0,max:3600,className:`w-16`,value:String(l.sustainSeconds),onChange:e=>u({sustainSeconds:Math.min(3600,Math.max(0,Number(e.target.value)||0))})}),`s`]}),r===void 0?null:x(G,{variant:`unstyled`,type:`button`,onClick:()=>i(void 0),className:`underline hover:text-foreground`,children:a(`system.notificationConditionWidgets.clear`,`Clear`)})]}),e.length===0&&x(`p`,{className:`text-[11px] text-warning`,children:a(`system.notificationConditionWidgets.noCameraPickedOnThe`,`No camera picked on the Devices tab: this watches EVERY camera's occupancy, and no zone can be offered until you choose one — a zone id belongs to a camera.`)}),x(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`system.notificationConditionWidgets.countsConfirmedTrackedObjectsFrom`,`Counts confirmed tracked objects from zone analytics. The change must hold for the sustain window before it fires; with no snapshot for the camera or zone the rule never fires.`)})]})}var Fh=[{value:`label`,labelKey:`system.notificationConditionWidgets.audioModeLabel`,Icon:ne},{value:`level`,labelKey:`system.notificationConditionWidgets.audioModeLevel`,Icon:he}];function Ih({taxonomy:e,value:t,onChange:n}){let{t:r}=q(),i=Rn(t),a=e=>n(bn(t,e)),{choices:o,unknownLabels:c}=An(e,i.labels),l=_n(t)??`label`;return s(`div`,{className:`mt-1 space-y-2`,children:[s(`div`,{className:`flex flex-wrap items-center gap-1`,children:[Fh.map(e=>x(G,{variant:`unstyled`,type:`button`,"aria-pressed":l===e.value,onClick:()=>a({mode:e.value}),className:`rounded border px-2 py-0.5 text-[11px] ${l===e.value?`border-primary bg-primary/15 text-foreground`:`border-border text-foreground-subtle hover:bg-surface-hover`}`,children:s(`span`,{className:`inline-flex items-center gap-1`,children:[x(e.Icon,{className:`h-3 w-3`}),r(e.labelKey)]})},e.value)),t===void 0?null:x(G,{variant:`unstyled`,type:`button`,onClick:()=>n(void 0),className:`ml-1 text-xs text-foreground-subtle underline hover:text-foreground`,children:r(`system.notificationConditionWidgets.clear`,`Clear`)})]}),l===`label`?s(F,{children:[x(`div`,{className:`flex flex-wrap gap-1`,children:o.map(e=>{let t=qn(i.labels,e.value),n=e.unknown?`border-dashed border-warning text-warning`:t?`border-primary bg-primary/15 text-foreground`:`border-border text-foreground hover:bg-surface-hover`;return x(G,{variant:`unstyled`,type:`button`,"aria-pressed":t,title:e.unknown?r(`system.notificationConditionWidgets.storedByTheRuleNot`,`Stored by the rule — not offered by this hub`):void 0,onClick:()=>a({labels:Nn(i.labels,e.value)}),className:`rounded border px-1.5 py-0.5 text-[10px] ${n}`,children:s(`span`,{className:`inline-flex items-center gap-1`,children:[x(wa,{iconId:e.iconId,size:12}),e.label]})},e.value)})}),c.length>0&&s(`p`,{className:`text-[10px] text-warning`,children:[r(`system.notificationConditionWidgets.keptFromTheRuleUnknown`,`Kept from the rule, unknown to this hub:`),` `,c.join(`, `)]}),s(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:[s(`label`,{className:`flex items-center gap-1`,children:[r(`system.notificationConditionWidgets.confirmAfter`,`Confirm after`),x(W,{type:`number`,min:1,max:20,step:1,className:`w-16`,value:String(i.confirmHits??2),onChange:e=>a({confirmHits:Number(e.target.value)})}),r(`system.notificationConditionWidgets.frames`)]}),s(`label`,{className:`flex items-center gap-1`,children:[r(`system.notificationConditionWidgets.within`),x(W,{type:`number`,min:1,max:60,step:1,className:`w-16`,value:String(i.confirmWindowSec??5),onChange:e=>a({confirmWindowSec:Number(e.target.value)})}),`s`]})]}),x(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`system.notificationConditionWidgets.audioConfirmHint`,{hits:2,window:5})})]}):s(F,{children:[x(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:s(`label`,{className:`flex items-center gap-1`,children:[r(`system.notificationConditionWidgets.louderThan`,`Louder than`),x(W,{type:`number`,min:wn,max:0,step:3,className:`w-20`,value:String(i.dbThreshold??Yn),onChange:e=>a({dbThreshold:Number(e.target.value)})}),`dBFS`]})}),s(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:[s(`label`,{className:`flex items-center gap-1`,children:[r(`system.notificationConditionWidgets.hits`,`Hits`),x(W,{type:`number`,min:1,max:100,step:5,className:`w-16`,value:String(i.hitPercent),onChange:e=>a({hitPercent:Number(e.target.value)})}),r(`system.notificationConditionWidgets.hitsPercentDefault`,{value:Fn.hitPercent})]}),s(`label`,{className:`flex items-center gap-1`,children:[r(`system.notificationConditionWidgets.over`),x(W,{type:`number`,min:1,max:300,step:5,className:`w-16`,value:String(i.samplingSeconds),onChange:e=>a({samplingSeconds:Number(e.target.value)})}),r(`system.notificationConditionWidgets.secondsDefault`,{value:Fn.samplingSeconds})]})]}),x(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`system.notificationConditionWidgets.dbfsHint`,{min:wn})})]}),Un(t)?x(`p`,{className:`text-[11px] text-warning`,children:r(`system.notificationConditionWidgets.withNeitherASoundNor`,`With neither a sound nor a level threshold this can never match — every sample would be a hit, so the engine refuses it rather than notifying on silence.`)}):null]})}function Lh({value:e,onChange:t}){let{t:n}=q(),r=e?.values??[],i=e?.maxDistance??1,a=e=>t(e.length>0?{values:e,maxDistance:i}:void 0),o=e=>t(r.length>0?{values:r,maxDistance:e}:void 0),c=Tf().filter(e=>!r.includes(e));return s(`div`,{className:`mt-1 space-y-1.5`,children:[x(Th,{value:r,placeholder:n(`system.notificationConditionWidgets.plateText`,`Plate text…`),onChange:a}),c.length>0&&s(`div`,{className:`flex flex-wrap items-center gap-1`,children:[x(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`system.notificationConditionWidgets.seen`,`Seen:`)}),c.slice(0,12).map(e=>x(G,{variant:`unstyled`,type:`button`,onClick:()=>a([...r,e]),className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:e},e))]}),s(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[n(`system.notificationConditionWidgets.maxDistance`,`Max distance`),x(W,{type:`number`,min:0,max:3,step:1,value:i,className:`max-w-[5rem]`,onChange:e=>{let t=Number(e.target.value);o(Number.isFinite(t)?Math.max(0,Math.min(3,t)):1)}})]})]})}function Rh({gateable:e,value:t,onChange:n}){let{t:r}=q(),i=xh(),a=e.find(e=>e.id===t?.deviceId),o=new Set(t?.states??[]),c=e=>{let t=Number(e);if(!Number.isFinite(t)||t===0)return n(void 0);n({deviceId:t,states:[]})},l=e=>{if(t===void 0)return;let r=new Set(o);r.has(e)?r.delete(e):r.add(e),n(r.size===0?void 0:{deviceId:t.deviceId,states:[...r]})};return s(`div`,{className:`mt-1 space-y-2`,children:[x(qe,{value:t===void 0?``:String(t.deviceId),options:[{value:``,label:r(`system.notificationConditionWidgets.noDeviceGate`,`— no device gate —`)},...e.map(e=>({value:String(e.id),label:e.name}))],onChange:e=>c(e.target.value)}),a!==void 0&&x(`div`,{className:`flex flex-wrap gap-1.5`,children:a.states.map(e=>x(G,{variant:`unstyled`,type:`button`,onClick:()=>l(e),className:o.has(e)?`rounded-md border border-primary bg-primary/10 px-2 py-0.5 text-[11px] text-primary`:`rounded-md border border-border px-2 py-0.5 text-[11px] text-foreground-subtle`,children:i(e)},e))}),a!==void 0&&a.states.length===0&&x(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:r(`system.notificationConditionWidgets.thisDeviceReportsNoState`,`This device reports no state the gate can read, so it cannot arm a rule.`)}),t!==void 0&&x(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:r(`system.notificationConditionWidgets.theRuleIsSilentWhile`,`The rule is silent while the device is in any other state — including when its state cannot be read at all.`)})]})}function zh(e,t){let n=t(e.verdict);return e.latched?`${n} · ${t(`latched`)}`:n}function Bh({scenes:e,value:t,onChange:n}){let{t:r}=q(),i=xh(),a=e.find(e=>e.sceneId===t?.sceneId),o=r=>{if(r===``)return n(void 0);let i=e.find(e=>e.sceneId===r);if(i===void 0)return n(void 0);n({sceneId:r,deviceId:i.deviceId,requiredState:t?.requiredState??`diverged`,...t?.latched===void 0?{}:{latched:t.latched}})},c=e=>{t!==void 0&&n({...t,requiredState:e===`matched`?`matched`:`diverged`})},l=e=>{if(t!==void 0){if(e===``){let{latched:e,...r}=t;return n(r)}n({...t,latched:e===`latched`})}};return e.length===0?x(`p`,{className:Ch,children:r(`notificationRules.scene.none`,`No scenes yet — create one on the Scenes page.`)}):s(`div`,{className:`mt-1 space-y-2`,children:[x(qe,{value:t?.sceneId??``,options:[{value:``,label:r(`notificationRules.scene.noGate`,`— no scene gate —`)},...e.map(e=>({value:e.sceneId,label:`${e.cameraName} · ${e.label} — ${zh(e,i)}`}))],onChange:e=>o(e.target.value)}),t!==void 0&&s(`div`,{className:`flex flex-wrap items-center gap-2`,children:[s(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[r(`notificationRules.scene.onlyWhile`,`Only while it is`),x(qe,{value:t.requiredState,options:[{value:`diverged`,label:i(`diverged`)},{value:`matched`,label:i(`matched`)}],onChange:e=>c(e.target.value)})]}),s(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[r(`notificationRules.scene.read`,`Read`),x(qe,{value:t.latched===void 0?``:t.latched?`latched`:`live`,options:[{value:``,label:a===void 0?r(`notificationRules.scene.readOwn`,`The scene's own setting`):`${r(`notificationRules.scene.readOwn`,`The scene's own setting`)} (${i(a.emit)})`},{value:`latched`,label:i(`latched`)},{value:`live`,label:i(`live`)}],onChange:e=>l(e.target.value)})]})]}),a!==void 0&&s(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:[r(`notificationRules.scene.rightNow`,`Right now:`),` `,zh(a,i)]}),t!==void 0&&a===void 0&&x(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:r(`notificationRules.scene.missing`,`This scene no longer exists — pick another or remove the gate.`)})]})}function Vh(e){return hp(e)}function Hh(e){return gp(e)}function Uh(){return{days:[1,2,3,4,5],startMinute:540,endMinute:1080}}function Wh(e){return{days:[...pp.days],minute:e}}var Gh=`Always active — add a window to restrict when the rule fires.`;function Kh({value:e,onChange:t,mode:n=`windows`,defaultMinute:r=pp.minute,emptyHint:i}){return n===`times`?x(Jh,{value:e,onChange:t,defaultMinute:r}):x(qh,{value:e,onChange:t,emptyHint:i??Gh})}function qh({value:e,onChange:t,emptyHint:n}){let{t:r}=q(),i=e?.windows??[],a=e?.invert??!1,o=(n,r)=>{if(n.length===0){t(void 0);return}t({windows:n,...r?{invert:!0}:{},...e?.timezone?{timezone:e.timezone}:{}})},c=()=>o([...i,Uh()],a),l=e=>o(i.filter((t,n)=>n!==e),a),u=(e,t)=>o(i.map((n,r)=>r===e?t:n),a);return s(`div`,{className:`mt-1 space-y-2`,"data-testid":`schedule-field-windows`,children:[i.length===0?x(`p`,{className:Ch,children:n}):i.map((e,t)=>x(Yh,{window:e,onChange:e=>u(t,e),onRemove:()=>l(t)},t)),s(`div`,{className:`flex items-center gap-3`,children:[s(G,{variant:`unstyled`,type:`button`,onClick:c,className:`flex items-center gap-1 rounded-md bg-surface-hover px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground`,children:[x(Ye,{className:`h-3 w-3`}),` `,r(`system.notificationScheduleField.addWindow`)]}),i.length>0&&s(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[x(L,{checked:a,onChange:e=>o([...i],e.target.checked),className:`accent-primary`}),r(`system.notificationScheduleField.activeOutsideTheWindows`,`Active outside the windows`)]})]})]})}function Jh({value:e,onChange:t,defaultMinute:n}){let{t:r}=q(),i=e?.timezone,a=e===void 0?{times:[],approximated:!1}:rn(e);if(a===null)return s(`div`,{className:`mt-1 space-y-2`,"data-testid":`schedule-field-times-fallback`,children:[x(`p`,{className:Ch,children:r(`system.notificationScheduleField.invertedScheduleShownAsBands`,`Inverted schedule — shown as bands. Clear the invert flag (or the windows) to author punctual times.`)}),x(qh,{value:e,onChange:t,emptyHint:Gh})]});let o=a.times,c=e=>{if(e.length===0){t(void 0);return}t(Ot(e,i))};return s(`div`,{className:`mt-1 space-y-2`,"data-testid":`schedule-field-times`,children:[a.approximated&&x(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,"data-testid":`schedule-field-times-approximated`,children:r(`system.notificationScheduleField.shownAsSendAtTimes`,`Shown as send-at times from each window's end (when the summary fires). Edit or save to store them as punctual one-minute windows.`)}),o.length===0?x(`p`,{className:Ch,children:r(`system.notificationScheduleField.noTimesYetAddOne`,`No times yet — add one to send on those days at that clock time.`)}):o.map((e,t)=>x(Xh,{time:e,index:t,onChange:e=>c(o.map((n,r)=>r===t?e:n)),onRemove:o.length>1?()=>c(o.filter((e,n)=>n!==t)):void 0},t)),s(G,{variant:`unstyled`,type:`button`,onClick:()=>c([...o,Wh(n)]),className:`flex items-center gap-1 rounded-md bg-surface-hover px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground`,"data-testid":`schedule-field-add-time`,children:[x(Ye,{className:`h-3 w-3`}),` `,r(`system.notificationScheduleField.addTime`)]})]})}function Yh({window:e,onChange:t,onRemove:n}){let{t:r}=q();return s(`div`,{className:`space-y-1.5 rounded-md border border-border p-2`,children:[s(`div`,{className:`flex items-center gap-2 text-xs`,children:[x(W,{type:`time`,value:Vh(e.startMinute),onChange:n=>t({...e,startMinute:Hh(n.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),x(`span`,{className:`text-foreground-subtle`,children:`→`}),x(W,{type:`time`,value:Vh(e.endMinute),onChange:n=>t({...e,endMinute:Hh(n.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),x(`span`,{className:`flex-1`}),x(G,{variant:`unstyled`,type:`button`,onClick:n,"aria-label":r(`system.notificationScheduleField.removeWindow`,`Remove window`),className:`text-foreground-subtle hover:text-danger`,children:x(gt,{className:`h-3.5 w-3.5`})})]}),x(Zh,{days:e.days,onToggle:n=>{let r=e.days.includes(n)?e.days.filter(e=>e!==n):[...e.days,n];r.length!==0&&t({...e,days:r})}})]})}function Xh({time:e,index:t,onChange:n,onRemove:r}){let{t:i}=q();return s(`div`,{className:`space-y-1.5 rounded-md border border-border p-2`,children:[s(`div`,{className:`flex items-center gap-2 text-xs`,children:[x(`span`,{className:`text-foreground-subtle`,children:i(`system.notificationScheduleField.at`,`At`)}),x(W,{type:`time`,value:hp(e.minute),onChange:t=>n({...e,minute:gp(t.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`,"data-testid":`schedule-field-time-${String(t)}`}),x(`span`,{className:`flex-1`}),r!==void 0&&x(G,{variant:`unstyled`,type:`button`,onClick:r,"aria-label":i(`system.notificationScheduleField.removeTime`,`Remove time`),className:`text-foreground-subtle hover:text-danger`,children:x(gt,{className:`h-3.5 w-3.5`})})]}),x(Zh,{days:e.days,onToggle:t=>{let r=e.days.includes(t)?e.days.filter(e=>e!==t):[...e.days,t];r.length!==0&&n({...e,days:r})}})]})}function Zh({days:e,onToggle:t}){return x(`div`,{className:`flex flex-wrap gap-1`,children:mp.map(n=>x(G,{variant:`unstyled`,type:`button`,onClick:()=>t(n.value),className:`rounded px-1.5 py-0.5 text-[10px] ${e.includes(n.value)?`bg-primary text-primary-foreground`:`bg-surface-hover text-foreground-subtle`}`,children:n.label},n.value))})}function Qh(e){return e>=8}O();function $h(e){if(typeof e!=`object`||!e)return;let t=Reflect.get(e,`windows`);if(!(!Array.isArray(t)||t.length===0))return e}function eg(e){return e.type===`multiselect`}function tg(e){let t=e.suggestions;return t===void 0||t.length===0?[]:t.map(e=>({value:e,label:e}))}function ng(e){return e.map(e=>({value:e.value,label:e.label,...e.description===void 0?{}:{description:e.description},...e.iconId===void 0?{}:{iconId:e.iconId}}))}function rg(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function ig({field:e,values:t,onChange:n,onChangeMany:r,disabled:i,translationFn:a,onTestField:o,externalProbe:c,allFields:l,onAction:u}){let{t:d}=q();if(e.type===`tags`){if(!_i(e,t,l))return null;let r=e.creatable!==!1;return x(mo,{mode:`multi`,options:tg(e),value:rg(t[e.key]),onChange:t=>n(e.key,t),disabled:i===!0||e.disabled===!0,creatable:r,...e.createLabel===void 0?{}:{createLabel:e.createLabel},...e.maxTags===void 0?{}:{maxItems:e.maxTags},label:og(e.label,a),description:e.description===void 0?void 0:og(e.description,a),placeholder:e.placeholder??d(`formBuilder.formBuilder.searchOrAdd`,`Search or add…`),testId:`config-tags-${e.key}`})}if(e.type===`schedule`){if(!_i(e,t,l))return null;let r=og(e.label,a),i=e.description===void 0?void 0:og(e.description,a),o=e.mode===`times`?`times`:`windows`;return s(`div`,{className:`space-y-1`,"data-testid":`config-schedule-${e.key}`,children:[r!==void 0&&x(`label`,{className:`block text-[11px] font-medium text-foreground-subtle`,children:r}),i!==void 0&&x(`p`,{className:`text-[10px] text-foreground-subtle`,children:i}),x(Kh,{mode:o,value:$h(t[e.key]),onChange:t=>n(e.key,t)})]})}return eg(e)&&(Qh(e.options.length)||e.creatable===!0)?_i(e,t,l)?x(mo,{mode:`multi`,options:ng(e.options),value:rg(t[e.key]),onChange:t=>n(e.key,t),disabled:i===!0||e.disabled===!0,creatable:e.creatable===!0,...e.createLabel===void 0?{}:{createLabel:e.createLabel},...e.maxItems===void 0?{}:{maxItems:e.maxItems},label:og(e.label,a),description:e.description===void 0?void 0:og(e.description,a),placeholder:e.placeholder??d(`formBuilder.formBuilder.searchToAdd`,`Search to add…`),testId:`config-multiselect-${e.key}`,listboxId:`msel-${e.key}`}):null:x(ci,{field:e,values:t,onChange:n,onChangeMany:r,disabled:i,translationFn:a,onTestField:o,externalProbe:c,allFields:l,onAction:u})}function ag(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function og(e,t){if(e!==void 0)return t&&ag(e)?t(e):e}function sg({section:e,values:t,onChange:n,onChangeMany:r,disabled:i,translationFn:a,onTestField:o,probeResults:c,onAction:l}){let[u,d]=w(e.defaultCollapsed??!1),f=e.style===`accordion`;if(e.fields.reduce((n,r)=>n+ +!!_i(r,t,e.fields),0)===0)return null;let p=e.fields,m=e.columns??2,h=m===1?`grid-cols-1`:m===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:m===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`,g=e.fields.length===1&&e.fields[0]?.type===`widget`?e.fields[0]:void 0,_=g!==void 0||!e.title&&!e.description;return s(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},"data-settings-section":e.id,children:[!_&&(f?s(`button`,{type:`button`,"aria-expanded":!u,onClick:()=>d(e=>!e),className:`flex w-full items-center justify-between mb-2 text-left`,children:[s(`div`,{children:[e.title&&x(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:og(e.title,a)}),e.description&&x(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:og(e.description,a)})]}),x(go,{expanded:!u,className:`ml-2`})]}):x(`div`,{className:`flex items-center justify-between mb-2`,children:s(`div`,{children:[e.title&&x(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:og(e.title,a)}),e.description&&x(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:og(e.description,a)})]})})),!(u&&!_)&&(g===void 0?x(F,{children:x(`div`,{className:`grid ${h} gap-x-3 gap-y-2.5`,children:p.map(s=>x(ig,{field:s,values:t,onChange:n,onChangeMany:r,disabled:i,translationFn:a,onTestField:o,externalProbe:c?.[s.key],allFields:e.fields,onAction:l},s.key))})}):x(ci,{field:g,values:t,onChange:n,onChangeMany:r,disabled:i,translationFn:a,onTestField:o,externalProbe:c?.[g.key],allFields:e.fields,onAction:l},g.key))]})}function cg({schema:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,probeResults:o,onClearProbe:s,onAction:c,visibilityContext:l}){let u=l?{...l,...t}:t,d=(e,r)=>{n({...t,[e]:r}),s?.(e)},f=e=>{n({...t,...e});for(let t of Object.keys(e))s?.(t)};return x(`div`,{className:`space-y-4`,children:e.sections.map((e,t)=>x(sg,{section:e,values:u,onChange:d,onChangeMany:f,disabled:r,translationFn:i,onTestField:a,probeResults:o,onAction:c},`${e.id}-${t}`))})}function lg(e){return{status:e.status===`validated`||e.status===`rejected`||e.status===`inconclusive`||e.status===`unsupported`?e.status:e.success?`validated`:`rejected`,...e.error===void 0?{}:{error:e.error},...e.detail===void 0?{}:{detail:e.detail}}}var ug={validated:`border-success/30 bg-success/5 text-success`,rejected:`border-danger/30 bg-danger/5 text-danger`,inconclusive:`border-warning/30 bg-warning/5 text-warning`,unsupported:`border-border bg-surface text-foreground-subtle`};function dg({verdict:e}){let{t}=q(),n=(()=>{switch(e.status){case`validated`:return e.detail?`${t(`integrations.connectionSuccess`)} — ${e.detail}`:t(`integrations.connectionSuccess`);case`rejected`:return`${t(`integrations.errorPrefix`)} ${e.error??``}`;case`inconclusive`:return`${t(`integrations.connectionInconclusive`,{defaultValue:`Could not be checked:`})} ${e.error??``}`;case`unsupported`:return e.error??t(`integrations.connectionUntestable`,{defaultValue:`This integration cannot be tested before it is created.`})}})();return x(`div`,{className:`rounded-lg border px-3 py-2 text-xs ${ug[e.status]}`,"data-testid":`connection-test-verdict`,children:n})}var fg=new Set;function pg(e){for(let t of fg)t(e)}function mg(e){return fg.add(e),()=>{fg.delete(e)}}var hg=new Set([`proc`,`sys`,`dev`,`run`,`boot`,`lost+found`,`snap`,`bin`,`sbin`,`lib`,`lib32`,`lib64`,`libx32`,`usr`,`etc`,`var`,`opt`,`tmp`,`srv`,`root`,`System`,`Library`,`Applications`,`cores`,`private`]),gg=[`recordings`,`data`,`mnt`,`media`,`Volumes`];function _g(e){let t=gg.findIndex(t=>t===`recordings`?e.startsWith(t):e===t);return t===-1?gg.length:t}function vg(e){return e.filter(e=>!e.name.startsWith(`.`)&&!hg.has(e.name)).toSorted((e,t)=>{let n=_g(e.name)-_g(t.name);return n===0?e.name.localeCompare(t.name):n}).map(e=>e.path)}O();function yg({nodeId:e,value:t,onChange:n}){let{t:r}=q(),i=V().trpcClient,[a,o]=w([]),[c,l]=w(t),[u,d]=w(null),[f,p]=w(null),[m,h]=w(``),g=b(async(t,r)=>{p(null);try{let a=await i.filesystemBrowse.browse.query({nodeId:e,path:t});d(a),l(a.path),r&&n(a.path)}catch(e){p(e instanceof Error?e.message:`browse failed`)}},[i,e,n]);S(()=>{l(t),(async()=>{let n=await i.filesystemBrowse.browse.query({nodeId:e,path:`/`}).then(e=>e).catch(()=>null);if(n){o(vg(n.entries)),await g(t.startsWith(`/`)?t:`/`,!1);return}try{let n=await i.filesystemBrowse.listAllowedRoots.query({nodeId:e});o(n),await g(t&&n.some(e=>t.startsWith(e))?t:n[0]??``,!1)}catch(e){o([]),d(null),p(e instanceof Error&&/not available on node/i.test(e.message)?`This node can't be browsed remotely. Enter the path manually.`:e instanceof Error?e.message:`browse unavailable`)}})()},[e]);let _=async()=>{if(!(!m.trim()||!u)){p(null);try{let t=`${u.path.replace(/\/+$/,``)}/${m.trim()}`;await i.filesystemBrowse.createDir.mutate({nodeId:e,path:t}),h(``),await g(u.path,!0)}catch(e){p(e instanceof Error?e.message:`create failed`)}}},v=e=>`${(e/1e9).toFixed(1)} GB`;return s(`div`,{className:`space-y-2 rounded border border-border p-2`,children:[x(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>x(G,{variant:`unstyled`,onClick:()=>void g(e,!0),className:`rounded border border-border px-2 py-0.5 text-[10px] font-mono hover:border-primary/40`,children:e},e))}),x(W,{value:c,onChange:e=>{l(e.target.value),n(e.target.value)},placeholder:`/absolute/path`,className:`w-full rounded border border-border bg-background px-2 py-1 text-[11px] font-mono`}),u&&x(`div`,{className:`text-[10px] text-foreground-subtle`,children:r(`storage.pathBrowser.free`,{free:v(u.freeBytes),total:v(u.totalBytes)})}),x(`div`,{className:`max-h-40 space-y-0.5 overflow-y-auto`,children:u?.entries.map(e=>s(G,{variant:`unstyled`,onClick:()=>void g(e.path,!0),className:`block w-full truncate rounded px-2 py-1 text-left text-xs hover:bg-primary/5`,children:[`📁 `,e.name]},e.path))}),s(`div`,{className:`flex gap-1`,children:[x(W,{value:m,onChange:e=>h(e.target.value),placeholder:r(`storage.pathBrowser.newFolder`,`new folder`),className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs`}),x(G,{variant:`unstyled`,onClick:()=>void _(),className:`rounded border border-border px-2 py-1 text-xs hover:border-primary/40`,children:r(`storage.pathBrowser.create`,`Create`)})]}),f&&x(`div`,{className:`text-[10px] text-danger`,children:f})]})}var bg=`storage/path-browser`,xg=`nodeId`,Sg=`providerId`,Cg=`basePath`,wg=`hub`;function Tg(e,t){let n=e[t];return typeof n==`string`?n:``}function Eg(e,t){let n=e.sections.flatMap(e=>e.fields),r=n.find(e=>e.key===xg);if(r===void 0)return null;let i=Tg(t,Sg),a=`showWhen`in r?r.showWhen:void 0;return a!==void 0&&!(i!==``&&a.in?.includes(i))?null:(i===``?[Cg]:[`${i}.${Cg}`,Cg]).find(e=>n.some(t=>t.key===e))??null}function Dg(e,t){let n=Eg(e,t);return n===null?[]:[n]}function Og({schema:e,values:t,onValuesChange:n}){let{t:r}=q(),i=Eg(e,t);if(i===null)return null;let a=Tg(t,xg);return s(`div`,{className:`space-y-1`,children:[x(`p`,{className:`text-xs font-medium text-foreground-muted`,children:r(`storage.pathBrowser.label`,`Folder on the node`)}),x(yg,{nodeId:a===``?wg:a,value:Tg(t,i),onChange:e=>n({...t,[i]:e})})]})}var kg=new Map([[bg,{Component:Og,ownedKeys:Dg}]]);function Ag(e){return kg.get(e)??null}function jg(e,t){return t.length===0?e:{...e,sections:e.sections.map(e=>({...e,fields:e.fields.filter(e=>!t.includes(e.key))}))}}O();function Mg({field:e,values:t,onLabels:n}){let{t:r}=q(),{query:i,found:a}=Wr(e,t);return S(()=>{n(new Map(a.map(e=>[e.value,e.label])))},[a.map(e=>`${e.value}\u0000${e.label}`).join(``),n]),i.isError?x(`p`,{"data-testid":`create-many-labels-failed`,className:`text-xs text-warning`,children:r(`providerInstances.createManyLabelsFailed`,`The names of the choices could not be read ({{message}}); each is named after its value.`,{message:i.error?.message??``})}):null}function Ng(e){for(let t of e?.sections??[])for(let e of t.fields)if(e.type===`select`&&e.discoverOptions?.pickManyOnCreate===!0)return e;return null}function Pg(e,t){return e.type!==`select`||e.key!==t||e.discoverOptions===void 0?e:{...e,discoverOptions:{...e.discoverOptions,multiple:!0}}}function Fg(e,t){return{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>Pg(e,t))}))}}function Ig(e){let{key:t,picked:n,labels:r,typedName:i,values:a}=e;return n.map(e=>({name:n.length===1&&i.length>0?i:r.get(e)??e,values:{...a,[t]:e}}))}function Lg(e,t){let n=[];for(let r of e.links??[]){let e=t[r.field],i=Array.isArray(e)?e:[e];for(let e of i)typeof e!=`string`||e===``||n.some(t=>t.field===r.field&&t.instanceId===e)||n.push({field:r.field,cap:r.to.cap,...r.to.kind===void 0?{}:{kind:r.to.kind},instanceId:e})}return n}function Rg(e,t){return e.find(e=>e.id===t.instanceId&&(t.kind===void 0||e.kind===t.kind))}function zg(e){let t=new Map(e.holders.map(e=>[e.addonId,e])),n=[];for(let r of e.functionProviders){let i=e.displayNames.get(r.addonId)??r.addonId,a=t.get(r.addonId);if(a===void 0){n.push({kind:`fixed`,key:`fixed:${r.addonId}`,addonId:r.addonId,providerName:i,name:i,description:e.descriptions.get(r.addonId)??``,isActive:r.isActive});continue}let o=e.notRunning?.get(r.addonId);for(let e of a.instances){let t=Kg(a.description,e.kind),s=Lg(a.description,e.formValues);n.push({kind:`instance`,key:`${r.addonId}:${e.id}`,addonId:r.addonId,providerName:i,id:e.id,name:e.name,configured:e.configured,enabled:e.enabled??!0,status:e.status,canTest:t?.canTest??a.description.canTest,...e.kind===void 0?{}:{kindId:e.kind},...e.kind===void 0?{}:{kindLabel:t?.label??e.kind},...t?.iconUrl===void 0?{}:{kindIconUrl:t.iconUrl},...e.lastCheckedAt===void 0?{}:{lastCheckedAt:e.lastCheckedAt},...t?.connectPath===void 0?{}:{connectPath:t.connectPath},...t?.disconnectPath===void 0?{}:{disconnectPath:t.disconnectPath},...o===void 0?{}:{notRunning:o},...s.length>0?{links:s}:{}})}}return n}var Bg=new Set([`running`,`unknown`]);function Vg(e){return e!==void 0&&!Bg.has(e)}function Hg(e,t){return typeof e==`object`&&e?Reflect.get(e,t):void 0}function Ug(e){let t=new Map;for(let n of e){let e=Hg(Hg(n,`manifest`),`id`),r=Hg(Hg(n,`process`),`state`);typeof e!=`string`||typeof r!=`string`||Vg(r)&&t.set(e,r)}return t}function Wg(e){let t=new Map;for(let n of e){let e=Hg(n,`manifest`),r=Hg(e,`id`);if(typeof r!=`string`||r.length===0)continue;let i=Hg(e,`name`),a=Hg(e,`packageDisplayName`);t.set(r,typeof i==`string`?i:typeof a==`string`?a:r)}return t}function Gg(e){let t=new Map;for(let n of e){let e=Hg(n,`manifest`),r=Hg(e,`id`),i=Hg(e,`description`);typeof r!=`string`||typeof i!=`string`||i.length>0&&t.set(r,i)}return t}function Kg(e,t){return t===void 0?void 0:e.kinds?.find(e=>e.id===t)}function qg(e,t,n){let r=e.kinds;if(r===void 0||r.length===0)return e;let i=r.filter(e=>n===void 0?e.functionCap===t:e.id===n&&pn(e,t));return i.length===0?null:{...e,kinds:i}}function Jg(e,t){let n=qg(e.description,t);if(n===null)return null;let r=n.kinds;if(e.description.kinds===void 0||r===void 0)return e;let i=new Set(r.map(e=>e.id));return{...e,description:n,instances:e.instances.filter(e=>e.kind===void 0||i.has(e.kind))}}function Yg(e){return(e.kinds?.length??0)>1}function Xg(e,t,n){return Yg(e)&&t!==void 0?t.label:n}function Zg(e){return e.label!==void 0&&e.label.length>0?e.label:e.state}function Qg(e){let t=new Set,n=[];for(let r of e)t.has(r.addonId)||(t.add(r.addonId),n.push({addonId:r.addonId,name:r.providerName}));return n}var $g={error:3,unknown:2,ok:1,off:0};function e_(e){return e.enabled?e.status===void 0?e.configured?`ok`:`unknown`:e.status.state:`off`}function t_(e){let t=null;for(let n of e){let e=e_(n);(t===null||$g[e]>$g[t])&&(t=e)}return t??`unknown`}function n_(e,t,n){return e.map(e=>{let r=n.get(e.addonId)??e.addonId,i=t.filter(t=>t.addonId===e.addonId),a=i.filter(e=>e.kind===`instance`),o=i.find(e=>e.kind===`fixed`);return o===void 0?{addonId:e.addonId,name:r,count:a.length,health:t_(a)}:{addonId:e.addonId,name:r,count:1,health:o.isActive?`ok`:`off`}})}function r_(e,t){return t===null?e:e.filter(e=>e.addonId===t)}function i_(e){return e.filter(e=>e.description.instanceMode===`multiple`||e.instances.length===0)}function a_(e,t){return e.flatMap(e=>{let n=t(e.addonId),r=e.description.kinds??[];return r.length===0?[{addonId:e.addonId,label:n,providerName:n}]:r.map(t=>({addonId:e.addonId,kind:t.id,label:t.label,providerName:n,...t.iconUrl===void 0?{}:{iconUrl:t.iconUrl}}))})}function o_(e){return e.some(e=>e.isError)?`error`:e.some(e=>e.isPending)?`pending`:`ready`}function s_(e,t){if(Object.is(e,t))return!0;if(typeof e!=`object`||typeof t!=`object`||e===null||t===null||Array.isArray(e)!==Array.isArray(t))return!1;let n=e,r=t,i=new Set([...Object.keys(n),...Object.keys(r)]);for(let e of i)if(!s_(n[e],r[e]))return!1;return!0}var c_=`enabled`;function l_(e,t){return t?.sections.some(e=>e.fields.some(e=>e.key===c_))===!0?{...e}:Object.fromEntries(Object.entries(e).filter(([e])=>e!==c_))}function u_(e,t){let n={};for(let[r,i]of Object.entries(t))i!==void 0&&(s_(e[r],i)||(n[r]=i));return n}function d_(e,t){let n={...e};for(let[e,r]of Object.entries(t))r!==void 0&&(n[e]=r);return n}function f_(e,t){return e.mintsId===!0?!1:(t?.role??e.role)!==`devices`}function p_(e,t,n){return e===`single`?t:`inst-${n()}`}function m_(){let e=crypto.getRandomValues(new Uint8Array(4));return Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``)}var h_=`+`;function g_(e,t,n){return t===void 0?e:t===null?`${e}:${h_}${n??``}`:`${e}:${t}`}function __(e){let t=e.indexOf(`:`);if(t<0)return{kind:`fixed`,addonId:e};let n=e.slice(0,t),r=e.slice(t+1);if(!r.startsWith(h_))return{kind:`instance`,addonId:n,id:r};let i=r.slice(1);return i===``?{kind:`create`,addonId:n}:{kind:`create`,addonId:n,kindId:i}}var v_=`sendWith`,y_=`smtpInstanceId`;function b_(e,t){return e.filter(e=>e.formValues[v_]===t||e.formValues[y_]===t).map(e=>e.name)}var x_=/^[a-z0-9][a-z0-9-]{0,63}$/;function S_(e,t){return t===``?`empty`:e.pattern.test(t)?`ok`:`invalid`}O();var C_=5e3,w_=`integration-instances`,T_=`provider-instances-holder`;function E_(e){let t=V(),n=_a({capName:e},{refetchInterval:C_}),r=_a({capName:w_},{refetchInterval:C_}),i=la(void 0,{refetchInterval:C_}),a=m(()=>(n.data??[]).map(e=>({addonId:e.addonId,isActive:e.isActive})),[n.data]),o=k({queries:m(()=>{let e=new Set((r.data??[]).map(e=>e.addonId));return a.map(e=>e.addonId).filter(t=>e.has(t))},[a,r.data]).map(e=>({queryKey:[T_,e],refetchInterval:C_,queryFn:async()=>{let n=t.trpcClient.integrationInstances,[r,i]=await Promise.all([n.describe.query({addonId:e}),n.listInstances.query({addonId:e})]);return{addonId:e,description:r,instances:i}}}))}),s=o_([n,r,...o]),c=m(()=>o.flatMap(t=>{let n=t.data===void 0?null:Jg(t.data,e);return n===null?[]:[n]}),[o,e]),l=m(()=>Wg(i.data??[]),[i.data]),u=m(()=>Gg(i.data??[]),[i.data]),d=m(()=>Ug(i.data??[]),[i.data]),f=m(()=>zg({functionProviders:a,holders:c,displayNames:l,descriptions:u,notRunning:d}),[a,c,l,u,d]),p=n.error??r.error??o.find(e=>e.error)?.error??null,h=b(()=>{n.refetch(),r.refetch();for(let e of o)e.refetch()},[n,r,o]);return{state:s,error:p===null?null:p.message,functionProviders:a,rows:f,holders:c,displayNames:l,descriptions:u,refetch:h}}O();var D_=`name`,O_=`kind`,k_=`restore`,A_=`restoreId`,j_=`typedId`,M_={};function N_(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function P_(e,t){let n=N_(e)?e:{};return t===null?{...n}:{...n,integrationId:t}}function F_({addonId:e,providerName:t,description:n,instance:r,onClose:i,onSaved:a,lead:o,typedId:c,testLabel:l,testHint:u}){let{t:d}=q(),f=V(),h=N(),g=r?.id??null,_=async(t,n,r)=>{let i=await f.trpcClient.addons.custom.mutate({addonId:e,action:t,input:P_(r,g)});return g!==null&&h.invalidateQueries({queryKey:[T_]}),i},v=n.kinds??[],y=Xg(n,Kg(n,r?.kind??v[0]?.id),t),[C,T]=w({[D_]:r?.name??y,[O_]:r?.kind??v[0]?.id??``,[k_]:!1,[A_]:``,[j_]:``}),D=p(y),O=C[O_];S(()=>{if(r!==null||typeof O!=`string`)return;let e=Xg(n,Kg(n,O),t),i=D.current;D.current=e,T(t=>t[D_]===i?{...t,[D_]:e}:t)},[O,n,r,t]);let k=e=>{let t=C[e];return typeof t==`string`?t.trim():``},A=k(D_),j=k(O_),M=Kg(n,j===``?void 0:j),P=C[k_]===!0,I=k(A_),L=r===null&&n.allowRestoreId===!0&&M?.signIn===void 0,te=L&&P&&I===``,ne=r===null&&M?.signIn===void 0&&!(L&&P)?c?.(j===``?void 0:j):void 0,re=k(j_),ie=ne===void 0?`ok`:S_(ne,re),[ae,oe]=w({...r?.formValues??M_}),[se,R]=w(null),le=m(()=>({sections:[{id:`instance-identity`,title:d(`providerInstances.identity`,`Identity`),columns:1,fields:[...r===null&&Yg(n)?[{type:`select`,key:O_,label:d(`providerInstances.colKind`,`Kind`),options:v.map(e=>({value:e.id,label:e.label}))}]:[],{type:`text`,key:D_,label:d(`providerInstances.colName`,`Name`),required:!0},...ne===void 0?[]:[{type:`text`,key:j_,label:d(`providerInstances.typedId`,`Id`),required:!0,description:ie===`invalid`?d(`providerInstances.typedIdInvalid`,`Lowercase letters, digits and dashes, starting with a letter or digit (up to 64).`):d(`providerInstances.typedIdHint`,`Chosen once; it cannot be changed after the record is created.`)}],...L?[{type:`boolean`,key:k_,label:d(`providerInstances.restore`,`Restore under its old id`),description:d(`providerInstances.restoreHint`,`Re-adding something that was removed under its original id keeps everything that points at it working.`)},{type:`text`,key:A_,label:d(`providerInstances.originalId`,`Original id`),required:!0,showWhen:{field:k_,equals:!0}}]:[]]}]}),[L,n,ne,r,v,d,ie]),[ue,de]=w(null),fe=g===null&&j!==``?j:void 0,z=E({queryKey:[`provider-instance-form`,e,g,fe??null],queryFn:()=>f.trpcClient.integrationInstances.instanceFormSchema.query({addonId:e,id:g,...fe===void 0?{}:{kind:fe}})}),pe=m(()=>r===null?M_:l_(r.formValues,z.data),[r,z.data]),me=m(()=>l_(ae,z.data),[ae,z.data]),B=r===null?Ng(z.data):null,he=B?.key,ge=m(()=>z.data&&he!==void 0?Fg(z.data,he):z.data,[z.data,he]),_e=B===null?[]:Nr(ae[B.key]),ve=_e.length>1,[ye,be]=w(()=>new Map),xe=b(e=>{be(e)},[]),Se=m(()=>ge?kn(ge,{...pe}):null,[ge,pe]),Ce=z.isSuccess&&!z.data,we=(M?.widgets??[]).flatMap(e=>{let t=e.placement===`connection`?Ag(e.id):null;return t===null?[]:[{id:e.id,widget:t}]}),Te=Se===null?[]:we.flatMap(({widget:e})=>e.ownedKeys(Se,ae)),Ee=ee({mutationFn:async()=>{let t=f.trpcClient.integrationInstances,i=u_(pe,me),a=B!==null&&_e.length===1?{...i,[B.key]:_e[0]}:i;if(r===null&&B!==null&&ve){let r=Ig({key:B.key,picked:_e,labels:ye,typedName:A,values:a}),i=``;for(let[a,o]of r.entries())try{let r=await t.createInstance.mutate({addonId:e,name:o.name,...f_(n,M)?{id:p_(n.instanceMode,e,m_)}:{},...j===``?{}:{kind:j}});await t.updateInstance.mutate({addonId:e,id:r.id,values:o.values}),i=r.id}catch(e){throw h.invalidateQueries({queryKey:[T_]}),Error(d(`providerInstances.createManyStopped`,`{{done}} of {{total}} created: {{message}}`,{done:a,total:r.length,message:e instanceof Error?e.message:String(e)}))}return i}if(r===null){let r=L&&P?I:ne===void 0?f_(n,M)?p_(n.instanceMode,e,m_):void 0:re,i=await t.createInstance.mutate({addonId:e,name:A,...r===void 0?{}:{id:r},...j===``?{}:{kind:j}});return Object.keys(a).length>0&&await t.updateInstance.mutate({addonId:e,id:i.id,values:a}),i.id}return await t.updateInstance.mutate({addonId:e,id:r.id,name:A,values:a}),r.id},onSuccess:e=>{h.invalidateQueries({queryKey:[T_]}),pg({title:d(`providerInstances.saved`,`Saved`),message:ve?String(_e.length):A,severity:`info`}),a?.(e),i()},onError:e=>R(e.message)}),De=ee({mutationFn:()=>f.trpcClient.integrationInstances.testInstance.mutate({addonId:e,id:g,values:u_(pe,me),...g===null&&M!==void 0?{kind:M.id}:{}}),onSuccess:e=>de(lg(e)),onError:e=>de({status:`inconclusive`,error:e.message})});return x(ro,{open:!0,onClose:i,title:r===null?d(`providerInstances.createTitle`,`Add {{provider}}`,{provider:Xg(n,M,t)}):d(`providerInstances.editTitle`,`Edit {{name}}`,{name:r.name}),error:se??(z.isError?z.error.message:null),width:`lg`,footer:s(F,{children:[(M?.canTest??n.canTest)&&s(G,{size:`sm`,variant:`outline`,type:`button`,disabled:De.isPending||Se===null&&!Ce,onClick:()=>{de(null),De.mutate()},children:[De.isPending?x(H,{className:`h-3.5 w-3.5 animate-spin`}):null,l??d(`providerInstances.test`,`Test connection`)]}),s(G,{size:`sm`,type:`button`,disabled:Ee.isPending||Se===null&&!Ce||A.length===0&&!ve||!ve&&(te||ie!==`ok`),onClick:()=>{R(null),Ee.mutate()},children:[Ee.isPending?x(H,{className:`h-3.5 w-3.5 animate-spin`}):null,r===null&&ve?d(`providerInstances.createMany`,`Create {{count}}`,{count:_e.length}):r===null?d(`providerInstances.create`,`Create`):d(`providerInstances.saveChanges`,`Save changes`)]})]}),children:s(`div`,{className:`space-y-4`,children:[r===null?null:o,x(cg,{schema:ve?jg(le,[D_,j_,k_,A_]):le,values:C,onChange:T}),B!==null&&ve&&x(Mg,{field:B,values:ae,onLabels:xe}),M?.signIn!==void 0&&x($d,{basePath:M.signIn.basePath,...M.signIn.methods===void 0?{}:{methods:M.signIn.methods},name:A,...r===null?{}:{brokerId:r.id},getSettings:()=>d_(pe,me),disabled:A.length===0,onSignedIn:e=>{h.invalidateQueries({queryKey:[`provider-instances-holder`]}),a?.(e),i()}}),r!==null&&M?.connectPath!==void 0&&s(G,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>wd(xd(M.connectPath??``,r.id),()=>void h.invalidateQueries({queryKey:[`provider-instances-holder`]})),children:[x(ce,{className:`h-3.5 w-3.5`}),d(`providerInstances.connect`,`Connect account`)]}),Se===null?z.isError?null:Ce?x(`p`,{className:`text-xs text-foreground-muted`,children:d(`providerInstances.noForm`,`This record has no configuration form beyond its name.`)}):s(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[x(H,{className:`h-3 w-3 animate-spin`}),d(`providerInstances.loading`,`Loading…`)]}):s(F,{children:[x(ai,{schema:jg(Se,Te),values:ae,onChange:oe,onAction:_}),we.map(({id:e,widget:{Component:t}})=>x(t,{schema:Se,values:ae,onValuesChange:oe},e))]}),u!==void 0&&(M?.canTest??n.canTest)&&x(`p`,{className:`text-xs text-foreground-subtle`,children:u}),ue!==null&&x(dg,{verdict:ue})]})})}O();var I_=`integration-instances`,L_=`instance-kinds-describe`;function R_(e,t){let n=[];for(let r of e)if(!(t.addonId!==void 0&&r.addonId!==t.addonId))for(let e of r.description.kinds??[]){if(!(t.match===`link`?pn(e,t.functionCap):e.functionCap===t.functionCap))continue;let i=e.brokerKind??e.id;t.kind!==void 0&&i!==t.kind&&e.id!==t.kind||n.push({addonId:r.addonId,kind:e.id,brokerKind:i,label:e.label,...e.connectPath===void 0?{}:{connectPath:e.connectPath},...e.disconnectPath===void 0?{}:{disconnectPath:e.disconnectPath},...e.signIn===void 0?{}:{signInBasePath:e.signIn.basePath},...e.iconUrl===void 0?{}:{iconUrl:e.iconUrl},canTest:e.canTest??r.description.canTest===!0})}return n}function z_(e){let t=V(),n=_a({capName:e.functionCap}),r=_a({capName:I_}),i=k({queries:m(()=>{let e=new Set((r.data??[]).map(e=>e.addonId));return(n.data??[]).map(e=>e.addonId).filter(t=>e.has(t))},[n.data,r.data]).map(e=>({queryKey:[L_,e],queryFn:async()=>({addonId:e,description:await t.trpcClient.integrationInstances.describe.query({addonId:e})})}))}),a=m(()=>i.flatMap(e=>e.data===void 0?[]:[e.data]),[i]);return{options:m(()=>R_(a,e),[a,e.functionCap,e.addonId,e.kind,e.match]),holders:a,isLoading:n.isLoading===!0||r.isLoading===!0||i.some(e=>e.isLoading)}}function B_({children:e,onClose:t}){return x(Mi,{open:!0,onOpenChange:e=>!e&&t(),children:s(Ir,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[x(Yr,{children:x(qi,{children:`\xA0`})}),x(zi,{children:e})]})})}function V_({functionCap:e,kind:t,addonId:n,onClose:r,onSaved:i,typedId:a,match:o}){let{t:s}=q(),c=V(),l=N(),u=z_({functionCap:e,...n===void 0?{}:{addonId:n},...t===void 0?{}:{kind:t},...o===void 0?{}:{match:o}}),d=u.options[0],f=n??d?.addonId,p=E({queryKey:[`instance-create-description`,f,e,d?.kind??null],enabled:f!==void 0,queryFn:async()=>qg(await c.trpcClient.integrationInstances.describe.query({addonId:f??``}),e,d?.kind)});return f===void 0||p.data===null?x(B_,{onClose:r,children:f===void 0&&u.isLoading?x(H,{className:`h-4 w-4 animate-spin`}):x(Or,{message:s(`brokers.editor.noProvider`)})}):p.isError?x(B_,{onClose:r,children:x(Or,{message:p.error.message})}):p.data===void 0?x(B_,{onClose:r,children:x(H,{className:`h-4 w-4 animate-spin`})}):x(F_,{addonId:f,providerName:d?.label??``,description:p.data,instance:null,onClose:r,...a===void 0?{}:{typedId:a},onSaved:e=>{l.invalidateQueries(),i(e)}})}O();var H_={ok:`success`,off:`default`,unknown:`default`,error:`danger`};function U_({kind:e,value:t,onChange:n,optional:r=!1,noneLabel:i,disabled:a=!1}){let{t:o}=q(),[c,l]=w(!1),u=Ea({kind:e}),d=to(u.data??[],t),f=d[0]?.id??null,p=!u.isLoading&&!u.isError&&u.data!==void 0;return S(()=>{!r&&!a&&p&&t===null&&f!==null&&n(f)},[r,a,p,t,f,n]),s(`div`,{className:`space-y-2`,children:[u.isLoading&&s(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[x(H,{className:`h-3.5 w-3.5 animate-spin`}),` `,o(`brokers.picker.loading`)]}),u.isError&&x(Or,{message:o(`brokers.picker.loadFailed`,{message:u.error?.message??o(`common.unknownError`)})}),!u.isLoading&&!u.isError&&d.length===0&&x(`p`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-xs text-foreground-subtle`,children:o(`brokers.picker.none`)}),r&&x(`button`,{type:`button`,"aria-pressed":t===null,disabled:a,onClick:()=>n(null),className:`flex w-full items-center rounded-lg border bg-surface p-3 text-left text-xs text-foreground-subtle transition-colors ${t===null?`border-primary ring-1 ring-primary`:`border-border hover:border-foreground-subtle/30`}`,children:i??o(`brokers.picker.noneChoice`)}),d.map(e=>s(`button`,{type:`button`,"aria-pressed":t===e.id,disabled:a,onClick:()=>n(e.id),className:`flex w-full items-center justify-between gap-3 rounded-lg border bg-surface p-3 text-left transition-colors ${t===e.id?`border-primary ring-1 ring-primary`:`border-border hover:border-foreground-subtle/30`}`,children:[x(`span`,{className:`text-xs font-semibold text-foreground`,children:e.name}),x(Ma,{variant:H_[e.state],className:`text-[10px]`,children:e.stateLabel??e.state})]},e.id)),s(G,{variant:`outline`,size:`sm`,disabled:a,onClick:()=>l(!0),children:[x(Ye,{className:`h-3.5 w-3.5`}),` `,o(`brokers.picker.createNew`)]}),c&&x(V_,{functionCap:`broker`,kind:e,onClose:()=>l(!1),onSaved:e=>{l(!1),n(e)}})]})}var W_=Yt;function G_(e,t){let n=t[0];if(n===void 0)return null;let r=t.find(t=>t.id===e);return r===void 0?n.id:r.id}function K_(e,t){return Et(e,t)}O();function q_(e=!0){S(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e])}O();function J_(e,t){let[n,r]=w(!1);return S(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}O();function Y_({kind:e,onResolved:t,onBack:n}){let{t:r}=q(),[i,a]=w(null);return s(`div`,{className:`space-y-4`,children:[s(G,{variant:`ghost`,size:`sm`,onClick:n,children:[x(at,{className:`h-3.5 w-3.5`}),` `,r(`common.back`)]}),x(U_,{kind:e,value:i,onChange:a}),x(`div`,{className:`flex justify-end pt-1`,children:x(G,{variant:`primary`,size:`sm`,disabled:i===null,onClick:()=>i!==null&&t(i),children:r(`integrations.brokerStep.useThisBroker`,`Use this broker`)})})]})}O();function X_({providerId:e,onImport:t,onSkip:n}){let{t:r}=q(),[i,a]=w(new Set),o=Di(),c=o.data,l=o.isPending||!o.data&&!o.isError;S(()=>{e&&(o.isPending||o.data||o.mutate({addonId:e}))},[e,o]);function u(e){a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(l)return s(`div`,{className:`flex flex-col items-center py-12`,children:[x(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),x(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:r(`integrations.searchingDevices`)})]});let d=c??[];return s(`div`,{className:`space-y-4`,children:[x(`p`,{className:`text-xs text-foreground-subtle`,children:d.length>0?r(`integrations.foundDevices`,{count:d.length}):r(`integrations.noDevicesFound`)}),d.length>0&&x(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:d.map(e=>{let t=e.stableId,n=e.suggestedName??t,a=i.has(t),o=e.alreadyOnboarded===!0;return s(G,{variant:`unstyled`,onClick:()=>{o||u(t)},disabled:o,title:o?r(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:e.onboardedName??n}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${o?`border-border bg-surface opacity-60 cursor-not-allowed`:a?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[x(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${a&&!o?`border-primary bg-primary`:`border-border`}`,children:a&&!o&&x(mt,{className:`h-3 w-3 text-primary-foreground`})}),x(Ke,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),x(`span`,{className:`text-xs font-medium text-foreground truncate`,children:n}),o&&x(`span`,{className:`ml-auto flex-shrink-0 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:r(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},t)})}),s(`div`,{className:`flex items-center justify-between pt-2`,children:[x(G,{variant:`unstyled`,onClick:n,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:r(`integrations.skip`)}),d.length>0&&s(G,{variant:`unstyled`,onClick:()=>t(Array.from(i)),disabled:i.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[r(`integrations.importSelected`),` (`,i.size,`)`]})]})]})}O();function Z_({addonId:e,configSchema:t,canTest:n=!0,instanceKind:r,initialName:i,initialConfig:a,submitLabel:o,hideName:c=!1,saving:l=!1,onScan:u,onSave:d,onBack:f}){let{t:p}=q(),[m,h]=w(i??``),[g,_]=w(a??{}),[v,y]=w(null),b=Oa({onSuccess:e=>y(lg(e)),onError:e=>y({status:`inconclusive`,error:String(e)})}),S=no(),C=!n||v?.status===`validated`,T=!c&&m.trim().length===0,E=!T&&C;return s(`div`,{className:`space-y-4`,children:[!c&&s(`div`,{children:[x(`label`,{htmlFor:`integration-name`,className:`block text-[11px] font-medium text-foreground mb-1`,children:p(`integrations.integrationName`)}),x(W,{id:`integration-name`,type:`text`,value:m,onChange:e=>h(e.target.value),placeholder:p(`integrations.integrationNamePlaceholder`),"aria-invalid":T,"aria-describedby":T?`integration-name-error`:void 0,className:`w-full rounded-lg border bg-surface px-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none ${T?`border-danger focus:border-danger`:`border-border focus:border-primary/50`}`}),T&&x(`p`,{id:`integration-name-error`,"data-testid":`integration-name-error`,className:`mt-1 text-xs text-danger`,children:p(`integrations.nameRequired`,`Name is required`)})]}),t&&x(cg,{schema:t,values:g,onChange:e=>{_(e),y(null)},onAction:async(i,a,o)=>{let s=await S.mutateAsync({addonId:e,action:i,input:o??{}});if(n&&typeof s==`object`&&s){let n=s;if(!(typeof n.token==`string`||typeof n.sslCertificate==`string`||typeof n.host==`string`))return s;let i={...g};for(let[e,t]of Object.entries(n))typeof t==`string`&&e!==`summary`&&(i[e]=t);let a=Sn(t,i);_(a),y(null),b.mutate({addonId:e,id:null,values:a,...r===void 0?{}:{kind:r}})}return s}}),v&&x(dg,{verdict:v}),s(`div`,{className:`flex items-center justify-between pt-2`,children:[x(G,{variant:`unstyled`,onClick:f,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:p(`integrations.back`)}),s(`div`,{className:`flex items-center gap-2`,children:[u&&s(G,{variant:`outline`,size:`sm`,onClick:u,"data-testid":`integration-scan`,children:[x(ge,{className:`h-3.5 w-3.5`}),p(`integrations.scanFromForm`,`Scan the network`)]}),n&&x(G,{variant:`unstyled`,onClick:()=>b.mutate({addonId:e,id:null,values:Sn(t,g),...r===void 0?{}:{kind:r}}),disabled:b.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 disabled:cursor-not-allowed`,children:b.isPending?p(`integrations.testing`):p(`integrations.testConnection`)}),s(`div`,{className:`flex flex-col items-end gap-1`,children:[T&&x(`p`,{"data-testid":`integration-name-submit-error`,className:`text-xs text-danger`,children:p(`integrations.nameRequiredSubmit`,`Enter a name before continuing.`)}),x(G,{variant:`unstyled`,onClick:()=>{T||d({name:m,config:Sn(t,g)})},disabled:!E||l,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:l?p(`integrations.saving`,{defaultValue:`Saving…`}):o??p(`integrations.forward`)})]})]})]})]})}var Q_=new Set([`@camstack/server`,`@camstack/types`,`@camstack/sdk`,`@camstack/shm-ring`,`@camstack/ui-library`]);function $_(e){return e!==void 0&&Q_.has(e)}var ev=`@camstack/addon-agent-ui`;function tv(e){return $_(e)||e===ev}function nv(e){return e.integrationSection===void 0?$_(e.packageName)?`system`:`providers`:e.integrationSection}function rv(e){let t=new Set;for(let n of e??[])nv(n.manifest)===`system`&&t.add(n.manifest.id);return t}function iv(e,t){return{providers:e.filter(e=>!t.has(e.addonId)),system:e.filter(e=>t.has(e.addonId))}}function av(e,t){return[...e].sort((e,n)=>e.name.localeCompare(n.name,t,{sensitivity:`base`}))}var ov=/\.(svg|png|jpe?g|webp)$/i,sv=`provider-`;function cv(e){return typeof e==`string`&&ov.test(e)&&!e.includes(`..`)}function lv(e){let t=[];for(let n of e??[]){let e=n,r=e?.manifest?.id;if(typeof r!=`string`||r.length===0)continue;let i=e?.declaration?.icon??e?.manifest?.icon;cv(i)&&t.push([r,i])}return new Map(t)}function uv(e,t){if(!t)return null;let n=t.startsWith(sv)?[t]:[t,`${sv}${t}`];for(let t of n){let n=e.get(t);if(n)return B(`/api/addon-assets/${encodeURIComponent(t)}/${n}`)}return null}O();var dv=5*6e4,fv=j(new Map);function pv({children:e}){let{data:t}=la(void 0,{staleTime:dv}),n=m(()=>lv(t),[t]);return x(fv.Provider,{value:n,children:e})}function mv(e){return uv(I(fv),e)}O();var hv={amcrest:{icon:ar,color:`#3b82f6`,label:`Amcrest`},hikvision:{icon:_e,color:`#a855f7`,label:`Hikvision`},reolink:{icon:Oe,color:`#06b6d4`,label:`Reolink`},homeassistant:{icon:Me,color:`#22d3ee`,label:`Home Assistant`},rtsp:{icon:nt,color:`#78716c`,label:`RTSP`},onvif:{icon:nt,color:`#78716c`,label:`ONVIF`}},gv={sm:`h-4 w-4`,md:`h-5 w-5`,lg:`h-6 w-6`,xl:`h-16 w-16`},_v={sm:`h-7 w-7`,md:`h-8 w-8`,lg:`h-10 w-10`,xl:`h-16 w-16`};function vv(e){let t=e.toLowerCase();return t.startsWith(`provider-`)?t.slice(9):t}function yv(e){return hv[vv(e)]??{icon:ar,color:`#78716c`,label:e}}function bv({type:e,size:t=`md`,showLabel:n,iconUrl:r}){let i=yv(e),a=i.icon,[o,c]=w(new Set),l=[r,mv(e)].find(e=>typeof e==`string`&&e!==``&&!o.has(e));return s(`div`,{className:`flex items-center gap-2`,children:[x(`div`,{className:`flex items-center justify-center rounded-lg ${_v[t]}`,style:{backgroundColor:`${i.color}15`},children:l===void 0?x(a,{className:gv[t],style:{color:i.color}}):x(`img`,{src:l,alt:i.label,className:gv[t],onError:()=>c(e=>new Set([...e,l]))})}),n&&x(`span`,{className:`text-xs font-medium text-foreground-subtle`,children:i.label})]})}function xv({children:e}){return x(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2 sm:gap-3 lg:grid-cols-3`,children:e})}function Sv({addonId:e,name:t,openLabel:n,onOpen:r,body:i,footer:a,disabled:o=!1,testId:c,buttonTestId:l,iconUrl:u}){return s(`article`,{"data-testid":c,className:`relative flex min-w-0 items-stretch gap-3 overflow-x-clip rounded-lg border border-border bg-surface p-3`,children:[x(G,{type:`button`,variant:`ghost`,"aria-label":n,disabled:o,"data-testid":l,onClick:r,className:`absolute inset-0 z-0 h-auto w-auto rounded-lg p-0 focus-visible:ring-2 focus-visible:ring-primary`}),x(`div`,{className:`pointer-events-none relative z-10 flex w-20 shrink-0 items-center justify-center`,children:x(bv,{type:e,size:`xl`,...u===void 0?{}:{iconUrl:u}})}),s(`div`,{className:`pointer-events-none relative z-10 grid min-w-0 flex-1 grid-rows-[1fr_auto_1fr] gap-1`,children:[x(`p`,{className:`min-w-0 self-start truncate text-sm font-semibold text-foreground`,children:t}),i,x(`div`,{className:`self-end justify-self-start`,children:a})]})]})}function Cv({kind:e,children:t}){let{t:n}=q(),r=`integrations-section-${e}`;return s(`section`,{"aria-labelledby":r,"data-testid":r,className:`min-w-0 space-y-2`,children:[x(`h2`,{id:r,className:Se,children:e===`providers`?n(`integrations.sections.providers`,`Providers`):n(`integrations.sections.system`,`System`)}),t]})}var wv=`(hover: none) and (pointer: coarse)`;function Tv(){if(typeof window>`u`||typeof window.matchMedia!=`function`)return!0;try{return!window.matchMedia(wv).matches}catch{return!0}}O();function Ev(e,t){return`${e.name} ${e.description} ${e.addonId}`.toLowerCase().includes(t)}function Dv({onSelect:e,onClose:t,pendingAddonId:n=null,source:r}){let{t:i,i18n:a}=q(),o=ll(),[c,l]=w(``),u=p(null),d=ca(void 0,{enabled:r===void 0}),f=r===void 0?d.data:void 0,h=r===void 0&&d.isLoading;S(()=>{h||!Tv()||u.current?.focus()},[h]);let{data:g}=la(void 0),_=n!==null,v=m(()=>r===void 0?(f??[]).map(n=>{let r=n.instanceMode===`unique`&&n.existingInstances.length>0;return{key:n.addonId,addonId:n.addonId,name:n.name,description:n.description??``,open:()=>{let i=n.existingInstances[0];r&&i!==void 0?(t(),o(K_(n.addonId,i.id))):e(n.addonId,n.instanceMode,n.discoveryMode,n.providerLabel??n.name,n.kind,n.brokerKind,n.mode,n.canTest)},footer:r?s(`span`,{className:`flex items-center gap-1 text-xs font-medium text-foreground-subtle`,children:[x(le,{className:`h-3 w-3`}),i(`integrations.manage`)]}):null}}):r.providers.map(e=>({...e,key:e.kind===void 0?e.addonId:`${e.addonId}-${e.kind}`,open:()=>r.onPick(e.addonId,e.kind),footer:null})),[r,f,t,e,o,i]),y=m(()=>{let e=c.trim().toLowerCase();return e.length===0?v:v.filter(t=>Ev(t,e))},[v,c]),b=m(()=>{let e=iv(y,rv(g));return{providers:av(e.providers,a.language),system:av(e.system,a.language)}},[y,g,a.language]);if(h)return x(`div`,{className:`grid grid-cols-1 gap-2 p-2 sm:grid-cols-2 lg:grid-cols-3`,children:[1,2,3,4].map(e=>x(`div`,{className:`h-24 rounded-lg bg-surface animate-pulse`},e))});let C=e=>x(xv,{children:e.map(e=>x(Sv,{testId:`provider-card-${e.key}`,buttonTestId:`provider-pick-${e.key}`,addonId:e.addonId,...e.iconUrl===void 0?{}:{iconUrl:e.iconUrl},name:e.name,openLabel:e.name,disabled:_,onOpen:e.open,body:e.description.length>0?x(`p`,{className:`line-clamp-2 text-xs text-foreground-muted`,children:e.description}):x(`span`,{}),footer:n===e.addonId?x(H,{className:`h-4 w-4 animate-spin text-primary`}):e.footer},e.key))});return s(`div`,{className:`space-y-3`,"data-testid":`provider-picker`,children:[s(`div`,{className:`relative`,children:[x(ne,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`,"aria-hidden":!0}),x(W,{ref:u,type:`search`,value:c,onChange:e=>l(e.target.value),placeholder:i(`integrations.searchProviders`,`Search integrations…`),className:`pl-8`,"data-testid":`provider-picker-search`,"data-dialog-autofocus":!0,"aria-label":i(`integrations.searchProviders`,`Search integrations…`)})]}),b.providers.length>0&&x(Cv,{kind:`providers`,children:C(b.providers)}),b.system.length>0&&x(Cv,{kind:`system`,children:C(b.system)}),y.length===0&&x(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:v.length===0?i(`integrations.noProviders`):i(`integrations.noProvidersMatch`,`No integrations match your search.`)})]})}function Ov(e){return e.setupIntegration===!0||e.prefilledConfig.setupIntegration===!0}function kv(e,t,n){let r={};for(let[e,n]of Object.entries(t.prefilledConfig))e!==`setupIntegration`&&(r[e]=typeof n==`string`&&e===`host`?n.trim():n);let i=n?.trim()??``;return{addonId:e,name:i.length>0?Gn(i):t.suggestedName,config:r,...t.stableId===void 0?{}:{originStableId:t.stableId}}}function Av(e,t,n){return Ov(t)?kv(e,t,n):null}function jv(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Mv(e){if(!jv(e)||!jv(e.integrationSeed))return null;let t=e.integrationSeed,n=t.addonId,r=t.name,i=t.config;if(typeof n!=`string`||n.length===0||typeof r!=`string`||!jv(i))return null;let a={};for(let[e,t]of Object.entries(i))a[e]=t;let o=t.originStableId;return{addonId:n,name:r,config:a,...typeof o==`string`&&o.length>0?{originStableId:o}:{}}}function Nv(e){let t=new Map;for(let n of e)t.set(n.stableId,n);let n=e=>{let n=e.parentStableId;if(n===void 0||n===e.stableId)return null;let r=t.get(n);if(r===void 0)return null;let i=new Set([e.stableId]),a=r;for(;a!==void 0;){if(i.has(a.stableId))return null;i.add(a.stableId),a=a.parentStableId===void 0?void 0:t.get(a.parentStableId)}return r},r=new Map,i=[];for(let t of e){let e=n(t);if(e===null){i.push(t);continue}let a=r.get(e.stableId)??[];a.push(t),r.set(e.stableId,a)}let a=e=>({candidate:e,children:(r.get(e.stableId)??[]).map(a)});return i.map(a)}function Pv(e){return e.flatMap(e=>[e.candidate,...Pv(e.children)])}O();var Fv=6e4;function Iv(){let e=fa({},{refetchInterval:Fv}),{refetch:t}=e,n=b(()=>void t(),[t]);return{count:e.data===void 0?null:e.data.proposals.length,refresh:n}}function Lv({count:e}){return e===null||e===0?null:x(Ma,{variant:`info`,style:`fill`,size:`sm`,"data-testid":`discovery-pill`,children:e})}function Rv({onSetupIntegration:e}){let{t}=q(),n=fa({},{refetchInterval:Fv}),r=ji(),i=Li(),[a,o]=w(new Set),{refetch:c}=n,l=b(async(e,t)=>{o(t=>new Set(t).add(e));try{await t(),c()}catch{}finally{o(t=>{let n=new Set(t);return n.delete(e),n})}},[c]),u=b(async t=>{let n=Av(t.addonId,t.candidate);if(n!==null){e(n);return}await l(t.id,()=>r.mutateAsync({addonId:t.addonId,candidate:t.candidate}))},[r,e,l]),d=b(e=>l(e.id,()=>i.mutateAsync({id:e.id})),[i,l]),f=n.data?.proposals??[];return f.length===0?null:s(`section`,{className:`space-y-2`,"data-testid":`discovery-proposals`,children:[s(`h3`,{className:`flex items-center gap-2`,children:[x(`span`,{className:Se,children:t(`integrations.discoveryProposals.title`,`Found in the background`)}),s(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`(`,f.length,`)`]})]}),x(`div`,{className:`space-y-1.5`,children:f.map(e=>s(`div`,{"data-testid":`discovery-proposal`,className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-2`,children:[s(`div`,{className:`min-w-0 flex-1`,children:[x(`p`,{className:`truncate text-sm font-medium text-foreground`,children:e.candidate.suggestedName}),x(`p`,{className:`truncate text-xs text-foreground-muted`,children:e.addonId})]}),a.has(e.id)?x(H,{className:`h-4 w-4 animate-spin text-foreground-muted`,"aria-hidden":!0}):s(F,{children:[x(G,{variant:`secondary`,size:`sm`,onClick:()=>void d(e),children:t(`integrations.discoveryProposals.dismiss`,`Dismiss`)}),s(G,{size:`sm`,onClick:()=>void u(e),children:[x(mt,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),t(`integrations.discoveryProposals.adopt`,`Adopt`)]})]})]},e.id))})]})}var zv=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\/(\d{1,2})$/;function Bv(e){let t=zv.exec(e.trim());if(t===null)return{ok:!1,reason:`format`};let n=[t[1],t[2],t[3],t[4]].map(e=>Number(e));if(n.some(e=>e>255))return{ok:!1,reason:`format`};let r=Number(t[5]);return r>32?{ok:!1,reason:`format`}:r<22?{ok:!1,reason:`prefix`}:{ok:!0,cidr:`${n.join(`.`)}/${r}`}}O();function Vv(){let{t:e}=q(),t=ka(),n=Tr({onSuccess:()=>void t.refetch()}),[r,i]=w(``),[a,o]=w(null),c=t.data?.subnets??[],l=async t=>{try{return await n.mutateAsync({subnets:[...t]}),!0}catch{return o(e(`integrations.scanNetworkModal.subnets.saveFailed`,`The network list could not be saved.`)),!1}},u=async()=>{let t=Bv(r);if(!t.ok){o(t.reason===`prefix`?e(`integrations.scanNetworkModal.subnets.errorPrefix`,`A network larger than a /22 cannot be scanned.`):e(`integrations.scanNetworkModal.subnets.errorFormat`,`Enter a network like 192.0.2.0/24.`));return}if(c.includes(t.cidr)){o(e(`integrations.scanNetworkModal.subnets.errorDuplicate`,`Already in the list.`));return}o(null),await l([...c,t.cidr])&&i(``)};return s(`section`,{className:`space-y-2`,"data-testid":`scan-subnets`,children:[x(`h3`,{className:Se,children:e(`integrations.scanNetworkModal.subnets.title`,`Extra networks to scan`)}),x(`p`,{className:`text-xs text-foreground-muted`,children:c.length===0?e(`integrations.scanNetworkModal.subnets.none`,`Only this hub's own networks are scanned.`):e(`integrations.scanNetworkModal.subnets.hint`,`Every scan covers this hub's own networks and these.`)}),c.length>0&&x(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map(e=>x(Ua,{label:e,testId:`scan-subnet-${e}`,onRemove:()=>void l(c.filter(t=>t!==e))},e))}),s(`div`,{className:`flex items-start gap-2`,children:[s(`div`,{className:`min-w-0 flex-1`,children:[x(W,{value:r,onChange:e=>{i(e.target.value),o(null)},onKeyDown:e=>{e.key===`Enter`&&u()},placeholder:`192.0.2.0/24`,state:a===null?`default`:`error`,"aria-label":e(`integrations.scanNetworkModal.subnets.title`,`Extra networks to scan`),"data-testid":`scan-subnet-input`}),a!==null&&x(`p`,{className:`mt-1 text-xs text-danger`,children:a})]}),s(G,{variant:`outline`,size:`sm`,onClick:()=>void u(),disabled:n.isPending||r.trim().length===0,"data-testid":`scan-subnet-add`,children:[x(Ye,{className:`h-3.5 w-3.5`}),e(`integrations.scanNetworkModal.subnets.add`,`Add network`)]})]})]})}O();function Hv({open:e,onClose:t,scope:n,onSetupIntegration:r,pickMode:i=`adopt`,onAdopted:a}){let{t:o}=q(),c=ji(),[l,u]=w(new Set),[d,f]=w(new Set),[p,h]=w(new Set),{data:g}=Zi({projection:`slim`}),_=m(()=>new Set((g??[]).map(e=>e.stableId)),[g]),v=b(async(e,t)=>{f(e=>new Set(e).add(t.stableId));try{await c.mutateAsync({addonId:e,candidate:t}),a?.(),u(e=>new Set(e).add(t.stableId)),h(e=>{let n=new Set(e);return n.delete(t.stableId),n})}catch{}finally{f(e=>{let n=new Set(e);return n.delete(t.stableId),n})}},[c,a]),y=b(async(e,n)=>{let a=i===`fill`?kv(e,n):Av(e,n);if(a!==null){r?.(a),t();return}await v(e,n)},[v,t,r,i]),S=b(e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),C=b(()=>{u(new Set),h(new Set)},[]),T=m(()=>({existingStableIds:_,adopted:l,adopting:d,selection:{selected:p,toggle:S},pick:y,adoptOne:v,fill:i===`fill`}),[_,l,d,p,S,y,i]),E=n?o(`integrations.scanNetworkModal.titleScoped`,`Scan network — {{label}}`,{label:n.label}):o(`integrations.scanNetworkModal.title`,`Scan network for devices`);return x(Mi,{open:e,onOpenChange:e=>!e&&t(),children:s(Ir,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[x(Yr,{children:x(qi,{children:s(`span`,{className:`flex items-center gap-2`,children:[x(ge,{className:`h-4 w-4 text-primary`}),E]})})}),s(zi,{className:`space-y-4`,children:[x(Vv,{}),!n&&i===`adopt`&&r&&x(Rv,{onSetupIntegration:e=>{t(),r(e)}}),n?x(Yv,{scope:n,row:T,onReset:C}):x(Jv,{row:T,onReset:C})]})]})})}function Uv(e,t){return!t&&e.selectable!==!1&&!Ov(e)}function Wv({addonId:e,nodes:t,row:n,depth:r}){return x(`div`,{className:r===0?`space-y-1.5`:`ml-4 space-y-1.5 border-l border-border pl-3`,"data-testid":r===0?void 0:`scan-children`,children:t.map(t=>s(`div`,{className:`space-y-1.5`,children:[x(Gv,{addonId:e,candidate:t.candidate,row:n}),t.children.length>0&&x(Wv,{addonId:e,nodes:t.children,row:n,depth:r+1})]},t.candidate.stableId))})}function Gv({addonId:e,candidate:t,row:n}){let{t:r}=q(),i=t.prefilledConfig.host,a=typeof i==`string`?i:null,o=n.existingStableIds.has(t.stableId)||t.alreadyOnboarded===!0||t.onboardedDeviceId!==void 0,c=n.adopted.has(t.stableId)||o,l=n.adopting.has(t.stableId),u=n.fill||Ov(t),d=!c&&(u||t.selectable!==!1),f=d&&Uv(t,n.fill);return s(`div`,{className:`flex items-center gap-3 rounded-lg border border-border bg-surface px-3 py-2`,"data-testid":`scan-row-${t.stableId}`,children:[f&&x(L,{checked:n.selection.selected.has(t.stableId),onChange:()=>n.selection.toggle(t.stableId),disabled:l,"aria-label":r(`integrations.scanNetworkModal.select`,`Select {{name}}`,{name:t.suggestedName})}),s(`div`,{className:`min-w-0 flex-1`,children:[x(`p`,{className:`truncate text-xs font-medium text-foreground`,children:t.suggestedName}),a&&x(`p`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,children:a}),o&&t.onboardedName!==void 0&&x(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.onboardedName})]}),c?s(`span`,{className:`flex items-center gap-1 text-[11px] text-foreground-subtle`,children:[x(mt,{className:`h-3.5 w-3.5`}),` `,o?r(`integrations.scanNetworkModal.alreadyAdded`,`Already added`):r(`integrations.scanNetworkModal.added`,`Added`)]}):d?s(G,{size:`sm`,variant:u?`outline`:`primary`,onClick:()=>void n.pick(e,t),disabled:l,children:[l?x(H,{className:`h-3.5 w-3.5 animate-spin`}):u?null:x(yt,{className:`h-3.5 w-3.5`}),u?n.fill?r(`integrations.scanNetworkModal.use`,`Use`):r(`integrations.scanNetworkModal.setUp`,`Set up`):r(`common.add`,`Add`)]}):null]})}function Kv({addonId:e,label:t,candidates:n,row:r}){let i=m(()=>Nv(n),[n]);return s(`section`,{className:`space-y-2`,"data-testid":`scan-group-${e}`,children:[s(`h3`,{className:`flex items-center gap-2`,children:[x(bv,{type:e,size:`sm`}),x(`span`,{className:Se,children:t}),s(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`(`,n.length,`)`]})]}),x(Wv,{addonId:e,nodes:i,row:r,depth:0})]})}function qv(e,t){return e.flatMap(e=>Pv(Nv(e.candidates)).filter(e=>Uv(e,t)).map(t=>({addonId:e.addonId,candidate:t})))}function Jv({row:e,onReset:t}){let{t:n}=q(),r=ni(),i=b(()=>{t(),r.mutate({})},[r,t]);S(()=>{!r.isPending&&!r.data&&i()},[]);let a=m(()=>(r.data?.groups??[]).filter(e=>e.candidates.length>0),[r.data]),o=m(()=>a.reduce((e,t)=>e+t.candidates.length,0),[a]),c=m(()=>qv(a,e.fill),[a,e.fill]);return s(`div`,{className:`space-y-4`,children:[s(`div`,{className:`flex items-center justify-between gap-2`,children:[x(`p`,{className:`text-xs text-foreground-subtle`,children:!r.isPending&&a.length>0?n(`integrations.scanNetworkModal.found`,{count:o}):null}),s(`div`,{className:`flex items-center gap-2`,children:[x(Xv,{entries:c,row:e}),s(G,{variant:`outline`,size:`sm`,onClick:i,disabled:r.isPending,children:[x(Ae,{className:`h-3.5 w-3.5 ${r.isPending?`animate-spin`:``}`}),n(`integrations.scanNetworkModal.reScan`,`Re-scan`)]})]})]}),r.isPending&&x(Qv,{label:n(`integrations.scanNetworkModal.scanningTheLocalNetwork`,`Scanning the local network…`)}),!r.isPending&&r.isError&&x($v,{}),!r.isPending&&r.data&&a.length===0&&x(Zv,{}),!r.isPending&&a.map(t=>x(Kv,{addonId:t.addonId,label:t.label,candidates:t.candidates,row:e},t.addonId))]})}function Yv({scope:e,row:t,onReset:n}){let{t:r}=q(),i=Ra({addonId:e.addonId}).data??null,[a,o]=w({}),c=So(),l=b(()=>{n(),c.mutate({addonId:e.addonId,params:a})},[c,e.addonId,a,n]),u=m(()=>c.data?.candidates??[],[c.data]),d=m(()=>qv([{addonId:e.addonId,candidates:u}],t.fill),[e.addonId,u,t.fill]);return s(`div`,{className:`space-y-4`,children:[i&&x(cg,{schema:i,values:a,onChange:o}),s(G,{onClick:l,disabled:c.isPending,children:[c.isPending?x(H,{className:`h-3.5 w-3.5 animate-spin`}):x(ge,{className:`h-3.5 w-3.5`}),c.isPending?r(`integrations.scanNetworkModal.scanning`,`Scanning…`):r(`integrations.scanNetworkModal.scan`,`Scan`)]}),x(Xv,{entries:d,row:t}),c.isError&&x($v,{}),!c.isPending&&c.data&&u.length===0&&x(Zv,{}),!c.isPending&&u.length>0&&s(`div`,{className:`space-y-2`,children:[x(`p`,{className:`text-xs text-foreground-subtle`,children:r(`integrations.scanNetworkModal.foundShort`,{count:u.length})}),x(Kv,{addonId:e.addonId,label:e.label,candidates:u,row:t})]})]})}function Xv({entries:e,row:t}){let{t:n}=q(),r=e.filter(e=>t.selection.selected.has(e.candidate.stableId));if(r.length===0)return null;let i=async()=>{for(let e of r)await t.adoptOne(e.addonId,e.candidate)};return s(G,{size:`sm`,onClick:()=>void i(),"data-testid":`scan-add-selected`,children:[x(yt,{className:`h-3.5 w-3.5`}),n(`integrations.scanNetworkModal.addSelected`,`Add selected ({{count}})`,{count:r.length})]})}function Zv(){let{t:e}=q();return x(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:e(`integrations.scanNetworkModal.noDevicesRespondedToThe`,`No devices responded to the scan.`)})}function Qv({label:e}){return s(`div`,{className:`flex flex-col items-center py-12`,children:[x(H,{className:`h-6 w-6 animate-spin text-primary`}),x(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:e})]})}function $v(){let{t:e}=q();return s(`div`,{className:`flex items-start gap-3 rounded-lg border border-danger/40 bg-danger/10 px-4 py-3`,children:[x(Ne,{className:`mt-0.5 h-4 w-4 shrink-0 text-danger`}),x(`p`,{className:`text-xs text-danger`,children:e(`integrations.scanNetworkModal.theScanFailedTryAgain`,`The scan failed. Try again.`)})]})}O();function ey(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var ty=2e4;function ny({open:e,onClose:t,seed:n=null,pickFrom:r}){let{t:i}=q(),a=ll(),o=N(),[c,l]=w(`picker`),[u,d]=w(null),[f,p]=w(null),[h,g]=w(`manual`),[_,v]=w(null),[y,b]=w(``),[C,T]=w(null),[E,D]=w(null),[O,k]=w(!1),[A,j]=w({}),[M,ee]=w(``),[P,I]=w(!1),[L,te]=w(0),[ne,re]=w(``),ie=Er({},{enabled:e&&c===`config`}),ae=(pa({addonId:u??``},{enabled:e&&c===`config`&&u!==null}).data?.kinds??[]).filter(e=>e.canTest!==!1),oe=ae.length===1?ae[0]?.id:void 0,se=u!==null&&(ie.data?.providers??[]).some(e=>e.addonId===u),R=n?.config.host,ce=n===null?``:`${n.addonId}\0${n.name}\0${typeof R==`string`?R:``}`;e&&n!==null&&M!==ce&&(ee(ce),d(n.addonId),b(n.name),j({...n.config}),l(`config`));let le=ca(void 0,{enabled:e&&n!==null}),ue=le.data?.find(e=>e.addonId===u)?.mode??`account`,{data:de}=Ga({addonId:u??``,id:null,mode:ue,...n?.originStableId===void 0?{}:{candidateStableId:n.originStableId}},{enabled:u!=null}),fe=m(()=>de?ey(de):null,[de]),z=Si({onSuccess:()=>{o.invalidateQueries({queryKey:[[`integrations`]]}),o.invalidateQueries({queryKey:[[`integrationInstances`]]})}}),pe=Di(),me=pe.data;S(()=>{if(!e||n===null)return;let t=le.data?.find(e=>e.addonId===n.addonId);if(!t)return;k(t.canTest),g(t.discoveryMode);let r=t.providerLabel??t.name;typeof r==`string`&&r.length>0&&b(vn({providerLabel:r,mode:t.mode,brokerKind:t.brokerKind}))},[e,n,le.data]),S(()=>{c!==`discovery`||!f||!u||pe.isPending||pe.data||pe.mutate({addonId:u})},[c,f,u,pe]);let B=ji({onSuccess:()=>o.invalidateQueries({queryKey:[[`deviceManager`]]})});function he(e,t,n,r,i,a,o,s){if(z.isPending)return;let c=vn({providerLabel:r,mode:o,brokerKind:a});if(d(e),k(s),g(n),b(c),D(null),z.reset(),o===`broker`){if(!a){D(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}v(a),l(`broker`);return}if(o===`account`){l(`config`);return}ge(e,c)}async function ge(e,n){try{let r=await z.mutateAsync({addonId:e,name:n,values:{}});t(),xe(),a(`${K_(e,r.id)}&add=1`)}catch{}}async function _e(e){if(u)try{let t=await z.mutateAsync({addonId:u,name:e.name,values:e.config,...oe===void 0?{}:{kind:oe},...n!==null&&n.addonId===u&&n.originStableId!==void 0?{originStableId:n.originStableId}:{}});p(t.id),T(t.id),h===`auto`||h===`both`?l(`discovery`):be(t.id,{openAdd:!0})}catch{}}async function ve(e){if(u)try{let t=await z.mutateAsync({addonId:u,name:y,values:{brokerId:e}});T(t.id),p(t.id),be(t.id)}catch{}}async function ye(e){if(u){for(let t of e){let e=me?.find(e=>e.stableId===t);e&&await B.mutateAsync({addonId:u,candidate:e,...C===null?{}:{integrationId:C}})}be()}}function be(e,n){let r=e??f??u;if(t(),xe(),r&&u){let e=K_(u,r);a(n?.openAdd===!0?`${e}&add=1`:e)}}function xe(){l(`picker`),d(null),p(null),g(`manual`),v(null),b(``),T(null),D(null),z.reset(),k(!1),j({}),ee(``)}function Se(){t(),xe()}q_(e);let Ce=z.isPending,we=J_(Ce,ty);if(!e)return null;let Te={picker:r?.title??i(`integrations.newIntegration`),config:i(`integrations.configureIntegration`),discovery:i(`integrations.importDevices`),broker:i(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Ee=Ce?u:null,De=z.error,Oe=Ce&&!we;return s(F,{children:[x(Mi,{open:!0,onOpenChange:e=>{!e&&!Oe&&Se()},children:s(Ir,{width:c===`picker`?`xl`:`lg`,scroll:`body`,onCancel:e=>{Oe&&e.preventDefault()},children:[x(Yr,{children:x(qi,{children:Te[c]})}),s(zi,{children:[De&&!Ce&&x(`div`,{className:`mb-3 rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:De instanceof Error?De.message:String(De)}),c===`picker`&&s(F,{children:[E&&x(`div`,{className:`mb-3 rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:E}),x(Dv,{onSelect:he,onClose:Se,pendingAddonId:Ee,...r===void 0?{}:{source:r}})]}),c===`config`&&u&&x(Z_,{addonId:u,configSchema:fe??null,canTest:O,...oe===void 0?{}:{instanceKind:oe},initialName:y.length>0?y:void 0,initialConfig:{...A},onScan:se?()=>{re(y.length>0?y:u),I(!0)}:void 0,onSave:_e,onBack:()=>{j({}),l(`picker`)}},`${ce.length>0?ce:u}:${y}:${L}`),c===`broker`&&_&&x(Y_,{kind:_,onResolved:e=>{ve(e)},onBack:()=>l(`picker`)}),c===`discovery`&&f&&x(X_,{providerId:f,onImport:ye,onSkip:be})]}),Ce&&s(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-lg bg-background/85 backdrop-blur-sm px-6 text-center`,children:[x(H,{className:`h-6 w-6 animate-spin text-primary`}),x(`p`,{className:`text-xs font-medium text-foreground`,children:i(`integrations.creating`,{defaultValue:`Creating integration…`})}),!we&&x(`p`,{className:`text-[10px] text-foreground-subtle`,children:i(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),we&&s(F,{children:[x(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:i(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),x(G,{variant:`unstyled`,onClick:Se,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:i(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})}),P&&u!==null&&x(Hv,{open:P,scope:{addonId:u,label:ne},pickMode:`fill`,onClose:()=>I(!1),onSetupIntegration:e=>{b(e.name),j({...e.config}),te(e=>e+1)}})]})}O();function ry({functionCap:e,disabled:t,onCreated:n}){let{t:r}=q(),{options:i}=z_({functionCap:e,match:`link`}),[a,o]=w({at:`closed`});if(i.length===0)return null;let c=()=>o({at:`closed`});return s(F,{children:[s(G,{variant:`outline`,size:`sm`,disabled:t,onClick:()=>{let e=i.length===1?i[0]:void 0;o(e===void 0?{at:`choose`}:{at:`edit`,option:e})},children:[x(Ye,{className:`h-3.5 w-3.5`}),` `,r(`brokers.picker.createNew`)]}),a.at===`choose`&&x(ny,{open:!0,onClose:c,pickFrom:{title:r(`brokers.picker.createNew`),providers:i.map(e=>({addonId:e.addonId,kind:e.kind,name:e.label,description:``,...e.iconUrl===void 0?{}:{iconUrl:e.iconUrl}})),onPick:(e,t)=>{let n=i.find(n=>n.addonId===e&&n.kind===t);o(n===void 0?{at:`closed`}:{at:`edit`,option:n})}}}),a.at===`edit`&&x(V_,{functionCap:e,addonId:a.option.addonId,kind:a.option.kind,match:`link`,onClose:c,onSaved:e=>{c(),n(e)}})]})}var iy=`broker`;function ay({functionCap:e,kind:t,noneLabel:n,required:r,disabled:i,value:a,onChange:o}){return e===iy&&t!==void 0?x(U_,{kind:t,value:a,onChange:o,optional:r===!1,disabled:i===!0,...n===void 0?{}:{noneLabel:n}}):s(`div`,{className:`space-y-2`,children:[x(Ei,{functionCap:e,...t===void 0?{}:{kind:t},...n===void 0?{}:{noneLabel:n},value:a??``,disabled:i===!0,onChange:e=>o(e===``?null:e),controlId:`instance-picker-${e}-${t??`any`}`}),t===void 0&&x(`div`,{children:x(ry,{functionCap:e,disabled:i===!0,onCreated:o})})]})}function oy({deviceId:e}){let{t}=q(),n=ma(V().trpcClient,e);return n===null?null:x(Kr,{headingId:`device-web-interface-${String(e)}`,title:t(`device.webInterface.title`,`Web interface`),icon:gr,testId:`device-web-interface-card`,children:s(`div`,{className:`flex flex-wrap items-center justify-between gap-2 px-3 py-2 sm:px-4`,children:[s(`div`,{className:`min-w-0 text-xs`,children:[x(`div`,{className:`font-medium text-foreground`,children:n.label}),x(`div`,{className:`break-all text-foreground-muted`,children:n.host})]}),s(G,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>window.open(n.url,`_blank`,`noopener,noreferrer`),children:[x(wt,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),t(`device.webInterface.open`,`Open`)]})]})})}var sy={streaming:{icon:ve,labelKey:`capabilityBadges.streaming`},detection:{icon:Fe,labelKey:`capabilityBadges.detection`},recording:{icon:ke,labelKey:`capabilityBadges.recording`},audio:{icon:ae,labelKey:`capabilityBadges.audio`},snapshot:{icon:Ke,labelKey:`capabilityBadges.snapshot`},motion:{icon:bt,labelKey:`capabilityBadges.motion`},ptz:{icon:le,labelKey:`capabilityBadges.ptz`},webrtc:{icon:Oe,labelKey:`capabilityBadges.webrtc`},onvif:{icon:Qe,labelKey:`capabilityBadges.onvif`},analytics:{icon:Ze,labelKey:`capabilityBadges.analytics`},"battery-operated":{icon:z,labelKey:`capabilityBadges.battery`},"native-snapshot":{icon:Ke,labelKey:`capabilityBadges.nativeSnapshot`},"pan-tilt-zoom":{icon:le,labelKey:`capabilityBadges.ptz`},"two-way-audio":{icon:ae,labelKey:`capabilityBadges.twoWayAudio`},"doorbell-button":{icon:se,labelKey:`capabilityBadges.doorbell`},rebootable:{icon:Ae,labelKey:`capabilityBadges.rebootable`},"vacuum-has-ai":{icon:Tt,labelKey:`capabilityBadges.aiObstacle`},"mower-has-targeted-mowing":{icon:ot,labelKey:`capabilityBadges.targetedMowing`}},cy=ze;function ly({capabilities:e,showLabels:t=!1}){let{t:n}=q();return x(`div`,{className:`flex items-center gap-1 flex-wrap`,children:e.map(e=>{let r=sy[e],i=r?.icon??cy,a=r?n(r.labelKey):e;return s(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-surface-hover px-1.5 py-0.5 text-[10px] text-foreground-subtle`,title:a,children:[x(i,{className:`h-3 w-3`}),t&&x(`span`,{children:a})]},e)})})}var uy=`customize`,dy=`/build/compositions/new`,fy=`/build/compositions/:blockId`,py=`/build?tab=custom-device`;function my(e){return`/devices/${e}`}function hy(e){return`/devices/${e}?tab=${uy}`}function gy(e){return`/build/compositions/${encodeURIComponent(e)}`}var _y=`template`,vy=`terminalId`;function yy(e){return`/build?${new URLSearchParams({tab:`custom-device`,new:`helper`,[_y]:`terminal`,[vy]:e}).toString()}`}function by({label:e,value:t,layout:n=`inline`}){return n===`stacked`?s(`div`,{className:`min-w-0 flex flex-col gap-0.5 px-0.5`,children:[x(`span`,{className:`text-[11px] text-foreground-subtle`,children:e}),x(`div`,{className:`min-w-0 text-[11px] text-foreground`,children:t})]}):s(`div`,{className:`${be} flex items-start gap-2 sm:gap-3`,children:[x(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),x(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}O();function xy(e,t){return e.kind===`same-device`?`same-device`:e.a.deviceId===t?`powers`:`powered-by`}function Sy(e){if(!e.ok)throw Error(e.message);return e.link}function Cy(e){return e.filter(e=>e.state!==`dismissed`)}function wy({deviceId:e}){let{t}=q(),n=oo({deviceId:e}),r=x(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-y border-border`,children:t(`overviewAdapters.identityLinks.header`,`Linked devices, matched on the identifiers above.`)});if(n.error)return s(F,{children:[r,x(`p`,{className:`px-3 sm:px-4 py-2 text-xs text-foreground-muted`,children:t(`overviewAdapters.identityLinks.unavailable`,`Linked devices could not be read.`)})]});if(n.data===void 0)return s(F,{children:[r,x(`div`,{className:`px-3 sm:px-4 py-2`,"data-testid":`identity-links-pending`,children:x(yr,{className:`h-4 w-1/2`})})]});if(n.data.status===`not-loaded`)return s(F,{children:[r,x(`p`,{className:`px-3 sm:px-4 py-2 text-xs text-foreground-muted`,children:t(`overviewAdapters.identityLinks.notLoaded`,`Linked devices are not read yet.`)})]});let i=Cy(n.data.links);return s(F,{children:[r,i.length===0?x(`p`,{className:`px-3 sm:px-4 py-2 text-xs text-foreground-muted`,children:t(`overviewAdapters.identityLinks.none`,`No linked devices.`)}):x(`div`,{className:`divide-y divide-border`,children:i.map(t=>x(Ty,{link:t,deviceId:e},t.id))})]})}function Ty({link:e,deviceId:t}){let{t:n}=q(),r=e.a.deviceId===t?e.b:e.a,{data:i}=$a({deviceId:r.deviceId}),a=N(),o={onSuccess:()=>void a.invalidateQueries({queryKey:[[`deviceManager`]]})},c=bi(o),l=Br(o),u=Na(o),d={"same-device":n(`overviewAdapters.identityLinks.sameDevice`,`Same device`),"powered-by":n(`overviewAdapters.identityLinks.poweredBy`,`Powered by`),powers:n(`overviewAdapters.identityLinks.powers`,`Powers`)},[f,p]=w(null),m=e=>{p(null),e.then(Sy).catch(e=>{p(e instanceof Error?e.message:String(e))})},h=i?.name??`#${r.deviceId}`,g=e.state===`proposed`;return x(by,{label:d[xy(e,t)],value:s(`div`,{className:`flex flex-wrap items-center gap-2 min-w-0`,children:[x(ku,{to:my(r.deviceId),className:`text-primary hover:underline truncate`,children:h}),g&&x(`span`,{className:`text-[11px] text-warning`,children:n(`overviewAdapters.identityLinks.proposed`,`Suggested`)}),e.evidenceGone===!0&&x(`span`,{className:`text-[11px] text-foreground-subtle`,children:n(`overviewAdapters.identityLinks.evidenceGone`,`No longer matched`)}),x(`span`,{className:`ml-auto flex gap-1.5`,children:g?s(F,{children:[x(G,{size:`sm`,disabled:c.isPending,onClick:()=>m(c.mutateAsync({linkId:e.id})),children:n(`overviewAdapters.identityLinks.confirm`,`Confirm`)}),x(G,{size:`sm`,variant:`outline`,disabled:l.isPending,onClick:()=>m(l.mutateAsync({linkId:e.id})),children:n(`overviewAdapters.identityLinks.dismiss`,`Dismiss`)})]}):x(Ia,{size:`sm`,label:n(`overviewAdapters.identityLinks.unlink`,`Unlink`),title:n(`overviewAdapters.identityLinks.unlinkTitle`,`Unlink these devices?`),description:n(`overviewAdapters.identityLinks.unlinkBody`,`The link is removed and not suggested again. Anything it added in Customize is removed with it.`),action:async()=>Sy(await u.mutateAsync({linkId:e.id}))})}),f!==null&&x(`span`,{className:`basis-full text-[11px] text-danger`,children:f})]})})}O();function Ey(e){return Zi({addonId:e,projection:`slim`})}function Dy(e){return $a({deviceId:e},{enabled:Number.isFinite(e)})}var Oy=3e4,ky=2e3;function Ay(e){let t=p(0);return t.current===0&&(t.current=Date.now()),Lr({parentDeviceId:e},{enabled:Number.isFinite(e),staleTime:0,refetchOnMount:`always`,refetchInterval:e=>{let n=e.state.data;return n&&n.length>0||Date.now()-t.current>=Oy?!1:ky}})}O();function jy({deviceId:e}){let{t}=q(),n=N(),{data:r}=Dy(e),{data:i}=Ay(e),[a,o]=w(null),c=ki({onSuccess:()=>{o(null),n.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{o(`Could not change primary child: ${e.message}`)}});if(r==null)return null;let l=String(r.type??``);if(l!==U.Container)return null;let u=String(r.name??``),d=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:ja(e,u),...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}}));if(d.length<=1)return null;let f=Co(d,typeof r.linkDeviceId==`number`?r.linkDeviceId:null,typeof r.primaryChildEntityId==`string`?r.primaryChildEntityId:null,l,nn(r)),p=f===null?d[0].id:f.id;return s(F,{children:[x(by,{label:t(`shared.primaryChildRow.primaryChild`,`Primary child`),value:x(ri,{childrenList:d,selectedId:p,onSetPrimary:t=>c.mutate({deviceId:e,primaryChildEntityId:t}),disabled:c.isPending})}),a!==null&&x(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:a})]})}O();var My=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`],Ny=[`mac`,`serial`,`vendor-uid`,`machine-uuid`,`hostname`,`ip`];function Py(e){let t=Hn.safeParse(e);if(!t.success)return[];let n=t.data;return Ny.flatMap(e=>{if(e===`mac`)return(n.mac??[]).map(t=>({key:e,value:t.value,derived:t.origin===`derived`}));let t=n[e];return t?[{key:e,value:t.value,derived:t.origin===`derived`}]:[]})}function Fy(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function Iy(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function Ly(){let{t:e}=q(),t=$i(),n=lo(),{data:r}=$a({deviceId:t??0},{enabled:t!==null}),{data:i}=Vi({deviceId:t??0},{enabled:t!==null}),{data:a}=oo({deviceId:t??0},{enabled:t!==null}),o=r??n??null,[c,l]=w(`identity`);if(t===null||!o)return null;let u=String(o.stableId??``),d=String(o.addonId??``),f=typeof o.integrationId==`string`&&o.integrationId.length>0?o.integrationId:null,p=typeof o.parentDeviceId==`number`?o.parentDeviceId:null,m=o.features??[],h=new Set([`device-status`,`feature-probe`,`device-ops`]),g=(i?.entries??[]).filter(e=>e.kind===`native`&&!h.has(e.capName)).map(e=>e.capName),_=m.length>0?m:g,v=o.metadata??null,y=Py(o.identifiers),b=a?.status===`answered`&&Cy(a.links).length>0,S=v!==null&&Object.keys(v).length>0||y.length>0||b;return s(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[s(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[x(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:e(`overviewAdapters.deviceInfoAdapter.deviceInfo`,`Device Info`)}),S&&s(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[x(Ry,{active:c===`identity`,onClick:()=>l(`identity`),label:e(`overviewAdapters.deviceInfoAdapter.identity`,`Identity`)}),x(Ry,{active:c===`hardware`,onClick:()=>l(`hardware`),label:e(`overviewAdapters.deviceInfoAdapter.hardware`,`Hardware`)})]})]}),(!S||c===`identity`)&&s(`div`,{className:`divide-y divide-border`,children:[x(by,{label:`ID`,value:s(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${t}`,s(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,u,`)`]})]})}),x(jy,{deviceId:t}),f!==null&&x(by,{label:e(`overviewAdapters.deviceInfoAdapter.integration`,`Integration`),value:x(`span`,{className:`font-mono text-[11px]`,children:f})}),p!==null&&x(by,{label:e(`overviewAdapters.deviceInfoAdapter.parent`,`Parent`),value:x(`span`,{className:`font-mono text-[11px]`,children:`#${String(p)}`})}),x(by,{label:e(`overviewAdapters.deviceInfoAdapter.provider`,`Provider`),value:x(bv,{type:d,size:`sm`,showLabel:!0})}),x(by,{label:e(`overviewAdapters.deviceInfoAdapter.capabilities`,`Capabilities`),value:_.length>0?x(ly,{capabilities:_,showLabels:!0}):x(`span`,{className:`text-[11px] text-foreground-subtle`,children:e(`overviewAdapters.deviceInfoAdapter.none`,`None`)})})]}),S&&c===`hardware`&&x(zy,{deviceId:t,metadata:v??{},identifiers:y})]})}function Ry({active:e,onClick:t,label:n}){return x(G,{variant:`unstyled`,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 zy({deviceId:e,metadata:t,identifiers:n}){let{t:r}=q(),i={mac:r(`overviewAdapters.deviceInfoAdapter.identifierMac`,`MAC address`),serial:r(`overviewAdapters.deviceInfoAdapter.identifierSerial`,`Serial number`),"vendor-uid":r(`overviewAdapters.deviceInfoAdapter.identifierVendorUid`,`Vendor ID`),"machine-uuid":r(`overviewAdapters.deviceInfoAdapter.identifierMachineUuid`,`Machine UUID`),hostname:r(`overviewAdapters.deviceInfoAdapter.identifierHostname`,`Hostname`),ip:r(`overviewAdapters.deviceInfoAdapter.identifierIp`,`IP address`)},a=My.filter(e=>e in t),o=Object.keys(t).filter(e=>!My.includes(e)).toSorted(),c=[...a,...o];return s(`div`,{children:[x(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-b border-border`,children:r(`overviewAdapters.deviceInfoAdapter.autoPopulatedByTheDriver`,`Auto-populated by the driver on every connect. Read-only.`)}),x(`div`,{className:`divide-y divide-border`,children:c.map(e=>x(by,{label:Fy(e),value:x(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:Iy(t[e])})},e))}),n.length>0&&s(F,{children:[x(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-y border-border`,children:r(`overviewAdapters.deviceInfoAdapter.identifiersDeclared`,`Identifiers declared by the provider. Read-only.`)}),x(`div`,{className:`divide-y divide-border`,children:n.map(e=>x(by,{label:i[e.key],value:s(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:[e.value,e.derived&&x(`span`,{className:`ml-1.5 text-foreground-subtle`,children:r(`overviewAdapters.deviceInfoAdapter.identifierDerived`,`(derived)`)})]})},`${e.key}:${e.value}`))})]}),x(wy,{deviceId:e})]})}function By(e){return e.hubReachable?e.authOk===!1?{kind:`auth-expired`}:{kind:`cluster-degraded`,offlineAgents:e.offlineAgents,offlineAgentIds:e.offlineAgentIds}:{kind:`hub-unreachable`}}function Vy(e){switch(e.kind){case`connected`:return null;case`reconnecting`:return{severity:`warning`,message:K.t(`connection.reconnecting`),i18nKey:`connection.reconnecting`,showSpinner:!0};case`cluster-degraded`:{let t=e.offlineAgentIds??[];return t.length>0?{severity:`warning`,message:K.t(`connection.degradedNodes`,{nodes:t.join(`, `),count:t.length}),i18nKey:`connection.degradedNodes`,i18nParams:{nodes:t.join(`, `),count:t.length},showSpinner:!0}:e.offlineAgents!==null&&e.offlineAgents>0?{severity:`warning`,message:K.t(`connection.degradedCount`,{count:e.offlineAgents}),i18nKey:`connection.degradedCount`,i18nParams:{count:e.offlineAgents},showSpinner:!0}:{severity:`warning`,message:K.t(`connection.degraded`),i18nKey:`connection.degraded`,showSpinner:!0}}case`hub-unreachable`:return{severity:`danger`,message:K.t(`connection.disconnected`),i18nKey:`connection.disconnected`,showSpinner:!0};case`auth-expired`:return{severity:`danger`,message:K.t(`connection.sessionExpired`),i18nKey:`connection.sessionExpired`,showSpinner:!1,action:`sign-in`}}}var Hy=4e3,Uy=5e3;function Wy(e){if(typeof e!=`object`||!e)return{offline:null,offlineIds:null,ok:null};let t={...e},n=typeof t.ok==`boolean`?t.ok:null,r=t.agents;if(typeof r!=`object`||!r)return{offline:null,offlineIds:null,ok:n};let i={...r},a=i.offline,o=typeof a==`number`?a:null,s=i.offlineIds;return{offline:o,offlineIds:Array.isArray(s)?s.filter(e=>typeof e==`string`):null,ok:n}}async function Gy(e,t,n,r){let i=new AbortController,a=setTimeout(()=>i.abort(),n);try{return await e(t,{method:`GET`,signal:i.signal,credentials:`omit`,...r===void 0?{}:{headers:r}})}finally{clearTimeout(a)}}async function Ky(e){let t=e.fetchFn??fetch,n=e.timeoutMs??Hy,r=e.origin.replace(/\/+$/,``),i;try{i=await Gy(t,`${r}/health`,n)}catch{return{hubReachable:!1,authOk:`unknown`,offlineAgents:null,offlineAgentIds:null}}if(!i.ok)return{hubReachable:!1,authOk:`unknown`,offlineAgents:null,offlineAgentIds:null};let a=null,o=e.getToken();if(o!==null&&o!==``)try{let e=await Gy(t,`${r}/health/details`,n,{Authorization:`Bearer ${o}`});e.ok&&(a=await e.json())}catch{}let s;try{s=Wy(a??await i.json())}catch{s={offline:null,offlineIds:null,ok:null}}if(s.ok===!1)return{hubReachable:!1,authOk:`unknown`,offlineAgents:null,offlineAgentIds:null};let c=e.getToken(),l=`unknown`;if(c!==null&&c!==``)try{let e=await Gy(t,`${r}/trpc/auth.me`,n,{Authorization:`Bearer ${c}`});e.status===401||e.status===403?l=!1:e.ok&&(l=!0)}catch{l=`unknown`}return{hubReachable:!0,authOk:l,offlineAgents:s.offline,offlineAgentIds:s.offlineIds}}var qy={kind:`connected`},Jy={kind:`reconnecting`};function Yy(e){let t=e.probeIntervalMs??Uy,n=new Set,r=qy,i=0,a=!1,o=null;function s(e){if(r!==e){r=e;for(let e of n)e()}}function c(){a=!1,o!==null&&(clearTimeout(o),o=null)}function l(){let n=i;e.probe().then(e=>{n!==i||!a||(s(By(e)),o=setTimeout(l,t))},()=>{n!==i||!a||(s({kind:`hub-unreachable`}),o=setTimeout(l,t))})}function u(e){if(i+=1,e===`connected`){c(),s(qy);return}if(e===`connecting`){c(),s(Jy);return}(r.kind===`connected`||r.kind===`reconnecting`)&&s(Jy),o!==null&&(clearTimeout(o),o=null),a=!0,l()}return{getSnapshot:()=>r,subscribe:e=>(n.add(e),()=>{n.delete(e)}),onSdkConnectionState:u,dispose:()=>{i+=1,c(),n.clear()}}}var Xy=null;function Zy(){return Xy===null&&(Xy=Yy({probe:()=>Ky({origin:je(),getToken:()=>localStorage.getItem(`camstack_admin_token`)})})),Xy}function Qy(e){Zy().onSdkConnectionState(e)}function $y(e){return e===`connected`}function eb(e){M.setOnline($y(e))}var tb=null,nb=0;function rb(){if(!tb){let e=nb;tb=yo({serverUrl:je(),token:localStorage.getItem(`camstack_admin_token`)??void 0,getLanguage:()=>K.language,refreshCredential:async e=>{e===`rejected`?await xb().refreshNow():await xb().ensureFresh()},onConnectionChange:t=>{e===nb&&(Qy(t),eb(t))}})}return tb}function ib(){let e=tb;tb=null,nb+=1,e?.close()}var ab=`camstack_admin_token`,ob=`camstack_admin_refresh`,sb=`camstack_admin_token_expires`;function cb(e){try{let t=localStorage.getItem(e);return t!==null&&t.length>0?t:null}catch{return null}}function lb(e,t){try{t===null?localStorage.removeItem(e):localStorage.setItem(e,t)}catch{}}function ub(){let e=cb(ab);if(e===null)return null;let t=cb(ob),n=Number(cb(sb));return{token:e,...t===null?{}:{refreshToken:t},...Number.isFinite(n)&&n>0?{expiresAt:n}:{}}}function db(e){lb(ab,e.token),lb(ob,e.refreshToken??null),lb(sb,e.expiresAt===void 0?null:String(e.expiresAt))}function fb(e){lb(ab,e),lb(ob,null),lb(sb,null)}function pb(){lb(ab,null),lb(ob,null),lb(sb,null)}function mb(e){let t=e.get(`token`);if(t===null||t.length===0)return null;let n=e.get(`refreshToken`),r=Number(e.get(`expiresAt`));return{token:t,...n!==null&&n.length>0?{refreshToken:n}:{},...Number.isFinite(r)&&r>0?{expiresAt:r}:{}}}async function hb(e){await fetch(B(`/api/auth/session`),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({token:e})}).catch(()=>{})}var gb=new Set;function _b(e){return gb.add(e),()=>gb.delete(e)}var vb=new Set;function yb(e){return vb.add(e),()=>vb.delete(e)}var bb=null;function xb(){return bb===null&&(bb=new oa({refresh:async e=>{let t=ub();if(t?.refreshToken!==void 0&&t.refreshToken!==e&&(t.expiresAt??0)>Date.now()+6e4)return t;let n=await rb().refreshSession(e);return{token:n.token,refreshToken:n.refreshToken,expiresAt:n.expiresAt}},onTokens:e=>{db(e),rb().setToken(e.token),hb(e.token);for(let e of vb)e()},onExpired:()=>{pb();for(let e of gb)e()}})),bb}function Sb(e){db(e),xb().adopt(e)}async function Cb(e){try{await xb().ensureFresh()}catch(e){console.warn(`[admin-session] pre-reconnect refresh failed; reconnecting anyway`,e)}e()}async function wb(){return await xb().refreshNow()!==null}var Tb=512;function Eb(e){if(!e||e.length>Tb)return null;let t=Vt(e);return t===null?!e.startsWith(`/`)||e.startsWith(`//`)||e.includes(`\\`)||e.includes(`://`)||e.includes(`..`)||e===`/login`||e.startsWith(`/login?`)||e.startsWith(`/login/`)?null:{kind:`path`,path:e}:{kind:`app-callback`,url:t}}var Db=/^[A-Za-z0-9_-]{43,128}$/,Ob=/^[A-Za-z0-9._~-]{1,256}$/;function kb(e){let{codeChallenge:t,state:n}=e;return!t||!Db.test(t)||(e.codeChallengeMethod??`S256`)!==`S256`||!n||!Ob.test(n)?null:{codeChallenge:t,state:n,purpose:e.purpose===`step-up`?`step-up`:`new-session`}}var Ab=`camstack:login-app-handoff`;function jb(e){if(!e)return null;try{let t=JSON.parse(e);if(typeof t!=`object`||!t)return null;let n=e=>{let n=Reflect.get(t,e);return typeof n==`string`?n:null};return kb({codeChallenge:n(`codeChallenge`),state:n(`state`),purpose:n(`purpose`)})}catch{return null}}function Mb(e,t=Date.now()){e!==null&&Wb(Ab,JSON.stringify(e),jb,t)}function Nb(e=Date.now()){return Gb(Ab,jb,e)}function Pb(e,t,n){return`${e}?${`code=${encodeURIComponent(t)}`}${n===void 0?``:`&state=${encodeURIComponent(n)}`}`}function Fb(e,t=Date.now()){return Jb(t)??Eb(e)}var Ib=2048;function Lb(e){return!e||e.length>Ib||!e.startsWith(`/`)||e.startsWith(`//`)||e.includes(`\\`)||e.includes(`://`)||e.includes(`..`)||e===`/login`||e.startsWith(`/login?`)||e.startsWith(`/login/`)?null:e}function Rb(e,t=Date.now()){Wb(Hb,e,Lb,t)}function zb(e=Date.now()){return Gb(Hb,Lb,e)}function Bb(e,t=Date.now()){return zb(t)??Lb(e)}var Vb=`camstack:login-redirect`,Hb=`camstack:login-next`,Ub=10*6e4;function Wb(e,t,n,r){let i=Kb();if(!i||!n(t))return;let a={raw:t??``,at:r};try{i.setItem(e,JSON.stringify(a))}catch{}}function Gb(e,t,n){let r=Kb();if(!r)return null;let i=null;try{i=r.getItem(e),r.removeItem(e)}catch{return null}if(!i)return null;try{let e=JSON.parse(i);if(typeof e!=`object`||!e)return null;let r=Reflect.get(e,`at`),a=Reflect.get(e,`raw`);return typeof r!=`number`||typeof a!=`string`||n-r>Ub?null:t(a)}catch{return null}}function Kb(){if(typeof window>`u`)return null;try{return window.sessionStorage}catch{return null}}function qb(e,t=Date.now()){Wb(Vb,e,Eb,t)}function Jb(e=Date.now()){return Gb(Vb,Eb,e)}var Yb=`changeme`;function Xb(e){try{let t=e.split(`.`);if(t.length<2||!t[1])return null;let n=JSON.parse(atob(t[1]));return{id:String(n.userId??``),username:String(n.username??`unknown`),isAdmin:!!n.isAdmin,exp:Number(n.exp??0),scopes:Zb(n.scopes)}}catch{return null}}function Zb(e){return xn(En(e))}function Qb(e){let t=Xb(e);return t?t.exp*1e3<Date.now():!0}O();var $b=Yb;function ex(e){return{token:e.token,...e.refreshToken===void 0?{}:{refreshToken:e.refreshToken},...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}}async function tx(e,t){if(await hb(e),t.kind===`path`){window.location.replace(B(t.path));return}try{ib();let e=Nb();if(e===null)throw Error(`The app sent no PKCE challenge and state`);let{code:n}=await rb().trpcClient.auth.createHandoffCode.mutate({purpose:e.purpose,codeChallenge:e.codeChallenge,state:e.state});window.location.replace(Pb(t.url,n,e.state))}catch{window.location.replace(B(`/`))}}async function nx(e,t){await hb(e),window.location.replace(B(t))}var rx=j(null);function ix({children:e}){let[t,n]=w(null),[r,i]=w(!0),[a,o]=w(!1);S(()=>{if(typeof window<`u`&&window.location.hash.startsWith(`#token=`)){let e=new URLSearchParams(window.location.hash.slice(1)),t=mb(e),n=t?.token??null;if(t!==null&&n!==null){Sb(t);let r=Jb();if(r){tx(n,r);return}let i=zb()??Lb(e.get(`next`));if(i){nx(n,i);return}window.history.replaceState({},``,B(`/`))}}s()},[]);let s=async()=>{let e=ub();if(e===null){i(!1);return}let t=e.token;if(e.refreshToken!==void 0){let n=xb();n.adopt(e),await n.ensureFresh();let r=ub();if(r===null){console.warn(`[auth] session restore: signed out — the hub refused the refresh token`),ib(),i(!1);return}t=r.token}if(Qb(t)){console.warn(`[auth] session restore: signed out — access token expired and no refresh recovered it`),pb(),ib(),i(!1);return}let r=Xb(t);if(!r){console.warn(`[auth] session restore: signed out — the stored access token is unreadable`),pb(),ib(),i(!1);return}hb(t);let a=rb();a.trpcClient.system.info.query().then(()=>n(r)).catch(async e=>{let t=e?.data?.code;if(t===`UNAUTHORIZED`||t===`FORBIDDEN`){if(await wb()){a.reconnect();try{await rb().trpcClient.system.info.query();let e=ub();n(e&&Xb(e.token)||r);return}catch{}}console.warn(`[auth] session restore: logout, probe UNAUTHORIZED and refresh did not recover it`),xb().stop(),pb(),ib()}else n(r)}).finally(()=>i(!1))};S(()=>_b(()=>{ib(),n(null),o(!1)}),[]);let c=b(async(e,t)=>{let r=await rb().login(e,t,{refreshable:!0}),i=r.secondFactors??(r.requiresTotp===!0?[`totp`]:[]);if(i.length>0)return{kind:`second-factor`,challengeToken:r.token,factors:i};let a=r.token;return Sb(ex(r)),await hb(a),ib(),n(Xb(a)),o(t===$b),{kind:`ok`}},[]),l=b(async(e,t)=>{let r=await rb().loginVerifyTotp(e,t,{refreshable:!0}),i=r.token;Sb(ex(r)),await hb(i),ib(),n(Xb(i)),o(!1)},[]),u=b(async(e,t)=>{Sb({token:e,...t}),await hb(e),ib(),n(Xb(e)),o(!1)},[]),d=b(()=>{rb().logout().catch(()=>{}),xb().stop(),pb(),fetch(B(`/api/auth/session`),{method:`DELETE`}).catch(()=>{}),ib(),n(null),o(!1)},[]),f=b(()=>{o(!1)},[]);return x(rx.Provider,{value:{user:t,loading:r,mustChangePassword:a,login:c,verifyTotp:l,finalizePasskeyLogin:u,logout:d,clearMustChangePassword:f},children:e})}function ax(){let e=I(rx);if(!e)throw Error(`useAuth must be used within AuthProvider`);return e}function ox(e){return(t,n,r)=>e(t,{...typeof n==`string`?{defaultValue:n}:{defaultValue_one:n.one,defaultValue_other:n.other},...r})}var sx=(e,t,n)=>ox(K.t.bind(K))(e,t,n);function cx(e,t){return e===`present`&&t.status===`ok`&&(t.data?.length??0)>0}O();function lx({deviceId:e,deviceName:t}){let{t:n}=q(),r=Ui(`remote`),i=Yi({deviceId:e},{enabled:r===`present`}),[a,o]=w(!1);return r!==`present`||(i.data?.commands.length??0)===0&&(i.data?.sources.length??0)===0?null:s(`div`,{className:`flex flex-wrap items-center justify-center gap-1`,children:[s(G,{size:`sm`,variant:`outline`,onClick:()=>o(!0),"data-testid":`hero-remote`,children:[x(ua,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),n(`remote.hero.open`)]}),a&&x(ux,{deviceId:e,deviceName:t,onClose:()=>o(!1)})]})}function ux({deviceId:e,deviceName:t,onClose:n}){let{t:r}=q(),i=Ki({deviceId:e}),a=Rr({kind:`remote`}),o=Yi({deviceId:e}),c=Ci(),l=Jr({deviceId:e}),[u,d]=w(null),f=i.data?.layoutTemplateId??null,p=(a.data??[]).find(e=>e.id===f),m=p===void 0?null:Xr(p.payload),h=new Set((o.data?.commands??[]).map(e=>e.role)),g=async t=>{let n=m?.buttons.find(e=>e.id===t)?.role;if(!(n===void 0||!h.has(n))){d(null);try{let t=await c.mutateAsync({deviceId:e,role:n,repeat:1});t.status===`refused`&&d(r(`remote.test.refused.${t.reason}`,{detail:t.detail??``}))}catch(e){d(e instanceof Error?e.message:String(e))}}};return x(Mi,{open:!0,onOpenChange:e=>!e&&n(),children:s(Ir,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[x(Yr,{children:x(qi,{children:r(`remote.hero.title`,{name:t})})}),s(zi,{className:`space-y-3`,children:[i.status===`error`?x(Or,{title:r(`remote.dialog.unreadable`),message:i.error?.message??``,onRetry:()=>void i.refetch()}):m===null?x(`p`,{className:`text-xs text-foreground-muted`,children:r(`remote.hero.noLayout`)}):x(`div`,{className:`mx-auto w-full max-w-xs`,"data-testid":`remote-press`,children:x(Pr,{grid:m,label:r(`remote.hero.title`,{name:t}),boundRoles:h,onSelect:e=>void g(e),renderWidget:(t,n)=>x(vi,{deviceId:e,button:t,sources:o.data?.sources??[],current:l.data?.source??``,placement:n})})}),u!==null&&x(`p`,{role:`alert`,className:`text-xs text-danger`,children:u})]})]})})}O();var dx=j({});function fx({value:e,children:t}){return x(dx.Provider,{value:e,children:t})}O();var px={"off-while-running":{title:`Turn off while running?`,message:`The device is running. Cutting its power now interrupts what it is doing.`,confirm:`Turn off`},unlock:{title:`Unlock?`,message:`The lock will open.`,confirm:`Unlock`},install:{title:`Install the update?`,message:`The device may restart and be unavailable for a while.`,confirm:`Install`},press:{title:`Run it now?`,message:`The device acts as soon as you confirm.`,confirm:`Run`}},mx=e=>e===`off-while-running`?`deviceHero.model.confirmOff`:`deviceHero.model.confirm.${e}`;function hx(){let{t:e,i18n:t}=q(),n=t.language;return m(()=>{let t=t=>({title:e(`${mx(t)}.title`,px[t].title),message:e(`${mx(t)}.message`,px[t].message),confirm:e(`${mx(t)}.confirm`,px[t].confirm)});return{noValue:e(`deviceHero.model.noValue`,`–`),callFailed:e(`deviceHero.model.callFailed`,`The device did not accept the command`),historyTooltip:e(`deviceHero.utility.history.tooltip`,`Opens the history of this device.`),consumables:{label:e(`deviceHero.utility.consumables.label`,`Consumables`),low:t=>e(`deviceHero.utility.consumables.low`,`{{count}} low`,{count:t}),ok:e(`deviceHero.utility.consumables.ok`,`OK`),tooltip:e(`deviceHero.utility.consumables.tooltip`,`Shows the level of each consumable and which ones need attention.`)},power:{label:e(`deviceHero.utility.power.label`,`Power source`),on:e(`deviceHero.utility.power.on`,`On`),off:e(`deviceHero.utility.power.off`,`Off`),tooltip:e(`deviceHero.utility.power.tooltip`,`Opens a menu to cut or restore the power feeding this device, or to restart it.`),tooltipReadOnly:e(`deviceHero.utility.power.tooltipReadOnly`,`Whether the power source feeding this device is on. Your session cannot change it.`)},confirm:{"off-while-running":t(`off-while-running`),unlock:t(`unlock`),install:t(`install`),press:t(`press`)}}},[e,n])}O();function gx(e){let[t]=w(()=>new D({defaultOptions:{queries:{retry:!1,staleTime:5e3}}}));return e??t}function _x({deviceId:e,kind:t,canActuate:n,onDrawn:r,showName:i}){let a=yi();return S(()=>{r?.(!0)},[r]),x(`div`,{className:`flex h-full justify-center`,children:x(Qi,{kind:t,deviceId:e,canActuate:n,orientation:a?`vertical`:`horizontal`,showName:i!==!1})})}function vx(e){let t=Ti(e.deviceId);return t===`pending`?x(yr,{className:`h-72 w-full`}):t===null?x(yx,{...e}):x(_x,{deviceId:e.deviceId,kind:t,canActuate:e.canActuate,onDrawn:e.onDrawn,showName:e.showName})}function yx(e){let t=yi();return x(`div`,{className:`flex h-full justify-center`,children:x(eo,{deviceId:e.deviceId,canActuate:e.canActuate,orientation:t?`vertical`:`horizontal`,showName:e.showName!==!1,placeholder:x(yr,{className:`h-72 w-full`}),fallback:x(`div`,{className:`w-full`,children:x(bx,{...e})}),...e.onDrawn===void 0?{}:{onDrawn:e.onDrawn}})})}function bx({deviceId:e,canActuate:t,fallback:n,onDrawn:r,defaultHistoryOpen:i,showName:a}){let{t:o,i18n:c}=q(),l=hx(),[u,d]=w(i===!0),f=Ja(e),p=cx(f.presence,f.list),m=b(()=>d(!0),[]);return s(F,{children:[x(qr,{deviceId:e,canActuate:t,lang:Wi(c.language),labels:l,renderRemote:t=>x(lx,{deviceId:e,deviceName:t}),fallback:n??null,showName:a!==!1,...p?{onOpenHistory:m}:{},...r===void 0?{}:{onDrawn:r}}),u?x(Mi,{open:!0,onOpenChange:e=>!e&&d(!1),children:s(Ir,{width:`xl`,scroll:`body`,children:[x(Yr,{children:x(qi,{children:o(`deviceModule.history`,`History`)})}),x(zi,{className:`mt-3`,children:x(qa,{deviceId:e})})]})}):null]})}function xx({deviceId:e,trpcClient:t,theme:n,locale:r,canActuate:i=!1,defaultHistoryOpen:a,queryClient:o,fallback:s,onDrawn:c,onOpenDevice:l,onOpenCamera:u,onClose:d,onNavigate:f,showName:p}){let h=gx(o),g=m(()=>K.cloneInstance({lng:r}),[r]),_=m(()=>ox(g.t.bind(g)),[g]),v=m(()=>({onOpenDevice:l,onOpenCamera:u,onClose:d,onNavigate:f}),[l,u,d,f]);return x(`div`,{className:`${n} h-full`,"data-theme":n,"data-testid":`device-detail-module`,children:x(vd,{i18n:g,children:x(dt,{t:_,children:x(Le,{client:t,children:x(Ka.Provider,{client:t,queryClient:h,children:x(P,{client:h,children:x(Xe,{children:x(fx,{value:v,children:x(vx,{deviceId:e,canActuate:i,fallback:s,onDrawn:c,defaultHistoryOpen:a,showName:p})})})})})})})})})}function Sx({deviceId:e}){let t=V(),{data:n,isLoading:r}=Dy(e),{data:i,isLoading:a}=Ay(e),o=r||a,s=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...typeof e.role==`string`?{role:e.role}:{},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,u=typeof n?.type==`string`?n.type:void 0;return o?x(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):x(`div`,{className:`flex h-full w-full flex-col`,children:x(Oi,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l,containerType:u,primaryChildPreference:n?nn(n):void 0})})}O();function Cx({dev:e,busy:t,setBusy:n}){let{t:r}=q(),i=e?.motionTrigger,a=de(e?.state.motionTrigger),[o,c]=w(!1);if(!i)return null;let l=a?.enabled===!0,u=a!==void 0,d=async()=>{if(t||!u)return;let e=!l;n(!0),c(!0);try{await i.setMotionTrigger({enabled:e})}finally{n(!1),c(!1)}},f=o?l?`Disabling…`:`Enabling…`:u?l?`On motion: on`:`On motion: off`:`On motion: …`;return s(G,{variant:`unstyled`,type:`button`,onClick:()=>{d()},disabled:t||!u,title:u?l?r(`hero.motionTriggerToggle.disableTriggerOnMotion`,`Disable trigger on motion`):r(`hero.motionTriggerToggle.enableTriggerOnMotion`,`Enable trigger on motion`):r(`hero.motionTriggerToggle.awaitingState`,`Awaiting state…`),"aria-pressed":l,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${l?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[x(he,{className:`h-3 w-3`}),x(`span`,{children:f})]})}O();function Q({deviceId:e,deviceName:t,deviceType:n,deviceRole:r,features:i}){let a=V(),o=Vr(n,r)?.HeroCard??Ni,c=fe(a.trpcClient,e),l=de(c?.state.deviceStatus),[u,d]=w(!1),f=l!==void 0&&l.online===!1,p=f?l.lastChangedAt:null;return s(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[f?x(`div`,{className:`flex justify-center`,children:x(Ri,{lastChangedAt:p})}):null,x(o,{trpc:a.trpcClient,deviceId:e,features:i}),n===U.MediaPlayer?x(lx,{deviceId:e,deviceName:t}):null,x(`div`,{className:`flex justify-center`,children:x(Cx,{dev:c,busy:u,setBusy:d})})]})}function wx({deviceId:e,features:t}){return x(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:x(Hi,{trpc:V().trpcClient,deviceId:e,features:t})})}function Tx({deviceId:e}){let{t}=q(),n=Hr({deviceId:e},{staleTime:15e3}).data;if(n===void 0||n.linked!==!0||n.switchOn===null)return x(F,{});let r=n.switchOn===!0?t(`deviceHero.powerLine.on`,`Power switch on`):t(`deviceHero.powerLine.off`,`Power switch off`);return x(`p`,{className:`px-3 pt-1 text-[11px] text-foreground-muted sm:px-4`,children:n.switchName===null||n.switchName===``?r:t(`deviceHero.powerLine.withName`,`{{state}} · {{name}}`,{state:r,name:n.switchName})})}function Ex({deviceId:e,features:t}){return x(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:x(Ni,{trpc:V().trpcClient,deviceId:e,features:t})})}function Dx(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}var Ox=1e3,kx=60*Ox,Ax=60*kx,jx=24*Ax;function Mx(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<Ox?K.t(`helpers.relativeTime.justNow`):n<kx?K.t(`helpers.relativeTime.secondsAgo`,{count:Math.floor(n/Ox)}):n<Ax?K.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(n/kx)}):n<jx?K.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(n/Ax)}):K.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(n/jx)})}function Nx(e){let t=null;for(let n of e){let e=n.description;if(!(e===void 0||e.length===0)){if(t===null){t=e;continue}if(t!==e)return null}}return t}function Px(e){let t=new Map,n=[];for(let r of e){if(r.source===void 0){n.push(r);continue}let e=t.get(r.source.id);t.set(r.source.id,{source:r.source,entries:[...e?.entries??[],r]})}return[...t.values(),...n.length===0?[]:[{source:null,entries:n}]]}function Fx(e,t){if(!e)return null;let n=(Zt(t,e.eventType,e.sourceId)??Zt(t,e.eventType))?.label??e.eventType;if(e.sourceId!==void 0)return{source:t.find(t=>t.source?.id===e.sourceId)?.source?.label??null,label:n};let r=Dx(e.data);return{source:r===null?null:K.t(`hero.eventEmitterHero.button`,{value1:String(r)}),label:n}}O();var Ix=1500,Lx=15e3,Rx=1e3;function zx({deviceId:e}){let{t}=q(),n=fe(V().trpcClient,e)?.state.eventEmitter,r=de(n);S(()=>{if(!n)return;n.refresh();let e=setInterval(()=>{n.refresh()},Lx);return()=>{clearInterval(e)}},[n]);let i=r?.lastEvent??null,a=i?.seq??null,o=p(null),[c,l]=w(!1);S(()=>{if(a===null)return;let e=o.current;if(o.current=a,e===null||e===a)return;l(!0);let t=setTimeout(()=>{l(!1)},Ix);return()=>{clearTimeout(t)}},[a]);let[u,d]=w(()=>Date.now());S(()=>{let e=setInterval(()=>{d(Date.now())},Rx);return()=>{clearInterval(e)}},[]);let f=r===void 0?[]:Qn(r),m=Px(f),h=Nx(f),g=Fx(i,f),_=g===null?null:g.source===null?g.label:`${g.source} · ${g.label}`,v=i===null?void 0:Zt(f,i.eventType,i.sourceId),y=r?.eventCountSinceStart??0,b=r!==void 0;return s(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[x(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(c),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${c?`border-primary bg-primary/20 text-primary shadow-lg shadow-primary/30 scale-105`:`border-border bg-surface text-foreground-subtle`}`,"aria-live":`polite`,title:_??t(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`),children:x(c?St:it,{className:`h-10 w-10`})}),s(`div`,{className:`text-center`,children:[g!==null&&g.source!==null&&x(`div`,{"data-testid":`event-emitter-source`,className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:g.source}),x(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${_?`text-foreground`:`text-foreground-subtle`}`,children:_??(b?t(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`):t(`hero.eventEmitterHero.awaitingState`,`Awaiting state…`))}),x(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:i?Mx(i.timestamp,u):t(`hero.eventEmitterHero.waitingForTheFirstEvent`,`Waiting for the first event`)})]}),h!==null&&x(`p`,{"data-testid":`event-emitter-notice`,className:`max-w-full text-center text-xs text-foreground-subtle`,children:h}),m.length>0&&x(`div`,{className:`flex max-w-full flex-col items-center gap-1`,children:m.map(e=>s(`div`,{"data-testid":`event-emitter-source-row`,className:`flex max-w-full flex-wrap items-center justify-center gap-1`,children:[e.source!==null&&x(`span`,{className:`text-[10px] font-semibold text-foreground-subtle`,children:e.source.label}),e.entries.map(t=>x(`span`,{"data-testid":`event-emitter-chip`,title:t.description??t.id,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${t===v?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:t.label},`${e.source?.id??``}:${t.id}`))]},e.source?.id??``))}),x(`div`,{className:`text-[10px] text-foreground-subtle`,children:t(`hero.eventEmitterHero.sinceStart`,{count:y})})]})}function Bx({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){let{t:a}=q();return s(`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:[x(bv,{type:n,size:`lg`}),s(`div`,{children:[x(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),x(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),s(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[!r&&x(Gi,{status:`offline`}),i.length>0&&x(ly,{capabilities:i})]}),x(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:a(`hero.genericHero.noLiveViewForThis`,`No live view for this device type. Use the Config tab or the shortcut row to interact.`)})]})}var Vx={[U.Switch]:Q,[U.Siren]:Q,[U.Light]:Q,[U.Sensor]:Q,[U.Button]:Q,[U.Cover]:wx,[U.Valve]:Q,[U.Humidifier]:Q,[U.WaterHeater]:Q,[U.Container]:Sx,[U.Lock]:Q,[U.Fan]:Q,[U.Climate]:Q,[U.MediaPlayer]:Q,[U.Control]:Q,[U.AlarmPanel]:Q,[U.EventEmitter]:zx,[U.Notifier]:Ex,[U.Script]:Q,[U.Automation]:Q,[U.Presence]:Q,[U.Update]:Q,[U.Vacuum]:Q,[U.LawnMower]:Q,[U.Weather]:Q,[U.WeatherStation]:Q,[U.Image]:Q,[U.PetFeeder]:Q,[U.PetFountain]:Q,[U.Dishwasher]:Q,[U.Washer]:Q,[U.Dryer]:Q,[U.EnergySystem]:Q,[U.Workload]:Q};function Hx(e){return Vx[e]??Bx}function Ux({deviceId:e}){let t=ct(V().trpcClient,e,e=>e.runningState);if(t===void 0||t.running!==!0&&t.running!==!1)return x(F,{});let n=t.running;return x(_r,{running:n,since:t?.since??null,phase:t?.phase??null,className:`px-3 pt-2 sm:px-4`})}function Wx(e){let t=Hx(e.deviceType);return s(F,{children:[x(Ux,{deviceId:e.deviceId}),x(Tx,{deviceId:e.deviceId}),x(t,{...e})]})}function Gx({deviceId:e,device:t,deviceName:n,defaultHistoryOpen:r=!1,legacyFallback:i=!0,onDrawn:a,onNavigate:o}){let{i18n:s}=q(),{resolvedMode:c}=ba(),l=ll(),u=N(),d=V(),{user:f}=ax(),p=t?.features??[],m=e=>{o===void 0?l(e):o(e)};return x(xx,{deviceId:e,trpcClient:d.trpcClient,queryClient:u,theme:c,locale:Wi(s.language),canActuate:f?.isAdmin===!0,showName:!1,defaultHistoryOpen:r,...a===void 0?{}:{onDrawn:a},onOpenDevice:e=>m(`/devices/${String(e)}`),onOpenCamera:e=>m(`/devices/${String(e)}`),onNavigate:m,...i?{fallback:x(Wx,{deviceId:e,deviceName:n,deviceType:t?.type??`unknown`,deviceRole:t?.role??null,provider:String(t?.addonId??`rtsp`),isOnline:t?.online===!0,features:p})}:{}})}function Kx(e,t){return e.icon===t.icon&&e.label===t.label&&e.unit===t.unit&&e.precision===t.precision&&e.hidden===t.hidden}function qx(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function Jx(e){if(e.trim()===``)return;let t=Number.parseInt(e,10);return Number.isFinite(t)?t:void 0}function Yx(e,t){let n=Jx(e.precision),r={...e.icon===``?{}:{icon:e.icon},...e.label.trim()===``?{}:{label:e.label.trim()},...e.unit===``?{}:{unit:e.unit},...n===void 0?{}:{precision:n},...e.hidden?{hidden:!0}:{},...t?.perCap===void 0?{}:{perCap:t.perCap}};return Object.keys(r).length===0?null:r}function Xx(e){let t=qx(e.display),n=e.tags??[];return{name:e.name,location:e.location,role:e.role,display:t,tags:n,baseName:e.name,baseLocation:e.location,baseRole:e.role,baseDisplay:t,baseTags:n,persistedDisplay:e.display}}function Zx(e,t){if(e===null)return Xx(t);let n=qx(t.display),r=e.name===t.name&&e.location===t.location&&e.role===t.role&&$x(e.tags,t.tags??[])&&Kx(e.display,n);return!Qx(e)||r?Xx(t):e}function Qx(e){return e===null?!1:e.name!==e.baseName||e.location!==e.baseLocation||e.role!==e.baseRole||!$x(e.tags,e.baseTags)||!Kx(e.display,e.baseDisplay)}function $x(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function eS(e){return e.name.trim().length===0?`name`:null}function tS(e){let t=e.name.trim(),n=e.location.trim();return{...t===e.baseName?{}:{name:t},...n===e.baseLocation?{}:{location:n===``?null:n},...e.role===e.baseRole?{}:{role:e.role},...$x(e.tags,e.baseTags)?{}:{tags:[...e.tags]},...Kx(e.display,e.baseDisplay)?{}:{display:Yx(e.display,e.persistedDisplay)}}}function nS(e){let t=e.map(e=>e.error).filter(e=>e!==null&&e.length>0);return{dirty:e.some(e=>e.dirty),saving:e.some(e=>e.saving),error:t.length===0?null:t.join(`; `)}}O();var rS=j(null);function iS(){return I(rS)}function aS({deviceId:e,seed:t,onClose:n,children:r}){let[i,a]=w(null),[o,s]=w([]),{t:c}=q(),l=ll(),u=He(),d=p(new Map);if(t!==null){let e=Zx(i,t);(i===null||e.name!==i.name||e.location!==i.location||e.role!==i.role||!$x(e.tags,i.tags)||!$x(e.baseTags,i.baseTags)||!Kx(e.display,i.display)||e.baseName!==i.baseName||e.baseLocation!==i.baseLocation||e.baseRole!==i.baseRole||!Kx(e.baseDisplay,i.baseDisplay)||e.persistedDisplay!==i.persistedDisplay)&&a(e)}let f=b(e=>(d.current.set(e.id,{save:e.save,discard:e.discard}),s(t=>{let n=t.find(t=>t.id===e.id);return n!==void 0&&n.dirty===e.dirty&&n.saving===e.saving&&n.error===e.error?t:[...t.filter(t=>t.id!==e.id),{...e,save:()=>d.current.get(e.id)?.save()??Promise.resolve(),discard:()=>{d.current.get(e.id)?.discard()}}]}),()=>{d.current.delete(e.id),s(t=>t.filter(t=>t.id!==e.id))}),[]),h=nS([{dirty:Qx(i),saving:!1,error:null},...o]).dirty,g=b(e=>{(async()=>{h&&!await u({title:c(`deviceQuickDetail.leaveTitle`,`Discard unsaved changes?`),message:c(`deviceQuickDetail.leaveMessage`,`Unsaved edits on this device will be discarded.`),confirmLabel:c(`deviceQuickDetail.discard`,`Discard`),variant:`warning`})||(l(e),n?.())})()},[h,u,c,l,n]),_=b(()=>g(`/devices/${String(e)}`),[g,e]),v=m(()=>({identity:i,setIdentityName:e=>{a(t=>t===null?t:{...t,name:e})},setIdentityLocation:e=>{a(t=>t===null?t:{...t,location:e})},setIdentityRole:e=>{a(t=>t===null?t:{...t,role:e})},setIdentityTags:e=>{a(t=>t===null?t:{...t,tags:e})},setIdentityDisplay:e=>{a(t=>t===null?t:{...t,display:{...t.display,...e}})},register:f,openDevicePage:_,leaveTo:g}),[i,f,_,g]);return x(rS.Provider,{value:v,children:x(oS,{deviceId:e,identity:i,contributions:o,onIdentitySaved:e=>a(e),children:r})})}function oS({deviceId:e,identity:t,contributions:n,onIdentitySaved:r,children:i}){return s(F,{children:[i,x(cS,{deviceId:e,identity:t,contributions:n,onIdentitySaved:r})]})}function sS(e){return e instanceof Error?e.message:String(e)}function cS({deviceId:e,identity:t,contributions:n,onIdentitySaved:r}){let{t:i}=q(),a=N(),[o,c]=w(null),[l,u]=w(!1),d=ho(),f=ea(),p=Dr(),m=ya(),h=jr(),g=nS([{dirty:Qx(t),saving:l,error:o},...n]),_=()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})};return!g.dirty&&!g.saving&&g.error===null?null:s(`div`,{className:`sticky bottom-0 z-10 mt-auto flex flex-col gap-2 border-t border-border bg-background px-1 pt-3`,children:[g.error!==null&&x(`p`,{className:`text-xs text-danger`,children:g.error}),x(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:s(`div`,{className:`flex items-center gap-2`,children:[x(G,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{t!==null&&r({...t,name:t.baseName,location:t.baseLocation,role:t.baseRole,display:t.baseDisplay,tags:t.baseTags});for(let e of n)e.discard();c(null)},disabled:!g.dirty||g.saving,children:i(`deviceQuickDetail.discard`,`Discard`)}),x(G,{type:`button`,size:`sm`,onClick:()=>{if(t!==null&&Qx(t)&&eS(t)===`name`){c(i(`deviceQuickDetail.nameRequired`,`Name is required`));return}c(null),u(!0),(async()=>{try{let i=t===null?{}:tS(t);if(t!==null&&i.name!==void 0&&await d.mutateAsync({deviceId:e,name:i.name}),t!==null&&i.location!==void 0&&await f.mutateAsync({deviceId:e,location:i.location}),t!==null&&i.role!==void 0&&await p.mutateAsync({deviceId:e,role:i.role}),t!==null&&i.tags!==void 0&&await h.mutateAsync({deviceId:e,tags:i.tags}),t!==null&&i.display!==void 0&&await m.mutateAsync({deviceId:e,display:i.display}),t!==null){let e=t.name.trim(),n=t.location.trim();r({...t,name:e,location:n,baseName:e,baseLocation:n,baseRole:t.role,baseDisplay:t.display,baseTags:t.tags,persistedDisplay:i.display===void 0?t.persistedDisplay:i.display??void 0})}for(let e of n)e.dirty&&await e.save();_()}catch(e){c(sS(e))}finally{u(!1)}})()},disabled:!g.dirty||g.saving,children:g.saving?i(`deviceQuickDetail.saving`,`Saving…`):i(`deviceQuickDetail.save`,`Save`)})]})})]})}O();function lS(e,t){for(let n of e)for(let e of n.fields){if(!(`key`in e)||e.key!==t)continue;if(e.type===`button`||e.type===`separator`||e.type===`info`)return!0;let r=e.immediate;return r===!0?!0:r===!1?!1:n.immediate===!0}return!1}function uS({schema:e,serverValues:t,onImmediateSave:n,onDeferredSave:r}){let[i,a]=w({}),[o,s]=w({}),[c,l]=w(!1),u=p(null),d=e?.sections??[],f=Object.keys(i).length>0,h=m(()=>({...t,...o,...i}),[t,o,i]);S(()=>{if(f||Object.keys(o).length>0){l(!0);return}u.current&&clearTimeout(u.current),u.current=setTimeout(()=>l(!1),500)},[f,o]),S(()=>()=>{u.current&&clearTimeout(u.current)},[]);let g=b(()=>{l(!0),u.current&&clearTimeout(u.current),u.current=setTimeout(()=>l(!1),2e3)},[]),_=b(e=>{g();let r={},o={},s={...t,...i};for(let[t,n]of Object.entries(e))s[t]!==n&&(lS(d,t)?r[t]=n:o[t]=n);Object.keys(r).length>0&&n(r),a(e=>{let t={...e};for(let e of Object.keys(r))delete t[e];for(let[e,n]of Object.entries(o))t[e]=n;return t})},[g,t,i,d,n]),v=b(e=>{let t={},n={};for(let[r,a]of Object.entries(i))e.includes(r)?t[r]=a:n[r]=a;if(a(n),Object.keys(t).length===0)return;let o=Object.keys(t),c=r(t);if(c===void 0||typeof c.then!=`function`)return;s(e=>({...e,...t}));let l=()=>s(e=>{let t={...e};for(let e of o)delete t[e];return t});c.then(l,()=>{l(),a(e=>{let n={...e};for(let e of o)e in n||(n[e]=t[e]);return n})})},[i,r]),y=b(e=>{a(t=>{let n={...t};for(let t of e)delete n[t];return n})},[]),x=b(()=>{a({})},[]);return{values:h,pendingKeys:Object.keys(i),hasPendingEdits:f,editingPaused:c,handleChange:_,handleSave:v,handleDiscard:y,resetAll:x}}function dS({pendingCount:e,onSave:t,onDiscard:n,saving:r=!1,saveLabel:i=`Save`,discardLabel:a=`Discard`}){let{t:o}=q();return e<=0?null:s(`div`,{className:`sticky bottom-0 -mb-3 flex items-center justify-between gap-3 rounded-lg border border-primary/40 bg-primary/5 px-3 py-2 shadow-sm z-10`,children:[x(`span`,{className:`text-xs text-foreground`,children:o(`formBuilder.saveBar.unsavedChanges`,{count:e})}),s(`div`,{className:`flex items-center gap-2`,children:[x(G,{variant:`unstyled`,type:`button`,onClick:n,disabled:r,className:`inline-flex items-center rounded-md border border-border px-2.5 py-1 text-xs text-foreground-subtle hover:bg-surface-hover disabled:opacity-50`,children:a}),x(G,{variant:`unstyled`,type:`button`,onClick:t,disabled:r,className:`inline-flex items-center rounded-md bg-primary px-3 py-1 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:r?o(`formBuilder.formSaveBar.saving`,`Saving…`):i})]})]})}function fS({tabs:e,activeId:t,onChange:n,countByTab:r,pendingByTab:i}){return e.length===0?null:x(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border shrink-0`,children:e.map(e=>{let a=e.id===t,o=r?.get(e.id)??0,c=i?.get(e.id)??0;return s(G,{variant:`unstyled`,type:`button`,onClick:()=>n(e.id),className:`relative shrink-0 px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors -mb-px border-b-2 whitespace-nowrap ${a?`text-primary border-primary bg-primary/5`:`text-foreground-subtle border-transparent hover:text-foreground hover:bg-surface-hover`}`,children:[e.label,o>0&&s(`span`,{className:`ml-1.5 text-[10px] opacity-60`,children:[`(`,o,`)`]}),c>0&&x(`span`,{className:`ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-primary`})]},e.id)})})}O();function pS({schema:e,values:t,pendingKeys:n,onChange:r,onAction:i,onSave:a,onDiscard:o,disabled:c,activeSubTab:l,onSubTabChange:u,flattenTabs:d=!1,visibilityContext:f,hideSaveBar:h=!1,leadingTabs:g=[]}){let _=e.tabs??[],v=m(()=>{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]),y=new Set(_.map(e=>e.id)),b=[...g.map(e=>({id:e.id,label:e.label})),..._,...[...v.keys()].filter(e=>!y.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],S=b[0]?.id??`general`,[C,T]=w(S),E=u!==void 0,D=new Set(b.map(e=>e.id)),O=p(new Set);for(let e of D)O.current.add(e);let k=O.current,A=(e=>e&&(D.has(e)||k.has(e))?e:S)(E?l:C),j=e=>{E?u(e):T(e)},M=g.find(e=>e.id===A),N=v.get(A)??[],ee={sections:N.length<=1?N.length===1?[{...N[0],title:``}]:N:N.every(e=>!e.title)?[{...N[0],title:``,fields:N.flatMap(e=>e.fields)}]:N},P=h?null:x(dS,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>o(n),saving:c});if(g.length===0&&(d||b.length<=1))return s(`div`,{className:`flex flex-col gap-3`,children:[x(cg,{schema:e,values:t,onChange:r,onAction:i,disabled:c,visibilityContext:f}),P]});let F=new Map,I=new Map;for(let[e,t]of v){F.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&&I.set(e,a)}return s(`div`,{className:`flex flex-col gap-3`,children:[x(fS,{tabs:b.map(e=>({id:e.id,label:e.label})),activeId:A,onChange:j,countByTab:F,pendingByTab:I}),x(ia,{tabKey:A,children:M===void 0?x(cg,{schema:ee,values:t,onChange:r,onAction:i,disabled:c,visibilityContext:f}):M.content}),P]})}var mS=`device-export`,hS=`export`,gS=`Export`;function _S(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(_S):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(_S)):e.writerCapName===mS}function vS(e){return e.tab===`export`?!0:e.fields.some(_S)}var yS=`host/extensions-panel`;function bS(e){return e.type===`widget`?e.widgetId===yS:e.type===`group`?e.fields.some(bS):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(bS)):!1}function xS(e){return e.fields.some(bS)}function SS(e,t){return!t&&e!==void 0&&Cn.includes(e)}function CS(e){return e.location!==`top-tab`&&e.location!==`hero`&&!vS(e)&&!xS(e)}function wS(e,t,n,r){return!r||SS(t,n)?!0:(e??[]).some(CS)}function TS(e,t){for(let n of e){if(n.type===`group`){TS(n.fields,t);continue}if(n.type===`sub-tabs`){for(let e of n.tabs)TS(e.fields,t);continue}if(!(`value`in n))continue;let e=n.value===void 0?n.default:n.value;e!==void 0&&(t[n.key]=e)}}function ES(e){let t={};for(let n of e)TS(n.fields,t);return t}O();function DS(e,t){return t&&t===`admin`?e:!0}function OS(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?vS(e)&&vS(t)?e.id.localeCompare(t.id):(e.order??0)-(t.order??0):n.localeCompare(r)})};return e.tabs?{...t,tabs:e.tabs}:t}function kS(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`||e.type===`account-sign-in`||e.type===`secret-presence`}function AS(e){return e.key}function jS(e){if(!kS(e))return e.value}function MS(e){return kS(e)?null:e}function NS(e,t){for(let n of e)if(t(n),n.type===`group`)NS(n.fields,t);else if(n.type===`sub-tabs`)for(let e of n.tabs)NS(e.fields,t)}function PS(e){if(!e)return{};let t={};for(let n of e.sections)NS(n.fields,e=>{let n=AS(e);n!==null&&(t[n]=jS(e))});return t}function FS(e,t){if(!e)return null;let n=null;for(let r of e.sections)if(NS(r.fields,e=>{if(n!==null||AS(e)!==t)return;let r=MS(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function IS(e){return{...e,fields:e.fields.map(LS)}}function LS(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function RS(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=MS(e);return n?DS(t,n.minRole)?e:LS(e):e})}))}}var zS={sections:[]};function BS({deviceId:e,sectionFilter:t,activeSubTab:n,onSubTabChange:r,flattenSubTabs:i,subTabGrouping:a,leadingTabs:o}){let{t:c}=q(),l=N(),{user:u}=ax(),d=u?.isAdmin===!0,f=p(!1),{data:h,isLoading:g}=Zr({deviceId:e},{refetchInterval:()=>f.current?!1:2500,enabled:Number.isFinite(e)}),{data:_}=$a({deviceId:e},{enabled:Number.isFinite(e)}),v=h?.settings??null,y=h?.live??null,C=m(()=>{if(!v&&!y)return null;let e=v?.sections??[],n=(y?.sections??[]).map(IS),r=[...e,...n],i=t?r.filter(t):r.filter(CS);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=[...v?.tabs??[],...(y?.tabs??[]).filter(e=>!(v?.tabs??[]).some(t=>t.id===e.id))].filter(e=>o.has(e.id));return s.length>0?{tabs:s,sections:i}:{sections:i}},[v,y,t,a]),w=m(()=>ES([...v?.sections??[],...y?.sections??[]]),[v,y]),T=m(()=>OS(C),[C]),E=m(()=>RS(T,d),[T,d]),D=m(()=>PS(E),[E]),O=Sr(),k=Pa(),A=di(),j=Sa(),M=br({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),ee={isPending:M.isPending,mutate:t=>{M.mutate({deviceId:e,changes:[...t]})}},P=uS({schema:E,serverValues:D,onImmediateSave:b(e=>{let t=Object.entries(e).map(([e,t])=>{let n=FS(E,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&ee.mutate(t)},[E,ee]),onDeferredSave:b(async t=>{let n=Object.entries(t).map(([e,t])=>{let n=FS(E,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);if(n.length!==0)try{let t=await M.mutateAsync({deviceId:e,changes:n});if(t.failures.length>0)throw Error(t.failures.map(e=>e.error).join(`; `))}finally{await l.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}},[E,M,e,l])}),{values:F,pendingKeys:I,handleChange:L,handleSave:te,handleDiscard:ne}=P;f.current=P.editingPaused;let re=iS(),ie=p(te),ae=p(ne);ie.current=te,ae.current=ne;let oe=re?.register,se=M.isError?M.error instanceof Error?M.error.message:String(M.error):null,R=I.join(`\0`);S(()=>{if(oe===void 0)return;let e=R===``?[]:R.split(`\0`);return oe({id:`export`,dirty:e.length>0,saving:M.isPending,error:se,save:()=>(ie.current(e),Promise.resolve()),discard:()=>ae.current(e)})},[oe,R,M.isPending,se]);let ce=o!==void 0&&o.length>0;if(g&&!ce)return s(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[x(H,{className:`h-4 w-4 animate-spin mr-2`}),x(`span`,{className:`text-xs`,children:c(`device.deviceAggregateSection.loadingDeviceAggregate`,`Loading device aggregate…`)})]});if(!ce&&(!E||E.sections.length===0))return x(`div`,{className:`text-xs text-foreground-subtle italic py-4 text-center`,children:c(`device.deviceAggregateSection.noAggregateContributionsForThis`,`No aggregate contributions for this device.`)});async function le(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=kt(e,r);await O.mutateAsync({brokerId:i}),l.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(t===`test-probe`){if(!_)return{status:`error`,error:c(`device.deviceAggregateSection.metadataNotLoaded`)};try{return await A.mutateAsync({addonId:_.addonId,type:_.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=kt(e,t),i=await k.mutateAsync({brokerId:r});return l.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),i}if(t===`device-custom-action`){let t=await j.mutateAsync({deviceId:e,action:n,input:r});return l.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),t}throw Error(`[device-aggregate] unknown action "${t}"`)}return x(pS,{schema:E??zS,values:F,pendingKeys:I,onChange:L,onAction:le,onSave:te,onDiscard:ne,hideSaveBar:re!==null,disabled:ee.isPending,activeSubTab:n,onSubTabChange:r,flattenTabs:i,leadingTabs:o,visibilityContext:w})}O();function VS({deviceId:e,device:t,name:n,onDrawn:r}){let i=iS();return x(li,{frame:`bare`,fill:!0,children:x(Gx,{deviceId:e,device:t,deviceName:n,legacyFallback:!1,onDrawn:r,...i===null?{}:{onNavigate:i.leaveTo}})})}function HS(){let{t:e}=q(),t=iS();return t===null?null:x(G,{type:`button`,variant:`outline`,size:`sm`,onClick:t.openDevicePage,children:e(`deviceQuickDetail.openPage`,`Open device page`)})}function US({deviceId:e,onClose:t}){let{t:n}=q(),[r,i]=w(`detail`),[a,o]=w(null),c=a===!1,l=r===`detail`&&c?`info`:r,{data:u}=$a({deviceId:e},{enabled:e>0}),d=typeof u?.name==`string`?u.name:``,f=ei(e,`full`,d.length>0?d:`#${String(e)}`),p=typeof u?.location==`string`?u.location:``,m=[...c?[]:[[`detail`,n(`deviceQuickDetail.tabDetail`,{defaultValue:`Detail`})]],[`info`,n(`deviceQuickDetail.tabInfo`,{defaultValue:`Device info`})],[`export`,n(`deviceQuickDetail.tabExport`,{defaultValue:`Export`})]];return x(Mi,{open:!0,onOpenChange:e=>!e&&t(),children:x(Ir,{width:`lg`,scroll:`body`,className:`md:h-[85dvh]`,children:s(aS,{deviceId:e,seed:u==null?null:{name:d,location:p,role:typeof u.role==`string`?u.role:null,display:u.display,tags:u.tags},onClose:t,children:[x(Yr,{children:s(`div`,{className:`flex flex-wrap items-center justify-between gap-2 pr-8`,children:[x(qi,{children:f}),x(HS,{})]})}),x(`div`,{className:`mt-3 flex items-center gap-1 rounded-md bg-surface-hover p-0.5 w-fit`,children:m.map(([e,t])=>x(`button`,{type:`button`,onClick:()=>i(e),className:`px-2.5 py-1 rounded text-[11px] font-medium transition-colors ${l===e?`bg-surface text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`}`,children:t},e))}),x(zi,{className:l===`detail`?`mt-3 overflow-hidden`:`mt-3`,children:s(va,{deviceId:e,device:u??void 0,children:[l===`detail`?x(`div`,{className:`h-full`,children:x(VS,{deviceId:e,device:u,name:f,onDrawn:o})}):null,s(`div`,{className:l===`info`?`flex flex-col gap-3`:`hidden`,children:[x(oy,{deviceId:e}),x(Ly,{})]}),x(`div`,{className:l===`export`?void 0:`hidden`,children:x(BS,{deviceId:e,sectionFilter:vS})})]})})]})})})}function WS({children:e}){let[t,n]=w(null),r=b(e=>n(e),[]),i=b(()=>n(null),[]);return s(vr,{open:r,children:[e,t===null?null:x(US,{deviceId:t,onClose:i})]})}O();function GS({tabs:e,active:t,onChange:n}){return x(`div`,{className:`flex rounded-lg border border-border bg-surface p-0.5 gap-0.5`,children:e.map(e=>x(G,{variant:`unstyled`,type:`button`,onClick:()=>n(e.id),className:[`flex-1 rounded-md px-3 py-1.5 text-xs font-medium transition-colors`,t===e.id?`bg-primary/12 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`].join(` `),children:e.label},e.id))})}function KS(e){let t=e.formats;if(!t)return``;let n=Object.values(t).filter(e=>e!==void 0&&e.sizeMB>0).map(e=>e.sizeMB);if(n.length===0)return``;let r=Math.min(...n),i=Math.max(...n);return r===i?`${r} MB`:`${r}-${i} MB`}function qS(e){return`${e.inputSize.width}x${e.inputSize.height}`}function JS(e){return e.formats?Object.keys(e.formats).filter(t=>e.formats[t]!==void 0):[]}function YS({entry:e,selected:t,onSelect:n,disabled:r}){let{t:i}=q(),a=KS(e),o=qS(e),c=JS(e);return s(G,{variant:`unstyled`,type:`button`,onClick:n,disabled:r,className:[`w-full text-left rounded-lg border p-3 transition-all`,t?`border-primary bg-primary/5 ring-1 ring-primary/30`:`border-border bg-background hover:border-foreground-subtle/40 hover:bg-surface-hover/50`,r?`opacity-50 cursor-not-allowed`:`cursor-pointer`].join(` `),children:[x(`div`,{className:`flex items-start justify-between gap-2`,children:s(`div`,{className:`flex-1 min-w-0`,children:[s(`div`,{className:`flex items-center gap-2`,children:[x(`span`,{className:`text-xs font-semibold text-foreground truncate`,children:e.name}),t&&x(mt,{className:`h-3.5 w-3.5 text-primary shrink-0`})]}),x(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 line-clamp-2`,children:e.description})]})}),s(`div`,{className:`flex items-center gap-3 mt-2 flex-wrap`,children:[s(`span`,{className:`inline-flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[x(Ze,{className:`h-3 w-3`}),o]}),a&&x(`span`,{className:`text-[10px] text-foreground-subtle`,children:a}),c.length>0&&x(`div`,{className:`flex gap-1`,children:c.map(e=>x(`span`,{className:`text-[9px] uppercase rounded bg-surface border border-border px-1 py-0.5 text-foreground-subtle font-mono`,children:e},e))}),e.labels.length>0&&x(`span`,{className:`text-[10px] text-foreground-subtle`,children:i(`common.labels`,{count:e.labels.length})})]})]})}function XS({field:e,value:t,onChange:n,disabled:r}){let{t:i}=q(),a=e.catalog??[],o=a.length>0,c=gn(a).length>0,l=e.allowCustomPath!==!1||e.allowCustom===!0,u=[...o?[{id:`catalog`,label:i(`formBuilder.modelSelector.models`,`Models ({{length}})`,{length:a.length})}]:[],...l?[{id:`custom`,label:i(`formBuilder.modelSelector.customPath`,`Custom Path`)}]:[]],[d,f]=w(o?`catalog`:`custom`),p=t==null?``:String(t);return s(`div`,{className:`space-y-3`,children:[u.length>1&&x(GS,{tabs:u,active:d,onChange:f}),d===`catalog`&&o&&c&&x(pi,{catalog:a,value:p,onChange:e=>n(e),disabled:r||e.disabled}),d===`catalog`&&o&&!c&&x(`div`,{className:`space-y-1.5 max-h-[320px] overflow-y-auto pr-1`,children:a.filter(e=>e.legacy!==!0).map(t=>x(YS,{entry:t,selected:p===t.id,onSelect:()=>n(t.id),disabled:r||e.disabled},t.id))}),d===`catalog`&&!o&&s(`div`,{className:`rounded-md border border-info/30 bg-info/5 px-3 py-2 flex items-start gap-2`,children:[x(lt,{className:`h-3.5 w-3.5 text-info shrink-0 mt-0.5`}),x(`p`,{className:`text-[11px] text-foreground-subtle leading-relaxed`,children:i(`formBuilder.modelSelector.noPredefinedModelsAvailableUse`,`No predefined models available. Use the Custom Path tab to specify a model file path or URL.`)})]}),d===`custom`&&l&&s(`div`,{className:`space-y-2`,children:[x(W,{type:`text`,className:`w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none disabled:opacity-50`,placeholder:i(`formBuilder.modelSelector.enterPathLikeDataModels`,`Enter path like /data/models/custom.onnx or https://...`),value:p,disabled:r||e.disabled,onChange:e=>n(e.target.value)}),e.acceptFormats&&e.acceptFormats.length>0&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:[i(`formBuilder.modelSelector.acceptedFormats`,`Accepted formats:`),` `,e.acceptFormats.join(`, `)]})]}),(e.compatibilityNote||e.conversionGuideUrl)&&s(`div`,{className:`flex items-start justify-between gap-3 pt-1`,children:[e.compatibilityNote&&s(`p`,{className:`flex items-start gap-1 text-[10px] text-foreground-subtle`,children:[x(lt,{className:`h-3 w-3 mt-0.5 shrink-0`}),e.compatibilityNote]}),e.conversionGuideUrl&&s(`a`,{href:e.conversionGuideUrl,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 text-[11px] text-primary hover:underline shrink-0`,children:[i(`formBuilder.modelSelector.howToConvertYourModel`,`How to convert your model`),x(wt,{className:`h-3 w-3`})]})]})]})}function ZS({to:e}){let{search:t}=Y();return x(X,{to:`${e}${t}`,replace:!0})}O();function QS(){return K.t(`helpers.keychainRevealHost.forbidden`)}function $S(e){if(typeof e!=`object`||!e)return null;let t=Reflect.get(e,`data`);if(typeof t!=`object`||!t)return null;let n=Reflect.get(t,`code`);return typeof n==`string`?n:null}function eC(e){let t=$S(e);if(t===`FORBIDDEN`||t===`UNAUTHORIZED`)return QS();let n=e instanceof Error?e.message:String(e);return n.length>0?K.t(`helpers.keychainRevealHost.failedWith`,{message:n}):K.t(`helpers.keychainRevealHost.failed`)}function tC({children:e}){let t=fo();return x(aa,{reveal:b(async e=>{try{return(await t.mutateAsync({ref:e})).value}catch(e){throw Error(eC(e))}},[t]),children:e})}O();function nC(){let e=V(),t=N(),[n,r]=w(()=>e.isConnected()?`connected`:`disconnected`),i=p(!1),[a,o]=w(0),[s,c]=w([]);S(()=>e.subscribeConnectionEvents(e=>{r(t=>(t!==`connected`&&e===`connected`&&i.current&&o(e=>e+1),e!==`connected`&&(i.current=!0),e))}),[e]),S(()=>{a!==0&&t.invalidateQueries({queryKey:[[`addons`,`getLastRestart`]]})},[a,t]);let{data:l}=ao(void 0,{enabled:n===`connected`&&a>0,staleTime:0,refetchOnMount:!1,refetchOnWindowFocus:!1}),u=p(null);return S(()=>{if(l==null||l.requestedAt===u.current)return;u.current=l.requestedAt;let e=iC(l);c(t=>[...t,e]);let t=window.setTimeout(()=>{c(t=>t.filter(t=>t.id!==e.id))},6e3);return()=>window.clearTimeout(t)},[l]),x(F,{children:s.length>0&&x(rC,{toasts:s})})}function rC({toasts:e}){return x(`div`,{className:`fixed top-[calc(env(safe-area-inset-top)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)] z-50 flex flex-col gap-2 max-w-sm w-full pointer-events-none`,children:e.map(e=>s(`div`,{className:`pointer-events-auto flex items-start gap-2 px-3 py-2.5 rounded-md border border-green-500/30 bg-green-500/10 shadow-lg`,children:[x(De,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),s(`div`,{children:[x(`div`,{className:`text-[11px] font-semibold text-foreground`,children:e.title}),x(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:e.message})]})]},e.id))})}function iC(e){let t=`restart-${e.requestedAt}`;if(e.kind===`framework-update`&&e.packageName!==void 0&&e.toVersion!==void 0){let n=e.fromVersion===void 0?`v${e.toVersion}`:`v${e.fromVersion} → v${e.toVersion}`;return{id:t,title:K.t(`system.reconnectOverlay.frameworkUpdated`,`Framework updated`),message:K.t(`system.reconnectOverlay.isNow`,`{{packageName}} is now {{fromTo}}.`,{packageName:e.packageName,fromTo:n})}}return{id:t,title:K.t(`system.reconnectOverlay.serverRestarted`,`Server restarted`),message:e.requestedBy===void 0?K.t(`system.reconnectOverlay.manualRestartCompleted`,`Manual restart completed.`):K.t(`system.reconnectOverlay.manualRestartByCompleted`,`Manual restart by {{requestedBy}} completed.`,{requestedBy:e.requestedBy})}}var aC=`/system/settings`,oC=[{path:`/system/capabilities`,tab:`capabilities`},{path:`/system/api-explorer`,tab:`api-explorer`}];function sC(e,t=``){let n=new URLSearchParams(t);return n.delete(`tab`),n.set(`tab`,e),`${aC}?${n.toString()}`}var cC=`/system/data`,lC=`/system/secrets`;function uC(e=``){let t=new URLSearchParams(e),n=t.get(`view`);return t.delete(`view`),t.set(`tab`,`secrets`),n===`audit`&&t.set(`secretsView`,`audit`),`${cC}?${t.toString()}`}function dC({tab:e}){let{search:t,hash:n}=Y();return x(X,{to:`${sC(e,t)}${n}`,replace:!0})}function fC(){let{search:e,hash:t}=Y();return x(X,{to:`${uC(e)}${t}`,replace:!0})}O();var pC={info:{bg:`bg-info/10`,border:`border-info/30`,icon:lt},warning:{bg:`bg-warning/10`,border:`border-warning/30`,icon:Ne},critical:{bg:`bg-danger/10`,border:`border-danger/30`,icon:te}};function mC({toast:e,onDismiss:t}){let n=pC[e.severity]??pC.info,r=n.icon;return S(()=>{let n=e.duration??5e3;if(n<=0)return;let r=setTimeout(()=>t(e.id),n);return()=>clearTimeout(r)},[e.id,e.duration,t]),x(`div`,{className:`rounded-lg bg-surface shadow-lg animate-in slide-in-from-right-5 fade-in duration-200`,children:s(`div`,{className:`flex items-start gap-3 px-4 py-3 rounded-lg border ${n.border} ${n.bg}`,children:[x(r,{className:`h-4 w-4 shrink-0 mt-0.5 text-foreground-subtle`}),s(`div`,{className:`flex-1 min-w-0`,children:[x(`div`,{className:`text-xs font-semibold text-foreground`,children:e.title}),x(`div`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:e.message})]}),x(G,{variant:`unstyled`,type:`button`,onClick:()=>t(e.id),className:`shrink-0 p-0.5 rounded hover:bg-surface-hover transition-colors`,children:x(xe,{className:`h-3.5 w-3.5 text-foreground-subtle`})})]})})}function hC(){let[e,t]=w([]),n=b(e=>{t(t=>t.filter(t=>t.id!==e))},[]),r=b(e=>{let n=`toast-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;t(t=>[...t,{...e,id:n,timestamp:Date.now()}])},[]);return wi(void 0,{onData:e=>r(e)}),S(()=>mg(r),[r]),e.length===0?null:x(`div`,{className:`fixed bottom-[calc(env(safe-area-inset-bottom)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)] z-50 flex flex-col gap-2 max-w-sm w-full pointer-events-none`,children:e.map(e=>x(`div`,{className:`pointer-events-auto`,children:x(mC,{toast:e,onDismiss:n})},e.id))})}O();function gC({children:e}){let{t}=q();return x(dt,{t:m(()=>ox(t),[t]),children:e})}O();function _C(e){if(typeof e!=`object`||!e)return;let{data:t}=e;return t?.code}function vC(e,t){let n=_C(e);return n===`UNAUTHORIZED`||n===`FORBIDDEN`?!0:/UNAUTHORIZED|FORBIDDEN/.test(t)}function yC(e,t,n,r){let[i,a]=w(!1),[o,s]=w(null);return S(()=>{if(a(!1),s(null),!t){a(!0);return}let i=!1;e.init().catch(()=>void 0);let o=t=>{e.awaitConnected().then(()=>{i||a(!0)},e=>{if(i)return;let c=e instanceof Error?e.message:String(e);if(vC(e,c)){if(t&&r!==void 0){r().then(e=>{if(!i){if(e){o(!1);return}console.warn(`[boot-gate] logout: probe UNAUTHORIZED and the refresh was refused`),n()}},()=>{i||(console.warn(`[boot-gate] logout: probe UNAUTHORIZED and recovery failed`),n())});return}console.warn(`[boot-gate] logout: probe UNAUTHORIZED after a successful refresh`,c),n();return}s(c),a(!0)})};return o(!0),()=>{i=!0}},[e,t,n,r]),{bootReady:i,bootError:o}}O();var bC=3e4;function xC(e){let t=p(e);t.current=e,S(()=>{let e=null,n=()=>{if(document.visibilityState===`hidden`){e=Date.now();return}if(document.visibilityState===`visible`&&e!==null){let n=Date.now()-e;e=null,n>=bC&&t.current()}},r=()=>{t.current()},i=e=>{e.persisted&&t.current()};return document.addEventListener(`visibilitychange`,n),window.addEventListener(`online`,r),window.addEventListener(`pageshow`,i),()=>{document.removeEventListener(`visibilitychange`,n),window.removeEventListener(`online`,r),window.removeEventListener(`pageshow`,i)}},[])}var SC=`@camstack/ui-library`;function CC(e){return typeof e==`object`&&!!e}var wC=/^>=\s*(\d+)\.(\d+)\.(\d+)/,TC=/^(\d+)\.(\d+)\.(\d+)/;function EC(e){return e===null?null:[Number(e[1]),Number(e[2]),Number(e[3])]}function DC(e,t){for(let n=0;n<3;n++){let r=e[n]??0,i=t[n]??0;if(r!==i)return r<i}return!1}function OC(e,t){let n=[];for(let r of Object.values(e)){let e=r[SC];if(!(typeof e!=`object`||!e))for(let r of Object.values(e)){if(!CC(r)||r.from!==t)continue;let e=r.shareConfig?.requiredVersion;typeof e==`string`&&n.push(e)}}return n}function kC(e,t){let n=e===null?null:EC(e.match(TC));if(n===null||e===null)return null;for(let r of t){let t=EC(r.match(wC));if(t!==null&&DC(n,t))return{required:t.join(`.`),host:e}}return null}O();function AC(){let{t:e}=q();return s(`div`,{role:`status`,"aria-busy":`true`,"aria-label":e(`layouts.addonPageLoader.loading`,`Loading page`),"data-testid":`addon-page-loading`,className:`flex flex-col gap-4 p-2 sm:p-4`,children:[x(yr,{className:`h-7 w-48`}),x(yr,{className:`h-5 w-72 max-w-full`}),x(yr,{className:`h-40`})]})}function jC({message:e}){let{t}=q();return x(`div`,{className:`p-2 sm:p-4`,"data-testid":`addon-page-error`,children:x(Or,{title:t(`layouts.addonPageLoader.failedTitle`,`This page could not be shown`),message:e})})}var MC=class extends l{state={error:null,resetKey:this.props.resetKey};static getDerivedStateFromError(e){return{error:e instanceof Error?e:Error(String(e))}}static getDerivedStateFromProps(e,t){return e.resetKey===t.resetKey?null:{error:null,resetKey:e.resetKey}}componentDidCatch(e,t){console.error(`[addon-page] ${this.props.resetKey} crashed`,e,t.componentStack)}render(){return this.state.error===null?this.props.children:x(jC,{message:this.state.error.message})}};function NC({resetKey:e,children:t}){return x(MC,{resetKey:e,children:t})}function PC({pageKey:e,children:t}){return x(MC,{resetKey:e,children:x(y,{fallback:x(AC,{}),children:t})})}O();function FC(e){let t=new Set,n=new Set,r=e=>e.page.remoteName.includes(e.addonId.replace(/[^a-zA-Z0-9]+/g,`_`)),i=[...e.filter(r),...e.filter(e=>!r(e))],a=[];for(let e of i){let r=`${e.addonId}::${e.page.id}`;t.has(r)||n.has(e.page.path)||(t.add(r),n.add(e.page.path),a.push({id:e.page.id,addonId:e.addonId,label:e.page.label,icon:e.page.icon,path:e.page.path,remoteName:e.page.remoteName,bundle:e.page.bundle,bundleUrl:e.bundleUrl,...e.page.section===void 0?{}:{section:e.page.section},...e.page.sectionLabel===void 0?{}:{sectionLabel:e.page.sectionLabel}}))}return a}var IC=2e4;function LC(e,t){let[n,r]=w(!1);return S(()=>{if(!e){r(!1);return}let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}var RC=new Map,zC=new Map,BC=new Set;function VC(e){return!e||typeof e!=`object`?!1:typeof e.default==`function`}var HC=class extends Error{problem;constructor(e){super(`ui-library ${e.host} is older than the ${e.required} this page requires`),this.problem=e}};function UC(e){let t=i()?.shareScopeMap;if(!t)return;let n=kC(Va,OC(t,e));if(n!==null)throw new HC(n)}async function WC(e,t){let i=RC.get(e);if(i)return i;let a=zC.get(e);if(a)return a;BC.has(e)||(xa(),r([{name:e,entry:B(t),type:`module`}],{force:!1}),BC.add(e));let o=n(`${e}/page`).then(n=>{if(UC(e),!VC(n))throw Error(`Addon page remote ${e} (${t}) does not expose a default React component on './page'`);return RC.set(e,n.default),zC.delete(e),n.default}).catch(t=>{throw zC.delete(e),UC(e),t});return zC.set(e,o),o}function GC(){let{t:e}=q(),{pagePath:t}=pl(),n=ll(),r=V(),{data:i,isError:a,error:o}=Ji(void 0),s=m(()=>i?FC(i):void 0,[i]),c=s?.find(e=>e.path===`/addon/${t}`),l=c?.remoteName,u=c?.bundleUrl,[d,f]=w(null),[p,h]=w(null);S(()=>{if(!l||!u)return;h(null);let t=RC.get(l);if(t){f(()=>t);return}f(null);let n=!1;return WC(l,u).then(e=>{n||f(()=>e)}).catch(t=>{n||h(t instanceof HC?e(`layouts.addonPageLoader.hostTooOld`,{defaultValue:`This page needs a newer admin UI (UI library {{required}} or later; this one has {{host}}). Update admin-ui.`,required:t.problem.required,host:t.problem.host}):t instanceof Error?t.message:String(t))}),()=>{n=!0}},[l,u]);let g=LC(!s&&!a,IC),_=LC(c!==void 0&&!d&&!p,IC);return s?c?p?x(jC,{message:p}):d?x(PC,{pageKey:c.remoteName,children:x(d,{trpc:r.trpcClient,theme:{isDark:document.documentElement.classList.contains(`dark`)},navigate:e=>{n(e.startsWith(`/`)?e:`/${e}`)}})}):_?x(jC,{message:e(`layouts.addonPageLoader.remoteStalled`,`The page did not load. Its addon may be starting or unreachable.`)}):x(AC,{}):x(`div`,{className:`flex items-center justify-center h-full text-foreground-subtle`,children:e(`layouts.addonPageLoader.addonPageNotFound`,`Addon page not found`)}):a?x(jC,{message:o?.message??e(`layouts.addonPageLoader.listFailed`,`The page list could not be loaded.`)}):g?x(jC,{message:e(`layouts.addonPageLoader.listStalled`,`The hub did not send the page list. Try again in a moment.`)}):x(AC,{})}var KC={"/system/pipeline":`pipeline-orchestrator`,"/system/history":`device-history`,"/system/ai":`llm`};function qC(e,t){return e.filter(e=>!e.adminOnly||t).map(e=>{let t=KC[e.path];return t===void 0?e:{...e,requiresCapability:t}})}function JC({t:e,isAdmin:t}){let n=qC([{label:e(`nav.devices`,`Devices`),icon:Ke,path:`/devices`},{label:e(`nav.integrations`),icon:ft,path:`/integrations`},{label:e(`nav.build`,`Build-your-self`),icon:ut,path:`/build`,adminOnly:!0},{label:e(`nav.locations`,`Locations`),icon:me,path:`/locations`,adminOnly:!0},{label:e(`nav.viewer`,`Viewer`),icon:ie,path:`/live`}],t),r=qC([{label:e(`nav.library`,`Library`),icon:mr,path:`/library`,adminOnly:!0,keywords:[`People`,`Vehicles`,`Events`,`Scenes`,`plates`,`faces`,`detection-intelligence`]},{label:e(`nav.archive`,`Archive`),icon:er,path:`/archive`,adminOnly:!0}],t),i=qC([{label:e(`nav.nodes`,`Nodes`),icon:Ie,path:`/system/nodes`,adminOnly:!0},{label:e(`nav.history`,`History`),icon:Be,path:`/system/history`,adminOnly:!0,keywords:[`charts`,`graphs`,`energy`,`temperature`,`metrics`,`trends`]},{label:e(`nav.pipeline`,`Pipeline`),icon:rr,path:`/system/pipeline`},{label:e(`system.addons`),icon:Ge,path:`/system/addons`,adminOnly:!0},{label:e(`system.ai`,`AI`),icon:Tt,path:`/system/ai`,adminOnly:!0}],t),a=qC([{label:e(`system.identity`,`Identity & Access`),icon:ue,path:`/system/identity`,adminOnly:!0},{label:e(`system.network`,`Network`),icon:gr,path:`/system/network`,adminOnly:!0},{label:e(`system.integrations`,`Connectivity`),icon:ft,path:`/system/integrations`,adminOnly:!0},{label:e(`system.data`,`Data`),icon:et,path:`/system/data`,adminOnly:!0},{label:e(`system.notifications`,`Notifications`),icon:se,path:`/system/notifications`,adminOnly:!0},{label:e(`system.calendars`,`Calendars`),icon:st,path:`/system/calendars`,adminOnly:!0},{label:e(`system.systemNav`,`System`),icon:le,path:aC,adminOnly:!0},{label:e(`system.logs`,`Logs`),icon:Ce,path:`/system/logs`,adminOnly:!0},{label:e(`system.terminal`,`Terminal`),icon:hr,path:`/system/terminal`,adminOnly:!0}],t);return[{key:`top`,label:null,items:n},{key:`detection`,label:e(`nav.detectionSection`,`Detection`),items:r},{key:`cluster`,label:e(`nav.clusterSection`,`Cluster`),items:i},{key:`administration`,label:e(`system.title`,`Administration`),items:a}]}var YC={gauge:Ve,puzzle:Ge,bot:xt,cpu:Ze,terminal:hr,box:ze,boxes:ze,monitor:ie,wrench:R,activity:he,plug:ft,"graduation-cap":ht};function XC(e){return YC[e]??Ge}function ZC(e,t){for(let n of JC(t))for(let t of n.items)if(t.path===e)return{icon:t.icon,title:t.label,path:t.path};return null}var QC=`/system/addons`;function $C({path:e,children:t}){let n=KC[e];return n===void 0?x(F,{children:t}):x(ew,{path:e,capability:n,children:t})}function ew({path:e,capability:t,children:n}){let{t:r}=q(),i=ll(),a=Ui(t);if(a===`present`)return x(F,{children:n});if(a===`pending`)return s(`div`,{className:`flex flex-col gap-4 p-2 sm:p-4`,"data-testid":`page-presence-pending`,children:[x(yr,{className:`h-7 w-48`}),x(yr,{className:`h-40`})]});if(a===`unknown`)return x(`div`,{className:`p-2 sm:p-4`,"data-testid":`page-presence-unknown`,children:x(Or,{title:r(`pageRequires.unknownTitle`,`Could not check whether this page is available`),message:r(`pageRequires.unknown`,`The hub did not answer the capability check. Reload the page to try again.`)})});let o=ZC(e,{t:r,isAdmin:!0});return x(`div`,{className:`p-2 sm:p-4`,"data-testid":`page-not-installed`,children:x(La,{icon:o?.icon??Ge,title:r(`pageRequires.absentTitle`,`{{page}} is not installed`,{page:o?.title??e}),description:r(`pageRequires.absentDescription`,`The addon that provides this page is not installed. Install it from System → Addons.`),action:x(G,{variant:`primary`,onClick:()=>i(QC),children:r(`pageRequires.openAddons`,`Open Addons`)})})})}function tw({capability:e,children:t}){return x(F,{children:t(Ui(e)===`absent`)})}function nw({children:e}){return x(Ai,{value:rw(si({})),children:e})}function rw(e){return e.data===void 0?e.isPending?{status:`pending`}:{status:`unknown`,reason:e.isError?String(e.error):`no palette`}:e.data.status===`unknown`?{status:`unknown`,reason:e.data.reason}:{status:`ready`,palette:e.data}}function iw(){let e=po(),{t}=q();return e.status===`unknown`?x(`p`,{role:`status`,className:`shrink-0 px-4 py-1 text-xs text-warning`,children:t(`pipeline.palette.unknown`,`The stored palette cannot be read ({{reason}}). Boxes use the bundled CamStack preset.`,{reason:e.reason})}):null}var aw=[`device`,`page`,`automation`,`script`,`scheduler`,`action`,`template`,`customDevice`,`integration`];function ow(e,t,n=200){if(Pn(t).length===0)return{groups:[],totalMatched:0,truncated:!1};let r=new Map;for(let n of e){let e=Vn(t,{label:n.label,keywords:n.keywords,identifiers:n.identifiers});if(e===null)continue;let i=r.get(n.domain)??[];i.push({item:n,rank:e}),r.set(n.domain,i)}let i=0;for(let e of r.values())i+=e.length;let a=n,o=[];for(let e of aw){let t=r.get(e);if(!t||t.length===0||a<=0)continue;t.sort((e,t)=>e.rank-t.rank||e.item.label.localeCompare(t.item.label));let n=t.slice(0,a).map(e=>e.item);a-=n.length,o.push({domain:e,items:n})}return{groups:o,totalMatched:i,truncated:i>n}}function sw(e){return e.flatMap(e=>e.items)}var cw=` · `;function lw(e,t,n,r){let i=[`#${t}`];return r!==void 0&&i.push(r),e.stableId.length>0&&e.stableId!==n&&i.push(e.stableId),i.push(e.type),e.disabled&&i.push(`disabled`),i.join(cw)}function uw(e,t=null){let n=gi(e),r=bo(K.language.startsWith(`it`)?`it`:`en`),i=Pi(e),a=_o(t);return e.map(e=>{let t=String(e.id),o=Mr(e,`compact`,i,r),s=o.length>0?o:e.stableId||`#${t}`,c=n.get(e.id),l=c!==void 0&&(s===c||s.split(cw).includes(c)),u=a(e),d=u.kind===`resolved`?u.integration.name:``;return{key:`device:${t}`,domain:`device`,label:s,subtitle:lw(e,t,s,l?void 0:c),identifiers:[t,`#${t}`],keywords:[...e.name.length>0&&e.name!==s?[e.name]:[],e.stableId,e.addonId,e.location??``,c??``,d].filter(e=>e.length>0),path:`/devices/${t}`,icon:xi(e)}})}function dw(e){return e.map(e=>({key:`integration:${e.id}`,domain:`integration`,label:e.name||e.addonId,subtitle:e.enabled?e.addonId:K.t(`helpers.searchItems.disabled`,{addonId:e.addonId}),keywords:[e.addonId,e.processState],path:K_(e.addonId,e.id)}))}function fw(e,t,n){let r=e.section?.trim();return r?t[r]??e.sectionLabel?.trim()??r:n}function pw(e,t,n){let r=e.flatMap(e=>e.items.map(t=>({key:`page:${t.path}`,domain:`page`,label:t.label,subtitle:e.label??void 0,path:t.path,icon:t.icon,...t.keywords!==void 0&&t.keywords.length>0?{keywords:t.keywords}:{}}))),i={detection:n.detection,cluster:n.cluster,administration:n.administration},a=t.map(e=>({key:`page:addon:${e.addonId}:${e.id}`,domain:`page`,label:e.label,subtitle:fw(e,i,n.ungrouped),keywords:[e.addonId],path:e.path,icon:XC(e.icon)}));return[...r,...a]}var mw=`edit`;function hw(e){return`/build?tab=templates&${mw}=${encodeURIComponent(e)}`}var gw=`const AUTOMATION_RECIPE =`,_w=`// EJECTED from the visual automation editor — this file is now hand-owned.
|
|
5
5
|
// The recipe that produced it was removed with it, on purpose: while it was
|
|
6
|
-
// here the editor could re-open this block and overwrite everything below.`;function vw(e){return e.includes(gw)}function yw(e){return!vw(e.code)}function bw(e){let t=e.indexOf(gw);if(t<0)return null;let n=e.indexOf(`{`,t+25);if(n<0)return null;let r=0,i=!1,a=!1;for(let o=n;o<e.length;o+=1){let s=e.charAt(o);if(i){a?a=!1:s===`\\`?a=!0:s===`"`&&(i=!1);continue}if(s===`"`){i=!0;continue}if(s===`{`)r+=1;else if(s===`}`&&(--r,r===0))return{declStart:t,literalEnd:o+1,json:e.slice(n,o+1)}}return null}function xw(e){let t=bw(e);if(t===null)return{ok:!1,reason:K.t(`helpers.recipeFromCode.noLiteral`)};let n;try{n=JSON.parse(t.json)}catch(e){let t=e instanceof Error?e.message:String(e);return{ok:!1,reason:K.t(`helpers.recipeFromCode.badJson`,{detail:t})}}let r=Et.safeParse(n);if(!r.success){let e=r.error.issues[0];return{ok:!1,reason:e===void 0?K.t(`helpers.recipeFromCode.schemaMismatch`):K.t(`helpers.recipeFromCode.schemaMismatchAt`,{path:e.path.join(`.`),message:e.message})}}return{ok:!0,recipe:r.data}}function Sw(e){let t=bw(e);if(t===null)return e;let n=e.slice(t.literalEnd),r=/^\s*as\s+const/.exec(n),i=t.literalEnd+(r===null?0:r[0].length);return`${e.slice(0,t.declStart)}${_w}${e.slice(i)}`}function Cw(e,t,n){return`/build?tab=${e}&${t}=${encodeURIComponent(n)}`}function ww(e){return e??[]}function Tw(e){let t=[];for(let n of e.blocks??[])vw(n.code)?t.push({key:`automation:${n.id}`,domain:`automation`,label:n.name,keywords:ww(n.tags),path:Cw(`automations`,`block`,n.id)}):En(n)===`code`&&yw(n)&&t.push({key:`script:${n.id}`,domain:`script`,label:n.name,keywords:ww(n.tags),path:Cw(`scripts`,`block`,n.id)});for(let n of e.schedulers??[])t.push({key:`scheduler:${n.id}`,domain:`scheduler`,label:n.name,keywords:ww(n.tags),path:Cw(`schedulers`,`scheduler`,n.id)});for(let n of e.actions??[])t.push({key:`action:${n.id}`,domain:`action`,label:n.name,keywords:ww(n.tags),path:Cw(`actions`,`action`,n.id)});for(let n of e.templates??[])t.push({key:`template:${n.id}`,domain:`template`,label:n.name,subtitle:n.kind,keywords:ww(n.tags),path:hw(n.id)});for(let n of e.compositions??[])t.push({key:`customDevice:${n.block.id}`,domain:`customDevice`,label:n.block.name,keywords:ww(n.block.tags),path:gy(n.block.id)});return t}O();var Ew={device:{labelKey:`search.resultsList.devices`,icon:Ke},page:{labelKey:`search.resultsList.pages`,icon:fr},integration:{labelKey:`search.resultsList.integrations`,icon:ft},automation:{labelKey:`search.resultsList.automations`,icon:oe},script:{labelKey:`search.resultsList.scripts`,icon:lr},scheduler:{labelKey:`search.resultsList.schedulers`,icon:rt},action:{labelKey:`search.resultsList.actions`,icon:we},template:{labelKey:`search.resultsList.templates`,icon:nr},customDevice:{labelKey:`search.resultsList.customDevices`,icon:Ct}};function Dw({groups:e,activeKey:t,query:n,totalMatched:r,truncated:i,pending:a=!1,onSelect:o,onHover:c}){let{t:l}=q(),u=p(null);if(S(()=>{t&&(u.current?.querySelector(`[data-key="${CSS.escape(t)}"]`))?.scrollIntoView({block:`nearest`})},[t]),n.trim().length===0)return null;if(e.length===0&&a)return x(`div`,{role:`status`,className:`px-3 py-4 text-center text-[12px] text-foreground-subtle`,"data-testid":`search-pending`,children:l(`search.resultsList.searching`,`Searching…`)});if(e.length===0)return x(`div`,{className:`px-3 py-4 text-center text-[12px] text-foreground-subtle`,children:l(`search.resultsList.noResults`,{query:n})});let d=e.reduce((e,t)=>e+t.items.length,0);return s(F,{children:[x(`div`,{ref:u,role:`listbox`,className:`max-h-[60vh] overflow-y-auto py-1`,children:e.map(e=>{let n=Ew[e.domain],r=n.icon;return s(`div`,{className:`px-1 py-1`,children:[s(`div`,{className:`sticky top-0 z-10 flex items-center gap-1.5 bg-surface px-2 py-1 text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/60`,children:[x(r,{className:`h-3 w-3`}),l(n.labelKey)]}),e.items.map(e=>{let r=e.icon??n.icon,i=e.key===t;return s(G,{variant:`unstyled`,type:`button`,role:`option`,"aria-selected":i,"data-key":e.key,onMouseEnter:()=>c(e),onClick:()=>o(e),className:`flex w-full items-center gap-2.5 rounded-md px-2 py-1.5 text-left text-[12px] transition-colors ${i?`bg-primary/12 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[x(r,{className:`h-3.5 w-3.5 shrink-0 ${i?`text-primary`:`text-foreground-subtle`}`}),s(`span`,{className:`flex-1 min-w-0`,children:[x(`span`,{className:`block truncate font-medium`,children:e.label}),e.subtitle&&x(`span`,{className:`block truncate text-[10px] text-foreground-subtle`,children:e.subtitle})]})]},e.key)})]},e.domain)})}),i&&x(`div`,{className:`border-t border-border px-3 py-1.5 text-center text-[10px] text-foreground-subtle`,children:l(`search.truncatedResults`,`Showing first {{shown}} of {{total}} — refine your search.`,{shown:d,total:r})})]})}O(),wo();function Ow({navSections:e,addonPages:t,compact:n,onNavigated:r}){let{t:i}=q(),a=ll(),o=p(null),c=p(null),l=p(null),[u,d]=w(null),[f,h]=w(``),[g,_]=w(0),[v,y]=w(!1),{data:C}=Zi({projection:`slim`}),{data:T}=za(void 0),E=v&&f.trim().length>0,D={enabled:E},O=Ba({},D),k=Za({},D),A=na({},D),j=Rr({},D),M=da({},D),N=E&&[O,k,A,j,M].some(e=>e.isLoading),ee=m(()=>{let n={detection:i(`nav.detectionSection`,`Detection`),cluster:i(`nav.clusterSection`,`Cluster`),administration:i(`system.title`,`Administration`),ungrouped:i(`nav.addonPages`,`Addon Pages`)};return[...uw(C??[],T??null),...pw(e,t,n),...dw(T??[]),...Tw({blocks:O.data?.blocks,actions:k.data,schedulers:A.data,templates:j.data,compositions:M.data?.state===`loaded`?M.data.views:void 0})]},[C,T,e,t,i,O.data,k.data,A.data,j.data,M.data]),{groups:P,totalMatched:F,truncated:I}=m(()=>ow(ee,f),[ee,f]),L=m(()=>sw(P),[P]);S(()=>{_(0)},[f,ee]),S(()=>{v&&o.current?.focus()},[v]);let te=b(()=>{y(!1),h(``),_(0)},[]),re=b(e=>{a(e.path),te(),o.current?.blur(),r?.()},[a,te,r]);Fr(o,{scope:Gr}),S(()=>{if(!v)return;function e(e){if(!(e.target instanceof Node))return;let t=c.current?.contains(e.target)===!0,n=l.current?.contains(e.target)===!0;!t&&!n&&y(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[v]);let ie=v&&f.trim().length>0;S(()=>{if(!ie){d(null);return}let e=()=>{let e=o.current?.getBoundingClientRect();e&&d({left:e.left,top:e.bottom+4,width:e.width})};return e(),window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},[ie]);let ae=L[g]?.key??null,oe=i(`search.placeholder`,`Search devices, pages, automations, scripts…`),se=s(`div`,{className:`relative`,children:[x(ne,{className:`pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`}),x(W,{ref:o,type:`text`,value:f,placeholder:oe,"aria-label":oe,role:`combobox`,"aria-expanded":v&&f.trim().length>0,"aria-controls":`global-search-results`,onChange:e=>{h(e.target.value),y(!0)},onFocus:()=>y(!0),onKeyDown:e=>{if(e.key===`ArrowDown`)e.preventDefault(),L.length>0&&_(e=>(e+1)%L.length);else if(e.key===`ArrowUp`)e.preventDefault(),L.length>0&&_(e=>(e-1+L.length)%L.length);else if(e.key===`Enter`){e.preventDefault();let t=L[g];t&&re(t)}else e.key===`Escape`&&(e.preventDefault(),te(),o.current?.blur())},className:`w-full rounded-md border border-border bg-surface py-1.5 pl-7 pr-6 text-[12px] text-foreground placeholder:text-foreground-subtle/70 focus:outline-none focus:ring-1 focus:ring-primary/50`}),f.length>0&&x(G,{variant:`unstyled`,type:`button`,"aria-label":i(`search.globalSearch.clearSearch`,`Clear search`),onClick:()=>{h(``),o.current?.focus()},className:`absolute right-1.5 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground`,children:x(xe,{className:`h-3 w-3`})}),ie&&u!==null&&To(x(`div`,{ref:l,id:`global-search-results`,className:`fixed z-50 w-max max-w-[26rem] rounded-lg border border-border bg-surface shadow-xl`,style:{left:u.left,top:u.top,minWidth:u.width},children:x(Dw,{groups:P,activeKey:ae,query:f,totalMatched:F,truncated:I,pending:N,onSelect:re,onHover:e=>{let t=L.findIndex(t=>t.key===e.key);t>=0&&_(t)}})}),document.body)]});return n?x(`div`,{ref:c,className:`px-1.5 pb-1.5`,children:v?x(`div`,{className:`fixed z-50 w-max min-w-72 max-w-[26rem]`,style:{left:`calc(env(safe-area-inset-left) + 3.5rem)`,top:`calc(env(safe-area-inset-top) + 3.5rem)`},children:se}):x(G,{variant:`unstyled`,type:`button`,onClick:()=>y(!0),"aria-label":oe,title:oe,className:`flex w-full items-center justify-center rounded-md px-0 py-2 text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,children:x(ne,{className:`h-3.5 w-3.5 shrink-0`})})}):x(`div`,{ref:c,className:`px-2 pb-2`,children:se})}var kw=/^(\d{1,3}\.){3}\d{1,3}$/;function Aw(e){let t=e.startsWith(`[`)&&e.endsWith(`]`)?e.slice(1,-1):e;return!!(kw.test(t)||t.includes(`:`))}function jw(e,t){return!t||Aw(e)?!1:e===t||e.endsWith(`.${t}`)}O();var Mw=`auth-webauthn/passkey-enrollment`,Nw=`camstack_passkey_prompt_dismissed:`,Pw=720*60*60*1e3;function Fw(e){try{let t=localStorage.getItem(`${Nw}${e}`);if(!t)return!1;let n=Number(t);return Number.isFinite(n)?Date.now()-n<Pw:!1}catch{return!1}}function Iw(e){try{localStorage.setItem(`${Nw}${e}`,String(Date.now()))}catch{}}function Lw(){let{user:e}=ax(),{t}=q(),n=V(),r=Ha(Mw),[i,a]=w(!1),[o,c]=w(!1),l=m(()=>e?Fw(e.id):!0,[e]),u=Ka.auth.listLoginMethods.useQuery().data?.find(e=>e.kind===`passkey`),d=u!==void 0&&jw(window.location.hostname,u.rpId),f=e!==null&&d&&r!=null&&!l,p=E({queryKey:[`auth`,`listOwnPasskeys`],queryFn:()=>n.listOwnPasskeys(),enabled:f,staleTime:6e4}),h=b(()=>{e&&Iw(e.id),a(!0),c(!1)},[e]),g=b(()=>{c(!1),p.refetch()},[p]);return!f||i||p.data===void 0||p.data.length>0?null:s(`div`,{className:`shrink-0 border-b border-primary/20 bg-primary/5`,children:[s(`div`,{className:`flex items-center gap-2.5 px-3 py-2 text-xs text-foreground`,children:[x(ir,{className:`h-4 w-4 text-primary shrink-0`}),x(`span`,{className:`flex-1 min-w-0`,children:t(`passkeyPrompt.message`,`Save a passkey for faster sign-in?`)}),x(G,{variant:`unstyled`,onClick:()=>c(e=>!e),className:`rounded bg-primary px-2.5 py-1 text-[11px] font-semibold text-primary-foreground hover:bg-primary/90`,children:t(`passkeyPrompt.enrollNow`,`Enroll now`)}),x(G,{variant:`unstyled`,onClick:h,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,children:t(`passkeyPrompt.notNow`,`Not now`)}),x(G,{variant:`unstyled`,onClick:h,"aria-label":t(`passkeyPrompt.notNow`,`Not now`),className:`p-1 rounded text-foreground-subtle hover:text-foreground`,children:x(xe,{className:`h-3.5 w-3.5`})})]}),o&&x(`div`,{className:`px-3 pb-3`,children:s(`div`,{className:`max-w-xl`,children:[x(Ii,{widgetId:Mw,host:`dashboard`}),x(`div`,{className:`mt-2 flex justify-end`,children:x(G,{variant:`unstyled`,onClick:g,className:`rounded border border-border px-2.5 py-1 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,children:t(`common.close`,`Close`)})})]})})]})}var Rw=`system-config`,zw=[`system-config`,`bootstrap-form`];function Bw(e){return typeof e==`object`&&!!e&&`sections`in e&&Array.isArray(e.sections)}function Vw(){let e=V();return E({queryKey:zw,queryFn:async()=>{let t=await e.trpcClient.addons.custom.mutate({addonId:Rw,action:`getBootstrapForm`,input:{}});if(!Bw(t))throw Error(`The hub did not return the settings form`);return t}})}function Hw(){let e=V(),t=N(),n=ee({mutationFn:async t=>{await e.trpcClient.addons.custom.mutate({addonId:Rw,action:`saveBootstrapForm`,input:t})},onSuccess:()=>Promise.all([t.invalidateQueries({queryKey:zw}),t.invalidateQueries({queryKey:[[`system`,`info`]]})])});return{mutateAsync:n.mutateAsync,isPending:n.isPending}}var Uw=6e4;function Ww(){let e=Ur(void 0,{staleTime:Uw});return{info:e.data?.serverName??null,isLoading:e.isLoading}}O();var Gw=`camstack_server_name_prompt_dismissed`;function Kw(){try{return sessionStorage.getItem(Gw)===`1`}catch{return!1}}function qw(){try{sessionStorage.setItem(Gw,`1`)}catch{}}function Jw(e){return e.isAdmin&&e.info!==null&&e.info.isDefault&&!e.dismissed}function Yw(){let{user:e}=ax(),{info:t}=Ww(),[n,r]=w(Kw);return Jw({isAdmin:e?.isAdmin===!0,info:t,dismissed:n})?x(Xw,{suggestion:t?.name??``,onLater:()=>{qw(),r(!0)}}):null}function Xw({suggestion:e,onLater:t}){let{t:n}=q(),r=N(),i=Hw(),[a,o]=w(e),[c,l]=w(null),u=p(null);S(()=>u.current?.focus(),[]);let d=b(async()=>{let e=cn.safeParse(a);if(!e.success){l(e.error.issues[0]?.message??n(`serverName.invalid`,`Not a valid name`));return}l(null);try{await i.mutateAsync({patch:{name:e.data}}),await r.invalidateQueries({queryKey:[[`system`,`info`]]})}catch(e){l(e instanceof Error&&e.message.length>0?e.message:`Could not save`)}},[r,i,n,a]);return x(Mi,{open:!0,onOpenChange:e=>!e&&t(),children:x(Ir,{children:s(`form`,{onSubmit:e=>{e.preventDefault(),i.isPending||d()},children:[s(Yr,{children:[x(qi,{children:n(`serverName.title`,`Name this server`)}),x($r,{children:n(`serverName.description`,`Pick a name for this hub. It shows in the admin UI and on the apps’ sign-in screen. You can change it later in System settings.`)})]}),x(zi,{children:x(co,{label:n(`serverName.label`,`Server name`),...c===null?{}:{error:c},children:x(W,{ref:u,value:a,maxLength:48,onChange:e=>o(e.target.value),state:c===null?`default`:`error`,"aria-label":n(`serverName.label`,`Server name`)})})}),s(Qa,{children:[x(G,{type:`button`,variant:`ghost`,onClick:t,disabled:i.isPending,children:n(`serverName.later`,`Later`)}),s(G,{type:`submit`,disabled:i.isPending||a.trim().length===0,children:[i.isPending&&x(H,{className:`h-4 w-4 animate-spin`}),n(`common.save`,`Save`)]})]})]})})})}var Zw=4,Qw=160,$w=320,eT=`env(safe-area-inset-top)`,tT=`env(safe-area-inset-bottom)`;function nT(e){let{rect:t,viewportWidth:n,viewportHeight:r}=e,i=Math.min($w,n-16),a={position:`fixed`,left:Math.max(8,Math.min(t.left,n-8-i)),width:i,zIndex:9999};if(r-t.bottom>=t.top){let e=`max(${t.bottom+Zw}px, calc(${eT} + 8px))`;return{...a,top:e,maxHeight:`max(${Qw}px, calc(100dvh - ${e} - ${tT} - 8px))`}}let o=`max(${r-t.top+Zw}px, calc(${tT} + 8px))`;return{...a,bottom:o,maxHeight:`max(${Qw}px, calc(100dvh - ${o} - ${eT} - 8px))`}}var rT=!1;function iT(){return rT}function aT(){rT=!0}function oT(e){return!e.read&&e.severity===`critical`}function sT(e){return e.filter(oT)}function cT(e){return e!==void 0&&typeof e.href==`string`&&e.href.length>0}function lT(e){return cT(e)||e!==void 0&&e.invoke!==void 0}var uT=/^\/addon\/[^/?#]+\/oauth\//;function dT(e){return e.navigation===void 0?uT.test(e.href):e.navigation===`server`}function fT(e){let t=e.action;if(lT(t)&&!(t.invoke!==void 0&&(e.status===`completed`||e.status===`dismissed`)))return t}O();function pT({action:e,className:t,onActivate:n}){let r=N(),i=V(),{t:a}=q(),[o,c]=w(!1),[l,u]=w(null);if(e.invoke!==void 0){let{addonId:d,action:f,input:p}=e.invoke;return s(`span`,{className:`inline-flex flex-col items-start gap-0.5`,children:[x(`button`,{type:`button`,className:t,disabled:o,onClick:e=>{e.preventDefault(),n?.(e),c(!0),u(null),i.trpcClient.addons.custom.mutate({addonId:d,action:f,input:p}).then(()=>r.invalidateQueries({queryKey:[[`alerts`]]})).catch(e=>u(e instanceof Error?e.message:String(e))).finally(()=>c(!1))},children:o?a(`ui.alertAction.running`,`Working…`):e.label}),l!==null&&x(`span`,{role:`alert`,className:`text-[10px] text-destructive`,children:l})]})}return cT(e)?dT(e)?x(`a`,{href:B(e.href),className:t,onClick:t=>{t.preventDefault(),n?.(t),wd(e.href,()=>{r.invalidateQueries({queryKey:[[`alerts`]]}),r.invalidateQueries({queryKey:[[`broker`]]}),r.invalidateQueries({queryKey:[[`recordEntries`]]})})},children:e.label}):x(ku,{to:e.href,className:t,onClick:n,children:e.label}):x(F,{})}O(),wo();var mT={info:lt,success:De,warning:Ne,error:te,critical:sr},hT={info:`text-info`,success:`text-success`,warning:`text-warning`,error:`text-danger`,critical:`text-danger`},gT={active:`border-l-info`,"in-progress":`border-l-warning`,completed:`border-l-success`,failed:`border-l-danger`,dismissed:`border-l-foreground-subtle/30`};function _T(e){let t=Math.floor((Date.now()-e)/1e3);if(t<60)return K.t(`helpers.relativeTime.justNow`);let n=Math.floor(t/60);if(n<60)return K.t(`helpers.relativeTime.minutesAgo`,{count:n});let r=Math.floor(n/60);if(r<24)return K.t(`helpers.relativeTime.hoursAgo`,{count:r});let i=Math.floor(r/24);return K.t(`helpers.relativeTime.daysAgo`,{count:i})}function vT(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function yT(e){return typeof e==`string`&&e.length>0?e:void 0}function bT(e){if(vT(e.metadata)){let t=yT(e.metadata.nodeId)??yT(e.metadata.agentId);if(t!==void 0)return t}let t=e.source;if(t!==void 0&&!(t.type!==`node`&&t.type!==`agent`))return yT(t.id)}function xT({alert:e,onMarkRead:t,onDismiss:n}){let{t:r}=q(),i=e.severity in mT?e.severity:`info`,a=fT(e),o=e.status in gT?e.status:`active`,c=mT[i],l=hT[i],u=gT[o],{nodes:d}=Xi(),f=bT(e),p=f===void 0?void 0:d.find(e=>e.id===f),m=f===void 0?void 0:p?.name??f;return s(`div`,{className:`flex items-start gap-2.5 px-3 py-2.5 border-l-2 ${u} ${e.read?`opacity-60`:``} hover:bg-surface-hover transition-colors`,children:[x(c,{className:`h-3.5 w-3.5 shrink-0 mt-0.5 ${l}`}),s(`div`,{className:`flex-1 min-w-0`,children:[s(`div`,{className:`flex items-center gap-1.5`,children:[x(`span`,{className:`text-[11px] font-semibold ${e.read?`text-foreground-subtle`:`text-foreground`}`,children:e.title}),!e.read&&x(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary shrink-0`})]}),m!==void 0&&x(`div`,{className:`text-foreground-subtle text-[10px] mt-0.5 truncate`,children:m}),x(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5 line-clamp-2`,children:e.message}),a!==void 0&&x(pT,{action:a,className:`inline-flex mt-1.5 items-center rounded-md bg-primary px-2 py-0.5 text-[10px] font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,onActivate:e=>e.stopPropagation()}),e.status===`in-progress`&&e.progress!==void 0&&s(`div`,{className:`mt-1.5 flex items-center gap-2`,children:[x(`div`,{className:`flex-1 h-1 bg-surface-hover rounded-full overflow-hidden`,children:x(`div`,{className:`h-full bg-primary rounded-full transition-all duration-300`,style:{width:`${String(Math.min(100,Math.max(0,e.progress)))}%`}})}),s(`span`,{className:`text-[9px] text-foreground-subtle font-mono shrink-0`,children:[String(Math.round(e.progress)),`%`]})]}),x(`div`,{className:`text-[9px] text-foreground-subtle/60 mt-1`,children:_T(e.updatedAt)})]}),s(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[!e.read&&x(G,{variant:`unstyled`,type:`button`,onClick:n=>{n.stopPropagation(),t(e.id)},className:`p-1 rounded hover:bg-surface-hover transition-colors`,title:r(`ui.alertBell.markAsRead`,`Mark as read`),children:x(mt,{className:`h-3 w-3 text-foreground-subtle`})}),e.status!==`in-progress`&&x(G,{variant:`unstyled`,type:`button`,onClick:t=>{t.stopPropagation(),n(e.id)},className:`p-1 rounded hover:bg-surface-hover transition-colors`,title:r(`ui.alertBell.dismiss`,`Dismiss`),children:x(xe,{className:`h-3 w-3 text-foreground-subtle`})})]})]})}function ST({variant:e=`icon`,compact:t=!1}={}){let{t:n}=q(),[r,i]=w(!1),[a,o]=w(!1),c=p(null),l=p(null),u=N(),{data:d=0}=mi(void 0,{refetchInterval:3e4}),{data:f=[],isLoading:m}=Fa({limit:50},{enabled:r}),h=a?f:f.filter(e=>!e.read),g=f.filter(e=>e.read).length,_=()=>{u.invalidateQueries({queryKey:[[`alerts`]]})},v=Aa({onSuccess:_}),y=Cr({onSuccess:_}),C=kr({onSuccess:_});so(`alert.created`,()=>{u.invalidateQueries({queryKey:[[`alerts`]]})}),so(`alert.updated`,()=>{u.invalidateQueries({queryKey:[[`alerts`]]})}),S(()=>{if(!r)return;let e=e=>{let t=e.target;c.current&&!c.current.contains(t)&&l.current&&!l.current.contains(t)&&i(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e)}},[r]);let T=b(e=>{v.mutate({alertId:e})},[v]),E=b(e=>{e&&C.mutate({alertId:e})},[C]),D=b(()=>{y.mutate(void 0),i(!1)},[y]),O=h.filter(oT),k=new Set(O.map(e=>e.id)),A=h.filter(e=>e.status===`in-progress`&&!k.has(e.id)),j=h.filter(e=>e.status!==`in-progress`&&!k.has(e.id)),[M,ee]=w({}),P=b(()=>{let e=l.current;e&&ee(nT({rect:e.getBoundingClientRect(),viewportWidth:window.innerWidth,viewportHeight:window.innerHeight}))},[]);return S(()=>{if(!r)return;P();let e=()=>P();return window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},[r,P]),s(`div`,{children:[e===`sidebar`?s(G,{variant:`unstyled`,ref:l,type:`button`,onClick:()=>i(!r),className:`flex w-full items-center gap-2.5 rounded-md ${t?`justify-center px-0 py-2`:`px-2.5 py-1.5`} text-[12px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,title:t?d>0?n(`ui.alertBell.alertsUnread`,{count:d}):n(`ui.alertBell.alerts`):void 0,children:[s(`span`,{className:`relative inline-flex shrink-0`,children:[x(Ce,{className:`h-3.5 w-3.5`}),t&&d>0&&x(`span`,{className:`absolute -top-1 -right-1 h-2 w-2 rounded-full bg-primary`})]}),!t&&x(`span`,{className:`flex-1 text-left`,children:n(`ui.alertBell.alerts`,`Alerts`)}),!t&&d>0&&x(`span`,{className:`flex items-center justify-center h-4 min-w-4 px-1 rounded-full bg-primary text-primary-foreground text-[9px] font-bold leading-none`,children:d>99?`99+`:String(d)})]}):s(G,{variant:`unstyled`,ref:l,type:`button`,onClick:()=>i(!r),className:`relative p-1.5 rounded-md hover:bg-surface-hover text-foreground-subtle hover:text-foreground transition-colors`,"aria-label":n(`ui.alertBell.alerts`,`Alerts`),children:[x(Ce,{className:`h-4.5 w-4.5`}),d>0&&x(`span`,{className:`absolute -top-0.5 -right-0.5 flex items-center justify-center h-4 min-w-4 px-0.5 rounded-full bg-primary text-primary-foreground text-[9px] font-bold leading-none`,children:d>99?`99+`:String(d)})]}),r&&To(s(`div`,{ref:c,style:M,className:`bg-surface border border-border rounded-lg shadow-xl flex flex-col overflow-hidden`,children:[s(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border shrink-0`,children:[x(`span`,{className:`text-[12px] font-semibold text-foreground`,children:n(`ui.alertBell.alerts`,`Alerts`)}),s(`div`,{className:`flex items-center gap-2`,children:[g>0&&s(`label`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle cursor-pointer select-none`,children:[x(L,{checked:a,onChange:e=>o(e.target.checked),className:`h-3 w-3 rounded border-border accent-primary cursor-pointer`}),n(`ui.alertBell.showRead`,`Show read`)]}),d>0&&s(G,{variant:`unstyled`,type:`button`,onClick:D,className:`flex items-center gap-1 text-[10px] text-primary hover:text-primary/80 transition-colors`,children:[x(or,{className:`h-3 w-3`}),n(`ui.alertBell.markAllRead`,`Mark all read`)]})]})]}),s(`div`,{className:`flex-1 overflow-y-auto`,children:[m&&x(`div`,{className:`flex items-center justify-center py-8`,children:x(H,{className:`h-4 w-4 animate-spin text-foreground-subtle`})}),!m&&h.length===0&&s(`div`,{className:`flex flex-col items-center justify-center py-8 text-foreground-subtle`,children:[x(Ce,{className:`h-6 w-6 mb-2 opacity-40`}),x(`span`,{className:`text-[11px]`,children:f.length>0?n(`ui.alertBell.noUnreadAlerts`,`No unread alerts`):n(`ui.alertBell.noAlerts`,`No alerts`)}),f.length>0&&!a&&x(G,{variant:`unstyled`,type:`button`,onClick:()=>o(!0),className:`text-[10px] text-primary mt-1 hover:underline`,children:n(`ui.alertBell.showRead`,{count:g})})]}),O.length>0&&s(`div`,{className:`border-b border-border`,children:[x(`div`,{className:`px-3 py-1.5 bg-danger/5`,children:x(`span`,{className:`text-[9px] font-semibold uppercase tracking-widest text-danger`,children:n(`ui.alertBell.urgent`,`Urgent`)})}),O.map(e=>x(xT,{alert:e,onMarkRead:T,onDismiss:E},e.id))]}),A.length>0&&s(`div`,{className:`border-b border-border`,children:[x(`div`,{className:`px-3 py-1.5 bg-surface-hover/50`,children:x(`span`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60`,children:n(`ui.alertBell.inProgress`,`In Progress`)})}),A.map(e=>x(xT,{alert:e,onMarkRead:T,onDismiss:E},e.id))]}),j.map(e=>x(xT,{alert:e,onMarkRead:T,onDismiss:E},e.id))]})]}),document.body)]})}O(),wo();function CT({alert:e,onMarkRead:t}){let{t:n}=q(),r=fT(e);return s(`div`,{className:`border-b border-border last:border-b-0 px-3 py-2.5`,children:[x(`div`,{className:`text-[12px] font-semibold text-foreground`,children:e.title}),x(`div`,{className:`text-[11px] text-foreground-muted mt-0.5`,children:e.message}),s(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[r!==void 0&&x(pT,{action:r,className:`inline-flex items-center justify-center rounded-md bg-primary px-2.5 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90 transition-colors`}),x(G,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>t(e.id),children:n(`ui.alertBell.markAsRead`,`Mark as read`)})]})]})}function wT(){let{t:e}=q(),t=N(),[n,r]=w(iT()),{data:i=[],isLoading:a}=Fa({limit:50}),o=m(()=>sT(i),[i]),c=Aa({onSuccess:b(()=>{t.invalidateQueries({queryKey:[[`alerts`]]})},[t])}),l=b(e=>{c.mutate({alertId:e})},[c]),u=b(()=>{aT(),r(!0)},[]);return a||n||o.length===0?null:To(x(`div`,{className:`fixed inset-x-0 bottom-0 z-[10000] flex justify-center p-2 sm:p-4 pb-[max(0.5rem,env(safe-area-inset-bottom))] pointer-events-none`,"data-testid":`critical-alerts-on-load-panel`,children:s(`div`,{className:`pointer-events-auto w-full max-w-lg bg-surface border border-danger/30 rounded-lg shadow-xl flex flex-col max-h-[min(70dvh,32rem)] overflow-hidden`,role:`region`,"aria-labelledby":`critical-alerts-panel-title`,children:[s(`div`,{className:`flex items-start justify-between gap-2 px-3 py-2.5 border-b border-border shrink-0 bg-danger/5`,children:[s(`div`,{children:[x(`h2`,{id:`critical-alerts-panel-title`,className:`text-[12px] font-semibold text-foreground`,children:e(`ui.criticalAlertsPanel.title`,`Urgent alerts`)}),x(`p`,{className:`text-[10px] text-foreground-muted mt-0.5`,children:e(`ui.criticalAlertsPanel.subtitle`,`These need your attention.`)})]}),x(Ar,{type:`button`,variant:`ghost`,onClick:u,"aria-label":e(`ui.criticalAlertsPanel.close`,`Close`),"data-testid":`critical-alerts-panel-close`,icon:xe})]}),x(`div`,{className:`flex-1 overflow-y-auto`,children:o.map(e=>x(CT,{alert:e,onMarkRead:l},e.id))})]})}),document.body)}O();function TT(){let e=Zy();return C(e.subscribe,e.getSnapshot,e.getSnapshot)}var ET=[`detection`,`cluster`,`administration`];function DT(e){return ET.includes(e)}function OT(e){let t=new Map,n=new Map,r=[];for(let i of e){let e=i.section?.trim();if(e===void 0||e.length===0){r.push(i);continue}if(DT(e)){let n=t.get(e)??[];n.push(i),t.set(e,n);continue}let a=n.get(e);a?a.pages.push(i):n.set(e,{label:i.sectionLabel?.trim()||e,pages:[i]})}return{known:t,custom:[...n.entries()].map(([e,t])=>({id:e,label:t.label,pages:t.pages})),ungrouped:r}}var kT=`camstack:last-path`,AT=512,jT=[`/login`,`/change-password`,`/access-denied`,`/logout`];function MT(e){return!e.startsWith(`/`)||e.startsWith(`//`)||e.length>AT?!1:!jT.some(t=>e===t||e.startsWith(t+`/`))}function NT(e){if(!(typeof window>`u`)&&MT(e))try{window.localStorage.setItem(kT,e)}catch{}}function PT(){if(typeof window>`u`)return null;try{let e=window.localStorage.getItem(kT);return e===null?null:MT(e)?e:null}catch{return null}}var FT=`/devices`;function IT(e){return e!==void 0&&MT(e)?e:PT()??FT}function LT(e){return e.split(`.`)[0]===`0`?`${e} beta`:e}function RT(e){if(e===null)return null;let t=e.trim();return t.length>0?t:null}function zT(e){let t=RT(e.productVersion),n=RT(e.serverVersion),r=RT(e.fallbackVersion);return t!==null&&n!==null?{kind:`both`,productLabel:LT(t),serverVersion:n}:t===null?n===null?r===null?{kind:`none`}:{kind:`fallback`,version:r}:{kind:`server`,serverVersion:n}:{kind:`product`,productLabel:LT(t)}}function BT(e,t){if(!Object.hasOwn(e,t))return null;let n=Reflect.get(e,t);return typeof n==`string`?n:null}function VT(e){return typeof e!=`object`||!e?null:{productVersion:BT(e,`productVersion`),serverVersion:BT(e,`serverVersion`)}}O();function HT(e,t){return e.kind===`both`?t(`releaseIdentity.both`,`{{product}} · server {{server}}`,{product:e.productLabel,server:e.serverVersion}):e.kind===`product`?e.productLabel:e.kind===`server`?t(`releaseIdentity.serverOnly`,`server {{version}}`,{version:e.serverVersion}):e.kind===`fallback`?t(`releaseIdentity.fallback`,`v{{version}}`,{version:e.version}):null}function UT({placement:e,compact:t=!1}){let{t:n}=q(),[r,i]=w({kind:`fallback`,version:`1.2.707`});S(()=>{let e=new AbortController;return fetch(B(`/api/release-identity`),{signal:e.signal}).then(async e=>e.ok?VT(await e.json()):null).then(t=>{e.signal.aborted||t===null||i(zT({productVersion:t.productVersion,serverVersion:t.serverVersion,fallbackVersion:`1.2.707`}))}).catch(t=>{e.signal.aborted||t instanceof DOMException&&t.name}),()=>e.abort()},[]);let a=HT(r,n);return a===null?null:e===`login`?x(`span`,{"data-testid":`release-identity`,children:a}):x(`div`,{"data-testid":`release-identity`,className:`pt-1 text-[10px] text-foreground-disabled select-none truncate ${t?`text-center`:`px-2`}`,title:a,children:a})}O();var WT=j(!0);function GT(e){return e===`/addon`||e.startsWith(`/addon/`)}function KT(e,t,n){let r=[...e.filter(e=>e!==t),t];return r.length<=n?r:r.slice(r.length-n)}function qT({maxCached:e=6}){let t=fl(),n=Y(),r=ol(),i=I(Zc),a=n.pathname,o=GT(a),c=p(new Map),l=p([]);if(o){c.current.set(a,{key:a,outlet:t,location:n,navigationType:r,routeContext:i});let o=KT(l.current,a,e),s=new Set(o);for(let e of c.current.keys())s.has(e)||c.current.delete(e);l.current=o}return s(F,{children:[l.current.map(e=>{let t=c.current.get(e);if(t?.outlet==null)return null;let n=o&&e===a;return x(`div`,{className:n?`h-full min-h-0`:void 0,style:n?void 0:{display:`none`},hidden:!n,"aria-hidden":!n,children:x(WT.Provider,{value:n,children:x(Xc.Provider,{value:{location:t.location,navigationType:t.navigationType},children:x(Zc.Provider,{value:t.routeContext,children:t.outlet})})})},e)}),!o&&t!=null?x(`div`,{className:`h-full min-h-0`,children:t},a):null]})}O();var JT={dark:ye,light:Ue,system:ie};function YT(){return x(`div`,{className:`flex h-full min-h-[50vh] items-center justify-center`,children:x(`span`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-primary/30 border-t-primary`})})}function XT(){let e=Y(),t=ll(),{user:n,logout:r}=ax(),i=ba(),{t:a}=q(),o=ui(),c=us(),l=oi(),{info:u}=Ww();S(()=>{document.title=u===null?`CamStack Admin`:`${u.name} \u00b7 CamStack Admin`},[u]);let d=Vy(TT()),[f,h]=w(!1);S(()=>{NT(e.pathname+e.search)},[e.pathname,e.search]);let[g,_]=w(()=>typeof window>`u`?!1:window.localStorage.getItem(`camstack:sidebar-collapsed`)===`1`);S(()=>{typeof window>`u`||window.localStorage.setItem(`camstack:sidebar-collapsed`,g?`1`:`0`)},[g]);let[v]=w(()=>{if(typeof window>`u`)return new Set;try{let e=window.localStorage.getItem(`camstack:sidebar-collapsed-groups`);if(!e)return new Set;let t=JSON.parse(e);return Array.isArray(t)?new Set(t.filter(e=>typeof e==`string`)):new Set}catch{return new Set}});S(()=>{typeof window>`u`||window.localStorage.setItem(`camstack:sidebar-collapsed-groups`,JSON.stringify([...v]))},[v]),S(()=>{l&&window.localStorage.getItem(`camstack:sidebar-collapsed`)===null&&_(!0)},[l]);let{data:b=[]}=Ca({nodeId:`hub`},{refetchInterval:3e4}),C=b.length,T=N(),E=p(Date.now()),{data:D}=Ji(void 0,{staleTime:0,refetchOnMount:`always`,refetchInterval:e=>{let t=e.state.data;return t&&t.length>0||Date.now()-E.current>=3e4?!1:2e3}}),O=m(()=>D&&n?.isAdmin?FC(D):[],[D,n?.isAdmin]),k=m(()=>OT(O),[O]),A=k.known.get(`detection`)??[],j=k.known.get(`cluster`)??[],M=k.known.get(`administration`)??[];so(`addon.page-ready`,()=>{T.invalidateQueries({queryKey:[[`addonPages`,`listPages`]]})});let ee=()=>{r(),t(`/login`)},P=t=>!!(e.pathname===t||e.pathname.startsWith(t+`/`)),I=[`/system/pipeline`,`/live`,`/addon/osd-manager`,`/build`].some(t=>e.pathname===t||e.pathname.startsWith(t+`/`)),L=n?.isAdmin===!0,te=m(()=>JC({t:a,isAdmin:L}),[a,L]),ne=te[0]?.items??[],re=te[1]?.items??[],ie=te[2]?.items??[],ae=te[3]?.items??[],oe=i?.mode??`system`,se={dark:a(`theme.dark`),light:a(`theme.light`),system:a(`theme.system`)},R=g&&!o,ce=(e,t=`md`,n=!1)=>`flex w-full items-center gap-2.5 rounded-md ${R?`justify-center px-0 py-2`:`px-2.5 py-1.5`} ${t===`lg`?`text-[13px] font-medium`:`text-[12px]`} transition-all ${e?t===`lg`?`bg-primary/12 text-primary shadow-sm shadow-primary/5`:`bg-primary/12 text-primary`:n?`text-foreground-disabled hover:bg-surface-hover`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,le=(e,t)=>e===0?null:R?x(`div`,{className:`pt-3 mb-1 mx-2 border-t border-border/60`},`sep-${t}`):x(`div`,{className:`pt-4 pb-1.5 px-2.5`,children:x(`span`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/60`,children:t})},`hdr-${t}`),ue=e=>{let n=P(e.path),r=XC(e.icon);return s(G,{variant:`unstyled`,onClick:()=>{t(e.path),h(!1)},className:ce(n),title:R?e.label:void 0,children:[x(r,{className:`h-3.5 w-3.5 shrink-0 ${n?`text-primary`:``}`}),!R&&e.label]},`${e.addonId}::${e.id}`)},de=e=>e.requiresCapability===void 0?fe(e,!1):x(tw,{capability:e.requiresCapability,children:t=>fe(e,t)},e.path),fe=(e,n)=>{let r=e.icon,i=P(e.path),o=e.path===`/system/addons`;return s(G,{variant:`unstyled`,"data-testid":`nav-${e.path.replace(/^\//,``).replace(/\//g,`-`)}`,onClick:()=>{t(e.path),h(!1)},className:ce(i,`md`,n),"aria-disabled":n||void 0,title:n?a(`nav.notInstalled`,`{{page}} — not installed`,{page:e.label}):R?e.label:void 0,children:[x(r,{className:`h-3.5 w-3.5 shrink-0 ${i?`text-primary`:``}`}),!R&&s(F,{children:[x(`span`,{className:`flex-1 text-left`,children:e.label}),o&&C>0&&x(`span`,{className:`ml-auto rounded-full bg-primary px-1.5 py-0.5 text-[9px] font-bold text-primary-foreground leading-none`,children:C})]}),R&&o&&C>0&&x(`span`,{className:`absolute mt-[-14px] ml-3 h-2 w-2 rounded-full bg-primary`})]},e.path)},z=s(F,{children:[s(`div`,{className:`flex h-14 items-center border-b border-border ${R?`justify-center px-1`:`pl-3 pr-4 gap-2`}`,children:[!R&&x(`img`,{src:i?.resolvedMode===`light`?B(`/brand/logo-horizontal-light.svg`):B(`/brand/logo-horizontal-dark.svg`),alt:a(`layouts.appLayout.camstackAdmin`,`CamStack Admin`),className:`h-9 flex-1 min-w-0`}),!o&&x(G,{variant:`unstyled`,onClick:()=>_(e=>!e),className:`p-1.5 rounded-md hover:bg-surface-hover text-foreground-subtle transition-colors flex-shrink-0 ${R?``:`mr-2`}`,"aria-label":g?a(`layouts.appLayout.expandSidebar`,`Expand sidebar`):a(`layouts.appLayout.collapseSidebar`,`Collapse sidebar`),title:g?a(`layouts.appLayout.expandSidebar`,`Expand sidebar`):a(`layouts.appLayout.collapseSidebar`,`Collapse sidebar`),children:x(g?Re:at,{className:`h-4 w-4`})})]}),!R&&u!==null&&x(`div`,{"data-testid":`sidebar-server-name`,title:u.name,className:`truncate border-b border-border px-3 py-1.5 text-xs font-medium text-foreground-muted`,children:u.name}),x(`div`,{className:`border-b border-border pt-2`,children:x(Ow,{navSections:te,addonPages:O,compact:R,onNavigated:()=>h(!1)})}),s(`nav`,{className:`flex-1 overflow-y-auto py-3 ${R?`px-1.5`:`px-2`} space-y-0.5`,children:[ne.map(e=>de(e)),le(re.length+A.length,a(`nav.detectionSection`,`Detection`)),re.map(e=>de(e)),A.map(e=>ue(e)),le(ie.length+j.length,a(`nav.clusterSection`,`Cluster`)),ie.map(e=>de(e)),j.map(e=>ue(e)),le(ae.length+M.length,a(`system.title`,`Administration`)),ae.map(e=>de(e)),M.map(e=>ue(e)),k.custom.map(e=>s(`div`,{className:`contents`,children:[le(e.pages.length,e.label),e.pages.map(e=>ue(e))]},`custom-${e.id}`)),le(k.ungrouped.length,a(`nav.addonPages`,`Addon Pages`)),k.ungrouped.map(e=>ue(e))]}),s(`div`,{className:`border-t border-border ${R?`p-1.5`:`p-2`} space-y-0.5`,children:[s(G,{variant:`unstyled`,onClick:()=>i?.toggleMode(),className:ce(!1),title:R?se[oe]:void 0,children:[(()=>{let e=JT[oe];return x(e,{className:`h-3.5 w-3.5 shrink-0`})})(),!R&&x(`span`,{children:se[oe]})]}),x(ST,{variant:`sidebar`,compact:R}),s(G,{variant:`unstyled`,type:`button`,onClick:()=>t(`/system/my-access`),className:ce(P(`/system/my-access`)),title:R?a(`system.myAccess`,`My access`):void 0,children:[x(pe,{className:`h-3.5 w-3.5 shrink-0`}),!R&&x(`span`,{className:`truncate`,children:a(`system.myAccess`,`My access`)})]}),s(G,{variant:`unstyled`,type:`button`,onClick:()=>c.setOn(!c.on),className:ce(c.on),"aria-pressed":c.on,title:R?a(`layouts.appLayout.debugLayers`,`Debug layers`):void 0,children:[x(Pe,{className:`h-3.5 w-3.5 shrink-0`}),!R&&x(`span`,{className:`truncate`,children:c.on?a(`layouts.appLayout.debugLayersOn`,`Debug layers: on`):a(`layouts.appLayout.debugLayers`,`Debug layers`)})]}),s(G,{variant:`unstyled`,onClick:ee,className:ce(!1).replace(`hover:text-foreground`,`hover:text-danger`),title:R?n?.username??a(`layouts.appLayout.logout`,`Logout`):void 0,children:[x(tr,{className:`h-3.5 w-3.5 shrink-0`}),!R&&x(`span`,{className:`truncate`,children:n?.username??a(`layouts.appLayout.user`,`User`)})]}),x(UT,{placement:`sidebar`,compact:R})]})]});return s(`div`,{className:`flex h-dvh flex-col overflow-hidden bg-background text-foreground pb-[env(safe-area-inset-bottom)]`,children:[x(`div`,{"aria-hidden":`true`,className:`h-[env(safe-area-inset-top)] shrink-0 bg-surface`}),s(`div`,{className:`flex min-h-0 flex-1`,children:[!o&&x(`aside`,{className:`flex flex-col border-r border-border bg-surface shrink-0 transition-[width] duration-150 ease-out ${R?`w-12`:`w-48`}`,children:z}),o&&x(Da,{open:f,onClose:()=>h(!1),width:`w-64`,children:z}),s(`div`,{className:`flex flex-1 flex-col min-w-0`,children:[d!==null&&s(`div`,{className:`flex items-center justify-center gap-2 px-3 py-2 text-[12px] font-medium shrink-0 ${d.severity===`danger`?`bg-danger/90 text-white`:`bg-warning/15 text-warning border-b border-warning/30`}`,children:[d.severity===`danger`?x($e,{className:`h-3.5 w-3.5`}):x(he,{className:`h-3.5 w-3.5`}),x(`span`,{children:a(d.i18nKey,{defaultValue:d.message,...d.i18nParams})}),d.action===`sign-in`&&x(G,{variant:`unstyled`,onClick:()=>r(),className:`ml-2 rounded border border-white/40 px-2 py-0.5 text-[11px] font-semibold hover:bg-white/10`,children:a(`connection.signIn`,`Sign in`)}),d.showSpinner&&x(H,{className:`h-3.5 w-3.5 animate-spin`})]}),x(Lw,{}),x(Yw,{}),x(wT,{}),o&&s(`header`,{"data-debug-header":``,className:`flex items-center h-12 border-b border-border px-3 shrink-0 bg-surface`,children:[x(G,{variant:`unstyled`,onClick:()=>h(!0),className:`p-1.5 -ml-1.5 rounded-md hover:bg-surface-hover text-foreground-muted transition-colors`,"aria-label":a(`layouts.appLayout.openMenu`,`Open menu`),children:x(tt,{className:`h-5 w-5`})}),x(`div`,{className:`flex-1 flex justify-center`,children:x(`img`,{src:i?.resolvedMode===`light`?B(`/brand/logo-horizontal-light.svg`):B(`/brand/logo-horizontal-dark.svg`),alt:a(`layouts.appLayout.camstack`,`CamStack`),className:`h-7`})}),x(ST,{})]}),s(nw,{children:[x(iw,{}),x(`main`,{className:`relative flex-1 min-h-0 overscroll-contain bg-background ${I?`overflow-hidden`:`overflow-auto`}`,children:x(NC,{resetKey:e.pathname,children:x(y,{fallback:x(YT,{}),children:x(qT,{})})})})]})]})]})]})}function $({children:e,requireAdmin:t}){let{t:n}=q(),{user:r,loading:i,mustChangePassword:a}=ax(),o=Y();return i?x(`div`,{className:`flex h-screen items-center justify-center bg-background text-foreground-subtle`,children:n(`layouts.protectedRoute.loading`,`Loading...`)}):r?a&&o.pathname!==`/change-password`?x(X,{to:`/change-password`,replace:!0}):t&&!r.isAdmin?x(X,{to:`/access-denied`,replace:!0}):x(F,{children:e}):x(X,{to:`/login`,replace:!0,state:{from:o.pathname+o.search}})}var ZT=`integration`,QT=`section`,$T=[ZT,QT,`instance`,`instance-new`],eE={connectivity:{path:`/system/integrations`,tab:null},remoteAccess:{path:`/system/network`,tab:`remote-access`},mesh:{path:`/system/network`,tab:`mesh`},turn:{path:`/system/network`,tab:`turn`},authentication:{path:`/system/identity`,tab:`authentication`},access:{path:`/system/identity`,tab:`access`},logging:{path:`/system/logs`,tab:`destinations`}},tE=`activity`;function nE(e,t={}){let{path:n,tab:r}=eE[e],i=new URLSearchParams;r===null?t.kindSection!==void 0&&i.set(`tab`,t.kindSection):i.set(`tab`,r),t.integration!==void 0&&i.set(ZT,t.integration),t.section!==void 0&&i.set(QT,t.section);let a=i.toString();return a.length>0?`${n}?${a}`:n}function rE(e){let{ids:t,requested:n,answered:r,legacyGroup:i=null,groupFirst:a={}}=e;if(n!==null&&t.includes(n))return{selectedId:n,staleId:null};let o=n!==null&&r?n:null,s=i===null?void 0:a[i];return s!==void 0&&t.includes(s)?{selectedId:s,staleId:o}:{selectedId:t[0]??null,staleId:o}}function iE(e,t,n=null,r=null){let i=new URLSearchParams(e);return i.set(ZT,t),r===null?i.delete(QT):i.set(QT,r),n!==null&&i.delete(n),i}function aE(e){return e===`/admin`||e===`/admin/`?`/`:e.startsWith(`/admin/`)?e.slice(6):e}var oE=`--color-surface`;function sE(e){let t=e.querySelector(`meta[name="theme-color"]`);if(t)return t;let n=e.createElement(`meta`);return n.name=`theme-color`,e.head.appendChild(n),n}function cE(e=document){let t=e.defaultView?.getComputedStyle(e.documentElement).getPropertyValue(oE).trim();if(!t)return;let n=sE(e);n.content!==t&&(n.content=t)}function lE(e=document){cE(e);let t=e.defaultView;if(!t)return()=>void 0;let n=new t.MutationObserver(()=>cE(e));return n.observe(e.documentElement,{attributes:!0,attributeFilter:[`class`]}),()=>n.disconnect()}function uE(){let{t:e}=q(),t=ll();return s(`div`,{className:`flex flex-col items-center justify-center text-foreground py-16 px-4`,children:[x(`div`,{className:`flex h-16 w-16 items-center justify-center rounded-2xl bg-danger/10 mb-4`,children:x(pr,{className:`h-8 w-8 text-danger`})}),x(`h1`,{className:`text-xl font-bold`,children:e(`accessDenied.accessDenied`,`Access Denied`)}),x(`p`,{className:`mt-2 text-sm text-foreground-subtle`,children:e(`accessDenied.youDonTHavePermission`,`You don't have permission to access this page.`)}),x(G,{variant:`unstyled`,onClick:()=>t(`/devices`),className:`mt-6 rounded-lg bg-primary px-5 py-2.5 text-sm font-medium text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg transition-all`,children:e(`accessDenied.goToDevices`,`Go to Devices`)})]})}function dE(e){let t=new Uint8Array(e),n=``;for(let e of t)n+=String.fromCharCode(e);return btoa(n).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=/g,``)}function fE(e){let t=e.replace(/-/g,`+`).replace(/_/g,`/`),n=(4-t.length%4)%4,r=t.padEnd(t.length+n,`=`),i=atob(r),a=new ArrayBuffer(i.length),o=new Uint8Array(a);for(let e=0;e<i.length;e++)o[e]=i.charCodeAt(e);return a}function pE(){return window?.PublicKeyCredential!==void 0&&typeof window.PublicKeyCredential==`function`}function mE(e){let{id:t}=e;return{...e,id:fE(t),transports:e.transports}}function hE(e){return e===`localhost`||/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(e)}var gE=class extends Error{constructor({message:e,code:t,cause:n,name:r}){super(e,{cause:n}),this.name=r??n.name,this.code=t}},_E=new class{createNewAbortSignal(){if(this.controller){let e=Error(`Cancelling existing WebAuthn API call for new one`);e.name=`AbortError`,this.controller.abort(e)}let e=new AbortController;return this.controller=e,e.signal}cancelCeremony(){if(this.controller){let e=Error(`Manually cancelling existing WebAuthn API call`);e.name=`AbortError`,this.controller.abort(e),this.controller=void 0}}},vE=[`cross-platform`,`platform`];function yE(e){if(e&&!(vE.indexOf(e)<0))return e}function bE(){if(!pE())return new Promise(e=>e(!1));let e=window.PublicKeyCredential;return e.isConditionalMediationAvailable===void 0?new Promise(e=>e(!1)):e.isConditionalMediationAvailable()}function xE({error:e,options:t}){let{publicKey:n}=t;if(!n)throw Error(`options was missing required publicKey property`);if(e.name===`AbortError`){if(t.signal instanceof AbortSignal)return new gE({message:`Authentication ceremony was sent an abort signal`,code:`ERROR_CEREMONY_ABORTED`,cause:e})}else if(e.name===`NotAllowedError`)return new gE({message:e.message,code:`ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY`,cause:e});else if(e.name===`SecurityError`){let t=window.location.hostname;if(!hE(t))return new gE({message:`${window.location.hostname} is an invalid domain`,code:`ERROR_INVALID_DOMAIN`,cause:e});if(n.rpId!==t)return new gE({message:`The RP ID "${n.rpId}" is invalid for this domain`,code:`ERROR_INVALID_RP_ID`,cause:e})}else if(e.name===`UnknownError`)return new gE({message:`The authenticator was unable to process the specified options, or could not create a new assertion signature`,code:`ERROR_AUTHENTICATOR_GENERAL_ERROR`,cause:e});return e}async function SE(e){let{optionsJSON:t,useBrowserAutofill:n=!1,verifyBrowserAutofillInput:r=!0}=e;if(!pE())throw Error(`WebAuthn is not supported in this browser`);let i;t.allowCredentials?.length!==0&&(i=t.allowCredentials?.map(mE));let a={...t,challenge:fE(t.challenge),allowCredentials:i},o={};if(n){if(!await bE())throw Error(`Browser does not support WebAuthn autofill`);if(document.querySelectorAll(`input[autocomplete$='webauthn']`).length<1&&r)throw Error('No <input> with "webauthn" as the only or last value in its `autocomplete` attribute was detected');o.mediation=`conditional`,a.allowCredentials=[]}o.publicKey=a,o.signal=_E.createNewAbortSignal();let s;try{s=await navigator.credentials.get(o)}catch(e){throw xE({error:e,options:o})}if(!s)throw Error(`Authentication was not completed`);let{id:c,rawId:l,response:u,type:d}=s,f;return u.userHandle&&(f=dE(u.userHandle)),{id:c,rawId:dE(l),response:{authenticatorData:dE(u.authenticatorData),clientDataJSON:dE(u.clientDataJSON),signature:dE(u.signature),userHandle:f},type:d,clientExtensionResults:s.getClientExtensionResults(),authenticatorAttachment:yE(s.authenticatorAttachment)}}function CE(e){return typeof e==`object`&&!!e}function wE(e){return CE(e)&&typeof e.challenge==`string`}O();function TE(e,t){return e instanceof Error&&e.message.length>0?e.message:t}function EE(e){let{t}=q(),n=V(),[r,i]=w(!1),[a,o]=w(``),[c,l]=w(null),[u,d]=w(null),f=p(null),m=b(e=>{f.current?.(e),f.current=null,i(!1),o(``),l(null),d(null)},[]),h=b(()=>new Promise(e=>{f.current?.(null),f.current=e,d(null),i(!0)}),[]),g=async()=>{l(`password`),d(null);try{let{reauthToken:e}=await n.reauthenticate({password:a});m(e)}catch(e){d(TE(e,`Password is incorrect`)),l(null)}},_=async()=>{l(`passkey`),d(null);try{let{optionsJSON:e}=await n.reauthBeginPasskey();if(!wE(e))throw Error(`passkey authentication options missing challenge`);let t=await SE({optionsJSON:e}),{reauthToken:r}=await n.reauthenticate({passkeyResponse:Object.fromEntries(Object.entries(t))});m(r)}catch(e){d(TE(e,`Passkey verification failed`)),l(null)}};return{requestProof:h,dialog:x(Mi,{open:r,onOpenChange:e=>!e&&m(null),children:s(Ir,{children:[s(Yr,{children:[x(qi,{children:t(`auth.reauthDialog.confirmItSYou`,`Confirm it’s you`)}),x($r,{children:t(`auth.reauthDialog.needsPassword`,{action:e})})]}),s(`form`,{className:`space-y-3`,onSubmit:e=>{e.preventDefault(),a.length>0&&c===null&&g()},children:[x(W,{type:`password`,autoComplete:`current-password`,placeholder:t(`auth.reauthDialog.currentPassword`,`Current password`),value:a,onChange:e=>o(e.target.value),"aria-label":t(`auth.reauthDialog.currentPassword`,`Current password`)}),u!==null&&x(`p`,{role:`alert`,className:`text-xs text-danger`,children:u}),s(Qa,{className:`flex flex-wrap gap-2`,children:[s(G,{type:`button`,variant:`outline`,disabled:c!==null,onClick:()=>void _(),children:[c===`passkey`?x(H,{className:`h-4 w-4 animate-spin`}):x(cr,{className:`h-4 w-4`}),t(`auth.reauthDialog.useAPasskey`,`Use a passkey`)]}),s(G,{type:`submit`,disabled:a.length===0||c!==null,children:[c===`password`&&x(H,{className:`h-4 w-4 animate-spin`}),t(`common.confirm`,`Confirm`)]})]})]})]})})}}O();function DE(e){return e.ip!==null&&e.approverIp!==null&&e.ip!==e.approverIp}function OE(e,t){return e instanceof Error&&e.message.length>0?e.message:t}function kE(e){let t=e instanceof Error?e.message:``;return t.startsWith(`Sign in again first`)||t.startsWith(`Confirm it is you`)}function AE(e,t){let n=Math.max(0,Math.round((t-e)/1e3));return n<5?{key:`justNow`,value:0}:n<60?{key:`seconds`,value:n}:{key:`minutes`,value:Math.round(n/60)}}function jE({onApproved:e,onDenied:t}){let{t:n}=q(),r=Ka.useUtils(),[i,a]=w(``),[o,c]=w(null),[l,u]=w(``),[d,f]=w(null),[p,m]=w(null),{requestProof:h,dialog:g}=EE(n(`cliLogin.reauthAction`,`Approving a terminal sign-in`)),_=Ka.auth.cliLoginApprove.useMutation(),v=Ka.auth.cliLoginDeny.useMutation(),y=async e=>{e.preventDefault(),f(`lookup`),m(null);try{c(await r.auth.cliLoginDescribe.fetch({userCode:i})),u(i)}catch(e){c(null),m(OE(e,n(`cliLogin.unknownCode`,`No pending sign-in with that code. Check the terminal.`)))}finally{f(null)}},b=async r=>{f(r),m(null);try{if(r===`deny`){await v.mutateAsync({userCode:l}),t();return}try{await _.mutateAsync({userCode:l})}catch(e){if(!kE(e))throw e;let t=await h();if(t===null)return;await _.mutateAsync({userCode:l,reauthToken:t})}e()}catch(e){m(OE(e,n(`cliLogin.failed`,`That did not work. Try again.`)))}finally{f(null)}},S=o===null?null:AE(o.createdAt,Date.now());return s(`div`,{className:`space-y-4`,"data-testid":`cli-login-approval`,children:[s(`div`,{className:`space-y-1`,children:[s(`h1`,{className:`flex items-center gap-2 text-sm font-semibold text-foreground`,children:[x(ur,{className:`h-4 w-4`,"aria-hidden":!0}),n(`cliLogin.title`,`Approve a terminal sign-in`)]}),x(`p`,{className:`text-xs text-foreground-subtle`,children:n(`cliLogin.intro`,`Type the code your terminal shows. Only approve a sign-in you started yourself.`)})]}),p!==null&&x(`div`,{role:`alert`,className:`rounded-md border border-danger/20 bg-danger/10 px-3 py-2 text-xs text-danger`,children:p}),o===null||S===null?s(`form`,{onSubmit:e=>void y(e),className:`space-y-3`,children:[x(W,{value:i,onChange:e=>a(e.target.value),placeholder:`ABCD-EFGH`,"aria-label":n(`cliLogin.codeLabel`,`Sign-in code`),autoComplete:`off`,autoCapitalize:`characters`,spellCheck:!1,maxLength:16,className:`text-center font-mono tracking-widest`}),s(G,{type:`submit`,variant:`primary`,className:`w-full`,disabled:i.trim().length<8||d!==null,children:[d===`lookup`&&x(H,{className:`h-4 w-4 animate-spin`,"aria-hidden":!0}),n(`cliLogin.continue`,`Continue`)]})]}):s(`div`,{className:`space-y-3`,children:[s(`dl`,{className:`space-y-1 rounded-md border border-border bg-background-elevated p-3 text-xs`,children:[s(`div`,{className:`flex justify-between gap-3`,children:[x(`dt`,{className:`text-foreground-muted`,children:n(`cliLogin.address`,`Terminal address`)}),x(`dd`,{className:`text-foreground`,"data-testid":`cli-login-ip`,children:o.ip??n(`cliLogin.unknownValue`,`Unknown`)})]}),s(`div`,{className:`flex justify-between gap-3`,children:[x(`dt`,{className:`text-foreground-muted`,children:n(`cliLogin.yourAddress`,`Your address`)}),x(`dd`,{className:`text-foreground`,"data-testid":`cli-login-approver-ip`,children:o.approverIp??n(`cliLogin.unknownValue`,`Unknown`)})]}),s(`div`,{className:`flex justify-between gap-3`,children:[x(`dt`,{className:`text-foreground-muted`,children:n(`cliLogin.program`,`Program (seen by the hub)`)}),x(`dd`,{className:`truncate text-foreground`,"data-testid":`cli-login-agent`,children:o.userAgent??n(`cliLogin.unknownValue`,`Unknown`)})]}),s(`div`,{className:`flex justify-between gap-3`,children:[x(`dt`,{className:`text-foreground-muted`,children:n(`cliLogin.client`,`Name it gave itself (unverified)`)}),x(`dd`,{className:`truncate text-foreground-muted`,"data-testid":`cli-login-client`,children:o.client??n(`cliLogin.unknownValue`,`Unknown`)})]}),s(`div`,{className:`flex justify-between gap-3`,children:[x(`dt`,{className:`text-foreground-muted`,children:n(`cliLogin.requested`,`Requested`)}),x(`dd`,{className:`text-foreground`,children:S.key===`justNow`?n(`cliLogin.ageNow`,`just now`):S.key===`seconds`?n(`cliLogin.ageSeconds`,`{{count}} s ago`,{count:S.value}):n(`cliLogin.ageMinutes`,`{{count}} min ago`,{count:S.value})})]})]}),DE(o)&&x(`div`,{role:`alert`,"data-testid":`cli-login-mismatch`,className:`rounded-md border border-warning/20 bg-warning/10 px-3 py-2 text-xs text-warning`,children:n(`cliLogin.mismatch`,`This request comes from a different address than the one you are using now. Approve it only if you started it from another machine of yours.`)}),x(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`cli-login-grant`,children:n(`cliLogin.grant`,`Approving signs this terminal in as you, with all of your rights, until the session expires or you end it under Tokens & sessions.`)}),s(`div`,{className:`flex gap-2`,children:[x(G,{type:`button`,variant:`ghost`,className:`flex-1`,disabled:d!==null,onClick:()=>void b(`deny`),children:n(`cliLogin.deny`,`Deny`)}),s(G,{type:`button`,variant:`primary`,className:`flex-1`,disabled:d!==null,onClick:()=>void b(`approve`),children:[d===`approve`&&x(H,{className:`h-4 w-4 animate-spin`,"aria-hidden":!0}),n(`cliLogin.approve`,`Approve`)]})]})]}),g]})}O();function ME(){let{t:e}=q(),t=ba(),n=ll(),[r,i]=w(!1);return x(`div`,{className:`flex min-h-screen items-center justify-center bg-background p-4`,children:s(`div`,{className:`w-full max-w-sm`,children:[x(`div`,{className:`mb-8 flex justify-center`,children:x(`img`,{src:t?.resolvedMode===`light`?B(`/brand/logo-horizontal-light.svg`):B(`/brand/logo-horizontal-dark.svg`),alt:e(`cliLogin.brand`,`CamStack`),className:`h-12`})}),x(`div`,{className:`rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10`,children:r?s(`div`,{className:`space-y-3 text-center`,"data-testid":`cli-login-denied`,children:[x(`p`,{className:`text-sm text-foreground`,children:e(`cliLogin.deniedBody`,`The sign-in was denied. The terminal stays signed out.`)}),x(G,{type:`button`,variant:`ghost`,onClick:()=>void n(`/`),children:e(`cliLogin.back`,`Back to CamStack`)})]}):x(jE,{onApproved:()=>window.location.assign(B(gn(null,{status:`success`,action:`cli-login`}))),onDenied:()=>i(!0)})})]})})}var NE=`auth.password-incorrect`;function PE(e,t){return typeof e==`object`&&e?Reflect.get(e,t):void 0}function FE(e){if(!(e instanceof Error))return{kind:`connection-lost`};let t=PE(e,`data`);return typeof t!=`object`||!t?{kind:`connection-lost`}:PE(PE(t,`i18n`),`code`)===NE?{kind:`wrong-current`}:PE(t,`code`)===`UNAUTHORIZED`?{kind:`session-ended`}:{kind:`rejected`,message:e.message}}O();var IE=8;function LE(e,t){let n=FE(e);switch(n.kind){case`wrong-current`:return t(`changePassword.errorWrongCurrent`,`The current password is incorrect.`);case`session-ended`:return t(`changePassword.errorSessionEnded`,`Your session ended before the change was confirmed. Sign in again — try the new password first.`);case`connection-lost`:return t(`changePassword.errorConnectionLost`,`The connection to the hub dropped before it confirmed the change. Sign in again — try the new password first.`);case`rejected`:return n.message}}function RE(){let{t:e}=q(),{user:t,mustChangePassword:n,clearMustChangePassword:r,logout:i}=ax(),a=V(),o=ba(),c=ll(),[l,u]=w(``),[d,f]=w(``),[p,m]=w(``),[h,g]=w(!1),[_,v]=w(``),[y,b]=w(!1),S=n?Yb:l;return x(`div`,{className:`flex min-h-screen items-center justify-center bg-background p-4`,children:s(`div`,{className:`w-full max-w-sm`,children:[x(`div`,{className:`flex justify-center mb-8`,children:x(`img`,{src:o?.resolvedMode===`light`?B(`/brand/logo-horizontal-light.svg`):B(`/brand/logo-horizontal-dark.svg`),alt:e(`changePassword.camstackAdmin`,`CamStack Admin`),className:`h-12`})}),s(`form`,{onSubmit:async i=>{if(i.preventDefault(),v(``),!t){v(`Not signed in`);return}if(!n&&l.length===0){v(e(`changePassword.enterCurrent`,`Enter your current password`));return}if(d.length<IE){v(`Password must be at least ${IE} characters`);return}if(d!==p){v(`The two passwords do not match`);return}if(d===`changeme`){v(`Choose a password different from the seed default`);return}b(!0);try{await a.changeOwnPassword({currentPassword:S,newPassword:d}),r(),c(`/devices`,{replace:!0})}catch(t){v(LE(t,e))}finally{b(!1)}},className:`space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10`,children:[s(`div`,{className:`space-y-1`,children:[x(`h1`,{className:`text-sm font-semibold text-foreground`,children:e(`changePassword.setANewPassword`,`Set a new password`)}),x(`p`,{className:`text-xs text-foreground-subtle`,children:n?e(`changePassword.youMustRotateTheSeed`,`You must rotate the seed password before continuing.`):e(`changePassword.chooseANewPasswordFor`,`Choose a new password for your account.`)})]}),_&&x(`div`,{role:`alert`,className:`rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger`,children:_}),!n&&s(`div`,{className:`space-y-1.5`,children:[x(`label`,{className:`text-xs font-medium text-foreground-subtle`,children:e(`changePassword.currentPassword`,`Current password`)}),x(W,{"data-testid":`change-password-current`,type:h?`text`:`password`,value:l,onChange:e=>u(e.target.value),autoComplete:`current-password`,className:`w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all`,autoFocus:!0})]}),s(`div`,{className:`space-y-1.5`,children:[x(`label`,{className:`text-xs font-medium text-foreground-subtle`,children:e(`changePassword.newPassword`,`New password`)}),s(`div`,{className:`relative`,children:[x(W,{"data-testid":`change-password-new`,type:h?`text`:`password`,value:d,onChange:e=>f(e.target.value),autoComplete:`new-password`,className:`w-full rounded-lg border border-border bg-background px-3 py-2.5 pr-10 text-sm text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all`,autoFocus:n}),x(G,{variant:`unstyled`,type:`button`,onClick:()=>g(!h),className:`absolute right-2.5 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground transition-colors`,tabIndex:-1,children:x(h?vt:Fe,{className:`h-4 w-4`})})]})]}),s(`div`,{className:`space-y-1.5`,children:[x(`label`,{className:`text-xs font-medium text-foreground-subtle`,children:e(`changePassword.confirmNewPassword`,`Confirm new password`)}),x(W,{"data-testid":`change-password-confirm`,type:h?`text`:`password`,value:p,onChange:e=>m(e.target.value),autoComplete:`new-password`,className:`w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all`})]}),x(G,{variant:`unstyled`,"data-testid":`change-password-submit`,type:`submit`,disabled:y||!d||!p,className:`w-full rounded-lg bg-primary px-4 py-2.5 text-sm font-semibold text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg hover:shadow-primary/30 disabled:opacity-50 disabled:shadow-none transition-all`,children:y?e(`changePassword.saving`,`Saving…`):e(`changePassword.saveAndContinue`,`Save and continue`)}),n&&x(G,{variant:`unstyled`,type:`button`,onClick:()=>{i(),c(`/login`,{replace:!0})},className:`w-full text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:e(`changePassword.signOutInstead`,`Sign out instead`)})]})]})})}O();async function zE(e){if(!wE(e))throw Error(`passkey authentication options missing challenge`);let t=await SE({optionsJSON:e});return Object.fromEntries(Object.entries(t))}function BE({method:e,challengeToken:t,onComplete:n,onSecondFactor:r,onError:i}){let[a,o]=w(!1),[c,l]=w(null),u=async()=>{l(null),o(!0);try{let e=rb();if(t){let r=await zE((await e.loginBeginPasskey(t)).optionsJSON),i=await e.loginVerifyPasskey(t,r,{refreshable:!0});n(i.token,i);return}let a=await zE((await e.passkeyLoginBegin()).optionsJSON),o=await e.passkeyLoginFinish(a,{refreshable:!0}),s=o.secondFactors??(o.requiresTotp===!0?[`totp`]:[]);if(s.length>0){if(r)r({challengeToken:o.token,factors:s});else{let e=`Additional verification is required — sign in with your password to continue.`;l(e),i?.(e)}return}n(o.token,o)}catch(e){let n=t?`Passkey verification failed`:`Passkey sign-in failed`,r=e instanceof Error?e.message:n;l(r),i?.(r)}finally{o(!1)}};return s(`div`,{className:`space-y-2`,children:[s(G,{variant:`unstyled`,type:`button`,"data-testid":t?`login-passkey`:`login-passkey-direct`,onClick:()=>void u(),disabled:a,className:`w-full flex items-center justify-center gap-2 rounded-lg border border-border bg-surface px-4 py-2.5 text-sm font-medium text-foreground hover:bg-surface-hover disabled:opacity-50 transition-colors`,children:[a?x(H,{className:`h-4 w-4 animate-spin text-primary`}):x(ir,{className:`h-4 w-4 text-primary`}),e.label]}),c&&x(`div`,{className:`rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger`,children:c})]})}var VE=()=>window.location.hostname;function HE(e,t=VE,n=null){return n===!1?!1:pE()&&jw(t(),e.rpId)}function UE(e,t=VE,n=null){let r=e.filter(e=>e.kind===`passkey`&&e.stage===`second-factor`).filter(e=>HE(e,t,n));return{passkeyMethods:r,widgetMethods:r.length>0?[]:e.filter(e=>e.kind===`widget`&&e.stage===`second-factor`)}}function WE(e,t){let n=e.includes(`passkey`),r=t.passkeyMethods.length>0||t.widgetMethods.length>0,i=e.includes(`totp`);return n&&!r&&!i}O();async function GE(){if(typeof PublicKeyCredential>`u`)return null;let e=PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable;if(typeof e!=`function`)return null;try{return await e.call(PublicKeyCredential)}catch{return null}}var KE=()=>`camstackAgentApp`in window;function qE(){let[e,t]=w(null);return S(()=>{if(!KE())return;let e=!0;return GE().then(n=>{e&&t(n)}),()=>{e=!1}},[]),e}function JE(e){let t=e.onComplete,n=e.onSecondFactor;return typeof t==`function`?{onComplete:t,onSecondFactor:typeof n==`function`?n:void 0}:null}function YE({methods:e,widgetConfig:t,onRedirect:n}){let{t:r}=q();Bi();let i=qE(),a=e.filter(e=>e.kind!==`passkey`||HE(e,void 0,i));return a.length===0?null:s(`div`,{className:`mt-6 space-y-3`,children:[s(`div`,{className:`flex items-center gap-3`,children:[x(`div`,{className:`h-px flex-1 bg-border`}),x(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:r(`login.primaryLoginMethods.orContinueWith`,`Or continue with`)}),x(`div`,{className:`h-px flex-1 bg-border`})]}),x(`div`,{className:`space-y-2`,children:a.map(e=>{if(e.kind===`redirect`){let t=(e.icon===void 0?void 0:zr(e.icon))??pe;return s(`a`,{href:e.startUrl,onClick:t=>{n?.(e)===!0&&t.preventDefault()},className:`flex items-center justify-center gap-2 w-full rounded-lg border border-border bg-surface px-4 py-2.5 text-sm font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[x(t,{className:`h-4 w-4 text-primary`}),e.label]},e.id)}if(e.kind===`passkey`){let n=JE(t);return n?x(BE,{method:e,onComplete:n.onComplete,onSecondFactor:n.onSecondFactor},e.id):null}return x(XE,{method:e,config:t},e.id)})})]})}function XE({method:e,config:t}){let{t:n}=q(),r=Ya(e.remote,e.bundleUrl);return r===null?s(`div`,{className:`flex items-center justify-center gap-2 rounded-lg border border-border bg-background px-4 py-2.5 text-xs text-foreground-subtle`,children:[x(H,{className:`h-3.5 w-3.5 animate-spin`}),n(`common.loading`,`Loading…`)]}):r===void 0?s(`div`,{"data-testid":`login-method-load-error`,className:`flex items-center justify-center gap-2 rounded-lg border border-danger/20 bg-danger/10 px-4 py-2.5 text-xs text-danger`,children:[x(te,{className:`h-3.5 w-3.5 shrink-0`}),n(`login.primaryMethods.loadFailed`)]}):x(r,{instanceId:e.id,host:`dashboard`,config:t})}var ZE=4e3,QE=/^[A-Za-z0-9._-]{1,64}$/;function $E(e){if(e.action===`cli-login`)return nE(`access`);let t=e.addonId!==void 0&&QE.test(e.addonId)?e.addonId:null,n=e.integration!==void 0&&QE.test(e.integration)?e.integration:null;if(t!==null&&e.brokerId!==void 0)return nE(`connectivity`,{integration:t,kindSection:`brokers`});let r=n??t;return nE(`connectivity`,r===null?{}:{integration:r})}function eD(e,t){let n=t.opener;if(n===null||n.closed||Vo(n)!==t.origin)return!1;try{return n.postMessage({type:yd,ok:e.status===`success`,...e.brokerId===void 0?{}:{brokerId:e.brokerId},...e.status===`error`?{error:e.reason??`unknown`}:{}},t.origin),!0}catch{return!1}}O();var tD=500;function nD(e){let{t}=q();switch(e){case`access_denied`:return t(`oauthLanding.reason.access_denied`,`Access was denied, so nothing was connected.`);case`invalid_state`:return t(`oauthLanding.reason.invalid_state`,`This sign-in link expired or was already used. Start the sign-in again.`);case`invalid_request`:return t(`oauthLanding.reason.invalid_request`,`The request was not valid for this hub. Start the link again from the beginning.`);case`unknown_broker`:return t(`oauthLanding.reason.unknown_broker`,`That connection no longer exists. Add it again, then sign in.`);case`not_configured`:return t(`oauthLanding.reason.not_configured`,`The connection is missing its client ID or secret. Fill them in, save, then sign in.`);case`exchange_failed`:return t(`oauthLanding.reason.exchange_failed`,`The provider did not accept the sign-in. Check the client ID and secret, then try again.`);case`no_authorization_code`:return t(`oauthLanding.reason.no_authorization_code`,`The provider finished the sign-in without granting CamStack access. Start the sign-in again from the beginning.`);case`no_refresh_token`:return t(`oauthLanding.reason.no_refresh_token`,`The provider returned no long-lived access. Remove CamStack from the account’s connected apps, then sign in again.`);case`unavailable`:return t(`oauthLanding.reason.unavailable`,`The hub is still starting this integration. Wait a moment and try again.`);case`unknown`:return t(`oauthLanding.reason.unknown`,`Something went wrong. Try again in a moment.`)}}function rD({outcome:e}){let{t}=q(),n=nD(e.reason??`unknown`);if(e.status===`error`)return s(F,{children:[x(Ee,{className:`mx-auto h-8 w-8 text-danger`,"aria-hidden":!0}),x(`h1`,{"data-testid":`oauth-landing-title`,className:`text-sm font-semibold text-foreground`,children:t(`oauthLanding.errorTitle`,`Sign-in did not finish`)}),x(`p`,{"data-testid":`oauth-landing-reason`,className:`rounded-md border border-danger/20 bg-danger/10 px-3 py-2 text-xs text-danger`,children:n})]});if(e.action===`cli-login`)return s(F,{children:[x(De,{className:`mx-auto h-8 w-8 text-success`,"aria-hidden":!0}),x(`h1`,{"data-testid":`oauth-landing-title`,className:`text-sm font-semibold text-foreground`,children:t(`oauthLanding.cliLoginTitle`,`Terminal signed in`)}),x(`p`,{className:`text-xs text-foreground-muted`,children:t(`oauthLanding.cliLoginBody`,`Go back to your terminal: it finishes the sign-in by itself.`)})]});let r=e.action===`disconnect`;return s(F,{children:[x(De,{className:`mx-auto h-8 w-8 text-success`,"aria-hidden":!0}),x(`h1`,{"data-testid":`oauth-landing-title`,className:`text-sm font-semibold text-foreground`,children:r?t(`oauthLanding.signedOutTitle`,`Signed out`):t(`oauthLanding.successTitle`,`Signed in`)}),x(`p`,{className:`text-xs text-foreground-muted`,children:r?t(`oauthLanding.signedOutBody`,`The account was disconnected from this hub.`):t(`oauthLanding.successBody`,`The account is connected. Returning to CamStack…`)})]})}function iD({outcome:e,closable:t,onContinue:n,onClose:r}){let{t:i}=q(),a=$E(e);return S(()=>{if(e.status!==`success`)return;let t=window.setTimeout(()=>n(a),ZE);return()=>window.clearTimeout(t)},[e.status,n,a]),x(`main`,{className:`flex min-h-screen items-center justify-center bg-background p-4`,children:s(`div`,{className:`w-full max-w-sm space-y-4`,children:[x(`div`,{className:`flex justify-center`,children:s(`picture`,{children:[x(`source`,{media:`(prefers-color-scheme: dark)`,srcSet:B(`/brand/logo-horizontal-dark.svg`)}),x(`img`,{src:B(`/brand/logo-horizontal-light.svg`),alt:i(`oauthLanding.brand`,`CamStack`),className:`h-12`})]})}),s(`div`,{className:`space-y-4 rounded-xl border border-border bg-surface p-6 text-center shadow-xl shadow-black/10`,children:[x(rD,{outcome:e}),s(`div`,{className:`flex flex-col gap-2`,children:[x(G,{type:`button`,variant:`primary`,onClick:()=>n(a),children:i(`oauthLanding.back`,`Back to CamStack`)}),t&&x(G,{type:`button`,variant:`ghost`,onClick:r,children:i(`oauthLanding.close`,`Close this window`)})]})]})]})})}function aD(e,t){window.history.replaceState(null,``,window.location.pathname);let n=window.opener,r=eD(t,{opener:n,origin:window.location.origin}),i=()=>e.render(x(iD,{outcome:t,closable:r,onContinue:e=>window.location.replace(B(e)),onClose:()=>window.close()}));if(r&&t.status===`success`){window.close(),window.setTimeout(i,tD);return}i()}function oD(e){return Pn(e)}var sD=`Done — you can close this window.`,cD=500,lD=`camstack_admin_token`;async function uD(e,t=``){try{let n=mb(new URLSearchParams(t));n!==null&&n.token===e?db(n):localStorage.setItem(lD,e)}catch{}await fetch(B(`/api/auth/session`),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({token:e})}).catch(()=>{})}function dD(){try{let e=localStorage.getItem(lD);return e!==null&&e.length>0?e:null}catch{return null}}function fD(e){let t=oD(window.location.hash);if(t!==null){aD(e,t);return}let n=Io(window.location.hash);window.history.replaceState(null,``,window.location.pathname);let r=t=>e.render(x(pD,{completion:n,result:t,hasOpener:window.opener!==null}));if(r(null),n===null)return;let i=Ho();Wo(n,{opener:window.opener,origin:window.location.origin,channel:i,addEventListener:(e,t)=>window.addEventListener(e,t),removeEventListener:(e,t)=>window.removeEventListener(e,t),close:()=>{window.close(),window.setTimeout(()=>r({kind:`done`,message:sD}),cD)},continueAt:e=>window.location.replace(B(e)),persistSession:e=>uD(e,n.target===`login`?n.fragment:``),showResult:r,setTimeout:(e,t)=>window.setTimeout(e,t)})}function pD({completion:e,result:t,hasOpener:n=!0}){let{t:r}=q();return x(`div`,{className:`flex min-h-screen items-center justify-center bg-background p-4`,children:x(`div`,{className:`flex flex-col items-center gap-3 text-sm text-foreground-subtle`,children:e===null?x(`a`,{className:`text-primary underline`,href:B(`/login`),children:r(`ssoComplete.nothingToFinishHereGo`,`Nothing to finish here — go to sign-in`)}):t===null?s(`span`,{className:`flex items-center gap-3`,children:[x(`span`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-primary/30 border-t-primary`}),r(`ssoComplete.finishingSignIn`,`Finishing sign-in…`)]}):s(F,{children:[x(`span`,{"data-testid":`sso-complete-result`,className:t.kind===`link-error`?`text-danger`:`text-foreground`,children:t.message}),x(G,{variant:`unstyled`,type:`button`,className:`rounded-md border border-border px-3 py-1.5 text-foreground hover:bg-surface-hover`,onClick:()=>window.close(),children:r(`ssoComplete.closeThisWindow`,`Close this window`)}),!n&&x(`a`,{className:`text-primary underline`,href:B(`/login`),children:r(`ssoComplete.backToSignIn`,`Back to sign-in`)})]})})})}O();function mD(e){if(typeof e!=`object`||!e)return!1;let t=Reflect.get(e,`message`),n=Reflect.get(e,`data`);return(typeof n==`object`&&n?Reflect.get(n,`code`):void 0)===`FORBIDDEN`||typeof t==`string`&&/sign in again first/i.test(t)}function hD(){let e=new URLSearchParams(window.location.search);return kb({codeChallenge:e.get(`code_challenge`),codeChallengeMethod:e.get(`code_challenge_method`),state:e.get(`state`),purpose:e.get(`purpose`)})}function gD(e){return Math.min(1e3*2**e,15e3)}function _D(){let{t:e}=q(),{login:t,verifyTotp:n,finalizePasskeyLogin:r,user:i}=ax(),{i18n:a}=q(),o=ba(),c=ll(),l=Y(),u=new URLSearchParams(window.location.search).get(`next`);S(()=>{Rb(u)},[u]);let d=new URLSearchParams(window.location.search).get(`redirect`);S(()=>{qb(d)},[d]);let f=hD();S(()=>{Mb(f)},[f?.codeChallenge,f?.state,f?.purpose]);let m=l.state,h=IT(m?.from),[g,_]=w(``),[v,y]=w(``),[b,C]=w(!1),[T,E]=w(``),[D,O]=w(!1),[k,A]=w(`credentials`),[j,M]=w(``),[N,ee]=w([]),[P,I]=w(``),[L,te]=w(void 0),[ne,ie]=w(`sso-not-linked`),ae=Ka.auth.listLoginMethods.useQuery(void 0,{retry:!0,retryDelay:gD}),oe=ae.data===void 0,se=(ae.data??[]).filter(e=>e.kind!==`device-certificate`),R=Ka.auth.getServerName.useQuery().data,ce=se.filter(e=>e.stage===`primary`),le=UE(se,void 0,qE());S(()=>{let e=Go(window.location.hash);if(e!==null){if(window.history.replaceState({},``,window.location.pathname+window.location.search),e.kind===`challenge`){M(e.challengeToken),ee(e.factors),I(``),A(`second-factor`);return}ie(e.code),te(e.provider)}},[]);let ue=L==null?null:se.find(e=>e.id===L&&`label`in e)?.label??null,de=T||(L===void 0?``:Ro(ne,ue)),{passkeyMethods:fe,widgetMethods:z}=le,pe=p(!1),me=async()=>{if(pe.current)return;pe.current=!0;let e=Fb(d);if(e?.kind===`app-callback`){await _e(e.url);return}else if(e){window.location.assign(B(e.path));return}let t=Bb(u);t?window.location.assign(B(t)):c(h,{replace:!0})},[he,ge]=w(null),_e=async e=>{ge({callbackBase:e,mintedUrl:null,failed:!1});try{let t=hD()??Nb();if(t===null)throw Error(`The app sent no PKCE challenge and state`);let{code:n}=await rb().trpcClient.auth.createHandoffCode.mutate({purpose:t.purpose,codeChallenge:t.codeChallenge,state:t.state}),r=Pb(e,n,t.state);ge({callbackBase:e,mintedUrl:r,failed:!1}),window.location.assign(r)}catch(t){if(mD(t)){pe.current=!1,ge(null),E(`Sign in again to confirm it is you.`);return}ge({callbackBase:e,mintedUrl:null,failed:!0})}},ve=i!==null,[ye,be]=w(!1);S(()=>{!ve||!d&&!u||ye||(be(!0),me())},[ve,d,u,ye]);let xe=async e=>{e.preventDefault(),E(``),te(void 0),O(!0);try{let e=await t(g,v);if(e.kind===`second-factor`){M(e.challengeToken),ee(e.factors),A(`second-factor`);return}v===`changeme`?c(`/change-password`,{replace:!0}):await me()}catch(e){E(e instanceof Error?e.message:`Login failed`)}finally{O(!1)}},Se=async e=>{e.preventDefault(),E(``),O(!0);try{await n(j,P.trim()),await me()}catch(e){E(e instanceof Error?e.message:`TOTP verification failed`),I(``)}finally{O(!1)}},Ce=async(e,t)=>{try{await r(e,t),await me()}catch(e){E(e instanceof Error?e.message:`Passkey sign-in failed`)}},we=p(null);S(()=>()=>we.current?.(),[]);let Ee=async e=>{if(e.target!==`login`)return;let t=mb(new URLSearchParams(e.fragment));if(t!==null){try{await r(t.token,t),await me()}catch(e){E(e instanceof Error?e.message:`Sign-in failed`)}return}let n=Go(`#${e.fragment}`);if(n!==null){if(n.kind===`challenge`){Oe({challengeToken:n.challengeToken,factors:n.factors});return}ie(n.code),te(n.provider)}},De=e=>{if(Eb(d)?.kind===`app-callback`)return!1;let t=zo(B(Lo(e.startUrl)));return t===null?!1:(E(``),te(void 0),we.current?.(),we.current=Uo(t,{onReturn:e=>{we.current?.(),we.current=null,Ee(e)},onDone:e=>{if(we.current?.(),we.current=null,e.target!==`login`)return;let t=dD()===null?null:ub();t!==null&&Ee({target:`login`,fragment:new URLSearchParams({token:t.token,...t.refreshToken===void 0?{}:{refreshToken:t.refreshToken},...t.expiresAt===void 0?{}:{expiresAt:String(t.expiresAt)}}).toString()})}}),!0)},Oe=e=>{let t=e.factors.filter(e=>e===`totp`||e===`passkey`);M(e.challengeToken),ee(t),I(``),E(``),A(`second-factor`)};return he===null?x(`div`,{className:`flex min-h-screen items-center justify-center bg-background p-4`,children:s(`div`,{className:`w-full max-w-sm`,children:[x(`div`,{className:`flex justify-center mb-8`,children:x(`img`,{src:o?.resolvedMode===`light`?B(`/brand/logo-horizontal-light.svg`):B(`/brand/logo-horizontal-dark.svg`),alt:e(`login.camstackAdmin`,`CamStack Admin`),className:`h-12`})}),R!==void 0&&!R.isDefault&&x(`p`,{"data-testid":`login-server-name`,className:`-mt-4 mb-6 text-center text-sm text-foreground-muted`,children:x(_d,{i18nKey:`login.signInTo`,values:{name:R.name},components:{b:x(`span`,{className:`font-semibold text-foreground`})}})}),k===`credentials`?s(`form`,{onSubmit:xe,className:`space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10`,children:[de&&x(`div`,{"data-testid":`login-error`,className:`rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger`,children:de}),s(`div`,{className:`space-y-1.5`,children:[x(`label`,{className:`text-xs font-medium text-foreground-subtle`,children:e(`login.username`,`Username`)}),x(W,{"data-testid":`login-username`,type:`text`,placeholder:e(`login.username`,`Username`),value:g,onChange:e=>_(e.target.value),className:`w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all`,autoFocus:!0})]}),s(`div`,{className:`space-y-1.5`,children:[x(`label`,{className:`text-xs font-medium text-foreground-subtle`,children:e(`login.password`,`Password`)}),s(`div`,{className:`relative`,children:[x(W,{"data-testid":`login-password`,type:b?`text`:`password`,placeholder:e(`login.password`,`Password`),value:v,onChange:e=>y(e.target.value),className:`w-full rounded-lg border border-border bg-background px-3 py-2.5 pr-10 text-sm text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all`}),x(G,{variant:`unstyled`,type:`button`,onClick:()=>C(!b),className:`absolute right-2.5 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground transition-colors`,tabIndex:-1,children:x(b?vt:Fe,{className:`h-4 w-4`})})]})]}),x(G,{variant:`unstyled`,"data-testid":`login-submit`,type:`submit`,disabled:D||!g||!v,className:`w-full rounded-lg bg-primary px-4 py-2.5 text-sm font-semibold text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg hover:shadow-primary/30 disabled:opacity-50 disabled:shadow-none transition-all`,children:D?s(`span`,{className:`flex items-center justify-center gap-2`,children:[x(`span`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-primary-foreground/30 border-t-primary-foreground`}),e(`login.loggingIn`,`Logging in...`)]}):e(`login.logIn`,`Log in`)})]}):s(`div`,{className:`space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10`,children:[s(`div`,{className:`flex items-center gap-2 pb-1 border-b border-border`,children:[x(re,{className:`h-4 w-4 text-primary`}),x(`div`,{className:`text-sm font-medium text-foreground`,children:e(`login.twoFactorAuthentication`,`Two-factor authentication`)})]}),x(`p`,{className:`text-xs text-foreground-subtle`,children:g?x(F,{children:x(_d,{i18nKey:`login.finishSigningInAs`,values:{username:g},components:{mono:x(`span`,{className:`font-mono text-foreground`})}})}):e(`login.finishSigningInAs`,`Finish signing in.`)}),T&&x(`div`,{className:`rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger`,children:T}),N.includes(`passkey`)&&fe.map(e=>x(BE,{method:e,challengeToken:j,onComplete:Ce},e.id)),N.includes(`passkey`)&&z.map(e=>x(XE,{method:e,config:{challengeToken:j,onComplete:Ce}},e.id)),WE(N,le)&&x(`div`,{className:`rounded-md border border-border bg-background px-3 py-2 text-xs text-foreground-subtle`,children:e(`login.passkeyVerificationIsnTAvailable`,`Passkey verification isn't available on this address. Open the hub via its domain URL to complete sign-in.`)}),N.includes(`passkey`)&&N.includes(`totp`)&&s(`div`,{className:`flex items-center gap-3`,children:[x(`div`,{className:`h-px flex-1 bg-border`}),x(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`or`}),x(`div`,{className:`h-px flex-1 bg-border`})]}),N.includes(`totp`)&&s(`form`,{onSubmit:Se,className:`space-y-4`,children:[s(`div`,{className:`space-y-1.5`,children:[x(`label`,{className:`text-xs font-medium text-foreground-subtle`,children:e(`login.authenticationCode`,`Authentication code`)}),x(W,{"data-testid":`login-totp`,type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:P,onChange:e=>I(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-lg border border-border bg-background px-3 py-3 text-center text-2xl font-mono tracking-widest text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all`,autoFocus:!0})]}),x(G,{variant:`unstyled`,"data-testid":`login-totp-submit`,type:`submit`,disabled:D||P.length!==6,className:`w-full rounded-lg bg-primary px-4 py-2.5 text-sm font-semibold text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg hover:shadow-primary/30 disabled:opacity-50 disabled:shadow-none transition-all`,children:D?s(`span`,{className:`flex items-center justify-center gap-2`,children:[x(`span`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-primary-foreground/30 border-t-primary-foreground`}),e(`login.verifying`,`Verifying...`)]}):e(`login.verifyAndSignIn`,`Verify and sign in`)})]}),s(G,{variant:`unstyled`,type:`button`,onClick:()=>{A(`credentials`),M(``),ee([]),I(``),E(``)},className:`w-full flex items-center justify-center gap-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:[x(Te,{className:`h-3 w-3`}),e(`login.backToUsernamePassword`,`Back to username + password`)]})]}),k===`credentials`&&oe&&s(`p`,{"data-testid":`login-methods-pending`,role:`status`,className:`mt-4 flex items-center justify-center gap-2 text-xs text-foreground-subtle`,children:[x(`span`,{className:`h-3 w-3 animate-spin rounded-full border-2 border-foreground-subtle/30 border-t-foreground-subtle`}),e(`login.methodsPending`,`Loading other sign-in options...`)]}),k===`credentials`&&x(YE,{methods:ce,widgetConfig:{onComplete:Ce,onSecondFactor:Oe,locale:a.language},onRedirect:De}),x(`p`,{className:`mt-6 text-center text-[10px] text-foreground-subtle/50`,children:x(UT,{placement:`login`})})]})}):x(`div`,{className:`flex min-h-screen items-center justify-center bg-background p-4`,children:s(`div`,{className:`w-full max-w-sm rounded-xl border border-border bg-surface p-6 text-center space-y-4`,children:[x(`h1`,{className:`text-sm font-semibold text-foreground`,children:e(`login.returningToTheApp`,`Returning to the app…`)}),he.failed?s(F,{children:[x(`p`,{className:`text-xs text-danger`,children:e(`login.couldNotPrepareTheSign`,`Could not prepare the sign-in handoff. You are logged in — retry below.`)}),x(G,{variant:`unstyled`,onClick:()=>void _e(he.callbackBase),className:`inline-flex rounded-lg bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90`,children:e(`common.retry`,`Retry`)})]}):he.mintedUrl===null?x(`p`,{className:`text-xs text-foreground-subtle`,children:e(`login.preparingAOneTimeSign`,`Preparing a one-time sign-in code…`)}):s(F,{children:[x(`p`,{className:`text-xs text-foreground-subtle`,children:e(`login.ifTheAppDoesNot`,`If the app does not open automatically, tap below (the code expires in 60s).`)}),x(`a`,{href:he.mintedUrl,className:`inline-flex rounded-lg bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90`,children:e(`login.openCamstack`,`Open CamStack`)})]})]})})}function vD(e){let t=new URLSearchParams(e).get(mw),n=new URLSearchParams({tab:`templates`});return t!==null&&n.set(mw,t),`/build?${n.toString()}`}function yD(){let{search:e}=Y();return x(X,{to:vD(e),replace:!0})}O();function bD(){let{pathname:e,search:t,hash:n}=Y();return x(X,{to:`${aE(e)}${t}${n}`,replace:!0})}function xD(){let{pathname:e,search:t}=Y();return x(X,{to:Rs(e,t)??`/archive`,replace:!0})}function SD(){let{nodeId:e=``}=pl();return x(X,{to:`/system/terminal?tab=shells&node=${encodeURIComponent(e)}`,replace:!0})}function CD(){let{pathname:e,search:t}=Y(),n=Rs(e,t);return n===null?x(ND,{}):x(X,{to:n,replace:!0})}function wD(){return x(X,{to:PT()??`/devices`,replace:!0})}var TD=g(()=>a(()=>import(`./Devices-VYfr6Qjh.js`).then(e=>({default:e.DevicesPage})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11]),import.meta.url)),ED=g(()=>a(()=>import(`./Integrations-CE8kyRYx.js`).then(e=>({default:e.IntegrationsPage})),__vite__mapDeps([12,1,2,3,4,5,13,6,14,7,8,10]),import.meta.url)),DD=g(()=>a(()=>import(`./IntegrationDetail-Bz-VToH2.js`).then(e=>({default:e.IntegrationDetailPage})),__vite__mapDeps([15,1,2,3,4,5,16,6,8,9]),import.meta.url)),OD=g(()=>a(()=>import(`./Pipeline-C5FSBQqW.js`).then(e=>({default:e.PipelinePage})),__vite__mapDeps([17,1,2,3,4,5,13,6,18,19,20,21,22,23,24,25,10]),import.meta.url)),kD=g(()=>a(()=>import(`./DeviceDetail-BbhNElsK.js`).then(e=>({default:e.DeviceDetailPage})),__vite__mapDeps([26,1,2,3,4,5,13,6,18,27,28,29,21,30,31,32,33,34,35,36,37,38,39,40,24,10,41,42,43]),import.meta.url)),AD=g(()=>a(()=>import(`./Showroom-BZ5FVUHJ.js`).then(e=>({default:e.ShowroomPage})),__vite__mapDeps([44,1,2,3,4,5]),import.meta.url)),jD=g(()=>a(()=>import(`./EmbedPlayerPage-Z2tf61w_.js`).then(e=>({default:e.EmbedPlayerPage})),__vite__mapDeps([45,1,2,3,4,5,6]),import.meta.url)),MD=g(()=>a(()=>import(`./EmbedDevicePage-R7WS-d3D.js`).then(e=>({default:e.EmbedDevicePage})),__vite__mapDeps([46,1,2,3,4,5,6]),import.meta.url)),ND=g(()=>a(()=>import(`./Library-BOlhpDfS.js`).then(e=>({default:e.LibraryPage})),__vite__mapDeps([47,1,2,3,4,5,13,6,18,48,20,49,50,51,52,41,38,53]),import.meta.url)),PD=g(()=>a(()=>import(`./Archive-tvC3GS9d.js`).then(e=>({default:e.ArchivePage})),__vite__mapDeps([54,1,2,3,4,5,13,6,18,55,49,50,51,37,38,56,57,58,59,60,22,23,53,41]),import.meta.url)),FD=g(()=>a(()=>import(`./Viewer-Cm8XLQl9.js`).then(e=>({default:e.ViewerPage})),__vite__mapDeps([61,2,3,4,5,62,6,38,1]),import.meta.url)),ID=g(()=>a(()=>import(`./Build-FmDDr5Iv.js`).then(e=>({default:e.BuildPage})),__vite__mapDeps([63,1,2,3,4,5,13,6,18,27,64,50,30,31,32,33,34,35,36,40,42,65]),import.meta.url)),LD=g(()=>a(()=>import(`./CompositionEditorPage-CKvufPBG.js`).then(e=>({default:e.CompositionEditorPage})),__vite__mapDeps([66,1,2,3,4,5,6,7,30,13,18,27,31,32,33,34,35,36]),import.meta.url)),RD=g(()=>a(()=>import(`./Locations-BEURX3s_.js`).then(e=>({default:e.LocationsPage})),__vite__mapDeps([67,1,2,3,4,5,13,6,50,39,34,35]),import.meta.url)),zD=g(()=>a(()=>import(`./Addons-b61CNfYt.js`).then(e=>({default:e.AddonsPage})),__vite__mapDeps([68,1,2,3,4,5,18,6,7,69,22,23,11,38]),import.meta.url)),BD=g(()=>a(()=>import(`./AiProfiles-DabE0DP8.js`).then(e=>({default:e.AiProfilesPage})),__vite__mapDeps([70,1,2,3,4,5,13,6,71,72,7,50,59,60,22,23,38,73]),import.meta.url)),VD=g(()=>a(()=>import(`./MyAccess-DRCDj6Xz.js`).then(e=>({default:e.MyAccessPage})),__vite__mapDeps([74,1,2,3,4,5,13,6,18,75,32,7,50,76,77,38,78]),import.meta.url)),HD=g(()=>a(()=>import(`./Logs-Do0Qz1Xm.js`).then(e=>({default:e.LogsPage})),__vite__mapDeps([79,1,2,3,4,5,21,80,6,7,50,59,60,22,23,38]),import.meta.url)),UD=g(()=>a(()=>import(`./Identity-D4kdH7U7.js`).then(e=>({default:e.IdentityPage})),__vite__mapDeps([81,1,2,3,4,5,13,6,18,31,82,75,32,7,50,59,60,22,23,38,76,77,83]),import.meta.url)),WD=g(()=>a(()=>import(`./Network-ZDD_Mojs.js`).then(e=>({default:e.NetworkPage})),__vite__mapDeps([84,1,2,3,4,5,13,6,18,7,50,59,60,22,23,38,85]),import.meta.url)),GD=g(()=>a(()=>import(`./Integrations-BzM7SsEz.js`).then(e=>({default:e.IntegrationsPage})),__vite__mapDeps([86,1,2,3,4,5,6,50,59,60,22,23,38]),import.meta.url)),KD=g(()=>a(()=>import(`./TrainingProviders-DcR68K6U.js`).then(e=>({default:e.TrainingProvidersPage})),__vite__mapDeps([87,1,2,3,4,5,6,7,59,60,22,23,38]),import.meta.url)),qD=g(()=>a(()=>import(`./Data-C2vZTveq.js`).then(e=>({default:e.DataPage})),__vite__mapDeps([88,1,2,3,4,5,13,6,18,28,89,58,7,50,59,60,22,23,38,56,57,53,41]),import.meta.url)),JD=g(()=>a(()=>import(`./System-CXy2jAEJ.js`).then(e=>({default:e.SystemPage})),__vite__mapDeps([90,1,2,3,4,5,13,6,91,7,50,83,23,38]),import.meta.url)),YD=g(()=>a(()=>import(`./Cluster-B0FV-fZt.js`).then(e=>({default:e.ClusterPage})),__vite__mapDeps([92,1,2,3,4,5,13,6,58,93,32,7,69,40,22,23,25,53]),import.meta.url)),XD=g(()=>a(()=>import(`./Terminal-BzVEx5-W.js`).then(e=>({default:e.TerminalPage})),__vite__mapDeps([94,1,2,3,4,5,18,6,7,59,60,22,23,38,76,33,40,13,85,95]),import.meta.url)),ZD=g(()=>a(()=>import(`./Notifications-BnLCpPnP.js`).then(e=>({default:e.NotificationsPage})),__vite__mapDeps([96,1,2,3,4,5,13,6,71,97,7,50,59,60,22,23,38,40,52,65,36,73,35,43]),import.meta.url)),QD=g(()=>a(()=>import(`./History-Bo9FgRVX.js`).then(e=>({default:e.HistoryPage})),__vite__mapDeps([98,1,2,3,4,5,18,6,7]),import.meta.url)),$D=g(()=>a(()=>import(`./Calendars-CdCIOI6j.js`).then(e=>({default:e.CalendarsPage})),__vite__mapDeps([99,1,2,3,4,5,13,6,7]),import.meta.url)),eO=new D({defaultOptions:{queries:{gcTime:0,staleTime:0,retry:!1,refetchOnWindowFocus:!1}}});Ta(eO);function tO({field:e,value:t,onChange:n,disabled:r}){return x(XS,{field:e,value:t,onChange:n,disabled:r})}var nO={"model-selector":tO};function rO({children:e}){let{t}=q(),{user:n,logout:r}=ax(),[i,a]=w(0),o=p(n?.username??null);S(()=>{let e=n?.username??null;e!==o.current&&(o.current=e,ib(),a(e=>e+1))},[n]);let c=m(()=>rb(),[i]),l=b(()=>{rb().reconnect(),a(e=>e+1),eO.invalidateQueries()},[]);xC(b(()=>Cb(l),[l])),S(()=>yb(()=>{rb().isSocketTokenStale()&&l()}),[l]);let u=b(async()=>{let e=await wb();return e&&l(),e},[l]),{bootReady:d,bootError:f}=yC(c,n??null,r,u);return x(gC,{children:x(Je,{system:c,children:x(Ka.Provider,{client:c.trpcClient,queryClient:eO,children:s(ga,{children:[x(Qr,{children:x(ha,{children:x(wr,{children:d?e:x(iO,{})})})}),d&&x(nC,{}),f!==null&&d&&s(`div`,{className:`fixed bottom-[calc(env(safe-area-inset-bottom)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)] z-50 max-w-sm rounded-lg border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning shadow-lg`,children:[t(`app.bootProbeFailed`,`Boot probe failed:`),` `,f,`. Retrying in background.`]})]})})})})}function iO(){let{t:e}=q();return x(`div`,{className:`flex min-h-screen items-center justify-center bg-background`,children:s(`div`,{className:`flex items-center gap-3 text-sm text-foreground-subtle`,children:[x(`span`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-primary/30 border-t-primary`}),e(`app.connecting`,`Connecting…`)]})})}function aO(){return x(`div`,{className:`flex min-h-screen items-center justify-center bg-background`,children:x(`span`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-primary/30 border-t-primary`})})}function oO(){return S(()=>lE(),[]),x(ta,{defaultMode:`dark`,children:x(ti,{children:x(P,{client:eO,children:x(ix,{children:x(rO,{children:x(Xe,{children:x(tC,{children:x(vo,{renderers:nO,children:s(xo,{picker:ay,children:[x(Du,{basename:pt(),children:x(WS,{children:x(y,{fallback:x(aO,{}),children:s(Rl,{children:[x(Z,{path:`/login`,element:x(_D,{})}),x(Z,{path:`/admin/*`,element:x(bD,{})}),x(Z,{path:`/admin`,element:x(bD,{})}),x(Z,{path:`/change-password`,element:x($,{children:x(RE,{})})}),x(Z,{path:`/approve`,element:x($,{children:x(ME,{})})}),x(Z,{path:`/showroom`,element:x(AD,{})}),x(Z,{path:`/embed/player`,element:x(jD,{})}),x(Z,{path:`/embed/device/:deviceId`,element:x($,{children:x(MD,{})})}),s(Z,{element:x($,{children:x(pv,{children:x(XT,{})})}),children:[x(Z,{index:!0,element:x(wD,{})}),x(Z,{path:`/access-denied`,element:x(uE,{})}),x(Z,{path:`/dashboard`,element:x(X,{to:`/devices`,replace:!0})}),x(Z,{path:`/devices`,element:x(TD,{})}),x(Z,{path:`/cameras`,element:x(X,{to:`/devices`,replace:!0})}),x(Z,{path:`/integrations`,element:x(ED,{})}),x(Z,{path:`/integrations/:addonId`,element:x(DD,{})}),x(Z,{path:`/system/pipeline`,element:x($C,{path:`/system/pipeline`,children:x(OD,{})})}),x(Z,{path:`/pipeline`,element:x(X,{to:`/system/pipeline`,replace:!0})}),x(Z,{path:`/live`,element:x(FD,{})}),x(Z,{path:`/devices/:deviceId`,element:x(kD,{})}),x(Z,{path:`/system/logs`,element:x($,{requireAdmin:!0,children:x(HD,{})})}),x(Z,{path:`/system/addons`,element:x($,{requireAdmin:!0,children:x(zD,{})})}),x(Z,{path:`/system/ai`,element:x($,{requireAdmin:!0,children:x(BD,{})})}),x(Z,{path:`/system/settings`,element:x($,{requireAdmin:!0,children:x(JD,{})})}),x(Z,{path:`/system/nodes`,element:x($,{requireAdmin:!0,children:x(YD,{})})}),x(Z,{path:`/system/notifications`,element:x($,{requireAdmin:!0,children:x(ZD,{})})}),x(Z,{path:`/system/history`,element:x($,{requireAdmin:!0,children:x(QD,{})})}),x(Z,{path:`/system/calendars`,element:x($,{requireAdmin:!0,children:x($D,{})})}),x(Z,{path:`/system/templates`,element:x(yD,{})}),x(Z,{path:`/system/identity`,element:x($,{requireAdmin:!0,children:x(UD,{})})}),x(Z,{path:`/system/my-access`,element:x(VD,{})}),x(Z,{path:`/system/network`,element:x($,{requireAdmin:!0,children:x(WD,{})})}),x(Z,{path:`/training/providers`,element:x($,{requireAdmin:!0,children:x(KD,{})})}),x(Z,{path:`/system/integrations`,element:x($,{requireAdmin:!0,children:x(GD,{})})}),x(Z,{path:`/system/data`,element:x($,{requireAdmin:!0,children:x(qD,{})})}),x(Z,{path:`/system`,element:x(X,{to:aC,replace:!0})}),x(Z,{path:`/system/terminal/:nodeId/*`,element:x(SD,{})}),x(Z,{path:`/system/terminal`,element:x($,{requireAdmin:!0,children:x(XD,{})})}),x(Z,{path:lC,element:x(fC,{})}),oC.map(e=>x(Z,{path:e.path,element:x(dC,{tab:e.tab})},e.path)),x(Z,{path:`/system/users`,element:x(X,{to:`/system/identity?tab=users`,replace:!0})}),x(Z,{path:`/system/api-keys`,element:x(X,{to:`/system/identity?tab=api-keys`,replace:!0})}),x(Z,{path:`/system/authentication`,element:x(X,{to:nE(`authentication`),replace:!0})}),x(Z,{path:`/system/linked-sessions`,element:x(X,{to:`/system/identity?tab=linked-sessions`,replace:!0})}),x(Z,{path:`/system/remote-access`,element:x(X,{to:nE(`remoteAccess`),replace:!0})}),x(Z,{path:`/system/turn`,element:x(X,{to:nE(`turn`),replace:!0})}),x(Z,{path:`/system/storage`,element:x(X,{to:`/system/data?tab=storage`,replace:!0})}),x(Z,{path:`/system/backup`,element:x(X,{to:`/system/data?tab=backup`,replace:!0})}),x(Z,{path:`/library`,element:x($,{requireAdmin:!0,children:x(CD,{})})}),x(Z,{path:`/retrain`,element:x(X,{to:`/addon/training`,replace:!0})}),x(Z,{path:`/archive`,element:x($,{requireAdmin:!0,children:x(PD,{})})}),x(Z,{path:`/archive/:deviceId`,element:x(xD,{})}),x(Z,{path:`/recordings`,element:x(xD,{})}),x(Z,{path:`/build`,element:x($,{requireAdmin:!0,children:x(ID,{})})}),x(Z,{path:dy,element:x($,{requireAdmin:!0,children:x(LD,{})})}),x(Z,{path:fy,element:x($,{requireAdmin:!0,children:x(LD,{})})}),x(Z,{path:`/locations`,element:x($,{requireAdmin:!0,children:x(RD,{})})}),x(Z,{path:`/automation`,element:x(ZS,{to:`/build`})}),x(Z,{path:`/addon/:pagePath`,element:x($,{requireAdmin:!0,children:x(GC,{})})}),x(Z,{path:`*`,element:x(X,{to:`/devices`,replace:!0})})]})]})})})}),x(hC,{}),x(Ss,{})]})})})})})})})})})}O(),window.__camstackUiLibrary=Wa,window.__camstackSdk=uo,window.__camstackTypes=qn;var sO=Eo(document.getElementById(`root`));Bo(window.location.pathname,pt())?fD(sO):sO.render(x(T,{children:x(oO,{})}));export{oy as $,nm as $n,wf as $r,Lh as $t,fS as A,Ps as Ai,Cm as An,Lf as Ar,Vg as At,fb as B,um as Bn,zf as Br,dg as Bt,eC as C,ll as Ci,bm as Cn,Hf as Cr,T_ as Ct,hS as D,As as Di,Dm as Dn,Zf as Dr,i_ as Dt,SS as E,js as Ei,km as En,Yf as Er,a_ as Et,Gx as F,xm as Fn,Af as Fr,Qg as Ft,py as G,$p as Gn,Kf as Gr,Oh as Gt,Ay as H,hm as Hn,fp as Hr,cg as Ht,xx as I,Nm as In,jf as Ir,qg as It,uy as J,cm as Jn,Qf as Jr,jh as Jt,_y as K,sm as Kn,Mf as Kr,wh as Kt,cx as L,zm as Ln,up as Lr,Zg as Lt,uS as M,Es as Mi,jm as Mn,tp as Mr,Yg as Mt,aS as N,Ts as Ni,Om as Nn,ap as Nr,__ as Nt,gS as O,Ms as Oi,wm as On,np as Or,r_ as Ot,iS as P,ws as Pi,Am as Pn,Uf as Pr,n_ as Pt,ly as Q,im as Qn,Ef as Qr,Ph as Qt,sx as R,gm as Rn,If as Rr,b_ as Rt,uC as S,Y as Si,ym as Sn,qf as Sr,F_ as St,wS as T,Lu as Ti,Wm as Tn,Of as Tr,x_ as Tt,Ey as U,_m as Un,Wf as Ur,Kh as Ut,Ly as V,pm as Vn,ep as Vr,lg as Vt,by as W,mm as Wn,Jf as Wr,Ih as Wt,my as X,am as Xn,ip as Xr,Sh as Xt,hy as Y,tm as Yn,Xf as Yr,Ch as Yt,yy as Z,rm as Zn,Nf as Zr,Dh as Zt,xw as _,xd as _i,Zm as _n,xp as _r,tv as _t,eE as a,rf as ai,gh as an,Xp as ar,Nv as at,ZC as b,ku as bi,Ym as bn,$f as br,G_ as bt,nE as c,cf as ci,hh as cn,Vp as cr,Cv as ct,Ww as d,lf as di,dh as dn,Hp as dr,bv as dt,xf as ei,Bh as en,Jp as er,ny as et,Vw as f,of as fi,oh as fn,Up as fr,mv as ft,vw as g,gf as gi,$m as gn,Dp as gr,$_ as gt,yw as h,_f as hi,eh as hn,yp as hr,rv as ht,$T as i,mf as ii,vh as in,Gp as ir,Iv as it,dS as j,Cs as ji,Pm as jn,rp as jr,Rg as jt,vS as k,Ns as ki,Fm as kn,lp as kr,g_ as kt,rE as l,uf as li,ph as ln,Pp as lr,Sv as lt,Sw as m,pf as mi,Jm as mn,vp as mr,iv as mt,EE as n,sf as ni,Eh as nn,Qp as nr,Vv as nt,ZT as o,af as oi,_h as on,Zp as or,Ov as ot,Hw as p,nf as pi,qm as pn,wp as pr,av as pt,vy as q,om as qn,Pf as qr,Rh as qt,tE as r,tf as ri,Ah as rn,Yp as rr,Lv as rt,QT as s,df as si,yh as sn,Rp as sr,Mv as st,AE as t,ff as ti,Th as tn,zp as tr,Hv as tt,iE as u,hf as ui,fh as un,Mp as ur,xv as ut,mw as v,wd as vi,Km as vn,Cp as vr,W_ as vt,BS as w,pl as wi,Lm as wn,Gf as wr,E_ as wt,aC as x,X as xi,Xm as xn,dp as xr,U_ as xt,hw as y,_d as yi,th as yn,Sp as yr,K_ as yt,ax as z,lm as zn,Rf as zr,pg as zt};
|
|
6
|
+
// here the editor could re-open this block and overwrite everything below.`;function vw(e){return e.includes(gw)}function yw(e){return!vw(e.code)}function bw(e){let t=e.indexOf(gw);if(t<0)return null;let n=e.indexOf(`{`,t+25);if(n<0)return null;let r=0,i=!1,a=!1;for(let o=n;o<e.length;o+=1){let s=e.charAt(o);if(i){a?a=!1:s===`\\`?a=!0:s===`"`&&(i=!1);continue}if(s===`"`){i=!0;continue}if(s===`{`)r+=1;else if(s===`}`&&(--r,r===0))return{declStart:t,literalEnd:o+1,json:e.slice(n,o+1)}}return null}function xw(e){let t=bw(e);if(t===null)return{ok:!1,reason:K.t(`helpers.recipeFromCode.noLiteral`)};let n;try{n=JSON.parse(t.json)}catch(e){let t=e instanceof Error?e.message:String(e);return{ok:!1,reason:K.t(`helpers.recipeFromCode.badJson`,{detail:t})}}let r=Tn.safeParse(n);if(!r.success){let e=r.error.issues[0];return{ok:!1,reason:e===void 0?K.t(`helpers.recipeFromCode.schemaMismatch`):K.t(`helpers.recipeFromCode.schemaMismatchAt`,{path:e.path.join(`.`),message:e.message})}}return{ok:!0,recipe:r.data}}function Sw(e){let t=bw(e);if(t===null)return e;let n=e.slice(t.literalEnd),r=/^\s*as\s+const/.exec(n),i=t.literalEnd+(r===null?0:r[0].length);return`${e.slice(0,t.declStart)}${_w}${e.slice(i)}`}function Cw(e,t,n){return`/build?tab=${e}&${t}=${encodeURIComponent(n)}`}function ww(e){return e??[]}function Tw(e){let t=[];for(let n of e.blocks??[])vw(n.code)?t.push({key:`automation:${n.id}`,domain:`automation`,label:n.name,keywords:ww(n.tags),path:Cw(`automations`,`block`,n.id)}):On(n)===`code`&&yw(n)&&t.push({key:`script:${n.id}`,domain:`script`,label:n.name,keywords:ww(n.tags),path:Cw(`scripts`,`block`,n.id)});for(let n of e.schedulers??[])t.push({key:`scheduler:${n.id}`,domain:`scheduler`,label:n.name,keywords:ww(n.tags),path:Cw(`schedulers`,`scheduler`,n.id)});for(let n of e.actions??[])t.push({key:`action:${n.id}`,domain:`action`,label:n.name,keywords:ww(n.tags),path:Cw(`actions`,`action`,n.id)});for(let n of e.templates??[])t.push({key:`template:${n.id}`,domain:`template`,label:n.name,subtitle:n.kind,keywords:ww(n.tags),path:hw(n.id)});for(let n of e.compositions??[])t.push({key:`customDevice:${n.block.id}`,domain:`customDevice`,label:n.block.name,keywords:ww(n.block.tags),path:gy(n.block.id)});return t}O();var Ew={device:{labelKey:`search.resultsList.devices`,icon:Ke},page:{labelKey:`search.resultsList.pages`,icon:fr},integration:{labelKey:`search.resultsList.integrations`,icon:ft},automation:{labelKey:`search.resultsList.automations`,icon:oe},script:{labelKey:`search.resultsList.scripts`,icon:lr},scheduler:{labelKey:`search.resultsList.schedulers`,icon:rt},action:{labelKey:`search.resultsList.actions`,icon:we},template:{labelKey:`search.resultsList.templates`,icon:nr},customDevice:{labelKey:`search.resultsList.customDevices`,icon:Ct}};function Dw({groups:e,activeKey:t,query:n,totalMatched:r,truncated:i,pending:a=!1,onSelect:o,onHover:c}){let{t:l}=q(),u=p(null);if(S(()=>{t&&(u.current?.querySelector(`[data-key="${CSS.escape(t)}"]`))?.scrollIntoView({block:`nearest`})},[t]),n.trim().length===0)return null;if(e.length===0&&a)return x(`div`,{role:`status`,className:`px-3 py-4 text-center text-[12px] text-foreground-subtle`,"data-testid":`search-pending`,children:l(`search.resultsList.searching`,`Searching…`)});if(e.length===0)return x(`div`,{className:`px-3 py-4 text-center text-[12px] text-foreground-subtle`,children:l(`search.resultsList.noResults`,{query:n})});let d=e.reduce((e,t)=>e+t.items.length,0);return s(F,{children:[x(`div`,{ref:u,role:`listbox`,className:`max-h-[60vh] overflow-y-auto py-1`,children:e.map(e=>{let n=Ew[e.domain],r=n.icon;return s(`div`,{className:`px-1 py-1`,children:[s(`div`,{className:`sticky top-0 z-10 flex items-center gap-1.5 bg-surface px-2 py-1 text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/60`,children:[x(r,{className:`h-3 w-3`}),l(n.labelKey)]}),e.items.map(e=>{let r=e.icon??n.icon,i=e.key===t;return s(G,{variant:`unstyled`,type:`button`,role:`option`,"aria-selected":i,"data-key":e.key,onMouseEnter:()=>c(e),onClick:()=>o(e),className:`flex w-full items-center gap-2.5 rounded-md px-2 py-1.5 text-left text-[12px] transition-colors ${i?`bg-primary/12 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[x(r,{className:`h-3.5 w-3.5 shrink-0 ${i?`text-primary`:`text-foreground-subtle`}`}),s(`span`,{className:`flex-1 min-w-0`,children:[x(`span`,{className:`block truncate font-medium`,children:e.label}),e.subtitle&&x(`span`,{className:`block truncate text-[10px] text-foreground-subtle`,children:e.subtitle})]})]},e.key)})]},e.domain)})}),i&&x(`div`,{className:`border-t border-border px-3 py-1.5 text-center text-[10px] text-foreground-subtle`,children:l(`search.truncatedResults`,`Showing first {{shown}} of {{total}} — refine your search.`,{shown:d,total:r})})]})}O(),wo();function Ow({navSections:e,addonPages:t,compact:n,onNavigated:r}){let{t:i}=q(),a=ll(),o=p(null),c=p(null),l=p(null),[u,d]=w(null),[f,h]=w(``),[g,_]=w(0),[v,y]=w(!1),{data:C}=Zi({projection:`slim`}),{data:T}=za(void 0),E=v&&f.trim().length>0,D={enabled:E},O=Ba({},D),k=Za({},D),A=na({},D),j=Rr({},D),M=da({},D),N=E&&[O,k,A,j,M].some(e=>e.isLoading),ee=m(()=>{let n={detection:i(`nav.detectionSection`,`Detection`),cluster:i(`nav.clusterSection`,`Cluster`),administration:i(`system.title`,`Administration`),ungrouped:i(`nav.addonPages`,`Addon Pages`)};return[...uw(C??[],T??null),...pw(e,t,n),...dw(T??[]),...Tw({blocks:O.data?.blocks,actions:k.data,schedulers:A.data,templates:j.data,compositions:M.data?.state===`loaded`?M.data.views:void 0})]},[C,T,e,t,i,O.data,k.data,A.data,j.data,M.data]),{groups:P,totalMatched:F,truncated:I}=m(()=>ow(ee,f),[ee,f]),L=m(()=>sw(P),[P]);S(()=>{_(0)},[f,ee]),S(()=>{v&&o.current?.focus()},[v]);let te=b(()=>{y(!1),h(``),_(0)},[]),re=b(e=>{a(e.path),te(),o.current?.blur(),r?.()},[a,te,r]);Fr(o,{scope:Gr}),S(()=>{if(!v)return;function e(e){if(!(e.target instanceof Node))return;let t=c.current?.contains(e.target)===!0,n=l.current?.contains(e.target)===!0;!t&&!n&&y(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[v]);let ie=v&&f.trim().length>0;S(()=>{if(!ie){d(null);return}let e=()=>{let e=o.current?.getBoundingClientRect();e&&d({left:e.left,top:e.bottom+4,width:e.width})};return e(),window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},[ie]);let ae=L[g]?.key??null,oe=i(`search.placeholder`,`Search devices, pages, automations, scripts…`),se=s(`div`,{className:`relative`,children:[x(ne,{className:`pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`}),x(W,{ref:o,type:`text`,value:f,placeholder:oe,"aria-label":oe,role:`combobox`,"aria-expanded":v&&f.trim().length>0,"aria-controls":`global-search-results`,onChange:e=>{h(e.target.value),y(!0)},onFocus:()=>y(!0),onKeyDown:e=>{if(e.key===`ArrowDown`)e.preventDefault(),L.length>0&&_(e=>(e+1)%L.length);else if(e.key===`ArrowUp`)e.preventDefault(),L.length>0&&_(e=>(e-1+L.length)%L.length);else if(e.key===`Enter`){e.preventDefault();let t=L[g];t&&re(t)}else e.key===`Escape`&&(e.preventDefault(),te(),o.current?.blur())},className:`w-full rounded-md border border-border bg-surface py-1.5 pl-7 pr-6 text-[12px] text-foreground placeholder:text-foreground-subtle/70 focus:outline-none focus:ring-1 focus:ring-primary/50`}),f.length>0&&x(G,{variant:`unstyled`,type:`button`,"aria-label":i(`search.globalSearch.clearSearch`,`Clear search`),onClick:()=>{h(``),o.current?.focus()},className:`absolute right-1.5 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground`,children:x(xe,{className:`h-3 w-3`})}),ie&&u!==null&&To(x(`div`,{ref:l,id:`global-search-results`,className:`fixed z-50 w-max max-w-[26rem] rounded-lg border border-border bg-surface shadow-xl`,style:{left:u.left,top:u.top,minWidth:u.width},children:x(Dw,{groups:P,activeKey:ae,query:f,totalMatched:F,truncated:I,pending:N,onSelect:re,onHover:e=>{let t=L.findIndex(t=>t.key===e.key);t>=0&&_(t)}})}),document.body)]});return n?x(`div`,{ref:c,className:`px-1.5 pb-1.5`,children:v?x(`div`,{className:`fixed z-50 w-max min-w-72 max-w-[26rem]`,style:{left:`calc(env(safe-area-inset-left) + 3.5rem)`,top:`calc(env(safe-area-inset-top) + 3.5rem)`},children:se}):x(G,{variant:`unstyled`,type:`button`,onClick:()=>y(!0),"aria-label":oe,title:oe,className:`flex w-full items-center justify-center rounded-md px-0 py-2 text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,children:x(ne,{className:`h-3.5 w-3.5 shrink-0`})})}):x(`div`,{ref:c,className:`px-2 pb-2`,children:se})}var kw=/^(\d{1,3}\.){3}\d{1,3}$/;function Aw(e){let t=e.startsWith(`[`)&&e.endsWith(`]`)?e.slice(1,-1):e;return!!(kw.test(t)||t.includes(`:`))}function jw(e,t){return!t||Aw(e)?!1:e===t||e.endsWith(`.${t}`)}O();var Mw=`auth-webauthn/passkey-enrollment`,Nw=`camstack_passkey_prompt_dismissed:`,Pw=720*60*60*1e3;function Fw(e){try{let t=localStorage.getItem(`${Nw}${e}`);if(!t)return!1;let n=Number(t);return Number.isFinite(n)?Date.now()-n<Pw:!1}catch{return!1}}function Iw(e){try{localStorage.setItem(`${Nw}${e}`,String(Date.now()))}catch{}}function Lw(){let{user:e}=ax(),{t}=q(),n=V(),r=Ha(Mw),[i,a]=w(!1),[o,c]=w(!1),l=m(()=>e?Fw(e.id):!0,[e]),u=Ka.auth.listLoginMethods.useQuery().data?.find(e=>e.kind===`passkey`),d=u!==void 0&&jw(window.location.hostname,u.rpId),f=e!==null&&d&&r!=null&&!l,p=E({queryKey:[`auth`,`listOwnPasskeys`],queryFn:()=>n.listOwnPasskeys(),enabled:f,staleTime:6e4}),h=b(()=>{e&&Iw(e.id),a(!0),c(!1)},[e]),g=b(()=>{c(!1),p.refetch()},[p]);return!f||i||p.data===void 0||p.data.length>0?null:s(`div`,{className:`shrink-0 border-b border-primary/20 bg-primary/5`,children:[s(`div`,{className:`flex items-center gap-2.5 px-3 py-2 text-xs text-foreground`,children:[x(ir,{className:`h-4 w-4 text-primary shrink-0`}),x(`span`,{className:`flex-1 min-w-0`,children:t(`passkeyPrompt.message`,`Save a passkey for faster sign-in?`)}),x(G,{variant:`unstyled`,onClick:()=>c(e=>!e),className:`rounded bg-primary px-2.5 py-1 text-[11px] font-semibold text-primary-foreground hover:bg-primary/90`,children:t(`passkeyPrompt.enrollNow`,`Enroll now`)}),x(G,{variant:`unstyled`,onClick:h,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,children:t(`passkeyPrompt.notNow`,`Not now`)}),x(G,{variant:`unstyled`,onClick:h,"aria-label":t(`passkeyPrompt.notNow`,`Not now`),className:`p-1 rounded text-foreground-subtle hover:text-foreground`,children:x(xe,{className:`h-3.5 w-3.5`})})]}),o&&x(`div`,{className:`px-3 pb-3`,children:s(`div`,{className:`max-w-xl`,children:[x(Ii,{widgetId:Mw,host:`dashboard`}),x(`div`,{className:`mt-2 flex justify-end`,children:x(G,{variant:`unstyled`,onClick:g,className:`rounded border border-border px-2.5 py-1 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,children:t(`common.close`,`Close`)})})]})})]})}var Rw=`system-config`,zw=[`system-config`,`bootstrap-form`];function Bw(e){return typeof e==`object`&&!!e&&`sections`in e&&Array.isArray(e.sections)}function Vw(){let e=V();return E({queryKey:zw,queryFn:async()=>{let t=await e.trpcClient.addons.custom.mutate({addonId:Rw,action:`getBootstrapForm`,input:{}});if(!Bw(t))throw Error(`The hub did not return the settings form`);return t}})}function Hw(){let e=V(),t=N(),n=ee({mutationFn:async t=>{await e.trpcClient.addons.custom.mutate({addonId:Rw,action:`saveBootstrapForm`,input:t})},onSuccess:()=>Promise.all([t.invalidateQueries({queryKey:zw}),t.invalidateQueries({queryKey:[[`system`,`info`]]})])});return{mutateAsync:n.mutateAsync,isPending:n.isPending}}var Uw=6e4;function Ww(){let e=Ur(void 0,{staleTime:Uw});return{info:e.data?.serverName??null,isLoading:e.isLoading}}O();var Gw=`camstack_server_name_prompt_dismissed`;function Kw(){try{return sessionStorage.getItem(Gw)===`1`}catch{return!1}}function qw(){try{sessionStorage.setItem(Gw,`1`)}catch{}}function Jw(e){return e.isAdmin&&e.info!==null&&e.info.isDefault&&!e.dismissed}function Yw(){let{user:e}=ax(),{info:t}=Ww(),[n,r]=w(Kw);return Jw({isAdmin:e?.isAdmin===!0,info:t,dismissed:n})?x(Xw,{suggestion:t?.name??``,onLater:()=>{qw(),r(!0)}}):null}function Xw({suggestion:e,onLater:t}){let{t:n}=q(),r=N(),i=Hw(),[a,o]=w(e),[c,l]=w(null),u=p(null);S(()=>u.current?.focus(),[]);let d=b(async()=>{let e=cn.safeParse(a);if(!e.success){l(e.error.issues[0]?.message??n(`serverName.invalid`,`Not a valid name`));return}l(null);try{await i.mutateAsync({patch:{name:e.data}}),await r.invalidateQueries({queryKey:[[`system`,`info`]]})}catch(e){l(e instanceof Error&&e.message.length>0?e.message:`Could not save`)}},[r,i,n,a]);return x(Mi,{open:!0,onOpenChange:e=>!e&&t(),children:x(Ir,{children:s(`form`,{onSubmit:e=>{e.preventDefault(),i.isPending||d()},children:[s(Yr,{children:[x(qi,{children:n(`serverName.title`,`Name this server`)}),x($r,{children:n(`serverName.description`,`Pick a name for this hub. It shows in the admin UI and on the apps’ sign-in screen. You can change it later in System settings.`)})]}),x(zi,{children:x(co,{label:n(`serverName.label`,`Server name`),...c===null?{}:{error:c},children:x(W,{ref:u,value:a,maxLength:48,onChange:e=>o(e.target.value),state:c===null?`default`:`error`,"aria-label":n(`serverName.label`,`Server name`)})})}),s(Qa,{children:[x(G,{type:`button`,variant:`ghost`,onClick:t,disabled:i.isPending,children:n(`serverName.later`,`Later`)}),s(G,{type:`submit`,disabled:i.isPending||a.trim().length===0,children:[i.isPending&&x(H,{className:`h-4 w-4 animate-spin`}),n(`common.save`,`Save`)]})]})]})})})}var Zw=4,Qw=160,$w=320,eT=`env(safe-area-inset-top)`,tT=`env(safe-area-inset-bottom)`;function nT(e){let{rect:t,viewportWidth:n,viewportHeight:r}=e,i=Math.min($w,n-16),a={position:`fixed`,left:Math.max(8,Math.min(t.left,n-8-i)),width:i,zIndex:9999};if(r-t.bottom>=t.top){let e=`max(${t.bottom+Zw}px, calc(${eT} + 8px))`;return{...a,top:e,maxHeight:`max(${Qw}px, calc(100dvh - ${e} - ${tT} - 8px))`}}let o=`max(${r-t.top+Zw}px, calc(${tT} + 8px))`;return{...a,bottom:o,maxHeight:`max(${Qw}px, calc(100dvh - ${o} - ${eT} - 8px))`}}var rT=!1;function iT(){return rT}function aT(){rT=!0}function oT(e){return!e.read&&e.severity===`critical`}function sT(e){return e.filter(oT)}function cT(e){return e!==void 0&&typeof e.href==`string`&&e.href.length>0}function lT(e){return cT(e)||e!==void 0&&e.invoke!==void 0}var uT=/^\/addon\/[^/?#]+\/oauth\//;function dT(e){return e.navigation===void 0?uT.test(e.href):e.navigation===`server`}function fT(e){let t=e.action;if(lT(t)&&!(t.invoke!==void 0&&(e.status===`completed`||e.status===`dismissed`)))return t}O();function pT({action:e,className:t,onActivate:n}){let r=N(),i=V(),{t:a}=q(),[o,c]=w(!1),[l,u]=w(null);if(e.invoke!==void 0){let{addonId:d,action:f,input:p}=e.invoke;return s(`span`,{className:`inline-flex flex-col items-start gap-0.5`,children:[x(`button`,{type:`button`,className:t,disabled:o,onClick:e=>{e.preventDefault(),n?.(e),c(!0),u(null),i.trpcClient.addons.custom.mutate({addonId:d,action:f,input:p}).then(()=>r.invalidateQueries({queryKey:[[`alerts`]]})).catch(e=>u(e instanceof Error?e.message:String(e))).finally(()=>c(!1))},children:o?a(`ui.alertAction.running`,`Working…`):e.label}),l!==null&&x(`span`,{role:`alert`,className:`text-[10px] text-destructive`,children:l})]})}return cT(e)?dT(e)?x(`a`,{href:B(e.href),className:t,onClick:t=>{t.preventDefault(),n?.(t),wd(e.href,()=>{r.invalidateQueries({queryKey:[[`alerts`]]}),r.invalidateQueries({queryKey:[[`broker`]]}),r.invalidateQueries({queryKey:[[`recordEntries`]]})})},children:e.label}):x(ku,{to:e.href,className:t,onClick:n,children:e.label}):x(F,{})}O(),wo();var mT={info:lt,success:De,warning:Ne,error:te,critical:sr},hT={info:`text-info`,success:`text-success`,warning:`text-warning`,error:`text-danger`,critical:`text-danger`},gT={active:`border-l-info`,"in-progress":`border-l-warning`,completed:`border-l-success`,failed:`border-l-danger`,dismissed:`border-l-foreground-subtle/30`};function _T(e){let t=Math.floor((Date.now()-e)/1e3);if(t<60)return K.t(`helpers.relativeTime.justNow`);let n=Math.floor(t/60);if(n<60)return K.t(`helpers.relativeTime.minutesAgo`,{count:n});let r=Math.floor(n/60);if(r<24)return K.t(`helpers.relativeTime.hoursAgo`,{count:r});let i=Math.floor(r/24);return K.t(`helpers.relativeTime.daysAgo`,{count:i})}function vT(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function yT(e){return typeof e==`string`&&e.length>0?e:void 0}function bT(e){if(vT(e.metadata)){let t=yT(e.metadata.nodeId)??yT(e.metadata.agentId);if(t!==void 0)return t}let t=e.source;if(t!==void 0&&!(t.type!==`node`&&t.type!==`agent`))return yT(t.id)}function xT({alert:e,onMarkRead:t,onDismiss:n}){let{t:r}=q(),i=e.severity in mT?e.severity:`info`,a=fT(e),o=e.status in gT?e.status:`active`,c=mT[i],l=hT[i],u=gT[o],{nodes:d}=Xi(),f=bT(e),p=f===void 0?void 0:d.find(e=>e.id===f),m=f===void 0?void 0:p?.name??f;return s(`div`,{className:`flex items-start gap-2.5 px-3 py-2.5 border-l-2 ${u} ${e.read?`opacity-60`:``} hover:bg-surface-hover transition-colors`,children:[x(c,{className:`h-3.5 w-3.5 shrink-0 mt-0.5 ${l}`}),s(`div`,{className:`flex-1 min-w-0`,children:[s(`div`,{className:`flex items-center gap-1.5`,children:[x(`span`,{className:`text-[11px] font-semibold ${e.read?`text-foreground-subtle`:`text-foreground`}`,children:e.title}),!e.read&&x(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary shrink-0`})]}),m!==void 0&&x(`div`,{className:`text-foreground-subtle text-[10px] mt-0.5 truncate`,children:m}),x(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5 line-clamp-2`,children:e.message}),a!==void 0&&x(pT,{action:a,className:`inline-flex mt-1.5 items-center rounded-md bg-primary px-2 py-0.5 text-[10px] font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,onActivate:e=>e.stopPropagation()}),e.status===`in-progress`&&e.progress!==void 0&&s(`div`,{className:`mt-1.5 flex items-center gap-2`,children:[x(`div`,{className:`flex-1 h-1 bg-surface-hover rounded-full overflow-hidden`,children:x(`div`,{className:`h-full bg-primary rounded-full transition-all duration-300`,style:{width:`${String(Math.min(100,Math.max(0,e.progress)))}%`}})}),s(`span`,{className:`text-[9px] text-foreground-subtle font-mono shrink-0`,children:[String(Math.round(e.progress)),`%`]})]}),x(`div`,{className:`text-[9px] text-foreground-subtle/60 mt-1`,children:_T(e.updatedAt)})]}),s(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[!e.read&&x(G,{variant:`unstyled`,type:`button`,onClick:n=>{n.stopPropagation(),t(e.id)},className:`p-1 rounded hover:bg-surface-hover transition-colors`,title:r(`ui.alertBell.markAsRead`,`Mark as read`),children:x(mt,{className:`h-3 w-3 text-foreground-subtle`})}),e.status!==`in-progress`&&x(G,{variant:`unstyled`,type:`button`,onClick:t=>{t.stopPropagation(),n(e.id)},className:`p-1 rounded hover:bg-surface-hover transition-colors`,title:r(`ui.alertBell.dismiss`,`Dismiss`),children:x(xe,{className:`h-3 w-3 text-foreground-subtle`})})]})]})}function ST({variant:e=`icon`,compact:t=!1}={}){let{t:n}=q(),[r,i]=w(!1),[a,o]=w(!1),c=p(null),l=p(null),u=N(),{data:d=0}=mi(void 0,{refetchInterval:3e4}),{data:f=[],isLoading:m}=Fa({limit:50},{enabled:r}),h=a?f:f.filter(e=>!e.read),g=f.filter(e=>e.read).length,_=()=>{u.invalidateQueries({queryKey:[[`alerts`]]})},v=Aa({onSuccess:_}),y=Cr({onSuccess:_}),C=kr({onSuccess:_});so(`alert.created`,()=>{u.invalidateQueries({queryKey:[[`alerts`]]})}),so(`alert.updated`,()=>{u.invalidateQueries({queryKey:[[`alerts`]]})}),S(()=>{if(!r)return;let e=e=>{let t=e.target;c.current&&!c.current.contains(t)&&l.current&&!l.current.contains(t)&&i(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e)}},[r]);let T=b(e=>{v.mutate({alertId:e})},[v]),E=b(e=>{e&&C.mutate({alertId:e})},[C]),D=b(()=>{y.mutate(void 0),i(!1)},[y]),O=h.filter(oT),k=new Set(O.map(e=>e.id)),A=h.filter(e=>e.status===`in-progress`&&!k.has(e.id)),j=h.filter(e=>e.status!==`in-progress`&&!k.has(e.id)),[M,ee]=w({}),P=b(()=>{let e=l.current;e&&ee(nT({rect:e.getBoundingClientRect(),viewportWidth:window.innerWidth,viewportHeight:window.innerHeight}))},[]);return S(()=>{if(!r)return;P();let e=()=>P();return window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},[r,P]),s(`div`,{children:[e===`sidebar`?s(G,{variant:`unstyled`,ref:l,type:`button`,onClick:()=>i(!r),className:`flex w-full items-center gap-2.5 rounded-md ${t?`justify-center px-0 py-2`:`px-2.5 py-1.5`} text-[12px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,title:t?d>0?n(`ui.alertBell.alertsUnread`,{count:d}):n(`ui.alertBell.alerts`):void 0,children:[s(`span`,{className:`relative inline-flex shrink-0`,children:[x(Ce,{className:`h-3.5 w-3.5`}),t&&d>0&&x(`span`,{className:`absolute -top-1 -right-1 h-2 w-2 rounded-full bg-primary`})]}),!t&&x(`span`,{className:`flex-1 text-left`,children:n(`ui.alertBell.alerts`,`Alerts`)}),!t&&d>0&&x(`span`,{className:`flex items-center justify-center h-4 min-w-4 px-1 rounded-full bg-primary text-primary-foreground text-[9px] font-bold leading-none`,children:d>99?`99+`:String(d)})]}):s(G,{variant:`unstyled`,ref:l,type:`button`,onClick:()=>i(!r),className:`relative p-1.5 rounded-md hover:bg-surface-hover text-foreground-subtle hover:text-foreground transition-colors`,"aria-label":n(`ui.alertBell.alerts`,`Alerts`),children:[x(Ce,{className:`h-4.5 w-4.5`}),d>0&&x(`span`,{className:`absolute -top-0.5 -right-0.5 flex items-center justify-center h-4 min-w-4 px-0.5 rounded-full bg-primary text-primary-foreground text-[9px] font-bold leading-none`,children:d>99?`99+`:String(d)})]}),r&&To(s(`div`,{ref:c,style:M,className:`bg-surface border border-border rounded-lg shadow-xl flex flex-col overflow-hidden`,children:[s(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border shrink-0`,children:[x(`span`,{className:`text-[12px] font-semibold text-foreground`,children:n(`ui.alertBell.alerts`,`Alerts`)}),s(`div`,{className:`flex items-center gap-2`,children:[g>0&&s(`label`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle cursor-pointer select-none`,children:[x(L,{checked:a,onChange:e=>o(e.target.checked),className:`h-3 w-3 rounded border-border accent-primary cursor-pointer`}),n(`ui.alertBell.showRead`,`Show read`)]}),d>0&&s(G,{variant:`unstyled`,type:`button`,onClick:D,className:`flex items-center gap-1 text-[10px] text-primary hover:text-primary/80 transition-colors`,children:[x(or,{className:`h-3 w-3`}),n(`ui.alertBell.markAllRead`,`Mark all read`)]})]})]}),s(`div`,{className:`flex-1 overflow-y-auto`,children:[m&&x(`div`,{className:`flex items-center justify-center py-8`,children:x(H,{className:`h-4 w-4 animate-spin text-foreground-subtle`})}),!m&&h.length===0&&s(`div`,{className:`flex flex-col items-center justify-center py-8 text-foreground-subtle`,children:[x(Ce,{className:`h-6 w-6 mb-2 opacity-40`}),x(`span`,{className:`text-[11px]`,children:f.length>0?n(`ui.alertBell.noUnreadAlerts`,`No unread alerts`):n(`ui.alertBell.noAlerts`,`No alerts`)}),f.length>0&&!a&&x(G,{variant:`unstyled`,type:`button`,onClick:()=>o(!0),className:`text-[10px] text-primary mt-1 hover:underline`,children:n(`ui.alertBell.showRead`,{count:g})})]}),O.length>0&&s(`div`,{className:`border-b border-border`,children:[x(`div`,{className:`px-3 py-1.5 bg-danger/5`,children:x(`span`,{className:`text-[9px] font-semibold uppercase tracking-widest text-danger`,children:n(`ui.alertBell.urgent`,`Urgent`)})}),O.map(e=>x(xT,{alert:e,onMarkRead:T,onDismiss:E},e.id))]}),A.length>0&&s(`div`,{className:`border-b border-border`,children:[x(`div`,{className:`px-3 py-1.5 bg-surface-hover/50`,children:x(`span`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60`,children:n(`ui.alertBell.inProgress`,`In Progress`)})}),A.map(e=>x(xT,{alert:e,onMarkRead:T,onDismiss:E},e.id))]}),j.map(e=>x(xT,{alert:e,onMarkRead:T,onDismiss:E},e.id))]})]}),document.body)]})}O(),wo();function CT({alert:e,onMarkRead:t}){let{t:n}=q(),r=fT(e);return s(`div`,{className:`border-b border-border last:border-b-0 px-3 py-2.5`,children:[x(`div`,{className:`text-[12px] font-semibold text-foreground`,children:e.title}),x(`div`,{className:`text-[11px] text-foreground-muted mt-0.5`,children:e.message}),s(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[r!==void 0&&x(pT,{action:r,className:`inline-flex items-center justify-center rounded-md bg-primary px-2.5 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90 transition-colors`}),x(G,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>t(e.id),children:n(`ui.alertBell.markAsRead`,`Mark as read`)})]})]})}function wT(){let{t:e}=q(),t=N(),[n,r]=w(iT()),{data:i=[],isLoading:a}=Fa({limit:50}),o=m(()=>sT(i),[i]),c=Aa({onSuccess:b(()=>{t.invalidateQueries({queryKey:[[`alerts`]]})},[t])}),l=b(e=>{c.mutate({alertId:e})},[c]),u=b(()=>{aT(),r(!0)},[]);return a||n||o.length===0?null:To(x(`div`,{className:`fixed inset-x-0 bottom-0 z-[10000] flex justify-center p-2 sm:p-4 pb-[max(0.5rem,env(safe-area-inset-bottom))] pointer-events-none`,"data-testid":`critical-alerts-on-load-panel`,children:s(`div`,{className:`pointer-events-auto w-full max-w-lg bg-surface border border-danger/30 rounded-lg shadow-xl flex flex-col max-h-[min(70dvh,32rem)] overflow-hidden`,role:`region`,"aria-labelledby":`critical-alerts-panel-title`,children:[s(`div`,{className:`flex items-start justify-between gap-2 px-3 py-2.5 border-b border-border shrink-0 bg-danger/5`,children:[s(`div`,{children:[x(`h2`,{id:`critical-alerts-panel-title`,className:`text-[12px] font-semibold text-foreground`,children:e(`ui.criticalAlertsPanel.title`,`Urgent alerts`)}),x(`p`,{className:`text-[10px] text-foreground-muted mt-0.5`,children:e(`ui.criticalAlertsPanel.subtitle`,`These need your attention.`)})]}),x(Ar,{type:`button`,variant:`ghost`,onClick:u,"aria-label":e(`ui.criticalAlertsPanel.close`,`Close`),"data-testid":`critical-alerts-panel-close`,icon:xe})]}),x(`div`,{className:`flex-1 overflow-y-auto`,children:o.map(e=>x(CT,{alert:e,onMarkRead:l},e.id))})]})}),document.body)}O();function TT(){let e=Zy();return C(e.subscribe,e.getSnapshot,e.getSnapshot)}var ET=[`detection`,`cluster`,`administration`];function DT(e){return ET.includes(e)}function OT(e){let t=new Map,n=new Map,r=[];for(let i of e){let e=i.section?.trim();if(e===void 0||e.length===0){r.push(i);continue}if(DT(e)){let n=t.get(e)??[];n.push(i),t.set(e,n);continue}let a=n.get(e);a?a.pages.push(i):n.set(e,{label:i.sectionLabel?.trim()||e,pages:[i]})}return{known:t,custom:[...n.entries()].map(([e,t])=>({id:e,label:t.label,pages:t.pages})),ungrouped:r}}var kT=`camstack:last-path`,AT=512,jT=[`/login`,`/change-password`,`/access-denied`,`/logout`];function MT(e){return!e.startsWith(`/`)||e.startsWith(`//`)||e.length>AT?!1:!jT.some(t=>e===t||e.startsWith(t+`/`))}function NT(e){if(!(typeof window>`u`)&&MT(e))try{window.localStorage.setItem(kT,e)}catch{}}function PT(){if(typeof window>`u`)return null;try{let e=window.localStorage.getItem(kT);return e===null?null:MT(e)?e:null}catch{return null}}var FT=`/devices`;function IT(e){return e!==void 0&&MT(e)?e:PT()??FT}function LT(e){return e.split(`.`)[0]===`0`?`${e} beta`:e}function RT(e){if(e===null)return null;let t=e.trim();return t.length>0?t:null}function zT(e){let t=RT(e.productVersion),n=RT(e.serverVersion),r=RT(e.fallbackVersion);return t!==null&&n!==null?{kind:`both`,productLabel:LT(t),serverVersion:n}:t===null?n===null?r===null?{kind:`none`}:{kind:`fallback`,version:r}:{kind:`server`,serverVersion:n}:{kind:`product`,productLabel:LT(t)}}function BT(e,t){if(!Object.hasOwn(e,t))return null;let n=Reflect.get(e,t);return typeof n==`string`?n:null}function VT(e){return typeof e!=`object`||!e?null:{productVersion:BT(e,`productVersion`),serverVersion:BT(e,`serverVersion`)}}O();function HT(e,t){return e.kind===`both`?t(`releaseIdentity.both`,`{{product}} · server {{server}}`,{product:e.productLabel,server:e.serverVersion}):e.kind===`product`?e.productLabel:e.kind===`server`?t(`releaseIdentity.serverOnly`,`server {{version}}`,{version:e.serverVersion}):e.kind===`fallback`?t(`releaseIdentity.fallback`,`v{{version}}`,{version:e.version}):null}function UT({placement:e,compact:t=!1}){let{t:n}=q(),[r,i]=w({kind:`fallback`,version:`1.2.708`});S(()=>{let e=new AbortController;return fetch(B(`/api/release-identity`),{signal:e.signal}).then(async e=>e.ok?VT(await e.json()):null).then(t=>{e.signal.aborted||t===null||i(zT({productVersion:t.productVersion,serverVersion:t.serverVersion,fallbackVersion:`1.2.708`}))}).catch(t=>{e.signal.aborted||t instanceof DOMException&&t.name}),()=>e.abort()},[]);let a=HT(r,n);return a===null?null:e===`login`?x(`span`,{"data-testid":`release-identity`,children:a}):x(`div`,{"data-testid":`release-identity`,className:`pt-1 text-[10px] text-foreground-disabled select-none truncate ${t?`text-center`:`px-2`}`,title:a,children:a})}O();var WT=j(!0);function GT(e){return e===`/addon`||e.startsWith(`/addon/`)}function KT(e,t,n){let r=[...e.filter(e=>e!==t),t];return r.length<=n?r:r.slice(r.length-n)}function qT({maxCached:e=6}){let t=fl(),n=Y(),r=ol(),i=I(Zc),a=n.pathname,o=GT(a),c=p(new Map),l=p([]);if(o){c.current.set(a,{key:a,outlet:t,location:n,navigationType:r,routeContext:i});let o=KT(l.current,a,e),s=new Set(o);for(let e of c.current.keys())s.has(e)||c.current.delete(e);l.current=o}return s(F,{children:[l.current.map(e=>{let t=c.current.get(e);if(t?.outlet==null)return null;let n=o&&e===a;return x(`div`,{className:n?`h-full min-h-0`:void 0,style:n?void 0:{display:`none`},hidden:!n,"aria-hidden":!n,children:x(WT.Provider,{value:n,children:x(Xc.Provider,{value:{location:t.location,navigationType:t.navigationType},children:x(Zc.Provider,{value:t.routeContext,children:t.outlet})})})},e)}),!o&&t!=null?x(`div`,{className:`h-full min-h-0`,children:t},a):null]})}O();var JT={dark:ye,light:Ue,system:ie};function YT(){return x(`div`,{className:`flex h-full min-h-[50vh] items-center justify-center`,children:x(`span`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-primary/30 border-t-primary`})})}function XT(){let e=Y(),t=ll(),{user:n,logout:r}=ax(),i=ba(),{t:a}=q(),o=ui(),c=us(),l=oi(),{info:u}=Ww();S(()=>{document.title=u===null?`CamStack Admin`:`${u.name} \u00b7 CamStack Admin`},[u]);let d=Vy(TT()),[f,h]=w(!1);S(()=>{NT(e.pathname+e.search)},[e.pathname,e.search]);let[g,_]=w(()=>typeof window>`u`?!1:window.localStorage.getItem(`camstack:sidebar-collapsed`)===`1`);S(()=>{typeof window>`u`||window.localStorage.setItem(`camstack:sidebar-collapsed`,g?`1`:`0`)},[g]);let[v]=w(()=>{if(typeof window>`u`)return new Set;try{let e=window.localStorage.getItem(`camstack:sidebar-collapsed-groups`);if(!e)return new Set;let t=JSON.parse(e);return Array.isArray(t)?new Set(t.filter(e=>typeof e==`string`)):new Set}catch{return new Set}});S(()=>{typeof window>`u`||window.localStorage.setItem(`camstack:sidebar-collapsed-groups`,JSON.stringify([...v]))},[v]),S(()=>{l&&window.localStorage.getItem(`camstack:sidebar-collapsed`)===null&&_(!0)},[l]);let{data:b=[]}=Ca({nodeId:`hub`},{refetchInterval:3e4}),C=b.length,T=N(),E=p(Date.now()),{data:D}=Ji(void 0,{staleTime:0,refetchOnMount:`always`,refetchInterval:e=>{let t=e.state.data;return t&&t.length>0||Date.now()-E.current>=3e4?!1:2e3}}),O=m(()=>D&&n?.isAdmin?FC(D):[],[D,n?.isAdmin]),k=m(()=>OT(O),[O]),A=k.known.get(`detection`)??[],j=k.known.get(`cluster`)??[],M=k.known.get(`administration`)??[];so(`addon.page-ready`,()=>{T.invalidateQueries({queryKey:[[`addonPages`,`listPages`]]})});let ee=()=>{r(),t(`/login`)},P=t=>!!(e.pathname===t||e.pathname.startsWith(t+`/`)),I=[`/system/pipeline`,`/live`,`/addon/osd-manager`,`/build`].some(t=>e.pathname===t||e.pathname.startsWith(t+`/`)),L=n?.isAdmin===!0,te=m(()=>JC({t:a,isAdmin:L}),[a,L]),ne=te[0]?.items??[],re=te[1]?.items??[],ie=te[2]?.items??[],ae=te[3]?.items??[],oe=i?.mode??`system`,se={dark:a(`theme.dark`),light:a(`theme.light`),system:a(`theme.system`)},R=g&&!o,ce=(e,t=`md`,n=!1)=>`flex w-full items-center gap-2.5 rounded-md ${R?`justify-center px-0 py-2`:`px-2.5 py-1.5`} ${t===`lg`?`text-[13px] font-medium`:`text-[12px]`} transition-all ${e?t===`lg`?`bg-primary/12 text-primary shadow-sm shadow-primary/5`:`bg-primary/12 text-primary`:n?`text-foreground-disabled hover:bg-surface-hover`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,le=(e,t)=>e===0?null:R?x(`div`,{className:`pt-3 mb-1 mx-2 border-t border-border/60`},`sep-${t}`):x(`div`,{className:`pt-4 pb-1.5 px-2.5`,children:x(`span`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/60`,children:t})},`hdr-${t}`),ue=e=>{let n=P(e.path),r=XC(e.icon);return s(G,{variant:`unstyled`,onClick:()=>{t(e.path),h(!1)},className:ce(n),title:R?e.label:void 0,children:[x(r,{className:`h-3.5 w-3.5 shrink-0 ${n?`text-primary`:``}`}),!R&&e.label]},`${e.addonId}::${e.id}`)},de=e=>e.requiresCapability===void 0?fe(e,!1):x(tw,{capability:e.requiresCapability,children:t=>fe(e,t)},e.path),fe=(e,n)=>{let r=e.icon,i=P(e.path),o=e.path===`/system/addons`;return s(G,{variant:`unstyled`,"data-testid":`nav-${e.path.replace(/^\//,``).replace(/\//g,`-`)}`,onClick:()=>{t(e.path),h(!1)},className:ce(i,`md`,n),"aria-disabled":n||void 0,title:n?a(`nav.notInstalled`,`{{page}} — not installed`,{page:e.label}):R?e.label:void 0,children:[x(r,{className:`h-3.5 w-3.5 shrink-0 ${i?`text-primary`:``}`}),!R&&s(F,{children:[x(`span`,{className:`flex-1 text-left`,children:e.label}),o&&C>0&&x(`span`,{className:`ml-auto rounded-full bg-primary px-1.5 py-0.5 text-[9px] font-bold text-primary-foreground leading-none`,children:C})]}),R&&o&&C>0&&x(`span`,{className:`absolute mt-[-14px] ml-3 h-2 w-2 rounded-full bg-primary`})]},e.path)},z=s(F,{children:[s(`div`,{className:`flex h-14 items-center border-b border-border ${R?`justify-center px-1`:`pl-3 pr-4 gap-2`}`,children:[!R&&x(`img`,{src:i?.resolvedMode===`light`?B(`/brand/logo-horizontal-light.svg`):B(`/brand/logo-horizontal-dark.svg`),alt:a(`layouts.appLayout.camstackAdmin`,`CamStack Admin`),className:`h-9 flex-1 min-w-0`}),!o&&x(G,{variant:`unstyled`,onClick:()=>_(e=>!e),className:`p-1.5 rounded-md hover:bg-surface-hover text-foreground-subtle transition-colors flex-shrink-0 ${R?``:`mr-2`}`,"aria-label":g?a(`layouts.appLayout.expandSidebar`,`Expand sidebar`):a(`layouts.appLayout.collapseSidebar`,`Collapse sidebar`),title:g?a(`layouts.appLayout.expandSidebar`,`Expand sidebar`):a(`layouts.appLayout.collapseSidebar`,`Collapse sidebar`),children:x(g?Re:at,{className:`h-4 w-4`})})]}),!R&&u!==null&&x(`div`,{"data-testid":`sidebar-server-name`,title:u.name,className:`truncate border-b border-border px-3 py-1.5 text-xs font-medium text-foreground-muted`,children:u.name}),x(`div`,{className:`border-b border-border pt-2`,children:x(Ow,{navSections:te,addonPages:O,compact:R,onNavigated:()=>h(!1)})}),s(`nav`,{className:`flex-1 overflow-y-auto py-3 ${R?`px-1.5`:`px-2`} space-y-0.5`,children:[ne.map(e=>de(e)),le(re.length+A.length,a(`nav.detectionSection`,`Detection`)),re.map(e=>de(e)),A.map(e=>ue(e)),le(ie.length+j.length,a(`nav.clusterSection`,`Cluster`)),ie.map(e=>de(e)),j.map(e=>ue(e)),le(ae.length+M.length,a(`system.title`,`Administration`)),ae.map(e=>de(e)),M.map(e=>ue(e)),k.custom.map(e=>s(`div`,{className:`contents`,children:[le(e.pages.length,e.label),e.pages.map(e=>ue(e))]},`custom-${e.id}`)),le(k.ungrouped.length,a(`nav.addonPages`,`Addon Pages`)),k.ungrouped.map(e=>ue(e))]}),s(`div`,{className:`border-t border-border ${R?`p-1.5`:`p-2`} space-y-0.5`,children:[s(G,{variant:`unstyled`,onClick:()=>i?.toggleMode(),className:ce(!1),title:R?se[oe]:void 0,children:[(()=>{let e=JT[oe];return x(e,{className:`h-3.5 w-3.5 shrink-0`})})(),!R&&x(`span`,{children:se[oe]})]}),x(ST,{variant:`sidebar`,compact:R}),s(G,{variant:`unstyled`,type:`button`,onClick:()=>t(`/system/my-access`),className:ce(P(`/system/my-access`)),title:R?a(`system.myAccess`,`My access`):void 0,children:[x(pe,{className:`h-3.5 w-3.5 shrink-0`}),!R&&x(`span`,{className:`truncate`,children:a(`system.myAccess`,`My access`)})]}),s(G,{variant:`unstyled`,type:`button`,onClick:()=>c.setOn(!c.on),className:ce(c.on),"aria-pressed":c.on,title:R?a(`layouts.appLayout.debugLayers`,`Debug layers`):void 0,children:[x(Pe,{className:`h-3.5 w-3.5 shrink-0`}),!R&&x(`span`,{className:`truncate`,children:c.on?a(`layouts.appLayout.debugLayersOn`,`Debug layers: on`):a(`layouts.appLayout.debugLayers`,`Debug layers`)})]}),s(G,{variant:`unstyled`,onClick:ee,className:ce(!1).replace(`hover:text-foreground`,`hover:text-danger`),title:R?n?.username??a(`layouts.appLayout.logout`,`Logout`):void 0,children:[x(tr,{className:`h-3.5 w-3.5 shrink-0`}),!R&&x(`span`,{className:`truncate`,children:n?.username??a(`layouts.appLayout.user`,`User`)})]}),x(UT,{placement:`sidebar`,compact:R})]})]});return s(`div`,{className:`flex h-dvh flex-col overflow-hidden bg-background text-foreground pb-[env(safe-area-inset-bottom)]`,children:[x(`div`,{"aria-hidden":`true`,className:`h-[env(safe-area-inset-top)] shrink-0 bg-surface`}),s(`div`,{className:`flex min-h-0 flex-1`,children:[!o&&x(`aside`,{className:`flex flex-col border-r border-border bg-surface shrink-0 transition-[width] duration-150 ease-out ${R?`w-12`:`w-48`}`,children:z}),o&&x(Da,{open:f,onClose:()=>h(!1),width:`w-64`,children:z}),s(`div`,{className:`flex flex-1 flex-col min-w-0`,children:[d!==null&&s(`div`,{className:`flex items-center justify-center gap-2 px-3 py-2 text-[12px] font-medium shrink-0 ${d.severity===`danger`?`bg-danger/90 text-white`:`bg-warning/15 text-warning border-b border-warning/30`}`,children:[d.severity===`danger`?x($e,{className:`h-3.5 w-3.5`}):x(he,{className:`h-3.5 w-3.5`}),x(`span`,{children:a(d.i18nKey,{defaultValue:d.message,...d.i18nParams})}),d.action===`sign-in`&&x(G,{variant:`unstyled`,onClick:()=>r(),className:`ml-2 rounded border border-white/40 px-2 py-0.5 text-[11px] font-semibold hover:bg-white/10`,children:a(`connection.signIn`,`Sign in`)}),d.showSpinner&&x(H,{className:`h-3.5 w-3.5 animate-spin`})]}),x(Lw,{}),x(Yw,{}),x(wT,{}),o&&s(`header`,{"data-debug-header":``,className:`flex items-center h-12 border-b border-border px-3 shrink-0 bg-surface`,children:[x(G,{variant:`unstyled`,onClick:()=>h(!0),className:`p-1.5 -ml-1.5 rounded-md hover:bg-surface-hover text-foreground-muted transition-colors`,"aria-label":a(`layouts.appLayout.openMenu`,`Open menu`),children:x(tt,{className:`h-5 w-5`})}),x(`div`,{className:`flex-1 flex justify-center`,children:x(`img`,{src:i?.resolvedMode===`light`?B(`/brand/logo-horizontal-light.svg`):B(`/brand/logo-horizontal-dark.svg`),alt:a(`layouts.appLayout.camstack`,`CamStack`),className:`h-7`})}),x(ST,{})]}),s(nw,{children:[x(iw,{}),x(`main`,{className:`relative flex-1 min-h-0 overscroll-contain bg-background ${I?`overflow-hidden`:`overflow-auto`}`,children:x(NC,{resetKey:e.pathname,children:x(y,{fallback:x(YT,{}),children:x(qT,{})})})})]})]})]})]})}function $({children:e,requireAdmin:t}){let{t:n}=q(),{user:r,loading:i,mustChangePassword:a}=ax(),o=Y();return i?x(`div`,{className:`flex h-screen items-center justify-center bg-background text-foreground-subtle`,children:n(`layouts.protectedRoute.loading`,`Loading...`)}):r?a&&o.pathname!==`/change-password`?x(X,{to:`/change-password`,replace:!0}):t&&!r.isAdmin?x(X,{to:`/access-denied`,replace:!0}):x(F,{children:e}):x(X,{to:`/login`,replace:!0,state:{from:o.pathname+o.search}})}var ZT=`integration`,QT=`section`,$T=[ZT,QT,`instance`,`instance-new`],eE={connectivity:{path:`/system/integrations`,tab:null},remoteAccess:{path:`/system/network`,tab:`remote-access`},mesh:{path:`/system/network`,tab:`mesh`},turn:{path:`/system/network`,tab:`turn`},authentication:{path:`/system/identity`,tab:`authentication`},access:{path:`/system/identity`,tab:`access`},logging:{path:`/system/logs`,tab:`destinations`}},tE=`activity`;function nE(e,t={}){let{path:n,tab:r}=eE[e],i=new URLSearchParams;r===null?t.kindSection!==void 0&&i.set(`tab`,t.kindSection):i.set(`tab`,r),t.integration!==void 0&&i.set(ZT,t.integration),t.section!==void 0&&i.set(QT,t.section);let a=i.toString();return a.length>0?`${n}?${a}`:n}function rE(e){let{ids:t,requested:n,answered:r,legacyGroup:i=null,groupFirst:a={}}=e;if(n!==null&&t.includes(n))return{selectedId:n,staleId:null};let o=n!==null&&r?n:null,s=i===null?void 0:a[i];return s!==void 0&&t.includes(s)?{selectedId:s,staleId:o}:{selectedId:t[0]??null,staleId:o}}function iE(e,t,n=null,r=null){let i=new URLSearchParams(e);return i.set(ZT,t),r===null?i.delete(QT):i.set(QT,r),n!==null&&i.delete(n),i}function aE(e){return e===`/admin`||e===`/admin/`?`/`:e.startsWith(`/admin/`)?e.slice(6):e}var oE=`--color-surface`;function sE(e){let t=e.querySelector(`meta[name="theme-color"]`);if(t)return t;let n=e.createElement(`meta`);return n.name=`theme-color`,e.head.appendChild(n),n}function cE(e=document){let t=e.defaultView?.getComputedStyle(e.documentElement).getPropertyValue(oE).trim();if(!t)return;let n=sE(e);n.content!==t&&(n.content=t)}function lE(e=document){cE(e);let t=e.defaultView;if(!t)return()=>void 0;let n=new t.MutationObserver(()=>cE(e));return n.observe(e.documentElement,{attributes:!0,attributeFilter:[`class`]}),()=>n.disconnect()}function uE(){let{t:e}=q(),t=ll();return s(`div`,{className:`flex flex-col items-center justify-center text-foreground py-16 px-4`,children:[x(`div`,{className:`flex h-16 w-16 items-center justify-center rounded-2xl bg-danger/10 mb-4`,children:x(pr,{className:`h-8 w-8 text-danger`})}),x(`h1`,{className:`text-xl font-bold`,children:e(`accessDenied.accessDenied`,`Access Denied`)}),x(`p`,{className:`mt-2 text-sm text-foreground-subtle`,children:e(`accessDenied.youDonTHavePermission`,`You don't have permission to access this page.`)}),x(G,{variant:`unstyled`,onClick:()=>t(`/devices`),className:`mt-6 rounded-lg bg-primary px-5 py-2.5 text-sm font-medium text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg transition-all`,children:e(`accessDenied.goToDevices`,`Go to Devices`)})]})}function dE(e){let t=new Uint8Array(e),n=``;for(let e of t)n+=String.fromCharCode(e);return btoa(n).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=/g,``)}function fE(e){let t=e.replace(/-/g,`+`).replace(/_/g,`/`),n=(4-t.length%4)%4,r=t.padEnd(t.length+n,`=`),i=atob(r),a=new ArrayBuffer(i.length),o=new Uint8Array(a);for(let e=0;e<i.length;e++)o[e]=i.charCodeAt(e);return a}function pE(){return window?.PublicKeyCredential!==void 0&&typeof window.PublicKeyCredential==`function`}function mE(e){let{id:t}=e;return{...e,id:fE(t),transports:e.transports}}function hE(e){return e===`localhost`||/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(e)}var gE=class extends Error{constructor({message:e,code:t,cause:n,name:r}){super(e,{cause:n}),this.name=r??n.name,this.code=t}},_E=new class{createNewAbortSignal(){if(this.controller){let e=Error(`Cancelling existing WebAuthn API call for new one`);e.name=`AbortError`,this.controller.abort(e)}let e=new AbortController;return this.controller=e,e.signal}cancelCeremony(){if(this.controller){let e=Error(`Manually cancelling existing WebAuthn API call`);e.name=`AbortError`,this.controller.abort(e),this.controller=void 0}}},vE=[`cross-platform`,`platform`];function yE(e){if(e&&!(vE.indexOf(e)<0))return e}function bE(){if(!pE())return new Promise(e=>e(!1));let e=window.PublicKeyCredential;return e.isConditionalMediationAvailable===void 0?new Promise(e=>e(!1)):e.isConditionalMediationAvailable()}function xE({error:e,options:t}){let{publicKey:n}=t;if(!n)throw Error(`options was missing required publicKey property`);if(e.name===`AbortError`){if(t.signal instanceof AbortSignal)return new gE({message:`Authentication ceremony was sent an abort signal`,code:`ERROR_CEREMONY_ABORTED`,cause:e})}else if(e.name===`NotAllowedError`)return new gE({message:e.message,code:`ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY`,cause:e});else if(e.name===`SecurityError`){let t=window.location.hostname;if(!hE(t))return new gE({message:`${window.location.hostname} is an invalid domain`,code:`ERROR_INVALID_DOMAIN`,cause:e});if(n.rpId!==t)return new gE({message:`The RP ID "${n.rpId}" is invalid for this domain`,code:`ERROR_INVALID_RP_ID`,cause:e})}else if(e.name===`UnknownError`)return new gE({message:`The authenticator was unable to process the specified options, or could not create a new assertion signature`,code:`ERROR_AUTHENTICATOR_GENERAL_ERROR`,cause:e});return e}async function SE(e){let{optionsJSON:t,useBrowserAutofill:n=!1,verifyBrowserAutofillInput:r=!0}=e;if(!pE())throw Error(`WebAuthn is not supported in this browser`);let i;t.allowCredentials?.length!==0&&(i=t.allowCredentials?.map(mE));let a={...t,challenge:fE(t.challenge),allowCredentials:i},o={};if(n){if(!await bE())throw Error(`Browser does not support WebAuthn autofill`);if(document.querySelectorAll(`input[autocomplete$='webauthn']`).length<1&&r)throw Error('No <input> with "webauthn" as the only or last value in its `autocomplete` attribute was detected');o.mediation=`conditional`,a.allowCredentials=[]}o.publicKey=a,o.signal=_E.createNewAbortSignal();let s;try{s=await navigator.credentials.get(o)}catch(e){throw xE({error:e,options:o})}if(!s)throw Error(`Authentication was not completed`);let{id:c,rawId:l,response:u,type:d}=s,f;return u.userHandle&&(f=dE(u.userHandle)),{id:c,rawId:dE(l),response:{authenticatorData:dE(u.authenticatorData),clientDataJSON:dE(u.clientDataJSON),signature:dE(u.signature),userHandle:f},type:d,clientExtensionResults:s.getClientExtensionResults(),authenticatorAttachment:yE(s.authenticatorAttachment)}}function CE(e){return typeof e==`object`&&!!e}function wE(e){return CE(e)&&typeof e.challenge==`string`}O();function TE(e,t){return e instanceof Error&&e.message.length>0?e.message:t}function EE(e){let{t}=q(),n=V(),[r,i]=w(!1),[a,o]=w(``),[c,l]=w(null),[u,d]=w(null),f=p(null),m=b(e=>{f.current?.(e),f.current=null,i(!1),o(``),l(null),d(null)},[]),h=b(()=>new Promise(e=>{f.current?.(null),f.current=e,d(null),i(!0)}),[]),g=async()=>{l(`password`),d(null);try{let{reauthToken:e}=await n.reauthenticate({password:a});m(e)}catch(e){d(TE(e,`Password is incorrect`)),l(null)}},_=async()=>{l(`passkey`),d(null);try{let{optionsJSON:e}=await n.reauthBeginPasskey();if(!wE(e))throw Error(`passkey authentication options missing challenge`);let t=await SE({optionsJSON:e}),{reauthToken:r}=await n.reauthenticate({passkeyResponse:Object.fromEntries(Object.entries(t))});m(r)}catch(e){d(TE(e,`Passkey verification failed`)),l(null)}};return{requestProof:h,dialog:x(Mi,{open:r,onOpenChange:e=>!e&&m(null),children:s(Ir,{children:[s(Yr,{children:[x(qi,{children:t(`auth.reauthDialog.confirmItSYou`,`Confirm it’s you`)}),x($r,{children:t(`auth.reauthDialog.needsPassword`,{action:e})})]}),s(`form`,{className:`space-y-3`,onSubmit:e=>{e.preventDefault(),a.length>0&&c===null&&g()},children:[x(W,{type:`password`,autoComplete:`current-password`,placeholder:t(`auth.reauthDialog.currentPassword`,`Current password`),value:a,onChange:e=>o(e.target.value),"aria-label":t(`auth.reauthDialog.currentPassword`,`Current password`)}),u!==null&&x(`p`,{role:`alert`,className:`text-xs text-danger`,children:u}),s(Qa,{className:`flex flex-wrap gap-2`,children:[s(G,{type:`button`,variant:`outline`,disabled:c!==null,onClick:()=>void _(),children:[c===`passkey`?x(H,{className:`h-4 w-4 animate-spin`}):x(cr,{className:`h-4 w-4`}),t(`auth.reauthDialog.useAPasskey`,`Use a passkey`)]}),s(G,{type:`submit`,disabled:a.length===0||c!==null,children:[c===`password`&&x(H,{className:`h-4 w-4 animate-spin`}),t(`common.confirm`,`Confirm`)]})]})]})]})})}}O();function DE(e){return e.ip!==null&&e.approverIp!==null&&e.ip!==e.approverIp}function OE(e,t){return e instanceof Error&&e.message.length>0?e.message:t}function kE(e){let t=e instanceof Error?e.message:``;return t.startsWith(`Sign in again first`)||t.startsWith(`Confirm it is you`)}function AE(e,t){let n=Math.max(0,Math.round((t-e)/1e3));return n<5?{key:`justNow`,value:0}:n<60?{key:`seconds`,value:n}:{key:`minutes`,value:Math.round(n/60)}}function jE({onApproved:e,onDenied:t}){let{t:n}=q(),r=Ka.useUtils(),[i,a]=w(``),[o,c]=w(null),[l,u]=w(``),[d,f]=w(null),[p,m]=w(null),{requestProof:h,dialog:g}=EE(n(`cliLogin.reauthAction`,`Approving a terminal sign-in`)),_=Ka.auth.cliLoginApprove.useMutation(),v=Ka.auth.cliLoginDeny.useMutation(),y=async e=>{e.preventDefault(),f(`lookup`),m(null);try{c(await r.auth.cliLoginDescribe.fetch({userCode:i})),u(i)}catch(e){c(null),m(OE(e,n(`cliLogin.unknownCode`,`No pending sign-in with that code. Check the terminal.`)))}finally{f(null)}},b=async r=>{f(r),m(null);try{if(r===`deny`){await v.mutateAsync({userCode:l}),t();return}try{await _.mutateAsync({userCode:l})}catch(e){if(!kE(e))throw e;let t=await h();if(t===null)return;await _.mutateAsync({userCode:l,reauthToken:t})}e()}catch(e){m(OE(e,n(`cliLogin.failed`,`That did not work. Try again.`)))}finally{f(null)}},S=o===null?null:AE(o.createdAt,Date.now());return s(`div`,{className:`space-y-4`,"data-testid":`cli-login-approval`,children:[s(`div`,{className:`space-y-1`,children:[s(`h1`,{className:`flex items-center gap-2 text-sm font-semibold text-foreground`,children:[x(ur,{className:`h-4 w-4`,"aria-hidden":!0}),n(`cliLogin.title`,`Approve a terminal sign-in`)]}),x(`p`,{className:`text-xs text-foreground-subtle`,children:n(`cliLogin.intro`,`Type the code your terminal shows. Only approve a sign-in you started yourself.`)})]}),p!==null&&x(`div`,{role:`alert`,className:`rounded-md border border-danger/20 bg-danger/10 px-3 py-2 text-xs text-danger`,children:p}),o===null||S===null?s(`form`,{onSubmit:e=>void y(e),className:`space-y-3`,children:[x(W,{value:i,onChange:e=>a(e.target.value),placeholder:`ABCD-EFGH`,"aria-label":n(`cliLogin.codeLabel`,`Sign-in code`),autoComplete:`off`,autoCapitalize:`characters`,spellCheck:!1,maxLength:16,className:`text-center font-mono tracking-widest`}),s(G,{type:`submit`,variant:`primary`,className:`w-full`,disabled:i.trim().length<8||d!==null,children:[d===`lookup`&&x(H,{className:`h-4 w-4 animate-spin`,"aria-hidden":!0}),n(`cliLogin.continue`,`Continue`)]})]}):s(`div`,{className:`space-y-3`,children:[s(`dl`,{className:`space-y-1 rounded-md border border-border bg-background-elevated p-3 text-xs`,children:[s(`div`,{className:`flex justify-between gap-3`,children:[x(`dt`,{className:`text-foreground-muted`,children:n(`cliLogin.address`,`Terminal address`)}),x(`dd`,{className:`text-foreground`,"data-testid":`cli-login-ip`,children:o.ip??n(`cliLogin.unknownValue`,`Unknown`)})]}),s(`div`,{className:`flex justify-between gap-3`,children:[x(`dt`,{className:`text-foreground-muted`,children:n(`cliLogin.yourAddress`,`Your address`)}),x(`dd`,{className:`text-foreground`,"data-testid":`cli-login-approver-ip`,children:o.approverIp??n(`cliLogin.unknownValue`,`Unknown`)})]}),s(`div`,{className:`flex justify-between gap-3`,children:[x(`dt`,{className:`text-foreground-muted`,children:n(`cliLogin.program`,`Program (seen by the hub)`)}),x(`dd`,{className:`truncate text-foreground`,"data-testid":`cli-login-agent`,children:o.userAgent??n(`cliLogin.unknownValue`,`Unknown`)})]}),s(`div`,{className:`flex justify-between gap-3`,children:[x(`dt`,{className:`text-foreground-muted`,children:n(`cliLogin.client`,`Name it gave itself (unverified)`)}),x(`dd`,{className:`truncate text-foreground-muted`,"data-testid":`cli-login-client`,children:o.client??n(`cliLogin.unknownValue`,`Unknown`)})]}),s(`div`,{className:`flex justify-between gap-3`,children:[x(`dt`,{className:`text-foreground-muted`,children:n(`cliLogin.requested`,`Requested`)}),x(`dd`,{className:`text-foreground`,children:S.key===`justNow`?n(`cliLogin.ageNow`,`just now`):S.key===`seconds`?n(`cliLogin.ageSeconds`,`{{count}} s ago`,{count:S.value}):n(`cliLogin.ageMinutes`,`{{count}} min ago`,{count:S.value})})]})]}),DE(o)&&x(`div`,{role:`alert`,"data-testid":`cli-login-mismatch`,className:`rounded-md border border-warning/20 bg-warning/10 px-3 py-2 text-xs text-warning`,children:n(`cliLogin.mismatch`,`This request comes from a different address than the one you are using now. Approve it only if you started it from another machine of yours.`)}),x(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`cli-login-grant`,children:n(`cliLogin.grant`,`Approving signs this terminal in as you, with all of your rights, until the session expires or you end it under Tokens & sessions.`)}),s(`div`,{className:`flex gap-2`,children:[x(G,{type:`button`,variant:`ghost`,className:`flex-1`,disabled:d!==null,onClick:()=>void b(`deny`),children:n(`cliLogin.deny`,`Deny`)}),s(G,{type:`button`,variant:`primary`,className:`flex-1`,disabled:d!==null,onClick:()=>void b(`approve`),children:[d===`approve`&&x(H,{className:`h-4 w-4 animate-spin`,"aria-hidden":!0}),n(`cliLogin.approve`,`Approve`)]})]})]}),g]})}O();function ME(){let{t:e}=q(),t=ba(),n=ll(),[r,i]=w(!1);return x(`div`,{className:`flex min-h-screen items-center justify-center bg-background p-4`,children:s(`div`,{className:`w-full max-w-sm`,children:[x(`div`,{className:`mb-8 flex justify-center`,children:x(`img`,{src:t?.resolvedMode===`light`?B(`/brand/logo-horizontal-light.svg`):B(`/brand/logo-horizontal-dark.svg`),alt:e(`cliLogin.brand`,`CamStack`),className:`h-12`})}),x(`div`,{className:`rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10`,children:r?s(`div`,{className:`space-y-3 text-center`,"data-testid":`cli-login-denied`,children:[x(`p`,{className:`text-sm text-foreground`,children:e(`cliLogin.deniedBody`,`The sign-in was denied. The terminal stays signed out.`)}),x(G,{type:`button`,variant:`ghost`,onClick:()=>void n(`/`),children:e(`cliLogin.back`,`Back to CamStack`)})]}):x(jE,{onApproved:()=>window.location.assign(B(hn(null,{status:`success`,action:`cli-login`}))),onDenied:()=>i(!0)})})]})})}var NE=`auth.password-incorrect`;function PE(e,t){return typeof e==`object`&&e?Reflect.get(e,t):void 0}function FE(e){if(!(e instanceof Error))return{kind:`connection-lost`};let t=PE(e,`data`);return typeof t!=`object`||!t?{kind:`connection-lost`}:PE(PE(t,`i18n`),`code`)===NE?{kind:`wrong-current`}:PE(t,`code`)===`UNAUTHORIZED`?{kind:`session-ended`}:{kind:`rejected`,message:e.message}}O();var IE=8;function LE(e,t){let n=FE(e);switch(n.kind){case`wrong-current`:return t(`changePassword.errorWrongCurrent`,`The current password is incorrect.`);case`session-ended`:return t(`changePassword.errorSessionEnded`,`Your session ended before the change was confirmed. Sign in again — try the new password first.`);case`connection-lost`:return t(`changePassword.errorConnectionLost`,`The connection to the hub dropped before it confirmed the change. Sign in again — try the new password first.`);case`rejected`:return n.message}}function RE(){let{t:e}=q(),{user:t,mustChangePassword:n,clearMustChangePassword:r,logout:i}=ax(),a=V(),o=ba(),c=ll(),[l,u]=w(``),[d,f]=w(``),[p,m]=w(``),[h,g]=w(!1),[_,v]=w(``),[y,b]=w(!1),S=n?Yb:l;return x(`div`,{className:`flex min-h-screen items-center justify-center bg-background p-4`,children:s(`div`,{className:`w-full max-w-sm`,children:[x(`div`,{className:`flex justify-center mb-8`,children:x(`img`,{src:o?.resolvedMode===`light`?B(`/brand/logo-horizontal-light.svg`):B(`/brand/logo-horizontal-dark.svg`),alt:e(`changePassword.camstackAdmin`,`CamStack Admin`),className:`h-12`})}),s(`form`,{onSubmit:async i=>{if(i.preventDefault(),v(``),!t){v(`Not signed in`);return}if(!n&&l.length===0){v(e(`changePassword.enterCurrent`,`Enter your current password`));return}if(d.length<IE){v(`Password must be at least ${IE} characters`);return}if(d!==p){v(`The two passwords do not match`);return}if(d===`changeme`){v(`Choose a password different from the seed default`);return}b(!0);try{await a.changeOwnPassword({currentPassword:S,newPassword:d}),r(),c(`/devices`,{replace:!0})}catch(t){v(LE(t,e))}finally{b(!1)}},className:`space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10`,children:[s(`div`,{className:`space-y-1`,children:[x(`h1`,{className:`text-sm font-semibold text-foreground`,children:e(`changePassword.setANewPassword`,`Set a new password`)}),x(`p`,{className:`text-xs text-foreground-subtle`,children:n?e(`changePassword.youMustRotateTheSeed`,`You must rotate the seed password before continuing.`):e(`changePassword.chooseANewPasswordFor`,`Choose a new password for your account.`)})]}),_&&x(`div`,{role:`alert`,className:`rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger`,children:_}),!n&&s(`div`,{className:`space-y-1.5`,children:[x(`label`,{className:`text-xs font-medium text-foreground-subtle`,children:e(`changePassword.currentPassword`,`Current password`)}),x(W,{"data-testid":`change-password-current`,type:h?`text`:`password`,value:l,onChange:e=>u(e.target.value),autoComplete:`current-password`,className:`w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all`,autoFocus:!0})]}),s(`div`,{className:`space-y-1.5`,children:[x(`label`,{className:`text-xs font-medium text-foreground-subtle`,children:e(`changePassword.newPassword`,`New password`)}),s(`div`,{className:`relative`,children:[x(W,{"data-testid":`change-password-new`,type:h?`text`:`password`,value:d,onChange:e=>f(e.target.value),autoComplete:`new-password`,className:`w-full rounded-lg border border-border bg-background px-3 py-2.5 pr-10 text-sm text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all`,autoFocus:n}),x(G,{variant:`unstyled`,type:`button`,onClick:()=>g(!h),className:`absolute right-2.5 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground transition-colors`,tabIndex:-1,children:x(h?vt:Fe,{className:`h-4 w-4`})})]})]}),s(`div`,{className:`space-y-1.5`,children:[x(`label`,{className:`text-xs font-medium text-foreground-subtle`,children:e(`changePassword.confirmNewPassword`,`Confirm new password`)}),x(W,{"data-testid":`change-password-confirm`,type:h?`text`:`password`,value:p,onChange:e=>m(e.target.value),autoComplete:`new-password`,className:`w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all`})]}),x(G,{variant:`unstyled`,"data-testid":`change-password-submit`,type:`submit`,disabled:y||!d||!p,className:`w-full rounded-lg bg-primary px-4 py-2.5 text-sm font-semibold text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg hover:shadow-primary/30 disabled:opacity-50 disabled:shadow-none transition-all`,children:y?e(`changePassword.saving`,`Saving…`):e(`changePassword.saveAndContinue`,`Save and continue`)}),n&&x(G,{variant:`unstyled`,type:`button`,onClick:()=>{i(),c(`/login`,{replace:!0})},className:`w-full text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:e(`changePassword.signOutInstead`,`Sign out instead`)})]})]})})}O();async function zE(e){if(!wE(e))throw Error(`passkey authentication options missing challenge`);let t=await SE({optionsJSON:e});return Object.fromEntries(Object.entries(t))}function BE({method:e,challengeToken:t,onComplete:n,onSecondFactor:r,onError:i}){let[a,o]=w(!1),[c,l]=w(null),u=async()=>{l(null),o(!0);try{let e=rb();if(t){let r=await zE((await e.loginBeginPasskey(t)).optionsJSON),i=await e.loginVerifyPasskey(t,r,{refreshable:!0});n(i.token,i);return}let a=await zE((await e.passkeyLoginBegin()).optionsJSON),o=await e.passkeyLoginFinish(a,{refreshable:!0}),s=o.secondFactors??(o.requiresTotp===!0?[`totp`]:[]);if(s.length>0){if(r)r({challengeToken:o.token,factors:s});else{let e=`Additional verification is required — sign in with your password to continue.`;l(e),i?.(e)}return}n(o.token,o)}catch(e){let n=t?`Passkey verification failed`:`Passkey sign-in failed`,r=e instanceof Error?e.message:n;l(r),i?.(r)}finally{o(!1)}};return s(`div`,{className:`space-y-2`,children:[s(G,{variant:`unstyled`,type:`button`,"data-testid":t?`login-passkey`:`login-passkey-direct`,onClick:()=>void u(),disabled:a,className:`w-full flex items-center justify-center gap-2 rounded-lg border border-border bg-surface px-4 py-2.5 text-sm font-medium text-foreground hover:bg-surface-hover disabled:opacity-50 transition-colors`,children:[a?x(H,{className:`h-4 w-4 animate-spin text-primary`}):x(ir,{className:`h-4 w-4 text-primary`}),e.label]}),c&&x(`div`,{className:`rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger`,children:c})]})}var VE=()=>window.location.hostname;function HE(e,t=VE,n=null){return n===!1?!1:pE()&&jw(t(),e.rpId)}function UE(e,t=VE,n=null){let r=e.filter(e=>e.kind===`passkey`&&e.stage===`second-factor`).filter(e=>HE(e,t,n));return{passkeyMethods:r,widgetMethods:r.length>0?[]:e.filter(e=>e.kind===`widget`&&e.stage===`second-factor`)}}function WE(e,t){let n=e.includes(`passkey`),r=t.passkeyMethods.length>0||t.widgetMethods.length>0,i=e.includes(`totp`);return n&&!r&&!i}O();async function GE(){if(typeof PublicKeyCredential>`u`)return null;let e=PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable;if(typeof e!=`function`)return null;try{return await e.call(PublicKeyCredential)}catch{return null}}var KE=()=>`camstackAgentApp`in window;function qE(){let[e,t]=w(null);return S(()=>{if(!KE())return;let e=!0;return GE().then(n=>{e&&t(n)}),()=>{e=!1}},[]),e}function JE(e){let t=e.onComplete,n=e.onSecondFactor;return typeof t==`function`?{onComplete:t,onSecondFactor:typeof n==`function`?n:void 0}:null}function YE({methods:e,widgetConfig:t,onRedirect:n}){let{t:r}=q();Bi();let i=qE(),a=e.filter(e=>e.kind!==`passkey`||HE(e,void 0,i));return a.length===0?null:s(`div`,{className:`mt-6 space-y-3`,children:[s(`div`,{className:`flex items-center gap-3`,children:[x(`div`,{className:`h-px flex-1 bg-border`}),x(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:r(`login.primaryLoginMethods.orContinueWith`,`Or continue with`)}),x(`div`,{className:`h-px flex-1 bg-border`})]}),x(`div`,{className:`space-y-2`,children:a.map(e=>{if(e.kind===`redirect`){let t=(e.icon===void 0?void 0:zr(e.icon))??pe;return s(`a`,{href:e.startUrl,onClick:t=>{n?.(e)===!0&&t.preventDefault()},className:`flex items-center justify-center gap-2 w-full rounded-lg border border-border bg-surface px-4 py-2.5 text-sm font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[x(t,{className:`h-4 w-4 text-primary`}),e.label]},e.id)}if(e.kind===`passkey`){let n=JE(t);return n?x(BE,{method:e,onComplete:n.onComplete,onSecondFactor:n.onSecondFactor},e.id):null}return x(XE,{method:e,config:t},e.id)})})]})}function XE({method:e,config:t}){let{t:n}=q(),r=Ya(e.remote,e.bundleUrl);return r===null?s(`div`,{className:`flex items-center justify-center gap-2 rounded-lg border border-border bg-background px-4 py-2.5 text-xs text-foreground-subtle`,children:[x(H,{className:`h-3.5 w-3.5 animate-spin`}),n(`common.loading`,`Loading…`)]}):r===void 0?s(`div`,{"data-testid":`login-method-load-error`,className:`flex items-center justify-center gap-2 rounded-lg border border-danger/20 bg-danger/10 px-4 py-2.5 text-xs text-danger`,children:[x(te,{className:`h-3.5 w-3.5 shrink-0`}),n(`login.primaryMethods.loadFailed`)]}):x(r,{instanceId:e.id,host:`dashboard`,config:t})}var ZE=4e3,QE=/^[A-Za-z0-9._-]{1,64}$/;function $E(e){if(e.action===`cli-login`)return nE(`access`);let t=e.addonId!==void 0&&QE.test(e.addonId)?e.addonId:null,n=e.integration!==void 0&&QE.test(e.integration)?e.integration:null;if(t!==null&&e.brokerId!==void 0)return nE(`connectivity`,{integration:t,kindSection:`brokers`});let r=n??t;return nE(`connectivity`,r===null?{}:{integration:r})}function eD(e,t){let n=t.opener;if(n===null||n.closed||Vo(n)!==t.origin)return!1;try{return n.postMessage({type:yd,ok:e.status===`success`,...e.brokerId===void 0?{}:{brokerId:e.brokerId},...e.status===`error`?{error:e.reason??`unknown`}:{}},t.origin),!0}catch{return!1}}O();var tD=500;function nD(e){let{t}=q();switch(e){case`access_denied`:return t(`oauthLanding.reason.access_denied`,`Access was denied, so nothing was connected.`);case`invalid_state`:return t(`oauthLanding.reason.invalid_state`,`This sign-in link expired or was already used. Start the sign-in again.`);case`invalid_request`:return t(`oauthLanding.reason.invalid_request`,`The request was not valid for this hub. Start the link again from the beginning.`);case`unknown_broker`:return t(`oauthLanding.reason.unknown_broker`,`That connection no longer exists. Add it again, then sign in.`);case`not_configured`:return t(`oauthLanding.reason.not_configured`,`The connection is missing its client ID or secret. Fill them in, save, then sign in.`);case`exchange_failed`:return t(`oauthLanding.reason.exchange_failed`,`The provider did not accept the sign-in. Check the client ID and secret, then try again.`);case`no_authorization_code`:return t(`oauthLanding.reason.no_authorization_code`,`The provider finished the sign-in without granting CamStack access. Start the sign-in again from the beginning.`);case`no_refresh_token`:return t(`oauthLanding.reason.no_refresh_token`,`The provider returned no long-lived access. Remove CamStack from the account’s connected apps, then sign in again.`);case`unavailable`:return t(`oauthLanding.reason.unavailable`,`The hub is still starting this integration. Wait a moment and try again.`);case`unknown`:return t(`oauthLanding.reason.unknown`,`Something went wrong. Try again in a moment.`)}}function rD({outcome:e}){let{t}=q(),n=nD(e.reason??`unknown`);if(e.status===`error`)return s(F,{children:[x(Ee,{className:`mx-auto h-8 w-8 text-danger`,"aria-hidden":!0}),x(`h1`,{"data-testid":`oauth-landing-title`,className:`text-sm font-semibold text-foreground`,children:t(`oauthLanding.errorTitle`,`Sign-in did not finish`)}),x(`p`,{"data-testid":`oauth-landing-reason`,className:`rounded-md border border-danger/20 bg-danger/10 px-3 py-2 text-xs text-danger`,children:n})]});if(e.action===`cli-login`)return s(F,{children:[x(De,{className:`mx-auto h-8 w-8 text-success`,"aria-hidden":!0}),x(`h1`,{"data-testid":`oauth-landing-title`,className:`text-sm font-semibold text-foreground`,children:t(`oauthLanding.cliLoginTitle`,`Terminal signed in`)}),x(`p`,{className:`text-xs text-foreground-muted`,children:t(`oauthLanding.cliLoginBody`,`Go back to your terminal: it finishes the sign-in by itself.`)})]});let r=e.action===`disconnect`;return s(F,{children:[x(De,{className:`mx-auto h-8 w-8 text-success`,"aria-hidden":!0}),x(`h1`,{"data-testid":`oauth-landing-title`,className:`text-sm font-semibold text-foreground`,children:r?t(`oauthLanding.signedOutTitle`,`Signed out`):t(`oauthLanding.successTitle`,`Signed in`)}),x(`p`,{className:`text-xs text-foreground-muted`,children:r?t(`oauthLanding.signedOutBody`,`The account was disconnected from this hub.`):t(`oauthLanding.successBody`,`The account is connected. Returning to CamStack…`)})]})}function iD({outcome:e,closable:t,onContinue:n,onClose:r}){let{t:i}=q(),a=$E(e);return S(()=>{if(e.status!==`success`)return;let t=window.setTimeout(()=>n(a),ZE);return()=>window.clearTimeout(t)},[e.status,n,a]),x(`main`,{className:`flex min-h-screen items-center justify-center bg-background p-4`,children:s(`div`,{className:`w-full max-w-sm space-y-4`,children:[x(`div`,{className:`flex justify-center`,children:s(`picture`,{children:[x(`source`,{media:`(prefers-color-scheme: dark)`,srcSet:B(`/brand/logo-horizontal-dark.svg`)}),x(`img`,{src:B(`/brand/logo-horizontal-light.svg`),alt:i(`oauthLanding.brand`,`CamStack`),className:`h-12`})]})}),s(`div`,{className:`space-y-4 rounded-xl border border-border bg-surface p-6 text-center shadow-xl shadow-black/10`,children:[x(rD,{outcome:e}),s(`div`,{className:`flex flex-col gap-2`,children:[x(G,{type:`button`,variant:`primary`,onClick:()=>n(a),children:i(`oauthLanding.back`,`Back to CamStack`)}),t&&x(G,{type:`button`,variant:`ghost`,onClick:r,children:i(`oauthLanding.close`,`Close this window`)})]})]})]})})}function aD(e,t){window.history.replaceState(null,``,window.location.pathname);let n=window.opener,r=eD(t,{opener:n,origin:window.location.origin}),i=()=>e.render(x(iD,{outcome:t,closable:r,onContinue:e=>window.location.replace(B(e)),onClose:()=>window.close()}));if(r&&t.status===`success`){window.close(),window.setTimeout(i,tD);return}i()}function oD(e){return In(e)}var sD=`Done — you can close this window.`,cD=500,lD=`camstack_admin_token`;async function uD(e,t=``){try{let n=mb(new URLSearchParams(t));n!==null&&n.token===e?db(n):localStorage.setItem(lD,e)}catch{}await fetch(B(`/api/auth/session`),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({token:e})}).catch(()=>{})}function dD(){try{let e=localStorage.getItem(lD);return e!==null&&e.length>0?e:null}catch{return null}}function fD(e){let t=oD(window.location.hash);if(t!==null){aD(e,t);return}let n=Io(window.location.hash);window.history.replaceState(null,``,window.location.pathname);let r=t=>e.render(x(pD,{completion:n,result:t,hasOpener:window.opener!==null}));if(r(null),n===null)return;let i=Ho();Wo(n,{opener:window.opener,origin:window.location.origin,channel:i,addEventListener:(e,t)=>window.addEventListener(e,t),removeEventListener:(e,t)=>window.removeEventListener(e,t),close:()=>{window.close(),window.setTimeout(()=>r({kind:`done`,message:sD}),cD)},continueAt:e=>window.location.replace(B(e)),persistSession:e=>uD(e,n.target===`login`?n.fragment:``),showResult:r,setTimeout:(e,t)=>window.setTimeout(e,t)})}function pD({completion:e,result:t,hasOpener:n=!0}){let{t:r}=q();return x(`div`,{className:`flex min-h-screen items-center justify-center bg-background p-4`,children:x(`div`,{className:`flex flex-col items-center gap-3 text-sm text-foreground-subtle`,children:e===null?x(`a`,{className:`text-primary underline`,href:B(`/login`),children:r(`ssoComplete.nothingToFinishHereGo`,`Nothing to finish here — go to sign-in`)}):t===null?s(`span`,{className:`flex items-center gap-3`,children:[x(`span`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-primary/30 border-t-primary`}),r(`ssoComplete.finishingSignIn`,`Finishing sign-in…`)]}):s(F,{children:[x(`span`,{"data-testid":`sso-complete-result`,className:t.kind===`link-error`?`text-danger`:`text-foreground`,children:t.message}),x(G,{variant:`unstyled`,type:`button`,className:`rounded-md border border-border px-3 py-1.5 text-foreground hover:bg-surface-hover`,onClick:()=>window.close(),children:r(`ssoComplete.closeThisWindow`,`Close this window`)}),!n&&x(`a`,{className:`text-primary underline`,href:B(`/login`),children:r(`ssoComplete.backToSignIn`,`Back to sign-in`)})]})})})}O();function mD(e){if(typeof e!=`object`||!e)return!1;let t=Reflect.get(e,`message`),n=Reflect.get(e,`data`);return(typeof n==`object`&&n?Reflect.get(n,`code`):void 0)===`FORBIDDEN`||typeof t==`string`&&/sign in again first/i.test(t)}function hD(){let e=new URLSearchParams(window.location.search);return kb({codeChallenge:e.get(`code_challenge`),codeChallengeMethod:e.get(`code_challenge_method`),state:e.get(`state`),purpose:e.get(`purpose`)})}function gD(e){return Math.min(1e3*2**e,15e3)}function _D(){let{t:e}=q(),{login:t,verifyTotp:n,finalizePasskeyLogin:r,user:i}=ax(),{i18n:a}=q(),o=ba(),c=ll(),l=Y(),u=new URLSearchParams(window.location.search).get(`next`);S(()=>{Rb(u)},[u]);let d=new URLSearchParams(window.location.search).get(`redirect`);S(()=>{qb(d)},[d]);let f=hD();S(()=>{Mb(f)},[f?.codeChallenge,f?.state,f?.purpose]);let m=l.state,h=IT(m?.from),[g,_]=w(``),[v,y]=w(``),[b,C]=w(!1),[T,E]=w(``),[D,O]=w(!1),[k,A]=w(`credentials`),[j,M]=w(``),[N,ee]=w([]),[P,I]=w(``),[L,te]=w(void 0),[ne,ie]=w(`sso-not-linked`),ae=Ka.auth.listLoginMethods.useQuery(void 0,{retry:!0,retryDelay:gD}),oe=ae.data===void 0,se=(ae.data??[]).filter(e=>e.kind!==`device-certificate`),R=Ka.auth.getServerName.useQuery().data,ce=se.filter(e=>e.stage===`primary`),le=UE(se,void 0,qE());S(()=>{let e=Go(window.location.hash);if(e!==null){if(window.history.replaceState({},``,window.location.pathname+window.location.search),e.kind===`challenge`){M(e.challengeToken),ee(e.factors),I(``),A(`second-factor`);return}ie(e.code),te(e.provider)}},[]);let ue=L==null?null:se.find(e=>e.id===L&&`label`in e)?.label??null,de=T||(L===void 0?``:Ro(ne,ue)),{passkeyMethods:fe,widgetMethods:z}=le,pe=p(!1),me=async()=>{if(pe.current)return;pe.current=!0;let e=Fb(d);if(e?.kind===`app-callback`){await _e(e.url);return}else if(e){window.location.assign(B(e.path));return}let t=Bb(u);t?window.location.assign(B(t)):c(h,{replace:!0})},[he,ge]=w(null),_e=async e=>{ge({callbackBase:e,mintedUrl:null,failed:!1});try{let t=hD()??Nb();if(t===null)throw Error(`The app sent no PKCE challenge and state`);let{code:n}=await rb().trpcClient.auth.createHandoffCode.mutate({purpose:t.purpose,codeChallenge:t.codeChallenge,state:t.state}),r=Pb(e,n,t.state);ge({callbackBase:e,mintedUrl:r,failed:!1}),window.location.assign(r)}catch(t){if(mD(t)){pe.current=!1,ge(null),E(`Sign in again to confirm it is you.`);return}ge({callbackBase:e,mintedUrl:null,failed:!0})}},ve=i!==null,[ye,be]=w(!1);S(()=>{!ve||!d&&!u||ye||(be(!0),me())},[ve,d,u,ye]);let xe=async e=>{e.preventDefault(),E(``),te(void 0),O(!0);try{let e=await t(g,v);if(e.kind===`second-factor`){M(e.challengeToken),ee(e.factors),A(`second-factor`);return}v===`changeme`?c(`/change-password`,{replace:!0}):await me()}catch(e){E(e instanceof Error?e.message:`Login failed`)}finally{O(!1)}},Se=async e=>{e.preventDefault(),E(``),O(!0);try{await n(j,P.trim()),await me()}catch(e){E(e instanceof Error?e.message:`TOTP verification failed`),I(``)}finally{O(!1)}},Ce=async(e,t)=>{try{await r(e,t),await me()}catch(e){E(e instanceof Error?e.message:`Passkey sign-in failed`)}},we=p(null);S(()=>()=>we.current?.(),[]);let Ee=async e=>{if(e.target!==`login`)return;let t=mb(new URLSearchParams(e.fragment));if(t!==null){try{await r(t.token,t),await me()}catch(e){E(e instanceof Error?e.message:`Sign-in failed`)}return}let n=Go(`#${e.fragment}`);if(n!==null){if(n.kind===`challenge`){Oe({challengeToken:n.challengeToken,factors:n.factors});return}ie(n.code),te(n.provider)}},De=e=>{if(Eb(d)?.kind===`app-callback`)return!1;let t=zo(B(Lo(e.startUrl)));return t===null?!1:(E(``),te(void 0),we.current?.(),we.current=Uo(t,{onReturn:e=>{we.current?.(),we.current=null,Ee(e)},onDone:e=>{if(we.current?.(),we.current=null,e.target!==`login`)return;let t=dD()===null?null:ub();t!==null&&Ee({target:`login`,fragment:new URLSearchParams({token:t.token,...t.refreshToken===void 0?{}:{refreshToken:t.refreshToken},...t.expiresAt===void 0?{}:{expiresAt:String(t.expiresAt)}}).toString()})}}),!0)},Oe=e=>{let t=e.factors.filter(e=>e===`totp`||e===`passkey`);M(e.challengeToken),ee(t),I(``),E(``),A(`second-factor`)};return he===null?x(`div`,{className:`flex min-h-screen items-center justify-center bg-background p-4`,children:s(`div`,{className:`w-full max-w-sm`,children:[x(`div`,{className:`flex justify-center mb-8`,children:x(`img`,{src:o?.resolvedMode===`light`?B(`/brand/logo-horizontal-light.svg`):B(`/brand/logo-horizontal-dark.svg`),alt:e(`login.camstackAdmin`,`CamStack Admin`),className:`h-12`})}),R!==void 0&&!R.isDefault&&x(`p`,{"data-testid":`login-server-name`,className:`-mt-4 mb-6 text-center text-sm text-foreground-muted`,children:x(_d,{i18nKey:`login.signInTo`,values:{name:R.name},components:{b:x(`span`,{className:`font-semibold text-foreground`})}})}),k===`credentials`?s(`form`,{onSubmit:xe,className:`space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10`,children:[de&&x(`div`,{"data-testid":`login-error`,className:`rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger`,children:de}),s(`div`,{className:`space-y-1.5`,children:[x(`label`,{className:`text-xs font-medium text-foreground-subtle`,children:e(`login.username`,`Username`)}),x(W,{"data-testid":`login-username`,type:`text`,placeholder:e(`login.username`,`Username`),value:g,onChange:e=>_(e.target.value),className:`w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all`,autoFocus:!0})]}),s(`div`,{className:`space-y-1.5`,children:[x(`label`,{className:`text-xs font-medium text-foreground-subtle`,children:e(`login.password`,`Password`)}),s(`div`,{className:`relative`,children:[x(W,{"data-testid":`login-password`,type:b?`text`:`password`,placeholder:e(`login.password`,`Password`),value:v,onChange:e=>y(e.target.value),className:`w-full rounded-lg border border-border bg-background px-3 py-2.5 pr-10 text-sm text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all`}),x(G,{variant:`unstyled`,type:`button`,onClick:()=>C(!b),className:`absolute right-2.5 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground transition-colors`,tabIndex:-1,children:x(b?vt:Fe,{className:`h-4 w-4`})})]})]}),x(G,{variant:`unstyled`,"data-testid":`login-submit`,type:`submit`,disabled:D||!g||!v,className:`w-full rounded-lg bg-primary px-4 py-2.5 text-sm font-semibold text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg hover:shadow-primary/30 disabled:opacity-50 disabled:shadow-none transition-all`,children:D?s(`span`,{className:`flex items-center justify-center gap-2`,children:[x(`span`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-primary-foreground/30 border-t-primary-foreground`}),e(`login.loggingIn`,`Logging in...`)]}):e(`login.logIn`,`Log in`)})]}):s(`div`,{className:`space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10`,children:[s(`div`,{className:`flex items-center gap-2 pb-1 border-b border-border`,children:[x(re,{className:`h-4 w-4 text-primary`}),x(`div`,{className:`text-sm font-medium text-foreground`,children:e(`login.twoFactorAuthentication`,`Two-factor authentication`)})]}),x(`p`,{className:`text-xs text-foreground-subtle`,children:g?x(F,{children:x(_d,{i18nKey:`login.finishSigningInAs`,values:{username:g},components:{mono:x(`span`,{className:`font-mono text-foreground`})}})}):e(`login.finishSigningInAs`,`Finish signing in.`)}),T&&x(`div`,{className:`rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger`,children:T}),N.includes(`passkey`)&&fe.map(e=>x(BE,{method:e,challengeToken:j,onComplete:Ce},e.id)),N.includes(`passkey`)&&z.map(e=>x(XE,{method:e,config:{challengeToken:j,onComplete:Ce}},e.id)),WE(N,le)&&x(`div`,{className:`rounded-md border border-border bg-background px-3 py-2 text-xs text-foreground-subtle`,children:e(`login.passkeyVerificationIsnTAvailable`,`Passkey verification isn't available on this address. Open the hub via its domain URL to complete sign-in.`)}),N.includes(`passkey`)&&N.includes(`totp`)&&s(`div`,{className:`flex items-center gap-3`,children:[x(`div`,{className:`h-px flex-1 bg-border`}),x(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`or`}),x(`div`,{className:`h-px flex-1 bg-border`})]}),N.includes(`totp`)&&s(`form`,{onSubmit:Se,className:`space-y-4`,children:[s(`div`,{className:`space-y-1.5`,children:[x(`label`,{className:`text-xs font-medium text-foreground-subtle`,children:e(`login.authenticationCode`,`Authentication code`)}),x(W,{"data-testid":`login-totp`,type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:P,onChange:e=>I(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-lg border border-border bg-background px-3 py-3 text-center text-2xl font-mono tracking-widest text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all`,autoFocus:!0})]}),x(G,{variant:`unstyled`,"data-testid":`login-totp-submit`,type:`submit`,disabled:D||P.length!==6,className:`w-full rounded-lg bg-primary px-4 py-2.5 text-sm font-semibold text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg hover:shadow-primary/30 disabled:opacity-50 disabled:shadow-none transition-all`,children:D?s(`span`,{className:`flex items-center justify-center gap-2`,children:[x(`span`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-primary-foreground/30 border-t-primary-foreground`}),e(`login.verifying`,`Verifying...`)]}):e(`login.verifyAndSignIn`,`Verify and sign in`)})]}),s(G,{variant:`unstyled`,type:`button`,onClick:()=>{A(`credentials`),M(``),ee([]),I(``),E(``)},className:`w-full flex items-center justify-center gap-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:[x(Te,{className:`h-3 w-3`}),e(`login.backToUsernamePassword`,`Back to username + password`)]})]}),k===`credentials`&&oe&&s(`p`,{"data-testid":`login-methods-pending`,role:`status`,className:`mt-4 flex items-center justify-center gap-2 text-xs text-foreground-subtle`,children:[x(`span`,{className:`h-3 w-3 animate-spin rounded-full border-2 border-foreground-subtle/30 border-t-foreground-subtle`}),e(`login.methodsPending`,`Loading other sign-in options...`)]}),k===`credentials`&&x(YE,{methods:ce,widgetConfig:{onComplete:Ce,onSecondFactor:Oe,locale:a.language},onRedirect:De}),x(`p`,{className:`mt-6 text-center text-[10px] text-foreground-subtle/50`,children:x(UT,{placement:`login`})})]})}):x(`div`,{className:`flex min-h-screen items-center justify-center bg-background p-4`,children:s(`div`,{className:`w-full max-w-sm rounded-xl border border-border bg-surface p-6 text-center space-y-4`,children:[x(`h1`,{className:`text-sm font-semibold text-foreground`,children:e(`login.returningToTheApp`,`Returning to the app…`)}),he.failed?s(F,{children:[x(`p`,{className:`text-xs text-danger`,children:e(`login.couldNotPrepareTheSign`,`Could not prepare the sign-in handoff. You are logged in — retry below.`)}),x(G,{variant:`unstyled`,onClick:()=>void _e(he.callbackBase),className:`inline-flex rounded-lg bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90`,children:e(`common.retry`,`Retry`)})]}):he.mintedUrl===null?x(`p`,{className:`text-xs text-foreground-subtle`,children:e(`login.preparingAOneTimeSign`,`Preparing a one-time sign-in code…`)}):s(F,{children:[x(`p`,{className:`text-xs text-foreground-subtle`,children:e(`login.ifTheAppDoesNot`,`If the app does not open automatically, tap below (the code expires in 60s).`)}),x(`a`,{href:he.mintedUrl,className:`inline-flex rounded-lg bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90`,children:e(`login.openCamstack`,`Open CamStack`)})]})]})})}function vD(e){let t=new URLSearchParams(e).get(mw),n=new URLSearchParams({tab:`templates`});return t!==null&&n.set(mw,t),`/build?${n.toString()}`}function yD(){let{search:e}=Y();return x(X,{to:vD(e),replace:!0})}O();function bD(){let{pathname:e,search:t,hash:n}=Y();return x(X,{to:`${aE(e)}${t}${n}`,replace:!0})}function xD(){let{pathname:e,search:t}=Y();return x(X,{to:Rs(e,t)??`/archive`,replace:!0})}function SD(){let{nodeId:e=``}=pl();return x(X,{to:`/system/terminal?tab=shells&node=${encodeURIComponent(e)}`,replace:!0})}function CD(){let{pathname:e,search:t}=Y(),n=Rs(e,t);return n===null?x(ND,{}):x(X,{to:n,replace:!0})}function wD(){return x(X,{to:PT()??`/devices`,replace:!0})}var TD=g(()=>a(()=>import(`./Devices-D8DTAwFv.js`).then(e=>({default:e.DevicesPage})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11]),import.meta.url)),ED=g(()=>a(()=>import(`./Integrations-9Im6toi_.js`).then(e=>({default:e.IntegrationsPage})),__vite__mapDeps([12,1,2,3,4,5,13,6,14,7,8,10]),import.meta.url)),DD=g(()=>a(()=>import(`./IntegrationDetail-HyHJN95v.js`).then(e=>({default:e.IntegrationDetailPage})),__vite__mapDeps([15,1,2,3,4,5,16,6,8,9]),import.meta.url)),OD=g(()=>a(()=>import(`./Pipeline-BOw5x-8P.js`).then(e=>({default:e.PipelinePage})),__vite__mapDeps([17,1,2,3,4,5,13,6,18,19,20,21,22,23,24,25,10]),import.meta.url)),kD=g(()=>a(()=>import(`./DeviceDetail-NBocrvbT.js`).then(e=>({default:e.DeviceDetailPage})),__vite__mapDeps([26,1,2,3,4,5,13,6,18,27,28,29,30,31,21,32,33,34,35,36,37,38,39,40,41,42,24,10,43,44]),import.meta.url)),AD=g(()=>a(()=>import(`./Showroom-BV_20igh.js`).then(e=>({default:e.ShowroomPage})),__vite__mapDeps([45,1,2,3,4,5]),import.meta.url)),jD=g(()=>a(()=>import(`./EmbedPlayerPage-B5_-KzBH.js`).then(e=>({default:e.EmbedPlayerPage})),__vite__mapDeps([46,1,2,3,4,5,6]),import.meta.url)),MD=g(()=>a(()=>import(`./EmbedDevicePage-CPQdBTEQ.js`).then(e=>({default:e.EmbedDevicePage})),__vite__mapDeps([47,1,2,3,4,5,6]),import.meta.url)),ND=g(()=>a(()=>import(`./Library-_igcImHQ.js`).then(e=>({default:e.LibraryPage})),__vite__mapDeps([48,1,2,3,4,5,13,6,18,49,20,50,51,52,53,43,37,54]),import.meta.url)),PD=g(()=>a(()=>import(`./Archive-C6_m1wEE.js`).then(e=>({default:e.ArchivePage})),__vite__mapDeps([55,1,2,3,4,5,13,6,18,56,50,51,52,36,37,57,58,59,60,61,22,23,54,43]),import.meta.url)),FD=g(()=>a(()=>import(`./Viewer-DZ8d24s6.js`).then(e=>({default:e.ViewerPage})),__vite__mapDeps([62,2,3,4,5,63,6,37,1]),import.meta.url)),ID=g(()=>a(()=>import(`./Build-DvKE6nTb.js`).then(e=>({default:e.BuildPage})),__vite__mapDeps([64,1,2,3,4,5,13,6,18,30,65,51,32,27,33,34,35,38,39,40,42,66]),import.meta.url)),LD=g(()=>a(()=>import(`./CompositionEditorPage-B9gDFYDb.js`).then(e=>({default:e.CompositionEditorPage})),__vite__mapDeps([67,1,2,3,4,5,6,7,32,13,18,27,33,34,35]),import.meta.url)),RD=g(()=>a(()=>import(`./Locations-BXSHCcGW.js`).then(e=>({default:e.LocationsPage})),__vite__mapDeps([68,1,2,3,4,5,13,6,51,41,34,35]),import.meta.url)),zD=g(()=>a(()=>import(`./Addons-DWymb9Vl.js`).then(e=>({default:e.AddonsPage})),__vite__mapDeps([69,1,2,3,4,5,18,6,7,70,22,23,11,37]),import.meta.url)),BD=g(()=>a(()=>import(`./AiProfiles-BIxZ2_6q.js`).then(e=>({default:e.AiProfilesPage})),__vite__mapDeps([71,1,2,3,4,5,13,6,72,73,7,51,60,61,22,23,37,74]),import.meta.url)),VD=g(()=>a(()=>import(`./MyAccess-d4Dxkbs9.js`).then(e=>({default:e.MyAccessPage})),__vite__mapDeps([75,1,2,3,4,5,13,6,18,76,39,7,51,77,78,37,79]),import.meta.url)),HD=g(()=>a(()=>import(`./Logs-BFhMej4c.js`).then(e=>({default:e.LogsPage})),__vite__mapDeps([80,1,2,3,4,5,21,81,6,7,51,60,61,22,23,37]),import.meta.url)),UD=g(()=>a(()=>import(`./Identity-D0tXeMJI.js`).then(e=>({default:e.IdentityPage})),__vite__mapDeps([82,1,2,3,4,5,13,6,18,31,83,76,39,7,51,60,61,22,23,37,77,78,84]),import.meta.url)),WD=g(()=>a(()=>import(`./Network-CZWNHZbt.js`).then(e=>({default:e.NetworkPage})),__vite__mapDeps([85,1,2,3,4,5,13,6,18,7,51,60,61,22,23,37,86]),import.meta.url)),GD=g(()=>a(()=>import(`./Integrations-CZBdHxHR.js`).then(e=>({default:e.IntegrationsPage})),__vite__mapDeps([87,1,2,3,4,5,6,51,60,61,22,23,37]),import.meta.url)),KD=g(()=>a(()=>import(`./TrainingProviders-QpCAaIRs.js`).then(e=>({default:e.TrainingProvidersPage})),__vite__mapDeps([88,1,2,3,4,5,6,7,60,61,22,23,37]),import.meta.url)),qD=g(()=>a(()=>import(`./Data-CcpaQCFA.js`).then(e=>({default:e.DataPage})),__vite__mapDeps([89,1,2,3,4,5,13,6,18,28,90,59,7,51,60,61,22,23,37,57,58,54,43]),import.meta.url)),JD=g(()=>a(()=>import(`./System-kmtCUnQG.js`).then(e=>({default:e.SystemPage})),__vite__mapDeps([91,1,2,3,4,5,13,6,92,7,51,84,23,37]),import.meta.url)),YD=g(()=>a(()=>import(`./Cluster-DbxqzICC.js`).then(e=>({default:e.ClusterPage})),__vite__mapDeps([93,1,2,3,4,5,13,6,59,94,39,7,70,42,22,23,25,54]),import.meta.url)),XD=g(()=>a(()=>import(`./Terminal-CCvtDRX3.js`).then(e=>({default:e.TerminalPage})),__vite__mapDeps([95,1,2,3,4,5,18,6,7,60,61,22,23,37,77,33,42,13,86,96]),import.meta.url)),ZD=g(()=>a(()=>import(`./Notifications-BvvHJsaT.js`).then(e=>({default:e.NotificationsPage})),__vite__mapDeps([97,1,2,3,4,5,13,6,72,98,7,51,60,61,22,23,37,42,53,66,40,74,35,44]),import.meta.url)),QD=g(()=>a(()=>import(`./History-ft50TIgH.js`).then(e=>({default:e.HistoryPage})),__vite__mapDeps([99,1,2,3,4,5,18,6,7]),import.meta.url)),$D=g(()=>a(()=>import(`./Calendars-DHzAhyJ7.js`).then(e=>({default:e.CalendarsPage})),__vite__mapDeps([100,1,2,3,4,5,13,6,7]),import.meta.url)),eO=new D({defaultOptions:{queries:{gcTime:0,staleTime:0,retry:!1,refetchOnWindowFocus:!1}}});Ta(eO);function tO({field:e,value:t,onChange:n,disabled:r}){return x(XS,{field:e,value:t,onChange:n,disabled:r})}var nO={"model-selector":tO};function rO({children:e}){let{t}=q(),{user:n,logout:r}=ax(),[i,a]=w(0),o=p(n?.username??null);S(()=>{let e=n?.username??null;e!==o.current&&(o.current=e,ib(),a(e=>e+1))},[n]);let c=m(()=>rb(),[i]),l=b(()=>{rb().reconnect(),a(e=>e+1),eO.invalidateQueries()},[]);xC(b(()=>Cb(l),[l])),S(()=>yb(()=>{rb().isSocketTokenStale()&&l()}),[l]);let u=b(async()=>{let e=await wb();return e&&l(),e},[l]),{bootReady:d,bootError:f}=yC(c,n??null,r,u);return x(gC,{children:x(Je,{system:c,children:x(Ka.Provider,{client:c.trpcClient,queryClient:eO,children:s(ga,{children:[x(Qr,{children:x(ha,{children:x(wr,{children:d?e:x(iO,{})})})}),d&&x(nC,{}),f!==null&&d&&s(`div`,{className:`fixed bottom-[calc(env(safe-area-inset-bottom)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)] z-50 max-w-sm rounded-lg border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning shadow-lg`,children:[t(`app.bootProbeFailed`,`Boot probe failed:`),` `,f,`. Retrying in background.`]})]})})})})}function iO(){let{t:e}=q();return x(`div`,{className:`flex min-h-screen items-center justify-center bg-background`,children:s(`div`,{className:`flex items-center gap-3 text-sm text-foreground-subtle`,children:[x(`span`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-primary/30 border-t-primary`}),e(`app.connecting`,`Connecting…`)]})})}function aO(){return x(`div`,{className:`flex min-h-screen items-center justify-center bg-background`,children:x(`span`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-primary/30 border-t-primary`})})}function oO(){return S(()=>lE(),[]),x(ta,{defaultMode:`dark`,children:x(ti,{children:x(P,{client:eO,children:x(ix,{children:x(rO,{children:x(Xe,{children:x(tC,{children:x(vo,{renderers:nO,children:s(xo,{picker:ay,children:[x(Du,{basename:pt(),children:x(WS,{children:x(y,{fallback:x(aO,{}),children:s(Rl,{children:[x(Z,{path:`/login`,element:x(_D,{})}),x(Z,{path:`/admin/*`,element:x(bD,{})}),x(Z,{path:`/admin`,element:x(bD,{})}),x(Z,{path:`/change-password`,element:x($,{children:x(RE,{})})}),x(Z,{path:`/approve`,element:x($,{children:x(ME,{})})}),x(Z,{path:`/showroom`,element:x(AD,{})}),x(Z,{path:`/embed/player`,element:x(jD,{})}),x(Z,{path:`/embed/device/:deviceId`,element:x($,{children:x(MD,{})})}),s(Z,{element:x($,{children:x(pv,{children:x(XT,{})})}),children:[x(Z,{index:!0,element:x(wD,{})}),x(Z,{path:`/access-denied`,element:x(uE,{})}),x(Z,{path:`/dashboard`,element:x(X,{to:`/devices`,replace:!0})}),x(Z,{path:`/devices`,element:x(TD,{})}),x(Z,{path:`/cameras`,element:x(X,{to:`/devices`,replace:!0})}),x(Z,{path:`/integrations`,element:x(ED,{})}),x(Z,{path:`/integrations/:addonId`,element:x(DD,{})}),x(Z,{path:`/system/pipeline`,element:x($C,{path:`/system/pipeline`,children:x(OD,{})})}),x(Z,{path:`/pipeline`,element:x(X,{to:`/system/pipeline`,replace:!0})}),x(Z,{path:`/live`,element:x(FD,{})}),x(Z,{path:`/devices/:deviceId`,element:x(kD,{})}),x(Z,{path:`/system/logs`,element:x($,{requireAdmin:!0,children:x(HD,{})})}),x(Z,{path:`/system/addons`,element:x($,{requireAdmin:!0,children:x(zD,{})})}),x(Z,{path:`/system/ai`,element:x($,{requireAdmin:!0,children:x(BD,{})})}),x(Z,{path:`/system/settings`,element:x($,{requireAdmin:!0,children:x(JD,{})})}),x(Z,{path:`/system/nodes`,element:x($,{requireAdmin:!0,children:x(YD,{})})}),x(Z,{path:`/system/notifications`,element:x($,{requireAdmin:!0,children:x(ZD,{})})}),x(Z,{path:`/system/history`,element:x($,{requireAdmin:!0,children:x(QD,{})})}),x(Z,{path:`/system/calendars`,element:x($,{requireAdmin:!0,children:x($D,{})})}),x(Z,{path:`/system/templates`,element:x(yD,{})}),x(Z,{path:`/system/identity`,element:x($,{requireAdmin:!0,children:x(UD,{})})}),x(Z,{path:`/system/my-access`,element:x(VD,{})}),x(Z,{path:`/system/network`,element:x($,{requireAdmin:!0,children:x(WD,{})})}),x(Z,{path:`/training/providers`,element:x($,{requireAdmin:!0,children:x(KD,{})})}),x(Z,{path:`/system/integrations`,element:x($,{requireAdmin:!0,children:x(GD,{})})}),x(Z,{path:`/system/data`,element:x($,{requireAdmin:!0,children:x(qD,{})})}),x(Z,{path:`/system`,element:x(X,{to:aC,replace:!0})}),x(Z,{path:`/system/terminal/:nodeId/*`,element:x(SD,{})}),x(Z,{path:`/system/terminal`,element:x($,{requireAdmin:!0,children:x(XD,{})})}),x(Z,{path:lC,element:x(fC,{})}),oC.map(e=>x(Z,{path:e.path,element:x(dC,{tab:e.tab})},e.path)),x(Z,{path:`/system/users`,element:x(X,{to:`/system/identity?tab=users`,replace:!0})}),x(Z,{path:`/system/api-keys`,element:x(X,{to:`/system/identity?tab=api-keys`,replace:!0})}),x(Z,{path:`/system/authentication`,element:x(X,{to:nE(`authentication`),replace:!0})}),x(Z,{path:`/system/linked-sessions`,element:x(X,{to:`/system/identity?tab=linked-sessions`,replace:!0})}),x(Z,{path:`/system/remote-access`,element:x(X,{to:nE(`remoteAccess`),replace:!0})}),x(Z,{path:`/system/turn`,element:x(X,{to:nE(`turn`),replace:!0})}),x(Z,{path:`/system/storage`,element:x(X,{to:`/system/data?tab=storage`,replace:!0})}),x(Z,{path:`/system/backup`,element:x(X,{to:`/system/data?tab=backup`,replace:!0})}),x(Z,{path:`/library`,element:x($,{requireAdmin:!0,children:x(CD,{})})}),x(Z,{path:`/retrain`,element:x(X,{to:`/addon/training`,replace:!0})}),x(Z,{path:`/archive`,element:x($,{requireAdmin:!0,children:x(PD,{})})}),x(Z,{path:`/archive/:deviceId`,element:x(xD,{})}),x(Z,{path:`/recordings`,element:x(xD,{})}),x(Z,{path:`/build`,element:x($,{requireAdmin:!0,children:x(ID,{})})}),x(Z,{path:dy,element:x($,{requireAdmin:!0,children:x(LD,{})})}),x(Z,{path:fy,element:x($,{requireAdmin:!0,children:x(LD,{})})}),x(Z,{path:`/locations`,element:x($,{requireAdmin:!0,children:x(RD,{})})}),x(Z,{path:`/automation`,element:x(ZS,{to:`/build`})}),x(Z,{path:`/addon/:pagePath`,element:x($,{requireAdmin:!0,children:x(GC,{})})}),x(Z,{path:`*`,element:x(X,{to:`/devices`,replace:!0})})]})]})})})}),x(hC,{}),x(Ss,{})]})})})})})})})})})}O(),window.__camstackUiLibrary=Wa,window.__camstackSdk=uo,window.__camstackTypes=Jn;var sO=Eo(document.getElementById(`root`));Bo(window.location.pathname,pt())?fD(sO):sO.render(x(T,{children:x(oO,{})}));export{oy as $,nm as $n,wf as $r,Lh as $t,fS as A,Ps as Ai,Cm as An,Lf as Ar,Vg as At,fb as B,um as Bn,zf as Br,dg as Bt,eC as C,ll as Ci,bm as Cn,Hf as Cr,T_ as Ct,hS as D,As as Di,Dm as Dn,Zf as Dr,i_ as Dt,SS as E,js as Ei,km as En,Yf as Er,a_ as Et,Gx as F,xm as Fn,Af as Fr,Qg as Ft,py as G,$p as Gn,Kf as Gr,Oh as Gt,Ay as H,hm as Hn,fp as Hr,cg as Ht,xx as I,Nm as In,jf as Ir,qg as It,uy as J,cm as Jn,Qf as Jr,jh as Jt,_y as K,sm as Kn,Mf as Kr,wh as Kt,cx as L,zm as Ln,up as Lr,Zg as Lt,uS as M,Es as Mi,jm as Mn,tp as Mr,Yg as Mt,aS as N,Ts as Ni,Om as Nn,ap as Nr,__ as Nt,gS as O,Ms as Oi,wm as On,np as Or,r_ as Ot,iS as P,ws as Pi,Am as Pn,Uf as Pr,n_ as Pt,ly as Q,im as Qn,Ef as Qr,Ph as Qt,sx as R,gm as Rn,If as Rr,b_ as Rt,uC as S,Y as Si,ym as Sn,qf as Sr,F_ as St,wS as T,Lu as Ti,Wm as Tn,Of as Tr,x_ as Tt,Ey as U,_m as Un,Wf as Ur,Kh as Ut,Ly as V,pm as Vn,ep as Vr,lg as Vt,by as W,mm as Wn,Jf as Wr,Ih as Wt,my as X,am as Xn,ip as Xr,Sh as Xt,hy as Y,tm as Yn,Xf as Yr,Ch as Yt,yy as Z,rm as Zn,Nf as Zr,Dh as Zt,xw as _,xd as _i,Zm as _n,xp as _r,tv as _t,eE as a,rf as ai,gh as an,Xp as ar,Nv as at,ZC as b,ku as bi,Ym as bn,$f as br,G_ as bt,nE as c,cf as ci,hh as cn,Vp as cr,Cv as ct,Ww as d,lf as di,dh as dn,Hp as dr,bv as dt,xf as ei,Bh as en,Jp as er,ny as et,Vw as f,of as fi,oh as fn,Up as fr,mv as ft,vw as g,gf as gi,$m as gn,Dp as gr,$_ as gt,yw as h,_f as hi,eh as hn,yp as hr,rv as ht,$T as i,mf as ii,vh as in,Gp as ir,Iv as it,dS as j,Cs as ji,Pm as jn,rp as jr,Rg as jt,vS as k,Ns as ki,Fm as kn,lp as kr,g_ as kt,rE as l,uf as li,ph as ln,Pp as lr,Sv as lt,Sw as m,pf as mi,Jm as mn,vp as mr,iv as mt,EE as n,sf as ni,Eh as nn,Qp as nr,Vv as nt,ZT as o,af as oi,_h as on,Zp as or,Ov as ot,Hw as p,nf as pi,qm as pn,wp as pr,av as pt,vy as q,om as qn,Pf as qr,Rh as qt,tE as r,tf as ri,Ah as rn,Yp as rr,Lv as rt,QT as s,df as si,yh as sn,Rp as sr,Mv as st,AE as t,ff as ti,Th as tn,zp as tr,Hv as tt,iE as u,hf as ui,fh as un,Mp as ur,xv as ut,mw as v,wd as vi,Km as vn,Cp as vr,W_ as vt,BS as w,pl as wi,Lm as wn,Gf as wr,E_ as wt,aC as x,X as xi,Xm as xn,dp as xr,U_ as xt,hw as y,_d as yi,th as yn,Sp as yr,K_ as yt,ax as z,lm as zn,Rf as zr,pg as zt};
|