@camstack/addon-admin-ui 1.2.508 → 1.2.510

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 (119) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/assets/{AddonAssetIcon-BI2lRuoS.js → AddonAssetIcon-C9hAoKXu.js} +1 -1
  3. package/dist/assets/{Addons-TpOqhnVb.js → Addons-RWj1BxGY.js} +1 -1
  4. package/dist/assets/{AdminPage-CoK_jJGS.js → AdminPage-DlYf-2bp.js} +1 -1
  5. package/dist/assets/{AdminSectionedPage-DSGzoNMN.js → AdminSectionedPage-BZCKp3Ch.js} +1 -1
  6. package/dist/assets/{AiProfiles-BAjucqPT.js → AiProfiles-JSlQDV72.js} +1 -1
  7. package/dist/assets/{BrokerEditorDialog-B89FOzdO.js → BrokerEditorDialog-Bd04efEw.js} +1 -1
  8. package/dist/assets/{Build-CFHVjKTp.js → Build-BZi_niS-.js} +1 -1
  9. package/dist/assets/{Calendars-B_klJh9f.js → Calendars-DP9Bg77f.js} +1 -1
  10. package/dist/assets/Cluster-Dd_vu_bM.js +1 -0
  11. package/dist/assets/{CompositionBlockEditor--2eeDknC.js → CompositionBlockEditor-CH-GMXbq.js} +1 -1
  12. package/dist/assets/{CompositionEditorPage-CdQhA7kv.js → CompositionEditorPage-Csnltw_A.js} +1 -1
  13. package/dist/assets/{Data-CZwL53Hx.js → Data-uCQZVzY1.js} +1 -1
  14. package/dist/assets/{DeviceDetail-SKPy4rTC.js → DeviceDetail-BxIy7-Dm.js} +1 -1
  15. package/dist/assets/{DeviceDoActionFields-B33Gsegz.js → DeviceDoActionFields-CK01sDyF.js} +1 -1
  16. package/dist/assets/{Devices-Rkjf5xy8.js → Devices-CVsltbg0.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-CIhSpElZ.js → EmbedPlayerPage-C5TPel_z.js} +1 -1
  18. package/dist/assets/{HelperWizard-CbDck6HU.js → HelperWizard-BPhC2XoW.js} +1 -1
  19. package/dist/assets/{History-DDDOyHZ5.js → History-B20ge-W7.js} +1 -1
  20. package/dist/assets/{Identity-r8ch-lOQ.js → Identity-DPilvdr-.js} +1 -1
  21. package/dist/assets/{IntegrationDetail-DtLleJdm.js → IntegrationDetail-QFz0_FYR.js} +1 -1
  22. package/dist/assets/{IntegrationHub-CySfaOMq.js → IntegrationHub-B1kSbU1F.js} +1 -1
  23. package/dist/assets/{Integrations-DgKqVXik.js → Integrations-DL3TkBVs.js} +1 -1
  24. package/dist/assets/{Integrations-DfhZYAU6.js → Integrations-DZSqPZJX.js} +1 -1
  25. package/dist/assets/{Library-DS1N1jEN.js → Library-lJCalEoT.js} +1 -1
  26. package/dist/assets/{Locations-DeBnLLF-.js → Locations-B0jWaHF6.js} +1 -1
  27. package/dist/assets/{Logs-CHh39x1m.js → Logs-DQLPAUyF.js} +1 -1
  28. package/dist/assets/{MaskShapeCanvas-Bc_okYTu.js → MaskShapeCanvas-CFljj6Sk.js} +1 -1
  29. package/dist/assets/{MotionZonesSettings-C-3oW42G.js → MotionZonesSettings-B8TBt4dC.js} +1 -1
  30. package/dist/assets/{MyAccess-C3LJW2D-.js → MyAccess-CZG0q7Mt.js} +1 -1
  31. package/dist/assets/{Network-DUpU_-CN.js → Network-BBrgIFOt.js} +1 -1
  32. package/dist/assets/{NodeAddonsSettingsPanel-DtuYEwYa.js → NodeAddonsSettingsPanel-CeHG4O24.js} +1 -1
  33. package/dist/assets/{Notifications-Co9i2XjT.js → Notifications-3RTWnoyO.js} +1 -1
  34. package/dist/assets/{Pipeline-q5F5QN1u.js → Pipeline-CGdO9F0O.js} +1 -1
  35. package/dist/assets/{PrivacyMaskSettings-BOI5MbOP.js → PrivacyMaskSettings-BJlCR0a3.js} +1 -1
  36. package/dist/assets/{Recordings-Ce7zfDAZ.js → Recordings-CURYqqF0.js} +1 -1
  37. package/dist/assets/{ScanNetworkModal-B6Qw9qG5.js → ScanNetworkModal-ojXdkkOk.js} +1 -1
  38. package/dist/assets/{SceneMonitorEditor-BP10OuX_.js → SceneMonitorEditor-CNgXiExG.js} +1 -1
  39. package/dist/assets/{SessionsList-LaUTUXTI.js → SessionsList-Bd4yBLfB.js} +1 -1
  40. package/dist/assets/{Showroom-Dq8K9w28.js → Showroom-Df0D9oOc.js} +1 -1
  41. package/dist/assets/{System-BXnin0ZR.js → System-DQkvS75J.js} +1 -1
  42. package/dist/assets/{Terminal-B-yYnFAl.js → Terminal-BhUVowlr.js} +1 -1
  43. package/dist/assets/{Viewer-CDe6m77J.js → Viewer-B4P4Bkxo.js} +1 -1
  44. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DmDesblz.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Cze0rRAV.js} +1 -1
  45. package/dist/assets/{addon-icons-context-C1MOrZ0k.js → addon-icons-context-fZFRR8Jh.js} +1 -1
  46. package/dist/assets/{archive-DfRpKbmd.js → archive-B0Gb92Md.js} +1 -1
  47. package/dist/assets/{assignment-candidates-XVSaMNWE.js → assignment-candidates-CLAnrBak.js} +1 -1
  48. package/dist/assets/{authed-media-acRzkBVq.js → authed-media-BZXVXyjI.js} +1 -1
  49. package/dist/assets/{bell-off-BDtTHYf7.js → bell-off-BFI_PtFI.js} +1 -1
  50. package/dist/assets/{board-model-D3K1Oad0.js → board-model-Cb9TF016.js} +1 -1
  51. package/dist/assets/{boxes-Dg0SsuKi.js → boxes-C9rq6GsW.js} +1 -1
  52. package/dist/assets/circle-slash-CrgSHCu9.js +1 -0
  53. package/dist/assets/client-CwJGlpR9.js +674 -0
  54. package/dist/assets/{cloud-upload-D5gzNxtI.js → cloud-upload-kAMSz6c0.js} +1 -1
  55. package/dist/assets/crop-DKZuvuZ0.js +1 -0
  56. package/dist/assets/{device-integration-icon-DMlXMoep.js → device-integration-icon-a0pkysxV.js} +1 -1
  57. package/dist/assets/device-picker-model-BTGIE40h.js +1 -0
  58. package/dist/assets/{dist-DU6BvfF_.js → dist-CG2a7mCH.js} +1 -1
  59. package/dist/assets/dist-D4krkzk0.js +674 -0
  60. package/dist/assets/{eraser-DatAKBqr.js → eraser-De_DOv3l.js} +1 -1
  61. package/dist/assets/{format-C5OjHr2B.js → format-7HUlrbym.js} +1 -1
  62. package/dist/assets/{hard-drive-download-BMn4pcLF.js → hard-drive-download-DKm5p-Le.js} +1 -1
  63. package/dist/assets/{hostInit-SgUIaQcR.js → hostInit-Ct3ew837.js} +1 -1
  64. package/dist/assets/i18n-9jE1YKjd.js +1 -0
  65. package/dist/assets/{icons-CfQXaR2o.js → icons-3VtN4bSW.js} +1 -1
  66. package/dist/assets/{index-BCZXKpVN.js → index-DG07MiZm.js} +3 -3
  67. package/dist/assets/{key-0qodB2RW.js → key-VHIrojXx.js} +1 -1
  68. package/dist/assets/{key-round-EDiKxWDb.js → key-round-Bfq08tmQ.js} +1 -1
  69. package/dist/assets/{layers-BuqS0QUs.js → layers-C2a0eh6-.js} +1 -1
  70. package/dist/assets/{linked-devices-model-EpVtXJ1y.js → linked-devices-model-D3jOXb7G.js} +1 -1
  71. package/dist/assets/{list-ordered-5xX0c-4M.js → list-ordered-Da2mHuCu.js} +1 -1
  72. package/dist/assets/{location-owned-usage-DYyj5DnK.js → location-owned-usage-DqvEUneY.js} +1 -1
  73. package/dist/assets/{log-in-DfGAqbts.js → log-in-eLGFJBOn.js} +1 -1
  74. package/dist/assets/{memory-stick-Cw-HmXQN.js → memory-stick-DnKI7rwN.js} +1 -1
  75. package/dist/assets/{message-square-plus-Cimd4hIM.js → message-square-plus-C6KwcZuQ.js} +1 -1
  76. package/dist/assets/{mf-entry-bootstrap-0-f0aece97.js → mf-entry-bootstrap-0-98f2c3e4.js} +2 -2
  77. package/dist/assets/{mic-off-BaeJlMpU.js → mic-off-D983qPJH.js} +1 -1
  78. package/dist/assets/{monitor-off-B5ZegpCN.js → monitor-off-BxsFOOUC.js} +1 -1
  79. package/dist/assets/{monitor-smartphone-GrRvroYr.js → monitor-smartphone-CVLLvvgV.js} +1 -1
  80. package/dist/assets/mount-BTGIE40h.js +1 -0
  81. package/dist/assets/{player-overlays-CzZYPO2s.js → player-overlays-g9d3qYrr.js} +1 -1
  82. package/dist/assets/{recycle-C0Za7XIk.js → recycle-DO_1Mgmd.js} +1 -1
  83. package/dist/assets/remoteEntry-CpKU5IE2.js +1 -0
  84. package/dist/assets/{scan-eye-DBcVKkv9.js → scan-eye-CyJ3ozW9.js} +1 -1
  85. package/dist/assets/{scissors-ClBtIo8F.js → scissors-BNMtq6Ob.js} +1 -1
  86. package/dist/assets/{search-x-vzCWLMzU.js → search-x-DDY8MfL6.js} +1 -1
  87. package/dist/assets/{send-C2xLiGxd.js → send-Ch2Il08w.js} +1 -1
  88. package/dist/assets/{settings-2-CE18osa2.js → settings-2-DuqbBWmE.js} +1 -1
  89. package/dist/assets/{sigma-BzZ_sr1s.js → sigma-C3PEOK_Y.js} +1 -1
  90. package/dist/assets/{speaker-DPhQgEkP.js → speaker-DkdRIL1K.js} +1 -1
  91. package/dist/assets/{src-DytYtgEw.js → src-DwNoxp86.js} +3 -3
  92. package/dist/assets/{step-inspector-model-CjRD_PYM.js → step-inspector-model-DQUr_7uJ.js} +1 -1
  93. package/dist/assets/{table-2-Ca1maW_p.js → table-2-DoxvwhSo.js} +1 -1
  94. package/dist/assets/{timer-reset-DLwEAlTU.js → timer-reset-DVNN3Abc.js} +1 -1
  95. package/dist/assets/{unlink-Bdb8-xwF.js → unlink-C-2ouMww.js} +1 -1
  96. package/dist/assets/{usb-DxqbvFPc.js → usb-PSQjoR7w.js} +1 -1
  97. package/dist/assets/{use-scenes-feed-YVkY4_qr.js → use-scenes-feed-B_j7CFbm.js} +1 -1
  98. package/dist/assets/{use-stationary-objects-FD4-OqJN.js → use-stationary-objects-Drf9XXJR.js} +1 -1
  99. package/dist/assets/useEventInvalidation-BTGIE40h.js +1 -0
  100. package/dist/assets/{useNodeUrlSelection-D8YOlTNk.js → useNodeUrlSelection-Cg0TPdbH.js} +1 -1
  101. package/dist/assets/user-round-Z0QH_kjR.js +1 -0
  102. package/dist/assets/{user-x-BQ6msuOU.js → user-x-BRStn-V-.js} +1 -1
  103. package/dist/assets/{variable-mkIJuabT.js → variable-vFOxYqY7.js} +1 -1
  104. package/dist/assets/{video-O02NyJP7.js → video-BFmrpvc7.js} +1 -1
  105. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CVBjsL5d.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-JzLE6zuc.js} +2 -2
  106. package/dist/index.html +9 -9
  107. package/dist/server/addon.js +13 -1
  108. package/package.json +1 -1
  109. package/dist/assets/Cluster-D4aPF2Mc.js +0 -1
  110. package/dist/assets/circle-slash-vr6zT4n3.js +0 -1
  111. package/dist/assets/client-BRyxs6lT.js +0 -674
  112. package/dist/assets/crop-CGtgnf44.js +0 -1
  113. package/dist/assets/device-picker-model-D0GfTZgv.js +0 -1
  114. package/dist/assets/dist-CPWJTJFO.js +0 -674
  115. package/dist/assets/i18n-DH8y-VcL.js +0 -1
  116. package/dist/assets/mount-D0GfTZgv.js +0 -1
  117. package/dist/assets/remoteEntry-BNJLevTL.js +0 -1
  118. package/dist/assets/useEventInvalidation-D0GfTZgv.js +0 -1
  119. package/dist/assets/user-round-D5DJkFym.js +0 -1
@@ -1,4 +1,4 @@
1
- import{C as e,E as t,J as n,K as r,P as i,R as a,S as o,V as s,Y as c,a as l,et as u,o as d,t as f,x as p}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$i as m,Ar as h,Di as g,Fn as _,Ht as v,In as y,Mi as b,Ti as x,Tr as S,Vn as C,dt as w,fr as T,mr as E,pa as D,ra as O,st as k,vt as A,wn as j,yi as M,yn as N,zt as P}from"./player-overlays-CzZYPO2s.js";import{$i as F,Ai as I,Di as L,Fi as R,Ka as ee,Pi as z,Qi as B,Xi as te,Zi as ne,da as re,ea as ie,fi as ae,fn as V,hi as oe,mi as se,na as ce,on as le,so as ue,ta as de,ua as fe,wi as pe}from"./client-BRyxs6lT.js";import{t as me}from"./boxes-Dg0SsuKi.js";import{i as H,n as he,r as ge,t as _e}from"./variable-mkIJuabT.js";import{s as ve}from"./video-O02NyJP7.js";import{$r as ye,Cn as be,Co as xe,Do as Se,Er as Ce,Fa as we,Ga as Te,Ia as Ee,Ir as De,Jo as Oe,Ka as ke,Kt as Ae,La as je,Md as Me,Mo as Ne,Nr as Pe,Or as Fe,Pd as Ie,Qr as Le,R as Re,Ra as ze,Sn as Be,Tr as U,Ua as Ve,Un as He,Va as Ue,Wa as We,Yr as W,Zt as Ge,_r as Ke,bn as qe,br as Je,cd as Ye,ci as Xe,dd as G,di as Ze,dr as Qe,en as $e,fi as et,ft as tt,gd as K,gi as nt,gn as rt,gr as it,hd as at,hi as ot,hr as st,li as ct,md as lt,mi as ut,mt as dt,pd as ft,pr as pt,ri as q,rn as mt,rt as ht,si as gt,ui as _t,vi as vt,vt as yt}from"./src-DytYtgEw.js";import{t as J}from"./i18n-DH8y-VcL.js";import{t as Y}from"./useTranslation-BJr-n0es.js";import{L as bt,T as xt,_r as St,h as Ct,lr as wt,m as Tt,mr as Et,pr as X,yr as Dt}from"./index-BCZXKpVN.js";import{t as Ot}from"./AdminSectionedPage-DSGzoNMN.js";import{n as kt}from"./format-C5OjHr2B.js";import{n as At,t as jt}from"./DeviceDoActionFields-B33Gsegz.js";import{J as Mt,P as Nt,V as Pt,p as Ft,t as It,u as Lt}from"./HelperWizard-CbDck6HU.js";import{t as Rt}from"./CompositionBlockEditor--2eeDknC.js";var zt=`const AUTOMATION_RECIPE =`,Bt=`// EJECTED from the visual automation editor — this file is now hand-owned.
1
+ import{C as e,E as t,J as n,K as r,P as i,R as a,S as o,V as s,Y as c,a as l,et as u,o as d,t as f,x as p}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$i as m,Ar as h,Di as g,Fn as _,Ht as v,In as y,Mi as b,Ti as x,Tr as S,Vn as C,dt as w,fr as T,mr as E,pa as D,ra as O,st as k,vt as A,wn as j,yi as M,yn as N,zt as P}from"./player-overlays-g9d3qYrr.js";import{$i as F,Ai as I,Di as L,Fi as R,Ka as ee,Pi as z,Qi as B,Xi as te,Zi as ne,da as re,ea as ie,fi as ae,fn as V,hi as oe,mi as se,na as ce,on as le,so as ue,ta as de,ua as fe,wi as pe}from"./client-CwJGlpR9.js";import{t as me}from"./boxes-C9rq6GsW.js";import{i as H,n as he,r as ge,t as _e}from"./variable-vFOxYqY7.js";import{s as ve}from"./video-BFmrpvc7.js";import{$r as ye,Cn as be,Co as xe,Do as Se,Er as Ce,Fa as we,Ga as Te,Ia as Ee,Ir as De,Jo as Oe,Ka as ke,Kt as Ae,La as je,Md as Me,Mo as Ne,Nr as Pe,Or as Fe,Pd as Ie,Qr as Le,R as Re,Ra as ze,Sn as Be,Tr as U,Ua as Ve,Un as He,Va as Ue,Wa as We,Yr as W,Zt as Ge,_r as Ke,bn as qe,br as Je,cd as Ye,ci as Xe,dd as G,di as Ze,dr as Qe,en as $e,fi as et,ft as tt,gd as K,gi as nt,gn as rt,gr as it,hd as at,hi as ot,hr as st,li as ct,md as lt,mi as ut,mt as dt,pd as ft,pr as pt,ri as q,rn as mt,rt as ht,si as gt,ui as _t,vi as vt,vt as yt}from"./src-DwNoxp86.js";import{t as J}from"./i18n-9jE1YKjd.js";import{t as Y}from"./useTranslation-BJr-n0es.js";import{L as bt,T as xt,_r as St,h as Ct,lr as wt,m as Tt,mr as Et,pr as X,yr as Dt}from"./index-DG07MiZm.js";import{t as Ot}from"./AdminSectionedPage-BZCKp3Ch.js";import{n as kt}from"./format-7HUlrbym.js";import{n as At,t as jt}from"./DeviceDoActionFields-CK01sDyF.js";import{J as Mt,P as Nt,V as Pt,p as Ft,t as It,u as Lt}from"./HelperWizard-BPhC2XoW.js";import{t as Rt}from"./CompositionBlockEditor-CH-GMXbq.js";var zt=`const AUTOMATION_RECIPE =`,Bt=`// EJECTED from the visual automation editor — this file is now hand-owned.
2
2
  // The recipe that produced it was removed with it, on purpose: while it was
3
3
  // here the editor could re-open this block and overwrite everything below.`;function Vt(e){return e.includes(zt)}function Ht(e){let t=e.indexOf(zt);if(t<0)return null;let n=e.indexOf(`{`,t+25);if(n<0)return null;let r=0,i=!1,a=!1;for(let o=n;o<e.length;o+=1){let s=e.charAt(o);if(i){a?a=!1:s===`\\`?a=!0:s===`"`&&(i=!1);continue}if(s===`"`){i=!0;continue}if(s===`{`)r+=1;else if(s===`}`&&(--r,r===0))return{declStart:t,literalEnd:o+1,json:e.slice(n,o+1)}}return null}function Ut(e){let t=Ht(e);if(t===null)return{ok:!1,reason:J.t(`helpers.recipeFromCode.noLiteral`)};let n;try{n=JSON.parse(t.json)}catch(e){let t=e instanceof Error?e.message:String(e);return{ok:!1,reason:J.t(`helpers.recipeFromCode.badJson`,{detail:t})}}let r=F.safeParse(n);if(!r.success){let e=r.error.issues[0];return{ok:!1,reason:e===void 0?J.t(`helpers.recipeFromCode.schemaMismatch`):J.t(`helpers.recipeFromCode.schemaMismatchAt`,{path:e.path.join(`.`),message:e.message})}}return{ok:!0,recipe:r.data}}function Wt(e){let t=Ht(e);if(t===null)return e;let n=e.slice(t.literalEnd),r=/^\s*as\s+const/.exec(n),i=t.literalEnd+(r===null?0:r[0].length);return`${e.slice(0,t.declStart)}${Bt}${e.slice(i)}`}u();function Gt(e){return e===void 0||!Number.isFinite(e)?``:String(e)}function Kt({value:e,onValue:t,onBrace:n,onBlur:r,...i}){let[a,s]=c(null);return o(K,{...i,inputMode:`decimal`,value:a??Gt(e),onChange:e=>{let r=e.target.value;if(r.includes(`{`)){n?.();return}s(r);let i=r.trim()===``?NaN:Number(r);t(Number.isFinite(i)?i:null)},onBlur:e=>{s(null),r?.(e)}})}function qt({widthClass:e,...t}){return o(`span`,{className:`block max-w-full ${e}`,children:o(G,{...t})})}var Jt=/(\{[A-Za-z0-9_]+\})/;function Yt(e){return e.toLowerCase().startsWith(`it`)?`it`:`en`}function Xt(e){return`${e.cap}:${e.id}`}function Zt(e){if(typeof e!=`object`||!e)return!1;let t=Object.keys(e);return t.length===1&&t[0]===`$var`&&typeof Reflect.get(e,`$var`)==`string`}function Qt(e){let t=[];for(let n of e.split(Jt))n!==``&&(n.startsWith(`{`)&&n.endsWith(`}`)?t.push({kind:`slot`,key:n.slice(1,-1)}):t.push({kind:`text`,text:n}));return t}function $t(e){let t=e.offer;switch(t.kind){case`number`:return{kind:`fixed`,value:t.min??0};case`enum`:{let e=t.values[0];return{kind:`fixed`,value:e===void 0?``:e.value}}case`boolean`:return{kind:`fixed`,value:!1};default:return{kind:`fixed`,value:``}}}function en(e){return Object.fromEntries(e.openArgs.map(e=>[e.key,$t(e)]))}function tn(e,t){return Zt(e)?{kind:`var`,name:e.$var}:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?{kind:`fixed`,value:e}:$t(t)}function nn(e,t){return JSON.stringify(e)===JSON.stringify(t)}function rn(e,t){if(typeof t.deviceId!=`number`)return null;let n=t.args??{},r=null,i=-1;for(let a of e){if(a.cap!==t.cap||a.method!==t.method)continue;let e=Object.entries(a.args);e.every(([e,t])=>nn(n[e],t))&&e.length>i&&(r=a,i=e.length)}if(r===null)return null;let a=Object.fromEntries(r.openArgs.map(e=>[e.key,tn(n[e.key],e)]));return{action:r,values:a}}function an(e){return e.kind===`var`?{$var:e.name}:e.value}function on(e){return e.kind===`fixed`&&e.value===``}function sn(e,t,n){let r={};for(let t of e.openArgs){let e=n[t.key]??$t(t);t.optional===!0&&on(e)||(r[t.key]=an(e))}let i={...e.args,...r};return{kind:`cap`,deviceId:t,cap:e.cap,method:e.method,...Object.keys(i).length===0?{}:{args:i}}}function cn(e,t){if(t.kind===`var`)return null;let n=e.offer;return n.kind===`number`?typeof t.value!=`number`||!Number.isFinite(t.value)?`empty`:n.min!==void 0&&t.value<n.min?`below`:n.max!==void 0&&t.value>n.max?`above`:null:n.kind===`text`||n.kind===`dynamic`?e.optional===!0||t.value!==``?null:`empty`:null}u();function ln(e){return e.kind===`fixed`?String(e.value):``}function un({arg:t,locale:n,variables:r,value:i,onChange:a}){let{t:s}=Y(),[l,u]=c(!1),d=t.label[n],f=cn(t,i),p=i.kind===`var`?o(ye,{label:i.name,onRemove:()=>a($t(t))}):o(dn,{arg:t,locale:n,value:i,onChange:a,onBrace:()=>u(!0)});return e(`span`,{className:`inline-flex flex-col gap-0.5 align-top`,"data-testid":`arg-${t.key}`,children:[e(`span`,{className:`inline-flex items-center gap-1`,children:[p,r.length>0&&e(gt,{open:l,onOpenChange:u,children:[o(_t,{"aria-label":s(`flow.arg.useVariable`,`Use a variable for {{label}}`,{label:d}),className:`h-8 rounded-md border border-border bg-surface px-2 font-mono text-xs text-foreground hover:bg-surface-hover`,children:`{x}`}),o(Xe,{children:r.map(e=>o(ct,{onClick:()=>a({kind:`var`,name:e.name}),children:`${e.name} · ${e.hint}`},e.name))})]})]}),o(pn,{arg:t,value:i,issue:f})]})}function dn({arg:e,locale:t,value:n,onChange:r,onBrace:i}){let{t:a}=Y(),s=e.offer,c=e.label[t];return s.kind===`enum`?o(qt,{widthClass:`w-40`,"aria-label":c,value:String(n.value),onChange:e=>{let t=s.values.find(t=>String(t.value)===e.target.value);t!==void 0&&r({kind:`fixed`,value:t.value})},options:s.values.map(e=>({value:String(e.value),label:e.label[t]}))}):s.kind===`boolean`?o(qt,{widthClass:`w-28`,"aria-label":c,value:n.value===!0?`yes`:`no`,onChange:e=>r({kind:`fixed`,value:e.target.value===`yes`}),options:[{value:`yes`,label:a(`common.yes`,`Yes`)},{value:`no`,label:a(`common.no`,`No`)}]}):s.kind===`number`?o(fn,{label:c,unit:s.unit,value:n,onChange:r,onBrace:i}):o(K,{"aria-label":c,type:s.kind===`text`&&s.secret===!0?`password`:`text`,className:`w-40`,value:ln(n),onChange:e=>{if(e.target.value.includes(`{`)){i();return}r({kind:`fixed`,value:e.target.value})}})}function fn({label:t,unit:n,value:r,onChange:i,onBrace:a}){return e(p,{children:[o(Kt,{"aria-label":t,className:`w-20`,value:typeof r.value==`number`?r.value:void 0,onValue:e=>i({kind:`fixed`,value:e??NaN}),onBrace:a}),n!==void 0&&o(`span`,{className:`text-sm text-foreground-muted`,children:n})]})}function pn({arg:e,value:t,issue:n}){let{t:r}=Y(),i=e.offer;if(t.kind!==`fixed`||i.kind!==`number`||i.min===void 0&&i.max===void 0)return null;let a=i.min!==void 0&&i.max!==void 0?r(`flow.arg.range`,`{{min}} to {{max}} {{unit}}`,{min:i.min,max:i.max,unit:i.unit??``}):i.min===void 0?r(`flow.arg.atMost`,`at most {{max}} {{unit}}`,{max:i.max,unit:i.unit??``}):r(`flow.arg.atLeast`,`at least {{min}} {{unit}}`,{min:i.min,unit:i.unit??``});return o(`span`,{className:`text-[11px] ${n===null?`text-foreground-subtle`:`text-danger`}`,role:n===null?void 0:`alert`,children:a.trim()})}u();function mn({devices:e,value:t,onChange:n,selection:i,noun:a=`device`,listState:s=`answered`,emptyLabel:c,testId:l}){return o(Re,{devices:r(()=>e.map(e=>({id:e.id,name:e.name,...e.type===void 0?{}:{type:e.type},location:e.location??null})),[e]),listState:s,value:[...t],onChange:e=>n(e),selection:i,noun:a,groupBy:`location`,...c===void 0?{}:{emptyLabel:c},testId:l})}u();function hn(e){return typeof e==`number`?e:typeof e==`object`&&e&&`$var`in e?{$var:e.$var}:[...e]}function gn(e,t,n){return e.map(e=>({value:Xt(e),label:e.label[t],description:e.phrase[t].replace(`{device}`,n)}))}function _n({step:t,devices:n,devicesState:i=`answered`,variables:a,onChange:s}){let{t:l,i18n:u}=Y(),d=Yt(u.language),[f,p]=c(!1),m=typeof t.deviceId==`number`,h=typeof t.deviceId==`number`?t.deviceId:0,g=n.find(e=>e.id===h),_=At(m?h:0),v=r(()=>_.data===void 0?[]:le(_.data,g?.type),[_.data,g?.type]),y=r(()=>rn(v,t),[v,t]),b=t.cap===``,x=m&&h>0&&_.data===void 0&&!_.isError;if(!(m&&!f&&(b||y!==null||x)))return o(yn,{step:t,devices:n,devicesState:i,onChange:s,onBack:m&&!b&&y!==null?()=>p(!1):null});let S=n.filter(e=>V(e.type??``));return e(`div`,{className:`space-y-2`,"data-testid":`command-step`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[g?.type!==void 0&&o(q,{variant:`neutral`,children:g.type}),o(W,{variant:`ghost`,size:`sm`,className:`ml-auto`,onClick:()=>p(!0),"data-testid":`command-step-advanced`,children:l(`flow.command.advanced`,`Advanced`)})]}),e(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[o(mn,{devices:S,selection:`single`,listState:i,value:h>0?[h]:[],testId:`command-step-device`,onChange:e=>{let t=e[0]??0;t!==h&&s({kind:`cap`,deviceId:t,cap:``,method:``})}}),o(Le,{mode:`single`,singleDisplay:`field`,options:gn(v,d,g?.name??``),value:y===null?``:Xt(y.action),placeholder:h===0?l(`flow.command.pickDeviceFirst`,`Pick a device first`):l(`flow.command.pickCommand`,`Pick a command`),disabled:h===0||x,searchable:v.length>=8,emptyMessage:l(`flow.command.noCommands`,`This device has no commands to offer.`),onChange:e=>{let t=v.find(t=>Xt(t)===e);t!==void 0&&s(sn(t,h,en(t)))}})]}),y!==null&&o(vn,{action:y.action,values:y.values,deviceName:g?.name??``,locale:d,variables:a,onChange:e=>s(sn(y.action,h,e))})]})}function vn({action:e,values:t,deviceName:n,locale:r,variables:i,onChange:a}){let s=[];return Qt(e.phrase[r]).forEach((c,l)=>{if(c.kind===`text`){s.push(o(`span`,{children:c.text},`t${String(l)}`));return}if(c.key===`device`){s.push(o(`span`,{className:`font-medium`,children:n},`device`));return}let u=e.openArgs.find(e=>e.key===c.key),d=t[c.key];u===void 0||d===void 0||s.push(o(un,{arg:u,locale:r,variables:i,value:d,onChange:e=>a({...t,[c.key]:e})},c.key))}),o(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-2 text-sm`,children:s})}function yn({step:t,devices:n,devicesState:r,onChange:i,onBack:a}){let{t:s}=Y();return e(`div`,{className:`space-y-2`,"data-testid":`command-step-generic`,children:[a!==null&&o(W,{variant:`ghost`,size:`sm`,onClick:a,children:s(`flow.command.backToSentence`,`Back to the sentence`)}),o(jt,{value:t,allowTriggerDevice:!0,allowMultiSameFamily:!0,devices:n,listState:r,onChange:e=>i({kind:`cap`,deviceId:hn(e.deviceId),cap:e.cap,method:e.method,...e.args===void 0?{}:{args:{...e.args}}})})]})}var bn={ran:`success`,failed:`danger`,aborted:`danger`,"skipped-trigger":`neutral`,"skipped-conditions":`warning`,"skipped-cooldown":`neutral`,"skipped-overlap":`neutral`},xn={pass:`border-success/50 bg-success/10`,fail:`border-danger/50 bg-danger/10`,idle:`border-border bg-surface text-foreground-subtle`},Sn={pass:`text-success`,fail:`text-danger`,idle:`text-foreground-subtle`};function Cn(){let{t:e}=Y();return t=>{switch(t){case`ran`:return e(`flow.runs.outcomeRan`,`Ran`);case`failed`:return e(`flow.runs.outcomeFailed`,`Failed`);case`aborted`:return e(`flow.runs.outcomeAborted`,`Stopped`);case`skipped-trigger`:return e(`flow.runs.outcomeSkippedTrigger`,`Trigger not met`);case`skipped-conditions`:return e(`flow.runs.outcomeSkippedConditions`,`Skipped by conditions`);case`skipped-cooldown`:return e(`flow.runs.outcomeSkippedCooldown`,`Skipped by cooldown`);default:return e(`flow.runs.outcomeSkippedOverlap`,`Skipped by run mode`)}}}function wn({traces:t,selectedId:n,onSelect:r}){let{t:i}=Y(),a=Cn(),s=t===void 0?[]:t.toReversed();return o(qe,{headingId:`runs-heading`,title:i(`flow.runs.title`,`Runs`),icon:S,children:t===void 0?o(Fe,{className:`m-3 h-16`}):s.length===0?o(Ce,{title:i(`flow.runs.emptyTitle`,`No runs yet`),description:i(`flow.runs.emptyDescription`,`Each run appears here with what it decided.`)}):e(p,{children:[o(`ul`,{className:`divide-y divide-border-subtle`,"data-testid":`runs-panel`,children:s.map(t=>{let i=t.runId===n;return o(`li`,{children:e(`button`,{type:`button`,"aria-pressed":i,onClick:()=>r(i?null:t.runId),className:`flex w-full flex-col gap-1 px-3 py-2 text-left hover:bg-surface-hover ${i?`bg-primary/10`:``}`,children:[e(`span`,{className:`flex flex-wrap items-center gap-2`,children:[o(q,{variant:bn[t.outcome],children:a(t.outcome)}),t.repeat>1&&o(q,{variant:`neutral`,style:`outline`,children:`x${String(t.repeat)}`}),o(`span`,{className:`text-xs text-foreground-subtle`,children:kt(t.lastAt)})]}),o(`span`,{className:`truncate text-sm text-foreground`,children:t.trigger.reason})]})},t.runId)})}),o(`p`,{className:`border-t border-border-subtle px-3 py-2 text-xs text-foreground-subtle`,children:i(`flow.runs.hint`,`Select a run to colour the blocks: green passed, red failed, grey not evaluated.`)})]})})}function Tn(e){return xn[e]}function En({step:t,title:n,hint:r,trace:i,children:a}){return e(`section`,{className:`rounded-lg border p-3 ${i===null?`border-border bg-surface`:xn[i.tone]}`,"data-testid":`block-${t}`,children:[e(`div`,{className:`mb-2 flex flex-wrap items-baseline gap-2`,children:[o(`h4`,{className:`text-sm font-semibold uppercase tracking-wide`,children:n}),r!==void 0&&o(`span`,{className:`text-xs text-foreground-subtle`,children:r})]}),i!==null&&i.reason!==null&&o(`p`,{className:`mb-2 text-xs font-medium ${Sn[i.tone]}`,children:i.reason}),o(`div`,{className:`space-y-2`,children:a})]})}u();var Dn=6e4;function On(){let e=Se({projection:`slim`});return r(()=>(e.data??[]).filter(e=>V(String(e.type))).map(e=>({id:e.id,name:e.name,stableId:e.stableId,type:String(e.type),location:e.location??null})).toSorted((e,t)=>e.name.localeCompare(t.name)),[e.data])}function kn(e){let t=w();return l({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:Dn,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function An(e,t){return e.find(e=>e.cap===t)?.fields??[]}u();function Z({children:e}){return o(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function jn(e){let t=kn(e.deviceId);if(t.data!==void 0)return An(t.data,e.cap).find(t=>t.path===e.fieldPath)}function Mn({value:t,devices:n,onChange:r}){let{t:i}=Y(),[a,s]=c(!1),l=n.find(e=>e.id===t.deviceId),u=t.deviceId===0?i(`automation.fieldPicker.pickAValue`,`Pick a device value…`):`${l?.name??`#${String(t.deviceId)}`}${t.cap===``?``:` · ${t.cap}.${t.fieldPath}`}`;return e(`div`,{className:`min-w-[14rem] max-w-full flex-[2]`,children:[o(Z,{children:i(`automation.fieldPicker.value`,`Device value`)}),e(W,{variant:`outline`,className:`w-full min-w-0 justify-between`,"data-testid":`field-picker-open`,onClick:()=>s(!0),children:[o(`span`,{className:`w-0 flex-1 truncate text-left`,children:u}),o(g,{className:`size-3.5 shrink-0`})]}),a&&o(Nn,{value:t,devices:n,onCancel:()=>s(!1),onConfirm:e=>{s(!1),r(e)}})]})}function Nn({value:t,devices:n,onCancel:i,onConfirm:a}){let{t:s}=Y(),l=Se({projection:`slim`}),u=r(()=>new Set(n.map(e=>e.id)),[n]),d=r(()=>e=>u.has(e.id),[u]),[f,p]=c(null),[m,h]=c(!1),[g,_]=c(t.cap===``?null:{cap:t.cap,path:t.fieldPath});!m&&l.status===`success`&&(h(!0),p(Mt(l.data).find(e=>e.id===t.deviceId)??null));let v=s(`automation.fieldPicker.title`,`Device value`);return o(Qe,{open:!0,onOpenChange:e=>!e&&i(),children:e(pt,{width:`xl`,children:[o(it,{children:o(Ke,{children:v})}),o(Pt,{kind:`formula`,enabled:!0,hostId:-1,destination:{cap:`automation`,targetId:`field`,title:v,pickerTargetKind:null},device:f,field:g,deviceFilter:d,onDeviceChange:p,onFieldChange:_}),e(st,{className:`flex flex-wrap gap-2`,children:[o(W,{variant:`ghost`,onClick:i,children:s(`common.cancel`,`Cancel`)}),o(W,{disabled:f===null||g===null,"data-testid":`field-picker-confirm`,onClick:()=>{f===null||g===null||a({deviceId:f.id,cap:g.cap,fieldPath:g.path})},children:s(`automation.fieldPicker.use`,`Use this value`)})]})]})})}var Pn=1e4;function Fn(e,t,n){let r=Object.fromEntries(Object.entries(e??{}).filter(([e])=>e!==t)),i=n===null?r:{...r,[t]:n};return Object.keys(i).length===0?void 0:i}function In(e,t){return{kind:`action`,actionId:e.actionId,...t===void 0?{}:{variables:t}}}function Ln({step:t,onChange:n}){let{t:r}=Y(),i=ot({},{refetchInterval:Pn});if(i.data===void 0)return o(Fe,{className:`h-8 w-64`});let a=i.data.find(e=>e.id===t.actionId),s=t.actionId!==``&&a===void 0;return e(`div`,{className:`space-y-2`,"data-testid":`run-action-step`,children:[e(`label`,{className:`block max-w-sm`,children:[o(Z,{children:r(`automation.runAction.action`,`Action`)}),o(G,{value:t.actionId,onChange:e=>n({kind:`action`,actionId:e.target.value}),options:[{value:``,label:r(`automation.runAction.pick`,`Pick an action`)},...s?[{value:t.actionId,label:r(`automation.runAction.missing`,`Missing action ({{id}})`,{id:t.actionId})}]:[],...i.data.map(e=>({value:e.id,label:e.name}))]})]}),s&&o(`p`,{className:`text-xs text-danger`,children:r(`automation.runAction.missingHint`,`This action no longer exists. Pick another, or the step will fail.`)}),(a?.variables??[]).length>0&&o(`div`,{className:`flex flex-wrap items-end gap-3`,children:(a?.variables??[]).map(e=>o(Rn,{variable:e,value:t.variables?.[e.name],onChange:r=>n(In(t,Fn(t.variables,e.name,r)))},e.name))})]})}function Rn({variable:t,value:n,onChange:r}){let{t:i}=Y(),a=t.label??t.name,s=t.default===void 0?i(`automation.runAction.required`,`required`):i(`automation.runAction.defaultIs`,`default {{value}}`,{value:String(t.default)});if(t.type===`boolean`||t.type===`select`){let c=t.type===`boolean`?[{value:`true`,label:i(`common.yes`,`Yes`)},{value:`false`,label:i(`common.no`,`No`)}]:(t.options??[]).map(e=>({value:e,label:e}));return e(`label`,{className:`block`,children:[o(Z,{children:a}),o(qt,{widthClass:`w-40`,value:n===void 0?``:String(n),onChange:e=>{e.target.value===``?r(null):r(t.type===`boolean`?e.target.value===`true`:e.target.value)},options:[{value:``,label:s},...c]})]})}return t.type===`number`?e(`label`,{className:`block`,children:[o(Z,{children:a}),o(Kt,{className:`w-40`,placeholder:s,value:typeof n==`number`?n:void 0,onValue:r})]}):e(`label`,{className:`block`,children:[o(Z,{children:a}),o(K,{className:`w-40`,placeholder:s,value:n===void 0?``:String(n),onChange:e=>r(e.target.value===``?null:e.target.value)})]})}var zn=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function Bn(e){switch(e){case`boolean`:return[`eq`,`ne`];case`number`:return[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`];case`string`:case`enum`:return[`eq`,`ne`,`contains`,`in`];default:return zn}}function Vn(e){switch(e){case`eq`:return J.t(`helpers.recipeParts.op_eq`);case`ne`:return J.t(`helpers.recipeParts.op_ne`);case`gt`:return J.t(`helpers.recipeParts.op_gt`);case`gte`:return J.t(`helpers.recipeParts.op_gte`);case`lt`:return J.t(`helpers.recipeParts.op_lt`);case`lte`:return J.t(`helpers.recipeParts.op_lte`);case`contains`:return J.t(`helpers.recipeParts.op_contains`);default:return J.t(`helpers.recipeParts.op_in`)}}function Hn(e){return Bn(e).map(e=>({value:e,label:Vn(e)}))}function Un(e){switch(e){case`device-state`:return J.t(`helpers.recipeParts.trigger_device_state`);case`device-event`:return J.t(`helpers.recipeParts.trigger_device_event`);case`schedule`:return J.t(`helpers.recipeParts.trigger_schedule`);case`stationary`:return J.t(`flow.trigger.stationary`);case`detection`:return J.t(`flow.trigger.detection`);case`interval`:return J.t(`flow.trigger.interval`);default:return J.t(`helpers.recipeParts.trigger_manual`)}}var Wn={triggers:[],actions:[]};function Gn(e){switch(e){case`device-state`:return{kind:e,deviceId:0,cap:``,fieldPath:``};case`device-event`:return{kind:e,category:``};case`schedule`:return{kind:e,cron:`0 30 23 * * *`};case`detection`:return{kind:e,classes:[],deviceIds:[]};case`stationary`:return{kind:e,deviceIds:[],phase:`appeared`};case`interval`:return{kind:e,minutes:5};default:return{kind:`manual`}}}function Kn(e){switch(e){case`wait`:return{kind:e,seconds:5};case`code`:return{kind:e,code:`// runs inside this automation, with ctx in scope
