@dominevo/addon-admin-ui 0.1.2 → 0.1.4

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.
Files changed (90) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/assets/{Addons-Ck90J9_n.js → Addons-Dqwyi0aS.js} +1 -1
  3. package/dist/assets/{AdminPage-CA4Sxydy.js → AdminPage-Bd8R8RtF.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-3XsaKUPh.js → AdminSectionedPage-Cwi1kvmM.js} +1 -1
  5. package/dist/assets/{AiProfiles-8UssQtkR.js → AiProfiles-SI2Iyt3F.js} +1 -1
  6. package/dist/assets/{Archive-5WNTy09R.js → Archive-ByC3bXel.js} +1 -1
  7. package/dist/assets/{BootstrapSettingsForm-CQLdqB1p.js → BootstrapSettingsForm-Cy8mCpHP.js} +1 -1
  8. package/dist/assets/{Build-B6m8-obM.js → Build-DfH4qlmf.js} +1 -1
  9. package/dist/assets/{Calendars-BbmdZy07.js → Calendars-K1Z15Ly2.js} +1 -1
  10. package/dist/assets/{Cluster-CzmgBDwN.js → Cluster-Ul0y1bLm.js} +1 -1
  11. package/dist/assets/{CompositionBlockEditor-DjJGal7a.js → CompositionBlockEditor-Kc1vM2A7.js} +1 -1
  12. package/dist/assets/{CompositionEditorPage-MACY9CFt.js → CompositionEditorPage-DOy1_xa6.js} +1 -1
  13. package/dist/assets/{Data-B2mmPVLY.js → Data-wkMPgPIi.js} +1 -1
  14. package/dist/assets/{DeviceDetail-D7GFYFEm.js → DeviceDetail-BxkGFnI2.js} +1 -1
  15. package/dist/assets/{Devices-NJ52UGWV.js → Devices-Dv9L-Kji.js} +1 -1
  16. package/dist/assets/{EmbedDevicePage-F1NEkMUT.js → EmbedDevicePage-DcLTsAsw.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-BKq1BRg_.js → EmbedPlayerPage-C2A2ZfFZ.js} +1 -1
  18. package/dist/assets/{FormBuilder-BjcOGVVa.js → FormBuilder-TrrVPEZX.js} +1 -1
  19. package/dist/assets/{History-CqTLHyoj.js → History-Am70bV1z.js} +1 -1
  20. package/dist/assets/Identity-BzYQSoVB.js +1 -0
  21. package/dist/assets/{InstancesTable-CCUTp360.js → InstancesTable-BhClC6c7.js} +1 -1
  22. package/dist/assets/{IntegrationDetail-CCyZhNWc.js → IntegrationDetail-CXJ4DIj2.js} +1 -1
  23. package/dist/assets/{Integrations-D1Ybtztv.js → Integrations-B7lFcabS.js} +1 -1
  24. package/dist/assets/{Integrations-B_Inbdpc.js → Integrations-ClCrv1nX.js} +1 -1
  25. package/dist/assets/{Jobs-BDZ-S8az.js → Jobs-D9dl7u2u.js} +1 -1
  26. package/dist/assets/{Library-BJXSgpWZ.js → Library-FfhywvlF.js} +1 -1
  27. package/dist/assets/{Locations-CEsFxXK8.js → Locations-DKSaqyPH.js} +1 -1
  28. package/dist/assets/{Logs-DrLmsP4V.js → Logs-C13uuzLz.js} +1 -1
  29. package/dist/assets/{MaskShapeCanvas-T6ZNfW4J.js → MaskShapeCanvas-B5mehyBe.js} +1 -1
  30. package/dist/assets/{MotionZonesSettings-B5KDfHoK.js → MotionZonesSettings-jMkiUUQz.js} +1 -1
  31. package/dist/assets/{MyAccess-CAtcn_a3.js → MyAccess-Dq0fJGPb.js} +1 -1
  32. package/dist/assets/{Network-BUfXtVhQ.js → Network-BVOnr0mt.js} +1 -1
  33. package/dist/assets/{NewExportModal-D64AhGe8.js → NewExportModal-weUsUP2K.js} +1 -1
  34. package/dist/assets/{NodeAddonsSettingsPanel-hnXBekcO.js → NodeAddonsSettingsPanel-BvlLXdhN.js} +1 -1
  35. package/dist/assets/{Notifications-CrrX9yK9.js → Notifications-DF8en3Zl.js} +1 -1
  36. package/dist/assets/{Pipeline-BGOu-2v_.js → Pipeline-D6QSFY4L.js} +1 -1
  37. package/dist/assets/{PrivacyMaskSettings-CERwQtiu.js → PrivacyMaskSettings-C4XdrpKI.js} +1 -1
  38. package/dist/assets/{SceneMonitorEditor-DxTYd8U2.js → SceneMonitorEditor-3kjADoN0.js} +1 -1
  39. package/dist/assets/SessionsList-BOKuwFwJ.js +2 -0
  40. package/dist/assets/{Showroom-CprRp6yl.js → Showroom-DSZ7_JVJ.js} +1 -1
  41. package/dist/assets/{StorageLocationsTable-B81bi89X.js → StorageLocationsTable-B_3fPv7s.js} +1 -1
  42. package/dist/assets/{System-D3mpSwHc.js → System-C2tFswFM.js} +1 -1
  43. package/dist/assets/{TemplateEditorDialog-CwArOYwD.js → TemplateEditorDialog-AIrV7BKf.js} +1 -1
  44. package/dist/assets/{Terminal-Dqxv-P1E.js → Terminal-CD78nora.js} +1 -1
  45. package/dist/assets/{TrainingProviders-CGpG1PvO.js → TrainingProviders-BsfUFtDp.js} +1 -1
  46. package/dist/assets/{Viewer-9ydpkUg6.js → Viewer-2F_bb_FE.js} +1 -1
  47. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Cc7iYWcG.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DD163xl-.js} +1 -1
  48. package/dist/assets/{ai-page.helpers-CiDsxXp3.js → ai-page.helpers-CH0oD27E.js} +1 -1
  49. package/dist/assets/{assignment-candidates-BfhoJg-T.js → assignment-candidates-mv6nvb2M.js} +1 -1
  50. package/dist/assets/{auth-context-CkfOTCG-.js → auth-context-CU5snbq3.js} +1 -1
  51. package/dist/assets/{authed-media-C-zK1a1B.js → authed-media-BavZM6fk.js} +1 -1
  52. package/dist/assets/{board-model-BvqJSvTB.js → board-model-BJOCdYZi.js} +1 -1
  53. package/dist/assets/{broker-oauth-popup-B_GRcwxo.js → broker-oauth-popup-C7Be_Cjq.js} +1 -1
  54. package/dist/assets/{camera-block-model-QrJ_0XZY.js → camera-block-model-Cg9j-LS6.js} +1 -1
  55. package/dist/assets/{device-integration-icon-B63imyJJ.js → device-integration-icon-C9zQRrG0.js} +1 -1
  56. package/dist/assets/device-picker-model-Bi7qSGNi.js +1 -0
  57. package/dist/assets/{dist-2ETbjdqB.js → dist-DMgC_62x.js} +1 -1
  58. package/dist/assets/{dist-B0ixn42U.js → dist-DUZyedAc.js} +3 -3
  59. package/dist/assets/{format-D43HvBR0.js → format-M1wlEHJl.js} +1 -1
  60. package/dist/assets/{hostInit-BjOFEl3v.js → hostInit-BDJZ4Hxi.js} +1 -1
  61. package/dist/assets/i18n-kurEJu5K.js +1 -0
  62. package/dist/assets/{icons-CNI0rnl8.js → icons-nvRYK39P.js} +1 -1
  63. package/dist/assets/{index-CuIsX0Bx.js → index-BHcNBXxj.js} +3 -3
  64. package/dist/assets/{linked-devices-model-Dl4vHeXt.js → linked-devices-model-B3xUuhef.js} +1 -1
  65. package/dist/assets/{mf-entry-bootstrap-0-395ec2fe.js → mf-entry-bootstrap-0-bed506dd.js} +2 -2
  66. package/dist/assets/mount-Bi7qSGNi.js +1 -0
  67. package/dist/assets/{notification-rule-status-T3SwZb2I.js → notification-rule-status-JiMjbzwM.js} +1 -1
  68. package/dist/assets/{player-overlays-qzCoRsrQ.js → player-overlays-Cs69NgAR.js} +1 -1
  69. package/dist/assets/remoteEntry-BFUfVr12.js +1 -0
  70. package/dist/assets/{src-Cf1Uvi4o.js → src-Bb9LsNcW.js} +4 -4
  71. package/dist/assets/{src-CJoX3s-1.js → src-BwDSKCnh.js} +3 -3
  72. package/dist/assets/{sso-popup-CPavla3I.js → sso-popup-DVrI_KPY.js} +1 -1
  73. package/dist/assets/{step-inspector-model-CMrG9Xaa.js → step-inspector-model-B-1rSpjV.js} +1 -1
  74. package/dist/assets/{use-scenes-feed-CosaOMpn.js → use-scenes-feed-Cm1QR46I.js} +1 -1
  75. package/dist/assets/{useAdminDeviceRemoval-C5EQsX7f.js → useAdminDeviceRemoval-C6mofiow.js} +1 -1
  76. package/dist/assets/{useDevice-JbC1lVOL.js → useDevice-B_IWTz7U.js} +1 -1
  77. package/dist/assets/useEventInvalidation-Bi7qSGNi.js +1 -0
  78. package/dist/assets/{useFaultTypeOptions-BCjpEaI1.js → useFaultTypeOptions-DaOrnWNh.js} +1 -1
  79. package/dist/assets/{useNodeUrlSelection-uTbHSv6T.js → useNodeUrlSelection-ESSKAIP0.js} +1 -1
  80. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BZ1YRJXZ.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-B4AKnF2Y.js} +2 -2
  81. package/dist/index.html +12 -12
  82. package/dist/server/addon.js +1 -1
  83. package/package.json +2 -2
  84. package/dist/assets/Identity-8tZo1PB_.js +0 -1
  85. package/dist/assets/SessionsList-CriK5VLX.js +0 -2
  86. package/dist/assets/device-picker-model-CYNi1aEm.js +0 -1
  87. package/dist/assets/i18n-BHLBFC1-.js +0 -1
  88. package/dist/assets/mount-CYNi1aEm.js +0 -1
  89. package/dist/assets/remoteEntry-Dc97BJQ9.js +0 -1
  90. package/dist/assets/useEventInvalidation-CYNi1aEm.js +0 -1
