@camstack/addon-admin-ui 1.2.50 → 1.2.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/AddLocationWizard-ByfVTf7z.js +1 -0
- package/dist/assets/{AddonCollectionPage-CT4Vuznz.js → AddonCollectionPage-BuFuYYvJ.js} +1 -1
- package/dist/assets/{Addons-B_VbpsZA.js → Addons-DDEVSb9E.js} +1 -1
- package/dist/assets/{AdminTabs-DDFIqZNV.js → AdminTabs-Bpp49XUt.js} +1 -1
- package/dist/assets/AiProfiles-DyI1sGHM.js +1 -0
- package/dist/assets/{BrokerForm-zPB5Fz9g.js → BrokerForm-CN34GcQh.js} +1 -1
- package/dist/assets/Build-6KbkAmwC.js +32 -0
- package/dist/assets/{Capabilities-C3BMCiwV.js → Capabilities-D-DpTlWs.js} +1 -1
- package/dist/assets/CapabilityBadges-CHhrKMvk.js +1 -0
- package/dist/assets/Cluster-CM4RcSfn.js +1 -0
- package/dist/assets/Data-BsrNNDe4.js +1 -0
- package/dist/assets/{DetectionIntelligence-BM6Ux7Vq.js → DetectionIntelligence-wwS6t-iu.js} +1 -1
- package/dist/assets/{DeviceAggregateSection-BA_SP-HR.js → DeviceAggregateSection-m7QBjvw1.js} +1 -1
- package/dist/assets/DeviceDetail-BRqNfgrV.js +2 -0
- package/dist/assets/{Devices-8u3JIqxr.js → Devices-C_Iy-1DY.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-aI1hmuAW.js → EmbedPlayerPage-BzJREYPg.js} +1 -1
- package/dist/assets/Events-CIAJeuGc.js +1 -0
- package/dist/assets/{FormBuilder-Uk2TiLIL.js → FormBuilder-8G0bykRV.js} +1 -1
- package/dist/assets/{Identity-9KqXr-j2.js → Identity-CKFcxYAD.js} +1 -1
- package/dist/assets/IntegrationDetail-CYO9evSX.js +1 -0
- package/dist/assets/Integrations-DIbr02Wd.js +1 -0
- package/dist/assets/{Integrations-B6hH0gGV.js → Integrations-DvDVnh_e.js} +1 -1
- package/dist/assets/{Logs-CVDkHZNL.js → Logs-DSbrNopM.js} +1 -1
- package/dist/assets/{MotionZonesSettings-CeR5VdHF.js → MotionZonesSettings-DhmylyWm.js} +1 -1
- package/dist/assets/{MyAccess-C1g595ov.js → MyAccess-2qf_vuZX.js} +1 -1
- package/dist/assets/{Network-Cq9iMt-S.js → Network-DM6W1cMH.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-BbU0zWTj.js → NodeAddonsSettingsPanel-OlYGh17A.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-zGiwPb9S.js → NodeInferenceDevices-D0dCWFuM.js} +1 -1
- package/dist/assets/Notifications-B57yS_N9.js +1 -0
- package/dist/assets/Pipeline-C36d_bUf.js +1 -0
- package/dist/assets/{Plates-pdxHQLhg.js → Plates-CaE-1mzS.js} +1 -1
- package/dist/assets/PrivacyMaskSettings-CKW0LV6c.js +1 -0
- package/dist/assets/{ProviderIcon-CSWSCcb3.js → ProviderIcon-CtnmYlEc.js} +1 -1
- package/dist/assets/Recordings-DN7GpdSr.js +1 -0
- package/dist/assets/{ScanNetworkModal-C9QX2cIu.js → ScanNetworkModal-D_uWkwpW.js} +1 -1
- package/dist/assets/{Settings-DCIeWgXU.js → Settings-BHNismMH.js} +1 -1
- package/dist/assets/{Showroom-C2_dUzIt.js → Showroom-DAfTzeRJ.js} +1 -1
- package/dist/assets/{Terminal-GcYPpGIe.js → Terminal-ChPkNmcT.js} +2 -2
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DSCIiy8m.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C4v0_fvJ.js} +1 -1
- package/dist/assets/bell-ring-B89FuVzx.js +1 -0
- package/dist/assets/{boxes-Doq7E83T.js → boxes-E67TckHL.js} +1 -1
- package/dist/assets/{build-cluster-graph-DR3K68id.js → build-cluster-graph-C9P8BH_Y.js} +1 -1
- package/dist/assets/circle-check-big-6KqLnh7I.js +1 -0
- package/dist/assets/{circle-x-F4_6Z6hp.js → circle-x-BOCM3Jay.js} +1 -1
- package/dist/assets/clock-BB5ZlM4P.js +1 -0
- package/dist/assets/{copy-D7L611bm.js → copy-BAh4BimG.js} +1 -1
- package/dist/assets/{debounced-invalidate-Cwz58epM.js → debounced-invalidate-B6n92LfS.js} +1 -1
- package/dist/assets/{dist-ByLBDbZ0.js → dist-DMs8CJMG.js} +1 -1
- package/dist/assets/dist-ujytOS_T.js +345 -0
- package/dist/assets/{download-DK6K1z5p.js → download-NchcTrNY.js} +1 -1
- package/dist/assets/{face-bbox-B9bqau8Q.js → face-bbox-CxWVEvLH.js} +1 -1
- package/dist/assets/{hard-drive-hP5NrPld.js → hard-drive-v3gsMgpj.js} +1 -1
- package/dist/assets/{hostInit-BEKkUU_i.js → hostInit-BsdExvxu.js} +1 -1
- package/dist/assets/{index-Dm9Uz1f0.js → index-DOGqQOnC.js} +3 -3
- package/dist/assets/index-DchMAgXl.css +2 -0
- package/dist/assets/{key-round-Cj7KTTaR.js → key-round-B8nOHuYS.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-ae1d8899.js → mf-entry-bootstrap-0-fb7d830c.js} +2 -2
- package/dist/assets/{pencil-DzxpzCXv.js → pencil-sz3vITXt.js} +1 -1
- package/dist/assets/play-BO_n_04H.js +1 -0
- package/dist/assets/{player-overlays-Cs56mPfn.js → player-overlays-35cjLMFQ.js} +1 -1
- package/dist/assets/plus-CzPndm5P.js +1 -0
- package/dist/assets/power-DFi-GnjG.js +1 -0
- package/dist/assets/{radio-BKHpiLrH.js → radio-DyOU1pqI.js} +1 -1
- package/dist/assets/{refresh-cw-BSZWNnN4.js → refresh-cw-yJ3BGqhW.js} +1 -1
- package/dist/assets/remoteEntry-DhlUKvH0.js +1 -0
- package/dist/assets/rotate-ccw-B2UqNaB5.js +1 -0
- package/dist/assets/rotate-cw-Ceq0Xutw.js +1 -0
- package/dist/assets/search-Djlmih4W.js +1 -0
- package/dist/assets/{send-BbwJgyZU.js → send-ibgpXPAd.js} +1 -1
- package/dist/assets/{server-6BSkkWM_.js → server-W3u0QEGh.js} +1 -1
- package/dist/assets/square-BhLZ-0MF.js +1 -0
- package/dist/assets/{square-check-big-CVctePO-.js → square-check-big-N3hx4ccu.js} +1 -1
- package/dist/assets/src-C9Wl4IAv.js +345 -0
- package/dist/assets/src-DfTnwu3m.js +67 -0
- package/dist/assets/{undo-2-QajNXpI1.js → undo-2-03JG1b2r.js} +1 -1
- package/dist/assets/{upload-COZK66d7.js → upload-PhcvMnIf.js} +1 -1
- package/dist/assets/{useEventInvalidation-BNRoP33J.js → useEventInvalidation-ChMOpmx7.js} +1 -1
- package/dist/assets/video-D3jIKSxB.js +1 -0
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CEAjda8_.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-2K3VQBSZ.js} +2 -2
- package/dist/assets/{wifi-BgmKj3zj.js → wifi-D-m2AtcE.js} +1 -1
- package/dist/assets/zap-FMbpMlZh.js +1 -0
- package/dist/index.html +6 -6
- package/dist/server/addon.js +561 -35
- package/package.json +1 -1
- package/dist/assets/AddLocationWizard-CooAni_i.js +0 -1
- package/dist/assets/AiProfiles-BzCtQi16.js +0 -1
- package/dist/assets/Build-C0IybqDl.js +0 -32
- package/dist/assets/CapabilityBadges-DKhByP_7.js +0 -1
- package/dist/assets/Cluster-BkqBoEsE.js +0 -1
- package/dist/assets/Data-aHHRJZhH.js +0 -1
- package/dist/assets/DeviceDetail-Bl4Y9PYy.js +0 -2
- package/dist/assets/Events-e_Q_LwJ5.js +0 -1
- package/dist/assets/IntegrationDetail-CeUR9Dyx.js +0 -1
- package/dist/assets/Integrations-BM-jkcfI.js +0 -1
- package/dist/assets/Notifications-D4RCvVQj.js +0 -1
- package/dist/assets/Pipeline-ClchQ6CM.js +0 -1
- package/dist/assets/PrivacyMaskSettings-9kxvi7tM.js +0 -1
- package/dist/assets/Recordings-CBMphQh7.js +0 -1
- package/dist/assets/circle-check-big-DCUpDJJ8.js +0 -1
- package/dist/assets/clock-C4ln4UIx.js +0 -1
- package/dist/assets/dist-C4ma4NyY.js +0 -345
- package/dist/assets/index-DfbxOmzG.css +0 -2
- package/dist/assets/play-CWNgmzrn.js +0 -1
- package/dist/assets/plus-B-ylzENt.js +0 -1
- package/dist/assets/power-DxUwR0ke.js +0 -1
- package/dist/assets/remoteEntry-O0N1CtRD.js +0 -1
- package/dist/assets/rotate-ccw-BfMMeeIh.js +0 -1
- package/dist/assets/rotate-cw-BbHvbnfD.js +0 -1
- package/dist/assets/search-DhjInNkL.js +0 -1
- package/dist/assets/square-KmrQB4nC.js +0 -1
- package/dist/assets/src-Bch8B6OR.js +0 -345
- package/dist/assets/src-V00nU2Tb.js +0 -67
- package/dist/assets/zap-BZasYUgo.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Ar as e,Cr as t,Dr as n,Er as r,Fr as i,Nr as a,Or as o,Pr as s,Sr as c,Tr as l,Xa as u,as as d,br as f,bt as p,is as m,jo as h,kr as g,rs as _,vo as v,wr as ee,xr as te,yr as ne,yt as y}from"./src-V00nU2Tb.js";import{I as b,Q as x,S,W as C,b as w,o as T,q as E,x as D,z as re}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{D as O,S as k}from"./src-Bch8B6OR.js";import{p as A}from"./player-overlays-Cs56mPfn.js";import{t as j}from"./boxes-Doq7E83T.js";import{t as M}from"./copy-D7L611bm.js";import{t as N}from"./play-CWNgmzrn.js";import{t as ie}from"./refresh-cw-BSZWNnN4.js";import{t as ae}from"./rotate-ccw-BfMMeeIh.js";import{t as P}from"./server-6BSkkWM_.js";import{t as F}from"./square-KmrQB4nC.js";import{t as oe}from"./wifi-BgmKj3zj.js";import{L as se,S as I,T as L,V as ce,W as R,b as le,i as ue,k as z,l as de,o as B,v as V,x as fe}from"./index-Dm9Uz1f0.js";import{t as pe}from"./AdminPage-Dq33XE9j.js";import{t as me}from"./AdminTabs-DDFIqZNV.js";import{t as H}from"./AddonCollectionPage-CT4Vuznz.js";import{t as U}from"./addon-display-names-DvSEQty-.js";var he=R(`log-in`,[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]),ge=R(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),W=R(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]);x();var G=5e3,_e={connected:!1,endpoint:null};function ve(){let e=T(),t=p({capName:`network-access`},{refetchInterval:G}),n=y(void 0,{refetchInterval:G}),r=C(()=>U(n.data??[]),[n.data]),a=C(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,r]),[o,c]=E(null),[l,u]=E({}),d=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),c(null),u(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},f=(e,t)=>{c(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);u(e=>({...e,[n]:r}))},m=s({onSuccess:d,onError:f}),h=i({onSuccess:d,onError:f});return D(H,{title:`Remote Access`,subtitle:`Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …). Settings, Logs and Events are docked under every provider.`,pageIcon:L,itemIcon:L,capability:`network-access`,installButtonLabel:`Add tunnel`,items:a,isLoading:t.isLoading,emptyTitle:`No remote-access providers installed`,emptyDescription:`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`,renderStatusBadges:e=>D(ye,{addonId:e.addonId}),itemError:e=>l[e.addonId]??null,renderPrimaryAction:e=>D(be,{addonId:e.addonId,busyId:o,onStart:e=>{c(e),m.mutate({addonId:e})},onStop:e=>{c(e),h.mutate({addonId:e})}})})}function K(e){let{data:t}=a({addonId:e},{refetchInterval:G,retry:!1}),n=t?O.safeParse(t):null;return n?.success?n.data:_e}function ye({addonId:e}){let t=K(e);return S(w,{children:[D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.connected?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.connected?`Connected`:`Disconnected`}),t.endpoint&&S(`a`,{href:t.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-[10px] text-emerald-700 dark:text-emerald-300 hover:underline flex items-center gap-1`,children:[D(z,{className:`h-3 w-3`}),t.endpoint.url]})]})}function be({addonId:e,busyId:t,onStart:n,onStop:r}){let i=K(e),a=t===e;return i.connected?S(d,{size:`sm`,variant:`secondary`,disabled:a,onClick:()=>r(e),children:[a?D(I,{className:`h-3 w-3 animate-spin`}):D(F,{className:`h-3 w-3`}),`Stop`]}):S(d,{size:`sm`,variant:`primary`,disabled:a,onClick:()=>n(e),children:[a?D(I,{className:`h-3 w-3 animate-spin`}):D(N,{className:`h-3 w-3`}),`Start`]})}x();var q=3e4;function xe(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function Se(){let e=p({capName:`turn-provider`},{refetchInterval:q}),t=y(void 0,{refetchInterval:q}),n=u(),r=n.data??[],i=C(()=>U(t.data??[]),[t.data]);return D(H,{title:`TURN Servers`,subtitle:`ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.`,pageIcon:V,itemIcon:V,capability:`turn-provider`,installButtonLabel:`Add provider`,items:C(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:i.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,i]),isLoading:e.isLoading,emptyTitle:`No TURN providers installed`,emptyDescription:`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`,renderExpandedPanel:e=>D(Ce,{addonId:e.addonId,enabled:e.isActive}),trailing:S(_,{children:[S(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[S(`div`,{children:[D(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),D(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),D(d,{size:`sm`,variant:`secondary`,onClick:()=>n.refetch(),disabled:n.isFetching,children:`Refresh`})]}),D(`div`,{className:`p-4`,children:r.length===0?D(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):D(`div`,{className:`flex flex-col gap-3`,children:r.map((e,t)=>{let n=Array.isArray(e.urls)?e.urls:[e.urls];return S(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&S(`div`,{className:`px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3`,children:[e.username&&S(`span`,{children:[D(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,D(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&S(`span`,{children:[D(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,D(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),D(`ul`,{className:`divide-y divide-border`,children:n.map(e=>D(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function Ce({addonId:e,enabled:t}){let n=u({addonId:e},{enabled:t,retry:!1}),r=C(()=>xe(n.data??[]),[n.data]);return!t||r.length===0?null:S(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[S(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,r.length,`)`]}),D(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>D(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}x();var we={lan:V,wifi:oe,docker:j,vpn:fe,loopback:P,other:P},Te={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Ee=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function De(e){let{interfaces:t,disabled:n,hideLoopback:r,ipv4Only:i,emptyMessage:a}=e,o=C(()=>t.filter(e=>!(r&&e.kind===`loopback`||i&&e.family!==`IPv4`)),[t,r,i]),s=C(()=>{let e=new Map;for(let t of o){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Ee.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[o]),c=t=>e.mode===`single`?e.value===t:e.value.includes(t),l=t=>{if(n||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let r=new Set(e.value);r.has(t.address)?r.delete(t.address):r.add(t.address),e.onChange([...r])};return o.length===0?D(`div`,{className:`text-xs text-foreground-subtle italic`,children:a??`No addresses available.`}):D(`div`,{className:`flex flex-col gap-3`,children:s.map(({kind:t,items:r})=>S(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[S(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[D(we[t]??P,{className:`h-3.5 w-3.5 text-foreground-subtle`}),D(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:Te[t]??t}),S(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),D(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=c(t.address),i=t.kind===`loopback`,a=!t.plausible&&!i;return S(`li`,{className:`flex items-center gap-3 px-3 py-2 ${i?`opacity-60 cursor-not-allowed`:n?`opacity-60`:a?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>l(t),children:[D(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${e.mode===`single`?`rounded-full`:`rounded`} border ${r?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:r&&D(se,{className:`h-3 w-3`})}),S(`div`,{className:`flex-1 min-w-0 ${a?`text-foreground-subtle`:``}`,children:[S(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[D(`span`,{className:`font-mono text-xs font-semibold ${a?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),D(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:t.family}),t.preferred&&D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),i&&D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),a&&S(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[D(B,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),S(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:[t.address,t.cidr&&t.cidr!==t.address?` (${t.cidr})`:``]})]})]},`${t.name}-${t.family}-${t.address}`)})})]},t))})}x();var J={"lan-ipv4":`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,"lan-ipv6":`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`,loopback:`bg-foreground-subtle/15 text-foreground-subtle`};function Oe(){let e=T(),n=A(),r=c(void 0,{refetchInterval:3e4}),i=ne(void 0),a=ee({onSuccess:()=>{e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),o=t({onSuccess:t=>{m(t.addresses),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),s=C(()=>r.data?.interfaces??[],[r.data]),u=f({port:typeof window<`u`?Number(window.location.port)||(window.location.protocol===`https:`?443:80):4e3,scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`},{refetchInterval:3e4}),[p,m]=E([]),[h,g]=E(!1);re(()=>{!h&&i.data&&(m(i.data.addresses),g(!0))},[i.data,h]);let v=i.data?.addresses??[],y=C(()=>{if(p.length!==v.length)return!0;let e=[...p].toSorted(),t=[...v].toSorted();return e.some((e,n)=>e!==t[n])},[p,v]),b=()=>{a.mutate({addresses:[...p]})},x=()=>{m(v)},w=()=>{m([])},O=()=>{r.refetch(),u.refetch(),i.refetch()},k=async()=>{try{let e=await n.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},j=te(),M=l({onSuccess:()=>void j.refetch()}),N=u.data?.endpoints??[],P=j.data?.baseUrl??null,F=j.data?.resolved??null;return S(pe,{children:[S(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[D(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Pick the local addresses SDK clients should race for the fastest path to this hub. Empty selection (auto) lets every non-loopback / non-link-local interface participate.`}),S(`div`,{className:`flex items-center gap-2 shrink-0`,children:[S(d,{size:`sm`,variant:`secondary`,onClick:O,disabled:r.isLoading,children:[D(ie,{className:`h-3 w-3 ${r.isLoading?`animate-spin`:``}`}),`Refresh`]}),D(d,{size:`sm`,variant:`secondary`,onClick:k,children:`Probe race`})]})]}),S(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[S(_,{children:[S(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[S(`div`,{children:[D(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),D(`div`,{className:`text-xs text-foreground-subtle`,children:p.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${p.length} pinned`})]}),S(`div`,{className:`flex items-center gap-1`,children:[S(d,{size:`sm`,variant:`secondary`,onClick:()=>o.mutate(void 0),disabled:o.isPending||a.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[D(de,{className:`h-3 w-3`}),o.isPending?`Detecting…`:`Best match`]}),S(d,{size:`sm`,variant:`secondary`,onClick:w,disabled:p.length===0||a.isPending,children:[D(ae,{className:`h-3 w-3`}),`Clear`]}),y&&D(d,{size:`sm`,variant:`secondary`,onClick:x,disabled:a.isPending,children:`Discard`}),S(d,{size:`sm`,variant:`primary`,onClick:b,disabled:!y||a.isPending,children:[D(ge,{className:`h-3 w-3`}),a.isPending?`Saving…`:`Save`]})]})]}),D(`div`,{className:`p-4`,children:D(De,{mode:`multiple`,interfaces:s,value:p,onChange:m,disabled:a.isPending,emptyMessage:r.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),S(_,{children:[S(`div`,{className:`px-4 py-3 border-b border-border`,children:[D(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints — priority order`}),D(`div`,{className:`text-xs text-foreground-subtle`,children:`Live preview of the ranked candidate list the SDK would race against. Updates with each Save.`}),S(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-2 text-xs`,children:[D(`span`,{className:`text-foreground-subtle`,children:`Notification links use:`}),D(`span`,{className:`font-mono text-foreground`,children:P??`${F??`nothing reachable`} (auto)`}),P!==null&&D(`button`,{type:`button`,disabled:M.isPending,onClick:()=>M.mutate({baseUrl:null}),className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:`reset to auto`})]}),P===null&&F===null&&D(`p`,{className:`mt-1 text-[11px] text-amber-600 dark:text-amber-400`,children:`No public address is reachable, so notification media ships as bytes only — a backend that can only take links (WhatsApp, gotify) receives none.`})]}),D(`div`,{className:`p-4`,children:N.length===0?D(`div`,{className:`text-xs text-foreground-subtle italic`,children:u.isLoading?`Loading…`:`No endpoints available.`}):D(`ul`,{className:`space-y-1 text-xs`,children:N.map(e=>S(`li`,{className:`flex items-center gap-2 flex-wrap ${e.plausible?``:`opacity-80`}`,children:[D(`span`,{className:`font-mono text-[10px] w-10 text-foreground-subtle`,children:String(e.priority).padStart(4,`0`)}),D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${J[e.kind]??J.loopback}`,children:e.kind}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&D(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-medium uppercase`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&S(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:e.plausibleReason||void 0,children:[D(B,{className:`h-2.5 w-2.5`}),`Unlikely usable`]}),D(`span`,{className:`font-mono break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),S(`span`,{className:`text-foreground-subtle`,children:[`— `,e.label]}),e.kind===`loopback`?null:P===e.baseUrl?S(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-primary/15 px-2 py-0.5 text-[10px] font-medium text-primary`,children:[D(ce,{className:`h-2.5 w-2.5`}),` notifications`]}):D(`button`,{type:`button`,disabled:M.isPending,onClick:()=>M.mutate({baseUrl:e.baseUrl}),className:`rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:`use for notifications`})]},`${e.priority}-${e.baseUrl}`))})})]})]})]})}x();var ke={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Y=5e3,Ae=3e4,X={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function je(){let e=p({capName:`mesh-network`},{refetchInterval:Y}),t=y(void 0,{refetchInterval:Y}),n=C(()=>U(t.data??[]),[t.data]);return D(H,{title:`Mesh Networks`,subtitle:`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`,pageIcon:j,itemIcon:V,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:C(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No mesh-network providers installed`,emptyDescription:`Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.`,renderStatusBadges:e=>D(Me,{addonId:e.addonId}),renderPrimaryAction:e=>D(Ne,{addonId:e.addonId}),renderExpandedPanel:e=>D(Pe,{addonId:e.addonId})})}function Z(e){let{data:t,isLoading:n}=r({addonId:e},{refetchInterval:Y,retry:!1}),i=t?k.safeParse(t):null;return{status:i?.success?i.data:X,isLoading:n}}function Me({addonId:e}){let{status:t}=Z(e);return S(w,{children:[D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.joined?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.joined?`Joined`:`Not joined`}),t.joined&&S(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:[t.peerCount,` peer`,t.peerCount===1?``:`s`]})]})}function Ne({addonId:t}){let r=T(),[i,a]=E(!1),[o,s]=E(null),c=A(),{status:l}=Z(t),u=b(()=>{r.invalidateQueries({queryKey:[[`meshNetwork`]]})},[r]),f=e(),p=n({onSuccess:u}),m=g({onSuccess:u}),h=b(async()=>{a(!0);let e={cancelled:!1};s(e);try{let n=await f.mutateAsync({addonId:t});if(e.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!e.cancelled&&(await ze(2e3),!e.cancelled);){let e=await c.trpcClient.meshNetwork.getStatus.query({addonId:t}).catch(()=>null),n=e?k.safeParse(e):null;if(n?.success&&n.data.joined){u();break}if(Date.now()-r>6e5)break}}finally{a(!1),s(null)}},[t,u,f,c]),_=b(()=>{o&&(o.cancelled=!0),a(!1),s(null)},[o]);return D(w,{children:l.joined?S(w,{children:[S(d,{size:`sm`,variant:`secondary`,disabled:p.isPending,onClick:()=>p.mutate({addonId:t}),children:[p.isPending?D(I,{className:`h-3 w-3 animate-spin`}):D(le,{className:`h-3 w-3`}),`Disconnect`]}),S(d,{size:`sm`,variant:`ghost`,disabled:m.isPending,onClick:()=>m.mutate({addonId:t}),children:[m.isPending?D(I,{className:`h-3 w-3 animate-spin`}):D(W,{className:`h-3 w-3`}),`Log out`]})]}):i?S(d,{size:`sm`,variant:`ghost`,onClick:_,children:[D(ue,{className:`h-3 w-3 mr-1`}),` Cancel`]}):S(w,{children:[S(d,{size:`sm`,variant:`primary`,onClick:()=>void h(),children:[D(he,{className:`h-3 w-3`}),`Connect`]}),S(d,{size:`sm`,variant:`ghost`,disabled:m.isPending,onClick:()=>m.mutate({addonId:t}),children:[m.isPending?D(I,{className:`h-3 w-3 animate-spin`}):D(W,{className:`h-3 w-3`}),`Log out`]})]})})}function Pe({addonId:e}){let{status:t}=Z(e),n=o({addonId:e},{refetchInterval:Ae,retry:!1});return S(`div`,{className:`rounded-lg border border-border bg-surface`,children:[S(`div`,{className:`p-4 space-y-4`,children:[t.error&&D(v,{message:t.error}),D(Fe,{status:t}),t.endpoints.length>0&&S(`div`,{className:`space-y-1.5`,children:[D(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>S(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[S(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${ke[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?D(L,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),S(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[D(z,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),D(`div`,{className:`border-t border-border`,children:D(Le,{peers:n.data?.peers??[],loading:n.isLoading})})]})}function Fe({status:e}){return D(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5`,children:[{label:`Tenant`,value:e.tenantName||`—`},{label:`User`,value:e.userLogin??`—`},{label:`Control plane`,value:e.controlPlaneUrl||`—`},{label:`Mesh IP`,value:e.meshIp||`—`,mono:!0},{label:`MagicDNS`,value:e.magicDnsHostname||`—`,mono:!0},{label:`DNS suffix`,value:e.magicDnsSuffix||`—`,mono:!0},{label:`Peers`,value:String(e.peerCount)},{label:`Key expiry`,value:e.keyExpiry?Ie(e.keyExpiry):`—`}].map(e=>S(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[D(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),D(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Ie(e){let t=e-Date.now();if(t<0)return`Expired ${$(e)}`;let n=Math.floor(t/864e5);if(n>60)return new Date(e).toLocaleDateString();if(n>1)return`in ${n} days`;let r=Math.floor(t/36e5);return r>1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))} min`}function Le({peers:e,loading:t}){let n=C(()=>e.map(e=>({...e,_id:e.id})),[e]),r=b(e=>{e&&navigator.clipboard?.writeText(e)},[]),i=C(()=>[{key:`hostname`,header:`Hostname`,render:e=>S(`div`,{className:`flex flex-col`,children:[S(`div`,{className:`flex items-center gap-1.5`,children:[D(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&D(m,{variant:`info`,children:`self`}),e.exitNodeOption&&D(m,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&D(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?S(`div`,{className:`flex items-center gap-1`,children:[D(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),D(`button`,{onClick:()=>r(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:D(M,{className:`h-3 w-3 text-foreground-subtle`})})]}):D(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?S(`div`,{className:`flex items-center gap-1`,children:[D(`span`,{className:`font-mono text-xs`,children:t}),D(`button`,{onClick:()=>r(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:D(M,{className:`h-3 w-3 text-foreground-subtle`})})]}):D(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>S(`div`,{className:`flex items-center gap-1.5`,children:[D(m,{variant:Re(e.connection),children:e.connection}),e.relay&&D(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?D(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):D(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>S(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Q(e.txBytes),` · ↓ `,Q(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>D(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?$(e.lastSeenMs):`—`})}],[r]);return t&&e.length===0?S(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[D(I,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):e.length===0?D(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):D(`div`,{className:`p-4`,children:D(h,{columns:i,rows:n,rowKey:e=>e._id,minWidthPx:820})})}function Re(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function Q(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${(e/1024/1024/1024).toFixed(2)}GB`}function $(e){let t=Date.now()-e;return t<6e4?`just now`:t<36e5?`${Math.round(t/6e4)}m ago`:t<864e5?`${Math.round(t/36e5)}h ago`:`${Math.round(t/864e5)}d ago`}function ze(e){return new Promise(t=>setTimeout(t,e))}function Be(){return D(`div`,{className:`flex flex-col p-4`,children:D(me,{tabs:[{id:`addresses`,label:`Network Addresses`,icon:P,content:D(Oe,{})},{id:`remote-access`,label:`Remote Access`,icon:L,content:D(ve,{})},{id:`mesh`,label:`Mesh Networks`,icon:j,content:D(je,{})},{id:`turn`,label:`TURN Servers`,icon:V,content:D(Se,{})}]})})}export{Be as NetworkPage};
|
|
1
|
+
import{Ar as e,Cr as t,Dr as n,Er as r,Fr as i,No as a,Nr as o,Or as s,Pr as c,Qa as l,Sr as u,Tr as d,bo as f,br as p,bt as m,cs as h,kr as g,ls as _,us as v,wr as ee,xr as te,yr as ne,yt as y}from"./src-DfTnwu3m.js";import{I as b,Q as x,S,W as C,b as w,o as T,q as E,x as D,z as re}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{E as O,S as k}from"./src-C9Wl4IAv.js";import{p as A}from"./player-overlays-35cjLMFQ.js";import{t as j}from"./boxes-E67TckHL.js";import{t as M}from"./copy-BAh4BimG.js";import{t as N}from"./play-BO_n_04H.js";import{t as ie}from"./refresh-cw-yJ3BGqhW.js";import{t as ae}from"./rotate-ccw-B2UqNaB5.js";import{t as P}from"./server-W3u0QEGh.js";import{t as F}from"./square-BhLZ-0MF.js";import{t as oe}from"./wifi-D-m2AtcE.js";import{L as se,S as I,T as L,V as ce,W as R,b as le,i as ue,k as z,l as de,o as B,v as V,x as fe}from"./index-DOGqQOnC.js";import{t as pe}from"./AdminPage-Dq33XE9j.js";import{t as me}from"./AdminTabs-Bpp49XUt.js";import{t as H}from"./AddonCollectionPage-BuFuYYvJ.js";import{t as U}from"./addon-display-names-DvSEQty-.js";var he=R(`log-in`,[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]),ge=R(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),W=R(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]);x();var G=5e3,_e={connected:!1,endpoint:null};function ve(){let e=T(),t=m({capName:`network-access`},{refetchInterval:G}),n=y(void 0,{refetchInterval:G}),r=C(()=>U(n.data??[]),[n.data]),a=C(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,r]),[o,s]=E(null),[l,u]=E({}),d=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),s(null),u(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},f=(e,t)=>{s(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);u(e=>({...e,[n]:r}))},p=c({onSuccess:d,onError:f}),h=i({onSuccess:d,onError:f});return D(H,{title:`Remote Access`,subtitle:`Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …). Settings, Logs and Events are docked under every provider.`,pageIcon:L,itemIcon:L,capability:`network-access`,installButtonLabel:`Add tunnel`,items:a,isLoading:t.isLoading,emptyTitle:`No remote-access providers installed`,emptyDescription:`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`,renderStatusBadges:e=>D(ye,{addonId:e.addonId}),itemError:e=>l[e.addonId]??null,renderPrimaryAction:e=>D(be,{addonId:e.addonId,busyId:o,onStart:e=>{s(e),p.mutate({addonId:e})},onStop:e=>{s(e),h.mutate({addonId:e})}})})}function K(e){let{data:t}=o({addonId:e},{refetchInterval:G,retry:!1}),n=t?O.safeParse(t):null;return n?.success?n.data:_e}function ye({addonId:e}){let t=K(e);return S(w,{children:[D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.connected?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.connected?`Connected`:`Disconnected`}),t.endpoint&&S(`a`,{href:t.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-[10px] text-emerald-700 dark:text-emerald-300 hover:underline flex items-center gap-1`,children:[D(z,{className:`h-3 w-3`}),t.endpoint.url]})]})}function be({addonId:e,busyId:t,onStart:n,onStop:r}){let i=K(e),a=t===e;return i.connected?S(v,{size:`sm`,variant:`secondary`,disabled:a,onClick:()=>r(e),children:[a?D(I,{className:`h-3 w-3 animate-spin`}):D(F,{className:`h-3 w-3`}),`Stop`]}):S(v,{size:`sm`,variant:`primary`,disabled:a,onClick:()=>n(e),children:[a?D(I,{className:`h-3 w-3 animate-spin`}):D(N,{className:`h-3 w-3`}),`Start`]})}x();var q=3e4;function xe(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function Se(){let e=m({capName:`turn-provider`},{refetchInterval:q}),t=y(void 0,{refetchInterval:q}),n=l(),r=n.data??[],i=C(()=>U(t.data??[]),[t.data]);return D(H,{title:`TURN Servers`,subtitle:`ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.`,pageIcon:V,itemIcon:V,capability:`turn-provider`,installButtonLabel:`Add provider`,items:C(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:i.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,i]),isLoading:e.isLoading,emptyTitle:`No TURN providers installed`,emptyDescription:`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`,renderExpandedPanel:e=>D(Ce,{addonId:e.addonId,enabled:e.isActive}),trailing:S(h,{children:[S(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[S(`div`,{children:[D(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),D(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),D(v,{size:`sm`,variant:`secondary`,onClick:()=>n.refetch(),disabled:n.isFetching,children:`Refresh`})]}),D(`div`,{className:`p-4`,children:r.length===0?D(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):D(`div`,{className:`flex flex-col gap-3`,children:r.map((e,t)=>{let n=Array.isArray(e.urls)?e.urls:[e.urls];return S(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&S(`div`,{className:`px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3`,children:[e.username&&S(`span`,{children:[D(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,D(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&S(`span`,{children:[D(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,D(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),D(`ul`,{className:`divide-y divide-border`,children:n.map(e=>D(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function Ce({addonId:e,enabled:t}){let n=l({addonId:e},{enabled:t,retry:!1}),r=C(()=>xe(n.data??[]),[n.data]);return!t||r.length===0?null:S(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[S(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,r.length,`)`]}),D(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>D(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}x();var we={lan:V,wifi:oe,docker:j,vpn:fe,loopback:P,other:P},Te={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Ee=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function De(e){let{interfaces:t,disabled:n,hideLoopback:r,ipv4Only:i,emptyMessage:a}=e,o=C(()=>t.filter(e=>!(r&&e.kind===`loopback`||i&&e.family!==`IPv4`)),[t,r,i]),s=C(()=>{let e=new Map;for(let t of o){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Ee.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[o]),c=t=>e.mode===`single`?e.value===t:e.value.includes(t),l=t=>{if(n||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let r=new Set(e.value);r.has(t.address)?r.delete(t.address):r.add(t.address),e.onChange([...r])};return o.length===0?D(`div`,{className:`text-xs text-foreground-subtle italic`,children:a??`No addresses available.`}):D(`div`,{className:`flex flex-col gap-3`,children:s.map(({kind:t,items:r})=>S(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[S(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[D(we[t]??P,{className:`h-3.5 w-3.5 text-foreground-subtle`}),D(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:Te[t]??t}),S(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),D(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=c(t.address),i=t.kind===`loopback`,a=!t.plausible&&!i;return S(`li`,{className:`flex items-center gap-3 px-3 py-2 ${i?`opacity-60 cursor-not-allowed`:n?`opacity-60`:a?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>l(t),children:[D(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${e.mode===`single`?`rounded-full`:`rounded`} border ${r?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:r&&D(se,{className:`h-3 w-3`})}),S(`div`,{className:`flex-1 min-w-0 ${a?`text-foreground-subtle`:``}`,children:[S(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[D(`span`,{className:`font-mono text-xs font-semibold ${a?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),D(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:t.family}),t.preferred&&D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),i&&D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),a&&S(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[D(B,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),S(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:[t.address,t.cidr&&t.cidr!==t.address?` (${t.cidr})`:``]})]})]},`${t.name}-${t.family}-${t.address}`)})})]},t))})}x();var J={"lan-ipv4":`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,"lan-ipv6":`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`,loopback:`bg-foreground-subtle/15 text-foreground-subtle`};function Oe(){let e=T(),n=A(),r=u(void 0,{refetchInterval:3e4}),i=ne(void 0),a=ee({onSuccess:()=>{e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),o=t({onSuccess:t=>{f(t.addresses),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),s=C(()=>r.data?.interfaces??[],[r.data]),c=p({port:typeof window<`u`?Number(window.location.port)||(window.location.protocol===`https:`?443:80):4e3,scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`},{refetchInterval:3e4}),[l,f]=E([]),[m,g]=E(!1);re(()=>{!m&&i.data&&(f(i.data.addresses),g(!0))},[i.data,m]);let _=i.data?.addresses??[],y=C(()=>{if(l.length!==_.length)return!0;let e=[...l].toSorted(),t=[..._].toSorted();return e.some((e,n)=>e!==t[n])},[l,_]),b=()=>{a.mutate({addresses:[...l]})},x=()=>{f(_)},w=()=>{f([])},O=()=>{r.refetch(),c.refetch(),i.refetch()},k=async()=>{try{let e=await n.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},j=te(),M=d({onSuccess:()=>void j.refetch()}),N=c.data?.endpoints??[],P=j.data?.baseUrl??null,F=j.data?.resolved??null;return S(pe,{children:[S(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[D(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Pick the local addresses SDK clients should race for the fastest path to this hub. Empty selection (auto) lets every non-loopback / non-link-local interface participate.`}),S(`div`,{className:`flex items-center gap-2 shrink-0`,children:[S(v,{size:`sm`,variant:`secondary`,onClick:O,disabled:r.isLoading,children:[D(ie,{className:`h-3 w-3 ${r.isLoading?`animate-spin`:``}`}),`Refresh`]}),D(v,{size:`sm`,variant:`secondary`,onClick:k,children:`Probe race`})]})]}),S(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[S(h,{children:[S(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[S(`div`,{children:[D(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),D(`div`,{className:`text-xs text-foreground-subtle`,children:l.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${l.length} pinned`})]}),S(`div`,{className:`flex items-center gap-1`,children:[S(v,{size:`sm`,variant:`secondary`,onClick:()=>o.mutate(void 0),disabled:o.isPending||a.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[D(de,{className:`h-3 w-3`}),o.isPending?`Detecting…`:`Best match`]}),S(v,{size:`sm`,variant:`secondary`,onClick:w,disabled:l.length===0||a.isPending,children:[D(ae,{className:`h-3 w-3`}),`Clear`]}),y&&D(v,{size:`sm`,variant:`secondary`,onClick:x,disabled:a.isPending,children:`Discard`}),S(v,{size:`sm`,variant:`primary`,onClick:b,disabled:!y||a.isPending,children:[D(ge,{className:`h-3 w-3`}),a.isPending?`Saving…`:`Save`]})]})]}),D(`div`,{className:`p-4`,children:D(De,{mode:`multiple`,interfaces:s,value:l,onChange:f,disabled:a.isPending,emptyMessage:r.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),S(h,{children:[S(`div`,{className:`px-4 py-3 border-b border-border`,children:[D(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints — priority order`}),D(`div`,{className:`text-xs text-foreground-subtle`,children:`Live preview of the ranked candidate list the SDK would race against. Updates with each Save.`}),S(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-2 text-xs`,children:[D(`span`,{className:`text-foreground-subtle`,children:`Notification links use:`}),D(`span`,{className:`font-mono text-foreground`,children:P??`${F??`nothing reachable`} (auto)`}),P!==null&&D(`button`,{type:`button`,disabled:M.isPending,onClick:()=>M.mutate({baseUrl:null}),className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:`reset to auto`})]}),P===null&&F===null&&D(`p`,{className:`mt-1 text-[11px] text-amber-600 dark:text-amber-400`,children:`No public address is reachable, so notification media ships as bytes only — a backend that can only take links (WhatsApp, gotify) receives none.`})]}),D(`div`,{className:`p-4`,children:N.length===0?D(`div`,{className:`text-xs text-foreground-subtle italic`,children:c.isLoading?`Loading…`:`No endpoints available.`}):D(`ul`,{className:`space-y-1 text-xs`,children:N.map(e=>S(`li`,{className:`flex items-center gap-2 flex-wrap ${e.plausible?``:`opacity-80`}`,children:[D(`span`,{className:`font-mono text-[10px] w-10 text-foreground-subtle`,children:String(e.priority).padStart(4,`0`)}),D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${J[e.kind]??J.loopback}`,children:e.kind}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&D(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-medium uppercase`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&S(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:e.plausibleReason||void 0,children:[D(B,{className:`h-2.5 w-2.5`}),`Unlikely usable`]}),D(`span`,{className:`font-mono break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),S(`span`,{className:`text-foreground-subtle`,children:[`— `,e.label]}),e.kind===`loopback`?null:P===e.baseUrl?S(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-primary/15 px-2 py-0.5 text-[10px] font-medium text-primary`,children:[D(ce,{className:`h-2.5 w-2.5`}),` notifications`]}):D(`button`,{type:`button`,disabled:M.isPending,onClick:()=>M.mutate({baseUrl:e.baseUrl}),className:`rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:`use for notifications`})]},`${e.priority}-${e.baseUrl}`))})})]})]})]})}x();var ke={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Y=5e3,Ae=3e4,X={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function je(){let e=m({capName:`mesh-network`},{refetchInterval:Y}),t=y(void 0,{refetchInterval:Y}),n=C(()=>U(t.data??[]),[t.data]);return D(H,{title:`Mesh Networks`,subtitle:`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`,pageIcon:j,itemIcon:V,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:C(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No mesh-network providers installed`,emptyDescription:`Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.`,renderStatusBadges:e=>D(Me,{addonId:e.addonId}),renderPrimaryAction:e=>D(Ne,{addonId:e.addonId}),renderExpandedPanel:e=>D(Pe,{addonId:e.addonId})})}function Z(e){let{data:t,isLoading:n}=r({addonId:e},{refetchInterval:Y,retry:!1}),i=t?k.safeParse(t):null;return{status:i?.success?i.data:X,isLoading:n}}function Me({addonId:e}){let{status:t}=Z(e);return S(w,{children:[D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.joined?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.joined?`Joined`:`Not joined`}),t.joined&&S(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:[t.peerCount,` peer`,t.peerCount===1?``:`s`]})]})}function Ne({addonId:t}){let r=T(),[i,a]=E(!1),[o,s]=E(null),c=A(),{status:l}=Z(t),u=b(()=>{r.invalidateQueries({queryKey:[[`meshNetwork`]]})},[r]),d=e(),f=n({onSuccess:u}),p=g({onSuccess:u}),m=b(async()=>{a(!0);let e={cancelled:!1};s(e);try{let n=await d.mutateAsync({addonId:t});if(e.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!e.cancelled&&(await ze(2e3),!e.cancelled);){let e=await c.trpcClient.meshNetwork.getStatus.query({addonId:t}).catch(()=>null),n=e?k.safeParse(e):null;if(n?.success&&n.data.joined){u();break}if(Date.now()-r>6e5)break}}finally{a(!1),s(null)}},[t,u,d,c]),h=b(()=>{o&&(o.cancelled=!0),a(!1),s(null)},[o]);return D(w,{children:l.joined?S(w,{children:[S(v,{size:`sm`,variant:`secondary`,disabled:f.isPending,onClick:()=>f.mutate({addonId:t}),children:[f.isPending?D(I,{className:`h-3 w-3 animate-spin`}):D(le,{className:`h-3 w-3`}),`Disconnect`]}),S(v,{size:`sm`,variant:`ghost`,disabled:p.isPending,onClick:()=>p.mutate({addonId:t}),children:[p.isPending?D(I,{className:`h-3 w-3 animate-spin`}):D(W,{className:`h-3 w-3`}),`Log out`]})]}):i?S(v,{size:`sm`,variant:`ghost`,onClick:h,children:[D(ue,{className:`h-3 w-3 mr-1`}),` Cancel`]}):S(w,{children:[S(v,{size:`sm`,variant:`primary`,onClick:()=>void m(),children:[D(he,{className:`h-3 w-3`}),`Connect`]}),S(v,{size:`sm`,variant:`ghost`,disabled:p.isPending,onClick:()=>p.mutate({addonId:t}),children:[p.isPending?D(I,{className:`h-3 w-3 animate-spin`}):D(W,{className:`h-3 w-3`}),`Log out`]})]})})}function Pe({addonId:e}){let{status:t}=Z(e),n=s({addonId:e},{refetchInterval:Ae,retry:!1});return S(`div`,{className:`rounded-lg border border-border bg-surface`,children:[S(`div`,{className:`p-4 space-y-4`,children:[t.error&&D(f,{message:t.error}),D(Fe,{status:t}),t.endpoints.length>0&&S(`div`,{className:`space-y-1.5`,children:[D(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>S(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[S(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${ke[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?D(L,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),S(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[D(z,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),D(`div`,{className:`border-t border-border`,children:D(Le,{peers:n.data?.peers??[],loading:n.isLoading})})]})}function Fe({status:e}){return D(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5`,children:[{label:`Tenant`,value:e.tenantName||`—`},{label:`User`,value:e.userLogin??`—`},{label:`Control plane`,value:e.controlPlaneUrl||`—`},{label:`Mesh IP`,value:e.meshIp||`—`,mono:!0},{label:`MagicDNS`,value:e.magicDnsHostname||`—`,mono:!0},{label:`DNS suffix`,value:e.magicDnsSuffix||`—`,mono:!0},{label:`Peers`,value:String(e.peerCount)},{label:`Key expiry`,value:e.keyExpiry?Ie(e.keyExpiry):`—`}].map(e=>S(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[D(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),D(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Ie(e){let t=e-Date.now();if(t<0)return`Expired ${$(e)}`;let n=Math.floor(t/864e5);if(n>60)return new Date(e).toLocaleDateString();if(n>1)return`in ${n} days`;let r=Math.floor(t/36e5);return r>1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))} min`}function Le({peers:e,loading:t}){let n=C(()=>e.map(e=>({...e,_id:e.id})),[e]),r=b(e=>{e&&navigator.clipboard?.writeText(e)},[]),i=C(()=>[{key:`hostname`,header:`Hostname`,render:e=>S(`div`,{className:`flex flex-col`,children:[S(`div`,{className:`flex items-center gap-1.5`,children:[D(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&D(_,{variant:`info`,children:`self`}),e.exitNodeOption&&D(_,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&D(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?S(`div`,{className:`flex items-center gap-1`,children:[D(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),D(`button`,{onClick:()=>r(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:D(M,{className:`h-3 w-3 text-foreground-subtle`})})]}):D(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?S(`div`,{className:`flex items-center gap-1`,children:[D(`span`,{className:`font-mono text-xs`,children:t}),D(`button`,{onClick:()=>r(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:D(M,{className:`h-3 w-3 text-foreground-subtle`})})]}):D(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>S(`div`,{className:`flex items-center gap-1.5`,children:[D(_,{variant:Re(e.connection),children:e.connection}),e.relay&&D(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?D(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):D(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>S(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Q(e.txBytes),` · ↓ `,Q(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>D(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?$(e.lastSeenMs):`—`})}],[r]);return t&&e.length===0?S(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[D(I,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):e.length===0?D(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):D(`div`,{className:`p-4`,children:D(a,{columns:i,rows:n,rowKey:e=>e._id,minWidthPx:820})})}function Re(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function Q(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${(e/1024/1024/1024).toFixed(2)}GB`}function $(e){let t=Date.now()-e;return t<6e4?`just now`:t<36e5?`${Math.round(t/6e4)}m ago`:t<864e5?`${Math.round(t/36e5)}h ago`:`${Math.round(t/864e5)}d ago`}function ze(e){return new Promise(t=>setTimeout(t,e))}function Be(){return D(`div`,{className:`flex flex-col p-4`,children:D(me,{tabs:[{id:`addresses`,label:`Network Addresses`,icon:P,content:D(Oe,{})},{id:`remote-access`,label:`Remote Access`,icon:L,content:D(ve,{})},{id:`mesh`,label:`Mesh Networks`,icon:j,content:D(je,{})},{id:`turn`,label:`TURN Servers`,icon:V,content:D(Se,{})}]})})}export{Be as NetworkPage};
|
package/dist/assets/{NodeAddonsSettingsPanel-BbU0zWTj.js → NodeAddonsSettingsPanel-OlYGh17A.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Rt as e,dt as t,on as n,ut as r,yt as i}from"./src-V00nU2Tb.js";import{H as a,I as o,K as s,Q as c,S as l,W as u,i as d,k as f,o as p,p as m,q as h,t as g,x as _,z as v}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{Q as y}from"./src-Bch8B6OR.js";import{p as ee}from"./player-overlays-Cs56mPfn.js";import{t as b}from"./FormBuilder-Uk2TiLIL.js";import{n as te,r as x,t as ne}from"./SchemaTabBar-BrF8ZUiR.js";import{t as re}from"./StableTabPanel-p16epZGa.js";c();var S=f(function({addonId:e,schema:t,serverValues:n,onImmediateSave:r,onStateChange:i,onAction:c,disabled:l},d){let f=x({schema:t,serverValues:n,onImmediateSave:o(t=>r(e,t),[e,r]),onDeferredSave:o(()=>{},[])});a(d,()=>({flush:()=>{let e={};for(let t of f.pendingKeys)e[t]=f.values[t];return f.handleDiscard(f.pendingKeys),e},discard:()=>f.resetAll()}),[f]);let p=f.pendingKeys,m=p.join(`|`),h=u(()=>p.map(e=>`${e}=${JSON.stringify(f.values[e])}`).join(`,`),[p,f.values]),g=s(i);v(()=>{g.current=i},[i]),v(()=>{let t={};for(let e of p)t[e]=f.values[e];g.current({addonId:e,pendingKeys:p,pendingValues:t})},[e,m,h]);let y=u(()=>{if(c)return(t,n,r)=>c(e,t,n,r)},[e,c]);return _(b,{schema:t,values:f.values,onChange:f.handleChange,disabled:l,onAction:y})});c();function C(e,t){if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`){let n=e.fields.map(e=>C(e,t));return{...e,fields:n}}let n=e;t[e.key]=n.value;let{value:r,...i}=n;return i}function w(e,t){return{...e,fields:e.fields.map(e=>C(e,t))}}function ie(e){let t={};return{schema:{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>w(e,t))},values:t}}function T({nodeId:a,addonIds:c,level:f,deviceId:v,capability:b,sectionIds:x,sectionTab:S,extraTabs:C,schemaTabExtras:w,title:T,description:E,selfTabbed:oe}){let D=p(),O=ee().trpcClient,k=t(),A=r(),j=n(),M=e(),N=oe===!0||!!(C&&C.length>0),[P,se]=h(null);if(f===`device`&&!v)throw Error(`NodeAddonsSettingsPanel: deviceId is required when level === "device"`);let F=a??`hub`,I=d({queries:c.map(e=>({queryKey:[[`addonSettings`,f===`global`?`getGlobalSettings`:`getDeviceSettings`],{addonId:e,nodeId:F,deviceId:v??null,cap:b??null}],queryFn:async()=>f===`global`?{addonId:e,result:await O.addonSettings.getGlobalSettings.query({addonId:e,nodeId:F,...b?{cap:b}:{}})}:{addonId:e,result:await O.addonSettings.getDeviceSettings.query({addonId:e,deviceId:v,nodeId:F})},placeholderData:m}))}),L=I.some(e=>e.isLoading),R=I.map(e=>{if(!e.data)return`-`;if(e.data.result===null)return`${e.data.addonId}:n`;let t=[];for(let n of e.data.result.sections){t.push(`s:${n.id}:${n.tab??`general`}`);for(let e of n.fields){if(!(`key`in e))continue;let n=`options`in e&&Array.isArray(e.options)?e.options.map(e=>e.value).join(`,`):``,r=e.value,i=r===void 0?``:typeof r==`string`?r:JSON.stringify(r);t.push(`f:${e.key}:${n}:${i}`)}}return`${e.data.addonId}:${t.join(`|`)}`}).join(`||`),z=u(()=>{let e=new Set;for(let t of I){let n=t.data?.result?.sections;if(n)for(let t of n)e.add(t.tab??`general`)}return[...e]},[R+`::`+I.map(e=>(e.data?.result?.sections??[]).map(e=>e.tab??`general`).join(`,`)).join(`::`)]),B=u(()=>new Map((C??[]).map(e=>[e.id,e])),[C]),V=u(()=>{if(!N)return[];let e=[...new Set([...z,...(C??[]).map(e=>e.id),...(w??[]).map(e=>e.tabId)])],t=e=>{let t=B.get(e);if(t?.order!==void 0)return t.order;let n=y[e];return n?n.order:50};return e.toSorted((e,n)=>{let r=t(e),i=t(n);return r===i?e.localeCompare(n):r-i})},[N,z,C,B,w]),ce=u(()=>{let e=new Map,t=e=>y[e]?.label??e.charAt(0).toUpperCase()+e.slice(1);for(let n of z)e.set(n,t(n));for(let n of w??[])e.has(n.tabId)||e.set(n.tabId,t(n.tabId));for(let t of C??[])e.set(t.id,t.label);return e},[z,C,w]),H=N?P&&V.includes(P)?P:V[0]??null:null,U=H!==null&&B.has(H),W=N?H&&!U?H:void 0:S,{data:G}=i(void 0),le=u(()=>{let e=new Map;for(let t of G??[]){let n=t.manifest?.id;if(!n)continue;let r=t.manifest?.name??t.manifest?.packageDisplayName??n;e.set(n,r)}return e},[G]),K=s(new Map),q=u(()=>{let e=x?new Set(x):null,t=[];for(let n of I){if(!n.data)continue;let r=n.data.result??K.current.get(n.data.addonId)??null;if(n.data.result!==null&&K.current.set(n.data.addonId,n.data.result),r===null)continue;let{schema:i,values:a}=ie(r),o=i.sections.filter(t=>e?e.has(t.id):!0);if(o.length===0)continue;let s={...r,sections:r.sections.filter(t=>e?e.has(t.id):!0)},c={...i,sections:o};t.push({addonId:n.data.addonId,schemaWithValues:s,schema:c,serverValues:a})}return t},[R,x]),[J,ue]=h(new Map),de=o(e=>{ue(t=>{let n=new Map(t);return n.set(e.addonId,e),n})},[]),Y=s(new Map),fe=o(e=>t=>{t?Y.current.set(e,t):Y.current.delete(e)},[]),X=o(async(e,t)=>{f===`global`?await k.mutateAsync({addonId:e,nodeId:F,patch:t}):await A.mutateAsync({addonId:e,deviceId:v,nodeId:F,patch:t}),D.invalidateQueries({queryKey:[[`addonSettings`]]})},[k,A,F,f,v,D]),pe=o(async(e,t,n,r)=>{let i=F;try{switch(t){case`reprobe-hwaccel`:await j.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-audio-engine`:await M.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;default:{let n=await O.addons.custom.mutate({addonId:e,action:t,input:r});return D.invalidateQueries({queryKey:[[`addonSettings`]]}),n}}}catch(n){throw console.error(`[NodeAddonsSettingsPanel] action failed`,{addonId:e,action:t,err:n}),n}},[j,M,F,D,O]),me=o((e,t)=>{X(e,t)},[X]),Z=g({mutationFn:async()=>{let e=[];for(let t of q){let n=J.get(t.addonId);!n||n.pendingKeys.length===0||e.push({addonId:t.addonId,patch:n.pendingValues})}return e.length===0?{saved:[]}:{saved:await Promise.all(e.map(async({addonId:e,patch:t})=>(f===`global`?await k.mutateAsync({addonId:e,nodeId:F,patch:t}):await A.mutateAsync({addonId:e,deviceId:v,nodeId:F,patch:t}),e)))}},onSuccess:({saved:e})=>{for(let t of e)Y.current.get(t)?.discard();D.invalidateQueries({queryKey:[[`addonSettings`]]})}}),he=o(()=>{for(let e of Y.current.values())e.discard()},[]),ge=u(()=>{let e=0;for(let t of q){let n=J.get(t.addonId);n&&(e+=n.pendingKeys.length)}return e},[q,J]),_e=u(()=>{let e=new Map;for(let t of q){let n=J.get(t.addonId);if(!n||n.pendingKeys.length===0)continue;let r=new Set(n.pendingKeys);for(let n of t.schema.sections){let t=n.tab??`general`;for(let i of n.fields)`key`in i&&r.has(i.key)&&e.set(t,(e.get(t)??0)+1)}}return e},[q,J]);if(L)return _(`div`,{className:`h-24 rounded-lg border border-border bg-surface animate-pulse`});let Q=H&&U?B.get(H):void 0;if(!N&&q.length===0)return l(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:[`No addons in `,c.length>0?`[${c.join(`, `)}]`:`the current selection`,` `,`expose `,f,`-level settings on this node.`]});let $=Z.isPending;return l(`div`,{className:`space-y-4`,children:[(T||E)&&l(`div`,{className:`border-b border-border pb-2`,children:[T&&_(`h2`,{className:`text-sm font-semibold text-foreground`,children:T}),E&&_(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:E})]}),N&&_(ne,{tabs:V.map(e=>({id:e,label:ce.get(e)??e})),activeId:H,onChange:se,pendingByTab:_e}),Z.isError&&l(`div`,{className:`rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-[11px] text-red-400`,children:[`Save failed: `,String(Z.error?.message??Z.error)]}),_(re,{tabKey:Q?`extra:${H??``}`:`tab:${H??``}`,children:Q?Q.content:(()=>{let e=W?q.reduce((e,t)=>e+t.schemaWithValues.sections.filter(e=>(e.tab??`general`)===W).length,0):0,t=W!==null&&e<=1,n=q.map(e=>({...e,renderedWithValues:{...e.schemaWithValues,sections:e.schemaWithValues.sections.filter(e=>W?(e.tab??`general`)===W:!0).map(e=>t?{...e,title:``,description:void 0}:e)}})).filter(e=>e.renderedWithValues.sections.length>0).toSorted((e,t)=>{let n=e=>{let t=1/0;for(let n of e)typeof n.order==`number`&&n.order<t&&(t=n.order);return t},r=n(e.renderedWithValues.sections),i=n(t.renderedWithValues.sections);return r===i?0:r-i}),r=(w??[]).filter(e=>e.tabId===W),i=r.filter(e=>(e.placement??`before`)===`before`),a=r.filter(e=>e.placement===`after`);return n.length===0&&r.length===0?_(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:`Nothing to configure here for this node.`}):l(`div`,{className:`space-y-6`,children:[i.map((e,t)=>_(`div`,{children:e.content},`extra-before-${t}`)),n.length>0&&_(ae,{entries:n,paneStates:J,displayNames:le,disabled:$,setPaneRef:fe,onPaneStateChange:de,onImmediateSave:me,onAction:pe,inline:N||!!S}),a.map((e,t)=>_(`div`,{children:e.content},`extra-after-${t}`))]})})()}),!L&&_(te,{pendingCount:ge,onSave:()=>Z.mutate(),onDiscard:he,saving:$})]})}function ae({entries:e,paneStates:t,displayNames:n,disabled:r,setPaneRef:i,onPaneStateChange:a,onImmediateSave:o,onAction:s,inline:c}){let d=u(()=>[...e].toSorted((e,t)=>{if(e.addonId===`system-config`)return-1;if(t.addonId===`system-config`)return 1;let r=n.get(e.addonId)??e.addonId,i=n.get(t.addonId)??t.addonId;return r.localeCompare(i)}),[e,n]),[f,p]=h(d[0]?.addonId??``);v(()=>{d.length!==0&&(d.find(e=>e.addonId===f)||p(d[0].addonId))},[d,f]);let m=d.find(e=>e.addonId===f)??d[0];if(!m)return null;let g=u(()=>s?(e,t,n,r)=>s(e,t,n,r):void 0,[s]),y=e=>_(S,{ref:i(e.addonId),addonId:e.addonId,schema:e.renderedWithValues,serverValues:e.serverValues,onImmediateSave:o,onStateChange:a,onAction:g,disabled:r},e.addonId);return d.length===1||c?_(`div`,{className:`flex flex-col gap-4`,children:d.map(y)}):l(`div`,{className:`flex flex-col gap-3`,children:[_(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border shrink-0`,children:d.map(e=>{let r=n.get(e.addonId)??e.addonId,i=e.addonId===m.addonId,a=(t.get(e.addonId)?.pendingKeys.length??0)>0;return l(`button`,{type:`button`,onClick:()=>p(e.addonId),className:`relative px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors -mb-px border-b-2 whitespace-nowrap ${i?`text-primary border-primary bg-primary/5`:`text-foreground-subtle border-transparent hover:text-foreground hover:bg-surface-hover`}`,children:[r,a&&_(`span`,{className:`ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-amber-400`})]},e.addonId)})}),_(`div`,{className:`space-y-2`,children:d.map(e=>_(`div`,{style:e.addonId===m.addonId?void 0:{display:`none`},children:y(e)},e.addonId))})]})}export{T as t};
|
|
1
|
+
import{Rt as e,dt as t,on as n,ut as r,yt as i}from"./src-DfTnwu3m.js";import{H as a,I as o,K as s,Q as c,S as l,W as u,i as d,k as f,o as p,p as m,q as h,t as g,x as _,z as v}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{$ as y}from"./src-C9Wl4IAv.js";import{p as ee}from"./player-overlays-35cjLMFQ.js";import{t as b}from"./FormBuilder-8G0bykRV.js";import{n as te,r as x,t as ne}from"./SchemaTabBar-BrF8ZUiR.js";import{t as re}from"./StableTabPanel-p16epZGa.js";c();var S=f(function({addonId:e,schema:t,serverValues:n,onImmediateSave:r,onStateChange:i,onAction:c,disabled:l},d){let f=x({schema:t,serverValues:n,onImmediateSave:o(t=>r(e,t),[e,r]),onDeferredSave:o(()=>{},[])});a(d,()=>({flush:()=>{let e={};for(let t of f.pendingKeys)e[t]=f.values[t];return f.handleDiscard(f.pendingKeys),e},discard:()=>f.resetAll()}),[f]);let p=f.pendingKeys,m=p.join(`|`),h=u(()=>p.map(e=>`${e}=${JSON.stringify(f.values[e])}`).join(`,`),[p,f.values]),g=s(i);v(()=>{g.current=i},[i]),v(()=>{let t={};for(let e of p)t[e]=f.values[e];g.current({addonId:e,pendingKeys:p,pendingValues:t})},[e,m,h]);let y=u(()=>{if(c)return(t,n,r)=>c(e,t,n,r)},[e,c]);return _(b,{schema:t,values:f.values,onChange:f.handleChange,disabled:l,onAction:y})});c();function C(e,t){if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`){let n=e.fields.map(e=>C(e,t));return{...e,fields:n}}let n=e;t[e.key]=n.value;let{value:r,...i}=n;return i}function w(e,t){return{...e,fields:e.fields.map(e=>C(e,t))}}function ie(e){let t={};return{schema:{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>w(e,t))},values:t}}function T({nodeId:a,addonIds:c,level:f,deviceId:v,capability:b,sectionIds:x,sectionTab:S,extraTabs:C,schemaTabExtras:w,title:T,description:E,selfTabbed:oe}){let D=p(),O=ee().trpcClient,k=t(),A=r(),j=n(),M=e(),N=oe===!0||!!(C&&C.length>0),[P,se]=h(null);if(f===`device`&&!v)throw Error(`NodeAddonsSettingsPanel: deviceId is required when level === "device"`);let F=a??`hub`,I=d({queries:c.map(e=>({queryKey:[[`addonSettings`,f===`global`?`getGlobalSettings`:`getDeviceSettings`],{addonId:e,nodeId:F,deviceId:v??null,cap:b??null}],queryFn:async()=>f===`global`?{addonId:e,result:await O.addonSettings.getGlobalSettings.query({addonId:e,nodeId:F,...b?{cap:b}:{}})}:{addonId:e,result:await O.addonSettings.getDeviceSettings.query({addonId:e,deviceId:v,nodeId:F})},placeholderData:m}))}),L=I.some(e=>e.isLoading),R=I.map(e=>{if(!e.data)return`-`;if(e.data.result===null)return`${e.data.addonId}:n`;let t=[];for(let n of e.data.result.sections){t.push(`s:${n.id}:${n.tab??`general`}`);for(let e of n.fields){if(!(`key`in e))continue;let n=`options`in e&&Array.isArray(e.options)?e.options.map(e=>e.value).join(`,`):``,r=e.value,i=r===void 0?``:typeof r==`string`?r:JSON.stringify(r);t.push(`f:${e.key}:${n}:${i}`)}}return`${e.data.addonId}:${t.join(`|`)}`}).join(`||`),z=u(()=>{let e=new Set;for(let t of I){let n=t.data?.result?.sections;if(n)for(let t of n)e.add(t.tab??`general`)}return[...e]},[R+`::`+I.map(e=>(e.data?.result?.sections??[]).map(e=>e.tab??`general`).join(`,`)).join(`::`)]),B=u(()=>new Map((C??[]).map(e=>[e.id,e])),[C]),V=u(()=>{if(!N)return[];let e=[...new Set([...z,...(C??[]).map(e=>e.id),...(w??[]).map(e=>e.tabId)])],t=e=>{let t=B.get(e);if(t?.order!==void 0)return t.order;let n=y[e];return n?n.order:50};return e.toSorted((e,n)=>{let r=t(e),i=t(n);return r===i?e.localeCompare(n):r-i})},[N,z,C,B,w]),ce=u(()=>{let e=new Map,t=e=>y[e]?.label??e.charAt(0).toUpperCase()+e.slice(1);for(let n of z)e.set(n,t(n));for(let n of w??[])e.has(n.tabId)||e.set(n.tabId,t(n.tabId));for(let t of C??[])e.set(t.id,t.label);return e},[z,C,w]),H=N?P&&V.includes(P)?P:V[0]??null:null,U=H!==null&&B.has(H),W=N?H&&!U?H:void 0:S,{data:G}=i(void 0),le=u(()=>{let e=new Map;for(let t of G??[]){let n=t.manifest?.id;if(!n)continue;let r=t.manifest?.name??t.manifest?.packageDisplayName??n;e.set(n,r)}return e},[G]),K=s(new Map),q=u(()=>{let e=x?new Set(x):null,t=[];for(let n of I){if(!n.data)continue;let r=n.data.result??K.current.get(n.data.addonId)??null;if(n.data.result!==null&&K.current.set(n.data.addonId,n.data.result),r===null)continue;let{schema:i,values:a}=ie(r),o=i.sections.filter(t=>e?e.has(t.id):!0);if(o.length===0)continue;let s={...r,sections:r.sections.filter(t=>e?e.has(t.id):!0)},c={...i,sections:o};t.push({addonId:n.data.addonId,schemaWithValues:s,schema:c,serverValues:a})}return t},[R,x]),[J,ue]=h(new Map),de=o(e=>{ue(t=>{let n=new Map(t);return n.set(e.addonId,e),n})},[]),Y=s(new Map),fe=o(e=>t=>{t?Y.current.set(e,t):Y.current.delete(e)},[]),X=o(async(e,t)=>{f===`global`?await k.mutateAsync({addonId:e,nodeId:F,patch:t}):await A.mutateAsync({addonId:e,deviceId:v,nodeId:F,patch:t}),D.invalidateQueries({queryKey:[[`addonSettings`]]})},[k,A,F,f,v,D]),pe=o(async(e,t,n,r)=>{let i=F;try{switch(t){case`reprobe-hwaccel`:await j.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-audio-engine`:await M.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;default:{let n=await O.addons.custom.mutate({addonId:e,action:t,input:r});return D.invalidateQueries({queryKey:[[`addonSettings`]]}),n}}}catch(n){throw console.error(`[NodeAddonsSettingsPanel] action failed`,{addonId:e,action:t,err:n}),n}},[j,M,F,D,O]),me=o((e,t)=>{X(e,t)},[X]),Z=g({mutationFn:async()=>{let e=[];for(let t of q){let n=J.get(t.addonId);!n||n.pendingKeys.length===0||e.push({addonId:t.addonId,patch:n.pendingValues})}return e.length===0?{saved:[]}:{saved:await Promise.all(e.map(async({addonId:e,patch:t})=>(f===`global`?await k.mutateAsync({addonId:e,nodeId:F,patch:t}):await A.mutateAsync({addonId:e,deviceId:v,nodeId:F,patch:t}),e)))}},onSuccess:({saved:e})=>{for(let t of e)Y.current.get(t)?.discard();D.invalidateQueries({queryKey:[[`addonSettings`]]})}}),he=o(()=>{for(let e of Y.current.values())e.discard()},[]),ge=u(()=>{let e=0;for(let t of q){let n=J.get(t.addonId);n&&(e+=n.pendingKeys.length)}return e},[q,J]),_e=u(()=>{let e=new Map;for(let t of q){let n=J.get(t.addonId);if(!n||n.pendingKeys.length===0)continue;let r=new Set(n.pendingKeys);for(let n of t.schema.sections){let t=n.tab??`general`;for(let i of n.fields)`key`in i&&r.has(i.key)&&e.set(t,(e.get(t)??0)+1)}}return e},[q,J]);if(L)return _(`div`,{className:`h-24 rounded-lg border border-border bg-surface animate-pulse`});let Q=H&&U?B.get(H):void 0;if(!N&&q.length===0)return l(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:[`No addons in `,c.length>0?`[${c.join(`, `)}]`:`the current selection`,` `,`expose `,f,`-level settings on this node.`]});let $=Z.isPending;return l(`div`,{className:`space-y-4`,children:[(T||E)&&l(`div`,{className:`border-b border-border pb-2`,children:[T&&_(`h2`,{className:`text-sm font-semibold text-foreground`,children:T}),E&&_(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:E})]}),N&&_(ne,{tabs:V.map(e=>({id:e,label:ce.get(e)??e})),activeId:H,onChange:se,pendingByTab:_e}),Z.isError&&l(`div`,{className:`rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-[11px] text-red-400`,children:[`Save failed: `,String(Z.error?.message??Z.error)]}),_(re,{tabKey:Q?`extra:${H??``}`:`tab:${H??``}`,children:Q?Q.content:(()=>{let e=W?q.reduce((e,t)=>e+t.schemaWithValues.sections.filter(e=>(e.tab??`general`)===W).length,0):0,t=W!==null&&e<=1,n=q.map(e=>({...e,renderedWithValues:{...e.schemaWithValues,sections:e.schemaWithValues.sections.filter(e=>W?(e.tab??`general`)===W:!0).map(e=>t?{...e,title:``,description:void 0}:e)}})).filter(e=>e.renderedWithValues.sections.length>0).toSorted((e,t)=>{let n=e=>{let t=1/0;for(let n of e)typeof n.order==`number`&&n.order<t&&(t=n.order);return t},r=n(e.renderedWithValues.sections),i=n(t.renderedWithValues.sections);return r===i?0:r-i}),r=(w??[]).filter(e=>e.tabId===W),i=r.filter(e=>(e.placement??`before`)===`before`),a=r.filter(e=>e.placement===`after`);return n.length===0&&r.length===0?_(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:`Nothing to configure here for this node.`}):l(`div`,{className:`space-y-6`,children:[i.map((e,t)=>_(`div`,{children:e.content},`extra-before-${t}`)),n.length>0&&_(ae,{entries:n,paneStates:J,displayNames:le,disabled:$,setPaneRef:fe,onPaneStateChange:de,onImmediateSave:me,onAction:pe,inline:N||!!S}),a.map((e,t)=>_(`div`,{children:e.content},`extra-after-${t}`))]})})()}),!L&&_(te,{pendingCount:ge,onSave:()=>Z.mutate(),onDiscard:he,saving:$})]})}function ae({entries:e,paneStates:t,displayNames:n,disabled:r,setPaneRef:i,onPaneStateChange:a,onImmediateSave:o,onAction:s,inline:c}){let d=u(()=>[...e].toSorted((e,t)=>{if(e.addonId===`system-config`)return-1;if(t.addonId===`system-config`)return 1;let r=n.get(e.addonId)??e.addonId,i=n.get(t.addonId)??t.addonId;return r.localeCompare(i)}),[e,n]),[f,p]=h(d[0]?.addonId??``);v(()=>{d.length!==0&&(d.find(e=>e.addonId===f)||p(d[0].addonId))},[d,f]);let m=d.find(e=>e.addonId===f)??d[0];if(!m)return null;let g=u(()=>s?(e,t,n,r)=>s(e,t,n,r):void 0,[s]),y=e=>_(S,{ref:i(e.addonId),addonId:e.addonId,schema:e.renderedWithValues,serverValues:e.serverValues,onImmediateSave:o,onStateChange:a,onAction:g,disabled:r},e.addonId);return d.length===1||c?_(`div`,{className:`flex flex-col gap-4`,children:d.map(y)}):l(`div`,{className:`flex flex-col gap-3`,children:[_(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border shrink-0`,children:d.map(e=>{let r=n.get(e.addonId)??e.addonId,i=e.addonId===m.addonId,a=(t.get(e.addonId)?.pendingKeys.length??0)>0;return l(`button`,{type:`button`,onClick:()=>p(e.addonId),className:`relative px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors -mb-px border-b-2 whitespace-nowrap ${i?`text-primary border-primary bg-primary/5`:`text-foreground-subtle border-transparent hover:text-foreground hover:bg-surface-hover`}`,children:[r,a&&_(`span`,{className:`ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-amber-400`})]},e.addonId)})}),_(`div`,{className:`space-y-2`,children:d.map(e=>_(`div`,{style:e.addonId===m.addonId?void 0:{display:`none`},children:y(e)},e.addonId))})]})}export{T as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{$o as e,Bi as t,En as n,Mn as r,On as i,is as a,ki as o}from"./src-V00nU2Tb.js";import{K as s,Q as c,S as l,W as u,b as d,o as f,q as p,x as m,z as h}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as g}from"./zap-BZasYUgo.js";import{P as _,W as v,a as y,j as b,x}from"./index-Dm9Uz1f0.js";var S=v(`circuit-board`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M11 9h4a2 2 0 0 0 2-2V3`,key:`1ve2rv`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`M7 21v-4a2 2 0 0 1 2-2h4`,key:`1fwkro`}],[`circle`,{cx:`15`,cy:`15`,r:`2`,key:`3i40o0`}]]),C=v(`layers`,[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]]),w=v(`lock-open`,[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 9.9-1`,key:`1mm8w8`}]]),T=v(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),E=v(`scale`,[[`path`,{d:`m16 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z`,key:`7g6ntu`}],[`path`,{d:`m2 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z`,key:`ijws7r`}],[`path`,{d:`M7 21h10`,key:`1b0cd5`}],[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 7h2c2 0 5-1 7-2 2 1 5 2 7 2h2`,key:`3gwbw2`}]]),D=v(`usb`,[[`circle`,{cx:`10`,cy:`7`,r:`1`,key:`dypaad`}],[`circle`,{cx:`4`,cy:`20`,r:`1`,key:`22iqad`}],[`path`,{d:`M4.7 19.3 19 5`,key:`1enqfc`}],[`path`,{d:`m21 3-3 1 2 2Z`,key:`d3ov82`}],[`path`,{d:`M9.26 7.68 5 12l2 5`,key:`1esawj`}],[`path`,{d:`m10 14 5 2 3.5-3.5`,key:`v8oal5`}],[`path`,{d:`m18 12 1-1 1 1-1 1Z`,key:`1bh22v`}]]);c();function O(e){return r({addonId:e})}function k(e){return i({deviceId:e},{enabled:Number.isFinite(e)})}var A=3e4,j=2e3;function M(e){let t=s(0);return t.current===0&&(t.current=Date.now()),n({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>=A?!1:j}})}function N(e){let t={};for(let n of e){let e=Object.keys(n.steps).length>0;t[n.key]={enabled:n.enabled,weight:Math.max(1,n.weight),...n.maxSessions!==null&&n.maxSessions>0?{maxSessions:n.maxSessions}:{},...e?{steps:n.steps}:{}}}return t}c();function P(e,t,n){return Math.min(Math.max(e,t),n)}function F(e){let t=e.reduce((e,t)=>e+Math.max(t.weight,0),0);if(t<=0){let t=e.length>0?100/e.length:0;return Object.fromEntries(e.map(e=>[e.id,t]))}return Object.fromEntries(e.map(e=>[e.id,Math.max(e.weight,0)/t*100]))}function I(e,t,n,r,i){let a=i.filter(e=>e!==t&&r.has(e)).reduce((t,n)=>t+Math.max(e[n]??0,0),0),o=Math.max(0,100-a),s=i.filter(e=>e!==t&&!r.has(e)),c=s.length===0?o:P(n,0,o),l={...e,[t]:c};if(s.length>0){let e=Math.max(0,o-c)/s.length;for(let t of s)l[t]=e}return l}function L(e,t,n){let r={},i=0,a=[];for(let o of t){let t=Math.max(e[o]??0,0);if(n.has(o)){let e=Math.round(t);r[o]=e,i+=e}else{let e=Math.floor(t);r[o]=e,a.push({id:o,floor:e,frac:t-e})}}let o=Math.max(0,100-i)-a.reduce((e,t)=>e+t.floor,0),s=[...a].sort((e,t)=>t.frac-e.frac);for(let e=0;o>0&&s.length>0;e+=1)r[s[e%s.length].id]+=1,--o;let c=[...a].sort((e,t)=>e.frac-t.frac);for(let e=0;o<0&&c.length>0;e+=1){let t=c[e%c.length].id;r[t]>0&&(--r[t],o+=1)}return r}function R({nodes:e,pending:t,onCommitWeights:n,weightLabel:r=`Detection weight`,emptyHint:i,footnote:a}){let[o,s]=p(()=>F(e)),[c,u]=p(new Set);h(()=>{s(F(e)),u(t=>new Set([...t].filter(t=>e.some(e=>e.id===t))))},[e.map(e=>`${e.id}:${e.weight}`).join(`|`)]);let f=e.map(e=>e.id),g=e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},_=(e,t)=>{s(n=>I(n,e,t,c,f))},v=()=>{let t=L(o,f,c),r=e.filter(e=>(t[e.id]??0)!==e.weight).map(e=>e.id);if(r.length===0)return;let i=new Set([...r,...c]);n(e.filter(e=>i.has(e.id)).map(e=>({nodeId:e.id,weight:t[e.id]??0})))};if(e.length===0)return m(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:i??`No detect-enabled nodes. Enable “Detect” on a node above to distribute detection weight.`});let y=e.length===1;return l(`div`,{className:`space-y-3`,children:[e.map(e=>{let n=o[e.id]??0,i=c.has(e.id);return l(`div`,{className:`flex items-center gap-3`,children:[m(`span`,{className:`w-28 shrink-0 truncate text-xs font-medium text-foreground`,title:e.name,children:e.name}),m(`input`,{"aria-label":`${r} for ${e.name}`,type:`range`,min:0,max:100,step:1,value:Math.round(n),disabled:t||i||y,onChange:t=>_(e.id,Number(t.target.value)),onPointerUp:()=>v(),onKeyUp:()=>v(),className:`h-1.5 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50`}),l(`span`,{className:`w-10 shrink-0 text-right font-mono text-xs tabular-nums text-foreground`,children:[Math.round(n),`%`]}),m(`button`,{type:`button`,onClick:()=>g(e.id),disabled:t||y,"aria-pressed":i,title:i?`Unlock — allow rebalancing`:`Lock this share when others change`,className:`shrink-0 rounded p-1 hover:bg-surface-hover disabled:opacity-40 ${i?`text-amber-400`:`text-foreground-subtle`}`,children:m(i?x:w,{className:`h-3.5 w-3.5`})})]},e.id)}),m(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:a??m(d,{children:`Dragging one slider splits the rest equally across the unlocked nodes; lock a node to pin its share — locked nodes never move and the total always stays at 100%, so a drag is bounded by the room the unlocked nodes leave. Detection only distributes across nodes that can source a camera’s frames.`})})]})}c();function z(e){let t=e.backend.toLowerCase(),n=e.device.toLowerCase();return e.key===`cpu`||n===`cpu`?{label:`CPU`,Icon:b,hue:`slate`}:t===`openvino`&&n===`npu`?{label:`Intel NPU (AI Boost)`,Icon:g,hue:`sky`}:t===`openvino`&&(n===`gpu`||n===`igpu`)?{label:`Intel iGPU`,Icon:S,hue:`violet`}:t===`edgetpu`?{label:`Coral Edge TPU`,Icon:D,hue:`emerald`}:{label:`${e.backend} ${e.device}`.replace(/\b\w/g,e=>e.toUpperCase()).trim(),Icon:b,hue:`slate`}}var B={sky:`bg-sky-500/12 text-sky-400 ring-sky-500/25`,violet:`bg-violet-500/12 text-violet-400 ring-violet-500/25`,emerald:`bg-emerald-500/12 text-emerald-400 ring-emerald-500/25`,slate:`bg-surface-hover text-foreground-subtle ring-border`};function V({nodeId:n,nodeName:r,isOnline:i}){let s=f(),{data:c,isLoading:g}=o({nodeId:n},{refetchInterval:15e3}),v=t({onSettled:()=>{s.invalidateQueries({queryKey:[`pipelineOrchestrator`,`getNodeInferenceDevices`]})}}),b=c?.devices??[],x=c?.reachable??i,[S,w]=p({});h(()=>{w(Object.fromEntries(b.map(e=>[e.key,{enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}])))},[b.map(e=>`${e.key}:${e.enabled}:${e.weight}:${e.maxSessions}:${JSON.stringify(e.steps??{})}`).join(`|`)]);let T=u(()=>b.filter(e=>S[e.key]?.enabled??e.enabled).length,[b,S]),[D,O]=p(null),k=D??T>0,A=e=>{let t=b.map(t=>{let n=e[t.key]??j(t);return{key:t.key,enabled:n.enabled,weight:n.weight,maxSessions:n.maxSessions,steps:n.steps}});v.mutate({agentNodeId:n,inferenceDevices:N(t)})},j=e=>({enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}),M=e=>{if(!e.available)return;let t=S[e.key]??j(e),n={...S,[e.key]:{...t,enabled:!t.enabled}};w(n),A(n)},P=(e,t)=>{let n=S[e.key]??j(e),r={...S,[e.key]:{...n,maxSessions:t}};w(r),A(r)},F=u(()=>b.filter(e=>(S[e.key]?.enabled??e.enabled)&&e.available),[b,S]),I=u(()=>F.map(e=>({id:e.key,name:z(e).label,weight:S[e.key]?.weight??e.weight})),[F,S]);return l(`div`,{className:`rounded-lg border border-border bg-surface/60`,children:[l(`button`,{type:`button`,onClick:()=>O(!k),className:`flex w-full items-center gap-2.5 px-3.5 py-2.5 text-left`,"aria-expanded":k,children:[m(_,{className:`h-4 w-4 shrink-0 text-foreground-subtle transition-transform ${k?`rotate-90`:``}`}),m(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:r}),m(`span`,{className:`ml-auto flex items-center gap-2 text-[11px]`,children:x?T>=2?l(`span`,{className:`inline-flex items-center gap-1 text-emerald-400`,children:[m(C,{className:`h-3.5 w-3.5`}),T,` accelerators`]}):T===1?m(`span`,{className:`text-foreground-subtle`,children:`single default`}):m(`span`,{className:`text-foreground-subtle/70`,children:`auto default`}):l(`span`,{className:`inline-flex items-center gap-1 text-foreground-subtle`,children:[m(y,{className:`h-3.5 w-3.5`}),` unreachable`]})})]}),k&&l(`div`,{className:`space-y-3 border-t border-border px-3.5 py-3`,children:[x?g&&b.length===0?m(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`Probing accelerators…`}):b.length===0?m(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`}):m(`ul`,{className:`space-y-2`,children:b.map(t=>{let n=z(t),r=S[t.key]??j(t),i=r.enabled&&t.available;return l(`li`,{className:`flex items-center gap-3 rounded-lg border px-3 py-2.5 transition-colors ${t.available?i?`border-primary/40 bg-primary/[0.04] ring-1 ring-inset ring-primary/20`:`border-border bg-surface`:`border-border/60 bg-background opacity-55`}`,children:[m(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-md ring-1 ring-inset ${B[n.hue]}`,children:m(n.Icon,{className:`h-4.5 w-4.5`})}),l(`div`,{className:`min-w-0 flex-1`,children:[l(`div`,{className:`flex items-center gap-2`,children:[m(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:n.label}),m(a,{variant:`default`,style:`outline`,className:`font-mono text-[9px]`,children:t.format}),!t.available&&m(a,{variant:`warning`,className:`text-[9px]`,children:`unavailable`})]}),l(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[m(`span`,{className:`font-mono`,children:t.key}),!i&&l(d,{children:[m(`span`,{"aria-hidden":!0,children:`·`}),l(`span`,{children:[`default model`,` `,m(`span`,{className:`font-mono text-foreground/80`,children:t.defaultModelId})]})]})]})]}),i&&l(`label`,{className:`flex shrink-0 items-center gap-1 text-[10px] text-foreground-subtle`,children:[m(`span`,{className:`hidden @sm/clustertab:inline`,children:`cap`}),m(`input`,{type:`number`,min:1,placeholder:`∞`,value:r.maxSessions??``,onChange:e=>{let n=e.target.value.trim(),r=n===``?null:Number.parseInt(n,10);P(t,r!=null&&r>0?r:null)},disabled:v.isPending,"aria-label":`Max concurrent sessions for ${n.label}`,className:`w-14 rounded border border-border bg-background px-1.5 py-1 text-right font-mono text-[11px] text-foreground focus:border-primary focus:outline-none`})]}),m(e,{checked:i,onCheckedChange:()=>M(t),disabled:!t.available||v.isPending,"aria-label":`Enable ${n.label}`,className:t.available?``:`cursor-not-allowed opacity-50`})]},t.key)})}):m(H,{}),x&&F.length>=2&&l(`div`,{className:`space-y-3 rounded-lg border border-border bg-background/60 p-3.5`,children:[l(`h4`,{className:`flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:[m(E,{className:`h-3.5 w-3.5`}),`Balancer weight`]}),m(R,{nodes:I,pending:v.isPending,onCommitWeights:e=>{let t={...S};for(let n of e){let e=t[n.nodeId];e&&(t[n.nodeId]={...e,weight:n.weight})}w(t),A(t)},weightLabel:`Balancer weight`,footnote:m(d,{children:`Drag to shift the share of detection sessions each accelerator handles; lock one to pin its share while the others rebalance. Shares always sum to 100%.`})})]}),v.isError&&l(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] text-danger`,children:[`Failed to save inference devices:`,` `,v.error instanceof Error?v.error.message:`unknown error`]})]})]})}function H(){return l(`div`,{className:`flex flex-col items-center gap-2 rounded-lg border border-dashed border-border bg-background px-4 py-8 text-center`,children:[m(y,{className:`h-6 w-6 text-foreground-subtle/60`}),m(`p`,{className:`text-xs font-medium text-foreground`,children:`Node unreachable`}),m(`p`,{className:`max-w-sm text-[11px] text-foreground-subtle`,children:`The platform probe couldn't be reached, so its live accelerator set is unavailable. Settings resume once the node reconnects.`})]})}export{k as a,T as c,N as i,C as l,z as n,M as o,R as r,O as s,V as t};
|
|
1
|
+
import{Ai as e,En as t,Mn as n,On as r,Vi as i,is as a,ls as o}from"./src-DfTnwu3m.js";import{K as s,Q as c,S as l,W as u,b as d,o as f,q as p,x as m,z as h}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as g}from"./zap-FMbpMlZh.js";import{P as _,W as v,a as y,j as b,x}from"./index-DOGqQOnC.js";var S=v(`circuit-board`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M11 9h4a2 2 0 0 0 2-2V3`,key:`1ve2rv`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`M7 21v-4a2 2 0 0 1 2-2h4`,key:`1fwkro`}],[`circle`,{cx:`15`,cy:`15`,r:`2`,key:`3i40o0`}]]),C=v(`layers`,[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]]),w=v(`lock-open`,[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 9.9-1`,key:`1mm8w8`}]]),T=v(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),E=v(`scale`,[[`path`,{d:`m16 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z`,key:`7g6ntu`}],[`path`,{d:`m2 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z`,key:`ijws7r`}],[`path`,{d:`M7 21h10`,key:`1b0cd5`}],[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 7h2c2 0 5-1 7-2 2 1 5 2 7 2h2`,key:`3gwbw2`}]]),D=v(`usb`,[[`circle`,{cx:`10`,cy:`7`,r:`1`,key:`dypaad`}],[`circle`,{cx:`4`,cy:`20`,r:`1`,key:`22iqad`}],[`path`,{d:`M4.7 19.3 19 5`,key:`1enqfc`}],[`path`,{d:`m21 3-3 1 2 2Z`,key:`d3ov82`}],[`path`,{d:`M9.26 7.68 5 12l2 5`,key:`1esawj`}],[`path`,{d:`m10 14 5 2 3.5-3.5`,key:`v8oal5`}],[`path`,{d:`m18 12 1-1 1 1-1 1Z`,key:`1bh22v`}]]);c();function O(e){return n({addonId:e})}function k(e){return r({deviceId:e},{enabled:Number.isFinite(e)})}var A=3e4,j=2e3;function M(e){let n=s(0);return n.current===0&&(n.current=Date.now()),t({parentDeviceId:e},{enabled:Number.isFinite(e),staleTime:0,refetchOnMount:`always`,refetchInterval:e=>{let t=e.state.data;return t&&t.length>0||Date.now()-n.current>=A?!1:j}})}function N(e){let t={};for(let n of e){let e=Object.keys(n.steps).length>0;t[n.key]={enabled:n.enabled,weight:Math.max(1,n.weight),...n.maxSessions!==null&&n.maxSessions>0?{maxSessions:n.maxSessions}:{},...e?{steps:n.steps}:{}}}return t}c();function P(e,t,n){return Math.min(Math.max(e,t),n)}function F(e){let t=e.reduce((e,t)=>e+Math.max(t.weight,0),0);if(t<=0){let t=e.length>0?100/e.length:0;return Object.fromEntries(e.map(e=>[e.id,t]))}return Object.fromEntries(e.map(e=>[e.id,Math.max(e.weight,0)/t*100]))}function I(e,t,n,r,i){let a=i.filter(e=>e!==t&&r.has(e)).reduce((t,n)=>t+Math.max(e[n]??0,0),0),o=Math.max(0,100-a),s=i.filter(e=>e!==t&&!r.has(e)),c=s.length===0?o:P(n,0,o),l={...e,[t]:c};if(s.length>0){let e=Math.max(0,o-c)/s.length;for(let t of s)l[t]=e}return l}function L(e,t,n){let r={},i=0,a=[];for(let o of t){let t=Math.max(e[o]??0,0);if(n.has(o)){let e=Math.round(t);r[o]=e,i+=e}else{let e=Math.floor(t);r[o]=e,a.push({id:o,floor:e,frac:t-e})}}let o=Math.max(0,100-i)-a.reduce((e,t)=>e+t.floor,0),s=[...a].sort((e,t)=>t.frac-e.frac);for(let e=0;o>0&&s.length>0;e+=1)r[s[e%s.length].id]+=1,--o;let c=[...a].sort((e,t)=>e.frac-t.frac);for(let e=0;o<0&&c.length>0;e+=1){let t=c[e%c.length].id;r[t]>0&&(--r[t],o+=1)}return r}function R({nodes:e,pending:t,onCommitWeights:n,weightLabel:r=`Detection weight`,emptyHint:i,footnote:a}){let[o,s]=p(()=>F(e)),[c,u]=p(new Set);h(()=>{s(F(e)),u(t=>new Set([...t].filter(t=>e.some(e=>e.id===t))))},[e.map(e=>`${e.id}:${e.weight}`).join(`|`)]);let f=e.map(e=>e.id),g=e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},_=(e,t)=>{s(n=>I(n,e,t,c,f))},v=()=>{let t=L(o,f,c),r=e.filter(e=>(t[e.id]??0)!==e.weight).map(e=>e.id);if(r.length===0)return;let i=new Set([...r,...c]);n(e.filter(e=>i.has(e.id)).map(e=>({nodeId:e.id,weight:t[e.id]??0})))};if(e.length===0)return m(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:i??`No detect-enabled nodes. Enable “Detect” on a node above to distribute detection weight.`});let y=e.length===1;return l(`div`,{className:`space-y-3`,children:[e.map(e=>{let n=o[e.id]??0,i=c.has(e.id);return l(`div`,{className:`flex items-center gap-3`,children:[m(`span`,{className:`w-28 shrink-0 truncate text-xs font-medium text-foreground`,title:e.name,children:e.name}),m(`input`,{"aria-label":`${r} for ${e.name}`,type:`range`,min:0,max:100,step:1,value:Math.round(n),disabled:t||i||y,onChange:t=>_(e.id,Number(t.target.value)),onPointerUp:()=>v(),onKeyUp:()=>v(),className:`h-1.5 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50`}),l(`span`,{className:`w-10 shrink-0 text-right font-mono text-xs tabular-nums text-foreground`,children:[Math.round(n),`%`]}),m(`button`,{type:`button`,onClick:()=>g(e.id),disabled:t||y,"aria-pressed":i,title:i?`Unlock — allow rebalancing`:`Lock this share when others change`,className:`shrink-0 rounded p-1 hover:bg-surface-hover disabled:opacity-40 ${i?`text-amber-400`:`text-foreground-subtle`}`,children:m(i?x:w,{className:`h-3.5 w-3.5`})})]},e.id)}),m(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:a??m(d,{children:`Dragging one slider splits the rest equally across the unlocked nodes; lock a node to pin its share — locked nodes never move and the total always stays at 100%, so a drag is bounded by the room the unlocked nodes leave. Detection only distributes across nodes that can source a camera’s frames.`})})]})}c();function z(e){let t=e.backend.toLowerCase(),n=e.device.toLowerCase();return e.key===`cpu`||n===`cpu`?{label:`CPU`,Icon:b,hue:`slate`}:t===`openvino`&&n===`npu`?{label:`Intel NPU (AI Boost)`,Icon:g,hue:`sky`}:t===`openvino`&&(n===`gpu`||n===`igpu`)?{label:`Intel iGPU`,Icon:S,hue:`violet`}:t===`edgetpu`?{label:`Coral Edge TPU`,Icon:D,hue:`emerald`}:{label:`${e.backend} ${e.device}`.replace(/\b\w/g,e=>e.toUpperCase()).trim(),Icon:b,hue:`slate`}}var B={sky:`bg-sky-500/12 text-sky-400 ring-sky-500/25`,violet:`bg-violet-500/12 text-violet-400 ring-violet-500/25`,emerald:`bg-emerald-500/12 text-emerald-400 ring-emerald-500/25`,slate:`bg-surface-hover text-foreground-subtle ring-border`};function V({nodeId:t,nodeName:n,isOnline:r}){let s=f(),{data:c,isLoading:g}=e({nodeId:t},{refetchInterval:15e3}),v=i({onSettled:()=>{s.invalidateQueries({queryKey:[`pipelineOrchestrator`,`getNodeInferenceDevices`]})}}),b=c?.devices??[],x=c?.reachable??r,[S,w]=p({});h(()=>{w(Object.fromEntries(b.map(e=>[e.key,{enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}])))},[b.map(e=>`${e.key}:${e.enabled}:${e.weight}:${e.maxSessions}:${JSON.stringify(e.steps??{})}`).join(`|`)]);let T=u(()=>b.filter(e=>S[e.key]?.enabled??e.enabled).length,[b,S]),[D,O]=p(null),k=D??T>0,A=e=>{let n=b.map(t=>{let n=e[t.key]??j(t);return{key:t.key,enabled:n.enabled,weight:n.weight,maxSessions:n.maxSessions,steps:n.steps}});v.mutate({agentNodeId:t,inferenceDevices:N(n)})},j=e=>({enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}),M=e=>{if(!e.available)return;let t=S[e.key]??j(e),n={...S,[e.key]:{...t,enabled:!t.enabled}};w(n),A(n)},P=(e,t)=>{let n=S[e.key]??j(e),r={...S,[e.key]:{...n,maxSessions:t}};w(r),A(r)},F=u(()=>b.filter(e=>(S[e.key]?.enabled??e.enabled)&&e.available),[b,S]),I=u(()=>F.map(e=>({id:e.key,name:z(e).label,weight:S[e.key]?.weight??e.weight})),[F,S]);return l(`div`,{className:`rounded-lg border border-border bg-surface/60`,children:[l(`button`,{type:`button`,onClick:()=>O(!k),className:`flex w-full items-center gap-2.5 px-3.5 py-2.5 text-left`,"aria-expanded":k,children:[m(_,{className:`h-4 w-4 shrink-0 text-foreground-subtle transition-transform ${k?`rotate-90`:``}`}),m(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:n}),m(`span`,{className:`ml-auto flex items-center gap-2 text-[11px]`,children:x?T>=2?l(`span`,{className:`inline-flex items-center gap-1 text-emerald-400`,children:[m(C,{className:`h-3.5 w-3.5`}),T,` accelerators`]}):T===1?m(`span`,{className:`text-foreground-subtle`,children:`single default`}):m(`span`,{className:`text-foreground-subtle/70`,children:`auto default`}):l(`span`,{className:`inline-flex items-center gap-1 text-foreground-subtle`,children:[m(y,{className:`h-3.5 w-3.5`}),` unreachable`]})})]}),k&&l(`div`,{className:`space-y-3 border-t border-border px-3.5 py-3`,children:[x?g&&b.length===0?m(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`Probing accelerators…`}):b.length===0?m(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`}):m(`ul`,{className:`space-y-2`,children:b.map(e=>{let t=z(e),n=S[e.key]??j(e),r=n.enabled&&e.available;return l(`li`,{className:`flex items-center gap-3 rounded-lg border px-3 py-2.5 transition-colors ${e.available?r?`border-primary/40 bg-primary/[0.04] ring-1 ring-inset ring-primary/20`:`border-border bg-surface`:`border-border/60 bg-background opacity-55`}`,children:[m(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-md ring-1 ring-inset ${B[t.hue]}`,children:m(t.Icon,{className:`h-4.5 w-4.5`})}),l(`div`,{className:`min-w-0 flex-1`,children:[l(`div`,{className:`flex items-center gap-2`,children:[m(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t.label}),m(o,{variant:`default`,style:`outline`,className:`font-mono text-[9px]`,children:e.format}),!e.available&&m(o,{variant:`warning`,className:`text-[9px]`,children:`unavailable`})]}),l(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[m(`span`,{className:`font-mono`,children:e.key}),!r&&l(d,{children:[m(`span`,{"aria-hidden":!0,children:`·`}),l(`span`,{children:[`default model`,` `,m(`span`,{className:`font-mono text-foreground/80`,children:e.defaultModelId})]})]})]})]}),r&&l(`label`,{className:`flex shrink-0 items-center gap-1 text-[10px] text-foreground-subtle`,children:[m(`span`,{className:`hidden @sm/clustertab:inline`,children:`cap`}),m(`input`,{type:`number`,min:1,placeholder:`∞`,value:n.maxSessions??``,onChange:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10);P(e,r!=null&&r>0?r:null)},disabled:v.isPending,"aria-label":`Max concurrent sessions for ${t.label}`,className:`w-14 rounded border border-border bg-background px-1.5 py-1 text-right font-mono text-[11px] text-foreground focus:border-primary focus:outline-none`})]}),m(a,{checked:r,onCheckedChange:()=>M(e),disabled:!e.available||v.isPending,"aria-label":`Enable ${t.label}`,className:e.available?``:`cursor-not-allowed opacity-50`})]},e.key)})}):m(H,{}),x&&F.length>=2&&l(`div`,{className:`space-y-3 rounded-lg border border-border bg-background/60 p-3.5`,children:[l(`h4`,{className:`flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:[m(E,{className:`h-3.5 w-3.5`}),`Balancer weight`]}),m(R,{nodes:I,pending:v.isPending,onCommitWeights:e=>{let t={...S};for(let n of e){let e=t[n.nodeId];e&&(t[n.nodeId]={...e,weight:n.weight})}w(t),A(t)},weightLabel:`Balancer weight`,footnote:m(d,{children:`Drag to shift the share of detection sessions each accelerator handles; lock one to pin its share while the others rebalance. Shares always sum to 100%.`})})]}),v.isError&&l(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] text-danger`,children:[`Failed to save inference devices:`,` `,v.error instanceof Error?v.error.message:`unknown error`]})]})]})}function H(){return l(`div`,{className:`flex flex-col items-center gap-2 rounded-lg border border-dashed border-border bg-background px-4 py-8 text-center`,children:[m(y,{className:`h-6 w-6 text-foreground-subtle/60`}),m(`p`,{className:`text-xs font-medium text-foreground`,children:`Node unreachable`}),m(`p`,{className:`max-w-sm text-[11px] text-foreground-subtle`,children:`The platform probe couldn't be reached, so its live accelerator set is unavailable. Settings resume once the node reconnects.`})]})}export{k as a,T as c,N as i,C as l,z as n,M as o,R as r,O as s,V as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{$o as e,Io as t,Lo as n,No as r,Qn as i,Qo as a,Ro as o,S as s,aa as c,bo as l,cs as u,is as d,ls as f,ns as p,os as m,rs as h,ss as g,ts as _,us as v,zo as y}from"./src-DfTnwu3m.js";import{Q as b,S as x,W as S,a as C,b as w,i as T,o as E,q as D,t as O,x as k,z as A}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{C as j,P as M,b as ee,c as N,o as P,s as F}from"./src-C9Wl4IAv.js";import{p as I}from"./player-overlays-35cjLMFQ.js";import{n as te,t as ne}from"./bell-ring-B89FuVzx.js";import{t as L}from"./circle-check-big-6KqLnh7I.js";import{t as re}from"./copy-BAh4BimG.js";import{t as ie}from"./pencil-sz3vITXt.js";import{t as R}from"./plus-CzPndm5P.js";import{t as ae}from"./refresh-cw-yJ3BGqhW.js";import{t as oe}from"./rotate-ccw-B2UqNaB5.js";import{t as se}from"./search-Djlmih4W.js";import{t as z}from"./send-ibgpXPAd.js";import{t as ce}from"./zap-FMbpMlZh.js";import{J as le,N as ue,S as B,V as de,W as fe,f as pe,i as me,o as he,s as V}from"./index-DOGqQOnC.js";import{t as H}from"./AdminPage-Dq33XE9j.js";import{t as ge}from"./AdminTabs-Bpp49XUt.js";var _e=fe(`flask-conical`,[[`path`,{d:`M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2`,key:`18mbvz`}],[`path`,{d:`M6.453 15h11.094`,key:`3shlmq`}],[`path`,{d:`M8.5 2h7`,key:`csnxdl`}]]),ve=fe(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),ye=fe(`languages`,[[`path`,{d:`m5 8 6 6`,key:`1wu5hv`}],[`path`,{d:`m4 14 6-6 2-3`,key:`1k1g8d`}],[`path`,{d:`M2 5h12`,key:`or177f`}],[`path`,{d:`M7 2h1`,key:`1t2jsx`}],[`path`,{d:`m22 22-5-10-5 10`,key:`don7ne`}],[`path`,{d:`M14 18h6`,key:`1m8k6r`}]]);b();var be={home:`Home`,away:`Away`,night:`Night`};function xe(e){return be[e]??e}function Se(e,t){if(e<=0)return t;if(e<60)return`${e} s`;let n=Math.floor(e/60),r=e%60;return r===0?`${n} min`:`${n} min ${r} s`}function Ce(e,t){return e.ruleCount===0?`Arms nothing — no enabled rule is gated on this mode.`:e.allDevices?`Every device — ${De(e.ruleCount,`rule`)} with no device scope.`:e.deviceIds.length===0?`${De(e.ruleCount,`rule`)}, no device restriction.`:e.deviceIds.map(e=>t.get(e)??`Device ${e}`).join(`, `)}function we(e,t){if(e.length===0)return``;let n=e.map(e=>`${t.get(e.deviceId)??`Device ${e.deviceId}`} (${Te[e.reason]})`);return`${e.length} excluded: ${n.join(`, `)}`}var Te={muted:`notifications muted`,"detection-off":`detection off`,offline:`offline`};function Ee(e){return e.ruleCount===0}function De(e,t){return e===1?`1 ${t}`:`${e} ${t}s`}function Oe(e,t){let n=e.trim();if(n===``)return null;let r=Number(n);return!Number.isFinite(r)||!Number.isInteger(r)||r<0||r>t?null:r}var ke=[`notificationRules`,`getAlarmConfig`],Ae=[`notificationOutput`,`listTargets`],je=[`deviceManager`,`listAll`,`alarm-coverage`],Me=600,Ne=3600;function Pe({label:e,hint:t,value:n,max:r,zeroMeans:i,disabled:a,onCommit:o}){let[s,c]=D(null);return x(`div`,{className:`flex flex-col gap-1`,children:[k(`label`,{className:`text-sm font-medium`,children:e}),x(`div`,{className:`flex items-center gap-2`,children:[k(g,{type:`number`,min:0,max:r,value:s??String(n),disabled:a,onChange:e=>c(e.target.value),onBlur:()=>{let e=s===null?null:Oe(s,r);c(null),e!==null&&e!==n&&o(e)},className:`w-28`,"data-testid":`alarm-delay-${e.toLowerCase().replace(/\s+/g,`-`)}`}),k(`span`,{className:`text-sm text-foreground-subtle`,children:Se(n,i)})]}),k(`p`,{className:`text-xs text-foreground-subtle`,children:t})]})}function Fe(){let e=I(),t=E(),n=C({queryKey:ke,queryFn:async()=>e.trpcClient.notificationRules.getAlarmConfig.query({})}),r=C({queryKey:Ae,queryFn:async()=>(await e.trpcClient.notificationOutput.listTargets.query({})).map(e=>({id:e.id,name:e.name,enabled:e.enabled}))}),i=C({queryKey:je,queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({projection:`slim`})).map(e=>({id:e.id,name:e.name}))}),a=O({mutationFn:t=>e.trpcClient.notificationRules.setAlarmConfig.mutate({patch:t}),onSuccess:()=>t.invalidateQueries({queryKey:ke})}),o=S(()=>{let e=new Map;for(let t of i.data??[])e.set(t.id,t.name);return e},[i.data]);if(n.isLoading)return k(H,{icon:pe,title:`Alarm`,subtitle:`Panel delays and mode coverage.`,children:k(B,{className:`h-5 w-5 animate-spin`})});let s=n.data;if(s===void 0||n.isError)return k(H,{icon:pe,title:`Alarm`,subtitle:`Panel delays and mode coverage.`,children:k(l,{title:`Alarm settings are not available`,message:`This hub has not been updated to serve the alarm configuration yet.`})});if(s.deviceId===null)return k(H,{icon:pe,title:`Alarm`,subtitle:`Panel delays and mode coverage.`,children:k(u,{className:`p-4`,children:k(`p`,{className:`text-sm text-foreground-subtle`,children:`This installation has no alarm panel. The panel is created by the Notification Center on the hub — if this is the hub, its creation failed and the server log says why.`})})});let c=s.settings,p=a.isPending,m=r.data??[],h=c.announceTargets,g=e=>{a.mutate(e)},_=e=>{g({announceTargets:h.includes(e)?h.filter(t=>t!==e):[...h,e]})};return k(H,{icon:pe,title:`Alarm`,subtitle:`Panel delays, and what each mode actually arms.`,children:x(`div`,{className:`flex flex-col gap-4`,children:[a.isError?k(l,{title:`Could not save`,message:String(a.error)}):null,x(u,{className:`p-4`,children:[k(`h3`,{className:`text-sm font-semibold mb-3`,children:`Delays`}),x(`div`,{className:`grid gap-4 sm:grid-cols-3`,children:[k(Pe,{label:`Exit delay`,hint:`Time between arming and the mode taking effect — long enough to leave.`,value:c.exitDelaySec,max:Me,zeroMeans:`arms immediately`,disabled:p,onCommit:e=>g({exitDelaySec:e})}),k(Pe,{label:`Entry delay`,hint:`Time between a trigger and the alarm firing — long enough to reach the keypad.`,value:c.entryDelaySec,max:Me,zeroMeans:`fires immediately`,disabled:p,onCommit:e=>g({entryDelaySec:e})}),k(Pe,{label:`Triggered for`,hint:`How long the alarm stays triggered before re-arming itself.`,value:c.triggeredDurationSec,max:Ne,zeroMeans:`until disarmed`,disabled:p,onCommit:e=>g({triggeredDurationSec:e})})]})]}),x(u,{className:`p-4`,children:[x(`div`,{className:`flex items-start justify-between gap-4`,children:[x(`div`,{children:[k(`h3`,{className:`text-sm font-semibold`,children:`Announce when a mode is armed`}),k(`p`,{className:`text-xs text-foreground-subtle mt-1`,children:`Sends one notification listing the devices that mode arms — the list below, as it stands at that moment.`})]}),k(d,{checked:c.announceArm,disabled:p,onCheckedChange:e=>g({announceArm:e}),"data-testid":`alarm-announce-toggle`})]}),c.announceArm?x(`div`,{className:`mt-3 flex flex-col gap-2`,children:[m.length===0?k(`p`,{className:`text-xs text-foreground-subtle`,children:`No notification targets are configured — nothing can be sent.`}):m.map(e=>x(`label`,{className:`flex items-center gap-2 text-sm`,children:[k(`input`,{type:`checkbox`,checked:h.includes(e.id),disabled:p,onChange:()=>_(e.id),"data-testid":`alarm-target-${e.id}`}),k(`span`,{children:e.name}),e.enabled?null:k(f,{variant:`warning`,children:`disabled`})]},e.id)),h.length===0?k(`p`,{className:`text-xs text-warning`,children:`No target selected — the announcement will not be sent.`}):null]}):null]}),x(u,{className:`p-4`,children:[k(`h3`,{className:`text-sm font-semibold mb-1`,children:`What each mode arms`}),k(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Derived from the enabled rules gated on this panel. Nothing here is stored — change a rule and this changes with it.`}),k(`div`,{className:`flex flex-col gap-2`,"data-testid":`alarm-coverage`,children:s.coverage.map(e=>x(`div`,{className:`flex items-start gap-3 rounded border border-border p-2`,"data-mode":e.mode,"data-empty":Ee(e)?`true`:`false`,children:[k(`div`,{className:`w-20 shrink-0 text-sm font-medium`,children:xe(e.mode)}),x(`div`,{className:`flex-1 text-sm text-foreground-subtle`,children:[Ce(e,o),e.skippedDevices.length>0?k(`div`,{className:`mt-0.5 text-xs text-warning`,"data-testid":`alarm-skipped`,children:we(e.skippedDevices,o)}):null]}),Ee(e)?k(he,{className:`h-4 w-4 shrink-0 text-warning`}):null]},e.mode))})]})]})})}b();var Ie=[{value:1,label:`Last hour`},{value:24,label:`Last 24 hours`},{value:168,label:`Last 7 days`},{value:0,label:`All time`}],Le=[{value:``,label:`Any status`},{value:`pending`,label:`Pending`},{value:`sent`,label:`Sent`},{value:`dead`,label:`Dead`}],Re=[50,100,250,500];function ze(){return{ruleId:``,deviceId:``,status:``,windowHours:24,limit:100}}function Be(e){return e===`pending`||e===`sent`||e===`dead`?e:void 0}function Ve(e){switch(e){case`pending`:return`info`;case`sent`:return`success`;case`dead`:return`danger`}}function He(){let e=I(),[t,n]=D(ze),i=e=>n(t=>({...t,...e})),a=C({queryKey:[`notificationRules`,`listRules`,`forHistory`],queryFn:async()=>(await e.trpcClient.notificationRules.listRules.query({})).rules}),o=C({queryKey:[`deviceManager`,`listAll`,`forHistory`],queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({})).filter(e=>e.type===M.Camera).map(e=>({id:e.id,name:e.name}))}),s=Date.now(),c=C({queryKey:[`notificationRules`,`getHistory`,t],retry:!1,queryFn:async()=>{let n=t.windowHours>0?s-t.windowHours*36e5:void 0;return(await e.trpcClient.notificationRules.getHistory.query({filter:{limit:t.limit,...t.ruleId?{ruleId:t.ruleId}:{},...t.deviceId?{deviceId:Number(t.deviceId)}:{},...Be(t.status)?{status:Be(t.status)}:{},...n===void 0?{}:{since:n}}})).entries}}),l=S(()=>{let e=new Map;for(let t of o.data??[])e.set(t.id,t.name);return e},[o.data]),d=e=>l.get(e)??`Camera #${String(e)}`,f=c.data??[],p=c.isError;return x(H,{icon:ve,title:`Delivery history`,subtitle:`A searchable log of every notification the rules delivered (or failed to deliver).`,children:[x(`div`,{className:`mb-4 grid grid-cols-2 gap-2 sm:grid-cols-5`,children:[x(`div`,{children:[k(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Rule`}),k(m,{value:t.ruleId,onChange:e=>i({ruleId:e.target.value}),options:[{value:``,label:`All rules`},...(a.data??[]).map(e=>({value:e.id,label:e.name}))]})]}),x(`div`,{children:[k(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Camera`}),k(m,{value:t.deviceId,onChange:e=>i({deviceId:e.target.value}),options:[{value:``,label:`All cameras`},...(o.data??[]).map(e=>({value:String(e.id),label:e.name}))]})]}),x(`div`,{children:[k(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Status`}),k(m,{value:t.status,onChange:e=>i({status:e.target.value}),options:Le.map(e=>({value:e.value,label:e.label}))})]}),x(`div`,{children:[k(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Window`}),k(m,{value:String(t.windowHours),onChange:e=>i({windowHours:Number(e.target.value)}),options:Ie.map(e=>({value:String(e.value),label:e.label}))})]}),x(`div`,{children:[k(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Limit`}),k(m,{value:String(t.limit),onChange:e=>i({limit:Number(e.target.value)}),options:Re.map(e=>({value:String(e),label:String(e)}))})]})]}),c.isLoading&&k(`div`,{className:`flex items-center justify-center py-16`,children:k(B,{className:`h-6 w-6 animate-spin text-primary`})}),p&&!c.isLoading&&k(u,{children:x(`div`,{className:`flex flex-col items-center gap-2 px-4 py-14 text-center`,children:[k(ve,{className:`h-6 w-6 text-foreground-subtle`}),k(`div`,{className:`text-sm font-medium text-foreground`,children:`Delivery history requires a server update`}),k(`p`,{className:`max-w-md text-xs text-foreground-subtle`,children:`The history query is not available on this hub yet. It becomes queryable after the next server update ships the notification-center history endpoint. Rules still deliver and record their outcome in the meantime.`}),x(`button`,{type:`button`,onClick:()=>void c.refetch(),className:`mt-1 inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:[k(ae,{className:`h-3 w-3`}),` Retry`]})]})}),!p&&!c.isLoading&&f.length===0&&k(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:`No deliveries match these filters.`}),!p&&f.length>0&&k(u,{children:k(r,{columns:Ue(d),rows:f,rowKey:e=>e.id,minWidthPx:720,bordered:!1})})]})}function Ue(e){return[{key:`when`,header:`When`,nowrap:!0,render:e=>k(`span`,{className:`text-[11px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})},{key:`rule`,header:`Rule`,render:e=>k(`span`,{className:`text-xs font-medium text-foreground`,children:e.ruleName})},{key:`camera`,header:`Camera`,nowrap:!0,render:t=>k(`span`,{className:`text-[11px] text-foreground-subtle`,children:e(t.deviceId)})},{key:`subject`,header:`Subject`,render:e=>x(`span`,{className:`text-[11px] text-foreground-subtle`,children:[e.subject.label??e.subject.className,e.subject.confidence===void 0?``:` · ${Math.round(e.subject.confidence*100)}%`]})},{key:`status`,header:`Status`,nowrap:!0,render:e=>x(`span`,{className:`flex items-center gap-1.5`,children:[k(f,{variant:Ve(e.status),children:e.status}),e.attempts>1?x(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`×`,e.attempts]}):null]})},{key:`error`,header:`Detail`,render:e=>e.error?k(`span`,{className:`text-[11px] text-danger`,children:e.error}):k(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`})}]}function We(e){let t=[],n=e.find(e=>e.type===M.AlarmPanel);n!==void 0&&t.push({id:`trigger-alarm`,label:`Trigger the alarm`,hint:`Presses ${n.name}. The panel's entry delay still runs, and a disarm during it cancels the alarm.`,build:()=>({name:`trigger the alarm`,enabled:!0,actions:[{kind:`cap`,deviceId:n.id,cap:`alarm-panel`,method:`trigger`,args:{}}]})});for(let n of e.filter(e=>e.type===M.Siren))t.push({id:`siren-${String(n.id)}`,label:`Sound ${n.name}`,hint:`On, 30 seconds, off. A siren left on by a failed step is the one this sequence exists to avoid.`,build:()=>({name:`sound ${n.name}`.toLowerCase(),enabled:!0,minDelaySec:60,actions:[{kind:`cap`,deviceId:n.id,cap:`switch`,method:`setState`,args:{on:!0}},{kind:`wait`,seconds:30},{kind:`cap`,deviceId:n.id,cap:`switch`,method:`setState`,args:{on:!1}}]})});return t}function Ge(e,t){let n=t.build(),r=new Set(e.sequences.map(e=>e.name.trim())),i=n.name;for(let e=2;r.has(i);e+=1)i=`${n.name} ${String(e)}`;return{...e,sequences:[...e.sequences,{...n,name:i}]}}var Ke=[{value:`acknowledge`,label:`Acknowledge`},{value:`dismiss`,label:`Dismiss`},{value:`silence`,label:`Silence`},{value:`view`,label:`View`},{value:`play`,label:`Play`},{value:`open`,label:`Open`},{value:`close`,label:`Close`},{value:`unlock`,label:`Unlock`},{value:`lock`,label:`Lock`},{value:`disarm`,label:`Disarm`},{value:`arm`,label:`Arm`},{value:`light`,label:`Light`},{value:`alert`,label:`Alert`}],qe={sequences:[],buttons:[]};function Je(e){return e===void 0?qe:{sequences:[...e.onTrigger??[]],buttons:[...e.buttons??[]]}}function Ye(e){let t=e.sequences.filter(e=>e.name.trim()!==``),n=e.buttons.filter(e=>e.id.trim()!==``&&e.label.trim()!==``);if(!(t.length===0&&n.length===0))return{...t.length>0?{onTrigger:t}:{},...n.length>0?{buttons:n}:{}}}function Xe(e){let t=[],n=new Set;for(let r of e.sequences){let e=r.name.trim();e!==``&&(n.has(e)&&t.push({kind:`duplicate-sequence`,message:`Two sequences are called "${e}". The name is how a button points at one, and how its throttle is keyed.`}),n.add(e),r.actions.length===0&&t.push({kind:`empty-sequence`,message:`"${e}" has no steps, so it would do nothing.`}))}let r=new Set;for(let i of e.buttons){let e=i.id.trim();e!==``&&(r.has(e)&&t.push({kind:`duplicate-button`,message:`Two buttons share the id "${e}". The id is what the audit line names when one is tapped.`}),r.add(e),n.has(i.sequence.trim())||t.push({kind:`unknown-sequence`,message:`"${i.label||e}" points at the sequence "${i.sequence}", which this rule does not have. It would never appear on a notification.`}))}return t}function Ze(e){return{name:`sequence ${String(e+1)}`,enabled:!1,actions:[]}}function Qe(e,t){return{id:`action-${String(e+1)}`,label:`Action`,sequence:t}}function $e(){return{kind:`wait`,seconds:5}}var U=`mt-1 w-full rounded border border-border bg-background px-2 py-1 text-xs`,W=`block text-[11px] font-medium text-foreground`;function et({value:e,onChange:t,devices:n}){let r=Xe(e),i=We(n),a=(n,r)=>t({...e,sequences:e.sequences.map((e,t)=>t===n?r:e)}),o=(n,r)=>t({...e,buttons:e.buttons.map((e,t)=>t===n?r:e)});return x(`div`,{className:`space-y-4`,children:[r.length>0&&k(`div`,{className:`space-y-1 rounded-md border border-warning/40 bg-warning/10 px-3 py-2 text-[11px] text-warning`,children:r.map(e=>k(`p`,{children:e.message},e.message))}),x(`section`,{className:`space-y-2`,children:[x(`div`,{className:`flex items-center justify-between`,children:[x(`div`,{children:[k(`h4`,{className:`text-xs font-semibold text-foreground`,children:`What this rule does`}),k(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Runs when the rule matches. A sequence stops at the first failed step, and its own delay limits how often it may physically run — separate from the notification cooldown.`})]}),x(`div`,{className:`flex items-center gap-1`,children:[i.map(n=>x(v,{size:`sm`,variant:`ghost`,type:`button`,title:n.hint,onClick:()=>t(Ge(e,n)),children:[k(ce,{className:`h-3.5 w-3.5`}),` `,n.label]},n.id)),x(v,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t({...e,sequences:[...e.sequences,Ze(e.sequences.length)]}),children:[k(R,{className:`h-3.5 w-3.5`}),` Sequence`]})]})]}),e.sequences.length===0?k(`p`,{className:`rounded border border-border px-3 py-2 text-[11px] text-foreground-subtle`,children:`This rule actuates nothing — it only notifies.`}):e.sequences.map((r,i)=>k(tt,{sequence:r,devices:n,onChange:e=>a(i,e),onRemove:()=>t({...e,sequences:e.sequences.filter((e,t)=>t!==i)})},`seq-${String(i)}`))]}),x(`section`,{className:`space-y-2`,children:[x(`div`,{className:`flex items-center justify-between`,children:[x(`div`,{children:[k(`h4`,{className:`text-xs font-semibold text-foreground`,children:`Buttons on the notification`}),k(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Each button runs one of the sequences above when tapped.`})]}),x(v,{size:`sm`,variant:`ghost`,type:`button`,disabled:e.sequences.length===0,onClick:()=>t({...e,buttons:[...e.buttons,Qe(e.buttons.length,e.sequences[0]?.name??``)]}),children:[k(R,{className:`h-3.5 w-3.5`}),` Button`]})]}),e.buttons.length>0&&x(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/40 bg-warning/10 px-3 py-2 text-[11px] text-warning`,children:[k(he,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),x(`span`,{children:[`A button's link travels inside the notification — through ntfy, a push relay, anyone it is forwarded to. The link is the only authority: it does not check who taps it. Anyone holding the notification can run the button `,k(`strong`,{children:`once`}),`, within 15 minutes. Do not add one for something you would not want a forwarded screenshot to do.`]})]}),e.sequences.length===0?k(`p`,{className:`rounded border border-border px-3 py-2 text-[11px] text-foreground-subtle`,children:`Add a sequence first — a button runs one, it does not define its own steps.`}):e.buttons.length===0?k(`p`,{className:`rounded border border-border px-3 py-2 text-[11px] text-foreground-subtle`,children:`No buttons. The notification arrives with nothing to tap.`}):e.buttons.map((n,r)=>k(it,{button:n,sequenceNames:e.sequences.map(e=>e.name),onChange:e=>o(r,e),onRemove:()=>t({...e,buttons:e.buttons.filter((e,t)=>t!==r)})},`btn-${String(r)}`))]})]})}function tt({sequence:e,devices:t,onChange:n,onRemove:r}){let i=(t,r)=>n({...e,actions:e.actions.map((e,n)=>n===t?r:e)});return x(`div`,{className:`space-y-2 rounded-md border border-border p-3`,children:[x(`div`,{className:`flex flex-wrap items-end gap-2`,children:[x(`div`,{className:`min-w-0 flex-1`,children:[k(`label`,{className:W,children:`Name`}),k(g,{className:`mt-1`,value:e.name,onChange:t=>n({...e,name:t.target.value})})]}),x(`div`,{className:`w-28`,children:[k(`label`,{className:W,children:`Min delay (s)`}),k(`input`,{type:`number`,min:0,className:U,value:e.minDelaySec??``,onChange:t=>{let r=t.target.value,i={...e};r===``?delete i.minDelaySec:i.minDelaySec=Number(r),n(i)}})]}),x(`div`,{className:`flex items-center gap-2 pb-1`,children:[k(d,{checked:e.enabled,onCheckedChange:t=>n({...e,enabled:t})}),k(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.enabled?`Runs on match`:`Only when a button is tapped`})]}),k(v,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,title:`Remove`,children:k(V,{className:`h-3.5 w-3.5`})})]}),x(`div`,{className:`space-y-2 border-l-2 border-border-subtle pl-3`,children:[e.actions.map((r,a)=>k(nt,{step:r,devices:t,onChange:e=>i(a,e),onRemove:()=>n({...e,actions:e.actions.filter((e,t)=>t!==a)})},`step-${String(a)}`)),x(v,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>n({...e,actions:[...e.actions,$e()]}),children:[k(R,{className:`h-3.5 w-3.5`}),` Step`]})]})]})}function nt({step:e,devices:t,onChange:n,onRemove:r}){return x(`div`,{className:`flex flex-wrap items-end gap-2`,children:[x(`div`,{className:`w-24`,children:[k(`label`,{className:W,children:`Step`}),x(`select`,{className:U,value:e.kind,onChange:e=>n(e.target.value===`wait`?{kind:`wait`,seconds:5}:{kind:`cap`,deviceId:t[0]?.id??0,cap:``,method:``}),children:[k(`option`,{value:`cap`,children:`Do`}),k(`option`,{value:`wait`,children:`Wait`})]})]}),e.kind===`wait`?x(`div`,{className:`w-28`,children:[k(`label`,{className:W,children:`Seconds`}),k(`input`,{type:`number`,min:0,max:300,className:U,value:e.seconds,onChange:e=>n({kind:`wait`,seconds:Number(e.target.value)})})]}):k(rt,{step:e,devices:t,onChange:n}),k(v,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,title:`Remove step`,children:k(V,{className:`h-3.5 w-3.5`})})]})}function rt({step:e,devices:t,onChange:n}){let r=I(),i=C({queryKey:[`deviceManager`,`getBindings`,e.deviceId],enabled:e.deviceId>0,staleTime:6e4,queryFn:async()=>{let t=await r.trpcClient.deviceManager.getBindings.query({deviceId:e.deviceId});return[...new Set(t.entries.map(e=>e.capName))].sort((e,t)=>e.localeCompare(t))}}).data??[];return x(w,{children:[x(`div`,{className:`min-w-[9rem] flex-1`,children:[k(`label`,{className:W,children:`Device`}),x(`select`,{className:U,value:String(e.deviceId),onChange:t=>n({...e,deviceId:Number(t.target.value),cap:``}),children:[k(`option`,{value:`0`,children:`Select…`}),t.map(e=>k(`option`,{value:String(e.id),children:e.name},e.id))]})]}),x(`div`,{className:`min-w-[8rem] flex-1`,children:[k(`label`,{className:W,children:`Capability`}),x(`select`,{className:U,value:e.cap,disabled:i.length===0,onChange:t=>n({...e,cap:t.target.value,method:``}),children:[k(`option`,{value:``,children:i.length===0?`No devices bound`:`Select…`}),i.map(e=>k(`option`,{value:e,children:e},e))]})]}),x(`div`,{className:`min-w-[7rem] flex-1`,children:[k(`label`,{className:W,children:`Method`}),k(g,{className:`mt-1`,value:e.method,placeholder:`arm`,onChange:t=>n({...e,method:t.target.value})})]}),x(`div`,{className:`min-w-[8rem] flex-1`,children:[k(`label`,{className:W,children:`Arguments (JSON)`}),k(g,{className:`mt-1`,value:e.args===void 0?``:JSON.stringify(e.args),placeholder:`{"mode":"away"}`,onChange:t=>{let r=t.target.value.trim();if(r===``){let t={...e};delete t.args,n(t);return}try{let t=JSON.parse(r);typeof t==`object`&&t&&!Array.isArray(t)&&n({...e,args:t})}catch{}}})]})]})}function it({button:e,sequenceNames:t,onChange:n,onRemove:r}){return x(`div`,{className:`flex flex-wrap items-end gap-2 rounded-md border border-border p-3`,children:[x(`div`,{className:`min-w-[7rem] flex-1`,children:[k(`label`,{className:W,children:`Label`}),k(g,{className:`mt-1`,value:e.label,onChange:t=>n({...e,label:t.target.value})})]}),x(`div`,{className:`min-w-[8rem] flex-1`,children:[k(`label`,{className:W,children:`Runs`}),x(`select`,{className:U,value:e.sequence,onChange:t=>n({...e,sequence:t.target.value}),children:[!t.includes(e.sequence)&&x(`option`,{value:e.sequence,children:[e.sequence,` (missing)`]}),t.map(e=>k(`option`,{value:e,children:e},e))]})]}),x(`div`,{className:`w-32`,children:[k(`label`,{className:W,children:`Icon`}),x(`select`,{className:U,value:e.icon??``,onChange:t=>{let r={...e};if(t.target.value===``)delete r.icon;else{let e=Ke.find(e=>e.value===t.target.value);e!==void 0&&(r.icon=e.value)}n(r)},children:[k(`option`,{value:``,children:`None`}),Ke.map(e=>k(`option`,{value:e.value,children:e.label},e.value))]})]}),x(`div`,{className:`flex items-center gap-2 pb-1`,children:[k(d,{checked:e.destructive===!0,onCheckedChange:t=>{let r={...e};t?r.destructive=!0:delete r.destructive,n(r)}}),k(f,{variant:e.destructive===!0?`danger`:`default`,children:`Destructive style`})]}),k(v,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,title:`Remove`,children:k(V,{className:`h-3.5 w-3.5`})})]})}var at={search:``,types:[],selectedOnly:!1};function ot(e){let t=new Map;for(let n of e)t.set(n.type,(t.get(n.type)??0)+1);return[...t.entries()].map(([e,t])=>({type:e,count:t})).sort((e,t)=>t.count-e.count||e.type.localeCompare(t.type))}function st(e,t,n){let r=new Set(n),i=t.search.trim().toLowerCase(),a=new Set(t.types);return e.filter(e=>r.has(e.id)?!0:!(t.selectedOnly||a.size>0&&!a.has(e.type)||i!==``&&!e.name.toLowerCase().includes(i)))}function ct(e){let t=new Map,n=[];for(let r of e){if(r.location===null||r.location===``){n.push(r);continue}let e=t.get(r.location)??[];e.push(r),t.set(r.location,e)}let r=[...t.entries()].sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({location:e,devices:[...t].sort((e,t)=>e.name.localeCompare(t.name))}));return n.length>0&&r.push({location:null,devices:[...n].sort((e,t)=>e.name.localeCompare(t.name))}),r}function lt(e,t){let n=new Set(t);for(let t of e)n.add(t.id);return[...n]}function ut(e,t){let n=new Set(e.map(e=>e.id));return t.filter(e=>!n.has(e))}function dt(e,t){return e.length===0?`Every device (${String(t)}) — no restriction`:`${String(e.length)} of ${String(t)} selected`}b();function ft({devices:e,value:t,onChange:n,loading:r=!1}){let[i,a]=D(at),o=S(()=>ot(e),[e]),s=S(()=>st(e,i,t),[e,i,t]),c=S(()=>ct(s),[s]),l=e=>a(t=>({...t,types:t.types.includes(e)?t.types.filter(t=>t!==e):[...t.types,e]})),u=e=>n(t.includes(e)?t.filter(t=>t!==e):[...t,e]);return r?k(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Loading devices…`}):x(`div`,{className:`space-y-3`,children:[x(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[k(`p`,{className:`text-[11px] text-foreground-subtle`,children:dt(t,e.length)}),x(`div`,{className:`flex items-center gap-1`,children:[k(v,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>n(lt(s,t)),children:`Select shown`}),k(v,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>n(ut(s,t)),children:`Clear shown`})]})]}),x(`div`,{className:`flex flex-wrap items-center gap-2`,children:[k(g,{className:`min-w-[10rem] flex-1`,value:i.search,placeholder:`Search by name…`,leftSlot:k(se,{className:`h-3.5 w-3.5 text-foreground-subtle`}),onChange:e=>a(t=>({...t,search:e.target.value}))}),x(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[k(`input`,{type:`checkbox`,checked:i.selectedOnly,onChange:e=>a(t=>({...t,selectedOnly:e.target.checked}))}),`Selected only`]})]}),k(`div`,{className:`flex flex-wrap gap-1`,children:o.map(e=>x(`button`,{type:`button`,onClick:()=>l(e.type),className:i.types.includes(e.type)?`rounded-full border border-primary bg-primary/10 px-2 py-0.5 text-[10px] text-foreground`:`rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-muted hover:bg-surface-hover`,children:[e.type,` `,k(`span`,{className:`text-foreground-subtle`,children:e.count})]},e.type))}),s.length===0?k(`p`,{className:`rounded border border-border px-3 py-2 text-[11px] text-foreground-subtle`,children:`No device matches this filter.`}):k(`div`,{className:`max-h-72 space-y-2 overflow-y-auto`,children:c.map(e=>x(`div`,{children:[k(`p`,{className:`px-1 pb-1 text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e.location??`No location`}),k(`div`,{className:`divide-y divide-border rounded-md border border-border`,children:e.devices.map(e=>x(`label`,{className:`flex cursor-pointer items-center gap-2.5 px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover`,children:[k(`input`,{type:`checkbox`,checked:t.includes(e.id),onChange:()=>u(e.id),className:`accent-primary`}),k(`span`,{className:`flex-1 truncate`,children:e.name}),k(f,{variant:`default`,children:e.type})]},e.id))})]},e.location??`__unplaced`))})]})}function G(e){return t=>Object.prototype.hasOwnProperty.call(e,t)}var pt=G({devices:!0}),mt=G({classes:!0,classesExclude:!0,labelEquals:!0,identities:!0,identitiesExclude:!0,eventTypeTokens:!0,sensorKinds:!0}),ht=G({zonesExclude:!0}),gt=G({minConfidence:!0,minImportance:!0,minLabelConfidence:!0}),_t=G({minDwellSeconds:!0}),vt=G({source:!0}),yt=G({crossing:!0}),bt=G({packagePhase:!0}),xt=G({zones:!0}),St=G({plates:!0}),Ct=G({occupancy:!0}),wt=G({systemEvent:!0}),Tt=G({deviceState:!0});function Et(e,t){let n=e[t];return Array.isArray(n)?n:[]}function Dt(e,t){let n=e[t];return typeof n==`number`?n:void 0}var Ot=[{id:`system`,label:`System events`},{id:`scope`,label:`Scope`},{id:`class`,label:`Classes`},{id:`zones`,label:`Zones`},{id:`quality`,label:`Quality`},{id:`label`,label:`Identity & plates`},{id:`device`,label:`Device event`},{id:`package`,label:`Package`},{id:`occupancy`,label:`Occupancy`},{id:`schedule`,label:`Schedule`}];function kt(e){let t=e.replace(/[-_]/g,` `);return t.charAt(0).toUpperCase()+t.slice(1)}function At(e,t){let n=e.filter(t),r=new Set(Ot.map(e=>e.id)),i=[];for(let e of Ot){let t=n.filter(t=>t.group===e.id);t.length>0&&i.push({id:e.id,label:e.label,descriptors:t})}let a=[];for(let e of n)r.has(e.group)||a.includes(e.group)||a.push(e.group);for(let e of a)i.push({id:e,label:kt(e),descriptors:n.filter(t=>t.group===e)});return i}b();function jt(e,t){let n=I().trpcClient,r=T({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 S(()=>{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)}},[r,t])}function Mt(e){let t=I().trpcClient,n=T({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 S(()=>{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 Nt(){let e=i();return S(()=>({options:(e.data??[]).map(e=>({value:e.name,label:e.name})),loading:e.isLoading}),[e.data,e.isLoading])}function Pt(){let e=c({limit:200});return S(()=>{let t=new Set;for(let n of e.data??[])n.text.trim().length>0&&t.add(n.text);return[...t].sort()},[e.data])}function K({options:e,value:t,onChange:n,loading:r,emptyHint:i,placeholder:a,noFreeText:o=!1}){let[s,c]=D(``),l=S(()=>new Set(e.map(e=>e.value)),[e]),u=S(()=>new Set(t),[t]),d=t.filter(e=>!l.has(e)),f=e=>{n(u.has(e)?t.filter(t=>t!==e):[...t,e])},p=()=>{let e=s.trim();e.length===0||t.includes(e)||(n([...t,e]),c(``))};return x(`div`,{className:`mt-1 space-y-1.5`,children:[d.length>0&&k(`div`,{className:`flex flex-wrap gap-1`,children:d.map(e=>x(`button`,{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:`Custom value — click to remove`,children:[e,` ×`]},e))}),e.length>0?k(`div`,{className:`max-h-40 overflow-y-auto rounded-md border border-border divide-y divide-border`,children:e.map(e=>x(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[k(`input`,{type:`checkbox`,checked:u.has(e.value),onChange:()=>f(e.value),className:`accent-primary`}),k(`span`,{className:`flex-1 truncate`,children:e.label}),e.hint!==void 0&&k(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.hint})]},e.value))}):k(`p`,{className:`text-[10px] text-foreground-subtle`,children:r===!0?`Loading…`:i}),!o&&k(`input`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),p())},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 Ft=[{value:`immediate`,label:`Immediate`,hint:`Fires on the first matching detection of a track (lowest latency).`},{value:`track-end`,label:`Track end`,hint:`Evaluates the finalised track record when it closes.`},{value:`device-event`,label:`Device event`,hint:`Doorbell press / sensor state change on a linked device.`},{value:`package-event`,label:`Package event`,hint:`A parcel delivery or pick-up.`},{value:`system-event`,label:`System event`,hint:`The installation itself: a camera or stream going offline, a node leaving the cluster, an addon or server update becoming available.`}];function It(e){return Ft.find(t=>t.value===e)?.label??e}function Lt(e){return Ft.find(t=>t.value===e)?.value}function Rt(e){return Ft.some(t=>t.value===e)}function q(e){return e===`system-event`}var zt=[{key:`all`,label:`All rules`,blurb:`Every notification rule, whatever its trigger. Each rule picks a trigger, matches conditions and fans out to one or more delivery targets.`},{key:`detection`,label:`Detections & devices`,blurb:`Rules driven by what the cameras and sensors SEE — detections, tracks, doorbell presses and package events.`},{key:`system`,label:`System events`,blurb:`Rules about the installation itself: a camera or stream dropping, a node leaving the cluster, an addon or server update becoming available. These carry no image and are not tied to a detection.`}];function Bt(e){return zt.find(t=>t.key===e)?.key}function Vt(e,t){return t===`all`?!0:t===`system`?q(e):!q(e)}function Ht(e){return e===`system`?`system-event`:`immediate`}var Ut=[{value:0,label:`No cooldown`},{value:30,label:`30 seconds`},{value:60,label:`1 minute`},{value:300,label:`5 minutes`},{value:600,label:`10 minutes`},{value:1800,label:`30 minutes`},{value:3600,label:`1 hour`}];function Wt(e){let t=Ut.find(t=>t.value===e);return t?t.label:e%3600==0?`${e/3600} hours`:e%60==0?`${e/60} minutes`:`${e} seconds`}function Gt(e){return Ut.some(t=>t.value===e)?Ut:[...Ut,{value:e,label:Wt(e)}].toSorted((e,t)=>e.value-t.value)}function Kt(e){if(e.trim().length===0)return;let t=Number(e);return Number.isFinite(t)&&t>=0?t:void 0}var qt=[{value:`best`,label:`Best available image`,description:`The best subject crop available when the notification is sent.`},{value:`best-matching`,label:`Best matching image`,description:`The image that explains why the rule fired — the face crop for an identity rule, the plate crop for a plate rule; falls back to the best image otherwise.`},{value:`keyFrame`,label:`Key frame`,description:`The clean full scene frame with no subject box.`},{value:`none`,label:`No attachment`,description:`Send the notification with no image.`}];function Jt(e){return qt.find(t=>t.value===e)?.value}var Yt=[{value:``,label:`Automatic`},{value:`cropped`,label:`Cropped on the subject`},{value:`full`,label:`Full frame`},{value:`boxed`,label:`Full frame with boxes`}];function Xt(e){let t=Yt.find(t=>t.value===e)?.value;return t===``?void 0:t}var Zt=[{value:``,label:`Lowest available`},{value:`low`,label:`Low`},{value:`mid`,label:`Medium`},{value:`high`,label:`High`}];function Qt(e){let t=Zt.find(t=>t.value===e)?.value;return t===``?void 0:t}var $t=[{value:`any`,label:`Any source`},{value:`pipeline`,label:`Pipeline`},{value:`onboard`,label:`Onboard (camera)`},{value:`sensor`,label:`Sensor`}],en=[{value:`delivered`,label:`Delivered`},{value:`picked-up`,label:`Picked up`},{value:`both`,label:`Both`}],tn=[{value:``,label:`Not set — entering`,hint:`Entries, and every detection that is not a crossing at all. Exits are excluded. This is what a rule without a crossing condition already does, and choosing it writes nothing to the rule.`},{value:`enter`,label:`Entered a zone`,hint:`The same matches as "not set", stated explicitly: entries and non-crossing detections pass, exits do not.`},{value:`exit`,label:`Left a zone`,hint:`ONLY an exit crossing. A detection that is not a crossing fails, so this rule cannot fire on ordinary movement — pair it with the zones the subject must have left.`},{value:`any`,label:`Entered or left`,hint:`No direction filter: entries, exits and non-crossing detections alike. This is the only choice that adds exits to what the rule already matched.`}];function nn(e){let t=tn.find(t=>t.value===e)?.value;return t===``||t===void 0?void 0:t}var rn=[{value:`any`,label:`Any of`},{value:`all`,label:`All of`}],an=[{value:1,label:`1 — Min`},{value:2,label:`2 — Low`},{value:3,label:`3 — Default`},{value:4,label:`4 — High`},{value:5,label:`5 — Max`}];function on(e=`immediate`){return{name:``,enabled:!0,delivery:e,targetIds:[],targetUsers:[],targetParams:{},priority:3,mediaAttach:`best`,mediaZoneCrop:!1,mediaFrame:void 0,mediaGif:!1,mediaClip:!1,mediaProfile:void 0,mediaClipSpeed:void 0,templateTitle:``,templateBody:``,conditions:{},schedule:void 0,snoozeAllowGlobal:!1,actions:qe,deviceIds:[],cooldownSec:60}}function sn(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,enabled:e.enabled,delivery:e.delivery,targetIds:e.targets.map(e=>e.targetId),targetUsers:e.targetUsers??[],targetParams:t,priority:e.priority,mediaAttach:e.media.attach,mediaZoneCrop:e.media.zoneCrop===!0,mediaFrame:e.media.frame,mediaGif:e.media.gif===!0,mediaClip:e.media.clip===!0,mediaProfile:e.media.profile,mediaClipSpeed:e.media.clipSpeed,templateTitle:e.template?.title??``,templateBody:e.template?.body??``,conditions:e.conditions,schedule:e.schedule,snoozeAllowGlobal:e.snoozeAllowGlobal===!0,actions:Je(e.actions),deviceIds:e.conditions.devices??[],cooldownSec:e.throttle.cooldownSec}}function cn(e){return Rt(e.delivery)&&(!q(e.delivery)||ln(e)>0)&&e.name.trim().length>0&&(e.targetIds.length>0||e.targetUsers.length>0)&&Xe(e.actions).length===0}function ln(e){return e.conditions.systemEvent?.kinds.length??0}function un(e,t){return e.appliesTo.includes(t)}var dn={source:`any`};function fn(e,t){if(t==null)return!0;if(Array.isArray(t))return t.length===0;if(typeof t==`string`)return t.length===0||dn[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}function pn(e,t,n){let r=n.length===0?null:new Set(n.filter(e=>e.id!==`schedule`&&un(e,t)).map(e=>e.id)),i={};for(let[t,n]of Object.entries(e))r!==null&&!r.has(t)||fn(t,n)||(i[t]=n);return i}function mn(e){return e!==void 0&&e.windows.length>0}function hn(e,t,n=[]){let r=e.templateTitle.trim(),i=e.templateBody.trim(),a=r.length>0||i.length>0?{...r.length>0?{title:r}:{},...i.length>0?{body:i}:{}}:void 0,o=Ye(e.actions),s=(n.length===0||n.some(t=>t.id===`schedule`&&un(t,e.delivery)))&&mn(e.schedule)?e.schedule:void 0,c=n.length===0?!0:n.some(t=>t.id===`devices`&&un(t,e.delivery));return{name:e.name.trim(),enabled:e.enabled,delivery:e.delivery,conditions:{...pn(e.conditions,e.delivery,n),...c&&e.deviceIds.length>0?{devices:[...e.deviceIds]}:{}},...s?{schedule:s}:{},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]}:{},media:q(e.delivery)?{attach:`none`}:{attach:e.mediaAttach,...e.mediaZoneCrop?{zoneCrop:!0}:{},...e.mediaFrame===void 0?{}:{frame:e.mediaFrame},...e.mediaGif?{gif:!0}:{},...e.mediaClip?{clip:!0}:{},...e.mediaProfile===void 0?{}:{profile:e.mediaProfile},...e.mediaClipSpeed===void 0?{}:{clipSpeed:e.mediaClipSpeed}},throttle:{cooldownSec:e.cooldownSec,scope:t?.throttle.scope??`rule-device`},priority:e.priority,...a?{template:a}:{},...e.snoozeAllowGlobal?{snoozeAllowGlobal:!0}:{},...o===void 0?{}:{actions:o}}}function gn(e,t){return e.options&&e.options.length>0?e.options:t}var _n=[{value:``,label:`Default (2×)`},{value:`1`,label:`1× — real time`},{value:`2`,label:`2×`},{value:`3`,label:`3×`},{value:`4`,label:`4×`},{value:`6`,label:`6×`},{value:`8`,label:`8×`}];function vn(e){if(e===``)return;let t=Number(e);return Number.isFinite(t)&&t>=1&&t<=8?t:void 0}var yn=[{key:`rule`,label:`Rule`,fields:[`name`,`enabled`,`delivery`,`targetIds`,`targetUsers`,`targetParams`]},{key:`devices`,label:`Devices`,fields:[`deviceIds`]},{key:`conditions`,label:`Conditions`,fields:[`conditions`,`schedule`]},{key:`notification`,label:`Notification`,fields:[`priority`,`mediaAttach`,`mediaFrame`,`mediaZoneCrop`,`mediaGif`,`mediaClip`,`mediaProfile`,`mediaClipSpeed`,`templateTitle`,`templateBody`]},{key:`actions`,label:`Actions`,fields:[`actions`]},{key:`advanced`,label:`Advanced`,fields:[`snoozeAllowGlobal`,`cooldownSec`]}];function bn(e){return q(e)?yn.filter(e=>e.key!==`devices`).map(e=>e.key===`conditions`?{...e,label:`Events`}:e):yn}var xn=`rule`;function Sn(e){return yn.find(t=>t.key===e)?.key}b();var J=`block text-[11px] font-medium text-foreground`,Y=`text-[10px] text-foreground-subtle mt-0.5`;function Cn({cameras:e,value:t,onChange:n}){if(e.length===0)return k(`p`,{className:Y,children:`No cameras available — the rule applies to all devices.`});let r=e=>n(t.includes(e)?t.filter(t=>t!==e):[...t,e]);return k(`div`,{className:`mt-1 max-h-40 overflow-y-auto rounded-md border border-border divide-y divide-border`,children:e.map(e=>x(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[k(`input`,{type:`checkbox`,checked:t.includes(e.id),onChange:()=>r(e.id),className:`accent-primary`}),k(`span`,{className:`flex-1 truncate`,children:e.name})]},e.id))})}function wn({value:e,placeholder:t,onChange:n}){let[r,i]=D(``),a=()=>{let t=r.trim();if(t.length===0||e.includes(t)){i(``);return}n([...e,t]),i(``)},o=t=>n(e.filter(e=>e!==t));return x(`div`,{className:`mt-1 space-y-1.5`,children:[e.length>0&&k(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>x(`span`,{className:`inline-flex items-center gap-1 rounded bg-surface-hover px-1.5 py-0.5 text-[11px] text-foreground`,children:[e,k(`button`,{type:`button`,onClick:()=>o(e),"aria-label":`remove ${e}`,className:`text-foreground-subtle hover:text-danger`,children:k(me,{className:`h-3 w-3`})})]},e))}),k(g,{value:r,placeholder:t,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),a())},onBlur:a})]})}function Tn({picker:e,value:t,onChange:n}){let r=S(()=>F(e),[e]),i=S(()=>new Set(t),[t]),a=t.filter(e=>!r.has(e)),o=e=>{n(i.has(e)?t.filter(t=>t!==e):[...t,e])};return x(`div`,{className:`space-y-2`,children:[a.length>0&&k(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>x(`button`,{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:`Custom value — click to remove`,children:[e,` ×`]},e))}),e.groups.map(e=>x(`div`,{children:[k(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-muted mb-1`,children:e.fallbackLabel}),k(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map(e=>{let t=i.has(e.value);return k(`button`,{type:`button`,"aria-pressed":t,onClick:()=>o(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 En({value:e,min:t,max:n,step:r,onChange:i}){return x(`div`,{className:`mt-1 flex items-center gap-2`,children:[k(g,{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&&k(`input`,{type:`range`,min:t,max:n,step:r,value:e,onChange:e=>i(Number(e.target.value)),className:`flex-1 accent-primary`,"aria-label":`value`})]})}function Dn({value:e,onChange:t,options:n}){let r=e??``,i=n&&n.length>0?n:tn,a=i.find(e=>e.value===r);return x(`div`,{className:`mt-1 space-y-1`,children:[k(m,{value:r,options:i.map(e=>({value:e.value,label:e.label})),onChange:e=>t(nn(e.target.value))}),a!==void 0&&k(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:a.hint})]})}function On({deviceIds:e,cameras:t,value:n,onChange:r}){let i=n?.ids??[],a=n?.match??`any`,o=e=>r(e.length>0?{ids:e,match:a}:void 0),s=e=>r(i.length>0?{ids:i,match:e}:void 0);return x(`div`,{className:`mt-1 space-y-1.5`,children:[k(`div`,{className:`max-w-[10rem]`,children:k(m,{value:a,options:rn.map(e=>({value:e.value,label:e.label})),onChange:e=>s(e.target.value===`all`?`all`:`any`)})}),k(kn,{deviceIds:e,cameras:t,value:i,onChange:o})]})}function kn({deviceIds:e,cameras:t,value:n,onChange:r}){let{options:i,loading:a}=jt(e,t);return k(K,{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 An({value:e,onChange:t}){let{options:n,loading:r}=Nt();return k(K,{options:n,value:e,onChange:t,loading:r,emptyHint:`No identities in the face gallery yet — type a name.`,placeholder:`Identity name…`})}function jn({deviceIds:e,value:t,onChange:n}){let{options:r,loading:i}=Mt(e);return k(K,{options:r,value:t,onChange:n,loading:i,emptyHint:e.length===0?`Select cameras above to pick their event kinds — or type a token.`:`No event kinds reported for the selected cameras — type a token.`,placeholder:`Event token…`})}var Mn=[{value:`became-occupied`,label:`Became occupied`},{value:`became-free`,label:`Became free`},{value:`>=`,label:`Count ≥`},{value:`<=`,label:`Count ≤`}],Nn={op:`became-occupied`,count:1,sustainSeconds:15};function Pn({deviceIds:e,cameras:t,classOptions:n,value:r,onChange:i}){let{options:a,loading:o}=jt(e,t),s=r??Nn,c=e=>i({...s,...e}),l=s.op===`became-occupied`||s.op===`became-free`;return x(`div`,{className:`mt-1 space-y-1.5`,children:[x(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[k(`div`,{className:`min-w-[10rem]`,children:k(m,{value:s.zoneId??``,options:[{value:``,label:o?`Loading zones…`:`— whole frame —`},...a.map(e=>({value:e.value,label:e.label}))],onChange:e=>c({zoneId:e.target.value===``?void 0:e.target.value})})}),k(`div`,{className:`min-w-[9rem]`,children:k(m,{value:s.className??``,options:[{value:``,label:`— any class —`},...n.map(e=>({value:e.value,label:e.label}))],onChange:e=>c({className:e.target.value===``?void 0:e.target.value})})}),k(`div`,{className:`min-w-[9rem]`,children:k(m,{value:s.op,options:Mn.map(e=>({value:e.value,label:e.label})),onChange:e=>{let t=Mn.find(t=>t.value===e.target.value);t&&c({op:t.value})}})})]}),x(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:[x(`label`,{className:`flex items-center gap-1`,children:[l?`Threshold`:`Count`,k(g,{type:`number`,min:0,className:`w-16`,value:String(s.count),onChange:e=>c({count:Math.max(0,Number(e.target.value)||0)})})]}),x(`label`,{className:`flex items-center gap-1`,children:[`Hold for`,k(g,{type:`number`,min:0,max:3600,className:`w-16`,value:String(s.sustainSeconds),onChange:e=>c({sustainSeconds:Math.min(3600,Math.max(0,Number(e.target.value)||0))})}),`s`]}),r===void 0?null:k(`button`,{type:`button`,onClick:()=>i(void 0),className:`underline hover:text-foreground`,children:`Clear`})]}),k(`p`,{className:`text-[11px] text-foreground-subtle`,children:`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.`})]})}function Fn({value:e,onChange:t}){let n=e?.values??[],r=e?.maxDistance??1,i=e=>t(e.length>0?{values:e,maxDistance:r}:void 0),a=e=>t(n.length>0?{values:n,maxDistance:e}:void 0),o=Pt().filter(e=>!n.includes(e));return x(`div`,{className:`mt-1 space-y-1.5`,children:[k(wn,{value:n,placeholder:`Plate text…`,onChange:i}),o.length>0&&x(`div`,{className:`flex flex-wrap items-center gap-1`,children:[k(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Seen:`}),o.slice(0,12).map(e=>k(`button`,{type:`button`,onClick:()=>i([...n,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))]}),x(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Max distance`,k(g,{type:`number`,min:0,max:3,step:1,value:r,className:`max-w-[5rem]`,onChange:e=>{let t=Number(e.target.value);a(Number.isFinite(t)?Math.max(0,Math.min(3,t)):1)}})]})]})}function In({gateable:e,value:t,onChange:n}){let r=e.find(e=>e.id===t?.deviceId),i=new Set(t?.states??[]),a=e=>{let t=Number(e);if(!Number.isFinite(t)||t===0)return n(void 0);n({deviceId:t,states:[]})},o=e=>{if(t===void 0)return;let r=new Set(i);r.has(e)?r.delete(e):r.add(e),n(r.size===0?void 0:{deviceId:t.deviceId,states:[...r]})};return x(`div`,{className:`mt-1 space-y-2`,children:[k(m,{value:t===void 0?``:String(t.deviceId),options:[{value:``,label:`— no device gate —`},...e.map(e=>({value:String(e.id),label:e.name}))],onChange:e=>a(e.target.value)}),r!==void 0&&k(`div`,{className:`flex flex-wrap gap-1.5`,children:r.states.map(e=>k(`button`,{type:`button`,onClick:()=>o(e),className:i.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:e},e))}),r!==void 0&&r.states.length===0&&k(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`This device reports no state the gate can read, so it cannot arm a rule.`}),t!==void 0&&k(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`The rule is silent while the device is in any other state — including when its state cannot be read at all.`})]})}var Ln=[{value:1,label:`Mon`},{value:2,label:`Tue`},{value:3,label:`Wed`},{value:4,label:`Thu`},{value:5,label:`Fri`},{value:6,label:`Sat`},{value:0,label:`Sun`}];function Rn(e){let t=Math.floor(e/60),n=e%60;return`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}`}function zn(e){let[t,n]=e.split(`:`),r=Number(t)*60+Number(n);return Number.isFinite(r)?Math.max(0,Math.min(1439,r)):0}function Bn(){return{days:[1,2,3,4,5],startMinute:540,endMinute:1080}}function Vn({value:e,onChange:t}){let n=e?.windows??[],r=e?.invert??!1,i=(n,r)=>{if(n.length===0){t(void 0);return}t({windows:n,...r?{invert:!0}:{},...e?.timezone?{timezone:e.timezone}:{}})},a=()=>i([...n,Bn()],r),o=e=>i(n.filter((t,n)=>n!==e),r),s=(e,t)=>i(n.map((n,r)=>r===e?t:n),r);return x(`div`,{className:`mt-1 space-y-2`,children:[n.length===0?k(`p`,{className:Y,children:`Always active — add a window to restrict when the rule fires.`}):n.map((e,t)=>k(Hn,{window:e,onChange:e=>s(t,e),onRemove:()=>o(t)},t)),x(`div`,{className:`flex items-center gap-3`,children:[x(`button`,{type:`button`,onClick:a,className:`flex items-center gap-1 rounded-md bg-surface-hover px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground`,children:[k(R,{className:`h-3 w-3`}),` Add window`]}),n.length>0&&x(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[k(`input`,{type:`checkbox`,checked:r,onChange:e=>i([...n],e.target.checked),className:`accent-primary`}),`Active outside the windows`]})]})]})}function Hn({window:e,onChange:t,onRemove:n}){let r=n=>{let r=e.days.includes(n)?e.days.filter(e=>e!==n):[...e.days,n];r.length!==0&&t({...e,days:r})};return x(`div`,{className:`space-y-1.5 rounded-md border border-border p-2`,children:[x(`div`,{className:`flex items-center gap-2 text-xs`,children:[k(`input`,{type:`time`,value:Rn(e.startMinute),onChange:n=>t({...e,startMinute:zn(n.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),k(`span`,{className:`text-foreground-subtle`,children:`→`}),k(`input`,{type:`time`,value:Rn(e.endMinute),onChange:n=>t({...e,endMinute:zn(n.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),k(`span`,{className:`flex-1`}),k(`button`,{type:`button`,onClick:n,"aria-label":`Remove window`,className:`text-foreground-subtle hover:text-danger`,children:k(V,{className:`h-3.5 w-3.5`})})]}),k(`div`,{className:`flex flex-wrap gap-1`,children:Ln.map(t=>k(`button`,{type:`button`,onClick:()=>r(t.value),className:`rounded px-1.5 py-0.5 text-[10px] ${e.days.includes(t.value)?`bg-primary text-primary-foreground`:`bg-surface-hover text-foreground-subtle`}`,children:t.label},t.value))})]})}var Un=[{id:`liveness`,label:`Devices & streams`,hint:`A device the hub can no longer reach, or a stream that stopped or came back.`,kinds:[{value:`device-offline`,label:`Device offline`},{value:`device-online`,label:`Device online`},{value:`stream-offline`,label:`Stream offline`},{value:`stream-online`,label:`Stream online`}]},{id:`switches`,label:`Device switch`,hint:`A device an operator turned off or back on. Not a fault — a choice.`,kinds:[{value:`device-disabled`,label:`Device switched off`},{value:`device-enabled`,label:`Device switched on`}]},{id:`nodes`,label:`Nodes`,hint:`An agent or worker node joining or leaving the cluster.`,kinds:[{value:`node-offline`,label:`Node offline`},{value:`node-online`,label:`Node online`}]},{id:`alarm`,label:`Alarm`,hint:`The alarm panel going off, being armed, or being disarmed.`,kinds:[{value:`alarm-triggered`,label:`Alarm triggered`},{value:`alarm-armed`,label:`Alarm armed`},{value:`alarm-disarmed`,label:`Alarm disarmed`}]},{id:`updates`,label:`Updates`,hint:`A newer version of an addon or of the server itself is available.`,kinds:[{value:`addon-update-available`,label:`Addon update available`},{value:`server-update-available`,label:`Server update available`}]}],Wn=Un.flatMap(e=>e.kinds);function Gn(e){return Wn.find(t=>t.value===e)?.label??e}function Kn(e){return{devices:e.some(e=>e.startsWith(`device-`)||e.startsWith(`stream-`)||e===`alarm-triggered`),deviceTypes:e.some(e=>e.startsWith(`device-`)),nodes:e.some(e=>e.startsWith(`node-`)||e===`addon-update-available`),packages:e.some(e=>e.endsWith(`update-available`))}}var qn=Object.values(M).map(e=>({value:e,label:Jn(e)})).toSorted((e,t)=>e.label.localeCompare(t.label));function Jn(e){let t=e.replaceAll(`-`,` `);return t.charAt(0).toUpperCase()+t.slice(1)}function Yn(e,t){let n=e?.kinds??[],r=n.includes(t)?n.filter(e=>e!==t):Wn.filter(e=>e.value===t||n.includes(e.value)).map(e=>e.value);if(r.length!==0)return Qn(e,r)}function Xn(e,t){let n=e?.kinds??[];if(n.length===0)return;let r=Zn(t,`deviceIds`,e?.deviceIds),i=Zn(t,`deviceTypes`,e?.deviceTypes),a=Zn(t,`nodeIds`,e?.nodeIds),o=Zn(t,`packageNames`,e?.packageNames);return{kinds:[...n],...r===void 0?{}:{deviceIds:[...r]},...i===void 0?{}:{deviceTypes:[...i]},...a===void 0?{}:{nodeIds:[...a]},...o===void 0?{}:{packageNames:[...o]}}}function Zn(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 Qn(e,t){let n=Kn(t),r=n.devices?e?.deviceIds:void 0,i=n.deviceTypes?e?.deviceTypes:void 0,a=n.nodes?e?.nodeIds:void 0,o=n.packages?e?.packageNames:void 0;return{kinds:[...t],...r&&r.length>0?{deviceIds:[...r]}:{},...i&&i.length>0?{deviceTypes:[...i]}:{},...a&&a.length>0?{nodeIds:[...a]}:{},...o&&o.length>0?{packageNames:[...o]}:{}}}function $n(e,t=2){if(e===void 0||e.length===0)return`No event selected`;let n=e.slice(0,t).map(Gn).join(`, `),r=e.length-Math.min(t,e.length);return r>0?`${n} +${r}`:n}function er(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;return r>0&&t.push(e.deviceTypes?.map(Jn).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`}`),t.length===0?`Everything`:t.join(` · `)}b();var tr=[`nc-pickers`,`nodes`],nr=[`nc-pickers`,`addon-packages`];function rr(){let e=I().trpcClient,t=C({queryKey:tr,staleTime:6e4,queryFn:async()=>(await e.nodes.topology.query()).map(e=>({value:e.id,label:e.name.length>0?e.name:e.id,hint:e.isOnline?e.id:`${e.id} · offline`}))});return{options:t.data??[],loading:t.isLoading}}function ir(){let e=I().trpcClient,t=C({queryKey:nr,staleTime:6e4,queryFn:async()=>(await e.addons.listPackages.query()).map(e=>({value:e.name,label:e.name,hint:e.version})).toSorted((e,t)=>e.label.localeCompare(t.label))});return{options:t.data??[],loading:t.isLoading}}function ar({value:e,cameras:t,onChange:n}){let r=S(()=>e?.kinds??[],[e]),i=Kn(r),a=rr(),o=ir();return x(`div`,{className:`mt-1 space-y-3`,"data-testid":`system-event-field`,children:[Un.map(t=>x(`div`,{children:[k(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:t.label}),k(`div`,{className:`mt-1 flex flex-wrap gap-1.5`,children:t.kinds.map(t=>{let i=r.includes(t.value);return k(`button`,{type:`button`,role:`checkbox`,"aria-checked":i,"aria-label":t.label,onClick:()=>n(Yn(e,t.value)),className:i?`rounded-md border border-primary bg-primary/10 px-2 py-1 text-[11px] text-primary`:`rounded-md border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:t.label},t.value)})}),k(`p`,{className:Y,children:t.hint})]},t.id)),r.length===0&&k(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-2.5 py-1.5 text-[11px] text-warning`,children:`Pick at least one event — a system rule with no event selected is never evaluated, and the hub refuses to save it.`}),i.deviceTypes&&x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Only these device types (optional)`}),k(K,{options:qn,value:e?.deviceTypes??[],onChange:t=>n(Xn(e,{deviceTypes:t})),emptyHint:`No device types listed — the rule watches every type.`,placeholder:`Device type…`}),k(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`Liveness is reported for EVERY device — cameras, plugs, sensors, the containers that hold them. Leave this empty to be told about all of them, or pick “Camera” to hear only about cameras.`})]}),i.devices&&x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Only these cameras (optional)`}),k(Cn,{cameras:t,value:e?.deviceIds??[],onChange:t=>n(Xn(e,{deviceIds:t}))}),k(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`Leave everything unchecked to watch every camera.`})]}),i.nodes&&x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Only these nodes (optional)`}),k(K,{options:a.options,value:e?.nodeIds??[],onChange:t=>n(Xn(e,{nodeIds:t})),loading:a.loading,emptyHint:`No nodes reported — the rule watches every node.`,placeholder:`Node id…`}),k(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`Leave everything unchecked to watch every node.`})]}),i.packages&&x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Only these packages (optional)`}),k(K,{options:o.options,value:e?.packageNames??[],onChange:t=>n(Xn(e,{packageNames:t})),loading:o.loading,emptyHint:`No installed packages listed — the rule watches every package.`,placeholder:`Package name…`}),k(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`Leave everything unchecked to be told about every addon and server update.`})]})]})}b();function or({catalog:e,taxonomy:t,delivery:n,conditions:r,schedule:i,cameras:a,gateable:o,onConditionsChange:s,onScheduleChange:c}){let l=(e,t)=>{let n={...r};t===void 0?delete n[e]:n[e]=t,s(n)},u=S(()=>At(e,e=>e.id!==`devices`&&cr(e,n)),[e,n]),d=S(()=>At(e,e=>e.id!==`devices`&&!cr(e,n)),[e,n]),[p,m]=D(()=>{if(lr(r,i))return!0;try{return localStorage.getItem(sr)===`1`}catch{return!1}}),h=()=>{let e=!p;m(e);try{localStorage.setItem(sr,e?`1`:`0`)}catch{}},g=e=>e.map(e=>x(`div`,{className:`space-y-2.5`,children:[k(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:e.label}),e.descriptors.map(e=>{let s=un(e,n);return x(`div`,{className:s?``:`opacity-50`,"data-testid":`condition-${e.id}`,children:[x(`div`,{className:`flex items-center justify-between gap-2`,children:[k(`label`,{className:J,children:e.label}),!s&&x(f,{variant:`default`,children:[`not for `,e.appliesTo.join(` / `)]})]}),s?k(ur,{descriptor:e,taxonomy:t,conditions:r,schedule:i,cameras:a,gateable:o,onFieldChange:l,onScheduleChange:c}):k(`p`,{className:Y,children:`Not evaluated for the selected trigger — switch the trigger to use it.`}),s&&e.description&&k(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:e.description})]},e.id)})]},e.id));return x(`div`,{className:`space-y-4`,children:[g(u),d.length>0&&k(`button`,{type:`button`,onClick:h,"data-testid":`nc-advanced-toggle`,className:`w-full rounded-md border border-border px-3 py-1.5 text-left text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:p?`▾ Hide advanced configurations`:`▸ Show more configurations`}),p&&g(d)]})}var sr=`camstack.nc.showAdvanced`;function cr(e,t){return t===`system-event`?e.id===`systemEvent`:P(e.id)}function lr(e,t){for(let[t,n]of Object.entries(e))if(!P(t)&&t!==`systemEvent`&&n!==void 0&&!(Array.isArray(n)&&n.length===0))return!0;return t!==void 0&&t.windows.length>0}function ur({descriptor:e,taxonomy:t,conditions:n,schedule:r,cameras:i,gateable:a,onFieldChange:o,onScheduleChange:s}){switch(e.valueType){case`deviceIdList`:{if(!pt(e.id))break;let t=e.id;return k(Cn,{cameras:i,value:n[t]??[],onChange:e=>o(t,e.length>0?e:void 0)})}case`stringList`:{if(!mt(e.id))break;let r=e.id,i=e=>o(r,e.length>0?e:void 0);if(r===`identities`||r===`identitiesExclude`)return k(An,{value:Et(n,r),onChange:i});if(r===`eventTypeTokens`)return k(jn,{deviceIds:n.devices??[],value:Et(n,r),onChange:i});let a=N(r,t);return a===null?k(wn,{value:Et(n,r),placeholder:`Add value…`,onChange:i}):k(Tn,{picker:a,value:Et(n,r),onChange:i})}case`zoneIdList`:{if(!ht(e.id))break;let t=e.id;return k(kn,{deviceIds:n.devices??[],cameras:i,value:Et(n,t),onChange:e=>o(t,e.length>0?e:void 0)})}case`number01`:{if(!gt(e.id))break;let t=e.id;return k(En,{value:Dt(n,t),min:0,max:1,step:.05,onChange:e=>o(t,e)})}case`number`:{if(!_t(e.id))break;let t=e.id;return k(En,{value:Dt(n,t),min:0,step:1,onChange:e=>o(t,e)})}case`sourceSelect`:{if(!vt(e.id))break;let t=e.id;return k(m,{value:n[t]??`any`,options:gn(e,$t).map(e=>({value:e.value,label:e.label})),onChange:e=>o(t,pr(e.target.value))})}case`systemEvent`:{if(!wt(e.id))break;let t=e.id;return k(ar,{value:n[t],cameras:i,onChange:e=>o(t,e)})}case`deviceState`:if(!Tt(e.id))break;return k(In,{gateable:a,value:n.deviceState,onChange:e=>o(`deviceState`,e)});case`crossingSelect`:{if(!yt(e.id))break;let t=e.id;return k(Dn,{value:n[t],onChange:e=>o(t,e),...e.options?{options:e.options}:{}})}case`packagePhase`:{if(!bt(e.id))break;let t=e.id;return k(m,{value:n[t]??``,options:[{value:``,label:`— any phase —`},...gn(e,en).map(e=>({value:e.value,label:e.label}))],onChange:e=>o(t,mr(e.target.value))})}case`zoneSelection`:{if(!xt(e.id))break;let t=e.id;return k(On,{deviceIds:n.devices??[],cameras:i,value:n[t],onChange:e=>o(t,e)})}case`plateMatcher`:{if(!St(e.id))break;let t=e.id;return k(Fn,{value:n[t],onChange:e=>o(t,e)})}case`occupancy`:{if(!Ct(e.id))break;let r=e.id;return k(Pn,{deviceIds:n.devices??[],cameras:i,classOptions:dr(t),value:n[r],onChange:e=>o(r,e)})}case`schedule`:return k(Vn,{value:r,onChange:s});default:break}return k(fr,{descriptor:e,conditions:n})}function dr(e){let t=N(`classes`,e);return t===null?[]:t.groups.flatMap(e=>e.options)}function fr({descriptor:e,conditions:t}){let n=Object.entries(t).find(([t])=>t===e.id);return x(`p`,{className:Y,children:[n!==void 0&&n[1]!==void 0?`Authored elsewhere and preserved — this admin editor cannot change it yet.`:`Not editable here yet — this condition has no admin editor.`,` `,x(`span`,{className:`text-foreground-muted`,children:[`(`,e.valueType,`)`]})]})}function pr(e){if(e===`pipeline`||e===`onboard`||e===`sensor`||e===`any`)return e}function mr(e){return en.find(t=>t.value===e)?.value}b();var hr=[`notificationRules`,`listSnoozes`],gr=3e4;function _r(e,t){return Math.max(0,Math.ceil((e.expiresAt-t)/6e4))}function vr(e){if(e===0)return`ending`;if(e<60)return`${e}m left`;let t=Math.floor(e/60),n=e%60;return n===0?`${t}h left`:`${t}h ${n}m left`}function yr({rules:e}){let t=I(),n=E(),r=C({queryKey:hr,refetchInterval:gr,queryFn:async()=>(await t.trpcClient.notificationRules.listSnoozes.query({})).snoozes}),i=O({mutationFn:e=>t.trpcClient.notificationRules.cancelSnooze.mutate({snoozeId:e}),onSuccess:()=>n.invalidateQueries({queryKey:hr})}),a=S(()=>{let t=new Map;for(let n of e)t.set(n.id,n.name);return t},[e]),o=Date.now(),s=(r.data??[]).filter(e=>o>=e.startedAt&&o<e.expiresAt);return s.length===0?null:x(u,{className:`p-4`,children:[x(`div`,{className:`flex items-center gap-2 mb-3`,children:[k(te,{className:`h-4 w-4 text-foreground-subtle`}),k(`h3`,{className:`text-sm font-medium text-foreground`,children:`Silenced right now`})]}),k(`div`,{className:`space-y-2`,children:s.map(e=>x(`div`,{className:`flex items-center justify-between gap-3 rounded-md border border-border px-3 py-2`,children:[x(`div`,{className:`min-w-0`,children:[x(`div`,{className:`flex items-center gap-2`,children:[k(`span`,{className:`text-xs text-foreground truncate`,children:e.scope===`all`?`Everything`:e.scope===`device`?`Camera ${e.deviceId??`?`}`:a.get(e.ruleId??``)??`A rule`}),e.global&&k(f,{variant:`warning`,className:`text-[10px]`,children:`everyone`}),!e.summary&&k(f,{variant:`default`,className:`text-[10px]`,children:`no summary`})]}),x(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`set by `,e.userId,` · `,vr(_r(e,o))]})]}),k(v,{size:`sm`,variant:`outline`,disabled:i.isPending,onClick:()=>i.mutate(e.id),children:`End now`})]},e.id))})]})}b();var br=[`notificationRules`,`listRules`],xr=[`notificationOutput`,`listTargets`,`forRules`],Sr=[`notificationRules`,`getConditionCatalog`],Cr=[`deviceManager`,`listAll`,`forRules`],wr=[`deviceManager`,`listAll`,`forRuleActions`],Tr=[`deviceManager`,`gateableDevices`],Er=j.options;function Dr({onSimulateRule:e}={}){let n=I(),[i,a]=D({mode:`closed`}),[s,c]=D(null),[d,f]=D(`all`),p=C({queryKey:br,queryFn:async()=>(await n.trpcClient.notificationRules.listRules.query({})).rules}),m=C({queryKey:xr,queryFn:()=>n.trpcClient.notificationOutput.listTargets.query({})}),h=C({queryKey:Sr,queryFn:()=>n.trpcClient.notificationRules.getConditionCatalog.query({})}),g=C({queryKey:Tr,queryFn:async()=>{let e=await n.trpcClient.deviceManager.listAll.query({}),t=[];for(let r of e){let e=ee(await n.trpcClient.deviceManager.loadRuntimeState.query({deviceId:r.id}),Er);e.length>0&&t.push({id:r.id,name:r.name,states:e})}return t},staleTime:6e4}),_=C({queryKey:wr,queryFn:async()=>(await n.trpcClient.deviceManager.listAll.query({projection:`slim`})).map(e=>({id:e.id,name:e.name,type:String(e.type),location:e.location??null})).sort((e,t)=>e.name.localeCompare(t.name)),staleTime:6e4}),b=C({queryKey:Cr,queryFn:async()=>(await n.trpcClient.deviceManager.listAll.query({})).filter(e=>e.type===M.Camera).map(e=>({id:e.id,name:e.name}))}),w=S(()=>{let e=new Map;for(let t of m.data??[])e.set(t.id,t.name);return e},[m.data]),T=O({mutationFn:e=>n.trpcClient.notificationRules.setRuleEnabled.mutate(e),onSuccess:()=>void p.refetch()}),E=O({mutationFn:e=>n.trpcClient.notificationRules.deleteRule.mutate({ruleId:e}),onSuccess:()=>{c(null),p.refetch()}}),A=p.data??[],j=S(()=>A.filter(e=>Vt(e.delivery,d)),[A,d]),N=S(()=>{let e=new Map;for(let t of zt)e.set(t.key,A.filter(e=>Vt(e.delivery,t.key)).length);return e},[A]),P=zt.find(e=>e.key===d)??zt[0],F=d===`system`;return x(H,{icon:ne,title:`Notification Rules`,subtitle:P.blurb,actions:x(v,{size:`sm`,type:`button`,onClick:()=>a({mode:`form`,rule:null,delivery:Ht(d)}),children:[k(R,{className:`h-3.5 w-3.5`}),F?`New system rule`:`New rule`]}),children:[k(t,{value:d,onValueChange:e=>f(Bt(e)??d),children:k(o,{className:`mb-3`,children:zt.map(e=>x(y,{value:e.key,children:[e.label,k(`span`,{className:`ml-1.5 text-[10px] text-foreground-subtle`,children:N.get(e.key)??0})]},e.key))})}),k(yr,{rules:A}),p.isLoading&&k(`div`,{className:`flex items-center justify-center py-16`,children:k(B,{className:`h-6 w-6 animate-spin text-primary`})}),p.isError&&!p.isLoading&&k(l,{title:`Failed to load rules`,message:p.error instanceof Error?p.error.message:`Unknown error`,onRetry:()=>void p.refetch()}),!p.isLoading&&!p.isError&&j.length===0&&k(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:F?`No system-event rules yet. Click "New system rule" to be told when a camera drops, a node leaves or an update lands.`:`No ${d===`all`?`notification`:`detection`} rules yet. Click "New rule" to author one.`}),j.length>0&&k(u,{children:k(r,{columns:F?kr({targetNameById:w,confirmDeleteId:s,deletePending:E.isPending,onToggle:(e,t)=>T.mutate({ruleId:e.id,enabled:t}),onEdit:e=>a({mode:`form`,rule:e}),onDuplicate:e=>a({mode:`form`,rule:{...e,id:``,name:`${e.name} (copy)`}}),onAskDelete:c,onConfirmDelete:e=>E.mutate(e.id)}):Or({targetNameById:w,confirmDeleteId:s,deletePending:E.isPending,onToggle:(e,t)=>T.mutate({ruleId:e.id,enabled:t}),onEdit:e=>a({mode:`form`,rule:e}),onDuplicate:e=>a({mode:`form`,rule:{...e,id:``,name:`${e.name} (copy)`}}),onAskDelete:c,onConfirmDelete:e=>E.mutate(e.id),...e?{onTest:e}:{}}),rows:j,rowKey:e=>e.id,minWidthPx:760,bordered:!1})}),i.mode===`form`&&k(Ar,{rule:i.rule,...i.delivery?{newRuleDelivery:i.delivery}:{},targets:m.data??[],actuatable:_.data??[],catalog:h.data?.catalog??[],taxonomy:h.data?.taxonomy,cameras:b.data??[],gateable:g.data??[],onCancel:()=>a({mode:`closed`}),onSaved:()=>{a({mode:`closed`}),p.refetch()}})]})}function Or(e){return[{key:`name`,header:`Rule`,render:e=>x(`span`,{className:`flex items-center gap-2`,children:[k(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),!e.enabled&&k(f,{variant:`warning`,children:`disabled`})]})},{key:`trigger`,header:`Trigger`,nowrap:!0,render:e=>x(`span`,{className:`flex items-center gap-1.5`,children:[k(`span`,{className:`text-[11px] text-foreground-subtle`,children:It(e.delivery)}),!Rt(e.delivery)&&k(f,{variant:`warning`,children:`read-only`})]})},{key:`targets`,header:`Targets`,render:t=>{let n=t.targets[0],r=n?e.targetNameById.get(n.targetId)??n.targetId:null;return k(`span`,{className:`text-[11px] text-foreground-subtle`,children:t.targets.length===1&&r?r:`${t.targets.length} target${t.targets.length===1?``:`s`}`})}},{key:`priority`,header:`Priority`,align:`center`,nowrap:!0,render:e=>k(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.priority})},{key:`enabled`,header:`On`,align:`center`,nowrap:!0,render:t=>k(d,{checked:t.enabled,onCheckedChange:n=>e.onToggle(t,n),"aria-label":`toggle ${t.name}`})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:t=>x(`span`,{className:`flex items-center justify-end gap-1`,children:[e.onTest&&k(v,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onTest?.(t),title:`Test — simulate an event this rule should match`,"aria-label":`test ${t.name}`,children:k(_e,{className:`h-3.5 w-3.5`})}),k(v,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onEdit(t),title:`Edit`,children:k(ie,{className:`h-3.5 w-3.5`})}),k(v,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onDuplicate(t),title:`Duplicate`,children:k(re,{className:`h-3.5 w-3.5`})}),e.confirmDeleteId===t.id?x(w,{children:[x(v,{size:`sm`,variant:`danger`,type:`button`,disabled:e.deletePending,onClick:()=>e.onConfirmDelete(t),children:[e.deletePending&&k(B,{className:`h-3.5 w-3.5 animate-spin`}),`Confirm`]}),k(v,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onAskDelete(null),children:`Cancel`})]}):k(v,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onAskDelete(t.id),title:`Delete`,children:k(V,{className:`h-3.5 w-3.5 text-danger`})})]})}]}function kr(e){let t=Or(e),n=e=>t.filter(t=>t.key===e);return[...n(`name`),{key:`events`,header:`Events`,render:e=>k(`span`,{className:`text-[11px] text-foreground-subtle`,children:$n(e.conditions.systemEvent?.kinds)})},{key:`scope`,header:`Scope`,nowrap:!0,render:e=>k(`span`,{className:`text-[11px] text-foreground-subtle`,children:er(e.conditions.systemEvent)})},{key:`targets`,header:`Targets`,render:t=>{let n=t.targets[0],r=n?e.targetNameById.get(n.targetId)??n.targetId:null;return k(`span`,{className:`text-[11px] text-foreground-subtle`,children:t.targets.length===1&&r?r:`${t.targets.length} target${t.targets.length===1?``:`s`}`})}},{key:`cooldown`,header:`Cooldown`,nowrap:!0,render:e=>k(`span`,{className:`text-[11px] text-foreground-subtle`,children:Wt(e.throttle.cooldownSec)})},...n(`enabled`),...n(`actions`)]}function Ar({rule:r,newRuleDelivery:i,targets:s,catalog:c,taxonomy:l,cameras:u,gateable:p,actuatable:h,onSaved:_,onCancel:b}){let S=I(),w=r!=null&&r.id.length>0,[T,E]=D(()=>r?sn(r):on(i)),[A,j]=D(null),[M,ee]=D(null),[N,P]=D(xn),F=e=>E(t=>({...t,...e})),te=w&&r?{throttle:r.throttle}:void 0,L=O({mutationFn:async()=>{let e=hn(T,te,c);w&&r?await S.trpcClient.notificationRules.updateRule.mutate({ruleId:r.id,patch:e}):await S.trpcClient.notificationRules.createRule.mutate({rule:e})},onSuccess:_,onError:e=>j(e instanceof Error?e.message:`Save failed`)}),re=O({mutationFn:async()=>{let e=hn(T,te,c);return(await S.trpcClient.notificationRules.testRule.mutate({rule:e,lookbackMinutes:60})).results},onMutate:()=>ee(null),onSuccess:e=>ee(e),onError:e=>j(e instanceof Error?e.message:`Test failed`)}),ie=T.targetIds.map(e=>s.find(t=>t.id===e)?.name??e),R=e=>F({targetIds:T.targetIds.includes(e)?T.targetIds.filter(t=>t!==e):[...T.targetIds,e]}),ae=C({queryKey:[`userManagement`,`listUsers`],queryFn:()=>S.trpcClient.userManagement.listUsers.query()}).data,oe=e=>F({targetUsers:T.targetUsers.includes(e)?T.targetUsers.filter(t=>t!==e):[...T.targetUsers,e]}),se=Ft.find(e=>e.value===T.delivery)?.hint,z=q(T.delivery),ce=bn(T.delivery),le=ce.some(e=>e.key===N)?N:xn;return Rt(T.delivery)?k(a,{open:!0,onOpenChange:e=>!e&&b(),children:x(e,{width:`lg`,placement:`sheet-on-mobile`,children:[x(`div`,{className:`flex items-center justify-between mb-3`,children:[x(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[k(ne,{className:`h-4 w-4 text-foreground-subtle`}),w?`Edit ${r?.name}`:`New notification rule`]}),k(v,{size:`sm`,variant:`ghost`,type:`button`,onClick:b,children:`Cancel`})]}),A&&k(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger mb-3`,children:A}),x(t,{value:le,onValueChange:e=>P(Sn(e)??N),children:[k(o,{className:`mb-3`,children:ce.map(e=>k(y,{value:e.key,children:e.label},e.key))}),x(n,{value:`rule`,className:`space-y-4`,children:[x(`div`,{className:`flex items-end gap-3`,children:[x(`div`,{className:`min-w-0 flex-1`,children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Name`}),k(g,{value:T.name,onChange:e=>F({name:e.target.value}),placeholder:`e.g. Front door package`})]}),x(`label`,{className:`flex items-center gap-2 pb-1.5 text-[11px] font-medium text-foreground`,children:[k(d,{checked:T.enabled,onCheckedChange:e=>F({enabled:e}),"aria-label":`enabled`}),`Enabled`]})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Trigger`}),k(m,{value:T.delivery,onChange:e=>{let t=Lt(e.target.value);t&&F({delivery:t})},options:Ft.map(e=>({value:e.value,label:e.label}))}),se&&k(`p`,{className:`text-[10px] text-foreground-subtle mt-1`,children:se})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Delivery targets`}),s.length===0?k(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No delivery targets configured. Add one under the Targets tab first.`}):k(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:s.map(e=>x(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[k(`input`,{type:`checkbox`,checked:T.targetIds.includes(e.id),onChange:()=>R(e.id),className:`accent-primary`}),k(`span`,{className:`flex-1 truncate`,children:e.name}),!e.enabled&&k(f,{variant:`warning`,children:`disabled`})]},e.id))})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Notify users`}),(ae??[]).length===0?k(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No users to notify.`}):k(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:(ae??[]).map(e=>x(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[k(`input`,{type:`checkbox`,checked:T.targetUsers.includes(e.id),onChange:()=>oe(e.id),className:`accent-primary`}),k(`span`,{className:`flex-1 truncate`,children:e.username}),e.isAdmin&&k(f,{variant:`info`,children:`admin`})]},e.id))}),k(`p`,{className:`text-[10px] text-foreground-subtle mt-1`,children:`Delivers to the targets each user owns, only for cameras that user can access.`})]})]}),k(n,{value:`devices`,className:`space-y-4`,children:k(ft,{devices:h,value:T.deviceIds,onChange:e=>F({deviceIds:e}),loading:h.length===0})}),k(n,{value:`actions`,className:`space-y-4`,children:k(et,{value:T.actions,onChange:e=>F({actions:e}),devices:h})}),x(n,{value:`advanced`,className:`space-y-4`,children:[x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Cooldown`}),k(m,{value:String(T.cooldownSec),onChange:e=>{let t=Kt(e.target.value);t!==void 0&&F({cooldownSec:t})},options:Gt(T.cooldownSec).map(e=>({value:String(e.value),label:e.label}))}),k(`p`,{className:`text-[10px] text-foreground-subtle mt-1`,children:z?`A camera that flaps, or a node that reconnects every minute, would otherwise send one notification per flap. The cooldown is the shortest gap between two deliveries of this rule.`:`The shortest gap between two deliveries of this rule. Counted per device unless the rule was configured otherwise.`})]}),x(`div`,{children:[x(`label`,{className:`flex items-center gap-2 text-[11px] font-medium text-foreground`,children:[k(d,{checked:T.snoozeAllowGlobal,onCheckedChange:e=>F({snoozeAllowGlobal:e}),"aria-label":`allow global snooze`}),`Anyone may snooze this rule for everyone`]}),k(`p`,{className:`text-[10px] text-foreground-subtle mt-1`,children:`A snooze is personal by default — it silences only the person who set it. Turn this on for a rule where silencing the whole household is legitimate (the gardener is here all afternoon). Admins can always do it.`})]})]}),x(n,{value:`notification`,className:`space-y-4`,children:[x(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Priority`}),k(m,{value:String(T.priority),onChange:e=>F({priority:Number(e.target.value)}),options:an.map(e=>({value:String(e.value),label:e.label}))})]}),z&&k(`div`,{className:`rounded-md border border-border px-3 py-2 text-[11px] text-foreground-subtle`,children:`A system event carries no image: there is no camera frame behind "a node went offline". This rule sends text only.`}),!z&&x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Media attachment`}),k(m,{value:T.mediaAttach,onChange:e=>{let t=Jt(e.target.value);t&&F({mediaAttach:t})},options:qt.map(e=>({value:e.value,label:e.label}))}),k(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:qt.find(e=>e.value===T.mediaAttach)?.description}),x(`div`,{className:`mt-2 space-y-1`,children:[x(`label`,{className:`flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[k(`input`,{type:`checkbox`,checked:T.mediaZoneCrop,onChange:e=>F({mediaZoneCrop:e.target.checked}),className:`accent-primary`}),`Crop the image to the rule's zone`]}),x(`label`,{className:`flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[k(`input`,{type:`checkbox`,checked:T.mediaGif,onChange:e=>F({mediaGif:e.target.checked}),className:`accent-primary`}),`Attach a GIF around the event`]}),x(`label`,{className:`flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[k(`input`,{type:`checkbox`,checked:T.mediaClip,onChange:e=>F({mediaClip:e.target.checked}),className:`accent-primary`}),`Attach an MP4 clip around the event`]})]}),(T.mediaGif||T.mediaClip)&&x(`div`,{className:`mt-2`,children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Video quality`}),k(m,{value:T.mediaProfile??``,onChange:e=>F({mediaProfile:Qt(e.target.value)}),options:Zt.map(e=>({value:e.value,label:e.label}))}),k(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:`A notification is watched on a phone — the cheapest stream is normally the right one, and the high profile only costs CPU to render.`}),k(`label`,{className:`mt-2 block text-[11px] font-medium text-foreground mb-1`,children:`Playback speed`}),k(m,{value:T.mediaClipSpeed===void 0?``:String(T.mediaClipSpeed),onChange:e=>F({mediaClipSpeed:vn(e.target.value)}),options:_n.map(e=>({value:e.value,label:e.label}))}),k(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:`A notification clip is glanced at, not watched: at 2× the recipient sees the whole passage in half the time and the file is half the size. Real time is there when the detail matters more than the glance.`})]})]}),!z&&x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Image frame`}),k(m,{value:T.mediaFrame??``,onChange:e=>F({mediaFrame:Xt(e.target.value)}),options:Yt.map(e=>({value:e.value,label:e.label}))}),k(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:`What the attached still shows. "Automatic" leaves it to the attachment mode above.`})]})]}),x(`div`,{className:`space-y-2`,children:[x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Notification title`}),k(g,{value:T.templateTitle,onChange:e=>F({templateTitle:e.target.value}),placeholder:`{{camera}} — {{class}}`})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Notification body`}),k(`textarea`,{value:T.templateBody,onChange:e=>F({templateBody:e.target.value}),rows:2,placeholder:`{{label}} seen in {{zone}} at {{time}}`,className:`w-full rounded-md border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),x(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Leave blank to use the backend default text. Supported variables include`,` `,k(`code`,{children:`{{camera}}`}),`, `,k(`code`,{children:`{{class}}`}),`, `,k(`code`,{children:`{{label}}`}),`,`,` `,k(`code`,{children:`{{zone}}`}),`, `,k(`code`,{children:`{{confidence}}`}),`,`,` `,k(`code`,{children:`{{time}}`}),`.`]})]})]}),x(n,{value:`conditions`,className:`space-y-4`,children:[x(`div`,{className:`rounded-md border border-border px-3 py-3`,children:[k(`div`,{className:`mb-2 text-[11px] font-semibold text-foreground`,children:z?`Which system events`:`Conditions`}),z&&k(`p`,{className:`mb-2 text-[10px] text-foreground-subtle`,children:`Pick the events this rule reacts to, then narrow them if you want. Nothing else on a system rule is a condition — there is no detection behind it.`}),c.length===0?k(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Condition catalog unavailable — this rule matches on its trigger and targets alone.`}):k(or,{catalog:c,taxonomy:l,delivery:T.delivery,conditions:T.conditions,schedule:T.schedule,cameras:u,gateable:p,onConditionsChange:e=>F({conditions:e}),onScheduleChange:e=>F({schedule:e})})]}),!z&&x(`div`,{className:`rounded-md border border-border px-3 py-3`,children:[x(`div`,{className:`flex items-center justify-between gap-2`,children:[k(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Test rule`}),x(v,{size:`sm`,variant:`outline`,type:`button`,disabled:re.isPending||!cn(T),onClick:()=>{j(null),re.mutate()},children:[re.isPending?k(B,{className:`h-3.5 w-3.5 animate-spin`}):k(_e,{className:`h-3.5 w-3.5`}),`Dry-run (last 60 min)`]})]}),k(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:`Evaluate the CURRENT (unsaved) rule against recently persisted records — no notification is sent.`}),M!==null&&k(Mr,{delivery:T.delivery,results:M,targetNames:ie})]})]})]}),x(`div`,{className:`flex justify-end gap-2 mt-4`,children:[k(v,{variant:`secondary`,size:`sm`,type:`button`,onClick:b,children:`Cancel`}),x(v,{size:`sm`,type:`button`,disabled:L.isPending||!cn(T),onClick:()=>{j(null),L.mutate()},children:[L.isPending&&k(B,{className:`h-3.5 w-3.5 animate-spin`}),w?`Save changes`:`Create rule`]})]})]})}):k(jr,{rule:r,onCancel:b})}function jr({rule:t,onCancel:n}){let r=Object.keys(t?.conditions??{});return k(a,{open:!0,onOpenChange:e=>!e&&n(),children:x(e,{width:`lg`,placement:`sheet-on-mobile`,children:[x(`div`,{className:`flex items-center justify-between mb-3`,children:[x(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[k(ne,{className:`h-4 w-4 text-foreground-subtle`}),t?.name??`Rule`]}),k(f,{variant:`warning`,children:`read-only`})]}),x(`div`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-2 text-xs text-warning`,"data-testid":`unsupported-trigger-notice`,children:[`This rule uses the trigger `,k(`code`,{children:t?.delivery}),`, which this version of the admin UI cannot author. It is shown exactly as stored and nothing here can change it — editing it with an editor that does not know the trigger would rewrite it. Update the server bundle, or edit this rule from the viewer app.`]}),x(`dl`,{className:`mt-3 space-y-1.5 text-[11px]`,children:[x(`div`,{className:`flex gap-2`,children:[k(`dt`,{className:`w-24 shrink-0 text-foreground-subtle`,children:`Trigger`}),k(`dd`,{className:`text-foreground`,children:t?.delivery})]}),x(`div`,{className:`flex gap-2`,children:[k(`dt`,{className:`w-24 shrink-0 text-foreground-subtle`,children:`Enabled`}),k(`dd`,{className:`text-foreground`,children:t?.enabled?`yes`:`no`})]}),x(`div`,{className:`flex gap-2`,children:[k(`dt`,{className:`w-24 shrink-0 text-foreground-subtle`,children:`Targets`}),k(`dd`,{className:`text-foreground`,children:t?.targets.length??0})]}),x(`div`,{className:`flex gap-2`,children:[k(`dt`,{className:`w-24 shrink-0 text-foreground-subtle`,children:`Conditions`}),k(`dd`,{className:`text-foreground`,children:r.length>0?r.join(`, `):`none`})]})]}),k(`div`,{className:`flex justify-end gap-2 mt-4`,children:k(v,{variant:`secondary`,size:`sm`,type:`button`,onClick:n,children:`Close`})})]})})}function Mr({delivery:e,results:t,targetNames:n}){if(e===`device-event`)return k(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:`Device-event rules cannot be dry-run: the sensor-event store has no cross-device scan surface, so a test returns no candidate records. The rule still fires live on a matching doorbell press / sensor change.`});if(t.length===0)return k(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:`No records in the last 60 minutes matched — nothing to evaluate.`});let r=t.filter(e=>e.wouldFire).length;return x(`div`,{className:`mt-2 space-y-1.5`,children:[x(`div`,{className:`text-[11px] text-foreground-subtle`,children:[r,` of `,t.length,` evaluated record`,t.length===1?``:`s`,` would fire.`]}),k(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:t.slice(0,50).map(e=>x(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5 text-[11px]`,children:[e.wouldFire?k(L,{className:`h-3.5 w-3.5 shrink-0 text-success`}):k(ue,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),k(`span`,{className:`w-32 shrink-0 text-foreground-subtle`,children:new Date(e.timestamp).toLocaleString()}),x(`span`,{className:`w-14 shrink-0 text-foreground-subtle`,children:[`#`,e.deviceId]}),k(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:e.label??e.className??`object`}),e.wouldFire?x(`span`,{className:`shrink-0 truncate text-success`,children:[`→ `,n.join(`, `)||`targets`]}):e.failedCondition&&x(`span`,{className:`shrink-0 text-foreground-subtle`,children:[`failed: `,e.failedCondition]})]},e.recordId))})]})}var Nr=[{value:`object-event`,label:`Object detection`,hint:`A detection on a live track — what an "Immediate" rule sees.`},{value:`track-end`,label:`Track end`,hint:`A finalised track: importance, dwell and label confidence exist only here.`},{value:`device-event`,label:`Device event`,hint:`A doorbell press or a linked sensor changing state.`},{value:`package-event`,label:`Package event`,hint:`A parcel delivered or picked up.`},{value:`audio-event`,label:`Audio event`,hint:`A classified audio episode. Rides the Immediate delivery, gated by the audio classes.`},{value:`occupancy-event`,label:`Occupancy edge`,hint:`A zone count crossing its threshold. Rides the Device-event delivery.`}];function Pr(e){return Nr.find(t=>t.value===e)?.value}function Fr(e){return e===`object-event`||e===`audio-event`?`immediate`:e===`occupancy-event`?`device-event`:e}function Ir(e){return``}var Lr={x:.25,y:.25,w:.5,h:.5},Rr={zoneId:``,zoneName:``,className:``,count:1,previousCount:0,occupied:!0,threshold:1};function zr(){return{trigger:`object-event`,deviceId:null,sourceDeviceId:null,classNames:[],label:``,confidence:void 0,labelConfidence:void 0,importance:void 0,dwellSeconds:void 0,zones:[],crossingEnabled:!1,crossingZoneId:``,crossingDirection:`enter`,sensorKind:``,eventType:``,packagePhase:``,source:``,bboxEnabled:!1,bbox:Lr,occupancy:Rr,timestampLocal:``,onlyRuleId:``,bypassCooldown:!1,bypassMute:!1,runActions:!1,still:`live`}}function Br(e){return e.deviceId!==null}function Vr(e){if(e.trim().length===0)return;let t=Number(e);return Number.isFinite(t)?t:void 0}function Hr(e){if(e.trim().length===0)return;let t=Date.parse(e);return Number.isFinite(t)?t:void 0}function Ur(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function Wr(e){if(e.deviceId===null)return null;let t=e.trigger,n=Hr(e.timestampLocal),r=e.label.trim(),i=e.sensorKind.trim(),a=e.eventType.trim(),o=e.onlyRuleId.trim(),s=t===`device-event`,c=t===`occupancy-event`;return{trigger:t,deviceId:e.deviceId,...s&&e.sourceDeviceId!==null&&e.sourceDeviceId!==e.deviceId?{sourceDeviceId:e.sourceDeviceId}:{},classNames:[...e.classNames],...r.length>0?{label:r}:{},...e.confidence===void 0?{}:{confidence:e.confidence},...e.labelConfidence===void 0?{}:{labelConfidence:e.labelConfidence},...e.importance===void 0?{}:{importance:e.importance},...e.dwellSeconds===void 0?{}:{dwellSeconds:e.dwellSeconds},zones:[...e.zones],...t===`object-event`&&e.crossingEnabled?{crossing:{zoneId:e.crossingZoneId,direction:e.crossingDirection}}:{},...s&&i.length>0?{sensorKind:i}:{},...s&&a.length>0?{eventType:a}:{},...t===`package-event`&&e.packagePhase!==``?{packagePhase:e.packagePhase}:{},...e.source===``?{}:{source:e.source},...e.bboxEnabled?{bbox:{...e.bbox}}:{},...c?{occupancy:Gr(e.occupancy)}:{},...n===void 0?{}:{timestamp:n},...o.length>0?{onlyRuleId:o}:{},bypassCooldown:e.bypassCooldown,bypassMute:e.bypassMute,runActions:e.runActions,still:e.still}}function Gr(e){let t=e.zoneId.trim(),n=e.zoneName.trim(),r=e.className.trim();return{...t.length>0?{zoneId:t}:{},...n.length>0?{zoneName:n}:{},...r.length>0?{className:r}:{},count:Math.max(0,Math.round(e.count)),previousCount:Math.max(0,Math.round(e.previousCount)),occupied:e.occupied,threshold:Math.max(1,Math.round(e.threshold))}}function Kr(e){return Math.min(1,Math.round((e+.05)*100)/100)}function qr(e){if(e.delivery===`immediate`){let t=e.conditions.classes??[];return t.length>0&&t.every(e=>e.startsWith(`audio-`))?`audio-event`:`object-event`}return e.delivery===`device-event`?e.conditions.occupancy===void 0?`device-event`:`occupancy-event`:e.delivery===`track-end`?`track-end`:`package-event`}function Jr(e){let t=zr(),n=e.conditions,r=qr(e),i=n.zones?.ids??[],a=n.identities?.[0]??n.labelEquals?.[0]??n.plates?.values?.[0],o=n.crossing===`exit`?`exit`:n.crossing===void 0?void 0:`enter`,s=r===`package-event`?n.packagePhase===`picked-up`?`picked-up`:`delivered`:``;return{...t,trigger:r,deviceId:n.devices?.[0]??null,classNames:[...n.classes??[]],...a===void 0?{}:{label:a},...n.minConfidence===void 0?{}:{confidence:Kr(n.minConfidence)},...n.minLabelConfidence===void 0?{}:{labelConfidence:Kr(n.minLabelConfidence)},...n.minImportance===void 0?{}:{importance:Kr(n.minImportance)},...n.minDwellSeconds===void 0?{}:{dwellSeconds:Math.round(n.minDwellSeconds)+1},zones:[...i],...r===`object-event`&&o!==void 0?{crossingEnabled:!0,crossingZoneId:i[0]??``,crossingDirection:o}:{},...n.sensorKinds?.[0]===void 0?{}:{sensorKind:n.sensorKinds[0]},...n.eventTypeTokens?.[0]===void 0?{}:{eventType:n.eventTypeTokens[0]},packagePhase:s,source:n.source!==void 0&&n.source!==`any`?n.source:Ir(r),...n.customZones!==void 0&&n.customZones.length>0?{bboxEnabled:!0}:{},...n.occupancy===void 0?{}:{occupancy:Yr(n.occupancy)},onlyRuleId:e.id}}function Yr(e){let t=Math.max(1,Math.round(e.count)),n={zoneId:e.zoneId??``,zoneName:``,className:e.className??``,threshold:t};if(e.op===`became-free`)return{...n,count:0,previousCount:t,occupied:!1};if(e.op===`<=`){let t=Math.max(0,Math.round(e.count));return{...n,count:t,previousCount:t+1,occupied:t>0}}return{...n,count:t,previousCount:Math.max(0,t-1),occupied:!0}}function Xr(e){let t=[];return e.conditions.deviceState!==void 0&&t.push({conditionId:`deviceState`,note:`This rule is gated on device #${e.conditions.deviceState.deviceId} being in a given state. The gate reads the REAL device — put it in that state first, or the simulation fails closed exactly as production would.`}),e.conditions.customZones!==void 0&&e.conditions.customZones.length>0&&t.push({conditionId:`customZones`,note:`This rule matches viewer-drawn polygons against the subject bbox. The bbox below is enabled but centred — move it over the polygon, or the condition fails.`}),t}function Zr(e){return{form:Jr(e),caveats:Xr(e),ruleName:e.name}}var Qr=null;function $r(e){Qr=e}function ei(){return Qr}function ti(){Qr=null}var ni=[`n/a`,`clear`,`suppressed`,`bypassed`],ri=[`live`,`none`,`unavailable`,`unattachable`];function ii(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function X(e,t){let n=e[t];return typeof n==`string`?n:void 0}function ai(e,t){let n=e[t];return Array.isArray(n)?n.filter(e=>typeof e==`string`):[]}function oi(e){if(!ii(e))return null;let t=X(e,`ruleId`),n=X(e,`ruleName`),r=X(e,`cooldown`),i=ni.find(e=>e===r);if(t===void 0||n===void 0||i===void 0||typeof e.matched!=`boolean`)return null;let a=X(e,`failedCondition`),o=Array.isArray(e.matchedOn)?ai(e,`matchedOn`):void 0;return{ruleId:t,ruleName:n,matched:e.matched,...a===void 0?{}:{failedCondition:a},...o===void 0?{}:{matchedOn:o},cooldown:i,enqueued:typeof e.enqueued==`number`?e.enqueued:0,targetIds:ai(e,`targetIds`)}}function si(e){if(!ii(e))return null;let t=X(e,`recordId`),n=X(e,`delivery`),r=X(e,`still`),i=ri.find(e=>e===r);if(t===void 0||n===void 0||i===void 0||e.origin!==`synthetic`)return null;let a=Array.isArray(e.outcomes)?e.outcomes:[],o=[];for(let e of a){let t=oi(e);t!==null&&o.push(t)}let s=X(e,`droppedBy`);return{recordId:t,origin:`synthetic`,delivery:n,candidates:typeof e.candidates==`number`?e.candidates:0,outcomes:o,still:i,notes:ai(e,`notes`),...s===void 0?{}:{droppedBy:s}}}function ci(e){if(e.droppedBy!==void 0)return`Dropped before evaluation (${e.droppedBy}) — no rule was consulted.`;if(e.candidates===0)return`No enabled rule declares the "${e.delivery}" delivery, so nothing was evaluated.`;let t=e.outcomes.filter(e=>e.matched).length,n=e.outcomes.reduce((e,t)=>e+t.enqueued,0);return t===0?`${e.candidates} candidate rule${e.candidates===1?``:`s`} evaluated, none matched.`:`${t} of ${e.candidates} candidate rule${e.candidates===1?``:`s`} matched — ${n} notification${n===1?``:`s`} enqueued.`}var li=new Set([`sensor`,`control`,`custom`]);function ui({form:e,cameras:t,taxonomy:n,kinds:r,kindsLoading:i,onPatch:a}){let o=e.deviceId===null?[]:[e.deviceId],s=N(`classes`,n);if(e.trigger===`device-event`)return x(`div`,{className:`space-y-3 rounded-md border border-border px-3 py-2`,children:[k(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`What happened`}),k(di,{form:e,kinds:r,loading:i,onPatch:a})]});if(e.trigger===`audio-event`){let n=r.filter(e=>e.category===`audio`&&e.level===`sub`).map(e=>({value:e.kind,label:e.label}));return x(`div`,{className:`space-y-3 rounded-md border border-border px-3 py-2`,children:[k(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`What happened`}),x(`div`,{children:[k(`label`,{className:J,children:`Audio classes`}),k(K,{options:n,value:e.classNames,onChange:e=>a({classNames:e}),loading:i,emptyHint:e.deviceId===null?`Pick a camera first — the audio vocabulary is per camera.`:`This camera advertises no audio kinds. The audio classifier is probably off for it.`,placeholder:`Audio class id…`})]}),x(`div`,{children:[k(`label`,{className:J,children:`Zones`}),k(kn,{deviceIds:o,cameras:t,value:e.zones,onChange:e=>a({zones:e})})]})]})}return e.trigger===`occupancy-event`?x(`div`,{className:`space-y-3 rounded-md border border-border px-3 py-2`,children:[k(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`What happened`}),k(fi,{form:e,cameras:t,taxonomy:n,onPatch:a})]}):x(`div`,{className:`space-y-3 rounded-md border border-border px-3 py-2`,children:[k(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`What happened`}),x(`div`,{children:[k(`label`,{className:J,children:`Detected classes`}),s===null?k(wn,{value:e.classNames,placeholder:`Class id (person, car…)`,onChange:e=>a({classNames:e})}):k(Tn,{picker:s,value:e.classNames,onChange:e=>a({classNames:e})})]}),x(`div`,{children:[k(`label`,{className:J,children:`Zones the subject is in`}),k(kn,{deviceIds:o,cameras:t,value:e.zones,onChange:e=>a({zones:e})})]}),e.trigger===`package-event`&&x(`div`,{className:`max-w-[14rem]`,children:[k(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Package phase`}),k(m,{value:e.packagePhase,options:[{value:``,label:`— none —`},{value:`delivered`,label:`Delivered`},{value:`picked-up`,label:`Picked up`}],onChange:e=>a({packagePhase:e.target.value===`delivered`?`delivered`:e.target.value===`picked-up`?`picked-up`:``})})]})]})}function di({form:e,kinds:t,loading:n,onPatch:r}){let i=t.filter(e=>li.has(e.category)),a=i.find(t=>t.kind===e.sensorKind);return x(w,{children:[x(`div`,{children:[k(`label`,{className:J,children:`Event kind`}),k(m,{value:e.sensorKind,options:[{value:``,label:n?`Loading kinds…`:`— pick a kind —`},...i.map(e=>({value:e.kind,label:`${e.label} (${e.category})`}))],onChange:e=>{let t=i.find(t=>t.kind===e.target.value);r({sensorKind:t?.kind??``,sourceDeviceId:t?.source.deviceId??null})}}),!n&&i.length===0&&k(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:e.deviceId===null?`Pick a camera first — sensor and control kinds come from the devices linked to it.`:`This camera has no linked sensor or control device, so it can produce no device event. Link one on the camera page first.`})]}),x(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[x(`div`,{children:[k(`label`,{className:J,children:`Source device`}),k(g,{type:`number`,value:e.sourceDeviceId===null?``:String(e.sourceDeviceId),placeholder:`the camera itself`,onChange:e=>r({sourceDeviceId:Vr(e.target.value)??null})}),k(`p`,{className:Y,children:a===void 0?`The linked device whose state changed. Filled in for you when you pick a kind.`:`Filled in from "${a.label}" — contributed by device #${a.source.deviceId} via the ${a.source.capName} capability.`})]}),x(`div`,{children:[k(`label`,{className:J,children:`Event type token`}),k(g,{value:e.eventType,placeholder:`press, press_long…`,onChange:e=>r({eventType:e.target.value})}),k(`p`,{className:Y,children:`Only event-emitter sources carry one. A passive sensor emits none, and a rule gating on a token would fail closed for it.`})]})]})]})}function fi({form:e,cameras:t,taxonomy:n,onPatch:r}){let i=e.deviceId===null?[]:[e.deviceId],a=N(`classes`,n),o=a===null?[]:a.groups.flatMap(e=>e.options),s=e.occupancy,c=e=>r({occupancy:{...s,...e}});return x(w,{children:[x(`div`,{children:[k(`label`,{className:J,children:`Zone`}),k(kn,{deviceIds:i,cameras:t,value:s.zoneId===``?[]:[s.zoneId],onChange:e=>c({zoneId:e[e.length-1]??``})}),k(`p`,{className:Y,children:`Leave empty for the whole frame.`})]}),x(`div`,{className:`max-w-[14rem]`,children:[k(`label`,{className:J,children:`Class`}),k(m,{value:s.className,options:[{value:``,label:`— any class —`},...o.map(e=>({value:e.value,label:e.label}))],onChange:e=>c({className:e.target.value})})]}),x(`div`,{className:`flex flex-wrap items-end gap-3`,children:[x(`label`,{className:`text-[11px] text-foreground-subtle`,children:[`Count now`,k(g,{type:`number`,min:0,className:`w-20`,value:String(s.count),onChange:e=>c({count:Vr(e.target.value)??0})})]}),x(`label`,{className:`text-[11px] text-foreground-subtle`,children:[`Count before`,k(g,{type:`number`,min:0,className:`w-20`,value:String(s.previousCount),onChange:e=>c({previousCount:Vr(e.target.value)??0})})]}),x(`label`,{className:`text-[11px] text-foreground-subtle`,children:[`Threshold`,k(g,{type:`number`,min:1,className:`w-20`,value:String(s.threshold),onChange:e=>c({threshold:Vr(e.target.value)??1})})]}),x(`label`,{className:`flex items-center gap-2 pb-1 text-[11px] text-foreground`,children:[k(d,{checked:s.occupied,onCheckedChange:e=>c({occupied:e}),"aria-label":`occupied`}),`Occupied`]})]})]})}function pi({form:e,cameras:t,onPatch:n}){let r=e.deviceId===null?[]:[e.deviceId];return x(`details`,{className:`rounded-md border border-border px-3 py-2`,children:[k(`summary`,{className:`cursor-pointer text-[11px] font-semibold text-foreground`,children:`Advanced`}),x(`div`,{className:`mt-2 space-y-3`,children:[e.trigger===`object-event`&&x(`div`,{children:[x(`label`,{className:`flex items-center gap-2 text-[11px] font-medium text-foreground`,children:[k(d,{checked:e.crossingEnabled,onCheckedChange:e=>n({crossingEnabled:e}),"aria-label":`zone crossing`}),`This event is a confirmed zone crossing`]}),e.crossingEnabled&&x(`div`,{className:`mt-1 space-y-1.5`,children:[k(`div`,{className:`max-w-[12rem]`,children:k(m,{value:e.crossingDirection,options:[{value:`enter`,label:`Entered the zone`},{value:`exit`,label:`Left the zone`}],onChange:e=>n({crossingDirection:e.target.value===`exit`?`exit`:`enter`})})}),k(kn,{deviceIds:r,cameras:t,value:e.crossingZoneId===``?[]:[e.crossingZoneId],onChange:e=>n({crossingZoneId:e[e.length-1]??``})})]})]}),x(`div`,{children:[x(`label`,{className:`flex items-center gap-2 text-[11px] font-medium text-foreground`,children:[k(d,{checked:e.bboxEnabled,onCheckedChange:e=>n({bboxEnabled:e}),"aria-label":`bounding box`}),`Carry a bounding box`]}),k(`p`,{className:Y,children:"Normalized 0–1, top-left origin. Feeds the `customZones` condition and decides how the still is cropped or boxed."}),e.bboxEnabled&&k(`div`,{className:`mt-1 flex flex-wrap gap-2`,children:[`x`,`y`,`w`,`h`].map(t=>x(`label`,{className:`text-[11px] text-foreground-subtle`,children:[t,k(g,{type:`number`,min:0,max:1,step:.05,className:`w-20`,value:String(e.bbox[t]),onChange:r=>n({bbox:{...e.bbox,[t]:Vr(r.target.value)??0}})})]},t))})]}),x(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[x(`div`,{children:[k(`label`,{className:J,children:`Happened at`}),x(`div`,{className:`flex items-center gap-2`,children:[k(g,{type:`datetime-local`,value:e.timestampLocal,onChange:e=>n({timestampLocal:e.target.value})}),e.timestampLocal===``?k(v,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>n({timestampLocal:Ur(Date.now())}),children:`Set`}):k(v,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>n({timestampLocal:``}),children:`Now`})]}),k(`p`,{className:Y,children:`Empty = now. Set it to a time inside (or outside) a rule's schedule window to test the schedule without waiting for the hour.`})]}),x(`div`,{children:[k(`label`,{className:J,children:`Detection source`}),k(m,{value:e.source,options:[{value:``,label:`— unset (reads as pipeline) —`},{value:`pipeline`,label:`Pipeline`},{value:`onboard`,label:`Onboard (camera)`},{value:`sensor`,label:`Sensor`},{value:`audio`,label:`Audio`}],onChange:e=>{let t=e.target.value;n({source:t===`pipeline`||t===`onboard`||t===`sensor`||t===`audio`?t:``})}})]})]})]})]})}function mi({checked:e,label:t,hint:n,danger:r=!1,onChange:i}){return x(`div`,{children:[x(`label`,{className:`flex items-center gap-2 text-[11px] font-medium text-foreground`,children:[k(d,{checked:e,onCheckedChange:i,"aria-label":t}),t,r&&k(f,{variant:`danger`,children:`actuates devices`})]}),k(`p`,{className:Y,children:n})]})}b();var hi={live:`A live snapshot of the camera was taken and attached.`,none:`No still was requested.`,unavailable:`A still was requested but the camera could not produce one.`,unattachable:`This trigger cannot carry a still at all — an audio or occupancy notification freezes no media owner, so it ships text-only in production too. This is not a limit of the test.`},gi={"n/a":`The rule did not match, so no cooldown was consulted.`,clear:`No cooldown was in effect — the rule was free to fire.`,suppressed:`A cooldown from an earlier fire silenced this one. Re-run with "Ignore cooldown".`,bypassed:`A cooldown was in effect and was deliberately ignored for this run.`};function _i({result:e,targetName:t}){return x(`div`,{className:`space-y-3 rounded-md border border-border px-3 py-3`,children:[k(`p`,{className:`text-xs font-medium text-foreground`,children:ci(e)}),x(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px] text-foreground-subtle`,children:[k(vi,{recordId:e.recordId}),x(`span`,{children:[`delivery `,k(`span`,{className:`text-foreground`,children:e.delivery})]}),x(`span`,{children:[`candidates `,k(`span`,{className:`text-foreground`,children:e.candidates})]}),x(`span`,{title:hi[e.still],children:[`still `,k(`span`,{className:`text-foreground`,children:e.still})]}),e.droppedBy!==void 0&&x(f,{variant:`warning`,children:[`dropped: `,e.droppedBy]})]}),e.notes.length>0&&k(`ul`,{className:`space-y-1 rounded-md border border-border bg-surface px-2.5 py-2`,children:e.notes.map(e=>k(`li`,{className:`text-[11px] leading-snug text-foreground-subtle`,children:e},e))}),e.outcomes.length===0?x(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`No rule was evaluated. Either no enabled rule declares the`,` `,k(`span`,{className:`text-foreground`,children:e.delivery}),` delivery, or the ones that do were filtered out before evaluation — the notes above say which.`]}):k(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:e.outcomes.map(e=>k(yi,{outcome:e,targetName:t},e.ruleId))})]})}function vi({recordId:e}){let[t,n]=D(!1);return x(`span`,{className:`inline-flex items-center gap-1 rounded border border-border px-1.5 py-0.5`,children:[k(`code`,{className:`text-[10px] text-foreground`,children:e}),k(v,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>{let t=navigator.clipboard;t!==void 0&&t.writeText(e).then(()=>{n(!0),setTimeout(()=>n(!1),1500)},()=>n(!1))},title:`Copy record id`,children:k(re,{className:`h-3 w-3`})}),t&&k(`span`,{className:`text-[10px] text-success`,children:`copied`})]})}function yi({outcome:e,targetName:t}){return x(`li`,{className:`space-y-1 px-2.5 py-2`,children:[x(`div`,{className:`flex items-center gap-2`,children:[e.matched?k(L,{className:`h-3.5 w-3.5 shrink-0 text-success`}):k(ue,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),k(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:e.ruleName}),x(`span`,{className:`shrink-0 text-[10px] text-foreground-subtle`,title:gi[e.cooldown],children:[`cooldown: `,e.cooldown]})]}),!e.matched&&k(`p`,{className:`pl-5 text-[11px] text-foreground-subtle`,children:e.failedCondition===void 0?`Did not match. The engine reported no failing condition id.`:x(w,{children:[`Did not match — first failing condition`,` `,k(`code`,{className:`text-foreground`,children:e.failedCondition}),`.`]})}),e.matched&&x(`p`,{className:`pl-5 text-[11px] text-foreground-subtle`,children:[e.enqueued,` outbox row`,e.enqueued===1?``:`s`,` enqueued`,e.targetIds.length>0?` → ${e.targetIds.map(t).join(`, `)}`:` — no target resolved, so nothing will be delivered`,`.`]}),e.matchedOn!==void 0&&e.matchedOn.length>0&&x(`p`,{className:`pl-5 text-[10px] text-foreground-muted`,children:[`matched on: `,e.matchedOn.join(`, `)]})]})}b();var bi=`pipeline-analytics`,xi=`nc.injectTestEvent`;function Si(){let e=I(),[t,n]=D(()=>ei()?.form??zr()),[r]=D(()=>ei()?.caveats??[]),[i]=D(()=>ei()?.ruleName??null);A(()=>ti(),[]);let[a,o]=D(null),[s,c]=D(!1),[d,f]=D(null),p=e=>n(t=>({...t,...e})),h=C({queryKey:Cr,queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({})).filter(e=>e.type===M.Camera).map(e=>({id:e.id,name:e.name}))}),_=C({queryKey:Sr,queryFn:()=>e.trpcClient.notificationRules.getConditionCatalog.query({})}),y=C({queryKey:br,queryFn:async()=>(await e.trpcClient.notificationRules.listRules.query({})).rules}),b=C({queryKey:xr,queryFn:()=>e.trpcClient.notificationOutput.listTargets.query({})}),w=t.deviceId,T=C({queryKey:[[`pipelineAnalytics`,`listEventKindsBatch`],{deviceId:w}],enabled:w!==null,staleTime:6e4,queryFn:async()=>w===null?[]:(await e.trpcClient.pipelineAnalytics.listEventKindsBatch.query({deviceIds:[w]})).flatMap(e=>[...e.kinds])}),E=h.data??[],j=_.data?.taxonomy,ee=T.data??[],N=S(()=>{let e=new Map;for(let t of b.data??[])e.set(t.id,t.name);return e},[b.data]),P=O({mutationFn:async()=>{let n=Wr(t);if(n===null)throw Error(`Pick a camera first.`);return e.trpcClient.addons.custom.mutate({addonId:bi,action:xi,input:n})},onMutate:()=>{o(null),c(!1),f(null)},onSuccess:e=>{let t=si(e);o(t),c(t===null)},onError:e=>f(e instanceof Error?e.message:`The simulation failed.`)}),F=Fr(t.trigger),te=y.data?.find(e=>e.id===t.onlyRuleId);return x(H,{icon:_e,title:`Simulate an event`,subtitle:`Inject a synthetic detection, doorbell press or occupancy edge and see exactly which rules match it, which condition each one fails on, and what would be delivered. Nothing is persisted — no track, no event row, no media.`,children:[h.isError&&k(l,{title:`Failed to load cameras`,message:h.error instanceof Error?h.error.message:`Unknown error`,onRetry:()=>void h.refetch()}),i!==null&&x(`div`,{className:`rounded-md border border-primary/40 bg-primary/5 px-3 py-2 text-[11px] text-foreground`,children:[`Seeded from the rule `,k(`span`,{className:`font-medium`,children:i}),`. Only that rule will be evaluated — clear "Evaluate only one rule" below to run the whole rule set.`]}),r.length>0&&k(`div`,{className:`space-y-1 rounded-md border border-warning/40 bg-warning/5 px-3 py-2`,children:r.map(e=>x(`p`,{className:`flex gap-1.5 text-[11px] text-foreground`,children:[k(he,{className:`mt-0.5 h-3 w-3 shrink-0 text-warning`}),k(`span`,{children:e.note})]},e.conditionId))}),x(u,{className:`space-y-4`,children:[x(`div`,{children:[k(`label`,{className:J,children:`Camera`}),k(m,{"data-testid":`simulate-camera`,value:t.deviceId===null?``:String(t.deviceId),options:[{value:``,label:E.length===0?`Loading cameras…`:`— pick a camera —`},...E.map(e=>({value:String(e.id),label:e.name}))],onChange:e=>{p({deviceId:Vr(e.target.value)??null,zones:[],crossingZoneId:``,sensorKind:``,sourceDeviceId:null,occupancy:{...t.occupancy,zoneId:``}})}}),k(`p`,{className:Y,children:`The camera the event is attributed to — what a notification shows.`})]}),x(`div`,{children:[k(`label`,{className:J,children:`Trigger`}),k(m,{"data-testid":`simulate-trigger`,value:t.trigger,options:Nr.map(e=>({value:e.value,label:e.label})),onChange:e=>{let n=Pr(e.target.value);if(!n)return;let r=Ir(t.trigger);p({trigger:n,source:t.source===``||t.source===r?Ir(n):t.source})}}),x(`p`,{className:Y,children:[Nr.find(e=>e.value===t.trigger)?.hint,` Only rules whose trigger is `,k(`span`,{className:`text-foreground`,children:F}),` are candidates.`]})]}),k(ui,{form:t,cameras:E,taxonomy:j,kinds:ee,kindsLoading:T.isLoading,onPatch:p}),x(`details`,{className:`rounded-md border border-border px-3 py-2`,open:!0,children:[k(`summary`,{className:`cursor-pointer text-[11px] font-semibold text-foreground`,children:`Quality`}),x(`div`,{className:`mt-2 space-y-3`,children:[k(`p`,{className:Y,children:`Every field here can be left EMPTY, and empty is a real state: a rule with a minimum confidence FAILS on a subject that carries none. Leave one blank to reproduce exactly that.`}),x(`div`,{children:[k(`label`,{className:J,children:`Label (identity name / plate / subclass)`}),k(g,{value:t.label,placeholder:`e.g. Marco, AB123CD`,onChange:e=>p({label:e.target.value})})]}),x(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[x(`div`,{children:[k(`label`,{className:J,children:`Detection confidence`}),k(En,{value:t.confidence,min:0,max:1,step:.05,onChange:e=>p({confidence:e})})]}),x(`div`,{children:[k(`label`,{className:J,children:`Label-match confidence`}),k(En,{value:t.labelConfidence,min:0,max:1,step:.05,onChange:e=>p({labelConfidence:e})})]}),x(`div`,{children:[k(`label`,{className:J,children:`Importance`}),k(En,{value:t.importance,min:0,max:1,step:.05,onChange:e=>p({importance:e})})]}),x(`div`,{children:[k(`label`,{className:J,children:`Dwell (seconds)`}),k(En,{value:t.dwellSeconds,min:0,step:1,onChange:e=>p({dwellSeconds:e})})]})]})]})]}),k(pi,{form:t,cameras:E,onPatch:p}),x(`div`,{className:`space-y-2 rounded-md border border-border px-3 py-2`,children:[k(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`How to run it`}),k(mi,{checked:t.bypassCooldown,label:`Ignore the cooldown`,hint:`A rule that already fired recently is normally silenced. Turn this on to fire anyway; leave it off to SEE the suppression.`,onChange:e=>p({bypassCooldown:e})}),k(mi,{checked:t.bypassMute,label:`Ignore mutes and snoozes`,hint:`A muted camera or a snoozed rule drops the event before any rule is consulted.`,onChange:e=>p({bypassMute:e})}),k(mi,{checked:t.runActions,danger:!0,label:`Run the rule's actions — this actuates real devices`,hint:`A matched rule's onTrigger sequences run for real: locks unlock, lights switch, sirens sound. Off unless you mean it.`,onChange:e=>p({runActions:e})}),x(`div`,{className:`max-w-[14rem]`,children:[k(`label`,{className:J,children:`Still image`}),k(m,{value:t.still,options:[{value:`live`,label:`Live snapshot of the camera`},{value:`none`,label:`No image`}],onChange:e=>p({still:e.target.value===`none`?`none`:`live`})})]}),x(`div`,{children:[k(`label`,{className:J,children:`Evaluate only one rule`}),k(m,{value:t.onlyRuleId,options:[{value:``,label:`— every enabled rule —`},...(y.data??[]).map(e=>({value:e.id,label:e.name}))],onChange:e=>p({onlyRuleId:e.target.value})}),t.onlyRuleId.length>0&&te===void 0&&x(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:[`Rule `,k(`code`,{children:t.onlyRuleId}),` is not in the current list — it may have been deleted. The run will find no candidate.`]})]})]}),d!==null&&k(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:d}),x(`div`,{className:`flex items-center justify-between gap-2`,children:[k(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Nothing is persisted: no track, no event row, no stored media. Delivery is real.`}),x(v,{size:`sm`,type:`button`,disabled:P.isPending||!Br(t),onClick:()=>P.mutate(),children:[P.isPending?k(B,{className:`h-3.5 w-3.5 animate-spin`}):k(_e,{className:`h-3.5 w-3.5`}),`Inject event`]})]})]}),s&&k(`div`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-2 text-[11px] text-foreground`,children:`The hub answered, but this build could not read the answer. That is what a hub older than the simulator looks like — update the server, then re-run.`}),a!==null&&k(_i,{result:a,targetName:e=>N.get(e)??e})]})}var Z=e=>typeof e==`string`&&e.length>0;function Ci(e){return{levels:e.levels,formats:e.format,bodyMaxLen:e.bodyMaxLen,attachmentSlots:e.attachments.mediaTypes,attachmentMode:e.attachments.mode,attachmentMax:e.attachments.max,attachmentMaxBytes:e.attachments.maxBytes,maxActions:e.actions,showActions:e.actions>0,showClickUrl:e.clickUrl,showSound:e.sound,showTtl:e.ttl,showTag:!0}}function wi(e,t){return e.format.includes(t)?t:e.format[0]??`text`}function Ti(e,t){let n=[];for(let r of e.attachments.mediaTypes){if(n.length>=e.attachments.max)break;let i=t[r];Z(i)&&n.push({mediaType:r,url:i})}return n}function Ei(e,t){if(e.actions<=0)return[];let n=[];for(let r of t){if(n.length>=e.actions)break;let t=Z(r.label),i=Z(r.url);!t&&!i||n.push({id:`test-${n.length+1}`,label:t?r.label:`Action ${n.length+1}`,...i?{url:r.url}:{}})}return n}function Di(e,t){let n=e.levels.some(e=>e.id===t.level)?t.level:void 0,r=Ti(e,t.attachmentUrls),i=Ei(e,t.actions),a=e.ttl&&Z(t.ttl)?Number(t.ttl):void 0;return{body:t.body,format:wi(e,t.format),priority:Oi(t.priority),...Z(t.title)?{title:t.title}:{},...n?{level:n}:{},...r.length>0?{attachments:r}:{},...i.length>0?{actions:i}:{},...e.clickUrl&&Z(t.clickUrl)?{clickUrl:t.clickUrl}:{},...e.sound&&Z(t.sound)?{sound:t.sound}:{},...a!==void 0&&Number.isFinite(a)?{ttl:a}:{},...Z(t.tag)?{tag:t.tag}:{}}}function Oi(e){return Number.isFinite(e)?Math.min(5,Math.max(1,Math.round(e))):3}function ki(e){return e.levels.find(e=>e.flags?.critical===!0)||e.levels.filter(e=>typeof e.ordinal==`number`).sort((e,t)=>t.ordinal-e.ordinal)[0]}function Ai(e){return{level:``,priority:3,format:e.format[0]??`text`,title:``,body:``,attachmentUrls:{},actions:[],clickUrl:``,sound:``,ttl:``,tag:``}}var ji={image:`/addon/notifiers/samples/image`,video:`/addon/notifiers/samples/video`,gif:`/addon/notifiers/samples/gif`,audio:`/addon/notifiers/samples/audio`,icon:`/addon/notifiers/samples/icon`};function Mi(e,t){return e.attachments.max>0&&e.attachments.mediaTypes.includes(t)}function Ni(e){let t=[`text`];for(let n of[`image`,`gif`,`video`,`audio`])Mi(e,n)&&t.push(n);return e.actions>0&&t.push(`actions`),e.levels.length>0&&t.push(`critical`),t.push(`overflow`),t}function Pi(e,t,n){let r=Ai(e);return Mi(e,t)?{...r,body:n,attachmentUrls:{[t]:ji[t]}}:{...r,body:n}}function Fi(e,t){let n=Ai(e);switch(t){case`text`:return{...n,title:`CamStack`,body:`Test notification — text only.`};case`image`:return Pi(e,`image`,`Test notification with an image.`);case`gif`:return Pi(e,`gif`,`Test notification with an animation.`);case`video`:return Pi(e,`video`,`Test notification with a video.`);case`audio`:return Pi(e,`audio`,`Test notification with audio.`);case`actions`:{let t=Array.from({length:e.actions},(e,t)=>({label:`Action ${t+1}`,url:`/`}));return{...n,title:`CamStack`,body:`Test notification with action buttons.`,actions:t,...e.clickUrl?{clickUrl:`/`}:{}}}case`critical`:{let t=ki(e);return{...n,title:`CamStack`,body:`Critical test notification.`,priority:5,level:t?.id??``}}case`overflow`:return{...n,body:`X`.repeat(e.bodyMaxLen+50)}}}b();var Ii={text:`Text only`,image:`With image`,gif:`With GIF`,video:`With video`,audio:`With audio`,actions:`With buttons`,critical:`Critical`,overflow:`Overflow (advanced)`},Q=`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,$=`block text-[11px] font-medium text-foreground mb-1`;function Li({target:t,kind:n,open:r,onClose:i}){let o=I(),s=S(()=>Ci(n.caps),[n.caps]),c=S(()=>Ni(n.caps),[n.caps]),[l,u]=D(()=>Ai(n.caps)),[d,m]=D(null),g=S(()=>Di(n.caps,l),[n.caps,l]),y=l.body.length,b=y>s.bodyMaxLen,C=e=>u(t=>({...t,...e})),w=O({mutationFn:()=>o.trpcClient.notificationOutput.testTarget.mutate({addonId:t.addonId,targetId:t.id,sample:Di(n.caps,l)}),onMutate:()=>m(null),onSuccess:e=>m(e),onError:e=>m({success:!1,error:e instanceof Error?e.message:`Test failed`})}),T=e=>{u(Fi(n.caps,e)),m(null)},E=(e,t,n)=>{let r=l.actions.length>0?[...l.actions]:[];for(;r.length<=e;)r.push({label:``,url:``});r[e]={...r[e],[t]:n},C({actions:r})};return k(a,{open:r,onOpenChange:e=>!e&&i(),children:x(e,{width:`lg`,className:`!max-w-2xl`,children:[k(p,{children:x(h,{children:[`Test "`,t.name,`" (`,n.label,`)`]})}),x(`div`,{className:`space-y-4 max-h-[60vh] overflow-y-auto pr-1`,children:[k(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map(e=>k(v,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>T(e),children:Ii[e]},e))}),x(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[s.levels.length>0&&x(`div`,{children:[k(`label`,{className:$,children:`Level`}),x(`select`,{className:Q,value:l.level,onChange:e=>C({level:e.target.value}),children:[k(`option`,{value:``,children:`— derive from priority —`}),s.levels.map(e=>x(`option`,{value:e.id,children:[e.label,e.ordinal===null?` (qualitative)`:` (p${e.ordinal})`]},e.id))]}),(()=>{let e=s.levels.find(e=>e.id===l.level);return e?x(`div`,{className:`mt-1 space-y-1`,children:[e.description&&k(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.description}),x(`div`,{className:`flex flex-wrap gap-1`,children:[e.flags?.critical&&k(f,{variant:`danger`,"data-testid":`flag-critical`,children:`critical`}),e.flags?.silent&&k(f,{variant:`info`,children:`silent`}),e.flags?.noPush&&k(f,{variant:`warning`,children:`no-push`})]}),e.requires&&e.requires.length>0&&x(`p`,{className:`text-[10px] text-warning`,children:[`Requires target config: `,e.requires.join(`, `)]})]}):null})()]}),x(`div`,{children:[x(`label`,{className:$,children:[`Priority (ordinal): `,l.priority]}),k(`input`,{type:`range`,min:1,max:5,step:1,value:l.priority,onChange:e=>C({priority:Number(e.target.value)}),className:`w-full accent-primary`,"aria-label":`priority`})]})]}),s.formats.length>0&&x(`div`,{children:[k(`label`,{className:$,children:`Format`}),k(`div`,{className:`flex flex-wrap gap-2`,children:s.formats.map(e=>x(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground cursor-pointer`,children:[k(`input`,{type:`radio`,name:`format`,className:`accent-primary`,checked:l.format===e,onChange:()=>C({format:e})}),e]},e))})]}),x(`div`,{children:[k(`label`,{className:$,children:`Title`}),k(`input`,{className:Q,value:l.title,onChange:e=>C({title:e.target.value})})]}),x(`div`,{children:[x(`label`,{className:$,children:[`Body`,` `,x(`span`,{className:b?`text-danger`:`text-foreground-subtle`,children:[`(`,y,`/`,s.bodyMaxLen,b?` — overflow`:``,`)`]})]}),k(`textarea`,{className:`${Q} min-h-[80px] resize-y`,value:l.body,onChange:e=>C({body:e.target.value})})]}),s.attachmentSlots.length>0&&x(`div`,{children:[x(`label`,{className:$,children:[`Attachments`,` `,x(`span`,{className:`text-foreground-subtle`,children:[`(mode: `,s.attachmentMode,`, max `,s.attachmentMax,s.attachmentMaxBytes?`, ≤${Math.round(s.attachmentMaxBytes/1024/1024)}MB`:``,`)`]})]}),k(`div`,{className:`space-y-1.5`,children:s.attachmentSlots.map(e=>x(`div`,{className:`flex items-center gap-2`,children:[k(`span`,{className:`text-[10px] w-12 shrink-0 text-foreground-subtle`,children:e}),k(`input`,{className:Q,placeholder:`${e} URL`,value:l.attachmentUrls[e]??``,onChange:t=>C({attachmentUrls:{...l.attachmentUrls,[e]:t.target.value}})})]},e))})]}),s.showActions&&x(`div`,{children:[x(`label`,{className:$,children:[`Actions (up to `,s.maxActions,`)`]}),k(`div`,{className:`space-y-1.5`,children:Array.from({length:Math.min(s.maxActions,3)},(e,t)=>x(`div`,{className:`flex items-center gap-2`,children:[k(`input`,{className:Q,placeholder:`label`,value:l.actions[t]?.label??``,onChange:e=>E(t,`label`,e.target.value)}),k(`input`,{className:Q,placeholder:`url`,value:l.actions[t]?.url??``,onChange:e=>E(t,`url`,e.target.value)})]},t))})]}),x(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[s.showClickUrl&&x(`div`,{children:[k(`label`,{className:$,children:`Click URL`}),k(`input`,{className:Q,value:l.clickUrl,onChange:e=>C({clickUrl:e.target.value})})]}),s.showSound&&x(`div`,{children:[k(`label`,{className:$,children:`Sound`}),k(`input`,{className:Q,value:l.sound,onChange:e=>C({sound:e.target.value})})]}),s.showTtl&&x(`div`,{children:[k(`label`,{className:$,children:`TTL (seconds)`}),k(`input`,{className:Q,type:`number`,value:l.ttl,onChange:e=>C({ttl:e.target.value})})]}),s.showTag&&x(`div`,{children:[k(`label`,{className:$,children:`Tag`}),k(`input`,{className:Q,value:l.tag,onChange:e=>C({tag:e.target.value})})]})]}),d&&k(Ri,{result:d}),x(`details`,{className:`text-[10px]`,children:[k(`summary`,{className:`cursor-pointer text-foreground-subtle`,children:`Payload preview`}),k(`pre`,{className:`mt-1 overflow-x-auto rounded bg-surface p-2 text-foreground-subtle`,children:JSON.stringify(g,null,2)})]})]}),x(_,{children:[k(v,{variant:`secondary`,size:`sm`,type:`button`,onClick:i,children:`Close`}),x(v,{size:`sm`,type:`button`,disabled:w.isPending||l.body.length===0,onClick:()=>w.mutate(),children:[w.isPending?k(B,{className:`h-3.5 w-3.5 animate-spin`}):k(z,{className:`h-3.5 w-3.5`}),`Send test`]})]})]})})}function Ri({result:e}){let t=e.renderedAs;return x(`div`,{className:`rounded-md border px-3 py-2 text-xs ${e.success?`border-success/40 bg-success/10`:`border-danger/40 bg-danger/10`}`,"data-testid":`test-result`,children:[x(`div`,{className:`flex items-center gap-2 font-medium`,children:[e.success?k(L,{className:`h-3.5 w-3.5 text-success`}):k(ue,{className:`h-3.5 w-3.5 text-danger`}),k(`span`,{children:e.success?`Delivered`:`Failed`})]}),e.error&&k(`p`,{className:`mt-1 text-danger`,children:e.error}),t&&x(`dl`,{className:`mt-2 grid grid-cols-2 gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[k(`dt`,{children:`Resolved level`}),k(`dd`,{className:`text-foreground`,children:t.level}),k(`dt`,{children:`Format sent`}),k(`dd`,{className:`text-foreground`,children:t.format}),k(`dt`,{children:`Attachments sent`}),k(`dd`,{className:`text-foreground`,children:t.attachmentsSent}),k(`dt`,{children:`Actions sent`}),k(`dd`,{className:`text-foreground`,children:t.actionsSent}),k(`dt`,{children:`Truncated`}),k(`dd`,{className:`text-foreground`,children:t.truncated?`yes`:`no`}),k(`dt`,{children:`Dropped`}),k(`dd`,{className:`text-foreground`,children:t.dropped.length>0?t.dropped.join(`, `):`—`})]})]})}function zi(e){let t=[],n=new Map;for(let r of e){let e=n.get(r.addonId);e?e.push(r):(n.set(r.addonId,[r]),t.push(r.addonId))}return t.map(e=>({addonId:e,kinds:n.get(e)??[]}))}function Bi(e){let t=[],n=e=>{for(let r of e){if(r.type===`password`){t.push(r.key);continue}if(r.type===`group`){n(r.fields);continue}if(r.type===`sub-tabs`)for(let e of r.tabs)n(e.fields)}};for(let t of e.sections)n(t.fields);return t}function Vi(e,t,n){let r=new Set(n),i={};for(let[n,a]of Object.entries(e)){if(!r.has(n)){i[n]=a;continue}a==null||a===``||a!==t[n]&&(i[n]=a)}return i}function Hi(e,t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))r[t]=n.has(t)?``:i;return r}b();var Ui=[`notificationOutput`,`listTargets`],Wi=[`notificationOutput`,`listTargetKinds`],Gi=[`userManagement`,`listUsers`],Ki=`ownerUserId`;function qi(e){let t=e.config[Ki];return typeof t==`string`&&t.length>0?t:null}function Ji(e){return[{key:`name`,header:`Target`,render:t=>{let n=e.kindByKey.get(t.kind);return x(`span`,{className:`flex items-center gap-2`,children:[k(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface text-xs`,title:n?.label??t.kind,children:k(Yi,{kind:n,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:``})}),k(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name}),!t.enabled&&k(f,{variant:`warning`,children:`disabled`})]})}},{key:`kind`,header:`Kind`,nowrap:!0,render:t=>k(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.kindByKey.get(t.kind)?.label??t.kind})},{key:`owner`,header:`Owner`,nowrap:!0,render:t=>{let n=qi(t);return n===null?k(f,{variant:`default`,children:`system`}):k(`span`,{className:`text-[11px] text-foreground`,children:e.userNameById.get(n)??n})}},{key:`enabled`,header:`On`,align:`center`,nowrap:!0,render:t=>k(d,{checked:t.enabled,onCheckedChange:n=>e.onToggle(t,n),"aria-label":`toggle ${t.name}`})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:t=>{let n=e.kindByKey.get(t.kind);return x(`span`,{className:`flex items-center justify-end gap-1`,children:[k(v,{size:`sm`,variant:`ghost`,type:`button`,disabled:!n,onClick:()=>e.onTest(t),title:`Test`,children:k(z,{className:`h-3.5 w-3.5`})}),k(v,{size:`sm`,variant:`ghost`,type:`button`,disabled:!n,onClick:()=>n&&e.onEdit(t,n),title:`Edit`,children:k(ie,{className:`h-3.5 w-3.5`})}),k(v,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onDelete(t),title:`Delete`,children:k(V,{className:`h-3.5 w-3.5 text-danger`})})]})}}]}function Yi({kind:e,imgClassName:t,fallbackClassName:n}){return e?.iconUrl?k(`img`,{src:e.iconUrl,alt:e.label,className:t,loading:`lazy`,draggable:!1}):k(`span`,{className:n,children:e?.icon??`🔔`})}function Xi(){let e=I(),[t,n]=D({mode:`closed`}),[i,a]=D(null),o=C({queryKey:Ui,queryFn:()=>e.trpcClient.notificationOutput.listTargets.query({})}),s=C({queryKey:Wi,queryFn:async()=>(await e.trpcClient.notificationOutput.listTargetKinds.query({})).map(e=>{let t=e.iconUrl;return{...e,configSchema:e.configSchema,iconUrl:t}})}),c=S(()=>s.data??[],[s.data]),d=S(()=>{let e=new Map;for(let t of c)e.set(t.kind,t);return e},[c]),f=C({queryKey:Gi,queryFn:()=>e.trpcClient.userManagement.listUsers.query()}),p=S(()=>{let e=new Map;for(let t of f.data??[])e.set(t.id,t.username);return e},[f.data]),m=O({mutationFn:t=>e.trpcClient.notificationOutput.setTargetEnabled.mutate({addonId:t.target.addonId,targetId:t.target.id,enabled:t.enabled}),onSuccess:()=>void o.refetch()}),h=O({mutationFn:t=>e.trpcClient.notificationOutput.deleteTarget.mutate({addonId:t.addonId,targetId:t.id}),onSuccess:()=>void o.refetch()}),g=i?d.get(i.kind):void 0;return x(H,{icon:de,title:`Notification Targets`,subtitle:`Deliver notifications to ntfy, Pushover, Telegram, Home Assistant and more. Each target's kind declares its capabilities; the test panel shows exactly what a message degrades to.`,actions:x(v,{size:`sm`,type:`button`,onClick:()=>n({mode:`pick-kind`}),children:[k(R,{className:`h-3.5 w-3.5`}),`Add target`]}),children:[o.isLoading&&k(`div`,{className:`flex items-center justify-center py-16`,children:k(B,{className:`h-6 w-6 animate-spin text-primary`})}),o.isError&&!o.isLoading&&k(l,{title:`Failed to load targets`,message:o.error instanceof Error?o.error.message:`Unknown error`,onRetry:()=>void o.refetch()}),!o.isLoading&&!o.isError&&(o.data??[]).length===0&&k(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No notification targets yet. Click "Add target" to configure one.`}),(o.data??[]).length>0&&k(u,{children:k(r,{columns:Ji({kindByKey:d,userNameById:p,onToggle:(e,t)=>m.mutate({target:e,enabled:t}),onTest:a,onEdit:(e,t)=>n({mode:`form`,kind:t,target:e}),onDelete:e=>h.mutate(e)}),rows:o.data??[],rowKey:e=>e.id,minWidthPx:720,bordered:!1})}),t.mode===`pick-kind`&&k(Zi,{kinds:c,onCancel:()=>n({mode:`closed`}),onPick:e=>n({mode:`form`,kind:e,target:null})}),t.mode===`form`&&k(Qi,{kind:t.kind,target:t.target,users:f.data??[],onCancel:()=>n({mode:`closed`}),onSaved:()=>{n({mode:`closed`}),o.refetch()}}),i&&g&&k(Li,{target:i,kind:g,open:!0,onClose:()=>a(null)})]})}function Zi({kinds:e,onPick:t,onCancel:n}){let r=S(()=>zi(e),[e]);return x(u,{className:`p-4 space-y-4`,children:[x(`div`,{className:`flex items-center justify-between`,children:[k(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Choose a notification kind`}),k(v,{size:`sm`,variant:`ghost`,type:`button`,onClick:n,children:`Cancel`})]}),r.length===0&&k(`p`,{className:`text-xs text-foreground-subtle`,children:`No notification providers are installed. Install the notifiers addon (or connect Home Assistant) to add targets.`}),r.map(e=>x(`div`,{children:[k(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5`,children:e.addonId}),k(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-2`,children:e.kinds.map(n=>x(`button`,{type:`button`,onClick:()=>t(n),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors`,children:[k(Yi,{kind:n,imgClassName:`h-7 w-7 object-contain`,fallbackClassName:`text-lg leading-7`}),k(`span`,{className:`font-medium text-foreground`,children:n.label}),n.supportsDiscovery&&k(f,{variant:`info`,style:`outline`,children:`discover`})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]})}function Qi({kind:e,target:t,users:n,onSaved:r,onCancel:i}){let a=I(),o=S(()=>Bi(e.configSchema),[e.configSchema]),c=S(()=>t?.config??{},[t]),[l,d]=D(t?.name??e.label),[f,p]=D(()=>t?Hi(t.config,o):{}),[h,g]=D(null),[_,y]=D(null),[b,C]=D(t?qi(t)??``:``),w=O({mutationFn:()=>a.trpcClient.notificationOutput.discoverTargets.query({addonId:e.addonId,kind:e.kind,config:f}),onSuccess:e=>g(e),onError:e=>y(e instanceof Error?e.message:`Discovery failed`)}),T=O({mutationFn:()=>{let{[Ki]:n,...r}=Vi(f,c,o),i=b===``?r:{...r,[Ki]:b},s={id:t?.id??`${e.kind}-${Date.now()}`,name:l,kind:e.kind,addonId:e.addonId,enabled:t?.enabled??!0,config:i};return a.trpcClient.notificationOutput.upsertTarget.mutate({addonId:e.addonId,target:s})},onSuccess:r,onError:e=>y(e instanceof Error?e.message:`Save failed`)}),E=e=>{d(e.suggestedName),p(t=>({...t,...e.config})),g(null)};return x(u,{className:`p-4 space-y-4`,children:[x(`div`,{className:`flex items-center justify-between`,children:[x(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[k(Yi,{kind:e,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:`text-lg`}),t?`Edit ${t.name}`:`Add ${e.label} target`]}),k(v,{size:`sm`,variant:`ghost`,type:`button`,onClick:i,children:`Cancel`})]}),_&&k(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:_}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Name`}),k(`input`,{className:`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,value:l,onChange:e=>d(e.target.value)})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Owner`}),k(m,{value:b,options:[{value:``,label:`System (shared, admin-managed)`},...n.map(e=>({value:e.id,label:e.username}))],onChange:e=>C(e.target.value)}),k(`p`,{className:`mt-0.5 text-[10px] text-foreground-subtle`,children:`A user-owned target belongs to that user: it shows in their viewer and their own rules may deliver to it. System targets stay admin-managed.`})]}),e.supportsDiscovery&&x(`div`,{className:`space-y-2`,children:[x(v,{size:`sm`,variant:`outline`,type:`button`,disabled:w.isPending,onClick:()=>{y(null),w.mutate()},children:[w.isPending?k(B,{className:`h-3.5 w-3.5 animate-spin`}):k(se,{className:`h-3.5 w-3.5`}),`Discover`]}),h&&h.length===0&&k(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No candidates discovered.`}),h&&h.length>0&&k(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:h.map((e,t)=>x(`button`,{type:`button`,onClick:()=>E(e),className:`flex w-full items-center justify-between px-3 py-1.5 text-xs hover:bg-surface-hover`,children:[k(`span`,{className:`text-foreground`,children:e.suggestedName}),k(`span`,{className:`text-[10px] text-primary`,children:`use`})]},`${e.suggestedName}-${t}`))})]}),o.length>0&&t&&k(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Secret fields are hidden. Leave them blank to keep the stored value; type a new value to replace it.`}),k(s,{schema:e.configSchema,values:f,onChange:p}),x(`div`,{className:`flex justify-end gap-2`,children:[k(v,{variant:`secondary`,size:`sm`,type:`button`,onClick:i,children:`Cancel`}),x(v,{size:`sm`,type:`button`,disabled:T.isPending||l.trim().length===0,onClick:()=>{y(null),T.mutate()},children:[T.isPending&&k(B,{className:`h-3.5 w-3.5 animate-spin`}),t?`Save changes`:`Create target`]})]})]})}var $i=`pipeline-analytics`,ea=`nc.getTexts`,ta=`nc.setLanguage`,na=`nc.setTextOverrides`,ra={en:`English`,it:`Italiano`};function ia(e){return e===`en`||e===`it`}function aa(e){return e===`override`||e===`shipped`||e===`fallback`}function oa(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function sa(e){if(!Array.isArray(e))return null;let t=[];for(let n of e){if(typeof n!=`string`)return null;t.push(n)}return t}function ca(e){if(!oa(e))return null;let{key:t,shipped:n,shippedLanguage:r,override:i,effective:a,source:o}=e;if(typeof t!=`string`||t.length===0||typeof n!=`string`||typeof a!=`string`||!ia(r)||!aa(o)||i!==null&&typeof i!=`string`)return null;let s=sa(e.placeholders),c=sa(e.pluralCategories);return s===null||c===null?null:{key:t,shipped:n,shippedLanguage:r,override:i,effective:a,source:o,placeholders:s,pluralCategories:c}}function la(e){if(!oa(e))return null;let{language:t,activeLanguage:n}=e;if(!ia(t)||!ia(n))return null;let r=sa(e.languages);if(r===null||r.length===0)return null;let i=[];for(let e of r)ia(e)&&i.push(e);if(i.length===0)return null;let a=e.entries;if(!Array.isArray(a))return null;let o=[];for(let e of a){let t=ca(e);if(t===null)return null;o.push(t)}return{language:t,activeLanguage:n,languages:i,entries:o}}function ua(e,t){return t.get(e.key)??e.override??e.shipped}function da(e,t){let n={};for(let r of e){let e=t.get(r.key);if(e===void 0)continue;let i=e.trim().length===0||e===r.shipped?null:e;i!==r.override&&(n[r.key]=i)}return n}function fa(e,t){return Object.keys(da(e,t)).length}function pa(e,t){let n=t.toLowerCase().split(/\s+/).filter(e=>e.length>0);return n.length===0?e:e.filter(e=>{let t=`${e.key}\n${e.shipped}\n${e.override??``}`.toLowerCase();return n.every(e=>t.includes(e))})}function ma(e){return e.placeholders.length===0?`No variables — this text is printed as written.`:`Variables: ${e.placeholders.map(e=>`{{${e}}}`).join(` `)}`}function ha(e){return e.pluralCategories.length===0?null:`This text has one form per count (${e.pluralCategories.join(`, `)}). An override replaces all of them with a single sentence.`}b();var ga=`notificationTexts`,_a=`Every sentence the Notification Center can print — and your wording for it.`;function va({entry:e,value:t,busy:n,onChange:r,onReset:i}){let a=ha(e),o=e.override!==null;return x(`div`,{className:`flex flex-col gap-1.5 rounded border border-border p-3`,"data-testid":`text-row-${e.key}`,"data-source":e.source,children:[x(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[k(`code`,{className:`text-xs font-medium`,children:e.key}),o?k(f,{variant:`info`,children:`customised`}):null,e.source===`fallback`?k(f,{variant:`warning`,children:`English fallback`}):null]}),x(`div`,{className:`flex items-start gap-2`,children:[k(g,{value:t,disabled:n,onChange:e=>r(e.target.value),className:`flex-1 font-mono text-xs`,"data-testid":`text-input-${e.key}`}),k(v,{variant:`ghost`,size:`sm`,disabled:n||!o&&t===e.shipped,onClick:i,title:`Reset to the shipped wording`,"data-testid":`text-reset-${e.key}`,children:k(oe,{className:`h-3.5 w-3.5`})})]}),x(`p`,{className:`text-xs text-foreground-subtle`,children:[k(`span`,{className:`font-medium`,children:`Shipped:`}),` `,k(`span`,{className:`font-mono`,children:e.shipped})]}),k(`p`,{className:`text-xs text-foreground-subtle`,children:ma(e)}),a===null?null:k(`p`,{className:`text-xs text-warning`,children:a})]})}function ya(){let e=I(),t=E(),[n,r]=D(null),[i,a]=D(``),[o,s]=D(new Map),[c,d]=D(!1),f=C({queryKey:[ga,n??`hub`],queryFn:async()=>{let t=la(await e.trpcClient.addons.custom.mutate({addonId:$i,action:ea,input:n===null?{}:{language:n}}));return d(t===null),t}}),p=()=>{s(new Map),t.invalidateQueries({queryKey:[ga]})},h=O({mutationFn:t=>e.trpcClient.addons.custom.mutate({addonId:$i,action:ta,input:{language:t}}),onSuccess:p}),_=O({mutationFn:t=>e.trpcClient.addons.custom.mutate({addonId:$i,action:na,input:t}),onSuccess:p}),y=f.data??null,b=S(()=>y===null?[]:pa(y.entries,i),[y,i]);if(f.isLoading)return k(H,{icon:ye,title:`Texts`,subtitle:_a,children:k(B,{className:`h-5 w-5 animate-spin`})});if(f.isError||y===null)return k(H,{icon:ye,title:`Texts`,subtitle:_a,children:k(l,{title:`The notification text catalog is not available on this hub`,message:c?`The hub answered something this admin build does not understand. Update both and reload.`:`This hub has not been updated to serve the notification text catalog yet. Deploy addon-post-analysis and reload — nothing is lost in the meantime: notifications keep using the shipped wording.`})});let w=y.language,T=h.isPending||_.isPending,A=da(y.entries,o),j=fa(y.entries,o),M=y.entries.filter(e=>e.override!==null).length,ee=y.languages.map(e=>({value:e,label:ra[e]})),N=(e,t)=>s(n=>new Map(n).set(e,t)),P=e=>N(e.key,e.shipped);return k(H,{icon:ye,title:`Texts`,subtitle:_a,children:x(`div`,{className:`flex flex-col gap-4`,children:[h.isError?k(l,{title:`Could not change the language`,message:String(h.error)}):null,_.isError?k(l,{title:`Could not save`,message:String(_.error)}):null,x(u,{className:`p-4`,children:[x(`div`,{className:`flex flex-wrap items-end gap-6`,children:[x(`div`,{className:`flex flex-col gap-1`,children:[k(`label`,{className:`text-sm font-medium`,children:`Hub language`}),k(`div`,{className:`w-44`,children:k(m,{value:y.activeLanguage,disabled:T,options:ee,onChange:e=>{let t=e.target.value;ia(t)&&h.mutate(t)},"data-testid":`texts-hub-language`})}),k(`p`,{className:`text-xs text-foreground-subtle`,children:`Every notification is written in this language.`})]}),x(`div`,{className:`flex flex-col gap-1`,children:[k(`label`,{className:`text-sm font-medium`,children:`Editing`}),k(`div`,{className:`w-44`,children:k(m,{value:w,disabled:T,options:ee,onChange:e=>{let t=e.target.value;ia(t)&&(s(new Map),r(t))},"data-testid":`texts-editing-language`})}),k(`p`,{className:`text-xs text-foreground-subtle`,children:w===y.activeLanguage?`${M} of ${y.entries.length} texts customised.`:`This hub does not speak this language — these words are not in use yet.`})]})]}),k(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:`A rule that writes its own title or body still overrides everything here — this page is the wording used when a rule does not.`})]}),x(`div`,{className:`flex items-center gap-3`,children:[x(`div`,{className:`relative flex-1`,children:[k(se,{className:`absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-muted`}),k(g,{value:i,placeholder:`Search a key or a sentence…`,onChange:e=>a(e.target.value),className:`pl-7`,"data-testid":`texts-search`})]}),x(`span`,{className:`text-xs text-foreground-subtle whitespace-nowrap`,children:[b.length,` of `,y.entries.length]}),x(v,{disabled:T||j===0,onClick:()=>_.mutate({language:w,overrides:A}),"data-testid":`texts-save`,children:[T?k(B,{className:`h-3.5 w-3.5 animate-spin`}):null,j===0?`Save`:`Save ${j}`]})]}),k(`div`,{className:`flex flex-col gap-2`,"data-testid":`texts-rows`,children:b.length===0?k(`p`,{className:`text-sm text-foreground-subtle`,children:`No text matches that search.`}):b.map(e=>k(va,{entry:e,value:ua(e,o),busy:T,onChange:t=>N(e.key,t),onReset:()=>P(e)},e.key))})]})})}var ba=`simulate`;function xa(){let[e,t]=le();return k(`div`,{className:`flex flex-col p-4`,children:k(ge,{tabs:[{id:`targets`,label:`Targets`,icon:de,content:k(Xi,{})},{id:`rules`,label:`Rules`,icon:ne,content:k(Dr,{onSimulateRule:n=>{$r(Zr(n));let r=new URLSearchParams(e);r.set(`tab`,ba),t(r,{replace:!0})}})},{id:ba,label:`Simulate`,icon:_e,content:k(Si,{})},{id:`history`,label:`History`,icon:ve,content:k(He,{})},{id:`alarm`,label:`Alarm`,icon:pe,content:k(Fe,{})},{id:`texts`,label:`Texts`,icon:ye,content:k(ya,{})}]})})}export{xa as NotificationsPage,xa as default};
|