@camstack/addon-admin-ui 1.2.420 → 1.2.421
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/{AddonAssetIcon-CUwwTa-R.js → AddonAssetIcon-BcUAeUFA.js} +1 -1
- package/dist/assets/{Addons-BxDL_z8K.js → Addons-CMFKnFy_.js} +1 -1
- package/dist/assets/{AdminPage-CeuyYsCA.js → AdminPage-Pnx0mTsE.js} +1 -1
- package/dist/assets/{AdminSectionedPage-DTUh9Cod.js → AdminSectionedPage-Cwqk3VSC.js} +1 -1
- package/dist/assets/{AiProfiles-y6zIS3pT.js → AiProfiles-Cm-uW0cp.js} +1 -1
- package/dist/assets/{BrokerForm-_lvmLM2q.js → BrokerForm-C29qpKHz.js} +1 -1
- package/dist/assets/{Build-D1UFnKKy.js → Build-jtQNSTVm.js} +1 -1
- package/dist/assets/{Calendars-DIf4uwcB.js → Calendars-DXVrSwsu.js} +1 -1
- package/dist/assets/{Cluster-CDw7Cr8z.js → Cluster-Dt4QC5gH.js} +1 -1
- package/dist/assets/{ClusterStepModel-zcaZRIvK.js → ClusterStepModel-nVqIETDq.js} +1 -1
- package/dist/assets/{CompositionEditor-BWpcmpg6.js → CompositionEditor-CWfZxpvY.js} +1 -1
- package/dist/assets/{CompositionEditorPage-CDMHjuJR.js → CompositionEditorPage-D2_5GID5.js} +1 -1
- package/dist/assets/{Data-DYDabIHg.js → Data-PX9MYiMq.js} +1 -1
- package/dist/assets/{DeviceDetail-GGBbMdyL.js → DeviceDetail-CvBViCpU.js} +1 -1
- package/dist/assets/{DeviceDoActionFields-CRdtYlvP.js → DeviceDoActionFields-Vpw3Hlks.js} +1 -1
- package/dist/assets/{Devices-CyiSENRc.js → Devices-NE3Jk6_G.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-CB66n6Ce.js → EmbedPlayerPage-o6tk8CLI.js} +1 -1
- package/dist/assets/{Identity-C7nTQ5HW.js → Identity-DvZevqOL.js} +1 -1
- package/dist/assets/{IntegrationDetail-C7V2Lw2t.js → IntegrationDetail-pyZVXw9L.js} +1 -1
- package/dist/assets/{IntegrationHub-I34k6eMx.js → IntegrationHub-C--iFSMN.js} +1 -1
- package/dist/assets/{Integrations-Btt92q19.js → Integrations-B8URUnQX.js} +1 -1
- package/dist/assets/{Integrations-DtRziEii.js → Integrations-Cadxh0XR.js} +1 -1
- package/dist/assets/{Library-CmIVJCQ-.js → Library-DHn4yJN3.js} +1 -1
- package/dist/assets/{Locations-CMXlnF3m.js → Locations-CMXm68gm.js} +1 -1
- package/dist/assets/{Logs-BzzOnW8m.js → Logs-Bg5PD7yc.js} +1 -1
- package/dist/assets/{MyAccess-DsKtQazv.js → MyAccess-BvJqlxVR.js} +1 -1
- package/dist/assets/{Network-B8KllZ1y.js → Network-Cq6PVeH5.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-B69iZTJL.js → NodeAddonsSettingsPanel-BK1RxciP.js} +1 -1
- package/dist/assets/{Notifications-3e9mrTSh.js → Notifications-Cwp9_it6.js} +1 -1
- package/dist/assets/{Recordings-C1GA_K_d.js → Recordings-ZhXXvJqY.js} +1 -1
- package/dist/assets/{ScanNetworkModal-CZD2XMwr.js → ScanNetworkModal-_RdncTUH.js} +1 -1
- package/dist/assets/{SessionsList-BsZ4138t.js → SessionsList-Dm6Me6Pk.js} +1 -1
- package/dist/assets/{Showroom-B84zCph9.js → Showroom-B6NjRCzE.js} +1 -1
- package/dist/assets/{System-Bs16FRnw.js → System-Q5wNMpYV.js} +1 -1
- package/dist/assets/{Terminal-Dtpd7dA2.js → Terminal-Bq2YkQer.js} +1 -1
- package/dist/assets/{Viewer-5St3Etot.js → Viewer-CA-_IKP2.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-fgk3R2YA.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DxkHv0jA.js} +1 -1
- package/dist/assets/{addon-icons-context-DGSjQzW5.js → addon-icons-context-BcFthDce.js} +1 -1
- package/dist/assets/{authed-media-wMr1ui8w.js → authed-media-B1N-Y_02.js} +1 -1
- package/dist/assets/{device-integration-icon-DNbEWHFM.js → device-integration-icon-CgVkQy_G.js} +1 -1
- package/dist/assets/device-picker-model-C-bu65w9.js +1 -0
- package/dist/assets/{hostInit-BSsVPy9C.js → hostInit-CU4FJ_9p.js} +1 -1
- package/dist/assets/{index-Xr95RVN2.js → index-AsTGrKva.js} +3 -3
- package/dist/assets/{location-owned-usage-DLdsU-mZ.js → location-owned-usage-C7aYDcAR.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-e96bc771.js → mf-entry-bootstrap-0-c3f6e5ea.js} +2 -2
- package/dist/assets/mount-C-bu65w9.js +1 -0
- package/dist/assets/{notification-schedule-field-DyI7heJv.js → notification-schedule-field-Dy4ByDYy.js} +1 -1
- package/dist/assets/remoteEntry-9Elsv3BT.js +1 -0
- package/dist/assets/{src-Bqr9lpc6.js → src-CIIJy_o8.js} +1 -1
- package/dist/assets/{use-scenes-feed-BD8OoH8Z.js → use-scenes-feed-DxSvhMQ5.js} +1 -1
- package/dist/assets/{use-stationary-objects-CaqT07d1.js → use-stationary-objects-BllXyUsy.js} +1 -1
- package/dist/assets/useEventInvalidation-C-bu65w9.js +1 -0
- package/dist/assets/{useNodeUrlSelection-DqPmoZO2.js → useNodeUrlSelection-DNAtiVHu.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Dd8x1dBQ.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-LWvJP_B9.js} +2 -2
- package/dist/index.html +6 -6
- package/dist/server/addon.js +1 -1
- package/package.json +1 -1
- package/dist/assets/device-picker-model-y0YT4n_j.js +0 -1
- package/dist/assets/mount-y0YT4n_j.js +0 -1
- package/dist/assets/remoteEntry-ClveP_Ct.js +0 -1
- package/dist/assets/useEventInvalidation-y0YT4n_j.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,Q as t,S as n,W as r,o as i,q as a,x as o,z as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{D as c,It as l,Lr as u,On as d,Pn as f,Tn as p,_i as m,ar as h,dt as g,ot as _,yi as v,yr as y}from"./player-overlays-C20AJTgs.js";import{t as b}from"./archive-4K83r_1n.js";import{t as x}from"./eraser-Bgk8Dzm-.js";import{t as S}from"./hard-drive-download-Cf7DR1zn.js";import{ii as C}from"./client-CKGZv6zJ.js";import{An as w,Bn as T,Dn as ee,En as te,Hc as ne,Tn as re,U as E,Vt as D,Zn as O,el as ie,jn as ae,kn as k,yr as A}from"./src-Bqr9lpc6.js";import{I as oe}from"./index-Xr95RVN2.js";import{t as j}from"./format-size-DIxKXxtj.js";t();function M(e){let t=e.trim().toLowerCase();return t.length===0?``:t.replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function N(e,t){let n=M(t);return`${e}:${n.length>0?n:`default`}`}var P=new Set([`proc`,`sys`,`dev`,`run`,`boot`,`lost+found`,`snap`,`bin`,`sbin`,`lib`,`lib32`,`lib64`,`libx32`,`usr`,`etc`,`var`,`opt`,`tmp`,`srv`,`root`,`System`,`Library`,`Applications`,`cores`,`private`]),F=[`recordings`,`data`,`mnt`,`media`,`Volumes`];function I(e){let t=F.findIndex(t=>t===`recordings`?e.startsWith(t):e===t);return t===-1?F.length:t}function se(e){return e.filter(e=>!e.name.startsWith(`.`)&&!P.has(e.name)).toSorted((e,t)=>{let n=I(e.name)-I(t.name);return n===0?e.name.localeCompare(t.name):n}).map(e=>e.path)}function ce({nodeId:t,value:r,onChange:i}){let c=_().trpcClient,[l,u]=a([]),[d,f]=a(r),[p,m]=a(null),[h,g]=a(null),[v,y]=a(``),b=e(async(e,n)=>{g(null);try{let r=await c.filesystemBrowse.browse.query({nodeId:t,path:e});m(r),f(r.path),n&&i(r.path)}catch(e){g(e instanceof Error?e.message:`browse failed`)}},[c,t,i]);s(()=>{f(r),(async()=>{let e=await c.filesystemBrowse.browse.query({nodeId:t,path:`/`}).then(e=>e).catch(()=>null);if(e){u(se(e.entries)),await b(r.startsWith(`/`)?r:`/`,!1);return}try{let e=await c.filesystemBrowse.listAllowedRoots.query({nodeId:t});u(e),await b(r&&e.some(e=>r.startsWith(e))?r:e[0]??``,!1)}catch(e){u([]),m(null),g(e instanceof Error&&/not available on node/i.test(e.message)?`This node can't be browsed remotely. Enter the path manually.`:e instanceof Error?e.message:`browse unavailable`)}})()},[t]);let x=async()=>{if(!(!v.trim()||!p)){g(null);try{let e=`${p.path.replace(/\/+$/,``)}/${v.trim()}`;await c.filesystemBrowse.createDir.mutate({nodeId:t,path:e}),y(``),await b(p.path,!0)}catch(e){g(e instanceof Error?e.message:`create failed`)}}},S=e=>`${(e/1e9).toFixed(1)} GB`;return n(`div`,{className:`space-y-2 rounded border border-border p-2`,children:[o(`div`,{className:`flex flex-wrap gap-1`,children:l.map(e=>o(`button`,{onClick:()=>void b(e,!0),className:`rounded border border-border px-2 py-0.5 text-[10px] font-mono hover:border-primary/40`,children:e},e))}),o(`input`,{value:d,onChange:e=>{f(e.target.value),i(e.target.value)},placeholder:`/absolute/path`,className:`w-full rounded border border-border bg-background px-2 py-1 text-[11px] font-mono`}),p&&n(`div`,{className:`text-[10px] text-foreground-subtle`,children:[S(p.freeBytes),` free / `,S(p.totalBytes)]}),o(`div`,{className:`max-h-40 space-y-0.5 overflow-y-auto`,children:p?.entries.map(e=>n(`button`,{onClick:()=>void b(e.path,!0),className:`block w-full truncate rounded px-2 py-1 text-left text-xs hover:bg-primary/5`,children:[`📁 `,e.name]},e.path))}),n(`div`,{className:`flex gap-1`,children:[o(`input`,{value:v,onChange:e=>y(e.target.value),placeholder:`new folder`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs`}),o(`button`,{onClick:()=>void x(),className:`rounded border border-border px-2 py-1 text-xs hover:border-primary/40`,children:`Create`})]}),h&&o(`div`,{className:`text-[10px] text-red-400`,children:h})]})}t();function L({initialType:e,onClose:t,onCreated:s}){let c=i(),l=_().trpcClient,[u,d]=a(`picker`),[f,p]=a(e),[g,v]=a(null),[y,b]=a({}),[x,S]=a(``),[C,T]=a(null),[D,O]=a(!1),[k,A]=a(`hub`),[j,M]=a(null),[P,F]=a(!1),I=e=>b(t=>({...t,basePath:e})),se=typeof y.basePath==`string`?y.basePath:``,L=ne(),R=r(()=>{let e=L.data;return Array.isArray(e)?e:[]},[L.data]),z=L.isLoading,B=ie({onSuccess:()=>{c.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),s()}}),V=r(()=>C!==null&&C.length>0?C:N(f,x),[f,x,C]),le=async()=>{if(g){F(!0),M(null);try{M(await(e=>l.storage.testConfig.query(e))({providerId:g.providerId,config:y}))}catch(e){M({ok:!1,error:e instanceof Error?e.message:String(e)})}finally{F(!1)}}};return o(re,{open:!0,onOpenChange:e=>!e&&t(),children:n(ee,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[n(w,{children:[o(ae,{children:{picker:`Add Location — Pick provider`,config:`Add Location — ${g?.displayName??``}`,naming:`Add Location — Name`}[u]}),n(`p`,{className:`text-xs text-foreground-subtle`,children:[`Type: `,o(`span`,{className:`font-mono`,children:f})]})]}),n(te,{children:[u===`picker`&&n(`div`,{className:`space-y-2`,children:[z&&o(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading providers…`}),!z&&R.length===0&&n(`div`,{className:`rounded border border-border bg-background px-3 py-4 text-center text-xs text-foreground-subtle`,children:[`No storage-provider supports type "`,f,`". Install a compatible addon (e.g.`,` `,o(`code`,{className:`font-mono`,children:`remote-storage`}),`) to enable it.`]}),R.map(e=>n(`button`,{onClick:()=>{v(e),d(`config`)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-background p-3 text-left hover:border-primary/40 hover:bg-primary/5 transition-colors`,children:[n(`div`,{className:`flex-1 min-w-0`,children:[o(`p`,{className:`text-xs font-semibold text-foreground`,children:e.displayName}),o(`p`,{className:`text-[10px] text-foreground-subtle font-mono mt-0.5 truncate`,children:e.providerId})]}),o(m,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},e.providerId))]}),u===`config`&&g&&n(`div`,{className:`space-y-3`,children:[o(oe,{schema:g.configSchema,values:y,onChange:b}),g.nodeLocal&&n(`div`,{className:`space-y-2`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Node`}),o(E,{selectedNodeId:k,onSelect:A,alwaysShow:!0}),o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Path`}),o(ce,{nodeId:k,value:se,onChange:I})]}),j&&o(`div`,{className:`rounded border px-3 py-2 text-[11px] ${j.ok?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:j.ok?`Connection OK.`:`Test failed: ${j.error??`unknown error`}`}),n(`div`,{className:`flex items-center justify-between pt-1`,children:[o(`button`,{onClick:()=>d(`picker`),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Back`}),n(`div`,{className:`flex items-center gap-2`,children:[o(`button`,{onClick:()=>{le()},disabled:P,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10 disabled:opacity-50`,children:P?`Testing…`:`Test connection`}),o(`button`,{onClick:()=>d(`naming`),className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Next`})]})]})]}),u===`naming`&&g&&n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Display name`}),o(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),placeholder:`${f} on ${g.displayName}`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),n(`div`,{className:`space-y-1`,children:[n(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:[`Id`,` `,o(`span`,{className:`lowercase tracking-normal text-foreground-subtle`,children:`— auto-derived; override if needed`})]}),o(`input`,{type:`text`,value:V,onChange:e=>T(e.target.value),placeholder:N(f,x),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground font-mono focus:outline-none focus:ring-1 focus:ring-primary`}),n(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,o(`code`,{className:`font-mono`,children:`<type>:<slug>`}),`. Lowercase letters, digits, and hyphens only.`]})]}),n(`label`,{className:`flex items-start gap-2 rounded border border-border bg-background px-3 py-2 cursor-pointer hover:bg-primary/5`,children:[o(`input`,{type:`checkbox`,checked:D,onChange:e=>O(e.target.checked),className:`accent-primary mt-0.5`}),n(`div`,{className:`space-y-0.5`,children:[o(`div`,{className:`text-xs font-medium text-foreground`,children:`Enable immediately`}),o(`div`,{className:`text-[10px] text-foreground-subtle`,children:`A disabled location receives no writes until enabled — reads and age-based retention still work, nothing new lands here. Leave this off to register the disk now and start using it later.`})]})]}),B.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:B.error instanceof Error?B.error.message:String(B.error)}),n(`div`,{className:`flex items-center justify-between pt-1`,children:[o(`button`,{onClick:()=>d(`config`),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Back`}),n(`div`,{className:`flex items-center gap-2`,children:[o(`button`,{onClick:()=>{p(e),v(null),b({}),S(``),T(null),O(!1),M(null),d(`picker`)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Reset`}),n(`button`,{onClick:()=>{g&&B.mutate({id:V,type:f,displayName:x.trim(),providerId:g.providerId,config:y,enabled:D,nodeId:g.nodeLocal?k:void 0})},disabled:B.isPending||x.trim().length===0,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:[B.isPending?o(h,{className:`h-3.5 w-3.5 animate-spin`}):null,B.isPending?`Saving…`:`Save`]})]})]})]})]})]})})}function R(e){return C(e)}function z(e){return e===`active`}var B=[{mode:`active`,label:`Active`,consequence:`New data is written here, and the oldest is deleted when the disk fills up.`,requiresConfirmation:!1},{mode:`readonly`,label:`Read-only`,consequence:`Nothing new is written and nothing is ever deleted. A frozen archive that stays on the timeline.`,requiresConfirmation:!1},{mode:`drain`,label:`Drain`,consequence:`Nothing new is written. The oldest data here is deleted, a little at a time, until this location is empty.`,requiresConfirmation:!1},{mode:`disabled`,label:`Disabled`,consequence:`Nothing is written and nothing is read: the footage stored here disappears from the timeline until you turn it back on. Nothing is deleted.`,requiresConfirmation:!0}];function V(e){return B.find(t=>t.mode===e)??B[0]}function le(e){return V(e).requiresConfirmation}var ue=`Blocked: this is the last location of its type still accepting writes — new data would have nowhere to go.`;function H(e,t,n){return z(n)||!z(R(e))||t.some(t=>t.id!==e.id&&z(R(t)))?{blocked:!1,reason:``}:{blocked:!0,reason:ue}}function de(e,t){return{active:H(e,t,`active`).reason,readonly:H(e,t,`readonly`).reason,drain:H(e,t,`drain`).reason,disabled:H(e,t,`disabled`).reason}}function fe(e,t,n){return!(n===`single`||t.length<=1||z(R(e))&&t.filter(e=>z(R(e))).length<=1)}function U(e){return e===`active`?{enabled:!0,readOnly:!1}:e===`readonly`?{enabled:!1,readOnly:!1}:{enabled:!1,readOnly:!0}}function pe(e,t){let n={...t.config??e.config};t.mode!==void 0&&(U(t.mode).readOnly?n.readOnly=!0:delete n.readOnly);let r={id:e.id,type:e.type,displayName:t.displayName??e.displayName,providerId:e.providerId,config:n,isSystem:e.isSystem},i=t.nodeId??e.nodeId,a=i===void 0?r:{...r,nodeId:i};return t.mode===void 0?e.enabled===void 0?a:{...a,enabled:e.enabled}:{...a,mode:t.mode,enabled:U(t.mode).enabled}}var me=1024**3;function W(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function he(e){let t=W(e.minFreeGb);if(t!==null)return{unit:`gb`,value:t};let n=W(e.minFreePercent);return n===null?{unit:`percent`,value:null}:{unit:`percent`,value:n}}function ge(e,t){return W(e[t===`gb`?`minFreeGb`:`minFreePercent`])}function _e(e,t){let n={...e};return delete n.minFreePercent,delete n.minFreeGb,t.value===null?n:t.unit===`gb`?{...n,minFreeGb:t.value}:{...n,minFreePercent:t.value}}function ve(e,t){let n=e.trim();if(n===``)return null;let r=Number(n);return Number.isFinite(r)?t===`percent`?Math.min(100,Math.max(0,r)):Math.max(0,r):null}function ye(e,t,n=10){if(e.unit===`gb`&&e.value!==null)return e.value*me;let r=e.value??n;return t===null||t<=0?null:t*Math.min(100,Math.max(0,r))/100}function be(e){return e===`gb`?`GB to keep free`:`% of the volume to keep free`}function xe(e,t=10){return`CamStack keeps ${e.value===null?`${String(t)}% of the volume (the default)`:e.unit===`gb`?`${String(e.value)} GB`:`${String(e.value)}% of the volume`} free on this disk. As it fills up, the OLDEST data stored here is deleted to hold that much free space; if it cannot be held any more, new data goes to another location of the same type instead of filling the disk. Leave the value empty for the default (${String(t)}%).`}function Se(e){return W(e.maxUsedGb)}function Ce(e,t){let n=W(e.maxUsedGb);return n===null||n<0?null:{bytes:n*me,reason:t===`drain`?`drain`:`legacy`}}t();function we({config:e,defaultPercent:t=10,onChange:r}){let[i,s]=a(()=>he(e).unit),c=ge(e,i),l={unit:i,value:c},u=Se(e),d=t=>{s(t),r(_e(e,{unit:t,value:null}))},f=t=>{r(_e(e,{unit:i,value:ve(t,i)}))};return n(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Protected free space`}),n(`div`,{className:`flex items-center gap-2`,children:[n(`select`,{"aria-label":`Protection unit`,value:i,onChange:e=>{d(e.target.value===`gb`?`gb`:`percent`)},className:`rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:[o(`option`,{value:`percent`,children:`% of the volume`}),o(`option`,{value:`gb`,children:`GB of free space`})]}),o(`input`,{type:`number`,"aria-label":be(i),min:0,max:i===`percent`?100:void 0,value:c===null?``:c,placeholder:i===`percent`?String(t):`default`,onChange:e=>{f(e.target.value)},className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),o(`p`,{className:`text-[10px] text-foreground-subtle`,children:xe(l,t)}),u!==null&&n(`p`,{className:`text-[10px] text-foreground-subtle italic`,children:[`This location also stores a maximum used size of `,u,` GB. That limit is managed by the system now and is no longer editable here; it is kept as it is.`]})]})}t();function Te({location:e,onClose:t,onSaved:s}){let c=i(),l=_().trpcClient,[u,d]=a({...e.config}),[f,p]=a(e.displayName),[m,g]=a(null),[v,y]=a(!1),b=ne(),x=r(()=>{let t=b.data;return Array.isArray(t)?t.find(t=>t.providerId===e.providerId)??null:null},[b.data,e.providerId]),S=ie({onSuccess:()=>{c.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),s()}}),C=x?.shouldSaveDiskSpace===!0,D=x?.nodeLocal===!0,[O,A]=a(typeof e.nodeId==`string`?e.nodeId:`hub`),j=typeof u.basePath==`string`?u.basePath:``,M=e=>d(t=>({...t,basePath:e})),N=x?.minFreePercent??10,P=async()=>{y(!0),g(null);try{g(await(e=>l.storage.testConfig.query(e))({providerId:e.providerId,locationId:e.id,config:u}))}catch(e){g({ok:!1,error:e instanceof Error?e.message:String(e)})}finally{y(!1)}};return o(re,{open:!0,onOpenChange:e=>!e&&t(),children:n(ee,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[n(w,{children:[n(ae,{children:[`Edit `,e.displayName]}),n(`p`,{className:`text-xs text-foreground-subtle`,children:[o(`span`,{className:`font-mono`,children:e.id}),` ·`,` `,x?.displayName??e.providerId]})]}),n(te,{className:`space-y-3`,children:[n(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Display name`}),o(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),x&&o(oe,{schema:x.configSchema,values:u,onChange:d}),D&&n(`div`,{className:`space-y-2`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Node`}),o(E,{selectedNodeId:O,onSelect:A,alwaysShow:!0}),o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Path`}),o(ce,{nodeId:O,value:j,onChange:M})]}),C&&o(we,{config:u,defaultPercent:N,onChange:d}),!x&&!b.isLoading&&n(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:[`Provider `,o(`code`,{className:`font-mono`,children:e.providerId}),` is no longer registered. Field schema unavailable; raw config is preserved on save.`]}),m&&o(`div`,{className:`rounded border px-3 py-2 text-[11px] ${m.ok?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:m.ok?`Connection OK.`:`Test failed: ${m.error??`unknown error`}`}),S.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:S.error instanceof Error?S.error.message:String(S.error)})]}),n(k,{className:`justify-between`,children:[o(T,{variant:`outline`,size:`sm`,onClick:t,children:`Cancel`}),n(`div`,{className:`flex items-center gap-2`,children:[o(T,{variant:`outline`,size:`sm`,onClick:()=>{P()},disabled:v||!x,children:v?`Testing…`:`Test connection`}),n(T,{size:`sm`,onClick:()=>{S.mutate(pe(e,{displayName:f.trim(),config:u,nodeId:D?O:e.nodeId}))},disabled:S.isPending||f.trim().length===0,children:[S.isPending?o(h,{className:`h-3.5 w-3.5 animate-spin`}):null,S.isPending?`Saving…`:`Save`]})]})]})]})})}function Ee(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function G(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function De(e){if(!Ee(e))return null;let t=e.locationId;if(typeof t!=`string`||t.length===0)return null;let n=G(e.startedAtMs),r=G(e.startBytes),i=G(e.bytesRemaining);return n===null||r===null||i===null||typeof e.drained!=`boolean`?null:{locationId:t,startedAtMs:n,startBytes:r,bytesRemaining:i,drained:e.drained,estimatedEmptyAtMs:G(e.estimatedEmptyAtMs)}}function Oe(e){let t=new Map;if(!Array.isArray(e))return t;for(let n of e){let e=De(n);e!==null&&t.set(e.locationId,e)}return t}function ke(e){if(e.startBytes<=0||e.bytesRemaining>e.startBytes)return null;let t=e.startBytes-e.bytesRemaining;return Math.min(1,Math.max(0,t/e.startBytes))}function Ae(e,t){return e?t===void 0?{kind:`unreported`}:t.drained||t.bytesRemaining<=0?{kind:`drained`}:{kind:`draining`,bytesRemaining:t.bytesRemaining,drainedFraction:ke(t),estimatedEmptyAtMs:t.estimatedEmptyAtMs}:{kind:`idle`}}function je(e){return e.mode===`drain`?!0:e.config.readOnly===!0}function Me(e){return`${(e/1024**3).toFixed(e>=100*1024**3?0:1)} GB`}function Ne(e){return new Date(e).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})}function Pe({drain:e}){if(e.kind===`idle`)return null;if(e.kind===`unreported`)return o(`span`,{"data-testid":`drain-unreported`,className:`text-[10px] text-foreground-subtle`,title:`This location is draining. The hub has not reported how much is left yet — either the drain has just been set, or this hub predates the drain-progress report.`,children:`Draining · remaining not reported yet`});if(e.kind===`drained`)return o(`span`,{"data-testid":`drain-done`,className:`text-[10px] text-success`,title:`Everything that was here has been moved. The location is still in drain mode — it receives no new writes until you change that.`,children:`Drained · nothing left to move`});let t=e.drainedFraction===null?null:Math.round(e.drainedFraction*100);return n(`span`,{"data-testid":`drain-progress`,className:`flex items-center gap-1.5 text-[10px] text-foreground-subtle tabular-nums`,children:[t!==null&&o(`span`,{"data-testid":`drain-bar`,className:`inline-block h-1 w-10 rounded-full bg-border overflow-hidden`,role:`progressbar`,"aria-label":`Drain progress`,"aria-valuenow":t,"aria-valuemin":0,"aria-valuemax":100,children:o(`span`,{className:`block h-full bg-warning`,style:{width:`${t}%`}})}),n(`span`,{children:[Me(e.bytesRemaining),` left`,t!==null&&` · ${t}% moved`]}),e.estimatedEmptyAtMs===null?o(`span`,{"data-testid":`drain-eta-absent`,title:`The drain is paced by how fast this class of data is still growing, and that has not been observed yet. There is no date to give.`,children:`· empty time not known yet`}):n(`span`,{"data-testid":`drain-eta`,children:[`· empty `,Ne(e.estimatedEmptyAtMs)]})]})}var Fe=[`ok`,`warn`,`critical`];function Ie(e){return e>=.95?`critical`:e>=.85?`warn`:`ok`}function Le(e){return Math.min(1,Math.max(0,e))}function K(e){let{availableBytes:t,totalBytes:n}=e;if(n===null||n<=0||t===null)return null;let r=Le((n-t)/n);return{fraction:r,severity:Ie(r),recordingsFraction:Le(e.usedBytes/n),freeBytes:t,totalBytes:n}}function Re(e){if(e.length===0)return null;let t=0,n=0,r=0,i=0,a=null;for(let o of e){let e=K(o);if(e===null){n+=1;continue}t+=1,r+=e.totalBytes,i+=e.freeBytes,(a===null||Fe.indexOf(e.severity)>Fe.indexOf(a))&&(a=e.severity)}return{knownVolumes:t,unknownVolumes:n,totalBytes:r,freeBytes:i,severity:a}}var ze=`Capacity unknown — nothing measured this volume from here. A remote share, a location on another node, or a mount that did not answer.`;function q(e){return Math.min(1,Math.max(0,e))}function J(e){return Math.round(q(e)*1e3)/10}function Y(e){return`${String(Math.round(q(e)*100))}%`}function Be(e,t,n={}){let{totalBytes:r,availableBytes:i}=e;if(r===null||r<=0||i===null){let e=n.ownedBytes===void 0||n.ownedBytes===null||!Number.isFinite(n.ownedBytes)||n.ownedBytes<0?null:j(n.ownedBytes);return{kind:`unknown`,owned:e,summary:e===null?ze:`${ze} CamStack holds ${e} here.`}}let a=Math.min(Math.max(i,0),r),o=r-a,s=t===null||t<=0?0:t,c=Math.min(s,a),l=s>a,u=a-c,d=n.ownedBytes,f=d==null||!Number.isFinite(d)||d<0?null:Math.min(d,o),p=o-(f??0),m=K({usedBytes:f??o,availableBytes:a,totalBytes:r}),h=m===null?q(o/r):m.fraction,g=m===null?Ie(h):m.severity,_=f===null?null:m===null?q(f/r):m.recordingsFraction,v=n.cap??null,y=v===null?null:q((c+v.bytes)/r),b=v!==null&&f!==null&&f>v.bytes,x={total:j(r),freeTotal:j(a),freeTotalPercent:Y(a/r),used:j(p),usedPercent:Y(p/r),free:j(u),freePercent:Y(u/r),reserve:s===0?null:`${j(s)} kept free`,owned:f===null||_===null?null:`${j(f)} of recordings (${Y(_)})`,cap:v===null?null:v.reason===`drain`?`${j(v.bytes)} drain target (managed by CamStack)`:`${j(v.bytes)} cap (managed by CamStack)`},S=[`${x.freeTotal} free of ${x.total} (${x.freeTotalPercent} free)`,x.owned===null?null:`CamStack holds ${x.owned}`,x.reserve===null?null:l?`${x.reserve} — less free than that right now, the oldest data here is being deleted`:x.reserve,x.cap===null?null:b?`${x.cap} — already below what is stored here, the oldest is being deleted`:x.cap].filter(e=>e!==null).join(` · `),C=[];return c>0&&C.push({segment:`reserve`,label:`Kept free`,value:j(s),alarming:l}),x.owned!==null&&C.push({segment:`owned`,label:`CamStack`,value:x.owned,alarming:!1}),C.push({segment:`used`,label:f===null?`Used`:`Other data`,value:`${x.used} (${x.usedPercent})`,alarming:g===`critical`}),C.push({segment:`free`,label:`Free`,value:`${x.free} (${x.freePercent})`,alarming:l}),v!==null&&C.push({segment:`cap`,label:v.reason===`drain`?`Drain target`:`Cap`,value:`${j(v.bytes)} · managed by CamStack`,alarming:b}),{kind:`known`,severity:g,legend:C,segments:{reservePercent:J(c/r),ownedPercent:f===null?null:J(f/r),usedPercent:J(p/r),freePercent:J(u/r),capPercent:y===null?null:J(y)},labels:x,reserveExceedsFree:l,capBelowOwned:b,summary:S}}var Ve={ok:`bg-primary`,warn:`bg-amber-500`,critical:`bg-danger`},X={reserve:`bg-danger/40`,owned:`bg-foreground/50`,free:`bg-border`,cap:`bg-foreground`};function He(e,t){return e===`used`?Ve[t]:X[e]}function Ue({location:e,ownedBytes:t}){let r=e.capacity??null,i=ye(he(e.config),r?.totalBytes??null),a=Be({totalBytes:r?.totalBytes??null,availableBytes:r?.availableBytes??null},i,{ownedBytes:t??null,cap:Ce(e.config,R(e))});return a.kind===`unknown`?o(`div`,{className:`text-[10px] text-foreground-subtle italic`,title:a.summary,children:a.owned===null?`Capacity unknown`:`Capacity unknown · CamStack holds ${a.owned}`}):n(`div`,{className:`mt-1 space-y-1`,title:a.summary,children:[n(`div`,{className:`relative flex h-2 w-full max-w-md overflow-hidden rounded-full bg-border`,children:[a.segments.reservePercent>0&&o(`div`,{className:X.reserve,style:{width:`${String(a.segments.reservePercent)}%`}}),a.segments.ownedPercent!==null&&o(`div`,{className:X.owned,style:{width:`${String(a.segments.ownedPercent)}%`}}),o(`div`,{className:Ve[a.severity],style:{width:`${String(a.segments.usedPercent)}%`}}),o(`div`,{className:X.free,style:{width:`${String(a.segments.freePercent)}%`}}),a.segments.capPercent!==null&&o(`div`,{className:`absolute inset-y-0 w-px ${a.capBelowOwned?`bg-danger`:X.cap}`,style:{left:`${String(a.segments.capPercent)}%`}})]}),o(`ul`,{className:`flex flex-wrap items-center gap-x-3 gap-y-0.5`,children:a.legend.map(e=>n(`li`,{className:`flex items-center gap-1`,children:[o(`span`,{"aria-hidden":`true`,className:`inline-block h-2 w-2 shrink-0 rounded-sm ${He(e.segment,a.severity)}`}),n(`span`,{className:`text-[10px] tabular-nums ${e.alarming?`text-danger`:`text-foreground-subtle`}`,children:[e.label,` `,e.value]})]},e.segment))})]})}var We={eventMedia:[`events`],recordingsLow:[`low`],recordings:[`high`,`mid`]},Ge={eventMedia:`pipeline-analytics`,recordingsLow:`recorder`,recordings:`recorder`},Ke=`storage.discardLocation`,qe=`storage.discardLocationStatus`,Je=`storage.discardLocationCancel`;function Ye(e){return We[e]??null}function Xe(e){return Ge[e]??null}function Ze(e){return!z(R(e))}function Qe(e,t){return Ye(e.type)===null||!Ze(e)?!1:t.some(t=>t.id!==e.id&&z(R(t)))}var $e=new Set([`idle`,`scanning`,`wiping-fs`,`wiping-db`,`cascading`,`complete`,`cancelled`,`error`]);function Z(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function Q(e){return typeof e==`string`?e:null}function et(e){if(typeof e!=`object`||!e)return null;let t=e;if(typeof t.running!=`boolean`)return null;let n=t.phase;if(typeof n!=`string`||!$e.has(n))return null;let r=Z(t.camerasTotal),i=Z(t.camerasDone),a=Z(t.foldersRemoved),o=Z(t.dbRowsDeleted),s=Z(t.ownersCascaded);return r===null||i===null||a===null||o===null||s===null?null:{running:t.running,locationId:Q(t.locationId),jobId:Q(t.jobId),phase:n,camerasTotal:r,camerasDone:i,foldersRemoved:a,dbRowsDeleted:o,ownersCascaded:s,detail:Q(t.detail)??``,startedAtMs:Z(t.startedAtMs),finishedAtMs:Z(t.finishedAtMs),error:Q(t.error)}}function tt(e){if(e.phase===`complete`)return 100;if(e.phase===`cancelled`||e.phase===`error`||e.phase===`idle`)return e.camerasTotal>0?Math.min(99,Math.round(e.camerasDone/e.camerasTotal*100)):0;if(e.camerasTotal>0){let t=e.camerasDone/e.camerasTotal*85;return e.phase===`wiping-db`?Math.min(95,Math.round(t+8)):e.phase===`cascading`?Math.min(99,Math.round(t+12)):Math.min(85,Math.round(t))}return e.phase===`scanning`?2:5}t();var nt=2e3;function rt({location:e,siblings:t}){return Qe(e,t)?o(it,{location:e}):null}function it({location:e}){let t=O(),r=A(),i=Xe(e.type),[c,l]=a(null),[u,d]=a(null),[f,p]=a(!1);if(s(()=>{if(i===null)return;let e=!1,t=async()=>{try{let t=await r.mutateAsync({addonId:i,action:qe,input:{}});if(e)return;l(et(t))}catch{}};t();let n=setInterval(()=>void t(),nt);return()=>{e=!0,clearInterval(n)}},[i,e.id]),i===null)return null;let m=c!==null&&c.locationId===e.id,_=m&&c.running,v=m&&c.phase!==`idle`,y=async()=>{if(await t({title:`Discard leftovers on "${e.displayName}"?`,message:`Permanently deletes leftover files and records on this location. Other locations are not affected. This cannot be undone and may take hours.`,confirmLabel:`Discard leftovers`,variant:`danger`})){d(null),p(!0);try{await r.mutateAsync({addonId:i,action:Ke,input:{locationId:e.id}}),l(et(await r.mutateAsync({addonId:i,action:qe,input:{}})))}catch(e){d(e instanceof Error?e.message:String(e))}finally{p(!1)}}},b=async()=>{try{await r.mutateAsync({addonId:i,action:Je,input:{}})}catch(e){d(e instanceof Error?e.message:String(e))}};return n(`div`,{className:`flex flex-col gap-1 min-w-[9rem] max-w-[16rem]`,children:[_?n(`button`,{type:`button`,onClick:()=>void b(),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger border border-danger/40 hover:bg-danger/10`,children:[o(g,{className:`h-3 w-3`}),`Cancel`]}):n(`button`,{type:`button`,onClick:()=>void y(),disabled:f,title:`Permanently delete leftover files on this location. Other locations are not affected.`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger border border-danger/40 hover:bg-danger/10 disabled:opacity-50`,children:[f?o(h,{className:`h-3 w-3 animate-spin`}):o(x,{className:`h-3 w-3`}),`Discard leftovers`]}),v&&c!==null&&n(`div`,{className:`space-y-0.5`,children:[o(`div`,{className:`h-1 rounded bg-border overflow-hidden`,children:o(`div`,{className:`h-full bg-primary transition-[width] duration-300`,style:{width:`${tt(c)}%`}})}),n(`p`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[c.phase,c.camerasTotal>0?` · ${c.camerasDone}/${c.camerasTotal} cam`:``,c.dbRowsDeleted>0?` · ${c.dbRowsDeleted} rows`:``,c.detail?` · ${c.detail}`:``]})]}),(u||m&&c?.error)&&o(`p`,{className:`text-[10px] text-danger leading-tight`,children:u??c?.error})]})}t();var $={active:p,readonly:b,drain:S,disabled:u},at={active:`border-success/30 text-success hover:bg-success/10`,readonly:`border-border text-foreground-subtle hover:text-foreground hover:bg-primary/10`,drain:`border-warning/40 text-warning hover:bg-warning/10`,disabled:`border-danger/40 text-danger hover:bg-danger/10`};function ot({mode:e,open:t,onToggle:r}){let i=V(e),a=$[e];return n(`button`,{type:`button`,"aria-expanded":t,"aria-label":`Location state`,onClick:r,title:i.consequence,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium border ${at[e]}`,children:[o(a,{className:`h-3 w-3`}),i.label,o(v,{className:`h-3 w-3 ${t?`rotate-180`:``}`})]})}function st({mode:e,blockedReasons:t,onSelect:r,onDismiss:i}){return s(()=>{let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e)}},[i]),n(`div`,{className:`w-full basis-full rounded-lg border border-border bg-background p-1`,role:`group`,"aria-label":`Location state choices`,children:[n(`div`,{className:`flex items-center justify-between px-2 py-1`,children:[o(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Location state`}),o(`button`,{type:`button`,"aria-label":`Close location state choices`,onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:o(g,{className:`h-3 w-3`})})]}),B.map(a=>{let s=t[a.mode],c=s!==``,l=$[a.mode],u=a.mode===e;return n(`button`,{type:`button`,role:`radio`,"aria-checked":u,"aria-label":a.label,disabled:c,onClick:()=>{c||(i(),u||r(a.mode))},className:`flex w-full flex-col items-start gap-0.5 rounded px-2 py-1.5 text-left ${c?`cursor-not-allowed opacity-60`:u?`bg-primary/10`:`hover:bg-primary/5`}`,children:[n(`span`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-foreground`,children:[o(l,{className:`h-3 w-3`}),a.label,u&&o(`span`,{className:`text-[9px] uppercase text-primary`,children:`current`})]}),o(`span`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:a.consequence}),c&&o(`span`,{className:`text-[10px] leading-snug text-warning`,children:s})]},a.mode)})]})}t();function ct(e){let t=e.basePath;if(typeof t==`string`&&t.length>0)return t;let n=Object.keys(e);return n.length===0?``:n.join(`, `)}function lt({location:e,onEdit:t,onDelete:r,onSetMode:i,blockedReasons:s,canDelete:c,siblings:u=[],drain:d,ownedBytes:p}){let[m,h]=a(!1),g=ct(e.config),_=R(e);return n(`div`,{className:`flex flex-wrap items-start gap-x-3 gap-y-2 px-3 py-2 border-t border-border first:border-t-0 hover:bg-primary/5`,children:[n(`div`,{className:`flex items-start gap-2 min-w-0 flex-1 basis-72`,children:[o(`div`,{className:`shrink-0 sm:w-32`,"data-testid":`location-badge-slot`,children:o(`span`,{className:`inline-block text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5 font-mono`,children:e.providerId})}),n(`div`,{className:`min-w-0 flex-1`,children:[o(`div`,{className:`text-xs font-medium text-foreground truncate`,children:e.displayName}),g&&o(`div`,{className:`text-[10px] text-foreground-subtle truncate font-mono`,children:g}),o(Ue,{location:e,ownedBytes:p??null}),d!==void 0&&o(Pe,{drain:d})]})]}),n(`div`,{className:`flex flex-wrap items-center gap-1 shrink-0`,children:[o(rt,{location:e,siblings:u}),o(ot,{mode:_,open:m,onToggle:()=>{h(e=>!e)}}),n(`button`,{onClick:()=>t(e),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle border border-border hover:text-foreground hover:bg-primary/10`,children:[o(f,{className:`h-3 w-3`}),`Edit`]}),c&&o(`button`,{onClick:()=>r(e),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10`,title:`Delete location`,children:o(l,{className:`h-3 w-3`})})]}),m&&o(st,{mode:_,blockedReasons:s,onSelect:t=>i(e,t),onDismiss:()=>{h(!1)}})]})}t();function ut({type:e,displayName:t,description:i,cardinality:a,locations:s,onAdd:l,onEdit:u,onDelete:f,onSetMode:p,ownedBytesById:m,drainById:h}){let g=r(()=>{let e=[...s];return e.sort((e,t)=>{let n=z(R(e));return n===z(R(t))?e.displayName.localeCompare(t.displayName):n?-1:1}),e},[s]);return n(D,{headingId:`storage-location-${e}`,title:t,icon:y,testId:`storage-location-group-${e}`,actions:a===`multi`?n(T,{size:`sm`,type:`button`,onClick:()=>l(e),children:[o(d,{className:`h-3 w-3`}),`Add`]}):void 0,children:[n(`div`,{className:`${c} space-y-2`,children:[n(`div`,{className:`space-y-0.5`,children:[o(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5 font-mono`,children:e}),i!==void 0&&i!==``&&o(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:i}),a===`single`&&o(`p`,{className:`text-[10px] text-foreground-subtle italic`,children:`Single — one location per type. Edit the existing entry; it can't be split.`})]}),g.length===0&&o(`div`,{className:`py-2 text-center text-[11px] text-foreground-subtle italic`,children:a===`multi`?`No location registered. Click "Add" to register one.`:`No location registered yet — should be auto-seeded at next boot.`})]}),g.length>0&&o(`div`,{className:`border-t border-border`,children:g.map(e=>o(lt,{location:e,cardinality:a,canDelete:fe(e,g,a),onEdit:u,onDelete:f,onSetMode:p,blockedReasons:de(e,g),ownedBytes:m?.get(e.id)??null,drain:Ae(je(e),h?.get(e.id)),siblings:g},e.id))})]})}var dt=[`recordings`,`recordingsLow`];function ft(e){return e.locationIds!==void 0&&e.locationIds.length>0?e.locationIds:e.locationId===null?[]:[e.locationId]}function pt(e,t){if(t===void 0||!dt.includes(e.type))return null;let n=t.find(t=>ft(t).includes(e.id));return n===void 0||!Number.isFinite(n.usedBytes)||n.usedBytes<0?null:n.usedBytes}function mt(e,t){let n=new Map;for(let r of e){let e=pt(r,t);e!==null&&n.set(r.id,e)}return n}export{Oe as a,V as c,Re as i,le as l,ut as n,Te as o,K as r,pe as s,mt as t,L as u};
|
|
1
|
+
import{I as e,Q as t,S as n,W as r,o as i,q as a,x as o,z as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{D as c,It as l,Lr as u,On as d,Pn as f,Tn as p,_i as m,ar as h,dt as g,ot as _,yi as v,yr as y}from"./player-overlays-C20AJTgs.js";import{t as b}from"./archive-4K83r_1n.js";import{t as x}from"./eraser-Bgk8Dzm-.js";import{t as S}from"./hard-drive-download-Cf7DR1zn.js";import{ii as C}from"./client-CKGZv6zJ.js";import{An as w,Bn as T,Dn as ee,En as te,Hc as ne,Tn as re,U as E,Vt as D,Zn as O,el as ie,jn as ae,kn as k,yr as A}from"./src-CIIJy_o8.js";import{I as oe}from"./index-AsTGrKva.js";import{t as j}from"./format-size-DIxKXxtj.js";t();function M(e){let t=e.trim().toLowerCase();return t.length===0?``:t.replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function N(e,t){let n=M(t);return`${e}:${n.length>0?n:`default`}`}var P=new Set([`proc`,`sys`,`dev`,`run`,`boot`,`lost+found`,`snap`,`bin`,`sbin`,`lib`,`lib32`,`lib64`,`libx32`,`usr`,`etc`,`var`,`opt`,`tmp`,`srv`,`root`,`System`,`Library`,`Applications`,`cores`,`private`]),F=[`recordings`,`data`,`mnt`,`media`,`Volumes`];function I(e){let t=F.findIndex(t=>t===`recordings`?e.startsWith(t):e===t);return t===-1?F.length:t}function se(e){return e.filter(e=>!e.name.startsWith(`.`)&&!P.has(e.name)).toSorted((e,t)=>{let n=I(e.name)-I(t.name);return n===0?e.name.localeCompare(t.name):n}).map(e=>e.path)}function ce({nodeId:t,value:r,onChange:i}){let c=_().trpcClient,[l,u]=a([]),[d,f]=a(r),[p,m]=a(null),[h,g]=a(null),[v,y]=a(``),b=e(async(e,n)=>{g(null);try{let r=await c.filesystemBrowse.browse.query({nodeId:t,path:e});m(r),f(r.path),n&&i(r.path)}catch(e){g(e instanceof Error?e.message:`browse failed`)}},[c,t,i]);s(()=>{f(r),(async()=>{let e=await c.filesystemBrowse.browse.query({nodeId:t,path:`/`}).then(e=>e).catch(()=>null);if(e){u(se(e.entries)),await b(r.startsWith(`/`)?r:`/`,!1);return}try{let e=await c.filesystemBrowse.listAllowedRoots.query({nodeId:t});u(e),await b(r&&e.some(e=>r.startsWith(e))?r:e[0]??``,!1)}catch(e){u([]),m(null),g(e instanceof Error&&/not available on node/i.test(e.message)?`This node can't be browsed remotely. Enter the path manually.`:e instanceof Error?e.message:`browse unavailable`)}})()},[t]);let x=async()=>{if(!(!v.trim()||!p)){g(null);try{let e=`${p.path.replace(/\/+$/,``)}/${v.trim()}`;await c.filesystemBrowse.createDir.mutate({nodeId:t,path:e}),y(``),await b(p.path,!0)}catch(e){g(e instanceof Error?e.message:`create failed`)}}},S=e=>`${(e/1e9).toFixed(1)} GB`;return n(`div`,{className:`space-y-2 rounded border border-border p-2`,children:[o(`div`,{className:`flex flex-wrap gap-1`,children:l.map(e=>o(`button`,{onClick:()=>void b(e,!0),className:`rounded border border-border px-2 py-0.5 text-[10px] font-mono hover:border-primary/40`,children:e},e))}),o(`input`,{value:d,onChange:e=>{f(e.target.value),i(e.target.value)},placeholder:`/absolute/path`,className:`w-full rounded border border-border bg-background px-2 py-1 text-[11px] font-mono`}),p&&n(`div`,{className:`text-[10px] text-foreground-subtle`,children:[S(p.freeBytes),` free / `,S(p.totalBytes)]}),o(`div`,{className:`max-h-40 space-y-0.5 overflow-y-auto`,children:p?.entries.map(e=>n(`button`,{onClick:()=>void b(e.path,!0),className:`block w-full truncate rounded px-2 py-1 text-left text-xs hover:bg-primary/5`,children:[`📁 `,e.name]},e.path))}),n(`div`,{className:`flex gap-1`,children:[o(`input`,{value:v,onChange:e=>y(e.target.value),placeholder:`new folder`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs`}),o(`button`,{onClick:()=>void x(),className:`rounded border border-border px-2 py-1 text-xs hover:border-primary/40`,children:`Create`})]}),h&&o(`div`,{className:`text-[10px] text-red-400`,children:h})]})}t();function L({initialType:e,onClose:t,onCreated:s}){let c=i(),l=_().trpcClient,[u,d]=a(`picker`),[f,p]=a(e),[g,v]=a(null),[y,b]=a({}),[x,S]=a(``),[C,T]=a(null),[D,O]=a(!1),[k,A]=a(`hub`),[j,M]=a(null),[P,F]=a(!1),I=e=>b(t=>({...t,basePath:e})),se=typeof y.basePath==`string`?y.basePath:``,L=ne(),R=r(()=>{let e=L.data;return Array.isArray(e)?e:[]},[L.data]),z=L.isLoading,B=ie({onSuccess:()=>{c.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),s()}}),V=r(()=>C!==null&&C.length>0?C:N(f,x),[f,x,C]),le=async()=>{if(g){F(!0),M(null);try{M(await(e=>l.storage.testConfig.query(e))({providerId:g.providerId,config:y}))}catch(e){M({ok:!1,error:e instanceof Error?e.message:String(e)})}finally{F(!1)}}};return o(re,{open:!0,onOpenChange:e=>!e&&t(),children:n(ee,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[n(w,{children:[o(ae,{children:{picker:`Add Location — Pick provider`,config:`Add Location — ${g?.displayName??``}`,naming:`Add Location — Name`}[u]}),n(`p`,{className:`text-xs text-foreground-subtle`,children:[`Type: `,o(`span`,{className:`font-mono`,children:f})]})]}),n(te,{children:[u===`picker`&&n(`div`,{className:`space-y-2`,children:[z&&o(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading providers…`}),!z&&R.length===0&&n(`div`,{className:`rounded border border-border bg-background px-3 py-4 text-center text-xs text-foreground-subtle`,children:[`No storage-provider supports type "`,f,`". Install a compatible addon (e.g.`,` `,o(`code`,{className:`font-mono`,children:`remote-storage`}),`) to enable it.`]}),R.map(e=>n(`button`,{onClick:()=>{v(e),d(`config`)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-background p-3 text-left hover:border-primary/40 hover:bg-primary/5 transition-colors`,children:[n(`div`,{className:`flex-1 min-w-0`,children:[o(`p`,{className:`text-xs font-semibold text-foreground`,children:e.displayName}),o(`p`,{className:`text-[10px] text-foreground-subtle font-mono mt-0.5 truncate`,children:e.providerId})]}),o(m,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},e.providerId))]}),u===`config`&&g&&n(`div`,{className:`space-y-3`,children:[o(oe,{schema:g.configSchema,values:y,onChange:b}),g.nodeLocal&&n(`div`,{className:`space-y-2`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Node`}),o(E,{selectedNodeId:k,onSelect:A,alwaysShow:!0}),o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Path`}),o(ce,{nodeId:k,value:se,onChange:I})]}),j&&o(`div`,{className:`rounded border px-3 py-2 text-[11px] ${j.ok?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:j.ok?`Connection OK.`:`Test failed: ${j.error??`unknown error`}`}),n(`div`,{className:`flex items-center justify-between pt-1`,children:[o(`button`,{onClick:()=>d(`picker`),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Back`}),n(`div`,{className:`flex items-center gap-2`,children:[o(`button`,{onClick:()=>{le()},disabled:P,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10 disabled:opacity-50`,children:P?`Testing…`:`Test connection`}),o(`button`,{onClick:()=>d(`naming`),className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Next`})]})]})]}),u===`naming`&&g&&n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Display name`}),o(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),placeholder:`${f} on ${g.displayName}`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),n(`div`,{className:`space-y-1`,children:[n(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:[`Id`,` `,o(`span`,{className:`lowercase tracking-normal text-foreground-subtle`,children:`— auto-derived; override if needed`})]}),o(`input`,{type:`text`,value:V,onChange:e=>T(e.target.value),placeholder:N(f,x),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground font-mono focus:outline-none focus:ring-1 focus:ring-primary`}),n(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,o(`code`,{className:`font-mono`,children:`<type>:<slug>`}),`. Lowercase letters, digits, and hyphens only.`]})]}),n(`label`,{className:`flex items-start gap-2 rounded border border-border bg-background px-3 py-2 cursor-pointer hover:bg-primary/5`,children:[o(`input`,{type:`checkbox`,checked:D,onChange:e=>O(e.target.checked),className:`accent-primary mt-0.5`}),n(`div`,{className:`space-y-0.5`,children:[o(`div`,{className:`text-xs font-medium text-foreground`,children:`Enable immediately`}),o(`div`,{className:`text-[10px] text-foreground-subtle`,children:`A disabled location receives no writes until enabled — reads and age-based retention still work, nothing new lands here. Leave this off to register the disk now and start using it later.`})]})]}),B.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:B.error instanceof Error?B.error.message:String(B.error)}),n(`div`,{className:`flex items-center justify-between pt-1`,children:[o(`button`,{onClick:()=>d(`config`),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Back`}),n(`div`,{className:`flex items-center gap-2`,children:[o(`button`,{onClick:()=>{p(e),v(null),b({}),S(``),T(null),O(!1),M(null),d(`picker`)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Reset`}),n(`button`,{onClick:()=>{g&&B.mutate({id:V,type:f,displayName:x.trim(),providerId:g.providerId,config:y,enabled:D,nodeId:g.nodeLocal?k:void 0})},disabled:B.isPending||x.trim().length===0,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:[B.isPending?o(h,{className:`h-3.5 w-3.5 animate-spin`}):null,B.isPending?`Saving…`:`Save`]})]})]})]})]})]})})}function R(e){return C(e)}function z(e){return e===`active`}var B=[{mode:`active`,label:`Active`,consequence:`New data is written here, and the oldest is deleted when the disk fills up.`,requiresConfirmation:!1},{mode:`readonly`,label:`Read-only`,consequence:`Nothing new is written and nothing is ever deleted. A frozen archive that stays on the timeline.`,requiresConfirmation:!1},{mode:`drain`,label:`Drain`,consequence:`Nothing new is written. The oldest data here is deleted, a little at a time, until this location is empty.`,requiresConfirmation:!1},{mode:`disabled`,label:`Disabled`,consequence:`Nothing is written and nothing is read: the footage stored here disappears from the timeline until you turn it back on. Nothing is deleted.`,requiresConfirmation:!0}];function V(e){return B.find(t=>t.mode===e)??B[0]}function le(e){return V(e).requiresConfirmation}var ue=`Blocked: this is the last location of its type still accepting writes — new data would have nowhere to go.`;function H(e,t,n){return z(n)||!z(R(e))||t.some(t=>t.id!==e.id&&z(R(t)))?{blocked:!1,reason:``}:{blocked:!0,reason:ue}}function de(e,t){return{active:H(e,t,`active`).reason,readonly:H(e,t,`readonly`).reason,drain:H(e,t,`drain`).reason,disabled:H(e,t,`disabled`).reason}}function fe(e,t,n){return!(n===`single`||t.length<=1||z(R(e))&&t.filter(e=>z(R(e))).length<=1)}function U(e){return e===`active`?{enabled:!0,readOnly:!1}:e===`readonly`?{enabled:!1,readOnly:!1}:{enabled:!1,readOnly:!0}}function pe(e,t){let n={...t.config??e.config};t.mode!==void 0&&(U(t.mode).readOnly?n.readOnly=!0:delete n.readOnly);let r={id:e.id,type:e.type,displayName:t.displayName??e.displayName,providerId:e.providerId,config:n,isSystem:e.isSystem},i=t.nodeId??e.nodeId,a=i===void 0?r:{...r,nodeId:i};return t.mode===void 0?e.enabled===void 0?a:{...a,enabled:e.enabled}:{...a,mode:t.mode,enabled:U(t.mode).enabled}}var me=1024**3;function W(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function he(e){let t=W(e.minFreeGb);if(t!==null)return{unit:`gb`,value:t};let n=W(e.minFreePercent);return n===null?{unit:`percent`,value:null}:{unit:`percent`,value:n}}function ge(e,t){return W(e[t===`gb`?`minFreeGb`:`minFreePercent`])}function _e(e,t){let n={...e};return delete n.minFreePercent,delete n.minFreeGb,t.value===null?n:t.unit===`gb`?{...n,minFreeGb:t.value}:{...n,minFreePercent:t.value}}function ve(e,t){let n=e.trim();if(n===``)return null;let r=Number(n);return Number.isFinite(r)?t===`percent`?Math.min(100,Math.max(0,r)):Math.max(0,r):null}function ye(e,t,n=10){if(e.unit===`gb`&&e.value!==null)return e.value*me;let r=e.value??n;return t===null||t<=0?null:t*Math.min(100,Math.max(0,r))/100}function be(e){return e===`gb`?`GB to keep free`:`% of the volume to keep free`}function xe(e,t=10){return`CamStack keeps ${e.value===null?`${String(t)}% of the volume (the default)`:e.unit===`gb`?`${String(e.value)} GB`:`${String(e.value)}% of the volume`} free on this disk. As it fills up, the OLDEST data stored here is deleted to hold that much free space; if it cannot be held any more, new data goes to another location of the same type instead of filling the disk. Leave the value empty for the default (${String(t)}%).`}function Se(e){return W(e.maxUsedGb)}function Ce(e,t){let n=W(e.maxUsedGb);return n===null||n<0?null:{bytes:n*me,reason:t===`drain`?`drain`:`legacy`}}t();function we({config:e,defaultPercent:t=10,onChange:r}){let[i,s]=a(()=>he(e).unit),c=ge(e,i),l={unit:i,value:c},u=Se(e),d=t=>{s(t),r(_e(e,{unit:t,value:null}))},f=t=>{r(_e(e,{unit:i,value:ve(t,i)}))};return n(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Protected free space`}),n(`div`,{className:`flex items-center gap-2`,children:[n(`select`,{"aria-label":`Protection unit`,value:i,onChange:e=>{d(e.target.value===`gb`?`gb`:`percent`)},className:`rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:[o(`option`,{value:`percent`,children:`% of the volume`}),o(`option`,{value:`gb`,children:`GB of free space`})]}),o(`input`,{type:`number`,"aria-label":be(i),min:0,max:i===`percent`?100:void 0,value:c===null?``:c,placeholder:i===`percent`?String(t):`default`,onChange:e=>{f(e.target.value)},className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),o(`p`,{className:`text-[10px] text-foreground-subtle`,children:xe(l,t)}),u!==null&&n(`p`,{className:`text-[10px] text-foreground-subtle italic`,children:[`This location also stores a maximum used size of `,u,` GB. That limit is managed by the system now and is no longer editable here; it is kept as it is.`]})]})}t();function Te({location:e,onClose:t,onSaved:s}){let c=i(),l=_().trpcClient,[u,d]=a({...e.config}),[f,p]=a(e.displayName),[m,g]=a(null),[v,y]=a(!1),b=ne(),x=r(()=>{let t=b.data;return Array.isArray(t)?t.find(t=>t.providerId===e.providerId)??null:null},[b.data,e.providerId]),S=ie({onSuccess:()=>{c.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),s()}}),C=x?.shouldSaveDiskSpace===!0,D=x?.nodeLocal===!0,[O,A]=a(typeof e.nodeId==`string`?e.nodeId:`hub`),j=typeof u.basePath==`string`?u.basePath:``,M=e=>d(t=>({...t,basePath:e})),N=x?.minFreePercent??10,P=async()=>{y(!0),g(null);try{g(await(e=>l.storage.testConfig.query(e))({providerId:e.providerId,locationId:e.id,config:u}))}catch(e){g({ok:!1,error:e instanceof Error?e.message:String(e)})}finally{y(!1)}};return o(re,{open:!0,onOpenChange:e=>!e&&t(),children:n(ee,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[n(w,{children:[n(ae,{children:[`Edit `,e.displayName]}),n(`p`,{className:`text-xs text-foreground-subtle`,children:[o(`span`,{className:`font-mono`,children:e.id}),` ·`,` `,x?.displayName??e.providerId]})]}),n(te,{className:`space-y-3`,children:[n(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Display name`}),o(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),x&&o(oe,{schema:x.configSchema,values:u,onChange:d}),D&&n(`div`,{className:`space-y-2`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Node`}),o(E,{selectedNodeId:O,onSelect:A,alwaysShow:!0}),o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Path`}),o(ce,{nodeId:O,value:j,onChange:M})]}),C&&o(we,{config:u,defaultPercent:N,onChange:d}),!x&&!b.isLoading&&n(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:[`Provider `,o(`code`,{className:`font-mono`,children:e.providerId}),` is no longer registered. Field schema unavailable; raw config is preserved on save.`]}),m&&o(`div`,{className:`rounded border px-3 py-2 text-[11px] ${m.ok?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:m.ok?`Connection OK.`:`Test failed: ${m.error??`unknown error`}`}),S.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:S.error instanceof Error?S.error.message:String(S.error)})]}),n(k,{className:`justify-between`,children:[o(T,{variant:`outline`,size:`sm`,onClick:t,children:`Cancel`}),n(`div`,{className:`flex items-center gap-2`,children:[o(T,{variant:`outline`,size:`sm`,onClick:()=>{P()},disabled:v||!x,children:v?`Testing…`:`Test connection`}),n(T,{size:`sm`,onClick:()=>{S.mutate(pe(e,{displayName:f.trim(),config:u,nodeId:D?O:e.nodeId}))},disabled:S.isPending||f.trim().length===0,children:[S.isPending?o(h,{className:`h-3.5 w-3.5 animate-spin`}):null,S.isPending?`Saving…`:`Save`]})]})]})]})})}function Ee(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function G(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function De(e){if(!Ee(e))return null;let t=e.locationId;if(typeof t!=`string`||t.length===0)return null;let n=G(e.startedAtMs),r=G(e.startBytes),i=G(e.bytesRemaining);return n===null||r===null||i===null||typeof e.drained!=`boolean`?null:{locationId:t,startedAtMs:n,startBytes:r,bytesRemaining:i,drained:e.drained,estimatedEmptyAtMs:G(e.estimatedEmptyAtMs)}}function Oe(e){let t=new Map;if(!Array.isArray(e))return t;for(let n of e){let e=De(n);e!==null&&t.set(e.locationId,e)}return t}function ke(e){if(e.startBytes<=0||e.bytesRemaining>e.startBytes)return null;let t=e.startBytes-e.bytesRemaining;return Math.min(1,Math.max(0,t/e.startBytes))}function Ae(e,t){return e?t===void 0?{kind:`unreported`}:t.drained||t.bytesRemaining<=0?{kind:`drained`}:{kind:`draining`,bytesRemaining:t.bytesRemaining,drainedFraction:ke(t),estimatedEmptyAtMs:t.estimatedEmptyAtMs}:{kind:`idle`}}function je(e){return e.mode===`drain`?!0:e.config.readOnly===!0}function Me(e){return`${(e/1024**3).toFixed(e>=100*1024**3?0:1)} GB`}function Ne(e){return new Date(e).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})}function Pe({drain:e}){if(e.kind===`idle`)return null;if(e.kind===`unreported`)return o(`span`,{"data-testid":`drain-unreported`,className:`text-[10px] text-foreground-subtle`,title:`This location is draining. The hub has not reported how much is left yet — either the drain has just been set, or this hub predates the drain-progress report.`,children:`Draining · remaining not reported yet`});if(e.kind===`drained`)return o(`span`,{"data-testid":`drain-done`,className:`text-[10px] text-success`,title:`Everything that was here has been moved. The location is still in drain mode — it receives no new writes until you change that.`,children:`Drained · nothing left to move`});let t=e.drainedFraction===null?null:Math.round(e.drainedFraction*100);return n(`span`,{"data-testid":`drain-progress`,className:`flex items-center gap-1.5 text-[10px] text-foreground-subtle tabular-nums`,children:[t!==null&&o(`span`,{"data-testid":`drain-bar`,className:`inline-block h-1 w-10 rounded-full bg-border overflow-hidden`,role:`progressbar`,"aria-label":`Drain progress`,"aria-valuenow":t,"aria-valuemin":0,"aria-valuemax":100,children:o(`span`,{className:`block h-full bg-warning`,style:{width:`${t}%`}})}),n(`span`,{children:[Me(e.bytesRemaining),` left`,t!==null&&` · ${t}% moved`]}),e.estimatedEmptyAtMs===null?o(`span`,{"data-testid":`drain-eta-absent`,title:`The drain is paced by how fast this class of data is still growing, and that has not been observed yet. There is no date to give.`,children:`· empty time not known yet`}):n(`span`,{"data-testid":`drain-eta`,children:[`· empty `,Ne(e.estimatedEmptyAtMs)]})]})}var Fe=[`ok`,`warn`,`critical`];function Ie(e){return e>=.95?`critical`:e>=.85?`warn`:`ok`}function Le(e){return Math.min(1,Math.max(0,e))}function K(e){let{availableBytes:t,totalBytes:n}=e;if(n===null||n<=0||t===null)return null;let r=Le((n-t)/n);return{fraction:r,severity:Ie(r),recordingsFraction:Le(e.usedBytes/n),freeBytes:t,totalBytes:n}}function Re(e){if(e.length===0)return null;let t=0,n=0,r=0,i=0,a=null;for(let o of e){let e=K(o);if(e===null){n+=1;continue}t+=1,r+=e.totalBytes,i+=e.freeBytes,(a===null||Fe.indexOf(e.severity)>Fe.indexOf(a))&&(a=e.severity)}return{knownVolumes:t,unknownVolumes:n,totalBytes:r,freeBytes:i,severity:a}}var ze=`Capacity unknown — nothing measured this volume from here. A remote share, a location on another node, or a mount that did not answer.`;function q(e){return Math.min(1,Math.max(0,e))}function J(e){return Math.round(q(e)*1e3)/10}function Y(e){return`${String(Math.round(q(e)*100))}%`}function Be(e,t,n={}){let{totalBytes:r,availableBytes:i}=e;if(r===null||r<=0||i===null){let e=n.ownedBytes===void 0||n.ownedBytes===null||!Number.isFinite(n.ownedBytes)||n.ownedBytes<0?null:j(n.ownedBytes);return{kind:`unknown`,owned:e,summary:e===null?ze:`${ze} CamStack holds ${e} here.`}}let a=Math.min(Math.max(i,0),r),o=r-a,s=t===null||t<=0?0:t,c=Math.min(s,a),l=s>a,u=a-c,d=n.ownedBytes,f=d==null||!Number.isFinite(d)||d<0?null:Math.min(d,o),p=o-(f??0),m=K({usedBytes:f??o,availableBytes:a,totalBytes:r}),h=m===null?q(o/r):m.fraction,g=m===null?Ie(h):m.severity,_=f===null?null:m===null?q(f/r):m.recordingsFraction,v=n.cap??null,y=v===null?null:q((c+v.bytes)/r),b=v!==null&&f!==null&&f>v.bytes,x={total:j(r),freeTotal:j(a),freeTotalPercent:Y(a/r),used:j(p),usedPercent:Y(p/r),free:j(u),freePercent:Y(u/r),reserve:s===0?null:`${j(s)} kept free`,owned:f===null||_===null?null:`${j(f)} of recordings (${Y(_)})`,cap:v===null?null:v.reason===`drain`?`${j(v.bytes)} drain target (managed by CamStack)`:`${j(v.bytes)} cap (managed by CamStack)`},S=[`${x.freeTotal} free of ${x.total} (${x.freeTotalPercent} free)`,x.owned===null?null:`CamStack holds ${x.owned}`,x.reserve===null?null:l?`${x.reserve} — less free than that right now, the oldest data here is being deleted`:x.reserve,x.cap===null?null:b?`${x.cap} — already below what is stored here, the oldest is being deleted`:x.cap].filter(e=>e!==null).join(` · `),C=[];return c>0&&C.push({segment:`reserve`,label:`Kept free`,value:j(s),alarming:l}),x.owned!==null&&C.push({segment:`owned`,label:`CamStack`,value:x.owned,alarming:!1}),C.push({segment:`used`,label:f===null?`Used`:`Other data`,value:`${x.used} (${x.usedPercent})`,alarming:g===`critical`}),C.push({segment:`free`,label:`Free`,value:`${x.free} (${x.freePercent})`,alarming:l}),v!==null&&C.push({segment:`cap`,label:v.reason===`drain`?`Drain target`:`Cap`,value:`${j(v.bytes)} · managed by CamStack`,alarming:b}),{kind:`known`,severity:g,legend:C,segments:{reservePercent:J(c/r),ownedPercent:f===null?null:J(f/r),usedPercent:J(p/r),freePercent:J(u/r),capPercent:y===null?null:J(y)},labels:x,reserveExceedsFree:l,capBelowOwned:b,summary:S}}var Ve={ok:`bg-primary`,warn:`bg-amber-500`,critical:`bg-danger`},X={reserve:`bg-danger/40`,owned:`bg-foreground/50`,free:`bg-border`,cap:`bg-foreground`};function He(e,t){return e===`used`?Ve[t]:X[e]}function Ue({location:e,ownedBytes:t}){let r=e.capacity??null,i=ye(he(e.config),r?.totalBytes??null),a=Be({totalBytes:r?.totalBytes??null,availableBytes:r?.availableBytes??null},i,{ownedBytes:t??null,cap:Ce(e.config,R(e))});return a.kind===`unknown`?o(`div`,{className:`text-[10px] text-foreground-subtle italic`,title:a.summary,children:a.owned===null?`Capacity unknown`:`Capacity unknown · CamStack holds ${a.owned}`}):n(`div`,{className:`mt-1 space-y-1`,title:a.summary,children:[n(`div`,{className:`relative flex h-2 w-full max-w-md overflow-hidden rounded-full bg-border`,children:[a.segments.reservePercent>0&&o(`div`,{className:X.reserve,style:{width:`${String(a.segments.reservePercent)}%`}}),a.segments.ownedPercent!==null&&o(`div`,{className:X.owned,style:{width:`${String(a.segments.ownedPercent)}%`}}),o(`div`,{className:Ve[a.severity],style:{width:`${String(a.segments.usedPercent)}%`}}),o(`div`,{className:X.free,style:{width:`${String(a.segments.freePercent)}%`}}),a.segments.capPercent!==null&&o(`div`,{className:`absolute inset-y-0 w-px ${a.capBelowOwned?`bg-danger`:X.cap}`,style:{left:`${String(a.segments.capPercent)}%`}})]}),o(`ul`,{className:`flex flex-wrap items-center gap-x-3 gap-y-0.5`,children:a.legend.map(e=>n(`li`,{className:`flex items-center gap-1`,children:[o(`span`,{"aria-hidden":`true`,className:`inline-block h-2 w-2 shrink-0 rounded-sm ${He(e.segment,a.severity)}`}),n(`span`,{className:`text-[10px] tabular-nums ${e.alarming?`text-danger`:`text-foreground-subtle`}`,children:[e.label,` `,e.value]})]},e.segment))})]})}var We={eventMedia:[`events`],recordingsLow:[`low`],recordings:[`high`,`mid`]},Ge={eventMedia:`pipeline-analytics`,recordingsLow:`recorder`,recordings:`recorder`},Ke=`storage.discardLocation`,qe=`storage.discardLocationStatus`,Je=`storage.discardLocationCancel`;function Ye(e){return We[e]??null}function Xe(e){return Ge[e]??null}function Ze(e){return!z(R(e))}function Qe(e,t){return Ye(e.type)===null||!Ze(e)?!1:t.some(t=>t.id!==e.id&&z(R(t)))}var $e=new Set([`idle`,`scanning`,`wiping-fs`,`wiping-db`,`cascading`,`complete`,`cancelled`,`error`]);function Z(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function Q(e){return typeof e==`string`?e:null}function et(e){if(typeof e!=`object`||!e)return null;let t=e;if(typeof t.running!=`boolean`)return null;let n=t.phase;if(typeof n!=`string`||!$e.has(n))return null;let r=Z(t.camerasTotal),i=Z(t.camerasDone),a=Z(t.foldersRemoved),o=Z(t.dbRowsDeleted),s=Z(t.ownersCascaded);return r===null||i===null||a===null||o===null||s===null?null:{running:t.running,locationId:Q(t.locationId),jobId:Q(t.jobId),phase:n,camerasTotal:r,camerasDone:i,foldersRemoved:a,dbRowsDeleted:o,ownersCascaded:s,detail:Q(t.detail)??``,startedAtMs:Z(t.startedAtMs),finishedAtMs:Z(t.finishedAtMs),error:Q(t.error)}}function tt(e){if(e.phase===`complete`)return 100;if(e.phase===`cancelled`||e.phase===`error`||e.phase===`idle`)return e.camerasTotal>0?Math.min(99,Math.round(e.camerasDone/e.camerasTotal*100)):0;if(e.camerasTotal>0){let t=e.camerasDone/e.camerasTotal*85;return e.phase===`wiping-db`?Math.min(95,Math.round(t+8)):e.phase===`cascading`?Math.min(99,Math.round(t+12)):Math.min(85,Math.round(t))}return e.phase===`scanning`?2:5}t();var nt=2e3;function rt({location:e,siblings:t}){return Qe(e,t)?o(it,{location:e}):null}function it({location:e}){let t=O(),r=A(),i=Xe(e.type),[c,l]=a(null),[u,d]=a(null),[f,p]=a(!1);if(s(()=>{if(i===null)return;let e=!1,t=async()=>{try{let t=await r.mutateAsync({addonId:i,action:qe,input:{}});if(e)return;l(et(t))}catch{}};t();let n=setInterval(()=>void t(),nt);return()=>{e=!0,clearInterval(n)}},[i,e.id]),i===null)return null;let m=c!==null&&c.locationId===e.id,_=m&&c.running,v=m&&c.phase!==`idle`,y=async()=>{if(await t({title:`Discard leftovers on "${e.displayName}"?`,message:`Permanently deletes leftover files and records on this location. Other locations are not affected. This cannot be undone and may take hours.`,confirmLabel:`Discard leftovers`,variant:`danger`})){d(null),p(!0);try{await r.mutateAsync({addonId:i,action:Ke,input:{locationId:e.id}}),l(et(await r.mutateAsync({addonId:i,action:qe,input:{}})))}catch(e){d(e instanceof Error?e.message:String(e))}finally{p(!1)}}},b=async()=>{try{await r.mutateAsync({addonId:i,action:Je,input:{}})}catch(e){d(e instanceof Error?e.message:String(e))}};return n(`div`,{className:`flex flex-col gap-1 min-w-[9rem] max-w-[16rem]`,children:[_?n(`button`,{type:`button`,onClick:()=>void b(),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger border border-danger/40 hover:bg-danger/10`,children:[o(g,{className:`h-3 w-3`}),`Cancel`]}):n(`button`,{type:`button`,onClick:()=>void y(),disabled:f,title:`Permanently delete leftover files on this location. Other locations are not affected.`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger border border-danger/40 hover:bg-danger/10 disabled:opacity-50`,children:[f?o(h,{className:`h-3 w-3 animate-spin`}):o(x,{className:`h-3 w-3`}),`Discard leftovers`]}),v&&c!==null&&n(`div`,{className:`space-y-0.5`,children:[o(`div`,{className:`h-1 rounded bg-border overflow-hidden`,children:o(`div`,{className:`h-full bg-primary transition-[width] duration-300`,style:{width:`${tt(c)}%`}})}),n(`p`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[c.phase,c.camerasTotal>0?` · ${c.camerasDone}/${c.camerasTotal} cam`:``,c.dbRowsDeleted>0?` · ${c.dbRowsDeleted} rows`:``,c.detail?` · ${c.detail}`:``]})]}),(u||m&&c?.error)&&o(`p`,{className:`text-[10px] text-danger leading-tight`,children:u??c?.error})]})}t();var $={active:p,readonly:b,drain:S,disabled:u},at={active:`border-success/30 text-success hover:bg-success/10`,readonly:`border-border text-foreground-subtle hover:text-foreground hover:bg-primary/10`,drain:`border-warning/40 text-warning hover:bg-warning/10`,disabled:`border-danger/40 text-danger hover:bg-danger/10`};function ot({mode:e,open:t,onToggle:r}){let i=V(e),a=$[e];return n(`button`,{type:`button`,"aria-expanded":t,"aria-label":`Location state`,onClick:r,title:i.consequence,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium border ${at[e]}`,children:[o(a,{className:`h-3 w-3`}),i.label,o(v,{className:`h-3 w-3 ${t?`rotate-180`:``}`})]})}function st({mode:e,blockedReasons:t,onSelect:r,onDismiss:i}){return s(()=>{let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e)}},[i]),n(`div`,{className:`w-full basis-full rounded-lg border border-border bg-background p-1`,role:`group`,"aria-label":`Location state choices`,children:[n(`div`,{className:`flex items-center justify-between px-2 py-1`,children:[o(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Location state`}),o(`button`,{type:`button`,"aria-label":`Close location state choices`,onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:o(g,{className:`h-3 w-3`})})]}),B.map(a=>{let s=t[a.mode],c=s!==``,l=$[a.mode],u=a.mode===e;return n(`button`,{type:`button`,role:`radio`,"aria-checked":u,"aria-label":a.label,disabled:c,onClick:()=>{c||(i(),u||r(a.mode))},className:`flex w-full flex-col items-start gap-0.5 rounded px-2 py-1.5 text-left ${c?`cursor-not-allowed opacity-60`:u?`bg-primary/10`:`hover:bg-primary/5`}`,children:[n(`span`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-foreground`,children:[o(l,{className:`h-3 w-3`}),a.label,u&&o(`span`,{className:`text-[9px] uppercase text-primary`,children:`current`})]}),o(`span`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:a.consequence}),c&&o(`span`,{className:`text-[10px] leading-snug text-warning`,children:s})]},a.mode)})]})}t();function ct(e){let t=e.basePath;if(typeof t==`string`&&t.length>0)return t;let n=Object.keys(e);return n.length===0?``:n.join(`, `)}function lt({location:e,onEdit:t,onDelete:r,onSetMode:i,blockedReasons:s,canDelete:c,siblings:u=[],drain:d,ownedBytes:p}){let[m,h]=a(!1),g=ct(e.config),_=R(e);return n(`div`,{className:`flex flex-wrap items-start gap-x-3 gap-y-2 px-3 py-2 border-t border-border first:border-t-0 hover:bg-primary/5`,children:[n(`div`,{className:`flex items-start gap-2 min-w-0 flex-1 basis-72`,children:[o(`div`,{className:`shrink-0 sm:w-32`,"data-testid":`location-badge-slot`,children:o(`span`,{className:`inline-block text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5 font-mono`,children:e.providerId})}),n(`div`,{className:`min-w-0 flex-1`,children:[o(`div`,{className:`text-xs font-medium text-foreground truncate`,children:e.displayName}),g&&o(`div`,{className:`text-[10px] text-foreground-subtle truncate font-mono`,children:g}),o(Ue,{location:e,ownedBytes:p??null}),d!==void 0&&o(Pe,{drain:d})]})]}),n(`div`,{className:`flex flex-wrap items-center gap-1 shrink-0`,children:[o(rt,{location:e,siblings:u}),o(ot,{mode:_,open:m,onToggle:()=>{h(e=>!e)}}),n(`button`,{onClick:()=>t(e),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle border border-border hover:text-foreground hover:bg-primary/10`,children:[o(f,{className:`h-3 w-3`}),`Edit`]}),c&&o(`button`,{onClick:()=>r(e),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10`,title:`Delete location`,children:o(l,{className:`h-3 w-3`})})]}),m&&o(st,{mode:_,blockedReasons:s,onSelect:t=>i(e,t),onDismiss:()=>{h(!1)}})]})}t();function ut({type:e,displayName:t,description:i,cardinality:a,locations:s,onAdd:l,onEdit:u,onDelete:f,onSetMode:p,ownedBytesById:m,drainById:h}){let g=r(()=>{let e=[...s];return e.sort((e,t)=>{let n=z(R(e));return n===z(R(t))?e.displayName.localeCompare(t.displayName):n?-1:1}),e},[s]);return n(D,{headingId:`storage-location-${e}`,title:t,icon:y,testId:`storage-location-group-${e}`,actions:a===`multi`?n(T,{size:`sm`,type:`button`,onClick:()=>l(e),children:[o(d,{className:`h-3 w-3`}),`Add`]}):void 0,children:[n(`div`,{className:`${c} space-y-2`,children:[n(`div`,{className:`space-y-0.5`,children:[o(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5 font-mono`,children:e}),i!==void 0&&i!==``&&o(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:i}),a===`single`&&o(`p`,{className:`text-[10px] text-foreground-subtle italic`,children:`Single — one location per type. Edit the existing entry; it can't be split.`})]}),g.length===0&&o(`div`,{className:`py-2 text-center text-[11px] text-foreground-subtle italic`,children:a===`multi`?`No location registered. Click "Add" to register one.`:`No location registered yet — should be auto-seeded at next boot.`})]}),g.length>0&&o(`div`,{className:`border-t border-border`,children:g.map(e=>o(lt,{location:e,cardinality:a,canDelete:fe(e,g,a),onEdit:u,onDelete:f,onSetMode:p,blockedReasons:de(e,g),ownedBytes:m?.get(e.id)??null,drain:Ae(je(e),h?.get(e.id)),siblings:g},e.id))})]})}var dt=[`recordings`,`recordingsLow`];function ft(e){return e.locationIds!==void 0&&e.locationIds.length>0?e.locationIds:e.locationId===null?[]:[e.locationId]}function pt(e,t){if(t===void 0||!dt.includes(e.type))return null;let n=t.find(t=>ft(t).includes(e.id));return n===void 0||!Number.isFinite(n.usedBytes)||n.usedBytes<0?null:n.usedBytes}function mt(e,t){let n=new Map;for(let r of e){let e=pt(r,t);e!==null&&n.set(r.id,e)}return n}export{Oe as a,V as c,Re as i,le as l,ut as n,Te as o,K as r,pe as s,mt as t,L as u};
|
|
@@ -12,8 +12,8 @@ const __mfImport = (src) =>
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
(async () => {
|
|
15
|
-
const __mfHostInit = await __mfImport("./hostInit-
|
|
15
|
+
const __mfHostInit = await __mfImport("./hostInit-CU4FJ_9p.js");
|
|
16
16
|
await __mfHostInit.__tla;
|
|
17
17
|
const { initHost } = __mfHostInit;
|
|
18
18
|
await initHost();
|
|
19
|
-
})().then(() => __mfImport("./index-
|
|
19
|
+
})().then(() => __mfImport("./index-AsTGrKva.js"));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./src-CIIJy_o8.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Q as e,S as t,W as n,b as r,i,q as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{It as s,On as c,Qi as l,dn as u,dt as d,ot as f}from"./player-overlays-C20AJTgs.js";import{Ar as p,At as m,Ct as h,Dt as g,Et as ee,F as te,G as ne,I as re,In as ie,K as ae,Ln as oe,M as se,N as ce,O as le,Ot as ue,P as de,R as fe,St as pe,Tt as _,ct as v,dt as me,et as he,ft as ge,gt as _e,ht as ve,it as ye,jt as be,kt as xe,lt as y,nt as Se,pt as Ce,rt as b,st as x,tt as we,vt as S,wt as C,yt as Te}from"./client-CKGZv6zJ.js";import{Gl as w,Xl as T,Ya as Ee,bc as De,d as Oe,nr as ke,vc as Ae}from"./src-Bqr9lpc6.js";import{t as E}from"./useTranslation-Bc5yH9V9.js";e();function D(e){return t=>Object.prototype.hasOwnProperty.call(e,t)}var je=D({devices:!0}),Me=D({classes:!0,classesExclude:!0,labelEquals:!0,identities:!0,identitiesExclude:!0,eventTypeTokens:!0,sensorKinds:!0}),Ne=D({minConfidence:!0,minImportance:!0,minLabelConfidence:!0}),Pe=D({minDwellSeconds:!0}),Fe=D({source:!0}),Ie=D({crossing:!0}),Le=D({packagePhase:!0}),Re=D({sensorTransition:!0}),ze=D({plates:!0}),Be=D({occupancy:!0}),Ve=D({audio:!0}),He=D({systemEvent:!0}),Ue=D({deviceState:!0}),We=D({scene:!0});function Ge(e,t){let n=e[t];return Array.isArray(n)?n:[]}function Ke(e,t){let n=e[t];return typeof n==`number`?n:void 0}function O(e,t){let r=f().trpcClient,a=i({queries:e.map(e=>({queryKey:[[`nc-pickers`,`zones`],{deviceId:e}],staleTime:3e4,queryFn:async()=>({deviceId:e,zones:(await r.zones.listZones.query({deviceId:e})).map(e=>({id:e.id,name:e.name}))})}))});return n(()=>{let e=[],n=new Set;for(let r of a){if(!r.data)continue;let i=t.find(e=>e.id===r.data.deviceId)?.name;for(let t of r.data.zones)n.has(t.id)||(n.add(t.id),e.push({value:t.id,label:t.name,...i===void 0?{}:{hint:i}}))}return{options:e,loading:a.some(e=>e.isLoading),failed:a.some(e=>e.isError)}},[a,t])}function qe(e){let t=f().trpcClient,r=i({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 n(()=>{let e=new Map;for(let t of r)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:r.some(e=>e.isLoading)}},[r])}function Je(){let e=Ee();return n(()=>({options:(e.data??[]).map(e=>({value:e.id,label:e.name})),loading:e.isLoading,failed:e.isError===!0}),[e.data,e.isLoading,e.isError])}function Ye(){let e=Ae({limit:200}),t=De();return n(()=>{let n=new Set;for(let e of t.data??[])e.name.trim().length>0&&n.add(e.name);let r=new Set;for(let t of e.data??[])t.text.trim().length>0&&r.add(t.text);return[...[...n].sort(),...[...r].sort()]},[e.data,t.data])}function k({options:e,value:r,onChange:i,loading:s,emptyHint:c,placeholder:l,noFreeText:u=!1}){let[d,f]=a(``),p=n(()=>new Set(e.map(e=>e.value)),[e]),m=n(()=>new Set(r),[r]),h=r.filter(e=>!p.has(e)),g=e=>{i(m.has(e)?r.filter(t=>t!==e):[...r,e])},ee=()=>{let e=d.trim();e.length===0||r.includes(e)||(i([...r,e]),f(``))};return t(`div`,{className:`mt-1 space-y-1.5`,children:[h.length>0&&o(`div`,{className:`flex flex-wrap gap-1`,children:h.map(e=>t(`button`,{type:`button`,onClick:()=>i(r.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?o(`div`,{className:`max-h-40 overflow-y-auto rounded-md border border-border divide-y divide-border`,children:e.map(e=>t(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[o(`input`,{type:`checkbox`,checked:m.has(e.value),onChange:()=>g(e.value),className:`accent-primary`}),o(`span`,{className:`flex-1 truncate`,children:e.label}),e.hint!==void 0&&o(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.hint})]},e.value))}):o(`p`,{className:`text-[10px] text-foreground-subtle`,children:s===!0?`Loading…`:c}),!u&&o(`input`,{value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),ee())},placeholder:l,className:`w-full rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground placeholder:text-foreground-subtle`})]})}var A=[{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, or an occupancy edge on a linked device.`},{value:`package-event`,label:`Package event`,hint:`A parcel delivery or pick-up.`},{value:`system-event`,label:`System event`,hint:`The installation itself: a camera or stream going offline, a node leaving the cluster, an addon or server update becoming available.`}],j=`Immediate, grouped`,Xe=A.flatMap(e=>e.value===`immediate`?[e,{value:`immediate-grouped`,label:j,hint:`Waits for subjects to be recognised, then sends one message with a mosaic, one picture per subject.`}]:[e]);function Ze(e){return e.groupingSec!==void 0&&x(e)?`immediate-grouped`:e.delivery}function Qe(e){let t=(e.delivery===`immediate`||e.delivery===`track-end`)&&x({delivery:`immediate`,conditions:e.conditions});return Xe.filter(e=>e.value!==`immediate-grouped`||t)}function $e(e){return Xe.find(t=>t.value===e)?.value}function et(e,t=j){return Ze(e)===`immediate-grouped`?`${t} · ${String(e.groupingSec)} s`:nt(e.delivery)}function tt(e){if(e.trim().length===0)return;let t=Number(e);return Number.isFinite(t)&&t>=0?Math.trunc(t):void 0}function nt(e){return A.find(t=>t.value===e)?.label??e}function rt(e){return A.some(t=>t.value===e)}var it=[{key:`all`,label:`All rules`,blurb:`Every notification rule — event-driven and scheduled producers. Tabs filter this same list; pick the type under New rule when creating from here.`,newRuleLabel:`New rule`,emptyHint:`No rules yet. Click "New rule" and pick a kind (Detection, Summary, Calendar events, …).`,creatable:!0},{key:`detection`,label:`Detections`,blurb:`Rules driven by what the cameras SEE — detections, tracks and package events. Doorbell presses and other sensor changes have their own section now (operator ruling, 2026-10-01).`,newRuleLabel:`New detection rule`,emptyHint:`No detection rules yet. Click "New detection rule" to author one.`,creatable:!0},{key:`sensor`,label:`Sensors`,blurb:`Rules driven by a device or sensor CHANGING STATE — a doorbell press, a linked sensor opening or closing. The picture is one snapshot of the camera the sensor is attributed to; there is no media choice to make.`,newRuleLabel:`New sensor rule`,emptyHint:`No sensor rules yet. Click "New sensor rule" to be told when a doorbell is pressed or a linked sensor changes.`,creatable:!0},{key:`audio`,label:`Sound`,blurb:`Rules on what the cameras HEAR: a sustained window of sound loud enough, or classified as one of the sounds you name. A sound rule is an immediate rule carrying the sound condition — it fires only on a confirmed sampling window, never on a picture.`,newRuleLabel:`New sound rule`,emptyHint:`No sound rules yet. Click "New sound rule" — it opens on the sound condition already filled in with a level threshold, so you only have to name the sounds and the targets.`,creatable:!0},{key:`occupancy`,label:`Occupancy`,blurb:`Rules on how many objects are in a camera frame or a zone, and for how long: "the driveway became occupied", "the garden emptied". An occupancy rule is a device-event rule carrying the occupancy condition.`,newRuleLabel:`New occupancy rule`,emptyHint:`No occupancy rules yet. Click "New occupancy rule" — it opens on the occupancy condition; pick the camera on the Devices tab, then the zone and the count.`,creatable:!0},{key:`device-events`,label:`Device events`,blurb:`Rules about your devices: offline or back, switched off or on, a stream dropping, a battery or consumable running low, a camera detecting nothing. These carry no image.`,newRuleLabel:`New device-event rule`,emptyHint:`No device-event rules yet. Click "New device-event rule" to be told when a device drops, a battery runs low or a camera goes blind.`,creatable:!0},{key:`system`,label:`System events`,blurb:`Rules about the installation itself: a node leaving the cluster, an addon crash-looping, an update available or installed, a backup or export finishing. These carry no image and are not tied to a detection.`,newRuleLabel:`New system rule`,emptyHint:`No system rules yet. Click "New system rule" to be told when a node leaves, an update lands or a backup finishes.`,creatable:!0},{key:`alarm`,label:`Alarm`,blurb:`Rules about the alarm panel: arming, armed, triggered, disarmed, and the refusals in between.`,newRuleLabel:`New alarm rule`,emptyHint:`No alarm rules yet. Click "New alarm rule" to be told when the alarm arms, goes off or is disarmed.`,creatable:!0},{key:`mixed`,label:`To recreate`,blurb:`System rules authored before the three families existed. Each mixes families and keeps firing as it is, but it cannot be edited: recreate it as one rule per family (Device events, System events, Alarm). Open none of them: Delete each once its replacements exist.`,newRuleLabel:`New rule`,emptyHint:`Nothing to recreate.`,creatable:!1}];function at(e){return y(v(e)).editable}function ot(e){return ye(st(e))}function st(e){switch(e){case`device-events`:case`system`:case`alarm`:case`mixed`:return e;default:return}}var ct=new Map([[0,`No cooldown`],[60,`1 minute`],[3600,`1 hour`]]),lt=86400;function ut(e){let t=ct.get(e);return t===void 0?e%3600==0?`${e/3600} hours`:e%60==0?`${e/60} minutes`:`${e} seconds`:t}function dt(e){if(e.trim().length===0)return;let t=Number(e);return Number.isFinite(t)&&t>=0?Math.trunc(t):void 0}var ft=[{value:`rule-device`,label:`Per device`},{value:`rule`,label:`Whole rule (one window for every device)`}];function pt(e){return ft.find(t=>t.value===e)?.value}var mt=[{value:`per-class`,label:`Separate windows per class (default)`},{value:`shared`,label:`Shared across classes`}];function ht(e){return mt.find(t=>t.value===e)?.value}var gt=[{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 _t(e){return gt.find(t=>t.value===e)?.value}var M=[{value:``,label:`Automatic`},{value:`cropped`,label:`Cropped on the subject`},{value:`full`,label:`Full frame`},{value:`boxed`,label:`Full frame with boxes`}];function vt(e){let t=M.find(t=>t.value===e)?.value;return t===``?void 0:t}var N=[{value:``,label:`Mosaic of every linked camera (default)`},{value:`mosaic`,label:`Mosaic of every linked camera`},{value:`each`,label:`One image per camera (first camera where only one is allowed)`}];function yt(e){let t=N.find(t=>t.value===e)?.value;return t===``?void 0:t}var P=[{value:``,label:`Lowest available`},{value:`low`,label:`Low`},{value:`mid`,label:`Medium`},{value:`high`,label:`High`}];function bt(e){let t=P.find(t=>t.value===e)?.value;return t===``?void 0:t}var xt=[{value:`any`,label:`Any source`},{value:`pipeline`,label:`Pipeline`},{value:`onboard`,label:`Onboard (camera)`},{value:`sensor`,label:`Sensor`}],St=[{value:`delivered`,label:`Delivered`},{value:`picked-up`,label:`Picked up`},{value:`both`,label:`Both`}],Ct=[{value:``,label:`It triggers and when it clears`},{value:`raised`,label:`Only when it triggers`},{value:`cleared`,label:`Only when it clears`}];function wt(e){return e===`raised`||e===`cleared`?e:void 0}function F(e,t){return e===`sensorTransition`?ae(t.sensorKinds):!0}var Tt=[{value:`enter`,label:`Entering`},{value:`exit`,label:`Leaving`},{value:`any`,label:`Entering or leaving`}],Et=`enter`;function I(e){return e===`exit`||e===`any`?e:void 0}var Dt=[{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 Ot(e,t){return e.options&&e.options.length>0?e.options:t}var kt=[{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 At(e){if(e===``)return;let t=Number(e);return Number.isFinite(t)&&t>=1&&t<=8?t:void 0}var jt=new Map(Object.entries({"device-offline":`Device offline`,"device-online":`Device online`,"device-disabled":`Device switched off`,"device-enabled":`Device switched on`,"stream-offline":`Stream offline`,"stream-online":`Stream online`,"device-battery-low":`Battery low`,"device-battery-normal":`Battery back to normal`,"device-consumable-low":`Consumable low`,"device-consumable-normal":`Consumable back to normal`,"device-tank-low":`Tank low (water, detergent)`,"device-tank-full":`Tank full (dirty water, dust)`,"device-tank-normal":`Tank back to normal`,"detection-blind":`Camera detecting nothing`,"recording-stalled":`Recording stalled`,"recording-healthy":`Recording healthy again`,"recording-degraded":`Recording degraded (restart storm)`,"storage-location-low":`Storage location low`,"storage-location-critical":`Storage location critical`,"storage-location-ok":`Storage location ok again`,"node-offline":`Node offline`,"node-online":`Node online`,"node-restarting":`Node restarting`,"node-updating":`Node updating (restart imminent)`,"node-inference-unavailable":`Node has no usable inference device`,"addon-crash-loop":`Addon stopped after repeated crashes`,"addon-update-available":`Addon update available`,"addon-updated":`Addons updated`,"server-update-available":`Server update available`,"server-updated":`Server updated`,"wrapper-update-available":`Container / app update available`,"export-completed":`Export completed`,"backup-completed":`Backup completed`,"alarm-arm-refused":`Alarm arm refused (something is open)`,"alarm-check-failed":`Alarm check failed (armed anyway)`,"alarm-arming":`Alarm arming (exit delay)`,"alarm-armed":`Alarm armed`,"alarm-pending":`Alarm entry delay started`,"alarm-triggered":`Alarm triggered`,"alarm-rearmed":`Alarm re-armed after siren`,"alarm-sensor-bypass":`Alarm sensor bypass`,"alarm-disarmed":`Alarm disarmed`}));function Mt(e){return jt.get(e)}var Nt={"device-state":`A device the hub can no longer reach, or that came back. Switched off / on is a device an operator turned off or back on — not a fault, a choice.`,streams:`A stream that stopped or came back.`,battery:`A battery below the cluster threshold, and (optionally) its return to normal. Devices with a binary low-battery indicator are judged by the indicator, not by the percentage.`,consumables:`A consumable — filter, brush, bag — at or below this rule’s threshold, or that the device reports as due for replacement, and (optionally) its return to normal after a change. A device that only says "replace" is judged by that, not by a percentage.`,tanks:`A robot vacuum tank the device reports as running low (clean water, detergent) or full (dirty water, dust bin), and (optionally) its return to normal once refilled or emptied.`,"detection-blind":`A camera that is running and being analysed, but detects nothing — up, and producing no work.`,recording:`A camera whose recording is on but no footage is landing (stall), a writer that burned its restart budget (degraded), and (optionally) the return to healthy writing.`,nodes:`An agent or worker node joining or leaving the cluster, or an online node whose inference devices all went away.`,addons:`An addon the hub has stopped restarting after repeated crashes.`,"addon-updates":`A newer version of an addon, or an addon update that just finished.`,updates:`A newer version of the server itself, or of the container / app the node runs inside, is available — or a server update just finished.`,"backups-exports":`A scheduled or manual backup of the hub finished, or a footage export finished rendering.`,storage:`A storage location running low or critical on free space — or whose capacity probe failed — and (optionally) its return to ok.`,alarm:`The alarm panel refusing to arm, arming, armed, counting down to a siren, going off, re-arming, excluding an open sensor, or being disarmed.`},L=_e.map(e=>({id:e.id,family:e.family,label:e.label,hint:Nt[e.id]??``,kinds:e.kinds.flatMap(e=>{let t=Mt(e);return t===void 0?[]:[{value:e,label:t}]})}));function R(e){return L.filter(t=>t.family===e)}function z(e){let t=me(e).conditions.systemEvent;return t===void 0?{kinds:(R(e)[0]?.kinds??[]).map(e=>e.value)}:{...t,kinds:[...t.kinds]}}var B=L.flatMap(e=>e.kinds);function V(e){return B.find(t=>t.value===e)?.label??e}function Pt(e){return{devices:S(e,`deviceIds`),deviceTypes:S(e,`deviceTypes`),nodes:S(e,`nodeIds`),packages:S(e,`packageNames`),consumableThreshold:S(e,`consumableLowPercent`)}}function H(e,t){let n=ve[e],r=Pt(t);return{devices:n.includes(`deviceIds`)&&r.devices,excludeDevices:n.includes(`excludeDeviceIds`)&&r.devices,deviceTypes:n.includes(`deviceTypes`)&&r.deviceTypes,nodes:n.includes(`nodeIds`)&&r.nodes,packages:n.includes(`packageNames`)&&r.packages,consumableThreshold:n.includes(`consumableLowPercent`)&&r.consumableThreshold}}var Ft=Object.values(p).map(e=>({value:e,label:It(e)})).toSorted((e,t)=>e.label.localeCompare(t.label));function It(e){let t=e.replaceAll(`-`,` `);return t.charAt(0).toUpperCase()+t.slice(1)}function Lt(e,t,n){if(!R(n).some(e=>e.kinds.some(e=>e.value===t)))return e;let r=e?.kinds??[];return r.length===1&&r[0]===t?e:Bt(e,r.includes(t)?r.filter(e=>e!==t):B.filter(e=>e.value===t||r.includes(e.value)).map(e=>e.value),n)}function Rt(e,t){return t===void 0?void 0:Bt(t,t.kinds,e)}function zt(e,t){let n=e?.kinds??[];if(n.length===0)return;let r=U(t,`deviceIds`,e?.deviceIds),i=U(t,`excludeDeviceIds`,e?.excludeDeviceIds),a=U(t,`deviceTypes`,e?.deviceTypes),o=U(t,`nodeIds`,e?.nodeIds),s=U(t,`packageNames`,e?.packageNames),c=Object.prototype.hasOwnProperty.call(t,`consumableLowPercent`)?t.consumableLowPercent:e?.consumableLowPercent;return{kinds:[...n],...r===void 0?{}:{deviceIds:[...r]},...i===void 0?{}:{excludeDeviceIds:[...i]},...a===void 0?{}:{deviceTypes:[...a]},...o===void 0?{}:{nodeIds:[...o]},...s===void 0?{}:{packageNames:[...s]},...c===void 0?{}:{consumableLowPercent:c}}}function U(e,t,n){let r=Object.prototype.hasOwnProperty.call(e,t)?e[t]:n;return r!==void 0&&r.length===0?void 0:r}function Bt(e,t,n){let r=H(n,t),i=r.devices?e?.deviceIds:void 0,a=r.excludeDevices?e?.excludeDeviceIds:void 0,o=r.deviceTypes?e?.deviceTypes:void 0,s=r.nodes?e?.nodeIds:void 0,c=r.packages?e?.packageNames:void 0,l=r.consumableThreshold?e?.consumableLowPercent:void 0;return{kinds:[...t],...i&&i.length>0?{deviceIds:[...i]}:{},...a&&a.length>0?{excludeDeviceIds:[...a]}:{},...o&&o.length>0?{deviceTypes:[...o]}:{},...s&&s.length>0?{nodeIds:[...s]}:{},...c&&c.length>0?{packageNames:[...c]}:{},...l===void 0?{}:{consumableLowPercent:l}}}var Vt=95;function Ht(e){let t=e.trim();if(t===``)return{kind:`clear`};let n=Number(t);return Number.isInteger(n)&&n>=1&&n<=Vt?{kind:`set`,value:n}:{kind:`invalid`}}function Ut(e,t=2){if(e===void 0||e.length===0)return`No event selected`;let n=e.slice(0,t).map(V).join(`, `),r=e.length-Math.min(t,e.length);return r>0?`${n} +${r}`:n}function Wt(e){if(e===void 0)return`—`;let t=[],n=e.deviceIds?.length??0,r=e.deviceTypes?.length??0,i=e.nodeIds?.length??0,a=e.packageNames?.length??0,o=e.excludeDeviceIds?.length??0;r>0&&t.push(e.deviceTypes?.map(It).join(`, `)??``),n>0&&t.push(`${n} device${n===1?``:`s`}`),i>0&&t.push(`${i} node${i===1?``:`s`}`),a>0&&t.push(`${a} package${a===1?``:`s`}`);let s=o>0?`except ${o} device${o===1?``:`s`}`:null,c=e.consumableLowPercent===void 0?[]:[`consumables at ${e.consumableLowPercent}%`];return t.length===0?[s===null?`Everything`:`Everything ${s}`,...c].join(` · `):[...t,...s===null?[]:[s],...c].join(` · `)}function Gt(e){return e===void 0||(e.deviceTypes?.length??0)===0?!1:e.kinds.some(e=>ie.includes(e))}var Kt=[`all`,`only`,`except`];function qt(e,t){return(e??[]).length>0?`only`:(t??[]).length>0?`except`:`all`}function W(e,t){let n=[...e??[]],r=[...t??[]];return{mode:qt(n,r),include:n,exclude:r,legacyBoth:n.length>0&&r.length>0}}function Jt(e,t){return{...e,mode:t}}function Yt(e){switch(e.mode){case`only`:return e.include;case`except`:return e.exclude;case`all`:return[]}}function Xt(e,t){switch(e.mode){case`only`:return{...e,include:[...t]};case`except`:return{...e,exclude:[...t]};case`all`:return e}}function Zt(e){return e.mode===`only`&&e.legacyBoth?e.exclude:[]}function Qt(e){return{...e,exclude:[],legacyBoth:!1}}function G(e){switch(e.mode){case`all`:return{};case`except`:return e.exclude.length>0?{exclude:[...e.exclude]}:{};case`only`:{let t=Zt(e);return{...e.include.length>0?{include:[...e.include]}:{},...t.length>0?{exclude:[...t]}:{}}}}}function $t(e){let t=G(e),n=t.include??[],r=t.exclude??[];return[...e.include.filter(e=>!n.includes(e)),...e.exclude.filter(e=>!r.includes(e))]}var K=[`onActivation`,`onDeactivation`,`onTrigger`,`onTriggerOff`],q={onActivation:{title:`On activation`,hint:`Runs when the rule is turned on.`},onDeactivation:{title:`On deactivation`,hint:`Runs when the rule is turned off.`},onTrigger:{title:`On trigger`,hint:`Runs on a positive / raised match.`},onTriggerOff:{title:`On trigger off`,hint:`Runs on a clear / leave match. Delivery types without a clear edge never fire this.`}},en={onActivation:[],onDeactivation:[],onTrigger:[],onTriggerOff:[],buttons:[]};function tn(e){return e===void 0?en:{onActivation:[...e.onActivation??[]],onDeactivation:[...e.onDeactivation??[]],onTrigger:[...e.onTrigger??[]],onTriggerOff:[...e.onTriggerOff??[]],buttons:[...e.buttons??[]]}}function J(e){let t=e.buttons.filter(e=>e.id.trim()!==``&&e.label.trim()!==``&&e.sequenceId.trim()!==``),n={onActivation:e.onActivation,onDeactivation:e.onDeactivation,onTrigger:e.onTrigger,onTriggerOff:e.onTriggerOff};if(!(!K.some(e=>n[e].length>0)&&t.length===0))return{...n.onActivation.length>0?{onActivation:[...n.onActivation]}:{},...n.onDeactivation.length>0?{onDeactivation:[...n.onDeactivation]}:{},...n.onTrigger.length>0?{onTrigger:[...n.onTrigger]}:{},...n.onTriggerOff.length>0?{onTriggerOff:[...n.onTriggerOff]}:{},...t.length>0?{buttons:t}:{}}}function nn(e,t){let n=[];for(let r of K){let i=e[r];i.length>4&&n.push({kind:`too-many`,message:`${q[r].title} has more than 4 bindings.`});for(let e of i)e.kind===`sequence`&&!t.has(e.sequenceId)&&n.push({kind:`unknown-sequence`,message:`${q[r].title} points at a sequence that does not exist.`})}let r=new Set;for(let i of e.buttons){let e=i.id.trim();e!==``&&(r.has(e)&&n.push({kind:`duplicate-button`,message:`Two buttons share the id "${e}". The id is what the audit line names when one is tapped.`}),r.add(e),t.has(i.sequenceId.trim())||n.push({kind:`unknown-sequence`,message:`"${i.label||e}" points at a sequence that does not exist. It would never appear on a notification.`}))}return n}function rn(e,t){return{id:`action-${String(e+1)}`,label:`Action`,sequenceId:t}}function an(){return{kind:`do`,action:{kind:`cap`,deviceId:0,cap:``,method:``}}}function on(e){return{kind:`sequence`,sequenceId:e}}function sn(){return{kind:`wait`,seconds:5}}var cn=[{value:`acknowledge`,label:`Acknowledge`},{value:`dismiss`,label:`Dismiss`},{value:`silence`,label:`Silence`},{value:`snooze`,label:`Snooze`},{value:`view`,label:`View`},{value:`play`,label:`Play`},{value:`camera`,label:`Camera`},{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:`arm-home`,label:`Arm — home`},{value:`arm-away`,label:`Arm — away`},{value:`arm-night`,label:`Arm — night`},{value:`light`,label:`Light`},{value:`alert`,label:`Alert`}],ln=[10,30,60],un=[5,10,15,30,60,120,240,480];function dn(e){return e>=60&&e%60==0?`${e/60} h`:`${e} min`}var fn=new Set([`alarm-arm-refused`,`alarm-check-failed`,`alarm-arming`,`alarm-armed`,`alarm-pending`,`alarm-triggered`,`alarm-rearmed`,`alarm-sensor-bypass`,`alarm-disarmed`]),pn=`alarm-panel`;function mn(e,t){for(let t of e.systemEvent?.kinds??[])if(fn.has(t))return!0;for(let e of t)if(e.kind===`cap`&&e.cap===pn)return!0;return!1}function hn(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[];for(let t of[`onActivation`,`onDeactivation`,`onTrigger`,`onTriggerOff`])for(let i of e[t])if(i.kind===`do`)r.push(i.action);else{let e=n.get(i.sequenceId);e!==void 0&&r.push(...e.actions)}for(let t of e.buttons){let e=n.get(t.sequenceId);e!==void 0&&r.push(...e.actions)}return r}function gn(e){let{devices:t,devicesExclude:n,classes:r,classesExclude:i,...a}=e;return{conditions:a,deviceScope:W(t,n),classScope:W(r,i)}}function _n(e){let t=G(e.deviceScope),n=G(e.classScope);return{...e.conditions,...t.include===void 0?{}:{devices:[...t.include]},...t.exclude===void 0?{}:{devicesExclude:[...t.exclude]},...n.include===void 0?{}:{classes:[...n.include]},...n.exclude===void 0?{}:{classesExclude:[...n.exclude]}}}function vn(e){return e.deviceScope.mode===`only`?e.deviceScope.include:[]}function yn(e,t,n){let r=v(n);return e.some(e=>e.id===t&&we(e,n.delivery,r))}function bn(e=`immediate`,t={}){return{name:``,enabled:!0,delivery:e,targetIds:[],targetUsers:[],targetParams:{},priority:3,mediaAttach:`best`,mediaZoneCrop:!1,mediaFrame:void 0,mediaGif:!1,mediaClip:!1,mediaProfile:void 0,mediaClipSpeed:void 0,mediaLinkedCameras:void 0,templateTitle:``,templateBody:``,...gn(t),schedule:void 0,systemEventDelivery:void 0,snoozeAllowGlobal:!1,groupingSec:void 0,snoozeOptions:void 0,actions:en,cooldownSec:30,cooldownScope:`rule-device`,cooldownGranularity:void 0}}function xn(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,mediaLinkedCameras:e.media.linkedCameras,templateTitle:e.template?.title??``,templateBody:e.template?.body??``,...gn(e.conditions),schedule:e.schedule,systemEventDelivery:e.systemEventDelivery,snoozeAllowGlobal:e.snoozeAllowGlobal===!0,groupingSec:e.groupingSec,snoozeOptions:e.snoozeOptions,actions:tn(e.actions),cooldownSec:e.throttle.cooldownSec,cooldownScope:e.throttle.scope,cooldownGranularity:e.throttle.granularity}}function Sn(e,t){let n=[];if(On(e)){let r=e.groupingSec;r!==void 0&&(!Number.isInteger(r)||r<5||r>60)&&n.push(`The grouping window is a whole number of seconds between 5 and 60.`);let i=t?.confirm;i?.enabled===!0&&i.expect!==void 0&&!kn(i.expect)&&n.push(`This rule’s AI confirm expects more than one subject, but a grouped message judges one picture per subject, so it would never send. Remove the confirm expectation (viewer or API), or choose Immediate.`)}if(_(e.conditions.audio)&&n.push(`This sound rule names neither a sound nor a level threshold, so it can never fire — every sample would count as a hit and the engine refuses it rather than notifying on silence. Pick at least one sound, or add a level.`),(!Number.isInteger(e.cooldownSec)||e.cooldownSec<0||e.cooldownSec>86400)&&n.push(`The cooldown is a whole number of seconds between 0 and ${String(lt)} (24 hours). 0 means every match is delivered.`),Y(e))for(let t of re({delivery:e.delivery,conditions:e.conditions,...e.systemEventDelivery===void 0?{}:{systemEventDelivery:e.systemEventDelivery},...J(e.actions)===void 0?{}:{actions:J(e.actions)}}))n.push(se(t));return n}function Cn(e){let t=e.systemEventDelivery;if(t===void 0)return{};if(!b(e.delivery))return t.mode===`summary`?{systemEventDelivery:{mode:`instant`}}:{};if(t.mode===`summary`&&te(t.schedule)===null){let e=de(t.schedule);if(e!==null&&e.times.length>0)return{systemEventDelivery:{...t,schedule:ce(e.times,t.schedule.timezone)}}}return{systemEventDelivery:t}}function wn(e){if(!Y(e))return null;if(!fe(e.templateBody))return`This body names none of the summary ({{summaryText}} or a section variable) — the hub appends {{summaryText}} to it when it sends.`;let t=e.templateBody;return(e.systemEventDelivery?.mode===`summary`?e.systemEventDelivery.split:void 0)===`section`&&t.trim().length>0&&!/\{\{\s*summaryText\s*\}\}/.test(t)?`Sent one per category: this body names no {{summaryText}}, so on every other category’s notification the hub appends {{summaryText}} (that category’s lines).`:null}function Y(e){return b(e.delivery)&&e.systemEventDelivery?.mode===`summary`}function Tn(e,t,n=new Set){return Sn(e,t).length===0&&rt(e.delivery)&&(!b(e.delivery)||Nn(e)>0)&&v(e)!==`mixed`&&e.name.trim().length>0&&(e.targetIds.length>0||e.targetUsers.length>0)&&nn(e.actions,n).length===0}function En(e,t){let n=jn(e.conditions,t);return b(t)&&(n.systemEvent?.kinds.length??0)===0?{...e,delivery:t,conditions:{...n,systemEvent:z(`device-events`)}}:{...e,delivery:t,conditions:n}}function Dn(e,t){return t===`immediate-grouped`?{...En(e,`immediate`),groupingSec:e.groupingSec??20}:{...En(e,t),groupingSec:void 0}}function On(e){return e.groupingSec!==void 0&&x(e)}function kn(e){switch(e.op){case`>`:return 1>e.count;case`<=`:return 1<=e.count;case`<`:return 1<e.count;case`==`:return e.count===1;default:return 1>=e.count}}var An=new Set([`immediate`,`track-end`,`package-event`]);function jn(e,t){if(e.source!==`pipeline`||An.has(t))return e;let{source:n,...r}=e;return r}function Mn(e,t){return Ce(e.conditions.systemEvent)===t?e:{...e,conditions:{...e.conditions,systemEvent:z(t)}}}function Nn(e){return e.conditions.systemEvent?.kinds.length??0}function X(e,t){return e.appliesTo.includes(t)}var Pn={source:`any`};function Fn(e,t){if(t==null)return!0;if(Array.isArray(t))return t.length===0;if(typeof t==`string`)return t.length===0||Pn[e]===t;if(typeof t==`number`)return!Number.isFinite(t);if(typeof t==`object`){if(`ids`in t){let e=t.ids;return!Array.isArray(e)||e.length===0}if(`values`in t){let e=t.values;return!Array.isArray(e)||e.length===0}return!1}return!1}var In=oe.filter(e=>e.id===`audio`);function Ln(e){if(e.length===0)return e;let t=new Set(e.map(e=>e.id)),n=In.filter(e=>!t.has(e.id));return n.length===0?e:[...e,...n]}function Rn(e,t,n,r=v({delivery:t,conditions:e})){let i=n.length===0?null:new Set(n.filter(e=>e.id!==`schedule`&&we(e,t,r)).map(e=>e.id)),a={};for(let[t,n]of Object.entries(e))i!==null&&!i.has(t)||F(t,e)&&(Fn(t,n)||(a[t]=n));return a}function zn(e,t){if(e===void 0)return{};let n=Rt(e,t.systemEvent);return n===void 0?{}:{systemEvent:n}}function Bn(e){return e!==void 0&&e.windows.length>0}function Vn(e){let t={...e.clipPreRollSec===void 0?{}:{clipPreRollSec:e.clipPreRollSec},...e.clipPostRollSec===void 0?{}:{clipPostRollSec:e.clipPostRollSec}};return Object.keys(t).length>0?t:void 0}function Hn(e){let t=Vn(e.media);return{...e.confirm===void 0?{}:{confirm:e.confirm},...t===void 0?{}:{media:t}}}function Un(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=J(e.actions),s=v(e),c=y(s),l=ge(s),u=n.length===0?!0:n.some(t=>t.id===`schedule`&&X(t,e.delivery)),d=!Y(e)&&u&&Bn(e.schedule)?e.schedule:void 0,f=n.length===0?!0:n.some(t=>t.id===`devices`&&X(t,e.delivery)),p=n.length===0?!0:n.some(t=>t.id===`devicesExclude`&&X(t,e.delivery)),{devices:m,devicesExclude:h,...g}=_n(e);return{name:e.name.trim(),enabled:e.enabled,delivery:e.delivery,conditions:{...Rn(g,e.delivery,n,s),...f&&m!==void 0?{devices:m}:{},...p&&h!==void 0?{devicesExclude:h}:{},...zn(l,e.conditions)},...d?{schedule:d}:{},...Cn(e),targets:e.targetIds.map(t=>{let n=e.targetParams[t];return n&&Object.keys(n).length>0?{targetId:t,params:n}:{targetId:t}}),...e.targetUsers.length>0?{targetUsers:[...e.targetUsers]}:{},media:c.carriesMedia?{attach:e.mediaAttach,...c.carriesSubjectCrop&&e.mediaZoneCrop?{zoneCrop:!0}:{},...c.carriesSubjectCrop&&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},...s===`sensor`&&e.mediaAttach!==`none`&&e.mediaLinkedCameras!==void 0?{linkedCameras:e.mediaLinkedCameras}:{},...(e.mediaGif||e.mediaClip)&&t?.media?.clipPreRollSec!==void 0?{clipPreRollSec:t.media.clipPreRollSec}:{},...(e.mediaGif||e.mediaClip)&&t?.media?.clipPostRollSec!==void 0?{clipPostRollSec:t.media.clipPostRollSec}:{}}:{attach:`none`},throttle:{cooldownSec:e.cooldownSec,scope:e.cooldownScope,...e.cooldownGranularity===void 0?{}:{granularity:e.cooldownGranularity}},priority:e.priority,...a?{template:a}:{},...e.snoozeAllowGlobal?{snoozeAllowGlobal:!0}:{},...On(e)?{groupingSec:e.groupingSec}:{},...e.snoozeOptions===void 0?{}:{snoozeOptions:[...e.snoozeOptions]},...t?.confirm===void 0?{}:{confirm:t.confirm},...o===void 0?{}:{actions:o}}}function Wn(e,t){let n=Un(e,void 0,t);return[`template`,`schedule`,`targetUsers`,`snoozeOptions`,`snoozeAllowGlobal`,`groupingSec`,`actions`].filter(e=>n[e]===void 0)}var Gn=[{key:`rule`,label:`Rule`,fields:[`name`,`enabled`,`delivery`,`groupingSec`,`targetIds`,`targetUsers`,`targetParams`]},{key:`devices`,label:`Devices`,fields:[`deviceScope`]},{key:`conditions`,label:`Conditions`,fields:[`conditions`,`classScope`,`schedule`,`systemEventDelivery`]},{key:`notification`,label:`Notification`,fields:[`priority`,`mediaAttach`,`mediaFrame`,`mediaZoneCrop`,`mediaGif`,`mediaClip`,`mediaProfile`,`mediaClipSpeed`,`mediaLinkedCameras`,`templateTitle`,`templateBody`]},{key:`actions`,label:`Actions`,fields:[`actions`]},{key:`advanced`,label:`Advanced`,fields:[`snoozeAllowGlobal`,`snoozeOptions`,`cooldownSec`,`cooldownScope`,`cooldownGranularity`]}];function Kn(e,t={}){let n=v({delivery:e,conditions:t}),r=y(n),i=Gn.map(e=>e.key===`conditions`?{...e,label:r.label}:e);return ye(n)?i.filter(e=>e.key!==`devices`):i}function qn(e){if(e.audio!==void 0)return`Sound`;if(e.occupancy!==void 0)return`Occupancy`}function Jn(e){let t=v(e),n=Se(_n(e),t);return t===`sensor`&&e.conditions.sensorTransition!==void 0&&!F(`sensorTransition`,e.conditions)?[...n,{conditionId:`sensorTransition`,reason:ne}]:n}var Yn=`rule`;function Xn(e){return Gn.find(t=>t.key===e)?.key}function Zn(e){return e?.toLowerCase().startsWith(`it`)===!0?`it`:`en`}function Qn(){let{i18n:e}=E(),t=Zn(e.language);return e=>le(e,t)}e();var $n=`block text-[11px] font-medium text-foreground`,Z=`text-[10px] text-foreground-subtle mt-0.5`;function er({cameras:e,fleet:t,value:n,onChange:r,emptyMeansAll:i=!1,savedHadDevices:a=!1}){return o(Oe,{devices:e,listState:t.state,fleet:t,value:n,onChange:r,emptyMeansAll:i,savedHadDevices:a})}function tr({value:e,placeholder:n,onChange:r}){let[i,s]=a(``),c=()=>{let t=i.trim();if(t.length===0||e.includes(t)){s(``);return}r([...e,t]),s(``)},l=t=>r(e.filter(e=>e!==t));return t(`div`,{className:`mt-1 space-y-1.5`,children:[e.length>0&&o(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>t(`span`,{className:`inline-flex items-center gap-1 rounded bg-surface-hover px-1.5 py-0.5 text-[11px] text-foreground`,children:[e,o(`button`,{type:`button`,onClick:()=>l(e),"aria-label":`remove ${e}`,className:`text-foreground-subtle hover:text-danger`,children:o(d,{className:`h-3 w-3`})})]},e))}),o(T,{value:i,placeholder:n,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),c())},onBlur:c})]})}function nr({picker:e,value:r,onChange:i}){let a=n(()=>Te(e),[e]),s=n(()=>new Set(r),[r]),c=r.filter(e=>!a.has(e)),l=e=>{i(s.has(e)?r.filter(t=>t!==e):[...r,e])};return t(`div`,{className:`space-y-2`,children:[c.length>0&&o(`div`,{className:`flex flex-wrap gap-1`,children:c.map(e=>t(`button`,{type:`button`,onClick:()=>i(r.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=>t(`div`,{children:[o(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-muted mb-1`,children:e.fallbackLabel}),o(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map(e=>{let t=s.has(e.value);return o(`button`,{type:`button`,"aria-pressed":t,onClick:()=>l(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 rr({value:e,min:n,max:r,step:i,onChange:a}){return t(`div`,{className:`mt-1 flex items-center gap-2`,children:[o(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&&o(`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 ir({value:e,onChange:n,options:r}){let{t:i}=E(),a=ar(r??[]),s=a.length>0?a:Tt;return t(`div`,{className:`mt-1 space-y-1`,children:[o(w,{value:e??`enter`,options:s.map(e=>({value:e.value,label:i(`notificationRules.crossing.${e.value}`,e.label)})),onChange:e=>n(I(e.target.value))}),o(`p`,{className:Z,children:i(`notificationRules.crossing.hint`,`Which way the subject crosses the zone.`)})]})}function ar(e){let t=[];for(let n of e){let e=n.value===``||n.value===`enter`?Et:I(n.value);e===void 0||t.some(t=>t.value===e)||t.push({value:e,label:n.label})}return t}function or({deviceIds:e,cameras:t,value:n,onChange:r}){let{options:i,loading:a}=O(e,t);return o(k,{options:i,value:n,onChange:r,loading:a,noFreeText:!0,emptyHint:e.length===0?`Select cameras first — a rule can only use zones those cameras actually have.`:`The selected cameras have no zones. Draw one in the camera’s zone editor first.`,placeholder:``})}function sr({deviceIds:e,value:t,onChange:n}){let{options:r,loading:i}=qe(e);return o(k,{options:r,value:t,onChange:n,loading:i,emptyHint:e.length===0?`Select cameras above to pick their event kinds — or type a token.`:`No event kinds reported for the selected cameras — type a token.`,placeholder:`Event token…`})}var cr=[{value:`became-occupied`,label:`Became occupied`},{value:`became-free`,label:`Became free`},{value:`>=`,label:`Count ≥`},{value:`<=`,label:`Count ≤`}];function lr(e,t){let n=e.map(e=>({value:e.value,label:e.label}));return t===void 0||t===``||n.some(e=>e.value===t)?n:[...n,{value:t,label:`${t} — sub-type, never counts (always 0)`}]}function ur({deviceIds:e,cameras:n,classOptions:r,value:i,onChange:a}){let{options:s,loading:c}=O(e,n),l=i??he,u=e=>a({...l,...e}),d=l.op===`became-occupied`||l.op===`became-free`,f=lr(r,l.className);return t(`div`,{className:`mt-1 space-y-1.5`,children:[t(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[o(`div`,{className:`min-w-[10rem]`,children:o(w,{value:l.zoneId??``,options:[{value:``,label:c?`Loading zones…`:`— whole frame —`},...s.map(e=>({value:e.value,label:e.label}))],onChange:e=>u({zoneId:e.target.value===``?void 0:e.target.value})})}),o(`div`,{className:`min-w-[9rem]`,children:o(w,{value:l.className??``,options:[{value:``,label:`— any class —`},...f],onChange:e=>u({className:e.target.value===``?void 0:e.target.value})})}),o(`div`,{className:`min-w-[9rem]`,children:o(w,{value:l.op,options:cr.map(e=>({value:e.value,label:e.label})),onChange:e=>{let t=cr.find(t=>t.value===e.target.value);t&&u({op:t.value})}})})]}),t(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:[t(`label`,{className:`flex items-center gap-1`,children:[d?`Threshold`:`Count`,o(T,{type:`number`,min:0,className:`w-16`,value:String(l.count),onChange:e=>u({count:Math.max(0,Number(e.target.value)||0)})})]}),t(`label`,{className:`flex items-center gap-1`,children:[`Hold for`,o(T,{type:`number`,min:0,max:3600,className:`w-16`,value:String(l.sustainSeconds),onChange:e=>u({sustainSeconds:Math.min(3600,Math.max(0,Number(e.target.value)||0))})}),`s`]}),i===void 0?null:o(`button`,{type:`button`,onClick:()=>a(void 0),className:`underline hover:text-foreground`,children:`Clear`})]}),e.length===0&&o(`p`,{className:`text-[11px] text-warning`,children:`No camera picked on the Devices tab: this watches EVERY camera's occupancy, and no zone can be offered until you choose one — a zone id belongs to a camera.`}),o(`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.`})]})}var dr=[{value:`label`,label:`Sounds — fires at once`,Icon:u},{value:`level`,label:`Volume — over a window`,Icon:l}];function fr({taxonomy:e,value:n,onChange:i}){let a=ue(n),s=e=>i(m(n,e)),{choices:c,unknownLabels:l}=ee(e,a.labels),u=g(n)??`label`;return t(`div`,{className:`mt-1 space-y-2`,children:[t(`div`,{className:`flex flex-wrap items-center gap-1`,children:[dr.map(e=>o(`button`,{type:`button`,"aria-pressed":u===e.value,onClick:()=>s({mode:e.value}),className:`rounded border px-2 py-0.5 text-[11px] ${u===e.value?`border-primary bg-primary/15 text-foreground`:`border-border text-foreground-subtle hover:bg-surface-hover`}`,children:t(`span`,{className:`inline-flex items-center gap-1`,children:[o(e.Icon,{className:`h-3 w-3`}),e.label]})},e.value)),n===void 0?null:o(`button`,{type:`button`,onClick:()=>i(void 0),className:`ml-1 text-xs text-foreground-subtle underline hover:text-foreground`,children:`Clear`})]}),u===`label`?t(r,{children:[o(`div`,{className:`flex flex-wrap gap-1`,children:c.map(e=>{let n=xe(a.labels,e.value),r=e.unknown?`border-dashed border-warning text-warning`:n?`border-primary bg-primary/15 text-foreground`:`border-border text-foreground hover:bg-surface-hover`;return o(`button`,{type:`button`,"aria-pressed":n,title:e.unknown?`Stored by the rule — not offered by this hub`:void 0,onClick:()=>s({labels:be(a.labels,e.value)}),className:`rounded border px-1.5 py-0.5 text-[10px] ${r}`,children:t(`span`,{className:`inline-flex items-center gap-1`,children:[o(ke,{iconId:e.iconId,size:12}),e.label]})},e.value)})}),l.length>0&&t(`p`,{className:`text-[10px] text-warning`,children:[`Kept from the rule, unknown to this hub: `,l.join(`, `)]}),t(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:[t(`label`,{className:`flex items-center gap-1`,children:[`Confirm after`,o(T,{type:`number`,min:1,max:20,step:1,className:`w-16`,value:String(a.confirmHits??2),onChange:e=>s({confirmHits:Number(e.target.value)})}),`frames`]}),t(`label`,{className:`flex items-center gap-1`,children:[`within`,o(T,{type:`number`,min:1,max:60,step:1,className:`w-16`,value:String(a.confirmWindowSec??5),onChange:e=>s({confirmWindowSec:Number(e.target.value)})}),`s`]})]}),t(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Fires when that many labelled frames land inside the window (default`,` `,2,` in `,5,` s). A single-frame false positive never reaches 2; a real episode usually labels two or three frames. The rule's cooldown is the other throttle.`]})]}):t(r,{children:[o(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:t(`label`,{className:`flex items-center gap-1`,children:[`Louder than`,o(T,{type:`number`,min:pe,max:0,step:3,className:`w-20`,value:String(a.dbThreshold??h),onChange:e=>s({dbThreshold:Number(e.target.value)})}),`dBFS`]})}),t(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:[t(`label`,{className:`flex items-center gap-1`,children:[`Hits`,o(T,{type:`number`,min:1,max:100,step:5,className:`w-16`,value:String(a.hitPercent),onChange:e=>s({hitPercent:Number(e.target.value)})}),`% (default `,C.hitPercent,`)`]}),t(`label`,{className:`flex items-center gap-1`,children:[`over`,o(T,{type:`number`,min:1,max:300,step:5,className:`w-16`,value:String(a.samplingSeconds),onChange:e=>s({samplingSeconds:Number(e.target.value)})}),`s (default `,C.samplingSeconds,`)`]})]}),t(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`dBFS is negative-going: 0 is full scale, `,pe,` is silence — so a HIGHER number is a narrower filter. Measured on this hub, a baby crying reads `,`−`,`55 to `,`−`,`26 dBFS, so a floor above `,`−`,`55 excludes most of it. The window must be FULL before it can match.`]})]}),_(n)?o(`p`,{className:`text-[11px] text-warning`,children:`With neither a sound nor a level threshold this can never match — every sample would be a hit, so the engine refuses it rather than notifying on silence.`}):null]})}function pr({value:e,onChange:n}){let r=e?.values??[],i=e?.maxDistance??1,a=e=>n(e.length>0?{values:e,maxDistance:i}:void 0),s=e=>n(r.length>0?{values:r,maxDistance:e}:void 0),c=Ye().filter(e=>!r.includes(e));return t(`div`,{className:`mt-1 space-y-1.5`,children:[o(tr,{value:r,placeholder:`Plate text…`,onChange:a}),c.length>0&&t(`div`,{className:`flex flex-wrap items-center gap-1`,children:[o(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Seen:`}),c.slice(0,12).map(e=>o(`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))]}),t(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Max distance`,o(T,{type:`number`,min:0,max:3,step:1,value:i,className:`max-w-[5rem]`,onChange:e=>{let t=Number(e.target.value);s(Number.isFinite(t)?Math.max(0,Math.min(3,t)):1)}})]})]})}function mr({gateable:e,value:n,onChange:r}){let i=Qn(),a=e.find(e=>e.id===n?.deviceId),s=new Set(n?.states??[]),c=e=>{let t=Number(e);if(!Number.isFinite(t)||t===0)return r(void 0);r({deviceId:t,states:[]})},l=e=>{if(n===void 0)return;let t=new Set(s);t.has(e)?t.delete(e):t.add(e),r(t.size===0?void 0:{deviceId:n.deviceId,states:[...t]})};return t(`div`,{className:`mt-1 space-y-2`,children:[o(w,{value:n===void 0?``:String(n.deviceId),options:[{value:``,label:`— no device gate —`},...e.map(e=>({value:String(e.id),label:e.name}))],onChange:e=>c(e.target.value)}),a!==void 0&&o(`div`,{className:`flex flex-wrap gap-1.5`,children:a.states.map(e=>o(`button`,{type:`button`,onClick:()=>l(e),className:s.has(e)?`rounded-md border border-primary bg-primary/10 px-2 py-0.5 text-[11px] text-primary`:`rounded-md border border-border px-2 py-0.5 text-[11px] text-foreground-subtle`,children:i(e)},e))}),a!==void 0&&a.states.length===0&&o(`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.`}),n!==void 0&&o(`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.`})]})}function hr(e,t){let n=t(e.verdict);return e.latched?`${n} · ${t(`latched`)}`:n}function gr({scenes:e,value:n,onChange:r}){let{t:i}=E(),a=Qn(),s=e.find(e=>e.sceneId===n?.sceneId),c=t=>{if(t===``)return r(void 0);let i=e.find(e=>e.sceneId===t);if(i===void 0)return r(void 0);r({sceneId:t,deviceId:i.deviceId,requiredState:n?.requiredState??`diverged`,...n?.latched===void 0?{}:{latched:n.latched}})},l=e=>{n!==void 0&&r({...n,requiredState:e===`matched`?`matched`:`diverged`})},u=e=>{if(n!==void 0){if(e===``){let{latched:e,...t}=n;return r(t)}r({...n,latched:e===`latched`})}};return e.length===0?o(`p`,{className:Z,children:i(`notificationRules.scene.none`,`No scenes yet — create one on the Scenes page.`)}):t(`div`,{className:`mt-1 space-y-2`,children:[o(w,{value:n?.sceneId??``,options:[{value:``,label:i(`notificationRules.scene.noGate`,`— no scene gate —`)},...e.map(e=>({value:e.sceneId,label:`${e.cameraName} · ${e.label} — ${hr(e,a)}`}))],onChange:e=>c(e.target.value)}),n!==void 0&&t(`div`,{className:`flex flex-wrap items-center gap-2`,children:[t(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[i(`notificationRules.scene.onlyWhile`,`Only while it is`),o(w,{value:n.requiredState,options:[{value:`diverged`,label:a(`diverged`)},{value:`matched`,label:a(`matched`)}],onChange:e=>l(e.target.value)})]}),t(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[i(`notificationRules.scene.read`,`Read`),o(w,{value:n.latched===void 0?``:n.latched?`latched`:`live`,options:[{value:``,label:s===void 0?i(`notificationRules.scene.readOwn`,`The scene's own setting`):`${i(`notificationRules.scene.readOwn`,`The scene's own setting`)} (${a(s.emit)})`},{value:`latched`,label:a(`latched`)},{value:`live`,label:a(`live`)}],onChange:e=>u(e.target.value)})]})]}),s!==void 0&&t(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:[i(`notificationRules.scene.rightNow`,`Right now:`),` `,hr(s,a)]}),n!==void 0&&s===void 0&&o(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:i(`notificationRules.scene.missing`,`This scene no longer exists — pick another or remove the gate.`)})]})}var Q={days:[0,1,2,3,4,5,6],minute:480},_r=[{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 vr(e){let t=Math.floor(e/60),n=e%60;return`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}`}function $(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 yr(e){if(typeof e!=`object`||!e||!(`data`in e))return;let t=e.data;if(!(typeof t!=`object`||!t||!(`code`in t)))return typeof t.code==`string`?t.code:void 0}function br(e){let t=Object.entries(e).map(([e,t])=>`${e} ${String(t)}`);return t.length>0?`Left out by this rule's filters or a camera mute: ${t.join(`, `)}.`:null}function xr(e,t,n,r=`rule`){if(e===`error`)return yr(n)===`NOT_FOUND`?{lines:[`This hub does not serve summary rules yet — update @camstack/server first. A rule saved now would be stored without its summary, and stay instant.`]}:{lines:[`The preview could not be read: ${n instanceof Error?n.message:String(n)}`]};if(e!==`success`||t===void 0)return null;let i=[];if(r===`section`&&t.split===void 0&&i.push(`This hub does not send per-category summaries yet — update @camstack/server first. Until then it sends one message.`),t.empty)i.push(`Nothing to report right now — no notification would be sent.`);else if(t.split===`section`&&t.rows!==void 0){let e=t.rows.length;i.push(`${String(e)} notification${e===1?``:`s`} would be sent now, one per category:`);for(let e of t.rows)i.push(`${e.title}\n${e.text}`)}else i.push(`${String(t.count)} item(s) would be sent now:\n${t.text}`);let a=br(t.dropped);return a!==null&&i.push(a),t.excludedGroups.includes(`backups-exports`)&&i.push(`Backups and exports are completed jobs, not a state — they are not in a summary.`),{lines:i}}function Sr(e,t){return{...e,schedule:t}}function Cr(e,t){let{split:n,...r}=e;return t===`section`?{...r,split:t}:r}function wr(e){return vr(e)}function Tr(e){return $(e)}function Er(){return{days:[1,2,3,4,5],startMinute:540,endMinute:1080}}function Dr(e){return{days:[...Q.days],minute:e}}var Or=`Always active — add a window to restrict when the rule fires.`;function kr({value:e,onChange:t,mode:n=`windows`,defaultMinute:r=Q.minute,emptyHint:i}){return n===`times`?o(jr,{value:e,onChange:t,defaultMinute:r}):o(Ar,{value:e,onChange:t,emptyHint:i??Or})}function Ar({value:e,onChange:n,emptyHint:r}){let i=e?.windows??[],a=e?.invert??!1,s=(t,r)=>{if(t.length===0){n(void 0);return}n({windows:t,...r?{invert:!0}:{},...e?.timezone?{timezone:e.timezone}:{}})},l=()=>s([...i,Er()],a),u=e=>s(i.filter((t,n)=>n!==e),a),d=(e,t)=>s(i.map((n,r)=>r===e?t:n),a);return t(`div`,{className:`mt-1 space-y-2`,"data-testid":`schedule-field-windows`,children:[i.length===0?o(`p`,{className:Z,children:r}):i.map((e,t)=>o(Mr,{window:e,onChange:e=>d(t,e),onRemove:()=>u(t)},t)),t(`div`,{className:`flex items-center gap-3`,children:[t(`button`,{type:`button`,onClick:l,className:`flex items-center gap-1 rounded-md bg-surface-hover px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground`,children:[o(c,{className:`h-3 w-3`}),` Add window`]}),i.length>0&&t(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[o(`input`,{type:`checkbox`,checked:a,onChange:e=>s([...i],e.target.checked),className:`accent-primary`}),`Active outside the windows`]})]})]})}function jr({value:e,onChange:n,defaultMinute:r}){let i=e?.timezone,a=e===void 0?{times:[],approximated:!1}:de(e);if(a===null)return t(`div`,{className:`mt-1 space-y-2`,"data-testid":`schedule-field-times-fallback`,children:[o(`p`,{className:Z,children:`Inverted schedule — shown as bands. Clear the invert flag (or the windows) to author punctual times.`}),o(Ar,{value:e,onChange:n,emptyHint:Or})]});let s=a.times,l=e=>{if(e.length===0){n(void 0);return}n(ce(e,i))};return t(`div`,{className:`mt-1 space-y-2`,"data-testid":`schedule-field-times`,children:[a.approximated&&o(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,"data-testid":`schedule-field-times-approximated`,children:`Shown as send-at times from each window's end (when the summary fires). Edit or save to store them as punctual one-minute windows.`}),s.length===0?o(`p`,{className:Z,children:`No times yet — add one to send on those days at that clock time.`}):s.map((e,t)=>o(Nr,{time:e,index:t,onChange:e=>l(s.map((n,r)=>r===t?e:n)),onRemove:s.length>1?()=>l(s.filter((e,n)=>n!==t)):void 0},t)),t(`button`,{type:`button`,onClick:()=>l([...s,Dr(r)]),className:`flex items-center gap-1 rounded-md bg-surface-hover px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground`,"data-testid":`schedule-field-add-time`,children:[o(c,{className:`h-3 w-3`}),` Add a time`]})]})}function Mr({window:e,onChange:n,onRemove:r}){return t(`div`,{className:`space-y-1.5 rounded-md border border-border p-2`,children:[t(`div`,{className:`flex items-center gap-2 text-xs`,children:[o(`input`,{type:`time`,value:wr(e.startMinute),onChange:t=>n({...e,startMinute:Tr(t.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),o(`span`,{className:`text-foreground-subtle`,children:`→`}),o(`input`,{type:`time`,value:wr(e.endMinute),onChange:t=>n({...e,endMinute:Tr(t.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),o(`span`,{className:`flex-1`}),o(`button`,{type:`button`,onClick:r,"aria-label":`Remove window`,className:`text-foreground-subtle hover:text-danger`,children:o(s,{className:`h-3.5 w-3.5`})})]}),o(Pr,{days:e.days,onToggle:t=>{let r=e.days.includes(t)?e.days.filter(e=>e!==t):[...e.days,t];r.length!==0&&n({...e,days:r})}})]})}function Nr({time:e,index:n,onChange:r,onRemove:i}){return t(`div`,{className:`space-y-1.5 rounded-md border border-border p-2`,children:[t(`div`,{className:`flex items-center gap-2 text-xs`,children:[o(`span`,{className:`text-foreground-subtle`,children:`At`}),o(`input`,{type:`time`,value:vr(e.minute),onChange:t=>r({...e,minute:$(t.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`,"data-testid":`schedule-field-time-${String(n)}`}),o(`span`,{className:`flex-1`}),i!==void 0&&o(`button`,{type:`button`,onClick:i,"aria-label":`Remove time`,className:`text-foreground-subtle hover:text-danger`,children:o(s,{className:`h-3.5 w-3.5`})})]}),o(Pr,{days:e.days,onToggle:t=>{let n=e.days.includes(t)?e.days.filter(e=>e!==t):[...e.days,t];n.length!==0&&r({...e,days:n})}})]})}function Pr({days:e,onToggle:t}){return o(`div`,{className:`flex flex-wrap gap-1`,children:_r.map(n=>o(`button`,{type:`button`,onClick:()=>t(n.value),className:`rounded px-1.5 py-0.5 text-[10px] ${e.includes(n.value)?`bg-primary text-primary-foreground`:`bg-surface-hover text-foreground-subtle`}`,children:n.label},n.value))})}export{Kt as $,k as $t,un as A,it as At,yn as B,ot as Bt,Xn as C,ft as Ct,Hn as D,gt as Dt,Un as E,N as Et,hn as F,Ze as Ft,K as G,pt as Gt,dn as H,At as Ht,Tn as I,Qe as It,rn as J,yt as Jt,q as K,$e as Kt,mn as L,Ot as Lt,Mn as M,xt as Mt,bn as N,F as Nt,Ln as O,St as Ot,vn as P,ut as Pt,nn as Q,et as Qt,Y as R,rt as Rt,Jn as S,lt as St,Wn as T,j as Tt,wn as U,dt as Ut,xn as V,bt as Vt,cn as W,ht as Wt,on as X,vt as Xt,an as Y,_t as Yt,sn as Z,wt as Zt,tr as _,Ge as _n,V as _t,Cr as a,Ue as an,Yt as at,Yn as b,kt as bt,er as c,Be as cn,Vt as ct,Z as d,We as dn,Ht as dt,Je as en,G as et,$n as f,Re as fn,zt as ft,gr as g,Ke as gn,R as gt,pr as h,He as hn,H as ht,Sr as i,je as in,Zt as it,Dn as j,Ct as jt,ln as k,Dt as kt,mr as l,Le as ln,Ft as lt,ur as m,Me as mn,Wt as mt,Q as n,Ve as nn,$t as nt,fr as o,Ne as on,Xt as ot,rr as p,Fe as pn,Ut as pt,J as q,tt as qt,xr as r,Ie as rn,W as rt,ir as s,Pe as sn,Jt as st,kr as t,O as tn,Qt as tt,sr as u,ze as un,Gt as ut,nr as v,Lt as vt,Kn as w,M as wt,qn as x,mt as xt,or as y,P as yt,Sn as z,at as zt};
|
|
1
|
+
import{Q as e,S as t,W as n,b as r,i,q as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{It as s,On as c,Qi as l,dn as u,dt as d,ot as f}from"./player-overlays-C20AJTgs.js";import{Ar as p,At as m,Ct as h,Dt as g,Et as ee,F as te,G as ne,I as re,In as ie,K as ae,Ln as oe,M as se,N as ce,O as le,Ot as ue,P as de,R as fe,St as pe,Tt as _,ct as v,dt as me,et as he,ft as ge,gt as _e,ht as ve,it as ye,jt as be,kt as xe,lt as y,nt as Se,pt as Ce,rt as b,st as x,tt as we,vt as S,wt as C,yt as Te}from"./client-CKGZv6zJ.js";import{Gl as w,Xl as T,Ya as Ee,bc as De,d as Oe,nr as ke,vc as Ae}from"./src-CIIJy_o8.js";import{t as E}from"./useTranslation-Bc5yH9V9.js";e();function D(e){return t=>Object.prototype.hasOwnProperty.call(e,t)}var je=D({devices:!0}),Me=D({classes:!0,classesExclude:!0,labelEquals:!0,identities:!0,identitiesExclude:!0,eventTypeTokens:!0,sensorKinds:!0}),Ne=D({minConfidence:!0,minImportance:!0,minLabelConfidence:!0}),Pe=D({minDwellSeconds:!0}),Fe=D({source:!0}),Ie=D({crossing:!0}),Le=D({packagePhase:!0}),Re=D({sensorTransition:!0}),ze=D({plates:!0}),Be=D({occupancy:!0}),Ve=D({audio:!0}),He=D({systemEvent:!0}),Ue=D({deviceState:!0}),We=D({scene:!0});function Ge(e,t){let n=e[t];return Array.isArray(n)?n:[]}function Ke(e,t){let n=e[t];return typeof n==`number`?n:void 0}function O(e,t){let r=f().trpcClient,a=i({queries:e.map(e=>({queryKey:[[`nc-pickers`,`zones`],{deviceId:e}],staleTime:3e4,queryFn:async()=>({deviceId:e,zones:(await r.zones.listZones.query({deviceId:e})).map(e=>({id:e.id,name:e.name}))})}))});return n(()=>{let e=[],n=new Set;for(let r of a){if(!r.data)continue;let i=t.find(e=>e.id===r.data.deviceId)?.name;for(let t of r.data.zones)n.has(t.id)||(n.add(t.id),e.push({value:t.id,label:t.name,...i===void 0?{}:{hint:i}}))}return{options:e,loading:a.some(e=>e.isLoading),failed:a.some(e=>e.isError)}},[a,t])}function qe(e){let t=f().trpcClient,r=i({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 n(()=>{let e=new Map;for(let t of r)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:r.some(e=>e.isLoading)}},[r])}function Je(){let e=Ee();return n(()=>({options:(e.data??[]).map(e=>({value:e.id,label:e.name})),loading:e.isLoading,failed:e.isError===!0}),[e.data,e.isLoading,e.isError])}function Ye(){let e=Ae({limit:200}),t=De();return n(()=>{let n=new Set;for(let e of t.data??[])e.name.trim().length>0&&n.add(e.name);let r=new Set;for(let t of e.data??[])t.text.trim().length>0&&r.add(t.text);return[...[...n].sort(),...[...r].sort()]},[e.data,t.data])}function k({options:e,value:r,onChange:i,loading:s,emptyHint:c,placeholder:l,noFreeText:u=!1}){let[d,f]=a(``),p=n(()=>new Set(e.map(e=>e.value)),[e]),m=n(()=>new Set(r),[r]),h=r.filter(e=>!p.has(e)),g=e=>{i(m.has(e)?r.filter(t=>t!==e):[...r,e])},ee=()=>{let e=d.trim();e.length===0||r.includes(e)||(i([...r,e]),f(``))};return t(`div`,{className:`mt-1 space-y-1.5`,children:[h.length>0&&o(`div`,{className:`flex flex-wrap gap-1`,children:h.map(e=>t(`button`,{type:`button`,onClick:()=>i(r.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?o(`div`,{className:`max-h-40 overflow-y-auto rounded-md border border-border divide-y divide-border`,children:e.map(e=>t(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[o(`input`,{type:`checkbox`,checked:m.has(e.value),onChange:()=>g(e.value),className:`accent-primary`}),o(`span`,{className:`flex-1 truncate`,children:e.label}),e.hint!==void 0&&o(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.hint})]},e.value))}):o(`p`,{className:`text-[10px] text-foreground-subtle`,children:s===!0?`Loading…`:c}),!u&&o(`input`,{value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),ee())},placeholder:l,className:`w-full rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground placeholder:text-foreground-subtle`})]})}var A=[{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, or an occupancy edge on a linked device.`},{value:`package-event`,label:`Package event`,hint:`A parcel delivery or pick-up.`},{value:`system-event`,label:`System event`,hint:`The installation itself: a camera or stream going offline, a node leaving the cluster, an addon or server update becoming available.`}],j=`Immediate, grouped`,Xe=A.flatMap(e=>e.value===`immediate`?[e,{value:`immediate-grouped`,label:j,hint:`Waits for subjects to be recognised, then sends one message with a mosaic, one picture per subject.`}]:[e]);function Ze(e){return e.groupingSec!==void 0&&x(e)?`immediate-grouped`:e.delivery}function Qe(e){let t=(e.delivery===`immediate`||e.delivery===`track-end`)&&x({delivery:`immediate`,conditions:e.conditions});return Xe.filter(e=>e.value!==`immediate-grouped`||t)}function $e(e){return Xe.find(t=>t.value===e)?.value}function et(e,t=j){return Ze(e)===`immediate-grouped`?`${t} · ${String(e.groupingSec)} s`:nt(e.delivery)}function tt(e){if(e.trim().length===0)return;let t=Number(e);return Number.isFinite(t)&&t>=0?Math.trunc(t):void 0}function nt(e){return A.find(t=>t.value===e)?.label??e}function rt(e){return A.some(t=>t.value===e)}var it=[{key:`all`,label:`All rules`,blurb:`Every notification rule — event-driven and scheduled producers. Tabs filter this same list; pick the type under New rule when creating from here.`,newRuleLabel:`New rule`,emptyHint:`No rules yet. Click "New rule" and pick a kind (Detection, Summary, Calendar events, …).`,creatable:!0},{key:`detection`,label:`Detections`,blurb:`Rules driven by what the cameras SEE — detections, tracks and package events. Doorbell presses and other sensor changes have their own section now (operator ruling, 2026-10-01).`,newRuleLabel:`New detection rule`,emptyHint:`No detection rules yet. Click "New detection rule" to author one.`,creatable:!0},{key:`sensor`,label:`Sensors`,blurb:`Rules driven by a device or sensor CHANGING STATE — a doorbell press, a linked sensor opening or closing. The picture is one snapshot of the camera the sensor is attributed to; there is no media choice to make.`,newRuleLabel:`New sensor rule`,emptyHint:`No sensor rules yet. Click "New sensor rule" to be told when a doorbell is pressed or a linked sensor changes.`,creatable:!0},{key:`audio`,label:`Sound`,blurb:`Rules on what the cameras HEAR: a sustained window of sound loud enough, or classified as one of the sounds you name. A sound rule is an immediate rule carrying the sound condition — it fires only on a confirmed sampling window, never on a picture.`,newRuleLabel:`New sound rule`,emptyHint:`No sound rules yet. Click "New sound rule" — it opens on the sound condition already filled in with a level threshold, so you only have to name the sounds and the targets.`,creatable:!0},{key:`occupancy`,label:`Occupancy`,blurb:`Rules on how many objects are in a camera frame or a zone, and for how long: "the driveway became occupied", "the garden emptied". An occupancy rule is a device-event rule carrying the occupancy condition.`,newRuleLabel:`New occupancy rule`,emptyHint:`No occupancy rules yet. Click "New occupancy rule" — it opens on the occupancy condition; pick the camera on the Devices tab, then the zone and the count.`,creatable:!0},{key:`device-events`,label:`Device events`,blurb:`Rules about your devices: offline or back, switched off or on, a stream dropping, a battery or consumable running low, a camera detecting nothing. These carry no image.`,newRuleLabel:`New device-event rule`,emptyHint:`No device-event rules yet. Click "New device-event rule" to be told when a device drops, a battery runs low or a camera goes blind.`,creatable:!0},{key:`system`,label:`System events`,blurb:`Rules about the installation itself: a node leaving the cluster, an addon crash-looping, an update available or installed, a backup or export finishing. These carry no image and are not tied to a detection.`,newRuleLabel:`New system rule`,emptyHint:`No system rules yet. Click "New system rule" to be told when a node leaves, an update lands or a backup finishes.`,creatable:!0},{key:`alarm`,label:`Alarm`,blurb:`Rules about the alarm panel: arming, armed, triggered, disarmed, and the refusals in between.`,newRuleLabel:`New alarm rule`,emptyHint:`No alarm rules yet. Click "New alarm rule" to be told when the alarm arms, goes off or is disarmed.`,creatable:!0},{key:`mixed`,label:`To recreate`,blurb:`System rules authored before the three families existed. Each mixes families and keeps firing as it is, but it cannot be edited: recreate it as one rule per family (Device events, System events, Alarm). Open none of them: Delete each once its replacements exist.`,newRuleLabel:`New rule`,emptyHint:`Nothing to recreate.`,creatable:!1}];function at(e){return y(v(e)).editable}function ot(e){return ye(st(e))}function st(e){switch(e){case`device-events`:case`system`:case`alarm`:case`mixed`:return e;default:return}}var ct=new Map([[0,`No cooldown`],[60,`1 minute`],[3600,`1 hour`]]),lt=86400;function ut(e){let t=ct.get(e);return t===void 0?e%3600==0?`${e/3600} hours`:e%60==0?`${e/60} minutes`:`${e} seconds`:t}function dt(e){if(e.trim().length===0)return;let t=Number(e);return Number.isFinite(t)&&t>=0?Math.trunc(t):void 0}var ft=[{value:`rule-device`,label:`Per device`},{value:`rule`,label:`Whole rule (one window for every device)`}];function pt(e){return ft.find(t=>t.value===e)?.value}var mt=[{value:`per-class`,label:`Separate windows per class (default)`},{value:`shared`,label:`Shared across classes`}];function ht(e){return mt.find(t=>t.value===e)?.value}var gt=[{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 _t(e){return gt.find(t=>t.value===e)?.value}var M=[{value:``,label:`Automatic`},{value:`cropped`,label:`Cropped on the subject`},{value:`full`,label:`Full frame`},{value:`boxed`,label:`Full frame with boxes`}];function vt(e){let t=M.find(t=>t.value===e)?.value;return t===``?void 0:t}var N=[{value:``,label:`Mosaic of every linked camera (default)`},{value:`mosaic`,label:`Mosaic of every linked camera`},{value:`each`,label:`One image per camera (first camera where only one is allowed)`}];function yt(e){let t=N.find(t=>t.value===e)?.value;return t===``?void 0:t}var P=[{value:``,label:`Lowest available`},{value:`low`,label:`Low`},{value:`mid`,label:`Medium`},{value:`high`,label:`High`}];function bt(e){let t=P.find(t=>t.value===e)?.value;return t===``?void 0:t}var xt=[{value:`any`,label:`Any source`},{value:`pipeline`,label:`Pipeline`},{value:`onboard`,label:`Onboard (camera)`},{value:`sensor`,label:`Sensor`}],St=[{value:`delivered`,label:`Delivered`},{value:`picked-up`,label:`Picked up`},{value:`both`,label:`Both`}],Ct=[{value:``,label:`It triggers and when it clears`},{value:`raised`,label:`Only when it triggers`},{value:`cleared`,label:`Only when it clears`}];function wt(e){return e===`raised`||e===`cleared`?e:void 0}function F(e,t){return e===`sensorTransition`?ae(t.sensorKinds):!0}var Tt=[{value:`enter`,label:`Entering`},{value:`exit`,label:`Leaving`},{value:`any`,label:`Entering or leaving`}],Et=`enter`;function I(e){return e===`exit`||e===`any`?e:void 0}var Dt=[{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 Ot(e,t){return e.options&&e.options.length>0?e.options:t}var kt=[{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 At(e){if(e===``)return;let t=Number(e);return Number.isFinite(t)&&t>=1&&t<=8?t:void 0}var jt=new Map(Object.entries({"device-offline":`Device offline`,"device-online":`Device online`,"device-disabled":`Device switched off`,"device-enabled":`Device switched on`,"stream-offline":`Stream offline`,"stream-online":`Stream online`,"device-battery-low":`Battery low`,"device-battery-normal":`Battery back to normal`,"device-consumable-low":`Consumable low`,"device-consumable-normal":`Consumable back to normal`,"device-tank-low":`Tank low (water, detergent)`,"device-tank-full":`Tank full (dirty water, dust)`,"device-tank-normal":`Tank back to normal`,"detection-blind":`Camera detecting nothing`,"recording-stalled":`Recording stalled`,"recording-healthy":`Recording healthy again`,"recording-degraded":`Recording degraded (restart storm)`,"storage-location-low":`Storage location low`,"storage-location-critical":`Storage location critical`,"storage-location-ok":`Storage location ok again`,"node-offline":`Node offline`,"node-online":`Node online`,"node-restarting":`Node restarting`,"node-updating":`Node updating (restart imminent)`,"node-inference-unavailable":`Node has no usable inference device`,"addon-crash-loop":`Addon stopped after repeated crashes`,"addon-update-available":`Addon update available`,"addon-updated":`Addons updated`,"server-update-available":`Server update available`,"server-updated":`Server updated`,"wrapper-update-available":`Container / app update available`,"export-completed":`Export completed`,"backup-completed":`Backup completed`,"alarm-arm-refused":`Alarm arm refused (something is open)`,"alarm-check-failed":`Alarm check failed (armed anyway)`,"alarm-arming":`Alarm arming (exit delay)`,"alarm-armed":`Alarm armed`,"alarm-pending":`Alarm entry delay started`,"alarm-triggered":`Alarm triggered`,"alarm-rearmed":`Alarm re-armed after siren`,"alarm-sensor-bypass":`Alarm sensor bypass`,"alarm-disarmed":`Alarm disarmed`}));function Mt(e){return jt.get(e)}var Nt={"device-state":`A device the hub can no longer reach, or that came back. Switched off / on is a device an operator turned off or back on — not a fault, a choice.`,streams:`A stream that stopped or came back.`,battery:`A battery below the cluster threshold, and (optionally) its return to normal. Devices with a binary low-battery indicator are judged by the indicator, not by the percentage.`,consumables:`A consumable — filter, brush, bag — at or below this rule’s threshold, or that the device reports as due for replacement, and (optionally) its return to normal after a change. A device that only says "replace" is judged by that, not by a percentage.`,tanks:`A robot vacuum tank the device reports as running low (clean water, detergent) or full (dirty water, dust bin), and (optionally) its return to normal once refilled or emptied.`,"detection-blind":`A camera that is running and being analysed, but detects nothing — up, and producing no work.`,recording:`A camera whose recording is on but no footage is landing (stall), a writer that burned its restart budget (degraded), and (optionally) the return to healthy writing.`,nodes:`An agent or worker node joining or leaving the cluster, or an online node whose inference devices all went away.`,addons:`An addon the hub has stopped restarting after repeated crashes.`,"addon-updates":`A newer version of an addon, or an addon update that just finished.`,updates:`A newer version of the server itself, or of the container / app the node runs inside, is available — or a server update just finished.`,"backups-exports":`A scheduled or manual backup of the hub finished, or a footage export finished rendering.`,storage:`A storage location running low or critical on free space — or whose capacity probe failed — and (optionally) its return to ok.`,alarm:`The alarm panel refusing to arm, arming, armed, counting down to a siren, going off, re-arming, excluding an open sensor, or being disarmed.`},L=_e.map(e=>({id:e.id,family:e.family,label:e.label,hint:Nt[e.id]??``,kinds:e.kinds.flatMap(e=>{let t=Mt(e);return t===void 0?[]:[{value:e,label:t}]})}));function R(e){return L.filter(t=>t.family===e)}function z(e){let t=me(e).conditions.systemEvent;return t===void 0?{kinds:(R(e)[0]?.kinds??[]).map(e=>e.value)}:{...t,kinds:[...t.kinds]}}var B=L.flatMap(e=>e.kinds);function V(e){return B.find(t=>t.value===e)?.label??e}function Pt(e){return{devices:S(e,`deviceIds`),deviceTypes:S(e,`deviceTypes`),nodes:S(e,`nodeIds`),packages:S(e,`packageNames`),consumableThreshold:S(e,`consumableLowPercent`)}}function H(e,t){let n=ve[e],r=Pt(t);return{devices:n.includes(`deviceIds`)&&r.devices,excludeDevices:n.includes(`excludeDeviceIds`)&&r.devices,deviceTypes:n.includes(`deviceTypes`)&&r.deviceTypes,nodes:n.includes(`nodeIds`)&&r.nodes,packages:n.includes(`packageNames`)&&r.packages,consumableThreshold:n.includes(`consumableLowPercent`)&&r.consumableThreshold}}var Ft=Object.values(p).map(e=>({value:e,label:It(e)})).toSorted((e,t)=>e.label.localeCompare(t.label));function It(e){let t=e.replaceAll(`-`,` `);return t.charAt(0).toUpperCase()+t.slice(1)}function Lt(e,t,n){if(!R(n).some(e=>e.kinds.some(e=>e.value===t)))return e;let r=e?.kinds??[];return r.length===1&&r[0]===t?e:Bt(e,r.includes(t)?r.filter(e=>e!==t):B.filter(e=>e.value===t||r.includes(e.value)).map(e=>e.value),n)}function Rt(e,t){return t===void 0?void 0:Bt(t,t.kinds,e)}function zt(e,t){let n=e?.kinds??[];if(n.length===0)return;let r=U(t,`deviceIds`,e?.deviceIds),i=U(t,`excludeDeviceIds`,e?.excludeDeviceIds),a=U(t,`deviceTypes`,e?.deviceTypes),o=U(t,`nodeIds`,e?.nodeIds),s=U(t,`packageNames`,e?.packageNames),c=Object.prototype.hasOwnProperty.call(t,`consumableLowPercent`)?t.consumableLowPercent:e?.consumableLowPercent;return{kinds:[...n],...r===void 0?{}:{deviceIds:[...r]},...i===void 0?{}:{excludeDeviceIds:[...i]},...a===void 0?{}:{deviceTypes:[...a]},...o===void 0?{}:{nodeIds:[...o]},...s===void 0?{}:{packageNames:[...s]},...c===void 0?{}:{consumableLowPercent:c}}}function U(e,t,n){let r=Object.prototype.hasOwnProperty.call(e,t)?e[t]:n;return r!==void 0&&r.length===0?void 0:r}function Bt(e,t,n){let r=H(n,t),i=r.devices?e?.deviceIds:void 0,a=r.excludeDevices?e?.excludeDeviceIds:void 0,o=r.deviceTypes?e?.deviceTypes:void 0,s=r.nodes?e?.nodeIds:void 0,c=r.packages?e?.packageNames:void 0,l=r.consumableThreshold?e?.consumableLowPercent:void 0;return{kinds:[...t],...i&&i.length>0?{deviceIds:[...i]}:{},...a&&a.length>0?{excludeDeviceIds:[...a]}:{},...o&&o.length>0?{deviceTypes:[...o]}:{},...s&&s.length>0?{nodeIds:[...s]}:{},...c&&c.length>0?{packageNames:[...c]}:{},...l===void 0?{}:{consumableLowPercent:l}}}var Vt=95;function Ht(e){let t=e.trim();if(t===``)return{kind:`clear`};let n=Number(t);return Number.isInteger(n)&&n>=1&&n<=Vt?{kind:`set`,value:n}:{kind:`invalid`}}function Ut(e,t=2){if(e===void 0||e.length===0)return`No event selected`;let n=e.slice(0,t).map(V).join(`, `),r=e.length-Math.min(t,e.length);return r>0?`${n} +${r}`:n}function Wt(e){if(e===void 0)return`—`;let t=[],n=e.deviceIds?.length??0,r=e.deviceTypes?.length??0,i=e.nodeIds?.length??0,a=e.packageNames?.length??0,o=e.excludeDeviceIds?.length??0;r>0&&t.push(e.deviceTypes?.map(It).join(`, `)??``),n>0&&t.push(`${n} device${n===1?``:`s`}`),i>0&&t.push(`${i} node${i===1?``:`s`}`),a>0&&t.push(`${a} package${a===1?``:`s`}`);let s=o>0?`except ${o} device${o===1?``:`s`}`:null,c=e.consumableLowPercent===void 0?[]:[`consumables at ${e.consumableLowPercent}%`];return t.length===0?[s===null?`Everything`:`Everything ${s}`,...c].join(` · `):[...t,...s===null?[]:[s],...c].join(` · `)}function Gt(e){return e===void 0||(e.deviceTypes?.length??0)===0?!1:e.kinds.some(e=>ie.includes(e))}var Kt=[`all`,`only`,`except`];function qt(e,t){return(e??[]).length>0?`only`:(t??[]).length>0?`except`:`all`}function W(e,t){let n=[...e??[]],r=[...t??[]];return{mode:qt(n,r),include:n,exclude:r,legacyBoth:n.length>0&&r.length>0}}function Jt(e,t){return{...e,mode:t}}function Yt(e){switch(e.mode){case`only`:return e.include;case`except`:return e.exclude;case`all`:return[]}}function Xt(e,t){switch(e.mode){case`only`:return{...e,include:[...t]};case`except`:return{...e,exclude:[...t]};case`all`:return e}}function Zt(e){return e.mode===`only`&&e.legacyBoth?e.exclude:[]}function Qt(e){return{...e,exclude:[],legacyBoth:!1}}function G(e){switch(e.mode){case`all`:return{};case`except`:return e.exclude.length>0?{exclude:[...e.exclude]}:{};case`only`:{let t=Zt(e);return{...e.include.length>0?{include:[...e.include]}:{},...t.length>0?{exclude:[...t]}:{}}}}}function $t(e){let t=G(e),n=t.include??[],r=t.exclude??[];return[...e.include.filter(e=>!n.includes(e)),...e.exclude.filter(e=>!r.includes(e))]}var K=[`onActivation`,`onDeactivation`,`onTrigger`,`onTriggerOff`],q={onActivation:{title:`On activation`,hint:`Runs when the rule is turned on.`},onDeactivation:{title:`On deactivation`,hint:`Runs when the rule is turned off.`},onTrigger:{title:`On trigger`,hint:`Runs on a positive / raised match.`},onTriggerOff:{title:`On trigger off`,hint:`Runs on a clear / leave match. Delivery types without a clear edge never fire this.`}},en={onActivation:[],onDeactivation:[],onTrigger:[],onTriggerOff:[],buttons:[]};function tn(e){return e===void 0?en:{onActivation:[...e.onActivation??[]],onDeactivation:[...e.onDeactivation??[]],onTrigger:[...e.onTrigger??[]],onTriggerOff:[...e.onTriggerOff??[]],buttons:[...e.buttons??[]]}}function J(e){let t=e.buttons.filter(e=>e.id.trim()!==``&&e.label.trim()!==``&&e.sequenceId.trim()!==``),n={onActivation:e.onActivation,onDeactivation:e.onDeactivation,onTrigger:e.onTrigger,onTriggerOff:e.onTriggerOff};if(!(!K.some(e=>n[e].length>0)&&t.length===0))return{...n.onActivation.length>0?{onActivation:[...n.onActivation]}:{},...n.onDeactivation.length>0?{onDeactivation:[...n.onDeactivation]}:{},...n.onTrigger.length>0?{onTrigger:[...n.onTrigger]}:{},...n.onTriggerOff.length>0?{onTriggerOff:[...n.onTriggerOff]}:{},...t.length>0?{buttons:t}:{}}}function nn(e,t){let n=[];for(let r of K){let i=e[r];i.length>4&&n.push({kind:`too-many`,message:`${q[r].title} has more than 4 bindings.`});for(let e of i)e.kind===`sequence`&&!t.has(e.sequenceId)&&n.push({kind:`unknown-sequence`,message:`${q[r].title} points at a sequence that does not exist.`})}let r=new Set;for(let i of e.buttons){let e=i.id.trim();e!==``&&(r.has(e)&&n.push({kind:`duplicate-button`,message:`Two buttons share the id "${e}". The id is what the audit line names when one is tapped.`}),r.add(e),t.has(i.sequenceId.trim())||n.push({kind:`unknown-sequence`,message:`"${i.label||e}" points at a sequence that does not exist. It would never appear on a notification.`}))}return n}function rn(e,t){return{id:`action-${String(e+1)}`,label:`Action`,sequenceId:t}}function an(){return{kind:`do`,action:{kind:`cap`,deviceId:0,cap:``,method:``}}}function on(e){return{kind:`sequence`,sequenceId:e}}function sn(){return{kind:`wait`,seconds:5}}var cn=[{value:`acknowledge`,label:`Acknowledge`},{value:`dismiss`,label:`Dismiss`},{value:`silence`,label:`Silence`},{value:`snooze`,label:`Snooze`},{value:`view`,label:`View`},{value:`play`,label:`Play`},{value:`camera`,label:`Camera`},{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:`arm-home`,label:`Arm — home`},{value:`arm-away`,label:`Arm — away`},{value:`arm-night`,label:`Arm — night`},{value:`light`,label:`Light`},{value:`alert`,label:`Alert`}],ln=[10,30,60],un=[5,10,15,30,60,120,240,480];function dn(e){return e>=60&&e%60==0?`${e/60} h`:`${e} min`}var fn=new Set([`alarm-arm-refused`,`alarm-check-failed`,`alarm-arming`,`alarm-armed`,`alarm-pending`,`alarm-triggered`,`alarm-rearmed`,`alarm-sensor-bypass`,`alarm-disarmed`]),pn=`alarm-panel`;function mn(e,t){for(let t of e.systemEvent?.kinds??[])if(fn.has(t))return!0;for(let e of t)if(e.kind===`cap`&&e.cap===pn)return!0;return!1}function hn(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[];for(let t of[`onActivation`,`onDeactivation`,`onTrigger`,`onTriggerOff`])for(let i of e[t])if(i.kind===`do`)r.push(i.action);else{let e=n.get(i.sequenceId);e!==void 0&&r.push(...e.actions)}for(let t of e.buttons){let e=n.get(t.sequenceId);e!==void 0&&r.push(...e.actions)}return r}function gn(e){let{devices:t,devicesExclude:n,classes:r,classesExclude:i,...a}=e;return{conditions:a,deviceScope:W(t,n),classScope:W(r,i)}}function _n(e){let t=G(e.deviceScope),n=G(e.classScope);return{...e.conditions,...t.include===void 0?{}:{devices:[...t.include]},...t.exclude===void 0?{}:{devicesExclude:[...t.exclude]},...n.include===void 0?{}:{classes:[...n.include]},...n.exclude===void 0?{}:{classesExclude:[...n.exclude]}}}function vn(e){return e.deviceScope.mode===`only`?e.deviceScope.include:[]}function yn(e,t,n){let r=v(n);return e.some(e=>e.id===t&&we(e,n.delivery,r))}function bn(e=`immediate`,t={}){return{name:``,enabled:!0,delivery:e,targetIds:[],targetUsers:[],targetParams:{},priority:3,mediaAttach:`best`,mediaZoneCrop:!1,mediaFrame:void 0,mediaGif:!1,mediaClip:!1,mediaProfile:void 0,mediaClipSpeed:void 0,mediaLinkedCameras:void 0,templateTitle:``,templateBody:``,...gn(t),schedule:void 0,systemEventDelivery:void 0,snoozeAllowGlobal:!1,groupingSec:void 0,snoozeOptions:void 0,actions:en,cooldownSec:30,cooldownScope:`rule-device`,cooldownGranularity:void 0}}function xn(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,mediaLinkedCameras:e.media.linkedCameras,templateTitle:e.template?.title??``,templateBody:e.template?.body??``,...gn(e.conditions),schedule:e.schedule,systemEventDelivery:e.systemEventDelivery,snoozeAllowGlobal:e.snoozeAllowGlobal===!0,groupingSec:e.groupingSec,snoozeOptions:e.snoozeOptions,actions:tn(e.actions),cooldownSec:e.throttle.cooldownSec,cooldownScope:e.throttle.scope,cooldownGranularity:e.throttle.granularity}}function Sn(e,t){let n=[];if(On(e)){let r=e.groupingSec;r!==void 0&&(!Number.isInteger(r)||r<5||r>60)&&n.push(`The grouping window is a whole number of seconds between 5 and 60.`);let i=t?.confirm;i?.enabled===!0&&i.expect!==void 0&&!kn(i.expect)&&n.push(`This rule’s AI confirm expects more than one subject, but a grouped message judges one picture per subject, so it would never send. Remove the confirm expectation (viewer or API), or choose Immediate.`)}if(_(e.conditions.audio)&&n.push(`This sound rule names neither a sound nor a level threshold, so it can never fire — every sample would count as a hit and the engine refuses it rather than notifying on silence. Pick at least one sound, or add a level.`),(!Number.isInteger(e.cooldownSec)||e.cooldownSec<0||e.cooldownSec>86400)&&n.push(`The cooldown is a whole number of seconds between 0 and ${String(lt)} (24 hours). 0 means every match is delivered.`),Y(e))for(let t of re({delivery:e.delivery,conditions:e.conditions,...e.systemEventDelivery===void 0?{}:{systemEventDelivery:e.systemEventDelivery},...J(e.actions)===void 0?{}:{actions:J(e.actions)}}))n.push(se(t));return n}function Cn(e){let t=e.systemEventDelivery;if(t===void 0)return{};if(!b(e.delivery))return t.mode===`summary`?{systemEventDelivery:{mode:`instant`}}:{};if(t.mode===`summary`&&te(t.schedule)===null){let e=de(t.schedule);if(e!==null&&e.times.length>0)return{systemEventDelivery:{...t,schedule:ce(e.times,t.schedule.timezone)}}}return{systemEventDelivery:t}}function wn(e){if(!Y(e))return null;if(!fe(e.templateBody))return`This body names none of the summary ({{summaryText}} or a section variable) — the hub appends {{summaryText}} to it when it sends.`;let t=e.templateBody;return(e.systemEventDelivery?.mode===`summary`?e.systemEventDelivery.split:void 0)===`section`&&t.trim().length>0&&!/\{\{\s*summaryText\s*\}\}/.test(t)?`Sent one per category: this body names no {{summaryText}}, so on every other category’s notification the hub appends {{summaryText}} (that category’s lines).`:null}function Y(e){return b(e.delivery)&&e.systemEventDelivery?.mode===`summary`}function Tn(e,t,n=new Set){return Sn(e,t).length===0&&rt(e.delivery)&&(!b(e.delivery)||Nn(e)>0)&&v(e)!==`mixed`&&e.name.trim().length>0&&(e.targetIds.length>0||e.targetUsers.length>0)&&nn(e.actions,n).length===0}function En(e,t){let n=jn(e.conditions,t);return b(t)&&(n.systemEvent?.kinds.length??0)===0?{...e,delivery:t,conditions:{...n,systemEvent:z(`device-events`)}}:{...e,delivery:t,conditions:n}}function Dn(e,t){return t===`immediate-grouped`?{...En(e,`immediate`),groupingSec:e.groupingSec??20}:{...En(e,t),groupingSec:void 0}}function On(e){return e.groupingSec!==void 0&&x(e)}function kn(e){switch(e.op){case`>`:return 1>e.count;case`<=`:return 1<=e.count;case`<`:return 1<e.count;case`==`:return e.count===1;default:return 1>=e.count}}var An=new Set([`immediate`,`track-end`,`package-event`]);function jn(e,t){if(e.source!==`pipeline`||An.has(t))return e;let{source:n,...r}=e;return r}function Mn(e,t){return Ce(e.conditions.systemEvent)===t?e:{...e,conditions:{...e.conditions,systemEvent:z(t)}}}function Nn(e){return e.conditions.systemEvent?.kinds.length??0}function X(e,t){return e.appliesTo.includes(t)}var Pn={source:`any`};function Fn(e,t){if(t==null)return!0;if(Array.isArray(t))return t.length===0;if(typeof t==`string`)return t.length===0||Pn[e]===t;if(typeof t==`number`)return!Number.isFinite(t);if(typeof t==`object`){if(`ids`in t){let e=t.ids;return!Array.isArray(e)||e.length===0}if(`values`in t){let e=t.values;return!Array.isArray(e)||e.length===0}return!1}return!1}var In=oe.filter(e=>e.id===`audio`);function Ln(e){if(e.length===0)return e;let t=new Set(e.map(e=>e.id)),n=In.filter(e=>!t.has(e.id));return n.length===0?e:[...e,...n]}function Rn(e,t,n,r=v({delivery:t,conditions:e})){let i=n.length===0?null:new Set(n.filter(e=>e.id!==`schedule`&&we(e,t,r)).map(e=>e.id)),a={};for(let[t,n]of Object.entries(e))i!==null&&!i.has(t)||F(t,e)&&(Fn(t,n)||(a[t]=n));return a}function zn(e,t){if(e===void 0)return{};let n=Rt(e,t.systemEvent);return n===void 0?{}:{systemEvent:n}}function Bn(e){return e!==void 0&&e.windows.length>0}function Vn(e){let t={...e.clipPreRollSec===void 0?{}:{clipPreRollSec:e.clipPreRollSec},...e.clipPostRollSec===void 0?{}:{clipPostRollSec:e.clipPostRollSec}};return Object.keys(t).length>0?t:void 0}function Hn(e){let t=Vn(e.media);return{...e.confirm===void 0?{}:{confirm:e.confirm},...t===void 0?{}:{media:t}}}function Un(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=J(e.actions),s=v(e),c=y(s),l=ge(s),u=n.length===0?!0:n.some(t=>t.id===`schedule`&&X(t,e.delivery)),d=!Y(e)&&u&&Bn(e.schedule)?e.schedule:void 0,f=n.length===0?!0:n.some(t=>t.id===`devices`&&X(t,e.delivery)),p=n.length===0?!0:n.some(t=>t.id===`devicesExclude`&&X(t,e.delivery)),{devices:m,devicesExclude:h,...g}=_n(e);return{name:e.name.trim(),enabled:e.enabled,delivery:e.delivery,conditions:{...Rn(g,e.delivery,n,s),...f&&m!==void 0?{devices:m}:{},...p&&h!==void 0?{devicesExclude:h}:{},...zn(l,e.conditions)},...d?{schedule:d}:{},...Cn(e),targets:e.targetIds.map(t=>{let n=e.targetParams[t];return n&&Object.keys(n).length>0?{targetId:t,params:n}:{targetId:t}}),...e.targetUsers.length>0?{targetUsers:[...e.targetUsers]}:{},media:c.carriesMedia?{attach:e.mediaAttach,...c.carriesSubjectCrop&&e.mediaZoneCrop?{zoneCrop:!0}:{},...c.carriesSubjectCrop&&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},...s===`sensor`&&e.mediaAttach!==`none`&&e.mediaLinkedCameras!==void 0?{linkedCameras:e.mediaLinkedCameras}:{},...(e.mediaGif||e.mediaClip)&&t?.media?.clipPreRollSec!==void 0?{clipPreRollSec:t.media.clipPreRollSec}:{},...(e.mediaGif||e.mediaClip)&&t?.media?.clipPostRollSec!==void 0?{clipPostRollSec:t.media.clipPostRollSec}:{}}:{attach:`none`},throttle:{cooldownSec:e.cooldownSec,scope:e.cooldownScope,...e.cooldownGranularity===void 0?{}:{granularity:e.cooldownGranularity}},priority:e.priority,...a?{template:a}:{},...e.snoozeAllowGlobal?{snoozeAllowGlobal:!0}:{},...On(e)?{groupingSec:e.groupingSec}:{},...e.snoozeOptions===void 0?{}:{snoozeOptions:[...e.snoozeOptions]},...t?.confirm===void 0?{}:{confirm:t.confirm},...o===void 0?{}:{actions:o}}}function Wn(e,t){let n=Un(e,void 0,t);return[`template`,`schedule`,`targetUsers`,`snoozeOptions`,`snoozeAllowGlobal`,`groupingSec`,`actions`].filter(e=>n[e]===void 0)}var Gn=[{key:`rule`,label:`Rule`,fields:[`name`,`enabled`,`delivery`,`groupingSec`,`targetIds`,`targetUsers`,`targetParams`]},{key:`devices`,label:`Devices`,fields:[`deviceScope`]},{key:`conditions`,label:`Conditions`,fields:[`conditions`,`classScope`,`schedule`,`systemEventDelivery`]},{key:`notification`,label:`Notification`,fields:[`priority`,`mediaAttach`,`mediaFrame`,`mediaZoneCrop`,`mediaGif`,`mediaClip`,`mediaProfile`,`mediaClipSpeed`,`mediaLinkedCameras`,`templateTitle`,`templateBody`]},{key:`actions`,label:`Actions`,fields:[`actions`]},{key:`advanced`,label:`Advanced`,fields:[`snoozeAllowGlobal`,`snoozeOptions`,`cooldownSec`,`cooldownScope`,`cooldownGranularity`]}];function Kn(e,t={}){let n=v({delivery:e,conditions:t}),r=y(n),i=Gn.map(e=>e.key===`conditions`?{...e,label:r.label}:e);return ye(n)?i.filter(e=>e.key!==`devices`):i}function qn(e){if(e.audio!==void 0)return`Sound`;if(e.occupancy!==void 0)return`Occupancy`}function Jn(e){let t=v(e),n=Se(_n(e),t);return t===`sensor`&&e.conditions.sensorTransition!==void 0&&!F(`sensorTransition`,e.conditions)?[...n,{conditionId:`sensorTransition`,reason:ne}]:n}var Yn=`rule`;function Xn(e){return Gn.find(t=>t.key===e)?.key}function Zn(e){return e?.toLowerCase().startsWith(`it`)===!0?`it`:`en`}function Qn(){let{i18n:e}=E(),t=Zn(e.language);return e=>le(e,t)}e();var $n=`block text-[11px] font-medium text-foreground`,Z=`text-[10px] text-foreground-subtle mt-0.5`;function er({cameras:e,fleet:t,value:n,onChange:r,emptyMeansAll:i=!1,savedHadDevices:a=!1}){return o(Oe,{devices:e,listState:t.state,fleet:t,value:n,onChange:r,emptyMeansAll:i,savedHadDevices:a})}function tr({value:e,placeholder:n,onChange:r}){let[i,s]=a(``),c=()=>{let t=i.trim();if(t.length===0||e.includes(t)){s(``);return}r([...e,t]),s(``)},l=t=>r(e.filter(e=>e!==t));return t(`div`,{className:`mt-1 space-y-1.5`,children:[e.length>0&&o(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>t(`span`,{className:`inline-flex items-center gap-1 rounded bg-surface-hover px-1.5 py-0.5 text-[11px] text-foreground`,children:[e,o(`button`,{type:`button`,onClick:()=>l(e),"aria-label":`remove ${e}`,className:`text-foreground-subtle hover:text-danger`,children:o(d,{className:`h-3 w-3`})})]},e))}),o(T,{value:i,placeholder:n,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),c())},onBlur:c})]})}function nr({picker:e,value:r,onChange:i}){let a=n(()=>Te(e),[e]),s=n(()=>new Set(r),[r]),c=r.filter(e=>!a.has(e)),l=e=>{i(s.has(e)?r.filter(t=>t!==e):[...r,e])};return t(`div`,{className:`space-y-2`,children:[c.length>0&&o(`div`,{className:`flex flex-wrap gap-1`,children:c.map(e=>t(`button`,{type:`button`,onClick:()=>i(r.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=>t(`div`,{children:[o(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-muted mb-1`,children:e.fallbackLabel}),o(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map(e=>{let t=s.has(e.value);return o(`button`,{type:`button`,"aria-pressed":t,onClick:()=>l(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 rr({value:e,min:n,max:r,step:i,onChange:a}){return t(`div`,{className:`mt-1 flex items-center gap-2`,children:[o(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&&o(`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 ir({value:e,onChange:n,options:r}){let{t:i}=E(),a=ar(r??[]),s=a.length>0?a:Tt;return t(`div`,{className:`mt-1 space-y-1`,children:[o(w,{value:e??`enter`,options:s.map(e=>({value:e.value,label:i(`notificationRules.crossing.${e.value}`,e.label)})),onChange:e=>n(I(e.target.value))}),o(`p`,{className:Z,children:i(`notificationRules.crossing.hint`,`Which way the subject crosses the zone.`)})]})}function ar(e){let t=[];for(let n of e){let e=n.value===``||n.value===`enter`?Et:I(n.value);e===void 0||t.some(t=>t.value===e)||t.push({value:e,label:n.label})}return t}function or({deviceIds:e,cameras:t,value:n,onChange:r}){let{options:i,loading:a}=O(e,t);return o(k,{options:i,value:n,onChange:r,loading:a,noFreeText:!0,emptyHint:e.length===0?`Select cameras first — a rule can only use zones those cameras actually have.`:`The selected cameras have no zones. Draw one in the camera’s zone editor first.`,placeholder:``})}function sr({deviceIds:e,value:t,onChange:n}){let{options:r,loading:i}=qe(e);return o(k,{options:r,value:t,onChange:n,loading:i,emptyHint:e.length===0?`Select cameras above to pick their event kinds — or type a token.`:`No event kinds reported for the selected cameras — type a token.`,placeholder:`Event token…`})}var cr=[{value:`became-occupied`,label:`Became occupied`},{value:`became-free`,label:`Became free`},{value:`>=`,label:`Count ≥`},{value:`<=`,label:`Count ≤`}];function lr(e,t){let n=e.map(e=>({value:e.value,label:e.label}));return t===void 0||t===``||n.some(e=>e.value===t)?n:[...n,{value:t,label:`${t} — sub-type, never counts (always 0)`}]}function ur({deviceIds:e,cameras:n,classOptions:r,value:i,onChange:a}){let{options:s,loading:c}=O(e,n),l=i??he,u=e=>a({...l,...e}),d=l.op===`became-occupied`||l.op===`became-free`,f=lr(r,l.className);return t(`div`,{className:`mt-1 space-y-1.5`,children:[t(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[o(`div`,{className:`min-w-[10rem]`,children:o(w,{value:l.zoneId??``,options:[{value:``,label:c?`Loading zones…`:`— whole frame —`},...s.map(e=>({value:e.value,label:e.label}))],onChange:e=>u({zoneId:e.target.value===``?void 0:e.target.value})})}),o(`div`,{className:`min-w-[9rem]`,children:o(w,{value:l.className??``,options:[{value:``,label:`— any class —`},...f],onChange:e=>u({className:e.target.value===``?void 0:e.target.value})})}),o(`div`,{className:`min-w-[9rem]`,children:o(w,{value:l.op,options:cr.map(e=>({value:e.value,label:e.label})),onChange:e=>{let t=cr.find(t=>t.value===e.target.value);t&&u({op:t.value})}})})]}),t(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:[t(`label`,{className:`flex items-center gap-1`,children:[d?`Threshold`:`Count`,o(T,{type:`number`,min:0,className:`w-16`,value:String(l.count),onChange:e=>u({count:Math.max(0,Number(e.target.value)||0)})})]}),t(`label`,{className:`flex items-center gap-1`,children:[`Hold for`,o(T,{type:`number`,min:0,max:3600,className:`w-16`,value:String(l.sustainSeconds),onChange:e=>u({sustainSeconds:Math.min(3600,Math.max(0,Number(e.target.value)||0))})}),`s`]}),i===void 0?null:o(`button`,{type:`button`,onClick:()=>a(void 0),className:`underline hover:text-foreground`,children:`Clear`})]}),e.length===0&&o(`p`,{className:`text-[11px] text-warning`,children:`No camera picked on the Devices tab: this watches EVERY camera's occupancy, and no zone can be offered until you choose one — a zone id belongs to a camera.`}),o(`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.`})]})}var dr=[{value:`label`,label:`Sounds — fires at once`,Icon:u},{value:`level`,label:`Volume — over a window`,Icon:l}];function fr({taxonomy:e,value:n,onChange:i}){let a=ue(n),s=e=>i(m(n,e)),{choices:c,unknownLabels:l}=ee(e,a.labels),u=g(n)??`label`;return t(`div`,{className:`mt-1 space-y-2`,children:[t(`div`,{className:`flex flex-wrap items-center gap-1`,children:[dr.map(e=>o(`button`,{type:`button`,"aria-pressed":u===e.value,onClick:()=>s({mode:e.value}),className:`rounded border px-2 py-0.5 text-[11px] ${u===e.value?`border-primary bg-primary/15 text-foreground`:`border-border text-foreground-subtle hover:bg-surface-hover`}`,children:t(`span`,{className:`inline-flex items-center gap-1`,children:[o(e.Icon,{className:`h-3 w-3`}),e.label]})},e.value)),n===void 0?null:o(`button`,{type:`button`,onClick:()=>i(void 0),className:`ml-1 text-xs text-foreground-subtle underline hover:text-foreground`,children:`Clear`})]}),u===`label`?t(r,{children:[o(`div`,{className:`flex flex-wrap gap-1`,children:c.map(e=>{let n=xe(a.labels,e.value),r=e.unknown?`border-dashed border-warning text-warning`:n?`border-primary bg-primary/15 text-foreground`:`border-border text-foreground hover:bg-surface-hover`;return o(`button`,{type:`button`,"aria-pressed":n,title:e.unknown?`Stored by the rule — not offered by this hub`:void 0,onClick:()=>s({labels:be(a.labels,e.value)}),className:`rounded border px-1.5 py-0.5 text-[10px] ${r}`,children:t(`span`,{className:`inline-flex items-center gap-1`,children:[o(ke,{iconId:e.iconId,size:12}),e.label]})},e.value)})}),l.length>0&&t(`p`,{className:`text-[10px] text-warning`,children:[`Kept from the rule, unknown to this hub: `,l.join(`, `)]}),t(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:[t(`label`,{className:`flex items-center gap-1`,children:[`Confirm after`,o(T,{type:`number`,min:1,max:20,step:1,className:`w-16`,value:String(a.confirmHits??2),onChange:e=>s({confirmHits:Number(e.target.value)})}),`frames`]}),t(`label`,{className:`flex items-center gap-1`,children:[`within`,o(T,{type:`number`,min:1,max:60,step:1,className:`w-16`,value:String(a.confirmWindowSec??5),onChange:e=>s({confirmWindowSec:Number(e.target.value)})}),`s`]})]}),t(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Fires when that many labelled frames land inside the window (default`,` `,2,` in `,5,` s). A single-frame false positive never reaches 2; a real episode usually labels two or three frames. The rule's cooldown is the other throttle.`]})]}):t(r,{children:[o(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:t(`label`,{className:`flex items-center gap-1`,children:[`Louder than`,o(T,{type:`number`,min:pe,max:0,step:3,className:`w-20`,value:String(a.dbThreshold??h),onChange:e=>s({dbThreshold:Number(e.target.value)})}),`dBFS`]})}),t(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:[t(`label`,{className:`flex items-center gap-1`,children:[`Hits`,o(T,{type:`number`,min:1,max:100,step:5,className:`w-16`,value:String(a.hitPercent),onChange:e=>s({hitPercent:Number(e.target.value)})}),`% (default `,C.hitPercent,`)`]}),t(`label`,{className:`flex items-center gap-1`,children:[`over`,o(T,{type:`number`,min:1,max:300,step:5,className:`w-16`,value:String(a.samplingSeconds),onChange:e=>s({samplingSeconds:Number(e.target.value)})}),`s (default `,C.samplingSeconds,`)`]})]}),t(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`dBFS is negative-going: 0 is full scale, `,pe,` is silence — so a HIGHER number is a narrower filter. Measured on this hub, a baby crying reads `,`−`,`55 to `,`−`,`26 dBFS, so a floor above `,`−`,`55 excludes most of it. The window must be FULL before it can match.`]})]}),_(n)?o(`p`,{className:`text-[11px] text-warning`,children:`With neither a sound nor a level threshold this can never match — every sample would be a hit, so the engine refuses it rather than notifying on silence.`}):null]})}function pr({value:e,onChange:n}){let r=e?.values??[],i=e?.maxDistance??1,a=e=>n(e.length>0?{values:e,maxDistance:i}:void 0),s=e=>n(r.length>0?{values:r,maxDistance:e}:void 0),c=Ye().filter(e=>!r.includes(e));return t(`div`,{className:`mt-1 space-y-1.5`,children:[o(tr,{value:r,placeholder:`Plate text…`,onChange:a}),c.length>0&&t(`div`,{className:`flex flex-wrap items-center gap-1`,children:[o(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Seen:`}),c.slice(0,12).map(e=>o(`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))]}),t(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Max distance`,o(T,{type:`number`,min:0,max:3,step:1,value:i,className:`max-w-[5rem]`,onChange:e=>{let t=Number(e.target.value);s(Number.isFinite(t)?Math.max(0,Math.min(3,t)):1)}})]})]})}function mr({gateable:e,value:n,onChange:r}){let i=Qn(),a=e.find(e=>e.id===n?.deviceId),s=new Set(n?.states??[]),c=e=>{let t=Number(e);if(!Number.isFinite(t)||t===0)return r(void 0);r({deviceId:t,states:[]})},l=e=>{if(n===void 0)return;let t=new Set(s);t.has(e)?t.delete(e):t.add(e),r(t.size===0?void 0:{deviceId:n.deviceId,states:[...t]})};return t(`div`,{className:`mt-1 space-y-2`,children:[o(w,{value:n===void 0?``:String(n.deviceId),options:[{value:``,label:`— no device gate —`},...e.map(e=>({value:String(e.id),label:e.name}))],onChange:e=>c(e.target.value)}),a!==void 0&&o(`div`,{className:`flex flex-wrap gap-1.5`,children:a.states.map(e=>o(`button`,{type:`button`,onClick:()=>l(e),className:s.has(e)?`rounded-md border border-primary bg-primary/10 px-2 py-0.5 text-[11px] text-primary`:`rounded-md border border-border px-2 py-0.5 text-[11px] text-foreground-subtle`,children:i(e)},e))}),a!==void 0&&a.states.length===0&&o(`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.`}),n!==void 0&&o(`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.`})]})}function hr(e,t){let n=t(e.verdict);return e.latched?`${n} · ${t(`latched`)}`:n}function gr({scenes:e,value:n,onChange:r}){let{t:i}=E(),a=Qn(),s=e.find(e=>e.sceneId===n?.sceneId),c=t=>{if(t===``)return r(void 0);let i=e.find(e=>e.sceneId===t);if(i===void 0)return r(void 0);r({sceneId:t,deviceId:i.deviceId,requiredState:n?.requiredState??`diverged`,...n?.latched===void 0?{}:{latched:n.latched}})},l=e=>{n!==void 0&&r({...n,requiredState:e===`matched`?`matched`:`diverged`})},u=e=>{if(n!==void 0){if(e===``){let{latched:e,...t}=n;return r(t)}r({...n,latched:e===`latched`})}};return e.length===0?o(`p`,{className:Z,children:i(`notificationRules.scene.none`,`No scenes yet — create one on the Scenes page.`)}):t(`div`,{className:`mt-1 space-y-2`,children:[o(w,{value:n?.sceneId??``,options:[{value:``,label:i(`notificationRules.scene.noGate`,`— no scene gate —`)},...e.map(e=>({value:e.sceneId,label:`${e.cameraName} · ${e.label} — ${hr(e,a)}`}))],onChange:e=>c(e.target.value)}),n!==void 0&&t(`div`,{className:`flex flex-wrap items-center gap-2`,children:[t(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[i(`notificationRules.scene.onlyWhile`,`Only while it is`),o(w,{value:n.requiredState,options:[{value:`diverged`,label:a(`diverged`)},{value:`matched`,label:a(`matched`)}],onChange:e=>l(e.target.value)})]}),t(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[i(`notificationRules.scene.read`,`Read`),o(w,{value:n.latched===void 0?``:n.latched?`latched`:`live`,options:[{value:``,label:s===void 0?i(`notificationRules.scene.readOwn`,`The scene's own setting`):`${i(`notificationRules.scene.readOwn`,`The scene's own setting`)} (${a(s.emit)})`},{value:`latched`,label:a(`latched`)},{value:`live`,label:a(`live`)}],onChange:e=>u(e.target.value)})]})]}),s!==void 0&&t(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:[i(`notificationRules.scene.rightNow`,`Right now:`),` `,hr(s,a)]}),n!==void 0&&s===void 0&&o(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:i(`notificationRules.scene.missing`,`This scene no longer exists — pick another or remove the gate.`)})]})}var Q={days:[0,1,2,3,4,5,6],minute:480},_r=[{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 vr(e){let t=Math.floor(e/60),n=e%60;return`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}`}function $(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 yr(e){if(typeof e!=`object`||!e||!(`data`in e))return;let t=e.data;if(!(typeof t!=`object`||!t||!(`code`in t)))return typeof t.code==`string`?t.code:void 0}function br(e){let t=Object.entries(e).map(([e,t])=>`${e} ${String(t)}`);return t.length>0?`Left out by this rule's filters or a camera mute: ${t.join(`, `)}.`:null}function xr(e,t,n,r=`rule`){if(e===`error`)return yr(n)===`NOT_FOUND`?{lines:[`This hub does not serve summary rules yet — update @camstack/server first. A rule saved now would be stored without its summary, and stay instant.`]}:{lines:[`The preview could not be read: ${n instanceof Error?n.message:String(n)}`]};if(e!==`success`||t===void 0)return null;let i=[];if(r===`section`&&t.split===void 0&&i.push(`This hub does not send per-category summaries yet — update @camstack/server first. Until then it sends one message.`),t.empty)i.push(`Nothing to report right now — no notification would be sent.`);else if(t.split===`section`&&t.rows!==void 0){let e=t.rows.length;i.push(`${String(e)} notification${e===1?``:`s`} would be sent now, one per category:`);for(let e of t.rows)i.push(`${e.title}\n${e.text}`)}else i.push(`${String(t.count)} item(s) would be sent now:\n${t.text}`);let a=br(t.dropped);return a!==null&&i.push(a),t.excludedGroups.includes(`backups-exports`)&&i.push(`Backups and exports are completed jobs, not a state — they are not in a summary.`),{lines:i}}function Sr(e,t){return{...e,schedule:t}}function Cr(e,t){let{split:n,...r}=e;return t===`section`?{...r,split:t}:r}function wr(e){return vr(e)}function Tr(e){return $(e)}function Er(){return{days:[1,2,3,4,5],startMinute:540,endMinute:1080}}function Dr(e){return{days:[...Q.days],minute:e}}var Or=`Always active — add a window to restrict when the rule fires.`;function kr({value:e,onChange:t,mode:n=`windows`,defaultMinute:r=Q.minute,emptyHint:i}){return n===`times`?o(jr,{value:e,onChange:t,defaultMinute:r}):o(Ar,{value:e,onChange:t,emptyHint:i??Or})}function Ar({value:e,onChange:n,emptyHint:r}){let i=e?.windows??[],a=e?.invert??!1,s=(t,r)=>{if(t.length===0){n(void 0);return}n({windows:t,...r?{invert:!0}:{},...e?.timezone?{timezone:e.timezone}:{}})},l=()=>s([...i,Er()],a),u=e=>s(i.filter((t,n)=>n!==e),a),d=(e,t)=>s(i.map((n,r)=>r===e?t:n),a);return t(`div`,{className:`mt-1 space-y-2`,"data-testid":`schedule-field-windows`,children:[i.length===0?o(`p`,{className:Z,children:r}):i.map((e,t)=>o(Mr,{window:e,onChange:e=>d(t,e),onRemove:()=>u(t)},t)),t(`div`,{className:`flex items-center gap-3`,children:[t(`button`,{type:`button`,onClick:l,className:`flex items-center gap-1 rounded-md bg-surface-hover px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground`,children:[o(c,{className:`h-3 w-3`}),` Add window`]}),i.length>0&&t(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[o(`input`,{type:`checkbox`,checked:a,onChange:e=>s([...i],e.target.checked),className:`accent-primary`}),`Active outside the windows`]})]})]})}function jr({value:e,onChange:n,defaultMinute:r}){let i=e?.timezone,a=e===void 0?{times:[],approximated:!1}:de(e);if(a===null)return t(`div`,{className:`mt-1 space-y-2`,"data-testid":`schedule-field-times-fallback`,children:[o(`p`,{className:Z,children:`Inverted schedule — shown as bands. Clear the invert flag (or the windows) to author punctual times.`}),o(Ar,{value:e,onChange:n,emptyHint:Or})]});let s=a.times,l=e=>{if(e.length===0){n(void 0);return}n(ce(e,i))};return t(`div`,{className:`mt-1 space-y-2`,"data-testid":`schedule-field-times`,children:[a.approximated&&o(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,"data-testid":`schedule-field-times-approximated`,children:`Shown as send-at times from each window's end (when the summary fires). Edit or save to store them as punctual one-minute windows.`}),s.length===0?o(`p`,{className:Z,children:`No times yet — add one to send on those days at that clock time.`}):s.map((e,t)=>o(Nr,{time:e,index:t,onChange:e=>l(s.map((n,r)=>r===t?e:n)),onRemove:s.length>1?()=>l(s.filter((e,n)=>n!==t)):void 0},t)),t(`button`,{type:`button`,onClick:()=>l([...s,Dr(r)]),className:`flex items-center gap-1 rounded-md bg-surface-hover px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground`,"data-testid":`schedule-field-add-time`,children:[o(c,{className:`h-3 w-3`}),` Add a time`]})]})}function Mr({window:e,onChange:n,onRemove:r}){return t(`div`,{className:`space-y-1.5 rounded-md border border-border p-2`,children:[t(`div`,{className:`flex items-center gap-2 text-xs`,children:[o(`input`,{type:`time`,value:wr(e.startMinute),onChange:t=>n({...e,startMinute:Tr(t.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),o(`span`,{className:`text-foreground-subtle`,children:`→`}),o(`input`,{type:`time`,value:wr(e.endMinute),onChange:t=>n({...e,endMinute:Tr(t.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),o(`span`,{className:`flex-1`}),o(`button`,{type:`button`,onClick:r,"aria-label":`Remove window`,className:`text-foreground-subtle hover:text-danger`,children:o(s,{className:`h-3.5 w-3.5`})})]}),o(Pr,{days:e.days,onToggle:t=>{let r=e.days.includes(t)?e.days.filter(e=>e!==t):[...e.days,t];r.length!==0&&n({...e,days:r})}})]})}function Nr({time:e,index:n,onChange:r,onRemove:i}){return t(`div`,{className:`space-y-1.5 rounded-md border border-border p-2`,children:[t(`div`,{className:`flex items-center gap-2 text-xs`,children:[o(`span`,{className:`text-foreground-subtle`,children:`At`}),o(`input`,{type:`time`,value:vr(e.minute),onChange:t=>r({...e,minute:$(t.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`,"data-testid":`schedule-field-time-${String(n)}`}),o(`span`,{className:`flex-1`}),i!==void 0&&o(`button`,{type:`button`,onClick:i,"aria-label":`Remove time`,className:`text-foreground-subtle hover:text-danger`,children:o(s,{className:`h-3.5 w-3.5`})})]}),o(Pr,{days:e.days,onToggle:t=>{let n=e.days.includes(t)?e.days.filter(e=>e!==t):[...e.days,t];n.length!==0&&r({...e,days:n})}})]})}function Pr({days:e,onToggle:t}){return o(`div`,{className:`flex flex-wrap gap-1`,children:_r.map(n=>o(`button`,{type:`button`,onClick:()=>t(n.value),className:`rounded px-1.5 py-0.5 text-[10px] ${e.includes(n.value)?`bg-primary text-primary-foreground`:`bg-surface-hover text-foreground-subtle`}`,children:n.label},n.value))})}export{Kt as $,k as $t,un as A,it as At,yn as B,ot as Bt,Xn as C,ft as Ct,Hn as D,gt as Dt,Un as E,N as Et,hn as F,Ze as Ft,K as G,pt as Gt,dn as H,At as Ht,Tn as I,Qe as It,rn as J,yt as Jt,q as K,$e as Kt,mn as L,Ot as Lt,Mn as M,xt as Mt,bn as N,F as Nt,Ln as O,St as Ot,vn as P,ut as Pt,nn as Q,et as Qt,Y as R,rt as Rt,Jn as S,lt as St,Wn as T,j as Tt,wn as U,dt as Ut,xn as V,bt as Vt,cn as W,ht as Wt,on as X,vt as Xt,an as Y,_t as Yt,sn as Z,wt as Zt,tr as _,Ge as _n,V as _t,Cr as a,Ue as an,Yt as at,Yn as b,kt as bt,er as c,Be as cn,Vt as ct,Z as d,We as dn,Ht as dt,Je as en,G as et,$n as f,Re as fn,zt as ft,gr as g,Ke as gn,R as gt,pr as h,He as hn,H as ht,Sr as i,je as in,Zt as it,Dn as j,Ct as jt,ln as k,Dt as kt,mr as l,Le as ln,Ft as lt,ur as m,Me as mn,Wt as mt,Q as n,Ve as nn,$t as nt,fr as o,Ne as on,Xt as ot,rr as p,Fe as pn,Ut as pt,J as q,tt as qt,xr as r,Ie as rn,W as rt,ir as s,Pe as sn,Jt as st,kr as t,O as tn,Qt as tt,sr as u,ze as un,Gt as ut,nr as v,Lt as vt,Kn as w,M as wt,qn as x,mt as xt,or as y,P as yt,Sn as z,at as zt};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,t}from"./virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-LWvJP_B9.js";export{t as get,e as init};
|