@@ -1 +1 @@
1
- import{C as e,K as t,R as n,S as r,Y as i,et as a,o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Cr as c,Pa as l,_n as u,wr as d,yt as f,zt as p}from"./player-overlays-qzCoRsrQ.js";import{Il as m}from"./src-CJoX3s-1.js";import{$i as h,Cc as g,Kl as _,Mc as v,Pa as y,Pt as b,St as x,Za as S,a as C,aa as w,ea as T,eo as E,gc as D,ia as O,ql as k,ta as A,xt as j}from"./src-Cf1Uvi4o.js";import{l as M}from"./chunk-4ZMWKKQ3-BCeNTgXs.js";import{t as N}from"./useTranslation-uIxPZ_3N.js";import{xt as P}from"./index-CuIsX0Bx.js";import{t as F}from"./AdminPage-CA4Sxydy.js";import"./useEventInvalidation-CYNi1aEm.js";import{t as I}from"./useAdminDeviceRemoval-C5EQsX7f.js";import{t as L}from"./device-integration-icon-B63imyJJ.js";import{n as R}from"./addon-kind-filter-CEGKkC1O.js";a();function z(e,t){return e.filter(e=>e.canAdd).map(e=>({addonId:e.addonId,name:e.name,instances:t.filter(t=>t.addonId===e.addonId&&t.enabled&&t.info?.fixed!==!0)})).filter(e=>e.instances.length>0||!t.some(t=>t.addonId===e.addonId&&t.info?.fixed===!0)).sort((e,t)=>e.name.localeCompare(t.name))}function B(e,t){return`${m(e,t)}&add=1`}function V(e){return`/integrations?setup=${encodeURIComponent(e)}`}function H({open:n,onClose:i}){let{t:a}=N(),o=M(),s=_(void 0,{enabled:n}),l=k(void 0,{enabled:n}),u=t(()=>s.data===void 0||l.data===void 0?null:z(s.data,l.data),[s.data,l.data]),d=s.isError||l.isError,p=e=>{i(),o(e)};return r(h,{open:n,onOpenChange:e=>!e&&i(),children:e(A,{width:`md`,placement:`sheet-on-mobile`,children:[r(O,{children:r(w,{children:a(`devices.addDevice.title`,`Add device`)})}),r(T,{children:d?r(S,{message:a(`devices.addDevice.loadFailed`,`Integrations could not be loaded.`),onRetry:()=>{s.refetch(),l.refetch()}}):u===null?e(`div`,{className:`space-y-2`,"data-testid":`add-device-pending`,children:[r(E,{className:`h-10 w-full`}),r(E,{className:`h-10 w-full`})]}):u.length===0?r(y,{icon:c,title:a(`devices.addDevice.noneTitle`,`No integration installed`),description:a(`devices.addDevice.noneDescription`,`Install an integration first, then add devices from it.`),action:r(f,{onClick:()=>p(R),children:a(`devices.browseIntegrations`,`Browse integrations`)})}):r(`ul`,{className:`space-y-1.5`,children:u.map(t=>t.instances.length===0?r(`li`,{children:e(f,{variant:`outline`,className:`w-full justify-between`,onClick:()=>p(V(t.addonId)),children:[r(`span`,{className:`truncate`,children:t.name}),r(`span`,{className:`text-foreground-subtle`,children:a(`devices.addDevice.setUp`,`Set up`)})]})},t.addonId):t.instances.map(n=>r(`li`,{children:e(f,{variant:`outline`,className:`w-full justify-between`,onClick:()=>p(B(t.addonId,n.id)),children:[r(`span`,{className:`truncate`,children:t.name}),n.name!==t.name&&r(`span`,{className:`truncate text-foreground-subtle`,children:n.name})]})},n.id)))})})]})})}var U=32;function W(e,t){let n=e=>t(e).kind===`orphan`,r=new Set;for(let t of e)n(t)&&r.add(t.id);let i=new Map;for(let t of e)i.set(t.id,t);let a=(e,t=0)=>{if(t>U)return!1;if(r.has(e.id))return!0;if(e.parentDeviceId==null)return!1;let n=i.get(e.parentDeviceId);return n?a(n,t+1):!1},o=[],s=[];for(let t of e)a(t)?s.push(t):o.push(t);return{activeDevices:o,orphanDevices:s}}a();function G(){let{t:a}=N(),m=M(),[h,_]=i(!1),y=p(),S=o();C([`deviceManager`],[`device.registered`,`device.unregistered`,`device.disabled`,`device.enabled`]),C([[`deviceManager`,`listAll`]],[`device.online`,`device.offline`]),C([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`]);let{data:w}=v({projection:`slim`}),{data:T}=k(void 0),E=I(),O=D({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),A=g({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),z=t(()=>w??[],[w]),B=t(()=>x(T),[T]),{activeDevices:V,orphanDevices:U}=t(()=>W(z,B),[z,B]),G=t(()=>b(z),[z]),K=n(e=>G.get(e)??null,[G]),q=t(()=>(T??[]).map(e=>({id:e.id,name:e.name??e.addonId,icon:r(P,{type:e.addonId,size:`sm`})})),[T]),J=n(e=>m(`/devices/${String(e)}`),[m]);return e(F,{icon:l,title:a(`nav.devices`,`Devices`),fill:U.length===0,actions:e(s,{children:[e(f,{variant:`outline`,size:`sm`,onClick:()=>m(R),children:[r(c,{className:`h-3.5 w-3.5`}),a(`devices.browseIntegrations`,`Browse integrations`)]}),e(f,{size:`sm`,onClick:()=>_(!0),children:[r(d,{className:`h-3.5 w-3.5`}),a(`devices.addDevice.title`,`Add device`)]})]}),children:[r(H,{open:h,onClose:()=>_(!1)}),r(j,{context:`devices`,devices:V,trpc:y.trpcClient,filters:{integrations:q},integrationOf:B,resolveIntegrationIcon:L,resolveParent:K,onNavigate:J,rowOperation:E.rowOperation,batchActions:{remove:E.remove,disable:O.mutate,enable:A.mutate}}),U.length>0&&e(`div`,{className:`mt-6 space-y-2`,children:[e(`div`,{className:`flex items-baseline gap-2`,children:[r(u,{className:`h-3.5 w-3.5 text-warning shrink-0`}),r(`h2`,{className:`text-sm font-semibold text-foreground`,children:a(`devices.orphanDevices`,`Orphan devices`)}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:a(`common.deviceOrphans`,{count:U.length})})]}),e(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 p-2`,children:[r(`p`,{className:`text-[11px] text-foreground-subtle px-2 pb-2`,children:a(`devices.theseDevicesReferenceAnIntegration`,"These devices reference an integration that is no longer registered (their `integrationId`, or — for older devices without one — their `addonId`). Delete them, or re-install the missing integration to bring them back online. The provider badge beside each row is the addon that serves it.")}),r(j,{context:`devices`,devices:U,trpc:y.trpcClient,integrationOf:B,urlScope:`nested`,lsKey:`devices:orphan`,resolveIntegrationIcon:L,resolveParent:K,onNavigate:J})]})]})]})}export{G as DevicesPage};
1
+ import{C as e,K as t,R as n,S as r,Y as i,et as a,o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Cr as c,Pa as l,_n as u,wr as d,yt as f,zt as p}from"./player-overlays-Cs69NgAR.js";import{Il as m}from"./src-BwDSKCnh.js";import{$i as h,Cc as g,Kl as _,Mc as v,Pa as y,Pt as b,St as x,Za as S,a as C,aa as w,ea as T,eo as E,gc as D,ia as O,ql as k,ta as A,xt as j}from"./src-Bb9LsNcW.js";import{l as M}from"./chunk-4ZMWKKQ3-BCeNTgXs.js";import{t as N}from"./useTranslation-uIxPZ_3N.js";import{xt as P}from"./index-BHcNBXxj.js";import{t as F}from"./AdminPage-Bd8R8RtF.js";import"./useEventInvalidation-Bi7qSGNi.js";import{t as I}from"./useAdminDeviceRemoval-C6mofiow.js";import{t as L}from"./device-integration-icon-C9zQRrG0.js";import{n as R}from"./addon-kind-filter-CEGKkC1O.js";a();function z(e,t){return e.filter(e=>e.canAdd).map(e=>({addonId:e.addonId,name:e.name,instances:t.filter(t=>t.addonId===e.addonId&&t.enabled&&t.info?.fixed!==!0)})).filter(e=>e.instances.length>0||!t.some(t=>t.addonId===e.addonId&&t.info?.fixed===!0)).sort((e,t)=>e.name.localeCompare(t.name))}function B(e,t){return`${m(e,t)}&add=1`}function V(e){return`/integrations?setup=${encodeURIComponent(e)}`}function H({open:n,onClose:i}){let{t:a}=N(),o=M(),s=_(void 0,{enabled:n}),l=k(void 0,{enabled:n}),u=t(()=>s.data===void 0||l.data===void 0?null:z(s.data,l.data),[s.data,l.data]),d=s.isError||l.isError,p=e=>{i(),o(e)};return r(h,{open:n,onOpenChange:e=>!e&&i(),children:e(A,{width:`md`,placement:`sheet-on-mobile`,children:[r(O,{children:r(w,{children:a(`devices.addDevice.title`,`Add device`)})}),r(T,{children:d?r(S,{message:a(`devices.addDevice.loadFailed`,`Integrations could not be loaded.`),onRetry:()=>{s.refetch(),l.refetch()}}):u===null?e(`div`,{className:`space-y-2`,"data-testid":`add-device-pending`,children:[r(E,{className:`h-10 w-full`}),r(E,{className:`h-10 w-full`})]}):u.length===0?r(y,{icon:c,title:a(`devices.addDevice.noneTitle`,`No integration installed`),description:a(`devices.addDevice.noneDescription`,`Install an integration first, then add devices from it.`),action:r(f,{onClick:()=>p(R),children:a(`devices.browseIntegrations`,`Browse integrations`)})}):r(`ul`,{className:`space-y-1.5`,children:u.map(t=>t.instances.length===0?r(`li`,{children:e(f,{variant:`outline`,className:`w-full justify-between`,onClick:()=>p(V(t.addonId)),children:[r(`span`,{className:`truncate`,children:t.name}),r(`span`,{className:`text-foreground-subtle`,children:a(`devices.addDevice.setUp`,`Set up`)})]})},t.addonId):t.instances.map(n=>r(`li`,{children:e(f,{variant:`outline`,className:`w-full justify-between`,onClick:()=>p(B(t.addonId,n.id)),children:[r(`span`,{className:`truncate`,children:t.name}),n.name!==t.name&&r(`span`,{className:`truncate text-foreground-subtle`,children:n.name})]})},n.id)))})})]})})}var U=32;function W(e,t){let n=e=>t(e).kind===`orphan`,r=new Set;for(let t of e)n(t)&&r.add(t.id);let i=new Map;for(let t of e)i.set(t.id,t);let a=(e,t=0)=>{if(t>U)return!1;if(r.has(e.id))return!0;if(e.parentDeviceId==null)return!1;let n=i.get(e.parentDeviceId);return n?a(n,t+1):!1},o=[],s=[];for(let t of e)a(t)?s.push(t):o.push(t);return{activeDevices:o,orphanDevices:s}}a();function G(){let{t:a}=N(),m=M(),[h,_]=i(!1),y=p(),S=o();C([`deviceManager`],[`device.registered`,`device.unregistered`,`device.disabled`,`device.enabled`]),C([[`deviceManager`,`listAll`]],[`device.online`,`device.offline`]),C([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`]);let{data:w}=v({projection:`slim`}),{data:T}=k(void 0),E=I(),O=D({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),A=g({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),z=t(()=>w??[],[w]),B=t(()=>x(T),[T]),{activeDevices:V,orphanDevices:U}=t(()=>W(z,B),[z,B]),G=t(()=>b(z),[z]),K=n(e=>G.get(e)??null,[G]),q=t(()=>(T??[]).map(e=>({id:e.id,name:e.name??e.addonId,icon:r(P,{type:e.addonId,size:`sm`})})),[T]),J=n(e=>m(`/devices/${String(e)}`),[m]);return e(F,{icon:l,title:a(`nav.devices`,`Devices`),fill:U.length===0,actions:e(s,{children:[e(f,{variant:`outline`,size:`sm`,onClick:()=>m(R),children:[r(c,{className:`h-3.5 w-3.5`}),a(`devices.browseIntegrations`,`Browse integrations`)]}),e(f,{size:`sm`,onClick:()=>_(!0),children:[r(d,{className:`h-3.5 w-3.5`}),a(`devices.addDevice.title`,`Add device`)]})]}),children:[r(H,{open:h,onClose:()=>_(!1)}),r(j,{context:`devices`,devices:V,trpc:y.trpcClient,filters:{integrations:q},integrationOf:B,resolveIntegrationIcon:L,resolveParent:K,onNavigate:J,rowOperation:E.rowOperation,batchActions:{remove:E.remove,disable:O.mutate,enable:A.mutate}}),U.length>0&&e(`div`,{className:`mt-6 space-y-2`,children:[e(`div`,{className:`flex items-baseline gap-2`,children:[r(u,{className:`h-3.5 w-3.5 text-warning shrink-0`}),r(`h2`,{className:`text-sm font-semibold text-foreground`,children:a(`devices.orphanDevices`,`Orphan devices`)}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:a(`common.deviceOrphans`,{count:U.length})})]}),e(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 p-2`,children:[r(`p`,{className:`text-[11px] text-foreground-subtle px-2 pb-2`,children:a(`devices.theseDevicesReferenceAnIntegration`,"These devices reference an integration that is no longer registered (their `integrationId`, or — for older devices without one — their `addonId`). Delete them, or re-install the missing integration to bring them back online. The provider badge beside each row is the addon that serves it.")}),r(j,{context:`devices`,devices:U,trpc:y.trpcClient,integrationOf:B,urlScope:`nested`,lsKey:`devices:orphan`,resolveIntegrationIcon:L,resolveParent:K,onNavigate:J})]})]})]})}export{G as DevicesPage};
@@ -1 +1 @@
1
- import{J as e,R as t,S as n,V as r,a as i,et as a,o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{zt as s}from"./player-overlays-qzCoRsrQ.js";import{A as c,D as l,F as u,S as d,k as f,p}from"./compat-muhdrMna.js";import{Fn as m,Za as h,br as g,en as _,eo as v}from"./src-Cf1Uvi4o.js";import{f as y,l as b,p as x}from"./chunk-4ZMWKKQ3-BCeNTgXs.js";import{t as S}from"./useTranslation-uIxPZ_3N.js";import{_ as C,n as w}from"./auth-context-CkfOTCG-.js";import{U as T}from"./index-CuIsX0Bx.js";a();var E=d(`type`,[c({type:l(`show-device`),deviceId:f().int().positive(),theme:p([`light`,`dark`]),lang:p([`en`,`it`])}),c({type:l(`set-token`),token:u().min(1)})]);function D(e,t,n,r){return e.source===null||e.source===void 0?e.origin===``||e.origin===t:(e.source===r||e.source===n)&&e.origin===t}function O(e){if(typeof e!=`string`)return e;try{return JSON.parse(e)}catch{return}}function k(e,t,n){if(!e)return{kind:`ignore`};let r=E.safeParse(t);if(!r.success)return{kind:`ignore`};if(r.data.type===`set-token`)return{kind:`token`,token:r.data.token};let i=new URLSearchParams(n);return i.set(`theme`,r.data.theme),i.set(`lang`,r.data.lang),i.set(`host`,`viewer`),{kind:`show`,path:`/embed/device/${String(r.data.deviceId)}?${i.toString()}`}}function A(e){return JSON.stringify({type:`card-ready`,deviceId:e})}function j(){let e=window.ReactNativeWebView;return e===void 0||typeof e.postMessage!=`function`?null:e}function M(e){let t=A(e);j()?.postMessage(t),window.parent!==window&&window.parent.postMessage(t,window.location.origin)}function N(e,t){C(e),t.setToken(e),t.reconnect()}function P(e){if(e===void 0||!/^[0-9]+$/.test(e))return null;let t=Number(e);return Number.isSafeInteger(t)&&t>0?t:null}function F(e){return e===`light`||e===`dark`?e:null}function I(e){return e===`en`||e===`it`?e:null}function L(e){return e===`viewer`?e:null}var R=`embed-transparent`;function z(e,t){return t?`${e} h-dvh overflow-hidden bg-transparent text-foreground`:`${e} min-h-screen bg-background text-foreground`}function B(e,t){return e===null?t:e.command}function V(){let{t:a,i18n:c}=S(),l=y(),[u]=x(),d=b(),f=s(),{user:p}=w(),{resolvedMode:C,setMode:E}=g(),A=o(),j=P(l.deviceId),V=i({queryKey:[`auth`,`deviceAccess`,j],queryFn:()=>f.trpcClient.auth.deviceAccess.query({deviceId:j??0}),enabled:j!==null,retry:!1}),H=F(u.get(`theme`));r(()=>{H!==null&&E(H)},[H,E]);let U=L(u.get(`host`))===`viewer`,W=e(null),G=t(e=>{j===null||W.current===j||(W.current=j,M(j))},[j]);if(r(()=>{let e=e=>{if(!(e instanceof MessageEvent))return;let t=O(e.data),n=k(D({origin:e.origin,source:e.source},window.location.origin,window.parent,window),t,u.toString());n.kind===`show`?d(n.path):n.kind===`token`&&N(n.token,f)};return window.addEventListener(`message`,e),document.addEventListener(`message`,e),()=>{window.removeEventListener(`message`,e),document.removeEventListener(`message`,e)}},[d,u,f]),r(()=>{if(!U)return;let e=document.documentElement;return e.classList.add(R),()=>e.classList.remove(R)},[U]),j===null)return n(`div`,{className:`min-h-screen bg-background p-3`,children:n(h,{message:a(`embedDevice.invalidId`,`This link does not name a device.`)})});let K=H??C;if(V.status===`pending`)return n(`main`,{className:U?z(K,!0):`${z(K,!1)} p-3`,children:n(v,{className:U?`h-72 w-full`:`mx-auto h-72 w-full max-w-2xl`})});let q=B(V.status===`success`?V.data:null,p?.isAdmin===!0);return n(`main`,{className:z(K,U),children:n(`div`,{className:U?`h-full w-full`:`mx-auto w-full max-w-2xl`,children:n(m,{frame:U?`bare`:`card`,fill:U,children:n(T,{deviceId:j,trpcClient:f.trpcClient,queryClient:A,theme:K,locale:I(u.get(`lang`))??_(c.language),canActuate:q,showName:!U,onDrawn:G,onOpenDevice:e=>d(`/embed/device/${String(e)}?${u.toString()}`)})})})})}export{V as EmbedDevicePage};
1
+ import{J as e,R as t,S as n,V as r,a as i,et as a,o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{zt as s}from"./player-overlays-Cs69NgAR.js";import{A as c,D as l,F as u,S as d,k as f,p}from"./compat-muhdrMna.js";import{Fn as m,Za as h,br as g,en as _,eo as v}from"./src-Bb9LsNcW.js";import{f as y,l as b,p as x}from"./chunk-4ZMWKKQ3-BCeNTgXs.js";import{t as S}from"./useTranslation-uIxPZ_3N.js";import{_ as C,n as w}from"./auth-context-CU5snbq3.js";import{U as T}from"./index-BHcNBXxj.js";a();var E=d(`type`,[c({type:l(`show-device`),deviceId:f().int().positive(),theme:p([`light`,`dark`]),lang:p([`en`,`it`])}),c({type:l(`set-token`),token:u().min(1)})]);function D(e,t,n,r){return e.source===null||e.source===void 0?e.origin===``||e.origin===t:(e.source===r||e.source===n)&&e.origin===t}function O(e){if(typeof e!=`string`)return e;try{return JSON.parse(e)}catch{return}}function k(e,t,n){if(!e)return{kind:`ignore`};let r=E.safeParse(t);if(!r.success)return{kind:`ignore`};if(r.data.type===`set-token`)return{kind:`token`,token:r.data.token};let i=new URLSearchParams(n);return i.set(`theme`,r.data.theme),i.set(`lang`,r.data.lang),i.set(`host`,`viewer`),{kind:`show`,path:`/embed/device/${String(r.data.deviceId)}?${i.toString()}`}}function A(e){return JSON.stringify({type:`card-ready`,deviceId:e})}function j(){let e=window.ReactNativeWebView;return e===void 0||typeof e.postMessage!=`function`?null:e}function M(e){let t=A(e);j()?.postMessage(t),window.parent!==window&&window.parent.postMessage(t,window.location.origin)}function N(e,t){C(e),t.setToken(e),t.reconnect()}function P(e){if(e===void 0||!/^[0-9]+$/.test(e))return null;let t=Number(e);return Number.isSafeInteger(t)&&t>0?t:null}function F(e){return e===`light`||e===`dark`?e:null}function I(e){return e===`en`||e===`it`?e:null}function L(e){return e===`viewer`?e:null}var R=`embed-transparent`;function z(e,t){return t?`${e} h-dvh overflow-hidden bg-transparent text-foreground`:`${e} min-h-screen bg-background text-foreground`}function B(e,t){return e===null?t:e.command}function V(){let{t:a,i18n:c}=S(),l=y(),[u]=x(),d=b(),f=s(),{user:p}=w(),{resolvedMode:C,setMode:E}=g(),A=o(),j=P(l.deviceId),V=i({queryKey:[`auth`,`deviceAccess`,j],queryFn:()=>f.trpcClient.auth.deviceAccess.query({deviceId:j??0}),enabled:j!==null,retry:!1}),H=F(u.get(`theme`));r(()=>{H!==null&&E(H)},[H,E]);let U=L(u.get(`host`))===`viewer`,W=e(null),G=t(e=>{j===null||W.current===j||(W.current=j,M(j))},[j]);if(r(()=>{let e=e=>{if(!(e instanceof MessageEvent))return;let t=O(e.data),n=k(D({origin:e.origin,source:e.source},window.location.origin,window.parent,window),t,u.toString());n.kind===`show`?d(n.path):n.kind===`token`&&N(n.token,f)};return window.addEventListener(`message`,e),document.addEventListener(`message`,e),()=>{window.removeEventListener(`message`,e),document.removeEventListener(`message`,e)}},[d,u,f]),r(()=>{if(!U)return;let e=document.documentElement;return e.classList.add(R),()=>e.classList.remove(R)},[U]),j===null)return n(`div`,{className:`min-h-screen bg-background p-3`,children:n(h,{message:a(`embedDevice.invalidId`,`This link does not name a device.`)})});let K=H??C;if(V.status===`pending`)return n(`main`,{className:U?z(K,!0):`${z(K,!1)} p-3`,children:n(v,{className:U?`h-72 w-full`:`mx-auto h-72 w-full max-w-2xl`})});let q=B(V.status===`success`?V.data:null,p?.isAdmin===!0);return n(`main`,{className:z(K,U),children:n(`div`,{className:U?`h-full w-full`:`mx-auto w-full max-w-2xl`,children:n(m,{frame:U?`bare`:`card`,fill:U,children:n(T,{deviceId:j,trpcClient:f.trpcClient,queryClient:A,theme:K,locale:I(u.get(`lang`))??_(c.language),canActuate:q,showName:!U,onDrawn:G,onOpenDevice:e=>d(`/embed/device/${String(e)}?${u.toString()}`)})})})})}export{V as EmbedDevicePage};
@@ -1 +1 @@
1
- import{C as e,K as t,S as n,V as r,Y as i,d as a,et as o,u as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{It as c}from"./player-overlays-qzCoRsrQ.js";import{bl as l}from"./src-CJoX3s-1.js";import{A as u,D as d,F as f,L as p,k as m,y as h}from"./compat-muhdrMna.js";import{Cr as g,Im as _,Ur as v,Zr as y,yr as b}from"./src-Cf1Uvi4o.js";import{t as x}from"./useTranslation-uIxPZ_3N.js";o();var S=p([u({kind:d(`adaptive`)}),u({kind:d(`profile`),profile:l})]),C=u({serverUrl:f().min(1),token:f().min(1),deviceId:m().int().nonnegative(),target:S,muted:h()});function w(e,t){let n=t===void 0?{type:`state`,state:e}:{type:`state`,state:e,message:t};window.ReactNativeWebView?.postMessage(JSON.stringify(n))}function T(e){switch(e){case`playing`:return`playing`;case`error`:return`error`;case`connecting`:case`disconnected`:case`idle`:return`connecting`}}function E(e){return e.kind===`adaptive`?{kind:`adaptive`}:{kind:`profile`,profile:e.profile}}function D(e){return e.kind===`adaptive`?`embed:adaptive`:`embed:profile:${e.profile}`}function O(){let e=window.__DOMINEVO_EMBED__;if(e==null)return{ok:!1,error:`window.__DOMINEVO_EMBED__ is not set`};let t=C.safeParse(e);return t.success?{ok:!0,config:t.data}:{ok:!1,error:t.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).join(`; `)}}function k({message:t}){let{t:n}=x();return r(()=>{w(`error`,t)},[t]),e(`div`,{style:{position:`fixed`,inset:0,display:`flex`,alignItems:`center`,justifyContent:`center`,background:`#000`,color:`#f87171`,fontFamily:`system-ui, sans-serif`,fontSize:13,padding:16,textAlign:`center`},children:[n(`embedPlayerPage.embedConfigError`,`Embed config error:`),` `,t]})}function A({system:e,deviceId:a,initialTarget:o,initialMuted:s}){let[c,l]=i(o),[u,d]=i(s),{handleOffer:f,getIceServers:p,addIceCandidate:m,getIceCandidates:h,closeSession:g,getSessionState:_,getSessionDebug:b,applyDownlinkProbe:x}=v(e.trpcClient,a),C=t(()=>E(c),[c]),O=t(()=>(e,t)=>f(C,e,t),[f,C]),k=t(()=>(e,t,n)=>f(n,t,e),[f]);r(()=>(window.__dominevoEmbed={setMuted:e=>d(e),setTarget:e=>{let t=S.safeParse(e);t.success&&l(t.data)}},()=>{window.__dominevoEmbed&&delete window.__dominevoEmbed}),[]);let A=D(c);return n(`div`,{style:{position:`fixed`,inset:0,width:`100vw`,height:`100vh`,background:`#000`},children:n(y,{serverUrl:e.serverUrl,streamKey:A,autoPlay:!0,muted:u,showControls:!1,className:`w-full h-full`,getSessionDebug:b,applyDownlinkProbe:x,handleOffer:O,reoffer:k,getSessionState:_,getIceServers:p,addIceCandidate:m,getIceCandidates:h,closeSession:g,onStateChange:e=>w(T(e)),onError:e=>w(`error`,e)},A)})}function j(){let{t:e}=x(),i=t(()=>O(),[]),o=t(()=>{if(!i.ok)return null;let e=g({serverUrl:i.config.serverUrl,token:i.config.token}),t=new a({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1}}});return b(t),{system:e,queryClient:t}},[i]);return r(()=>{if(o)return()=>{o.system.close()}},[o]),i.ok?o?n(c,{system:o.system,children:n(s,{client:o.queryClient,children:n(_.Provider,{client:o.system.trpcClient,queryClient:o.queryClient,children:n(A,{system:o.system,deviceId:i.config.deviceId,initialTarget:i.config.target,initialMuted:i.config.muted})})})}):n(k,{message:e(`embedPlayerPage.failedToInitialiseTheEmbed`,`Failed to initialise the embed player`)}):n(k,{message:i.error})}export{j as EmbedPlayerPage};
1
+ import{C as e,K as t,S as n,V as r,Y as i,d as a,et as o,u as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{It as c}from"./player-overlays-Cs69NgAR.js";import{bl as l}from"./src-BwDSKCnh.js";import{A as u,D as d,F as f,L as p,k as m,y as h}from"./compat-muhdrMna.js";import{Cr as g,Im as _,Ur as v,Zr as y,yr as b}from"./src-Bb9LsNcW.js";import{t as x}from"./useTranslation-uIxPZ_3N.js";o();var S=p([u({kind:d(`adaptive`)}),u({kind:d(`profile`),profile:l})]),C=u({serverUrl:f().min(1),token:f().min(1),deviceId:m().int().nonnegative(),target:S,muted:h()});function w(e,t){let n=t===void 0?{type:`state`,state:e}:{type:`state`,state:e,message:t};window.ReactNativeWebView?.postMessage(JSON.stringify(n))}function T(e){switch(e){case`playing`:return`playing`;case`error`:return`error`;case`connecting`:case`disconnected`:case`idle`:return`connecting`}}function E(e){return e.kind===`adaptive`?{kind:`adaptive`}:{kind:`profile`,profile:e.profile}}function D(e){return e.kind===`adaptive`?`embed:adaptive`:`embed:profile:${e.profile}`}function O(){let e=window.__DOMINEVO_EMBED__;if(e==null)return{ok:!1,error:`window.__DOMINEVO_EMBED__ is not set`};let t=C.safeParse(e);return t.success?{ok:!0,config:t.data}:{ok:!1,error:t.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).join(`; `)}}function k({message:t}){let{t:n}=x();return r(()=>{w(`error`,t)},[t]),e(`div`,{style:{position:`fixed`,inset:0,display:`flex`,alignItems:`center`,justifyContent:`center`,background:`#000`,color:`#f87171`,fontFamily:`system-ui, sans-serif`,fontSize:13,padding:16,textAlign:`center`},children:[n(`embedPlayerPage.embedConfigError`,`Embed config error:`),` `,t]})}function A({system:e,deviceId:a,initialTarget:o,initialMuted:s}){let[c,l]=i(o),[u,d]=i(s),{handleOffer:f,getIceServers:p,addIceCandidate:m,getIceCandidates:h,closeSession:g,getSessionState:_,getSessionDebug:b,applyDownlinkProbe:x}=v(e.trpcClient,a),C=t(()=>E(c),[c]),O=t(()=>(e,t)=>f(C,e,t),[f,C]),k=t(()=>(e,t,n)=>f(n,t,e),[f]);r(()=>(window.__dominevoEmbed={setMuted:e=>d(e),setTarget:e=>{let t=S.safeParse(e);t.success&&l(t.data)}},()=>{window.__dominevoEmbed&&delete window.__dominevoEmbed}),[]);let A=D(c);return n(`div`,{style:{position:`fixed`,inset:0,width:`100vw`,height:`100vh`,background:`#000`},children:n(y,{serverUrl:e.serverUrl,streamKey:A,autoPlay:!0,muted:u,showControls:!1,className:`w-full h-full`,getSessionDebug:b,applyDownlinkProbe:x,handleOffer:O,reoffer:k,getSessionState:_,getIceServers:p,addIceCandidate:m,getIceCandidates:h,closeSession:g,onStateChange:e=>w(T(e)),onError:e=>w(`error`,e)},A)})}function j(){let{t:e}=x(),i=t(()=>O(),[]),o=t(()=>{if(!i.ok)return null;let e=g({serverUrl:i.config.serverUrl,token:i.config.token}),t=new a({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1}}});return b(t),{system:e,queryClient:t}},[i]);return r(()=>{if(o)return()=>{o.system.close()}},[o]),i.ok?o?n(c,{system:o.system,children:n(s,{client:o.queryClient,children:n(_.Provider,{client:o.system.trpcClient,queryClient:o.queryClient,children:n(A,{system:o.system,deviceId:i.config.deviceId,initialTarget:i.config.target,initialMuted:i.config.muted})})})}):n(k,{message:e(`embedPlayerPage.failedToInitialiseTheEmbed`,`Failed to initialise the embed player`)}):n(k,{message:i.error})}export{j as EmbedPlayerPage};
@@ -1 +1 @@
1
- import{C as e,K as t,S as n,Y as r,et as i,i 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-CEyXHAdg.js";import{Gt as s,Q as c,So as l,bo as u,bt as d,or as f,wr as p,xn as m,xo as h,xt as g,yt as _,zt as v}from"./player-overlays-qzCoRsrQ.js";import{$ as y,$t as b,At as ee,Ci as te,Dt as ne,Et as re,G as ie,Gt as ae,H as oe,Ht as se,J as ce,Jt as le,K as ue,Kt as de,Lt as x,Mt as fe,Nc as pe,Nt as S,Ot as me,Pt as he,Q as ge,Qt as _e,R as ve,Rt as C,Ti as ye,U as be,Ut as xe,V as Se,Vt as Ce,W as w,X as we,Xt as Te,Y as Ee,Yt as T,Z as E,Zt as De,an as Oe,ca as ke,cn as Ae,ct as je,dn as Me,ds as Ne,en as Pe,fn as Fe,gt as Ie,in as D,jt as O,kt as k,ln as Le,ls as Re,on as ze,pn as Be,q as Ve,sn as He,st as Ue,tn as We,un as Ge,vc as Ke,wi as qe,zt as A}from"./src-CJoX3s-1.js";import{Ka as Je,Tl as Ye,Ui as Xe,Wi as j,fa as Ze,gf as Qe,im as $e,k as et,la as tt,lm as nt,pa as rt,vf as it}from"./src-Cf1Uvi4o.js";import{t as M}from"./i18n-BHLBFC1-.js";import{t as N}from"./useTranslation-uIxPZ_3N.js";i();function P(e){return t=>Object.prototype.hasOwnProperty.call(e,t)}var at=P({devices:!0}),ot=P({classes:!0,classesExclude:!0,labelEquals:!0,identities:!0,identitiesExclude:!0,eventTypeTokens:!0,sensorKinds:!0}),st=P({minConfidence:!0,minImportance:!0,minLabelConfidence:!0}),ct=P({minDwellSeconds:!0}),lt=P({source:!0}),ut=P({crossing:!0}),dt=P({packagePhase:!0}),ft=P({sensorTransition:!0}),pt=P({plates:!0}),mt=P({occupancy:!0}),ht=P({audio:!0}),gt=P({systemEvent:!0}),_t=P({deviceState:!0}),vt=P({scene:!0});function yt(e,t){let n=e[t];return Array.isArray(n)?n:[]}function bt(e,t){let n=e[t];return typeof n==`number`?n:void 0}var xt=`event-emitter`;function St(e){let t=new Map,n=[],r=!1,i=0;for(let a of e){if(a.status===`pending`){r=!0;continue}if(a.status===`error`){n.push(a.deviceName);continue}if(a.data===null||a.data===void 0)continue;let e=Ne.safeParse(a.data);if(!e.success){n.push(a.deviceName);continue}i+=1;for(let n of Ke(e.data)){let e=t.get(n.id);e===void 0?t.set(n.id,{label:n.label,devices:[a.deviceName]}):e.devices.includes(a.deviceName)||t.set(n.id,{label:e.label,devices:[...e.devices,a.deviceName]})}}let a=i>1;return{options:[...t.entries()].map(([e,t])=>a?{value:e,label:t.label,hint:t.devices.join(`, `)}:{value:e,label:t.label}),pending:r,unknownDevices:n,eventDeviceCount:i}}function Ct(e,t,n){let r=new Set(t.map(e=>e.id)),i=new Map((n??[]).map(e=>[e.id,e.name]));return e.filter(e=>!r.has(e)).map(e=>({deviceId:e,deviceName:i.get(e)??`#${e}`}))}function F(e,n){let r=v().trpcClient,i=a({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 t(()=>{let e=[],t=new Set;for(let r of i){if(!r.data)continue;let i=n.find(e=>e.id===r.data.deviceId)?.name;for(let n of r.data.zones)t.has(n.id)||(t.add(n.id),e.push({value:n.id,label:n.name,...i===void 0?{}:{hint:i}}))}return{options:e,loading:i.some(e=>e.isLoading),failed:i.some(e=>e.isError)}},[i,n])}function wt(e){let n=v().trpcClient,r=a({queries:e.map(e=>({queryKey:[[`nc-pickers`,`event-kinds`],{deviceId:e}],staleTime:6e4,queryFn:async()=>(await n.pipelineAnalytics.listEventKinds.query({deviceId:e})).map(e=>({kind:e.kind,label:e.label}))}))});return t(()=>{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 Tt(e){let n=v().trpcClient,r=a({queries:e.map(({deviceId:e})=>({queryKey:[[`nc-pickers`,`declared-events`],{deviceId:e}],staleTime:3e4,queryFn:async()=>n.deviceState.getCapSlice.query({deviceId:e,capName:xt})}))});return t(()=>St(e.map((e,t)=>({...e,status:r[t]?.status??`pending`,data:r[t]?.data}))),[e,r])}function Et(){let e=Ye();return t(()=>({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 Dt(){let e=Qe({limit:200}),n=it();return t(()=>{let t=new Set;for(let e of n.data??[])e.name.trim().length>0&&t.add(e.name);let r=new Set;for(let t of e.data??[])t.text.trim().length>0&&r.add(t.text);return[...[...t].sort(),...[...r].sort()]},[e.data,n.data])}function I({options:i,value:a,onChange:o,loading:s,emptyHint:c,placeholder:l,noFreeText:u=!1}){let{t:d}=N(),[f,p]=r(``),m=t(()=>new Set(i.map(e=>e.value)),[i]),v=t(()=>new Set(a),[a]),y=a.filter(e=>!m.has(e)),b=e=>{o(v.has(e)?a.filter(t=>t!==e):[...a,e])},ee=()=>{let e=f.trim();e.length===0||a.includes(e)||(o([...a,e]),p(``))};return e(`div`,{className:`mt-1 space-y-1.5`,children:[y.length>0&&n(`div`,{className:`flex flex-wrap gap-1`,children:y.map(t=>e(_,{variant:`unstyled`,type:`button`,onClick:()=>o(a.filter(e=>e!==t)),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:d(`system.notificationRulePickers.customValueClickToRemove`,`Custom value — click to remove`),children:[t,` ×`]},t))}),i.length>0?n(`div`,{className:`max-h-40 overflow-y-auto rounded-md border border-border divide-y divide-border`,children:i.map(t=>e(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[n(h,{checked:v.has(t.value),onChange:()=>b(t.value),className:`accent-primary`}),n(`span`,{className:`flex-1 truncate`,children:t.label}),t.hint!==void 0&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:t.hint})]},t.value))}):n(`p`,{className:`text-[10px] text-foreground-subtle`,children:s===!0?d(`common.loading`,`Loading…`):c}),!u&&n(g,{value:f,onChange:e=>p(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 L=[{value:`immediate`,get label(){return M.t(`helpers.ruleFormParsers.immediate`)},get hint(){return M.t(`helpers.ruleFormParsers.immediateHint`)}},{value:`track-end`,get label(){return M.t(`helpers.ruleFormParsers.trackEnd`)},get hint(){return M.t(`helpers.ruleFormParsers.trackEndHint`)}},{value:`device-event`,get label(){return M.t(`helpers.ruleFormParsers.deviceEvent`)},get hint(){return M.t(`helpers.ruleFormParsers.deviceEventHint`)}},{value:`package-event`,get label(){return M.t(`helpers.ruleFormParsers.packageEvent`)},get hint(){return M.t(`helpers.ruleFormParsers.packageEventHint`)}},{value:`system-event`,get label(){return M.t(`helpers.ruleFormParsers.systemEvent`)},get hint(){return M.t(`helpers.ruleFormParsers.systemEventHint`)}}],Ot=`Immediate, grouped`,kt=L.flatMap(e=>e.value===`immediate`?[e,{value:`immediate-grouped`,get label(){return M.t(`notificationRules.grouping.choice`)},get hint(){return M.t(`helpers.ruleFormParsers.groupedHint`)}}]:[e]);function At(e){return e.groupingSec!==void 0&&x(e)?`immediate-grouped`:e.delivery}function jt(e){let t=(e.delivery===`immediate`||e.delivery===`track-end`)&&x({delivery:`immediate`,conditions:e.conditions});return kt.filter(e=>e.value!==`immediate-grouped`||t)}function Mt(e){return kt.find(t=>t.value===e)?.value}function Nt(e,t=Ot){return At(e)===`immediate-grouped`?`${t} · ${String(e.groupingSec)} s`:Pt(e.delivery)}function Pt(e){return L.find(t=>t.value===e)?.label??e}function Ft(e){return L.some(t=>t.value===e)}var It=[{key:`all`,get label(){return M.t(`helpers.ruleFormParsers.sec_all_label`)},get blurb(){return M.t(`helpers.ruleFormParsers.sec_all_blurb`)},get newRuleLabel(){return M.t(`helpers.ruleFormParsers.sec_all_new`)},get emptyHint(){return M.t(`helpers.ruleFormParsers.sec_all_empty`)},creatable:!0},{key:`detection`,get label(){return M.t(`helpers.ruleFormParsers.sec_detection_label`)},get blurb(){return M.t(`helpers.ruleFormParsers.sec_detection_blurb`)},get newRuleLabel(){return M.t(`helpers.ruleFormParsers.sec_detection_new`)},get emptyHint(){return M.t(`helpers.ruleFormParsers.sec_detection_empty`)},creatable:!0},{key:`sensor`,get label(){return M.t(`helpers.ruleFormParsers.sec_sensor_label`)},get blurb(){return M.t(`helpers.ruleFormParsers.sec_sensor_blurb`)},get newRuleLabel(){return M.t(`helpers.ruleFormParsers.sec_sensor_new`)},get emptyHint(){return M.t(`helpers.ruleFormParsers.sec_sensor_empty`)},creatable:!0},{key:`audio`,get label(){return M.t(`helpers.ruleFormParsers.sec_audio_label`)},get blurb(){return M.t(`helpers.ruleFormParsers.sec_audio_blurb`)},get newRuleLabel(){return M.t(`helpers.ruleFormParsers.sec_audio_new`)},get emptyHint(){return M.t(`helpers.ruleFormParsers.sec_audio_empty`)},creatable:!0},{key:`occupancy`,get label(){return M.t(`helpers.ruleFormParsers.sec_occupancy_label`)},get blurb(){return M.t(`helpers.ruleFormParsers.sec_occupancy_blurb`)},get newRuleLabel(){return M.t(`helpers.ruleFormParsers.sec_occupancy_new`)},get emptyHint(){return M.t(`helpers.ruleFormParsers.sec_occupancy_empty`)},creatable:!0},{key:`device-events`,get label(){return M.t(`helpers.ruleFormParsers.sec_deviceEvents_label`)},get blurb(){return M.t(`helpers.ruleFormParsers.sec_deviceEvents_blurb`)},get newRuleLabel(){return M.t(`helpers.ruleFormParsers.sec_deviceEvents_new`)},get emptyHint(){return M.t(`helpers.ruleFormParsers.sec_deviceEvents_empty`)},creatable:!0},{key:`system`,get label(){return M.t(`helpers.ruleFormParsers.sec_system_label`)},get blurb(){return M.t(`helpers.ruleFormParsers.sec_system_blurb`)},get newRuleLabel(){return M.t(`helpers.ruleFormParsers.sec_system_new`)},get emptyHint(){return M.t(`helpers.ruleFormParsers.sec_system_empty`)},creatable:!0},{key:`alarm`,get label(){return M.t(`helpers.ruleFormParsers.sec_alarm_label`)},get blurb(){return M.t(`helpers.ruleFormParsers.sec_alarm_blurb`)},get newRuleLabel(){return M.t(`helpers.ruleFormParsers.sec_alarm_new`)},get emptyHint(){return M.t(`helpers.ruleFormParsers.sec_alarm_empty`)},creatable:!0},{key:`mixed`,get label(){return M.t(`helpers.ruleFormParsers.sec_mixed_label`)},get blurb(){return M.t(`helpers.ruleFormParsers.sec_mixed_blurb`)},get newRuleLabel(){return M.t(`helpers.ruleFormParsers.sec_mixed_new`)},get emptyHint(){return M.t(`helpers.ruleFormParsers.sec_mixed_empty`)},creatable:!1}];function Lt(e){return A(C(e)).editable}function Rt(e){return he(zt(e))}function zt(e){switch(e){case`device-events`:case`system`:case`alarm`:case`mixed`:return e;default:return}}var Bt=new Map([[0,`helpers.ruleFormParsers.cdNone`],[60,`helpers.ruleFormParsers.cd1m`],[3600,`helpers.ruleFormParsers.cd1h`]]),Vt=86400;function Ht(e){let t=Bt.get(e);return t===void 0?e%3600==0?M.t(`helpers.ruleFormParsers.cdHours`,{count:e/3600}):e%60==0?M.t(`helpers.ruleFormParsers.cdMinutes`,{count:e/60}):M.t(`helpers.ruleFormParsers.cdSeconds`,{count:e}):M.t(t)}var Ut=[{value:`rule-device`,get label(){return M.t(`helpers.ruleFormParsers.scopeDevice`)}},{value:`rule`,get label(){return M.t(`helpers.ruleFormParsers.scopeRule`)}}];function Wt(e){return Ut.find(t=>t.value===e)?.value}var Gt=[{value:`per-class`,get label(){return M.t(`helpers.ruleFormParsers.granPerClass`)}},{value:`shared`,get label(){return M.t(`helpers.ruleFormParsers.granShared`)}}];function Kt(e){return Gt.find(t=>t.value===e)?.value}var qt=[{value:`scene-boxes`,get label(){return M.t(`helpers.ruleFormParsers.imageSceneBoxes`)},get description(){return M.t(`helpers.ruleFormParsers.imageSceneBoxesDesc`)}},{value:`crop`,get label(){return M.t(`helpers.ruleFormParsers.imageCrop`)},get description(){return M.t(`helpers.ruleFormParsers.imageCropDesc`)}},{value:`clean`,get label(){return M.t(`helpers.ruleFormParsers.imageClean`)},get description(){return M.t(`helpers.ruleFormParsers.imageCleanDesc`)}},{value:`none`,get label(){return M.t(`helpers.ruleFormParsers.imageNone`)},get description(){return M.t(`helpers.ruleFormParsers.imageNoneDesc`)}}];function Jt(e){return qt.find(t=>t.value===e)?.value}var Yt=[{value:``,get label(){return M.t(`helpers.ruleFormParsers.linkedDefault`)}},{value:`mosaic`,get label(){return M.t(`helpers.ruleFormParsers.linkedMosaic`)}},{value:`each`,get label(){return M.t(`helpers.ruleFormParsers.linkedEach`)}}];function Xt(e){let t=Yt.find(t=>t.value===e)?.value;return t===``?void 0:t}var Zt=[{value:``,get label(){return M.t(`helpers.ruleFormParsers.profileLowest`)}},{value:`low`,get label(){return M.t(`helpers.ruleFormParsers.profileLow`)}},{value:`mid`,get label(){return M.t(`helpers.ruleFormParsers.profileMid`)}},{value:`high`,get label(){return M.t(`helpers.ruleFormParsers.profileHigh`)}}];function Qt(e){let t=Zt.find(t=>t.value===e)?.value;return t===``?void 0:t}var $t=[{value:`any`,get label(){return M.t(`helpers.ruleFormParsers.srcAny`)}},{value:`pipeline`,get label(){return M.t(`helpers.ruleFormParsers.srcPipeline`)}},{value:`onboard`,get label(){return M.t(`helpers.ruleFormParsers.srcOnboard`)}},{value:`sensor`,get label(){return M.t(`helpers.ruleFormParsers.srcSensor`)}}],en=[{value:`delivered`,get label(){return M.t(`helpers.ruleFormParsers.phaseDelivered`)}},{value:`picked-up`,get label(){return M.t(`helpers.ruleFormParsers.phasePickedUp`)}},{value:`both`,get label(){return M.t(`helpers.ruleFormParsers.phaseBoth`)}}],tn=[{value:``,get label(){return M.t(`helpers.ruleFormParsers.stBoth`)}},{value:`raised`,get label(){return M.t(`helpers.ruleFormParsers.stRaised`)}},{value:`cleared`,get label(){return M.t(`helpers.ruleFormParsers.stCleared`)}}];function nn(e){return e===`raised`||e===`cleared`?e:void 0}function R(e,t){return e===`sensorTransition`?je(t.sensorKinds):!0}var rn=[{value:`enter`,get label(){return M.t(`helpers.ruleFormParsers.crossEnter`)}},{value:`exit`,get label(){return M.t(`helpers.ruleFormParsers.crossExit`)}},{value:`any`,get label(){return M.t(`helpers.ruleFormParsers.crossAny`)}}],an=`enter`;function on(e){return e===`exit`||e===`any`?e:void 0}var sn=[{value:1,get label(){return M.t(`helpers.ruleFormParsers.prioMin`)}},{value:2,get label(){return M.t(`helpers.ruleFormParsers.prioLow`)}},{value:3,get label(){return M.t(`helpers.ruleFormParsers.prioDefault`)}},{value:4,get label(){return M.t(`helpers.ruleFormParsers.prioHigh`)}},{value:5,get label(){return M.t(`helpers.ruleFormParsers.prioMax`)}}];function cn(e,t){return e.options&&e.options.length>0?e.options:t}var ln=[{value:``,get label(){return M.t(`helpers.ruleFormParsers.speedDefault`)}},{value:`1`,get label(){return M.t(`helpers.ruleFormParsers.speedReal`)}},{value:`2`,label:`2×`},{value:`3`,label:`3×`},{value:`4`,label:`4×`},{value:`6`,label:`6×`},{value:`8`,label:`8×`}];function un(e){if(e===``)return;let t=Number(e);return Number.isFinite(t)&&t>=1&&t<=8?t:void 0}var z={days:[0,1,2,3,4,5,6],minute:480},dn=[{value:1,get label(){return M.t(`helpers.notificationSystemEventDelivery.wd_mon`)}},{value:2,get label(){return M.t(`helpers.notificationSystemEventDelivery.wd_tue`)}},{value:3,get label(){return M.t(`helpers.notificationSystemEventDelivery.wd_wed`)}},{value:4,get label(){return M.t(`helpers.notificationSystemEventDelivery.wd_thu`)}},{value:5,get label(){return M.t(`helpers.notificationSystemEventDelivery.wd_fri`)}},{value:6,get label(){return M.t(`helpers.notificationSystemEventDelivery.wd_sat`)}},{value:0,get label(){return M.t(`helpers.notificationSystemEventDelivery.wd_sun`)}}];function fn(e){let t=Math.floor(e/60),n=e%60;return`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}`}function pn(e){let[t,n]=e.split(`:`),r=Number(t)*60+Number(n);return Number.isFinite(r)?Math.max(0,Math.min(1439,r)):0}var mn={mode:`modes`,onActivation:!0,onDeactivation:!1};function hn(e){return e!==void 0&&Se.includes(e)}function gn(e,t){return ge({conditions:t.length>0?{systemEvent:{kinds:[...t]}}:{},...e===void 0?{}:{systemEventDelivery:e}})}function _n(e){return{mode:`modes`,onActivation:e.onActivation,onDeactivation:e.onDeactivation}}function vn(e,t,n){return t===`activation`?{...e,onActivation:n}:t===`deactivation`?{...e,onDeactivation:n}:n?e.onSchedule===void 0?{...e,onSchedule:{schedule:w([z]),grouping:`section`}}:e:_n(e)}function yn(e,t){return{...e,onSchedule:{schedule:t,grouping:e.onSchedule?.grouping??`section`}}}function bn(e,t){return e.onSchedule===void 0?e:{...e,onSchedule:{...e.onSchedule,grouping:t}}}function xn(e){let t=new Set,n=0;for(let r of e){let e=E(r);e===void 0?n+=1:t.add(e.label)}return{adds:[...t],without:n}}function Sn(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 Cn(e){let t=Object.entries(e).map(([e,t])=>`${e} ${String(t)}`);return t.length>0?M.t(`helpers.notificationSystemEventDelivery.dropped`,{parts:t.join(`, `)}):null}function wn(e,t,n,r=`rule`){if(e===`error`)return Sn(n)===`NOT_FOUND`?{lines:[`This hub does not serve summary rules yet — update @dominevo/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 @dominevo/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=Cn(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}}var Tn=`notificationRules.systemEventKinds.`,En=`notificationRules.systemEventGroups.`,Dn=`notificationRules.systemEventHints.`;function On(e){return!ye.some(t=>t===e)}function B(e){let t=`${Tn}${e}`;return M.exists(t)?M.t(t):e}function kn(){return de.map(e=>({id:e.id,family:e.family,label:M.t(`${En}${e.id}`,e.label),hint:M.t(`${Dn}${e.id}`),kinds:e.kinds.filter(On).map(e=>({value:e,label:B(e)}))}))}function V(e){return kn().filter(t=>t.family===e)}function An(e){let t=Ce(e).conditions.systemEvent;return t===void 0?{kinds:(V(e)[0]?.kinds??[]).map(e=>e.value)}:{...t,kinds:[...t.kinds]}}function jn(){return kn().flatMap(e=>e.kinds)}function Mn(e){return{devices:T(e,`deviceIds`),deviceTypes:T(e,`deviceTypes`),nodes:T(e,`nodeIds`),packages:T(e,`packageNames`),consumableThreshold:T(e,`consumableLowPercent`),commandActions:T(e,`commandActions`),commandOutcomes:T(e,`commandOutcomes`),commandActorKinds:T(e,`commandActorKinds`),faultCodes:T(e,`faultCodes`),faultSeverities:T(e,`faultSeverities`)}}function Nn(e,t){let n=ae[e],r=Mn(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,commandActions:n.includes(`commandActions`)&&r.commandActions,commandOutcomes:n.includes(`commandOutcomes`)&&r.commandOutcomes,commandActorKinds:n.includes(`commandActorKinds`)&&r.commandActorKinds,faultCodes:n.includes(`faultCodes`)&&r.faultCodes,faultSeverities:n.includes(`faultSeverities`)&&r.faultSeverities}}var Pn=ke.options;function Fn(e){return Pn.filter(t=>e.includes(t))}var In=Object.values(pe).map(e=>({value:e,label:Ln(e)})).toSorted((e,t)=>e.label.localeCompare(t.label));function Ln(e){let t=e.replaceAll(`-`,` `);return t.charAt(0).toUpperCase()+t.slice(1)}function Rn(e,t){let n=[],r=new Set;for(let i of e.kinds){let e=E(i.value);if(e===void 0){n.push({key:i.value,label:i.label,kinds:[i.value],clears:[i.value]});continue}r.has(e.id)||(r.add(e.id),n.push({key:`class:${e.id}`,label:t?e.snapshotLabel:e.label,kinds:t?[...e.bad]:we(e),clears:we(e),classId:e.id,...t&&e.snapshotSection===null?{noSnapshot:!0}:{}}))}return n}function zn(e,t){return t.clears.some(t=>e.includes(t))}function Bn(e,t,n){if(!V(n).some(e=>e.kinds.some(e=>t.kinds.includes(e.value))))return e;let r=e?.kinds??[];if(zn(r,t)){let i=r.filter(e=>!t.clears.includes(e));return i.length===0?e:U(e,i,n)}return U(e,jn().filter(e=>t.kinds.includes(e.value)||r.includes(e.value)).map(e=>e.value),n)}function Vn(e,t){return t===void 0?void 0:U(t,t.kinds,e)}function Hn(e,t){let n=e?.kinds??[];if(n.length===0)return;let r=H(t,`deviceIds`,e?.deviceIds),i=H(t,`excludeDeviceIds`,e?.excludeDeviceIds),a=H(t,`deviceTypes`,e?.deviceTypes),o=H(t,`nodeIds`,e?.nodeIds),s=H(t,`packageNames`,e?.packageNames),c=H(t,`faultCodes`,e?.faultCodes),l=H(t,`faultSeverities`,e?.faultSeverities),u=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?{}:{faultCodes:[...c]},...l===void 0?{}:{faultSeverities:[...l]},...u===void 0?{}:{consumableLowPercent:u}}}function H(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 U(e,t,n){let r=Nn(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.faultCodes?e?.faultCodes:void 0,u=r.faultSeverities?e?.faultSeverities:void 0,d=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&&l.length>0?{faultCodes:[...l]}:{},...u&&u.length>0?{faultSeverities:[...u]}:{},...d===void 0?{}:{consumableLowPercent:d}}}var Un=95;function Wn(e){let t=e.trim();if(t===``)return{kind:`clear`};let n=Number(t);return Number.isInteger(n)&&n>=1&&n<=Un?{kind:`set`,value:n}:{kind:`invalid`}}function Gn(e,t=2){if(e===void 0||e.length===0)return M.t(`helpers.notificationSystemEvents.noneSelected`);let n=e.slice(0,t).map(B).join(`, `),r=e.length-Math.min(t,e.length);return r>0?`${n} +${r}`:n}function Kn(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(Ln).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 qn(e){return e===void 0||(e.deviceTypes?.length??0)===0?!1:e.kinds.some(e=>te.includes(e))}var Jn=[`all`,`only`,`except`];function Yn(e,t){return(e??[]).length>0?`only`:(t??[]).length>0?`except`:`all`}function W(e,t){let n=[...e??[]],r=[...t??[]];return{mode:Yn(n,r),include:n,exclude:r,legacyBoth:n.length>0&&r.length>0}}function Xn(e,t){return{...e,mode:t}}function Zn(e){switch(e.mode){case`only`:return e.include;case`except`:return e.exclude;case`all`:return[]}}function Qn(e,t){switch(e.mode){case`only`:return{...e,include:[...t]};case`except`:return{...e,exclude:[...t]};case`all`:return e}}function $n(e){return e.mode===`only`&&e.legacyBoth?e.exclude:[]}function er(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=$n(e);return{...e.include.length>0?{include:[...e.include]}:{},...t.length>0?{exclude:[...t]}:{}}}}}function tr(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:{get title(){return M.t(`helpers.notificationRuleActions.onActivationTitle`)},get hint(){return M.t(`helpers.notificationRuleActions.onActivationHint`)}},onDeactivation:{get title(){return M.t(`helpers.notificationRuleActions.onDeactivationTitle`)},get hint(){return M.t(`helpers.notificationRuleActions.onDeactivationHint`)}},onTrigger:{get title(){return M.t(`helpers.notificationRuleActions.onTriggerTitle`)},get hint(){return M.t(`helpers.notificationRuleActions.onTriggerHint`)}},onTriggerOff:{get title(){return M.t(`helpers.notificationRuleActions.onTriggerOffTitle`)},get hint(){return M.t(`helpers.notificationRuleActions.onTriggerOffHint`)}}},nr={onActivation:[],onDeactivation:[],onTrigger:[],onTriggerOff:[],buttons:[]};function rr(e){return e===void 0?nr:{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.actionId.trim()!==``),n=e=>e.filter(e=>e.trim()!==``),r={onActivation:n(e.onActivation),onDeactivation:n(e.onDeactivation),onTrigger:n(e.onTrigger),onTriggerOff:n(e.onTriggerOff)};if(!(!K.some(e=>r[e].length>0)&&t.length===0))return{...r.onActivation.length>0?{onActivation:[...r.onActivation]}:{},...r.onDeactivation.length>0?{onDeactivation:[...r.onDeactivation]}:{},...r.onTrigger.length>0?{onTrigger:[...r.onTrigger]}:{},...r.onTriggerOff.length>0?{onTriggerOff:[...r.onTriggerOff]}:{},...t.length>0?{buttons:t}:{}}}function ir(e,t){let n=[];for(let r of K){let i=e[r];i.length>4&&n.push({kind:`too-many`,message:M.t(`helpers.notificationRuleActions.tooMany`,{title:q[r].title})}),i.some(e=>e.trim()!==``&&!t.has(e))&&n.push({kind:`unknown-action`,message:M.t(`helpers.notificationRuleActions.hookUnknownAction`,{title:q[r].title})})}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:M.t(`helpers.notificationRuleActions.dupButton`,{id:e})}),r.add(e),t.has(i.actionId.trim())||n.push({kind:`unknown-action`,message:M.t(`helpers.notificationRuleActions.buttonUnknownAction`,{label:i.label||e})}))}return n}function ar(e,t){let{confirm:n,...r}=e;return t?{...r,confirm:!0}:r}function or(e,t){return{id:`action-${String(e+1)}`,label:M.t(`helpers.notificationRuleActions.newButtonLabel`),actionId:t}}var sr=[{value:`acknowledge`,get label(){return M.t(`helpers.notificationRuleActions.icon_acknowledge`)}},{value:`dismiss`,get label(){return M.t(`helpers.notificationRuleActions.icon_dismiss`)}},{value:`silence`,get label(){return M.t(`helpers.notificationRuleActions.icon_silence`)}},{value:`snooze`,get label(){return M.t(`helpers.notificationRuleActions.icon_snooze`)}},{value:`view`,get label(){return M.t(`helpers.notificationRuleActions.icon_view`)}},{value:`play`,get label(){return M.t(`helpers.notificationRuleActions.icon_play`)}},{value:`camera`,get label(){return M.t(`helpers.notificationRuleActions.icon_camera`)}},{value:`open`,get label(){return M.t(`helpers.notificationRuleActions.icon_open`)}},{value:`close`,get label(){return M.t(`helpers.notificationRuleActions.icon_close`)}},{value:`unlock`,get label(){return M.t(`helpers.notificationRuleActions.icon_unlock`)}},{value:`lock`,get label(){return M.t(`helpers.notificationRuleActions.icon_lock`)}},{value:`disarm`,get label(){return M.t(`helpers.notificationRuleActions.icon_disarm`)}},{value:`arm`,get label(){return M.t(`helpers.notificationRuleActions.icon_arm`)}},{value:`arm-home`,get label(){return M.t(`helpers.notificationRuleActions.icon_arm_home`)}},{value:`arm-away`,get label(){return M.t(`helpers.notificationRuleActions.icon_arm_away`)}},{value:`arm-night`,get label(){return M.t(`helpers.notificationRuleActions.icon_arm_night`)}},{value:`light`,get label(){return M.t(`helpers.notificationRuleActions.icon_light`)}},{value:`alert`,get label(){return M.t(`helpers.notificationRuleActions.icon_alert`)}}];function cr(e){let t=new Set;for(let n of K)for(let r of e[n])r.trim()!==``&&t.add(r);for(let n of e.buttons)n.actionId.trim()!==``&&t.add(n.actionId);return t}function lr(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[];for(let t of cr(e))r.push(...n.get(t)?.steps??[]);return r}var ur=[10,30,60],dr=[5,10,15,30,60,120,240,480];function fr(e){return e>=60&&e%60==0?M.t(`helpers.ruleFormState.snoozeHours`,{count:e/60}):M.t(`helpers.ruleFormState.snoozeMin`,{count:e})}var pr=new Set([`alarm-arm-refused`,`alarm-check-failed`,`alarm-arming`,`alarm-armed`,`alarm-pending`,`alarm-triggered`,`alarm-rearmed`,`alarm-sensor-bypass`,`alarm-disarmed`]);function mr(e,t){for(let t of e.systemEvent?.kinds??[])if(pr.has(t))return!0;for(let e of Re(t))if(Ie(e))return!0;return!1}function hr(e,t){return lr(e,t)}function gr(e){let{devices:t,devicesExclude:n,classes:r,classesExclude:i,...a}=e;return{conditions:a,deviceScope:W(t,n),classScope:W(r,i)}}function _r(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 vr(e){return e.deviceScope.mode===`only`?e.deviceScope.include:[]}function yr(e,t,n){let r=C(n);return e.some(e=>e.id===t&&O(e,n.delivery,r))}function br(e=`immediate`,t={}){return{name:``,tags:[],enabled:!0,delivery:e,targetIds:[],targetUsers:[],targetParams:{},targetOverrides:{},priority:3,mediaImage:re({},C({delivery:e,conditions:t})),mediaShowTriggerZone:!1,mediaShowSubjectPath:!1,mediaGif:!1,mediaClip:!1,mediaProfile:void 0,mediaClipSpeed:void 0,mediaLinkedCameras:void 0,mediaWakeSleepingCamera:void 0,templateTitle:``,templateBody:``,...gr(t),schedule:void 0,systemEventDelivery:e===`system-event`?mn:void 0,snoozeAllowGlobal:!1,groupingSec:void 0,groupWithinSec:k({delivery:e}),snoozeOptions:void 0,askVerdict:void 0,offerAlertAction:void 0,actions:nr,cooldownSec:30,cooldownScope:`rule-device`,cooldownGranularity:void 0}}function xr(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,tags:e.tags??[],enabled:e.enabled,delivery:e.delivery,targetIds:e.targets.map(e=>e.targetId),targetUsers:e.targetUsers??[],targetParams:t,targetOverrides:e.targetOverrides??{},priority:e.priority,mediaImage:re(e.media,C(e)),mediaShowTriggerZone:e.media.showTriggerZone===!0,mediaShowSubjectPath:e.media.showSubjectPath===!0,mediaGif:e.media.gif===!0,mediaClip:e.media.clip===!0,mediaProfile:e.media.profile,mediaClipSpeed:e.media.clipSpeed,mediaLinkedCameras:e.media.linkedCameras,mediaWakeSleepingCamera:e.media.wakeSleepingCamera,templateTitle:e.template?.title??``,templateBody:e.template?.body??``,...gr(e.conditions),schedule:e.schedule,systemEventDelivery:e.systemEventDelivery,snoozeAllowGlobal:e.snoozeAllowGlobal===!0,groupingSec:e.groupingSec,groupWithinSec:k(e),snoozeOptions:e.snoozeOptions,askVerdict:e.askVerdict,offerAlertAction:e.offerAlertAction,actions:rr(e.actions),cooldownSec:e.throttle.cooldownSec,cooldownScope:e.throttle.scope,cooldownGranularity:e.throttle.granularity}}function Sr(e,t){let n=[],r=e.groupWithinSec;if((!Number.isInteger(r)||r<0||r>300)&&n.push(`Group notifications within is a whole number of seconds between 0 and 300.`),Mr(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&&!Nr(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(He(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(Vt)} (24 hours). 0 means every match is delivered.`),S(e.delivery))for(let t of Ve({delivery:e.delivery,conditions:e.conditions,...e.systemEventDelivery===void 0?{}:{systemEventDelivery:e.systemEventDelivery},...J(e.actions)===void 0?{}:{actions:J(e.actions)}}))n.push(oe(t));return n}function Cr(e){let t=e.systemEventDelivery;if(t===void 0)return{};if(!S(e.delivery))return t.mode===`instant`?{}:{systemEventDelivery:{mode:`instant`}};let n=le(e.conditions.systemEvent?.kinds??[]);if(!(n.kind===`family`&&Se.includes(n.family)))return t.mode===`modes`?{}:{systemEventDelivery:t};let r=y({systemEventDelivery:t}).schedule;if(r!==null&&ue(r.schedule)===null){let e=ie(r.schedule);if(e!==null&&e.times.length>0){let n=w(e.times,r.schedule.timezone);if(t.mode===`modes`)return{systemEventDelivery:{...t,onSchedule:{...r,schedule:n}}};if(t.mode===`summary`)return{systemEventDelivery:{...t,schedule:n}}}}return{systemEventDelivery:t}}function wr(e){if(!Y(e))return null;if(!Ee(e.templateBody))return M.t(`helpers.ruleFormState.summaryWarnNone`,{token:`{{summaryText}}`});let t=e.templateBody;return ce({...e.systemEventDelivery===void 0?{}:{systemEventDelivery:e.systemEventDelivery}})===`section`&&t.trim().length>0&&!/\{\{\s*summaryText\s*\}\}/.test(t)?M.t(`helpers.ruleFormState.summaryWarnSplit`,{token:`{{summaryText}}`}):null}function Y(e){return be({delivery:e.delivery,...e.systemEventDelivery===void 0?{}:{systemEventDelivery:e.systemEventDelivery}})}function Tr(e,t,n=new Set){return Sr(e,t).length===0&&Ft(e.delivery)&&(!S(e.delivery)||Lr(e)>0)&&C(e)!==`mixed`&&e.name.trim().length>0&&(e.targetIds.length>0||e.targetUsers.length>0)&&ir(e.actions,n).length===0}function Er(e,t){let n=Fr(e.conditions,t),r=S(t)&&(n.systemEvent?.kinds.length??0)===0,i=S(t)&&e.systemEventDelivery===void 0?mn:e.systemEventDelivery;return r?{...e,delivery:t,systemEventDelivery:i,conditions:{...n,systemEvent:An(`device-events`)}}:{...e,delivery:t,conditions:n,systemEventDelivery:i}}function Dr(e,t){return t===`immediate-grouped`?Or(e,{...Er(e,`immediate`),groupingSec:e.groupingSec??20}):Or(e,{...Er(e,t),groupingSec:void 0})}function Or(e,t){let n=k({delivery:e.delivery}),r=k({delivery:t.delivery}),i=e.groupWithinSec!==n;return{...t,groupWithinSec:i?e.groupWithinSec:r}}function kr(e){return e.delivery===`immediate`||e.delivery===`track-end`}var Ar=new Set([`alert-critical`,`alert-error`,`device-attention-required`]);function jr(e){return(e.conditions.systemEvent?.kinds??[]).some(e=>Ar.has(e))}function Mr(e){return e.groupingSec!==void 0&&x(e)}function Nr(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 Pr=new Set([`immediate`,`track-end`,`package-event`]);function Fr(e,t){if(e.source!==`pipeline`||Pr.has(t))return e;let{source:n,...r}=e;return r}function Ir(e,t){return xe(e.conditions.systemEvent)===t?e:{...e,conditions:{...e.conditions,systemEvent:An(t)}}}function Lr(e){return e.conditions.systemEvent?.kinds.length??0}function Rr(e,t){return n=>{let r=e.find(e=>e.id===n);if(r===void 0)return;let i=t.find(e=>e.kind===r.kind&&e.addonId===r.addonId)?.caps;return i===void 0?void 0:De(i)}}function zr(e,t,n){let r=Rr(t,n),i=_e(e.map(e=>({name:t.find(t=>t.id===e)?.name??e,fields:r(e)})));return new Map(i.map(e=>[e.field,e]))}function Br(e,t,n){let r={};for(let i of e){let e=t[i];if(e===void 0)continue;let a=Pe(e,n?.(i));a!==void 0&&(r[i]=a)}return r}function Vr(e,t,n){let{[t]:r,...i}=e;return n===void 0?i:{...i,[t]:n}}function Hr(e,t,n,r){let{[t]:i,...a}=e,{[n]:o,...s}=i??{},c=r===void 0?s:{...s,[n]:r};return Object.keys(c).length===0?a:{...a,[t]:c}}function Ur(e,t,n){let r=t.find(t=>t.id===e);if(r===void 0)return;let i=n.find(e=>e.kind===r.kind&&e.addonId===r.addonId)?.caps;if(i!==void 0)return{levels:b(i),attachmentKinds:Te(i)}}var Wr={rule:{fields:[`title`,`body`,`priority`,`attachments`,`actions`],attachmentKinds:[`none`,`image`,`clip`,`gif`]},summary:{fields:[`title`,`body`,`priority`,`attachments`],attachmentKinds:[`none`,`image`]},timelapse:{fields:[`title`,`body`,`priority`,`attachments`],attachmentKinds:[`none`,`image`,`clip`]},"calendar-events":{fields:[`title`,`body`,`priority`],attachmentKinds:[]}};function Gr(e,t){return Wr[e].fields.includes(t)}function Kr(e,t){let n=Wr[e].attachmentKinds;return t.filter(e=>n.includes(e))}function qr(e){return e.map(e=>({id:e.id,name:e.name,enabled:e.enabled,kind:e.kind??``,addonId:e.addonId??``,config:{}}))}function X(e,t){return e.appliesTo.includes(t)}var Jr={source:`any`};function Yr(e,t){if(t==null)return!0;if(Array.isArray(t))return t.length===0;if(typeof t==`string`)return t.length===0||Jr[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 Xr=qe.filter(e=>e.id===`audio`);function Zr(e){if(e.length===0)return e;let t=new Set(e.map(e=>e.id)),n=Xr.filter(e=>!t.has(e.id));return n.length===0?e:[...e,...n]}function Qr(e,t,n,r=C({delivery:t,conditions:e})){let i=n.length===0?null:new Set(n.filter(e=>e.id!==`schedule`&&O(e,t,r)).map(e=>e.id)),a={};for(let[t,n]of Object.entries(e))i!==null&&!i.has(t)||R(t,e)&&(Yr(t,n)||(a[t]=n));return a}function $r(e,t){if(e===void 0)return{};let n=Vn(e,t.systemEvent);return n===void 0?{}:{systemEvent:n}}function ei(e){return e!==void 0&&e.windows.length>0}function ti(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 ni(e){let t=ti(e.media);return{...e.confirm===void 0?{}:{confirm:e.confirm},...t===void 0?{}:{media:t}}}function ri(e,t,n=[],r){let i=e.templateTitle.trim(),a=e.templateBody.trim(),o=i.length>0||a.length>0?{...i.length>0?{title:i}:{},...a.length>0?{body:a}:{}}:void 0,s=J(e.actions),c=C(e),l=A(c),u=se(c),d=n.length===0?!0:n.some(t=>t.id===`schedule`&&X(t,e.delivery)),f=!Y(e)&&d&&ei(e.schedule)?e.schedule:void 0,p=n.length===0?!0:n.some(t=>t.id===`devices`&&X(t,e.delivery)),m=n.length===0?!0:n.some(t=>t.id===`devicesExclude`&&X(t,e.delivery)),{devices:h,devicesExclude:g,..._}=_r(e),v=Qr(_,e.delivery,n,c);return{name:e.name.trim(),tags:[...e.tags],enabled:e.enabled,delivery:e.delivery,conditions:{...v,...p&&h!==void 0?{devices:h}:{},...m&&g!==void 0?{devicesExclude:g}:{},...$r(u,e.conditions)},...f?{schedule:f}:{},...Cr(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]}:{},targetOverrides:Br(e.targetIds,e.targetOverrides,r),media:l.carriesMedia?{image:e.mediaImage,...e.mediaShowTriggerZone&&e.mediaImage!==`crop`&&e.mediaImage!==`none`&&ne(v).length>0?{showTriggerZone:!0}:{},...e.mediaShowSubjectPath&&e.mediaImage!==`none`&&me(c)?{showSubjectPath:!0}:{},...e.mediaGif?{gif:!0}:{},...e.mediaClip?{clip:!0}:{},...e.mediaProfile===void 0?{}:{profile:e.mediaProfile},...e.mediaClipSpeed===void 0?{}:{clipSpeed:e.mediaClipSpeed},...c===`sensor`&&e.mediaImage!==`none`&&e.mediaLinkedCameras!==void 0?{linkedCameras:e.mediaLinkedCameras}:{},...c===`sensor`&&e.mediaImage!==`none`&&e.mediaWakeSleepingCamera===!1?{wakeSleepingCamera:!1}:{},...(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}:{}}:{image:`none`},throttle:{cooldownSec:e.cooldownSec,scope:e.cooldownScope,...e.cooldownGranularity===void 0?{}:{granularity:e.cooldownGranularity}},priority:e.priority,...o?{template:o}:{},...e.snoozeAllowGlobal?{snoozeAllowGlobal:!0}:{},...Mr(e)?{groupingSec:e.groupingSec}:{},groupWithinSec:e.groupWithinSec,...e.snoozeOptions===void 0?{}:{snoozeOptions:[...e.snoozeOptions]},...e.askVerdict!==void 0&&kr(e)?{askVerdict:e.askVerdict}:{},...e.offerAlertAction!==void 0&&jr(e)?{offerAlertAction:e.offerAlertAction}:{},...t?.confirm===void 0?{}:{confirm:t.confirm},...s===void 0?{}:{actions:s}}}function ii(e,t){let n=ri(e,void 0,t);return[`template`,`schedule`,`targetUsers`,`snoozeOptions`,`snoozeAllowGlobal`,`groupingSec`,`actions`].filter(e=>n[e]===void 0)}var ai=[{key:`rule`,get label(){return M.t(`helpers.ruleFormTabs.tab_rule`)},fields:[`name`,`tags`,`enabled`,`delivery`,`groupingSec`,`groupWithinSec`,`targetIds`,`targetUsers`,`targetParams`,`targetOverrides`]},{key:`devices`,get label(){return M.t(`helpers.ruleFormTabs.tab_devices`)},fields:[`deviceScope`]},{key:`conditions`,get label(){return M.t(`helpers.ruleFormTabs.tab_conditions`)},fields:[`conditions`,`classScope`,`schedule`]},{key:`notification`,get label(){return M.t(`helpers.ruleFormTabs.tab_notification`)},fields:[`priority`,`mediaImage`,`mediaShowTriggerZone`,`mediaShowSubjectPath`,`mediaGif`,`mediaClip`,`mediaProfile`,`mediaClipSpeed`,`mediaLinkedCameras`,`mediaWakeSleepingCamera`,`templateTitle`,`templateBody`,`systemEventDelivery`]},{key:`actions`,get label(){return M.t(`helpers.ruleFormTabs.tab_actions`)},fields:[`actions`]},{key:`advanced`,get label(){return M.t(`helpers.ruleFormTabs.tab_advanced`)},fields:[`snoozeAllowGlobal`,`snoozeOptions`,`askVerdict`,`offerAlertAction`,`cooldownSec`,`cooldownScope`,`cooldownGranularity`]}];function oi(e,t={}){let n=C({delivery:e,conditions:t}),r=A(n),i=ai.map(e=>e.key===`conditions`?{...e,label:r.label}:e);return he(n)?i.filter(e=>e.key!==`devices`):i}function si(e){if(e.audio!==void 0)return M.t(`helpers.ruleFormTabs.condSound`);if(e.occupancy!==void 0)return M.t(`helpers.ruleFormTabs.condOccupancy`)}function ci(e){let t=C(e),n=fe(_r(e),t);return t===`sensor`&&e.conditions.sensorTransition!==void 0&&!R(`sensorTransition`,e.conditions)?[...n,{conditionId:`sensorTransition`,reason:Ue}]:n}var li=`rule`;function ui(e){return ai.find(t=>t.key===e)?.key}function di(e){return e?.toLowerCase().startsWith(`it`)===!0?`it`:`en`}function fi(){let{i18n:e}=N(),t=di(e.language);return e=>ve(e,t)}i();var pi=`block text-[11px] font-medium text-foreground`,Z=`text-[10px] text-foreground-subtle mt-0.5`;function mi({cameras:e,fleet:t,value:r,onChange:i,emptyMeansAll:a=!1,savedHadDevices:o=!1}){return n(et,{devices:e,listState:t.state,fleet:t,value:r,onChange:i,emptyMeansAll:a,savedHadDevices:o})}function hi({value:t,placeholder:i,onChange:a}){let{t:o}=N(),[c,l]=r(``),u=()=>{let e=c.trim();if(e.length===0||t.includes(e)){l(``);return}a([...t,e]),l(``)},d=e=>a(t.filter(t=>t!==e));return e(`div`,{className:`mt-1 space-y-1.5`,children:[t.length>0&&n(`div`,{className:`flex flex-wrap gap-1`,children:t.map(t=>e(`span`,{className:`inline-flex items-center gap-1 rounded bg-surface-hover px-1.5 py-0.5 text-[11px] text-foreground`,children:[t,n(_,{variant:`unstyled`,type:`button`,onClick:()=>d(t),"aria-label":o(`system.notificationConditionWidgets.remove`,`remove {{v}}`,{v:t}),className:`text-foreground-subtle hover:text-danger`,children:n(s,{className:`h-3 w-3`})})]},t))}),n(g,{value:c,placeholder:i,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),u())},onBlur:u})]})}function gi({picker:r,value:i,onChange:a}){let{t:o}=N(),s=t(()=>We(r),[r]),c=t(()=>new Set(i),[i]),l=i.filter(e=>!s.has(e)),u=e=>{a(c.has(e)?i.filter(t=>t!==e):[...i,e])};return e(`div`,{className:`space-y-2`,children:[l.length>0&&n(`div`,{className:`flex flex-wrap gap-1`,children:l.map(t=>e(_,{variant:`unstyled`,type:`button`,onClick:()=>a(i.filter(e=>e!==t)),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:o(`system.notificationConditionWidgets.customValueClickToRemove`,`Custom value — click to remove`),children:[t,` ×`]},t))}),r.groups.map(t=>e(`div`,{children:[n(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-muted mb-1`,children:t.fallbackLabel}),n(`div`,{className:`flex flex-wrap gap-1`,children:t.options.map(e=>{let t=c.has(e.value);return n(_,{variant:`unstyled`,type:`button`,"aria-pressed":t,onClick:()=>u(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)})})]},t.key))]})}function _i({value:t,min:r,max:i,step:a,onChange:o}){let{t:s}=N();return e(`div`,{className:`mt-1 flex items-center gap-2`,children:[n(g,{type:`number`,value:t??``,min:r,max:i,step:a,className:`max-w-[8rem]`,onChange:e=>{let t=e.target.value;if(t===``){o(void 0);return}let n=Number(t);o(Number.isFinite(n)?n:void 0)}}),t!==void 0&&i!==void 0&&n(l,{min:r,max:i,step:a,value:t,onChange:e=>o(Number(e.target.value)),className:`flex-1 accent-primary`,"aria-label":s(`common.valueWord`)})]})}function vi({value:t,onChange:r,options:i}){let{t:a}=N(),o=yi(i??[]),s=o.length>0?o:rn;return e(`div`,{className:`mt-1 space-y-1`,children:[n(d,{value:t??`enter`,options:s.map(e=>({value:e.value,label:a(`notificationRules.crossing.${e.value}`,e.label)})),onChange:e=>r(on(e.target.value))}),n(`p`,{className:Z,children:a(`notificationRules.crossing.hint`,`Which way the subject crosses the zone.`)})]})}function yi(e){let t=[];for(let n of e){let e=n.value===``||n.value===`enter`?an:on(n.value);e===void 0||t.some(t=>t.value===e)||t.push({value:e,label:n.label})}return t}function bi({deviceIds:e,cameras:t,value:r,onChange:i}){let{options:a,loading:o}=F(e,t);return n(I,{options:a,value:r,onChange:i,loading:o,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 xi({deviceIds:r,cameras:i,allDevices:a,value:s,onChange:c}){let{t:l}=N(),{options:u,loading:d}=wt(r),f=Tt(t(()=>Ct(r,i,a),[r,i,a]));return e(o,{children:[n(I,{options:t(()=>{let e=new Set(f.options.map(e=>e.value));return[...f.options,...u.filter(t=>!e.has(t.value))]},[f.options,u]),value:s,onChange:c,loading:d||f.pending,emptyHint:r.length===0?l(`system.notificationConditionWidgets.eventTokensSelectDevices`,`Select a device above to pick one of its events — or type a token.`):l(`system.notificationConditionWidgets.eventTokensNone`,`The selected devices declare no events — type a token.`),placeholder:l(`system.notificationConditionWidgets.eventToken`,`Event token…`)}),f.unknownDevices.length>0&&n(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:l(`system.notificationConditionWidgets.eventTokensUnknown`,`Could not read the events of: {{devices}}. They are unknown, not absent.`,{devices:f.unknownDevices.join(`, `)})})]})}var Q=[{value:`became-occupied`,labelKey:`system.notificationConditionWidgets.opBecameOccupied`},{value:`became-free`,labelKey:`system.notificationConditionWidgets.opBecameFree`},{value:`>=`,labelKey:`system.notificationConditionWidgets.opCountAtLeast`},{value:`<=`,labelKey:`system.notificationConditionWidgets.opCountAtMost`}];function Si(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:M.t(`system.notificationConditionWidgets.subTypeNeverCountsAlways`,`{{stored}} — sub-type, never counts (always 0)`,{stored:t})}]}function Ci({deviceIds:t,cameras:r,classOptions:i,value:a,onChange:o}){let{t:s}=N(),{options:l,loading:u}=F(t,r),f=a??ee,p=e=>o({...f,...e}),m=f.op===`became-occupied`||f.op===`became-free`,h=Si(i,f.className);return e(`div`,{className:`mt-1 space-y-1.5`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[n(`div`,{className:`min-w-[10rem]`,children:n(d,{value:f.zoneId??``,options:[{value:``,label:u?s(`system.notificationConditionWidgets.loadingZones`,`Loading zones…`):s(`system.notificationConditionWidgets.wholeFrame`,`— whole frame —`)},...l.map(e=>({value:e.value,label:e.label}))],onChange:e=>p({zoneId:e.target.value===``?void 0:e.target.value})})}),n(`div`,{className:`min-w-[9rem]`,children:n(d,{value:f.className??``,options:[{value:``,label:s(`system.notificationConditionWidgets.anyClass`,`— any class —`)},...h],onChange:e=>p({className:e.target.value===``?void 0:e.target.value})})}),n(`div`,{className:`min-w-[9rem]`,children:n(d,{value:f.op,options:Q.map(e=>({value:e.value,label:s(e.labelKey)})),onChange:e=>{let t=Q.find(t=>t.value===e.target.value);t&&p({op:t.value})}})})]}),e(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:[e(`label`,{className:`flex items-center gap-1`,children:[m?s(`system.notificationConditionWidgets.threshold`,`Threshold`):s(`system.notificationConditionWidgets.count`,`Count`),n(g,{type:`number`,min:0,className:`w-16`,value:String(f.count),onChange:e=>p({count:Math.max(0,Number(e.target.value)||0)})})]}),e(`div`,{className:`flex items-center gap-1`,children:[s(`system.notificationConditionWidgets.holdFor`,`Hold for`),n(c,{"aria-label":s(`system.notificationConditionWidgets.holdFor`,`Hold for`),value:f.sustainSeconds,min:0,max:3600,onChange:e=>p({sustainSeconds:Math.min(3600,Math.max(0,e))})}),` `]}),a===void 0?null:n(_,{variant:`unstyled`,type:`button`,onClick:()=>o(void 0),className:`underline hover:text-foreground`,children:s(`system.notificationConditionWidgets.clear`,`Clear`)})]}),t.length===0&&n(`p`,{className:`text-[11px] text-warning`,children:s(`system.notificationConditionWidgets.noCameraPickedOnThe`,`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.`)}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:s(`system.notificationConditionWidgets.countsConfirmedTrackedObjectsFrom`,`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 wi=[{value:`label`,labelKey:`system.notificationConditionWidgets.audioModeLabel`,Icon:f},{value:`level`,labelKey:`system.notificationConditionWidgets.audioModeLevel`,Icon:u}];function Ti({taxonomy:t,value:r,onChange:i}){let{t:a}=N(),s=Ge(r),l=e=>i(Fe(r,e)),{choices:u,unknownLabels:d}=Ae(t,s.labels),f=Le(r)??`label`;return e(`div`,{className:`mt-1 space-y-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1`,children:[wi.map(t=>n(_,{variant:`unstyled`,type:`button`,"aria-pressed":f===t.value,onClick:()=>l({mode:t.value}),className:`rounded border px-2 py-0.5 text-[11px] ${f===t.value?`border-primary bg-primary/15 text-foreground`:`border-border text-foreground-subtle hover:bg-surface-hover`}`,children:e(`span`,{className:`inline-flex items-center gap-1`,children:[n(t.Icon,{className:`h-3 w-3`}),a(t.labelKey)]})},t.value)),r===void 0?null:n(_,{variant:`unstyled`,type:`button`,onClick:()=>i(void 0),className:`ml-1 text-xs text-foreground-subtle underline hover:text-foreground`,children:a(`system.notificationConditionWidgets.clear`,`Clear`)})]}),f===`label`?e(o,{children:[n(`div`,{className:`flex flex-wrap gap-1`,children:u.map(t=>{let r=Me(s.labels,t.value),i=t.unknown?`border-dashed border-warning text-warning`:r?`border-primary bg-primary/15 text-foreground`:`border-border text-foreground hover:bg-surface-hover`;return n(_,{variant:`unstyled`,type:`button`,"aria-pressed":r,title:t.unknown?a(`system.notificationConditionWidgets.storedByTheRuleNot`,`Stored by the rule — not offered by this hub`):void 0,onClick:()=>l({labels:Be(s.labels,t.value)}),className:`rounded border px-1.5 py-0.5 text-[10px] ${i}`,children:e(`span`,{className:`inline-flex items-center gap-1`,children:[n($e,{iconId:t.iconId,size:12}),t.label]})},t.value)})}),d.length>0&&e(`p`,{className:`text-[10px] text-warning`,children:[a(`system.notificationConditionWidgets.keptFromTheRuleUnknown`,`Kept from the rule, unknown to this hub:`),` `,d.join(`, `)]}),e(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:[e(`label`,{className:`flex items-center gap-1`,children:[a(`system.notificationConditionWidgets.confirmAfter`,`Confirm after`),n(g,{type:`number`,min:1,max:20,step:1,className:`w-16`,value:String(s.confirmHits??2),onChange:e=>l({confirmHits:Number(e.target.value)})}),a(`system.notificationConditionWidgets.frames`)]}),e(`div`,{className:`flex items-center gap-1`,children:[a(`system.notificationConditionWidgets.within`),n(c,{"aria-label":a(`system.notificationConditionWidgets.within`),value:s.confirmWindowSec??5,min:1,max:60,onChange:e=>l({confirmWindowSec:e})}),` `]})]}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`system.notificationConditionWidgets.audioConfirmHint`,{hits:2,window:5})})]}):e(o,{children:[n(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:e(`label`,{className:`flex items-center gap-1`,children:[a(`system.notificationConditionWidgets.louderThan`,`Louder than`),n(g,{type:`number`,min:D,max:0,step:3,className:`w-20`,value:String(s.dbThreshold??Oe),onChange:e=>l({dbThreshold:Number(e.target.value)})}),`dBFS`]})}),e(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:[e(`label`,{className:`flex items-center gap-1`,children:[a(`system.notificationConditionWidgets.hits`,`Hits`),n(g,{type:`number`,min:1,max:100,step:5,className:`w-16`,value:String(s.hitPercent),onChange:e=>l({hitPercent:Number(e.target.value)})}),a(`system.notificationConditionWidgets.hitsPercentDefault`,{value:ze.hitPercent})]}),e(`div`,{className:`flex items-center gap-1`,children:[a(`system.notificationConditionWidgets.over`),n(c,{"aria-label":a(`system.notificationConditionWidgets.over`),value:s.samplingSeconds,min:1,max:300,onChange:e=>l({samplingSeconds:e})}),a(`system.notificationConditionWidgets.secondsDefault`,{value:ze.samplingSeconds})]})]}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`system.notificationConditionWidgets.dbfsHint`,{min:D})})]}),He(r)?n(`p`,{className:`text-[11px] text-warning`,children:a(`system.notificationConditionWidgets.withNeitherASoundNor`,`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 Ei({value:t,onChange:r}){let{t:i}=N(),a=t?.values??[],o=t?.maxDistance??1,s=e=>r(e.length>0?{values:e,maxDistance:o}:void 0),c=e=>r(a.length>0?{values:a,maxDistance:e}:void 0),l=Dt().filter(e=>!a.includes(e));return e(`div`,{className:`mt-1 space-y-1.5`,children:[n(hi,{value:a,placeholder:i(`system.notificationConditionWidgets.plateText`,`Plate text…`),onChange:s}),l.length>0&&e(`div`,{className:`flex flex-wrap items-center gap-1`,children:[n(`span`,{className:`text-[10px] text-foreground-subtle`,children:i(`system.notificationConditionWidgets.seen`,`Seen:`)}),l.slice(0,12).map(e=>n(_,{variant:`unstyled`,type:`button`,onClick:()=>s([...a,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))]}),e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[i(`system.notificationConditionWidgets.maxDistance`,`Max distance`),n(g,{type:`number`,min:0,max:3,step:1,value:o,className:`max-w-[5rem]`,onChange:e=>{let t=Number(e.target.value);c(Number.isFinite(t)?Math.max(0,Math.min(3,t)):1)}})]})]})}function Di({gateable:t,value:r,onChange:i}){let{t:a}=N(),o=fi(),s=t.find(e=>e.id===r?.deviceId),c=new Set(r?.states??[]),l=e=>{let t=Number(e);if(!Number.isFinite(t)||t===0)return i(void 0);i({deviceId:t,states:[]})},u=e=>{if(r===void 0)return;let t=new Set(c);t.has(e)?t.delete(e):t.add(e),i(t.size===0?void 0:{deviceId:r.deviceId,states:[...t]})};return e(`div`,{className:`mt-1 space-y-2`,children:[n(d,{value:r===void 0?``:String(r.deviceId),options:[{value:``,label:a(`system.notificationConditionWidgets.noDeviceGate`,`— no device gate —`)},...t.map(e=>({value:String(e.id),label:e.name}))],onChange:e=>l(e.target.value)}),s!==void 0&&n(`div`,{className:`flex flex-wrap gap-1.5`,children:s.states.map(e=>n(_,{variant:`unstyled`,type:`button`,onClick:()=>u(e),className:c.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:o(e)},e))}),s!==void 0&&s.states.length===0&&n(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:a(`system.notificationConditionWidgets.thisDeviceReportsNoState`,`This device reports no state the gate can read, so it cannot arm a rule.`)}),r!==void 0&&n(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:a(`system.notificationConditionWidgets.theRuleIsSilentWhile`,`The rule is silent while the device is in any other state — including when its state cannot be read at all.`)})]})}function Oi(e,t){let n=t(e.verdict);return e.latched?`${n} · ${t(`latched`)}`:n}function ki({scenes:t,value:r,onChange:i}){let{t:a}=N(),o=fi(),s=t.find(e=>e.sceneId===r?.sceneId),c=e=>{if(e===``)return i(void 0);let n=t.find(t=>t.sceneId===e);if(n===void 0)return i(void 0);i({sceneId:e,deviceId:n.deviceId,requiredState:r?.requiredState??`diverged`,...r?.latched===void 0?{}:{latched:r.latched}})},l=e=>{r!==void 0&&i({...r,requiredState:e===`matched`?`matched`:`diverged`})},u=e=>{if(r!==void 0){if(e===``){let{latched:e,...t}=r;return i(t)}i({...r,latched:e===`latched`})}};return t.length===0?n(`p`,{className:Z,children:a(`notificationRules.scene.none`,`No scenes yet — create one on the Scenes page.`)}):e(`div`,{className:`mt-1 space-y-2`,children:[n(d,{value:r?.sceneId??``,options:[{value:``,label:a(`notificationRules.scene.noGate`,`— no scene gate —`)},...t.map(e=>({value:e.sceneId,label:`${e.cameraName} · ${e.label} — ${Oi(e,o)}`}))],onChange:e=>c(e.target.value)}),r!==void 0&&e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[a(`notificationRules.scene.onlyWhile`,`Only while it is`),n(d,{value:r.requiredState,options:[{value:`diverged`,label:o(`diverged`)},{value:`matched`,label:o(`matched`)}],onChange:e=>l(e.target.value)})]}),e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[a(`notificationRules.scene.read`,`Read`),n(d,{value:r.latched===void 0?``:r.latched?`latched`:`live`,options:[{value:``,label:s===void 0?a(`notificationRules.scene.readOwn`,`The scene's own setting`):`${a(`notificationRules.scene.readOwn`,`The scene's own setting`)} (${o(s.emit)})`},{value:`latched`,label:o(`latched`)},{value:`live`,label:o(`live`)}],onChange:e=>u(e.target.value)})]})]}),s!==void 0&&e(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:[a(`notificationRules.scene.rightNow`,`Right now:`),` `,Oi(s,o)]}),r!==void 0&&s===void 0&&n(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:a(`notificationRules.scene.missing`,`This scene no longer exists — pick another or remove the gate.`)})]})}function Ai(){return{days:[1,2,3,4,5],startMinute:540,endMinute:1080}}function ji(e){return{days:[...z.days],minute:e}}var Mi=`Always active — add a window to restrict when the rule fires.`;function Ni({value:e,onChange:t,mode:r=`windows`,defaultMinute:i=z.minute,emptyHint:a}){return r===`times`?n(Fi,{value:e,onChange:t,defaultMinute:i}):n(Pi,{value:e,onChange:t,emptyHint:a??Mi})}function Pi({value:t,onChange:r,emptyHint:i}){let{t:a}=N(),o=t?.windows??[],s=t?.invert??!1,c=(e,n)=>{if(e.length===0){r(void 0);return}r({windows:e,...n?{invert:!0}:{},...t?.timezone?{timezone:t.timezone}:{}})},l=()=>c([...o,Ai()],s),u=e=>c(o.filter((t,n)=>n!==e),s),d=(e,t)=>c(o.map((n,r)=>r===e?t:n),s);return e(`div`,{className:`mt-1 space-y-2`,"data-testid":`schedule-field-windows`,children:[o.length===0?n(`p`,{className:Z,children:i}):o.map((e,t)=>n(Ii,{window:e,onChange:e=>d(t,e),onRemove:()=>u(t)},t)),e(`div`,{className:`flex items-center gap-3`,children:[e(_,{variant:`unstyled`,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:[n(p,{className:`h-3 w-3`}),` `,a(`system.notificationScheduleField.addWindow`)]}),o.length>0&&e(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[n(h,{checked:s,onChange:e=>c([...o],e.target.checked),className:`accent-primary`}),a(`system.notificationScheduleField.activeOutsideTheWindows`,`Active outside the windows`)]})]})]})}function Fi({value:t,onChange:r,defaultMinute:i}){let{t:a}=N(),o=t?.timezone,s=t===void 0?{times:[],approximated:!1}:ie(t);if(s===null)return e(`div`,{className:`mt-1 space-y-2`,"data-testid":`schedule-field-times-fallback`,children:[n(`p`,{className:Z,children:a(`system.notificationScheduleField.invertedScheduleShownAsBands`,`Inverted schedule — shown as bands. Clear the invert flag (or the windows) to author punctual times.`)}),n(Pi,{value:t,onChange:r,emptyHint:Mi})]});let c=s.times,l=e=>{if(e.length===0){r(void 0);return}r(w(e,o))};return e(`div`,{className:`mt-1 space-y-2`,"data-testid":`schedule-field-times`,children:[s.approximated&&n(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,"data-testid":`schedule-field-times-approximated`,children:a(`system.notificationScheduleField.shownAsSendAtTimes`,`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.`)}),c.length===0?n(`p`,{className:Z,children:a(`system.notificationScheduleField.noTimesYetAddOne`,`No times yet — add one to send on those days at that clock time.`)}):c.map((e,t)=>n(Li,{time:e,index:t,onChange:e=>l(c.map((n,r)=>r===t?e:n)),onRemove:c.length>1?()=>l(c.filter((e,n)=>n!==t)):void 0},t)),e(_,{variant:`unstyled`,type:`button`,onClick:()=>l([...c,ji(i)]),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:[n(p,{className:`h-3 w-3`}),` `,a(`system.notificationScheduleField.addTime`)]})]})}function Ii({window:t,onChange:r,onRemove:i}){let{t:a}=N();return n(`div`,{className:`space-y-1.5 rounded-md border border-border p-2`,children:e(`div`,{className:`flex items-start gap-2 text-xs`,children:[n(tt,{clockOnly:!0,value:rt(t),onChange:e=>{let t=Ze(e);t!==null&&r(t)},testIdPrefix:`schedule-window`}),n(_,{variant:`unstyled`,type:`button`,onClick:i,"aria-label":a(`system.notificationScheduleField.removeWindow`,`Remove window`),className:`text-foreground-subtle hover:text-danger`,children:n(m,{className:`h-3.5 w-3.5`})})]})})}function Li({time:t,index:r,onChange:i,onRemove:a}){let{t:o}=N();return e(`div`,{className:`space-y-1.5 rounded-md border border-border p-2`,children:[e(`div`,{className:`flex items-center gap-2 text-xs`,children:[n(`span`,{className:`text-foreground-subtle`,children:o(`system.notificationScheduleField.at`,`At`)}),n(g,{type:`time`,value:fn(t.minute),onChange:e=>i({...t,minute:pn(e.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`,"data-testid":`schedule-field-time-${String(r)}`}),n(`span`,{className:`flex-1`}),a!==void 0&&n(_,{variant:`unstyled`,type:`button`,onClick:a,"aria-label":o(`system.notificationScheduleField.removeTime`,`Remove time`),className:`text-foreground-subtle hover:text-danger`,children:n(m,{className:`h-3.5 w-3.5`})})]}),n(Ri,{days:t.days,onToggle:e=>{let n=t.days.includes(e)?t.days.filter(t=>t!==e):[...t.days,e];n.length!==0&&i({...t,days:n})}})]})}function Ri({days:e,onToggle:t}){return n(`div`,{className:`flex flex-wrap gap-1`,children:dn.map(r=>n(_,{variant:`unstyled`,type:`button`,onClick:()=>t(r.value),className:`rounded px-1.5 py-0.5 text-[10px] ${e.includes(r.value)?`bg-primary text-primary-foreground`:`bg-surface-hover text-foreground-subtle`}`,children:r.label},r.value))})}function zi(e){return e>=8}i();function Bi(e){if(typeof e!=`object`||!e)return;let t=Reflect.get(e,`windows`);if(!(!Array.isArray(t)||t.length===0))return e}function Vi(e){return e.type===`multiselect`}function Hi(e){let t=e.suggestions;return t===void 0||t.length===0?[]:t.map(e=>({value:e,label:e}))}function Ui(e){return e.map(e=>({value:e.value,label:e.label,...e.description===void 0?{}:{description:e.description},...e.iconId===void 0?{}:{iconId:e.iconId}}))}function Wi(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function Gi({field:t,values:r,onChange:i,onChangeMany:a,disabled:o,translationFn:s,onTestField:c,externalProbe:l,allFields:u,onAction:d}){let{t:f}=N();if(t.type===`tags`){if(!j(t,r,u))return null;let e=t.creatable!==!1;return n(Je,{mode:`multi`,options:Hi(t),value:Wi(r[t.key]),onChange:e=>i(t.key,e),disabled:o===!0||t.disabled===!0,creatable:e,...t.createLabel===void 0?{}:{createLabel:t.createLabel},...t.maxTags===void 0?{}:{maxItems:t.maxTags},label:$(t.label,s),description:t.description===void 0?void 0:$(t.description,s),placeholder:t.placeholder??f(`formBuilder.formBuilder.searchOrAdd`,`Search or add…`),testId:`config-tags-${t.key}`})}if(t.type===`schedule`){if(!j(t,r,u))return null;let a=$(t.label,s),o=t.description===void 0?void 0:$(t.description,s),c=t.mode===`times`?`times`:`windows`;return e(`div`,{className:`space-y-1`,"data-testid":`config-schedule-${t.key}`,children:[a!==void 0&&n(`label`,{className:`block text-[11px] font-medium text-foreground-subtle`,children:a}),o!==void 0&&n(`p`,{className:`text-[10px] text-foreground-subtle`,children:o}),n(Ni,{mode:c,value:Bi(r[t.key]),onChange:e=>i(t.key,e)})]})}return Vi(t)&&(zi(t.options.length)||t.creatable===!0)?j(t,r,u)?n(Je,{mode:`multi`,options:Ui(t.options),value:Wi(r[t.key]),onChange:e=>i(t.key,e),disabled:o===!0||t.disabled===!0,creatable:t.creatable===!0,...t.createLabel===void 0?{}:{createLabel:t.createLabel},...t.maxItems===void 0?{}:{maxItems:t.maxItems},label:$(t.label,s),description:t.description===void 0?void 0:$(t.description,s),placeholder:t.placeholder??f(`formBuilder.formBuilder.searchToAdd`,`Search to add…`),testId:`config-multiselect-${t.key}`,listboxId:`msel-${t.key}`}):null:n(Xe,{field:t,values:r,onChange:i,onChangeMany:a,disabled:o,translationFn:s,onTestField:c,externalProbe:l,allFields:u,onAction:d})}function Ki(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function $(e,t){if(e!==void 0)return t&&Ki(e)?t(e):e}function qi({section:t,values:i,onChange:a,onChangeMany:s,disabled:c,translationFn:l,onTestField:u,probeResults:d,onAction:f}){let[p,m]=r(t.defaultCollapsed??!1),h=t.style===`accordion`;if(t.fields.reduce((e,n)=>e+ +!!j(n,i,t.fields),0)===0)return null;let g=t.fields,_=t.columns??2,v=_===1?`grid-cols-1`:_===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:_===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`,y=t.fields.length===1&&t.fields[0]?.type===`widget`?t.fields[0]:void 0,b=y!==void 0||!t.title&&!t.description;return e(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},"data-settings-section":t.id,children:[!b&&(h?e(`button`,{type:`button`,"aria-expanded":!p,onClick:()=>m(e=>!e),className:`flex w-full items-center justify-between mb-2 text-left`,children:[e(`div`,{children:[t.title&&n(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:$(t.title,l)}),t.description&&n(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:$(t.description,l)})]}),n(nt,{expanded:!p,className:`ml-2`})]}):n(`div`,{className:`flex items-center justify-between mb-2`,children:e(`div`,{children:[t.title&&n(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:$(t.title,l)}),t.description&&n(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:$(t.description,l)})]})})),!(p&&!b)&&(y===void 0?n(o,{children:n(`div`,{className:`grid ${v} gap-x-3 gap-y-2.5`,children:g.map(e=>n(Gi,{field:e,values:i,onChange:a,onChangeMany:s,disabled:c,translationFn:l,onTestField:u,externalProbe:d?.[e.key],allFields:t.fields,onAction:f},e.key))})}):n(Xe,{field:y,values:i,onChange:a,onChangeMany:s,disabled:c,translationFn:l,onTestField:u,externalProbe:d?.[y.key],allFields:t.fields,onAction:f},y.key))]})}function Ji({schema:e,values:t,onChange:r,disabled:i,translationFn:a,onTestField:o,probeResults:s,onClearProbe:c,onAction:l,visibilityContext:u}){let d=u?{...u,...t}:t,f=(e,n)=>{r({...t,[e]:n}),c?.(e)},p=e=>{r({...t,...e});for(let t of Object.keys(e))c?.(t)};return n(`div`,{className:`space-y-4`,children:e.sections.map((e,t)=>n(qi,{section:e,values:d,onChange:f,onChangeMany:p,disabled:i,translationFn:a,onTestField:o,probeResults:s,onAction:l},`${e.id}-${t}`))})}export{K as $,jt as $t,Ur as A,bt as An,xn as At,br as B,Vt as Bt,ri as C,dt as Cn,Kn as Ct,Br as D,lt as Dn,B as Dt,zr as E,ft as En,V as Et,ur as F,bn as Ft,Y as G,en as Gt,hr as H,Ot as Ht,dr as I,yn as It,xr as J,tn as Jt,Sr as K,sn as Kt,jr as L,Zt as Lt,qr as M,gn as Mt,Vr as N,wn as Nt,Kr as O,ot as On,zn as Ot,Hr as P,vn as Pt,sr as Q,At as Qt,Dr as R,ln as Rt,ii as S,mt as Sn,Gn as St,Zr as T,vt as Tn,Rn as Tt,Tr as U,qt as Ut,vr as V,Ut as Vt,mr as W,Yt as Wt,wr as X,R as Xt,fr as Y,$t as Yt,kr as Z,Ht as Zt,li as _,ut as _n,Pn as _t,mi as a,un as an,ir as at,ui as b,st as bn,Wn as bt,Z as c,Mt as cn,er as ct,Ci as d,nn as dn,$n as dt,cn as en,q as et,Ei as f,Nt as fn,Zn as ft,bi as g,ht as gn,In as gt,gi as h,F as hn,Un as ht,vi as i,Qt as in,ar as it,Rr as j,yt as jn,hn as jt,Gr as k,gt as kn,Bn as kt,pi as l,Xt as ln,tr as lt,hi as m,Et as mn,Xn as mt,Ni as n,Lt as nn,or as nt,Di as o,Kt as on,Jn as ot,ki as p,I as pn,Qn as pt,yr as q,It as qt,Ti as r,Rt as rn,cr as rt,xi as s,Wt as sn,G as st,Ji as t,Ft as tn,J as tt,_i as u,Jt as un,W as ut,si as v,at as vn,qn as vt,ni as w,pt as wn,Nn as wt,oi as x,ct as xn,Hn as xt,ci as y,_t as yn,Fn as yt,Ir as z,Gt as zt};
1
+ import{C as e,K as t,S as n,Y as r,et as i,i 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-CEyXHAdg.js";import{Gt as s,Q as c,So as l,bo as u,bt as d,or as f,wr as p,xn as m,xo as h,xt as g,yt as _,zt as v}from"./player-overlays-Cs69NgAR.js";import{$ as y,$t as b,At as ee,Ci as te,Dt as ne,Et as re,G as ie,Gt as ae,H as oe,Ht as se,J as ce,Jt as le,K as ue,Kt as de,Lt as x,Mt as fe,Nc as pe,Nt as S,Ot as me,Pt as he,Q as ge,Qt as _e,R as ve,Rt as C,Ti as ye,U as be,Ut as xe,V as Se,Vt as Ce,W as w,X as we,Xt as Te,Y as Ee,Yt as T,Z as E,Zt as De,an as Oe,ca as ke,cn as Ae,ct as je,dn as Me,ds as Ne,en as Pe,fn as Fe,gt as Ie,in as D,jt as O,kt as k,ln as Le,ls as Re,on as ze,pn as Be,q as Ve,sn as He,st as Ue,tn as We,un as Ge,vc as Ke,wi as qe,zt as A}from"./src-BwDSKCnh.js";import{Ka as Je,Tl as Ye,Ui as Xe,Wi as j,fa as Ze,gf as Qe,im as $e,k as et,la as tt,lm as nt,pa as rt,vf as it}from"./src-Bb9LsNcW.js";import{t as M}from"./i18n-kurEJu5K.js";import{t as N}from"./useTranslation-uIxPZ_3N.js";i();function P(e){return t=>Object.prototype.hasOwnProperty.call(e,t)}var at=P({devices:!0}),ot=P({classes:!0,classesExclude:!0,labelEquals:!0,identities:!0,identitiesExclude:!0,eventTypeTokens:!0,sensorKinds:!0}),st=P({minConfidence:!0,minImportance:!0,minLabelConfidence:!0}),ct=P({minDwellSeconds:!0}),lt=P({source:!0}),ut=P({crossing:!0}),dt=P({packagePhase:!0}),ft=P({sensorTransition:!0}),pt=P({plates:!0}),mt=P({occupancy:!0}),ht=P({audio:!0}),gt=P({systemEvent:!0}),_t=P({deviceState:!0}),vt=P({scene:!0});function yt(e,t){let n=e[t];return Array.isArray(n)?n:[]}function bt(e,t){let n=e[t];return typeof n==`number`?n:void 0}var xt=`event-emitter`;function St(e){let t=new Map,n=[],r=!1,i=0;for(let a of e){if(a.status===`pending`){r=!0;continue}if(a.status===`error`){n.push(a.deviceName);continue}if(a.data===null||a.data===void 0)continue;let e=Ne.safeParse(a.data);if(!e.success){n.push(a.deviceName);continue}i+=1;for(let n of Ke(e.data)){let e=t.get(n.id);e===void 0?t.set(n.id,{label:n.label,devices:[a.deviceName]}):e.devices.includes(a.deviceName)||t.set(n.id,{label:e.label,devices:[...e.devices,a.deviceName]})}}let a=i>1;return{options:[...t.entries()].map(([e,t])=>a?{value:e,label:t.label,hint:t.devices.join(`, `)}:{value:e,label:t.label}),pending:r,unknownDevices:n,eventDeviceCount:i}}function Ct(e,t,n){let r=new Set(t.map(e=>e.id)),i=new Map((n??[]).map(e=>[e.id,e.name]));return e.filter(e=>!r.has(e)).map(e=>({deviceId:e,deviceName:i.get(e)??`#${e}`}))}function F(e,n){let r=v().trpcClient,i=a({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 t(()=>{let e=[],t=new Set;for(let r of i){if(!r.data)continue;let i=n.find(e=>e.id===r.data.deviceId)?.name;for(let n of r.data.zones)t.has(n.id)||(t.add(n.id),e.push({value:n.id,label:n.name,...i===void 0?{}:{hint:i}}))}return{options:e,loading:i.some(e=>e.isLoading),failed:i.some(e=>e.isError)}},[i,n])}function wt(e){let n=v().trpcClient,r=a({queries:e.map(e=>({queryKey:[[`nc-pickers`,`event-kinds`],{deviceId:e}],staleTime:6e4,queryFn:async()=>(await n.pipelineAnalytics.listEventKinds.query({deviceId:e})).map(e=>({kind:e.kind,label:e.label}))}))});return t(()=>{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 Tt(e){let n=v().trpcClient,r=a({queries:e.map(({deviceId:e})=>({queryKey:[[`nc-pickers`,`declared-events`],{deviceId:e}],staleTime:3e4,queryFn:async()=>n.deviceState.getCapSlice.query({deviceId:e,capName:xt})}))});return t(()=>St(e.map((e,t)=>({...e,status:r[t]?.status??`pending`,data:r[t]?.data}))),[e,r])}function Et(){let e=Ye();return t(()=>({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 Dt(){let e=Qe({limit:200}),n=it();return t(()=>{let t=new Set;for(let e of n.data??[])e.name.trim().length>0&&t.add(e.name);let r=new Set;for(let t of e.data??[])t.text.trim().length>0&&r.add(t.text);return[...[...t].sort(),...[...r].sort()]},[e.data,n.data])}function I({options:i,value:a,onChange:o,loading:s,emptyHint:c,placeholder:l,noFreeText:u=!1}){let{t:d}=N(),[f,p]=r(``),m=t(()=>new Set(i.map(e=>e.value)),[i]),v=t(()=>new Set(a),[a]),y=a.filter(e=>!m.has(e)),b=e=>{o(v.has(e)?a.filter(t=>t!==e):[...a,e])},ee=()=>{let e=f.trim();e.length===0||a.includes(e)||(o([...a,e]),p(``))};return e(`div`,{className:`mt-1 space-y-1.5`,children:[y.length>0&&n(`div`,{className:`flex flex-wrap gap-1`,children:y.map(t=>e(_,{variant:`unstyled`,type:`button`,onClick:()=>o(a.filter(e=>e!==t)),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:d(`system.notificationRulePickers.customValueClickToRemove`,`Custom value — click to remove`),children:[t,` ×`]},t))}),i.length>0?n(`div`,{className:`max-h-40 overflow-y-auto rounded-md border border-border divide-y divide-border`,children:i.map(t=>e(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[n(h,{checked:v.has(t.value),onChange:()=>b(t.value),className:`accent-primary`}),n(`span`,{className:`flex-1 truncate`,children:t.label}),t.hint!==void 0&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:t.hint})]},t.value))}):n(`p`,{className:`text-[10px] text-foreground-subtle`,children:s===!0?d(`common.loading`,`Loading…`):c}),!u&&n(g,{value:f,onChange:e=>p(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 L=[{value:`immediate`,get label(){return M.t(`helpers.ruleFormParsers.immediate`)},get hint(){return M.t(`helpers.ruleFormParsers.immediateHint`)}},{value:`track-end`,get label(){return M.t(`helpers.ruleFormParsers.trackEnd`)},get hint(){return M.t(`helpers.ruleFormParsers.trackEndHint`)}},{value:`device-event`,get label(){return M.t(`helpers.ruleFormParsers.deviceEvent`)},get hint(){return M.t(`helpers.ruleFormParsers.deviceEventHint`)}},{value:`package-event`,get label(){return M.t(`helpers.ruleFormParsers.packageEvent`)},get hint(){return M.t(`helpers.ruleFormParsers.packageEventHint`)}},{value:`system-event`,get label(){return M.t(`helpers.ruleFormParsers.systemEvent`)},get hint(){return M.t(`helpers.ruleFormParsers.systemEventHint`)}}],Ot=`Immediate, grouped`,kt=L.flatMap(e=>e.value===`immediate`?[e,{value:`immediate-grouped`,get label(){return M.t(`notificationRules.grouping.choice`)},get hint(){return M.t(`helpers.ruleFormParsers.groupedHint`)}}]:[e]);function At(e){return e.groupingSec!==void 0&&x(e)?`immediate-grouped`:e.delivery}function jt(e){let t=(e.delivery===`immediate`||e.delivery===`track-end`)&&x({delivery:`immediate`,conditions:e.conditions});return kt.filter(e=>e.value!==`immediate-grouped`||t)}function Mt(e){return kt.find(t=>t.value===e)?.value}function Nt(e,t=Ot){return At(e)===`immediate-grouped`?`${t} · ${String(e.groupingSec)} s`:Pt(e.delivery)}function Pt(e){return L.find(t=>t.value===e)?.label??e}function Ft(e){return L.some(t=>t.value===e)}var It=[{key:`all`,get label(){return M.t(`helpers.ruleFormParsers.sec_all_label`)},get blurb(){return M.t(`helpers.ruleFormParsers.sec_all_blurb`)},get newRuleLabel(){return M.t(`helpers.ruleFormParsers.sec_all_new`)},get emptyHint(){return M.t(`helpers.ruleFormParsers.sec_all_empty`)},creatable:!0},{key:`detection`,get label(){return M.t(`helpers.ruleFormParsers.sec_detection_label`)},get blurb(){return M.t(`helpers.ruleFormParsers.sec_detection_blurb`)},get newRuleLabel(){return M.t(`helpers.ruleFormParsers.sec_detection_new`)},get emptyHint(){return M.t(`helpers.ruleFormParsers.sec_detection_empty`)},creatable:!0},{key:`sensor`,get label(){return M.t(`helpers.ruleFormParsers.sec_sensor_label`)},get blurb(){return M.t(`helpers.ruleFormParsers.sec_sensor_blurb`)},get newRuleLabel(){return M.t(`helpers.ruleFormParsers.sec_sensor_new`)},get emptyHint(){return M.t(`helpers.ruleFormParsers.sec_sensor_empty`)},creatable:!0},{key:`audio`,get label(){return M.t(`helpers.ruleFormParsers.sec_audio_label`)},get blurb(){return M.t(`helpers.ruleFormParsers.sec_audio_blurb`)},get newRuleLabel(){return M.t(`helpers.ruleFormParsers.sec_audio_new`)},get emptyHint(){return M.t(`helpers.ruleFormParsers.sec_audio_empty`)},creatable:!0},{key:`occupancy`,get label(){return M.t(`helpers.ruleFormParsers.sec_occupancy_label`)},get blurb(){return M.t(`helpers.ruleFormParsers.sec_occupancy_blurb`)},get newRuleLabel(){return M.t(`helpers.ruleFormParsers.sec_occupancy_new`)},get emptyHint(){return M.t(`helpers.ruleFormParsers.sec_occupancy_empty`)},creatable:!0},{key:`device-events`,get label(){return M.t(`helpers.ruleFormParsers.sec_deviceEvents_label`)},get blurb(){return M.t(`helpers.ruleFormParsers.sec_deviceEvents_blurb`)},get newRuleLabel(){return M.t(`helpers.ruleFormParsers.sec_deviceEvents_new`)},get emptyHint(){return M.t(`helpers.ruleFormParsers.sec_deviceEvents_empty`)},creatable:!0},{key:`system`,get label(){return M.t(`helpers.ruleFormParsers.sec_system_label`)},get blurb(){return M.t(`helpers.ruleFormParsers.sec_system_blurb`)},get newRuleLabel(){return M.t(`helpers.ruleFormParsers.sec_system_new`)},get emptyHint(){return M.t(`helpers.ruleFormParsers.sec_system_empty`)},creatable:!0},{key:`alarm`,get label(){return M.t(`helpers.ruleFormParsers.sec_alarm_label`)},get blurb(){return M.t(`helpers.ruleFormParsers.sec_alarm_blurb`)},get newRuleLabel(){return M.t(`helpers.ruleFormParsers.sec_alarm_new`)},get emptyHint(){return M.t(`helpers.ruleFormParsers.sec_alarm_empty`)},creatable:!0},{key:`mixed`,get label(){return M.t(`helpers.ruleFormParsers.sec_mixed_label`)},get blurb(){return M.t(`helpers.ruleFormParsers.sec_mixed_blurb`)},get newRuleLabel(){return M.t(`helpers.ruleFormParsers.sec_mixed_new`)},get emptyHint(){return M.t(`helpers.ruleFormParsers.sec_mixed_empty`)},creatable:!1}];function Lt(e){return A(C(e)).editable}function Rt(e){return he(zt(e))}function zt(e){switch(e){case`device-events`:case`system`:case`alarm`:case`mixed`:return e;default:return}}var Bt=new Map([[0,`helpers.ruleFormParsers.cdNone`],[60,`helpers.ruleFormParsers.cd1m`],[3600,`helpers.ruleFormParsers.cd1h`]]),Vt=86400;function Ht(e){let t=Bt.get(e);return t===void 0?e%3600==0?M.t(`helpers.ruleFormParsers.cdHours`,{count:e/3600}):e%60==0?M.t(`helpers.ruleFormParsers.cdMinutes`,{count:e/60}):M.t(`helpers.ruleFormParsers.cdSeconds`,{count:e}):M.t(t)}var Ut=[{value:`rule-device`,get label(){return M.t(`helpers.ruleFormParsers.scopeDevice`)}},{value:`rule`,get label(){return M.t(`helpers.ruleFormParsers.scopeRule`)}}];function Wt(e){return Ut.find(t=>t.value===e)?.value}var Gt=[{value:`per-class`,get label(){return M.t(`helpers.ruleFormParsers.granPerClass`)}},{value:`shared`,get label(){return M.t(`helpers.ruleFormParsers.granShared`)}}];function Kt(e){return Gt.find(t=>t.value===e)?.value}var qt=[{value:`scene-boxes`,get label(){return M.t(`helpers.ruleFormParsers.imageSceneBoxes`)},get description(){return M.t(`helpers.ruleFormParsers.imageSceneBoxesDesc`)}},{value:`crop`,get label(){return M.t(`helpers.ruleFormParsers.imageCrop`)},get description(){return M.t(`helpers.ruleFormParsers.imageCropDesc`)}},{value:`clean`,get label(){return M.t(`helpers.ruleFormParsers.imageClean`)},get description(){return M.t(`helpers.ruleFormParsers.imageCleanDesc`)}},{value:`none`,get label(){return M.t(`helpers.ruleFormParsers.imageNone`)},get description(){return M.t(`helpers.ruleFormParsers.imageNoneDesc`)}}];function Jt(e){return qt.find(t=>t.value===e)?.value}var Yt=[{value:``,get label(){return M.t(`helpers.ruleFormParsers.linkedDefault`)}},{value:`mosaic`,get label(){return M.t(`helpers.ruleFormParsers.linkedMosaic`)}},{value:`each`,get label(){return M.t(`helpers.ruleFormParsers.linkedEach`)}}];function Xt(e){let t=Yt.find(t=>t.value===e)?.value;return t===``?void 0:t}var Zt=[{value:``,get label(){return M.t(`helpers.ruleFormParsers.profileLowest`)}},{value:`low`,get label(){return M.t(`helpers.ruleFormParsers.profileLow`)}},{value:`mid`,get label(){return M.t(`helpers.ruleFormParsers.profileMid`)}},{value:`high`,get label(){return M.t(`helpers.ruleFormParsers.profileHigh`)}}];function Qt(e){let t=Zt.find(t=>t.value===e)?.value;return t===``?void 0:t}var $t=[{value:`any`,get label(){return M.t(`helpers.ruleFormParsers.srcAny`)}},{value:`pipeline`,get label(){return M.t(`helpers.ruleFormParsers.srcPipeline`)}},{value:`onboard`,get label(){return M.t(`helpers.ruleFormParsers.srcOnboard`)}},{value:`sensor`,get label(){return M.t(`helpers.ruleFormParsers.srcSensor`)}}],en=[{value:`delivered`,get label(){return M.t(`helpers.ruleFormParsers.phaseDelivered`)}},{value:`picked-up`,get label(){return M.t(`helpers.ruleFormParsers.phasePickedUp`)}},{value:`both`,get label(){return M.t(`helpers.ruleFormParsers.phaseBoth`)}}],tn=[{value:``,get label(){return M.t(`helpers.ruleFormParsers.stBoth`)}},{value:`raised`,get label(){return M.t(`helpers.ruleFormParsers.stRaised`)}},{value:`cleared`,get label(){return M.t(`helpers.ruleFormParsers.stCleared`)}}];function nn(e){return e===`raised`||e===`cleared`?e:void 0}function R(e,t){return e===`sensorTransition`?je(t.sensorKinds):!0}var rn=[{value:`enter`,get label(){return M.t(`helpers.ruleFormParsers.crossEnter`)}},{value:`exit`,get label(){return M.t(`helpers.ruleFormParsers.crossExit`)}},{value:`any`,get label(){return M.t(`helpers.ruleFormParsers.crossAny`)}}],an=`enter`;function on(e){return e===`exit`||e===`any`?e:void 0}var sn=[{value:1,get label(){return M.t(`helpers.ruleFormParsers.prioMin`)}},{value:2,get label(){return M.t(`helpers.ruleFormParsers.prioLow`)}},{value:3,get label(){return M.t(`helpers.ruleFormParsers.prioDefault`)}},{value:4,get label(){return M.t(`helpers.ruleFormParsers.prioHigh`)}},{value:5,get label(){return M.t(`helpers.ruleFormParsers.prioMax`)}}];function cn(e,t){return e.options&&e.options.length>0?e.options:t}var ln=[{value:``,get label(){return M.t(`helpers.ruleFormParsers.speedDefault`)}},{value:`1`,get label(){return M.t(`helpers.ruleFormParsers.speedReal`)}},{value:`2`,label:`2×`},{value:`3`,label:`3×`},{value:`4`,label:`4×`},{value:`6`,label:`6×`},{value:`8`,label:`8×`}];function un(e){if(e===``)return;let t=Number(e);return Number.isFinite(t)&&t>=1&&t<=8?t:void 0}var z={days:[0,1,2,3,4,5,6],minute:480},dn=[{value:1,get label(){return M.t(`helpers.notificationSystemEventDelivery.wd_mon`)}},{value:2,get label(){return M.t(`helpers.notificationSystemEventDelivery.wd_tue`)}},{value:3,get label(){return M.t(`helpers.notificationSystemEventDelivery.wd_wed`)}},{value:4,get label(){return M.t(`helpers.notificationSystemEventDelivery.wd_thu`)}},{value:5,get label(){return M.t(`helpers.notificationSystemEventDelivery.wd_fri`)}},{value:6,get label(){return M.t(`helpers.notificationSystemEventDelivery.wd_sat`)}},{value:0,get label(){return M.t(`helpers.notificationSystemEventDelivery.wd_sun`)}}];function fn(e){let t=Math.floor(e/60),n=e%60;return`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}`}function pn(e){let[t,n]=e.split(`:`),r=Number(t)*60+Number(n);return Number.isFinite(r)?Math.max(0,Math.min(1439,r)):0}var mn={mode:`modes`,onActivation:!0,onDeactivation:!1};function hn(e){return e!==void 0&&Se.includes(e)}function gn(e,t){return ge({conditions:t.length>0?{systemEvent:{kinds:[...t]}}:{},...e===void 0?{}:{systemEventDelivery:e}})}function _n(e){return{mode:`modes`,onActivation:e.onActivation,onDeactivation:e.onDeactivation}}function vn(e,t,n){return t===`activation`?{...e,onActivation:n}:t===`deactivation`?{...e,onDeactivation:n}:n?e.onSchedule===void 0?{...e,onSchedule:{schedule:w([z]),grouping:`section`}}:e:_n(e)}function yn(e,t){return{...e,onSchedule:{schedule:t,grouping:e.onSchedule?.grouping??`section`}}}function bn(e,t){return e.onSchedule===void 0?e:{...e,onSchedule:{...e.onSchedule,grouping:t}}}function xn(e){let t=new Set,n=0;for(let r of e){let e=E(r);e===void 0?n+=1:t.add(e.label)}return{adds:[...t],without:n}}function Sn(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 Cn(e){let t=Object.entries(e).map(([e,t])=>`${e} ${String(t)}`);return t.length>0?M.t(`helpers.notificationSystemEventDelivery.dropped`,{parts:t.join(`, `)}):null}function wn(e,t,n,r=`rule`){if(e===`error`)return Sn(n)===`NOT_FOUND`?{lines:[`This hub does not serve summary rules yet — update @dominevo/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 @dominevo/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=Cn(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}}var Tn=`notificationRules.systemEventKinds.`,En=`notificationRules.systemEventGroups.`,Dn=`notificationRules.systemEventHints.`;function On(e){return!ye.some(t=>t===e)}function B(e){let t=`${Tn}${e}`;return M.exists(t)?M.t(t):e}function kn(){return de.map(e=>({id:e.id,family:e.family,label:M.t(`${En}${e.id}`,e.label),hint:M.t(`${Dn}${e.id}`),kinds:e.kinds.filter(On).map(e=>({value:e,label:B(e)}))}))}function V(e){return kn().filter(t=>t.family===e)}function An(e){let t=Ce(e).conditions.systemEvent;return t===void 0?{kinds:(V(e)[0]?.kinds??[]).map(e=>e.value)}:{...t,kinds:[...t.kinds]}}function jn(){return kn().flatMap(e=>e.kinds)}function Mn(e){return{devices:T(e,`deviceIds`),deviceTypes:T(e,`deviceTypes`),nodes:T(e,`nodeIds`),packages:T(e,`packageNames`),consumableThreshold:T(e,`consumableLowPercent`),commandActions:T(e,`commandActions`),commandOutcomes:T(e,`commandOutcomes`),commandActorKinds:T(e,`commandActorKinds`),faultCodes:T(e,`faultCodes`),faultSeverities:T(e,`faultSeverities`)}}function Nn(e,t){let n=ae[e],r=Mn(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,commandActions:n.includes(`commandActions`)&&r.commandActions,commandOutcomes:n.includes(`commandOutcomes`)&&r.commandOutcomes,commandActorKinds:n.includes(`commandActorKinds`)&&r.commandActorKinds,faultCodes:n.includes(`faultCodes`)&&r.faultCodes,faultSeverities:n.includes(`faultSeverities`)&&r.faultSeverities}}var Pn=ke.options;function Fn(e){return Pn.filter(t=>e.includes(t))}var In=Object.values(pe).map(e=>({value:e,label:Ln(e)})).toSorted((e,t)=>e.label.localeCompare(t.label));function Ln(e){let t=e.replaceAll(`-`,` `);return t.charAt(0).toUpperCase()+t.slice(1)}function Rn(e,t){let n=[],r=new Set;for(let i of e.kinds){let e=E(i.value);if(e===void 0){n.push({key:i.value,label:i.label,kinds:[i.value],clears:[i.value]});continue}r.has(e.id)||(r.add(e.id),n.push({key:`class:${e.id}`,label:t?e.snapshotLabel:e.label,kinds:t?[...e.bad]:we(e),clears:we(e),classId:e.id,...t&&e.snapshotSection===null?{noSnapshot:!0}:{}}))}return n}function zn(e,t){return t.clears.some(t=>e.includes(t))}function Bn(e,t,n){if(!V(n).some(e=>e.kinds.some(e=>t.kinds.includes(e.value))))return e;let r=e?.kinds??[];if(zn(r,t)){let i=r.filter(e=>!t.clears.includes(e));return i.length===0?e:U(e,i,n)}return U(e,jn().filter(e=>t.kinds.includes(e.value)||r.includes(e.value)).map(e=>e.value),n)}function Vn(e,t){return t===void 0?void 0:U(t,t.kinds,e)}function Hn(e,t){let n=e?.kinds??[];if(n.length===0)return;let r=H(t,`deviceIds`,e?.deviceIds),i=H(t,`excludeDeviceIds`,e?.excludeDeviceIds),a=H(t,`deviceTypes`,e?.deviceTypes),o=H(t,`nodeIds`,e?.nodeIds),s=H(t,`packageNames`,e?.packageNames),c=H(t,`faultCodes`,e?.faultCodes),l=H(t,`faultSeverities`,e?.faultSeverities),u=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?{}:{faultCodes:[...c]},...l===void 0?{}:{faultSeverities:[...l]},...u===void 0?{}:{consumableLowPercent:u}}}function H(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 U(e,t,n){let r=Nn(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.faultCodes?e?.faultCodes:void 0,u=r.faultSeverities?e?.faultSeverities:void 0,d=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&&l.length>0?{faultCodes:[...l]}:{},...u&&u.length>0?{faultSeverities:[...u]}:{},...d===void 0?{}:{consumableLowPercent:d}}}var Un=95;function Wn(e){let t=e.trim();if(t===``)return{kind:`clear`};let n=Number(t);return Number.isInteger(n)&&n>=1&&n<=Un?{kind:`set`,value:n}:{kind:`invalid`}}function Gn(e,t=2){if(e===void 0||e.length===0)return M.t(`helpers.notificationSystemEvents.noneSelected`);let n=e.slice(0,t).map(B).join(`, `),r=e.length-Math.min(t,e.length);return r>0?`${n} +${r}`:n}function Kn(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(Ln).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 qn(e){return e===void 0||(e.deviceTypes?.length??0)===0?!1:e.kinds.some(e=>te.includes(e))}var Jn=[`all`,`only`,`except`];function Yn(e,t){return(e??[]).length>0?`only`:(t??[]).length>0?`except`:`all`}function W(e,t){let n=[...e??[]],r=[...t??[]];return{mode:Yn(n,r),include:n,exclude:r,legacyBoth:n.length>0&&r.length>0}}function Xn(e,t){return{...e,mode:t}}function Zn(e){switch(e.mode){case`only`:return e.include;case`except`:return e.exclude;case`all`:return[]}}function Qn(e,t){switch(e.mode){case`only`:return{...e,include:[...t]};case`except`:return{...e,exclude:[...t]};case`all`:return e}}function $n(e){return e.mode===`only`&&e.legacyBoth?e.exclude:[]}function er(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=$n(e);return{...e.include.length>0?{include:[...e.include]}:{},...t.length>0?{exclude:[...t]}:{}}}}}function tr(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:{get title(){return M.t(`helpers.notificationRuleActions.onActivationTitle`)},get hint(){return M.t(`helpers.notificationRuleActions.onActivationHint`)}},onDeactivation:{get title(){return M.t(`helpers.notificationRuleActions.onDeactivationTitle`)},get hint(){return M.t(`helpers.notificationRuleActions.onDeactivationHint`)}},onTrigger:{get title(){return M.t(`helpers.notificationRuleActions.onTriggerTitle`)},get hint(){return M.t(`helpers.notificationRuleActions.onTriggerHint`)}},onTriggerOff:{get title(){return M.t(`helpers.notificationRuleActions.onTriggerOffTitle`)},get hint(){return M.t(`helpers.notificationRuleActions.onTriggerOffHint`)}}},nr={onActivation:[],onDeactivation:[],onTrigger:[],onTriggerOff:[],buttons:[]};function rr(e){return e===void 0?nr:{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.actionId.trim()!==``),n=e=>e.filter(e=>e.trim()!==``),r={onActivation:n(e.onActivation),onDeactivation:n(e.onDeactivation),onTrigger:n(e.onTrigger),onTriggerOff:n(e.onTriggerOff)};if(!(!K.some(e=>r[e].length>0)&&t.length===0))return{...r.onActivation.length>0?{onActivation:[...r.onActivation]}:{},...r.onDeactivation.length>0?{onDeactivation:[...r.onDeactivation]}:{},...r.onTrigger.length>0?{onTrigger:[...r.onTrigger]}:{},...r.onTriggerOff.length>0?{onTriggerOff:[...r.onTriggerOff]}:{},...t.length>0?{buttons:t}:{}}}function ir(e,t){let n=[];for(let r of K){let i=e[r];i.length>4&&n.push({kind:`too-many`,message:M.t(`helpers.notificationRuleActions.tooMany`,{title:q[r].title})}),i.some(e=>e.trim()!==``&&!t.has(e))&&n.push({kind:`unknown-action`,message:M.t(`helpers.notificationRuleActions.hookUnknownAction`,{title:q[r].title})})}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:M.t(`helpers.notificationRuleActions.dupButton`,{id:e})}),r.add(e),t.has(i.actionId.trim())||n.push({kind:`unknown-action`,message:M.t(`helpers.notificationRuleActions.buttonUnknownAction`,{label:i.label||e})}))}return n}function ar(e,t){let{confirm:n,...r}=e;return t?{...r,confirm:!0}:r}function or(e,t){return{id:`action-${String(e+1)}`,label:M.t(`helpers.notificationRuleActions.newButtonLabel`),actionId:t}}var sr=[{value:`acknowledge`,get label(){return M.t(`helpers.notificationRuleActions.icon_acknowledge`)}},{value:`dismiss`,get label(){return M.t(`helpers.notificationRuleActions.icon_dismiss`)}},{value:`silence`,get label(){return M.t(`helpers.notificationRuleActions.icon_silence`)}},{value:`snooze`,get label(){return M.t(`helpers.notificationRuleActions.icon_snooze`)}},{value:`view`,get label(){return M.t(`helpers.notificationRuleActions.icon_view`)}},{value:`play`,get label(){return M.t(`helpers.notificationRuleActions.icon_play`)}},{value:`camera`,get label(){return M.t(`helpers.notificationRuleActions.icon_camera`)}},{value:`open`,get label(){return M.t(`helpers.notificationRuleActions.icon_open`)}},{value:`close`,get label(){return M.t(`helpers.notificationRuleActions.icon_close`)}},{value:`unlock`,get label(){return M.t(`helpers.notificationRuleActions.icon_unlock`)}},{value:`lock`,get label(){return M.t(`helpers.notificationRuleActions.icon_lock`)}},{value:`disarm`,get label(){return M.t(`helpers.notificationRuleActions.icon_disarm`)}},{value:`arm`,get label(){return M.t(`helpers.notificationRuleActions.icon_arm`)}},{value:`arm-home`,get label(){return M.t(`helpers.notificationRuleActions.icon_arm_home`)}},{value:`arm-away`,get label(){return M.t(`helpers.notificationRuleActions.icon_arm_away`)}},{value:`arm-night`,get label(){return M.t(`helpers.notificationRuleActions.icon_arm_night`)}},{value:`light`,get label(){return M.t(`helpers.notificationRuleActions.icon_light`)}},{value:`alert`,get label(){return M.t(`helpers.notificationRuleActions.icon_alert`)}}];function cr(e){let t=new Set;for(let n of K)for(let r of e[n])r.trim()!==``&&t.add(r);for(let n of e.buttons)n.actionId.trim()!==``&&t.add(n.actionId);return t}function lr(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[];for(let t of cr(e))r.push(...n.get(t)?.steps??[]);return r}var ur=[10,30,60],dr=[5,10,15,30,60,120,240,480];function fr(e){return e>=60&&e%60==0?M.t(`helpers.ruleFormState.snoozeHours`,{count:e/60}):M.t(`helpers.ruleFormState.snoozeMin`,{count:e})}var pr=new Set([`alarm-arm-refused`,`alarm-check-failed`,`alarm-arming`,`alarm-armed`,`alarm-pending`,`alarm-triggered`,`alarm-rearmed`,`alarm-sensor-bypass`,`alarm-disarmed`]);function mr(e,t){for(let t of e.systemEvent?.kinds??[])if(pr.has(t))return!0;for(let e of Re(t))if(Ie(e))return!0;return!1}function hr(e,t){return lr(e,t)}function gr(e){let{devices:t,devicesExclude:n,classes:r,classesExclude:i,...a}=e;return{conditions:a,deviceScope:W(t,n),classScope:W(r,i)}}function _r(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 vr(e){return e.deviceScope.mode===`only`?e.deviceScope.include:[]}function yr(e,t,n){let r=C(n);return e.some(e=>e.id===t&&O(e,n.delivery,r))}function br(e=`immediate`,t={}){return{name:``,tags:[],enabled:!0,delivery:e,targetIds:[],targetUsers:[],targetParams:{},targetOverrides:{},priority:3,mediaImage:re({},C({delivery:e,conditions:t})),mediaShowTriggerZone:!1,mediaShowSubjectPath:!1,mediaGif:!1,mediaClip:!1,mediaProfile:void 0,mediaClipSpeed:void 0,mediaLinkedCameras:void 0,mediaWakeSleepingCamera:void 0,templateTitle:``,templateBody:``,...gr(t),schedule:void 0,systemEventDelivery:e===`system-event`?mn:void 0,snoozeAllowGlobal:!1,groupingSec:void 0,groupWithinSec:k({delivery:e}),snoozeOptions:void 0,askVerdict:void 0,offerAlertAction:void 0,actions:nr,cooldownSec:30,cooldownScope:`rule-device`,cooldownGranularity:void 0}}function xr(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,tags:e.tags??[],enabled:e.enabled,delivery:e.delivery,targetIds:e.targets.map(e=>e.targetId),targetUsers:e.targetUsers??[],targetParams:t,targetOverrides:e.targetOverrides??{},priority:e.priority,mediaImage:re(e.media,C(e)),mediaShowTriggerZone:e.media.showTriggerZone===!0,mediaShowSubjectPath:e.media.showSubjectPath===!0,mediaGif:e.media.gif===!0,mediaClip:e.media.clip===!0,mediaProfile:e.media.profile,mediaClipSpeed:e.media.clipSpeed,mediaLinkedCameras:e.media.linkedCameras,mediaWakeSleepingCamera:e.media.wakeSleepingCamera,templateTitle:e.template?.title??``,templateBody:e.template?.body??``,...gr(e.conditions),schedule:e.schedule,systemEventDelivery:e.systemEventDelivery,snoozeAllowGlobal:e.snoozeAllowGlobal===!0,groupingSec:e.groupingSec,groupWithinSec:k(e),snoozeOptions:e.snoozeOptions,askVerdict:e.askVerdict,offerAlertAction:e.offerAlertAction,actions:rr(e.actions),cooldownSec:e.throttle.cooldownSec,cooldownScope:e.throttle.scope,cooldownGranularity:e.throttle.granularity}}function Sr(e,t){let n=[],r=e.groupWithinSec;if((!Number.isInteger(r)||r<0||r>300)&&n.push(`Group notifications within is a whole number of seconds between 0 and 300.`),Mr(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&&!Nr(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(He(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(Vt)} (24 hours). 0 means every match is delivered.`),S(e.delivery))for(let t of Ve({delivery:e.delivery,conditions:e.conditions,...e.systemEventDelivery===void 0?{}:{systemEventDelivery:e.systemEventDelivery},...J(e.actions)===void 0?{}:{actions:J(e.actions)}}))n.push(oe(t));return n}function Cr(e){let t=e.systemEventDelivery;if(t===void 0)return{};if(!S(e.delivery))return t.mode===`instant`?{}:{systemEventDelivery:{mode:`instant`}};let n=le(e.conditions.systemEvent?.kinds??[]);if(!(n.kind===`family`&&Se.includes(n.family)))return t.mode===`modes`?{}:{systemEventDelivery:t};let r=y({systemEventDelivery:t}).schedule;if(r!==null&&ue(r.schedule)===null){let e=ie(r.schedule);if(e!==null&&e.times.length>0){let n=w(e.times,r.schedule.timezone);if(t.mode===`modes`)return{systemEventDelivery:{...t,onSchedule:{...r,schedule:n}}};if(t.mode===`summary`)return{systemEventDelivery:{...t,schedule:n}}}}return{systemEventDelivery:t}}function wr(e){if(!Y(e))return null;if(!Ee(e.templateBody))return M.t(`helpers.ruleFormState.summaryWarnNone`,{token:`{{summaryText}}`});let t=e.templateBody;return ce({...e.systemEventDelivery===void 0?{}:{systemEventDelivery:e.systemEventDelivery}})===`section`&&t.trim().length>0&&!/\{\{\s*summaryText\s*\}\}/.test(t)?M.t(`helpers.ruleFormState.summaryWarnSplit`,{token:`{{summaryText}}`}):null}function Y(e){return be({delivery:e.delivery,...e.systemEventDelivery===void 0?{}:{systemEventDelivery:e.systemEventDelivery}})}function Tr(e,t,n=new Set){return Sr(e,t).length===0&&Ft(e.delivery)&&(!S(e.delivery)||Lr(e)>0)&&C(e)!==`mixed`&&e.name.trim().length>0&&(e.targetIds.length>0||e.targetUsers.length>0)&&ir(e.actions,n).length===0}function Er(e,t){let n=Fr(e.conditions,t),r=S(t)&&(n.systemEvent?.kinds.length??0)===0,i=S(t)&&e.systemEventDelivery===void 0?mn:e.systemEventDelivery;return r?{...e,delivery:t,systemEventDelivery:i,conditions:{...n,systemEvent:An(`device-events`)}}:{...e,delivery:t,conditions:n,systemEventDelivery:i}}function Dr(e,t){return t===`immediate-grouped`?Or(e,{...Er(e,`immediate`),groupingSec:e.groupingSec??20}):Or(e,{...Er(e,t),groupingSec:void 0})}function Or(e,t){let n=k({delivery:e.delivery}),r=k({delivery:t.delivery}),i=e.groupWithinSec!==n;return{...t,groupWithinSec:i?e.groupWithinSec:r}}function kr(e){return e.delivery===`immediate`||e.delivery===`track-end`}var Ar=new Set([`alert-critical`,`alert-error`,`device-attention-required`]);function jr(e){return(e.conditions.systemEvent?.kinds??[]).some(e=>Ar.has(e))}function Mr(e){return e.groupingSec!==void 0&&x(e)}function Nr(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 Pr=new Set([`immediate`,`track-end`,`package-event`]);function Fr(e,t){if(e.source!==`pipeline`||Pr.has(t))return e;let{source:n,...r}=e;return r}function Ir(e,t){return xe(e.conditions.systemEvent)===t?e:{...e,conditions:{...e.conditions,systemEvent:An(t)}}}function Lr(e){return e.conditions.systemEvent?.kinds.length??0}function Rr(e,t){return n=>{let r=e.find(e=>e.id===n);if(r===void 0)return;let i=t.find(e=>e.kind===r.kind&&e.addonId===r.addonId)?.caps;return i===void 0?void 0:De(i)}}function zr(e,t,n){let r=Rr(t,n),i=_e(e.map(e=>({name:t.find(t=>t.id===e)?.name??e,fields:r(e)})));return new Map(i.map(e=>[e.field,e]))}function Br(e,t,n){let r={};for(let i of e){let e=t[i];if(e===void 0)continue;let a=Pe(e,n?.(i));a!==void 0&&(r[i]=a)}return r}function Vr(e,t,n){let{[t]:r,...i}=e;return n===void 0?i:{...i,[t]:n}}function Hr(e,t,n,r){let{[t]:i,...a}=e,{[n]:o,...s}=i??{},c=r===void 0?s:{...s,[n]:r};return Object.keys(c).length===0?a:{...a,[t]:c}}function Ur(e,t,n){let r=t.find(t=>t.id===e);if(r===void 0)return;let i=n.find(e=>e.kind===r.kind&&e.addonId===r.addonId)?.caps;if(i!==void 0)return{levels:b(i),attachmentKinds:Te(i)}}var Wr={rule:{fields:[`title`,`body`,`priority`,`attachments`,`actions`],attachmentKinds:[`none`,`image`,`clip`,`gif`]},summary:{fields:[`title`,`body`,`priority`,`attachments`],attachmentKinds:[`none`,`image`]},timelapse:{fields:[`title`,`body`,`priority`,`attachments`],attachmentKinds:[`none`,`image`,`clip`]},"calendar-events":{fields:[`title`,`body`,`priority`],attachmentKinds:[]}};function Gr(e,t){return Wr[e].fields.includes(t)}function Kr(e,t){let n=Wr[e].attachmentKinds;return t.filter(e=>n.includes(e))}function qr(e){return e.map(e=>({id:e.id,name:e.name,enabled:e.enabled,kind:e.kind??``,addonId:e.addonId??``,config:{}}))}function X(e,t){return e.appliesTo.includes(t)}var Jr={source:`any`};function Yr(e,t){if(t==null)return!0;if(Array.isArray(t))return t.length===0;if(typeof t==`string`)return t.length===0||Jr[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 Xr=qe.filter(e=>e.id===`audio`);function Zr(e){if(e.length===0)return e;let t=new Set(e.map(e=>e.id)),n=Xr.filter(e=>!t.has(e.id));return n.length===0?e:[...e,...n]}function Qr(e,t,n,r=C({delivery:t,conditions:e})){let i=n.length===0?null:new Set(n.filter(e=>e.id!==`schedule`&&O(e,t,r)).map(e=>e.id)),a={};for(let[t,n]of Object.entries(e))i!==null&&!i.has(t)||R(t,e)&&(Yr(t,n)||(a[t]=n));return a}function $r(e,t){if(e===void 0)return{};let n=Vn(e,t.systemEvent);return n===void 0?{}:{systemEvent:n}}function ei(e){return e!==void 0&&e.windows.length>0}function ti(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 ni(e){let t=ti(e.media);return{...e.confirm===void 0?{}:{confirm:e.confirm},...t===void 0?{}:{media:t}}}function ri(e,t,n=[],r){let i=e.templateTitle.trim(),a=e.templateBody.trim(),o=i.length>0||a.length>0?{...i.length>0?{title:i}:{},...a.length>0?{body:a}:{}}:void 0,s=J(e.actions),c=C(e),l=A(c),u=se(c),d=n.length===0?!0:n.some(t=>t.id===`schedule`&&X(t,e.delivery)),f=!Y(e)&&d&&ei(e.schedule)?e.schedule:void 0,p=n.length===0?!0:n.some(t=>t.id===`devices`&&X(t,e.delivery)),m=n.length===0?!0:n.some(t=>t.id===`devicesExclude`&&X(t,e.delivery)),{devices:h,devicesExclude:g,..._}=_r(e),v=Qr(_,e.delivery,n,c);return{name:e.name.trim(),tags:[...e.tags],enabled:e.enabled,delivery:e.delivery,conditions:{...v,...p&&h!==void 0?{devices:h}:{},...m&&g!==void 0?{devicesExclude:g}:{},...$r(u,e.conditions)},...f?{schedule:f}:{},...Cr(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]}:{},targetOverrides:Br(e.targetIds,e.targetOverrides,r),media:l.carriesMedia?{image:e.mediaImage,...e.mediaShowTriggerZone&&e.mediaImage!==`crop`&&e.mediaImage!==`none`&&ne(v).length>0?{showTriggerZone:!0}:{},...e.mediaShowSubjectPath&&e.mediaImage!==`none`&&me(c)?{showSubjectPath:!0}:{},...e.mediaGif?{gif:!0}:{},...e.mediaClip?{clip:!0}:{},...e.mediaProfile===void 0?{}:{profile:e.mediaProfile},...e.mediaClipSpeed===void 0?{}:{clipSpeed:e.mediaClipSpeed},...c===`sensor`&&e.mediaImage!==`none`&&e.mediaLinkedCameras!==void 0?{linkedCameras:e.mediaLinkedCameras}:{},...c===`sensor`&&e.mediaImage!==`none`&&e.mediaWakeSleepingCamera===!1?{wakeSleepingCamera:!1}:{},...(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}:{}}:{image:`none`},throttle:{cooldownSec:e.cooldownSec,scope:e.cooldownScope,...e.cooldownGranularity===void 0?{}:{granularity:e.cooldownGranularity}},priority:e.priority,...o?{template:o}:{},...e.snoozeAllowGlobal?{snoozeAllowGlobal:!0}:{},...Mr(e)?{groupingSec:e.groupingSec}:{},groupWithinSec:e.groupWithinSec,...e.snoozeOptions===void 0?{}:{snoozeOptions:[...e.snoozeOptions]},...e.askVerdict!==void 0&&kr(e)?{askVerdict:e.askVerdict}:{},...e.offerAlertAction!==void 0&&jr(e)?{offerAlertAction:e.offerAlertAction}:{},...t?.confirm===void 0?{}:{confirm:t.confirm},...s===void 0?{}:{actions:s}}}function ii(e,t){let n=ri(e,void 0,t);return[`template`,`schedule`,`targetUsers`,`snoozeOptions`,`snoozeAllowGlobal`,`groupingSec`,`actions`].filter(e=>n[e]===void 0)}var ai=[{key:`rule`,get label(){return M.t(`helpers.ruleFormTabs.tab_rule`)},fields:[`name`,`tags`,`enabled`,`delivery`,`groupingSec`,`groupWithinSec`,`targetIds`,`targetUsers`,`targetParams`,`targetOverrides`]},{key:`devices`,get label(){return M.t(`helpers.ruleFormTabs.tab_devices`)},fields:[`deviceScope`]},{key:`conditions`,get label(){return M.t(`helpers.ruleFormTabs.tab_conditions`)},fields:[`conditions`,`classScope`,`schedule`]},{key:`notification`,get label(){return M.t(`helpers.ruleFormTabs.tab_notification`)},fields:[`priority`,`mediaImage`,`mediaShowTriggerZone`,`mediaShowSubjectPath`,`mediaGif`,`mediaClip`,`mediaProfile`,`mediaClipSpeed`,`mediaLinkedCameras`,`mediaWakeSleepingCamera`,`templateTitle`,`templateBody`,`systemEventDelivery`]},{key:`actions`,get label(){return M.t(`helpers.ruleFormTabs.tab_actions`)},fields:[`actions`]},{key:`advanced`,get label(){return M.t(`helpers.ruleFormTabs.tab_advanced`)},fields:[`snoozeAllowGlobal`,`snoozeOptions`,`askVerdict`,`offerAlertAction`,`cooldownSec`,`cooldownScope`,`cooldownGranularity`]}];function oi(e,t={}){let n=C({delivery:e,conditions:t}),r=A(n),i=ai.map(e=>e.key===`conditions`?{...e,label:r.label}:e);return he(n)?i.filter(e=>e.key!==`devices`):i}function si(e){if(e.audio!==void 0)return M.t(`helpers.ruleFormTabs.condSound`);if(e.occupancy!==void 0)return M.t(`helpers.ruleFormTabs.condOccupancy`)}function ci(e){let t=C(e),n=fe(_r(e),t);return t===`sensor`&&e.conditions.sensorTransition!==void 0&&!R(`sensorTransition`,e.conditions)?[...n,{conditionId:`sensorTransition`,reason:Ue}]:n}var li=`rule`;function ui(e){return ai.find(t=>t.key===e)?.key}function di(e){return e?.toLowerCase().startsWith(`it`)===!0?`it`:`en`}function fi(){let{i18n:e}=N(),t=di(e.language);return e=>ve(e,t)}i();var pi=`block text-[11px] font-medium text-foreground`,Z=`text-[10px] text-foreground-subtle mt-0.5`;function mi({cameras:e,fleet:t,value:r,onChange:i,emptyMeansAll:a=!1,savedHadDevices:o=!1}){return n(et,{devices:e,listState:t.state,fleet:t,value:r,onChange:i,emptyMeansAll:a,savedHadDevices:o})}function hi({value:t,placeholder:i,onChange:a}){let{t:o}=N(),[c,l]=r(``),u=()=>{let e=c.trim();if(e.length===0||t.includes(e)){l(``);return}a([...t,e]),l(``)},d=e=>a(t.filter(t=>t!==e));return e(`div`,{className:`mt-1 space-y-1.5`,children:[t.length>0&&n(`div`,{className:`flex flex-wrap gap-1`,children:t.map(t=>e(`span`,{className:`inline-flex items-center gap-1 rounded bg-surface-hover px-1.5 py-0.5 text-[11px] text-foreground`,children:[t,n(_,{variant:`unstyled`,type:`button`,onClick:()=>d(t),"aria-label":o(`system.notificationConditionWidgets.remove`,`remove {{v}}`,{v:t}),className:`text-foreground-subtle hover:text-danger`,children:n(s,{className:`h-3 w-3`})})]},t))}),n(g,{value:c,placeholder:i,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),u())},onBlur:u})]})}function gi({picker:r,value:i,onChange:a}){let{t:o}=N(),s=t(()=>We(r),[r]),c=t(()=>new Set(i),[i]),l=i.filter(e=>!s.has(e)),u=e=>{a(c.has(e)?i.filter(t=>t!==e):[...i,e])};return e(`div`,{className:`space-y-2`,children:[l.length>0&&n(`div`,{className:`flex flex-wrap gap-1`,children:l.map(t=>e(_,{variant:`unstyled`,type:`button`,onClick:()=>a(i.filter(e=>e!==t)),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:o(`system.notificationConditionWidgets.customValueClickToRemove`,`Custom value — click to remove`),children:[t,` ×`]},t))}),r.groups.map(t=>e(`div`,{children:[n(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-muted mb-1`,children:t.fallbackLabel}),n(`div`,{className:`flex flex-wrap gap-1`,children:t.options.map(e=>{let t=c.has(e.value);return n(_,{variant:`unstyled`,type:`button`,"aria-pressed":t,onClick:()=>u(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)})})]},t.key))]})}function _i({value:t,min:r,max:i,step:a,onChange:o}){let{t:s}=N();return e(`div`,{className:`mt-1 flex items-center gap-2`,children:[n(g,{type:`number`,value:t??``,min:r,max:i,step:a,className:`max-w-[8rem]`,onChange:e=>{let t=e.target.value;if(t===``){o(void 0);return}let n=Number(t);o(Number.isFinite(n)?n:void 0)}}),t!==void 0&&i!==void 0&&n(l,{min:r,max:i,step:a,value:t,onChange:e=>o(Number(e.target.value)),className:`flex-1 accent-primary`,"aria-label":s(`common.valueWord`)})]})}function vi({value:t,onChange:r,options:i}){let{t:a}=N(),o=yi(i??[]),s=o.length>0?o:rn;return e(`div`,{className:`mt-1 space-y-1`,children:[n(d,{value:t??`enter`,options:s.map(e=>({value:e.value,label:a(`notificationRules.crossing.${e.value}`,e.label)})),onChange:e=>r(on(e.target.value))}),n(`p`,{className:Z,children:a(`notificationRules.crossing.hint`,`Which way the subject crosses the zone.`)})]})}function yi(e){let t=[];for(let n of e){let e=n.value===``||n.value===`enter`?an:on(n.value);e===void 0||t.some(t=>t.value===e)||t.push({value:e,label:n.label})}return t}function bi({deviceIds:e,cameras:t,value:r,onChange:i}){let{options:a,loading:o}=F(e,t);return n(I,{options:a,value:r,onChange:i,loading:o,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 xi({deviceIds:r,cameras:i,allDevices:a,value:s,onChange:c}){let{t:l}=N(),{options:u,loading:d}=wt(r),f=Tt(t(()=>Ct(r,i,a),[r,i,a]));return e(o,{children:[n(I,{options:t(()=>{let e=new Set(f.options.map(e=>e.value));return[...f.options,...u.filter(t=>!e.has(t.value))]},[f.options,u]),value:s,onChange:c,loading:d||f.pending,emptyHint:r.length===0?l(`system.notificationConditionWidgets.eventTokensSelectDevices`,`Select a device above to pick one of its events — or type a token.`):l(`system.notificationConditionWidgets.eventTokensNone`,`The selected devices declare no events — type a token.`),placeholder:l(`system.notificationConditionWidgets.eventToken`,`Event token…`)}),f.unknownDevices.length>0&&n(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:l(`system.notificationConditionWidgets.eventTokensUnknown`,`Could not read the events of: {{devices}}. They are unknown, not absent.`,{devices:f.unknownDevices.join(`, `)})})]})}var Q=[{value:`became-occupied`,labelKey:`system.notificationConditionWidgets.opBecameOccupied`},{value:`became-free`,labelKey:`system.notificationConditionWidgets.opBecameFree`},{value:`>=`,labelKey:`system.notificationConditionWidgets.opCountAtLeast`},{value:`<=`,labelKey:`system.notificationConditionWidgets.opCountAtMost`}];function Si(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:M.t(`system.notificationConditionWidgets.subTypeNeverCountsAlways`,`{{stored}} — sub-type, never counts (always 0)`,{stored:t})}]}function Ci({deviceIds:t,cameras:r,classOptions:i,value:a,onChange:o}){let{t:s}=N(),{options:l,loading:u}=F(t,r),f=a??ee,p=e=>o({...f,...e}),m=f.op===`became-occupied`||f.op===`became-free`,h=Si(i,f.className);return e(`div`,{className:`mt-1 space-y-1.5`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[n(`div`,{className:`min-w-[10rem]`,children:n(d,{value:f.zoneId??``,options:[{value:``,label:u?s(`system.notificationConditionWidgets.loadingZones`,`Loading zones…`):s(`system.notificationConditionWidgets.wholeFrame`,`— whole frame —`)},...l.map(e=>({value:e.value,label:e.label}))],onChange:e=>p({zoneId:e.target.value===``?void 0:e.target.value})})}),n(`div`,{className:`min-w-[9rem]`,children:n(d,{value:f.className??``,options:[{value:``,label:s(`system.notificationConditionWidgets.anyClass`,`— any class —`)},...h],onChange:e=>p({className:e.target.value===``?void 0:e.target.value})})}),n(`div`,{className:`min-w-[9rem]`,children:n(d,{value:f.op,options:Q.map(e=>({value:e.value,label:s(e.labelKey)})),onChange:e=>{let t=Q.find(t=>t.value===e.target.value);t&&p({op:t.value})}})})]}),e(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:[e(`label`,{className:`flex items-center gap-1`,children:[m?s(`system.notificationConditionWidgets.threshold`,`Threshold`):s(`system.notificationConditionWidgets.count`,`Count`),n(g,{type:`number`,min:0,className:`w-16`,value:String(f.count),onChange:e=>p({count:Math.max(0,Number(e.target.value)||0)})})]}),e(`div`,{className:`flex items-center gap-1`,children:[s(`system.notificationConditionWidgets.holdFor`,`Hold for`),n(c,{"aria-label":s(`system.notificationConditionWidgets.holdFor`,`Hold for`),value:f.sustainSeconds,min:0,max:3600,onChange:e=>p({sustainSeconds:Math.min(3600,Math.max(0,e))})}),` `]}),a===void 0?null:n(_,{variant:`unstyled`,type:`button`,onClick:()=>o(void 0),className:`underline hover:text-foreground`,children:s(`system.notificationConditionWidgets.clear`,`Clear`)})]}),t.length===0&&n(`p`,{className:`text-[11px] text-warning`,children:s(`system.notificationConditionWidgets.noCameraPickedOnThe`,`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.`)}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:s(`system.notificationConditionWidgets.countsConfirmedTrackedObjectsFrom`,`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 wi=[{value:`label`,labelKey:`system.notificationConditionWidgets.audioModeLabel`,Icon:f},{value:`level`,labelKey:`system.notificationConditionWidgets.audioModeLevel`,Icon:u}];function Ti({taxonomy:t,value:r,onChange:i}){let{t:a}=N(),s=Ge(r),l=e=>i(Fe(r,e)),{choices:u,unknownLabels:d}=Ae(t,s.labels),f=Le(r)??`label`;return e(`div`,{className:`mt-1 space-y-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1`,children:[wi.map(t=>n(_,{variant:`unstyled`,type:`button`,"aria-pressed":f===t.value,onClick:()=>l({mode:t.value}),className:`rounded border px-2 py-0.5 text-[11px] ${f===t.value?`border-primary bg-primary/15 text-foreground`:`border-border text-foreground-subtle hover:bg-surface-hover`}`,children:e(`span`,{className:`inline-flex items-center gap-1`,children:[n(t.Icon,{className:`h-3 w-3`}),a(t.labelKey)]})},t.value)),r===void 0?null:n(_,{variant:`unstyled`,type:`button`,onClick:()=>i(void 0),className:`ml-1 text-xs text-foreground-subtle underline hover:text-foreground`,children:a(`system.notificationConditionWidgets.clear`,`Clear`)})]}),f===`label`?e(o,{children:[n(`div`,{className:`flex flex-wrap gap-1`,children:u.map(t=>{let r=Me(s.labels,t.value),i=t.unknown?`border-dashed border-warning text-warning`:r?`border-primary bg-primary/15 text-foreground`:`border-border text-foreground hover:bg-surface-hover`;return n(_,{variant:`unstyled`,type:`button`,"aria-pressed":r,title:t.unknown?a(`system.notificationConditionWidgets.storedByTheRuleNot`,`Stored by the rule — not offered by this hub`):void 0,onClick:()=>l({labels:Be(s.labels,t.value)}),className:`rounded border px-1.5 py-0.5 text-[10px] ${i}`,children:e(`span`,{className:`inline-flex items-center gap-1`,children:[n($e,{iconId:t.iconId,size:12}),t.label]})},t.value)})}),d.length>0&&e(`p`,{className:`text-[10px] text-warning`,children:[a(`system.notificationConditionWidgets.keptFromTheRuleUnknown`,`Kept from the rule, unknown to this hub:`),` `,d.join(`, `)]}),e(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:[e(`label`,{className:`flex items-center gap-1`,children:[a(`system.notificationConditionWidgets.confirmAfter`,`Confirm after`),n(g,{type:`number`,min:1,max:20,step:1,className:`w-16`,value:String(s.confirmHits??2),onChange:e=>l({confirmHits:Number(e.target.value)})}),a(`system.notificationConditionWidgets.frames`)]}),e(`div`,{className:`flex items-center gap-1`,children:[a(`system.notificationConditionWidgets.within`),n(c,{"aria-label":a(`system.notificationConditionWidgets.within`),value:s.confirmWindowSec??5,min:1,max:60,onChange:e=>l({confirmWindowSec:e})}),` `]})]}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`system.notificationConditionWidgets.audioConfirmHint`,{hits:2,window:5})})]}):e(o,{children:[n(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:e(`label`,{className:`flex items-center gap-1`,children:[a(`system.notificationConditionWidgets.louderThan`,`Louder than`),n(g,{type:`number`,min:D,max:0,step:3,className:`w-20`,value:String(s.dbThreshold??Oe),onChange:e=>l({dbThreshold:Number(e.target.value)})}),`dBFS`]})}),e(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:[e(`label`,{className:`flex items-center gap-1`,children:[a(`system.notificationConditionWidgets.hits`,`Hits`),n(g,{type:`number`,min:1,max:100,step:5,className:`w-16`,value:String(s.hitPercent),onChange:e=>l({hitPercent:Number(e.target.value)})}),a(`system.notificationConditionWidgets.hitsPercentDefault`,{value:ze.hitPercent})]}),e(`div`,{className:`flex items-center gap-1`,children:[a(`system.notificationConditionWidgets.over`),n(c,{"aria-label":a(`system.notificationConditionWidgets.over`),value:s.samplingSeconds,min:1,max:300,onChange:e=>l({samplingSeconds:e})}),a(`system.notificationConditionWidgets.secondsDefault`,{value:ze.samplingSeconds})]})]}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`system.notificationConditionWidgets.dbfsHint`,{min:D})})]}),He(r)?n(`p`,{className:`text-[11px] text-warning`,children:a(`system.notificationConditionWidgets.withNeitherASoundNor`,`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 Ei({value:t,onChange:r}){let{t:i}=N(),a=t?.values??[],o=t?.maxDistance??1,s=e=>r(e.length>0?{values:e,maxDistance:o}:void 0),c=e=>r(a.length>0?{values:a,maxDistance:e}:void 0),l=Dt().filter(e=>!a.includes(e));return e(`div`,{className:`mt-1 space-y-1.5`,children:[n(hi,{value:a,placeholder:i(`system.notificationConditionWidgets.plateText`,`Plate text…`),onChange:s}),l.length>0&&e(`div`,{className:`flex flex-wrap items-center gap-1`,children:[n(`span`,{className:`text-[10px] text-foreground-subtle`,children:i(`system.notificationConditionWidgets.seen`,`Seen:`)}),l.slice(0,12).map(e=>n(_,{variant:`unstyled`,type:`button`,onClick:()=>s([...a,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))]}),e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[i(`system.notificationConditionWidgets.maxDistance`,`Max distance`),n(g,{type:`number`,min:0,max:3,step:1,value:o,className:`max-w-[5rem]`,onChange:e=>{let t=Number(e.target.value);c(Number.isFinite(t)?Math.max(0,Math.min(3,t)):1)}})]})]})}function Di({gateable:t,value:r,onChange:i}){let{t:a}=N(),o=fi(),s=t.find(e=>e.id===r?.deviceId),c=new Set(r?.states??[]),l=e=>{let t=Number(e);if(!Number.isFinite(t)||t===0)return i(void 0);i({deviceId:t,states:[]})},u=e=>{if(r===void 0)return;let t=new Set(c);t.has(e)?t.delete(e):t.add(e),i(t.size===0?void 0:{deviceId:r.deviceId,states:[...t]})};return e(`div`,{className:`mt-1 space-y-2`,children:[n(d,{value:r===void 0?``:String(r.deviceId),options:[{value:``,label:a(`system.notificationConditionWidgets.noDeviceGate`,`— no device gate —`)},...t.map(e=>({value:String(e.id),label:e.name}))],onChange:e=>l(e.target.value)}),s!==void 0&&n(`div`,{className:`flex flex-wrap gap-1.5`,children:s.states.map(e=>n(_,{variant:`unstyled`,type:`button`,onClick:()=>u(e),className:c.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:o(e)},e))}),s!==void 0&&s.states.length===0&&n(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:a(`system.notificationConditionWidgets.thisDeviceReportsNoState`,`This device reports no state the gate can read, so it cannot arm a rule.`)}),r!==void 0&&n(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:a(`system.notificationConditionWidgets.theRuleIsSilentWhile`,`The rule is silent while the device is in any other state — including when its state cannot be read at all.`)})]})}function Oi(e,t){let n=t(e.verdict);return e.latched?`${n} · ${t(`latched`)}`:n}function ki({scenes:t,value:r,onChange:i}){let{t:a}=N(),o=fi(),s=t.find(e=>e.sceneId===r?.sceneId),c=e=>{if(e===``)return i(void 0);let n=t.find(t=>t.sceneId===e);if(n===void 0)return i(void 0);i({sceneId:e,deviceId:n.deviceId,requiredState:r?.requiredState??`diverged`,...r?.latched===void 0?{}:{latched:r.latched}})},l=e=>{r!==void 0&&i({...r,requiredState:e===`matched`?`matched`:`diverged`})},u=e=>{if(r!==void 0){if(e===``){let{latched:e,...t}=r;return i(t)}i({...r,latched:e===`latched`})}};return t.length===0?n(`p`,{className:Z,children:a(`notificationRules.scene.none`,`No scenes yet — create one on the Scenes page.`)}):e(`div`,{className:`mt-1 space-y-2`,children:[n(d,{value:r?.sceneId??``,options:[{value:``,label:a(`notificationRules.scene.noGate`,`— no scene gate —`)},...t.map(e=>({value:e.sceneId,label:`${e.cameraName} · ${e.label} — ${Oi(e,o)}`}))],onChange:e=>c(e.target.value)}),r!==void 0&&e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[a(`notificationRules.scene.onlyWhile`,`Only while it is`),n(d,{value:r.requiredState,options:[{value:`diverged`,label:o(`diverged`)},{value:`matched`,label:o(`matched`)}],onChange:e=>l(e.target.value)})]}),e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[a(`notificationRules.scene.read`,`Read`),n(d,{value:r.latched===void 0?``:r.latched?`latched`:`live`,options:[{value:``,label:s===void 0?a(`notificationRules.scene.readOwn`,`The scene's own setting`):`${a(`notificationRules.scene.readOwn`,`The scene's own setting`)} (${o(s.emit)})`},{value:`latched`,label:o(`latched`)},{value:`live`,label:o(`live`)}],onChange:e=>u(e.target.value)})]})]}),s!==void 0&&e(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:[a(`notificationRules.scene.rightNow`,`Right now:`),` `,Oi(s,o)]}),r!==void 0&&s===void 0&&n(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:a(`notificationRules.scene.missing`,`This scene no longer exists — pick another or remove the gate.`)})]})}function Ai(){return{days:[1,2,3,4,5],startMinute:540,endMinute:1080}}function ji(e){return{days:[...z.days],minute:e}}var Mi=`Always active — add a window to restrict when the rule fires.`;function Ni({value:e,onChange:t,mode:r=`windows`,defaultMinute:i=z.minute,emptyHint:a}){return r===`times`?n(Fi,{value:e,onChange:t,defaultMinute:i}):n(Pi,{value:e,onChange:t,emptyHint:a??Mi})}function Pi({value:t,onChange:r,emptyHint:i}){let{t:a}=N(),o=t?.windows??[],s=t?.invert??!1,c=(e,n)=>{if(e.length===0){r(void 0);return}r({windows:e,...n?{invert:!0}:{},...t?.timezone?{timezone:t.timezone}:{}})},l=()=>c([...o,Ai()],s),u=e=>c(o.filter((t,n)=>n!==e),s),d=(e,t)=>c(o.map((n,r)=>r===e?t:n),s);return e(`div`,{className:`mt-1 space-y-2`,"data-testid":`schedule-field-windows`,children:[o.length===0?n(`p`,{className:Z,children:i}):o.map((e,t)=>n(Ii,{window:e,onChange:e=>d(t,e),onRemove:()=>u(t)},t)),e(`div`,{className:`flex items-center gap-3`,children:[e(_,{variant:`unstyled`,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:[n(p,{className:`h-3 w-3`}),` `,a(`system.notificationScheduleField.addWindow`)]}),o.length>0&&e(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[n(h,{checked:s,onChange:e=>c([...o],e.target.checked),className:`accent-primary`}),a(`system.notificationScheduleField.activeOutsideTheWindows`,`Active outside the windows`)]})]})]})}function Fi({value:t,onChange:r,defaultMinute:i}){let{t:a}=N(),o=t?.timezone,s=t===void 0?{times:[],approximated:!1}:ie(t);if(s===null)return e(`div`,{className:`mt-1 space-y-2`,"data-testid":`schedule-field-times-fallback`,children:[n(`p`,{className:Z,children:a(`system.notificationScheduleField.invertedScheduleShownAsBands`,`Inverted schedule — shown as bands. Clear the invert flag (or the windows) to author punctual times.`)}),n(Pi,{value:t,onChange:r,emptyHint:Mi})]});let c=s.times,l=e=>{if(e.length===0){r(void 0);return}r(w(e,o))};return e(`div`,{className:`mt-1 space-y-2`,"data-testid":`schedule-field-times`,children:[s.approximated&&n(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,"data-testid":`schedule-field-times-approximated`,children:a(`system.notificationScheduleField.shownAsSendAtTimes`,`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.`)}),c.length===0?n(`p`,{className:Z,children:a(`system.notificationScheduleField.noTimesYetAddOne`,`No times yet — add one to send on those days at that clock time.`)}):c.map((e,t)=>n(Li,{time:e,index:t,onChange:e=>l(c.map((n,r)=>r===t?e:n)),onRemove:c.length>1?()=>l(c.filter((e,n)=>n!==t)):void 0},t)),e(_,{variant:`unstyled`,type:`button`,onClick:()=>l([...c,ji(i)]),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:[n(p,{className:`h-3 w-3`}),` `,a(`system.notificationScheduleField.addTime`)]})]})}function Ii({window:t,onChange:r,onRemove:i}){let{t:a}=N();return n(`div`,{className:`space-y-1.5 rounded-md border border-border p-2`,children:e(`div`,{className:`flex items-start gap-2 text-xs`,children:[n(tt,{clockOnly:!0,value:rt(t),onChange:e=>{let t=Ze(e);t!==null&&r(t)},testIdPrefix:`schedule-window`}),n(_,{variant:`unstyled`,type:`button`,onClick:i,"aria-label":a(`system.notificationScheduleField.removeWindow`,`Remove window`),className:`text-foreground-subtle hover:text-danger`,children:n(m,{className:`h-3.5 w-3.5`})})]})})}function Li({time:t,index:r,onChange:i,onRemove:a}){let{t:o}=N();return e(`div`,{className:`space-y-1.5 rounded-md border border-border p-2`,children:[e(`div`,{className:`flex items-center gap-2 text-xs`,children:[n(`span`,{className:`text-foreground-subtle`,children:o(`system.notificationScheduleField.at`,`At`)}),n(g,{type:`time`,value:fn(t.minute),onChange:e=>i({...t,minute:pn(e.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`,"data-testid":`schedule-field-time-${String(r)}`}),n(`span`,{className:`flex-1`}),a!==void 0&&n(_,{variant:`unstyled`,type:`button`,onClick:a,"aria-label":o(`system.notificationScheduleField.removeTime`,`Remove time`),className:`text-foreground-subtle hover:text-danger`,children:n(m,{className:`h-3.5 w-3.5`})})]}),n(Ri,{days:t.days,onToggle:e=>{let n=t.days.includes(e)?t.days.filter(t=>t!==e):[...t.days,e];n.length!==0&&i({...t,days:n})}})]})}function Ri({days:e,onToggle:t}){return n(`div`,{className:`flex flex-wrap gap-1`,children:dn.map(r=>n(_,{variant:`unstyled`,type:`button`,onClick:()=>t(r.value),className:`rounded px-1.5 py-0.5 text-[10px] ${e.includes(r.value)?`bg-primary text-primary-foreground`:`bg-surface-hover text-foreground-subtle`}`,children:r.label},r.value))})}function zi(e){return e>=8}i();function Bi(e){if(typeof e!=`object`||!e)return;let t=Reflect.get(e,`windows`);if(!(!Array.isArray(t)||t.length===0))return e}function Vi(e){return e.type===`multiselect`}function Hi(e){let t=e.suggestions;return t===void 0||t.length===0?[]:t.map(e=>({value:e,label:e}))}function Ui(e){return e.map(e=>({value:e.value,label:e.label,...e.description===void 0?{}:{description:e.description},...e.iconId===void 0?{}:{iconId:e.iconId}}))}function Wi(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function Gi({field:t,values:r,onChange:i,onChangeMany:a,disabled:o,translationFn:s,onTestField:c,externalProbe:l,allFields:u,onAction:d}){let{t:f}=N();if(t.type===`tags`){if(!j(t,r,u))return null;let e=t.creatable!==!1;return n(Je,{mode:`multi`,options:Hi(t),value:Wi(r[t.key]),onChange:e=>i(t.key,e),disabled:o===!0||t.disabled===!0,creatable:e,...t.createLabel===void 0?{}:{createLabel:t.createLabel},...t.maxTags===void 0?{}:{maxItems:t.maxTags},label:$(t.label,s),description:t.description===void 0?void 0:$(t.description,s),placeholder:t.placeholder??f(`formBuilder.formBuilder.searchOrAdd`,`Search or add…`),testId:`config-tags-${t.key}`})}if(t.type===`schedule`){if(!j(t,r,u))return null;let a=$(t.label,s),o=t.description===void 0?void 0:$(t.description,s),c=t.mode===`times`?`times`:`windows`;return e(`div`,{className:`space-y-1`,"data-testid":`config-schedule-${t.key}`,children:[a!==void 0&&n(`label`,{className:`block text-[11px] font-medium text-foreground-subtle`,children:a}),o!==void 0&&n(`p`,{className:`text-[10px] text-foreground-subtle`,children:o}),n(Ni,{mode:c,value:Bi(r[t.key]),onChange:e=>i(t.key,e)})]})}return Vi(t)&&(zi(t.options.length)||t.creatable===!0)?j(t,r,u)?n(Je,{mode:`multi`,options:Ui(t.options),value:Wi(r[t.key]),onChange:e=>i(t.key,e),disabled:o===!0||t.disabled===!0,creatable:t.creatable===!0,...t.createLabel===void 0?{}:{createLabel:t.createLabel},...t.maxItems===void 0?{}:{maxItems:t.maxItems},label:$(t.label,s),description:t.description===void 0?void 0:$(t.description,s),placeholder:t.placeholder??f(`formBuilder.formBuilder.searchToAdd`,`Search to add…`),testId:`config-multiselect-${t.key}`,listboxId:`msel-${t.key}`}):null:n(Xe,{field:t,values:r,onChange:i,onChangeMany:a,disabled:o,translationFn:s,onTestField:c,externalProbe:l,allFields:u,onAction:d})}function Ki(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function $(e,t){if(e!==void 0)return t&&Ki(e)?t(e):e}function qi({section:t,values:i,onChange:a,onChangeMany:s,disabled:c,translationFn:l,onTestField:u,probeResults:d,onAction:f}){let[p,m]=r(t.defaultCollapsed??!1),h=t.style===`accordion`;if(t.fields.reduce((e,n)=>e+ +!!j(n,i,t.fields),0)===0)return null;let g=t.fields,_=t.columns??2,v=_===1?`grid-cols-1`:_===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:_===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`,y=t.fields.length===1&&t.fields[0]?.type===`widget`?t.fields[0]:void 0,b=y!==void 0||!t.title&&!t.description;return e(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},"data-settings-section":t.id,children:[!b&&(h?e(`button`,{type:`button`,"aria-expanded":!p,onClick:()=>m(e=>!e),className:`flex w-full items-center justify-between mb-2 text-left`,children:[e(`div`,{children:[t.title&&n(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:$(t.title,l)}),t.description&&n(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:$(t.description,l)})]}),n(nt,{expanded:!p,className:`ml-2`})]}):n(`div`,{className:`flex items-center justify-between mb-2`,children:e(`div`,{children:[t.title&&n(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:$(t.title,l)}),t.description&&n(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:$(t.description,l)})]})})),!(p&&!b)&&(y===void 0?n(o,{children:n(`div`,{className:`grid ${v} gap-x-3 gap-y-2.5`,children:g.map(e=>n(Gi,{field:e,values:i,onChange:a,onChangeMany:s,disabled:c,translationFn:l,onTestField:u,externalProbe:d?.[e.key],allFields:t.fields,onAction:f},e.key))})}):n(Xe,{field:y,values:i,onChange:a,onChangeMany:s,disabled:c,translationFn:l,onTestField:u,externalProbe:d?.[y.key],allFields:t.fields,onAction:f},y.key))]})}function Ji({schema:e,values:t,onChange:r,disabled:i,translationFn:a,onTestField:o,probeResults:s,onClearProbe:c,onAction:l,visibilityContext:u}){let d=u?{...u,...t}:t,f=(e,n)=>{r({...t,[e]:n}),c?.(e)},p=e=>{r({...t,...e});for(let t of Object.keys(e))c?.(t)};return n(`div`,{className:`space-y-4`,children:e.sections.map((e,t)=>n(qi,{section:e,values:d,onChange:f,onChangeMany:p,disabled:i,translationFn:a,onTestField:o,probeResults:s,onAction:l},`${e.id}-${t}`))})}export{K as $,jt as $t,Ur as A,bt as An,xn as At,br as B,Vt as Bt,ri as C,dt as Cn,Kn as Ct,Br as D,lt as Dn,B as Dt,zr as E,ft as En,V as Et,ur as F,bn as Ft,Y as G,en as Gt,hr as H,Ot as Ht,dr as I,yn as It,xr as J,tn as Jt,Sr as K,sn as Kt,jr as L,Zt as Lt,qr as M,gn as Mt,Vr as N,wn as Nt,Kr as O,ot as On,zn as Ot,Hr as P,vn as Pt,sr as Q,At as Qt,Dr as R,ln as Rt,ii as S,mt as Sn,Gn as St,Zr as T,vt as Tn,Rn as Tt,Tr as U,qt as Ut,vr as V,Ut as Vt,mr as W,Yt as Wt,wr as X,R as Xt,fr as Y,$t as Yt,kr as Z,Ht as Zt,li as _,ut as _n,Pn as _t,mi as a,un as an,ir as at,ui as b,st as bn,Wn as bt,Z as c,Mt as cn,er as ct,Ci as d,nn as dn,$n as dt,cn as en,q as et,Ei as f,Nt as fn,Zn as ft,bi as g,ht as gn,In as gt,gi as h,F as hn,Un as ht,vi as i,Qt as in,ar as it,Rr as j,yt as jn,hn as jt,Gr as k,gt as kn,Bn as kt,pi as l,Xt as ln,tr as lt,hi as m,Et as mn,Xn as mt,Ni as n,Lt as nn,or as nt,Di as o,Kt as on,Jn as ot,ki as p,I as pn,Qn as pt,yr as q,It as qt,Ti as r,Rt as rn,cr as rt,xi as s,Wt as sn,G as st,Ji as t,Ft as tn,J as tt,_i as u,Jt as un,W as ut,si as v,at as vn,qn as vt,ni as w,pt as wn,Nn as wt,oi as x,ct as xn,Hn as xt,ci as y,_t as yn,Fn as yt,Ir as z,Gt as zt};
@@ -1 +1 @@
1
- import{C as e,K as t,S as n,Y as r,et as i,i 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-CEyXHAdg.js";import{D as s,Gt as c,Oo as l,_t as u,hr as d,ht as f,ka as p,lr as m,oi as h,xn as g,yi as _,yt as v,z as y,zt as b}from"./player-overlays-qzCoRsrQ.js";import{Nc as x,ji as S}from"./src-CJoX3s-1.js";import{g as C}from"./terminal-BncJ-1sF.js";import{$a as w,$i as ee,Am as T,An as E,Cn as D,Dn as O,En as k,Gr as A,Jr as j,Ma as M,Mc as N,On as P,Pa as F,Sn as te,Tn as ne,Vi as re,Yr as I,Za as L,_n as ie,aa as ae,an as oe,ao as se,cn as ce,co as R,dn as le,ea as ue,eo as z,fn as de,fo as B,gn as fe,hn as pe,ia as me,in as he,jm as ge,jr as _e,kn as ve,kr as ye,ln as be,mn as V,nc as xe,on as Se,op as Ce,pn as H,ra as we,rc as Te,ta as Ee,wn as De}from"./src-Cf1Uvi4o.js";import{p as Oe}from"./chunk-4ZMWKKQ3-BCeNTgXs.js";import{t as U}from"./useTranslation-uIxPZ_3N.js";import{t as ke}from"./AdminPage-CA4Sxydy.js";i();function W(e,t){return e.scope===``?e.displayName:`${e.displayName} · ${t?.(e)??e.scope}`}function Ae(e,t,n){let r=[];for(let{device:t,series:i}of e)for(let e of i){let i={subject:{kind:`device`,deviceId:t.id},key:e.key,scope:e.scope};r.push({id:V(i),ref:i,info:e,subjectName:t.name,location:t.location??``,nodeId:``,metric:W(e,n)})}for(let{node:e,series:i}of t)for(let t of i){let i={subject:{kind:`node`,nodeId:e.id},key:t.key,scope:t.scope};r.push({id:V(i),ref:i,info:t,subjectName:e.name,location:``,nodeId:e.id,metric:W(t,n)})}return r}function je(e){return[e.subjectName,e.location,e.metric,e.info.key,e.info.unit??``,e.nodeId].join(` `)}function G(e,t,n){if(e.ref.subject.kind!==`device`||t===null)return e.subjectName;let r=t.byId.get(e.ref.subject.deviceId);return r===void 0?e.subjectName:se(r,`compact`,t,n)}var Me=[`energy`,`temperatures`,`nodes`,`storage`],Ne=new Set([`cap:temperature-sensor.temperature`,`cap:climate-control.currentTemp`]),K=[`addon:metrics-native/node-cpu-percent`,`addon:metrics-native/node-memory-percent`],Pe=`addon:storage-orchestrator/location-used-percent`;function Fe(e,t){let n=(e,n)=>{let r=t.filter(e);return H((n?[...r].sort(n):r).map(e=>e.ref))};switch(e){case`energy`:return n(e=>e.ref.subject.kind===`device`&&e.info.key===`derived:energy.kwh`);case`temperatures`:return n(e=>e.ref.subject.kind===`device`&&Ne.has(e.info.key)&&e.info.scope===``,(e,t)=>e.location.localeCompare(t.location)||e.subjectName.localeCompare(t.subjectName));case`nodes`:return n(e=>e.ref.subject.kind===`node`&&K.includes(e.info.key)&&e.info.scope===``,(e,t)=>K.indexOf(e.info.key)-K.indexOf(t.info.key)||e.subjectName.localeCompare(t.subjectName));case`storage`:return n(e=>e.ref.subject.kind===`node`&&e.info.key===Pe)}}function Ie(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=[],a=[],o=[];for(let t of H(e)){let e=n.get(V(t));if(e===void 0){o.push(t);continue}e.info.key===`derived:energy.kwh`?a.push(e):e.info.kind===`boolean`||e.info.kind===`enum`?i.push(e):r.push(e)}return{lines:r,states:i,energy:a,missing:o}}function q(e){return e.subject.kind===`device`?{deviceId:e.subject.deviceId,key:e.key,scope:e.scope}:{forNodeId:e.subject.nodeId,key:e.key,scope:e.scope}}var J=`history-page`;function Le({part:r,window:i}){let{t:a}=U(),o=l(),s=B(),c=R(),u=e=>`${G(e,s,c)} · ${e.metric}`,d=t(()=>[...r.lines,...r.states,...r.energy],[r]),f=ce(t(()=>d.map(e=>q(e.ref)),[d]),i,!1),m=e=>f.status===`ok`?f.data.current.get(Se(q(e.ref))):void 0,h=e=>{let t=m(e);return t?.ok?t.result:void 0};if(d.length===0)return n(F,{icon:p,title:a(`history.page.emptyTitle`,`Pick series to compare`),description:a(`history.page.emptyHint`,`Choose up to 24 series on the left, or start from a panel above.`)});if(f.status===`error`)return n(L,{title:a(`history.page.readFailed`,`History could not be read`),message:f.error});let g=f.status===`pending`,_=d.map(e=>({c:e,e:m(e)})).filter(e=>e.e?.ok===!1),v=r.lines.map((e,t)=>{let n=h(e),r=D(e.info,n,i.from);return{id:e.id,label:u(e),unit:e.info.unit,colorIndex:t,points:r.points,gapMs:r.gapMs,interpolation:r.held&&n?.resolution===`raw`?`step`:`linear`}}),y=r.states.map((e,t)=>{let n=De(e.info,h(e),i.from,i.to),r=ie(e.info.key,o);return{id:e.id,label:u(e),kind:e.info.kind===`boolean`?`boolean`:`enum`,colorIndex:e.info.kind===`boolean`?t:0,states:n.states,segments:n.segments,totals:n.totals,stateLabel:e.info.kind===`boolean`?e=>e===`true`?r.on:r.off:void 0}}),b=r.energy.map(e=>({c:e,...te(h(e))})),x=b[0]?.bucketMs??36e5,S=[...new Set(b.flatMap(e=>e.buckets.map(e=>e.t)))].sort((e,t)=>e-t).map(e=>({t:e,values:b.map(t=>t.buckets.find(t=>t.t===e)?.values[0]??null)}));return e(`div`,{className:`space-y-5 min-w-0`,children:[_.length>0&&n(L,{title:a(`history.page.someFailed`,`Some series could not be read`),message:_.map(e=>`${u(e.c)}: ${e.e.error}`).join(` · `)}),v.length>0&&n(ve,{title:a(`history.page.lines`,`Measurements`),series:v,range:i,height:260,syncKey:J,reserveRightAxis:!0,pending:g}),b.length>0&&n(M,{title:a(`history.page.energy`,`Energy`),layers:b.map((e,t)=>({id:e.c.id,label:G(e.c,s,c),colorIndex:t})),buckets:S,bucketMs:x,range:i,unit:`kWh`,showTotal:!0,height:160,syncKey:J,reserveRightAxis:!0,pending:g}),y.length>0&&n(E,{title:y.length===1?y[0]?.label??``:a(`history.page.states`,`States`),rows:y,range:i,syncKey:J,reserveRightAxis:!0,pending:g})]})}function Re(e,t){let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}async function ze(e,t){let n=[];for(let r of Re(e,50))try{let{results:e}=await t(r),i=new Map(e.map(e=>[e.seriesId,e]));for(let e of r)n.push(i.get(e)??{seriesId:e,ok:!1,reason:`not-found`})}catch(e){let t=e instanceof Error?e.message:String(e);for(let e of r)n.push({seriesId:e,ok:!1,reason:`request-failed`,message:t})}return n}function Y(e){return e.raw+e[`5m`]+e[`1h`]+e[`1d`]}function Be(e){return e.reduce((e,t)=>t.ok?{...e,deleted:e.deleted+1,points:e.points+Y(t.deleted)}:{...e,refused:e.refused+1},{deleted:0,refused:0,points:0})}function Ve(e,t){let n=new Map(e.map(e=>[e.seriesId,e]));return t.flatMap(e=>{let t=n.get(e.seriesId);return t===void 0?[]:[{series:t,outcome:e}]})}var X=e=>new Date(e).toLocaleDateString(void 0,{dateStyle:`short`});function Z(e,t,n){let r=t.get(e.deviceId);return r===void 0?e.reason===`device-gone`?n(`history.orphans.deviceRemoved`,`#{{id}} (removed)`,{id:e.deviceId}):n(`history.orphans.deviceId`,`#{{id}}`,{id:e.deviceId}):r}function Q(e){let t=e.displayName??e.key;return e.scope===``?t:`${t} · ${e.scope}`}function He(t,r,i){return{mobile:`primary`,key:`series`,header:i(`history.orphans.colSeries`,`Series`),render:a=>{let o=t(a);return e(`div`,{className:`min-w-0 max-w-[16rem]`,children:[n(`div`,{className:`truncate text-foreground`,title:o.key,children:Q(o)}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:Z(o,r,i)})]})},sortValue:e=>`${Z(t(e),r,i)} ${Q(t(e))}`}}var Ue=[`raw`,`5m`,`1h`,`1d`];function We(e,t){return e===`raw`?t(`history.orphans.colRaw`,`Raw points`):e===`5m`?t(`history.orphans.col5m`,`5 min`):e===`1h`?t(`history.orphans.col1h`,`1 h`):t(`history.orphans.col1d`,`1 day`)}function Ge(t,r){return[He(e=>e,t,r),{mobile:`detail`,key:`reason`,header:r(`history.orphans.colReason`,`Reason`),render:t=>e(`div`,{className:`flex flex-col items-start gap-0.5`,children:[n(w,{variant:t.reason===`device-gone`?`warning`:`neutral`,className:`text-[10px]`,children:t.reason===`device-gone`?r(`history.orphans.deviceGone`,`Device removed`):r(`history.orphans.undeclared`,`No longer declared`)}),t.missingSince!==null&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:r(`history.orphans.since`,`since {{date}}`,{date:X(t.missingSince)})})]}),sortValue:e=>e.reason},{mobile:`hidden`,key:`span`,header:r(`history.orphans.colSpan`,`Recorded`),render:t=>e(`span`,{className:`tabular-nums text-foreground-muted`,children:[X(t.firstTs),` → `,X(t.lastTs)]}),sortValue:e=>e.lastTs},...Ue.map(e=>({mobile:`hidden`,key:`rows-${e}`,header:We(e,r),align:`right`,render:t=>n(`span`,{className:`tabular-nums text-foreground-muted`,children:t.rows[e].toLocaleString()}),sortValue:t=>t.rows[e]}))]}function Ke(e,t){if(e.ok)return n(w,{variant:`success`,className:`text-[10px]`,children:t(`history.orphans.deleted`,{count:Y(e.deleted),points:Y(e.deleted).toLocaleString(),defaultValue_one:`Deleted · {{points}} point`,defaultValue_other:`Deleted · {{points}} points`})});let r=e.reason===`request-failed`?t(`history.orphans.requestFailed`,`Not sent: {{message}}`,{message:e.message}):e.reason===`not-orphan`?t(`history.orphans.refusedNotOrphan`,`Kept: no longer orphan`):e.reason===`not-found`?t(`history.orphans.refusedNotFound`,`Already gone`):t(`history.orphans.refusedFailed`,`The hub could not delete it`);return n(w,{variant:e.reason===`not-found`?`neutral`:`warning`,className:`text-[10px]`,children:r})}function qe(e,t){return[He(e=>e.series,e,t),{mobile:`detail`,key:`result`,header:t(`history.orphans.colResult`,`Result`),render:e=>Ke(e.outcome,t),sortValue:e=>+!e.outcome.ok}]}i();function Je({open:i,onClose:a,list:o,deviceNames:s,onDelete:c,onRefresh:l,refreshing:u}){let{t:p}=U(),m=f(),[_,y]=r(new Set),[b,x]=r(!1),[S,C]=r([]),w=t(()=>Ge(s,p),[s,p]),T=t(()=>qe(s,p),[s,p]),E=t(()=>new Set(o.series.map(e=>String(e.seriesId))),[o.series]),D=[..._].filter(e=>E.has(e)).map(Number),O=Be(S.map(e=>e.outcome)),k=async()=>{if(await m({title:p(`history.orphans.confirmTitle`,{count:D.length,defaultValue_one:`Delete {{count}} series`,defaultValue_other:`Delete {{count}} series`}),message:p(`history.orphans.confirmMessage`,`Every recorded point of these series is removed from the hub. This cannot be undone.`),confirmLabel:p(`history.orphans.confirmLabel`,`Delete`),variant:`danger`})){x(!0);try{let e=await ze(D,c);C(Ve(o.series,e)),y(new Set)}finally{x(!1),l()}}};return n(ee,{open:i,onOpenChange:e=>!e&&a(),children:e(Ee,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`orphan-series-dialog`,children:[n(me,{children:n(ae,{children:p(`history.orphans.title`,`Series no longer linked to a device`)})}),e(ue,{className:`space-y-3`,children:[n(`p`,{className:`text-xs text-foreground-muted`,children:p(`history.orphans.intro`,`Nothing records into these series any more: their device was removed, or no capability declares them now. Select the ones to delete.`)}),o.truncated&&e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`orphan-truncated`,children:[n(`p`,{className:`text-xs text-warning`,children:p(`history.orphans.truncated`,`More series are unlinked than are listed here. Delete these, then load the rest.`)}),e(v,{size:`sm`,variant:`outline`,onClick:l,disabled:u,children:[n(d,{className:`h-3 w-3`,"aria-hidden":!0}),p(`history.orphans.loadAgain`,`Load again`)]})]}),S.length>0&&e(`div`,{className:`space-y-2`,"data-testid":`orphan-outcomes`,children:[n(`p`,{className:`text-xs text-foreground`,"aria-live":`polite`,children:p(`history.orphans.summary`,{count:O.deleted,refused:O.refused,points:O.points.toLocaleString(),defaultValue_one:`{{count}} series deleted ({{points}} points), {{refused}} kept.`,defaultValue_other:`{{count}} series deleted ({{points}} points), {{refused}} kept.`})}),n(j,{columns:T,rows:S,rowKey:e=>String(e.series.seriesId),minWidthPx:420,maxBodyHeight:`max-h-[60vh]`,emptyMessage:``})]}),n(j,{columns:w,rows:o.series,rowKey:e=>String(e.seriesId),minWidthPx:760,maxBodyHeight:I,defaultSort:{columnKey:`series`,dir:`asc`},emptyMessage:p(`history.orphans.empty`,`Every series is linked to a device.`),selection:{selected:_,onChange:y,rowLabel:e=>`${Q(e)} — ${Z(e,s,p)}`,pageLabel:p(`history.orphans.selectAll`,`Select every listed series`)}})]}),e(we,{children:[n(`span`,{className:`mr-auto text-[11px] tabular-nums text-foreground`,"aria-live":`polite`,children:p(`history.orphans.selected`,{count:D.length,defaultValue_one:`{{count}} selected`,defaultValue_other:`{{count}} selected`})}),n(v,{variant:`ghost`,size:`sm`,onClick:a,children:p(`history.orphans.close`,`Close`)}),e(v,{variant:`danger`,size:`sm`,disabled:D.length===0||b,onClick:()=>void k(),children:[b?n(h,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):n(g,{className:`h-3 w-3`,"aria-hidden":!0}),p(`history.orphans.deleteSelected`,`Delete selected`)]})]})]})})}i();var Ye=5*6e4;function Xe({enabled:i}){let{t:a}=U(),[s,c]=r(!1),l=Te({},{enabled:i,staleTime:Ye}),u=N({projection:`slim`},{enabled:i}),d=xe(),f=t(()=>new Map((u.data??[]).map(e=>[e.id,e.name])),[u.data]),p=e=>d.mutateAsync({seriesIds:[...e]});if(!i||l.status===`pending`)return null;if(l.status===`error`)return n(L,{variant:`warning`,title:a(`history.orphans.checkFailedTitle`,`Could not check for unlinked series`),message:l.error.message,onRetry:()=>void l.refetch()});let m=l.data;if(m.series.length===0&&!s)return null;let h=m.series.length;return e(o,{children:[h>0&&n(L,{variant:`warning`,message:m.truncated?a(`history.orphans.noticeMore`,{count:h,defaultValue_one:`More than {{count}} series are no longer linked to a device.`,defaultValue_other:`More than {{count}} series are no longer linked to a device.`}):a(`history.orphans.notice`,{count:h,defaultValue_one:`{{count}} series is no longer linked to a device.`,defaultValue_other:`{{count}} series are no longer linked to a device.`}),action:n(v,{size:`sm`,variant:`outline`,onClick:()=>c(!0),children:a(`history.orphans.review`,`Review`)})}),n(Je,{open:s,onClose:()=>c(!1),list:m,deviceNames:f,onDelete:p,onRefresh:()=>void l.refetch(),refreshing:l.isFetching})]})}i();var Ze=`device`,Qe=`node`;function $e({catalog:r,selected:i,onChange:a,loading:o}){let{t:s}=U(),c=B(),l=R(),u=e=>G(e,c,l),d=ye(r,{searchText:e=>[je(e)],facetGroups:[{id:`subject`,value:e=>e.ref.subject.kind===`device`?Ze:Qe},{id:`room`,value:e=>e.location},{id:`unit`,value:e=>e.info.unit??``}]}),f=t(()=>[{mobile:`primary`,key:`metric`,header:s(`history.picker.series`,`Series`),render:t=>e(`div`,{className:`min-w-0`,children:[n(`div`,{className:`truncate text-foreground`,children:t.metric}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.location===``?u(t):`${u(t)} · ${t.location}`})]}),sortValue:e=>`${e.subjectName} ${e.metric}`},{mobile:`detail`,key:`unit`,header:s(`history.picker.unit`,`Unit`),render:e=>n(`span`,{className:`text-foreground-muted`,children:e.info.unit??`—`}),sortValue:e=>e.info.unit??``}],[s,c,l]),p=i.size>=24;return e(`div`,{className:`space-y-2 min-w-0`,children:[n(_e,{state:d.state,facets:[],groups:[{...d.groups.find(e=>e.id===`subject`)??{id:`subject`,facets:[],selected:[]},label:s(`history.picker.subject`,`Source`),facetLabel:e=>e===Ze?s(`history.picker.devices`,`Devices`):s(`history.picker.nodes`,`Nodes`)},{...d.groups.find(e=>e.id===`room`)??{id:`room`,facets:[],selected:[]},label:s(`history.picker.room`,`Room`),facetLabel:e=>e===``?s(`history.picker.noRoom`,`No room`):e},{...d.groups.find(e=>e.id===`unit`)??{id:`unit`,facets:[],selected:[]},label:s(`history.picker.metricType`,`Unit`),facetLabel:e=>e===``?s(`history.picker.noUnit`,`States & counts`):e}],labels:{searchPlaceholder:s(`history.picker.search`,`Search device, room, metric or node…`),searchLabel:s(`history.picker.searchLabel`,`Search series`),facetsLabel:s(`history.picker.facets`,`Filters`),clearLabel:s(`history.picker.clear`,`Clear`)},onSearch:d.setSearch,onToggleFacet:d.toggleFacet,onToggleGroupFacet:d.toggleGroupFacet,onClear:d.clear}),n(`p`,{className:`text-[10px] text-foreground-subtle`,"aria-live":`polite`,children:s(`history.picker.count`,`{{count}} of {{max}} selected`,{count:i.size,max:24})}),n(j,{columns:f,rows:d.rows,rowKey:e=>e.id,maxBodyHeight:I,pageSize:50,defaultSort:{columnKey:`metric`,dir:`asc`},emptyMessage:o?s(`history.picker.loading`,`Reading the series of every device…`):d.active?s(`history.picker.emptyFiltered`,`No series match these filters.`):s(`history.picker.empty`,`Nothing is recorded yet.`),selection:{selected:i,onChange:e=>{let t=[...e].filter(e=>i.has(e)),n=[...e].filter(e=>!i.has(e));a(new Set([...t,...n].slice(0,24)))},isSelectable:e=>i.has(e.id)||!p,rowLabel:e=>`${u(e)} · ${e.metric}`,pageLabel:s(`history.picker.selectPage`,`Select every series on this page`)}})]})}i();var et=new Set([x.Container]),$=5*6e4;function tt(){let{t:r}=U(),i=T(`device-history`),[a,o]=Oe(),s=t(()=>H(a.getAll(`s`).flatMap(e=>{let t=le(e);return t===null?[]:[t]})),[a]),l=a.get(`window`),d=O(l)?l:`7d`,h=ne(a.get(`range`)),g=(e,t,n)=>{let r=new URLSearchParams;for(let t of H(e))r.append(`s`,de(t));t!==`7d`&&r.set(`window`,t);let i=n===void 0?a.get(`range`):n;t===`custom`&&i&&r.set(`range`,i),o(r,{replace:!0})},y=nt(i===`present`),b=P(d,Date.now(),h),x=P(d,oe(Date.now(),b.to-b.from),h),S=t(()=>Ie(s,y.candidates),[s,y.candidates]),C=t(()=>new Set(s.map(V)),[s]),w=he(),ee=u(),E=f(),D=async()=>{let e=await ee({title:r(`history.page.saveTitle`,`Save as panel`),label:r(`history.page.saveName`,`Panel name`),confirmLabel:r(`history.page.save`,`Save`)});e===null||e.trim()===``||await w.update(t=>pe(t,{id:`panel-${Date.now().toString(36)}`,name:e.trim().slice(0,80),window:d,selection:[...s]}))},j=async(e,t)=>{await E({title:r(`history.page.deleteTitle`,`Delete panel`),message:r(`history.page.deleteMessage`,`The panel "{{name}}" is removed from your account.`,{name:t}),confirmLabel:r(`history.page.delete`,`Delete`),variant:`danger`})&&await w.update(t=>fe(t,e))},M=e=>e===`energy`?r(`history.panels.energy`,`Total energy`):e===`temperatures`?r(`history.panels.temperatures`,`Temperatures by room`):e===`nodes`?r(`history.panels.nodes`,`Cluster nodes`):r(`history.panels.storage`,`Storage locations`);return n(ke,{icon:p,title:r(`history.page.title`,`History`),subtitle:r(`history.page.subtitle`,`What devices, nodes and storage recorded over time, side by side.`),actions:i===`present`?e(v,{size:`sm`,variant:`outline`,onClick:()=>void D(),disabled:s.length===0||!w.writable,children:[n(m,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),r(`history.page.saveTitle`,`Save as panel`)]}):void 0,children:i===`pending`?n(z,{className:`h-64 w-full`}):i===`unknown`?n(L,{title:r(`history.page.presenceUnknownTitle`,`Could not reach the hub`),message:r(`history.page.presenceUnknown`,`The hub did not say whether device history is installed. Try again in a moment.`)}):i===`absent`?n(F,{icon:_,title:r(`history.page.absentTitle`,`Device history is not running on this hub`),description:r(`history.page.absent`,`Nothing is recorded until the device-history system addon is enabled.`)}):e(`div`,{className:`space-y-3 sm:space-y-4`,children:[n(Xe,{enabled:i===`present`}),e(`div`,{className:`flex flex-wrap items-center gap-2`,role:`group`,"aria-label":r(`history.page.panels`,`Panels`),children:[Me.map(e=>n(v,{size:`sm`,variant:`outline`,disabled:y.status!==`ok`,onClick:()=>g(Fe(e,y.candidates),d),children:M(e)},e)),w.value.panels.map(t=>e(`span`,{className:`inline-flex items-center`,children:[n(v,{size:`sm`,variant:`secondary`,onClick:()=>g(t.selection,t.window,null),children:t.name}),n(v,{size:`sm`,variant:`ghost`,"aria-label":r(`history.page.deleteNamed`,`Delete panel {{name}}`,{name:t.name}),onClick:()=>void j(t.id,t.name),disabled:!w.writable,children:n(c,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]},t.id))]}),e(`div`,{className:`grid grid-cols-1 gap-3 sm:gap-4 xl:grid-cols-5`,children:[n(`div`,{className:`min-w-0 xl:col-span-2`,children:n(A,{headingId:`history-picker`,title:r(`history.picker.title`,`Series`),children:n(`div`,{className:`p-2 sm:p-3`,children:y.status===`error`?n(L,{message:y.error}):n($e,{catalog:y.candidates,loading:y.status===`pending`,selected:C,onChange:e=>{let t=s.filter(t=>e.has(V(t))),n=y.candidates.filter(t=>e.has(t.id)&&!C.has(t.id)).map(e=>e.ref);g([...t,...n],d)}})})})}),n(`div`,{className:`min-w-0 xl:col-span-3`,children:n(A,{headingId:`history-overlay`,title:r(`history.page.overlay`,`Overlay`),actions:s.length>0?n(v,{size:`sm`,variant:`ghost`,onClick:()=>g([],d),children:r(`history.page.clear`,`Clear`)}):void 0,children:e(`div`,{className:`p-2 sm:p-3 space-y-3 min-w-0`,children:[n(be,{value:d,onChange:e=>g(s,e),custom:h,onCustomChange:e=>g(s,`custom`,k(e))}),y.status===`pending`&&s.length>0?n(z,{className:`h-64 w-full`}):n(Le,{part:S,window:x}),S.missing.length>0&&y.status===`ok`&&n(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`history.page.missing`,{count:S.missing.length,defaultValue_one:`{{count}} selected series is no longer recorded.`,defaultValue_other:`{{count}} selected series are no longer recorded.`})})]})})})]}),n(at,{})]})})}function nt(e){let{t:n}=U(),r=n(`history.picker.wholeFrame`,`Whole frame`),i=b().trpcClient,o=N({projection:`slim`},{enabled:e}),{nodes:s}=ge(),c=t(()=>(o.data??[]).filter(e=>!et.has(String(e.type))),[o.data]),l=a({queries:c.map(t=>({queryKey:[`device-history`,`listSeries`,t.id],queryFn:()=>i.deviceHistory.listSeries.query({deviceId:t.id}),enabled:e,staleTime:$}))}),u=a({queries:s.map(t=>({queryKey:[`device-history`,`listNodeSeries`,t.id],queryFn:()=>i.deviceHistory.listNodeSeries.query({forNodeId:t.id}),enabled:e,staleTime:$}))}),d=Ce({},{enabled:e,staleTime:$}),f=t(()=>new Map((d?.data??[]).map(e=>[e.id,e.displayName])),[d?.data]),p=l.map(e=>e.data),m=u.map(e=>e.data),h=t(()=>Ae(c.flatMap((e,t)=>{let n=p[t];return n===void 0?[]:[{device:{id:e.id,name:e.name,location:e.location??null},series:n}]}),s.flatMap((e,t)=>{let n=m[t];return n===void 0?[]:[{node:{id:e.id,name:e.name},series:n}]}),e=>{if(e.key!==`addon:pipeline-analytics/occupancy`)return f.get(e.scope)??e.scope;let{zoneId:t,className:n}=S(e.scope),i=t===``?r:t;return n===void 0?i:`${i} · ${n}`}),[c,s,f,[...l,...u].map(e=>e.dataUpdatedAt).join(`,`),r]);return o.status===`error`?{status:`error`,error:o.error.message,candidates:[]}:{status:o.status===`pending`||l.some(e=>e.isPending)||u.some(e=>e.isPending)?`pending`:`ok`,error:``,candidates:h}}var rt=`device-history`,it=`device-history`;function at(){let{t}=U(),r=b();return n(A,{headingId:`history-retention`,icon:C,title:t(`history.retention.title`,`Retention`),children:e(`div`,{className:`${s} space-y-3`,children:[n(`p`,{className:y,children:t(`history.retention.hint`,`How long each resolution of the recorded history is kept.`)}),n(re,{trpc:r.trpcClient,addonId:rt,cap:it,scope:`cluster`,bare:!0})]})})}export{tt as HistoryPage};
1
+ import{C as e,K as t,S as n,Y as r,et as i,i 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-CEyXHAdg.js";import{D as s,Gt as c,Oo as l,_t as u,hr as d,ht as f,ka as p,lr as m,oi as h,xn as g,yi as _,yt as v,z as y,zt as b}from"./player-overlays-Cs69NgAR.js";import{Nc as x,ji as S}from"./src-BwDSKCnh.js";import{g as C}from"./terminal-BncJ-1sF.js";import{$a as w,$i as ee,Am as T,An as E,Cn as D,Dn as O,En as k,Gr as A,Jr as j,Ma as M,Mc as N,On as P,Pa as F,Sn as te,Tn as ne,Vi as re,Yr as I,Za as L,_n as ie,aa as ae,an as oe,ao as se,cn as ce,co as R,dn as le,ea as ue,eo as z,fn as de,fo as B,gn as fe,hn as pe,ia as me,in as he,jm as ge,jr as _e,kn as ve,kr as ye,ln as be,mn as V,nc as xe,on as Se,op as Ce,pn as H,ra as we,rc as Te,ta as Ee,wn as De}from"./src-Bb9LsNcW.js";import{p as Oe}from"./chunk-4ZMWKKQ3-BCeNTgXs.js";import{t as U}from"./useTranslation-uIxPZ_3N.js";import{t as ke}from"./AdminPage-Bd8R8RtF.js";i();function W(e,t){return e.scope===``?e.displayName:`${e.displayName} · ${t?.(e)??e.scope}`}function Ae(e,t,n){let r=[];for(let{device:t,series:i}of e)for(let e of i){let i={subject:{kind:`device`,deviceId:t.id},key:e.key,scope:e.scope};r.push({id:V(i),ref:i,info:e,subjectName:t.name,location:t.location??``,nodeId:``,metric:W(e,n)})}for(let{node:e,series:i}of t)for(let t of i){let i={subject:{kind:`node`,nodeId:e.id},key:t.key,scope:t.scope};r.push({id:V(i),ref:i,info:t,subjectName:e.name,location:``,nodeId:e.id,metric:W(t,n)})}return r}function je(e){return[e.subjectName,e.location,e.metric,e.info.key,e.info.unit??``,e.nodeId].join(` `)}function G(e,t,n){if(e.ref.subject.kind!==`device`||t===null)return e.subjectName;let r=t.byId.get(e.ref.subject.deviceId);return r===void 0?e.subjectName:se(r,`compact`,t,n)}var Me=[`energy`,`temperatures`,`nodes`,`storage`],Ne=new Set([`cap:temperature-sensor.temperature`,`cap:climate-control.currentTemp`]),K=[`addon:metrics-native/node-cpu-percent`,`addon:metrics-native/node-memory-percent`],Pe=`addon:storage-orchestrator/location-used-percent`;function Fe(e,t){let n=(e,n)=>{let r=t.filter(e);return H((n?[...r].sort(n):r).map(e=>e.ref))};switch(e){case`energy`:return n(e=>e.ref.subject.kind===`device`&&e.info.key===`derived:energy.kwh`);case`temperatures`:return n(e=>e.ref.subject.kind===`device`&&Ne.has(e.info.key)&&e.info.scope===``,(e,t)=>e.location.localeCompare(t.location)||e.subjectName.localeCompare(t.subjectName));case`nodes`:return n(e=>e.ref.subject.kind===`node`&&K.includes(e.info.key)&&e.info.scope===``,(e,t)=>K.indexOf(e.info.key)-K.indexOf(t.info.key)||e.subjectName.localeCompare(t.subjectName));case`storage`:return n(e=>e.ref.subject.kind===`node`&&e.info.key===Pe)}}function Ie(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=[],a=[],o=[];for(let t of H(e)){let e=n.get(V(t));if(e===void 0){o.push(t);continue}e.info.key===`derived:energy.kwh`?a.push(e):e.info.kind===`boolean`||e.info.kind===`enum`?i.push(e):r.push(e)}return{lines:r,states:i,energy:a,missing:o}}function q(e){return e.subject.kind===`device`?{deviceId:e.subject.deviceId,key:e.key,scope:e.scope}:{forNodeId:e.subject.nodeId,key:e.key,scope:e.scope}}var J=`history-page`;function Le({part:r,window:i}){let{t:a}=U(),o=l(),s=B(),c=R(),u=e=>`${G(e,s,c)} · ${e.metric}`,d=t(()=>[...r.lines,...r.states,...r.energy],[r]),f=ce(t(()=>d.map(e=>q(e.ref)),[d]),i,!1),m=e=>f.status===`ok`?f.data.current.get(Se(q(e.ref))):void 0,h=e=>{let t=m(e);return t?.ok?t.result:void 0};if(d.length===0)return n(F,{icon:p,title:a(`history.page.emptyTitle`,`Pick series to compare`),description:a(`history.page.emptyHint`,`Choose up to 24 series on the left, or start from a panel above.`)});if(f.status===`error`)return n(L,{title:a(`history.page.readFailed`,`History could not be read`),message:f.error});let g=f.status===`pending`,_=d.map(e=>({c:e,e:m(e)})).filter(e=>e.e?.ok===!1),v=r.lines.map((e,t)=>{let n=h(e),r=D(e.info,n,i.from);return{id:e.id,label:u(e),unit:e.info.unit,colorIndex:t,points:r.points,gapMs:r.gapMs,interpolation:r.held&&n?.resolution===`raw`?`step`:`linear`}}),y=r.states.map((e,t)=>{let n=De(e.info,h(e),i.from,i.to),r=ie(e.info.key,o);return{id:e.id,label:u(e),kind:e.info.kind===`boolean`?`boolean`:`enum`,colorIndex:e.info.kind===`boolean`?t:0,states:n.states,segments:n.segments,totals:n.totals,stateLabel:e.info.kind===`boolean`?e=>e===`true`?r.on:r.off:void 0}}),b=r.energy.map(e=>({c:e,...te(h(e))})),x=b[0]?.bucketMs??36e5,S=[...new Set(b.flatMap(e=>e.buckets.map(e=>e.t)))].sort((e,t)=>e-t).map(e=>({t:e,values:b.map(t=>t.buckets.find(t=>t.t===e)?.values[0]??null)}));return e(`div`,{className:`space-y-5 min-w-0`,children:[_.length>0&&n(L,{title:a(`history.page.someFailed`,`Some series could not be read`),message:_.map(e=>`${u(e.c)}: ${e.e.error}`).join(` · `)}),v.length>0&&n(ve,{title:a(`history.page.lines`,`Measurements`),series:v,range:i,height:260,syncKey:J,reserveRightAxis:!0,pending:g}),b.length>0&&n(M,{title:a(`history.page.energy`,`Energy`),layers:b.map((e,t)=>({id:e.c.id,label:G(e.c,s,c),colorIndex:t})),buckets:S,bucketMs:x,range:i,unit:`kWh`,showTotal:!0,height:160,syncKey:J,reserveRightAxis:!0,pending:g}),y.length>0&&n(E,{title:y.length===1?y[0]?.label??``:a(`history.page.states`,`States`),rows:y,range:i,syncKey:J,reserveRightAxis:!0,pending:g})]})}function Re(e,t){let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}async function ze(e,t){let n=[];for(let r of Re(e,50))try{let{results:e}=await t(r),i=new Map(e.map(e=>[e.seriesId,e]));for(let e of r)n.push(i.get(e)??{seriesId:e,ok:!1,reason:`not-found`})}catch(e){let t=e instanceof Error?e.message:String(e);for(let e of r)n.push({seriesId:e,ok:!1,reason:`request-failed`,message:t})}return n}function Y(e){return e.raw+e[`5m`]+e[`1h`]+e[`1d`]}function Be(e){return e.reduce((e,t)=>t.ok?{...e,deleted:e.deleted+1,points:e.points+Y(t.deleted)}:{...e,refused:e.refused+1},{deleted:0,refused:0,points:0})}function Ve(e,t){let n=new Map(e.map(e=>[e.seriesId,e]));return t.flatMap(e=>{let t=n.get(e.seriesId);return t===void 0?[]:[{series:t,outcome:e}]})}var X=e=>new Date(e).toLocaleDateString(void 0,{dateStyle:`short`});function Z(e,t,n){let r=t.get(e.deviceId);return r===void 0?e.reason===`device-gone`?n(`history.orphans.deviceRemoved`,`#{{id}} (removed)`,{id:e.deviceId}):n(`history.orphans.deviceId`,`#{{id}}`,{id:e.deviceId}):r}function Q(e){let t=e.displayName??e.key;return e.scope===``?t:`${t} · ${e.scope}`}function He(t,r,i){return{mobile:`primary`,key:`series`,header:i(`history.orphans.colSeries`,`Series`),render:a=>{let o=t(a);return e(`div`,{className:`min-w-0 max-w-[16rem]`,children:[n(`div`,{className:`truncate text-foreground`,title:o.key,children:Q(o)}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:Z(o,r,i)})]})},sortValue:e=>`${Z(t(e),r,i)} ${Q(t(e))}`}}var Ue=[`raw`,`5m`,`1h`,`1d`];function We(e,t){return e===`raw`?t(`history.orphans.colRaw`,`Raw points`):e===`5m`?t(`history.orphans.col5m`,`5 min`):e===`1h`?t(`history.orphans.col1h`,`1 h`):t(`history.orphans.col1d`,`1 day`)}function Ge(t,r){return[He(e=>e,t,r),{mobile:`detail`,key:`reason`,header:r(`history.orphans.colReason`,`Reason`),render:t=>e(`div`,{className:`flex flex-col items-start gap-0.5`,children:[n(w,{variant:t.reason===`device-gone`?`warning`:`neutral`,className:`text-[10px]`,children:t.reason===`device-gone`?r(`history.orphans.deviceGone`,`Device removed`):r(`history.orphans.undeclared`,`No longer declared`)}),t.missingSince!==null&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:r(`history.orphans.since`,`since {{date}}`,{date:X(t.missingSince)})})]}),sortValue:e=>e.reason},{mobile:`hidden`,key:`span`,header:r(`history.orphans.colSpan`,`Recorded`),render:t=>e(`span`,{className:`tabular-nums text-foreground-muted`,children:[X(t.firstTs),` → `,X(t.lastTs)]}),sortValue:e=>e.lastTs},...Ue.map(e=>({mobile:`hidden`,key:`rows-${e}`,header:We(e,r),align:`right`,render:t=>n(`span`,{className:`tabular-nums text-foreground-muted`,children:t.rows[e].toLocaleString()}),sortValue:t=>t.rows[e]}))]}function Ke(e,t){if(e.ok)return n(w,{variant:`success`,className:`text-[10px]`,children:t(`history.orphans.deleted`,{count:Y(e.deleted),points:Y(e.deleted).toLocaleString(),defaultValue_one:`Deleted · {{points}} point`,defaultValue_other:`Deleted · {{points}} points`})});let r=e.reason===`request-failed`?t(`history.orphans.requestFailed`,`Not sent: {{message}}`,{message:e.message}):e.reason===`not-orphan`?t(`history.orphans.refusedNotOrphan`,`Kept: no longer orphan`):e.reason===`not-found`?t(`history.orphans.refusedNotFound`,`Already gone`):t(`history.orphans.refusedFailed`,`The hub could not delete it`);return n(w,{variant:e.reason===`not-found`?`neutral`:`warning`,className:`text-[10px]`,children:r})}function qe(e,t){return[He(e=>e.series,e,t),{mobile:`detail`,key:`result`,header:t(`history.orphans.colResult`,`Result`),render:e=>Ke(e.outcome,t),sortValue:e=>+!e.outcome.ok}]}i();function Je({open:i,onClose:a,list:o,deviceNames:s,onDelete:c,onRefresh:l,refreshing:u}){let{t:p}=U(),m=f(),[_,y]=r(new Set),[b,x]=r(!1),[S,C]=r([]),w=t(()=>Ge(s,p),[s,p]),T=t(()=>qe(s,p),[s,p]),E=t(()=>new Set(o.series.map(e=>String(e.seriesId))),[o.series]),D=[..._].filter(e=>E.has(e)).map(Number),O=Be(S.map(e=>e.outcome)),k=async()=>{if(await m({title:p(`history.orphans.confirmTitle`,{count:D.length,defaultValue_one:`Delete {{count}} series`,defaultValue_other:`Delete {{count}} series`}),message:p(`history.orphans.confirmMessage`,`Every recorded point of these series is removed from the hub. This cannot be undone.`),confirmLabel:p(`history.orphans.confirmLabel`,`Delete`),variant:`danger`})){x(!0);try{let e=await ze(D,c);C(Ve(o.series,e)),y(new Set)}finally{x(!1),l()}}};return n(ee,{open:i,onOpenChange:e=>!e&&a(),children:e(Ee,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`orphan-series-dialog`,children:[n(me,{children:n(ae,{children:p(`history.orphans.title`,`Series no longer linked to a device`)})}),e(ue,{className:`space-y-3`,children:[n(`p`,{className:`text-xs text-foreground-muted`,children:p(`history.orphans.intro`,`Nothing records into these series any more: their device was removed, or no capability declares them now. Select the ones to delete.`)}),o.truncated&&e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`orphan-truncated`,children:[n(`p`,{className:`text-xs text-warning`,children:p(`history.orphans.truncated`,`More series are unlinked than are listed here. Delete these, then load the rest.`)}),e(v,{size:`sm`,variant:`outline`,onClick:l,disabled:u,children:[n(d,{className:`h-3 w-3`,"aria-hidden":!0}),p(`history.orphans.loadAgain`,`Load again`)]})]}),S.length>0&&e(`div`,{className:`space-y-2`,"data-testid":`orphan-outcomes`,children:[n(`p`,{className:`text-xs text-foreground`,"aria-live":`polite`,children:p(`history.orphans.summary`,{count:O.deleted,refused:O.refused,points:O.points.toLocaleString(),defaultValue_one:`{{count}} series deleted ({{points}} points), {{refused}} kept.`,defaultValue_other:`{{count}} series deleted ({{points}} points), {{refused}} kept.`})}),n(j,{columns:T,rows:S,rowKey:e=>String(e.series.seriesId),minWidthPx:420,maxBodyHeight:`max-h-[60vh]`,emptyMessage:``})]}),n(j,{columns:w,rows:o.series,rowKey:e=>String(e.seriesId),minWidthPx:760,maxBodyHeight:I,defaultSort:{columnKey:`series`,dir:`asc`},emptyMessage:p(`history.orphans.empty`,`Every series is linked to a device.`),selection:{selected:_,onChange:y,rowLabel:e=>`${Q(e)} — ${Z(e,s,p)}`,pageLabel:p(`history.orphans.selectAll`,`Select every listed series`)}})]}),e(we,{children:[n(`span`,{className:`mr-auto text-[11px] tabular-nums text-foreground`,"aria-live":`polite`,children:p(`history.orphans.selected`,{count:D.length,defaultValue_one:`{{count}} selected`,defaultValue_other:`{{count}} selected`})}),n(v,{variant:`ghost`,size:`sm`,onClick:a,children:p(`history.orphans.close`,`Close`)}),e(v,{variant:`danger`,size:`sm`,disabled:D.length===0||b,onClick:()=>void k(),children:[b?n(h,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):n(g,{className:`h-3 w-3`,"aria-hidden":!0}),p(`history.orphans.deleteSelected`,`Delete selected`)]})]})]})})}i();var Ye=5*6e4;function Xe({enabled:i}){let{t:a}=U(),[s,c]=r(!1),l=Te({},{enabled:i,staleTime:Ye}),u=N({projection:`slim`},{enabled:i}),d=xe(),f=t(()=>new Map((u.data??[]).map(e=>[e.id,e.name])),[u.data]),p=e=>d.mutateAsync({seriesIds:[...e]});if(!i||l.status===`pending`)return null;if(l.status===`error`)return n(L,{variant:`warning`,title:a(`history.orphans.checkFailedTitle`,`Could not check for unlinked series`),message:l.error.message,onRetry:()=>void l.refetch()});let m=l.data;if(m.series.length===0&&!s)return null;let h=m.series.length;return e(o,{children:[h>0&&n(L,{variant:`warning`,message:m.truncated?a(`history.orphans.noticeMore`,{count:h,defaultValue_one:`More than {{count}} series are no longer linked to a device.`,defaultValue_other:`More than {{count}} series are no longer linked to a device.`}):a(`history.orphans.notice`,{count:h,defaultValue_one:`{{count}} series is no longer linked to a device.`,defaultValue_other:`{{count}} series are no longer linked to a device.`}),action:n(v,{size:`sm`,variant:`outline`,onClick:()=>c(!0),children:a(`history.orphans.review`,`Review`)})}),n(Je,{open:s,onClose:()=>c(!1),list:m,deviceNames:f,onDelete:p,onRefresh:()=>void l.refetch(),refreshing:l.isFetching})]})}i();var Ze=`device`,Qe=`node`;function $e({catalog:r,selected:i,onChange:a,loading:o}){let{t:s}=U(),c=B(),l=R(),u=e=>G(e,c,l),d=ye(r,{searchText:e=>[je(e)],facetGroups:[{id:`subject`,value:e=>e.ref.subject.kind===`device`?Ze:Qe},{id:`room`,value:e=>e.location},{id:`unit`,value:e=>e.info.unit??``}]}),f=t(()=>[{mobile:`primary`,key:`metric`,header:s(`history.picker.series`,`Series`),render:t=>e(`div`,{className:`min-w-0`,children:[n(`div`,{className:`truncate text-foreground`,children:t.metric}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.location===``?u(t):`${u(t)} · ${t.location}`})]}),sortValue:e=>`${e.subjectName} ${e.metric}`},{mobile:`detail`,key:`unit`,header:s(`history.picker.unit`,`Unit`),render:e=>n(`span`,{className:`text-foreground-muted`,children:e.info.unit??`—`}),sortValue:e=>e.info.unit??``}],[s,c,l]),p=i.size>=24;return e(`div`,{className:`space-y-2 min-w-0`,children:[n(_e,{state:d.state,facets:[],groups:[{...d.groups.find(e=>e.id===`subject`)??{id:`subject`,facets:[],selected:[]},label:s(`history.picker.subject`,`Source`),facetLabel:e=>e===Ze?s(`history.picker.devices`,`Devices`):s(`history.picker.nodes`,`Nodes`)},{...d.groups.find(e=>e.id===`room`)??{id:`room`,facets:[],selected:[]},label:s(`history.picker.room`,`Room`),facetLabel:e=>e===``?s(`history.picker.noRoom`,`No room`):e},{...d.groups.find(e=>e.id===`unit`)??{id:`unit`,facets:[],selected:[]},label:s(`history.picker.metricType`,`Unit`),facetLabel:e=>e===``?s(`history.picker.noUnit`,`States & counts`):e}],labels:{searchPlaceholder:s(`history.picker.search`,`Search device, room, metric or node…`),searchLabel:s(`history.picker.searchLabel`,`Search series`),facetsLabel:s(`history.picker.facets`,`Filters`),clearLabel:s(`history.picker.clear`,`Clear`)},onSearch:d.setSearch,onToggleFacet:d.toggleFacet,onToggleGroupFacet:d.toggleGroupFacet,onClear:d.clear}),n(`p`,{className:`text-[10px] text-foreground-subtle`,"aria-live":`polite`,children:s(`history.picker.count`,`{{count}} of {{max}} selected`,{count:i.size,max:24})}),n(j,{columns:f,rows:d.rows,rowKey:e=>e.id,maxBodyHeight:I,pageSize:50,defaultSort:{columnKey:`metric`,dir:`asc`},emptyMessage:o?s(`history.picker.loading`,`Reading the series of every device…`):d.active?s(`history.picker.emptyFiltered`,`No series match these filters.`):s(`history.picker.empty`,`Nothing is recorded yet.`),selection:{selected:i,onChange:e=>{let t=[...e].filter(e=>i.has(e)),n=[...e].filter(e=>!i.has(e));a(new Set([...t,...n].slice(0,24)))},isSelectable:e=>i.has(e.id)||!p,rowLabel:e=>`${u(e)} · ${e.metric}`,pageLabel:s(`history.picker.selectPage`,`Select every series on this page`)}})]})}i();var et=new Set([x.Container]),$=5*6e4;function tt(){let{t:r}=U(),i=T(`device-history`),[a,o]=Oe(),s=t(()=>H(a.getAll(`s`).flatMap(e=>{let t=le(e);return t===null?[]:[t]})),[a]),l=a.get(`window`),d=O(l)?l:`7d`,h=ne(a.get(`range`)),g=(e,t,n)=>{let r=new URLSearchParams;for(let t of H(e))r.append(`s`,de(t));t!==`7d`&&r.set(`window`,t);let i=n===void 0?a.get(`range`):n;t===`custom`&&i&&r.set(`range`,i),o(r,{replace:!0})},y=nt(i===`present`),b=P(d,Date.now(),h),x=P(d,oe(Date.now(),b.to-b.from),h),S=t(()=>Ie(s,y.candidates),[s,y.candidates]),C=t(()=>new Set(s.map(V)),[s]),w=he(),ee=u(),E=f(),D=async()=>{let e=await ee({title:r(`history.page.saveTitle`,`Save as panel`),label:r(`history.page.saveName`,`Panel name`),confirmLabel:r(`history.page.save`,`Save`)});e===null||e.trim()===``||await w.update(t=>pe(t,{id:`panel-${Date.now().toString(36)}`,name:e.trim().slice(0,80),window:d,selection:[...s]}))},j=async(e,t)=>{await E({title:r(`history.page.deleteTitle`,`Delete panel`),message:r(`history.page.deleteMessage`,`The panel "{{name}}" is removed from your account.`,{name:t}),confirmLabel:r(`history.page.delete`,`Delete`),variant:`danger`})&&await w.update(t=>fe(t,e))},M=e=>e===`energy`?r(`history.panels.energy`,`Total energy`):e===`temperatures`?r(`history.panels.temperatures`,`Temperatures by room`):e===`nodes`?r(`history.panels.nodes`,`Cluster nodes`):r(`history.panels.storage`,`Storage locations`);return n(ke,{icon:p,title:r(`history.page.title`,`History`),subtitle:r(`history.page.subtitle`,`What devices, nodes and storage recorded over time, side by side.`),actions:i===`present`?e(v,{size:`sm`,variant:`outline`,onClick:()=>void D(),disabled:s.length===0||!w.writable,children:[n(m,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),r(`history.page.saveTitle`,`Save as panel`)]}):void 0,children:i===`pending`?n(z,{className:`h-64 w-full`}):i===`unknown`?n(L,{title:r(`history.page.presenceUnknownTitle`,`Could not reach the hub`),message:r(`history.page.presenceUnknown`,`The hub did not say whether device history is installed. Try again in a moment.`)}):i===`absent`?n(F,{icon:_,title:r(`history.page.absentTitle`,`Device history is not running on this hub`),description:r(`history.page.absent`,`Nothing is recorded until the device-history system addon is enabled.`)}):e(`div`,{className:`space-y-3 sm:space-y-4`,children:[n(Xe,{enabled:i===`present`}),e(`div`,{className:`flex flex-wrap items-center gap-2`,role:`group`,"aria-label":r(`history.page.panels`,`Panels`),children:[Me.map(e=>n(v,{size:`sm`,variant:`outline`,disabled:y.status!==`ok`,onClick:()=>g(Fe(e,y.candidates),d),children:M(e)},e)),w.value.panels.map(t=>e(`span`,{className:`inline-flex items-center`,children:[n(v,{size:`sm`,variant:`secondary`,onClick:()=>g(t.selection,t.window,null),children:t.name}),n(v,{size:`sm`,variant:`ghost`,"aria-label":r(`history.page.deleteNamed`,`Delete panel {{name}}`,{name:t.name}),onClick:()=>void j(t.id,t.name),disabled:!w.writable,children:n(c,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]},t.id))]}),e(`div`,{className:`grid grid-cols-1 gap-3 sm:gap-4 xl:grid-cols-5`,children:[n(`div`,{className:`min-w-0 xl:col-span-2`,children:n(A,{headingId:`history-picker`,title:r(`history.picker.title`,`Series`),children:n(`div`,{className:`p-2 sm:p-3`,children:y.status===`error`?n(L,{message:y.error}):n($e,{catalog:y.candidates,loading:y.status===`pending`,selected:C,onChange:e=>{let t=s.filter(t=>e.has(V(t))),n=y.candidates.filter(t=>e.has(t.id)&&!C.has(t.id)).map(e=>e.ref);g([...t,...n],d)}})})})}),n(`div`,{className:`min-w-0 xl:col-span-3`,children:n(A,{headingId:`history-overlay`,title:r(`history.page.overlay`,`Overlay`),actions:s.length>0?n(v,{size:`sm`,variant:`ghost`,onClick:()=>g([],d),children:r(`history.page.clear`,`Clear`)}):void 0,children:e(`div`,{className:`p-2 sm:p-3 space-y-3 min-w-0`,children:[n(be,{value:d,onChange:e=>g(s,e),custom:h,onCustomChange:e=>g(s,`custom`,k(e))}),y.status===`pending`&&s.length>0?n(z,{className:`h-64 w-full`}):n(Le,{part:S,window:x}),S.missing.length>0&&y.status===`ok`&&n(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`history.page.missing`,{count:S.missing.length,defaultValue_one:`{{count}} selected series is no longer recorded.`,defaultValue_other:`{{count}} selected series are no longer recorded.`})})]})})})]}),n(at,{})]})})}function nt(e){let{t:n}=U(),r=n(`history.picker.wholeFrame`,`Whole frame`),i=b().trpcClient,o=N({projection:`slim`},{enabled:e}),{nodes:s}=ge(),c=t(()=>(o.data??[]).filter(e=>!et.has(String(e.type))),[o.data]),l=a({queries:c.map(t=>({queryKey:[`device-history`,`listSeries`,t.id],queryFn:()=>i.deviceHistory.listSeries.query({deviceId:t.id}),enabled:e,staleTime:$}))}),u=a({queries:s.map(t=>({queryKey:[`device-history`,`listNodeSeries`,t.id],queryFn:()=>i.deviceHistory.listNodeSeries.query({forNodeId:t.id}),enabled:e,staleTime:$}))}),d=Ce({},{enabled:e,staleTime:$}),f=t(()=>new Map((d?.data??[]).map(e=>[e.id,e.displayName])),[d?.data]),p=l.map(e=>e.data),m=u.map(e=>e.data),h=t(()=>Ae(c.flatMap((e,t)=>{let n=p[t];return n===void 0?[]:[{device:{id:e.id,name:e.name,location:e.location??null},series:n}]}),s.flatMap((e,t)=>{let n=m[t];return n===void 0?[]:[{node:{id:e.id,name:e.name},series:n}]}),e=>{if(e.key!==`addon:pipeline-analytics/occupancy`)return f.get(e.scope)??e.scope;let{zoneId:t,className:n}=S(e.scope),i=t===``?r:t;return n===void 0?i:`${i} · ${n}`}),[c,s,f,[...l,...u].map(e=>e.dataUpdatedAt).join(`,`),r]);return o.status===`error`?{status:`error`,error:o.error.message,candidates:[]}:{status:o.status===`pending`||l.some(e=>e.isPending)||u.some(e=>e.isPending)?`pending`:`ok`,error:``,candidates:h}}var rt=`device-history`,it=`device-history`;function at(){let{t}=U(),r=b();return n(A,{headingId:`history-retention`,icon:C,title:t(`history.retention.title`,`Retention`),children:e(`div`,{className:`${s} space-y-3`,children:[n(`p`,{className:y,children:t(`history.retention.hint`,`How long each resolution of the recorded history is kept.`)}),n(re,{trpc:r.trpcClient,addonId:rt,cap:it,scope:`cluster`,bare:!0})]})})}export{tt as HistoryPage};