4
4
  `};case`action`:return{kind:e,actionId:``};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function qn(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function Jn(){return{kind:`stationary-present`,deviceId:0}}function Yn(){return{kind:`expression`,expr:``,bindings:{}}}function Xn(e,t,n){return e.map((e,r)=>r===t?n:e)}function Zn(e,t){return e.filter((e,n)=>n!==t)}function Qn(e,t,n){let r=e[t];if(r===void 0)return e;let i=Math.min(Math.max(n,0),e.length-1);if(i===t)return e;let a=Zn(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function $n(e,t){return{...e,triggers:[...t]}}function er(e,t){return{...e,actions:[...t]}}var tr=[{value:`cap`,labelKey:`automation.actionList.kindCap`},{value:`action`,labelKey:`automation.actionList.kindAction`},{value:`wait`,labelKey:`automation.actionList.kindWait`},{value:`code`,labelKey:`automation.actionList.kindCode`}];function nr({actions:t,devices:n,devicesState:r=`answered`,allowedKinds:i,variables:a=[],stepTones:s,onChange:c}){let{t:l}=Y(),u=tr.filter(e=>i===void 0||i.includes(e.value));return e(`div`,{className:`space-y-2`,children:[t.length===0&&o(`p`,{className:`text-xs text-warning`,children:l(`automation.actionList.noActionsYetAnAutomation`,`No actions yet. An automation that does nothing is not an automation.`)}),t.map((i,d)=>e(`div`,{className:`space-y-2 rounded border p-3 ${s===void 0?`border-border`:Tn(s[d]??`idle`)}`,children:[e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[o(q,{variant:`default`,children:d+1}),e(`label`,{className:`w-40`,children:[o(Z,{children:l(`automation.actionList.step`,`Step`)}),o(G,{value:i.kind,onChange:e=>c(Xn(t,d,Kn(rr(e.target.value)))),options:u.map(e=>({value:e.value,label:l(e.labelKey)}))})]}),e(`div`,{className:`ml-auto flex items-center gap-1`,children:[o(W,{variant:`ghost`,disabled:d===0,onClick:()=>c(Qn(t,d,d-1)),title:l(`automation.actionList.runThisStepEarlier`,`Run this step earlier`),children:o(m,{className:`h-3.5 w-3.5`})}),o(W,{variant:`ghost`,disabled:d===t.length-1,onClick:()=>c(Qn(t,d,d+1)),title:l(`automation.actionList.runThisStepLater`,`Run this step later`),children:o(O,{className:`h-3.5 w-3.5`})}),o(W,{variant:`ghost`,onClick:()=>c(Zn(t,d)),title:l(`automation.actionList.removeThisStep`,`Remove this step`),children:o(v,{className:`h-3.5 w-3.5`})})]})]}),i.kind===`wait`&&e(`label`,{className:`block w-32`,children:[o(Z,{children:l(`automation.actionList.seconds`,`Seconds`)}),o(K,{type:`number`,min:0,max:300,value:String(i.seconds),onChange:e=>c(Xn(t,d,{kind:`wait`,seconds:Number(e.target.value)}))})]}),i.kind===`code`&&e(`label`,{className:`block`,children:[o(Z,{children:l(`automation.actionList.code`,`Code`)}),o(`textarea`,{className:`h-32 w-full rounded-md border border-border bg-surface p-2 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,value:i.code,spellCheck:!1,onChange:e=>c(Xn(t,d,{kind:`code`,code:e.target.value}))}),o(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:o(X,{i18nKey:`automation.actionList.codeHint`,components:{code:o(`code`,{})}})})]}),i.kind===`cap`&&o(_n,{step:i,devices:n,devicesState:r,variables:a,onChange:e=>c(Xn(t,d,e))}),i.kind===`action`&&o(Ln,{step:i,onChange:e=>c(Xn(t,d,e))})]},`${i.kind}-${String(d)}`)),e(`div`,{className:`flex items-center gap-2`,children:[e(W,{variant:`outline`,onClick:()=>c([...t,Kn(u[0]?.value??`cap`)]),children:[o(_,{className:`h-4 w-4`}),` `,l(`automation.actionList.addStep`)]}),t.length>1&&o(`span`,{className:`text-xs text-foreground-subtle`,children:l(`automation.actionList.stepsRunInOrderAnd`,`Steps run in order and stop at the first failure.`)})]})]})}function rr(e){return tr.find(t=>t.value===e)?.value??`cap`}function ir(e,t){return e.map(e=>({name:e.name,hint:e.label??t(`flow.scope.type_${e.type}`,e.type)}))}function ar(e){return[{name:`deviceId`,hint:e(`flow.scope.deviceId`,`the camera that saw it`)},{name:`className`,hint:e(`flow.scope.className`,`what it saw`)},{name:`trackId`,hint:e(`flow.scope.trackId`,`the track`)},{name:`score`,hint:e(`flow.scope.score`,`how sure the detector was`)}]}function or(e){return[{name:`deviceId`,hint:e(`flow.scope.deviceId`,`the camera that saw it`)},{name:`className`,hint:e(`flow.scope.className`,`what it saw`)},{name:`phase`,hint:e(`flow.scope.phase`,`appeared or departed`)},{name:`entryId`,hint:e(`flow.scope.entryId`,`the stopped object`)}]}function sr(e,t){if(e.length===0)return[];let[n,...r]=e.map(e=>e.kind===`detection`?ar(t):e.kind===`stationary`?or(t):[]);return n===void 0?[]:n.filter(e=>r.every(t=>t.some(t=>t.name===e.name)))}var cr=`conditions`;function lr(e){return e===void 0||e.trim()===``?null:e}function ur(e){let t=e.slice(e.lastIndexOf(`.`)+1),n=Number(t);return Number.isInteger(n)?n:0}function dr(e){return e.steps.map(e=>({index:ur(e.path),tone:e.outcome===`ok`?`pass`:e.outcome===`error`?`fail`:`idle`,message:lr(e.message)}))}function fr(e){let t=e.conditions.find(e=>e.path===cr);return t===void 0?null:{tone:t.outcome===`pass`?`pass`:t.outcome===`fail`?`fail`:`idle`,reason:lr(t.reason)}}function pr(e,t){return e.outcome===`ran`?{tone:`pass`,reason:null}:e.outcome===`failed`||e.outcome===`aborted`?{tone:`fail`,reason:t.find(e=>e.tone===`fail`)?.message??null}:{tone:`idle`,reason:lr(e.verdict?.reason)}}function mr(e){let t=dr(e);return{when:{tone:e.trigger.outcome===`pass`?`pass`:`fail`,reason:lr(e.trigger.reason)},condition:fr(e),thenBlock:pr(e,t),steps:t}}function hr(e,t){return e===null?null:e.steps.find(e=>e.index===t)?.tone??`idle`}var gr={name:``,steps:[],variables:[]};function _r(e){return e===null?gr:{name:e.name,steps:e.steps??[],variables:e.variables??[]}}function vr(e){let t=[],n=e=>{t.includes(e)||t.push(e)},r=e=>{if(Zt(e)){n(e.$var);return}Array.isArray(e)?e.forEach(r):typeof e==`object`&&e&&Object.values(e).forEach(r)};for(let t of e)t.kind===`cap`&&(r(t.deviceId),r(t.args));return t}function yr(e){let t=new Set(e.variables.map(e=>e.name));return vr(e.steps).find(e=>!t.has(e))??null}function br(e){if(e.name.trim()===``)return{ok:!1,reason:{kind:`name`}};if(e.steps.length===0)return{ok:!1,reason:{kind:`no-steps`}};let t=e.variables.find(e=>!Tr(e.name));if(t!==void 0)return{ok:!1,reason:{kind:`bad-name`,name:t.name}};let n=Er(e.variables)[0];if(n!==void 0)return{ok:!1,reason:{kind:`duplicate`,name:n}};let r=yr(e);if(r!==null)return{ok:!1,reason:{kind:`undeclared`,name:r}};let i=te.safeParse({name:e.name.trim(),steps:e.steps,...e.variables.length===0?{}:{variables:e.variables}});if(!i.success){let e=i.error.issues[0];return{ok:!1,reason:{kind:`schema`,message:`${e===void 0||e.path.length===0?``:`${e.path.join(`.`)}: `}${e?.message??`invalid`}`}}}return{ok:!0,input:i.data}}function xr(e,t,n){return Zt(e)?e.$var===t?{$var:n}:e:Array.isArray(e)?e.map(e=>xr(e,t,n)):typeof e==`object`&&e?Object.fromEntries(Object.entries(e).map(([e,r])=>[e,xr(r,t,n)])):e}function Sr(e,t,n){if(e.kind!==`cap`)return e;let r=Zt(e.deviceId)&&e.deviceId.$var===t?{$var:n}:e.deviceId,i=e.args===void 0?void 0:Object.fromEntries(Object.entries(e.args).map(([e,r])=>[e,xr(r,t,n)]));return{...e,deviceId:r,...i===void 0?{}:{args:i}}}function Cr(e,t,n){let r=e.variables[t];return r===void 0||r.name===n?e:{...e,variables:e.variables.map((e,r)=>r===t?{...e,name:n}:e),steps:e.steps.map(e=>Sr(e,r.name,n))}}function wr(e){let t=new Set(e.map(e=>e.name)),n=`value`;for(let e=2;t.has(n);e++)n=`value${String(e)}`;return{name:n,type:`string`}}function Tr(e){return/^[A-Za-z_][A-Za-z0-9_]*$/.test(e)}function Er(e){let t=new Set,n=new Set;for(let r of e)t.has(r.name)&&n.add(r.name),t.add(r.name);return[...n]}var Dr=[`number`,`string`,`boolean`,`select`];function Or(e,t){return{name:e.name,...e.label===void 0?{}:{label:e.label},type:t,...t===`select`?{options:e.options??[`option`]}:{}}}function kr(e,t){let n=t.split(`,`).map(e=>e.trim()).filter(e=>e!==``),r=e.default!==void 0&&typeof e.default==`string`&&n.includes(e.default),{default:i,...a}=e;return{...r?e:a,options:n.length===0?[`option`]:n}}function Ar(e,t){let{default:n,...r}=e;return t===null?r:{...r,default:t}}function jr(e,t){let{label:n,...r}=e;return t.trim()===``?r:{...r,label:t}}function Mr({variables:t,onChange:n,onRename:r}){let{t:i}=Y(),a=e=>{switch(e){case`number`:return i(`actions.variables.typeNumber`,`number`);case`string`:return i(`actions.variables.typeText`,`text`);case`boolean`:return i(`actions.variables.typeBoolean`,`yes / no`);default:return i(`actions.variables.typeSelect`,`select`)}},s=(e,r)=>n(t.map((t,n)=>n===e?r:t));return o(qe,{headingId:`vars-heading`,title:i(`actions.variables.title`,`Variables`),icon:_e,actions:e(W,{variant:`outline`,size:`sm`,onClick:()=>n([...t,wr(t)]),children:[o(_,{className:`h-4 w-4`}),` `,i(`actions.variables.add`,`Variable`)]}),children:e(`div`,{className:`space-y-3 p-3`,children:[t.map((c,l)=>e(`div`,{className:`grid gap-2 sm:grid-cols-[1fr_1fr_8rem_1fr_1.2fr_auto] sm:items-end`,"data-testid":`variable-row`,children:[e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.name`,`Name`)}),o(K,{"aria-label":i(`actions.variables.nameAria`,`Variable name`),value:c.name,"aria-invalid":!Tr(c.name),onChange:e=>r(l,e.target.value)})]}),e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.label`,`Label`)}),o(K,{"aria-label":i(`actions.variables.label`,`Label`),value:c.label??``,onChange:e=>s(l,jr(c,e.target.value))})]}),e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.type`,`Type`)}),o(qt,{widthClass:`w-full`,"aria-label":i(`actions.variables.type`,`Type`),value:c.type,options:Dr.map(e=>({value:e,label:a(e)})),onChange:e=>{let t=Dr.find(t=>t===e.target.value);t!==void 0&&s(l,Or(c,t))}})]}),e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.default`,`Default`)}),o(Nr,{variable:c,onChange:e=>s(l,Ar(c,e))})]}),e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.options`,`Options`)}),o(K,{"aria-label":i(`actions.variables.options`,`Options`),value:(c.options??[]).join(`, `),disabled:c.type!==`select`,placeholder:i(`actions.variables.optionsHint`,`Only for a select`),onChange:e=>s(l,kr(c,e.target.value))})]}),o(W,{variant:`ghost`,"aria-label":i(`actions.variables.remove`,`Remove variable`),onClick:()=>n(t.filter((e,t)=>t!==l)),children:o(v,{className:`h-4 w-4`})})]},`${String(l)}`)),o(`p`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.hint`,`Callers can override a variable. In a step, the {x} button puts one in an argument.`)})]})})}function Nr({variable:e,onChange:t}){let{t:n}=Y(),r=n(`actions.variables.default`,`Default`);if(e.type===`number`)return o(Kt,{"aria-label":r,value:typeof e.default==`number`?e.default:void 0,onValue:t});if(e.type===`boolean`||e.type===`select`){let i=e.type===`boolean`?[{value:`true`,label:n(`common.yes`,`Yes`)},{value:`false`,label:n(`common.no`,`No`)}]:(e.options??[]).map(e=>({value:e,label:e}));return o(qt,{widthClass:`w-full`,"aria-label":r,value:e.default===void 0?``:String(e.default),options:[{value:``,label:n(`actions.variables.noDefault`,`None`)},...i],onChange:n=>{n.target.value===``?t(null):t(e.type===`boolean`?n.target.value===`true`:n.target.value)}})}return o(K,{"aria-label":r,value:typeof e.default==`string`?e.default:``,onChange:e=>t(e.target.value===``?null:e.target.value)})}u();var Pr=5e3;function Fr(e){return e.kind===`cap`||e.kind===`wait`}function Ir(e){return e instanceof Error?e.message:String(e)}function Lr(){let{t:e}=Y();return t=>{switch(t.kind){case`name`:return e(`actions.editor.problemName`,`Give the action a name.`);case`no-steps`:return e(`actions.editor.problemNoSteps`,`Add at least one step.`);case`undeclared`:return e(`actions.editor.problemUndeclared`,`A step uses {{name}}, which is not declared under Variables.`,{name:t.name});case`duplicate`:return e(`actions.editor.problemDuplicate`,`The variable {{name}} is declared twice.`,{name:t.name});case`bad-name`:return e(`actions.editor.problemBadName`,`The variable name "{{name}}" must start with a letter and use letters, digits or _.`,{name:t.name});default:return t.message}}}function Rr({entry:t,onClose:n,onSaved:i}){let{t:a}=Y(),s=d(),l=k(),u=On(),f=Lr(),[m,h]=c(()=>_r(t)),[g,_]=c(null),b=t!==null&&t.readOnly,x=()=>{s.invalidateQueries({queryKey:[[`actions`]]})},S=Ze({onSuccess:e=>{x(),i(e.action.id)}}),C=vt({onSuccess:x}),w=et({onSuccess:()=>{x(),n()}}),D=nt({onSuccess:x}),O=ut({actionId:t?.id??`none`},{enabled:t!==null,refetchInterval:Pr}),A=O.data?.traces.find(e=>e.runId===g)??null,j=r(()=>A===null?null:mr(A),[A]),M=br(m),N=r(()=>ir(m.variables,a),[m.variables,a]),P=S.isPending||C.isPending,F=S.error??C.error??w.error??D.error,I=(t?.variables??[]).some(e=>e.required===!0&&e.default===void 0);return e(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]`,"data-testid":`action-editor`,children:[e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(E,{className:`h-4 w-4 text-foreground-muted`}),o(K,{"aria-label":a(`actions.editor.name`,`Name`),className:`max-w-xs flex-1`,value:m.name,disabled:b,placeholder:a(`actions.editor.namePlaceholder`,`What this action does`),onChange:e=>h({...m,name:e.target.value})}),o(q,{variant:b?`info`:`primary`,children:b?t?.addonId??``:a(`actions.source.internal`,`Internal`)})]}),b?o(`p`,{className:`rounded-md border border-border bg-surface p-3 text-sm text-foreground-muted`,children:a(`actions.editor.readOnly`,`This action is declared by {{addon}}. Edit it there; you can run it from here.`,{addon:t?.addonId??``})}):e(p,{children:[o(Mr,{variables:m.variables,onChange:e=>h({...m,variables:e}),onRename:(e,t)=>h(Cr(m,e,t))}),o(En,{step:`steps`,title:a(`actions.editor.steps`,`Steps`),trace:j===null?null:j.thenBlock,children:o(nr,{actions:m.steps,devices:u,allowedKinds:[`cap`,`wait`],variables:N,onChange:e=>h({...m,steps:e.filter(Fr)})})})]}),!M.ok&&!b&&m.name!==``&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:f(M.reason)}),F!==null&&o(U,{message:Ir(F)}),e(`div`,{className:`flex flex-wrap gap-2`,children:[!b&&e(W,{onClick:()=>{M.ok&&(t===null?S.mutate({action:M.input}):C.mutate({actionId:t.id,action:M.input}))},disabled:P||!M.ok,children:[P&&o(T,{className:`h-4 w-4 animate-spin`}),` `,a(`common.save`,`Save`)]}),t!==null&&e(W,{variant:`outline`,disabled:D.isPending||I,title:I?a(`actions.editor.runNeedsDefaults`,`Give each required variable a default to run it from here.`):void 0,onClick:()=>D.mutate({actionId:t.id}),children:[o(y,{className:`h-4 w-4`}),` `,a(`actions.editor.runNow`,`Run now`)]}),t!==null&&!b&&e(W,{variant:`ghost`,disabled:w.isPending,onClick:()=>{l({title:a(`actions.editor.deleteTitle`,`Delete this action?`),message:a(`actions.editor.deleteMessage`,`{{name}} will be deleted, and removed from every camera that links it.`,{name:t.name}),confirmLabel:a(`common.delete`,`Delete`),variant:`danger`}).then(e=>{e&&w.mutate({actionId:t.id})})},children:[o(v,{className:`h-4 w-4`}),` `,a(`common.delete`,`Delete`)]}),o(W,{variant:`ghost`,onClick:n,children:a(`common.close`,`Close`)})]})]}),o(`div`,{className:`order-first lg:order-last`,children:o(wn,{traces:t===null?[]:O.data?.traces,selectedId:g,onSelect:_})})]})}u();var zr=5e3;function Br(e){return e instanceof Error?e.message:String(e)}function Vr(){let{t:e}=Y();return t=>t.status.isRunning?{variant:`info`,label:e(`actions.status.running`,`Running`)}:t.status.lastError===null?t.status.lastRunAt===null?{variant:`neutral`,label:e(`actions.status.neverRan`,`Never ran`)}:{variant:`success`,label:e(`actions.status.ok`,`OK`)}:{variant:`danger`,label:e(`actions.status.failed`,`Failed`)}}function Hr({createRequested:t=!1,onCreateConsumed:n}){let{t:i}=Y(),a=d(),c=Vr(),{state:l,openNew:u,openEdit:f,close:p}=tt({editKey:`action`,newKey:`new`}),m=ot({},{refetchInterval:zr}),h=nt({onSuccess:()=>void a.invalidateQueries({queryKey:[[`actions`]]})});s(()=>{t&&(u(),n?.())},[t,n,u]);let g=m.data??[],v=l.mode===`edit`?g.find(e=>e.id===l.id)??null:null,b=r(()=>[{key:`name`,header:i(`actions.list.name`,`Name`),render:e=>o(`span`,{className:`font-medium`,children:e.name}),sortValue:e=>e.name},{key:`source`,header:i(`actions.list.source`,`Source`),render:e=>e.readOnly?o(q,{variant:`info`,children:e.addonId}):o(q,{variant:`primary`,children:i(`actions.source.internal`,`Internal`)}),sortValue:e=>e.addonId},{key:`lastRun`,header:i(`actions.list.lastRun`,`Last run`),render:e=>e.status.lastRunAt===null?o(`span`,{className:`text-foreground-subtle`,children:`-`}):kt(e.status.lastRunAt),sortValue:e=>e.status.lastRunAt},{key:`status`,header:i(`actions.list.status`,`Status`),render:e=>{let t=c(e);return o(`span`,{title:e.status.lastError??void 0,children:o(q,{variant:t.variant,children:t.label})})},notSortableReason:i(`actions.list.statusNotSortable`,`Derived from the latest run`)},{key:`run`,align:`right`,render:t=>e(W,{variant:`outline`,size:`sm`,disabled:h.isPending||t.status.isRunning,"aria-label":i(`actions.list.runAria`,`Run {{name}}`,{name:t.name}),onClick:e=>{e.stopPropagation(),h.mutate({actionId:t.id})},children:[o(y,{className:`h-4 w-4`}),` `,i(`actions.list.run`,`Run`)]}),notSortableReason:i(`actions.list.runNotSortable`,`A control`)}],[h,c,i]);return l.mode===`closed`?e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:i(`actions.list.hint`,`Actions are things this installation can do. Run one here, link it to a camera, or use it in an automation.`)}),m.error!=null&&o(U,{title:i(`actions.list.couldNotRead`,`Could not read the actions`),message:Br(m.error),onRetry:()=>void m.refetch()}),h.error!=null&&o(U,{message:Br(h.error)}),m.data!==void 0&&g.length===0?o(Ce,{icon:E,title:i(`actions.list.emptyTitle`,`No actions yet`),description:i(`actions.list.emptyDescription`,`An action is a short list of commands, such as feeding the dog, that you can reuse.`),action:e(W,{onClick:u,children:[o(_,{className:`h-4 w-4`}),` `,i(`actions.list.new`,`New action`)]})}):o(Be,{columns:b,rows:g,rowKey:e=>e.id,pageSize:25,maxBodyHeight:be,emptyMessage:i(`actions.list.loading`,`Loading actions…`),onRowClick:e=>f(e.id)})]}):o(Rr,{entry:v,onClose:p,onSaved:f},v?.id??`new`)}function Ur({value:t,field:n,deviceId:r,cap:i,onChange:a}){let{t:s}=Y(),c=Yr(n,r,i);if(n?.kind===`boolean`)return o(G,{value:t===!0?`true`:`false`,onChange:e=>a(e.target.value===`true`),options:[{value:`true`,label:s(`common.true`)},{value:`false`,label:s(`common.false`)}]});if(n?.kind===`enum`&&n.enumValues!==void 0&&n.enumValues.length>0)return o(G,{value:String(t),onChange:e=>a(e.target.value),options:n.enumValues.map(e=>({value:e,label:e}))});if(n?.kind===`number`){let n=typeof t==`number`&&c?c.toDisplayValue(t):t;return e(`span`,{className:`inline-flex items-center gap-1`,children:[o(K,{type:`number`,value:typeof n==`number`?String(n):``,placeholder:`0`,onChange:e=>{let t=Number(e.target.value);e.target.value!==``&&!Number.isNaN(t)&&a(c?c.fromDisplayValue(t):t)}}),c!==void 0&&c.unit.length>0?o(`span`,{className:`text-xs text-foreground-subtle`,children:c.unit}):null]})}return o(K,{value:String(t),placeholder:s(`common.valueWord`),onChange:e=>a(e.target.value)})}function Wr({value:e,field:t,deviceId:n,cap:r,onChange:i}){let{t:a}=Y(),s=Yr(t,n,r);return o(K,{value:(s?e.map(e=>typeof e==`number`?s.toDisplayValue(e):e):e).join(`, `),placeholder:a(`automation.valueInput.oneTwoThree`,`one, two, three`),onChange:e=>{let n=e.target.value.split(`,`).map(e=>e.trim()).filter(e=>e!==``);i(t?.kind===`number`?n.map(e=>Number(e)).filter(e=>!Number.isNaN(e)).map(e=>s?s.fromDisplayValue(e):e):n)}})}function Gr(e){return typeof e==`object`}function Kr(e){return Gr(e)?e[0]??``:e}function qr(e){return Gr(e)?e:typeof e==`boolean`?[]:[e]}function Jr(e,t){if(!(e===void 0||e===`none`)){if(e!==`device`)return e;if(!(t===void 0||t===`device`||t===`none`))return t}}function Yr(e,t,n){let r=t??0,i=e?.kind===`number`&&e.quantity!==void 0,{data:a}=xe({deviceId:r},{enabled:i&&r>0}),o=a?.sourceInfo?.quantity,s=ee(o)?o:void 0,c=Jr(e?.quantity,s);if(c===void 0)return;let l=a?.display;return Ge({quantity:c,display:l,capName:n})}function Xr({leaf:t,devices:n,onChange:r}){let{t:i}=Y(),a={deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath},s=jn(a),c=Hn(s?.kind),l=t.operator===`in`,u=e=>{r({...t,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath})},d=e=>{let n=Zr(e,c);r({...t,operator:n,value:n===`in`?qr(t.value):Kr(t.value)})};return e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[o(Mn,{value:a,devices:n,onChange:u}),e(`label`,{className:`min-w-[8rem]`,children:[o(Z,{children:i(`automation.conditionRow.comparison`,`Comparison`)}),o(G,{value:t.operator,onChange:e=>d(e.target.value),options:c.map(e=>({value:e.value,label:e.label}))})]}),e(`label`,{className:`min-w-[9rem] flex-1`,children:[o(Z,{children:i(`automation.conditionRow.value`,`Value`)}),l?o(Wr,{value:qr(t.value),field:s,deviceId:t.deviceId,cap:t.cap,onChange:e=>r({...t,value:e})}):o(Ur,{value:Kr(t.value),field:s,deviceId:t.deviceId,cap:t.cap,onChange:e=>r({...t,value:e})})]})]})}function Zr(e,t){return t.find(t=>t.value===e)?.value??`eq`}var Qr={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function $r({leaf:t,devices:n,onChange:r}){let{t:i}=Y(),a=Object.entries(t.bindings),s=e=>{r({kind:`expression`,expr:t.expr,bindings:e})};return e(`div`,{className:`space-y-2`,children:[e(`label`,{className:`block`,children:[o(Z,{children:i(`automation.expressionLeafRow.expression`,`Expression`)}),o(K,{value:t.expr,placeholder:i(`automation.expressionLeafRow.indoorOutdoor5`,`indoor - outdoor > 5`),onChange:e=>r({kind:`expression`,expr:e.target.value,bindings:t.bindings})}),o(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:i(`automation.expressionLeafRow.mustEvaluateToTrueOr`,`Must evaluate to true or false. Every name in it has to be bound below — an unbound name is refused when the automation is saved, not when it runs.`)})]}),e(`div`,{className:`space-y-1.5`,children:[a.length===0&&o(`p`,{className:`text-xs text-foreground-subtle`,children:i(`automation.expressionLeafRow.noNamesBoundYetAn`,`No names bound yet. An expression reads devices only through these.`)}),a.map(([e,r])=>o(ei,{alias:e,source:r,devices:n,onRename:n=>s(oi(t.bindings,e,n)),onChange:n=>s({...t.bindings,[e]:n}),onRemove:()=>s(si(t.bindings,e))},e)),e(W,{variant:`ghost`,onClick:()=>s({...t.bindings,[ai(t.bindings)]:Qr}),children:[o(_,{className:`h-3.5 w-3.5`}),` `,i(`common.name`)]})]})]})}function ei({alias:t,source:n,devices:r,onRename:i,onChange:a,onRemove:s}){let{t:c}=Y(),l=n.kind===`literal`,u=l?{deviceId:0,cap:``,fieldPath:``}:{deviceId:ri(r,ni(n)),cap:n.cap,fieldPath:n.fieldPath};return e(`div`,{className:`flex flex-wrap items-end gap-2 rounded border border-border p-2`,children:[e(`label`,{className:`w-32`,children:[o(Z,{children:c(`automation.expressionLeafRow.name`,`Name`)}),o(K,{value:t,placeholder:c(`automation.expressionLeafRow.aliasExample`),onChange:e=>i(e.target.value)})]}),e(`label`,{className:`w-36`,children:[o(Z,{children:c(`automation.expressionLeafRow.reads`,`Reads`)}),o(G,{value:l?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:Qr),options:[{value:`global`,label:c(`automation.expressionLeafRow.aDeviceField`,`A device field`)},{value:`literal`,label:c(`automation.expressionLeafRow.aConstant`,`A constant`)}]})]}),l?e(`label`,{className:`min-w-[9rem] flex-1`,children:[o(Z,{children:c(`automation.expressionLeafRow.constant`,`Constant`)}),o(K,{value:n.value===null?``:String(n.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:ti(e.target.value)})})]}):o(Mn,{value:u,devices:r,onChange:e=>a({kind:`global`,sourceStableId:ii(r,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),o(W,{variant:`ghost`,onClick:s,title:c(`automation.expressionLeafRow.removeThisName`,`Remove this name`),children:o(v,{className:`h-3.5 w-3.5`})})]})}function ti(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function ni(e){return e.kind===`global`?e.sourceStableId:``}function ri(e,t){return e.find(e=>e.stableId===t)?.id??0}function ii(e,t){return e.find(e=>e.id===t)?.stableId??``}function ai(e){for(let t=0;t<26;t+=1){let n=String.fromCharCode(97+t);if(!(n in e))return n}return`n${String(Object.keys(e).length)}`}function oi(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function si(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function ci(e){return e.kind===`all`||e.kind===`any`}function Q(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:ci(t)?t:{kind:`all`,children:[t]}}function li(e,t){return t===null||ci(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function ui(e){return li(e,Q(e))}function di(e,t){if(t.length===0)return e;let[n,...r]=t;if(n===void 0)return e;if(e.kind===`not`)return n===0?di(e.child,r):null;if(!ci(e))return null;let i=e.children[n];return i===void 0?null:di(i,r)}function fi(e,t,n){if(t.length===0)return n(e);let[r,...i]=t;if(r===void 0)return n(e);if(e.kind===`not`){if(r!==0)return e;let t=fi(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!ci(e))return e;let a=e.children[r];if(a===void 0)return e;let o=fi(a,i,n),s=o===null?[...e.children.slice(0,r),...e.children.slice(r+1)]:[...e.children.slice(0,r),o,...e.children.slice(r+1)];return s.length===0?null:{kind:e.kind,children:s}}function pi(e){return e===null?null:ce({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function mi(e){let t=Q(e);return{depth:t.children.length===0?0:ie(t),leaves:t.children.length===0?0:de(t),depthLimit:3,leafLimit:32}}function hi(e,t){let n=pi(t);return n===null?{ok:!0,recipe:li(e,t)}:{ok:!1,reason:n}}function gi(e,t){let n=Q(e);return hi(e,{kind:n.kind,children:[...n.children,t]})}function _i(e,t,n){return li(e,fi(Q(e),t,()=>n))}function vi(e,t){return li(e,fi(Q(e),t,()=>null))}function yi(e,t,n){return li(e,fi(Q(e),t,e=>ci(e)?{kind:n,children:e.children}:e))}function bi(e,t){return di(Q(e),t)===null?{ok:!1,reason:J.t(`helpers.recipeOps.rowGone`)}:hi(e,fi(Q(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function xi(e){if(e.length===0)return null;let t=e[e.length-1];return t===void 0?null:{path:e.slice(0,-1),index:t}}function Si(e,t,n){if(t.length<2)return{ok:!1,reason:J.t(`helpers.recipeOps.selectTwo`)};if(new Set(t.map(e=>e.slice(0,-1).join(`/`))).size!==1)return{ok:!1,reason:J.t(`helpers.recipeOps.differentGroups`)};let r=xi(t[0]??[]);if(r===null)return{ok:!1,reason:J.t(`helpers.recipeOps.rootGroup`)};let i=Q(e),a=di(i,r.path);if(a===null||!ci(a))return{ok:!1,reason:J.t(`helpers.recipeOps.insideNot`)};let o=[...t.map(e=>e[e.length-1]??-1)].sort((e,t)=>e-t),s=o.map(e=>a.children[e]).filter(e=>e!==void 0);if(s.length!==o.length)return{ok:!1,reason:J.t(`helpers.recipeOps.selectedGone`)};let c=a.children.filter((e,t)=>!o.includes(t)),l=o[0]??0,u={kind:n,children:s},d={kind:a.kind,children:[...c.slice(0,l),u,...c.slice(l)]};return hi(e,fi(i,r.path,()=>d))}function Ci(e,t){if(t.length===0)return{ok:!1,reason:J.t(`helpers.recipeOps.outerNotGroup`)};let n=Q(e),r=di(n,t);if(r===null)return{ok:!1,reason:J.t(`helpers.recipeOps.groupGone`)};if(r.kind===`not`)return hi(e,fi(n,t,()=>r.child));if(!ci(r))return{ok:!1,reason:J.t(`helpers.recipeOps.rowIsCondition`)};let i=xi(t);if(i===null)return{ok:!1,reason:J.t(`helpers.recipeOps.noParent`)};let a=di(n,i.path);if(a===null||!ci(a))return{ok:!1,reason:J.t(`helpers.recipeOps.groupInNot`)};let o={kind:a.kind,children:[...a.children.slice(0,i.index),...r.children,...a.children.slice(i.index+1)]};return hi(e,fi(n,i.path,()=>o))}var wi=`text-xs text-foreground-subtle`;function Ti({children:e}){return o(`span`,{className:wi,children:e})}function Ei(e,t){return e.includes(t)?e.filter(e=>e!==t):[...e,t]}function Di(){let{t:e}=Y();return t=>{switch(t){case`person`:return e(`flow.class.person`,`Person`);case`vehicle`:return e(`flow.class.vehicle`,`Vehicle`);case`animal`:return e(`flow.class.animal`,`Animal`);case`package`:return e(`flow.class.package`,`Package`);default:return t}}}function Oi({selected:t,onChange:n,hint:r}){let{t:i}=Y(),a=Di(),s=ne.map(e=>e.id),c=t.filter(e=>!s.includes(e));return e(`div`,{className:`space-y-1`,children:[o(Ti,{children:i(`flow.scene.class`,`Class`)}),o(`div`,{className:`flex flex-wrap gap-2`,children:[...s,...c].map(e=>o(W,{size:`sm`,variant:t.includes(e)?`primary`:`outline`,"aria-pressed":t.includes(e),onClick:()=>n(Ei(t,e)),children:a(e)},e))}),r!==void 0&&o(`p`,{className:wi,children:r})]})}function ki({devices:t,selected:n,onChange:r}){let{t:i}=Y(),a=t.filter(e=>e.type===re.Camera);return e(`div`,{className:`space-y-1`,children:[o(Ti,{children:i(`flow.scene.cameras`,`Cameras`)}),o(mn,{devices:a,selection:`multiple`,noun:`camera`,value:n,testId:`scene-cameras`,onChange:r})]})}function Ai({device:t,deviceId:n,selected:r,onToggle:i}){let a=Ye({deviceId:n});return a.data===void 0||a.data.length===0?null:e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(`span`,{className:wi,children:t?.name??`#${String(n)}`}),a.data.map(e=>o(W,{size:`sm`,variant:r.includes(e.id)?`primary`:`outline`,"aria-pressed":r.includes(e.id),onClick:()=>i(e.id),children:e.name},e.id))]})}function ji({devices:t,deviceIds:n,selected:r,onChange:i}){let{t:a}=Y();if(n.length===0)return null;let s=e=>{let t=Ei(r,e);i(t.length===0?void 0:t)};return e(`div`,{className:`space-y-1`,children:[o(Ti,{children:a(`flow.scene.zones`,`Zones`)}),o(`div`,{className:`space-y-2`,children:n.map(e=>o(Ai,{device:t.find(t=>t.id===e),deviceId:e,selected:r,onToggle:s},e))}),o(`p`,{className:wi,children:r.length===0?a(`flow.scene.wholeScene`,`None picked: the whole scene counts.`):a(`flow.scene.zonesPicked`,`Only these zones count.`)})]})}var Mi=100;function Ni({trigger:t,devices:n,onChange:r}){let{t:i}=Y(),a=Math.round((t.minScore??0)*Mi),s=e=>{let{zones:n,...i}=t;r(e===void 0?i:{...i,zones:[...e]})},c=e=>{let{minScore:n,...i}=t;r(e<=0?i:{...i,minScore:e/Mi})};return e(`div`,{className:`w-full space-y-3`,"data-testid":`detection-fields`,children:[o(Oi,{selected:t.classes,onChange:e=>r({...t,classes:[...e]})}),o(ki,{devices:n,selected:t.deviceIds,onChange:e=>r({...t,deviceIds:[...e]})}),o(ji,{devices:n,deviceIds:t.deviceIds,selected:t.zones??[],onChange:s}),e(`div`,{className:`space-y-1`,children:[o(Ti,{children:a===0?i(`flow.scene.minScoreAny`,`Minimum score: any`):i(`flow.scene.minScore`,`Minimum score: {{value}}`,{value:(a/Mi).toFixed(2)})}),o(`input`,{type:`range`,min:0,max:Mi,value:a,"aria-label":i(`flow.scene.minScoreAria`,`Minimum score`),className:`block w-full max-w-sm accent-primary`,onChange:e=>c(Number(e.target.value))})]})]})}function Pi({trigger:t,devices:n,onChange:r}){let{t:i}=Y();return e(`div`,{className:`w-full space-y-3`,"data-testid":`stationary-fields`,children:[o(Oi,{selected:t.classes??[],onChange:e=>{let{classes:n,...i}=t;r(e.length===0?i:{...i,classes:[...e]})},hint:t.classes===void 0?i(`flow.scene.anyClass`,`None picked: any class counts.`):void 0}),o(ki,{devices:n,selected:t.deviceIds,onChange:e=>r({...t,deviceIds:[...e]})}),o(ji,{devices:n,deviceIds:t.deviceIds,selected:t.zones??[],onChange:e=>{let{zones:n,...i}=t;r(e===void 0?i:{...i,zones:[...e]})}}),o(ht,{label:i(`flow.scene.firesWhen`,`Fires when it`),value:t.phase,onChange:e=>r({...t,phase:e}),options:[{value:`appeared`,label:i(`flow.scene.phaseAppeared`,`Stopped (parked)`)},{value:`departed`,label:i(`flow.scene.phaseDeparted`,`Left`)}]})]})}function Fi({trigger:t,onChange:n}){let{t:r}=Y();return e(`div`,{className:`flex items-center gap-2`,"data-testid":`interval-fields`,children:[o(Ti,{children:r(`flow.scene.every`,`Every`)}),o(Kt,{"aria-label":r(`flow.scene.intervalMinutes`,`Minutes`),className:`w-20`,value:t.minutes,onValue:e=>{e!==null&&n({kind:`interval`,minutes:Math.round(e)})}}),o(Ti,{children:r(`flow.scene.minutes`,`minutes`)})]})}function Ii({leaf:t,devices:n,onChange:r}){let{t:i}=Y(),a=n.filter(e=>e.type===re.Camera),s=e=>{let{classes:n,...i}=t;r(e.length===0?i:{...i,classes:[...e]})},c=e=>{let{zones:n,...i}=t;r(e===void 0?i:{...i,zones:[...e]})},l=e=>{let{zones:n,...i}=t;r({...i,deviceId:e})};return e(`div`,{className:`space-y-3`,"data-testid":`stationary-present-fields`,children:[e(`div`,{className:`space-y-1`,children:[o(Ti,{children:i(`flow.scene.parkedOn`,`An object is parked on`)}),o(mn,{devices:a,selection:`single`,noun:`camera`,value:t.deviceId>0?[t.deviceId]:[],testId:`stationary-present-camera`,onChange:e=>{let n=e[0];n!==void 0&&n!==t.deviceId&&l(n)}})]}),o(Oi,{selected:t.classes??[],onChange:s,hint:t.classes===void 0?i(`flow.scene.anyClass`,`None picked: any class counts.`):void 0}),o(ji,{devices:n,deviceIds:t.deviceId>0?[t.deviceId]:[],selected:t.zones??[],onChange:c})]})}u();var Li=[{value:`all`,labelKey:`automation.conditionTree.allOf`},{value:`any`,labelKey:`automation.conditionTree.anyOf`}];function Ri(e){return e.join(`/`)}function zi(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Bi({recipe:t,devices:n,onChange:i}){let{t:a}=Y(),[s,l]=c([]),[u,d]=c(null),f=Q(t),p=mi(t),m=r(()=>s.map(zi),[s]),h=e=>{if(!e.ok){d(e.reason);return}d(null),l([]),i(e.recipe)},g=Si(t,m,`all`),v=Si(t,m,`any`),y=m.length===1?bi(t,m[0]??[]):{ok:!1,reason:a(`automation.conditionTree.selectOneNegate`)},x={devices:n,selected:new Set(s),onToggleSelect:e=>l(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(e,n)=>i(_i(t,e,n)),onRemove:e=>{l([]),i(vi(t,e))},onSetKind:(e,n)=>i(yi(t,e,n)),onUngroup:e=>h(Ci(t,e))};return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(q,{variant:`default`,children:a(`automation.conditionTree.andOnlyIf`,`And only if`)}),o(`div`,{className:`w-32`,children:o(G,{value:f.kind,onChange:e=>i(yi(t,[],Vi(e.target.value))),options:Li.map(e=>({value:e.value,label:a(e.labelKey)}))})}),o(`span`,{className:`text-xs text-foreground-subtle`,children:a(`automation.conditionTree.budget`,{depth:p.depth,depthLimit:p.depthLimit,leaves:p.leaves,leafLimit:p.leafLimit})})]}),f.children.length===0?o(`p`,{className:`text-xs text-foreground-subtle`,children:a(`automation.conditionTree.noConditionsTheActionsRun`,`No conditions. The actions run every time a trigger fires.`)}):o(Hi,{container:f,path:[],handlers:x}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(W,{variant:`outline`,onClick:()=>h(gi(t,qn())),title:a(`automation.conditionTree.compareOneDeviceFieldTo`,`Compare one device field to a value`),children:[o(_,{className:`h-4 w-4`}),` `,a(`automation.conditionTree.addCondition`)]}),e(W,{variant:`outline`,onClick:()=>h(gi(t,Yn())),title:a(`automation.conditionTree.arithmeticAcrossDeviceFieldsThe`,`Arithmetic across device fields — the bounded expression engine`),children:[o(H,{className:`h-4 w-4`}),` `,a(`automation.conditionTree.addExpression`)]}),e(W,{variant:`outline`,onClick:()=>h(gi(t,Jn())),title:a(`flow.scene.addParkedTitle`,`True while an object is parked on a camera, in a zone`),children:[o(b,{className:`h-4 w-4`}),` `,a(`flow.scene.addParked`,`Parked object`)]}),o(`span`,{className:`mx-1 h-5 w-px bg-border`}),o(W,{variant:`ghost`,disabled:!g.ok,onClick:()=>h(g),title:g.ok?a(`automation.conditionTree.allSelectedRowsMustBe`,`All selected rows must be true`):g.reason,children:a(`automation.conditionTree.groupAsAll`,`Group as ALL`)}),o(W,{variant:`ghost`,disabled:!v.ok,onClick:()=>h(v),title:v.ok?a(`automation.conditionTree.anyOneOfTheSelected`,`Any one of the selected rows is enough`):v.reason,children:a(`automation.conditionTree.groupAsAny`,`Group as ANY`)}),o(W,{variant:`ghost`,disabled:!y.ok,onClick:()=>h(y),title:y.ok?a(`automation.conditionTree.invertTheSelectedRow`,`Invert the selected row`):y.reason,children:`NOT`}),s.length>0&&o(`span`,{className:`text-xs text-foreground-subtle`,children:a(`common.selectedCount`,{count:s.length})})]}),u!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:u})]})}function Vi(e){return e===`any`?`any`:`all`}function Hi({container:e,path:t,handlers:n}){return o(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>o(Ui,{node:e,path:[...t,r],handlers:n},Ri([...t,r])))})}function Ui({node:t,path:n,handlers:r}){let{t:i}=Y(),a=Ri(n),s=o(He,{checked:r.selected.has(a),onChange:()=>r.onToggleSelect(a),"aria-label":i(`automation.conditionTree.selectThisRowForGrouping`,`Select this row for grouping`)});return ci(t)?e(`div`,{className:`rounded border border-border bg-surface-subtle/40 p-2`,children:[e(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[s,o(`div`,{className:`w-32`,children:o(G,{value:t.kind,onChange:e=>r.onSetKind(n,Vi(e.target.value)),options:Li.map(e=>({value:e.value,label:i(e.labelKey)}))})}),e(W,{variant:`ghost`,onClick:()=>r.onUngroup(n),title:i(`automation.conditionTree.dissolveThisGroupKeepingIts`,`Dissolve this group, keeping its rows`),children:[o(he,{className:`h-3.5 w-3.5`}),` `,i(`automation.conditionTree.ungroup`)]}),o(W,{variant:`ghost`,onClick:()=>r.onRemove(n),title:i(`automation.conditionTree.deleteThisGroupAndEverything`,`Delete this group and everything in it`),children:o(v,{className:`h-3.5 w-3.5`})})]}),o(`div`,{className:`pl-4`,children:o(Hi,{container:t,path:n,handlers:r})})]}):t.kind===`not`?e(`div`,{className:`rounded border border-border p-2`,children:[e(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[s,o(q,{variant:`warning`,children:`NOT`}),e(W,{variant:`ghost`,onClick:()=>r.onUngroup(n),title:i(`automation.conditionTree.removeTheNotKeepingThe`,`Remove the NOT, keeping the row`),children:[o(he,{className:`h-3.5 w-3.5`}),` `,i(`automation.conditionTree.removeNot`)]})]}),o(`div`,{className:`pl-4`,children:o(Ui,{node:t.child,path:[...n,0],handlers:r})})]}):e(`div`,{className:`flex items-start gap-2 rounded border border-border p-2`,children:[o(`div`,{className:`pt-6`,children:s}),o(`div`,{className:`min-w-0 flex-1`,children:t.kind===`condition`?o(Xr,{leaf:t,devices:r.devices,onChange:e=>r.onUpdate(n,e)}):t.kind===`expression`?o($r,{leaf:t,devices:r.devices,onChange:e=>r.onUpdate(n,e)}):o(Ii,{leaf:t,devices:r.devices,onChange:e=>r.onUpdate(n,e)})}),o(W,{variant:`ghost`,onClick:()=>r.onRemove(n),title:i(`automation.conditionTree.removeThisCondition`,`Remove this condition`),children:o(v,{className:`h-3.5 w-3.5`})})]})}u();function Wi({code:t,error:n,canEject:r,ejecting:i,onEject:a}){let{t:s}=Y(),[l,u]=c(!1),d=k(),f=async()=>{await d({title:s(`automation.generatedCodePanel.ejectToCodeThisCannot`,`Eject to code — this cannot be undone`),message:s(`automation.generatedCodePanel.theRecipeIsRemovedFrom`,`The recipe is removed from the block and it becomes an ordinary script. The visual editor will no longer open it, and there is no way back to it except authoring a new automation from scratch. The code itself is kept exactly as it is now.`),confirmLabel:s(`automation.generatedCodePanel.ejectToCode`,`Eject to code`),cancelLabel:s(`automation.generatedCodePanel.keepItVisual`,`Keep it visual`),variant:`warning`})&&a()};return e(`div`,{className:`rounded border border-border`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-2`,children:[e(W,{variant:`ghost`,onClick:()=>u(!l),children:[o(l?g:x,{className:`h-4 w-4`}),s(`automation.generatedCodePanel.generatedCode`,`Generated code`)]}),o(`span`,{className:`text-xs text-foreground-subtle`,children:s(`automation.generatedCodePanel.derivedFromTheRecipeAbove`,`Derived from the recipe above — regenerated on every save, never edited here.`)}),e(W,{className:`ml-auto`,variant:`ghost`,disabled:!r||t===null||i,onClick:()=>void f(),title:r?s(`automation.generatedCodePanel.takePermanentOwnershipOfThis`,`Take permanent ownership of this code as a script`):s(`automation.generatedCodePanel.saveTheAutomationFirstThere`,`Save the automation first — there is no stored block to eject yet`),children:[o(ve,{className:`h-4 w-4`}),` `,s(`automation.generatedCodePanel.eject`)]})]}),l&&o(`div`,{className:`border-t border-border p-3`,children:t===null?o(`p`,{className:`text-xs text-warning`,children:n??s(`automation.generatedCodePanel.theRecipeIsNotComplete`,`The recipe is not complete enough to generate a block yet.`)}):o(rt,{maxHeight:420,children:t})})]})}var Gi=[`detection`,`stationary`,`device-state`,`device-event`,`schedule`,`interval`,`manual`],Ki={detection:`scene`,stationary:`scene`,"device-state":`device`,"device-event":`device`,schedule:`time`,interval:`time`,manual:`manual`};function qi(){let{t:e}=Y(),t={scene:e(`flow.triggerGroup.scene`,`Scene`),device:e(`flow.triggerGroup.device`,`Devices`),time:e(`flow.triggerGroup.time`,`Time`),manual:e(`flow.triggerGroup.manual`,`By hand`)},n={detection:e(`flow.triggerHint.detection`,`An object class is detected on a camera`),stationary:e(`flow.triggerHint.stationary`,`An object stops, or leaves`),"device-state":e(`flow.triggerHint.deviceState`,`A device value changes or takes a value`),"device-event":e(`flow.triggerHint.deviceEvent`,`An event on the system`),schedule:e(`flow.triggerHint.schedule`,`At a time of day`),interval:e(`flow.triggerHint.interval`,`Again and again, every few minutes`),manual:e(`flow.triggerHint.manual`,`Only when you run it`)};return Gi.map(e=>({value:e,label:Un(e),description:n[e],group:t[Ki[e]]}))}var Ji=Object.values(ue).sort((e,t)=>e.localeCompare(t));function Yi({triggers:t,devices:n,onChange:r}){let{t:i}=Y();return e(`div`,{className:`space-y-2`,children:[t.length===0&&o(`p`,{className:`text-xs text-warning`,children:i(`automation.triggerEditor.noTriggersYetWithoutOne`,`No triggers yet. Without one nothing can ever start this automation — not even "Run actions", which needs a manual trigger to have somewhere to arrive.`)}),t.map((e,i)=>o(Xi,{trigger:e,devices:n,position:i,onChange:e=>r(Xn(t,i,e)),onRemove:()=>r(Zn(t,i))},`${e.kind}-${String(i)}`)),e(W,{variant:`outline`,onClick:()=>r([...t,Gn(`device-state`)]),title:i(`automation.triggerEditor.addAnotherWayThisAutomation`,`Add another way this automation can start`),children:[o(_,{className:`h-4 w-4`}),` `,i(`automation.triggerEditor.trigger`)]})]})}function Xi({trigger:t,devices:n,position:r,onChange:i,onRemove:a}){let{t:s}=Y(),c=qi();return e(`div`,{className:`rounded border border-border p-3`,children:[e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[o(q,{variant:`default`,children:r===0?s(`automation.triggerEditor.when`,`When`):s(`automation.triggerEditor.orWhen`,`or when`)}),e(`div`,{className:`min-w-[13rem] flex-1`,children:[o(Z,{children:s(`automation.triggerEditor.trigger`,`Trigger`)}),o(Le,{mode:`single`,singleDisplay:`field`,options:c,value:t.kind,onChange:e=>{e!==t.kind&&i(Gn(Zi(e)))}})]}),o(W,{variant:`ghost`,onClick:a,title:s(`automation.triggerEditor.removeThisTrigger`,`Remove this trigger`),children:o(v,{className:`h-4 w-4`})})]}),e(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[t.kind===`device-state`&&o($i,{trigger:t,devices:n,onChange:i}),t.kind===`device-event`&&o(ta,{trigger:t,devices:n,onChange:i}),t.kind===`schedule`&&e(`label`,{className:`min-w-[14rem] flex-1`,children:[o(Z,{children:s(`automation.triggerEditor.cronExpression`,`Cron expression`)}),o(K,{value:t.cron,placeholder:`0 30 23 * * *`,onChange:e=>i({kind:`schedule`,cron:e.target.value})}),o(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:o(X,{i18nKey:`automation.triggerEditor.cronHint`,components:{code:o(`code`,{})}})})]}),t.kind===`detection`&&o(Ni,{trigger:t,devices:n,onChange:i}),t.kind===`stationary`&&o(Pi,{trigger:t,devices:n,onChange:i}),t.kind===`interval`&&o(Fi,{trigger:t,onChange:i}),t.kind===`manual`&&o(`p`,{className:`text-xs text-foreground-subtle`,children:o(X,{i18nKey:`automation.triggerEditor.manualHint`,components:{b:o(`strong`,{})}})})]})]})}function Zi(e){return Gi.find(t=>t===e)??`manual`}function Qi(e,t){return{kind:`device-state`,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath,...t.becomes===void 0?{}:{becomes:t.becomes},...t.edge===void 0?{}:{edge:t.edge},...t.forMs===void 0?{}:{forMs:t.forMs},...t.debounceMs===void 0?{}:{debounceMs:t.debounceMs}}}function $i({trigger:t,devices:n,onChange:r}){let{t:i}=Y(),a={deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath},s=jn(a),c={...t.becomes===void 0?{}:{becomes:t.becomes},...t.edge===void 0?{}:{edge:t.edge},...t.forMs===void 0?{}:{forMs:t.forMs},...t.debounceMs===void 0?{}:{debounceMs:t.debounceMs}};return e(p,{children:[o(Mn,{value:a,devices:n,onChange:e=>r(Qi(e,c))}),e(`div`,{className:`min-w-[11rem] flex-1`,children:[o(Z,{children:i(`automation.triggerEditor.becomes`,`Becomes`)}),e(`div`,{className:`flex items-center gap-2`,children:[e(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[o(He,{checked:t.becomes===void 0,onChange:e=>r(Qi(a,{...c,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),i(`automation.triggerEditor.anyChange`,`any change`)]}),t.becomes!==void 0&&o(Ur,{value:t.becomes,field:s,deviceId:a.deviceId,cap:a.cap,onChange:e=>r(Qi(a,{...c,becomes:e}))})]})]}),e(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[o(He,{checked:t.edge===!0,onChange:e=>r(Qi(a,{...c,...e.target.checked?{edge:!0}:{edge:void 0}}))}),i(`automation.triggerEditor.onlyOnAChange`,`only on a change`)]}),e(`label`,{className:`w-28`,children:[o(Z,{children:i(`automation.triggerEditor.heldForS`,`Held for (s)`)}),o(K,{type:`number`,min:0,value:t.forMs===void 0?``:String(t.forMs/1e3),placeholder:`0`,onChange:e=>r(Qi(a,{...c,forMs:ea(e.target.value)}))})]}),e(`label`,{className:`w-28`,children:[o(Z,{children:i(`automation.triggerEditor.debounceS`,`Debounce (s)`)}),o(K,{type:`number`,min:0,value:t.debounceMs===void 0?``:String(t.debounceMs/1e3),placeholder:`0`,onChange:e=>r(Qi(a,{...c,debounceMs:ea(e.target.value)}))})]})]})}function ea(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function ta({trigger:t,devices:n,onChange:r}){let{t:i}=Y();return e(p,{children:[e(`label`,{className:`min-w-[15rem] flex-1`,children:[o(Z,{children:i(`automation.triggerEditor.eventCategory`,`Event category`)}),o(G,{value:t.category,onChange:e=>r({kind:`device-event`,category:e.target.value,...t.deviceId===void 0?{}:{deviceId:t.deviceId}}),options:[{value:``,label:i(`automation.triggerEditor.selectAnEvent`,`Select an event…`)},...Ji.map(e=>({value:e,label:e}))]})]}),e(`div`,{className:`min-w-[11rem] flex-1`,children:[o(Z,{children:i(`automation.triggerEditor.fromDevice`,`From device`)}),o(mn,{devices:n,selection:`single`,value:t.deviceId===void 0?[]:[t.deviceId],emptyLabel:i(`automation.triggerEditor.anyDevice`,`Any device`),testId:`trigger-event-device`,onChange:e=>r({kind:`device-event`,category:t.category,...e[0]===void 0?{}:{deviceId:e[0]}})})]})]})}var na=[`single`,`restart`,`queued`,`parallel`,`cooldown`],ra=2,ia=30;function aa(e){return e.runMode??{mode:`single`}}function oa(e,t){let{runMode:n,...r}=e;return t.mode===`single`?r:{...r,runMode:t}}function sa(e){switch(e){case`queued`:return{mode:`queued`,max:ra};case`parallel`:return{mode:`parallel`,max:ra};case`cooldown`:return{mode:`cooldown`,minutes:ia};case`restart`:return{mode:`restart`};default:return{mode:`single`}}}function ca(e){return na.find(t=>t===e)??`single`}function la({value:t,onChange:n}){let{t:r}=Y(),i={single:r(`flow.runMode.single`,`Skip it`),restart:r(`flow.runMode.restart`,`Restart the run`),queued:r(`flow.runMode.queued`,`Queue it`),parallel:r(`flow.runMode.parallel`,`Run at the same time`),cooldown:r(`flow.runMode.cooldown`,`Wait after a run`)},a={single:r(`flow.runMode.singleHint`,`A trigger that arrives during a run is dropped.`),restart:r(`flow.runMode.restartHint`,`The run in progress stops and a new one starts.`),queued:r(`flow.runMode.queuedHint`,`Triggers wait their turn, up to the limit.`),parallel:r(`flow.runMode.parallelHint`,`Runs overlap, up to the limit.`),cooldown:r(`flow.runMode.cooldownHint`,`No new run until this long after the last one began.`)};return e(`div`,{className:`flex flex-wrap items-end gap-3`,"data-testid":`run-mode`,children:[e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`block text-xs text-foreground-subtle`,children:r(`flow.runMode.label`,`When it is already running`)}),o(qt,{widthClass:`w-56`,value:t.mode,options:na.map(e=>({value:e,label:i[e]})),onChange:e=>n(sa(ca(e.target.value)))})]}),(t.mode===`queued`||t.mode===`parallel`)&&e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`block text-xs text-foreground-subtle`,children:r(`flow.runMode.max`,`Up to`)}),o(Kt,{className:`w-20`,"aria-label":r(`flow.runMode.max`,`Up to`),value:t.max,onValue:e=>{e!==null&&n({mode:t.mode,max:Math.round(e)})}})]}),t.mode===`cooldown`&&e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`block text-xs text-foreground-subtle`,children:r(`flow.runMode.minutes`,`Minutes`)}),o(Kt,{className:`w-20`,"aria-label":r(`flow.runMode.minutes`,`Minutes`),value:t.minutes,onValue:e=>{e!==null&&n({mode:`cooldown`,minutes:Math.round(e)})}})]}),o(`p`,{className:`basis-full text-xs text-foreground-subtle`,children:a[t.mode]})]})}u();var ua=`hub`,da=5e3;function fa({existing:t,initialRecipe:n,saving:i,saveError:a,ejecting:s,onSave:l,onEject:u,onCancel:d}){let{t:f}=Y(),[p,m]=c(t?.name??``),[h,g]=c(()=>ui(n)),[_,v]=c(!1),[y,b]=c(null),x=Ue({blockId:t?.id??`none`},{enabled:t!==null,refetchInterval:da}),S=x.data?.traces.find(e=>e.runId===y)??null,C=r(()=>S===null?null:mr(S),[S]),w=r(()=>sr(h.triggers,f),[h.triggers,f]),E=On(),D=ce(h),O=r(()=>pa(h),[h]),k=r(()=>ma(p.trim()===``?`Untitled automation`:p.trim(),h),[p,h]),A=p.trim()===``,j=A||D!==null||O!==null||k.code===null;return e(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]`,"data-testid":`automation-editor`,children:[e(`div`,{className:`space-y-4`,children:[o(`div`,{className:`flex flex-wrap items-center gap-2`,children:o(q,{variant:`info`,children:f(`automation.automationEditor.runsOnTheHub`,`runs on the hub`)})}),e(`label`,{className:`block max-w-md text-sm`,children:[o(`span`,{className:`text-foreground-subtle`,children:f(`automation.automationEditor.name`,`Name`)}),o(K,{className:`mt-1`,value:p,onChange:e=>m(e.target.value),placeholder:f(`automation.automationEditor.whatThisAutomationDoes`,`What this automation does`)})]}),o(En,{step:`when`,title:f(`automation.automationEditor.when`,`When`),trace:C===null?null:C.when,hint:f(`automation.automationEditor.anyOneOfTheseStarts`,`Any one of these starts a run.`),children:o(Yi,{triggers:h.triggers,devices:E,onChange:e=>g($n(h,e))})}),o(En,{step:`if`,title:f(`automation.automationEditor.andOnlyIf`,`And only if`),trace:C===null?null:C.condition,hint:f(`automation.automationEditor.checkedAfterATriggerFires`,`Checked after a trigger fires. Nothing runs unless this is true.`),children:o(Bi,{recipe:h,devices:E,onChange:g})}),o(En,{step:`then`,title:f(`automation.automationEditor.then`,`Then`),trace:C===null?null:C.thenBlock,hint:f(`automation.automationEditor.inThisOrderStoppingAt`,`In this order, stopping at the first failure.`),children:o(nr,{actions:h.actions,devices:E,variables:w,stepTones:C===null?void 0:h.actions.map((e,t)=>hr(C,t)??`idle`),onChange:e=>g(er(h,e))})}),o(En,{step:`mode`,title:f(`flow.runMode.title`,`Overlap`),trace:null,hint:f(`flow.runMode.hint`,`What happens when a trigger arrives mid-run.`),children:o(la,{value:aa(h),onChange:e=>g(oa(h,e))})}),o(Wi,{code:k.code,error:k.error,canEject:t!==null,ejecting:s,onEject:u}),D!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:D}),D===null&&O!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:O}),a!==null&&o(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:a}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(W,{onClick:()=>{k.code!==null&&l({name:p.trim(),code:k.code,enabled:t?.enabled??!0,placement:ua})},disabled:i||j,children:[i&&o(T,{className:`h-4 w-4 animate-spin`}),` `,f(`common.save`)]}),e(W,{variant:`ghost`,onClick:()=>v(!_),disabled:t===null,title:t===null?f(`automation.automationEditor.logsAppearOnceTheAutomation`,`Logs appear once the automation has been saved and started`):f(`automation.automationEditor.showThisAutomationSProcess`,`Show this automation's process logs`),"data-testid":`automation-logs-toggle`,children:[o(N,{className:`h-4 w-4`}),` `,f(`common.logs`),` `,_?`▾`:`▸`]}),o(W,{variant:`ghost`,onClick:d,disabled:i,children:f(`common.close`,`Close`)}),A&&o(q,{variant:`warning`,children:f(`automation.automationEditor.nameRequired`,`Name required`)})]}),_&&t!==null&&e(`div`,{className:`rounded border border-border`,"data-testid":`automation-logs-panel`,children:[o(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:o(X,{i18nKey:`common.logsOf`,values:{id:ae(t.id)},components:{code:o(`code`,{})}})}),o($e,{addonId:ae(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]}),o(`div`,{className:`order-first lg:order-last`,children:o(wn,{traces:t===null?[]:x.data?.traces,selectedId:y,onSelect:b})})]})}function pa(e){let t=F.safeParse(e);if(t.success)return null;let n=t.error.issues[0];return n===void 0?J.t(`helpers.automationEditor.incomplete`):`${n.path.length===0?``:`${n.path.join(`.`)}: `}${n.message}`}function ma(e,t){try{return{code:B({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function ha(e){if(!e.enabled)return{tone:`idle`,label:J.t(`helpers.coreBlockStatus.disabled`),detail:J.t(`helpers.coreBlockStatus.disabledDetail`)};switch(e.status){case`running`:return{tone:`ok`,label:J.t(`helpers.coreBlockStatus.running`),detail:J.t(`helpers.coreBlockStatus.runningDetail`)};case`starting`:return{tone:`pending`,label:J.t(`helpers.coreBlockStatus.starting`),detail:e.lastError??J.t(`helpers.coreBlockStatus.startingDetail`)};case`failed`:return{tone:`error`,label:J.t(`helpers.coreBlockStatus.failed`),detail:e.lastError??J.t(`helpers.coreBlockStatus.failedDetail`)};default:return{tone:`error`,label:J.t(`helpers.coreBlockStatus.notRunning`),detail:e.lastError??J.t(`helpers.coreBlockStatus.notRunningDetail`)}}}function ga(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function _a(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function va(e){let t=e=>{let t=ha(e).tone;return t===`error`?0:t===`pending`?1:t===`ok`?2:3};return[...e].sort((e,n)=>t(e)-t(n)||e.name.localeCompare(n.name))}function ya(e){if(e.length===0)return J.t(`helpers.coreBlockStatus.noBlocks`);let t=e.filter(e=>ha(e).tone===`error`).length,n=e.filter(e=>ha(e).tone===`ok`).length,r=[J.t(`helpers.coreBlockStatus.blocks`,{count:e.length})];return n>0&&r.push(J.t(`helpers.coreBlockStatus.runningCount`,{count:n})),t>0&&r.push(J.t(`helpers.coreBlockStatus.notRunningCount`,{count:t})),r.join(` · `)}function ba({block:t,busy:n,logsOpen:r,unreadable:i,onEdit:a,onToggle:s,onToggleLogs:c,onDelete:l}){let u=D(),{t:d}=Y(),f=ha(t),p=Ae(t.updatedAt,u);return e(`li`,{className:`flex flex-col gap-2 p-3`,children:[e(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[e(`div`,{className:`min-w-0 flex-1`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(`span`,{className:`truncate font-medium`,children:t.name}),o(q,{variant:ga(f.tone),children:f.label}),p!==null&&o(`span`,{className:`text-xs text-foreground-subtle`,children:d(`common.edited`,{when:p})})]}),o(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:f.detail}),i!==null&&o(`p`,{className:`mt-0.5 text-xs text-warning`,children:d(`automation.editor.listUnreadable`,{reason:i})})]}),e(`div`,{className:`flex justify-end gap-1`,children:[o(W,{variant:`ghost`,onClick:e=>{e.stopPropagation(),a()},disabled:i!==null,title:i===null?d(`common.edit`,`Edit`):d(`automation.automationList.thisBlockCannotBeOpened`,`This block cannot be opened visually`),children:o(C,{className:`h-4 w-4`})}),e(ft,{children:[o(at,{children:o(W,{variant:`ghost`,disabled:!0,title:d(`automation.automationList.runActions`,`Run actions`),children:o(y,{className:`h-4 w-4`})})}),o(lt,{children:d(`automation.automationList.runningAnAutomationByHand`,`Running an automation by hand needs the automation-control authority, which is not wired up yet. There is deliberately no second way to execute one.`)})]}),o(W,{variant:`ghost`,onClick:e=>{e.stopPropagation(),c()},title:d(`automation.automationList.logs`,`Logs`),children:o(N,{className:`h-4 w-4`})}),o(W,{variant:`ghost`,onClick:e=>{e.stopPropagation(),s(!t.enabled)},disabled:n,title:t.enabled?d(`common.disable`,`Disable`):d(`common.enable`,`Enable`),children:t.enabled?d(`common.disable`,`Disable`):d(`common.enable`,`Enable`)}),o(W,{variant:`ghost`,onClick:e=>{e.stopPropagation(),l()},title:d(`common.delete`,`Delete`),children:o(v,{className:`h-4 w-4`})})]})]}),r&&e(`div`,{className:`rounded border border-border`,children:[o(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:o(X,{i18nKey:`common.logsOf`,values:{id:ae(t.id)},components:{code:o(`code`,{})}})}),o($e,{addonId:ae(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function xa({onCreate:t}){let{t:n}=Y();return o(Je,{children:e(`div`,{className:`space-y-2 p-4`,children:[o(`p`,{className:`text-sm text-foreground`,children:n(`automation.automationList.noAutomationsYet`,`No automations yet.`)}),o(`p`,{className:`max-w-2xl text-xs text-foreground-subtle`,children:n(`automation.automationList.anAutomationIsATrigger`,`An automation is a trigger, a set of conditions and a list of actions. It compiles to an ordinary block and runs in its own supervised process — there is no separate engine, so anything that goes wrong shows up here with a reason.`)}),o(W,{onClick:t,children:n(`automation.automationList.newAutomation`,`New automation`)})]})})}u();var Sa=[`coreBlocks`,`list`],Ca=5e3;function wa(e){return e instanceof Error?e.message:String(e)}function Ta({onOpenScripts:t,initialBlockId:i,onBlockIdChange:a,createRequested:u=!1,onCreateConsumed:d}){let{t:p}=Y(),m=w(),{state:h,openNew:g,openEdit:_,close:v}=tt({editKey:`block`,newKey:`new`}),[y,b]=c(null),x=k(),[S,C]=c(null),T=n(null),E=h.mode!==`closed`;s(()=>{u&&(b(null),g(),a?.(null),d?.())},[u,d,a,g]);let D=l({queryKey:Sa,refetchInterval:Ca,queryFn:async()=>(await m.trpcClient.coreBlocks.list.query({})).blocks}),O=()=>{D.refetch()},j=D.data;s(()=>{i===void 0||T.current===i||j?.find(e=>e.id===i&&Vt(e.code))!==void 0&&(T.current=i,_(i),a?.(i))},[i,j,_,a]);let M=f({mutationFn:e=>m.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{b(e.block),_(e.block.id),a?.(e.block.id),O()}}),N=f({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{b(e.block),_(e.block.id),a?.(e.block.id),O()}}),P=f({mutationFn:e=>m.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:O}),F=f({mutationFn:e=>m.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:O}),I=f({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:Wt(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:e=>{v(),b(null),O(),t(e.block.id)}}),L=D.data,R=va((L??[]).filter(e=>Vt(e.code))),ee=L!==void 0&&R.length===0,z=h.mode===`edit`?R.find(e=>e.id===h.id)??(y!==null&&y.id===h.id?y:null):null,B=h.mode===`new`||z===null?null:_a(R,z),te=B===null?null:Ut(B.code),ne=M.error===null?N.error===null?I.error===null?null:wa(I.error):wa(N.error):wa(M.error),re=r(()=>[{key:`row`,header:p(`build.automationsTab.automation`,`Automation`),nowrap:!1,notSortableReason:`Composite status row`,render:e=>{let t=Ut(e.code);return o(`ul`,{className:`list-none`,children:o(ba,{block:e,busy:F.isPending||P.isPending,logsOpen:S===e.id,unreadable:t.ok?null:t.reason,onEdit:()=>{b(e),_(e.id),a?.(e.id)},onToggle:t=>F.mutate({blockId:e.id,enabled:t}),onToggleLogs:()=>C(S===e.id?null:e.id),onDelete:()=>{x({title:p(`automation.automationList.deleteThisAutomation`,`Delete this automation?`),message:p(`automation.automationList.deleteMessage`,`{{name}} will be deleted. This cannot be undone.`,{name:e.name}),confirmLabel:p(`common.delete`,`Delete`),variant:`danger`}).then(t=>{t&&P.mutate(e.id)})}})})},sortValue:e=>e.name}],[x,S,a,_,P,F,p]);return E?e(`div`,{className:`space-y-3`,"data-testid":`automation-editor-panel`,children:[e(`h3`,{className:`flex items-center gap-2 text-sm font-semibold`,children:[o(A,{className:`h-4 w-4 text-foreground-muted`}),B===null?p(`build.automationsTab.newAutomation`,`New automation`):p(`build.automationsTab.edit`,`Edit {{name}}`,{name:B.name})]}),o(fa,{existing:B,initialRecipe:te!==null&&te.ok?te.recipe:Wn,saving:M.isPending||N.isPending,saveError:ne,ejecting:I.isPending,onSave:e=>{B===null?M.mutate(e):N.mutate({blockId:B.id,block:e})},onEject:()=>{B!==null&&I.mutate(B)},onCancel:()=>{M.reset(),N.reset(),I.reset(),b(null),v(),a?.(null)}},B?.id??`new`),P.error!=null&&o(U,{message:wa(P.error)})]}):e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:L===void 0?``:ya(R)}),D.error!=null&&o(U,{title:p(`build.automationsTab.couldNotReadTheAutomations`,`Could not read the automations`),message:wa(D.error),onRetry:O}),ee?o(xa,{onCreate:()=>{b(null),g(),a?.(null)}}):o(Be,{columns:re,rows:R,rowKey:e=>e.id,pageSize:25,maxBodyHeight:be,emptyMessage:L===void 0?p(`build.automationsTab.loadingAutomations`,`Loading automations…`):p(`build.automationsTab.noAutomationsYet`,`No automations yet.`),onRowClick:e=>{b(e),_(e.id),a?.(e.id)}}),P.error!=null&&o(U,{message:wa(P.error)}),F.error!=null&&o(U,{message:wa(F.error)})]})}u();function Ea({mode:e,onTitle:t}){return o(e===`helper`?Da:Oa,{onTitle:t})}function Da({onTitle:e}){let{t}=Y(),n=St(),r=we(),i=Oe(),a=Ne({addonId:`composer`}),[l,u]=c(null),[d,f]=c(!1),p=Aa(l,t);return s(()=>{d||e(p)},[e,p,d]),d?o(Oa,{onTitle:e}):o(`div`,{className:`flex flex-col gap-3`,"data-testid":`composition-create-form`,children:o(It,{onFreeComposition:()=>f(!0),purpose:`create`,initial:null,start:`template`,saving:r.isPending,onDraftChange:u,onSave:async(e,o)=>{let s=null,c=await Ft(e,async(e,c)=>{let{block:l}=await r.mutateAsync({block:{...c===``?{}:{name:c},enabled:!0,composition:e}}),u=await ja(l.id,async()=>(await a.refetch()).data??a.data);if(u===null)throw Error(t(`helper.devicePending`));s=u,c!==``&&await i.mutateAsync({deviceId:u,name:c}),o===`open`&&n(Ct(u),{replace:!0})}),l=s;return c.length>0||l===null?{kind:`refused`,lines:Ma(c,t)}:{kind:`saved`,deviceId:l}}})})}function Oa({onTitle:t}){let{t:n}=Y(),r=D(),i=St(),a=we(),l=Oe(),u=Ne({addonId:`composer`}),[d,f]=c(re.Sensor),[p,m]=c(fe.TemperatureSensor),[h,g]=c(``),[_,v]=c(null),y=Nt({type:d,role:p});return s(()=>{t(n(`helper.newComposition`))},[t,n]),e(`div`,{className:`flex flex-col gap-3`,"data-testid":`blank-composition-form`,children:[e(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`compositionEditor.targetType`),o(G,{value:d,onChange:e=>{let t=Object.values(re).find(t=>t===e.target.value);t!==void 0&&f(t)},options:Object.values(re).map(e=>({value:e,label:Ie(e,r).label}))})]}),e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`customize.identity.role`),o(G,{value:p??``,onChange:e=>m(Object.values(fe).find(t=>t===e.target.value)??null),options:[{value:``,label:n(`customize.identity.noRole`)},...Object.values(fe).map(e=>({value:e,label:Me(e,r).label}))]})]}),e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`compositionEditor.name`),o(K,{"aria-label":n(`compositionEditor.name`),value:h,onChange:e=>g(e.target.value)})]})]}),_!==null&&o(`p`,{role:`alert`,className:`text-xs text-danger`,children:_}),o(W,{disabled:y===null||a.isPending,onClick:()=>{y!==null&&ka({composition:y,name:h,create:e=>a.mutateAsync({block:e}),rename:(e,t)=>l.mutateAsync({deviceId:e,name:t}),readFleet:async()=>(await u.refetch()).data??u.data,onError:e=>v(e),onOpen:e=>i(Tt(e),{replace:!0}),pending:n(`helper.devicePending`)})},children:n(`compositionEditor.save`)})]})}async function ka(e){e.onError(null);try{let t=e.name.trim(),{block:n}=await e.create({...t===``?{}:{name:t},enabled:!0,composition:e.composition}),r=await ja(n.id,e.readFleet);if(r===null){e.onError(e.pending);return}t!==``&&await e.rename(r,t),e.onOpen(r)}catch(t){e.onError(t instanceof Error?t.message:String(t))}}function Aa(e,t){if(e===null)return t(`helper.newComposed`);if(e.kind===`statistic`)return t(`helper.newTitle.statistic`);if(e.kind===`integral`)return t(`helper.newTitle.integral`);if(e.kind===`arithmetic`)return t(`helper.newTitle.${e.op}`);if(e.kind===`threshold`||e.kind===`expression`||e.kind===`derivative`)return t(`helper.newTitle.${e.kind}`);if(e.templateId===`appliance`&&e.appliance!==null)return t(`helper.newTitle.${e.appliance}`);if(e.templateId===`appliance`)return t(`helper.newComposed`);let n=pe(e.templateId);return t(n===null?`helper.newComposed`:`helper.newTitle.${n.id}`)}async function ja(e,t){let n=`${L}${e}`;return(await t())?.find(e=>e.stableId===n)?.id??null}function Ma(e,t){return e.length>0?e:Lt(t(`helper.devicePending`))}function Na(e){let t=e.helper;if(t===void 0)return{section:`advanced`,kind:null};switch(t.kind){case`group`:return{section:`group`,kind:t.templateId};case`appliance`:return{section:`group`,kind:`appliance`};case`arithmetic`:return{section:`calculation`,kind:t.op};case`expression`:return{section:`advanced`,kind:`expression`};default:return{section:`calculation`,kind:t.kind}}}function Pa(e){return{state:`answered`,byRef:new Map(e.map(e=>[z(e),e]))}}function Fa(e,t){if(e.state!==`unanswered`)return e.byRef.get(z(t))??null}function Ia(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function La(e){return R(e).map(e=>e.source)}function Ra(e){let t=e.block.source?.kind===`composition`?e.block.source.composition:null;if(t===null)return[];let n=[];for(let e of t.features){if(e.kind===`passthrough`){n.push(e.source);continue}for(let t of Object.values(e.fields))n.push(...La(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...La(e))}let r=new Set;return n.filter(e=>{let t=z(e);return r.has(t)?!1:(r.add(t),!0)})}function za(e){let t=e.fields.filter(e=>e.state===`unavailable`),n=e.fields.filter(e=>e.state===`stale`);if(t.length===0&&n.length===0)return{tone:`ok`,label:J.t(`helpers.compositionRows.running`),reason:null};let r=[...t.length>0?[J.t(`helpers.compositionRows.fieldsUnavailable`,{count:t.length})]:[],...n.length>0?[J.t(`helpers.compositionRows.fieldsStale`,{count:n.length})]:[]].join(`, `),i=t[0]??n[0],a=i===void 0?``:` — ${i.cap}.${i.path}: ${i.reason??J.t(`helpers.compositionRows.noReason`)}`;return{tone:`pending`,label:J.t(`helpers.compositionRows.running`),reason:`${r}${a}`}}function Ba(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return za(e);case`degraded`:return{tone:`pending`,label:J.t(`helpers.compositionRows.degraded`),reason:n??J.t(`helpers.compositionRows.degradedReason`)};case`starting`:return{tone:`pending`,label:J.t(`helpers.compositionRows.starting`),reason:n};case`failed`:return{tone:`error`,label:J.t(`helpers.compositionRows.failed`),reason:n??J.t(`helpers.compositionRows.failedReason`)};default:return{tone:`error`,label:J.t(`helpers.compositionRows.notRunning`),reason:n??J.t(`helpers.compositionRows.notRunningReason`)}}}function Va(e){let{block:t,state:n}=e;if(!t.enabled)return{tone:`idle`,label:J.t(`helpers.compositionRows.off`),reason:null};if(n.kind===`unreachable`)return{tone:`pending`,label:J.t(`helpers.compositionRows.unknown`),reason:J.t(`helpers.compositionRows.unreachable`,{error:n.error})};if(n.state!==null)return Ba(n.state,t.lastError);let r=t.lastError===void 0?t.status:`${t.status}: ${t.lastError}`;return{tone:`pending`,label:J.t(`helpers.compositionRows.notReported`),reason:J.t(`helpers.compositionRows.noRecord`,{stored:r})}}function Ha(e){return z(e)}function Ua(e,t){let n=Fa(t,e);return{key:z(e),label:n?n.name:Ha(e),presence:Ia(n),deviceId:n?n.id:null}}function Wa(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function Ga(e,t){let n=e.block.source?.kind===`composition`?e.block.source.composition:null;if(n===null)return null;let r=n.target,i=r.kind===`existing`?r.device:I(e.block.id),a=z(i),o=Ra(e).filter(e=>z(e)!==a).map(e=>Ua(e,t)),s=n.features.map(e=>e.enabled===!1?J.t(`helpers.compositionRows.featureOff`,{cap:e.cap}):e.cap),c=Fa(t,i),l=Wa(e),u=Va(e);if(r.kind===`new`)return{blockId:e.block.id,kind:`composed`,name:e.block.name,namePresence:`present`,type:r.role===void 0?r.type:`${r.type} · ${r.role}`,origin:Na(n),features:s,state:u,sources:o,reportedDeviceId:l};let d=Ia(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:Ha(r.device),namePresence:d,type:c?c.type:null,origin:Na(n),features:s,state:u,sources:o,reportedDeviceId:l}}function Ka(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function qa(e,t){return Ka(e)-Ka(t)||e.name.localeCompare(t.name)}function Ja(e,t){let n=e.flatMap(e=>{let n=Ga(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(qa),customizations:n.filter(e=>e.kind===`customization`).toSorted(qa)}}u();var Ya=1e4;function Xa(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function Za(){let e=wt();return e.data===void 0?{state:`unanswered`,reason:e.error==null?J.t(`build.customDeviceTab.deviceListPending`):J.t(`build.customDeviceTab.deviceListUnreadable`,{error:Xa(e.error)})}:Pa(e.data)}function Qa(e,t){return e===`blank`?`blank`:e===`helper`||e===`1`||t?`helper`:null}function $a({createRequested:t=!1,onCreateConsumed:n}={}){let{t:r}=Y(),[i,a]=Dt(),s=Ve({},{refetchInterval:Ya}),l=Za(),u=tt({editKey:`block`,newKey:`new`}),d=u.state.mode===`edit`?u.state.id:null,f=d===null?Qa(i.get(`new`),t):null,m=f!==null,[h,g]=c(``),_=k(),v=Ee(),y=()=>{u.close(),a(()=>{let e=new URLSearchParams(window.location.search);return e.delete(`new`),e.delete(`block`),e},{replace:!0}),n?.()},b=s.data;return e(p,{children:[to(b,s.error,()=>void s.refetch(),l,{onEditComposed:e=>u.openEdit(e),deleting:v.isPending,onDelete:e=>{_({title:r(`build.customDeviceTab.deleteThisComposedDevice`,`Delete this composed device?`),message:r(`build.customDeviceTab.deleteMessage`,`{{name}} will be deleted. This cannot be undone.`,{name:e.name}),confirmLabel:r(`common.delete`,`Delete`),variant:`danger`}).then(t=>{t&&v.mutate({blockId:e.blockId},{onSuccess:()=>void s.refetch()})})}}),o(dt,{open:m||d!==null,onClose:y,title:m?h||r(f===`blank`?`helper.newComposition`:`helper.newComposed`):r(`build.customDeviceTab.editComposedDevice`,`Edit composed device`),icon:me,width:`xl`,testId:`composed-device-editor`,children:m&&f!==null?o(Ea,{mode:f,onTitle:g},f):d===null?null:o(Rt,{blockId:d})}),v.error!=null&&o(U,{message:Xa(v.error)})]})}function eo(t){return o(Je,{children:e(`div`,{className:`space-y-1 p-4`,children:[o(`p`,{className:`text-sm text-warning`,children:J.t(`build.customDeviceTab.theCompositionStoreHasNot`,`The composition store has not been read yet.`)}),e(`p`,{className:`text-xs text-foreground-subtle`,children:[J.t(`build.customDeviceTab.thisIsNotTheSame`,`This is not the same as having none — the list appears once the hub has read it (`),t,`).`]})]})})}function to(e,t,n,r,i){if(t!=null&&e===void 0)return o(U,{title:J.t(`build.customDeviceTab.couldNotReadTheCompositions`,`Could not read the compositions`),message:Xa(t),onRetry:n});if(e===void 0)return o(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:J.t(`build.customDeviceTab.loadingCompositions`,`Loading compositions…`)});if(e.state===`not-loaded`)return eo(e.reason);let a=t==null?null:Xa(t);return o(no,{lists:Ja(e.views,r),fleet:r,refreshError:a,handlers:i})}function no({lists:t,fleet:n,refreshError:r,handlers:i}){let{t:a}=Y();return e(`div`,{className:`space-y-4`,children:[r!==null&&e(`p`,{className:`text-xs text-warning`,children:[a(`build.customDeviceTab.showingTheLastAnswerThe`,`Showing the last answer — the latest refresh failed:`),` `,r]}),n.state===`unanswered`&&e(`p`,{className:`text-xs text-warning`,children:[a(`build.customDeviceTab.deviceNamesAreShownAs`,`Device names are shown as references:`),` `,n.reason,`. No source is marked missing until it has.`]}),o(ro,{title:a(`build.customDeviceTab.composedDevices`,`Composed devices`),hint:a(`build.customDeviceTab.aNewDeviceWhoseState`,`A new device whose state is derived from other devices.`),rows:t.composed,nameHeader:`Name`,emptyMessage:a(`build.customDeviceTab.noComposedDevices`,`No composed devices.`),kind:`composed`,handlers:i}),o(ro,{title:a(`build.customDeviceTab.customizations`,`Customizations`),hint:a(`build.customDeviceTab.fieldsAddedToOrReplaced`,`Fields added to or replaced on an existing device — one per device, edited from the device.`),rows:t.customizations,nameHeader:`Device`,emptyMessage:a(`build.customDeviceTab.noCustomizations`,`No customizations.`),kind:`customization`,handlers:i})]})}function ro({title:t,hint:n,rows:r,nameHeader:i,emptyMessage:a,kind:s,handlers:c}){let{t:l}=Y();return e(`section`,{className:`space-y-2`,"aria-label":t,children:[e(`div`,{children:[o(`h3`,{className:`font-medium`,children:t}),o(`p`,{className:`text-xs text-foreground-subtle`,children:n})]}),o(Be,{columns:io(i,s,c,l),rows:r,rowKey:e=>e.blockId,pageSize:25,maxBodyHeight:be,emptyMessage:a,onRowClick:s===`composed`?e=>c.onEditComposed(e.blockId):void 0})]})}function io(t,n,r,i){let a=[{key:`name`,header:t,sortValue:e=>e.name.toLowerCase(),render:e=>o(oo,{row:e})},{key:`type`,header:J.t(`build.customDeviceTab.type`,`Type`),sortValue:e=>e.type,render:e=>o(`span`,{className:`text-xs text-foreground-subtle`,children:e.type??J.t(`common.unknownWord`)})},...n===`composed`?[{key:`origin`,header:J.t(`build.customDeviceTab.builtAs`,`Built as`),sortValue:e=>ao(e.origin,i),render:e=>o(q,{variant:`default`,"data-testid":`composed-origin-badge`,children:ao(e.origin,i)})}]:[],{key:`state`,header:J.t(`build.customDeviceTab.state`,`State`),nowrap:!1,notSortableReason:`A state and its reason are read together, not ordered.`,render:t=>e(`div`,{className:`space-y-0.5`,children:[o(q,{variant:ga(t.state.tone),children:t.state.label}),t.state.reason!==null&&o(`p`,{className:`max-w-md whitespace-normal text-xs text-foreground-subtle`,children:t.state.reason})]})},{key:`sources`,header:J.t(`build.customDeviceTab.sources`,`Sources`),nowrap:!1,notSortableReason:`A list of devices has no single order.`,render:e=>o(co,{sources:e.sources})}];return n===`composed`&&a.push({key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,nowrap:!0,render:t=>e(`div`,{className:`flex justify-end gap-1`,children:[o(W,{variant:`ghost`,title:i(`common.edit`,`Edit`),onClick:e=>{e.stopPropagation(),r.onEditComposed(t.blockId)},children:i(`common.edit`,`Edit`)}),o(W,{variant:`ghost`,title:i(`common.delete`,`Delete`),disabled:r.deleting,"aria-label":i(`common.delete`,`Delete`),onClick:e=>{e.stopPropagation(),r.onDelete(t)},children:o(v,{className:`h-4 w-4`})})]})}),a}function ao(e,t){let n=e.kind===null?null:t(`helper.template.${e.kind}`);return e.section===`group`?t(`helper.badge.group`,{kind:n}):e.section===`calculation`?t(`helper.badge.calculation`,{kind:n}):n===null?t(`helper.badge.advanced`):t(`helper.badge.advancedKind`,{kind:n})}function oo({row:t}){let{t:n}=Y();return e(`div`,{className:`space-y-0.5`,children:[o(so,{row:t}),t.namePresence===`missing`&&o(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:n(`build.customDeviceTab.deviceMissing`,`device missing`)}),o(`p`,{className:`text-[11px] text-foreground-subtle`,children:t.features.join(`, `)})]})}function so({row:e}){let{t}=Y(),n=De(e.reportedDeviceId??0,`compact`,e.name),r=e.reportedDeviceId===null?e.name:n;return e.reportedDeviceId===null?e.kind===`composed`?o(`span`,{className:`text-xs font-medium text-foreground`,children:e.name}):o(`span`,{className:`text-xs text-foreground-subtle`,children:t(`build.customDeviceTab.notReported`,{name:r})}):o(Et,{to:e.kind===`composed`?Ct(e.reportedDeviceId):Tt(e.reportedDeviceId),className:`text-xs font-medium text-foreground hover:underline`,onClick:e=>e.stopPropagation(),children:r})}function co({sources:t}){let{t:n}=Y();return t.length===0?o(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):o(`ul`,{className:`space-y-0.5`,children:t.map(t=>e(`li`,{className:`text-xs`,children:[t.deviceId===null?o(`span`,{className:t.presence===`missing`?`text-danger`:`text-foreground`,children:t.label}):o(Et,{to:`/devices/${String(t.deviceId)}`,className:`hover:underline`,children:t.label}),t.presence===`missing`&&o(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:n(`common.missing`)})]},t.key))})}function lo(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function uo(e){if(Array.isArray(e))return e}function fo(e,t,n){return(t=xo(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function po(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t!==0)for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function mo(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
@@ -1 +1 @@
1
- import{C as e,K as t,R as n,S as r,Y as i,et as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Ei as s,Ti as c}from"./player-overlays-CzZYPO2s.js";import{fr as l,pr as u}from"./client-BRyxs6lT.js";import{h as d}from"./video-O02NyJP7.js";import{Ma as f,Na as p,Pa as m,Yr as h,_r as g,dr as _,fr as v,gr as y,hr as b,ja as x,pr as S}from"./src-DytYtgEw.js";import{t as C}from"./i18n-DH8y-VcL.js";import{t as w}from"./useTranslation-BJr-n0es.js";import{mr as T,pr as E}from"./index-BCZXKpVN.js";import{t as D}from"./AdminPage-CoK_jJGS.js";a();var O=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function k(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function A(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function j(e){let t=e.getDay();return k(A(e,t===0?-6:1-t))}function M(e,t){if(t===`day`){let t=k(e);return{startMs:t.getTime(),endMs:A(t,1).getTime()}}if(t===`week`){let t=j(e);return{startMs:t.getTime(),endMs:A(t,7).getTime()}}let n=new Date(e.getFullYear(),e.getMonth(),1),r=new Date(e.getFullYear(),e.getMonth()+1,0),i=j(n),a=A(j(r),7);return{startMs:i.getTime(),endMs:a.getTime()}}function N(e,t){if(t===`day`)return e.toLocaleDateString(void 0,{weekday:`long`,year:`numeric`,month:`long`,day:`numeric`});if(t===`week`){let t=j(e),n=A(t,6),r={month:`short`,day:`numeric`};return`${t.toLocaleDateString(void 0,r)} – ${n.toLocaleDateString(void 0,{...r,year:`numeric`})}`}return e.toLocaleDateString(void 0,{month:`long`,year:`numeric`})}function P(e,t,n){return t===`day`?A(e,n):t===`week`?A(e,n*7):new Date(e.getFullYear(),e.getMonth()+n,1)}function F(e,t){if(t===void 0)return e;let n=t.calendars[e.id];return n===void 0?e:{...e,visible:n.visible??e.visible,color:n.color??e.defaultColor}}function I(e){return e.providerAddonId!==void 0&&e.providerAddonId.length>0?e.providerAddonId:e.source===`ha`?`Home Assistant`:e.source}function L(e){if(e.allDay===!0)return C.t(`systemPage.calendars.allDay`);let t=new Date(e.startMs),n=new Date(e.endMs),r={hour:`2-digit`,minute:`2-digit`};return`${t.toLocaleTimeString([],r)} – ${n.toLocaleTimeString([],r)}`}function R(e){let t=l(e),n=new Date(t.startMs),r=new Date(t.endMs),i={weekday:`short`,year:`numeric`,month:`short`,day:`numeric`};if(e.allDay===!0){let e=k(n),t=A(k(r),-1);return H(e,t)?C.t(`systemPage.calendars.dayAllDay`,{date:n.toLocaleDateString(void 0,i)}):C.t(`systemPage.calendars.rangeAllDay`,{from:n.toLocaleDateString(void 0,i),to:t.toLocaleDateString(void 0,i)})}let a={hour:`2-digit`,minute:`2-digit`};return H(n,r)?`${n.toLocaleDateString(void 0,i)} · ${n.toLocaleTimeString([],a)} – ${r.toLocaleTimeString([],a)}`:`${n.toLocaleString(void 0,{...i,...a})} – ${r.toLocaleString(void 0,{...i,...a})}`}function z({label:t,children:n}){return e(`div`,{className:`grid grid-cols-[7rem_minmax(0,1fr)] gap-x-3 gap-y-1 text-sm`,children:[r(`dt`,{className:`text-foreground-subtle`,children:t}),r(`dd`,{className:`min-w-0 break-words text-foreground`,children:n})]})}function B({ev:t,calendarName:n,color:i,onClose:a}){let{t:o}=w();return r(_,{open:!0,onOpenChange:e=>!e&&a(),children:e(S,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`calendars-event-detail`,children:[r(y,{children:e(`div`,{className:`flex min-w-0 items-start gap-2.5`,children:[r(`span`,{className:`mt-1.5 h-3 w-3 shrink-0 rounded-full`,style:{backgroundColor:i},"aria-hidden":!0}),r(g,{className:`min-w-0 break-words`,children:t.title})]})}),r(v,{children:e(`dl`,{className:`space-y-3`,children:[r(z,{label:o(`systemPage.calendars.when`,`When`),children:R(t)}),r(z,{label:o(`systemPage.calendars.calendar`,`Calendar`),children:n}),t.location!==void 0&&t.location.length>0?r(z,{label:o(`systemPage.calendars.location`,`Location`),children:t.location}):null,t.description!==void 0&&t.description.length>0?r(z,{label:o(`systemPage.calendars.description`,`Description`),children:r(`span`,{className:`whitespace-pre-wrap`,children:t.description})}):null]})}),r(b,{children:r(h,{type:`button`,size:`sm`,variant:`secondary`,onClick:a,children:o(`common.close`,`Close`)})})]})})}function V(e,t){return e.filter(e=>u(e,t))}function H(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function U({mode:e,onChange:t}){let{t:n}=w(),i=[{id:`month`,label:n(`systemPage.calendars.month`,`Month`)},{id:`week`,label:n(`systemPage.calendars.week`,`Week`)},{id:`day`,label:n(`systemPage.calendars.day`,`Day`)}];return r(`div`,{className:`inline-flex rounded-lg border border-border bg-surface p-0.5`,role:`group`,"aria-label":n(`systemPage.calendars.calendarView`,`Calendar view`),children:i.map(n=>r(`button`,{type:`button`,className:e===n.id?`rounded-md bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground`:`rounded-md px-2.5 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground`,"aria-pressed":e===n.id,onClick:()=>t(n.id),"data-testid":`calendars-view-${n.id}`,children:n.label},n.id))})}function W({calendars:t,onToggleVisible:n,onColorChange:i,busy:a}){let{t:o}=w();return e(`aside`,{className:`w-full shrink-0 space-y-2 lg:w-56 xl:w-64`,"data-testid":`calendars-legend`,children:[r(`h2`,{className:`text-xs font-medium text-foreground-subtle`,children:o(`systemPage.calendars.calendars`,`Calendars`)}),r(`ul`,{className:`space-y-1`,children:t.map(t=>e(`li`,{className:`flex items-start gap-2 rounded-md px-1.5 py-1.5 hover:bg-surface`,children:[r(`input`,{type:`checkbox`,className:`mt-1 h-3.5 w-3.5 shrink-0 accent-primary`,checked:t.visible,disabled:a,onChange:e=>n(t.id,e.target.checked),"aria-label":o(`systemPage.calendars.show`,`Show {{name}}`,{name:t.name}),"data-testid":`calendars-visible-${t.id}`}),r(`input`,{type:`color`,className:`mt-0.5 h-6 w-6 shrink-0 cursor-pointer rounded border border-border bg-transparent p-0`,value:t.color,disabled:a,onChange:e=>i(t.id,e.target.value.toUpperCase()),"aria-label":o(`systemPage.calendars.colourFor`,`Colour for {{name}}`,{name:t.name}),"data-testid":`calendars-color-${t.id}`}),e(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`truncate text-sm font-medium ${t.visible?`text-foreground`:`text-foreground-subtle`}`,children:t.name}),e(`div`,{className:`truncate text-[11px] text-foreground-subtle`,children:[I(t),t.enabled?``:` · ${o(`systemPage.calendars.unavailableAtSource`)}`]})]})]},t.id))})]})}function G({ev:t,color:n,compact:i,onSelect:a}){return r(`button`,{type:`button`,className:i?`block w-full truncate rounded px-1 py-0.5 text-left text-[10px] leading-tight text-white hover:brightness-110`:`block w-full rounded-md px-2 py-1.5 text-left text-xs text-white hover:brightness-110`,style:{backgroundColor:n},title:t.title,onClick:()=>a(t),"data-testid":`calendars-event-${t.id}`,children:i?t.title:e(o,{children:[r(`div`,{className:`font-medium`,children:t.title}),r(`div`,{className:`opacity-90`,children:L(t)})]})})}function K({anchor:t,events:n,colorById:i,today:a,onSelectEvent:o}){let{t:s}=w(),{startMs:c,endMs:l}=M(t,`month`),u=[];for(let e=new Date(c);e.getTime()<l;e=A(e,1))u.push(e);let d=t.getMonth();return e(`div`,{"data-testid":`calendars-month`,children:[r(`div`,{className:`mb-1 grid grid-cols-7 gap-px`,children:O.map(e=>r(`div`,{className:`px-1 py-1 text-center text-[11px] font-medium text-foreground-subtle`,children:e},e))}),r(`div`,{className:`grid grid-cols-7 gap-px overflow-hidden rounded-lg border border-border bg-border`,children:u.map(t=>{let c=k(t).getTime(),l=V(n,c),u=t.getMonth()!==d,f=H(t,a);return e(`div`,{className:`min-h-[5.5rem] bg-background p-1 ${u?`opacity-45`:``}`,children:[r(`div`,{className:f?`mb-1 inline-flex h-5 w-5 items-center justify-center rounded-full bg-primary text-[11px] font-semibold text-primary-foreground`:`mb-1 text-[11px] font-medium text-foreground-subtle`,children:t.getDate()}),e(`div`,{className:`space-y-0.5`,children:[l.slice(0,3).map(e=>r(G,{ev:e,color:i.get(e.calendarId)??`#64748B`,compact:!0,onSelect:o},e.id)),l.length>3?r(`div`,{className:`text-[10px] text-foreground-subtle`,children:s(`common.moreCount`,{count:l.length-3})}):null]})]},c)})})]})}function q({anchor:t,events:n,colorById:i,today:a,onSelectEvent:o}){let s=j(t);return r(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-7 sm:gap-px sm:overflow-hidden sm:rounded-lg sm:border sm:border-border sm:bg-border`,"data-testid":`calendars-week`,children:Array.from({length:7},(e,t)=>A(s,t)).map(t=>{let s=k(t).getTime(),c=V(n,s);return e(`div`,{className:`min-h-[8rem] bg-background p-2 sm:min-h-[12rem]`,children:[r(`div`,{className:H(t,a)?`mb-2 text-xs font-semibold text-primary`:`mb-2 text-xs font-medium text-foreground-subtle`,children:t.toLocaleDateString(void 0,{weekday:`short`,day:`numeric`})}),r(`div`,{className:`space-y-1`,children:c.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):c.map(e=>r(G,{ev:e,color:i.get(e.calendarId)??`#64748B`,onSelect:o},e.id))})]},s)})})}function J({anchor:t,events:n,colorById:i,calName:a,onSelectEvent:o}){let{t:s}=w(),c=V(n,k(t).getTime());return c.length===0?r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-day-empty`,children:s(`systemPage.calendars.noEventsOnThisDay`,`No events on this day.`)}):r(`ul`,{className:`divide-y divide-border rounded-lg border border-border`,"data-testid":`calendars-day`,children:c.map(t=>r(`li`,{children:e(`button`,{type:`button`,className:`flex w-full items-start gap-3 px-3 py-3 text-left hover:bg-surface`,onClick:()=>o(t),"data-testid":`calendars-event-${t.id}`,children:[r(`span`,{className:`mt-1 h-2.5 w-2.5 shrink-0 rounded-full`,style:{backgroundColor:i.get(t.calendarId)??`#64748B`}}),e(`div`,{className:`min-w-0`,children:[r(`div`,{className:`font-medium text-sm text-foreground`,children:t.title}),e(`div`,{className:`text-xs text-foreground-subtle`,children:[L(t),` · `,a.get(t.calendarId)??t.calendarId]}),t.location!==void 0&&t.location.length>0?r(`div`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:t.location}):null]})]})},t.id))})}function Y(){let{t:a}=w(),o=f(),l=x({}),u=m(),[h,g]=i(`month`),[_,v]=i(()=>k(new Date)),[y,b]=i(null),S=t(()=>k(new Date),[]),C=o.isSuccess,O=l.isSuccess&&l.data!==void 0?l.data:void 0,A=t(()=>!C||o.data===void 0?[]:o.data.map(e=>F(e,O)),[C,o.data,O]),j=t(()=>A.filter(e=>e.visible),[A]),I=t(()=>j.map(e=>e.id),[j]),L=t(()=>M(_,h),[_,h]),R=p({startMs:L.startMs,endMs:L.endMs,calendarIds:[...I]},{enabled:C&&I.length>0}),z=R.data??[],V=t(()=>{let e=new Map;for(let t of A)e.set(t.id,t.color);return e},[A]),H=t(()=>{let e=new Map;for(let t of A)e.set(t.id,t.name);return e},[A]),G=n((e,t)=>{u.mutateAsync({calendarId:e,visible:t}).then(()=>l.refetch())},[l,u]),Y=n((e,t)=>{/^#[0-9A-Fa-f]{6}$/.test(t)&&u.mutateAsync({calendarId:e,color:t}).then(()=>l.refetch())},[l,u]),X=n(()=>v(k(new Date)),[]),Z=n(()=>v(e=>P(e,h,-1)),[h]),ee=n(()=>v(e=>P(e,h,1)),[h]),Q=`inline-flex h-8 w-8 items-center justify-center rounded-lg border border-border bg-surface text-foreground hover:bg-primary/5 disabled:opacity-50`,$;return $=o.isPending?r(`p`,{className:`text-sm text-foreground-subtle`,children:a(`systemPage.calendars.loadingCalendars`,`Loading calendars…`)}):o.isError?e(`p`,{className:`text-sm text-destructive`,children:[a(`systemPage.calendars.couldNotListCalendars`,`Could not list calendars:`),` `,o.error.message]}):A.length===0?r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-sources`,children:r(E,{i18nKey:`systemPage.calendars.emptySources`,components:{link:r(T,{to:`/system/integrations?tab=calendars`,className:`text-accent underline-offset-2 hover:underline`})}})}):I.length===0?e(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[r(W,{calendars:A,onToggleVisible:G,onColorChange:Y,busy:u.isPending}),r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-hidden`,children:a(`systemPage.calendars.allCalendarsAreHiddenTurn`,`All calendars are hidden. Turn one on in the legend to see events.`)})]}):e(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[r(W,{calendars:A,onToggleVisible:G,onColorChange:Y,busy:u.isPending}),e(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(U,{mode:h,onChange:g}),e(`div`,{className:`flex items-center gap-1`,children:[r(`button`,{type:`button`,className:Q,onClick:Z,"aria-label":a(`systemPage.calendars.previous`,`Previous`),"data-testid":`calendars-prev`,children:r(s,{className:`h-4 w-4`})}),r(`button`,{type:`button`,className:`inline-flex items-center rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5`,onClick:X,"data-testid":`calendars-today`,children:a(`systemPage.calendars.today`,`Today`)}),r(`button`,{type:`button`,className:Q,onClick:ee,"aria-label":a(`common.next`,`Next`),"data-testid":`calendars-next`,children:r(c,{className:`h-4 w-4`})})]}),r(`span`,{className:`text-sm font-medium text-foreground`,"data-testid":`calendars-period`,children:N(_,h)})]}),R.isPending?r(`p`,{className:`text-sm text-foreground-subtle`,children:a(`systemPage.calendars.loadingEvents`,`Loading events…`)}):R.isError?e(`p`,{className:`text-sm text-destructive`,children:[a(`systemPage.calendars.couldNotListEvents`,`Could not list events:`),` `,R.error.message]}):h===`month`?r(K,{anchor:_,events:z,colorById:V,today:S,onSelectEvent:b}):h===`week`?r(q,{anchor:_,events:z,colorById:V,today:S,onSelectEvent:b}):r(J,{anchor:_,events:z,colorById:V,calName:H,onSelectEvent:b})]})]}),e(D,{icon:d,title:a(`systemPage.calendars.calendars`,`Calendars`),subtitle:a(`systemPage.calendars.calendarsFromConnectedSourcesUsed`,`Calendars from connected sources. Used by Calendar events notification rules.`),children:[$,y===null?null:r(B,{ev:y,calendarName:H.get(y.calendarId)??y.calendarId,color:V.get(y.calendarId)??`#64748B`,onClose:()=>b(null)})]})}export{Y as CalendarsPage,Y as default};
1
+ import{C as e,K as t,R as n,S as r,Y as i,et as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Ei as s,Ti as c}from"./player-overlays-g9d3qYrr.js";import{fr as l,pr as u}from"./client-CwJGlpR9.js";import{h as d}from"./video-BFmrpvc7.js";import{Ma as f,Na as p,Pa as m,Yr as h,_r as g,dr as _,fr as v,gr as y,hr as b,ja as x,pr as S}from"./src-DwNoxp86.js";import{t as C}from"./i18n-9jE1YKjd.js";import{t as w}from"./useTranslation-BJr-n0es.js";import{mr as T,pr as E}from"./index-DG07MiZm.js";import{t as D}from"./AdminPage-DlYf-2bp.js";a();var O=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function k(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function A(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function j(e){let t=e.getDay();return k(A(e,t===0?-6:1-t))}function M(e,t){if(t===`day`){let t=k(e);return{startMs:t.getTime(),endMs:A(t,1).getTime()}}if(t===`week`){let t=j(e);return{startMs:t.getTime(),endMs:A(t,7).getTime()}}let n=new Date(e.getFullYear(),e.getMonth(),1),r=new Date(e.getFullYear(),e.getMonth()+1,0),i=j(n),a=A(j(r),7);return{startMs:i.getTime(),endMs:a.getTime()}}function N(e,t){if(t===`day`)return e.toLocaleDateString(void 0,{weekday:`long`,year:`numeric`,month:`long`,day:`numeric`});if(t===`week`){let t=j(e),n=A(t,6),r={month:`short`,day:`numeric`};return`${t.toLocaleDateString(void 0,r)} – ${n.toLocaleDateString(void 0,{...r,year:`numeric`})}`}return e.toLocaleDateString(void 0,{month:`long`,year:`numeric`})}function P(e,t,n){return t===`day`?A(e,n):t===`week`?A(e,n*7):new Date(e.getFullYear(),e.getMonth()+n,1)}function F(e,t){if(t===void 0)return e;let n=t.calendars[e.id];return n===void 0?e:{...e,visible:n.visible??e.visible,color:n.color??e.defaultColor}}function I(e){return e.providerAddonId!==void 0&&e.providerAddonId.length>0?e.providerAddonId:e.source===`ha`?`Home Assistant`:e.source}function L(e){if(e.allDay===!0)return C.t(`systemPage.calendars.allDay`);let t=new Date(e.startMs),n=new Date(e.endMs),r={hour:`2-digit`,minute:`2-digit`};return`${t.toLocaleTimeString([],r)} – ${n.toLocaleTimeString([],r)}`}function R(e){let t=l(e),n=new Date(t.startMs),r=new Date(t.endMs),i={weekday:`short`,year:`numeric`,month:`short`,day:`numeric`};if(e.allDay===!0){let e=k(n),t=A(k(r),-1);return H(e,t)?C.t(`systemPage.calendars.dayAllDay`,{date:n.toLocaleDateString(void 0,i)}):C.t(`systemPage.calendars.rangeAllDay`,{from:n.toLocaleDateString(void 0,i),to:t.toLocaleDateString(void 0,i)})}let a={hour:`2-digit`,minute:`2-digit`};return H(n,r)?`${n.toLocaleDateString(void 0,i)} · ${n.toLocaleTimeString([],a)} – ${r.toLocaleTimeString([],a)}`:`${n.toLocaleString(void 0,{...i,...a})} – ${r.toLocaleString(void 0,{...i,...a})}`}function z({label:t,children:n}){return e(`div`,{className:`grid grid-cols-[7rem_minmax(0,1fr)] gap-x-3 gap-y-1 text-sm`,children:[r(`dt`,{className:`text-foreground-subtle`,children:t}),r(`dd`,{className:`min-w-0 break-words text-foreground`,children:n})]})}function B({ev:t,calendarName:n,color:i,onClose:a}){let{t:o}=w();return r(_,{open:!0,onOpenChange:e=>!e&&a(),children:e(S,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`calendars-event-detail`,children:[r(y,{children:e(`div`,{className:`flex min-w-0 items-start gap-2.5`,children:[r(`span`,{className:`mt-1.5 h-3 w-3 shrink-0 rounded-full`,style:{backgroundColor:i},"aria-hidden":!0}),r(g,{className:`min-w-0 break-words`,children:t.title})]})}),r(v,{children:e(`dl`,{className:`space-y-3`,children:[r(z,{label:o(`systemPage.calendars.when`,`When`),children:R(t)}),r(z,{label:o(`systemPage.calendars.calendar`,`Calendar`),children:n}),t.location!==void 0&&t.location.length>0?r(z,{label:o(`systemPage.calendars.location`,`Location`),children:t.location}):null,t.description!==void 0&&t.description.length>0?r(z,{label:o(`systemPage.calendars.description`,`Description`),children:r(`span`,{className:`whitespace-pre-wrap`,children:t.description})}):null]})}),r(b,{children:r(h,{type:`button`,size:`sm`,variant:`secondary`,onClick:a,children:o(`common.close`,`Close`)})})]})})}function V(e,t){return e.filter(e=>u(e,t))}function H(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function U({mode:e,onChange:t}){let{t:n}=w(),i=[{id:`month`,label:n(`systemPage.calendars.month`,`Month`)},{id:`week`,label:n(`systemPage.calendars.week`,`Week`)},{id:`day`,label:n(`systemPage.calendars.day`,`Day`)}];return r(`div`,{className:`inline-flex rounded-lg border border-border bg-surface p-0.5`,role:`group`,"aria-label":n(`systemPage.calendars.calendarView`,`Calendar view`),children:i.map(n=>r(`button`,{type:`button`,className:e===n.id?`rounded-md bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground`:`rounded-md px-2.5 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground`,"aria-pressed":e===n.id,onClick:()=>t(n.id),"data-testid":`calendars-view-${n.id}`,children:n.label},n.id))})}function W({calendars:t,onToggleVisible:n,onColorChange:i,busy:a}){let{t:o}=w();return e(`aside`,{className:`w-full shrink-0 space-y-2 lg:w-56 xl:w-64`,"data-testid":`calendars-legend`,children:[r(`h2`,{className:`text-xs font-medium text-foreground-subtle`,children:o(`systemPage.calendars.calendars`,`Calendars`)}),r(`ul`,{className:`space-y-1`,children:t.map(t=>e(`li`,{className:`flex items-start gap-2 rounded-md px-1.5 py-1.5 hover:bg-surface`,children:[r(`input`,{type:`checkbox`,className:`mt-1 h-3.5 w-3.5 shrink-0 accent-primary`,checked:t.visible,disabled:a,onChange:e=>n(t.id,e.target.checked),"aria-label":o(`systemPage.calendars.show`,`Show {{name}}`,{name:t.name}),"data-testid":`calendars-visible-${t.id}`}),r(`input`,{type:`color`,className:`mt-0.5 h-6 w-6 shrink-0 cursor-pointer rounded border border-border bg-transparent p-0`,value:t.color,disabled:a,onChange:e=>i(t.id,e.target.value.toUpperCase()),"aria-label":o(`systemPage.calendars.colourFor`,`Colour for {{name}}`,{name:t.name}),"data-testid":`calendars-color-${t.id}`}),e(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`truncate text-sm font-medium ${t.visible?`text-foreground`:`text-foreground-subtle`}`,children:t.name}),e(`div`,{className:`truncate text-[11px] text-foreground-subtle`,children:[I(t),t.enabled?``:` · ${o(`systemPage.calendars.unavailableAtSource`)}`]})]})]},t.id))})]})}function G({ev:t,color:n,compact:i,onSelect:a}){return r(`button`,{type:`button`,className:i?`block w-full truncate rounded px-1 py-0.5 text-left text-[10px] leading-tight text-white hover:brightness-110`:`block w-full rounded-md px-2 py-1.5 text-left text-xs text-white hover:brightness-110`,style:{backgroundColor:n},title:t.title,onClick:()=>a(t),"data-testid":`calendars-event-${t.id}`,children:i?t.title:e(o,{children:[r(`div`,{className:`font-medium`,children:t.title}),r(`div`,{className:`opacity-90`,children:L(t)})]})})}function K({anchor:t,events:n,colorById:i,today:a,onSelectEvent:o}){let{t:s}=w(),{startMs:c,endMs:l}=M(t,`month`),u=[];for(let e=new Date(c);e.getTime()<l;e=A(e,1))u.push(e);let d=t.getMonth();return e(`div`,{"data-testid":`calendars-month`,children:[r(`div`,{className:`mb-1 grid grid-cols-7 gap-px`,children:O.map(e=>r(`div`,{className:`px-1 py-1 text-center text-[11px] font-medium text-foreground-subtle`,children:e},e))}),r(`div`,{className:`grid grid-cols-7 gap-px overflow-hidden rounded-lg border border-border bg-border`,children:u.map(t=>{let c=k(t).getTime(),l=V(n,c),u=t.getMonth()!==d,f=H(t,a);return e(`div`,{className:`min-h-[5.5rem] bg-background p-1 ${u?`opacity-45`:``}`,children:[r(`div`,{className:f?`mb-1 inline-flex h-5 w-5 items-center justify-center rounded-full bg-primary text-[11px] font-semibold text-primary-foreground`:`mb-1 text-[11px] font-medium text-foreground-subtle`,children:t.getDate()}),e(`div`,{className:`space-y-0.5`,children:[l.slice(0,3).map(e=>r(G,{ev:e,color:i.get(e.calendarId)??`#64748B`,compact:!0,onSelect:o},e.id)),l.length>3?r(`div`,{className:`text-[10px] text-foreground-subtle`,children:s(`common.moreCount`,{count:l.length-3})}):null]})]},c)})})]})}function q({anchor:t,events:n,colorById:i,today:a,onSelectEvent:o}){let s=j(t);return r(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-7 sm:gap-px sm:overflow-hidden sm:rounded-lg sm:border sm:border-border sm:bg-border`,"data-testid":`calendars-week`,children:Array.from({length:7},(e,t)=>A(s,t)).map(t=>{let s=k(t).getTime(),c=V(n,s);return e(`div`,{className:`min-h-[8rem] bg-background p-2 sm:min-h-[12rem]`,children:[r(`div`,{className:H(t,a)?`mb-2 text-xs font-semibold text-primary`:`mb-2 text-xs font-medium text-foreground-subtle`,children:t.toLocaleDateString(void 0,{weekday:`short`,day:`numeric`})}),r(`div`,{className:`space-y-1`,children:c.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):c.map(e=>r(G,{ev:e,color:i.get(e.calendarId)??`#64748B`,onSelect:o},e.id))})]},s)})})}function J({anchor:t,events:n,colorById:i,calName:a,onSelectEvent:o}){let{t:s}=w(),c=V(n,k(t).getTime());return c.length===0?r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-day-empty`,children:s(`systemPage.calendars.noEventsOnThisDay`,`No events on this day.`)}):r(`ul`,{className:`divide-y divide-border rounded-lg border border-border`,"data-testid":`calendars-day`,children:c.map(t=>r(`li`,{children:e(`button`,{type:`button`,className:`flex w-full items-start gap-3 px-3 py-3 text-left hover:bg-surface`,onClick:()=>o(t),"data-testid":`calendars-event-${t.id}`,children:[r(`span`,{className:`mt-1 h-2.5 w-2.5 shrink-0 rounded-full`,style:{backgroundColor:i.get(t.calendarId)??`#64748B`}}),e(`div`,{className:`min-w-0`,children:[r(`div`,{className:`font-medium text-sm text-foreground`,children:t.title}),e(`div`,{className:`text-xs text-foreground-subtle`,children:[L(t),` · `,a.get(t.calendarId)??t.calendarId]}),t.location!==void 0&&t.location.length>0?r(`div`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:t.location}):null]})]})},t.id))})}function Y(){let{t:a}=w(),o=f(),l=x({}),u=m(),[h,g]=i(`month`),[_,v]=i(()=>k(new Date)),[y,b]=i(null),S=t(()=>k(new Date),[]),C=o.isSuccess,O=l.isSuccess&&l.data!==void 0?l.data:void 0,A=t(()=>!C||o.data===void 0?[]:o.data.map(e=>F(e,O)),[C,o.data,O]),j=t(()=>A.filter(e=>e.visible),[A]),I=t(()=>j.map(e=>e.id),[j]),L=t(()=>M(_,h),[_,h]),R=p({startMs:L.startMs,endMs:L.endMs,calendarIds:[...I]},{enabled:C&&I.length>0}),z=R.data??[],V=t(()=>{let e=new Map;for(let t of A)e.set(t.id,t.color);return e},[A]),H=t(()=>{let e=new Map;for(let t of A)e.set(t.id,t.name);return e},[A]),G=n((e,t)=>{u.mutateAsync({calendarId:e,visible:t}).then(()=>l.refetch())},[l,u]),Y=n((e,t)=>{/^#[0-9A-Fa-f]{6}$/.test(t)&&u.mutateAsync({calendarId:e,color:t}).then(()=>l.refetch())},[l,u]),X=n(()=>v(k(new Date)),[]),Z=n(()=>v(e=>P(e,h,-1)),[h]),ee=n(()=>v(e=>P(e,h,1)),[h]),Q=`inline-flex h-8 w-8 items-center justify-center rounded-lg border border-border bg-surface text-foreground hover:bg-primary/5 disabled:opacity-50`,$;return $=o.isPending?r(`p`,{className:`text-sm text-foreground-subtle`,children:a(`systemPage.calendars.loadingCalendars`,`Loading calendars…`)}):o.isError?e(`p`,{className:`text-sm text-destructive`,children:[a(`systemPage.calendars.couldNotListCalendars`,`Could not list calendars:`),` `,o.error.message]}):A.length===0?r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-sources`,children:r(E,{i18nKey:`systemPage.calendars.emptySources`,components:{link:r(T,{to:`/system/integrations?tab=calendars`,className:`text-accent underline-offset-2 hover:underline`})}})}):I.length===0?e(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[r(W,{calendars:A,onToggleVisible:G,onColorChange:Y,busy:u.isPending}),r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-hidden`,children:a(`systemPage.calendars.allCalendarsAreHiddenTurn`,`All calendars are hidden. Turn one on in the legend to see events.`)})]}):e(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[r(W,{calendars:A,onToggleVisible:G,onColorChange:Y,busy:u.isPending}),e(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(U,{mode:h,onChange:g}),e(`div`,{className:`flex items-center gap-1`,children:[r(`button`,{type:`button`,className:Q,onClick:Z,"aria-label":a(`systemPage.calendars.previous`,`Previous`),"data-testid":`calendars-prev`,children:r(s,{className:`h-4 w-4`})}),r(`button`,{type:`button`,className:`inline-flex items-center rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5`,onClick:X,"data-testid":`calendars-today`,children:a(`systemPage.calendars.today`,`Today`)}),r(`button`,{type:`button`,className:Q,onClick:ee,"aria-label":a(`common.next`,`Next`),"data-testid":`calendars-next`,children:r(c,{className:`h-4 w-4`})})]}),r(`span`,{className:`text-sm font-medium text-foreground`,"data-testid":`calendars-period`,children:N(_,h)})]}),R.isPending?r(`p`,{className:`text-sm text-foreground-subtle`,children:a(`systemPage.calendars.loadingEvents`,`Loading events…`)}):R.isError?e(`p`,{className:`text-sm text-destructive`,children:[a(`systemPage.calendars.couldNotListEvents`,`Could not list events:`),` `,R.error.message]}):h===`month`?r(K,{anchor:_,events:z,colorById:V,today:S,onSelectEvent:b}):h===`week`?r(q,{anchor:_,events:z,colorById:V,today:S,onSelectEvent:b}):r(J,{anchor:_,events:z,colorById:V,calName:H,onSelectEvent:b})]})]}),e(D,{icon:d,title:a(`systemPage.calendars.calendars`,`Calendars`),subtitle:a(`systemPage.calendars.calendarsFromConnectedSourcesUsed`,`Calendars from connected sources. Used by Calendar events notification rules.`),children:[$,y===null?null:r(B,{ev:y,calendarName:H.get(y.calendarId)??y.calendarId,color:V.get(y.calendarId)??`#64748B`,onClose:()=>b(null)})]})}export{Y as CalendarsPage,Y as default};
@@ -0,0 +1 @@
1
+ import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,o as c,x as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{D as u,Di as d,Dn as f,En as p,Fn as m,Gn as h,Ht as g,Kr as _,Li as v,Oi as y,Ti as b,Vn as x,_n as S,dt as C,fr as w,gt as T,ia as E,kn as D,ni as O,pi as k,pn as A,st as j,vn as M,wn as N,xi as P,yi as F,yn as I,zt as L}from"./player-overlays-g9d3qYrr.js";import{Ca as R,Ta as ee,ka as te,wa as ne}from"./client-CwJGlpR9.js";import{t as re}from"./hard-drive-download-DKm5p-Le.js";import{t as ie}from"./memory-stick-DnKI7rwN.js";import{t as ae}from"./unlink-C-2ouMww.js";import{$t as oe,Bd as z,Cn as se,Do as ce,Er as le,Eu as ue,Id as de,Ld as B,P as fe,Sn as V,Td as pe,Tr as H,Yr as U,_c as me,_r as he,at as ge,au as _e,bc as ve,bn as ye,ci as be,dc as xe,dr as Se,en as Ce,fr as we,gd as W,gr as Te,hr as Ee,iu as De,kn as Oe,li as ke,ll as Ae,mr as je,nu as Me,pr as Ne,ri as Pe,ru as Fe,si as Ie,tl as Le,uc as Re,ui as ze,vc as Be,vl as Ve,vt as He,wl as Ue,wr as We,xn as Ge,xt as G,yc as Ke}from"./src-DwNoxp86.js";import{t as K}from"./i18n-9jE1YKjd.js";import{t as q}from"./useTranslation-BJr-n0es.js";import{x as qe,yr as Je}from"./index-DG07MiZm.js";import{t as Ye}from"./AdminPage-DlYf-2bp.js";import{t as Xe}from"./NodeAddonsSettingsPanel-CeHG4O24.js";import{f as Ze,l as Qe,m as $e,u as et}from"./board-model-Cb9TF016.js";import{t as J}from"./format-size-DIxKXxtj.js";import{n as tt,t as nt}from"./useNodeUrlSelection-Cg0TPdbH.js";s();var rt={unpaired:`Not paired`,pending:`Pairing…`,paired:`Paired`},it=new Set([`paired`,`rejected`,`failed`,`expired`]);function Y(e){return it.has(e)}function at(e){return e.replace(/\D/g,``).slice(0,6)}function ot(e){return e.length===6}function st(e,t){let n=Math.max(0,Math.ceil((e-t)/1e3)),r=Math.floor(n/60),i=n%60;return`${r}:${String(i).padStart(2,`0`)}`}function ct(e,t){return e.includes(`:`)?`[${e}]:${t}`:`${e}:${t}`}function lt(e){return e.length<=23?e:`${e.slice(0,20)}…`}function ut({view:e,beginError:t}){if(e===null)return t===null?`sending`:`send-failed`;switch(e.state){case`paired`:return`paired`;case`rejected`:return`rejected`;case`failed`:return`failed`;case`expired`:return`expired`;case`completing`:return`completing`;case`awaiting-confirmation`:return e.hubConfirmed&&!e.agentConfirmed?`awaiting-agent`:e.agentConfirmed&&!e.hubConfirmed?`awaiting-hub`:`awaiting-both`}}function dt(e){return e===`awaiting-both`||e===`awaiting-hub`}var ft={sending:`Sending the pairing offer to the agent…`,"send-failed":`The agent could not be reached`,"awaiting-both":`Waiting for both confirmations`,"awaiting-agent":`Confirmed here — waiting for the agent`,"awaiting-hub":`The agent is confirmed — now confirm here`,completing:`Issuing the node certificate…`,paired:`Paired`,rejected:`Pairing was rejected`,failed:`Pairing failed`,expired:`The pairing expired`},pt=2e3,mt=1e3;function ht(e){return e.message.length>0?e.message:K.t(`pairing.agentsFoundSection.requestFailed`)}function gt(e){return e.length===6?`${e.slice(0,3)} ${e.slice(3)}`:e}function _t(e){let[t,n]=o(()=>Date.now());return a(()=>{if(!e)return;let t=setInterval(()=>n(Date.now()),mt);return()=>clearInterval(t)},[e]),t}function vt({target:n,onClose:r,onSettled:s,onOpenNode:c}){let{t:u}=q(),[d,f]=o(null),[p,m]=o(null),[h,g]=o(``),[_,v]=o(null),y=t(null),b=z.agentPairing.beginPairing.useMutation(),x=z.agentPairing.confirmPairing.useMutation(),S=z.agentPairing.rejectPairing.useMutation();a(()=>{if(n===null){y.current=null,f(null),m(null),g(``),v(null);return}if(y.current!==n){if(y.current=n,n.pairingId!==void 0){f(n.pairingId);return}b.mutateAsync({host:n.host,port:n.port}).then(e=>{y.current===n&&f(e.pairingId)}).catch(e=>{y.current===n&&m(ht(e))})}},[n]);let C=z.agentPairing.getPairing.useQuery({pairingId:d??``},{enabled:d!==null,refetchInterval:e=>{let t=e.state.data?.state;return t!==void 0&&Y(t)?!1:pt}}),T=yt(x.data??S.data??null,C.data??null),E=ut({view:T,beginError:p}),D=T!==null&&Y(T.state),O=t(!1);a(()=>{if(!D){O.current=!1;return}O.current||(O.current=!0,s())},[D,s]);let k=_t(T!==null&&!D),A=()=>{d===null||!ot(h)||(v(null),x.mutate({pairingId:d,code:h},{onError:e=>{v(ht(e)),g(``)}}))};return i(Se,{open:n!==null,onOpenChange:e=>!e&&r(),children:e(Ne,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[e(Te,{children:[i(he,{children:u(`pairing.pairingDialog.title`,{node:n?.nodeId??``})}),i(je,{children:n===null?``:u(`pairing.pairingDialog.eachScreenShowsACode`,`Both screens show the same six digits. Check they match, then type the code you read on the agent. Agent at {{value1}}`,{value1:ct(n.host,n.port)})})]}),e(we,{className:`space-y-4`,children:[i(bt,{phase:E}),E===`send-failed`&&p!==null&&i(H,{title:u(`pairing.pairingDialog.couldNotStartThePairing`,`Could not start the pairing`),message:p}),T!==null&&!D&&i(xt,{view:T,phase:E,now:k,typed:h,onType:e=>g(at(e)),onSubmit:A,confirmError:_,busy:x.isPending}),E===`paired`&&T!==null&&i(St,{nodeId:T.nodeId,onOpenNode:c,onClose:r}),D&&E!==`paired`&&T?.failure!=null&&i(H,{message:T.failure})]}),i(Ee,{children:D||E===`send-failed`?i(U,{type:`button`,variant:`outline`,onClick:r,children:u(`common.close`,`Close`)}):e(l,{children:[i(U,{type:`button`,variant:`outline`,disabled:S.isPending,onClick:()=>{if(d===null){r();return}S.mutate({pairingId:d},{onSettled:r})},children:u(`pairing.pairingDialog.reject`,`Reject`)}),dt(E)&&e(U,{type:`button`,disabled:!ot(h)||x.isPending,onClick:A,children:[x.isPending&&i(w,{className:`h-4 w-4 animate-spin`}),u(`common.confirm`,`Confirm`)]})]})})]})})}function yt(e,t){if(t===null)return e;if(e===null)return t;let n=e=>(Y(e.state)?10:e.state===`completing`?5:0)+ +!!e.hubConfirmed+ +!!e.agentConfirmed;return n(e)>n(t)?e:t}function bt({phase:t}){let n=t===`sending`||t===`completing`,r=t===`paired`,a=t===`rejected`||t===`failed`||t===`expired`||t===`send-failed`;return e(`p`,{role:`status`,className:`flex items-center gap-2 text-sm font-medium ${r?`text-success`:a?`text-danger`:`text-foreground`}`,children:[n&&i(w,{className:`h-4 w-4 animate-spin`}),r&&i(F,{className:`h-4 w-4`}),a&&i(k,{className:`h-4 w-4`}),ft[t]]})}function xt({view:t,phase:n,now:r,typed:a,onType:o,onSubmit:s,confirmError:c,busy:l}){let{t:u}=q();return e(`div`,{className:`space-y-4`,children:[e(`section`,{"aria-label":u(`pairing.pairingDialog.codeOnThisHub`,`Code on this hub`),className:`rounded-md border border-border bg-surface p-3`,children:[i(`p`,{className:`text-xs text-foreground-muted`,children:u(`pairing.pairingDialog.codeOnThisHubRead`,`Code on this hub: the agent must show the same digits`)}),i(`p`,{"data-testid":`hub-code`,className:`mt-1 font-mono text-3xl font-semibold tracking-widest text-foreground`,children:gt(t.code)}),i(`p`,{className:`mt-2 text-xs text-foreground-muted`,children:u(`pairing.pairingDialog.onTheAgentEnterThis`,`On the agent, enter this code and the agent’s local PIN (shown on the agent’s console or log, or on its own screen).`)})]}),dt(n)?i(`form`,{className:`space-y-2`,onSubmit:e=>{e.preventDefault(),s()},children:i(G,{label:u(`pairing.pairingDialog.codeShownOnTheAgent`,`Code shown on the agent`),description:u(`pairing.pairingDialog.typeTheSixDigitsThe`,`Type the six digits you read on the agent; do not paste. If they differ from the code above, stop and press Reject.`),...c===null?{}:{error:c},children:i(W,{value:a,onChange:e=>o(e.target.value),inputMode:`numeric`,autoComplete:`off`,spellCheck:!1,placeholder:`000000`,maxLength:6,disabled:l,"aria-label":u(`pairing.pairingDialog.codeShownOnTheAgent`,`Code shown on the agent`),className:`font-mono tracking-widest`})})}):i(`p`,{className:`text-xs text-foreground-muted`,children:n===`awaiting-agent`?u(`pairing.pairingDialog.youConfirmedHereTheAgent`,`You confirmed here. The agent still has to enter the hub code and its PIN.`):u(`pairing.pairingDialog.working`,`Working…`)}),e(`ul`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-xs text-foreground-muted`,children:[i(`li`,{children:t.hubConfirmed?u(`pairing.pairingDialog.hubConfirmed`,`Hub: confirmed`):u(`pairing.pairingDialog.hubNotConfirmed`,`Hub: not confirmed`)}),i(`li`,{children:t.agentConfirmed?u(`pairing.pairingDialog.agentConfirmed`,`Agent: confirmed`):u(`pairing.pairingDialog.agentNotConfirmed`,`Agent: not confirmed`)}),i(`li`,{"data-testid":`countdown`,children:u(`pairing.pairingDialog.expiresIn`,{countdown:st(t.expiresAt,r)})})]})]})}function St({nodeId:t,onOpenNode:n,onClose:r}){let{t:a}=q(),{nodes:o}=de(),s=o?.some(e=>e.id===t&&e.isOnline)===!0;return e(`div`,{className:`space-y-2 rounded-md border border-success/40 bg-success/10 p-3 text-sm`,children:[e(`p`,{className:`flex items-center gap-2 text-success`,children:[i(A,{className:`h-4 w-4`}),s?a(`pairing.pairingDialog.joinedAndRegisteredItsCapabilities`,`{{nodeId}} joined and registered its capabilities.`,{nodeId:t}):a(`pairing.pairingDialog.holdsItsCertificateWaitingFor`,`{{nodeId}} holds its certificate. Waiting for it to connect and register its capabilities…`,{nodeId:t})]}),i(U,{type:`button`,size:`sm`,variant:`outline`,disabled:!s,onClick:()=>{r(),n(t)},children:a(`pairing.pairingDialog.openNode`,`Open node`)})]})}var Ct={paired:`success`,pending:`warning`,unpaired:`default`};function wt({state:t,connected:n}){let{t:r}=q();return e(`span`,{className:`inline-flex items-center gap-1.5`,children:[i(Pe,{variant:Ct[t],className:`text-[10px]`,children:rt[t]}),t===`paired`&&i(`span`,{className:`text-[10px] text-foreground-muted`,children:n?r(`common.connected`):r(`pairing.agentStateBadge.notConnected`,`not connected`)})]})}s();var X={pending:0,unpaired:1,paired:2};function Tt(e){if(e.trim().length===0)return;let t=Number(e);return Number.isInteger(t)&&t>=1&&t<=65535?t:null}function Et({onOpenNode:t}){let{t:r}=q(),a=j(),s=z.useUtils(),c=z.agentPairing.listDiscoveredAgents.useQuery(void 0,{refetchInterval:15e3}),[d,f]=o(null),[h,g]=o(null),[_,v]=o(!1),[y,b]=o(``),[x,S]=o(``),[C,T]=o(null),[E,O]=o(!1),k=()=>void s.agentPairing.listDiscoveredAgents.invalidate(),A=z.agentPairing.addAgentByAddress.useMutation({onSuccess:()=>{v(!1),b(``),S(``),T(null),k()},onError:e=>T(e.message)}),M=z.agentPairing.unpairAgent.useMutation({onSuccess:e=>{g({tone:`success`,message:`${e.nodeId}: ${e.next}${e.agentNotified?``:` The agent could not be told; forget the hub on its own page.`}`}),k()},onError:e=>g({tone:`danger`,message:r(`pairing.agentsFoundSection.unpairFailed`,`Unpair failed: {{message}}`,{message:e.message})})}),N=n(()=>(c.data?.agents??[]).toSorted((e,t)=>X[e.state]-X[t.state]),[c.data]),P=async()=>{O(!0);try{await s.agentPairing.listDiscoveredAgents.fetch({refresh:!0}),k()}finally{O(!1)}},F=()=>{let e=Tt(x);if(e===null){T(`The port must be a whole number between 1 and 65535.`);return}T(null),A.mutate({host:y.trim(),...e===void 0?{}:{port:e}})},I=async e=>{await a({title:r(`pairing.agentsFoundSection.unpair`,`Unpair {{nodeId}}`,{nodeId:e.nodeId}),message:r(`pairing.agentsFoundSection.sCertificatesAreRevokedAt`,`{{nodeId}}'s certificates are revoked at once and it is disconnected from the mesh. It must be paired again before it can rejoin.`,{nodeId:e.nodeId}),confirmLabel:r(`pairing.agentsFoundSection.unpair2`,`Unpair`),variant:`danger`})&&(g(null),M.mutate({nodeId:e.nodeId}))},L=n(()=>[{key:`node`,header:r(`pairing.agentsFoundSection.node`,`Node`),render:e=>i(`span`,{className:`font-medium text-foreground`,children:e.nodeId}),sortValue:e=>e.nodeId},{key:`address`,header:r(`pairing.agentsFoundSection.address`,`Address`),render:e=>i(`span`,{className:`font-mono text-xs`,children:ct(e.host,e.port)}),sortValue:e=>e.host},{key:`version`,header:r(`pairing.agentsFoundSection.version`,`Version`),render:e=>e.version??`—`,sortValue:e=>e.version},{key:`state`,header:r(`pairing.agentsFoundSection.state`,`State`),render:e=>i(wt,{state:e.state,connected:e.connected}),sortValue:e=>X[e.state]},{key:`fingerprint`,header:r(`pairing.agentsFoundSection.certificate`,`Certificate`),render:e=>e.fingerprint===null?`—`:i(`span`,{className:`font-mono text-xs`,title:e.fingerprint,children:lt(e.fingerprint)}),sortValue:e=>e.fingerprint},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,render:e=>{let t=e.pairing;return e.state===`unpaired`?i(U,{type:`button`,size:`sm`,onClick:()=>f({nodeId:e.nodeId,host:e.host,port:e.port}),children:r(`pairing.agentsFoundSection.pair`,`Pair`)}):e.state===`paired`?i(U,{type:`button`,size:`sm`,variant:`outline`,disabled:M.isPending,onClick:()=>void I(e),children:r(`pairing.agentsFoundSection.unpair2`,`Unpair`)}):e.state===`pending`&&t!==null?i(U,{type:`button`,size:`sm`,onClick:()=>f({nodeId:e.nodeId,host:e.host,port:e.port,pairingId:t.pairingId}),children:r(`pairing.agentsFoundSection.resume`,`Resume`)}):null}}],[M.isPending,r]);return e(ye,{headingId:`agents-found`,title:r(`pairing.agentsFoundSection.agentsFoundOnTheNetwork`,`Agents found on the network`),icon:D,testId:`agents-found`,actions:e(l,{children:[e(U,{type:`button`,size:`sm`,variant:`outline`,disabled:E,onClick:()=>void P(),children:[E?i(w,{className:`h-3.5 w-3.5 animate-spin`}):i(p,{className:`h-3.5 w-3.5`}),r(`pairing.agentsFoundSection.scan`,`Scan`)]}),e(U,{type:`button`,size:`sm`,onClick:()=>v(e=>!e),children:[i(m,{className:`h-3.5 w-3.5`}),r(`pairing.agentsFoundSection.addByAddress`,`Add by address`)]})]}),children:[e(`div`,{className:`${u} space-y-3`,children:[i(`p`,{className:`text-[11px] leading-relaxed text-foreground-muted`,children:r(`pairing.agentsFoundSection.anAgentHoldsNoSecret`,`An agent holds no secret: pairing issues it a certificate after you confirm the same six digits on this page and on the agent. Discovery needs the agent on its own IP or host networking; a Docker bridge hides it — add it by address.`)}),_&&e(`form`,{"aria-label":r(`pairing.agentsFoundSection.addAgentByAddress`,`Add agent by address`),className:`flex flex-wrap items-start gap-2`,onSubmit:e=>{e.preventDefault(),y.trim().length>0&&!A.isPending&&F()},children:[i(G,{label:r(`pairing.agentsFoundSection.address`,`Address`),description:r(`pairing.agentsFoundSection.aPrivateOrLocalAddress`,`A private or local address only.`),...C===null?{}:{error:C},children:i(W,{value:y,onChange:e=>b(e.target.value),placeholder:`192.0.2.20`,"aria-label":r(`pairing.agentsFoundSection.agentAddress`,`Agent address`),autoComplete:`off`})}),i(G,{label:r(`pairing.agentsFoundSection.port`,`Port`),description:r(`pairing.agentsFoundSection.optional`,`Optional.`),children:i(W,{value:x,onChange:e=>S(e.target.value),placeholder:`4444`,inputMode:`numeric`,"aria-label":r(`pairing.agentsFoundSection.agentPort`,`Agent port`),className:`w-24`})}),e(U,{type:`submit`,size:`sm`,className:`mt-5`,disabled:y.trim().length===0||A.isPending,children:[A.isPending&&i(w,{className:`h-3.5 w-3.5 animate-spin`}),r(`common.add`,`Add`)]})]}),h!==null&&i(`p`,{role:`status`,className:`rounded border px-3 py-2 text-xs ${h.tone===`success`?`border-success/30 text-foreground`:`border-danger/40 text-danger`}`,children:h.message}),c.isError?i(H,{title:r(`pairing.agentsFoundSection.couldNotListAgents`,`Could not list agents`),message:c.error?.message??r(`pairing.agentsFoundSection.requestFailed`,`Request failed`),onRetry:k}):c.isLoading?i(`p`,{className:`py-4 text-center text-xs text-foreground-muted`,children:r(`pairing.agentsFoundSection.lookingForAgents`,`Looking for agents…`)}):N.length===0?i(le,{icon:D,title:r(`pairing.agentsFoundSection.noAgentsFound`,`No agents found`),description:r(`pairing.agentsFoundSection.nothingIsAdvertisingOnThis`,`Nothing is advertising on this network. Start the agent on its own IP (or host networking), or add it by address.`)}):i(V,{columns:L,rows:N,rowKey:e=>e.nodeId,minWidthPx:720,defaultSort:{columnKey:`state`,dir:`asc`}})]}),i(vt,{target:d,onClose:()=>f(null),onSettled:k,onOpenNode:t})]})}function Dt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ot(e){if(!Dt(e))return null;let t=e.ticket;if(typeof t!=`string`||t.length===0)return null;let n=e.dashboardUrl;return typeof n==`string`&&n.length>0?{ticket:t,dashboardUrl:n}:{ticket:t}}function kt(e){let t=e.trim();return!(t.length===0||t.includes(`/`)||t.includes(`?`)||t.includes(`#`)||t.includes(`@`)||t.includes(`:`))}function Z(e){return e.startsWith(`172.17.`)}function At(e){let t=/^100\.(\d+)\./.exec(e);if(t===null)return!1;let n=Number(t[1]);return n>=64&&n<=127}function jt(e){if(e.startsWith(`10.`)||e.startsWith(`192.168.`))return!0;let t=/^172\.(\d+)\./.exec(e);if(t===null)return!1;let n=Number(t[1]);return n>=16&&n<=31&&!Z(e)}function Mt(e,t){if(typeof t==`string`&&kt(t))return t.trim();let n=e.filter(e=>!e.includes(`:`)),r=n.find(e=>!e.startsWith(`127.`)&&!e.startsWith(`169.254.`)&&!Z(e)&&!At(e)&&jt(e));if(r!==void 0)return r;for(let e of n)if(!e.startsWith(`127.`)&&!e.startsWith(`169.254.`)&&!Z(e))return e;return null}function Nt(e){return`http://${e}:4444/`}function Pt(e,t){let n=new URL(Nt(e));return n.searchParams.set(`ticket`,t),n.toString()}function Ft(){return window.open(`about:blank`,`_blank`)}function It(e,t){return e===null||e.closed?!1:(e.location.href=t,!0)}function Lt({node:t}){let{info:n}=qe();return!t.isHub||n===null?i(`span`,{className:`text-sm font-semibold shrink-0`,children:t.name}):e(l,{children:[i(`span`,{className:`text-sm font-semibold shrink-0`,"data-testid":`node-title-name`,children:n.name}),n.name!==t.id&&i(`span`,{className:`text-xs text-foreground-subtle shrink-0`,"data-testid":`node-title-id`,children:t.id})]})}s();function Rt(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function zt(e){return e===`running`?`running`:e===`crashed`||e===`failed`?`error`:`stopped`}var Bt=[`trace`,`debug`,`info`,`warn`,`error`];function Vt({proc:t,nodeId:n,defaultExpanded:r,activePanel:a,onTogglePanel:s}){let{t:c}=q(),l=t.services??[],u=l.length===1,[p,m]=o(u||r),[h,g]=o(null),[_,y]=o(`info`),x=t.name.includes(`(core)`),C=Be(),w=Ke(),T=ve(),E=async e=>{g(e);try{await C.mutateAsync({nodeId:n,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{g(null)}},D=async()=>{g(t.name);try{await w.mutateAsync({nodeId:n,processName:t.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{g(null)}},O=async e=>{let r=`${n}/${t.name}`;try{await T.mutateAsync({nodeId:r,level:e}),y(e)}catch(e){console.error(`Failed to set log level:`,e)}};return e(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[e(`div`,{role:u?void 0:`button`,tabIndex:u?void 0:0,onClick:u?void 0:()=>m(!p),onKeyDown:u?void 0:e=>{(e.key===`Enter`||e.key===` `)&&m(!p)},className:`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${u?``:`hover:bg-muted/40 cursor-pointer`}`,children:[u?i(`span`,{className:`h-3 w-3 shrink-0`}):i(p?d:b,{className:`h-3 w-3 text-muted-foreground shrink-0`}),x?i(S,{className:`h-3.5 w-3.5 text-primary shrink-0`}):i(v,{className:`h-3.5 w-3.5 text-warning shrink-0`}),i(`span`,{className:`text-xs font-semibold min-w-0 flex-1 basis-full truncate sm:basis-auto`,children:t.name}),e(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:[`PID `,t.pid]}),i(ge,{status:zt(t.state),label:t.state}),i(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:c(`cluster.forksTab.cpu`,{percent:t.cpuPercent})}),i(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:J(t.memoryRss)}),i(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:Rt(t.uptimeSeconds)}),!x&&e(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[e(Ie,{children:[i(ze,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:c(`cluster.forksTab.setLogLevel`,`Set log level`),children:_}),i(be,{align:`end`,className:`min-w-[70px] py-0.5`,children:Bt.map(e=>i(ke,{onClick:()=>O(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===_?`text-primary font-semibold`:``}`,children:e},e))})]}),i(`button`,{onClick:D,disabled:h===t.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:c(`cluster.forksTab.restartProcess`,`Restart process`),children:i(N,{className:`h-3 w-3 ${h===t.name?`animate-spin`:``}`})})]})]}),p&&l.length>0&&i(`div`,{className:`divide-y divide-border/30`,children:l.map(t=>e(`div`,{children:[e(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[i(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${t.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),i(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:t.addonId}),t.capabilities.length>0&&e(`div`,{className:`flex gap-1 flex-shrink-0`,children:[t.capabilities.slice(0,3).map(e=>i(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-info/10 text-info truncate max-w-[80px]`,children:e},e)),t.capabilities.length>3&&e(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,t.capabilities.length-3]})]}),e(`div`,{className:`flex items-center gap-1 shrink-0`,children:[i(`button`,{onClick:()=>s(t.addonId,`logs`),className:`p-0.5 rounded transition-colors ${a?.addonId===t.addonId&&a.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:c(`cluster.forksTab.showLogsFor`,`Show logs for {{addonId}}`,{addonId:t.addonId}),children:i(I,{className:`h-3 w-3`})}),i(`button`,{onClick:()=>s(t.addonId,`events`),className:`p-0.5 rounded transition-colors ${a?.addonId===t.addonId&&a.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:c(`cluster.forksTab.showEventsFor`,`Show events for {{addonId}}`,{addonId:t.addonId}),children:i(f,{className:`h-3 w-3`})}),i(`button`,{onClick:()=>E(t.addonId),disabled:h===t.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:c(`cluster.forksTab.restart`,`Restart {{addonId}}`,{addonId:t.addonId}),children:i(N,{className:`h-3 w-3 ${h===t.addonId?`animate-spin`:``}`})})]})]}),a?.addonId===t.addonId&&a.type===`logs`&&i(`div`,{className:`border-t border-border/40 bg-muted/5`,children:i(Ce,{addonId:t.addonId,agentId:n,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>s(t.addonId,`logs`)})}),a?.addonId===t.addonId&&a.type===`events`&&i(`div`,{className:`border-t border-border/40 bg-muted/5`,children:i(oe,{addonId:t.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>s(t.addonId,`events`)})})]},t.addonId))}),p&&l.length===0&&i(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:c(`cluster.forksTab.noServices`,`No services`)})]})}function Ht({nodeId:e,processes:t}){let{t:n}=q(),[r,a]=o(null),s=(e,t)=>{a(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?i(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:n(`cluster.forksTab.noProcessesOnThisNode`,`No processes on this node`)}):i(`div`,{className:`space-y-2 py-1`,children:t.map((t,n)=>i(Vt,{proc:t,nodeId:e,defaultExpanded:n===0,activePanel:r,onTogglePanel:s},t.name))})}var Ut={system:0,managed:1,root:2};s();function Wt(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function Gt(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function Kt({nodeId:t}){let{t:r}=q(),a=c(),o=B(`metrics.node-processes-snapshot`,e=>e.nodeId===t),{data:s}=xe({nodeId:t}),l=o?.processes??s,u=n(()=>l?[...l]:[],[l]),d=n(()=>[{key:`classification`,header:r(`cluster.processesTab.class`,`Class`),sortValue:e=>Ut[e.classification],render:e=>i(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`root`?`bg-info/20 text-info`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})},{key:`pid`,header:`PID`,align:`right`,sortValue:e=>e.pid,render:e=>i(`span`,{className:`font-mono`,children:e.pid})},{key:`ppid`,header:`PPID`,align:`right`,sortValue:e=>e.ppid,render:e=>i(`span`,{className:`font-mono text-foreground-subtle`,children:e.ppid})},{key:`addonId`,header:r(`cluster.processesTab.addon`,`Addon`),sortValue:e=>e.addonId,render:e=>i(`span`,{className:`text-foreground-subtle text-[11px]`,children:e.addonId??`—`})},{key:`command`,header:r(`cluster.processesTab.command`,`Command`),nowrap:!1,render:e=>i(`span`,{className:`font-mono text-[10px] text-foreground-subtle break-all`,children:Gt(e.command)})},{key:`cpuPercent`,header:r(`cluster.processesTab.cpu`,`CPU%`),align:`right`,sortValue:e=>e.cpuPercent,render:e=>e.cpuPercent.toFixed(1)},{key:`memoryRssBytes`,header:`RSS`,align:`right`,sortValue:e=>e.memoryRssBytes,render:e=>J(e.memoryRssBytes)},{key:`uptimeSec`,header:r(`cluster.processesTab.uptime`,`Uptime`),align:`right`,sortValue:e=>e.uptimeSec,render:e=>i(`span`,{className:`text-foreground-subtle`,children:Wt(e.uptimeSec)})}],[r]);return e(`div`,{className:`space-y-4`,children:[i(`div`,{className:`flex items-start justify-end gap-4`,children:e(`button`,{type:`button`,onClick:()=>a.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[i(p,{className:`h-3 w-3`}),` `,r(`common.refresh`)]})}),i(V,{columns:d,rows:u,rowKey:e=>e.pid,minWidthPx:880,maxBodyHeight:se,emptyMessage:r(`cluster.processesTab.scanning`,`Scanning…`)})]})}s();var qt=96;function Jt({title:e,points:t,mainLabel:r,gcLabel:a,formatValue:o,emptyMessage:s,gapMs:c}){return i(fe,{title:e,series:n(()=>[{id:`main`,label:r,unit:`%`,colorIndex:0,gapMs:c,points:t.map(e=>({t:e.atMs,v:e.main}))},{id:`gc`,label:a,unit:`%`,colorIndex:1,gapMs:c,points:t.map(e=>({t:e.atMs,v:e.gc}))}],[t,r,a,c]),stacked:!0,height:qt,formatValue:e=>o(e),axisFor:()=>({floor:25}),emptyMessage:s})}function Q({title:e,points:t,formatValue:r,emptyMessage:a,axisFloor:o,axisScale:s=`linear`,gapMs:c}){return i(fe,{title:e,series:n(()=>[{id:`value`,label:e,unit:s===`bytes`?`B`:null,colorIndex:0,gapMs:c,points:t.map(e=>({t:e.atMs,v:e.value}))}],[t,e,s,c]),height:qt,formatValue:e=>r(e),axisFor:()=>({floor:o,scale:s}),emptyMessage:a})}function Yt(e,t){let n=e.at(-1);return n===void 0?[t]:t.atMs>n.atMs?[...e,t]:e.some(e=>e.atMs===t.atMs)?e:[...e,t].toSorted((e,t)=>e.atMs-t.atMs)}function Xt(e,t,n,r){let i=e.get(t),a=Yt(i?.points??[],r);if(i!==void 0&&a===i.points)return e;let o=new Map(e);return o.set(t,{key:t,kind:n,points:a.slice(Math.max(0,a.length-720))}),o}function Zt(e,t,n){let r=e;for(let e of te(t,n))r=Xt(r,e.key,e.kind,e.point);return r}function Qt(e,t){let n=e;for(let e of t)for(let t of e.points)n=Xt(n,e.key,e.kind,t);return n}function $t(e){let t=null;for(let n of e.values()){let e=n.points.at(-1);e!==void 0&&(t===null||e.atMs>t)&&(t=e.atMs)}return t}var en=12e4;function tn(e,t){return e===null?!1:t-e>en}function nn(e){let t=e=>{let t=e.points.at(-1);return t===void 0?-1:t.cpuMainPercent!==null&&t.cpuGcPercent!==null?t.cpuMainPercent+t.cpuGcPercent:t.cpuLifetimePercent};return[...e.values()].toSorted((e,n)=>{let r=t(n)-t(e);return r===0?e.key.localeCompare(n.key):r})}function rn(e){for(let t of e.values()){let e=t.points.at(-1);if(e&&e.cpuMainPercent!==null)return!0}return!1}var an={key:`cpu`,dir:`desc`};function on(e){let t=e.points.at(-1);return t===void 0?null:t.cpuMainPercent!==null&&t.cpuGcPercent!==null?t.cpuMainPercent+t.cpuGcPercent:t.cpuLifetimePercent}function sn(e){return e.points.at(-1)?.memoryRssBytes??null}function cn(e,t,n){let r=n.trim().toLowerCase();return r===``?!0:e.toLowerCase().includes(r)||t.toLowerCase().includes(r)}function ln(e,t){return t===`memory`?sn(e):on(e)}function un(e,t,n){let r=e.filter(e=>t.selectedKeys.size>0&&!t.selectedKeys.has(e.key)?!1:cn(n(e),e.key,t.search)),i=(e,t)=>e.key.localeCompare(t.key);return[...r].toSorted((e,r)=>{if(t.sort.key===`name`){let a=n(e).localeCompare(n(r)),o=t.sort.dir===`asc`?a:-a;return o===0?i(e,r):o}let a=ln(e,t.sort.key),o=ln(r,t.sort.key);if(a===null&&o===null)return i(e,r);if(a===null)return 1;if(o===null)return-1;let s=t.sort.dir===`desc`?o-a:a-o;return s===0?i(e,r):s})}s();function dn(e,n=720){let r=B(`metrics.node-processes-snapshot`,t=>t.nodeId===e),[i,s]=o(new Map),[c,l]=o(void 0),u=t(null),{data:d,isPending:f}=Re({forNodeId:e,sinceMs:c,maxPoints:n});a(()=>{d!==void 0&&s(e=>{let t=Qt(e,d.series);return u.current=$t(t),t})},[d]);let p=r?.timestamp;a(()=>{r==null||p===void 0||(tn(u.current,p)&&l(u.current??0),s(e=>{let t=Zt(e,r.processes,p);return u.current=$t(t),t}))},[p]),a(()=>{s(new Map),l(void 0),u.current=null},[e]);let m=0;for(let e of i.values())m=Math.max(m,e.points.length);return{series:nn(i),sampleCount:m,threadSplitAvailable:rn(i),loadingRetained:f,durable:d?.durable??null,bucketMs:d?.bucketMs??null,cadenceMs:d?.cadenceMs??null,retainedSamples:d?.retainedSamples??null}}var fn=`__unclaimed__`;function pn(e,t){return{kind:e,deviceId:t,cpu:0,cpuKnown:!0,rss:0,rssKnown:!0,count:0,roles:new Set}}function mn(e,t){return{key:e,kind:t.kind,deviceId:t.deviceId,cpuSeconds:t.cpuKnown?Math.round(t.cpu*100)/100:null,rssBytes:t.rssKnown?t.rss:null,unitCount:t.count,roles:[...t.roles].sort()}}function hn(e,t){let n=new Map,r=new Set;for(let t of e){t.pid!==void 0&&r.add(t.pid);let e=t.deviceId!==null&&t.attribution!==`unattributable`,i=e?`device:${t.deviceId}`:`shared:${t.role}`,a=n.get(i)??pn(e?`camera`:`shared`,e?t.deviceId:null);a.count+=1,a.roles.add(t.role),t.cpuSeconds===void 0?a.cpuKnown=!1:a.cpu+=t.cpuSeconds,t.rssBytes===void 0?a.rssKnown=!1:a.rss+=t.rssBytes,n.set(i,a)}let i=[...n.entries()].map(([e,t])=>mn(e,t));if(t===void 0)return i;let a=t.filter(e=>!r.has(e.pid));if(a.length===0)return i;let o=pn(`unclaimed`,null);for(let e of a)o.count+=1,o.rss+=e.memoryRssBytes;return o.cpuKnown=!1,[...i,mn(fn,o)]}var gn=[{family:`decode`,attribution:`measured`,unit:`one forked decode-worker child per decode SESSION`,perCamera:!0,wiredToday:!0,missingLink:``,evidence:[`packages/addon-pipeline/src/session-decode/fork-decode-worker.ts:118`,`packages/addon-pipeline/src/session-decode/fork-decode-worker.ts:131`,`packages/addon-pipeline/src/pipeline-runner/index.ts:2765`,`packages/types/src/process/child-cost-registry.ts:188`]},{family:`transcode`,attribution:`measured`,unit:`one ffmpeg child per (camera, encode plan)`,perCamera:!0,wiredToday:!0,missingLink:``,evidence:[`packages/addon-pipeline/src/stream-broker/stream-broker/egress-transcode-manager.ts:960`,`packages/addon-pipeline/src/stream-broker/stream-broker/transcode-egress.ts:282`,`packages/addon-pipeline/src/stream-broker/stream-broker/transcode-egress.ts:324`,`packages/types/src/ffmpeg/sharing-key.ts:139`]},{family:`recording`,attribution:`measured`,unit:`one passthrough ffmpeg per (camera, profile)`,perCamera:!0,wiredToday:!0,missingLink:``,evidence:[`packages/addon-pipeline/src/recorder/addon/segment-writer.ts:33`,`packages/addon-pipeline/src/recorder/addon/segment-writer.ts:217`,`packages/addon-pipeline/src/recorder/addon/segment-writer.ts:279`,`packages/addon-pipeline/src/recorder/addon/recording-controller.ts:1710`]},{family:`detection`,attribution:`accounted`,unit:`a SHARED inference pool per (node, runtime, device) — no per-camera process`,perCamera:!1,wiredToday:!0,missingLink:"Nothing is missing for COUNTING — per-camera inference milliseconds, processed/shed frames and bytes-to-pool are already accumulated. What is missing is any basis for CPU seconds: `deviceId` reaches the pool as a diagnostic label and selects nothing, so cost can only ever be apportioned, never measured. Since 2026-08-27 the pool DECLARES this itself, contributing `deviceId: null` + `attribution: unattributable` rather than leaving an observer to infer it — the renunciation is data, and it is still refused by the chart gate.",evidence:[`packages/addon-pipeline/src/detection-pipeline/provider.ts:540`,`packages/addon-pipeline/src/detection-pipeline/engine/shared-inference-pool.ts:413`,`packages/types/src/interfaces/inference-engine.ts:24`,`packages/addon-pipeline/src/pipeline-runner/timing-sampler.ts:63`,`packages/addon-pipeline/src/pipeline-runner/runner.ts:353`,`packages/addon-pipeline/src/pipeline-runner/runner.ts:849`,`packages/addon-pipeline/src/pipeline-runner/frame-lazy-metrics.ts:100`]},{family:`streaming`,attribution:`measured`,unit:"one StreamBroker per `${deviceId}/${camStreamId}`, with an exact RTP ring byte counter",perCamera:!0,wiredToday:!1,missingLink:"The ffmpeg-backed ingest is now reported per camera, but that is the minority path. `rtpRingBytes` — the exact figure for the in-process case — is maintained on every push and drop and is still private and absent from `getStats()`. The three `EncodedRingBuffer`s track packets and duration and have no byte accumulator at all; the only byte figure they offer is `preRollBudgetBytes`, which is a BUDGET, not an occupancy.",evidence:[`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:2895`,`packages/addon-pipeline/src/stream-broker/rtsp/ffmpeg-push-reader.ts:189`,`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:494`,`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:498`,`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:2505`,`packages/addon-pipeline/src/stream-broker/stream-broker/pre-roll.ts:269`]}];function _n(e){return e.attribution===`measured`&&e.wiredToday}function vn(){let e=new Set;for(let t of gn)_n(t)&&e.add(t.family);return e}var yn=vn();function bn(e){return!yn.has(e.role)||e.deviceId===null?!1:e.attribution===`measured`}function xn(e){return`${e.addonId}${e.role}${e.unit}${e.pid??`-`}`}function Sn(){return{cpuSeconds:0,cpuKnown:!0,rssBytes:0,rssKnown:!0,unitCount:0,roles:new Set}}function Cn(e,t,n){if(t.cpuSeconds===void 0)return null;if(e===void 0)return t.startedAtMs===void 0||t.startedAtMs<n?null:t.cpuSeconds;if(e.cpuSeconds===void 0||e.startedAtMs===void 0||t.startedAtMs===void 0||e.startedAtMs!==t.startedAtMs)return null;let r=t.cpuSeconds-e.cpuSeconds;return r<0?null:r}function wn(e){return Math.round(e*10)/10}function Tn(e,t){let n=t.atMs-e.atMs;if(n<=0)return[];let r=n/1e3,i=new Map;for(let t of e.entries)bn(t)&&i.set(xn(t),t);let a=new Map,o=new Set;for(let n of t.entries){if(!bn(n)||n.deviceId===null)continue;let t=xn(n);o.add(t);let r=a.get(n.deviceId)??Sn();r.unitCount+=1,r.roles.add(n.role);let s=Cn(i.get(t),n,e.atMs);s===null?r.cpuKnown=!1:r.cpuSeconds+=s,n.rssBytes===void 0?r.rssKnown=!1:r.rssBytes+=n.rssBytes,a.set(n.deviceId,r)}for(let[e,t]of i){if(o.has(e)||t.deviceId===null)continue;let n=a.get(t.deviceId);n!==void 0&&(n.cpuKnown=!1)}return[...a.entries()].map(([e,n])=>({deviceId:e,point:{atMs:t.atMs,cpuPercent:n.cpuKnown?wn(n.cpuSeconds/r*100):null,rssBytes:n.rssKnown?n.rssBytes:null,unitCount:n.unitCount,roles:[...n.roles].toSorted()}}))}function En(e,t){if(t.length===0)return e;let n=new Map(e);for(let e of t){let t=n.get(e.deviceId),r=t?.points.at(-1);if(r!==void 0&&e.point.atMs<=r.atMs)continue;let i=[...t?.points??[],e.point];n.set(e.deviceId,{deviceId:e.deviceId,points:i.slice(Math.max(0,i.length-720))})}return n}function Dn(e){let t=e=>{for(let t=e.points.length-1;t>=0;t--){let n=e.points[t]?.cpuPercent;if(n!=null)return n}return-1};return[...e.values()].toSorted((e,n)=>{let r=t(n)-t(e);return r===0?e.deviceId-n.deviceId:r})}function On(e){let t=e.indexOf(`@`);return t===-1?{addonId:e,nodeId:null}:{addonId:e.slice(0,t),nodeId:e.slice(t+1)}}function kn(e,t){let n=On(e);return n.nodeId===null?t.isHub:n.nodeId===t.nodeId}function An(e,t){return e.filter(e=>kn(e.addonId,t))}s();function jn(e){let n=B(`metrics.node-processes-snapshot`,t=>t.nodeId===e.nodeId),r=ue(void 0,{staleTime:1/0,refetchOnWindowFocus:!1}),[i,s]=o(new Map),c=t(null),l=t(r.refetch);l.current=r.refetch;let u=n?.timestamp;a(()=>{u!==void 0&&l.current()},[u]),a(()=>{s(new Map),c.current=null},[e.nodeId,e.isHub]);let d=r.data,f=r.dataUpdatedAt;a(()=>{if(d===void 0||f===0)return;let t={atMs:f,entries:An(d,e)},n=c.current;if(c.current=t,n===null)return;let r=Tn(n,t);r.length!==0&&s(e=>En(e,r))},[d,f,e.nodeId,e.isHub]);let p=d===void 0?[]:An(d,e),m=n?.processes,h=hn(p,m);return{series:Dn(i),unclaimed:h.find(e=>e.kind===`unclaimed`)??null,loading:r.isPending,error:r.error===null?null:r.error.message}}function Mn(e){let t=new Map;for(let n of e){let e=n.name?.trim();e===void 0||e===``||t.set(n.id,e)}return t}var Nn=25,Pn=64*1024*1024,Fn=1e4;function In({scope:t,cadenceMs:n}){let{t:r}=q(),a=jn(t),{data:o=[]}=ce({isCamera:!0,projection:`slim`}),s=Mn(o),c=We(n??Fn);return e(`section`,{className:`space-y-3`,children:[a.error!==null&&e(`div`,{className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[i(L,{className:`h-3 w-3 mt-0.5 shrink-0`}),i(`span`,{children:r(`cameraLoad.readFailed`,`Could not read the load contributions: {{error}}. This is a failed read, NOT an idle cluster.`,{error:a.error})})]}),i(Rn,{unclaimed:a.unclaimed}),a.series.length===0&&a.error===null&&i(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:a.loading?r(`cameraLoad.loading`,`Reading what the addons report…`):r(`cameraLoad.waitingWindow`,`No per-camera window yet.`)}),i(`div`,{className:`space-y-3`,children:a.series.map(t=>e(`div`,{className:`rounded-lg border border-border p-3`,children:[e(`div`,{className:`flex items-baseline justify-between gap-2 mb-2`,children:[i(Ln,{deviceId:t.deviceId,name:s.get(t.deviceId)}),i(`span`,{className:`text-[10px] text-foreground-subtle`,children:r(`cameraLoad.unitCount`,`{{count}} unit(s): {{roles}}`,{count:t.points.at(-1)?.unitCount??0,roles:(t.points.at(-1)?.roles??[]).join(`, `)})})]}),e(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[i(Q,{title:r(`cameraLoad.cpuTitle`,`CPU % of one core (delta)`),points:t.points.map(e=>({atMs:e.atMs,value:e.cpuPercent})),formatValue:e=>`${e.toFixed(1)}%`,axisFloor:Nn,gapMs:c,emptyMessage:r(`cameraLoad.cpuUnavailable`,`No measurable window yet.`)}),i(Q,{title:r(`cameraLoad.memoryTitle`,`Memory RSS`),points:t.points.map(e=>({atMs:e.atMs,value:e.rssBytes})),formatValue:J,axisFloor:Pn,axisScale:`bytes`,gapMs:c,emptyMessage:r(`cameraLoad.memoryUnavailable`,`No memory reported.`)})]})]},t.deviceId))})]})}function Ln({deviceId:t,name:n}){let{t:r}=q();return n===void 0?i(`span`,{className:`text-xs font-medium text-foreground`,children:r(`cameraLoad.deviceLabel`,`Camera {{deviceId}}`,{deviceId:t})}):e(`span`,{className:`flex items-baseline gap-1.5 min-w-0`,children:[i(`span`,{className:`text-xs font-medium text-foreground truncate`,children:n}),e(`span`,{className:`shrink-0 text-[10px] font-mono text-foreground-subtle`,children:[`#`,t]})]})}function Rn({unclaimed:e}){let{t}=q();return e===null||e.unitCount===0?null:i(`div`,{className:`flex items-center gap-2`,children:i(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full bg-warning/10 text-warning font-medium tabular-nums`,children:t(`cameraLoad.unclaimedBadge`,`{{count}} unclaimed · {{rss}}`,{count:e.unitCount,rss:e.rssBytes===null?`—`:J(e.rssBytes)})})})}s();var zn=256*1024*1024,Bn=1e4;function Vn({nodeId:r,isHub:a}){let s=t(null);pe(s);let{t:c}=q(),{series:l,sampleCount:u,threadSplitAvailable:d,loadingRetained:f,bucketMs:p,cadenceMs:m}=dn(r),[h,g]=o(``),[_,v]=o(new Set),[y,b]=o(an),x=e=>e.key===`__root__`?c(`clusterLoad.bucketRoot`,`Node supervisor`):e.key===`__unattributed__`?c(`clusterLoad.bucketUnattributed`,`Unattributed processes`):e.key,S=We(p??m??Bn),C=n(()=>un(l,{search:h,selectedKeys:_,sort:y},x),[l,h,_,y]),w=e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return e(`div`,{className:`space-y-4`,children:[i(Hn,{bucketMs:p,cadenceMs:m}),!d&&u>0&&e(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/40 bg-warning/5 px-3 py-2 text-[11px] text-warning`,children:[i(L,{className:`h-3 w-3 mt-0.5 shrink-0`}),i(`span`,{children:c(`clusterLoad.noThreadSplit`,`No thread-level CPU split on this node — /proc/<pid>/task is Linux-only, and the first sample after a restart has no window to measure. CPU below falls back to the ps lifetime AVERAGE, which is not a rate.`)})]}),u===0&&i(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:f?c(`clusterLoad.loadingRetained`,`Reading the retained series from this node…`):c(`clusterLoad.waitingFirstSample`,`No retained samples for this node — waiting for the next snapshot (up to 20s). The chart needs two to draw a rate.`)}),l.length>0&&e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(`label`,{className:`relative flex-1 min-w-[160px]`,children:[i(M,{className:`pointer-events-none absolute left-2 top-1/2 h-3 w-3 -translate-y-1/2 text-foreground-subtle`}),i(`input`,{ref:s,type:`search`,value:h,onChange:e=>g(e.target.value),placeholder:c(`clusterLoad.searchPlaceholder`,`Find a runner…`),"aria-label":c(`clusterLoad.searchLabel`,`Find a runner`),className:`w-full rounded border border-border bg-background py-1 pl-7 pr-2 text-[11px] text-foreground placeholder:text-foreground-subtle`})]}),i(Un,{sort:y,onChange:b})]}),e(`div`,{className:`flex flex-wrap items-center gap-1`,children:[l.map(e=>{let t=_.has(e.key);return i(`button`,{type:`button`,"aria-pressed":t,onClick:()=>w(e.key),className:`rounded-full border px-2 py-0.5 text-[10px] transition-colors ${t?`border-primary bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground`}`,children:x(e)},e.key)}),_.size>0&&e(`button`,{type:`button`,onClick:()=>v(new Set),className:`inline-flex items-center gap-1 rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground`,children:[i(T,{className:`h-2.5 w-2.5`}),c(`clusterLoad.clearFilter`,`All runners`)]})]})]}),l.length>0&&C.length===0&&i(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:c(`clusterLoad.noMatches`,`No runner matches this search on {{count}} present. The node is reporting — the filter is hiding them.`,{count:l.length})}),i(`div`,{className:`space-y-3`,children:C.map(t=>e(`div`,{className:`rounded-lg border border-border p-3`,children:[e(`div`,{className:`flex items-baseline justify-between gap-2 mb-2`,children:[i(`span`,{className:`text-xs font-medium text-foreground`,children:x(t)}),i(`span`,{className:`text-[10px] text-foreground-subtle`,children:c(`clusterLoad.processCount`,`{{count}} process(es)`,{count:t.points.at(-1)?.processCount??0})})]}),e(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[i(Jt,{title:d?c(`clusterLoad.cpuTitle`,`CPU % of one core`):c(`clusterLoad.cpuTitleLifetime`,`CPU % (ps lifetime average)`),mainLabel:c(`clusterLoad.seriesMain`,`Main threads`),gcLabel:c(`clusterLoad.seriesGc`,`GC / V8 helpers`),points:t.points.map(e=>({atMs:e.atMs,main:e.cpuMainPercent,gc:e.cpuGcPercent})),formatValue:e=>`${e.toFixed(0)}%`,gapMs:S,emptyMessage:c(`clusterLoad.cpuUnavailable`,`No thread split on this node. Lifetime average: {{avg}}%`,{avg:(t.points.at(-1)?.cpuLifetimePercent??0).toFixed(1)})}),i(Q,{title:c(`clusterLoad.memoryTitle`,`Memory RSS`),points:t.points.map(e=>({atMs:e.atMs,value:e.memoryRssBytes})),formatValue:J,axisFloor:zn,axisScale:`bytes`,gapMs:S,emptyMessage:c(`clusterLoad.memoryUnavailable`,`No memory samples yet.`)})]})]},t.key))}),i(In,{scope:{nodeId:r,isHub:a},cadenceMs:m})]})}function Hn({bucketMs:e,cadenceMs:t}){let{t:n}=q();return e===null?null:i(`p`,{className:`text-[10px] text-foreground-subtle`,children:t!==null&&e>t?n(`clusterLoad.captionBucket`,`1 point = {{bucket}}s (bucket MAXIMUM, not a mean)`,{bucket:Math.round(e/1e3)}):n(`clusterLoad.captionRaw`,`1 point = 1 snapshot`)})}function Un({sort:t,onChange:n}){let{t:r}=q(),a=[{key:`cpu`,label:r(`clusterLoad.sortCpu`,`CPU`)},{key:`memory`,label:r(`clusterLoad.sortMemory`,`Memory`)},{key:`name`,label:r(`clusterLoad.sortName`,`Name`)}];return e(`div`,{className:`flex items-center gap-1`,children:[i(`span`,{className:`text-[10px] text-foreground-subtle`,children:r(`clusterLoad.sortBy`,`Sort by`)}),a.map(r=>{let i=t.key===r.key;return e(`button`,{type:`button`,"aria-pressed":i,onClick:()=>n(i?{key:r.key,dir:t.dir===`desc`?`asc`:`desc`}:{key:r.key,dir:r.key===`name`?`asc`:`desc`}),className:`rounded border px-1.5 py-0.5 text-[10px] transition-colors ${i?`border-primary bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground`}`,children:[r.label,i&&(t.dir===`desc`?` ↓`:` ↑`)]},r.key)})]})}var Wn=`No per-node settings on this node. Every other setting these addons expose is one value for the whole cluster — edit those in System → Settings, not here.`;function Gn({nodeId:e,addonIds:t}){let{t:n}=q();return t.length===0?i(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:n(`cluster.nodeDetailSettingsTab.noAddonsOnThisNode`,`No addons on this node`)}):i(`div`,{className:`w-full py-2`,children:i(Xe,{nodeId:e,addonIds:t,level:`global`,fieldScope:`perNode`,emptyMessage:Wn,selfTabbed:!0})})}s();function Kn({nodeId:e,addons:t}){let{t:r}=q(),a=c(),{data:o,isLoading:s}=Le({nodeId:e}),l=n(()=>{let e=new Map;for(let n of t)for(let t of n.capabilities){let r=e.get(t)??[];r.push(n.id),e.set(t,r)}return[...e.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({capName:e,providers:t}))},[t]),u=Ue({onSuccess:()=>{a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return l.length===0?i(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:r(`cluster.nodeDetailCapabilitiesTab.noCapabilitiesOnThisNode`,`No capabilities on this node`)}):i(V,{columns:[{key:`capName`,header:r(`cluster.nodeDetailCapabilitiesTab.capability`,`Capability`),width:`w-1/2`,sortValue:e=>e.capName,render:e=>i(`span`,{className:`font-medium`,children:e.capName})},{key:`provider`,header:r(`cluster.nodeDetailCapabilitiesTab.boundProvider`,`Bound provider`),render:t=>{let n=o?.[t.capName]??t.providers[0]??``,a=t.providers.length===1;return i(`select`,{value:n,onChange:n=>u.mutate({nodeId:e,capName:t.capName,addonId:n.target.value}),disabled:a||u.isPending||s,className:`w-full rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-60`,title:a?r(`cluster.nodeDetailCapabilitiesTab.onlyOneProviderInstalledChoice`,`Only one provider installed — choice becomes available once a second addon registers this capability`):void 0,children:t.providers.map(e=>i(`option`,{value:e,children:e},e))})}}],rows:l,rowKey:e=>e.capName,minWidthPx:520,maxBodyHeight:se})}s();function qn(e){if(e==null)return`—`;let t=Math.floor(e/1e3),n=Math.floor(t/86400),r=Math.floor(t%86400/3600),i=Math.floor(t%3600/60);return n>0?`${n}d ${r}h ${i}m`:r>0?`${r}h ${i}m`:`${i}m`}function Jn(t){let{t:n}=q(),[r,a]=o(!1),[s,l]=o(t.name),u=c(),d=me({onSuccess:()=>{u.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),f=(t.localIps??[]).filter(e=>!e.includes(`:`)),p=(t.localIps??[]).filter(e=>e.includes(`:`)),m=async()=>{if(!s.trim()||s===t.name){a(!1);return}try{await d.mutateAsync({nodeId:t.nodeId,name:s.trim()}),a(!1)}catch(e){console.error(`Rename failed:`,e)}},h=[[`Node ID`,i(`span`,{className:`font-mono text-xs`,children:t.nodeId})],[`Display Name`,r?e(`div`,{className:`flex items-center gap-1.5`,children:[i(`input`,{type:`text`,className:`flex-1 px-2 py-0.5 text-xs border border-border rounded bg-background focus:outline-none focus:ring-1 focus:ring-primary`,value:s,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&a(!1)},disabled:d.isPending,autoFocus:!0}),i(`button`,{onClick:()=>void m(),disabled:d.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:n(`common.save`,`Save`),children:i(y,{className:`h-3.5 w-3.5`})}),i(`button`,{onClick:()=>a(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:n(`common.cancel`,`Cancel`),children:i(T,{className:`h-3.5 w-3.5`})})]}):e(`div`,{className:`flex items-center gap-1.5`,children:[i(`span`,{className:`text-xs`,children:t.name}),!t.isHub&&i(`button`,{onClick:()=>{l(t.name),a(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:n(`cluster.nodeInfoTab.rename`,`Rename`),children:i(x,{className:`h-3 w-3`})})]})],[`Hostname`,i(`span`,{className:`text-xs`,children:t.hostname})],[`Role`,t.isHub?i(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:n(`cluster.nodeInfoTab.hub`,`Hub`)}):i(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:n(`cluster.nodeInfoTab.agent`,`Agent`)})],[`Root Package`,t.rootPackage?e(`span`,{className:`font-mono text-xs`,children:[t.rootPackage.name,`@`,t.rootPackage.version]}):i(`span`,{className:`text-xs text-muted-foreground`,children:`—`})],[`Platform`,e(`span`,{className:`text-xs`,children:[t.platform,` / `,t.arch]})],[`CPU`,e(`span`,{className:`text-xs`,children:[t.cpuModel??`—`,` (`,n(`cluster.nodeInfoTab.cores`,{count:t.cpuCores}),`)`]})],[`Memory`,i(`span`,{className:`text-xs`,children:t.memoryMB>0?n(`cluster.nodeInfoTab.gb`,`{{value1}} GB`,{value1:(t.memoryMB/1024).toFixed(1)}):`—`})],[`Uptime`,i(`span`,{className:`text-xs`,children:qn(t.uptime)})],[n(`cluster.nodeInfoTab.installedRuntimes`,`Installed runtimes`),t.engines.length>0?i(`div`,{className:`flex flex-wrap gap-1`,title:n(`cluster.nodeInfoTab.installedRuntimesHint`,`Inference runtimes installed on this node. Its live inference devices are on Pipeline → Load balancing.`),children:t.engines.map(e=>i(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium`,children:e},e))}):i(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return f.length>0&&h.push([`IPv4`,i(`div`,{className:`flex flex-wrap gap-1.5`,children:f.map((e,t)=>i(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),p.length>0&&h.push([`IPv6`,i(`div`,{className:`flex flex-wrap gap-1.5`,children:p.map((e,t)=>i(`span`,{className:`font-mono text-[10px] px-1.5 py-0.5 rounded bg-muted truncate max-w-[280px]`,title:e,children:e},`${e}-${t}`))})]),i(`div`,{className:`py-2`,children:i(`table`,{className:`w-full text-sm`,children:i(`tbody`,{children:h.map(([t,n],r)=>e(`tr`,{className:r%2==0?`bg-muted/20`:``,children:[i(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:t}),i(`td`,{className:`py-1.5 px-2`,children:n})]},t))})})})}s();function Yn({nodeId:t,value:n,detectedHosts:r,status:s,errorMessage:c,onCommit:l}){let{t:u}=q(),[d,f]=o(n??``);a(()=>{f(n??``)},[n]);let p=r[0],m=p===void 0?`auto-detect`:`auto: ${p}`,h=s===`pending`,g=d.trim(),_=g!==(n??``),v=_&&!h,b=()=>{v&&l(t,g.length>0?g:null)};return e(`div`,{className:`flex items-center gap-1.5`,children:[i(W,{"aria-label":u(`placementBoard.reachableHostInput.reachableHostFor`,`Reachable host for {{nodeId}}`,{nodeId:t}),type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:m,value:d,disabled:h,onChange:e=>f(e.target.value),onBlur:b,onKeyDown:e=>{e.key===`Enter`&&b(),e.key===`Escape`&&f(n??``)},className:`w-36`}),e(U,{variant:`outline`,size:`sm`,onClick:b,disabled:!v,"aria-label":u(`placementBoard.reachableHostInput.saveReachableHostFor`,`Save reachable host for {{nodeId}}`,{nodeId:t}),title:u(`placementBoard.reachableHostInput.saveReachableHost`,`Save reachable host`),children:[h?i(w,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):i(y,{className:`h-3 w-3`,"aria-hidden":`true`}),u(`common.save`,`Save`)]}),!_&&!h&&s===`success`&&i(y,{className:`h-3.5 w-3.5 shrink-0 text-success`,"aria-label":u(`placementBoard.reachableHostInput.saved`,`Saved`),role:`img`}),s===`error`&&i(`span`,{title:c??u(`placementBoard.reachableHostInput.failedToSaveReachableHost`,`Failed to save reachable host`),children:i(P,{className:`h-3.5 w-3.5 shrink-0 text-danger`,"aria-label":c??u(`placementBoard.reachableHostInput.failedToSaveReachableHost`,`Failed to save reachable host`),role:`img`})})]})}s();function Xn(e){let t=ne.safeParse(Ze(e,`color`));return t.success?t.data:null}function Zn(e,t){return t.variables?.agentNodeId===e?t.isPending?`pending`:t.isError?`error`:t.isSuccess?`success`:`idle`:`idle`}function Qn({nodeId:t,detectedHosts:r}){let{t:a}=q(),o=c(),s=Ae(void 0),l=Ve({onSuccess:()=>Qe(o)}),u=Ve({onSuccess:()=>Qe(o)}),d=n(()=>s.data?.find(e=>e.nodeId===t)?.settings,[s.data,t]),f=Xn(d)??(s.isLoading?null:ee(t)),p=$e(d,`reachableHost`),m=Zn(t,l),h=m===`error`?et(l.error):null,g=r.filter(e=>!e.includes(`:`)),_=e=>{e!==f&&u.mutate({agentNodeId:t,color:e})};return e(`div`,{className:`rounded-lg border border-border bg-surface/40 divide-y divide-border px-3`,children:[i(Ge,{label:a(`nodes.general.nodeColour`,`Node colour`),children:i(`div`,{role:`group`,"aria-label":a(`nodes.general.nodeColourGroup`,`Node colour`),className:`flex flex-wrap gap-2`,children:R.map(e=>{let t=f===e;return i(U,{type:`button`,role:`radio`,"aria-checked":t,"aria-label":e,variant:`outline`,size:`sm`,disabled:s.isLoading||u.isPending,title:e,onClick:()=>_(e),className:`h-6 w-6 min-w-6 shrink-0 rounded-full border-0 p-0 ${Oe(e)} ${t?`ring-2 ring-primary ring-offset-2 ring-offset-background`:`opacity-80 hover:opacity-100`}`,children:i(`span`,{className:`sr-only`,children:e})},e)})})}),i(Ge,{label:a(`nodes.general.reachableHost`,`Reachable host`),children:i(Yn,{nodeId:t,value:p,detectedHosts:g,status:m,errorMessage:h,onCommit:(e,t)=>{l.mutate({agentNodeId:e,reachableHost:t})}})})]})}s();var $n=[[`serverManagement`,`getServerPackageStatus`]];function er({label:e,tone:t}){return i(`span`,{className:`inline-flex items-center rounded px-2 py-0.5 text-[11px] font-medium ${{neutral:`bg-surface-muted text-foreground-subtle`,ok:`bg-success/15 text-success`,info:`bg-info/15 text-info`,warn:`bg-warning/15 text-warning`,error:`bg-danger/15 text-danger`}[t]}`,children:e})}function $({label:t,value:n}){return e(`div`,{className:`flex items-center justify-between gap-4 text-sm`,children:[i(`span`,{className:`text-foreground-subtle`,children:t}),i(`span`,{className:`font-mono text-foreground`,children:n??`—`})]})}function tr({runningVersion:t,latestVersion:n,seedVersion:r,nodeRuntimeVersion:a,labelRunning:o,labelLatest:s,labelSeed:c,labelRuntime:l}){return i(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-sm`,children:[{key:`running`,label:o,value:t},{key:`latest`,label:s,value:n},{key:`seed`,label:c,value:r},{key:`runtime`,label:l,value:a}].map(({key:t,label:n,value:r})=>e(`span`,{className:`inline-flex items-baseline gap-1`,children:[i(`span`,{className:`text-foreground-subtle`,children:n}),i(`span`,{className:`font-mono text-foreground`,children:r??`—`})]},t))})}var nr={ok:`border-success/40 bg-success/10 text-success`,warn:`border-warning/40 bg-warning/10 text-warning`,error:`border-danger/40 bg-danger/10 text-danger`};function rr(e){return e.outcome===`failed`?`error`:(e.outcome,e.accepted?`ok`:`warn`)}function ir(e,t){let n=t instanceof Error?t.message:String(t);return`${e(`serverManagement.outcomeDropped`,`The connection dropped and the result could not be confirmed. The node may be restarting — re-check the version above.`)} — ${n}`}function ar({node:t}){let{t:n}=q(),a=c(),s=j(),[l,u]=o(!1),[d,f]=o(null),m=t.isHub?void 0:{nodeId:t.id},h=De(m,{refetchInterval:1e4,enabled:t.isOnline,retry:1}),g=h.data??null,_=r(()=>{a.invalidateQueries({queryKey:$n})},[a]),v=Fe({onSettled:_}),y=Me({onSettled:_}),b=_e({onSettled:_}),x=r(async()=>{if(g?.latestVersion==null){f({tone:`warn`,text:n(`serverManagement.outcomeNoTarget`,`No target version is known for this node — run "Check for update" first.`)});return}if(await s({title:n(`serverManagement.confirmUpdateTitle`,`Update node root package`),message:n(`serverManagement.confirmUpdateBody`,`Install {{pkg}}@{{version}} on "{{node}}" and restart to apply.`,{pkg:g.packageName,version:g.latestVersion,node:t.name}),confirmLabel:n(`serverManagement.confirmUpdateAction`,`Update & restart`)})){f(null);try{let e=await y.mutateAsync({version:g.latestVersion,...m});f({tone:rr(e),text:e.message}),e.restarting&&u(!0)}catch(e){f({tone:`warn`,text:ir(n,e)})}}},[y,s,t.name,m,g,n]),S=r(async()=>{if(await s({title:n(`serverManagement.confirmRestartTitle`,`Restart node`),message:n(`serverManagement.confirmRestartBody`,`Restart "{{node}}"? In-flight requests to this node are dropped.`,{node:t.name}),confirmLabel:n(`serverManagement.confirmRestartAction`,`Restart`),variant:`warning`})){f(null);try{let e=await b.mutateAsync(m);f({tone:rr(e),text:e.message}),e.restarting&&u(!0)}catch(e){f({tone:`warn`,text:ir(n,e)})}}},[s,t.name,b,m,n]),C=()=>{switch(g?.bootMode){case`data-root`:return{label:n(`serverManagement.bootDataRoot`,`runtime-updatable`),tone:`ok`};case`workspace`:return{label:n(`serverManagement.bootWorkspace`,`dev workspace`),tone:`info`};default:return{label:n(`serverManagement.bootBaked`,`baked image seed`),tone:`neutral`}}},T=()=>{if(g==null)return null;switch(g.updateState){case`checking`:return{label:n(`serverManagement.stateChecking`,`checking…`),tone:`info`};case`staging`:return{label:n(`serverManagement.stateStaging`,`updating…`),tone:`info`};case`pending-restart`:return{label:n(`serverManagement.statePending`,`restart pending`),tone:`warn`};default:return g.restartRequired===!0?{label:n(`serverManagement.stateRestartRequired`,`restart required`),tone:`warn`}:g.updateAvailable?{label:n(`serverManagement.stateUpdateAvailable`,`update available`),tone:`warn`}:{label:n(`serverManagement.stateUpToDate`,`up to date`),tone:`ok`}}},D=g?.bootMode===`workspace`,O=t.isOnline&&g!=null&&!D&&g.updateAvailable&&g.updateState===`idle`&&!y.isPending,k=t.isOnline&&g!=null&&g.updateState===`idle`&&!b.isPending,A=t.isOnline?T():null;return e(`div`,{className:`space-y-4 py-2`,children:[e(`div`,{className:`flex items-center justify-between gap-3`,children:[e(`div`,{className:`flex items-center gap-2 min-w-0`,children:[i(`span`,{className:`font-mono text-xs text-foreground-subtle truncate`,children:g?.packageName??t.rootPackage?.name??`@camstack/server`}),t.isOnline&&g!=null&&i(er,{...C()})]}),A!=null&&i(er,{...A})]}),!t.isOnline&&i($,{label:n(`serverManagement.lastReportedVersion`,`Last reported version`),value:t.rootPackage?.version??null}),t.isOnline&&h.isLoading&&e(`div`,{className:`flex items-center gap-2 text-sm text-foreground-subtle`,children:[i(w,{className:`h-4 w-4 animate-spin`}),n(`common.loading`,`Loading…`)]}),t.isOnline&&h.isError&&e(`div`,{className:`space-y-1.5`,children:[i(`p`,{className:`text-sm text-danger`,children:n(`serverManagement.loadError`,`Could not load the node root-package status.`)}),t.rootPackage!=null&&i($,{label:n(`serverManagement.lastReportedVersion`,`Last reported version`),value:t.rootPackage.version})]}),t.isOnline&&g!=null&&e(`div`,{className:`space-y-1.5`,children:[i(tr,{runningVersion:g.runningVersion,latestVersion:g.latestVersion,seedVersion:g.seedVersion,nodeRuntimeVersion:g.nodeRuntimeVersion,labelRunning:n(`serverManagement.runningVersionShort`,`Running`),labelLatest:n(`serverManagement.latestVersionShort`,`Latest`),labelSeed:n(`serverManagement.imageSeedShort`,`Seed`),labelRuntime:n(`serverManagement.nodeRuntimeVersionShort`,`Node.js`)}),g.pendingVersion!=null&&i($,{label:n(`serverManagement.pendingVersion`,`Staged (applies on restart)`),value:g.pendingVersion}),g.installedVersion!=null&&g.installedVersion!==g.runningVersion&&i($,{label:n(`serverManagement.installedVersion`,`Installed on disk (runs after restart)`),value:g.installedVersion})]}),t.isOnline&&g?.imageContract?.state===`behind-series`&&e(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs leading-relaxed text-danger`,children:[i(`p`,{className:`mb-0.5 font-semibold`,children:n(`serverManagement.imageContractDiverged`,`Container image diverges from the deployment contract`)}),i(`p`,{children:g.imageContract.message})]}),t.isOnline&&D&&i(`p`,{className:`text-xs text-foreground-subtle`,children:n(`serverManagement.workspaceNote`,`Development workspace detected — runtime updates are disabled (the dev loop resolves code from the workspace).`)}),d!=null&&i(`p`,{role:`status`,className:`rounded border px-2 py-1.5 text-xs leading-relaxed ${nr[d.tone]}`,children:d.text}),l&&e(`div`,{className:`flex items-center gap-2 text-sm text-warning`,children:[i(w,{className:`h-4 w-4 animate-spin`}),n(`serverManagement.nodeRestarting`,`The node is restarting to apply the change…`)]}),t.isOnline&&e(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[e(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:v.isPending||g?.updateState===`staging`,onClick:()=>v.mutate(m),children:[v.isPending?i(w,{className:`h-3.5 w-3.5 animate-spin`}):i(p,{className:`h-3.5 w-3.5`}),n(`serverManagement.checkForUpdate`,`Check for update`)]}),O&&e(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-2.5 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,onClick:()=>void x(),children:[y.isPending?i(w,{className:`h-3.5 w-3.5 animate-spin`}):i(E,{className:`h-3.5 w-3.5`}),n(`serverManagement.updateTo`,`Update to {{version}}`,{version:g?.latestVersion??``})]}),e(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:!k,onClick:()=>void S(),children:[b.isPending?i(w,{className:`h-3.5 w-3.5 animate-spin`}):i(N,{className:`h-3.5 w-3.5`}),n(`serverManagement.restart`,`Restart`)]})]}),t.isOnline&&g?.lastCheckedAtMs!=null&&e(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[i(re,{className:`h-3 w-3`}),n(`serverManagement.lastChecked`,`Last checked: {{when}}`,{when:new Date(g.lastCheckedAtMs).toLocaleString()})]})]})}s();function or(e){if(typeof e!=`object`||!e||Array.isArray(e))return null;let t=Reflect.get(e,`reachableHost`);return typeof t==`string`&&t.length>0?t:null}function sr({node:t}){let{t:a}=q(),s=C(),u=c(),d=j(),[f,p]=o(!1),[m,h]=o(`info`),[v,y]=o(!1),[b,x]=o(null),S=t.processes??[],w=t.addons.map(e=>e.id),T=Ae(void 0),E=n(()=>{let e=T.data?.find(e=>e.nodeId===t.id);return or(e?.settings)},[T.data,t.id]),[D,k]=o(!1),[A,M]=o(null),[N,P]=o(null),F=r(async()=>{if(D||t.isHub)return;let e=Mt(t.localIps??[],E);if(e===null){M(`No LAN IPv4 on this node — open its :4444 URL by hand.`),P(null);return}let n=Ft();k(!0),M(null),P(null);try{let r=Ot(await s.trpcClient.addons.custom.mutate({addonId:`system-config`,action:`mintAgentUiUnlockTicket`,input:{nodeId:t.id,dashboardBaseUrl:Nt(e)}})),i=r===null?null:r.dashboardUrl??Pt(e,r.ticket);if(i===null){n?.close(),M(`Hub did not return an unlock ticket.`);return}It(n,i)||(P(i),M(`Browser blocked the new tab — click the link below (or allow popups for this site).`))}catch(e){n?.close(),M(e instanceof Error?e.message:String(e))}finally{k(!1)}},[t.id,t.isHub,t.localIps,D,E,s.trpcClient]),I=async()=>{if(!v){y(!0),x(null);try{await s.trpcClient.pipelineOrchestrator.removeAgentSettings.mutate({agentNodeId:t.id}).catch(()=>void 0);let e=await s.trpcClient.clusterNodes.forgetNode.mutate({nodeId:t.id});x({tone:e.stillListed?`warn`:`ok`,text:e.message}),e.stillListed||u.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}catch(e){x({tone:`warn`,text:a(`cluster.nodeCard.forgetFailed`,{error:e instanceof Error?e.message:String(e)})})}finally{y(!1)}}},L=async()=>{if(!f&&await d({title:a(`cluster.nodeCard.unpair`,`Unpair {{name}}`,{name:t.name}),message:a(`cluster.nodeCard.unpairItDisconnectsAndMust`,`Unpair {{name}}? It disconnects and must be paired again.`,{name:t.name}),confirmLabel:a(`cluster.nodeCard.unpair2`,`Unpair`),variant:`danger`})){p(!0),x(null);try{let e=await s.trpcClient.agentPairing.unpairAgent.mutate({nodeId:t.id});x({tone:e.agentNotified?`ok`:`warn`,text:`${e.nodeId}: ${e.next}${e.agentNotified?``:` The agent could not be told; forget the hub on its own page.`}`}),u.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}catch(e){x({tone:`warn`,text:a(`cluster.nodeCard.unpairFailed`,{error:e instanceof Error?e.message:String(e)})})}finally{p(!1)}}},R=t.isHub?null:e(U,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void L(),disabled:f,title:a(`cluster.nodeCard.unpairThisNodeRevokesIts`,`Unpair this node — revokes its certificates; it must be paired again to rejoin`),children:[i(ae,{className:`h-3 w-3`,"aria-hidden":!0}),f?a(`cluster.nodeCard.unpairing`,`Unpairing…`):a(`cluster.nodeCard.unpair2`,`Unpair`)]});return t.isOnline?e(`div`,{className:`border border-border rounded-xl`,children:[e(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2 px-4 py-3 bg-muted/30 border-b border-border rounded-t-xl`,children:[e(`div`,{className:`flex min-w-0 flex-1 basis-full items-center gap-x-2 gap-y-1 sm:basis-auto sm:flex-initial`,children:[i(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success shrink-0`}),i(Lt,{node:t}),e(`span`,{className:`text-xs text-muted-foreground min-w-0 truncate`,children:[t.cpuModel??t.platform,` ·`,` `,t.memoryMB>0?a(`cluster.nodeCard.gb`,`{{value1}}GB`,{value1:Math.round(t.memoryMB/1024)}):``,` `,`· `,t.arch]})]}),t.engines.map(e=>i(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium shrink-0`,title:a(`cluster.nodeInfoTab.installedRuntimesHint`,`Inference runtimes installed on this node. Its live inference devices are on Pipeline → Load balancing.`),children:e},e)),e(`div`,{className:`flex min-w-0 flex-wrap items-center justify-end gap-x-3 gap-y-1 text-xs text-muted-foreground w-full sm:ml-auto sm:w-auto`,children:[!t.isHub&&e(`button`,{type:`button`,onClick:()=>void F(),disabled:D,title:a(`cluster.nodeCard.openThisAgentSStatus`,`Open this agent's status dashboard (unlocks with a short-lived hub ticket)`),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-xs text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[i(_,{className:`h-3 w-3`}),D?a(`cluster.nodeCard.opening`,`Opening…`):a(`cluster.nodeCard.openDashboard`,`Open dashboard`)]}),R,e(`span`,{className:`flex items-center gap-1`,children:[i(O,{className:`h-3 w-3`}),` `,t.cpuPercent,`%`]}),e(`span`,{className:`flex items-center gap-1`,children:[i(ie,{className:`h-3 w-3`}),` `,t.memoryPercent,`%`]})]})]}),b!=null&&i(`p`,{role:`status`,className:`px-4 pt-2 text-xs ${b.tone===`ok`?`text-success`:`text-warning`}`,children:b.text}),(A!==null||N!==null)&&e(`p`,{role:`status`,className:`px-4 pt-2 text-xs text-warning`,children:[A,N!==null&&e(l,{children:[` `,i(`a`,{href:N,target:`_blank`,rel:`noreferrer`,className:`underline text-foreground`,children:a(`cluster.nodeCard.openDashboard`,`Open dashboard`)})]})]}),i(`div`,{className:`sticky top-0 z-20 flex border-b border-border px-4 bg-background overflow-x-auto`,children:[`info`,`forks`,`processes`,`load`,`settings`,`capabilities`].map(e=>i(`button`,{onClick:()=>h(e),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${m===e?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:e===`info`?a(`cluster.nodeCard.general`,`General`):e===`forks`?a(`cluster.nodeCard.forks`,`Forks ({{length}})`,{length:S.length}):e===`processes`?a(`cluster.nodeCard.processes`,`Processes`):e===`load`?a(`cluster.nodeCard.load`,`Load`):e===`settings`?a(`cluster.nodeCard.settings`,`Settings`):a(`cluster.nodeCard.capabilities`,`Capabilities`)},e))}),e(`div`,{className:`px-4 py-2`,children:[m===`info`&&e(`div`,{className:`space-y-3`,children:[i(Jn,{nodeId:t.id,name:t.name,hostname:t.hostname,platform:t.platform,arch:t.arch,cpuModel:t.cpuModel,cpuCores:t.cpuCores,memoryMB:t.memoryMB,engines:t.engines,isHub:t.isHub,uptime:t.uptime,localIps:t.localIps,rootPackage:t.rootPackage}),i(Qn,{nodeId:t.id,detectedHosts:t.localIps??[]}),i(`div`,{className:`border-t border-border pt-1`,children:i(ar,{node:{id:t.id,name:t.name,isHub:t.isHub,isOnline:t.isOnline,rootPackage:t.rootPackage??null}})})]}),m===`forks`&&i(Ht,{nodeId:t.id,processes:S}),m===`processes`&&i(Kt,{nodeId:t.id}),m===`load`&&i(Vn,{nodeId:t.id,isHub:t.isHub}),m===`settings`&&i(Gn,{nodeId:t.id,addonIds:w}),m===`capabilities`&&i(Kn,{nodeId:t.id,addons:t.addons})]})]}):e(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[e(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2 px-4 py-3 bg-muted/30`,children:[i(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive shrink-0`}),i(Lt,{node:t}),e(`span`,{className:`text-xs text-muted-foreground min-w-0 truncate`,children:[t.cpuModel??t.platform,` ·`,` `,t.memoryMB>0?a(`cluster.nodeCard.gb`,`{{value1}}GB`,{value1:Math.round(t.memoryMB/1024)}):``,` `,`· `,t.arch]}),t.engines.map(e=>i(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium`,title:a(`cluster.nodeInfoTab.installedRuntimesHint`,`Inference runtimes installed on this node. Its live inference devices are on Pipeline → Load balancing.`),children:e},e)),t.rootPackage&&e(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[t.rootPackage.name,`@`,t.rootPackage.version]}),i(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:a(`common.offline`)})]}),e(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[e(`span`,{className:`text-xs text-muted-foreground`,children:[t.lastSeen?i(`span`,{className:`mr-1`,children:a(`cluster.nodeCard.lastSeen`,{when:new Date(t.lastSeen).toLocaleString()})}):null,a(`cluster.nodeCard.addonsAssigned`,{count:t.addons.length})]}),e(`div`,{className:`flex shrink-0 items-center gap-2`,children:[R,e(`button`,{type:`button`,onClick:()=>void I(),disabled:v,title:a(`cluster.nodeCard.forgetThisNodeRemovesIts`,`Forget this node — removes its saved history and pipeline assignments`),className:`flex items-center gap-1 text-xs px-2 py-1 rounded-md border border-border text-muted-foreground hover:text-destructive hover:border-destructive/50 disabled:opacity-50 transition-colors`,children:[i(g,{className:`h-3 w-3`}),v?a(`cluster.nodeCard.forgetting`,`Forgetting…`):a(`cluster.nodeCard.forgetNode`,`Forget node`)]})]})]}),b!=null&&i(`p`,{role:`status`,className:`px-4 pb-3 text-xs leading-relaxed ${b.tone===`ok`?`text-success`:`text-warning`}`,children:b.text})]})}var cr=3,lr=7e3;function ur(e){return[...e].sort((e,t)=>e.isHub===t.isHub?0:e.isHub?1:-1)}function dr(e){return e.isHub?{}:{nodeId:e.id}}function fr(e){return e.updateState===`staging`||e.updateState===`pending-restart`||e.pendingVersion!==null?!0:!e.updateAvailable}async function pr(e,t){let n=dr(e),r=K.t(`helpers.clusterUpdateAll.noAnswer`);for(let i=1;i<=cr;i+=1)try{let r=await t.readStatus(n);return fr(r)?{nodeId:e.id,nodeName:e.name,outcome:`applied`,detail:K.t(`helpers.clusterUpdateAll.landed`,{state:r.updateState,version:r.runningVersion??K.t(`helpers.clusterUpdateAll.unknown`)})}:{nodeId:e.id,nodeName:e.name,outcome:`failed`,detail:K.t(`helpers.clusterUpdateAll.unchanged`,{version:r.runningVersion??K.t(`helpers.clusterUpdateAll.unknown`)})}}catch(e){r=e instanceof Error?e.message:String(e),i<cr&&await t.wait(lr)}return{nodeId:e.id,nodeName:e.name,outcome:`unconfirmed`,detail:K.t(`helpers.clusterUpdateAll.unconfirmed`,{attempts:cr,error:r})}}function mr(e){return e.accepted?`applied`:e.outcome===`failed`?`failed`:`refused`}async function hr(e,t){let n=[];for(let r of ur(e))try{let e=await t.apply(dr(r));n.push({nodeId:r.id,nodeName:r.name,outcome:mr(e),detail:e.message})}catch{n.push(await pr(r,t))}return n}s();function gr(){let{nodes:e,isLoading:t}=de(),r=n(()=>e??[],[e]);return{nodes:r,isLoading:t&&r.length===0}}var _r={applied:`border-success/40 bg-success/10 text-success`,refused:`border-warning/40 bg-warning/10 text-warning`,failed:`border-danger/40 bg-danger/10 text-danger`,unconfirmed:`border-warning/40 bg-warning/10 text-warning`};function vr(){let{t}=q(),s=j(),{nodes:c,isLoading:u}=gr(),[d,f]=Je(),{selection:p,selectNode:m}=nt(c),g=p.node,_=n(()=>c.filter(e=>e.isOnline),[c]),v=_.length,y=c.filter(e=>!e.isOnline).length,b=Me(),x=C(),[S,T]=o(!1),[D,O]=o([]),k=d.get(`unlockNode`),A=d.get(`returnTo`),[M,N]=o(null);a(()=>{if(k===null||A===null)return;let e=!1;return(async()=>{try{let t=await x.trpcClient.addons.custom.mutate({addonId:`system-config`,action:`mintAgentUiUnlockTicket`,input:{nodeId:k,dashboardBaseUrl:A}});if(e)return;let n=Ot(t),r=n===null?null:n.dashboardUrl??(()=>{let e=new URL(A);return e.searchParams.set(`ticket`,n.ticket),e.toString()})();if(r===null){N(`Could not mint an unlock ticket.`);return}let i=new URLSearchParams(d);i.delete(`unlockNode`),i.delete(`returnTo`),f(i,{replace:!0}),window.location.assign(r)}catch(t){e||N(t instanceof Error?t.message:String(t))}})(),()=>{e=!0}},[k,A,d,f,x.trpcClient]);let P=r(async()=>{let e=_.map(e=>({id:e.id,name:e.name,isHub:e.isHub}));if(await s({title:t(`serverManagement.confirmUpdateAllTitle`,`Update all nodes`),message:t(`serverManagement.confirmUpdateAllBody`,`Update and restart every online node, agents first, hub last. Up-to-date nodes are skipped; this page reconnects when the hub comes back.`),confirmLabel:t(`serverManagement.confirmUpdateAllAction`,`Update all & restart`),variant:`warning`})){T(!0),O([]);try{O(await hr(e,{apply:e=>b.mutateAsync(e),readStatus:e=>x.trpcClient.serverManagement.getServerPackageStatus.query(e),wait:e=>new Promise(t=>setTimeout(t,e))}))}finally{T(!1)}}},[b,s,_,x,t]);return e(Ye,{icon:h,title:t(`nav.nodes`,`Nodes`),subtitle:t(`cluster.subtitle`,`One node at a time — topology and packages. Agents join by pairing (certificate, no shared secret).`),actions:e(l,{children:[v>0&&i(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-xs text-success`,children:t(`common.onlineCount`,{count:v})}),y>0&&i(`span`,{className:`rounded-full bg-destructive/10 px-2 py-0.5 text-xs text-destructive`,children:t(`common.offlineCount`,{count:y})}),v>1&&e(U,{type:`button`,size:`sm`,disabled:S,title:t(`serverManagement.updateAllHint`,`Sequenced agents-first, hub-last — up-to-date nodes are skipped.`),onClick:()=>void P(),children:[S?i(w,{className:`h-3.5 w-3.5 animate-spin`}):i(E,{className:`h-3.5 w-3.5`}),t(`serverManagement.updateAll`,`Update all nodes`)]})]}),children:[D.length>0&&i(`ul`,{"aria-label":`update-all-report`,className:`flex flex-col gap-1 text-xs`,children:D.map(t=>e(`li`,{"data-outcome":t.outcome,className:`rounded border px-2 py-1 ${_r[t.outcome]}`,children:[i(`span`,{className:`font-medium`,children:t.nodeName}),i(`span`,{className:`mx-1 uppercase tracking-wide`,children:t.outcome}),i(`span`,{className:`opacity-80`,children:t.detail})]},t.nodeId))}),M!==null&&e(`p`,{role:`alert`,className:`rounded border border-warning/40 bg-warning/10 px-3 py-2 text-xs text-warning`,children:[t(`system.cluster.unlockFromAgentFailed`,`Unlock from agent failed:`),` `,M]}),i(Et,{onOpenNode:m}),u?i(`div`,{className:`flex items-center justify-center py-12 text-muted-foreground`,children:t(`system.cluster.loadingClusterTopology`,`Loading cluster topology...`)}):g===null?i(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-xs text-foreground-subtle`,children:t(`cluster.noNodes`,`No nodes in this cluster yet.`)}):e(`div`,{className:`flex flex-col gap-3`,children:[i(tt,{staleNodeId:p.staleNodeId,shownNodeName:g.name}),i(He,{selectedNodeId:g.id,onSelect:m,allowOffline:!0,alwaysShow:!0}),i(sr,{node:g})]})]})}export{vr as ClusterPage};
@@ -1 +1 @@
1
- import{C as e,K as t,S as n,et as r}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{da as i,pi as a}from"./client-BRyxs6lT.js";import{Tr as o,Wo as s,qa as c,ri as l,za as u}from"./src-DytYtgEw.js";import{t as d}from"./useTranslation-BJr-n0es.js";import{D as f,E as p,F as m,_ as h,h as g,o as _,p as v,r as y,t as b}from"./HelperWizard-CbDck6HU.js";r();function x({blockId:r}){let{t:x}=d(),S=u({blockId:r}),C=c(),w=s(),T=t(()=>{let e=new Set;for(let{cap:t}of g())e.add(t);for(let{cap:t}of h())e.add(t);for(let{cap:t}of p())e.add(t);return e},[]);if(S.status===`pending`)return n(`p`,{role:`status`,children:x(`compositionEditor.loading`)});if(S.status===`error`)return n(o,{title:x(`compositionEditor.loadFailed`),message:S.error.message});if(S.data.state===`not-loaded`)return n(`p`,{role:`status`,children:x(`customize.status.notLoaded`,{reason:S.data.reason})});let E=S.data.view;if(E===null)return n(`p`,{children:x(`compositionEditor.notFound`,{blockId:r})});let D=a(E.block);if(D===null)return n(`p`,{children:x(`compositionEditor.notComposition`)});if(_(D)){let e=y(D.helper,E.block.name,``);if(e===null)return n(`p`,{role:`alert`,children:x(`helper.unreadable`)});let t=E.state.kind===`answered`?E.state.state?.deviceId??null:null;return n(b,{purpose:`edit`,initial:e,start:`parameters`,saving:C.isPending,onSave:async e=>{let n=await v(e,async(n,r)=>{await C.mutateAsync({blockId:E.block.id,expectedUpdatedAt:E.block.updatedAt,block:{composition:n,...r===``?{}:{name:r}}}),t!==null&&e.room.trim()!==``&&await w.mutateAsync({deviceId:t,location:e.room.trim()}),await S.refetch()});return n.length>0?{kind:`refused`,lines:n}:{kind:`saved`,deviceId:t??0}}})}let O=m(D),k={id:0,name:E.block.name,addonId:`composer`,stableId:`composed-${r}`,type:D.target.kind===`new`?D.target.type:i.Sensor,location:``,disabled:!1,parentDeviceId:null,role:D.target.kind===`new`?D.target.role:null,online:!0,probed:!0,features:[],isCamera:!1,config:{},secretConfigPaths:[],metadata:{}},A={target:{addonId:`composer`,stableId:k.stableId},state:{kind:`present`,view:E,composition:D},saving:C.isPending,save:async e=>{if(e===null)return{kind:`refused`,reason:`cannot delete here`};try{return await C.mutateAsync({blockId:E.block.id,expectedUpdatedAt:E.block.updatedAt,block:{composition:e}}),await S.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:e instanceof Error?e.message:String(e)}}}};return e(`div`,{className:`flex flex-col gap-2`,children:[n(l,{variant:O===`incomplete`?`warning`:`success`,children:x(`customize.blockStatus.${O===`incomplete`?`incomplete`:E.block.status}`)}),n(f,{device:k,handle:A,skipCaps:T})]})}export{x as t};
1
+ import{C as e,K as t,S as n,et as r}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{da as i,pi as a}from"./client-CwJGlpR9.js";import{Tr as o,Wo as s,qa as c,ri as l,za as u}from"./src-DwNoxp86.js";import{t as d}from"./useTranslation-BJr-n0es.js";import{D as f,E as p,F as m,_ as h,h as g,o as _,p as v,r as y,t as b}from"./HelperWizard-BPhC2XoW.js";r();function x({blockId:r}){let{t:x}=d(),S=u({blockId:r}),C=c(),w=s(),T=t(()=>{let e=new Set;for(let{cap:t}of g())e.add(t);for(let{cap:t}of h())e.add(t);for(let{cap:t}of p())e.add(t);return e},[]);if(S.status===`pending`)return n(`p`,{role:`status`,children:x(`compositionEditor.loading`)});if(S.status===`error`)return n(o,{title:x(`compositionEditor.loadFailed`),message:S.error.message});if(S.data.state===`not-loaded`)return n(`p`,{role:`status`,children:x(`customize.status.notLoaded`,{reason:S.data.reason})});let E=S.data.view;if(E===null)return n(`p`,{children:x(`compositionEditor.notFound`,{blockId:r})});let D=a(E.block);if(D===null)return n(`p`,{children:x(`compositionEditor.notComposition`)});if(_(D)){let e=y(D.helper,E.block.name,``);if(e===null)return n(`p`,{role:`alert`,children:x(`helper.unreadable`)});let t=E.state.kind===`answered`?E.state.state?.deviceId??null:null;return n(b,{purpose:`edit`,initial:e,start:`parameters`,saving:C.isPending,onSave:async e=>{let n=await v(e,async(n,r)=>{await C.mutateAsync({blockId:E.block.id,expectedUpdatedAt:E.block.updatedAt,block:{composition:n,...r===``?{}:{name:r}}}),t!==null&&e.room.trim()!==``&&await w.mutateAsync({deviceId:t,location:e.room.trim()}),await S.refetch()});return n.length>0?{kind:`refused`,lines:n}:{kind:`saved`,deviceId:t??0}}})}let O=m(D),k={id:0,name:E.block.name,addonId:`composer`,stableId:`composed-${r}`,type:D.target.kind===`new`?D.target.type:i.Sensor,location:``,disabled:!1,parentDeviceId:null,role:D.target.kind===`new`?D.target.role:null,online:!0,probed:!0,features:[],isCamera:!1,config:{},secretConfigPaths:[],metadata:{}},A={target:{addonId:`composer`,stableId:k.stableId},state:{kind:`present`,view:E,composition:D},saving:C.isPending,save:async e=>{if(e===null)return{kind:`refused`,reason:`cannot delete here`};try{return await C.mutateAsync({blockId:E.block.id,expectedUpdatedAt:E.block.updatedAt,block:{composition:e}}),await S.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:e instanceof Error?e.message:String(e)}}}};return e(`div`,{className:`flex flex-col gap-2`,children:[n(l,{variant:O===`incomplete`?`warning`:`success`,children:x(`customize.blockStatus.${O===`incomplete`?`incomplete`:E.block.status}`)}),n(f,{device:k,handle:A,skipCaps:T})]})}export{x as t};
@@ -1 +1 @@
1
- import{C as e,S as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{pi as n}from"./client-BRyxs6lT.js";import{t as r}from"./boxes-Dg0SsuKi.js";import{Yr as i,za as a}from"./src-DytYtgEw.js";import{t as o}from"./useTranslation-BJr-n0es.js";import{_r as s,f as c,hr as l,m as u,mr as d,vr as f}from"./index-BCZXKpVN.js";import{t as p}from"./CompositionBlockEditor--2eeDknC.js";import{t as m}from"./AdminPage-CoK_jJGS.js";var h=`rounded-lg border border-border bg-surface p-4`,g=`new`;function _(){let{blockId:_}=f(),{t:v}=o(),y=s(),b=_===void 0||_===g,x=a({blockId:_??``},{enabled:!b}),S=e=>t(m,{icon:r,title:v(`compositionEditor.pageTitle`),children:e});if(b)return t(l,{to:`${c}&new=helper`,replace:!0});if(x.status===`success`&&x.data.state===`loaded`&&x.data.view!==null){let e=x.data.view;if(n(e.block)?.target.kind===`existing`){let n=e.state.kind===`answered`?e.state.state?.deviceId??null:null;if(n!==null)return S(t(`section`,{className:h,children:t(d,{className:`text-primary text-sm`,to:u(n),children:v(`compositionEditor.openOnDevice`)})}))}}return S(e(`section`,{className:`${h} flex flex-col gap-2`,children:[t(i,{variant:`ghost`,size:`sm`,onClick:()=>y(c),children:v(`compositionEditor.cancel`)}),t(p,{blockId:_??``})]}))}export{_ as CompositionEditorPage};
1
+ import{C as e,S as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{pi as n}from"./client-CwJGlpR9.js";import{t as r}from"./boxes-C9rq6GsW.js";import{Yr as i,za as a}from"./src-DwNoxp86.js";import{t as o}from"./useTranslation-BJr-n0es.js";import{_r as s,f as c,hr as l,m as u,mr as d,vr as f}from"./index-DG07MiZm.js";import{t as p}from"./CompositionBlockEditor-CH-GMXbq.js";import{t as m}from"./AdminPage-DlYf-2bp.js";var h=`rounded-lg border border-border bg-surface p-4`,g=`new`;function _(){let{blockId:_}=f(),{t:v}=o(),y=s(),b=_===void 0||_===g,x=a({blockId:_??``},{enabled:!b}),S=e=>t(m,{icon:r,title:v(`compositionEditor.pageTitle`),children:e});if(b)return t(l,{to:`${c}&new=helper`,replace:!0});if(x.status===`success`&&x.data.state===`loaded`&&x.data.view!==null){let e=x.data.view;if(n(e.block)?.target.kind===`existing`){let n=e.state.kind===`answered`?e.state.state?.deviceId??null:null;if(n!==null)return S(t(`section`,{className:h,children:t(d,{className:`text-primary text-sm`,to:u(n),children:v(`compositionEditor.openOnDevice`)})}))}}return S(e(`section`,{className:`${h} flex flex-col gap-2`,children:[t(i,{variant:`ghost`,size:`sm`,onClick:()=>y(c),children:v(`compositionEditor.cancel`)}),t(p,{blockId:_??``})]}))}export{_ as CompositionEditorPage};