@camstack/addon-admin-ui 1.2.425 → 1.2.427

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 (121) hide show
  1. package/dist/assets/{AddonAssetIcon-CYCgFnh-.js → AddonAssetIcon-BgXfFdy2.js} +1 -1
  2. package/dist/assets/Addons-BTWw53aT.js +4 -0
  3. package/dist/assets/{AdminPage-250c5IIz.js → AdminPage-C0Zxs_ot.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-Bx9l4jGV.js → AdminSectionedPage-D2kYQhvu.js} +1 -1
  5. package/dist/assets/{AiProfiles-CUuAciGa.js → AiProfiles-Ca7zuVMp.js} +1 -1
  6. package/dist/assets/{BrokerForm-nkI-Qcl_.js → BrokerForm-6-BwPs-g.js} +1 -1
  7. package/dist/assets/Build-BsduavcU.js +40 -0
  8. package/dist/assets/{Calendars-B5LzurzV.js → Calendars-DVTk_2iT.js} +1 -1
  9. package/dist/assets/Cluster-BPJ4maiI.js +1 -0
  10. package/dist/assets/{ClusterStepModel-RbVpM7O6.js → ClusterStepModel-CjuZ-oml.js} +1 -1
  11. package/dist/assets/CompositionEditor-DJcmWU2U.js +1 -0
  12. package/dist/assets/{CompositionEditorPage-Dwc53zIU.js → CompositionEditorPage-CDyW_Buu.js} +1 -1
  13. package/dist/assets/{Data-w3RkRs0J.js → Data-CLLvqZwG.js} +1 -1
  14. package/dist/assets/{DeviceDetail-De_43vZZ.js → DeviceDetail-BKw1gufS.js} +2 -2
  15. package/dist/assets/{DeviceDoActionFields-GnzcNn1m.js → DeviceDoActionFields-R-ZYIdMv.js} +1 -1
  16. package/dist/assets/{Devices-CPzgp4KM.js → Devices-CHeb_BTk.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-f4jubzvX.js → EmbedPlayerPage-B4y0Q0wO.js} +1 -1
  18. package/dist/assets/{Identity-CAsJZhy-.js → Identity-NOlTR-3q.js} +1 -1
  19. package/dist/assets/{IntegrationDetail-DVzyFVQi.js → IntegrationDetail-CcZkPlbN.js} +1 -1
  20. package/dist/assets/IntegrationHub-CuW7-WRy.js +1 -0
  21. package/dist/assets/{Integrations-DYJZbIJb.js → Integrations-ACdx4iPR.js} +1 -1
  22. package/dist/assets/Integrations-DjnhmLye.js +1 -0
  23. package/dist/assets/{Library-CuaDA83A.js → Library-B3iyoKdK.js} +1 -1
  24. package/dist/assets/Locations-Cs1VwmXB.js +3 -0
  25. package/dist/assets/Logs-BMc6WXCH.js +1 -0
  26. package/dist/assets/{MotionZonesSettings-sQ16MBx7.js → MotionZonesSettings-DjvGw8j4.js} +1 -1
  27. package/dist/assets/MyAccess-BfUfTXrv.js +2 -0
  28. package/dist/assets/{Network-gdhbKSd3.js → Network-F2lAIcbT.js} +1 -1
  29. package/dist/assets/NodeAddonsSettingsPanel-D3ux_JIo.js +1 -0
  30. package/dist/assets/Notifications-Cp3qo_EC.js +1 -0
  31. package/dist/assets/{PrivacyMaskSettings-ck5SNB0S.js → PrivacyMaskSettings-IK6ytyM8.js} +1 -1
  32. package/dist/assets/{Recordings-C_wXXKNm.js → Recordings-D91q74Ga.js} +1 -1
  33. package/dist/assets/{ScanNetworkModal-DL_B-AVn.js → ScanNetworkModal-DjU-xM4X.js} +1 -1
  34. package/dist/assets/{SceneMonitorEditor-8CpDpVOM.js → SceneMonitorEditor-V_pHxg3U.js} +1 -1
  35. package/dist/assets/{SessionsList-DZBaHZJv.js → SessionsList-DQ7kj8fX.js} +1 -1
  36. package/dist/assets/{Showroom-CaiMghAf.js → Showroom-Cw-6ZdvC.js} +1 -1
  37. package/dist/assets/System-DLLa4weE.js +1 -0
  38. package/dist/assets/{Terminal-C6_w6IRM.js → Terminal-D-YHBrHK.js} +1 -1
  39. package/dist/assets/{Viewer-ClJ6Xfm_.js → Viewer-BmXiweP2.js} +1 -1
  40. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DUcH4sBh.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-wt87pCBz.js} +1 -1
  41. package/dist/assets/{addon-icons-context-_Q-TMhpS.js → addon-icons-context-CvwUgMRr.js} +1 -1
  42. package/dist/assets/{archive-5Mi3cn4y.js → archive-Bwv0mNo-.js} +1 -1
  43. package/dist/assets/{authed-media-CIBSu5eS.js → authed-media-0TPg9TTZ.js} +1 -1
  44. package/dist/assets/{bell-off-O6w2Rfx2.js → bell-off-D2KzCQW2.js} +1 -1
  45. package/dist/assets/{boxes-gwiYF6bh.js → boxes-BXQUMgws.js} +1 -1
  46. package/dist/assets/circle-slash-DpUtlEnB.js +1 -0
  47. package/dist/assets/client-CjyKfSu1.js +358 -0
  48. package/dist/assets/{cloud-upload-BkkCpA1A.js → cloud-upload-BsULjxPu.js} +1 -1
  49. package/dist/assets/crop-BtQBZ9jm.js +1 -0
  50. package/dist/assets/{device-integration-icon-CPrOtTLY.js → device-integration-icon-CCoHGEQZ.js} +1 -1
  51. package/dist/assets/device-picker-model-1Z6p3UkP.js +1 -0
  52. package/dist/assets/{dist-CJ-8B9yY.js → dist-DQtBl_2T.js} +1 -1
  53. package/dist/assets/dist-DWoekMi0.js +358 -0
  54. package/dist/assets/{eraser-TGwVVn87.js → eraser-DB7_WMyf.js} +1 -1
  55. package/dist/assets/{file-up-BGAdeddG.js → file-up-DuqaeMYR.js} +1 -1
  56. package/dist/assets/{hard-drive-download-srWFcoIp.js → hard-drive-download-CKj8xKOz.js} +1 -1
  57. package/dist/assets/{history-BuUr8Pf8.js → history-V8RQKQAb.js} +1 -1
  58. package/dist/assets/{hostInit-DWnakaq9.js → hostInit-CdxLRG1l.js} +1 -1
  59. package/dist/assets/{icons-DrL-Fdok.js → icons-CEMmjIEL.js} +1 -1
  60. package/dist/assets/{index-D7FGxQMl.js → index-D66JvELZ.js} +3 -3
  61. package/dist/assets/{key-B0MTvYot.js → key-Bj5-ZBrb.js} +1 -1
  62. package/dist/assets/{key-round-Cl-qLeAZ.js → key-round-B2I1YisX.js} +1 -1
  63. package/dist/assets/{layers-Df1aeR99.js → layers-BARFkXZ5.js} +1 -1
  64. package/dist/assets/{list-ordered-BzkisKLy.js → list-ordered-9lF0Gp3K.js} +1 -1
  65. package/dist/assets/{location-owned-usage-CVdW20Z2.js → location-owned-usage-CNXQ-Obv.js} +1 -1
  66. package/dist/assets/{log-in-xkUb0jne.js → log-in-CjtrIfG3.js} +1 -1
  67. package/dist/assets/{memory-stick-C4-nNgvT.js → memory-stick-B26_SbtH.js} +1 -1
  68. package/dist/assets/{message-square-plus-B2M8qlsN.js → message-square-plus-COMrVZEZ.js} +1 -1
  69. package/dist/assets/{mf-entry-bootstrap-0-cd3d1253.js → mf-entry-bootstrap-0-ec37d41a.js} +2 -2
  70. package/dist/assets/{mic-off-C-BZDmBY.js → mic-off-DBIqFVjg.js} +1 -1
  71. package/dist/assets/{monitor-off-DeEjoNtE.js → monitor-off-CTQMySOs.js} +1 -1
  72. package/dist/assets/{monitor-smartphone-DmzFXiIW.js → monitor-smartphone-iBd_3nPv.js} +1 -1
  73. package/dist/assets/mount-1Z6p3UkP.js +1 -0
  74. package/dist/assets/{notification-schedule-field-BDMeSniX.js → notification-schedule-field-D8dd67dT.js} +1 -1
  75. package/dist/assets/{octagon-alert-AbeyZo0w.js → octagon-alert-DMjnTemh.js} +1 -1
  76. package/dist/assets/{player-overlays-DEJGWVeQ.js → player-overlays-DWMIy1MJ.js} +1 -1
  77. package/dist/assets/{recycle-Cg5L5URL.js → recycle-BCVF0r6Y.js} +1 -1
  78. package/dist/assets/remoteEntry-RwWzzVu_.js +1 -0
  79. package/dist/assets/{scan-eye-QKQlUjSj.js → scan-eye-DRXP3PgB.js} +1 -1
  80. package/dist/assets/{scissors-CixnGpmu.js → scissors-DUFtPb9T.js} +1 -1
  81. package/dist/assets/{search-x-Cjg-NClW.js → search-x-B3nve3vV.js} +1 -1
  82. package/dist/assets/{send-C_JQVC2l.js → send-P2KlabIu.js} +1 -1
  83. package/dist/assets/{settings-2-0Dzmg5ID.js → settings-2-reEhyiKz.js} +1 -1
  84. package/dist/assets/{speaker-D_GGxoIS.js → speaker-DSNMuvS8.js} +1 -1
  85. package/dist/assets/{src-CVCI1YgT.js → src-BLkInT8U.js} +8 -8
  86. package/dist/assets/{timer-reset-DbjUS-e3.js → timer-reset-CsRTbSzh.js} +1 -1
  87. package/dist/assets/{ungroup-Bn_PEJ2F.js → ungroup-BLeVa8__.js} +1 -1
  88. package/dist/assets/{unlink-C2XiU97D.js → unlink-DeNvF8r-.js} +1 -1
  89. package/dist/assets/{usb-Yb2y3179.js → usb-CFseVsQJ.js} +1 -1
  90. package/dist/assets/{use-scenes-feed-Bg10fjvd.js → use-scenes-feed-C8frh3hQ.js} +1 -1
  91. package/dist/assets/{use-stationary-objects-BE7lNV-s.js → use-stationary-objects-DNayAuMq.js} +1 -1
  92. package/dist/assets/useEventInvalidation-1Z6p3UkP.js +1 -0
  93. package/dist/assets/{useNodeUrlSelection-DVvZOo0G.js → useNodeUrlSelection-BsLRiUy8.js} +1 -1
  94. package/dist/assets/user-round-BB0VDRnJ.js +1 -0
  95. package/dist/assets/{user-x-HpPBhUXj.js → user-x-CpaZ5HO0.js} +1 -1
  96. package/dist/assets/{video-47m9GMk0.js → video--MLJeLNU.js} +1 -1
  97. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BHVW3f4G.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-1Do_dc2z.js} +2 -2
  98. package/dist/index.html +9 -9
  99. package/dist/server/addon.js +34 -5
  100. package/package.json +1 -1
  101. package/dist/assets/Addons-BrNO-gNV.js +0 -4
  102. package/dist/assets/Build-BKUHKW99.js +0 -40
  103. package/dist/assets/Cluster-BRfEOot0.js +0 -1
  104. package/dist/assets/CompositionEditor-paHohkHN.js +0 -1
  105. package/dist/assets/IntegrationHub-Bufk1Dn6.js +0 -1
  106. package/dist/assets/Integrations-CrWX5s2l.js +0 -1
  107. package/dist/assets/Locations-DC7Mbk0N.js +0 -3
  108. package/dist/assets/Logs-B3gxHPJx.js +0 -1
  109. package/dist/assets/MyAccess-Dk-eK9Ik.js +0 -2
  110. package/dist/assets/NodeAddonsSettingsPanel-Dh4z-QGr.js +0 -1
  111. package/dist/assets/Notifications-CP3XZDYw.js +0 -1
  112. package/dist/assets/System-DBkSQMrh.js +0 -1
  113. package/dist/assets/circle-slash-LeaAcO0Z.js +0 -1
  114. package/dist/assets/client-Cm-sr0wc.js +0 -358
  115. package/dist/assets/crop-CSoFpLsd.js +0 -1
  116. package/dist/assets/device-picker-model-DSRwVBTr.js +0 -1
  117. package/dist/assets/dist-DH3WcYkO.js +0 -358
  118. package/dist/assets/mount-DSRwVBTr.js +0 -1
  119. package/dist/assets/remoteEntry-Cdw06LwW.js +0 -1
  120. package/dist/assets/useEventInvalidation-DSRwVBTr.js +0 -1
  121. package/dist/assets/user-round-Bn5beI9W.js +0 -1
