@camstack/addon-admin-ui 1.2.34 → 1.2.36
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-DzP-CYOi.js → AddLocationWizard-D3WNwwzO.js} +1 -1
- package/dist/assets/{AddonCollectionPage-B5t3SHZE.js → AddonCollectionPage-D6-DslHs.js} +1 -1
- package/dist/assets/Addons-xiv8mENL.js +1 -0
- package/dist/assets/{AdminTabs-DTECFIAe.js → AdminTabs-EuBAqr82.js} +1 -1
- package/dist/assets/{AiProfiles-D0jpUF4v.js → AiProfiles-YpD0cNHK.js} +1 -1
- package/dist/assets/{Automation-BX0bNbpp.js → Automation-Bnvadu_q.js} +2 -2
- package/dist/assets/{BrokerForm-CROZPAB-.js → BrokerForm-lcZzCH84.js} +1 -1
- package/dist/assets/{Capabilities-DIGQ9fiv.js → Capabilities-BO4EdQiS.js} +1 -1
- package/dist/assets/{CapabilityBadges-B4vHw0qw.js → CapabilityBadges-DDCH_NHd.js} +1 -1
- package/dist/assets/Cluster-HqhJz5p-.js +1 -0
- package/dist/assets/{ClusterRecordingTab-BVkyOEdI.js → ClusterRecordingTab-uoQhw_ij.js} +1 -1
- package/dist/assets/{Dashboard-BlkR2NIh.js → Dashboard-BM-5S-Cj.js} +1 -1
- package/dist/assets/{Data-CECcPfPj.js → Data-DBvjn1Ul.js} +1 -1
- package/dist/assets/DetectionIntelligence-pRUA7cQB.js +1 -0
- package/dist/assets/{DeviceAggregateSection-CbCIksD2.js → DeviceAggregateSection-Cfju7u5B.js} +1 -1
- package/dist/assets/DeviceDetail-DUZkWQjP.js +2 -0
- package/dist/assets/{Devices-COMVrlGU.js → Devices-dbkRu6sh.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-B4Y1MxZ9.js → EmbedPlayerPage-CCTm073s.js} +1 -1
- package/dist/assets/Events-D9bI1DWk.js +1 -0
- package/dist/assets/{FormBuilder-Cogt0U0A.js → FormBuilder-pSCqn9Pp.js} +1 -1
- package/dist/assets/Identity-EphebNT0.js +1 -0
- package/dist/assets/IntegrationDetail-vt_WT2kb.js +1 -0
- package/dist/assets/{Integrations-qNIS4emE.js → Integrations-B3fddOYM.js} +1 -1
- package/dist/assets/Integrations-D2z39cEx.js +1 -0
- package/dist/assets/{Logs-rH1aVfpt.js → Logs-xK4--bh0.js} +1 -1
- package/dist/assets/{MotionZonesSettings-DDSnsNc9.js → MotionZonesSettings-C0sxf_os.js} +1 -1
- package/dist/assets/{MyAccess-J8p1dKF3.js → MyAccess-D043-D3_.js} +1 -1
- package/dist/assets/{Network-C6bXHvxd.js → Network-DQkG5Rat.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-6Dzcc5in.js → NodeAddonsSettingsPanel-CV-reVXD.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-DraQNeS_.js → NodeInferenceDevices-tLptbnD4.js} +1 -1
- package/dist/assets/Notifications-DZMSKwIB.js +1 -0
- package/dist/assets/Pipeline-f6X5D5vg.js +1 -0
- package/dist/assets/Plates-Dct--YKd.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-ByZ6t3aH.js → PrivacyMaskSettings-Cj47lnFx.js} +1 -1
- package/dist/assets/{ProviderIcon-9BELU-vo.js → ProviderIcon-DFIIdGww.js} +1 -1
- package/dist/assets/Recordings-Sn1cAwz6.js +1 -0
- package/dist/assets/Retrain-cSIFr_tD.js +1 -0
- package/dist/assets/{ScanNetworkModal-DGnLpsYA.js → ScanNetworkModal-DEK5U2cd.js} +1 -1
- package/dist/assets/{Settings-DhIPBQcW.js → Settings-Casus0ex.js} +1 -1
- package/dist/assets/{Showroom-C7QnFCQp.js → Showroom-f88Jp6ju.js} +1 -1
- package/dist/assets/{Terminal-DVjWHgq3.js → Terminal-M_8UHE7n.js} +2 -2
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DkbcXBBJ.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-AQtYY37w.js} +1 -1
- package/dist/assets/{build-cluster-graph-BDFGSfk8.js → build-cluster-graph-CAb1HaUw.js} +2 -2
- package/dist/assets/circle-check-big-DG4qagl7.js +1 -0
- package/dist/assets/clock-XeL04zsb.js +1 -0
- package/dist/assets/{copy-oDpB_CYv.js → copy-BtwlORlH.js} +1 -1
- package/dist/assets/debounced-invalidate-D3Cu80c9.js +1 -0
- package/dist/assets/{dist-Dx0ACB1O.js → dist-B_UrLLw9.js} +1 -1
- package/dist/assets/dist-rfpANeiT.js +7 -0
- package/dist/assets/{download-c60BtWes.js → download-T_lOWVlB.js} +1 -1
- package/dist/assets/{face-bbox-nkg8OmFa.js → face-bbox-f3p_Yctl.js} +1 -1
- package/dist/assets/{hostInit-BpyXzSDR.js → hostInit-tEAagC07.js} +1 -1
- package/dist/assets/image-off-CxrOL9bA.js +1 -0
- package/dist/assets/index-BJkpCYtR.css +2 -0
- package/dist/assets/index-CY7HK9zV.js +4 -0
- package/dist/assets/{key-round-BlSZq_ro.js → key-round-DDU-8is6.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-3845b4a0.js → mf-entry-bootstrap-0-482a4da7.js} +2 -2
- package/dist/assets/{pencil-DUgcFYZU.js → pencil-DXM3cvvP.js} +1 -1
- package/dist/assets/{player-overlays-CzjKRHin.js → player-overlays-Ba-DoE5F.js} +1 -1
- package/dist/assets/plus-DrqAQeFJ.js +1 -0
- package/dist/assets/{radio-eY0YHItP.js → radio-DGfartpy.js} +1 -1
- package/dist/assets/{refresh-cw-D_fKxMIe.js → refresh-cw-NwlTy6_-.js} +1 -1
- package/dist/assets/remoteEntry-BzAN7Tig.js +1 -0
- package/dist/assets/{rotate-ccw-DU4_rBQq.js → rotate-ccw-DGfCNuX0.js} +1 -1
- package/dist/assets/rotate-cw-W4djelbj.js +1 -0
- package/dist/assets/search-DOYQxoHy.js +1 -0
- package/dist/assets/{send-B9r8Lohp.js → send-zoWD-FsL.js} +1 -1
- package/dist/assets/{server-BhdxNAPC.js → server-Bv5NUu2G.js} +1 -1
- package/dist/assets/square-CBtc15_U.js +1 -0
- package/dist/assets/{square-check-big-DMenPwwp.js → square-check-big-C_0qc0Ud.js} +1 -1
- package/dist/assets/{src-BBe6PrXe.js → src-CPanq9UB.js} +10 -10
- package/dist/assets/src-EmgPMReM.js +7 -0
- package/dist/assets/undo-2-B5eeo7kt.js +1 -0
- package/dist/assets/{upload-AwB-upJP.js → upload-B2QyA3Ml.js} +1 -1
- package/dist/assets/{useEventInvalidation-qhbuBjhg.js → useEventInvalidation-CQp2HDcf.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CPcVkZQ0.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BmbjlXvs.js} +2 -2
- package/dist/assets/{wifi-DyeEKGI-.js → wifi-DiUaWSk8.js} +1 -1
- package/dist/assets/{zap-C32Ix0E1.js → zap-y-GpHg-7.js} +1 -1
- package/dist/index.html +6 -6
- package/dist/server/addon.js +483 -4
- package/package.json +1 -1
- package/dist/assets/Addons-DCR8DMgD.js +0 -1
- package/dist/assets/Cluster-BnTT5Wsb.js +0 -1
- package/dist/assets/DetectionIntelligence-CzMadCA-.js +0 -1
- package/dist/assets/DeviceDetail-oWNRSfva.js +0 -2
- package/dist/assets/Events-BIZWrXMY.js +0 -1
- package/dist/assets/Identity-i_LhUVHo.js +0 -1
- package/dist/assets/IntegrationDetail-CPE4VRwU.js +0 -1
- package/dist/assets/Integrations-DhMaG2V3.js +0 -1
- package/dist/assets/Notifications-BL4Cp1b2.js +0 -1
- package/dist/assets/Pipeline-Bf8P_Drx.js +0 -1
- package/dist/assets/Plates-BkYxLI16.js +0 -1
- package/dist/assets/Recordings-OoJn-xbL.js +0 -1
- package/dist/assets/circle-check-big-DX7P42Tw.js +0 -1
- package/dist/assets/clock-DMJpZrGI.js +0 -1
- package/dist/assets/debounced-invalidate-CPxCM-Lt.js +0 -1
- package/dist/assets/dist-CekX4Hra.js +0 -7
- package/dist/assets/index-2QX2zxyn.js +0 -4
- package/dist/assets/index-BIqRUg3I.css +0 -2
- package/dist/assets/plus-C7qYd7DF.js +0 -1
- package/dist/assets/remoteEntry-CFMi51wk.js +0 -1
- package/dist/assets/rotate-cw-CktlNgLW.js +0 -1
- package/dist/assets/search-CY5Hv7Yv.js +0 -1
- package/dist/assets/square-S_5NH0Gl.js +0 -1
- package/dist/assets/src-DSZBcu6j.js +0 -7
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{B as e,Co as t,Jr as n,Mn as r,No as i,Pr as a,So as o,Wa as s,Xr as c,Zr as l,ei as u,q as d,qr as f,ti as p,to as m,xt as h,z as g}from"./src-BBe6PrXe.js";import{I as _,K as v,Q as y,S as b,W as x,b as ee,i as S,o as C,q as w,x as T,z as E}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{E as D,Q as O,T as k,z as A}from"./src-DSZBcu6j.js";import{p as j}from"./player-overlays-CzjKRHin.js";import{t as M}from"./clock-DMJpZrGI.js";import{t as N}from"./copy-oDpB_CYv.js";import{a as te,c as ne,d as re,f as P,i as F,m as I,n as ie,o as ae,p as L,r as oe,s as R,t as z}from"./debounced-invalidate-CPxCM-Lt.js";import{t as B}from"./search-CY5Hv7Yv.js";import{t as V}from"./square-check-big-DMenPwwp.js";import{t as H}from"./square-S_5NH0Gl.js";import{C as U,D as se,F as W,G,L as K,R as q,W as ce,c as le,i as ue,t as de}from"./index-2QX2zxyn.js";import{t as fe}from"./AdminPage-Dq33XE9j.js";import{r as pe,t as me}from"./authed-media-XfBD4Ma-.js";var he=G(`arrow-down-wide-narrow`,[[`path`,{d:`m3 16 4 4 4-4`,key:`1co6wj`}],[`path`,{d:`M7 20V4`,key:`1yoxec`}],[`path`,{d:`M11 4h10`,key:`1w87gc`}],[`path`,{d:`M11 8h7`,key:`djye34`}],[`path`,{d:`M11 12h4`,key:`q8tih4`}]]),ge=G(`bug`,[[`path`,{d:`m8 2 1.88 1.88`,key:`fmnt4t`}],[`path`,{d:`M14.12 3.88 16 2`,key:`qol33r`}],[`path`,{d:`M9 7.13v-1a3.003 3.003 0 1 1 6 0v1`,key:`d7y7pr`}],[`path`,{d:`M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6`,key:`xs1cw7`}],[`path`,{d:`M12 20v-9`,key:`1qisl0`}],[`path`,{d:`M6.53 9C4.6 8.8 3 7.1 3 5`,key:`32zzws`}],[`path`,{d:`M6 13H2`,key:`82j7cp`}],[`path`,{d:`M3 21c0-2.1 1.7-3.9 3.8-4`,key:`4p0ekp`}],[`path`,{d:`M20.97 5c0 2.1-1.6 3.8-3.5 4`,key:`18gb23`}],[`path`,{d:`M22 13h-4`,key:`1jl80f`}],[`path`,{d:`M17.2 17c2.1.1 3.8 1.9 3.8 4`,key:`k3fwyw`}]]),_e=G(`graduation-cap`,[[`path`,{d:`M21.42 10.922a1 1 0 0 0-.019-1.838L12.83 5.18a2 2 0 0 0-1.66 0L2.6 9.08a1 1 0 0 0 0 1.832l8.57 3.908a2 2 0 0 0 1.66 0z`,key:`j76jl0`}],[`path`,{d:`M22 10v6`,key:`1lu8f3`}],[`path`,{d:`M6 12.5V16a6 3 0 0 0 12 0v-3.5`,key:`1r8lef`}]]),ve=G(`square-parking`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 17V7h4a3 3 0 0 1 0 6H9`,key:`1dfk2c`}]]),ye=G(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]);y();var be=720*60*60*1e3;function xe(e){let t=[];for(let n of e)t.push(...n);return t}function Se(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function Ce(e,t){return e.filter(e=>!(e.importance<t.minImportance||t.cameras.size>0&&!t.cameras.has(e.deviceId)||t.classes.size>0&&!t.classes.has(e.className)))}function J(e,t){return`${String(e)}:${t}`}function we(e,t){let n=new Map,r=new Set;for(let i of e){let e=J(i.deviceId,i.trackId);if(!t.has(e)||r.has(e))continue;r.add(e);let a=n.get(i.deviceId);a?a.push(i.trackId):n.set(i.deviceId,[i.trackId])}return n}function Te(e,t){return{since:e.fromMs??t-be,until:e.toMs??t}}var Y=typeof f==`function`,Ee=`Track deletion arrives with the next server update`;function De(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Oe=Y?f:De,ke=200,Ae=3e4;function je(e){let t=j(),n=S({queries:e.deviceIds.map(n=>({queryKey:[`events-feed`,n,e.since,e.until,e.minImportance??null,e.classFilter??null],staleTime:Ae,refetchInterval:Ae,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEvents.query({deviceId:n,since:e.since,until:e.until,limit:ke,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>({...e,deviceId:n}))}))});return{rows:Se(xe(n.map(e=>e.data??[])),`importance`),isLoading:n.some(e=>e.isLoading)}}var Me=[`events-feed`],Ne=2e3;function Pe(e){let t=C(),n=e?.paused===!0,r=v(t);r.current=t;let i=v(n);i.current=n;let[a,o]=w(!1),s=_(()=>{r.current.invalidateQueries({queryKey:Me})},[]),c=v(void 0);c.current||=z({delayMs:Ne,invalidate:()=>{i.current?o(!0):s()}}),E(()=>()=>c.current?.cancel(),[]),E(()=>{n||!a||(o(!1),s())},[n,a,s]);let l=_(()=>{o(!1),s()},[s]);return m(O.PipelineAnalyticsDetectionEvent,()=>{c.current?.trigger()}),m(O.PipelineAnalyticsTrackEnded,()=>{c.current?.trigger()}),{pending:a,refreshNow:l}}y();function Fe(){return Object.values(k).filter(e=>e.level===`macro`).map(e=>({macro:e,subs:Object.values(k).filter(t=>t.parentKind===e.kind).sort((e,t)=>e.label.localeCompare(t.label))})).sort((e,t)=>e.macro.label.localeCompare(t.macro.label))}function Ie({selected:t,onChange:n}){let{t:r}=de(),[i,a]=w(!1),[o,s]=w(``),[c,l]=w(new Set),u=x(Fe,[]),d=o.trim().toLowerCase(),f=e=>d.length===0||g(e,r).toLowerCase().includes(d),p=x(()=>u.map(e=>({macro:e.macro,subs:e.subs.filter(t=>f(t)||f(e.macro))})).filter(e=>f(e.macro)||e.subs.length>0),[u,d]),m=e=>l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),h=e=>{let r=new Set(t),i=t.has(e.macro.kind)&&e.subs.every(e=>t.has(e.kind)),a=[e.macro.kind,...e.subs.map(e=>e.kind)];if(i)for(let e of a)r.delete(e);else for(let e of a)r.add(e);n(r)},_=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},v=()=>n(new Set),y=t.size;return b(`div`,{className:`relative`,children:[b(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${y>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[T(ye,{className:`h-3.5 w-3.5`}),y>0?`Kinds (${String(y)})`:`Kinds`,T(K,{className:`h-3 w-3`})]}),i&&b(`div`,{className:`absolute z-20 mt-1 max-h-80 w-64 overflow-auto rounded-md border border-border bg-surface p-2 shadow-lg`,children:[b(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[T(B,{className:`h-3.5 w-3.5 text-foreground-subtle`}),T(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`Search kinds…`,className:`w-full bg-transparent py-1 text-xs outline-none`}),y>0&&T(`button`,{type:`button`,onClick:v,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),p.map(n=>{let i=e(n.macro.iconId),a=c.has(n.macro.kind)||d.length>0,o=t.has(n.macro.kind);return b(`div`,{className:`mb-0.5`,children:[b(`div`,{className:`flex items-center gap-1`,children:[n.subs.length>0?T(`button`,{type:`button`,onClick:()=>m(n.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:T(a?K:W,{className:`h-3 w-3`})}):T(`span`,{className:`w-3`}),b(`label`,{className:`flex flex-1 cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[T(`input`,{type:`checkbox`,checked:o,onChange:()=>h(n),className:`accent-primary`}),T(i,{className:`h-3.5 w-3.5`,style:{color:n.macro.color}}),T(`span`,{className:`font-medium`,children:g(n.macro,r)})]})]}),a&&n.subs.map(n=>{let i=e(n.iconId);return b(`label`,{className:`ml-5 flex cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[T(`input`,{type:`checkbox`,checked:t.has(n.kind),onChange:()=>_(n.kind),className:`accent-primary`}),T(i,{className:`h-3.5 w-3.5`,style:{color:n.color}}),T(`span`,{children:g(n,r)})]},n.kind)})]},n.macro.kind)})]})]})}var X=100,Le=120,Re={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Z=e=>e<0?0:e>1?1:e,Q=e=>Math.round(e*100)/100;function ze(e,t){if(e.length<=t)return[...e];let n=(e.length-1)/(t-1),r=[];for(let i=0;i<t;i++)r.push(e[Math.round(i*n)]);return r[r.length-1]=e[e.length-1],r}function Be(e,t,n){if(e.length===0||t===null)return Re;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return Re;let a=ze(e,n?.maxPoints??Le).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X)})),o=a[0]??null,s=a[a.length-1]??null,c=a.length>=2?a.map(e=>`${e.x},${e.y}`).join(` `):``,l=(n?.snapshots??[]).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X),mediaKey:e.mediaKey})),u=null,d=-1;for(let t of e){let e=Z(t.bbox.w/r)*Z(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Q(Z(u.bbox.x/r)*X),y:Q(Z(u.bbox.y/i)*X),w:Q(Z(u.bbox.w/r)*X),h:Q(Z(u.bbox.h/i)*X)}:null}}var Ve=typeof p==`function`,He=`Track flags arrive with the next server update`;function Ue(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var We=Ve?p:Ue;function Ge(e){if(typeof e!=`object`||!e||!(`trackId`in e)||!(`markForTrain`in e)||!(`debug`in e))return null;let{trackId:t,markForTrain:n,debug:r}=e;return typeof t!=`string`||typeof n!=`boolean`||typeof r!=`boolean`?null:{trackId:t,markForTrain:n,debug:r}}y();function Ke({label:e,hint:t,checked:n,disabled:r,title:i,icon:a,onToggle:o}){return b(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":e,disabled:r,title:i,onClick:o,className:`flex w-full items-center gap-2 rounded-md border px-2 py-1.5 text-left transition-colors disabled:opacity-50 ${n?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[T(`span`,{className:n?`text-primary`:`text-foreground-subtle`,children:a}),b(`span`,{className:`min-w-0 flex-1`,children:[T(`span`,{className:`block text-[11px] font-medium text-foreground`,children:e}),T(`span`,{className:`block text-[10px] text-foreground-subtle`,children:t})]}),T(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${n?`bg-primary`:`bg-border`}`,children:T(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${n?`translate-x-3`:``}`})})]})}function qe({deviceId:e,trackId:t,markForTrain:n,debug:r,onChange:i}){let a=We(),[o,s]=w(null),c=o?.markForTrain??n===!0,l=o?.debug??r===!0,u=!Ve||a.isPending,d=Ve?void 0:He,f=n=>{u||(async()=>{try{let r=Ge(await a.mutateAsync({deviceId:e,trackId:t,flags:n}));if(!r)return;s(r),i?.(r)}catch(e){let t=e instanceof Error?e.message:``;window.alert(t===``?`Could not update this track. Check the server logs.`:`Could not update this track — ${t}`)}})()};return b(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[T(Ke,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:c,disabled:u,...d===void 0?{}:{title:d},icon:T(_e,{className:`h-4 w-4`}),onToggle:()=>f({markForTrain:!c})}),T(Ke,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:l,disabled:u,...d===void 0?{}:{title:d},icon:T(ge,{className:`h-4 w-4`}),onToggle:()=>f({debug:!l})})]})}var Je={firstFrame:`First frame (track start)`,lastFrame:`Last frame (track end)`,thumbnail:`Best detection`,thumbnailSmall:`Best detection (480)`,snapshot:`Snapshot`,keyFrame:`Key frame (native-res)`,keyFrameSmall:`Key frame (960)`,crop:`Object crop`,fullFrame:`Full frame`,fullFrameBoxed:`Full frame (boxed)`,faceCrop:`Face crop`,plateCrop:`Plate crop`};function Ye(e){return e in Je}function Xe(e){return Ye(e)?Je[e]:e}function Ze(e,t){return`${e}${me}/${encodeURIComponent(t)}`}y();var Qe=1400,$e=`Admin-gated URL — opens only inside an authenticated session`;function et({label:e,value:t,title:n}){let[r,i]=w(!1);return E(()=>{if(!r)return;let e=setTimeout(()=>i(!1),Qe);return()=>clearTimeout(e)},[r]),b(`button`,{type:`button`,onClick:_(()=>{(async()=>{try{await navigator.clipboard.writeText(t),i(!0)}catch{window.prompt(`Copy the media URL:`,t)}})()},[t]),title:n,"aria-label":`Copy ${e} URL`,className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${r?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[T(r?q:N,{className:`h-2.5 w-2.5 shrink-0`}),T(`span`,{className:`truncate`,children:r?`Copied`:e})]})}function tt({localUrl:e,publicUrl:t}){return b(`div`,{className:`flex flex-wrap gap-1`,children:[T(et,{label:`Local`,value:e,title:`Copy LAN URL — ${$e}`}),t&&T(et,{label:`Public`,value:t,title:`Copy public URL — ${$e}`})]})}y();var nt=3e4;function rt(e){let[t,n]=w(null),r=_(e=>{n(t=>t??e)},[]);return E(()=>{e||n(null)},[e]),{publicOrigin:t,probes:e?T(it,{onOrigin:r}):null}}function it({onOrigin:e}){let{data:t}=h({capName:`network-access`});return T(ee,{children:(t??[]).map(t=>T(at,{addonId:t.addonId,onOrigin:e},t.addonId))})}function at({addonId:e,onOrigin:t}){let{data:n}=a({addonId:e},{refetchInterval:nt,retry:!1});return E(()=>{let e=n?D.safeParse(n):null,r=e?.success?e.data.endpoint?.url:void 0;if(r)try{t(new URL(r).origin)}catch{}},[n,t]),null}y();var ot=15e3,st=window.location.origin,ct=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),lt=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]);function ut(e){let[t,n]=w(null);return E(()=>{if(n(null),!e)return;let t=!1,r=new Image;return r.onload=()=>{t||n({width:r.naturalWidth,height:r.naturalHeight})},r.src=e,()=>{t=!0,r.onload=null}},[e]),t}function dt({overlay:e,onPickSnapshot:t}){return!e.polyline&&!e.peakBox&&e.snapshots.length===0?null:b(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[e.peakBox&&T(`rect`,{x:e.peakBox.x,y:e.peakBox.y,width:e.peakBox.w,height:e.peakBox.h,fill:`none`,stroke:`#f59e0b`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),e.polyline&&T(`polyline`,{points:e.polyline,fill:`none`,stroke:`#38bdf8`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),e.points.map((e,t)=>T(`circle`,{cx:e.x,cy:e.y,r:1,fill:`#38bdf8`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),e.snapshots.map((e,n)=>T(`circle`,{cx:e.x,cy:e.y,r:1.9,fill:`#0ea5e9`,fillOpacity:.95,stroke:`#082f49`,strokeWidth:.7,vectorEffect:`non-scaling-stroke`,className:t?`pointer-events-auto cursor-pointer`:void 0,onClick:t?n=>{n.stopPropagation(),t(e.mediaKey)}:void 0,children:T(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${e.mediaKey}-${String(n)}`)),e.start&&T(`circle`,{cx:e.start.x,cy:e.start.y,r:2.4,fill:`#22c55e`,stroke:`#052e16`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),e.end&&T(`circle`,{cx:e.end.x,cy:e.end.y,r:2.4,fill:`#ef4444`,stroke:`#450a0a`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function $({label:e,value:t,mono:n}){return b(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[T(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),T(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function ft({row:e,cameraName:r,deleteAvailable:a,onClose:u,onDeleted:d,onFlagsChanged:f}){let p=j(),m=Oe(),h=e!==null,g=e?.deviceId??0,v=e?.trackId??``,y=e?.bestEventId??``,S=e?.timestamp??0,C=e?.windowMs??0,{data:D}=c({deviceId:g,trackId:v},{enabled:h}),{data:O}=l({trackId:v},{enabled:h}),{data:k}=n({eventId:y},{enabled:h&&y!==``}),{data:A}=s({deviceId:g,since:S-ot,until:S+C+ot},{enabled:h}),[M,N]=w(null),[te,ne]=w(!1),{publicOrigin:P,probes:ie}=rt(h);E(()=>{N(null)},[g,v]);let ae=x(()=>{let e=O??[],t=k??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[O,k]),oe=pe(ae?`${me}/${encodeURIComponent(ae.key)}`:void 0),R=x(()=>{let e=new Set,t=[];for(let n of[...k??[],...O??[]])!n.base64||e.has(n.key)||(e.add(n.key),t.push(n));return t},[k,O]),z=x(()=>R.find(e=>ct.has(e.kind))??null,[R]),B=ut(z?`data:image/jpeg;base64,${z.base64}`:null),V=x(()=>Be(D?.positions??[],B,{snapshots:(D?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaKey:e.mediaKey}))}),[D?.positions,D?.snapshots,B]),H=_(e=>{let t=R.find(t=>t.key===e);t&&N(t)},[R]);if(e===null)return null;let W=M?`data:image/jpeg;base64,${M.base64}`:oe.src,G=M?.kind??ae?.kind,K=G!==void 0&<.has(G)&&B!==null&&(D?.positions.length??0)>=2,q=A&&A.length>0?A[0]:null,ce=()=>{q&&(ne(!0),(async()=>{try{let t=await p.trpcClient.videoclips.getClipPlayback.query({deviceId:e.deviceId,clipId:q.id});window.open(t.playbackUrl,`_blank`,`noopener`)}catch{window.alert(`Could not resolve clip playback. Check the server logs.`)}finally{ne(!1)}})())},de=()=>{!a||m.isPending||window.confirm(`Delete this track and all its media? This cannot be undone.`)&&(async()=>{try{await m.mutateAsync({deviceId:e.deviceId,trackIds:[e.trackId]}),d()}catch{window.alert(`Failed to delete this track. Check the server logs.`)}})()},fe=Math.round(e.importance*100),he=D?.importanceReason?`${String(fe)}% · ${D.importanceReason}`:`${String(fe)}%`,ge=D?.zonesVisited&&D.zonesVisited.length>0?D.zonesVisited.join(`, `):`—`,_e=D?.audioLabels&&D.audioLabels.length>0?D.audioLabels.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `):`—`,ve=D?D.totalDistance.toFixed(2):`—`,ye=L(D?D.firstSeen:S),be=D?L(D.lastSeen):`—`;return T(o,{open:!0,onOpenChange:e=>!e&&u(),children:b(t,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Event detail`,className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[b(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[b(`div`,{className:`min-w-0`,children:[b(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[e.className,e.label?b(`span`,{className:`text-foreground-subtle`,children:[` · `,e.label]}):null]}),T(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:r})]}),T(`button`,{type:`button`,onClick:u,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:T(ue,{className:`h-4 w-4`})})]}),b(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[W?T(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:T(F,{src:W,alt:`Key frame from ${r}`,fit:`natural`,className:`w-full`,overlay:K?T(dt,{overlay:V,onPickSnapshot:H}):void 0})}):T(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:oe.failed?b(ee,{children:[T(I,{className:`h-8 w-8 opacity-60`}),T(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):T(U,{className:`h-6 w-6 animate-spin opacity-70`})}),R.length>0&&T(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:R.map(e=>{let t=`data:image/jpeg;base64,${e.base64}`,n=Xe(e.kind),r=Ze(st,e.key),i=P?Ze(P,e.key):null;return b(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[T(`button`,{type:`button`,onClick:()=>N(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${n} · ${L(e.timestamp)}`,children:T(`img`,{src:t,alt:n,className:`h-full w-full object-cover`})}),b(`figcaption`,{className:`min-w-0 px-0.5`,children:[T(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:n,children:n}),T(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:L(e.timestamp),children:re(e.timestamp)})]}),T(tt,{localUrl:r,publicUrl:i})]},e.key)})}),ie,q&&b(i,{variant:`secondary`,onClick:ce,disabled:te,children:[te?T(U,{className:`h-3.5 w-3.5 animate-spin`}):T(se,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),T(qe,{deviceId:e.deviceId,trackId:e.trackId,...(D?.markForTrain??e.markForTrain)===void 0?{}:{markForTrain:D?.markForTrain??e.markForTrain},...(D?.debug??e.debug)===void 0?{}:{debug:D?.debug??e.debug},onChange:f}),b(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[T($,{label:`Camera`,value:r}),T($,{label:`Class`,value:e.className}),T($,{label:`Label`,value:e.label??`—`}),T($,{label:`Importance`,value:he}),T($,{label:`Zones visited`,value:ge}),T($,{label:`Audio heard`,value:_e}),T($,{label:`Total distance`,value:ve}),T($,{label:`First seen`,value:ye}),T($,{label:`Last seen`,value:be}),T($,{label:`Track`,value:e.trackId,mono:!0})]})]}),T(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:T(`span`,{title:a?void 0:Ee,children:b(i,{variant:`secondary`,onClick:de,disabled:!a||m.isPending,children:[m.isPending?T(U,{className:`h-3.5 w-3.5 animate-spin`}):T(le,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}function pt(e){if(e===void 0||!Number.isFinite(e)||e<=0)return``;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`${String(n)}m ${String(r).padStart(2,`0`)}s`}function mt({row:e,cameraName:t,nowMs:n,onOpenDetail:r,selected:i=!1,onToggleSelect:a,score:o}){let s=pe(e.bestEventId?`${me}/${e.bestEventId}`:void 0),c=Math.round(e.importance*100),l=o===void 0?void 0:Math.round(o*100),u=pt(e.windowMs),d=()=>r(e);return b(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[b(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[s.src?T(`img`,{src:s.src,alt:`Event from ${t}`,onClick:d,className:`h-full w-full cursor-zoom-in object-cover`}):T(`button`,{type:`button`,onClick:d,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:s.failed?`Key-event media unavailable`:`No key-event media`,children:T(I,{className:`h-6 w-6 opacity-60`})}),a&&T(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(J(e.deviceId,e.trackId))},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Deselect`:`Select`,children:i?T(V,{className:`h-4 w-4 text-primary`}):T(H,{className:`h-4 w-4`})}),l!==void 0&&b(`span`,{className:`absolute left-1 top-1 z-10 rounded bg-primary/85 px-1.5 py-0.5 text-[10px] font-semibold text-white tabular-nums`,title:`CLIP semantic-match score`,children:[String(l),`%`]}),c>0&&T(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(c)}),(e.markForTrain===!0||e.debug===!0)&&b(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[e.markForTrain===!0&&T(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Marked for training`,"aria-label":`Marked for training`,children:T(_e,{className:`h-3 w-3`})}),e.debug===!0&&T(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:`Flagged for debug`,"aria-label":`Flagged for debug`,children:T(ge,{className:`h-3 w-3`})})]})]}),b(`button`,{type:`button`,onClick:d,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[b(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,e.label?b(`span`,{className:`text-foreground-subtle`,children:[` · `,e.label]}):null]}),T(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),b(`div`,{className:`flex items-center justify-between gap-2`,children:[T(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:P(e.timestamp,n)}),u&&T(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:u})]})]})]})}y();function ht(){let[e,t]=w(!1),n=v(null),[r,i]=w(0),a=_(e=>{n.current!==e&&(n.current=e,i(e=>e+1))},[]);return E(()=>{let e=n.current;if(!e||typeof IntersectionObserver>`u`){t(!1);return}let r=new IntersectionObserver(e=>{let n=e[e.length-1];n&&t(!n.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return r.observe(e),()=>r.disconnect()},[r]),{ref:a,scrolledPast:e}}y();var gt=[`events-feed`],_t=60,vt=[{value:`importance`,label:`Importance`,icon:he},{value:`time`,label:`Recent`,icon:M}];function yt(){let e=C(),[t,n]=w(R),[a,o]=w(new Set),[s,c]=w(new Set),[l,u]=w(0),[d,f]=w(`time`),[p,m]=w(new Set),[h,g]=w(null),[_,v]=w(()=>Date.now());E(()=>{let e=setInterval(()=>v(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:y,until:S}=x(()=>Te({fromMs:t.fromMs,toMs:t.toMs},_),[t.fromMs,t.toMs,_]),D=ht(),{pending:O,refreshNow:k}=Pe({paused:h!==null||p.size>0||D.scrolledPast}),{data:j}=r({}),M=x(()=>(j??[]).filter(e=>e.type===A.Camera),[j]),N=x(()=>M.map(e=>e.id),[M]),re=Oe(),P=re.isPending,{rows:F,isLoading:I}=je({deviceIds:N,since:y,until:S,minImportance:l>0?l:void 0,classFilter:s.size===1?[...s][0]:void 0}),L=x(()=>{let e=new Map;for(let t of M??[])e.set(t.id,t.name);return e},[M]),z=e=>L.get(e)??`Camera #${String(e)}`,B=x(()=>ne(F).map(e=>({id:e,name:z(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[F,L]),V=x(()=>Se(Ce(F,{cameras:a,classes:s,minImportance:l}),d),[F,a,s,l,d]),H=ie(V,_t,x(()=>JSON.stringify([[...a].sort((e,t)=>e-t),[...s].sort(),l,d,y,S]),[a,s,l,d,y,S])),se=()=>{e.invalidateQueries({queryKey:gt})},W=()=>m(new Set);function G(e){m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function K(){if(p.size===0||!Y)return;let e=we(F,p),t=[...e.values()].reduce((e,t)=>e+t.length,0);if(t===0||!window.confirm(`Delete ${String(t)} track${t===1?``:`s`} and all their media? This cannot be undone.`))return;let n=[...e];Promise.allSettled(n.map(([e,t])=>re.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{se();let t=[],r=new Set;if(e.forEach((e,i)=>{let a=n[i];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)r.add(J(o,e));else t.push(o)}),m(e=>{let t=new Set(e);for(let e of r)t.delete(e);return t}),t.length>0){let e=t.map(e=>z(e)).join(`, `);window.alert(`Failed to delete tracks on: ${e}. They remain selected — retry, or check the server logs.`)}})}let q=V.length!==F.length;return b(`div`,{className:`relative space-y-3`,children:[b(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[T(te,{onChange:n}),T(ae,{cameras:B,selected:a,onChange:o}),T(Ie,{selected:s,onChange:c}),b(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[T(`span`,{children:`Min score`}),T(`input`,{type:`range`,min:0,max:1,step:.05,value:l,onChange:e=>u(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":`Minimum importance`}),T(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(l*100)})]}),T(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:vt.map(e=>{let t=e.icon;return b(`button`,{type:`button`,onClick:()=>f(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${d===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[T(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!I&&T(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:q?`${String(V.length)} of ${String(F.length)} events`:`${String(V.length)} event${V.length===1?``:`s`}`})]}),p.size>0&&b(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[b(`span`,{className:`text-xs font-medium text-foreground`,children:[p.size,` selected`]}),b(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[T(`span`,{title:Y?void 0:`Track deletion arrives with the next server update`,children:b(i,{variant:`secondary`,onClick:K,disabled:!Y||P,children:[P?T(U,{className:`h-3.5 w-3.5 animate-spin`}):T(le,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),T(i,{variant:`ghost`,onClick:W,disabled:P,children:T(ue,{className:`h-3.5 w-3.5`})})]})]}),I&&b(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[T(U,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!I&&V.length===0&&T(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),O&&T(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:T(`button`,{type:`button`,onClick:k,className:`rounded-full border border-primary/40 bg-surface px-3 py-1 text-[11px] font-medium text-primary shadow-sm hover:bg-primary/10`,children:`New events — refresh`})}),!I&&V.length>0&&b(ee,{children:[T(`div`,{ref:D.ref,"aria-hidden":!0,className:`h-0`}),T(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:H.pageItems.map(e=>T(mt,{row:e,cameraName:z(e.deviceId),nowMs:_,selected:p.has(J(e.deviceId,e.trackId)),onToggleSelect:G,onOpenDetail:g},J(e.deviceId,e.trackId)))}),T(oe,{currentPage:H.page,totalItems:H.totalItems,pageSize:H.pageSize,onPageChange:H.setPage,itemNoun:`events`})]}),h&&T(ft,{row:h,cameraName:z(h.deviceId),deleteAvailable:Y,onClose:()=>g(null),onDeleted:()=>{se(),g(null)},onFlagsChanged:e=>{g(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug}:t)}})]})}y();var bt=50,xt=350,St=[`person`,`vehicle`,`animal`],Ct=[{value:.2,label:`Loose`},{value:.25,label:`Balanced`},{value:.3,label:`Strict`}];function wt(e){return{id:e.id,trackId:e.trackId??e.id,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,importance:e.importance??0,bestEventId:e.mediaKey??e.trackId??e.id,windowMs:void 0}}function Tt({onActiveChange:e}){let[t,n]=w(``),[i,a]=w(.2),[o,s]=w(null),[c,l]=w(null),[f,p]=w(null),m=d(t,xt).trim(),h=m.length>0;E(()=>{e(h)},[h,e]);let[g,_]=w(()=>Date.now());E(()=>{let e=setInterval(()=>_(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:v}=r({}),y=x(()=>(v??[]).filter(e=>e.type===A.Camera),[v]),ee=x(()=>{let e=new Map;for(let t of v??[])e.set(t.id,t.name);return e},[v]),S=e=>ee.get(e)??`Camera #${String(e)}`,{data:C,isFetching:D,isError:O,error:k}=u({text:m,minScore:i,limit:bt,classFilter:o??void 0,deviceId:c??void 0},{enabled:h}),j=x(()=>[...C??[]].sort((e,t)=>t.score-e.score).map(e=>({...wt(e),score:e.score})),[C]);function M(e){s(t=>t===e?null:e)}return b(`div`,{className:`space-y-3`,children:[b(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[b(`div`,{className:`flex flex-wrap items-center gap-2`,children:[b(`div`,{className:`relative min-w-[16rem] flex-1`,children:[T(B,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),T(`input`,{type:`text`,value:t,onChange:e=>n(e.target.value),placeholder:`Semantic search — describe what you're looking for…`,className:`h-9 w-full rounded-md border border-border bg-background pl-8 pr-8 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":`Semantic event search`}),t&&T(`button`,{type:`button`,onClick:()=>n(``),className:`absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Clear search`,children:T(ue,{className:`h-3.5 w-3.5`})})]}),D&&h&&T(U,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),b(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[T(`div`,{className:`flex items-center gap-1`,children:St.map(e=>T(`button`,{type:`button`,onClick:()=>M(e),className:`rounded-md px-2.5 py-1 text-xs capitalize transition-colors ${o===e?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e},e))}),b(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[T(`span`,{children:`Camera`}),b(`select`,{value:c===null?``:String(c),onChange:e=>l(e.target.value===``?null:Number(e.target.value)),className:`h-7 rounded-md border border-border bg-background px-1.5 text-xs text-foreground focus:border-primary focus:outline-none`,"aria-label":`Filter by camera`,children:[T(`option`,{value:``,children:`All`}),y.map(e=>T(`option`,{value:String(e.id),children:e.name},e.id))]})]}),b(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[T(`span`,{children:`Match`}),T(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Ct.map(e=>T(`button`,{type:`button`,onClick:()=>a(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:`Minimum CLIP score ${e.value.toFixed(2)}`,children:e.label},e.value))})]}),h&&!D&&!O&&b(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[j.length,` match`,j.length===1?``:`es`]})]})]}),h&&b(`div`,{className:`space-y-3`,children:[O&&b(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,k instanceof Error?k.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!O&&D&&j.length===0&&b(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[T(U,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!O&&!D&&j.length===0&&b(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:[`No semantic matches for “`,m,`”. Try a looser match threshold or a different phrasing.`]}),!O&&j.length>0&&T(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:j.map(e=>T(mt,{row:e,cameraName:S(e.deviceId),nowMs:g,score:e.score,onOpenDetail:p},e.id))})]}),f&&T(ft,{row:f,cameraName:S(f.deviceId),deleteAvailable:Y,onClose:()=>p(null),onDeleted:()=>p(null)})]})}var Et=15e3;function Dt(e){let t=j(),n=S({queries:e.map(e=>({queryKey:[`stationary-objects`,e],staleTime:Et,refetchInterval:Et,queryFn:async()=>((await t.trpcClient.zoneAnalytics.getCurrentSnapshot.query({deviceId:e}))?.stationaryObjects??[]).map(t=>({...t,deviceId:e}))}))});return{rows:n.flatMap(e=>e.data??[]).toSorted((e,t)=>t.becameStationaryAt-e.becameStationaryAt),isLoading:n.some(e=>e.isLoading)}}y();function Ot(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return`just now`;if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function kt({row:e,cameraName:t,nowMs:n}){let r=e.keyFrameMediaKey?.startsWith(`track:`)?e.keyFrameMediaKey.split(`:`)[1]:e.keyFrameMediaKey,i=pe(r?`${me}/${r}`:void 0);return b(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[b(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[i.src?T(`img`,{src:i.src,alt:`Parked ${e.className} on ${t}`,className:`h-full w-full object-cover`}):T(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:T(ve,{className:`h-6 w-6`})}),T(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:e.label??e.className})]}),b(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[T(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),b(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,Ot(n,e.becameStationaryAt)]})]})]})}function At(){let[e,t]=w(!1),n=Date.now(),{data:i}=r({}),a=x(()=>(i??[]).filter(e=>e.type===A.Camera),[i]),o=x(()=>a.map(e=>e.id),[a]),s=x(()=>{let e=new Map;for(let t of a)e.set(t.id,t.name);return e},[a]),{rows:c}=Dt(o);return c.length===0?null:b(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[b(`button`,{type:`button`,onClick:()=>t(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[T(e?K:W,{className:`h-4 w-4 text-foreground-subtle`}),T(ve,{className:`h-4 w-4 text-foreground-subtle`}),T(`span`,{className:`text-sm font-semibold text-foreground`,children:`Stationary`}),T(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:c.length}),T(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:`Parked objects — kept out of the event feed`})]}),e&&T(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:c.map(e=>T(kt,{row:e,cameraName:s.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}y();function jt(){let[e,t]=w(!1);return T(fe,{icon:ce,title:`Events`,subtitle:`Every captured key event across all cameras — trajectory, media, and clips.`,children:b(`section`,{className:`space-y-3`,children:[T(Tt,{onActiveChange:t}),!e&&T(At,{}),!e&&T(yt,{})]})})}export{jt as EventsPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Aa as e,Ba as t,Fa as n,Ha as r,Ia as i,Ja as a,La as o,Ma as s,Na as c,No as l,Pa as u,Ra as d,Ua as f,Va as p,bt as m,c as h,ja as g,ka as _,lo as v,s as y,xt as b,za as x}from"./src-BBe6PrXe.js";import{Q as S,S as C,W as w,b as T,o as E,q as D,x as O}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 k}from"./circle-check-big-DX7P42Tw.js";import{t as A}from"./copy-oDpB_CYv.js";import{t as j}from"./key-round-BlSZq_ro.js";import{t as M}from"./AddonCollectionPage-B5t3SHZE.js";import{t as ee}from"./plus-C7qYd7DF.js";import{C as N,E as P,G as F,R as I,T as L,c as R,d as z,i as B,p as V,r as H}from"./index-2QX2zxyn.js";import{t as U}from"./AdminPage-Dq33XE9j.js";import{t as W}from"./AdminTabs-DTECFIAe.js";import{t as G}from"./addon-display-names-DvSEQty-.js";var te=F(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),ne=F(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]),re=F(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),K=F(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]),ie=F(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]);S();function ae({userId:e,username:t,onClose:n}){let r=E(),i=a(),o=c({userId:e}),u=o.data,d=()=>r.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),f=s({onSuccess:()=>{d(),n()}}),p=o.isLoading?`loading`:u?.enabled?`enrolled`:`not_enrolled`;return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[C(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[C(`div`,{className:`flex items-center gap-2`,children:[O(z,{className:`h-4 w-4 text-primary`}),C(`div`,{children:[O(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),C(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,O(`span`,{className:`font-mono`,children:t})]})]})]}),O(`button`,{onClick:n,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:O(B,{className:`h-4 w-4`})})]}),C(`div`,{className:`p-4 space-y-4`,children:[p===`loading`&&C(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[O(N,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),p===`not_enrolled`&&C(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[O(L,{className:`h-4 w-4 mt-0.5 shrink-0`}),C(`div`,{children:[O(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),O(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),p===`enrolled`&&u&&C(T,{children:[C(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[O(k,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),C(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[O(`div`,{className:`font-medium`,children:`2FA is active`}),C(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,u.confirmedAt?new Date(u.confirmedAt).toLocaleString():`—`]})]})]}),O(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),C(`div`,{className:`flex justify-end gap-2`,children:[O(l,{onClick:n,variant:`secondary`,children:`Close`}),C(`button`,{onClick:async()=>{await i({title:`Remove 2FA`,message:`Remove two-factor authentication for "${t}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&f.mutate({userId:e})},disabled:f.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[f.isPending?O(N,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function oe(){let t=E(),{user:n}=H(),[i,s]=D(!1),[c,l]=D(``),[u,p]=D(``),[m,h]=D(!1),[_,y]=D(null),{data:b,isLoading:x,isError:S}=o(),w=a(),T=()=>t.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),k=e({onSuccess:()=>{T(),s(!1),l(``),p(``),h(!1),y(null)},onError:e=>{y(e instanceof Error?e.message:`Failed to create user`)}}),A=g({onSuccess:T}),j=f({onSuccess:T}),M=d({onSuccess:T}),P=r({onSuccess:()=>{T(),I(null)}}),[F,I]=D(null),[L,W]=D(null),G=b??[];async function te(e){await w({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&A.mutate({id:e.id})}async function ne(e){let t=window.prompt(`New password for "${e.username}":`);if(t){if(t.length<8){window.alert(`Password must be at least 8 characters.`);return}await w({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&M.mutate({id:e.id,newPassword:t})}}function K(e,t){t!==e.isAdmin&&j.mutate({id:e.id,isAdmin:t})}function ie(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return C(U,{children:[O(`div`,{className:`flex items-center justify-end`,children:C(`button`,{onClick:()=>s(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm hover:bg-primary/90`,children:[O(ee,{className:`h-3.5 w-3.5`}),`Create User`]})}),i&&C(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[C(`div`,{className:`flex items-center justify-between`,children:[O(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),O(`button`,{onClick:()=>s(!1),className:`text-foreground-subtle hover:text-foreground`,children:O(B,{className:`h-4 w-4`})})]}),C(`div`,{className:`grid grid-cols-3 gap-3`,children:[C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),O(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`john`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),O(`input`,{type:`password`,value:u,onChange:e=>p(e.target.value),placeholder:`••••••••`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),C(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[O(`input`,{type:`checkbox`,checked:m,onChange:e=>h(e.target.checked),className:`rounded border-border focus:ring-primary`}),O(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),_&&O(`p`,{className:`text-[10px] text-danger`,children:_}),C(`div`,{className:`flex justify-end gap-2`,children:[O(`button`,{onClick:()=>s(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),O(`button`,{onClick:()=>k.mutate({username:c,password:u,isAdmin:m}),disabled:k.isPending||!c||!u,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:k.isPending?`Creating...`:`Create`})]})]}),x&&O(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),S&&O(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!x&&!S&&G.length===0&&O(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>A.isPending&&A.variables?.id===e.id||j.isPending&&j.variables?.id===e.id||M.isPending&&M.variables?.id===e.id;return O(v,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:t=>C(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[O(`input`,{type:`checkbox`,checked:t.isAdmin,onChange:e=>K(t,e.target.checked),disabled:e(t),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),O(`span`,{className:t.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:t.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Scopes`,render:e=>{if(e.isAdmin)return O(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`unscoped`});let t=e.scopes??[];return C(`button`,{onClick:()=>I(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground`,title:`Edit scope grants`,children:[O(V,{className:`h-3 w-3`}),t.length===0?`no access`:`${t.length} grant${t.length===1?``:`s`}`]})}},{key:`createdAt`,header:`Created`,render:e=>O(`span`,{className:`text-foreground-subtle`,children:ie(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:t=>{let r=e(t);return C(`div`,{className:`flex items-center justify-end gap-1`,children:[t.id!==n?.id&&t.totpEnabled&&C(`button`,{onClick:()=>W(t),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[O(z,{className:`h-3 w-3`}),`Remove 2FA`]}),C(`button`,{onClick:()=>ne(t),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[O(re,{className:`h-3 w-3`}),`Reset password`]}),C(`button`,{onClick:()=>te(t),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete user`,children:[r?O(N,{className:`h-3 w-3 animate-spin`}):O(R,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:G,rowKey:e=>e.id,minWidthPx:560})})(),L&&O(ae,{userId:L.id,username:L.username,onClose:()=>W(null)}),F&&O(se,{user:F,onClose:()=>I(null),onSubmit:e=>P.mutate({userId:F.id,scopes:e}),submitting:P.isPending})]})}function se(e){let{user:t}=H(),n=t?.isAdmin===!0;return O(ce,{...e,callerScopes:n?null:t?.scopes??[]})}function ce({user:e,onClose:t,onSubmit:n,submitting:r,callerScopes:i}){let[a,o]=D(w(()=>(e.scopes??[]).map(e=>({...e,access:[...e.access]})),[e.scopes])),s=h(a);return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,children:C(`div`,{className:`w-full max-w-2xl rounded-lg border border-border bg-surface shadow-xl`,children:[C(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-3`,children:[C(`div`,{children:[C(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Edit scopes — `,e.username]}),O(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`Admin users bypass the scope check; this list is ignored.`:`Pick which capabilities this user can call, and which access flavours within each.`})]}),O(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:O(B,{className:`h-4 w-4`})})]}),C(`div`,{className:`px-4 py-4`,children:[O(y,{value:a,onChange:o,clampToParent:i,emptyHint:C(T,{children:[`No scopes granted.`,` `,O(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until a scope is added.`]})}),s&&O(`p`,{className:`mt-2 text-[10px] text-danger`,children:s})]}),C(`div`,{className:`flex items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[O(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),O(`button`,{onClick:()=>n(a),disabled:r||s!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:r?O(N,{className:`h-3 w-3 animate-spin`}):`Save scopes`})]})]})})}S();var le=`bg-primary/10 text-primary`,ue=`bg-foreground-subtle/10 text-foreground-subtle`;function q(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function de(e){return e?e===`*`?`*`:e.join(`, `):``}function fe(){let e=E(),t=a(),{data:n,isLoading:r}=u(),{data:i}=o(),s=w(()=>n??[],[n]),c=w(()=>i??[],[i]),l=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),d=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[f,m]=D(!1),[h,g]=D(null),v=x({onSuccess:l}),y=_({onSuccess:({token:e,record:t})=>{d(),m(!1),g({token:e,label:t.name})}}),b=p({onSuccess:d}),S=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&v.mutate({id:e})},T=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&b.mutate({id:e})};return C(U,{children:[C(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[O(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius.`}),C(`button`,{onClick:()=>m(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,disabled:c.length===0,title:c.length===0?`Create a user first`:`Issue a scoped token`,children:[O(V,{className:`h-3.5 w-3.5`}),`New token`]})]}),C(J,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[c.length===0&&O(me,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),c.map(e=>O(ge,{userId:e.id,username:e.username,onRevoke:(e,t)=>{T(e,t)},revokePending:b.isPending,revokeId:b.variables?.id},e.id))]}),s.length>0&&O(J,{title:`Legacy API keys`,subtitle:`${s.length} pre-existing — revoke only`,children:O(he,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:s.map(e=>{let t=!!e.isAdmin,n=v.isPending&&v.variables?.id===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${t?le:ue}`,children:t?`admin`:`regular`})}),C(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:de(e.allowedProviders)||`all`}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:C(`button`,{onClick:()=>{S(e.id,e.label)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?O(N,{className:`h-3 w-3 animate-spin`}):O(R,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),r&&O(pe,{}),f&&O(_e,{users:c.map(e=>({id:e.id,username:e.username})),onClose:()=>m(!1),onSubmit:e=>y.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:y.isPending}),h&&O(ve,{token:h.token,label:h.label,onClose:()=>g(null)})]})}function J({title:e,subtitle:t,children:n}){return C(`div`,{className:`space-y-2`,children:[C(`div`,{className:`flex items-baseline justify-between`,children:[O(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&O(`span`,{className:`text-[10px] text-foreground-subtle`,children:t})]}),n]})}function pe(){return O(`div`,{className:`space-y-2`,children:[1,2].map(e=>O(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function me({text:e}){return O(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function he({headers:e,rows:t}){return O(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[640px]`,children:[O(`thead`,{children:O(`tr`,{children:e.map((t,n)=>O(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),O(`tbody`,{children:t})]})})}function ge({userId:e,username:t,onRevoke:n,revokePending:r,revokeId:a}){let{data:o,isLoading:s}=i({userId:e}),c=o??[];return s||c.length===0?null:C(`div`,{className:`space-y-1.5`,children:[O(`div`,{className:`text-[11px] font-medium text-foreground`,children:t}),O(he,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:c.map(e=>{let t=r&&a===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),C(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>C(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:[e.type,`:`,e.type===`device`?`[${e.targets.join(`,`)}]`:e.target]},t))})}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.expiresAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.createdAt)}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:C(`button`,{onClick:()=>n(e.id,e.name),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[t?O(N,{className:`h-3 w-3 animate-spin`}):O(R,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function _e({users:e,onClose:t,onSubmit:n,submitting:r}){let{user:i}=H(),a=i?.isAdmin===!0?null:i?.scopes??[],[o,s]=D(e[0]?.id??``),[c,l]=D(``),[u,d]=D([{type:`capability`,target:``,access:[`view`,`create`]}]),[f,p]=D(``),m=h(u),g=o!==``&&c.trim().length>0&&u.length>0&&m===null&&!r;return C(ye,{title:`Create scoped token`,onClose:t,children:[C(`div`,{className:`space-y-3`,children:[O(Y,{label:`On behalf of user`,children:O(`select`,{value:o,onChange:e=>s(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>O(`option`,{value:e.id,children:e.username},e.id))})}),O(Y,{label:`Name`,children:O(`input`,{value:c,onChange:e=>l(e.target.value),placeholder:`cloudflare-tunnel-route`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})}),C(Y,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[O(y,{value:u,onChange:d,clampToParent:a}),m&&O(`p`,{className:`mt-1 text-[10px] text-danger`,children:m})]}),O(Y,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:O(`input`,{type:`number`,min:1,value:f,onChange:e=>p(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),C(be,{children:[O(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),C(`button`,{onClick:()=>{let e=parseInt(f,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;n({userId:o,name:c.trim(),scopes:u,expiresAt:t})},disabled:!g,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[r?O(N,{className:`h-3.5 w-3.5 animate-spin`}):O(V,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function ve({token:e,label:t,onClose:n}){let[r,i]=D(!1),a=async()=>{try{await navigator.clipboard.writeText(e),i(!0)}catch{}};return C(ye,{title:`Token: ${t}`,onClose:n,children:[C(`div`,{className:`space-y-3`,children:[O(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),O(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),C(be,{children:[C(`button`,{onClick:()=>{a()},className:`inline-flex items-center gap-1.5 rounded bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[r?O(I,{className:`h-3.5 w-3.5 text-primary`}):O(A,{className:`h-3.5 w-3.5`}),r?`Copied`:`Copy`]}),O(`button`,{onClick:n,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function ye({title:e,onClose:t,children:n}){return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[C(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[O(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),O(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:O(B,{className:`h-4 w-4`})})]}),O(`div`,{className:`p-4`,children:n})]})})}function be({children:e}){return O(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Y({label:e,hint:t,children:n}){return C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),n,t&&O(`p`,{className:`text-[10px] text-foreground-subtle`,children:t})]})}S();function X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function xe(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function Se(){return O(`div`,{className:`space-y-2`,children:[1,2].map(e=>O(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function Ce({text:e}){return O(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function we({headers:e,rows:t}){return O(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[640px]`,children:[O(`thead`,{children:O(`tr`,{children:e.map((t,n)=>O(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),O(`tbody`,{children:t})]})})}function Te(){let e=E(),r=a(),{data:i,isLoading:o}=n(),s=w(()=>i??[],[i]),c=t({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),l=async(e,t)=>{await r({title:`Revoke "${t}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&c.mutate({id:e})};return C(U,{icon:K,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[o&&O(Se,{}),!o&&s.length===0&&O(Ce,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!o&&s.length>0&&O(we,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:s.map(e=>{let t=e.revokedAt!==null,n=(c.isPending?c.variables?.id:void 0)===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>O(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:xe(e)},t))})}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 border-b border-border`,children:t?C(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,X(e.revokedAt)]}):O(`span`,{className:`inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300`,children:`Active`})}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!t&&C(`button`,{onClick:()=>{l(e.id,e.integrationId)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?O(N,{className:`h-3 w-3 animate-spin`}):O(R,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}S();var Z=3e4,Q=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],$={title:`Authentication providers`,subtitle:`Every registered authentication surface in one list: login providers (local password, OIDC, SAML, magic-link) and second-factor providers (passkeys / WebAuthn — configure the relying-party RP ID + origin inline; users enroll from My access → Passkeys). Multiple providers run in parallel — enable/disable each independently. Disabling one only removes that method; local password login is unaffected.`,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,installLabel:`Add provider`};function Ee(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:ne,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA is self-enrolled: each user enables it from their own profile page (My access → Two-factor authentication).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:P,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`First-time sign-ins are auto-provisioned with the configured Default Role.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.",`Paste issuer + credentials in the Settings panel below — saves on every change.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:P,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:z,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:z,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:V,bullets:[`Generic authentication provider. No additional hints registered.`]}}function De(){let e=b({capName:Q[0].capName},{refetchInterval:Z}),t=b({capName:Q[1].capName},{refetchInterval:Z}),n=m(void 0,{refetchInterval:Z}),r=w(()=>G(n.data??[]),[n.data]),i=w(()=>{let n=[],i=[e.data??[],t.data??[]];for(let[e,t]of Q.entries())for(let a of i[e]??[])n.push({addonId:a.addonId,displayName:r.get(a.addonId)??a.addonId,isActive:a.isActive,capName:t.capName,stageBadge:t.stageBadge});return n},[e.data,t.data,r]);return O(M,{title:$.title,subtitle:$.subtitle,pageIcon:V,itemIcon:V,capability:Q[0].capName,installButtonLabel:$.installLabel,items:i,isLoading:e.isLoading||t.isLoading,emptyTitle:$.emptyTitle,emptyDescription:$.emptyDescription,renderStatusBadges:e=>e.stageBadge===null?null:O(`span`,{className:`inline-flex items-center rounded-full border border-primary/30 bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary`,children:e.stageBadge}),renderExpandedPanel:e=>O(Oe,{addonId:e.addonId})})}function Oe({addonId:e}){let t=Ee(e),n=t.icon;return C(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[C(`div`,{className:`flex items-start gap-2.5`,children:[O(n,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),O(`div`,{className:`text-xs text-foreground font-medium`,children:t.headline})]}),O(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:t.bullets.map((e,t)=>O(`li`,{children:e},t))}),t.setupSteps&&t.setupSteps.length>0&&C(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[C(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[O(te,{className:`h-3 w-3`}),`Setup steps`]}),O(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:t.setupSteps.map((e,t)=>O(`li`,{children:e},t))})]}),e===`local-auth`&&C(`div`,{className:`rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[O(L,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),C(`span`,{children:[`TOTP / 2FA is self-service: each user enrols from their own profile page —`,` `,O(`a`,{href:`/system/my-access`,className:`underline text-primary`,children:`My access`}),` `,`→ “Two-factor authentication” → Enable 2FA. Admins can only remove a user’s active enrollment (lost device) from the`,` `,O(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function ke(){return O(`div`,{className:`flex flex-col p-4`,children:O(W,{tabs:[{id:`users`,label:`Users`,icon:ie,content:O(oe,{})},{id:`api-keys`,label:`Tokens`,icon:j,content:O(fe,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:K,content:O(Te,{})},{id:`authentication`,label:`Authentication`,icon:V,content:O(De,{})}]})})}export{ke as IdentityPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Cn as e,En as t,Fn as n,G as r,K as i,Kn as a,Ln as o,Mn as s,Oo as c,Sn as l,Tt as u,_n as d,cr as f,d as p,fn as m,fr as h,g,gr as _,hn as v,it as y,lr as b,mn as x,mr as S,nt as C,pn as w,uo as T,ur as ee,ut as te,vn as E,x as D}from"./src-BBe6PrXe.js";import{I as O,K as ne,Q as k,S as A,W as j,b as M,o as N,q as P,x as F,z as re}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{z as I}from"./src-DSZBcu6j.js";import{p as L}from"./player-overlays-CzjKRHin.js";import{t as R}from"./ProviderIcon-9BELU-vo.js";import{t as z}from"./FormBuilder-Cogt0U0A.js";import{t as B}from"./plus-C7qYd7DF.js";import{n as V,r as ie,t as ae}from"./ScanNetworkModal-DGnLpsYA.js";import{t as oe}from"./refresh-cw-D_fKxMIe.js";import{t as se}from"./rotate-cw-CktlNgLW.js";import{t as H}from"./wifi-DyeEKGI-.js";import{C as U,F as W,G,J as ce,L as K,O as le,R as ue,U as de,Y as fe,c as pe,h as me,i as he,k as q,m as ge,q as _e,s as J,t as ve}from"./index-2QX2zxyn.js";var ye=G(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);k();function Y(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Y(n.fields));return t}function be(e,t,n){let[r,i]=P(`idle`),[a,o]=P({}),s=j(()=>{let t=[];for(let n of e.sections)t.push(...Y(n.fields));return t},[e]),c=s.length>0&&n!==void 0,l=O(e=>{o(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:r,hasProbeFields:c,probeResults:a,handleTestAll:O(async()=>{if(!n)return;let e=s.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;i(`testing`);let r={};for(let t of e)r[t]={status:`probing`};o(r);let a=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await n(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),c={};for(let e of a)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;c[t]={status:n.status===`ok`?`ok`:`error`,result:n}}o(c),i(`idle`)},[n,s,t]),clearProbeResult:l}}k();function xe(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...xe(n.fields));return t}function Se(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Ce(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Ce(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function we(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Te({open:e,integrationId:r,addonId:i,onClose:o}){let{t:s}=ve(),c=N(),[l,u]=P({}),[f,p]=P(!1),[m,h]=P(null),[_,v]=P(we),y=n({addonId:i},{enabled:e}),b=y.data?.deviceType??null,x=t({addonId:i,type:b??I.Camera},{enabled:e&&y.isSuccess&&b!==null}),S=x.data??null;re(()=>{e&&(u(S?Ce(S.sections.flatMap(e=>e.fields)):{}),v(we()),p(!1),h(null))},[e,r,S]);let C=j(()=>({...l,_probeRequestId:_}),[l,_]),w=d({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),T=a(),ee=O(async(e,t)=>{p(!0);let n=await T.mutateAsync({addonId:i,type:b??I.Camera,key:e,value:t,formValues:C});return n.status===`ok`&&n.suggestedValues&&u(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Se(e[i])&&!Se(a)&&(r[i]=a,t=!0);return t?r:e}),n},[T,i,C,b]),{testAllStatus:te,hasProbeFields:E,probeResults:D,handleTestAll:ne,clearProbeResult:k}=be(S??{sections:[]},l,ee);async function M(e){h(null);try{await w.mutateAsync({addonId:i,type:b??I.Camera,config:l,integrationId:r}),e?u(S?Ce(S.sections.flatMap(e=>e.fields)):{}):o()}catch(e){h(e instanceof Error?e.message:String(e))}}if(!e)return null;let L=xe((S?.sections??[]).flatMap(e=>e.fields)).filter(e=>Se(l[e])),R=L.length===0,B=y.isLoading||b!==null&&x.isLoading,V=y.isError||y.isSuccess&&b===null||x.isError||x.isSuccess&&S===null;return A(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[F(`div`,{className:`absolute inset-0 bg-black/60`,onClick:o}),A(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[90vh] rounded-xl border border-border bg-background shadow-2xl`,children:[A(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[F(`h2`,{className:`text-sm font-semibold text-foreground`,children:s(`integrations.addDevice`)}),F(`button`,{onClick:o,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:F(he,{className:`h-4 w-4`})})]}),F(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:B?F(`div`,{className:`flex items-center justify-center py-8`,children:F(U,{className:`h-5 w-5 animate-spin text-primary`})}):V?A(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[F(J,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),A(`div`,{className:`space-y-1`,children:[F(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),A(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,F(`span`,{className:`font-mono`,children:i}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):F(z,{schema:S,values:l,onChange:u,onTestField:ee,probeResults:D,onClearProbe:k})}),!V&&!B&&A(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[A(`button`,{type:`button`,onClick:()=>p(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[A(`span`,{className:`flex items-center gap-2`,children:[F(me,{className:`h-3.5 w-3.5`}),`Test logs`,F(`span`,{className:`font-mono text-[9px] opacity-60`,children:_.slice(0,14)})]}),F(K,{className:`h-3.5 w-3.5 transition-transform ${f?`rotate-180`:``}`})]}),f&&F(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:F(g,{addonId:i,requestId:_,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!V&&!B&&(m||L.length>0)&&F(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:A(`div`,{className:`flex items-start gap-2`,children:[F(J,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),F(`p`,{className:`text-[11px] text-destructive`,children:m||`Required: ${L.join(`, `)}`})]})}),A(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[A(`div`,{className:`flex items-center gap-2`,children:[F(`button`,{onClick:o,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:s(`integrations.cancel`)}),!V&&E&&A(`button`,{type:`button`,onClick:ne,disabled:te===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[te===`testing`?F(U,{className:`h-3.5 w-3.5 animate-spin`}):F(H,{className:`h-3.5 w-3.5`}),`Test All`]})]}),A(`div`,{className:`flex items-center gap-2`,children:[F(`button`,{onClick:()=>M(!0),disabled:V||!R||w.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:s(`integrations.saveAndNew`)}),F(`button`,{onClick:()=>M(!1),disabled:V||!R||w.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:w.isPending?s(`integrations.saving`):s(`integrations.save`)})]})]})]})]})}function X(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}k();var Z=`devices`,Q={id:Z,label:`Devices`,isDefault:!0},Ee=2e4,De=100;function Oe({addonId:e,integrationId:t,onClose:n}){let{t:i}=ve(),[a,o]=P(new Set),[s,c]=P(new Set),[l,u]=P(new Map),[d,f]=P(null),{data:p}=ee(),h=(p??[]).find(t=>t.addonId===e)?.supportsLocationImport??!1,[g,_]=P(!0),b=w({addonId:e,integrationId:t}).data?.filters,S=b&&b.length>0?b:[Q],[T,te]=P(S.find(e=>e.isDefault)?.id??(S.some(e=>e.id===Z)?Z:S[0].id)),E=T!==Z,D=v(),k=x({addonId:e,integrationId:t,page:1,pageSize:Ee,filter:T}),j=k.refetch,M=D.mutate,N=O(()=>{M({addonId:e,integrationId:t},{onSettled:()=>{j()}})},[M,e,t,j]),I=ne(null);re(()=>{let n=`${e}::${t}`;I.current===n||k.isLoading||(I.current=n,(k.data?.candidates.length??0)===0&&N())},[e,t,k.isLoading,k.data,N]);let L=D.isPending,R=D.isError?D.error instanceof Error?D.error.message:String(D.error):null,z=k.data?.candidates??[],B=k.isError?k.error instanceof Error?k.error.message:String(k.error):null,V=m(),ie=O(e=>{e.alreadyAdopted||o(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),ae=O(e=>{c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),oe=O((e,t)=>{u(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),H=O(e=>{let t={};for(let n of e){let e=l.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[l]),W=O(async()=>{f(null);let r=[...a];if(r.length!==0)try{let i=H(r);await V.mutateAsync({addonId:e,integrationId:t,filter:T,childNativeIds:r,...i?{perCandidate:i}:{},...h?{importLocations:g}:{}}),o(new Set),u(new Map),await j(),n()}catch(e){f(e instanceof Error?e.message:String(e))}},[a,H,V,e,t,T,j,h,g]),G=O(e=>{te(e),o(new Set),c(new Set),u(new Map),f(null)},[]),ce=a.size;return A(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[F(`div`,{className:`absolute inset-0 bg-black/60`,onClick:n}),A(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[A(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[A(`div`,{className:`min-w-0`,children:[F(`h2`,{className:`text-sm font-semibold text-foreground`,children:i(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),F(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:i(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),A(`div`,{className:`flex items-center gap-3 shrink-0`,children:[h&&A(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[F(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`accent-primary`}),i(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),F(`button`,{onClick:n,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:F(he,{className:`h-4 w-4`})})]})]}),A(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(R??B)&&z.length===0&&F(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:A(`div`,{className:`flex items-start gap-2`,children:[F(J,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),A(`div`,{className:`min-w-0`,children:[F(`p`,{className:`text-xs font-medium text-destructive`,children:i(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),F(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:R??B})]})]})}),S.length>1&&F(ke,{filters:S,activeFilter:T,onSelect:G}),F(`div`,{className:`flex-1 min-h-0`,children:F(r,{mode:`generic`,items:z,pageSize:De,getKey:e=>e.childNativeId,getSearchText:X,getFilterType:e=>e.type,filterOptions:C(),filterLabel:i(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:k.isLoading||L&&z.length===0,searchPlaceholder:i(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(R??B)&&z.length===0?``:i(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:A(`button`,{type:`button`,onClick:N,disabled:L,title:i(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[F(se,{className:`h-3.5 w-3.5 ${L?`animate-spin`:``}`}),i(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:i(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>F(Ae,{candidate:e,expandable:!E,expanded:s.has(e.childNativeId),onToggleExpand:()=>ae(e.childNativeId),adoptedLabel:i(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:i(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=y(e.type),n=t.icon;return A(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[F(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>F(`div`,{className:`flex items-center justify-end`,children:F(`button`,{onClick:()=>ie(e),disabled:e.alreadyAdopted,"aria-label":a.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${a.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:a.has(e.childNativeId)&&F(ue,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!E&&s.has(e.childNativeId),renderExpanded:E?void 0:e=>F($,{candidate:e,hiddenChildIds:l.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>oe(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:a.has(e.childNativeId)?`bg-primary/5`:``})})]}),d&&F(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:A(`div`,{className:`flex items-start gap-2`,children:[F(J,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),F(`p`,{className:`text-[11px] text-destructive`,children:d})]})}),A(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[F(`div`,{}),A(`div`,{className:`flex items-center gap-2`,children:[F(`button`,{onClick:n,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.cancel`,{defaultValue:`Cancel`})}),A(`button`,{onClick:W,disabled:ce===0||V.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[V.isPending&&F(U,{className:`h-3.5 w-3.5 animate-spin`}),i(`integrations.addSelected`,{defaultValue:`Add selected`}),ce>0?` (${ce})`:``]})]})]})]})]})}function ke({filters:e,activeFilter:t,onSelect:n}){return F(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return F(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function Ae({candidate:e,expandable:t,expanded:n,onToggleExpand:r,adoptedLabel:i}){let a=(e.children??[]).length;return A(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&a>0?A(`button`,{type:`button`,onClick:r,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[F(n?K:W,{className:`h-3.5 w-3.5`}),a]}):F(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),F(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&F(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:i})]})}function $({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let r=e.children??[];return r.length===0?null:F(`div`,{className:`space-y-1 py-1`,children:r.map(e=>{let r=t.has(e.childNativeId),i=e.capabilities??[];return A(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${r?`opacity-50`:``}`,children:[F(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),i.length>0&&F(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:i.join(`, `)}),F(`button`,{onClick:()=>n(e.childNativeId),"aria-label":r?`Show child`:`Hide child`,title:r?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:F(r?q:le,{className:`h-3 w-3`})})]},e.childNativeId)})})}k();function je({integrationId:e,addonId:t,name:n,kind:r,brokerKind:i,trpc:a,onClose:o}){let{t:s}=ve(),c=N(),l=r===`device-adoption`,{data:u}=h({id:e},{enabled:l}),d=j(()=>{let e=u?.brokerId;return typeof e==`string`?e:null},[u]),f=S();return F(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:o,children:A(`div`,{className:`max-h-[85vh] w-full max-w-md overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[A(`div`,{className:`mb-3 flex items-center justify-between`,children:[A(`h2`,{className:`text-sm font-semibold text-foreground`,children:[s(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),F(`button`,{onClick:o,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":s(`common.close`,{defaultValue:`Close`}),children:F(he,{className:`h-4 w-4`})})]}),l?i?A(`div`,{className:`space-y-3`,children:[F(`p`,{className:`text-[11px] text-foreground-subtle`,children:s(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),d&&A(`p`,{className:`text-[11px] text-foreground`,children:[s(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,F(`span`,{className:`font-mono text-foreground-subtle`,children:d})]}),f.isPending?A(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[F(U,{className:`h-3 w-3 animate-spin`}),s(`integrations.saving`,{defaultValue:`Saving…`})]}):F(V,{kind:i,onResolved:t=>{f.mutate({id:e,settings:{brokerId:t}},{onSuccess:()=>{c.invalidateQueries(),o()}})},onBack:o}),f.isError&&F(`p`,{className:`text-[11px] text-danger`,children:s(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):F(`p`,{className:`text-[11px] text-danger`,children:s(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):F(D,{trpc:a,addonId:t,nodeId:`hub`,title:n})]})})}k();function Me(){let{t}=ve(),{integrationId:n}=ce(),a=N(),d=_e(),[m,h]=fe(),v=L(),[y,x]=P(!1),[S,C]=P(!1),[w,D]=P(!1),[ne,k]=P(!1),[I,z]=P(!1),{data:V,isLoading:se}=b({id:n??``},{enabled:!!n}),{data:H}=te({addonId:V?.addonId??``,nodeId:`hub`},{enabled:!!V?.addonId}),{data:W,isSuccess:G}=ee(),K=j(()=>{let e=V?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[W,V?.addonId,G]),{data:le}=l({}),ue=j(()=>(le?.providers??[]).some(e=>e.addonId===V?.addonId),[le,V?.addonId]),q=K!==null,Y=V?.info?.fixed===!0,be=q?K===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),xe=j(()=>{let e=V?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.brokerKind??null},[W,V?.addonId,G]),Se=j(()=>{let e=V?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.mode??null},[W,V?.addonId,G]);re(()=>{m.get(`add`)===`1`&&q&&(x(!0),h(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[m,q,h]);let Ce=H!=null&&Array.isArray(H.sections)&&H.sections.some(e=>e.fields.length>0),{data:we}=s({},{refetchInterval:5e3}),X=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Z=_({onMutate:async e=>{await a.cancelQueries({queryKey:X});let t=a.getQueryData(X);return t!=null&&a.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&a.setQueryData(X,r.previous)},onSettled:()=>{a.invalidateQueries({queryKey:[[`integrations`]]}),a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=f({onSuccess:()=>{a.invalidateQueries({queryKey:[[`integrations`]]}),a.invalidateQueries({queryKey:[[`deviceManager`]]}),k(!1),d(`/integrations`)}}),Ee=u({onSuccess:()=>{a.invalidateQueries({queryKey:[[`integrations`]]}),a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),De=o({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=E({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ae=e({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=j(()=>we??[],[we]),Me=j(()=>{let e=new Map;for(let t of $)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[$]),Ne=O(e=>Me.get(e)??null,[Me]),Pe=O(e=>F(R,{type:e,size:`sm`}),[]),Fe=O(e=>d(`/devices/${String(e)}`),[d]),Ie=j(()=>{let e=V?.addonId;return e?$.filter(t=>t.addonId===e):[]},[$,V?.addonId]),Le=j(()=>i(Ie).length,[Ie]);return se?A(`div`,{className:`p-4`,children:[F(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),F(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):V?A(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[F(T,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},{label:V.name}]}),A(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[A(`div`,{className:`flex items-center gap-3 min-w-0`,children:[F(`img`,{src:`/api/addon-assets/${V.addonId}/assets/icon.svg`,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),A(`div`,{className:`min-w-0`,children:[F(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:V.name}),A(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[V.addonId,` · `,Le,` `,t(`integrations.devices`)]})]})]}),A(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[ue&&A(`button`,{onClick:()=>C(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the network for devices (incl. a different subnet)`,children:[F(ie,{className:`h-3.5 w-3.5`}),`Scan network`]}),!Y&&A(`button`,{onClick:()=>x(!0),disabled:!q,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:be,children:[F(B,{className:`h-3.5 w-3.5`}),be]}),A(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Z.isPending?`opacity-60`:``} ${V.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[F(c,{checked:V.enabled,onCheckedChange:e=>Z.mutate({id:n,enabled:e}),disabled:Z.isPending,"aria-label":V.enabled?`Disable integration`:`Enable integration`}),F(`span`,{className:`text-[11px] font-medium ${V.enabled?`text-success`:`text-foreground-subtle`}`,children:V.enabled?`Enabled`:`Disabled`}),Z.isPending&&F(U,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Se!==`standalone`&&(Ce||K===`device-adoption`)&&A(`button`,{onClick:()=>D(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[F(ge,{className:`h-3 w-3`}),t(`integrations.config`)]}),A(`button`,{onClick:()=>z(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrations.logs`,{defaultValue:`View logs`}),children:[F(me,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),F(p,{label:`Restart`,icon:oe,title:`Restart "${V.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Le} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Ee.isPending,action:()=>Ee.mutateAsync({addonId:V.addonId})}),!Y&&A(`button`,{onClick:()=>k(!0),className:`flex items-center gap-1.5 rounded-lg border border-danger bg-danger/10 px-3 py-1.5 text-[11px] font-medium text-danger hover:bg-danger hover:text-background transition-colors`,title:t(`integrations.delete`,{defaultValue:`Delete integration`}),children:[F(pe,{className:`h-3 w-3`}),t(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),F(r,{context:`integration-detail`,devices:$,trpc:v.trpcClient,defaultView:`cards`,forceAddon:V.addonId,urlScope:`root`,lsKey:`integration-detail:${V.addonId}`,resolveIntegrationIcon:Pe,resolveParent:Ne,onNavigate:Fe,batchActions:{remove:De.mutate,disable:ke.mutate,enable:Ae.mutate},...Y?{}:{onDeleteDevice:e=>De.mutate({deviceId:e.id})}}),y&&n&&K===`device-adoption`&&F(Oe,{addonId:V.addonId,integrationId:n,onClose:()=>x(!1)}),y&&n&&K===`device-provider`&&F(Te,{open:y,integrationId:n,addonId:V.addonId,onClose:()=>x(!1)}),S&&V&&F(ae,{open:S,scope:{addonId:V.addonId,label:V.name},onClose:()=>C(!1)}),w&&n&&K!==null&&F(je,{integrationId:n,addonId:V.addonId,name:V.name,kind:K,brokerKind:xe,trpc:v.trpcClient,onClose:()=>D(!1)}),I&&F(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>z(!1),children:A(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[A(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[A(`div`,{className:`flex items-center gap-2 min-w-0`,children:[F(me,{className:`h-4 w-4 text-primary shrink-0`}),F(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:V.name}),A(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[V.addonId,n?` · ${n}`:``]})]}),F(`button`,{onClick:()=>z(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:F(he,{className:`h-4 w-4`})})]}),F(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:F(g,{addonId:V.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),ne&&F(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Q.isPending&&k(!1),children:A(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[A(`div`,{className:`flex items-start gap-3`,children:[F(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:F(J,{className:`h-4 w-4 text-danger`})}),A(`div`,{className:`min-w-0`,children:[F(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),F(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:V.name,count:Le})})]})]}),Q.error&&F(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:Q.error instanceof Error?Q.error.message:String(Q.error)}),A(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[F(`button`,{onClick:()=>k(!1),disabled:Q.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:t(`integrations.cancel`,{defaultValue:`Cancel`})}),F(`button`,{onClick:()=>Q.mutate({id:n}),disabled:Q.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-danger px-3 py-1.5 text-[11px] font-medium text-background hover:bg-danger/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed`,children:Q.isPending?A(M,{children:[F(U,{className:`h-3 w-3 animate-spin`}),t(`integrations.deleting`,{defaultValue:`Deleting…`})]}):A(M,{children:[F(pe,{className:`h-3 w-3`}),t(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):A(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[F(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:F(ye,{className:`h-6 w-6 text-foreground-subtle`})}),A(`div`,{className:`space-y-1 max-w-sm`,children:[F(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),F(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:n??``})})]}),A(`button`,{onClick:()=>d(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[F(de,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{Me as IntegrationDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Bo as e,G as t,K as n,Mn as r,bn as i,dn as a,hr as o,pr as s,sr as c,ur as l,ut as u}from"./src-BBe6PrXe.js";import{I as d,Q as f,S as p,W as m,b as h,o as ee,q 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{p as y}from"./player-overlays-CzjKRHin.js";import{t as b}from"./ProviderIcon-9BELU-vo.js";import{t as x}from"./FormBuilder-Cogt0U0A.js";import{t as S}from"./plus-C7qYd7DF.js";import{n as te,r as C,t as w}from"./ScanNetworkModal-DGnLpsYA.js";import{t as T}from"./refresh-cw-D_fKxMIe.js";import{B as E,C as D,F as O,L as k,R as A,Y as j,i as M,m as N,q as P,t as F,v as ne}from"./index-2QX2zxyn.js";import{t as I}from"./AdminPage-Dq33XE9j.js";import{t as L}from"./StatusBadge-Dcr2bw58.js";import{t as R}from"./useEventInvalidation-qhbuBjhg.js";import{t as z}from"./useBodyScrollLock-B_rtaBV1.js";f();function B(e,t){let[n,r]=g(!1);return v(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}function V({onSelect:e,onClose:t,pendingAddonId:n=null}){let{t:r}=F(),i=P(),{data:a,isLoading:o}=l();if(o)return _(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>_(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let s=n!==null;return p(`div`,{className:`space-y-2`,children:[(a??[]).map(a=>{let o=a.instanceMode===`unique`&&a.existingInstances.length>0,c=n===a.addonId,l=s;return p(`button`,{disabled:l,onClick:()=>{if(!l)if(o){let e=a.existingInstances[0].id;t(),i(`/integrations/${e}`)}else e(a.addonId,a.instanceMode,a.discoveryMode,a.name,a.kind,a.brokerKind,a.mode)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[a.iconUrl?_(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${a.color}15`},children:_(`img`,{src:a.iconUrl,alt:``,className:`h-5 w-5`})}):_(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${a.color}15`},children:_(`span`,{className:`text-sm`,style:{color:a.color},children:`◉`})}),p(`div`,{className:`flex-1 min-w-0`,children:[_(`p`,{className:`text-xs font-semibold text-foreground`,children:a.name}),a.description&&_(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:a.description})]}),c?_(D,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):o?p(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[_(N,{className:`h-3 w-3`}),r(`integrations.manage`)]}):_(O,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},a.addonId)}),(a??[]).length===0&&_(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:r(`integrations.noProviders`)})]})}f();function re({addonId:e,configSchema:t,onSave:n,onBack:r}){let{t:i}=F(),[a,s]=g(``),[c,l]=g({}),[u,d]=g(null),f=o({onSuccess:e=>d(e),onError:e=>d({success:!1,error:String(e)})});return p(`div`,{className:`space-y-4`,children:[p(`div`,{children:[_(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:i(`integrations.integrationName`)}),_(`input`,{type:`text`,value:a,onChange:e=>s(e.target.value),placeholder:i(`integrations.integrationNamePlaceholder`),className:`w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:border-primary/50`})]}),t&&_(x,{schema:t,values:c,onChange:l}),u&&_(`div`,{className:`rounded-lg border px-3 py-2 text-xs ${u.success?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:u.success?i(`integrations.connectionSuccess`):`${i(`integrations.errorPrefix`)} ${u.error}`}),p(`div`,{className:`flex items-center justify-between pt-2`,children:[_(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.back`)}),p(`div`,{className:`flex items-center gap-2`,children:[_(`button`,{onClick:()=>f.mutate({addonId:e,settings:c}),disabled:f.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:f.isPending?i(`integrations.testing`):i(`integrations.testConnection`)}),_(`button`,{onClick:()=>n({name:a,config:c}),disabled:!a.trim(),className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:i(`integrations.forward`)})]})]})]})}f();function H({providerId:e,onImport:t,onSkip:n}){let{t:r}=F(),[a,o]=g(new Set),s=i(),c=s.data,l=s.isPending||!s.data&&!s.isError;v(()=>{e&&(s.isPending||s.data||s.mutate({addonId:e}))},[e,s]);function u(e){o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(l)return p(`div`,{className:`flex flex-col items-center py-12`,children:[_(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),_(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:r(`integrations.searchingDevices`)})]});let d=c??[];return p(`div`,{className:`space-y-4`,children:[_(`p`,{className:`text-xs text-foreground-subtle`,children:d.length>0?r(`integrations.foundDevices`,{count:d.length}):r(`integrations.noDevicesFound`)}),d.length>0&&_(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:d.map(e=>{let t=e.stableId,n=e.suggestedName??t,r=a.has(t);return p(`button`,{onClick:()=>u(t),className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${r?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[_(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${r?`border-primary bg-primary`:`border-border`}`,children:r&&_(A,{className:`h-3 w-3 text-primary-foreground`})}),_(E,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),_(`span`,{className:`text-xs font-medium text-foreground truncate`,children:n})]},t)})}),p(`div`,{className:`flex items-center justify-between pt-2`,children:[_(`button`,{onClick:n,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:r(`integrations.skip`)}),d.length>0&&p(`button`,{onClick:()=>t(Array.from(a)),disabled:a.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[r(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}f();function U(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var ie=2e4;function ae({open:e,onClose:t}){let{t:n}=F(),r=P(),o=ee(),[s,l]=g(`picker`),[d,f]=g(null),[y,b]=g(null),[x,S]=g(`manual`),[C,w]=g(null),[T,E]=g(``),[O,k]=g(null),[A,j]=g(null),{data:N}=u({addonId:d??``,nodeId:`hub`},{enabled:d!=null}),ne=m(()=>N?U(N):null,[N]),I=c({onSuccess:()=>o.invalidateQueries({queryKey:[[`integrations`]]})}),L=i(),R=L.data;v(()=>{s!==`discovery`||!y||!d||L.isPending||L.data||L.mutate({addonId:d})},[s,y,d,L]);let ae=a({onSuccess:()=>o.invalidateQueries({queryKey:[[`deviceManager`]]})});function W(e,t,n,r,i,a,o){if(!I.isPending){if(f(e),S(n),E(r),j(null),o===`broker`){if(!a){j(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}w(a),l(`broker`);return}if(o===`account`){l(`config`);return}oe(e,r)}}async function oe(e,n){try{let i=await I.mutateAsync({addonId:e,name:n,settings:{}});t(),J(),r(`/integrations/${i.id}?add=1`)}catch{}}async function se(e){if(d)try{let t=await I.mutateAsync({addonId:d,name:e.name,settings:e.config});b(t.id),x===`auto`||x===`both`?l(`discovery`):q(t.id)}catch{}}async function G(e){if(d)try{let t=await I.mutateAsync({addonId:d,name:T,settings:{brokerId:e}});k(t.id),b(t.id),q(t.id)}catch{}}async function K(e){if(d){for(let t of e){let e=R?.find(e=>e.stableId===t);e&&await ae.mutateAsync({addonId:d,candidate:e,...O===null?{}:{integrationId:O}})}q()}}function q(e){let n=e??y??d;t(),J(),n&&r(`/integrations/${n}`)}function J(){l(`picker`),f(null),b(null),S(`manual`),w(null),E(``),k(null),j(null)}function Y(){t(),J()}z(e);let X=I.isPending,Z=B(X,ie);if(!e)return null;let ce={picker:n(`integrations.newIntegration`),config:n(`integrations.configureIntegration`),discovery:n(`integrations.importDevices`),broker:n(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},le=X?d:null,Q=I.error,$=X&&!Z;return p(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[_(`div`,{className:`absolute inset-0 bg-black/60`,onClick:$?void 0:Y}),p(`div`,{className:`relative z-10 w-full max-w-lg max-h-[85vh] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[p(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[_(`h2`,{className:`text-sm font-semibold text-foreground`,children:ce[s]}),_(`button`,{onClick:Y,disabled:$,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:_(M,{className:`h-4 w-4`})})]}),p(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[Q&&!X&&_(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:Q instanceof Error?Q.message:String(Q)}),s===`picker`&&p(h,{children:[A&&_(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:A}),_(V,{onSelect:W,onClose:Y,pendingAddonId:le})]}),s===`config`&&d&&_(re,{addonId:d,configSchema:ne??null,onSave:se,onBack:()=>l(`picker`)}),s===`broker`&&C&&_(te,{kind:C,onResolved:e=>{G(e)},onBack:()=>l(`picker`)}),s===`discovery`&&y&&_(H,{providerId:y,onImport:K,onSkip:q})]}),X&&p(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[_(D,{className:`h-6 w-6 animate-spin text-primary`}),_(`p`,{className:`text-xs font-medium text-foreground`,children:n(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:n(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&p(h,{children:[_(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:n(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),_(`button`,{onClick:Y,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:n(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function W({integration:e,expanded:t,onToggleExpand:n}){return p(`div`,{className:`flex items-center gap-2.5`,children:[_(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),n(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:_(t?k:O,{className:`h-3.5 w-3.5`})}),_(b,{type:e.addonId,size:`sm`}),p(`div`,{className:`flex min-w-0 flex-col`,children:[_(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),_(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function oe(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>_(W,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>_(L,{status:e.status})}]}f();function se(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var G=`expand`;function K(){let{t:i}=F(),a=P(),o=y(),[c]=j(),[l,u]=g(!1),f=d(()=>u(!0),[]),ee=d(()=>u(!1),[]),[v,x]=g(!1),te=d(()=>x(!0),[]),E=d(()=>x(!1),[]);R([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),R([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:D,isLoading:O,refetch:k}=s(void 0),{data:A,isLoading:M,refetch:N}=r({}),L=m(()=>A??[],[A]),z=m(()=>D??[],[D]),B=m(()=>{let e=new Map;for(let t of L)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[L]),V=m(()=>{let e=new Map;for(let t of n(L)){let n=t.addonId??``;n&&e.set(n,(e.get(n)??0)+1)}return e},[L]),re=m(()=>z.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:se(e),deviceCount:V.get(e.addonId)??0})),[z,V]),H=c.get(G),U=d(e=>{let t=new URLSearchParams(window.location.search);t.get(G)===e?t.delete(G):t.set(G,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),ie=d(e=>a(`/integrations/${e.id}`),[a]),W=d(e=>B.get(e)??null,[B]),K=d(e=>_(b,{type:e,size:`sm`}),[]),q=d(e=>a(`/devices/${String(e)}`),[a]),J=d(e=>_(t,{context:`integration-detail`,devices:L,trpc:o.trpcClient,forceAddon:e.addonId,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:K,resolveParent:W,onNavigate:q}),[L,o.trpcClient,K,W,q]),Y=d(e=>H===e.addonId,[H]),X=m(()=>oe({isExpanded:Y,onToggleExpand:U}),[Y,U]),Z=d(e=>`${e.name} ${e.addonId}`,[]),ce=d(e=>e.addonId,[]),le=d(()=>{k(),N()},[k,N]),Q=O||M,$=z.length>0;return p(I,{icon:ne,title:i(`nav.integrations`,`Integrations`),actions:p(h,{children:[_(`button`,{onClick:le,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:_(T,{className:e(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),p(`button`,{onClick:te,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[_(C,{className:`h-3.5 w-3.5`}),`Scan network`]}),p(`button`,{onClick:f,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[_(S,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&_(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>_(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&p(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[_(`p`,{className:`text-sm`,children:`No integrations configured.`}),_(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&$&&_(t,{mode:`generic`,items:re,getKey:ce,getSearchText:Z,columns:X,onRowClick:ie,isExpanded:Y,renderExpanded:J,searchPlaceholder:i(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:i(`integrations.empty`,{defaultValue:`No integrations found.`})}),_(ae,{open:l,onClose:ee}),_(w,{open:v,onClose:E})]})}export{K as IntegrationsPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$n as e,Ao as t,Co as n,Do as r,Eo as i,Mo as a,No as o,Oo as s,S as c,So as l,To as u,Ya as d,Yi as f,fo as p,ho as m,jo as h,ko as g,lo as _,mo as v,po as y}from"./src-BBe6PrXe.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}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 A,b as ee,c as j,o as M,s as te,z as N}from"./src-DSZBcu6j.js";import{p as P}from"./player-overlays-CzjKRHin.js";import{t as F}from"./circle-check-big-DX7P42Tw.js";import{t as I}from"./copy-oDpB_CYv.js";import{t as L}from"./pencil-DUgcFYZU.js";import{t as R}from"./plus-C7qYd7DF.js";import{t as ne}from"./refresh-cw-D_fKxMIe.js";import{t as z}from"./search-CY5Hv7Yv.js";import{t as re}from"./send-B9r8Lohp.js";import{C as B,G as V,H as ie,P as ae,c as H,i as oe,p as U,s as se}from"./index-2QX2zxyn.js";import{t as W}from"./AdminPage-Dq33XE9j.js";import{t as ce}from"./AdminTabs-DTECFIAe.js";var le=V(`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`}]]),ue=V(`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`}]]),de=V(`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`}]]),fe=V(`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 G=e=>typeof e==`string`&&e.length>0;function pe(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 me(e,t){return e.format.includes(t)?t:e.format[0]??`text`}function he(e,t){let n=[];for(let r of e.attachments.mediaTypes){if(n.length>=e.attachments.max)break;let i=t[r];G(i)&&n.push({mediaType:r,url:i})}return n}function ge(e,t){if(e.actions<=0)return[];let n=[];for(let r of t){if(n.length>=e.actions)break;let t=G(r.label),i=G(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 _e(e,t){let n=e.levels.some(e=>e.id===t.level)?t.level:void 0,r=he(e,t.attachmentUrls),i=ge(e,t.actions),a=e.ttl&&G(t.ttl)?Number(t.ttl):void 0;return{body:t.body,format:me(e,t.format),priority:ve(t.priority),...G(t.title)?{title:t.title}:{},...n?{level:n}:{},...r.length>0?{attachments:r}:{},...i.length>0?{actions:i}:{},...e.clickUrl&&G(t.clickUrl)?{clickUrl:t.clickUrl}:{},...e.sound&&G(t.sound)?{sound:t.sound}:{},...a!==void 0&&Number.isFinite(a)?{ttl:a}:{},...G(t.tag)?{tag:t.tag}:{}}}function ve(e){return Number.isFinite(e)?Math.min(5,Math.max(1,Math.round(e))):3}function ye(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 be(e){return{level:``,priority:3,format:e.format[0]??`text`,title:``,body:``,attachmentUrls:{},actions:[],clickUrl:``,sound:``,ttl:``,tag:``}}var xe={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 Se(e,t){return e.attachments.max>0&&e.attachments.mediaTypes.includes(t)}function Ce(e){let t=[`text`];for(let n of[`image`,`gif`,`video`,`audio`])Se(e,n)&&t.push(n);return e.actions>0&&t.push(`actions`),e.levels.length>0&&t.push(`critical`),t.push(`overflow`),t}function K(e,t,n){let r=be(e);return Se(e,t)?{...r,body:n,attachmentUrls:{[t]:xe[t]}}:{...r,body:n}}function we(e,t){let n=be(e);switch(t){case`text`:return{...n,title:`CamStack`,body:`Test notification — text only.`};case`image`:return K(e,`image`,`Test notification with an image.`);case`gif`:return K(e,`gif`,`Test notification with an animation.`);case`video`:return K(e,`video`,`Test notification with a video.`);case`audio`:return K(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=ye(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 Te={text:`Text only`,image:`With image`,gif:`With GIF`,video:`With video`,audio:`With audio`,actions:`With buttons`,critical:`Critical`,overflow:`Overflow (advanced)`},q=`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,J=`block text-[11px] font-medium text-foreground mb-1`;function Ee({target:e,kind:t,open:s,onClose:c}){let d=P(),f=S(()=>pe(t.caps),[t.caps]),p=S(()=>Ce(t.caps),[t.caps]),[m,h]=D(()=>be(t.caps)),[g,_]=D(null),v=S(()=>_e(t.caps,m),[t.caps,m]),y=m.body.length,b=y>f.bodyMaxLen,C=e=>h(t=>({...t,...e})),w=O({mutationFn:()=>d.trpcClient.notificationOutput.testTarget.mutate({addonId:e.addonId,targetId:e.id,sample:_e(t.caps,m)}),onMutate:()=>_(null),onSuccess:e=>_(e),onError:e=>_({success:!1,error:e instanceof Error?e.message:`Test failed`})}),T=e=>{h(we(t.caps,e)),_(null)},E=(e,t,n)=>{let r=m.actions.length>0?[...m.actions]:[];for(;r.length<=e;)r.push({label:``,url:``});r[e]={...r[e],[t]:n},C({actions:r})};return k(l,{open:s,onOpenChange:e=>!e&&c(),children:x(n,{width:`lg`,className:`!max-w-2xl`,children:[k(i,{children:x(r,{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:p.map(e=>k(o,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>T(e),children:Te[e]},e))}),x(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[f.levels.length>0&&x(`div`,{children:[k(`label`,{className:J,children:`Level`}),x(`select`,{className:q,value:m.level,onChange:e=>C({level:e.target.value}),children:[k(`option`,{value:``,children:`— derive from priority —`}),f.levels.map(e=>x(`option`,{value:e.id,children:[e.label,e.ordinal===null?` (qualitative)`:` (p${e.ordinal})`]},e.id))]}),(()=>{let e=f.levels.find(e=>e.id===m.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(a,{variant:`danger`,"data-testid":`flag-critical`,children:`critical`}),e.flags?.silent&&k(a,{variant:`info`,children:`silent`}),e.flags?.noPush&&k(a,{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:J,children:[`Priority (ordinal): `,m.priority]}),k(`input`,{type:`range`,min:1,max:5,step:1,value:m.priority,onChange:e=>C({priority:Number(e.target.value)}),className:`w-full accent-primary`,"aria-label":`priority`})]})]}),f.formats.length>0&&x(`div`,{children:[k(`label`,{className:J,children:`Format`}),k(`div`,{className:`flex flex-wrap gap-2`,children:f.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:m.format===e,onChange:()=>C({format:e})}),e]},e))})]}),x(`div`,{children:[k(`label`,{className:J,children:`Title`}),k(`input`,{className:q,value:m.title,onChange:e=>C({title:e.target.value})})]}),x(`div`,{children:[x(`label`,{className:J,children:[`Body`,` `,x(`span`,{className:b?`text-danger`:`text-foreground-subtle`,children:[`(`,y,`/`,f.bodyMaxLen,b?` — overflow`:``,`)`]})]}),k(`textarea`,{className:`${q} min-h-[80px] resize-y`,value:m.body,onChange:e=>C({body:e.target.value})})]}),f.attachmentSlots.length>0&&x(`div`,{children:[x(`label`,{className:J,children:[`Attachments`,` `,x(`span`,{className:`text-foreground-subtle`,children:[`(mode: `,f.attachmentMode,`, max `,f.attachmentMax,f.attachmentMaxBytes?`, ≤${Math.round(f.attachmentMaxBytes/1024/1024)}MB`:``,`)`]})]}),k(`div`,{className:`space-y-1.5`,children:f.attachmentSlots.map(e=>x(`div`,{className:`flex items-center gap-2`,children:[k(`span`,{className:`text-[10px] w-12 shrink-0 text-foreground-subtle`,children:e}),k(`input`,{className:q,placeholder:`${e} URL`,value:m.attachmentUrls[e]??``,onChange:t=>C({attachmentUrls:{...m.attachmentUrls,[e]:t.target.value}})})]},e))})]}),f.showActions&&x(`div`,{children:[x(`label`,{className:J,children:[`Actions (up to `,f.maxActions,`)`]}),k(`div`,{className:`space-y-1.5`,children:Array.from({length:Math.min(f.maxActions,3)},(e,t)=>x(`div`,{className:`flex items-center gap-2`,children:[k(`input`,{className:q,placeholder:`label`,value:m.actions[t]?.label??``,onChange:e=>E(t,`label`,e.target.value)}),k(`input`,{className:q,placeholder:`url`,value:m.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:[f.showClickUrl&&x(`div`,{children:[k(`label`,{className:J,children:`Click URL`}),k(`input`,{className:q,value:m.clickUrl,onChange:e=>C({clickUrl:e.target.value})})]}),f.showSound&&x(`div`,{children:[k(`label`,{className:J,children:`Sound`}),k(`input`,{className:q,value:m.sound,onChange:e=>C({sound:e.target.value})})]}),f.showTtl&&x(`div`,{children:[k(`label`,{className:J,children:`TTL (seconds)`}),k(`input`,{className:q,type:`number`,value:m.ttl,onChange:e=>C({ttl:e.target.value})})]}),f.showTag&&x(`div`,{children:[k(`label`,{className:J,children:`Tag`}),k(`input`,{className:q,value:m.tag,onChange:e=>C({tag:e.target.value})})]})]}),g&&k(De,{result:g}),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(u,{children:[k(o,{variant:`secondary`,size:`sm`,type:`button`,onClick:c,children:`Close`}),x(o,{size:`sm`,type:`button`,disabled:w.isPending||m.body.length===0,onClick:()=>w.mutate(),children:[w.isPending?k(B,{className:`h-3.5 w-3.5 animate-spin`}):k(re,{className:`h-3.5 w-3.5`}),`Send test`]})]})]})})}function De({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(F,{className:`h-3.5 w-3.5 text-success`}):k(ae,{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 Oe(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 ke(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 Ae(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 je(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 Me=[`notificationOutput`,`listTargets`],Ne=[`notificationOutput`,`listTargetKinds`],Pe=[`userManagement`,`listUsers`],Fe=`ownerUserId`;function Ie(e){let t=e.config[Fe];return typeof t==`string`&&t.length>0?t:null}function Le(e){return[{key:`name`,header:`Target`,render:t=>{let n=e.kindByKey.get(t.kind);return x(`span`,{className:`flex items-center gap-2`,children:[k(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface text-xs`,title:n?.label??t.kind,children:k(Re,{kind:n,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:``})}),k(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name}),!t.enabled&&k(a,{variant:`warning`,children:`disabled`})]})}},{key:`kind`,header:`Kind`,nowrap:!0,render:t=>k(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.kindByKey.get(t.kind)?.label??t.kind})},{key:`owner`,header:`Owner`,nowrap:!0,render:t=>{let n=Ie(t);return n===null?k(a,{variant:`default`,children:`system`}):k(`span`,{className:`text-[11px] text-foreground`,children:e.userNameById.get(n)??n})}},{key:`enabled`,header:`On`,align:`center`,nowrap:!0,render:t=>k(s,{checked:t.enabled,onCheckedChange:n=>e.onToggle(t,n),"aria-label":`toggle ${t.name}`})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:t=>{let n=e.kindByKey.get(t.kind);return x(`span`,{className:`flex items-center justify-end gap-1`,children:[k(o,{size:`sm`,variant:`ghost`,type:`button`,disabled:!n,onClick:()=>e.onTest(t),title:`Test`,children:k(re,{className:`h-3.5 w-3.5`})}),k(o,{size:`sm`,variant:`ghost`,type:`button`,disabled:!n,onClick:()=>n&&e.onEdit(t,n),title:`Edit`,children:k(L,{className:`h-3.5 w-3.5`})}),k(o,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onDelete(t),title:`Delete`,children:k(H,{className:`h-3.5 w-3.5 text-danger`})})]})}}]}function Re({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 ze(){let e=P(),[t,n]=D({mode:`closed`}),[r,i]=D(null),a=C({queryKey:Me,queryFn:()=>e.trpcClient.notificationOutput.listTargets.query({})}),s=C({queryKey:Ne,queryFn:async()=>(await e.trpcClient.notificationOutput.listTargetKinds.query({})).map(e=>{let t=e.iconUrl;return{...e,configSchema:e.configSchema,iconUrl:t}})}),c=S(()=>s.data??[],[s.data]),l=S(()=>{let e=new Map;for(let t of c)e.set(t.kind,t);return e},[c]),u=C({queryKey:Pe,queryFn:()=>e.trpcClient.userManagement.listUsers.query()}),f=S(()=>{let e=new Map;for(let t of u.data??[])e.set(t.id,t.username);return e},[u.data]),p=O({mutationFn:t=>e.trpcClient.notificationOutput.setTargetEnabled.mutate({addonId:t.target.addonId,targetId:t.target.id,enabled:t.enabled}),onSuccess:()=>void a.refetch()}),m=O({mutationFn:t=>e.trpcClient.notificationOutput.deleteTarget.mutate({addonId:t.addonId,targetId:t.id}),onSuccess:()=>void a.refetch()}),g=r?l.get(r.kind):void 0;return x(W,{icon:ie,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(o,{size:`sm`,type:`button`,onClick:()=>n({mode:`pick-kind`}),children:[k(R,{className:`h-3.5 w-3.5`}),`Add target`]}),children:[a.isLoading&&k(`div`,{className:`flex items-center justify-center py-16`,children:k(B,{className:`h-6 w-6 animate-spin text-primary`})}),a.isError&&!a.isLoading&&k(d,{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(h,{children:k(_,{columns:Le({kindByKey:l,userNameById:f,onToggle:(e,t)=>p.mutate({target:e,enabled:t}),onTest:i,onEdit:(e,t)=>n({mode:`form`,kind:t,target:e}),onDelete:e=>m.mutate(e)}),rows:a.data??[],rowKey:e=>e.id,minWidthPx:720,bordered:!1})}),t.mode===`pick-kind`&&k(Be,{kinds:c,onCancel:()=>n({mode:`closed`}),onPick:e=>n({mode:`form`,kind:e,target:null})}),t.mode===`form`&&k(Ve,{kind:t.kind,target:t.target,users:u.data??[],onCancel:()=>n({mode:`closed`}),onSaved:()=>{n({mode:`closed`}),a.refetch()}}),r&&g&&k(Ee,{target:r,kind:g,open:!0,onClose:()=>i(null)})]})}function Be({kinds:e,onPick:t,onCancel:n}){let r=S(()=>Oe(e),[e]);return x(h,{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(o,{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(Re,{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(a,{variant:`info`,style:`outline`,children:`discover`})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]})}function Ve({kind:e,target:t,users:n,onSaved:r,onCancel:i}){let a=P(),s=S(()=>ke(e.configSchema),[e.configSchema]),l=S(()=>t?.config??{},[t]),[u,d]=D(t?.name??e.label),[f,p]=D(()=>t?je(t.config,s):{}),[m,_]=D(null),[v,y]=D(null),[b,C]=D(t?Ie(t)??``:``),w=O({mutationFn:()=>a.trpcClient.notificationOutput.discoverTargets.query({addonId:e.addonId,kind:e.kind,config:f}),onSuccess:e=>_(e),onError:e=>y(e instanceof Error?e.message:`Discovery failed`)}),T=O({mutationFn:()=>{let{[Fe]:n,...r}=Ae(f,l,s),i=b===``?r:{...r,[Fe]:b},o={id:t?.id??`${e.kind}-${Date.now()}`,name:u,kind:e.kind,addonId:e.addonId,enabled:t?.enabled??!0,config:i};return a.trpcClient.notificationOutput.upsertTarget.mutate({addonId:e.addonId,target:o})},onSuccess:r,onError:e=>y(e instanceof Error?e.message:`Save failed`)}),E=e=>{d(e.suggestedName),p(t=>({...t,...e.config})),_(null)};return x(h,{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(Re,{kind:e,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:`text-lg`}),t?`Edit ${t.name}`:`Add ${e.label} target`]}),k(o,{size:`sm`,variant:`ghost`,type:`button`,onClick:i,children:`Cancel`})]}),v&&k(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:v}),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:u,onChange:e=>d(e.target.value)})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Owner`}),k(g,{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(o,{size:`sm`,variant:`outline`,type:`button`,disabled:w.isPending,onClick:()=>{y(null),w.mutate()},children:[w.isPending?k(B,{className:`h-3.5 w-3.5 animate-spin`}):k(z,{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}`))})]}),s.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:f,onChange:p}),x(`div`,{className:`flex justify-end gap-2`,children:[k(o,{variant:`secondary`,size:`sm`,type:`button`,onClick:i,children:`Cancel`}),x(o,{size:`sm`,type:`button`,disabled:T.isPending||u.trim().length===0,onClick:()=>{y(null),T.mutate()},children:[T.isPending&&k(B,{className:`h-3.5 w-3.5 animate-spin`}),t?`Save changes`:`Create target`]})]})]})}var He=[{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`}],Ue={sequences:[],buttons:[]};function We(e){return e===void 0?Ue:{sequences:[...e.onTrigger??[]],buttons:[...e.buttons??[]]}}function Ge(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 Ke(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 qe(e){return{name:`sequence ${String(e+1)}`,enabled:!1,actions:[]}}function Je(e,t){return{id:`action-${String(e+1)}`,label:`Action`,sequence:t}}function Ye(){return{kind:`wait`,seconds:5}}var Y=`mt-1 w-full rounded border border-border bg-background px-2 py-1 text-xs`,X=`block text-[11px] font-medium text-foreground`;function Xe({value:e,onChange:t,devices:n}){let r=Ke(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(o,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t({...e,sequences:[...e.sequences,qe(e.sequences.length)]}),children:[k(R,{className:`h-3.5 w-3.5`}),` Sequence`]})]}),e.sequences.length===0?k(`p`,{className:`rounded border border-border px-3 py-2 text-[11px] text-foreground-subtle`,children:`This rule actuates nothing — it only notifies.`}):e.sequences.map((r,a)=>k(Ze,{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(o,{size:`sm`,variant:`ghost`,type:`button`,disabled:e.sequences.length===0,onClick:()=>t({...e,buttons:[...e.buttons,Je(e.buttons.length,e.sequences[0]?.name??``)]}),children:[k(R,{className:`h-3.5 w-3.5`}),` Button`]})]}),e.buttons.length>0&&x(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/40 bg-warning/10 px-3 py-2 text-[11px] text-warning`,children:[k(se,{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(et,{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 Ze({sequence:e,devices:n,onChange:r,onRemove:i}){let a=(t,n)=>r({...e,actions:e.actions.map((e,r)=>r===t?n:e)});return x(`div`,{className:`space-y-2 rounded-md border border-border p-3`,children:[x(`div`,{className:`flex flex-wrap items-end gap-2`,children:[x(`div`,{className:`min-w-0 flex-1`,children:[k(`label`,{className:X,children:`Name`}),k(t,{className:`mt-1`,value:e.name,onChange:t=>r({...e,name:t.target.value})})]}),x(`div`,{className:`w-28`,children:[k(`label`,{className:X,children:`Min delay (s)`}),k(`input`,{type:`number`,min:0,className:Y,value:e.minDelaySec??``,onChange:t=>{let n=t.target.value,i={...e};n===``?delete i.minDelaySec:i.minDelaySec=Number(n),r(i)}})]}),x(`div`,{className:`flex items-center gap-2 pb-1`,children:[k(s,{checked:e.enabled,onCheckedChange:t=>r({...e,enabled:t})}),k(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.enabled?`Runs on match`:`Only when a button is tapped`})]}),k(o,{size:`sm`,variant:`ghost`,type:`button`,onClick:i,title:`Remove`,children:k(H,{className:`h-3.5 w-3.5`})})]}),x(`div`,{className:`space-y-2 border-l-2 border-border-subtle pl-3`,children:[e.actions.map((t,i)=>k(Qe,{step:t,devices:n,onChange:e=>a(i,e),onRemove:()=>r({...e,actions:e.actions.filter((e,t)=>t!==i)})},`step-${String(i)}`)),x(o,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>r({...e,actions:[...e.actions,Ye()]}),children:[k(R,{className:`h-3.5 w-3.5`}),` Step`]})]})]})}function Qe({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:X,children:`Step`}),x(`select`,{className:Y,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:X,children:`Seconds`}),k(`input`,{type:`number`,min:0,max:300,className:Y,value:e.seconds,onChange:e=>n({kind:`wait`,seconds:Number(e.target.value)})})]}):k($e,{step:e,devices:t,onChange:n}),k(o,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,title:`Remove step`,children:k(H,{className:`h-3.5 w-3.5`})})]})}function $e({step:e,devices:n,onChange:r}){let i=P(),a=C({queryKey:[`deviceManager`,`getBindings`,e.deviceId],enabled:e.deviceId>0,staleTime:6e4,queryFn:async()=>{let t=await i.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:X,children:`Device`}),x(`select`,{className:Y,value:String(e.deviceId),onChange:t=>r({...e,deviceId:Number(t.target.value),cap:``}),children:[k(`option`,{value:`0`,children:`Select…`}),n.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:X,children:`Capability`}),x(`select`,{className:Y,value:e.cap,disabled:a.length===0,onChange:t=>r({...e,cap:t.target.value,method:``}),children:[k(`option`,{value:``,children:a.length===0?`No devices bound`:`Select…`}),a.map(e=>k(`option`,{value:e,children:e},e))]})]}),x(`div`,{className:`min-w-[7rem] flex-1`,children:[k(`label`,{className:X,children:`Method`}),k(t,{className:`mt-1`,value:e.method,placeholder:`arm`,onChange:t=>r({...e,method:t.target.value})})]}),x(`div`,{className:`min-w-[8rem] flex-1`,children:[k(`label`,{className:X,children:`Arguments (JSON)`}),k(t,{className:`mt-1`,value:e.args===void 0?``:JSON.stringify(e.args),placeholder:`{"mode":"away"}`,onChange:t=>{let n=t.target.value.trim();if(n===``){let t={...e};delete t.args,r(t);return}try{let t=JSON.parse(n);typeof t==`object`&&t&&!Array.isArray(t)&&r({...e,args:t})}catch{}}})]})]})}function et({button:e,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:X,children:`Label`}),k(t,{className:`mt-1`,value:e.label,onChange:t=>r({...e,label:t.target.value})})]}),x(`div`,{className:`min-w-[8rem] flex-1`,children:[k(`label`,{className:X,children:`Runs`}),x(`select`,{className:Y,value:e.sequence,onChange:t=>r({...e,sequence:t.target.value}),children:[!n.includes(e.sequence)&&x(`option`,{value:e.sequence,children:[e.sequence,` (missing)`]}),n.map(e=>k(`option`,{value:e,children:e},e))]})]}),x(`div`,{className:`w-32`,children:[k(`label`,{className:X,children:`Icon`}),x(`select`,{className:Y,value:e.icon??``,onChange:t=>{let n={...e};if(t.target.value===``)delete n.icon;else{let e=He.find(e=>e.value===t.target.value);e!==void 0&&(n.icon=e.value)}r(n)},children:[k(`option`,{value:``,children:`None`}),He.map(e=>k(`option`,{value:e.value,children:e.label},e.value))]})]}),x(`div`,{className:`flex items-center gap-2 pb-1`,children:[k(s,{checked:e.destructive===!0,onCheckedChange:t=>{let n={...e};t?n.destructive=!0:delete n.destructive,r(n)}}),k(a,{variant:e.destructive===!0?`danger`:`default`,children:`Destructive style`})]}),k(o,{size:`sm`,variant:`ghost`,type:`button`,onClick:i,title:`Remove`,children:k(H,{className:`h-3.5 w-3.5`})})]})}var tt={search:``,types:[],selectedOnly:!1};function nt(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 rt(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 it(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 at(e,t){let n=new Set(t);for(let t of e)n.add(t.id);return[...n]}function ot(e,t){let n=new Set(e.map(e=>e.id));return t.filter(e=>!n.has(e))}function st(e,t){return e.length===0?`Every device (${String(t)}) — no restriction`:`${String(e.length)} of ${String(t)} selected`}b();function ct({devices:e,value:n,onChange:r,loading:i=!1}){let[s,c]=D(tt),l=S(()=>nt(e),[e]),u=S(()=>rt(e,s,n),[e,s,n]),d=S(()=>it(u),[u]),f=e=>c(t=>({...t,types:t.types.includes(e)?t.types.filter(t=>t!==e):[...t.types,e]})),p=e=>r(n.includes(e)?n.filter(t=>t!==e):[...n,e]);return i?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:st(n,e.length)}),x(`div`,{className:`flex items-center gap-1`,children:[k(o,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>r(at(u,n)),children:`Select shown`}),k(o,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>r(ot(u,n)),children:`Clear shown`})]})]}),x(`div`,{className:`flex flex-wrap items-center gap-2`,children:[k(t,{className:`min-w-[10rem] flex-1`,value:s.search,placeholder:`Search by name…`,leftSlot:k(z,{className:`h-3.5 w-3.5 text-foreground-subtle`}),onChange:e=>c(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:s.selectedOnly,onChange:e=>c(t=>({...t,selectedOnly:e.target.checked}))}),`Selected only`]})]}),k(`div`,{className:`flex flex-wrap gap-1`,children:l.map(e=>x(`button`,{type:`button`,onClick:()=>f(e.type),className:s.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))}),u.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:d.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:n.includes(e.id),onChange:()=>p(e.id),className:`accent-primary`}),k(`span`,{className:`flex-1 truncate`,children:e.name}),k(a,{variant:`default`,children:e.type})]},e.id))})]},e.location??`__unplaced`))})]})}function Z(e){return t=>Object.prototype.hasOwnProperty.call(e,t)}var lt=Z({devices:!0}),ut=Z({classes:!0,classesExclude:!0,labelEquals:!0,identities:!0,identitiesExclude:!0,eventTypeTokens:!0,sensorKinds:!0}),dt=Z({zonesExclude:!0}),ft=Z({minConfidence:!0,minImportance:!0,minLabelConfidence:!0}),pt=Z({minDwellSeconds:!0}),mt=Z({source:!0}),ht=Z({crossing:!0}),gt=Z({packagePhase:!0}),_t=Z({zones:!0}),vt=Z({plates:!0}),yt=Z({occupancy:!0}),bt=Z({deviceState:!0});function Q(e,t){let n=e[t];return Array.isArray(n)?n:[]}function xt(e,t){let n=e[t];return typeof n==`number`?n:void 0}var St=[{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 Ct(e){let t=e.replace(/[-_]/g,` `);return t.charAt(0).toUpperCase()+t.slice(1)}function wt(e,t){let n=e.filter(t),r=new Set(St.map(e=>e.id)),i=[];for(let e of St){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:Ct(e),descriptors:n.filter(t=>t.group===e)});return i}b();function Tt(e,t){let n=P().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 Et(e){let t=P().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 Dt(){let t=e();return S(()=>({options:(t.data??[]).map(e=>({value:e.name,label:e.name})),loading:t.isLoading}),[t.data,t.isLoading])}function Ot(){let e=f({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 kt({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 $=[{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 At(e){return $.find(t=>t.value===e)?.label??e}function jt(e){return $.find(t=>t.value===e)?.value}var Mt=[{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 Nt(e){return Mt.find(t=>t.value===e)?.value}var Pt=[{value:``,label:`Automatic`},{value:`cropped`,label:`Cropped on the subject`},{value:`full`,label:`Full frame`},{value:`boxed`,label:`Full frame with boxes`}];function Ft(e){let t=Pt.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 Lt(e){let t=It.find(t=>t.value===e)?.value;return t===``?void 0:t}var Rt=[{value:`any`,label:`Any source`},{value:`pipeline`,label:`Pipeline`},{value:`onboard`,label:`Onboard (camera)`},{value:`sensor`,label:`Sensor`}],zt=[{value:`delivered`,label:`Delivered`},{value:`picked-up`,label:`Picked up`},{value:`both`,label:`Both`}],Bt=[{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 Vt(e){let t=Bt.find(t=>t.value===e)?.value;return t===``||t===void 0?void 0:t}var Ht=[{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 Wt(){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,mediaClipSpeed:void 0,templateTitle:``,templateBody:``,conditions:{},schedule:void 0,snoozeAllowGlobal:!1,actions:Ue,deviceIds:[]}}function Gt(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:We(e.actions),deviceIds:e.conditions.devices??[]}}function Kt(e){return e.name.trim().length>0&&(e.targetIds.length>0||e.targetUsers.length>0)&&Ke(e.actions).length===0}function qt(e,t){return e.appliesTo.includes(t)}var Jt={source:`any`};function Yt(e,t){if(t==null)return!0;if(Array.isArray(t))return t.length===0;if(typeof t==`string`)return t.length===0||Jt[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 Xt(e,t,n){let r=n.length===0?null:new Set(n.filter(e=>e.id!==`schedule`&&qt(e,t)).map(e=>e.id)),i={};for(let[t,n]of Object.entries(e))r!==null&&!r.has(t)||Yt(t,n)||(i[t]=n);return i}function Zt(e){return e!==void 0&&e.windows.length>0}function Qt(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=Ge(e.actions),s=(n.length===0||n.some(t=>t.id===`schedule`&&qt(t,e.delivery)))&&Zt(e.schedule)?e.schedule:void 0;return{name:e.name.trim(),enabled:e.enabled,delivery:e.delivery,conditions:{...Xt(e.conditions,e.delivery,n),...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:{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:t?.throttle??{cooldownSec:60,scope:`rule-device`},priority:e.priority,...a?{template:a}:{},...e.snoozeAllowGlobal?{snoozeAllowGlobal:!0}:{},...o===void 0?{}:{actions:o}}}function $t(e,t){return e.options&&e.options.length>0?e.options:t}var en=[{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 tn(e){if(e===``)return;let t=Number(e);return Number.isFinite(t)&&t>=1&&t<=8?t:void 0}var nn=[{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`]}],rn=`rule`;function an(e){return nn.find(t=>t.key===e)?.key}b();var on=`block text-[11px] font-medium text-foreground`,sn=`text-[10px] text-foreground-subtle mt-0.5`;function cn({cameras:e,value:t,onChange:n}){if(e.length===0)return k(`p`,{className:sn,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 ln({value:e,placeholder:n,onChange:r}){let[i,a]=D(``),o=()=>{let t=i.trim();if(t.length===0||e.includes(t)){a(``);return}r([...e,t]),a(``)},s=t=>r(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:()=>s(e),"aria-label":`remove ${e}`,className:`text-foreground-subtle hover:text-danger`,children:k(oe,{className:`h-3 w-3`})})]},e))}),k(t,{value:i,placeholder:n,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),o())},onBlur:o})]})}function un({picker:e,value:t,onChange:n}){let r=S(()=>te(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 dn({value:e,min:n,max:r,step:i,onChange:a}){return x(`div`,{className:`mt-1 flex items-center gap-2`,children:[k(t,{type:`number`,value:e??``,min:n,max:r,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&&r!==void 0&&k(`input`,{type:`range`,min:n,max:r,step:i,value:e,onChange:e=>a(Number(e.target.value)),className:`flex-1 accent-primary`,"aria-label":`value`})]})}function fn({value:e,onChange:t,options:n}){let r=e??``,i=n&&n.length>0?n:Bt,a=i.find(e=>e.value===r);return x(`div`,{className:`mt-1 space-y-1`,children:[k(g,{value:r,options:i.map(e=>({value:e.value,label:e.label})),onChange:e=>t(Vt(e.target.value))}),a!==void 0&&k(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:a.hint})]})}function pn({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(g,{value:a,options:Ht.map(e=>({value:e.value,label:e.label})),onChange:e=>s(e.target.value===`all`?`all`:`any`)})}),k(mn,{deviceIds:e,cameras:t,value:i,onChange:o})]})}function mn({deviceIds:e,cameras:t,value:n,onChange:r}){let{options:i,loading:a}=Tt(e,t);return k(kt,{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 hn({value:e,onChange:t}){let{options:n,loading:r}=Dt();return k(kt,{options:n,value:e,onChange:t,loading:r,emptyHint:`No identities in the face gallery yet — type a name.`,placeholder:`Identity name…`})}function gn({deviceIds:e,value:t,onChange:n}){let{options:r,loading:i}=Et(e);return k(kt,{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 _n=[{value:`became-occupied`,label:`Became occupied`},{value:`became-free`,label:`Became free`},{value:`>=`,label:`Count ≥`},{value:`<=`,label:`Count ≤`}],vn={op:`became-occupied`,count:1,sustainSeconds:15};function yn({deviceIds:e,cameras:n,classOptions:r,value:i,onChange:a}){let{options:o,loading:s}=Tt(e,n),c=i??vn,l=e=>a({...c,...e}),u=c.op===`became-occupied`||c.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(g,{value:c.zoneId??``,options:[{value:``,label:s?`Loading zones…`:`— whole frame —`},...o.map(e=>({value:e.value,label:e.label}))],onChange:e=>l({zoneId:e.target.value===``?void 0:e.target.value})})}),k(`div`,{className:`min-w-[9rem]`,children:k(g,{value:c.className??``,options:[{value:``,label:`— any class —`},...r.map(e=>({value:e.value,label:e.label}))],onChange:e=>l({className:e.target.value===``?void 0:e.target.value})})}),k(`div`,{className:`min-w-[9rem]`,children:k(g,{value:c.op,options:_n.map(e=>({value:e.value,label:e.label})),onChange:e=>{let t=_n.find(t=>t.value===e.target.value);t&&l({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:[u?`Threshold`:`Count`,k(t,{type:`number`,min:0,className:`w-16`,value:String(c.count),onChange:e=>l({count:Math.max(0,Number(e.target.value)||0)})})]}),x(`label`,{className:`flex items-center gap-1`,children:[`Hold for`,k(t,{type:`number`,min:0,max:3600,className:`w-16`,value:String(c.sustainSeconds),onChange:e=>l({sustainSeconds:Math.min(3600,Math.max(0,Number(e.target.value)||0))})}),`s`]}),i===void 0?null:k(`button`,{type:`button`,onClick:()=>a(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 bn({value:e,onChange:n}){let r=e?.values??[],i=e?.maxDistance??1,a=e=>n(e.length>0?{values:e,maxDistance:i}:void 0),o=e=>n(r.length>0?{values:r,maxDistance:e}:void 0),s=Ot().filter(e=>!r.includes(e));return x(`div`,{className:`mt-1 space-y-1.5`,children:[k(ln,{value:r,placeholder:`Plate text…`,onChange:a}),s.length>0&&x(`div`,{className:`flex flex-wrap items-center gap-1`,children:[k(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Seen:`}),s.slice(0,12).map(e=>k(`button`,{type:`button`,onClick:()=>a([...r,e]),className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:e},e))]}),x(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Max distance`,k(t,{type:`number`,min:0,max:3,step:1,value:i,className:`max-w-[5rem]`,onChange:e=>{let t=Number(e.target.value);o(Number.isFinite(t)?Math.max(0,Math.min(3,t)):1)}})]})]})}function xn({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(g,{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 Sn=[{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 Cn(e){let t=Math.floor(e/60),n=e%60;return`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}`}function wn(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 Tn(){return{days:[1,2,3,4,5],startMinute:540,endMinute:1080}}function En({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,Tn()],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:sn,children:`Always active — add a window to restrict when the rule fires.`}):n.map((e,t)=>k(Dn,{window:e,onChange:e=>s(t,e),onRemove:()=>o(t)},t)),x(`div`,{className:`flex items-center gap-3`,children:[x(`button`,{type:`button`,onClick:a,className:`flex items-center gap-1 rounded-md bg-surface-hover px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground`,children:[k(R,{className:`h-3 w-3`}),` Add window`]}),n.length>0&&x(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[k(`input`,{type:`checkbox`,checked:r,onChange:e=>i([...n],e.target.checked),className:`accent-primary`}),`Active outside the windows`]})]})]})}function Dn({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:Cn(e.startMinute),onChange:n=>t({...e,startMinute:wn(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:Cn(e.endMinute),onChange:n=>t({...e,endMinute:wn(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(H,{className:`h-3.5 w-3.5`})})]}),k(`div`,{className:`flex flex-wrap gap-1`,children:Sn.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))})]})}b();function On({catalog:e,taxonomy:t,delivery:n,conditions:r,schedule:i,cameras:o,gateable:s,onConditionsChange:c,onScheduleChange:l}){let u=(e,t)=>{let n={...r};t===void 0?delete n[e]:n[e]=t,c(n)},d=S(()=>wt(e,e=>e.id!==`devices`&&M(e.id)),[e]),f=S(()=>wt(e,e=>e.id!==`devices`&&!M(e.id)),[e]),[p,m]=D(()=>{if(An(r,i))return!0;try{return localStorage.getItem(kn)===`1`}catch{return!1}}),h=()=>{let e=!p;m(e);try{localStorage.setItem(kn,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 c=qt(e,n);return x(`div`,{className:c?``:`opacity-50`,"data-testid":`condition-${e.id}`,children:[x(`div`,{className:`flex items-center justify-between gap-2`,children:[k(`label`,{className:on,children:e.label}),!c&&x(a,{variant:`default`,children:[`not for `,e.appliesTo.join(` / `)]})]}),c?k(jn,{descriptor:e,taxonomy:t,conditions:r,schedule:i,cameras:o,gateable:s,onFieldChange:u,onScheduleChange:l}):k(`p`,{className:sn,children:`Not evaluated for the selected trigger — switch the trigger to use it.`}),c&&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(d),f.length>0&&k(`button`,{type:`button`,onClick:h,"data-testid":`nc-advanced-toggle`,className:`w-full rounded-md border border-border px-3 py-1.5 text-left text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:p?`▾ Hide advanced configurations`:`▸ Show more configurations`}),p&&g(f)]})}var kn=`camstack.nc.showAdvanced`;function An(e,t){for(let[t,n]of Object.entries(e))if(!M(t)&&n!==void 0&&!(Array.isArray(n)&&n.length===0))return!0;return t!==void 0&&t.windows.length>0}function jn({descriptor:e,taxonomy:t,conditions:n,schedule:r,cameras:i,gateable:a,onFieldChange:o,onScheduleChange:s}){switch(e.valueType){case`deviceIdList`:{if(!lt(e.id))break;let t=e.id;return k(cn,{cameras:i,value:n[t]??[],onChange:e=>o(t,e.length>0?e:void 0)})}case`stringList`:{if(!ut(e.id))break;let r=e.id,i=e=>o(r,e.length>0?e:void 0);if(r===`identities`||r===`identitiesExclude`)return k(hn,{value:Q(n,r),onChange:i});if(r===`eventTypeTokens`)return k(gn,{deviceIds:n.devices??[],value:Q(n,r),onChange:i});let a=j(r,t);return a===null?k(ln,{value:Q(n,r),placeholder:`Add value…`,onChange:i}):k(un,{picker:a,value:Q(n,r),onChange:i})}case`zoneIdList`:{if(!dt(e.id))break;let t=e.id;return k(mn,{deviceIds:n.devices??[],cameras:i,value:Q(n,t),onChange:e=>o(t,e.length>0?e:void 0)})}case`number01`:{if(!ft(e.id))break;let t=e.id;return k(dn,{value:xt(n,t),min:0,max:1,step:.05,onChange:e=>o(t,e)})}case`number`:{if(!pt(e.id))break;let t=e.id;return k(dn,{value:xt(n,t),min:0,step:1,onChange:e=>o(t,e)})}case`sourceSelect`:{if(!mt(e.id))break;let t=e.id;return k(g,{value:n[t]??`any`,options:$t(e,Rt).map(e=>({value:e.value,label:e.label})),onChange:e=>o(t,Pn(e.target.value))})}case`deviceState`:if(!bt(e.id))break;return k(xn,{gateable:a,value:n.deviceState,onChange:e=>o(`deviceState`,e)});case`crossingSelect`:{if(!ht(e.id))break;let t=e.id;return k(fn,{value:n[t],onChange:e=>o(t,e),...e.options?{options:e.options}:{}})}case`packagePhase`:{if(!gt(e.id))break;let t=e.id;return k(g,{value:n[t]??``,options:[{value:``,label:`— any phase —`},...$t(e,zt).map(e=>({value:e.value,label:e.label}))],onChange:e=>o(t,Fn(e.target.value))})}case`zoneSelection`:{if(!_t(e.id))break;let t=e.id;return k(pn,{deviceIds:n.devices??[],cameras:i,value:n[t],onChange:e=>o(t,e)})}case`plateMatcher`:{if(!vt(e.id))break;let t=e.id;return k(bn,{value:n[t],onChange:e=>o(t,e)})}case`occupancy`:{if(!yt(e.id))break;let r=e.id;return k(yn,{deviceIds:n.devices??[],cameras:i,classOptions:Mn(t),value:n[r],onChange:e=>o(r,e)})}case`schedule`:return k(En,{value:r,onChange:s});default:break}return k(Nn,{descriptor:e,conditions:n})}function Mn(e){let t=j(`classes`,e);return t===null?[]:t.groups.flatMap(e=>e.options)}function Nn({descriptor:e,conditions:t}){let n=Object.entries(t).find(([t])=>t===e.id);return x(`p`,{className:sn,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 Pn(e){if(e===`pipeline`||e===`onboard`||e===`sensor`||e===`any`)return e}function Fn(e){return zt.find(t=>t.value===e)?.value}b();var In=[`notificationRules`,`listSnoozes`],Ln=3e4;function Rn(e,t){return Math.max(0,Math.ceil((e.expiresAt-t)/6e4))}function zn(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 Bn({rules:e}){let t=P(),n=E(),r=C({queryKey:In,refetchInterval:Ln,queryFn:async()=>(await t.trpcClient.notificationRules.listSnoozes.query({})).snoozes}),i=O({mutationFn:e=>t.trpcClient.notificationRules.cancelSnooze.mutate({snoozeId:e}),onSuccess:()=>n.invalidateQueries({queryKey:In})}),s=S(()=>{let t=new Map;for(let n of e)t.set(n.id,n.name);return t},[e]),c=Date.now(),l=(r.data??[]).filter(e=>c>=e.startedAt&&c<e.expiresAt);return l.length===0?null:x(h,{className:`p-4`,children:[x(`div`,{className:`flex items-center gap-2 mb-3`,children:[k(le,{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:l.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??`?`}`:s.get(e.ruleId??``)??`A rule`}),e.global&&k(a,{variant:`warning`,className:`text-[10px]`,children:`everyone`}),!e.summary&&k(a,{variant:`default`,className:`text-[10px]`,children:`no summary`})]}),x(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`set by `,e.userId,` · `,zn(Rn(e,c))]})]}),k(o,{size:`sm`,variant:`outline`,disabled:i.isPending,onClick:()=>i.mutate(e.id),children:`End now`})]},e.id))})]})}b();var Vn=[`notificationRules`,`listRules`],Hn=[`notificationOutput`,`listTargets`,`forRules`],Un=[`notificationRules`,`getConditionCatalog`],Wn=[`deviceManager`,`listAll`,`forRules`],Gn=[`deviceManager`,`listAll`,`forRuleActions`],Kn=[`deviceManager`,`gateableDevices`],qn=A.options;function Jn(){let e=P(),[t,n]=D({mode:`closed`}),[r,i]=D(null),a=C({queryKey:Vn,queryFn:async()=>(await e.trpcClient.notificationRules.listRules.query({})).rules}),s=C({queryKey:Hn,queryFn:()=>e.trpcClient.notificationOutput.listTargets.query({})}),c=C({queryKey:Un,queryFn:()=>e.trpcClient.notificationRules.getConditionCatalog.query({})}),l=C({queryKey:Kn,queryFn:async()=>{let t=await e.trpcClient.deviceManager.listAll.query({}),n=[];for(let r of t){let t=ee(await e.trpcClient.deviceManager.loadRuntimeState.query({deviceId:r.id}),qn);t.length>0&&n.push({id:r.id,name:r.name,states:t})}return n},staleTime:6e4}),u=C({queryKey:Gn,queryFn:async()=>(await e.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}),f=C({queryKey:Wn,queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({})).filter(e=>e.type===N.Camera).map(e=>({id:e.id,name:e.name}))}),p=S(()=>{let e=new Map;for(let t of s.data??[])e.set(t.id,t.name);return e},[s.data]),m=O({mutationFn:t=>e.trpcClient.notificationRules.setRuleEnabled.mutate(t),onSuccess:()=>void a.refetch()}),g=O({mutationFn:t=>e.trpcClient.notificationRules.deleteRule.mutate({ruleId:t}),onSuccess:()=>{i(null),a.refetch()}}),v=a.data??[];return x(W,{icon:ue,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:x(o,{size:`sm`,type:`button`,onClick:()=>n({mode:`form`,rule:null}),children:[k(R,{className:`h-3.5 w-3.5`}),`New rule`]}),children:[k(Bn,{rules:v}),a.isLoading&&k(`div`,{className:`flex items-center justify-center py-16`,children:k(B,{className:`h-6 w-6 animate-spin text-primary`})}),a.isError&&!a.isLoading&&k(d,{title:`Failed to load rules`,message:a.error instanceof Error?a.error.message:`Unknown error`,onRetry:()=>void a.refetch()}),!a.isLoading&&!a.isError&&v.length===0&&k(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No notification rules yet. Click "New rule" to author one.`}),v.length>0&&k(h,{children:k(_,{columns:Yn({targetNameById:p,confirmDeleteId:r,deletePending:g.isPending,onToggle:(e,t)=>m.mutate({ruleId:e.id,enabled:t}),onEdit:e=>n({mode:`form`,rule:e}),onDuplicate:e=>n({mode:`form`,rule:{...e,id:``,name:`${e.name} (copy)`}}),onAskDelete:i,onConfirmDelete:e=>g.mutate(e.id)}),rows:v,rowKey:e=>e.id,minWidthPx:760,bordered:!1})}),t.mode===`form`&&k(Xn,{rule:t.rule,targets:s.data??[],actuatable:u.data??[],catalog:c.data?.catalog??[],taxonomy:c.data?.taxonomy,cameras:f.data??[],gateable:l.data??[],onCancel:()=>n({mode:`closed`}),onSaved:()=>{n({mode:`closed`}),a.refetch()}})]})}function Yn(e){return[{key:`name`,header:`Rule`,render:e=>x(`span`,{className:`flex items-center gap-2`,children:[k(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),!e.enabled&&k(a,{variant:`warning`,children:`disabled`})]})},{key:`trigger`,header:`Trigger`,nowrap:!0,render:e=>k(`span`,{className:`text-[11px] text-foreground-subtle`,children:At(e.delivery)})},{key:`targets`,header:`Targets`,render:t=>{let n=t.targets[0],r=n?e.targetNameById.get(n.targetId)??n.targetId:null;return k(`span`,{className:`text-[11px] text-foreground-subtle`,children:t.targets.length===1&&r?r:`${t.targets.length} target${t.targets.length===1?``:`s`}`})}},{key:`priority`,header:`Priority`,align:`center`,nowrap:!0,render:e=>k(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.priority})},{key:`enabled`,header:`On`,align:`center`,nowrap:!0,render:t=>k(s,{checked:t.enabled,onCheckedChange:n=>e.onToggle(t,n),"aria-label":`toggle ${t.name}`})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:t=>x(`span`,{className:`flex items-center justify-end gap-1`,children:[k(o,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onEdit(t),title:`Edit`,children:k(L,{className:`h-3.5 w-3.5`})}),k(o,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onDuplicate(t),title:`Duplicate`,children:k(I,{className:`h-3.5 w-3.5`})}),e.confirmDeleteId===t.id?x(w,{children:[x(o,{size:`sm`,variant:`danger`,type:`button`,disabled:e.deletePending,onClick:()=>e.onConfirmDelete(t),children:[e.deletePending&&k(B,{className:`h-3.5 w-3.5 animate-spin`}),`Confirm`]}),k(o,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onAskDelete(null),children:`Cancel`})]}):k(o,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onAskDelete(t.id),title:`Delete`,children:k(H,{className:`h-3.5 w-3.5 text-danger`})})]})}]}function Xn({rule:e,targets:r,catalog:i,taxonomy:c,cameras:u,gateable:d,actuatable:f,onSaved:h,onCancel:_}){let b=P(),S=e!=null&&e.id.length>0,[w,T]=D(()=>e?Gt(e):Wt()),[E,A]=D(null),[ee,j]=D(null),[M,te]=D(rn),N=e=>T(t=>({...t,...e})),F=S&&e?{throttle:e.throttle}:void 0,I=O({mutationFn:async()=>{let t=Qt(w,F,i);S&&e?await b.trpcClient.notificationRules.updateRule.mutate({ruleId:e.id,patch:t}):await b.trpcClient.notificationRules.createRule.mutate({rule:t})},onSuccess:h,onError:e=>A(e instanceof Error?e.message:`Save failed`)}),L=O({mutationFn:async()=>{let e=Qt(w,F,i);return(await b.trpcClient.notificationRules.testRule.mutate({rule:e,lookbackMinutes:60})).results},onMutate:()=>j(null),onSuccess:e=>j(e),onError:e=>A(e instanceof Error?e.message:`Test failed`)}),R=w.targetIds.map(e=>r.find(t=>t.id===e)?.name??e),ne=e=>N({targetIds:w.targetIds.includes(e)?w.targetIds.filter(t=>t!==e):[...w.targetIds,e]}),z=C({queryKey:[`userManagement`,`listUsers`],queryFn:()=>b.trpcClient.userManagement.listUsers.query()}).data,re=e=>N({targetUsers:w.targetUsers.includes(e)?w.targetUsers.filter(t=>t!==e):[...w.targetUsers,e]}),V=$.find(e=>e.value===w.delivery)?.hint;return k(l,{open:!0,onOpenChange:e=>!e&&_(),children:x(n,{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(ue,{className:`h-4 w-4 text-foreground-subtle`}),S?`Edit ${e?.name}`:`New notification rule`]}),k(o,{size:`sm`,variant:`ghost`,type:`button`,onClick:_,children:`Cancel`})]}),E&&k(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger mb-3`,children:E}),x(p,{value:M,onValueChange:e=>te(an(e)??M),children:[k(v,{className:`mb-3`,children:nn.map(e=>k(m,{value:e.key,children:e.label},e.key))}),x(y,{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(t,{value:w.name,onChange:e=>N({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(s,{checked:w.enabled,onCheckedChange:e=>N({enabled:e}),"aria-label":`enabled`}),`Enabled`]})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Trigger`}),k(g,{value:w.delivery,onChange:e=>{let t=jt(e.target.value);t&&N({delivery:t})},options:$.map(e=>({value:e.value,label:e.label}))}),V&&k(`p`,{className:`text-[10px] text-foreground-subtle mt-1`,children:V})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Delivery targets`}),r.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:r.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:w.targetIds.includes(e.id),onChange:()=>ne(e.id),className:`accent-primary`}),k(`span`,{className:`flex-1 truncate`,children:e.name}),!e.enabled&&k(a,{variant:`warning`,children:`disabled`})]},e.id))})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Notify users`}),(z??[]).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:(z??[]).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:w.targetUsers.includes(e.id),onChange:()=>re(e.id),className:`accent-primary`}),k(`span`,{className:`flex-1 truncate`,children:e.username}),e.isAdmin&&k(a,{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(y,{value:`devices`,className:`space-y-4`,children:k(ct,{devices:f,value:w.deviceIds,onChange:e=>N({deviceIds:e}),loading:f.length===0})}),k(y,{value:`actions`,className:`space-y-4`,children:k(Xe,{value:w.actions,onChange:e=>N({actions:e}),devices:f})}),k(y,{value:`advanced`,className:`space-y-4`,children:x(`div`,{children:[x(`label`,{className:`flex items-center gap-2 text-[11px] font-medium text-foreground`,children:[k(s,{checked:w.snoozeAllowGlobal,onCheckedChange:e=>N({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(y,{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(g,{value:String(w.priority),onChange:e=>N({priority:Number(e.target.value)}),options:Ut.map(e=>({value:String(e.value),label:e.label}))})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Media attachment`}),k(g,{value:w.mediaAttach,onChange:e=>{let t=Nt(e.target.value);t&&N({mediaAttach:t})},options:Mt.map(e=>({value:e.value,label:e.label}))}),k(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:Mt.find(e=>e.value===w.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:w.mediaZoneCrop,onChange:e=>N({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:w.mediaGif,onChange:e=>N({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:w.mediaClip,onChange:e=>N({mediaClip:e.target.checked}),className:`accent-primary`}),`Attach an MP4 clip around the event`]})]}),(w.mediaGif||w.mediaClip)&&x(`div`,{className:`mt-2`,children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Video quality`}),k(g,{value:w.mediaProfile??``,onChange:e=>N({mediaProfile:Lt(e.target.value)}),options:It.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(g,{value:w.mediaClipSpeed===void 0?``:String(w.mediaClipSpeed),onChange:e=>N({mediaClipSpeed: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 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.`})]})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Image frame`}),k(g,{value:w.mediaFrame??``,onChange:e=>N({mediaFrame:Ft(e.target.value)}),options:Pt.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(t,{value:w.templateTitle,onChange:e=>N({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:w.templateBody,onChange:e=>N({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(y,{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:`Conditions`}),i.length===0?k(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Condition catalog unavailable — this rule matches on its trigger and targets alone.`}):k(On,{catalog:i,taxonomy:c,delivery:w.delivery,conditions:w.conditions,schedule:w.schedule,cameras:u,gateable:d,onConditionsChange:e=>N({conditions:e}),onScheduleChange:e=>N({schedule:e})})]}),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(o,{size:`sm`,variant:`outline`,type:`button`,disabled:L.isPending||!Kt(w),onClick:()=>{A(null),L.mutate()},children:[L.isPending?k(B,{className:`h-3.5 w-3.5 animate-spin`}):k(de,{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(Zn,{delivery:w.delivery,results:ee,targetNames:R})]})]})]}),x(`div`,{className:`flex justify-end gap-2 mt-4`,children:[k(o,{variant:`secondary`,size:`sm`,type:`button`,onClick:_,children:`Cancel`}),x(o,{size:`sm`,type:`button`,disabled:I.isPending||!Kt(w),onClick:()=>{A(null),I.mutate()},children:[I.isPending&&k(B,{className:`h-3.5 w-3.5 animate-spin`}),S?`Save changes`:`Create rule`]})]})]})})}function Zn({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(F,{className:`h-3.5 w-3.5 shrink-0 text-success`}):k(ae,{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 Qn=[{value:1,label:`Last hour`},{value:24,label:`Last 24 hours`},{value:168,label:`Last 7 days`},{value:0,label:`All time`}],$n=[{value:``,label:`Any status`},{value:`pending`,label:`Pending`},{value:`sent`,label:`Sent`},{value:`dead`,label:`Dead`}],er=[50,100,250,500];function tr(){return{ruleId:``,deviceId:``,status:``,windowHours:24,limit:100}}function nr(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 ir(){let e=P(),[t,n]=D(tr),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===N.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)}:{},...nr(t.status)?{status:nr(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(W,{icon:fe,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(g,{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(g,{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(g,{value:t.status,onChange:e=>r({status:e.target.value}),options:$n.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(g,{value:String(t.windowHours),onChange:e=>r({windowHours:Number(e.target.value)}),options:Qn.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(g,{value:String(t.limit),onChange:e=>r({limit:Number(e.target.value)}),options:er.map(e=>({value:String(e),label:String(e)}))})]})]}),s.isLoading&&k(`div`,{className:`flex items-center justify-center py-16`,children:k(B,{className:`h-6 w-6 animate-spin text-primary`})}),d&&!s.isLoading&&k(h,{children:x(`div`,{className:`flex flex-col items-center gap-2 px-4 py-14 text-center`,children:[k(fe,{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(ne,{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(h,{children:k(_,{columns:ar(l),rows:u,rowKey:e=>e.id,minWidthPx:720,bordered:!1})})]})}function ar(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(a,{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 or={home:`Home`,away:`Away`,night:`Night`,vacation:`Vacation`,custom_bypass:`Custom`};function sr(e){return or[e]??e}function cr(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 lr(e,t){return e.ruleCount===0?`Arms nothing — no enabled rule is gated on this mode.`:e.allDevices?`Every device — ${dr(e.ruleCount,`rule`)} with no device scope.`:e.deviceIds.length===0?`${dr(e.ruleCount,`rule`)}, no device restriction.`:e.deviceIds.map(e=>t.get(e)??`Device ${e}`).join(`, `)}function ur(e){return e.ruleCount===0}function dr(e,t){return e===1?`1 ${t}`:`${e} ${t}s`}function fr(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 pr=[`notificationRules`,`getAlarmConfig`],mr=[`notificationOutput`,`listTargets`],hr=[`deviceManager`,`listAll`,`alarm-coverage`],gr=600,_r=3600;function vr({label:e,hint:n,value:r,max:i,zeroMeans:a,disabled:o,onCommit:s}){let[c,l]=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(t,{type:`number`,min:0,max:i,value:c??String(r),disabled:o,onChange:e=>l(e.target.value),onBlur:()=>{let e=c===null?null:fr(c,i);l(null),e!==null&&e!==r&&s(e)},className:`w-28`,"data-testid":`alarm-delay-${e.toLowerCase().replace(/\s+/g,`-`)}`}),k(`span`,{className:`text-sm text-foreground-subtle`,children:cr(r,a)})]}),k(`p`,{className:`text-xs text-foreground-subtle`,children:n})]})}function yr(){let e=P(),t=E(),n=C({queryKey:pr,queryFn:async()=>e.trpcClient.notificationRules.getAlarmConfig.query({})}),r=C({queryKey:mr,queryFn:async()=>(await e.trpcClient.notificationOutput.listTargets.query({})).map(e=>({id:e.id,name:e.name,enabled:e.enabled}))}),i=C({queryKey:hr,queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({projection:`slim`})).map(e=>({id:e.id,name:e.name}))}),o=O({mutationFn:t=>e.trpcClient.notificationRules.setAlarmConfig.mutate({patch:t}),onSuccess:()=>t.invalidateQueries({queryKey:pr})}),c=S(()=>{let e=new Map;for(let t of i.data??[])e.set(t.id,t.name);return e},[i.data]);if(n.isLoading)return k(W,{icon:U,title:`Alarm`,subtitle:`Panel delays and mode coverage.`,children:k(B,{className:`h-5 w-5 animate-spin`})});let l=n.data;if(l===void 0||n.isError)return k(W,{icon:U,title:`Alarm`,subtitle:`Panel delays and mode coverage.`,children:k(d,{title:`Alarm settings are not available`,message:`This hub has not been updated to serve the alarm configuration yet.`})});if(l.deviceId===null)return k(W,{icon:U,title:`Alarm`,subtitle:`Panel delays and mode coverage.`,children:k(h,{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 u=l.settings,f=o.isPending,p=r.data??[],m=u.announceTargets,g=e=>{o.mutate(e)},_=e=>{g({announceTargets:m.includes(e)?m.filter(t=>t!==e):[...m,e]})};return k(W,{icon:U,title:`Alarm`,subtitle:`Panel delays, and what each mode actually arms.`,children:x(`div`,{className:`flex flex-col gap-4`,children:[o.isError?k(d,{title:`Could not save`,message:String(o.error)}):null,x(h,{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(vr,{label:`Exit delay`,hint:`Time between arming and the mode taking effect — long enough to leave.`,value:u.exitDelaySec,max:gr,zeroMeans:`arms immediately`,disabled:f,onCommit:e=>g({exitDelaySec:e})}),k(vr,{label:`Entry delay`,hint:`Time between a trigger and the alarm firing — long enough to reach the keypad.`,value:u.entryDelaySec,max:gr,zeroMeans:`fires immediately`,disabled:f,onCommit:e=>g({entryDelaySec:e})}),k(vr,{label:`Triggered for`,hint:`How long the alarm stays triggered before re-arming itself.`,value:u.triggeredDurationSec,max:_r,zeroMeans:`until disarmed`,disabled:f,onCommit:e=>g({triggeredDurationSec:e})})]})]}),x(h,{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(s,{checked:u.announceArm,disabled:f,onCheckedChange:e=>g({announceArm:e}),"data-testid":`alarm-announce-toggle`})]}),u.announceArm?x(`div`,{className:`mt-3 flex flex-col gap-2`,children:[p.length===0?k(`p`,{className:`text-xs text-foreground-subtle`,children:`No notification targets are configured — nothing can be sent.`}):p.map(e=>x(`label`,{className:`flex items-center gap-2 text-sm`,children:[k(`input`,{type:`checkbox`,checked:m.includes(e.id),disabled:f,onChange:()=>_(e.id),"data-testid":`alarm-target-${e.id}`}),k(`span`,{children:e.name}),e.enabled?null:k(a,{variant:`warning`,children:`disabled`})]},e.id)),m.length===0?k(`p`,{className:`text-xs text-warning`,children:`No target selected — the announcement will not be sent.`}):null]}):null]}),x(h,{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:l.coverage.map(e=>x(`div`,{className:`flex items-start gap-3 rounded border border-border p-2`,"data-mode":e.mode,"data-empty":ur(e)?`true`:`false`,children:[k(`div`,{className:`w-20 shrink-0 text-sm font-medium`,children:sr(e.mode)}),k(`div`,{className:`flex-1 text-sm text-foreground-subtle`,children:lr(e,c)}),ur(e)?k(se,{className:`h-4 w-4 shrink-0 text-warning`}):null]},e.mode))})]})]})})}function br(){return k(`div`,{className:`flex flex-col p-4`,children:k(ce,{tabs:[{id:`targets`,label:`Targets`,icon:ie,content:k(ze,{})},{id:`rules`,label:`Rules`,icon:ue,content:k(Jn,{})},{id:`history`,label:`History`,icon:fe,content:k(ir,{})},{id:`alarm`,label:`Alarm`,icon:U,content:k(yr,{})}]})})}export{br as NotificationsPage,br as default};
|