@camstack/addon-admin-ui 1.2.17 → 1.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddLocationWizard-KwzmlSoV.js → AddLocationWizard-BowIG3iq.js} +1 -1
- package/dist/assets/{AddonCollectionPage-Dn32SNWM.js → AddonCollectionPage-DzUEOYUV.js} +1 -1
- package/dist/assets/{Addons-EyEW4D4A.js → Addons-B5DucodR.js} +1 -1
- package/dist/assets/{AdminTabs-57hhQmVl.js → AdminTabs-C-SMNF-6.js} +1 -1
- package/dist/assets/{AiProfiles-uNlhciHT.js → AiProfiles-D65CezzL.js} +1 -1
- package/dist/assets/{BrokerForm-DyoPjxXz.js → BrokerForm-ENHOk64X.js} +1 -1
- package/dist/assets/{Capabilities-cVsIOc2t.js → Capabilities-dtlaxRnV.js} +1 -1
- package/dist/assets/{CapabilityBadges-s1q6EazS.js → CapabilityBadges-QVudw7lC.js} +1 -1
- package/dist/assets/{Cluster-BkmB4wXT.js → Cluster-9-Ysfuh5.js} +1 -1
- package/dist/assets/{ClusterRecordingTab-BH11-IbA.js → ClusterRecordingTab-CvimJgTY.js} +1 -1
- package/dist/assets/{Dashboard-CwGNZIik.js → Dashboard-CXFEM2IR.js} +1 -1
- package/dist/assets/{Data-DU6dKN0-.js → Data-DPmsq4Rb.js} +1 -1
- package/dist/assets/{DetectionIntelligence-DgBcQaJ7.js → DetectionIntelligence-CsY0BCKS.js} +1 -1
- package/dist/assets/{DeviceAggregateSection-DDZxpHxU.js → DeviceAggregateSection-CzThj0Vt.js} +1 -1
- package/dist/assets/{DeviceDetail-Z501iVY2.js → DeviceDetail-BWX7NeMm.js} +1 -1
- package/dist/assets/{Devices-BUppgEis.js → Devices-CdMd1Rxe.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-DyKLMuTg.js → EmbedPlayerPage-BPMSAjgX.js} +1 -1
- package/dist/assets/{Events-DRMEOb-1.js → Events-DlSc5xWS.js} +1 -1
- package/dist/assets/{FormBuilder-V9-ZYyfi.js → FormBuilder-BTBth7Mm.js} +1 -1
- package/dist/assets/{Identity-BOlAVEHc.js → Identity-BkJfHHax.js} +1 -1
- package/dist/assets/{IntegrationDetail-xhGos6_v.js → IntegrationDetail-DjcVm32z.js} +1 -1
- package/dist/assets/{Integrations-Dp5hPLpw.js → Integrations-BstWDI9y.js} +1 -1
- package/dist/assets/{Integrations-CXfoHU1-.js → Integrations-CCkqm_Su.js} +1 -1
- package/dist/assets/{Logs-kyji_5ss.js → Logs-BKvPV_wj.js} +1 -1
- package/dist/assets/{MotionZonesSettings-M7Q0c7HT.js → MotionZonesSettings-C3F5tNrn.js} +1 -1
- package/dist/assets/{MyAccess-BP00gmMz.js → MyAccess-D94hQDyr.js} +1 -1
- package/dist/assets/{Network-BupOQchv.js → Network-DRjrjeQG.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-BHYPuuzP.js → NodeAddonsSettingsPanel-CL75zTHK.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-CYZafvHq.js → NodeInferenceDevices-gVLIWG74.js} +1 -1
- package/dist/assets/Notifications-7spoN22j.js +1 -0
- package/dist/assets/{Pipeline-Cc89loIx.js → Pipeline-Dmgt7OdK.js} +1 -1
- package/dist/assets/{Plates-CaHuT1aj.js → Plates-0nXxdKJX.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-C8tsyRZP.js → PrivacyMaskSettings-BC6o9lqJ.js} +1 -1
- package/dist/assets/{ProviderIcon-CD80TWfL.js → ProviderIcon-tK6tKDtF.js} +1 -1
- package/dist/assets/{Recordings-Ds0k0Oit.js → Recordings-BtjWTugI.js} +1 -1
- package/dist/assets/{ScanNetworkModal-C1fdwcgx.js → ScanNetworkModal-CwPUWLnW.js} +1 -1
- package/dist/assets/{Settings-D9xYfuNz.js → Settings-CmklSlYL.js} +1 -1
- package/dist/assets/{Showroom-DfupwGEQ.js → Showroom-fSzPo12F.js} +1 -1
- package/dist/assets/{Terminal-QIfVJ57m.js → Terminal-DLULQ5yw.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DTU5DNxA.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C8V797Ba.js} +1 -1
- package/dist/assets/{build-cluster-graph-DryWXcym.js → build-cluster-graph-DIGI0NJ3.js} +1 -1
- package/dist/assets/circle-check-big-DifLR11P.js +1 -0
- package/dist/assets/clock-BXw5TTp6.js +1 -0
- package/dist/assets/{copy-xvYnf3mn.js → copy-D4StuZzs.js} +1 -1
- package/dist/assets/{debounced-invalidate-CT06Xct6.js → debounced-invalidate-CXo5TVm0.js} +1 -1
- package/dist/assets/{dist-kk5V4ONk.js → dist-B1ZcDDOx.js} +1 -1
- package/dist/assets/dist-BqHHqLgd.js +7 -0
- package/dist/assets/{download-4PdCPJIH.js → download-Dq6V-5xf.js} +1 -1
- package/dist/assets/{face-bbox-BOfEr6-A.js → face-bbox-CnD55hf6.js} +1 -1
- package/dist/assets/{hostInit-BbElAo79.js → hostInit-DyHdo8Gk.js} +1 -1
- package/dist/assets/{index-DUFmNDGR.js → index-BsmimqzB.js} +3 -3
- package/dist/assets/{key-round-BluylYau.js → key-round-BC8uv06u.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-d0572cd2.js → mf-entry-bootstrap-0-278ef480.js} +2 -2
- package/dist/assets/{pencil-upvlHQDr.js → pencil-BuY8CueB.js} +1 -1
- package/dist/assets/{player-overlays-DFxnnQ5-.js → player-overlays-CNHQKrHd.js} +1 -1
- package/dist/assets/plus-DyBHOfPx.js +1 -0
- package/dist/assets/{radio-CNyLw5GQ.js → radio-CQ2Qddgd.js} +1 -1
- package/dist/assets/{refresh-cw-Brd1nmbC.js → refresh-cw-BwbLLVV6.js} +1 -1
- package/dist/assets/remoteEntry-BQiHtOSG.js +1 -0
- package/dist/assets/{rotate-ccw-CrfFxSL1.js → rotate-ccw-D9ag3NNh.js} +1 -1
- package/dist/assets/rotate-cw-J5QBXynE.js +1 -0
- package/dist/assets/search-BLl1nrAm.js +1 -0
- package/dist/assets/{send-DcQrPOWq.js → send-CrQGjBpn.js} +1 -1
- package/dist/assets/{server-s54U0Xav.js → server-C-ApRIN8.js} +1 -1
- package/dist/assets/square-D5oi0WlG.js +1 -0
- package/dist/assets/{square-check-big-CkGVGfz1.js → square-check-big-D0Ns-qwF.js} +1 -1
- package/dist/assets/{src-Btp5jZp0.js → src-BDNLbHXL.js} +10 -10
- package/dist/assets/src-SFNx0Juf.js +7 -0
- package/dist/assets/{upload-ZqMKZ88x.js → upload-OKC5mQ8W.js} +1 -1
- package/dist/assets/{useEventInvalidation-ByOUWkAr.js → useEventInvalidation-BHTo3YFv.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CsWv8uI6.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CkMK9IKI.js} +2 -2
- package/dist/assets/{wifi-C008K8Xa.js → wifi-xQgrxKer.js} +1 -1
- package/dist/assets/{zap-VYSIuI1A.js → zap-B6f_Rmgy.js} +1 -1
- package/dist/index.html +5 -5
- package/dist/server/addon.js +106 -4
- package/package.json +1 -1
- package/dist/assets/Notifications-C7yz_fFq.js +0 -1
- package/dist/assets/circle-check-big-Cz1WD2g9.js +0 -1
- package/dist/assets/clock-D9iqCSCa.js +0 -1
- package/dist/assets/dist-9AilmwYu.js +0 -7
- package/dist/assets/plus-pXafUidG.js +0 -1
- package/dist/assets/remoteEntry-CNHP9pn9.js +0 -1
- package/dist/assets/rotate-cw-BvJwWYA6.js +0 -1
- package/dist/assets/search-DHWQ7t3y.js +0 -1
- package/dist/assets/square-CqUnowVe.js +0 -1
- package/dist/assets/src-DlGmnrz9.js +0 -7
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{$n as e,Ao as t,Co as n,Do as r,Eo as i,Ka as a,Ki as o,Oo as s,S as c,So as l,To as u,bo as d,ko as f,oo as p,wo as m,yo as h}from"./src-BDNLbHXL.js";import{Q as g,S as _,W as v,a as y,b,i as x,q as S,t as C,x as w}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{E as T,T as E,k as D,w as O}from"./src-SFNx0Juf.js";import{p as k}from"./player-overlays-CNHQKrHd.js";import{t as A}from"./circle-check-big-DifLR11P.js";import{t as j}from"./copy-D4StuZzs.js";import{t as ee}from"./pencil-BuY8CueB.js";import{t as M}from"./plus-DyBHOfPx.js";import{t as N}from"./refresh-cw-BwbLLVV6.js";import{t as te}from"./search-BLl1nrAm.js";import{t as P}from"./send-CrQGjBpn.js";import{N as ne,S as F,V as re,W as I,i as ie,s as L}from"./index-BsmimqzB.js";import{t as R}from"./AdminPage-Dq33XE9j.js";import{t as ae}from"./AdminTabs-C-SMNF-6.js";var oe=I(`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`}]]),se=I(`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`}]]),z=I(`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`}]]);g();var B=e=>typeof e==`string`&&e.length>0;function ce(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 le(e,t){return e.format.includes(t)?t:e.format[0]??`text`}function ue(e,t){let n=[];for(let r of e.attachments.mediaTypes){if(n.length>=e.attachments.max)break;let i=t[r];B(i)&&n.push({mediaType:r,url:i})}return n}function de(e,t){if(e.actions<=0)return[];let n=[];for(let r of t){if(n.length>=e.actions)break;let t=B(r.label),i=B(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 fe(e,t){let n=e.levels.some(e=>e.id===t.level)?t.level:void 0,r=ue(e,t.attachmentUrls),i=de(e,t.actions),a=e.ttl&&B(t.ttl)?Number(t.ttl):void 0;return{body:t.body,format:le(e,t.format),priority:pe(t.priority),...B(t.title)?{title:t.title}:{},...n?{level:n}:{},...r.length>0?{attachments:r}:{},...i.length>0?{actions:i}:{},...e.clickUrl&&B(t.clickUrl)?{clickUrl:t.clickUrl}:{},...e.sound&&B(t.sound)?{sound:t.sound}:{},...a!==void 0&&Number.isFinite(a)?{ttl:a}:{},...B(t.tag)?{tag:t.tag}:{}}}function pe(e){return Number.isFinite(e)?Math.min(5,Math.max(1,Math.round(e))):3}function me(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 V(e){return{level:``,priority:3,format:e.format[0]??`text`,title:``,body:``,attachmentUrls:{},actions:[],clickUrl:``,sound:``,ttl:``,tag:``}}var he={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 ge(e,t){return e.attachments.max>0&&e.attachments.mediaTypes.includes(t)}function _e(e){let t=[`text`];for(let n of[`image`,`gif`,`video`,`audio`])ge(e,n)&&t.push(n);return e.actions>0&&t.push(`actions`),e.levels.length>0&&t.push(`critical`),t.push(`overflow`),t}function H(e,t,n){let r=V(e);return ge(e,t)?{...r,body:n,attachmentUrls:{[t]:he[t]}}:{...r,body:n}}function ve(e,t){let n=V(e);switch(t){case`text`:return{...n,title:`CamStack`,body:`Test notification — text only.`};case`image`:return H(e,`image`,`Test notification with an image.`);case`gif`:return H(e,`gif`,`Test notification with an animation.`);case`video`:return H(e,`video`,`Test notification with a video.`);case`audio`:return H(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=me(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 ye={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 be({target:e,kind:r,open:i,onClose:a}){let o=k(),s=v(()=>ce(r.caps),[r.caps]),c=v(()=>_e(r.caps),[r.caps]),[u,p]=S(()=>V(r.caps)),[g,y]=S(null),b=v(()=>fe(r.caps,u),[r.caps,u]),x=u.body.length,T=x>s.bodyMaxLen,E=e=>p(t=>({...t,...e})),D=C({mutationFn:()=>o.trpcClient.notificationOutput.testTarget.mutate({addonId:e.addonId,targetId:e.id,sample:fe(r.caps,u)}),onMutate:()=>y(null),onSuccess:e=>y(e),onError:e=>y({success:!1,error:e instanceof Error?e.message:`Test failed`})}),O=e=>{p(ve(r.caps,e)),y(null)},A=(e,t,n)=>{let r=u.actions.length>0?[...u.actions]:[];for(;r.length<=e;)r.push({label:``,url:``});r[e]={...r[e],[t]:n},E({actions:r})};return w(h,{open:i,onOpenChange:e=>!e&&a(),children:_(d,{width:`lg`,className:`!max-w-2xl`,children:[w(n,{children:_(m,{children:[`Test "`,e.name,`" (`,r.label,`)`]})}),_(`div`,{className:`space-y-4 max-h-[60vh] overflow-y-auto pr-1`,children:[w(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map(e=>w(t,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>O(e),children:ye[e]},e))}),_(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[s.levels.length>0&&_(`div`,{children:[w(`label`,{className:W,children:`Level`}),_(`select`,{className:U,value:u.level,onChange:e=>E({level:e.target.value}),children:[w(`option`,{value:``,children:`— derive from priority —`}),s.levels.map(e=>_(`option`,{value:e.id,children:[e.label,e.ordinal===null?` (qualitative)`:` (p${e.ordinal})`]},e.id))]}),(()=>{let e=s.levels.find(e=>e.id===u.level);return e?_(`div`,{className:`mt-1 space-y-1`,children:[e.description&&w(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.description}),_(`div`,{className:`flex flex-wrap gap-1`,children:[e.flags?.critical&&w(f,{variant:`danger`,"data-testid":`flag-critical`,children:`critical`}),e.flags?.silent&&w(f,{variant:`info`,children:`silent`}),e.flags?.noPush&&w(f,{variant:`warning`,children:`no-push`})]}),e.requires&&e.requires.length>0&&_(`p`,{className:`text-[10px] text-warning`,children:[`Requires target config: `,e.requires.join(`, `)]})]}):null})()]}),_(`div`,{children:[_(`label`,{className:W,children:[`Priority (ordinal): `,u.priority]}),w(`input`,{type:`range`,min:1,max:5,step:1,value:u.priority,onChange:e=>E({priority:Number(e.target.value)}),className:`w-full accent-primary`,"aria-label":`priority`})]})]}),s.formats.length>0&&_(`div`,{children:[w(`label`,{className:W,children:`Format`}),w(`div`,{className:`flex flex-wrap gap-2`,children:s.formats.map(e=>_(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground cursor-pointer`,children:[w(`input`,{type:`radio`,name:`format`,className:`accent-primary`,checked:u.format===e,onChange:()=>E({format:e})}),e]},e))})]}),_(`div`,{children:[w(`label`,{className:W,children:`Title`}),w(`input`,{className:U,value:u.title,onChange:e=>E({title:e.target.value})})]}),_(`div`,{children:[_(`label`,{className:W,children:[`Body`,` `,_(`span`,{className:T?`text-danger`:`text-foreground-subtle`,children:[`(`,x,`/`,s.bodyMaxLen,T?` — overflow`:``,`)`]})]}),w(`textarea`,{className:`${U} min-h-[80px] resize-y`,value:u.body,onChange:e=>E({body:e.target.value})})]}),s.attachmentSlots.length>0&&_(`div`,{children:[_(`label`,{className:W,children:[`Attachments`,` `,_(`span`,{className:`text-foreground-subtle`,children:[`(mode: `,s.attachmentMode,`, max `,s.attachmentMax,s.attachmentMaxBytes?`, ≤${Math.round(s.attachmentMaxBytes/1024/1024)}MB`:``,`)`]})]}),w(`div`,{className:`space-y-1.5`,children:s.attachmentSlots.map(e=>_(`div`,{className:`flex items-center gap-2`,children:[w(`span`,{className:`text-[10px] w-12 shrink-0 text-foreground-subtle`,children:e}),w(`input`,{className:U,placeholder:`${e} URL`,value:u.attachmentUrls[e]??``,onChange:t=>E({attachmentUrls:{...u.attachmentUrls,[e]:t.target.value}})})]},e))})]}),s.showActions&&_(`div`,{children:[_(`label`,{className:W,children:[`Actions (up to `,s.maxActions,`)`]}),w(`div`,{className:`space-y-1.5`,children:Array.from({length:Math.min(s.maxActions,3)},(e,t)=>_(`div`,{className:`flex items-center gap-2`,children:[w(`input`,{className:U,placeholder:`label`,value:u.actions[t]?.label??``,onChange:e=>A(t,`label`,e.target.value)}),w(`input`,{className:U,placeholder:`url`,value:u.actions[t]?.url??``,onChange:e=>A(t,`url`,e.target.value)})]},t))})]}),_(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[s.showClickUrl&&_(`div`,{children:[w(`label`,{className:W,children:`Click URL`}),w(`input`,{className:U,value:u.clickUrl,onChange:e=>E({clickUrl:e.target.value})})]}),s.showSound&&_(`div`,{children:[w(`label`,{className:W,children:`Sound`}),w(`input`,{className:U,value:u.sound,onChange:e=>E({sound:e.target.value})})]}),s.showTtl&&_(`div`,{children:[w(`label`,{className:W,children:`TTL (seconds)`}),w(`input`,{className:U,type:`number`,value:u.ttl,onChange:e=>E({ttl:e.target.value})})]}),s.showTag&&_(`div`,{children:[w(`label`,{className:W,children:`Tag`}),w(`input`,{className:U,value:u.tag,onChange:e=>E({tag:e.target.value})})]})]}),g&&w(xe,{result:g}),_(`details`,{className:`text-[10px]`,children:[w(`summary`,{className:`cursor-pointer text-foreground-subtle`,children:`Payload preview`}),w(`pre`,{className:`mt-1 overflow-x-auto rounded bg-surface p-2 text-foreground-subtle`,children:JSON.stringify(b,null,2)})]})]}),_(l,{children:[w(t,{variant:`secondary`,size:`sm`,type:`button`,onClick:a,children:`Close`}),_(t,{size:`sm`,type:`button`,disabled:D.isPending||u.body.length===0,onClick:()=>D.mutate(),children:[D.isPending?w(F,{className:`h-3.5 w-3.5 animate-spin`}):w(P,{className:`h-3.5 w-3.5`}),`Send test`]})]})]})})}function xe({result:e}){let t=e.renderedAs;return _(`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:[_(`div`,{className:`flex items-center gap-2 font-medium`,children:[e.success?w(A,{className:`h-3.5 w-3.5 text-success`}):w(ne,{className:`h-3.5 w-3.5 text-danger`}),w(`span`,{children:e.success?`Delivered`:`Failed`})]}),e.error&&w(`p`,{className:`mt-1 text-danger`,children:e.error}),t&&_(`dl`,{className:`mt-2 grid grid-cols-2 gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[w(`dt`,{children:`Resolved level`}),w(`dd`,{className:`text-foreground`,children:t.level}),w(`dt`,{children:`Format sent`}),w(`dd`,{className:`text-foreground`,children:t.format}),w(`dt`,{children:`Attachments sent`}),w(`dd`,{className:`text-foreground`,children:t.attachmentsSent}),w(`dt`,{children:`Actions sent`}),w(`dd`,{className:`text-foreground`,children:t.actionsSent}),w(`dt`,{children:`Truncated`}),w(`dd`,{className:`text-foreground`,children:t.truncated?`yes`:`no`}),w(`dt`,{children:`Dropped`}),w(`dd`,{className:`text-foreground`,children:t.dropped.length>0?t.dropped.join(`, `):`—`})]})]})}function Se(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 Ce(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 we(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 Te(e,t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))r[t]=n.has(t)?``:i;return r}g();var Ee=[`notificationOutput`,`listTargets`],De=[`notificationOutput`,`listTargetKinds`],Oe=[`userManagement`,`listUsers`],G=`ownerUserId`;function ke(e){let t=e.config[G];return typeof t==`string`&&t.length>0?t:null}function Ae(e){return[{key:`name`,header:`Target`,render:t=>{let n=e.kindByKey.get(t.kind);return _(`span`,{className:`flex items-center gap-2`,children:[w(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface text-xs`,title:n?.label??t.kind,children:w(K,{kind:n,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:``})}),w(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name}),!t.enabled&&w(f,{variant:`warning`,children:`disabled`})]})}},{key:`kind`,header:`Kind`,nowrap:!0,render:t=>w(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.kindByKey.get(t.kind)?.label??t.kind})},{key:`owner`,header:`Owner`,nowrap:!0,render:t=>{let n=ke(t);return n===null?w(f,{variant:`default`,children:`system`}):w(`span`,{className:`text-[11px] text-foreground`,children:e.userNameById.get(n)??n})}},{key:`enabled`,header:`On`,align:`center`,nowrap:!0,render:t=>w(u,{checked:t.enabled,onCheckedChange:n=>e.onToggle(t,n),"aria-label":`toggle ${t.name}`})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:n=>{let r=e.kindByKey.get(n.kind);return _(`span`,{className:`flex items-center justify-end gap-1`,children:[w(t,{size:`sm`,variant:`ghost`,type:`button`,disabled:!r,onClick:()=>e.onTest(n),title:`Test`,children:w(P,{className:`h-3.5 w-3.5`})}),w(t,{size:`sm`,variant:`ghost`,type:`button`,disabled:!r,onClick:()=>r&&e.onEdit(n,r),title:`Edit`,children:w(ee,{className:`h-3.5 w-3.5`})}),w(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onDelete(n),title:`Delete`,children:w(L,{className:`h-3.5 w-3.5 text-danger`})})]})}}]}function K({kind:e,imgClassName:t,fallbackClassName:n}){return e?.iconUrl?w(`img`,{src:e.iconUrl,alt:e.label,className:t,loading:`lazy`,draggable:!1}):w(`span`,{className:n,children:e?.icon??`🔔`})}function je(){let e=k(),[n,r]=S({mode:`closed`}),[i,o]=S(null),c=y({queryKey:Ee,queryFn:()=>e.trpcClient.notificationOutput.listTargets.query({})}),l=y({queryKey:De,queryFn:async()=>(await e.trpcClient.notificationOutput.listTargetKinds.query({})).map(e=>{let t=e.iconUrl;return{...e,configSchema:e.configSchema,iconUrl:t}})}),u=v(()=>l.data??[],[l.data]),d=v(()=>{let e=new Map;for(let t of u)e.set(t.kind,t);return e},[u]),f=y({queryKey:Oe,queryFn:()=>e.trpcClient.userManagement.listUsers.query()}),m=v(()=>{let e=new Map;for(let t of f.data??[])e.set(t.id,t.username);return e},[f.data]),h=C({mutationFn:t=>e.trpcClient.notificationOutput.setTargetEnabled.mutate({addonId:t.target.addonId,targetId:t.target.id,enabled:t.enabled}),onSuccess:()=>void c.refetch()}),g=C({mutationFn:t=>e.trpcClient.notificationOutput.deleteTarget.mutate({addonId:t.addonId,targetId:t.id}),onSuccess:()=>void c.refetch()}),b=i?d.get(i.kind):void 0;return _(R,{icon:re,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:_(t,{size:`sm`,type:`button`,onClick:()=>r({mode:`pick-kind`}),children:[w(M,{className:`h-3.5 w-3.5`}),`Add target`]}),children:[c.isLoading&&w(`div`,{className:`flex items-center justify-center py-16`,children:w(F,{className:`h-6 w-6 animate-spin text-primary`})}),c.isError&&!c.isLoading&&w(a,{title:`Failed to load targets`,message:c.error instanceof Error?c.error.message:`Unknown error`,onRetry:()=>void c.refetch()}),!c.isLoading&&!c.isError&&(c.data??[]).length===0&&w(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No notification targets yet. Click "Add target" to configure one.`}),(c.data??[]).length>0&&w(s,{children:w(p,{columns:Ae({kindByKey:d,userNameById:m,onToggle:(e,t)=>h.mutate({target:e,enabled:t}),onTest:o,onEdit:(e,t)=>r({mode:`form`,kind:t,target:e}),onDelete:e=>g.mutate(e)}),rows:c.data??[],rowKey:e=>e.id,minWidthPx:720,bordered:!1})}),n.mode===`pick-kind`&&w(Me,{kinds:u,onCancel:()=>r({mode:`closed`}),onPick:e=>r({mode:`form`,kind:e,target:null})}),n.mode===`form`&&w(Ne,{kind:n.kind,target:n.target,users:f.data??[],onCancel:()=>r({mode:`closed`}),onSaved:()=>{r({mode:`closed`}),c.refetch()}}),i&&b&&w(be,{target:i,kind:b,open:!0,onClose:()=>o(null)})]})}function Me({kinds:e,onPick:n,onCancel:r}){let i=v(()=>Se(e),[e]);return _(s,{className:`p-4 space-y-4`,children:[_(`div`,{className:`flex items-center justify-between`,children:[w(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Choose a notification kind`}),w(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,children:`Cancel`})]}),i.length===0&&w(`p`,{className:`text-xs text-foreground-subtle`,children:`No notification providers are installed. Install the notifiers addon (or connect Home Assistant) to add targets.`}),i.map(e=>_(`div`,{children:[w(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5`,children:e.addonId}),w(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-2`,children:e.kinds.map(t=>_(`button`,{type:`button`,onClick:()=>n(t),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:[w(K,{kind:t,imgClassName:`h-7 w-7 object-contain`,fallbackClassName:`text-lg leading-7`}),w(`span`,{className:`font-medium text-foreground`,children:t.label}),t.supportsDiscovery&&w(f,{variant:`info`,style:`outline`,children:`discover`})]},`${e.addonId}:${t.kind}`))})]},e.addonId))]})}function Ne({kind:e,target:n,users:r,onSaved:a,onCancel:o}){let l=k(),u=v(()=>Ce(e.configSchema),[e.configSchema]),d=v(()=>n?.config??{},[n]),[f,p]=S(n?.name??e.label),[m,h]=S(()=>n?Te(n.config,u):{}),[g,y]=S(null),[b,x]=S(null),[T,E]=S(n?ke(n)??``:``),D=C({mutationFn:()=>l.trpcClient.notificationOutput.discoverTargets.query({addonId:e.addonId,kind:e.kind,config:m}),onSuccess:e=>y(e),onError:e=>x(e instanceof Error?e.message:`Discovery failed`)}),O=C({mutationFn:()=>{let{[G]:t,...r}=we(m,d,u),i=T===``?r:{...r,[G]:T},a={id:n?.id??`${e.kind}-${Date.now()}`,name:f,kind:e.kind,addonId:e.addonId,enabled:n?.enabled??!0,config:i};return l.trpcClient.notificationOutput.upsertTarget.mutate({addonId:e.addonId,target:a})},onSuccess:a,onError:e=>x(e instanceof Error?e.message:`Save failed`)}),A=e=>{p(e.suggestedName),h(t=>({...t,...e.config})),y(null)};return _(s,{className:`p-4 space-y-4`,children:[_(`div`,{className:`flex items-center justify-between`,children:[_(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[w(K,{kind:e,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:`text-lg`}),n?`Edit ${n.name}`:`Add ${e.label} target`]}),w(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:o,children:`Cancel`})]}),b&&w(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:b}),_(`div`,{children:[w(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Name`}),w(`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:f,onChange:e=>p(e.target.value)})]}),_(`div`,{children:[w(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Owner`}),w(i,{value:T,options:[{value:``,label:`System (shared, admin-managed)`},...r.map(e=>({value:e.id,label:e.username}))],onChange:e=>E(e.target.value)}),w(`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&&_(`div`,{className:`space-y-2`,children:[_(t,{size:`sm`,variant:`outline`,type:`button`,disabled:D.isPending,onClick:()=>{x(null),D.mutate()},children:[D.isPending?w(F,{className:`h-3.5 w-3.5 animate-spin`}):w(te,{className:`h-3.5 w-3.5`}),`Discover`]}),g&&g.length===0&&w(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No candidates discovered.`}),g&&g.length>0&&w(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:g.map((e,t)=>_(`button`,{type:`button`,onClick:()=>A(e),className:`flex w-full items-center justify-between px-3 py-1.5 text-xs hover:bg-surface-hover`,children:[w(`span`,{className:`text-foreground`,children:e.suggestedName}),w(`span`,{className:`text-[10px] text-primary`,children:`use`})]},`${e.suggestedName}-${t}`))})]}),u.length>0&&n&&w(`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.`}),w(c,{schema:e.configSchema,values:m,onChange:h}),_(`div`,{className:`flex justify-end gap-2`,children:[w(t,{variant:`secondary`,size:`sm`,type:`button`,onClick:o,children:`Cancel`}),_(t,{size:`sm`,type:`button`,disabled:O.isPending||f.trim().length===0,onClick:()=>{x(null),O.mutate()},children:[O.isPending&&w(F,{className:`h-3.5 w-3.5 animate-spin`}),n?`Save changes`:`Create target`]})]})]})}function q(e){return t=>Object.prototype.hasOwnProperty.call(e,t)}var Pe=q({devices:!0}),Fe=q({classes:!0,classesExclude:!0,labelEquals:!0,identities:!0,identitiesExclude:!0,eventTypeTokens:!0,sensorKinds:!0}),Ie=q({zonesExclude:!0}),Le=q({minConfidence:!0,minImportance:!0,minLabelConfidence:!0}),Re=q({minDwellSeconds:!0}),ze=q({source:!0}),Be=q({crossing:!0}),Ve=q({packagePhase:!0}),He=q({zones:!0}),Ue=q({plates:!0}),We=q({occupancy:!0});function J(e,t){let n=e[t];return Array.isArray(n)?n:[]}function Ge(e,t){let n=e[t];return typeof n==`number`?n:void 0}var Ke=[{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 qe(e){let t=e.replace(/[-_]/g,` `);return t.charAt(0).toUpperCase()+t.slice(1)}function Je(e,t){let n=e.filter(t),r=new Set(Ke.map(e=>e.id)),i=[];for(let e of Ke){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:qe(e),descriptors:n.filter(t=>t.group===e)});return i}g();function Ye(e,t){let n=k().trpcClient,r=x({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 v(()=>{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 Xe(e){let t=k().trpcClient,n=x({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 v(()=>{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 Ze(){let t=e();return v(()=>({options:(t.data??[]).map(e=>({value:e.name,label:e.name})),loading:t.isLoading}),[t.data,t.isLoading])}function Qe(){let e=o({limit:200});return v(()=>{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 Y({options:e,value:t,onChange:n,loading:r,emptyHint:i,placeholder:a}){let[o,s]=S(``),c=v(()=>new Set(e.map(e=>e.value)),[e]),l=v(()=>new Set(t),[t]),u=t.filter(e=>!c.has(e)),d=e=>{n(l.has(e)?t.filter(t=>t!==e):[...t,e])},f=()=>{let e=o.trim();e.length===0||t.includes(e)||(n([...t,e]),s(``))};return _(`div`,{className:`mt-1 space-y-1.5`,children:[u.length>0&&w(`div`,{className:`flex flex-wrap gap-1`,children:u.map(e=>_(`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?w(`div`,{className:`max-h-40 overflow-y-auto rounded-md border border-border divide-y divide-border`,children:e.map(e=>_(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[w(`input`,{type:`checkbox`,checked:l.has(e.value),onChange:()=>d(e.value),className:`accent-primary`}),w(`span`,{className:`flex-1 truncate`,children:e.label}),e.hint!==void 0&&w(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.hint})]},e.value))}):w(`p`,{className:`text-[10px] text-foreground-subtle`,children:r===!0?`Loading…`:i}),w(`input`,{value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),f())},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 X=[{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.`}];function $e(e){return X.find(t=>t.value===e)?.label??e}function et(e){return X.find(t=>t.value===e)?.value}var Z=[{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 tt(e){return Z.find(t=>t.value===e)?.value}var nt=[{value:``,label:`Automatic`},{value:`cropped`,label:`Cropped on the subject`},{value:`full`,label:`Full frame`},{value:`boxed`,label:`Full frame with boxes`}];function rt(e){let t=nt.find(t=>t.value===e)?.value;return t===``?void 0:t}var it=[{value:``,label:`Lowest available`},{value:`low`,label:`Low`},{value:`mid`,label:`Medium`},{value:`high`,label:`High`}];function at(e){let t=it.find(t=>t.value===e)?.value;return t===``?void 0:t}var ot=[{value:`any`,label:`Any source`},{value:`pipeline`,label:`Pipeline`},{value:`onboard`,label:`Onboard (camera)`},{value:`sensor`,label:`Sensor`}],st=[{value:`delivered`,label:`Delivered`},{value:`picked-up`,label:`Picked up`},{value:`both`,label:`Both`}],Q=[{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 ct(e){let t=Q.find(t=>t.value===e)?.value;return t===``||t===void 0?void 0:t}var lt=[{value:`any`,label:`Any of`},{value:`all`,label:`All of`}],ut=[{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 dt(){return{name:``,enabled:!0,delivery:`immediate`,targetIds:[],targetUsers:[],targetParams:{},priority:3,mediaAttach:`best`,mediaZoneCrop:!1,mediaFrame:void 0,mediaGif:!1,mediaClip:!1,mediaProfile:void 0,templateTitle:``,templateBody:``,conditions:{},schedule:void 0}}function ft(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,templateTitle:e.template?.title??``,templateBody:e.template?.body??``,conditions:e.conditions,schedule:e.schedule}}function pt(e){return e.name.trim().length>0&&(e.targetIds.length>0||e.targetUsers.length>0)}function mt(e,t){return e.appliesTo.includes(t)}var ht={source:`any`};function gt(e,t){if(t==null)return!0;if(Array.isArray(t))return t.length===0;if(typeof t==`string`)return t.length===0||ht[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 _t(e,t,n){let r=n.length===0?null:new Set(n.filter(e=>e.id!==`schedule`&&mt(e,t)).map(e=>e.id)),i={};for(let[t,n]of Object.entries(e))r!==null&&!r.has(t)||gt(t,n)||(i[t]=n);return i}function vt(e){return e!==void 0&&e.windows.length>0}function yt(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=(n.length===0||n.some(t=>t.id===`schedule`&&mt(t,e.delivery)))&&vt(e.schedule)?e.schedule:void 0;return{name:e.name.trim(),enabled:e.enabled,delivery:e.delivery,conditions:_t(e.conditions,e.delivery,n),...o?{schedule:o}:{},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:{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}},throttle:t?.throttle??{cooldownSec:60,scope:`rule-device`},priority:e.priority,...a?{template:a}:{}}}g();var bt=`block text-[11px] font-medium text-foreground`,$=`text-[10px] text-foreground-subtle mt-0.5`;function xt({cameras:e,value:t,onChange:n}){if(e.length===0)return w(`p`,{className:$,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 w(`div`,{className:`mt-1 max-h-40 overflow-y-auto rounded-md border border-border divide-y divide-border`,children:e.map(e=>_(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[w(`input`,{type:`checkbox`,checked:t.includes(e.id),onChange:()=>r(e.id),className:`accent-primary`}),w(`span`,{className:`flex-1 truncate`,children:e.name})]},e.id))})}function St({value:e,placeholder:t,onChange:n}){let[i,a]=S(``),o=()=>{let t=i.trim();if(t.length===0||e.includes(t)){a(``);return}n([...e,t]),a(``)},s=t=>n(e.filter(e=>e!==t));return _(`div`,{className:`mt-1 space-y-1.5`,children:[e.length>0&&w(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>_(`span`,{className:`inline-flex items-center gap-1 rounded bg-surface-hover px-1.5 py-0.5 text-[11px] text-foreground`,children:[e,w(`button`,{type:`button`,onClick:()=>s(e),"aria-label":`remove ${e}`,className:`text-foreground-subtle hover:text-danger`,children:w(ie,{className:`h-3 w-3`})})]},e))}),w(r,{value:i,placeholder:t,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),o())},onBlur:o})]})}function Ct({picker:e,value:t,onChange:n}){let r=v(()=>E(e),[e]),i=v(()=>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 _(`div`,{className:`space-y-2`,children:[a.length>0&&w(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>_(`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=>_(`div`,{children:[w(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-muted mb-1`,children:e.fallbackLabel}),w(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map(e=>{let t=i.has(e.value);return w(`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 wt({value:e,min:t,max:n,step:i,onChange:a}){return _(`div`,{className:`mt-1 flex items-center gap-2`,children:[w(r,{type:`number`,value:e??``,min:t,max:n,step:i,className:`max-w-[8rem]`,onChange:e=>{let t=e.target.value;if(t===``){a(void 0);return}let n=Number(t);a(Number.isFinite(n)?n:void 0)}}),e!==void 0&&n!==void 0&&w(`input`,{type:`range`,min:t,max:n,step:i,value:e,onChange:e=>a(Number(e.target.value)),className:`flex-1 accent-primary`,"aria-label":`value`})]})}function Tt({value:e,onChange:t}){let n=e??``,r=Q.find(e=>e.value===n);return _(`div`,{className:`mt-1 space-y-1`,children:[w(i,{value:n,options:Q.map(e=>({value:e.value,label:e.label})),onChange:e=>t(ct(e.target.value))}),r!==void 0&&w(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:r.hint})]})}function Et({deviceIds:e,cameras:t,value:n,onChange:r}){let a=n?.ids??[],o=n?.match??`any`,s=e=>r(e.length>0?{ids:e,match:o}:void 0),c=e=>r(a.length>0?{ids:a,match:e}:void 0);return _(`div`,{className:`mt-1 space-y-1.5`,children:[w(`div`,{className:`max-w-[10rem]`,children:w(i,{value:o,options:lt.map(e=>({value:e.value,label:e.label})),onChange:e=>c(e.target.value===`all`?`all`:`any`)})}),w(Dt,{deviceIds:e,cameras:t,value:a,onChange:s})]})}function Dt({deviceIds:e,cameras:t,value:n,onChange:r}){let{options:i,loading:a}=Ye(e,t);return w(Y,{options:i,value:n,onChange:r,loading:a,emptyHint:e.length===0?`Select cameras above to pick their zones by name — or type a zone id.`:`The selected cameras have no zones — type a zone id if you know one.`,placeholder:`Zone id…`})}function Ot({value:e,onChange:t}){let{options:n,loading:r}=Ze();return w(Y,{options:n,value:e,onChange:t,loading:r,emptyHint:`No identities in the face gallery yet — type a name.`,placeholder:`Identity name…`})}function kt({deviceIds:e,value:t,onChange:n}){let{options:r,loading:i}=Xe(e);return w(Y,{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 At=[{value:`became-occupied`,label:`Became occupied`},{value:`became-free`,label:`Became free`},{value:`>=`,label:`Count ≥`},{value:`<=`,label:`Count ≤`}],jt={op:`became-occupied`,count:1,sustainSeconds:15};function Mt({deviceIds:e,cameras:t,classOptions:n,value:a,onChange:o}){let{options:s,loading:c}=Ye(e,t),l=a??jt,u=e=>o({...l,...e}),d=l.op===`became-occupied`||l.op===`became-free`;return _(`div`,{className:`mt-1 space-y-1.5`,children:[_(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[w(`div`,{className:`min-w-[10rem]`,children:w(i,{value:l.zoneId??``,options:[{value:``,label:c?`Loading zones…`:`— whole frame —`},...s.map(e=>({value:e.value,label:e.label}))],onChange:e=>u({zoneId:e.target.value===``?void 0:e.target.value})})}),w(`div`,{className:`min-w-[9rem]`,children:w(i,{value:l.className??``,options:[{value:``,label:`— any class —`},...n.map(e=>({value:e.value,label:e.label}))],onChange:e=>u({className:e.target.value===``?void 0:e.target.value})})}),w(`div`,{className:`min-w-[9rem]`,children:w(i,{value:l.op,options:At.map(e=>({value:e.value,label:e.label})),onChange:e=>{let t=At.find(t=>t.value===e.target.value);t&&u({op:t.value})}})})]}),_(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:[_(`label`,{className:`flex items-center gap-1`,children:[d?`Threshold`:`Count`,w(r,{type:`number`,min:0,className:`w-16`,value:String(l.count),onChange:e=>u({count:Math.max(0,Number(e.target.value)||0)})})]}),_(`label`,{className:`flex items-center gap-1`,children:[`Hold for`,w(r,{type:`number`,min:0,max:3600,className:`w-16`,value:String(l.sustainSeconds),onChange:e=>u({sustainSeconds:Math.min(3600,Math.max(0,Number(e.target.value)||0))})}),`s`]}),a===void 0?null:w(`button`,{type:`button`,onClick:()=>o(void 0),className:`underline hover:text-foreground`,children:`Clear`})]}),w(`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 Nt({value:e,onChange:t}){let n=e?.values??[],i=e?.maxDistance??1,a=e=>t(e.length>0?{values:e,maxDistance:i}:void 0),o=e=>t(n.length>0?{values:n,maxDistance:e}:void 0),s=Qe().filter(e=>!n.includes(e));return _(`div`,{className:`mt-1 space-y-1.5`,children:[w(St,{value:n,placeholder:`Plate text…`,onChange:a}),s.length>0&&_(`div`,{className:`flex flex-wrap items-center gap-1`,children:[w(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Seen:`}),s.slice(0,12).map(e=>w(`button`,{type:`button`,onClick:()=>a([...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))]}),_(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Max distance`,w(r,{type:`number`,min:0,max:3,step:1,value:i,className:`max-w-[5rem]`,onChange:e=>{let t=Number(e.target.value);o(Number.isFinite(t)?Math.max(0,Math.min(3,t)):1)}})]})]})}var Pt=[{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 Ft(e){let t=Math.floor(e/60),n=e%60;return`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}`}function It(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 Lt(){return{days:[1,2,3,4,5],startMinute:540,endMinute:1080}}function Rt({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,Lt()],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 _(`div`,{className:`mt-1 space-y-2`,children:[n.length===0?w(`p`,{className:$,children:`Always active — add a window to restrict when the rule fires.`}):n.map((e,t)=>w(zt,{window:e,onChange:e=>s(t,e),onRemove:()=>o(t)},t)),_(`div`,{className:`flex items-center gap-3`,children:[_(`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:[w(M,{className:`h-3 w-3`}),` Add window`]}),n.length>0&&_(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[w(`input`,{type:`checkbox`,checked:r,onChange:e=>i([...n],e.target.checked),className:`accent-primary`}),`Active outside the windows`]})]})]})}function zt({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 _(`div`,{className:`space-y-1.5 rounded-md border border-border p-2`,children:[_(`div`,{className:`flex items-center gap-2 text-xs`,children:[w(`input`,{type:`time`,value:Ft(e.startMinute),onChange:n=>t({...e,startMinute:It(n.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),w(`span`,{className:`text-foreground-subtle`,children:`→`}),w(`input`,{type:`time`,value:Ft(e.endMinute),onChange:n=>t({...e,endMinute:It(n.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),w(`span`,{className:`flex-1`}),w(`button`,{type:`button`,onClick:n,"aria-label":`Remove window`,className:`text-foreground-subtle hover:text-danger`,children:w(L,{className:`h-3.5 w-3.5`})})]}),w(`div`,{className:`flex flex-wrap gap-1`,children:Pt.map(t=>w(`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))})]})}g();function Bt({catalog:e,taxonomy:t,delivery:n,conditions:r,schedule:i,cameras:a,onConditionsChange:o,onScheduleChange:s}){let c=(e,t)=>{let n={...r};t===void 0?delete n[e]:n[e]=t,o(n)},l=v(()=>Je(e,e=>O(e.id)),[e]),u=v(()=>Je(e,e=>!O(e.id)),[e]),[d,p]=S(()=>{if(Ht(r,i))return!0;try{return localStorage.getItem(Vt)===`1`}catch{return!1}}),m=()=>{let e=!d;p(e);try{localStorage.setItem(Vt,e?`1`:`0`)}catch{}},h=e=>e.map(e=>_(`div`,{className:`space-y-2.5`,children:[w(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:e.label}),e.descriptors.map(e=>{let o=mt(e,n);return _(`div`,{className:o?``:`opacity-50`,"data-testid":`condition-${e.id}`,children:[_(`div`,{className:`flex items-center justify-between gap-2`,children:[w(`label`,{className:bt,children:e.label}),!o&&_(f,{variant:`default`,children:[`not for `,e.appliesTo.join(` / `)]})]}),o?w(Ut,{descriptor:e,taxonomy:t,conditions:r,schedule:i,cameras:a,onFieldChange:c,onScheduleChange:s}):w(`p`,{className:$,children:`Not evaluated for the selected trigger — switch the trigger to use it.`}),o&&e.description&&w(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:e.description})]},e.id)})]},e.id));return _(`div`,{className:`space-y-4`,children:[h(l),u.length>0&&w(`button`,{type:`button`,onClick:m,"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:d?`▾ Hide advanced configurations`:`▸ Show more configurations`}),d&&h(u)]})}var Vt=`camstack.nc.showAdvanced`;function Ht(e,t){for(let[t,n]of Object.entries(e))if(!O(t)&&n!==void 0&&!(Array.isArray(n)&&n.length===0))return!0;return t!==void 0&&t.windows.length>0}function Ut({descriptor:e,taxonomy:t,conditions:n,schedule:r,cameras:a,onFieldChange:o,onScheduleChange:s}){switch(e.valueType){case`deviceIdList`:{if(!Pe(e.id))break;let t=e.id;return w(xt,{cameras:a,value:n[t]??[],onChange:e=>o(t,e.length>0?e:void 0)})}case`stringList`:{if(!Fe(e.id))break;let r=e.id,i=e=>o(r,e.length>0?e:void 0);if(r===`identities`||r===`identitiesExclude`)return w(Ot,{value:J(n,r),onChange:i});if(r===`eventTypeTokens`)return w(kt,{deviceIds:n.devices??[],value:J(n,r),onChange:i});let a=T(r,t);return a===null?w(St,{value:J(n,r),placeholder:`Add value…`,onChange:i}):w(Ct,{picker:a,value:J(n,r),onChange:i})}case`zoneIdList`:{if(!Ie(e.id))break;let t=e.id;return w(Dt,{deviceIds:n.devices??[],cameras:a,value:J(n,t),onChange:e=>o(t,e.length>0?e:void 0)})}case`number01`:{if(!Le(e.id))break;let t=e.id;return w(wt,{value:Ge(n,t),min:0,max:1,step:.05,onChange:e=>o(t,e)})}case`number`:{if(!Re(e.id))break;let t=e.id;return w(wt,{value:Ge(n,t),min:0,step:1,onChange:e=>o(t,e)})}case`sourceSelect`:{if(!ze(e.id))break;let t=e.id;return w(i,{value:n[t]??`any`,options:ot.map(e=>({value:e.value,label:e.label})),onChange:e=>o(t,Kt(e.target.value))})}case`crossingSelect`:{if(!Be(e.id))break;let t=e.id;return w(Tt,{value:n[t],onChange:e=>o(t,e)})}case`packagePhase`:{if(!Ve(e.id))break;let t=e.id;return w(i,{value:n[t]??``,options:[{value:``,label:`— any phase —`},...st.map(e=>({value:e.value,label:e.label}))],onChange:e=>o(t,qt(e.target.value))})}case`zoneSelection`:{if(!He(e.id))break;let t=e.id;return w(Et,{deviceIds:n.devices??[],cameras:a,value:n[t],onChange:e=>o(t,e)})}case`plateMatcher`:{if(!Ue(e.id))break;let t=e.id;return w(Nt,{value:n[t],onChange:e=>o(t,e)})}case`occupancy`:{if(!We(e.id))break;let r=e.id;return w(Mt,{deviceIds:n.devices??[],cameras:a,classOptions:Wt(t),value:n[r],onChange:e=>o(r,e)})}case`schedule`:return w(Rt,{value:r,onChange:s});default:break}return w(Gt,{descriptor:e,conditions:n})}function Wt(e){let t=T(`classes`,e);return t===null?[]:t.groups.flatMap(e=>e.options)}function Gt({descriptor:e,conditions:t}){let n=Object.entries(t).find(([t])=>t===e.id);return _(`p`,{className:$,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.`,` `,_(`span`,{className:`text-foreground-muted`,children:[`(`,e.valueType,`)`]})]})}function Kt(e){if(e===`pipeline`||e===`onboard`||e===`sensor`||e===`any`)return e}function qt(e){return st.find(t=>t.value===e)?.value}g();var Jt=[`notificationRules`,`listRules`],Yt=[`notificationOutput`,`listTargets`,`forRules`],Xt=[`notificationRules`,`getConditionCatalog`],Zt=[`deviceManager`,`listAll`,`forRules`];function Qt(){let e=k(),[n,r]=S({mode:`closed`}),[i,o]=S(null),c=y({queryKey:Jt,queryFn:async()=>(await e.trpcClient.notificationRules.listRules.query({})).rules}),l=y({queryKey:Yt,queryFn:()=>e.trpcClient.notificationOutput.listTargets.query({})}),u=y({queryKey:Xt,queryFn:()=>e.trpcClient.notificationRules.getConditionCatalog.query({})}),d=y({queryKey:Zt,queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({})).filter(e=>e.type===D.Camera).map(e=>({id:e.id,name:e.name}))}),f=v(()=>{let e=new Map;for(let t of l.data??[])e.set(t.id,t.name);return e},[l.data]),m=C({mutationFn:t=>e.trpcClient.notificationRules.setRuleEnabled.mutate(t),onSuccess:()=>void c.refetch()}),h=C({mutationFn:t=>e.trpcClient.notificationRules.deleteRule.mutate({ruleId:t}),onSuccess:()=>{o(null),c.refetch()}}),g=c.data??[];return _(R,{icon:oe,title:`Notification Rules`,subtitle:`Author rules that turn detections, doorbell presses and package events into notifications. Each rule picks a trigger, matches conditions and fans out to one or more delivery targets.`,actions:_(t,{size:`sm`,type:`button`,onClick:()=>r({mode:`form`,rule:null}),children:[w(M,{className:`h-3.5 w-3.5`}),`New rule`]}),children:[c.isLoading&&w(`div`,{className:`flex items-center justify-center py-16`,children:w(F,{className:`h-6 w-6 animate-spin text-primary`})}),c.isError&&!c.isLoading&&w(a,{title:`Failed to load rules`,message:c.error instanceof Error?c.error.message:`Unknown error`,onRetry:()=>void c.refetch()}),!c.isLoading&&!c.isError&&g.length===0&&w(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No notification rules yet. Click "New rule" to author one.`}),g.length>0&&w(s,{children:w(p,{columns:$t({targetNameById:f,confirmDeleteId:i,deletePending:h.isPending,onToggle:(e,t)=>m.mutate({ruleId:e.id,enabled:t}),onEdit:e=>r({mode:`form`,rule:e}),onDuplicate:e=>r({mode:`form`,rule:{...e,id:``,name:`${e.name} (copy)`}}),onAskDelete:o,onConfirmDelete:e=>h.mutate(e.id)}),rows:g,rowKey:e=>e.id,minWidthPx:760,bordered:!1})}),n.mode===`form`&&w(en,{rule:n.rule,targets:l.data??[],catalog:u.data?.catalog??[],taxonomy:u.data?.taxonomy,cameras:d.data??[],onCancel:()=>r({mode:`closed`}),onSaved:()=>{r({mode:`closed`}),c.refetch()}})]})}function $t(e){return[{key:`name`,header:`Rule`,render:e=>_(`span`,{className:`flex items-center gap-2`,children:[w(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),!e.enabled&&w(f,{variant:`warning`,children:`disabled`})]})},{key:`trigger`,header:`Trigger`,nowrap:!0,render:e=>w(`span`,{className:`text-[11px] text-foreground-subtle`,children:$e(e.delivery)})},{key:`targets`,header:`Targets`,render:t=>{let n=t.targets[0],r=n?e.targetNameById.get(n.targetId)??n.targetId:null;return w(`span`,{className:`text-[11px] text-foreground-subtle`,children:t.targets.length===1&&r?r:`${t.targets.length} target${t.targets.length===1?``:`s`}`})}},{key:`priority`,header:`Priority`,align:`center`,nowrap:!0,render:e=>w(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.priority})},{key:`enabled`,header:`On`,align:`center`,nowrap:!0,render:t=>w(u,{checked:t.enabled,onCheckedChange:n=>e.onToggle(t,n),"aria-label":`toggle ${t.name}`})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:n=>_(`span`,{className:`flex items-center justify-end gap-1`,children:[w(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onEdit(n),title:`Edit`,children:w(ee,{className:`h-3.5 w-3.5`})}),w(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onDuplicate(n),title:`Duplicate`,children:w(j,{className:`h-3.5 w-3.5`})}),e.confirmDeleteId===n.id?_(b,{children:[_(t,{size:`sm`,variant:`danger`,type:`button`,disabled:e.deletePending,onClick:()=>e.onConfirmDelete(n),children:[e.deletePending&&w(F,{className:`h-3.5 w-3.5 animate-spin`}),`Confirm`]}),w(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onAskDelete(null),children:`Cancel`})]}):w(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onAskDelete(n.id),title:`Delete`,children:w(L,{className:`h-3.5 w-3.5 text-danger`})})]})}]}function en({rule:e,targets:n,catalog:a,taxonomy:o,cameras:s,onSaved:c,onCancel:l}){let p=k(),m=e!=null&&e.id.length>0,[g,v]=S(()=>e?ft(e):dt()),[b,x]=S(null),[T,E]=S(null),D=e=>v(t=>({...t,...e})),O=m&&e?{throttle:e.throttle}:void 0,A=C({mutationFn:async()=>{let t=yt(g,O,a);m&&e?await p.trpcClient.notificationRules.updateRule.mutate({ruleId:e.id,patch:t}):await p.trpcClient.notificationRules.createRule.mutate({rule:t})},onSuccess:c,onError:e=>x(e instanceof Error?e.message:`Save failed`)}),j=C({mutationFn:async()=>{let e=yt(g,O,a);return(await p.trpcClient.notificationRules.testRule.mutate({rule:e,lookbackMinutes:60})).results},onMutate:()=>E(null),onSuccess:e=>E(e),onError:e=>x(e instanceof Error?e.message:`Test failed`)}),ee=g.targetIds.map(e=>n.find(t=>t.id===e)?.name??e),M=e=>D({targetIds:g.targetIds.includes(e)?g.targetIds.filter(t=>t!==e):[...g.targetIds,e]}),N=y({queryKey:[`userManagement`,`listUsers`],queryFn:()=>p.trpcClient.userManagement.listUsers.query()}).data,te=e=>D({targetUsers:g.targetUsers.includes(e)?g.targetUsers.filter(t=>t!==e):[...g.targetUsers,e]}),P=X.find(e=>e.value===g.delivery)?.hint;return w(h,{open:!0,onOpenChange:e=>!e&&l(),children:_(d,{width:`lg`,placement:`sheet-on-mobile`,children:[_(`div`,{className:`flex items-center justify-between mb-3`,children:[_(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[w(oe,{className:`h-4 w-4 text-foreground-subtle`}),m?`Edit ${e?.name}`:`New notification rule`]}),w(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:l,children:`Cancel`})]}),b&&w(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger mb-3`,children:b}),_(`div`,{className:`space-y-4`,children:[_(`div`,{className:`flex items-end gap-3`,children:[_(`div`,{className:`min-w-0 flex-1`,children:[w(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Name`}),w(r,{value:g.name,onChange:e=>D({name:e.target.value}),placeholder:`e.g. Front door package`})]}),_(`label`,{className:`flex items-center gap-2 pb-1.5 text-[11px] font-medium text-foreground`,children:[w(u,{checked:g.enabled,onCheckedChange:e=>D({enabled:e}),"aria-label":`enabled`}),`Enabled`]})]}),_(`div`,{children:[w(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Trigger`}),w(i,{value:g.delivery,onChange:e=>{let t=et(e.target.value);t&&D({delivery:t})},options:X.map(e=>({value:e.value,label:e.label}))}),P&&w(`p`,{className:`text-[10px] text-foreground-subtle mt-1`,children:P})]}),_(`div`,{children:[w(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Delivery targets`}),n.length===0?w(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No delivery targets configured. Add one under the Targets tab first.`}):w(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:n.map(e=>_(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[w(`input`,{type:`checkbox`,checked:g.targetIds.includes(e.id),onChange:()=>M(e.id),className:`accent-primary`}),w(`span`,{className:`flex-1 truncate`,children:e.name}),!e.enabled&&w(f,{variant:`warning`,children:`disabled`})]},e.id))})]}),_(`div`,{children:[w(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Notify users`}),(N??[]).length===0?w(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No users to notify.`}):w(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:(N??[]).map(e=>_(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[w(`input`,{type:`checkbox`,checked:g.targetUsers.includes(e.id),onChange:()=>te(e.id),className:`accent-primary`}),w(`span`,{className:`flex-1 truncate`,children:e.username}),e.isAdmin&&w(f,{variant:`info`,children:`admin`})]},e.id))}),w(`p`,{className:`text-[10px] text-foreground-subtle mt-1`,children:`Delivers to the targets each user owns, only for cameras that user can access.`})]}),_(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[_(`div`,{children:[w(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Priority`}),w(i,{value:String(g.priority),onChange:e=>D({priority:Number(e.target.value)}),options:ut.map(e=>({value:String(e.value),label:e.label}))})]}),_(`div`,{children:[w(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Media attachment`}),w(i,{value:g.mediaAttach,onChange:e=>{let t=tt(e.target.value);t&&D({mediaAttach:t})},options:Z.map(e=>({value:e.value,label:e.label}))}),w(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:Z.find(e=>e.value===g.mediaAttach)?.description}),_(`div`,{className:`mt-2 space-y-1`,children:[_(`label`,{className:`flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[w(`input`,{type:`checkbox`,checked:g.mediaZoneCrop,onChange:e=>D({mediaZoneCrop:e.target.checked}),className:`accent-primary`}),`Crop the image to the rule's zone`]}),_(`label`,{className:`flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[w(`input`,{type:`checkbox`,checked:g.mediaGif,onChange:e=>D({mediaGif:e.target.checked}),className:`accent-primary`}),`Attach a GIF around the event`]}),_(`label`,{className:`flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[w(`input`,{type:`checkbox`,checked:g.mediaClip,onChange:e=>D({mediaClip:e.target.checked}),className:`accent-primary`}),`Attach an MP4 clip around the event`]})]}),(g.mediaGif||g.mediaClip)&&_(`div`,{className:`mt-2`,children:[w(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Video quality`}),w(i,{value:g.mediaProfile??``,onChange:e=>D({mediaProfile:at(e.target.value)}),options:it.map(e=>({value:e.value,label:e.label}))}),w(`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.`})]})]}),_(`div`,{children:[w(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Image frame`}),w(i,{value:g.mediaFrame??``,onChange:e=>D({mediaFrame:rt(e.target.value)}),options:nt.map(e=>({value:e.value,label:e.label}))}),w(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:`What the attached still shows. "Automatic" leaves it to the attachment mode above.`})]})]}),_(`div`,{className:`space-y-2`,children:[_(`div`,{children:[w(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Notification title`}),w(r,{value:g.templateTitle,onChange:e=>D({templateTitle:e.target.value}),placeholder:`{{camera}} — {{class}}`})]}),_(`div`,{children:[w(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Notification body`}),w(`textarea`,{value:g.templateBody,onChange:e=>D({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`})]}),_(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Leave blank to use the backend default text. Supported variables include`,` `,w(`code`,{children:`{{camera}}`}),`, `,w(`code`,{children:`{{class}}`}),`, `,w(`code`,{children:`{{label}}`}),`,`,` `,w(`code`,{children:`{{zone}}`}),`, `,w(`code`,{children:`{{confidence}}`}),`, `,w(`code`,{children:`{{time}}`}),`.`]})]}),_(`div`,{className:`rounded-md border border-border px-3 py-3`,children:[w(`div`,{className:`mb-2 text-[11px] font-semibold text-foreground`,children:`Conditions`}),a.length===0?w(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Condition catalog unavailable — this rule matches on its trigger and targets alone.`}):w(Bt,{catalog:a,taxonomy:o,delivery:g.delivery,conditions:g.conditions,schedule:g.schedule,cameras:s,onConditionsChange:e=>D({conditions:e}),onScheduleChange:e=>D({schedule:e})})]}),_(`div`,{className:`rounded-md border border-border px-3 py-3`,children:[_(`div`,{className:`flex items-center justify-between gap-2`,children:[w(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Test rule`}),_(t,{size:`sm`,variant:`outline`,type:`button`,disabled:j.isPending||!pt(g),onClick:()=>{x(null),j.mutate()},children:[j.isPending?w(F,{className:`h-3.5 w-3.5 animate-spin`}):w(se,{className:`h-3.5 w-3.5`}),`Dry-run (last 60 min)`]})]}),w(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:`Evaluate the CURRENT (unsaved) rule against recently persisted records — no notification is sent.`}),T!==null&&w(tn,{delivery:g.delivery,results:T,targetNames:ee})]})]}),_(`div`,{className:`flex justify-end gap-2 mt-4`,children:[w(t,{variant:`secondary`,size:`sm`,type:`button`,onClick:l,children:`Cancel`}),_(t,{size:`sm`,type:`button`,disabled:A.isPending||!pt(g),onClick:()=>{x(null),A.mutate()},children:[A.isPending&&w(F,{className:`h-3.5 w-3.5 animate-spin`}),m?`Save changes`:`Create rule`]})]})]})})}function tn({delivery:e,results:t,targetNames:n}){if(e===`device-event`)return w(`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 w(`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 _(`div`,{className:`mt-2 space-y-1.5`,children:[_(`div`,{className:`text-[11px] text-foreground-subtle`,children:[r,` of `,t.length,` evaluated record`,t.length===1?``:`s`,` would fire.`]}),w(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:t.slice(0,50).map(e=>_(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5 text-[11px]`,children:[e.wouldFire?w(A,{className:`h-3.5 w-3.5 shrink-0 text-success`}):w(ne,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),w(`span`,{className:`w-32 shrink-0 text-foreground-subtle`,children:new Date(e.timestamp).toLocaleString()}),_(`span`,{className:`w-14 shrink-0 text-foreground-subtle`,children:[`#`,e.deviceId]}),w(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:e.label??e.className??`object`}),e.wouldFire?_(`span`,{className:`shrink-0 truncate text-success`,children:[`→ `,n.join(`, `)||`targets`]}):e.failedCondition&&_(`span`,{className:`shrink-0 text-foreground-subtle`,children:[`failed: `,e.failedCondition]})]},e.recordId))})]})}g();var nn=[{value:1,label:`Last hour`},{value:24,label:`Last 24 hours`},{value:168,label:`Last 7 days`},{value:0,label:`All time`}],rn=[{value:``,label:`Any status`},{value:`pending`,label:`Pending`},{value:`sent`,label:`Sent`},{value:`dead`,label:`Dead`}],an=[50,100,250,500];function on(){return{ruleId:``,deviceId:``,status:``,windowHours:24,limit:100}}function sn(e){return e===`pending`||e===`sent`||e===`dead`?e:void 0}function cn(e){switch(e){case`pending`:return`info`;case`sent`:return`success`;case`dead`:return`danger`}}function ln(){let e=k(),[t,n]=S(on),r=e=>n(t=>({...t,...e})),a=y({queryKey:[`notificationRules`,`listRules`,`forHistory`],queryFn:async()=>(await e.trpcClient.notificationRules.listRules.query({})).rules}),o=y({queryKey:[`deviceManager`,`listAll`,`forHistory`],queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({})).filter(e=>e.type===D.Camera).map(e=>({id:e.id,name:e.name}))}),c=Date.now(),l=y({queryKey:[`notificationRules`,`getHistory`,t],retry:!1,queryFn:async()=>{let n=t.windowHours>0?c-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)}:{},...sn(t.status)?{status:sn(t.status)}:{},...n===void 0?{}:{since:n}}})).entries}}),u=v(()=>{let e=new Map;for(let t of o.data??[])e.set(t.id,t.name);return e},[o.data]),d=e=>u.get(e)??`Camera #${String(e)}`,f=l.data??[],m=l.isError;return _(R,{icon:z,title:`Delivery history`,subtitle:`A searchable log of every notification the rules delivered (or failed to deliver).`,children:[_(`div`,{className:`mb-4 grid grid-cols-2 gap-2 sm:grid-cols-5`,children:[_(`div`,{children:[w(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Rule`}),w(i,{value:t.ruleId,onChange:e=>r({ruleId:e.target.value}),options:[{value:``,label:`All rules`},...(a.data??[]).map(e=>({value:e.id,label:e.name}))]})]}),_(`div`,{children:[w(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Camera`}),w(i,{value:t.deviceId,onChange:e=>r({deviceId:e.target.value}),options:[{value:``,label:`All cameras`},...(o.data??[]).map(e=>({value:String(e.id),label:e.name}))]})]}),_(`div`,{children:[w(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Status`}),w(i,{value:t.status,onChange:e=>r({status:e.target.value}),options:rn.map(e=>({value:e.value,label:e.label}))})]}),_(`div`,{children:[w(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Window`}),w(i,{value:String(t.windowHours),onChange:e=>r({windowHours:Number(e.target.value)}),options:nn.map(e=>({value:String(e.value),label:e.label}))})]}),_(`div`,{children:[w(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Limit`}),w(i,{value:String(t.limit),onChange:e=>r({limit:Number(e.target.value)}),options:an.map(e=>({value:String(e),label:String(e)}))})]})]}),l.isLoading&&w(`div`,{className:`flex items-center justify-center py-16`,children:w(F,{className:`h-6 w-6 animate-spin text-primary`})}),m&&!l.isLoading&&w(s,{children:_(`div`,{className:`flex flex-col items-center gap-2 px-4 py-14 text-center`,children:[w(z,{className:`h-6 w-6 text-foreground-subtle`}),w(`div`,{className:`text-sm font-medium text-foreground`,children:`Delivery history requires a server update`}),w(`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.`}),_(`button`,{type:`button`,onClick:()=>void l.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:[w(N,{className:`h-3 w-3`}),` Retry`]})]})}),!m&&!l.isLoading&&f.length===0&&w(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:`No deliveries match these filters.`}),!m&&f.length>0&&w(s,{children:w(p,{columns:un(d),rows:f,rowKey:e=>e.id,minWidthPx:720,bordered:!1})})]})}function un(e){return[{key:`when`,header:`When`,nowrap:!0,render:e=>w(`span`,{className:`text-[11px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})},{key:`rule`,header:`Rule`,render:e=>w(`span`,{className:`text-xs font-medium text-foreground`,children:e.ruleName})},{key:`camera`,header:`Camera`,nowrap:!0,render:t=>w(`span`,{className:`text-[11px] text-foreground-subtle`,children:e(t.deviceId)})},{key:`subject`,header:`Subject`,render:e=>_(`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=>_(`span`,{className:`flex items-center gap-1.5`,children:[w(f,{variant:cn(e.status),children:e.status}),e.attempts>1?_(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`×`,e.attempts]}):null]})},{key:`error`,header:`Detail`,render:e=>e.error?w(`span`,{className:`text-[11px] text-danger`,children:e.error}):w(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`})}]}function dn(){return w(`div`,{className:`flex flex-col p-4`,children:w(ae,{tabs:[{id:`targets`,label:`Targets`,icon:re,content:w(je,{})},{id:`rules`,label:`Rules`,icon:oe,content:w(Qt,{})},{id:`history`,label:`History`,icon:z,content:w(ln,{})}]})})}export{dn as NotificationsPage,dn as default};
|