@@ -1 +0,0 @@
1
- import{G as e,I as t,K as n,Q as r,S as i,b as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{D as l,O as u,V as d,ot as f}from"./player-overlays-DEJGWVeQ.js";import{Ar as p,Cr as m,Er as h,Ir as g,Lr as _,Sr as v,Tr as y,_n as b,_r as x,an as S,cn as C,kr as w,ln as ee,mr as T,on as te,sn as ne,vr as re,wr as E,xr as ie,yr as ae}from"./client-Cm-sr0wc.js";import{Bn as D,Li as oe,Ln as O,Ua as se,Xl as ce,Zn as le,ar as ue,cu as de,ji as fe,ma as k,pa as pe,s as me,uu as he}from"./src-CVCI1YgT.js";import{t as A}from"./useTranslation-Bc5yH9V9.js";r();function ge(e){return{target:{kind:`new`,type:e},name:``,features:[]}}function _e(e){return{target:{kind:`existing`,device:e},name:``,features:[]}}function j(e,t){return{target:e.target,name:t,features:e.features.flatMap(e=>e.kind===`fields`?[e]:[])}}function M(e,t,n){return{...e,features:e.features.map(e=>e.cap===t?n(e):e)}}function N(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>e!==t))}function ve(e,t){switch(t.type){case`set-new-type`:return e.target.kind===`new`?{...e,target:{...e.target,type:t.deviceType}}:e;case`set-new-role`:{if(e.target.kind!==`new`)return e;let{role:n,...r}=e.target;return{...e,target:t.role===null?r:{...r,role:t.role}}}case`set-name`:return{...e,name:t.name};case`add-feature`:return e.features.some(e=>e.cap===t.cap)?e:{...e,features:[...e.features,{kind:`fields`,cap:t.cap,fields:{}}]};case`remove-feature`:return{...e,features:e.features.filter(e=>e.cap!==t.cap)};case`set-field`:return M(e,t.cap,e=>({...e,fields:{...e.fields,[t.path]:t.source}}));case`clear-field`:return M(e,t.cap,e=>({...e,fields:N(e.fields,t.path)}));case`remove-binding`:return M(e,t.cap,e=>{let n=e.fields[t.path];return n?.kind===`expression`?{...e,fields:{...e.fields,[t.path]:{...n,bindings:N(n.bindings,t.bindingName)}}}:e});case`copy-feature`:return M(e,t.cap,e=>({...e,fields:{...e.fields,...Object.fromEntries(t.paths.map(e=>[e,{kind:`from`,source:t.from,cap:t.sourceCap,fieldPath:e}]))}}))}}function ye(e){let t=ae.safeParse({target:e.target,features:e.features});return t.success?{ok:!0,composition:t.data}:{ok:!1,problems:t.error.issues.map(e=>`${e.path.join(`.`)||`composition`}: ${e.message}`)}}function be(e,t){return JSON.stringify(e)!==JSON.stringify(t)}function xe(e){for(let t=1;;t++){let n=`s${t}`;if(!e.includes(n))return n}}var Se=[`room`,`converted-sensor`,`derived-binary`],P={addonId:`provider-homeassistant`,stableId:`sensor.template_source`};function Ce(){return j(C({temperatureSources:te,motionSources:S,occupancyWindowMs:ne}),`Room`)}function we(){return j({target:{kind:`new`,type:p.Sensor},features:[{kind:`fields`,cap:`numeric-sensor`,fields:{value:{kind:`expression`,expr:`convert(v, "°C", "°F")`,bindings:{v:{kind:`from`,source:P,cap:`numeric-sensor`,fieldPath:`value`}}},unit:{kind:`expression`,expr:`"°F"`,bindings:{}},lastFetchedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Converted sensor`)}function Te(){return j({target:{kind:`new`,type:p.Sensor},features:[{kind:`fields`,cap:`binary`,fields:{on:{kind:`expression`,expr:`v > 20`,bindings:{v:{kind:`from`,source:P,cap:`temperature-sensor`,fieldPath:`celsius`}}},lastChangedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Derived binary`)}function Ee(e){switch(e){case`room`:return Ce();case`converted-sensor`:return we();case`derived-binary`:return Te()}}function De(e,t){return typeof t==`number`&&Number.isFinite(t)&&t>0?{kind:`device`,path:`/devices/${t}`}:{kind:`editor`,path:`/build/compositions/${encodeURIComponent(e)}`}}var F=`rounded-lg border border-border bg-surface p-4`,Oe=F;function ke(e){return{addonId:e.addonId,stableId:e.stableId}}function I(e){return new Map(e.map(e=>[y(ke(e)),e]))}function Ae(e,t,n){let r=e?.features??[],i=r.findIndex(e=>e.cap===n.cap);return{target:e?.target??{kind:`existing`,device:t},features:i===-1?[...r,n]:r.map((e,t)=>t===i?n:e)}}function je(e,t){let n=e.features.filter(e=>e.cap!==t);return n.length===0?null:{target:e.target,features:n}}function Me(e,t){let n=e?.features.find(e=>e.cap===t);return n!==void 0&&n.kind===`fields`?n:null}function L(e){return Array.isArray(e)?e.map(L):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,L(t)]))}function R(e){return JSON.stringify(L(e))}function Ne(e,t){return R(e)===R(t)}function z(e,t){return R(e)===R(t)}function Pe(e,t){switch(e.kind){case`pending`:return{kind:`refused`,reason:`the customization has not been read yet — try again`};case`unknown`:return{kind:`refused`,reason:`the customization could not be read: ${e.reason}`};case`not-loaded`:return{kind:`refused`,reason:`the customizations are not loaded yet: ${e.reason}`};case`none`:return t===null?{kind:`noop`}:{kind:`create`,input:{enabled:!0,composition:t}};case`present`:{let n=e.view.block.id;return t===null?{kind:`delete`,blockId:n}:R(t)===R(e.composition)?{kind:`noop`}:{kind:`update`,blockId:n,expectedUpdatedAt:e.view.block.updatedAt,composition:t}}}}function B(e,t){let n=e===`enum`?`string`:e,r=t.kind===`enum`?`string`:t.kind,i={source:t.source,cap:t.cap,fieldPath:t.fieldPath};return r===n?{kind:`from`,...i}:n===`number`&&r===`string`?{kind:`expression`,expr:`number(x)`,bindings:{x:{kind:`from`,...i}}}:null}function V(e){return{kind:`expression`,expr:e,bindings:{}}}function H(e){let t=B(`number`,e.percentage);return t===null?null:{kind:`fields`,cap:`battery`,fields:e.mode===`replace`?{percentage:t}:{percentage:t,charging:V(`"unknown"`),sleeping:V(`false`),lastUpdated:V(`now`)}}}var Fe=[`percent`,...b.options];function U(e,t){return t===`percent`?{level:e}:{"remaining.value":e,"remaining.unit":V(JSON.stringify(t))}}function Ie(e,t){let n=B(`number`,t.remaining);if(n===null||!re.test(t.key)||t.label.trim()===``)return null;let r={label:t.label.trim(),fields:U(n,t.unit)};return{kind:`fields`,cap:`consumables`,...e?.enabled===void 0?{}:{enabled:e.enabled},fields:e?.fields??{lastChangedAt:V(`now`),lastFetchedAt:V(`now`)},items:{...e?.items,[t.key]:r}}}function Le(e){if(e.level!==void 0)return`percent`;let t=e[`remaining.unit`];if(t===void 0||t.kind!==`expression`)return null;try{let e=b.safeParse(JSON.parse(t.expr));return e.success?e.data:null}catch{return null}}function Re(e){return Object.entries(e?.items??{}).map(([e,t])=>{let n=Le(t.fields),r=W(t.fields.level??t.fields[`remaining.value`]),i=r===null?null:B(`number`,r);return n!==null&&i!==null&&Ne(U(i,n),t.fields)?{key:e,label:t.label,unit:n,source:r}:{key:e,label:t.label,unit:null,source:null}})}function ze(e,t){let n=Object.fromEntries(Object.entries(e.items??{}).filter(([e])=>e!==t));return Object.keys(n).length===0?null:{...e,items:n}}function Be(e){return e.toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,48)}function Ve(e){let t=e.fields.lastPressedAt;if(t===void 0||t.kind!==`expression`)return[];let n=Object.entries(t.bindings).filter(([e])=>e.startsWith(`active`)).flatMap(([,e])=>e.kind===`from`?[e.source]:[]);return[...new Map(n.map(e=>[y(e),e])).values()]}function He(e){let t=e.fields.lastPressedAt;if(t===void 0||t.kind!==`expression`)return[];let n=t.bindings;return Object.entries(n).flatMap(([e,t])=>{if(!e.startsWith(`active`)||t.kind!==`from`)return[];let r=n[`changed${e.slice(6)}`];return r===void 0||r.kind!==`from`?[]:[{source:t.source,cap:t.cap,activeField:t.fieldPath,changedAtField:r.fieldPath}]})}function W(e){if(e===void 0)return null;if(e.kind===`from`){let{kind:t,...n}=e;return{...n,kind:`number`}}if(e.kind!==`expression`||e.expr!==`number(x)`)return null;let t=e.bindings.x;if(t===void 0||t.kind!==`from`||Object.keys(e.bindings).length!==1)return null;let{kind:n,...r}=t;return{...r,kind:`string`}}function Ue(e,t){let n=W(e.fields.percentage);if(n===null)return!1;let r=H({percentage:n,mode:t}),{enabled:i,...a}=e;return r!==null&&z(a,r)}function G(e){return e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,location:e.location,type:e.type}))}function We(e,t,n){let r=t.trim().toLowerCase();return r===``?[]:e.filter(e=>!n.includes(e.id)&&[e.name,e.stableId,e.location??``].some(e=>e.toLowerCase().includes(r))).toSorted((e,t)=>e.name.localeCompare(t.name)).slice(0,20)}function K(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n||Array.isArray(n))return;n=Object.getOwnPropertyDescriptor(n,e)?.value}return n}function Ge(e,t,n,r){return r===null?{kind:`from`,source:e,cap:t,fieldPath:n.path}:B(r,{source:e,cap:t,fieldPath:n.path,kind:n.kind})}function Ke(e,t,n,r){let i={addonId:e.addonId,stableId:e.stableId};return t.caps.flatMap(e=>e.fields.filter(e=>e.item!==!0).map(t=>({cap:e.cap,path:t.path,kind:t.kind,value:n===null?void 0:K(n[e.cap],t.path),source:Ge(i,e.cap,t,r)})))}function q(e,t){return t?e===void 0?`—`:e===null?`null`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e):`…`}var qe=[];function J({title:e,targetKind:t,excludeDeviceIds:n=qe,onPick:r,onCancel:a}){let{t:c}=A(),[f,p]=o(null);return i(`aside`,{"aria-label":e,className:`${u} ${l} flex flex-col gap-2`,children:[s(`h3`,{className:d,children:e}),f===null?s(Je,{excludeDeviceIds:n,onSelect:p}):s(Y,{device:f,targetKind:t,onPick:r,onBack:()=>p(null)}),s(`div`,{children:s(D,{variant:`ghost`,size:`sm`,onClick:a,children:c(`customize.picker.cancel`)})})]})}function Je({excludeDeviceIds:e,onSelect:t}){let{t:n}=A(),[r,c]=o(``),l=k({projection:`slim`});return i(a,{children:[i(`label`,{className:`flex flex-col gap-1 text-[11px] text-foreground-subtle`,children:[n(`customize.picker.search`),s(ce,{type:`search`,"aria-label":n(`customize.picker.search`),value:r,onChange:e=>c(e.target.value)})]}),l.status===`pending`&&s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:n(`customize.picker.loadingDevices`)}),l.status===`error`&&s(O,{title:n(`customize.picker.devicesFailed`),message:l.error?.message??``}),l.status===`success`&&s(`ul`,{className:`flex flex-col gap-1`,children:We(G(l.data),r,e).map(e=>s(`li`,{children:i(`button`,{type:`button`,className:`text-left text-[11px] hover:underline`,onClick:()=>t(e),children:[e.name,` `,i(`span`,{className:`text-foreground-subtle`,children:[`· `,e.stableId]})]})},e.id))})]})}function Y({device:e,targetKind:t,selected:n,onPick:r,onBack:a}){let{t:o}=A(),c=pe({deviceId:e.id}),l=se({deviceId:e.id});if(c.status===`pending`)return s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:o(`customize.picker.loadingFields`)});if(c.status===`error`)return s(O,{title:o(`customize.picker.fieldsFailed`),message:c.error?.message??``});let u=Ke(e,c.data,l.status===`success`?l.data:null,t),d=u.filter(e=>e.source===null).length,f={addonId:e.addonId,stableId:e.stableId};return i(`div`,{className:`flex flex-col gap-1`,children:[i(`button`,{type:`button`,className:`text-left text-[11px] text-primary`,onClick:a,children:[`← `,e.name]}),l.status===`error`&&s(`p`,{role:`alert`,className:`text-[10px] text-warning`,children:o(`customize.picker.valuesFailed`,{reason:l.error?.message??``})}),s(`ul`,{role:`listbox`,"aria-label":o(`customize.picker.fields`),className:`flex flex-col gap-1`,children:u.map(t=>{let a=t.source;if(a===null)return null;let o=()=>r({device:e,ref:f,cap:t.cap,path:t.path,kind:t.kind,source:a,value:t.value});return i(`li`,{role:`option`,"aria-selected":n?.cap===t.cap&&n.path===t.path,tabIndex:0,className:`flex justify-between gap-2 text-[11px] cursor-pointer hover:bg-surface-hover rounded px-1`,onClick:o,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&o()},children:[i(`span`,{className:`font-mono`,children:[t.cap,`.`,t.path]}),s(`span`,{children:q(t.value,l.status===`success`)})]},`${t.cap}.${t.path}`)})}),d>0&&t!==null&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:o(`customize.picker.hidden`,{count:d,kind:o(`customize.kinds.${t}`)})})]})}var Ye=`integration`;function X(e,t){switch(e.kind){case`from`:{let n=y(e.source);return`${t.get(n)??n} · ${e.cap}.${e.fieldPath}`}case`expression`:return e.expr;case`code`:return`code`}}function Xe(e,t){if(e.kind===`unreachable`)return{kind:`unknown`,reason:e.error};if(e.state===null)return{kind:`unknown`,reason:`the composer has not reported this customization yet`};let n=e.state.fields.find(t);return n===void 0?{kind:`unknown`,reason:`the composer reports no value for this field`}:n.state===`unavailable`?{kind:`unavailable`,reason:n.reason??`unavailable`}:{kind:`value`,value:n.value,staleReason:n.state===`stale`?n.reason??`stale`:null}}function Ze(e,t,n,r){return{key:`${e.feature.cap}.${t}`,cap:e.feature.cap,field:t,origin:`composed`,mode:e.mode,from:X(n,e.input.sourceNames),value:e.enabled?Xe(e.input.state,r):{kind:`off`}}}function Qe(e){let t=e.feature.cap;return Object.entries(e.feature.fields).map(([n,r])=>Ze(e,n,r,e=>e.cap===t&&e.path===n&&e.item===void 0))}function $e(e){let t=e.feature.cap;return Object.entries(e.feature.items??{}).flatMap(([n,r])=>Object.entries(r.fields).map(([r,i])=>Ze(e,v(x,n,r),i,e=>e.cap===t&&e.path===r&&e.item?.arrayPath===`items`&&e.item.key===n)))}function et(e,t,n){if(e===null)return{kind:`unknown`,reason:`the device state could not be read`};let r=K(e[t],n),i=r===void 0?void 0:g(r);return i===void 0?{kind:`unknown`,reason:`not reported`}:{kind:`value`,value:i,staleReason:null}}function tt(e){if(e.mode!==`replace`)return[];let t=e.feature.cap,n=new Set(Object.keys(e.feature.fields));return(e.input.nativeFields.get(t)??[]).filter(e=>!n.has(e)).map(n=>({key:`${t}.${n}`,cap:t,field:n,origin:`native`,mode:e.mode,from:Ye,value:et(e.input.snapshot,t,n)}))}function nt(e){return e.composition.features.flatMap(t=>{if(t.kind!==`fields`)return[];let n={feature:t,mode:e.nativeCaps.has(t.cap)?`replace`:`add`,enabled:ie(t),input:e};return[...Qe(n),...$e(n),...tt(n)]})}var rt={min:`min(a, b, …)`,max:`max(a, b, …)`,abs:`abs(x)`,floor:`floor(x)`,ceil:`ceil(x)`,sqrt:`sqrt(x)`,round:`round(x, digits?)`,pow:`pow(x, y)`,clamp:`clamp(x, lo, hi)`,avg:`avg(a, b, …)`,sum:`sum(a, b, …)`,coalesce:`coalesce(a, b, …)`,age:`age(now, ts)`,convert:`convert(x, "from", "to")`,any:`any(a, b, …)`,all:`all(a, b, …)`,within:`within(ts, ms)`,number:`number(x)`,latest:`latest(ts, …)`,rose:`rose(level, changedAt, debounceMs?)`,count:`count(x)`},Z=/[A-Za-z_][A-Za-z0-9_]*$/;function it(e,t,n){let r=Z.exec(e.slice(0,t))?.[0]??``;if(r===``)return[];let i=n.filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`binding`,label:e,insert:e,hintKey:null})),a=`now`.startsWith(r)?[{kind:`now`,label:`now`,insert:`now`,hintKey:`compositionEditor.now`}]:[],o=[..._].filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`builtin`,label:rt[e]??e,insert:`${e}(`,hintKey:`compositionEditor.builtins.${e}`}));return[...i,...a,...o].slice(0,8)}function at(e,t,n){let r=t-(Z.exec(e.slice(0,t))?.[0]??``).length;return{text:`${e.slice(0,r)}${n.insert}${e.slice(t)}`,cursor:r+n.insert.length}}r();function ot({label:e,value:t,bindings:r,onChange:a}){let{t:c}=A(),l=n(null),[u,d]=o(t.length),f=it(t,u,r);return i(`div`,{className:`flex flex-col gap-1`,children:[i(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[e,s(`input`,{ref:l,className:`font-mono px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`,value:t,onChange:e=>{a(e.target.value),d(e.target.selectionStart??e.target.value.length)},onSelect:e=>d(e.currentTarget.selectionStart??t.length)})]}),f.length>0&&s(`ul`,{role:`listbox`,"aria-label":c(`compositionEditor.suggestions`),className:`rounded border border-border bg-surface text-[11px]`,children:f.map(e=>i(`li`,{role:`option`,"aria-selected":!1,tabIndex:0,className:`flex justify-between gap-2 px-1 cursor-pointer hover:bg-surface-hover`,onClick:()=>{let n=at(t,u,e);a(n.text),d(n.cursor),l.current?.focus()},children:[s(`span`,{className:`font-mono`,children:e.label}),e.hintKey!==null&&s(`span`,{className:`text-foreground-subtle`,children:c(e.hintKey)})]},`${e.kind}:${e.label}`))})]})}function st(e,t,n){if(e.kind===`code`)return{kind:`unavailable`,reason:`code fields arrive in slice 4`};if(e.kind===`expression`&&(T(e.expr,`rose`)||T(e.expr,`count`)))return{kind:`runtime-only`};let r=h(e).filter(e=>t.get(E(e.source,e.cap))?.kind!==`value`).map(m);if(r.length>0)return{kind:`waiting`,missing:r};let i=ee({source:e,now:n,read:e=>{let n=t.get(E(e.source,e.cap)),r=n?.kind===`value`?K(n.slice,e.fieldPath):void 0,i=r===void 0?void 0:g(r);return i===void 0?{state:`unavailable`,reason:`${e.cap}.${e.fieldPath} is not reported`,fatal:!1}:{state:`fresh`,value:i}}});return i.state===`unavailable`?{kind:`unavailable`,reason:i.reason}:{kind:`value`,value:i.value,stale:i.reason}}r();function ct({sliceKey:e,deviceId:t,capName:n,onReading:r}){let i=me(f().trpcClient,t,n);return c(()=>{r(e,i===void 0?{kind:`pending`}:{kind:`value`,slice:i})},[e,i,r]),null}function lt(e,t){return[...new Map(h(e).map(e=>[E(e.source,e.cap),e]))].map(([e,n])=>({key:e,read:n,device:t.get(y(n.source))}))}function ut({source:e}){let{t:n}=A(),r=k({projection:`slim`}),[a,c]=o(new Map),l=t((e,t)=>{c(n=>new Map([...n,[e,t]]))},[]),u=lt(e,I(r.status===`success`?G(r.data):[])),d=r.status===`success`?u.filter(e=>e.device===void 0).map(e=>y(e.read.source)):[];return i(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[u.map(e=>e.device===void 0?null:s(ct,{sliceKey:e.key,deviceId:e.device.id,capName:e.read.cap,onReading:l},e.key)),s(`span`,{className:`text-foreground-subtle`,children:n(`compositionEditor.preview.label`)}),r.status===`error`?s(`span`,{className:`text-warning`,children:n(`compositionEditor.preview.devicesFailed`,{reason:r.error?.message??``})}):d.length>0?s(`span`,{className:`text-warning`,children:n(`compositionEditor.preview.unknownDevice`,{sources:d.join(`, `)})}):s(dt,{preview:st(e,a,Date.now())})]})}function dt({preview:e}){let{t}=A();switch(e.kind){case`value`:return i(`strong`,{children:[`→ `,q(e.value,!0),e.stale===null?``:` (${e.stale})`]});case`unavailable`:return s(`span`,{className:`text-warning`,children:e.reason});case`waiting`:return s(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.waiting`,{sources:e.missing.join(`, `)})});case`runtime-only`:return s(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.runtimeOnly`)})}}r();function ft({path:e,kind:t,required:n,source:r,onSet:c,onClear:l,onRemoveBinding:u,sourceNames:d}){let{t:f}=A(),[p,m]=o(`idle`),h=r?.kind===`expression`?r:null;return i(`div`,{className:`flex flex-col gap-1 rounded border border-border p-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[s(`span`,{className:`font-mono text-[11px]`,children:e}),i(`span`,{className:`text-[10px] text-foreground-subtle`,children:[f(`customize.kinds.${t}`),n?` · ${f(`compositionEditor.required`)}`:``]}),s(D,{size:`sm`,variant:`outline`,onClick:()=>m(`take`),children:f(`compositionEditor.takeFrom`)}),s(D,{size:`sm`,variant:`outline`,"aria-pressed":h!==null,onClick:()=>c(h??{kind:`expression`,expr:`null`,bindings:{}}),children:f(`compositionEditor.formula`)}),r!==void 0&&s(D,{size:`sm`,variant:`ghost`,onClick:l,children:f(`compositionEditor.clear`)})]}),r?.kind===`from`&&s(`span`,{className:`text-[11px]`,children:X(r,d)}),h!==null&&i(a,{children:[s(ot,{label:f(`compositionEditor.formulaFor`,{path:e}),value:h.expr,bindings:Object.keys(h.bindings),onChange:e=>c({...h,expr:e})}),s(`ul`,{className:`text-[11px] flex flex-col gap-0.5`,children:Object.entries(h.bindings).map(([e,t])=>i(`li`,{className:`flex flex-wrap items-center gap-2`,children:[s(`span`,{className:`font-mono`,children:e}),s(`span`,{children:t.kind===`from`?X(t,d):JSON.stringify(t.value)}),s(D,{size:`sm`,variant:`ghost`,"aria-label":f(`compositionEditor.removeBinding`,{name:e}),onClick:()=>u(e),children:`×`})]},e))}),s(D,{size:`sm`,variant:`ghost`,onClick:()=>m(`add-binding`),children:f(`compositionEditor.addSource`)})]}),p!==`idle`&&s(J,{title:f(p===`take`?`compositionEditor.takeFrom`:`compositionEditor.addSource`),targetKind:p===`take`?t:null,onCancel:()=>m(`idle`),onPick:e=>{if(p===`take`)c(e.source);else if(h!==null){let t=xe(Object.keys(h.bindings));c({...h,bindings:{...h.bindings,[t]:{kind:`from`,source:e.ref,cap:e.cap,fieldPath:e.path}}})}m(`idle`)}}),r!==void 0&&s(ut,{source:r})]})}r();function Q(e){return e===null||e.kind===`known`?null:e}function pt({draft:e,deviceType:t,nativeCaps:n,targetFields:r,dispatch:c}){let{t:l}=A(),u=fe({deviceType:t}),d=k({projection:`slim`}),f=new Map([...I(d.status===`success`?G(d.data):[])].map(([e,t])=>[e,t.name])),[p,m]=o(null),h=Q(n)??Q(r),g=n?.kind===`known`?n.value:new Set,_=new Set(e.features.map(e=>e.cap)),v=u.status===`success`?u.data.caps.filter(e=>!_.has(e.cap)&&!g.has(e.cap)):[],y=[...g].filter(e=>!_.has(e)),b=e=>g.has(e)?((r?.kind===`known`?r.value.caps.find(t=>t.cap===e):void 0)?.fields??[]).filter(e=>e.item!==!0&&!e.path.includes(`.`)).map(e=>({path:e.path,kind:e.kind,required:!1})):((u.status===`success`?u.data.caps.find(t=>t.cap===e):void 0)?.fields??[]).map(e=>({path:e.path,kind:e.kind,required:e.required}));return h===null?i(a,{children:[i(`section`,{"aria-labelledby":`editor-features`,className:`${F} flex flex-col gap-2`,children:[s(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),u.status===`pending`&&s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.checking`)}),u.status===`error`&&s(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.unknown`,{reason:u.error?.message??``})}),i(`div`,{className:`flex flex-wrap gap-1`,children:[e.features.map(e=>i(`span`,{className:`flex items-center gap-1 rounded border border-border px-1.5 text-[11px]`,children:[e.cap,s(ue,{variant:g.has(e.cap)?`default`:`info`,children:g.has(e.cap)?l(`compositionEditor.replaces`):l(`compositionEditor.added`)}),s(`button`,{type:`button`,"aria-label":l(`compositionEditor.removeFeature`,{cap:e.cap}),onClick:()=>c({type:`remove-feature`,cap:e.cap}),children:`×`})]},e.cap)),v.map(e=>i(D,{size:`sm`,variant:`outline`,onClick:()=>c({type:`add-feature`,cap:e.cap}),children:[`+ `,e.cap]},e.cap)),y.map(e=>s(D,{size:`sm`,variant:`ghost`,onClick:()=>c({type:`add-feature`,cap:e}),children:l(`compositionEditor.replaceIn`,{cap:e})},e))]})]}),e.features.map(e=>i(`section`,{"aria-label":l(`compositionEditor.steps.fieldsOf`,{cap:e.cap}),className:`${F} flex flex-col gap-2`,children:[i(`div`,{className:`flex items-center justify-between`,children:[s(`h2`,{className:`text-sm font-semibold`,children:l(`compositionEditor.steps.fieldsOf`,{cap:e.cap})}),s(D,{size:`sm`,variant:`outline`,onClick:()=>m(e.cap),children:l(`compositionEditor.copyFeature`)})]}),p===e.cap&&s(J,{title:l(`compositionEditor.copyFeature`),targetKind:null,onCancel:()=>m(null),onPick:t=>{c({type:`copy-feature`,cap:e.cap,from:t.ref,sourceCap:t.cap,paths:b(e.cap).map(e=>e.path)}),m(null)}}),b(e.cap).map(t=>s(ft,{path:t.path,kind:t.kind,required:t.required,source:e.fields[t.path],onSet:n=>c({type:`set-field`,cap:e.cap,path:t.path,source:n}),onClear:()=>c({type:`clear-field`,cap:e.cap,path:t.path}),onRemoveBinding:n=>c({type:`remove-binding`,cap:e.cap,path:t.path,bindingName:n}),sourceNames:f},t.path))]},e.cap))]}):i(`section`,{"aria-labelledby":`editor-features`,className:`${F} flex flex-col gap-2`,children:[s(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:h.kind===`unknown`?h.reason:l(`compositionEditor.reading`)})]})}var $=`px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`;function mt({draft:e,targetName:t,dispatch:n}){let{t:r}=A(),a=e.target;return i(`section`,{"aria-labelledby":`editor-target`,className:`${F} flex flex-col gap-2`,children:[s(`h2`,{id:`editor-target`,className:`text-sm font-semibold`,children:r(`compositionEditor.steps.target`)}),a.kind===`existing`?s(`p`,{className:`text-[11px]`,children:r(`compositionEditor.existingTarget`,{name:t??`${a.device.addonId}/${a.device.stableId}`})}):i(`div`,{className:`grid grid-cols-3 gap-2`,children:[i(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[r(`compositionEditor.targetType`),s(`select`,{className:$,value:a.type,onChange:e=>{let t=Object.values(p).find(t=>t===e.target.value);t!==void 0&&n({type:`set-new-type`,deviceType:t})},children:Object.values(p).map(e=>s(`option`,{value:e,children:he(e).label},e))})]}),i(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[r(`customize.identity.role`),i(`select`,{className:$,value:a.role??``,onChange:e=>n({type:`set-new-role`,role:Object.values(w).find(t=>t===e.target.value)??null}),children:[s(`option`,{value:``,children:r(`customize.identity.noRole`)}),Object.values(w).map(e=>s(`option`,{value:e,children:de(e).label},e))]})]}),i(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[r(`compositionEditor.name`),s(`input`,{className:$,value:e.name,onChange:e=>n({type:`set-name`,name:e.target.value})})]})]})]})}r();function ht({draft:e,blockId:t,saving:n,onSave:r,onCancel:a}){let{t:l}=A(),u=oe(),d=ye(e),f=d.ok?JSON.stringify(d.composition):``,[p,m]=o({key:``,state:{kind:`checking`}});c(()=>{if(!d.ok)return;let e=d.composition,n=setTimeout(()=>{u.mutateAsync({composition:e,...t===null?{}:{blockId:t}}).then(e=>m({key:f,state:e.ok?{kind:`ok`}:{kind:`refused`,problems:e.problems}})).catch(e=>m({key:f,state:{kind:`unknown`,reason:e instanceof Error?e.message:String(e)}}))},500);return()=>clearTimeout(n)},[f,t]);let h=d.ok?p.key===f?p.state:{kind:`checking`}:{kind:`invalid-draft`,problems:d.problems};return i(`section`,{"aria-labelledby":`editor-verify`,className:`${F} flex flex-col gap-2`,children:[s(`h2`,{id:`editor-verify`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.verify`)}),h.kind===`checking`&&s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.verify.checking`)}),h.kind===`ok`&&s(`p`,{className:`text-[11px] text-success`,children:l(`compositionEditor.verify.ok`)}),h.kind===`unknown`&&s(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.verify.unknown`,{reason:h.reason})}),(h.kind===`invalid-draft`||h.kind===`refused`)&&s(`ul`,{role:`alert`,className:`flex flex-col gap-1 text-[11px] text-danger`,children:h.kind===`invalid-draft`?h.problems.map(e=>s(`li`,{children:e},e)):h.problems.map(e=>i(`li`,{children:[s(`span`,{className:`font-mono`,children:e.path}),` — `,e.message]},`${e.path}:${e.code}`))}),i(`div`,{className:`flex gap-2`,children:[s(D,{variant:`ghost`,onClick:a,children:l(`compositionEditor.cancel`)}),s(D,{disabled:h.kind!==`ok`||n||!d.ok,onClick:()=>d.ok&&r(d.composition),children:l(`compositionEditor.save`)})]})]})}r();function gt({initial:e,blockId:t,deviceType:n,targetName:r=null,nativeCaps:i,targetFields:a,save:c,onCancel:l,showTemplates:u=!1}){let[d,f]=o(e),p=`${d.name}:${d.features.map(e=>e.cap).join(`,`)}:${d.target.kind===`new`?d.target.type:`existing`}`;return s(_t,{seed:d,blockId:t,deviceType:n,targetName:r,nativeCaps:i,targetFields:a,showTemplates:u,onApplyTemplate:e=>{f(Ee(e))},save:c,onCancel:l},p)}function _t({seed:t,blockId:n,deviceType:r,targetName:a,nativeCaps:c,targetFields:l,showTemplates:u,onApplyTemplate:d,save:f,onCancel:p}){let{t:m}=A(),h=le(),[g,_]=e(ve,t),[v,y]=o(!1),[b,x]=o(null),S=async e=>{be(t,g)&&!await h({title:m(`compositionEditor.templates.confirmTitle`),message:m(`compositionEditor.templates.confirmMessage`),confirmLabel:m(`compositionEditor.templates.confirmApply`),variant:`danger`})||d(e)},C=g.target.kind===`new`?g.target.type:r,w=async e=>{y(!0);let t=await f(e,g.name);y(!1),x(t.kind===`refused`?t.reason:null)};return i(`div`,{className:`flex flex-col gap-4`,children:[u&&g.target.kind===`new`&&i(`div`,{className:`rounded-lg border border-border bg-surface p-4 flex flex-wrap gap-2`,"data-testid":`composition-templates`,children:[s(`span`,{className:`text-[11px] text-foreground-subtle self-center`,children:m(`compositionEditor.templates.label`)}),Se.map(e=>s(D,{size:`sm`,variant:`outline`,onClick:()=>void S(e),children:m(`compositionEditor.templates.${e}`)},e))]}),s(mt,{draft:g,targetName:a,dispatch:_}),s(pt,{draft:g,deviceType:C,nativeCaps:c,targetFields:l,dispatch:_}),s(ht,{draft:g,blockId:n,saving:v,onSave:e=>void w(e),onCancel:p}),b!==null&&s(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:b})]})}export{je as C,_e as D,j as E,ge as O,Ae as S,De as T,W as _,Y as a,Pe as b,G as c,Ie as d,Re as f,Be as g,Ue as h,nt as i,Fe as l,He as m,st as n,q as o,Ve as p,ot as r,K as s,gt as t,H as u,ze as v,Oe as w,z as x,Me as y};
@@ -1 +0,0 @@
1
- import{D as e,K as t,L as n,Q as r,S as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Jt as d,Nt as f,On as p,Pi as m,V as h,ar as g,cr as _,fn as v,kn as y,yn as b}from"./player-overlays-DEJGWVeQ.js";import{t as x}from"./settings-2-0Dzmg5ID.js";import{Bn as S,It as C,Ln as ee,Mr as w,Pn as T,Rn as E,Rr as D,Tt as O,Vt as k,ar as te,wt as ne}from"./src-CVCI1YgT.js";import{J as A,Q as j,d as M,f as N,h as P,l as F,m as I,o as L,u as R}from"./index-D7FGxQMl.js";import{t as z}from"./AdminPage-250c5IIz.js";import{t as B}from"./NodeAddonsSettingsPanel-Dh4z-QGr.js";import{t as V}from"./AddonAssetIcon-CYCgFnh-.js";r();function H(e){let{ids:t,answered:n,legacyGroupParam:r=null,groupFirst:i}=e,[o]=j(),s=o.get(F),c=r===null?null:o.get(r),l=o.get(R),u=a(()=>I({ids:t,requested:s,answered:n,legacyGroup:c,...i===void 0?{}:{groupFirst:i}}),[t,s,n,c,i]),d=a(()=>(e,t)=>`?${P(o,e,r,t??null).toString()}`,[o,r]);return{...u,requestedSection:l,hrefFor:d}}var U=[[[`addons`,`listCapabilityProviders`]],[[`addons`,`list`]]],W=`text-[10px]`;function G({isActive:e}){return l(te,{variant:e?`success`:`default`,className:W,children:e?`Enabled`:`Disabled`})}function K({capName:e,addonId:t,isActive:n}){let r=s(),a=D({onSuccess:()=>{for(let e of U)r.invalidateQueries({queryKey:e})}}),o=a.isPending;return i(S,{size:`sm`,variant:n?`secondary`:`primary`,disabled:o,onClick:()=>a.mutate({capName:e,addonId:t,enabled:!n}),children:[o?l(g,{className:`h-3 w-3 animate-spin`}):l(n?d:y,{className:`h-3 w-3`}),n?`Disable`:`Enable`]})}function re({addonId:e,displayName:t}){let n=s(),r=w({onSuccess:()=>{for(let e of U)n.invalidateQueries({queryKey:e})}});return l(C,{label:`Restart`,icon:b,size:`sm`,title:`Restart "${t}"?`,description:`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`ghost`,confirmVariant:`danger`,disabled:r.isPending,action:()=>r.mutateAsync({addonId:e})})}r();var q=600,J=e(null);function Y({id:e,title:r,icon:a,actions:s,framed:c=!1,children:u}){let d=n(J),f=t(null),p=`integration-section-${e}`;X(f,d,e);let m=i(o,{children:[d===null?null:l(A,{to:d.sectionHref(e),"aria-label":`Link to ${r}`,title:`Link to ${r}`,className:`rounded p-0.5 text-foreground-subtle/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,children:l(_,{className:`h-3 w-3`,"aria-hidden":!0})}),s]});return c?l(`div`,{ref:f,className:`scroll-mt-4`,children:l(k,{headingId:p,title:r,icon:a,actions:m,children:u})}):i(`section`,{ref:f,"aria-labelledby":p,className:`scroll-mt-4 space-y-2`,children:[i(`header`,{className:`flex min-h-7 flex-wrap items-center gap-2 px-0.5`,children:[a!==void 0&&l(a,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),l(`h2`,{id:p,className:`${h} min-w-0 flex-1`,children:r}),m]}),u]})}function X(e,t,n){let r=t?.requestedSection===n,i=t?.integrationId;u(()=>{if(!r)return;let t=()=>e.current?.scrollIntoView?.({block:`start`});t();let n=!1,i=()=>{n=!0},a=[`wheel`,`touchmove`,`keydown`];for(let e of a)window.addEventListener(e,i,{once:!0,passive:!0});let o=window.setTimeout(()=>{n||t()},q);return()=>{window.clearTimeout(o);for(let e of a)window.removeEventListener(e,i)}},[r,i,e])}r();var Z=`max-h-72`;function ie({addonId:e,displayName:t,capName:n,isActive:r,badges:a,primaryAction:o,error:s=null,lead:c,panels:u=[],settingsContent:d}){let f=u.filter(e=>e.placement!==`end`),p=u.filter(e=>e.placement===`end`);return i(`div`,{className:`flex flex-col gap-4`,children:[l(ae,{addonId:e,displayName:t,capName:n,isActive:r,badges:a,primaryAction:o}),s!==null&&l(ee,{message:s}),c,l(Q,{panels:f}),l(Y,{id:M,title:`Settings`,icon:x,children:d===void 0?l(B,{nodeId:`hub`,addonIds:[e],level:`global`,capability:n}):d}),l($,{addonId:e}),l(Q,{panels:p})]})}function Q({panels:e}){return l(o,{children:e.map(e=>l(Y,{id:e.id,title:e.title,icon:e.icon,children:e.content},e.id))})}function ae({addonId:e,displayName:t,capName:n,isActive:r,badges:a,primaryAction:o}){return i(`div`,{className:`flex flex-wrap items-center justify-between gap-2 rounded-lg border border-border bg-surface px-2 py-1.5 sm:px-3`,"data-testid":`integration-status-strip`,children:[i(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[l(G,{isActive:r}),a,l(`span`,{className:`break-all font-mono text-[11px] text-foreground-subtle`,children:e})]}),i(`div`,{className:`flex flex-wrap items-center justify-end gap-1`,children:[o,l(K,{capName:n,addonId:e,isActive:r}),l(re,{addonId:e,displayName:t})]})]})}var oe=[{kind:`logs`,label:`Logs`,icon:v},{kind:`events`,label:`Events`,icon:m}];function $({addonId:e}){let[t,n]=c(`logs`);return l(Y,{id:L,title:`Activity`,framed:!0,actions:l(`div`,{role:`group`,"aria-label":`Activity stream`,className:`flex items-center gap-1`,children:oe.map(({kind:e,label:r,icon:a})=>i(`button`,{type:`button`,"aria-pressed":t===e,onClick:()=>n(e),className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${t===e?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[l(a,{className:`h-3 w-3`,"aria-hidden":!0}),r]},e))}),children:t===`logs`?l(O,{addonId:e,maxHeight:Z,showFilters:!1}):l(ne,{addonId:e,category:`addon.*`,maxHeight:Z})})}var se=`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,ce=`border-primary bg-primary/10 text-primary font-medium`,le=`border-border bg-surface text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,ue={ok:`bg-success`,off:`bg-foreground-subtle/60`,error:`bg-danger`,unknown:`border border-foreground-subtle bg-transparent`};function de({label:e,groups:t,selectedId:n,hrefFor:r}){let a=t.length>1;return l(`nav`,{"aria-label":e,className:a?`flex flex-col gap-2 sm:grid sm:grid-cols-[max-content_minmax(0,1fr)] sm:items-start sm:gap-x-3`:`flex flex-col`,children:t.map(e=>i(`div`,{role:`group`,"aria-label":e.label,className:a?`flex min-w-0 flex-col gap-1 sm:col-span-2 sm:grid sm:grid-cols-subgrid sm:items-start`:`min-w-0`,children:[a&&l(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle sm:pt-2`,children:e.label}),i(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[e.entries.map(e=>l(fe,{entry:e,current:e.id===n,href:r(e.id)},e.id)),e.install&&i(A,{to:N(e.install.capability),className:`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 border-dashed border-border pl-2 text-foreground-subtle hover:border-primary/50 hover:text-foreground`,children:[l(p,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),l(`span`,{className:`truncate`,children:e.install.label})]})]})]},e.id))})}function fe({entry:e,current:t,href:n}){let r=e.state===`ok`;return i(A,{to:n,"aria-current":t?`true`:void 0,className:`${se} ${t?ce:le}`,"data-testid":`integration-pill-${e.id}`,children:[l(V,{addonId:e.id,fallback:e.fallbackIcon,tileClassName:``,size:`sm`}),l(`span`,{className:`truncate`,children:e.name}),e.showState!==!1&&l(pe,{entry:e,quiet:r})]})}function pe({entry:e,quiet:t}){return i(o,{children:[l(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${ue[e.state]}`,"aria-hidden":!0}),l(`span`,{className:t?`sr-only`:`shrink-0 text-[10px] font-normal text-foreground-subtle`,children:e.stateLabel})]})}r();function me({icon:e,title:t,subtitle:n,groups:r,isLoading:s,emptyTitle:c,emptyDescription:u,legacyGroupParam:d,trailing:f,embedded:p=!1}){let m=a(()=>r.flatMap(e=>e.entries),[r]),h=a(()=>m.map(e=>e.id),[m]),g=a(()=>{let e={};for(let t of r){let n=t.entries[0];n!==void 0&&(e[t.id]=n.id)}return e},[r]),_=H({ids:h,answered:!s,legacyGroupParam:d??null,groupFirst:g}),v=m.find(e=>e.id===_.selectedId)??null,y=a(()=>v===null?null:{integrationId:v.id,requestedSection:_.requestedSection,sectionHref:e=>_.hrefFor(v.id,e)},[v,_]),b=s?null:l(de,{label:`${t} integrations`,groups:r,selectedId:_.selectedId,hrefFor:e=>_.hrefFor(e)}),x=s?l(T,{children:l(`div`,{className:`p-6 text-sm text-foreground-subtle`,children:`Loading…`})}):i(o,{children:[_.staleId!==null&&l(ge,{staleId:_.staleId,shownName:v?.name??null}),v!==null&&y!==null?l(J.Provider,{value:y,children:l(`div`,{role:`region`,"aria-label":v.name,"data-testid":`integration-body`,children:v.render()},v.id)}):l(he,{groups:r,title:c,description:u}),f]});return p?i(`div`,{className:`space-y-3`,"data-testid":`integration-hub-embedded`,children:[b,x]}):l(z,{icon:e,title:t,subtitle:n,nav:b,children:x})}function he({groups:e,title:t,description:n}){let r=e.find(e=>e.install!==void 0)?.install;return l(T,{children:l(E,{title:t,description:n,action:r?l(A,{to:N(r.capability),children:i(S,{variant:`primary`,size:`sm`,children:[l(p,{className:`mr-1 h-3.5 w-3.5`}),r.label]})}):void 0})})}function ge({staleId:e,shownName:t}){return i(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-[11px] text-foreground-subtle`,children:[l(f,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),i(`span`,{children:[`This link named `,l(`span`,{className:`font-mono text-foreground`,children:e}),`, which is not installed here.`,t!==null&&i(o,{children:[` `,`Showing `,l(`span`,{className:`font-medium text-foreground`,children:t}),` instead.`]})]})]})}export{H as i,ie as n,W as r,me as t};
@@ -1 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,W as i,a,b as o,o as s,q as c,t as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Dn as f,It as p,On as m,Pn as h,Q as g,ar as _,bn as v,cn as y,ht as b,ot as ee,tr as te}from"./player-overlays-DEJGWVeQ.js";import{m as x,o as S}from"./video-47m9GMk0.js";import{t as C}from"./log-in-xkUb0jne.js";import{t as w}from"./monitor-smartphone-DmzFXiIW.js";import{t as ne}from"./recycle-Cg5L5URL.js";import{Dr as T,Nt as E,ar as D}from"./client-Cm-sr0wc.js";import{$ as O,An as k,Bn as A,Dn as j,En as re,Er as ie,Ht as ae,L as oe,Ln as M,On as N,Q as P,Tn as F,Vi as I,Zn as se,_i as ce,ar as L,bn as le,di as R,fi as z,gi as ue,hi as B,jn as V,mi as H,vi as de,yi as fe,z as pe,zn as me}from"./src-CVCI1YgT.js";import{t as U}from"./useTranslation-Bc5yH9V9.js";import"./mount-DSRwVBTr.js";import{C as W,I as he,Q as ge,X as _e,r as ve,s as ye,t as be}from"./index-D7FGxQMl.js";import{t as xe}from"./AdminSectionedPage-Bx9l4jGV.js";import{t as Se}from"./NodeAddonsSettingsPanel-Dh4z-QGr.js";import{t as Ce}from"./BrokerForm-nkI-Qcl_.js";import{n as we,r as G,t as Te}from"./IntegrationHub-Bufk1Dn6.js";n();var K=`kind`,q=`name`,J=`restore`,Y=`restoreId`;function Ee(e){return{sections:[{id:`broker-identity`,title:`Broker`,columns:1,fields:[{type:`select`,key:K,label:`Kind`,options:e.map(e=>({value:e.key,label:e.label})),disabled:e.length<=1},{type:`text`,key:q,label:`Name`,placeholder:`My Home Assistant`,required:!0},{type:`boolean`,key:J,label:`Restore a broker that was removed, under its original id`,description:`Devices remember the broker id they were discovered under, so restoring the original id reconnects them instead of needing re-discovery. An id that is still in use is refused.`},{type:`text`,key:Y,label:`Original broker id`,placeholder:`ha_004`,required:!0,showWhen:{field:J,equals:!0}}]}]}}function De(e){let t=t=>{let n=e[t];return typeof n==`string`?n.trim():``},n=t(K);if(n===``)return{ok:!1,problem:`Pick a kind.`};let r=t(q);if(r===``)return{ok:!1,problem:`Enter a name before saving.`};if(e.restore!==!0)return{ok:!0,identity:{kindKey:n,name:r,restoreId:null}};let i=t(Y);return i===``?{ok:!1,problem:`Enter the original id, or turn restore off to create a new broker.`}:{ok:!0,identity:{kindKey:n,name:r,restoreId:i}}}function Oe(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.type===`camstack:broker-oauth`&&typeof t.ok==`boolean`}function ke(e,t){return e.split(`{{brokerId}}`).join(encodeURIComponent(t))}function Ae(e,t,n=window){let r=n.location.origin,i=!1,a=e=>{i||(i=!0,n.removeEventListener(`message`,o),window.clearInterval(s),t(e))},o=t=>{t.origin!==r||t.source!==e||Oe(t.data)&&a({ok:t.data.ok,...t.data.brokerId===void 0?{}:{brokerId:t.data.brokerId},...t.data.error===void 0?{}:{error:t.data.error}})};n.addEventListener(`message`,o);let s=window.setInterval(()=>{e.closed&&a({ok:!0})},500);return()=>{i=!0,n.removeEventListener(`message`,o),window.clearInterval(s)}}function X(e,t,n){let r=g(ve(ke(e,t))),i=be(r);if(i===null){window.location.assign(r);return}Ae(i,e=>{n?.(e)})}var je={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function Z(e){return je[e]??e}function Me(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var Ne={connected:`success`,connecting:`warning`,disconnected:`default`,"auth-failed":`danger`,unreachable:`danger`,error:`danger`};function Pe({status:e}){return u(L,{variant:Ne[e],className:`text-[10px]`,children:e})}function Fe(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function Ie({title:e,subtitle:t,onClose:n,children:i}){return u(F,{open:!0,onOpenChange:e=>!e&&n(),children:r(j,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[r(k,{children:[u(V,{children:e}),t&&u(N,{children:t})]}),u(re,{className:`space-y-3 pr-1`,children:i})]})})}function Le({kinds:e,onClose:t,onDone:n}){let a=s(),o=i(()=>Ee(e.map(e=>({key:Q(e),label:e.label}))),[e]),[l,d]=c(()=>({[K]:Q(e[0]),[q]:``,[J]:!1,[Y]:``})),[f,p]=c(null),m=e.find(e=>Q(e)===l.kind)??e[0],h=m?.kind??``,g=m?.addonId,_=m?.interactiveConnectPath,v=R({onSuccess:e=>{a.invalidateQueries({queryKey:[[`broker`,`list`]]});let t=typeof e==`object`&&e&&typeof e.id==`string`?e.id:null;t!==null&&_!==void 0&&_.length>0&&X(_,t,()=>{a.invalidateQueries({queryKey:[[`broker`,`list`]]})}),n()}}),y=e=>{let t=De(l);if(!t.ok){p(t.problem);return}p(null);let{name:n,restoreId:r}=t.identity;v.mutate({kind:h,name:n,settings:e,...r===null?{}:{id:r},...g===void 0?{}:{addonId:g}})};return r(Ie,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:v.isPending?()=>{}:t,children:[u(he,{schema:o,values:l,onChange:d}),f!==null&&u(M,{message:f}),v.isError&&u(M,{message:v.error instanceof Error?v.error.message:String(v.error)}),h&&u(Ce,{kind:h,...g===void 0?{}:{addonId:g},onSubmit:y,onCancel:t,submitLabel:v.isPending?`Adding…`:`Add broker`,disabled:v.isPending},Q(m))]})}function Q(e){return e===void 0?``:`${e.addonId??``}::${e.kind}`}function Re({broker:e,onClose:t,onDone:n}){let a=s(),o=z({id:e.id,addonId:e.addonId}),c=de({onSuccess:()=>{a.invalidateQueries({queryKey:[[`broker`,`list`]]}),a.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),n()}}),l=i(()=>{let e=o.data;return e&&typeof e==`object`?{...e}:{}},[o.data]);return u(Ie,{title:`Edit ${e.name}`,subtitle:`${Z(e.kind)} · ${e.id}`,onClose:c.isPending?()=>{}:t,children:o.isLoading?r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[u(_,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):o.isError?r(`div`,{className:`space-y-3`,children:[u(M,{message:`Failed to load settings: ${o.error instanceof Error?o.error.message:`Unknown error`}`}),u(`div`,{className:`flex justify-end`,children:u(A,{variant:`outline`,size:`sm`,onClick:t,children:`Close`})})]}):r(`div`,{className:`space-y-3`,children:[c.isError&&u(M,{message:c.error instanceof Error?c.error.message:String(c.error)}),u(Ce,{kind:e.kind,addonId:e.addonId,brokerId:e.id,initialValues:l,onSubmit:t=>{c.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:t,submitLabel:c.isPending?`Saving…`:`Save`,disabled:c.isPending})]})})}function ze({broker:e,interactiveConnectPath:t,interactiveDisconnectPath:n,onEdit:i}){let a=s(),o=se(),[l,d]=c(null),f=fe({onSuccess:e=>d(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>d({ok:!1,error:e instanceof Error?e.message:String(e)})}),m=ce({onSuccess:()=>{a.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),g=async()=>{await o({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&m.mutate({id:e.id,addonId:e.addonId})},v=t!==void 0&&t.length>0&&e.status!==`connected`,y=n!==void 0&&n.length>0&&e.status===`connected`;return r(`tr`,{className:`border-b border-border last:border-0`,children:[u(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),u(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:Z(e.kind)}),r(`td`,{className:`px-3 py-2`,children:[u(Pe,{status:e.status}),l&&u(`span`,{className:`ml-2 text-[10px] ${l.ok?`text-success`:`text-danger`}`,children:l.ok?`OK`:l.error??`failed`})]}),u(`td`,{className:`px-3 py-2`,children:r(`div`,{className:`flex items-center justify-end gap-1.5`,children:[v&&r(A,{variant:`primary`,size:`sm`,onClick:()=>{X(t,e.id,()=>{a.invalidateQueries({queryKey:[[`broker`,`list`]]})})},title:`Sign in — opens a popup that closes when done`,children:[u(C,{className:`h-3 w-3`}),` Sign in`]}),y&&r(A,{variant:`outline`,size:`sm`,onClick:()=>{X(n,e.id,()=>{a.invalidateQueries({queryKey:[[`broker`,`list`]]})})},title:`Sign out — clears the linked Google account on this broker`,children:[u(S,{className:`h-3 w-3`}),` Sign out`]}),r(A,{variant:`outline`,size:`sm`,onClick:()=>f.mutate({id:e.id,addonId:e.addonId}),disabled:f.isPending,title:`Test connection`,children:[f.isPending?u(_,{className:`h-3 w-3 animate-spin`}):u(b,{className:`h-3 w-3`}),`Test`]}),r(A,{variant:`outline`,size:`sm`,onClick:()=>i(e),title:`Edit`,children:[u(h,{className:`h-3 w-3`}),` Edit`]}),r(A,{variant:`outline`,size:`sm`,className:`border-danger/40 text-danger hover:bg-danger/10`,onClick:()=>{g()},disabled:m.isPending,title:`Delete`,children:[m.isPending?u(_,{className:`h-3 w-3 animate-spin`}):u(p,{className:`h-3 w-3`}),`Delete`]})]})})]})}function Be({addonId:e}={}){let t=B({}),n=ue(),a=i(()=>Fe(t.data).filter(t=>e===void 0||t.addonId===e),[t.data,e]),[o,s]=c(!1),[l,d]=c(null),f=i(()=>{let t=new Map;for(let r of Me(n.data))if(!(e!==void 0&&r.addonId!==e))for(let e of r.kinds){let n=typeof e.interactiveConnectPath==`string`&&e.interactiveConnectPath.length>0?e.interactiveConnectPath:void 0,i=typeof e.interactiveDisconnectPath==`string`&&e.interactiveDisconnectPath.length>0?e.interactiveDisconnectPath:void 0;t.set(`${r.addonId}::${e.kind}`,{addonId:r.addonId,kind:e.kind,label:e.label,...n===void 0?{}:{interactiveConnectPath:n},...i===void 0?{}:{interactiveDisconnectPath:i}})}for(let e of a)[...t.values()].some(t=>t.kind===e.kind)||t.set(`::${e.kind}`,{kind:e.kind,label:Z(e.kind)});return[...t.values()]},[a,n.data,e]),p=i(()=>{let e=new Map;for(let t of f)e.has(t.kind)||e.set(t.kind,{...t.interactiveConnectPath===void 0?{}:{connect:t.interactiveConnectPath},...t.interactiveDisconnectPath===void 0?{}:{disconnect:t.interactiveDisconnectPath}});return e},[f]);return r(`div`,{className:`space-y-3`,children:[u(`div`,{className:`flex items-center justify-end`,children:r(A,{variant:`primary`,size:`sm`,onClick:()=>s(!0),disabled:f.length===0,title:f.length===0?`No broker providers available`:void 0,children:[u(m,{className:`h-3.5 w-3.5`}),` Add broker`]})}),u(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:r(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[u(`thead`,{children:r(`tr`,{className:`border-b border-border bg-background/50`,children:[u(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Name`}),u(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Kind`}),u(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Status`}),u(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Actions`})]})}),r(`tbody`,{children:[t.isLoading&&u(`tr`,{children:r(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[u(_,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),t.isError&&u(`tr`,{children:r(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,t.error instanceof Error?t.error.message:`Unknown error`]})}),!t.isLoading&&!t.isError&&a.length===0&&u(`tr`,{children:u(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`No brokers registered yet. Add one to publish device events for downstream automations.`})}),a.map(e=>{let t=p.get(e.kind);return u(ze,{broker:e,...t?.connect===void 0?{}:{interactiveConnectPath:t.connect},...t?.disconnect===void 0?{}:{interactiveDisconnectPath:t.disconnect},onEdit:d},e.id)})]})]})}),o&&u(Le,{kinds:f,onClose:()=>s(!1),onDone:()=>s(!1)}),l&&u(Re,{broker:l,onClose:()=>d(null),onDone:()=>d(null)})]})}function Ve(e){if(typeof e==`string`)return e;if(typeof e==`object`&&e){let t=e.name;if(typeof t==`string`)return t}return null}function He(e){let t=e,n=t?.manifest;if(n?.id===void 0)return null;let r=(n.capabilities??[]).map(Ve).filter(e=>e!==null);return{addonId:n.id,displayName:n.packageDisplayName??n.name??n.id,capNames:r,processState:t?.process?.state??null}}function Ue(e,t){return Object.entries(e).filter(([,e])=>e===t).map(([e])=>e)}function We(e,t){return t.find(t=>e.capNames.includes(t))??null}function Ge(e){switch(e){case`running`:return{state:`ok`,label:`running`};case`crashed`:case`failed`:return{state:`error`,label:e};case`stopped`:case`disabled`:return{state:`off`,label:`stopped`};default:return{state:`unknown`,label:e??`unknown`}}}n();var Ke=[`wasteCollections`,`listSources`],qe=[`wasteCollections`,`listCountries`];function Je(e){return e instanceof Error?e.message:String(e)}function Ye(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function Xe(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n!=`object`||!n)continue;let e=Reflect.get(n,`id`),r=Reflect.get(n,`label`),i=Reflect.get(n,`module`);if(typeof e!=`string`||typeof r!=`string`||typeof i!=`string`)continue;let a=Reflect.get(n,`argsJson`),o=Reflect.get(n,`enabled`),s=Reflect.get(n,`formValues`),c=Reflect.get(n,`serviceId`),l=Reflect.get(n,`countryId`);t.push({id:e,label:r,module:i,argsJson:typeof a==`string`?a:`{}`,enabled:typeof o==`boolean`?o:!0,formValues:typeof s==`object`&&s&&!Array.isArray(s)?s:void 0,serviceId:typeof c==`string`?c:void 0,countryId:typeof l==`string`?l:void 0})}return t}function Ze(e){return Array.isArray(e)?e.flatMap(e=>{if(typeof e!=`object`||!e)return[];let t=Reflect.get(e,`id`),n=Reflect.get(e,`label`);return typeof t!=`string`||typeof n!=`string`?[]:[{id:t,label:n}]}):[]}function Qe(e){return Array.isArray(e)?e.flatMap(e=>{if(typeof e!=`object`||!e)return[];let t=Reflect.get(e,`id`),n=Reflect.get(e,`label`),r=Reflect.get(e,`module`);if(typeof t!=`string`||typeof n!=`string`||typeof r!=`string`)return[];let i=Reflect.get(e,`title`);return[{id:t,label:n,title:typeof i==`string`&&i.length>0?i:n,module:r}]}):[]}function $e(e,t,n){return{sections:[{id:`picker`,title:`Country & service`,columns:2,fields:[{type:`select`,key:`countryId`,label:`Country`,options:[{value:``,label:`Select country…`},...e.map(e=>({value:e.id,label:e.label}))]},{type:`select`,key:`serviceId`,label:`Service`,options:[{value:``,label:n===``?`Pick a country first`:`Select service…`},...t.map(e=>({value:e.id,label:e.label}))]}]}]}}function et({addonId:n,capName:f}){let h=ee(),g=s(),_=se(),v=oe({editKey:`wasteEdit`,newKey:`wasteNew`}),[y,b]=c(!1),[te,x]=c(null),[S,C]=c({countryId:``,serviceId:``}),[w,T]=c({label:`New source`,enabled:!0}),E=t(null),D=typeof S.countryId==`string`?S.countryId:``,O=typeof S.serviceId==`string`?S.serviceId:``,k=e((e,t)=>h.trpcClient.addons.custom.mutate({addonId:n,action:e,input:t}),[n,h]),j=a({queryKey:[...Ke,n],queryFn:async()=>Xe(await k(`listSources`,{}))}),re=a({queryKey:[...qe,n],queryFn:async()=>Ze(await k(`listCountries`,{}))}),ie=a({queryKey:[`wasteCollections`,`listServices`,n,D],enabled:D!==``,queryFn:async()=>Qe(await k(`listServices`,{countryId:D}))}),M=a({queryKey:[`wasteCollections`,`serviceFormSchema`,n,O],enabled:O!==``,queryFn:async()=>k(`serviceFormSchema`,{serviceId:O})}),N=j.data??[],P=re.data??[],F=ie.data??[],I=Ye(M.data)?M.data:void 0,ce=i(()=>$e(P,D===``?[]:F,D),[P,F,D]),R=v.state,z=R.mode===`edit`?N.find(e=>e.id===R.id)??null:null;d(()=>{if(v.state.mode===`edit`&&z!==null){let e=`edit:${z.id}`;if(E.current===e)return;E.current=e,x(null),C({countryId:z.countryId??``,serviceId:z.serviceId??``}),T(z.formValues===void 0?{label:z.label,enabled:z.enabled}:{...z.formValues});return}if(v.state.mode===`new`){if(E.current===`new`)return;E.current=`new`,x(null),C({countryId:``,serviceId:``}),T({label:`New source`,enabled:!0})}},[z,v.state]),d(()=>{if(v.state.mode!==`new`||O===``)return;let e=F.find(e=>e.id===O);e&&T(t=>{let n=t.label;return typeof n==`string`&&n!==``&&n!==`New source`?t:{...t,label:e.title}})},[v.state.mode,O,F]);let ue=e(e=>{C(t=>{let n=typeof e.countryId==`string`?e.countryId:``;return n===(typeof t.countryId==`string`?t.countryId:``)?e:{countryId:n,serviceId:``}})},[]),B=e(async()=>{await g.invalidateQueries({queryKey:Ke})},[g]),V=l({mutationFn:async e=>k(`deleteSource`,{id:e}),onSuccess:async()=>B()}),H=e(async e=>{await _({title:`Delete waste source?`,message:`Remove “${e.label}” (${e.id}). Its calendar under System → Calendars is dropped.`,confirmLabel:`Delete`,cancelLabel:`Cancel`,variant:`danger`})&&(await V.mutateAsync(e.id),v.state.mode===`edit`&&v.state.id===e.id&&(v.close(),E.current=null))},[_,V,v]),de=e(async()=>{let e=w.label,t=typeof e==`string`&&e.trim()!==``?e.trim():``;if(t===``){x(`Label is required.`);return}if(O===``){x(`Pick a country and a service.`);return}let n=v.state.mode===`new`,r=z?.id;if(!n&&(r===void 0||r===``)){x(`That source is no longer available.`);return}let i=w.enabled,a={...w};delete a.label,delete a.enabled,b(!0),x(null);try{n?await k(`createSource`,{label:t,serviceId:O,args:a,enabled:typeof i==`boolean`?i:!0}):r!==void 0&&await k(`updateSource`,{id:r,label:t,serviceId:O,args:a,enabled:typeof i==`boolean`?i:!0}),await B(),v.close(),E.current=null}catch(e){x(Je(e))}finally{b(!1)}},[k,z,v,w,B,O]),fe=i(()=>[{key:`label`,header:`Label`,sortValue:e=>e.label,render:e=>u(`span`,{className:`text-sm text-foreground`,children:e.label})},{key:`module`,header:`Module`,sortValue:e=>e.module,render:e=>u(`span`,{className:`font-mono text-xs text-foreground-muted`,children:e.module})},{key:`enabled`,header:`Enabled`,sortValue:e=>+!!e.enabled,render:e=>u(L,{variant:e.enabled?`success`:`default`,children:e.enabled?`On`:`Off`})},{key:`actions`,header:``,notSortableReason:`actions`,render:e=>u(A,{type:`button`,size:`sm`,variant:`ghost`,"aria-label":`Delete ${e.label}`,"data-testid":`waste-source-delete-${e.id}`,onClick:t=>{t.stopPropagation(),H(e)},children:u(p,{className:`h-3.5 w-3.5 text-danger`})})}],[H]),U=v.state.mode===`new`,W=U||z!==null,he=`${O}:${U?`new`:z?.id??`closed`}`;return r(`div`,{className:`flex min-h-0 flex-col gap-4`,"data-testid":`waste-settings-sources`,children:[r(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[u(`p`,{className:`text-sm text-foreground-muted`,children:`Pick a country and a service — configuration fields come from that HACS source.`}),r(A,{type:`button`,size:`sm`,"data-testid":`waste-sources-add`,onClick:()=>v.openNew(),children:[u(m,{className:`h-3.5 w-3.5`}),`Add source`]})]}),j.isError?u(`p`,{className:`text-sm text-danger`,children:`Could not load sources.`}):null,j.isPending?u(me,{className:`h-32 w-full`}):u(ae,{columns:fe,rows:N,rowKey:e=>e.id,pageSize:25,mobileMode:`scroll`,emptyMessage:`No waste sources yet. Add one to register a municipal service.`,onRowClick:e=>v.openEdit(e.id),defaultSort:{columnKey:`label`,dir:`asc`}}),u(pe,{open:W,onClose:()=>{v.close(),x(null),E.current=null},title:U?`Add waste source`:`Edit ${z?.label??`source`}`,icon:ne,width:`xl`,testId:`waste-source-editor`,error:te,footer:u(A,{type:`button`,size:`sm`,disabled:y||O===``,onClick:()=>void de(),children:y?`Saving…`:`Save`}),children:W?r(o,{children:[u(`div`,{"data-testid":`waste-country-service`,children:u(le,{schema:ce,values:S,onChange:ue},`picker:${D}:${F.length}`)}),O!==``&&I!==void 0?u(le,{schema:I,values:w,onChange:T,bare:!0},he):O!==``&&M.isPending?u(`p`,{className:`text-sm text-foreground-muted`,children:`Loading fields…`}):u(`p`,{className:`text-sm text-foreground-muted`,children:`Choose a country and service to see the required fields.`})]}):null}),u(Se,{nodeId:`hub`,addonIds:[n],level:`global`,capability:f,hideSectionChrome:!0})]})}n();var $=1e4,tt={"device-export":`exporters`,exporters:`exporters`,email:`email`,broker:`brokers`,brokers:`brokers`,"message-brokers":`brokers`,calendar:`calendars`,calendars:`calendars`,"calendar-source":`calendars`},nt=[{sectionId:`exporters`,kind:`device-export`,label:`Exporters`,icon:y,installLabel:`Add export`,emptyTitle:`No device exporters installed`,emptyDescription:`Install an export addon to publish devices to Alexa, HomeKit, Google Home or Home Assistant.`},{sectionId:`email`,kind:`email`,label:`Email`,icon:te,installLabel:`Add email provider`,emptyTitle:`No email providers installed`,emptyDescription:`Install an SMTP or Gmail addon to send notification email from this hub.`},{sectionId:`brokers`,kind:`broker`,label:`Brokers`,icon:v,installLabel:`Add broker addon`,emptyTitle:`No message brokers installed`,emptyDescription:`Install a broker addon to connect Home Assistant, Homematic, MQTT, Matter and similar systems.`},{sectionId:`calendars`,kind:`calendar`,label:`Calendars`,icon:x,installLabel:`Add calendar source`,emptyTitle:`No calendar sources installed`,emptyDescription:`Install a calendar-source addon (Google Calendar, waste collections, …) to feed System → Calendars.`}];function rt(e,t,n){let i=Ue(E,e.kind),a=t.flatMap(t=>{let a=We(t,i);if(a===null)return[];let s=Ge(t.processState);return[{id:t.addonId,name:t.displayName,fallbackIcon:e.icon,state:s.state,stateLabel:s.label,render:()=>u(we,{addonId:t.addonId,displayName:t.displayName,capName:a,isActive:t.processState===`running`,badges:r(o,{children:[u(st,{processState:t.processState}),u(ct,{kind:e.kind,addonId:t.addonId})]}),lead:e.kind===`device-export`?u(O,{addonId:t.addonId}):void 0,panels:ot(e.kind,t.addonId,e=>n(`/devices/${e}`)),settingsContent:t.addonId===`waste-collections`?u(et,{addonId:t.addonId,capName:a}):void 0})}]});return{id:e.sectionId,label:e.label,entries:a,install:{capability:i[0]??e.kind,label:e.installLabel}}}function it({descriptor:e,rows:t,isLoading:n}){let r=_e(),a=i(()=>rt(e,t,r),[e,t,r]);return u(Te,{embedded:!0,icon:e.icon,title:e.label,subtitle:null,groups:[a],isLoading:n,emptyTitle:e.emptyTitle,emptyDescription:e.emptyDescription})}function at(){let{t:e}=U(),t=ie(void 0,{refetchInterval:$}),[n,r]=ge(),a=W(`/system/integrations`,{t:e,isAdmin:!0})??{icon:f,title:`Connectivity`};d(()=>{let e=n.get(`tab`);if(e===null)return;let t=tt[e];t===void 0||t===e||r(e=>{let n=new URLSearchParams(e);return n.set(`tab`,t),n},{replace:!0})},[n,r]);let o=i(()=>(t.data??[]).map(He).filter(e=>e!==null),[t.data]),s=i(()=>nt.map(e=>({id:e.sectionId,label:e.label,ownedParams:ye,content:u(it,{descriptor:e,rows:o,isLoading:t.isLoading})})),[t.isLoading,o]);return u(xe,{icon:a.icon,title:a.title,subtitle:`External systems this hub talks to — exporters, email, brokers and calendar sources.`,defaultSection:`exporters`,sectionsLabel:`Connectivity sections`,sections:s})}function ot(e,t,n){return e===`device-export`?[{id:`devices`,title:`Devices`,icon:w,placement:`end`,content:u(P,{addonId:t,onOpenDevice:n,showSetup:!1})}]:e===`broker`?[{id:`connections`,title:`Connections`,icon:v,content:u(Be,{addonId:t})}]:[]}function st({processState:e}){let{state:t,label:n}=Ge(e);return u(L,{variant:t===`ok`?`success`:t===`error`?`danger`:`default`,className:`${G} capitalize`,children:n})}function ct({kind:e,addonId:t}){return e===`broker`?u(lt,{addonId:t}):e===`device-export`?u(ut,{addonId:t}):null}function lt({addonId:e}){let{data:t}=H({addonId:e},{refetchInterval:$,retry:!1}),n=T.safeParse(t);if(!n.success)return null;let{brokerCount:r,connectedCount:i}=n.data;return u(L,{variant:`info`,className:G,children:`${r} connection${r===1?``:`s`}${i>0?` · ${i} connected`:``}`})}function ut({addonId:e}){let{data:t}=I({addonId:e},{refetchInterval:$,retry:!1}),n=D.safeParse(t);if(!n.success)return null;let{linkState:r,exposedDeviceCount:i}=n.data;return u(L,{variant:r===`linked`?`success`:r===`error`?`danger`:`default`,className:G,children:`${r} · ${i} exposed`})}export{at as IntegrationsPage};
@@ -1,3 +0,0 @@
1
- import{Q as e,S as t,W as n,b as r,o as i,q as a,x as o,z as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{$t as c,Br as l,Fi as u,Fr as d,Hi as f,It as p,Mr as m,O as h,On as g,Pn as _,Qi as v,Qr as y,Rt as b,V as x,Vr as S,Vt as C,Xi as w,Zi as T,_i as E,dt as D,er as O,fn as k,hr as A,ji as j,k as ee,ki as M,lr as N,nn as P,nr as F,pt as I,sn as L,ui as R,ut as z,wi as B,yi as te,yn as ne,z as V,zt as re}from"./player-overlays-DEJGWVeQ.js";import{t as ie}from"./boxes-gwiYF6bh.js";import{n as ae,r as oe,t as H}from"./speaker-D_GGxoIS.js";import{t as se}from"./user-round-Bn5beI9W.js";import{Qn as U,Xt as ce,er as le,rr as ue}from"./client-Cm-sr0wc.js";import{Aa as de,Bn as W,Da as fe,Ea as pe,Gi as me,Gl as G,Ht as K,Ma as he,Na as ge,Nt as _e,Pt as ve,Ql as ye,Ra as be,Ta as xe,W as Se,Wi as Ce,Xl as q,Zl as we,Zn as Te,_a as Ee,an as De,ar as Oe,au as ke,en as Ae,ga as je,ja as Me,ma as Ne,nn as Pe,on as Fe,ou as Ie,rn as Le,va as Re,wa as ze,ya as Be}from"./src-CVCI1YgT.js";import{t as Ve}from"./useTranslation-Bc5yH9V9.js";import{J,Q as He}from"./index-D7FGxQMl.js";import{t as Ue}from"./AdminSectionedPage-Bx9l4jGV.js";e();var We={camera:B,hub:ae,container:ie,light:N,siren:P,switch:re,sensor:v,thermostat:C,climate:T,button:R,"event-emitter":z,update:oe,notifier:u,script:k,automation:I,lock:F,cover:j,valve:S,humidifier:l,"water-heater":m,fan:d,"media-player":H,"alarm-panel":L,control:c,presence:se,weather:y,vacuum:M,"lawn-mower":b,image:A,smoke:w};function Y({type:e,className:t}){return o(We[e]??R,{"aria-hidden":`true`,className:t??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function X({online:e,deviceName:t}){return o(`span`,{className:e?`inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-success`:`inline-block h-1.5 w-1.5 shrink-0 rounded-full border border-foreground-subtle`,role:`img`,"aria-label":`${t}: ${e?`online`:`offline`}`,title:e?`online`:`offline`})}function Ge({name:e,description:n,busy:r,onSave:i}){let[c,l]=a(n??``);return s(()=>{l(n??``)},[n]),t(`div`,{className:`border-t border-border px-3 py-2 sm:px-4`,children:[o(Fe,{htmlFor:`location-description-${e}`,className:`block`,children:`What is there`}),o(`textarea`,{id:`location-description-${e}`,value:c,onChange:e=>l(e.target.value),onBlur:()=>{let e=c.trim();e!==(n??``)&&i(e.length===0?null:e)},disabled:r,rows:2,maxLength:400,placeholder:`Surfaces, boundaries, what is normally parked or stored here.`,className:`mt-1 w-full resize-y rounded-md border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-inset focus:ring-primary disabled:cursor-not-allowed disabled:opacity-50`}),o(`p`,{className:`mt-1 ${V}`,children:`Given to the AI with the pictures, so it knows what it is looking at. Describe the PLACE, not what happens in it — events change, the ground does not.`})]})}function Ke(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0||n.description.length===0?null:n.description}var Z=` none`;function qe({name:e,zones:n,zoneKey:r,busy:i,onChange:a}){if(n.length===0)return null;let s=[{value:Z,label:`— none —`},...n.map(e=>({value:e.zoneKey,label:e.label}))];return t(`div`,{className:`flex items-center gap-2 border-t border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:[o(Fe,{htmlFor:`location-zone-${e}`,children:`Zone`}),o(G,{id:`location-zone-${e}`,value:r??Z,disabled:i,onChange:e=>{let t=e.target.value;if(t===Z){a(null);return}let r=n.find(e=>e.zoneKey===t);r!==void 0&&a(r.label)},options:s})]})}function Je(e,t){return e.find(e=>e.locationKeys.includes(t))?.zoneKey??null}function Ye({name:e,icon:t,busy:n,onPick:r}){return o(ye,{value:t,onPick:r,fallbackGlyph:O,clearGlyph:f,labels:{trigger:`Change the icon of ${e}`,panel:`Icon for ${e}`,searchPlaceholder:`Search icons`,clear:`No icon`,noMatches:`No icon matches that`},disabled:n})}function Xe(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0?null:le(n.icon)??`map-pin`}function Q(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function Ze(e,t){let n=Q(t);return n===null?[]:e.filter(e=>Q(e.location)===n)}function Qe(e,t){let n=Ze(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function $e(e,t){let n=Q(e.location);return n===null||new Set(t.map(e=>Q(e))).has(n)?null:e.location?.trim()??null}function et(e,t){let n=Q(e.location);return n!==null&&t.has(n)}function tt(e,t){let n=new Set(t.map(e=>Q(e))),r=new Set(e.filter(e=>et(e,n)).map(e=>e.id));return e.filter(e=>!(et(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function nt(e,t){return tt(e,t).filter(e=>e.parentDeviceId===null)}function rt(e,t){let n=new Map;for(let t of e){if(t.parentDeviceId===null)continue;let e=n.get(t.parentDeviceId);e?e.push(t):n.set(t.parentDeviceId,[t])}let r=[],i=new Set([t]),a=[t];for(;a.length>0;){let e=[];for(let t of a)for(let a of n.get(t)??[])i.has(a.id)||(i.add(a.id),r.push(a),e.push(a.id));a=e}return r}function it(e,t){return rt(e,t).length}function at(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function ot(e,t){return t.map(t=>({name:t,members:Qe(e,t)}))}function st(e){return`${e.kind}:${String(e.device.id)}`}function ct(e,t,n){return e.flatMap(e=>{let r=at(t,e.id),i=n.has(e.id),a={kind:`member`,device:e,accessories:r,open:i};return!i||r.length===0?[a]:[a,...r.map(t=>({kind:`accessory`,device:t,parent:e}))]})}e();function lt({name:e,members:i,devices:s,busy:c,icon:l,description:u,onRename:d,onDelete:f,onRebuildLinks:m,onPickIcon:g,onSaveDescription:v,zones:y,zoneKey:b,onChangeZone:x}){let{t:S}=Ve(),[C,w]=a(!1),[T,E]=a(e),O=_e(i,n(()=>({searchText:e=>[e.name,...at(s,e.id).map(e=>e.name)],facetValue:e=>e.type}),[s])),[k,A]=a(()=>new Set),j=e=>A(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),M=n(()=>ct(O.rows,s,k),[O.rows,s,k]),N=[{key:`name`,header:S(`locations.columns.device`),notSortableReason:S(`locations.columns.noSort`),render:e=>e.kind===`member`?o(ut,{row:e,onToggle:()=>j(e.device.id)}):o(dt,{row:e})},{key:`type`,header:S(`locations.columns.type`),notSortableReason:S(`locations.columns.noSort`),render:e=>o(`span`,{className:`text-xs text-foreground-muted`,children:e.device.type})},{key:`status`,header:S(`locations.columns.status`),notSortableReason:S(`locations.columns.noSort`),render:e=>t(`span`,{className:`flex items-center gap-1.5`,children:[o(X,{online:e.device.online,deviceName:e.device.name}),o(`span`,{className:`text-xs text-foreground-muted`,children:e.device.online?`online`:`offline`})]})}],P=()=>{E(e),w(!1)},F=async()=>{let t=T.trim();if(t.length===0||t===e){P();return}await d(t),w(!1)},I=[{id:`rename`,label:`Rename`,icon:_,disabled:c,onClick:()=>{E(e),w(!0)}},{id:`rebuild-links`,label:`Rebuild linked devices`,icon:ne,separatorBefore:!0,disabled:c,onClick:()=>void m()},{id:`delete`,label:`Delete`,icon:p,danger:!0,separatorBefore:!0,disabled:c,onClick:()=>void f()}];return t(`section`,{className:`min-w-0 ${h}`,children:[t(`header`,{className:`${ee} flex min-h-9 items-center gap-1.5`,children:[o(Ye,{name:e,icon:l,busy:c,onPick:g}),C?t(r,{children:[o(q,{value:T,onChange:e=>E(e.target.value),onKeyDown:e=>{e.key===`Enter`&&F(),e.key===`Escape`&&P()},"aria-label":`Rename ${e}`,className:`min-w-0 flex-1`,autoFocus:!0}),o(W,{type:`button`,size:`sm`,onClick:()=>void F(),children:`Save`}),o(we,{type:`button`,variant:`ghost`,icon:D,onClick:P,"aria-label":`Cancel rename`})]}):t(r,{children:[o(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:e}),o(Se,{items:I,title:`Actions for ${e}`,triggerClassName:`p-1`})]})]}),o(qe,{name:e,zones:y,zoneKey:b,busy:c,onChange:x}),o(Ge,{name:e,description:u,busy:c,onSave:v}),i.length>0&&o(`div`,{className:`border-b border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:o(ve,{state:O.state,facets:O.facets,labels:{searchPlaceholder:S(`locations.filter.searchPlaceholder`),searchLabel:S(`locations.room.searchLabel`,{room:e}),facetsLabel:S(`locations.filter.typesLabel`),clearLabel:S(`locations.filter.clear`)},onSearch:O.setSearch,onToggleFacet:O.toggleFacet,onClear:O.clear})}),i.length===0?o(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:`Nothing here yet — assign a device from the table below.`}):o(K,{columns:N,rows:M,rowKey:st,bordered:!1,minWidthPx:360,mobileMode:`scroll`,emptyMessage:S(`locations.filter.noMatch`)})]})}function ut({row:e,onToggle:n}){let{device:r,accessories:i,open:a}=e,s=a?te:E;return t(`span`,{className:`flex items-center gap-1.5`,children:[i.length>0?t(W,{type:`button`,variant:`ghost`,onClick:n,"aria-expanded":a,"aria-label":`${a?`Collapse`:`Expand`} ${String(i.length)} companion device(s) of ${r.name}`,className:`h-auto shrink-0 gap-0.5 p-0.5 text-foreground-subtle hover:text-foreground`,children:[o(s,{className:`h-3 w-3`}),o(`span`,{className:`text-[10px] tabular-nums`,children:i.length})]}):o(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),o(Y,{type:r.type}),o(J,{to:`/devices/${String(r.id)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:r.name})]})}function dt({row:e}){let{device:n}=e;return t(`span`,{className:`flex items-center gap-1.5 pl-6`,children:[o(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),o(Y,{type:n.type,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),o(J,{to:`/devices/${String(n.id)}`,className:`min-w-0 truncate text-xs text-foreground-muted hover:underline`,children:n.name})]})}e();function ft({zones:e,busy:t,onRename:n,onDelete:r,onPickIcon:i}){let[s,c]=a(null),[l,u]=a(``),d=async e=>{let t=l.trim();c(null),!(t.length===0||t===e)&&await n(e,t)};return o(K,{columns:[{key:`icon`,header:`Icon`,width:`w-12`,notSortableReason:`An icon has no order`,render:e=>o(Ye,{name:e.label,icon:e.icon,busy:t,onPick:t=>i(e.label,t)})},{key:`name`,header:`Zone`,sortValue:e=>e.label.toLowerCase(),render:e=>s===e.label?o(q,{value:l,onChange:e=>u(e.target.value),onKeyDown:t=>{t.key===`Enter`&&d(e.label),t.key===`Escape`&&c(null)},onBlur:()=>void d(e.label),"aria-label":`Rename ${e.label}`,autoFocus:!0}):o(W,{type:`button`,variant:`ghost`,size:`sm`,className:`px-0`,onClick:()=>{u(e.label),c(e.label)},disabled:t,title:`Rename the zone`,children:e.label})},{key:`rooms`,header:`Rooms`,align:`right`,sortValue:e=>e.locationKeys.length,render:e=>o(`span`,{className:`tabular-nums text-foreground-subtle`,children:e.locationKeys.length===0?`empty`:`${String(e.locationKeys.length)} ${e.locationKeys.length===1?`room`:`rooms`}`})},{key:`actions`,header:`Actions`,align:`right`,notSortableReason:`Actions have no order`,render:e=>o(W,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void r(e.label),disabled:t,"aria-label":`Delete ${e.label}`,title:`Delete the zone — the rooms in it are kept`,children:o(p,{className:`h-3.5 w-3.5`})})}],rows:e,rowKey:e=>e.zoneKey,mobileMode:`cards`,emptyMessage:`No zones yet. A zone groups rooms — “Zona notte” for the bedrooms — and shows up before them in the app’s camera filter.`})}function pt(){return Ie(),e=>ke(ue(e,`map-pin`))??O}e();function mt({busy:e,onCreate:n}){let[r,i]=a(!1),[s,c]=a(``),l=()=>{c(``),i(!1)},u=async()=>{let e=s.trim();e.length!==0&&(await n(e),l())};return r?t(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),u()},children:[o(q,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Escape`&&l()},placeholder:`Ingresso, Salone, Cucina…`,"aria-label":`New location name`,className:`min-w-[12rem] flex-1`,autoFocus:!0}),t(W,{size:`sm`,type:`submit`,disabled:s.trim().length===0||e,children:[o(g,{className:`h-3.5 w-3.5`}),`Add`]}),o(W,{size:`sm`,variant:`ghost`,type:`button`,onClick:l,"aria-label":`Cancel new location`,children:o(D,{className:`h-3.5 w-3.5`})})]}):t(W,{size:`sm`,type:`button`,onClick:()=>i(!0),"data-testid":`new-location-button`,children:[o(g,{className:`h-3.5 w-3.5`}),`New location`]})}e();function ht({busy:e,onCreate:n}){let[r,i]=a(!1),[s,c]=a(``),l=()=>{c(``),i(!1)},u=async()=>{let e=s.trim();e.length!==0&&(await n(e),l())};return r?t(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),u()},children:[o(q,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Escape`&&l()},placeholder:`Zona giorno, Zona notte…`,"aria-label":`New zone name`,className:`min-w-[12rem] flex-1`,autoFocus:!0}),t(W,{size:`sm`,type:`submit`,disabled:s.trim().length===0||e,children:[o(g,{className:`h-3.5 w-3.5`}),`Add`]}),o(W,{size:`sm`,variant:`ghost`,type:`button`,onClick:l,"aria-label":`Cancel new zone`,children:o(D,{className:`h-3.5 w-3.5`})})]}):t(W,{size:`sm`,type:`button`,onClick:()=>i(!0),"data-testid":`new-zone-button`,children:[o(g,{className:`h-3.5 w-3.5`}),`New zone`]})}e();var gt={searchText:e=>[e.name],facetValue:e=>e.type};function _t({rows:e,fleet:r,locations:i,busy:s,emptyMessage:c,onAssign:l}){let{t:u}=Ve(),[d,f]=a([]),[p,m]=a(``),h=_e(e,gt),g=h.rows,_=n(()=>g.map(e=>e.id),[g]),v=n(()=>d.filter(e=>_.includes(e)),[d,_]),y=g.length>0&&v.length===g.length,b=n(()=>{let t=new Map;for(let n of e)t.set(n.id,it(r,n.id));return t},[e,r]),S=v.reduce((e,t)=>e+(b.get(t)??0),0),C=e=>f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),w=()=>f(y?[]:_),T=()=>{p.length===0||v.length===0||(l(v,p),f([]),m(``))},E=i.map(e=>({value:e,label:e})),D=[{key:`select`,width:`w-8`,headerRender:()=>o(De,{checked:y,onChange:w,"aria-label":y?`Clear selection`:`Select all unassigned devices`}),render:e=>o(De,{checked:v.includes(e.id),onChange:()=>C(e.id),"aria-label":`Select ${e.name}`})},{key:`name`,header:`Device`,sortValue:e=>e.name.toLowerCase(),render:e=>{let n=$e(e,i);return t(`span`,{className:`flex items-center gap-1.5`,children:[o(Y,{type:e.type}),o(J,{to:`/devices/${String(e.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:e.name}),n!==null&&t(Oe,{variant:`warning`,children:[`unknown room “`,n,`”`]})]})}},{key:`type`,header:`Type`,sortValue:e=>e.type,render:e=>o(`span`,{className:`text-xs text-foreground-muted`,children:e.type})},{key:`status`,header:`Status`,sortValue:e=>+!!e.online,render:e=>t(`span`,{className:`flex items-center gap-1.5`,children:[o(X,{online:e.online,deviceName:e.name}),o(`span`,{className:`text-xs text-foreground-muted`,children:e.online?`online`:`offline`})]})},{key:`followers`,header:`Accessories in tow`,align:`right`,sortValue:e=>b.get(e.id)??0,render:e=>o(`span`,{className:`tabular-nums text-xs text-foreground-muted`,children:b.get(e.id)??0})},{key:`assign`,header:`Assign to`,align:`right`,notSortableReason:`This column is a control, not a value.`,render:e=>o(G,{"aria-label":`Location for ${e.name}`,value:``,disabled:s||i.length===0,onChange:t=>{let n=t.target.value;n.length!==0&&l([e.id],n)},className:`max-w-[11rem]`,options:[{value:``,label:`—`},...E]})}];return t(`section`,{className:`space-y-2`,children:[t(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[o(`h2`,{className:x,children:`Not in a room`}),o(`p`,{className:V,children:`Top-level devices only — accessories move with their parent.`})]}),e.length>0&&o(ve,{state:h.state,facets:h.facets,labels:{searchPlaceholder:u(`locations.filter.searchPlaceholder`),searchLabel:u(`locations.unassigned.searchLabel`),facetsLabel:u(`locations.filter.typesLabel`),clearLabel:u(`locations.filter.clear`)},onSearch:h.setSearch,onToggleFacet:h.toggleFacet,onClear:h.clear}),v.length>0&&t(`div`,{role:`group`,"aria-label":`Bulk assignment`,className:`flex flex-wrap items-center gap-2 rounded border border-primary/40 bg-primary/5 px-2 py-1.5`,children:[t(`span`,{className:`text-xs text-foreground`,children:[v.length,` selected`,S>0&&` · ${String(S)} accessories in tow`]}),o(G,{"aria-label":`Assign selected devices to`,value:p,onChange:e=>m(e.target.value),className:`w-auto min-w-[10rem]`,options:[{value:``,label:`Assign to…`},...E]}),o(W,{type:`button`,size:`sm`,onClick:T,disabled:s||p.length===0,children:`Assign`}),o(W,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>f([]),children:`Clear`})]}),o(K,{columns:D,rows:g,rowKey:e=>e.id,minWidthPx:720,mobileMode:`scroll`,emptyMessage:h.active?u(`locations.filter.noMatch`):c})]})}function vt(e){return{id:e.id,parentDeviceId:e.parentDeviceId,location:e.location,type:e.type,stableId:e.stableId??``,...e.primaryChildEntityId===void 0?{}:{primaryChildEntityId:e.primaryChildEntityId},...e.role!==void 0&&e.role!==null?{role:e.role}:{},name:e.name}}function yt(e,t){let n=t.map(vt),r=[];for(let i of t)i.isCamera&&i.location===e&&r.push({deviceId:i.id,name:i.name,ids:ce({selfId:i.id,selfLocation:i.location,candidates:n})});return{entries:r}}var bt=`device-manager:linked-devices`;function xt(e){return{deviceId:e.deviceId,slotRef:bt,value:{slot:`linked-devices`,deviceIds:[...e.ids]}}}e();var $=`__unassigned__`;function St(){let e=i(),r=Te(),a=pt(),{data:s,isLoading:c}=Re(),{data:l}=Ee(),{data:u}=je(),{data:d}=Be(),{data:f,isLoading:p}=Ne({projection:`slim`}),m=()=>{e.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listLocationIcons`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listLocationDescriptions`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listSiteZones`]]})},h=me({onSuccess:m}),g=ze({onSuccess:m}),_=de({onSuccess:m}),v=pe({onSuccess:m}),y=he({onSuccess:m}),b=Me({onSuccess:m}),x=be({onSuccess:m}),S=xe({onSuccess:m}),C=fe({onSuccess:m}),w=ge({onSuccess:m}),T=Ce(),E=n(()=>(f??[]).map(e=>({id:e.id,name:e.name,location:e.location??null,type:String(e.type),isCamera:e.isCamera,parentDeviceId:e.parentDeviceId,online:e.online,role:e.role??null,stableId:e.stableId,primaryChildEntityId:e.primaryChildEntityId??null})),[f]),D=s??[],k=n(()=>ot(E,D),[E,D]),[A,j]=He(),ee=A.get(`tab`)===`zones`?`zones`:`locations`,M=A.get(`room`),N=n(()=>nt(E,D),[E,D]),P=M===$,F=P?null:M!==null&&k.some(e=>e.name===M)?M:k[0]?.name??null,I=F===null?null:k.find(e=>e.name===F)??null,L=P?$:F??k[0]?.name??`__unassigned__`,R=e=>{j(t=>{let n=new URLSearchParams(t);return n.set(`room`,e),n},{replace:!0})},z=c||p,B=_.isPending||g.isPending||h.isPending||y.isPending,te=async e=>{await h.mutateAsync({name:e})},ne=async(e,t)=>{let n=t.trim();n.length===0||n===e||await v.mutateAsync({from:e,to:n})},V=async e=>{let t=yt(e,E);if(t.entries.length===0){await r({title:`Rebuild linked devices`,message:`No camera is assigned to “${e}”.`,confirmLabel:`OK`});return}if(!await r({title:`Rebuild linked devices`,message:`Replace the linked-device list of every camera in “${e}” with what the room contains?\n\n${t.entries.map(e=>`• ${e.name}: ${String(e.ids.length)} device(s)`).join(`
2
- `)}\n\nAnything linked by hand that is not in this room is lost.`,confirmLabel:`Rebuild`,variant:`danger`}))return;let n=[];for(let e of t.entries)try{await T.mutateAsync(xt(e))}catch(t){n.push(`• ${e.name}: ${t instanceof Error?t.message:String(t)}`)}m(),n.length>0&&await r({title:`Rebuild linked devices`,message:`Not rebuilt:\n\n${n.join(`
3
- `)}`,confirmLabel:`OK`})},re=async(e,t)=>{await r({title:`Delete location`,message:`Delete the location “${e}”?${t>0?` ${String(t)} device(s) will become unassigned.`:``}`,confirmLabel:`Delete`,variant:`danger`})&&await g.mutateAsync({name:e,cascade:!0})},ie=async e=>{await r({title:`Delete zone`,message:`Delete the zone “${e}”? The rooms in it are kept.`,confirmLabel:`Delete`,variant:`danger`})&&await S.mutateAsync({name:e})},ae=async(e,t)=>{await y.mutateAsync({location:e,icon:t})},oe=async(e,t)=>{await b.mutateAsync({location:e,description:t})},H=d??[],se=async(e,t)=>{await w.mutateAsync({location:e,zone:t})},ce=t(`div`,{className:`flex flex-col gap-3`,"data-testid":`locations-section`,children:[z&&o(`p`,{className:`text-xs text-foreground-subtle`,children:`Loading locations and devices…`}),o(Ae,{appearance:`pills`,value:L,onValueChange:R,children:t(Pe,{"aria-label":`Locations`,children:[k.map(e=>{let n=a(Xe(l,U(e.name)));return t(Le,{value:e.name,"data-testid":`location-kind-${e.name}`,children:[o(n,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),e.name,o(`span`,{className:`text-foreground-subtle tabular-nums`,children:e.members.length})]},e.name)}),t(Le,{value:$,"data-testid":`location-kind-unassigned`,children:[`Unassigned`,o(`span`,{className:`text-foreground-subtle tabular-nums`,children:N.length})]})]})}),P||I===null?o(_t,{rows:N,fleet:E,locations:D,busy:B,emptyMessage:z?`Loading…`:`Every top-level device has a room.`,onAssign:(e,t)=>{for(let n of e)_.mutate({deviceId:n,location:t})}}):o(lt,{name:I.name,members:I.members,devices:E,busy:B,icon:Xe(l,U(I.name)),onPickIcon:e=>ae(I.name,e),description:Ke(u,U(I.name)),onSaveDescription:e=>oe(I.name,e),zones:H,zoneKey:Je(H,U(I.name)),onChangeZone:e=>se(I.name,e),onRename:e=>ne(I.name,e),onDelete:()=>re(I.name,Ze(E,I.name).length),onRebuildLinks:()=>V(I.name)},I.name),D.length===0&&!z&&o(`p`,{className:`text-xs text-foreground-subtle`,children:`No locations yet. Add Ingresso, Salone, Cucina…`})]});return o(Ue,{icon:O,title:`Locations`,subtitle:`Rooms and areas of the site. Assign any device here — storage disks are under Data → Storage.`,defaultSection:`locations`,sectionsLabel:`Locations sections`,actions:ee===`zones`?o(ht,{busy:x.isPending,onCreate:e=>x.mutateAsync({name:e})}):o(mt,{busy:h.isPending,onCreate:te}),sections:[{id:`locations`,label:`Locations`,ownedParams:[`room`],content:ce},{id:`zones`,label:`Zones`,content:o(ft,{zones:H,busy:B,onRename:(e,t)=>C.mutateAsync({from:e,to:t}),onDelete:ie,onPickIcon:(e,t)=>x.mutateAsync({name:e,icon:t})})}]})}export{St as LocationsPage};
@@ -1 +0,0 @@
1
- import{Q as e,S as t,W as n,q as r,x as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Qi as a,ar as o,bi as s,fn as c,wi as l}from"./player-overlays-DEJGWVeQ.js";import{n as u,t as d}from"./timer-reset-DbjUS-e3.js";import{t as f}from"./layers-Df1aeR99.js";import{Dr as p,Er as m,Tt as h,al as g,du as _,sl as v}from"./src-CVCI1YgT.js";import{t as y}from"./useTranslation-Bc5yH9V9.js";import{C as b,c as x,s as S}from"./index-D7FGxQMl.js";import{t as C}from"./AdminSectionedPage-Bx9l4jGV.js";import{t as w}from"./AdminPage-250c5IIz.js";import{n as T,t as E}from"./IntegrationHub-Bufk1Dn6.js";import{n as D,t as O}from"./addon-display-names-BkwMrExv.js";e();var k=5e3,A=`log-destination`,j={"winston-logging":`Rotated log files on this node’s disk.`,"console-logging":`stdout / stderr of the node process.`,"loki-logging":`Pushes to a Grafana Loki instance. Off until enabled with a URL.`,"hub-forwarder":`Agent-only — forwards this node’s entries to the hub.`};function M(){let e=p({capName:`log-destination`},{refetchInterval:k}),t=m(void 0,{refetchInterval:k}),r=n(()=>O(t.data??[]),[t.data]),a=n(()=>{let e=new Map;for(let n of t.data??[]){let t=n.description,r=n.id;typeof r==`string`&&typeof t==`string`&&t.length>0&&e.set(r,t)}return e},[t.data]),o=n(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive,caption:a.get(e.addonId)??j[e.addonId]??``})),[e.data,r,a]);return i(E,{embedded:!0,icon:c,title:`Destinations`,subtitle:`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another.`,groups:[{id:A,label:`Log destinations`,install:{capability:A,label:`Add destination`},entries:o.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:u,...D(e.isActive),render:()=>i(T,{addonId:e.addonId,displayName:e.displayName,capName:A,isActive:e.isActive,badges:e.caption.length>0?i(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.caption}):null})}))}],isLoading:e.isLoading,emptyTitle:`No log destinations registered`,emptyDescription:`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`})}e();var N=[12e4,3e5,6e5,18e5],P={"request-census":`Counts every tRPC call by TRANSPORT PLANE — http, ws, mesh — and by procedure, caller, address and user-agent. Subscriptions are counted apart from calls, so a long-lived stream cannot pass for a storm. Arm it, then restart: the deadline is persisted, so the window is still running when clients reconnect.`};function F(){let{t:e}=y(),n=g({},{refetchInterval:5e3}),s=v(),[c,l]=r(null),u=(e,t)=>{l(e),s.mutate({patch:{diagnostics:[{id:e,armMs:t}]}},{onSettled:()=>{l(null),n.refetch()}})},d=n.data?.activeWindows??[],f=n.data?.channels??[],p=n.data?.activeChannels??[],m=(e,t,r)=>{l(e),s.mutate({patch:{channels:[{channel:e,armMs:t,deviceIds:r}]}},{onSettled:()=>{l(null),n.refetch()}})};return t(w,{embedded:!0,icon:a,title:e(`logging.diagnostics.title`,`Diagnostics`),subtitle:e(`logging.diagnostics.subtitle`,`Diagnostics are armed for a window, never switched on. Each carries a deadline and expires by itself — one left running is an incident of its own.`),children:[n.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(o,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:d.map(e=>i(L,{window:e,busy:c===e.id,onArm:t=>u(e.id,t)},e.id))}),i(`h3`,{className:`mt-6 text-sm font-medium text-foreground`,children:e(`logging.diagnostics.channels`,`Component channels`)}),i(`p`,{className:`mb-2 max-w-3xl text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.channelsSubtitle`,`Declared by the addons that own them — this list is not maintained by hand. Arming a channel opens a window with a deadline; it closes by itself.`)}),f.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.noChannels`,`No addon on this cluster declares a log channel, or none could be reached right now.`)}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:f.map(e=>i(I,{channel:e,state:p.find(t=>t.channel===e.name),busy:c===e.name,onArm:(t,n)=>m(e.name,t,n)},e.name))})]})}function I({channel:e,state:n,busy:a,onArm:o}){let{t:s}=y(),[c,u]=r(``),f=n?.armed===!0,p=()=>{let e=c.split(/[\s,+]+/).filter(e=>/^\d+$/.test(e)).map(e=>Number(e));return e.length>0?e:null};return t(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.name}),f?t(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[i(d,{className:`h-3 w-3`}),s(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:R(n?.remainingMs??0)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:s(`logging.diagnostics.disarmed`,`disarmed`)}),f&&n?.deviceIds!==null&&n?.deviceIds!==void 0&&t(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[i(l,{className:`h-3 w-3`}),n.deviceIds.join(`, `)]}),!e.perDevice&&i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:s(`logging.diagnostics.notPerCamera`,`not filterable per camera`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:e.description})]}),t(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[e.perDevice&&i(`input`,{type:`text`,inputMode:`numeric`,value:c,disabled:a,onChange:e=>u(e.target.value),placeholder:s(`logging.diagnostics.camerasPlaceholder`,`all cameras`),className:`w-28 rounded border border-border bg-surface px-2 py-1 text-[11px] text-foreground`}),N.map(e=>i(`button`,{type:`button`,disabled:a,onClick:()=>o(e,p()),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:R(e)},e)),i(`button`,{type:`button`,disabled:a||!f,onClick:()=>o(0,null),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:s(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function L({window:e,busy:n,onArm:r}){let{t:a}=y();return t(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.id}),e.armed?t(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[i(d,{className:`h-3 w-3`}),a(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:R(e.remainingMs)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:a(`logging.diagnostics.disarmed`,`disarmed`)}),e.armed&&!e.persisted&&i(`span`,{className:`text-[10px] text-warning`,children:a(`logging.diagnostics.notPersisted`,`not persisted — will not survive a restart`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:P[e.id]??``})]}),t(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[N.map(e=>i(`button`,{type:`button`,disabled:n,onClick:()=>r(e),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:R(e)},e)),i(`button`,{type:`button`,disabled:n||!e.armed,onClick:()=>r(0),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:a(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function R(e){let t=Math.max(0,Math.round(e/1e3)),n=Math.floor(t/60),r=t%60;return n===0?`${r}s`:r===0?`${n}m`:`${n}m ${r}s`}e();var z=[`debug`,`info`,`warn`,`error`],B=``,V=``;function H(){let{t:e}=y(),[a,s]=r(B),[c,l]=r(V),{nodes:u}=_(),d=n(()=>u.map(e=>({id:e.id,label:e.name||e.id})),[u]),p=g({...a===B?{}:{scopeNodeId:a},...c===V?{}:{scopeComponent:c}},{refetchInterval:15e3}),m=v(),h=p.data,b=m.isPending||p.isFetching,x=h?.channels??[],S=(e,t)=>{m.mutate({...e.nodeId===null?{}:{scopeNodeId:e.nodeId},...e.component===null?{}:{scopeComponent:e.component},patch:{level:t}},{onSuccess:()=>void p.refetch()})};return i(w,{embedded:!0,icon:f,title:e(`logging.levels.title`,`Levels`),subtitle:e(`logging.levels.subtitle`,`Cluster → node, most specific wins. The floor gates what reaches the log destinations; the in-memory viewer keeps every line either way.`),actions:t(`div`,{className:`flex flex-wrap items-center gap-3`,children:[t(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.scope`,`Scope`),t(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground disabled:opacity-50`,value:a,disabled:c!==V,onChange:e=>s(e.target.value),children:[i(`option`,{value:B,children:e(`logging.levels.cluster`,`Cluster`)}),d.map(e=>i(`option`,{value:e.id,children:e.label},e.id))]})]}),t(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.component`,`Component`),t(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground`,value:c,onChange:e=>l(e.target.value),children:[i(`option`,{value:V,children:e(`logging.levels.noComponent`,`None`)}),x.map(e=>i(`option`,{value:e.name,children:e.name},e.name))]})]})]}),children:p.isLoading||h===void 0?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(o,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):t(`div`,{className:`space-y-3`,children:[i(W,{level:h.effective.level,source:h.effective.levelSource,persisted:h.persisted}),i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:h.explicit.layers.map(e=>i(G,{layer:e,inForce:e.scope===h.effective.levelSource,busy:b,onSet:t=>S(e,t),onClear:()=>S(e,null)},`${e.scope}:${e.nodeId??e.component??`cluster`}`))}),c!==V&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:x.find(e=>e.name===c)?.description??``}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.levels.componentNote`,`A component is a log channel an addon declared. Its level is cluster-wide and beats both the node and the cluster layer.`)}),i(U,{days:h.opsLogRetentionDays,busy:b,onSet:e=>m.mutate({patch:{opsLogRetentionDays:e}},{onSuccess:()=>void p.refetch()})})]})})}function U({days:e,busy:n,onSet:r}){let{t:a}=y();return t(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-1`,children:[t(`label`,{className:`flex items-center justify-between gap-3`,children:[i(`span`,{className:`text-xs font-medium`,children:a(`logging.levels.opsLogRetention`,`Retention audit trail`)}),t(`span`,{className:`flex items-center gap-1.5`,children:[i(`input`,{type:`number`,min:0,max:3650,step:1,defaultValue:e,disabled:n,onBlur:t=>{let n=Number.parseInt(t.target.value,10);Number.isFinite(n)&&n!==e&&r(n)},className:`w-20 rounded border border-border bg-surface px-2 py-1 text-xs`}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`common.days`,`days`)})]})]}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`logging.levels.opsLogRetentionNote`,`How long the record of what retention deleted is kept. Cluster-wide, and deliberately longer than any camera window — it is the history of the sweep, not of the camera, and it is what makes a storage leak explainable after the fact. 0 keeps it forever.`)})]})}function W({level:e,source:n,persisted:r}){let{t:a}=y();return t(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-xs text-foreground-subtle`,children:a(`logging.levels.effective`,`In force here`)}),i(`span`,{className:`rounded bg-primary/10 px-2 py-0.5 text-xs font-semibold text-primary`,children:e}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:n==="default"?a(`logging.levels.fromDefault`,`nothing is set anywhere — this is the default`):a(`logging.levels.fromLayer`,`decided by the {{source}} layer`,{source:n})})]}),!r&&i(`p`,{className:`mt-1 text-[11px] text-warning`,children:a(`logging.levels.notPersisted`,`The settings store could not be read or written — what you see is live, but it would not survive a restart.`)})]})}function G({layer:e,inForce:n,busy:r,onSet:a,onClear:o}){let{t:c}=y();return t(`div`,{className:`flex flex-col gap-2 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.scope===`cluster`?c(`logging.levels.cluster`,`Cluster`):e.scope===`component`?e.component??``:e.nodeId??``}),n&&t(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[i(s,{className:`h-3 w-3`}),c(`logging.levels.inForce`,`in force`)]})]}),i(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:e.level===null?c(`logging.levels.inherits`,`inherits — nothing set at this layer`):c(`logging.levels.setHere`,`set here: {{level}}`,{level:e.level})})]}),t(`div`,{className:`flex shrink-0 items-center gap-1`,children:[z.map(t=>i(`button`,{type:`button`,disabled:r,onClick:()=>a(t),className:`rounded px-2 py-1 text-[11px] font-medium transition-colors disabled:opacity-50 ${e.level===t?`bg-primary text-primary-foreground`:`border border-border text-foreground-subtle hover:text-foreground`}`,children:t},t)),i(`button`,{type:`button`,disabled:r||e.level===null,onClick:o,className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-40`,children:c(`logging.levels.clear`,`Clear`)})]})]})}function K(){return i(w,{embedded:!0,children:i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:i(h,{limit:500,maxHeight:`max-h-[calc(100vh-310px)]`,showScope:!0,showFilters:!0})})})}function q(){let{t:e}=y(),t=b(`/system/logs`,{t:e,isAdmin:!0})??{icon:c,title:e(`system.logs`,`Logs`)};return i(C,{icon:t.icon,title:t.title,defaultSection:`viewer`,sectionsLabel:`${t.title} sections`,sections:[{id:`viewer`,label:`Viewer`,content:i(K,{})},{id:x.logging.tab,label:`Destinations`,content:i(M,{}),ownedParams:S},{id:`levels`,label:`Levels`,content:i(H,{})},{id:`diagnostics`,label:`Diagnostics`,content:i(F,{})}]})}export{q as LogsPage};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./browser-BHo8W_uH.js","./rolldown-runtime-Cyuzqnbw.js"])))=>i.map(i=>d[i]);
2
- import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{t}from"./vite-preload-helper-kNaey6uv.js";import{K as n,Q as r,S as i,W as a,a as o,b as s,q as c,t as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Hi as f,Ir as p,It as m,Nt as h,Pn as g,Q as _,Qt as v,Yr as y,ar as b,cr as x,fi as S,nr as C,ot as w,pi as T,pr as E}from"./player-overlays-DEJGWVeQ.js";import{o as D}from"./video-47m9GMk0.js";import{t as O}from"./key-round-Cl-qLeAZ.js";import{t as k}from"./monitor-smartphone-DmzFXiIW.js";import{t as A}from"./unlink-C2XiU97D.js";import{Kn as j,qn as M}from"./client-Cm-sr0wc.js";import{Bn as ee,Cn as te,Do as ne,Ft as re,Gl as N,Wn as ie,Z as ae,Zn as P,gu as F,ko as oe,wn as se}from"./src-CVCI1YgT.js";import{t as I}from"./useTranslation-Bc5yH9V9.js";import"./mount-DSRwVBTr.js";import{R as L,i as R,n as z,r as B,t as V}from"./index-D7FGxQMl.js";import{t as H}from"./AdminPage-250c5IIz.js";import{N as U,P as W,_ as G,a as K,g as ce,k as le,r as ue,t as de,v as q}from"./SessionsList-DZBaHZJv.js";r();function fe({value:n,size:r=192}){let[a,o]=c(null),[s,l]=c(null);if(d(()=>{let r=!1;return t(()=>import(`./browser-BHo8W_uH.js`).then(t=>e(t.default,1)).then(async e=>{if(r)return;let t=e.create;if(typeof t!=`function`){l(`qrcode.create() unavailable in installed version`);return}try{let e=t(n,{errorCorrectionLevel:`M`});r||o(e)}catch(e){r||l(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1]),import.meta.url).catch(()=>{r||l(`qrcode library not installed`)}),()=>{r=!0}},[n]),s)return u(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:r,height:r},children:`QR rendering unavailable — use the secret below.`});if(!a)return u(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:r,height:r},children:`Generating…`});let f=a.modules.size,p=r/f,m=[];for(let e=0;e<f;e++)for(let t=0;t<f;t++)a.modules.data[e*f+t]&&m.push(u(`rect`,{x:t*p,y:e*p,width:p,height:p,fill:`currentColor`},`${t}-${e}`));return i(`svg`,{width:r,height:r,viewBox:`0 0 ${r} ${r}`,className:`text-black`,children:[u(`rect`,{x:0,y:0,width:r,height:r,fill:`white`}),m]})}var pe=`${j}/connect`,J={public:0,mesh:1,lan:2,"lan-ipv6":3};function me(e){switch(e.kind){case`public`:return e.interfaceKind===`vpn`?`mesh`:`public`;case`lan-ipv4`:return`lan`;case`lan-ipv6`:return`lan-ipv6`;case`custom`:return`public`;case`loopback`:case`app-link`:return null}}function Y(e){return M(e)}function he(e){return e.startsWith(`https://`)}function ge(e){let t=e.flatMap(e=>{let t=me(e),n=Y(e.baseUrl);return t===null||n===null?[]:[{endpoint:e,tier:t,origin:n}]}).toSorted((e,t)=>J[e.tier]-J[t.tier]||Number(t.endpoint.plausible)-Number(e.endpoint.plausible)||e.endpoint.priority-t.endpoint.priority),n=new Set;return t.flatMap(({endpoint:e,tier:t,origin:r})=>n.has(r)?[]:(n.add(r),[{origin:r,label:e.label,tier:t,secure:he(r),plausible:e.plausible}]))}function _e(e,t,n=null){for(let r of[t,n]){if(r===null)continue;let t=Y(r),n=e.find(e=>e.origin===t);if(n!==void 0)return n}return e[0]??null}function ve(e){let t=new URL(pe);return t.searchParams.set(`hub`,e),t.toString()}r();var ye=176,X={scheme:`https`};function be(){let{t:e}=I(),t=oe(X),n=ne(X).data?.roles.publicEndpoint.resolved??null;return i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[i(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[u(v,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`connectPhone.title`)})]}),i(`div`,{className:`p-4 space-y-3`,children:[u(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`connectPhone.description`)}),t.isPending?i(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[u(b,{className:`h-3.5 w-3.5 animate-spin`}),e(`connectPhone.loading`)]}):t.isError?i(`div`,{className:`flex items-start gap-2 text-[11px] text-danger`,children:[u(h,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),i(`div`,{className:`flex-1 min-w-0 space-y-1.5`,children:[u(`div`,{className:`break-words`,children:e(`connectPhone.error`,{message:t.error.message})}),u(ee,{size:`sm`,variant:`ghost`,onClick:()=>void t.refetch(),children:e(`connectPhone.retry`)})]})]}):u(xe,{candidates:ge(t.data.endpoints),preferredOrigin:n})]})]})}function xe({candidates:e,preferredOrigin:t}){let{t:n}=I(),[r,o]=c(null),s=_e(e,r,t),l=a(()=>s?ve(s.origin):null,[s]);if(s===null||l===null)return u(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`connectPhone.empty`)});let d=e=>n(`connectPhone.tier.${e}`),f=e.map(e=>({value:e.origin,label:`${d(e.tier)} — ${e.origin}`}));return i(`div`,{className:`flex flex-col sm:flex-row gap-4`,children:[u(te,{value:l,size:ye,alt:n(`connectPhone.qrAlt`),className:`self-start`}),i(`div`,{className:`flex-1 min-w-0 space-y-3`,children:[i(`label`,{className:`block space-y-1`,children:[u(`span`,{className:`text-[11px] font-medium text-foreground`,children:n(`connectPhone.addressLabel`)}),u(N,{value:s.origin,options:f,onChange:e=>o(e.target.value)}),i(`span`,{className:`block text-[10px] text-foreground-subtle`,children:[d(s.tier),` · `,s.label]})]}),!s.secure&&u(Z,{text:n(`connectPhone.insecure`)}),!s.plausible&&u(Z,{text:n(`connectPhone.implausible`)}),i(`div`,{className:`space-y-1`,children:[u(`span`,{className:`text-[11px] font-medium text-foreground`,children:n(`connectPhone.linkLabel`)}),i(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[u(`code`,{className:`flex-1 min-w-0 font-mono text-[11px] text-foreground break-all select-all`,children:l}),u(re,{value:l,srLabel:n(`connectPhone.linkLabel`)})]})]}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`connectPhone.signInHint`)})]})]})}function Z({text:e}){return i(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[u(h,{className:`h-3.5 w-3.5 text-warning mt-0.5 shrink-0`}),u(`span`,{children:e})]})}r();function Se(e){return new Date(e).toLocaleDateString()}function Ce(){let e=P(),t=F.useUtils(),r=F.auth.listLinkableProviders.useQuery(),a=F.auth.listOwnExternalIdentities.useQuery(),[o,s]=c(null),[l,f]=c(()=>R(window.location.search)),p=n(null),m=G(`Linking a sign-in account`),h=n(null);d(()=>()=>h.current?.(),[]);let[g,v]=c(null);d(()=>{if(l===null)return;let e=new URL(window.location.href);e.searchParams.delete(`linked`),e.searchParams.delete(`linkError`),window.history.replaceState({},``,e.pathname+e.search+e.hash)},[l]);let y=F.auth.beginExternalLink.useMutation({onSuccess:({url:e})=>{let n=p.current;if(p.current=null,n===null||n.closed){window.location.assign(e);return}let r=e=>{v(null),f(R(`?${e}`)),t.auth.listOwnExternalIdentities.invalidate()};h.current?.(),h.current=z(n,{onReturn:e=>{e.target===`profile`&&r(e.query)},onDone:e=>{e.target===`profile`&&r(e.query)},onClosed:()=>{h.current?.(),h.current=null,t.auth.listOwnExternalIdentities.invalidate()}}),n.location.href=_(B(e))},onError:e=>{p.current?.close(),p.current=null,v(null),s(e.message)}}),C=F.auth.unlinkOwnExternalIdentity.useMutation({onSuccess:()=>void t.auth.listOwnExternalIdentities.invalidate(),onError:e=>s(e.message)}),w=r.data??[],E=a.data??[],D=g!==null&&E.some(e=>e.provider===g);if(d(()=>{!D||g===null||(v(null),f({kind:`linked`,provider:g}))},[D,g]),w.length===0&&E.length===0)return null;let O=new Set(E.map(e=>e.provider)),k=e=>w.find(t=>t.provider===e)?.label??e,j=async(t,n)=>{await e({title:`Unlink sign-in account`,message:`Stop signing in with this ${n} account?`,confirmLabel:`Unlink`,variant:`danger`})&&(s(null),C.mutate({provider:t.provider,subject:t.subject}))};return i(`div`,{"data-testid":`linked-sign-ins`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[m.dialog,i(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[u(x,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`div`,{className:`text-xs font-semibold text-foreground`,children:`Linked sign-in accounts`})]}),i(`div`,{className:`p-4 space-y-3`,children:[u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Sign in with an external account instead of your password. Only accounts you link here can sign you in; your two-factor authentication still applies.`}),l?.kind===`linked`&&i(`div`,{className:`flex items-center gap-2 rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2 text-xs text-foreground`,children:[u(S,{className:`h-3.5 w-3.5 text-emerald-500 shrink-0`}),`Linked your `,k(l.provider),` account.`]}),(l?.kind===`error`||o)&&i(`div`,{className:`flex items-center gap-2 rounded-md border border-danger/20 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[u(T,{className:`h-3.5 w-3.5 shrink-0`}),o??(l?.kind===`error`?l.message:``)]}),E.length>0&&u(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:E.map(e=>{let t=e.providerLabel??e.provider;return i(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[i(`div`,{className:`flex-1 min-w-0`,children:[i(`div`,{className:`font-medium text-foreground truncate`,children:[t,!e.available&&u(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:`provider unavailable`})]}),i(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:[e.label??e.subject,` · linked `,Se(e.linkedAt)]})]}),i(`button`,{onClick:()=>void j(e,t),disabled:C.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[u(A,{className:`h-3 w-3`}),`Unlink`]})]},`${e.provider}|${e.subject}`)})}),u(`div`,{className:`flex flex-wrap gap-2`,children:w.filter(e=>!O.has(e.provider)).map(e=>i(`button`,{onClick:()=>{s(null),f(null),m.requestProof().then(t=>{t!==null&&(p.current=V(null),v(p.current===null?null:e.provider),y.mutate({provider:e.provider,reauthToken:t}))})},disabled:y.isPending,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[y.isPending&&y.variables?.provider===e.provider?u(b,{className:`h-3 w-3 animate-spin`}):u(x,{className:`h-3 w-3`}),`Link `,e.label]},e.provider))})]})]})}r();function Q(e){return e.message.length>0?e.message:`Request failed`}function we(){let{logout:e}=L(),t=P(),n=F.useUtils(),r=F.auth.listOwnSessions.useQuery(),[a,o]=c(null),s=F.auth.revokeOwnSession.useMutation({onSuccess:()=>void n.auth.listOwnSessions.invalidate(),onError:e=>o(`Sign out failed: ${Q(e)}`)}),l=F.auth.logout.useMutation({onSuccess:()=>e(),onError:e=>o(`Sign out failed: ${Q(e)}`)}),d=async e=>{await t({title:`Sign out this session`,message:`${q(e.client).label} will have to sign in again.`,confirmLabel:`Sign out`,variant:`danger`})&&(o(null),s.mutate({id:e.id}))},f=async()=>{await t({title:`Sign out everywhere`,message:`Every session of your account ends, this browser included: you will be signed out here too and every device has to sign in again.`,confirmLabel:`Sign out everywhere`,variant:`danger`})&&(o(null),l.mutate({everywhere:!0}))};return i(`div`,{"data-testid":`my-sessions`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[i(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[u(k,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`div`,{className:`text-xs font-semibold text-foreground`,children:`Active sessions`})]}),i(`div`,{className:`p-4 space-y-3`,children:[u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`The browsers and apps signed in to your account. Signing one out ends it at once.`}),a!==null&&u(`div`,{className:`text-[11px] text-danger`,children:a}),u(de,{sessions:r.data??[],isLoading:r.isLoading,loadError:r.isError?r.error?.message??`Request failed`:null,emptyText:`No active sessions.`,onRevoke:e=>void d(e),revokingId:s.isPending?s.variables?.id??null:null}),u(`div`,{className:`flex justify-end`,children:i(`button`,{onClick:()=>void f(),disabled:l.isPending,className:`inline-flex items-center gap-1.5 rounded border border-danger/40 px-2.5 py-1 text-[11px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,children:[l.isPending?u(b,{className:`h-3 w-3 animate-spin`}):u(D,{className:`h-3 w-3`}),`Sign out everywhere`]})})]})]})}r();var Te=`You`;function Ee(){let e=P(),t=F.useUtils(),n=F.auth.listOwnDeviceCredentials.useQuery(),[r,i]=c(null),o=F.auth.revokeOwnDeviceCredential.useMutation({onSuccess:e=>{e.revoked||i(`That device could not be revoked - it may already be gone.`),t.auth.listOwnDeviceCredentials.invalidate()},onError:e=>i(`Revoke failed: ${e.message}`)}),s=a(()=>(n.data??[]).map(e=>ue(e,Te)),[n.data]),l=async t=>{await e({title:`Revoke "${t.name}"?`,message:`The device stops signing in at once and its open sessions end. To use it again you have to pair it anew. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&(i(null),o.mutate({id:t.id}))},d={label:`Revoke`,icon:f,isAvailable:K,onRun:e=>void l(e),busyId:o.isPending?o.variables?.id??null:null,disabled:o.isPending};return u(U,{id:`my-devices`,title:`My devices`,icon:v,description:`Phones that stay signed in to your account with a certificate. If one is lost, revoke it here and it is signed out at once.`,notice:W(r),onDismissNotice:()=>i(null),children:u(le,{rows:s,label:`devices`,isLoading:n.isPending,loadError:n.error===null?null:n.error.message||`Request failed`,emptyText:`No devices are signed in with a certificate.`,hideOwner:!0,expiresNone:`—`,action:d})})}r();var De={view:{icon:p,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:g,cls:`bg-primary/15 text-primary`},delete:{icon:m,cls:`bg-danger/15 text-danger`}};function Oe(){let{user:e,logout:t}=L();if(!e)return u(H,{children:u(`div`,{className:`text-xs text-foreground-subtle`,children:`Not signed in.`})});let n=e.isAdmin,r=e.scopes??[];return i(H,{children:[i(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[u(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-primary font-semibold text-base`,children:e.username.slice(0,1).toUpperCase()}),i(`div`,{className:`flex-1 min-w-0`,children:[u(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:e.username}),i(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n?`Administrator`:`User`,` · session id`,` `,i(`span`,{className:`font-mono`,children:[e.id.slice(0,8),`…`]})]})]})]}),n&&i(`div`,{className:`rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5`,children:[u(E,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),i(`div`,{children:[u(`div`,{className:`font-semibold text-foreground`,children:`Unrestricted access`}),u(`p`,{className:`text-foreground-subtle mt-0.5`,children:`Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below.`})]})]}),u(ke,{}),u(Ae,{username:e.username}),u(je,{}),u(Ce,{}),u(ce,{}),u(we,{}),u(Ee,{}),u(be,{}),r.length>0&&i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[i(`div`,{className:`px-4 py-2 border-b border-border`,children:[u(`div`,{className:`text-xs font-semibold text-foreground`,children:`Granted scopes`}),u(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Baked into your session token at login; sign out + back in to refresh after changes.`})]}),i(`div`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[u(`div`,{children:`Type`}),u(`div`,{children:`Target`}),u(`div`,{children:`Access`})]}),u(`ul`,{className:`divide-y divide-border`,children:r.map((e,t)=>i(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[u(`span`,{className:`font-mono text-foreground-subtle`,children:e.type}),u(`span`,{className:`font-mono text-foreground`,children:e.type===`device`?ae(e.selector):e.target}),u(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(t=>{let n=e.access.includes(t),{icon:r,cls:a}=De[t];return i(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${n?a:`bg-transparent text-foreground-subtle/40 line-through`}`,title:n?`Can ${t}`:`Cannot ${t}`,children:[u(r,{className:`h-3 w-3`}),t]},t)})})]},t))})]}),u(`div`,{className:`flex justify-end`,children:i(`button`,{onClick:t,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground transition-colors`,children:[u(D,{className:`h-3 w-3`}),`Sign out`]})})]})}function ke(){let e=w(),[t,n]=c(``),[r,a]=c(``),[o,s]=c(``),[d,f]=c(null),p=l({mutationFn:t=>e.changeOwnPassword(t),onSuccess:()=>{f({kind:`success`,msg:`Password updated.`}),n(``),a(``),s(``)},onError:e=>{f({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),m=r.length>0&&o.length>0&&r!==o,h=r.length>0&&r.length<8,g=t.length>=1&&r.length>=8&&r===o;return i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[i(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[u(O,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`div`,{className:`text-xs font-semibold text-foreground`,children:`Change password`})]}),i(`div`,{className:`p-4 space-y-3`,children:[u($,{label:`Current password`,value:t,onChange:n,autoComplete:`current-password`}),u($,{label:`New password`,value:r,onChange:a,autoComplete:`new-password`,hint:`At least 8 characters.`}),u($,{label:`Confirm new password`,value:o,onChange:s,autoComplete:`new-password`}),(m||h)&&u(`div`,{className:`text-[11px] text-danger`,children:m?`Passwords do not match.`:`New password must be at least 8 characters.`}),d&&i(`div`,{className:`text-[11px] flex items-center gap-1 ${d.kind===`success`?`text-emerald-500`:`text-danger`}`,children:[d.kind===`success`?u(S,{className:`h-3 w-3`}):u(T,{className:`h-3 w-3`}),d.msg]}),u(`div`,{className:`flex justify-end`,children:i(`button`,{onClick:()=>{f(null),p.mutate({currentPassword:t,newPassword:r})},disabled:!g||p.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[p.isPending?u(b,{className:`h-3 w-3 animate-spin`}):u(C,{className:`h-3 w-3`}),`Update password`]})})]})]})}function $({label:e,value:t,onChange:n,autoComplete:r,hint:a}){return i(`div`,{className:`space-y-1`,children:[u(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),u(`input`,{type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:r,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),a&&u(`div`,{className:`text-[10px] text-foreground-subtle`,children:a})]})}function Ae({username:e}){let t=w(),n=o({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>t.getOwnTotpStatus()}),r=n.data,[f,p]=c(null),[m,h]=c(``),[g,_]=c(null),[x,C]=c(!1),E=l({mutationFn:()=>t.setupOwnTotp(),onSuccess:e=>{p({secret:e.secret,otpauthUrl:e.otpauthUrl}),h(``),_(null)},onError:e=>_(e instanceof Error?e.message:`Setup failed`)}),D=l({mutationFn:e=>t.confirmOwnTotp(e),onSuccess:()=>{p(null),h(``),_(null),n.refetch()},onError:e=>_(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),O=G(`Turning off two-factor authentication`),k=l({mutationFn:async()=>{let e=await O.requestProof();return e===null?null:t.disableOwnTotp({reauthToken:e})},onSuccess:()=>{_(null),n.refetch()},onError:e=>_(e instanceof Error?e.message:`Disable failed`)});d(()=>{if(!x)return;let e=setTimeout(()=>C(!1),1500);return()=>clearTimeout(e)},[x]);let A=a(()=>n.isLoading?`loading`:f?`setup_in_progress`:r?.enabled?`enrolled`:`not_enrolled`,[n.isLoading,r?.enabled,f]);return i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[O.dialog,i(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[u(v,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`div`,{className:`text-xs font-semibold text-foreground`,children:`Two-factor authentication`})]}),i(`div`,{className:`p-4 space-y-3`,children:[A===`loading`&&i(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[u(b,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),A===`not_enrolled`&&i(s,{children:[u(`div`,{className:`text-xs text-foreground-subtle`,children:`2FA isn't active on your account. Enable it to require a 6-digit code from your authenticator app at every login.`}),u(`div`,{className:`flex justify-end`,children:i(`button`,{onClick:()=>{_(null),E.mutate()},disabled:E.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[E.isPending?u(b,{className:`h-3 w-3 animate-spin`}):u(v,{className:`h-3 w-3`}),`Enable 2FA`]})})]}),A===`setup_in_progress`&&f&&i(s,{children:[i(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`Scan the QR code (or enter the secret manually) into your authenticator app for`,` `,u(`span`,{className:`font-mono`,children:e}),`, then enter the 6-digit code below to confirm.`]}),i(`div`,{className:`flex flex-col items-center gap-3`,children:[u(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:u(fe,{value:f.otpauthUrl,size:180})}),i(`div`,{className:`w-full`,children:[u(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:`Secret (manual entry)`}),i(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[u(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:f.secret}),i(`button`,{onClick:()=>{f&&navigator.clipboard.writeText(f.secret).then(()=>C(!0))},className:`inline-flex items-center gap-1 text-[10px] text-foreground-subtle hover:text-foreground`,children:[x?u(S,{className:`h-3 w-3 text-emerald-500`}):u(y,{className:`h-3 w-3`}),x?`Copied`:`Copy`]})]})]})]}),i(`div`,{className:`space-y-1`,children:[u(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),u(`input`,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:m,onChange:e=>h(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary`})]}),g&&i(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[u(T,{className:`h-3 w-3`}),g]}),i(`div`,{className:`flex justify-end gap-2`,children:[u(`button`,{onClick:()=>{p(null),_(null),h(``)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),i(`button`,{onClick:()=>{_(null),D.mutate({code:m})},disabled:D.isPending||m.length!==6,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[D.isPending?u(b,{className:`h-3 w-3 animate-spin`}):u(S,{className:`h-3 w-3`}),`Confirm`]})]})]}),A===`enrolled`&&r&&i(s,{children:[i(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[u(S,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),i(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[u(`div`,{className:`font-medium`,children:`2FA is active`}),i(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,r.confirmedAt?new Date(r.confirmedAt).toLocaleString():`—`]})]})]}),g&&i(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[u(T,{className:`h-3 w-3`}),g]}),u(`div`,{className:`flex justify-end`,children:i(`button`,{onClick:()=>{_(null),k.mutate()},disabled:k.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[k.isPending?u(b,{className:`h-3 w-3 animate-spin`}):u(v,{className:`h-3 w-3`}),`Disable 2FA`]})})]})]})]})}function je(){return ie(`auth-webauthn/passkey-enrollment`)?u(se,{widgetId:`auth-webauthn/passkey-enrollment`,host:`dashboard`}):null}export{Oe as MyAccessPage};
@@ -1 +0,0 @@
1
- import{H as e,I as t,K as n,Q as r,S as i,W as a,b as o,i as s,k as c,o as l,p as u,q as d,t as f,x as p,z as m}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{ot as h}from"./player-overlays-DEJGWVeQ.js";import{hi as g}from"./client-Cm-sr0wc.js";import{Er as _,Ri as v,V as y,_r as ee,gr as te,qr as ne}from"./src-CVCI1YgT.js";import{F as re,I as b,L as x,P as ie}from"./index-D7FGxQMl.js";r();var S=c(function({addonId:r,schema:i,serverValues:o,onImmediateSave:s,onStateChange:c,onAction:l,disabled:u},d){let f=x({schema:i,serverValues:o,onImmediateSave:t(e=>s(r,e),[r,s]),onDeferredSave:t(()=>{},[])});e(d,()=>({flush:()=>{let e={};for(let t of f.pendingKeys)e[t]=f.values[t];return f.handleDiscard(f.pendingKeys),e},discard:()=>f.resetAll()}),[f]);let h=f.pendingKeys,g=h.join(`|`),_=a(()=>h.map(e=>`${e}=${JSON.stringify(f.values[e])}`).join(`,`),[h,f.values]),v=n(c);m(()=>{v.current=c},[c]),m(()=>{let e={};for(let t of h)e[t]=f.values[t];v.current({addonId:r,pendingKeys:h,pendingValues:e})},[r,g,_]);let y=a(()=>{if(l)return(e,t,n)=>l(r,e,t,n)},[r,l]);return p(b,{schema:i,values:f.values,onChange:f.handleChange,disabled:u,onAction:y})});function C(e){return`perNode`in e&&e.perNode===!0}function w(e,t){if(e.type===`group`){let n=T(e.fields,t);return n.length>0?{...e,fields:n}:null}if(e.type===`sub-tabs`){let n=e.tabs.map(e=>({...e,fields:T(e.fields,t)})).filter(e=>e.fields.length>0);return n.length>0?{...e,tabs:n}:null}return C(e)===(t===`perNode`)?e:null}function T(e,t){let n=[];for(let r of e){let e=w(r,t);e!==null&&n.push(e)}return n}function ae(e,t){let n=[];for(let r of e.sections){let e=T(r.fields,t);e.length!==0&&n.push({...r,fields:e})}return{...e,sections:n}}function oe(e,t){let n=e??`general`;return t?.[n]??n}function E(e){return typeof e!=`object`||!e||!(`key`in e)?null:typeof e.key==`string`?e.key:null}function se(e,t){let n=t.fieldKeys===void 0?null:new Set(t.fieldKeys),r=[];for(let i of e){let e=n===null?i.fields:i.fields.filter(e=>{let t=E(e);return t!==null&&n.has(t)});e.length!==0&&r.push({...i,fields:e,...t.tabAliases===void 0?{}:{tab:oe(i.tab,t.tabAliases)},...t.hideSectionChrome===!0?{title:``,description:void 0}:{}})}return r}r();function D(e,t){if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`){let n=e.fields.map(e=>D(e,t));return{...e,fields:n}}let n=e;t[e.key]=n.value;let{value:r,...i}=n;return i}function O(e,t){return{...e,fields:e.fields.map(e=>D(e,t))}}function ce(e){let t={};return{schema:{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>O(e,t))},values:t}}function k({nodeId:e,addonIds:r,level:c,deviceId:m,capability:b,sectionIds:x,omitSectionIds:S,fieldKeys:C,hideSectionChrome:w,tabAliases:T,tabLabelOverrides:E,sectionTab:D,fieldScope:O,surface:k,emptyMessage:ue,extraTabs:A,schemaTabExtras:j,title:M,description:N,selfTabbed:de,activeTab:P,onActiveTabChange:fe}){let F=l(),I=h().trpcClient,L=ee(),R=te(),pe=v(),me=ne(),z=de===!0||!!(A&&A.length>0),[he,ge]=d(null);if(c===`device`&&!m)throw Error(`NodeAddonsSettingsPanel: deviceId is required when level === "device"`);if(k!==void 0){if(c!==`global`||m!==void 0)throw Error(`NodeAddonsSettingsPanel: integration-level settings are addon-wide — they cannot be mounted at device level or with a deviceId. A second page, never a second scope.`);if(e!==null)throw Error(`NodeAddonsSettingsPanel: an integration has no node behind it — pass nodeId={null}. Received ${JSON.stringify(e)}.`);if(O!==void 0)throw Error("NodeAddonsSettingsPanel: integration-level settings arrive already cluster-scoped from core — remove `fieldScope` rather than restating it.")}let B=e??`hub`,V=s({queries:r.map(e=>({queryKey:[[`addonSettings`,k===void 0?c===`global`?`getGlobalSettings`:`getDeviceSettings`:`getIntegrationSettings`],{addonId:e,nodeId:B,deviceId:m??null,cap:b??null,scope:O??null}],queryFn:async()=>{let t=e=>e!==null&&O!==void 0?ae(e,O):e;return k===void 0?c===`global`?{addonId:e,result:t(await I.addonSettings.getGlobalSettings.query({addonId:e,nodeId:B,...b?{cap:b}:{}}))}:{addonId:e,result:t(await I.addonSettings.getDeviceSettings.query({addonId:e,deviceId:m,nodeId:B}))}:{addonId:e,result:await I.addonSettings.getIntegrationSettings.query({addonId:e,nodeId:B})}},placeholderData:u}))}),_e=V.some(e=>e.isLoading),ve=V.map(e=>{if(!e.data)return`-`;if(e.data.result===null)return`${e.data.addonId}:n`;let t=[];for(let n of e.data.result.sections){t.push(`s:${n.id}:${n.tab??`general`}`);for(let e of n.fields){if(!(`key`in e))continue;let n=`options`in e&&Array.isArray(e.options)?e.options.map(e=>e.value).join(`,`):``,r=e.value,i=r===void 0?``:typeof r==`string`?r:JSON.stringify(r);t.push(`f:${e.key}:${n}:${i}`)}}return`${e.data.addonId}:${t.join(`|`)}`}).join(`||`),H=a(()=>{let e=new Set;for(let t of V){let n=t.data?.result?.sections;if(n)for(let t of n)e.add(oe(t.tab,T))}return[...e]},[T,ve+`::`+V.map(e=>(e.data?.result?.sections??[]).map(e=>e.tab??`general`).join(`,`)).join(`::`)]),U=a(()=>new Map((A??[]).map(e=>[e.id,e])),[A]),W=a(()=>{if(!z)return[];let e=[...new Set([...H,...(A??[]).map(e=>e.id),...(j??[]).map(e=>e.tabId)])],t=e=>{let t=U.get(e);if(t?.order!==void 0)return t.order;let n=g[e];return n?n.order:50};return e.toSorted((e,n)=>{let r=t(e),i=t(n);return r===i?e.localeCompare(n):r-i})},[z,H,A,U,j]),ye=a(()=>{let e=new Map,t=e=>g[e]?.label??e.charAt(0).toUpperCase()+e.slice(1);for(let n of H)e.set(n,t(n));for(let n of j??[])e.has(n.tabId)||e.set(n.tabId,t(n.tabId));for(let t of A??[])e.set(t.id,t.label);for(let[t,n]of Object.entries(E??{}))e.set(t,n);return e},[H,A,j,E]),G=P===void 0?he:P,K=z?G&&W.includes(G)?G:W[0]??null:null,be=e=>{ge(e),fe?.(e)},xe=K!==null&&U.has(K),q=z?K&&!xe?K:void 0:D,{data:Se}=_(void 0),Ce=a(()=>{let e=new Map;for(let t of Se??[]){let n=t.manifest?.id;if(!n)continue;let r=t.manifest?.name??t.manifest?.packageDisplayName??n;e.set(n,r)}return e},[Se]),we=n(new Map),J=a(()=>{let e=x?new Set(x):null,t=S?new Set(S):null,n=n=>!(e!==null&&!e.has(n)||t!==null&&t.has(n)),r=[];for(let e of V){if(!e.data)continue;let t=e.data.result??we.current.get(e.data.addonId)??null;if(e.data.result!==null&&we.current.set(e.data.addonId,e.data.result),t===null)continue;let{schema:i,values:a}=ce(t),o={...C===void 0?{}:{fieldKeys:C},...w===void 0?{}:{hideSectionChrome:w},...T===void 0?{}:{tabAliases:T}},s=se(i.sections.filter(e=>n(e.id)),o);if(s.length===0)continue;let c={...t,sections:se(t.sections.filter(e=>n(e.id)),o)},l={...i,sections:s};r.push({addonId:e.data.addonId,schemaWithValues:c,schema:l,serverValues:a})}return r},[ve,x,S,C,w,T]),[Y,Te]=d(new Map),Ee=t(e=>{Te(t=>{let n=new Map(t);return n.set(e.addonId,e),n})},[]),X=n(new Map),De=t(e=>t=>{t?X.current.set(e,t):X.current.delete(e)},[]),Z=t(async(e,t)=>{c===`global`?await L.mutateAsync({addonId:e,nodeId:B,patch:t}):await R.mutateAsync({addonId:e,deviceId:m,nodeId:B,patch:t}),F.invalidateQueries({queryKey:[[`addonSettings`]]})},[L,R,B,c,m,F]),Oe=t(async(e,t,n,r)=>{let i=B;try{switch(t){case`reprobe-hwaccel`:await pe.mutateAsync({nodeId:i}),F.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-audio-engine`:await me.mutateAsync({nodeId:i}),F.invalidateQueries({queryKey:[[`addonSettings`]]});return;default:{let n=await I.addons.custom.mutate({addonId:e,action:t,input:r});return F.invalidateQueries({queryKey:[[`addonSettings`]]}),n}}}catch(n){throw console.error(`[NodeAddonsSettingsPanel] action failed`,{addonId:e,action:t,err:n}),n}},[pe,me,B,F,I]),ke=t((e,t)=>{Z(e,t)},[Z]),Q=f({mutationFn:async()=>{let e=[];for(let t of J){let n=Y.get(t.addonId);!n||n.pendingKeys.length===0||e.push({addonId:t.addonId,patch:n.pendingValues})}return e.length===0?{saved:[]}:{saved:await Promise.all(e.map(async({addonId:e,patch:t})=>(c===`global`?await L.mutateAsync({addonId:e,nodeId:B,patch:t}):await R.mutateAsync({addonId:e,deviceId:m,nodeId:B,patch:t}),e)))}},onSuccess:({saved:e})=>{for(let t of e)X.current.get(t)?.discard();F.invalidateQueries({queryKey:[[`addonSettings`]]})}}),Ae=t(()=>{for(let e of X.current.values())e.discard()},[]),je=a(()=>{let e=0;for(let t of J){let n=Y.get(t.addonId);n&&(e+=n.pendingKeys.length)}return e},[J,Y]),Me=a(()=>{let e=new Map;for(let t of J){let n=Y.get(t.addonId);if(!n||n.pendingKeys.length===0)continue;let r=new Set(n.pendingKeys);for(let n of t.schema.sections){let t=n.tab??`general`;for(let i of n.fields)`key`in i&&r.has(i.key)&&e.set(t,(e.get(t)??0)+1)}}return e},[J,Y]);if(_e)return p(`div`,{className:`h-24 rounded-lg border border-border bg-surface animate-pulse`});let $=K&&xe?U.get(K):void 0;if(!z&&J.length===0)return p(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:ue??i(o,{children:[`No addons in`,` `,r.length>0?`[${r.join(`, `)}]`:`the current selection`,` expose`,` `,c,`-level settings on this node.`]})});let Ne=Q.isPending;return i(`div`,{className:`space-y-4`,children:[(M||N)&&i(`div`,{className:`border-b border-border pb-2`,children:[M&&p(`h2`,{className:`text-sm font-semibold text-foreground`,children:M}),N&&p(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:N})]}),z&&p(ie,{tabs:W.map(e=>({id:e,label:ye.get(e)??e})),activeId:K,onChange:be,pendingByTab:Me}),Q.isError&&i(`div`,{className:`rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-[11px] text-red-400`,children:[`Save failed: `,String(Q.error?.message??Q.error)]}),p(y,{tabKey:$?`extra:${K??``}`:`tab:${K??``}`,children:$?$.content:(()=>{let e=q?J.reduce((e,t)=>e+t.schemaWithValues.sections.filter(e=>(e.tab??`general`)===q).length,0):0,t=!!q&&e<=1,n=J.map(e=>({...e,renderedWithValues:{...e.schemaWithValues,sections:e.schemaWithValues.sections.filter(e=>q?(e.tab??`general`)===q:!0).map(e=>t?{...e,title:``,description:void 0}:e)}})).filter(e=>e.renderedWithValues.sections.length>0).toSorted((e,t)=>{let n=e=>{let t=1/0;for(let n of e)typeof n.order==`number`&&n.order<t&&(t=n.order);return t},r=n(e.renderedWithValues.sections),i=n(t.renderedWithValues.sections);return r===i?0:r-i}),r=(j??[]).filter(e=>e.tabId===q),a=r.filter(e=>(e.placement??`before`)===`before`),o=r.filter(e=>e.placement===`after`);return n.length===0&&r.length===0?p(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:ue??`Nothing to configure here for this node.`}):i(`div`,{className:`space-y-6`,children:[a.map((e,t)=>p(`div`,{children:e.content},`extra-before-${t}`)),n.length>0&&p(le,{entries:n,paneStates:Y,displayNames:Ce,disabled:Ne,setPaneRef:De,onPaneStateChange:Ee,onImmediateSave:ke,onAction:Oe,inline:z||!!D}),o.map((e,t)=>p(`div`,{children:e.content},`extra-after-${t}`))]})})()}),!_e&&p(re,{pendingCount:je,onSave:()=>Q.mutate(),onDiscard:Ae,saving:Ne})]})}function le({entries:e,paneStates:t,displayNames:n,disabled:r,setPaneRef:o,onPaneStateChange:s,onImmediateSave:c,onAction:l,inline:u}){let f=a(()=>[...e].toSorted((e,t)=>{if(e.addonId===`system-config`)return-1;if(t.addonId===`system-config`)return 1;let r=n.get(e.addonId)??e.addonId,i=n.get(t.addonId)??t.addonId;return r.localeCompare(i)}),[e,n]),[h,g]=d(f[0]?.addonId??``);m(()=>{f.length!==0&&(f.find(e=>e.addonId===h)||g(f[0].addonId))},[f,h]);let _=f.find(e=>e.addonId===h)??f[0];if(!_)return null;let v=a(()=>l?(e,t,n,r)=>l(e,t,n,r):void 0,[l]),y=e=>p(S,{ref:o(e.addonId),addonId:e.addonId,schema:e.renderedWithValues,serverValues:e.serverValues,onImmediateSave:c,onStateChange:s,onAction:v,disabled:r},e.addonId);return f.length===1||u?p(`div`,{className:`flex flex-col gap-4`,children:f.map(y)}):i(`div`,{className:`flex flex-col gap-3`,children:[p(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border shrink-0`,children:f.map(e=>{let r=n.get(e.addonId)??e.addonId,a=e.addonId===_.addonId,o=(t.get(e.addonId)?.pendingKeys.length??0)>0;return i(`button`,{type:`button`,onClick:()=>g(e.addonId),className:`relative px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors -mb-px border-b-2 whitespace-nowrap ${a?`text-primary border-primary bg-primary/5`:`text-foreground-subtle border-transparent hover:text-foreground hover:bg-surface-hover`}`,children:[r,o&&p(`span`,{className:`ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-amber-400`})]},e.addonId)})}),p(`div`,{className:`space-y-2`,children:f.map(e=>p(`div`,{style:e.addonId===_.addonId?void 0:{display:`none`},children:y(e)},e.addonId))})]})}export{k as t};