@camstack/addon-admin-ui 1.1.44 → 1.1.45

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 (75) hide show
  1. package/dist/assets/{AddLocationWizard-W-dt-zcF.js → AddLocationWizard-Bvw9_2YN.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-BfbidCIk.js → AddonCollectionPage-DLYcF1eI.js} +1 -1
  3. package/dist/assets/{Addons-CiErH07A.js → Addons-BDiRSQCj.js} +1 -1
  4. package/dist/assets/{AdminTabs-DrhpSgcL.js → AdminTabs-CY2rlSZx.js} +1 -1
  5. package/dist/assets/{BrokerForm-BsEdM3IE.js → BrokerForm-DrGabABg.js} +1 -1
  6. package/dist/assets/{Capabilities-B5t7v_pY.js → Capabilities-CcpO8NTn.js} +1 -1
  7. package/dist/assets/{CapabilityBadges-_S1XuALV.js → CapabilityBadges-CYoWl0J1.js} +1 -1
  8. package/dist/assets/{Cluster-CcDlebrP.js → Cluster-CpXN23Iz.js} +1 -1
  9. package/dist/assets/{Dashboard-CMXG2pAs.js → Dashboard-Bo25XR8Q.js} +1 -1
  10. package/dist/assets/{Data-B4QFRILt.js → Data-Blw93_kT.js} +1 -1
  11. package/dist/assets/{DetectionIntelligence-DEFWthMx.js → DetectionIntelligence-Kl1XQi-o.js} +1 -1
  12. package/dist/assets/{DeviceDetail-CDsrMXH5.js → DeviceDetail-BAb02UMT.js} +1 -1
  13. package/dist/assets/{Devices-DYAE6I8E.js → Devices-DcjotJtp.js} +1 -1
  14. package/dist/assets/{EmbedPlayerPage-DtWip1D7.js → EmbedPlayerPage-ilPK8vT0.js} +1 -1
  15. package/dist/assets/{FormBuilder-ctPbkSgx.js → FormBuilder-DmAaqS0P.js} +1 -1
  16. package/dist/assets/{Identity-I201Qzj3.js → Identity-C2h8wn_8.js} +1 -1
  17. package/dist/assets/{IntegrationDetail-BpLmdyV0.js → IntegrationDetail-10_w9sQG.js} +1 -1
  18. package/dist/assets/{Integrations-Ba1Ft6Lg.js → Integrations-AjG9O0Zs.js} +1 -1
  19. package/dist/assets/{Integrations-72vMf_ew.js → Integrations-CU-UBQ8j.js} +1 -1
  20. package/dist/assets/{Logs-OajAHe1T.js → Logs-DkJkJGxW.js} +1 -1
  21. package/dist/assets/{MotionZonesSettings-DnVWhQ3W.js → MotionZonesSettings-DL55VLbI.js} +1 -1
  22. package/dist/assets/{MyAccess-BI02Q775.js → MyAccess-C92RXlCz.js} +1 -1
  23. package/dist/assets/{Network-CbckA9FR.js → Network-DrP265Eb.js} +1 -1
  24. package/dist/assets/{NodeAddonsSettingsPanel-DLV3dQah.js → NodeAddonsSettingsPanel-B-nngyAf.js} +1 -1
  25. package/dist/assets/{NotificationTargets-DPgzOZJj.js → NotificationTargets-DFzihL8u.js} +1 -1
  26. package/dist/assets/{Pipeline-CzL14MLN.js → Pipeline-DcmtJ_a1.js} +1 -1
  27. package/dist/assets/{PrivacyMaskSettings-BF7f56Ma.js → PrivacyMaskSettings-8aXddQXv.js} +1 -1
  28. package/dist/assets/{ProviderIcon-R9NDoXR8.js → ProviderIcon-CJ8-0ZH-.js} +1 -1
  29. package/dist/assets/{ScanNetworkModal-Bkgknqh0.js → ScanNetworkModal-CrN7Gcg1.js} +1 -1
  30. package/dist/assets/{ServerManagement-CiOBwHFm.js → ServerManagement-r1GIGpJa.js} +1 -1
  31. package/dist/assets/{Settings-BJ5JyTmk.js → Settings-IWs_JmTb.js} +1 -1
  32. package/dist/assets/{Showroom-BVOBdodI.js → Showroom-BvK9z4rI.js} +1 -1
  33. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-B9iXARjp.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-D33LJRoa.js} +1 -1
  34. package/dist/assets/{build-cluster-graph-D5l4dXUI.js → build-cluster-graph-9hzchTfD.js} +1 -1
  35. package/dist/assets/circle-check-big-DOB-ecd1.js +1 -0
  36. package/dist/assets/{copy-C4YYit8o.js → copy-B5w123s3.js} +1 -1
  37. package/dist/assets/{dist-_--y0TkY.js → dist-BqJ4ODEV.js} +1 -1
  38. package/dist/assets/{dist-Cc1jotFK.js → dist-bNuNFLZO.js} +1 -1
  39. package/dist/assets/{download-CcmtuTlP.js → download-DWrwa5ZQ.js} +1 -1
  40. package/dist/assets/{hostInit-N8y4wuPR.js → hostInit-Dum3X3mF.js} +1 -1
  41. package/dist/assets/index-BXn17UrG.css +2 -0
  42. package/dist/assets/index-Da74gHj8.js +4 -0
  43. package/dist/assets/{key-round-9Pliwnd3.js → key-round-Bu_8dxr0.js} +1 -1
  44. package/dist/assets/{mf-entry-bootstrap-0-26120332.js → mf-entry-bootstrap-0-13dbf296.js} +2 -2
  45. package/dist/assets/{pencil-CTazAhnk.js → pencil-CMdxyxwT.js} +1 -1
  46. package/dist/assets/{player-overlays-DvECsQcQ.js → player-overlays-BjWq4Lsw.js} +1 -1
  47. package/dist/assets/plus-1uqeoQzi.js +1 -0
  48. package/dist/assets/{radio-Du7Wln2r.js → radio-BIgunYjc.js} +1 -1
  49. package/dist/assets/{refresh-cw-CJ45Ilhx.js → refresh-cw-tNOo1uMj.js} +1 -1
  50. package/dist/assets/remoteEntry-C23sPYAV.js +1 -0
  51. package/dist/assets/{rotate-ccw-W3q0lk1C.js → rotate-ccw-DclQoHZh.js} +1 -1
  52. package/dist/assets/rotate-cw-DLAr4sQa.js +1 -0
  53. package/dist/assets/search-pN6xkGSc.js +1 -0
  54. package/dist/assets/{sparkles-D554Wh_Z.js → sparkles-Oe69VehF.js} +1 -1
  55. package/dist/assets/square-BKeg-u96.js +1 -0
  56. package/dist/assets/{square-check-big-DIp1zufT.js → square-check-big-BbU9Wg7X.js} +1 -1
  57. package/dist/assets/{src-C6jtYpqC.js → src-PqKMUhAl.js} +1 -1
  58. package/dist/assets/{src-B0KmWVsT.js → src-nTmr96zw.js} +4 -4
  59. package/dist/assets/{upload-DXXNcUOb.js → upload-noUat_HJ.js} +1 -1
  60. package/dist/assets/{useDevice-B6x5GJHo.js → useDevice-DWAforOz.js} +1 -1
  61. package/dist/assets/{useEventInvalidation-Dre3P4lQ.js → useEventInvalidation-DEG6y8gC.js} +1 -1
  62. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DNODt-Nr.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-qa0QFz07.js} +2 -2
  63. package/dist/assets/{wifi-BsxKQH3U.js → wifi-BSE6EyYx.js} +1 -1
  64. package/dist/assets/{zap-CJJPiCEM.js → zap-C03h8r1S.js} +1 -1
  65. package/dist/index.html +6 -6
  66. package/dist/server/addon.js +29 -1
  67. package/package.json +1 -1
  68. package/dist/assets/circle-check-big-CXE5SuGj.js +0 -1
  69. package/dist/assets/index-BNTiPmxL.css +0 -2
  70. package/dist/assets/index-DwPiqIa2.js +0 -4
  71. package/dist/assets/plus-bMOzNfod.js +0 -1
  72. package/dist/assets/remoteEntry-DvYnqxQP.js +0 -1
  73. package/dist/assets/rotate-cw-DDj0C8XB.js +0 -1
  74. package/dist/assets/search-CfaoVnI_.js +0 -1
  75. package/dist/assets/square-uC5wQ_s4.js +0 -1
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MotionZonesSettings-DnVWhQ3W.js","assets/player-overlays-DvECsQcQ.js","assets/src-C6jtYpqC.js","assets/schemas-CuE8EXQ7.js","assets/MaskShapeCanvas-pGn6MKOi.js","assets/PrivacyMaskSettings-BF7f56Ma.js"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-Cyuzqnbw.js";import{a as t,i as n,o as r,r as i}from"./virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DNODt-Nr.js";import{t as a}from"./vite-preload-helper-zJ_50EbN.js";import{B as o,C as s,D as c,G as l,I as u,J as d,K as f,L as p,O as m,Q as h,S as g,T as _,U as v,V as y,W as b,X as x,Z as S,a as C,b as w,d as T,j as E,k as D,o as O,q as k,t as A,u as j,v as M,x as N,z as P}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{C as F,D as I,g as L,h as R,w as ee}from"./schemas-CuE8EXQ7.js";import{B as z,C as B,F as V,P as te,R as H,S as U,V as ne,_ as re,a as ie,c as ae,d as oe,f as se,h as W,i as ce,j as le,l as ue,m as de,r as fe,v as pe,w as G,x as me,z as he}from"./src-C6jtYpqC.js";import{A as ge,B as _e,C as ve,D as ye,E as be,F as xe,I as Se,L as Ce,M as we,N as Te,O as Ee,P as De,R as Oe,S as ke,T as Ae,V as je,_ as Me,a as Ne,b as Pe,c as Fe,d as Ie,f as Le,g as K,h as Re,i as ze,j as Be,k as Ve,l as He,m as Ue,n as We,o as Ge,p as Ke,r as qe,s as Je,t as Ye,u as Xe,v as Ze,w as Qe,x as $e,y as et,z as tt}from"./player-overlays-DvECsQcQ.js";import{n as nt,r as rt,t as it}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.js-D9-wIasd.js";import{n as at,t as ot}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-DstpX0yz.js";import{T as st,b as ct,g as lt,k as ut,o as dt,x as ft}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_client__loadShare__.js-CSJxMxg6.js";import{n as pt,t as mt}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DkcC9IVF.js";var ht={frigate:`#3b82f6`,scrypted:`#a855f7`,reolink:`#06b6d4`,homeAssistant:`#22d3ee`,rtsp:`#78716c`},gt={primary:`#f59e42`,primaryForeground:`#0c0a09`,background:`#0c0a09`,backgroundElevated:`#1c1917`,surface:`#1c1917`,surfaceHover:`#292524`,border:`#292524`,borderSubtle:`#1c1917`,foreground:`#fafaf9`,foregroundMuted:`#a8a29e`,foregroundSubtle:`#78716c`,foregroundDisabled:`#57534e`,success:`#4ade80`,warning:`#fbbf24`,danger:`#f87171`,info:`#60a5fa`,provider:ht},_t={primary:`#e67e22`,primaryForeground:`#ffffff`,background:`#fafaf9`,backgroundElevated:`#ffffff`,surface:`#f5f5f4`,surfaceHover:`#e7e5e4`,border:`#d6d3d1`,borderSubtle:`#e7e5e4`,foreground:`#1c1917`,foregroundMuted:`#57534e`,foregroundSubtle:`#78716c`,foregroundDisabled:`#a8a29e`,success:`#16a34a`,warning:`#d97706`,danger:`#dc2626`,info:`#2563eb`,provider:ht},vt={colors:{dark:gt,light:_t},spacing:{xs:2,sm:4,md:8,lg:12,xl:16,"2xl":24,"3xl":32},radius:{sm:4,md:6,lg:8,xl:12},typography:{fontFamily:`-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`,sizes:{xs:{fontSize:10,lineHeight:14},sm:{fontSize:11,lineHeight:16},base:{fontSize:12,lineHeight:18},lg:{fontSize:13,lineHeight:18},xl:{fontSize:14,lineHeight:20},"2xl":{fontSize:16,lineHeight:22},"3xl":{fontSize:20,lineHeight:28}},weights:{regular:400,medium:500,semibold:600,bold:700}},table:{rowHeight:28,headerHeight:24,cellPaddingX:8,cellPaddingY:6},sidebar:{width:176,itemHeight:28,iconSize:14}};function yt(e,t){let n={...e};for(let r in t){let i=t[r],a=e[r];i!==void 0&&typeof i==`object`&&i&&!Array.isArray(i)&&typeof a==`object`&&a?n[r]=yt(a,i):i!==void 0&&(n[r]=i)}return n}function bt(e){return e?yt(structuredClone(vt),e):structuredClone(vt)}function xt(e){return e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function St(e){return`--color-${xt(e)}`}function Ct(e){let t=[];for(let[n,r]of Object.entries(e))n!==`provider`&&t.push(` ${St(n)}: ${r};`);return t.join(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MotionZonesSettings-DL55VLbI.js","assets/player-overlays-BjWq4Lsw.js","assets/src-PqKMUhAl.js","assets/schemas-CuE8EXQ7.js","assets/MaskShapeCanvas-pGn6MKOi.js","assets/PrivacyMaskSettings-8aXddQXv.js"])))=>i.map(i=>d[i]);
2
+ import{r as e}from"./rolldown-runtime-Cyuzqnbw.js";import{a as t,i as n,o as r,r as i}from"./virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-qa0QFz07.js";import{t as a}from"./vite-preload-helper-zJ_50EbN.js";import{B as o,C as s,D as c,G as l,I as u,J as d,K as f,L as p,O as m,Q as h,S as g,T as _,U as v,V as y,W as b,X as x,Z as S,a as C,b as w,d as T,j as E,k as D,o as O,q as k,t as A,u as j,v as M,x as N,z as P}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{C as F,D as I,g as L,h as R,w as ee}from"./schemas-CuE8EXQ7.js";import{B as z,C as B,F as V,P as te,R as H,S as U,V as ne,_ as re,a as ie,c as ae,d as oe,f as se,h as W,i as ce,j as le,l as ue,m as de,r as fe,v as pe,w as G,x as me,z as he}from"./src-PqKMUhAl.js";import{A as ge,B as _e,C as ve,D as ye,E as be,F as xe,I as Se,L as Ce,M as we,N as Te,O as Ee,P as De,R as Oe,S as ke,T as Ae,V as je,_ as Me,a as Ne,b as Pe,c as Fe,d as Ie,f as Le,g as K,h as Re,i as ze,j as Be,k as Ve,l as He,m as Ue,n as We,o as Ge,p as Ke,r as qe,s as Je,t as Ye,u as Xe,v as Ze,w as Qe,x as $e,y as et,z as tt}from"./player-overlays-BjWq4Lsw.js";import{n as nt,r as rt,t as it}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.js-D9-wIasd.js";import{n as at,t as ot}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-DstpX0yz.js";import{T as st,b as ct,g as lt,k as ut,o as dt,x as ft}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_client__loadShare__.js-CSJxMxg6.js";import{n as pt,t as mt}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DkcC9IVF.js";var ht={frigate:`#3b82f6`,scrypted:`#a855f7`,reolink:`#06b6d4`,homeAssistant:`#22d3ee`,rtsp:`#78716c`},gt={primary:`#f59e42`,primaryForeground:`#0c0a09`,background:`#0c0a09`,backgroundElevated:`#1c1917`,surface:`#1c1917`,surfaceHover:`#292524`,border:`#292524`,borderSubtle:`#1c1917`,foreground:`#fafaf9`,foregroundMuted:`#a8a29e`,foregroundSubtle:`#78716c`,foregroundDisabled:`#57534e`,success:`#4ade80`,warning:`#fbbf24`,danger:`#f87171`,info:`#60a5fa`,provider:ht},_t={primary:`#e67e22`,primaryForeground:`#ffffff`,background:`#fafaf9`,backgroundElevated:`#ffffff`,surface:`#f5f5f4`,surfaceHover:`#e7e5e4`,border:`#d6d3d1`,borderSubtle:`#e7e5e4`,foreground:`#1c1917`,foregroundMuted:`#57534e`,foregroundSubtle:`#78716c`,foregroundDisabled:`#a8a29e`,success:`#16a34a`,warning:`#d97706`,danger:`#dc2626`,info:`#2563eb`,provider:ht},vt={colors:{dark:gt,light:_t},spacing:{xs:2,sm:4,md:8,lg:12,xl:16,"2xl":24,"3xl":32},radius:{sm:4,md:6,lg:8,xl:12},typography:{fontFamily:`-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`,sizes:{xs:{fontSize:10,lineHeight:14},sm:{fontSize:11,lineHeight:16},base:{fontSize:12,lineHeight:18},lg:{fontSize:13,lineHeight:18},xl:{fontSize:14,lineHeight:20},"2xl":{fontSize:16,lineHeight:22},"3xl":{fontSize:20,lineHeight:28}},weights:{regular:400,medium:500,semibold:600,bold:700}},table:{rowHeight:28,headerHeight:24,cellPaddingX:8,cellPaddingY:6},sidebar:{width:176,itemHeight:28,iconSize:14}};function yt(e,t){let n={...e};for(let r in t){let i=t[r],a=e[r];i!==void 0&&typeof i==`object`&&i&&!Array.isArray(i)&&typeof a==`object`&&a?n[r]=yt(a,i):i!==void 0&&(n[r]=i)}return n}function bt(e){return e?yt(structuredClone(vt),e):structuredClone(vt)}function xt(e){return e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function St(e){return`--color-${xt(e)}`}function Ct(e){let t=[];for(let[n,r]of Object.entries(e))n!==`provider`&&t.push(` ${St(n)}: ${r};`);return t.join(`
3
3
  `)}function wt(e){let t=[];for(let[n,r]of Object.entries(e))t.push(` --color-provider-${xt(n)}: ${r};`);return t.join(`
4
4
  `)}function Tt(e){let t=[];for(let[n,r]of Object.entries(e))t.push(` --spacing-${n}: ${r}px;`);return t.join(`
5
5
  `)}function Et(e){let t=[];for(let[n,r]of Object.entries(e))t.push(` --radius-${n}: ${r}px;`);return t.join(`
@@ -61,7 +61,7 @@ ${n.replace(/^ {2}/gm,` `)}
61
61
  @media (prefers-reduced-motion: reduce) {
62
62
  .acv-streak, .acv-fan, .acv-sway-wrap, .acv-glow, .acv-swing { animation: none !important; }
63
63
  }
64
- `;function tD({trpc:e,deviceId:t,layout:n,optimistic:r}){let{cap:i,slice:a,available:o}=Q({trpc:e,deviceId:t,cap:e=>e.climateControl,slice:e=>e.state.climateControl}),{display:s,applyOptimistic:c}=vu(a,{enabled:r??!0});if(i===void 0||s===void 0)return null;let l=!o;if(n===`compact`)return g(`div`,{"data-mode":s.mode,className:`inline-flex items-center gap-1`,children:[N(`span`,{className:X(`text-xs tabular-nums font-medium`,UE[s.mode]),children:s.target===null?s.currentTemp===null?null:g(`span`,{className:`text-foreground-subtle`,children:[s.currentTemp,`°`]}):g(w,{children:[s.target,`°`,s.currentTemp!==null&&g(`span`,{className:`text-foreground-subtle font-normal`,children:[` `,`(`,s.currentTemp,`°)`]})]})}),s.target!==null&&g(w,{children:[N(`button`,{type:`button`,"aria-label":`Decrease target`,disabled:l,onClick:e=>{if(e.stopPropagation(),!l&&s.target!==null){let e=s.target-1;c({target:e}),i.setTarget({target:e})}},className:X(`inline-flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors text-xs`,l&&`opacity-40 cursor-not-allowed`),children:`−`}),N(`button`,{type:`button`,"aria-label":`Increase target`,disabled:l,onClick:e=>{if(e.stopPropagation(),!l&&s.target!==null){let e=s.target+1;c({target:e}),i.setTarget({target:e})}},className:X(`inline-flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors text-xs`,l&&`opacity-40 cursor-not-allowed`),children:`+`})]}),N(`select`,{"aria-label":`Mode`,value:s.mode,disabled:l,onChange:e=>{e.stopPropagation();let t=s.availableModes.find(t=>t===e.target.value);!l&&t&&(c({mode:t}),i.setMode({mode:t}))},className:X(`bg-transparent px-0.5 text-xs text-foreground-subtle hover:text-foreground cursor-pointer`,l&&`opacity-40 cursor-not-allowed`),children:s.availableModes.map(e=>N(`option`,{value:e,children:KE[e]},e))})]});let u=JE[s.mode],d=s.mode!==`off`,f=QE(s.preset),p=s.preset===`turbo`,m=Math.max(.55,$E(s.fanMode)*(p?.6:1)),h=s.swingVertical!==null,_=s.swingHorizontal!==null,v=d&&(s.swingVertical===!0||s.swingHorizontal===!0);return g(`div`,{"data-mode":s.mode,className:X(`relative flex flex-col items-stretch gap-2.5 overflow-hidden rounded-lg border p-3 transition-colors`,HE[s.mode]),children:[N(`style`,{children:eD}),g(`div`,{className:`relative z-10 flex flex-col items-center justify-center gap-1 overflow-hidden rounded-lg border border-border/50 bg-surface/30 px-3 py-3`,children:[N(`div`,{className:`pointer-events-none absolute inset-0 opacity-60`,children:N(sD,{mode:s.mode,accent:u,periodSec:m,swaying:v})}),N(`div`,{className:`pointer-events-none absolute inset-0 bg-gradient-to-b from-surface/50 via-transparent to-surface/50`}),d&&N(`span`,{"aria-hidden":!0,className:`acv-glow pointer-events-none absolute left-1/2 top-1/2 h-16 w-16 -translate-x-1/2 -translate-y-1/2 rounded-full blur-2xl`,style:{background:u,animation:`acv-glow 3.2s ease-in-out infinite`}}),g(`div`,{className:`relative z-10 flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-wide`,style:{color:u},children:[N(rD,{mode:s.mode,className:`h-3.5 w-3.5`}),KE[s.mode],s.currentTemp!==null&&g(`span`,{className:`normal-case text-foreground-subtle`,children:[`· `,s.currentTemp,`° now`]}),s.currentHumidity!==null&&g(`span`,{className:`inline-flex items-center gap-0.5 normal-case text-foreground-subtle`,children:[N(Qi,{className:`h-3 w-3`}),s.currentHumidity,`%`]})]}),s.target===null?g(`div`,{className:`relative z-10 flex items-baseline gap-0.5`,children:[N(`span`,{className:`text-4xl font-bold leading-none tabular-nums text-foreground`,children:s.currentTemp??`—`}),N(`span`,{className:`text-lg text-foreground-subtle`,children:`°`})]}):g(w,{children:[g(`div`,{className:`relative z-10 flex items-center gap-3`,children:[N(aD,{label:`Decrease target`,symbol:`−`,disabled:l,onClick:()=>{if(l||s.target===null)return;let e=s.target-1;c({target:e}),i.setTarget({target:e})}}),g(`div`,{className:`flex items-baseline gap-0.5`,children:[N(`span`,{className:`text-4xl font-bold leading-none tabular-nums`,style:{color:u},children:s.target}),N(`span`,{className:`text-lg text-foreground-subtle`,children:`°`})]}),N(aD,{label:`Increase target`,symbol:`+`,disabled:l,onClick:()=>{if(l||s.target===null)return;let e=s.target+1;c({target:e}),i.setTarget({target:e})}})]}),N(`div`,{className:`relative z-10 w-36`,children:N(oD,{value:s.target,min:YE,max:XE,accent:u})})]})]}),g(`div`,{className:`relative z-10 grid grid-cols-3 gap-2`,children:[N(iD,{label:`Mode`,icon:N(`span`,{style:{color:u},className:`flex`,children:N(rD,{mode:s.mode,className:`h-4 w-4`})}),value:s.mode,options:s.availableModes.map(e=>({value:e,label:KE[e]})),disabled:l,onChange:e=>{let t=s.availableModes.find(t=>t===e);t&&(c({mode:t}),i.setMode({mode:t}))}}),s.availableFanModes.length>0&&N(iD,{label:`Fan`,icon:N(es,{className:`h-4 w-4 text-sky-500`}),value:s.fanMode,options:s.availableFanModes.map(e=>({value:e,label:ZE(e)})),disabled:l,onChange:e=>{c({fanMode:e}),i.setFanMode({fanMode:e})}}),s.availablePresets.length>0&&N(iD,{label:`Preset`,icon:N(f,{className:`h-4 w-4 text-emerald-500`}),value:s.preset,options:s.availablePresets.map(e=>({value:e,label:ZE(e)})),disabled:l,onChange:e=>{c({preset:e}),i.setPreset({preset:e})}})]}),(h||_)&&N(nD,{label:`Swing`,children:g(`div`,{className:`grid grid-cols-2 gap-1`,children:[h&&N(lD,{axis:`vertical`,on:s.swingVertical??!1,busy:l,onToggle:e=>{c({swingVertical:e}),i.setSwingVertical({on:e})}}),_&&N(lD,{axis:`horizontal`,on:s.swingHorizontal??!1,busy:l,onToggle:e=>{c({swingHorizontal:e}),i.setSwingHorizontal({on:e})}})]})})]})}function nD({label:e,children:t}){return g(`div`,{className:`relative z-10 flex flex-col gap-1`,children:[N(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:e}),t]})}function rD({mode:e,className:t}){let n=qE[e];return N(n,{className:t,"aria-hidden":!0})}function iD({label:e,icon:t,value:n,options:r,disabled:i,onChange:a}){return g(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[N(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:e}),g(`div`,{className:X(`flex items-center gap-1 overflow-hidden rounded-lg border border-border/60 bg-surface-subtle px-1.5 py-1.5`,i&&`opacity-40`),children:[N(`span`,{className:`flex shrink-0`,children:t}),N(`select`,{"aria-label":e,value:n,disabled:i,onChange:e=>{e.stopPropagation(),i||a(e.target.value)},className:`min-w-0 flex-1 cursor-pointer appearance-none truncate bg-transparent text-xs font-medium text-foreground outline-none`,children:r.map(e=>N(`option`,{value:e.value,children:e.label},e.value))}),N(Re,{className:`h-3 w-3 shrink-0 text-foreground-subtle`})]})]})}function aD({label:e,symbol:t,disabled:n,onClick:r}){return N(`button`,{type:`button`,"aria-label":e,disabled:n,onClick:r,className:X(`flex h-8 w-8 shrink-0 items-center justify-center rounded-full border border-border bg-surface text-lg leading-none text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground active:scale-95`,n&&`opacity-40 cursor-not-allowed`),children:t})}function oD({value:e,min:t,max:n,accent:r}){let i=`${Math.min(1,Math.max(0,(e-t)/(n-t)))*100}%`;return g(`div`,{className:`mt-2 w-full`,children:[g(`div`,{className:`relative h-1.5 w-full rounded-full bg-surface-subtle`,children:[N(`div`,{className:`absolute inset-y-0 left-0 rounded-full`,style:{width:i,background:r}}),N(`div`,{className:`absolute top-1/2 h-3 w-3 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-surface shadow`,style:{left:i,background:r}})]}),g(`div`,{className:`mt-0.5 flex justify-between text-[9px] tabular-nums text-foreground-subtle`,children:[g(`span`,{children:[t,`°`]}),g(`span`,{children:[n,`°`]})]})]})}function sD({mode:e,accent:t,periodSec:n,swaying:r}){let i=[0,1,2,3,4,5],a=e===`heat`,o=e===`dry`;return N(`div`,{"aria-hidden":!0,className:`absolute inset-0 overflow-hidden`,children:e===`off`?N(`div`,{className:`flex h-full items-center justify-center gap-2 opacity-30`,children:i.map(e=>N(`span`,{className:`h-8 w-1 rounded-full bg-foreground-subtle opacity-40`},e))}):e===`fan_only`?N(`div`,{className:`flex h-full items-center justify-center`,children:N(cD,{color:t,periodSec:Math.max(.5,n*.7),size:56})}):N(`div`,{className:X(`acv-sway-wrap absolute inset-0`,r&&`acv-sway`),style:r?{animation:`acv-sway 2.6s ease-in-out infinite`}:void 0,children:i.map(e=>N(`span`,{className:`acv-streak absolute rounded-full`,style:{left:`${8+e*15}%`,width:o?`0.4rem`:`0.3rem`,height:o?`0.4rem`:`1.9rem`,background:t,boxShadow:`0 0 6px ${t}`,animationName:a?`acv-rise`:`acv-fall`,animationTimingFunction:`linear`,animationIterationCount:`infinite`,animationDuration:`${n}s`,animationDelay:`${e%3*(n/3)+e*.05}s`}},e))})})}function cD({color:e,periodSec:t,size:n}){return g(`svg`,{width:n,height:n,viewBox:`0 0 100 100`,className:`acv-fan`,style:{animation:`acv-spin ${t}s linear infinite`,transformOrigin:`50% 50%`},"aria-hidden":!0,children:[[0,120,240].map(t=>N(`path`,{d:`M50 50 C 58 30, 78 26, 84 12 C 66 20, 54 34, 50 50 Z`,fill:e,opacity:.85,transform:`rotate(${t} 50 50)`},t)),N(`circle`,{cx:`50`,cy:`50`,r:`7`,fill:e})]})}function lD({axis:e,on:t,busy:n,onToggle:r}){let i=e===`vertical`?`Vertical`:`Horizontal`,a=e===`vertical`?Ua:Ha,o=e===`vertical`?`acv-swing-v`:`acv-swing-h`;return g(`button`,{type:`button`,"aria-label":`${i} swing`,"aria-pressed":t,disabled:n,onClick:()=>{n||r(!t)},className:X(`flex items-center justify-center gap-2 rounded-lg border px-2 py-1.5 text-xs font-medium transition-colors`,t?`border-transparent bg-indigo-400 text-indigo-950 shadow-sm`:`border-border/60 bg-surface-subtle text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,n&&`opacity-40 cursor-not-allowed`),children:[N(a,{className:`acv-swing h-4 w-4`,"aria-hidden":!0,style:t?{animation:`${o} 1.4s ease-in-out infinite`}:void 0}),i]})}var uD={playing:`border-green-400 bg-green-50 dark:bg-green-950`,paused:`border-amber-400 bg-amber-50 dark:bg-amber-950`,buffering:`border-blue-400 bg-blue-50 dark:bg-blue-950`,on:`border-slate-400 bg-slate-50 dark:bg-slate-950`,idle:`border-slate-400 bg-slate-50 dark:bg-slate-950`,off:`border-zinc-300 bg-zinc-50 dark:bg-zinc-900`,standby:`border-zinc-300 bg-zinc-50 dark:bg-zinc-900`},dD={playing:`bg-green-500`,paused:`bg-amber-400`,buffering:`bg-blue-400`,on:`bg-slate-400`,idle:`bg-slate-400`,off:`bg-zinc-300`,standby:`bg-zinc-300`},fD=[`off`,`all`,`one`];function pD(e){return fD.includes(e)}var mD={off:`Off`,all:`All`,one:`One`};function hD(e){return e===`playing`||e===`buffering`?`pause`:`play`}function gD({trpc:e,deviceId:t,features:n,layout:r,optimistic:i}){let{cap:a,slice:o,available:s}=Q({trpc:e,deviceId:t,cap:e=>e.mediaPlayer,slice:e=>e.state.mediaPlayer}),{display:c,applyOptimistic:l}=vu(o,{enabled:i??!0});if(c===void 0)return null;let u=!s,d=hD(c.state);return g(`div`,{"data-state":c.state,className:X(`inline-flex items-center gap-2 rounded border px-2 py-1 transition-colors`,uD[c.state],r===`full`&&`flex-col items-stretch gap-3`),children:[g(`div`,{className:`inline-flex items-center gap-2`,children:[N(`span`,{role:`status`,"aria-label":c.state,className:X(`inline-block h-2 w-2 rounded-full flex-shrink-0`,dD[c.state])}),N(`button`,{type:`button`,"aria-label":d===`play`?`Play`:`Pause`,disabled:u,onClick:e=>{e.stopPropagation(),!u&&(d===`play`?(l({state:`playing`}),a?.play({})):(l({state:`paused`}),a?.pause({})))},className:X(`inline-flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors text-xs`,u&&`opacity-40 cursor-not-allowed`),children:d===`play`?`▶`:`⏸`})]}),r===`full`&&g(w,{children:[g(`div`,{className:`inline-flex items-center gap-1`,children:[N(`button`,{type:`button`,"aria-label":`Previous`,disabled:u,onClick:e=>{e.stopPropagation(),u||a?.previous({})},className:X(`inline-flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors text-xs`,u&&`opacity-40 cursor-not-allowed`),children:`⏮`}),N(`button`,{type:`button`,"aria-label":`Next`,disabled:u,onClick:e=>{e.stopPropagation(),u||a?.next({})},className:X(`inline-flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors text-xs`,u&&`opacity-40 cursor-not-allowed`),children:`⏭`})]}),c.volumeLevel!==null&&g(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[N(`span`,{children:`Vol`}),N(`input`,{"aria-label":`Volume`,type:`range`,min:0,max:100,step:1,value:c.volumeLevel,disabled:u,onChange:e=>{let t=Number(e.target.value);l({volumeLevel:t}),u||a?.setVolume({volumeLevel:t})}}),g(`span`,{className:`tabular-nums w-8 text-right`,children:[c.volumeLevel,`%`]})]}),c.isMuted!==null&&N(`button`,{type:`button`,"aria-label":c.isMuted?`Unmute`:`Mute`,disabled:u,onClick:e=>{if(e.stopPropagation(),!u&&c.isMuted!==null){let e=!c.isMuted;l({isMuted:e}),a?.setMute({muted:e})}},className:X(`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-xs transition-colors`,c.isMuted?`bg-amber-400 text-amber-950`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,u&&`opacity-40 cursor-not-allowed`),children:c.isMuted?`🔇`:`🔊`}),c.availableSources.length>0&&g(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[N(`span`,{children:`Source`}),g(`select`,{"aria-label":`Source`,value:c.source,disabled:u,onChange:e=>{let t=e.target.value;!u&&t&&(l({source:t}),a?.selectSource({source:t}))},className:`rounded border border-border bg-surface px-1 py-0.5`,children:[N(`option`,{value:``,disabled:!0,children:`—`}),c.availableSources.map(e=>N(`option`,{value:e,children:e},e))]})]}),c.shuffle!==null&&N(`button`,{type:`button`,"aria-label":`Shuffle`,disabled:u,onClick:e=>{if(e.stopPropagation(),!u&&c.shuffle!==null){let e=!c.shuffle;l({shuffle:e}),a?.setShuffle({shuffle:e})}},className:X(`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-xs transition-colors`,c.shuffle?`bg-green-400 text-green-950`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,u&&`opacity-40 cursor-not-allowed`),children:`⇌ Shuffle`}),c.repeat!==null&&g(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[N(`span`,{children:`Repeat`}),N(`select`,{"aria-label":`Repeat`,value:c.repeat,disabled:u,onChange:e=>{let t=e.target.value;!u&&pD(t)&&(l({repeat:t}),a?.setRepeat({repeat:t}))},className:`rounded border border-border bg-surface px-1 py-0.5`,children:fD.map(e=>N(`option`,{value:e,children:mD[e]},e))})]})]})]})}h();function _D(e){return e.slice(0,10)}function vD(e){return e.slice(0,5)}function yD(e){return(e.includes(`T`)?e:e.replace(` `,`T`)).slice(0,16)}function bD({value:e,busy:t,onCommit:n,unit:r,min:i,max:a,step:o,precision:s}){let[c,l]=k(xr(e,s)),u=Number(c),d=c!==``&&!Number.isNaN(u),f=o??1,p=e=>{let t=e;return i!==void 0&&(t=Math.max(i,t)),a!==void 0&&(t=Math.min(a,t)),t},m=()=>{!t&&d&&n(p(u))};return g(`div`,{className:`inline-flex items-center gap-1`,children:[N(`button`,{type:`button`,"aria-label":`Decrement`,disabled:t,onClick:r=>{if(r.stopPropagation(),!t){let t=p(e-f);l(xr(t,s)),n(t)}},className:X(`inline-flex h-5 w-5 items-center justify-center rounded border border-border bg-surface text-xs transition-colors hover:bg-surface-hover`,t&&`opacity-40 cursor-not-allowed`),children:`−`}),N(`input`,{"aria-label":`Numeric value`,type:`number`,disabled:t,value:c,onChange:e=>{l(e.target.value);let r=Number(e.target.value);e.target.value!==``&&!Number.isNaN(r)&&(t||n(p(r)))},onBlur:m,onKeyDown:e=>{e.key===`Enter`&&m()},className:X(`w-16 rounded border border-border bg-surface px-1 py-0.5 text-xs tabular-nums text-center`,t&&`opacity-40 cursor-not-allowed`)}),r!==void 0&&N(`span`,{className:`text-foreground-subtle text-xs`,children:r}),N(`button`,{type:`button`,"aria-label":`Increment`,disabled:t,onClick:r=>{if(r.stopPropagation(),!t){let t=p(e+f);l(xr(t,s)),n(t)}},className:X(`inline-flex h-5 w-5 items-center justify-center rounded border border-border bg-surface text-xs transition-colors hover:bg-surface-hover`,t&&`opacity-40 cursor-not-allowed`),children:`+`})]})}function xD({value:e,busy:t,onCommit:n}){let[r,i]=k(e);return N(`input`,{type:`text`,disabled:t,value:r,onChange:e=>i(e.target.value),onBlur:()=>{t||n(r)},onKeyDown:e=>{e.key===`Enter`&&!t&&n(r)},className:X(`rounded border border-border bg-surface px-2 py-0.5 text-xs`,t&&`opacity-40 cursor-not-allowed`)})}function SD({slice:e,busy:t,setValueFn:n,layout:r}){switch(e.kind){case`numeric`:return N(bD,{value:typeof e.value==`number`?e.value:Number(e.value),busy:t,onCommit:e=>{n({control:{kind:`numeric`,value:e}})},unit:e.unit,min:e.min,max:e.max,step:e.step,precision:e.precision});case`select`:return N(`select`,{"aria-label":`Control value`,disabled:t,value:String(e.value),onChange:e=>{e.stopPropagation(),t||n({control:{kind:`select`,value:e.target.value}})},className:X(`w-full max-w-full min-w-0 truncate rounded border border-border bg-surface px-1 py-0.5 text-xs`,t&&`opacity-40 cursor-not-allowed`),children:e.options.map(e=>N(`option`,{value:e,children:e},e))});case`text`:return N(xD,{value:String(e.value),busy:t,onCommit:e=>{n({control:{kind:`text`,value:e}})}});case`datetime`:{let i=String(e.value),a=e.format??`datetime`;return r===`compact`?i===``?N(`span`,{"aria-label":`Control value`,className:`text-xs text-foreground-subtle`,children:`—`}):N(`span`,{"aria-label":`Control value`,className:`text-xs text-foreground`,children:br(i,a)}):N(`input`,{type:a===`date`?`date`:a===`time`?`time`:`datetime-local`,"aria-label":`Control value`,disabled:t,value:a===`date`?_D(i):a===`time`?vD(i):yD(i),onChange:e=>{e.stopPropagation(),t||n({control:{kind:`datetime`,value:e.target.value}})},className:X(`rounded border border-border bg-surface px-1 py-0.5 text-xs`,t&&`opacity-40 cursor-not-allowed`)})}default:return null}}function CD({trpc:e,deviceId:t,features:n,layout:r,optimistic:i}){let{cap:a,slice:o,available:s}=Q({trpc:e,deviceId:t,cap:e=>e.control,slice:e=>e.state.control}),{display:c,applyOptimistic:l}=vu(o,{enabled:i??!0});if(c===void 0)return null;let u=!s;return N(`div`,{"data-kind":c.kind,className:`inline-flex min-w-0 max-w-full items-center gap-1 rounded border border-border px-2 py-1 transition-colors`,children:N(SD,{slice:c,busy:u,setValueFn:e=>{!u&&a&&(l({value:e.control.value}),a.setValue(e))},layout:r})})}var wD=5,TD=35;function ED(e,t,n){return n<=t?0:Math.min(1,Math.max(0,(e-t)/(n-t)))}function DD(e,t,n){return Math.round(t+e*(n-t))}var OD=176,kD=76,AD=2*Math.PI*kD,jD=270/360*AD,MD=OD/2-kD-10;function ND(e){let t=OD/2,n=OD/2,r=AD-jD,i=e.mode===`band`?(()=>{let t=e.band.from*jD,n=Math.max(0,(e.band.to-e.band.from)*jD);return{dasharray:`${n} ${AD-n}`,dashoffset:-t}})():(()=>{let t=e.fraction*jD;return{dasharray:`${t} ${AD-t}`,dashoffset:void 0}})();return g(`svg`,{width:OD,height:OD,viewBox:`0 0 ${OD} ${OD}`,"aria-hidden":`true`,className:`absolute inset-0`,style:{transform:`rotate(135deg)`},children:[N(`circle`,{cx:t,cy:n,r:kD,fill:`none`,stroke:`var(--color-border)`,strokeWidth:12,strokeDasharray:`${jD} ${r}`,strokeLinecap:`round`}),N(`circle`,{cx:t,cy:n,r:kD,fill:`none`,stroke:e.color,strokeWidth:12,strokeDasharray:i.dasharray,...i.dashoffset===void 0?{}:{strokeDashoffset:i.dashoffset},strokeLinecap:`round`})]})}var PD={heat:`#f59e0b`,cool:`#60a5fa`,auto:`#c084fc`,heat_cool:`#e879f9`,fan_only:`#94a3b8`,dry:`#22d3ee`,off:`#d4d4d8`};function FD({trpc:e,deviceId:t,features:n,optimistic:r}){let{cap:i,slice:a,available:o}=Q({trpc:e,deviceId:t,cap:e=>e.climateControl,slice:e=>e.state.climateControl}),{display:s,applyOptimistic:c}=vu(a,{enabled:r??!0});if(i===void 0||s===void 0)return null;let l=!o,u=PD[s.mode],d=s.mode===`heat_cool`||s.targetLow!==null&&s.targetHigh!==null,f=wD,p=TD,m=!d&&s.target!==null?ED(s.target,f,p):0,h=d&&s.targetLow!==null?ED(s.targetLow,f,p):0,_=d&&s.targetHigh!==null?ED(s.targetHigh,f,p):0;return g(`div`,{"data-mode":s.mode,className:X(`flex flex-col items-stretch gap-4 rounded-lg border border-border bg-surface p-4 transition-colors`,HE[s.mode]),children:[g(`div`,{className:`flex flex-col items-center gap-3`,children:[g(`div`,{className:`relative`,style:{width:OD,height:OD},children:[d?N(ND,{mode:`band`,band:{from:h,to:_},color:u}):N(ND,{mode:`fill`,fraction:m,color:u}),d?g(w,{children:[N(`div`,{"data-testid":`arc-knob`,children:N(fu,{fraction:h,color:u,knobTopPx:MD,onDragFraction:e=>{if(l||s.targetHigh===null)return;let t=Math.min(DD(e,f,p),s.targetHigh);c({targetLow:t}),i.setTargetRange({targetLow:t,targetHigh:s.targetHigh})}})}),N(`div`,{"data-testid":`arc-knob`,children:N(fu,{fraction:_,color:u,knobTopPx:MD,onDragFraction:e=>{if(l||s.targetLow===null)return;let t=Math.max(DD(e,f,p),s.targetLow);c({targetHigh:t}),i.setTargetRange({targetLow:s.targetLow,targetHigh:t})}})})]}):N(`div`,{"data-testid":`arc-knob`,children:N(fu,{fraction:m,color:u,knobTopPx:MD,onDragFraction:e=>{if(l)return;let t=DD(e,f,p);c({target:t}),i.setTarget({target:t})}})}),g(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-0.5 pointer-events-none`,children:[g(`div`,{"data-testid":`current-temp`,className:`text-4xl font-bold tabular-nums text-foreground leading-none`,children:[s.currentTemp===null?`—`:s.currentTemp,N(`span`,{className:`text-lg text-foreground-subtle font-normal ml-0.5`,children:`°`})]}),!d&&s.target!==null&&g(`div`,{className:`text-xs font-semibold`,style:{color:u},children:[`set `,s.target,`°`]}),d&&s.targetLow!==null&&s.targetHigh!==null&&g(`div`,{className:`text-xs font-semibold`,style:{color:u},children:[s.targetLow,`° – `,s.targetHigh,`°`]})]})]}),!d&&s.target!==null&&N(`div`,{className:`w-[200px]`,children:N(ou,{value:`${s.target}°`,onDelta:e=>{if(l||s.target===null)return;let t=s.target+e;c({target:t}),i.setTarget({target:t})}})})]}),N(`select`,{"aria-label":`Mode`,value:s.mode,disabled:l,onChange:e=>{e.stopPropagation();let t=e.target.value;!l&&t&&(c({mode:s.availableModes.find(e=>e===t)??s.mode}),i.setMode({mode:s.availableModes.find(e=>e===t)??s.mode}))},className:X(`w-full rounded border border-border bg-surface px-3 py-1.5 text-sm`,l&&`opacity-40 cursor-not-allowed`),children:s.availableModes.map(e=>N(`option`,{value:e,children:e},e))})]})}function ID(e){return e===`locked`||e===`locking`}function LD(e){return e===`jammed`}var RD={locked:{colorClass:`border-success/30 bg-success/10 text-success`,icon:`locked`},locking:{colorClass:`border-success/30 bg-success/10 text-success`,icon:`locked`},unlocked:{colorClass:`border-warning/30 bg-warning/10 text-warning`,icon:`open`},unlocking:{colorClass:`border-warning/30 bg-warning/10 text-warning`,icon:`open`},jammed:{colorClass:`border-danger/30 bg-danger/10 text-danger`,icon:`locked`}};function zD({state:e}){let t=RD[e];return N(`div`,{"data-testid":`lock-glyph`,"data-state":e,className:X(`flex h-16 w-16 items-center justify-center rounded-full border-2`,t.colorClass),children:t.icon===`locked`?N(ka,{className:`h-8 w-8`,"aria-hidden":`true`}):N(Oa,{className:`h-8 w-8`,"aria-hidden":`true`})})}function BD({state:e}){return N(`span`,{className:X(`text-sm font-medium capitalize`,LD(e)?`text-danger`:`text-foreground-muted`),children:e})}function VD({busy:e,onOpen:t}){return g(`button`,{type:`button`,"aria-label":`Open (unlatch)`,title:`Open (unlatch)`,disabled:e,onClick:e=>{e.stopPropagation(),t()},className:X(`inline-flex items-center gap-1.5 rounded-md border border-border px-3 py-1.5 text-xs font-medium`,`text-foreground-muted hover:bg-surface-hover transition-colors`,e&&`opacity-40 cursor-not-allowed`),children:[N(Yi,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Open`]})}function HD({trpc:e,deviceId:t,features:n,optimistic:r}){let{cap:i,slice:a,available:o}=Q({trpc:e,deviceId:t,cap:e=>e.lockControl,slice:e=>e.state.lockControl}),{display:s,applyOptimistic:c}=vu(a,{enabled:r??!0});if(i===void 0||s===void 0)return null;let l=ID(s.state),u=LD(s.state)||!o,d=n?.includes(U.LockOpen)===!0,f=()=>{u||(l?(c({state:`unlocking`}),i.unlock({})):(c({state:`locking`}),i.lock({})))},p=()=>{u||i.open({})},m=l?`Unlock`:`Lock`;return g(`div`,{className:`flex flex-col items-stretch gap-4 rounded-lg border border-border bg-surface p-4`,children:[g(`div`,{className:`flex flex-col items-center gap-2`,children:[N(zD,{state:s.state}),N(BD,{state:s.state})]}),N(`div`,{className:X(u&&`pointer-events-none opacity-40`),children:N(su,{on:l,targetLabel:m,onConfirm:f})}),d&&N(`div`,{className:`flex justify-center`,children:N(VD,{busy:u,onOpen:p})})]})}var UD=150,WD=64,GD=UD/2,KD=2*Math.PI*WD,qD=270/360*KD;function JD({fraction:e,color:t,children:n,onDragFraction:r}){let i=Math.min(1,Math.max(0,e)),a=UD/2,o=UD/2,s=KD-qD,c=i*qD;return g(`div`,{className:`relative`,style:{width:UD,height:UD},children:[g(`svg`,{width:UD,height:UD,viewBox:`0 0 ${UD} ${UD}`,"aria-hidden":`true`,className:`absolute inset-0`,style:{transform:`rotate(135deg)`},children:[N(`circle`,{cx:a,cy:o,r:WD,fill:`none`,stroke:`var(--color-border)`,strokeWidth:11,strokeDasharray:`${qD} ${s}`,strokeLinecap:`round`}),N(`circle`,{cx:a,cy:o,r:WD,fill:`none`,stroke:t,strokeWidth:11,strokeDasharray:`${c} ${KD-c}`,strokeLinecap:`round`})]}),N(`div`,{"data-testid":`arc-knob`,children:N(fu,{fraction:i,color:t,knobTopPx:GD-WD-10,...r===void 0?{}:{onDragFraction:r}})}),N(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-0.5 pointer-events-none`,children:n})]})}function YD({on:e,busy:t,onToggle:n}){let r={transform:e?`translateX(30px)`:`translateX(3px)`};return N(`button`,{type:`button`,"aria-pressed":e,title:e?`Turn off`:`Turn on`,disabled:t,onClick:e=>{e.stopPropagation(),n()},className:X(`relative inline-flex h-8 w-16 items-center rounded-full border transition-colors flex-shrink-0`,e?`bg-success/30 border-success/50`:`bg-surface-hover border-border`,t&&`opacity-60 cursor-not-allowed`),children:N(`span`,{className:X(`absolute h-6 w-6 rounded-full transition-all`,e?`bg-success`:`bg-foreground-subtle`),style:r})})}var XD=500,ZD=150,QD=`linear-gradient(90deg, #9ec9ff, #ffffff, #ffb24d)`;function $D(e,t,n){return n<=t?0:Math.min(1,Math.max(0,(e-t)/(n-t)))}function eO(e){return $D(e,ZD,XD)}var tO=`#f4b740`,nO=`#d4d4d8`;function rO({trpc:e,deviceId:t,features:n,optimistic:r}){let i=Q({trpc:e,deviceId:t,cap:e=>e.switch,slice:e=>e.state.switch}),a=Q({trpc:e,deviceId:t,cap:e=>e.brightness,slice:e=>e.state.brightness}),o=Q({trpc:e,deviceId:t,cap:e=>e.color,slice:e=>e.state.color}),s=vu(i.slice,{enabled:r??!0}),c=vu(a.slice,{enabled:r??!0}),l=vu(o.slice,{enabled:r??!0});if(i.cap===void 0||s.display===void 0)return null;let u=s.display.on===!0,d=!i.available,f=c.display?.percentage??0,p=!a.available,m=u?f/100:0,h=u?tO:nO,_=(n?.includes(U.LightColorMired)??!1)&&o.cap!==void 0,v=l.display?.mireds,y=!o.available;return g(`div`,{className:`flex flex-col items-stretch gap-4 rounded-lg border border-border bg-surface p-4`,children:[g(`div`,{className:`flex flex-col items-center gap-3`,children:[g(JD,{fraction:m,color:h,children:[g(`div`,{"data-testid":`brightness-readout`,className:`text-3xl font-bold tabular-nums text-foreground leading-none`,children:[f,N(`span`,{className:`text-base text-foreground-subtle font-normal ml-0.5`,children:`%`})]}),N(Ca,{className:`h-5 w-5 text-foreground-subtle`,"aria-hidden":`true`})]}),a.cap!==void 0&&g(`label`,{className:`flex w-full items-center gap-2 text-xs text-foreground-subtle`,children:[N(`span`,{className:`w-16`,children:`Brightness`}),N(`input`,{"aria-label":`Brightness`,type:`range`,min:0,max:100,step:1,className:`flex-1`,value:f,disabled:p||!u,onChange:e=>{let t=Number(e.target.value);c.applyOptimistic({percentage:t}),p||a.cap?.setBrightness({percentage:t})}}),g(`span`,{className:`tabular-nums w-9 text-right`,children:[f,`%`]})]})]}),g(`div`,{className:`flex items-center justify-between`,children:[N(`span`,{className:`text-sm font-medium text-foreground-muted`,children:u?`On`:`Off`}),N(YD,{on:u,busy:d,onToggle:()=>{if(d)return;let e=!u;s.applyOptimistic({on:e}),i.cap?.setState({on:e})}})]}),_&&g(`div`,{className:`flex items-center gap-2`,"data-testid":`color-temp-strip`,children:[N(Lo,{className:`h-4 w-4 text-foreground-subtle`,"aria-hidden":`true`}),g(`label`,{className:`flex-1`,children:[N(`span`,{className:`sr-only`,children:`Colour temperature`}),N(`input`,{"aria-label":`Colour temperature`,type:`range`,min:ZD,max:XD,step:1,className:`w-full`,value:v??XD,disabled:y||!u,onChange:e=>{let t=Number(e.target.value);l.applyOptimistic({mode:`mired`,mireds:t}),y||o.cap?.setColor({color:{mode:`mired`,mireds:t}})}}),N(`div`,{className:`pointer-events-none mt-1`,children:N(pu,{fraction:v===void 0?.5:eO(v),color:QD})})]})]})]})}var iO=`#3aa6a0`,aO=`#d4d4d8`;function oO({trpc:e,deviceId:t,features:n,optimistic:r}){let i=Q({trpc:e,deviceId:t,cap:e=>e.switch,slice:e=>e.state.switch}),a=Q({trpc:e,deviceId:t,cap:e=>e.fanControl,slice:e=>e.state.fanControl}),o=vu(i.slice,{enabled:r??!0}),s=vu(a.slice,{enabled:r??!0});if(i.cap===void 0||o.display===void 0)return null;let c=o.display.on===!0,l=!i.available,u=s.display?.percentage??0,d=!a.available,f=c?u/100:0,p=c?iO:aO,m=n?.includes(U.FanSpeed)??!1,h=(n?.includes(U.FanOscillating)??!1)&&a.cap!==void 0,_=s.display?.availablePresets??[],v=(n?.includes(U.FanPreset)??!1)&&a.cap!==void 0&&_.length>0,y=s.display?.preset??``,b=s.display?.oscillating===!0,x=()=>{if(l)return;let e=!c;o.applyOptimistic({on:e}),i.cap?.setState({on:e})},S=()=>{if(d)return;let e=!b;s.applyOptimistic({oscillating:e}),a.cap?.setOscillating({oscillating:e})},C=e=>{if(d)return;let t=s.display;if(t===void 0)return;let n=t.percentageStep!==void 0&&t.percentageStep>0?t.percentageStep:1,r=Math.min(100,Math.max(0,Math.round(e*100/n)*n));s.applyOptimistic({percentage:r}),a.cap?.setPercentage({percentage:r})},w=e=>{d||e===``||(s.applyOptimistic({preset:e}),a.cap?.setPreset({preset:e}))};return g(`div`,{className:`flex flex-col items-stretch gap-4 rounded-lg border border-border bg-surface p-4`,children:[N(`div`,{className:`flex flex-col items-center gap-3`,children:m?g(JD,{fraction:f,color:p,onDragFraction:C,children:[g(`div`,{"data-testid":`speed-readout`,className:`text-3xl font-bold tabular-nums text-foreground leading-none`,children:[u,N(`span`,{className:`text-base text-foreground-subtle font-normal ml-0.5`,children:`%`})]}),N(ra,{className:`h-5 w-5 text-foreground-subtle`,"aria-hidden":`true`})]}):N(`div`,{"data-testid":`fan-onoff-icon`,className:`flex h-[150px] w-[150px] items-center justify-center`,children:N(ra,{className:`h-16 w-16`,style:{color:p},"aria-hidden":`true`})})}),v&&N(`div`,{className:`flex justify-center`,children:g(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[N(`span`,{children:`Preset`}),g(`select`,{"aria-label":`Fan preset`,value:y,disabled:d,onChange:e=>{e.stopPropagation(),w(e.target.value)},className:X(`bg-surface border border-border rounded px-1 py-0.5`,d&&`opacity-40 cursor-not-allowed`),children:[N(`option`,{value:``,disabled:!0,children:`—`}),_.map(e=>N(`option`,{value:e,children:e},e))]})]})}),g(`div`,{className:`flex items-center justify-between gap-2`,children:[h?g(`button`,{type:`button`,"aria-label":`Oscillate`,"aria-pressed":b,disabled:d,onClick:e=>{e.stopPropagation(),S()},className:X(`inline-flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs font-medium transition-colors`,b?`border-success/50 bg-success/10 text-success`:`border-border text-foreground-muted hover:bg-surface-hover`,d&&`opacity-40 cursor-not-allowed`),children:[N(oo,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Oscillate`]}):N(`span`,{className:`text-sm font-medium text-foreground-muted`,children:c?`On`:`Off`}),N(YD,{on:c,busy:l,onToggle:x})]})]})}function sO({trpc:e,deviceId:t,optimistic:n}){let{cap:r,slice:i,available:a}=Q({trpc:e,deviceId:t,cap:e=>e.switch,slice:e=>e.state.switch}),{display:o,applyOptimistic:s}=vu(i,{enabled:n??!0});if(r===void 0||o===void 0)return null;let c=o.on===!0,l=!a;return g(`div`,{className:`flex flex-col items-center gap-4 rounded-lg border border-border bg-surface p-6`,children:[N(`div`,{"data-testid":`switch-glyph`,"data-state":c?`on`:`off`,className:X(`flex h-16 w-16 items-center justify-center rounded-full border-2 transition-colors`,c?`border-success/30 bg-success/10 text-success`:`border-border bg-surface-subtle text-foreground-subtle`),children:N(no,{className:`h-8 w-8`,"aria-hidden":`true`})}),N(`span`,{className:`text-sm font-medium text-foreground-muted`,children:c?`On`:`Off`}),N(YD,{on:c,busy:l,onToggle:()=>{if(l)return;let e=!c;s({on:e}),r.setState({on:e})}})]})}function cO(e){return e===`playing`||e===`buffering`?`pause`:`play`}function lO(e,t){return e===null||t===null||t<=0?0:Math.min(1,Math.max(0,e/t))}function uO(e){if(e===null)return`--:--`;let t=Math.floor(e/1e3);return`${Math.floor(t/60)}:${(t%60).toString().padStart(2,`0`)}`}function dO({title:e,subtitle:t}){return g(`div`,{className:`flex flex-col items-center gap-1 text-center`,children:[N(Ga,{className:`h-6 w-6 text-foreground-subtle`,"aria-hidden":`true`}),N(`span`,{className:`text-base font-semibold text-foreground line-clamp-1`,children:e??`Nothing playing`}),t&&N(`span`,{className:`text-xs text-foreground-subtle line-clamp-1`,children:t})]})}function fO({label:e,busy:t,onPress:n,children:r,primary:i}){return N(`button`,{type:`button`,"aria-label":e,title:e,disabled:t,onClick:e=>{e.stopPropagation(),t||n()},className:X(`inline-flex items-center justify-center rounded-full transition-colors`,i?`h-12 w-12 bg-primary text-primary-foreground hover:bg-primary/90 shadow-md`:`h-10 w-10 text-foreground-muted hover:bg-surface-hover`,t&&`opacity-40 cursor-not-allowed`),children:r})}function pO({trpc:e,deviceId:t,features:n,optimistic:r}){let{cap:i,slice:a,available:o}=Q({trpc:e,deviceId:t,cap:e=>e.mediaPlayer,slice:e=>e.state.mediaPlayer}),{display:s,applyOptimistic:c}=vu(a,{enabled:r??!0});if(i===void 0||s===void 0)return null;let l=!o,u=cO(s.state),d=(n?.includes(U.MediaPlayerSeek)??!1)&&s.durationMs!==null&&s.durationMs>0,f=n?.includes(U.MediaPlayerNext)??!1,p=n?.includes(U.MediaPlayerPrevious)??!1,m=(n?.includes(U.MediaPlayerVolume)??!1)&&s.volumeLevel!==null,h=()=>{l||(u===`play`?(c({state:`playing`}),i.play({})):(c({state:`paused`}),i.pause({})))},_=s.currentMedia?.artist??s.currentMedia?.album??null,v=lO(s.positionMs,s.durationMs),y=s.volumeLevel??0;return g(`div`,{className:`flex flex-col items-stretch gap-4 rounded-lg border border-border bg-surface p-6`,children:[N(dO,{title:s.currentMedia?.title??null,subtitle:_}),d&&g(`div`,{"data-testid":`media-seek`,className:`flex flex-col gap-1`,children:[g(`label`,{className:`relative block`,children:[N(`span`,{className:`sr-only`,children:`Seek`}),N(`input`,{"aria-label":`Seek`,type:`range`,min:0,max:s.durationMs??0,step:1e3,className:`absolute inset-0 h-4 w-full cursor-pointer opacity-0`,value:s.positionMs??0,disabled:l,onChange:e=>{if(l)return;let t=Number(e.target.value);c({positionMs:t}),i.seek({positionMs:t})}}),N(`div`,{className:`pointer-events-none`,children:N(pu,{fraction:v})})]}),g(`div`,{className:`flex justify-between text-[11px] tabular-nums text-foreground-subtle`,children:[N(`span`,{children:uO(s.positionMs)}),N(`span`,{children:uO(s.durationMs)})]})]}),g(`div`,{className:`flex items-center justify-center gap-4`,children:[p&&N(fO,{label:`Previous`,busy:l,onPress:()=>void i.previous({}),children:N(Co,{className:`h-5 w-5`,"aria-hidden":`true`})}),N(fO,{label:u===`play`?`Play`:`Pause`,busy:l,onPress:h,primary:!0,children:N(u===`play`?Qa:Ja,{className:`h-6 w-6`,"aria-hidden":`true`})}),f&&N(fO,{label:`Next`,busy:l,onPress:()=>void i.next({}),children:N(wo,{className:`h-5 w-5`,"aria-hidden":`true`})})]}),m&&g(`div`,{"data-testid":`media-volume`,className:`flex items-center gap-2`,children:[N(`button`,{type:`button`,"aria-label":s.isMuted===!0?`Unmute`:`Mute`,title:s.isMuted===!0?`Unmute`:`Mute`,disabled:l,onClick:e=>{if(e.stopPropagation(),l||s.isMuted===null)return;let t=!s.isMuted;c({isMuted:t}),i.setMute({muted:t})},className:X(`inline-flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,l&&`opacity-40 cursor-not-allowed`),children:s.isMuted===!0?N(Xo,{className:`h-4 w-4`,"aria-hidden":`true`}):N(Yo,{className:`h-4 w-4`,"aria-hidden":`true`})}),g(`label`,{className:`relative block flex-1`,children:[N(`span`,{className:`sr-only`,children:`Volume`}),N(`input`,{"aria-label":`Volume`,type:`range`,min:0,max:100,step:1,className:`absolute inset-0 h-4 w-full cursor-pointer opacity-0`,value:y,disabled:l,onChange:e=>{if(l)return;let t=Number(e.target.value);c({volumeLevel:t}),i.setVolume({volumeLevel:t})}}),N(`div`,{className:`pointer-events-none`,children:N(pu,{fraction:y/100})})]}),g(`span`,{className:`w-9 text-right text-[11px] tabular-nums text-foreground-subtle`,children:[y,`%`]})]})]})}var mO={disarmed:{label:`Disarmed`,colorClass:`border-border bg-surface-subtle text-foreground-subtle`,icon:`disarmed`},armed_home:{label:`Armed Home`,colorClass:`border-success/30 bg-success/10 text-success`,icon:`armed`},armed_away:{label:`Armed Away`,colorClass:`border-success/30 bg-success/10 text-success`,icon:`armed`},armed_night:{label:`Armed Night`,colorClass:`border-success/30 bg-success/10 text-success`,icon:`armed`},armed_vacation:{label:`Armed Vacation`,colorClass:`border-success/30 bg-success/10 text-success`,icon:`armed`},armed_custom_bypass:{label:`Armed (Bypass)`,colorClass:`border-success/30 bg-success/10 text-success`,icon:`armed`},arming:{label:`Arming…`,colorClass:`border-warning/30 bg-warning/10 text-warning`,icon:`pending`},disarming:{label:`Disarming…`,colorClass:`border-warning/30 bg-warning/10 text-warning`,icon:`pending`},pending:{label:`Pending`,colorClass:`border-warning/30 bg-warning/10 text-warning`,icon:`pending`},triggered:{label:`Triggered`,colorClass:`border-danger/30 bg-danger/10 text-danger`,icon:`triggered`}},hO={home:`Home`,away:`Away`,night:`Night`,vacation:`Vacation`,custom_bypass:`Bypass`};function gO(e){return e.startsWith(`armed_`)}function _O(e){return e===`arming`||e===`disarming`}function vO({icon:e}){return N(e===`disarmed`?yo:e===`triggered`?_o:e===`pending`?bo:vo,{className:`h-8 w-8`,"aria-hidden":`true`})}function yO({label:e,active:t,busy:n,onSelect:r}){return N(`button`,{type:`button`,"aria-label":e,"aria-pressed":t,disabled:n,onClick:e=>{e.stopPropagation(),n||r()},className:X(`flex-1 rounded-md px-3 py-2 text-sm font-medium transition-colors`,t?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-muted hover:bg-surface-hover`,n&&`opacity-40 cursor-not-allowed`),children:e})}function bO({state:e,availableModes:t,busy:n,onDisarm:r,onArm:i}){let a=gO(e),o=_O(e);return g(`div`,{className:`flex items-stretch gap-1 rounded-lg border border-border bg-surface-subtle p-1`,children:[N(yO,{label:`Disarm`,active:!a&&!o,busy:n,onSelect:r}),t.map(t=>N(yO,{label:hO[t],active:!o&&e===`armed_${t}`,busy:n,onSelect:()=>i(t)},t))]})}function xO(e,t,n){let{cap:r,slice:i,available:a}=Q({trpc:e,deviceId:t,cap:e=>e.alarmPanel,slice:e=>e.state.alarmPanel}),{display:o,applyOptimistic:s}=vu(i,{enabled:n??!0}),c=!a;return{display:o,capPresent:r!==void 0,busy:c,handleDisarm:()=>{r===void 0||c||(s({state:`disarming`}),r.disarm({}))},handleArm:e=>{r===void 0||c||(s({state:`arming`}),r.arm({mode:e}))}}}function SO({trpc:e,deviceId:t,optimistic:n}){let{display:r,capPresent:i,busy:a,handleDisarm:o,handleArm:s}=xO(e,t,n);return!i||r===void 0?null:N(bO,{state:r.state,availableModes:r.availableModes,busy:a,onDisarm:o,onArm:s})}function CO({trpc:e,deviceId:t,optimistic:n}){let{display:r,capPresent:i,busy:a,handleDisarm:o,handleArm:s}=xO(e,t,n);if(!i||r===void 0)return null;let c=mO[r.state];return g(`div`,{className:`flex flex-col items-stretch gap-4 rounded-lg border border-border bg-surface p-6`,children:[g(`div`,{className:`flex flex-col items-center gap-2`,children:[N(`div`,{"data-testid":`alarm-state`,"data-state":r.state,className:X(`flex h-16 w-16 items-center justify-center rounded-full border-2`,c.colorClass),children:N(vO,{icon:c.icon})}),N(`span`,{className:`text-sm font-medium text-foreground-muted`,children:c.label})]}),N(bO,{state:r.state,availableModes:r.availableModes,busy:a,onDisarm:o,onArm:s})]})}function wO({children:e}){return N(`div`,{className:`flex flex-col items-stretch gap-3 rounded-lg border border-border bg-surface p-4`,children:e})}function TO(e,t){let{cap:n}=Q({trpc:e,deviceId:t,cap:e=>e.switch,slice:e=>e.state.switch});return n!==void 0}function EO({trpc:e,deviceId:t,features:n,optimistic:r}){return TO(e,t)?N(LE,{trpc:e,deviceId:t,features:n,layout:`compact`,optimistic:r}):null}function DO(e,t){let{cap:n}=Q({trpc:e,deviceId:t,cap:e=>e.lockControl,slice:e=>e.state.lockControl});return n!==void 0}function OO({trpc:e,deviceId:t,features:n,optimistic:r}){return DO(e,t)?N(zE,{trpc:e,deviceId:t,features:n,layout:`compact`,optimistic:r}):null}function kO({trpc:e,deviceId:t,features:n,optimistic:r}){return TO(e,t)?g(`div`,{className:`inline-flex items-center gap-2`,children:[N(LE,{trpc:e,deviceId:t,features:n,layout:`compact`,optimistic:r}),N(BE,{trpc:e,deviceId:t,features:n,layout:`compact`,optimistic:r})]}):null}function AO(e,t){let{cap:n}=Q({trpc:e,deviceId:t,cap:e=>e.fanControl,slice:e=>e.state.fanControl});return n!==void 0}function jO({trpc:e,deviceId:t,features:n,optimistic:r}){return AO(e,t)?g(`div`,{className:`inline-flex items-center gap-2`,children:[N(LE,{trpc:e,deviceId:t,features:n,layout:`compact`,optimistic:r}),N(VE,{trpc:e,deviceId:t,features:n,layout:`compact`,optimistic:r})]}):null}function MO(e,t){let{cap:n}=Q({trpc:e,deviceId:t,cap:e=>e.climateControl,slice:e=>e.state.climateControl});return n!==void 0}function NO({trpc:e,deviceId:t,features:n,optimistic:r}){return MO(e,t)?N(GE,{trpc:e,deviceId:t,features:n,layout:`compact`,optimistic:r}):null}function PO({trpc:e,deviceId:t,features:n,optimistic:r}){return MO(e,t)?N(tD,{trpc:e,deviceId:t,features:n,layout:`compact`,optimistic:r}):null}function FO({trpc:e,deviceId:t,features:n,optimistic:r}){return MO(e,t)?N(tD,{trpc:e,deviceId:t,features:n,layout:`full`,optimistic:r}):null}function IO(e,t){let{cap:n}=Q({trpc:e,deviceId:t,cap:e=>e.mediaPlayer,slice:e=>e.state.mediaPlayer});return n!==void 0}function LO({trpc:e,deviceId:t,features:n,optimistic:r}){return IO(e,t)?N(gD,{trpc:e,deviceId:t,features:n,layout:`compact`,optimistic:r}):null}function RO(e,t){let{cap:n}=Q({trpc:e,deviceId:t,cap:e=>e.control,slice:e=>e.state.control});return n!==void 0}function zO({trpc:e,deviceId:t,features:n,optimistic:r}){return RO(e,t)?N(CD,{trpc:e,deviceId:t,features:n,layout:`compact`,optimistic:r}):null}function BO({trpc:e,deviceId:t,features:n,optimistic:r}){return RO(e,t)?N(wO,{children:N(CD,{trpc:e,deviceId:t,features:n,layout:`full`,optimistic:r})}):null}var VO={InlineControl:Su,HeroCard:Du},HO={InlineControl:Ou,HeroCard:ku},UO={InlineControl:qw,HeroCard:nT},WO={InlineControl:aT,HeroCard:oT},GO={InlineControl:EO,HeroCard:sO},KO={InlineControl:OO,HeroCard:HD},qO={InlineControl:kO,HeroCard:rO},JO={InlineControl:jO,HeroCard:oO},YO={InlineControl:NO,HeroCard:FD},XO={InlineControl:PO,HeroCard:FO},ZO={InlineControl:LO,HeroCard:pO},QO={InlineControl:SO,HeroCard:CO},$O={InlineControl:zO,HeroCard:BO},ek={InlineControl:yT,HeroCard:xT},tk={InlineControl:MT,HeroCard:PT},nk={InlineControl:zT,HeroCard:WT},rk={InlineControl:qT,HeroCard:YT},ik={InlineControl:$T,HeroCard:tE},ak={InlineControl:sE,HeroCard:fE},ok={InlineControl:yE,HeroCard:bE},sk={InlineControl:FE,HeroCard:IE},ck={[G.Cover]:VO,[G.Valve]:nk,[G.Humidifier]:rk,[G.WaterHeater]:ik,[G.Camera]:HO,[G.Hub]:HO,[G.Switch]:GO,[G.Siren]:GO,[G.Light]:qO,[G.Fan]:JO,[G.Sensor]:UO,[G.Thermostat]:YO,[G.Climate]:XO,[G.Button]:{InlineControl:mu,HeroCard:hu},[G.EventEmitter]:HO,[G.Update]:WO,[G.Generic]:HO,[G.Notifier]:HO,[G.Script]:HO,[G.Automation]:HO,[G.Lock]:KO,[G.MediaPlayer]:ZO,[G.AlarmPanel]:QO,[G.Control]:$O,[G.Presence]:UO,[G.Weather]:ak,[G.Vacuum]:ek,[G.LawnMower]:tk,[G.Container]:HO,[G.Image]:ok,[G.PetFeeder]:sk},lk={[G.Cover]:!0,[G.Valve]:!0,[G.Thermostat]:!0,[G.Climate]:!0,[G.Control]:!0,[G.Button]:!0,[G.MediaPlayer]:!0,[G.AlarmPanel]:!0,[G.Lock]:!1,[G.Vacuum]:!1,[G.LawnMower]:!1,[G.Humidifier]:!1,[G.Switch]:!1,[G.Siren]:!1,[G.Light]:!1,[G.Fan]:!1,[G.WaterHeater]:!1,[G.Sensor]:!1,[G.Presence]:!1,[G.EventEmitter]:!1,[G.Notifier]:!1,[G.Script]:!1,[G.Automation]:!1,[G.Camera]:!1,[G.Hub]:!1,[G.Update]:!1,[G.Generic]:!1,[G.Weather]:!1,[G.Container]:!1,[G.Image]:!1,[G.PetFeeder]:!1},uk=new Set(Object.values(G));function dk(e){return uk.has(e)?ck[e]:null}function fk(e,t){return t===`table`?`fit`:uk.has(e)&&lk[e]?tu:t===`center`?ru:nu}var pk=[`media-player`,`alarm-panel`,`thermostat`,`climate`,`humidifier`,`water-heater`,`lock`,`cover`,`valve`,`fan`,`vacuum`,`lawn-mower`,`light`,`switch`,`siren`,`button`,`control`,`notifier`,`script`,`automation`,`update`,`presence`,`weather`,`image`,`sensor`];function mk(e,t){if(t!==void 0){let n=e.find(e=>e.entityId===t);if(n!==void 0)return n}return[...e].toSorted((e,t)=>hk(e.type)-hk(t.type))[0]??null}function hk(e){let t=pk.indexOf(e);return t===-1?pk.length:t}function gk(e){return e.sourceInfo?.id??e.stableId}function _k(e){return{id:e.id,entityId:gk(e),type:e.type}}function vk(e,t){if(t==null)return;let n=e.find(e=>e.id===t);return n===void 0?void 0:gk(n)}function yk(e,t,n){return mk(e.map(_k),n!=null&&n!==``?n:vk(e,t))}var bk={[G.Camera]:{icon:xi,label:`Camera`},[G.Hub]:{icon:qa,label:`Hub`},[G.Light]:{icon:Ca,label:`Light`},[G.Siren]:{icon:So,label:`Siren`},[G.Switch]:{icon:Ro,label:`Switch`},[G.Sensor]:{icon:Qr,label:`Sensor`},[G.Thermostat]:{icon:Lo,label:`Thermostat`},[G.Climate]:{icon:$r,label:`Air conditioner`},[G.Button]:{icon:ji,label:`Button`},[G.EventEmitter]:{icon:is,label:`Event Emitter`},[G.Update]:{icon:oo,label:`Update`},[G.Generic]:{icon:yi,label:`Generic`},[G.Notifier]:{icon:hi,label:`Notifier`},[G.Script]:{icon:fo,label:`Script`},[G.Automation]:{icon:ts,label:`Automation`},[G.Lock]:{icon:ka,label:`Lock`},[G.Cover]:{icon:gi,label:`Cover`},[G.Valve]:{icon:Za,label:`Valve`},[G.Humidifier]:{icon:Zo,label:`Humidifier`},[G.WaterHeater]:{icon:ci,label:`Water heater`},[G.Fan]:{icon:ra,label:`Fan`},[G.MediaPlayer]:{icon:za,label:`Media player`},[G.AlarmPanel]:{icon:_o,label:`Alarm panel`},[G.Control]:{icon:To,label:`Control`},[G.Presence]:{icon:ja,label:`Presence`},[G.Weather]:{icon:Vi,label:`Weather`},[G.Vacuum]:{icon:vi,label:`Vacuum`},[G.LawnMower]:{icon:zo,label:`Lawn mower`},[G.Container]:{icon:yi,label:`Container`},[G.Image]:{icon:va,label:`Image`},[G.PetFeeder]:{icon:_i,label:`Pet feeder`}},xk={[B.Siren]:{icon:So,label:`Siren`},[B.Floodlight]:{icon:Ca,label:`Floodlight`},[B.Spotlight]:{icon:sa,label:`Spotlight`},[B.PirSensor]:{icon:io,label:`PIR sensor`},[B.Chime]:{icon:hi,label:`Chime`},[B.Autotrack]:{icon:Ki,label:`Auto-track`},[B.Nightvision]:{icon:Ba,label:`Night vision`},[B.PrivacyMask]:{icon:ta,label:`Privacy mask`},[B.Doorbell]:{icon:Ji,label:`Doorbell`},[B.BinaryHelper]:{icon:Ro,label:`Binary helper`},[B.MotionSensor]:{icon:la,label:`Motion sensor`},[B.ContactSensor]:{icon:Yi,label:`Contact sensor`},[B.LeakSensor]:{icon:Zi,label:`Leak sensor`},[B.SmokeSensor]:{icon:ei,label:`Smoke sensor`},[B.COSensor]:{icon:es,label:`CO sensor`},[B.GasSensor]:{icon:oa,label:`Gas sensor`},[B.TamperSensor]:{icon:_o,label:`Tamper sensor`},[B.VibrationSensor]:{icon:Jo,label:`Vibration sensor`},[B.ConnectivitySensor]:{icon:$o,label:`Connectivity`},[B.SoundSensor]:{icon:Yo,label:`Sound sensor`},[B.BinarySensor]:{icon:Ro,label:`Binary sensor`},[B.TemperatureSensor]:{icon:Lo,label:`Temperature`},[B.HumiditySensor]:{icon:Qi,label:`Humidity`},[B.AmbientLightSensor]:{icon:No,label:`Ambient light`},[B.PressureSensor]:{icon:fa,label:`Pressure`},[B.WindSensor]:{icon:es,label:`Wind`},[B.RainSensor]:{icon:zi,label:`Rain`},[B.UvSensor]:{icon:Mo,label:`UV index`},[B.SolarRadiationSensor]:{icon:Po,label:`Solar radiation`},[B.SoilMoistureSensor]:{icon:ko,label:`Soil moisture`},[B.PowerSensor]:{icon:is,label:`Power`},[B.EnergySensor]:{icon:is,label:`Energy`},[B.VoltageSensor]:{icon:is,label:`Voltage`},[B.CurrentSensor]:{icon:is,label:`Current`},[B.AirQualitySensor]:{icon:es,label:`Air quality`},[B.BatterySensor]:{icon:fa,label:`Battery`},[B.NumericSensor]:{icon:ha,label:`Numeric sensor`},[B.EnumSensor]:{icon:Ta,label:`Enum sensor`},[B.DateTimeSensor]:{icon:Ii,label:`Date / time`},[B.GenericSensor]:{icon:fa,label:`Sensor`},[B.NumericControl]:{icon:To,label:`Numeric control`},[B.SelectControl]:{icon:wa,label:`Select control`},[B.TextControl]:{icon:Wo,label:`Text control`},[B.DateTimeControl]:{icon:Ii,label:`Date / time control`},[B.MobilePushNotifier]:{icon:Eo,label:`Mobile push`},[B.MessagingNotifier]:{icon:Fa,label:`Messaging`},[B.EmailNotifier]:{icon:Aa,label:`Email`},[B.GenericNotifier]:{icon:hi,label:`Notifier`}},Sk=new Set(Object.values(G)),Ck=new Set(Object.values(B));function wk(e){return Sk.has(e)}function Tk(e){return Ck.has(e)}function Ek(e){return bk[e]}function Dk(e){return xk[e]}var Ok=bk[G.Generic],kk=xk[B.GenericSensor];function Ak(e){return wk(e)?bk[e]??Ok:Ok}function jk(e){return Tk(e)?xk[e]??kk:kk}var Mk={thermometer:Lo,droplets:Qi,droplet:Zi,gauge:fa,sun:No,"sun-medium":Mo,sunrise:Po,moon:Ba,wind:es,"cloud-rain":zi,"cloud-sun":Vi,waves:Zo,sprout:ko,zap:is,flame:oa,bell:hi,siren:So,radar:io,activity:Qr,hash:ha,clock:Ii,gauge2:fa,pipette:Za,fan:ra,bath:ci,footprints:la,"alarm-smoke":ei,"shield-alert":_o,vibrate:Jo,wifi:$o,"volume-2":Yo,lightbulb:Ca,flashlight:sa};function Nk(e){return Object.hasOwn(Mk,e)?Mk[e]:void 0}var Pk=Object.values(G).map(e=>{let t=Ak(e);return{id:e,label:t.label,icon:t.icon}});function Fk(){return Pk}function Ik(e){return e.parentDeviceId===null?`top-level`:e.role?`accessory`:`adopted`}var Lk={minimal:{showIntegrationIcon:!1,showParentBadge:!1,showSnapshot:!1,showBattery:!1,showStableId:!1,showId:!1,showSwitchToggle:!0,showChildrenAccordion:!1},compact:{showIntegrationIcon:!0,showParentBadge:!0,showSnapshot:!0,showBattery:!0,showStableId:!1,showId:!1,showSwitchToggle:!0,showChildrenAccordion:!0},expanded:{showIntegrationIcon:!1,showParentBadge:!0,showSnapshot:!0,showBattery:!0,showStableId:!0,showId:!0,showSwitchToggle:!0,showChildrenAccordion:!0}};function Rk(e){let t=Lk[e.variant??`compact`];return{showIntegrationIcon:e.showIntegrationIcon??t.showIntegrationIcon,showParentBadge:e.showParentBadge??t.showParentBadge,showSnapshot:e.showSnapshot??t.showSnapshot,showBattery:e.showBattery??t.showBattery,showStableId:e.showStableId??t.showStableId,showId:e.showId??t.showId,showSwitchToggle:e.showSwitchToggle??t.showSwitchToggle,showChildrenAccordion:e.showChildrenAccordion??t.showChildrenAccordion}}function zk(e){if(e.display?.icon){let t=Nk(e.display.icon);if(t)return t}return e.role?jk(e.role).icon:Ak(e.type).icon}var Bk=[` — `,` `];function Vk(e,t){if(t.length===0)return e;for(let n of Bk){let r=`${t}${n}`;if(e.startsWith(r))return e.slice(r.length)}return e}function Hk(e,t){return e.display?.label?e.display.label:Vk(e.name,t)}var Uk={"native-snapshot":va,"two-way-audio":Ia,"pan-tilt-zoom":Ki,"ptz-autotrack":Da,"doorbell-button":Yi,"motion-trigger":Qr,"battery-operated":pi,rebootable:co},Wk={"native-snapshot":`Native snapshot`,"two-way-audio":`Two-way audio`,"pan-tilt-zoom":`Pan-Tilt-Zoom`,"ptz-autotrack":`PTZ autotrack`,"doorbell-button":`Doorbell button`,"motion-trigger":`Motion trigger`,"battery-operated":`Battery operated`,rebootable:`Rebootable`},Gk={"native-snapshot":`snapshot`,rebootable:`reboot`,"pan-tilt-zoom":`ptz`,"ptz-autotrack":`ptz-autotrack`,"two-way-audio":`intercom`,"motion-trigger":`motion-trigger`},Kk=new Set([`camera`,`hub`,`nvr`]);function qk(e){return!Kk.has(e.type.toLowerCase())}function Jk(e){return e.role?!0:!Kk.has(e.type.toLowerCase())}function Yk(e){return(e.features??[]).includes(`motion-trigger`)}function Xk(e,t){if(e.type!==G.Container)return e.online;let n=t??[];if(n.length===0)return e.online;let r=yk(n,e.linkDeviceId,e.primaryChildEntityId);if(r===null)return e.online;let i=n.find(e=>e.id===r.id);return i===void 0?e.online:i.online}function Zk(e,t){if(e.type!==G.Container)return e.type;let n=t??[];if(n.length===0)return e.type;let r=yk(n,e.linkDeviceId,e.primaryChildEntityId);if(r===null)return e.type;let i=n.find(e=>e.id===r.id);return i===void 0?e.type:i.type}function Qk(e,t){if(e.type!==G.Container)return e;let n=t??[];if(n.length===0)return e;let r=yk(n,e.linkDeviceId,e.primaryChildEntityId);return r===null?e:n.find(e=>e.id===r.id)??e}function $k(e){if(e.length<=24)return e;let t=e.lastIndexOf(`:`);if(t>=0&&t<e.length-4)return e.slice(t+1);let n=e.split(`-`);if(n.length>2){let e=n.slice(-2).join(`-`);if(e.length>=6)return e}return`…${e.slice(-18)}`}h();function eA(e){return e instanceof Error?e.message:String(e)}function tA({trpc:e,deviceId:t,deviceName:n}){let{dev:r,cap:i}=Q({trpc:e,deviceId:t,cap:e=>e.reboot,slice:()=>void 0}),[a,o]=k(!1),[s,c]=k(!1),[l,u]=k(null);if(r===null||i==null)return null;let d=e=>{e.stopPropagation(),u(null),o(!0)},f=async()=>{if(!s){u(null),c(!0);try{await i.reboot({}),o(!1)}catch(e){u(eA(e))}finally{c(!1)}}};return g(w,{children:[N(`button`,{type:`button`,onClick:d,className:X(`inline-flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,a&&`bg-surface-hover text-foreground`),title:`Reboot device`,"aria-label":`Reboot device`,"aria-haspopup":`dialog`,"aria-expanded":a,children:N(co,{className:`h-3 w-3`})}),N(Ms,{open:a,onOpenChange:e=>{s||o(e)},children:g(Fs,{width:`sm`,onClick:e=>e.stopPropagation(),children:[g(Is,{children:[g(Rs,{className:`flex items-center gap-2`,children:[N(co,{className:`h-4 w-4 text-amber-400`}),`Reboot device?`]}),g(zs,{children:[`This will restart `,n,`. It may be unavailable for a moment.`]})]}),l!==null&&N(`div`,{className:`mt-2 px-3 py-2 rounded border border-danger/40 bg-danger/10 text-xs text-danger`,children:l}),g(Ls,{children:[N(ps,{type:`button`,variant:`ghost`,size:`sm`,disabled:s,onClick:()=>{s||o(!1)},children:`Cancel`}),g(ps,{type:`button`,variant:`danger`,size:`sm`,disabled:s,onClick:()=>{f()},children:[s&&N(Ea,{className:`h-3.5 w-3.5 animate-spin`}),`Reboot`]})]})]})})]})}h();var nA=[],rA=c(null);function iA({value:e,children:t}){return N(rA.Provider,{value:e,children:t})}function aA(e){return p(rA)?.get(e)??nA}h(),rt();var oA=new Set([G.Sensor,G.Presence]);function sA({trpc:e,device:t,controlPlacement:n}){let r=aA(t.id),i=n??`right`;if(t.disabled)return null;if(t.type===G.Container){let n=yk(r,t.linkDeviceId,t.primaryChildEntityId),a=n===null?void 0:r.find(e=>e.id===n.id);return a===void 0?null:N(cA,{trpc:e,child:a,placement:i})}let a=oA.has(t.type),o=(a?null:dk(t.type))?.InlineControl??null,s=fk(t.type,i),c=Yk(t),l=(t.features??[]).includes(`rebootable`),u=(t.features??[]).includes(`pan-tilt-zoom`);return g(w,{children:[a&&g(iu,{align:fk(t.type,i),children:[c&&N(lA,{trpc:e,deviceId:t.id,features:t.features}),N(Gw,{trpc:e,device:t})]}),o!==null&&g(iu,{align:s,onClick:e=>e.stopPropagation(),children:[c&&N(lA,{trpc:e,deviceId:t.id,features:t.features}),N(o,{trpc:e,deviceId:t.id,features:t.features})]}),!a&&o===null&&c&&N(lA,{trpc:e,deviceId:t.id,features:t.features}),u&&N(fA,{trpc:e,deviceId:t.id}),l&&N(tA,{trpc:e,deviceId:t.id,deviceName:t.name})]})}function cA({trpc:e,child:t,placement:n}){if(oA.has(t.type))return N(iu,{align:fk(t.type,n),children:N(Gw,{trpc:e,device:t})});let r=dk(t.type)?.InlineControl??null;return r===null?null:N(iu,{align:fk(t.type,n),onClick:e=>e.stopPropagation(),children:N(r,{trpc:e,deviceId:t.id,features:t.features})})}function lA({trpc:e,deviceId:t,features:n}){let{dev:r,cap:i,slice:a,available:o}=Q({trpc:e,deviceId:t,cap:e=>e.motionTrigger,slice:e=>e.state.motionTrigger,requireFeature:`motion-trigger`,deviceFeatures:n}),[s,c]=k(!1);if(r!==null&&!i)return null;let l=a?.enabled===!0,u=async e=>{if(e.stopPropagation(),!(s||!o||!i)){c(!0);try{await i.setMotionTrigger({enabled:!l})}finally{c(!1)}}};return N(`button`,{type:`button`,onClick:e=>{u(e)},disabled:s||!o,className:X(`inline-flex h-4 w-4 items-center justify-center rounded transition-colors flex-shrink-0`,l?`text-primary bg-primary/10`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,(s||!o)&&`opacity-50`),title:o?l?`Motion-trigger: on (click to disable)`:`Motion-trigger: off (click to enable)`:`Awaiting state…`,"aria-pressed":l,children:N(Qr,{className:`h-2.5 w-2.5`})})}var uA=4,dA=300;function fA({trpc:e,deviceId:t}){let n=f(null),r=f(null),[i,a]=k(null),o=i!==null,s=Ql(e,t,{enabled:o}),c=()=>a(null),l=()=>{let e=n.current;if(!e)return;let t=e.getBoundingClientRect(),r=Math.min(dA,window.innerWidth-16),i=Math.max(8,Math.min(t.right-r,window.innerWidth-r-8)),o=t.bottom+uA;a({top:o,left:i,width:r,maxHeight:Math.max(160,window.innerHeight-o-8)})};return P(()=>{if(!o)return;let e=e=>{let t=n.current,i=r.current,a=e.target;a!==null&&(t&&t.contains(a)||i&&i.contains(a)||c())},t=e=>{e.key===`Escape`&&(e.stopPropagation(),c())};return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e),document.removeEventListener(`keydown`,t)}},[o]),g(w,{children:[N(`button`,{ref:n,type:`button`,onClick:e=>{e.stopPropagation(),o?c():l()},className:X(`inline-flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,o&&`bg-surface-hover text-foreground`),title:`PTZ controls`,"aria-label":`PTZ controls`,"aria-haspopup":`dialog`,"aria-expanded":o,children:N(da,{className:`h-3 w-3`})}),i&&it(N(`div`,{ref:r,style:{position:`fixed`,top:i.top,left:i.left,width:i.width,maxHeight:i.maxHeight},className:`z-[9999] overflow-y-auto rounded-lg border border-border bg-surface shadow-lg shadow-black/30`,onClick:e=>e.stopPropagation(),children:N(eu,{mode:`panel`,controls:s})}),document.body)]})}h();function pA({trpc:e,accessoryChildren:t,adoptedChildren:n,onNavigate:r,parentName:i}){return g(`div`,{className:`border-t border-border-subtle/50`,children:[n.length>0&&N(mA,{trpc:e,label:`Adopted devices`,rows:n,onNavigate:r,parentName:i}),t.length>0&&N(mA,{trpc:e,label:`Accessories`,rows:t,onNavigate:r,parentName:i})]})}function mA({trpc:e,label:t,rows:n,onNavigate:r,parentName:i}){return g(`div`,{children:[N(`div`,{className:`px-3 pt-1.5 pb-1 text-[9px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:t}),N(`ul`,{children:n.map(t=>N(hA,{trpc:e,child:t,onNavigate:r,parentName:i},t.id))})]})}function hA({trpc:e,child:t,onNavigate:n,parentName:r}){let i=!t.disabled,a=i&&qk(t),o=i&&Yk(t);return N(`li`,{children:g(`div`,{onClick:e=>{e.stopPropagation(),n(t.id)},className:`w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-surface-hover transition-colors cursor-pointer`,children:[N(zk(t),{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),N(`span`,{className:`text-[10.5px] text-foreground flex-1 truncate`,children:Hk(t,r)}),o&&N(_A,{trpc:e,deviceId:t.id,features:t.features}),a&&N(gA,{trpc:e,deviceId:t.id}),N(`span`,{className:X(`h-1.5 w-1.5 rounded-full flex-shrink-0`,t.online?`bg-success`:`bg-foreground-subtle/40`),title:t.online?`Online`:`Offline`})]})})}function gA({trpc:e,deviceId:t}){let{dev:n,cap:r,slice:i,available:a}=Q({trpc:e,deviceId:t,cap:e=>e.switch,slice:e=>e.state.switch}),[o,s]=k(!1);if(n!==null&&!r)return null;let c=i?.on===!0,l={transform:c?`translateX(14px)`:`translateX(2px)`},u=async e=>{if(e.stopPropagation(),!(o||!a||!r)){s(!0);try{await r.setState({on:!c})}finally{s(!1)}}};return N(`button`,{type:`button`,onClick:e=>{u(e)},disabled:o||!a,className:X(`relative inline-flex h-4 w-7 items-center rounded-full border transition-colors flex-shrink-0`,c?`bg-success/30 border-success/50`:`bg-surface-hover border-border`,o&&`opacity-60`,!a&&`opacity-40 cursor-not-allowed`),title:a?c?`Turn off`:`Turn on`:`Awaiting state…`,"aria-pressed":c,children:N(`span`,{className:X(`absolute h-3 w-3 rounded-full transition-all`,c?`bg-success`:`bg-foreground-subtle`),style:l})})}function _A({trpc:e,deviceId:t,features:n}){let{dev:r,cap:i,slice:a,available:o}=Q({trpc:e,deviceId:t,cap:e=>e.motionTrigger,slice:e=>e.state.motionTrigger,requireFeature:`motion-trigger`,deviceFeatures:n}),[s,c]=k(!1);if(r!==null&&!i)return null;let l=a?.enabled===!0,u=async e=>{if(e.stopPropagation(),!(s||!o||!i)){c(!0);try{await i.setMotionTrigger({enabled:!l})}finally{c(!1)}}};return N(`button`,{type:`button`,onClick:e=>{u(e)},disabled:s||!o,className:X(`inline-flex h-4 w-4 items-center justify-center rounded transition-colors flex-shrink-0`,l?`text-primary bg-primary/10`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,(s||!o)&&`opacity-50`),title:o?l?`Motion-trigger: on (click to disable)`:`Motion-trigger: off (click to enable)`:`Awaiting state…`,"aria-pressed":l,children:N(Qr,{className:`h-2.5 w-2.5`})})}function vA({icon:e,label:t,onClick:n,danger:r=!1}){return N(`button`,{type:`button`,"aria-label":t,title:t,onClick:n,className:X(`inline-flex h-6 w-6 items-center justify-center rounded transition-colors flex-shrink-0`,r?`text-danger hover:bg-danger/10`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`),children:N(e,{className:`h-3.5 w-3.5`})})}function yA({device:e,onDelete:t}){let n=Cl(),r=async()=>{await n({title:`Delete device?`,message:`This will remove "${e.name.trim()===``?`#${String(e.id)}`:e.name}" and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&t(e)};return N(`span`,{onClick:e=>e.stopPropagation(),children:N(vA,{icon:Bo,label:`Delete device`,danger:!0,onClick:()=>{r()}})})}h();var bA=Object.freeze([]);function xA(e){return e===`native`?`native`:`enhanced`}function SA(e){return e.map(e=>({kind:`marker`,feature:e}))}function CA(e,t){let n=new Map,r=t.entries??[];for(let e of r)n.set(e.capName,e);let i=[];for(let t of e){let e=Gk[t];if(e===void 0){i.push({kind:`marker`,feature:t});continue}let r=n.get(e);r&&i.push({kind:xA(r.kind),feature:t,capName:e})}return i}function wA(e,t,n){let[r,i]=k(null),[a,o]=k(!1),[s,c]=k(!0);return P(()=>{if(t===null){i(null),o(!1),c(!1);return}let n=!1;c(!0),o(!1);let r=async()=>{try{let r=await e.deviceManager.getBindings.query({deviceId:t});if(n)return;i(r),c(!1)}catch{if(n)return;o(!0),c(!1)}};r();let a=e.live?.onEvent.subscribe({category:`capability.binding-changed`},{onData:e=>{let n=e.data?.source;if(!n){r();return}n.type===`device`&&n.id===t&&r()}});return()=>{n=!0,a?.unsubscribe()}},[e,t]),n.length===0?{loading:s,resolved:bA}:s||a||!r?{loading:s,resolved:SA(n)}:{loading:!1,resolved:CA(n,r)}}h(),rt();var TA=[];function EA({trpc:e,device:t,flags:n,accessoryCount:r,adoptedCount:i,showFeatureRow:a=!1}){let o=r+i,s=n.showChildrenAccordion&&o>0,c=t.features??TA,l=a&&c.length>0,{resolved:u}=wA(e,l?t.id:null,c),d=l&&u.length>0;return!s&&!d?null:g(`div`,{className:`flex items-center gap-1.5 flex-nowrap whitespace-nowrap min-w-0`,children:[s&&N(DA,{accessoryCount:r,adoptedCount:i}),d&&N(AA,{resolved:u})]})}function DA({accessoryCount:e,adoptedCount:t}){let n=e+t;return n===0?null:g(`span`,{className:`text-[9px] font-medium text-foreground-subtle bg-surface-elevated/60 rounded px-1.5 py-0.5 flex-shrink-0`,title:t>0&&e>0?`${String(t)} adopted · ${String(e)} accessor${e===1?`y`:`ies`}`:t>0?`${String(t)} adopted`:`${String(e)} accessor${e===1?`y`:`ies`}`,children:[`+`,n]})}var OA=240,kA=200;function AA({resolved:e}){let t=f(null),[n,r]=k(null);return g(`span`,{ref:t,className:`relative inline-flex items-center gap-1 cursor-help`,onMouseEnter:()=>{let e=t.current;if(!e)return;let n=e.getBoundingClientRect();r({top:window.innerHeight-n.bottom>=kA?n.bottom+4:n.top-kA-4,left:Math.max(8,Math.min(n.left,window.innerWidth-OA-8))})},onMouseLeave:()=>r(null),children:[e.map(e=>{let t=Uk[e.feature];return t?N(`span`,{className:`inline-flex items-center justify-center h-4 w-4 rounded bg-surface-elevated/60 text-foreground-subtle`,title:Wk[e.feature]??e.feature,children:N(t,{className:`h-2.5 w-2.5`})},e.feature):null}),n&&it(N(jA,{resolved:e,position:n}),document.body)]})}function jA({resolved:e,position:t}){return g(`div`,{style:{position:`fixed`,top:t.top,left:t.left,width:OA,pointerEvents:`none`},className:`z-[9999] rounded-md border border-border bg-surface shadow-lg shadow-black/30 p-2`,children:[N(`h5`,{className:`text-[9px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5`,children:`Features`}),N(`ul`,{className:`space-y-0.5`,children:e.map(e=>N(MA,{entry:e},e.feature))})]})}function MA({entry:e}){let t=Uk[e.feature],n=Wk[e.feature]??e.feature;return g(`li`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[g(`span`,{className:`flex items-center gap-1.5 text-foreground`,children:[t&&N(t,{className:`h-3 w-3 text-foreground-subtle`}),N(`span`,{children:n})]}),N(NA,{kind:e.kind})]})}function NA({kind:e}){return e===`marker`?N(`span`,{className:`text-[8.5px] px-1 rounded text-foreground-subtle`,title:`Informational marker (no cap registered)`,children:`marker`}):N(`span`,{className:X(`text-[8.5px] px-1 rounded`,e===`native`?`bg-success/15 text-success`:`bg-primary/15 text-primary`),children:e})}var PA={horizontal:`h-3.5 w-3.5`,stacked:`h-4 w-4 mt-0.5`};function FA({device:e,variant:t,flags:n,parent:r,integrationIcon:i,hasChildren:a,expanded:o,onToggleExpand:s,onNavigateToParent:c,stacked:l=!1}){let u=zk(Qk(e,aA(e.id))),d=l?PA.stacked:PA.horizontal;return g(`div`,{className:X(l?`flex items-start gap-2 w-full min-w-0`:`flex items-center gap-2 flex-1 min-w-0`),children:[n.showChildrenAccordion&&a?N(`button`,{type:`button`,"data-testid":`chevron-slot`,onClick:e=>{e.stopPropagation(),s()},className:X(`flex items-center justify-center text-foreground-subtle hover:text-foreground transition-colors flex-shrink-0`,d),"aria-label":o?`Collapse children`:`Expand children`,"aria-expanded":o,children:N(o?Re:Ue,{className:`h-3 w-3`})}):n.showChildrenAccordion?N(`span`,{"data-testid":`chevron-slot`,className:X(`flex-shrink-0`,d)}):null,N(u,{className:X(`text-foreground-subtle flex-shrink-0`,l?`h-4 w-4 mt-0.5`:t===`minimal`?`h-3 w-3`:`h-3.5 w-3.5`)}),g(`div`,{className:`flex-1 min-w-0`,children:[g(`div`,{className:X(`min-w-0`,l?`flex flex-col gap-1`:`flex items-center gap-1.5`),children:[n.showIntegrationIcon&&i&&N(`span`,{className:`flex-shrink-0`,children:i}),N(`span`,{className:X(`font-semibold text-foreground`,l?`text-[13px] leading-snug line-clamp-2 break-words`:X(`truncate`,t===`minimal`?`text-[10.5px]`:`text-[11px]`)),title:e.name,children:e.name})]}),(n.showId||n.showStableId)&&g(`div`,{className:`mt-0.5 flex items-center gap-1 text-[9px] text-foreground-subtle font-mono truncate`,title:n.showStableId?`stableId: ${e.stableId}`:void 0,children:[n.showId&&g(`span`,{className:`flex-shrink-0 tabular-nums`,children:[`#`,String(e.id)]}),n.showId&&n.showStableId&&N(`span`,{className:`flex-shrink-0 opacity-50`,children:`·`}),n.showStableId&&N(`span`,{className:`truncate`,children:$k(e.stableId)})]}),n.showParentBadge&&r&&g(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c(r.id)},className:`mt-0.5 inline-flex max-w-full items-center gap-1 text-[9px] text-foreground-subtle hover:text-primary transition-colors`,title:`Open parent: ${r.name} (#${String(r.id)})`,children:[N(qa,{className:`h-2.5 w-2.5 shrink-0`}),g(`span`,{className:`truncate`,children:[`Under: `,r.name]})]})]})]})}function IA(e,t){return He(e,t,e=>e.battery)??null}h();function LA(e,t){let n=Fe(e,t),r=f(!1),{data:i,isLoading:a,isFetching:o,refetch:s}=C({queryKey:[`device`,t,`snapshot`],queryFn:()=>{if(!n)throw Error(`useDeviceSnapshotImage: device proxy not ready`);let e=r.current;return r.current=!1,n.snapshot?.getSnapshot({force:e})??null},enabled:n!==null&&t!==null,staleTime:1e4,gcTime:1440*60*1e3,refetchOnWindowFocus:!1,refetchOnReconnect:!1,retry:!1}),c=i?`data:${i.contentType};base64,${i.base64}`:null;function l(){r.current=!0,s()}return{src:c,loading:a||o,refresh:l}}var RA=50;function zA(e){return e<=10?fi:e<=30?ui:e<=70?di:li}function BA(e,t){return t===`none`?e<=10?`text-rose-400`:e<=30?`text-amber-400`:`text-foreground-subtle`:`text-emerald-400`}function VA({status:e,variant:t=`compact`,className:n}){if(!e)return null;if(e.binary===!0){let t=e.percentage<RA,r=t?fi:li;return g(`span`,{className:X(`inline-flex items-center gap-1 text-[10px] font-medium`,t?`text-rose-400`:`text-foreground-subtle`,n),title:`Battery: ${t?`low`:`normal`}`,children:[N(r,{className:`h-3.5 w-3.5`}),N(`span`,{children:t?`Low`:`Normal`})]})}let r=zA(e.percentage),i=BA(e.percentage,e.charging),a=e.charging===`solar`?No:e.charging===`dc`?eo:null,o=e.sleeping;return g(`span`,{className:X(`inline-flex items-center gap-1 text-[10px] font-medium`,i,n),title:`Battery: ${Math.round(e.percentage)}%`+(e.charging===`none`?``:` · charging (${e.charging})`)+(e.sleeping?` · sleeping`:``),children:[N(r,{className:`h-3.5 w-3.5`}),g(`span`,{children:[Math.round(e.percentage),`%`]}),a&&N(a,{className:`h-3 w-3`}),o&&N(Ba,{className:`h-3 w-3 text-blue-300`}),t===`full`&&e.charging!==`none`&&N(`span`,{className:`text-foreground-subtle`,children:e.charging})]})}h(),rt();var HA=288,UA=196,WA=`h-7 w-7 rounded`,GA=8,KA=8;function qA({src:e,alt:t,caption:n,placeholder:r=`No image`,thumbClassName:i=WA,expandedWidth:a=HA,expandedHeight:o=UA}){let s=f(null),[c,l]=k(null),[d,p]=k(!1);P(()=>{p(!1)},[e]);let m=e!==null&&!d,h=e??void 0,_=u(()=>{let e=s.current;if(!e)return;let t=e.getBoundingClientRect(),n=t.top,r=window.innerHeight-t.bottom,i=n<o+GA&&r>n?t.bottom+GA:t.top-o-GA,c=t.right-a;l({top:i,left:Math.max(KA,Math.min(c,window.innerWidth-a-KA))})},[a,o]),v=u(()=>l(null),[]);return g(w,{children:[N(`button`,{ref:s,type:`button`,onClick:e=>e.stopPropagation(),onMouseEnter:_,onMouseLeave:v,onFocus:_,onBlur:v,"aria-label":t,className:`flex flex-shrink-0 items-center justify-center overflow-hidden border border-border bg-background text-foreground-subtle transition-colors hover:bg-surface-hover ${i}`,children:m?N(`img`,{src:h,alt:``,onError:()=>p(!0),className:`h-full w-full object-cover`}):N(_a,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})}),c&&it(g(`div`,{"aria-hidden":`true`,style:{position:`fixed`,top:c.top,left:c.left,width:a,pointerEvents:`none`},className:`z-[9999] overflow-hidden rounded-lg border border-border bg-surface shadow-lg shadow-black/30`,children:[N(`div`,{className:`flex h-40 items-center justify-center bg-background`,children:m?N(`img`,{src:h,alt:t,className:`h-full w-full object-cover`}):N(`span`,{className:`text-xs text-foreground-subtle`,children:r})}),N(`div`,{className:`px-3 py-2`,children:N(`p`,{className:`truncate text-xs font-semibold text-foreground`,children:n??t})})]}),document.body)]})}function JA({trpc:e,device:t,status:n,enabled:r,showStatusPills:i=!1}){let a=LA(e,r&&t.online?t.id:null),o=(t.features??[]).includes(`battery-operated`),s=i&&o&&!t.disabled,c=IA(e,s?t.id:null);if(!r&&!s)return null;let l=n===`offline`||n===`disabled`,u=n===`offline`?`Offline — no snapshot`:n===`disabled`?`Disabled`:`No snapshot yet`;return g(`span`,{className:`inline-flex items-center gap-1.5 flex-nowrap whitespace-nowrap`,children:[s&&c&&N(VA,{status:c}),r&&N(qA,{src:l?null:a.src,alt:t.name,placeholder:u,thumbClassName:`h-7 w-7 rounded`})]})}function YA(e,t){if(e===`disabled`)return`Disabled`;if(e===`online`)return`Online`;let n=mr(t);return n===null?`Offline`:`Offline · last seen ${n}`}function XA({status:e,lastChangedAt:t}){return N(`span`,{className:X(`h-1.5 w-1.5 rounded-full flex-shrink-0`,e===`disabled`?`bg-warning`:e===`online`?`bg-success`:`bg-danger`),title:YA(e,t)})}var ZA=`Disabled`;function QA(e,t,n){let r=t.filter(e=>e.disabled!==!0),i=$A(t.filter(e=>e.disabled===!0));if(n===void 0||n.length===0)return{sections:[],ungrouped:r,disabledSection:i};let a=new Map;for(let e of r)a.set(e.stableId,e);let o=[],s=new Map,c=new Set;for(let t of n){let n=`${e}-${t.childKey}`,r=a.get(n);if(r===void 0)continue;let i=s.get(t.section);i===void 0&&(i={title:t.section,entries:[],collapsed:!1},s.set(t.section,i),o.push(t.section)),i.entries.push({child:r,order:t.order??2**53-1}),t.collapsed===!0&&(i.collapsed=!0),c.add(r.id)}return{sections:o.map(e=>{let t=s.get(e),n=[...t===void 0?[]:t.entries].toSorted((e,t)=>e.order===t.order?e.child.name.localeCompare(t.child.name):e.order-t.order),r=t===void 0?!0:!t.collapsed;return{title:e,children:n.map(e=>e.child),defaultOpen:r}}),ungrouped:r.filter(e=>!c.has(e.id)),disabledSection:i}}function $A(e){if(e.length!==0)return{title:ZA,children:[...e].toSorted((e,t)=>e.name.localeCompare(t.name)),defaultOpen:!1,muted:!0}}h();function ej({title:e,count:t,children:n,defaultOpen:r=!0}){let[i,a]=k(r);return g(`div`,{className:`rounded-md border border-border-subtle/50`,children:[g(`button`,{type:`button`,onClick:()=>a(e=>!e),className:X(`w-full flex items-center gap-1.5 px-2 py-1.5 text-left transition-colors`,`hover:bg-surface-hover`),"aria-expanded":i,children:[N(i?Re:Ue,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),N(`span`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle flex-1 truncate`,children:e}),N(`span`,{className:`text-[10px] font-medium text-foreground-subtle/70 tabular-nums`,children:t})]}),i&&N(`div`,{className:`space-y-1 px-1 pb-1.5`,children:n})]})}h();function tj(e){let{trpc:t,device:n,parent:r,integrationIcon:i,onNavigate:a,className:o,renderRowAction:s,onDelete:c,selection:l}=e,u=Rk(e),d=e.variant??`compact`,f=e.view??`card`,p=!n.disabled,m=n.isCamera??n.type.toLowerCase()===`camera`,h=e.children??[],_=h.filter(Jk),v=h.filter(e=>!Jk(e)),y=h.length>0,[b,x]=k(!1),S=e.expanded??b,C=e.onToggleExpand??(()=>x(e=>!e)),w=e=>{a?.(e)},T=e.rowClickSelects===!0&&l!==void 0,E=()=>{if(T&&l!==void 0){l.onToggle();return}w(n.id)},D=e.indentLevel??(e.isAccessoryRow?2:0),O=Xk(n,h),A=p?O?`online`:`offline`:`disabled`;return f===`table`?N(rj,{trpc:t,device:n,variant:d,flags:u,parent:r??null,integrationIcon:i??null,accessoryCount:_.length,adoptedCount:v.length,hasChildren:y,expanded:S,onToggleExpand:C,onRowClick:E,rowSelects:T,rowSelected:l?.selected??!1,onNavigate:w,displayStatus:A,isCamera:m,showSnapshot:u.showSnapshot&&m,isAccessoryRow:e.isAccessoryRow??!1,indentLevel:D,className:o,renderRowAction:s??null,onDelete:c??null,selection:l,showTypeCell:e.showTypeCell??!0,showManufacturerCell:e.showManufacturerCell??!0,showFeaturesCell:e.showFeaturesCell??!0}):d===`minimal`?g(`div`,{className:X(`rounded-lg border border-border bg-surface transition-colors`,!p&&`opacity-60`,o),children:[g(`div`,{"data-testid":`device-card-body`,onClick:E,...T?{role:`button`,"aria-pressed":l?.selected??!1,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),E())}}:{},className:X(`flex items-center gap-2 cursor-pointer hover:border-foreground-subtle/30 w-full px-2.5 py-1.5`,l?.selected&&`bg-primary/10`),children:[l&&N(`input`,{type:`checkbox`,checked:l.selected,onChange:l.onToggle,onClick:e=>e.stopPropagation(),"aria-label":`Select ${n.name}`,className:`flex-shrink-0`}),N(FA,{device:n,variant:d,flags:u,parent:r??null,integrationIcon:i??null,hasChildren:y,expanded:S,onToggleExpand:C,onNavigateToParent:w}),N(EA,{trpc:t,device:n,flags:u,accessoryCount:_.length,adoptedCount:v.length,showFeatureRow:!1}),N(JA,{trpc:t,device:n,status:A,enabled:u.showSnapshot&&m,showStatusPills:!0}),N(sA,{trpc:t,device:n,flags:u,controlPlacement:`right`}),s&&N(`span`,{onClick:e=>e.stopPropagation(),children:s(n)}),N(XA,{status:A})]}),S&&y&&N(pA,{trpc:t,accessoryChildren:_,adoptedChildren:v,onNavigate:w,parentName:n.name})]}):g(`div`,{className:X(`group rounded-xl border border-border bg-surface transition-colors`,`hover:border-foreground-subtle/30`,!p&&`opacity-60`,o),children:[g(`div`,{"data-testid":`device-card-body`,onClick:E,...T?{role:`button`,"aria-pressed":l?.selected??!1,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),E())}}:{},className:X(`flex flex-col gap-2 cursor-pointer w-full p-3 rounded-xl`,l?.selected&&`bg-primary/10`),children:[g(`div`,{className:`flex items-start justify-between gap-2`,children:[l&&N(`input`,{type:`checkbox`,checked:l.selected,onChange:l.onToggle,onClick:e=>e.stopPropagation(),"aria-label":`Select ${n.name}`,className:`flex-shrink-0 mt-0.5`}),N(FA,{device:n,variant:d,flags:u,parent:r??null,integrationIcon:i??null,hasChildren:y,expanded:S,onToggleExpand:C,onNavigateToParent:w,stacked:!0}),N(XA,{status:A})]}),N(EA,{trpc:t,device:n,flags:u,accessoryCount:_.length,adoptedCount:v.length,showFeatureRow:!1}),g(`div`,{className:`flex items-center justify-end gap-1.5`,children:[N(JA,{trpc:t,device:n,status:A,enabled:u.showSnapshot&&m,showStatusPills:!0}),N(sA,{trpc:t,device:n,flags:u,controlPlacement:`right`}),s&&N(`span`,{onClick:e=>e.stopPropagation(),children:s(n)})]})]}),S&&y&&N(pA,{trpc:t,accessoryChildren:_,adoptedChildren:v,onNavigate:w,parentName:n.name})]})}var nj={0:`pl-2`,1:`pl-6`,2:`pl-8`};function rj(e){let{trpc:t,device:n,variant:r,flags:i,parent:a,integrationIcon:o,accessoryCount:s,adoptedCount:c,hasChildren:l,expanded:u,onToggleExpand:d,onNavigate:f,onRowClick:p,rowSelects:m,rowSelected:h,displayStatus:_,isCamera:v,showSnapshot:y,isAccessoryRow:b,indentLevel:x,className:S,renderRowAction:C,onDelete:w,selection:T,showTypeCell:E,showManufacturerCell:D,showFeaturesCell:O}=e,k=aA(n.id);return g(`tr`,{onClick:p,...m?{role:`button`,"aria-pressed":h,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),p())}}:{},className:X(`group cursor-pointer hover:bg-surface-hover transition-colors`,!l&&`border-b border-border-subtle/40`,b&&`bg-foreground-subtle/[0.03]`,h&&`bg-primary/10`,S),children:[N(`td`,{className:X(`sticky left-0 z-[1] py-1.5 align-middle pr-2 transition-colors`,h?`bg-primary/10 group-hover:bg-surface-hover`:b?`bg-surface-subtle group-hover:bg-surface-hover`:`bg-surface group-hover:bg-surface-hover`,`w-64 max-w-[16rem] min-w-0 overflow-hidden`,nj[x]),children:g(`div`,{className:`flex items-center gap-1.5`,children:[T&&N(`input`,{type:`checkbox`,checked:T.selected,onChange:T.onToggle,onClick:e=>e.stopPropagation(),"aria-label":`Select ${n.name}`,className:`flex-shrink-0`}),N(FA,{device:n,variant:r,flags:i,parent:a,integrationIcon:o,hasChildren:l,expanded:u,onToggleExpand:d,onNavigateToParent:f})]})}),E&&N(`td`,{className:X(zl.type,`px-2 py-1.5 align-middle text-[10px] text-foreground-subtle whitespace-nowrap`),children:Zk(n,k)}),D&&N(`td`,{className:X(zl.manufacturer,`px-2 py-1.5 align-middle w-40 max-w-[10rem] min-w-0 overflow-hidden`),children:N(Xl,{device:n})}),O&&N(`td`,{className:X(zl.features,`px-2 py-1.5 align-middle`),children:N(EA,{trpc:t,device:n,flags:i,accessoryCount:s,adoptedCount:c,showFeatureRow:!0})}),N(`td`,{className:`px-2 py-1.5 align-middle text-right whitespace-nowrap`,children:g(`span`,{className:`inline-flex items-center justify-end gap-1.5`,children:[N(sA,{trpc:t,device:n,flags:i,controlPlacement:`table`}),N(JA,{trpc:t,device:n,status:_,enabled:y&&v,showStatusPills:!0}),C&&N(`span`,{onClick:e=>e.stopPropagation(),children:C(n)}),w&&N(yA,{device:n,onDelete:w}),N(XA,{status:_})]})})]})}h();function ij({selectedIds:e,onClear:t,remove:n,disable:r,enable:i}){let[a,o]=k(!1);if(e.size===0)return null;let s=[...e],c=s.length;return g(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg border border-border bg-surface-hover`,children:[g(`span`,{className:`text-xs font-medium text-foreground-subtle shrink-0`,children:[c,` selected`]}),N(`div`,{className:`h-3.5 w-px bg-border shrink-0`,"aria-hidden":`true`}),g(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[N(`button`,{type:`button`,onClick:()=>{for(let e of s)r({deviceId:e});t()},className:X(`inline-flex items-center h-6 px-2.5 rounded-md border text-[10.5px] font-medium transition-colors`,`border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface`),children:`Disable`}),N(`button`,{type:`button`,onClick:()=>{for(let e of s)i({deviceId:e});t()},className:X(`inline-flex items-center h-6 px-2.5 rounded-md border text-[10.5px] font-medium transition-colors`,`border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface`),children:`Enable`}),a?g(w,{children:[g(`button`,{type:`button`,onClick:()=>{for(let e of s)n({deviceId:e});o(!1),t()},className:X(`inline-flex items-center h-6 px-2.5 rounded-md border text-[10.5px] font-medium transition-colors`,`border-red-500/50 bg-red-500/10 text-red-400 hover:bg-red-500/20`),children:[`Confirm delete `,c,`?`]}),N(`button`,{type:`button`,onClick:()=>{o(!1)},className:X(`inline-flex items-center h-6 px-2.5 rounded-md border text-[10.5px] font-medium transition-colors`,`border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface`),children:`Cancel`})]}):N(`button`,{type:`button`,onClick:()=>{o(!0)},className:X(`inline-flex items-center h-6 px-2.5 rounded-md border text-[10.5px] font-medium transition-colors`,`border-red-500/40 bg-red-500/10 text-red-400 hover:bg-red-500/20`),children:`Delete`}),N(`button`,{type:`button`,onClick:()=>{o(!1),t()},className:X(`inline-flex items-center h-6 px-2.5 rounded-md border text-[10.5px] font-medium transition-colors`,`border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface`),children:`Clear`})]})]})}h();function aj(e){let[t,n]=k(!1),r=f(null),i=e.selectedIds.size;return P(()=>{if(!t)return;let e=e=>{let t=e.target instanceof Node?e.target:null;t&&r.current&&!r.current.contains(t)&&n(!1)},i=e=>{e.key===`Escape`&&n(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e),document.addEventListener(`keydown`,i),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e),document.removeEventListener(`keydown`,i)}},[t]),i===0?null:g(w,{children:[N(`div`,{className:`hidden sm:block`,children:N(ij,{...e})}),g(`div`,{ref:r,"data-testid":`batch-actions-compact`,className:`relative sm:hidden`,children:[g(`button`,{type:`button`,onClick:()=>n(e=>!e),"aria-haspopup":`menu`,"aria-expanded":t,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full border border-primary/40 bg-primary/15 text-[10.5px] font-medium text-primary`,children:[g(`span`,{children:[`Actions · `,String(i)]}),N(Re,{className:`h-3 w-3 transition-transform ${t?`rotate-180`:``}`})]}),t&&N(`div`,{role:`menu`,className:`absolute left-0 top-full mt-1 z-30 rounded-lg border border-border bg-surface shadow-md`,children:N(ij,{...e})})]})]})}h();function oj(e,t){let[n,r]=k(e);return P(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}h();var sj=[25,50,100,200],cj=`camstack.device-list.pageSize`;function lj(e){return sj.includes(e)}function uj(e){return lj(e)?e:50}function dj(e){if(typeof window>`u`)return e;try{let t=window.localStorage.getItem(cj);if(t===null)return e;let n=Number.parseInt(t,10);return Number.isFinite(n)&&lj(n)?n:e}catch{return e}}function fj(e){if(!(typeof window>`u`))try{window.localStorage.setItem(cj,String(e))}catch{}}function pj(e){let t=uj(e),[n,r]=k(()=>dj(t));return[n,u(e=>{lj(e)&&(r(e),fj(e))},[])]}function mj(e){let t=new Map;for(let n of e)t.set(n.id,n);return e.filter(e=>{if(e.parentDeviceId===null||e.parentDeviceId===void 0)return!0;let n=t.get(e.parentDeviceId);return n?hj.has(n.type.toLowerCase()):!0})}var hj=new Set([`hub`,`nvr`]);function gj(e,t){let n=t?.includeHidden??!1,r=new Map;for(let t of e)r.set(t.id,t);let i=[],a=new Map;for(let t of e){if(!n&&t.display?.hidden===!0)continue;let e=t.parentDeviceId;if(e==null){i.push(t);continue}let o=r.get(e);if(!o){i.push(t);continue}let s=t.role!==null&&t.role!==void 0;if(hj.has(o.type)&&!s){i.push(t);continue}let c=a.get(e);c?c.push(t):a.set(e,[t])}return{topLevel:i,accessoriesByParent:a}}function _j(e){return e.toLowerCase().replace(/[-_\s]+/g,``)}function vj(e,t){let n=_j(e);return n===``?!0:_j(t).includes(n)}var yj=2;function bj(e,t){if(t<=1)return[{kind:`page`,n:1}];if(t<=7){let e=[];for(let n=1;n<=t;n++)e.push({kind:`page`,n});return e}let n=[],r=Math.max(2,e-yj),i=Math.min(t-1,e+yj);n.push({kind:`page`,n:1}),r>2&&n.push({kind:`ellipsis`,side:`left`});for(let e=r;e<=i;e++)n.push({kind:`page`,n:e});return i<t-1&&n.push({kind:`ellipsis`,side:`right`}),n.push({kind:`page`,n:t}),n}function xj({currentPage:e,totalItems:t,pageSize:n,onPageChange:r,itemNoun:i=`devices`}){if(t<=n)return null;let a=Math.ceil(t/n),o=(e-1)*n+1,s=Math.min(e*n,t),c=bj(e,a);return g(`div`,{className:`flex items-center justify-between gap-4 flex-wrap pt-2 text-[11px] text-foreground-subtle`,children:[g(`span`,{children:[`Showing `,o,`–`,s,` of `,t,` `,i]}),g(`span`,{className:`inline-flex items-center gap-1`,children:[N(`button`,{type:`button`,"aria-label":`Previous page`,disabled:e===1,onClick:()=>r(e-1),className:X(`inline-flex items-center justify-center h-7 w-7 rounded border border-border bg-surface text-foreground-subtle`,`hover:text-foreground hover:bg-surface-hover transition-colors`,`disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-surface`),children:N(wi,{className:`h-3 w-3`})}),c.map((t,n)=>t.kind===`ellipsis`?N(`span`,{className:`px-1 text-foreground-subtle/60 select-none`,children:`…`},`e-${n}`):N(`button`,{type:`button`,onClick:()=>r(t.n),className:X(`inline-flex items-center justify-center h-7 min-w-7 px-1.5 rounded border text-[10.5px] font-medium transition-colors`,t.n===e?`border-primary/40 bg-primary/10 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover`),children:t.n},`p-${t.n}`)),N(`button`,{type:`button`,"aria-label":`Next page`,disabled:e===a,onClick:()=>r(e+1),className:X(`inline-flex items-center justify-center h-7 w-7 rounded border border-border bg-surface text-foreground-subtle`,`hover:text-foreground hover:bg-surface-hover transition-colors`,`disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-surface`),children:N(Ue,{className:`h-3 w-3`})})]})]})}h();function Sj({label:e,options:t,selected:n,onChange:r}){let[i,a]=k(!1),o=f(null);P(()=>{if(!i)return;let e=e=>{let t=e.target instanceof Node?e.target:null;t&&o.current&&!o.current.contains(t)&&a(!1)},t=e=>{e.key===`Escape`&&a(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e),document.removeEventListener(`keydown`,t)}},[i]);let s=new Set(n),c=n.length,l=e=>{let n=new Set(s);n.has(e)?n.delete(e):n.add(e),r(t.filter(e=>n.has(e.id)).map(e=>e.id))};return g(`div`,{ref:o,className:`relative`,children:[g(`button`,{type:`button`,onClick:()=>a(e=>!e),"aria-haspopup":`listbox`,"aria-expanded":i,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full border text-[10.5px] font-medium transition-colors ${c>0?`border-primary/40 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[g(`span`,{children:[e,c>0?` · ${String(c)}`:``]}),N(Re,{className:`h-3 w-3 transition-transform ${i?`rotate-180`:``}`})]}),i&&g(`div`,{role:`listbox`,className:`absolute left-0 top-full mt-1 z-30 min-w-[180px] max-h-72 overflow-y-auto rounded-lg border border-border bg-surface shadow-xl py-1`,children:[c>0&&N(`button`,{type:`button`,onClick:()=>r([]),className:`flex w-full items-center px-3 py-1.5 text-left text-[10.5px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:`Clear selection`}),t.map(e=>{let t=s.has(e.id),n=e.icon;return g(`button`,{type:`button`,role:`option`,"aria-selected":t,onClick:()=>l(e.id),className:`flex w-full items-center gap-2 px-3 py-1.5 text-left text-[10.5px] text-foreground hover:bg-surface-hover`,children:[N(`span`,{className:`flex h-3.5 w-3.5 items-center justify-center rounded border shrink-0 ${t?`border-primary bg-primary`:`border-border`}`,children:t&&N(Ci,{className:`h-2.5 w-2.5 text-primary-foreground`})}),n&&N(n,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),N(`span`,{className:`truncate`,children:e.label})]},e.id)})]})]})}h();function Cj({label:e,options:t,selected:n,onChange:r}){let i=f(null),[a,o]=k(null);P(()=>{let e=i.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(e=>{let t=e[0];t&&o(t.contentRect.width)});return t.observe(e),()=>t.disconnect()},[]);let s=new Set(n),c=e=>{let n=new Set(s);n.has(e)?n.delete(e):n.add(e),r(t.filter(e=>n.has(e.id)).map(e=>e.id))},l=56+t.length*88;return N(`div`,{ref:i,className:`min-w-0 flex-1`,children:a!==null&&a>=l?g(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[N(`span`,{className:`text-[10px] font-medium uppercase tracking-wider text-foreground-subtle`,children:e}),t.map(e=>{let t=s.has(e.id),n=e.icon;return g(`button`,{type:`button`,onClick:()=>c(e.id),"aria-pressed":t,className:`inline-flex items-center gap-1 h-7 px-2.5 rounded-full border text-[10.5px] font-medium transition-colors ${t?`border-primary/40 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[n&&N(n,{className:`h-3 w-3 shrink-0`}),e.label]},e.id)})]}):N(Sj,{label:e,options:t,selected:n,onChange:r})})}h();function wj({view:e,onViewChange:t,hideView:n=!1,typeOptions:r,selectedTypes:i,onTypesChange:a,addons:o,selectedAddons:s,onAddonsChange:c,hideAddons:l=!1}){return g(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[!n&&e!==void 0&&t!==void 0&&g(`span`,{className:`inline-flex border border-border rounded-md overflow-hidden`,children:[N(`button`,{type:`button`,onClick:()=>t(`cards`),className:X(`inline-flex items-center justify-center h-7 w-8 transition-colors`,e===`cards`?`bg-primary/10 text-primary`:`bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover`),"aria-label":`Cards view`,children:N(xa,{className:`h-3.5 w-3.5`})}),N(`button`,{type:`button`,onClick:()=>t(`table`),className:X(`inline-flex items-center justify-center h-7 w-8 border-l border-border transition-colors`,e===`table`?`bg-primary/10 text-primary`:`bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover`),"aria-label":`Table view`,children:N(Fo,{className:`h-3.5 w-3.5`})})]}),r&&r.length>0&&N(Cj,{label:`Type`,options:r,selected:i,onChange:a}),!l&&o&&o.length>0&&N(Tj,{addons:o,selected:s,onChange:c})]})}function Tj({addons:e,selected:t,onChange:n}){let[r,i]=k(!1),a=f(null);P(()=>{if(!r)return;let e=e=>{let t=e.target;t&&a.current&&!a.current.contains(t)&&i(!1)},t=e=>{e.key===`Escape`&&i(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e),document.removeEventListener(`keydown`,t)}},[r]);let o=new Set(t),s=t.length,c=t=>{let r=new Set(o);r.has(t)?r.delete(t):r.add(t),n(e.filter(e=>r.has(e.id)).map(e=>e.id))};return g(`div`,{ref:a,className:`relative`,children:[g(`button`,{type:`button`,onClick:()=>i(e=>!e),className:X(`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full border text-[10.5px] font-medium transition-colors`,s>0?`border-primary/40 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover`),"aria-haspopup":`listbox`,"aria-expanded":r,children:[g(`span`,{children:[`Integration`,s>0?` · ${String(s)}`:``]}),N(Re,{className:X(`h-3 w-3 transition-transform`,r&&`rotate-180`)})]}),r&&g(`div`,{role:`listbox`,className:`absolute left-0 top-full mt-1 z-30 min-w-[180px] max-h-72 overflow-y-auto rounded-lg border border-border bg-surface shadow-xl py-1`,children:[s>0&&N(`button`,{type:`button`,onClick:()=>n([]),className:`flex w-full items-center px-3 py-1.5 text-left text-[10.5px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:`Clear selection`}),e.map(e=>{let t=o.has(e.id);return g(`button`,{type:`button`,role:`option`,"aria-selected":t,onClick:()=>c(e.id),className:X(`flex w-full items-center gap-2 px-3 py-1.5 text-left text-[10.5px] transition-colors`,t?`text-primary`:`text-foreground hover:bg-surface-hover`),children:[N(`span`,{className:X(`flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded border`,t?`border-primary bg-primary/20`:`border-border`),children:t&&N(Ci,{className:`h-2.5 w-2.5`})}),e.icon&&N(`span`,{className:`inline-flex items-center`,children:e.icon}),N(`span`,{className:`truncate`,children:e.name})]},e.id)})]})]})}function Ej({variant:e,onClearFilters:t}){return g(`div`,{className:`flex flex-col items-center justify-center py-12 text-center`,children:[N(ya,{className:`h-8 w-8 text-foreground-subtle/40 mb-3`}),N(`p`,{className:`text-sm font-medium text-foreground-subtle`,children:e===`filtered`?`No devices match the current filters`:`No devices yet`}),e===`filtered`&&t&&N(`button`,{type:`button`,onClick:t,className:`mt-2 text-[11px] text-primary hover:underline`,children:`Clear filters`})]})}h();function Dj(e){return e?e.split(`,`).map(e=>e.trim()).filter(e=>e.length>0):[]}function Oj(e,t){if(e===`root`)return t===`addons`?`addon`:t===`types`?`type`:t;switch(t){case`view`:return`deviceView`;case`page`:return`devicePage`;case`types`:return`deviceType`;case`q`:return`deviceQ`;case`addons`:return`deviceAddon`}}function kj(e){try{let t=localStorage.getItem(`camstack:${e}:lastFilters`);if(!t)return{};let n=JSON.parse(t);return typeof n!=`object`||!n?{}:n}catch{return{}}}function Aj(e,t){try{localStorage.setItem(`camstack:${e}:lastFilters`,JSON.stringify(t))}catch{}}function jj(e,t,n){let r=new URLSearchParams(window.location.search),i=r.get(Oj(e,`view`)),a=i===`cards`||i===`table`?i:n.view??t,o=r.get(Oj(e,`page`)),s=o?parseInt(o,10):1;return{view:a,page:Number.isFinite(s)&&s>=1?s:1,addons:Dj(r.get(Oj(e,`addons`))??n.addon??null),types:Dj(r.get(Oj(e,`types`))??n.type??null),q:r.get(Oj(e,`q`))??n.q??``}}function Mj(e,t,n){let r=new URLSearchParams(window.location.search),i=(e,t)=>{t===null||t===``?r.delete(e):r.set(e,t)};i(Oj(e,`view`),t.view===n?null:t.view),i(Oj(e,`page`),t.page===1?null:String(t.page)),i(Oj(e,`addons`),t.addons.length>0?t.addons.join(`,`):null),i(Oj(e,`types`),t.types.length>0?t.types.join(`,`):null),i(Oj(e,`q`),t.q||null);let a=r.toString(),o=a?`${window.location.pathname}?${a}`:window.location.pathname;window.history.replaceState(null,``,o)}function Nj(e){let{scope:t,defaultView:n,lsKey:r}=e,[i,a]=k(()=>jj(t,n,kj(r))),o=f(i);o.current=i,P(()=>{let e=()=>{let e=jj(t,n,kj(r));o.current=e,a(e)};return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[t,n,r]);let s=u(e=>{let i=e(o.current);o.current=i,a(i),Mj(t,i,n),Aj(r,{view:i.view,addon:i.addons.length>0?i.addons.join(`,`):null,type:i.types.length>0?i.types.join(`,`):null,q:i.q})},[t,n,r]);return{state:i,setView:u(e=>s(t=>({...t,view:e})),[s]),setPage:u(e=>s(t=>({...t,page:e})),[s]),setAddons:u(e=>s(t=>({...t,addons:e,page:1})),[s]),setTypes:u(e=>s(t=>({...t,types:e,page:1})),[s]),setQ:u(e=>s(t=>({...t,q:e,page:1})),[s]),clearFilters:u(()=>s(e=>({...e,addons:[],types:[],q:``,page:1})),[s])}}function Pj({rows:e,accessoriesByParent:t,trpc:n,resolveIntegrationIcon:r,resolveParent:i,onNavigate:a,renderRowAction:o,selectable:s,rowClickSelects:c,activeSelected:l,onToggleSelection:u}){return N(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3 items-stretch`,children:e.map(e=>{let d=t.get(e.id)??[],f=s?{selected:l.has(e.id),onToggle:()=>u(e.id)}:void 0;return N(tj,{trpc:n,device:e,view:`card`,integrationIcon:r?.(e.addonId)??null,parent:e.parentDeviceId===null?null:i?.(e.parentDeviceId)??null,children:d,onNavigate:a??void 0,renderRowAction:o??void 0,selection:f,rowClickSelects:c},e.id)})})}function Fj({columnId:e,label:t,sort:n,onSort:r}){let i=n!==null&&n.columnId===e;return g(`button`,{type:`button`,onClick:()=>r(e),className:`group/sort inline-flex items-center gap-0.5 uppercase tracking-wider hover:text-foreground transition-colors`,children:[N(`span`,{children:t}),i?n.dir===`asc`?N(Ti,{className:`h-3 w-3 flex-shrink-0`}):N(Re,{className:`h-3 w-3 flex-shrink-0`}):N(Ti,{className:X(`h-3 w-3 flex-shrink-0 opacity-0 transition-opacity`,`group-hover/sort:opacity-30`)})]})}h();function Ij(e,t){return e===null||e.columnId!==t?`none`:e.dir===`asc`?`ascending`:`descending`}var Lj=new Set([`hub`,`nvr`]);function Rj(e,t){return e.parentDeviceId===null||t===null?0:+!!Lj.has(t.toLowerCase())}function zj({rows:e,accessoriesByParent:t,autoExpandedParents:n,devices:r,visibleColumns:i,trpc:a,resolveIntegrationIcon:o,resolveParent:s,onNavigate:c,renderRowAction:l,onDeleteDevice:u,selectable:d,rowClickSelects:f,activeSelected:p,onToggleSelection:m,sort:h,onSort:_}){let v=i.includes(`type`),y=i.includes(`features`),x=i.includes(`manufacturer`),S=i.includes(`icon`),C=b(()=>{let e=new Map;for(let t of r)e.set(t.id,t.type);return e},[r]);return N(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:g(`table`,{className:`w-full border-collapse`,children:[N(`thead`,{children:g(`tr`,{className:`border-b border-border`,children:[N(`th`,{"aria-sort":Ij(h,`name`),className:`sticky left-0 z-[1] bg-surface text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-64 max-w-[16rem]`,children:N(Fj,{columnId:`name`,label:`Name`,sort:h,onSort:_})}),v&&N(`th`,{"aria-sort":Ij(h,`type`),className:X(zl.type,`text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-24`),children:N(Fj,{columnId:`type`,label:`Type`,sort:h,onSort:_})}),x&&N(`th`,{"aria-sort":Ij(h,`manufacturer`),className:X(zl.manufacturer,`text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-40`),children:N(Fj,{columnId:`manufacturer`,label:`Hardware`,sort:h,onSort:_})}),y&&N(`th`,{className:X(zl.features,`text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-32`),children:`Features`}),N(`th`,{className:`text-right px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-32`,children:`Preview`})]})}),N(`tbody`,{children:e.map(e=>{let r=t.get(e.id)??[],i=r.length>0,h=n.has(e.id),g=e.parentDeviceId===null?null:s?.(e.parentDeviceId)??null,_=e.parentDeviceId===null?null:C.get(e.parentDeviceId)??null,b=d?{selected:p.has(e.id),onToggle:()=>m(e.id)}:void 0;return N(Bj,{parent:e,accessories:r,hasAccessories:i,forceExpanded:h,trpc:a,integrationIcon:S?o?.(e.addonId)??null:null,showType:v,showManufacturer:x,showFeatures:y,parentRowParent:g,indentLevel:Rj(e,_),onNavigate:c??null,renderRowAction:l??null,onDeleteDevice:u,selection:b,rowClickSelects:f},e.id)})})]})})}function Bj({parent:e,accessories:t,hasAccessories:n,forceExpanded:r,trpc:i,integrationIcon:a,showType:o,showManufacturer:s,showFeatures:c,parentRowParent:l,indentLevel:u,onNavigate:d,renderRowAction:p,onDeleteDevice:m,selection:h,rowClickSelects:_}){let[v,y]=k(r),x=f(r);P(()=>{x.current!==r&&(y(r),x.current=r)},[r]);let S=()=>y(e=>!e),C=n&&v,T=b(()=>QA(e.stableId,t,e.childLayout),[e.stableId,e.childLayout,t]),[E,D]=k(()=>{let e=T.sections.filter(e=>!e.defaultOpen).map(e=>e.title);return T.disabledSection!==void 0&&!T.disabledSection.defaultOpen&&e.push(T.disabledSection.title),new Set(e)}),O=e=>D(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),A=2+ +!!o+ +!!s+ +!!c,j=T.disabledSection;return g(w,{children:[N(tj,{trpc:i,device:e,view:`table`,integrationIcon:a,parent:l,children:t,onNavigate:d??void 0,showChildrenAccordion:!0,expanded:v,onToggleExpand:S,indentLevel:u,renderRowAction:p??void 0,onDelete:m??void 0,selection:h,rowClickSelects:_,showTypeCell:o,showManufacturerCell:s,showFeaturesCell:c}),C&&T.ungrouped.map(t=>N(Vj,{trpc:i,accessory:t,parentName:e.name,showType:o,showManufacturer:s,showFeatures:c,onNavigate:d},t.id)),C&&T.sections.map(t=>{let n=!E.has(t.title);return N(Hj,{title:t.title,count:t.children.length,open:n,colSpan:A,onToggle:()=>O(t.title),rows:t.children,trpc:i,parentName:e.name,showType:o,showManufacturer:s,showFeatures:c,onNavigate:d},t.title)}),C&&j!==void 0&&N(Hj,{title:j.title,count:j.children.length,open:!E.has(j.title),colSpan:A,onToggle:()=>O(j.title),rows:j.children,trpc:i,parentName:e.name,showType:o,showManufacturer:s,showFeatures:c,onNavigate:d,muted:!0},j.title)]})}function Vj({trpc:e,accessory:t,parentName:n,showType:r,showManufacturer:i,showFeatures:a,onNavigate:o,muted:s}){return N(tj,{trpc:e,device:{...t,name:Hk(t,n)},view:`table`,integrationIcon:null,parent:null,isAccessoryRow:!0,showChildrenAccordion:!1,onNavigate:o??void 0,showTypeCell:r,showManufacturerCell:i,showFeaturesCell:a,className:s===!0?`opacity-60`:void 0})}function Hj({title:e,count:t,open:n,colSpan:r,onToggle:i,rows:a,trpc:o,parentName:s,showType:c,showManufacturer:l,showFeatures:u,onNavigate:d,muted:f}){return g(w,{children:[N(`tr`,{className:X(`border-b border-border-subtle/40 bg-surface`,f===!0&&`opacity-60`),children:N(`td`,{colSpan:r,className:`p-0`,children:g(`button`,{type:`button`,onClick:i,className:`w-full flex items-center gap-1.5 pl-8 pr-2 py-1 text-left hover:bg-surface-hover transition-colors`,"aria-expanded":n,children:[N(n?Re:Ue,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),N(`span`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle flex-1 truncate`,children:e}),N(`span`,{className:`text-[10px] font-medium text-foreground-subtle/70 tabular-nums`,children:t})]})})}),n&&a.map(e=>N(Vj,{trpc:o,accessory:e,parentName:s,showType:c,showManufacturer:l,showFeatures:u,onNavigate:d,muted:f},e.id))]})}function Uj(e){return Ak(e.type).label.toLowerCase()}function Wj(e){return e.name.toLowerCase()}function Gj(e){return e===`name`?(e,t)=>Wj(e).localeCompare(Wj(t)):e===`type`?(e,t)=>Uj(e).localeCompare(Uj(t)):Yl}function Kj(e,t){return e===null||e.columnId!==t?{columnId:t,dir:`asc`}:e.dir===`asc`?{columnId:t,dir:`desc`}:null}function qj(e,t){if(t===null)return[...e];let n=Gj(t.columnId),r=t.dir===`asc`?1:-1;return[...e].toSorted((e,i)=>{if(t.columnId===`manufacturer`){let t=Kl(e);if(t!==Kl(i))return t?-1:1}return r*n(e,i)})}h();var Jj={cards:24,table:50};function Yj(e){let{devices:t,trpc:n,context:r=`devices`,defaultView:i=`table`,filters:a,forceAddon:o,resolveIntegrationIcon:s,resolveParent:c,onNavigate:l,pageSize:u=Jj,urlScope:d=`root`,lsKey:f=d===`root`?`devices`:`integrations:nested`,renderRowAction:p,onDeleteDevice:m,selectable:h=!1,selectedIds:_,onSelectionChange:v,batchActions:y}=e,[x,S]=k(!1),[C,T]=k(new Set),E=_??C,D=e=>{let t=new Set(E);t.has(e)?t.delete(e):t.add(e),_===void 0&&T(t),v?.(t)},O=()=>{_===void 0?T(new Set):v?.(new Set)},A=()=>{O(),S(!1)},j=h||y!==void 0&&x,M=y!==void 0&&x,F=b(()=>Ll(r),[r]),[I,L]=k(null),R=e=>L(t=>Kj(t,e)),ee=a?.typeOptions,z=b(()=>ee??Fk(),[ee]),B=Nj({scope:d,defaultView:i,lsKey:f}),V=B.state.view,[te,H]=pj(u.table),U=V===`cards`?u.cards:te,[ne,re]=k(B.state.q),ie=oj(ne,300);P(()=>{ie!==B.state.q&&B.setQ(ie)},[ie]);let ae=b(()=>o===void 0?B.state.addons:[o],[o,B.state.addons]),oe=b(()=>{let e=new Map;for(let n of t){if(n.parentDeviceId===null||n.parentDeviceId===void 0)continue;let t=e.get(n.parentDeviceId);t?t.push(n):e.set(n.parentDeviceId,[n])}return e},[t]),se=b(()=>{let e=B.state.q,n=ae.length>0?new Set(ae):null,r=B.state.types.length>0?new Set(B.state.types):null;return t.filter(t=>!(n&&!n.has(t.addonId)||r&&!r.has(Zk(t,oe.get(t.id)))||e.trim()!==``&&!vj(e,t.name)&&!vj(e,t.stableId)))},[t,oe,ae,B.state.types,B.state.q]),W=b(()=>gj(se),[se]),ce=b(()=>qj(W.topLevel,I),[W.topLevel,I]),le=b(()=>{if(B.state.q.trim()===``)return new Set;let e=B.state.q,t=new Set;for(let[n,r]of W.accessoriesByParent.entries())r.some(t=>vj(e,t.name)||vj(e,t.stableId))&&t.add(n);return t},[W.accessoriesByParent,B.state.q]),ue=W.topLevel.length,de=Math.max(1,Math.ceil(ue/U)),fe=Math.min(B.state.page,de),pe=(fe-1)*U,G=ce.slice(pe,pe+U);P(()=>{fe!==B.state.page&&B.setPage(fe)},[fe]),Xj();let me=ae.length>0||B.state.types.length>0||B.state.q!==``,he=ue===0;return g(`div`,{className:`flex flex-col gap-3`,children:[g(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[N(wj,{view:V,onViewChange:B.setView,typeOptions:z,selectedTypes:B.state.types,onTypesChange:B.setTypes,addons:a?.addons,selectedAddons:B.state.addons,onAddonsChange:B.setAddons,hideAddons:o!==void 0}),g(`div`,{className:`flex items-center gap-2`,children:[y!==void 0&&(x?g(`button`,{type:`button`,onClick:A,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md border border-border bg-surface text-[11px] font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[N(rs,{className:`h-3 w-3`}),`Done`]}):g(`button`,{type:`button`,onClick:()=>S(!0),className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md border border-border bg-surface text-[11px] font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[N(wa,{className:`h-3 w-3`}),`Select`]})),g(`div`,{className:`relative`,children:[N(po,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle pointer-events-none`}),N(`input`,{type:`text`,value:ne,onChange:e=>re(e.target.value),placeholder:`Search by name or stableId`,"aria-label":`Search devices by name or stableId`,className:`h-7 pl-7 pr-2.5 rounded-md border border-border bg-surface text-[11px] text-foreground placeholder:text-foreground-subtle/60 focus:outline-none focus:ring-1 focus:ring-primary/40 w-56`})]})]})]}),y!==void 0&&x&&N(aj,{selectedIds:E,onClear:O,remove:y.remove,disable:y.disable,enable:y.enable}),he?N(Ej,{variant:me?`filtered`:`nofilter`,onClearFilters:me?B.clearFilters:void 0}):V===`cards`?N(iA,{value:W.accessoriesByParent,children:N(Pj,{rows:G,accessoriesByParent:W.accessoriesByParent,trpc:n,resolveIntegrationIcon:s??null,resolveParent:c??null,onNavigate:l??null,renderRowAction:p??null,selectable:j,rowClickSelects:M,activeSelected:E,onToggleSelection:D})}):N(iA,{value:W.accessoriesByParent,children:N(zj,{rows:G,accessoriesByParent:W.accessoriesByParent,autoExpandedParents:le,visibleColumns:F,sort:I,onSort:R,devices:se,trpc:n,resolveIntegrationIcon:s??null,resolveParent:c??null,onNavigate:l??null,renderRowAction:p??null,onDeleteDevice:m??null,selectable:j,rowClickSelects:M,activeSelected:E,onToggleSelection:D})}),!he&&V===`table`&&g(`div`,{className:`flex items-center justify-between gap-4 flex-wrap pt-2 text-[11px] text-foreground-subtle`,children:[g(`div`,{className:`inline-flex items-center gap-2`,children:[ue<=te&&g(`span`,{children:[ue,` `,ue===1?`device`:`devices`]}),g(`div`,{className:`inline-flex items-center gap-1.5`,children:[N(`span`,{"aria-hidden":`true`,children:`Per page`}),N(`select`,{"aria-label":`Devices per page`,value:te,onChange:e=>{H(Number.parseInt(e.target.value,10))},className:`h-7 px-1.5 rounded-md border border-border bg-surface text-[11px] text-foreground focus:outline-none focus:ring-1 focus:ring-primary/40`,children:sj.map(e=>N(`option`,{value:e,children:e},e))})]})]}),N(xj,{currentPage:fe,totalItems:ue,pageSize:U,onPageChange:B.setPage})]}),!he&&V===`cards`&&N(xj,{currentPage:fe,totalItems:ue,pageSize:U,onPageChange:B.setPage}),o===void 0&&me&&ue>0&&g(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Showing `,ue,` of `,mj(t).length,` devices`,ae.length>0&&g(w,{children:[` `,`· filtered by`,` `,N(`strong`,{className:`text-primary`,children:ae.map(e=>a?.addons?.find(t=>t.id===e)?.name??e).join(`, `)})]})]})]})}function Xj(){O()}h();function Zj(e){let{items:t,getKey:n,getSearchText:r,renderItem:i,getFilterType:a,mapFilterOption:s,filterOptions:c,filterLabel:l=`Type`,columns:u,renderExpanded:d,isExpanded:f,rowClassName:p,onRowClick:m,isLoading:h=!1,searchPlaceholder:_=`Search`,emptyLabel:v=`No items found.`,pageSize:y=100,toolbar:x}=e,[S,C]=k(``),w=oj(S,300),[T,E]=k([]),[D,O]=k(1);P(()=>{O(1)},[w,T]);let A=b(()=>{if(!a)return[];if(c)return c;let e=new Set;for(let n of t){let t=a(n);t!==null&&t!==``&&e.add(t)}return[...e].toSorted().map(e=>{let t=s?.(e);return{id:e,label:t?.label??e,...t?.icon?{icon:t.icon}:{}}})},[t,a,s,c]),j=b(()=>new Set(T),[T]),M=b(()=>{let e=w;return t.filter(t=>{if(j.size>0&&a){let e=a(t);if(e===null||!j.has(e))return!1}return!(e.trim()!==``&&!vj(e,r(t)))})},[t,w,r,j,a]),F=M.length,I=Math.max(1,Math.ceil(F/y)),L=Math.min(D,I),R=(L-1)*y,ee=M.slice(R,R+y);return P(()=>{L!==D&&O(L)},[L,D]),g(`div`,{className:`flex flex-col gap-3 h-full min-h-0`,children:[g(`div`,{className:`flex items-center justify-between gap-3 flex-wrap shrink-0`,children:[a&&A.length>0?N(Cj,{label:l,options:A,selected:T,onChange:E}):N(`span`,{}),g(`div`,{className:`flex items-center gap-2`,children:[g(`div`,{className:`relative`,children:[N(po,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle pointer-events-none`}),N(`input`,{type:`text`,value:S,onChange:e=>C(e.target.value),placeholder:_,"aria-label":_,className:`h-7 pl-7 pr-2.5 rounded-md border border-border bg-surface text-[11px] text-foreground placeholder:text-foreground-subtle/60 focus:outline-none focus:ring-1 focus:ring-primary/40 w-56`})]}),x]})]}),N(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:h&&F===0?N(`div`,{className:`flex items-center justify-center py-12 text-xs text-foreground-subtle`,children:`Loading…`}):F===0?N(`div`,{className:`flex items-center justify-center py-12 text-xs text-foreground-subtle`,children:v}):u?N(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:g(`table`,{className:`w-full border-collapse`,children:[N(`thead`,{children:N(`tr`,{className:`border-b border-border`,children:u.map(e=>N(`th`,{className:`text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle ${e.headerClassName??``}`,children:e.header},e.key))})}),N(`tbody`,{children:ee.map(e=>g(o,{children:[N(`tr`,{className:`border-b border-border/60 ${m?`cursor-pointer hover:bg-surface-hover transition-colors`:``} ${p?.(e)??``}`,...m?{onClick:()=>m(e),role:`button`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),m(e))}}:{},children:u.map(t=>N(`td`,{className:`px-2 py-2 align-middle ${t.cellClassName??``}`,children:t.cell(e)},t.key))}),d&&f?.(e)&&N(`tr`,{className:`border-b border-border/60 bg-surface/40`,children:N(`td`,{colSpan:u.length,className:`px-2 pb-2 pt-0`,children:d(e)})})]},n(e)))})]})}):N(`div`,{className:`space-y-1.5`,children:ee.map(e=>N(o,{children:i?.(e)},n(e)))})}),N(`div`,{className:`shrink-0`,children:N(xj,{currentPage:L,totalItems:F,pageSize:y,onPageChange:O})})]})}function Qj(e){return`mode`in e&&e.mode===`generic`?N(Zj,{...e}):N(Yj,{...e})}function $j({trpc:e,deviceId:t,features:n,layout:r}){let{cap:i,slice:a,available:o}=Q({trpc:e,deviceId:t,cap:e=>e.cover,slice:e=>e.state.cover});if(a===void 0)return null;let s=(n??[]).includes(`cover-positionable`),c=!o,l=a.position,u=e=>{c||!e||e({})};return g(`div`,{className:X(`inline-flex items-center gap-1`,r===`full`&&`flex-col items-stretch gap-2`),children:[g(`div`,{className:`inline-flex items-center gap-1`,children:[N(eM,{label:`Open`,busy:c,onClick:()=>u(i?.open),children:N(Ti,{className:`h-3.5 w-3.5`})}),N(eM,{label:`Stop`,busy:c,onClick:()=>u(i?.stop),children:N(Ao,{className:`h-3 w-3`})}),N(eM,{label:`Close`,busy:c,onClick:()=>u(i?.close),children:N(Re,{className:`h-3.5 w-3.5`})})]}),s&&r===`full`&&g(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[N(`span`,{children:`Position`}),N(`input`,{"aria-label":`Position`,type:`range`,min:0,max:100,step:1,value:l??0,disabled:c,onChange:e=>{c||i?.setPosition({position:Number(e.target.value)})}}),g(`span`,{className:`tabular-nums w-8 text-right`,children:[l??`—`,`%`]})]})]})}function eM({label:e,busy:t,onClick:n,children:r}){return N(`button`,{type:`button`,"aria-label":e,title:e,disabled:t,onClick:e=>{e.stopPropagation(),n()},className:X(`inline-flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,t&&`opacity-40 cursor-not-allowed`),children:r})}var tM=[`cover`,`lock-control`,`switch`,`brightness`,`fan-control`,`climate-control`,`media-player`,`control`,`pet-feeder`];h(),rt();var nM=240,rM=6;function iM({icon:e,title:t,children:n}){let r=f(null),i=f(null),[a,o]=k(null),s=a!==null,c=()=>o(null),l=()=>{let e=r.current;if(!e)return;let t=e.getBoundingClientRect(),n=Math.min(nM,window.innerWidth-16),i=Math.max(8,Math.min(t.right-n,window.innerWidth-n-8));o({top:t.bottom+rM,left:i,width:n})};return P(()=>{if(!s)return;let e=e=>{let t=e.target;i.current?.contains(t)||r.current?.contains(t)||c()},t=e=>{e.key===`Escape`&&c()};return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e),document.removeEventListener(`keydown`,t)}},[s]),g(w,{children:[N(`button`,{ref:r,type:`button`,title:t,"aria-label":t,"aria-haspopup":`dialog`,"aria-expanded":s,onClick:e=>{e.stopPropagation(),s?c():l()},className:X(`inline-flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,s&&`bg-surface-hover text-foreground`),children:N(e,{className:`h-3 w-3`})}),a&&it(N(`div`,{ref:i,style:{position:`fixed`,top:a.top,left:a.left,width:a.width},className:`z-[9999] rounded-lg border border-border bg-surface shadow-lg shadow-black/30 p-2`,onClick:e=>e.stopPropagation(),children:n}),document.body)]})}function aM({lastChangedAt:e,className:t}){let n=mr(e);return g(`span`,{title:n===null?`Unavailable`:`Unavailable · last seen ${n}`,className:X(`inline-flex items-center gap-1 rounded-full px-2 py-0.5`,`bg-surface-hover text-foreground-subtle text-[10px] font-medium`,`border border-border`,t),children:[N(Qo,{className:`h-3 w-3 flex-shrink-0`,"aria-hidden":`true`}),N(`span`,{children:`Unavailable`}),n===null?null:N(`span`,{className:`text-foreground-subtle/70`,children:`· last seen ${n}`})]})}function oM({trpc:e,children:t,linkDeviceId:n,primaryChildEntityId:r}){let i=yk(t,n,r),a=i===null?void 0:t.find(e=>e.id===i.id);return a===void 0?N(`div`,{className:`flex h-full w-full items-center justify-center p-4 text-[11px] italic text-foreground-subtle`,children:`No child entities to display.`}):N(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:N(dk(a.type)?.HeroCard??ku,{trpc:e,deviceId:a.id,features:a.features})})}var sM=`rounded-md border border-border bg-surface px-1.5 py-0.5 text-[11px] text-foreground`;function cM({childrenList:e,selectedId:t,onSetPrimary:n,disabled:r,className:i}){return N(`select`,{value:t,disabled:r,onChange:r=>{let i=Number(r.target.value);if(!Number.isFinite(i)||i===t)return;let a=e.find(e=>e.id===i);a!==void 0&&n(gk(a))},className:i===void 0?sM:`${sM} ${i}`,children:e.map(e=>g(`option`,{value:e.id,children:[e.name,` (`,e.type,`)`]},e.id))})}function lM({options:e,value:t,onChange:n}){return N(`div`,{className:`flex flex-wrap gap-2`,children:e.map(e=>{let r=e.id===t;return g(`button`,{onClick:()=>e.available&&n(e.id),disabled:!e.available,className:`flex items-center gap-2 rounded-lg border px-3 py-2 text-xs font-medium transition-all ${r?`border-primary/40 bg-primary/10 text-primary`:e.available?`border-border bg-surface text-foreground-subtle hover:bg-surface-hover hover:text-foreground`:`border-border/40 bg-surface/40 text-foreground-subtle/40 cursor-not-allowed`}`,children:[N(Gi,{className:`h-3.5 w-3.5 shrink-0`}),e.label,e.isBest&&g(`span`,{className:`inline-flex items-center gap-0.5 rounded-full bg-amber-500/15 px-1.5 py-0.5 text-[10px] font-semibold text-amber-400`,children:[N(jo,{className:`h-2.5 w-2.5`}),`Best`]}),e.platformScore!=null&&g(`span`,{className:`text-[10px] text-foreground-subtle/60`,children:[`(`,e.platformScore,`)`]}),N(`span`,{className:`h-1.5 w-1.5 rounded-full ${e.available?`bg-success`:`bg-danger`}`})]},e.id)})})}function uM(e,t){let n=new Set(t.slots.flatMap(e=>e.addons.map(e=>e.id))),r=[];function i(e){if(!n.has(e.addonId))return r.push(`Addon "${e.addonId}" is no longer available — step removed`),null;let a=t.slots.flatMap(e=>e.addons).find(t=>t.id===e.addonId),o=e.modelId;if(a&&!a.models.some(e=>e.id===o)){let t=a.defaultModelId;r.push(`Model "${o}" not available for ${e.addonId} — using "${t}"`),o=t}let s=e.children.map(e=>i(e)).filter(e=>e!==null);return{...e,modelId:o,children:s}}let a=e.map(e=>i(e)).filter(e=>e!==null);return{valid:r.length===0,steps:a,warnings:r}}h();function dM(e){let t=new Map;for(let n of e.slots)for(let e of n.addons)t.set(e.id,e);return t}function fM(e){return{addonId:e.id,addonName:e.name,slot:e.slot,inputClasses:[...e.inputClasses],outputClasses:[...e.outputClasses],enabled:!0,modelId:e.defaultModelId,children:[]}}function pM({addon:e,onClick:t}){return N(`button`,{type:`button`,onClick:t,className:`w-full rounded-lg border border-dashed border-border/60 px-3 py-2.5 text-left transition-all hover:border-primary/30 hover:bg-surface/60 group`,children:g(`div`,{className:`flex items-center gap-3`,children:[N(Ni,{className:`h-[18px] w-[18px] text-foreground-subtle/30 group-hover:text-primary/60 shrink-0`}),g(`div`,{className:`flex-1 min-w-0`,children:[N(`span`,{className:`text-[13px] font-medium text-foreground-subtle/50 group-hover:text-foreground-subtle block truncate`,children:e.name}),g(`div`,{className:`flex items-center gap-1 mt-0.5 flex-wrap`,children:[e.inputClasses.map(e=>N(`span`,{className:`text-[9px] uppercase font-semibold tracking-wide px-1.5 py-0.5 rounded bg-blue-500/8 text-blue-400/50`,children:e},e)),e.inputClasses.length>0&&e.outputClasses.length>0&&N(`span`,{className:`text-foreground-subtle/25 text-[10px]`,children:`→`}),e.outputClasses.map(e=>N(`span`,{className:`text-[9px] uppercase font-semibold tracking-wide px-1.5 py-0.5 rounded bg-green-500/8 text-green-400/50`,children:e},e))]})]})]})})}function mM({schema:e,steps:t,onChange:n,templates:r,selectedTemplateId:i,onSelectTemplate:a,onSaveTemplate:o,onUpdateTemplate:s,onDeleteTemplate:c,readOnly:l=!1,excludeAddons:u=[],hideTemplates:d=!1,showOnlyEnabled:f=!1,showSlotLabels:p=!1,toggleMode:m=`simple`,overrides:h={},onOverrideChange:_,inheritedEnabledByAddon:v={},hideModelAndSettings:y=!1,allowAutoModel:x=!1}){let S=e=>({toggleMode:m,hideModelAndSettings:y,allowAutoModel:x,...m===`threeState`?{overrideState:h[e]===void 0?null:h[e],onOverrideChange:_?t=>_(e,t):void 0,inheritedEnabled:v[e]}:{}}),C=b(()=>new Set(u),[u]),w=b(()=>dM(e),[e]),[T,E]=k([]),D=i?JSON.stringify(t)!==JSON.stringify(r.find(e=>e.id===i)?.steps):!1;function O(t){let n=t.target.value||null;if(n){let t=r.find(e=>e.id===n);t&&E([...uM(t.steps,e).warnings])}else E([]);a(n)}function A(){i&&s(i,t)}function j(){let e=window.prompt(`Template name:`);e?.trim()&&o(e.trim(),t)}function M(){if(!i)return;let e=r.find(e=>e.id===i);e&&window.confirm(`Delete template "${e.name}"?`)&&c(i)}function P(e){n(t.map(t=>t.addonId===e.addonId?F(e):t))}function F(e){let t=e.children.some(e=>e.enabled||e.children.some(e=>e.enabled));return{...e,enabled:e.enabled||t,children:e.children.map(e=>{let t=e.children.some(e=>e.enabled);return{...e,enabled:e.enabled||t}})}}function I(e,r){let i=fM(r);n(t.map(t=>t.addonId===e?{...t,children:[...t.children,i]}:t))}function L(e){let t=new Set;for(let n of e){t.add(n.addonId);for(let e of n.children)t.add(e.addonId);let e=L(n.children);for(let n of e)t.add(n)}return t}let R=L(t);function ee(t){let n=w.get(t.addonId);if(!n)return[];let r=e.slots.find(e=>e.id===n.slot)?.parentSlot==null,i=n.childSlots,a=new Set(t.children.map(e=>e.addonId)),o=[];for(let n of e.slots)if(i.includes(n.id))for(let e of n.addons){if(a.has(e.id)||C.has(e.id))continue;let n=e.inputClasses.length===0;n&&!r||(n||e.inputClasses.some(e=>t.outputClasses.includes(e)))&&o.push(e)}return o}function z(e){let r=f?{...e,children:e.children.filter(e=>e.enabled).map(e=>({...e,children:e.children.filter(e=>e.enabled)}))}:e,i=f?[]:ee(r);return g(`div`,{className:`space-y-1.5`,children:[N(Oc,{step:r,schema:w.get(r.addonId)??null,allSchemas:w,onChange:P,onDelete:l?void 0:e=>n(t.filter(t=>t.addonId!==e)),readOnly:l,...S(r.addonId)}),(r.children.length>0||i.length>0)&&g(`div`,{className:`ml-4 pl-3 border-l border-border/60 space-y-1.5`,children:[p&&N(`span`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/40`,children:`Slot: Cropper / Classifier`}),r.children.map(e=>{let t=ee(e);return g(`div`,{className:`space-y-1.5`,children:[N(Oc,{step:e,schema:w.get(e.addonId)??null,allSchemas:w,depth:1,onChange:e=>{P({...r,children:r.children.map(t=>t.addonId===e.addonId?e:t)})},onDelete:l?void 0:e=>{P({...r,children:r.children.filter(t=>t.addonId!==e)})},readOnly:l,...S(e.addonId)}),(e.children.length>0||t.length>0)&&g(`div`,{className:`ml-4 pl-3 border-l border-border/40 space-y-1.5`,children:[p&&N(`span`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/30`,children:`Slot: Recognizer`}),e.children.map(t=>N(Oc,{step:t,schema:w.get(t.addonId)??null,allSchemas:w,depth:2,onChange:t=>{P({...r,children:r.children.map(n=>n.addonId===e.addonId?{...n,children:n.children.map(e=>e.addonId===t.addonId?t:e)}:n)})},onDelete:l?void 0:t=>{P({...r,children:r.children.map(n=>n.addonId===e.addonId?{...n,children:n.children.filter(e=>e.addonId!==t)}:n)})},readOnly:l,...S(t.addonId)},t.addonId)),!l&&t.map(t=>N(pM,{addon:t,onClick:()=>{let n=fM(t);P({...r,children:r.children.map(t=>t.addonId===e.addonId?{...t,children:[...t.children,n]}:t)})}},t.id))]})]},e.addonId)}),!l&&i.map(e=>N(pM,{addon:e,onClick:()=>I(r.addonId,e)},e.id))]})]},r.addonId)}let B=e.slots.filter(e=>e.parentSlot===null).toSorted((e,t)=>e.priority-t.priority);return g(`div`,{className:`space-y-4`,children:[!d&&N(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:g(`div`,{className:`flex items-center gap-2`,children:[N(`div`,{className:`relative flex-1 min-w-0`,children:g(`select`,{value:i??``,onChange:O,className:`w-full rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground focus:outline-none focus:border-primary/50`,children:[N(`option`,{value:``,children:`No template`}),r.map(e=>N(`option`,{value:e.id,children:e.name},e.id))]})}),D&&N(`span`,{className:`h-1.5 w-1.5 rounded-full bg-amber-500 shrink-0`}),N(`button`,{onClick:A,disabled:!i||l,title:`Save`,className:X(`p-2 rounded-lg border border-border transition-colors`,i&&!l?`text-foreground-subtle hover:bg-surface-hover`:`text-foreground-subtle/30 cursor-not-allowed`),children:N(lo,{className:`h-4 w-4`})}),N(`button`,{onClick:j,disabled:l,title:`Save As`,className:X(`p-2 rounded-lg border border-border transition-colors`,l?`text-foreground-subtle/30 cursor-not-allowed`:`text-foreground-subtle hover:bg-surface-hover`),children:N(Ui,{className:`h-4 w-4`})}),N(`button`,{onClick:M,disabled:!i||l,title:`Delete`,className:X(`p-2 rounded-lg border border-border transition-colors`,i&&!l?`text-foreground-subtle hover:text-danger`:`text-foreground-subtle/30 cursor-not-allowed`),children:N(Bo,{className:`h-4 w-4`})})]})}),T.length>0&&g(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/5 p-3 text-xs text-amber-400 space-y-1`,children:[g(`div`,{className:`flex items-center justify-between`,children:[N(`span`,{className:`font-medium`,children:`Template loaded with warnings:`}),N(`button`,{onClick:()=>E([]),className:`text-amber-400/60 hover:text-amber-400`,children:N(rs,{className:`h-3.5 w-3.5`})})]}),T.map((e,t)=>g(`div`,{children:[`• `,e]},t))]}),B.map(e=>{let r=t.filter(t=>t.slot===e.id&&!C.has(t.addonId)),i=f?r.filter(e=>e.enabled):r,a=f?[]:e.addons.filter(e=>!R.has(e.id)&&!C.has(e.id)),o=new Map,s=[];for(let e of i)e.group?(o.has(e.group)||o.set(e.group,[]),o.get(e.group).push(e)):s.push(e);return g(`div`,{className:`space-y-2`,children:[p&&g(`span`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/50`,children:[`Slot: `,e.label]}),s.map(e=>z(e)),[...o.entries()].map(([e,t])=>g(`div`,{className:`space-y-2 rounded-lg border border-border/40 p-2`,children:[N(`span`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/50 px-1`,children:e}),t.map(e=>z(e))]},e)),!l&&a.map(e=>N(pM,{addon:e,onClick:()=>{n([...t,fM(e)])}},e.id))]},e.id)})]})}var hM={person:`#3b82f6`,vehicle:`#f59e0b`,animal:`#22c55e`,face:`#a855f7`,plate:`#ec4899`,bird:`#14b8a6`,dog:`#84cc16`,cat:`#f97316`,car:`#f59e0b`,truck:`#d97706`,bus:`#b45309`,motorcycle:`#eab308`,bicycle:`#ca8a04`,motion:`#facc15`},gM=[`#ef4444`,`#8b5cf6`,`#06b6d4`,`#f97316`,`#10b981`,`#6366f1`,`#e11d48`,`#0891b2`,`#7c3aed`,`#059669`],_M=`#f59e42`;function vM(e,t){if(t?.[e])return t[e];if(t?.[e.toLowerCase()])return t[e.toLowerCase()];if(hM[e])return hM[e];if(hM[e.toLowerCase()])return hM[e.toLowerCase()];let n=0;for(let t=0;t<e.length;t++)n=n*31+(e.codePointAt(t)??0)>>>0;return gM[n%gM.length]??`#f59e42`}h();function yM({src:e,imageWidth:t,imageHeight:n,detections:r=[],classColors:i,aspectRatio:a,className:o,placeholder:s,showConfidence:c=!0,minConfidence:l=0,borderWidth:u=2}){function d(e){return vM(e,i)}let f=a??(t&&n?`${t}/${n}`:`16/9`),p=r.filter(e=>e.score>=l),m=p.filter(e=>e.kind===`first-level`),h=p.filter(e=>e.kind===`detail`),_=CM(h,e=>e.parentId??``);return N(`div`,{className:X(`rounded-lg border border-border bg-surface overflow-hidden relative`,o),style:{aspectRatio:f},children:e?g(w,{children:[N(`img`,{src:e,className:`absolute inset-0 w-full h-full object-fill`,alt:``}),p.map((e,r)=>e.debug?.mask&&e.debug.maskWidth&&e.debug.maskHeight?N(xM,{mask:e.debug.mask,maskWidth:e.debug.maskWidth,maskHeight:e.debug.maskHeight,bbox:e.bbox,imageWidth:t,imageHeight:n,color:d(e.macroClass)},`mask-${r}`):null),m.map(e=>{let r=_.get(e.id)??[];return N(bM,{detection:e,imageWidth:t,imageHeight:n,color:d(e.macroClass),showConfidence:c,borderWidth:e.debug?.mask?1:u,children:r.map(t=>N(SM,{child:t,parentBbox:e.bbox,color:d(t.macroClass),showConfidence:c},`child-${t.id}`))},`det-${e.id}`)}),h.filter(e=>!e.parentId||!m.some(t=>t.id===e.parentId)).map(e=>N(bM,{detection:e,imageWidth:t,imageHeight:n,color:d(e.macroClass),showConfidence:c,borderWidth:u},`orphan-${e.id}`))]}):N(`div`,{className:`w-full h-full flex items-center justify-center text-foreground-subtle text-sm`,children:s??`No image loaded`})})}function bM({detection:e,imageWidth:t,imageHeight:n,color:r,showConfidence:i,borderWidth:a,children:o}){let{x:s,y:c,width:l,height:u}=e.bbox,d=g(`div`,{className:`absolute left-0 flex flex-col items-start gap-px`,style:{bottom:`100%`,marginBottom:`2px`},children:[g(`span`,{className:`text-[10px] px-1 rounded-sm whitespace-nowrap text-white`,style:{backgroundColor:r},children:[e.macroClass,i&&` ${(e.score*100).toFixed(0)}%`]}),e.labels.map((t,n)=>g(`span`,{className:`text-[9px] font-semibold px-1 rounded-sm whitespace-nowrap text-white`,style:{backgroundColor:vM(t.label)},children:[t.label,` `,(t.score*100).toFixed(0),`%`]},`${e.id}-lbl-${n}`))]});return g(`div`,{className:`absolute rounded-sm`,style:{left:`${s/t*100}%`,top:`${c/n*100}%`,width:`${l/t*100}%`,height:`${u/n*100}%`,borderWidth:`${a}px`,borderStyle:`solid`,borderColor:r},children:[d,o]})}function xM({mask:e,maskWidth:t,maskHeight:n,bbox:r,imageWidth:i,imageHeight:a,color:o}){let s=f(null);return P(()=>{let r=s.current;if(!r)return;let i=r.getContext(`2d`);if(!i)return;let a=atob(e),c=new Uint8Array(a.length);for(let e=0;e<a.length;e++)c[e]=a.charCodeAt(e);let l=parseInt(o.slice(1,3),16),u=parseInt(o.slice(3,5),16),d=parseInt(o.slice(5,7),16);r.width=t,r.height=n;let f=i.createImageData(t,n),p=t*n;for(let e=0;e<p;e++){let t=e<c.length?c[e]:0,n=e*4;t>0&&(f.data[n]=l,f.data[n+1]=u,f.data[n+2]=d,f.data[n+3]=120)}i.putImageData(f,0,0)},[e,t,n,o]),N(`canvas`,{ref:s,className:`absolute pointer-events-none`,style:{left:`${r.x/i*100}%`,top:`${r.y/a*100}%`,width:`${r.width/i*100}%`,height:`${r.height/a*100}%`,imageRendering:`pixelated`}})}function SM({child:e,parentBbox:t,color:n,showConfidence:r}){if(t.width<=0||t.height<=0)return null;let i=(e.bbox.x-t.x)/t.width*100,a=(e.bbox.y-t.y)/t.height*100,o=e.bbox.width/t.width*100,s=e.bbox.height/t.height*100;return N(`div`,{className:`absolute rounded-sm`,style:{left:`${Math.max(0,i)}%`,top:`${Math.max(0,a)}%`,width:`${Math.min(100,o)}%`,height:`${Math.min(100,s)}%`,borderWidth:`1px`,borderStyle:`solid`,borderColor:n},children:g(`div`,{className:`absolute left-0 flex flex-col items-start gap-px`,style:{bottom:`100%`,marginBottom:`1px`},children:[g(`span`,{className:`text-[9px] px-0.5 rounded-sm whitespace-nowrap text-white`,style:{backgroundColor:n},children:[e.macroClass,r&&` ${(e.score*100).toFixed(0)}%`]}),e.labels.map((t,n)=>g(`span`,{className:`text-[8px] font-semibold px-0.5 rounded-sm whitespace-nowrap text-white`,style:{backgroundColor:vM(t.label)},children:[t.label,` `,(t.score*100).toFixed(0),`%`]},`${e.id}-lbl-${n}`))]})})}function CM(e,t){let n=new Map;for(let r of e){let e=t(r),i=n.get(e)??[];i.push(r),n.set(e,i)}return n}h();function wM({detections:e,classColors:t,className:n,hiddenKeys:r,onToggleVisibility:i}){let a=t;if(e.length===0)return N(`div`,{className:`text-sm text-foreground-subtle italic text-center py-4`,children:`No detections`});let o=e.filter(e=>e.kind===`first-level`),s=e.filter(e=>e.kind===`detail`),c=new Map;for(let e of s){if(!e.parentId)continue;let t=c.get(e.parentId)??[];t.push(e),c.set(e.parentId,t)}let l=s.filter(e=>!e.parentId||!o.some(t=>t.id===e.parentId));return g(`div`,{className:n,children:[g(`div`,{className:`text-xs font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Detections (`,e.length,`)`]}),g(`div`,{className:`space-y-2`,children:[o.map(e=>N(TM,{detection:e,children_:c.get(e.id)??[],colors:a,hiddenKeys:r,onToggleVisibility:i},e.id)),l.map(e=>N(TM,{detection:e,children_:[],colors:a,hiddenKeys:r,onToggleVisibility:i},e.id))]})]})}function TM({detection:e,children_:t,colors:n,hiddenKeys:r,onToggleVisibility:i}){let a=vM(e.macroClass,n),o=!r?.has(e.id),s=e.debug?.mask,c=e.debug?.maskWidth,l=e.debug?.maskHeight,u=e.debug?.alternateLabels;return g(`div`,{className:`rounded-md border border-border bg-surface p-3 space-y-1 ${o?``:`opacity-40`}`,children:[g(`div`,{className:`flex justify-between items-center`,children:[g(`div`,{className:`flex items-center gap-2`,children:[i&&N(`input`,{type:`checkbox`,checked:o,onChange:()=>i(e.id,!o),className:`h-3.5 w-3.5 rounded border-border accent-primary cursor-pointer shrink-0`}),N(`span`,{className:`h-2.5 w-2.5 rounded-full shrink-0`,style:{backgroundColor:a}}),N(`span`,{className:`text-sm font-medium text-foreground`,children:e.macroClass}),e.kind===`detail`&&N(`span`,{className:`text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary`,children:`detail`}),s&&c&&l&&g(`span`,{className:`text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary`,children:[`mask `,c,`x`,l]})]}),N(OM,{confidence:e.score})]}),g(`div`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`bbox: [`,Math.round(e.bbox.x),`, `,Math.round(e.bbox.y),`,`,` `,Math.round(e.bbox.x+e.bbox.width),`,`,` `,Math.round(e.bbox.y+e.bbox.height),`]`]}),e.labels.length>0&&N(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:e.labels.map((e,t)=>g(`span`,{className:`inline-flex items-center gap-1 text-[10px] font-medium px-1.5 py-0.5 rounded-full`,style:{backgroundColor:vM(e.label,n)+`20`,color:vM(e.label,n)},children:[e.label,g(`span`,{className:`opacity-60`,children:[(e.score*100).toFixed(0),`%`]}),e.detectionId&&g(`span`,{className:`opacity-40 text-[8px]`,children:[`→ `,e.detectionId]})]},t))}),u&&Object.keys(u).length>0&&N(DM,{alternateLabels:u,colors:n}),t.length>0&&N(EM,{items:t,colors:n,hiddenKeys:r,onToggleVisibility:i})]})}function EM({items:e,colors:t,hiddenKeys:n,onToggleVisibility:r}){return N(`div`,{className:`ml-4 mt-1.5 space-y-1.5 border-l-2 border-border pl-3`,children:e.map(e=>{let i=vM(e.macroClass,t),a=!n?.has(e.id),o=e.debug?.mask,s=e.debug?.maskWidth,c=e.debug?.maskHeight;return g(`div`,{className:`text-xs space-y-0.5 ${a?``:`opacity-40`}`,children:[g(`div`,{className:`flex items-center gap-1.5`,children:[r&&N(`input`,{type:`checkbox`,checked:a,onChange:()=>r(e.id,!a),className:`h-3 w-3 rounded border-border accent-primary cursor-pointer shrink-0`}),N(`span`,{className:`h-1.5 w-1.5 rounded-full shrink-0`,style:{backgroundColor:i}}),N(`span`,{className:`font-medium`,style:{color:i},children:e.macroClass}),g(`span`,{className:`text-foreground-subtle`,children:[(e.score*100).toFixed(0),`%`]}),o&&s&&c&&g(`span`,{className:`text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary`,children:[`mask `,s,`x`,c]})]}),e.labels.length>0&&N(`div`,{className:`flex flex-wrap gap-1 ml-5 mt-0.5`,children:e.labels.map((e,n)=>g(`span`,{className:`inline-flex items-center gap-0.5 text-[9px] font-medium px-1 py-0.5 rounded-full`,style:{backgroundColor:vM(e.label,t)+`20`,color:vM(e.label,t)},children:[e.label,` `,g(`span`,{className:`opacity-60`,children:[(e.score*100).toFixed(0),`%`]})]},n))})]},e.id)})})}function DM({alternateLabels:e,colors:t}){let[n,r]=k(!1),i=Object.keys(e);return g(`div`,{className:`mt-1`,children:[g(`button`,{onClick:()=>r(e=>!e),className:`text-[9px] text-foreground-subtle hover:text-foreground transition-colors flex items-center gap-1`,children:[N(`span`,{className:`transition-transform ${n?`rotate-90`:``}`,children:`▶`}),`Alternates (`,i.length,` source`,i.length===1?``:`s`,`)`]}),n&&N(`div`,{className:`mt-1 ml-3 space-y-1.5`,children:i.map(n=>{let r=e[n];return!r||r.length===0?null:g(`div`,{children:[N(`div`,{className:`text-[9px] font-medium text-foreground-subtle mb-0.5`,children:n}),N(`div`,{className:`flex flex-wrap gap-1`,children:r.map((e,r)=>g(`span`,{className:`inline-flex items-center gap-0.5 text-[9px] px-1 py-0.5 rounded-full`,style:{backgroundColor:vM(n,t)+`10`,color:vM(n,t),opacity:Math.max(.4,e.score)},children:[e.label,g(`span`,{className:`opacity-60`,children:[(e.score*100).toFixed(1),`%`]})]},r))})]},n)})})]})}function OM({confidence:e}){return g(`span`,{className:`text-xs font-medium px-2 py-0.5 rounded-full ${e>=.8?`bg-success/10 text-success`:e>=.5?`bg-warning/10 text-warning`:`bg-danger/10 text-danger`}`,children:[(e*100).toFixed(1),`%`]})}function kM({timings:e,totalMs:t,className:n}){let r=Object.entries(e);return r.length===0&&t===void 0?null:g(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-2 ${n??``}`,children:[N(`div`,{className:`text-xs font-medium text-foreground-subtle uppercase tracking-wide`,children:`Timings`}),g(`div`,{className:`space-y-1 text-xs`,children:[r.map(([e,t])=>g(`div`,{className:`flex justify-between`,children:[N(`span`,{className:`text-foreground-subtle`,children:e}),g(`span`,{className:`font-mono text-foreground`,children:[t.toFixed(1),`ms`]})]},e)),t!==void 0&&g(`div`,{className:`flex justify-between pt-1 border-t border-border font-medium text-foreground`,children:[N(`span`,{children:`Total`}),g(`span`,{className:`font-mono`,children:[t.toFixed(1),`ms`]})]})]})]})}function AM({images:e,selectedFilename:t,uploadedName:n,onSelect:r,onUpload:i,className:a,accept:o=`image/*`,uploadLabel:s=`Upload...`}){return g(`div`,{className:`flex flex-wrap items-center gap-2 ${a??``}`,children:[e.map(e=>N(`button`,{onClick:()=>r(e.filename),className:`px-3 py-1.5 text-xs rounded-md border transition-colors ${t===e.filename?`bg-primary text-primary-foreground border-primary`:`bg-surface border-border text-foreground hover:border-primary/50`}`,children:e.id??e.filename.replace(/\.[^.]+$/,``)},e.filename)),N(`button`,{onClick:()=>{let e=document.createElement(`input`);e.type=`file`,e.accept=o,e.addEventListener(`change`,()=>{let t=e.files?.[0];if(!t)return;let n=new FileReader;n.addEventListener(`load`,()=>{let e=n.result,r=e.split(`,`)[1];r&&i(r,t.name,e)}),n.readAsDataURL(t)}),e.click()},className:`px-3 py-1.5 text-xs rounded-md border border-border bg-surface text-foreground hover:bg-surface-hover transition-colors`,children:s}),n&&N(`span`,{className:`text-xs text-foreground-subtle`,children:n})]})}var jM=`w-full px-3 py-2 text-sm rounded-md border border-border bg-surface text-foreground focus:outline-none focus:ring-2 focus:ring-primary/50`;function MM({runtime:e,backend:t,modelId:n,agentId:r=`hub`,runtimes:i,backends:a,models:o,agents:s=[],onRuntimeChange:c,onBackendChange:l,onModelChange:u,onAgentChange:d,layout:f=`grid`,className:p,showAgent:m=!1}){return g(`div`,{className:`${f===`grid`?`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4`:f===`horizontal`?`flex flex-wrap items-end gap-4`:`space-y-3`} ${p??``}`,children:[m&&s.length>0&&g(`label`,{className:`space-y-1`,children:[N(`span`,{className:`text-xs font-medium text-foreground-subtle`,children:`Agent`}),N(`select`,{value:r,onChange:e=>d?.(e.target.value),className:jM,children:s.map(e=>g(`option`,{value:e.id,children:[e.name,` (`,e.status,`)`]},e.id))})]}),g(`label`,{className:`space-y-1`,children:[N(`span`,{className:`text-xs font-medium text-foreground-subtle`,children:`Runtime`}),N(`select`,{value:e,onChange:e=>c(e.target.value),className:jM,children:i.map(e=>g(`option`,{value:e.value,disabled:!e.available,children:[e.label,e.available?``:` (unavailable)`]},e.value))})]}),g(`label`,{className:`space-y-1`,children:[N(`span`,{className:`text-xs font-medium text-foreground-subtle`,children:`Backend`}),N(`select`,{value:t,onChange:e=>l(e.target.value),className:jM,children:a.map(e=>g(`option`,{value:e.id,disabled:!e.available,children:[e.label,e.available?``:` (unavailable)`]},e.id))})]}),g(`label`,{className:`space-y-1`,children:[N(`span`,{className:`text-xs font-medium text-foreground-subtle`,children:`Model`}),N(`select`,{value:n,onChange:e=>u(e.target.value),className:jM,children:o.length===0?N(`option`,{value:``,children:`No compatible models`}):o.map(e=>g(`option`,{value:e.id,children:[e.name,e.downloaded?` ✓`:``]},e.id))})]})]})}var NM=class{constructor(){this.keyToValue=new Map,this.valueToKey=new Map}set(e,t){this.keyToValue.set(e,t),this.valueToKey.set(t,e)}getByKey(e){return this.keyToValue.get(e)}getByValue(e){return this.valueToKey.get(e)}clear(){this.keyToValue.clear(),this.valueToKey.clear()}},PM=class{constructor(e){this.generateIdentifier=e,this.kv=new NM}register(e,t){this.kv.getByValue(e)||(t||=this.generateIdentifier(e),this.kv.set(t,e))}clear(){this.kv.clear()}getIdentifier(e){return this.kv.getByValue(e)}getValue(e){return this.kv.getByKey(e)}},FM=class extends PM{constructor(){super(e=>e.name),this.classToAllowedProps=new Map}register(e,t){typeof t==`object`?(t.allowProps&&this.classToAllowedProps.set(e,t.allowProps),super.register(e,t.identifier)):super.register(e,t)}getAllowedProps(e){return this.classToAllowedProps.get(e)}};function IM(e){if(`values`in Object)return Object.values(e);let t=[];for(let n in e)e.hasOwnProperty(n)&&t.push(e[n]);return t}function LM(e,t){let n=IM(e);if(`find`in n)return n.find(t);let r=n;for(let e=0;e<r.length;e++){let n=r[e];if(t(n))return n}}function RM(e,t){Object.entries(e).forEach(([e,n])=>t(n,e))}function zM(e,t){return e.indexOf(t)!==-1}function BM(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(t(r))return r}}var VM=class{constructor(){this.transfomers={}}register(e){this.transfomers[e.name]=e}findApplicable(e){return LM(this.transfomers,t=>t.isApplicable(e))}findByName(e){return this.transfomers[e]}},HM=e=>Object.prototype.toString.call(e).slice(8,-1),UM=e=>e===void 0,WM=e=>e===null,GM=e=>typeof e!=`object`||!e||e===Object.prototype?!1:Object.getPrototypeOf(e)===null?!0:Object.getPrototypeOf(e)===Object.prototype,KM=e=>GM(e)&&Object.keys(e).length===0,qM=e=>Array.isArray(e),JM=e=>typeof e==`string`,YM=e=>typeof e==`number`&&!isNaN(e),XM=e=>typeof e==`boolean`,ZM=e=>e instanceof RegExp,QM=e=>e instanceof Map,$M=e=>e instanceof Set,eN=e=>HM(e)===`Symbol`,tN=e=>e instanceof Date&&!isNaN(e.valueOf()),nN=e=>e instanceof Error,rN=e=>typeof e==`number`&&isNaN(e),iN=e=>XM(e)||WM(e)||UM(e)||YM(e)||JM(e)||eN(e),aN=e=>typeof e==`bigint`,oN=e=>e===1/0||e===-1/0,sN=e=>ArrayBuffer.isView(e)&&!(e instanceof DataView),cN=e=>e instanceof URL,lN=e=>e.replace(/\\/g,`\\\\`).replace(/\./g,`\\.`),uN=e=>e.map(String).map(lN).join(`.`),dN=(e,t)=>{let n=[],r=``;for(let i=0;i<e.length;i++){let a=e.charAt(i);if(!t&&a===`\\`){let t=e.charAt(i+1);if(t===`\\`){r+=`\\`,i++;continue}else if(t!==`.`)throw Error(`invalid path`)}if(a===`\\`&&e.charAt(i+1)===`.`){r+=`.`,i++;continue}if(a===`.`){n.push(r),r=``;continue}r+=a}let i=r;return n.push(i),n};function fN(e,t,n,r){return{isApplicable:e,annotation:t,transform:n,untransform:r}}var pN=[fN(UM,`undefined`,()=>null,()=>void 0),fN(aN,`bigint`,e=>e.toString(),e=>typeof BigInt<`u`?BigInt(e):(console.error(`Please add a BigInt polyfill.`),e)),fN(tN,`Date`,e=>e.toISOString(),e=>new Date(e)),fN(nN,`Error`,(e,t)=>{let n={name:e.name,message:e.message};return`cause`in e&&(n.cause=e.cause),t.allowedErrorProps.forEach(t=>{n[t]=e[t]}),n},(e,t)=>{let n=Error(e.message,{cause:e.cause});return n.name=e.name,n.stack=e.stack,t.allowedErrorProps.forEach(t=>{n[t]=e[t]}),n}),fN(ZM,`regexp`,e=>``+e,e=>{let t=e.slice(1,e.lastIndexOf(`/`)),n=e.slice(e.lastIndexOf(`/`)+1);return new RegExp(t,n)}),fN($M,`set`,e=>[...e.values()],e=>new Set(e)),fN(QM,`map`,e=>[...e.entries()],e=>new Map(e)),fN(e=>rN(e)||oN(e),`number`,e=>rN(e)?`NaN`:e>0?`Infinity`:`-Infinity`,Number),fN(e=>e===0&&1/e==-1/0,`number`,()=>`-0`,Number),fN(cN,`URL`,e=>e.toString(),e=>new URL(e))];function mN(e,t,n,r){return{isApplicable:e,annotation:t,transform:n,untransform:r}}var hN=mN((e,t)=>eN(e)?!!t.symbolRegistry.getIdentifier(e):!1,(e,t)=>[`symbol`,t.symbolRegistry.getIdentifier(e)],e=>e.description,(e,t,n)=>{let r=n.symbolRegistry.getValue(t[1]);if(!r)throw Error(`Trying to deserialize unknown symbol`);return r}),gN=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,Uint8ClampedArray].reduce((e,t)=>(e[t.name]=t,e),{}),_N=mN(sN,e=>[`typed-array`,e.constructor.name],e=>[...e],(e,t)=>{let n=gN[t[1]];if(!n)throw Error(`Trying to deserialize unknown typed array`);return new n(e)});function vN(e,t){return e?.constructor?!!t.classRegistry.getIdentifier(e.constructor):!1}var yN=mN(vN,(e,t)=>[`class`,t.classRegistry.getIdentifier(e.constructor)],(e,t)=>{let n=t.classRegistry.getAllowedProps(e.constructor);if(!n)return{...e};let r={};return n.forEach(t=>{r[t]=e[t]}),r},(e,t,n)=>{let r=n.classRegistry.getValue(t[1]);if(!r)throw Error(`Trying to deserialize unknown class '${t[1]}' - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564`);return Object.assign(Object.create(r.prototype),e)}),bN=mN((e,t)=>!!t.customTransformerRegistry.findApplicable(e),(e,t)=>[`custom`,t.customTransformerRegistry.findApplicable(e).name],(e,t)=>t.customTransformerRegistry.findApplicable(e).serialize(e),(e,t,n)=>{let r=n.customTransformerRegistry.findByName(t[1]);if(!r)throw Error(`Trying to deserialize unknown custom value`);return r.deserialize(e)}),xN=[yN,hN,bN,_N],SN=(e,t)=>{let n=BM(xN,n=>n.isApplicable(e,t));if(n)return{value:n.transform(e,t),type:n.annotation(e,t)};let r=BM(pN,n=>n.isApplicable(e,t));if(r)return{value:r.transform(e,t),type:r.annotation}},CN={};pN.forEach(e=>{CN[e.annotation]=e});var wN=(e,t,n)=>{if(qM(t))switch(t[0]){case`symbol`:return hN.untransform(e,t,n);case`class`:return yN.untransform(e,t,n);case`custom`:return bN.untransform(e,t,n);case`typed-array`:return _N.untransform(e,t,n);default:throw Error(`Unknown transformation: `+t)}else{let r=CN[t];if(!r)throw Error(`Unknown transformation: `+t);return r.untransform(e,n)}},TN=(e,t)=>{if(t>e.size)throw Error(`index out of bounds`);let n=e.keys();for(;t>0;)n.next(),t--;return n.next().value};function EN(e){if(zM(e,`__proto__`))throw Error(`__proto__ is not allowed as a property`);if(zM(e,`prototype`))throw Error(`prototype is not allowed as a property`);if(zM(e,`constructor`))throw Error(`constructor is not allowed as a property`)}var DN=(e,t)=>{EN(t);for(let n=0;n<t.length;n++){let r=t[n];if($M(e))e=TN(e,+r);else if(QM(e)){let i=+r,a=+t[++n]==0?`key`:`value`,o=TN(e,i);switch(a){case`key`:e=o;break;case`value`:e=e.get(o);break}}else e=e[r]}return e},ON=(e,t,n)=>{if(EN(t),t.length===0)return n(e);let r=e;for(let e=0;e<t.length-1;e++){let n=t[e];if(qM(r)){let e=+n;r=r[e]}else if(GM(r))r=r[n];else if($M(r)){let e=+n;r=TN(r,e)}else if(QM(r)){if(e===t.length-2)break;let i=+n,a=+t[++e]==0?`key`:`value`,o=TN(r,i);switch(a){case`key`:r=o;break;case`value`:r=r.get(o);break}}}let i=t[t.length-1];if(qM(r)?r[+i]=n(r[+i]):GM(r)&&(r[i]=n(r[i])),$M(r)){let e=TN(r,+i),t=n(e);e!==t&&(r.delete(e),r.add(t))}if(QM(r)){let e=+t[t.length-2],a=TN(r,e);switch(+i==0?`key`:`value`){case`key`:{let e=n(a);r.set(e,r.get(a)),e!==a&&r.delete(a);break}case`value`:r.set(a,n(r.get(a)));break}}return e},kN=e=>e<1;function AN(e,t,n,r=[]){if(!e)return;let i=kN(n);if(!qM(e)){RM(e,(e,a)=>AN(e,t,n,[...r,...dN(a,i)]));return}let[a,o]=e;o&&RM(o,(e,a)=>{AN(e,t,n,[...r,...dN(a,i)])}),t(a,r)}function jN(e,t,n,r){return AN(t,(t,n)=>{e=ON(e,n,e=>wN(e,t,r))},n),e}function MN(e,t,n){let r=kN(n);function i(t,n){let i=DN(e,dN(n,r));t.map(e=>dN(e,r)).forEach(t=>{e=ON(e,t,()=>i)})}if(qM(t)){let[n,a]=t;n.forEach(t=>{e=ON(e,dN(t,r),()=>e)}),a&&RM(a,i)}else RM(t,i);return e}var NN=(e,t)=>GM(e)||qM(e)||QM(e)||$M(e)||nN(e)||vN(e,t);function PN(e,t,n){let r=n.get(e);r?r.push(t):n.set(e,[t])}function FN(e,t){let n={},r;return e.forEach(e=>{if(e.length<=1)return;t||(e=e.map(e=>e.map(String)).sort((e,t)=>e.length-t.length));let[i,...a]=e;i.length===0?r=a.map(uN):n[uN(i)]=a.map(uN)}),r?KM(n)?[r]:[r,n]:KM(n)?void 0:n}var IN=(e,t,n,r,i=[],a=[],o=new Map)=>{let s=iN(e);if(!s){PN(e,i,t);let n=o.get(e);if(n)return r?{transformedValue:null}:n}if(!NN(e,n)){let t=SN(e,n),r=t?{transformedValue:t.value,annotations:[t.type]}:{transformedValue:e};return s||o.set(e,r),r}if(zM(a,e))return{transformedValue:null};let c=SN(e,n),l=c?.value??e,u=qM(l)?[]:{},d={};RM(l,(s,c)=>{if(c===`__proto__`||c===`constructor`||c===`prototype`)throw Error(`Detected property ${c}. This is a prototype pollution risk, please remove it from your object.`);let l=IN(s,t,n,r,[...i,c],[...a,e],o);u[c]=l.transformedValue,qM(l.annotations)?d[lN(c)]=l.annotations:GM(l.annotations)&&RM(l.annotations,(e,t)=>{d[lN(c)+`.`+t]=e})});let f=KM(d)?{transformedValue:u,annotations:c?[c.type]:void 0}:{transformedValue:u,annotations:c?[c.type,d]:d};return s||o.set(e,f),f};function LN(e){return Object.prototype.toString.call(e).slice(8,-1)}function RN(e){return LN(e)===`Array`}function zN(e){if(LN(e)!==`Object`)return!1;let t=Object.getPrototypeOf(e);return!!t&&t.constructor===Object&&t===Object.prototype}function BN(e,t,n,r,i){let a={}.propertyIsEnumerable.call(r,t)?`enumerable`:`nonenumerable`;a===`enumerable`&&(e[t]=n),i&&a===`nonenumerable`&&Object.defineProperty(e,t,{value:n,enumerable:!1,writable:!0,configurable:!0})}function VN(e,t={}){if(RN(e))return e.map(e=>VN(e,t));if(!zN(e))return e;let n=Object.getOwnPropertyNames(e),r=Object.getOwnPropertySymbols(e);return[...n,...r].reduce((n,r)=>{if(r===`__proto__`||RN(t.props)&&!t.props.includes(r))return n;let i=e[r];return BN(n,r,VN(i,t),e,t.nonenumerable),n},{})}var $=class{constructor({dedupe:e=!1}={}){this.classRegistry=new FM,this.symbolRegistry=new PM(e=>e.description??``),this.customTransformerRegistry=new VM,this.allowedErrorProps=[],this.dedupe=e}serialize(e){let t=new Map,n=IN(e,t,this,this.dedupe),r={json:n.transformedValue};n.annotations&&(r.meta={...r.meta,values:n.annotations});let i=FN(t,this.dedupe);return i&&(r.meta={...r.meta,referentialEqualities:i}),r.meta&&(r.meta.v=1),r}deserialize(e,t){let{json:n,meta:r}=e,i=t?.inPlace?n:VN(n);return r?.values&&(i=jN(i,r.values,r.v??0,this)),r?.referentialEqualities&&(i=MN(i,r.referentialEqualities,r.v??0)),i}stringify(e){return JSON.stringify(this.serialize(e))}parse(e){return this.deserialize(JSON.parse(e),{inPlace:!0})}registerClass(e,t){this.classRegistry.register(e,t)}registerSymbol(e,t){this.symbolRegistry.register(e,t)}registerCustom(e,t){this.customTransformerRegistry.register({name:t,...e})}allowErrorProps(...e){this.allowedErrorProps.push(...e)}};$.defaultInstance=new $,$.serialize=$.defaultInstance.serialize.bind($.defaultInstance),$.deserialize=$.defaultInstance.deserialize.bind($.defaultInstance),$.stringify=$.defaultInstance.stringify.bind($.defaultInstance),$.parse=$.defaultInstance.parse.bind($.defaultInstance),$.registerClass=$.defaultInstance.registerClass.bind($.defaultInstance),$.registerSymbol=$.defaultInstance.registerSymbol.bind($.defaultInstance),$.registerCustom=$.defaultInstance.registerCustom.bind($.defaultInstance),$.allowErrorProps=$.defaultInstance.allowErrorProps.bind($.defaultInstance),$.serialize,$.deserialize,$.stringify,$.parse,$.registerClass,$.registerCustom,$.registerSymbol,$.allowErrorProps;var HN=1e4,UN=6e3,WN=2e3,GN=3e4,KN=class{_serverUrl;useWs;baseRetryMs;maxRetryMs;onConnectionChange;token;_trpcClient;_wsClient=null;mirror=null;mirrorInit=null;connected=!1;connectedPromise=null;_systemProxy;_connectionVersion=0;connectionListeners=new Set;constructor(e){this._serverUrl=e.serverUrl.replace(/\/+$/,``),this.token=e.token;let t=typeof window<`u`;this.useWs=e.useWebSocket??t,this.onConnectionChange=e.onConnectionChange,this.baseRetryMs=e.retryDelayMs??WN,this.maxRetryMs=e.maxRetryDelayMs??GN,this._trpcClient=this.buildTrpcClient(),this._systemProxy=se(this._trpcClient)}get serverUrl(){return this._serverUrl}get connectionVersion(){return this._connectionVersion}subscribeConnectionEvents(e){return this.connectionListeners.add(e),()=>{this.connectionListeners.delete(e)}}emitConnectionEvent(e){try{this.onConnectionChange?.(e)}catch{}for(let t of this.connectionListeners)try{t(e,this._connectionVersion)}catch{}}async awaitConnected(e){if(this.connected)return;if(this.connectedPromise)return this.connectedPromise;let t=e??15e3;this.connectedPromise=(async()=>{let e=this._trpcClient.auth.me.query();Number.isFinite(t)?await new Promise((n,r)=>{let i=setTimeout(()=>r(Error(`System.awaitConnected: probe timed out after ${t}ms`)),t);e.then(()=>{clearTimeout(i),n()},e=>{clearTimeout(i),r(e instanceof Error?e:Error(String(e)))})}):await e,this.connected=!0})();try{await this.connectedPromise}finally{this.connectedPromise=null}}async init(e){if(this.mirror?.isReady())return;if(this.mirrorInit)return this.mirrorInit;let t=new oe(this._trpcClient);return this.mirror=t,this.mirrorInit=(async()=>{await this.awaitConnected(e),await t.init(e)})().finally(()=>{this.mirrorInit=null}),this.mirrorInit}async awaitReady(){if(!this.mirror?.isReady())return this.mirrorInit?this.mirrorInit:this.init()}isReady(){return this.mirror?.isReady()??!1}isConnected(){return this.connected}reconnect(){this.useWs&&(this.emitConnectionEvent(`connecting`),this._wsClient?.close(),this.disposeMirror(),this.connected=!1,this.connectedPromise=null,this._trpcClient=this.buildTrpcClient(),this._systemProxy=se(this._trpcClient))}switchServerUrl(e){let t=e.replace(/\/+$/,``);t!==this._serverUrl&&(this._serverUrl=t,this.reconnect())}async raceConnectionEndpoints(e){let t=e?.perCandidateTimeoutMs??1500,n=(()=>{try{return new URL(this._serverUrl)}catch{return null}})(),r=n?.port?Number(n.port):n?.protocol===`https:`?443:80,i=n?.protocol===`https:`?`https`:`http`,a=this._trpcClient.localNetwork?.getConnectionEndpoints;if(!a)return{winner:this._serverUrl,switched:!1};let o;try{o=(await a.query({port:r,ipv4Only:e?.ipv4Only,scheme:i})).endpoints}catch{return{winner:this._serverUrl,switched:!1}}if(o.length===0)return{winner:this._serverUrl,switched:!1};let s=await JN(o.map(e=>e.baseUrl),t);return!s||s===this._serverUrl?{winner:s??this._serverUrl,switched:!1}:(this.switchServerUrl(s),{winner:s,switched:!0})}close(){this.disposeMirror(),this.connected=!1,this.connectedPromise=null,this._wsClient?.close()}disposeMirror(){this.mirror?.dispose(),this.mirror=null,this.mirrorInit=null}async login(e,t){let n=await this._trpcClient.auth.login.mutate({username:e,password:t});if(typeof n==`object`&&n&&`token`in n){let e=n,t=e.token,r=e.requiresTotp===!0||Array.isArray(e.secondFactors)&&e.secondFactors.length>0;typeof t==`string`&&!r&&this.setToken(t)}return n}async loginVerifyTotp(e,t){let n=await this._trpcClient.auth.loginVerifyTotp.mutate({challengeToken:e,code:t});if(typeof n==`object`&&n&&`token`in n){let e=n.token;typeof e==`string`&&this.setToken(e)}return n}async loginBeginPasskey(e){return await this._trpcClient.auth.loginBeginPasskey.mutate({challengeToken:e})}async loginVerifyPasskey(e,t){let n=await this._trpcClient.auth.loginVerifyPasskey.mutate({challengeToken:e,response:t});if(typeof n==`object`&&n&&`token`in n){let e=n.token;typeof e==`string`&&this.setToken(e)}return n}async passkeyLoginBegin(){return await this._trpcClient.auth.passkeyLoginBegin.mutate()}async passkeyLoginFinish(e){let t=await this._trpcClient.auth.passkeyLoginFinish.mutate({response:e});if(typeof t==`object`&&t&&`token`in t){let e=t.token;typeof e==`string`&&this.setToken(e)}return t}async logout(){await this._trpcClient.auth.logout.mutate()}async getMe(){return await this._trpcClient.auth.me.query()}async changeOwnPassword(e){return await this._trpcClient.auth.changeOwnPassword.mutate(e)}async setupOwnTotp(){return await this._trpcClient.auth.setupOwnTotp.mutate()}async confirmOwnTotp(e){return await this._trpcClient.auth.confirmOwnTotp.mutate(e)}async disableOwnTotp(){return await this._trpcClient.auth.disableOwnTotp.mutate()}async getOwnTotpStatus(){return await this._trpcClient.auth.getOwnTotpStatus.query()}async beginOwnPasskeyRegistration(){return await this._trpcClient.auth.beginOwnPasskeyRegistration.mutate()}async finishOwnPasskeyRegistration(e){return await this._trpcClient.auth.finishOwnPasskeyRegistration.mutate(e)}async listOwnPasskeys(){return await this._trpcClient.auth.listOwnPasskeys.query()}async removeOwnPasskey(e){return await this._trpcClient.auth.removeOwnPasskey.mutate(e)}setToken(e){this.token=e}listDevices(e){return this.mirror?(e?this.mirror.query(e):this.mirror.getAllDevices()).map(e=>this.attachBinding(e)):[]}getDeviceInfo(e){return this.mirror?.getDeviceInfo(e)??null}listDeviceInfos(e){let t=this.mirror;if(!t)return[];let n=e?t.query(e):t.getAllDevices(),r=[];for(let e of n){let n=t.getDeviceInfo(e.deviceId);n&&r.push(n)}return r}getDevice(e){let t=this.mirror?.getDeviceById(e)??null;return t?this.attachBinding(t):null}getDeviceByName(e){let t=this.mirror?.getDeviceByName(e)??null;return t?this.attachBinding(t):null}getDeviceByStableId(e){let t=this.mirror?.getDeviceByStableId(e)??null;return t?this.attachBinding(t):null}async waitForDevice(e,t){this.mirror||await this.init();let n=await this.mirror.waitForDevice(e,t??3e4);return this.attachBinding(n)}onDeviceAdded(e){if(!this.mirror)throw Error(`System.onDeviceAdded: call init() before subscribing`);return this.mirror.onDeviceAdded(e)}onDeviceRemoved(e){if(!this.mirror)throw Error(`System.onDeviceRemoved: call init() before subscribing`);return this.mirror.onDeviceRemoved(e)}attachBinding(e){let t=this.lookupBinding(e.deviceId);if(t===e.binding)return e;let n=e;return n.binding=t,e}lookupBinding(e){return this.mirror?this.mirror.getDeviceById(e)?.binding??null:null}get addonPages(){return this._systemProxy.addonPages}get addonSettings(){return this._systemProxy.addonSettings}get alerts(){return this._systemProxy.alerts}get audioAnalyzer(){return this._systemProxy.audioAnalyzer}get audioCodec(){return this._systemProxy.audioCodec}get backup(){return this._systemProxy.backup}get decoder(){return this._systemProxy.decoder}get deviceManager(){return this._systemProxy.deviceManager}get deviceProvider(){return this._systemProxy.deviceProvider}get deviceState(){return this._systemProxy.deviceState}get metricsProvider(){return this._systemProxy.metricsProvider}get notificationOutput(){return this._systemProxy.notificationOutput}get pipelineExecutor(){return this._systemProxy.pipelineExecutor}get pipelineOrchestrator(){return this._systemProxy.pipelineOrchestrator}get pipelineRunner(){return this._systemProxy.pipelineRunner}get settingsStore(){return this._systemProxy.settingsStore}get storage(){return this._systemProxy.storage}get streamBroker(){return this._systemProxy.streamBroker}get turnProvider(){return this._systemProxy.turnProvider}get userManagement(){return this._systemProxy.userManagement}subscribeEvent(e,t){let n=this._trpcClient.live.onEvent.subscribe({category:e},{onData:e=>{try{t(e)}catch{}}});return()=>{try{n.unsubscribe()}catch{}}}get trpcClient(){return this._trpcClient}get wsClient(){return this._wsClient}buildTrpcClient(){let e=()=>{let e={};return this.token&&(e.Authorization=`Bearer ${this.token}`),e};if(this.useWs){let e=this._serverUrl.replace(/^http/,`ws`)+`/trpc`,t=this.baseRetryMs,n=this.maxRetryMs;return this._wsClient=st({url:e,connectionParams:()=>({token:this.token}),retryDelayMs:e=>Math.min(t*2**e,n),keepAlive:{enabled:!0,intervalMs:HN,pongTimeoutMs:UN},onOpen:()=>{this._connectionVersion+=1,this.emitConnectionEvent(`connected`)},onClose:()=>{this.emitConnectionEvent(`disconnected`)}}),ft({links:[ct({client:this._wsClient,transformer:$})]})}return this._wsClient=null,ft({links:[dt({url:`${this._serverUrl}/trpc`,headers:e,transformer:$})]})}};function qN(e){return new KN(e)}async function JN(e,t){if(e.length===0)return null;if(typeof fetch!=`function`)return e[0]??null;let n=typeof window<`u`&&window.location!==void 0&&window.location.protocol===`https:`?e.filter(e=>e.toLowerCase().startsWith(`https://`)):e;if(n.length===0)return null;let r=n.map(()=>new AbortController),i=n.map(async(e,n)=>{let i=r[n],a=setTimeout(()=>i.abort(),t);try{let t=await fetch(`${e.replace(/\/+$/,``)}/trpc/health`,{method:`GET`,signal:i.signal,credentials:`omit`});if(!t.ok)throw Error(`${t.status}`);return e}finally{clearTimeout(a)}});try{let e=await Promise.any(i);for(let e of r)try{e.abort()}catch{}return e}catch{return null}}var YN=function(e){return e.Motion=`motion`,e.Person=`person`,e.Vehicle=`vehicle`,e.Animal=`animal`,e.Audio=`audio`,e.Face=`face`,e.Plate=`plate`,e.Package=`package`,e.Doorbell=`doorbell`,e.Sensor=`sensor`,e}({}),XN=`animal.dog_cat.dog.cat.horse.sheep.cow.elephant.bear.zebra.giraffe.mouse.rabbit.deer.lion.tiger.bird.eagle.owl.pigeon.fish.whale.dolphin.snake.turtle.lizard`.split(`.`),ZN=[`person`,`people`,`pedestrian`,`rider`,`driver`,`cyclist`,`skier`,`skateboarder`,`face`,`hand`,`head`,`body`],QN=[`vehicle`,`car`,`truck`,`bus`,`motorcycle`,`bicycle`,`van`,`ambulance`,`police_car`,`fire_truck`,`train`,`subway`,`tram`,`airplane`,`boat`,`ship`,`helicopter`],$N=`face.eyes.nose.mouth.ears.eyebrows.left_eye.right_eye.pupil.iris.eyelid.eye_corner.upper_lip.lower_lip.teeth.chin.cheek.forehead.jaw.glasses.sunglasses.facial_hair.beard.mustache.facial_landmark.facial_keypoint`.split(`.`),eP=[`plate`,`license_plate`,`front_plate`,`rear_plate`,`motorcycle_plate`,`temporary_plate`,`dealer_plate`,`licensePlate`,`plate_number`,`plate_character`,`plate_digit`,`plate_letter`,`plate_symbol`,`plate_region`,`plate_country_identifier`,`plate_frame`,`plate_bolt`,`plate_sticker`,`plate_validation_tag`,`damaged_plate`,`obscured_plate`,`dirty_plate`],tP=[`motion`,`movement`,`other`],nP=[`package`,`packet`],rP=[`audio`],iP=`speech.scream.babbling.yell.bellow.whoop.whispering.laughter.snicker.crying.cry.sigh.singing.choir.chant.mantra.child_singing.rapping.humming.groan.grunt.whistling.breathing.wheeze.snoring.gasp.pant.snort.cough.throat_clearing.sneeze.sniff.cheering.applause.chatter.crowd.children_playing.bark.yip.howl.bow-wow.growling.whimper_dog.purr.meow.hiss.caterwaul.pets.livestock.doorbell.ding-dong.door.slam.knock.alarm.telephone.music.dog.dogs`.split(`.`),aP=[`doorbell`,`ring`],oP=[`lock`,`binary`,`flood`,`entry`,`door`,`leak`,`door_open`,`flooded`,`entry_open`],sP={...XN.reduce((e,t)=>({...e,[t]:`animal`}),{}),...ZN.reduce((e,t)=>({...e,[t]:`person`}),{}),...QN.reduce((e,t)=>({...e,[t]:`vehicle`}),{}),...tP.reduce((e,t)=>({...e,[t]:`motion`}),{}),...nP.reduce((e,t)=>({...e,[t]:`package`}),{}),...$N.reduce((e,t)=>({...e,[t]:`face`}),{}),...eP.reduce((e,t)=>({...e,[t]:`plate`}),{}),...rP.reduce((e,t)=>({...e,[t]:`audio`}),{}),...iP.reduce((e,t)=>({...e,[t]:`audio`}),{}),...aP.reduce((e,t)=>({...e,[t]:`doorbell`}),{}),...oP.reduce((e,t)=>({...e,[t]:`sensor`}),{})},cP=e=>$N.includes(e),lP=e=>eP.includes(e),uP=e=>XN.includes(e),dP=e=>ZN.includes(e),fP=e=>QN.includes(e),pP=e=>tP.includes(e),mP=e=>aP.includes(e),hP=e=>nP.includes(e),gP=e=>rP.includes(e)||iP.includes(e),_P=e=>oP.includes(e),vP=e=>cP(e)||lP(e),yP=e=>sP[e],bP=e=>{let{className:t}=e,n={face:`person`,plate:`vehicle`},r=sP[t];return r&&r!==t?r:n[t]},xP=Object.values(YN),SP=xP.filter(e=>e!==`motion`),CP=[`person`,`doorbell`,`package`],wP=[...CP,`vehicle`,`animal`,`audio`,`face`,`plate`],TP=[...SP];function EP(e,t){switch(e){case`critical`:return CP;case`important`:return wP;case`all`:return TP;case`custom`:return t?.length?t:SP;default:return SP}}var DP={Light:`light`,Switch:`switch`,WindowCovering:`cover`,Lock:`lock`,SecuritySystem:`alarm`,Buttons:`button`,Select:`select`,Siren:`siren`,Sensor:`sensor`,Entry:`entry`,Program:`script`,MediaPlayer:`media_player`,Outlet:`switch`,light:`light`,switch:`switch`,input_boolean:`switch`,cover:`cover`,lock:`lock`,alarm_control_panel:`alarm`,input_button:`button`,button:`button`,input_select:`select`,select:`select`,siren:`siren`,sensor:`sensor`,media_player:`media_player`,script:`script`},OP={light:`light`,switch:`switch`,input_boolean:`switch`,cover:`cover`,lock:`lock`,alarm_control_panel:`alarm`,input_button:`button`,button:`button`,input_select:`select`,select:`select`,siren:`siren`,sensor:`sensor`,binary_sensor:`sensor`,media_player:`media_player`,script:`script`,climate:`climate`,camera:`camera`,fan:`fan`,vacuum:`vacuum`,automation:`automation`,scene:`scene`,input_number:`sensor`,person:`person`,device_tracker:`tracker`,weather:`weather`,water_heater:`climate`},kP={Light:`light`,Switch:`switch`,WindowCovering:`cover`,Lock:`lock`,SecuritySystem:`alarm`,Buttons:`button`,Select:`select`,Siren:`siren`,Sensor:`sensor`,Entry:`entry`,Program:`script`,MediaPlayer:`media_player`,Camera:`camera`,Doorbell:`doorbell`,Fan:`fan`,Outlet:`switch`};function AP(e){return DP[e]||(DP[e.toLowerCase()]??null)}var jP=[`Entry`,`Light`,`Switch`,`Lock`,`SecuritySystem`,`Buttons`,`WindowCovering`,`Siren`,`Sensor`,`Select`,`Program`],MP=new Set(jP),NP=[`light`,`switch`,`input_boolean`,`cover`,`lock`,`alarm_control_panel`,`input_button`,`button`,`input_select`,`select`,`siren`,`media_player`,`script`],PP=new Set(NP),FP=[{id:`liveStream`,label:`Live Stream`,sources:{frigate:!0,scrypted:!0,rtsp:!0},adapterMethod:`getLiveStream`},{id:`multiResolution`,label:`Multi-Resolution`,sources:{frigate:!0,scrypted:!0,rtsp:!1},adapterMethod:`getResolutions`},{id:`motion`,label:`Motion Detection`,sources:{frigate:!1,scrypted:!0,rtsp:!1},adapterMethod:`getMotion`},{id:`objectDetection`,label:`Object Detection`,sources:{frigate:!1,scrypted:!0,rtsp:!1},adapterMethod:`getObjectDetections`},{id:`audioVolume`,label:`Audio Level`,sources:{frigate:!1,scrypted:!0,rtsp:!1},adapterMethod:`getAudioVolume`},{id:`audioVolumes`,label:`Audio Volumes (dBFS)`,sources:{frigate:!1,scrypted:!0,rtsp:!1},adapterMethod:`getAudioVolumes`},{id:`ptz`,label:`PTZ Control`,sources:{frigate:!1,scrypted:!0,rtsp:!1},adapterMethod:`getPTZ`},{id:`intercom`,label:`Intercom (Mic)`,sources:{frigate:!1,scrypted:!0,rtsp:!1},adapterMethod:`getIntercomSupport`},{id:`deviceStatus`,label:`Device Status`,sources:{frigate:!1,scrypted:!0,rtsp:!1},adapterMethod:`getStatus`},{id:`timeline`,label:`Detection Timeline`,sources:{frigate:!0,scrypted:!0,rtsp:!1},adapterMethod:`getCameraDayData`},{id:`clusteredTimeline`,label:`Clustered Timeline`,sources:{frigate:!0,scrypted:!0,rtsp:!1},requiresBackend:!0,adapterMethod:`getClusteredDayData`},{id:`detectionClasses`,label:`Detection Classes`,sources:{frigate:!0,scrypted:!0,rtsp:!1},adapterMethod:`getDetectionClasses`},{id:`videoClips`,label:`Video Clips`,sources:{frigate:!0,scrypted:!0,rtsp:!1},adapterMethod:`getVideoClips`},{id:`nvrPlayback`,label:`NVR Playback`,sources:{frigate:!0,scrypted:!0,rtsp:!1},adapterMethod:`getNvrPlaybackSupported`},{id:`nvrScrub`,label:`NVR Scrub/Seek`,sources:{frigate:!1,scrypted:!0,rtsp:!1},adapterMethod:`seekRecordingStream`},{id:`recordingThumbnail`,label:`Recording Thumbnails`,sources:{frigate:!0,scrypted:!0,rtsp:!1},adapterMethod:`getRecordingStreamThumbnail`},{id:`nvrSeekToLive`,label:`Seek to Live`,sources:{frigate:!1,scrypted:!0,rtsp:!1},adapterMethod:`seekNvrToLive`}];function IP(e,t,n){let r=FP.find(t=>t.id===e);return!(!r||!r.sources[t]||r.platforms&&r.platforms[n]===!1)}function LP(e){return FP.filter(t=>t.sources[e])}function RP(){return FP.filter(e=>e.requiresBackend)}var zP=e({DEFAULT_ENABLED_CLASSES:()=>SP,DetectionClass:()=>YN,ELIGIBLE_HA_DOMAINS:()=>NP,ELIGIBLE_HA_DOMAINS_SET:()=>PP,ELIGIBLE_SCRYPTED_DEVICE_TYPES:()=>jP,ELIGIBLE_SCRYPTED_DEVICE_TYPES_SET:()=>MP,FEATURE_MATRIX:()=>FP,HA_DOMAIN_TYPE_MAP:()=>OP,RAW_TO_CANONICAL:()=>DP,SCRYPTED_TYPE_TO_CANONICAL:()=>kP,System:()=>KN,TIMELINE_PRESET_ALL:()=>TP,TIMELINE_PRESET_CRITICAL:()=>CP,TIMELINE_PRESET_IMPORTANT:()=>wP,animalClasses:()=>XN,audioClasses:()=>rP,audioLabelClasses:()=>iP,createSystem:()=>qN,defaultDetectionClasses:()=>xP,detectionClassesDefaultMap:()=>sP,doorbellClasses:()=>aP,faceClasses:()=>$N,getBackendRequiredFeatures:()=>RP,getCanonicalDeviceType:()=>AP,getClassesForTimelinePreset:()=>EP,getParentClass:()=>yP,getParentDetectionClass:()=>bP,getSourceFeatures:()=>LP,isAnimalClassname:()=>uP,isAudioClassname:()=>gP,isDoorbellClassname:()=>mP,isFaceClassname:()=>cP,isFeatureAvailable:()=>IP,isLabelDetection:()=>vP,isMotionClassname:()=>pP,isPackageClassname:()=>hP,isPersonClassname:()=>dP,isPlateClassname:()=>lP,isSensorLabelClassname:()=>_P,isVehicleClassname:()=>fP,licensePlateClasses:()=>eP,motionClasses:()=>tP,packageClasses:()=>nP,personClasses:()=>ZN,raceFastestEndpoint:()=>JN,sensorLabelClasses:()=>oP,vehicleClasses:()=>QN});h();function BP({className:e}){return g(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,children:[N(`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`}),N(`circle`,{cx:`12`,cy:`12`,r:`3`})]})}function VP({className:e}){return g(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,children:[N(`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`}),N(`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`}),N(`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`}),N(`path`,{d:`m2 2 20 20`})]})}function HP({className:e}){return N(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,children:N(`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`})})}function UP({onLogin:e,serverUrl:t,logoSrc:n,error:r,className:i}){let[a,o]=k(``),[s,c]=k(``),[l,u]=k(!1),[d,f]=k(!1),[p,m]=k(null),h=r??p;return N(`div`,{className:X(`flex min-h-screen items-center justify-center bg-background p-4`,i),children:g(`div`,{className:`w-full max-w-sm`,children:[n&&N(`div`,{className:`flex justify-center mb-8`,children:N(`img`,{src:n,alt:`Logo`,className:`h-12`})}),t&&N(`p`,{className:`mb-4 text-center text-xs text-foreground-subtle truncate`,children:t}),g(`form`,{onSubmit:async t=>{if(t.preventDefault(),!d){m(null),f(!0);try{await e(a,s)}catch(e){m(e instanceof Error?e.message:`Login failed. Please try again.`)}finally{f(!1)}}},className:`space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10`,children:[h&&N(`div`,{className:`rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger`,children:h}),g(`div`,{className:`space-y-1.5`,children:[N(`label`,{className:`text-xs font-medium text-foreground-subtle`,children:`Username`}),N(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),autoComplete:`username`,required:!0,className:`w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary`})]}),g(`div`,{className:`space-y-1.5`,children:[N(`label`,{className:`text-xs font-medium text-foreground-subtle`,children:`Password`}),g(`div`,{className:`relative`,children:[N(`input`,{type:l?`text`:`password`,value:s,onChange:e=>c(e.target.value),autoComplete:`current-password`,required:!0,className:`w-full rounded-lg border border-border bg-background px-3 py-2.5 pr-10 text-sm text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary`}),N(`button`,{type:`button`,onClick:()=>u(e=>!e),className:`absolute right-2.5 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground`,tabIndex:-1,children:N(l?VP:BP,{className:`h-4 w-4`})})]})]}),g(`button`,{type:`submit`,disabled:d,className:`w-full rounded-lg bg-primary px-4 py-2.5 text-sm font-semibold text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex items-center justify-center gap-2`,children:[d&&N(HP,{className:`h-4 w-4 animate-spin`}),d?`Logging in...`:`Log in`]})]})]})})}h();var WP=`camstack_dev_token`,GP=c(null);function KP(){let e=p(GP);if(!e)throw Error(`useDevShell must be used within a DevShell`);return e}function qP(){return typeof window>`u`?null:localStorage.getItem(WP)}function JP({className:e}){return g(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,children:[N(`circle`,{cx:`12`,cy:`12`,r:`4`}),N(`path`,{d:`M12 2v2`}),N(`path`,{d:`M12 20v2`}),N(`path`,{d:`m4.93 4.93 1.41 1.41`}),N(`path`,{d:`m17.66 17.66 1.41 1.41`}),N(`path`,{d:`M2 12h2`}),N(`path`,{d:`M20 12h2`}),N(`path`,{d:`m6.34 17.66-1.41 1.41`}),N(`path`,{d:`m19.07 4.93-1.41 1.41`})]})}function YP({className:e}){return N(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,children:N(`path`,{d:`M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z`})})}function XP({children:e,serverUrl:t,title:n,token:r,onLogout:i}){let a=Pt(),o=b(()=>[lt({condition:e=>e.type===`subscription`,true:ct({client:st({url:t.replace(/^http/,`ws`)+`/trpc`,connectionParams:()=>({token:r})}),transformer:$}),false:dt({url:`${t}/trpc`,transformer:$,headers:()=>({authorization:`Bearer ${r}`})})})],[t,r]),s=b(()=>ft({links:o}),[o]),c=b(()=>Z.createClient({links:o}),[o]),l=b(()=>qN({serverUrl:t,token:r}),[t,r]);P(()=>(l.init().catch(()=>void 0),()=>{l.close()}),[l]);let u=b(()=>new T,[]),d=b(()=>({trpc:s,token:r,logout:i}),[s,r,i]);return N(Ie,{system:l,children:N(Z.Provider,{client:c,queryClient:u,children:N(j,{client:u,children:N(GP.Provider,{value:d,children:g(`div`,{className:`min-h-screen bg-background text-foreground`,children:[g(`div`,{className:`flex items-center justify-between border-b border-border bg-surface px-4 py-2`,children:[g(`div`,{className:`flex items-center gap-2`,children:[N(`span`,{className:`rounded bg-warning/20 px-2 py-0.5 text-xs font-bold text-warning`,children:`DEV MODE`}),n&&N(`span`,{className:`text-sm font-medium text-foreground`,children:n}),N(`span`,{className:`text-xs text-foreground-subtle`,children:t})]}),g(`div`,{className:`flex items-center gap-2`,children:[g(`button`,{type:`button`,onClick:a.toggleMode,className:`flex items-center gap-1.5 rounded-md px-2 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Theme: ${a.mode}`,children:[a.resolvedMode===`dark`?N(JP,{className:`h-3.5 w-3.5`}):N(YP,{className:`h-3.5 w-3.5`}),a.mode===`dark`?`Dark`:a.mode===`light`?`Light`:`System`]}),N(`button`,{type:`button`,onClick:i,className:`rounded-md px-2.5 py-1 text-xs font-medium text-danger hover:bg-danger/10 transition-colors`,children:`Logout`})]})]}),N(`div`,{className:`p-4`,children:e({trpc:s,theme:a})})]})})})})})}function ZP({children:e,serverUrl:t=`https://localhost:4443`,title:n}){let[r,i]=k(qP),a=u(async(e,n)=>{let r=await ft({links:[dt({url:`${t}/trpc`,transformer:$})]}).auth.login.mutate({username:e,password:n});if(!r.token)throw Error(`No token returned`);localStorage.setItem(WP,r.token),i(r.token)},[t]),o=u(()=>{localStorage.removeItem(WP),i(null)},[]);return r?N(Nt,{children:N(XP,{serverUrl:t,title:n,token:r,onLogout:o,children:e})}):N(Nt,{children:N(UP,{onLogin:a,serverUrl:t})})}h();function QP(e,t={}){let{serverUrl:n=`https://localhost:4443`,title:r,rootId:i=`root`}=t,a=document.getElementById(i);if(!a){console.error(`[mountAddonPage] Element #${i} not found`);return}ot(a).render(m(ZP,{serverUrl:n,title:r,children:({trpc:t,theme:n})=>m(e,{trpc:t,theme:{isDark:n.resolvedMode===`dark`},navigate:e=>{console.log(`[dev] navigate:`,e)}})}))}h();var $P=Me(`camstack:custom-field-renderers`,{});function eF({renderers:e,children:t}){return N($P.Provider,{value:e,children:t})}function tF(e){return p($P)[e]??null}h();var nF=Me(`camstack:device-context`,null);function rF({deviceId:e,device:t,children:n}){let r={deviceId:e,device:t??null};return N(nF.Provider,{value:r,children:n})}function iF(){return p(nF)?.deviceId??null}function aF(){return p(nF)?.device??null}h();var oF=Me(`camstack:widget-registry`,null),sF=new Map,cF=new Map,lF=new Set;function uF(e,t){return`${e}::${t}`}function dF(e){if(!e||typeof e!=`object`)return!1;let t=e.default;return typeof t==`object`&&!!t}function fF(e){if(!e||typeof e!=`object`)return typeof e;let t=e,n=Object.getPrototypeOf(t),r=n&&typeof n==`object`?n.constructor?.name:void 0;return{ownKeys:Object.keys(t),allKeys:Object.getOwnPropertyNames(t),proto:typeof r==`string`?r:void 0}}async function pF(e,n,i){let a=uF(e,n),o=sF.get(a);if(o)return o;let s=cF.get(a);if(s)return s;lF.has(e)||(zr(),r([{name:e,entry:i,type:`module`}],{force:!1}),lF.add(e));let c=t(`${e}/${n.startsWith(`./`)?n.slice(2):n}`).then(t=>{if(!dF(t)){let r=fF(t);throw Error(`Remote ${e} (${i}) does not expose a default record on '${n}'. Got: ${JSON.stringify(r)}`)}let r=t.default;return sF.set(a,r),cF.delete(a),r}).catch(e=>{throw cF.delete(a),e});return cF.set(a,c),c}function mF(e,t){return sF.get(uF(e,t))}var hF=3e4,gF=2e3;function _F({children:e}){let t=O(),n=f(Date.now()),{data:r}=_d(void 0,{staleTime:0,refetchOnMount:`always`,refetchInterval:e=>{let t=e.state.data;return t&&t.length>0||Date.now()-n.current>=hF?!1:gF}});il(`addon.widget-ready`,()=>{t.invalidateQueries({queryKey:[[`addonWidgets`,`listWidgets`]]})});let[i,a]=k(0),o=b(()=>r??[],[r]);P(()=>{if(o.length===0)return;let e=!1,t=new Set;for(let n of o){let r=uF(n.remote.remoteName,n.remote.exposedModule);if(t.has(r)||(t.add(r),sF.has(r)))continue;let i=n.bundleUrl;pF(n.remote.remoteName,n.remote.exposedModule,i).then(()=>{e||a(e=>e+1)}).catch(e=>{let t=e instanceof Error?e.message:String(e);(typeof globalThis<`u`?globalThis.console:void 0)?.error?.(`[WidgetRegistry] Failed to load widget remote`,{remoteName:n.remote.remoteName,exposedModule:n.remote.exposedModule,entryUrl:i,reason:t})})}return()=>{e=!0}},[o]);let s=b(()=>{let e=new Map,t=new Map;for(let n of o)e.set(`${n.addonId}/${n.stableId}`,n),t.set(n.remote.remoteName,n.bundleUrl);let n=(e,t)=>({widgetId:e,addonId:t.addonId,stableId:t.stableId,tab:t.tab,subTab:t.subTab,label:t.label,order:t.order,kind:t.kind,remote:t.remote,description:t.description,icon:t.icon,bundleUrl:t.bundleUrl,hosts:t.hosts,requires:t.requires,defaultSize:t.defaultSize,allowedSizes:t.allowedSizes,defaultColumns:t.defaultColumns,defaultRows:t.defaultRows});return{resolve:t=>{let n=e.get(t);if(!n)return;let r=mF(n.remote.remoteName,n.remote.exposedModule);if(!r)return null;let i=r[n.remote.componentKey??n.stableId];if(i)return i},metadata:t=>{let r=e.get(t);if(r)return n(t,r)},listAll:()=>{let t=[];for(let[r,i]of e)t.push(n(r,i));return t},entryUrlFor:e=>t.get(e)}},[o,i]);return N(oF.Provider,{value:s,children:e})}function vF(e){return SF().resolve(e)}function yF(e){return SF().metadata(e)}function bF(){return SF().listAll()}function xF(e,t){let n=CF(),r=t??n?.entryUrlFor(e.remoteName),[i,a]=k(0),[o,s]=k(!1);return P(()=>{if(!r||(s(!1),mF(e.remoteName,e.exposedModule)))return;let t=!1;return pF(e.remoteName,e.exposedModule,r).then(()=>{t||a(e=>e+1)}).catch(n=>{let i=n instanceof Error?n.message:String(n);(typeof globalThis<`u`?globalThis.console:void 0)?.error?.(`[WidgetRegistry] Failed to load remote component`,{remoteName:e.remoteName,exposedModule:e.exposedModule,entryUrl:r,reason:i}),t||s(!0)}),()=>{t=!0}},[e.remoteName,e.exposedModule,r]),b(()=>{if(!r||o)return;let t=mF(e.remoteName,e.exposedModule);if(!t)return null;let n=e.componentKey;return n===void 0?Object.values(t)[0]??void 0:t[n]??void 0},[e.remoteName,e.exposedModule,e.componentKey,r,i,o])}function SF(){let e=CF();if(!e)throw Error(`useWidgetRegistry(): no <WidgetRegistryProvider> in tree`);return e}function CF(){return wF(oF)}function wF(e){return p(e)}h();function TF({deviceId:e}){let t=Fe(Ke().trpcClient,e),[n,r]=k(null),[i,a]=k(!1);P(()=>{if(!t)return;let e=!1;return(async()=>{try{let n=await t.ptz?.getStatus({});if(e||!n)return;r(n.autofocus)}catch{}})(),()=>{e=!0}},[t]);let o=u(async()=>{if(!(!t?.ptz||n===null)){a(!0);try{let e=!n;await t.ptz.setAutofocus({enabled:e}),r(e)}catch(e){console.error(`ptz.setAutofocus failed`,e)}finally{a(!1)}}},[t,n]);return n===null?null:g(`div`,{className:`flex items-center justify-between border-t border-border/40 mt-2 pt-2`,children:[N(`span`,{className:`text-[10.5px] font-semibold text-foreground`,children:`Autofocus`}),g(`button`,{type:`button`,onClick:()=>void o(),disabled:i,"aria-pressed":n,className:`flex items-center gap-1.5 rounded-md px-2 py-1 text-[10px] font-medium transition-colors ${n?`bg-success/15 text-success hover:bg-success/25`:`bg-surface-elevated/40 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`} disabled:opacity-50`,children:[N(`span`,{className:`h-1.5 w-1.5 rounded-full ${n?`bg-success`:`bg-foreground-subtle/40`}`}),n?`On`:`Off`]})]})}function EF({deviceId:e}){let t=Ke(),n=Number.isFinite(e),r=Ql(t.trpcClient,n?e:0,{enabled:n});if(!n)return g(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let i=r.options?.hasAutofocus===!0;return g(Je,{title:`PTZ`,icon:N(Wa,{className:`h-3.5 w-3.5 text-foreground-subtle`}),bodyClassName:`p-3 flex flex-col overflow-y-auto`,children:[N(eu,{controls:r,mode:`panel`}),i&&N(TF,{deviceId:e})]})}h();var DF=15;function OF(e){return e.status===`replace`||e.level!==null&&e.level<=DF}function kF(e){try{return new Date(e).toLocaleDateString(void 0,{year:`numeric`,month:`short`,day:`numeric`})}catch{return``}}function AF({item:e,busy:t,canReset:n,onReset:r}){let i=OF(e),a=i?`bg-warning`:`bg-success`;return g(`div`,{className:`flex flex-col gap-1.5 rounded-md border p-3 ${i?`border-warning/40 bg-warning/5`:`border-border/40 bg-surface-elevated/30`}`,children:[g(`div`,{className:`flex items-center justify-between gap-2`,children:[N(`span`,{className:`text-xs font-semibold ${i?`text-warning`:`text-foreground`}`,children:e.label}),e.resettable&&N(`button`,{type:`button`,onClick:()=>r(e.key),disabled:t||!n,className:`rounded-md border border-border bg-surface px-2 py-0.5 text-[10px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:`Replaced`})]}),e.level===null?e.status===null?N(`span`,{className:`text-[10px] text-foreground-subtle`,children:`—`}):N(`span`,{className:`inline-flex w-fit items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium ${e.status===`replace`?`bg-warning/15 text-warning`:`bg-success/15 text-success`}`,children:e.status===`replace`?`Replace`:`OK`}):g(`div`,{className:`flex items-center gap-2`,children:[N(`div`,{className:`h-1.5 flex-1 overflow-hidden rounded-full bg-surface-elevated/60`,children:N(`div`,{className:`h-full rounded-full ${a} transition-all`,style:{width:`${Math.max(0,Math.min(100,e.level))}%`}})}),g(`span`,{className:`text-[10px] font-medium tabular-nums text-foreground-subtle`,children:[Math.round(e.level),`%`]})]}),e.lastResetAt!==null&&g(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`Replaced `,kF(e.lastResetAt)]})]})}function jF({deviceId:e}){let t=Ke(),n=Number.isFinite(e),{cap:r,slice:i,available:a}=Q({trpc:t.trpcClient,deviceId:n?e:null,cap:e=>e.consumables,slice:e=>e.state.consumables}),[o,s]=k(null),c=u(async e=>{if(r){s(e);try{await r.reset({key:e})}catch(e){console.error(`consumables.reset failed`,e)}finally{s(null)}}},[r]),l=i?.items??[];return N(Je,{title:`Consumables`,icon:N(fa,{className:`h-3.5 w-3.5 text-foreground-subtle`}),bodyClassName:`p-3 overflow-y-auto`,children:l.length===0?N(`p`,{className:`text-[11px] text-foreground-subtle italic leading-relaxed`,children:`No consumables reported.`}):N(`div`,{className:`flex flex-col gap-2`,children:l.map(e=>N(AF,{item:e,busy:o===e.key,canReset:a,onReset:e=>void c(e)},e.key))})})}h();function MF(e){let t=O(),n=hx({deviceId:e??0},{enabled:e!==null&&Number.isFinite(e),refetchInterval:5e3,retry:1}),r=gx({onSuccess:()=>{t.invalidateQueries({queryKey:[[`ptzAutotrack`]]})}}),i=vx({onSuccess:()=>{t.invalidateQueries({queryKey:[[`ptzAutotrack`]]})}}),a=u(async t=>{e!==null&&await r.mutateAsync({deviceId:e,enabled:t})},[e,r]),o=u(async t=>{e!==null&&await i.mutateAsync({deviceId:e,settings:t})},[e,i]),s=n.error?n.error.message:r.error?r.error.message:i.error?i.error.message:null;return{status:n.data??null,isLoading:n.isLoading,isPending:r.isPending||i.isPending,error:s,setEnabled:a,setSettings:o}}h();function NF({deviceId:e}){let{status:t,isLoading:n,isPending:r,error:i,setEnabled:a,setSettings:o}=MF(Number.isFinite(e)?e:null),[s,c]=k({targetType:``,stopDelaySeconds:30,disappearDelaySeconds:15}),[l,u]=k(!1);P(()=>{if(l)return;let e=t?.currentSettings;e&&c({targetType:e.targetType,stopDelaySeconds:e.stopDelaySeconds,disappearDelaySeconds:e.disappearDelaySeconds})},[t,l]);let d=N(Ki,{className:`h-3.5 w-3.5 text-foreground-subtle`});return n&&!t?N(Je,{title:`Autotrack`,icon:d,children:g(`div`,{className:`flex items-center gap-2 text-[10.5px] text-foreground-subtle`,children:[N(Ea,{className:`h-3 w-3 animate-spin`}),`Loading autotrack…`]})}):g(Je,{title:`Autotrack`,icon:d,headerRight:g(`button`,{type:`button`,onClick:()=>{a(!(t?.enabled??!1))},disabled:r,className:`flex items-center gap-1.5 rounded-md px-2 py-1 text-[10px] font-medium transition-colors ${t?.enabled?`bg-success/15 text-success hover:bg-success/25`:`bg-surface-elevated/40 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`} disabled:opacity-50`,"aria-pressed":t?.enabled??!1,children:[N(`span`,{className:`h-1.5 w-1.5 rounded-full ${t?.enabled?`bg-success`:`bg-foreground-subtle/40`}`}),t?.enabled?`Enabled`:`Disabled`]}),bodyClassName:`p-3 space-y-2`,children:[i&&g(`div`,{className:`flex items-start gap-1.5 rounded-md border border-danger/30 bg-danger/5 px-2 py-1.5 text-[10px] text-danger`,children:[N(Oi,{className:`h-3 w-3 flex-shrink-0 mt-0.5`}),N(`span`,{className:`leading-snug break-words`,children:i})]}),g(`div`,{className:`grid grid-cols-2 gap-2 px-2`,children:[(t?.supportedTargetTypes?.length??0)>0&&g(`label`,{className:`col-span-2 flex flex-col gap-1`,children:[N(`span`,{className:`text-[10px] font-medium text-foreground-subtle`,children:`Target type`}),N(`select`,{value:s.targetType,onFocus:()=>u(!0),onChange:e=>c(t=>({...t,targetType:e.target.value})),onBlur:()=>{u(!1);let e=t?.currentSettings?.targetType??``;s.targetType!==e&&o({targetType:s.targetType})},disabled:r,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground focus:border-primary focus:outline-none disabled:opacity-50`,children:(t?.supportedTargetTypes??[]).map(e=>N(`option`,{value:e.value,children:e.label},e.value))})]}),g(`label`,{className:`flex flex-col gap-1`,children:[N(`span`,{className:`text-[10px] font-medium text-foreground-subtle`,children:`Stop delay (s)`}),N(`input`,{type:`number`,min:0,max:300,value:s.stopDelaySeconds,onFocus:()=>u(!0),onChange:e=>c(t=>({...t,stopDelaySeconds:Number(e.target.value)||0})),onBlur:()=>{u(!1);let e=t?.currentSettings?.stopDelaySeconds??30;s.stopDelaySeconds!==e&&o({stopDelaySeconds:s.stopDelaySeconds})},disabled:r,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground focus:border-primary focus:outline-none disabled:opacity-50`})]}),g(`label`,{className:`flex flex-col gap-1`,children:[N(`span`,{className:`text-[10px] font-medium text-foreground-subtle`,children:`Disappear delay (s)`}),N(`input`,{type:`number`,min:0,max:300,value:s.disappearDelaySeconds,onFocus:()=>u(!0),onChange:e=>c(t=>({...t,disappearDelaySeconds:Number(e.target.value)||0})),onBlur:()=>{u(!1);let e=t?.currentSettings?.disappearDelaySeconds??15;s.disappearDelaySeconds!==e&&o({disappearDelaySeconds:s.disappearDelaySeconds})},disabled:r,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground focus:border-primary focus:outline-none disabled:opacity-50`})]})]}),N(`p`,{className:`px-2 text-[9.5px] text-foreground-subtle leading-snug italic`,children:`Settings save on blur. Vendor support varies — Reolink honours all three; Hikvision honours target type + stop delay only (disappear delay is accepted but ignored at firmware push).`})]})}function PF(){return{schedule:{kind:`always`},mode:`continuous`,preBufferSec:0,postBufferSec:0,resetTimeoutOnNewEvent:!0}}function FF(e){return e===`onMotion`||e===`onAudioThreshold`}function IF(e,t,n){return e.map((e,r)=>r===t?{...e,...n}:e)}function LF(e,t){return e.filter((e,n)=>n!==t)}function RF(e){return e.schedules&&e.schedules.length>0?[...e.schedules]:e.schedule?[e.schedule]:[]}function zF(e){return{mode:e.mode??(e.enabled?`continuous`:`off`),profiles:e.profiles,segmentSeconds:e.segmentSeconds,schedules:RF(e),triggers:e.triggers??{},preBufferSec:e.preBufferSec,postBufferSec:e.postBufferSec,retention:e.retention}}function BF(e){return{enabled:e.mode!==`off`,mode:e.mode,profiles:e.profiles?[...e.profiles]:void 0,segmentSeconds:e.segmentSeconds,schedules:e.schedules.length>0?[...e.schedules]:void 0,triggers:Object.keys(e.triggers).length>0?e.triggers:void 0,preBufferSec:e.preBufferSec,postBufferSec:e.postBufferSec,retention:e.retention}}function VF(e){return e.mode==null&&(e.rules?.length??0)>0}var HF=[{d:0,label:`S`},{d:1,label:`M`},{d:2,label:`T`},{d:3,label:`W`},{d:4,label:`T`},{d:5,label:`F`},{d:6,label:`S`}];function UF(e){return e===`onMotion`||e===`onAudioThreshold`?e:`continuous`}function WF(e,t){return t===`onAudioThreshold`?{mode:t,thresholdDbfs:e.thresholdDbfs??-30}:t===`onMotion`?{mode:t,thresholdDbfs:void 0}:{mode:t,preBufferSec:0,postBufferSec:0,thresholdDbfs:void 0}}function GF({schedule:e,onChange:t}){let n=n=>{let r=e.days??[0,1,2,3,4,5,6],i=r.includes(n)?r.filter(e=>e!==n):[...r,n].toSorted((e,t)=>e-t);t({...e,days:i})};return g(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[N(`input`,{type:`time`,value:e.start,onChange:n=>t({...e,start:n.target.value}),className:`rounded-md border border-border bg-background px-2 py-1 text-xs`}),N(`span`,{children:`–`}),N(`input`,{type:`time`,value:e.end,onChange:n=>t({...e,end:n.target.value}),className:`rounded-md border border-border bg-background px-2 py-1 text-xs`}),N(`div`,{className:`flex gap-1`,children:HF.map(({d:t,label:r})=>N(`button`,{type:`button`,onClick:()=>n(t),className:`h-6 w-6 rounded text-[10px] ${!e.days||e.days.includes(t)?`bg-primary text-primary-foreground`:`bg-surface-hover text-foreground-subtle`}`,children:r},t))})]})}function KF({rules:e,onChange:t}){return g(`div`,{className:`space-y-2`,children:[e.length===0?N(`p`,{className:`text-xs text-foreground-subtle`,children:`No rules — recording is continuous (always) when enabled.`}):null,e.map((n,r)=>g(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:[g(`div`,{className:`flex items-center justify-between gap-2`,children:[g(`select`,{className:`rounded-md border border-border bg-background px-2 py-1 text-xs`,value:n.schedule.kind,onChange:n=>{t(IF(e,r,{schedule:n.target.value===`timeOfDay`?{kind:`timeOfDay`,start:`00:00`,end:`23:59`}:{kind:`always`}}))},children:[N(`option`,{value:`always`,children:`Always`}),N(`option`,{value:`timeOfDay`,children:`Time of day`})]}),N(`button`,{type:`button`,onClick:()=>t(LF(e,r)),className:`text-foreground-subtle hover:text-red-500`,children:N(rs,{className:`h-4 w-4`})})]}),n.schedule.kind===`timeOfDay`?N(GF,{schedule:n.schedule,onChange:n=>t(IF(e,r,{schedule:n}))}):null,g(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[g(`select`,{className:`rounded-md border border-border bg-background px-2 py-1 text-xs`,value:n.mode,onChange:i=>t(IF(e,r,WF(n,UF(i.target.value)))),children:[N(`option`,{value:`continuous`,children:`Continuous`}),N(`option`,{value:`onMotion`,children:`On motion`}),N(`option`,{value:`onAudioThreshold`,children:`On audio`})]}),FF(n.mode)?g(w,{children:[g(`label`,{className:`flex items-center gap-1`,children:[`pre`,N(`input`,{type:`number`,min:0,value:n.preBufferSec,onChange:n=>t(IF(e,r,{preBufferSec:Number(n.target.value)})),className:`w-14 rounded-md border border-border bg-background px-1 py-1 text-xs`}),`s`]}),g(`label`,{className:`flex items-center gap-1`,children:[`post`,N(`input`,{type:`number`,min:0,value:n.postBufferSec,onChange:n=>t(IF(e,r,{postBufferSec:Number(n.target.value)})),className:`w-14 rounded-md border border-border bg-background px-1 py-1 text-xs`}),`s`]}),g(`label`,{className:`flex items-center gap-1`,children:[N(`input`,{type:`checkbox`,checked:n.resetTimeoutOnNewEvent,onChange:n=>t(IF(e,r,{resetTimeoutOnNewEvent:n.target.checked}))}),`reset`]})]}):null,n.mode===`onAudioThreshold`?g(`label`,{className:`flex items-center gap-1`,children:[`thr`,N(`input`,{type:`number`,value:n.thresholdDbfs??-30,onChange:n=>t(IF(e,r,{thresholdDbfs:Number(n.target.value)})),className:`w-16 rounded-md border border-border bg-background px-1 py-1 text-xs`}),`dBFS`]}):null]})]},r)),g(`button`,{type:`button`,onClick:()=>t([...e,PF()]),className:`flex items-center gap-1 rounded-md border border-dashed border-border px-3 py-1.5 text-xs text-foreground-subtle hover:border-primary hover:text-foreground`,children:[N($a,{className:`h-3.5 w-3.5`}),` Add rule`]})]})}var qF=[{value:1,label:`Mon`},{value:2,label:`Tue`},{value:3,label:`Wed`},{value:4,label:`Thu`},{value:5,label:`Fri`},{value:6,label:`Sat`},{value:0,label:`Sun`}];function JF(){return{kind:`timeOfDay`,start:`09:00`,end:`18:00`}}function YF({schedules:e,onChange:t}){let n=(n,r)=>t(e.map((e,t)=>t===n?r:e)),r=n=>t(e.filter((e,t)=>t!==n));return g(`div`,{className:`space-y-2`,children:[e.length===0?N(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Always (24/7) — add a band to restrict hours.`}):e.map((e,t)=>N(XF,{band:e,onChange:e=>n(t,e),onRemove:()=>r(t)},t)),g(`button`,{type:`button`,onClick:()=>t([...e,JF()]),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($a,{className:`h-3 w-3`}),` Add band`]})]})}function XF({band:e,onChange:t,onRemove:n}){if(e.kind===`always`)return g(`div`,{className:`flex items-center gap-2 text-xs`,children:[N(`span`,{className:`flex-1`,children:`Always`}),N(`button`,{type:`button`,onClick:()=>t(JF()),className:`text-foreground-subtle hover:text-foreground underline`,children:`Set band`}),N(`button`,{type:`button`,onClick:n,"aria-label":`Remove band`,className:`text-foreground-subtle hover:text-red-500`,children:N(Bo,{className:`h-3.5 w-3.5`})})]});let r=e.days??[],i=n=>{let i=r.includes(n)?r.filter(e=>e!==n):[...r,n];t({...e,days:i.length>0?i:void 0})};return g(`div`,{className:`space-y-1.5 rounded-md border border-border p-2`,children:[g(`div`,{className:`flex items-center gap-2 text-xs`,children:[N(`input`,{type:`time`,value:e.start,onChange:n=>t({...e,start:n.target.value}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),N(`span`,{className:`text-foreground-subtle`,children:`→`}),N(`input`,{type:`time`,value:e.end,onChange:n=>t({...e,end:n.target.value}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),N(`span`,{className:`flex-1`}),N(`button`,{type:`button`,onClick:n,"aria-label":`Remove band`,className:`text-foreground-subtle hover:text-red-500`,children:N(Bo,{className:`h-3.5 w-3.5`})})]}),g(`div`,{className:`flex flex-wrap gap-1`,children:[qF.map(e=>N(`button`,{type:`button`,onClick:()=>i(e.value),className:`rounded px-1.5 py-0.5 text-[10px] ${r.includes(e.value)?`bg-primary text-primary-foreground`:`bg-surface-hover text-foreground-subtle`}`,children:e.label},e.value)),r.length===0?N(`span`,{className:`self-center text-[10px] text-foreground-subtle`,children:`every day`}):null]})]})}h();var ZF=[`high`,`mid`,`low`],QF=[{value:`off`,label:`Off`},{value:`events`,label:`Events`},{value:`continuous`,label:`Continuous`}];function $F({initial:e,saving:t,onSave:n}){let[r,i]=k(VF(e)?`advanced`:`base`),[a,o]=k(zF(e)),[s,c]=k(e.enabled),[l,u]=k(e.rules?[...e.rules]:[]),[d,f]=k({profiles:e.profiles,segmentSeconds:e.segmentSeconds,retention:e.retention}),p=d.retention??{},m=e=>f({...d,retention:{...p,...e}}),h=e=>e===``?void 0:Number(e),_=e=>{let t=d.profiles??[...ZF],n=t.includes(e)?t.filter(t=>t!==e):[...t,e];f({...d,profiles:n.length?n:void 0})},v=e=>o({...a,triggers:{...a.triggers,...e}}),y=e=>{e===`advanced`&&l.length===0&&u([PF()]),i(e)};return g(`div`,{className:`space-y-4`,children:[N(`div`,{className:`flex gap-1 text-xs`,children:[`base`,`advanced`].map(e=>N(`button`,{type:`button`,onClick:()=>y(e),className:`rounded px-2.5 py-1 ${r===e?`bg-primary text-primary-foreground`:`bg-surface-hover text-foreground-subtle`}`,children:e===`base`?`Base`:`Advanced (rules)`},e))}),r===`base`?g(`div`,{className:`space-y-4`,children:[g(`div`,{className:`flex items-center gap-2 text-xs`,children:[N(`span`,{className:`text-foreground-subtle`,children:`Mode:`}),QF.map(e=>N(`button`,{type:`button`,onClick:()=>o({...a,mode:e.value}),className:`rounded px-2.5 py-1 ${a.mode===e.value?`bg-primary text-primary-foreground`:`bg-surface-hover text-foreground-subtle`}`,children:e.label},e.value))]}),a.mode===`off`?null:g(`div`,{children:[N(`div`,{className:`mb-1.5 text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Time bands`}),N(YF,{schedules:a.schedules,onChange:e=>o({...a,schedules:e})})]}),a.mode===`events`?g(`div`,{className:`space-y-2`,children:[N(`div`,{className:`text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Trigger`}),g(`label`,{className:`flex items-center gap-2 text-xs`,children:[N(`input`,{type:`checkbox`,checked:a.triggers.motion??!1,onChange:e=>v({motion:e.target.checked?!0:void 0})}),`Motion`]}),g(`label`,{className:`flex items-center gap-2 text-xs`,children:[N(`input`,{type:`checkbox`,checked:a.triggers.audioThresholdDbfs!=null,onChange:e=>v({audioThresholdDbfs:e.target.checked?-30:void 0})}),`Audio above threshold`,a.triggers.audioThresholdDbfs==null?null:N(`input`,{type:`number`,value:a.triggers.audioThresholdDbfs,onChange:e=>v({audioThresholdDbfs:h(e.target.value)}),className:`w-16 rounded-md border border-border bg-background px-1 py-0.5 text-xs`}),N(`span`,{className:`text-foreground-subtle`,children:`dBFS`})]}),g(`div`,{className:`flex flex-wrap items-center gap-3 text-xs`,children:[g(`label`,{className:`flex items-center gap-1`,children:[`Pre-buffer`,N(`input`,{type:`number`,min:0,value:a.preBufferSec??``,placeholder:`0`,onChange:e=>o({...a,preBufferSec:h(e.target.value)}),className:`w-16 rounded-md border border-border bg-background px-1 py-1 text-xs`}),`s`]}),g(`label`,{className:`flex items-center gap-1`,children:[`Post-buffer`,N(`input`,{type:`number`,min:0,value:a.postBufferSec??``,placeholder:`0`,onChange:e=>o({...a,postBufferSec:h(e.target.value)}),className:`w-16 rounded-md border border-border bg-background px-1 py-1 text-xs`}),`s`]})]})]}):null]}):g(`div`,{className:`space-y-4`,children:[g(`label`,{className:`flex items-center gap-2 text-xs`,children:[N(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked)}),`Record this camera`]}),g(`div`,{children:[N(`div`,{className:`mb-1.5 text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Rules`}),N(KF,{rules:l,onChange:u})]})]}),g(`div`,{className:`flex flex-wrap items-center gap-4 text-xs`,children:[g(`div`,{className:`flex items-center gap-2`,children:[N(`span`,{className:`text-foreground-subtle`,children:`Profiles:`}),ZF.map(e=>N(`button`,{type:`button`,onClick:()=>_(e),className:`rounded px-2 py-1 ${d.profiles==null||d.profiles.includes(e)?`bg-primary text-primary-foreground`:`bg-surface-hover text-foreground-subtle`}`,children:e},e))]}),g(`label`,{className:`flex items-center gap-1`,children:[`Segment`,N(`input`,{type:`number`,min:1,value:d.segmentSeconds??``,placeholder:`default`,onChange:e=>f({...d,segmentSeconds:h(e.target.value)}),className:`w-16 rounded-md border border-border bg-background px-1 py-1 text-xs`}),`s`]})]}),g(`div`,{children:[N(`div`,{className:`mb-1.5 text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Retention (empty = node default)`}),g(`div`,{className:`flex flex-wrap items-center gap-3 text-xs`,children:[g(`label`,{className:`flex items-center gap-1`,children:[`Max age`,N(`input`,{type:`number`,min:0,value:p.maxAgeDays??``,placeholder:`14`,onChange:e=>m({maxAgeDays:h(e.target.value)}),className:`w-16 rounded-md border border-border bg-background px-1 py-1 text-xs`}),`days`]}),g(`label`,{className:`flex items-center gap-1`,children:[`Max size`,N(`input`,{type:`number`,min:0,value:p.maxSizeGb??``,placeholder:`∞`,onChange:e=>m({maxSizeGb:h(e.target.value)}),className:`w-16 rounded-md border border-border bg-background px-1 py-1 text-xs`}),`GB`]})]})]}),N(`div`,{className:`flex justify-end`,children:g(`button`,{type:`button`,disabled:t,onClick:()=>{n(r===`base`?BF({...a,profiles:d.profiles,segmentSeconds:d.segmentSeconds,retention:d.retention}):{enabled:s,rules:l,profiles:d.profiles?[...d.profiles]:void 0,segmentSeconds:d.segmentSeconds,retention:d.retention})},className:`flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-60`,children:[t?N(Ea,{className:`h-3.5 w-3.5 animate-spin`}):N(lo,{className:`h-3.5 w-3.5`}),` `,`Save`]})})]})}h();var eI=Me(`camstack:vod-playback`,{request:null,play:()=>{},clear:()=>{}});function tI({children:e}){let[t,n]=k(null),r=b(()=>({request:t,play:e=>n(e),clear:()=>n(null)}),[t]);return N(eI.Provider,{value:r,children:e})}function nI(){return p(eI)}h();var rI=Me(`camstack:recorded-playback`,{bindControlChannel:null,channelOpen:!1,mode:`live`,positionMs:null,send:()=>!1});function iI({children:e}){let t=f(null),[n,r]=k(!1),[i,a]=k(`live`),[o,s]=k(null),c=u(e=>{t.current=e;let n=()=>{t.current===e&&(t.current=null,r(!1),a(`live`),s(null))};e.onopen=()=>{t.current===e&&r(!0)},e.onclose=n,e.onerror=n,e.onmessage=n=>{if(t.current!==e)return;let r=n.data;if(typeof r!=`string`)return;let i=Ur(r);i&&(i.kind===`position`?s(i.epochMs):(a(i.state),i.state===`live`&&s(null)))},e.readyState===`open`?r(!0):e.readyState===`closed`||e.readyState===`closing`?n():r(!1)},[]),l=u(e=>{let n=t.current;return!n||n.readyState!==`open`?!1:(n.send(Br(e)),!0)},[]),d=b(()=>({bindControlChannel:c,channelOpen:n,mode:i,positionMs:o,send:l}),[c,n,i,o,l]);return N(rI.Provider,{value:d,children:e})}function aI(){return p(rI)}function oI(e){let t=e.filter(e=>e.endMs>e.startMs).map(e=>({startMs:e.startMs,endMs:e.endMs})).toSorted((e,t)=>e.startMs-t.startMs),n=[];for(let e of t){let t=n[n.length-1];t&&e.startMs<=t.endMs?e.endMs>t.endMs&&(n[n.length-1]={startMs:t.startMs,endMs:e.endMs}):n.push(e)}return n}function sI(e){if(!Number.isFinite(e)||e<0)return`—`;if(e<1024)return`${Math.round(e)} B`;let t=[`KB`,`MB`,`GB`,`TB`,`PB`],n=e/1024,r=`KB`;for(let e of t){if(r=e,n<1024)break;n/=1024}return`${n>=100?Math.round(n).toString():n.toFixed(1)} ${r}`}var cI=[`object`,`motion`,`audio`];function lI(e,t,n){let r=[];for(let i of e){let e={motion:i.motion,object:i.object,audio:i.audio},a=e.motion+e.object+e.audio;if(a===0)continue;let o=Math.floor((i.bucketStart-t)/n),s=null,c=-1;for(let t of cI)e[t]>c&&(c=e[t],s=t);r.push({index:o,startMs:i.bucketStart,endMs:i.bucketStart+n,counts:e,total:a,dominant:s})}return r.toSorted((e,t)=>e.index-t.index)}function uI(e,t){return e<t.startMs?t.startMs-e:e>t.endMs?e-t.endMs:0}function dI(e,t){if(t.length===0)return null;let n=t.find(t=>e>=t.startMs&&e<=t.endMs);if(n)return{fromMs:e,toMs:n.endMs};let r=null,i=1/0;for(let n of t){let t=uI(e,n);t<i&&(i=t,r=n)}return r?{fromMs:r.startMs,toMs:r.endMs}:null}function fI(e,t,n){let r=n-t;if(r<=0)return 0;let i=(e-t)/r*100;return i<0?0:i>100?100:i}function pI(e,t){let n=new Date(e.getFullYear(),e.getMonth(),e.getDate(),0,0,0,0).getTime(),r=new Date(e.getFullYear(),e.getMonth(),e.getDate()+1,0,0,0,0).getTime();return{fromMs:n,toMs:Math.max(n,Math.min(r,t))}}var mI=[24*36e5,12*36e5,6*36e5,36e5,15*6e4];function hI(e,t,n){if(t>=e.toMs-e.fromMs)return e;let r=Math.min(Math.max(n,e.fromMs+t),e.toMs);return{fromMs:r-t,toMs:r}}function gI(e,t,n){let r=e.toMs-e.fromMs,i=e.fromMs+n,a=e.toMs+n;return i<t.fromMs&&(i=t.fromMs,a=i+r),a>t.toMs&&(a=t.toMs,i=a-r),{fromMs:i,toMs:a}}var _I=[15*6e4,5*6e4,6e4,3e4,15e3,5e3];function vI(e){let t=e/100;for(let e of _I)if(e<=t)return e;return _I[_I.length-1]??5e3}function yI(e,t,n){if(n<=1)return[{pct:0,label:new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})}];let r=[];for(let i=0;i<n;i++){let a=e+i/(n-1)*(t-e),o=fI(a,e,t),s=new Date(a).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`});r.push({pct:o,label:s})}return r}h();function bI({windowFrom:e,windowTo:t,spans:n,playheadMs:r,onSeek:i,onScrubStart:a,onScrubMove:o,onScrubEnd:s}){let[c,l]=k(null),u=!!s,[d,p]=k(!1),m=f(null),h=n=>{let r=n.currentTarget.getBoundingClientRect();if(r.width<=0)return null;let i=(n.clientX-r.left)/r.width;return e+Math.min(1,Math.max(0,i))*(t-e)},_=e=>{if(u)return;let t=h(e);t!==null&&i(t)},v=e=>{if(!u)return;e.currentTarget.setPointerCapture(e.pointerId),p(!0),a?.();let t=h(e);t!==null&&(m.current=t,o?.(t))},y=e=>{if(!u||!d)return;let t=h(e);t!==null&&(m.current=t,o?.(t))},b=e=>{if(!u||!d)return;p(!1);let t=h(e)??m.current;m.current=null,t!==null&&s?.(t)},x=()=>{if(!d)return;p(!1);let e=m.current;m.current=null,e!==null&&s?.(e)},S=e=>{let t=h(e);if(t===null)return;let n=e.currentTarget.getBoundingClientRect();l({xPct:n.width>0?(e.clientX-n.left)/n.width*100:0,ms:t})},C=()=>{l(null)},w=c===null?null:new Date(c.ms).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`});return g(`div`,{className:`relative`,children:[g(`div`,{"data-testid":`coverage-track`,"data-scrubbing":d?`true`:`false`,onClick:_,onPointerDown:v,onPointerMove:y,onPointerUp:b,onPointerCancel:x,onMouseMove:S,onMouseLeave:C,className:`relative h-5 overflow-hidden rounded bg-background/40 ${u?`cursor-ew-resize touch-none select-none`:`cursor-pointer`}`,role:`group`,"aria-label":`Recorded coverage timeline`,children:[n.map(n=>{let r=fI(n.startMs,e,t),i=fI(n.endMs,e,t);return N(`div`,{"data-testid":`coverage-band`,className:`absolute inset-y-0 bg-gradient-to-b from-primary to-primary/80`,style:{left:`${r}%`,width:`${Math.max(.5,i-r)}%`}},`${n.startMs}-${n.endMs}`)}),r===null?null:N(`div`,{"data-testid":`coverage-playhead`,className:`absolute inset-y-[-2px] w-0.5 bg-amber-500 shadow-[0_0_6px] shadow-amber-500`,style:{left:`${fI(r,e,t)}%`}})]}),c!==null&&w!==null?N(`div`,{"data-testid":`coverage-hover-tooltip`,className:`pointer-events-none absolute top-full z-10 mt-0.5 -translate-x-1/2 rounded bg-popover px-1.5 py-0.5 text-[9px] text-popover-foreground shadow`,style:{left:`${c.xPct}%`},children:w}):null]})}var xI={motion:`bg-emerald-500`,object:`bg-violet-500`,audio:`bg-orange-500`};function SI({windowFrom:e,windowTo:t,buckets:n,selectedIndex:r,onSelectBucket:i}){let a=n.reduce((e,t)=>Math.max(e,t.total),0),o=n[0],s=o?fI(o.endMs,e,t)-fI(o.startMs,e,t):0;return N(`div`,{className:`relative h-6 rounded bg-background/40`,children:n.map(n=>{if(n.total===0||n.dominant===null)return null;let o=a>0?Math.max(15,n.total/a*100):0,c=fI(n.startMs,e,t),l=n.index===r;return N(`button`,{type:`button`,"data-testid":`heatmap-bar`,title:`${new Date(n.startMs).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})} · motion ${n.counts.motion} · object ${n.counts.object}`,onClick:()=>i(n.index),className:`absolute bottom-0 rounded-t-sm transition-opacity ${xI[n.dominant]} ${l?`opacity-100 ring-1 ring-amber-400`:`opacity-80 hover:opacity-100`}`,style:{left:`${c}%`,width:`${Math.max(.6,s)}%`,height:`${o}%`}},n.index)})})}h();function CI({mediaUrl:e,kind:t}){let[n,r]=k(!1);return e&&!n?N(`img`,{src:e,alt:``,className:`h-full w-full object-cover`,loading:`lazy`,onError:()=>r(!0)}):N(`div`,{className:`flex h-full w-full items-center justify-center text-white/30`,children:N(wI,{kind:t,large:!0})})}function wI({kind:e,large:t=!1}){return N(e===`object`?yi:e===`audio`?Yo:Qr,{className:t?`h-7 w-7`:`h-3.5 w-3.5 text-foreground-subtle`})}var TI=[`motion`,`object`,`audio`];function EI(e){return new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})}function DI({clips:e,loading:t,busyKey:n,onPlay:r,enabledKinds:i,onToggleKind:a,hasMore:o,onLoadMore:s}){let c=N(`div`,{className:`flex items-center gap-3 pb-1`,children:TI.map(e=>g(`label`,{className:`flex cursor-pointer items-center gap-1 text-xs text-foreground-subtle select-none`,children:[N(`input`,{type:`checkbox`,checked:i.has(e),onChange:()=>a(e),className:`h-3.5 w-3.5 accent-primary`}),e]},e))});return t&&e.length===0?g(`div`,{className:`space-y-2`,children:[c,N(`div`,{className:`px-1 py-2 text-xs text-foreground-subtle`,children:`Loading events…`})]}):e.length===0?g(`div`,{className:`space-y-2`,children:[c,N(`div`,{className:`px-1 py-2 text-xs text-foreground-subtle`,children:`No events in this window.`})]}):g(`div`,{className:`space-y-2`,children:[c,t?N(`div`,{className:`px-1 text-[10px] text-foreground-subtle`,children:`Loading events…`}):null,N(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3`,children:e.map(e=>{let t=`event:${e.id}`;return g(`button`,{type:`button`,disabled:n!==null,onClick:()=>r(e),className:`group overflow-hidden rounded-lg border border-border text-left transition-colors hover:border-primary disabled:opacity-60`,children:[g(`div`,{className:`relative aspect-video bg-black/90`,children:[N(CI,{mediaUrl:e.mediaUrl,kind:e.kind}),N(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/0 transition-colors group-hover:bg-black/30`,children:n===t?N(Ea,{className:`h-6 w-6 animate-spin text-white`}):N(Qa,{className:`h-6 w-6 text-white opacity-0 transition-opacity group-hover:opacity-100`})})]}),g(`div`,{className:`flex items-center gap-1.5 bg-surface px-2 py-1.5`,children:[N(wI,{kind:e.kind}),g(`div`,{className:`min-w-0 flex-1`,children:[N(`div`,{className:`truncate text-xs font-medium text-foreground`,children:e.label}),N(`div`,{className:`text-[10px] text-foreground-subtle`,children:EI(e.timestamp)})]})]})]},t)})}),e.length>0?g(`div`,{className:`flex items-center gap-2 pt-1 text-[11px] text-foreground-subtle`,children:[g(`span`,{children:[`(`,e.length,` shown)`]}),o?N(`button`,{type:`button`,onClick:s,className:`rounded px-2 py-0.5 text-[11px] font-medium text-primary hover:underline`,children:`Load more`}):null]}):null]})}function OI(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function kI(e){let t=e.split(`-`),n=t[0]===void 0?NaN:parseInt(t[0],10),r=t[1]===void 0?NaN:parseInt(t[1],10),i=t[2]===void 0?NaN:parseInt(t[2],10);return isNaN(n)||isNaN(r)||isNaN(i)?null:new Date(n,r-1,i)}function AI({day:e,onDayChange:t,view:n,dayBounds:r,onViewChange:i}){let a=e=>{let n=kI(e.target.value);n!==null&&t(n)},o=n.toMs-n.fromMs,s=(()=>{let e=0,t=1/0;for(let n=0;n<mI.length;n++){let r=mI[n];if(r===void 0)continue;let i=Math.abs(r-o);i<t&&(t=i,e=n)}return e})(),c=n.toMs,l=()=>{let e=mI[Math.min(s+1,mI.length-1)];e!==void 0&&i(hI(r,e,c))},u=()=>{let e=mI[Math.max(s-1,0)];e!==void 0&&i(hI(r,e,c))},d=s<mI.length-1,f=s>0,p=Math.max(1,Math.round(o*.9)),m=n.fromMs>r.fromMs,h=n.toMs<r.toMs;return g(`div`,{className:`flex items-center gap-2`,children:[N(`input`,{type:`date`,value:OI(e),max:OI(new Date),onChange:a,className:`rounded border border-border bg-background px-2 py-0.5 text-[11px] text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":`Select recording day`}),g(`div`,{className:`ml-auto flex items-center gap-1`,children:[N(`button`,{type:`button`,onClick:()=>{i(gI(n,r,-p))},disabled:!m,title:`Earlier (pan back)`,"aria-label":`Pan earlier`,className:`rounded p-1 text-foreground-subtle transition-colors hover:bg-background/60 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40`,children:N(wi,{size:14})}),N(`button`,{type:`button`,onClick:()=>{i(gI(n,r,p))},disabled:!h,title:`Later (pan forward)`,"aria-label":`Pan later`,className:`rounded p-1 text-foreground-subtle transition-colors hover:bg-background/60 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40`,children:N(Ue,{size:14})}),N(`span`,{className:`mx-0.5 h-3 w-px bg-border`,"aria-hidden":`true`}),N(`button`,{type:`button`,onClick:u,disabled:!f,title:`Zoom out`,"aria-label":`Zoom out`,className:`rounded p-1 text-foreground-subtle transition-colors hover:bg-background/60 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40`,children:N(os,{size:13})}),N(`button`,{type:`button`,onClick:l,disabled:!d,title:`Zoom in`,"aria-label":`Zoom in`,className:`rounded p-1 text-foreground-subtle transition-colors hover:bg-background/60 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40`,children:N(as,{size:13})})]}),N(`span`,{className:`text-[9px] text-foreground-subtle`,children:jI(o)})]})}function jI(e){let t=e/36e5;if(t>=24)return`24h`;if(t>=1)return`${Math.round(t)}h`;let n=e/6e4;return`${Math.round(n)}m`}h();var MI=[`motion`,`object`,`audio`],NI=60,PI=18e3/100,FI=5e3,II=1e4,LI=[],RI={live:`Live`,loading:`Loading…`,playing:`Playing`,paused:`Paused`,gap:`No footage`,ended:`Ended`,error:`Error`};function zI({deviceId:e}){let t=Ke(),n=nI(),[r,i]=k(null),[a,o]=k(null),[s,c]=k(null),[l,d]=k(null),p=aI(),{send:m,mode:h,positionMs:_}=p,[v,y]=k(!1),x=p.channelOpen&&!v,S=f(x);S.current=x;let C=b(()=>({scrubStart:()=>{},scrubTo:()=>{},scrubCommit:e=>{m({t:`scrubCommit`,epoch:e})},seek:e=>{m({t:`seek`,epoch:e})}}),[m]),w=f(h);w.current=h;let{state:T,beginScrub:E,updateScrub:D,endScrub:O,seek:A,setPlayhead:j,reset:M}=Zr(C,u(()=>w.current===`live`,[]));P(()=>{_!==null&&j(_)},[_,j]),P(()=>{(!p.channelOpen||h===`live`)&&M()},[p.channelOpen,h,M]);let F=u(()=>{m({t:`goLive`}),M()},[m,M]),I=u(()=>{m({t:`setRate`,rate:+(w.current===`paused`)})},[m]),[L,R]=k(()=>new Set(MI)),ee=u(e=>{R(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),[z,B]=k(NI),V=u(()=>{B(e=>e+NI)},[]);P(()=>{B(NI)},[r]);let[te,H]=k(()=>new Date),[U,ne]=k(()=>pI(new Date,Date.now())),re=b(()=>pI(te,Date.now()),[te]),ie=u(e=>{H(e),ne(pI(e,Date.now())),i(null)},[]),ae=u(e=>{ne(e),i(null)},[]),oe=f(null),se=u(e=>{let t=Math.abs(e.deltaX)>Math.abs(e.deltaY)?e.deltaX:e.shiftKey?e.deltaY:0;if(t===0)return;e.preventDefault();let n=t*PI;ne(e=>gI(e,re,n))},[re]),W=vI(U.toMs-U.fromMs),ce=bx({deviceId:e,fromMs:U.fromMs,toMs:U.toMs}),le=ay({deviceId:e,since:U.fromMs,until:U.toMs,bucketMs:W}),ue=ce.data?.ranges??LI,de=b(()=>oI(ue),[ue]),fe=b(()=>lI(le.data??[],U.fromMs,W),[le.data,U.fromMs,W]),pe=r===null?void 0:fe.find(e=>e.index===r),G=pe!==void 0,me=pe?.startMs??0,he=pe?Math.min(pe.endMs,U.toMs):0,ge=ry({deviceId:e,since:me,until:he,limit:z,projection:`slim`},{enabled:G&&L.has(`object`)}),_e=ny({deviceId:e,since:me,until:he,limit:z,projection:`slim`},{enabled:G&&L.has(`motion`)}),ve=iy({deviceId:e,since:me,until:he,limit:z,projection:`slim`},{enabled:G&&L.has(`audio`)}),ye=b(()=>{if(!pe)return[];let e=[];if(L.has(`object`))for(let t of ge.data??[])e.push({id:t.id,timestamp:t.timestamp,kind:`object`,label:t.label??t.className,mediaUrl:t.mediaUrl});if(L.has(`motion`))for(let t of _e.data??[])e.push({id:t.id,timestamp:t.timestamp,kind:`motion`,label:`Motion (${t.regionCount})`,mediaUrl:t.mediaUrl});if(L.has(`audio`))for(let t of ve.data??[])e.push({id:t.id,timestamp:t.timestamp,kind:`audio`,label:t.classification?.className??`Audio`,mediaUrl:t.mediaUrl});return e.toSorted((e,t)=>t.timestamp-e.timestamp)},[pe,L,ge.data,_e.data,ve.data]),be=b(()=>!!(L.has(`object`)&&(ge.data?.length??0)===z||L.has(`motion`)&&(_e.data?.length??0)===z||L.has(`audio`)&&(ve.data?.length??0)===z),[L,ge.data,_e.data,ve.data,z]),xe=u(async(r,i,a,s,l)=>{c(r),d(null);try{let r=await t.trpcClient.recording.getPlaybackManifest.query({deviceId:e,fromMs:i,toMs:a});r?.playbackUrl?(o(l),n.play({url:r.playbackUrl,label:s})):d(`No playable footage for this selection.`)}catch{d(`Could not load this recording.`)}finally{c(null)}},[t,e,n]),Se=u(e=>{let t=dI(e,de);if(!t)return;if(S.current){A(t.fromMs,`timeline`);return}let n=`Recording · ${new Date(t.fromMs).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}`;xe(`seek:${t.fromMs}`,t.fromMs,t.toMs,n,t.fromMs)},[de,xe,A]),Ce=u(()=>{E(`timeline`)},[E]),we=u(e=>{D(e,`timeline`)},[D]),Te=u(e=>{O(dI(e,de)?.fromMs??e,`timeline`)},[de,O]),Ee=u(e=>{if(S.current){A(e.timestamp-FI,`timeline`);return}let t=`${e.label} · ${new Date(e.timestamp).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})}`;xe(`event:${e.id}`,e.timestamp-FI,e.timestamp+II,t,e.timestamp)},[xe,A]),De=u(e=>{i(t=>t===e?null:e)},[]),Oe=ce.isLoading,ke=le.isLoading,Ae=(ge.isLoading||_e.isLoading||ve.isLoading)&&G,je=b(()=>yI(U.fromMs,U.toMs,5),[U.fromMs,U.toMs]),Me=x?T.scrubbing?T.scrubEpoch:T.playheadEpoch:a,Ne=x&&(h===`playing`||h===`paused`);return g(`div`,{className:`space-y-3`,children:[ce.isError?N(xl,{variant:`warning`,message:`Recorder unavailable — the recording service may not be running for this node.`}):null,l?N(xl,{variant:`warning`,message:l}):null,N(AI,{day:te,onDayChange:ie,view:U,dayBounds:re,onViewChange:ae}),p.channelOpen?g(`div`,{"data-testid":`frame-push-status-row`,className:`flex flex-wrap items-center gap-2 text-[10px]`,children:[N(`span`,{"data-testid":`frame-push-mode-chip`,className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 font-semibold uppercase tracking-wider ${x&&h!==`live`?h===`error`?`bg-rose-500/15 text-rose-400`:`bg-primary/15 text-primary`:`bg-background/40 text-foreground-subtle`}`,children:x?RI[h]:`HLS mode`}),x&&_!==null&&!T.scrubbing?N(`span`,{className:`tabular-nums text-foreground-subtle`,children:new Date(_).toLocaleTimeString()}):null,Ne?g(`button`,{type:`button`,"data-testid":`frame-push-rate-toggle`,onClick:I,className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 font-medium text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,title:h===`paused`?`Resume playback`:`Pause playback`,children:[N(h===`paused`?Qa:Ja,{className:`h-3 w-3`}),h===`paused`?`Resume`:`Pause`]}):null,x&&h!==`live`?g(`button`,{type:`button`,"data-testid":`frame-push-go-live`,onClick:F,className:`inline-flex items-center gap-1 rounded bg-danger/10 px-1.5 py-0.5 font-medium text-danger transition-colors hover:bg-danger/20`,title:`Return to the live stream`,children:[N(ao,{className:`h-3 w-3`}),`Go live`]}):null,N(`button`,{type:`button`,"data-testid":`frame-push-hls-toggle`,onClick:()=>y(e=>!e),className:`ml-auto inline-flex items-center gap-1 rounded px-1.5 py-0.5 font-medium transition-colors ${v?`bg-primary/15 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:`Play recordings through the HLS player instead of the live WebRTC session`,children:`HLS`})]}):null,g(`div`,{ref:oe,onWheel:se,className:`space-y-1`,children:[g(`div`,{className:`space-y-1`,children:[N(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Recorded`}),Oe?N(`div`,{className:`h-5 animate-pulse rounded bg-background/40`}):de.length===0?N(yl,{icon:aa,title:`No recordings for this window.`}):N(bI,{windowFrom:U.fromMs,windowTo:U.toMs,spans:de,playheadMs:Me,onSeek:Se,...x?{onScrubStart:Ce,onScrubMove:we,onScrubEnd:Te}:{}})]}),g(`div`,{className:`space-y-1`,children:[N(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Events · density`}),ke?N(`div`,{className:`h-6 animate-pulse rounded bg-background/40`}):N(SI,{windowFrom:U.fromMs,windowTo:U.toMs,buckets:fe,selectedIndex:r,onSelectBucket:De})]}),N(`div`,{className:`relative h-3`,children:je.map(e=>N(`span`,{className:`absolute -translate-x-1/2 text-[9px] text-foreground-subtle`,style:{left:`${e.pct}%`},children:e.label},e.pct))})]}),pe?N(DI,{clips:ye,loading:Ae,busyKey:s,onPlay:Ee,enabledKinds:L,onToggleKind:ee,hasMore:be,onLoadMore:V}):N(`p`,{className:`text-[11px] text-foreground-subtle`,children:x?`Click or drag the coverage bar to play from any point (frames play in the main player above), or click a density bar to browse that window’s events.`:`Click the coverage bar to play from any point, or a density bar to browse that window’s events.`})]})}h();var BI=1440*60*1e3;function VI(e){let t=Math.round(e/1e3),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?`${n}h ${r}m`:r>0?`${r}m ${i}s`:`${i}s`}function HI({deviceId:e}){let t=O(),n=Ax({deviceId:e}),r=wx({deviceId:e}),i=Dx(),a=Ox(),o=t=>{i.mutate({deviceId:e,config:t},{onSuccess:()=>{r.refetch(),n.refetch()}})},s=u(()=>{a.mutate({deviceId:e},{onSuccess:()=>{t.invalidateQueries({queryKey:[[`recording`]]})}})},[e,t,a]),c=b(()=>Date.now(),[]),l=bx({deviceId:e,fromMs:c-BI,toMs:c}),d=n.data?ie.safeParse(n.data):null,f=d?.success?d.data:null,p=r.data?le.safeParse(r.data):null,m=p?.success?p.data:null,h=l.data?.ranges??[],_=h.reduce((e,t)=>e+Math.max(0,t.endMs-t.startMs),0),v=f?.enabled===!0&&f.activeMode===`continuous`;return g(`div`,{className:`space-y-3`,children:[N(Je,{title:`Settings`,icon:N(ho,{className:`h-3.5 w-3.5 text-foreground-subtle`}),collapsible:!0,defaultOpen:!1,children:m?N($F,{initial:m,saving:i.isPending,onSave:o},JSON.stringify(m)):N(`div`,{className:`px-1 py-2 text-xs text-foreground-subtle`,children:`Loading settings…`})}),N(Je,{title:`Recording`,icon:N(aa,{className:`h-3.5 w-3.5 text-foreground-subtle`}),headerRight:g(`span`,{className:`flex items-center gap-2`,children:[v?g(`span`,{className:`flex items-center gap-1.5 text-[10px] text-emerald-500`,children:[N(ao,{className:`h-3 w-3`}),` Recording`]}):null,N(`button`,{type:`button`,onClick:s,disabled:a.isPending,"aria-label":`Rescan storage`,className:`flex items-center rounded p-0.5 text-foreground-subtle transition-colors hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50`,children:N(oo,{className:`h-3.5 w-3.5 ${a.isPending?`animate-spin`:``}`})})]}),children:g(`div`,{className:`space-y-3`,children:[g(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-3`,children:[N(Ge,{label:`Status`,icon:N(ji,{className:`h-3.5 w-3.5 ${v?`text-emerald-500`:``}`}),footer:f?.nodeId?`node: ${f.nodeId}`:void 0,children:n.isLoading?`…`:v?`Recording (continuous)`:`Idle`}),N(Ge,{label:`Storage`,icon:N(ma,{className:`h-3.5 w-3.5`}),children:f?sI(f.storageBytes):`—`}),N(Ge,{label:`Recorded (24h)`,icon:N(Ii,{className:`h-3.5 w-3.5`}),footer:`${h.length} segment range${h.length===1?``:`s`}`,children:l.isLoading?`…`:VI(_)})]}),n.isError?N(xl,{variant:`warning`,message:`Recorder unavailable — the recording service may not be running for this node.`}):null,N(zI,{deviceId:e}),N(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Recordings play in the main player above — switch back to live from there.`})]})})]})}h();var UI={"host/motion-zones-grid":E(()=>a(()=>import(`./MotionZonesSettings-DnVWhQ3W.js`).then(e=>({default:e.MotionZonesSettings})),__vite__mapDeps([0,1,2,3,4]))),"host/privacy-mask-grid":E(()=>a(()=>import(`./PrivacyMaskSettings-BF7f56Ma.js`).then(e=>({default:e.PrivacyMaskSettings})),__vite__mapDeps([5,1,2,3,4]))),"host/ptz-panel":EF,"host/consumables-panel":jF,"host/ptz-autotrack":NF,"host/recording-panel":HI};h();function WI(e){let{widgetId:t,deviceId:n}=e,r=UI[t];return r===void 0?N(GI,{...e}):n===void 0?N(JI,{widgetId:t,reason:`missing-device-context`}):N(x,{fallback:N(qI,{}),children:N(r,{deviceId:n})})}function GI(e){let{widgetId:t}=e,n=yF(t);return n===void 0?N(JI,{widgetId:t,reason:`unknown`}):N(KI,{...e,metadata:n})}function KI(e){let{widgetId:t,host:n=`device-tab`,config:r,deviceId:i,integrationId:a,instanceId:o,size:s,columns:c,rows:l,metadata:u}=e,d=xF(u.remote,u.bundleUrl),f=b(()=>o??t,[o,t]);return d===null?N(qI,{}):d===void 0?N(JI,{widgetId:t,reason:`missing-export`}):u.requires.deviceContext&&i===void 0?N(JI,{widgetId:t,reason:`missing-device-context`}):u.requires.integrationContext&&a===void 0?N(JI,{widgetId:t,reason:`missing-integration-context`}):N(d,{instanceId:f,host:n,config:r,deviceId:i,integrationId:a,size:s,columns:c,rows:l})}function qI(){return g(`div`,{className:`rounded-lg border border-border bg-surface/40 p-4 animate-pulse`,children:[N(`div`,{className:`h-3 w-24 bg-foreground-subtle/20 rounded mb-2`}),N(`div`,{className:`h-2 w-full bg-foreground-subtle/10 rounded mb-1`}),N(`div`,{className:`h-2 w-3/4 bg-foreground-subtle/10 rounded`})]})}function JI({widgetId:e,reason:t}){return N(`div`,{className:`rounded-lg border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:t===`unknown`?`Widget "${e}" not registered`:t===`missing-export`?`Widget "${e}" bundle does not export this stableId`:t===`missing-device-context`?`Widget "${e}" requires a deviceId`:`Widget "${e}" requires an integrationId`})}h();var YI=Object.defineProperty,XI=Object.getOwnPropertySymbols,ZI=Object.prototype.hasOwnProperty,QI=Object.prototype.propertyIsEnumerable,$I=(e,t,n)=>t in e?YI(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,eL=(e,t)=>{for(var n in t||={})ZI.call(t,n)&&$I(e,n,t[n]);if(XI)for(var n of XI(t))QI.call(t,n)&&$I(e,n,t[n]);return e},tL=(e,t)=>{var n={};for(var r in e)ZI.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&XI)for(var r of XI(e))t.indexOf(r)<0&&QI.call(e,r)&&(n[r]=e[r]);return n},nL;(e=>{let t=class t{constructor(e,n,r,a){if(this.version=e,this.errorCorrectionLevel=n,this.modules=[],this.isFunction=[],e<t.MIN_VERSION||e>t.MAX_VERSION)throw RangeError(`Version value out of range`);if(a<-1||a>7)throw RangeError(`Mask value out of range`);this.size=e*4+17;let o=[];for(let e=0;e<this.size;e++)o.push(!1);for(let e=0;e<this.size;e++)this.modules.push(o.slice()),this.isFunction.push(o.slice());this.drawFunctionPatterns();let s=this.addEccAndInterleave(r);if(this.drawCodewords(s),a==-1){let e=1e9;for(let t=0;t<8;t++){this.applyMask(t),this.drawFormatBits(t);let n=this.getPenaltyScore();n<e&&(a=t,e=n),this.applyMask(t)}}i(0<=a&&a<=7),this.mask=a,this.applyMask(a),this.drawFormatBits(a),this.isFunction=[]}static encodeText(n,r){let i=e.QrSegment.makeSegments(n);return t.encodeSegments(i,r)}static encodeBinary(n,r){let i=e.QrSegment.makeBytes(n);return t.encodeSegments([i],r)}static encodeSegments(e,r,a=1,s=40,c=-1,l=!0){if(!(t.MIN_VERSION<=a&&a<=s&&s<=t.MAX_VERSION)||c<-1||c>7)throw RangeError(`Invalid value`);let u,d;for(u=a;;u++){let n=t.getNumDataCodewords(u,r)*8,i=o.getTotalBits(e,u);if(i<=n){d=i;break}if(u>=s)throw RangeError(`Data too long`)}for(let e of[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH])l&&d<=t.getNumDataCodewords(u,e)*8&&(r=e);let f=[];for(let t of e){n(t.mode.modeBits,4,f),n(t.numChars,t.mode.numCharCountBits(u),f);for(let e of t.getData())f.push(e)}i(f.length==d);let p=t.getNumDataCodewords(u,r)*8;i(f.length<=p),n(0,Math.min(4,p-f.length),f),n(0,(8-f.length%8)%8,f),i(f.length%8==0);for(let e=236;f.length<p;e^=253)n(e,8,f);let m=[];for(;m.length*8<f.length;)m.push(0);return f.forEach((e,t)=>m[t>>>3]|=e<<7-(t&7)),new t(u,r,m,c)}getModule(e,t){return 0<=e&&e<this.size&&0<=t&&t<this.size&&this.modules[t][e]}getModules(){return this.modules}drawFunctionPatterns(){for(let e=0;e<this.size;e++)this.setFunctionModule(6,e,e%2==0),this.setFunctionModule(e,6,e%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);let e=this.getAlignmentPatternPositions(),t=e.length;for(let n=0;n<t;n++)for(let r=0;r<t;r++)n==0&&r==0||n==0&&r==t-1||n==t-1&&r==0||this.drawAlignmentPattern(e[n],e[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(e){let t=this.errorCorrectionLevel.formatBits<<3|e,n=t;for(let e=0;e<10;e++)n=n<<1^(n>>>9)*1335;let a=(t<<10|n)^21522;i(a>>>15==0);for(let e=0;e<=5;e++)this.setFunctionModule(8,e,r(a,e));this.setFunctionModule(8,7,r(a,6)),this.setFunctionModule(8,8,r(a,7)),this.setFunctionModule(7,8,r(a,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,r(a,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,r(a,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,r(a,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;let t=this.version<<12|e;i(t>>>18==0);for(let e=0;e<18;e++){let n=r(t,e),i=this.size-11+e%3,a=Math.floor(e/3);this.setFunctionModule(i,a,n),this.setFunctionModule(a,i,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),a=e+r,o=t+n;0<=a&&a<this.size&&0<=o&&o<this.size&&this.setFunctionModule(a,o,i!=2&&i!=4)}}drawAlignmentPattern(e,t){for(let n=-2;n<=2;n++)for(let r=-2;r<=2;r++)this.setFunctionModule(e+r,t+n,Math.max(Math.abs(r),Math.abs(n))!=1)}setFunctionModule(e,t,n){this.modules[t][e]=n,this.isFunction[t][e]=!0}addEccAndInterleave(e){let n=this.version,r=this.errorCorrectionLevel;if(e.length!=t.getNumDataCodewords(n,r))throw RangeError(`Invalid argument`);let a=t.NUM_ERROR_CORRECTION_BLOCKS[r.ordinal][n],o=t.ECC_CODEWORDS_PER_BLOCK[r.ordinal][n],s=Math.floor(t.getNumRawDataModules(n)/8),c=a-s%a,l=Math.floor(s/a),u=[],d=t.reedSolomonComputeDivisor(o);for(let n=0,r=0;n<a;n++){let i=e.slice(r,r+l-o+(n<c?0:1));r+=i.length;let a=t.reedSolomonComputeRemainder(i,d);n<c&&i.push(0),u.push(i.concat(a))}let f=[];for(let e=0;e<u[0].length;e++)u.forEach((t,n)=>{(e!=l-o||n>=c)&&f.push(t[e])});return i(f.length==s),f}drawCodewords(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw RangeError(`Invalid argument`);let n=0;for(let t=this.size-1;t>=1;t-=2){t==6&&(t=5);for(let i=0;i<this.size;i++)for(let a=0;a<2;a++){let o=t-a,s=t+1&2?i:this.size-1-i;!this.isFunction[s][o]&&n<e.length*8&&(this.modules[s][o]=r(e[n>>>3],7-(n&7)),n++)}}i(n==e.length*8)}applyMask(e){if(e<0||e>7)throw RangeError(`Mask value out of range`);for(let t=0;t<this.size;t++)for(let n=0;n<this.size;n++){let r;switch(e){case 0:r=(n+t)%2==0;break;case 1:r=t%2==0;break;case 2:r=n%3==0;break;case 3:r=(n+t)%3==0;break;case 4:r=(Math.floor(n/3)+Math.floor(t/2))%2==0;break;case 5:r=n*t%2+n*t%3==0;break;case 6:r=(n*t%2+n*t%3)%2==0;break;case 7:r=((n+t)%2+n*t%3)%2==0;break;default:throw Error(`Unreachable`)}!this.isFunction[t][n]&&r&&(this.modules[t][n]=!this.modules[t][n])}}getPenaltyScore(){let e=0;for(let n=0;n<this.size;n++){let r=!1,i=0,a=[0,0,0,0,0,0,0];for(let o=0;o<this.size;o++)this.modules[n][o]==r?(i++,i==5?e+=t.PENALTY_N1:i>5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[n][o],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n<this.size;n++){let r=!1,i=0,a=[0,0,0,0,0,0,0];for(let o=0;o<this.size;o++)this.modules[o][n]==r?(i++,i==5?e+=t.PENALTY_N1:i>5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[o][n],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n<this.size-1;n++)for(let r=0;r<this.size-1;r++){let i=this.modules[n][r];i==this.modules[n][r+1]&&i==this.modules[n+1][r]&&i==this.modules[n+1][r+1]&&(e+=t.PENALTY_N2)}let n=0;for(let e of this.modules)n=e.reduce((e,t)=>e+ +!!t,n);let r=this.size*this.size,a=Math.ceil(Math.abs(n*20-r*10)/r)-1;return i(0<=a&&a<=9),e+=a*t.PENALTY_N4,i(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(this.version==1)return[];{let e=Math.floor(this.version/7)+2,t=this.version==32?26:Math.ceil((this.version*4+4)/(e*2-2))*2,n=[6];for(let r=this.size-7;n.length<e;r-=t)n.splice(1,0,r);return n}}static getNumRawDataModules(e){if(e<t.MIN_VERSION||e>t.MAX_VERSION)throw RangeError(`Version number out of range`);let n=(16*e+128)*e+64;if(e>=2){let t=Math.floor(e/7)+2;n-=(25*t-10)*t-55,e>=7&&(n-=36)}return i(208<=n&&n<=29648),n}static getNumDataCodewords(e,n){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw RangeError(`Degree out of range`);let n=[];for(let t=0;t<e-1;t++)n.push(0);n.push(1);let r=1;for(let i=0;i<e;i++){for(let e=0;e<n.length;e++)n[e]=t.reedSolomonMultiply(n[e],r),e+1<n.length&&(n[e]^=n[e+1]);r=t.reedSolomonMultiply(r,2)}return n}static reedSolomonComputeRemainder(e,n){let r=n.map(e=>0);for(let i of e){let e=i^r.shift();r.push(0),n.forEach((n,i)=>r[i]^=t.reedSolomonMultiply(n,e))}return r}static reedSolomonMultiply(e,t){if(e>>>8||t>>>8)throw RangeError(`Byte out of range`);let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return i(n>>>8==0),n}finderPenaltyCountPatterns(e){let t=e[1];i(t<=this.size*3);let n=t>0&&e[2]==t&&e[3]==t*3&&e[4]==t&&e[5]==t;return(n&&e[0]>=t*4&&e[6]>=t?1:0)+(n&&e[6]>=t*4&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){t[0]==0&&(e+=this.size),t.pop(),t.unshift(e)}};t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;function n(e,t,n){if(t<0||t>31||e>>>t)throw RangeError(`Value out of range`);for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function r(e,t){return(e>>>t&1)!=0}function i(e){if(!e)throw Error(`Assertion error`)}let a=class e{constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw RangeError(`Invalid argument`);this.bitData=n.slice()}static makeBytes(t){let r=[];for(let e of t)n(e,8,r);return new e(e.Mode.BYTE,t.length,r)}static makeNumeric(t){if(!e.isNumeric(t))throw RangeError(`String contains non-numeric characters`);let r=[];for(let e=0;e<t.length;){let i=Math.min(t.length-e,3);n(parseInt(t.substring(e,e+i),10),i*3+1,r),e+=i}return new e(e.Mode.NUMERIC,t.length,r)}static makeAlphanumeric(t){if(!e.isAlphanumeric(t))throw RangeError(`String contains unencodable characters in alphanumeric mode`);let r=[],i;for(i=0;i+2<=t.length;i+=2){let a=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i))*45;a+=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i+1)),n(a,11,r)}return i<t.length&&n(e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i)),6,r),new e(e.Mode.ALPHANUMERIC,t.length,r)}static makeSegments(t){return t==``?[]:e.isNumeric(t)?[e.makeNumeric(t)]:e.isAlphanumeric(t)?[e.makeAlphanumeric(t)]:[e.makeBytes(e.toUtf8ByteArray(t))]}static makeEci(t){let r=[];if(t<0)throw RangeError(`ECI assignment value out of range`);if(t<128)n(t,8,r);else if(t<16384)n(2,2,r),n(t,14,r);else if(t<1e6)n(6,3,r),n(t,21,r);else throw RangeError(`ECI assignment value out of range`);return new e(e.Mode.ECI,0,r)}static isNumeric(t){return e.NUMERIC_REGEX.test(t)}static isAlphanumeric(t){return e.ALPHANUMERIC_REGEX.test(t)}getData(){return this.bitData.slice()}static getTotalBits(e,t){let n=0;for(let r of e){let e=r.mode.numCharCountBits(t);if(r.numChars>=1<<e)return 1/0;n+=4+e+r.bitData.length}return n}static toUtf8ByteArray(e){e=encodeURI(e);let t=[];for(let n=0;n<e.length;n++)e.charAt(n)==`%`?(t.push(parseInt(e.substring(n+1,n+3),16)),n+=2):t.push(e.charCodeAt(n));return t}};a.NUMERIC_REGEX=/^[0-9]*$/,a.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,a.ALPHANUMERIC_CHARSET=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`;let o=a;e.QrSegment=a})(nL||={}),(e=>{(e=>{let t=class{constructor(e,t){this.ordinal=e,this.formatBits=t}};t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),e.Ecc=t})(e.QrCode||={})})(nL||={}),(e=>{(e=>{let t=class{constructor(e,t){this.modeBits=e,this.numBitsCharCount=t}numCharCountBits(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}};t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),e.Mode=t})(e.QrSegment||={})})(nL||={});var rL=nL,iL={L:rL.QrCode.Ecc.LOW,M:rL.QrCode.Ecc.MEDIUM,Q:rL.QrCode.Ecc.QUARTILE,H:rL.QrCode.Ecc.HIGH},aL=128,oL=`L`,sL=`#FFFFFF`,cL=`#000000`,lL=!1,uL=1,dL=4,fL=0,pL=.1;function mL(e,t=0){let n=[];return e.forEach(function(e,r){let i=null;e.forEach(function(a,o){if(!a&&i!==null){n.push(`M${i+t} ${r+t}h${o-i}v1H${i+t}z`),i=null;return}if(o===e.length-1){if(!a)return;i===null?n.push(`M${o+t},${r+t} h1v1H${o+t}z`):n.push(`M${i+t},${r+t} h${o+1-i}v1H${i+t}z`);return}a&&i===null&&(i=o)})}),n.join(``)}function hL(e,t){return e.slice().map((e,n)=>n<t.y||n>=t.y+t.h?e:e.map((e,n)=>n<t.x||n>=t.x+t.w?e:!1))}function gL(e,t,n,r){if(r==null)return null;let i=e.length+n*2,a=Math.floor(t*pL),o=i/t,s=(r.width||a)*o,c=(r.height||a)*o,l=r.x==null?e.length/2-s/2:r.x*o,u=r.y==null?e.length/2-c/2:r.y*o,d=r.opacity==null?1:r.opacity,f=null;if(r.excavate){let e=Math.floor(l),t=Math.floor(u);f={x:e,y:t,w:Math.ceil(s+l-e),h:Math.ceil(c+u-t)}}let p=r.crossOrigin;return{x:l,y:u,h:c,w:s,excavation:f,opacity:d,crossOrigin:p}}function _L(e,t){return t==null?e?dL:fL:Math.max(Math.floor(t),0)}function vL({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:a,size:o,boostLevel:s}){let c=_.useMemo(()=>{let r=(Array.isArray(e)?e:[e]).reduce((e,t)=>(e.push(...rL.QrSegment.makeSegments(t)),e),[]);return rL.QrCode.encodeSegments(r,iL[t],n,void 0,void 0,s)},[e,t,n,s]),{cells:l,margin:u,numCells:d,calculatedImageSettings:f}=_.useMemo(()=>{let e=c.getModules(),t=_L(r,i);return{cells:e,margin:t,numCells:e.length+t*2,calculatedImageSettings:gL(e,o,t,a)}},[c,o,a,r,i]);return{qrcode:c,margin:u,cells:l,numCells:d,calculatedImageSettings:f}}var yL=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),bL=_.forwardRef(function(e,t){let n=e,{value:r,size:i=aL,level:a=oL,bgColor:o=sL,fgColor:s=cL,includeMargin:c=lL,minVersion:l=uL,boostLevel:u,marginSize:d,imageSettings:f}=n,p=tL(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`marginSize`,`imageSettings`]),{style:m}=p,h=tL(p,[`style`]),g=f?.src,v=_.useRef(null),y=_.useRef(null),b=_.useCallback(e=>{v.current=e,typeof t==`function`?t(e):t&&(t.current=e)},[t]),[x,S]=_.useState(!1),{margin:C,cells:w,numCells:T,calculatedImageSettings:E}=vL({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:d,imageSettings:f,size:i});_.useEffect(()=>{if(v.current!=null){let e=v.current,t=e.getContext(`2d`);if(!t)return;let n=w,r=y.current,a=E!=null&&r!==null&&r.complete&&r.naturalHeight!==0&&r.naturalWidth!==0;a&&E.excavation!=null&&(n=hL(w,E.excavation));let c=window.devicePixelRatio||1;e.height=e.width=i*c;let l=i/T*c;t.scale(l,l),t.fillStyle=o,t.fillRect(0,0,T,T),t.fillStyle=s,yL?t.fill(new Path2D(mL(n,C))):w.forEach(function(e,n){e.forEach(function(e,r){e&&t.fillRect(r+C,n+C,1,1)})}),E&&(t.globalAlpha=E.opacity),a&&t.drawImage(r,E.x+C,E.y+C,E.w,E.h)}}),_.useEffect(()=>{S(!1)},[g]);let D=eL({height:i,width:i},m),O=null;return g!=null&&(O=_.createElement(`img`,{src:g,key:g,style:{display:`none`},onLoad:()=>{S(!0)},ref:y,crossOrigin:E?.crossOrigin})),_.createElement(_.Fragment,null,_.createElement(`canvas`,eL({style:D,height:i,width:i,ref:b,role:`img`},h)),O)});bL.displayName=`QRCodeCanvas`;var xL=_.forwardRef(function(e,t){let n=e,{value:r,size:i=aL,level:a=oL,bgColor:o=sL,fgColor:s=cL,includeMargin:c=lL,minVersion:l=uL,boostLevel:u,title:d,marginSize:f,imageSettings:p}=n,m=tL(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`title`,`marginSize`,`imageSettings`]),{margin:h,cells:g,numCells:v,calculatedImageSettings:y}=vL({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:f,imageSettings:p,size:i}),b=g,x=null;p!=null&&y!=null&&(y.excavation!=null&&(b=hL(g,y.excavation)),x=_.createElement(`image`,{href:p.src,height:y.h,width:y.w,x:y.x+h,y:y.y+h,preserveAspectRatio:`none`,opacity:y.opacity,crossOrigin:y.crossOrigin}));let S=mL(b,h);return _.createElement(`svg`,eL({height:i,width:i,viewBox:`0 0 ${v} ${v}`,ref:t,role:`img`},m),!!d&&_.createElement(`title`,null,d),_.createElement(`path`,{fill:o,d:`M0,0 h${v}v${v}H0z`,shapeRendering:`crispEdges`}),_.createElement(`path`,{fill:s,d:S,shapeRendering:`crispEdges`}),x)});xL.displayName=`QRCodeSVG`;var SL=192;function CL({value:e,size:t=SL,className:n,alt:r}){let i=e.trim();return i.length===0?null:N(`div`,{className:X(`inline-flex rounded-md bg-white p-2`,n),children:N(xL,{value:i,size:t,marginSize:1,title:r??`QR code`})})}var wL=`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none disabled:opacity-50 disabled:cursor-not-allowed`;function TL({value:e,onChange:t,disabled:n}){let r=[];for(let e of te)r.includes(e.region)||r.push(e.region);return g(`select`,{className:wL,value:e,disabled:n,onChange:e=>t(e.target.value),children:[!V(e)&&N(`option`,{value:``,children:`— Select timezone —`}),r.map(e=>N(`optgroup`,{label:e,children:te.filter(t=>t.region===e).map(e=>N(`option`,{value:e.id,children:e.label},e.id))},e))]})}h();var EL=`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none disabled:opacity-50 disabled:cursor-not-allowed`,DL=`block text-[11px] font-medium text-foreground mb-1 break-words`,OL=`text-[10px] text-foreground-subtle mt-0.5 break-words`;function kL({label:e,description:t,required:n,span:r,children:i,translationFn:a}){let o=r===2?`col-span-1 @[480px]:col-span-2`:r===3?`col-span-1 @[480px]:col-span-2 @[880px]:col-span-3`:r===4?`col-span-1 @[480px]:col-span-2 @[1140px]:col-span-4`:`col-span-1`,s=yR(e,a),c=yR(t,a),l=s!==void 0&&s!==``;return g(`div`,{className:`${o} min-w-0`,children:[l&&g(`label`,{className:DL,children:[s,n&&N(`span`,{className:`text-danger ml-0.5`,children:`*`})]}),i,c&&N(`p`,{className:OL,children:c})]})}function AL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:N(`input`,{type:e.inputType??`text`,className:EL,value:t==null?``:String(t),placeholder:e.placeholder,maxLength:e.maxLength,pattern:e.pattern,disabled:r||e.disabled,onChange:e=>n(e.target.value)})})}function jL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){let[a,o]=k(t==null?``:String(t)),s=f(!1);P(()=>{s.current||o(t==null?``:String(t))},[t]);let c=e=>{if(o(e),e===``||e===`-`){n(void 0);return}let t=Number(e);Number.isNaN(t)||n(t)};return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:g(`div`,{className:`flex items-center gap-1`,children:[N(`input`,{type:`number`,className:EL,value:a,placeholder:e.placeholder,min:e.min,max:e.max,step:e.step,disabled:r||e.disabled,onFocus:()=>{s.current=!0},onBlur:()=>{s.current=!1},onChange:e=>c(e.target.value)}),e.unit&&N(`span`,{className:`text-xs text-foreground-subtle whitespace-nowrap`,children:e.unit})]})})}function ML({field:e,value:t,onChange:n,disabled:r,translationFn:i}){let a=!!t,o=r||e.disabled;return e.style===`checkbox`?N(kL,{label:void 0,description:e.description,required:e.required,span:e.span,translationFn:i,children:g(`label`,{className:`flex items-center gap-2 cursor-pointer select-none`,children:[N(`input`,{type:`checkbox`,className:`h-3.5 w-3.5 rounded border-border accent-primary`,checked:a,disabled:o,onChange:e=>n(e.target.checked)}),N(`span`,{className:`text-xs font-medium text-foreground`,children:yR(e.label,i)}),e.required&&N(`span`,{className:`text-danger`,children:`*`})]})}):N(kL,{label:void 0,description:e.description,required:e.required,span:e.span,translationFn:i,children:g(`div`,{className:`flex items-center justify-between`,children:[g(`span`,{className:`block text-[11px] font-medium text-foreground mb-1 break-words mb-0`,children:[yR(e.label,i),e.required&&N(`span`,{className:`text-danger ml-0.5`,children:`*`})]}),N(`button`,{type:`button`,role:`switch`,"aria-checked":a,disabled:o,onClick:()=>!o&&n(!a),className:[`relative inline-flex h-4 w-8 shrink-0 items-center rounded-full transition-colors duration-150`,a?`bg-primary`:`bg-foreground-subtle/30`,o?`opacity-50 cursor-not-allowed`:`cursor-pointer`].join(` `),children:N(`span`,{className:[`inline-block h-3 w-3 rounded-full bg-white shadow transition-transform duration-150`,a?`translate-x-4`:`translate-x-0.5`].join(` `)})})]})})}function NL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){let a=e.options.some(e=>e.value===``);return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:g(`select`,{className:EL,value:t==null?``:String(t),disabled:r||e.disabled,onChange:e=>n(e.target.value),children:[!e.required&&!a&&N(`option`,{value:``,children:`— Select —`}),e.options.map(e=>N(`option`,{value:e.value,children:e.label},e.value))]})})}function PL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:N(TL,{value:typeof t==`string`?t:``,onChange:n,disabled:r||e.disabled})})}function FL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:N(`input`,{type:`datetime-local`,className:EL,value:typeof t==`string`?t:``,placeholder:e.placeholder,disabled:r||e.disabled,onChange:e=>n(e.target.value)})})}function IL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){let a=Array.isArray(t)?t:[],o=t=>{if(a.includes(t))n(a.filter(e=>e!==t));else{if(e.maxItems!==void 0&&a.length>=e.maxItems)return;n([...a,t])}};return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:N(`div`,{className:`flex flex-wrap gap-2`,children:e.options.map(t=>{let n=a.includes(t.value);return g(`label`,{className:[`flex items-center gap-1.5 rounded-md border px-2 py-1 text-xs cursor-pointer select-none transition-colors`,n?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground hover:bg-surface`,r||e.disabled?`opacity-50 cursor-not-allowed`:``].join(` `),children:[N(`input`,{type:`checkbox`,className:`sr-only`,checked:n,disabled:r||e.disabled,onChange:()=>o(t.value)}),t.label]},t.value)})})})}function LL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){let[a,o]=k(!1),s=e.showToggle!==!1;return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:g(`div`,{className:`relative`,children:[N(`input`,{type:a?`text`:`password`,className:EL+(s?` pr-9`:``),value:t==null?``:String(t),placeholder:e.placeholder,disabled:r||e.disabled,onChange:e=>n(e.target.value)}),s&&N(`button`,{type:`button`,className:`absolute right-2 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground`,tabIndex:-1,onClick:()=>o(e=>!e),children:N(a?ta:na,{className:`h-3.5 w-3.5`})})]})})}function RL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:N(`textarea`,{className:`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none disabled:opacity-50 disabled:cursor-not-allowed resize-y min-h-[60px]`,value:t==null?``:String(t),placeholder:e.placeholder,rows:e.rows??3,maxLength:e.maxLength,disabled:r||e.disabled,onChange:e=>n(e.target.value)})})}function zL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){let a=t==null,o=e.nullable===!0,s=a?e.default??e.min:Number(t),c=e.showValue!==!1,l=e.nullLabel??`Auto`,u=r||e.disabled,d=e.displayScale??1,f=e.min/d,p=e.max/d,m=s/d,h=(e.step??1)/d;if(o&&a)return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:g(`button`,{className:`w-full rounded-lg border border-dashed border-border px-3 py-2 text-xs text-foreground-subtle hover:border-primary/40 hover:text-primary transition-colors text-left`,disabled:u,onClick:()=>n(e.default??e.min),children:[l,` — click to set manually`]})});let _=e.showStepper===!0&&c,v=t=>{let r=s+t*(e.step??1),i=Math.min(e.max,Math.max(e.min,r));i!==s&&n(i)},y=`flex h-6 w-6 shrink-0 items-center justify-center rounded border border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:cursor-not-allowed disabled:opacity-40`;return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:g(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[g(`div`,{className:`flex min-w-0 flex-1 basis-[160px] items-center gap-2`,children:[N(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums shrink-0`,children:f}),N(`input`,{type:`range`,className:`min-w-0 flex-1 h-1 accent-primary cursor-pointer disabled:opacity-50`,min:f,max:p,step:h,value:m,disabled:u,onChange:e=>n(Number(e.target.value)*d)}),N(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums shrink-0`,children:p})]}),(c||o||e.unit)&&g(`div`,{className:`flex shrink-0 items-center gap-2`,children:[_&&N(`button`,{type:`button`,className:y,disabled:u||s<=e.min,onClick:()=>v(-1),title:`Decrease by ${e.step??1}`,"aria-label":`Decrement`,children:N(Ra,{className:`h-3 w-3`})}),c&&N(`input`,{type:`number`,className:`w-16 rounded border border-border bg-surface px-1.5 py-0.5 text-xs text-center text-foreground tabular-nums focus:outline-none focus:ring-1 focus:ring-primary`,min:f,max:p,step:h,value:m,disabled:u,onChange:t=>{if(t.target.value===``){n(o?null:e.min);return}let r=Number(t.target.value)*d,i=e.step??1,a=r-e.min,s=e.min+Math.round(a/i)*i;n(Math.min(e.max,Math.max(e.min,s)))}}),_&&N(`button`,{type:`button`,className:y,disabled:u||s>=e.max,onClick:()=>v(1),title:`Increase by ${e.step??1}`,"aria-label":`Increment`,children:N($a,{className:`h-3 w-3`})}),e.unit&&N(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.unit}),o&&N(`button`,{className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors`,title:`Reset to ${l}`,disabled:u,onClick:()=>n(null),children:l})]})]})})}function BL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){let a=Array.isArray(t)?t:[],[o,s]=k(``),c=f(null),l=u(t=>{let r=t.trim();!r||a.includes(r)||e.maxTags!==void 0&&a.length>=e.maxTags||(n([...a,r]),s(``))},[a,e.maxTags,n]),d=e=>n(a.filter(t=>t!==e)),p=e=>{e.key===`Enter`||e.key===`,`?(e.preventDefault(),l(o)):e.key===`Backspace`&&o===``&&a.length>0&&d(a[a.length-1])},m=r||e.disabled;return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:g(`div`,{className:[`flex flex-wrap gap-1.5 rounded-md border border-border bg-background px-2 py-1.5 min-h-[38px] cursor-text`,`focus-within:border-primary focus-within:ring-1 focus-within:ring-primary/30`,m?`opacity-50 cursor-not-allowed`:``].join(` `),onClick:()=>!m&&c.current?.focus(),children:[a.map(e=>g(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-primary/10 px-1.5 py-0.5 text-xs text-primary`,children:[e,!m&&N(`button`,{type:`button`,onClick:()=>d(e),className:`hover:text-danger`,children:N(rs,{className:`h-2.5 w-2.5`})})]},e)),N(`input`,{ref:c,type:`text`,className:`flex-1 min-w-[80px] bg-transparent text-sm text-foreground outline-none placeholder:text-foreground-disabled`,value:o,placeholder:a.length===0?e.placeholder??`Add tags…`:``,disabled:m,list:`tags-suggestions-${e.key}`,onChange:e=>s(e.target.value),onKeyDown:p,onBlur:()=>{o.trim()&&l(o)}}),e.suggestions&&N(`datalist`,{id:`tags-suggestions-${e.key}`,children:e.suggestions.map(e=>N(`option`,{value:e},e))})]})})}function VL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){let{nodes:a}=cl(),o=typeof t==`string`?t:``,s=e.showOffline?a:a.filter(e=>e.isOnline);return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:g(`select`,{className:`w-full px-3 py-2 text-sm bg-background border border-border rounded-lg text-foreground focus:outline-none focus:border-primary/50 disabled:opacity-50`,value:o,onChange:e=>n(e.target.value),disabled:r,children:[N(`option`,{value:``,children:`Select node…`}),s.map(e=>g(`option`,{value:e.id,disabled:!e.isOnline,children:[e.shortName,e.isOnline?``:` (offline)`]},e.id))]})})}function HL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){let{nodes:a}=cl(),o=new Set(Array.isArray(t)?t.map(String):[]),s=e.showOffline?a:a.filter(e=>e.isOnline),c=e=>{let t=new Set(o);t.has(e)?t.delete(e):t.add(e),n([...t])};return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:N(`div`,{className:`flex flex-wrap gap-1.5`,children:s.map(e=>{let t=o.has(e.id);return N(`button`,{type:`button`,onClick:()=>c(e.id),disabled:r||!e.isOnline,className:`px-2.5 py-1 text-xs font-medium rounded-md border transition-colors ${t?`border-primary bg-primary/10 text-primary`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover`} ${e.isOnline?``:`opacity-50 cursor-not-allowed`}`,children:e.shortName},e.id)})})})}function UL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){let a=t==null?`#000000`:String(t);return g(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:[g(`div`,{className:`flex items-center gap-2`,children:[N(`input`,{type:`color`,className:`h-9 w-9 rounded-md border border-border bg-background cursor-pointer p-0.5 disabled:opacity-50`,value:a,disabled:r||e.disabled,onChange:e=>n(e.target.value)}),N(`input`,{type:`text`,className:`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none disabled:opacity-50 disabled:cursor-not-allowed flex-1 font-mono`,value:a,placeholder:`#000000`,disabled:r||e.disabled,onChange:e=>n(e.target.value)})]}),e.presets&&e.presets.length>0&&N(`div`,{className:`flex gap-1.5 mt-1.5`,children:e.presets.map(t=>N(`button`,{type:`button`,className:`h-5 w-5 rounded-md border border-border hover:scale-110 transition-transform disabled:opacity-50`,style:{backgroundColor:t},disabled:r||e.disabled,title:t,onClick:()=>n(t)},t))})]})}function WL({field:e,value:t,onChange:n,disabled:r,translationFn:i,onTestField:a,onAction:o,externalProbe:s}){let[c,l]=k(`idle`),[d,f]=k(null),p=s?.status??c,m=s?.result??d,h=!!a||!!o,_=u(async()=>{if(h){l(`probing`),f(null);try{let n=a?await a(e.key,t):await o(`test-probe`,e.key,t),r=n&&typeof n==`object`?n:{status:`error`,error:`Probe handler returned no result`};f(r),l(r.status===`ok`?`ok`:`error`)}catch(e){f({status:`error`,error:e instanceof Error?e.message:String(e)}),l(`error`)}}},[a,o,e.key,t,h]),v=p===`probing`?`border-primary/40 bg-primary/10 text-primary`:p===`ok`?`border-success/40 bg-success/10 text-success hover:bg-success/15`:p===`error`?`border-danger/40 bg-danger/10 text-danger hover:bg-danger/15`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,y=p===`probing`?N(Ea,{className:`h-3 w-3 animate-spin`}):N(p===`ok`?ki:p===`error`?Oi:$o,{className:`h-3 w-3`});return g(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:[g(`div`,{className:`@container flex items-center gap-2`,style:{containerType:`inline-size`},children:[g(`button`,{type:`button`,onClick:_,title:`Test`,disabled:e.disabled||p===`probing`||!h||!t,className:`flex-shrink-0 inline-flex items-center gap-1.5 rounded-md border px-2 py-2 text-xs font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed @[280px]:px-3 ${v}`,children:[y,N(`span`,{className:`hidden @[280px]:inline`,children:`Test`})]}),N(`input`,{type:e.inputType??`url`,className:`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none disabled:opacity-50 disabled:cursor-not-allowed flex-1 min-w-0`,value:t==null?``:String(t),placeholder:e.placeholder,disabled:r||e.disabled,onChange:e=>{n(e.target.value),c!==`idle`&&(l(`idle`),f(null))}})]}),p===`ok`&&m?.labels&&m.labels.length>0&&N(`div`,{className:`flex flex-wrap gap-1 mt-1.5`,children:m.labels.map((e,t)=>N(`span`,{className:`text-xs bg-success/10 text-success rounded px-2 py-0.5 font-mono`,children:e},t))}),p===`error`&&m?.error&&N(`p`,{className:`text-xs text-danger mt-1 truncate`,title:m.error,children:m.error})]})}function GL({field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a}){let[o,s]=k(e.defaultCollapsed??!1),c=e.style===`accordion`;return N(`div`,{className:`${e.span===2?`col-span-2`:e.span===3?`col-span-3`:e.span===4?`col-span-4`:`col-span-1`} min-w-0`,children:g(`div`,{className:`@container rounded-lg border border-border bg-surface/50 overflow-hidden`,style:{containerType:`inline-size`},children:[g(`div`,{className:[`px-3 py-2 flex items-center justify-between min-w-0`,c?`cursor-pointer hover:bg-surface`:``].join(` `),onClick:c?()=>s(e=>!e):void 0,children:[N(`span`,{className:`text-xs font-semibold text-foreground min-w-0 break-words`,children:yR(e.label,i)}),c&&N(`span`,{className:`text-foreground-subtle text-xs shrink-0 ml-2`,children:o?`▸`:`▾`})]}),!o&&N(`div`,{className:`px-3 pb-3 grid grid-cols-1 @[480px]:grid-cols-2 gap-x-4 gap-y-3`,children:e.fields.map(e=>N(_R,{field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a},e.key))})]})})}function KL({field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,onAction:o}){let[s,c]=k(e.tabs[0]?.id??``),l=e.span===2?`col-span-2`:e.span===3?`col-span-3`:e.span===4?`col-span-4`:`col-span-1`;return e.tabs.length===0?null:g(`div`,{className:`${l} min-w-0`,children:[e.label&&N(`div`,{className:DL,children:yR(e.label,i)}),g(`div`,{className:`@container rounded-lg border border-border-subtle bg-surface-hover/40 overflow-hidden`,style:{containerType:`inline-size`},children:[N(`div`,{className:`flex flex-wrap gap-1 p-1.5 border-b border-border-subtle bg-surface/40`,role:`tablist`,children:e.tabs.map(e=>{let t=e.id===s;return g(`button`,{type:`button`,role:`tab`,"aria-selected":t,onClick:()=>c(e.id),className:`inline-flex items-center gap-1.5 whitespace-nowrap rounded-md px-2.5 py-1 text-[11px] transition-colors ${t?`bg-primary text-primary-foreground font-medium shadow-sm`:`bg-transparent text-foreground-subtle hover:bg-surface hover:text-foreground`}`,children:[N(`span`,{children:yR(e.label,i)}),e.badge&&N(`span`,{className:`text-[9px] px-1 py-0.5 rounded-full font-medium ${t?`bg-primary-foreground/20 text-primary-foreground`:`bg-primary/10 text-primary`}`,children:e.badge})]},e.id)})}),e.tabs.map(e=>e.id===s?N(`div`,{role:`tabpanel`,className:`px-3 pb-3 pt-2 grid grid-cols-1 @[480px]:grid-cols-2 gap-x-4 gap-y-3`,children:e.fields.map((s,c)=>{let l=`key`in s&&typeof s.key==`string`?s.key:`__${e.id}__${c}`;return N(_R,{field:s,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,onAction:o},l)})},e.id):null)]})]})}function qL({span:e}){return N(`div`,{className:e===2?`col-span-2`:e===3?`col-span-3`:e===4?`col-span-4`:`col-span-full`,children:N(`hr`,{className:`border-border`})})}var JL={info:{border:`border-info`,bg:`bg-info/5`,text:`text-info`},warning:{border:`border-warning`,bg:`bg-warning/5`,text:`text-warning`},success:{border:`border-success`,bg:`bg-success/5`,text:`text-success`},danger:{border:`border-danger`,bg:`bg-danger/5`,text:`text-danger`}};function YL(e){if(typeof window>`u`||typeof DOMParser>`u`)return``;let t=new Set([`A`,`UL`,`OL`,`LI`,`STRONG`,`EM`,`CODE`,`BR`,`P`,`SPAN`]),n=new DOMParser().parseFromString(`<div>${e}</div>`,`text/html`),r=n.body.firstElementChild;if(!r)return``;let i=e=>{let r=Array.from(e.children);for(let e of r){if(!t.has(e.tagName)){let t=n.createTextNode(e.textContent??``);e.replaceWith(t);continue}let r=e.tagName===`A`?new Set([`href`]):new Set;for(let t of Array.from(e.attributes))r.has(t.name)||e.removeAttribute(t.name);if(e.tagName===`A`){let t=e.getAttribute(`href`)??``;!/^https?:\/\//i.test(t)&&!t.startsWith(`mailto:`)?e.removeAttribute(`href`):(e.setAttribute(`target`,`_blank`),e.setAttribute(`rel`,`noopener noreferrer`))}i(e)}};return i(r),r.innerHTML}function XL({field:e}){let t=JL[e.variant??`info`]??JL.info,n=e.format===`html`;return N(`div`,{className:`col-span-full`,children:g(`div`,{className:`rounded-md border-l-4 px-3 py-2.5 ${t.border} ${t.bg}`,children:[e.label&&N(`p`,{className:`text-xs font-semibold mb-0.5 ${t.text}`,children:e.label}),n?N(`div`,{className:`text-xs text-foreground-subtle leading-relaxed info-html-content`,dangerouslySetInnerHTML:{__html:YL(e.content)}}):N(`p`,{className:`text-xs text-foreground-subtle leading-relaxed whitespace-pre-line`,children:e.content})]})})}function ZL({field:e}){let t=e.value;if(!t||t.length===0)return null;let n=e.size??192,r=e.alt??e.label;return N(`div`,{className:`col-span-full`,children:g(`div`,{className:`rounded-md border border-foreground-subtle/20 px-3 py-3 bg-background-subtle/40 flex flex-col items-start gap-2`,children:[e.label&&N(`p`,{className:`text-xs font-semibold text-foreground`,children:e.label}),e.caption&&N(`p`,{className:`text-xs text-foreground-subtle leading-relaxed`,children:e.caption}),N(CL,{value:t,size:n,alt:r})]})})}var QL={ok:`bg-success`,warn:`bg-amber-500`,danger:`bg-danger`,idle:`bg-foreground-subtle/40`,unknown:`bg-foreground-subtle/40`};function $L(e){if(!Number.isFinite(e)||e<0)return`—`;if(e<1e3)return`${e}ms`;let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60),r=t%60;return r===0?`${n}m`:`${n}m ${r}s`}function eR(e){return!Number.isFinite(e)||e<=0?`—`:new Date(e).toLocaleTimeString()}function tR({kind:e,value:t}){return t==null||t===``?N(`span`,{className:`text-foreground-subtle/60`,children:`—`}):e===`monospace`?N(`span`,{className:`font-mono text-[11px]`,children:String(t)}):e===`status`?g(`span`,{className:`inline-flex items-center gap-1.5`,children:[N(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full ${QL[String(t).toLowerCase()]??QL.unknown}`}),N(`span`,{children:String(t)})]}):e===`duration`&&typeof t==`number`?N(`span`,{className:`font-mono text-[11px]`,children:$L(t)}):e===`timestamp`&&typeof t==`number`?N(`span`,{className:`font-mono text-[11px]`,children:eR(t)}):N(`span`,{children:String(t)})}function nR({field:e}){let t=e.value??[],n=e.description;return g(`div`,{className:`col-span-full`,children:[e.label&&N(`p`,{className:`text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1`,children:e.label}),n&&N(`p`,{className:`text-xs text-foreground-subtle mb-2`,children:n}),t.length===0?N(`div`,{className:`rounded-md border border-border bg-surface-subtle px-3 py-2 text-xs text-foreground-subtle`,children:e.emptyMessage??`No entries`}):N(`div`,{className:`rounded-md border border-border overflow-hidden`,children:g(`table`,{className:`w-full text-xs`,children:[N(`thead`,{className:`bg-surface-subtle border-b border-border`,children:N(`tr`,{children:e.columns.map(e=>N(`th`,{className:`px-3 py-1.5 text-left font-medium text-foreground-subtle`,style:e.width?{width:e.width}:void 0,children:e.label},e.key))})}),N(`tbody`,{className:`divide-y divide-border`,children:t.map((t,n)=>N(`tr`,{className:`hover:bg-surface-hover/40`,children:e.columns.map(e=>N(`td`,{className:`px-3 py-1.5 align-top text-foreground`,children:N(tR,{kind:e.kind,value:t[e.key]})},e.key))},n))})]})})]})}function rR({field:e,value:t,onChange:n,disabled:r,translationFn:i,onTestField:a,onAction:o}){let s=Array.isArray(t)?t:[],c=e.minRows??0,l=e.maxRows??1/0,u=(e,t,r)=>{let i=s.slice();i[e]={...i[e]??{},[t]:r},n(i)},d=e=>{s.length<=c||n(s.filter((t,n)=>n!==e))},f=()=>{if(s.length>=l)return;let t=e.defaultItem??{};n([...s,{...t}])},p=(t,n)=>e.rowTitleTemplate?e.rowTitleTemplate.replace(/\{(\w+)\}/g,(e,n)=>{let r=t[n];return r==null||r===``?`—`:String(r)}):`Row ${n+1}`,m=s.length>c,h=s.length<l;return g(`div`,{className:`col-span-full space-y-2`,children:[g(`div`,{className:`space-y-0.5`,children:[e.label&&N(`p`,{className:`text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:yR(e.label,i)}),e.description&&N(`p`,{className:`text-[11px] text-foreground-subtle`,children:yR(e.description,i)})]}),s.length===0?N(`div`,{className:`rounded-md border border-dashed border-border bg-background px-3 py-3 text-center text-[11px] text-foreground-subtle`,children:e.emptyMessage??`No entries`}):N(`div`,{className:`space-y-2`,children:s.map((t,n)=>g(`div`,{className:`rounded-md border border-border bg-background`,children:[g(`div`,{className:`flex items-center justify-between border-b border-border px-3 py-1.5`,children:[N(`span`,{className:`text-xs font-medium text-foreground`,children:p(t,n)}),g(`button`,{type:`button`,onClick:()=>d(n),disabled:r||!m,className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-30 disabled:cursor-not-allowed`,title:m?`Remove this row`:`At least ${c} row(s) required`,children:[N(Ra,{className:`h-3 w-3`}),`Remove`]})]}),N(`div`,{className:`grid grid-cols-1 @[480px]:grid-cols-2 gap-x-3 gap-y-2 p-3`,children:e.itemFields.map(s=>N(_R,{field:s,values:t,onChange:(e,t)=>u(n,e,t),disabled:r,translationFn:i,onTestField:a,allFields:e.itemFields,onAction:o},s.key))})]},n))}),g(`div`,{children:[g(`button`,{type:`button`,onClick:f,disabled:r||!h,className:`inline-flex items-center gap-1 rounded border border-border bg-surface px-3 py-1 text-[11px] font-medium text-foreground hover:border-primary/40 hover:bg-primary/5 disabled:opacity-30 disabled:cursor-not-allowed`,children:[N($a,{className:`h-3 w-3`}),e.addLabel??`Add`]}),!h&&Number.isFinite(l)&&g(`span`,{className:`ml-2 text-[10px] text-foreground-subtle`,children:[`(limit: `,l,`)`]})]})]})}function iR({field:e,disabled:t,onAction:n}){let[r,i]=k(!1),a=Cl(),o=async()=>{if(!(e.confirmMessage&&!await a({title:e.label,message:e.confirmMessage,confirmLabel:e.buttonLabel,variant:e.variant===`danger`?`danger`:`default`}))&&n){i(!0);try{await n(e.action,e.key)}finally{i(!1)}}},s={default:`border border-border text-foreground hover:bg-surface-hover`,primary:`bg-primary text-primary-foreground hover:bg-primary/90`,danger:`bg-danger text-white hover:bg-danger/90`};return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,children:N(`button`,{onClick:o,disabled:t||r,className:`inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors disabled:opacity-50 ${s[e.variant??`default`]??s.default}`,children:r?`Processing...`:e.buttonLabel})})}function aR(e,t){let n={...e.paramsStatic};if(e.paramsFromForm)for(let[r,i]of Object.entries(e.paramsFromForm)){let e=t[i];e!=null&&e!==``&&(n[r]=e)}return n}function oR({field:e,value:t,values:n,onChange:r,disabled:i,onAction:a}){let[o,s]=k(!1),[c,l]=k(null),[u,d]=k(null),f=aR(e,n),p=Object.keys(e.paramsFromForm??{}).some(e=>f[e]===void 0);P(()=>{if(!a||p){d(null),l(null);return}let t=!1;return s(!0),l(null),a(e.action,e.key,f).then(e=>{if(t)return;let n=e,r=[];if(Array.isArray(n))r=n;else if(n&&typeof n==`object`)for(let e of Object.keys(n)){let t=n[e];if(Array.isArray(t)){r=t;break}}d(r)}).catch(e=>{t||(l(e instanceof Error?e.message:String(e)),d([]))}).finally(()=>{t||s(!1)}),()=>{t=!0}},[(e.refreshOn??Object.values(e.paramsFromForm??{})).map(e=>`${e}=${JSON.stringify(n[e])}`).join(`|`),a,e.action,e.key]);let m=e.mapOption.value,h=e.mapOption.label,_=e.mapOption.description;return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,children:p?N(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e.emptyParamsMessage??`Fill the prerequisite fields above first.`}):o?g(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[N(Ea,{className:`h-3 w-3 animate-spin`}),` Loading options…`]}):c?N(`div`,{className:`text-[11px] text-danger`,children:c}):u&&u.length===0?N(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e.emptyResultsMessage??`No options returned.`}):(()=>{let e=(u??[]).some(e=>{let t=e[m];return t===``||t===void 0});return g(`select`,{className:`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-xs text-foreground`,value:typeof t==`string`?t:``,disabled:i,onChange:e=>r(e.target.value),children:[!e&&N(`option`,{value:``,children:`— Select —`}),(u??[]).map((e,t)=>{let n=e[m],r=e[h],i=_?e[_]:void 0,a=typeof n==`string`&&n!==``?n:`row-${t}`;return g(`option`,{value:typeof n==`string`?n:String(n??``),children:[typeof r==`string`?r:String(r??a),i===void 0?``:` (${String(i)})`]},a)})]})})()})}function sR({field:e,values:t,disabled:n,onAction:r}){let[i,a]=k(!1),[o,s]=k(null),c=Cl(),l=async()=>{if(e.confirmMessage&&!await c({title:e.label,message:e.confirmMessage,confirmLabel:e.buttonLabel,variant:e.variant===`danger`?`danger`:`default`})||!r)return;let n=aR(e,t);a(!0),s(null);try{let t=await r(e.action,e.key,n),i=typeof t==`object`&&t?t:null;s({kind:`ok`,text:e.successMessage?e.successMessage.replace(/\{(\w+)\}/g,(e,t)=>{let n=i?.[t];return n===void 0?``:String(n)}):`Done.`})}catch(e){s({kind:`error`,text:e instanceof Error?e.message:String(e)})}finally{a(!1)}},u={default:`border border-border text-foreground hover:bg-surface-hover`,primary:`bg-primary text-primary-foreground hover:bg-primary/90`,danger:`bg-danger text-white hover:bg-danger/90`};return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,children:g(`div`,{className:`flex flex-col gap-1.5`,children:[N(`button`,{onClick:l,disabled:n||i,className:`inline-flex w-fit items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors disabled:opacity-50 ${u[e.variant??`default`]??u.default}`,children:i?`Working…`:e.buttonLabel}),o&&N(`div`,{className:`text-[11px] ${o.kind===`ok`?`text-emerald-700 dark:text-emerald-300`:`text-danger`}`,children:o.text})]})})}function cR({field:e,values:t,disabled:n,onAction:r}){let[i,a]=k(!1),[o,s]=k(null),c=Cl(),l=async()=>{if(e.confirmMessage&&!await c({title:e.label,message:e.confirmMessage,confirmLabel:e.buttonLabel,variant:e.variant===`danger`?`danger`:`default`})||!r)return;let n=aR(e,t);a(!0),s(null);try{let t=await r(`device-custom-action`,e.action,n),i=typeof t==`object`&&t?t:null;s({kind:`ok`,text:e.successMessage?e.successMessage.replace(/\{(\w+)\}/g,(e,t)=>{let n=i?.[t];return n===void 0?``:String(n)}):`Done.`})}catch(e){s({kind:`error`,text:e instanceof Error?e.message:String(e)})}finally{a(!1)}},u={default:`border border-border text-foreground hover:bg-surface-hover`,primary:`bg-primary text-primary-foreground hover:bg-primary/90`,danger:`bg-danger text-white hover:bg-danger/90`};return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,children:g(`div`,{className:`flex flex-col gap-1.5`,children:[N(`button`,{onClick:l,disabled:n||i,className:`inline-flex w-fit items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors disabled:opacity-50 ${u[e.variant??`default`]??u.default}`,children:i?`Working…`:e.buttonLabel}),o&&N(`div`,{className:`text-[11px] ${o.kind===`ok`?`text-emerald-700 dark:text-emerald-300`:`text-danger`}`,children:o.text})]})})}function lR({field:e}){let t=iF();return N(kL,{label:void 0,description:void 0,span:e.span,children:N(WI,{widgetId:e.widgetId,host:`device-tab`,config:e.widgetConfig,deviceId:t??void 0,instanceId:e.key})})}function uR(e,t){if(e==null)return`—`;if(typeof e==`boolean`)return e?`yes`:`no`;if(typeof e==`number`){let n=Number.isInteger(e)?String(e):e.toFixed(2);return t?`${n} ${t}`:n}return typeof e==`string`?e:JSON.stringify(e)}function dR({field:e,values:t,onAction:n,translationFn:r}){let i=`key`in e?e.key:void 0;if(!i)return null;let a=t[i],o=a===void 0?`default`in e?e.default:void 0:a,s=uR(o,`unit`in e?e.unit:void 0),c=`label`in e?e.label:void 0,l=`description`in e?e.description:void 0,u=`span`in e?e.span:void 0,d=`actions`in e?e.actions??[]:[];return N(kL,{label:c,description:l,span:u,translationFn:r,children:g(`div`,{className:`flex items-stretch gap-1`,children:[N(`div`,{className:`flex-1 rounded-md border border-border bg-surface-alt px-2.5 py-1.5 text-xs text-foreground font-mono break-all`,children:s}),d.length>0&&N(`div`,{className:`flex items-center gap-1`,children:d.map(e=>N(pR,{action:e,fieldKey:i,value:o,onAction:n},e.action))})]})})}function fR({name:e}){let t=`h-3.5 w-3.5`;switch(e){case`copy`:return N(Wi,{className:t});case`refresh-cw`:return N(oo,{className:t});case`external-link`:return N(ea,{className:t});case`trash-2`:return N(Bo,{className:t});case`download`:return N(Xi,{className:t});case`upload`:return N(Ko,{className:t});default:return N(ns,{className:t})}}function pR({action:e,fieldKey:t,value:n,onAction:r}){let i=Cl(),[a,o]=k(!1),s=e.variant===`danger`?`text-danger hover:bg-danger/10 border-danger/30`:e.variant===`primary`?`text-primary hover:bg-primary/10 border-primary/30`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover border-border`;return N(`button`,{type:`button`,onClick:async()=>{if(!(e.confirmMessage&&!await i({title:e.tooltip,message:e.confirmMessage,variant:e.variant===`danger`?`danger`:`default`}))){if(e.action===`copy-value`){try{await navigator.clipboard.writeText(typeof n==`string`?n:String(n))}catch{}return}if(r){o(!0);try{await r(e.action,t)}finally{o(!1)}}}},disabled:a,title:e.tooltip,className:`inline-flex items-center justify-center rounded-md border px-2 py-1.5 transition-colors disabled:opacity-50 ${s}`,children:N(fR,{name:e.icon})})}function mR(e){return`multiple`in e&&e.multiple!=null}function hR({field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,externalProbe:o,allFields:s,onAction:c}){let l=e.multiple,u=l.min,d=l.max,f=t[e.key],p=[...Array.isArray(f)?f:f==null?[]:[f]],m=l.itemDefault===void 0?`default`in e&&e.default!==void 0?e.default:``:l.itemDefault;for(;p.length<u;)p.push(m);let h=t=>n(e.key,[...t]),_=(e,t)=>{let n=[...p];n[e]=t,h(n)},v=()=>{p.length>=d||h([...p,m])},y=e=>{p.length<=u||h(p.filter((t,n)=>n!==e))},b=()=>{let{multiple:t,...n}=e,r={label:void 0,description:void 0,required:!1};return{...n,...r}};return N(kL,{label:e.label,description:e.description,required:u>0?e.required:!1,span:e.span,translationFn:i,children:g(`div`,{className:`space-y-2`,children:[p.map((n,o)=>{let d=l.itemLabel?.replace("${n}",String(o+1));return g(`div`,{className:`space-y-1`,children:[d&&N(`div`,{className:DL,children:d}),g(`div`,{className:`flex items-center gap-2`,children:[N(`div`,{className:`flex-1 min-w-0`,children:N(_R,{field:b(),values:{...t,[e.key]:n},onChange:(e,t)=>_(o,t),disabled:r,translationFn:i,onTestField:a,onAction:c,allFields:s})}),p.length>u&&N(`button`,{type:`button`,onClick:()=>y(o),disabled:r,title:`Remove`,className:`flex-shrink-0 inline-flex items-center justify-center rounded-md border border-border p-1.5 text-foreground-subtle hover:text-danger hover:border-danger/50 transition-colors disabled:opacity-40`,children:N(Bo,{className:`h-3.5 w-3.5`})})]})]},o)}),g(`div`,{className:`flex items-center justify-between pt-1`,children:[p.length<d?g(`button`,{type:`button`,onClick:v,disabled:r,className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40`,children:[N($a,{className:`h-3 w-3`}),l.addLabel??`Add`]}):N(`span`,{}),g(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[p.length,`/`,d]})]})]})})}function gR(e,t,n){if(!(`showWhen`in e)||!e.showWhen)return!0;let r=e.showWhen,i=t[r.field],a=n?.find(e=>`key`in e&&e.key===r.field),o=a&&`default`in a?a.default:void 0,s=i===void 0?o:i;return r.equals===void 0?r.notEquals===void 0?r.in===void 0?r.notIn===void 0?r.includes===void 0?r.notIncludes===void 0?!0:!Array.isArray(s)||!s.includes(r.notIncludes):Array.isArray(s)&&s.includes(r.includes):!r.notIn.includes(s):r.in.includes(s):s!==r.notEquals:s===r.equals}function _R({field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,externalProbe:o,allFields:s,onAction:c}){if(mR(e))return N(hR,{field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,externalProbe:o,allFields:s,onAction:c});if(`readonlyField`in e&&e.readonlyField===!0)return N(dR,{field:e,values:t,onAction:c,translationFn:i});if(!gR(e,t,s))return null;let l=t[e.key],u=l===void 0?`default`in e?e.default:void 0:l,d=t=>n(e.key,t),f=tF(e.type);switch(e.type){case`text`:return N(AL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`number`:return N(jL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`boolean`:return N(ML,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`select`:return N(NL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`multiselect`:return N(IL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`timezone`:return N(PL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`datetime`:return N(FL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`password`:return N(LL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`textarea`:return N(RL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`slider`:return N(zL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`tags`:return N(BL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`color`:return N(UL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`node-select`:return N(VL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`node-multiselect`:return N(HL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`probe`:return N(WL,{field:e,value:u,onChange:d,disabled:r,translationFn:i,onTestField:a,onAction:c,externalProbe:o});case`group`:return N(GL,{field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a});case`sub-tabs`:return N(KL,{field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,onAction:c});case`separator`:return N(qL,{});case`info`:return N(XL,{field:e});case`qr-code`:return N(ZL,{field:e});case`object-array`:return N(nR,{field:e});case`editable-array`:return N(rR,{field:e,value:u,onChange:d,disabled:r,translationFn:i,onTestField:a,onAction:c});case`button`:return N(iR,{field:e,disabled:r,onAction:c});case`addon-action-select`:return N(oR,{field:e,value:u,values:t,onChange:d,disabled:r,onAction:c});case`addon-action-button`:return N(sR,{field:e,values:t,disabled:r,onAction:c});case`device-action-button`:return N(cR,{field:e,values:t,disabled:r,onAction:c});case`widget`:return N(lR,{field:e});default:return f?N(f,{field:e,value:u,onChange:d,disabled:r}):null}}h();function vR(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function yR(e,t){if(e!==void 0)return t&&vR(e)?t(e):e}function bR({section:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,probeResults:o}){let[s,c]=k(e.defaultCollapsed??!1),l=e.style===`accordion`,u=e.columns??2,d=u===1?`grid-cols-1`:u===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:u===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`;return g(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},children:[g(`div`,{className:[`flex items-center justify-between mb-2`,l?`cursor-pointer`:``].join(` `),onClick:l?()=>c(e=>!e):void 0,children:[g(`div`,{children:[N(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:yR(e.title,i)}),e.description&&N(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:yR(e.description,i)})]}),l&&N(`span`,{className:`text-foreground-subtle text-xs ml-2`,children:s?`▸`:`▾`})]}),!s&&N(`div`,{className:`grid ${d} gap-x-3 gap-y-2.5`,children:e.fields.map(e=>N(_R,{field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,externalProbe:o?.[e.key]},e.key))})]})}function xR({schema:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,probeResults:o,onClearProbe:s}){let c=(e,r)=>{n({...t,[e]:r}),s?.(e)};return N(`div`,{className:`space-y-4`,children:e.sections.map(e=>N(bR,{section:e,values:t,onChange:c,disabled:r,translationFn:i,onTestField:a,probeResults:o},e.id))})}h();var SR=({open:e})=>N(`svg`,{className:`h-3 w-3 transition-transform ${e?`rotate-90`:``}`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,children:N(`polyline`,{points:`9 18 15 12 9 6`})});function CR(e){let t={};if(!e)return t;for(let n of e.sections)for(let e of n.fields){if(e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`group`)continue;let n=e.key;t[n]=e.value}return t}function wR(e){return{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`group`)return e;let{value:t,...n}=e;return n})}))}}function TR({trpc:e,addonId:t,nodeId:n,title:r,disabled:i,onAfterChange:a,refreshToken:o,collapsible:s,defaultOpen:c,mode:l,onOverrideChange:u}){let d=l??`persist`,[f,p]=k(null),[m,h]=k(!0),[_,v]=k(null),[y,x]=k(!1),[S,C]=k(c??!1),[T,E]=k({}),[D,O]=k(null);P(()=>{O(null),E({})},[e,t,n,o,d]),P(()=>{let r=!1;h(!0),v(null);let i=d===`override`&&Object.keys(T).length>0?T:void 0;return e.addonSettings.getGlobalSettings.query({addonId:t,nodeId:n,...i?{overlay:i}:{}}).then(e=>{r||(p(t=>e??t),!i&&e&&O(CR(e)),h(!1))}).catch(e=>{r||(v(e instanceof Error?e.message:String(e)),h(!1))}),()=>{r=!0}},[e,t,n,o,d,JSON.stringify(T)]);let A=b(()=>CR(f),[f]),j=b(()=>f?wR(f):null,[f]),M=async r=>{if(d===`override`){let e=D??A,t={};for(let n of Object.keys(r))r[n]!==e[n]&&(t[n]=r[n]);let n={...e,...t};E(t),u?.(t,n);return}let i={};for(let e of Object.keys(r))r[e]!==A[e]&&(i[e]=r[e]);if(Object.keys(i).length!==0){x(!0);try{await e.addonSettings.updateGlobalSettings.mutate({addonId:t,nodeId:n,patch:i});let r=await e.addonSettings.getGlobalSettings.query({addonId:t,nodeId:n});r&&p(r),a?.()}catch(e){v(e instanceof Error?e.message:String(e))}finally{x(!1)}}};if(m)return g(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:[`Loading `,r??t,`…`]});if(_)return g(`div`,{className:`text-xs text-red-400`,children:[r??t,`: `,_]});if(!f||!j)return g(`div`,{className:`text-xs text-foreground-subtle`,children:[r??t,` not available on `,n,`.`]});let F=d===`override`?{...A,...T}:A,I=g(w,{children:[d===`override`?N(`div`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:`Benchmark override — applies to this run only. The addon's saved settings are not changed.`}):null,N(xR,{schema:j,values:F,onChange:M,disabled:i===!0||y})]});return s===!0?g(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[g(`button`,{type:`button`,onClick:()=>C(e=>!e),className:`w-full px-4 py-2 flex items-center gap-2 hover:bg-surface-hover text-left`,"aria-expanded":S,children:[N(SR,{open:S}),N(`h3`,{className:`text-xs font-semibold text-foreground uppercase tracking-wide flex-1`,children:r??t}),N(`span`,{className:`text-[10px] text-foreground-subtle`,children:S?`hide`:`edit`})]}),S?N(`div`,{className:`border-t border-border px-4 py-3`,children:I}):null]}):r?g(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[N(`div`,{className:`border-b border-border px-4 py-2`,children:N(`h3`,{className:`text-xs font-semibold text-foreground uppercase tracking-wide`,children:r})}),N(`div`,{className:`px-4 py-3`,children:I})]}):N(`div`,{children:I})}function ER({detections:{motion:e,motionRaw:t,detection:n,phase:r},showMotionZones:i=!0,showMotionRaw:a=!0,showDetections:o=!0,showPhaseIndicator:s=!0}){let c=i&&e&&e.zones.length>0,l=a&&t&&t.boxes.length>0,u=o&&n&&n.detections.length>0;return!c&&!l&&!u&&!s?null:g(`div`,{className:`absolute inset-0 pointer-events-none z-10`,children:[s&&N(DR,{phase:r}),l&&N(OR,{raw:t}),c&&N(kR,{motion:e}),u&&N(AR,{detections:n.detections,frameWidth:n.frameWidth,frameHeight:n.frameHeight})]})}function DR({phase:e}){let t=Ar(e);return g(`div`,{className:`absolute top-2 left-2 flex items-center gap-1.5 px-2 py-1 rounded-md bg-black/60 backdrop-blur-sm`,children:[N(`span`,{className:`w-2 h-2 rounded-full ${t.dotClass}`}),N(`span`,{className:`text-[10px] font-semibold text-white uppercase tracking-wider`,children:t.label})]})}function OR({raw:e}){return e.frameWidth===0||e.frameHeight===0?null:N(w,{children:e.boxes.map((t,n)=>{let[r,i,a,o]=t.bbox,s=r/e.frameWidth*100,c=i/e.frameHeight*100,l=(a-r)/e.frameWidth*100,u=(o-i)/e.frameHeight*100,d=Math.max(.05,Math.min(.25,t.changeScore*.3));return N(`div`,{className:`absolute rounded-sm`,style:{left:`${s}%`,top:`${c}%`,width:`${l}%`,height:`${u}%`,backgroundColor:`rgba(239, 68, 68, ${d})`}},`mr-${n}`)})})}function kR({motion:e}){return e.frameWidth===0||e.frameHeight===0?null:N(w,{children:e.zones.filter(t=>t.w*t.h/(e.frameWidth*e.frameHeight)<.9).map((t,n)=>{let r=Math.max(.15,Math.min(.5,t.intensity/255));return N(`div`,{className:`absolute rounded-sm`,style:{left:`${t.x/e.frameWidth*100}%`,top:`${t.y/e.frameHeight*100}%`,width:`${t.w/e.frameWidth*100}%`,height:`${t.h/e.frameHeight*100}%`,border:`1px solid rgba(250, 204, 21, ${r})`,backgroundColor:`rgba(250, 204, 21, ${r*.15})`}},`mz-${n}`)})})}function AR({detections:e,frameWidth:t,frameHeight:n}){return t===0||n===0?null:N(w,{children:e.map(e=>{let{x:r,y:i,width:a,height:o}=e.bbox,s=r/t*100,c=i/n*100,l=a/t*100,u=o/n*100,d=vM(e.macroClass),f=[`${e.macroClass} ${(e.score*100).toFixed(0)}%`];for(let t of e.labels)f.push(t.label);return N(`div`,{className:`absolute border-2 rounded-sm`,style:{left:`${s}%`,top:`${c}%`,width:`${l}%`,height:`${u}%`,borderColor:d},children:N(`div`,{className:`absolute -top-4 left-0 px-1 py-0.5 text-[9px] font-bold text-white rounded-sm whitespace-nowrap`,style:{backgroundColor:d},children:f.join(` | `)})},`det-${e.id}`)})})}h();function jR(){return typeof window>`u`?!1:window.matchMedia(`(hover: none) and (pointer: coarse)`).matches||typeof navigator<`u`&&navigator.maxTouchPoints>0||`ontouchstart`in window}function MR(e,t,n){let r=0;for(let i=0;i<8;i++)for(let a=0;a<8;a++){let o=Math.min(t-1,Math.floor((a+.5)/8*t)),s=Math.min(n-1,Math.floor((i+.5)/8*n)),{data:c}=e.getImageData(o,s,1,1);.2126*(c[0]??0)+.7152*(c[1]??0)+.0722*(c[2]??0)>12&&r++}return r<=1}function NR(e){let t={};if(typeof window<`u`){if(e){let n=e.getBoundingClientRect();n.width>0&&n.height>0&&(t.viewportWidth=Math.round(n.width),t.viewportHeight=Math.round(n.height))}t.viewportWidth===void 0&&(t.viewportWidth=window.innerWidth,t.viewportHeight=window.innerHeight),t.devicePixelRatio=window.devicePixelRatio||1;let n=navigator.connection;n?.downlink&&n.downlink>0&&(t.downlinkMbps=n.downlink)}return t}var PR=1500,FR=15e3,IR=40;function LR({serverUrl:e,streamKey:t,label:n,autoPlay:r=!0,muted:i=!0,showControls:a=!0,showStats:o=!1,onPlaybackStats:s,className:c=``,onStateChange:l,onError:d,overlay:p,createSession:m,sendAnswer:h,handleOffer:_,getIceServers:v,addIceCandidate:y,getIceCandidates:b,closeSession:x,getSessionState:S,reoffer:C,posterUrl:w,hintsOverride:T,reconnectSignal:E,onControlChannel:D}){let O=f(null),A=f(null),j=f(null),M=f(new Set),F=f(null),I=f(null),L=f(0),R=f(!0),ee=f(D);ee.current=D;let z=f(null),B=f(null),V=f(0),te=f(!1),H=f(async()=>{}),[U,ne]=k(`idle`),[re,ie]=k(``),[ae,oe]=k(i),[se,W]=k(!1),[ce,le]=k(!1),ue=jR(),[de,fe]=k(!0),pe=f(null),G=f(!1);(h||m)&&(G.current=!0);let me=G.current,he=f(!1);_&&(he.current=!0);let ge=he.current,[_e,ve]=k(!1),ye=f(null),[be,xe]=k(null),[Se,Ce]=k(!1),we=u(()=>{let e=O.current;if(!(!e||e.readyState<2||!e.videoWidth||!e.videoHeight))try{let t=document.createElement(`canvas`);t.width=e.videoWidth,t.height=e.videoHeight;let n=t.getContext(`2d`);if(!n||(n.drawImage(e,0,0),MR(n,t.width,t.height)))return;ye.current=t.toDataURL(`image/jpeg`,.6)}catch{}},[]),Te=u(e=>{ne(e),e===`playing`&&ve(!0),l?.(e)},[l]),Ee=u(()=>{if(F.current?.abort(),F.current=null,I.current&&=(clearTimeout(I.current),null),B.current&&=(clearTimeout(B.current),null),z.current=null,te.current=!1,V.current=0,j.current&&=(j.current.close(),null),x&&M.current.size>0){for(let e of M.current)x(e).catch(()=>{});M.current.clear()}},[x]),De=u(()=>{F.current?.abort(),F.current=null,I.current&&=(clearTimeout(I.current),null),B.current&&=(clearTimeout(B.current),null),z.current=null,te.current=!1,V.current=0},[]),Oe=1e3,ke=u(e=>{if(!S||!C)return;B.current&&=(clearTimeout(B.current),null);let t=async()=>{if(R.current&&z.current===e){if(!te.current)try{let{pendingRenegotiation:t}=await S(e);if(R.current&&z.current===e&&t&&t.epoch>V.current&&!te.current){V.current=t.epoch,await H.current(e,t.target);return}}catch{}!R.current||z.current!==e||(B.current=setTimeout(()=>{t()},Oe))}};B.current=setTimeout(()=>{t()},Oe)},[S,C]),Ae=u(async(e=!1)=>{if(!R.current||!m||!h)return;let t=e?j.current:null,n=e?new Set(M.current):null;e?De():Ee(),Te(`connecting`);let r=new AbortController;F.current=r;try{let{sessionId:i,sdpOffer:a,iceServers:o}=await m({...NR(A.current),...T});if(M.current.add(i),!R.current||r.signal.aborted){x?.(i).catch(()=>{}),M.current.delete(i);return}let s=new RTCPeerConnection({iceServers:[...o??[],{urls:`stun:stun.l.google.com:19302`}]});e||(j.current=s);let c=new MediaStream,l=!1,u=()=>{if(!(l||!R.current)){if(l=!0,j.current=s,O.current&&(O.current.srcObject=c,O.current.play().catch(()=>{})),t&&t!==s)try{t.close()}catch{}if(n)for(let e of n)M.current.delete(e),x?.(e).catch(()=>{})}};s.ontrack=t=>{if(console.debug(`[WebRTC] ontrack`,t.track.kind,t.track.readyState),c.addTrack(t.track),e){u();return}O.current&&(O.current.srcObject=c,O.current.play().catch(()=>{}))},s.oniceconnectionstatechange=()=>{if(!R.current)return;let t=s.iceConnectionState;if(console.debug(`[WebRTC] ICE state:`,t),t===`connected`||t===`completed`)L.current=0,e&&u(),Te(`playing`),O.current?.paused&&(console.debug(`[WebRTC] video was paused at ICE connected — calling play()`),O.current.play().catch(()=>{}));else if(t===`failed`||t===`disconnected`||t===`closed`){if(e&&!l)try{s.close()}catch{}Te(`disconnected`),Fe()}},s.onicecandidateerror=e=>{console.debug(`[WebRTC] ICE candidate error:`,e)},console.debug(`[WebRTC] Setting remote description (server offer)...`),await s.setRemoteDescription({type:`offer`,sdp:a});let d=await s.createAnswer();if(await s.setLocalDescription(d),console.debug(`[WebRTC] Local description set, waiting for ICE gathering...`),await zR(s),!R.current)return;let f=(s.localDescription?.sdp??``).split(`
64
+ `;function tD({trpc:e,deviceId:t,layout:n,optimistic:r}){let{cap:i,slice:a,available:o}=Q({trpc:e,deviceId:t,cap:e=>e.climateControl,slice:e=>e.state.climateControl}),{display:s,applyOptimistic:c}=vu(a,{enabled:r??!0});if(i===void 0||s===void 0)return null;let l=!o;if(n===`compact`)return g(`div`,{"data-mode":s.mode,className:`inline-flex items-center gap-1`,children:[N(`span`,{className:X(`text-xs tabular-nums font-medium`,UE[s.mode]),children:s.target===null?s.currentTemp===null?null:g(`span`,{className:`text-foreground-subtle`,children:[s.currentTemp,`°`]}):g(w,{children:[s.target,`°`,s.currentTemp!==null&&g(`span`,{className:`text-foreground-subtle font-normal`,children:[` `,`(`,s.currentTemp,`°)`]})]})}),s.target!==null&&g(w,{children:[N(`button`,{type:`button`,"aria-label":`Decrease target`,disabled:l,onClick:e=>{if(e.stopPropagation(),!l&&s.target!==null){let e=s.target-1;c({target:e}),i.setTarget({target:e})}},className:X(`inline-flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors text-xs`,l&&`opacity-40 cursor-not-allowed`),children:`−`}),N(`button`,{type:`button`,"aria-label":`Increase target`,disabled:l,onClick:e=>{if(e.stopPropagation(),!l&&s.target!==null){let e=s.target+1;c({target:e}),i.setTarget({target:e})}},className:X(`inline-flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors text-xs`,l&&`opacity-40 cursor-not-allowed`),children:`+`})]}),N(`select`,{"aria-label":`Mode`,value:s.mode,disabled:l,onChange:e=>{e.stopPropagation();let t=s.availableModes.find(t=>t===e.target.value);!l&&t&&(c({mode:t}),i.setMode({mode:t}))},className:X(`bg-transparent px-0.5 text-xs text-foreground-subtle hover:text-foreground cursor-pointer`,l&&`opacity-40 cursor-not-allowed`),children:s.availableModes.map(e=>N(`option`,{value:e,children:KE[e]},e))})]});let u=JE[s.mode],d=s.mode!==`off`,f=QE(s.preset),p=s.preset===`turbo`,m=Math.max(.55,$E(s.fanMode)*(p?.6:1)),h=s.swingVertical!==null,_=s.swingHorizontal!==null,v=d&&(s.swingVertical===!0||s.swingHorizontal===!0);return g(`div`,{"data-mode":s.mode,className:X(`relative flex flex-col items-stretch gap-2.5 overflow-hidden rounded-lg border p-3 transition-colors`,HE[s.mode]),children:[N(`style`,{children:eD}),g(`div`,{className:`relative z-10 flex flex-col items-center justify-center gap-1 overflow-hidden rounded-lg border border-border/50 bg-surface/30 px-3 py-3`,children:[N(`div`,{className:`pointer-events-none absolute inset-0 opacity-60`,children:N(sD,{mode:s.mode,accent:u,periodSec:m,swaying:v})}),N(`div`,{className:`pointer-events-none absolute inset-0 bg-gradient-to-b from-surface/50 via-transparent to-surface/50`}),d&&N(`span`,{"aria-hidden":!0,className:`acv-glow pointer-events-none absolute left-1/2 top-1/2 h-16 w-16 -translate-x-1/2 -translate-y-1/2 rounded-full blur-2xl`,style:{background:u,animation:`acv-glow 3.2s ease-in-out infinite`}}),g(`div`,{className:`relative z-10 flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-wide`,style:{color:u},children:[N(rD,{mode:s.mode,className:`h-3.5 w-3.5`}),KE[s.mode],s.currentTemp!==null&&g(`span`,{className:`normal-case text-foreground-subtle`,children:[`· `,s.currentTemp,`° now`]}),s.currentHumidity!==null&&g(`span`,{className:`inline-flex items-center gap-0.5 normal-case text-foreground-subtle`,children:[N(Qi,{className:`h-3 w-3`}),s.currentHumidity,`%`]})]}),s.target===null?g(`div`,{className:`relative z-10 flex items-baseline gap-0.5`,children:[N(`span`,{className:`text-4xl font-bold leading-none tabular-nums text-foreground`,children:s.currentTemp??`—`}),N(`span`,{className:`text-lg text-foreground-subtle`,children:`°`})]}):g(w,{children:[g(`div`,{className:`relative z-10 flex items-center gap-3`,children:[N(aD,{label:`Decrease target`,symbol:`−`,disabled:l,onClick:()=>{if(l||s.target===null)return;let e=s.target-1;c({target:e}),i.setTarget({target:e})}}),g(`div`,{className:`flex items-baseline gap-0.5`,children:[N(`span`,{className:`text-4xl font-bold leading-none tabular-nums`,style:{color:u},children:s.target}),N(`span`,{className:`text-lg text-foreground-subtle`,children:`°`})]}),N(aD,{label:`Increase target`,symbol:`+`,disabled:l,onClick:()=>{if(l||s.target===null)return;let e=s.target+1;c({target:e}),i.setTarget({target:e})}})]}),N(`div`,{className:`relative z-10 w-36`,children:N(oD,{value:s.target,min:YE,max:XE,accent:u})})]})]}),g(`div`,{className:`relative z-10 grid grid-cols-3 gap-2`,children:[N(iD,{label:`Mode`,icon:N(`span`,{style:{color:u},className:`flex`,children:N(rD,{mode:s.mode,className:`h-4 w-4`})}),value:s.mode,options:s.availableModes.map(e=>({value:e,label:KE[e]})),disabled:l,onChange:e=>{let t=s.availableModes.find(t=>t===e);t&&(c({mode:t}),i.setMode({mode:t}))}}),s.availableFanModes.length>0&&N(iD,{label:`Fan`,icon:N(es,{className:`h-4 w-4 text-sky-500`}),value:s.fanMode,options:s.availableFanModes.map(e=>({value:e,label:ZE(e)})),disabled:l,onChange:e=>{c({fanMode:e}),i.setFanMode({fanMode:e})}}),s.availablePresets.length>0&&N(iD,{label:`Preset`,icon:N(f,{className:`h-4 w-4 text-emerald-500`}),value:s.preset,options:s.availablePresets.map(e=>({value:e,label:ZE(e)})),disabled:l,onChange:e=>{c({preset:e}),i.setPreset({preset:e})}})]}),(h||_)&&N(nD,{label:`Swing`,children:g(`div`,{className:`grid grid-cols-2 gap-1`,children:[h&&N(lD,{axis:`vertical`,on:s.swingVertical??!1,busy:l,onToggle:e=>{c({swingVertical:e}),i.setSwingVertical({on:e})}}),_&&N(lD,{axis:`horizontal`,on:s.swingHorizontal??!1,busy:l,onToggle:e=>{c({swingHorizontal:e}),i.setSwingHorizontal({on:e})}})]})})]})}function nD({label:e,children:t}){return g(`div`,{className:`relative z-10 flex flex-col gap-1`,children:[N(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:e}),t]})}function rD({mode:e,className:t}){let n=qE[e];return N(n,{className:t,"aria-hidden":!0})}function iD({label:e,icon:t,value:n,options:r,disabled:i,onChange:a}){return g(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[N(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:e}),g(`div`,{className:X(`flex items-center gap-1 overflow-hidden rounded-lg border border-border/60 bg-surface-subtle px-1.5 py-1.5`,i&&`opacity-40`),children:[N(`span`,{className:`flex shrink-0`,children:t}),N(`select`,{"aria-label":e,value:n,disabled:i,onChange:e=>{e.stopPropagation(),i||a(e.target.value)},className:`min-w-0 flex-1 cursor-pointer appearance-none truncate bg-transparent text-xs font-medium text-foreground outline-none`,children:r.map(e=>N(`option`,{value:e.value,children:e.label},e.value))}),N(Re,{className:`h-3 w-3 shrink-0 text-foreground-subtle`})]})]})}function aD({label:e,symbol:t,disabled:n,onClick:r}){return N(`button`,{type:`button`,"aria-label":e,disabled:n,onClick:r,className:X(`flex h-8 w-8 shrink-0 items-center justify-center rounded-full border border-border bg-surface text-lg leading-none text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground active:scale-95`,n&&`opacity-40 cursor-not-allowed`),children:t})}function oD({value:e,min:t,max:n,accent:r}){let i=`${Math.min(1,Math.max(0,(e-t)/(n-t)))*100}%`;return g(`div`,{className:`mt-2 w-full`,children:[g(`div`,{className:`relative h-1.5 w-full rounded-full bg-surface-subtle`,children:[N(`div`,{className:`absolute inset-y-0 left-0 rounded-full`,style:{width:i,background:r}}),N(`div`,{className:`absolute top-1/2 h-3 w-3 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-surface shadow`,style:{left:i,background:r}})]}),g(`div`,{className:`mt-0.5 flex justify-between text-[9px] tabular-nums text-foreground-subtle`,children:[g(`span`,{children:[t,`°`]}),g(`span`,{children:[n,`°`]})]})]})}function sD({mode:e,accent:t,periodSec:n,swaying:r}){let i=[0,1,2,3,4,5],a=e===`heat`,o=e===`dry`;return N(`div`,{"aria-hidden":!0,className:`absolute inset-0 overflow-hidden`,children:e===`off`?N(`div`,{className:`flex h-full items-center justify-center gap-2 opacity-30`,children:i.map(e=>N(`span`,{className:`h-8 w-1 rounded-full bg-foreground-subtle opacity-40`},e))}):e===`fan_only`?N(`div`,{className:`flex h-full items-center justify-center`,children:N(cD,{color:t,periodSec:Math.max(.5,n*.7),size:56})}):N(`div`,{className:X(`acv-sway-wrap absolute inset-0`,r&&`acv-sway`),style:r?{animation:`acv-sway 2.6s ease-in-out infinite`}:void 0,children:i.map(e=>N(`span`,{className:`acv-streak absolute rounded-full`,style:{left:`${8+e*15}%`,width:o?`0.4rem`:`0.3rem`,height:o?`0.4rem`:`1.9rem`,background:t,boxShadow:`0 0 6px ${t}`,animationName:a?`acv-rise`:`acv-fall`,animationTimingFunction:`linear`,animationIterationCount:`infinite`,animationDuration:`${n}s`,animationDelay:`${e%3*(n/3)+e*.05}s`}},e))})})}function cD({color:e,periodSec:t,size:n}){return g(`svg`,{width:n,height:n,viewBox:`0 0 100 100`,className:`acv-fan`,style:{animation:`acv-spin ${t}s linear infinite`,transformOrigin:`50% 50%`},"aria-hidden":!0,children:[[0,120,240].map(t=>N(`path`,{d:`M50 50 C 58 30, 78 26, 84 12 C 66 20, 54 34, 50 50 Z`,fill:e,opacity:.85,transform:`rotate(${t} 50 50)`},t)),N(`circle`,{cx:`50`,cy:`50`,r:`7`,fill:e})]})}function lD({axis:e,on:t,busy:n,onToggle:r}){let i=e===`vertical`?`Vertical`:`Horizontal`,a=e===`vertical`?Ua:Ha,o=e===`vertical`?`acv-swing-v`:`acv-swing-h`;return g(`button`,{type:`button`,"aria-label":`${i} swing`,"aria-pressed":t,disabled:n,onClick:()=>{n||r(!t)},className:X(`flex items-center justify-center gap-2 rounded-lg border px-2 py-1.5 text-xs font-medium transition-colors`,t?`border-transparent bg-indigo-400 text-indigo-950 shadow-sm`:`border-border/60 bg-surface-subtle text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,n&&`opacity-40 cursor-not-allowed`),children:[N(a,{className:`acv-swing h-4 w-4`,"aria-hidden":!0,style:t?{animation:`${o} 1.4s ease-in-out infinite`}:void 0}),i]})}var uD={playing:`border-green-400 bg-green-50 dark:bg-green-950`,paused:`border-amber-400 bg-amber-50 dark:bg-amber-950`,buffering:`border-blue-400 bg-blue-50 dark:bg-blue-950`,on:`border-slate-400 bg-slate-50 dark:bg-slate-950`,idle:`border-slate-400 bg-slate-50 dark:bg-slate-950`,off:`border-zinc-300 bg-zinc-50 dark:bg-zinc-900`,standby:`border-zinc-300 bg-zinc-50 dark:bg-zinc-900`},dD={playing:`bg-green-500`,paused:`bg-amber-400`,buffering:`bg-blue-400`,on:`bg-slate-400`,idle:`bg-slate-400`,off:`bg-zinc-300`,standby:`bg-zinc-300`},fD=[`off`,`all`,`one`];function pD(e){return fD.includes(e)}var mD={off:`Off`,all:`All`,one:`One`};function hD(e){return e===`playing`||e===`buffering`?`pause`:`play`}function gD({trpc:e,deviceId:t,features:n,layout:r,optimistic:i}){let{cap:a,slice:o,available:s}=Q({trpc:e,deviceId:t,cap:e=>e.mediaPlayer,slice:e=>e.state.mediaPlayer}),{display:c,applyOptimistic:l}=vu(o,{enabled:i??!0});if(c===void 0)return null;let u=!s,d=hD(c.state);return g(`div`,{"data-state":c.state,className:X(`inline-flex items-center gap-2 rounded border px-2 py-1 transition-colors`,uD[c.state],r===`full`&&`flex-col items-stretch gap-3`),children:[g(`div`,{className:`inline-flex items-center gap-2`,children:[N(`span`,{role:`status`,"aria-label":c.state,className:X(`inline-block h-2 w-2 rounded-full flex-shrink-0`,dD[c.state])}),N(`button`,{type:`button`,"aria-label":d===`play`?`Play`:`Pause`,disabled:u,onClick:e=>{e.stopPropagation(),!u&&(d===`play`?(l({state:`playing`}),a?.play({})):(l({state:`paused`}),a?.pause({})))},className:X(`inline-flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors text-xs`,u&&`opacity-40 cursor-not-allowed`),children:d===`play`?`▶`:`⏸`})]}),r===`full`&&g(w,{children:[g(`div`,{className:`inline-flex items-center gap-1`,children:[N(`button`,{type:`button`,"aria-label":`Previous`,disabled:u,onClick:e=>{e.stopPropagation(),u||a?.previous({})},className:X(`inline-flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors text-xs`,u&&`opacity-40 cursor-not-allowed`),children:`⏮`}),N(`button`,{type:`button`,"aria-label":`Next`,disabled:u,onClick:e=>{e.stopPropagation(),u||a?.next({})},className:X(`inline-flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors text-xs`,u&&`opacity-40 cursor-not-allowed`),children:`⏭`})]}),c.volumeLevel!==null&&g(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[N(`span`,{children:`Vol`}),N(`input`,{"aria-label":`Volume`,type:`range`,min:0,max:100,step:1,value:c.volumeLevel,disabled:u,onChange:e=>{let t=Number(e.target.value);l({volumeLevel:t}),u||a?.setVolume({volumeLevel:t})}}),g(`span`,{className:`tabular-nums w-8 text-right`,children:[c.volumeLevel,`%`]})]}),c.isMuted!==null&&N(`button`,{type:`button`,"aria-label":c.isMuted?`Unmute`:`Mute`,disabled:u,onClick:e=>{if(e.stopPropagation(),!u&&c.isMuted!==null){let e=!c.isMuted;l({isMuted:e}),a?.setMute({muted:e})}},className:X(`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-xs transition-colors`,c.isMuted?`bg-amber-400 text-amber-950`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,u&&`opacity-40 cursor-not-allowed`),children:c.isMuted?`🔇`:`🔊`}),c.availableSources.length>0&&g(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[N(`span`,{children:`Source`}),g(`select`,{"aria-label":`Source`,value:c.source,disabled:u,onChange:e=>{let t=e.target.value;!u&&t&&(l({source:t}),a?.selectSource({source:t}))},className:`rounded border border-border bg-surface px-1 py-0.5`,children:[N(`option`,{value:``,disabled:!0,children:`—`}),c.availableSources.map(e=>N(`option`,{value:e,children:e},e))]})]}),c.shuffle!==null&&N(`button`,{type:`button`,"aria-label":`Shuffle`,disabled:u,onClick:e=>{if(e.stopPropagation(),!u&&c.shuffle!==null){let e=!c.shuffle;l({shuffle:e}),a?.setShuffle({shuffle:e})}},className:X(`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-xs transition-colors`,c.shuffle?`bg-green-400 text-green-950`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,u&&`opacity-40 cursor-not-allowed`),children:`⇌ Shuffle`}),c.repeat!==null&&g(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[N(`span`,{children:`Repeat`}),N(`select`,{"aria-label":`Repeat`,value:c.repeat,disabled:u,onChange:e=>{let t=e.target.value;!u&&pD(t)&&(l({repeat:t}),a?.setRepeat({repeat:t}))},className:`rounded border border-border bg-surface px-1 py-0.5`,children:fD.map(e=>N(`option`,{value:e,children:mD[e]},e))})]})]})]})}h();function _D(e){return e.slice(0,10)}function vD(e){return e.slice(0,5)}function yD(e){return(e.includes(`T`)?e:e.replace(` `,`T`)).slice(0,16)}function bD({value:e,busy:t,onCommit:n,unit:r,min:i,max:a,step:o,precision:s}){let[c,l]=k(xr(e,s)),u=Number(c),d=c!==``&&!Number.isNaN(u),f=o??1,p=e=>{let t=e;return i!==void 0&&(t=Math.max(i,t)),a!==void 0&&(t=Math.min(a,t)),t},m=()=>{!t&&d&&n(p(u))};return g(`div`,{className:`inline-flex items-center gap-1`,children:[N(`button`,{type:`button`,"aria-label":`Decrement`,disabled:t,onClick:r=>{if(r.stopPropagation(),!t){let t=p(e-f);l(xr(t,s)),n(t)}},className:X(`inline-flex h-5 w-5 items-center justify-center rounded border border-border bg-surface text-xs transition-colors hover:bg-surface-hover`,t&&`opacity-40 cursor-not-allowed`),children:`−`}),N(`input`,{"aria-label":`Numeric value`,type:`number`,disabled:t,value:c,onChange:e=>{l(e.target.value);let r=Number(e.target.value);e.target.value!==``&&!Number.isNaN(r)&&(t||n(p(r)))},onBlur:m,onKeyDown:e=>{e.key===`Enter`&&m()},className:X(`w-16 rounded border border-border bg-surface px-1 py-0.5 text-xs tabular-nums text-center`,t&&`opacity-40 cursor-not-allowed`)}),r!==void 0&&N(`span`,{className:`text-foreground-subtle text-xs`,children:r}),N(`button`,{type:`button`,"aria-label":`Increment`,disabled:t,onClick:r=>{if(r.stopPropagation(),!t){let t=p(e+f);l(xr(t,s)),n(t)}},className:X(`inline-flex h-5 w-5 items-center justify-center rounded border border-border bg-surface text-xs transition-colors hover:bg-surface-hover`,t&&`opacity-40 cursor-not-allowed`),children:`+`})]})}function xD({value:e,busy:t,onCommit:n}){let[r,i]=k(e);return N(`input`,{type:`text`,disabled:t,value:r,onChange:e=>i(e.target.value),onBlur:()=>{t||n(r)},onKeyDown:e=>{e.key===`Enter`&&!t&&n(r)},className:X(`rounded border border-border bg-surface px-2 py-0.5 text-xs`,t&&`opacity-40 cursor-not-allowed`)})}function SD({slice:e,busy:t,setValueFn:n,layout:r}){switch(e.kind){case`numeric`:return N(bD,{value:typeof e.value==`number`?e.value:Number(e.value),busy:t,onCommit:e=>{n({control:{kind:`numeric`,value:e}})},unit:e.unit,min:e.min,max:e.max,step:e.step,precision:e.precision});case`select`:return N(`select`,{"aria-label":`Control value`,disabled:t,value:String(e.value),onChange:e=>{e.stopPropagation(),t||n({control:{kind:`select`,value:e.target.value}})},className:X(`w-full max-w-full min-w-0 truncate rounded border border-border bg-surface px-1 py-0.5 text-xs`,t&&`opacity-40 cursor-not-allowed`),children:e.options.map(e=>N(`option`,{value:e,children:e},e))});case`text`:return N(xD,{value:String(e.value),busy:t,onCommit:e=>{n({control:{kind:`text`,value:e}})}});case`datetime`:{let i=String(e.value),a=e.format??`datetime`;return r===`compact`?i===``?N(`span`,{"aria-label":`Control value`,className:`text-xs text-foreground-subtle`,children:`—`}):N(`span`,{"aria-label":`Control value`,className:`text-xs text-foreground`,children:br(i,a)}):N(`input`,{type:a===`date`?`date`:a===`time`?`time`:`datetime-local`,"aria-label":`Control value`,disabled:t,value:a===`date`?_D(i):a===`time`?vD(i):yD(i),onChange:e=>{e.stopPropagation(),t||n({control:{kind:`datetime`,value:e.target.value}})},className:X(`rounded border border-border bg-surface px-1 py-0.5 text-xs`,t&&`opacity-40 cursor-not-allowed`)})}default:return null}}function CD({trpc:e,deviceId:t,features:n,layout:r,optimistic:i}){let{cap:a,slice:o,available:s}=Q({trpc:e,deviceId:t,cap:e=>e.control,slice:e=>e.state.control}),{display:c,applyOptimistic:l}=vu(o,{enabled:i??!0});if(c===void 0)return null;let u=!s;return N(`div`,{"data-kind":c.kind,className:`inline-flex min-w-0 max-w-full items-center gap-1 rounded border border-border px-2 py-1 transition-colors`,children:N(SD,{slice:c,busy:u,setValueFn:e=>{!u&&a&&(l({value:e.control.value}),a.setValue(e))},layout:r})})}var wD=5,TD=35;function ED(e,t,n){return n<=t?0:Math.min(1,Math.max(0,(e-t)/(n-t)))}function DD(e,t,n){return Math.round(t+e*(n-t))}var OD=176,kD=76,AD=2*Math.PI*kD,jD=270/360*AD,MD=OD/2-kD-10;function ND(e){let t=OD/2,n=OD/2,r=AD-jD,i=e.mode===`band`?(()=>{let t=e.band.from*jD,n=Math.max(0,(e.band.to-e.band.from)*jD);return{dasharray:`${n} ${AD-n}`,dashoffset:-t}})():(()=>{let t=e.fraction*jD;return{dasharray:`${t} ${AD-t}`,dashoffset:void 0}})();return g(`svg`,{width:OD,height:OD,viewBox:`0 0 ${OD} ${OD}`,"aria-hidden":`true`,className:`absolute inset-0`,style:{transform:`rotate(135deg)`},children:[N(`circle`,{cx:t,cy:n,r:kD,fill:`none`,stroke:`var(--color-border)`,strokeWidth:12,strokeDasharray:`${jD} ${r}`,strokeLinecap:`round`}),N(`circle`,{cx:t,cy:n,r:kD,fill:`none`,stroke:e.color,strokeWidth:12,strokeDasharray:i.dasharray,...i.dashoffset===void 0?{}:{strokeDashoffset:i.dashoffset},strokeLinecap:`round`})]})}var PD={heat:`#f59e0b`,cool:`#60a5fa`,auto:`#c084fc`,heat_cool:`#e879f9`,fan_only:`#94a3b8`,dry:`#22d3ee`,off:`#d4d4d8`};function FD({trpc:e,deviceId:t,features:n,optimistic:r}){let{cap:i,slice:a,available:o}=Q({trpc:e,deviceId:t,cap:e=>e.climateControl,slice:e=>e.state.climateControl}),{display:s,applyOptimistic:c}=vu(a,{enabled:r??!0});if(i===void 0||s===void 0)return null;let l=!o,u=PD[s.mode],d=s.mode===`heat_cool`||s.targetLow!==null&&s.targetHigh!==null,f=wD,p=TD,m=!d&&s.target!==null?ED(s.target,f,p):0,h=d&&s.targetLow!==null?ED(s.targetLow,f,p):0,_=d&&s.targetHigh!==null?ED(s.targetHigh,f,p):0;return g(`div`,{"data-mode":s.mode,className:X(`flex flex-col items-stretch gap-4 rounded-lg border border-border bg-surface p-4 transition-colors`,HE[s.mode]),children:[g(`div`,{className:`flex flex-col items-center gap-3`,children:[g(`div`,{className:`relative`,style:{width:OD,height:OD},children:[d?N(ND,{mode:`band`,band:{from:h,to:_},color:u}):N(ND,{mode:`fill`,fraction:m,color:u}),d?g(w,{children:[N(`div`,{"data-testid":`arc-knob`,children:N(fu,{fraction:h,color:u,knobTopPx:MD,onDragFraction:e=>{if(l||s.targetHigh===null)return;let t=Math.min(DD(e,f,p),s.targetHigh);c({targetLow:t}),i.setTargetRange({targetLow:t,targetHigh:s.targetHigh})}})}),N(`div`,{"data-testid":`arc-knob`,children:N(fu,{fraction:_,color:u,knobTopPx:MD,onDragFraction:e=>{if(l||s.targetLow===null)return;let t=Math.max(DD(e,f,p),s.targetLow);c({targetHigh:t}),i.setTargetRange({targetLow:s.targetLow,targetHigh:t})}})})]}):N(`div`,{"data-testid":`arc-knob`,children:N(fu,{fraction:m,color:u,knobTopPx:MD,onDragFraction:e=>{if(l)return;let t=DD(e,f,p);c({target:t}),i.setTarget({target:t})}})}),g(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-0.5 pointer-events-none`,children:[g(`div`,{"data-testid":`current-temp`,className:`text-4xl font-bold tabular-nums text-foreground leading-none`,children:[s.currentTemp===null?`—`:s.currentTemp,N(`span`,{className:`text-lg text-foreground-subtle font-normal ml-0.5`,children:`°`})]}),!d&&s.target!==null&&g(`div`,{className:`text-xs font-semibold`,style:{color:u},children:[`set `,s.target,`°`]}),d&&s.targetLow!==null&&s.targetHigh!==null&&g(`div`,{className:`text-xs font-semibold`,style:{color:u},children:[s.targetLow,`° – `,s.targetHigh,`°`]})]})]}),!d&&s.target!==null&&N(`div`,{className:`w-[200px]`,children:N(ou,{value:`${s.target}°`,onDelta:e=>{if(l||s.target===null)return;let t=s.target+e;c({target:t}),i.setTarget({target:t})}})})]}),N(`select`,{"aria-label":`Mode`,value:s.mode,disabled:l,onChange:e=>{e.stopPropagation();let t=e.target.value;!l&&t&&(c({mode:s.availableModes.find(e=>e===t)??s.mode}),i.setMode({mode:s.availableModes.find(e=>e===t)??s.mode}))},className:X(`w-full rounded border border-border bg-surface px-3 py-1.5 text-sm`,l&&`opacity-40 cursor-not-allowed`),children:s.availableModes.map(e=>N(`option`,{value:e,children:e},e))})]})}function ID(e){return e===`locked`||e===`locking`}function LD(e){return e===`jammed`}var RD={locked:{colorClass:`border-success/30 bg-success/10 text-success`,icon:`locked`},locking:{colorClass:`border-success/30 bg-success/10 text-success`,icon:`locked`},unlocked:{colorClass:`border-warning/30 bg-warning/10 text-warning`,icon:`open`},unlocking:{colorClass:`border-warning/30 bg-warning/10 text-warning`,icon:`open`},jammed:{colorClass:`border-danger/30 bg-danger/10 text-danger`,icon:`locked`}};function zD({state:e}){let t=RD[e];return N(`div`,{"data-testid":`lock-glyph`,"data-state":e,className:X(`flex h-16 w-16 items-center justify-center rounded-full border-2`,t.colorClass),children:t.icon===`locked`?N(ka,{className:`h-8 w-8`,"aria-hidden":`true`}):N(Oa,{className:`h-8 w-8`,"aria-hidden":`true`})})}function BD({state:e}){return N(`span`,{className:X(`text-sm font-medium capitalize`,LD(e)?`text-danger`:`text-foreground-muted`),children:e})}function VD({busy:e,onOpen:t}){return g(`button`,{type:`button`,"aria-label":`Open (unlatch)`,title:`Open (unlatch)`,disabled:e,onClick:e=>{e.stopPropagation(),t()},className:X(`inline-flex items-center gap-1.5 rounded-md border border-border px-3 py-1.5 text-xs font-medium`,`text-foreground-muted hover:bg-surface-hover transition-colors`,e&&`opacity-40 cursor-not-allowed`),children:[N(Yi,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Open`]})}function HD({trpc:e,deviceId:t,features:n,optimistic:r}){let{cap:i,slice:a,available:o}=Q({trpc:e,deviceId:t,cap:e=>e.lockControl,slice:e=>e.state.lockControl}),{display:s,applyOptimistic:c}=vu(a,{enabled:r??!0});if(i===void 0||s===void 0)return null;let l=ID(s.state),u=LD(s.state)||!o,d=n?.includes(U.LockOpen)===!0,f=()=>{u||(l?(c({state:`unlocking`}),i.unlock({})):(c({state:`locking`}),i.lock({})))},p=()=>{u||i.open({})},m=l?`Unlock`:`Lock`;return g(`div`,{className:`flex flex-col items-stretch gap-4 rounded-lg border border-border bg-surface p-4`,children:[g(`div`,{className:`flex flex-col items-center gap-2`,children:[N(zD,{state:s.state}),N(BD,{state:s.state})]}),N(`div`,{className:X(u&&`pointer-events-none opacity-40`),children:N(su,{on:l,targetLabel:m,onConfirm:f})}),d&&N(`div`,{className:`flex justify-center`,children:N(VD,{busy:u,onOpen:p})})]})}var UD=150,WD=64,GD=UD/2,KD=2*Math.PI*WD,qD=270/360*KD;function JD({fraction:e,color:t,children:n,onDragFraction:r}){let i=Math.min(1,Math.max(0,e)),a=UD/2,o=UD/2,s=KD-qD,c=i*qD;return g(`div`,{className:`relative`,style:{width:UD,height:UD},children:[g(`svg`,{width:UD,height:UD,viewBox:`0 0 ${UD} ${UD}`,"aria-hidden":`true`,className:`absolute inset-0`,style:{transform:`rotate(135deg)`},children:[N(`circle`,{cx:a,cy:o,r:WD,fill:`none`,stroke:`var(--color-border)`,strokeWidth:11,strokeDasharray:`${qD} ${s}`,strokeLinecap:`round`}),N(`circle`,{cx:a,cy:o,r:WD,fill:`none`,stroke:t,strokeWidth:11,strokeDasharray:`${c} ${KD-c}`,strokeLinecap:`round`})]}),N(`div`,{"data-testid":`arc-knob`,children:N(fu,{fraction:i,color:t,knobTopPx:GD-WD-10,...r===void 0?{}:{onDragFraction:r}})}),N(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-0.5 pointer-events-none`,children:n})]})}function YD({on:e,busy:t,onToggle:n}){let r={transform:e?`translateX(30px)`:`translateX(3px)`};return N(`button`,{type:`button`,"aria-pressed":e,title:e?`Turn off`:`Turn on`,disabled:t,onClick:e=>{e.stopPropagation(),n()},className:X(`relative inline-flex h-8 w-16 items-center rounded-full border transition-colors flex-shrink-0`,e?`bg-success/30 border-success/50`:`bg-surface-hover border-border`,t&&`opacity-60 cursor-not-allowed`),children:N(`span`,{className:X(`absolute h-6 w-6 rounded-full transition-all`,e?`bg-success`:`bg-foreground-subtle`),style:r})})}var XD=500,ZD=150,QD=`linear-gradient(90deg, #9ec9ff, #ffffff, #ffb24d)`;function $D(e,t,n){return n<=t?0:Math.min(1,Math.max(0,(e-t)/(n-t)))}function eO(e){return $D(e,ZD,XD)}var tO=`#f4b740`,nO=`#d4d4d8`;function rO({trpc:e,deviceId:t,features:n,optimistic:r}){let i=Q({trpc:e,deviceId:t,cap:e=>e.switch,slice:e=>e.state.switch}),a=Q({trpc:e,deviceId:t,cap:e=>e.brightness,slice:e=>e.state.brightness}),o=Q({trpc:e,deviceId:t,cap:e=>e.color,slice:e=>e.state.color}),s=vu(i.slice,{enabled:r??!0}),c=vu(a.slice,{enabled:r??!0}),l=vu(o.slice,{enabled:r??!0});if(i.cap===void 0||s.display===void 0)return null;let u=s.display.on===!0,d=!i.available,f=c.display?.percentage??0,p=!a.available,m=u?f/100:0,h=u?tO:nO,_=(n?.includes(U.LightColorMired)??!1)&&o.cap!==void 0,v=l.display?.mireds,y=!o.available;return g(`div`,{className:`flex flex-col items-stretch gap-4 rounded-lg border border-border bg-surface p-4`,children:[g(`div`,{className:`flex flex-col items-center gap-3`,children:[g(JD,{fraction:m,color:h,children:[g(`div`,{"data-testid":`brightness-readout`,className:`text-3xl font-bold tabular-nums text-foreground leading-none`,children:[f,N(`span`,{className:`text-base text-foreground-subtle font-normal ml-0.5`,children:`%`})]}),N(Ca,{className:`h-5 w-5 text-foreground-subtle`,"aria-hidden":`true`})]}),a.cap!==void 0&&g(`label`,{className:`flex w-full items-center gap-2 text-xs text-foreground-subtle`,children:[N(`span`,{className:`w-16`,children:`Brightness`}),N(`input`,{"aria-label":`Brightness`,type:`range`,min:0,max:100,step:1,className:`flex-1`,value:f,disabled:p||!u,onChange:e=>{let t=Number(e.target.value);c.applyOptimistic({percentage:t}),p||a.cap?.setBrightness({percentage:t})}}),g(`span`,{className:`tabular-nums w-9 text-right`,children:[f,`%`]})]})]}),g(`div`,{className:`flex items-center justify-between`,children:[N(`span`,{className:`text-sm font-medium text-foreground-muted`,children:u?`On`:`Off`}),N(YD,{on:u,busy:d,onToggle:()=>{if(d)return;let e=!u;s.applyOptimistic({on:e}),i.cap?.setState({on:e})}})]}),_&&g(`div`,{className:`flex items-center gap-2`,"data-testid":`color-temp-strip`,children:[N(Lo,{className:`h-4 w-4 text-foreground-subtle`,"aria-hidden":`true`}),g(`label`,{className:`flex-1`,children:[N(`span`,{className:`sr-only`,children:`Colour temperature`}),N(`input`,{"aria-label":`Colour temperature`,type:`range`,min:ZD,max:XD,step:1,className:`w-full`,value:v??XD,disabled:y||!u,onChange:e=>{let t=Number(e.target.value);l.applyOptimistic({mode:`mired`,mireds:t}),y||o.cap?.setColor({color:{mode:`mired`,mireds:t}})}}),N(`div`,{className:`pointer-events-none mt-1`,children:N(pu,{fraction:v===void 0?.5:eO(v),color:QD})})]})]})]})}var iO=`#3aa6a0`,aO=`#d4d4d8`;function oO({trpc:e,deviceId:t,features:n,optimistic:r}){let i=Q({trpc:e,deviceId:t,cap:e=>e.switch,slice:e=>e.state.switch}),a=Q({trpc:e,deviceId:t,cap:e=>e.fanControl,slice:e=>e.state.fanControl}),o=vu(i.slice,{enabled:r??!0}),s=vu(a.slice,{enabled:r??!0});if(i.cap===void 0||o.display===void 0)return null;let c=o.display.on===!0,l=!i.available,u=s.display?.percentage??0,d=!a.available,f=c?u/100:0,p=c?iO:aO,m=n?.includes(U.FanSpeed)??!1,h=(n?.includes(U.FanOscillating)??!1)&&a.cap!==void 0,_=s.display?.availablePresets??[],v=(n?.includes(U.FanPreset)??!1)&&a.cap!==void 0&&_.length>0,y=s.display?.preset??``,b=s.display?.oscillating===!0,x=()=>{if(l)return;let e=!c;o.applyOptimistic({on:e}),i.cap?.setState({on:e})},S=()=>{if(d)return;let e=!b;s.applyOptimistic({oscillating:e}),a.cap?.setOscillating({oscillating:e})},C=e=>{if(d)return;let t=s.display;if(t===void 0)return;let n=t.percentageStep!==void 0&&t.percentageStep>0?t.percentageStep:1,r=Math.min(100,Math.max(0,Math.round(e*100/n)*n));s.applyOptimistic({percentage:r}),a.cap?.setPercentage({percentage:r})},w=e=>{d||e===``||(s.applyOptimistic({preset:e}),a.cap?.setPreset({preset:e}))};return g(`div`,{className:`flex flex-col items-stretch gap-4 rounded-lg border border-border bg-surface p-4`,children:[N(`div`,{className:`flex flex-col items-center gap-3`,children:m?g(JD,{fraction:f,color:p,onDragFraction:C,children:[g(`div`,{"data-testid":`speed-readout`,className:`text-3xl font-bold tabular-nums text-foreground leading-none`,children:[u,N(`span`,{className:`text-base text-foreground-subtle font-normal ml-0.5`,children:`%`})]}),N(ra,{className:`h-5 w-5 text-foreground-subtle`,"aria-hidden":`true`})]}):N(`div`,{"data-testid":`fan-onoff-icon`,className:`flex h-[150px] w-[150px] items-center justify-center`,children:N(ra,{className:`h-16 w-16`,style:{color:p},"aria-hidden":`true`})})}),v&&N(`div`,{className:`flex justify-center`,children:g(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[N(`span`,{children:`Preset`}),g(`select`,{"aria-label":`Fan preset`,value:y,disabled:d,onChange:e=>{e.stopPropagation(),w(e.target.value)},className:X(`bg-surface border border-border rounded px-1 py-0.5`,d&&`opacity-40 cursor-not-allowed`),children:[N(`option`,{value:``,disabled:!0,children:`—`}),_.map(e=>N(`option`,{value:e,children:e},e))]})]})}),g(`div`,{className:`flex items-center justify-between gap-2`,children:[h?g(`button`,{type:`button`,"aria-label":`Oscillate`,"aria-pressed":b,disabled:d,onClick:e=>{e.stopPropagation(),S()},className:X(`inline-flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs font-medium transition-colors`,b?`border-success/50 bg-success/10 text-success`:`border-border text-foreground-muted hover:bg-surface-hover`,d&&`opacity-40 cursor-not-allowed`),children:[N(oo,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Oscillate`]}):N(`span`,{className:`text-sm font-medium text-foreground-muted`,children:c?`On`:`Off`}),N(YD,{on:c,busy:l,onToggle:x})]})]})}function sO({trpc:e,deviceId:t,optimistic:n}){let{cap:r,slice:i,available:a}=Q({trpc:e,deviceId:t,cap:e=>e.switch,slice:e=>e.state.switch}),{display:o,applyOptimistic:s}=vu(i,{enabled:n??!0});if(r===void 0||o===void 0)return null;let c=o.on===!0,l=!a;return g(`div`,{className:`flex flex-col items-center gap-4 rounded-lg border border-border bg-surface p-6`,children:[N(`div`,{"data-testid":`switch-glyph`,"data-state":c?`on`:`off`,className:X(`flex h-16 w-16 items-center justify-center rounded-full border-2 transition-colors`,c?`border-success/30 bg-success/10 text-success`:`border-border bg-surface-subtle text-foreground-subtle`),children:N(no,{className:`h-8 w-8`,"aria-hidden":`true`})}),N(`span`,{className:`text-sm font-medium text-foreground-muted`,children:c?`On`:`Off`}),N(YD,{on:c,busy:l,onToggle:()=>{if(l)return;let e=!c;s({on:e}),r.setState({on:e})}})]})}function cO(e){return e===`playing`||e===`buffering`?`pause`:`play`}function lO(e,t){return e===null||t===null||t<=0?0:Math.min(1,Math.max(0,e/t))}function uO(e){if(e===null)return`--:--`;let t=Math.floor(e/1e3);return`${Math.floor(t/60)}:${(t%60).toString().padStart(2,`0`)}`}function dO({title:e,subtitle:t}){return g(`div`,{className:`flex flex-col items-center gap-1 text-center`,children:[N(Ga,{className:`h-6 w-6 text-foreground-subtle`,"aria-hidden":`true`}),N(`span`,{className:`text-base font-semibold text-foreground line-clamp-1`,children:e??`Nothing playing`}),t&&N(`span`,{className:`text-xs text-foreground-subtle line-clamp-1`,children:t})]})}function fO({label:e,busy:t,onPress:n,children:r,primary:i}){return N(`button`,{type:`button`,"aria-label":e,title:e,disabled:t,onClick:e=>{e.stopPropagation(),t||n()},className:X(`inline-flex items-center justify-center rounded-full transition-colors`,i?`h-12 w-12 bg-primary text-primary-foreground hover:bg-primary/90 shadow-md`:`h-10 w-10 text-foreground-muted hover:bg-surface-hover`,t&&`opacity-40 cursor-not-allowed`),children:r})}function pO({trpc:e,deviceId:t,features:n,optimistic:r}){let{cap:i,slice:a,available:o}=Q({trpc:e,deviceId:t,cap:e=>e.mediaPlayer,slice:e=>e.state.mediaPlayer}),{display:s,applyOptimistic:c}=vu(a,{enabled:r??!0});if(i===void 0||s===void 0)return null;let l=!o,u=cO(s.state),d=(n?.includes(U.MediaPlayerSeek)??!1)&&s.durationMs!==null&&s.durationMs>0,f=n?.includes(U.MediaPlayerNext)??!1,p=n?.includes(U.MediaPlayerPrevious)??!1,m=(n?.includes(U.MediaPlayerVolume)??!1)&&s.volumeLevel!==null,h=()=>{l||(u===`play`?(c({state:`playing`}),i.play({})):(c({state:`paused`}),i.pause({})))},_=s.currentMedia?.artist??s.currentMedia?.album??null,v=lO(s.positionMs,s.durationMs),y=s.volumeLevel??0;return g(`div`,{className:`flex flex-col items-stretch gap-4 rounded-lg border border-border bg-surface p-6`,children:[N(dO,{title:s.currentMedia?.title??null,subtitle:_}),d&&g(`div`,{"data-testid":`media-seek`,className:`flex flex-col gap-1`,children:[g(`label`,{className:`relative block`,children:[N(`span`,{className:`sr-only`,children:`Seek`}),N(`input`,{"aria-label":`Seek`,type:`range`,min:0,max:s.durationMs??0,step:1e3,className:`absolute inset-0 h-4 w-full cursor-pointer opacity-0`,value:s.positionMs??0,disabled:l,onChange:e=>{if(l)return;let t=Number(e.target.value);c({positionMs:t}),i.seek({positionMs:t})}}),N(`div`,{className:`pointer-events-none`,children:N(pu,{fraction:v})})]}),g(`div`,{className:`flex justify-between text-[11px] tabular-nums text-foreground-subtle`,children:[N(`span`,{children:uO(s.positionMs)}),N(`span`,{children:uO(s.durationMs)})]})]}),g(`div`,{className:`flex items-center justify-center gap-4`,children:[p&&N(fO,{label:`Previous`,busy:l,onPress:()=>void i.previous({}),children:N(Co,{className:`h-5 w-5`,"aria-hidden":`true`})}),N(fO,{label:u===`play`?`Play`:`Pause`,busy:l,onPress:h,primary:!0,children:N(u===`play`?Qa:Ja,{className:`h-6 w-6`,"aria-hidden":`true`})}),f&&N(fO,{label:`Next`,busy:l,onPress:()=>void i.next({}),children:N(wo,{className:`h-5 w-5`,"aria-hidden":`true`})})]}),m&&g(`div`,{"data-testid":`media-volume`,className:`flex items-center gap-2`,children:[N(`button`,{type:`button`,"aria-label":s.isMuted===!0?`Unmute`:`Mute`,title:s.isMuted===!0?`Unmute`:`Mute`,disabled:l,onClick:e=>{if(e.stopPropagation(),l||s.isMuted===null)return;let t=!s.isMuted;c({isMuted:t}),i.setMute({muted:t})},className:X(`inline-flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,l&&`opacity-40 cursor-not-allowed`),children:s.isMuted===!0?N(Xo,{className:`h-4 w-4`,"aria-hidden":`true`}):N(Yo,{className:`h-4 w-4`,"aria-hidden":`true`})}),g(`label`,{className:`relative block flex-1`,children:[N(`span`,{className:`sr-only`,children:`Volume`}),N(`input`,{"aria-label":`Volume`,type:`range`,min:0,max:100,step:1,className:`absolute inset-0 h-4 w-full cursor-pointer opacity-0`,value:y,disabled:l,onChange:e=>{if(l)return;let t=Number(e.target.value);c({volumeLevel:t}),i.setVolume({volumeLevel:t})}}),N(`div`,{className:`pointer-events-none`,children:N(pu,{fraction:y/100})})]}),g(`span`,{className:`w-9 text-right text-[11px] tabular-nums text-foreground-subtle`,children:[y,`%`]})]})]})}var mO={disarmed:{label:`Disarmed`,colorClass:`border-border bg-surface-subtle text-foreground-subtle`,icon:`disarmed`},armed_home:{label:`Armed Home`,colorClass:`border-success/30 bg-success/10 text-success`,icon:`armed`},armed_away:{label:`Armed Away`,colorClass:`border-success/30 bg-success/10 text-success`,icon:`armed`},armed_night:{label:`Armed Night`,colorClass:`border-success/30 bg-success/10 text-success`,icon:`armed`},armed_vacation:{label:`Armed Vacation`,colorClass:`border-success/30 bg-success/10 text-success`,icon:`armed`},armed_custom_bypass:{label:`Armed (Bypass)`,colorClass:`border-success/30 bg-success/10 text-success`,icon:`armed`},arming:{label:`Arming…`,colorClass:`border-warning/30 bg-warning/10 text-warning`,icon:`pending`},disarming:{label:`Disarming…`,colorClass:`border-warning/30 bg-warning/10 text-warning`,icon:`pending`},pending:{label:`Pending`,colorClass:`border-warning/30 bg-warning/10 text-warning`,icon:`pending`},triggered:{label:`Triggered`,colorClass:`border-danger/30 bg-danger/10 text-danger`,icon:`triggered`}},hO={home:`Home`,away:`Away`,night:`Night`,vacation:`Vacation`,custom_bypass:`Bypass`};function gO(e){return e.startsWith(`armed_`)}function _O(e){return e===`arming`||e===`disarming`}function vO({icon:e}){return N(e===`disarmed`?yo:e===`triggered`?_o:e===`pending`?bo:vo,{className:`h-8 w-8`,"aria-hidden":`true`})}function yO({label:e,active:t,busy:n,onSelect:r}){return N(`button`,{type:`button`,"aria-label":e,"aria-pressed":t,disabled:n,onClick:e=>{e.stopPropagation(),n||r()},className:X(`flex-1 rounded-md px-3 py-2 text-sm font-medium transition-colors`,t?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-muted hover:bg-surface-hover`,n&&`opacity-40 cursor-not-allowed`),children:e})}function bO({state:e,availableModes:t,busy:n,onDisarm:r,onArm:i}){let a=gO(e),o=_O(e);return g(`div`,{className:`flex items-stretch gap-1 rounded-lg border border-border bg-surface-subtle p-1`,children:[N(yO,{label:`Disarm`,active:!a&&!o,busy:n,onSelect:r}),t.map(t=>N(yO,{label:hO[t],active:!o&&e===`armed_${t}`,busy:n,onSelect:()=>i(t)},t))]})}function xO(e,t,n){let{cap:r,slice:i,available:a}=Q({trpc:e,deviceId:t,cap:e=>e.alarmPanel,slice:e=>e.state.alarmPanel}),{display:o,applyOptimistic:s}=vu(i,{enabled:n??!0}),c=!a;return{display:o,capPresent:r!==void 0,busy:c,handleDisarm:()=>{r===void 0||c||(s({state:`disarming`}),r.disarm({}))},handleArm:e=>{r===void 0||c||(s({state:`arming`}),r.arm({mode:e}))}}}function SO({trpc:e,deviceId:t,optimistic:n}){let{display:r,capPresent:i,busy:a,handleDisarm:o,handleArm:s}=xO(e,t,n);return!i||r===void 0?null:N(bO,{state:r.state,availableModes:r.availableModes,busy:a,onDisarm:o,onArm:s})}function CO({trpc:e,deviceId:t,optimistic:n}){let{display:r,capPresent:i,busy:a,handleDisarm:o,handleArm:s}=xO(e,t,n);if(!i||r===void 0)return null;let c=mO[r.state];return g(`div`,{className:`flex flex-col items-stretch gap-4 rounded-lg border border-border bg-surface p-6`,children:[g(`div`,{className:`flex flex-col items-center gap-2`,children:[N(`div`,{"data-testid":`alarm-state`,"data-state":r.state,className:X(`flex h-16 w-16 items-center justify-center rounded-full border-2`,c.colorClass),children:N(vO,{icon:c.icon})}),N(`span`,{className:`text-sm font-medium text-foreground-muted`,children:c.label})]}),N(bO,{state:r.state,availableModes:r.availableModes,busy:a,onDisarm:o,onArm:s})]})}function wO({children:e}){return N(`div`,{className:`flex flex-col items-stretch gap-3 rounded-lg border border-border bg-surface p-4`,children:e})}function TO(e,t){let{cap:n}=Q({trpc:e,deviceId:t,cap:e=>e.switch,slice:e=>e.state.switch});return n!==void 0}function EO({trpc:e,deviceId:t,features:n,optimistic:r}){return TO(e,t)?N(LE,{trpc:e,deviceId:t,features:n,layout:`compact`,optimistic:r}):null}function DO(e,t){let{cap:n}=Q({trpc:e,deviceId:t,cap:e=>e.lockControl,slice:e=>e.state.lockControl});return n!==void 0}function OO({trpc:e,deviceId:t,features:n,optimistic:r}){return DO(e,t)?N(zE,{trpc:e,deviceId:t,features:n,layout:`compact`,optimistic:r}):null}function kO({trpc:e,deviceId:t,features:n,optimistic:r}){return TO(e,t)?g(`div`,{className:`inline-flex items-center gap-2`,children:[N(LE,{trpc:e,deviceId:t,features:n,layout:`compact`,optimistic:r}),N(BE,{trpc:e,deviceId:t,features:n,layout:`compact`,optimistic:r})]}):null}function AO(e,t){let{cap:n}=Q({trpc:e,deviceId:t,cap:e=>e.fanControl,slice:e=>e.state.fanControl});return n!==void 0}function jO({trpc:e,deviceId:t,features:n,optimistic:r}){return AO(e,t)?g(`div`,{className:`inline-flex items-center gap-2`,children:[N(LE,{trpc:e,deviceId:t,features:n,layout:`compact`,optimistic:r}),N(VE,{trpc:e,deviceId:t,features:n,layout:`compact`,optimistic:r})]}):null}function MO(e,t){let{cap:n}=Q({trpc:e,deviceId:t,cap:e=>e.climateControl,slice:e=>e.state.climateControl});return n!==void 0}function NO({trpc:e,deviceId:t,features:n,optimistic:r}){return MO(e,t)?N(GE,{trpc:e,deviceId:t,features:n,layout:`compact`,optimistic:r}):null}function PO({trpc:e,deviceId:t,features:n,optimistic:r}){return MO(e,t)?N(tD,{trpc:e,deviceId:t,features:n,layout:`compact`,optimistic:r}):null}function FO({trpc:e,deviceId:t,features:n,optimistic:r}){return MO(e,t)?N(tD,{trpc:e,deviceId:t,features:n,layout:`full`,optimistic:r}):null}function IO(e,t){let{cap:n}=Q({trpc:e,deviceId:t,cap:e=>e.mediaPlayer,slice:e=>e.state.mediaPlayer});return n!==void 0}function LO({trpc:e,deviceId:t,features:n,optimistic:r}){return IO(e,t)?N(gD,{trpc:e,deviceId:t,features:n,layout:`compact`,optimistic:r}):null}function RO(e,t){let{cap:n}=Q({trpc:e,deviceId:t,cap:e=>e.control,slice:e=>e.state.control});return n!==void 0}function zO({trpc:e,deviceId:t,features:n,optimistic:r}){return RO(e,t)?N(CD,{trpc:e,deviceId:t,features:n,layout:`compact`,optimistic:r}):null}function BO({trpc:e,deviceId:t,features:n,optimistic:r}){return RO(e,t)?N(wO,{children:N(CD,{trpc:e,deviceId:t,features:n,layout:`full`,optimistic:r})}):null}var VO={InlineControl:Su,HeroCard:Du},HO={InlineControl:Ou,HeroCard:ku},UO={InlineControl:qw,HeroCard:nT},WO={InlineControl:aT,HeroCard:oT},GO={InlineControl:EO,HeroCard:sO},KO={InlineControl:OO,HeroCard:HD},qO={InlineControl:kO,HeroCard:rO},JO={InlineControl:jO,HeroCard:oO},YO={InlineControl:NO,HeroCard:FD},XO={InlineControl:PO,HeroCard:FO},ZO={InlineControl:LO,HeroCard:pO},QO={InlineControl:SO,HeroCard:CO},$O={InlineControl:zO,HeroCard:BO},ek={InlineControl:yT,HeroCard:xT},tk={InlineControl:MT,HeroCard:PT},nk={InlineControl:zT,HeroCard:WT},rk={InlineControl:qT,HeroCard:YT},ik={InlineControl:$T,HeroCard:tE},ak={InlineControl:sE,HeroCard:fE},ok={InlineControl:yE,HeroCard:bE},sk={InlineControl:FE,HeroCard:IE},ck={[G.Cover]:VO,[G.Valve]:nk,[G.Humidifier]:rk,[G.WaterHeater]:ik,[G.Camera]:HO,[G.Hub]:HO,[G.Switch]:GO,[G.Siren]:GO,[G.Light]:qO,[G.Fan]:JO,[G.Sensor]:UO,[G.Thermostat]:YO,[G.Climate]:XO,[G.Button]:{InlineControl:mu,HeroCard:hu},[G.EventEmitter]:HO,[G.Update]:WO,[G.Generic]:HO,[G.Notifier]:HO,[G.Script]:HO,[G.Automation]:HO,[G.Lock]:KO,[G.MediaPlayer]:ZO,[G.AlarmPanel]:QO,[G.Control]:$O,[G.Presence]:UO,[G.Weather]:ak,[G.Vacuum]:ek,[G.LawnMower]:tk,[G.Container]:HO,[G.Image]:ok,[G.PetFeeder]:sk},lk={[G.Cover]:!0,[G.Valve]:!0,[G.Thermostat]:!0,[G.Climate]:!0,[G.Control]:!0,[G.Button]:!0,[G.MediaPlayer]:!0,[G.AlarmPanel]:!0,[G.Lock]:!1,[G.Vacuum]:!1,[G.LawnMower]:!1,[G.Humidifier]:!1,[G.Switch]:!1,[G.Siren]:!1,[G.Light]:!1,[G.Fan]:!1,[G.WaterHeater]:!1,[G.Sensor]:!1,[G.Presence]:!1,[G.EventEmitter]:!1,[G.Notifier]:!1,[G.Script]:!1,[G.Automation]:!1,[G.Camera]:!1,[G.Hub]:!1,[G.Update]:!1,[G.Generic]:!1,[G.Weather]:!1,[G.Container]:!1,[G.Image]:!1,[G.PetFeeder]:!1},uk=new Set(Object.values(G));function dk(e){return uk.has(e)?ck[e]:null}function fk(e,t){return t===`table`?`fit`:uk.has(e)&&lk[e]?tu:t===`center`?ru:nu}var pk=[`media-player`,`alarm-panel`,`thermostat`,`climate`,`humidifier`,`water-heater`,`lock`,`cover`,`valve`,`fan`,`vacuum`,`lawn-mower`,`light`,`switch`,`siren`,`button`,`control`,`notifier`,`script`,`automation`,`update`,`presence`,`weather`,`image`,`sensor`];function mk(e,t){if(t!==void 0){let n=e.find(e=>e.entityId===t);if(n!==void 0)return n}return[...e].toSorted((e,t)=>hk(e.type)-hk(t.type))[0]??null}function hk(e){let t=pk.indexOf(e);return t===-1?pk.length:t}function gk(e){return e.sourceInfo?.id??e.stableId}function _k(e){return{id:e.id,entityId:gk(e),type:e.type}}function vk(e,t){if(t==null)return;let n=e.find(e=>e.id===t);return n===void 0?void 0:gk(n)}function yk(e,t,n){return mk(e.map(_k),n!=null&&n!==``?n:vk(e,t))}var bk={[G.Camera]:{icon:xi,label:`Camera`},[G.Hub]:{icon:qa,label:`Hub`},[G.Light]:{icon:Ca,label:`Light`},[G.Siren]:{icon:So,label:`Siren`},[G.Switch]:{icon:Ro,label:`Switch`},[G.Sensor]:{icon:Qr,label:`Sensor`},[G.Thermostat]:{icon:Lo,label:`Thermostat`},[G.Climate]:{icon:$r,label:`Air conditioner`},[G.Button]:{icon:ji,label:`Button`},[G.EventEmitter]:{icon:is,label:`Event Emitter`},[G.Update]:{icon:oo,label:`Update`},[G.Generic]:{icon:yi,label:`Generic`},[G.Notifier]:{icon:hi,label:`Notifier`},[G.Script]:{icon:fo,label:`Script`},[G.Automation]:{icon:ts,label:`Automation`},[G.Lock]:{icon:ka,label:`Lock`},[G.Cover]:{icon:gi,label:`Cover`},[G.Valve]:{icon:Za,label:`Valve`},[G.Humidifier]:{icon:Zo,label:`Humidifier`},[G.WaterHeater]:{icon:ci,label:`Water heater`},[G.Fan]:{icon:ra,label:`Fan`},[G.MediaPlayer]:{icon:za,label:`Media player`},[G.AlarmPanel]:{icon:_o,label:`Alarm panel`},[G.Control]:{icon:To,label:`Control`},[G.Presence]:{icon:ja,label:`Presence`},[G.Weather]:{icon:Vi,label:`Weather`},[G.Vacuum]:{icon:vi,label:`Vacuum`},[G.LawnMower]:{icon:zo,label:`Lawn mower`},[G.Container]:{icon:yi,label:`Container`},[G.Image]:{icon:va,label:`Image`},[G.PetFeeder]:{icon:_i,label:`Pet feeder`}},xk={[B.Siren]:{icon:So,label:`Siren`},[B.Floodlight]:{icon:Ca,label:`Floodlight`},[B.Spotlight]:{icon:sa,label:`Spotlight`},[B.PirSensor]:{icon:io,label:`PIR sensor`},[B.Chime]:{icon:hi,label:`Chime`},[B.Autotrack]:{icon:Ki,label:`Auto-track`},[B.Nightvision]:{icon:Ba,label:`Night vision`},[B.PrivacyMask]:{icon:ta,label:`Privacy mask`},[B.Doorbell]:{icon:Ji,label:`Doorbell`},[B.BinaryHelper]:{icon:Ro,label:`Binary helper`},[B.MotionSensor]:{icon:la,label:`Motion sensor`},[B.ContactSensor]:{icon:Yi,label:`Contact sensor`},[B.LeakSensor]:{icon:Zi,label:`Leak sensor`},[B.SmokeSensor]:{icon:ei,label:`Smoke sensor`},[B.COSensor]:{icon:es,label:`CO sensor`},[B.GasSensor]:{icon:oa,label:`Gas sensor`},[B.TamperSensor]:{icon:_o,label:`Tamper sensor`},[B.VibrationSensor]:{icon:Jo,label:`Vibration sensor`},[B.ConnectivitySensor]:{icon:$o,label:`Connectivity`},[B.SoundSensor]:{icon:Yo,label:`Sound sensor`},[B.BinarySensor]:{icon:Ro,label:`Binary sensor`},[B.TemperatureSensor]:{icon:Lo,label:`Temperature`},[B.HumiditySensor]:{icon:Qi,label:`Humidity`},[B.AmbientLightSensor]:{icon:No,label:`Ambient light`},[B.PressureSensor]:{icon:fa,label:`Pressure`},[B.WindSensor]:{icon:es,label:`Wind`},[B.RainSensor]:{icon:zi,label:`Rain`},[B.UvSensor]:{icon:Mo,label:`UV index`},[B.SolarRadiationSensor]:{icon:Po,label:`Solar radiation`},[B.SoilMoistureSensor]:{icon:ko,label:`Soil moisture`},[B.PowerSensor]:{icon:is,label:`Power`},[B.EnergySensor]:{icon:is,label:`Energy`},[B.VoltageSensor]:{icon:is,label:`Voltage`},[B.CurrentSensor]:{icon:is,label:`Current`},[B.AirQualitySensor]:{icon:es,label:`Air quality`},[B.BatterySensor]:{icon:fa,label:`Battery`},[B.NumericSensor]:{icon:ha,label:`Numeric sensor`},[B.EnumSensor]:{icon:Ta,label:`Enum sensor`},[B.DateTimeSensor]:{icon:Ii,label:`Date / time`},[B.GenericSensor]:{icon:fa,label:`Sensor`},[B.NumericControl]:{icon:To,label:`Numeric control`},[B.SelectControl]:{icon:wa,label:`Select control`},[B.TextControl]:{icon:Wo,label:`Text control`},[B.DateTimeControl]:{icon:Ii,label:`Date / time control`},[B.MobilePushNotifier]:{icon:Eo,label:`Mobile push`},[B.MessagingNotifier]:{icon:Fa,label:`Messaging`},[B.EmailNotifier]:{icon:Aa,label:`Email`},[B.GenericNotifier]:{icon:hi,label:`Notifier`}},Sk=new Set(Object.values(G)),Ck=new Set(Object.values(B));function wk(e){return Sk.has(e)}function Tk(e){return Ck.has(e)}function Ek(e){return bk[e]}function Dk(e){return xk[e]}var Ok=bk[G.Generic],kk=xk[B.GenericSensor];function Ak(e){return wk(e)?bk[e]??Ok:Ok}function jk(e){return Tk(e)?xk[e]??kk:kk}var Mk={thermometer:Lo,droplets:Qi,droplet:Zi,gauge:fa,sun:No,"sun-medium":Mo,sunrise:Po,moon:Ba,wind:es,"cloud-rain":zi,"cloud-sun":Vi,waves:Zo,sprout:ko,zap:is,flame:oa,bell:hi,siren:So,radar:io,activity:Qr,hash:ha,clock:Ii,gauge2:fa,pipette:Za,fan:ra,bath:ci,footprints:la,"alarm-smoke":ei,"shield-alert":_o,vibrate:Jo,wifi:$o,"volume-2":Yo,lightbulb:Ca,flashlight:sa};function Nk(e){return Object.hasOwn(Mk,e)?Mk[e]:void 0}var Pk=Object.values(G).map(e=>{let t=Ak(e);return{id:e,label:t.label,icon:t.icon}});function Fk(){return Pk}function Ik(e){return e.parentDeviceId===null?`top-level`:e.role?`accessory`:`adopted`}var Lk={minimal:{showIntegrationIcon:!1,showParentBadge:!1,showSnapshot:!1,showBattery:!1,showStableId:!1,showId:!1,showSwitchToggle:!0,showChildrenAccordion:!1},compact:{showIntegrationIcon:!0,showParentBadge:!0,showSnapshot:!0,showBattery:!0,showStableId:!1,showId:!1,showSwitchToggle:!0,showChildrenAccordion:!0},expanded:{showIntegrationIcon:!1,showParentBadge:!0,showSnapshot:!0,showBattery:!0,showStableId:!0,showId:!0,showSwitchToggle:!0,showChildrenAccordion:!0}};function Rk(e){let t=Lk[e.variant??`compact`];return{showIntegrationIcon:e.showIntegrationIcon??t.showIntegrationIcon,showParentBadge:e.showParentBadge??t.showParentBadge,showSnapshot:e.showSnapshot??t.showSnapshot,showBattery:e.showBattery??t.showBattery,showStableId:e.showStableId??t.showStableId,showId:e.showId??t.showId,showSwitchToggle:e.showSwitchToggle??t.showSwitchToggle,showChildrenAccordion:e.showChildrenAccordion??t.showChildrenAccordion}}function zk(e){if(e.display?.icon){let t=Nk(e.display.icon);if(t)return t}return e.role?jk(e.role).icon:Ak(e.type).icon}var Bk=[` — `,` `];function Vk(e,t){if(t.length===0)return e;for(let n of Bk){let r=`${t}${n}`;if(e.startsWith(r))return e.slice(r.length)}return e}function Hk(e,t){return e.display?.label?e.display.label:Vk(e.name,t)}var Uk={"native-snapshot":va,"two-way-audio":Ia,"pan-tilt-zoom":Ki,"ptz-autotrack":Da,"doorbell-button":Yi,"motion-trigger":Qr,"battery-operated":pi,rebootable:co},Wk={"native-snapshot":`Native snapshot`,"two-way-audio":`Two-way audio`,"pan-tilt-zoom":`Pan-Tilt-Zoom`,"ptz-autotrack":`PTZ autotrack`,"doorbell-button":`Doorbell button`,"motion-trigger":`Motion trigger`,"battery-operated":`Battery operated`,rebootable:`Rebootable`},Gk={"native-snapshot":`snapshot`,rebootable:`reboot`,"pan-tilt-zoom":`ptz`,"ptz-autotrack":`ptz-autotrack`,"two-way-audio":`intercom`,"motion-trigger":`motion-trigger`},Kk=new Set([`camera`,`hub`,`nvr`]);function qk(e){return!Kk.has(e.type.toLowerCase())}function Jk(e){return e.role?!0:!Kk.has(e.type.toLowerCase())}function Yk(e){return(e.features??[]).includes(`motion-trigger`)}function Xk(e,t){if(e.type!==G.Container)return e.online;let n=t??[];if(n.length===0)return e.online;let r=yk(n,e.linkDeviceId,e.primaryChildEntityId);if(r===null)return e.online;let i=n.find(e=>e.id===r.id);return i===void 0?e.online:i.online}function Zk(e,t){if(e.type!==G.Container)return e.type;let n=t??[];if(n.length===0)return e.type;let r=yk(n,e.linkDeviceId,e.primaryChildEntityId);if(r===null)return e.type;let i=n.find(e=>e.id===r.id);return i===void 0?e.type:i.type}function Qk(e,t){if(e.type!==G.Container)return e;let n=t??[];if(n.length===0)return e;let r=yk(n,e.linkDeviceId,e.primaryChildEntityId);return r===null?e:n.find(e=>e.id===r.id)??e}function $k(e){if(e.length<=24)return e;let t=e.lastIndexOf(`:`);if(t>=0&&t<e.length-4)return e.slice(t+1);let n=e.split(`-`);if(n.length>2){let e=n.slice(-2).join(`-`);if(e.length>=6)return e}return`…${e.slice(-18)}`}h();function eA(e){return e instanceof Error?e.message:String(e)}function tA({trpc:e,deviceId:t,deviceName:n}){let{dev:r,cap:i}=Q({trpc:e,deviceId:t,cap:e=>e.reboot,slice:()=>void 0}),[a,o]=k(!1),[s,c]=k(!1),[l,u]=k(null);if(r===null||i==null)return null;let d=e=>{e.stopPropagation(),u(null),o(!0)},f=async()=>{if(!s){u(null),c(!0);try{await i.reboot({}),o(!1)}catch(e){u(eA(e))}finally{c(!1)}}};return g(w,{children:[N(`button`,{type:`button`,onClick:d,className:X(`inline-flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,a&&`bg-surface-hover text-foreground`),title:`Reboot device`,"aria-label":`Reboot device`,"aria-haspopup":`dialog`,"aria-expanded":a,children:N(co,{className:`h-3 w-3`})}),N(Ms,{open:a,onOpenChange:e=>{s||o(e)},children:g(Fs,{width:`sm`,onClick:e=>e.stopPropagation(),children:[g(Is,{children:[g(Rs,{className:`flex items-center gap-2`,children:[N(co,{className:`h-4 w-4 text-amber-400`}),`Reboot device?`]}),g(zs,{children:[`This will restart `,n,`. It may be unavailable for a moment.`]})]}),l!==null&&N(`div`,{className:`mt-2 px-3 py-2 rounded border border-danger/40 bg-danger/10 text-xs text-danger`,children:l}),g(Ls,{children:[N(ps,{type:`button`,variant:`ghost`,size:`sm`,disabled:s,onClick:()=>{s||o(!1)},children:`Cancel`}),g(ps,{type:`button`,variant:`danger`,size:`sm`,disabled:s,onClick:()=>{f()},children:[s&&N(Ea,{className:`h-3.5 w-3.5 animate-spin`}),`Reboot`]})]})]})})]})}h();var nA=[],rA=c(null);function iA({value:e,children:t}){return N(rA.Provider,{value:e,children:t})}function aA(e){return p(rA)?.get(e)??nA}h(),rt();var oA=new Set([G.Sensor,G.Presence]);function sA({trpc:e,device:t,controlPlacement:n}){let r=aA(t.id),i=n??`right`;if(t.disabled)return null;if(t.type===G.Container){let n=yk(r,t.linkDeviceId,t.primaryChildEntityId),a=n===null?void 0:r.find(e=>e.id===n.id);return a===void 0?null:N(cA,{trpc:e,child:a,placement:i})}let a=oA.has(t.type),o=(a?null:dk(t.type))?.InlineControl??null,s=fk(t.type,i),c=Yk(t),l=(t.features??[]).includes(`rebootable`),u=(t.features??[]).includes(`pan-tilt-zoom`);return g(w,{children:[a&&g(iu,{align:fk(t.type,i),children:[c&&N(lA,{trpc:e,deviceId:t.id,features:t.features}),N(Gw,{trpc:e,device:t})]}),o!==null&&g(iu,{align:s,onClick:e=>e.stopPropagation(),children:[c&&N(lA,{trpc:e,deviceId:t.id,features:t.features}),N(o,{trpc:e,deviceId:t.id,features:t.features})]}),!a&&o===null&&c&&N(lA,{trpc:e,deviceId:t.id,features:t.features}),u&&N(fA,{trpc:e,deviceId:t.id}),l&&N(tA,{trpc:e,deviceId:t.id,deviceName:t.name})]})}function cA({trpc:e,child:t,placement:n}){if(oA.has(t.type))return N(iu,{align:fk(t.type,n),children:N(Gw,{trpc:e,device:t})});let r=dk(t.type)?.InlineControl??null;return r===null?null:N(iu,{align:fk(t.type,n),onClick:e=>e.stopPropagation(),children:N(r,{trpc:e,deviceId:t.id,features:t.features})})}function lA({trpc:e,deviceId:t,features:n}){let{dev:r,cap:i,slice:a,available:o}=Q({trpc:e,deviceId:t,cap:e=>e.motionTrigger,slice:e=>e.state.motionTrigger,requireFeature:`motion-trigger`,deviceFeatures:n}),[s,c]=k(!1);if(r!==null&&!i)return null;let l=a?.enabled===!0,u=async e=>{if(e.stopPropagation(),!(s||!o||!i)){c(!0);try{await i.setMotionTrigger({enabled:!l})}finally{c(!1)}}};return N(`button`,{type:`button`,onClick:e=>{u(e)},disabled:s||!o,className:X(`inline-flex h-4 w-4 items-center justify-center rounded transition-colors flex-shrink-0`,l?`text-primary bg-primary/10`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,(s||!o)&&`opacity-50`),title:o?l?`Motion-trigger: on (click to disable)`:`Motion-trigger: off (click to enable)`:`Awaiting state…`,"aria-pressed":l,children:N(Qr,{className:`h-2.5 w-2.5`})})}var uA=4,dA=300;function fA({trpc:e,deviceId:t}){let n=f(null),r=f(null),[i,a]=k(null),o=i!==null,s=Ql(e,t,{enabled:o}),c=()=>a(null),l=()=>{let e=n.current;if(!e)return;let t=e.getBoundingClientRect(),r=Math.min(dA,window.innerWidth-16),i=Math.max(8,Math.min(t.right-r,window.innerWidth-r-8)),o=t.bottom+uA;a({top:o,left:i,width:r,maxHeight:Math.max(160,window.innerHeight-o-8)})};return P(()=>{if(!o)return;let e=e=>{let t=n.current,i=r.current,a=e.target;a!==null&&(t&&t.contains(a)||i&&i.contains(a)||c())},t=e=>{e.key===`Escape`&&(e.stopPropagation(),c())};return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e),document.removeEventListener(`keydown`,t)}},[o]),g(w,{children:[N(`button`,{ref:n,type:`button`,onClick:e=>{e.stopPropagation(),o?c():l()},className:X(`inline-flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,o&&`bg-surface-hover text-foreground`),title:`PTZ controls`,"aria-label":`PTZ controls`,"aria-haspopup":`dialog`,"aria-expanded":o,children:N(da,{className:`h-3 w-3`})}),i&&it(N(`div`,{ref:r,style:{position:`fixed`,top:i.top,left:i.left,width:i.width,maxHeight:i.maxHeight},className:`z-[9999] overflow-y-auto rounded-lg border border-border bg-surface shadow-lg shadow-black/30`,onClick:e=>e.stopPropagation(),children:N(eu,{mode:`panel`,controls:s})}),document.body)]})}h();function pA({trpc:e,accessoryChildren:t,adoptedChildren:n,onNavigate:r,parentName:i}){return g(`div`,{className:`border-t border-border-subtle/50`,children:[n.length>0&&N(mA,{trpc:e,label:`Adopted devices`,rows:n,onNavigate:r,parentName:i}),t.length>0&&N(mA,{trpc:e,label:`Accessories`,rows:t,onNavigate:r,parentName:i})]})}function mA({trpc:e,label:t,rows:n,onNavigate:r,parentName:i}){return g(`div`,{children:[N(`div`,{className:`px-3 pt-1.5 pb-1 text-[9px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:t}),N(`ul`,{children:n.map(t=>N(hA,{trpc:e,child:t,onNavigate:r,parentName:i},t.id))})]})}function hA({trpc:e,child:t,onNavigate:n,parentName:r}){let i=!t.disabled,a=i&&qk(t),o=i&&Yk(t);return N(`li`,{children:g(`div`,{onClick:e=>{e.stopPropagation(),n(t.id)},className:`w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-surface-hover transition-colors cursor-pointer`,children:[N(zk(t),{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),N(`span`,{className:`text-[10.5px] text-foreground flex-1 truncate`,children:Hk(t,r)}),o&&N(_A,{trpc:e,deviceId:t.id,features:t.features}),a&&N(gA,{trpc:e,deviceId:t.id}),N(`span`,{className:X(`h-1.5 w-1.5 rounded-full flex-shrink-0`,t.online?`bg-success`:`bg-foreground-subtle/40`),title:t.online?`Online`:`Offline`})]})})}function gA({trpc:e,deviceId:t}){let{dev:n,cap:r,slice:i,available:a}=Q({trpc:e,deviceId:t,cap:e=>e.switch,slice:e=>e.state.switch}),[o,s]=k(!1);if(n!==null&&!r)return null;let c=i?.on===!0,l={transform:c?`translateX(14px)`:`translateX(2px)`},u=async e=>{if(e.stopPropagation(),!(o||!a||!r)){s(!0);try{await r.setState({on:!c})}finally{s(!1)}}};return N(`button`,{type:`button`,onClick:e=>{u(e)},disabled:o||!a,className:X(`relative inline-flex h-4 w-7 items-center rounded-full border transition-colors flex-shrink-0`,c?`bg-success/30 border-success/50`:`bg-surface-hover border-border`,o&&`opacity-60`,!a&&`opacity-40 cursor-not-allowed`),title:a?c?`Turn off`:`Turn on`:`Awaiting state…`,"aria-pressed":c,children:N(`span`,{className:X(`absolute h-3 w-3 rounded-full transition-all`,c?`bg-success`:`bg-foreground-subtle`),style:l})})}function _A({trpc:e,deviceId:t,features:n}){let{dev:r,cap:i,slice:a,available:o}=Q({trpc:e,deviceId:t,cap:e=>e.motionTrigger,slice:e=>e.state.motionTrigger,requireFeature:`motion-trigger`,deviceFeatures:n}),[s,c]=k(!1);if(r!==null&&!i)return null;let l=a?.enabled===!0,u=async e=>{if(e.stopPropagation(),!(s||!o||!i)){c(!0);try{await i.setMotionTrigger({enabled:!l})}finally{c(!1)}}};return N(`button`,{type:`button`,onClick:e=>{u(e)},disabled:s||!o,className:X(`inline-flex h-4 w-4 items-center justify-center rounded transition-colors flex-shrink-0`,l?`text-primary bg-primary/10`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,(s||!o)&&`opacity-50`),title:o?l?`Motion-trigger: on (click to disable)`:`Motion-trigger: off (click to enable)`:`Awaiting state…`,"aria-pressed":l,children:N(Qr,{className:`h-2.5 w-2.5`})})}function vA({icon:e,label:t,onClick:n,danger:r=!1}){return N(`button`,{type:`button`,"aria-label":t,title:t,onClick:n,className:X(`inline-flex h-6 w-6 items-center justify-center rounded transition-colors flex-shrink-0`,r?`text-danger hover:bg-danger/10`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`),children:N(e,{className:`h-3.5 w-3.5`})})}function yA({device:e,onDelete:t}){let n=Cl(),r=async()=>{await n({title:`Delete device?`,message:`This will remove "${e.name.trim()===``?`#${String(e.id)}`:e.name}" and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&t(e)};return N(`span`,{onClick:e=>e.stopPropagation(),children:N(vA,{icon:Bo,label:`Delete device`,danger:!0,onClick:()=>{r()}})})}h();var bA=Object.freeze([]);function xA(e){return e===`native`?`native`:`enhanced`}function SA(e){return e.map(e=>({kind:`marker`,feature:e}))}function CA(e,t){let n=new Map,r=t.entries??[];for(let e of r)n.set(e.capName,e);let i=[];for(let t of e){let e=Gk[t];if(e===void 0){i.push({kind:`marker`,feature:t});continue}let r=n.get(e);r&&i.push({kind:xA(r.kind),feature:t,capName:e})}return i}function wA(e,t,n){let[r,i]=k(null),[a,o]=k(!1),[s,c]=k(!0);return P(()=>{if(t===null){i(null),o(!1),c(!1);return}let n=!1;c(!0),o(!1);let r=async()=>{try{let r=await e.deviceManager.getBindings.query({deviceId:t});if(n)return;i(r),c(!1)}catch{if(n)return;o(!0),c(!1)}};r();let a=e.live?.onEvent.subscribe({category:`capability.binding-changed`},{onData:e=>{let n=e.data?.source;if(!n){r();return}n.type===`device`&&n.id===t&&r()}});return()=>{n=!0,a?.unsubscribe()}},[e,t]),n.length===0?{loading:s,resolved:bA}:s||a||!r?{loading:s,resolved:SA(n)}:{loading:!1,resolved:CA(n,r)}}h(),rt();var TA=[];function EA({trpc:e,device:t,flags:n,accessoryCount:r,adoptedCount:i,showFeatureRow:a=!1}){let o=r+i,s=n.showChildrenAccordion&&o>0,c=t.features??TA,l=a&&c.length>0,{resolved:u}=wA(e,l?t.id:null,c),d=l&&u.length>0;return!s&&!d?null:g(`div`,{className:`flex items-center gap-1.5 flex-nowrap whitespace-nowrap min-w-0`,children:[s&&N(DA,{accessoryCount:r,adoptedCount:i}),d&&N(AA,{resolved:u})]})}function DA({accessoryCount:e,adoptedCount:t}){let n=e+t;return n===0?null:g(`span`,{className:`text-[9px] font-medium text-foreground-subtle bg-surface-elevated/60 rounded px-1.5 py-0.5 flex-shrink-0`,title:t>0&&e>0?`${String(t)} adopted · ${String(e)} accessor${e===1?`y`:`ies`}`:t>0?`${String(t)} adopted`:`${String(e)} accessor${e===1?`y`:`ies`}`,children:[`+`,n]})}var OA=240,kA=200;function AA({resolved:e}){let t=f(null),[n,r]=k(null);return g(`span`,{ref:t,className:`relative inline-flex items-center gap-1 cursor-help`,onMouseEnter:()=>{let e=t.current;if(!e)return;let n=e.getBoundingClientRect();r({top:window.innerHeight-n.bottom>=kA?n.bottom+4:n.top-kA-4,left:Math.max(8,Math.min(n.left,window.innerWidth-OA-8))})},onMouseLeave:()=>r(null),children:[e.map(e=>{let t=Uk[e.feature];return t?N(`span`,{className:`inline-flex items-center justify-center h-4 w-4 rounded bg-surface-elevated/60 text-foreground-subtle`,title:Wk[e.feature]??e.feature,children:N(t,{className:`h-2.5 w-2.5`})},e.feature):null}),n&&it(N(jA,{resolved:e,position:n}),document.body)]})}function jA({resolved:e,position:t}){return g(`div`,{style:{position:`fixed`,top:t.top,left:t.left,width:OA,pointerEvents:`none`},className:`z-[9999] rounded-md border border-border bg-surface shadow-lg shadow-black/30 p-2`,children:[N(`h5`,{className:`text-[9px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5`,children:`Features`}),N(`ul`,{className:`space-y-0.5`,children:e.map(e=>N(MA,{entry:e},e.feature))})]})}function MA({entry:e}){let t=Uk[e.feature],n=Wk[e.feature]??e.feature;return g(`li`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[g(`span`,{className:`flex items-center gap-1.5 text-foreground`,children:[t&&N(t,{className:`h-3 w-3 text-foreground-subtle`}),N(`span`,{children:n})]}),N(NA,{kind:e.kind})]})}function NA({kind:e}){return e===`marker`?N(`span`,{className:`text-[8.5px] px-1 rounded text-foreground-subtle`,title:`Informational marker (no cap registered)`,children:`marker`}):N(`span`,{className:X(`text-[8.5px] px-1 rounded`,e===`native`?`bg-success/15 text-success`:`bg-primary/15 text-primary`),children:e})}var PA={horizontal:`h-3.5 w-3.5`,stacked:`h-4 w-4 mt-0.5`};function FA({device:e,variant:t,flags:n,parent:r,integrationIcon:i,hasChildren:a,expanded:o,onToggleExpand:s,onNavigateToParent:c,stacked:l=!1}){let u=zk(Qk(e,aA(e.id))),d=l?PA.stacked:PA.horizontal;return g(`div`,{className:X(l?`flex items-start gap-2 w-full min-w-0`:`flex items-center gap-2 flex-1 min-w-0`),children:[n.showChildrenAccordion&&a?N(`button`,{type:`button`,"data-testid":`chevron-slot`,onClick:e=>{e.stopPropagation(),s()},className:X(`flex items-center justify-center text-foreground-subtle hover:text-foreground transition-colors flex-shrink-0`,d),"aria-label":o?`Collapse children`:`Expand children`,"aria-expanded":o,children:N(o?Re:Ue,{className:`h-3 w-3`})}):n.showChildrenAccordion?N(`span`,{"data-testid":`chevron-slot`,className:X(`flex-shrink-0`,d)}):null,N(u,{className:X(`text-foreground-subtle flex-shrink-0`,l?`h-4 w-4 mt-0.5`:t===`minimal`?`h-3 w-3`:`h-3.5 w-3.5`)}),g(`div`,{className:`flex-1 min-w-0`,children:[g(`div`,{className:X(`min-w-0`,l?`flex flex-col gap-1`:`flex items-center gap-1.5`),children:[n.showIntegrationIcon&&i&&N(`span`,{className:`flex-shrink-0`,children:i}),N(`span`,{className:X(`font-semibold text-foreground`,l?`text-[13px] leading-snug line-clamp-2 break-words`:X(`truncate`,t===`minimal`?`text-[10.5px]`:`text-[11px]`)),title:e.name,children:e.name})]}),(n.showId||n.showStableId)&&g(`div`,{className:`mt-0.5 flex items-center gap-1 text-[9px] text-foreground-subtle font-mono truncate`,title:n.showStableId?`stableId: ${e.stableId}`:void 0,children:[n.showId&&g(`span`,{className:`flex-shrink-0 tabular-nums`,children:[`#`,String(e.id)]}),n.showId&&n.showStableId&&N(`span`,{className:`flex-shrink-0 opacity-50`,children:`·`}),n.showStableId&&N(`span`,{className:`truncate`,children:$k(e.stableId)})]}),n.showParentBadge&&r&&g(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c(r.id)},className:`mt-0.5 inline-flex max-w-full items-center gap-1 text-[9px] text-foreground-subtle hover:text-primary transition-colors`,title:`Open parent: ${r.name} (#${String(r.id)})`,children:[N(qa,{className:`h-2.5 w-2.5 shrink-0`}),g(`span`,{className:`truncate`,children:[`Under: `,r.name]})]})]})]})}function IA(e,t){return He(e,t,e=>e.battery)??null}h();function LA(e,t){let n=Fe(e,t),r=f(!1),{data:i,isLoading:a,isFetching:o,refetch:s}=C({queryKey:[`device`,t,`snapshot`],queryFn:()=>{if(!n)throw Error(`useDeviceSnapshotImage: device proxy not ready`);let e=r.current;return r.current=!1,n.snapshot?.getSnapshot({force:e})??null},enabled:n!==null&&t!==null,staleTime:1e4,gcTime:1440*60*1e3,refetchOnWindowFocus:!1,refetchOnReconnect:!1,retry:!1}),c=i?`data:${i.contentType};base64,${i.base64}`:null;function l(){r.current=!0,s()}return{src:c,loading:a||o,refresh:l}}var RA=50;function zA(e){return e<=10?fi:e<=30?ui:e<=70?di:li}function BA(e,t){return t===`none`?e<=10?`text-rose-400`:e<=30?`text-amber-400`:`text-foreground-subtle`:`text-emerald-400`}function VA({status:e,variant:t=`compact`,className:n}){if(!e)return null;if(e.binary===!0){let t=e.percentage<RA,r=t?fi:li;return g(`span`,{className:X(`inline-flex items-center gap-1 text-[10px] font-medium`,t?`text-rose-400`:`text-foreground-subtle`,n),title:`Battery: ${t?`low`:`normal`}`,children:[N(r,{className:`h-3.5 w-3.5`}),N(`span`,{children:t?`Low`:`Normal`})]})}let r=zA(e.percentage),i=BA(e.percentage,e.charging),a=e.charging===`solar`?No:e.charging===`dc`?eo:null,o=e.sleeping;return g(`span`,{className:X(`inline-flex items-center gap-1 text-[10px] font-medium`,i,n),title:`Battery: ${Math.round(e.percentage)}%`+(e.charging===`none`?``:` · charging (${e.charging})`)+(e.sleeping?` · sleeping`:``),children:[N(r,{className:`h-3.5 w-3.5`}),g(`span`,{children:[Math.round(e.percentage),`%`]}),a&&N(a,{className:`h-3 w-3`}),o&&N(Ba,{className:`h-3 w-3 text-blue-300`}),t===`full`&&e.charging!==`none`&&N(`span`,{className:`text-foreground-subtle`,children:e.charging})]})}h(),rt();var HA=288,UA=196,WA=`h-7 w-7 rounded`,GA=8,KA=8;function qA({src:e,alt:t,caption:n,placeholder:r=`No image`,thumbClassName:i=WA,expandedWidth:a=HA,expandedHeight:o=UA}){let s=f(null),[c,l]=k(null),[d,p]=k(!1);P(()=>{p(!1)},[e]);let m=e!==null&&!d,h=e??void 0,_=u(()=>{let e=s.current;if(!e)return;let t=e.getBoundingClientRect(),n=t.top,r=window.innerHeight-t.bottom,i=n<o+GA&&r>n?t.bottom+GA:t.top-o-GA,c=t.right-a;l({top:i,left:Math.max(KA,Math.min(c,window.innerWidth-a-KA))})},[a,o]),v=u(()=>l(null),[]);return g(w,{children:[N(`button`,{ref:s,type:`button`,onClick:e=>e.stopPropagation(),onMouseEnter:_,onMouseLeave:v,onFocus:_,onBlur:v,"aria-label":t,className:`flex flex-shrink-0 items-center justify-center overflow-hidden border border-border bg-background text-foreground-subtle transition-colors hover:bg-surface-hover ${i}`,children:m?N(`img`,{src:h,alt:``,onError:()=>p(!0),className:`h-full w-full object-cover`}):N(_a,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})}),c&&it(g(`div`,{"aria-hidden":`true`,style:{position:`fixed`,top:c.top,left:c.left,width:a,pointerEvents:`none`},className:`z-[9999] overflow-hidden rounded-lg border border-border bg-surface shadow-lg shadow-black/30`,children:[N(`div`,{className:`flex h-40 items-center justify-center bg-background`,children:m?N(`img`,{src:h,alt:t,className:`h-full w-full object-cover`}):N(`span`,{className:`text-xs text-foreground-subtle`,children:r})}),N(`div`,{className:`px-3 py-2`,children:N(`p`,{className:`truncate text-xs font-semibold text-foreground`,children:n??t})})]}),document.body)]})}function JA({trpc:e,device:t,status:n,enabled:r,showStatusPills:i=!1}){let a=LA(e,r&&t.online?t.id:null),o=(t.features??[]).includes(`battery-operated`),s=i&&o&&!t.disabled,c=IA(e,s?t.id:null);if(!r&&!s)return null;let l=n===`offline`||n===`disabled`,u=n===`offline`?`Offline — no snapshot`:n===`disabled`?`Disabled`:`No snapshot yet`;return g(`span`,{className:`inline-flex items-center gap-1.5 flex-nowrap whitespace-nowrap`,children:[s&&c&&N(VA,{status:c}),r&&N(qA,{src:l?null:a.src,alt:t.name,placeholder:u,thumbClassName:`h-7 w-7 rounded`})]})}function YA(e,t){if(e===`disabled`)return`Disabled`;if(e===`online`)return`Online`;let n=mr(t);return n===null?`Offline`:`Offline · last seen ${n}`}function XA({status:e,lastChangedAt:t}){return N(`span`,{className:X(`h-1.5 w-1.5 rounded-full flex-shrink-0`,e===`disabled`?`bg-warning`:e===`online`?`bg-success`:`bg-danger`),title:YA(e,t)})}var ZA=`Disabled`;function QA(e,t,n){let r=t.filter(e=>e.disabled!==!0),i=$A(t.filter(e=>e.disabled===!0));if(n===void 0||n.length===0)return{sections:[],ungrouped:r,disabledSection:i};let a=new Map;for(let e of r)a.set(e.stableId,e);let o=[],s=new Map,c=new Set;for(let t of n){let n=`${e}-${t.childKey}`,r=a.get(n);if(r===void 0)continue;let i=s.get(t.section);i===void 0&&(i={title:t.section,entries:[],collapsed:!1},s.set(t.section,i),o.push(t.section)),i.entries.push({child:r,order:t.order??2**53-1}),t.collapsed===!0&&(i.collapsed=!0),c.add(r.id)}return{sections:o.map(e=>{let t=s.get(e),n=[...t===void 0?[]:t.entries].toSorted((e,t)=>e.order===t.order?e.child.name.localeCompare(t.child.name):e.order-t.order),r=t===void 0?!0:!t.collapsed;return{title:e,children:n.map(e=>e.child),defaultOpen:r}}),ungrouped:r.filter(e=>!c.has(e.id)),disabledSection:i}}function $A(e){if(e.length!==0)return{title:ZA,children:[...e].toSorted((e,t)=>e.name.localeCompare(t.name)),defaultOpen:!1,muted:!0}}h();function ej({title:e,count:t,children:n,defaultOpen:r=!0}){let[i,a]=k(r);return g(`div`,{className:`rounded-md border border-border-subtle/50`,children:[g(`button`,{type:`button`,onClick:()=>a(e=>!e),className:X(`w-full flex items-center gap-1.5 px-2 py-1.5 text-left transition-colors`,`hover:bg-surface-hover`),"aria-expanded":i,children:[N(i?Re:Ue,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),N(`span`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle flex-1 truncate`,children:e}),N(`span`,{className:`text-[10px] font-medium text-foreground-subtle/70 tabular-nums`,children:t})]}),i&&N(`div`,{className:`space-y-1 px-1 pb-1.5`,children:n})]})}h();function tj(e){let{trpc:t,device:n,parent:r,integrationIcon:i,onNavigate:a,className:o,renderRowAction:s,onDelete:c,selection:l}=e,u=Rk(e),d=e.variant??`compact`,f=e.view??`card`,p=!n.disabled,m=n.isCamera??n.type.toLowerCase()===`camera`,h=e.children??[],_=h.filter(Jk),v=h.filter(e=>!Jk(e)),y=h.length>0,[b,x]=k(!1),S=e.expanded??b,C=e.onToggleExpand??(()=>x(e=>!e)),w=e=>{a?.(e)},T=e.rowClickSelects===!0&&l!==void 0,E=()=>{if(T&&l!==void 0){l.onToggle();return}w(n.id)},D=e.indentLevel??(e.isAccessoryRow?2:0),O=Xk(n,h),A=p?O?`online`:`offline`:`disabled`;return f===`table`?N(rj,{trpc:t,device:n,variant:d,flags:u,parent:r??null,integrationIcon:i??null,accessoryCount:_.length,adoptedCount:v.length,hasChildren:y,expanded:S,onToggleExpand:C,onRowClick:E,rowSelects:T,rowSelected:l?.selected??!1,onNavigate:w,displayStatus:A,isCamera:m,showSnapshot:u.showSnapshot&&m,isAccessoryRow:e.isAccessoryRow??!1,indentLevel:D,className:o,renderRowAction:s??null,onDelete:c??null,selection:l,showTypeCell:e.showTypeCell??!0,showManufacturerCell:e.showManufacturerCell??!0,showFeaturesCell:e.showFeaturesCell??!0}):d===`minimal`?g(`div`,{className:X(`rounded-lg border border-border bg-surface transition-colors`,!p&&`opacity-60`,o),children:[g(`div`,{"data-testid":`device-card-body`,onClick:E,...T?{role:`button`,"aria-pressed":l?.selected??!1,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),E())}}:{},className:X(`flex items-center gap-2 cursor-pointer hover:border-foreground-subtle/30 w-full px-2.5 py-1.5`,l?.selected&&`bg-primary/10`),children:[l&&N(`input`,{type:`checkbox`,checked:l.selected,onChange:l.onToggle,onClick:e=>e.stopPropagation(),"aria-label":`Select ${n.name}`,className:`flex-shrink-0`}),N(FA,{device:n,variant:d,flags:u,parent:r??null,integrationIcon:i??null,hasChildren:y,expanded:S,onToggleExpand:C,onNavigateToParent:w}),N(EA,{trpc:t,device:n,flags:u,accessoryCount:_.length,adoptedCount:v.length,showFeatureRow:!1}),N(JA,{trpc:t,device:n,status:A,enabled:u.showSnapshot&&m,showStatusPills:!0}),N(sA,{trpc:t,device:n,flags:u,controlPlacement:`right`}),s&&N(`span`,{onClick:e=>e.stopPropagation(),children:s(n)}),N(XA,{status:A})]}),S&&y&&N(pA,{trpc:t,accessoryChildren:_,adoptedChildren:v,onNavigate:w,parentName:n.name})]}):g(`div`,{className:X(`group rounded-xl border border-border bg-surface transition-colors`,`hover:border-foreground-subtle/30`,!p&&`opacity-60`,o),children:[g(`div`,{"data-testid":`device-card-body`,onClick:E,...T?{role:`button`,"aria-pressed":l?.selected??!1,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),E())}}:{},className:X(`flex flex-col gap-2 cursor-pointer w-full p-3 rounded-xl`,l?.selected&&`bg-primary/10`),children:[g(`div`,{className:`flex items-start justify-between gap-2`,children:[l&&N(`input`,{type:`checkbox`,checked:l.selected,onChange:l.onToggle,onClick:e=>e.stopPropagation(),"aria-label":`Select ${n.name}`,className:`flex-shrink-0 mt-0.5`}),N(FA,{device:n,variant:d,flags:u,parent:r??null,integrationIcon:i??null,hasChildren:y,expanded:S,onToggleExpand:C,onNavigateToParent:w,stacked:!0}),N(XA,{status:A})]}),N(EA,{trpc:t,device:n,flags:u,accessoryCount:_.length,adoptedCount:v.length,showFeatureRow:!1}),g(`div`,{className:`flex items-center justify-end gap-1.5`,children:[N(JA,{trpc:t,device:n,status:A,enabled:u.showSnapshot&&m,showStatusPills:!0}),N(sA,{trpc:t,device:n,flags:u,controlPlacement:`right`}),s&&N(`span`,{onClick:e=>e.stopPropagation(),children:s(n)})]})]}),S&&y&&N(pA,{trpc:t,accessoryChildren:_,adoptedChildren:v,onNavigate:w,parentName:n.name})]})}var nj={0:`pl-2`,1:`pl-6`,2:`pl-8`};function rj(e){let{trpc:t,device:n,variant:r,flags:i,parent:a,integrationIcon:o,accessoryCount:s,adoptedCount:c,hasChildren:l,expanded:u,onToggleExpand:d,onNavigate:f,onRowClick:p,rowSelects:m,rowSelected:h,displayStatus:_,isCamera:v,showSnapshot:y,isAccessoryRow:b,indentLevel:x,className:S,renderRowAction:C,onDelete:w,selection:T,showTypeCell:E,showManufacturerCell:D,showFeaturesCell:O}=e,k=aA(n.id);return g(`tr`,{onClick:p,...m?{role:`button`,"aria-pressed":h,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),p())}}:{},className:X(`group cursor-pointer hover:bg-surface-hover transition-colors`,!l&&`border-b border-border-subtle/40`,b&&`bg-foreground-subtle/[0.03]`,h&&`bg-primary/10`,S),children:[N(`td`,{className:X(`sticky left-0 z-[1] py-1.5 align-middle pr-2 transition-colors`,h?`bg-primary/10 group-hover:bg-surface-hover`:b?`bg-surface-subtle group-hover:bg-surface-hover`:`bg-surface group-hover:bg-surface-hover`,`w-64 max-w-[16rem] min-w-0 overflow-hidden`,nj[x]),children:g(`div`,{className:`flex items-center gap-1.5`,children:[T&&N(`input`,{type:`checkbox`,checked:T.selected,onChange:T.onToggle,onClick:e=>e.stopPropagation(),"aria-label":`Select ${n.name}`,className:`flex-shrink-0`}),N(FA,{device:n,variant:r,flags:i,parent:a,integrationIcon:o,hasChildren:l,expanded:u,onToggleExpand:d,onNavigateToParent:f})]})}),E&&N(`td`,{className:X(zl.type,`px-2 py-1.5 align-middle text-[10px] text-foreground-subtle whitespace-nowrap`),children:Zk(n,k)}),D&&N(`td`,{className:X(zl.manufacturer,`px-2 py-1.5 align-middle w-40 max-w-[10rem] min-w-0 overflow-hidden`),children:N(Xl,{device:n})}),O&&N(`td`,{className:X(zl.features,`px-2 py-1.5 align-middle`),children:N(EA,{trpc:t,device:n,flags:i,accessoryCount:s,adoptedCount:c,showFeatureRow:!0})}),N(`td`,{className:`px-2 py-1.5 align-middle text-right whitespace-nowrap`,children:g(`span`,{className:`inline-flex items-center justify-end gap-1.5`,children:[N(sA,{trpc:t,device:n,flags:i,controlPlacement:`table`}),N(JA,{trpc:t,device:n,status:_,enabled:y&&v,showStatusPills:!0}),C&&N(`span`,{onClick:e=>e.stopPropagation(),children:C(n)}),w&&N(yA,{device:n,onDelete:w}),N(XA,{status:_})]})})]})}h();function ij({selectedIds:e,onClear:t,remove:n,disable:r,enable:i}){let[a,o]=k(!1);if(e.size===0)return null;let s=[...e],c=s.length;return g(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg border border-border bg-surface-hover`,children:[g(`span`,{className:`text-xs font-medium text-foreground-subtle shrink-0`,children:[c,` selected`]}),N(`div`,{className:`h-3.5 w-px bg-border shrink-0`,"aria-hidden":`true`}),g(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[N(`button`,{type:`button`,onClick:()=>{for(let e of s)r({deviceId:e});t()},className:X(`inline-flex items-center h-6 px-2.5 rounded-md border text-[10.5px] font-medium transition-colors`,`border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface`),children:`Disable`}),N(`button`,{type:`button`,onClick:()=>{for(let e of s)i({deviceId:e});t()},className:X(`inline-flex items-center h-6 px-2.5 rounded-md border text-[10.5px] font-medium transition-colors`,`border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface`),children:`Enable`}),a?g(w,{children:[g(`button`,{type:`button`,onClick:()=>{for(let e of s)n({deviceId:e});o(!1),t()},className:X(`inline-flex items-center h-6 px-2.5 rounded-md border text-[10.5px] font-medium transition-colors`,`border-red-500/50 bg-red-500/10 text-red-400 hover:bg-red-500/20`),children:[`Confirm delete `,c,`?`]}),N(`button`,{type:`button`,onClick:()=>{o(!1)},className:X(`inline-flex items-center h-6 px-2.5 rounded-md border text-[10.5px] font-medium transition-colors`,`border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface`),children:`Cancel`})]}):N(`button`,{type:`button`,onClick:()=>{o(!0)},className:X(`inline-flex items-center h-6 px-2.5 rounded-md border text-[10.5px] font-medium transition-colors`,`border-red-500/40 bg-red-500/10 text-red-400 hover:bg-red-500/20`),children:`Delete`}),N(`button`,{type:`button`,onClick:()=>{o(!1),t()},className:X(`inline-flex items-center h-6 px-2.5 rounded-md border text-[10.5px] font-medium transition-colors`,`border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface`),children:`Clear`})]})]})}h();function aj(e){let[t,n]=k(!1),r=f(null),i=e.selectedIds.size;return P(()=>{if(!t)return;let e=e=>{let t=e.target instanceof Node?e.target:null;t&&r.current&&!r.current.contains(t)&&n(!1)},i=e=>{e.key===`Escape`&&n(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e),document.addEventListener(`keydown`,i),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e),document.removeEventListener(`keydown`,i)}},[t]),i===0?null:g(w,{children:[N(`div`,{className:`hidden sm:block`,children:N(ij,{...e})}),g(`div`,{ref:r,"data-testid":`batch-actions-compact`,className:`relative sm:hidden`,children:[g(`button`,{type:`button`,onClick:()=>n(e=>!e),"aria-haspopup":`menu`,"aria-expanded":t,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full border border-primary/40 bg-primary/15 text-[10.5px] font-medium text-primary`,children:[g(`span`,{children:[`Actions · `,String(i)]}),N(Re,{className:`h-3 w-3 transition-transform ${t?`rotate-180`:``}`})]}),t&&N(`div`,{role:`menu`,className:`absolute left-0 top-full mt-1 z-30 rounded-lg border border-border bg-surface shadow-md`,children:N(ij,{...e})})]})]})}h();function oj(e,t){let[n,r]=k(e);return P(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}h();var sj=[25,50,100,200],cj=`camstack.device-list.pageSize`;function lj(e){return sj.includes(e)}function uj(e){return lj(e)?e:50}function dj(e){if(typeof window>`u`)return e;try{let t=window.localStorage.getItem(cj);if(t===null)return e;let n=Number.parseInt(t,10);return Number.isFinite(n)&&lj(n)?n:e}catch{return e}}function fj(e){if(!(typeof window>`u`))try{window.localStorage.setItem(cj,String(e))}catch{}}function pj(e){let t=uj(e),[n,r]=k(()=>dj(t));return[n,u(e=>{lj(e)&&(r(e),fj(e))},[])]}function mj(e){let t=new Map;for(let n of e)t.set(n.id,n);return e.filter(e=>{if(e.parentDeviceId===null||e.parentDeviceId===void 0)return!0;let n=t.get(e.parentDeviceId);return n?hj.has(n.type.toLowerCase()):!0})}var hj=new Set([`hub`,`nvr`]);function gj(e,t){let n=t?.includeHidden??!1,r=new Map;for(let t of e)r.set(t.id,t);let i=[],a=new Map;for(let t of e){if(!n&&t.display?.hidden===!0)continue;let e=t.parentDeviceId;if(e==null){i.push(t);continue}let o=r.get(e);if(!o){i.push(t);continue}let s=t.role!==null&&t.role!==void 0;if(hj.has(o.type)&&!s){i.push(t);continue}let c=a.get(e);c?c.push(t):a.set(e,[t])}return{topLevel:i,accessoriesByParent:a}}function _j(e){return e.toLowerCase().replace(/[-_\s]+/g,``)}function vj(e,t){let n=_j(e);return n===``?!0:_j(t).includes(n)}var yj=2;function bj(e,t){if(t<=1)return[{kind:`page`,n:1}];if(t<=7){let e=[];for(let n=1;n<=t;n++)e.push({kind:`page`,n});return e}let n=[],r=Math.max(2,e-yj),i=Math.min(t-1,e+yj);n.push({kind:`page`,n:1}),r>2&&n.push({kind:`ellipsis`,side:`left`});for(let e=r;e<=i;e++)n.push({kind:`page`,n:e});return i<t-1&&n.push({kind:`ellipsis`,side:`right`}),n.push({kind:`page`,n:t}),n}function xj({currentPage:e,totalItems:t,pageSize:n,onPageChange:r,itemNoun:i=`devices`}){if(t<=n)return null;let a=Math.ceil(t/n),o=(e-1)*n+1,s=Math.min(e*n,t),c=bj(e,a);return g(`div`,{className:`flex items-center justify-between gap-4 flex-wrap pt-2 text-[11px] text-foreground-subtle`,children:[g(`span`,{children:[`Showing `,o,`–`,s,` of `,t,` `,i]}),g(`span`,{className:`inline-flex items-center gap-1`,children:[N(`button`,{type:`button`,"aria-label":`Previous page`,disabled:e===1,onClick:()=>r(e-1),className:X(`inline-flex items-center justify-center h-7 w-7 rounded border border-border bg-surface text-foreground-subtle`,`hover:text-foreground hover:bg-surface-hover transition-colors`,`disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-surface`),children:N(wi,{className:`h-3 w-3`})}),c.map((t,n)=>t.kind===`ellipsis`?N(`span`,{className:`px-1 text-foreground-subtle/60 select-none`,children:`…`},`e-${n}`):N(`button`,{type:`button`,onClick:()=>r(t.n),className:X(`inline-flex items-center justify-center h-7 min-w-7 px-1.5 rounded border text-[10.5px] font-medium transition-colors`,t.n===e?`border-primary/40 bg-primary/10 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover`),children:t.n},`p-${t.n}`)),N(`button`,{type:`button`,"aria-label":`Next page`,disabled:e===a,onClick:()=>r(e+1),className:X(`inline-flex items-center justify-center h-7 w-7 rounded border border-border bg-surface text-foreground-subtle`,`hover:text-foreground hover:bg-surface-hover transition-colors`,`disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-surface`),children:N(Ue,{className:`h-3 w-3`})})]})]})}h();function Sj({label:e,options:t,selected:n,onChange:r}){let[i,a]=k(!1),o=f(null);P(()=>{if(!i)return;let e=e=>{let t=e.target instanceof Node?e.target:null;t&&o.current&&!o.current.contains(t)&&a(!1)},t=e=>{e.key===`Escape`&&a(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e),document.removeEventListener(`keydown`,t)}},[i]);let s=new Set(n),c=n.length,l=e=>{let n=new Set(s);n.has(e)?n.delete(e):n.add(e),r(t.filter(e=>n.has(e.id)).map(e=>e.id))};return g(`div`,{ref:o,className:`relative`,children:[g(`button`,{type:`button`,onClick:()=>a(e=>!e),"aria-haspopup":`listbox`,"aria-expanded":i,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full border text-[10.5px] font-medium transition-colors ${c>0?`border-primary/40 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[g(`span`,{children:[e,c>0?` · ${String(c)}`:``]}),N(Re,{className:`h-3 w-3 transition-transform ${i?`rotate-180`:``}`})]}),i&&g(`div`,{role:`listbox`,className:`absolute left-0 top-full mt-1 z-30 min-w-[180px] max-h-72 overflow-y-auto rounded-lg border border-border bg-surface shadow-xl py-1`,children:[c>0&&N(`button`,{type:`button`,onClick:()=>r([]),className:`flex w-full items-center px-3 py-1.5 text-left text-[10.5px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:`Clear selection`}),t.map(e=>{let t=s.has(e.id),n=e.icon;return g(`button`,{type:`button`,role:`option`,"aria-selected":t,onClick:()=>l(e.id),className:`flex w-full items-center gap-2 px-3 py-1.5 text-left text-[10.5px] text-foreground hover:bg-surface-hover`,children:[N(`span`,{className:`flex h-3.5 w-3.5 items-center justify-center rounded border shrink-0 ${t?`border-primary bg-primary`:`border-border`}`,children:t&&N(Ci,{className:`h-2.5 w-2.5 text-primary-foreground`})}),n&&N(n,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),N(`span`,{className:`truncate`,children:e.label})]},e.id)})]})]})}h();function Cj({label:e,options:t,selected:n,onChange:r}){let i=f(null),[a,o]=k(null);P(()=>{let e=i.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(e=>{let t=e[0];t&&o(t.contentRect.width)});return t.observe(e),()=>t.disconnect()},[]);let s=new Set(n),c=e=>{let n=new Set(s);n.has(e)?n.delete(e):n.add(e),r(t.filter(e=>n.has(e.id)).map(e=>e.id))},l=56+t.length*88;return N(`div`,{ref:i,className:`min-w-0 flex-1`,children:a!==null&&a>=l?g(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[N(`span`,{className:`text-[10px] font-medium uppercase tracking-wider text-foreground-subtle`,children:e}),t.map(e=>{let t=s.has(e.id),n=e.icon;return g(`button`,{type:`button`,onClick:()=>c(e.id),"aria-pressed":t,className:`inline-flex items-center gap-1 h-7 px-2.5 rounded-full border text-[10.5px] font-medium transition-colors ${t?`border-primary/40 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[n&&N(n,{className:`h-3 w-3 shrink-0`}),e.label]},e.id)})]}):N(Sj,{label:e,options:t,selected:n,onChange:r})})}h();function wj({view:e,onViewChange:t,hideView:n=!1,typeOptions:r,selectedTypes:i,onTypesChange:a,addons:o,selectedAddons:s,onAddonsChange:c,hideAddons:l=!1}){return g(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[!n&&e!==void 0&&t!==void 0&&g(`span`,{className:`inline-flex border border-border rounded-md overflow-hidden`,children:[N(`button`,{type:`button`,onClick:()=>t(`cards`),className:X(`inline-flex items-center justify-center h-7 w-8 transition-colors`,e===`cards`?`bg-primary/10 text-primary`:`bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover`),"aria-label":`Cards view`,children:N(xa,{className:`h-3.5 w-3.5`})}),N(`button`,{type:`button`,onClick:()=>t(`table`),className:X(`inline-flex items-center justify-center h-7 w-8 border-l border-border transition-colors`,e===`table`?`bg-primary/10 text-primary`:`bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover`),"aria-label":`Table view`,children:N(Fo,{className:`h-3.5 w-3.5`})})]}),r&&r.length>0&&N(Cj,{label:`Type`,options:r,selected:i,onChange:a}),!l&&o&&o.length>0&&N(Tj,{addons:o,selected:s,onChange:c})]})}function Tj({addons:e,selected:t,onChange:n}){let[r,i]=k(!1),a=f(null);P(()=>{if(!r)return;let e=e=>{let t=e.target;t&&a.current&&!a.current.contains(t)&&i(!1)},t=e=>{e.key===`Escape`&&i(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e),document.removeEventListener(`keydown`,t)}},[r]);let o=new Set(t),s=t.length,c=t=>{let r=new Set(o);r.has(t)?r.delete(t):r.add(t),n(e.filter(e=>r.has(e.id)).map(e=>e.id))};return g(`div`,{ref:a,className:`relative`,children:[g(`button`,{type:`button`,onClick:()=>i(e=>!e),className:X(`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full border text-[10.5px] font-medium transition-colors`,s>0?`border-primary/40 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover`),"aria-haspopup":`listbox`,"aria-expanded":r,children:[g(`span`,{children:[`Integration`,s>0?` · ${String(s)}`:``]}),N(Re,{className:X(`h-3 w-3 transition-transform`,r&&`rotate-180`)})]}),r&&g(`div`,{role:`listbox`,className:`absolute left-0 top-full mt-1 z-30 min-w-[180px] max-h-72 overflow-y-auto rounded-lg border border-border bg-surface shadow-xl py-1`,children:[s>0&&N(`button`,{type:`button`,onClick:()=>n([]),className:`flex w-full items-center px-3 py-1.5 text-left text-[10.5px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:`Clear selection`}),e.map(e=>{let t=o.has(e.id);return g(`button`,{type:`button`,role:`option`,"aria-selected":t,onClick:()=>c(e.id),className:X(`flex w-full items-center gap-2 px-3 py-1.5 text-left text-[10.5px] transition-colors`,t?`text-primary`:`text-foreground hover:bg-surface-hover`),children:[N(`span`,{className:X(`flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded border`,t?`border-primary bg-primary/20`:`border-border`),children:t&&N(Ci,{className:`h-2.5 w-2.5`})}),e.icon&&N(`span`,{className:`inline-flex items-center`,children:e.icon}),N(`span`,{className:`truncate`,children:e.name})]},e.id)})]})]})}function Ej({variant:e,onClearFilters:t}){return g(`div`,{className:`flex flex-col items-center justify-center py-12 text-center`,children:[N(ya,{className:`h-8 w-8 text-foreground-subtle/40 mb-3`}),N(`p`,{className:`text-sm font-medium text-foreground-subtle`,children:e===`filtered`?`No devices match the current filters`:`No devices yet`}),e===`filtered`&&t&&N(`button`,{type:`button`,onClick:t,className:`mt-2 text-[11px] text-primary hover:underline`,children:`Clear filters`})]})}h();function Dj(e){return e?e.split(`,`).map(e=>e.trim()).filter(e=>e.length>0):[]}function Oj(e,t){if(e===`root`)return t===`addons`?`addon`:t===`types`?`type`:t;switch(t){case`view`:return`deviceView`;case`page`:return`devicePage`;case`types`:return`deviceType`;case`q`:return`deviceQ`;case`addons`:return`deviceAddon`}}function kj(e){try{let t=localStorage.getItem(`camstack:${e}:lastFilters`);if(!t)return{};let n=JSON.parse(t);return typeof n!=`object`||!n?{}:n}catch{return{}}}function Aj(e,t){try{localStorage.setItem(`camstack:${e}:lastFilters`,JSON.stringify(t))}catch{}}function jj(e,t,n){let r=new URLSearchParams(window.location.search),i=r.get(Oj(e,`view`)),a=i===`cards`||i===`table`?i:n.view??t,o=r.get(Oj(e,`page`)),s=o?parseInt(o,10):1;return{view:a,page:Number.isFinite(s)&&s>=1?s:1,addons:Dj(r.get(Oj(e,`addons`))??n.addon??null),types:Dj(r.get(Oj(e,`types`))??n.type??null),q:r.get(Oj(e,`q`))??n.q??``}}function Mj(e,t,n){let r=new URLSearchParams(window.location.search),i=(e,t)=>{t===null||t===``?r.delete(e):r.set(e,t)};i(Oj(e,`view`),t.view===n?null:t.view),i(Oj(e,`page`),t.page===1?null:String(t.page)),i(Oj(e,`addons`),t.addons.length>0?t.addons.join(`,`):null),i(Oj(e,`types`),t.types.length>0?t.types.join(`,`):null),i(Oj(e,`q`),t.q||null);let a=r.toString(),o=a?`${window.location.pathname}?${a}`:window.location.pathname;window.history.replaceState(null,``,o)}function Nj(e){let{scope:t,defaultView:n,lsKey:r}=e,[i,a]=k(()=>jj(t,n,kj(r))),o=f(i);o.current=i,P(()=>{let e=()=>{let e=jj(t,n,kj(r));o.current=e,a(e)};return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[t,n,r]);let s=u(e=>{let i=e(o.current);o.current=i,a(i),Mj(t,i,n),Aj(r,{view:i.view,addon:i.addons.length>0?i.addons.join(`,`):null,type:i.types.length>0?i.types.join(`,`):null,q:i.q})},[t,n,r]);return{state:i,setView:u(e=>s(t=>({...t,view:e})),[s]),setPage:u(e=>s(t=>({...t,page:e})),[s]),setAddons:u(e=>s(t=>({...t,addons:e,page:1})),[s]),setTypes:u(e=>s(t=>({...t,types:e,page:1})),[s]),setQ:u(e=>s(t=>({...t,q:e,page:1})),[s]),clearFilters:u(()=>s(e=>({...e,addons:[],types:[],q:``,page:1})),[s])}}function Pj({rows:e,accessoriesByParent:t,trpc:n,resolveIntegrationIcon:r,resolveParent:i,onNavigate:a,renderRowAction:o,selectable:s,rowClickSelects:c,activeSelected:l,onToggleSelection:u}){return N(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3 items-stretch`,children:e.map(e=>{let d=t.get(e.id)??[],f=s?{selected:l.has(e.id),onToggle:()=>u(e.id)}:void 0;return N(tj,{trpc:n,device:e,view:`card`,integrationIcon:r?.(e.addonId)??null,parent:e.parentDeviceId===null?null:i?.(e.parentDeviceId)??null,children:d,onNavigate:a??void 0,renderRowAction:o??void 0,selection:f,rowClickSelects:c},e.id)})})}function Fj({columnId:e,label:t,sort:n,onSort:r}){let i=n!==null&&n.columnId===e;return g(`button`,{type:`button`,onClick:()=>r(e),className:`group/sort inline-flex items-center gap-0.5 uppercase tracking-wider hover:text-foreground transition-colors`,children:[N(`span`,{children:t}),i?n.dir===`asc`?N(Ti,{className:`h-3 w-3 flex-shrink-0`}):N(Re,{className:`h-3 w-3 flex-shrink-0`}):N(Ti,{className:X(`h-3 w-3 flex-shrink-0 opacity-0 transition-opacity`,`group-hover/sort:opacity-30`)})]})}h();function Ij(e,t){return e===null||e.columnId!==t?`none`:e.dir===`asc`?`ascending`:`descending`}var Lj=new Set([`hub`,`nvr`]);function Rj(e,t){return e.parentDeviceId===null||t===null?0:+!!Lj.has(t.toLowerCase())}function zj({rows:e,accessoriesByParent:t,autoExpandedParents:n,devices:r,visibleColumns:i,trpc:a,resolveIntegrationIcon:o,resolveParent:s,onNavigate:c,renderRowAction:l,onDeleteDevice:u,selectable:d,rowClickSelects:f,activeSelected:p,onToggleSelection:m,sort:h,onSort:_}){let v=i.includes(`type`),y=i.includes(`features`),x=i.includes(`manufacturer`),S=i.includes(`icon`),C=b(()=>{let e=new Map;for(let t of r)e.set(t.id,t.type);return e},[r]);return N(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:g(`table`,{className:`w-full border-collapse`,children:[N(`thead`,{children:g(`tr`,{className:`border-b border-border`,children:[N(`th`,{"aria-sort":Ij(h,`name`),className:`sticky left-0 z-[1] bg-surface text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-64 max-w-[16rem]`,children:N(Fj,{columnId:`name`,label:`Name`,sort:h,onSort:_})}),v&&N(`th`,{"aria-sort":Ij(h,`type`),className:X(zl.type,`text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-24`),children:N(Fj,{columnId:`type`,label:`Type`,sort:h,onSort:_})}),x&&N(`th`,{"aria-sort":Ij(h,`manufacturer`),className:X(zl.manufacturer,`text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-40`),children:N(Fj,{columnId:`manufacturer`,label:`Hardware`,sort:h,onSort:_})}),y&&N(`th`,{className:X(zl.features,`text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-32`),children:`Features`}),N(`th`,{className:`text-right px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-32`,children:`Preview`})]})}),N(`tbody`,{children:e.map(e=>{let r=t.get(e.id)??[],i=r.length>0,h=n.has(e.id),g=e.parentDeviceId===null?null:s?.(e.parentDeviceId)??null,_=e.parentDeviceId===null?null:C.get(e.parentDeviceId)??null,b=d?{selected:p.has(e.id),onToggle:()=>m(e.id)}:void 0;return N(Bj,{parent:e,accessories:r,hasAccessories:i,forceExpanded:h,trpc:a,integrationIcon:S?o?.(e.addonId)??null:null,showType:v,showManufacturer:x,showFeatures:y,parentRowParent:g,indentLevel:Rj(e,_),onNavigate:c??null,renderRowAction:l??null,onDeleteDevice:u,selection:b,rowClickSelects:f},e.id)})})]})})}function Bj({parent:e,accessories:t,hasAccessories:n,forceExpanded:r,trpc:i,integrationIcon:a,showType:o,showManufacturer:s,showFeatures:c,parentRowParent:l,indentLevel:u,onNavigate:d,renderRowAction:p,onDeleteDevice:m,selection:h,rowClickSelects:_}){let[v,y]=k(r),x=f(r);P(()=>{x.current!==r&&(y(r),x.current=r)},[r]);let S=()=>y(e=>!e),C=n&&v,T=b(()=>QA(e.stableId,t,e.childLayout),[e.stableId,e.childLayout,t]),[E,D]=k(()=>{let e=T.sections.filter(e=>!e.defaultOpen).map(e=>e.title);return T.disabledSection!==void 0&&!T.disabledSection.defaultOpen&&e.push(T.disabledSection.title),new Set(e)}),O=e=>D(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),A=2+ +!!o+ +!!s+ +!!c,j=T.disabledSection;return g(w,{children:[N(tj,{trpc:i,device:e,view:`table`,integrationIcon:a,parent:l,children:t,onNavigate:d??void 0,showChildrenAccordion:!0,expanded:v,onToggleExpand:S,indentLevel:u,renderRowAction:p??void 0,onDelete:m??void 0,selection:h,rowClickSelects:_,showTypeCell:o,showManufacturerCell:s,showFeaturesCell:c}),C&&T.ungrouped.map(t=>N(Vj,{trpc:i,accessory:t,parentName:e.name,showType:o,showManufacturer:s,showFeatures:c,onNavigate:d},t.id)),C&&T.sections.map(t=>{let n=!E.has(t.title);return N(Hj,{title:t.title,count:t.children.length,open:n,colSpan:A,onToggle:()=>O(t.title),rows:t.children,trpc:i,parentName:e.name,showType:o,showManufacturer:s,showFeatures:c,onNavigate:d},t.title)}),C&&j!==void 0&&N(Hj,{title:j.title,count:j.children.length,open:!E.has(j.title),colSpan:A,onToggle:()=>O(j.title),rows:j.children,trpc:i,parentName:e.name,showType:o,showManufacturer:s,showFeatures:c,onNavigate:d,muted:!0},j.title)]})}function Vj({trpc:e,accessory:t,parentName:n,showType:r,showManufacturer:i,showFeatures:a,onNavigate:o,muted:s}){return N(tj,{trpc:e,device:{...t,name:Hk(t,n)},view:`table`,integrationIcon:null,parent:null,isAccessoryRow:!0,showChildrenAccordion:!1,onNavigate:o??void 0,showTypeCell:r,showManufacturerCell:i,showFeaturesCell:a,className:s===!0?`opacity-60`:void 0})}function Hj({title:e,count:t,open:n,colSpan:r,onToggle:i,rows:a,trpc:o,parentName:s,showType:c,showManufacturer:l,showFeatures:u,onNavigate:d,muted:f}){return g(w,{children:[N(`tr`,{className:X(`border-b border-border-subtle/40 bg-surface`,f===!0&&`opacity-60`),children:N(`td`,{colSpan:r,className:`p-0`,children:g(`button`,{type:`button`,onClick:i,className:`w-full flex items-center gap-1.5 pl-8 pr-2 py-1 text-left hover:bg-surface-hover transition-colors`,"aria-expanded":n,children:[N(n?Re:Ue,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),N(`span`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle flex-1 truncate`,children:e}),N(`span`,{className:`text-[10px] font-medium text-foreground-subtle/70 tabular-nums`,children:t})]})})}),n&&a.map(e=>N(Vj,{trpc:o,accessory:e,parentName:s,showType:c,showManufacturer:l,showFeatures:u,onNavigate:d,muted:f},e.id))]})}function Uj(e){return Ak(e.type).label.toLowerCase()}function Wj(e){return e.name.toLowerCase()}function Gj(e){return e===`name`?(e,t)=>Wj(e).localeCompare(Wj(t)):e===`type`?(e,t)=>Uj(e).localeCompare(Uj(t)):Yl}function Kj(e,t){return e===null||e.columnId!==t?{columnId:t,dir:`asc`}:e.dir===`asc`?{columnId:t,dir:`desc`}:null}function qj(e,t){if(t===null)return[...e];let n=Gj(t.columnId),r=t.dir===`asc`?1:-1;return[...e].toSorted((e,i)=>{if(t.columnId===`manufacturer`){let t=Kl(e);if(t!==Kl(i))return t?-1:1}return r*n(e,i)})}h();var Jj={cards:24,table:50};function Yj(e){let{devices:t,trpc:n,context:r=`devices`,defaultView:i=`table`,filters:a,forceAddon:o,resolveIntegrationIcon:s,resolveParent:c,onNavigate:l,pageSize:u=Jj,urlScope:d=`root`,lsKey:f=d===`root`?`devices`:`integrations:nested`,renderRowAction:p,onDeleteDevice:m,selectable:h=!1,selectedIds:_,onSelectionChange:v,batchActions:y}=e,[x,S]=k(!1),[C,T]=k(new Set),E=_??C,D=e=>{let t=new Set(E);t.has(e)?t.delete(e):t.add(e),_===void 0&&T(t),v?.(t)},O=()=>{_===void 0?T(new Set):v?.(new Set)},A=()=>{O(),S(!1)},j=h||y!==void 0&&x,M=y!==void 0&&x,F=b(()=>Ll(r),[r]),[I,L]=k(null),R=e=>L(t=>Kj(t,e)),ee=a?.typeOptions,z=b(()=>ee??Fk(),[ee]),B=Nj({scope:d,defaultView:i,lsKey:f}),V=B.state.view,[te,H]=pj(u.table),U=V===`cards`?u.cards:te,[ne,re]=k(B.state.q),ie=oj(ne,300);P(()=>{ie!==B.state.q&&B.setQ(ie)},[ie]);let ae=b(()=>o===void 0?B.state.addons:[o],[o,B.state.addons]),oe=b(()=>{let e=new Map;for(let n of t){if(n.parentDeviceId===null||n.parentDeviceId===void 0)continue;let t=e.get(n.parentDeviceId);t?t.push(n):e.set(n.parentDeviceId,[n])}return e},[t]),se=b(()=>{let e=B.state.q,n=ae.length>0?new Set(ae):null,r=B.state.types.length>0?new Set(B.state.types):null;return t.filter(t=>!(n&&!n.has(t.addonId)||r&&!r.has(Zk(t,oe.get(t.id)))||e.trim()!==``&&!vj(e,t.name)&&!vj(e,t.stableId)))},[t,oe,ae,B.state.types,B.state.q]),W=b(()=>gj(se),[se]),ce=b(()=>qj(W.topLevel,I),[W.topLevel,I]),le=b(()=>{if(B.state.q.trim()===``)return new Set;let e=B.state.q,t=new Set;for(let[n,r]of W.accessoriesByParent.entries())r.some(t=>vj(e,t.name)||vj(e,t.stableId))&&t.add(n);return t},[W.accessoriesByParent,B.state.q]),ue=W.topLevel.length,de=Math.max(1,Math.ceil(ue/U)),fe=Math.min(B.state.page,de),pe=(fe-1)*U,G=ce.slice(pe,pe+U);P(()=>{fe!==B.state.page&&B.setPage(fe)},[fe]),Xj();let me=ae.length>0||B.state.types.length>0||B.state.q!==``,he=ue===0;return g(`div`,{className:`flex flex-col gap-3`,children:[g(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[N(wj,{view:V,onViewChange:B.setView,typeOptions:z,selectedTypes:B.state.types,onTypesChange:B.setTypes,addons:a?.addons,selectedAddons:B.state.addons,onAddonsChange:B.setAddons,hideAddons:o!==void 0}),g(`div`,{className:`flex items-center gap-2`,children:[y!==void 0&&(x?g(`button`,{type:`button`,onClick:A,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md border border-border bg-surface text-[11px] font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[N(rs,{className:`h-3 w-3`}),`Done`]}):g(`button`,{type:`button`,onClick:()=>S(!0),className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md border border-border bg-surface text-[11px] font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[N(wa,{className:`h-3 w-3`}),`Select`]})),g(`div`,{className:`relative`,children:[N(po,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle pointer-events-none`}),N(`input`,{type:`text`,value:ne,onChange:e=>re(e.target.value),placeholder:`Search by name or stableId`,"aria-label":`Search devices by name or stableId`,className:`h-7 pl-7 pr-2.5 rounded-md border border-border bg-surface text-[11px] text-foreground placeholder:text-foreground-subtle/60 focus:outline-none focus:ring-1 focus:ring-primary/40 w-56`})]})]})]}),y!==void 0&&x&&N(aj,{selectedIds:E,onClear:O,remove:y.remove,disable:y.disable,enable:y.enable}),he?N(Ej,{variant:me?`filtered`:`nofilter`,onClearFilters:me?B.clearFilters:void 0}):V===`cards`?N(iA,{value:W.accessoriesByParent,children:N(Pj,{rows:G,accessoriesByParent:W.accessoriesByParent,trpc:n,resolveIntegrationIcon:s??null,resolveParent:c??null,onNavigate:l??null,renderRowAction:p??null,selectable:j,rowClickSelects:M,activeSelected:E,onToggleSelection:D})}):N(iA,{value:W.accessoriesByParent,children:N(zj,{rows:G,accessoriesByParent:W.accessoriesByParent,autoExpandedParents:le,visibleColumns:F,sort:I,onSort:R,devices:se,trpc:n,resolveIntegrationIcon:s??null,resolveParent:c??null,onNavigate:l??null,renderRowAction:p??null,onDeleteDevice:m??null,selectable:j,rowClickSelects:M,activeSelected:E,onToggleSelection:D})}),!he&&V===`table`&&g(`div`,{className:`flex items-center justify-between gap-4 flex-wrap pt-2 text-[11px] text-foreground-subtle`,children:[g(`div`,{className:`inline-flex items-center gap-2`,children:[ue<=te&&g(`span`,{children:[ue,` `,ue===1?`device`:`devices`]}),g(`div`,{className:`inline-flex items-center gap-1.5`,children:[N(`span`,{"aria-hidden":`true`,children:`Per page`}),N(`select`,{"aria-label":`Devices per page`,value:te,onChange:e=>{H(Number.parseInt(e.target.value,10))},className:`h-7 px-1.5 rounded-md border border-border bg-surface text-[11px] text-foreground focus:outline-none focus:ring-1 focus:ring-primary/40`,children:sj.map(e=>N(`option`,{value:e,children:e},e))})]})]}),N(xj,{currentPage:fe,totalItems:ue,pageSize:U,onPageChange:B.setPage})]}),!he&&V===`cards`&&N(xj,{currentPage:fe,totalItems:ue,pageSize:U,onPageChange:B.setPage}),o===void 0&&me&&ue>0&&g(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Showing `,ue,` of `,mj(t).length,` devices`,ae.length>0&&g(w,{children:[` `,`· filtered by`,` `,N(`strong`,{className:`text-primary`,children:ae.map(e=>a?.addons?.find(t=>t.id===e)?.name??e).join(`, `)})]})]})]})}function Xj(){O()}h();function Zj(e){let{items:t,getKey:n,getSearchText:r,renderItem:i,getFilterType:a,mapFilterOption:s,filterOptions:c,filterLabel:l=`Type`,columns:u,renderExpanded:d,isExpanded:f,rowClassName:p,onRowClick:m,isLoading:h=!1,searchPlaceholder:_=`Search`,emptyLabel:v=`No items found.`,pageSize:y=100,toolbar:x}=e,[S,C]=k(``),w=oj(S,300),[T,E]=k([]),[D,O]=k(1);P(()=>{O(1)},[w,T]);let A=b(()=>{if(!a)return[];if(c)return c;let e=new Set;for(let n of t){let t=a(n);t!==null&&t!==``&&e.add(t)}return[...e].toSorted().map(e=>{let t=s?.(e);return{id:e,label:t?.label??e,...t?.icon?{icon:t.icon}:{}}})},[t,a,s,c]),j=b(()=>new Set(T),[T]),M=b(()=>{let e=w;return t.filter(t=>{if(j.size>0&&a){let e=a(t);if(e===null||!j.has(e))return!1}return!(e.trim()!==``&&!vj(e,r(t)))})},[t,w,r,j,a]),F=M.length,I=Math.max(1,Math.ceil(F/y)),L=Math.min(D,I),R=(L-1)*y,ee=M.slice(R,R+y);return P(()=>{L!==D&&O(L)},[L,D]),g(`div`,{className:`flex flex-col gap-3 h-full min-h-0`,children:[g(`div`,{className:`flex items-center justify-between gap-3 flex-wrap shrink-0`,children:[a&&A.length>0?N(Cj,{label:l,options:A,selected:T,onChange:E}):N(`span`,{}),g(`div`,{className:`flex items-center gap-2`,children:[g(`div`,{className:`relative`,children:[N(po,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle pointer-events-none`}),N(`input`,{type:`text`,value:S,onChange:e=>C(e.target.value),placeholder:_,"aria-label":_,className:`h-7 pl-7 pr-2.5 rounded-md border border-border bg-surface text-[11px] text-foreground placeholder:text-foreground-subtle/60 focus:outline-none focus:ring-1 focus:ring-primary/40 w-56`})]}),x]})]}),N(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:h&&F===0?N(`div`,{className:`flex items-center justify-center py-12 text-xs text-foreground-subtle`,children:`Loading…`}):F===0?N(`div`,{className:`flex items-center justify-center py-12 text-xs text-foreground-subtle`,children:v}):u?N(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:g(`table`,{className:`w-full border-collapse`,children:[N(`thead`,{children:N(`tr`,{className:`border-b border-border`,children:u.map(e=>N(`th`,{className:`text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle ${e.headerClassName??``}`,children:e.header},e.key))})}),N(`tbody`,{children:ee.map(e=>g(o,{children:[N(`tr`,{className:`border-b border-border/60 ${m?`cursor-pointer hover:bg-surface-hover transition-colors`:``} ${p?.(e)??``}`,...m?{onClick:()=>m(e),role:`button`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),m(e))}}:{},children:u.map(t=>N(`td`,{className:`px-2 py-2 align-middle ${t.cellClassName??``}`,children:t.cell(e)},t.key))}),d&&f?.(e)&&N(`tr`,{className:`border-b border-border/60 bg-surface/40`,children:N(`td`,{colSpan:u.length,className:`px-2 pb-2 pt-0`,children:d(e)})})]},n(e)))})]})}):N(`div`,{className:`space-y-1.5`,children:ee.map(e=>N(o,{children:i?.(e)},n(e)))})}),N(`div`,{className:`shrink-0`,children:N(xj,{currentPage:L,totalItems:F,pageSize:y,onPageChange:O})})]})}function Qj(e){return`mode`in e&&e.mode===`generic`?N(Zj,{...e}):N(Yj,{...e})}function $j({trpc:e,deviceId:t,features:n,layout:r}){let{cap:i,slice:a,available:o}=Q({trpc:e,deviceId:t,cap:e=>e.cover,slice:e=>e.state.cover});if(a===void 0)return null;let s=(n??[]).includes(`cover-positionable`),c=!o,l=a.position,u=e=>{c||!e||e({})};return g(`div`,{className:X(`inline-flex items-center gap-1`,r===`full`&&`flex-col items-stretch gap-2`),children:[g(`div`,{className:`inline-flex items-center gap-1`,children:[N(eM,{label:`Open`,busy:c,onClick:()=>u(i?.open),children:N(Ti,{className:`h-3.5 w-3.5`})}),N(eM,{label:`Stop`,busy:c,onClick:()=>u(i?.stop),children:N(Ao,{className:`h-3 w-3`})}),N(eM,{label:`Close`,busy:c,onClick:()=>u(i?.close),children:N(Re,{className:`h-3.5 w-3.5`})})]}),s&&r===`full`&&g(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[N(`span`,{children:`Position`}),N(`input`,{"aria-label":`Position`,type:`range`,min:0,max:100,step:1,value:l??0,disabled:c,onChange:e=>{c||i?.setPosition({position:Number(e.target.value)})}}),g(`span`,{className:`tabular-nums w-8 text-right`,children:[l??`—`,`%`]})]})]})}function eM({label:e,busy:t,onClick:n,children:r}){return N(`button`,{type:`button`,"aria-label":e,title:e,disabled:t,onClick:e=>{e.stopPropagation(),n()},className:X(`inline-flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,t&&`opacity-40 cursor-not-allowed`),children:r})}var tM=[`cover`,`lock-control`,`switch`,`brightness`,`fan-control`,`climate-control`,`media-player`,`control`,`pet-feeder`];h(),rt();var nM=240,rM=6;function iM({icon:e,title:t,children:n}){let r=f(null),i=f(null),[a,o]=k(null),s=a!==null,c=()=>o(null),l=()=>{let e=r.current;if(!e)return;let t=e.getBoundingClientRect(),n=Math.min(nM,window.innerWidth-16),i=Math.max(8,Math.min(t.right-n,window.innerWidth-n-8));o({top:t.bottom+rM,left:i,width:n})};return P(()=>{if(!s)return;let e=e=>{let t=e.target;i.current?.contains(t)||r.current?.contains(t)||c()},t=e=>{e.key===`Escape`&&c()};return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e),document.removeEventListener(`keydown`,t)}},[s]),g(w,{children:[N(`button`,{ref:r,type:`button`,title:t,"aria-label":t,"aria-haspopup":`dialog`,"aria-expanded":s,onClick:e=>{e.stopPropagation(),s?c():l()},className:X(`inline-flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,s&&`bg-surface-hover text-foreground`),children:N(e,{className:`h-3 w-3`})}),a&&it(N(`div`,{ref:i,style:{position:`fixed`,top:a.top,left:a.left,width:a.width},className:`z-[9999] rounded-lg border border-border bg-surface shadow-lg shadow-black/30 p-2`,onClick:e=>e.stopPropagation(),children:n}),document.body)]})}function aM({lastChangedAt:e,className:t}){let n=mr(e);return g(`span`,{title:n===null?`Unavailable`:`Unavailable · last seen ${n}`,className:X(`inline-flex items-center gap-1 rounded-full px-2 py-0.5`,`bg-surface-hover text-foreground-subtle text-[10px] font-medium`,`border border-border`,t),children:[N(Qo,{className:`h-3 w-3 flex-shrink-0`,"aria-hidden":`true`}),N(`span`,{children:`Unavailable`}),n===null?null:N(`span`,{className:`text-foreground-subtle/70`,children:`· last seen ${n}`})]})}function oM({trpc:e,children:t,linkDeviceId:n,primaryChildEntityId:r}){let i=yk(t,n,r),a=i===null?void 0:t.find(e=>e.id===i.id);return a===void 0?N(`div`,{className:`flex h-full w-full items-center justify-center p-4 text-[11px] italic text-foreground-subtle`,children:`No child entities to display.`}):N(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:N(dk(a.type)?.HeroCard??ku,{trpc:e,deviceId:a.id,features:a.features})})}var sM=`rounded-md border border-border bg-surface px-1.5 py-0.5 text-[11px] text-foreground`;function cM({childrenList:e,selectedId:t,onSetPrimary:n,disabled:r,className:i}){return N(`select`,{value:t,disabled:r,onChange:r=>{let i=Number(r.target.value);if(!Number.isFinite(i)||i===t)return;let a=e.find(e=>e.id===i);a!==void 0&&n(gk(a))},className:i===void 0?sM:`${sM} ${i}`,children:e.map(e=>g(`option`,{value:e.id,children:[e.name,` (`,e.type,`)`]},e.id))})}function lM({options:e,value:t,onChange:n}){return N(`div`,{className:`flex flex-wrap gap-2`,children:e.map(e=>{let r=e.id===t;return g(`button`,{onClick:()=>e.available&&n(e.id),disabled:!e.available,className:`flex items-center gap-2 rounded-lg border px-3 py-2 text-xs font-medium transition-all ${r?`border-primary/40 bg-primary/10 text-primary`:e.available?`border-border bg-surface text-foreground-subtle hover:bg-surface-hover hover:text-foreground`:`border-border/40 bg-surface/40 text-foreground-subtle/40 cursor-not-allowed`}`,children:[N(Gi,{className:`h-3.5 w-3.5 shrink-0`}),e.label,e.isBest&&g(`span`,{className:`inline-flex items-center gap-0.5 rounded-full bg-amber-500/15 px-1.5 py-0.5 text-[10px] font-semibold text-amber-400`,children:[N(jo,{className:`h-2.5 w-2.5`}),`Best`]}),e.platformScore!=null&&g(`span`,{className:`text-[10px] text-foreground-subtle/60`,children:[`(`,e.platformScore,`)`]}),N(`span`,{className:`h-1.5 w-1.5 rounded-full ${e.available?`bg-success`:`bg-danger`}`})]},e.id)})})}function uM(e,t){let n=new Set(t.slots.flatMap(e=>e.addons.map(e=>e.id))),r=[];function i(e){if(!n.has(e.addonId))return r.push(`Addon "${e.addonId}" is no longer available — step removed`),null;let a=t.slots.flatMap(e=>e.addons).find(t=>t.id===e.addonId),o=e.modelId;if(a&&!a.models.some(e=>e.id===o)){let t=a.defaultModelId;r.push(`Model "${o}" not available for ${e.addonId} — using "${t}"`),o=t}let s=e.children.map(e=>i(e)).filter(e=>e!==null);return{...e,modelId:o,children:s}}let a=e.map(e=>i(e)).filter(e=>e!==null);return{valid:r.length===0,steps:a,warnings:r}}h();function dM(e){let t=new Map;for(let n of e.slots)for(let e of n.addons)t.set(e.id,e);return t}function fM(e){return{addonId:e.id,addonName:e.name,slot:e.slot,inputClasses:[...e.inputClasses],outputClasses:[...e.outputClasses],enabled:!0,modelId:e.defaultModelId,children:[]}}function pM({addon:e,onClick:t}){return N(`button`,{type:`button`,onClick:t,className:`w-full rounded-lg border border-dashed border-border/60 px-3 py-2.5 text-left transition-all hover:border-primary/30 hover:bg-surface/60 group`,children:g(`div`,{className:`flex items-center gap-3`,children:[N(Ni,{className:`h-[18px] w-[18px] text-foreground-subtle/30 group-hover:text-primary/60 shrink-0`}),g(`div`,{className:`flex-1 min-w-0`,children:[N(`span`,{className:`text-[13px] font-medium text-foreground-subtle/50 group-hover:text-foreground-subtle block truncate`,children:e.name}),g(`div`,{className:`flex items-center gap-1 mt-0.5 flex-wrap`,children:[e.inputClasses.map(e=>N(`span`,{className:`text-[9px] uppercase font-semibold tracking-wide px-1.5 py-0.5 rounded bg-blue-500/8 text-blue-400/50`,children:e},e)),e.inputClasses.length>0&&e.outputClasses.length>0&&N(`span`,{className:`text-foreground-subtle/25 text-[10px]`,children:`→`}),e.outputClasses.map(e=>N(`span`,{className:`text-[9px] uppercase font-semibold tracking-wide px-1.5 py-0.5 rounded bg-green-500/8 text-green-400/50`,children:e},e))]})]})]})})}function mM({schema:e,steps:t,onChange:n,templates:r,selectedTemplateId:i,onSelectTemplate:a,onSaveTemplate:o,onUpdateTemplate:s,onDeleteTemplate:c,readOnly:l=!1,excludeAddons:u=[],hideTemplates:d=!1,showOnlyEnabled:f=!1,showSlotLabels:p=!1,toggleMode:m=`simple`,overrides:h={},onOverrideChange:_,inheritedEnabledByAddon:v={},hideModelAndSettings:y=!1,allowAutoModel:x=!1}){let S=e=>({toggleMode:m,hideModelAndSettings:y,allowAutoModel:x,...m===`threeState`?{overrideState:h[e]===void 0?null:h[e],onOverrideChange:_?t=>_(e,t):void 0,inheritedEnabled:v[e]}:{}}),C=b(()=>new Set(u),[u]),w=b(()=>dM(e),[e]),[T,E]=k([]),D=i?JSON.stringify(t)!==JSON.stringify(r.find(e=>e.id===i)?.steps):!1;function O(t){let n=t.target.value||null;if(n){let t=r.find(e=>e.id===n);t&&E([...uM(t.steps,e).warnings])}else E([]);a(n)}function A(){i&&s(i,t)}function j(){let e=window.prompt(`Template name:`);e?.trim()&&o(e.trim(),t)}function M(){if(!i)return;let e=r.find(e=>e.id===i);e&&window.confirm(`Delete template "${e.name}"?`)&&c(i)}function P(e){n(t.map(t=>t.addonId===e.addonId?F(e):t))}function F(e){let t=e.children.some(e=>e.enabled||e.children.some(e=>e.enabled));return{...e,enabled:e.enabled||t,children:e.children.map(e=>{let t=e.children.some(e=>e.enabled);return{...e,enabled:e.enabled||t}})}}function I(e,r){let i=fM(r);n(t.map(t=>t.addonId===e?{...t,children:[...t.children,i]}:t))}function L(e){let t=new Set;for(let n of e){t.add(n.addonId);for(let e of n.children)t.add(e.addonId);let e=L(n.children);for(let n of e)t.add(n)}return t}let R=L(t);function ee(t){let n=w.get(t.addonId);if(!n)return[];let r=e.slots.find(e=>e.id===n.slot)?.parentSlot==null,i=n.childSlots,a=new Set(t.children.map(e=>e.addonId)),o=[];for(let n of e.slots)if(i.includes(n.id))for(let e of n.addons){if(a.has(e.id)||C.has(e.id))continue;let n=e.inputClasses.length===0;n&&!r||(n||e.inputClasses.some(e=>t.outputClasses.includes(e)))&&o.push(e)}return o}function z(e){let r=f?{...e,children:e.children.filter(e=>e.enabled).map(e=>({...e,children:e.children.filter(e=>e.enabled)}))}:e,i=f?[]:ee(r);return g(`div`,{className:`space-y-1.5`,children:[N(Oc,{step:r,schema:w.get(r.addonId)??null,allSchemas:w,onChange:P,onDelete:l?void 0:e=>n(t.filter(t=>t.addonId!==e)),readOnly:l,...S(r.addonId)}),(r.children.length>0||i.length>0)&&g(`div`,{className:`ml-4 pl-3 border-l border-border/60 space-y-1.5`,children:[p&&N(`span`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/40`,children:`Slot: Cropper / Classifier`}),r.children.map(e=>{let t=ee(e);return g(`div`,{className:`space-y-1.5`,children:[N(Oc,{step:e,schema:w.get(e.addonId)??null,allSchemas:w,depth:1,onChange:e=>{P({...r,children:r.children.map(t=>t.addonId===e.addonId?e:t)})},onDelete:l?void 0:e=>{P({...r,children:r.children.filter(t=>t.addonId!==e)})},readOnly:l,...S(e.addonId)}),(e.children.length>0||t.length>0)&&g(`div`,{className:`ml-4 pl-3 border-l border-border/40 space-y-1.5`,children:[p&&N(`span`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/30`,children:`Slot: Recognizer`}),e.children.map(t=>N(Oc,{step:t,schema:w.get(t.addonId)??null,allSchemas:w,depth:2,onChange:t=>{P({...r,children:r.children.map(n=>n.addonId===e.addonId?{...n,children:n.children.map(e=>e.addonId===t.addonId?t:e)}:n)})},onDelete:l?void 0:t=>{P({...r,children:r.children.map(n=>n.addonId===e.addonId?{...n,children:n.children.filter(e=>e.addonId!==t)}:n)})},readOnly:l,...S(t.addonId)},t.addonId)),!l&&t.map(t=>N(pM,{addon:t,onClick:()=>{let n=fM(t);P({...r,children:r.children.map(t=>t.addonId===e.addonId?{...t,children:[...t.children,n]}:t)})}},t.id))]})]},e.addonId)}),!l&&i.map(e=>N(pM,{addon:e,onClick:()=>I(r.addonId,e)},e.id))]})]},r.addonId)}let B=e.slots.filter(e=>e.parentSlot===null).toSorted((e,t)=>e.priority-t.priority);return g(`div`,{className:`space-y-4`,children:[!d&&N(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:g(`div`,{className:`flex items-center gap-2`,children:[N(`div`,{className:`relative flex-1 min-w-0`,children:g(`select`,{value:i??``,onChange:O,className:`w-full rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground focus:outline-none focus:border-primary/50`,children:[N(`option`,{value:``,children:`No template`}),r.map(e=>N(`option`,{value:e.id,children:e.name},e.id))]})}),D&&N(`span`,{className:`h-1.5 w-1.5 rounded-full bg-amber-500 shrink-0`}),N(`button`,{onClick:A,disabled:!i||l,title:`Save`,className:X(`p-2 rounded-lg border border-border transition-colors`,i&&!l?`text-foreground-subtle hover:bg-surface-hover`:`text-foreground-subtle/30 cursor-not-allowed`),children:N(lo,{className:`h-4 w-4`})}),N(`button`,{onClick:j,disabled:l,title:`Save As`,className:X(`p-2 rounded-lg border border-border transition-colors`,l?`text-foreground-subtle/30 cursor-not-allowed`:`text-foreground-subtle hover:bg-surface-hover`),children:N(Ui,{className:`h-4 w-4`})}),N(`button`,{onClick:M,disabled:!i||l,title:`Delete`,className:X(`p-2 rounded-lg border border-border transition-colors`,i&&!l?`text-foreground-subtle hover:text-danger`:`text-foreground-subtle/30 cursor-not-allowed`),children:N(Bo,{className:`h-4 w-4`})})]})}),T.length>0&&g(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/5 p-3 text-xs text-amber-400 space-y-1`,children:[g(`div`,{className:`flex items-center justify-between`,children:[N(`span`,{className:`font-medium`,children:`Template loaded with warnings:`}),N(`button`,{onClick:()=>E([]),className:`text-amber-400/60 hover:text-amber-400`,children:N(rs,{className:`h-3.5 w-3.5`})})]}),T.map((e,t)=>g(`div`,{children:[`• `,e]},t))]}),B.map(e=>{let r=t.filter(t=>t.slot===e.id&&!C.has(t.addonId)),i=f?r.filter(e=>e.enabled):r,a=f?[]:e.addons.filter(e=>!R.has(e.id)&&!C.has(e.id)),o=new Map,s=[];for(let e of i)e.group?(o.has(e.group)||o.set(e.group,[]),o.get(e.group).push(e)):s.push(e);return g(`div`,{className:`space-y-2`,children:[p&&g(`span`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/50`,children:[`Slot: `,e.label]}),s.map(e=>z(e)),[...o.entries()].map(([e,t])=>g(`div`,{className:`space-y-2 rounded-lg border border-border/40 p-2`,children:[N(`span`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/50 px-1`,children:e}),t.map(e=>z(e))]},e)),!l&&a.map(e=>N(pM,{addon:e,onClick:()=>{n([...t,fM(e)])}},e.id))]},e.id)})]})}var hM={person:`#3b82f6`,vehicle:`#f59e0b`,animal:`#22c55e`,face:`#a855f7`,plate:`#ec4899`,bird:`#14b8a6`,dog:`#84cc16`,cat:`#f97316`,car:`#f59e0b`,truck:`#d97706`,bus:`#b45309`,motorcycle:`#eab308`,bicycle:`#ca8a04`,motion:`#facc15`},gM=[`#ef4444`,`#8b5cf6`,`#06b6d4`,`#f97316`,`#10b981`,`#6366f1`,`#e11d48`,`#0891b2`,`#7c3aed`,`#059669`],_M=`#f59e42`;function vM(e,t){if(t?.[e])return t[e];if(t?.[e.toLowerCase()])return t[e.toLowerCase()];if(hM[e])return hM[e];if(hM[e.toLowerCase()])return hM[e.toLowerCase()];let n=0;for(let t=0;t<e.length;t++)n=n*31+(e.codePointAt(t)??0)>>>0;return gM[n%gM.length]??`#f59e42`}h();function yM({src:e,imageWidth:t,imageHeight:n,detections:r=[],classColors:i,aspectRatio:a,className:o,placeholder:s,showConfidence:c=!0,minConfidence:l=0,borderWidth:u=2}){function d(e){return vM(e,i)}let f=a??(t&&n?`${t}/${n}`:`16/9`),p=r.filter(e=>e.score>=l),m=p.filter(e=>e.kind===`first-level`),h=p.filter(e=>e.kind===`detail`),_=CM(h,e=>e.parentId??``);return N(`div`,{className:X(`rounded-lg border border-border bg-surface overflow-hidden relative`,o),style:{aspectRatio:f},children:e?g(w,{children:[N(`img`,{src:e,className:`absolute inset-0 w-full h-full object-fill`,alt:``}),p.map((e,r)=>e.debug?.mask&&e.debug.maskWidth&&e.debug.maskHeight?N(xM,{mask:e.debug.mask,maskWidth:e.debug.maskWidth,maskHeight:e.debug.maskHeight,bbox:e.bbox,imageWidth:t,imageHeight:n,color:d(e.macroClass)},`mask-${r}`):null),m.map(e=>{let r=_.get(e.id)??[];return N(bM,{detection:e,imageWidth:t,imageHeight:n,color:d(e.macroClass),showConfidence:c,borderWidth:e.debug?.mask?1:u,children:r.map(t=>N(SM,{child:t,parentBbox:e.bbox,color:d(t.macroClass),showConfidence:c},`child-${t.id}`))},`det-${e.id}`)}),h.filter(e=>!e.parentId||!m.some(t=>t.id===e.parentId)).map(e=>N(bM,{detection:e,imageWidth:t,imageHeight:n,color:d(e.macroClass),showConfidence:c,borderWidth:u},`orphan-${e.id}`))]}):N(`div`,{className:`w-full h-full flex items-center justify-center text-foreground-subtle text-sm`,children:s??`No image loaded`})})}function bM({detection:e,imageWidth:t,imageHeight:n,color:r,showConfidence:i,borderWidth:a,children:o}){let{x:s,y:c,width:l,height:u}=e.bbox,d=g(`div`,{className:`absolute left-0 flex flex-col items-start gap-px`,style:{bottom:`100%`,marginBottom:`2px`},children:[g(`span`,{className:`text-[10px] px-1 rounded-sm whitespace-nowrap text-white`,style:{backgroundColor:r},children:[e.macroClass,i&&` ${(e.score*100).toFixed(0)}%`]}),e.labels.map((t,n)=>g(`span`,{className:`text-[9px] font-semibold px-1 rounded-sm whitespace-nowrap text-white`,style:{backgroundColor:vM(t.label)},children:[t.label,` `,(t.score*100).toFixed(0),`%`]},`${e.id}-lbl-${n}`))]});return g(`div`,{className:`absolute rounded-sm`,style:{left:`${s/t*100}%`,top:`${c/n*100}%`,width:`${l/t*100}%`,height:`${u/n*100}%`,borderWidth:`${a}px`,borderStyle:`solid`,borderColor:r},children:[d,o]})}function xM({mask:e,maskWidth:t,maskHeight:n,bbox:r,imageWidth:i,imageHeight:a,color:o}){let s=f(null);return P(()=>{let r=s.current;if(!r)return;let i=r.getContext(`2d`);if(!i)return;let a=atob(e),c=new Uint8Array(a.length);for(let e=0;e<a.length;e++)c[e]=a.charCodeAt(e);let l=parseInt(o.slice(1,3),16),u=parseInt(o.slice(3,5),16),d=parseInt(o.slice(5,7),16);r.width=t,r.height=n;let f=i.createImageData(t,n),p=t*n;for(let e=0;e<p;e++){let t=e<c.length?c[e]:0,n=e*4;t>0&&(f.data[n]=l,f.data[n+1]=u,f.data[n+2]=d,f.data[n+3]=120)}i.putImageData(f,0,0)},[e,t,n,o]),N(`canvas`,{ref:s,className:`absolute pointer-events-none`,style:{left:`${r.x/i*100}%`,top:`${r.y/a*100}%`,width:`${r.width/i*100}%`,height:`${r.height/a*100}%`,imageRendering:`pixelated`}})}function SM({child:e,parentBbox:t,color:n,showConfidence:r}){if(t.width<=0||t.height<=0)return null;let i=(e.bbox.x-t.x)/t.width*100,a=(e.bbox.y-t.y)/t.height*100,o=e.bbox.width/t.width*100,s=e.bbox.height/t.height*100;return N(`div`,{className:`absolute rounded-sm`,style:{left:`${Math.max(0,i)}%`,top:`${Math.max(0,a)}%`,width:`${Math.min(100,o)}%`,height:`${Math.min(100,s)}%`,borderWidth:`1px`,borderStyle:`solid`,borderColor:n},children:g(`div`,{className:`absolute left-0 flex flex-col items-start gap-px`,style:{bottom:`100%`,marginBottom:`1px`},children:[g(`span`,{className:`text-[9px] px-0.5 rounded-sm whitespace-nowrap text-white`,style:{backgroundColor:n},children:[e.macroClass,r&&` ${(e.score*100).toFixed(0)}%`]}),e.labels.map((t,n)=>g(`span`,{className:`text-[8px] font-semibold px-0.5 rounded-sm whitespace-nowrap text-white`,style:{backgroundColor:vM(t.label)},children:[t.label,` `,(t.score*100).toFixed(0),`%`]},`${e.id}-lbl-${n}`))]})})}function CM(e,t){let n=new Map;for(let r of e){let e=t(r),i=n.get(e)??[];i.push(r),n.set(e,i)}return n}h();function wM({detections:e,classColors:t,className:n,hiddenKeys:r,onToggleVisibility:i}){let a=t;if(e.length===0)return N(`div`,{className:`text-sm text-foreground-subtle italic text-center py-4`,children:`No detections`});let o=e.filter(e=>e.kind===`first-level`),s=e.filter(e=>e.kind===`detail`),c=new Map;for(let e of s){if(!e.parentId)continue;let t=c.get(e.parentId)??[];t.push(e),c.set(e.parentId,t)}let l=s.filter(e=>!e.parentId||!o.some(t=>t.id===e.parentId));return g(`div`,{className:n,children:[g(`div`,{className:`text-xs font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Detections (`,e.length,`)`]}),g(`div`,{className:`space-y-2`,children:[o.map(e=>N(TM,{detection:e,children_:c.get(e.id)??[],colors:a,hiddenKeys:r,onToggleVisibility:i},e.id)),l.map(e=>N(TM,{detection:e,children_:[],colors:a,hiddenKeys:r,onToggleVisibility:i},e.id))]})]})}function TM({detection:e,children_:t,colors:n,hiddenKeys:r,onToggleVisibility:i}){let a=vM(e.macroClass,n),o=!r?.has(e.id),s=e.debug?.mask,c=e.debug?.maskWidth,l=e.debug?.maskHeight,u=e.debug?.alternateLabels;return g(`div`,{className:`rounded-md border border-border bg-surface p-3 space-y-1 ${o?``:`opacity-40`}`,children:[g(`div`,{className:`flex justify-between items-center`,children:[g(`div`,{className:`flex items-center gap-2`,children:[i&&N(`input`,{type:`checkbox`,checked:o,onChange:()=>i(e.id,!o),className:`h-3.5 w-3.5 rounded border-border accent-primary cursor-pointer shrink-0`}),N(`span`,{className:`h-2.5 w-2.5 rounded-full shrink-0`,style:{backgroundColor:a}}),N(`span`,{className:`text-sm font-medium text-foreground`,children:e.macroClass}),e.kind===`detail`&&N(`span`,{className:`text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary`,children:`detail`}),s&&c&&l&&g(`span`,{className:`text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary`,children:[`mask `,c,`x`,l]})]}),N(OM,{confidence:e.score})]}),g(`div`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`bbox: [`,Math.round(e.bbox.x),`, `,Math.round(e.bbox.y),`,`,` `,Math.round(e.bbox.x+e.bbox.width),`,`,` `,Math.round(e.bbox.y+e.bbox.height),`]`]}),e.labels.length>0&&N(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:e.labels.map((e,t)=>g(`span`,{className:`inline-flex items-center gap-1 text-[10px] font-medium px-1.5 py-0.5 rounded-full`,style:{backgroundColor:vM(e.label,n)+`20`,color:vM(e.label,n)},children:[e.label,g(`span`,{className:`opacity-60`,children:[(e.score*100).toFixed(0),`%`]}),e.detectionId&&g(`span`,{className:`opacity-40 text-[8px]`,children:[`→ `,e.detectionId]})]},t))}),u&&Object.keys(u).length>0&&N(DM,{alternateLabels:u,colors:n}),t.length>0&&N(EM,{items:t,colors:n,hiddenKeys:r,onToggleVisibility:i})]})}function EM({items:e,colors:t,hiddenKeys:n,onToggleVisibility:r}){return N(`div`,{className:`ml-4 mt-1.5 space-y-1.5 border-l-2 border-border pl-3`,children:e.map(e=>{let i=vM(e.macroClass,t),a=!n?.has(e.id),o=e.debug?.mask,s=e.debug?.maskWidth,c=e.debug?.maskHeight;return g(`div`,{className:`text-xs space-y-0.5 ${a?``:`opacity-40`}`,children:[g(`div`,{className:`flex items-center gap-1.5`,children:[r&&N(`input`,{type:`checkbox`,checked:a,onChange:()=>r(e.id,!a),className:`h-3 w-3 rounded border-border accent-primary cursor-pointer shrink-0`}),N(`span`,{className:`h-1.5 w-1.5 rounded-full shrink-0`,style:{backgroundColor:i}}),N(`span`,{className:`font-medium`,style:{color:i},children:e.macroClass}),g(`span`,{className:`text-foreground-subtle`,children:[(e.score*100).toFixed(0),`%`]}),o&&s&&c&&g(`span`,{className:`text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary`,children:[`mask `,s,`x`,c]})]}),e.labels.length>0&&N(`div`,{className:`flex flex-wrap gap-1 ml-5 mt-0.5`,children:e.labels.map((e,n)=>g(`span`,{className:`inline-flex items-center gap-0.5 text-[9px] font-medium px-1 py-0.5 rounded-full`,style:{backgroundColor:vM(e.label,t)+`20`,color:vM(e.label,t)},children:[e.label,` `,g(`span`,{className:`opacity-60`,children:[(e.score*100).toFixed(0),`%`]})]},n))})]},e.id)})})}function DM({alternateLabels:e,colors:t}){let[n,r]=k(!1),i=Object.keys(e);return g(`div`,{className:`mt-1`,children:[g(`button`,{onClick:()=>r(e=>!e),className:`text-[9px] text-foreground-subtle hover:text-foreground transition-colors flex items-center gap-1`,children:[N(`span`,{className:`transition-transform ${n?`rotate-90`:``}`,children:`▶`}),`Alternates (`,i.length,` source`,i.length===1?``:`s`,`)`]}),n&&N(`div`,{className:`mt-1 ml-3 space-y-1.5`,children:i.map(n=>{let r=e[n];return!r||r.length===0?null:g(`div`,{children:[N(`div`,{className:`text-[9px] font-medium text-foreground-subtle mb-0.5`,children:n}),N(`div`,{className:`flex flex-wrap gap-1`,children:r.map((e,r)=>g(`span`,{className:`inline-flex items-center gap-0.5 text-[9px] px-1 py-0.5 rounded-full`,style:{backgroundColor:vM(n,t)+`10`,color:vM(n,t),opacity:Math.max(.4,e.score)},children:[e.label,g(`span`,{className:`opacity-60`,children:[(e.score*100).toFixed(1),`%`]})]},r))})]},n)})})]})}function OM({confidence:e}){return g(`span`,{className:`text-xs font-medium px-2 py-0.5 rounded-full ${e>=.8?`bg-success/10 text-success`:e>=.5?`bg-warning/10 text-warning`:`bg-danger/10 text-danger`}`,children:[(e*100).toFixed(1),`%`]})}function kM({timings:e,totalMs:t,className:n}){let r=Object.entries(e);return r.length===0&&t===void 0?null:g(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-2 ${n??``}`,children:[N(`div`,{className:`text-xs font-medium text-foreground-subtle uppercase tracking-wide`,children:`Timings`}),g(`div`,{className:`space-y-1 text-xs`,children:[r.map(([e,t])=>g(`div`,{className:`flex justify-between`,children:[N(`span`,{className:`text-foreground-subtle`,children:e}),g(`span`,{className:`font-mono text-foreground`,children:[t.toFixed(1),`ms`]})]},e)),t!==void 0&&g(`div`,{className:`flex justify-between pt-1 border-t border-border font-medium text-foreground`,children:[N(`span`,{children:`Total`}),g(`span`,{className:`font-mono`,children:[t.toFixed(1),`ms`]})]})]})]})}function AM({images:e,selectedFilename:t,uploadedName:n,onSelect:r,onUpload:i,className:a,accept:o=`image/*`,uploadLabel:s=`Upload...`}){return g(`div`,{className:`flex flex-wrap items-center gap-2 ${a??``}`,children:[e.map(e=>N(`button`,{onClick:()=>r(e.filename),className:`px-3 py-1.5 text-xs rounded-md border transition-colors ${t===e.filename?`bg-primary text-primary-foreground border-primary`:`bg-surface border-border text-foreground hover:border-primary/50`}`,children:e.id??e.filename.replace(/\.[^.]+$/,``)},e.filename)),N(`button`,{onClick:()=>{let e=document.createElement(`input`);e.type=`file`,e.accept=o,e.addEventListener(`change`,()=>{let t=e.files?.[0];if(!t)return;let n=new FileReader;n.addEventListener(`load`,()=>{let e=n.result,r=e.split(`,`)[1];r&&i(r,t.name,e)}),n.readAsDataURL(t)}),e.click()},className:`px-3 py-1.5 text-xs rounded-md border border-border bg-surface text-foreground hover:bg-surface-hover transition-colors`,children:s}),n&&N(`span`,{className:`text-xs text-foreground-subtle`,children:n})]})}var jM=`w-full px-3 py-2 text-sm rounded-md border border-border bg-surface text-foreground focus:outline-none focus:ring-2 focus:ring-primary/50`;function MM({runtime:e,backend:t,modelId:n,agentId:r=`hub`,runtimes:i,backends:a,models:o,agents:s=[],onRuntimeChange:c,onBackendChange:l,onModelChange:u,onAgentChange:d,layout:f=`grid`,className:p,showAgent:m=!1}){return g(`div`,{className:`${f===`grid`?`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4`:f===`horizontal`?`flex flex-wrap items-end gap-4`:`space-y-3`} ${p??``}`,children:[m&&s.length>0&&g(`label`,{className:`space-y-1`,children:[N(`span`,{className:`text-xs font-medium text-foreground-subtle`,children:`Agent`}),N(`select`,{value:r,onChange:e=>d?.(e.target.value),className:jM,children:s.map(e=>g(`option`,{value:e.id,children:[e.name,` (`,e.status,`)`]},e.id))})]}),g(`label`,{className:`space-y-1`,children:[N(`span`,{className:`text-xs font-medium text-foreground-subtle`,children:`Runtime`}),N(`select`,{value:e,onChange:e=>c(e.target.value),className:jM,children:i.map(e=>g(`option`,{value:e.value,disabled:!e.available,children:[e.label,e.available?``:` (unavailable)`]},e.value))})]}),g(`label`,{className:`space-y-1`,children:[N(`span`,{className:`text-xs font-medium text-foreground-subtle`,children:`Backend`}),N(`select`,{value:t,onChange:e=>l(e.target.value),className:jM,children:a.map(e=>g(`option`,{value:e.id,disabled:!e.available,children:[e.label,e.available?``:` (unavailable)`]},e.id))})]}),g(`label`,{className:`space-y-1`,children:[N(`span`,{className:`text-xs font-medium text-foreground-subtle`,children:`Model`}),N(`select`,{value:n,onChange:e=>u(e.target.value),className:jM,children:o.length===0?N(`option`,{value:``,children:`No compatible models`}):o.map(e=>g(`option`,{value:e.id,children:[e.name,e.downloaded?` ✓`:``]},e.id))})]})]})}var NM=class{constructor(){this.keyToValue=new Map,this.valueToKey=new Map}set(e,t){this.keyToValue.set(e,t),this.valueToKey.set(t,e)}getByKey(e){return this.keyToValue.get(e)}getByValue(e){return this.valueToKey.get(e)}clear(){this.keyToValue.clear(),this.valueToKey.clear()}},PM=class{constructor(e){this.generateIdentifier=e,this.kv=new NM}register(e,t){this.kv.getByValue(e)||(t||=this.generateIdentifier(e),this.kv.set(t,e))}clear(){this.kv.clear()}getIdentifier(e){return this.kv.getByValue(e)}getValue(e){return this.kv.getByKey(e)}},FM=class extends PM{constructor(){super(e=>e.name),this.classToAllowedProps=new Map}register(e,t){typeof t==`object`?(t.allowProps&&this.classToAllowedProps.set(e,t.allowProps),super.register(e,t.identifier)):super.register(e,t)}getAllowedProps(e){return this.classToAllowedProps.get(e)}};function IM(e){if(`values`in Object)return Object.values(e);let t=[];for(let n in e)e.hasOwnProperty(n)&&t.push(e[n]);return t}function LM(e,t){let n=IM(e);if(`find`in n)return n.find(t);let r=n;for(let e=0;e<r.length;e++){let n=r[e];if(t(n))return n}}function RM(e,t){Object.entries(e).forEach(([e,n])=>t(n,e))}function zM(e,t){return e.indexOf(t)!==-1}function BM(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(t(r))return r}}var VM=class{constructor(){this.transfomers={}}register(e){this.transfomers[e.name]=e}findApplicable(e){return LM(this.transfomers,t=>t.isApplicable(e))}findByName(e){return this.transfomers[e]}},HM=e=>Object.prototype.toString.call(e).slice(8,-1),UM=e=>e===void 0,WM=e=>e===null,GM=e=>typeof e!=`object`||!e||e===Object.prototype?!1:Object.getPrototypeOf(e)===null?!0:Object.getPrototypeOf(e)===Object.prototype,KM=e=>GM(e)&&Object.keys(e).length===0,qM=e=>Array.isArray(e),JM=e=>typeof e==`string`,YM=e=>typeof e==`number`&&!isNaN(e),XM=e=>typeof e==`boolean`,ZM=e=>e instanceof RegExp,QM=e=>e instanceof Map,$M=e=>e instanceof Set,eN=e=>HM(e)===`Symbol`,tN=e=>e instanceof Date&&!isNaN(e.valueOf()),nN=e=>e instanceof Error,rN=e=>typeof e==`number`&&isNaN(e),iN=e=>XM(e)||WM(e)||UM(e)||YM(e)||JM(e)||eN(e),aN=e=>typeof e==`bigint`,oN=e=>e===1/0||e===-1/0,sN=e=>ArrayBuffer.isView(e)&&!(e instanceof DataView),cN=e=>e instanceof URL,lN=e=>e.replace(/\\/g,`\\\\`).replace(/\./g,`\\.`),uN=e=>e.map(String).map(lN).join(`.`),dN=(e,t)=>{let n=[],r=``;for(let i=0;i<e.length;i++){let a=e.charAt(i);if(!t&&a===`\\`){let t=e.charAt(i+1);if(t===`\\`){r+=`\\`,i++;continue}else if(t!==`.`)throw Error(`invalid path`)}if(a===`\\`&&e.charAt(i+1)===`.`){r+=`.`,i++;continue}if(a===`.`){n.push(r),r=``;continue}r+=a}let i=r;return n.push(i),n};function fN(e,t,n,r){return{isApplicable:e,annotation:t,transform:n,untransform:r}}var pN=[fN(UM,`undefined`,()=>null,()=>void 0),fN(aN,`bigint`,e=>e.toString(),e=>typeof BigInt<`u`?BigInt(e):(console.error(`Please add a BigInt polyfill.`),e)),fN(tN,`Date`,e=>e.toISOString(),e=>new Date(e)),fN(nN,`Error`,(e,t)=>{let n={name:e.name,message:e.message};return`cause`in e&&(n.cause=e.cause),t.allowedErrorProps.forEach(t=>{n[t]=e[t]}),n},(e,t)=>{let n=Error(e.message,{cause:e.cause});return n.name=e.name,n.stack=e.stack,t.allowedErrorProps.forEach(t=>{n[t]=e[t]}),n}),fN(ZM,`regexp`,e=>``+e,e=>{let t=e.slice(1,e.lastIndexOf(`/`)),n=e.slice(e.lastIndexOf(`/`)+1);return new RegExp(t,n)}),fN($M,`set`,e=>[...e.values()],e=>new Set(e)),fN(QM,`map`,e=>[...e.entries()],e=>new Map(e)),fN(e=>rN(e)||oN(e),`number`,e=>rN(e)?`NaN`:e>0?`Infinity`:`-Infinity`,Number),fN(e=>e===0&&1/e==-1/0,`number`,()=>`-0`,Number),fN(cN,`URL`,e=>e.toString(),e=>new URL(e))];function mN(e,t,n,r){return{isApplicable:e,annotation:t,transform:n,untransform:r}}var hN=mN((e,t)=>eN(e)?!!t.symbolRegistry.getIdentifier(e):!1,(e,t)=>[`symbol`,t.symbolRegistry.getIdentifier(e)],e=>e.description,(e,t,n)=>{let r=n.symbolRegistry.getValue(t[1]);if(!r)throw Error(`Trying to deserialize unknown symbol`);return r}),gN=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,Uint8ClampedArray].reduce((e,t)=>(e[t.name]=t,e),{}),_N=mN(sN,e=>[`typed-array`,e.constructor.name],e=>[...e],(e,t)=>{let n=gN[t[1]];if(!n)throw Error(`Trying to deserialize unknown typed array`);return new n(e)});function vN(e,t){return e?.constructor?!!t.classRegistry.getIdentifier(e.constructor):!1}var yN=mN(vN,(e,t)=>[`class`,t.classRegistry.getIdentifier(e.constructor)],(e,t)=>{let n=t.classRegistry.getAllowedProps(e.constructor);if(!n)return{...e};let r={};return n.forEach(t=>{r[t]=e[t]}),r},(e,t,n)=>{let r=n.classRegistry.getValue(t[1]);if(!r)throw Error(`Trying to deserialize unknown class '${t[1]}' - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564`);return Object.assign(Object.create(r.prototype),e)}),bN=mN((e,t)=>!!t.customTransformerRegistry.findApplicable(e),(e,t)=>[`custom`,t.customTransformerRegistry.findApplicable(e).name],(e,t)=>t.customTransformerRegistry.findApplicable(e).serialize(e),(e,t,n)=>{let r=n.customTransformerRegistry.findByName(t[1]);if(!r)throw Error(`Trying to deserialize unknown custom value`);return r.deserialize(e)}),xN=[yN,hN,bN,_N],SN=(e,t)=>{let n=BM(xN,n=>n.isApplicable(e,t));if(n)return{value:n.transform(e,t),type:n.annotation(e,t)};let r=BM(pN,n=>n.isApplicable(e,t));if(r)return{value:r.transform(e,t),type:r.annotation}},CN={};pN.forEach(e=>{CN[e.annotation]=e});var wN=(e,t,n)=>{if(qM(t))switch(t[0]){case`symbol`:return hN.untransform(e,t,n);case`class`:return yN.untransform(e,t,n);case`custom`:return bN.untransform(e,t,n);case`typed-array`:return _N.untransform(e,t,n);default:throw Error(`Unknown transformation: `+t)}else{let r=CN[t];if(!r)throw Error(`Unknown transformation: `+t);return r.untransform(e,n)}},TN=(e,t)=>{if(t>e.size)throw Error(`index out of bounds`);let n=e.keys();for(;t>0;)n.next(),t--;return n.next().value};function EN(e){if(zM(e,`__proto__`))throw Error(`__proto__ is not allowed as a property`);if(zM(e,`prototype`))throw Error(`prototype is not allowed as a property`);if(zM(e,`constructor`))throw Error(`constructor is not allowed as a property`)}var DN=(e,t)=>{EN(t);for(let n=0;n<t.length;n++){let r=t[n];if($M(e))e=TN(e,+r);else if(QM(e)){let i=+r,a=+t[++n]==0?`key`:`value`,o=TN(e,i);switch(a){case`key`:e=o;break;case`value`:e=e.get(o);break}}else e=e[r]}return e},ON=(e,t,n)=>{if(EN(t),t.length===0)return n(e);let r=e;for(let e=0;e<t.length-1;e++){let n=t[e];if(qM(r)){let e=+n;r=r[e]}else if(GM(r))r=r[n];else if($M(r)){let e=+n;r=TN(r,e)}else if(QM(r)){if(e===t.length-2)break;let i=+n,a=+t[++e]==0?`key`:`value`,o=TN(r,i);switch(a){case`key`:r=o;break;case`value`:r=r.get(o);break}}}let i=t[t.length-1];if(qM(r)?r[+i]=n(r[+i]):GM(r)&&(r[i]=n(r[i])),$M(r)){let e=TN(r,+i),t=n(e);e!==t&&(r.delete(e),r.add(t))}if(QM(r)){let e=+t[t.length-2],a=TN(r,e);switch(+i==0?`key`:`value`){case`key`:{let e=n(a);r.set(e,r.get(a)),e!==a&&r.delete(a);break}case`value`:r.set(a,n(r.get(a)));break}}return e},kN=e=>e<1;function AN(e,t,n,r=[]){if(!e)return;let i=kN(n);if(!qM(e)){RM(e,(e,a)=>AN(e,t,n,[...r,...dN(a,i)]));return}let[a,o]=e;o&&RM(o,(e,a)=>{AN(e,t,n,[...r,...dN(a,i)])}),t(a,r)}function jN(e,t,n,r){return AN(t,(t,n)=>{e=ON(e,n,e=>wN(e,t,r))},n),e}function MN(e,t,n){let r=kN(n);function i(t,n){let i=DN(e,dN(n,r));t.map(e=>dN(e,r)).forEach(t=>{e=ON(e,t,()=>i)})}if(qM(t)){let[n,a]=t;n.forEach(t=>{e=ON(e,dN(t,r),()=>e)}),a&&RM(a,i)}else RM(t,i);return e}var NN=(e,t)=>GM(e)||qM(e)||QM(e)||$M(e)||nN(e)||vN(e,t);function PN(e,t,n){let r=n.get(e);r?r.push(t):n.set(e,[t])}function FN(e,t){let n={},r;return e.forEach(e=>{if(e.length<=1)return;t||(e=e.map(e=>e.map(String)).sort((e,t)=>e.length-t.length));let[i,...a]=e;i.length===0?r=a.map(uN):n[uN(i)]=a.map(uN)}),r?KM(n)?[r]:[r,n]:KM(n)?void 0:n}var IN=(e,t,n,r,i=[],a=[],o=new Map)=>{let s=iN(e);if(!s){PN(e,i,t);let n=o.get(e);if(n)return r?{transformedValue:null}:n}if(!NN(e,n)){let t=SN(e,n),r=t?{transformedValue:t.value,annotations:[t.type]}:{transformedValue:e};return s||o.set(e,r),r}if(zM(a,e))return{transformedValue:null};let c=SN(e,n),l=c?.value??e,u=qM(l)?[]:{},d={};RM(l,(s,c)=>{if(c===`__proto__`||c===`constructor`||c===`prototype`)throw Error(`Detected property ${c}. This is a prototype pollution risk, please remove it from your object.`);let l=IN(s,t,n,r,[...i,c],[...a,e],o);u[c]=l.transformedValue,qM(l.annotations)?d[lN(c)]=l.annotations:GM(l.annotations)&&RM(l.annotations,(e,t)=>{d[lN(c)+`.`+t]=e})});let f=KM(d)?{transformedValue:u,annotations:c?[c.type]:void 0}:{transformedValue:u,annotations:c?[c.type,d]:d};return s||o.set(e,f),f};function LN(e){return Object.prototype.toString.call(e).slice(8,-1)}function RN(e){return LN(e)===`Array`}function zN(e){if(LN(e)!==`Object`)return!1;let t=Object.getPrototypeOf(e);return!!t&&t.constructor===Object&&t===Object.prototype}function BN(e,t,n,r,i){let a={}.propertyIsEnumerable.call(r,t)?`enumerable`:`nonenumerable`;a===`enumerable`&&(e[t]=n),i&&a===`nonenumerable`&&Object.defineProperty(e,t,{value:n,enumerable:!1,writable:!0,configurable:!0})}function VN(e,t={}){if(RN(e))return e.map(e=>VN(e,t));if(!zN(e))return e;let n=Object.getOwnPropertyNames(e),r=Object.getOwnPropertySymbols(e);return[...n,...r].reduce((n,r)=>{if(r===`__proto__`||RN(t.props)&&!t.props.includes(r))return n;let i=e[r];return BN(n,r,VN(i,t),e,t.nonenumerable),n},{})}var $=class{constructor({dedupe:e=!1}={}){this.classRegistry=new FM,this.symbolRegistry=new PM(e=>e.description??``),this.customTransformerRegistry=new VM,this.allowedErrorProps=[],this.dedupe=e}serialize(e){let t=new Map,n=IN(e,t,this,this.dedupe),r={json:n.transformedValue};n.annotations&&(r.meta={...r.meta,values:n.annotations});let i=FN(t,this.dedupe);return i&&(r.meta={...r.meta,referentialEqualities:i}),r.meta&&(r.meta.v=1),r}deserialize(e,t){let{json:n,meta:r}=e,i=t?.inPlace?n:VN(n);return r?.values&&(i=jN(i,r.values,r.v??0,this)),r?.referentialEqualities&&(i=MN(i,r.referentialEqualities,r.v??0)),i}stringify(e){return JSON.stringify(this.serialize(e))}parse(e){return this.deserialize(JSON.parse(e),{inPlace:!0})}registerClass(e,t){this.classRegistry.register(e,t)}registerSymbol(e,t){this.symbolRegistry.register(e,t)}registerCustom(e,t){this.customTransformerRegistry.register({name:t,...e})}allowErrorProps(...e){this.allowedErrorProps.push(...e)}};$.defaultInstance=new $,$.serialize=$.defaultInstance.serialize.bind($.defaultInstance),$.deserialize=$.defaultInstance.deserialize.bind($.defaultInstance),$.stringify=$.defaultInstance.stringify.bind($.defaultInstance),$.parse=$.defaultInstance.parse.bind($.defaultInstance),$.registerClass=$.defaultInstance.registerClass.bind($.defaultInstance),$.registerSymbol=$.defaultInstance.registerSymbol.bind($.defaultInstance),$.registerCustom=$.defaultInstance.registerCustom.bind($.defaultInstance),$.allowErrorProps=$.defaultInstance.allowErrorProps.bind($.defaultInstance),$.serialize,$.deserialize,$.stringify,$.parse,$.registerClass,$.registerCustom,$.registerSymbol,$.allowErrorProps;var HN=1e4,UN=6e3,WN=2e3,GN=3e4,KN=class{_serverUrl;useWs;baseRetryMs;maxRetryMs;onConnectionChange;token;_trpcClient;_wsClient=null;mirror=null;mirrorInit=null;connected=!1;connectedPromise=null;_systemProxy;_connectionVersion=0;connectionListeners=new Set;constructor(e){this._serverUrl=e.serverUrl.replace(/\/+$/,``),this.token=e.token;let t=typeof window<`u`;this.useWs=e.useWebSocket??t,this.onConnectionChange=e.onConnectionChange,this.baseRetryMs=e.retryDelayMs??WN,this.maxRetryMs=e.maxRetryDelayMs??GN,this._trpcClient=this.buildTrpcClient(),this._systemProxy=se(this._trpcClient)}get serverUrl(){return this._serverUrl}get connectionVersion(){return this._connectionVersion}subscribeConnectionEvents(e){return this.connectionListeners.add(e),()=>{this.connectionListeners.delete(e)}}emitConnectionEvent(e){try{this.onConnectionChange?.(e)}catch{}for(let t of this.connectionListeners)try{t(e,this._connectionVersion)}catch{}}async awaitConnected(e){if(this.connected)return;if(this.connectedPromise)return this.connectedPromise;let t=e??15e3;this.connectedPromise=(async()=>{let e=this._trpcClient.auth.me.query();Number.isFinite(t)?await new Promise((n,r)=>{let i=setTimeout(()=>r(Error(`System.awaitConnected: probe timed out after ${t}ms`)),t);e.then(()=>{clearTimeout(i),n()},e=>{clearTimeout(i),r(e instanceof Error?e:Error(String(e)))})}):await e,this.connected=!0})();try{await this.connectedPromise}finally{this.connectedPromise=null}}async init(e){if(this.mirror?.isReady())return;if(this.mirrorInit)return this.mirrorInit;let t=new oe(this._trpcClient);return this.mirror=t,this.mirrorInit=(async()=>{await this.awaitConnected(e),await t.init(e)})().finally(()=>{this.mirrorInit=null}),this.mirrorInit}async awaitReady(){if(!this.mirror?.isReady())return this.mirrorInit?this.mirrorInit:this.init()}isReady(){return this.mirror?.isReady()??!1}isConnected(){return this.connected}reconnect(){this.useWs&&(this.emitConnectionEvent(`connecting`),this._wsClient?.close(),this.disposeMirror(),this.connected=!1,this.connectedPromise=null,this._trpcClient=this.buildTrpcClient(),this._systemProxy=se(this._trpcClient))}switchServerUrl(e){let t=e.replace(/\/+$/,``);t!==this._serverUrl&&(this._serverUrl=t,this.reconnect())}async raceConnectionEndpoints(e){let t=e?.perCandidateTimeoutMs??1500,n=(()=>{try{return new URL(this._serverUrl)}catch{return null}})(),r=n?.port?Number(n.port):n?.protocol===`https:`?443:80,i=n?.protocol===`https:`?`https`:`http`,a=this._trpcClient.localNetwork?.getConnectionEndpoints;if(!a)return{winner:this._serverUrl,switched:!1};let o;try{o=(await a.query({port:r,ipv4Only:e?.ipv4Only,scheme:i})).endpoints}catch{return{winner:this._serverUrl,switched:!1}}if(o.length===0)return{winner:this._serverUrl,switched:!1};let s=await JN(o.map(e=>e.baseUrl),t);return!s||s===this._serverUrl?{winner:s??this._serverUrl,switched:!1}:(this.switchServerUrl(s),{winner:s,switched:!0})}close(){this.disposeMirror(),this.connected=!1,this.connectedPromise=null,this._wsClient?.close()}disposeMirror(){this.mirror?.dispose(),this.mirror=null,this.mirrorInit=null}async login(e,t){let n=await this._trpcClient.auth.login.mutate({username:e,password:t});if(typeof n==`object`&&n&&`token`in n){let e=n,t=e.token,r=e.requiresTotp===!0||Array.isArray(e.secondFactors)&&e.secondFactors.length>0;typeof t==`string`&&!r&&this.setToken(t)}return n}async loginVerifyTotp(e,t){let n=await this._trpcClient.auth.loginVerifyTotp.mutate({challengeToken:e,code:t});if(typeof n==`object`&&n&&`token`in n){let e=n.token;typeof e==`string`&&this.setToken(e)}return n}async loginBeginPasskey(e){return await this._trpcClient.auth.loginBeginPasskey.mutate({challengeToken:e})}async loginVerifyPasskey(e,t){let n=await this._trpcClient.auth.loginVerifyPasskey.mutate({challengeToken:e,response:t});if(typeof n==`object`&&n&&`token`in n){let e=n.token;typeof e==`string`&&this.setToken(e)}return n}async passkeyLoginBegin(){return await this._trpcClient.auth.passkeyLoginBegin.mutate()}async passkeyLoginFinish(e){let t=await this._trpcClient.auth.passkeyLoginFinish.mutate({response:e});if(typeof t==`object`&&t&&`token`in t){let e=t,n=e.requiresTotp===!0||Array.isArray(e.secondFactors)&&e.secondFactors.length>0;typeof e.token==`string`&&!n&&this.setToken(e.token)}return t}async logout(){await this._trpcClient.auth.logout.mutate()}async getMe(){return await this._trpcClient.auth.me.query()}async changeOwnPassword(e){return await this._trpcClient.auth.changeOwnPassword.mutate(e)}async setupOwnTotp(){return await this._trpcClient.auth.setupOwnTotp.mutate()}async confirmOwnTotp(e){return await this._trpcClient.auth.confirmOwnTotp.mutate(e)}async disableOwnTotp(){return await this._trpcClient.auth.disableOwnTotp.mutate()}async getOwnTotpStatus(){return await this._trpcClient.auth.getOwnTotpStatus.query()}async beginOwnPasskeyRegistration(){return await this._trpcClient.auth.beginOwnPasskeyRegistration.mutate()}async finishOwnPasskeyRegistration(e){return await this._trpcClient.auth.finishOwnPasskeyRegistration.mutate(e)}async listOwnPasskeys(){return await this._trpcClient.auth.listOwnPasskeys.query()}async removeOwnPasskey(e){return await this._trpcClient.auth.removeOwnPasskey.mutate(e)}async getOwnPasskeySecondFactorPreference(){return await this._trpcClient.auth.getOwnPasskeySecondFactorPreference.query()}async setOwnPasskeySecondFactorPreference(e){return await this._trpcClient.auth.setOwnPasskeySecondFactorPreference.mutate(e)}setToken(e){this.token=e}listDevices(e){return this.mirror?(e?this.mirror.query(e):this.mirror.getAllDevices()).map(e=>this.attachBinding(e)):[]}getDeviceInfo(e){return this.mirror?.getDeviceInfo(e)??null}listDeviceInfos(e){let t=this.mirror;if(!t)return[];let n=e?t.query(e):t.getAllDevices(),r=[];for(let e of n){let n=t.getDeviceInfo(e.deviceId);n&&r.push(n)}return r}getDevice(e){let t=this.mirror?.getDeviceById(e)??null;return t?this.attachBinding(t):null}getDeviceByName(e){let t=this.mirror?.getDeviceByName(e)??null;return t?this.attachBinding(t):null}getDeviceByStableId(e){let t=this.mirror?.getDeviceByStableId(e)??null;return t?this.attachBinding(t):null}async waitForDevice(e,t){this.mirror||await this.init();let n=await this.mirror.waitForDevice(e,t??3e4);return this.attachBinding(n)}onDeviceAdded(e){if(!this.mirror)throw Error(`System.onDeviceAdded: call init() before subscribing`);return this.mirror.onDeviceAdded(e)}onDeviceRemoved(e){if(!this.mirror)throw Error(`System.onDeviceRemoved: call init() before subscribing`);return this.mirror.onDeviceRemoved(e)}attachBinding(e){let t=this.lookupBinding(e.deviceId);if(t===e.binding)return e;let n=e;return n.binding=t,e}lookupBinding(e){return this.mirror?this.mirror.getDeviceById(e)?.binding??null:null}get addonPages(){return this._systemProxy.addonPages}get addonSettings(){return this._systemProxy.addonSettings}get alerts(){return this._systemProxy.alerts}get audioAnalyzer(){return this._systemProxy.audioAnalyzer}get audioCodec(){return this._systemProxy.audioCodec}get backup(){return this._systemProxy.backup}get decoder(){return this._systemProxy.decoder}get deviceManager(){return this._systemProxy.deviceManager}get deviceProvider(){return this._systemProxy.deviceProvider}get deviceState(){return this._systemProxy.deviceState}get metricsProvider(){return this._systemProxy.metricsProvider}get notificationOutput(){return this._systemProxy.notificationOutput}get pipelineExecutor(){return this._systemProxy.pipelineExecutor}get pipelineOrchestrator(){return this._systemProxy.pipelineOrchestrator}get pipelineRunner(){return this._systemProxy.pipelineRunner}get settingsStore(){return this._systemProxy.settingsStore}get storage(){return this._systemProxy.storage}get streamBroker(){return this._systemProxy.streamBroker}get turnProvider(){return this._systemProxy.turnProvider}get userManagement(){return this._systemProxy.userManagement}subscribeEvent(e,t){let n=this._trpcClient.live.onEvent.subscribe({category:e},{onData:e=>{try{t(e)}catch{}}});return()=>{try{n.unsubscribe()}catch{}}}get trpcClient(){return this._trpcClient}get wsClient(){return this._wsClient}buildTrpcClient(){let e=()=>{let e={};return this.token&&(e.Authorization=`Bearer ${this.token}`),e};if(this.useWs){let e=this._serverUrl.replace(/^http/,`ws`)+`/trpc`,t=this.baseRetryMs,n=this.maxRetryMs;return this._wsClient=st({url:e,connectionParams:()=>({token:this.token}),retryDelayMs:e=>Math.min(t*2**e,n),keepAlive:{enabled:!0,intervalMs:HN,pongTimeoutMs:UN},onOpen:()=>{this._connectionVersion+=1,this.emitConnectionEvent(`connected`)},onClose:()=>{this.emitConnectionEvent(`disconnected`)}}),ft({links:[ct({client:this._wsClient,transformer:$})]})}return this._wsClient=null,ft({links:[dt({url:`${this._serverUrl}/trpc`,headers:e,transformer:$})]})}};function qN(e){return new KN(e)}async function JN(e,t){if(e.length===0)return null;if(typeof fetch!=`function`)return e[0]??null;let n=typeof window<`u`&&window.location!==void 0&&window.location.protocol===`https:`?e.filter(e=>e.toLowerCase().startsWith(`https://`)):e;if(n.length===0)return null;let r=n.map(()=>new AbortController),i=n.map(async(e,n)=>{let i=r[n],a=setTimeout(()=>i.abort(),t);try{let t=await fetch(`${e.replace(/\/+$/,``)}/trpc/health`,{method:`GET`,signal:i.signal,credentials:`omit`});if(!t.ok)throw Error(`${t.status}`);return e}finally{clearTimeout(a)}});try{let e=await Promise.any(i);for(let e of r)try{e.abort()}catch{}return e}catch{return null}}var YN=function(e){return e.Motion=`motion`,e.Person=`person`,e.Vehicle=`vehicle`,e.Animal=`animal`,e.Audio=`audio`,e.Face=`face`,e.Plate=`plate`,e.Package=`package`,e.Doorbell=`doorbell`,e.Sensor=`sensor`,e}({}),XN=`animal.dog_cat.dog.cat.horse.sheep.cow.elephant.bear.zebra.giraffe.mouse.rabbit.deer.lion.tiger.bird.eagle.owl.pigeon.fish.whale.dolphin.snake.turtle.lizard`.split(`.`),ZN=[`person`,`people`,`pedestrian`,`rider`,`driver`,`cyclist`,`skier`,`skateboarder`,`face`,`hand`,`head`,`body`],QN=[`vehicle`,`car`,`truck`,`bus`,`motorcycle`,`bicycle`,`van`,`ambulance`,`police_car`,`fire_truck`,`train`,`subway`,`tram`,`airplane`,`boat`,`ship`,`helicopter`],$N=`face.eyes.nose.mouth.ears.eyebrows.left_eye.right_eye.pupil.iris.eyelid.eye_corner.upper_lip.lower_lip.teeth.chin.cheek.forehead.jaw.glasses.sunglasses.facial_hair.beard.mustache.facial_landmark.facial_keypoint`.split(`.`),eP=[`plate`,`license_plate`,`front_plate`,`rear_plate`,`motorcycle_plate`,`temporary_plate`,`dealer_plate`,`licensePlate`,`plate_number`,`plate_character`,`plate_digit`,`plate_letter`,`plate_symbol`,`plate_region`,`plate_country_identifier`,`plate_frame`,`plate_bolt`,`plate_sticker`,`plate_validation_tag`,`damaged_plate`,`obscured_plate`,`dirty_plate`],tP=[`motion`,`movement`,`other`],nP=[`package`,`packet`],rP=[`audio`],iP=`speech.scream.babbling.yell.bellow.whoop.whispering.laughter.snicker.crying.cry.sigh.singing.choir.chant.mantra.child_singing.rapping.humming.groan.grunt.whistling.breathing.wheeze.snoring.gasp.pant.snort.cough.throat_clearing.sneeze.sniff.cheering.applause.chatter.crowd.children_playing.bark.yip.howl.bow-wow.growling.whimper_dog.purr.meow.hiss.caterwaul.pets.livestock.doorbell.ding-dong.door.slam.knock.alarm.telephone.music.dog.dogs`.split(`.`),aP=[`doorbell`,`ring`],oP=[`lock`,`binary`,`flood`,`entry`,`door`,`leak`,`door_open`,`flooded`,`entry_open`],sP={...XN.reduce((e,t)=>({...e,[t]:`animal`}),{}),...ZN.reduce((e,t)=>({...e,[t]:`person`}),{}),...QN.reduce((e,t)=>({...e,[t]:`vehicle`}),{}),...tP.reduce((e,t)=>({...e,[t]:`motion`}),{}),...nP.reduce((e,t)=>({...e,[t]:`package`}),{}),...$N.reduce((e,t)=>({...e,[t]:`face`}),{}),...eP.reduce((e,t)=>({...e,[t]:`plate`}),{}),...rP.reduce((e,t)=>({...e,[t]:`audio`}),{}),...iP.reduce((e,t)=>({...e,[t]:`audio`}),{}),...aP.reduce((e,t)=>({...e,[t]:`doorbell`}),{}),...oP.reduce((e,t)=>({...e,[t]:`sensor`}),{})},cP=e=>$N.includes(e),lP=e=>eP.includes(e),uP=e=>XN.includes(e),dP=e=>ZN.includes(e),fP=e=>QN.includes(e),pP=e=>tP.includes(e),mP=e=>aP.includes(e),hP=e=>nP.includes(e),gP=e=>rP.includes(e)||iP.includes(e),_P=e=>oP.includes(e),vP=e=>cP(e)||lP(e),yP=e=>sP[e],bP=e=>{let{className:t}=e,n={face:`person`,plate:`vehicle`},r=sP[t];return r&&r!==t?r:n[t]},xP=Object.values(YN),SP=xP.filter(e=>e!==`motion`),CP=[`person`,`doorbell`,`package`],wP=[...CP,`vehicle`,`animal`,`audio`,`face`,`plate`],TP=[...SP];function EP(e,t){switch(e){case`critical`:return CP;case`important`:return wP;case`all`:return TP;case`custom`:return t?.length?t:SP;default:return SP}}var DP={Light:`light`,Switch:`switch`,WindowCovering:`cover`,Lock:`lock`,SecuritySystem:`alarm`,Buttons:`button`,Select:`select`,Siren:`siren`,Sensor:`sensor`,Entry:`entry`,Program:`script`,MediaPlayer:`media_player`,Outlet:`switch`,light:`light`,switch:`switch`,input_boolean:`switch`,cover:`cover`,lock:`lock`,alarm_control_panel:`alarm`,input_button:`button`,button:`button`,input_select:`select`,select:`select`,siren:`siren`,sensor:`sensor`,media_player:`media_player`,script:`script`},OP={light:`light`,switch:`switch`,input_boolean:`switch`,cover:`cover`,lock:`lock`,alarm_control_panel:`alarm`,input_button:`button`,button:`button`,input_select:`select`,select:`select`,siren:`siren`,sensor:`sensor`,binary_sensor:`sensor`,media_player:`media_player`,script:`script`,climate:`climate`,camera:`camera`,fan:`fan`,vacuum:`vacuum`,automation:`automation`,scene:`scene`,input_number:`sensor`,person:`person`,device_tracker:`tracker`,weather:`weather`,water_heater:`climate`},kP={Light:`light`,Switch:`switch`,WindowCovering:`cover`,Lock:`lock`,SecuritySystem:`alarm`,Buttons:`button`,Select:`select`,Siren:`siren`,Sensor:`sensor`,Entry:`entry`,Program:`script`,MediaPlayer:`media_player`,Camera:`camera`,Doorbell:`doorbell`,Fan:`fan`,Outlet:`switch`};function AP(e){return DP[e]||(DP[e.toLowerCase()]??null)}var jP=[`Entry`,`Light`,`Switch`,`Lock`,`SecuritySystem`,`Buttons`,`WindowCovering`,`Siren`,`Sensor`,`Select`,`Program`],MP=new Set(jP),NP=[`light`,`switch`,`input_boolean`,`cover`,`lock`,`alarm_control_panel`,`input_button`,`button`,`input_select`,`select`,`siren`,`media_player`,`script`],PP=new Set(NP),FP=[{id:`liveStream`,label:`Live Stream`,sources:{frigate:!0,scrypted:!0,rtsp:!0},adapterMethod:`getLiveStream`},{id:`multiResolution`,label:`Multi-Resolution`,sources:{frigate:!0,scrypted:!0,rtsp:!1},adapterMethod:`getResolutions`},{id:`motion`,label:`Motion Detection`,sources:{frigate:!1,scrypted:!0,rtsp:!1},adapterMethod:`getMotion`},{id:`objectDetection`,label:`Object Detection`,sources:{frigate:!1,scrypted:!0,rtsp:!1},adapterMethod:`getObjectDetections`},{id:`audioVolume`,label:`Audio Level`,sources:{frigate:!1,scrypted:!0,rtsp:!1},adapterMethod:`getAudioVolume`},{id:`audioVolumes`,label:`Audio Volumes (dBFS)`,sources:{frigate:!1,scrypted:!0,rtsp:!1},adapterMethod:`getAudioVolumes`},{id:`ptz`,label:`PTZ Control`,sources:{frigate:!1,scrypted:!0,rtsp:!1},adapterMethod:`getPTZ`},{id:`intercom`,label:`Intercom (Mic)`,sources:{frigate:!1,scrypted:!0,rtsp:!1},adapterMethod:`getIntercomSupport`},{id:`deviceStatus`,label:`Device Status`,sources:{frigate:!1,scrypted:!0,rtsp:!1},adapterMethod:`getStatus`},{id:`timeline`,label:`Detection Timeline`,sources:{frigate:!0,scrypted:!0,rtsp:!1},adapterMethod:`getCameraDayData`},{id:`clusteredTimeline`,label:`Clustered Timeline`,sources:{frigate:!0,scrypted:!0,rtsp:!1},requiresBackend:!0,adapterMethod:`getClusteredDayData`},{id:`detectionClasses`,label:`Detection Classes`,sources:{frigate:!0,scrypted:!0,rtsp:!1},adapterMethod:`getDetectionClasses`},{id:`videoClips`,label:`Video Clips`,sources:{frigate:!0,scrypted:!0,rtsp:!1},adapterMethod:`getVideoClips`},{id:`nvrPlayback`,label:`NVR Playback`,sources:{frigate:!0,scrypted:!0,rtsp:!1},adapterMethod:`getNvrPlaybackSupported`},{id:`nvrScrub`,label:`NVR Scrub/Seek`,sources:{frigate:!1,scrypted:!0,rtsp:!1},adapterMethod:`seekRecordingStream`},{id:`recordingThumbnail`,label:`Recording Thumbnails`,sources:{frigate:!0,scrypted:!0,rtsp:!1},adapterMethod:`getRecordingStreamThumbnail`},{id:`nvrSeekToLive`,label:`Seek to Live`,sources:{frigate:!1,scrypted:!0,rtsp:!1},adapterMethod:`seekNvrToLive`}];function IP(e,t,n){let r=FP.find(t=>t.id===e);return!(!r||!r.sources[t]||r.platforms&&r.platforms[n]===!1)}function LP(e){return FP.filter(t=>t.sources[e])}function RP(){return FP.filter(e=>e.requiresBackend)}var zP=e({DEFAULT_ENABLED_CLASSES:()=>SP,DetectionClass:()=>YN,ELIGIBLE_HA_DOMAINS:()=>NP,ELIGIBLE_HA_DOMAINS_SET:()=>PP,ELIGIBLE_SCRYPTED_DEVICE_TYPES:()=>jP,ELIGIBLE_SCRYPTED_DEVICE_TYPES_SET:()=>MP,FEATURE_MATRIX:()=>FP,HA_DOMAIN_TYPE_MAP:()=>OP,RAW_TO_CANONICAL:()=>DP,SCRYPTED_TYPE_TO_CANONICAL:()=>kP,System:()=>KN,TIMELINE_PRESET_ALL:()=>TP,TIMELINE_PRESET_CRITICAL:()=>CP,TIMELINE_PRESET_IMPORTANT:()=>wP,animalClasses:()=>XN,audioClasses:()=>rP,audioLabelClasses:()=>iP,createSystem:()=>qN,defaultDetectionClasses:()=>xP,detectionClassesDefaultMap:()=>sP,doorbellClasses:()=>aP,faceClasses:()=>$N,getBackendRequiredFeatures:()=>RP,getCanonicalDeviceType:()=>AP,getClassesForTimelinePreset:()=>EP,getParentClass:()=>yP,getParentDetectionClass:()=>bP,getSourceFeatures:()=>LP,isAnimalClassname:()=>uP,isAudioClassname:()=>gP,isDoorbellClassname:()=>mP,isFaceClassname:()=>cP,isFeatureAvailable:()=>IP,isLabelDetection:()=>vP,isMotionClassname:()=>pP,isPackageClassname:()=>hP,isPersonClassname:()=>dP,isPlateClassname:()=>lP,isSensorLabelClassname:()=>_P,isVehicleClassname:()=>fP,licensePlateClasses:()=>eP,motionClasses:()=>tP,packageClasses:()=>nP,personClasses:()=>ZN,raceFastestEndpoint:()=>JN,sensorLabelClasses:()=>oP,vehicleClasses:()=>QN});h();function BP({className:e}){return g(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,children:[N(`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`}),N(`circle`,{cx:`12`,cy:`12`,r:`3`})]})}function VP({className:e}){return g(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,children:[N(`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`}),N(`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`}),N(`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`}),N(`path`,{d:`m2 2 20 20`})]})}function HP({className:e}){return N(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,children:N(`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`})})}function UP({onLogin:e,serverUrl:t,logoSrc:n,error:r,className:i}){let[a,o]=k(``),[s,c]=k(``),[l,u]=k(!1),[d,f]=k(!1),[p,m]=k(null),h=r??p;return N(`div`,{className:X(`flex min-h-screen items-center justify-center bg-background p-4`,i),children:g(`div`,{className:`w-full max-w-sm`,children:[n&&N(`div`,{className:`flex justify-center mb-8`,children:N(`img`,{src:n,alt:`Logo`,className:`h-12`})}),t&&N(`p`,{className:`mb-4 text-center text-xs text-foreground-subtle truncate`,children:t}),g(`form`,{onSubmit:async t=>{if(t.preventDefault(),!d){m(null),f(!0);try{await e(a,s)}catch(e){m(e instanceof Error?e.message:`Login failed. Please try again.`)}finally{f(!1)}}},className:`space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10`,children:[h&&N(`div`,{className:`rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger`,children:h}),g(`div`,{className:`space-y-1.5`,children:[N(`label`,{className:`text-xs font-medium text-foreground-subtle`,children:`Username`}),N(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),autoComplete:`username`,required:!0,className:`w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary`})]}),g(`div`,{className:`space-y-1.5`,children:[N(`label`,{className:`text-xs font-medium text-foreground-subtle`,children:`Password`}),g(`div`,{className:`relative`,children:[N(`input`,{type:l?`text`:`password`,value:s,onChange:e=>c(e.target.value),autoComplete:`current-password`,required:!0,className:`w-full rounded-lg border border-border bg-background px-3 py-2.5 pr-10 text-sm text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary`}),N(`button`,{type:`button`,onClick:()=>u(e=>!e),className:`absolute right-2.5 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground`,tabIndex:-1,children:N(l?VP:BP,{className:`h-4 w-4`})})]})]}),g(`button`,{type:`submit`,disabled:d,className:`w-full rounded-lg bg-primary px-4 py-2.5 text-sm font-semibold text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex items-center justify-center gap-2`,children:[d&&N(HP,{className:`h-4 w-4 animate-spin`}),d?`Logging in...`:`Log in`]})]})]})})}h();var WP=`camstack_dev_token`,GP=c(null);function KP(){let e=p(GP);if(!e)throw Error(`useDevShell must be used within a DevShell`);return e}function qP(){return typeof window>`u`?null:localStorage.getItem(WP)}function JP({className:e}){return g(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,children:[N(`circle`,{cx:`12`,cy:`12`,r:`4`}),N(`path`,{d:`M12 2v2`}),N(`path`,{d:`M12 20v2`}),N(`path`,{d:`m4.93 4.93 1.41 1.41`}),N(`path`,{d:`m17.66 17.66 1.41 1.41`}),N(`path`,{d:`M2 12h2`}),N(`path`,{d:`M20 12h2`}),N(`path`,{d:`m6.34 17.66-1.41 1.41`}),N(`path`,{d:`m19.07 4.93-1.41 1.41`})]})}function YP({className:e}){return N(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,children:N(`path`,{d:`M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z`})})}function XP({children:e,serverUrl:t,title:n,token:r,onLogout:i}){let a=Pt(),o=b(()=>[lt({condition:e=>e.type===`subscription`,true:ct({client:st({url:t.replace(/^http/,`ws`)+`/trpc`,connectionParams:()=>({token:r})}),transformer:$}),false:dt({url:`${t}/trpc`,transformer:$,headers:()=>({authorization:`Bearer ${r}`})})})],[t,r]),s=b(()=>ft({links:o}),[o]),c=b(()=>Z.createClient({links:o}),[o]),l=b(()=>qN({serverUrl:t,token:r}),[t,r]);P(()=>(l.init().catch(()=>void 0),()=>{l.close()}),[l]);let u=b(()=>new T,[]),d=b(()=>({trpc:s,token:r,logout:i}),[s,r,i]);return N(Ie,{system:l,children:N(Z.Provider,{client:c,queryClient:u,children:N(j,{client:u,children:N(GP.Provider,{value:d,children:g(`div`,{className:`min-h-screen bg-background text-foreground`,children:[g(`div`,{className:`flex items-center justify-between border-b border-border bg-surface px-4 py-2`,children:[g(`div`,{className:`flex items-center gap-2`,children:[N(`span`,{className:`rounded bg-warning/20 px-2 py-0.5 text-xs font-bold text-warning`,children:`DEV MODE`}),n&&N(`span`,{className:`text-sm font-medium text-foreground`,children:n}),N(`span`,{className:`text-xs text-foreground-subtle`,children:t})]}),g(`div`,{className:`flex items-center gap-2`,children:[g(`button`,{type:`button`,onClick:a.toggleMode,className:`flex items-center gap-1.5 rounded-md px-2 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Theme: ${a.mode}`,children:[a.resolvedMode===`dark`?N(JP,{className:`h-3.5 w-3.5`}):N(YP,{className:`h-3.5 w-3.5`}),a.mode===`dark`?`Dark`:a.mode===`light`?`Light`:`System`]}),N(`button`,{type:`button`,onClick:i,className:`rounded-md px-2.5 py-1 text-xs font-medium text-danger hover:bg-danger/10 transition-colors`,children:`Logout`})]})]}),N(`div`,{className:`p-4`,children:e({trpc:s,theme:a})})]})})})})})}function ZP({children:e,serverUrl:t=`https://localhost:4443`,title:n}){let[r,i]=k(qP),a=u(async(e,n)=>{let r=await ft({links:[dt({url:`${t}/trpc`,transformer:$})]}).auth.login.mutate({username:e,password:n});if(!r.token)throw Error(`No token returned`);localStorage.setItem(WP,r.token),i(r.token)},[t]),o=u(()=>{localStorage.removeItem(WP),i(null)},[]);return r?N(Nt,{children:N(XP,{serverUrl:t,title:n,token:r,onLogout:o,children:e})}):N(Nt,{children:N(UP,{onLogin:a,serverUrl:t})})}h();function QP(e,t={}){let{serverUrl:n=`https://localhost:4443`,title:r,rootId:i=`root`}=t,a=document.getElementById(i);if(!a){console.error(`[mountAddonPage] Element #${i} not found`);return}ot(a).render(m(ZP,{serverUrl:n,title:r,children:({trpc:t,theme:n})=>m(e,{trpc:t,theme:{isDark:n.resolvedMode===`dark`},navigate:e=>{console.log(`[dev] navigate:`,e)}})}))}h();var $P=Me(`camstack:custom-field-renderers`,{});function eF({renderers:e,children:t}){return N($P.Provider,{value:e,children:t})}function tF(e){return p($P)[e]??null}h();var nF=Me(`camstack:device-context`,null);function rF({deviceId:e,device:t,children:n}){let r={deviceId:e,device:t??null};return N(nF.Provider,{value:r,children:n})}function iF(){return p(nF)?.deviceId??null}function aF(){return p(nF)?.device??null}h();var oF=Me(`camstack:widget-registry`,null),sF=new Map,cF=new Map,lF=new Set;function uF(e,t){return`${e}::${t}`}function dF(e){if(!e||typeof e!=`object`)return!1;let t=e.default;return typeof t==`object`&&!!t}function fF(e){if(!e||typeof e!=`object`)return typeof e;let t=e,n=Object.getPrototypeOf(t),r=n&&typeof n==`object`?n.constructor?.name:void 0;return{ownKeys:Object.keys(t),allKeys:Object.getOwnPropertyNames(t),proto:typeof r==`string`?r:void 0}}async function pF(e,n,i){let a=uF(e,n),o=sF.get(a);if(o)return o;let s=cF.get(a);if(s)return s;lF.has(e)||(zr(),r([{name:e,entry:i,type:`module`}],{force:!1}),lF.add(e));let c=t(`${e}/${n.startsWith(`./`)?n.slice(2):n}`).then(t=>{if(!dF(t)){let r=fF(t);throw Error(`Remote ${e} (${i}) does not expose a default record on '${n}'. Got: ${JSON.stringify(r)}`)}let r=t.default;return sF.set(a,r),cF.delete(a),r}).catch(e=>{throw cF.delete(a),e});return cF.set(a,c),c}function mF(e,t){return sF.get(uF(e,t))}var hF=3e4,gF=2e3;function _F({children:e}){let t=O(),n=f(Date.now()),{data:r}=_d(void 0,{staleTime:0,refetchOnMount:`always`,refetchInterval:e=>{let t=e.state.data;return t&&t.length>0||Date.now()-n.current>=hF?!1:gF}});il(`addon.widget-ready`,()=>{t.invalidateQueries({queryKey:[[`addonWidgets`,`listWidgets`]]})});let[i,a]=k(0),o=b(()=>r??[],[r]);P(()=>{if(o.length===0)return;let e=!1,t=new Set;for(let n of o){let r=uF(n.remote.remoteName,n.remote.exposedModule);if(t.has(r)||(t.add(r),sF.has(r)))continue;let i=n.bundleUrl;pF(n.remote.remoteName,n.remote.exposedModule,i).then(()=>{e||a(e=>e+1)}).catch(e=>{let t=e instanceof Error?e.message:String(e);(typeof globalThis<`u`?globalThis.console:void 0)?.error?.(`[WidgetRegistry] Failed to load widget remote`,{remoteName:n.remote.remoteName,exposedModule:n.remote.exposedModule,entryUrl:i,reason:t})})}return()=>{e=!0}},[o]);let s=b(()=>{let e=new Map,t=new Map;for(let n of o)e.set(`${n.addonId}/${n.stableId}`,n),t.set(n.remote.remoteName,n.bundleUrl);let n=(e,t)=>({widgetId:e,addonId:t.addonId,stableId:t.stableId,tab:t.tab,subTab:t.subTab,label:t.label,order:t.order,kind:t.kind,remote:t.remote,description:t.description,icon:t.icon,bundleUrl:t.bundleUrl,hosts:t.hosts,requires:t.requires,defaultSize:t.defaultSize,allowedSizes:t.allowedSizes,defaultColumns:t.defaultColumns,defaultRows:t.defaultRows});return{resolve:t=>{let n=e.get(t);if(!n)return;let r=mF(n.remote.remoteName,n.remote.exposedModule);if(!r)return null;let i=r[n.remote.componentKey??n.stableId];if(i)return i},metadata:t=>{let r=e.get(t);if(r)return n(t,r)},listAll:()=>{let t=[];for(let[r,i]of e)t.push(n(r,i));return t},entryUrlFor:e=>t.get(e)}},[o,i]);return N(oF.Provider,{value:s,children:e})}function vF(e){return SF().resolve(e)}function yF(e){return SF().metadata(e)}function bF(){return SF().listAll()}function xF(e,t){let n=CF(),r=t??n?.entryUrlFor(e.remoteName),[i,a]=k(0),[o,s]=k(!1);return P(()=>{if(!r||(s(!1),mF(e.remoteName,e.exposedModule)))return;let t=!1;return pF(e.remoteName,e.exposedModule,r).then(()=>{t||a(e=>e+1)}).catch(n=>{let i=n instanceof Error?n.message:String(n);(typeof globalThis<`u`?globalThis.console:void 0)?.error?.(`[WidgetRegistry] Failed to load remote component`,{remoteName:e.remoteName,exposedModule:e.exposedModule,entryUrl:r,reason:i}),t||s(!0)}),()=>{t=!0}},[e.remoteName,e.exposedModule,r]),b(()=>{if(!r||o)return;let t=mF(e.remoteName,e.exposedModule);if(!t)return null;let n=e.componentKey;return n===void 0?Object.values(t)[0]??void 0:t[n]??void 0},[e.remoteName,e.exposedModule,e.componentKey,r,i,o])}function SF(){let e=CF();if(!e)throw Error(`useWidgetRegistry(): no <WidgetRegistryProvider> in tree`);return e}function CF(){return wF(oF)}function wF(e){return p(e)}h();function TF({deviceId:e}){let t=Fe(Ke().trpcClient,e),[n,r]=k(null),[i,a]=k(!1);P(()=>{if(!t)return;let e=!1;return(async()=>{try{let n=await t.ptz?.getStatus({});if(e||!n)return;r(n.autofocus)}catch{}})(),()=>{e=!0}},[t]);let o=u(async()=>{if(!(!t?.ptz||n===null)){a(!0);try{let e=!n;await t.ptz.setAutofocus({enabled:e}),r(e)}catch(e){console.error(`ptz.setAutofocus failed`,e)}finally{a(!1)}}},[t,n]);return n===null?null:g(`div`,{className:`flex items-center justify-between border-t border-border/40 mt-2 pt-2`,children:[N(`span`,{className:`text-[10.5px] font-semibold text-foreground`,children:`Autofocus`}),g(`button`,{type:`button`,onClick:()=>void o(),disabled:i,"aria-pressed":n,className:`flex items-center gap-1.5 rounded-md px-2 py-1 text-[10px] font-medium transition-colors ${n?`bg-success/15 text-success hover:bg-success/25`:`bg-surface-elevated/40 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`} disabled:opacity-50`,children:[N(`span`,{className:`h-1.5 w-1.5 rounded-full ${n?`bg-success`:`bg-foreground-subtle/40`}`}),n?`On`:`Off`]})]})}function EF({deviceId:e}){let t=Ke(),n=Number.isFinite(e),r=Ql(t.trpcClient,n?e:0,{enabled:n});if(!n)return g(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let i=r.options?.hasAutofocus===!0;return g(Je,{title:`PTZ`,icon:N(Wa,{className:`h-3.5 w-3.5 text-foreground-subtle`}),bodyClassName:`p-3 flex flex-col overflow-y-auto`,children:[N(eu,{controls:r,mode:`panel`}),i&&N(TF,{deviceId:e})]})}h();var DF=15;function OF(e){return e.status===`replace`||e.level!==null&&e.level<=DF}function kF(e){try{return new Date(e).toLocaleDateString(void 0,{year:`numeric`,month:`short`,day:`numeric`})}catch{return``}}function AF({item:e,busy:t,canReset:n,onReset:r}){let i=OF(e),a=i?`bg-warning`:`bg-success`;return g(`div`,{className:`flex flex-col gap-1.5 rounded-md border p-3 ${i?`border-warning/40 bg-warning/5`:`border-border/40 bg-surface-elevated/30`}`,children:[g(`div`,{className:`flex items-center justify-between gap-2`,children:[N(`span`,{className:`text-xs font-semibold ${i?`text-warning`:`text-foreground`}`,children:e.label}),e.resettable&&N(`button`,{type:`button`,onClick:()=>r(e.key),disabled:t||!n,className:`rounded-md border border-border bg-surface px-2 py-0.5 text-[10px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:`Replaced`})]}),e.level===null?e.status===null?N(`span`,{className:`text-[10px] text-foreground-subtle`,children:`—`}):N(`span`,{className:`inline-flex w-fit items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium ${e.status===`replace`?`bg-warning/15 text-warning`:`bg-success/15 text-success`}`,children:e.status===`replace`?`Replace`:`OK`}):g(`div`,{className:`flex items-center gap-2`,children:[N(`div`,{className:`h-1.5 flex-1 overflow-hidden rounded-full bg-surface-elevated/60`,children:N(`div`,{className:`h-full rounded-full ${a} transition-all`,style:{width:`${Math.max(0,Math.min(100,e.level))}%`}})}),g(`span`,{className:`text-[10px] font-medium tabular-nums text-foreground-subtle`,children:[Math.round(e.level),`%`]})]}),e.lastResetAt!==null&&g(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`Replaced `,kF(e.lastResetAt)]})]})}function jF({deviceId:e}){let t=Ke(),n=Number.isFinite(e),{cap:r,slice:i,available:a}=Q({trpc:t.trpcClient,deviceId:n?e:null,cap:e=>e.consumables,slice:e=>e.state.consumables}),[o,s]=k(null),c=u(async e=>{if(r){s(e);try{await r.reset({key:e})}catch(e){console.error(`consumables.reset failed`,e)}finally{s(null)}}},[r]),l=i?.items??[];return N(Je,{title:`Consumables`,icon:N(fa,{className:`h-3.5 w-3.5 text-foreground-subtle`}),bodyClassName:`p-3 overflow-y-auto`,children:l.length===0?N(`p`,{className:`text-[11px] text-foreground-subtle italic leading-relaxed`,children:`No consumables reported.`}):N(`div`,{className:`flex flex-col gap-2`,children:l.map(e=>N(AF,{item:e,busy:o===e.key,canReset:a,onReset:e=>void c(e)},e.key))})})}h();function MF(e){let t=O(),n=hx({deviceId:e??0},{enabled:e!==null&&Number.isFinite(e),refetchInterval:5e3,retry:1}),r=gx({onSuccess:()=>{t.invalidateQueries({queryKey:[[`ptzAutotrack`]]})}}),i=vx({onSuccess:()=>{t.invalidateQueries({queryKey:[[`ptzAutotrack`]]})}}),a=u(async t=>{e!==null&&await r.mutateAsync({deviceId:e,enabled:t})},[e,r]),o=u(async t=>{e!==null&&await i.mutateAsync({deviceId:e,settings:t})},[e,i]),s=n.error?n.error.message:r.error?r.error.message:i.error?i.error.message:null;return{status:n.data??null,isLoading:n.isLoading,isPending:r.isPending||i.isPending,error:s,setEnabled:a,setSettings:o}}h();function NF({deviceId:e}){let{status:t,isLoading:n,isPending:r,error:i,setEnabled:a,setSettings:o}=MF(Number.isFinite(e)?e:null),[s,c]=k({targetType:``,stopDelaySeconds:30,disappearDelaySeconds:15}),[l,u]=k(!1);P(()=>{if(l)return;let e=t?.currentSettings;e&&c({targetType:e.targetType,stopDelaySeconds:e.stopDelaySeconds,disappearDelaySeconds:e.disappearDelaySeconds})},[t,l]);let d=N(Ki,{className:`h-3.5 w-3.5 text-foreground-subtle`});return n&&!t?N(Je,{title:`Autotrack`,icon:d,children:g(`div`,{className:`flex items-center gap-2 text-[10.5px] text-foreground-subtle`,children:[N(Ea,{className:`h-3 w-3 animate-spin`}),`Loading autotrack…`]})}):g(Je,{title:`Autotrack`,icon:d,headerRight:g(`button`,{type:`button`,onClick:()=>{a(!(t?.enabled??!1))},disabled:r,className:`flex items-center gap-1.5 rounded-md px-2 py-1 text-[10px] font-medium transition-colors ${t?.enabled?`bg-success/15 text-success hover:bg-success/25`:`bg-surface-elevated/40 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`} disabled:opacity-50`,"aria-pressed":t?.enabled??!1,children:[N(`span`,{className:`h-1.5 w-1.5 rounded-full ${t?.enabled?`bg-success`:`bg-foreground-subtle/40`}`}),t?.enabled?`Enabled`:`Disabled`]}),bodyClassName:`p-3 space-y-2`,children:[i&&g(`div`,{className:`flex items-start gap-1.5 rounded-md border border-danger/30 bg-danger/5 px-2 py-1.5 text-[10px] text-danger`,children:[N(Oi,{className:`h-3 w-3 flex-shrink-0 mt-0.5`}),N(`span`,{className:`leading-snug break-words`,children:i})]}),g(`div`,{className:`grid grid-cols-2 gap-2 px-2`,children:[(t?.supportedTargetTypes?.length??0)>0&&g(`label`,{className:`col-span-2 flex flex-col gap-1`,children:[N(`span`,{className:`text-[10px] font-medium text-foreground-subtle`,children:`Target type`}),N(`select`,{value:s.targetType,onFocus:()=>u(!0),onChange:e=>c(t=>({...t,targetType:e.target.value})),onBlur:()=>{u(!1);let e=t?.currentSettings?.targetType??``;s.targetType!==e&&o({targetType:s.targetType})},disabled:r,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground focus:border-primary focus:outline-none disabled:opacity-50`,children:(t?.supportedTargetTypes??[]).map(e=>N(`option`,{value:e.value,children:e.label},e.value))})]}),g(`label`,{className:`flex flex-col gap-1`,children:[N(`span`,{className:`text-[10px] font-medium text-foreground-subtle`,children:`Stop delay (s)`}),N(`input`,{type:`number`,min:0,max:300,value:s.stopDelaySeconds,onFocus:()=>u(!0),onChange:e=>c(t=>({...t,stopDelaySeconds:Number(e.target.value)||0})),onBlur:()=>{u(!1);let e=t?.currentSettings?.stopDelaySeconds??30;s.stopDelaySeconds!==e&&o({stopDelaySeconds:s.stopDelaySeconds})},disabled:r,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground focus:border-primary focus:outline-none disabled:opacity-50`})]}),g(`label`,{className:`flex flex-col gap-1`,children:[N(`span`,{className:`text-[10px] font-medium text-foreground-subtle`,children:`Disappear delay (s)`}),N(`input`,{type:`number`,min:0,max:300,value:s.disappearDelaySeconds,onFocus:()=>u(!0),onChange:e=>c(t=>({...t,disappearDelaySeconds:Number(e.target.value)||0})),onBlur:()=>{u(!1);let e=t?.currentSettings?.disappearDelaySeconds??15;s.disappearDelaySeconds!==e&&o({disappearDelaySeconds:s.disappearDelaySeconds})},disabled:r,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground focus:border-primary focus:outline-none disabled:opacity-50`})]})]}),N(`p`,{className:`px-2 text-[9.5px] text-foreground-subtle leading-snug italic`,children:`Settings save on blur. Vendor support varies — Reolink honours all three; Hikvision honours target type + stop delay only (disappear delay is accepted but ignored at firmware push).`})]})}function PF(){return{schedule:{kind:`always`},mode:`continuous`,preBufferSec:0,postBufferSec:0,resetTimeoutOnNewEvent:!0}}function FF(e){return e===`onMotion`||e===`onAudioThreshold`}function IF(e,t,n){return e.map((e,r)=>r===t?{...e,...n}:e)}function LF(e,t){return e.filter((e,n)=>n!==t)}function RF(e){return e.schedules&&e.schedules.length>0?[...e.schedules]:e.schedule?[e.schedule]:[]}function zF(e){return{mode:e.mode??(e.enabled?`continuous`:`off`),profiles:e.profiles,segmentSeconds:e.segmentSeconds,schedules:RF(e),triggers:e.triggers??{},preBufferSec:e.preBufferSec,postBufferSec:e.postBufferSec,retention:e.retention}}function BF(e){return{enabled:e.mode!==`off`,mode:e.mode,profiles:e.profiles?[...e.profiles]:void 0,segmentSeconds:e.segmentSeconds,schedules:e.schedules.length>0?[...e.schedules]:void 0,triggers:Object.keys(e.triggers).length>0?e.triggers:void 0,preBufferSec:e.preBufferSec,postBufferSec:e.postBufferSec,retention:e.retention}}function VF(e){return e.mode==null&&(e.rules?.length??0)>0}var HF=[{d:0,label:`S`},{d:1,label:`M`},{d:2,label:`T`},{d:3,label:`W`},{d:4,label:`T`},{d:5,label:`F`},{d:6,label:`S`}];function UF(e){return e===`onMotion`||e===`onAudioThreshold`?e:`continuous`}function WF(e,t){return t===`onAudioThreshold`?{mode:t,thresholdDbfs:e.thresholdDbfs??-30}:t===`onMotion`?{mode:t,thresholdDbfs:void 0}:{mode:t,preBufferSec:0,postBufferSec:0,thresholdDbfs:void 0}}function GF({schedule:e,onChange:t}){let n=n=>{let r=e.days??[0,1,2,3,4,5,6],i=r.includes(n)?r.filter(e=>e!==n):[...r,n].toSorted((e,t)=>e-t);t({...e,days:i})};return g(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[N(`input`,{type:`time`,value:e.start,onChange:n=>t({...e,start:n.target.value}),className:`rounded-md border border-border bg-background px-2 py-1 text-xs`}),N(`span`,{children:`–`}),N(`input`,{type:`time`,value:e.end,onChange:n=>t({...e,end:n.target.value}),className:`rounded-md border border-border bg-background px-2 py-1 text-xs`}),N(`div`,{className:`flex gap-1`,children:HF.map(({d:t,label:r})=>N(`button`,{type:`button`,onClick:()=>n(t),className:`h-6 w-6 rounded text-[10px] ${!e.days||e.days.includes(t)?`bg-primary text-primary-foreground`:`bg-surface-hover text-foreground-subtle`}`,children:r},t))})]})}function KF({rules:e,onChange:t}){return g(`div`,{className:`space-y-2`,children:[e.length===0?N(`p`,{className:`text-xs text-foreground-subtle`,children:`No rules — recording is continuous (always) when enabled.`}):null,e.map((n,r)=>g(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:[g(`div`,{className:`flex items-center justify-between gap-2`,children:[g(`select`,{className:`rounded-md border border-border bg-background px-2 py-1 text-xs`,value:n.schedule.kind,onChange:n=>{t(IF(e,r,{schedule:n.target.value===`timeOfDay`?{kind:`timeOfDay`,start:`00:00`,end:`23:59`}:{kind:`always`}}))},children:[N(`option`,{value:`always`,children:`Always`}),N(`option`,{value:`timeOfDay`,children:`Time of day`})]}),N(`button`,{type:`button`,onClick:()=>t(LF(e,r)),className:`text-foreground-subtle hover:text-red-500`,children:N(rs,{className:`h-4 w-4`})})]}),n.schedule.kind===`timeOfDay`?N(GF,{schedule:n.schedule,onChange:n=>t(IF(e,r,{schedule:n}))}):null,g(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[g(`select`,{className:`rounded-md border border-border bg-background px-2 py-1 text-xs`,value:n.mode,onChange:i=>t(IF(e,r,WF(n,UF(i.target.value)))),children:[N(`option`,{value:`continuous`,children:`Continuous`}),N(`option`,{value:`onMotion`,children:`On motion`}),N(`option`,{value:`onAudioThreshold`,children:`On audio`})]}),FF(n.mode)?g(w,{children:[g(`label`,{className:`flex items-center gap-1`,children:[`pre`,N(`input`,{type:`number`,min:0,value:n.preBufferSec,onChange:n=>t(IF(e,r,{preBufferSec:Number(n.target.value)})),className:`w-14 rounded-md border border-border bg-background px-1 py-1 text-xs`}),`s`]}),g(`label`,{className:`flex items-center gap-1`,children:[`post`,N(`input`,{type:`number`,min:0,value:n.postBufferSec,onChange:n=>t(IF(e,r,{postBufferSec:Number(n.target.value)})),className:`w-14 rounded-md border border-border bg-background px-1 py-1 text-xs`}),`s`]}),g(`label`,{className:`flex items-center gap-1`,children:[N(`input`,{type:`checkbox`,checked:n.resetTimeoutOnNewEvent,onChange:n=>t(IF(e,r,{resetTimeoutOnNewEvent:n.target.checked}))}),`reset`]})]}):null,n.mode===`onAudioThreshold`?g(`label`,{className:`flex items-center gap-1`,children:[`thr`,N(`input`,{type:`number`,value:n.thresholdDbfs??-30,onChange:n=>t(IF(e,r,{thresholdDbfs:Number(n.target.value)})),className:`w-16 rounded-md border border-border bg-background px-1 py-1 text-xs`}),`dBFS`]}):null]})]},r)),g(`button`,{type:`button`,onClick:()=>t([...e,PF()]),className:`flex items-center gap-1 rounded-md border border-dashed border-border px-3 py-1.5 text-xs text-foreground-subtle hover:border-primary hover:text-foreground`,children:[N($a,{className:`h-3.5 w-3.5`}),` Add rule`]})]})}var qF=[{value:1,label:`Mon`},{value:2,label:`Tue`},{value:3,label:`Wed`},{value:4,label:`Thu`},{value:5,label:`Fri`},{value:6,label:`Sat`},{value:0,label:`Sun`}];function JF(){return{kind:`timeOfDay`,start:`09:00`,end:`18:00`}}function YF({schedules:e,onChange:t}){let n=(n,r)=>t(e.map((e,t)=>t===n?r:e)),r=n=>t(e.filter((e,t)=>t!==n));return g(`div`,{className:`space-y-2`,children:[e.length===0?N(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Always (24/7) — add a band to restrict hours.`}):e.map((e,t)=>N(XF,{band:e,onChange:e=>n(t,e),onRemove:()=>r(t)},t)),g(`button`,{type:`button`,onClick:()=>t([...e,JF()]),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($a,{className:`h-3 w-3`}),` Add band`]})]})}function XF({band:e,onChange:t,onRemove:n}){if(e.kind===`always`)return g(`div`,{className:`flex items-center gap-2 text-xs`,children:[N(`span`,{className:`flex-1`,children:`Always`}),N(`button`,{type:`button`,onClick:()=>t(JF()),className:`text-foreground-subtle hover:text-foreground underline`,children:`Set band`}),N(`button`,{type:`button`,onClick:n,"aria-label":`Remove band`,className:`text-foreground-subtle hover:text-red-500`,children:N(Bo,{className:`h-3.5 w-3.5`})})]});let r=e.days??[],i=n=>{let i=r.includes(n)?r.filter(e=>e!==n):[...r,n];t({...e,days:i.length>0?i:void 0})};return g(`div`,{className:`space-y-1.5 rounded-md border border-border p-2`,children:[g(`div`,{className:`flex items-center gap-2 text-xs`,children:[N(`input`,{type:`time`,value:e.start,onChange:n=>t({...e,start:n.target.value}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),N(`span`,{className:`text-foreground-subtle`,children:`→`}),N(`input`,{type:`time`,value:e.end,onChange:n=>t({...e,end:n.target.value}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),N(`span`,{className:`flex-1`}),N(`button`,{type:`button`,onClick:n,"aria-label":`Remove band`,className:`text-foreground-subtle hover:text-red-500`,children:N(Bo,{className:`h-3.5 w-3.5`})})]}),g(`div`,{className:`flex flex-wrap gap-1`,children:[qF.map(e=>N(`button`,{type:`button`,onClick:()=>i(e.value),className:`rounded px-1.5 py-0.5 text-[10px] ${r.includes(e.value)?`bg-primary text-primary-foreground`:`bg-surface-hover text-foreground-subtle`}`,children:e.label},e.value)),r.length===0?N(`span`,{className:`self-center text-[10px] text-foreground-subtle`,children:`every day`}):null]})]})}h();var ZF=[`high`,`mid`,`low`],QF=[{value:`off`,label:`Off`},{value:`events`,label:`Events`},{value:`continuous`,label:`Continuous`}];function $F({initial:e,saving:t,onSave:n}){let[r,i]=k(VF(e)?`advanced`:`base`),[a,o]=k(zF(e)),[s,c]=k(e.enabled),[l,u]=k(e.rules?[...e.rules]:[]),[d,f]=k({profiles:e.profiles,segmentSeconds:e.segmentSeconds,retention:e.retention}),p=d.retention??{},m=e=>f({...d,retention:{...p,...e}}),h=e=>e===``?void 0:Number(e),_=e=>{let t=d.profiles??[...ZF],n=t.includes(e)?t.filter(t=>t!==e):[...t,e];f({...d,profiles:n.length?n:void 0})},v=e=>o({...a,triggers:{...a.triggers,...e}}),y=e=>{e===`advanced`&&l.length===0&&u([PF()]),i(e)};return g(`div`,{className:`space-y-4`,children:[N(`div`,{className:`flex gap-1 text-xs`,children:[`base`,`advanced`].map(e=>N(`button`,{type:`button`,onClick:()=>y(e),className:`rounded px-2.5 py-1 ${r===e?`bg-primary text-primary-foreground`:`bg-surface-hover text-foreground-subtle`}`,children:e===`base`?`Base`:`Advanced (rules)`},e))}),r===`base`?g(`div`,{className:`space-y-4`,children:[g(`div`,{className:`flex items-center gap-2 text-xs`,children:[N(`span`,{className:`text-foreground-subtle`,children:`Mode:`}),QF.map(e=>N(`button`,{type:`button`,onClick:()=>o({...a,mode:e.value}),className:`rounded px-2.5 py-1 ${a.mode===e.value?`bg-primary text-primary-foreground`:`bg-surface-hover text-foreground-subtle`}`,children:e.label},e.value))]}),a.mode===`off`?null:g(`div`,{children:[N(`div`,{className:`mb-1.5 text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Time bands`}),N(YF,{schedules:a.schedules,onChange:e=>o({...a,schedules:e})})]}),a.mode===`events`?g(`div`,{className:`space-y-2`,children:[N(`div`,{className:`text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Trigger`}),g(`label`,{className:`flex items-center gap-2 text-xs`,children:[N(`input`,{type:`checkbox`,checked:a.triggers.motion??!1,onChange:e=>v({motion:e.target.checked?!0:void 0})}),`Motion`]}),g(`label`,{className:`flex items-center gap-2 text-xs`,children:[N(`input`,{type:`checkbox`,checked:a.triggers.audioThresholdDbfs!=null,onChange:e=>v({audioThresholdDbfs:e.target.checked?-30:void 0})}),`Audio above threshold`,a.triggers.audioThresholdDbfs==null?null:N(`input`,{type:`number`,value:a.triggers.audioThresholdDbfs,onChange:e=>v({audioThresholdDbfs:h(e.target.value)}),className:`w-16 rounded-md border border-border bg-background px-1 py-0.5 text-xs`}),N(`span`,{className:`text-foreground-subtle`,children:`dBFS`})]}),g(`div`,{className:`flex flex-wrap items-center gap-3 text-xs`,children:[g(`label`,{className:`flex items-center gap-1`,children:[`Pre-buffer`,N(`input`,{type:`number`,min:0,value:a.preBufferSec??``,placeholder:`0`,onChange:e=>o({...a,preBufferSec:h(e.target.value)}),className:`w-16 rounded-md border border-border bg-background px-1 py-1 text-xs`}),`s`]}),g(`label`,{className:`flex items-center gap-1`,children:[`Post-buffer`,N(`input`,{type:`number`,min:0,value:a.postBufferSec??``,placeholder:`0`,onChange:e=>o({...a,postBufferSec:h(e.target.value)}),className:`w-16 rounded-md border border-border bg-background px-1 py-1 text-xs`}),`s`]})]})]}):null]}):g(`div`,{className:`space-y-4`,children:[g(`label`,{className:`flex items-center gap-2 text-xs`,children:[N(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked)}),`Record this camera`]}),g(`div`,{children:[N(`div`,{className:`mb-1.5 text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Rules`}),N(KF,{rules:l,onChange:u})]})]}),g(`div`,{className:`flex flex-wrap items-center gap-4 text-xs`,children:[g(`div`,{className:`flex items-center gap-2`,children:[N(`span`,{className:`text-foreground-subtle`,children:`Profiles:`}),ZF.map(e=>N(`button`,{type:`button`,onClick:()=>_(e),className:`rounded px-2 py-1 ${d.profiles==null||d.profiles.includes(e)?`bg-primary text-primary-foreground`:`bg-surface-hover text-foreground-subtle`}`,children:e},e))]}),g(`label`,{className:`flex items-center gap-1`,children:[`Segment`,N(`input`,{type:`number`,min:1,value:d.segmentSeconds??``,placeholder:`default`,onChange:e=>f({...d,segmentSeconds:h(e.target.value)}),className:`w-16 rounded-md border border-border bg-background px-1 py-1 text-xs`}),`s`]})]}),g(`div`,{children:[N(`div`,{className:`mb-1.5 text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Retention (empty = node default)`}),g(`div`,{className:`flex flex-wrap items-center gap-3 text-xs`,children:[g(`label`,{className:`flex items-center gap-1`,children:[`Max age`,N(`input`,{type:`number`,min:0,value:p.maxAgeDays??``,placeholder:`14`,onChange:e=>m({maxAgeDays:h(e.target.value)}),className:`w-16 rounded-md border border-border bg-background px-1 py-1 text-xs`}),`days`]}),g(`label`,{className:`flex items-center gap-1`,children:[`Max size`,N(`input`,{type:`number`,min:0,value:p.maxSizeGb??``,placeholder:`∞`,onChange:e=>m({maxSizeGb:h(e.target.value)}),className:`w-16 rounded-md border border-border bg-background px-1 py-1 text-xs`}),`GB`]})]})]}),N(`div`,{className:`flex justify-end`,children:g(`button`,{type:`button`,disabled:t,onClick:()=>{n(r===`base`?BF({...a,profiles:d.profiles,segmentSeconds:d.segmentSeconds,retention:d.retention}):{enabled:s,rules:l,profiles:d.profiles?[...d.profiles]:void 0,segmentSeconds:d.segmentSeconds,retention:d.retention})},className:`flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-60`,children:[t?N(Ea,{className:`h-3.5 w-3.5 animate-spin`}):N(lo,{className:`h-3.5 w-3.5`}),` `,`Save`]})})]})}h();var eI=Me(`camstack:vod-playback`,{request:null,play:()=>{},clear:()=>{}});function tI({children:e}){let[t,n]=k(null),r=b(()=>({request:t,play:e=>n(e),clear:()=>n(null)}),[t]);return N(eI.Provider,{value:r,children:e})}function nI(){return p(eI)}h();var rI=Me(`camstack:recorded-playback`,{bindControlChannel:null,channelOpen:!1,mode:`live`,positionMs:null,send:()=>!1});function iI({children:e}){let t=f(null),[n,r]=k(!1),[i,a]=k(`live`),[o,s]=k(null),c=u(e=>{t.current=e;let n=()=>{t.current===e&&(t.current=null,r(!1),a(`live`),s(null))};e.onopen=()=>{t.current===e&&r(!0)},e.onclose=n,e.onerror=n,e.onmessage=n=>{if(t.current!==e)return;let r=n.data;if(typeof r!=`string`)return;let i=Ur(r);i&&(i.kind===`position`?s(i.epochMs):(a(i.state),i.state===`live`&&s(null)))},e.readyState===`open`?r(!0):e.readyState===`closed`||e.readyState===`closing`?n():r(!1)},[]),l=u(e=>{let n=t.current;return!n||n.readyState!==`open`?!1:(n.send(Br(e)),!0)},[]),d=b(()=>({bindControlChannel:c,channelOpen:n,mode:i,positionMs:o,send:l}),[c,n,i,o,l]);return N(rI.Provider,{value:d,children:e})}function aI(){return p(rI)}function oI(e){let t=e.filter(e=>e.endMs>e.startMs).map(e=>({startMs:e.startMs,endMs:e.endMs})).toSorted((e,t)=>e.startMs-t.startMs),n=[];for(let e of t){let t=n[n.length-1];t&&e.startMs<=t.endMs?e.endMs>t.endMs&&(n[n.length-1]={startMs:t.startMs,endMs:e.endMs}):n.push(e)}return n}function sI(e){if(!Number.isFinite(e)||e<0)return`—`;if(e<1024)return`${Math.round(e)} B`;let t=[`KB`,`MB`,`GB`,`TB`,`PB`],n=e/1024,r=`KB`;for(let e of t){if(r=e,n<1024)break;n/=1024}return`${n>=100?Math.round(n).toString():n.toFixed(1)} ${r}`}var cI=[`object`,`motion`,`audio`];function lI(e,t,n){let r=[];for(let i of e){let e={motion:i.motion,object:i.object,audio:i.audio},a=e.motion+e.object+e.audio;if(a===0)continue;let o=Math.floor((i.bucketStart-t)/n),s=null,c=-1;for(let t of cI)e[t]>c&&(c=e[t],s=t);r.push({index:o,startMs:i.bucketStart,endMs:i.bucketStart+n,counts:e,total:a,dominant:s})}return r.toSorted((e,t)=>e.index-t.index)}function uI(e,t){return e<t.startMs?t.startMs-e:e>t.endMs?e-t.endMs:0}function dI(e,t){if(t.length===0)return null;let n=t.find(t=>e>=t.startMs&&e<=t.endMs);if(n)return{fromMs:e,toMs:n.endMs};let r=null,i=1/0;for(let n of t){let t=uI(e,n);t<i&&(i=t,r=n)}return r?{fromMs:r.startMs,toMs:r.endMs}:null}function fI(e,t,n){let r=n-t;if(r<=0)return 0;let i=(e-t)/r*100;return i<0?0:i>100?100:i}function pI(e,t){let n=new Date(e.getFullYear(),e.getMonth(),e.getDate(),0,0,0,0).getTime(),r=new Date(e.getFullYear(),e.getMonth(),e.getDate()+1,0,0,0,0).getTime();return{fromMs:n,toMs:Math.max(n,Math.min(r,t))}}var mI=[24*36e5,12*36e5,6*36e5,36e5,15*6e4];function hI(e,t,n){if(t>=e.toMs-e.fromMs)return e;let r=Math.min(Math.max(n,e.fromMs+t),e.toMs);return{fromMs:r-t,toMs:r}}function gI(e,t,n){let r=e.toMs-e.fromMs,i=e.fromMs+n,a=e.toMs+n;return i<t.fromMs&&(i=t.fromMs,a=i+r),a>t.toMs&&(a=t.toMs,i=a-r),{fromMs:i,toMs:a}}var _I=[15*6e4,5*6e4,6e4,3e4,15e3,5e3];function vI(e){let t=e/100;for(let e of _I)if(e<=t)return e;return _I[_I.length-1]??5e3}function yI(e,t,n){if(n<=1)return[{pct:0,label:new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})}];let r=[];for(let i=0;i<n;i++){let a=e+i/(n-1)*(t-e),o=fI(a,e,t),s=new Date(a).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`});r.push({pct:o,label:s})}return r}h();function bI({windowFrom:e,windowTo:t,spans:n,playheadMs:r,onSeek:i,onScrubStart:a,onScrubMove:o,onScrubEnd:s}){let[c,l]=k(null),u=!!s,[d,p]=k(!1),m=f(null),h=n=>{let r=n.currentTarget.getBoundingClientRect();if(r.width<=0)return null;let i=(n.clientX-r.left)/r.width;return e+Math.min(1,Math.max(0,i))*(t-e)},_=e=>{if(u)return;let t=h(e);t!==null&&i(t)},v=e=>{if(!u)return;e.currentTarget.setPointerCapture(e.pointerId),p(!0),a?.();let t=h(e);t!==null&&(m.current=t,o?.(t))},y=e=>{if(!u||!d)return;let t=h(e);t!==null&&(m.current=t,o?.(t))},b=e=>{if(!u||!d)return;p(!1);let t=h(e)??m.current;m.current=null,t!==null&&s?.(t)},x=()=>{if(!d)return;p(!1);let e=m.current;m.current=null,e!==null&&s?.(e)},S=e=>{let t=h(e);if(t===null)return;let n=e.currentTarget.getBoundingClientRect();l({xPct:n.width>0?(e.clientX-n.left)/n.width*100:0,ms:t})},C=()=>{l(null)},w=c===null?null:new Date(c.ms).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`});return g(`div`,{className:`relative`,children:[g(`div`,{"data-testid":`coverage-track`,"data-scrubbing":d?`true`:`false`,onClick:_,onPointerDown:v,onPointerMove:y,onPointerUp:b,onPointerCancel:x,onMouseMove:S,onMouseLeave:C,className:`relative h-5 overflow-hidden rounded bg-background/40 ${u?`cursor-ew-resize touch-none select-none`:`cursor-pointer`}`,role:`group`,"aria-label":`Recorded coverage timeline`,children:[n.map(n=>{let r=fI(n.startMs,e,t),i=fI(n.endMs,e,t);return N(`div`,{"data-testid":`coverage-band`,className:`absolute inset-y-0 bg-gradient-to-b from-primary to-primary/80`,style:{left:`${r}%`,width:`${Math.max(.5,i-r)}%`}},`${n.startMs}-${n.endMs}`)}),r===null?null:N(`div`,{"data-testid":`coverage-playhead`,className:`absolute inset-y-[-2px] w-0.5 bg-amber-500 shadow-[0_0_6px] shadow-amber-500`,style:{left:`${fI(r,e,t)}%`}})]}),c!==null&&w!==null?N(`div`,{"data-testid":`coverage-hover-tooltip`,className:`pointer-events-none absolute top-full z-10 mt-0.5 -translate-x-1/2 rounded bg-popover px-1.5 py-0.5 text-[9px] text-popover-foreground shadow`,style:{left:`${c.xPct}%`},children:w}):null]})}var xI={motion:`bg-emerald-500`,object:`bg-violet-500`,audio:`bg-orange-500`};function SI({windowFrom:e,windowTo:t,buckets:n,selectedIndex:r,onSelectBucket:i}){let a=n.reduce((e,t)=>Math.max(e,t.total),0),o=n[0],s=o?fI(o.endMs,e,t)-fI(o.startMs,e,t):0;return N(`div`,{className:`relative h-6 rounded bg-background/40`,children:n.map(n=>{if(n.total===0||n.dominant===null)return null;let o=a>0?Math.max(15,n.total/a*100):0,c=fI(n.startMs,e,t),l=n.index===r;return N(`button`,{type:`button`,"data-testid":`heatmap-bar`,title:`${new Date(n.startMs).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})} · motion ${n.counts.motion} · object ${n.counts.object}`,onClick:()=>i(n.index),className:`absolute bottom-0 rounded-t-sm transition-opacity ${xI[n.dominant]} ${l?`opacity-100 ring-1 ring-amber-400`:`opacity-80 hover:opacity-100`}`,style:{left:`${c}%`,width:`${Math.max(.6,s)}%`,height:`${o}%`}},n.index)})})}h();function CI({mediaUrl:e,kind:t}){let[n,r]=k(!1);return e&&!n?N(`img`,{src:e,alt:``,className:`h-full w-full object-cover`,loading:`lazy`,onError:()=>r(!0)}):N(`div`,{className:`flex h-full w-full items-center justify-center text-white/30`,children:N(wI,{kind:t,large:!0})})}function wI({kind:e,large:t=!1}){return N(e===`object`?yi:e===`audio`?Yo:Qr,{className:t?`h-7 w-7`:`h-3.5 w-3.5 text-foreground-subtle`})}var TI=[`motion`,`object`,`audio`];function EI(e){return new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})}function DI({clips:e,loading:t,busyKey:n,onPlay:r,enabledKinds:i,onToggleKind:a,hasMore:o,onLoadMore:s}){let c=N(`div`,{className:`flex items-center gap-3 pb-1`,children:TI.map(e=>g(`label`,{className:`flex cursor-pointer items-center gap-1 text-xs text-foreground-subtle select-none`,children:[N(`input`,{type:`checkbox`,checked:i.has(e),onChange:()=>a(e),className:`h-3.5 w-3.5 accent-primary`}),e]},e))});return t&&e.length===0?g(`div`,{className:`space-y-2`,children:[c,N(`div`,{className:`px-1 py-2 text-xs text-foreground-subtle`,children:`Loading events…`})]}):e.length===0?g(`div`,{className:`space-y-2`,children:[c,N(`div`,{className:`px-1 py-2 text-xs text-foreground-subtle`,children:`No events in this window.`})]}):g(`div`,{className:`space-y-2`,children:[c,t?N(`div`,{className:`px-1 text-[10px] text-foreground-subtle`,children:`Loading events…`}):null,N(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3`,children:e.map(e=>{let t=`event:${e.id}`;return g(`button`,{type:`button`,disabled:n!==null,onClick:()=>r(e),className:`group overflow-hidden rounded-lg border border-border text-left transition-colors hover:border-primary disabled:opacity-60`,children:[g(`div`,{className:`relative aspect-video bg-black/90`,children:[N(CI,{mediaUrl:e.mediaUrl,kind:e.kind}),N(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/0 transition-colors group-hover:bg-black/30`,children:n===t?N(Ea,{className:`h-6 w-6 animate-spin text-white`}):N(Qa,{className:`h-6 w-6 text-white opacity-0 transition-opacity group-hover:opacity-100`})})]}),g(`div`,{className:`flex items-center gap-1.5 bg-surface px-2 py-1.5`,children:[N(wI,{kind:e.kind}),g(`div`,{className:`min-w-0 flex-1`,children:[N(`div`,{className:`truncate text-xs font-medium text-foreground`,children:e.label}),N(`div`,{className:`text-[10px] text-foreground-subtle`,children:EI(e.timestamp)})]})]})]},t)})}),e.length>0?g(`div`,{className:`flex items-center gap-2 pt-1 text-[11px] text-foreground-subtle`,children:[g(`span`,{children:[`(`,e.length,` shown)`]}),o?N(`button`,{type:`button`,onClick:s,className:`rounded px-2 py-0.5 text-[11px] font-medium text-primary hover:underline`,children:`Load more`}):null]}):null]})}function OI(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function kI(e){let t=e.split(`-`),n=t[0]===void 0?NaN:parseInt(t[0],10),r=t[1]===void 0?NaN:parseInt(t[1],10),i=t[2]===void 0?NaN:parseInt(t[2],10);return isNaN(n)||isNaN(r)||isNaN(i)?null:new Date(n,r-1,i)}function AI({day:e,onDayChange:t,view:n,dayBounds:r,onViewChange:i}){let a=e=>{let n=kI(e.target.value);n!==null&&t(n)},o=n.toMs-n.fromMs,s=(()=>{let e=0,t=1/0;for(let n=0;n<mI.length;n++){let r=mI[n];if(r===void 0)continue;let i=Math.abs(r-o);i<t&&(t=i,e=n)}return e})(),c=n.toMs,l=()=>{let e=mI[Math.min(s+1,mI.length-1)];e!==void 0&&i(hI(r,e,c))},u=()=>{let e=mI[Math.max(s-1,0)];e!==void 0&&i(hI(r,e,c))},d=s<mI.length-1,f=s>0,p=Math.max(1,Math.round(o*.9)),m=n.fromMs>r.fromMs,h=n.toMs<r.toMs;return g(`div`,{className:`flex items-center gap-2`,children:[N(`input`,{type:`date`,value:OI(e),max:OI(new Date),onChange:a,className:`rounded border border-border bg-background px-2 py-0.5 text-[11px] text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":`Select recording day`}),g(`div`,{className:`ml-auto flex items-center gap-1`,children:[N(`button`,{type:`button`,onClick:()=>{i(gI(n,r,-p))},disabled:!m,title:`Earlier (pan back)`,"aria-label":`Pan earlier`,className:`rounded p-1 text-foreground-subtle transition-colors hover:bg-background/60 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40`,children:N(wi,{size:14})}),N(`button`,{type:`button`,onClick:()=>{i(gI(n,r,p))},disabled:!h,title:`Later (pan forward)`,"aria-label":`Pan later`,className:`rounded p-1 text-foreground-subtle transition-colors hover:bg-background/60 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40`,children:N(Ue,{size:14})}),N(`span`,{className:`mx-0.5 h-3 w-px bg-border`,"aria-hidden":`true`}),N(`button`,{type:`button`,onClick:u,disabled:!f,title:`Zoom out`,"aria-label":`Zoom out`,className:`rounded p-1 text-foreground-subtle transition-colors hover:bg-background/60 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40`,children:N(os,{size:13})}),N(`button`,{type:`button`,onClick:l,disabled:!d,title:`Zoom in`,"aria-label":`Zoom in`,className:`rounded p-1 text-foreground-subtle transition-colors hover:bg-background/60 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40`,children:N(as,{size:13})})]}),N(`span`,{className:`text-[9px] text-foreground-subtle`,children:jI(o)})]})}function jI(e){let t=e/36e5;if(t>=24)return`24h`;if(t>=1)return`${Math.round(t)}h`;let n=e/6e4;return`${Math.round(n)}m`}h();var MI=[`motion`,`object`,`audio`],NI=60,PI=18e3/100,FI=5e3,II=1e4,LI=[],RI={live:`Live`,loading:`Loading…`,playing:`Playing`,paused:`Paused`,gap:`No footage`,ended:`Ended`,error:`Error`};function zI({deviceId:e}){let t=Ke(),n=nI(),[r,i]=k(null),[a,o]=k(null),[s,c]=k(null),[l,d]=k(null),p=aI(),{send:m,mode:h,positionMs:_}=p,[v,y]=k(!1),x=p.channelOpen&&!v,S=f(x);S.current=x;let C=b(()=>({scrubStart:()=>{},scrubTo:()=>{},scrubCommit:e=>{m({t:`scrubCommit`,epoch:e})},seek:e=>{m({t:`seek`,epoch:e})}}),[m]),w=f(h);w.current=h;let{state:T,beginScrub:E,updateScrub:D,endScrub:O,seek:A,setPlayhead:j,reset:M}=Zr(C,u(()=>w.current===`live`,[]));P(()=>{_!==null&&j(_)},[_,j]),P(()=>{(!p.channelOpen||h===`live`)&&M()},[p.channelOpen,h,M]);let F=u(()=>{m({t:`goLive`}),M()},[m,M]),I=u(()=>{m({t:`setRate`,rate:+(w.current===`paused`)})},[m]),[L,R]=k(()=>new Set(MI)),ee=u(e=>{R(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),[z,B]=k(NI),V=u(()=>{B(e=>e+NI)},[]);P(()=>{B(NI)},[r]);let[te,H]=k(()=>new Date),[U,ne]=k(()=>pI(new Date,Date.now())),re=b(()=>pI(te,Date.now()),[te]),ie=u(e=>{H(e),ne(pI(e,Date.now())),i(null)},[]),ae=u(e=>{ne(e),i(null)},[]),oe=f(null),se=u(e=>{let t=Math.abs(e.deltaX)>Math.abs(e.deltaY)?e.deltaX:e.shiftKey?e.deltaY:0;if(t===0)return;e.preventDefault();let n=t*PI;ne(e=>gI(e,re,n))},[re]),W=vI(U.toMs-U.fromMs),ce=bx({deviceId:e,fromMs:U.fromMs,toMs:U.toMs}),le=ay({deviceId:e,since:U.fromMs,until:U.toMs,bucketMs:W}),ue=ce.data?.ranges??LI,de=b(()=>oI(ue),[ue]),fe=b(()=>lI(le.data??[],U.fromMs,W),[le.data,U.fromMs,W]),pe=r===null?void 0:fe.find(e=>e.index===r),G=pe!==void 0,me=pe?.startMs??0,he=pe?Math.min(pe.endMs,U.toMs):0,ge=ry({deviceId:e,since:me,until:he,limit:z,projection:`slim`},{enabled:G&&L.has(`object`)}),_e=ny({deviceId:e,since:me,until:he,limit:z,projection:`slim`},{enabled:G&&L.has(`motion`)}),ve=iy({deviceId:e,since:me,until:he,limit:z,projection:`slim`},{enabled:G&&L.has(`audio`)}),ye=b(()=>{if(!pe)return[];let e=[];if(L.has(`object`))for(let t of ge.data??[])e.push({id:t.id,timestamp:t.timestamp,kind:`object`,label:t.label??t.className,mediaUrl:t.mediaUrl});if(L.has(`motion`))for(let t of _e.data??[])e.push({id:t.id,timestamp:t.timestamp,kind:`motion`,label:`Motion (${t.regionCount})`,mediaUrl:t.mediaUrl});if(L.has(`audio`))for(let t of ve.data??[])e.push({id:t.id,timestamp:t.timestamp,kind:`audio`,label:t.classification?.className??`Audio`,mediaUrl:t.mediaUrl});return e.toSorted((e,t)=>t.timestamp-e.timestamp)},[pe,L,ge.data,_e.data,ve.data]),be=b(()=>!!(L.has(`object`)&&(ge.data?.length??0)===z||L.has(`motion`)&&(_e.data?.length??0)===z||L.has(`audio`)&&(ve.data?.length??0)===z),[L,ge.data,_e.data,ve.data,z]),xe=u(async(r,i,a,s,l)=>{c(r),d(null);try{let r=await t.trpcClient.recording.getPlaybackManifest.query({deviceId:e,fromMs:i,toMs:a});r?.playbackUrl?(o(l),n.play({url:r.playbackUrl,label:s})):d(`No playable footage for this selection.`)}catch{d(`Could not load this recording.`)}finally{c(null)}},[t,e,n]),Se=u(e=>{let t=dI(e,de);if(!t)return;if(S.current){A(t.fromMs,`timeline`);return}let n=`Recording · ${new Date(t.fromMs).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}`;xe(`seek:${t.fromMs}`,t.fromMs,t.toMs,n,t.fromMs)},[de,xe,A]),Ce=u(()=>{E(`timeline`)},[E]),we=u(e=>{D(e,`timeline`)},[D]),Te=u(e=>{O(dI(e,de)?.fromMs??e,`timeline`)},[de,O]),Ee=u(e=>{if(S.current){A(e.timestamp-FI,`timeline`);return}let t=`${e.label} · ${new Date(e.timestamp).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})}`;xe(`event:${e.id}`,e.timestamp-FI,e.timestamp+II,t,e.timestamp)},[xe,A]),De=u(e=>{i(t=>t===e?null:e)},[]),Oe=ce.isLoading,ke=le.isLoading,Ae=(ge.isLoading||_e.isLoading||ve.isLoading)&&G,je=b(()=>yI(U.fromMs,U.toMs,5),[U.fromMs,U.toMs]),Me=x?T.scrubbing?T.scrubEpoch:T.playheadEpoch:a,Ne=x&&(h===`playing`||h===`paused`);return g(`div`,{className:`space-y-3`,children:[ce.isError?N(xl,{variant:`warning`,message:`Recorder unavailable — the recording service may not be running for this node.`}):null,l?N(xl,{variant:`warning`,message:l}):null,N(AI,{day:te,onDayChange:ie,view:U,dayBounds:re,onViewChange:ae}),p.channelOpen?g(`div`,{"data-testid":`frame-push-status-row`,className:`flex flex-wrap items-center gap-2 text-[10px]`,children:[N(`span`,{"data-testid":`frame-push-mode-chip`,className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 font-semibold uppercase tracking-wider ${x&&h!==`live`?h===`error`?`bg-rose-500/15 text-rose-400`:`bg-primary/15 text-primary`:`bg-background/40 text-foreground-subtle`}`,children:x?RI[h]:`HLS mode`}),x&&_!==null&&!T.scrubbing?N(`span`,{className:`tabular-nums text-foreground-subtle`,children:new Date(_).toLocaleTimeString()}):null,Ne?g(`button`,{type:`button`,"data-testid":`frame-push-rate-toggle`,onClick:I,className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 font-medium text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,title:h===`paused`?`Resume playback`:`Pause playback`,children:[N(h===`paused`?Qa:Ja,{className:`h-3 w-3`}),h===`paused`?`Resume`:`Pause`]}):null,x&&h!==`live`?g(`button`,{type:`button`,"data-testid":`frame-push-go-live`,onClick:F,className:`inline-flex items-center gap-1 rounded bg-danger/10 px-1.5 py-0.5 font-medium text-danger transition-colors hover:bg-danger/20`,title:`Return to the live stream`,children:[N(ao,{className:`h-3 w-3`}),`Go live`]}):null,N(`button`,{type:`button`,"data-testid":`frame-push-hls-toggle`,onClick:()=>y(e=>!e),className:`ml-auto inline-flex items-center gap-1 rounded px-1.5 py-0.5 font-medium transition-colors ${v?`bg-primary/15 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:`Play recordings through the HLS player instead of the live WebRTC session`,children:`HLS`})]}):null,g(`div`,{ref:oe,onWheel:se,className:`space-y-1`,children:[g(`div`,{className:`space-y-1`,children:[N(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Recorded`}),Oe?N(`div`,{className:`h-5 animate-pulse rounded bg-background/40`}):de.length===0?N(yl,{icon:aa,title:`No recordings for this window.`}):N(bI,{windowFrom:U.fromMs,windowTo:U.toMs,spans:de,playheadMs:Me,onSeek:Se,...x?{onScrubStart:Ce,onScrubMove:we,onScrubEnd:Te}:{}})]}),g(`div`,{className:`space-y-1`,children:[N(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Events · density`}),ke?N(`div`,{className:`h-6 animate-pulse rounded bg-background/40`}):N(SI,{windowFrom:U.fromMs,windowTo:U.toMs,buckets:fe,selectedIndex:r,onSelectBucket:De})]}),N(`div`,{className:`relative h-3`,children:je.map(e=>N(`span`,{className:`absolute -translate-x-1/2 text-[9px] text-foreground-subtle`,style:{left:`${e.pct}%`},children:e.label},e.pct))})]}),pe?N(DI,{clips:ye,loading:Ae,busyKey:s,onPlay:Ee,enabledKinds:L,onToggleKind:ee,hasMore:be,onLoadMore:V}):N(`p`,{className:`text-[11px] text-foreground-subtle`,children:x?`Click or drag the coverage bar to play from any point (frames play in the main player above), or click a density bar to browse that window’s events.`:`Click the coverage bar to play from any point, or a density bar to browse that window’s events.`})]})}h();var BI=1440*60*1e3;function VI(e){let t=Math.round(e/1e3),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?`${n}h ${r}m`:r>0?`${r}m ${i}s`:`${i}s`}function HI({deviceId:e}){let t=O(),n=Ax({deviceId:e}),r=wx({deviceId:e}),i=Dx(),a=Ox(),o=t=>{i.mutate({deviceId:e,config:t},{onSuccess:()=>{r.refetch(),n.refetch()}})},s=u(()=>{a.mutate({deviceId:e},{onSuccess:()=>{t.invalidateQueries({queryKey:[[`recording`]]})}})},[e,t,a]),c=b(()=>Date.now(),[]),l=bx({deviceId:e,fromMs:c-BI,toMs:c}),d=n.data?ie.safeParse(n.data):null,f=d?.success?d.data:null,p=r.data?le.safeParse(r.data):null,m=p?.success?p.data:null,h=l.data?.ranges??[],_=h.reduce((e,t)=>e+Math.max(0,t.endMs-t.startMs),0),v=f?.enabled===!0&&f.activeMode===`continuous`;return g(`div`,{className:`space-y-3`,children:[N(Je,{title:`Settings`,icon:N(ho,{className:`h-3.5 w-3.5 text-foreground-subtle`}),collapsible:!0,defaultOpen:!1,children:m?N($F,{initial:m,saving:i.isPending,onSave:o},JSON.stringify(m)):N(`div`,{className:`px-1 py-2 text-xs text-foreground-subtle`,children:`Loading settings…`})}),N(Je,{title:`Recording`,icon:N(aa,{className:`h-3.5 w-3.5 text-foreground-subtle`}),headerRight:g(`span`,{className:`flex items-center gap-2`,children:[v?g(`span`,{className:`flex items-center gap-1.5 text-[10px] text-emerald-500`,children:[N(ao,{className:`h-3 w-3`}),` Recording`]}):null,N(`button`,{type:`button`,onClick:s,disabled:a.isPending,"aria-label":`Rescan storage`,className:`flex items-center rounded p-0.5 text-foreground-subtle transition-colors hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50`,children:N(oo,{className:`h-3.5 w-3.5 ${a.isPending?`animate-spin`:``}`})})]}),children:g(`div`,{className:`space-y-3`,children:[g(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-3`,children:[N(Ge,{label:`Status`,icon:N(ji,{className:`h-3.5 w-3.5 ${v?`text-emerald-500`:``}`}),footer:f?.nodeId?`node: ${f.nodeId}`:void 0,children:n.isLoading?`…`:v?`Recording (continuous)`:`Idle`}),N(Ge,{label:`Storage`,icon:N(ma,{className:`h-3.5 w-3.5`}),children:f?sI(f.storageBytes):`—`}),N(Ge,{label:`Recorded (24h)`,icon:N(Ii,{className:`h-3.5 w-3.5`}),footer:`${h.length} segment range${h.length===1?``:`s`}`,children:l.isLoading?`…`:VI(_)})]}),n.isError?N(xl,{variant:`warning`,message:`Recorder unavailable — the recording service may not be running for this node.`}):null,N(zI,{deviceId:e}),N(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Recordings play in the main player above — switch back to live from there.`})]})})]})}h();var UI={"host/motion-zones-grid":E(()=>a(()=>import(`./MotionZonesSettings-DL55VLbI.js`).then(e=>({default:e.MotionZonesSettings})),__vite__mapDeps([0,1,2,3,4]))),"host/privacy-mask-grid":E(()=>a(()=>import(`./PrivacyMaskSettings-8aXddQXv.js`).then(e=>({default:e.PrivacyMaskSettings})),__vite__mapDeps([5,1,2,3,4]))),"host/ptz-panel":EF,"host/consumables-panel":jF,"host/ptz-autotrack":NF,"host/recording-panel":HI};h();function WI(e){let{widgetId:t,deviceId:n}=e,r=UI[t];return r===void 0?N(GI,{...e}):n===void 0?N(JI,{widgetId:t,reason:`missing-device-context`}):N(x,{fallback:N(qI,{}),children:N(r,{deviceId:n})})}function GI(e){let{widgetId:t}=e,n=yF(t);return n===void 0?N(JI,{widgetId:t,reason:`unknown`}):N(KI,{...e,metadata:n})}function KI(e){let{widgetId:t,host:n=`device-tab`,config:r,deviceId:i,integrationId:a,instanceId:o,size:s,columns:c,rows:l,metadata:u}=e,d=xF(u.remote,u.bundleUrl),f=b(()=>o??t,[o,t]);return d===null?N(qI,{}):d===void 0?N(JI,{widgetId:t,reason:`missing-export`}):u.requires.deviceContext&&i===void 0?N(JI,{widgetId:t,reason:`missing-device-context`}):u.requires.integrationContext&&a===void 0?N(JI,{widgetId:t,reason:`missing-integration-context`}):N(d,{instanceId:f,host:n,config:r,deviceId:i,integrationId:a,size:s,columns:c,rows:l})}function qI(){return g(`div`,{className:`rounded-lg border border-border bg-surface/40 p-4 animate-pulse`,children:[N(`div`,{className:`h-3 w-24 bg-foreground-subtle/20 rounded mb-2`}),N(`div`,{className:`h-2 w-full bg-foreground-subtle/10 rounded mb-1`}),N(`div`,{className:`h-2 w-3/4 bg-foreground-subtle/10 rounded`})]})}function JI({widgetId:e,reason:t}){return N(`div`,{className:`rounded-lg border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:t===`unknown`?`Widget "${e}" not registered`:t===`missing-export`?`Widget "${e}" bundle does not export this stableId`:t===`missing-device-context`?`Widget "${e}" requires a deviceId`:`Widget "${e}" requires an integrationId`})}h();var YI=Object.defineProperty,XI=Object.getOwnPropertySymbols,ZI=Object.prototype.hasOwnProperty,QI=Object.prototype.propertyIsEnumerable,$I=(e,t,n)=>t in e?YI(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,eL=(e,t)=>{for(var n in t||={})ZI.call(t,n)&&$I(e,n,t[n]);if(XI)for(var n of XI(t))QI.call(t,n)&&$I(e,n,t[n]);return e},tL=(e,t)=>{var n={};for(var r in e)ZI.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&XI)for(var r of XI(e))t.indexOf(r)<0&&QI.call(e,r)&&(n[r]=e[r]);return n},nL;(e=>{let t=class t{constructor(e,n,r,a){if(this.version=e,this.errorCorrectionLevel=n,this.modules=[],this.isFunction=[],e<t.MIN_VERSION||e>t.MAX_VERSION)throw RangeError(`Version value out of range`);if(a<-1||a>7)throw RangeError(`Mask value out of range`);this.size=e*4+17;let o=[];for(let e=0;e<this.size;e++)o.push(!1);for(let e=0;e<this.size;e++)this.modules.push(o.slice()),this.isFunction.push(o.slice());this.drawFunctionPatterns();let s=this.addEccAndInterleave(r);if(this.drawCodewords(s),a==-1){let e=1e9;for(let t=0;t<8;t++){this.applyMask(t),this.drawFormatBits(t);let n=this.getPenaltyScore();n<e&&(a=t,e=n),this.applyMask(t)}}i(0<=a&&a<=7),this.mask=a,this.applyMask(a),this.drawFormatBits(a),this.isFunction=[]}static encodeText(n,r){let i=e.QrSegment.makeSegments(n);return t.encodeSegments(i,r)}static encodeBinary(n,r){let i=e.QrSegment.makeBytes(n);return t.encodeSegments([i],r)}static encodeSegments(e,r,a=1,s=40,c=-1,l=!0){if(!(t.MIN_VERSION<=a&&a<=s&&s<=t.MAX_VERSION)||c<-1||c>7)throw RangeError(`Invalid value`);let u,d;for(u=a;;u++){let n=t.getNumDataCodewords(u,r)*8,i=o.getTotalBits(e,u);if(i<=n){d=i;break}if(u>=s)throw RangeError(`Data too long`)}for(let e of[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH])l&&d<=t.getNumDataCodewords(u,e)*8&&(r=e);let f=[];for(let t of e){n(t.mode.modeBits,4,f),n(t.numChars,t.mode.numCharCountBits(u),f);for(let e of t.getData())f.push(e)}i(f.length==d);let p=t.getNumDataCodewords(u,r)*8;i(f.length<=p),n(0,Math.min(4,p-f.length),f),n(0,(8-f.length%8)%8,f),i(f.length%8==0);for(let e=236;f.length<p;e^=253)n(e,8,f);let m=[];for(;m.length*8<f.length;)m.push(0);return f.forEach((e,t)=>m[t>>>3]|=e<<7-(t&7)),new t(u,r,m,c)}getModule(e,t){return 0<=e&&e<this.size&&0<=t&&t<this.size&&this.modules[t][e]}getModules(){return this.modules}drawFunctionPatterns(){for(let e=0;e<this.size;e++)this.setFunctionModule(6,e,e%2==0),this.setFunctionModule(e,6,e%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);let e=this.getAlignmentPatternPositions(),t=e.length;for(let n=0;n<t;n++)for(let r=0;r<t;r++)n==0&&r==0||n==0&&r==t-1||n==t-1&&r==0||this.drawAlignmentPattern(e[n],e[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(e){let t=this.errorCorrectionLevel.formatBits<<3|e,n=t;for(let e=0;e<10;e++)n=n<<1^(n>>>9)*1335;let a=(t<<10|n)^21522;i(a>>>15==0);for(let e=0;e<=5;e++)this.setFunctionModule(8,e,r(a,e));this.setFunctionModule(8,7,r(a,6)),this.setFunctionModule(8,8,r(a,7)),this.setFunctionModule(7,8,r(a,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,r(a,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,r(a,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,r(a,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;let t=this.version<<12|e;i(t>>>18==0);for(let e=0;e<18;e++){let n=r(t,e),i=this.size-11+e%3,a=Math.floor(e/3);this.setFunctionModule(i,a,n),this.setFunctionModule(a,i,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),a=e+r,o=t+n;0<=a&&a<this.size&&0<=o&&o<this.size&&this.setFunctionModule(a,o,i!=2&&i!=4)}}drawAlignmentPattern(e,t){for(let n=-2;n<=2;n++)for(let r=-2;r<=2;r++)this.setFunctionModule(e+r,t+n,Math.max(Math.abs(r),Math.abs(n))!=1)}setFunctionModule(e,t,n){this.modules[t][e]=n,this.isFunction[t][e]=!0}addEccAndInterleave(e){let n=this.version,r=this.errorCorrectionLevel;if(e.length!=t.getNumDataCodewords(n,r))throw RangeError(`Invalid argument`);let a=t.NUM_ERROR_CORRECTION_BLOCKS[r.ordinal][n],o=t.ECC_CODEWORDS_PER_BLOCK[r.ordinal][n],s=Math.floor(t.getNumRawDataModules(n)/8),c=a-s%a,l=Math.floor(s/a),u=[],d=t.reedSolomonComputeDivisor(o);for(let n=0,r=0;n<a;n++){let i=e.slice(r,r+l-o+(n<c?0:1));r+=i.length;let a=t.reedSolomonComputeRemainder(i,d);n<c&&i.push(0),u.push(i.concat(a))}let f=[];for(let e=0;e<u[0].length;e++)u.forEach((t,n)=>{(e!=l-o||n>=c)&&f.push(t[e])});return i(f.length==s),f}drawCodewords(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw RangeError(`Invalid argument`);let n=0;for(let t=this.size-1;t>=1;t-=2){t==6&&(t=5);for(let i=0;i<this.size;i++)for(let a=0;a<2;a++){let o=t-a,s=t+1&2?i:this.size-1-i;!this.isFunction[s][o]&&n<e.length*8&&(this.modules[s][o]=r(e[n>>>3],7-(n&7)),n++)}}i(n==e.length*8)}applyMask(e){if(e<0||e>7)throw RangeError(`Mask value out of range`);for(let t=0;t<this.size;t++)for(let n=0;n<this.size;n++){let r;switch(e){case 0:r=(n+t)%2==0;break;case 1:r=t%2==0;break;case 2:r=n%3==0;break;case 3:r=(n+t)%3==0;break;case 4:r=(Math.floor(n/3)+Math.floor(t/2))%2==0;break;case 5:r=n*t%2+n*t%3==0;break;case 6:r=(n*t%2+n*t%3)%2==0;break;case 7:r=((n+t)%2+n*t%3)%2==0;break;default:throw Error(`Unreachable`)}!this.isFunction[t][n]&&r&&(this.modules[t][n]=!this.modules[t][n])}}getPenaltyScore(){let e=0;for(let n=0;n<this.size;n++){let r=!1,i=0,a=[0,0,0,0,0,0,0];for(let o=0;o<this.size;o++)this.modules[n][o]==r?(i++,i==5?e+=t.PENALTY_N1:i>5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[n][o],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n<this.size;n++){let r=!1,i=0,a=[0,0,0,0,0,0,0];for(let o=0;o<this.size;o++)this.modules[o][n]==r?(i++,i==5?e+=t.PENALTY_N1:i>5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[o][n],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n<this.size-1;n++)for(let r=0;r<this.size-1;r++){let i=this.modules[n][r];i==this.modules[n][r+1]&&i==this.modules[n+1][r]&&i==this.modules[n+1][r+1]&&(e+=t.PENALTY_N2)}let n=0;for(let e of this.modules)n=e.reduce((e,t)=>e+ +!!t,n);let r=this.size*this.size,a=Math.ceil(Math.abs(n*20-r*10)/r)-1;return i(0<=a&&a<=9),e+=a*t.PENALTY_N4,i(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(this.version==1)return[];{let e=Math.floor(this.version/7)+2,t=this.version==32?26:Math.ceil((this.version*4+4)/(e*2-2))*2,n=[6];for(let r=this.size-7;n.length<e;r-=t)n.splice(1,0,r);return n}}static getNumRawDataModules(e){if(e<t.MIN_VERSION||e>t.MAX_VERSION)throw RangeError(`Version number out of range`);let n=(16*e+128)*e+64;if(e>=2){let t=Math.floor(e/7)+2;n-=(25*t-10)*t-55,e>=7&&(n-=36)}return i(208<=n&&n<=29648),n}static getNumDataCodewords(e,n){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw RangeError(`Degree out of range`);let n=[];for(let t=0;t<e-1;t++)n.push(0);n.push(1);let r=1;for(let i=0;i<e;i++){for(let e=0;e<n.length;e++)n[e]=t.reedSolomonMultiply(n[e],r),e+1<n.length&&(n[e]^=n[e+1]);r=t.reedSolomonMultiply(r,2)}return n}static reedSolomonComputeRemainder(e,n){let r=n.map(e=>0);for(let i of e){let e=i^r.shift();r.push(0),n.forEach((n,i)=>r[i]^=t.reedSolomonMultiply(n,e))}return r}static reedSolomonMultiply(e,t){if(e>>>8||t>>>8)throw RangeError(`Byte out of range`);let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return i(n>>>8==0),n}finderPenaltyCountPatterns(e){let t=e[1];i(t<=this.size*3);let n=t>0&&e[2]==t&&e[3]==t*3&&e[4]==t&&e[5]==t;return(n&&e[0]>=t*4&&e[6]>=t?1:0)+(n&&e[6]>=t*4&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){t[0]==0&&(e+=this.size),t.pop(),t.unshift(e)}};t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;function n(e,t,n){if(t<0||t>31||e>>>t)throw RangeError(`Value out of range`);for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function r(e,t){return(e>>>t&1)!=0}function i(e){if(!e)throw Error(`Assertion error`)}let a=class e{constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw RangeError(`Invalid argument`);this.bitData=n.slice()}static makeBytes(t){let r=[];for(let e of t)n(e,8,r);return new e(e.Mode.BYTE,t.length,r)}static makeNumeric(t){if(!e.isNumeric(t))throw RangeError(`String contains non-numeric characters`);let r=[];for(let e=0;e<t.length;){let i=Math.min(t.length-e,3);n(parseInt(t.substring(e,e+i),10),i*3+1,r),e+=i}return new e(e.Mode.NUMERIC,t.length,r)}static makeAlphanumeric(t){if(!e.isAlphanumeric(t))throw RangeError(`String contains unencodable characters in alphanumeric mode`);let r=[],i;for(i=0;i+2<=t.length;i+=2){let a=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i))*45;a+=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i+1)),n(a,11,r)}return i<t.length&&n(e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i)),6,r),new e(e.Mode.ALPHANUMERIC,t.length,r)}static makeSegments(t){return t==``?[]:e.isNumeric(t)?[e.makeNumeric(t)]:e.isAlphanumeric(t)?[e.makeAlphanumeric(t)]:[e.makeBytes(e.toUtf8ByteArray(t))]}static makeEci(t){let r=[];if(t<0)throw RangeError(`ECI assignment value out of range`);if(t<128)n(t,8,r);else if(t<16384)n(2,2,r),n(t,14,r);else if(t<1e6)n(6,3,r),n(t,21,r);else throw RangeError(`ECI assignment value out of range`);return new e(e.Mode.ECI,0,r)}static isNumeric(t){return e.NUMERIC_REGEX.test(t)}static isAlphanumeric(t){return e.ALPHANUMERIC_REGEX.test(t)}getData(){return this.bitData.slice()}static getTotalBits(e,t){let n=0;for(let r of e){let e=r.mode.numCharCountBits(t);if(r.numChars>=1<<e)return 1/0;n+=4+e+r.bitData.length}return n}static toUtf8ByteArray(e){e=encodeURI(e);let t=[];for(let n=0;n<e.length;n++)e.charAt(n)==`%`?(t.push(parseInt(e.substring(n+1,n+3),16)),n+=2):t.push(e.charCodeAt(n));return t}};a.NUMERIC_REGEX=/^[0-9]*$/,a.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,a.ALPHANUMERIC_CHARSET=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`;let o=a;e.QrSegment=a})(nL||={}),(e=>{(e=>{let t=class{constructor(e,t){this.ordinal=e,this.formatBits=t}};t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),e.Ecc=t})(e.QrCode||={})})(nL||={}),(e=>{(e=>{let t=class{constructor(e,t){this.modeBits=e,this.numBitsCharCount=t}numCharCountBits(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}};t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),e.Mode=t})(e.QrSegment||={})})(nL||={});var rL=nL,iL={L:rL.QrCode.Ecc.LOW,M:rL.QrCode.Ecc.MEDIUM,Q:rL.QrCode.Ecc.QUARTILE,H:rL.QrCode.Ecc.HIGH},aL=128,oL=`L`,sL=`#FFFFFF`,cL=`#000000`,lL=!1,uL=1,dL=4,fL=0,pL=.1;function mL(e,t=0){let n=[];return e.forEach(function(e,r){let i=null;e.forEach(function(a,o){if(!a&&i!==null){n.push(`M${i+t} ${r+t}h${o-i}v1H${i+t}z`),i=null;return}if(o===e.length-1){if(!a)return;i===null?n.push(`M${o+t},${r+t} h1v1H${o+t}z`):n.push(`M${i+t},${r+t} h${o+1-i}v1H${i+t}z`);return}a&&i===null&&(i=o)})}),n.join(``)}function hL(e,t){return e.slice().map((e,n)=>n<t.y||n>=t.y+t.h?e:e.map((e,n)=>n<t.x||n>=t.x+t.w?e:!1))}function gL(e,t,n,r){if(r==null)return null;let i=e.length+n*2,a=Math.floor(t*pL),o=i/t,s=(r.width||a)*o,c=(r.height||a)*o,l=r.x==null?e.length/2-s/2:r.x*o,u=r.y==null?e.length/2-c/2:r.y*o,d=r.opacity==null?1:r.opacity,f=null;if(r.excavate){let e=Math.floor(l),t=Math.floor(u);f={x:e,y:t,w:Math.ceil(s+l-e),h:Math.ceil(c+u-t)}}let p=r.crossOrigin;return{x:l,y:u,h:c,w:s,excavation:f,opacity:d,crossOrigin:p}}function _L(e,t){return t==null?e?dL:fL:Math.max(Math.floor(t),0)}function vL({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:a,size:o,boostLevel:s}){let c=_.useMemo(()=>{let r=(Array.isArray(e)?e:[e]).reduce((e,t)=>(e.push(...rL.QrSegment.makeSegments(t)),e),[]);return rL.QrCode.encodeSegments(r,iL[t],n,void 0,void 0,s)},[e,t,n,s]),{cells:l,margin:u,numCells:d,calculatedImageSettings:f}=_.useMemo(()=>{let e=c.getModules(),t=_L(r,i);return{cells:e,margin:t,numCells:e.length+t*2,calculatedImageSettings:gL(e,o,t,a)}},[c,o,a,r,i]);return{qrcode:c,margin:u,cells:l,numCells:d,calculatedImageSettings:f}}var yL=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),bL=_.forwardRef(function(e,t){let n=e,{value:r,size:i=aL,level:a=oL,bgColor:o=sL,fgColor:s=cL,includeMargin:c=lL,minVersion:l=uL,boostLevel:u,marginSize:d,imageSettings:f}=n,p=tL(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`marginSize`,`imageSettings`]),{style:m}=p,h=tL(p,[`style`]),g=f?.src,v=_.useRef(null),y=_.useRef(null),b=_.useCallback(e=>{v.current=e,typeof t==`function`?t(e):t&&(t.current=e)},[t]),[x,S]=_.useState(!1),{margin:C,cells:w,numCells:T,calculatedImageSettings:E}=vL({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:d,imageSettings:f,size:i});_.useEffect(()=>{if(v.current!=null){let e=v.current,t=e.getContext(`2d`);if(!t)return;let n=w,r=y.current,a=E!=null&&r!==null&&r.complete&&r.naturalHeight!==0&&r.naturalWidth!==0;a&&E.excavation!=null&&(n=hL(w,E.excavation));let c=window.devicePixelRatio||1;e.height=e.width=i*c;let l=i/T*c;t.scale(l,l),t.fillStyle=o,t.fillRect(0,0,T,T),t.fillStyle=s,yL?t.fill(new Path2D(mL(n,C))):w.forEach(function(e,n){e.forEach(function(e,r){e&&t.fillRect(r+C,n+C,1,1)})}),E&&(t.globalAlpha=E.opacity),a&&t.drawImage(r,E.x+C,E.y+C,E.w,E.h)}}),_.useEffect(()=>{S(!1)},[g]);let D=eL({height:i,width:i},m),O=null;return g!=null&&(O=_.createElement(`img`,{src:g,key:g,style:{display:`none`},onLoad:()=>{S(!0)},ref:y,crossOrigin:E?.crossOrigin})),_.createElement(_.Fragment,null,_.createElement(`canvas`,eL({style:D,height:i,width:i,ref:b,role:`img`},h)),O)});bL.displayName=`QRCodeCanvas`;var xL=_.forwardRef(function(e,t){let n=e,{value:r,size:i=aL,level:a=oL,bgColor:o=sL,fgColor:s=cL,includeMargin:c=lL,minVersion:l=uL,boostLevel:u,title:d,marginSize:f,imageSettings:p}=n,m=tL(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`title`,`marginSize`,`imageSettings`]),{margin:h,cells:g,numCells:v,calculatedImageSettings:y}=vL({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:f,imageSettings:p,size:i}),b=g,x=null;p!=null&&y!=null&&(y.excavation!=null&&(b=hL(g,y.excavation)),x=_.createElement(`image`,{href:p.src,height:y.h,width:y.w,x:y.x+h,y:y.y+h,preserveAspectRatio:`none`,opacity:y.opacity,crossOrigin:y.crossOrigin}));let S=mL(b,h);return _.createElement(`svg`,eL({height:i,width:i,viewBox:`0 0 ${v} ${v}`,ref:t,role:`img`},m),!!d&&_.createElement(`title`,null,d),_.createElement(`path`,{fill:o,d:`M0,0 h${v}v${v}H0z`,shapeRendering:`crispEdges`}),_.createElement(`path`,{fill:s,d:S,shapeRendering:`crispEdges`}),x)});xL.displayName=`QRCodeSVG`;var SL=192;function CL({value:e,size:t=SL,className:n,alt:r}){let i=e.trim();return i.length===0?null:N(`div`,{className:X(`inline-flex rounded-md bg-white p-2`,n),children:N(xL,{value:i,size:t,marginSize:1,title:r??`QR code`})})}var wL=`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none disabled:opacity-50 disabled:cursor-not-allowed`;function TL({value:e,onChange:t,disabled:n}){let r=[];for(let e of te)r.includes(e.region)||r.push(e.region);return g(`select`,{className:wL,value:e,disabled:n,onChange:e=>t(e.target.value),children:[!V(e)&&N(`option`,{value:``,children:`— Select timezone —`}),r.map(e=>N(`optgroup`,{label:e,children:te.filter(t=>t.region===e).map(e=>N(`option`,{value:e.id,children:e.label},e.id))},e))]})}h();var EL=`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none disabled:opacity-50 disabled:cursor-not-allowed`,DL=`block text-[11px] font-medium text-foreground mb-1 break-words`,OL=`text-[10px] text-foreground-subtle mt-0.5 break-words`;function kL({label:e,description:t,required:n,span:r,children:i,translationFn:a}){let o=r===2?`col-span-1 @[480px]:col-span-2`:r===3?`col-span-1 @[480px]:col-span-2 @[880px]:col-span-3`:r===4?`col-span-1 @[480px]:col-span-2 @[1140px]:col-span-4`:`col-span-1`,s=yR(e,a),c=yR(t,a),l=s!==void 0&&s!==``;return g(`div`,{className:`${o} min-w-0`,children:[l&&g(`label`,{className:DL,children:[s,n&&N(`span`,{className:`text-danger ml-0.5`,children:`*`})]}),i,c&&N(`p`,{className:OL,children:c})]})}function AL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:N(`input`,{type:e.inputType??`text`,className:EL,value:t==null?``:String(t),placeholder:e.placeholder,maxLength:e.maxLength,pattern:e.pattern,disabled:r||e.disabled,onChange:e=>n(e.target.value)})})}function jL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){let[a,o]=k(t==null?``:String(t)),s=f(!1);P(()=>{s.current||o(t==null?``:String(t))},[t]);let c=e=>{if(o(e),e===``||e===`-`){n(void 0);return}let t=Number(e);Number.isNaN(t)||n(t)};return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:g(`div`,{className:`flex items-center gap-1`,children:[N(`input`,{type:`number`,className:EL,value:a,placeholder:e.placeholder,min:e.min,max:e.max,step:e.step,disabled:r||e.disabled,onFocus:()=>{s.current=!0},onBlur:()=>{s.current=!1},onChange:e=>c(e.target.value)}),e.unit&&N(`span`,{className:`text-xs text-foreground-subtle whitespace-nowrap`,children:e.unit})]})})}function ML({field:e,value:t,onChange:n,disabled:r,translationFn:i}){let a=!!t,o=r||e.disabled;return e.style===`checkbox`?N(kL,{label:void 0,description:e.description,required:e.required,span:e.span,translationFn:i,children:g(`label`,{className:`flex items-center gap-2 cursor-pointer select-none`,children:[N(`input`,{type:`checkbox`,className:`h-3.5 w-3.5 rounded border-border accent-primary`,checked:a,disabled:o,onChange:e=>n(e.target.checked)}),N(`span`,{className:`text-xs font-medium text-foreground`,children:yR(e.label,i)}),e.required&&N(`span`,{className:`text-danger`,children:`*`})]})}):N(kL,{label:void 0,description:e.description,required:e.required,span:e.span,translationFn:i,children:g(`div`,{className:`flex items-center justify-between`,children:[g(`span`,{className:`block text-[11px] font-medium text-foreground mb-1 break-words mb-0`,children:[yR(e.label,i),e.required&&N(`span`,{className:`text-danger ml-0.5`,children:`*`})]}),N(`button`,{type:`button`,role:`switch`,"aria-checked":a,disabled:o,onClick:()=>!o&&n(!a),className:[`relative inline-flex h-4 w-8 shrink-0 items-center rounded-full transition-colors duration-150`,a?`bg-primary`:`bg-foreground-subtle/30`,o?`opacity-50 cursor-not-allowed`:`cursor-pointer`].join(` `),children:N(`span`,{className:[`inline-block h-3 w-3 rounded-full bg-white shadow transition-transform duration-150`,a?`translate-x-4`:`translate-x-0.5`].join(` `)})})]})})}function NL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){let a=e.options.some(e=>e.value===``);return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:g(`select`,{className:EL,value:t==null?``:String(t),disabled:r||e.disabled,onChange:e=>n(e.target.value),children:[!e.required&&!a&&N(`option`,{value:``,children:`— Select —`}),e.options.map(e=>N(`option`,{value:e.value,children:e.label},e.value))]})})}function PL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:N(TL,{value:typeof t==`string`?t:``,onChange:n,disabled:r||e.disabled})})}function FL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:N(`input`,{type:`datetime-local`,className:EL,value:typeof t==`string`?t:``,placeholder:e.placeholder,disabled:r||e.disabled,onChange:e=>n(e.target.value)})})}function IL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){let a=Array.isArray(t)?t:[],o=t=>{if(a.includes(t))n(a.filter(e=>e!==t));else{if(e.maxItems!==void 0&&a.length>=e.maxItems)return;n([...a,t])}};return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:N(`div`,{className:`flex flex-wrap gap-2`,children:e.options.map(t=>{let n=a.includes(t.value);return g(`label`,{className:[`flex items-center gap-1.5 rounded-md border px-2 py-1 text-xs cursor-pointer select-none transition-colors`,n?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground hover:bg-surface`,r||e.disabled?`opacity-50 cursor-not-allowed`:``].join(` `),children:[N(`input`,{type:`checkbox`,className:`sr-only`,checked:n,disabled:r||e.disabled,onChange:()=>o(t.value)}),t.label]},t.value)})})})}function LL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){let[a,o]=k(!1),s=e.showToggle!==!1;return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:g(`div`,{className:`relative`,children:[N(`input`,{type:a?`text`:`password`,className:EL+(s?` pr-9`:``),value:t==null?``:String(t),placeholder:e.placeholder,disabled:r||e.disabled,onChange:e=>n(e.target.value)}),s&&N(`button`,{type:`button`,className:`absolute right-2 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground`,tabIndex:-1,onClick:()=>o(e=>!e),children:N(a?ta:na,{className:`h-3.5 w-3.5`})})]})})}function RL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:N(`textarea`,{className:`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none disabled:opacity-50 disabled:cursor-not-allowed resize-y min-h-[60px]`,value:t==null?``:String(t),placeholder:e.placeholder,rows:e.rows??3,maxLength:e.maxLength,disabled:r||e.disabled,onChange:e=>n(e.target.value)})})}function zL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){let a=t==null,o=e.nullable===!0,s=a?e.default??e.min:Number(t),c=e.showValue!==!1,l=e.nullLabel??`Auto`,u=r||e.disabled,d=e.displayScale??1,f=e.min/d,p=e.max/d,m=s/d,h=(e.step??1)/d;if(o&&a)return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:g(`button`,{className:`w-full rounded-lg border border-dashed border-border px-3 py-2 text-xs text-foreground-subtle hover:border-primary/40 hover:text-primary transition-colors text-left`,disabled:u,onClick:()=>n(e.default??e.min),children:[l,` — click to set manually`]})});let _=e.showStepper===!0&&c,v=t=>{let r=s+t*(e.step??1),i=Math.min(e.max,Math.max(e.min,r));i!==s&&n(i)},y=`flex h-6 w-6 shrink-0 items-center justify-center rounded border border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:cursor-not-allowed disabled:opacity-40`;return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:g(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[g(`div`,{className:`flex min-w-0 flex-1 basis-[160px] items-center gap-2`,children:[N(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums shrink-0`,children:f}),N(`input`,{type:`range`,className:`min-w-0 flex-1 h-1 accent-primary cursor-pointer disabled:opacity-50`,min:f,max:p,step:h,value:m,disabled:u,onChange:e=>n(Number(e.target.value)*d)}),N(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums shrink-0`,children:p})]}),(c||o||e.unit)&&g(`div`,{className:`flex shrink-0 items-center gap-2`,children:[_&&N(`button`,{type:`button`,className:y,disabled:u||s<=e.min,onClick:()=>v(-1),title:`Decrease by ${e.step??1}`,"aria-label":`Decrement`,children:N(Ra,{className:`h-3 w-3`})}),c&&N(`input`,{type:`number`,className:`w-16 rounded border border-border bg-surface px-1.5 py-0.5 text-xs text-center text-foreground tabular-nums focus:outline-none focus:ring-1 focus:ring-primary`,min:f,max:p,step:h,value:m,disabled:u,onChange:t=>{if(t.target.value===``){n(o?null:e.min);return}let r=Number(t.target.value)*d,i=e.step??1,a=r-e.min,s=e.min+Math.round(a/i)*i;n(Math.min(e.max,Math.max(e.min,s)))}}),_&&N(`button`,{type:`button`,className:y,disabled:u||s>=e.max,onClick:()=>v(1),title:`Increase by ${e.step??1}`,"aria-label":`Increment`,children:N($a,{className:`h-3 w-3`})}),e.unit&&N(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.unit}),o&&N(`button`,{className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors`,title:`Reset to ${l}`,disabled:u,onClick:()=>n(null),children:l})]})]})})}function BL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){let a=Array.isArray(t)?t:[],[o,s]=k(``),c=f(null),l=u(t=>{let r=t.trim();!r||a.includes(r)||e.maxTags!==void 0&&a.length>=e.maxTags||(n([...a,r]),s(``))},[a,e.maxTags,n]),d=e=>n(a.filter(t=>t!==e)),p=e=>{e.key===`Enter`||e.key===`,`?(e.preventDefault(),l(o)):e.key===`Backspace`&&o===``&&a.length>0&&d(a[a.length-1])},m=r||e.disabled;return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:g(`div`,{className:[`flex flex-wrap gap-1.5 rounded-md border border-border bg-background px-2 py-1.5 min-h-[38px] cursor-text`,`focus-within:border-primary focus-within:ring-1 focus-within:ring-primary/30`,m?`opacity-50 cursor-not-allowed`:``].join(` `),onClick:()=>!m&&c.current?.focus(),children:[a.map(e=>g(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-primary/10 px-1.5 py-0.5 text-xs text-primary`,children:[e,!m&&N(`button`,{type:`button`,onClick:()=>d(e),className:`hover:text-danger`,children:N(rs,{className:`h-2.5 w-2.5`})})]},e)),N(`input`,{ref:c,type:`text`,className:`flex-1 min-w-[80px] bg-transparent text-sm text-foreground outline-none placeholder:text-foreground-disabled`,value:o,placeholder:a.length===0?e.placeholder??`Add tags…`:``,disabled:m,list:`tags-suggestions-${e.key}`,onChange:e=>s(e.target.value),onKeyDown:p,onBlur:()=>{o.trim()&&l(o)}}),e.suggestions&&N(`datalist`,{id:`tags-suggestions-${e.key}`,children:e.suggestions.map(e=>N(`option`,{value:e},e))})]})})}function VL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){let{nodes:a}=cl(),o=typeof t==`string`?t:``,s=e.showOffline?a:a.filter(e=>e.isOnline);return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:g(`select`,{className:`w-full px-3 py-2 text-sm bg-background border border-border rounded-lg text-foreground focus:outline-none focus:border-primary/50 disabled:opacity-50`,value:o,onChange:e=>n(e.target.value),disabled:r,children:[N(`option`,{value:``,children:`Select node…`}),s.map(e=>g(`option`,{value:e.id,disabled:!e.isOnline,children:[e.shortName,e.isOnline?``:` (offline)`]},e.id))]})})}function HL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){let{nodes:a}=cl(),o=new Set(Array.isArray(t)?t.map(String):[]),s=e.showOffline?a:a.filter(e=>e.isOnline),c=e=>{let t=new Set(o);t.has(e)?t.delete(e):t.add(e),n([...t])};return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:N(`div`,{className:`flex flex-wrap gap-1.5`,children:s.map(e=>{let t=o.has(e.id);return N(`button`,{type:`button`,onClick:()=>c(e.id),disabled:r||!e.isOnline,className:`px-2.5 py-1 text-xs font-medium rounded-md border transition-colors ${t?`border-primary bg-primary/10 text-primary`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover`} ${e.isOnline?``:`opacity-50 cursor-not-allowed`}`,children:e.shortName},e.id)})})})}function UL({field:e,value:t,onChange:n,disabled:r,translationFn:i}){let a=t==null?`#000000`:String(t);return g(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:[g(`div`,{className:`flex items-center gap-2`,children:[N(`input`,{type:`color`,className:`h-9 w-9 rounded-md border border-border bg-background cursor-pointer p-0.5 disabled:opacity-50`,value:a,disabled:r||e.disabled,onChange:e=>n(e.target.value)}),N(`input`,{type:`text`,className:`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none disabled:opacity-50 disabled:cursor-not-allowed flex-1 font-mono`,value:a,placeholder:`#000000`,disabled:r||e.disabled,onChange:e=>n(e.target.value)})]}),e.presets&&e.presets.length>0&&N(`div`,{className:`flex gap-1.5 mt-1.5`,children:e.presets.map(t=>N(`button`,{type:`button`,className:`h-5 w-5 rounded-md border border-border hover:scale-110 transition-transform disabled:opacity-50`,style:{backgroundColor:t},disabled:r||e.disabled,title:t,onClick:()=>n(t)},t))})]})}function WL({field:e,value:t,onChange:n,disabled:r,translationFn:i,onTestField:a,onAction:o,externalProbe:s}){let[c,l]=k(`idle`),[d,f]=k(null),p=s?.status??c,m=s?.result??d,h=!!a||!!o,_=u(async()=>{if(h){l(`probing`),f(null);try{let n=a?await a(e.key,t):await o(`test-probe`,e.key,t),r=n&&typeof n==`object`?n:{status:`error`,error:`Probe handler returned no result`};f(r),l(r.status===`ok`?`ok`:`error`)}catch(e){f({status:`error`,error:e instanceof Error?e.message:String(e)}),l(`error`)}}},[a,o,e.key,t,h]),v=p===`probing`?`border-primary/40 bg-primary/10 text-primary`:p===`ok`?`border-success/40 bg-success/10 text-success hover:bg-success/15`:p===`error`?`border-danger/40 bg-danger/10 text-danger hover:bg-danger/15`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,y=p===`probing`?N(Ea,{className:`h-3 w-3 animate-spin`}):N(p===`ok`?ki:p===`error`?Oi:$o,{className:`h-3 w-3`});return g(kL,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:i,children:[g(`div`,{className:`@container flex items-center gap-2`,style:{containerType:`inline-size`},children:[g(`button`,{type:`button`,onClick:_,title:`Test`,disabled:e.disabled||p===`probing`||!h||!t,className:`flex-shrink-0 inline-flex items-center gap-1.5 rounded-md border px-2 py-2 text-xs font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed @[280px]:px-3 ${v}`,children:[y,N(`span`,{className:`hidden @[280px]:inline`,children:`Test`})]}),N(`input`,{type:e.inputType??`url`,className:`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none disabled:opacity-50 disabled:cursor-not-allowed flex-1 min-w-0`,value:t==null?``:String(t),placeholder:e.placeholder,disabled:r||e.disabled,onChange:e=>{n(e.target.value),c!==`idle`&&(l(`idle`),f(null))}})]}),p===`ok`&&m?.labels&&m.labels.length>0&&N(`div`,{className:`flex flex-wrap gap-1 mt-1.5`,children:m.labels.map((e,t)=>N(`span`,{className:`text-xs bg-success/10 text-success rounded px-2 py-0.5 font-mono`,children:e},t))}),p===`error`&&m?.error&&N(`p`,{className:`text-xs text-danger mt-1 truncate`,title:m.error,children:m.error})]})}function GL({field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a}){let[o,s]=k(e.defaultCollapsed??!1),c=e.style===`accordion`;return N(`div`,{className:`${e.span===2?`col-span-2`:e.span===3?`col-span-3`:e.span===4?`col-span-4`:`col-span-1`} min-w-0`,children:g(`div`,{className:`@container rounded-lg border border-border bg-surface/50 overflow-hidden`,style:{containerType:`inline-size`},children:[g(`div`,{className:[`px-3 py-2 flex items-center justify-between min-w-0`,c?`cursor-pointer hover:bg-surface`:``].join(` `),onClick:c?()=>s(e=>!e):void 0,children:[N(`span`,{className:`text-xs font-semibold text-foreground min-w-0 break-words`,children:yR(e.label,i)}),c&&N(`span`,{className:`text-foreground-subtle text-xs shrink-0 ml-2`,children:o?`▸`:`▾`})]}),!o&&N(`div`,{className:`px-3 pb-3 grid grid-cols-1 @[480px]:grid-cols-2 gap-x-4 gap-y-3`,children:e.fields.map(e=>N(_R,{field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a},e.key))})]})})}function KL({field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,onAction:o}){let[s,c]=k(e.tabs[0]?.id??``),l=e.span===2?`col-span-2`:e.span===3?`col-span-3`:e.span===4?`col-span-4`:`col-span-1`;return e.tabs.length===0?null:g(`div`,{className:`${l} min-w-0`,children:[e.label&&N(`div`,{className:DL,children:yR(e.label,i)}),g(`div`,{className:`@container rounded-lg border border-border-subtle bg-surface-hover/40 overflow-hidden`,style:{containerType:`inline-size`},children:[N(`div`,{className:`flex flex-wrap gap-1 p-1.5 border-b border-border-subtle bg-surface/40`,role:`tablist`,children:e.tabs.map(e=>{let t=e.id===s;return g(`button`,{type:`button`,role:`tab`,"aria-selected":t,onClick:()=>c(e.id),className:`inline-flex items-center gap-1.5 whitespace-nowrap rounded-md px-2.5 py-1 text-[11px] transition-colors ${t?`bg-primary text-primary-foreground font-medium shadow-sm`:`bg-transparent text-foreground-subtle hover:bg-surface hover:text-foreground`}`,children:[N(`span`,{children:yR(e.label,i)}),e.badge&&N(`span`,{className:`text-[9px] px-1 py-0.5 rounded-full font-medium ${t?`bg-primary-foreground/20 text-primary-foreground`:`bg-primary/10 text-primary`}`,children:e.badge})]},e.id)})}),e.tabs.map(e=>e.id===s?N(`div`,{role:`tabpanel`,className:`px-3 pb-3 pt-2 grid grid-cols-1 @[480px]:grid-cols-2 gap-x-4 gap-y-3`,children:e.fields.map((s,c)=>{let l=`key`in s&&typeof s.key==`string`?s.key:`__${e.id}__${c}`;return N(_R,{field:s,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,onAction:o},l)})},e.id):null)]})]})}function qL({span:e}){return N(`div`,{className:e===2?`col-span-2`:e===3?`col-span-3`:e===4?`col-span-4`:`col-span-full`,children:N(`hr`,{className:`border-border`})})}var JL={info:{border:`border-info`,bg:`bg-info/5`,text:`text-info`},warning:{border:`border-warning`,bg:`bg-warning/5`,text:`text-warning`},success:{border:`border-success`,bg:`bg-success/5`,text:`text-success`},danger:{border:`border-danger`,bg:`bg-danger/5`,text:`text-danger`}};function YL(e){if(typeof window>`u`||typeof DOMParser>`u`)return``;let t=new Set([`A`,`UL`,`OL`,`LI`,`STRONG`,`EM`,`CODE`,`BR`,`P`,`SPAN`]),n=new DOMParser().parseFromString(`<div>${e}</div>`,`text/html`),r=n.body.firstElementChild;if(!r)return``;let i=e=>{let r=Array.from(e.children);for(let e of r){if(!t.has(e.tagName)){let t=n.createTextNode(e.textContent??``);e.replaceWith(t);continue}let r=e.tagName===`A`?new Set([`href`]):new Set;for(let t of Array.from(e.attributes))r.has(t.name)||e.removeAttribute(t.name);if(e.tagName===`A`){let t=e.getAttribute(`href`)??``;!/^https?:\/\//i.test(t)&&!t.startsWith(`mailto:`)?e.removeAttribute(`href`):(e.setAttribute(`target`,`_blank`),e.setAttribute(`rel`,`noopener noreferrer`))}i(e)}};return i(r),r.innerHTML}function XL({field:e}){let t=JL[e.variant??`info`]??JL.info,n=e.format===`html`;return N(`div`,{className:`col-span-full`,children:g(`div`,{className:`rounded-md border-l-4 px-3 py-2.5 ${t.border} ${t.bg}`,children:[e.label&&N(`p`,{className:`text-xs font-semibold mb-0.5 ${t.text}`,children:e.label}),n?N(`div`,{className:`text-xs text-foreground-subtle leading-relaxed info-html-content`,dangerouslySetInnerHTML:{__html:YL(e.content)}}):N(`p`,{className:`text-xs text-foreground-subtle leading-relaxed whitespace-pre-line`,children:e.content})]})})}function ZL({field:e}){let t=e.value;if(!t||t.length===0)return null;let n=e.size??192,r=e.alt??e.label;return N(`div`,{className:`col-span-full`,children:g(`div`,{className:`rounded-md border border-foreground-subtle/20 px-3 py-3 bg-background-subtle/40 flex flex-col items-start gap-2`,children:[e.label&&N(`p`,{className:`text-xs font-semibold text-foreground`,children:e.label}),e.caption&&N(`p`,{className:`text-xs text-foreground-subtle leading-relaxed`,children:e.caption}),N(CL,{value:t,size:n,alt:r})]})})}var QL={ok:`bg-success`,warn:`bg-amber-500`,danger:`bg-danger`,idle:`bg-foreground-subtle/40`,unknown:`bg-foreground-subtle/40`};function $L(e){if(!Number.isFinite(e)||e<0)return`—`;if(e<1e3)return`${e}ms`;let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60),r=t%60;return r===0?`${n}m`:`${n}m ${r}s`}function eR(e){return!Number.isFinite(e)||e<=0?`—`:new Date(e).toLocaleTimeString()}function tR({kind:e,value:t}){return t==null||t===``?N(`span`,{className:`text-foreground-subtle/60`,children:`—`}):e===`monospace`?N(`span`,{className:`font-mono text-[11px]`,children:String(t)}):e===`status`?g(`span`,{className:`inline-flex items-center gap-1.5`,children:[N(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full ${QL[String(t).toLowerCase()]??QL.unknown}`}),N(`span`,{children:String(t)})]}):e===`duration`&&typeof t==`number`?N(`span`,{className:`font-mono text-[11px]`,children:$L(t)}):e===`timestamp`&&typeof t==`number`?N(`span`,{className:`font-mono text-[11px]`,children:eR(t)}):N(`span`,{children:String(t)})}function nR({field:e}){let t=e.value??[],n=e.description;return g(`div`,{className:`col-span-full`,children:[e.label&&N(`p`,{className:`text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1`,children:e.label}),n&&N(`p`,{className:`text-xs text-foreground-subtle mb-2`,children:n}),t.length===0?N(`div`,{className:`rounded-md border border-border bg-surface-subtle px-3 py-2 text-xs text-foreground-subtle`,children:e.emptyMessage??`No entries`}):N(`div`,{className:`rounded-md border border-border overflow-hidden`,children:g(`table`,{className:`w-full text-xs`,children:[N(`thead`,{className:`bg-surface-subtle border-b border-border`,children:N(`tr`,{children:e.columns.map(e=>N(`th`,{className:`px-3 py-1.5 text-left font-medium text-foreground-subtle`,style:e.width?{width:e.width}:void 0,children:e.label},e.key))})}),N(`tbody`,{className:`divide-y divide-border`,children:t.map((t,n)=>N(`tr`,{className:`hover:bg-surface-hover/40`,children:e.columns.map(e=>N(`td`,{className:`px-3 py-1.5 align-top text-foreground`,children:N(tR,{kind:e.kind,value:t[e.key]})},e.key))},n))})]})})]})}function rR({field:e,value:t,onChange:n,disabled:r,translationFn:i,onTestField:a,onAction:o}){let s=Array.isArray(t)?t:[],c=e.minRows??0,l=e.maxRows??1/0,u=(e,t,r)=>{let i=s.slice();i[e]={...i[e]??{},[t]:r},n(i)},d=e=>{s.length<=c||n(s.filter((t,n)=>n!==e))},f=()=>{if(s.length>=l)return;let t=e.defaultItem??{};n([...s,{...t}])},p=(t,n)=>e.rowTitleTemplate?e.rowTitleTemplate.replace(/\{(\w+)\}/g,(e,n)=>{let r=t[n];return r==null||r===``?`—`:String(r)}):`Row ${n+1}`,m=s.length>c,h=s.length<l;return g(`div`,{className:`col-span-full space-y-2`,children:[g(`div`,{className:`space-y-0.5`,children:[e.label&&N(`p`,{className:`text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:yR(e.label,i)}),e.description&&N(`p`,{className:`text-[11px] text-foreground-subtle`,children:yR(e.description,i)})]}),s.length===0?N(`div`,{className:`rounded-md border border-dashed border-border bg-background px-3 py-3 text-center text-[11px] text-foreground-subtle`,children:e.emptyMessage??`No entries`}):N(`div`,{className:`space-y-2`,children:s.map((t,n)=>g(`div`,{className:`rounded-md border border-border bg-background`,children:[g(`div`,{className:`flex items-center justify-between border-b border-border px-3 py-1.5`,children:[N(`span`,{className:`text-xs font-medium text-foreground`,children:p(t,n)}),g(`button`,{type:`button`,onClick:()=>d(n),disabled:r||!m,className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-30 disabled:cursor-not-allowed`,title:m?`Remove this row`:`At least ${c} row(s) required`,children:[N(Ra,{className:`h-3 w-3`}),`Remove`]})]}),N(`div`,{className:`grid grid-cols-1 @[480px]:grid-cols-2 gap-x-3 gap-y-2 p-3`,children:e.itemFields.map(s=>N(_R,{field:s,values:t,onChange:(e,t)=>u(n,e,t),disabled:r,translationFn:i,onTestField:a,allFields:e.itemFields,onAction:o},s.key))})]},n))}),g(`div`,{children:[g(`button`,{type:`button`,onClick:f,disabled:r||!h,className:`inline-flex items-center gap-1 rounded border border-border bg-surface px-3 py-1 text-[11px] font-medium text-foreground hover:border-primary/40 hover:bg-primary/5 disabled:opacity-30 disabled:cursor-not-allowed`,children:[N($a,{className:`h-3 w-3`}),e.addLabel??`Add`]}),!h&&Number.isFinite(l)&&g(`span`,{className:`ml-2 text-[10px] text-foreground-subtle`,children:[`(limit: `,l,`)`]})]})]})}function iR({field:e,disabled:t,onAction:n}){let[r,i]=k(!1),a=Cl(),o=async()=>{if(!(e.confirmMessage&&!await a({title:e.label,message:e.confirmMessage,confirmLabel:e.buttonLabel,variant:e.variant===`danger`?`danger`:`default`}))&&n){i(!0);try{await n(e.action,e.key)}finally{i(!1)}}},s={default:`border border-border text-foreground hover:bg-surface-hover`,primary:`bg-primary text-primary-foreground hover:bg-primary/90`,danger:`bg-danger text-white hover:bg-danger/90`};return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,children:N(`button`,{onClick:o,disabled:t||r,className:`inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors disabled:opacity-50 ${s[e.variant??`default`]??s.default}`,children:r?`Processing...`:e.buttonLabel})})}function aR(e,t){let n={...e.paramsStatic};if(e.paramsFromForm)for(let[r,i]of Object.entries(e.paramsFromForm)){let e=t[i];e!=null&&e!==``&&(n[r]=e)}return n}function oR({field:e,value:t,values:n,onChange:r,disabled:i,onAction:a}){let[o,s]=k(!1),[c,l]=k(null),[u,d]=k(null),f=aR(e,n),p=Object.keys(e.paramsFromForm??{}).some(e=>f[e]===void 0);P(()=>{if(!a||p){d(null),l(null);return}let t=!1;return s(!0),l(null),a(e.action,e.key,f).then(e=>{if(t)return;let n=e,r=[];if(Array.isArray(n))r=n;else if(n&&typeof n==`object`)for(let e of Object.keys(n)){let t=n[e];if(Array.isArray(t)){r=t;break}}d(r)}).catch(e=>{t||(l(e instanceof Error?e.message:String(e)),d([]))}).finally(()=>{t||s(!1)}),()=>{t=!0}},[(e.refreshOn??Object.values(e.paramsFromForm??{})).map(e=>`${e}=${JSON.stringify(n[e])}`).join(`|`),a,e.action,e.key]);let m=e.mapOption.value,h=e.mapOption.label,_=e.mapOption.description;return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,children:p?N(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e.emptyParamsMessage??`Fill the prerequisite fields above first.`}):o?g(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[N(Ea,{className:`h-3 w-3 animate-spin`}),` Loading options…`]}):c?N(`div`,{className:`text-[11px] text-danger`,children:c}):u&&u.length===0?N(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e.emptyResultsMessage??`No options returned.`}):(()=>{let e=(u??[]).some(e=>{let t=e[m];return t===``||t===void 0});return g(`select`,{className:`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-xs text-foreground`,value:typeof t==`string`?t:``,disabled:i,onChange:e=>r(e.target.value),children:[!e&&N(`option`,{value:``,children:`— Select —`}),(u??[]).map((e,t)=>{let n=e[m],r=e[h],i=_?e[_]:void 0,a=typeof n==`string`&&n!==``?n:`row-${t}`;return g(`option`,{value:typeof n==`string`?n:String(n??``),children:[typeof r==`string`?r:String(r??a),i===void 0?``:` (${String(i)})`]},a)})]})})()})}function sR({field:e,values:t,disabled:n,onAction:r}){let[i,a]=k(!1),[o,s]=k(null),c=Cl(),l=async()=>{if(e.confirmMessage&&!await c({title:e.label,message:e.confirmMessage,confirmLabel:e.buttonLabel,variant:e.variant===`danger`?`danger`:`default`})||!r)return;let n=aR(e,t);a(!0),s(null);try{let t=await r(e.action,e.key,n),i=typeof t==`object`&&t?t:null;s({kind:`ok`,text:e.successMessage?e.successMessage.replace(/\{(\w+)\}/g,(e,t)=>{let n=i?.[t];return n===void 0?``:String(n)}):`Done.`})}catch(e){s({kind:`error`,text:e instanceof Error?e.message:String(e)})}finally{a(!1)}},u={default:`border border-border text-foreground hover:bg-surface-hover`,primary:`bg-primary text-primary-foreground hover:bg-primary/90`,danger:`bg-danger text-white hover:bg-danger/90`};return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,children:g(`div`,{className:`flex flex-col gap-1.5`,children:[N(`button`,{onClick:l,disabled:n||i,className:`inline-flex w-fit items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors disabled:opacity-50 ${u[e.variant??`default`]??u.default}`,children:i?`Working…`:e.buttonLabel}),o&&N(`div`,{className:`text-[11px] ${o.kind===`ok`?`text-emerald-700 dark:text-emerald-300`:`text-danger`}`,children:o.text})]})})}function cR({field:e,values:t,disabled:n,onAction:r}){let[i,a]=k(!1),[o,s]=k(null),c=Cl(),l=async()=>{if(e.confirmMessage&&!await c({title:e.label,message:e.confirmMessage,confirmLabel:e.buttonLabel,variant:e.variant===`danger`?`danger`:`default`})||!r)return;let n=aR(e,t);a(!0),s(null);try{let t=await r(`device-custom-action`,e.action,n),i=typeof t==`object`&&t?t:null;s({kind:`ok`,text:e.successMessage?e.successMessage.replace(/\{(\w+)\}/g,(e,t)=>{let n=i?.[t];return n===void 0?``:String(n)}):`Done.`})}catch(e){s({kind:`error`,text:e instanceof Error?e.message:String(e)})}finally{a(!1)}},u={default:`border border-border text-foreground hover:bg-surface-hover`,primary:`bg-primary text-primary-foreground hover:bg-primary/90`,danger:`bg-danger text-white hover:bg-danger/90`};return N(kL,{label:e.label,description:e.description,required:e.required,span:e.span,children:g(`div`,{className:`flex flex-col gap-1.5`,children:[N(`button`,{onClick:l,disabled:n||i,className:`inline-flex w-fit items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors disabled:opacity-50 ${u[e.variant??`default`]??u.default}`,children:i?`Working…`:e.buttonLabel}),o&&N(`div`,{className:`text-[11px] ${o.kind===`ok`?`text-emerald-700 dark:text-emerald-300`:`text-danger`}`,children:o.text})]})})}function lR({field:e}){let t=iF();return N(kL,{label:void 0,description:void 0,span:e.span,children:N(WI,{widgetId:e.widgetId,host:`device-tab`,config:e.widgetConfig,deviceId:t??void 0,instanceId:e.key})})}function uR(e,t){if(e==null)return`—`;if(typeof e==`boolean`)return e?`yes`:`no`;if(typeof e==`number`){let n=Number.isInteger(e)?String(e):e.toFixed(2);return t?`${n} ${t}`:n}return typeof e==`string`?e:JSON.stringify(e)}function dR({field:e,values:t,onAction:n,translationFn:r}){let i=`key`in e?e.key:void 0;if(!i)return null;let a=t[i],o=a===void 0?`default`in e?e.default:void 0:a,s=uR(o,`unit`in e?e.unit:void 0),c=`label`in e?e.label:void 0,l=`description`in e?e.description:void 0,u=`span`in e?e.span:void 0,d=`actions`in e?e.actions??[]:[];return N(kL,{label:c,description:l,span:u,translationFn:r,children:g(`div`,{className:`flex items-stretch gap-1`,children:[N(`div`,{className:`flex-1 rounded-md border border-border bg-surface-alt px-2.5 py-1.5 text-xs text-foreground font-mono break-all`,children:s}),d.length>0&&N(`div`,{className:`flex items-center gap-1`,children:d.map(e=>N(pR,{action:e,fieldKey:i,value:o,onAction:n},e.action))})]})})}function fR({name:e}){let t=`h-3.5 w-3.5`;switch(e){case`copy`:return N(Wi,{className:t});case`refresh-cw`:return N(oo,{className:t});case`external-link`:return N(ea,{className:t});case`trash-2`:return N(Bo,{className:t});case`download`:return N(Xi,{className:t});case`upload`:return N(Ko,{className:t});default:return N(ns,{className:t})}}function pR({action:e,fieldKey:t,value:n,onAction:r}){let i=Cl(),[a,o]=k(!1),s=e.variant===`danger`?`text-danger hover:bg-danger/10 border-danger/30`:e.variant===`primary`?`text-primary hover:bg-primary/10 border-primary/30`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover border-border`;return N(`button`,{type:`button`,onClick:async()=>{if(!(e.confirmMessage&&!await i({title:e.tooltip,message:e.confirmMessage,variant:e.variant===`danger`?`danger`:`default`}))){if(e.action===`copy-value`){try{await navigator.clipboard.writeText(typeof n==`string`?n:String(n))}catch{}return}if(r){o(!0);try{await r(e.action,t)}finally{o(!1)}}}},disabled:a,title:e.tooltip,className:`inline-flex items-center justify-center rounded-md border px-2 py-1.5 transition-colors disabled:opacity-50 ${s}`,children:N(fR,{name:e.icon})})}function mR(e){return`multiple`in e&&e.multiple!=null}function hR({field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,externalProbe:o,allFields:s,onAction:c}){let l=e.multiple,u=l.min,d=l.max,f=t[e.key],p=[...Array.isArray(f)?f:f==null?[]:[f]],m=l.itemDefault===void 0?`default`in e&&e.default!==void 0?e.default:``:l.itemDefault;for(;p.length<u;)p.push(m);let h=t=>n(e.key,[...t]),_=(e,t)=>{let n=[...p];n[e]=t,h(n)},v=()=>{p.length>=d||h([...p,m])},y=e=>{p.length<=u||h(p.filter((t,n)=>n!==e))},b=()=>{let{multiple:t,...n}=e,r={label:void 0,description:void 0,required:!1};return{...n,...r}};return N(kL,{label:e.label,description:e.description,required:u>0?e.required:!1,span:e.span,translationFn:i,children:g(`div`,{className:`space-y-2`,children:[p.map((n,o)=>{let d=l.itemLabel?.replace("${n}",String(o+1));return g(`div`,{className:`space-y-1`,children:[d&&N(`div`,{className:DL,children:d}),g(`div`,{className:`flex items-center gap-2`,children:[N(`div`,{className:`flex-1 min-w-0`,children:N(_R,{field:b(),values:{...t,[e.key]:n},onChange:(e,t)=>_(o,t),disabled:r,translationFn:i,onTestField:a,onAction:c,allFields:s})}),p.length>u&&N(`button`,{type:`button`,onClick:()=>y(o),disabled:r,title:`Remove`,className:`flex-shrink-0 inline-flex items-center justify-center rounded-md border border-border p-1.5 text-foreground-subtle hover:text-danger hover:border-danger/50 transition-colors disabled:opacity-40`,children:N(Bo,{className:`h-3.5 w-3.5`})})]})]},o)}),g(`div`,{className:`flex items-center justify-between pt-1`,children:[p.length<d?g(`button`,{type:`button`,onClick:v,disabled:r,className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40`,children:[N($a,{className:`h-3 w-3`}),l.addLabel??`Add`]}):N(`span`,{}),g(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[p.length,`/`,d]})]})]})})}function gR(e,t,n){if(!(`showWhen`in e)||!e.showWhen)return!0;let r=e.showWhen,i=t[r.field],a=n?.find(e=>`key`in e&&e.key===r.field),o=a&&`default`in a?a.default:void 0,s=i===void 0?o:i;return r.equals===void 0?r.notEquals===void 0?r.in===void 0?r.notIn===void 0?r.includes===void 0?r.notIncludes===void 0?!0:!Array.isArray(s)||!s.includes(r.notIncludes):Array.isArray(s)&&s.includes(r.includes):!r.notIn.includes(s):r.in.includes(s):s!==r.notEquals:s===r.equals}function _R({field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,externalProbe:o,allFields:s,onAction:c}){if(mR(e))return N(hR,{field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,externalProbe:o,allFields:s,onAction:c});if(`readonlyField`in e&&e.readonlyField===!0)return N(dR,{field:e,values:t,onAction:c,translationFn:i});if(!gR(e,t,s))return null;let l=t[e.key],u=l===void 0?`default`in e?e.default:void 0:l,d=t=>n(e.key,t),f=tF(e.type);switch(e.type){case`text`:return N(AL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`number`:return N(jL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`boolean`:return N(ML,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`select`:return N(NL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`multiselect`:return N(IL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`timezone`:return N(PL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`datetime`:return N(FL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`password`:return N(LL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`textarea`:return N(RL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`slider`:return N(zL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`tags`:return N(BL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`color`:return N(UL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`node-select`:return N(VL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`node-multiselect`:return N(HL,{field:e,value:u,onChange:d,disabled:r,translationFn:i});case`probe`:return N(WL,{field:e,value:u,onChange:d,disabled:r,translationFn:i,onTestField:a,onAction:c,externalProbe:o});case`group`:return N(GL,{field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a});case`sub-tabs`:return N(KL,{field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,onAction:c});case`separator`:return N(qL,{});case`info`:return N(XL,{field:e});case`qr-code`:return N(ZL,{field:e});case`object-array`:return N(nR,{field:e});case`editable-array`:return N(rR,{field:e,value:u,onChange:d,disabled:r,translationFn:i,onTestField:a,onAction:c});case`button`:return N(iR,{field:e,disabled:r,onAction:c});case`addon-action-select`:return N(oR,{field:e,value:u,values:t,onChange:d,disabled:r,onAction:c});case`addon-action-button`:return N(sR,{field:e,values:t,disabled:r,onAction:c});case`device-action-button`:return N(cR,{field:e,values:t,disabled:r,onAction:c});case`widget`:return N(lR,{field:e});default:return f?N(f,{field:e,value:u,onChange:d,disabled:r}):null}}h();function vR(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function yR(e,t){if(e!==void 0)return t&&vR(e)?t(e):e}function bR({section:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,probeResults:o}){let[s,c]=k(e.defaultCollapsed??!1),l=e.style===`accordion`,u=e.columns??2,d=u===1?`grid-cols-1`:u===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:u===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`;return g(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},children:[g(`div`,{className:[`flex items-center justify-between mb-2`,l?`cursor-pointer`:``].join(` `),onClick:l?()=>c(e=>!e):void 0,children:[g(`div`,{children:[N(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:yR(e.title,i)}),e.description&&N(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:yR(e.description,i)})]}),l&&N(`span`,{className:`text-foreground-subtle text-xs ml-2`,children:s?`▸`:`▾`})]}),!s&&N(`div`,{className:`grid ${d} gap-x-3 gap-y-2.5`,children:e.fields.map(e=>N(_R,{field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,externalProbe:o?.[e.key]},e.key))})]})}function xR({schema:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,probeResults:o,onClearProbe:s}){let c=(e,r)=>{n({...t,[e]:r}),s?.(e)};return N(`div`,{className:`space-y-4`,children:e.sections.map(e=>N(bR,{section:e,values:t,onChange:c,disabled:r,translationFn:i,onTestField:a,probeResults:o},e.id))})}h();var SR=({open:e})=>N(`svg`,{className:`h-3 w-3 transition-transform ${e?`rotate-90`:``}`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,children:N(`polyline`,{points:`9 18 15 12 9 6`})});function CR(e){let t={};if(!e)return t;for(let n of e.sections)for(let e of n.fields){if(e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`group`)continue;let n=e.key;t[n]=e.value}return t}function wR(e){return{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`group`)return e;let{value:t,...n}=e;return n})}))}}function TR({trpc:e,addonId:t,nodeId:n,title:r,disabled:i,onAfterChange:a,refreshToken:o,collapsible:s,defaultOpen:c,mode:l,onOverrideChange:u}){let d=l??`persist`,[f,p]=k(null),[m,h]=k(!0),[_,v]=k(null),[y,x]=k(!1),[S,C]=k(c??!1),[T,E]=k({}),[D,O]=k(null);P(()=>{O(null),E({})},[e,t,n,o,d]),P(()=>{let r=!1;h(!0),v(null);let i=d===`override`&&Object.keys(T).length>0?T:void 0;return e.addonSettings.getGlobalSettings.query({addonId:t,nodeId:n,...i?{overlay:i}:{}}).then(e=>{r||(p(t=>e??t),!i&&e&&O(CR(e)),h(!1))}).catch(e=>{r||(v(e instanceof Error?e.message:String(e)),h(!1))}),()=>{r=!0}},[e,t,n,o,d,JSON.stringify(T)]);let A=b(()=>CR(f),[f]),j=b(()=>f?wR(f):null,[f]),M=async r=>{if(d===`override`){let e=D??A,t={};for(let n of Object.keys(r))r[n]!==e[n]&&(t[n]=r[n]);let n={...e,...t};E(t),u?.(t,n);return}let i={};for(let e of Object.keys(r))r[e]!==A[e]&&(i[e]=r[e]);if(Object.keys(i).length!==0){x(!0);try{await e.addonSettings.updateGlobalSettings.mutate({addonId:t,nodeId:n,patch:i});let r=await e.addonSettings.getGlobalSettings.query({addonId:t,nodeId:n});r&&p(r),a?.()}catch(e){v(e instanceof Error?e.message:String(e))}finally{x(!1)}}};if(m)return g(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:[`Loading `,r??t,`…`]});if(_)return g(`div`,{className:`text-xs text-red-400`,children:[r??t,`: `,_]});if(!f||!j)return g(`div`,{className:`text-xs text-foreground-subtle`,children:[r??t,` not available on `,n,`.`]});let F=d===`override`?{...A,...T}:A,I=g(w,{children:[d===`override`?N(`div`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:`Benchmark override — applies to this run only. The addon's saved settings are not changed.`}):null,N(xR,{schema:j,values:F,onChange:M,disabled:i===!0||y})]});return s===!0?g(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[g(`button`,{type:`button`,onClick:()=>C(e=>!e),className:`w-full px-4 py-2 flex items-center gap-2 hover:bg-surface-hover text-left`,"aria-expanded":S,children:[N(SR,{open:S}),N(`h3`,{className:`text-xs font-semibold text-foreground uppercase tracking-wide flex-1`,children:r??t}),N(`span`,{className:`text-[10px] text-foreground-subtle`,children:S?`hide`:`edit`})]}),S?N(`div`,{className:`border-t border-border px-4 py-3`,children:I}):null]}):r?g(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[N(`div`,{className:`border-b border-border px-4 py-2`,children:N(`h3`,{className:`text-xs font-semibold text-foreground uppercase tracking-wide`,children:r})}),N(`div`,{className:`px-4 py-3`,children:I})]}):N(`div`,{children:I})}function ER({detections:{motion:e,motionRaw:t,detection:n,phase:r},showMotionZones:i=!0,showMotionRaw:a=!0,showDetections:o=!0,showPhaseIndicator:s=!0}){let c=i&&e&&e.zones.length>0,l=a&&t&&t.boxes.length>0,u=o&&n&&n.detections.length>0;return!c&&!l&&!u&&!s?null:g(`div`,{className:`absolute inset-0 pointer-events-none z-10`,children:[s&&N(DR,{phase:r}),l&&N(OR,{raw:t}),c&&N(kR,{motion:e}),u&&N(AR,{detections:n.detections,frameWidth:n.frameWidth,frameHeight:n.frameHeight})]})}function DR({phase:e}){let t=Ar(e);return g(`div`,{className:`absolute top-2 left-2 flex items-center gap-1.5 px-2 py-1 rounded-md bg-black/60 backdrop-blur-sm`,children:[N(`span`,{className:`w-2 h-2 rounded-full ${t.dotClass}`}),N(`span`,{className:`text-[10px] font-semibold text-white uppercase tracking-wider`,children:t.label})]})}function OR({raw:e}){return e.frameWidth===0||e.frameHeight===0?null:N(w,{children:e.boxes.map((t,n)=>{let[r,i,a,o]=t.bbox,s=r/e.frameWidth*100,c=i/e.frameHeight*100,l=(a-r)/e.frameWidth*100,u=(o-i)/e.frameHeight*100,d=Math.max(.05,Math.min(.25,t.changeScore*.3));return N(`div`,{className:`absolute rounded-sm`,style:{left:`${s}%`,top:`${c}%`,width:`${l}%`,height:`${u}%`,backgroundColor:`rgba(239, 68, 68, ${d})`}},`mr-${n}`)})})}function kR({motion:e}){return e.frameWidth===0||e.frameHeight===0?null:N(w,{children:e.zones.filter(t=>t.w*t.h/(e.frameWidth*e.frameHeight)<.9).map((t,n)=>{let r=Math.max(.15,Math.min(.5,t.intensity/255));return N(`div`,{className:`absolute rounded-sm`,style:{left:`${t.x/e.frameWidth*100}%`,top:`${t.y/e.frameHeight*100}%`,width:`${t.w/e.frameWidth*100}%`,height:`${t.h/e.frameHeight*100}%`,border:`1px solid rgba(250, 204, 21, ${r})`,backgroundColor:`rgba(250, 204, 21, ${r*.15})`}},`mz-${n}`)})})}function AR({detections:e,frameWidth:t,frameHeight:n}){return t===0||n===0?null:N(w,{children:e.map(e=>{let{x:r,y:i,width:a,height:o}=e.bbox,s=r/t*100,c=i/n*100,l=a/t*100,u=o/n*100,d=vM(e.macroClass),f=[`${e.macroClass} ${(e.score*100).toFixed(0)}%`];for(let t of e.labels)f.push(t.label);return N(`div`,{className:`absolute border-2 rounded-sm`,style:{left:`${s}%`,top:`${c}%`,width:`${l}%`,height:`${u}%`,borderColor:d},children:N(`div`,{className:`absolute -top-4 left-0 px-1 py-0.5 text-[9px] font-bold text-white rounded-sm whitespace-nowrap`,style:{backgroundColor:d},children:f.join(` | `)})},`det-${e.id}`)})})}h();function jR(){return typeof window>`u`?!1:window.matchMedia(`(hover: none) and (pointer: coarse)`).matches||typeof navigator<`u`&&navigator.maxTouchPoints>0||`ontouchstart`in window}function MR(e,t,n){let r=0;for(let i=0;i<8;i++)for(let a=0;a<8;a++){let o=Math.min(t-1,Math.floor((a+.5)/8*t)),s=Math.min(n-1,Math.floor((i+.5)/8*n)),{data:c}=e.getImageData(o,s,1,1);.2126*(c[0]??0)+.7152*(c[1]??0)+.0722*(c[2]??0)>12&&r++}return r<=1}function NR(e){let t={};if(typeof window<`u`){if(e){let n=e.getBoundingClientRect();n.width>0&&n.height>0&&(t.viewportWidth=Math.round(n.width),t.viewportHeight=Math.round(n.height))}t.viewportWidth===void 0&&(t.viewportWidth=window.innerWidth,t.viewportHeight=window.innerHeight),t.devicePixelRatio=window.devicePixelRatio||1;let n=navigator.connection;n?.downlink&&n.downlink>0&&(t.downlinkMbps=n.downlink)}return t}var PR=1500,FR=15e3,IR=40;function LR({serverUrl:e,streamKey:t,label:n,autoPlay:r=!0,muted:i=!0,showControls:a=!0,showStats:o=!1,onPlaybackStats:s,className:c=``,onStateChange:l,onError:d,overlay:p,createSession:m,sendAnswer:h,handleOffer:_,getIceServers:v,addIceCandidate:y,getIceCandidates:b,closeSession:x,getSessionState:S,reoffer:C,posterUrl:w,hintsOverride:T,reconnectSignal:E,onControlChannel:D}){let O=f(null),A=f(null),j=f(null),M=f(new Set),F=f(null),I=f(null),L=f(0),R=f(!0),ee=f(D);ee.current=D;let z=f(null),B=f(null),V=f(0),te=f(!1),H=f(async()=>{}),[U,ne]=k(`idle`),[re,ie]=k(``),[ae,oe]=k(i),[se,W]=k(!1),[ce,le]=k(!1),ue=jR(),[de,fe]=k(!0),pe=f(null),G=f(!1);(h||m)&&(G.current=!0);let me=G.current,he=f(!1);_&&(he.current=!0);let ge=he.current,[_e,ve]=k(!1),ye=f(null),[be,xe]=k(null),[Se,Ce]=k(!1),we=u(()=>{let e=O.current;if(!(!e||e.readyState<2||!e.videoWidth||!e.videoHeight))try{let t=document.createElement(`canvas`);t.width=e.videoWidth,t.height=e.videoHeight;let n=t.getContext(`2d`);if(!n||(n.drawImage(e,0,0),MR(n,t.width,t.height)))return;ye.current=t.toDataURL(`image/jpeg`,.6)}catch{}},[]),Te=u(e=>{ne(e),e===`playing`&&ve(!0),l?.(e)},[l]),Ee=u(()=>{if(F.current?.abort(),F.current=null,I.current&&=(clearTimeout(I.current),null),B.current&&=(clearTimeout(B.current),null),z.current=null,te.current=!1,V.current=0,j.current&&=(j.current.close(),null),x&&M.current.size>0){for(let e of M.current)x(e).catch(()=>{});M.current.clear()}},[x]),De=u(()=>{F.current?.abort(),F.current=null,I.current&&=(clearTimeout(I.current),null),B.current&&=(clearTimeout(B.current),null),z.current=null,te.current=!1,V.current=0},[]),Oe=1e3,ke=u(e=>{if(!S||!C)return;B.current&&=(clearTimeout(B.current),null);let t=async()=>{if(R.current&&z.current===e){if(!te.current)try{let{pendingRenegotiation:t}=await S(e);if(R.current&&z.current===e&&t&&t.epoch>V.current&&!te.current){V.current=t.epoch,await H.current(e,t.target);return}}catch{}!R.current||z.current!==e||(B.current=setTimeout(()=>{t()},Oe))}};B.current=setTimeout(()=>{t()},Oe)},[S,C]),Ae=u(async(e=!1)=>{if(!R.current||!m||!h)return;let t=e?j.current:null,n=e?new Set(M.current):null;e?De():Ee(),Te(`connecting`);let r=new AbortController;F.current=r;try{let{sessionId:i,sdpOffer:a,iceServers:o}=await m({...NR(A.current),...T});if(M.current.add(i),!R.current||r.signal.aborted){x?.(i).catch(()=>{}),M.current.delete(i);return}let s=new RTCPeerConnection({iceServers:[...o??[],{urls:`stun:stun.l.google.com:19302`}]});e||(j.current=s);let c=new MediaStream,l=!1,u=()=>{if(!(l||!R.current)){if(l=!0,j.current=s,O.current&&(O.current.srcObject=c,O.current.play().catch(()=>{})),t&&t!==s)try{t.close()}catch{}if(n)for(let e of n)M.current.delete(e),x?.(e).catch(()=>{})}};s.ontrack=t=>{if(console.debug(`[WebRTC] ontrack`,t.track.kind,t.track.readyState),c.addTrack(t.track),e){u();return}O.current&&(O.current.srcObject=c,O.current.play().catch(()=>{}))},s.oniceconnectionstatechange=()=>{if(!R.current)return;let t=s.iceConnectionState;if(console.debug(`[WebRTC] ICE state:`,t),t===`connected`||t===`completed`)L.current=0,e&&u(),Te(`playing`),O.current?.paused&&(console.debug(`[WebRTC] video was paused at ICE connected — calling play()`),O.current.play().catch(()=>{}));else if(t===`failed`||t===`disconnected`||t===`closed`){if(e&&!l)try{s.close()}catch{}Te(`disconnected`),Fe()}},s.onicecandidateerror=e=>{console.debug(`[WebRTC] ICE candidate error:`,e)},console.debug(`[WebRTC] Setting remote description (server offer)...`),await s.setRemoteDescription({type:`offer`,sdp:a});let d=await s.createAnswer();if(await s.setLocalDescription(d),console.debug(`[WebRTC] Local description set, waiting for ICE gathering...`),await zR(s),!R.current)return;let f=(s.localDescription?.sdp??``).split(`
65
65
  `).filter(e=>e.startsWith(`a=candidate:`)).length;console.debug(`[WebRTC] Sending answer to server`,{localCandidates:f,sessionId:i.slice(0,8)}),await h(i,s.localDescription?.sdp??``),console.debug(`[WebRTC] Answer sent successfully`);let p=s,g=()=>{let e=p.connectionState;if(e===`closed`||e===`failed`)return;let t=O.current;t&&t.readyState===0&&console.log(`[WebRTC] no video data yet (ice=${p.iceConnectionState})`)};setTimeout(g,3e3),setTimeout(g,8e3)}catch(e){if(!R.current)return;let t=e instanceof Error?e.message:String(e);ie(t),Te(`error`),d?.(t),Fe()}},[e,t,m,h,Ee,De,x,Te,d,T]),je=u(async()=>{if(R.current){Ee(),Te(`connecting`);try{let n=new RTCPeerConnection({iceServers:[{urls:`stun:stun.l.google.com:19302`}]});j.current=n,n.addTransceiver(`video`,{direction:`recvonly`}),n.addTransceiver(`audio`,{direction:`recvonly`});let r=new MediaStream;n.ontrack=e=>{r.addTrack(e.track),O.current&&(O.current.srcObject=r,O.current.play().catch(()=>{}))},n.oniceconnectionstatechange=()=>{if(!R.current)return;let e=n.iceConnectionState;e===`connected`||e===`completed`?(L.current=0,Te(`playing`),O.current?.paused&&O.current.play().catch(()=>{})):(e===`failed`||e===`disconnected`||e===`closed`)&&(Te(`disconnected`),Fe())};let i=await n.createOffer();if(await n.setLocalDescription(i),await zR(n),!R.current)return;let a=`${e}/api/webrtc?src=${encodeURIComponent(t)}`,o=await fetch(a,{method:`POST`,headers:{"Content-Type":`application/sdp`},body:n.localDescription?.sdp??``});if(!o.ok)throw Error(`WHEP ${o.status}: ${o.statusText}`);let s=await o.text();await n.setRemoteDescription({type:`answer`,sdp:s})}catch(e){if(!R.current)return;let t=e instanceof Error?e.message:String(e);ie(t),Te(`error`),d?.(t),Fe()}}},[e,t,Ee,Te,d]),Me=u(async(e=!1)=>{if(!R.current||!_)return;let n=e?j.current:null,r=e?new Set(M.current):null;e?De():Ee(),Te(`connecting`);let i=new AbortController;F.current=i;let a=performance.now(),o=()=>Math.round(performance.now()-a),s={};try{let a=await v?.();if(s.iceServersMs=o(),!R.current||i.signal.aborted)return;let c=new RTCPeerConnection({iceServers:[...a??[],{urls:`stun:stun.l.google.com:19302`}]});e||(j.current=c);let l=new MediaStream,u=!1,d=()=>{if(!(u||!R.current)){if(u=!0,j.current=c,O.current&&(O.current.srcObject=l,O.current.play().catch(()=>{})),n&&n!==c)try{n.close()}catch{}if(r)for(let e of r)M.current.delete(e),x?.(e).catch(()=>{})}};c.ontrack=t=>{if(s.firstTrackMs===void 0&&(s.firstTrackMs=o()),console.debug(`[WebRTC] ontrack (client-offer)`,t.track.kind,t.track.readyState),l.addTrack(t.track),e){d();return}O.current&&(O.current.srcObject=l,O.current.play().catch(()=>{}))};let f=!1;c.oniceconnectionstatechange=()=>{if(!R.current)return;let n=c.iceConnectionState;if(console.debug(`[WebRTC] ICE state (client-offer):`,n),n===`connected`||n===`completed`)f||(f=!0,s.iceConnectedMs=o(),console.info(`[WebRTC timing] client-offer connected`,{streamKey:t,...s})),L.current=0,e&&d(),Te(`playing`),O.current?.paused&&O.current.play().catch(()=>{});else if(n===`failed`||n===`disconnected`||n===`closed`){if(e&&!u)try{c.close()}catch{}Te(`disconnected`),Fe()}};let p=null,m=[];if(c.onicecandidate=e=>{if(!e.candidate)return;let t=e.candidate.toJSON();p&&y?y(p,t).catch(()=>{}):m.push(t)},c.addTransceiver(`video`,{direction:`recvonly`}),c.addTransceiver(`audio`,{direction:`recvonly`}),ee.current){let e=c.createDataChannel(`camstack-control`);ee.current(e)}let h=await c.createOffer();if(s.offerCreatedMs=o(),await c.setLocalDescription(h),s.localSetMs=o(),!R.current||i.signal.aborted)return;let g=o(),{sessionId:S,sdpAnswer:C}=await _(c.localDescription?.sdp??h.sdp??``);if(s.signalingRttMs=o()-g,p=S,M.current.add(S),z.current=S,!R.current||i.signal.aborted){x?.(S).catch(()=>{}),M.current.delete(S);return}if(y)for(let e of m)y(S,e).catch(()=>{});if(m.length=0,await c.setRemoteDescription({type:`answer`,sdp:C}),s.answerSetMs=o(),console.debug(`[WebRTC] Client-offer answer set (trickle)`,{sessionId:S.slice(0,8)}),b){let e=new Set,t=Date.now(),n=async()=>{if(!(!R.current||i.signal.aborted)&&!(c.connectionState===`closed`||c.signalingState===`closed`)){try{let{candidates:n,done:r}=await b(S);for(let t of n){let n=t.candidate??``;n&&!e.has(n)&&(e.add(n),c.addIceCandidate(new RTCIceCandidate(t)).catch(()=>{}))}let i=c.iceConnectionState;if(r||Date.now()-t>1e4||i===`connected`||i===`completed`)return}catch{}setTimeout(()=>{n()},200)}};n()}ke(S)}catch(e){if(!R.current)return;let t=e instanceof Error?e.message:String(e);ie(t),Te(`error`),d?.(t),Fe()}},[_,v,y,b,x,Ee,De,Te,d,ke]);H.current=u(async(e,t)=>{let n=C;if(!R.current||!n)return;let r=j.current;te.current=!0;try{let i=await v?.();if(!R.current)return;let a=new RTCPeerConnection({iceServers:[...i??[],{urls:`stun:stun.l.google.com:19302`}]}),o=new MediaStream,s=!1,c=()=>{s||!R.current||(s=!0,j.current=a,O.current&&(O.current.srcObject=o,O.current.play().catch(()=>{})),r&&r!==a&&r.close())};a.ontrack=e=>{console.debug(`[WebRTC] ontrack (reoffer)`,e.track.kind,e.track.readyState),o.addTrack(e.track),c()},a.oniceconnectionstatechange=()=>{if(!R.current)return;let e=a.iceConnectionState;console.debug(`[WebRTC] ICE state (reoffer):`,e),e===`connected`||e===`completed`?(L.current=0,c(),Te(`playing`),O.current?.paused&&O.current.play().catch(()=>{})):(e===`failed`||e===`closed`)&&(!s&&e===`failed`&&a.close(),Te(`disconnected`),Fe())};let l=null,u=[];if(a.onicecandidate=e=>{if(!e.candidate)return;let t=e.candidate.toJSON();l&&y?y(l,t).catch(()=>{}):u.push(t)},a.addTransceiver(`video`,{direction:`recvonly`}),a.addTransceiver(`audio`,{direction:`recvonly`}),ee.current){let e=a.createDataChannel(`camstack-control`);ee.current(e)}let d=await a.createOffer();if(await a.setLocalDescription(d),!R.current){a.close();return}let{sessionId:f,sdpAnswer:p}=await n(e,a.localDescription?.sdp??d.sdp??``,t);if(!R.current){a.close();return}if(l=f,M.current.add(f),z.current=f,y)for(let e of u)y(f,e).catch(()=>{});if(u.length=0,await a.setRemoteDescription({type:`answer`,sdp:p}),b){let e=new Set,t=Date.now(),n=async()=>{if(R.current&&!(a.connectionState===`closed`||a.signalingState===`closed`)){try{let{candidates:n,done:r}=await b(f);for(let t of n){let n=t.candidate??``;n&&!e.has(n)&&(e.add(n),a.addIceCandidate(new RTCIceCandidate(t)).catch(()=>{}))}let i=a.iceConnectionState;if(r||Date.now()-t>1e4||i===`connected`||i===`completed`)return}catch{}setTimeout(()=>{n()},200)}};n()}ke(f)}catch(t){console.debug(`[WebRTC] reoffer failed; keeping last frame, re-arming poll`,t instanceof Error?t.message:String(t)),ke(e)}finally{te.current=!1}},[C,v,y,b,Te,ke]);let Ne=ge?Me:me?Ae:je,Pe=f(()=>{});Pe.current=Ne;let Fe=u(()=>{if(!R.current||L.current>=IR)return;let e=L.current;L.current+=1;let t=Math.min(FR,PR*2**e),n=Math.round(t*(.8+Math.random()*.4));I.current=setTimeout(()=>{R.current&&Pe.current()},n)},[]);P(()=>(R.current=!0,L.current=0,r&&Ne(),()=>{R.current=!1,Ee()}),[e,t]);let Ie=f(!1);P(()=>{if(r){if(ge){if(!_)return}else if(me){if(!m||!h)return}else return;Ie.current||j.current||(Ie.current=!0,Ne())}},[r,ge,me,_,m,h,Ne]);let Le=()=>{L.current=0,Ne()},K=()=>{if(L.current=0,j.current&&ge){Me(!0);return}if(j.current&&me){Ae(!0);return}Ne()},Re=f(E);P(()=>{Re.current!==E&&(Re.current=E,R.current&&K())},[E]);let ze=()=>{O.current&&(O.current.muted=!O.current.muted,oe(O.current.muted))},Be=async()=>{if(A.current)try{if(document.fullscreenElement){await document.exitFullscreen();return}if(A.current.requestFullscreen){await A.current.requestFullscreen();return}let e=O.current;e?.webkitEnterFullscreen&&e.webkitEnterFullscreen()}catch(e){console.warn(`Fullscreen toggle failed: ${e instanceof Error?e.message:e}`)}},Ve=async()=>{let e=O.current;if(e)try{if(typeof e.webkitSetPresentationMode==`function`){e.webkitSetPresentationMode(e.webkitPresentationMode===`picture-in-picture`?`inline`:`picture-in-picture`);return}document.pictureInPictureElement?await document.exitPictureInPicture():await e.requestPictureInPicture()}catch(e){console.warn(`PiP toggle failed: ${e instanceof Error?e.message:String(e)}`)}},He=()=>{if(!O.current)return;let e=document.createElement(`canvas`);e.width=O.current.videoWidth||1280,e.height=O.current.videoHeight||720;let n=e.getContext(`2d`);if(!n)return;n.drawImage(O.current,0,0);let r=document.createElement(`a`);r.download=`${t.replace(/[/:]/g,`-`)}-${Date.now()}.jpg`,r.href=e.toDataURL(`image/jpeg`,.92),r.click()};P(()=>{let e=()=>W(!!document.fullscreenElement);document.addEventListener(`fullscreenchange`,e);let t=O.current;return t?.addEventListener(`webkitbeginfullscreen`,e),t?.addEventListener(`webkitendfullscreen`,e),()=>{document.removeEventListener(`fullscreenchange`,e),t?.removeEventListener(`webkitbeginfullscreen`,e),t?.removeEventListener(`webkitendfullscreen`,e)}},[]),P(()=>{let e=O.current,t=typeof document<`u`&&document.pictureInPictureEnabled===!0,n=e!==null&&typeof e.webkitSetPresentationMode==`function`;le(t||n)},[]);let[Ue,We]=k(``),Ge=f(null);P(()=>{if(!o){We(``),Ge.current=null;return}let e=async()=>{let e=j.current;if(e)try{let t=await e.getStats(),n=0,r=0,i=0,a=0,o=0,s=0;t.forEach(e=>{let t=e;t.type===`inbound-rtp`&&(t.kind??t.mediaType)===`video`?(n=t.bytesReceived??0,r=t.timestamp,i=t.framesPerSecond??0,a=t.frameWidth??0,o=t.frameHeight??0):t.type===`candidate-pair`&&t.nominated&&typeof t.currentRoundTripTime==`number`&&(s=t.currentRoundTripTime)});let c=0;Ge.current&&r>Ge.current.ts&&(c=Math.round((n-Ge.current.bytes)*8/(r-Ge.current.ts))),Ge.current={bytes:n,ts:r};let l=[];a&&o&&l.push(`${a}×${o}`),i&&l.push(`${Math.round(i)}fps`),c>0&&l.push(`${c} kbps`),s&&l.push(`${Math.round(s*1e3)}ms`),We(l.join(` · `))}catch{}};e();let t=setInterval(()=>{e()},1e3);return()=>clearInterval(t)},[o]);let Ke=f(null);P(()=>{if(!s){Ke.current=null;return}let e=async()=>{let e=j.current,t=O.current;if(e)try{let n=await e.getStats(),r=0,i=0,a=0,o=0,c=0,l=0,u=0,d=0;n.forEach(e=>{let t=e;t.type===`inbound-rtp`&&(t.kind??t.mediaType)===`video`&&(r=t.framesReceived??0,i=t.framesDecoded??0,a=t.framesDropped??0,o=t.framesPerSecond??0,c=t.freezeCount??0,l=t.totalFreezesDuration??0,u=t.jitterBufferDelay??0,d=t.jitterBufferEmittedCount??0)});let f=t?.currentTime??0,p=Date.now(),m=Ke.current,h=d>0?Math.round(u/d*1e3):0;m&&s({dRecv:r-m.recv,dDec:i-m.dec,dDrop:a-m.drop,fps:Math.round(o),dFreeze:c-m.freeze,freezeTotalMs:Math.round(l*1e3),avgJitterMs:h,dCtMs:Math.round((f-m.ct)*1e3),dtMs:p-m.ts,readyState:t?.readyState??-1}),Ke.current={recv:r,dec:i,drop:a,freeze:c,ct:f,ts:p}}catch{}};e();let t=setInterval(()=>{e()},1e3);return()=>clearInterval(t)},[s]),P(()=>{oe(i);let e=O.current;e&&(e.muted=i,i||e.play().catch(()=>{}))},[i]);let qe=()=>{ue||(fe(!0),pe.current&&clearTimeout(pe.current),pe.current=setTimeout(()=>fe(!1),3e3))},Je=()=>{fe(e=>!e),pe.current&&clearTimeout(pe.current)};P(()=>{if(U===`playing`){we();let e=setInterval(we,2e3);return()=>clearInterval(e)}_e&&ye.current&&xe(ye.current)},[U,_e,we]),P(()=>{if(U!==`playing`){Ce(!1);return}let e=O.current;if(!e)return;let t=!1,n=()=>{t||Ce(!0)},r;typeof e.requestVideoFrameCallback==`function`&&(r=e.requestVideoFrameCallback(()=>n())),e.addEventListener(`loadeddata`,n,{once:!0});let i=setTimeout(n,12e3);return()=>{t=!0,clearTimeout(i),r!==void 0&&typeof e.cancelVideoFrameCallback==`function`&&e.cancelVideoFrameCallback(r),e.removeEventListener(`loadeddata`,n)}},[U]);let Ye=_e&&be?be:w??null,Xe=!Se&&Ye!==null;return g(`div`,{ref:A,className:`relative isolate bg-black overflow-hidden group ${c}`,onMouseMove:qe,onMouseEnter:qe,onTouchStart:Je,children:[N(`video`,{ref:O,autoPlay:r,muted:ae,playsInline:!0,className:`w-full h-full object-contain relative z-0`}),Xe&&Ye&&N(`img`,{src:Ye,alt:``,className:`absolute inset-0 w-full h-full object-contain z-[5] transform-gpu pointer-events-none`}),n&&U===`playing`&&N(`div`,{className:`absolute top-2 left-2 z-10 transform-gpu px-2 py-0.5 rounded bg-black/60 text-[10px] text-white font-medium`,children:n}),o&&Ue&&N(`div`,{className:`absolute top-2 right-2 z-10 transform-gpu px-2 py-0.5 rounded bg-black/60 text-[10px] text-white font-mono`,children:Ue}),p,!Ye&&U===`connecting`&&g(`div`,{className:`absolute inset-0 z-10 transform-gpu flex flex-col items-center justify-center bg-black/70 gap-2`,children:[N(`svg`,{className:`h-6 w-6 text-white/60 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:N(`circle`,{cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`3`,strokeLinecap:`round`,strokeDasharray:`32`,strokeDashoffset:`32`,className:`animate-[dash_1.5s_ease-in-out_infinite]`})}),N(`span`,{className:`text-xs text-white/60`,children:`Connecting…`})]}),!Ye&&(U===`error`||U===`disconnected`)&&g(`div`,{className:`absolute inset-0 z-10 transform-gpu flex flex-col items-center justify-center bg-black/70 gap-2`,children:[N(`svg`,{className:`h-6 w-6 text-red-400`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:N(`path`,{d:`M1 1l5.5 5.5M23 23l-5.5-5.5M8.11 15.89a8 8 0 0110.78-10.78M3.64 3.64A12 12 0 0020.36 20.36`,strokeLinecap:`round`})}),N(`span`,{className:`text-xs text-red-400 text-center px-4`,children:U===`error`?re||`Connection failed`:`Disconnected`}),N(`button`,{onClick:Le,className:`mt-1 inline-flex items-center gap-1.5 rounded px-3 py-1 text-xs bg-white/10 text-white hover:bg-white/20 transition-colors`,children:`Reconnect`})]}),Ye&&(U===`connecting`||U===`disconnected`)&&N(`div`,{className:`absolute top-2 left-2 z-10 transform-gpu flex h-6 w-6 items-center justify-center rounded-full bg-black/55`,children:N(`svg`,{className:`h-3.5 w-3.5 text-white/90 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:N(`circle`,{cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`3`,strokeLinecap:`round`,strokeDasharray:`32`,strokeDashoffset:`32`,className:`animate-[dash_1.5s_ease-in-out_infinite]`})})}),Ye&&U===`error`&&N(`button`,{onClick:Le,title:re||`Reconnect`,className:`absolute top-2 left-2 z-10 transform-gpu flex h-6 w-6 items-center justify-center rounded-full bg-black/55 text-white/90 hover:bg-black/75 transition-colors`,children:g(`svg`,{className:`h-3.5 w-3.5`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[N(`path`,{d:`M23 4v6h-6M1 20v-6h6`}),N(`path`,{d:`M3.51 9a9 9 0 0114.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0020.49 15`})]})}),a&&U!==`idle`&&U!==`error`&&g(`div`,{className:`absolute bottom-0 inset-x-0 z-20 transform-gpu flex items-center justify-between px-3 py-1.5 bg-gradient-to-t from-black/80 to-transparent transition-opacity duration-200 ${ue||de?`opacity-100 pointer-events-auto`:`opacity-0 pointer-events-none`}`,children:[N(`div`,{className:`flex items-center gap-1`,children:N(RR,{onClick:ze,title:ae?`Unmute`:`Mute`,children:ae?g(`svg`,{className:`h-3.5 w-3.5`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,children:[N(`polygon`,{points:`11 5 6 9 2 9 2 15 6 15 11 19 11 5`}),N(`line`,{x1:`23`,y1:`9`,x2:`17`,y2:`15`}),N(`line`,{x1:`17`,y1:`9`,x2:`23`,y2:`15`})]}):g(`svg`,{className:`h-3.5 w-3.5`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,children:[N(`polygon`,{points:`11 5 6 9 2 9 2 15 6 15 11 19 11 5`}),N(`path`,{d:`M19.07 4.93a10 10 0 010 14.14M15.54 8.46a5 5 0 010 7.07`})]})})}),g(`div`,{className:`flex items-center gap-1`,children:[N(RR,{onClick:He,title:`Take snapshot`,children:g(`svg`,{className:`h-3.5 w-3.5`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,children:[N(`path`,{d:`M23 19a2 2 0 01-2 2H3a2 2 0 01-2-2V8a2 2 0 012-2h4l2-3h6l2 3h4a2 2 0 012 2z`}),N(`circle`,{cx:`12`,cy:`13`,r:`4`})]})}),ce&&N(RR,{onClick:Ve,title:`Picture-in-Picture`,children:g(`svg`,{className:`h-3.5 w-3.5`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[N(`path`,{d:`M21 9V6a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2h4`}),N(`rect`,{width:`10`,height:`7`,x:`12`,y:`13`,rx:`2`})]})}),N(RR,{onClick:Be,title:se?`Exit fullscreen`:`Fullscreen`,children:se?N(`svg`,{className:`h-3.5 w-3.5`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,children:N(`path`,{d:`M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3`})}):N(`svg`,{className:`h-3.5 w-3.5`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,children:N(`path`,{d:`M8 3H5a2 2 0 00-2 2v3m18 0V5a2 2 0 00-2-2h-3m0 18h3a2 2 0 002-2v-3M3 16v3a2 2 0 002 2h3`})})})]})]})]})}function RR({onClick:e,title:t,children:n}){return N(`button`,{onClick:e,title:t,className:`rounded-full p-1.5 min-w-[44px] min-h-[44px] flex items-center justify-center text-white/80 hover:text-white hover:bg-white/20 active:bg-white/30 transition-colors`,children:n})}async function zR(e){if(e.iceGatheringState!==`complete`)return new Promise(t=>{let n=!1,r,i=()=>{n||(n=!0,r&&clearInterval(r),e.removeEventListener(`icegatheringstatechange`,a),t())},a=()=>{e.iceGatheringState===`complete`&&i()};e.addEventListener(`icegatheringstatechange`,a);let o=Date.now();r=setInterval(()=>{let t=e.localDescription?.sdp??``;/ typ host/.test(t)&&Date.now()-o>=600&&i()},100),setTimeout(i,2500)})}function BR(e,t){return e.name!==void 0&&e.name.length>0?e.name:e.height!==void 0&&e.height>0?`${e.height}p`:e.bitrate!==void 0&&e.bitrate>0?`${Math.round(e.bitrate/1e3)} kbps`:`Level ${t+1}`}function VR(e){return[{value:-1,label:`Auto`},...e.map((e,t)=>({value:t,label:BR(e,t)}))]}h();function HR(e){return{height:e.height>0?e.height:void 0,bitrate:e.bitrate>0?e.bitrate:void 0,name:e.name.length>0?e.name:void 0}}function UR({url:e,authToken:t,posterUrl:n,autoPlay:r=!0,className:i,onQualityOptions:o,selectedLevel:s=-1}){let c=f(null),l=f(null),[u,d]=k(null),[p,m]=k(!0);return P(()=>{let n=c.current;if(!n||!e)return;d(null),m(!0),o?.([]);let i=()=>m(!1);if(n.addEventListener(`playing`,i),!(`MediaSource`in window)&&n.canPlayType(`application/vnd.apple.mpegurl`)){n.src=e;let t=()=>{r&&n.play().catch(()=>{})};return n.addEventListener(`loadedmetadata`,t),n.addEventListener(`error`,()=>d(`Could not load this recording.`)),()=>{n.removeEventListener(`loadedmetadata`,t),n.removeEventListener(`playing`,i),n.removeAttribute(`src`),n.load()}}let s=!1;return a(async()=>{let{default:e}=await import(`./hls-IujbK-0_.js`);return{default:e}},[]).then(({default:i})=>{if(s)return;if(!i.isSupported()){n.canPlayType(`application/vnd.apple.mpegurl`)?(n.src=e,n.addEventListener(`loadedmetadata`,()=>{r&&n.play().catch(()=>{})}),n.addEventListener(`error`,()=>d(`Could not load this recording.`))):(m(!1),d(`HLS playback is not supported in this browser.`));return}let a=new i({enableWorker:!0,lowLatencyMode:!1,xhrSetup:e=>{e.withCredentials=!0,t&&e.setRequestHeader(`Authorization`,`Bearer ${t}`)}});l.current=a,a.loadSource(e),a.attachMedia(n),a.on(i.Events.MANIFEST_PARSED,(e,t)=>{let i=t.levels.map(HR);o?.(i.length>1?VR(i):[]),r&&n.play().catch(()=>{})}),a.on(i.Events.ERROR,(e,t)=>{t.fatal&&(m(!1),d(`Playback error (${t.type}).`))})}),()=>{s=!0,n.removeEventListener(`playing`,i),l.current?.destroy(),l.current=null}},[e,t,r,o]),P(()=>{let e=l.current;e!==null&&(e.currentLevel=s)},[s]),g(`div`,{className:`relative h-full w-full bg-black ${i??``}`,children:[N(`video`,{ref:c,controls:!0,playsInline:!0,className:`h-full w-full`,...n?{poster:n}:{}}),p&&!u?N(`div`,{className:`pointer-events-none absolute inset-0 flex items-center justify-center`,children:N(`div`,{className:`h-8 w-8 animate-spin rounded-full border-2 border-white/20 border-t-white/60`})}):null,u?N(`div`,{className:`absolute inset-0 flex items-center justify-center px-4 text-center text-sm text-amber-400`,children:u}):null]})}h();function WR(e){return e===`streaming`?`bg-emerald-500`:e===`connecting`?`bg-amber-500`:e===`error`?`bg-rose-500`:`bg-zinc-500`}function GR(e){let t=Math.floor(e/1e3);return t<60?`${t}s`:t<3600?`${Math.floor(t/60)}m`:`${Math.floor(t/3600)}h${Math.floor(t%3600/60)}m`}function KR({className:e}){return N(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:N(`polygon`,{points:`5 3 19 12 5 21 5 3`})})}function qR({className:e}){return N(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`currentColor`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:N(`rect`,{x:`6`,y:`6`,width:`12`,height:`12`,rx:`1`})})}function JR({className:e}){return g(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[N(`path`,{d:`M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3z`}),N(`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`}),N(`line`,{x1:`12`,y1:`19`,x2:`12`,y2:`23`}),N(`line`,{x1:`8`,y1:`23`,x2:`16`,y2:`23`})]})}function YR({className:e}){return g(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`currentColor`,children:[N(`circle`,{cx:`5`,cy:`12`,r:`2`}),N(`circle`,{cx:`12`,cy:`12`,r:`2`}),N(`circle`,{cx:`19`,cy:`12`,r:`2`})]})}function XR({label:e,active:t,onClick:n}){return g(`button`,{type:`button`,onClick:n,className:`w-full flex items-center justify-between gap-3 px-3 py-1.5 text-[11px] text-foreground hover:bg-surface-hover transition-colors`,children:[N(`span`,{children:e}),N(`span`,{className:`inline-block h-3 w-5 rounded-full transition-colors ${t?`bg-primary`:`bg-foreground-subtle/30`} relative`,children:N(`span`,{className:`absolute top-0.5 h-2 w-2 rounded-full bg-white transition-all ${t?`left-2.5`:`left-0.5`}`})})]})}function ZR({className:e}){return g(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[N(`circle`,{cx:`12`,cy:`12`,r:`2`,fill:`currentColor`}),N(`path`,{d:`M16.24 7.76a6 6 0 0 1 0 8.49M7.76 16.24a6 6 0 0 1 0-8.49M19.07 4.93a10 10 0 0 1 0 14.14M4.93 19.07a10 10 0 0 1 0-14.14`})]})}function QR({className:e}){return g(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[N(`polyline`,{points:`23 4 23 10 17 10`}),N(`polyline`,{points:`1 20 1 14 7 14`}),N(`path`,{d:`M3.51 9a9 9 0 0114.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0020.49 15`})]})}function $R({className:e}){return g(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[N(`line`,{x1:`2`,y1:`2`,x2:`22`,y2:`22`}),N(`path`,{d:`M10.41 10.41a2 2 0 11-2.83-2.83`}),N(`line`,{x1:`13.5`,y1:`13.5`,x2:`6`,y2:`21`}),N(`path`,{d:`M18 12l-1.5-1.5`}),N(`path`,{d:`M21 15V5a2 2 0 00-2-2H5`}),N(`path`,{d:`M21 21H5a2 2 0 01-2-2V11`})]})}function ez({serverUrl:e,createSession:t,sendAnswer:n,handleOffer:r,getIceServers:i,addIceCandidate:a,getIceCandidates:o,closeSession:s,getSessionState:c,playbackUrl:l,playbackAuthToken:d,onExitPlayback:p,posterUrl:m,streams:h,activeStreamId:_,onStreamChange:v,deviceName:y,phase:x,pipelineMetrics:S,detections:C,defaultShowDetections:T=!0,defaultShowMotion:E=!1,streamStats:D,autoPlay:O=!1,showPlayStop:A=!1,snapshotSrc:j,snapshotLoading:M=!1,onRefreshSnapshot:F,showStreamStats:I=!1,children:L,extraOverlay:R,ptzAvailable:ee=!1,ptzShown:z=!1,ptzOverlay:B,onPtzToggle:V,intercomAvailable:te=!1,intercomShown:H=!1,onIntercomToggle:U,chromeless:ne=!1,className:re}){let ie=Ne(),ae=aI(),[oe,se]=k(O),[W,ce]=k(T),[le,ue]=k(E),[de,fe]=k(null),[pe,G]=k([]),[me,he]=k(-1),[ge,_e]=k(!1),ve=f(null);P(()=>{if(!ge)return;function e(e){ve.current&&!ve.current.contains(e.target)&&_e(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[ge]),P(()=>{he(-1)},[l]);let ye=u(e=>{G(e)},[]),be=_??de??h?.[0]?.id??``,xe=h?.find(e=>e.id===be)??h?.[0],Se=xe?.inputFps==null?null:{status:xe.status??`unknown`,inputFps:xe.inputFps,bitrateKbps:xe.bitrateKbps??0},Ce=e=>{fe(e),v?.(e),oe&&A&&(se(!1),setTimeout(()=>se(!0),50))},we=b(()=>{let e=xe?.target;if(!(!e||!t))return n=>t(e,n)},[t,xe]),Te=b(()=>{let e=xe?.target;if(!(!e||!r))return(t,n)=>r(e,t,n)},[r,xe]),Ee=b(()=>{if(r)return(e,t,n)=>r(n,t,e)},[r]),De=h,Oe=()=>se(!0),ke=()=>se(!1),Ae=S?.phase??x,je=Ae===`active`,Me=!!C,Pe=Me&&(W||le),Fe=ee&&z&&!!B,Ie=!!l,Le=Ie||(A?oe:!0);return g(`div`,{className:`overflow-hidden ${ne?``:`rounded-xl border border-border bg-surface`} ${re??``}`,children:[g(`div`,{className:`flex flex-wrap items-center justify-between gap-2 px-3 py-2 border-b border-border`,children:[g(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(D??Se)&&N(`span`,{className:`shrink-0 w-2 h-2 rounded-full ${WR((D??Se).status)}`}),y&&N(`span`,{className:`text-xs font-medium text-foreground truncate`,children:y}),!Ie&&De&&De.length>1&&g(`div`,{className:`relative`,children:[N(`select`,{"data-testid":`stream-profile-select`,value:be,onChange:e=>Ce(e.target.value),className:`appearance-none cursor-pointer rounded-md border border-border bg-surface-hover hover:bg-surface text-foreground text-[11px] font-medium pl-2 pr-6 py-1 focus:outline-none focus:ring-1 focus:ring-primary transition-colors`,children:De.map(e=>N(`option`,{value:e.id,children:e.label},e.id))}),N(`span`,{className:`pointer-events-none absolute right-1.5 top-1/2 -translate-y-1/2 text-foreground-subtle`,children:N(`svg`,{className:`h-2.5 w-2.5`,viewBox:`0 0 12 12`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:N(`polyline`,{points:`3 4.5 6 7.5 9 4.5`})})})]}),Ie&&pe.length>1&&g(`div`,{className:`relative`,children:[N(`select`,{"data-testid":`vod-quality-select`,value:me,onChange:e=>he(Number(e.target.value)),className:`appearance-none cursor-pointer rounded-md border border-border bg-surface-hover hover:bg-surface text-foreground text-[11px] font-medium pl-2 pr-6 py-1 focus:outline-none focus:ring-1 focus:ring-primary transition-colors`,children:pe.map(e=>N(`option`,{value:e.value,children:e.label},e.value))}),N(`span`,{className:`pointer-events-none absolute right-1.5 top-1/2 -translate-y-1/2 text-foreground-subtle`,children:N(`svg`,{className:`h-2.5 w-2.5`,viewBox:`0 0 12 12`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:N(`polyline`,{points:`3 4.5 6 7.5 9 4.5`})})})]})]}),g(`div`,{className:`flex items-center gap-1.5 shrink-0 ml-auto`,children:[te&&!Ie&&g(`button`,{"data-testid":`stream-intercom-toggle`,"data-intercom-shown":H?`true`:`false`,onClick:U,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors ${H?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,title:H?`Close intercom`:`Open intercom`,children:[N(JR,{className:`h-3 w-3`}),N(`span`,{className:`hidden xl:inline`,children:`Intercom`})]}),ie.map(e=>{let t=e.tone===`primary`?`bg-primary text-primary-foreground`:`bg-primary/15 text-primary`;return g(`button`,{type:`button`,"data-toolbar-button-id":e.id,"data-toolbar-button-active":e.active?`true`:`false`,onClick:e.onClick,disabled:e.disabled,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors disabled:opacity-50 ${e.active?t:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,title:e.title??e.label,children:[e.icon,N(`span`,{className:`hidden xl:inline`,children:e.label})]},e.id)}),A&&g(`button`,{"data-testid":`stream-play-toggle`,"data-stream-playing":Le?`true`:`false`,"data-vod":Ie?`true`:`false`,onClick:Ie?p:Le?ke:Oe,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors ${Ie?`bg-primary/10 text-primary hover:bg-primary/20`:Le?`bg-danger/10 text-danger hover:bg-danger/20`:`bg-primary/10 text-primary hover:bg-primary/20`}`,title:Ie?`Return to live`:Le?`Stop stream`:`Start stream`,children:[N(Ie?ZR:Le?qR:KR,{className:`h-3 w-3`}),N(`span`,{className:`hidden xl:inline`,children:Ie?`Live`:Le?`Stop`:`Play`})]}),F&&!Ie&&g(`button`,{"data-testid":`stream-snapshot-refresh`,onClick:F,disabled:M,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Force snapshot refresh`,children:[N(QR,{className:`h-3 w-3 ${M?`animate-spin`:``}`}),N(`span`,{className:`hidden xl:inline`,children:`Snapshot`})]}),(Me||ee||S||Ae||D||Se&&Se.inputFps>0)&&g(`div`,{ref:ve,className:`relative`,children:[N(`button`,{onClick:()=>_e(e=>!e),title:`More controls`,className:`inline-flex items-center justify-center rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:N(YR,{className:`h-3.5 w-3.5`})}),ge&&g(`div`,{className:`absolute right-0 top-full mt-1 z-30 min-w-[200px] rounded-lg border border-border bg-surface shadow-xl py-1.5`,children:[I&&D&&g(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle border-b border-border-subtle`,children:[g(`div`,{className:`flex justify-between gap-3`,children:[N(`span`,{children:`Input`}),g(`span`,{className:`tabular-nums text-foreground`,children:[D.inputFps.toFixed(1),` fps`]})]}),g(`div`,{className:`flex justify-between gap-3`,children:[N(`span`,{children:`Decode`}),g(`span`,{className:`tabular-nums text-foreground`,children:[D.decodeFps.toFixed(1),` fps`]})]}),g(`div`,{className:`flex justify-between gap-3`,children:[N(`span`,{children:`Uptime`}),N(`span`,{className:`tabular-nums text-foreground`,children:GR(D.uptimeMs)})]})]}),!I&&Se&&Se.inputFps>0&&g(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle border-b border-border-subtle`,children:[g(`div`,{className:`flex justify-between gap-3`,children:[N(`span`,{children:`Input`}),g(`span`,{className:`tabular-nums text-foreground`,children:[Se.inputFps.toFixed(1),` fps`]})]}),Se.bitrateKbps>0&&g(`div`,{className:`flex justify-between gap-3`,children:[N(`span`,{children:`Bitrate`}),g(`span`,{className:`tabular-nums text-foreground`,children:[Se.bitrateKbps,` kbps`]})]})]}),(S||Me&&Ae)&&g(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle border-b border-border-subtle`,children:[g(`div`,{className:`flex justify-between gap-3 items-center`,children:[N(`span`,{children:`Phase`}),g(`span`,{className:`flex items-center gap-1 font-semibold uppercase tracking-wider ${je?`text-red-400`:`text-emerald-400`}`,children:[N(`span`,{className:`w-1.5 h-1.5 rounded-full ${je?`bg-red-500 animate-pulse`:`bg-emerald-500`}`}),je?`Active`:`Watching`]})]}),S&&S.detectionFps>0&&g(`div`,{className:`flex justify-between gap-3`,children:[N(`span`,{children:`Detection`}),g(`span`,{className:`tabular-nums text-foreground`,children:[S.detectionFps.toFixed(1),` det/s`]})]}),S&&S.avgInferenceMs>0&&g(`div`,{className:`flex justify-between gap-3`,children:[N(`span`,{children:`Inference`}),g(`span`,{className:`tabular-nums text-foreground`,children:[S.avgInferenceMs.toFixed(0),` ms`]})]})]}),Me&&g(w,{children:[N(XR,{label:`Show detections`,active:W,onClick:()=>ce(e=>!e)}),N(XR,{label:`Show motion`,active:le,onClick:()=>ue(e=>!e)})]}),ee&&N(XR,{label:`PTZ controls`,active:z,onClick:()=>{V?.(),_e(!1)}})]})]})]})]}),l?g(`div`,{className:`aspect-video relative`,children:[N(UR,{url:l,authToken:d??null,onQualityOptions:ye,selectedLevel:me,...m?{posterUrl:m}:{}}),R||Fe?g(w,{children:[R,Fe&&B]}):null]}):Le&&e?N(`div`,{className:`aspect-video relative`,children:N(LR,{serverUrl:e,streamKey:be,autoPlay:!0,className:`w-full h-full`,createSession:we,sendAnswer:n,handleOffer:Te,reoffer:Ee,getSessionState:c,getIceServers:i,addIceCandidate:a,getIceCandidates:o,closeSession:s,...ae.bindControlChannel?{onControlChannel:ae.bindControlChannel}:{},...m?{posterUrl:m}:{},overlay:Pe||R||Fe?g(w,{children:[Pe&&N(ER,{detections:C,showPhaseIndicator:!1,showMotionZones:le,showMotionRaw:le,showDetections:W}),R,Fe&&B]}):void 0},be)}):N(tz,{src:j??null,isLoading:M,onPlay:Oe,onRetry:F,extraOverlay:R||Fe?g(w,{children:[R,Fe&&B]}):null,suppressPlayHover:!!R||Fe}),L]})}function tz({src:e,isLoading:t,onPlay:n,onRetry:r,extraOverlay:i,suppressPlayHover:a=!1}){return e?g(`div`,{className:`relative w-full aspect-video bg-black/90 flex items-center justify-center`,children:[N(`img`,{src:e,alt:`Camera snapshot`,className:`w-full h-full object-contain`}),!a&&N(`button`,{onClick:n,className:`absolute inset-0 flex items-center justify-center bg-black/30 opacity-0 hover:opacity-100 transition-opacity cursor-pointer`,children:N(`div`,{className:`h-14 w-14 rounded-full bg-white/20 backdrop-blur-sm flex items-center justify-center`,children:N(KR,{className:`h-7 w-7 text-white ml-0.5`})})}),i]}):t?N(`div`,{className:`relative w-full aspect-video bg-black/90 flex items-center justify-center`,children:N(`div`,{className:`h-8 w-8 border-2 border-white/20 border-t-white/60 rounded-full animate-spin`})}):N(`div`,{className:`relative w-full aspect-video bg-black/90 flex items-center justify-center`,children:g(`div`,{className:`flex flex-col items-center gap-2 text-white/40`,children:[N($R,{className:`h-8 w-8`}),N(`span`,{className:`text-xs`,children:`No snapshot available`}),g(`div`,{className:`flex items-center gap-2 mt-1`,children:[r&&g(`button`,{onClick:r,className:`inline-flex items-center gap-1.5 rounded-md border border-white/20 px-3 py-1.5 text-xs font-medium text-white/60 hover:text-white hover:border-white/40 transition-colors`,children:[N(QR,{className:`h-3 w-3`}),`Retry`]}),g(`button`,{onClick:n,className:`inline-flex items-center gap-1.5 rounded-md bg-primary/80 px-3 py-1.5 text-xs font-medium text-white hover:bg-primary transition-colors`,children:[N(KR,{className:`h-3 w-3`}),`Play Live`]})]})]})})}h();var nz={value:`auto`,label:`Auto (best available)`};function rz(e){return e.charAt(0).toUpperCase()+e.slice(1)}function iz({deviceId:e,value:t,onChange:n,disabled:r,label:i,className:a}){let o=y(),s=Uf({deviceId:e},{refetchOnWindowFocus:!1}),[c,l]=k([nz]);P(()=>{if(!s.data)return;let t=`${e}/`,n=[nz];for(let e of s.data){if(!e.enabled)continue;let r=e.brokerId.startsWith(t)?e.brokerId.slice(t.length):e.brokerId;n.push({value:r,label:rz(r)})}l(n)},[s.data,e]);let u=i??`Preferred stream`,d=s.isLoading?`Loading available streams…`:s.isError?`Could not load streams — only Auto available.`:c.length===1?`No enabled streams found — only Auto available.`:null;return g(`div`,{className:a,children:[N(`label`,{id:o,className:`text-xs font-medium text-foreground-muted block mb-1`,children:u}),N(Ds,{"aria-labelledby":o,options:c,value:t,disabled:r,onChange:e=>n(e.target.value)}),d!==null&&N(`p`,{className:`text-foreground-subtle text-[10px] mt-1`,children:d})]})}h();var az=2e3;function oz({value:e,label:t,className:n,disabled:r}){let[i,a]=k(!1),o=u(()=>{e&&navigator.clipboard.writeText(e).then(()=>{a(!0),setTimeout(()=>a(!1),az)})},[e]);return g(ps,{size:`sm`,variant:`ghost`,type:`button`,disabled:r||e.length===0,onClick:o,className:X(n),"aria-label":i?`Copied`:`Copy ${t??`value`}`,children:[i?N(Ci,{className:`h-3.5 w-3.5 text-success`}):N(Wi,{className:`h-3.5 w-3.5`}),t?N(`span`,{className:`ml-1`,children:i?`Copied`:t}):null]})}h();var sz=R(ue),cz=ee({id:F(),stableId:I(),addonId:I(),type:I(),name:I(),online:L(),disabled:L(),parentDeviceId:F().nullable(),role:I().nullable().optional(),features:R(I()).optional(),isCamera:L().optional(),sourceInfo:me.optional()}),lz=R(I()),uz=1e4;function dz(e){return e===`linked`?`success`:e===`error`?`danger`:`warning`}function fz(e){return e===`linked`?`Linked`:e===`unlinked`?`Unlinked`:e===`error`?`Error`:e}function pz({field:e}){let[t,n]=k(!1),r=e.secret===!0,i=r&&!t?`•`.repeat(Math.min(e.value.length,24)):e.value;return g(`div`,{className:`flex items-center gap-2 py-1.5`,children:[N(`span`,{className:`text-[11px] text-foreground-subtle w-32 shrink-0`,children:e.label}),N(`span`,{className:`flex-1 min-w-0 truncate font-mono text-xs text-foreground`,children:i||`—`}),r&&N(ps,{size:`sm`,variant:`ghost`,type:`button`,"aria-label":t?`Hide value`:`Reveal value`,onClick:()=>n(e=>!e),children:N(t?ta:na,{className:`h-3.5 w-3.5`})}),N(oz,{value:e.value,label:e.label})]})}function mz({setup:e}){let t=e.fields??[];return g(`div`,{className:`border-b border-border bg-surface-hover/10`,children:[g(`div`,{className:`flex items-center gap-2 px-4 py-2 border-b border-border`,children:[N(ro,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}),N(`span`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Setup`})]}),g(`div`,{className:`flex flex-col gap-3 p-4 sm:flex-row sm:items-start`,children:[e.qr&&N(`div`,{className:`shrink-0`,children:N(CL,{value:e.qr,alt:`Pairing QR code`})}),g(`div`,{className:`flex-1 min-w-0`,children:[e.note&&N(`p`,{className:`text-xs text-foreground-muted whitespace-pre-line mb-2`,children:e.note}),t.length>0&&N(`div`,{className:`divide-y divide-border-subtle`,children:t.map(e=>N(pz,{field:e},e.label))})]})]})]})}function hz({addonId:e,deviceId:t,exposed:n,busy:r,onExpose:i,onUnexpose:a}){return N(ps,{size:`sm`,variant:n?`ghost`:`primary`,disabled:r,onClick:e=>{e.stopPropagation(),!r&&(n?a(t):i(t))},title:n?`Stop exposing to "${e}"`:`Expose to "${e}"`,children:n?g(w,{children:[N(Go,{className:`mr-1 h-3.5 w-3.5`}),`Exposed`]}):g(w,{children:[N(go,{className:`mr-1 h-3.5 w-3.5`}),`Expose`]})})}function gz({addonId:e,trpc:t,onOpenDevice:n}){let r=O(),i=Yp({nodeId:`hub`,addonId:e},{refetchInterval:uz,retry:!1}),a=Zp({nodeId:`hub`,addonId:e},{refetchInterval:uz,retry:!1}),o=Xp({nodeId:`hub`,addonId:e},{retry:!1}),s=Am({},{refetchInterval:5e3}),c=u(()=>{r.invalidateQueries({queryKey:[[`deviceExport`]]})},[r]),l=Qp({onSuccess:c}),d=$p({onSuccess:c}),f=b(()=>{let e=ae.safeParse(i.data);return e.success?e.data:null},[i.data]),p=b(()=>{let e=sz.safeParse(a.data);return e.success?e.data:[]},[a.data]),m=b(()=>new Set(p.map(e=>e.deviceId)),[p]),h=b(()=>{let e=lz.safeParse(o.data);return new Set(e.success?e.data:[])},[o.data]),_=b(()=>[...h].toSorted(),[h]),v=b(()=>_.map(e=>{let t=Ak(e);return{id:e,label:t.label,icon:t.icon}}),[_]),y=b(()=>{let e=s.data;if(!Array.isArray(e))return[];let t=[];for(let n of e){let e=cz.safeParse(n);e.success&&h.has(e.data.type)&&t.push(e.data)}return t},[s.data,h]),x=f?.linkState??`unlinked`,S=i.isLoading||a.isLoading||o.isLoading||s.isLoading,C=f?.exposedDeviceCount??m.size,w=l.isPending||d.isPending,T=u(t=>{l.mutate({deviceId:t,nodeId:`hub`,addonId:e})},[l,e]),E=u(t=>{d.mutate({deviceId:t,nodeId:`hub`,addonId:e})},[d,e]),D=u(t=>{let n=String(t.id);return N(hz,{addonId:e,deviceId:n,exposed:m.has(n),busy:w,onExpose:T,onUnexpose:E})},[e,m,w,T,E]),k=u(e=>n?.(String(e)),[n]),A=_.length>0;return g(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[g(`div`,{className:`flex items-center justify-between gap-3 px-4 py-2.5 border-b border-border bg-surface-hover/20`,children:[g(`div`,{className:`flex items-center gap-2 min-w-0`,children:[N(go,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}),N(`span`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Exported devices`}),N(_s,{variant:dz(x),children:fz(x)}),g(`span`,{className:`text-[11px] text-foreground-subtle`,children:[C,` exposed`]})]}),S&&N(Ea,{className:`h-3.5 w-3.5 animate-spin text-foreground-subtle`})]}),f?.error&&N(`div`,{className:`px-4 py-3 border-b border-border`,children:N(xl,{message:f.error})}),f?.setup&&N(mz,{setup:f.setup}),N(`div`,{className:`p-3`,children:A&&y.length>0?N(Qj,{devices:y,trpc:t,defaultView:`table`,filters:{typeOptions:v},urlScope:`nested`,lsKey:`device-export:${e}`,onNavigate:n?k:void 0,renderRowAction:D}):N(yl,{icon:go,title:`No exportable devices`,description:A?`No devices of the supported kinds (${_.join(`, `)}) are available to expose to "${e}".`:`"${e}" reports no exportable device kinds yet.`})})]})}h();function _z({samples:e,sampleRate:t=16e3,height:n=96,className:r=``,color:i=`#3b82f6`,bgColor:a=`transparent`}){let o=f(null),s=f(null),c=u(()=>{let t=o.current,r=s.current;if(!t||!r||!e||e.length===0)return;let c=r.clientWidth;if(c===0)return;let l=window.devicePixelRatio||1;t.width=c*l,t.height=n*l,t.style.width=`${c}px`,t.style.height=`${n}px`;let u=t.getContext(`2d`);if(!u)return;u.scale(l,l),a===`transparent`?u.clearRect(0,0,c,n):(u.fillStyle=a,u.fillRect(0,0,c,n));let d=e.length/c,f=n/2;u.fillStyle=i,u.globalAlpha=.7;for(let t=0;t<c;t++){let n=Math.floor(t*d),r=Math.min(Math.floor((t+1)*d),e.length),i=0,a=0;for(let t=n;t<r;t++){let n=e[t];n<i&&(i=n),n>a&&(a=n)}let o=f-a*f,s=f-i*f,c=Math.max(1,s-o);u.fillRect(t,o,1,c)}u.globalAlpha=1,u.strokeStyle=i,u.globalAlpha=.2,u.lineWidth=1,u.beginPath(),u.moveTo(0,f),u.lineTo(c,f),u.stroke(),u.globalAlpha=1},[e,n,i,a]);P(()=>{c()},[c]),P(()=>{let e=new ResizeObserver(()=>c()),t=s.current;return t&&e.observe(t),()=>e.disconnect()},[c]);let l=((e&&t?Math.round(e.length/t*1e3):0)/1e3).toFixed(1);return g(`div`,{ref:s,className:`relative ${r}`,children:[N(`canvas`,{ref:o,className:`w-full rounded-md`}),e&&e.length>0&&g(`div`,{className:`absolute bottom-1 right-2 text-[10px] text-foreground-subtle/60 font-mono`,children:[l,`s · `,t/1e3,`kHz · `,e.length.toLocaleString(),` samples`]})]})}h();function vz({currentDbfs:e,durationSec:t=30,maxSamples:n=120,height:r=64,className:i=``,color:a=`#10b981`,clipColor:o=`#ef4444`,clipThreshold:s=-6,minDbfs:c=-96}){let l=f(null),d=f(null),[p,m]=k([]);P(()=>{e!==null&&m(t=>{let r=[...t,{dbfs:e,timestamp:Date.now()}];return r.length>n?r.slice(-n):r})},[e,n]);let h=u(()=>{let e=l.current,n=d.current;if(!e||!n)return;let i=n.clientWidth;if(i===0)return;let u=window.devicePixelRatio||1;e.width=i*u,e.height=r*u,e.style.width=`${i}px`,e.style.height=`${r}px`;let f=e.getContext(`2d`);if(!f||(f.scale(u,u),f.clearRect(0,0,i,r),p.length===0))return;let m=p[p.length-1].timestamp,h=t*1e3,g=m-h,_=p.filter(e=>e.timestamp>=g);if(_.length===0)return;let v=Math.max(1,Math.floor(i/(t*2))),y=Math.abs(c);for(let e of _){let t=e.timestamp-g,n=Math.floor(t/h*i),l=(Math.max(c,Math.min(0,e.dbfs))-c)/y,u=Math.max(1,l*r);f.fillStyle=e.dbfs>=s?o:a,f.globalAlpha=.8,f.fillRect(n,r-u,v,u)}f.globalAlpha=1;let b=r-(s-c)/y*r;f.strokeStyle=o,f.globalAlpha=.25,f.lineWidth=1,f.setLineDash([4,4]),f.beginPath(),f.moveTo(0,b),f.lineTo(i,b),f.stroke(),f.setLineDash([]),f.globalAlpha=1},[p,t,r,a,o,s,c]);P(()=>{h()},[h]),P(()=>{let e=new ResizeObserver(()=>h()),t=d.current;return t&&e.observe(t),()=>e.disconnect()},[h]);let _=p.length>0?p[p.length-1].dbfs:null;return g(`div`,{ref:d,className:`relative ${i}`,children:[N(`canvas`,{ref:l,className:`w-full rounded-md`}),g(`div`,{className:`absolute top-1 left-2 text-[9px] text-foreground-subtle/50 font-mono`,children:[t,`s`]}),_!==null&&g(`div`,{className:`absolute bottom-1 right-2 text-[9px] text-foreground-subtle/50 font-mono`,children:[_.toFixed(1),` dBFS · `,p.length,` samples`]})]})}function yz(e){return e>=.8?`bg-emerald-500`:e>=.5?`bg-amber-500`:e>=.3?`bg-orange-500`:`bg-zinc-500`}function bz(e){return e>=.8?`text-emerald-400`:e>=.5?`text-amber-400`:e>=.3?`text-orange-400`:`text-zinc-400`}function xz({classifications:e,processing:t=!1,inferenceMs:n,maxItems:r=10,className:i=``}){let a=e.slice(0,r),o=a.length>0?a[0].score:1;return t?N(`div`,{className:`rounded-xl border border-border bg-surface p-4 text-center ${i}`,children:N(`div`,{className:`text-sm text-foreground-subtle animate-pulse`,children:`Classifying audio...`})}):a.length===0?N(`div`,{className:`rounded-xl border border-border bg-surface p-4 text-center ${i}`,children:N(`div`,{className:`text-xs text-foreground-subtle`,children:`No classifications yet`})}):g(`div`,{className:`rounded-xl border border-border bg-surface overflow-hidden ${i}`,children:[g(`div`,{className:`px-3 py-2 border-b border-border flex items-center justify-between`,children:[N(`h3`,{className:`text-xs font-medium text-foreground`,children:`Audio Classifications`}),g(`div`,{className:`flex items-center gap-3 text-[10px] text-foreground-subtle`,children:[a.length<e.length&&g(`span`,{children:[`showing `,a.length,` of `,e.length]}),n!==void 0&&g(`span`,{className:`font-mono`,children:[n.toFixed(1),`ms`]})]})]}),N(`div`,{className:`divide-y divide-border/50`,children:a.map((e,t)=>{let n=o>0?e.score/o*100:0;return g(`div`,{className:`px-3 py-1.5 flex items-center gap-3 hover:bg-surface-hover/30`,children:[N(`span`,{className:`text-[10px] text-foreground-subtle w-5 text-right font-mono`,children:t+1}),N(`span`,{className:`text-xs font-medium text-foreground min-w-[120px]`,children:e.className}),N(`div`,{className:`flex-1 h-2 rounded-full bg-zinc-800 overflow-hidden`,children:N(`div`,{className:`h-full rounded-full transition-all duration-300 ${yz(e.score)}`,style:{width:`${n}%`}})}),g(`span`,{className:`text-xs font-mono font-semibold w-14 text-right ${bz(e.score)}`,children:[(e.score*100).toFixed(1),`%`]})]},`${e.className}-${t}`)})})]})}h();function Sz({data:e,label:t=`Response`,className:n=``}){let[r,i]=k(!1);if(!e)return null;let a=JSON.stringify(e,null,2);return g(`div`,{className:`rounded-xl border border-border bg-surface overflow-hidden ${n}`,children:[g(`div`,{className:`px-3 py-2 border-b border-border flex items-center justify-between cursor-pointer select-none hover:bg-surface-hover/30`,onClick:()=>i(e=>!e),children:[g(`div`,{className:`flex items-center gap-2`,children:[N(`span`,{className:`text-[10px] text-foreground-subtle`,children:r?`▼`:`▶`}),N(`h3`,{className:`text-xs font-medium text-foreground`,children:t})]}),N(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:a.length>1e3?`${(a.length/1024).toFixed(1)} KB`:`${a.length} bytes`})]}),r&&N(`div`,{className:`max-h-80 overflow-y-auto overflow-x-auto`,children:N(`pre`,{className:`p-3 text-[10px] leading-4 font-mono text-foreground-subtle whitespace-pre`,children:a})})]})}var Cz={Activity:Qr,Eye:na,AlertTriangle:Uo,PauseCircle:Mi,PowerOff:to};function wz({phase:e,...t}){let n=Cz[Ar(e).icon];return N(n,{...t})}h();function Tz(e){let[t,n]=k([]),r=u(t=>{n(n=>{let r=[...n,t];return r.length>e?r.slice(-e):r})},[e]),i=u(()=>{n([])},[]);return b(()=>({entries:t,append:r,reset:i}),[t,r,i])}function Ez(e,t=40){return e.scrollHeight-e.scrollTop-e.clientHeight<=t}h();function Dz(e){if(e===null)return`null`;if(e===void 0)return`undefined`;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{return JSON.stringify(e)}catch{return String(e)}}var Oz={error:{icon:Oi,color:`text-red-400`},warn:{icon:Uo,color:`text-amber-400`},info:{icon:ba,color:`text-blue-400`},debug:{icon:bi,color:`text-gray-500`}},kz={debug:0,info:1,warn:2,error:3},Az=[`debug`,`info`,`warn`,`error`],jz=500;function Mz(e,t){return t?(kz[e]??0)>=(kz[t]??0):!0}function Nz({agentId:e,addonId:t,deviceId:n,containerDeviceId:r,integrationId:i,requestId:a,level:o,maxHeight:s=`max-h-96`,showScope:c=!1,showDeviceChip:l=!1,showFilters:d=!0,limit:p=100,liveBuffer:m,onClose:h,className:_}){let[y,x]=k(``),[S,C]=k(``),[w,T]=k(o??`info`),E=e,D=t??(y||void 0),O=n??(S?Number(S):void 0),A=i,j=a,M=b(()=>{let e={};return E&&(e.agentId=E),D&&(e.addonId=D),r!==void 0&&Number.isFinite(r)?e.containerDeviceId=r:O!==void 0&&Number.isFinite(O)&&(e.deviceId=O),A&&(e.integrationId=A),j&&(e.requestId=j),Object.keys(e).length>0?e:void 0},[E,D,O,r,A,j]),F=Tz(jz),I=m??F,L=I.entries,[R,ee]=k(0),[z,B]=k(!0),V=f(!1),[te,H]=k(!1),[U,ne]=k(!1),[re,ie]=k(new Set),[ae,oe]=k(``),se=f(null),W=`${E??``}:${D??``}:${String(O??``)}:${String(r??``)}:${A??``}:${j??``}`,ce=f(W);P(()=>{ce.current!==W&&(ce.current=W,I.reset(),ee(0),ie(new Set),H(!1))},[W,I]);let{data:le,isLoading:ue}=Z.logs.query.useQuery({...M?{tags:M}:{},limit:p},{staleTime:3e4});Z.logs.subscribe.useSubscription(M?{tags:M}:{},{onData:e=>{I.append(e)}});let de=b(()=>{let e=(le??[]).map(e=>({timestamp:e.timestamp,level:e.level,message:e.message,scope:e.scope,tags:e.tags,meta:e.meta})),t=new Map;for(let n of e)t.set(`${n.timestamp}|${n.level}|${n.scope??``}|${n.message}`,n);for(let e of L)t.set(`${e.timestamp}|${e.level}|${e.scope??``}|${e.message}`,e);let n=[...t.values()].toSorted((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime()),r=(R>0?n.filter(e=>new Date(e.timestamp).getTime()>R):n).filter(e=>Mz(e.level,w)),i=ae.trim().toLowerCase();return i?r.filter(e=>{if(e.message.toLowerCase().includes(i)||e.scope&&e.scope.toLowerCase().includes(i))return!0;if(e.tags){for(let t of Object.values(e.tags))if(t!==void 0&&String(t).toLowerCase().includes(i))return!0}if(e.meta){for(let t of Object.values(e.meta))if(t!=null&&Dz(t).toLowerCase().includes(i))return!0}return!1}):r},[le,L,w,R,ae]),fe=u(e=>{let t=se.current;t&&(V.current=!0,t.scrollTo({top:t.scrollHeight,...e?{behavior:e}:{}}))},[]),[pe,G]=k(!1),me=f(de.length);v(()=>{let e=de.length>me.current;me.current=de.length,e&&(z?fe():G(!0))},[de.length,z,fe]),P(()=>{z&&pe&&G(!1)},[z,pe]);let he=u(()=>{B(!0),fe(`smooth`)},[fe]),ge=u(()=>{if(V.current){V.current=!1;return}let e=se.current;if(!e)return;let t=Ez(e,40);B(e=>e===t?e:t)},[]),_e=b(()=>de.filter(e=>e.tags&&Object.keys(e.tags).length>0||e.meta&&Object.keys(e.meta).length>0).map(e=>`${e.timestamp}|${e.level}|${e.scope??``}|${e.message}`),[de]),ve=u(()=>{H(e=>(e&&ie(new Set),!e))},[]),ye=u(()=>{let e=de.map(e=>{let t=new Date(e.timestamp).toLocaleTimeString(),n=e.tags?` `+Object.entries(e.tags).filter(([,e])=>e).map(([e,t])=>`${e}=${t}`).join(` `):``;return`${t} [${e.level.toUpperCase()}]${e.scope?` [${e.scope}]`:``}${n} ${e.message}`});navigator.clipboard.writeText(e.join(`
66
66
  `)).then(()=>{ne(!0),setTimeout(()=>ne(!1),1500)})},[de]),be=Z.logs.clear.useMutation(),xe=u(()=>{ee(Date.now()),I.reset(),be.mutate(M?{tags:M}:{})},[I,be,M]),Se=u(e=>{ie(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),[Ce,we]=k(null),Te=u((e,t)=>{let n=new Date(e.timestamp).toISOString(),r=e.tags?` `+Object.entries(e.tags).filter(([,e])=>e).map(([e,t])=>`${e}=${t}`).join(` `):``,i=e.meta&&Object.keys(e.meta).length>0?` meta=${JSON.stringify(e.meta)}`:``,a=`${n} [${e.level.toUpperCase()}]${e.scope?` [${e.scope}]`:``}${r} ${e.message}${i}`;navigator.clipboard.writeText(a).then(()=>{we(t),setTimeout(()=>we(e=>e===t?null:e),1200)})},[]),Ee=u(e=>`${e.timestamp}|${e.level}|${e.scope??``}|${e.message}`,[]);return g(`div`,{className:X(`h-full min-h-0 flex flex-col`,_),onClick:e=>e.stopPropagation(),children:[g(`div`,{className:`flex items-center justify-between px-3 py-1.5 bg-surface-hover/30 gap-2 shrink-0`,children:[g(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[N(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`Logs`}),E&&N(Iz,{label:`agent`,value:E}),D&&N(Iz,{label:`addon`,value:D}),O!==void 0&&N(Iz,{label:`device`,value:`#${O}`}),N(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:Az.map((e,t)=>g(`button`,{type:`button`,onClick:()=>T(e),className:X(`px-1.5 py-0.5 capitalize transition-colors`,w===e?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`,t>0&&`border-l border-border`),children:[e,`+`]},e))}),N(Rz,{icon:ti,label:z?`Following`:`Paused`,active:z,onClick:()=>{z?B(!1):he()}}),N(Rz,{icon:te?Ei:Di,label:te?`Collapse`:`Expand`,active:te,onClick:ve,disabled:_e.length===0}),N(Rz,{icon:Wi,label:U?`Copied!`:`Copy`,onClick:ye,disabled:de.length===0}),N(Rz,{icon:Bo,label:`Clear`,onClick:xe}),g(`div`,{className:`relative`,children:[N(`input`,{type:`text`,value:ae,onChange:e=>oe(e.target.value),placeholder:`Search…`,className:`w-32 pl-1.5 pr-5 py-0.5 rounded border border-border bg-background text-foreground text-[10px] focus:outline-none focus:border-primary/50`}),ae&&N(`button`,{type:`button`,onClick:()=>oe(``),className:`absolute right-1 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground`,title:`Clear search`,children:N(rs,{className:`h-2.5 w-2.5`})})]}),L.length>0&&g(`span`,{className:`text-[9px] text-emerald-400 font-medium`,children:[`+`,L.length,` live`]})]}),h&&N(`button`,{type:`button`,onClick:h,className:`text-foreground-subtle hover:text-foreground`,children:N(rs,{className:`h-3.5 w-3.5`})})]}),d&&(!t||!n)&&g(`div`,{className:`flex items-center gap-2 px-3 py-1 border-b border-border/50 bg-surface/50 text-[10px]`,children:[!t&&g(`label`,{className:`flex items-center gap-1`,children:[N(`span`,{className:`text-foreground-subtle`,children:`Addon:`}),N(`input`,{type:`text`,value:y,onChange:e=>x(e.target.value),placeholder:`all`,className:`w-28 px-1.5 py-0.5 rounded border border-border bg-background text-foreground text-[10px] focus:outline-none focus:border-primary/50`})]}),!n&&g(`label`,{className:`flex items-center gap-1`,children:[N(`span`,{className:`text-foreground-subtle`,children:`Device:`}),N(`input`,{type:`text`,inputMode:`numeric`,value:S,onChange:e=>C(e.target.value),placeholder:`all`,className:`w-16 px-1.5 py-0.5 rounded border border-border bg-background text-foreground text-[10px] focus:outline-none focus:border-primary/50`})]})]}),g(`div`,{className:`relative flex-1 min-h-0 flex flex-col`,children:[!z&&pe&&g(`button`,{type:`button`,onClick:he,className:`absolute bottom-2 left-1/2 -translate-x-1/2 z-10 inline-flex items-center gap-1 px-2 py-1 rounded-full border border-primary/40 bg-primary/15 text-primary text-[10px] font-medium shadow-md backdrop-blur-sm hover:bg-primary/25 transition-colors`,title:`Jump to the newest log line and resume following`,children:[N(ti,{className:`h-3 w-3`}),`Jump to latest`]}),g(`div`,{ref:se,onScroll:ge,className:X(`flex-1 min-h-0 overflow-auto font-mono text-[10px]`,s),children:[ue&&g(`div`,{className:`flex items-center justify-center gap-2 py-6 text-foreground-subtle`,children:[N(Ea,{className:`h-3.5 w-3.5 animate-spin`}),`Loading logs...`]}),!ue&&de.length===0&&N(`div`,{className:`py-4 text-center text-foreground-subtle`,children:`No logs found`}),de.length>0&&N(`table`,{className:`w-full`,children:N(`tbody`,{children:de.map(e=>{let t=Oz[e.level]??Oz.info,n=t.icon,r=Ee(e),i=te||re.has(r),a=e.tags&&Object.keys(e.tags).length>0,o=e.meta&&Object.keys(e.meta).length>0,s=a||o;return g(`tr`,{className:X(`hover:bg-surface-hover/30 border-b border-border/30`,s&&`cursor-pointer`),onClick:s?()=>Se(r):void 0,children:[N(`td`,{className:`px-2 py-1 text-foreground-subtle whitespace-nowrap align-top w-[70px]`,children:new Date(e.timestamp).toLocaleTimeString()}),N(`td`,{className:X(`px-1 py-1 align-top w-5`,t.color),children:N(n,{className:`h-3 w-3`})}),c&&N(`td`,{className:`px-2 py-1 text-foreground-subtle align-top truncate max-w-[120px]`,title:e.scope,children:e.scope?.replace(/^addon:/,``)??``}),N(`td`,{className:`px-2 py-1 text-foreground break-all`,children:g(`div`,{className:`flex items-start gap-1`,children:[s&&N(i?Re:Ue,{className:`h-3 w-3 text-foreground-subtle shrink-0 mt-0.5`}),g(`div`,{className:`flex-1 min-w-0`,children:[l&&e.tags?.deviceId!==void 0&&N(Fz,{deviceId:e.tags.deviceId,deviceName:e.tags.deviceName}),e.message,i&&s&&g(`div`,{className:`mt-0.5 pl-3 text-[9px] leading-snug`,children:[o&&Object.entries(e.meta).filter(([,e])=>e!==void 0&&e!==``).map(([e,t])=>g(`div`,{className:`break-all`,children:[N(`span`,{className:`text-amber-400/80`,children:e}),N(`span`,{className:`text-foreground-subtle`,children:`=`}),N(`span`,{className:`text-foreground`,children:Dz(t)})]},`m-${e}`)),a&&Object.entries(e.tags).filter(([,e])=>e!==void 0).map(([e,t])=>g(`div`,{className:`break-all`,children:[N(`span`,{className:`text-primary/70`,children:e}),N(`span`,{className:`text-foreground-subtle`,children:`=`}),N(`span`,{className:`text-foreground`,children:t})]},`t-${e}`))]})]})]})}),N(`td`,{className:`px-1 py-1 align-top w-5`,children:N(Lz,{copied:Ce===r,onCopy:()=>Te(e,r)})})]},r)})})})]})]})]})}function Pz({position:e=`bottom`,className:t,...n}){return N(`div`,{className:X(e===`bottom`?`absolute bottom-0 left-0 right-0 z-10 border-t border-border bg-surface/95 backdrop-blur-sm`:`absolute inset-x-2 bottom-2 z-10 rounded-lg border border-border bg-surface/95 backdrop-blur-sm shadow-xl`,t),children:N(Nz,{maxHeight:`max-h-48`,...n})})}function Fz({deviceId:e,deviceName:t}){let n=t?`${t} #${e}`:`#${e}`;return N(`span`,{className:`inline-block align-middle mr-1 px-1 py-0 rounded bg-primary/10 text-primary text-[9px] font-medium whitespace-nowrap`,title:`device ${e}`,children:n})}function Iz({label:e,value:t}){return g(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium`,children:[e,`: `,t]})}function Lz({copied:e,onCopy:t}){return N(`button`,{type:`button`,title:`Copy this row`,onClick:e=>{e.stopPropagation(),t()},className:X(`rounded p-0.5 transition-colors`,e?`text-emerald-400`:`text-foreground-subtle/60 hover:text-foreground hover:bg-surface-hover`),children:N(e?Ci:Wi,{className:`h-3 w-3`})})}function Rz({icon:e,label:t,onClick:n,disabled:r,active:i}){return g(`button`,{type:`button`,onClick:n,disabled:r,className:X(`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors`,i?`border-amber-500/30 bg-amber-500/10 text-amber-400`:`border-border text-foreground-subtle hover:text-foreground`,r&&`opacity-40 cursor-not-allowed`),children:[N(e,{className:`h-2.5 w-2.5`}),t]})}h();function zz(e,t,n,r){if(r!==void 0&&(e.source.deviceId??(e.source.type===`device`&&typeof e.source.id==`number`?e.source.id:void 0))!==r||n!==void 0&&(e.source.addonId??(e.source.type===`addon`&&typeof e.source.id==`string`?e.source.id:void 0))!==n)return!1;if(t!==void 0){let n=e.source.nodeId;if(!n||n!==t&&!n.startsWith(`${t}/`))return!1}return!0}var Bz={[H.AddonStarted]:{icon:Qa,color:`bg-emerald-500/15 text-emerald-400 border-emerald-500/30`,label:`Started`},[H.AddonInstalled]:{icon:Xi,color:`bg-emerald-500/15 text-emerald-400 border-emerald-500/30`,label:`Installed`},[H.AddonRestarted]:{icon:oo,color:`bg-blue-500/15 text-blue-400 border-blue-500/30`,label:`Restarted`},[H.AddonUpdated]:{icon:Ko,color:`bg-blue-500/15 text-blue-400 border-blue-500/30`,label:`Updated`},[H.AddonStopped]:{icon:Ao,color:`bg-foreground-subtle/10 text-foreground-subtle border-border`,label:`Stopped`},[H.AddonUninstalled]:{icon:Bo,color:`bg-foreground-subtle/10 text-foreground-subtle border-border`,label:`Uninstalled`},[H.AddonCrashed]:{icon:Oi,color:`bg-red-500/15 text-red-400 border-red-500/30`,label:`Crashed`},[H.AddonError]:{icon:Uo,color:`bg-red-500/15 text-red-400 border-red-500/30`,label:`Error`},[H.DetectionPhaseTransition]:{icon:Qr,color:`bg-violet-500/15 text-violet-400 border-violet-500/30`,label:`Phase`},[H.DetectionResult]:{icon:uo,color:`bg-purple-500/15 text-purple-400 border-purple-500/30`,label:`Detection`},[H.DetectionEvent]:{icon:na,color:`bg-blue-500/15 text-blue-400 border-blue-500/30`,label:`Event`},[H.DetectionCameraNative]:{icon:Io,color:`bg-cyan-500/15 text-cyan-400 border-cyan-500/30`,label:`Camera AI`},[H.ProviderMotion]:{icon:is,color:`bg-orange-500/15 text-orange-400 border-orange-500/30`,label:`Motion`},[H.MotionOnMotionChanged]:{icon:is,color:`bg-orange-500/15 text-orange-400 border-orange-500/30`,label:`Motion`},[H.MotionAnalysis]:{icon:Qr,color:`bg-orange-500/10 text-orange-300 border-orange-500/20`,label:`Motion analysis`},[H.MotionZonesRaw]:{icon:Qr,color:`bg-orange-500/10 text-orange-300 border-orange-500/20`,label:`Motion zones`},[H.ProviderDetection]:{icon:Io,color:`bg-cyan-500/15 text-cyan-400 border-cyan-500/30`,label:`Provider Det`},[H.PipelineAudioInferenceResult]:{icon:Ia,color:`bg-pink-500/15 text-pink-400 border-pink-500/30`,label:`Audio`},[H.AgentOnline]:{icon:Qa,color:`bg-emerald-500/15 text-emerald-400 border-emerald-500/30`,label:`Agent Online`},[H.AgentOffline]:{icon:Ao,color:`bg-red-500/15 text-red-400 border-red-500/30`,label:`Agent Offline`},[H.DeviceRegistered]:{icon:Xi,color:`bg-emerald-500/15 text-emerald-400 border-emerald-500/30`,label:`Registered`},[H.DeviceUnregistered]:{icon:Bo,color:`bg-red-500/15 text-red-400 border-red-500/30`,label:`Unregistered`},[H.DeviceStateChanged]:{icon:Qr,color:`bg-foreground-subtle/10 text-foreground-subtle border-border`,label:`State`},[H.EventEmitted]:{icon:is,color:`bg-amber-500/15 text-amber-400 border-amber-500/30`,label:`Event`}};function Vz(e,t){let n=Bz[e]??{icon:Qa,color:`bg-foreground-subtle/10 text-foreground-subtle border-border`,label:e.split(`.`).pop()??e};if(e===H.DeviceStateChanged&&t&&typeof t.capName==`string`){let e=t.capName;return{...n,label:e}}return n}var Hz=Object.freeze([...new Set(Object.values(H))].toSorted()),Uz=Object.freeze([H.PipelineCameraMetricsSnapshot,H.PipelineRunnerLoadSnapshot,H.PipelineEngineMetricsSnapshot,H.PipelineInferenceResult,H.PipelineTrace,H.PipelineProgress,H.StreamBrokerMetricsSnapshot,H.MetricsNodeResourcesSnapshot,H.MetricsNodeProcessesSnapshot,H.ClusterTopologySnapshot,H.MotionAnalysis,H.MotionZonesRaw,H.DetectionResult,H.PipelineAudioInferenceResult,H.PlatformProbePhase,H.BenchmarkProgress,H.ModelDownloadProgress]),Wz=new Set(Uz),Gz=Object.freeze(Hz.filter(e=>!Wz.has(e)));function Kz(e,t){if(e===H.DetectionPhaseTransition){let e=t.to,n=t.from,r=typeof t.source==`string`?t.source:null,i=typeof t.cooldownMs==`number`?t.cooldownMs:null,a=r?` (${r}${i?`, ${Math.round(i/1e3)}s cooldown`:``})`:``;return e===`active`?`Motion detected — phase active${a}`:e===`watching`?`Cooldown expired — phase watching${a}`:`Phase: ${String(n)} → ${String(e)}${a}`}if(e===H.DetectionResult){let e=t.frame?.detections??[];if(e.length===0)return null;let n=new Map;for(let t of e){let e=t,r=e.class??e.macroClass,i=typeof r==`string`?r:``;i&&n.set(i,(n.get(i)??0)+1)}return[...n.entries()].map(([e,t])=>t>1?`${e} ×${t}`:e).join(`, `)}if(e===H.PipelineAudioInferenceResult){let e=t.frame?.detections??[];return e.length===0?null:e.map(e=>{let t=e,n=t.macroClass??t.class??t.label,r=typeof n==`string`?n:``,i=t.score;return i?`${r} (${Math.round(i*100)}%)`:r}).filter(Boolean).join(`, `)}if(e===H.DetectionEvent){let e=t.label??t.class,n=t.score??t.confidence,r=[];return typeof e==`string`&&r.push(e),typeof n==`number`&&r.push(`${Math.round(n*100)}%`),r.length>0?r.join(` — `):null}if(e===H.ProviderMotion)return t.active===!0?`motion start`:`motion stop`;if(e===H.DeviceStateChanged){let e=t.slice;if(e&&typeof e==`object`){let t=Object.keys(e).filter(e=>e!==`lastFetchedAt`&&e!==`ts`);if(t.length>0)return t.slice(0,4).join(`, `)+(t.length>4?`…`:``)}return null}if(e===H.EventEmitted)return(typeof t.eventType==`string`?t.eventType:null)??null;if(e===H.MotionOnMotionChanged){let e=t.detected,n=typeof t.source==`string`?t.source:null,r=e===!0?`motion start`:e===!1?`motion stop`:`motion`;return n?`${r} (${n})`:r}if(e===H.ProviderDetection||e===H.DetectionCameraNative){let e=t.detections??[];if(!Array.isArray(e)||e.length===0)return(typeof t.class==`string`?t.class:null)??null;let n=new Map;for(let t of e){let e=t,r=e.class??e.macroClass,i=typeof r==`string`?r:``;i&&n.set(i,(n.get(i)??0)+1)}return[...n.entries()].map(([e,t])=>t>1?`${e} ×${t}`:e).join(`, `)}let n=t.addonId;return t.error||(n?`addon: ${n}`:null)}function qz(e){let t=e.category;return t===H.DetectionResult||t===H.PipelineAudioInferenceResult?Kz(t,e.data)!==null:!0}var Jz=300;function Yz({agentId:e,addonId:t,deviceId:n,defaultCategories:r,categories:i,category:a,maxHeight:o=`max-h-96`,limit:s=50,showCategoryFilter:c=!0,showFilters:l=!1,liveBuffer:d,onClose:p,className:m}){let h=b(()=>r??i??Gz,[r,i]),_=b(()=>[...h].toSorted().join(`,`),[h]),[v,y]=k(()=>new Set(h)),x=f(_);P(()=>{x.current!==_&&(x.current=_,y(new Set(h)))},[_,h]);let S=Tz(Jz),C=d??S,w=C.entries,[T,E]=k(!0),[D,O]=k(new Set),[A,j]=k(``),[M,F]=k(!1),[I,L]=k(``),[R,ee]=k(0),z=f(null),B=f(null),V=`${e??``}:${t??``}:${String(n??``)}:${a??``}`,te=f(V);P(()=>{te.current!==V&&(te.current=V,C.reset(),O(new Set),ee(0))},[V,C]),P(()=>{if(!M)return;let e=e=>{let t=B.current;t&&e.target instanceof Node&&!t.contains(e.target)&&F(!1)};return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[M]);let H=b(()=>{let r={};return e&&(r.agentId=e),t&&(r.addonId=t),n!==void 0&&(r.deviceId=n),a&&(r.category=a),r},[e,t,n,a]),U=b(()=>[...v].toSorted(),[v]),ne=b(()=>{let e={...H,limit:s};return U.length>0&&U.length<Hz.length&&(e.category=U),e},[H,s,b(()=>U.join(`,`),[U]),U]),{data:re,isLoading:ie}=Z.systemEvents.getRecent.useQuery(ne,{staleTime:3e4}),ae=f(v);P(()=>{ae.current=v},[v]);let oe=H;Z.systemEvents.subscribe.useSubscription(oe,{onData:r=>{let i=r;i?.id&&zz(i,e,t,n)&&ae.current.has(i.category)&&C.append(i)}});let se=f(w.length);P(()=>{let e=z.current;if(!e){se.current=w.length;return}let t=se.current;if(se.current=w.length,!(w.length<=t)){if(T&&e.scrollTop<=8)e.scrollTo({top:0});else if(!T&&e.scrollTop>0){let n=e.firstElementChild?.firstElementChild,r=n instanceof HTMLElement?n.offsetHeight:28;e.scrollTop+=r*(w.length-t)}}},[w.length,T]);let W=b(()=>{let e=new Map;for(let t of re??[])e.set(t.id,t);for(let t of w)e.set(t.id,t);let t=[...e.values()].filter(e=>v.has(e.category)).filter(qz);R>0&&(t=t.filter(e=>new Date(e.timestamp).getTime()>R));let n=A.trim().toLowerCase();return n&&(t=t.filter(e=>{if(e.category.toLowerCase().includes(n)||Vz(e.category,e.data).label.toLowerCase().includes(n))return!0;let t=Kz(e.category,e.data);if(t&&t.toLowerCase().includes(n))return!0;try{if(new Date(e.timestamp).toLocaleTimeString().toLowerCase().includes(n))return!0}catch{}try{if(JSON.stringify(e.data).toLowerCase().includes(n)||JSON.stringify(e.source).toLowerCase().includes(n))return!0}catch{}return!1})),t.toSorted((e,t)=>new Date(t.timestamp).getTime()-new Date(e.timestamp).getTime())},[re,w,v,A,R]),ce=u(e=>{O(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),le=u(e=>{y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ue=u(()=>{y(new Set(h)),j(``),ee(0)},[h]),de=u(()=>{ee(Date.now()),C.reset()},[C]),[fe,pe]=k(!1),[G,me]=k(null),he=u(e=>{let t=new Date(e.timestamp).toISOString(),n=Kz(e.category,e.data)??``,r=n?` ${n}`:``;return`${t} [${e.category}]${r} data=${JSON.stringify(e.data)}`},[]),ge=u(()=>{let e=W.map(he);navigator.clipboard.writeText(e.join(`
67
- `)).then(()=>{pe(!0),setTimeout(()=>pe(!1),1500)})},[W,he]),_e=u(e=>{navigator.clipboard.writeText(he(e)).then(()=>{me(e.id),setTimeout(()=>me(t=>t===e.id?null:t),1200)})},[he]),ve=u(()=>{y(new Set(Hz))},[]),ye=u(()=>{y(new Set)},[]),be=b(()=>{let e=I.trim().toLowerCase();return e?Hz.filter(t=>t.toLowerCase().includes(e)):Hz},[I]),xe=Hz.length,Se=v.size,Ce=Se===xe,we=Ce?`All`:`${Se}/${xe}`;return g(`div`,{className:X(`h-full min-h-0 flex flex-col`,m),onClick:e=>e.stopPropagation(),children:[g(`div`,{className:`flex items-center justify-between px-3 py-1.5 bg-surface-hover/30 gap-2 shrink-0`,children:[g(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[N(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`Events`}),e&&N(Qz,{label:`agent`,value:e}),t&&N(Qz,{label:`addon`,value:t}),n!==void 0&&N(Qz,{label:`device`,value:`#${n}`}),a&&N(Qz,{label:`category`,value:a}),g(`button`,{type:`button`,onClick:()=>{E(e=>!e),!T&&z.current&&z.current.scrollTo({top:0,behavior:`smooth`})},className:X(`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors`,T?`border-border text-foreground-subtle hover:text-foreground`:`border-amber-500/30 bg-amber-500/10 text-amber-400`),children:[N(ai,{className:`h-2.5 w-2.5`}),T?`Auto`:`Paused`]}),c&&g(`div`,{className:`relative`,ref:B,children:[g(`button`,{type:`button`,onClick:()=>F(e=>!e),className:X(`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors`,Ce?`border-border text-foreground-subtle hover:text-foreground`:`border-violet-500/30 bg-violet-500/10 text-violet-400`),title:`Pick events to track`,children:[N(ua,{className:`h-2.5 w-2.5`}),`Filter (`,we,`)`]}),M&&N(Xz,{search:I,onSearchChange:L,categories:be,active:v,onToggle:le,onSelectAll:ve,onSelectNone:ye,onResetDefaults:ue})]}),g(`button`,{type:`button`,onClick:ue,className:`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground transition-colors`,title:`Reset filters to defaults`,children:[N(so,{className:`h-2.5 w-2.5`}),`Reset`]}),g(`button`,{type:`button`,onClick:de,className:`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground transition-colors`,title:`Clear visible entries`,children:[N(Bo,{className:`h-2.5 w-2.5`}),`Clear`]}),g(`button`,{type:`button`,onClick:ge,disabled:W.length===0,className:X(`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors`,fe?`border-emerald-500/30 bg-emerald-500/10 text-emerald-400`:`border-border text-foreground-subtle hover:text-foreground`,W.length===0&&`opacity-40 cursor-not-allowed`),title:`Copy all visible events`,children:[N(Wi,{className:`h-2.5 w-2.5`}),fe?`Copied!`:`Copy`]}),g(`div`,{className:`relative`,children:[N(`input`,{type:`text`,value:A,onChange:e=>j(e.target.value),placeholder:`Search…`,className:`w-32 pl-1.5 pr-5 py-0.5 rounded border border-border bg-background text-foreground text-[10px] focus:outline-none focus:border-primary/50`}),A&&N(`button`,{type:`button`,onClick:()=>j(``),className:`absolute right-1 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground`,title:`Clear search`,children:N(rs,{className:`h-2.5 w-2.5`})})]}),w.length>0&&g(`span`,{className:`text-[9px] text-emerald-400 font-medium`,children:[`+`,w.length,` live`]})]}),p&&N(`button`,{type:`button`,onClick:p,className:`text-foreground-subtle hover:text-foreground`,children:N(rs,{className:`h-3.5 w-3.5`})})]}),g(`div`,{ref:z,className:X(`flex-1 min-h-0 overflow-auto text-[10px]`,o),children:[ie&&g(`div`,{className:`flex items-center justify-center gap-2 py-6 text-foreground-subtle`,children:[N(Ea,{className:`h-3.5 w-3.5 animate-spin`}),`Loading events...`]}),!ie&&W.length===0&&N(`div`,{className:`py-4 text-center text-foreground-subtle`,children:`No events found`}),W.length>0&&N(`div`,{className:`divide-y divide-border/30`,children:W.map(e=>{let t=Vz(e.category,e.data),n=t.icon,r=Kz(e.category,e.data),i=D.has(e.id);return g(`div`,{className:`flex items-start gap-2 px-3 py-1.5 hover:bg-surface-hover/30 cursor-pointer`,onClick:()=>ce(e.id),children:[N(`span`,{className:`text-foreground-subtle whitespace-nowrap w-[70px] shrink-0 pt-0.5`,children:new Date(e.timestamp).toLocaleTimeString()}),N($z,{copied:G===e.id,onCopy:()=>_e(e)}),g(`div`,{className:`flex-1 min-w-0`,children:[g(`div`,{className:`flex items-center gap-1.5`,children:[N(i?Re:Ue,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),g(`span`,{className:X(`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[9px] font-medium`,t.color),children:[N(n,{className:`h-2.5 w-2.5`}),t.label]}),e.source.nodeId&&e.source.nodeId!==`hub`&&N(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:e.source.nodeId})]}),r&&N(`p`,{className:`text-foreground-subtle text-[10px] mt-0.5 ml-5`,children:r}),i&&g(`div`,{className:`mt-1 ml-5 text-[9px] bg-surface rounded px-2 py-1.5 space-y-0.5 font-mono overflow-x-auto`,children:[g(`div`,{children:[N(`span`,{className:`text-primary/70`,children:`source`}),N(`span`,{className:`text-foreground-subtle`,children:`: `}),N(`span`,{className:`text-foreground`,children:JSON.stringify(e.source)})]}),g(`div`,{children:[N(`span`,{className:`text-primary/70`,children:`category`}),N(`span`,{className:`text-foreground-subtle`,children:`: `}),N(`span`,{className:`text-foreground`,children:e.category})]}),Object.entries(e.data).map(([e,t])=>g(`div`,{children:[N(`span`,{className:`text-primary/70`,children:e}),N(`span`,{className:`text-foreground-subtle`,children:`: `}),N(`span`,{className:`text-foreground break-all`,children:typeof t==`object`?JSON.stringify(t):String(t)})]},e))]})]})]},e.id)})})]})]})}function Xz({search:e,onSearchChange:t,categories:n,active:r,onToggle:i,onSelectAll:a,onSelectNone:o,onResetDefaults:s}){return g(`div`,{className:`absolute z-20 top-full mt-1 left-0 w-72 max-h-80 rounded-md border border-border bg-surface shadow-lg flex flex-col`,onClick:e=>e.stopPropagation(),children:[g(`div`,{className:`flex items-center gap-1 px-2 py-1.5 border-b border-border/50`,children:[N(po,{className:`h-3 w-3 text-foreground-subtle`}),N(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),placeholder:`Filter categories…`,className:`flex-1 bg-transparent text-[10px] focus:outline-none text-foreground placeholder:text-foreground-subtle`,autoFocus:!0}),e&&N(`button`,{type:`button`,onClick:()=>t(``),className:`text-foreground-subtle hover:text-foreground`,children:N(rs,{className:`h-2.5 w-2.5`})})]}),g(`div`,{className:`flex items-center gap-1 px-2 py-1 border-b border-border/50 text-[9px]`,children:[N(`button`,{type:`button`,onClick:a,className:`px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground`,children:`All`}),N(`button`,{type:`button`,onClick:o,className:`px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground`,children:`None`}),N(`button`,{type:`button`,onClick:s,className:`px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground`,children:`Defaults`})]}),g(`div`,{className:`overflow-y-auto flex-1`,children:[n.length===0&&N(`div`,{className:`text-[10px] text-foreground-subtle italic px-2 py-3 text-center`,children:`No matches`}),n.map(e=>{let t=r.has(e),n=Vz(e),a=n.icon;return g(`button`,{type:`button`,onClick:()=>i(e),className:`w-full flex items-center gap-2 px-2 py-1 text-left hover:bg-surface-hover/40 text-[10px]`,children:[N(`input`,{type:`checkbox`,readOnly:!0,checked:t,className:`accent-violet-500`}),g(`span`,{className:X(`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[9px] font-medium shrink-0`,n.color),children:[N(a,{className:`h-2.5 w-2.5`}),n.label]}),N(`span`,{className:`text-foreground-subtle font-mono truncate`,children:e})]},e)})]})]})}function Zz({position:e=`bottom`,className:t,...n}){return N(`div`,{className:X(e===`bottom`?`absolute bottom-0 left-0 right-0 z-10 border-t border-border bg-surface/95 backdrop-blur-sm`:`absolute inset-x-2 bottom-2 z-10 rounded-lg border border-border bg-surface/95 backdrop-blur-sm shadow-xl`,t),children:N(Yz,{maxHeight:`max-h-48`,...n})})}function Qz({label:e,value:t}){return g(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium`,children:[e,`: `,t]})}function $z({copied:e,onCopy:t}){return N(`button`,{type:`button`,title:`Copy this event`,onClick:e=>{e.stopPropagation(),t()},className:X(`rounded p-0.5 transition-colors mt-0.5`,e?`text-emerald-400`:`text-foreground-subtle/60 hover:text-foreground hover:bg-surface-hover`),children:N(e?Ci:Wi,{className:`h-3 w-3`})})}h();function eB({deviceId:e,className:t=``,onOpenChild:n}){let r=Z.useUtils(),i=Z.deviceDiscovery.listDiscovered.useQuery({deviceId:e},{refetchInterval:1e4,retry:!1}),a=Z.deviceDiscovery.getStatus.useQuery({deviceId:e},{refetchInterval:1e4,retry:!1}),o=Z.deviceDiscovery.refreshDiscovery.useMutation({onSuccess:()=>{r.deviceDiscovery.listDiscovered.invalidate({deviceId:e}),r.deviceDiscovery.getStatus.invalidate({deviceId:e})}}),s=Z.deviceDiscovery.adoptDevice.useMutation({onSuccess:()=>{r.deviceDiscovery.listDiscovered.invalidate({deviceId:e})}}),c=Z.deviceDiscovery.releaseDevice.useMutation({onSuccess:()=>{r.deviceDiscovery.listDiscovered.invalidate({deviceId:e})}}),[l,u]=k(null),{available:d,adopted:f}=b(()=>{let e=i.data??[],t=e=>typeof e.metadata.rtspChannel==`number`?e.metadata.rtspChannel:1/0,n=(e,n)=>{let r=t(e),i=t(n);return r===i?e.name.localeCompare(n.name):r-i};return{available:e.filter(e=>!e.alreadyAdopted).toSorted(n),adopted:e.filter(e=>e.alreadyAdopted).toSorted(n)}},[i.data]),p=a.data,m=p?.lastError??null,h=p?.lastDiscoveryAt??null;async function _(){await o.mutateAsync({deviceId:e}).catch(()=>{})}async function v(t){u(t.childNativeId);try{await s.mutateAsync({deviceId:e,childNativeId:t.childNativeId})}finally{u(null)}}async function y(t){if(t.adoptedDeviceId!=null){u(t.childNativeId);try{await c.mutateAsync({deviceId:e,childDeviceId:t.adoptedDeviceId})}finally{u(null)}}}return g(`div`,{className:`rounded-xl border border-border bg-surface ${t}`,children:[g(`div`,{className:`flex items-start justify-between gap-2 border-b border-border px-3 py-2 sm:px-5 sm:py-3`,children:[g(`div`,{className:`min-w-0`,children:[N(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Discovered devices`}),g(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Channels behind this hub. Click `,N(`span`,{className:`font-medium`,children:`Add`}),` to promote a channel to a managed device, or `,N(`span`,{className:`font-medium`,children:`Remove`}),` to detach.`]})]}),g(`button`,{type:`button`,onClick:_,disabled:o.isPending,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-2 py-1.5 sm:px-3 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 shrink-0`,children:[o.isPending?N(Ea,{className:`h-3.5 w-3.5 animate-spin`}):N(oo,{className:`h-3.5 w-3.5`}),N(`span`,{className:`hidden sm:inline`,children:`Refresh`})]})]}),m?g(`div`,{className:`flex items-start gap-2 border-b border-border bg-destructive/10 px-5 py-2 text-[11px] text-destructive`,children:[N(Uo,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),g(`span`,{children:[`Last refresh failed: `,m]})]}):null,i.isLoading?N(`div`,{className:`flex items-center justify-center py-8 text-foreground-subtle`,children:N(Ea,{className:`h-5 w-5 animate-spin`})}):d.length===0&&f.length===0?N(`div`,{className:`px-5 py-8 text-center text-xs text-foreground-subtle`,children:`No channels reported by the hub yet. Click Refresh to enumerate.`}):g(w,{children:[d.length>0?N(tB,{title:`Available to add`,count:d.length,tone:`primary`,children:d.map(e=>N(nB,{child:e,busy:l===e.childNativeId,onAdopt:v,onRelease:y,onOpenChild:n},e.childNativeId))}):null,f.length>0?N(tB,{title:`Already adopted`,count:f.length,tone:`muted`,children:f.map(e=>N(nB,{child:e,busy:l===e.childNativeId,onAdopt:v,onRelease:y,onOpenChild:n},e.childNativeId))}):null]}),h==null?null:g(`div`,{className:`border-t border-border px-5 py-2 text-[10px] text-foreground-subtle`,children:[`Last refreshed `,new Date(h).toLocaleString()]})]})}function tB({title:e,count:t,tone:n,children:r}){return g(`div`,{className:`border-t border-border`,children:[g(`div`,{className:`flex items-center justify-between border-b px-3 sm:px-5 py-1.5 text-[10px] uppercase tracking-wider ${n===`primary`?`bg-primary/5 text-primary border-primary/30`:`bg-surface text-foreground-subtle border-border`}`,children:[N(`span`,{className:`font-semibold`,children:e}),N(`span`,{className:`font-mono`,children:t})]}),N(`div`,{className:`divide-y divide-border`,children:r})]})}function nB({child:e,busy:t,onAdopt:n,onRelease:r,onOpenChild:i}){return g(`div`,{className:`flex flex-wrap items-center justify-between gap-2 px-3 py-2 sm:px-5 sm:py-3 sm:flex-nowrap sm:gap-3`,children:[g(`div`,{className:`min-w-0 flex-1`,children:[g(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[N(rB,{status:e.status}),N(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),e.metadata.isDoorbell?N(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:`Doorbell`}):null,e.metadata.isBattery?N(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:`Battery`}):null,e.metadata.isMultifocal?N(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:`Multifocal`}):null]}),g(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[typeof e.metadata.rtspChannel==`number`?g(`span`,{children:[`ch `,N(`span`,{className:`font-mono`,children:e.metadata.rtspChannel})]}):null,e.metadata.model?N(`span`,{className:`truncate max-w-[160px]`,children:e.metadata.model}):null,e.metadata.uid?g(`span`,{className:`font-mono truncate max-w-[140px]`,children:[e.metadata.uid.slice(0,12),`…`]}):null]})]}),e.alreadyAdopted?g(`div`,{className:`flex items-center gap-2`,children:[i&&e.adoptedDeviceId!==null?g(`button`,{type:`button`,onClick:()=>i(e.adoptedDeviceId),className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Open device detail`,children:[N(ea,{className:`h-3.5 w-3.5`}),`Open`]}):null,g(`button`,{type:`button`,onClick:()=>{r(e)},disabled:t,className:`inline-flex items-center gap-1.5 rounded-lg border border-destructive/30 px-3 py-1.5 text-xs text-destructive hover:bg-destructive/10 transition-colors disabled:opacity-50`,children:[t?N(Ea,{className:`h-3.5 w-3.5 animate-spin`}):N(Bo,{className:`h-3.5 w-3.5`}),`Remove`]})]}):g(`button`,{type:`button`,onClick:()=>{n(e)},disabled:t,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[t?N(Ea,{className:`h-3.5 w-3.5 animate-spin`}):N($a,{className:`h-3.5 w-3.5`}),`Add`]})]})}function rB({status:e}){switch(e){case`online`:return g(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-emerald-500/40 bg-emerald-500/10 px-2 py-0.5 text-[10px] font-medium text-emerald-500`,children:[N($o,{className:`h-2.5 w-2.5`}),` online`]});case`sleeping`:return g(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] font-medium text-amber-500`,children:[N(Ba,{className:`h-2.5 w-2.5`}),` sleeping`]});case`offline`:return g(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-destructive/40 bg-destructive/10 px-2 py-0.5 text-[10px] font-medium text-destructive`,children:[N(Qo,{className:`h-2.5 w-2.5`}),` offline`]});default:return g(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-border bg-surface px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:[N(Pi,{className:`h-2.5 w-2.5`}),` unknown`]})}}h();function iB(e,t){if(!e||typeof e!=`object`)return null;let n=e;if(n.category!==H.DeviceStateChanged)return null;let r=n.data;return!r||typeof r!=`object`||r.deviceId!==t||typeof r.capName!=`string`||!r.slice||typeof r.slice!=`object`?null:{capName:r.capName,slice:r.slice}}function aB(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function oB(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.source==`string`?!!t.data&&typeof t.data==`object`&&!Array.isArray(t.data):!1}function sB(e,t){let n=new Map;for(let[r,i]of Object.entries(e)){let e=i&&typeof i==`object`&&!Array.isArray(i)?i:{value:i};n.set(r,{slice:e,updatedAt:t})}return n}var cB=Object.freeze([...new Set(ce.filter(e=>e.scope===`device`).map(e=>e.name))].toSorted()),lB=1;function uB({deviceId:e,defaultCaps:t,maxHeight:n=`max-h-96`,onClose:r,className:i}){let[a,o]=k(b(()=>new Set(t??[]),[t])),[s,c]=k(``),[l,d]=k(!1),[p,m]=k(``),[h,_]=k(`normalized`),v=f(null),[y,x]=k(new Map),[S,T]=k(new Map),[,E]=k(0),D=f(e);P(()=>{D.current!==e&&(D.current=e,x(new Map),T(new Map))},[e]);let{data:O,isLoading:A}=Z.deviceState.getAllSnapshots.useQuery({},{staleTime:3e4}),j=f(!1);P(()=>{if(j.current||!aB(O))return;let t=O[String(e)];if(j.current=!0,!t)return;let n=Date.now();x(e=>{let r=new Map(e);for(let[e,i]of Object.entries(t))r.has(e)||r.set(e,{slice:i,updatedAt:n});return r})},[O,e]),P(()=>{j.current=!1},[e]);let M=u((e,t)=>{x(n=>{let r=new Map(n);return r.set(e,{slice:t,updatedAt:Date.now()}),r})},[]),F=Fe(Ke().trpcClient,e)?.deviceOps?.getRawState,I=C({queryKey:[`device-raw-state`,e],queryFn:()=>F({deviceId:e}),enabled:F!=null,staleTime:6e4}),L=oB(I.data)?I.data:null,R=I.isFetched&&!I.isError&&L!=null;P(()=>{h===`raw`&&!R&&_(`normalized`)},[h,R]);let ee=b(()=>L?sB(L.data,I.dataUpdatedAt||Date.now()):new Map,[L,I.dataUpdatedAt]);P(()=>{let e=setInterval(()=>E(e=>e+1),5e3);return()=>clearInterval(e)},[]);let z=b(()=>{let e=new Set(cB);for(let t of y.keys())e.add(t);return[...e].toSorted()},[y]),B=b(()=>{let e=s.trim().toLowerCase();return[...y.keys()].toSorted().filter(t=>a.size>0&&!a.has(t)?!1:!e||t.toLowerCase().includes(e)?!0:xB(y.get(t)?.slice??{},e))},[y,a,s]),V=u(e=>{o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),te=u(()=>{o(new Set(t??[])),c(``)},[t]),H=u(()=>{o(new Set(z))},[z]),U=u(()=>{o(new Set)},[]),ne=u((e,t)=>{T(n=>{let r=new Map(n);return r.set(e,!t),r})},[]),re=u((e,t)=>{let n=S.get(e);return n===void 0?t<lB:n},[S]),[ie,ae]=k(!1),oe=u(()=>{let e={};for(let t of B){let n=y.get(t);n&&(e[t]=n.slice)}navigator.clipboard.writeText(JSON.stringify(e,null,2)).then(()=>{ae(!0),setTimeout(()=>ae(!1),1500)})},[B,y]),se=b(()=>{let e=p.trim().toLowerCase();return e?z.filter(t=>t.toLowerCase().includes(e)):z},[p,z]),W=z.length,ce=a.size,le=ce===0||ce===W,ue=le?`All`:`${ce}/${W}`;P(()=>{if(!l)return;let e=e=>{let t=v.current;t&&!t.contains(e.target)&&d(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[l]);let de=s.trim().toLowerCase();return g(`div`,{className:X(`h-full min-h-0 flex flex-col`,i),onClick:e=>e.stopPropagation(),children:[g(`div`,{className:`flex items-center justify-between px-3 py-1.5 bg-surface-hover/30 gap-2 shrink-0`,children:[g(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[N(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`State`}),N(CB,{label:`device`,value:`#${e}`}),R&&N(dB,{mode:h,onChange:_}),h===`normalized`&&g(w,{children:[g(`div`,{className:`relative`,ref:v,children:[g(`button`,{type:`button`,onClick:()=>d(e=>!e),className:X(`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors`,le?`border-border text-foreground-subtle hover:text-foreground`:`border-violet-500/30 bg-violet-500/10 text-violet-400`),title:`Pick caps to show`,children:[N(ua,{className:`h-2.5 w-2.5`}),`Filter (`,ue,`)`]}),l&&N(wB,{search:p,onSearchChange:m,caps:se,active:a,onToggle:V,onSelectAll:H,onSelectNone:U,onResetDefaults:te})]}),g(`button`,{type:`button`,onClick:te,className:`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground transition-colors`,title:`Reset filters`,children:[N(so,{className:`h-2.5 w-2.5`}),`Reset`]}),g(`button`,{type:`button`,onClick:oe,disabled:B.length===0,className:X(`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors`,ie?`border-emerald-500/30 bg-emerald-500/10 text-emerald-400`:`border-border text-foreground-subtle hover:text-foreground`,B.length===0&&`opacity-40 cursor-not-allowed`),title:`Copy visible state as JSON`,children:[N(Wi,{className:`h-2.5 w-2.5`}),ie?`Copied!`:`Copy`]}),g(`div`,{className:`relative`,children:[N(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`Search…`,className:`w-32 pl-1.5 pr-5 py-0.5 rounded border border-border bg-background text-foreground text-[10px] focus:outline-none focus:border-primary/50`}),s&&N(`button`,{type:`button`,onClick:()=>c(``),className:`absolute right-1 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground`,title:`Clear search`,children:N(rs,{className:`h-2.5 w-2.5`})})]}),g(`span`,{className:`text-[9px] text-emerald-400 font-medium inline-flex items-center gap-1`,children:[N(`span`,{className:`h-1.5 w-1.5 rounded-full bg-emerald-400 animate-pulse`}),`live`]})]}),h===`raw`&&L&&g(w,{children:[g(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-sky-500/30 bg-sky-500/15 text-sky-400 px-2 py-0.5 text-[9px] font-medium font-sans`,children:[`source: `,L.source]}),g(`button`,{type:`button`,onClick:()=>I.refetch(),disabled:I.isFetching,className:X(`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground transition-colors`,I.isFetching&&`opacity-60 cursor-wait`),title:`Re-read raw upstream state`,children:[N(so,{className:X(`h-2.5 w-2.5`,I.isFetching&&`animate-spin`)}),`Refresh`]})]})]}),h===`normalized`&&N(fB,{deviceId:e,onPatch:M}),r&&N(`button`,{type:`button`,onClick:r,className:`text-foreground-subtle hover:text-foreground`,children:N(rs,{className:`h-3.5 w-3.5`})})]}),N(`div`,{className:X(`flex-1 min-h-0 overflow-auto text-[10px] font-mono`,n),children:h===`raw`?ee.size===0?N(`div`,{className:`py-4 text-center text-foreground-subtle font-sans`,children:`No raw state`}):N(`div`,{className:`py-1`,children:[...ee.entries()].map(([e,t])=>N(pB,{capName:e,slice:t.slice,updatedAt:t.updatedAt,searchNeedle:``,isPathOpen:re,onToggle:ne},e))}):g(w,{children:[A&&y.size===0&&g(`div`,{className:`flex items-center justify-center gap-2 py-6 text-foreground-subtle font-sans`,children:[N(Ea,{className:`h-3.5 w-3.5 animate-spin`}),`Loading device state...`]}),!A&&y.size===0&&N(`div`,{className:`py-4 text-center text-foreground-subtle font-sans`,children:`No runtime state`}),!A&&y.size>0&&B.length===0&&N(`div`,{className:`py-4 text-center text-foreground-subtle font-sans`,children:`No caps match the filter`}),B.length>0&&N(`div`,{className:`py-1`,children:B.map(e=>{let t=y.get(e);return t?N(pB,{capName:e,slice:t.slice,updatedAt:t.updatedAt,searchNeedle:de,isPathOpen:re,onToggle:ne},e):null})})]})})]})}function dB({mode:e,onChange:t}){return N(`div`,{className:`inline-flex items-center rounded border border-border overflow-hidden`,children:[{value:`normalized`,label:`Normalized`},{value:`raw`,label:`Raw`}].map(n=>N(`button`,{type:`button`,onClick:()=>t(n.value),className:X(`text-[9px] px-1.5 py-0.5 transition-colors`,e===n.value?`bg-violet-500/15 text-violet-400`:`text-foreground-subtle hover:text-foreground`),children:n.label},n.value))})}function fB({deviceId:e,onPatch:t}){return Z.systemEvents.subscribe.useSubscription({deviceId:e,category:H.DeviceStateChanged},{onData:n=>{let r=iB(n,e);r&&t(r.capName,r.slice)}}),null}function pB({capName:e,slice:t,updatedAt:n,searchNeedle:r,isPathOpen:i,onToggle:a}){let o=e,s=i(o,0),c=Object.entries(t);return g(`div`,{children:[g(`div`,{className:`flex items-center gap-1.5 px-3 py-1 hover:bg-surface-hover/30 cursor-pointer select-none`,onClick:()=>a(o,s),children:[N(gB,{open:s,hasChildren:c.length>0}),N(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-violet-500/30 bg-violet-500/15 text-violet-400 px-2 py-0.5 text-[9px] font-medium font-sans`,children:e}),g(`span`,{className:`text-[9px] text-foreground-subtle font-sans`,children:[c.length,` `,c.length===1?`key`:`keys`]}),g(`span`,{className:`ml-auto text-[9px] text-foreground-subtle/70 font-sans tabular-nums`,children:[`updated `,SB(n)]})]}),s&&N(`div`,{children:c.length===0?N(hB,{depth:1,label:`empty slice`}):c.map(([e,t])=>N(mB,{path:`${o}.${e}`,nodeKey:e,value:t,depth:1,searchNeedle:r,isPathOpen:i,onToggle:a},e))})]})}function mB({path:e,nodeKey:t,value:n,depth:r,searchNeedle:i,isPathOpen:a,onToggle:o}){let s=_B(n),c={paddingLeft:`${12+r*14}px`};if(!s)return g(`div`,{className:`flex items-start gap-1 px-3 py-0.5`,style:c,children:[N(`span`,{className:X(`shrink-0`,bB(t,i,`text-primary/70`)),children:t}),N(`span`,{className:`text-foreground-subtle`,children:`:`}),N(`span`,{className:X(`break-all`,bB(vB(n),i,yB(n))),children:vB(n)})]});let l=a(e,r);return g(`div`,{children:[g(`div`,{className:`flex items-center gap-1 px-3 py-0.5 hover:bg-surface-hover/30 cursor-pointer select-none`,style:c,onClick:()=>o(e,l),children:[N(gB,{open:l,hasChildren:s.entries.length>0}),N(`span`,{className:bB(t,i,`text-primary/70`),children:t}),N(`span`,{className:`text-foreground-subtle/70 text-[9px]`,children:s.summary})]}),l&&(s.entries.length===0?N(hB,{depth:r+1,label:s.kind===`array`?`empty array`:`empty object`}):s.entries.map(([t,n])=>N(mB,{path:`${e}.${t}`,nodeKey:t,value:n,depth:r+1,searchNeedle:i,isPathOpen:a,onToggle:o},t)))]})}function hB({depth:e,label:t}){return N(`div`,{className:`px-3 py-0.5 text-foreground-subtle/60 italic`,style:{paddingLeft:`${12+e*14}px`},children:t})}function gB({open:e,hasChildren:t}){return t?N(e?Re:Ue,{className:`h-3 w-3 text-foreground-subtle shrink-0`}):N(`span`,{className:`inline-block w-3 shrink-0`})}function _B(e){if(Array.isArray(e))return{kind:`array`,entries:e.map((e,t)=>[String(t),e]),summary:`[${e.length}]`};if(e&&typeof e==`object`){let t=Object.entries(e);return{kind:`object`,entries:t,summary:`{${t.length}}`}}return null}function vB(e){if(e===null)return`null`;if(e===void 0)return`undefined`;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{return JSON.stringify(e)}catch{return String(e)}}function yB(e){return e==null?`text-foreground-subtle/60`:typeof e==`number`?`text-amber-400`:typeof e==`boolean`?e?`text-emerald-400`:`text-rose-400`:`text-foreground`}function bB(e,t,n){return t&&e.toLowerCase().includes(t)?X(n,`bg-violet-500/20 rounded px-0.5`):n}function xB(e,t){if(Array.isArray(e))return e.some(e=>xB(e,t));if(e&&typeof e==`object`){for(let[n,r]of Object.entries(e))if(n.toLowerCase().includes(t)||xB(r,t))return!0;return!1}return vB(e).toLowerCase().includes(t)}function SB(e){let t=Date.now()-e;if(t<5e3)return`just now`;let n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;let r=Math.floor(n/60);return r<60?`${r}m ago`:`${Math.floor(r/60)}h ago`}function CB({label:e,value:t}){return g(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium font-sans`,children:[e,`: `,t]})}function wB({search:e,onSearchChange:t,caps:n,active:r,onToggle:i,onSelectAll:a,onSelectNone:o,onResetDefaults:s}){return g(`div`,{className:`absolute z-20 top-full mt-1 left-0 w-72 max-h-80 rounded-md border border-border bg-surface shadow-lg flex flex-col font-sans`,onClick:e=>e.stopPropagation(),children:[g(`div`,{className:`flex items-center gap-1 px-2 py-1.5 border-b border-border/50`,children:[N(po,{className:`h-3 w-3 text-foreground-subtle`}),N(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),placeholder:`Filter caps…`,className:`flex-1 bg-transparent text-[10px] focus:outline-none text-foreground placeholder:text-foreground-subtle`,autoFocus:!0}),e&&N(`button`,{type:`button`,onClick:()=>t(``),className:`text-foreground-subtle hover:text-foreground`,children:N(rs,{className:`h-2.5 w-2.5`})})]}),g(`div`,{className:`flex items-center gap-1 px-2 py-1 border-b border-border/50 text-[9px]`,children:[N(`button`,{type:`button`,onClick:a,className:`px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground`,children:`All`}),N(`button`,{type:`button`,onClick:o,className:`px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground`,children:`None`}),N(`button`,{type:`button`,onClick:s,className:`px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground`,children:`Defaults`})]}),g(`div`,{className:`overflow-y-auto flex-1`,children:[n.length===0&&N(`div`,{className:`text-[10px] text-foreground-subtle italic px-2 py-3 text-center`,children:`No matches`}),n.map(e=>g(`button`,{type:`button`,onClick:()=>i(e),className:`w-full flex items-center gap-2 px-2 py-1 text-left hover:bg-surface-hover/40 text-[10px]`,children:[N(`input`,{type:`checkbox`,readOnly:!0,checked:r.has(e),className:`accent-violet-500`}),N(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-violet-500/30 bg-violet-500/15 text-violet-400 px-1.5 py-0.5 text-[9px] font-medium shrink-0`,children:e})]},e))]})]})}h();var TB=500,EB=[{id:`logs`,label:`Logs`,icon:fo},{id:`events`,label:`Events`,icon:hi},{id:`state`,label:`State`,icon:qi}];function DB({deviceId:e,containerDeviceId:t,defaultEventCategories:n,defaultStateCaps:r,initialTab:i=`events`,className:a,maxHeight:o=`max-h-96`}){let[s,c]=k(i),l=Tz(TB),u=Tz(TB),d=Tz(TB),f=l.reset,p=u.reset,m=d.reset;return P(()=>{f(),p(),m()},[e,f,p,m]),g(`div`,{className:X(`flex flex-col h-full min-h-0`,a),children:[N(`div`,{className:`flex items-center gap-1 mb-2 shrink-0`,children:EB.map(({id:e,label:t,icon:n})=>g(`button`,{type:`button`,onClick:()=>c(e),className:X(`inline-flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-[11px] font-medium transition-colors`,s===e?`bg-primary/15 text-primary border border-primary/30`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover border border-transparent`),children:[N(n,{className:`h-3.5 w-3.5`}),t]},e))}),g(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:[s===`logs`&&N(Nz,{...t===void 0?{deviceId:e}:{containerDeviceId:t},maxHeight:o,showFilters:!1,liveBuffer:l}),s===`events`&&N(Yz,{deviceId:e,defaultCategories:n,maxHeight:o,showCategoryFilter:!0,liveBuffer:u}),s===`state`&&N(uB,{deviceId:e,defaultCaps:r,maxHeight:o,liveBuffer:d})]})]})}h();function OB({label:e,icon:t,title:n=`Confirm action`,description:r,confirmLabel:i,triggerVariant:a=`outline`,confirmVariant:o=`danger`,size:s=`sm`,disabled:c,className:l,action:u,onSuccess:d}){let[f,p]=k(!1),[m,h]=k(!1),[_,v]=k(null),y=async()=>{v(null),h(!0);try{let e=await u();d?.(e),p(!1)}catch(e){v(e instanceof Error?e.message:String(e))}finally{h(!1)}};return g(w,{children:[g(ps,{type:`button`,variant:a,size:s,disabled:c,onClick:()=>{v(null),p(!0)},className:l,children:[t&&N(t,{className:`h-3.5 w-3.5`}),e]}),N(Ms,{open:f,onOpenChange:e=>!m&&p(e),children:g(Fs,{children:[g(Is,{children:[g(Rs,{className:`flex items-center gap-2`,children:[N(Uo,{className:`h-4 w-4 text-amber-400`}),n]}),typeof r==`string`?N(zs,{children:r}):r]}),_&&N(`div`,{className:X(`mt-2 px-3 py-2 rounded border border-danger/40 bg-danger/10`,`text-xs text-danger`),children:_}),g(Ls,{children:[N(ps,{type:`button`,variant:`ghost`,size:s,disabled:m,onClick:()=>p(!1),children:`Cancel`}),g(ps,{type:`button`,variant:o,size:s,disabled:m,onClick:()=>{y()},children:[m&&N(Ea,{className:`h-3.5 w-3.5 animate-spin`}),i??e]})]})]})})]})}h();function kB(e,t){let n=document.createElement(`a`);n.href=t,n.download=e,document.body.appendChild(n),n.click(),document.body.removeChild(n)}function AB({trpc:e,deviceId:t,deviceName:n,size:r=`sm`,className:i}){let[a,o]=k(!1),[s,c]=k(!1),[l,d]=k(null),f=n.replace(/[^a-zA-Z0-9_.-]+/g,`_`),p=u(async n=>{o(!0),d(null),c(!1);try{let r=await e.snapshot.getSnapshot.query({deviceId:t,force:!0});if(!r)throw Error(`No snapshot available`);let i=`data:${r.contentType};base64,${r.base64}`;if(n===`copy`)try{await navigator.clipboard.writeText(i)}catch{throw Error(`Clipboard unavailable`)}else{let e=r.contentType.includes(`png`)?`png`:`jpg`;kB(`${f}-${new Date().toISOString().replace(/[:.]/g,`-`)}.${e}`,i)}c(!0),setTimeout(()=>c(!1),1500)}catch(e){d(e instanceof Error?e.message:String(e))}finally{o(!1)}},[e,t,f]),m=r===`md`?`h-9 px-3 text-sm gap-2`:`h-7 px-2.5 text-[11px] gap-1.5`,[h,_]=k(null),[v,y]=k(!1),b=()=>{y(!1),_(setTimeout(()=>{y(!0),p(`copy`)},600))},x=()=>{h&&(clearTimeout(h),_(null)),v||p(`download`)},S=()=>{h&&(clearTimeout(h),_(null))};return g(`button`,{type:`button`,title:`Click to download · long-press to copy`,disabled:a,onPointerDown:b,onPointerUp:x,onPointerLeave:S,onPointerCancel:S,className:X(`inline-flex items-center justify-center rounded-lg font-medium border border-border`,`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,`disabled:opacity-50 transition-colors`,m,l&&`border-danger/40 text-danger`,i),children:[a?N(Ea,{className:`h-3.5 w-3.5 animate-spin`}):s?N(Ci,{className:`h-3.5 w-3.5 text-success`}):N(xi,{className:`h-3.5 w-3.5`}),`Snapshot`]})}function jB(e){let t=Date.now()-e;return t<6e4?`just now`:t<36e5?`${Math.floor(t/6e4)}m ago`:t<864e5?`${Math.floor(t/36e5)}h ago`:`${Math.floor(t/864e5)}d ago`}function MB({history:e,limit:t=5,latestIsFresh:n,className:r}){if(e.length===0)return null;let i=n?mi:hi,a=e.slice(0,t);return g(`div`,{className:X(`rounded-lg border border-border bg-surface px-3 py-2`,r),children:[g(`div`,{className:`flex items-center gap-2 mb-2`,children:[N(i,{className:X(`h-4 w-4 text-amber-400`,n&&`animate-pulse`)}),N(`span`,{className:`text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Recent presses`}),N(`span`,{className:`ml-auto rounded-full bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle border border-border`,children:e.length})]}),N(`ul`,{className:`space-y-1`,children:a.map(e=>g(`li`,{className:`flex items-center justify-between text-[11px]`,title:new Date(e.timestamp).toLocaleString(),children:[N(`span`,{className:`text-foreground`,children:jB(e.timestamp)}),N(`span`,{className:`text-foreground-subtle font-mono text-[10px]`,children:new Date(e.timestamp).toLocaleTimeString()})]},`${e.deviceId}-${e.timestamp}`))})]})}h();function NB({items:e,header:t,triggerClassName:n,title:r=`More actions`}){let[i,a]=k(!1),o=e.filter(e=>!e.hidden);return o.length===0?null:g(sc,{open:i,onOpenChange:a,children:[N(cc,{title:r,className:X(`inline-flex items-center justify-center rounded-lg p-2`,`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,`border border-transparent transition-colors`,n),children:N($i,{className:`h-4 w-4`})}),g(lc,{className:`left-auto right-0 mt-1 min-w-[200px] p-1`,children:[t&&N(`div`,{className:`px-2 py-1 text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t}),N(`ul`,{className:`space-y-0.5`,children:o.map((e,t)=>g(`li`,{children:[e.separatorBefore&&t>0&&N(`div`,{className:`my-1 h-px bg-border`}),g(`button`,{type:`button`,disabled:e.disabled,onClick:()=>{e.disabled||(e.onClick(),a(!1))},className:X(`flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left text-[12px]`,`transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,e.danger?`text-foreground hover:bg-danger/10 hover:text-danger`:`text-foreground hover:bg-surface-hover`),children:[e.icon&&N(e.icon,{className:X(`h-3.5 w-3.5 shrink-0 mt-0.5`,e.danger&&`text-danger/80`)}),g(`span`,{className:`flex-1 min-w-0`,children:[N(`span`,{className:`block leading-tight`,children:e.label}),e.description&&N(`span`,{className:`block mt-0.5 text-[10px] text-foreground-subtle leading-tight`,children:e.description})]})]})]},e.id))})]})]})}h();var PB=[{value:`view`,label:`View`,icon:na,hint:`Read-only — queries + subscriptions`},{value:`create`,label:`Create`,icon:Xa,hint:`Mutations that create or update`},{value:`delete`,label:`Delete`,icon:Bo,hint:`Destructive ops (delete/revoke/reset/…)`}],FB=[`device`,`system`];function IB(){return{type:`capability`,target:``,access:[`view`]}}function LB(e){if(e==null)return[];let t=new Set;for(let n of e)if(n.type===`device`)for(let e of n.targets)t.add(e);return[...t]}function RB(e,t,n,r){let i;switch(e){case`addon`:i=n;break;case`capability`:i=r;break;case`category`:i=FB.map(e=>({value:e,label:e}));break}if(t==null)return i;let a=new Set(t.filter(t=>t.type!==`device`&&t.type===e).map(e=>e.target));return i.filter(e=>a.has(e.value))}function zB(e,t){if(t==null)return[`view`,`create`,`delete`];let n=t.filter(t=>t.type===e.type?t.type===`device`&&e.type===`device`?t.targets.some(t=>e.targets.includes(t)):t.type!==`device`&&e.type!==`device`?t.target===e.target:!1:!1);if(n.length===0)return[];let r=new Set;for(let e of n)for(let t of e.access)r.add(t);return[...r]}function BB({value:e,onChange:t,clampToParent:n,emptyHint:r}){let{data:i}=Nu(),{data:a}=Am({}),o=b(()=>(i??[]).map(e=>({value:e.manifest.id,label:e.manifest.id})).sort((e,t)=>e.label.localeCompare(t.label)),[i]),s=b(()=>[...fe].toSorted().map(e=>({value:e,label:e})),[]),c=b(()=>(a??[]).map(e=>({value:String(e.id),label:`${e.name} (#${e.id} · ${e.addonId})`})).sort((e,t)=>e.label.localeCompare(t.label)),[a]),l=b(()=>n==null?null:LB(n),[n]),u=(e,t)=>{let n=[...t];switch(e){case`category`:return{type:`category`,target:`device`,access:n};case`capability`:return{type:`capability`,target:``,access:n};case`addon`:return{type:`addon`,target:``,access:n};case`device`:return{type:`device`,targets:[],access:n}}},d=(n,r)=>{t(e.map((e,t)=>{if(t!==n)return e;if(r.type!==void 0&&r.type!==e.type)return u(r.type,r.access??e.access);let i=[...r.access??e.access];return e.type===`device`?{type:`device`,targets:[...r.targets??e.targets],access:i}:e.type===`category`?{type:`category`,target:r.target??e.target,access:i}:e.type===`capability`?{type:`capability`,target:r.target??e.target,access:i}:{type:`addon`,target:r.target??e.target,access:i}}))},f=n=>{t(e.filter((e,t)=>t!==n))};return g(`div`,{className:`space-y-2`,children:[e.length===0&&r&&N(`div`,{className:`text-[10px] text-foreground-subtle italic px-2 py-2`,children:r}),e.map((e,t)=>{let r=zB(e,n);return g(`div`,{className:`flex flex-wrap items-start gap-1.5 rounded border border-border bg-surface px-2 py-1.5`,children:[g(`select`,{value:e.type,onChange:e=>d(t,{type:e.target.value}),className:`rounded border border-border bg-background px-2 py-1 text-[11px] focus:outline-none focus:ring-1 focus:ring-primary`,children:[N(`option`,{value:`category`,children:`category`}),N(`option`,{value:`capability`,children:`capability`}),N(`option`,{value:`addon`,children:`addon`}),N(`option`,{value:`device`,children:`device`})]}),e.type===`device`?N(VB,{value:e.targets,choices:c,clampToParent:l,onChange:e=>d(t,{targets:e})}):g(`select`,{value:e.target,onChange:e=>d(t,{target:e.target.value}),className:`flex-1 min-w-[160px] rounded border border-border bg-background px-2 py-1 text-[11px] font-mono focus:outline-none focus:ring-1 focus:ring-primary`,children:[g(`option`,{value:``,children:[`— pick `,e.type,` —`]}),RB(e.type,n,o,s).map(e=>N(`option`,{value:e.value,children:e.label},e.value))]}),N(`div`,{className:`flex items-center gap-1`,children:PB.map(({value:i,label:a,icon:o,hint:s})=>{let c=e.access.includes(i),l=n!=null&&!r.includes(i)&&!c;return g(`label`,{title:l?`${s} — not granted by your scope`:s,className:`inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] cursor-pointer transition-colors ${c?`bg-primary/15 text-primary font-medium`:`text-foreground-subtle hover:bg-foreground-subtle/10`} ${l?`opacity-40 cursor-not-allowed`:``}`,children:[N(`input`,{type:`checkbox`,checked:c,disabled:l,onChange:n=>{let r=new Set(e.access);n.target.checked?r.add(i):r.delete(i),d(t,{access:[...r]})},className:`sr-only`}),N(o,{className:`h-3 w-3`}),a]},i)})}),N(`button`,{type:`button`,onClick:()=>f(t),className:`rounded p-1 text-foreground-subtle hover:bg-danger/10 hover:text-danger transition-colors`,title:`Remove scope`,children:N(rs,{className:`h-3 w-3`})})]},t)}),g(`button`,{type:`button`,onClick:()=>{t([...e,IB()])},className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-foreground-subtle/10 transition-colors`,children:[N($a,{className:`h-3 w-3`}),`Add scope`]})]})}function VB({value:e,choices:t,clampToParent:n,onChange:r}){let[i,a]=k(``),o=b(()=>{let r=n==null?t:t.filter(e=>n.includes(e.value)),i=new Set(e);return r.filter(e=>!i.has(e.value))},[t,n,e]),s=e=>t.find(t=>t.value===e)?.label??`#${e}`,c=t=>{t&&(r([...e,t]),a(``))},l=t=>{r(e.filter(e=>e!==t))};return g(`div`,{className:`flex-1 min-w-[160px] flex flex-wrap items-center gap-1`,children:[e.length===0&&N(`span`,{className:`text-[10px] text-foreground-subtle italic px-1`,children:`no devices selected`}),e.map(e=>g(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-mono text-primary`,children:[s(e),N(`button`,{type:`button`,onClick:()=>l(e),className:`hover:text-danger transition-colors`,title:`Remove device`,children:N(rs,{className:`h-2.5 w-2.5`})})]},e)),o.length>0&&g(`select`,{value:i,onChange:e=>c(e.target.value),className:`rounded border border-border bg-background px-1.5 py-0.5 text-[10px] focus:outline-none focus:ring-1 focus:ring-primary`,children:[N(`option`,{value:``,children:`+ add device…`}),o.map(e=>N(`option`,{value:e.value,children:e.label},e.value))]})]})}function HB(e){for(let t of e){if(t.type===`device`){if(t.targets.length===0)return`Scope device: pick at least one device`}else if(t.target.trim().length===0)return`Scope ${t.type}: pick a target`;if(t.access.length===0){let e=t.type===`device`?`[${t.targets.join(`,`)}]`:t.target;return`Scope ${t.type}:${e}: pick at least one access`}}return null}h();var UB=Me(`camstack:zone-editing`,null);function WB({children:e}){let[t,n]=k(!1),[r,i]=k(null),[a,o]=k(null),[s,c]=k(null),l=u(e=>{n(e),e||(i(null),o(null),c(null))},[]),d=u(e=>{i(e)},[]),f=u(e=>{o(e)},[]),p=u(e=>{n(!0),o(null),i(e),c(null)},[]),m=u(()=>{n(!1),i(null),o(null),c(null)},[]),h=u(e=>{o(e.id),c(e)},[]),g=u(e=>{c(t=>t===null?t:{...t,...e})},[]),_=u(()=>{c(null)},[]),v=b(()=>({editing:t,drawingKind:r,selectedZoneId:a,editingDraft:s,setEditing:l,setDrawingKind:d,setSelectedZoneId:f,startDrawing:p,exitEditing:m,enterDraft:h,updateDraft:g,discardDraft:_}),[t,r,a,s,l,d,f,p,m,h,g,_]);return N(UB.Provider,{value:v,children:e})}function GB(){return p(UB)}h();var KB=500,qB=800;function JB(e,t,n){try{let r=e.live;if(!r)return null;let i=r.onEvent;return!i||typeof i.subscribe!=`function`?null:i.subscribe({category:t},{onData:n})}catch{return null}}function YB(e,t){return e?.id===t}function XB(e,t){let[n,r]=k(null),[i,a]=k(null),[o,s]=k(null),[c,l]=k(`watching`),u=f(void 0),d=f(void 0),p=f(void 0);return P(()=>{if(t===null)return;let n=JB(e,`detection.motion-analysis`,e=>{let n=e;if(!YB(n?.source,t))return;let i=n.data;!i?.regions||i.regions.length===0||(r({zones:i.regions.map(e=>({...e.bbox,intensity:e.intensity})),frameWidth:i.frameWidth,frameHeight:i.frameHeight}),u.current&&clearTimeout(u.current),u.current=setTimeout(()=>r(null),KB))});return()=>{n?.unsubscribe(),u.current&&clearTimeout(u.current)}},[e,t]),P(()=>{if(t===null)return;let n=JB(e,`detection.motion-zones-raw`,e=>{let n=e;if(!YB(n?.source,t))return;let r=n.data;r?.zones&&(a({boxes:r.zones.map(e=>({bbox:e.bbox,changeScore:e.changeScore})),frameWidth:r.frameSize?.width??0,frameHeight:r.frameSize?.height??0,motionScore:r.zones.length>0?r.zones.reduce((e,t)=>e+t.changeScore,0)/r.zones.length:0}),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>a(null),KB))});return()=>{n?.unsubscribe(),d.current&&clearTimeout(d.current)}},[e,t]),P(()=>{if(t===null)return;let n=JB(e,`detection.result`,e=>{let n=e;if(!YB(n?.source,t))return;let r=n.data?.frame;r?.detections?.length&&(s({detections:r.detections,frameWidth:r.width,frameHeight:r.height}),p.current&&clearTimeout(p.current),p.current=setTimeout(()=>s(null),qB))});return()=>{n?.unsubscribe(),p.current&&clearTimeout(p.current)}},[e,t]),P(()=>{if(t===null)return;let n=JB(e,`detection.phase-transition`,e=>{let n=e;YB(n?.source,t)&&n.data?.to&&l(n.data.to)});return()=>{n?.unsubscribe()}},[e,t]),{motion:n,motionRaw:i,detection:o,phase:c}}h();function ZB(e,t,n=5e3){let[r,i]=k([]);P(()=>{if(t===null)return;let r=!1,a=()=>{e.webrtcSession.listStreams.query({deviceId:t}).then(e=>{r||i(e)}).catch(()=>{})};a();let o=setInterval(a,n);return()=>{r=!0,clearInterval(o)}},[e,t,n]);let[a,o]=k(null);P(()=>{if(t===null)return;let n=!1;return e.pipelineOrchestrator&&e.pipelineOrchestrator.getCameraMetrics.query({deviceId:t}).then(e=>{n||!e||o({phase:e.phase,detectionFps:e.actualFps,avgInferenceMs:e.avgInferenceTimeMs,droppedFrames:e.droppedFrames})}).catch(()=>{}),()=>{n=!0}},[e,t]),il(`pipeline.camera-metrics-snapshot`,e=>{if(t===null)return;let n=e.data;n.deviceId!==t||!n.metrics||o({phase:n.metrics.phase,detectionFps:n.metrics.actualFps,avgInferenceMs:n.metrics.avgInferenceTimeMs,droppedFrames:n.metrics.droppedFrames})});let{streams:s,hasWebrtc:c}=b(()=>t===null||r.length===0?{streams:[],hasWebrtc:!1}:{streams:r.map(e=>({id:e.id,label:e.label,target:e.target,status:e.status,inputFps:e.inputFps,decodeFps:e.decodeFps,bitrateKbps:e.bitrateKbps})),hasWebrtc:!0},[t,r]),l=u(async()=>{if(e.turnProvider)try{return(await e.turnProvider.getTurnServers.query()).map(e=>({urls:typeof e.urls==`string`?e.urls:[...e.urls],...e.username===void 0?{}:{username:e.username},...e.credential===void 0?{}:{credential:e.credential}}))}catch{return}},[e]),d=u(async(n,r)=>{if(t===null)throw Error(`No device selected`);let i=await e.webrtcSession.createSession.mutate({deviceId:t,target:n,hints:r}),a=await l();return{sessionId:i.sessionId,sdpOffer:i.sdpOffer,...a?{iceServers:a}:{}}},[e,t,l]),f=u(async(n,r,i)=>{if(t===null)throw Error(`No device selected`);return e.webrtcSession.handleOffer.mutate({deviceId:t,target:n,sdpOffer:r,...i===void 0?{}:{sessionId:i}})},[e,t]),p=u(async(n,r)=>{if(t===null)throw Error(`No device selected`);await e.webrtcSession.handleAnswer.mutate({deviceId:t,sessionId:n,sdpAnswer:r})},[e,t]);return{streams:s,hasWebrtc:c,pipelineMetrics:a,createSession:d,handleOffer:f,getIceServers:l,addIceCandidate:u(async(n,r)=>{t!==null&&await e.webrtcSession.addIceCandidate.mutate({deviceId:t,sessionId:n,candidate:r.candidate??``,sdpMid:r.sdpMid??null,sdpMLineIndex:r.sdpMLineIndex??null}).catch(()=>{})},[e,t]),getIceCandidates:u(async n=>t===null?{candidates:[],done:!0}:e.webrtcSession.getIceCandidates.query({deviceId:t,sessionId:n}),[e,t]),sendAnswer:p,closeSession:u(async n=>{t!==null&&await e.webrtcSession.closeSession.mutate({deviceId:t,sessionId:n}).catch(()=>{})},[e,t]),getSessionState:u(async n=>{if(t===null)return{pendingRenegotiation:null};try{return await e.webrtcSession.getSessionState.query({deviceId:t,sessionId:n})}catch{return{pendingRenegotiation:null}}},[e,t])}}h();function QB(e){let t=e?.deviceId??null,n=e?.historyLimit??20,r=ol(`doorbell.onPressed`,t===null?void 0:e=>e.deviceId===t),[i,a]=k([]);return P(()=>{r&&a(e=>{if(e.length>0&&e[0].deviceId===r.deviceId&&e[0].timestamp===r.timestamp)return e;let t=[r,...e];return t.length>n?t.slice(0,n):t})},[r,n]),{latest:r??null,history:i}}h();function $B(e){let t=Ke(),n=b(()=>e?JSON.stringify(e):``,[e]),[r,i]=k(()=>t.listDevices(e));return P(()=>{let n=()=>{i(t.listDevices(e))};n();let r=null,a=null;try{r=t.onDeviceAdded(n),a=t.onDeviceRemoved(n)}catch{}let o=t.subscribeConnectionEvents(e=>{e===`connected`&&n()});return()=>{r?.(),a?.(),o()}},[t,e,n]),r}function eV(e){let t=Ke(),[n,r]=k(()=>e===null?null:t.getDevice(e));return P(()=>{if(e===null){r(null);return}let n=()=>{r(t.getDevice(e))};n();let i=null,a=null;try{i=t.onDeviceAdded(n),a=t.onDeviceRemoved(n)}catch{}let o=t.subscribeConnectionEvents(e=>{e===`connected`&&n()});return()=>{i?.(),a?.(),o()}},[t,e]),n}function tV(e,t,n){let r=Ke();return C({queryKey:e,queryFn:()=>t(r)(),...n})}function nV(e,t){let n=Ke();return A({mutationFn:t=>e(n)(t),...t})}h();function rV(e,t){let n=Ke(),r=O(),[i,a]=k(n.connectionVersion);P(()=>n.subscribeConnectionEvents((e,t)=>{e===`connected`&&a(t)}),[n]);let o=t.join(`|`),s=JSON.stringify(e);P(()=>{let e=[],t=()=>{let e=JSON.parse(s),t=e.length===1&&Array.isArray(e[0])?e:[e];r.invalidateQueries({queryKey:t})};t();for(let r of o.split(`|`))if(r)try{e.push(n.subscribeEvent(r,t))}catch{}return()=>{for(let t of e)t()}},[n,r,o,s,i])}h();function iV(e,t,n){let r=f(null),i=f(null);(r.current===null||i.current!==e)&&(r.current=de(e),i.current=e);let a=f(void 0),o=f(null),s=o.current;return t===null?(a.current=void 0,o.current=null):(a.current===void 0||s===null||s.source!==r.current||s.deviceId!==t||s.capName!==n)&&(a.current=W(r.current,t,n),o.current={source:r.current,deviceId:t,capName:n}),Xe(a.current)}var aV=e({AddonGlobalSettingsForm:()=>TR,AgentStepEditor:()=>Vc,AlarmHeroCard:()=>CO,AlarmPanelInlineControl:()=>SO,AppShell:()=>jl,ArcKnob:()=>fu,AudioClassificationList:()=>xz,AudioLevelWaveform:()=>vz,AudioWaveform:()=>_z,AutotrackSection:()=>NF,BTN_COMPACT:()=>Ze,BTN_COMPACT_DANGER:()=>et,BTN_COMPACT_PRIMARY:()=>Pe,BTN_COMPACT_WARNING:()=>$e,Badge:()=>_s,BatteryBadge:()=>VA,BottomSheet:()=>ic,Breadcrumb:()=>yc,BrightnessPanel:()=>BE,Button:()=>ps,ButtonControl:()=>mu,ButtonHeroCard:()=>hu,CENTER:()=>ru,CHIP_ACTIVE:()=>ke,CHIP_BASE:()=>ve,CHIP_INACTIVE:()=>Qe,CLASS_COLORS:()=>hM,COLUMN_BREAKPOINT_CLASS:()=>zl,COLUMN_PRIORITY:()=>Rl,COMMIT_DEDUPE_TOLERANCE_MS:()=>750,COMMIT_DEDUPE_WINDOW_MS:()=>qr,CONTROL_CAP_NAMES:()=>tM,CONTROL_FILLS:()=>lk,CameraStreamPlayer:()=>LR,Card:()=>ys,Checkbox:()=>Os,ChildSectionAccordion:()=>ej,ClimatePanel:()=>GE,CodeBlock:()=>Dl,CollapsibleCard:()=>bs,ConfigFormBuilder:()=>xR,ConfigFormField:()=>_R,ConfigSchemaField:()=>Mc,ConfirmActionButton:()=>OB,ConfirmDialogProvider:()=>wl,ConsumablesPanel:()=>jF,ContainerChildrenProvider:()=>iA,ContainerPrimaryHero:()=>oM,ControlColumn:()=>iu,ControlHeroCard:()=>BO,ControlInlineControl:()=>zO,ControlPanel:()=>CD,CopyButton:()=>oz,CoverHeroCard:()=>Du,CoverInlineControl:()=>Su,CoverPanel:()=>$j,CustomFieldRenderersProvider:()=>eF,DEFAULT_COLOR:()=>_M,DEVICE_COLUMNS:()=>Fl,DEVICE_LIST_PAGE_SIZE_KEY:()=>cj,DEVICE_LIST_PAGE_SIZE_OPTIONS:()=>sj,DEVICE_ROLE_META:()=>xk,DEVICE_TYPE_CONTROL:()=>ck,DEVICE_TYPE_META:()=>bk,DISPLAY_ICON_REGISTRY:()=>Mk,DataTable:()=>xc,DetectionCanvas:()=>yM,DetectionOverlay:()=>ER,DetectionResultTree:()=>wM,DevShell:()=>ZP,DeviceActivityPanel:()=>DB,DeviceBatchToolbar:()=>ij,DeviceCard:()=>Nl,DeviceContextProvider:()=>rF,DeviceExportPanel:()=>gz,DeviceGrid:()=>Pl,DeviceItem:()=>tj,DeviceList:()=>Qj,Dialog:()=>Ms,DialogContent:()=>Fs,DialogDescription:()=>zs,DialogFooter:()=>Ls,DialogHeader:()=>Is,DialogTitle:()=>Rs,DialogTrigger:()=>Ns,DiscoveryPanel:()=>eB,DoorbellRecentPanel:()=>MB,Dropdown:()=>Hs,DropdownContent:()=>Ws,DropdownItem:()=>Gs,DropdownTrigger:()=>Us,DummyHeroCard:()=>ku,DummyInline:()=>Ou,EmptyState:()=>yl,ErrorBox:()=>xl,EventStream:()=>Yz,FILL:()=>tu,FanHeroCard:()=>oO,FanInlineControl:()=>jO,FanPanel:()=>VE,FilterBar:()=>Ol,FloatingEventStream:()=>Zz,FloatingLogStream:()=>Pz,FloatingPanel:()=>_c,FormField:()=>_l,GRID_GAP:()=>Ae,GRID_PAIRED:()=>be,GRID_QUICK_STATS:()=>ye,GripTrack:()=>pu,GroupedModelSelector:()=>Fc,HOST_WIDGETS:()=>UI,HlsVideo:()=>UR,HoverZoomImage:()=>qA,HumidifierHeroCard:()=>YT,HumidifierInlineControl:()=>qT,INPUT_COMPACT:()=>Ee,IconAction:()=>vA,IconButton:()=>hs,ImageHeroCard:()=>bE,ImageInlineControl:()=>yE,ImageSelector:()=>AM,InferenceConfigSelector:()=>MM,Input:()=>Es,KebabMenu:()=>NB,KeyValueList:()=>El,LIST_ROW:()=>Ve,Label:()=>xs,LawnMowerHeroCard:()=>PT,LawnMowerInlineControl:()=>MT,LightHeroCard:()=>rO,LightInlineControl:()=>kO,LockHeroCard:()=>HD,LockInlineControl:()=>OO,LockPanel:()=>zE,LogStream:()=>Nz,LoginForm:()=>UP,MODE_COLOR:()=>HE,MaskShapeCanvas:()=>oV,MediaPlayerHeroCard:()=>pO,MediaPlayerInlineControl:()=>LO,MediaPlayerPanel:()=>gD,MobileDrawer:()=>vc,MotionZonesSettings:()=>sV,NodeMultiSelectField:()=>HL,NodePicker:()=>ll,NodeSelectField:()=>VL,OfflineBadge:()=>aM,PHASE_CONFIG:()=>kr,PRIORITY:()=>pk,PTZOverlay:()=>eu,PageHeader:()=>vl,PhaseIcon:()=>wz,PipelineBuilder:()=>mM,PipelineRuntimeSelector:()=>lM,PipelineStep:()=>Oc,PipelineTreeMatrix:()=>nl,PlayerOverlaysProvider:()=>Ye,Popover:()=>sc,PopoverContent:()=>lc,PopoverRowAction:()=>iM,PopoverTrigger:()=>cc,PrimaryChildPicker:()=>cM,PrivacyMaskSettings:()=>cV,ProviderBadge:()=>pl,PtzPanel:()=>EF,QrCode:()=>CL,RECORDED_PLAYBACK_MODES:()=>Vr,RIGHT:()=>nu,ROLE_DESCRIPTOR:()=>Rw,RadialGauge:()=>JD,RecordedPlaybackProvider:()=>iI,RecordingPanel:()=>HI,ResponseLog:()=>Sz,SECTION_BODY:()=>ge,SECTION_CARD:()=>Be,SECTION_HEADER:()=>we,SPLIT_PANEL_OUTER:()=>Te,SPLIT_PANEL_SIDE:()=>De,STACK_GAP:()=>xe,STATE_COLOR:()=>uD,ScopePicker:()=>BB,ScrollArea:()=>gc,Select:()=>Ds,SemanticBadge:()=>hl,SensorHeroCard:()=>nT,SensorInlineControl:()=>qw,SensorValueAtom:()=>Gw,Separator:()=>Cs,Sidebar:()=>Al,SidebarItem:()=>kl,Skeleton:()=>ws,SlideOverPanel:()=>Sc,SlideToggle:()=>su,SnapshotButton:()=>AB,StatCard:()=>Tl,StateValuesStream:()=>uB,StatusBadge:()=>dl,StepTimings:()=>kM,StepTreeMaster:()=>Tc,Stepper:()=>ou,StreamBrokerSelector:()=>iz,StreamPanel:()=>ez,Switch:()=>ks,SwitchHeroCard:()=>sO,SwitchInlineControl:()=>EO,SwitchPanel:()=>LE,SystemProvider:()=>Ie,TEXT_FIELD_LABEL:()=>Se,TEXT_HINT:()=>Ce,TEXT_METRIC:()=>Oe,TEXT_SECTION_LABEL:()=>tt,TEXT_VALUE:()=>_e,TIMEZONES:()=>te,Tabs:()=>fc,TabsContent:()=>hc,TabsList:()=>pc,TabsTrigger:()=>mc,TapToggle:()=>YD,ThemeProvider:()=>Nt,ThermostatHeroCard:()=>FD,ThermostatInlineControl:()=>NO,TimezoneSelector:()=>TL,Tooltip:()=>Js,TooltipContent:()=>Xs,TooltipTrigger:()=>Ys,VacuumHeroCard:()=>xT,VacuumInlineControl:()=>yT,ValueReadout:()=>au,ValveHeroCard:()=>WT,ValveInlineControl:()=>zT,VersionBadge:()=>gl,VodPlaybackProvider:()=>tI,WaterHeaterHeroCard:()=>tE,WaterHeaterInlineControl:()=>$T,WeatherHeroCard:()=>fE,WeatherInlineControl:()=>sE,WidgetMetricCard:()=>Ge,WidgetPanel:()=>Je,WidgetRegistryProvider:()=>_F,WidgetSlot:()=>WI,ZoneEditingProvider:()=>WB,allDeviceTypeFilterOptions:()=>Fk,buildStepTreeFromSchema:()=>Ec,childEntityId:()=>gk,childListName:()=>Hk,cn:()=>X,columnsForContext:()=>Ll,containerChildToRef:()=>_k,countableDevices:()=>mj,coverHighlight:()=>yu,createSharedContext:()=>Me,createTheme:()=>bt,cursorFractionFor:()=>Yr,darkColors:()=>gt,defaultTheme:()=>vt,deriveDeviceKind:()=>Ik,deviceRoleMeta:()=>Dk,deviceRoleMetaOf:()=>jk,deviceTypeMeta:()=>Ek,deviceTypeMetaOf:()=>Ak,ensureMfHostInit:()=>zr,findTimezone:()=>V,formatControlDateTime:()=>br,formatLastSeen:()=>mr,formatNumeric:()=>xr,fuzzyMatch:()=>vj,getClassColor:()=>vM,getPhaseVisual:()=>Ar,groupChildrenByLayout:()=>QA,hardwareLabel:()=>Wl,humidifierTint:()=>GT,initialScrubState:()=>Wr,isAbsentProvider:()=>je,isFieldVisible:()=>gR,lawnMowerActivityMeta:()=>ST,lightColors:()=>_t,loadRemoteBundle:()=>pF,makeScrubBridge:()=>Xr,metadataEntries:()=>Gl,metadataString:()=>Ul,mirror:()=>Or,mountAddonPage:()=>QP,nextSort:()=>Kj,normalizeForSearch:()=>_j,overrideEntityIdFromLink:()=>vk,parseRecordedServerMessage:()=>Ur,providerIcons:()=>ss,resolveContainerPrimary:()=>yk,resolveControlAlign:()=>fk,resolveDeviceControl:()=>dk,resolveDisplayIcon:()=>Nk,resolvePrimaryChild:()=>mk,resolveSensorDisplay:()=>Cr,scrubReducer:()=>Gr,serializeRecordedCommand:()=>Br,shouldCommit:()=>Jr,shouldEmit:()=>Kr,sortRows:()=>qj,statusIcons:()=>cs,stripParentNamePrefix:()=>Vk,tankAlert:()=>hT,themeToCss:()=>Dt,trpc:()=>Z,useAccessoriesGetStatus:()=>ju,useAccessoriesSetChildHidden:()=>Au,useAddonPagesListPages:()=>Mu,useAddonSettingsGetDeviceSettings:()=>hd,useAddonSettingsGetGlobalSettings:()=>pd,useAddonSettingsUpdateDeviceSettings:()=>gd,useAddonSettingsUpdateGlobalSettings:()=>md,useAddonWidgetsListWidgets:()=>_d,useAddonsApplyAutoUpdateToAll:()=>od,useAddonsCancelJob:()=>dd,useAddonsCustom:()=>sd,useAddonsForceRefresh:()=>Ku,useAddonsGetAddonAutoUpdate:()=>id,useAddonsGetAutoUpdateSettings:()=>nd,useAddonsGetJob:()=>ld,useAddonsGetLastRestart:()=>Ju,useAddonsGetLogs:()=>Pu,useAddonsGetVersions:()=>$u,useAddonsInstallFromWorkspace:()=>Lu,useAddonsInstallPackage:()=>Iu,useAddonsIsWorkspaceAvailable:()=>Ru,useAddonsList:()=>Nu,useAddonsListCapabilityProviders:()=>Xu,useAddonsListFrameworkPackages:()=>Yu,useAddonsListJobs:()=>ud,useAddonsListPackages:()=>Fu,useAddonsListUpdates:()=>Uu,useAddonsListWorkspacePackages:()=>zu,useAddonsOnAddonLogs:()=>fd,useAddonsReloadPackages:()=>Vu,useAddonsRestartAddon:()=>ed,useAddonsRestartServer:()=>qu,useAddonsRetryLoad:()=>td,useAddonsRollbackPackage:()=>Gu,useAddonsSearchAvailable:()=>Hu,useAddonsSetAddonAutoUpdate:()=>ad,useAddonsSetAutoUpdateSettings:()=>rd,useAddonsSetCapabilityProviderEnabled:()=>Zu,useAddonsStartJob:()=>cd,useAddonsUninstallPackage:()=>Bu,useAddonsUpdateFrameworkPackage:()=>Qu,useAddonsUpdatePackage:()=>Wu,useAirQualitySensorGetStatus:()=>vd,useAlarmPanelArm:()=>yd,useAlarmPanelDisarm:()=>bd,useAlarmPanelGetStatus:()=>Sd,useAlarmPanelTrigger:()=>xd,useAlertsDismiss:()=>kd,useAlertsEmit:()=>Cd,useAlertsGetUnreadCount:()=>Ed,useAlertsList:()=>Td,useAlertsMarkAllRead:()=>Od,useAlertsMarkRead:()=>Dd,useAlertsUpdate:()=>wd,useAllWidgets:()=>bF,useAmbientLightSensorGetStatus:()=>Ad,useAudioAnalysisApplyDeviceSettingsPatch:()=>Pd,useAudioAnalysisGetDeviceLiveContribution:()=>Nd,useAudioAnalysisGetDeviceSettingsContribution:()=>Md,useAudioAnalysisResolveDeviceSettings:()=>jd,useAudioAnalyzerAnalyseChunk:()=>Fd,useAudioAnalyzerClassify:()=>Id,useAudioAnalyzerDispose:()=>Rd,useAudioAnalyzerIsReady:()=>Ld,useAudioAnalyzerReprobeAudioEngine:()=>zd,useAudioCodecCanHandle:()=>Vd,useAudioCodecCloseSession:()=>Wd,useAudioCodecCreateDecodeSession:()=>Hd,useAudioCodecCreateEncodeSession:()=>Ud,useAudioCodecFlushEncode:()=>Yd,useAudioCodecListActiveSessions:()=>Xd,useAudioCodecListSupportedCodecs:()=>Bd,useAudioCodecPullEncoded:()=>Jd,useAudioCodecPullPcm:()=>Kd,useAudioCodecPushEncodedFrame:()=>Gd,useAudioCodecPushPcm:()=>qd,useAudioMetricsGetCurrentSnapshot:()=>Zd,useAudioMetricsGetHistory:()=>Qd,useAutomationControlDisable:()=>ef,useAutomationControlEnable:()=>$d,useAutomationControlGetStatus:()=>nf,useAutomationControlTrigger:()=>tf,useBackupDelete:()=>uf,useBackupGetEntries:()=>cf,useBackupList:()=>of,useBackupListArchives:()=>df,useBackupListDestinations:()=>rf,useBackupListLocations:()=>sf,useBackupPreviewSchedule:()=>pf,useBackupRestore:()=>lf,useBackupTrigger:()=>af,useBackupUpsertDestinationPolicy:()=>ff,useBatteryGetStatus:()=>hf,useBatteryWakeForStream:()=>mf,useBinaryGetStatus:()=>gf,useBrightnessGetStatus:()=>vf,useBrightnessSetBrightness:()=>_f,useBrokerAdd:()=>Sf,useBrokerGet:()=>bf,useBrokerGetBrokerConfig:()=>Df,useBrokerGetSettings:()=>Tf,useBrokerGetSettingsSchema:()=>Of,useBrokerGetState:()=>Nf,useBrokerGetStatus:()=>Pf,useBrokerList:()=>yf,useBrokerListProviders:()=>xf,useBrokerPublish:()=>Af,useBrokerRemove:()=>Cf,useBrokerSetSettings:()=>Ef,useBrokerSubscribe:()=>jf,useBrokerTestConnection:()=>wf,useBrokerTestSettings:()=>kf,useBrokerUnsubscribe:()=>Mf,useButtonPress:()=>Ff,useCameraCredentialsGetCredentials:()=>If,useCameraCredentialsGetStatus:()=>Lf,useCameraPipelineConfigApplyDeviceSettingsPatch:()=>Bf,useCameraPipelineConfigGetDeviceLiveContribution:()=>zf,useCameraPipelineConfigGetDeviceSettingsContribution:()=>Rf,useCameraStreamsGetBrokerStreams:()=>Hf,useCameraStreamsGetCameraStreams:()=>Vf,useCameraStreamsGetProfileRtspEntries:()=>Wf,useCameraStreamsGetRtspEntries:()=>Uf,useCameraStreamsPickStream:()=>Gf,useCarbonMonoxideGetStatus:()=>Kf,useClimateControlGetStatus:()=>tp,useClimateControlSetFanMode:()=>Jf,useClimateControlSetMode:()=>qf,useClimateControlSetPreset:()=>Yf,useClimateControlSetSwingHorizontal:()=>ep,useClimateControlSetSwingVertical:()=>$f,useClimateControlSetTarget:()=>Xf,useClimateControlSetTargetHumidity:()=>Qf,useClimateControlSetTargetRange:()=>Zf,useClusterNodes:()=>cl,useColorGetStatus:()=>rp,useColorSetColor:()=>np,useConfirm:()=>Cl,useConnectivityGetStatus:()=>ip,useConsumablesGetStatus:()=>op,useConsumablesReset:()=>ap,useContactGetStatus:()=>sp,useContainerChildren:()=>aA,useControlGetStatus:()=>lp,useControlSetValue:()=>cp,useCoverClose:()=>dp,useCoverGetStatus:()=>hp,useCoverOpen:()=>up,useCoverSetPosition:()=>pp,useCoverSetTiltPosition:()=>mp,useCoverStop:()=>fp,useCustomFieldRenderer:()=>tF,useDayNightGetOptions:()=>gp,useDayNightGetStatus:()=>vp,useDayNightSetSettings:()=>_p,useDebouncedString:()=>oj,useDecoderCreateSession:()=>xp,useDecoderDestroySession:()=>Sp,useDecoderGetFrame:()=>Dp,useDecoderGetInfo:()=>bp,useDecoderGetShmStats:()=>Op,useDecoderGetStats:()=>Ap,useDecoderListActiveSessions:()=>jp,useDecoderOpenStream:()=>wp,useDecoderPullFrames:()=>Tp,useDecoderPullHandles:()=>Ep,useDecoderPushPacket:()=>Cp,useDecoderReprobeHwaccel:()=>Mp,useDecoderSupportsCodec:()=>yp,useDecoderUpdateConfig:()=>kp,useDetectionPipelineApplyDeviceSettingsPatch:()=>Fp,useDetectionPipelineGetDeviceLiveContribution:()=>Pp,useDetectionPipelineGetDeviceSettingsContribution:()=>Np,useDevShell:()=>KP,useDevice:()=>eV,useDeviceAdoptionAdopt:()=>Bp,useDeviceAdoptionGetCandidate:()=>Rp,useDeviceAdoptionGetStatus:()=>Up,useDeviceAdoptionListCandidateFilters:()=>Ip,useDeviceAdoptionListCandidates:()=>Lp,useDeviceAdoptionRefresh:()=>zp,useDeviceAdoptionRelease:()=>Vp,useDeviceAdoptionResync:()=>Hp,useDeviceAutotrack:()=>MF,useDeviceBattery:()=>IA,useDeviceCapSlice:()=>iV,useDeviceCapability:()=>Q,useDeviceDetections:()=>XB,useDeviceDiscoveryAdoptDevice:()=>Kp,useDeviceDiscoveryGetStatus:()=>Jp,useDeviceDiscoveryListDiscovered:()=>Wp,useDeviceDiscoveryRefreshDiscovery:()=>Gp,useDeviceDiscoveryReleaseDevice:()=>qp,useDeviceExportApplyDeviceSettingsPatch:()=>nm,useDeviceExportExposeDevice:()=>Qp,useDeviceExportGetDeviceLiveContribution:()=>tm,useDeviceExportGetDeviceSettingsContribution:()=>em,useDeviceExportGetStatus:()=>Yp,useDeviceExportListExposedDevices:()=>Zp,useDeviceExportListSupportedDeviceKinds:()=>Xp,useDeviceExportUnexposeDevice:()=>$p,useDeviceId:()=>iF,useDeviceListPageSize:()=>pj,useDeviceManagerAddLocation:()=>Em,useDeviceManagerAdoptDevice:()=>nh,useDeviceManagerAdoptionAdopt:()=>lh,useDeviceManagerAdoptionListCandidateFilters:()=>oh,useDeviceManagerAdoptionListCandidates:()=>sh,useDeviceManagerAdoptionRefresh:()=>ch,useDeviceManagerAdoptionRelease:()=>uh,useDeviceManagerAdoptionResync:()=>dh,useDeviceManagerAllocateDeviceId:()=>rm,useDeviceManagerApplyInitialMeta:()=>Cm,useDeviceManagerCreateDevice:()=>ih,useDeviceManagerDisable:()=>Rm,useDeviceManagerDiscoverAllProviders:()=>ph,useDeviceManagerDiscoverDevices:()=>th,useDeviceManagerDiscoverProvider:()=>mh,useDeviceManagerDiscoveryProviders:()=>fh,useDeviceManagerEnable:()=>Lm,useDeviceManagerGetAllBindings:()=>Gm,useDeviceManagerGetBindings:()=>Wm,useDeviceManagerGetChildren:()=>Mm,useDeviceManagerGetConfigSchema:()=>Pm,useDeviceManagerGetCreationSchema:()=>rh,useDeviceManagerGetDevice:()=>jm,useDeviceManagerGetDeviceAggregate:()=>Zm,useDeviceManagerGetDeviceLiveInfoAggregate:()=>Xm,useDeviceManagerGetDeviceSettingsAggregate:()=>Ym,useDeviceManagerGetDeviceStatusAggregate:()=>vh,useDeviceManagerGetRoleDisplayDefaults:()=>ym,useDeviceManagerGetSettingsSchema:()=>Fm,useDeviceManagerGetStreamProfileMap:()=>Vm,useDeviceManagerGetStreamSources:()=>Nm,useDeviceManagerGetWireableFields:()=>xm,useDeviceManagerListAll:()=>Am,useDeviceManagerListBindableCapsForDeviceType:()=>Jm,useDeviceManagerListLocations:()=>Tm,useDeviceManagerListPersistedByAddon:()=>km,useDeviceManagerListWrappersForCap:()=>qm,useDeviceManagerLoadConfig:()=>sm,useDeviceManagerLoadMeta:()=>lm,useDeviceManagerLoadRuntimeState:()=>cm,useDeviceManagerPersistConfig:()=>om,useDeviceManagerProbeStreams:()=>Um,useDeviceManagerProviderCreationType:()=>hh,useDeviceManagerProviderDiscoveryParamsSchema:()=>gh,useDeviceManagerRegisterDevice:()=>im,useDeviceManagerRemove:()=>zm,useDeviceManagerRemoveByIntegration:()=>Bm,useDeviceManagerRemoveDevice:()=>am,useDeviceManagerRemoveLocation:()=>Dm,useDeviceManagerRunDeviceAction:()=>Qm,useDeviceManagerSetChildLayout:()=>gm,useDeviceManagerSetDeviceLinks:()=>_m,useDeviceManagerSetDisabled:()=>Om,useDeviceManagerSetDisplay:()=>vm,useDeviceManagerSetIntegrationId:()=>pm,useDeviceManagerSetLinkDeviceId:()=>mm,useDeviceManagerSetLocation:()=>dm,useDeviceManagerSetMetadata:()=>wm,useDeviceManagerSetName:()=>um,useDeviceManagerSetPrimaryChildEntityId:()=>hm,useDeviceManagerSetRole:()=>Sm,useDeviceManagerSetRoleDisplayDefaults:()=>bm,useDeviceManagerSetStreamProfileMap:()=>Hm,useDeviceManagerSetType:()=>fm,useDeviceManagerSetWrapperActive:()=>Km,useDeviceManagerTestCreationField:()=>ah,useDeviceManagerTestField:()=>_h,useDeviceManagerUpdateConfig:()=>Im,useDeviceManagerUpdateDeviceField:()=>$m,useDeviceManagerUpdateDeviceFieldsBatch:()=>eh,useDeviceOpsGetConfigEntries:()=>bh,useDeviceOpsGetRawState:()=>Th,useDeviceOpsGetSettingsSchema:()=>wh,useDeviceOpsGetStreamSources:()=>yh,useDeviceOpsRemoveDevice:()=>Ch,useDeviceOpsRunAction:()=>Sh,useDeviceOpsSetConfig:()=>xh,useDeviceProviderAdoptDiscoveredDevice:()=>Ph,useDeviceProviderCreateDevice:()=>Lh,useDeviceProviderDiscoverDevices:()=>jh,useDeviceProviderGetChildCreationSchema:()=>Ih,useDeviceProviderGetDevices:()=>kh,useDeviceProviderGetDiscoveryParamsSchema:()=>Mh,useDeviceProviderGetManualCreationType:()=>Nh,useDeviceProviderGetStatus:()=>Oh,useDeviceProviderStart:()=>Eh,useDeviceProviderStop:()=>Dh,useDeviceProviderSupportsDiscovery:()=>Ah,useDeviceProviderSupportsManualCreation:()=>Fh,useDeviceProviderTestCreationField:()=>Rh,useDeviceProxy:()=>Fe,useDeviceSnapshot:()=>aF,useDeviceSnapshotImage:()=>LA,useDeviceState:()=>He,useDeviceStateGetAllSnapshots:()=>Vh,useDeviceStateGetCapSlice:()=>Bh,useDeviceStateGetSnapshot:()=>zh,useDeviceStateSetCapSlice:()=>Hh,useDeviceStateSlice:()=>Xe,useDeviceStatusGetStatus:()=>Uh,useDeviceWebrtc:()=>ZB,useDevices:()=>$B,useDoorbellEvents:()=>QB,useDoorbellGetStatus:()=>Wh,useEnumSensorGetStatus:()=>Gh,useEventEmitterGetStatus:()=>Kh,useEventInvalidation:()=>rV,useEventStreamLatest:()=>ol,useEventStreamMap:()=>sl,useEventsGetEventClipUrl:()=>Yh,useEventsGetEventThumbnail:()=>Jh,useEventsGetEvents:()=>qh,useFaceGalleryAssignFace:()=>ag,useFaceGalleryAssignFaces:()=>cg,useFaceGalleryCreateIdentity:()=>Zh,useFaceGalleryDeleteFace:()=>sg,useFaceGalleryDeleteIdentity:()=>$h,useFaceGalleryGetFaceByTrack:()=>rg,useFaceGalleryGetFaceMedia:()=>ig,useFaceGalleryListIdentities:()=>Xh,useFaceGalleryListIdentitySamples:()=>eg,useFaceGalleryListRecentFaces:()=>ng,useFaceGalleryRemoveSample:()=>tg,useFaceGalleryRenameIdentity:()=>Qh,useFaceGallerySuggestFaceClusters:()=>ug,useFaceGalleryUnassignFace:()=>og,useFaceGalleryUnassignFaces:()=>lg,useFanControlGetStatus:()=>hg,useFanControlSetDirection:()=>pg,useFanControlSetOscillating:()=>mg,useFanControlSetPercentage:()=>dg,useFanControlSetPreset:()=>fg,useFeatureProbeGetStatus:()=>gg,useFloodGetStatus:()=>_g,useGasGetStatus:()=>vg,useHumidifierGetStatus:()=>Sg,useHumidifierSetMode:()=>xg,useHumidifierSetOn:()=>yg,useHumidifierSetTargetHumidity:()=>bg,useHumiditySensorGetStatus:()=>Cg,useImageGetStatus:()=>wg,useImageSettingsGetOptions:()=>Tg,useImageSettingsGetStatus:()=>Dg,useImageSettingsSetSettings:()=>Eg,useIntegrationsCreate:()=>jg,useIntegrationsDelete:()=>Ng,useIntegrationsGet:()=>kg,useIntegrationsGetAvailableTypes:()=>Ig,useIntegrationsGetByAddonId:()=>Ag,useIntegrationsGetSettings:()=>Pg,useIntegrationsList:()=>Og,useIntegrationsSetSettings:()=>Fg,useIntegrationsTestConnection:()=>Lg,useIntegrationsUpdate:()=>Mg,useIntercomEndTalkSession:()=>Ug,useIntercomGetStatus:()=>Wg,useIntercomHandleAnswer:()=>zg,useIntercomPushTalkAudio:()=>Hg,useIntercomStartSession:()=>Rg,useIntercomStartTalkSession:()=>Vg,useIntercomStopSession:()=>Bg,useIsMidWidth:()=>rc,useIsMobile:()=>nc,useLawnMowerControlDock:()=>qg,useLawnMowerControlGetStatus:()=>Jg,useLawnMowerControlPause:()=>Kg,useLawnMowerControlStartMowing:()=>Gg,useLiveBuffer:()=>Tz,useLiveEvent:()=>il,useLocalNetworkGetAllowedAddresses:()=>Qg,useLocalNetworkGetConnectionEndpoints:()=>Zg,useLocalNetworkGetPreferred:()=>Xg,useLocalNetworkList:()=>Yg,useLocalNetworkResetAllowlistToBestMatch:()=>e_,useLocalNetworkSetAllowedAddresses:()=>$g,useLockControlGetStatus:()=>i_,useLockControlLock:()=>t_,useLockControlOpen:()=>r_,useLockControlUnlock:()=>n_,useMediaPlayerGetStatus:()=>__,useMediaPlayerNext:()=>c_,useMediaPlayerPause:()=>o_,useMediaPlayerPlay:()=>a_,useMediaPlayerPlayMedia:()=>g_,useMediaPlayerPrevious:()=>l_,useMediaPlayerSeek:()=>u_,useMediaPlayerSelectSource:()=>h_,useMediaPlayerSetMute:()=>f_,useMediaPlayerSetRepeat:()=>m_,useMediaPlayerSetShuffle:()=>p_,useMediaPlayerSetVolume:()=>d_,useMediaPlayerStop:()=>s_,useMeshNetworkGetStatus:()=>v_,useMeshNetworkJoin:()=>y_,useMeshNetworkLeave:()=>x_,useMeshNetworkListPeers:()=>C_,useMeshNetworkLogout:()=>S_,useMeshNetworkStartLogin:()=>b_,useMeshNetworkTestConnection:()=>w_,useMetricsProviderCollectSnapshot:()=>T_,useMetricsProviderDumpHeapSnapshot:()=>I_,useMetricsProviderGetAddonStats:()=>N_,useMetricsProviderGetCached:()=>E_,useMetricsProviderGetCpuTemperature:()=>A_,useMetricsProviderGetCurrent:()=>D_,useMetricsProviderGetDiskSpace:()=>O_,useMetricsProviderGetGpuInfo:()=>k_,useMetricsProviderGetProcessStats:()=>j_,useMetricsProviderKillProcess:()=>F_,useMetricsProviderListAddonInstances:()=>M_,useMetricsProviderListNodeProcesses:()=>P_,useMotionDetectionAnalyze:()=>z_,useMotionDetectionApplyDeviceSettingsPatch:()=>W_,useMotionDetectionGetDeviceLiveContribution:()=>U_,useMotionDetectionGetDeviceSettingsContribution:()=>H_,useMotionDetectionRemoveCamera:()=>B_,useMotionDetectionReset:()=>V_,useMotionGetStatus:()=>R_,useMotionIsDetected:()=>L_,useMotionTriggerGetStatus:()=>K_,useMotionTriggerSetMotionTrigger:()=>G_,useMotionZonesGetOptions:()=>q_,useMotionZonesGetStatus:()=>Y_,useMotionZonesSetZone:()=>J_,useMqttBrokerAddBroker:()=>Q_,useMqttBrokerGetBrokerConfig:()=>Z_,useMqttBrokerGetStatus:()=>rv,useMqttBrokerListBrokers:()=>X_,useMqttBrokerRemoveBroker:()=>$_,useMqttBrokerStartEmbeddedBroker:()=>tv,useMqttBrokerStopEmbeddedBroker:()=>nv,useMqttBrokerTestConnection:()=>ev,useNativeObjectDetectionGetStatus:()=>av,useNativeObjectDetectionSetEnabled:()=>iv,useNetworkAccessGetEndpoint:()=>cv,useNetworkAccessGetStatus:()=>lv,useNetworkAccessListEndpoints:()=>uv,useNetworkAccessStart:()=>ov,useNetworkAccessStop:()=>sv,useNetworkQualityGetAllStats:()=>fv,useNetworkQualityGetDeviceStats:()=>dv,useNetworkQualityReportClientStats:()=>pv,useNodesClusterAddonStatus:()=>Sv,useNodesDeployAddon:()=>hv,useNodesExecuteQuery:()=>Ev,useNodesGetCapUsageGraph:()=>Cv,useNodesGetNodeAddons:()=>wv,useNodesRenameNode:()=>xv,useNodesRestartAddon:()=>_v,useNodesRestartNode:()=>yv,useNodesRestartProcess:()=>vv,useNodesSetProcessLogLevel:()=>Tv,useNodesShutdownNode:()=>bv,useNodesTopology:()=>mv,useNodesUndeployAddon:()=>gv,useNotificationOutputDeleteTarget:()=>Nv,useNotificationOutputDiscoverTargets:()=>kv,useNotificationOutputListTargetKinds:()=>Dv,useNotificationOutputListTargets:()=>Ov,useNotificationOutputSend:()=>Av,useNotificationOutputSetTargetEnabled:()=>Pv,useNotificationOutputTestTarget:()=>jv,useNotificationOutputUpsertTarget:()=>Mv,useNotifierCancel:()=>Iv,useNotifierGetStatus:()=>Lv,useNotifierSend:()=>Fv,useNumericSensorGetStatus:()=>Rv,useOptimisticSlice:()=>vu,useOptionalSystem:()=>Le,useOptionalWidgetRegistry:()=>CF,useOsdGetStatus:()=>Bv,useOsdSetOverlay:()=>zv,usePTZ:()=>Ql,usePetFeederCallPet:()=>Gv,usePetFeederCancelFeed:()=>Hv,usePetFeederFeed:()=>Vv,usePetFeederGetStatus:()=>Zv,usePetFeederMarkFoodReplenished:()=>Wv,usePetFeederPlaySound:()=>Kv,usePetFeederResetDesiccant:()=>Uv,usePetFeederSetChildLock:()=>qv,usePetFeederSetFeedSound:()=>Yv,usePetFeederSetIndicatorLight:()=>Jv,usePetFeederSetVolume:()=>Xv,usePipelineAnalyticsApplyDeviceSettingsPatch:()=>fy,usePipelineAnalyticsClearTracks:()=>ty,usePipelineAnalyticsGetActiveTracks:()=>Qv,usePipelineAnalyticsGetAudioEvents:()=>iy,usePipelineAnalyticsGetDeviceLiveContribution:()=>dy,usePipelineAnalyticsGetDeviceSettingsContribution:()=>uy,usePipelineAnalyticsGetEventDensity:()=>ay,usePipelineAnalyticsGetEventMedia:()=>sy,usePipelineAnalyticsGetMotionEvents:()=>ny,usePipelineAnalyticsGetObjectEvents:()=>ry,usePipelineAnalyticsGetTrack:()=>$v,usePipelineAnalyticsGetTrackMedia:()=>cy,usePipelineAnalyticsListTracks:()=>ey,usePipelineAnalyticsPruneEventsBefore:()=>oy,usePipelineAnalyticsSearchObjectEvents:()=>ly,usePipelineExecutorCacheFrameInPool:()=>Iy,usePipelineExecutorClearDeviceOverrides:()=>by,usePipelineExecutorDeleteModel:()=>Ny,usePipelineExecutorDeleteTemplate:()=>ky,usePipelineExecutorDownloadModel:()=>My,usePipelineExecutorGetAddonModels:()=>jy,usePipelineExecutorGetAudioCapabilities:()=>qy,usePipelineExecutorGetAvailableEngines:()=>py,usePipelineExecutorGetCapabilities:()=>Ay,usePipelineExecutorGetDefaultSteps:()=>hy,usePipelineExecutorGetDetectionConfigSchema:()=>Yy,usePipelineExecutorGetEffectiveTuning:()=>zy,usePipelineExecutorGetEngineProvisioning:()=>_y,usePipelineExecutorGetGlobalPipelineConfig:()=>Cy,usePipelineExecutorGetGlobalSteps:()=>Sy,usePipelineExecutorGetOrchestratorConfigSchema:()=>wy,usePipelineExecutorGetReferenceAudio:()=>Ky,usePipelineExecutorGetReferenceAudioFiles:()=>Gy,usePipelineExecutorGetReferenceImage:()=>Wy,usePipelineExecutorGetSchema:()=>xy,usePipelineExecutorGetSelectedEngine:()=>my,usePipelineExecutorGetVideoPipelineSteps:()=>vy,usePipelineExecutorInferCached:()=>Ly,usePipelineExecutorKillEngine:()=>Hy,usePipelineExecutorListLoadedEngines:()=>By,usePipelineExecutorListReferenceImages:()=>Uy,usePipelineExecutorListTemplates:()=>Ey,usePipelineExecutorReprobeEngine:()=>gy,usePipelineExecutorRunAudioTest:()=>Jy,usePipelineExecutorRunPipeline:()=>Py,usePipelineExecutorRunPipelineBatch:()=>Fy,usePipelineExecutorSaveTemplate:()=>Dy,usePipelineExecutorSetVideoPipelineSteps:()=>yy,usePipelineExecutorSpinEngine:()=>Vy,usePipelineExecutorUncacheFrame:()=>Ry,usePipelineExecutorUpdateTemplate:()=>Oy,usePipelineExecutorValidatePipeline:()=>Ty,usePipelineOrchestratorApplyDeviceSettingsPatch:()=>Fb,usePipelineOrchestratorAssignAudio:()=>sb,usePipelineOrchestratorAssignPipeline:()=>Xy,usePipelineOrchestratorDeleteTemplate:()=>Mb,usePipelineOrchestratorGetAgentLoad:()=>tb,usePipelineOrchestratorGetAgentSettings:()=>fb,usePipelineOrchestratorGetAudioAssignment:()=>lb,usePipelineOrchestratorGetAudioAssignments:()=>db,usePipelineOrchestratorGetAudioNodeLoad:()=>ub,usePipelineOrchestratorGetCameraMetrics:()=>rb,usePipelineOrchestratorGetCameraSettings:()=>xb,usePipelineOrchestratorGetCameraStatus:()=>Db,usePipelineOrchestratorGetCameraStatuses:()=>Ob,usePipelineOrchestratorGetCameraStepOverrides:()=>Cb,usePipelineOrchestratorGetCapabilityBindings:()=>ib,usePipelineOrchestratorGetDeviceLiveContribution:()=>Pb,usePipelineOrchestratorGetDeviceSettingsContribution:()=>Nb,usePipelineOrchestratorGetGlobalMetrics:()=>nb,usePipelineOrchestratorGetIngestOwner:()=>ob,usePipelineOrchestratorGetPipelineAssignment:()=>eb,usePipelineOrchestratorGetPipelineAssignments:()=>$y,usePipelineOrchestratorListAgentSettings:()=>pb,usePipelineOrchestratorListTemplates:()=>kb,usePipelineOrchestratorRebalance:()=>Qy,usePipelineOrchestratorRemoveAgentSettings:()=>hb,usePipelineOrchestratorResetNodePipelineDefaults:()=>bb,usePipelineOrchestratorResolvePipeline:()=>Eb,usePipelineOrchestratorSaveTemplate:()=>Ab,usePipelineOrchestratorSetAgentAddonDefaults:()=>mb,usePipelineOrchestratorSetAgentCapabilities:()=>vb,usePipelineOrchestratorSetAgentDetectWeight:()=>_b,usePipelineOrchestratorSetAgentMaxCameras:()=>gb,usePipelineOrchestratorSetAgentReachableHost:()=>yb,usePipelineOrchestratorSetCameraPipelineForAgent:()=>Tb,usePipelineOrchestratorSetCameraStepOverride:()=>wb,usePipelineOrchestratorSetCameraStepToggle:()=>Sb,usePipelineOrchestratorSetCapabilityBinding:()=>ab,usePipelineOrchestratorUnassignAudio:()=>cb,usePipelineOrchestratorUnassignPipeline:()=>Zy,usePipelineOrchestratorUpdateTemplate:()=>jb,usePipelineRunnerAttachCamera:()=>Ib,usePipelineRunnerDetachCamera:()=>Lb,usePipelineRunnerGetAllCameraMetrics:()=>Hb,usePipelineRunnerGetCameraMetrics:()=>Vb,usePipelineRunnerGetLocalCameras:()=>Ub,usePipelineRunnerGetLocalLoad:()=>zb,usePipelineRunnerGetLocalMetrics:()=>Bb,usePipelineRunnerReportMotion:()=>Rb,usePlateGalleryCorrectPlateText:()=>Yb,usePlateGalleryDeletePlate:()=>Xb,usePlateGalleryGetPlateByTrack:()=>Gb,usePlateGalleryGetPlateMedia:()=>Kb,usePlateGalleryListPlates:()=>Wb,usePlateGallerySearchPlates:()=>qb,usePlateGallerySuggestPlateClusters:()=>Jb,usePlayerOverlayLayer:()=>We,usePlayerOverlayLayers:()=>qe,usePlayerToolbarButton:()=>ze,usePlayerToolbarButtons:()=>Ne,usePowerMeterGetStatus:()=>Zb,usePresenceGetStatus:()=>Qb,usePressureSensorGetStatus:()=>$b,usePrivacyMaskGetOptions:()=>ex,usePrivacyMaskGetStatus:()=>nx,usePrivacyMaskSetMask:()=>tx,usePtzAutotrackGetSettings:()=>_x,usePtzAutotrackGetStatus:()=>hx,usePtzAutotrackSetEnabled:()=>gx,usePtzAutotrackSetSettings:()=>vx,usePtzContinuousMove:()=>ix,usePtzDeletePreset:()=>lx,usePtzGetOptions:()=>ux,usePtzGetPosition:()=>fx,usePtzGetPresets:()=>ox,usePtzGetStatus:()=>mx,usePtzGoHome:()=>dx,usePtzGoToPreset:()=>sx,usePtzMove:()=>rx,usePtzSavePreset:()=>cx,usePtzSetAutofocus:()=>px,usePtzStop:()=>ax,useRebootReboot:()=>yx,useRecordedPlayback:()=>aI,useRecordingApplyDeviceSettingsPatch:()=>Nx,useRecordingGetAvailability:()=>bx,useRecordingGetDaysWithRecordings:()=>xx,useRecordingGetDeviceConfig:()=>wx,useRecordingGetDeviceLiveContribution:()=>Mx,useRecordingGetDeviceSettingsContribution:()=>jx,useRecordingGetPlaybackManifest:()=>Sx,useRecordingGetStatus:()=>Ax,useRecordingGetStorageUsage:()=>Cx,useRecordingLocateSegment:()=>Tx,useRecordingPruneFootage:()=>kx,useRecordingReadSegmentBytes:()=>Ex,useRecordingRescanStorage:()=>Ox,useRecordingSetDeviceConfig:()=>Dx,useRemoteComponent:()=>xF,useScriptRunnerGetStatus:()=>Ix,useScriptRunnerRun:()=>Px,useScriptRunnerStop:()=>Fx,useScrubController:()=>Zr,useServerManagementApplyServerUpdate:()=>zx,useServerManagementCheckServerUpdate:()=>Rx,useServerManagementGetServerPackageStatus:()=>Lx,useServerManagementRestartServer:()=>Vx,useServerManagementRollbackServerUpdate:()=>Bx,useSettingsStoreCount:()=>Jx,useSettingsStoreDeclareCollection:()=>Zx,useSettingsStoreDelete:()=>qx,useSettingsStoreGet:()=>Hx,useSettingsStoreHistogram:()=>Yx,useSettingsStoreInsert:()=>Gx,useSettingsStoreIsEmpty:()=>Xx,useSettingsStoreQuery:()=>Wx,useSettingsStoreSet:()=>Ux,useSettingsStoreUpdate:()=>Kx,useSmokeGetStatus:()=>Qx,useSnapshotApplyDeviceSettingsPatch:()=>iS,useSnapshotGetDeviceLiveContribution:()=>rS,useSnapshotGetDeviceSettingsContribution:()=>nS,useSnapshotGetSnapshot:()=>$x,useSnapshotGetStatus:()=>tS,useSnapshotInvalidateCache:()=>eS,useStorageAbortUpload:()=>hS,useStorageBeginDownload:()=>gS,useStorageBeginUpload:()=>fS,useStorageDelete:()=>uS,useStorageDeleteLocation:()=>CS,useStorageEndDownload:()=>vS,useStorageExists:()=>cS,useStorageFinalizeUpload:()=>mS,useStorageGetAvailableSpace:()=>dS,useStorageGetDefaultLocation:()=>bS,useStorageList:()=>lS,useStorageListLocationDeclarations:()=>xS,useStorageListLocations:()=>yS,useStorageListProviders:()=>TS,useStorageRead:()=>sS,useStorageReadChunk:()=>_S,useStorageResolve:()=>aS,useStorageTestConfig:()=>ES,useStorageTestLocation:()=>wS,useStorageUpsertLocation:()=>SS,useStorageWrite:()=>oS,useStorageWriteChunk:()=>pS,useStreamBrokerApplyDeviceSettingsPatch:()=>rC,useStreamBrokerAssignProfile:()=>kS,useStreamBrokerGetAllRtspEntries:()=>XS,useStreamBrokerGetBrokerStats:()=>NS,useStreamBrokerGetDeviceLiveContribution:()=>nC,useStreamBrokerGetDeviceSettingsContribution:()=>tC,useStreamBrokerGetPreBufferInfo:()=>JS,useStreamBrokerGetRtspEntry:()=>ZS,useStreamBrokerGetRtspPort:()=>YS,useStreamBrokerGetStreamUrl:()=>RS,useStreamBrokerGetStreamWithCodec:()=>zS,useStreamBrokerIsRtspEnabled:()=>eC,useStreamBrokerKillClient:()=>IS,useStreamBrokerListAllCameraStreams:()=>jS,useStreamBrokerListAllProfileSlots:()=>MS,useStreamBrokerListClients:()=>FS,useStreamBrokerProbeStream:()=>PS,useStreamBrokerPublishCameraStream:()=>DS,useStreamBrokerPullAudioChunks:()=>HS,useStreamBrokerPullFrameHandles:()=>GS,useStreamBrokerRegenerateRtspToken:()=>QS,useStreamBrokerReleaseStreamWithCodec:()=>BS,useStreamBrokerRestartProfile:()=>LS,useStreamBrokerRetractCameraStream:()=>OS,useStreamBrokerSetPreBufferDuration:()=>qS,useStreamBrokerSetRtspEnabled:()=>$S,useStreamBrokerSubscribeAudioChunks:()=>VS,useStreamBrokerSubscribeFrames:()=>WS,useStreamBrokerUnassignProfile:()=>AS,useStreamBrokerUnsubscribeAudioChunks:()=>US,useStreamBrokerUnsubscribeFrames:()=>KS,useStreamCatalogGetCatalog:()=>iC,useStreamParamsGetConfigSchema:()=>sC,useStreamParamsGetOptions:()=>aC,useStreamParamsGetStatus:()=>cC,useStreamParamsSetProfile:()=>oC,useSwitchGetStatus:()=>uC,useSwitchSetState:()=>lC,useSystem:()=>Ke,useSystemFeatureFlags:()=>pC,useSystemForceRetentionCleanup:()=>_C,useSystemGetRetentionConfig:()=>hC,useSystemHealth:()=>fC,useSystemInfo:()=>dC,useSystemMutation:()=>nV,useSystemNetworkAddresses:()=>mC,useSystemQuery:()=>tV,useSystemSetRetentionConfig:()=>gC,useTamperGetStatus:()=>vC,useTemperatureSensorGetStatus:()=>yC,useThemeMode:()=>Pt,useToastOnToast:()=>bC,useTurnProviderGetTurnServers:()=>xC,useUpdateGetStatus:()=>CC,useUpdateInstallUpdate:()=>SC,useUserManagementConfirmTotp:()=>BC,useUserManagementCreateApiKey:()=>MC,useUserManagementCreateScopedToken:()=>FC,useUserManagementCreateUser:()=>TC,useUserManagementDeleteUser:()=>DC,useUserManagementDisableTotp:()=>VC,useUserManagementGetTotpStatus:()=>HC,useUserManagementListApiKeys:()=>jC,useUserManagementListOauthSessions:()=>JC,useUserManagementListScopedTokens:()=>RC,useUserManagementListUsers:()=>wC,useUserManagementOauthExchangeCode:()=>GC,useUserManagementOauthIssueCode:()=>WC,useUserManagementOauthRefresh:()=>KC,useUserManagementOauthVerifyAccessToken:()=>qC,useUserManagementResetPassword:()=>OC,useUserManagementRevokeApiKey:()=>NC,useUserManagementRevokeOauthSession:()=>YC,useUserManagementRevokeScopedToken:()=>IC,useUserManagementSetUserScopes:()=>kC,useUserManagementSetupTotp:()=>zC,useUserManagementUpdateUser:()=>EC,useUserManagementValidateApiKey:()=>PC,useUserManagementValidateCredentials:()=>AC,useUserManagementValidateScopedToken:()=>LC,useUserManagementVerifyTotp:()=>UC,useVacuumControlGetStatus:()=>nw,useVacuumControlLocate:()=>ew,useVacuumControlPause:()=>ZC,useVacuumControlReturnToBase:()=>$C,useVacuumControlSetFanSpeed:()=>tw,useVacuumControlStart:()=>XC,useVacuumControlStop:()=>QC,useValveClose:()=>iw,useValveGetStatus:()=>sw,useValveOpen:()=>rw,useValveSetPosition:()=>ow,useValveStop:()=>aw,useVibrationGetStatus:()=>cw,useVideoclipsGetClipPlayback:()=>uw,useVideoclipsListClips:()=>lw,useVodPlayback:()=>nI,useWaterHeaterGetStatus:()=>mw,useWaterHeaterSetAway:()=>pw,useWaterHeaterSetOperationMode:()=>fw,useWaterHeaterSetTargetTemp:()=>dw,useWeatherGetStatus:()=>hw,useWebrtcSessionAddIceCandidate:()=>bw,useWebrtcSessionCloseSession:()=>Sw,useWebrtcSessionCreateSession:()=>_w,useWebrtcSessionGetIceCandidates:()=>xw,useWebrtcSessionGetSessionState:()=>ww,useWebrtcSessionHandleAnswer:()=>yw,useWebrtcSessionHandleOffer:()=>vw,useWebrtcSessionHasAdaptiveBitrate:()=>Cw,useWebrtcSessionListStreams:()=>gw,useWidget:()=>vF,useWidgetMetadata:()=>yF,useWidgetRegistry:()=>SF,useZoneAnalyticsGetCameraHistory:()=>Dw,useZoneAnalyticsGetCurrentSnapshot:()=>Tw,useZoneAnalyticsGetUnzonedHistory:()=>Ow,useZoneAnalyticsGetZoneHistory:()=>Ew,useZoneEditing:()=>GB,useZoneRulesListRules:()=>kw,useZoneRulesSetRules:()=>Aw,useZonesAddZone:()=>Mw,useZonesListZones:()=>jw,useZonesRemoveZone:()=>Nw,useZonesUpdateZone:()=>Pw,vacuumStateMeta:()=>sT,validateScopes:()=>HB,valveStateMeta:()=>FT,waterHeaterPhase:()=>ZT,waterHeaterTint:()=>XT,weatherConditionMeta:()=>nE,weatherTint:()=>rE});h();var oV=E(()=>a(()=>import(`./MaskShapeCanvas-pGn6MKOi.js`).then(e=>({default:e.MaskShapeCanvas})),__vite__mapDeps([4]))),sV=E(()=>a(()=>import(`./MotionZonesSettings-DnVWhQ3W.js`).then(e=>({default:e.MotionZonesSettings})),__vite__mapDeps([0,1,2,3,4]))),cV=E(()=>a(()=>import(`./PrivacyMaskSettings-BF7f56Ma.js`).then(e=>({default:e.PrivacyMaskSettings})),__vite__mapDeps([5,1,2,3,4])));export{Fk as $,wl as $i,og as $n,Ob as $r,Cf as $t,bF as A,Es as Aa,TS as Ai,hh as An,Sv as Ar,Wu as At,cM as B,mr as Ba,HC as Bi,Km as Bn,py as Br,df as Bt,_R as C,Ms as Ca,Rx as Ci,jm as Cn,b_ as Cr,qu as Ct,tI as D,Is as Da,CS as Di,Am as Dn,ov as Dr,Zu as Dt,iI as E,Ls as Ea,Bx as Ei,xm as En,lv as Er,ad as Et,aF as F,Ao as Fa,xC as Fi,vm as Fn,Tv as Fr,Dd as Ft,tj as G,OC as Gi,sg as Gn,gy as Gr,af as Gt,aM as H,Pt as Ha,JC as Hi,eh as Hn,my as Hr,sf as Ht,eF as I,ta as Ia,FC as Ii,dm as In,mv as Ir,zd as It,VA as J,IC as Ji,eg as Jn,Mb as Jr,Tf as Jt,ej as K,NC as Ki,$h as Kn,sb as Kr,ff as Kt,zP as L,zr as La,TC as Li,um as Ln,gv as Lr,Zd as Lt,yF as M,_s as Ma,PS as Mi,zm as Mn,xv as Mr,Ed as Mt,rF as N,ps as Na,QS as Ni,Qm as Nn,_v as Nr,Td as Nt,nI as O,Rs as Oa,xS as Oi,Jm as On,sv as Or,cd as Ot,iF as P,Bo as Pa,bC as Pi,_m as Pn,vv as Pr,Od as Pt,Mk as Q,Du as Qi,ug as Qn,xb as Qr,xf as Qt,qN as R,Ar as Ra,DC as Ri,hm as Rn,Ny as Rr,uf as Rt,xR as S,Us as Sa,zx as Si,rh as Sn,S_ as Sr,ed as St,WI as T,zs as Ta,Vx as Ti,ym as Tn,P_ as Tr,Hu as Tt,Qj as U,Nt as Ua,RC as Ui,cg as Un,Hy as Ur,pf as Ut,oM as V,X as Va,jC as Vi,ah as Vn,xy as Vr,rf as Vt,mj as W,wC as Wi,Zh as Wn,By as Wr,lf as Wt,IA as X,EC as Xi,tg as Xn,db as Xr,Pf as Xt,LA as Y,kC as Yi,ng as Yn,fb as Yr,Of as Yt,Hk as Z,ku as Zi,Qh as Zn,ub as Zr,yf as Zt,wz as _,rc as _a,Zy as _i,mh as _n,e_ as _r,Nu as _t,XB as a,ol as aa,Qy as ai,Gp as an,Ag as ar,Mu as at,LR as b,Ws as ba,Ub as bi,Wm as bn,x_ as br,Uu as bt,HB as c,Z as ca,mb as ci,lh as cn,Fg as cr,gd as ct,OB as d,Fc as da,yb as di,ch as dn,zg as dr,Ku as dt,Cl as ea,ib as ei,Ef as en,lg as er,jk as et,uB as f,Ec as fa,Tb as fi,dh as fn,Rg as fr,id as ft,Nz as g,vc as ga,cb as gi,th as gn,Yg as gr,Iu as gt,Pz as h,yc as ha,ab as hi,ph as hn,Zg as hr,$u as ht,ZB as i,cl as ia,kb as ii,Wp as in,Ig as ir,Rw as it,xF as j,ys as ja,SS as ji,gh as jn,wv as jr,kd as jt,_F as k,ks as ka,yS as ki,Tm as kn,dv as kr,Bu as kt,NB as l,nl as la,vb as li,oh as ln,Lg as lr,md as lt,Yz as m,xc as ma,Sb as mi,Rm as mn,Qg as mr,Ju as mt,iV as n,yl as na,$y as ni,kf as nn,Ng as nr,yk as nt,WB as o,sl as oa,bb as oi,Yp as on,Pg as or,hd as ot,eB as p,Sc as pa,wb as pi,ih as pn,Bg as pr,nd as pt,QA as q,YC as qi,Xh as qn,Xy as qr,Sf as qt,QB as r,ll as ra,pb as ri,Mp as rn,kg as rr,dk as rt,BB as s,il as sa,Eb as si,nh as sn,Og as sr,pd as st,aV as t,xl as ta,eb as ti,wf as tn,jg as tr,Ak as tt,MB as u,Vc as ua,_b as ui,sh as un,Mg as ur,od as ut,gz as v,nc as va,jb as vi,fh as vn,$g as vr,Xu as vt,gR as w,Fs as wa,Lx as wi,Zm as wn,F_ as wr,td as wt,TR as x,Gs as xa,yx as xi,Mm as xn,C_ as xr,Vu as xt,ez as y,Hs as ya,Vb as yi,Lm as yn,v_ as yr,ud as yt,mM as z,Or as za,VC as zi,bm as zn,My as zr,cf as zt};
67
+ `)).then(()=>{pe(!0),setTimeout(()=>pe(!1),1500)})},[W,he]),_e=u(e=>{navigator.clipboard.writeText(he(e)).then(()=>{me(e.id),setTimeout(()=>me(t=>t===e.id?null:t),1200)})},[he]),ve=u(()=>{y(new Set(Hz))},[]),ye=u(()=>{y(new Set)},[]),be=b(()=>{let e=I.trim().toLowerCase();return e?Hz.filter(t=>t.toLowerCase().includes(e)):Hz},[I]),xe=Hz.length,Se=v.size,Ce=Se===xe,we=Ce?`All`:`${Se}/${xe}`;return g(`div`,{className:X(`h-full min-h-0 flex flex-col`,m),onClick:e=>e.stopPropagation(),children:[g(`div`,{className:`flex items-center justify-between px-3 py-1.5 bg-surface-hover/30 gap-2 shrink-0`,children:[g(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[N(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`Events`}),e&&N(Qz,{label:`agent`,value:e}),t&&N(Qz,{label:`addon`,value:t}),n!==void 0&&N(Qz,{label:`device`,value:`#${n}`}),a&&N(Qz,{label:`category`,value:a}),g(`button`,{type:`button`,onClick:()=>{E(e=>!e),!T&&z.current&&z.current.scrollTo({top:0,behavior:`smooth`})},className:X(`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors`,T?`border-border text-foreground-subtle hover:text-foreground`:`border-amber-500/30 bg-amber-500/10 text-amber-400`),children:[N(ai,{className:`h-2.5 w-2.5`}),T?`Auto`:`Paused`]}),c&&g(`div`,{className:`relative`,ref:B,children:[g(`button`,{type:`button`,onClick:()=>F(e=>!e),className:X(`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors`,Ce?`border-border text-foreground-subtle hover:text-foreground`:`border-violet-500/30 bg-violet-500/10 text-violet-400`),title:`Pick events to track`,children:[N(ua,{className:`h-2.5 w-2.5`}),`Filter (`,we,`)`]}),M&&N(Xz,{search:I,onSearchChange:L,categories:be,active:v,onToggle:le,onSelectAll:ve,onSelectNone:ye,onResetDefaults:ue})]}),g(`button`,{type:`button`,onClick:ue,className:`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground transition-colors`,title:`Reset filters to defaults`,children:[N(so,{className:`h-2.5 w-2.5`}),`Reset`]}),g(`button`,{type:`button`,onClick:de,className:`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground transition-colors`,title:`Clear visible entries`,children:[N(Bo,{className:`h-2.5 w-2.5`}),`Clear`]}),g(`button`,{type:`button`,onClick:ge,disabled:W.length===0,className:X(`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors`,fe?`border-emerald-500/30 bg-emerald-500/10 text-emerald-400`:`border-border text-foreground-subtle hover:text-foreground`,W.length===0&&`opacity-40 cursor-not-allowed`),title:`Copy all visible events`,children:[N(Wi,{className:`h-2.5 w-2.5`}),fe?`Copied!`:`Copy`]}),g(`div`,{className:`relative`,children:[N(`input`,{type:`text`,value:A,onChange:e=>j(e.target.value),placeholder:`Search…`,className:`w-32 pl-1.5 pr-5 py-0.5 rounded border border-border bg-background text-foreground text-[10px] focus:outline-none focus:border-primary/50`}),A&&N(`button`,{type:`button`,onClick:()=>j(``),className:`absolute right-1 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground`,title:`Clear search`,children:N(rs,{className:`h-2.5 w-2.5`})})]}),w.length>0&&g(`span`,{className:`text-[9px] text-emerald-400 font-medium`,children:[`+`,w.length,` live`]})]}),p&&N(`button`,{type:`button`,onClick:p,className:`text-foreground-subtle hover:text-foreground`,children:N(rs,{className:`h-3.5 w-3.5`})})]}),g(`div`,{ref:z,className:X(`flex-1 min-h-0 overflow-auto text-[10px]`,o),children:[ie&&g(`div`,{className:`flex items-center justify-center gap-2 py-6 text-foreground-subtle`,children:[N(Ea,{className:`h-3.5 w-3.5 animate-spin`}),`Loading events...`]}),!ie&&W.length===0&&N(`div`,{className:`py-4 text-center text-foreground-subtle`,children:`No events found`}),W.length>0&&N(`div`,{className:`divide-y divide-border/30`,children:W.map(e=>{let t=Vz(e.category,e.data),n=t.icon,r=Kz(e.category,e.data),i=D.has(e.id);return g(`div`,{className:`flex items-start gap-2 px-3 py-1.5 hover:bg-surface-hover/30 cursor-pointer`,onClick:()=>ce(e.id),children:[N(`span`,{className:`text-foreground-subtle whitespace-nowrap w-[70px] shrink-0 pt-0.5`,children:new Date(e.timestamp).toLocaleTimeString()}),N($z,{copied:G===e.id,onCopy:()=>_e(e)}),g(`div`,{className:`flex-1 min-w-0`,children:[g(`div`,{className:`flex items-center gap-1.5`,children:[N(i?Re:Ue,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),g(`span`,{className:X(`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[9px] font-medium`,t.color),children:[N(n,{className:`h-2.5 w-2.5`}),t.label]}),e.source.nodeId&&e.source.nodeId!==`hub`&&N(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:e.source.nodeId})]}),r&&N(`p`,{className:`text-foreground-subtle text-[10px] mt-0.5 ml-5`,children:r}),i&&g(`div`,{className:`mt-1 ml-5 text-[9px] bg-surface rounded px-2 py-1.5 space-y-0.5 font-mono overflow-x-auto`,children:[g(`div`,{children:[N(`span`,{className:`text-primary/70`,children:`source`}),N(`span`,{className:`text-foreground-subtle`,children:`: `}),N(`span`,{className:`text-foreground`,children:JSON.stringify(e.source)})]}),g(`div`,{children:[N(`span`,{className:`text-primary/70`,children:`category`}),N(`span`,{className:`text-foreground-subtle`,children:`: `}),N(`span`,{className:`text-foreground`,children:e.category})]}),Object.entries(e.data).map(([e,t])=>g(`div`,{children:[N(`span`,{className:`text-primary/70`,children:e}),N(`span`,{className:`text-foreground-subtle`,children:`: `}),N(`span`,{className:`text-foreground break-all`,children:typeof t==`object`?JSON.stringify(t):String(t)})]},e))]})]})]},e.id)})})]})]})}function Xz({search:e,onSearchChange:t,categories:n,active:r,onToggle:i,onSelectAll:a,onSelectNone:o,onResetDefaults:s}){return g(`div`,{className:`absolute z-20 top-full mt-1 left-0 w-72 max-h-80 rounded-md border border-border bg-surface shadow-lg flex flex-col`,onClick:e=>e.stopPropagation(),children:[g(`div`,{className:`flex items-center gap-1 px-2 py-1.5 border-b border-border/50`,children:[N(po,{className:`h-3 w-3 text-foreground-subtle`}),N(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),placeholder:`Filter categories…`,className:`flex-1 bg-transparent text-[10px] focus:outline-none text-foreground placeholder:text-foreground-subtle`,autoFocus:!0}),e&&N(`button`,{type:`button`,onClick:()=>t(``),className:`text-foreground-subtle hover:text-foreground`,children:N(rs,{className:`h-2.5 w-2.5`})})]}),g(`div`,{className:`flex items-center gap-1 px-2 py-1 border-b border-border/50 text-[9px]`,children:[N(`button`,{type:`button`,onClick:a,className:`px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground`,children:`All`}),N(`button`,{type:`button`,onClick:o,className:`px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground`,children:`None`}),N(`button`,{type:`button`,onClick:s,className:`px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground`,children:`Defaults`})]}),g(`div`,{className:`overflow-y-auto flex-1`,children:[n.length===0&&N(`div`,{className:`text-[10px] text-foreground-subtle italic px-2 py-3 text-center`,children:`No matches`}),n.map(e=>{let t=r.has(e),n=Vz(e),a=n.icon;return g(`button`,{type:`button`,onClick:()=>i(e),className:`w-full flex items-center gap-2 px-2 py-1 text-left hover:bg-surface-hover/40 text-[10px]`,children:[N(`input`,{type:`checkbox`,readOnly:!0,checked:t,className:`accent-violet-500`}),g(`span`,{className:X(`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[9px] font-medium shrink-0`,n.color),children:[N(a,{className:`h-2.5 w-2.5`}),n.label]}),N(`span`,{className:`text-foreground-subtle font-mono truncate`,children:e})]},e)})]})]})}function Zz({position:e=`bottom`,className:t,...n}){return N(`div`,{className:X(e===`bottom`?`absolute bottom-0 left-0 right-0 z-10 border-t border-border bg-surface/95 backdrop-blur-sm`:`absolute inset-x-2 bottom-2 z-10 rounded-lg border border-border bg-surface/95 backdrop-blur-sm shadow-xl`,t),children:N(Yz,{maxHeight:`max-h-48`,...n})})}function Qz({label:e,value:t}){return g(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium`,children:[e,`: `,t]})}function $z({copied:e,onCopy:t}){return N(`button`,{type:`button`,title:`Copy this event`,onClick:e=>{e.stopPropagation(),t()},className:X(`rounded p-0.5 transition-colors mt-0.5`,e?`text-emerald-400`:`text-foreground-subtle/60 hover:text-foreground hover:bg-surface-hover`),children:N(e?Ci:Wi,{className:`h-3 w-3`})})}h();function eB({deviceId:e,className:t=``,onOpenChild:n}){let r=Z.useUtils(),i=Z.deviceDiscovery.listDiscovered.useQuery({deviceId:e},{refetchInterval:1e4,retry:!1}),a=Z.deviceDiscovery.getStatus.useQuery({deviceId:e},{refetchInterval:1e4,retry:!1}),o=Z.deviceDiscovery.refreshDiscovery.useMutation({onSuccess:()=>{r.deviceDiscovery.listDiscovered.invalidate({deviceId:e}),r.deviceDiscovery.getStatus.invalidate({deviceId:e})}}),s=Z.deviceDiscovery.adoptDevice.useMutation({onSuccess:()=>{r.deviceDiscovery.listDiscovered.invalidate({deviceId:e})}}),c=Z.deviceDiscovery.releaseDevice.useMutation({onSuccess:()=>{r.deviceDiscovery.listDiscovered.invalidate({deviceId:e})}}),[l,u]=k(null),{available:d,adopted:f}=b(()=>{let e=i.data??[],t=e=>typeof e.metadata.rtspChannel==`number`?e.metadata.rtspChannel:1/0,n=(e,n)=>{let r=t(e),i=t(n);return r===i?e.name.localeCompare(n.name):r-i};return{available:e.filter(e=>!e.alreadyAdopted).toSorted(n),adopted:e.filter(e=>e.alreadyAdopted).toSorted(n)}},[i.data]),p=a.data,m=p?.lastError??null,h=p?.lastDiscoveryAt??null;async function _(){await o.mutateAsync({deviceId:e}).catch(()=>{})}async function v(t){u(t.childNativeId);try{await s.mutateAsync({deviceId:e,childNativeId:t.childNativeId})}finally{u(null)}}async function y(t){if(t.adoptedDeviceId!=null){u(t.childNativeId);try{await c.mutateAsync({deviceId:e,childDeviceId:t.adoptedDeviceId})}finally{u(null)}}}return g(`div`,{className:`rounded-xl border border-border bg-surface ${t}`,children:[g(`div`,{className:`flex items-start justify-between gap-2 border-b border-border px-3 py-2 sm:px-5 sm:py-3`,children:[g(`div`,{className:`min-w-0`,children:[N(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Discovered devices`}),g(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Channels behind this hub. Click `,N(`span`,{className:`font-medium`,children:`Add`}),` to promote a channel to a managed device, or `,N(`span`,{className:`font-medium`,children:`Remove`}),` to detach.`]})]}),g(`button`,{type:`button`,onClick:_,disabled:o.isPending,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-2 py-1.5 sm:px-3 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 shrink-0`,children:[o.isPending?N(Ea,{className:`h-3.5 w-3.5 animate-spin`}):N(oo,{className:`h-3.5 w-3.5`}),N(`span`,{className:`hidden sm:inline`,children:`Refresh`})]})]}),m?g(`div`,{className:`flex items-start gap-2 border-b border-border bg-destructive/10 px-5 py-2 text-[11px] text-destructive`,children:[N(Uo,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),g(`span`,{children:[`Last refresh failed: `,m]})]}):null,i.isLoading?N(`div`,{className:`flex items-center justify-center py-8 text-foreground-subtle`,children:N(Ea,{className:`h-5 w-5 animate-spin`})}):d.length===0&&f.length===0?N(`div`,{className:`px-5 py-8 text-center text-xs text-foreground-subtle`,children:`No channels reported by the hub yet. Click Refresh to enumerate.`}):g(w,{children:[d.length>0?N(tB,{title:`Available to add`,count:d.length,tone:`primary`,children:d.map(e=>N(nB,{child:e,busy:l===e.childNativeId,onAdopt:v,onRelease:y,onOpenChild:n},e.childNativeId))}):null,f.length>0?N(tB,{title:`Already adopted`,count:f.length,tone:`muted`,children:f.map(e=>N(nB,{child:e,busy:l===e.childNativeId,onAdopt:v,onRelease:y,onOpenChild:n},e.childNativeId))}):null]}),h==null?null:g(`div`,{className:`border-t border-border px-5 py-2 text-[10px] text-foreground-subtle`,children:[`Last refreshed `,new Date(h).toLocaleString()]})]})}function tB({title:e,count:t,tone:n,children:r}){return g(`div`,{className:`border-t border-border`,children:[g(`div`,{className:`flex items-center justify-between border-b px-3 sm:px-5 py-1.5 text-[10px] uppercase tracking-wider ${n===`primary`?`bg-primary/5 text-primary border-primary/30`:`bg-surface text-foreground-subtle border-border`}`,children:[N(`span`,{className:`font-semibold`,children:e}),N(`span`,{className:`font-mono`,children:t})]}),N(`div`,{className:`divide-y divide-border`,children:r})]})}function nB({child:e,busy:t,onAdopt:n,onRelease:r,onOpenChild:i}){return g(`div`,{className:`flex flex-wrap items-center justify-between gap-2 px-3 py-2 sm:px-5 sm:py-3 sm:flex-nowrap sm:gap-3`,children:[g(`div`,{className:`min-w-0 flex-1`,children:[g(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[N(rB,{status:e.status}),N(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),e.metadata.isDoorbell?N(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:`Doorbell`}):null,e.metadata.isBattery?N(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:`Battery`}):null,e.metadata.isMultifocal?N(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:`Multifocal`}):null]}),g(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[typeof e.metadata.rtspChannel==`number`?g(`span`,{children:[`ch `,N(`span`,{className:`font-mono`,children:e.metadata.rtspChannel})]}):null,e.metadata.model?N(`span`,{className:`truncate max-w-[160px]`,children:e.metadata.model}):null,e.metadata.uid?g(`span`,{className:`font-mono truncate max-w-[140px]`,children:[e.metadata.uid.slice(0,12),`…`]}):null]})]}),e.alreadyAdopted?g(`div`,{className:`flex items-center gap-2`,children:[i&&e.adoptedDeviceId!==null?g(`button`,{type:`button`,onClick:()=>i(e.adoptedDeviceId),className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Open device detail`,children:[N(ea,{className:`h-3.5 w-3.5`}),`Open`]}):null,g(`button`,{type:`button`,onClick:()=>{r(e)},disabled:t,className:`inline-flex items-center gap-1.5 rounded-lg border border-destructive/30 px-3 py-1.5 text-xs text-destructive hover:bg-destructive/10 transition-colors disabled:opacity-50`,children:[t?N(Ea,{className:`h-3.5 w-3.5 animate-spin`}):N(Bo,{className:`h-3.5 w-3.5`}),`Remove`]})]}):g(`button`,{type:`button`,onClick:()=>{n(e)},disabled:t,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[t?N(Ea,{className:`h-3.5 w-3.5 animate-spin`}):N($a,{className:`h-3.5 w-3.5`}),`Add`]})]})}function rB({status:e}){switch(e){case`online`:return g(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-emerald-500/40 bg-emerald-500/10 px-2 py-0.5 text-[10px] font-medium text-emerald-500`,children:[N($o,{className:`h-2.5 w-2.5`}),` online`]});case`sleeping`:return g(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] font-medium text-amber-500`,children:[N(Ba,{className:`h-2.5 w-2.5`}),` sleeping`]});case`offline`:return g(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-destructive/40 bg-destructive/10 px-2 py-0.5 text-[10px] font-medium text-destructive`,children:[N(Qo,{className:`h-2.5 w-2.5`}),` offline`]});default:return g(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-border bg-surface px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:[N(Pi,{className:`h-2.5 w-2.5`}),` unknown`]})}}h();function iB(e,t){if(!e||typeof e!=`object`)return null;let n=e;if(n.category!==H.DeviceStateChanged)return null;let r=n.data;return!r||typeof r!=`object`||r.deviceId!==t||typeof r.capName!=`string`||!r.slice||typeof r.slice!=`object`?null:{capName:r.capName,slice:r.slice}}function aB(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function oB(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.source==`string`?!!t.data&&typeof t.data==`object`&&!Array.isArray(t.data):!1}function sB(e,t){let n=new Map;for(let[r,i]of Object.entries(e)){let e=i&&typeof i==`object`&&!Array.isArray(i)?i:{value:i};n.set(r,{slice:e,updatedAt:t})}return n}var cB=Object.freeze([...new Set(ce.filter(e=>e.scope===`device`).map(e=>e.name))].toSorted()),lB=1;function uB({deviceId:e,defaultCaps:t,maxHeight:n=`max-h-96`,onClose:r,className:i}){let[a,o]=k(b(()=>new Set(t??[]),[t])),[s,c]=k(``),[l,d]=k(!1),[p,m]=k(``),[h,_]=k(`normalized`),v=f(null),[y,x]=k(new Map),[S,T]=k(new Map),[,E]=k(0),D=f(e);P(()=>{D.current!==e&&(D.current=e,x(new Map),T(new Map))},[e]);let{data:O,isLoading:A}=Z.deviceState.getAllSnapshots.useQuery({},{staleTime:3e4}),j=f(!1);P(()=>{if(j.current||!aB(O))return;let t=O[String(e)];if(j.current=!0,!t)return;let n=Date.now();x(e=>{let r=new Map(e);for(let[e,i]of Object.entries(t))r.has(e)||r.set(e,{slice:i,updatedAt:n});return r})},[O,e]),P(()=>{j.current=!1},[e]);let M=u((e,t)=>{x(n=>{let r=new Map(n);return r.set(e,{slice:t,updatedAt:Date.now()}),r})},[]),F=Fe(Ke().trpcClient,e)?.deviceOps?.getRawState,I=C({queryKey:[`device-raw-state`,e],queryFn:()=>F({deviceId:e}),enabled:F!=null,staleTime:6e4}),L=oB(I.data)?I.data:null,R=I.isFetched&&!I.isError&&L!=null;P(()=>{h===`raw`&&!R&&_(`normalized`)},[h,R]);let ee=b(()=>L?sB(L.data,I.dataUpdatedAt||Date.now()):new Map,[L,I.dataUpdatedAt]);P(()=>{let e=setInterval(()=>E(e=>e+1),5e3);return()=>clearInterval(e)},[]);let z=b(()=>{let e=new Set(cB);for(let t of y.keys())e.add(t);return[...e].toSorted()},[y]),B=b(()=>{let e=s.trim().toLowerCase();return[...y.keys()].toSorted().filter(t=>a.size>0&&!a.has(t)?!1:!e||t.toLowerCase().includes(e)?!0:xB(y.get(t)?.slice??{},e))},[y,a,s]),V=u(e=>{o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),te=u(()=>{o(new Set(t??[])),c(``)},[t]),H=u(()=>{o(new Set(z))},[z]),U=u(()=>{o(new Set)},[]),ne=u((e,t)=>{T(n=>{let r=new Map(n);return r.set(e,!t),r})},[]),re=u((e,t)=>{let n=S.get(e);return n===void 0?t<lB:n},[S]),[ie,ae]=k(!1),oe=u(()=>{let e={};for(let t of B){let n=y.get(t);n&&(e[t]=n.slice)}navigator.clipboard.writeText(JSON.stringify(e,null,2)).then(()=>{ae(!0),setTimeout(()=>ae(!1),1500)})},[B,y]),se=b(()=>{let e=p.trim().toLowerCase();return e?z.filter(t=>t.toLowerCase().includes(e)):z},[p,z]),W=z.length,ce=a.size,le=ce===0||ce===W,ue=le?`All`:`${ce}/${W}`;P(()=>{if(!l)return;let e=e=>{let t=v.current;t&&!t.contains(e.target)&&d(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[l]);let de=s.trim().toLowerCase();return g(`div`,{className:X(`h-full min-h-0 flex flex-col`,i),onClick:e=>e.stopPropagation(),children:[g(`div`,{className:`flex items-center justify-between px-3 py-1.5 bg-surface-hover/30 gap-2 shrink-0`,children:[g(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[N(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`State`}),N(CB,{label:`device`,value:`#${e}`}),R&&N(dB,{mode:h,onChange:_}),h===`normalized`&&g(w,{children:[g(`div`,{className:`relative`,ref:v,children:[g(`button`,{type:`button`,onClick:()=>d(e=>!e),className:X(`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors`,le?`border-border text-foreground-subtle hover:text-foreground`:`border-violet-500/30 bg-violet-500/10 text-violet-400`),title:`Pick caps to show`,children:[N(ua,{className:`h-2.5 w-2.5`}),`Filter (`,ue,`)`]}),l&&N(wB,{search:p,onSearchChange:m,caps:se,active:a,onToggle:V,onSelectAll:H,onSelectNone:U,onResetDefaults:te})]}),g(`button`,{type:`button`,onClick:te,className:`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground transition-colors`,title:`Reset filters`,children:[N(so,{className:`h-2.5 w-2.5`}),`Reset`]}),g(`button`,{type:`button`,onClick:oe,disabled:B.length===0,className:X(`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors`,ie?`border-emerald-500/30 bg-emerald-500/10 text-emerald-400`:`border-border text-foreground-subtle hover:text-foreground`,B.length===0&&`opacity-40 cursor-not-allowed`),title:`Copy visible state as JSON`,children:[N(Wi,{className:`h-2.5 w-2.5`}),ie?`Copied!`:`Copy`]}),g(`div`,{className:`relative`,children:[N(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`Search…`,className:`w-32 pl-1.5 pr-5 py-0.5 rounded border border-border bg-background text-foreground text-[10px] focus:outline-none focus:border-primary/50`}),s&&N(`button`,{type:`button`,onClick:()=>c(``),className:`absolute right-1 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground`,title:`Clear search`,children:N(rs,{className:`h-2.5 w-2.5`})})]}),g(`span`,{className:`text-[9px] text-emerald-400 font-medium inline-flex items-center gap-1`,children:[N(`span`,{className:`h-1.5 w-1.5 rounded-full bg-emerald-400 animate-pulse`}),`live`]})]}),h===`raw`&&L&&g(w,{children:[g(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-sky-500/30 bg-sky-500/15 text-sky-400 px-2 py-0.5 text-[9px] font-medium font-sans`,children:[`source: `,L.source]}),g(`button`,{type:`button`,onClick:()=>I.refetch(),disabled:I.isFetching,className:X(`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground transition-colors`,I.isFetching&&`opacity-60 cursor-wait`),title:`Re-read raw upstream state`,children:[N(so,{className:X(`h-2.5 w-2.5`,I.isFetching&&`animate-spin`)}),`Refresh`]})]})]}),h===`normalized`&&N(fB,{deviceId:e,onPatch:M}),r&&N(`button`,{type:`button`,onClick:r,className:`text-foreground-subtle hover:text-foreground`,children:N(rs,{className:`h-3.5 w-3.5`})})]}),N(`div`,{className:X(`flex-1 min-h-0 overflow-auto text-[10px] font-mono`,n),children:h===`raw`?ee.size===0?N(`div`,{className:`py-4 text-center text-foreground-subtle font-sans`,children:`No raw state`}):N(`div`,{className:`py-1`,children:[...ee.entries()].map(([e,t])=>N(pB,{capName:e,slice:t.slice,updatedAt:t.updatedAt,searchNeedle:``,isPathOpen:re,onToggle:ne},e))}):g(w,{children:[A&&y.size===0&&g(`div`,{className:`flex items-center justify-center gap-2 py-6 text-foreground-subtle font-sans`,children:[N(Ea,{className:`h-3.5 w-3.5 animate-spin`}),`Loading device state...`]}),!A&&y.size===0&&N(`div`,{className:`py-4 text-center text-foreground-subtle font-sans`,children:`No runtime state`}),!A&&y.size>0&&B.length===0&&N(`div`,{className:`py-4 text-center text-foreground-subtle font-sans`,children:`No caps match the filter`}),B.length>0&&N(`div`,{className:`py-1`,children:B.map(e=>{let t=y.get(e);return t?N(pB,{capName:e,slice:t.slice,updatedAt:t.updatedAt,searchNeedle:de,isPathOpen:re,onToggle:ne},e):null})})]})})]})}function dB({mode:e,onChange:t}){return N(`div`,{className:`inline-flex items-center rounded border border-border overflow-hidden`,children:[{value:`normalized`,label:`Normalized`},{value:`raw`,label:`Raw`}].map(n=>N(`button`,{type:`button`,onClick:()=>t(n.value),className:X(`text-[9px] px-1.5 py-0.5 transition-colors`,e===n.value?`bg-violet-500/15 text-violet-400`:`text-foreground-subtle hover:text-foreground`),children:n.label},n.value))})}function fB({deviceId:e,onPatch:t}){return Z.systemEvents.subscribe.useSubscription({deviceId:e,category:H.DeviceStateChanged},{onData:n=>{let r=iB(n,e);r&&t(r.capName,r.slice)}}),null}function pB({capName:e,slice:t,updatedAt:n,searchNeedle:r,isPathOpen:i,onToggle:a}){let o=e,s=i(o,0),c=Object.entries(t);return g(`div`,{children:[g(`div`,{className:`flex items-center gap-1.5 px-3 py-1 hover:bg-surface-hover/30 cursor-pointer select-none`,onClick:()=>a(o,s),children:[N(gB,{open:s,hasChildren:c.length>0}),N(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-violet-500/30 bg-violet-500/15 text-violet-400 px-2 py-0.5 text-[9px] font-medium font-sans`,children:e}),g(`span`,{className:`text-[9px] text-foreground-subtle font-sans`,children:[c.length,` `,c.length===1?`key`:`keys`]}),g(`span`,{className:`ml-auto text-[9px] text-foreground-subtle/70 font-sans tabular-nums`,children:[`updated `,SB(n)]})]}),s&&N(`div`,{children:c.length===0?N(hB,{depth:1,label:`empty slice`}):c.map(([e,t])=>N(mB,{path:`${o}.${e}`,nodeKey:e,value:t,depth:1,searchNeedle:r,isPathOpen:i,onToggle:a},e))})]})}function mB({path:e,nodeKey:t,value:n,depth:r,searchNeedle:i,isPathOpen:a,onToggle:o}){let s=_B(n),c={paddingLeft:`${12+r*14}px`};if(!s)return g(`div`,{className:`flex items-start gap-1 px-3 py-0.5`,style:c,children:[N(`span`,{className:X(`shrink-0`,bB(t,i,`text-primary/70`)),children:t}),N(`span`,{className:`text-foreground-subtle`,children:`:`}),N(`span`,{className:X(`break-all`,bB(vB(n),i,yB(n))),children:vB(n)})]});let l=a(e,r);return g(`div`,{children:[g(`div`,{className:`flex items-center gap-1 px-3 py-0.5 hover:bg-surface-hover/30 cursor-pointer select-none`,style:c,onClick:()=>o(e,l),children:[N(gB,{open:l,hasChildren:s.entries.length>0}),N(`span`,{className:bB(t,i,`text-primary/70`),children:t}),N(`span`,{className:`text-foreground-subtle/70 text-[9px]`,children:s.summary})]}),l&&(s.entries.length===0?N(hB,{depth:r+1,label:s.kind===`array`?`empty array`:`empty object`}):s.entries.map(([t,n])=>N(mB,{path:`${e}.${t}`,nodeKey:t,value:n,depth:r+1,searchNeedle:i,isPathOpen:a,onToggle:o},t)))]})}function hB({depth:e,label:t}){return N(`div`,{className:`px-3 py-0.5 text-foreground-subtle/60 italic`,style:{paddingLeft:`${12+e*14}px`},children:t})}function gB({open:e,hasChildren:t}){return t?N(e?Re:Ue,{className:`h-3 w-3 text-foreground-subtle shrink-0`}):N(`span`,{className:`inline-block w-3 shrink-0`})}function _B(e){if(Array.isArray(e))return{kind:`array`,entries:e.map((e,t)=>[String(t),e]),summary:`[${e.length}]`};if(e&&typeof e==`object`){let t=Object.entries(e);return{kind:`object`,entries:t,summary:`{${t.length}}`}}return null}function vB(e){if(e===null)return`null`;if(e===void 0)return`undefined`;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{return JSON.stringify(e)}catch{return String(e)}}function yB(e){return e==null?`text-foreground-subtle/60`:typeof e==`number`?`text-amber-400`:typeof e==`boolean`?e?`text-emerald-400`:`text-rose-400`:`text-foreground`}function bB(e,t,n){return t&&e.toLowerCase().includes(t)?X(n,`bg-violet-500/20 rounded px-0.5`):n}function xB(e,t){if(Array.isArray(e))return e.some(e=>xB(e,t));if(e&&typeof e==`object`){for(let[n,r]of Object.entries(e))if(n.toLowerCase().includes(t)||xB(r,t))return!0;return!1}return vB(e).toLowerCase().includes(t)}function SB(e){let t=Date.now()-e;if(t<5e3)return`just now`;let n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;let r=Math.floor(n/60);return r<60?`${r}m ago`:`${Math.floor(r/60)}h ago`}function CB({label:e,value:t}){return g(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium font-sans`,children:[e,`: `,t]})}function wB({search:e,onSearchChange:t,caps:n,active:r,onToggle:i,onSelectAll:a,onSelectNone:o,onResetDefaults:s}){return g(`div`,{className:`absolute z-20 top-full mt-1 left-0 w-72 max-h-80 rounded-md border border-border bg-surface shadow-lg flex flex-col font-sans`,onClick:e=>e.stopPropagation(),children:[g(`div`,{className:`flex items-center gap-1 px-2 py-1.5 border-b border-border/50`,children:[N(po,{className:`h-3 w-3 text-foreground-subtle`}),N(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),placeholder:`Filter caps…`,className:`flex-1 bg-transparent text-[10px] focus:outline-none text-foreground placeholder:text-foreground-subtle`,autoFocus:!0}),e&&N(`button`,{type:`button`,onClick:()=>t(``),className:`text-foreground-subtle hover:text-foreground`,children:N(rs,{className:`h-2.5 w-2.5`})})]}),g(`div`,{className:`flex items-center gap-1 px-2 py-1 border-b border-border/50 text-[9px]`,children:[N(`button`,{type:`button`,onClick:a,className:`px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground`,children:`All`}),N(`button`,{type:`button`,onClick:o,className:`px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground`,children:`None`}),N(`button`,{type:`button`,onClick:s,className:`px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground`,children:`Defaults`})]}),g(`div`,{className:`overflow-y-auto flex-1`,children:[n.length===0&&N(`div`,{className:`text-[10px] text-foreground-subtle italic px-2 py-3 text-center`,children:`No matches`}),n.map(e=>g(`button`,{type:`button`,onClick:()=>i(e),className:`w-full flex items-center gap-2 px-2 py-1 text-left hover:bg-surface-hover/40 text-[10px]`,children:[N(`input`,{type:`checkbox`,readOnly:!0,checked:r.has(e),className:`accent-violet-500`}),N(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-violet-500/30 bg-violet-500/15 text-violet-400 px-1.5 py-0.5 text-[9px] font-medium shrink-0`,children:e})]},e))]})]})}h();var TB=500,EB=[{id:`logs`,label:`Logs`,icon:fo},{id:`events`,label:`Events`,icon:hi},{id:`state`,label:`State`,icon:qi}];function DB({deviceId:e,containerDeviceId:t,defaultEventCategories:n,defaultStateCaps:r,initialTab:i=`events`,className:a,maxHeight:o=`max-h-96`}){let[s,c]=k(i),l=Tz(TB),u=Tz(TB),d=Tz(TB),f=l.reset,p=u.reset,m=d.reset;return P(()=>{f(),p(),m()},[e,f,p,m]),g(`div`,{className:X(`flex flex-col h-full min-h-0`,a),children:[N(`div`,{className:`flex items-center gap-1 mb-2 shrink-0`,children:EB.map(({id:e,label:t,icon:n})=>g(`button`,{type:`button`,onClick:()=>c(e),className:X(`inline-flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-[11px] font-medium transition-colors`,s===e?`bg-primary/15 text-primary border border-primary/30`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover border border-transparent`),children:[N(n,{className:`h-3.5 w-3.5`}),t]},e))}),g(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:[s===`logs`&&N(Nz,{...t===void 0?{deviceId:e}:{containerDeviceId:t},maxHeight:o,showFilters:!1,liveBuffer:l}),s===`events`&&N(Yz,{deviceId:e,defaultCategories:n,maxHeight:o,showCategoryFilter:!0,liveBuffer:u}),s===`state`&&N(uB,{deviceId:e,defaultCaps:r,maxHeight:o,liveBuffer:d})]})]})}h();function OB({label:e,icon:t,title:n=`Confirm action`,description:r,confirmLabel:i,triggerVariant:a=`outline`,confirmVariant:o=`danger`,size:s=`sm`,disabled:c,className:l,action:u,onSuccess:d}){let[f,p]=k(!1),[m,h]=k(!1),[_,v]=k(null),y=async()=>{v(null),h(!0);try{let e=await u();d?.(e),p(!1)}catch(e){v(e instanceof Error?e.message:String(e))}finally{h(!1)}};return g(w,{children:[g(ps,{type:`button`,variant:a,size:s,disabled:c,onClick:()=>{v(null),p(!0)},className:l,children:[t&&N(t,{className:`h-3.5 w-3.5`}),e]}),N(Ms,{open:f,onOpenChange:e=>!m&&p(e),children:g(Fs,{children:[g(Is,{children:[g(Rs,{className:`flex items-center gap-2`,children:[N(Uo,{className:`h-4 w-4 text-amber-400`}),n]}),typeof r==`string`?N(zs,{children:r}):r]}),_&&N(`div`,{className:X(`mt-2 px-3 py-2 rounded border border-danger/40 bg-danger/10`,`text-xs text-danger`),children:_}),g(Ls,{children:[N(ps,{type:`button`,variant:`ghost`,size:s,disabled:m,onClick:()=>p(!1),children:`Cancel`}),g(ps,{type:`button`,variant:o,size:s,disabled:m,onClick:()=>{y()},children:[m&&N(Ea,{className:`h-3.5 w-3.5 animate-spin`}),i??e]})]})]})})]})}h();function kB(e,t){let n=document.createElement(`a`);n.href=t,n.download=e,document.body.appendChild(n),n.click(),document.body.removeChild(n)}function AB({trpc:e,deviceId:t,deviceName:n,size:r=`sm`,className:i}){let[a,o]=k(!1),[s,c]=k(!1),[l,d]=k(null),f=n.replace(/[^a-zA-Z0-9_.-]+/g,`_`),p=u(async n=>{o(!0),d(null),c(!1);try{let r=await e.snapshot.getSnapshot.query({deviceId:t,force:!0});if(!r)throw Error(`No snapshot available`);let i=`data:${r.contentType};base64,${r.base64}`;if(n===`copy`)try{await navigator.clipboard.writeText(i)}catch{throw Error(`Clipboard unavailable`)}else{let e=r.contentType.includes(`png`)?`png`:`jpg`;kB(`${f}-${new Date().toISOString().replace(/[:.]/g,`-`)}.${e}`,i)}c(!0),setTimeout(()=>c(!1),1500)}catch(e){d(e instanceof Error?e.message:String(e))}finally{o(!1)}},[e,t,f]),m=r===`md`?`h-9 px-3 text-sm gap-2`:`h-7 px-2.5 text-[11px] gap-1.5`,[h,_]=k(null),[v,y]=k(!1),b=()=>{y(!1),_(setTimeout(()=>{y(!0),p(`copy`)},600))},x=()=>{h&&(clearTimeout(h),_(null)),v||p(`download`)},S=()=>{h&&(clearTimeout(h),_(null))};return g(`button`,{type:`button`,title:`Click to download · long-press to copy`,disabled:a,onPointerDown:b,onPointerUp:x,onPointerLeave:S,onPointerCancel:S,className:X(`inline-flex items-center justify-center rounded-lg font-medium border border-border`,`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,`disabled:opacity-50 transition-colors`,m,l&&`border-danger/40 text-danger`,i),children:[a?N(Ea,{className:`h-3.5 w-3.5 animate-spin`}):s?N(Ci,{className:`h-3.5 w-3.5 text-success`}):N(xi,{className:`h-3.5 w-3.5`}),`Snapshot`]})}function jB(e){let t=Date.now()-e;return t<6e4?`just now`:t<36e5?`${Math.floor(t/6e4)}m ago`:t<864e5?`${Math.floor(t/36e5)}h ago`:`${Math.floor(t/864e5)}d ago`}function MB({history:e,limit:t=5,latestIsFresh:n,className:r}){if(e.length===0)return null;let i=n?mi:hi,a=e.slice(0,t);return g(`div`,{className:X(`rounded-lg border border-border bg-surface px-3 py-2`,r),children:[g(`div`,{className:`flex items-center gap-2 mb-2`,children:[N(i,{className:X(`h-4 w-4 text-amber-400`,n&&`animate-pulse`)}),N(`span`,{className:`text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Recent presses`}),N(`span`,{className:`ml-auto rounded-full bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle border border-border`,children:e.length})]}),N(`ul`,{className:`space-y-1`,children:a.map(e=>g(`li`,{className:`flex items-center justify-between text-[11px]`,title:new Date(e.timestamp).toLocaleString(),children:[N(`span`,{className:`text-foreground`,children:jB(e.timestamp)}),N(`span`,{className:`text-foreground-subtle font-mono text-[10px]`,children:new Date(e.timestamp).toLocaleTimeString()})]},`${e.deviceId}-${e.timestamp}`))})]})}h();function NB({items:e,header:t,triggerClassName:n,title:r=`More actions`}){let[i,a]=k(!1),o=e.filter(e=>!e.hidden);return o.length===0?null:g(sc,{open:i,onOpenChange:a,children:[N(cc,{title:r,className:X(`inline-flex items-center justify-center rounded-lg p-2`,`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,`border border-transparent transition-colors`,n),children:N($i,{className:`h-4 w-4`})}),g(lc,{className:`left-auto right-0 mt-1 min-w-[200px] p-1`,children:[t&&N(`div`,{className:`px-2 py-1 text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t}),N(`ul`,{className:`space-y-0.5`,children:o.map((e,t)=>g(`li`,{children:[e.separatorBefore&&t>0&&N(`div`,{className:`my-1 h-px bg-border`}),g(`button`,{type:`button`,disabled:e.disabled,onClick:()=>{e.disabled||(e.onClick(),a(!1))},className:X(`flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left text-[12px]`,`transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,e.danger?`text-foreground hover:bg-danger/10 hover:text-danger`:`text-foreground hover:bg-surface-hover`),children:[e.icon&&N(e.icon,{className:X(`h-3.5 w-3.5 shrink-0 mt-0.5`,e.danger&&`text-danger/80`)}),g(`span`,{className:`flex-1 min-w-0`,children:[N(`span`,{className:`block leading-tight`,children:e.label}),e.description&&N(`span`,{className:`block mt-0.5 text-[10px] text-foreground-subtle leading-tight`,children:e.description})]})]})]},e.id))})]})]})}h();var PB=[{value:`view`,label:`View`,icon:na,hint:`Read-only — queries + subscriptions`},{value:`create`,label:`Create`,icon:Xa,hint:`Mutations that create or update`},{value:`delete`,label:`Delete`,icon:Bo,hint:`Destructive ops (delete/revoke/reset/…)`}],FB=[`device`,`system`];function IB(){return{type:`capability`,target:``,access:[`view`]}}function LB(e){if(e==null)return[];let t=new Set;for(let n of e)if(n.type===`device`)for(let e of n.targets)t.add(e);return[...t]}function RB(e,t,n,r){let i;switch(e){case`addon`:i=n;break;case`capability`:i=r;break;case`category`:i=FB.map(e=>({value:e,label:e}));break}if(t==null)return i;let a=new Set(t.filter(t=>t.type!==`device`&&t.type===e).map(e=>e.target));return i.filter(e=>a.has(e.value))}function zB(e,t){if(t==null)return[`view`,`create`,`delete`];let n=t.filter(t=>t.type===e.type?t.type===`device`&&e.type===`device`?t.targets.some(t=>e.targets.includes(t)):t.type!==`device`&&e.type!==`device`?t.target===e.target:!1:!1);if(n.length===0)return[];let r=new Set;for(let e of n)for(let t of e.access)r.add(t);return[...r]}function BB({value:e,onChange:t,clampToParent:n,emptyHint:r}){let{data:i}=Nu(),{data:a}=Am({}),o=b(()=>(i??[]).map(e=>({value:e.manifest.id,label:e.manifest.id})).sort((e,t)=>e.label.localeCompare(t.label)),[i]),s=b(()=>[...fe].toSorted().map(e=>({value:e,label:e})),[]),c=b(()=>(a??[]).map(e=>({value:String(e.id),label:`${e.name} (#${e.id} · ${e.addonId})`})).sort((e,t)=>e.label.localeCompare(t.label)),[a]),l=b(()=>n==null?null:LB(n),[n]),u=(e,t)=>{let n=[...t];switch(e){case`category`:return{type:`category`,target:`device`,access:n};case`capability`:return{type:`capability`,target:``,access:n};case`addon`:return{type:`addon`,target:``,access:n};case`device`:return{type:`device`,targets:[],access:n}}},d=(n,r)=>{t(e.map((e,t)=>{if(t!==n)return e;if(r.type!==void 0&&r.type!==e.type)return u(r.type,r.access??e.access);let i=[...r.access??e.access];return e.type===`device`?{type:`device`,targets:[...r.targets??e.targets],access:i}:e.type===`category`?{type:`category`,target:r.target??e.target,access:i}:e.type===`capability`?{type:`capability`,target:r.target??e.target,access:i}:{type:`addon`,target:r.target??e.target,access:i}}))},f=n=>{t(e.filter((e,t)=>t!==n))};return g(`div`,{className:`space-y-2`,children:[e.length===0&&r&&N(`div`,{className:`text-[10px] text-foreground-subtle italic px-2 py-2`,children:r}),e.map((e,t)=>{let r=zB(e,n);return g(`div`,{className:`flex flex-wrap items-start gap-1.5 rounded border border-border bg-surface px-2 py-1.5`,children:[g(`select`,{value:e.type,onChange:e=>d(t,{type:e.target.value}),className:`rounded border border-border bg-background px-2 py-1 text-[11px] focus:outline-none focus:ring-1 focus:ring-primary`,children:[N(`option`,{value:`category`,children:`category`}),N(`option`,{value:`capability`,children:`capability`}),N(`option`,{value:`addon`,children:`addon`}),N(`option`,{value:`device`,children:`device`})]}),e.type===`device`?N(VB,{value:e.targets,choices:c,clampToParent:l,onChange:e=>d(t,{targets:e})}):g(`select`,{value:e.target,onChange:e=>d(t,{target:e.target.value}),className:`flex-1 min-w-[160px] rounded border border-border bg-background px-2 py-1 text-[11px] font-mono focus:outline-none focus:ring-1 focus:ring-primary`,children:[g(`option`,{value:``,children:[`— pick `,e.type,` —`]}),RB(e.type,n,o,s).map(e=>N(`option`,{value:e.value,children:e.label},e.value))]}),N(`div`,{className:`flex items-center gap-1`,children:PB.map(({value:i,label:a,icon:o,hint:s})=>{let c=e.access.includes(i),l=n!=null&&!r.includes(i)&&!c;return g(`label`,{title:l?`${s} — not granted by your scope`:s,className:`inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] cursor-pointer transition-colors ${c?`bg-primary/15 text-primary font-medium`:`text-foreground-subtle hover:bg-foreground-subtle/10`} ${l?`opacity-40 cursor-not-allowed`:``}`,children:[N(`input`,{type:`checkbox`,checked:c,disabled:l,onChange:n=>{let r=new Set(e.access);n.target.checked?r.add(i):r.delete(i),d(t,{access:[...r]})},className:`sr-only`}),N(o,{className:`h-3 w-3`}),a]},i)})}),N(`button`,{type:`button`,onClick:()=>f(t),className:`rounded p-1 text-foreground-subtle hover:bg-danger/10 hover:text-danger transition-colors`,title:`Remove scope`,children:N(rs,{className:`h-3 w-3`})})]},t)}),g(`button`,{type:`button`,onClick:()=>{t([...e,IB()])},className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-foreground-subtle/10 transition-colors`,children:[N($a,{className:`h-3 w-3`}),`Add scope`]})]})}function VB({value:e,choices:t,clampToParent:n,onChange:r}){let[i,a]=k(``),o=b(()=>{let r=n==null?t:t.filter(e=>n.includes(e.value)),i=new Set(e);return r.filter(e=>!i.has(e.value))},[t,n,e]),s=e=>t.find(t=>t.value===e)?.label??`#${e}`,c=t=>{t&&(r([...e,t]),a(``))},l=t=>{r(e.filter(e=>e!==t))};return g(`div`,{className:`flex-1 min-w-[160px] flex flex-wrap items-center gap-1`,children:[e.length===0&&N(`span`,{className:`text-[10px] text-foreground-subtle italic px-1`,children:`no devices selected`}),e.map(e=>g(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-mono text-primary`,children:[s(e),N(`button`,{type:`button`,onClick:()=>l(e),className:`hover:text-danger transition-colors`,title:`Remove device`,children:N(rs,{className:`h-2.5 w-2.5`})})]},e)),o.length>0&&g(`select`,{value:i,onChange:e=>c(e.target.value),className:`rounded border border-border bg-background px-1.5 py-0.5 text-[10px] focus:outline-none focus:ring-1 focus:ring-primary`,children:[N(`option`,{value:``,children:`+ add device…`}),o.map(e=>N(`option`,{value:e.value,children:e.label},e.value))]})]})}function HB(e){for(let t of e){if(t.type===`device`){if(t.targets.length===0)return`Scope device: pick at least one device`}else if(t.target.trim().length===0)return`Scope ${t.type}: pick a target`;if(t.access.length===0){let e=t.type===`device`?`[${t.targets.join(`,`)}]`:t.target;return`Scope ${t.type}:${e}: pick at least one access`}}return null}h();var UB=Me(`camstack:zone-editing`,null);function WB({children:e}){let[t,n]=k(!1),[r,i]=k(null),[a,o]=k(null),[s,c]=k(null),l=u(e=>{n(e),e||(i(null),o(null),c(null))},[]),d=u(e=>{i(e)},[]),f=u(e=>{o(e)},[]),p=u(e=>{n(!0),o(null),i(e),c(null)},[]),m=u(()=>{n(!1),i(null),o(null),c(null)},[]),h=u(e=>{o(e.id),c(e)},[]),g=u(e=>{c(t=>t===null?t:{...t,...e})},[]),_=u(()=>{c(null)},[]),v=b(()=>({editing:t,drawingKind:r,selectedZoneId:a,editingDraft:s,setEditing:l,setDrawingKind:d,setSelectedZoneId:f,startDrawing:p,exitEditing:m,enterDraft:h,updateDraft:g,discardDraft:_}),[t,r,a,s,l,d,f,p,m,h,g,_]);return N(UB.Provider,{value:v,children:e})}function GB(){return p(UB)}h();var KB=500,qB=800;function JB(e,t,n){try{let r=e.live;if(!r)return null;let i=r.onEvent;return!i||typeof i.subscribe!=`function`?null:i.subscribe({category:t},{onData:n})}catch{return null}}function YB(e,t){return e?.id===t}function XB(e,t){let[n,r]=k(null),[i,a]=k(null),[o,s]=k(null),[c,l]=k(`watching`),u=f(void 0),d=f(void 0),p=f(void 0);return P(()=>{if(t===null)return;let n=JB(e,`detection.motion-analysis`,e=>{let n=e;if(!YB(n?.source,t))return;let i=n.data;!i?.regions||i.regions.length===0||(r({zones:i.regions.map(e=>({...e.bbox,intensity:e.intensity})),frameWidth:i.frameWidth,frameHeight:i.frameHeight}),u.current&&clearTimeout(u.current),u.current=setTimeout(()=>r(null),KB))});return()=>{n?.unsubscribe(),u.current&&clearTimeout(u.current)}},[e,t]),P(()=>{if(t===null)return;let n=JB(e,`detection.motion-zones-raw`,e=>{let n=e;if(!YB(n?.source,t))return;let r=n.data;r?.zones&&(a({boxes:r.zones.map(e=>({bbox:e.bbox,changeScore:e.changeScore})),frameWidth:r.frameSize?.width??0,frameHeight:r.frameSize?.height??0,motionScore:r.zones.length>0?r.zones.reduce((e,t)=>e+t.changeScore,0)/r.zones.length:0}),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>a(null),KB))});return()=>{n?.unsubscribe(),d.current&&clearTimeout(d.current)}},[e,t]),P(()=>{if(t===null)return;let n=JB(e,`detection.result`,e=>{let n=e;if(!YB(n?.source,t))return;let r=n.data?.frame;r?.detections?.length&&(s({detections:r.detections,frameWidth:r.width,frameHeight:r.height}),p.current&&clearTimeout(p.current),p.current=setTimeout(()=>s(null),qB))});return()=>{n?.unsubscribe(),p.current&&clearTimeout(p.current)}},[e,t]),P(()=>{if(t===null)return;let n=JB(e,`detection.phase-transition`,e=>{let n=e;YB(n?.source,t)&&n.data?.to&&l(n.data.to)});return()=>{n?.unsubscribe()}},[e,t]),{motion:n,motionRaw:i,detection:o,phase:c}}h();function ZB(e,t,n=5e3){let[r,i]=k([]);P(()=>{if(t===null)return;let r=!1,a=()=>{e.webrtcSession.listStreams.query({deviceId:t}).then(e=>{r||i(e)}).catch(()=>{})};a();let o=setInterval(a,n);return()=>{r=!0,clearInterval(o)}},[e,t,n]);let[a,o]=k(null);P(()=>{if(t===null)return;let n=!1;return e.pipelineOrchestrator&&e.pipelineOrchestrator.getCameraMetrics.query({deviceId:t}).then(e=>{n||!e||o({phase:e.phase,detectionFps:e.actualFps,avgInferenceMs:e.avgInferenceTimeMs,droppedFrames:e.droppedFrames})}).catch(()=>{}),()=>{n=!0}},[e,t]),il(`pipeline.camera-metrics-snapshot`,e=>{if(t===null)return;let n=e.data;n.deviceId!==t||!n.metrics||o({phase:n.metrics.phase,detectionFps:n.metrics.actualFps,avgInferenceMs:n.metrics.avgInferenceTimeMs,droppedFrames:n.metrics.droppedFrames})});let{streams:s,hasWebrtc:c}=b(()=>t===null||r.length===0?{streams:[],hasWebrtc:!1}:{streams:r.map(e=>({id:e.id,label:e.label,target:e.target,status:e.status,inputFps:e.inputFps,decodeFps:e.decodeFps,bitrateKbps:e.bitrateKbps})),hasWebrtc:!0},[t,r]),l=u(async()=>{if(e.turnProvider)try{return(await e.turnProvider.getTurnServers.query()).map(e=>({urls:typeof e.urls==`string`?e.urls:[...e.urls],...e.username===void 0?{}:{username:e.username},...e.credential===void 0?{}:{credential:e.credential}}))}catch{return}},[e]),d=u(async(n,r)=>{if(t===null)throw Error(`No device selected`);let i=await e.webrtcSession.createSession.mutate({deviceId:t,target:n,hints:r}),a=await l();return{sessionId:i.sessionId,sdpOffer:i.sdpOffer,...a?{iceServers:a}:{}}},[e,t,l]),f=u(async(n,r,i)=>{if(t===null)throw Error(`No device selected`);return e.webrtcSession.handleOffer.mutate({deviceId:t,target:n,sdpOffer:r,...i===void 0?{}:{sessionId:i}})},[e,t]),p=u(async(n,r)=>{if(t===null)throw Error(`No device selected`);await e.webrtcSession.handleAnswer.mutate({deviceId:t,sessionId:n,sdpAnswer:r})},[e,t]);return{streams:s,hasWebrtc:c,pipelineMetrics:a,createSession:d,handleOffer:f,getIceServers:l,addIceCandidate:u(async(n,r)=>{t!==null&&await e.webrtcSession.addIceCandidate.mutate({deviceId:t,sessionId:n,candidate:r.candidate??``,sdpMid:r.sdpMid??null,sdpMLineIndex:r.sdpMLineIndex??null}).catch(()=>{})},[e,t]),getIceCandidates:u(async n=>t===null?{candidates:[],done:!0}:e.webrtcSession.getIceCandidates.query({deviceId:t,sessionId:n}),[e,t]),sendAnswer:p,closeSession:u(async n=>{t!==null&&await e.webrtcSession.closeSession.mutate({deviceId:t,sessionId:n}).catch(()=>{})},[e,t]),getSessionState:u(async n=>{if(t===null)return{pendingRenegotiation:null};try{return await e.webrtcSession.getSessionState.query({deviceId:t,sessionId:n})}catch{return{pendingRenegotiation:null}}},[e,t])}}h();function QB(e){let t=e?.deviceId??null,n=e?.historyLimit??20,r=ol(`doorbell.onPressed`,t===null?void 0:e=>e.deviceId===t),[i,a]=k([]);return P(()=>{r&&a(e=>{if(e.length>0&&e[0].deviceId===r.deviceId&&e[0].timestamp===r.timestamp)return e;let t=[r,...e];return t.length>n?t.slice(0,n):t})},[r,n]),{latest:r??null,history:i}}h();function $B(e){let t=Ke(),n=b(()=>e?JSON.stringify(e):``,[e]),[r,i]=k(()=>t.listDevices(e));return P(()=>{let n=()=>{i(t.listDevices(e))};n();let r=null,a=null;try{r=t.onDeviceAdded(n),a=t.onDeviceRemoved(n)}catch{}let o=t.subscribeConnectionEvents(e=>{e===`connected`&&n()});return()=>{r?.(),a?.(),o()}},[t,e,n]),r}function eV(e){let t=Ke(),[n,r]=k(()=>e===null?null:t.getDevice(e));return P(()=>{if(e===null){r(null);return}let n=()=>{r(t.getDevice(e))};n();let i=null,a=null;try{i=t.onDeviceAdded(n),a=t.onDeviceRemoved(n)}catch{}let o=t.subscribeConnectionEvents(e=>{e===`connected`&&n()});return()=>{i?.(),a?.(),o()}},[t,e]),n}function tV(e,t,n){let r=Ke();return C({queryKey:e,queryFn:()=>t(r)(),...n})}function nV(e,t){let n=Ke();return A({mutationFn:t=>e(n)(t),...t})}h();function rV(e,t){let n=Ke(),r=O(),[i,a]=k(n.connectionVersion);P(()=>n.subscribeConnectionEvents((e,t)=>{e===`connected`&&a(t)}),[n]);let o=t.join(`|`),s=JSON.stringify(e);P(()=>{let e=[],t=()=>{let e=JSON.parse(s),t=e.length===1&&Array.isArray(e[0])?e:[e];r.invalidateQueries({queryKey:t})};t();for(let r of o.split(`|`))if(r)try{e.push(n.subscribeEvent(r,t))}catch{}return()=>{for(let t of e)t()}},[n,r,o,s,i])}h();function iV(e,t,n){let r=f(null),i=f(null);(r.current===null||i.current!==e)&&(r.current=de(e),i.current=e);let a=f(void 0),o=f(null),s=o.current;return t===null?(a.current=void 0,o.current=null):(a.current===void 0||s===null||s.source!==r.current||s.deviceId!==t||s.capName!==n)&&(a.current=W(r.current,t,n),o.current={source:r.current,deviceId:t,capName:n}),Xe(a.current)}var aV=e({AddonGlobalSettingsForm:()=>TR,AgentStepEditor:()=>Vc,AlarmHeroCard:()=>CO,AlarmPanelInlineControl:()=>SO,AppShell:()=>jl,ArcKnob:()=>fu,AudioClassificationList:()=>xz,AudioLevelWaveform:()=>vz,AudioWaveform:()=>_z,AutotrackSection:()=>NF,BTN_COMPACT:()=>Ze,BTN_COMPACT_DANGER:()=>et,BTN_COMPACT_PRIMARY:()=>Pe,BTN_COMPACT_WARNING:()=>$e,Badge:()=>_s,BatteryBadge:()=>VA,BottomSheet:()=>ic,Breadcrumb:()=>yc,BrightnessPanel:()=>BE,Button:()=>ps,ButtonControl:()=>mu,ButtonHeroCard:()=>hu,CENTER:()=>ru,CHIP_ACTIVE:()=>ke,CHIP_BASE:()=>ve,CHIP_INACTIVE:()=>Qe,CLASS_COLORS:()=>hM,COLUMN_BREAKPOINT_CLASS:()=>zl,COLUMN_PRIORITY:()=>Rl,COMMIT_DEDUPE_TOLERANCE_MS:()=>750,COMMIT_DEDUPE_WINDOW_MS:()=>qr,CONTROL_CAP_NAMES:()=>tM,CONTROL_FILLS:()=>lk,CameraStreamPlayer:()=>LR,Card:()=>ys,Checkbox:()=>Os,ChildSectionAccordion:()=>ej,ClimatePanel:()=>GE,CodeBlock:()=>Dl,CollapsibleCard:()=>bs,ConfigFormBuilder:()=>xR,ConfigFormField:()=>_R,ConfigSchemaField:()=>Mc,ConfirmActionButton:()=>OB,ConfirmDialogProvider:()=>wl,ConsumablesPanel:()=>jF,ContainerChildrenProvider:()=>iA,ContainerPrimaryHero:()=>oM,ControlColumn:()=>iu,ControlHeroCard:()=>BO,ControlInlineControl:()=>zO,ControlPanel:()=>CD,CopyButton:()=>oz,CoverHeroCard:()=>Du,CoverInlineControl:()=>Su,CoverPanel:()=>$j,CustomFieldRenderersProvider:()=>eF,DEFAULT_COLOR:()=>_M,DEVICE_COLUMNS:()=>Fl,DEVICE_LIST_PAGE_SIZE_KEY:()=>cj,DEVICE_LIST_PAGE_SIZE_OPTIONS:()=>sj,DEVICE_ROLE_META:()=>xk,DEVICE_TYPE_CONTROL:()=>ck,DEVICE_TYPE_META:()=>bk,DISPLAY_ICON_REGISTRY:()=>Mk,DataTable:()=>xc,DetectionCanvas:()=>yM,DetectionOverlay:()=>ER,DetectionResultTree:()=>wM,DevShell:()=>ZP,DeviceActivityPanel:()=>DB,DeviceBatchToolbar:()=>ij,DeviceCard:()=>Nl,DeviceContextProvider:()=>rF,DeviceExportPanel:()=>gz,DeviceGrid:()=>Pl,DeviceItem:()=>tj,DeviceList:()=>Qj,Dialog:()=>Ms,DialogContent:()=>Fs,DialogDescription:()=>zs,DialogFooter:()=>Ls,DialogHeader:()=>Is,DialogTitle:()=>Rs,DialogTrigger:()=>Ns,DiscoveryPanel:()=>eB,DoorbellRecentPanel:()=>MB,Dropdown:()=>Hs,DropdownContent:()=>Ws,DropdownItem:()=>Gs,DropdownTrigger:()=>Us,DummyHeroCard:()=>ku,DummyInline:()=>Ou,EmptyState:()=>yl,ErrorBox:()=>xl,EventStream:()=>Yz,FILL:()=>tu,FanHeroCard:()=>oO,FanInlineControl:()=>jO,FanPanel:()=>VE,FilterBar:()=>Ol,FloatingEventStream:()=>Zz,FloatingLogStream:()=>Pz,FloatingPanel:()=>_c,FormField:()=>_l,GRID_GAP:()=>Ae,GRID_PAIRED:()=>be,GRID_QUICK_STATS:()=>ye,GripTrack:()=>pu,GroupedModelSelector:()=>Fc,HOST_WIDGETS:()=>UI,HlsVideo:()=>UR,HoverZoomImage:()=>qA,HumidifierHeroCard:()=>YT,HumidifierInlineControl:()=>qT,INPUT_COMPACT:()=>Ee,IconAction:()=>vA,IconButton:()=>hs,ImageHeroCard:()=>bE,ImageInlineControl:()=>yE,ImageSelector:()=>AM,InferenceConfigSelector:()=>MM,Input:()=>Es,KebabMenu:()=>NB,KeyValueList:()=>El,LIST_ROW:()=>Ve,Label:()=>xs,LawnMowerHeroCard:()=>PT,LawnMowerInlineControl:()=>MT,LightHeroCard:()=>rO,LightInlineControl:()=>kO,LockHeroCard:()=>HD,LockInlineControl:()=>OO,LockPanel:()=>zE,LogStream:()=>Nz,LoginForm:()=>UP,MODE_COLOR:()=>HE,MaskShapeCanvas:()=>oV,MediaPlayerHeroCard:()=>pO,MediaPlayerInlineControl:()=>LO,MediaPlayerPanel:()=>gD,MobileDrawer:()=>vc,MotionZonesSettings:()=>sV,NodeMultiSelectField:()=>HL,NodePicker:()=>ll,NodeSelectField:()=>VL,OfflineBadge:()=>aM,PHASE_CONFIG:()=>kr,PRIORITY:()=>pk,PTZOverlay:()=>eu,PageHeader:()=>vl,PhaseIcon:()=>wz,PipelineBuilder:()=>mM,PipelineRuntimeSelector:()=>lM,PipelineStep:()=>Oc,PipelineTreeMatrix:()=>nl,PlayerOverlaysProvider:()=>Ye,Popover:()=>sc,PopoverContent:()=>lc,PopoverRowAction:()=>iM,PopoverTrigger:()=>cc,PrimaryChildPicker:()=>cM,PrivacyMaskSettings:()=>cV,ProviderBadge:()=>pl,PtzPanel:()=>EF,QrCode:()=>CL,RECORDED_PLAYBACK_MODES:()=>Vr,RIGHT:()=>nu,ROLE_DESCRIPTOR:()=>Rw,RadialGauge:()=>JD,RecordedPlaybackProvider:()=>iI,RecordingPanel:()=>HI,ResponseLog:()=>Sz,SECTION_BODY:()=>ge,SECTION_CARD:()=>Be,SECTION_HEADER:()=>we,SPLIT_PANEL_OUTER:()=>Te,SPLIT_PANEL_SIDE:()=>De,STACK_GAP:()=>xe,STATE_COLOR:()=>uD,ScopePicker:()=>BB,ScrollArea:()=>gc,Select:()=>Ds,SemanticBadge:()=>hl,SensorHeroCard:()=>nT,SensorInlineControl:()=>qw,SensorValueAtom:()=>Gw,Separator:()=>Cs,Sidebar:()=>Al,SidebarItem:()=>kl,Skeleton:()=>ws,SlideOverPanel:()=>Sc,SlideToggle:()=>su,SnapshotButton:()=>AB,StatCard:()=>Tl,StateValuesStream:()=>uB,StatusBadge:()=>dl,StepTimings:()=>kM,StepTreeMaster:()=>Tc,Stepper:()=>ou,StreamBrokerSelector:()=>iz,StreamPanel:()=>ez,Switch:()=>ks,SwitchHeroCard:()=>sO,SwitchInlineControl:()=>EO,SwitchPanel:()=>LE,SystemProvider:()=>Ie,TEXT_FIELD_LABEL:()=>Se,TEXT_HINT:()=>Ce,TEXT_METRIC:()=>Oe,TEXT_SECTION_LABEL:()=>tt,TEXT_VALUE:()=>_e,TIMEZONES:()=>te,Tabs:()=>fc,TabsContent:()=>hc,TabsList:()=>pc,TabsTrigger:()=>mc,TapToggle:()=>YD,ThemeProvider:()=>Nt,ThermostatHeroCard:()=>FD,ThermostatInlineControl:()=>NO,TimezoneSelector:()=>TL,Tooltip:()=>Js,TooltipContent:()=>Xs,TooltipTrigger:()=>Ys,VacuumHeroCard:()=>xT,VacuumInlineControl:()=>yT,ValueReadout:()=>au,ValveHeroCard:()=>WT,ValveInlineControl:()=>zT,VersionBadge:()=>gl,VodPlaybackProvider:()=>tI,WaterHeaterHeroCard:()=>tE,WaterHeaterInlineControl:()=>$T,WeatherHeroCard:()=>fE,WeatherInlineControl:()=>sE,WidgetMetricCard:()=>Ge,WidgetPanel:()=>Je,WidgetRegistryProvider:()=>_F,WidgetSlot:()=>WI,ZoneEditingProvider:()=>WB,allDeviceTypeFilterOptions:()=>Fk,buildStepTreeFromSchema:()=>Ec,childEntityId:()=>gk,childListName:()=>Hk,cn:()=>X,columnsForContext:()=>Ll,containerChildToRef:()=>_k,countableDevices:()=>mj,coverHighlight:()=>yu,createSharedContext:()=>Me,createTheme:()=>bt,cursorFractionFor:()=>Yr,darkColors:()=>gt,defaultTheme:()=>vt,deriveDeviceKind:()=>Ik,deviceRoleMeta:()=>Dk,deviceRoleMetaOf:()=>jk,deviceTypeMeta:()=>Ek,deviceTypeMetaOf:()=>Ak,ensureMfHostInit:()=>zr,findTimezone:()=>V,formatControlDateTime:()=>br,formatLastSeen:()=>mr,formatNumeric:()=>xr,fuzzyMatch:()=>vj,getClassColor:()=>vM,getPhaseVisual:()=>Ar,groupChildrenByLayout:()=>QA,hardwareLabel:()=>Wl,humidifierTint:()=>GT,initialScrubState:()=>Wr,isAbsentProvider:()=>je,isFieldVisible:()=>gR,lawnMowerActivityMeta:()=>ST,lightColors:()=>_t,loadRemoteBundle:()=>pF,makeScrubBridge:()=>Xr,metadataEntries:()=>Gl,metadataString:()=>Ul,mirror:()=>Or,mountAddonPage:()=>QP,nextSort:()=>Kj,normalizeForSearch:()=>_j,overrideEntityIdFromLink:()=>vk,parseRecordedServerMessage:()=>Ur,providerIcons:()=>ss,resolveContainerPrimary:()=>yk,resolveControlAlign:()=>fk,resolveDeviceControl:()=>dk,resolveDisplayIcon:()=>Nk,resolvePrimaryChild:()=>mk,resolveSensorDisplay:()=>Cr,scrubReducer:()=>Gr,serializeRecordedCommand:()=>Br,shouldCommit:()=>Jr,shouldEmit:()=>Kr,sortRows:()=>qj,statusIcons:()=>cs,stripParentNamePrefix:()=>Vk,tankAlert:()=>hT,themeToCss:()=>Dt,trpc:()=>Z,useAccessoriesGetStatus:()=>ju,useAccessoriesSetChildHidden:()=>Au,useAddonPagesListPages:()=>Mu,useAddonSettingsGetDeviceSettings:()=>hd,useAddonSettingsGetGlobalSettings:()=>pd,useAddonSettingsUpdateDeviceSettings:()=>gd,useAddonSettingsUpdateGlobalSettings:()=>md,useAddonWidgetsListWidgets:()=>_d,useAddonsApplyAutoUpdateToAll:()=>od,useAddonsCancelJob:()=>dd,useAddonsCustom:()=>sd,useAddonsForceRefresh:()=>Ku,useAddonsGetAddonAutoUpdate:()=>id,useAddonsGetAutoUpdateSettings:()=>nd,useAddonsGetJob:()=>ld,useAddonsGetLastRestart:()=>Ju,useAddonsGetLogs:()=>Pu,useAddonsGetVersions:()=>$u,useAddonsInstallFromWorkspace:()=>Lu,useAddonsInstallPackage:()=>Iu,useAddonsIsWorkspaceAvailable:()=>Ru,useAddonsList:()=>Nu,useAddonsListCapabilityProviders:()=>Xu,useAddonsListFrameworkPackages:()=>Yu,useAddonsListJobs:()=>ud,useAddonsListPackages:()=>Fu,useAddonsListUpdates:()=>Uu,useAddonsListWorkspacePackages:()=>zu,useAddonsOnAddonLogs:()=>fd,useAddonsReloadPackages:()=>Vu,useAddonsRestartAddon:()=>ed,useAddonsRestartServer:()=>qu,useAddonsRetryLoad:()=>td,useAddonsRollbackPackage:()=>Gu,useAddonsSearchAvailable:()=>Hu,useAddonsSetAddonAutoUpdate:()=>ad,useAddonsSetAutoUpdateSettings:()=>rd,useAddonsSetCapabilityProviderEnabled:()=>Zu,useAddonsStartJob:()=>cd,useAddonsUninstallPackage:()=>Bu,useAddonsUpdateFrameworkPackage:()=>Qu,useAddonsUpdatePackage:()=>Wu,useAirQualitySensorGetStatus:()=>vd,useAlarmPanelArm:()=>yd,useAlarmPanelDisarm:()=>bd,useAlarmPanelGetStatus:()=>Sd,useAlarmPanelTrigger:()=>xd,useAlertsDismiss:()=>kd,useAlertsEmit:()=>Cd,useAlertsGetUnreadCount:()=>Ed,useAlertsList:()=>Td,useAlertsMarkAllRead:()=>Od,useAlertsMarkRead:()=>Dd,useAlertsUpdate:()=>wd,useAllWidgets:()=>bF,useAmbientLightSensorGetStatus:()=>Ad,useAudioAnalysisApplyDeviceSettingsPatch:()=>Pd,useAudioAnalysisGetDeviceLiveContribution:()=>Nd,useAudioAnalysisGetDeviceSettingsContribution:()=>Md,useAudioAnalysisResolveDeviceSettings:()=>jd,useAudioAnalyzerAnalyseChunk:()=>Fd,useAudioAnalyzerClassify:()=>Id,useAudioAnalyzerDispose:()=>Rd,useAudioAnalyzerIsReady:()=>Ld,useAudioAnalyzerReprobeAudioEngine:()=>zd,useAudioCodecCanHandle:()=>Vd,useAudioCodecCloseSession:()=>Wd,useAudioCodecCreateDecodeSession:()=>Hd,useAudioCodecCreateEncodeSession:()=>Ud,useAudioCodecFlushEncode:()=>Yd,useAudioCodecListActiveSessions:()=>Xd,useAudioCodecListSupportedCodecs:()=>Bd,useAudioCodecPullEncoded:()=>Jd,useAudioCodecPullPcm:()=>Kd,useAudioCodecPushEncodedFrame:()=>Gd,useAudioCodecPushPcm:()=>qd,useAudioMetricsGetCurrentSnapshot:()=>Zd,useAudioMetricsGetHistory:()=>Qd,useAutomationControlDisable:()=>ef,useAutomationControlEnable:()=>$d,useAutomationControlGetStatus:()=>nf,useAutomationControlTrigger:()=>tf,useBackupDelete:()=>uf,useBackupGetEntries:()=>cf,useBackupList:()=>of,useBackupListArchives:()=>df,useBackupListDestinations:()=>rf,useBackupListLocations:()=>sf,useBackupPreviewSchedule:()=>pf,useBackupRestore:()=>lf,useBackupTrigger:()=>af,useBackupUpsertDestinationPolicy:()=>ff,useBatteryGetStatus:()=>hf,useBatteryWakeForStream:()=>mf,useBinaryGetStatus:()=>gf,useBrightnessGetStatus:()=>vf,useBrightnessSetBrightness:()=>_f,useBrokerAdd:()=>Sf,useBrokerGet:()=>bf,useBrokerGetBrokerConfig:()=>Df,useBrokerGetSettings:()=>Tf,useBrokerGetSettingsSchema:()=>Of,useBrokerGetState:()=>Nf,useBrokerGetStatus:()=>Pf,useBrokerList:()=>yf,useBrokerListProviders:()=>xf,useBrokerPublish:()=>Af,useBrokerRemove:()=>Cf,useBrokerSetSettings:()=>Ef,useBrokerSubscribe:()=>jf,useBrokerTestConnection:()=>wf,useBrokerTestSettings:()=>kf,useBrokerUnsubscribe:()=>Mf,useButtonPress:()=>Ff,useCameraCredentialsGetCredentials:()=>If,useCameraCredentialsGetStatus:()=>Lf,useCameraPipelineConfigApplyDeviceSettingsPatch:()=>Bf,useCameraPipelineConfigGetDeviceLiveContribution:()=>zf,useCameraPipelineConfigGetDeviceSettingsContribution:()=>Rf,useCameraStreamsGetBrokerStreams:()=>Hf,useCameraStreamsGetCameraStreams:()=>Vf,useCameraStreamsGetProfileRtspEntries:()=>Wf,useCameraStreamsGetRtspEntries:()=>Uf,useCameraStreamsPickStream:()=>Gf,useCarbonMonoxideGetStatus:()=>Kf,useClimateControlGetStatus:()=>tp,useClimateControlSetFanMode:()=>Jf,useClimateControlSetMode:()=>qf,useClimateControlSetPreset:()=>Yf,useClimateControlSetSwingHorizontal:()=>ep,useClimateControlSetSwingVertical:()=>$f,useClimateControlSetTarget:()=>Xf,useClimateControlSetTargetHumidity:()=>Qf,useClimateControlSetTargetRange:()=>Zf,useClusterNodes:()=>cl,useColorGetStatus:()=>rp,useColorSetColor:()=>np,useConfirm:()=>Cl,useConnectivityGetStatus:()=>ip,useConsumablesGetStatus:()=>op,useConsumablesReset:()=>ap,useContactGetStatus:()=>sp,useContainerChildren:()=>aA,useControlGetStatus:()=>lp,useControlSetValue:()=>cp,useCoverClose:()=>dp,useCoverGetStatus:()=>hp,useCoverOpen:()=>up,useCoverSetPosition:()=>pp,useCoverSetTiltPosition:()=>mp,useCoverStop:()=>fp,useCustomFieldRenderer:()=>tF,useDayNightGetOptions:()=>gp,useDayNightGetStatus:()=>vp,useDayNightSetSettings:()=>_p,useDebouncedString:()=>oj,useDecoderCreateSession:()=>xp,useDecoderDestroySession:()=>Sp,useDecoderGetFrame:()=>Dp,useDecoderGetInfo:()=>bp,useDecoderGetShmStats:()=>Op,useDecoderGetStats:()=>Ap,useDecoderListActiveSessions:()=>jp,useDecoderOpenStream:()=>wp,useDecoderPullFrames:()=>Tp,useDecoderPullHandles:()=>Ep,useDecoderPushPacket:()=>Cp,useDecoderReprobeHwaccel:()=>Mp,useDecoderSupportsCodec:()=>yp,useDecoderUpdateConfig:()=>kp,useDetectionPipelineApplyDeviceSettingsPatch:()=>Fp,useDetectionPipelineGetDeviceLiveContribution:()=>Pp,useDetectionPipelineGetDeviceSettingsContribution:()=>Np,useDevShell:()=>KP,useDevice:()=>eV,useDeviceAdoptionAdopt:()=>Bp,useDeviceAdoptionGetCandidate:()=>Rp,useDeviceAdoptionGetStatus:()=>Up,useDeviceAdoptionListCandidateFilters:()=>Ip,useDeviceAdoptionListCandidates:()=>Lp,useDeviceAdoptionRefresh:()=>zp,useDeviceAdoptionRelease:()=>Vp,useDeviceAdoptionResync:()=>Hp,useDeviceAutotrack:()=>MF,useDeviceBattery:()=>IA,useDeviceCapSlice:()=>iV,useDeviceCapability:()=>Q,useDeviceDetections:()=>XB,useDeviceDiscoveryAdoptDevice:()=>Kp,useDeviceDiscoveryGetStatus:()=>Jp,useDeviceDiscoveryListDiscovered:()=>Wp,useDeviceDiscoveryRefreshDiscovery:()=>Gp,useDeviceDiscoveryReleaseDevice:()=>qp,useDeviceExportApplyDeviceSettingsPatch:()=>nm,useDeviceExportExposeDevice:()=>Qp,useDeviceExportGetDeviceLiveContribution:()=>tm,useDeviceExportGetDeviceSettingsContribution:()=>em,useDeviceExportGetStatus:()=>Yp,useDeviceExportListExposedDevices:()=>Zp,useDeviceExportListSupportedDeviceKinds:()=>Xp,useDeviceExportUnexposeDevice:()=>$p,useDeviceId:()=>iF,useDeviceListPageSize:()=>pj,useDeviceManagerAddLocation:()=>Em,useDeviceManagerAdoptDevice:()=>nh,useDeviceManagerAdoptionAdopt:()=>lh,useDeviceManagerAdoptionListCandidateFilters:()=>oh,useDeviceManagerAdoptionListCandidates:()=>sh,useDeviceManagerAdoptionRefresh:()=>ch,useDeviceManagerAdoptionRelease:()=>uh,useDeviceManagerAdoptionResync:()=>dh,useDeviceManagerAllocateDeviceId:()=>rm,useDeviceManagerApplyInitialMeta:()=>Cm,useDeviceManagerCreateDevice:()=>ih,useDeviceManagerDisable:()=>Rm,useDeviceManagerDiscoverAllProviders:()=>ph,useDeviceManagerDiscoverDevices:()=>th,useDeviceManagerDiscoverProvider:()=>mh,useDeviceManagerDiscoveryProviders:()=>fh,useDeviceManagerEnable:()=>Lm,useDeviceManagerGetAllBindings:()=>Gm,useDeviceManagerGetBindings:()=>Wm,useDeviceManagerGetChildren:()=>Mm,useDeviceManagerGetConfigSchema:()=>Pm,useDeviceManagerGetCreationSchema:()=>rh,useDeviceManagerGetDevice:()=>jm,useDeviceManagerGetDeviceAggregate:()=>Zm,useDeviceManagerGetDeviceLiveInfoAggregate:()=>Xm,useDeviceManagerGetDeviceSettingsAggregate:()=>Ym,useDeviceManagerGetDeviceStatusAggregate:()=>vh,useDeviceManagerGetRoleDisplayDefaults:()=>ym,useDeviceManagerGetSettingsSchema:()=>Fm,useDeviceManagerGetStreamProfileMap:()=>Vm,useDeviceManagerGetStreamSources:()=>Nm,useDeviceManagerGetWireableFields:()=>xm,useDeviceManagerListAll:()=>Am,useDeviceManagerListBindableCapsForDeviceType:()=>Jm,useDeviceManagerListLocations:()=>Tm,useDeviceManagerListPersistedByAddon:()=>km,useDeviceManagerListWrappersForCap:()=>qm,useDeviceManagerLoadConfig:()=>sm,useDeviceManagerLoadMeta:()=>lm,useDeviceManagerLoadRuntimeState:()=>cm,useDeviceManagerPersistConfig:()=>om,useDeviceManagerProbeStreams:()=>Um,useDeviceManagerProviderCreationType:()=>hh,useDeviceManagerProviderDiscoveryParamsSchema:()=>gh,useDeviceManagerRegisterDevice:()=>im,useDeviceManagerRemove:()=>zm,useDeviceManagerRemoveByIntegration:()=>Bm,useDeviceManagerRemoveDevice:()=>am,useDeviceManagerRemoveLocation:()=>Dm,useDeviceManagerRunDeviceAction:()=>Qm,useDeviceManagerSetChildLayout:()=>gm,useDeviceManagerSetDeviceLinks:()=>_m,useDeviceManagerSetDisabled:()=>Om,useDeviceManagerSetDisplay:()=>vm,useDeviceManagerSetIntegrationId:()=>pm,useDeviceManagerSetLinkDeviceId:()=>mm,useDeviceManagerSetLocation:()=>dm,useDeviceManagerSetMetadata:()=>wm,useDeviceManagerSetName:()=>um,useDeviceManagerSetPrimaryChildEntityId:()=>hm,useDeviceManagerSetRole:()=>Sm,useDeviceManagerSetRoleDisplayDefaults:()=>bm,useDeviceManagerSetStreamProfileMap:()=>Hm,useDeviceManagerSetType:()=>fm,useDeviceManagerSetWrapperActive:()=>Km,useDeviceManagerTestCreationField:()=>ah,useDeviceManagerTestField:()=>_h,useDeviceManagerUpdateConfig:()=>Im,useDeviceManagerUpdateDeviceField:()=>$m,useDeviceManagerUpdateDeviceFieldsBatch:()=>eh,useDeviceOpsGetConfigEntries:()=>bh,useDeviceOpsGetRawState:()=>Th,useDeviceOpsGetSettingsSchema:()=>wh,useDeviceOpsGetStreamSources:()=>yh,useDeviceOpsRemoveDevice:()=>Ch,useDeviceOpsRunAction:()=>Sh,useDeviceOpsSetConfig:()=>xh,useDeviceProviderAdoptDiscoveredDevice:()=>Ph,useDeviceProviderCreateDevice:()=>Lh,useDeviceProviderDiscoverDevices:()=>jh,useDeviceProviderGetChildCreationSchema:()=>Ih,useDeviceProviderGetDevices:()=>kh,useDeviceProviderGetDiscoveryParamsSchema:()=>Mh,useDeviceProviderGetManualCreationType:()=>Nh,useDeviceProviderGetStatus:()=>Oh,useDeviceProviderStart:()=>Eh,useDeviceProviderStop:()=>Dh,useDeviceProviderSupportsDiscovery:()=>Ah,useDeviceProviderSupportsManualCreation:()=>Fh,useDeviceProviderTestCreationField:()=>Rh,useDeviceProxy:()=>Fe,useDeviceSnapshot:()=>aF,useDeviceSnapshotImage:()=>LA,useDeviceState:()=>He,useDeviceStateGetAllSnapshots:()=>Vh,useDeviceStateGetCapSlice:()=>Bh,useDeviceStateGetSnapshot:()=>zh,useDeviceStateSetCapSlice:()=>Hh,useDeviceStateSlice:()=>Xe,useDeviceStatusGetStatus:()=>Uh,useDeviceWebrtc:()=>ZB,useDevices:()=>$B,useDoorbellEvents:()=>QB,useDoorbellGetStatus:()=>Wh,useEnumSensorGetStatus:()=>Gh,useEventEmitterGetStatus:()=>Kh,useEventInvalidation:()=>rV,useEventStreamLatest:()=>ol,useEventStreamMap:()=>sl,useEventsGetEventClipUrl:()=>Yh,useEventsGetEventThumbnail:()=>Jh,useEventsGetEvents:()=>qh,useFaceGalleryAssignFace:()=>ag,useFaceGalleryAssignFaces:()=>cg,useFaceGalleryCreateIdentity:()=>Zh,useFaceGalleryDeleteFace:()=>sg,useFaceGalleryDeleteIdentity:()=>$h,useFaceGalleryGetFaceByTrack:()=>rg,useFaceGalleryGetFaceMedia:()=>ig,useFaceGalleryListIdentities:()=>Xh,useFaceGalleryListIdentitySamples:()=>eg,useFaceGalleryListRecentFaces:()=>ng,useFaceGalleryRemoveSample:()=>tg,useFaceGalleryRenameIdentity:()=>Qh,useFaceGallerySuggestFaceClusters:()=>ug,useFaceGalleryUnassignFace:()=>og,useFaceGalleryUnassignFaces:()=>lg,useFanControlGetStatus:()=>hg,useFanControlSetDirection:()=>pg,useFanControlSetOscillating:()=>mg,useFanControlSetPercentage:()=>dg,useFanControlSetPreset:()=>fg,useFeatureProbeGetStatus:()=>gg,useFloodGetStatus:()=>_g,useGasGetStatus:()=>vg,useHumidifierGetStatus:()=>Sg,useHumidifierSetMode:()=>xg,useHumidifierSetOn:()=>yg,useHumidifierSetTargetHumidity:()=>bg,useHumiditySensorGetStatus:()=>Cg,useImageGetStatus:()=>wg,useImageSettingsGetOptions:()=>Tg,useImageSettingsGetStatus:()=>Dg,useImageSettingsSetSettings:()=>Eg,useIntegrationsCreate:()=>jg,useIntegrationsDelete:()=>Ng,useIntegrationsGet:()=>kg,useIntegrationsGetAvailableTypes:()=>Ig,useIntegrationsGetByAddonId:()=>Ag,useIntegrationsGetSettings:()=>Pg,useIntegrationsList:()=>Og,useIntegrationsSetSettings:()=>Fg,useIntegrationsTestConnection:()=>Lg,useIntegrationsUpdate:()=>Mg,useIntercomEndTalkSession:()=>Ug,useIntercomGetStatus:()=>Wg,useIntercomHandleAnswer:()=>zg,useIntercomPushTalkAudio:()=>Hg,useIntercomStartSession:()=>Rg,useIntercomStartTalkSession:()=>Vg,useIntercomStopSession:()=>Bg,useIsMidWidth:()=>rc,useIsMobile:()=>nc,useLawnMowerControlDock:()=>qg,useLawnMowerControlGetStatus:()=>Jg,useLawnMowerControlPause:()=>Kg,useLawnMowerControlStartMowing:()=>Gg,useLiveBuffer:()=>Tz,useLiveEvent:()=>il,useLocalNetworkGetAllowedAddresses:()=>Qg,useLocalNetworkGetConnectionEndpoints:()=>Zg,useLocalNetworkGetPreferred:()=>Xg,useLocalNetworkList:()=>Yg,useLocalNetworkResetAllowlistToBestMatch:()=>e_,useLocalNetworkSetAllowedAddresses:()=>$g,useLockControlGetStatus:()=>i_,useLockControlLock:()=>t_,useLockControlOpen:()=>r_,useLockControlUnlock:()=>n_,useMediaPlayerGetStatus:()=>__,useMediaPlayerNext:()=>c_,useMediaPlayerPause:()=>o_,useMediaPlayerPlay:()=>a_,useMediaPlayerPlayMedia:()=>g_,useMediaPlayerPrevious:()=>l_,useMediaPlayerSeek:()=>u_,useMediaPlayerSelectSource:()=>h_,useMediaPlayerSetMute:()=>f_,useMediaPlayerSetRepeat:()=>m_,useMediaPlayerSetShuffle:()=>p_,useMediaPlayerSetVolume:()=>d_,useMediaPlayerStop:()=>s_,useMeshNetworkGetStatus:()=>v_,useMeshNetworkJoin:()=>y_,useMeshNetworkLeave:()=>x_,useMeshNetworkListPeers:()=>C_,useMeshNetworkLogout:()=>S_,useMeshNetworkStartLogin:()=>b_,useMeshNetworkTestConnection:()=>w_,useMetricsProviderCollectSnapshot:()=>T_,useMetricsProviderDumpHeapSnapshot:()=>I_,useMetricsProviderGetAddonStats:()=>N_,useMetricsProviderGetCached:()=>E_,useMetricsProviderGetCpuTemperature:()=>A_,useMetricsProviderGetCurrent:()=>D_,useMetricsProviderGetDiskSpace:()=>O_,useMetricsProviderGetGpuInfo:()=>k_,useMetricsProviderGetProcessStats:()=>j_,useMetricsProviderKillProcess:()=>F_,useMetricsProviderListAddonInstances:()=>M_,useMetricsProviderListNodeProcesses:()=>P_,useMotionDetectionAnalyze:()=>z_,useMotionDetectionApplyDeviceSettingsPatch:()=>W_,useMotionDetectionGetDeviceLiveContribution:()=>U_,useMotionDetectionGetDeviceSettingsContribution:()=>H_,useMotionDetectionRemoveCamera:()=>B_,useMotionDetectionReset:()=>V_,useMotionGetStatus:()=>R_,useMotionIsDetected:()=>L_,useMotionTriggerGetStatus:()=>K_,useMotionTriggerSetMotionTrigger:()=>G_,useMotionZonesGetOptions:()=>q_,useMotionZonesGetStatus:()=>Y_,useMotionZonesSetZone:()=>J_,useMqttBrokerAddBroker:()=>Q_,useMqttBrokerGetBrokerConfig:()=>Z_,useMqttBrokerGetStatus:()=>rv,useMqttBrokerListBrokers:()=>X_,useMqttBrokerRemoveBroker:()=>$_,useMqttBrokerStartEmbeddedBroker:()=>tv,useMqttBrokerStopEmbeddedBroker:()=>nv,useMqttBrokerTestConnection:()=>ev,useNativeObjectDetectionGetStatus:()=>av,useNativeObjectDetectionSetEnabled:()=>iv,useNetworkAccessGetEndpoint:()=>cv,useNetworkAccessGetStatus:()=>lv,useNetworkAccessListEndpoints:()=>uv,useNetworkAccessStart:()=>ov,useNetworkAccessStop:()=>sv,useNetworkQualityGetAllStats:()=>fv,useNetworkQualityGetDeviceStats:()=>dv,useNetworkQualityReportClientStats:()=>pv,useNodesClusterAddonStatus:()=>Sv,useNodesDeployAddon:()=>hv,useNodesExecuteQuery:()=>Ev,useNodesGetCapUsageGraph:()=>Cv,useNodesGetNodeAddons:()=>wv,useNodesRenameNode:()=>xv,useNodesRestartAddon:()=>_v,useNodesRestartNode:()=>yv,useNodesRestartProcess:()=>vv,useNodesSetProcessLogLevel:()=>Tv,useNodesShutdownNode:()=>bv,useNodesTopology:()=>mv,useNodesUndeployAddon:()=>gv,useNotificationOutputDeleteTarget:()=>Nv,useNotificationOutputDiscoverTargets:()=>kv,useNotificationOutputListTargetKinds:()=>Dv,useNotificationOutputListTargets:()=>Ov,useNotificationOutputSend:()=>Av,useNotificationOutputSetTargetEnabled:()=>Pv,useNotificationOutputTestTarget:()=>jv,useNotificationOutputUpsertTarget:()=>Mv,useNotifierCancel:()=>Iv,useNotifierGetStatus:()=>Lv,useNotifierSend:()=>Fv,useNumericSensorGetStatus:()=>Rv,useOptimisticSlice:()=>vu,useOptionalSystem:()=>Le,useOptionalWidgetRegistry:()=>CF,useOsdGetStatus:()=>Bv,useOsdSetOverlay:()=>zv,usePTZ:()=>Ql,usePetFeederCallPet:()=>Gv,usePetFeederCancelFeed:()=>Hv,usePetFeederFeed:()=>Vv,usePetFeederGetStatus:()=>Zv,usePetFeederMarkFoodReplenished:()=>Wv,usePetFeederPlaySound:()=>Kv,usePetFeederResetDesiccant:()=>Uv,usePetFeederSetChildLock:()=>qv,usePetFeederSetFeedSound:()=>Yv,usePetFeederSetIndicatorLight:()=>Jv,usePetFeederSetVolume:()=>Xv,usePipelineAnalyticsApplyDeviceSettingsPatch:()=>fy,usePipelineAnalyticsClearTracks:()=>ty,usePipelineAnalyticsGetActiveTracks:()=>Qv,usePipelineAnalyticsGetAudioEvents:()=>iy,usePipelineAnalyticsGetDeviceLiveContribution:()=>dy,usePipelineAnalyticsGetDeviceSettingsContribution:()=>uy,usePipelineAnalyticsGetEventDensity:()=>ay,usePipelineAnalyticsGetEventMedia:()=>sy,usePipelineAnalyticsGetMotionEvents:()=>ny,usePipelineAnalyticsGetObjectEvents:()=>ry,usePipelineAnalyticsGetTrack:()=>$v,usePipelineAnalyticsGetTrackMedia:()=>cy,usePipelineAnalyticsListTracks:()=>ey,usePipelineAnalyticsPruneEventsBefore:()=>oy,usePipelineAnalyticsSearchObjectEvents:()=>ly,usePipelineExecutorCacheFrameInPool:()=>Iy,usePipelineExecutorClearDeviceOverrides:()=>by,usePipelineExecutorDeleteModel:()=>Ny,usePipelineExecutorDeleteTemplate:()=>ky,usePipelineExecutorDownloadModel:()=>My,usePipelineExecutorGetAddonModels:()=>jy,usePipelineExecutorGetAudioCapabilities:()=>qy,usePipelineExecutorGetAvailableEngines:()=>py,usePipelineExecutorGetCapabilities:()=>Ay,usePipelineExecutorGetDefaultSteps:()=>hy,usePipelineExecutorGetDetectionConfigSchema:()=>Yy,usePipelineExecutorGetEffectiveTuning:()=>zy,usePipelineExecutorGetEngineProvisioning:()=>_y,usePipelineExecutorGetGlobalPipelineConfig:()=>Cy,usePipelineExecutorGetGlobalSteps:()=>Sy,usePipelineExecutorGetOrchestratorConfigSchema:()=>wy,usePipelineExecutorGetReferenceAudio:()=>Ky,usePipelineExecutorGetReferenceAudioFiles:()=>Gy,usePipelineExecutorGetReferenceImage:()=>Wy,usePipelineExecutorGetSchema:()=>xy,usePipelineExecutorGetSelectedEngine:()=>my,usePipelineExecutorGetVideoPipelineSteps:()=>vy,usePipelineExecutorInferCached:()=>Ly,usePipelineExecutorKillEngine:()=>Hy,usePipelineExecutorListLoadedEngines:()=>By,usePipelineExecutorListReferenceImages:()=>Uy,usePipelineExecutorListTemplates:()=>Ey,usePipelineExecutorReprobeEngine:()=>gy,usePipelineExecutorRunAudioTest:()=>Jy,usePipelineExecutorRunPipeline:()=>Py,usePipelineExecutorRunPipelineBatch:()=>Fy,usePipelineExecutorSaveTemplate:()=>Dy,usePipelineExecutorSetVideoPipelineSteps:()=>yy,usePipelineExecutorSpinEngine:()=>Vy,usePipelineExecutorUncacheFrame:()=>Ry,usePipelineExecutorUpdateTemplate:()=>Oy,usePipelineExecutorValidatePipeline:()=>Ty,usePipelineOrchestratorApplyDeviceSettingsPatch:()=>Fb,usePipelineOrchestratorAssignAudio:()=>sb,usePipelineOrchestratorAssignPipeline:()=>Xy,usePipelineOrchestratorDeleteTemplate:()=>Mb,usePipelineOrchestratorGetAgentLoad:()=>tb,usePipelineOrchestratorGetAgentSettings:()=>fb,usePipelineOrchestratorGetAudioAssignment:()=>lb,usePipelineOrchestratorGetAudioAssignments:()=>db,usePipelineOrchestratorGetAudioNodeLoad:()=>ub,usePipelineOrchestratorGetCameraMetrics:()=>rb,usePipelineOrchestratorGetCameraSettings:()=>xb,usePipelineOrchestratorGetCameraStatus:()=>Db,usePipelineOrchestratorGetCameraStatuses:()=>Ob,usePipelineOrchestratorGetCameraStepOverrides:()=>Cb,usePipelineOrchestratorGetCapabilityBindings:()=>ib,usePipelineOrchestratorGetDeviceLiveContribution:()=>Pb,usePipelineOrchestratorGetDeviceSettingsContribution:()=>Nb,usePipelineOrchestratorGetGlobalMetrics:()=>nb,usePipelineOrchestratorGetIngestOwner:()=>ob,usePipelineOrchestratorGetPipelineAssignment:()=>eb,usePipelineOrchestratorGetPipelineAssignments:()=>$y,usePipelineOrchestratorListAgentSettings:()=>pb,usePipelineOrchestratorListTemplates:()=>kb,usePipelineOrchestratorRebalance:()=>Qy,usePipelineOrchestratorRemoveAgentSettings:()=>hb,usePipelineOrchestratorResetNodePipelineDefaults:()=>bb,usePipelineOrchestratorResolvePipeline:()=>Eb,usePipelineOrchestratorSaveTemplate:()=>Ab,usePipelineOrchestratorSetAgentAddonDefaults:()=>mb,usePipelineOrchestratorSetAgentCapabilities:()=>vb,usePipelineOrchestratorSetAgentDetectWeight:()=>_b,usePipelineOrchestratorSetAgentMaxCameras:()=>gb,usePipelineOrchestratorSetAgentReachableHost:()=>yb,usePipelineOrchestratorSetCameraPipelineForAgent:()=>Tb,usePipelineOrchestratorSetCameraStepOverride:()=>wb,usePipelineOrchestratorSetCameraStepToggle:()=>Sb,usePipelineOrchestratorSetCapabilityBinding:()=>ab,usePipelineOrchestratorUnassignAudio:()=>cb,usePipelineOrchestratorUnassignPipeline:()=>Zy,usePipelineOrchestratorUpdateTemplate:()=>jb,usePipelineRunnerAttachCamera:()=>Ib,usePipelineRunnerDetachCamera:()=>Lb,usePipelineRunnerGetAllCameraMetrics:()=>Hb,usePipelineRunnerGetCameraMetrics:()=>Vb,usePipelineRunnerGetLocalCameras:()=>Ub,usePipelineRunnerGetLocalLoad:()=>zb,usePipelineRunnerGetLocalMetrics:()=>Bb,usePipelineRunnerReportMotion:()=>Rb,usePlateGalleryCorrectPlateText:()=>Yb,usePlateGalleryDeletePlate:()=>Xb,usePlateGalleryGetPlateByTrack:()=>Gb,usePlateGalleryGetPlateMedia:()=>Kb,usePlateGalleryListPlates:()=>Wb,usePlateGallerySearchPlates:()=>qb,usePlateGallerySuggestPlateClusters:()=>Jb,usePlayerOverlayLayer:()=>We,usePlayerOverlayLayers:()=>qe,usePlayerToolbarButton:()=>ze,usePlayerToolbarButtons:()=>Ne,usePowerMeterGetStatus:()=>Zb,usePresenceGetStatus:()=>Qb,usePressureSensorGetStatus:()=>$b,usePrivacyMaskGetOptions:()=>ex,usePrivacyMaskGetStatus:()=>nx,usePrivacyMaskSetMask:()=>tx,usePtzAutotrackGetSettings:()=>_x,usePtzAutotrackGetStatus:()=>hx,usePtzAutotrackSetEnabled:()=>gx,usePtzAutotrackSetSettings:()=>vx,usePtzContinuousMove:()=>ix,usePtzDeletePreset:()=>lx,usePtzGetOptions:()=>ux,usePtzGetPosition:()=>fx,usePtzGetPresets:()=>ox,usePtzGetStatus:()=>mx,usePtzGoHome:()=>dx,usePtzGoToPreset:()=>sx,usePtzMove:()=>rx,usePtzSavePreset:()=>cx,usePtzSetAutofocus:()=>px,usePtzStop:()=>ax,useRebootReboot:()=>yx,useRecordedPlayback:()=>aI,useRecordingApplyDeviceSettingsPatch:()=>Nx,useRecordingGetAvailability:()=>bx,useRecordingGetDaysWithRecordings:()=>xx,useRecordingGetDeviceConfig:()=>wx,useRecordingGetDeviceLiveContribution:()=>Mx,useRecordingGetDeviceSettingsContribution:()=>jx,useRecordingGetPlaybackManifest:()=>Sx,useRecordingGetStatus:()=>Ax,useRecordingGetStorageUsage:()=>Cx,useRecordingLocateSegment:()=>Tx,useRecordingPruneFootage:()=>kx,useRecordingReadSegmentBytes:()=>Ex,useRecordingRescanStorage:()=>Ox,useRecordingSetDeviceConfig:()=>Dx,useRemoteComponent:()=>xF,useScriptRunnerGetStatus:()=>Ix,useScriptRunnerRun:()=>Px,useScriptRunnerStop:()=>Fx,useScrubController:()=>Zr,useServerManagementApplyServerUpdate:()=>zx,useServerManagementCheckServerUpdate:()=>Rx,useServerManagementGetServerPackageStatus:()=>Lx,useServerManagementRestartServer:()=>Vx,useServerManagementRollbackServerUpdate:()=>Bx,useSettingsStoreCount:()=>Jx,useSettingsStoreDeclareCollection:()=>Zx,useSettingsStoreDelete:()=>qx,useSettingsStoreGet:()=>Hx,useSettingsStoreHistogram:()=>Yx,useSettingsStoreInsert:()=>Gx,useSettingsStoreIsEmpty:()=>Xx,useSettingsStoreQuery:()=>Wx,useSettingsStoreSet:()=>Ux,useSettingsStoreUpdate:()=>Kx,useSmokeGetStatus:()=>Qx,useSnapshotApplyDeviceSettingsPatch:()=>iS,useSnapshotGetDeviceLiveContribution:()=>rS,useSnapshotGetDeviceSettingsContribution:()=>nS,useSnapshotGetSnapshot:()=>$x,useSnapshotGetStatus:()=>tS,useSnapshotInvalidateCache:()=>eS,useStorageAbortUpload:()=>hS,useStorageBeginDownload:()=>gS,useStorageBeginUpload:()=>fS,useStorageDelete:()=>uS,useStorageDeleteLocation:()=>CS,useStorageEndDownload:()=>vS,useStorageExists:()=>cS,useStorageFinalizeUpload:()=>mS,useStorageGetAvailableSpace:()=>dS,useStorageGetDefaultLocation:()=>bS,useStorageList:()=>lS,useStorageListLocationDeclarations:()=>xS,useStorageListLocations:()=>yS,useStorageListProviders:()=>TS,useStorageRead:()=>sS,useStorageReadChunk:()=>_S,useStorageResolve:()=>aS,useStorageTestConfig:()=>ES,useStorageTestLocation:()=>wS,useStorageUpsertLocation:()=>SS,useStorageWrite:()=>oS,useStorageWriteChunk:()=>pS,useStreamBrokerApplyDeviceSettingsPatch:()=>rC,useStreamBrokerAssignProfile:()=>kS,useStreamBrokerGetAllRtspEntries:()=>XS,useStreamBrokerGetBrokerStats:()=>NS,useStreamBrokerGetDeviceLiveContribution:()=>nC,useStreamBrokerGetDeviceSettingsContribution:()=>tC,useStreamBrokerGetPreBufferInfo:()=>JS,useStreamBrokerGetRtspEntry:()=>ZS,useStreamBrokerGetRtspPort:()=>YS,useStreamBrokerGetStreamUrl:()=>RS,useStreamBrokerGetStreamWithCodec:()=>zS,useStreamBrokerIsRtspEnabled:()=>eC,useStreamBrokerKillClient:()=>IS,useStreamBrokerListAllCameraStreams:()=>jS,useStreamBrokerListAllProfileSlots:()=>MS,useStreamBrokerListClients:()=>FS,useStreamBrokerProbeStream:()=>PS,useStreamBrokerPublishCameraStream:()=>DS,useStreamBrokerPullAudioChunks:()=>HS,useStreamBrokerPullFrameHandles:()=>GS,useStreamBrokerRegenerateRtspToken:()=>QS,useStreamBrokerReleaseStreamWithCodec:()=>BS,useStreamBrokerRestartProfile:()=>LS,useStreamBrokerRetractCameraStream:()=>OS,useStreamBrokerSetPreBufferDuration:()=>qS,useStreamBrokerSetRtspEnabled:()=>$S,useStreamBrokerSubscribeAudioChunks:()=>VS,useStreamBrokerSubscribeFrames:()=>WS,useStreamBrokerUnassignProfile:()=>AS,useStreamBrokerUnsubscribeAudioChunks:()=>US,useStreamBrokerUnsubscribeFrames:()=>KS,useStreamCatalogGetCatalog:()=>iC,useStreamParamsGetConfigSchema:()=>sC,useStreamParamsGetOptions:()=>aC,useStreamParamsGetStatus:()=>cC,useStreamParamsSetProfile:()=>oC,useSwitchGetStatus:()=>uC,useSwitchSetState:()=>lC,useSystem:()=>Ke,useSystemFeatureFlags:()=>pC,useSystemForceRetentionCleanup:()=>_C,useSystemGetRetentionConfig:()=>hC,useSystemHealth:()=>fC,useSystemInfo:()=>dC,useSystemMutation:()=>nV,useSystemNetworkAddresses:()=>mC,useSystemQuery:()=>tV,useSystemSetRetentionConfig:()=>gC,useTamperGetStatus:()=>vC,useTemperatureSensorGetStatus:()=>yC,useThemeMode:()=>Pt,useToastOnToast:()=>bC,useTurnProviderGetTurnServers:()=>xC,useUpdateGetStatus:()=>CC,useUpdateInstallUpdate:()=>SC,useUserManagementConfirmTotp:()=>BC,useUserManagementCreateApiKey:()=>MC,useUserManagementCreateScopedToken:()=>FC,useUserManagementCreateUser:()=>TC,useUserManagementDeleteUser:()=>DC,useUserManagementDisableTotp:()=>VC,useUserManagementGetTotpStatus:()=>HC,useUserManagementListApiKeys:()=>jC,useUserManagementListOauthSessions:()=>JC,useUserManagementListScopedTokens:()=>RC,useUserManagementListUsers:()=>wC,useUserManagementOauthExchangeCode:()=>GC,useUserManagementOauthIssueCode:()=>WC,useUserManagementOauthRefresh:()=>KC,useUserManagementOauthVerifyAccessToken:()=>qC,useUserManagementResetPassword:()=>OC,useUserManagementRevokeApiKey:()=>NC,useUserManagementRevokeOauthSession:()=>YC,useUserManagementRevokeScopedToken:()=>IC,useUserManagementSetUserScopes:()=>kC,useUserManagementSetupTotp:()=>zC,useUserManagementUpdateUser:()=>EC,useUserManagementValidateApiKey:()=>PC,useUserManagementValidateCredentials:()=>AC,useUserManagementValidateScopedToken:()=>LC,useUserManagementVerifyTotp:()=>UC,useVacuumControlGetStatus:()=>nw,useVacuumControlLocate:()=>ew,useVacuumControlPause:()=>ZC,useVacuumControlReturnToBase:()=>$C,useVacuumControlSetFanSpeed:()=>tw,useVacuumControlStart:()=>XC,useVacuumControlStop:()=>QC,useValveClose:()=>iw,useValveGetStatus:()=>sw,useValveOpen:()=>rw,useValveSetPosition:()=>ow,useValveStop:()=>aw,useVibrationGetStatus:()=>cw,useVideoclipsGetClipPlayback:()=>uw,useVideoclipsListClips:()=>lw,useVodPlayback:()=>nI,useWaterHeaterGetStatus:()=>mw,useWaterHeaterSetAway:()=>pw,useWaterHeaterSetOperationMode:()=>fw,useWaterHeaterSetTargetTemp:()=>dw,useWeatherGetStatus:()=>hw,useWebrtcSessionAddIceCandidate:()=>bw,useWebrtcSessionCloseSession:()=>Sw,useWebrtcSessionCreateSession:()=>_w,useWebrtcSessionGetIceCandidates:()=>xw,useWebrtcSessionGetSessionState:()=>ww,useWebrtcSessionHandleAnswer:()=>yw,useWebrtcSessionHandleOffer:()=>vw,useWebrtcSessionHasAdaptiveBitrate:()=>Cw,useWebrtcSessionListStreams:()=>gw,useWidget:()=>vF,useWidgetMetadata:()=>yF,useWidgetRegistry:()=>SF,useZoneAnalyticsGetCameraHistory:()=>Dw,useZoneAnalyticsGetCurrentSnapshot:()=>Tw,useZoneAnalyticsGetUnzonedHistory:()=>Ow,useZoneAnalyticsGetZoneHistory:()=>Ew,useZoneEditing:()=>GB,useZoneRulesListRules:()=>kw,useZoneRulesSetRules:()=>Aw,useZonesAddZone:()=>Mw,useZonesListZones:()=>jw,useZonesRemoveZone:()=>Nw,useZonesUpdateZone:()=>Pw,vacuumStateMeta:()=>sT,validateScopes:()=>HB,valveStateMeta:()=>FT,waterHeaterPhase:()=>ZT,waterHeaterTint:()=>XT,weatherConditionMeta:()=>nE,weatherTint:()=>rE});h();var oV=E(()=>a(()=>import(`./MaskShapeCanvas-pGn6MKOi.js`).then(e=>({default:e.MaskShapeCanvas})),__vite__mapDeps([4]))),sV=E(()=>a(()=>import(`./MotionZonesSettings-DL55VLbI.js`).then(e=>({default:e.MotionZonesSettings})),__vite__mapDeps([0,1,2,3,4]))),cV=E(()=>a(()=>import(`./PrivacyMaskSettings-8aXddQXv.js`).then(e=>({default:e.PrivacyMaskSettings})),__vite__mapDeps([5,1,2,3,4])));export{Fk as $,wl as $i,og as $n,Ob as $r,Cf as $t,bF as A,Es as Aa,TS as Ai,hh as An,Sv as Ar,Wu as At,cM as B,mr as Ba,HC as Bi,Km as Bn,py as Br,df as Bt,_R as C,Ms as Ca,Rx as Ci,jm as Cn,b_ as Cr,qu as Ct,tI as D,Is as Da,CS as Di,Am as Dn,ov as Dr,Zu as Dt,iI as E,Ls as Ea,Bx as Ei,xm as En,lv as Er,ad as Et,aF as F,Ao as Fa,xC as Fi,vm as Fn,Tv as Fr,Dd as Ft,tj as G,OC as Gi,sg as Gn,gy as Gr,af as Gt,aM as H,Pt as Ha,JC as Hi,eh as Hn,my as Hr,sf as Ht,eF as I,ta as Ia,FC as Ii,dm as In,mv as Ir,zd as It,VA as J,IC as Ji,eg as Jn,Mb as Jr,Tf as Jt,ej as K,NC as Ki,$h as Kn,sb as Kr,ff as Kt,zP as L,zr as La,TC as Li,um as Ln,gv as Lr,Zd as Lt,yF as M,_s as Ma,PS as Mi,zm as Mn,xv as Mr,Ed as Mt,rF as N,ps as Na,QS as Ni,Qm as Nn,_v as Nr,Td as Nt,nI as O,Rs as Oa,xS as Oi,Jm as On,sv as Or,cd as Ot,iF as P,Bo as Pa,bC as Pi,_m as Pn,vv as Pr,Od as Pt,Mk as Q,Du as Qi,ug as Qn,xb as Qr,xf as Qt,qN as R,Ar as Ra,DC as Ri,hm as Rn,Ny as Rr,uf as Rt,xR as S,Us as Sa,zx as Si,rh as Sn,S_ as Sr,ed as St,WI as T,zs as Ta,Vx as Ti,ym as Tn,P_ as Tr,Hu as Tt,Qj as U,Nt as Ua,RC as Ui,cg as Un,Hy as Ur,pf as Ut,oM as V,X as Va,jC as Vi,ah as Vn,xy as Vr,rf as Vt,mj as W,wC as Wi,Zh as Wn,By as Wr,lf as Wt,IA as X,EC as Xi,tg as Xn,db as Xr,Pf as Xt,LA as Y,kC as Yi,ng as Yn,fb as Yr,Of as Yt,Hk as Z,ku as Zi,Qh as Zn,ub as Zr,yf as Zt,wz as _,rc as _a,Zy as _i,mh as _n,e_ as _r,Nu as _t,XB as a,ol as aa,Qy as ai,Gp as an,Ag as ar,Mu as at,LR as b,Ws as ba,Ub as bi,Wm as bn,x_ as br,Uu as bt,HB as c,Z as ca,mb as ci,lh as cn,Fg as cr,gd as ct,OB as d,Fc as da,yb as di,ch as dn,zg as dr,Ku as dt,Cl as ea,ib as ei,Ef as en,lg as er,jk as et,uB as f,Ec as fa,Tb as fi,dh as fn,Rg as fr,id as ft,Nz as g,vc as ga,cb as gi,th as gn,Yg as gr,Iu as gt,Pz as h,yc as ha,ab as hi,ph as hn,Zg as hr,$u as ht,ZB as i,cl as ia,kb as ii,Wp as in,Ig as ir,Rw as it,xF as j,ys as ja,SS as ji,gh as jn,wv as jr,kd as jt,_F as k,ks as ka,yS as ki,Tm as kn,dv as kr,Bu as kt,NB as l,nl as la,vb as li,oh as ln,Lg as lr,md as lt,Yz as m,xc as ma,Sb as mi,Rm as mn,Qg as mr,Ju as mt,iV as n,yl as na,$y as ni,kf as nn,Ng as nr,yk as nt,WB as o,sl as oa,bb as oi,Yp as on,Pg as or,hd as ot,eB as p,Sc as pa,wb as pi,ih as pn,Bg as pr,nd as pt,QA as q,YC as qi,Xh as qn,Xy as qr,Sf as qt,QB as r,ll as ra,pb as ri,Mp as rn,kg as rr,dk as rt,BB as s,il as sa,Eb as si,nh as sn,Og as sr,pd as st,aV as t,xl as ta,eb as ti,wf as tn,jg as tr,Ak as tt,MB as u,Vc as ua,_b as ui,sh as un,Mg as ur,od as ut,gz as v,nc as va,jb as vi,fh as vn,$g as vr,Xu as vt,gR as w,Fs as wa,Lx as wi,Zm as wn,F_ as wr,td as wt,TR as x,Gs as xa,yx as xi,Mm as xn,C_ as xr,Vu as xt,ez as y,Hs as ya,Vb as yi,Lm as yn,v_ as yr,ud as yt,mM as z,Or as za,VC as zi,bm as zn,My as zr,cf as zt};