@camstack/addon-admin-ui 1.2.47 → 1.2.49
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-D8Izx1gh.js → AddLocationWizard-BJu3mtSw.js} +1 -1
- package/dist/assets/{AddonCollectionPage-DqaifWMB.js → AddonCollectionPage-CK4v9jSU.js} +1 -1
- package/dist/assets/Addons-Dnx44V_o.js +1 -0
- package/dist/assets/{AdminTabs-qMC1WN7t.js → AdminTabs-BjQnY4OV.js} +1 -1
- package/dist/assets/{AiProfiles-CkaDb5G-.js → AiProfiles-Tiz5n9gM.js} +1 -1
- package/dist/assets/{BrokerForm-nGOoPwcx.js → BrokerForm-CUTNnLfC.js} +1 -1
- package/dist/assets/Build-BRIKYrPw.js +32 -0
- package/dist/assets/{Capabilities-BvTJQt-3.js → Capabilities-DmsUSTXd.js} +1 -1
- package/dist/assets/{CapabilityBadges-74hb8M82.js → CapabilityBadges-Da9_ag1O.js} +1 -1
- package/dist/assets/{Cluster-BdYYMi89.js → Cluster-BmsvZJvy.js} +1 -1
- package/dist/assets/{Data-D8MGzmyj.js → Data-H8wE3b6C.js} +1 -1
- package/dist/assets/DetectionIntelligence-I9-ie1ja.js +1 -0
- package/dist/assets/{DeviceAggregateSection-Tq3TjsO-.js → DeviceAggregateSection-D1VtHpJo.js} +1 -1
- package/dist/assets/DeviceDetail-DV8r8vC8.js +2 -0
- package/dist/assets/{Devices-DQeFVfTP.js → Devices-rXat7KjL.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-B2geI7HH.js → EmbedPlayerPage-DNvt-aaI.js} +1 -1
- package/dist/assets/Events-FgGu0qQ0.js +1 -0
- package/dist/assets/{FormBuilder-_oFQtE7x.js → FormBuilder-D4TCK09f.js} +1 -1
- package/dist/assets/{Identity-B9xM3PPQ.js → Identity-C7zrPYT4.js} +1 -1
- package/dist/assets/{IntegrationDetail-D6srOD52.js → IntegrationDetail-Blpd6T8m.js} +1 -1
- package/dist/assets/{Integrations-D5GsA0v6.js → Integrations-C21FuAge.js} +1 -1
- package/dist/assets/{Integrations-BMDYnEUm.js → Integrations-CWOM_mMA.js} +1 -1
- package/dist/assets/{Logs-Cr3usRtb.js → Logs-CNmLN2Va.js} +1 -1
- package/dist/assets/{MotionZonesSettings-BgF0ipHJ.js → MotionZonesSettings-Dok-N0KG.js} +1 -1
- package/dist/assets/{MyAccess-COg9lyIf.js → MyAccess-DyujbjpW.js} +1 -1
- package/dist/assets/{Network-DzuA8p3Z.js → Network-Ct57a8tW.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-BAVG1LEY.js → NodeAddonsSettingsPanel-BVpPQh6Y.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-CcxOtvMd.js → NodeInferenceDevices-DciF7oLw.js} +1 -1
- package/dist/assets/Notifications-OJ3PnTPK.js +1 -0
- package/dist/assets/Pipeline-eSN-kICU.js +1 -0
- package/dist/assets/Plates-DWVIZ4YS.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-yOIEXwrU.js → PrivacyMaskSettings-CUaRx10f.js} +1 -1
- package/dist/assets/{ProviderIcon-Ck_2pUvf.js → ProviderIcon-nTPdMviY.js} +1 -1
- package/dist/assets/Recordings-BkZiVZTc.js +1 -0
- package/dist/assets/{ScanNetworkModal-D2dbax7J.js → ScanNetworkModal-DBfj4Bdm.js} +1 -1
- package/dist/assets/{Settings-n3YjyvD9.js → Settings-BxZlSYcW.js} +1 -1
- package/dist/assets/{Showroom-kb37ihHy.js → Showroom-BwtVPGmm.js} +1 -1
- package/dist/assets/{Terminal-DPgh1LOa.js → Terminal-D-FupEae.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DD9SArM5.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DOJdLj_I.js} +1 -1
- package/dist/assets/{boxes-0BrwpGRK.js → boxes-DvSDRyF7.js} +1 -1
- package/dist/assets/{build-cluster-graph-CNmW9-To.js → build-cluster-graph-DyYa_05V.js} +1 -1
- package/dist/assets/circle-check-big-FWiOlzic.js +1 -0
- package/dist/assets/{circle-x-CeSEyt9j.js → circle-x-DtQPDgsE.js} +1 -1
- package/dist/assets/clock-DHnCdO7L.js +1 -0
- package/dist/assets/{copy-CLkoN4vv.js → copy-BfSZhaqH.js} +1 -1
- package/dist/assets/{debounced-invalidate-CjozCZrp.js → debounced-invalidate-6ffK2Oyp.js} +1 -1
- package/dist/assets/{dist-5MqZUHpg.js → dist-35X66BEr.js} +1 -1
- package/dist/assets/dist-IhEsNjtp.js +345 -0
- package/dist/assets/{download-D2kk10ws.js → download-BYiYWbFt.js} +1 -1
- package/dist/assets/{face-bbox-Dd_CKaP5.js → face-bbox-CnPEtuY2.js} +1 -1
- package/dist/assets/{hard-drive-YgwGO7Iy.js → hard-drive-DrH4p5NE.js} +1 -1
- package/dist/assets/{hostInit-DQHnlGm4.js → hostInit-CyX7yag6.js} +1 -1
- package/dist/assets/{index-qYnug9Qs.js → index-BQrlv_je.js} +3 -3
- package/dist/assets/{key-round-58wJWtml.js → key-round-dZ1BFcdp.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-d57082e0.js → mf-entry-bootstrap-0-9f224a8e.js} +2 -2
- package/dist/assets/{pencil-DDNEW9Yb.js → pencil-Bz_ZrJOa.js} +1 -1
- package/dist/assets/play-BlvH1l2D.js +1 -0
- package/dist/assets/{player-overlays-BzwYRH08.js → player-overlays-COkjFkib.js} +1 -1
- package/dist/assets/plus-C5i2pOFJ.js +1 -0
- package/dist/assets/power-w9jdL6aH.js +1 -0
- package/dist/assets/{radio-M8jdl_tl.js → radio-Db7gl-zS.js} +1 -1
- package/dist/assets/{refresh-cw-CYEUy6Ve.js → refresh-cw-CGyy1yV7.js} +1 -1
- package/dist/assets/remoteEntry-C6r9GH5z.js +1 -0
- package/dist/assets/rotate-ccw-DC6Yovo0.js +1 -0
- package/dist/assets/rotate-cw-DLAOZ01F.js +1 -0
- package/dist/assets/search-BFiLJvvR.js +1 -0
- package/dist/assets/{send-DeNrNMe8.js → send-BRkSGin7.js} +1 -1
- package/dist/assets/{server-C3tpWUwZ.js → server-BQv2rJCm.js} +1 -1
- package/dist/assets/square-DVLwx5hK.js +1 -0
- package/dist/assets/{square-check-big-DEqd8dem.js → square-check-big-Ga52OEfa.js} +1 -1
- package/dist/assets/src-Di5BmOTg.js +345 -0
- package/dist/assets/src-bB3TQU8X.js +67 -0
- package/dist/assets/{undo-2-BnRU8pkW.js → undo-2-J1RIT6Px.js} +1 -1
- package/dist/assets/{upload--4mqPfVH.js → upload-BvwaLd2o.js} +1 -1
- package/dist/assets/{useEventInvalidation-XgGxFYwt.js → useEventInvalidation-BsKdSBfH.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Cl2xnNlc.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BJpuTutd.js} +2 -2
- package/dist/assets/{wifi-C8Oz0yjQ.js → wifi-DQcK0Biw.js} +1 -1
- package/dist/assets/{zap-BQjibRA6.js → zap-B_NogjfF.js} +1 -1
- package/dist/index.html +5 -5
- package/dist/server/addon.js +109 -7
- package/package.json +1 -1
- package/dist/assets/Addons-Cbum2Ue7.js +0 -1
- package/dist/assets/Build-D4A-vNUJ.js +0 -32
- package/dist/assets/DetectionIntelligence-E410sfaW.js +0 -1
- package/dist/assets/DeviceDetail-Cyp63o9e.js +0 -2
- package/dist/assets/Events-tUp70vOo.js +0 -1
- package/dist/assets/Notifications-mGunk-af.js +0 -1
- package/dist/assets/Pipeline-YdFX0pzB.js +0 -1
- package/dist/assets/Plates-BZ8XXBRF.js +0 -1
- package/dist/assets/Recordings-DN2qpsF8.js +0 -1
- package/dist/assets/circle-check-big-CX86TDQ3.js +0 -1
- package/dist/assets/clock-dbqOPTlc.js +0 -1
- package/dist/assets/dist-Bayrm69X.js +0 -345
- package/dist/assets/play-rmom08n0.js +0 -1
- package/dist/assets/plus-DW_KHfhe.js +0 -1
- package/dist/assets/power-DV05ZWPi.js +0 -1
- package/dist/assets/remoteEntry-BAJ0ezfD.js +0 -1
- package/dist/assets/rotate-ccw-DTUvT-HV.js +0 -1
- package/dist/assets/rotate-cw-DWJibY6w.js +0 -1
- package/dist/assets/search-BVDP_pJD.js +0 -1
- package/dist/assets/square-C5l0pveB.js +0 -1
- package/dist/assets/src-BoczRE1G.js +0 -67
- package/dist/assets/src-Bok3PEiz.js +0 -345
package/dist/assets/{NodeAddonsSettingsPanel-BAVG1LEY.js → NodeAddonsSettingsPanel-BVpPQh6Y.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Rt as e,dt as t,on as n,ut as r,yt as i}from"./src-BoczRE1G.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{Z as y}from"./src-Bok3PEiz.js";import{p as ee}from"./player-overlays-BzwYRH08.js";import{t as b}from"./FormBuilder-_oFQtE7x.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-bB3TQU8X.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-Di5BmOTg.js";import{p as ee}from"./player-overlays-COkjFkib.js";import{t as b}from"./FormBuilder-D4TCK09f.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-BoczRE1G.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-BQjibRA6.js";import{P as _,W as v,a as y,j as b,x}from"./index-qYnug9Qs.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{$o as e,Bi as t,En as n,Mn as r,On as i,is as a,ki as o}from"./src-bB3TQU8X.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-B_NogjfF.js";import{P as _,W as v,a as y,j as b,x}from"./index-BQrlv_je.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{$o as e,Fo as t,Io as n,Jo as r,Lo as i,Po as a,Qn as o,Qo as s,S as c,Xo as l,Zo as u,aa as d,as as f,is as p,jo as m,ns as h,qo as g,rs as _,ts as v,vo as y}from"./src-bB3TQU8X.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,F as ee,b as te,c as M,o as N,s as P,w as ne}from"./src-Di5BmOTg.js";import{p as F}from"./player-overlays-COkjFkib.js";import{t as I}from"./circle-check-big-FWiOlzic.js";import{t as re}from"./copy-BfSZhaqH.js";import{t as ie}from"./pencil-Bz_ZrJOa.js";import{t as L}from"./plus-C5i2pOFJ.js";import{t as ae}from"./refresh-cw-CGyy1yV7.js";import{t as oe}from"./search-BFiLJvvR.js";import{t as se}from"./send-BRkSGin7.js";import{J as R,N as ce,S as z,V as le,W as ue,f as de,i as fe,o as pe,s as B}from"./index-BQrlv_je.js";import{t as V}from"./AdminPage-Dq33XE9j.js";import{t as me}from"./AdminTabs-BjQnY4OV.js";var he=ue(`bell-off`,[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742`,key:`178tsu`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05`,key:`1hqiys`}]]),ge=ue(`bell-ring`,[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M22 8c0-2.3-.8-4.3-2-6`,key:`5bb3ad`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}],[`path`,{d:`M4 2C2.8 3.7 2 5.7 2 8`,key:`tap9e0`}]]),_e=ue(`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=ue(`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`}]]);b();var H=e=>typeof e==`string`&&e.length>0;function ye(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 be(e,t){return e.format.includes(t)?t:e.format[0]??`text`}function xe(e,t){let n=[];for(let r of e.attachments.mediaTypes){if(n.length>=e.attachments.max)break;let i=t[r];H(i)&&n.push({mediaType:r,url:i})}return n}function Se(e,t){if(e.actions<=0)return[];let n=[];for(let r of t){if(n.length>=e.actions)break;let t=H(r.label),i=H(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 Ce(e,t){let n=e.levels.some(e=>e.id===t.level)?t.level:void 0,r=xe(e,t.attachmentUrls),i=Se(e,t.actions),a=e.ttl&&H(t.ttl)?Number(t.ttl):void 0;return{body:t.body,format:be(e,t.format),priority:we(t.priority),...H(t.title)?{title:t.title}:{},...n?{level:n}:{},...r.length>0?{attachments:r}:{},...i.length>0?{actions:i}:{},...e.clickUrl&&H(t.clickUrl)?{clickUrl:t.clickUrl}:{},...e.sound&&H(t.sound)?{sound:t.sound}:{},...a!==void 0&&Number.isFinite(a)?{ttl:a}:{},...H(t.tag)?{tag:t.tag}:{}}}function we(e){return Number.isFinite(e)?Math.min(5,Math.max(1,Math.round(e))):3}function Te(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 Ee(e){return{level:``,priority:3,format:e.format[0]??`text`,title:``,body:``,attachmentUrls:{},actions:[],clickUrl:``,sound:``,ttl:``,tag:``}}var De={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 Oe(e,t){return e.attachments.max>0&&e.attachments.mediaTypes.includes(t)}function ke(e){let t=[`text`];for(let n of[`image`,`gif`,`video`,`audio`])Oe(e,n)&&t.push(n);return e.actions>0&&t.push(`actions`),e.levels.length>0&&t.push(`critical`),t.push(`overflow`),t}function Ae(e,t,n){let r=Ee(e);return Oe(e,t)?{...r,body:n,attachmentUrls:{[t]:De[t]}}:{...r,body:n}}function je(e,t){let n=Ee(e);switch(t){case`text`:return{...n,title:`CamStack`,body:`Test notification — text only.`};case`image`:return Ae(e,`image`,`Test notification with an image.`);case`gif`:return Ae(e,`gif`,`Test notification with an animation.`);case`video`:return Ae(e,`video`,`Test notification with a video.`);case`audio`:return Ae(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=Te(e);return{...n,title:`CamStack`,body:`Critical test notification.`,priority:5,level:t?.id??``}}case`overflow`:return{...n,body:`X`.repeat(e.bodyMaxLen+50)}}}var Me={text:`Text only`,image:`With image`,gif:`With GIF`,video:`With video`,audio:`With audio`,actions:`With buttons`,critical:`Critical`,overflow:`Overflow (advanced)`},U=`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`,W=`block text-[11px] font-medium text-foreground mb-1`;function Ne({target:e,kind:t,open:n,onClose:i}){let a=F(),o=S(()=>ye(t.caps),[t.caps]),c=S(()=>ke(t.caps),[t.caps]),[d,m]=D(()=>Ee(t.caps)),[h,_]=D(null),v=S(()=>Ce(t.caps,d),[t.caps,d]),y=d.body.length,b=y>o.bodyMaxLen,C=e=>m(t=>({...t,...e})),w=O({mutationFn:()=>a.trpcClient.notificationOutput.testTarget.mutate({addonId:e.addonId,targetId:e.id,sample:Ce(t.caps,d)}),onMutate:()=>_(null),onSuccess:e=>_(e),onError:e=>_({success:!1,error:e instanceof Error?e.message:`Test failed`})}),T=e=>{m(je(t.caps,e)),_(null)},E=(e,t,n)=>{let r=d.actions.length>0?[...d.actions]:[];for(;r.length<=e;)r.push({label:``,url:``});r[e]={...r[e],[t]:n},C({actions:r})};return k(g,{open:n,onOpenChange:e=>!e&&i(),children:x(r,{width:`lg`,className:`!max-w-2xl`,children:[k(u,{children:x(s,{children:[`Test "`,e.name,`" (`,t.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(f,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>T(e),children:Me[e]},e))}),x(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[o.levels.length>0&&x(`div`,{children:[k(`label`,{className:W,children:`Level`}),x(`select`,{className:U,value:d.level,onChange:e=>C({level:e.target.value}),children:[k(`option`,{value:``,children:`— derive from priority —`}),o.levels.map(e=>x(`option`,{value:e.id,children:[e.label,e.ordinal===null?` (qualitative)`:` (p${e.ordinal})`]},e.id))]}),(()=>{let e=o.levels.find(e=>e.id===d.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(p,{variant:`danger`,"data-testid":`flag-critical`,children:`critical`}),e.flags?.silent&&k(p,{variant:`info`,children:`silent`}),e.flags?.noPush&&k(p,{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:W,children:[`Priority (ordinal): `,d.priority]}),k(`input`,{type:`range`,min:1,max:5,step:1,value:d.priority,onChange:e=>C({priority:Number(e.target.value)}),className:`w-full accent-primary`,"aria-label":`priority`})]})]}),o.formats.length>0&&x(`div`,{children:[k(`label`,{className:W,children:`Format`}),k(`div`,{className:`flex flex-wrap gap-2`,children:o.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:d.format===e,onChange:()=>C({format:e})}),e]},e))})]}),x(`div`,{children:[k(`label`,{className:W,children:`Title`}),k(`input`,{className:U,value:d.title,onChange:e=>C({title:e.target.value})})]}),x(`div`,{children:[x(`label`,{className:W,children:[`Body`,` `,x(`span`,{className:b?`text-danger`:`text-foreground-subtle`,children:[`(`,y,`/`,o.bodyMaxLen,b?` — overflow`:``,`)`]})]}),k(`textarea`,{className:`${U} min-h-[80px] resize-y`,value:d.body,onChange:e=>C({body:e.target.value})})]}),o.attachmentSlots.length>0&&x(`div`,{children:[x(`label`,{className:W,children:[`Attachments`,` `,x(`span`,{className:`text-foreground-subtle`,children:[`(mode: `,o.attachmentMode,`, max `,o.attachmentMax,o.attachmentMaxBytes?`, ≤${Math.round(o.attachmentMaxBytes/1024/1024)}MB`:``,`)`]})]}),k(`div`,{className:`space-y-1.5`,children:o.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:U,placeholder:`${e} URL`,value:d.attachmentUrls[e]??``,onChange:t=>C({attachmentUrls:{...d.attachmentUrls,[e]:t.target.value}})})]},e))})]}),o.showActions&&x(`div`,{children:[x(`label`,{className:W,children:[`Actions (up to `,o.maxActions,`)`]}),k(`div`,{className:`space-y-1.5`,children:Array.from({length:Math.min(o.maxActions,3)},(e,t)=>x(`div`,{className:`flex items-center gap-2`,children:[k(`input`,{className:U,placeholder:`label`,value:d.actions[t]?.label??``,onChange:e=>E(t,`label`,e.target.value)}),k(`input`,{className:U,placeholder:`url`,value:d.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:[o.showClickUrl&&x(`div`,{children:[k(`label`,{className:W,children:`Click URL`}),k(`input`,{className:U,value:d.clickUrl,onChange:e=>C({clickUrl:e.target.value})})]}),o.showSound&&x(`div`,{children:[k(`label`,{className:W,children:`Sound`}),k(`input`,{className:U,value:d.sound,onChange:e=>C({sound:e.target.value})})]}),o.showTtl&&x(`div`,{children:[k(`label`,{className:W,children:`TTL (seconds)`}),k(`input`,{className:U,type:`number`,value:d.ttl,onChange:e=>C({ttl:e.target.value})})]}),o.showTag&&x(`div`,{children:[k(`label`,{className:W,children:`Tag`}),k(`input`,{className:U,value:d.tag,onChange:e=>C({tag:e.target.value})})]})]}),h&&k(Pe,{result:h}),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(v,null,2)})]})]}),x(l,{children:[k(f,{variant:`secondary`,size:`sm`,type:`button`,onClick:i,children:`Close`}),x(f,{size:`sm`,type:`button`,disabled:w.isPending||d.body.length===0,onClick:()=>w.mutate(),children:[w.isPending?k(z,{className:`h-3.5 w-3.5 animate-spin`}):k(se,{className:`h-3.5 w-3.5`}),`Send test`]})]})]})})}function Pe({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(I,{className:`h-3.5 w-3.5 text-success`}):k(ce,{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 Fe(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 Ie(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 Le(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 Re(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 ze=[`notificationOutput`,`listTargets`],Be=[`notificationOutput`,`listTargetKinds`],Ve=[`userManagement`,`listUsers`],He=`ownerUserId`;function Ue(e){let t=e.config[He];return typeof t==`string`&&t.length>0?t:null}function We(t){return[{key:`name`,header:`Target`,render:e=>{let n=t.kindByKey.get(e.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??e.kind,children:k(Ge,{kind:n,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:``})}),k(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),!e.enabled&&k(p,{variant:`warning`,children:`disabled`})]})}},{key:`kind`,header:`Kind`,nowrap:!0,render:e=>k(`span`,{className:`text-[11px] text-foreground-subtle`,children:t.kindByKey.get(e.kind)?.label??e.kind})},{key:`owner`,header:`Owner`,nowrap:!0,render:e=>{let n=Ue(e);return n===null?k(p,{variant:`default`,children:`system`}):k(`span`,{className:`text-[11px] text-foreground`,children:t.userNameById.get(n)??n})}},{key:`enabled`,header:`On`,align:`center`,nowrap:!0,render:n=>k(e,{checked:n.enabled,onCheckedChange:e=>t.onToggle(n,e),"aria-label":`toggle ${n.name}`})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:e=>{let n=t.kindByKey.get(e.kind);return x(`span`,{className:`flex items-center justify-end gap-1`,children:[k(f,{size:`sm`,variant:`ghost`,type:`button`,disabled:!n,onClick:()=>t.onTest(e),title:`Test`,children:k(se,{className:`h-3.5 w-3.5`})}),k(f,{size:`sm`,variant:`ghost`,type:`button`,disabled:!n,onClick:()=>n&&t.onEdit(e,n),title:`Edit`,children:k(ie,{className:`h-3.5 w-3.5`})}),k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t.onDelete(e),title:`Delete`,children:k(B,{className:`h-3.5 w-3.5 text-danger`})})]})}}]}function Ge({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 Ke(){let e=F(),[t,n]=D({mode:`closed`}),[r,i]=D(null),a=C({queryKey:ze,queryFn:()=>e.trpcClient.notificationOutput.listTargets.query({})}),o=C({queryKey:Be,queryFn:async()=>(await e.trpcClient.notificationOutput.listTargetKinds.query({})).map(e=>{let t=e.iconUrl;return{...e,configSchema:e.configSchema,iconUrl:t}})}),s=S(()=>o.data??[],[o.data]),c=S(()=>{let e=new Map;for(let t of s)e.set(t.kind,t);return e},[s]),l=C({queryKey:Ve,queryFn:()=>e.trpcClient.userManagement.listUsers.query()}),u=S(()=>{let e=new Map;for(let t of l.data??[])e.set(t.id,t.username);return e},[l.data]),d=O({mutationFn:t=>e.trpcClient.notificationOutput.setTargetEnabled.mutate({addonId:t.target.addonId,targetId:t.target.id,enabled:t.enabled}),onSuccess:()=>void a.refetch()}),p=O({mutationFn:t=>e.trpcClient.notificationOutput.deleteTarget.mutate({addonId:t.addonId,targetId:t.id}),onSuccess:()=>void a.refetch()}),h=r?c.get(r.kind):void 0;return x(V,{icon:le,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(f,{size:`sm`,type:`button`,onClick:()=>n({mode:`pick-kind`}),children:[k(L,{className:`h-3.5 w-3.5`}),`Add target`]}),children:[a.isLoading&&k(`div`,{className:`flex items-center justify-center py-16`,children:k(z,{className:`h-6 w-6 animate-spin text-primary`})}),a.isError&&!a.isLoading&&k(y,{title:`Failed to load targets`,message:a.error instanceof Error?a.error.message:`Unknown error`,onRetry:()=>void a.refetch()}),!a.isLoading&&!a.isError&&(a.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.`}),(a.data??[]).length>0&&k(_,{children:k(m,{columns:We({kindByKey:c,userNameById:u,onToggle:(e,t)=>d.mutate({target:e,enabled:t}),onTest:i,onEdit:(e,t)=>n({mode:`form`,kind:t,target:e}),onDelete:e=>p.mutate(e)}),rows:a.data??[],rowKey:e=>e.id,minWidthPx:720,bordered:!1})}),t.mode===`pick-kind`&&k(qe,{kinds:s,onCancel:()=>n({mode:`closed`}),onPick:e=>n({mode:`form`,kind:e,target:null})}),t.mode===`form`&&k(Je,{kind:t.kind,target:t.target,users:l.data??[],onCancel:()=>n({mode:`closed`}),onSaved:()=>{n({mode:`closed`}),a.refetch()}}),r&&h&&k(Ne,{target:r,kind:h,open:!0,onClose:()=>i(null)})]})}function qe({kinds:e,onPick:t,onCancel:n}){let r=S(()=>Fe(e),[e]);return x(_,{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(f,{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(Ge,{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(p,{variant:`info`,style:`outline`,children:`discover`})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]})}function Je({kind:e,target:t,users:n,onSaved:r,onCancel:i}){let a=F(),o=S(()=>Ie(e.configSchema),[e.configSchema]),s=S(()=>t?.config??{},[t]),[l,u]=D(t?.name??e.label),[d,p]=D(()=>t?Re(t.config,o):{}),[m,h]=D(null),[g,y]=D(null),[b,C]=D(t?Ue(t)??``:``),w=O({mutationFn:()=>a.trpcClient.notificationOutput.discoverTargets.query({addonId:e.addonId,kind:e.kind,config:d}),onSuccess:e=>h(e),onError:e=>y(e instanceof Error?e.message:`Discovery failed`)}),T=O({mutationFn:()=>{let{[He]:n,...r}=Le(d,s,o),i=b===``?r:{...r,[He]:b},c={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:c})},onSuccess:r,onError:e=>y(e instanceof Error?e.message:`Save failed`)}),E=e=>{u(e.suggestedName),p(t=>({...t,...e.config})),h(null)};return x(_,{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(Ge,{kind:e,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:`text-lg`}),t?`Edit ${t.name}`:`Add ${e.label} target`]}),k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:i,children:`Cancel`})]}),g&&k(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:g}),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=>u(e.target.value)})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Owner`}),k(v,{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(f,{size:`sm`,variant:`outline`,type:`button`,disabled:w.isPending,onClick:()=>{y(null),w.mutate()},children:[w.isPending?k(z,{className:`h-3.5 w-3.5 animate-spin`}):k(oe,{className:`h-3.5 w-3.5`}),`Discover`]}),m&&m.length===0&&k(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No candidates discovered.`}),m&&m.length>0&&k(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:m.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(c,{schema:e.configSchema,values:d,onChange:p}),x(`div`,{className:`flex justify-end gap-2`,children:[k(f,{variant:`secondary`,size:`sm`,type:`button`,onClick:i,children:`Cancel`}),x(f,{size:`sm`,type:`button`,disabled:T.isPending||l.trim().length===0,onClick:()=>{y(null),T.mutate()},children:[T.isPending&&k(z,{className:`h-3.5 w-3.5 animate-spin`}),t?`Save changes`:`Create target`]})]})]})}var Ye=[{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`}],Xe={sequences:[],buttons:[]};function Ze(e){return e===void 0?Xe:{sequences:[...e.onTrigger??[]],buttons:[...e.buttons??[]]}}function Qe(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 $e(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 et(e){return{name:`sequence ${String(e+1)}`,enabled:!1,actions:[]}}function tt(e,t){return{id:`action-${String(e+1)}`,label:`Action`,sequence:t}}function nt(){return{kind:`wait`,seconds:5}}var G=`mt-1 w-full rounded border border-border bg-background px-2 py-1 text-xs`,K=`block text-[11px] font-medium text-foreground`;function rt({value:e,onChange:t,devices:n}){let r=$e(e),i=(n,r)=>t({...e,sequences:e.sequences.map((e,t)=>t===n?r:e)}),a=(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(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t({...e,sequences:[...e.sequences,et(e.sequences.length)]}),children:[k(L,{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,a)=>k(it,{sequence:r,devices:n,onChange:e=>i(a,e),onRemove:()=>t({...e,sequences:e.sequences.filter((e,t)=>t!==a)})},`seq-${String(a)}`))]}),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(f,{size:`sm`,variant:`ghost`,type:`button`,disabled:e.sequences.length===0,onClick:()=>t({...e,buttons:[...e.buttons,tt(e.buttons.length,e.sequences[0]?.name??``)]}),children:[k(L,{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(pe,{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(st,{button:n,sequenceNames:e.sequences.map(e=>e.name),onChange:e=>a(r,e),onRemove:()=>t({...e,buttons:e.buttons.filter((e,t)=>t!==r)})},`btn-${String(r)}`))]})]})}function it({sequence:t,devices:n,onChange:r,onRemove:i}){let a=(e,n)=>r({...t,actions:t.actions.map((t,r)=>r===e?n:t)});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:K,children:`Name`}),k(h,{className:`mt-1`,value:t.name,onChange:e=>r({...t,name:e.target.value})})]}),x(`div`,{className:`w-28`,children:[k(`label`,{className:K,children:`Min delay (s)`}),k(`input`,{type:`number`,min:0,className:G,value:t.minDelaySec??``,onChange:e=>{let n=e.target.value,i={...t};n===``?delete i.minDelaySec:i.minDelaySec=Number(n),r(i)}})]}),x(`div`,{className:`flex items-center gap-2 pb-1`,children:[k(e,{checked:t.enabled,onCheckedChange:e=>r({...t,enabled:e})}),k(`span`,{className:`text-[11px] text-foreground-subtle`,children:t.enabled?`Runs on match`:`Only when a button is tapped`})]}),k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:i,title:`Remove`,children:k(B,{className:`h-3.5 w-3.5`})})]}),x(`div`,{className:`space-y-2 border-l-2 border-border-subtle pl-3`,children:[t.actions.map((e,i)=>k(at,{step:e,devices:n,onChange:e=>a(i,e),onRemove:()=>r({...t,actions:t.actions.filter((e,t)=>t!==i)})},`step-${String(i)}`)),x(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>r({...t,actions:[...t.actions,nt()]}),children:[k(L,{className:`h-3.5 w-3.5`}),` Step`]})]})]})}function at({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:K,children:`Step`}),x(`select`,{className:G,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:K,children:`Seconds`}),k(`input`,{type:`number`,min:0,max:300,className:G,value:e.seconds,onChange:e=>n({kind:`wait`,seconds:Number(e.target.value)})})]}):k(ot,{step:e,devices:t,onChange:n}),k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,title:`Remove step`,children:k(B,{className:`h-3.5 w-3.5`})})]})}function ot({step:e,devices:t,onChange:n}){let r=F(),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:K,children:`Device`}),x(`select`,{className:G,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:K,children:`Capability`}),x(`select`,{className:G,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:K,children:`Method`}),k(h,{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:K,children:`Arguments (JSON)`}),k(h,{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 st({button:t,sequenceNames:n,onChange:r,onRemove:i}){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:K,children:`Label`}),k(h,{className:`mt-1`,value:t.label,onChange:e=>r({...t,label:e.target.value})})]}),x(`div`,{className:`min-w-[8rem] flex-1`,children:[k(`label`,{className:K,children:`Runs`}),x(`select`,{className:G,value:t.sequence,onChange:e=>r({...t,sequence:e.target.value}),children:[!n.includes(t.sequence)&&x(`option`,{value:t.sequence,children:[t.sequence,` (missing)`]}),n.map(e=>k(`option`,{value:e,children:e},e))]})]}),x(`div`,{className:`w-32`,children:[k(`label`,{className:K,children:`Icon`}),x(`select`,{className:G,value:t.icon??``,onChange:e=>{let n={...t};if(e.target.value===``)delete n.icon;else{let t=Ye.find(t=>t.value===e.target.value);t!==void 0&&(n.icon=t.value)}r(n)},children:[k(`option`,{value:``,children:`None`}),Ye.map(e=>k(`option`,{value:e.value,children:e.label},e.value))]})]}),x(`div`,{className:`flex items-center gap-2 pb-1`,children:[k(e,{checked:t.destructive===!0,onCheckedChange:e=>{let n={...t};e?n.destructive=!0:delete n.destructive,r(n)}}),k(p,{variant:t.destructive===!0?`danger`:`default`,children:`Destructive style`})]}),k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:i,title:`Remove`,children:k(B,{className:`h-3.5 w-3.5`})})]})}var ct={search:``,types:[],selectedOnly:!1};function lt(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 ut(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 dt(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 ft(e,t){let n=new Set(t);for(let t of e)n.add(t.id);return[...n]}function pt(e,t){let n=new Set(e.map(e=>e.id));return t.filter(e=>!n.has(e))}function mt(e,t){return e.length===0?`Every device (${String(t)}) — no restriction`:`${String(e.length)} of ${String(t)} selected`}b();function ht({devices:e,value:t,onChange:n,loading:r=!1}){let[i,a]=D(ct),o=S(()=>lt(e),[e]),s=S(()=>ut(e,i,t),[e,i,t]),c=S(()=>dt(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:mt(t,e.length)}),x(`div`,{className:`flex items-center gap-1`,children:[k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>n(ft(s,t)),children:`Select shown`}),k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>n(pt(s,t)),children:`Clear shown`})]})]}),x(`div`,{className:`flex flex-wrap items-center gap-2`,children:[k(h,{className:`min-w-[10rem] flex-1`,value:i.search,placeholder:`Search by name…`,leftSlot:k(oe,{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(p,{variant:`default`,children:e.type})]},e.id))})]},e.location??`__unplaced`))})]})}function q(e){return t=>Object.prototype.hasOwnProperty.call(e,t)}var gt=q({devices:!0}),_t=q({classes:!0,classesExclude:!0,labelEquals:!0,identities:!0,identitiesExclude:!0,eventTypeTokens:!0,sensorKinds:!0}),vt=q({zonesExclude:!0}),yt=q({minConfidence:!0,minImportance:!0,minLabelConfidence:!0}),bt=q({minDwellSeconds:!0}),xt=q({source:!0}),St=q({crossing:!0}),Ct=q({packagePhase:!0}),wt=q({zones:!0}),Tt=q({plates:!0}),Et=q({occupancy:!0}),Dt=q({systemEvent:!0}),Ot=q({deviceState:!0});function kt(e,t){let n=e[t];return Array.isArray(n)?n:[]}function At(e,t){let n=e[t];return typeof n==`number`?n:void 0}var jt=[{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 Mt(e){let t=e.replace(/[-_]/g,` `);return t.charAt(0).toUpperCase()+t.slice(1)}function Nt(e,t){let n=e.filter(t),r=new Set(jt.map(e=>e.id)),i=[];for(let e of jt){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:Mt(e),descriptors:n.filter(t=>t.group===e)});return i}b();function Pt(e,t){let n=F().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 Ft(e){let t=F().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 It(){let e=o();return S(()=>({options:(e.data??[]).map(e=>({value:e.name,label:e.name})),loading:e.isLoading}),[e.data,e.isLoading])}function Lt(){let e=d({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 J({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 Rt=[{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 zt(e){return Rt.find(t=>t.value===e)?.label??e}function Bt(e){return Rt.find(t=>t.value===e)?.value}function Vt(e){return Rt.some(t=>t.value===e)}function Y(e){return e===`system-event`}var Ht=[{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 Ut(e){return Ht.find(t=>t.key===e)?.key}function Wt(e,t){return t===`all`?!0:t===`system`?Y(e):!Y(e)}function Gt(e){return e===`system`?`system-event`:`immediate`}var Kt=[{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 qt(e){let t=Kt.find(t=>t.value===e);return t?t.label:e%3600==0?`${e/3600} hours`:e%60==0?`${e/60} minutes`:`${e} seconds`}function Jt(e){return Kt.some(t=>t.value===e)?Kt:[...Kt,{value:e,label:qt(e)}].toSorted((e,t)=>e.value-t.value)}function Yt(e){if(e.trim().length===0)return;let t=Number(e);return Number.isFinite(t)&&t>=0?t:void 0}var Xt=[{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 Zt(e){return Xt.find(t=>t.value===e)?.value}var Qt=[{value:``,label:`Automatic`},{value:`cropped`,label:`Cropped on the subject`},{value:`full`,label:`Full frame`},{value:`boxed`,label:`Full frame with boxes`}];function $t(e){let t=Qt.find(t=>t.value===e)?.value;return t===``?void 0:t}var en=[{value:``,label:`Lowest available`},{value:`low`,label:`Low`},{value:`mid`,label:`Medium`},{value:`high`,label:`High`}];function tn(e){let t=en.find(t=>t.value===e)?.value;return t===``?void 0:t}var nn=[{value:`any`,label:`Any source`},{value:`pipeline`,label:`Pipeline`},{value:`onboard`,label:`Onboard (camera)`},{value:`sensor`,label:`Sensor`}],rn=[{value:`delivered`,label:`Delivered`},{value:`picked-up`,label:`Picked up`},{value:`both`,label:`Both`}],an=[{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 on(e){let t=an.find(t=>t.value===e)?.value;return t===``||t===void 0?void 0:t}var sn=[{value:`any`,label:`Any of`},{value:`all`,label:`All of`}],cn=[{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 ln(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:Xe,deviceIds:[],cooldownSec:60}}function un(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:Ze(e.actions),deviceIds:e.conditions.devices??[],cooldownSec:e.throttle.cooldownSec}}function dn(e){return Vt(e.delivery)&&(!Y(e.delivery)||fn(e)>0)&&e.name.trim().length>0&&(e.targetIds.length>0||e.targetUsers.length>0)&&$e(e.actions).length===0}function fn(e){return e.conditions.systemEvent?.kinds.length??0}function pn(e,t){return e.appliesTo.includes(t)}var mn={source:`any`};function hn(e,t){if(t==null)return!0;if(Array.isArray(t))return t.length===0;if(typeof t==`string`)return t.length===0||mn[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 gn(e,t,n){let r=n.length===0?null:new Set(n.filter(e=>e.id!==`schedule`&&pn(e,t)).map(e=>e.id)),i={};for(let[t,n]of Object.entries(e))r!==null&&!r.has(t)||hn(t,n)||(i[t]=n);return i}function _n(e){return e!==void 0&&e.windows.length>0}function vn(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=Qe(e.actions),s=(n.length===0||n.some(t=>t.id===`schedule`&&pn(t,e.delivery)))&&_n(e.schedule)?e.schedule:void 0,c=n.length===0?!0:n.some(t=>t.id===`devices`&&pn(t,e.delivery));return{name:e.name.trim(),enabled:e.enabled,delivery:e.delivery,conditions:{...gn(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:Y(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 yn(e,t){return e.options&&e.options.length>0?e.options:t}var bn=[{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 xn(e){if(e===``)return;let t=Number(e);return Number.isFinite(t)&&t>=1&&t<=8?t:void 0}var Sn=[{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 Cn(e){return Y(e)?Sn.filter(e=>e.key!==`devices`).map(e=>e.key===`conditions`?{...e,label:`Events`}:e):Sn}var wn=`rule`;function Tn(e){return Sn.find(t=>t.key===e)?.key}b();var X=`block text-[11px] font-medium text-foreground`,Z=`text-[10px] text-foreground-subtle mt-0.5`;function En({cameras:e,value:t,onChange:n}){if(e.length===0)return k(`p`,{className:Z,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 Dn({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(fe,{className:`h-3 w-3`})})]},e))}),k(h,{value:r,placeholder:t,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),a())},onBlur:a})]})}function On({picker:e,value:t,onChange:n}){let r=S(()=>P(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 Q({value:e,min:t,max:n,step:r,onChange:i}){return x(`div`,{className:`mt-1 flex items-center gap-2`,children:[k(h,{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 kn({value:e,onChange:t,options:n}){let r=e??``,i=n&&n.length>0?n:an,a=i.find(e=>e.value===r);return x(`div`,{className:`mt-1 space-y-1`,children:[k(v,{value:r,options:i.map(e=>({value:e.value,label:e.label})),onChange:e=>t(on(e.target.value))}),a!==void 0&&k(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:a.hint})]})}function An({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(v,{value:a,options:sn.map(e=>({value:e.value,label:e.label})),onChange:e=>s(e.target.value===`all`?`all`:`any`)})}),k(jn,{deviceIds:e,cameras:t,value:i,onChange:o})]})}function jn({deviceIds:e,cameras:t,value:n,onChange:r}){let{options:i,loading:a}=Pt(e,t);return k(J,{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 Mn({value:e,onChange:t}){let{options:n,loading:r}=It();return k(J,{options:n,value:e,onChange:t,loading:r,emptyHint:`No identities in the face gallery yet — type a name.`,placeholder:`Identity name…`})}function Nn({deviceIds:e,value:t,onChange:n}){let{options:r,loading:i}=Ft(e);return k(J,{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 Pn=[{value:`became-occupied`,label:`Became occupied`},{value:`became-free`,label:`Became free`},{value:`>=`,label:`Count ≥`},{value:`<=`,label:`Count ≤`}],Fn={op:`became-occupied`,count:1,sustainSeconds:15};function In({deviceIds:e,cameras:t,classOptions:n,value:r,onChange:i}){let{options:a,loading:o}=Pt(e,t),s=r??Fn,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(v,{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(v,{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(v,{value:s.op,options:Pn.map(e=>({value:e.value,label:e.label})),onChange:e=>{let t=Pn.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(h,{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(h,{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 Ln({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=Lt().filter(e=>!n.includes(e));return x(`div`,{className:`mt-1 space-y-1.5`,children:[k(Dn,{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(h,{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 Rn({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(v,{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 zn=[{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 Bn(e){let t=Math.floor(e/60),n=e%60;return`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}`}function Vn(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 Hn(){return{days:[1,2,3,4,5],startMinute:540,endMinute:1080}}function Un({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,Hn()],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:Z,children:`Always active — add a window to restrict when the rule fires.`}):n.map((e,t)=>k(Wn,{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(L,{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 Wn({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:Bn(e.startMinute),onChange:n=>t({...e,startMinute:Vn(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:Bn(e.endMinute),onChange:n=>t({...e,endMinute:Vn(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(B,{className:`h-3.5 w-3.5`})})]}),k(`div`,{className:`flex flex-wrap gap-1`,children:zn.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 Gn=[{id:`liveness`,label:`Cameras & streams`,hint:`A camera the hub can no longer reach, or a stream that stopped or came back.`,kinds:[{value:`camera-offline`,label:`Camera offline`},{value:`camera-online`,label:`Camera online`},{value:`stream-offline`,label:`Stream offline`},{value:`stream-online`,label:`Stream online`}]},{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:`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`}]}],Kn=Gn.flatMap(e=>e.kinds);function qn(e){return Kn.find(t=>t.value===e)?.label??e}function Jn(e){return{devices:e.some(e=>e.startsWith(`camera-`)||e.startsWith(`stream-`)),nodes:e.some(e=>e.startsWith(`node-`)||e===`addon-update-available`),packages:e.some(e=>e.endsWith(`update-available`))}}function Yn(e,t){let n=e?.kinds??[],r=n.includes(t)?n.filter(e=>e!==t):Kn.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,`nodeIds`,e?.nodeIds),a=Zn(t,`packageNames`,e?.packageNames);return{kinds:[...n],...r===void 0?{}:{deviceIds:[...r]},...i===void 0?{}:{nodeIds:[...i]},...a===void 0?{}:{packageNames:[...a]}}}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=Jn(t),r=n.devices?e?.deviceIds:void 0,i=n.nodes?e?.nodeIds:void 0,a=n.packages?e?.packageNames:void 0;return{kinds:[...t],...r&&r.length>0?{deviceIds:[...r]}:{},...i&&i.length>0?{nodeIds:[...i]}:{},...a&&a.length>0?{packageNames:[...a]}:{}}}function $n(e,t=2){if(e===void 0||e.length===0)return`No event selected`;let n=e.slice(0,t).map(qn).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.nodeIds?.length??0,i=e.packageNames?.length??0;return n>0&&t.push(`${n} camera${n===1?``:`s`}`),r>0&&t.push(`${r} node${r===1?``:`s`}`),i>0&&t.push(`${i} package${i===1?``:`s`}`),t.length===0?`Everything`:t.join(` · `)}j.options,b();var tr=[`nc-pickers`,`nodes`],nr=[`nc-pickers`,`addon-packages`];function rr(){let e=F().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=F().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=Jn(r),a=rr(),o=ir();return x(`div`,{className:`mt-1 space-y-3`,"data-testid":`system-event-field`,children:[Gn.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:Z,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.devices&&x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Only these cameras (optional)`}),k(En,{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(J,{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(J,{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(()=>Nt(e,e=>e.id!==`devices`&&cr(e,n)),[e,n]),d=S(()=>Nt(e,e=>e.id!==`devices`&&!cr(e,n)),[e,n]),[f,m]=D(()=>{if(lr(r,i))return!0;try{return localStorage.getItem(sr)===`1`}catch{return!1}}),h=()=>{let e=!f;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=pn(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:X,children:e.label}),!s&&x(p,{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:Z,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:f?`▾ Hide advanced configurations`:`▸ Show more configurations`}),f&&g(d)]})}var sr=`camstack.nc.showAdvanced`;function cr(e,t){return t===`system-event`?e.id===`systemEvent`:N(e.id)}function lr(e,t){for(let[t,n]of Object.entries(e))if(!N(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(!gt(e.id))break;let t=e.id;return k(En,{cameras:i,value:n[t]??[],onChange:e=>o(t,e.length>0?e:void 0)})}case`stringList`:{if(!_t(e.id))break;let r=e.id,i=e=>o(r,e.length>0?e:void 0);if(r===`identities`||r===`identitiesExclude`)return k(Mn,{value:kt(n,r),onChange:i});if(r===`eventTypeTokens`)return k(Nn,{deviceIds:n.devices??[],value:kt(n,r),onChange:i});let a=M(r,t);return a===null?k(Dn,{value:kt(n,r),placeholder:`Add value…`,onChange:i}):k(On,{picker:a,value:kt(n,r),onChange:i})}case`zoneIdList`:{if(!vt(e.id))break;let t=e.id;return k(jn,{deviceIds:n.devices??[],cameras:i,value:kt(n,t),onChange:e=>o(t,e.length>0?e:void 0)})}case`number01`:{if(!yt(e.id))break;let t=e.id;return k(Q,{value:At(n,t),min:0,max:1,step:.05,onChange:e=>o(t,e)})}case`number`:{if(!bt(e.id))break;let t=e.id;return k(Q,{value:At(n,t),min:0,step:1,onChange:e=>o(t,e)})}case`sourceSelect`:{if(!xt(e.id))break;let t=e.id;return k(v,{value:n[t]??`any`,options:yn(e,nn).map(e=>({value:e.value,label:e.label})),onChange:e=>o(t,pr(e.target.value))})}case`systemEvent`:{if(!Dt(e.id))break;let t=e.id;return k(ar,{value:n[t],cameras:i,onChange:e=>o(t,e)})}case`deviceState`:if(!Ot(e.id))break;return k(Rn,{gateable:a,value:n.deviceState,onChange:e=>o(`deviceState`,e)});case`crossingSelect`:{if(!St(e.id))break;let t=e.id;return k(kn,{value:n[t],onChange:e=>o(t,e),...e.options?{options:e.options}:{}})}case`packagePhase`:{if(!Ct(e.id))break;let t=e.id;return k(v,{value:n[t]??``,options:[{value:``,label:`— any phase —`},...yn(e,rn).map(e=>({value:e.value,label:e.label}))],onChange:e=>o(t,mr(e.target.value))})}case`zoneSelection`:{if(!wt(e.id))break;let t=e.id;return k(An,{deviceIds:n.devices??[],cameras:i,value:n[t],onChange:e=>o(t,e)})}case`plateMatcher`:{if(!Tt(e.id))break;let t=e.id;return k(Ln,{value:n[t],onChange:e=>o(t,e)})}case`occupancy`:{if(!Et(e.id))break;let r=e.id;return k(In,{deviceIds:n.devices??[],cameras:i,classOptions:dr(t),value:n[r],onChange:e=>o(r,e)})}case`schedule`:return k(Un,{value:r,onChange:s});default:break}return k(fr,{descriptor:e,conditions:n})}function dr(e){let t=M(`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:Z,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 rn.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=F(),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(_,{className:`p-4`,children:[x(`div`,{className:`flex items-center gap-2 mb-3`,children:[k(he,{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(p,{variant:`warning`,className:`text-[10px]`,children:`everyone`}),!e.summary&&k(p,{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(f,{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=ne.options;function Dr({onSimulateRule:e}={}){let t=F(),[r,o]=D({mode:`closed`}),[s,c]=D(null),[l,u]=D(`all`),d=C({queryKey:br,queryFn:async()=>(await t.trpcClient.notificationRules.listRules.query({})).rules}),p=C({queryKey:xr,queryFn:()=>t.trpcClient.notificationOutput.listTargets.query({})}),h=C({queryKey:Sr,queryFn:()=>t.trpcClient.notificationRules.getConditionCatalog.query({})}),g=C({queryKey:Tr,queryFn:async()=>{let e=await t.trpcClient.deviceManager.listAll.query({}),n=[];for(let r of e){let e=te(await t.trpcClient.deviceManager.loadRuntimeState.query({deviceId:r.id}),Er);e.length>0&&n.push({id:r.id,name:r.name,states:e})}return n},staleTime:6e4}),v=C({queryKey:wr,queryFn:async()=>(await t.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 t.trpcClient.deviceManager.listAll.query({})).filter(e=>e.type===ee.Camera).map(e=>({id:e.id,name:e.name}))}),w=S(()=>{let e=new Map;for(let t of p.data??[])e.set(t.id,t.name);return e},[p.data]),T=O({mutationFn:e=>t.trpcClient.notificationRules.setRuleEnabled.mutate(e),onSuccess:()=>void d.refetch()}),E=O({mutationFn:e=>t.trpcClient.notificationRules.deleteRule.mutate({ruleId:e}),onSuccess:()=>{c(null),d.refetch()}}),A=d.data??[],j=S(()=>A.filter(e=>Wt(e.delivery,l)),[A,l]),M=S(()=>{let e=new Map;for(let t of Ht)e.set(t.key,A.filter(e=>Wt(e.delivery,t.key)).length);return e},[A]),N=Ht.find(e=>e.key===l)??Ht[0],P=l===`system`;return x(V,{icon:ge,title:`Notification Rules`,subtitle:N.blurb,actions:x(f,{size:`sm`,type:`button`,onClick:()=>o({mode:`form`,rule:null,delivery:Gt(l)}),children:[k(L,{className:`h-3.5 w-3.5`}),P?`New system rule`:`New rule`]}),children:[k(a,{value:l,onValueChange:e=>u(Ut(e)??l),children:k(n,{className:`mb-3`,children:Ht.map(e=>x(i,{value:e.key,children:[e.label,k(`span`,{className:`ml-1.5 text-[10px] text-foreground-subtle`,children:M.get(e.key)??0})]},e.key))})}),k(yr,{rules:A}),d.isLoading&&k(`div`,{className:`flex items-center justify-center py-16`,children:k(z,{className:`h-6 w-6 animate-spin text-primary`})}),d.isError&&!d.isLoading&&k(y,{title:`Failed to load rules`,message:d.error instanceof Error?d.error.message:`Unknown error`,onRetry:()=>void d.refetch()}),!d.isLoading&&!d.isError&&j.length===0&&k(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:P?`No system-event rules yet. Click "New system rule" to be told when a camera drops, a node leaves or an update lands.`:`No ${l===`all`?`notification`:`detection`} rules yet. Click "New rule" to author one.`}),j.length>0&&k(_,{children:k(m,{columns:P?kr({targetNameById:w,confirmDeleteId:s,deletePending:E.isPending,onToggle:(e,t)=>T.mutate({ruleId:e.id,enabled:t}),onEdit:e=>o({mode:`form`,rule:e}),onDuplicate:e=>o({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=>o({mode:`form`,rule:e}),onDuplicate:e=>o({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})}),r.mode===`form`&&k(Ar,{rule:r.rule,...r.delivery?{newRuleDelivery:r.delivery}:{},targets:p.data??[],actuatable:v.data??[],catalog:h.data?.catalog??[],taxonomy:h.data?.taxonomy,cameras:b.data??[],gateable:g.data??[],onCancel:()=>o({mode:`closed`}),onSaved:()=>{o({mode:`closed`}),d.refetch()}})]})}function Or(t){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(p,{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:zt(e.delivery)}),!Vt(e.delivery)&&k(p,{variant:`warning`,children:`read-only`})]})},{key:`targets`,header:`Targets`,render:e=>{let n=e.targets[0],r=n?t.targetNameById.get(n.targetId)??n.targetId:null;return k(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.targets.length===1&&r?r:`${e.targets.length} target${e.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:n=>k(e,{checked:n.enabled,onCheckedChange:e=>t.onToggle(n,e),"aria-label":`toggle ${n.name}`})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:e=>x(`span`,{className:`flex items-center justify-end gap-1`,children:[t.onTest&&k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t.onTest?.(e),title:`Test — simulate an event this rule should match`,"aria-label":`test ${e.name}`,children:k(_e,{className:`h-3.5 w-3.5`})}),k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t.onEdit(e),title:`Edit`,children:k(ie,{className:`h-3.5 w-3.5`})}),k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t.onDuplicate(e),title:`Duplicate`,children:k(re,{className:`h-3.5 w-3.5`})}),t.confirmDeleteId===e.id?x(w,{children:[x(f,{size:`sm`,variant:`danger`,type:`button`,disabled:t.deletePending,onClick:()=>t.onConfirmDelete(e),children:[t.deletePending&&k(z,{className:`h-3.5 w-3.5 animate-spin`}),`Confirm`]}),k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t.onAskDelete(null),children:`Cancel`})]}):k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t.onAskDelete(e.id),title:`Delete`,children:k(B,{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:qt(e.throttle.cooldownSec)})},...n(`enabled`),...n(`actions`)]}function Ar({rule:o,newRuleDelivery:s,targets:c,catalog:l,taxonomy:u,cameras:d,gateable:m,actuatable:_,onSaved:y,onCancel:b}){let S=F(),w=o!=null&&o.id.length>0,[T,E]=D(()=>o?un(o):ln(s)),[A,j]=D(null),[ee,te]=D(null),[M,N]=D(wn),P=e=>E(t=>({...t,...e})),ne=w&&o?{throttle:o.throttle}:void 0,I=O({mutationFn:async()=>{let e=vn(T,ne,l);w&&o?await S.trpcClient.notificationRules.updateRule.mutate({ruleId:o.id,patch:e}):await S.trpcClient.notificationRules.createRule.mutate({rule:e})},onSuccess:y,onError:e=>j(e instanceof Error?e.message:`Save failed`)}),re=O({mutationFn:async()=>{let e=vn(T,ne,l);return(await S.trpcClient.notificationRules.testRule.mutate({rule:e,lookbackMinutes:60})).results},onMutate:()=>te(null),onSuccess:e=>te(e),onError:e=>j(e instanceof Error?e.message:`Test failed`)}),ie=T.targetIds.map(e=>c.find(t=>t.id===e)?.name??e),L=e=>P({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=>P({targetUsers:T.targetUsers.includes(e)?T.targetUsers.filter(t=>t!==e):[...T.targetUsers,e]}),se=Rt.find(e=>e.value===T.delivery)?.hint,R=Y(T.delivery),ce=Cn(T.delivery),le=ce.some(e=>e.key===M)?M:wn;return Vt(T.delivery)?k(g,{open:!0,onOpenChange:e=>!e&&b(),children:x(r,{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(ge,{className:`h-4 w-4 text-foreground-subtle`}),w?`Edit ${o?.name}`:`New notification rule`]}),k(f,{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(a,{value:le,onValueChange:e=>N(Tn(e)??M),children:[k(n,{className:`mb-3`,children:ce.map(e=>k(i,{value:e.key,children:e.label},e.key))}),x(t,{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(h,{value:T.name,onChange:e=>P({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(e,{checked:T.enabled,onCheckedChange:e=>P({enabled:e}),"aria-label":`enabled`}),`Enabled`]})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Trigger`}),k(v,{value:T.delivery,onChange:e=>{let t=Bt(e.target.value);t&&P({delivery:t})},options:Rt.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`}),c.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:c.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:()=>L(e.id),className:`accent-primary`}),k(`span`,{className:`flex-1 truncate`,children:e.name}),!e.enabled&&k(p,{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(p,{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(t,{value:`devices`,className:`space-y-4`,children:k(ht,{devices:_,value:T.deviceIds,onChange:e=>P({deviceIds:e}),loading:_.length===0})}),k(t,{value:`actions`,className:`space-y-4`,children:k(rt,{value:T.actions,onChange:e=>P({actions:e}),devices:_})}),x(t,{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(v,{value:String(T.cooldownSec),onChange:e=>{let t=Yt(e.target.value);t!==void 0&&P({cooldownSec:t})},options:Jt(T.cooldownSec).map(e=>({value:String(e.value),label:e.label}))}),k(`p`,{className:`text-[10px] text-foreground-subtle mt-1`,children:R?`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(e,{checked:T.snoozeAllowGlobal,onCheckedChange:e=>P({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(t,{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(v,{value:String(T.priority),onChange:e=>P({priority:Number(e.target.value)}),options:cn.map(e=>({value:String(e.value),label:e.label}))})]}),R&&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.`}),!R&&x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Media attachment`}),k(v,{value:T.mediaAttach,onChange:e=>{let t=Zt(e.target.value);t&&P({mediaAttach:t})},options:Xt.map(e=>({value:e.value,label:e.label}))}),k(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:Xt.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=>P({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=>P({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=>P({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(v,{value:T.mediaProfile??``,onChange:e=>P({mediaProfile:tn(e.target.value)}),options:en.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(v,{value:T.mediaClipSpeed===void 0?``:String(T.mediaClipSpeed),onChange:e=>P({mediaClipSpeed:xn(e.target.value)}),options:bn.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.`})]})]}),!R&&x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Image frame`}),k(v,{value:T.mediaFrame??``,onChange:e=>P({mediaFrame:$t(e.target.value)}),options:Qt.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(h,{value:T.templateTitle,onChange:e=>P({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=>P({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(t,{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:R?`Which system events`:`Conditions`}),R&&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.`}),l.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:l,taxonomy:u,delivery:T.delivery,conditions:T.conditions,schedule:T.schedule,cameras:d,gateable:m,onConditionsChange:e=>P({conditions:e}),onScheduleChange:e=>P({schedule:e})})]}),!R&&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(f,{size:`sm`,variant:`outline`,type:`button`,disabled:re.isPending||!dn(T),onClick:()=>{j(null),re.mutate()},children:[re.isPending?k(z,{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.`}),ee!==null&&k(Mr,{delivery:T.delivery,results:ee,targetNames:ie})]})]})]}),x(`div`,{className:`flex justify-end gap-2 mt-4`,children:[k(f,{variant:`secondary`,size:`sm`,type:`button`,onClick:b,children:`Cancel`}),x(f,{size:`sm`,type:`button`,disabled:I.isPending||!dn(T),onClick:()=>{j(null),I.mutate()},children:[I.isPending&&k(z,{className:`h-3.5 w-3.5 animate-spin`}),w?`Save changes`:`Create rule`]})]})]})}):k(jr,{rule:o,onCancel:b})}function jr({rule:e,onCancel:t}){let n=Object.keys(e?.conditions??{});return k(g,{open:!0,onOpenChange:e=>!e&&t(),children:x(r,{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(ge,{className:`h-4 w-4 text-foreground-subtle`}),e?.name??`Rule`]}),k(p,{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:e?.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:e?.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:e?.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:e?.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:n.length>0?n.join(`, `):`none`})]})]}),k(`div`,{className:`flex justify-end gap-2 mt-4`,children:k(f,{variant:`secondary`,size:`sm`,type:`button`,onClick:t,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(I,{className:`h-3.5 w-3.5 shrink-0 text-success`}):k(ce,{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))})]})}b();var Nr=[{value:1,label:`Last hour`},{value:24,label:`Last 24 hours`},{value:168,label:`Last 7 days`},{value:0,label:`All time`}],Pr=[{value:``,label:`Any status`},{value:`pending`,label:`Pending`},{value:`sent`,label:`Sent`},{value:`dead`,label:`Dead`}],Fr=[50,100,250,500];function Ir(){return{ruleId:``,deviceId:``,status:``,windowHours:24,limit:100}}function Lr(e){return e===`pending`||e===`sent`||e===`dead`?e:void 0}function Rr(e){switch(e){case`pending`:return`info`;case`sent`:return`success`;case`dead`:return`danger`}}function zr(){let e=F(),[t,n]=D(Ir),r=e=>n(t=>({...t,...e})),i=C({queryKey:[`notificationRules`,`listRules`,`forHistory`],queryFn:async()=>(await e.trpcClient.notificationRules.listRules.query({})).rules}),a=C({queryKey:[`deviceManager`,`listAll`,`forHistory`],queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({})).filter(e=>e.type===ee.Camera).map(e=>({id:e.id,name:e.name}))}),o=Date.now(),s=C({queryKey:[`notificationRules`,`getHistory`,t],retry:!1,queryFn:async()=>{let n=t.windowHours>0?o-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)}:{},...Lr(t.status)?{status:Lr(t.status)}:{},...n===void 0?{}:{since:n}}})).entries}}),c=S(()=>{let e=new Map;for(let t of a.data??[])e.set(t.id,t.name);return e},[a.data]),l=e=>c.get(e)??`Camera #${String(e)}`,u=s.data??[],d=s.isError;return x(V,{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(v,{value:t.ruleId,onChange:e=>r({ruleId:e.target.value}),options:[{value:``,label:`All rules`},...(i.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(v,{value:t.deviceId,onChange:e=>r({deviceId:e.target.value}),options:[{value:``,label:`All cameras`},...(a.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(v,{value:t.status,onChange:e=>r({status:e.target.value}),options:Pr.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(v,{value:String(t.windowHours),onChange:e=>r({windowHours:Number(e.target.value)}),options:Nr.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(v,{value:String(t.limit),onChange:e=>r({limit:Number(e.target.value)}),options:Fr.map(e=>({value:String(e),label:String(e)}))})]})]}),s.isLoading&&k(`div`,{className:`flex items-center justify-center py-16`,children:k(z,{className:`h-6 w-6 animate-spin text-primary`})}),d&&!s.isLoading&&k(_,{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 s.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`]})]})}),!d&&!s.isLoading&&u.length===0&&k(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:`No deliveries match these filters.`}),!d&&u.length>0&&k(_,{children:k(m,{columns:Br(l),rows:u,rowKey:e=>e.id,minWidthPx:720,bordered:!1})})]})}function Br(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(p,{variant:Rr(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:`—`})}]}var Vr={home:`Home`,away:`Away`,night:`Night`,vacation:`Vacation`,custom_bypass:`Custom`};function Hr(e){return Vr[e]??e}function Ur(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 Wr(e,t){return e.ruleCount===0?`Arms nothing — no enabled rule is gated on this mode.`:e.allDevices?`Every device — ${Kr(e.ruleCount,`rule`)} with no device scope.`:e.deviceIds.length===0?`${Kr(e.ruleCount,`rule`)}, no device restriction.`:e.deviceIds.map(e=>t.get(e)??`Device ${e}`).join(`, `)}function Gr(e){return e.ruleCount===0}function Kr(e,t){return e===1?`1 ${t}`:`${e} ${t}s`}function qr(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}b();var Jr=[`notificationRules`,`getAlarmConfig`],Yr=[`notificationOutput`,`listTargets`],Xr=[`deviceManager`,`listAll`,`alarm-coverage`],Zr=600,Qr=3600;function $r({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(h,{type:`number`,min:0,max:r,value:s??String(n),disabled:a,onChange:e=>c(e.target.value),onBlur:()=>{let e=s===null?null:qr(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:Ur(n,i)})]}),k(`p`,{className:`text-xs text-foreground-subtle`,children:t})]})}function ei(){let t=F(),n=E(),r=C({queryKey:Jr,queryFn:async()=>t.trpcClient.notificationRules.getAlarmConfig.query({})}),i=C({queryKey:Yr,queryFn:async()=>(await t.trpcClient.notificationOutput.listTargets.query({})).map(e=>({id:e.id,name:e.name,enabled:e.enabled}))}),a=C({queryKey:Xr,queryFn:async()=>(await t.trpcClient.deviceManager.listAll.query({projection:`slim`})).map(e=>({id:e.id,name:e.name}))}),o=O({mutationFn:e=>t.trpcClient.notificationRules.setAlarmConfig.mutate({patch:e}),onSuccess:()=>n.invalidateQueries({queryKey:Jr})}),s=S(()=>{let e=new Map;for(let t of a.data??[])e.set(t.id,t.name);return e},[a.data]);if(r.isLoading)return k(V,{icon:de,title:`Alarm`,subtitle:`Panel delays and mode coverage.`,children:k(z,{className:`h-5 w-5 animate-spin`})});let c=r.data;if(c===void 0||r.isError)return k(V,{icon:de,title:`Alarm`,subtitle:`Panel delays and mode coverage.`,children:k(y,{title:`Alarm settings are not available`,message:`This hub has not been updated to serve the alarm configuration yet.`})});if(c.deviceId===null)return k(V,{icon:de,title:`Alarm`,subtitle:`Panel delays and mode coverage.`,children:k(_,{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 l=c.settings,u=o.isPending,d=i.data??[],f=l.announceTargets,m=e=>{o.mutate(e)},h=e=>{m({announceTargets:f.includes(e)?f.filter(t=>t!==e):[...f,e]})};return k(V,{icon:de,title:`Alarm`,subtitle:`Panel delays, and what each mode actually arms.`,children:x(`div`,{className:`flex flex-col gap-4`,children:[o.isError?k(y,{title:`Could not save`,message:String(o.error)}):null,x(_,{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($r,{label:`Exit delay`,hint:`Time between arming and the mode taking effect — long enough to leave.`,value:l.exitDelaySec,max:Zr,zeroMeans:`arms immediately`,disabled:u,onCommit:e=>m({exitDelaySec:e})}),k($r,{label:`Entry delay`,hint:`Time between a trigger and the alarm firing — long enough to reach the keypad.`,value:l.entryDelaySec,max:Zr,zeroMeans:`fires immediately`,disabled:u,onCommit:e=>m({entryDelaySec:e})}),k($r,{label:`Triggered for`,hint:`How long the alarm stays triggered before re-arming itself.`,value:l.triggeredDurationSec,max:Qr,zeroMeans:`until disarmed`,disabled:u,onCommit:e=>m({triggeredDurationSec:e})})]})]}),x(_,{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(e,{checked:l.announceArm,disabled:u,onCheckedChange:e=>m({announceArm:e}),"data-testid":`alarm-announce-toggle`})]}),l.announceArm?x(`div`,{className:`mt-3 flex flex-col gap-2`,children:[d.length===0?k(`p`,{className:`text-xs text-foreground-subtle`,children:`No notification targets are configured — nothing can be sent.`}):d.map(e=>x(`label`,{className:`flex items-center gap-2 text-sm`,children:[k(`input`,{type:`checkbox`,checked:f.includes(e.id),disabled:u,onChange:()=>h(e.id),"data-testid":`alarm-target-${e.id}`}),k(`span`,{children:e.name}),e.enabled?null:k(p,{variant:`warning`,children:`disabled`})]},e.id)),f.length===0?k(`p`,{className:`text-xs text-warning`,children:`No target selected — the announcement will not be sent.`}):null]}):null]}),x(_,{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:c.coverage.map(e=>x(`div`,{className:`flex items-start gap-3 rounded border border-border p-2`,"data-mode":e.mode,"data-empty":Gr(e)?`true`:`false`,children:[k(`div`,{className:`w-20 shrink-0 text-sm font-medium`,children:Hr(e.mode)}),k(`div`,{className:`flex-1 text-sm text-foreground-subtle`,children:Wr(e,s)}),Gr(e)?k(pe,{className:`h-4 w-4 shrink-0 text-warning`}):null]},e.mode))})]})]})})}var ti=[{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 ni(e){return ti.find(t=>t.value===e)?.value}function ri(e){return e===`object-event`||e===`audio-event`?`immediate`:e===`occupancy-event`?`device-event`:e}function ii(e){return``}var ai={x:.25,y:.25,w:.5,h:.5},oi={zoneId:``,zoneName:``,className:``,count:1,previousCount:0,occupied:!0,threshold:1};function si(){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:ai,occupancy:oi,timestampLocal:``,onlyRuleId:``,bypassCooldown:!1,bypassMute:!1,runActions:!1,still:`live`}}function ci(e){return e.deviceId!==null}function li(e){if(e.trim().length===0)return;let t=Number(e);return Number.isFinite(t)?t:void 0}function ui(e){if(e.trim().length===0)return;let t=Date.parse(e);return Number.isFinite(t)?t:void 0}function di(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 fi(e){if(e.deviceId===null)return null;let t=e.trigger,n=ui(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:pi(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 pi(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 mi(e){return Math.min(1,Math.round((e+.05)*100)/100)}function hi(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 gi(e){let t=si(),n=e.conditions,r=hi(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:mi(n.minConfidence)},...n.minLabelConfidence===void 0?{}:{labelConfidence:mi(n.minLabelConfidence)},...n.minImportance===void 0?{}:{importance:mi(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:ii(r),...n.customZones!==void 0&&n.customZones.length>0?{bboxEnabled:!0}:{},...n.occupancy===void 0?{}:{occupancy:_i(n.occupancy)},onlyRuleId:e.id}}function _i(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 vi(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 yi(e){return{form:gi(e),caveats:vi(e),ruleName:e.name}}var bi=null;function xi(e){bi=e}function Si(){return bi}function Ci(){bi=null}var wi=[`n/a`,`clear`,`suppressed`,`bypassed`],Ti=[`live`,`none`,`unavailable`,`unattachable`];function Ei(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function $(e,t){let n=e[t];return typeof n==`string`?n:void 0}function Di(e,t){let n=e[t];return Array.isArray(n)?n.filter(e=>typeof e==`string`):[]}function Oi(e){if(!Ei(e))return null;let t=$(e,`ruleId`),n=$(e,`ruleName`),r=$(e,`cooldown`),i=wi.find(e=>e===r);if(t===void 0||n===void 0||i===void 0||typeof e.matched!=`boolean`)return null;let a=$(e,`failedCondition`),o=Array.isArray(e.matchedOn)?Di(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:Di(e,`targetIds`)}}function ki(e){if(!Ei(e))return null;let t=$(e,`recordId`),n=$(e,`delivery`),r=$(e,`still`),i=Ti.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=$(e,`droppedBy`);return{recordId:t,origin:`synthetic`,delivery:n,candidates:typeof e.candidates==`number`?e.candidates:0,outcomes:o,still:i,notes:Di(e,`notes`),...s===void 0?{}:{droppedBy:s}}}function Ai(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 ji=new Set([`sensor`,`control`,`custom`]);function Mi({form:e,cameras:t,taxonomy:n,kinds:r,kindsLoading:i,onPatch:a}){let o=e.deviceId===null?[]:[e.deviceId],s=M(`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(Ni,{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:X,children:`Audio classes`}),k(J,{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:X,children:`Zones`}),k(jn,{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(Pi,{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:X,children:`Detected classes`}),s===null?k(Dn,{value:e.classNames,placeholder:`Class id (person, car…)`,onChange:e=>a({classNames:e})}):k(On,{picker:s,value:e.classNames,onChange:e=>a({classNames:e})})]}),x(`div`,{children:[k(`label`,{className:X,children:`Zones the subject is in`}),k(jn,{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(v,{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 Ni({form:e,kinds:t,loading:n,onPatch:r}){let i=t.filter(e=>ji.has(e.category)),a=i.find(t=>t.kind===e.sensorKind);return x(w,{children:[x(`div`,{children:[k(`label`,{className:X,children:`Event kind`}),k(v,{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:X,children:`Source device`}),k(h,{type:`number`,value:e.sourceDeviceId===null?``:String(e.sourceDeviceId),placeholder:`the camera itself`,onChange:e=>r({sourceDeviceId:li(e.target.value)??null})}),k(`p`,{className:Z,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:X,children:`Event type token`}),k(h,{value:e.eventType,placeholder:`press, press_long…`,onChange:e=>r({eventType:e.target.value})}),k(`p`,{className:Z,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 Pi({form:t,cameras:n,taxonomy:r,onPatch:i}){let a=t.deviceId===null?[]:[t.deviceId],o=M(`classes`,r),s=o===null?[]:o.groups.flatMap(e=>e.options),c=t.occupancy,l=e=>i({occupancy:{...c,...e}});return x(w,{children:[x(`div`,{children:[k(`label`,{className:X,children:`Zone`}),k(jn,{deviceIds:a,cameras:n,value:c.zoneId===``?[]:[c.zoneId],onChange:e=>l({zoneId:e[e.length-1]??``})}),k(`p`,{className:Z,children:`Leave empty for the whole frame.`})]}),x(`div`,{className:`max-w-[14rem]`,children:[k(`label`,{className:X,children:`Class`}),k(v,{value:c.className,options:[{value:``,label:`— any class —`},...s.map(e=>({value:e.value,label:e.label}))],onChange:e=>l({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(h,{type:`number`,min:0,className:`w-20`,value:String(c.count),onChange:e=>l({count:li(e.target.value)??0})})]}),x(`label`,{className:`text-[11px] text-foreground-subtle`,children:[`Count before`,k(h,{type:`number`,min:0,className:`w-20`,value:String(c.previousCount),onChange:e=>l({previousCount:li(e.target.value)??0})})]}),x(`label`,{className:`text-[11px] text-foreground-subtle`,children:[`Threshold`,k(h,{type:`number`,min:1,className:`w-20`,value:String(c.threshold),onChange:e=>l({threshold:li(e.target.value)??1})})]}),x(`label`,{className:`flex items-center gap-2 pb-1 text-[11px] text-foreground`,children:[k(e,{checked:c.occupied,onCheckedChange:e=>l({occupied:e}),"aria-label":`occupied`}),`Occupied`]})]})]})}function Fi({form:t,cameras:n,onPatch:r}){let i=t.deviceId===null?[]:[t.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:[t.trigger===`object-event`&&x(`div`,{children:[x(`label`,{className:`flex items-center gap-2 text-[11px] font-medium text-foreground`,children:[k(e,{checked:t.crossingEnabled,onCheckedChange:e=>r({crossingEnabled:e}),"aria-label":`zone crossing`}),`This event is a confirmed zone crossing`]}),t.crossingEnabled&&x(`div`,{className:`mt-1 space-y-1.5`,children:[k(`div`,{className:`max-w-[12rem]`,children:k(v,{value:t.crossingDirection,options:[{value:`enter`,label:`Entered the zone`},{value:`exit`,label:`Left the zone`}],onChange:e=>r({crossingDirection:e.target.value===`exit`?`exit`:`enter`})})}),k(jn,{deviceIds:i,cameras:n,value:t.crossingZoneId===``?[]:[t.crossingZoneId],onChange:e=>r({crossingZoneId:e[e.length-1]??``})})]})]}),x(`div`,{children:[x(`label`,{className:`flex items-center gap-2 text-[11px] font-medium text-foreground`,children:[k(e,{checked:t.bboxEnabled,onCheckedChange:e=>r({bboxEnabled:e}),"aria-label":`bounding box`}),`Carry a bounding box`]}),k(`p`,{className:Z,children:"Normalized 0–1, top-left origin. Feeds the `customZones` condition and decides how the still is cropped or boxed."}),t.bboxEnabled&&k(`div`,{className:`mt-1 flex flex-wrap gap-2`,children:[`x`,`y`,`w`,`h`].map(e=>x(`label`,{className:`text-[11px] text-foreground-subtle`,children:[e,k(h,{type:`number`,min:0,max:1,step:.05,className:`w-20`,value:String(t.bbox[e]),onChange:n=>r({bbox:{...t.bbox,[e]:li(n.target.value)??0}})})]},e))})]}),x(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[x(`div`,{children:[k(`label`,{className:X,children:`Happened at`}),x(`div`,{className:`flex items-center gap-2`,children:[k(h,{type:`datetime-local`,value:t.timestampLocal,onChange:e=>r({timestampLocal:e.target.value})}),t.timestampLocal===``?k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>r({timestampLocal:di(Date.now())}),children:`Set`}):k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>r({timestampLocal:``}),children:`Now`})]}),k(`p`,{className:Z,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:X,children:`Detection source`}),k(v,{value:t.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;r({source:t===`pipeline`||t===`onboard`||t===`sensor`||t===`audio`?t:``})}})]})]})]})]})}function Ii({checked:t,label:n,hint:r,danger:i=!1,onChange:a}){return x(`div`,{children:[x(`label`,{className:`flex items-center gap-2 text-[11px] font-medium text-foreground`,children:[k(e,{checked:t,onCheckedChange:a,"aria-label":n}),n,i&&k(p,{variant:`danger`,children:`actuates devices`})]}),k(`p`,{className:Z,children:r})]})}b();var Li={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.`},Ri={"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 zi({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:Ai(e)}),x(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px] text-foreground-subtle`,children:[k(Bi,{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:Li[e.still],children:[`still `,k(`span`,{className:`text-foreground`,children:e.still})]}),e.droppedBy!==void 0&&x(p,{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(Vi,{outcome:e,targetName:t},e.ruleId))})]})}function Bi({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(f,{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 Vi({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(I,{className:`h-3.5 w-3.5 shrink-0 text-success`}):k(ce,{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:Ri[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 Hi=`pipeline-analytics`,Ui=`nc.injectTestEvent`;function Wi(){let e=F(),[t,n]=D(()=>Si()?.form??si()),[r]=D(()=>Si()?.caveats??[]),[i]=D(()=>Si()?.ruleName??null);A(()=>Ci(),[]);let[a,o]=D(null),[s,c]=D(!1),[l,u]=D(null),d=e=>n(t=>({...t,...e})),p=C({queryKey:Cr,queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({})).filter(e=>e.type===ee.Camera).map(e=>({id:e.id,name:e.name}))}),m=C({queryKey:Sr,queryFn:()=>e.trpcClient.notificationRules.getConditionCatalog.query({})}),g=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=p.data??[],j=m.data?.taxonomy,te=T.data??[],M=S(()=>{let e=new Map;for(let t of b.data??[])e.set(t.id,t.name);return e},[b.data]),N=O({mutationFn:async()=>{let n=fi(t);if(n===null)throw Error(`Pick a camera first.`);return e.trpcClient.addons.custom.mutate({addonId:Hi,action:Ui,input:n})},onMutate:()=>{o(null),c(!1),u(null)},onSuccess:e=>{let t=ki(e);o(t),c(t===null)},onError:e=>u(e instanceof Error?e.message:`The simulation failed.`)}),P=ri(t.trigger),ne=g.data?.find(e=>e.id===t.onlyRuleId);return x(V,{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:[p.isError&&k(y,{title:`Failed to load cameras`,message:p.error instanceof Error?p.error.message:`Unknown error`,onRetry:()=>void p.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(pe,{className:`mt-0.5 h-3 w-3 shrink-0 text-warning`}),k(`span`,{children:e.note})]},e.conditionId))}),x(_,{className:`space-y-4`,children:[x(`div`,{children:[k(`label`,{className:X,children:`Camera`}),k(v,{"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=>{d({deviceId:li(e.target.value)??null,zones:[],crossingZoneId:``,sensorKind:``,sourceDeviceId:null,occupancy:{...t.occupancy,zoneId:``}})}}),k(`p`,{className:Z,children:`The camera the event is attributed to — what a notification shows.`})]}),x(`div`,{children:[k(`label`,{className:X,children:`Trigger`}),k(v,{"data-testid":`simulate-trigger`,value:t.trigger,options:ti.map(e=>({value:e.value,label:e.label})),onChange:e=>{let n=ni(e.target.value);if(!n)return;let r=ii(t.trigger);d({trigger:n,source:t.source===``||t.source===r?ii(n):t.source})}}),x(`p`,{className:Z,children:[ti.find(e=>e.value===t.trigger)?.hint,` Only rules whose trigger is `,k(`span`,{className:`text-foreground`,children:P}),` are candidates.`]})]}),k(Mi,{form:t,cameras:E,taxonomy:j,kinds:te,kindsLoading:T.isLoading,onPatch:d}),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:Z,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:X,children:`Label (identity name / plate / subclass)`}),k(h,{value:t.label,placeholder:`e.g. Marco, AB123CD`,onChange:e=>d({label:e.target.value})})]}),x(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[x(`div`,{children:[k(`label`,{className:X,children:`Detection confidence`}),k(Q,{value:t.confidence,min:0,max:1,step:.05,onChange:e=>d({confidence:e})})]}),x(`div`,{children:[k(`label`,{className:X,children:`Label-match confidence`}),k(Q,{value:t.labelConfidence,min:0,max:1,step:.05,onChange:e=>d({labelConfidence:e})})]}),x(`div`,{children:[k(`label`,{className:X,children:`Importance`}),k(Q,{value:t.importance,min:0,max:1,step:.05,onChange:e=>d({importance:e})})]}),x(`div`,{children:[k(`label`,{className:X,children:`Dwell (seconds)`}),k(Q,{value:t.dwellSeconds,min:0,step:1,onChange:e=>d({dwellSeconds:e})})]})]})]})]}),k(Fi,{form:t,cameras:E,onPatch:d}),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(Ii,{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=>d({bypassCooldown:e})}),k(Ii,{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=>d({bypassMute:e})}),k(Ii,{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=>d({runActions:e})}),x(`div`,{className:`max-w-[14rem]`,children:[k(`label`,{className:X,children:`Still image`}),k(v,{value:t.still,options:[{value:`live`,label:`Live snapshot of the camera`},{value:`none`,label:`No image`}],onChange:e=>d({still:e.target.value===`none`?`none`:`live`})})]}),x(`div`,{children:[k(`label`,{className:X,children:`Evaluate only one rule`}),k(v,{value:t.onlyRuleId,options:[{value:``,label:`— every enabled rule —`},...(g.data??[]).map(e=>({value:e.id,label:e.name}))],onChange:e=>d({onlyRuleId:e.target.value})}),t.onlyRuleId.length>0&&ne===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.`]})]})]}),l!==null&&k(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:l}),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(f,{size:`sm`,type:`button`,disabled:N.isPending||!ci(t),onClick:()=>N.mutate(),children:[N.isPending?k(z,{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(zi,{result:a,targetName:e=>M.get(e)??e})]})}var Gi=`simulate`;function Ki(){let[e,t]=R();return k(`div`,{className:`flex flex-col p-4`,children:k(me,{tabs:[{id:`targets`,label:`Targets`,icon:le,content:k(Ke,{})},{id:`rules`,label:`Rules`,icon:ge,content:k(Dr,{onSimulateRule:n=>{xi(yi(n));let r=new URLSearchParams(e);r.set(`tab`,Gi),t(r,{replace:!0})}})},{id:Gi,label:`Simulate`,icon:_e,content:k(Wi,{})},{id:`history`,label:`History`,icon:ve,content:k(zr,{})},{id:`alarm`,label:`Alarm`,icon:de,content:k(ei,{})}]})})}export{Ki as NotificationsPage,Ki as default};
|