@camstack/addon-admin-ui 1.2.447 → 1.2.449

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 (134) hide show
  1. package/dist/assets/{AddonAssetIcon-4Dl3K5Yu.js → AddonAssetIcon-Rj3wnYY_.js} +1 -1
  2. package/dist/assets/Addons-WsKSFif5.js +4 -0
  3. package/dist/assets/{AdminPage-CTKQzYSK.js → AdminPage-C-diJ3HN.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-DB1wuvwM.js → AdminSectionedPage-B7UrSrns.js} +1 -1
  5. package/dist/assets/AiProfiles-BxHwvLTC.js +3 -0
  6. package/dist/assets/{BrokerForm-DgJKJJ9V.js → BrokerForm-DGyoc2rs.js} +1 -1
  7. package/dist/assets/Build-CWbm1ri9.js +40 -0
  8. package/dist/assets/Calendars-DuG_m8wt.js +1 -0
  9. package/dist/assets/{Cluster-CUFJA8Yh.js → Cluster-Cxo9fb5E.js} +1 -1
  10. package/dist/assets/{ClusterStepModel-G54nm4iG.js → ClusterStepModel-D7FHDo3b.js} +1 -1
  11. package/dist/assets/CompositionEditor-CW5KG78s.js +1 -0
  12. package/dist/assets/{CompositionEditorPage-DqCZgEdJ.js → CompositionEditorPage-C4wgJDTS.js} +1 -1
  13. package/dist/assets/Data-DrUKAnew.js +2 -0
  14. package/dist/assets/DeviceDetail-CgxNDsue.js +2 -0
  15. package/dist/assets/{DeviceDoActionFields-CU_AKA1W.js → DeviceDoActionFields-J1qr8JLD.js} +1 -1
  16. package/dist/assets/{Devices-CdmAtZP1.js → Devices-dusaAUzl.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-OyxmU511.js → EmbedPlayerPage-BuFLE2BZ.js} +1 -1
  18. package/dist/assets/History-D-IwtcW5.js +1 -0
  19. package/dist/assets/Identity-D-M8PFe5.js +1 -0
  20. package/dist/assets/IntegrationDetail-Cm6nS6Dd.js +1 -0
  21. package/dist/assets/IntegrationHub-jG5pe50x.js +1 -0
  22. package/dist/assets/Integrations-CIjceDno.js +1 -0
  23. package/dist/assets/Integrations-CuQ5m9xg.js +1 -0
  24. package/dist/assets/Library-B6dY6kqg.js +1 -0
  25. package/dist/assets/Locations-DcVyPbjW.js +3 -0
  26. package/dist/assets/{Logs-CaO5TsuY.js → Logs-CrcdhSoT.js} +1 -1
  27. package/dist/assets/{MaskShapeCanvas-CnazBudR.js → MaskShapeCanvas-D7B1a_d6.js} +1 -1
  28. package/dist/assets/{MotionZonesSettings-BcEiYvgb.js → MotionZonesSettings-Dv0SmFTj.js} +1 -1
  29. package/dist/assets/MyAccess-B1M-TD_l.js +2 -0
  30. package/dist/assets/{Network-BNthoi6m.js → Network-CNloyJcw.js} +1 -1
  31. package/dist/assets/{NodeAddonsSettingsPanel-CpONFsu0.js → NodeAddonsSettingsPanel-CGnlyS6W.js} +1 -1
  32. package/dist/assets/Notifications-DSQJwH9f.js +1 -0
  33. package/dist/assets/{PrivacyMaskSettings-B89MVHxL.js → PrivacyMaskSettings-ChKQKD1z.js} +1 -1
  34. package/dist/assets/Recordings-Bz4wjb-a.js +1 -0
  35. package/dist/assets/{ScanNetworkModal-B9n2JdTA.js → ScanNetworkModal-CLxLy0Jx.js} +1 -1
  36. package/dist/assets/{SceneMonitorEditor-Bmn_UcYs.js → SceneMonitorEditor-Dc0QrZZd.js} +1 -1
  37. package/dist/assets/SessionsList-D9f2zkon.js +2 -0
  38. package/dist/assets/{Showroom-BaHMWO3G.js → Showroom-lbpS7Xdx.js} +1 -1
  39. package/dist/assets/System-DLjh08cE.js +1 -0
  40. package/dist/assets/{Terminal-TaTeiXX0.js → Terminal-BKjM6jgI.js} +3 -3
  41. package/dist/assets/{Viewer-DXjhAdbS.js → Viewer-CykE8wsK.js} +1 -1
  42. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BYUIhxrf.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DJhucDeE.js} +1 -1
  43. package/dist/assets/{addon-icons-context-0MDrwtIo.js → addon-icons-context-BCJdR2as.js} +1 -1
  44. package/dist/assets/{archive-C3J7kPmp.js → archive-CnyG155u.js} +1 -1
  45. package/dist/assets/{authed-media-dGvmAGIm.js → authed-media-C0Di1-mt.js} +1 -1
  46. package/dist/assets/{bell-off-Df5MKmnk.js → bell-off-BCgckLrg.js} +1 -1
  47. package/dist/assets/{board-model-BVOHJW-k.js → board-model-BEF98n5Q.js} +1 -1
  48. package/dist/assets/{boxes-B4UVG1kT.js → boxes-uA3JVB9e.js} +1 -1
  49. package/dist/assets/circle-slash-CXSKoFJ3.js +1 -0
  50. package/dist/assets/client-CBY2Ai10.js +358 -0
  51. package/dist/assets/{cloud-upload-I7yc63rr.js → cloud-upload-C1akQpc4.js} +1 -1
  52. package/dist/assets/crop-CZVwalbq.js +1 -0
  53. package/dist/assets/{device-integration-icon-C_jsalSP.js → device-integration-icon-BwPIgj71.js} +1 -1
  54. package/dist/assets/device-picker-model-DspKRUOC.js +1 -0
  55. package/dist/assets/{dist-BOKrykX2.js → dist-DICOq93r.js} +1 -1
  56. package/dist/assets/dist-ucVPOol3.js +358 -0
  57. package/dist/assets/{eraser-WGJr5dAG.js → eraser-C_0A9Hjb.js} +1 -1
  58. package/dist/assets/{hard-drive-download-BqS2ahXp.js → hard-drive-download-B-DH1PV-.js} +1 -1
  59. package/dist/assets/{hostInit-Cn05saXf.js → hostInit-BEZmxPgL.js} +1 -1
  60. package/dist/assets/i18n-DBncQ6jl.js +1 -0
  61. package/dist/assets/{icons-BgfaaZCZ.js → icons-DprpVmeV.js} +1 -1
  62. package/dist/assets/{index-2_qB4G1l.js → index-DM2PlJTq.js} +3 -3
  63. package/dist/assets/{key-D741QkPA.js → key-CL8Jmw2S.js} +1 -1
  64. package/dist/assets/{key-round-_blTK3l4.js → key-round-C-Aw6TmA.js} +1 -1
  65. package/dist/assets/{layers-CBNWlTsd.js → layers-DSNZIEzf.js} +1 -1
  66. package/dist/assets/{linked-devices-model-Csh4WaVK.js → linked-devices-model-DzL0krEK.js} +1 -1
  67. package/dist/assets/{list-ordered-BTh8rts2.js → list-ordered-C1bZw0BL.js} +1 -1
  68. package/dist/assets/{location-owned-usage-Dqp8xgaw.js → location-owned-usage-dAl9CTze.js} +1 -1
  69. package/dist/assets/{log-in-Fh5saGuL.js → log-in-Ce7WBmUI.js} +1 -1
  70. package/dist/assets/{memory-stick-2qy4HWOo.js → memory-stick-DRGsvLsv.js} +1 -1
  71. package/dist/assets/{message-square-plus-D70FuCBB.js → message-square-plus-Cjk8neRy.js} +1 -1
  72. package/dist/assets/{mf-entry-bootstrap-0-1defdd87.js → mf-entry-bootstrap-0-2f4164ab.js} +2 -2
  73. package/dist/assets/{mic-off-MTwAUBdb.js → mic-off-CraNg8N9.js} +1 -1
  74. package/dist/assets/{monitor-off-Dn82QkPx.js → monitor-off-CgatD4nF.js} +1 -1
  75. package/dist/assets/{monitor-smartphone-K0Y4ODGq.js → monitor-smartphone-Ct9M1imf.js} +1 -1
  76. package/dist/assets/mount-DspKRUOC.js +1 -0
  77. package/dist/assets/notification-schedule-field-BJxF3SRn.js +1 -0
  78. package/dist/assets/{player-overlays-DyNPyo_W.js → player-overlays-B32sNiuW.js} +1 -1
  79. package/dist/assets/{recycle-DO1B1SCp.js → recycle-YQKD8v3i.js} +1 -1
  80. package/dist/assets/remoteEntry-Ba2ucEqQ.js +1 -0
  81. package/dist/assets/{scan-eye-DSsbXKWH.js → scan-eye-DkWYA8Qn.js} +1 -1
  82. package/dist/assets/{scissors-CGMgxeDq.js → scissors-d-Q62-mJ.js} +1 -1
  83. package/dist/assets/{search-x-CUa_1rys.js → search-x-Dh-cGhc7.js} +1 -1
  84. package/dist/assets/{send-CKZO6JbT.js → send-CUvOOMzH.js} +1 -1
  85. package/dist/assets/{settings-2-Dee5_Dd_.js → settings-2-DOLBKbT-.js} +1 -1
  86. package/dist/assets/{speaker-CGMtKx0N.js → speaker-GR-Ncblv.js} +1 -1
  87. package/dist/assets/src-wMLlETeo.js +67 -0
  88. package/dist/assets/{timer-reset-Dg8WnmrV.js → timer-reset-BSlB8Uty.js} +1 -1
  89. package/dist/assets/{ungroup-DqYydoru.js → ungroup-DlVR3lck.js} +1 -1
  90. package/dist/assets/{unlink-XIrgZrQf.js → unlink-CNQUhGTn.js} +1 -1
  91. package/dist/assets/{usb-33G087e5.js → usb-Bek6n_7R.js} +1 -1
  92. package/dist/assets/{use-scenes-feed-DsXuB27l.js → use-scenes-feed-v_NBqxW2.js} +1 -1
  93. package/dist/assets/{use-stationary-objects-D_FqXLHG.js → use-stationary-objects-CuK9Ramz.js} +1 -1
  94. package/dist/assets/useEventInvalidation-DspKRUOC.js +1 -0
  95. package/dist/assets/{useNodeUrlSelection-DWli8jTd.js → useNodeUrlSelection-WhpPPOny.js} +1 -1
  96. package/dist/assets/user-round-CtzL736C.js +1 -0
  97. package/dist/assets/{user-x-ODLis0Xn.js → user-x-B4ynO2HW.js} +1 -1
  98. package/dist/assets/{video-BtFmM3eg.js → video-JAYMKNkG.js} +1 -1
  99. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CHMiEHNO.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DHtR5Duv.js} +2 -2
  100. package/dist/index.html +10 -10
  101. package/dist/server/addon.js +27 -33
  102. package/package.json +1 -1
  103. package/dist/assets/Addons-D6G-9sO_.js +0 -4
  104. package/dist/assets/AiProfiles-DGYy6F5H.js +0 -3
  105. package/dist/assets/Build-ChuBRxJe.js +0 -40
  106. package/dist/assets/Calendars-DTLTaLNh.js +0 -1
  107. package/dist/assets/CompositionEditor-ZIvK82Sw.js +0 -1
  108. package/dist/assets/Data-Dt-vrsjS.js +0 -2
  109. package/dist/assets/DeviceDetail-B-JixtlL.js +0 -2
  110. package/dist/assets/History-CYEo0VmZ.js +0 -1
  111. package/dist/assets/Identity-CFqxjMZh.js +0 -1
  112. package/dist/assets/IntegrationDetail-Cv36j4Pb.js +0 -1
  113. package/dist/assets/IntegrationHub-Debcc46Y.js +0 -1
  114. package/dist/assets/Integrations-CTza89BR.js +0 -1
  115. package/dist/assets/Integrations-lU3DuymB.js +0 -1
  116. package/dist/assets/Library-D6P3tPHr.js +0 -1
  117. package/dist/assets/Locations-C0hvZIQb.js +0 -3
  118. package/dist/assets/MyAccess-CaTk0IGs.js +0 -2
  119. package/dist/assets/Notifications-WmYoCGsa.js +0 -1
  120. package/dist/assets/Recordings-BBu3Qb1s.js +0 -1
  121. package/dist/assets/SessionsList-D93VogSm.js +0 -2
  122. package/dist/assets/System-D-2Ma-Kz.js +0 -1
  123. package/dist/assets/circle-slash-BTU53Q69.js +0 -1
  124. package/dist/assets/client-CRCWO8cg.js +0 -358
  125. package/dist/assets/crop-B9ZtPXzr.js +0 -1
  126. package/dist/assets/device-picker-model-B0uThmDr.js +0 -1
  127. package/dist/assets/dist-C6cNUgRP.js +0 -358
  128. package/dist/assets/i18n-DzruZdmx.js +0 -1
  129. package/dist/assets/mount-B0uThmDr.js +0 -1
  130. package/dist/assets/notification-schedule-field-CeZmOaz1.js +0 -1
  131. package/dist/assets/remoteEntry-BiLc8a2-.js +0 -1
  132. package/dist/assets/src-_mtQMfPm.js +0 -67
  133. package/dist/assets/useEventInvalidation-B0uThmDr.js +0 -1
  134. package/dist/assets/user-round-CKL9ygyb.js +0 -1
@@ -0,0 +1 @@
1
+ import{$ as e,B as t,J as n,K as r,L as i,S as a,b as o,q as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{D as l,O as u,V as d,ca as f,ot as p}from"./player-overlays-B32sNiuW.js";import{Br as m,Cn as h,Fr as g,Gr as _,Hr as v,Kr as y,Nn as b,Rr as x,Sn as S,Ur as C,Wr as w,bn as ee,ei as T,oi as E,qr as D,si as O,ti as te,xn as ne,yn as re,zr as ie}from"./client-CBY2Ai10.js";import{Ar as ae,Ja as oe,Ku as se,Mu as ce,Rr as le,Wu as ue,Ya as k,_a as de,da as fe,fr as A,hr as j,s as pe,wo as me}from"./src-wMLlETeo.js";import{t as M}from"./i18n-DBncQ6jl.js";import{t as N}from"./useTranslation-D3Is_4B6.js";e();function he(e){return{target:{kind:`new`,type:e},name:``,features:[]}}function ge(e){return{target:{kind:`existing`,device:e},name:``,features:[]}}function P(e,t){return{target:e.target,name:t,features:e.features.flatMap(e=>e.kind===`fields`?[e]:[])}}function F(e,t,n){return{...e,features:e.features.map(e=>e.cap===t?n(e):e)}}function I(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>e!==t))}function _e(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 F(e,t.cap,e=>({...e,fields:{...e.fields,[t.path]:t.source}}));case`clear-field`:return F(e,t.cap,e=>({...e,fields:I(e.fields,t.path)}));case`remove-binding`:return F(e,t.cap,e=>{let n=e.fields[t.path];return n?.kind===`expression`?{...e,fields:{...e.fields,[t.path]:{...n,bindings:I(n.bindings,t.bindingName)}}}:e});case`copy-feature`:return F(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 ve(e){let t=m.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 ye(e,t){return JSON.stringify(e)!==JSON.stringify(t)}function be(e){for(let t=1;;t++){let n=`s${t}`;if(!e.includes(n))return n}}var xe=[`room`,`converted-sensor`,`derived-binary`],L={addonId:`provider-homeassistant`,stableId:`sensor.template_source`};function Se(){return P(S({temperatureSources:ee,motionSources:re,occupancyWindowMs:ne}),`Room`)}function Ce(){return P({target:{kind:`new`,type:O.Sensor},features:[{kind:`fields`,cap:`numeric-sensor`,fields:{value:{kind:`expression`,expr:`convert(v, "°C", "°F")`,bindings:{v:{kind:`from`,source:L,cap:`numeric-sensor`,fieldPath:`value`}}},unit:{kind:`expression`,expr:`"°F"`,bindings:{}},lastFetchedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Converted sensor`)}function we(){return P({target:{kind:`new`,type:O.Sensor},features:[{kind:`fields`,cap:`binary`,fields:{on:{kind:`expression`,expr:`v > 20`,bindings:{v:{kind:`from`,source:L,cap:`temperature-sensor`,fieldPath:`celsius`}}},lastChangedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Derived binary`)}function Te(e){switch(e){case`room`:return Se();case`converted-sensor`:return Ce();case`derived-binary`:return we()}}function Ee(e,t){return typeof t==`number`&&Number.isFinite(t)&&t>0?{kind:`device`,path:`/devices/${t}`}:{kind:`editor`,path:`/build/compositions/${encodeURIComponent(e)}`}}var R=`rounded-lg border border-border bg-surface p-4`,De=R;function Oe(e){return{addonId:e.addonId,stableId:e.stableId}}function z(e){return new Map(e.map(e=>[y(Oe(e)),e]))}function ke(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 Ae(e,t){let n=e.features.filter(e=>e.cap!==t);return n.length===0?null:{target:e.target,features:n}}function je(e,t){let n=e?.features.find(e=>e.cap===t);return n!==void 0&&n.kind===`fields`?n:null}function B(e){return Array.isArray(e)?e.map(B):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,B(t)]))}function V(e){return JSON.stringify(B(e))}function Me(e,t){return V(e)===V(t)}function H(e,t){return V(e)===V(t)}function Ne(e,t){switch(e.kind){case`pending`:return{kind:`refused`,reason:M.t(`helpers.customizationSave.notReadYet`)};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}:V(t)===V(e.composition)?{kind:`noop`}:{kind:`update`,blockId:n,expectedUpdatedAt:e.view.block.updatedAt,composition:t}}}}function U(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 W(e){return{kind:`expression`,expr:e,bindings:{}}}function G(e){let t=U(`number`,e.percentage);return t===null?null:{kind:`fields`,cap:`battery`,fields:e.mode===`replace`?{percentage:t}:{percentage:t,charging:W(`"unknown"`),sleeping:W(`false`),lastUpdated:W(`now`)}}}var Pe=[`percent`,...b.options];function K(e,t){return t===`percent`?{level:e}:{"remaining.value":e,"remaining.unit":W(JSON.stringify(t))}}function Fe(e,t){let n=U(`number`,t.remaining);if(n===null||!ie.test(t.key)||t.label.trim()===``)return null;let r={label:t.label.trim(),fields:K(n,t.unit)};return{kind:`fields`,cap:`consumables`,...e?.enabled===void 0?{}:{enabled:e.enabled},fields:e?.fields??{lastChangedAt:W(`now`),lastFetchedAt:W(`now`)},items:{...e?.items,[t.key]:r}}}function Ie(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 Le(e){return Object.entries(e?.items??{}).map(([e,t])=>{let n=Ie(t.fields),r=q(t.fields.level??t.fields[`remaining.value`]),i=r===null?null:U(`number`,r);return n!==null&&i!==null&&Me(K(i,n),t.fields)?{key:e,label:t.label,unit:n,source:r}:{key:e,label:t.label,unit:null,source:null}})}function Re(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 ze(e){return e.toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,48)}function Be(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 Ve(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 q(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 He(e,t){let n=q(e.fields.percentage);if(n===null)return!1;let r=G({percentage:n,mode:t}),{enabled:i,...a}=e;return r!==null&&H(a,r)}function J(e){return e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,location:e.location,type:e.type}))}function Ue(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 Y(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 We(e,t,n,r){return r===null?{kind:`from`,source:e,cap:t,fieldPath:n.path}:U(r,{source:e,cap:t,fieldPath:n.path,kind:n.kind})}function Ge(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:Y(n[e.cap],t.path),source:We(i,e.cap,t,r)})))}function X(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 Ke=[];function Z({title:e,targetKind:t,excludeDeviceIds:r=Ke,onPick:i,onCancel:o}){let{t:s}=N(),[f,p]=n(null);return a(`aside`,{"aria-label":e,className:`${u} ${l} flex flex-col gap-2`,children:[c(`h3`,{className:d,children:e}),f===null?c(qe,{excludeDeviceIds:r,onSelect:p}):c(Je,{device:f,targetKind:t,onPick:i,onBack:()=>p(null)}),c(`div`,{children:c(j,{variant:`ghost`,size:`sm`,onClick:o,children:s(`customize.picker.cancel`)})})]})}function qe({excludeDeviceIds:e,onSelect:t}){let{t:r}=N(),[i,s]=n(``),l=k({projection:`slim`});return a(o,{children:[a(`label`,{className:`flex flex-col gap-1 text-[11px] text-foreground-subtle`,children:[r(`customize.picker.search`),c(ce,{type:`search`,"aria-label":r(`customize.picker.search`),value:i,onChange:e=>s(e.target.value)})]}),l.status===`pending`&&c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:r(`customize.picker.loadingDevices`)}),l.status===`error`&&c(A,{title:r(`customize.picker.devicesFailed`),message:l.error?.message??``}),l.status===`success`&&c(`ul`,{className:`flex flex-col gap-1`,children:Ue(J(l.data),i,e).map(e=>c(`li`,{children:a(`button`,{type:`button`,className:`text-left text-[11px] hover:underline`,onClick:()=>t(e),children:[e.name,` `,a(`span`,{className:`text-foreground-subtle`,children:[`· `,e.stableId]})]})},e.id))})]})}function Je({device:e,targetKind:t,selected:n,onPick:r,onBack:i}){let{t:o}=N(),s=oe({deviceId:e.id}),l=me({deviceId:e.id});if(s.status===`pending`)return c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:o(`customize.picker.loadingFields`)});if(s.status===`error`)return c(A,{title:o(`customize.picker.fieldsFailed`),message:s.error?.message??``});let u=Ge(e,s.data,l.status===`success`?l.data:null,t),d=u.filter(e=>e.source===null).length,f={addonId:e.addonId,stableId:e.stableId};return a(`div`,{className:`flex flex-col gap-1`,children:[a(`button`,{type:`button`,className:`text-left text-[11px] text-primary`,onClick:i,children:[`← `,e.name]}),l.status===`error`&&c(`p`,{role:`alert`,className:`text-[10px] text-warning`,children:o(`customize.picker.valuesFailed`,{reason:l.error?.message??``})}),c(`ul`,{role:`listbox`,"aria-label":o(`customize.picker.fields`),className:`flex flex-col gap-1`,children:u.map(t=>{let i=t.source;if(i===null)return null;let o=()=>r({device:e,ref:f,cap:t.cap,path:t.path,kind:t.kind,source:i,value:t.value});return a(`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:[a(`span`,{className:`font-mono`,children:[t.cap,`.`,t.path]}),c(`span`,{children:X(t.value,l.status===`success`)})]},`${t.cap}.${t.path}`)})}),d>0&&t!==null&&c(`p`,{className:`text-[10px] text-foreground-subtle`,children:o(`customize.picker.hidden`,{count:d,kind:o(`customize.kinds.${t}`)})})]})}var Ye=`integration`;function Q(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:M.t(`helpers.fieldsTableRows.composerNotReported`)};let n=e.state.fields.find(t);return n===void 0?{kind:`unknown`,reason:M.t(`helpers.fieldsTableRows.noValue`)}:n.state===`unavailable`?{kind:`unavailable`,reason:n.reason??M.t(`common.unavailable`)}:{kind:`value`,value:n.value,staleReason:n.state===`stale`?n.reason??M.t(`common.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:Q(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,C(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:M.t(`helpers.fieldsTableRows.stateUnreadable`)};let r=Y(e[t],n),i=r===void 0?void 0:T(r);return i===void 0?{kind:`unknown`,reason:M.t(`helpers.fieldsTableRows.notReported`)}:{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:v(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)`},it=/[A-Za-z_][A-Za-z0-9_]*$/;function at(e,t,n){let r=it.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=[...te].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 ot(e,t,n){let r=t-(it.exec(e.slice(0,t))?.[0]??``).length;return{text:`${e.slice(0,r)}${n.insert}${e.slice(t)}`,cursor:r+n.insert.length}}e();function st({label:e,value:t,bindings:r,onChange:i}){let{t:o}=N(),l=s(null),[u,d]=n(t.length),f=at(t,u,r);return a(`div`,{className:`flex flex-col gap-1`,children:[a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[e,c(`input`,{ref:l,className:`font-mono px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`,value:t,onChange:e=>{i(e.target.value),d(e.target.selectionStart??e.target.value.length)},onSelect:e=>d(e.currentTarget.selectionStart??t.length)})]}),f.length>0&&c(`ul`,{role:`listbox`,"aria-label":o(`compositionEditor.suggestions`),className:`rounded border border-border bg-surface text-[11px]`,children:f.map(e=>a(`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=ot(t,u,e);i(n.text),d(n.cursor),l.current?.focus()},children:[c(`span`,{className:`font-mono`,children:e.label}),e.hintKey!==null&&c(`span`,{className:`text-foreground-subtle`,children:o(e.hintKey)})]},`${e.kind}:${e.label}`))})]})}function ct(e,t,n){if(e.kind===`code`)return{kind:`unavailable`,reason:M.t(`helpers.fieldPreview.codeFields`)};if(e.kind===`expression`&&(g(e.expr,`rose`)||g(e.expr,`count`)))return{kind:`runtime-only`};let r=D(e).filter(e=>t.get(_(e.source,e.cap))?.kind!==`value`).map(w);if(r.length>0)return{kind:`waiting`,missing:r};let i=h({source:e,now:n,read:e=>{let n=t.get(_(e.source,e.cap)),r=n?.kind===`value`?Y(n.slice,e.fieldPath):void 0,i=r===void 0?void 0:T(r);return i===void 0?{state:`unavailable`,reason:M.t(`helpers.fieldPreview.notReported`,{path:`${e.cap}.${e.fieldPath}`}),fatal:!1}:{state:`fresh`,value:i}}});return i.state===`unavailable`?{kind:`unavailable`,reason:i.reason}:{kind:`value`,value:i.value,stale:i.reason}}e();function lt({sliceKey:e,deviceId:n,capName:r,onReading:i}){let a=pe(p().trpcClient,n,r);return t(()=>{i(e,a===void 0?{kind:`pending`}:{kind:`value`,slice:a})},[e,a,i]),null}function ut(e,t){return[...new Map(D(e).map(e=>[_(e.source,e.cap),e]))].map(([e,n])=>({key:e,read:n,device:t.get(y(n.source))}))}function dt({source:e}){let{t}=N(),r=k({projection:`slim`}),[o,s]=n(new Map),l=i((e,t)=>{s(n=>new Map([...n,[e,t]]))},[]),u=ut(e,z(r.status===`success`?J(r.data):[])),d=r.status===`success`?u.filter(e=>e.device===void 0).map(e=>y(e.read.source)):[];return a(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[u.map(e=>e.device===void 0?null:c(lt,{sliceKey:e.key,deviceId:e.device.id,capName:e.read.cap,onReading:l},e.key)),c(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.label`)}),r.status===`error`?c(`span`,{className:`text-warning`,children:t(`compositionEditor.preview.devicesFailed`,{reason:r.error?.message??``})}):d.length>0?c(`span`,{className:`text-warning`,children:t(`compositionEditor.preview.unknownDevice`,{sources:d.join(`, `)})}):c(ft,{preview:ct(e,o,Date.now())})]})}function ft({preview:e}){let{t}=N();switch(e.kind){case`value`:return a(`strong`,{children:[`→ `,X(e.value,!0),e.stale===null?``:` (${e.stale})`]});case`unavailable`:return c(`span`,{className:`text-warning`,children:e.reason});case`waiting`:return c(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.waiting`,{sources:e.missing.join(`, `)})});case`runtime-only`:return c(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.runtimeOnly`)})}}e();function pt({path:e,kind:t,required:r,source:i,onSet:s,onClear:l,onRemoveBinding:u,sourceNames:d}){let{t:f}=N(),[p,m]=n(`idle`),h=i?.kind===`expression`?i:null;return a(`div`,{className:`flex flex-col gap-1 rounded border border-border p-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[c(`span`,{className:`font-mono text-[11px]`,children:e}),a(`span`,{className:`text-[10px] text-foreground-subtle`,children:[f(`customize.kinds.${t}`),r?` · ${f(`compositionEditor.required`)}`:``]}),c(j,{size:`sm`,variant:`outline`,onClick:()=>m(`take`),children:f(`compositionEditor.takeFrom`)}),c(j,{size:`sm`,variant:`outline`,"aria-pressed":h!==null,onClick:()=>s(h??{kind:`expression`,expr:`null`,bindings:{}}),children:f(`compositionEditor.formula`)}),i!==void 0&&c(j,{size:`sm`,variant:`ghost`,onClick:l,children:f(`compositionEditor.clear`)})]}),i?.kind===`from`&&c(`span`,{className:`text-[11px]`,children:Q(i,d)}),h!==null&&a(o,{children:[c(st,{label:f(`compositionEditor.formulaFor`,{path:e}),value:h.expr,bindings:Object.keys(h.bindings),onChange:e=>s({...h,expr:e})}),c(`ul`,{className:`text-[11px] flex flex-col gap-0.5`,children:Object.entries(h.bindings).map(([e,t])=>a(`li`,{className:`flex flex-wrap items-center gap-2`,children:[c(`span`,{className:`font-mono`,children:e}),c(`span`,{children:t.kind===`from`?Q(t,d):JSON.stringify(t.value)}),c(j,{size:`sm`,variant:`ghost`,"aria-label":f(`compositionEditor.removeBinding`,{name:e}),onClick:()=>u(e),children:`×`})]},e))}),c(j,{size:`sm`,variant:`ghost`,onClick:()=>m(`add-binding`),children:f(`compositionEditor.addSource`)})]}),p!==`idle`&&c(Z,{title:f(p===`take`?`compositionEditor.takeFrom`:`compositionEditor.addSource`),targetKind:p===`take`?t:null,onCancel:()=>m(`idle`),onPick:e=>{if(p===`take`)s(e.source);else if(h!==null){let t=be(Object.keys(h.bindings));s({...h,bindings:{...h.bindings,[t]:{kind:`from`,source:e.ref,cap:e.cap,fieldPath:e.path}}})}m(`idle`)}}),i!==void 0&&c(dt,{source:i})]})}e();function mt(e){return e===null||e.kind===`known`?null:e}function ht({draft:e,deviceType:t,nativeCaps:r,targetFields:i,dispatch:s}){let{t:l}=N(),u=fe({deviceType:t}),d=k({projection:`slim`}),f=new Map([...z(d.status===`success`?J(d.data):[])].map(([e,t])=>[e,t.name])),[p,m]=n(null),h=mt(r)??mt(i),g=r?.kind===`known`?r.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)?((i?.kind===`known`?i.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?a(o,{children:[a(`section`,{"aria-labelledby":`editor-features`,className:`${R} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),u.status===`pending`&&c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.checking`)}),u.status===`error`&&c(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.unknown`,{reason:u.error?.message??``})}),a(`div`,{className:`flex flex-wrap gap-1`,children:[e.features.map(e=>a(`span`,{className:`flex items-center gap-1 rounded border border-border px-1.5 text-[11px]`,children:[e.cap,c(le,{variant:g.has(e.cap)?`default`:`info`,children:g.has(e.cap)?l(`compositionEditor.replaces`):l(`compositionEditor.added`)}),c(`button`,{type:`button`,"aria-label":l(`compositionEditor.removeFeature`,{cap:e.cap}),onClick:()=>s({type:`remove-feature`,cap:e.cap}),children:`×`})]},e.cap)),v.map(e=>a(j,{size:`sm`,variant:`outline`,onClick:()=>s({type:`add-feature`,cap:e.cap}),children:[`+ `,e.cap]},e.cap)),y.map(e=>c(j,{size:`sm`,variant:`ghost`,onClick:()=>s({type:`add-feature`,cap:e}),children:l(`compositionEditor.replaceIn`,{cap:e})},e))]})]}),e.features.map(e=>a(`section`,{"aria-label":l(`compositionEditor.steps.fieldsOf`,{cap:e.cap}),className:`${R} flex flex-col gap-2`,children:[a(`div`,{className:`flex items-center justify-between`,children:[c(`h2`,{className:`text-sm font-semibold`,children:l(`compositionEditor.steps.fieldsOf`,{cap:e.cap})}),c(j,{size:`sm`,variant:`outline`,onClick:()=>m(e.cap),children:l(`compositionEditor.copyFeature`)})]}),p===e.cap&&c(Z,{title:l(`compositionEditor.copyFeature`),targetKind:null,onCancel:()=>m(null),onPick:t=>{s({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=>c(pt,{path:t.path,kind:t.kind,required:t.required,source:e.fields[t.path],onSet:n=>s({type:`set-field`,cap:e.cap,path:t.path,source:n}),onClear:()=>s({type:`clear-field`,cap:e.cap,path:t.path}),onRemoveBinding:n=>s({type:`remove-binding`,cap:e.cap,path:t.path,bindingName:n}),sourceNames:f},t.path))]},e.cap))]}):a(`section`,{"aria-labelledby":`editor-features`,className:`${R} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),c(`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 gt({draft:e,targetName:t,dispatch:n}){let r=f(),{t:i}=N(),o=e.target;return a(`section`,{"aria-labelledby":`editor-target`,className:`${R} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-target`,className:`text-sm font-semibold`,children:i(`compositionEditor.steps.target`)}),o.kind===`existing`?c(`p`,{className:`text-[11px]`,children:i(`compositionEditor.existingTarget`,{name:t??`${o.device.addonId}/${o.device.stableId}`})}):a(`div`,{className:`grid grid-cols-3 gap-2`,children:[a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[i(`compositionEditor.targetType`),c(`select`,{className:$,value:o.type,onChange:e=>{let t=Object.values(O).find(t=>t===e.target.value);t!==void 0&&n({type:`set-new-type`,deviceType:t})},children:Object.values(O).map(e=>c(`option`,{value:e,children:se(e,r).label},e))})]}),a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[i(`customize.identity.role`),a(`select`,{className:$,value:o.role??``,onChange:e=>n({type:`set-new-role`,role:Object.values(E).find(t=>t===e.target.value)??null}),children:[c(`option`,{value:``,children:i(`customize.identity.noRole`)}),Object.values(E).map(e=>c(`option`,{value:e,children:ue(e,r).label},e))]})]}),a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[i(`compositionEditor.name`),c(`input`,{className:$,value:e.name,onChange:e=>n({type:`set-name`,name:e.target.value})})]})]})]})}e();function _t({draft:e,blockId:r,saving:i,onSave:o,onCancel:s}){let{t:l}=N(),u=de(),d=ve(e),f=d.ok?JSON.stringify(d.composition):``,[p,m]=n({key:``,state:{kind:`checking`}});t(()=>{if(!d.ok)return;let e=d.composition,t=setTimeout(()=>{u.mutateAsync({composition:e,...r===null?{}:{blockId:r}}).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(t)},[f,r]);let h=d.ok?p.key===f?p.state:{kind:`checking`}:{kind:`invalid-draft`,problems:d.problems};return a(`section`,{"aria-labelledby":`editor-verify`,className:`${R} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-verify`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.verify`)}),h.kind===`checking`&&c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.verify.checking`)}),h.kind===`ok`&&c(`p`,{className:`text-[11px] text-success`,children:l(`compositionEditor.verify.ok`)}),h.kind===`unknown`&&c(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.verify.unknown`,{reason:h.reason})}),(h.kind===`invalid-draft`||h.kind===`refused`)&&c(`ul`,{role:`alert`,className:`flex flex-col gap-1 text-[11px] text-danger`,children:h.kind===`invalid-draft`?h.problems.map(e=>c(`li`,{children:e},e)):h.problems.map(e=>a(`li`,{children:[c(`span`,{className:`font-mono`,children:e.path}),` — `,e.message]},`${e.path}:${e.code}`))}),a(`div`,{className:`flex gap-2`,children:[c(j,{variant:`ghost`,onClick:s,children:l(`compositionEditor.cancel`)}),c(j,{disabled:h.kind!==`ok`||i||!d.ok,onClick:()=>d.ok&&o(d.composition),children:l(`compositionEditor.save`)})]})]})}e();function vt({initial:e,blockId:t,deviceType:r,targetName:i=null,nativeCaps:a,targetFields:o,save:s,onCancel:l,showTemplates:u=!1}){let[d,f]=n(e),p=`${d.name}:${d.features.map(e=>e.cap).join(`,`)}:${d.target.kind===`new`?d.target.type:`existing`}`;return c(yt,{seed:d,blockId:t,deviceType:r,targetName:i,nativeCaps:a,targetFields:o,showTemplates:u,onApplyTemplate:e=>{f(Te(e))},save:s,onCancel:l},p)}function yt({seed:e,blockId:t,deviceType:i,targetName:o,nativeCaps:s,targetFields:l,showTemplates:u,onApplyTemplate:d,save:f,onCancel:p}){let{t:m}=N(),h=ae(),[g,_]=r(_e,e),[v,y]=n(!1),[b,x]=n(null),S=async t=>{ye(e,g)&&!await h({title:m(`compositionEditor.templates.confirmTitle`),message:m(`compositionEditor.templates.confirmMessage`),confirmLabel:m(`compositionEditor.templates.confirmApply`),variant:`danger`})||d(t)},C=g.target.kind===`new`?g.target.type:i,w=async e=>{y(!0);let t=await f(e,g.name);y(!1),x(t.kind===`refused`?t.reason:null)};return a(`div`,{className:`flex flex-col gap-4`,children:[u&&g.target.kind===`new`&&a(`div`,{className:`rounded-lg border border-border bg-surface p-4 flex flex-wrap gap-2`,"data-testid":`composition-templates`,children:[c(`span`,{className:`text-[11px] text-foreground-subtle self-center`,children:m(`compositionEditor.templates.label`)}),xe.map(e=>c(j,{size:`sm`,variant:`outline`,onClick:()=>void S(e),children:m(`compositionEditor.templates.${e}`)},e))]}),c(gt,{draft:g,targetName:o,dispatch:_}),c(ht,{draft:g,deviceType:C,nativeCaps:s,targetFields:l,dispatch:_}),c(_t,{draft:g,blockId:t,saving:v,onSave:e=>void w(e),onCancel:p}),b!==null&&c(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:b})]})}export{Ae as C,ge as D,P as E,he as O,ke as S,Ee as T,q as _,Je as a,Ne as b,J as c,Fe as d,Le as f,ze as g,He as h,nt as i,Pe as l,Ve as m,ct as n,X as o,Be as p,st as r,Y as s,vt as t,G as u,Re as v,De as w,H as x,je as y};
@@ -1 +1 @@
1
- import{S as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Xr as n,xr as r}from"./client-CRCWO8cg.js";import{t as i}from"./boxes-B4UVG1kT.js";import{aa as a,fa as o,fr as s,ta as c}from"./src-_mtQMfPm.js";import{t as l}from"./useTranslation-D3Is_4B6.js";import{Q as u,_ as d,et as f,f as p,tt as m}from"./index-2_qB4G1l.js";import{E as h,O as g,T as _,t as v,w as y}from"./CompositionEditor-ZIvK82Sw.js";import{t as b}from"./AdminPage-CTKQzYSK.js";var x=`new`;function S(e){return e instanceof Error?e.message:String(e)}function C(e){let t=e.trim();return t===``?{}:{name:t}}function w(){let{blockId:w}=m(),{t:T}=l(),E=f(),D=c(),O=o(),k=w===void 0||w===x,A=a({blockId:w??``},{enabled:!k}),j=()=>{E(p)},M=e=>t(b,{icon:i,title:T(`compositionEditor.pageTitle`),children:e}),N=e=>t(`section`,{className:`${y} flex flex-col gap-2`,children:e});if(k)return M(t(v,{initial:g(n.Sensor),blockId:null,deviceType:n.Sensor,nativeCaps:null,targetFields:null,showTemplates:!0,onCancel:j,save:async(e,t)=>{try{let{block:n}=await D.mutateAsync({block:{...C(t),enabled:!0,composition:e}});return E(_(n.id,null).path,{replace:!0}),{kind:`saved`}}catch(e){return{kind:`refused`,reason:S(e)}}}}));if(A.status===`pending`)return M(N(t(`p`,{role:`status`,children:T(`compositionEditor.loading`)})));if(A.status===`error`)return M(N(t(s,{title:T(`compositionEditor.loadFailed`),message:A.error.message})));if(A.data.state===`not-loaded`)return M(N(t(`p`,{role:`status`,children:T(`customize.status.notLoaded`,{reason:A.data.reason})})));let P=A.data.view;if(P===null)return M(N(t(`p`,{children:T(`compositionEditor.notFound`,{blockId:w})})));let F=r(P.block);if(F===null)return M(N(t(`p`,{children:T(`compositionEditor.notComposition`)})));if(F.target.kind===`existing`){let e=P.state.kind===`answered`?P.state.state?.deviceId??null:null;return M(N(e===null?t(`p`,{children:T(`compositionEditor.customizationUnknownDevice`)}):t(u,{className:`text-primary`,to:d(e),children:T(`compositionEditor.openOnDevice`)})))}let I=P.state.kind===`answered`?P.state.state?.deviceId??null:null,L=I===null?null:_(P.block.id,I);return M(e(`div`,{className:`flex flex-col gap-3`,children:[L!==null&&L.kind===`device`&&t(u,{className:`text-sm text-primary`,to:L.path,"data-testid":`open-composed-device`,children:T(`compositionEditor.openComposedDevice`,{id:I})}),t(v,{initial:h(F,P.block.name),blockId:P.block.id,deviceType:F.target.type,nativeCaps:null,targetFields:null,onCancel:j,save:async(e,t)=>{try{return await O.mutateAsync({blockId:P.block.id,expectedUpdatedAt:P.block.updatedAt,block:{...C(t),composition:e}}),await A.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:S(e)}}}},`${P.block.id}@${P.block.updatedAt}`)]}))}export{w as CompositionEditorPage};
1
+ import{S as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Mr as n,si as r}from"./client-CBY2Ai10.js";import{t as i}from"./boxes-uA3JVB9e.js";import{aa as a,fr as o,ga as s,la as c}from"./src-wMLlETeo.js";import{t as l}from"./useTranslation-D3Is_4B6.js";import{Q as u,_ as d,et as f,f as p,tt as m}from"./index-DM2PlJTq.js";import{E as h,O as g,T as _,t as v,w as y}from"./CompositionEditor-CW5KG78s.js";import{t as b}from"./AdminPage-C-diJ3HN.js";var x=`new`;function S(e){return e instanceof Error?e.message:String(e)}function C(e){let t=e.trim();return t===``?{}:{name:t}}function w(){let{blockId:w}=m(),{t:T}=l(),E=f(),D=a(),O=s(),k=w===void 0||w===x,A=c({blockId:w??``},{enabled:!k}),j=()=>{E(p)},M=e=>t(b,{icon:i,title:T(`compositionEditor.pageTitle`),children:e}),N=e=>t(`section`,{className:`${y} flex flex-col gap-2`,children:e});if(k)return M(t(v,{initial:g(r.Sensor),blockId:null,deviceType:r.Sensor,nativeCaps:null,targetFields:null,showTemplates:!0,onCancel:j,save:async(e,t)=>{try{let{block:n}=await D.mutateAsync({block:{...C(t),enabled:!0,composition:e}});return E(_(n.id,null).path,{replace:!0}),{kind:`saved`}}catch(e){return{kind:`refused`,reason:S(e)}}}}));if(A.status===`pending`)return M(N(t(`p`,{role:`status`,children:T(`compositionEditor.loading`)})));if(A.status===`error`)return M(N(t(o,{title:T(`compositionEditor.loadFailed`),message:A.error.message})));if(A.data.state===`not-loaded`)return M(N(t(`p`,{role:`status`,children:T(`customize.status.notLoaded`,{reason:A.data.reason})})));let P=A.data.view;if(P===null)return M(N(t(`p`,{children:T(`compositionEditor.notFound`,{blockId:w})})));let F=n(P.block);if(F===null)return M(N(t(`p`,{children:T(`compositionEditor.notComposition`)})));if(F.target.kind===`existing`){let e=P.state.kind===`answered`?P.state.state?.deviceId??null:null;return M(N(e===null?t(`p`,{children:T(`compositionEditor.customizationUnknownDevice`)}):t(u,{className:`text-primary`,to:d(e),children:T(`compositionEditor.openOnDevice`)})))}let I=P.state.kind===`answered`?P.state.state?.deviceId??null:null,L=I===null?null:_(P.block.id,I);return M(e(`div`,{className:`flex flex-col gap-3`,children:[L!==null&&L.kind===`device`&&t(u,{className:`text-sm text-primary`,to:L.path,"data-testid":`open-composed-device`,children:T(`compositionEditor.openComposedDevice`,{id:I})}),t(v,{initial:h(F,P.block.name),blockId:P.block.id,deviceType:F.target.type,nativeCaps:null,targetFields:null,onCancel:j,save:async(e,t)=>{try{return await O.mutateAsync({blockId:P.block.id,expectedUpdatedAt:P.block.updatedAt,block:{...C(t),composition:e}}),await A.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:S(e)}}}},`${P.block.id}@${P.block.updatedAt}`)]}))}export{w as CompositionEditorPage};
@@ -0,0 +1,2 @@
1
+ import{$ as e,B as t,G as n,J as r,L as i,S as a,b as o,o as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{An as l,D as u,Fn as d,Gr as f,It as p,Ki as m,Nt as h,Q as g,Qr as _,Si as v,Xi as y,Yr as b,Zi as x,bi as S,ci as C,fn as w,ir as T,kn as E,mi as D,oi as O,or as k,rr as A,vn as j}from"./player-overlays-B32sNiuW.js";import{n as M,t as N}from"./cloud-upload-C1akQpc4.js";import{t as P}from"./circle-slash-CXSKoFJ3.js";import{t as F}from"./hard-drive-download-B-DH1PV-.js";import{$n as I,Ai as ee,An as L,Ar as R,Bi as te,Cl as z,Dn as ne,Du as re,Fi as ie,Hi as ae,Ii as oe,Li as B,Ll as se,Mi as ce,Mn as le,Mu as ue,Ni as de,Nu as V,Pa as fe,Pi as pe,Qn as me,Ri as he,Sl as ge,Ui as _e,Vi as ve,Wi as ye,_n as be,at as xe,dt as Se,er as Ce,fr as we,gn as Te,hr as H,ir as Ee,ji as De,ki as Oe,kn as ke,lt as Ae,nr as je,pi as Me,pr as Ne,rr as Pe,ul as Fe,ut as Ie,vt as U,wl as Le,xl as Re,zi as ze}from"./src-wMLlETeo.js";import{t as W}from"./i18n-DBncQ6jl.js";import{t as G}from"./useTranslation-D3Is_4B6.js";import"./mount-DspKRUOC.js";import{$ as Be,T as Ve,Z as He,nt as Ue}from"./index-DM2PlJTq.js";import{t as We}from"./AdminSectionedPage-B7UrSrns.js";import{t as Ge}from"./AdminPage-C-diJ3HN.js";import{n as Ke}from"./authed-media-C0Di1-mt.js";import{t as K}from"./format-size-DIxKXxtj.js";import{a as qe,c as Je,l as Ye,n as Xe,o as Ze,s as Qe,t as $e,u as et}from"./location-owned-usage-dAl9CTze.js";e();function tt(){let{t:e}=G(),r=s(),i=R(),{data:o,isLoading:l,isError:u}=Le({}),d=z(),f=n(()=>d.data??[],[d.data]),{data:p}=Fe({},{refetchOnWindowFocus:!1}),m=n(()=>$e(o??[],p?.locations),[o,p?.locations]),{data:h}=ge({},{refetchOnWindowFocus:!1}),g=n(()=>qe(h),[h]),{state:_,openNew:v,openEdit:y,close:b}=Ae(),[x,S]=Ie(`type`),C=()=>{S(null),b()},w=e=>{S(e),v()},T=e=>{S(null),y(e.id)},E=o??[],D=_.mode===`edit`?E.find(e=>e.id===_.id)??null:null;t(()=>{_.mode===`new`&&(x===null||x===``)&&(S(null),b())},[_.mode,x,b,S]),t(()=>{_.mode===`edit`&&!l&&D===null&&(S(null),b())},[_.mode,l,D,b,S]),t(()=>{_.mode===`closed`&&x!==null&&S(null)},[_.mode,x,S]);let O=Re({onSuccess:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),k=se({onSuccess:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),A=async(t,n)=>{Ye(n)&&!await i({title:e(`system.storage.disable`,`Disable "{{displayName}}"?`,{displayName:t.displayName}),message:e(`system.storage.nothingIsDeletedSetThe`,`{{consequence}} Nothing is deleted — set the location back to Read-only or Active to bring its footage back.`,{consequence:Je(n).consequence}),confirmLabel:e(`common.disable`,`Disable`),variant:`danger`})||k.mutate(Qe(t,{mode:n}))},j=async t=>{if(await i({title:e(`system.storage.deleteLocation`,`Delete location "{{displayName}}"?`,{displayName:t.displayName}),message:e(`system.storage.thisRemovesTheLocationRecord`,`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`}))try{await O.mutateAsync({id:t.id}),_.mode===`edit`&&_.id===t.id&&C()}catch(n){await i({title:e(`system.storage.deleteAnyway`,`Delete anyway?`),message:e(`system.storage.forcingNote`,{error:n instanceof Error?n.message:String(n)}),confirmLabel:e(`system.storage.forceDelete`,`Force delete`),variant:`danger`})&&O.mutate({id:t.id,force:!0},{onSuccess:()=>{_.mode===`edit`&&_.id===t.id&&C()}})}},M=n(()=>{let e=new Map;for(let t of o??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[o]),N=l||d.isLoading,P=u||d.isError,F=_.mode===`new`&&x!==null&&x!==``,I=_.mode===`edit`&&D!==null;return a(Ge,{embedded:!0,children:[N&&c(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:e(`system.storage.loadingLocations`,`Loading locations…`)}),P&&c(`div`,{className:`text-xs text-danger`,children:e(`system.storage.failedToLoadStorageLocations`,`Failed to load storage locations.`)}),!N&&!P&&a(`div`,{className:`space-y-3`,children:[f.length===0&&c(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:e(`system.storage.noStorageLocationsDeclaredBy`,`No storage locations declared by any installed addon.`)}),f.map(e=>c(Xe,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:M.get(e.id)??[],onAdd:w,onEdit:T,onDelete:e=>{j(e)},ownedBytesById:m,drainById:g,onSetMode:(e,t)=>{A(e,t)}},e.id))]}),F&&x!==null&&c(et,{initialType:x,onClose:C,onCreated:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),C()}}),I&&D!==null&&c(Ze,{location:D,onClose:C,onSaved:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),C()}})]})}var q={settings:{labelKey:`helpers.backupDatabases.settings.label`,descriptionKey:`helpers.backupDatabases.settings.description`,shortKey:`helpers.backupDatabases.settings.short`},events:{labelKey:`helpers.backupDatabases.events.label`,descriptionKey:`helpers.backupDatabases.events.description`,shortKey:`helpers.backupDatabases.events.short`},history:{labelKey:`helpers.backupDatabases.history.label`,descriptionKey:`helpers.backupDatabases.history.description`,shortKey:`helpers.backupDatabases.history.short`}},nt=Object.keys(q),J=[`settings`];function rt(){return W.t(`helpers.backupDatabases.notCreated`)}function it(e){return W.t(q[e].labelKey)}function at(e){return W.t(q[e].shortKey)}function ot(e){return W.t(q[e].descriptionKey)}function Y(e){let t=new Set(e);return nt.filter(e=>t.has(e))}function X(e){return e!==void 0&&e.length>0?Y(e):J}function st(e){return Y(e)}function ct(e,t){return t===void 0||!t.answered?`unknown`:t.databases.includes(e)?`present`:`absent`}function lt(e,t,n){return ct(e,t)===`absent`&&!n.has(e)}function ut(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function dt(e){return!e.includes(`settings`)}function ft(e){return{databases:[...st(e)]}}function pt(e,t){return e!==void 0&&e.length>0?Y(e):t!==void 0&&t.length>0?Y(t.map(e=>e.databaseId??`settings`)):J}function Z({databases:e}){return c(`span`,{className:`text-xs font-medium uppercase tracking-wide text-foreground-muted`,"data-testid":`backup-database-badges`,children:e.map(e=>at(e)).join(` · `)})}e();var mt=[[`backup`,`listDestinations`]],ht=[`backup`,`listArchives`];function gt({destinationId:e,restoreSupported:t,onOpenRestoreWizard:o}){let{t:l}=G(),u=s(),d=R(),{data:m,isLoading:h,isError:g}=ie({destinationId:e}),_=m??[],v=ee({onSuccess:()=>{u.invalidateQueries({queryKey:[[...ht]]}),u.invalidateQueries({queryKey:mt})}}),y=i(async t=>{await d({title:l(`backup.archiveList.deleteThisArchive`,`Delete this archive?`),message:l(`backup.archiveList.permanentlyDeletesAndFrees`,`Permanently deletes "{{value1}}" and frees {{value2}}.`,{value1:t.label??t.id,value2:K(t.sizeBytes)}),confirmLabel:l(`common.delete`,`Delete`),variant:`danger`})&&v.mutate({destinationId:e,backupId:t.id})},[d,e,v,l]),[b,x]=r(null),S=i(async t=>{x(t.id);try{let n=await Ke(_t(e,t.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${t.label??t.id}.tar.gz${t.encryption===void 0?``:`.csbk`}`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{x(null)}},[e]),C=n(()=>[..._].toSorted((e,t)=>t.createdAt-e.createdAt),[_]);return h?c(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:l(`backup.archiveList.loadingArchives`,`Loading archives…`)}):g?c(`div`,{className:`text-xs text-danger py-2`,children:l(`backup.archiveList.failedToReadManifestFor`,`Failed to read manifest for this destination`)}):C.length===0?c(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:l(`backup.archiveList.noArchivesAtThisDestination`,`No archives at this destination yet.`)}):c(Te,{columns:[{key:`when`,header:l(`backup.archiveList.when`,`When`),sortValue:e=>e.createdAt,render:e=>c(`span`,{className:`tabular-nums`,children:vt(e.createdAt)})},{key:`label`,header:l(`backup.archiveList.label`,`Label`),sortValue:e=>e.label??null,render:e=>a(`span`,{className:`inline-flex items-center gap-1`,children:[e.encryption!==void 0&&c(A,{className:`h-3 w-3 text-success`,"aria-label":l(`backup.archiveList.encryptedRestoreNeedsBackupKey`,`encrypted — restore needs backup key {{keyId}}`,{keyId:e.encryption.keyId})}),e.label??c(`span`,{className:`text-foreground-subtle italic`,children:`—`})]})},{key:`databases`,header:l(`backup.archiveList.databases`,`Databases`),nowrap:!1,notSortableReason:`Database badges`,render:e=>c(Z,{databases:X(e.databases)})},{key:`includes`,header:l(`backup.archiveList.files`,`Files`),nowrap:!1,notSortableReason:`Location list`,render:e=>e.locations.length>0?c(`span`,{className:`text-foreground-subtle`,children:e.locations.join(`, `)}):c(`span`,{className:`text-foreground-subtle italic`,children:l(`common.none`)})},{key:`size`,header:l(`backup.archiveList.size`,`Size`),align:`right`,sortValue:e=>e.sizeBytes,render:e=>c(`span`,{className:`tabular-nums`,children:K(e.sizeBytes)})},{key:`actions`,header:``,align:`right`,notSortableReason:`Actions`,render:n=>a(`span`,{className:`flex items-center justify-end gap-1`,children:[a(H,{variant:`ghost`,size:`sm`,onClick:()=>{S(n)},disabled:b===n.id,title:l(`backup.archiveList.downloadArchive`,`Download archive`),children:[b===n.id?c(k,{className:`h-3 w-3 animate-spin`}):c(f,{className:`h-3 w-3`}),l(`backup.archiveList.download`,`Download`)]}),t&&o&&a(H,{variant:`ghost`,size:`sm`,onClick:()=>o({destinationId:e,archiveId:n.id}),title:l(`backup.archiveList.restoreFromThisArchive`,`Restore from this archive`),children:[c(j,{className:`h-3 w-3`}),l(`backup.archiveList.restore`,`Restore`)]}),c(V,{variant:`ghost`,size:`sm`,icon:p,"aria-label":l(`backup.archiveList.delete`,`Delete {{value1}}`,{value1:n.label??n.id}),disabled:v.isPending,onClick:()=>{y(n)}})]})}],rows:C,rowKey:e=>e.id,minWidthPx:760,emptyMessage:l(`backup.archiveList.noArchivesAtThisDestination`,`No archives at this destination yet.`)})}function _t(e,t){return g(`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}function vt(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}e();var yt=[[`backup`,`listSchedules`]];function bt({onEdit:e,onOpenRestoreWizard:t}){let{t:o}=G(),{data:s,isLoading:l,isError:u,error:d,refetch:f}=ze(),p=s??[],m=B().data??[],h=n(()=>{let e=new Map;for(let t of m)e.set(t.id,t);return e},[m]),[g,_]=r(null),v=i(e=>{_(t=>t===e?null:e)},[]),y=n(()=>xt({destById:h,expandedId:g,onToggleExpand:v,onEdit:e}),[h,g,v,e]);return l?a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle animate-pulse`,children:[c(k,{className:`h-3.5 w-3.5 animate-spin`}),o(`backup.backupEntriesTable.loadingBackupEntries`,`Loading backup entries…`)]}):u?c(we,{title:o(`backup.backupEntriesTable.failedToLoadBackupEntries`,`Failed to load backup entries`),message:d instanceof Error?d.message:o(`backup.backupEntriesTable.unknownError`,`Unknown error`),onRetry:()=>void f()}):p.length===0?c(Ne,{icon:M,title:o(`backup.backupEntriesTable.noBackupEntriesYet`,`No backup entries yet`),description:o(`backup.backupEntriesTable.createOneToScheduleBackups`,`Create one to schedule backups across one or more storage locations.`)}):c(Te,{columns:y,rows:p,rowKey:e=>e.id,minWidthPx:980,maxBodyHeight:be,emptyMessage:o(`backup.backupEntriesTable.noBackupEntriesYet`,`No backup entries yet`),onRowClick:t=>e(t),isExpanded:e=>e.id===g,renderExpanded:e=>c(Ot,{row:e,destById:h,...t?{onOpenRestoreWizard:t}:{}})})}function xt(e){return[{key:`expand`,header:``,width:`w-8`,nowrap:!0,notSortableReason:`Expand control`,render:t=>{let n=e.expandedId===t.id;return c(V,{variant:`ghost`,size:`sm`,icon:n?v:S,"aria-label":n?W.t(`backup.backupEntriesTable.hideArchives`,`Hide archives`):W.t(`backup.backupEntriesTable.showArchives`,`Show archives`),"aria-expanded":n,onClick:n=>{n.stopPropagation(),e.onToggleExpand(t.id)}})}},{key:`entry`,header:W.t(`backup.backupEntriesTable.entry`,`Entry`),sortValue:e=>e.label,render:e=>a(`span`,{className:`flex min-w-0 flex-col`,children:[c(`span`,{className:`truncate font-medium text-foreground`,children:e.label||W.t(`backup.backupEntriesTable.unnamed`,`(unnamed)`)}),e.lastRunAt!==void 0&&c(`span`,{className:`text-[10px] text-foreground-subtle`,children:W.t(`backup.backupEntriesTable.lastRun`,{when:new Date(e.lastRunAt).toLocaleString()})})]})},{key:`enabled`,header:W.t(`backup.backupEntriesTable.enabled`,`Enabled`),width:`w-20`,nowrap:!0,sortValue:e=>+!!e.enabled,render:e=>c(`span`,{onClick:e=>e.stopPropagation(),children:c(Tt,{row:e})})},{key:`databases`,header:W.t(`backup.backupEntriesTable.backsUp`,`Backs up`),nowrap:!1,notSortableReason:`Database badges`,render:e=>c(Z,{databases:X(e.databases)})},{key:`locations`,header:W.t(`backup.backupEntriesTable.locations`,`Locations`),nowrap:!1,notSortableReason:`Location chips`,render:t=>c(St,{row:t,destById:e.destById})},{key:`retention`,header:W.t(`backup.backupEntriesTable.retention`,`Retention`),width:`w-24`,nowrap:!0,sortValue:e=>e.retentionCount,render:e=>c(`span`,{onClick:e=>e.stopPropagation(),children:c(Et,{row:e})})},{key:`schedule`,header:W.t(`backup.backupEntriesTable.schedule`,`Schedule`),width:`w-48`,nowrap:!0,sortValue:e=>e.cron,render:e=>c(Ct,{row:e})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:t=>c(`span`,{onClick:e=>e.stopPropagation(),children:c(Dt,{row:t,onEdit:()=>e.onEdit(t)})})}]}function St({row:e,destById:t}){let{t:n}=G();return e.locationIds.length===0?c(`span`,{className:`text-[11px] italic text-danger`,children:n(`backup.backupEntriesTable.noLocations`,`No locations`)}):c(`span`,{className:`flex flex-wrap gap-1`,children:e.locationIds.map(e=>c(`span`,{className:`inline-flex items-center rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-foreground`,title:e,children:t.get(e)?.displayName??e},e))})}function Ct({row:e}){let{t}=G(),n=e.cron.trim().length>0;return a(`span`,{className:`flex flex-col items-start gap-0.5`,children:[a(`span`,{className:`inline-flex items-center gap-1`,children:[c(M,{className:`h-3 w-3 text-foreground-subtle`}),c(`span`,{className:`font-mono text-[11px] text-foreground`,children:n?e.cron:t(`backup.backupEntriesTable.manual`,`Manual`)})]}),n&&e.nextRunAt!==void 0&&c(`span`,{className:`text-[10px] text-foreground-subtle`,children:W.t(`common.nextRun`,{when:new Date(e.nextRunAt).toLocaleString()})})]})}function wt(e){return n(()=>({id:e.id,label:e.label,cron:e.cron,locationIds:[...e.locationIds],retentionCount:e.retentionCount,...e.dataSources?{dataSources:[...e.dataSources]}:{},...e.databases?{databases:[...e.databases]}:{}}),[e])}function Tt({row:e}){let{t}=G(),n=s(),r=ye({onSuccess:()=>{n.invalidateQueries({queryKey:yt})}}),i=wt(e);return c(`label`,{className:`inline-flex cursor-pointer items-center`,children:c(`input`,{type:`checkbox`,className:`accent-primary`,checked:e.enabled,disabled:r.isPending,onChange:e=>r.mutate({...i,enabled:e.target.checked}),"aria-label":t(`backup.backupEntriesTable.enable`,`Enable {{value1}}`,{value1:e.label||e.id})})})}function Et({row:e}){let{t:n}=G(),i=s(),a=ye({onSuccess:()=>{i.invalidateQueries({queryKey:yt})}}),o=wt(e),[l,u]=r(String(e.retentionCount));return t(()=>{u(String(e.retentionCount))},[e.retentionCount]),c(ue,{type:`number`,min:1,max:1e3,value:l,disabled:a.isPending,onChange:e=>u(e.target.value),onBlur:()=>{let t=Number.parseInt(l,10);if(Number.isNaN(t)||t<1){u(String(e.retentionCount));return}t!==e.retentionCount&&a.mutate({...o,enabled:e.enabled,retentionCount:t})},onKeyDown:t=>{t.key===`Enter`&&t.target.blur(),t.key===`Escape`&&u(String(e.retentionCount))},className:`w-16`,"aria-label":n(`backup.backupEntriesTable.retentionFor`,`Retention for {{value1}}`,{value1:e.label||e.id})})}function Dt({row:e,onEdit:t}){let{t:n}=G(),r=s(),i=R(),o=De({onSuccess:()=>{r.invalidateQueries({queryKey:yt})}}),u=_e({onMutate:()=>{r.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{r.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),r.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),r.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})}}),f=()=>{e.locationIds.length!==0&&u.mutate({destinations:[...e.locationIds],...e.dataSources&&e.dataSources.length>0?{locations:[...e.dataSources]}:{},label:e.label,retentionCount:e.retentionCount,databases:[...X(e.databases)]})},m=async()=>{await i({title:n(`backup.backupEntriesTable.deleteBackupEntry`,`Delete backup entry?`),message:n(`backup.backupEntriesTable.willStopRunningExistingArchives`,`"{{value1}}" will stop running. Existing archives are kept.`,{value1:e.label||e.id}),confirmLabel:n(`common.delete`,`Delete`),variant:`warning`})&&o.mutate({id:e.id})};return a(`span`,{className:`flex items-center justify-end gap-1.5`,children:[a(H,{size:`sm`,type:`button`,onClick:f,disabled:u.isPending||e.locationIds.length===0,title:n(`backup.backupEntriesTable.runThisEntryNow`,`Run this entry now`),children:[u.isPending?c(k,{className:`h-3 w-3 animate-spin`}):c(l,{className:`h-3 w-3`}),n(`backup.backupEntriesTable.runNow`,`Run now`)]}),c(V,{variant:`ghost`,size:`sm`,icon:d,"aria-label":n(`backup.backupEntriesTable.edit`,`Edit {{value1}}`,{value1:e.label||e.id}),onClick:t}),c(V,{variant:`ghost`,size:`sm`,icon:p,"aria-label":n(`backup.backupEntriesTable.delete`,`Delete {{value1}}`,{value1:e.label||e.id}),disabled:o.isPending,onClick:()=>{m()}})]})}function Ot({row:e,destById:t,onOpenRestoreWizard:n}){let{t:r}=G();return a(`div`,{className:`space-y-4 rounded-lg border border-border bg-background/30 px-4 py-3`,children:[c(`p`,{className:`text-[11px] font-medium text-foreground-subtle`,children:r(`backup.backupEntriesTable.archivesFor`,{name:e.label||e.id})}),e.locationIds.length===0&&c(`p`,{className:`text-xs italic text-foreground-subtle`,children:r(`backup.backupEntriesTable.thisEntryHasNoLocations`,`This entry has no locations selected.`)}),e.locationIds.map(e=>a(`div`,{className:`space-y-1.5`,children:[c(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:t.get(e)?.displayName??e}),c(gt,{destinationId:e,restoreSupported:t.get(e)?.restoreSupported??!0,...n?{onOpenRestoreWizard:n}:{}})]},e))]})}function kt({selected:e,onChange:t,disabled:n=!1,testId:r=`backup-databases`}){let{t:i}=G(),o=oe().data,s=e.size>0&&dt(Y(e)),l=e.size===0?`Pick at least one.`:s?`Snapshots only: configuration and files are not part of this backup.`:null;return c(U,{label:i(`backup.backupDatabasePicker.whatToBackUp`,`What to back up`),required:!0,...l===null?{}:{description:l},children:c(`div`,{className:`divide-y divide-border rounded border border-border bg-background`,"data-testid":r,children:nt.map(i=>{let s=ct(i,o),l=n||lt(i,o,e);return a(`label`,{className:`flex items-start gap-2 px-3 py-2 text-xs ${l?`opacity-60`:`cursor-pointer hover:bg-primary/5`}`,children:[c(le,{checked:e.has(i),disabled:l,onChange:()=>t(ut(e,i)),"data-testid":`${r}-${i}`}),a(`span`,{className:`min-w-0 flex-1`,children:[c(`span`,{className:`flex flex-wrap items-center gap-1.5 text-foreground`,children:it(i)}),c(`span`,{className:`block text-[11px] text-foreground-subtle`,children:s===`absent`?rt():ot(i)})]})]},i)})})})}e();function At({onClose:e}){let{t}=G(),n=s(),[i,o]=r(new Set(J)),u=_e({onMutate:()=>{n.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{n.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),n.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),n.invalidateQueries({queryKey:[[`backup`,`listRuns`]]}),e()}});return c(me,{open:!0,onOpenChange:t=>!t&&e(),children:a(Ce,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(Pe,{children:[c(Ee,{children:t(`backup.backupNowDialog.backUpNow`,`Back up now`)}),c(`p`,{className:`text-xs text-foreground-subtle`,children:t(`backup.backupNowDialog.runsOnceAndWritesThe`,`Runs once and writes the archive to every enabled backup location.`)})]}),c(I,{children:a(`div`,{className:`p-4`,children:[c(kt,{selected:i,onChange:o,disabled:u.isPending,testId:`backup-now-databases`}),u.error&&c(`p`,{role:`alert`,className:`pt-2 text-xs text-danger`,children:u.error.message})]})}),a(je,{children:[c(H,{variant:`outline`,size:`sm`,onClick:e,children:t(`common.cancel`,`Cancel`)}),a(H,{size:`sm`,onClick:()=>{i.size!==0&&u.mutate(ft(i))},disabled:i.size===0||u.isPending,"data-testid":`backup-now-run`,children:[u.isPending?c(k,{className:`h-3.5 w-3.5 animate-spin`}):c(l,{className:`h-3.5 w-3.5`}),t(`backup.backupNowDialog.backUpNow`,`Back up now`)]})]})]})})}e();function jt(e){return e===null?`—`:new Date(e).toLocaleString()}function Mt(e){let t=new Blob([`${e.secretKey}\n`],{type:`text/plain`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`camstack-backup-key-${e.keyId}.txt`,r.click(),URL.revokeObjectURL(n)}function Nt({revealed:e,onDone:t}){let{t:n}=G(),[i,o]=r(!1),[s,l]=r(!1);return c(me,{open:!0,onOpenChange:e=>!e&&i&&t(),children:a(Ce,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`border-danger/40`,"aria-labelledby":`backup-key-title`,children:[c(Pe,{children:c(Ee,{id:`backup-key-title`,children:n(`backup.encryptionCard.yourKey`,{keyId:e.keyId})})}),a(I,{className:`space-y-3`,children:[a(`p`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 p-2 text-xs text-foreground`,children:[c(h,{className:`mt-0.5 h-4 w-4 shrink-0 text-danger`}),c(`span`,{children:n(`backup.backupEncryptionCard.thisKeyIsShownOnly`,`This key is shown only once. CamStack does not keep it — not the hub, not its database, not its backups. Without it, an encrypted backup cannot be restored by anyone, including you. Store it in a password manager or print it, away from this server.`)})]}),c(`div`,{className:`break-all rounded-md border border-border bg-background p-2 font-mono text-xs text-foreground select-all`,children:e.secretKey}),a(`div`,{className:`flex flex-wrap gap-2`,children:[a(H,{size:`sm`,variant:`outline`,onClick:()=>{navigator.clipboard?.writeText(e.secretKey).then(()=>l(!0))},children:[c(_,{className:`mr-1 h-3.5 w-3.5`}),s?n(`backup.backupEncryptionCard.copied`,`Copied`):n(`common.copy`,`Copy`)]}),a(H,{size:`sm`,variant:`outline`,onClick:()=>Mt(e),children:[c(f,{className:`mr-1 h-3.5 w-3.5`}),n(`backup.backupEncryptionCard.downloadAsFile`,`Download as file`)]})]}),a(`label`,{className:`flex items-center gap-2 text-xs text-foreground`,children:[c(`input`,{type:`checkbox`,checked:i,onChange:e=>o(e.target.checked),className:`accent-primary`}),n(`backup.backupEncryptionCard.iHaveStoredThisKey`,`I have stored this key somewhere safe, off this server.`)]})]}),c(je,{children:c(H,{size:`sm`,disabled:!i,onClick:t,children:n(`backup.backupEncryptionCard.iHaveStoredIt`,`I have stored it`)})})]})})}function Pt(){let{t:e}=G(),t=de(),n=ae(),i=ce(),s=R(),[l,u]=r(null),[d,f]=r(null),p=t.data?.enabled??!1,m=t.data?.active??null,h=(t.data?.keys??[]).filter(e=>e.retiredAt!==null),g=async()=>{if(await s({title:p?e(`backup.backupEncryptionCard.replaceTheBackupKey`,`Replace the backup key`):e(`backup.backupEncryptionCard.encryptBackups`,`Encrypt backups`),message:p?e(`backup.backupEncryptionCard.aNewKeyIsGenerated`,`A new key is generated and shown once; new backups are encrypted to it. Older backups keep needing the key they were made with — keep that one too.`):e(`backup.backupEncryptionCard.aBackupKeyIsGenerated`,`A backup key is generated and shown once. Every new backup is encrypted to it, and restoring one will ask for it. Existing backups stay as they are.`),confirmLabel:p?e(`backup.backupEncryptionCard.generateANewKey`,`Generate a new key`):e(`backup.backupEncryptionCard.generateTheKey`,`Generate the key`),variant:`warning`})){f(null);try{let e=await n.mutateAsync({});u({keyId:e.keyId,secretKey:e.secretKey})}catch(e){f(e instanceof Error?e.message:String(e))}}},_=async()=>{if(await s({title:e(`backup.backupEncryptionCard.turnBackupEncryptionOff`,`Turn backup encryption off`),message:e(`backup.backupEncryptionCard.newBackupsWillBeWritten`,`New backups will be written unencrypted. Existing encrypted backups still need their key to be restored.`),confirmLabel:e(`backup.backupEncryptionCard.turnOff`,`Turn off`),variant:`danger`})){f(null);try{await i.mutateAsync({}),t.refetch()}catch(e){f(e instanceof Error?e.message:String(e))}}};return a(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-4`,children:[a(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[a(`div`,{className:`flex items-center gap-2`,children:[p?c(A,{className:`h-4 w-4 text-success`}):c(T,{className:`h-4 w-4 text-foreground-subtle`}),c(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`backup.backupEncryptionCard.encryption`,`Encryption`)}),c(`span`,{className:`text-xs text-foreground-subtle`,children:p&&m!==null?e(`backup.backupEncryptionCard.onKeySince`,`On — key {{keyId}}, since {{value2}}`,{keyId:m.keyId,value2:jt(m.createdAt)}):e(`backup.backupEncryptionCard.offBackupsAreNotEncrypted`,`Off — backups are not encrypted`)})]}),c(`div`,{className:`flex gap-2`,children:p?a(o,{children:[c(H,{size:`sm`,variant:`outline`,disabled:n.isPending,onClick:()=>void g(),children:e(`backup.backupEncryptionCard.replaceKey`,`Replace key`)}),c(H,{size:`sm`,variant:`outline`,disabled:i.isPending,onClick:()=>void _(),children:e(`backup.backupEncryptionCard.turnOff`,`Turn off`)})]}):c(H,{size:`sm`,disabled:n.isPending,onClick:()=>void g(),children:e(`backup.backupEncryptionCard.enableEncryption`,`Enable encryption`)})})]}),c(`p`,{className:`text-xs text-foreground-subtle`,children:e(`backup.backupEncryptionCard.archivesAreEncryptedOnThis`,`Archives are encrypted on this server before they reach any destination. The server keeps only a public key, so it can encrypt scheduled backups but cannot decrypt them — only your backup key can. Covers the database snapshot, config.yaml, addon data (HomeKit pairing, Matter fabric, Tailscale state) and TLS.`)}),h.length>0&&a(`div`,{className:`text-xs`,children:[c(`p`,{className:`text-foreground-subtle`,children:e(`backup.backupEncryptionCard.olderKeysBackupsMadeWith`,`Older keys (backups made with them still need them):`)}),c(`ul`,{className:`font-mono text-foreground`,children:h.map(e=>a(`li`,{children:[e.keyId,` · `,jt(e.createdAt),` → `,jt(e.retiredAt)]},e.keyId))})]}),d!==null&&c(`p`,{className:`text-xs text-danger`,children:d}),l!==null&&c(Nt,{revealed:l,onDone:()=>{u(null),t.refetch()}})]})}e();var Ft=[{id:`manual`,labelKey:`backup.cronEditor.presetManual`,cron:``},{id:`hourly`,labelKey:`backup.cronEditor.presetHourly`,cron:`0 * * * *`,descriptionKey:`backup.cronEditor.presetHourlyDesc`},{id:`every-3h`,labelKey:`backup.cronEditor.preset3h`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,labelKey:`backup.cronEditor.preset6h`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,labelKey:`backup.cronEditor.presetDaily`,cron:`0 3 * * *`,descriptionKey:`backup.cronEditor.presetDailyDesc`},{id:`weekly-sun`,labelKey:`backup.cronEditor.presetWeekly`,cron:`0 3 * * 0`,descriptionKey:`backup.cronEditor.presetWeeklyDesc`}];function It(e){let t=e.trim();for(let e of Ft)if(e.cron===t)return e.id;return`custom`}function Lt({value:e,onChange:n,previewCount:i=5,disabled:o=!1}){let{t:s}=G(),l=It(e),[u,d]=r(l===`custom`);t(()=>{l!==`custom`&&d(!1)},[l]);let f=Bt(e,250),p=te({cron:f,count:i},{enabled:f.trim().length>0}),m=p.data??null,h=e=>{d(!1),n(e.cron)},g=u||l===`custom`;return a(`div`,{className:`space-y-3`,children:[a(`div`,{className:`space-y-1`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:s(`backup.cronEditor.schedulePreset`,`Schedule preset`)}),a(`div`,{className:`flex flex-wrap gap-1.5`,children:[Ft.map(e=>c(`button`,{type:`button`,onClick:()=>h(e),disabled:o,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!u&&l===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.descriptionKey===void 0?e.description??s(e.labelKey):s(e.descriptionKey),children:s(e.labelKey)},e.id)),c(`button`,{type:`button`,onClick:()=>{d(!0),e.trim().length===0&&n(`0 3 * * *`)},disabled:o,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(g?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:s(`backup.cronEditor.custom`,`Custom…`)})]})]}),g&&a(`div`,{className:`space-y-1`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:s(`backup.cronEditor.cronExpression5FieldPosix`,`Cron expression (5-field POSIX)`)}),c(`input`,{type:`text`,value:e,onChange:e=>n(e.target.value),disabled:o,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),a(`p`,{className:`text-[10px] text-foreground-subtle`,children:[s(`backup.cronEditor.format`,`Format:`),` `,c(He,{i18nKey:`backup.cronEditor.formatLine`,components:{code:c(`span`,{className:`font-mono`})}})]})]}),c(Rt,{cron:f,preview:m,loading:p.isFetching})]})}function Rt({cron:e,preview:t,loading:n}){let{t:r}=G();return n&&t===null?a(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[c(k,{className:`h-3 w-3 animate-spin`}),r(`backup.cronEditor.validating`,`Validating…`)]}):t===null?null:t.ok?t.nextRuns.length===0?c(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:r(`backup.cronEditor.noFutureRunsMatchThis`,`No future runs match this expression.`)}):a(`div`,{className:`space-y-1`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:r(`backup.cronEditor.nextRuns`,`Next runs`)}),c(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>a(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[c(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),c(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:zt(e)})]},`${e}-${t}`))})]}):c(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??r(`backup.cronEditor.invalidCronExpression`,`Invalid cron expression`)})}function zt(e){let t=e-Date.now();if(t<=0)return W.t(`helpers.relativeTime.now`);let n=Math.floor(t/1e3);if(n<60)return W.t(`helpers.relativeTime.inSeconds`,{count:n});let r=Math.floor(n/60);if(r<60)return W.t(`helpers.relativeTime.inMinutes`,{count:r});let i=Math.floor(r/60);if(i<24)return W.t(`helpers.relativeTime.inHours`,{count:i});let a=Math.floor(i/24);return W.t(`helpers.relativeTime.inDays`,{count:a})}function Bt(e,i){let[a,o]=r(e),s=n(()=>e,[e]);return t(()=>{let e=setTimeout(()=>o(s),i);return()=>clearTimeout(e)},[s,i]),a}e();var Vt=[[`backup`,`listSchedules`]];function Ht({entry:e,onClose:t,onSaved:i}){let{t:o}=G(),l=s(),u=B(),d=u.data??[],[f,p]=r(e?.label??``),[m,h]=r(e?.cron??`0 3 * * *`),[g,_]=r(e?.enabled??!0),[v,y]=r(String(e?.retentionCount??7)),[b,x]=r(new Set(e?.locationIds??[])),[S,C]=r(new Set(e===null?J:X(e.databases))),w=ye({onSuccess:()=>{l.invalidateQueries({queryKey:Vt}),i()}}),T=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},E=Number.parseInt(v,10),D=n(()=>f.trim().length>0&&b.size>0&&S.size>0&&!Number.isNaN(E)&&E>=1&&E<=1e3,[f,b,S,E]),O=()=>{D&&w.mutate({...e?{id:e.id}:{},label:f.trim(),cron:m.trim(),enabled:g,locationIds:Array.from(b),retentionCount:E,databases:[...st(S)]})},A=w.error instanceof Error?w.error.message:null;return c(Se,{open:!0,onClose:t,title:e?o(`backup.backupEntryModal.editBackupEntry`,`Edit backup entry`):o(`backup.backupEntryModal.newBackupEntry`,`New backup entry`),icon:M,error:A,width:`lg`,testId:`backup-entry-form`,footer:a(H,{size:`sm`,type:`button`,onClick:O,disabled:!D||w.isPending,children:[w.isPending?c(k,{className:`h-3.5 w-3.5 animate-spin`}):null,e?o(`common.save`,`Save`):o(`backup.backupEntryModal.createEntry`,`Create entry`)]}),children:a(`div`,{className:`space-y-4`,children:[c(U,{label:o(`backup.backupEntryModal.name`,`Name`),required:!0,children:c(ue,{value:f,onChange:e=>p(e.target.value),placeholder:o(`backup.backupEntryModal.nightlyOffsite`,`Nightly offsite`),autoFocus:!0,"data-testid":`backup-entry-name`})}),a(U,{label:o(`backup.backupEntryModal.locationsSelected`,`Locations ({{value1}} selected)`,{value1:String(b.size)}),required:!0,children:[u.isLoading&&a(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[c(k,{className:`h-3.5 w-3.5 animate-spin`}),o(`backup.backupEntryModal.loadingLocations`,`Loading locations…`)]}),!u.isLoading&&d.length===0&&c(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:o(`backup.backupEntryModal.noBackupsStorageLocationsConfigured`,"No `backups` storage locations configured. Add one in Settings → Storage first.")}),d.length>0&&c(`div`,{className:`max-h-52 divide-y divide-border overflow-y-auto rounded border border-border bg-background`,children:d.map(e=>a(`label`,{className:`flex cursor-pointer items-center justify-between px-3 py-2 text-xs hover:bg-primary/5`,children:[a(`div`,{className:`flex items-center gap-2`,children:[c(`input`,{type:`checkbox`,checked:b.has(e.id),onChange:()=>T(e.id),className:`accent-primary`}),c(`span`,{className:`text-foreground`,children:e.displayName})]}),a(`div`,{className:`flex items-center gap-1.5`,children:[c(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e.kind}),c(`span`,{className:`font-mono text-[10px] text-foreground-subtle`,children:e.id})]})]},e.id))})]}),c(kt,{selected:S,onChange:C,disabled:w.isPending,testId:`backup-entry-databases`}),a(`div`,{className:`grid grid-cols-2 gap-3`,children:[c(U,{label:o(`backup.backupEntryModal.retentionArchivesKept`,`Retention (archives kept)`),required:!0,children:c(ue,{type:`number`,min:1,max:1e3,value:v,onChange:e=>y(e.target.value),"data-testid":`backup-entry-retention`})}),c(U,{label:o(`backup.backupEntryModal.enabled`,`Enabled`),description:o(`backup.backupEntryModal.runOnScheduleWhenChecked`,`Run on schedule when checked.`),children:a(`label`,{className:`inline-flex cursor-pointer items-center gap-2 py-1.5 text-xs text-foreground`,children:[c(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`accent-primary`,"data-testid":`backup-entry-enabled`}),c(`span`,{children:o(`backup.backupEntryModal.runOnSchedule`,`Run on schedule`)})]})})]}),c(U,{label:o(`backup.backupEntryModal.schedule`,`Schedule`),children:c(Lt,{value:m,onChange:h,disabled:w.isPending})})]})})}e();var Ut=2e3,Wt=5e3;function Q(e){return e.state===`queued`||e.state===`running`}function Gt(e){if(e.state===`queued`)return{title:W.t(`backup.backupRunsPanel.cancelQueuedBackupRun`,`Cancel queued backup run?`),message:W.t(`backup.backupRunsPanel.thisRunHasNotStarted`,`This run has not started. Cancelling removes it from the queue — nothing has been written, nothing is deleted.`),confirmLabel:W.t(`backup.backupRunsPanel.cancelRun`,`Cancel run`),variant:`warning`};let t=e.completedDestinationIds.length,n=t>0?`${t===1?`The 1 destination`:`The ${t} destinations`} that already completed KEEP${t===1?`S`:``} the archive.`:`No destination has completed yet, so nothing will be kept.`;return{title:W.t(`backup.backupRunsPanel.stopThisBackupRun`,`Stop this backup run?`),message:W.t(`backup.backupRunsPanel.theHalfWrittenStagingArchive`,`The half-written staging archive is deleted and the destination currently uploading discards its partial copy. {{keptSentence}}`,{keptSentence:n}),confirmLabel:W.t(`backup.backupRunsPanel.stopRun`,`Stop run`),variant:`danger`}}function Kt(){let e=R(),[t,n]=r(null),a=he(void 0,{refetchInterval:e=>(e.state.data??[]).some(Q)?Ut:Wt}),o=Oe({onSettled:()=>{n(null),a.refetch()}}),s=i(async t=>{await e(Gt(t))&&(n(t.id),o.mutate({runId:t.id}))},[e,o]);return c(qt,{queryState:a.isError?`error`:a.data===void 0?`pending`:`ready`,runs:a.data??[],cancelingId:t,onCancelRequest:e=>{s(e)},now:Date.now()})}function qt({queryState:e,runs:t,cancelingId:n,onCancelRequest:r,now:i}){let{t:o}=G(),s=e===`ready`&&t.some(Q),l=t.filter(e=>e.state===`running`),u=t.filter(e=>e.state===`queued`),d=t.filter(e=>!Q(e)),f=[...l,...u,...d];return a(`section`,{className:`rounded-lg border border-border bg-surface`,children:[a(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border`,children:[c(`h2`,{className:`text-xs font-semibold text-foreground`,children:o(`backup.backupRunsPanel.runs`,`Runs`)}),s&&a(`span`,{className:`inline-flex items-center gap-1 text-[10px] font-medium text-primary`,title:o(`backup.backupRunsPanel.aBackupRunIsIn`,`A backup run is in progress`),children:[c(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary animate-pulse`}),o(`backup.runsPanel.live`)]}),c(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:o(`backup.backupRunsPanel.oneRunExecutesAtA`,`One run executes at a time — queued runs wait in line.`)})]}),e===`pending`&&c(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle animate-pulse`,children:o(`backup.backupRunsPanel.checkingForBackupRuns`,`Checking for backup runs…`)}),e===`error`&&c(`div`,{className:`px-3 py-2.5 text-xs text-danger`,children:o(`backup.backupRunsPanel.couldNotReadBackupRuns`,`Could not read backup runs — the orchestrator did not answer.`)}),e===`ready`&&t.length===0&&c(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle italic`,children:o(`backup.backupRunsPanel.noBackupRunsYetRuns`,`No backup runs yet. Runs appear here the moment one starts — manual or scheduled.`)}),e===`ready`&&t.length>0&&c(`div`,{className:`overflow-x-auto`,children:a(`table`,{className:`w-full text-xs min-w-[720px]`,children:[c(`thead`,{children:a(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.run`,`Run`)}),c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.state`,`State`)}),c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.progress`,`Progress`)}),c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.destinations`,`Destinations`)}),c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.timing`,`Timing`)}),c(`th`,{className:`text-right px-3 py-1.5 font-medium w-28`,children:o(`backup.backupRunsPanel.actions`,`Actions`)})]})}),c(`tbody`,{children:f.map(e=>c(Jt,{run:e,canceling:n===e.id,onCancelRequest:r,now:i},e.id))})]})})]})}function Jt({run:e,canceling:t,onCancelRequest:n,now:r}){let{t:i}=G(),o=Q(e);return a(`tr`,{className:`border-t border-border hover:bg-primary/5 align-top`,children:[c(`td`,{className:`px-3 py-2`,children:c(`div`,{className:`text-foreground`,title:e.id,children:e.label??c(`span`,{className:`text-foreground-subtle italic`,children:i(`backup.runsPanel.manual`)})})}),a(`td`,{className:`px-3 py-2`,children:[c(Yt,{run:e}),e.state===`failed`&&e.error!==void 0&&c(`div`,{className:`mt-1 text-[10px] text-danger max-w-56 truncate`,title:e.error,children:e.error})]}),c(`td`,{className:`px-3 py-2`,children:c(Xt,{run:e})}),c(`td`,{className:`px-3 py-2`,children:c(Zt,{run:e})}),c(`td`,{className:`px-3 py-2 text-foreground-subtle tabular-nums`,children:c(Qt,{run:e,now:r})}),c(`td`,{className:`px-3 py-2`,children:c(`div`,{className:`flex justify-end`,children:o&&a(`button`,{onClick:()=>n(e),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:e.state===`queued`?i(`backup.backupRunsPanel.removeThisRunFromThe`,`Remove this run from the queue before it starts`):i(`backup.backupRunsPanel.stopThisRunTheHalf`,`Stop this run — the half-written archive is discarded`),children:[t?c(k,{className:`h-3 w-3 animate-spin`}):c(m,{className:`h-3 w-3`}),e.state===`queued`?i(`common.cancel`,`Cancel`):i(`backup.backupRunsPanel.stop`,`Stop`)]})})})]})}function Yt({run:e}){let{t}=G();switch(e.state){case`queued`:return a(`span`,{className:`inline-flex items-center gap-1 rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:[c(O,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.queued`,`Queued`)]});case`running`:return a(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`,children:[c(k,{className:`h-3 w-3 animate-spin`}),e.phase===`uploading`?t(`backup.backupRunsPanel.uploading`,`Uploading`):t(`backup.backupRunsPanel.buildingArchive`,`Building archive`)]});case`succeeded`:return a(`span`,{className:`inline-flex items-center gap-1 rounded bg-success/10 px-1.5 py-0.5 text-[10px] font-medium text-success`,children:[c(D,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.succeeded`,`Succeeded`)]});case`failed`:return a(`span`,{className:`inline-flex items-center gap-1 rounded bg-danger/10 px-1.5 py-0.5 text-[10px] font-medium text-danger`,children:[c(C,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.failed`,`Failed`)]});case`cancelled`:return a(`span`,{className:`inline-flex items-center gap-1 rounded bg-amber-500/10 px-1.5 py-0.5 text-[10px] font-medium text-amber-700 dark:text-amber-300`,title:t(`backup.backupRunsPanel.stoppedBeforeCompletingEveryDestination`,`Stopped before completing every destination — not a success`),children:[c(P,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.stopped`,`Stopped`)]})}}function Xt({run:e}){let{t}=G();if(e.state===`queued`)return c(`span`,{className:`text-foreground-subtle`,children:e.queuePosition===void 0?c(`span`,{className:`italic`,children:t(`backup.backupRunsPanel.waitingItsTurn`,`waiting its turn`)}):a(`span`,{className:`inline-flex items-center gap-1`,children:[c(`span`,{className:e.queuePosition===1?`rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`:`rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium`,children:$t(e.queuePosition)}),t(`backup.backupRunsPanel.inLine`,`in line`)]})});if(e.state===`running`&&e.phase===`building`)return a(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[c(F,{className:`h-3 w-3 text-primary`}),c(`span`,{className:`tabular-nums font-medium animate-pulse`,children:K(e.stagedBytes)}),c(`span`,{className:`text-foreground-subtle`,children:t(`backup.backupRunsPanel.stagedSoFar`,`staged so far`)})]});if(e.state===`running`){let n=e.archiveSizeBytes;return a(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[c(N,{className:`h-3 w-3 text-primary`}),a(`span`,{className:`tabular-nums font-medium`,children:[K(e.uploadedBytes),n===void 0?``:` / ${K(n)}`]}),c(`span`,{className:`text-foreground-subtle`,children:t(`backup.backupRunsPanel.toCurrentDestination`,`to current destination`)})]})}let n=e.archiveSizeBytes??(e.stagedBytes>0?e.stagedBytes:void 0);return n===void 0?c(`span`,{className:`text-foreground-subtle italic`,children:`—`}):c(`span`,{className:`tabular-nums text-foreground`,children:t(`backup.runsPanel.archiveSize`,{size:K(n)})})}function Zt({run:e}){let{t}=G(),n=e.destinationIds.length,r=e.completedDestinationIds.length,i=e.failedDestinationIds.length;return n===0?c(`span`,{className:`text-foreground-subtle italic`,children:t(`backup.backupRunsPanel.notResolvedYet`,`not resolved yet`)}):a(`div`,{className:`flex flex-col gap-0.5`,children:[c(`span`,{className:`text-foreground-subtle`,title:e.destinationIds.join(`, `),children:t(`backup.runsPanel.targets`,{count:n})}),a(`span`,{className:`inline-flex items-center gap-2 text-[10px]`,children:[r>0&&c(`span`,{className:`text-success`,title:t(`backup.backupRunsPanel.keptTheirArchive`,`Kept their archive: {{value1}}`,{value1:e.completedDestinationIds.join(`, `)}),children:t(`backup.runsPanel.completed`,{count:r})}),i>0&&c(`span`,{className:`text-danger`,title:t(`backup.backupRunsPanel.failed2`,`Failed: {{value1}}`,{value1:e.failedDestinationIds.join(`, `)}),children:t(`backup.runsPanel.failedCount`,{count:i})})]})]})}function Qt({run:e,now:t}){let{t:n}=G();return e.state===`queued`?c(`span`,{children:n(`backup.runsPanel.queuedAgo`,{elapsed:en(t-e.requestedAt)})}):e.startedAt===void 0?c(`span`,{children:`—`}):e.finishedAt===void 0?c(`span`,{children:n(`backup.runsPanel.runningFor`,{elapsed:en(t-e.startedAt)})}):a(`div`,{className:`flex flex-col gap-0.5`,children:[c(`span`,{children:tn(e.finishedAt)}),c(`span`,{className:`text-[10px]`,children:n(`backup.runsPanel.took`,{elapsed:en(e.finishedAt-e.startedAt)})})]})}function $t(e){if(e<=1)return`next`;let t=e%100;if(t>=11&&t<=13)return`${e}th`;switch(e%10){case 1:return`${e}st`;case 2:return`${e}nd`;case 3:return`${e}rd`;default:return`${e}th`}}function en(e){let t=Math.max(0,Math.floor(e/1e3));if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m ${String(t%60).padStart(2,`0`)}s`:`${Math.floor(n/60)}h ${String(n%60).padStart(2,`0`)}m`}function tn(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}e();var nn=[[`backup`,`list`]];function rn({initialDestinationId:e,initialArchiveId:i,onClose:o,onScheduled:l}){let{t:u}=G(),d=s(),[f,p]=r(e&&i?2:1),[m,h]=r(e),[g,_]=r(i),[v,b]=r(new Set),[S,C]=r(``),{data:w}=B(),T=w??[],{data:E,isLoading:D}=ie({destinationId:m??``},{enabled:!!m}),O=E??[];t(()=>{if(m!==void 0)return;let e=T.filter(e=>e.restoreSupported);e.length===1&&h(e[0].id)},[m,T]);let{data:A}=pe({destinationId:m??``,backupId:g??``},{enabled:!!m&&!!g}),M=n(()=>A?.locations??[],[A]);t(()=>{M.length!==0&&b(e=>e.size===0?new Set(M):e)},[M]);let N=ve({onSuccess:()=>{d.invalidateQueries({queryKey:nn}),l(),o()}}),P=e=>{b(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},F=O.find(e=>e.id===g),ee=F?.encryption!==void 0,L=pt(F?.databases,A?.sqliteSnapshots),R=dt(L),te=!!m&&!!g,z=R||v.size>0,ne=te&&z&&!N.isPending&&(!ee||S.trim().length>0),re=()=>{!m||!g||N.mutate({destinationId:m,backupId:g,...R?{}:{locations:[...v]},...ee?{backupSecretKey:S.trim()}:{}})};return c(me,{open:!0,onOpenChange:e=>!e&&o(),children:a(Ce,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(Pe,{children:[c(Ee,{children:u(`backup.restoreWizard.restoreBackup`,`Restore Backup`)}),c(`p`,{className:`text-xs text-foreground-subtle`,children:u(`backup.restoreWizard.stepOf`,{step:f,name:f===1?u(`backup.restoreWizard.pickSource`,`pick source`):f===2?u(`backup.restoreWizard.pickLocations`,`pick locations`):u(`backup.restoreWizard.confirmStep`)})})]}),a(I,{children:[f===1&&c(an,{destinations:T,destinationId:m,onPickDestination:e=>{h(e),_(void 0),b(new Set)},archives:O,archivesLoading:D,archiveId:g,onPickArchive:_}),f===2&&c(on,{locations:M,picked:v,onToggle:P,databases:L,snapshotsOnly:R}),f===3&&c(sn,{destinationName:T.find(e=>e.id===m)?.displayName??m??``,archive:F,picked:[...v],databases:L,snapshotsOnly:R}),f===3&&F?.encryption!==void 0&&c(cn,{keyId:F.encryption.keyId,value:S,onChange:C}),f===3&&N.error&&c(`p`,{role:`alert`,className:`px-4 pb-2 text-xs text-danger`,children:N.error.message})]}),a(je,{className:`justify-between`,children:[c(`div`,{children:f>1&&a(H,{variant:`outline`,size:`sm`,onClick:()=>p(e=>e===3?2:1),children:[c(x,{className:`h-3 w-3`}),u(`common.back`,`Back`)]})}),a(`div`,{className:`flex items-center gap-2`,children:[c(H,{variant:`outline`,size:`sm`,onClick:o,children:u(`common.cancel`,`Cancel`)}),f<3?a(H,{size:`sm`,disabled:f===1&&!te||f===2&&!z,onClick:()=>p(e=>e===1?2:3),children:[u(`common.next`,`Next`),c(y,{className:`h-3 w-3`})]}):a(H,{size:`sm`,onClick:re,disabled:!ne,children:[N.isPending?c(k,{className:`h-3.5 w-3.5 animate-spin`}):c(j,{className:`h-3.5 w-3.5`}),u(`backup.restoreWizard.scheduleRestore`,`Schedule Restore`)]})]})]})]})})}function an({destinations:e,destinationId:t,onPickDestination:n,archives:r,archivesLoading:i,archiveId:o,onPickArchive:s}){let{t:l}=G(),u=e.filter(e=>e.restoreSupported);return a(`div`,{className:`p-4 space-y-3`,children:[a(`div`,{className:`space-y-1.5`,children:[c(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:l(`backup.restoreWizard.destination`,`Destination`)}),c(re,{value:t??``,onChange:e=>n(e.target.value),options:[{value:``,label:l(`backup.restoreWizard.selectDestination`,`Select destination…`)},...u.map(e=>({value:e.id,label:`${e.displayName} (${e.kind})`}))]})]}),a(`div`,{className:`space-y-1.5`,children:[c(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:l(`backup.restoreWizard.archive`,`Archive`)}),!t&&c(`div`,{className:`text-xs text-foreground-subtle italic`,children:l(`backup.restoreWizard.pickADestinationFirst`,`Pick a destination first.`)}),t&&i&&c(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:l(`backup.restoreWizard.readingArchives`,`Reading archives…`)}),t&&!i&&r.length===0&&c(`div`,{className:`text-xs text-foreground-subtle italic`,children:l(`backup.restoreWizard.noArchivesAvailableAtThis`,`No archives available at this destination.`)}),t&&r.length>0&&c(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:r.map(e=>{let t=o===e.id;return a(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[a(`div`,{className:`flex items-center gap-2`,children:[c(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>s(e.id),className:`accent-primary`}),a(`div`,{children:[a(`div`,{className:`flex items-center gap-1 font-medium text-foreground`,children:[e.encryption!==void 0&&c(A,{className:`h-3 w-3 text-success`,"aria-label":l(`backup.restoreWizard.encryptedKey`,`encrypted (key {{keyId}})`,{keyId:e.encryption.keyId})}),e.label??e.id]}),c(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()}),c(`div`,{className:`pt-1`,children:c(Z,{databases:pt(e.databases,void 0)})})]})]}),c(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:K(e.sizeBytes)})]},e.id)})})]})]})}function on({locations:e,picked:t,onToggle:n,databases:r,snapshotsOnly:i}){let{t:o}=G();return i?a(`div`,{className:`space-y-3 p-4`,children:[a(`div`,{className:`space-y-1.5`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:o(`backup.restoreWizard.databasesInThisArchive`,`Databases in this archive`)}),c(Z,{databases:r})]}),c(`div`,{className:`rounded border border-info/30 bg-info/10 px-3 py-2 text-[11px] text-info`,children:o(`backup.restoreWizard.snapshotsOnlyRestoringThisArchive`,`Snapshots only: restoring this archive replaces just these databases. It does NOT touch configuration, addons, addon data or certificates.`)})]}):e.length===0?c(`div`,{className:`p-4`,children:c(`div`,{className:`text-xs text-foreground-subtle`,children:o(`backup.restoreWizard.loadingArchiveManifestIfThis`,`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`)})}):a(`div`,{className:`p-4 space-y-3`,children:[a(`div`,{className:`space-y-1.5`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:o(`backup.restoreWizard.databasesInThisArchive`,`Databases in this archive`)}),c(Z,{databases:r})]}),c(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-[11px] text-warning`,children:o(`backup.restoreWizard.selectedEntriesWillOverwriteLive`,`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`)}),a(`div`,{className:`space-y-1.5`,children:[c(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:o(`common.apply`,`Apply`)}),c(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>a(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[c(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>n(e),className:`accent-primary`}),c(`span`,{className:`font-mono text-foreground`,children:e}),c(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:un(e)})]},e))})]})]})}function sn({destinationName:e,archive:t,picked:n,databases:r,snapshotsOnly:i}){let{t:o}=G();return a(`div`,{className:`p-4 space-y-3 text-xs`,children:[c(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-warning`,children:o(`backup.restoreWizard.restoreIsAppliedAtNext`,`Restore is applied at next server boot. Active connections will drop when you restart.`)}),a(`dl`,{className:`space-y-1.5`,children:[c($,{term:`Destination`,value:e}),c($,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&c($,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${K(t.sizeBytes)}`}),a(`div`,{className:`flex justify-between gap-3`,children:[c(`dt`,{className:`text-foreground-subtle`,children:`Databases`}),c(`dd`,{className:`text-right`,children:c(Z,{databases:r})})]}),c($,{term:`Locations`,value:i?`none (configuration is not touched)`:n.length>0?n.join(`, `):`— (full archive)`})]})]})}function cn({keyId:e,value:t,onChange:n}){let{t:r}=G();return a(`div`,{className:`space-y-1.5 px-4 pb-3`,children:[c(`label`,{htmlFor:`restore-backup-key`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:r(`backup.restoreWizard.backupKey`,`Backup key`)}),c(`input`,{id:`restore-backup-key`,type:`password`,autoComplete:`off`,spellCheck:!1,value:t,onChange:e=>n(e.target.value),placeholder:r(`backup.restoreWizard.camstackBackupSecretV1`,`camstack-backup-secret-v1:…`),className:`w-full rounded border border-border bg-background px-2 py-1.5 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),c(`p`,{className:`text-[11px] text-foreground-subtle`,children:c(He,{i18nKey:`backup.restoreWizard.encryptedTo`,values:{keyId:e},components:{mono:c(`span`,{className:`font-mono`})}})})]})}function $({term:e,value:t}){return a(`div`,{className:`flex justify-between gap-3`,children:[c(`dt`,{className:`text-foreground-subtle`,children:e}),c(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var ln={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function un(e){return ln[e]??``}e();function dn(){let{t:e}=G(),n=R(),i=Me(),{state:o,openNew:s,openEdit:u,close:d}=Ae({editKey:`edit`,newKey:`new`}),f=ze(),p=f.data??[],[m,h]=r(null),[g,_]=r(!1),[v,y]=r(!1),[b,x]=r(!1),S=o.mode===`edit`?p.find(e=>e.id===o.id)??null:null;t(()=>{o.mode===`edit`&&!f.isLoading&&S===null&&d()},[o.mode,f.isLoading,S,d]);let C=o.mode===`new`||o.mode===`edit`&&S!==null,w=async()=>{await n({title:e(`system.backup.restartServerNow`,`Restart server now?`),message:e(`system.backup.activeConnectionsWillDropAnd`,`Active connections will drop and the apply-backup hook will run before boot.`),confirmLabel:e(`system.backup.restart`,`Restart`),variant:`warning`})&&i.mutate({confirm:!0})};return a(Ge,{embedded:!0,children:[a(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,"data-testid":`backup-actions`,children:[a(H,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>x(!0),"data-testid":`backup-now`,children:[c(l,{className:`h-3.5 w-3.5`}),e(`system.backup.backUpNow`,`Back up now`)]}),a(H,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>_(!0),children:[c(j,{className:`h-3.5 w-3.5`}),e(`system.backup.restore`,`Restore…`)]}),a(H,{size:`sm`,type:`button`,onClick:s,"data-testid":`backup-new-entry`,children:[c(E,{className:`h-3.5 w-3.5`}),e(`system.backup.newEntry`,`New entry`)]})]}),v&&c(`div`,{className:`rounded-lg border border-warning/30 bg-warning/10 px-3 py-2.5 text-xs text-warning`,children:a(`div`,{className:`flex items-center justify-between gap-3`,children:[a(`div`,{className:`flex items-center gap-2`,children:[c(j,{className:`h-3.5 w-3.5`}),c(`span`,{children:e(`system.backup.restoreScheduledRestartTheServer`,`Restore scheduled. Restart the server to apply.`)})]}),a(H,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>{w()},disabled:i.isPending,children:[i.isPending?c(k,{className:`h-3.5 w-3.5 animate-spin`}):c(j,{className:`h-3.5 w-3.5`}),e(`system.backup.restartNow`,`Restart Now`)]})]})}),c(Pt,{}),c(Kt,{}),c(bt,{onEdit:e=>u(e.id),onOpenRestoreWizard:e=>h(e)}),C&&c(Ht,{entry:S,onClose:d,onSaved:d}),b&&c(At,{onClose:()=>x(!1)}),(m||g)&&c(rn,{...m?{initialDestinationId:m.destinationId,initialArchiveId:m.archiveId}:{},onClose:()=>{h(null),_(!1)},onScheduled:()=>y(!0)})]})}e();function fn(e){return Object.entries(e).map(([e,t])=>`${e} ${t}`).join(` · `)}function pn(e){return e.reduce((e,t)=>e+Object.values(t.stores).reduce((e,t)=>e+t,0),0)}function mn(){let{t:e}=G(),t=R(),n=fe(),[i,s]=r(null),[l,u]=r(null),d=async e=>{u(null);try{s(await n.mutateAsync({confirm:e}))}catch(e){u(e instanceof Error?e.message:String(e))}},f=async()=>{i===null||i.status!==`dry-run`||await t({title:e(`systemPage.deletedDevices.confirmTitle`,`Delete the data of deleted devices?`),message:i.devices.map(e=>`#${e.deviceId}: ${fn(e.stores)}`).join(`
2
+ `),confirmLabel:e(`systemPage.deletedDevices.confirmLabel`,`Delete`),variant:`danger`})&&await d(!0)},m=[{key:`device`,header:e(`systemPage.deletedDevices.device`,`Device`),render:e=>`#${e.deviceId}`},{key:`stores`,header:e(`systemPage.deletedDevices.stores`,`Data held`),nowrap:!1,render:e=>fn(e.stores)}];return a(`div`,{className:`space-y-4`,"data-testid":`deleted-devices-data`,children:[c(`p`,{className:`text-sm text-foreground-muted`,children:e(`systemPage.deletedDevices.intro`,`Data that still belongs to devices that were deleted before deletions were recorded: footage, events, history and per-addon settings. Scanning deletes nothing; deleting asks first and shows what goes.`)}),a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[a(H,{variant:`outline`,onClick:()=>void d(!1),disabled:n.isPending,"data-testid":`deleted-devices-scan`,children:[n.isPending?c(k,{className:`mr-2 h-4 w-4 animate-spin`}):c(w,{className:`mr-2 h-4 w-4`}),e(`systemPage.deletedDevices.scan`,`Scan`)]}),i?.status===`dry-run`&&i.devices.length>0?a(H,{variant:`danger`,onClick:()=>void f(),disabled:n.isPending,"data-testid":`deleted-devices-delete`,children:[c(p,{className:`mr-2 h-4 w-4`}),e(`systemPage.deletedDevices.delete`,`Delete the data of {{count}} devices…`,{count:i.devices.length})]}):null]}),l===null?null:c(`p`,{className:`text-sm text-danger`,children:l}),i?.status===`skipped`?c(`p`,{className:`text-sm text-warning`,"data-testid":`deleted-devices-skipped`,children:e(`systemPage.deletedDevices.skipped`,`Nothing was listed or deleted: the device list could not be trusted ({{reason}}). Try again.`,{reason:i.reason??``})}):null,i!==null&&i.status!==`skipped`?a(o,{children:[c(`p`,{className:`text-sm`,"data-testid":`deleted-devices-summary`,children:i.status===`cleaned`?e(`systemPage.deletedDevices.cleaned`,`Deleted {{rows}} items of {{count}} devices.`,{rows:pn(i.devices),count:i.devices.length}):e(`systemPage.deletedDevices.found`,`{{count}} deleted devices still hold {{rows}} items.`,{rows:pn(i.devices),count:i.devices.length})}),c(Te,{columns:m,rows:i.devices,rowKey:e=>e.deviceId,emptyMessage:e(`systemPage.deletedDevices.none`,`No data belongs to a deleted device.`)}),i.unreachable.length>0?c(`p`,{className:`text-xs text-foreground-muted`,children:e(`systemPage.deletedDevices.unreachable`,`Not asked (unreachable): {{names}}`,{names:i.unreachable.join(`, `)})}):null]}):null]})}var hn=`view`,gn=`kinds`,_n=`deleted-devices`;function vn(){let{t:e}=G(),[t,n]=Ue(),r=t.get(`view`)===`deleted-devices`?_n:gn;return a(`div`,{className:u,children:[a(`div`,{className:`mb-3 space-y-2`,children:[c(ne,{appearance:`pills`,value:r,onValueChange:e=>{n(t=>{let n=new URLSearchParams(t);return e===`kinds`?n.delete(hn):n.set(hn,e),n},{replace:!0})},children:a(ke,{className:`flex flex-wrap gap-1`,children:[c(L,{value:gn,children:e(`systemPage.data.viewKinds`,`Record kinds`)}),c(L,{value:_n,children:e(`systemPage.data.viewDeletedDevices`,`Deleted devices`)})]})}),r===`kinds`?c(`p`,{className:`text-xs text-foreground-muted`,children:e(`systemPage.data.recordsUnifiedIntro`,`Every declared record kind on this hub. Entry kinds can be added, edited and deleted; the rest are read-only. Secret fields are redacted.`)}):null]}),c(r===`kinds`?xe:mn,{})]})}var yn={entries:null,"deleted-devices":`deleted-devices`};function bn(){let{t:e}=G(),t=Ve(`/system/data`,{t:e,isAdmin:!0})??{icon:b,title:e(`system.data`,`Data`)},[n]=Ue(),r=yn[n.get(`tab`)??``];if(r!==void 0){let e=new URLSearchParams(n);return e.set(`tab`,`records`),r!==null&&e.set(`view`,r),c(Be,{replace:!0,to:{search:e.toString()}})}return c(We,{icon:t.icon,title:t.title,defaultSection:`storage`,sectionsLabel:`${t.title} sections`,sections:[{id:`storage`,label:e(`systemPage.data.storage`,`Storage`),content:c(tt,{})},{id:`records`,label:e(`systemPage.data.records`,`Records`),content:c(vn,{}),ownedParams:[`view`,`recordsOwner`,`recordsKind`,`entryNew`,`entryEdit`]},{id:`backup`,label:e(`systemPage.data.backup`,`Backup`),content:c(dn,{})}]})}export{bn as DataPage};
@@ -0,0 +1,2 @@
1
+ import{$ as e,B as t,G as n,J as r,L as i,S as a,a as o,b as s,o as c,q as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Br as f,Ci as p,Cr as m,D as h,En as g,G as _,Gn as v,Hi as y,It as b,J as x,Jn as S,K as C,Kn as w,O as T,Oi as E,Ri as D,Rn as O,St as k,T as A,V as j,Vr as M,W as ee,Xn as N,Yr as P,Z as F,Zr as te,Zt as I,_t as L,bn as R,ca as ne,cr as z,dn as re,dt as B,en as V,ht as ie,lr as ae,m as oe,mi as se,na as H,or as ce,ot as U,pn as le,r as ue,t as de,ui as fe,vn as pe,xn as W,yn as me,z as he,zi as ge,zn as _e}from"./player-overlays-B32sNiuW.js";import{Cn as ve,Dr as ye,En as be,Fi as xe,Gr as Se,Ii as Ce,Ir as we,Kr as G,Mr as Te,Pn as Ee,Qn as De,Rr as Oe,Ur as ke,Xn as Ae,Zn as je,_ as Me,_n as Ne,ai as Pe,d as Fe,gn as Ie,h as Le,hn as Re,m as ze,mn as Be,mr as Ve,ni as He,oi as K,p as Ue,qn as We,ri as Ge,si as q,v as Ke,vn as qe,wn as Je,x as Ye}from"./client-CBY2Ai10.js";import{t as Xe}from"./archive-CnyG155u.js";import{i as Ze,n as Qe,r as $e,t as et}from"./scan-eye-DkWYA8Qn.js";import{t as tt}from"./bell-off-BCgckLrg.js";import{t as nt}from"./boxes-uA3JVB9e.js";import{n as rt}from"./video-JAYMKNkG.js";import{t as it}from"./circle-slash-CXSKoFJ3.js";import{t as at}from"./layers-DSNZIEzf.js";import{$ as ot,$n as st,An as ct,Ar as lt,Br as ut,Ca as dt,Cc as ft,Co as pt,Dn as mt,Dt as ht,Du as gt,F as _t,Fc as vt,Fn as yt,Ft as bt,Fu as xt,G as St,Ga as Ct,Gt as wt,Ha as Tt,Hn as Et,Ht as Dt,Ia as Ot,Ic as kt,In as At,It as jt,Iu as Mt,J as Nt,Ja as Pt,Jo as Ft,Jr as It,K as Lt,Ka as Rt,Kc as zt,Kt as Bt,Ku as Vt,Lc as Ht,Ln as Ut,Lu as Wt,Ma as Gt,Mn as Kt,Mt as qt,Mu as Jt,N as Yt,Nc as Xt,Nt as Zt,Nu as Qt,Oi as $t,On as en,Pc as tn,Pn as nn,Qn as rn,Qu as an,Rc as on,Rn as sn,Rr as cn,Rt as ln,Sa as un,Tn as dn,Tr as fn,Uo as pn,Ut as mn,Va as hn,Vr as gn,Vs as _n,Vt as vn,Wu as yn,Xa as bn,Xt as xn,Y as Sn,Ya as Cn,Yo as wn,Yt as Tn,Zn as En,Zt as Dn,_o as On,_r as kn,a as An,aa as jn,an as Mn,ar as Nn,ba as Pn,bo as Fn,br as In,bt as Ln,c as Rn,cr as zn,da as Bn,dc as Vn,er as Hn,et as Un,fi as Wn,fn as Gn,fr as Kn,ga as qn,gn as Jn,gr as Yn,gt as Xn,hr as J,i as Zn,io as Qn,ir as $n,jn as er,js as tr,jt as nr,kn as rr,kt as ir,l as ar,lc as or,lr as sr,mc as cr,mn as lr,nr as ur,nt as dr,o as fr,oa as pr,or as mr,pc as hr,qo as gr,qt as _r,qu as vr,r as yr,rr as br,s as xr,sl as Sr,to as Cr,tt as wr,ua as Tr,uc as Er,uo as Dr,vc as Or,vr as kr,wa as Ar,wn as jr,ya as Mr,yn as Nr,yr as Pr,yt as Fr,zs as Ir,zt as Lr,zu as Rr}from"./src-wMLlETeo.js";import{t as Y}from"./i18n-DBncQ6jl.js";import{t as X}from"./useTranslation-D3Is_4B6.js";import"./mount-DspKRUOC.js";import{A as zr,F as Br,H as Vr,I as Hr,J as Ur,K as Wr,M as Gr,N as Kr,P as qr,Q as Jr,U as Yr,V as Xr,W as Zr,X as Qr,Y as $r,Z as ei,et as ti,g as ni,h as ri,j as ii,nt as ai,p as oi,q as si,tt as ci}from"./index-DM2PlJTq.js";import{C as li,D as ui,E as di,S as fi,_ as pi,a as mi,b as hi,c as gi,d as _i,f as vi,g as yi,h as bi,i as xi,l as Si,m as Ci,n as wi,o as Ti,p as Ei,r as Di,s as Oi,t as ki,u as Ai,v as ji,x as Mi,y as Ni}from"./CompositionEditor-CW5KG78s.js";import{_ as Pi,a as Fi,c as Ii,d as Li,f as Ri,g as zi,h as Bi,i as Vi,l as Hi,m as Ui,n as Wi,o as Gi,p as Ki,s as qi,t as Ji,u as Yi,v as Xi,y as Zi}from"./ClusterStepModel-D7FHDo3b.js";import"./useEventInvalidation-DspKRUOC.js";import{t as Qi}from"./use-stationary-objects-CuK9Ramz.js";import{a as $i,c as ea,d as ta,f as na,i as ra,l as ia,n as aa,o as oa,p as sa,r as ca,s as la,t as ua,u as da}from"./linked-devices-model-DzL0krEK.js";import{t as fa}from"./authed-media-C0Di1-mt.js";e();function pa(e){if(typeof e!=`object`||!e)return null;let t=e,n=t.id,r=t.label;if(typeof n!=`string`||typeof r!=`string`)return null;let i=t.available===!0,a=t.enabled,o=t.unavailableReason;return{id:n,label:r,costWhenOff:typeof t.costWhenOff==`string`?t.costWhenOff:``,on:i&&typeof a==`boolean`?a:null,available:i,unavailableReason:typeof o==`string`?o:null}}function ma(e){if(typeof e!=`object`||!e)return null;let t=e.switches;if(!Array.isArray(t))return null;let n=t.map(pa).filter(e=>e!==null);return n.length===0?null:n}var ha=[[/privacy|mask/i,`privacy`],[/microphone|mic\b/i,`microphone`],[/speaker|broker audio|stream audio/i,`speaker`],[/audio/i,`listening`],[/object|detect/i,`detection`],[/event/i,`archive`],[/record/i,`recording`],[/notif/i,`notifications`],[/stream|broker/i,`stream`]];function ga(e){for(let[t,n]of ha)if(t.test(e))return n;return`generic`}function _a(e){let t=e.filter(e=>e.on===!1).map(e=>e.id),n=e.filter(e=>e.on===null).map(e=>e.id),r=t=>t.map(t=>e.find(e=>e.id===t)?.label??t).join(`, `),i=[];return t.length>0&&i.push(Y.t(`helpers.cameraSwitchRows.off`,{list:r(t)})),n.length>0&&i.push(Y.t(`helpers.cameraSwitchRows.unknown`,{list:r(n)})),{offIds:t,unknownIds:n,summary:i.length===0?Y.t(`helpers.cameraSwitchRows.allOn`):i.join(` · `)}}var va={stream:W,detection:et,privacy:f,microphone:N,speaker:k,listening:Qe,archive:Xe,recording:$e,notifications:D,generic:V};function ya({deviceId:e}){let{t}=X(),n=c(),o=Number.isFinite(e),[s,l]=r(null),[u,f]=r(!1),p=cr({deviceId:e},{enabled:o});yr([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let m=ma(p.data),h=on({onError:(t,r)=>{console.error(`[CameraFunctionSwitches] switch write failed — reverting`,{tags:{deviceId:e},meta:{switchId:r.switchId,error:t instanceof Error?t.message:String(t)}}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSwitches`]]}),l({id:r.switchId,message:t instanceof Error?t.message:String(t)})},onSuccess:()=>{l(null),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),n.invalidateQueries({queryKey:[[`deviceManager`]]}),n.invalidateQueries({queryKey:[[`recording`]]})}}),g=i(t=>{!t.available||t.on===null||h.mutate({deviceId:e,switchId:t.id,enabled:!t.on})},[e,h]);if(m===null)return null;let _=_a(m),v=e=>s?.id===e.id?s.message:null;return a(xt,{open:u,onOpenChange:f,children:[a(Wt,{"aria-label":t(`device.cameraFunctionSwitches.cameraFunctions`,`Camera functions`),title:_.summary,className:`inline-flex items-center gap-1 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors ${s===null?_.offIds.length>0?`border-warning/40 text-warning hover:bg-warning/10`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`:`border-danger/50 text-danger bg-danger/5`}`,children:[d(V,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden lg:inline`,children:t(`device.cameraFunctionSwitches.functions`,`Functions`)}),_.offIds.length>0&&d(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:t(`device.cameraFunctionSwitches.offCount`,{count:_.offIds.length})})]}),a(Mt,{align:`end`,className:`min-w-[240px] max-h-[60vh] overflow-y-auto p-1`,children:[d(`div`,{className:`px-2 py-1 text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t(`device.cameraFunctionSwitches.cameraFunctions`,`Camera functions`)}),d(`ul`,{className:`space-y-0.5`,children:m.map(e=>d(`li`,{children:d(ba,{row:e,failure:v(e),onToggle:()=>g(e)})},e.id))})]})]})}function ba({row:e,failure:t,onToggle:n}){let{t:r}=X(),i=va[ga(e.label)],o=e.on===null,s=e.on===!1,c=t===null?o?e.unavailableReason??`The source that owns this did not answer.`:e.costWhenOff:`Write failed: ${t}`,l=t===null?o?e.unavailableReason??`unknown`:null:`write failed`;return a(`button`,{type:`button`,role:`switch`,"aria-label":e.label,"aria-checked":e.on===!0,disabled:!e.available,onClick:n,title:c,className:`flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-[12px] text-foreground transition-colors hover:bg-surface-hover disabled:opacity-40 disabled:cursor-not-allowed`,children:[d(i,{className:`h-3.5 w-3.5 shrink-0 ${t===null?o?`text-foreground-subtle/50`:s?`text-warning`:`text-success`:`text-danger`}`}),a(`span`,{className:`flex-1 min-w-0 truncate`,children:[e.label,l!==null&&a(`span`,{className:`ml-1 text-[10px] text-foreground-subtle`,children:[`· `,l]})]}),d(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[9px] font-semibold uppercase tracking-wide ${o?`bg-surface-hover text-foreground-subtle/60`:s?`bg-warning/20 text-warning`:`bg-success/20 text-success`}`,children:o?`—`:r(s?`common.off`:`common.on`)})]})}function xa({deviceId:e}){let t=ln(U().trpcClient,e);return t===null?null:a(`a`,{href:t.url,target:`_blank`,rel:`noopener noreferrer`,title:`${t.label} — ${t.host}`,className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[d(M,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden sm:inline`,children:t.label})]})}function Sa({parentDeviceId:e}){let{t}=X(),n=ti(),r=U(),{data:i,isLoading:o,isError:s}=Zr(e),{data:c}=Ct({deviceId:e},{enabled:Number.isFinite(e)});if(o)return d(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:d(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(s)return d(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:d(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let l=(i??[]).filter(e=>e.display?.hidden!==!0);if(l.length===0)return null;let u=Zt(c?.stableId??``,l,c?.childLayout),f=u.ungrouped,p=e=>n(`/devices/${String(e)}`),m=c?.name??``,h=(e,t)=>d(nr,{trpc:r.trpcClient,device:{...t,name:Lr(t,m)},variant:`minimal`,onNavigate:p},e),g=f.some(e=>!!e.role),_=f.some(e=>!e.role),v=g&&!_?t(`device.accessories`,{defaultValue:`Accessories`}):!g&&_?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),y=f.length>0?a(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[d(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:v}),d(`div`,{className:`space-y-1`,children:f.map(e=>h(e.id,e))})]}):null,b=u.disabledSection===void 0?null:d(qt,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:u.disabledSection.children.length,defaultOpen:!1,children:d(`div`,{className:`opacity-60 space-y-1`,children:u.disabledSection.children.map(e=>h(e.id,e))})},u.disabledSection.title);if(u.sections.length===0)return b===null?y:a(`div`,{className:`space-y-2`,children:[y,b]});let x=_&&!g;return a(`div`,{className:`space-y-2`,children:[x?y:null,u.sections.map(e=>d(qt,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>h(e.id,e))},e.title)),x?null:y,b]})}function Ca({deviceId:e}){let t=U(),{data:n,isLoading:r}=Yr(e),{data:i,isLoading:a}=Zr(e),o=r||a,s=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),c=typeof n?.linkDeviceId==`number`?n.linkDeviceId:null,l=typeof n?.primaryChildEntityId==`string`?n.primaryChildEntityId:null;return o?d(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):d(`div`,{className:`flex h-full w-full flex-col`,children:d(vn,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}e();function wa({dev:e,busy:t,setBusy:n}){let{t:i}=X(),o=e?.motionTrigger,s=x(e?.state.motionTrigger),[c,l]=r(!1);if(!o)return null;let u=s?.enabled===!0,f=s!==void 0,p=async()=>{if(t||!f)return;let e=!u;n(!0),l(!0);try{await o.setMotionTrigger({enabled:e})}finally{n(!1),l(!1)}},m=c?u?`Disabling…`:`Enabling…`:f?u?`On motion: on`:`On motion: off`:`On motion: …`;return a(`button`,{type:`button`,onClick:()=>{p()},disabled:t||!f,title:f?u?i(`hero.motionTriggerToggle.disableTriggerOnMotion`,`Disable trigger on motion`):i(`hero.motionTriggerToggle.enableTriggerOnMotion`,`Enable trigger on motion`):i(`hero.motionTriggerToggle.awaitingState`,`Awaiting state…`),"aria-pressed":u,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${u?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[d(H,{className:`h-3 w-3`}),d(`span`,{children:m})]})}e();function Z({deviceId:e,deviceType:t,features:n}){let i=U(),o=wt(t)?.HeroCard??Bt,s=C(i.trpcClient,e),c=x(s?.state.deviceStatus),[l,u]=r(!1),f=c!==void 0&&c.online===!1,p=f?c.lastChangedAt:null;return a(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[f?d(`div`,{className:`flex justify-center`,children:d(mn,{lastChangedAt:p})}):null,d(o,{trpc:i.trpcClient,deviceId:e,features:n}),d(`div`,{className:`flex justify-center`,children:d(wa,{dev:s,busy:l,setBusy:u})})]})}function Ta({deviceId:e,features:t}){return d(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:d(_r,{trpc:U().trpcClient,deviceId:e,features:t})})}function Ea({deviceId:e,features:t}){return d(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:d(Bt,{trpc:U().trpcClient,deviceId:e,features:t})})}function Da(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function Oa(e){if(!e)return null;let t=Da(e.data);return t===null?e.eventType:Y.t(`helpers.eventEmitterFormat.buttonHeadline`,{channel:String(t),eventType:e.eventType})}var ka=1e3,Aa=60*ka,ja=60*Aa,Ma=24*ja;function Na(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<ka?Y.t(`helpers.relativeTime.justNow`):n<Aa?Y.t(`helpers.relativeTime.secondsAgo`,{count:Math.floor(n/ka)}):n<ja?Y.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(n/Aa)}):n<Ma?Y.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(n/ja)}):Y.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(n/Ma)})}e();var Pa=1500,Fa=15e3,Ia=1e3;function La({deviceId:e}){let{t:n}=X(),i=C(U().trpcClient,e)?.state.eventEmitter,o=x(i);t(()=>{if(!i)return;i.refresh();let e=setInterval(()=>{i.refresh()},Fa);return()=>{clearInterval(e)}},[i]);let s=o?.lastEvent??null,c=s?.seq??null,u=l(null),[f,p]=r(!1);t(()=>{if(c===null)return;let e=u.current;if(u.current=c,e===null||e===c)return;p(!0);let t=setTimeout(()=>{p(!1)},Pa);return()=>{clearTimeout(t)}},[c]);let[h,g]=r(()=>Date.now());t(()=>{let e=setInterval(()=>{g(Date.now())},Ia);return()=>{clearInterval(e)}},[]);let _=Oa(s),y=o?.eventTypes??[],b=o?.eventCountSinceStart??0,S=o!==void 0,w=Da(s?.data);return a(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[d(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(f),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${f?`border-primary bg-primary/20 text-primary shadow-lg shadow-primary/30 scale-105`:`border-border bg-surface text-foreground-subtle`}`,"aria-live":`polite`,title:_??n(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`),children:d(f?v:m,{className:`h-10 w-10`})}),a(`div`,{className:`text-center`,children:[w!==null&&d(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:n(`hero.eventEmitterHero.button`,`Button {{value1}}`,{value1:String(w)})}),d(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${_?`text-foreground`:`text-foreground-subtle`}`,children:_??(S?n(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`):n(`hero.eventEmitterHero.awaitingState`,`Awaiting state…`))}),d(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:s?Na(s.timestamp,h):n(`hero.eventEmitterHero.waitingForTheFirstEvent`,`Waiting for the first event`)})]}),y.length>0&&d(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:y.map(e=>d(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===s?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:n(`hero.eventEmitterHero.sinceStart`,{count:b})})]})}function Ra({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){let{t:o}=X();return a(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[d($r,{type:n,size:`lg`}),a(`div`,{children:[d(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),d(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),a(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[d(dr,{status:r?`online`:`offline`}),i.length>0&&d(Qr,{capabilities:i})]}),d(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:o(`hero.genericHero.noLiveViewForThis`,`No live view for this device type. Use the Config tab or the shortcut row to interact.`)})]})}e();function za({deviceId:e}){let{t}=X(),r=c(),i=Mr({deviceId:e},{refetchInterval:1e4,retry:!1}),o=Pn({onSuccess:()=>{r.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),r.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),s=n(()=>Ba(i.data??[]),[i.data]);return a(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[a(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[d(Va,{label:t(`hero.hubHero.discovered`,`Discovered`),value:s.total,icon:d(_e,{className:`h-3.5 w-3.5`})}),d(Va,{label:t(`hero.hubHero.adopted`,`Adopted`),value:s.adopted,accent:`success`}),d(Va,{label:t(`hero.hubHero.available`,`Available`),value:s.available,accent:s.available>0?`primary`:void 0}),a(`button`,{type:`button`,onClick:()=>{o.mutateAsync({deviceId:e}).catch(()=>{})},disabled:o.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[o.isPending?d(ce,{className:`h-3.5 w-3.5 animate-spin`}):d(R,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden sm:inline`,children:t(`hero.hubHero.discover`,`Discover`)})]})]}),a(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[d(Ha,{icon:d(ie,{className:`h-3 w-3 text-emerald-500`}),label:t(`hero.hubHero.online`,`{{online}} online`,{online:s.online})}),d(Ha,{icon:d(w,{className:`h-3 w-3 text-amber-500`}),label:t(`hero.hubHero.sleeping`,`{{sleeping}} sleeping`,{sleeping:s.sleeping})}),d(Ha,{icon:d(L,{className:`h-3 w-3 text-destructive`}),label:t(`hero.hubHero.offline`,`{{offline}} offline`,{offline:s.offline})}),s.unknown>0?d(Ha,{icon:d(fe,{className:`h-3 w-3 text-foreground-subtle`}),label:t(`hero.hubHero.unknown`,`{{unknown}} unknown`,{unknown:s.unknown})}):null]})]})}function Ba(e){let t={total:e.length,adopted:0,available:0,online:0,sleeping:0,offline:0,unknown:0};for(let n of e)n.alreadyAdopted?t.adopted+=1:t.available+=1,t[n.status]+=1;return t}function Va({label:e,value:t,icon:n,accent:r}){return a(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${r===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:r===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[a(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,d(`span`,{className:`truncate`,children:e})]}),d(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function Ha({icon:e,label:t}){return a(`span`,{className:`inline-flex items-center gap-1`,children:[e,d(`span`,{children:t})]})}var Ua={[q.Switch]:Z,[q.Siren]:Z,[q.Light]:Z,[q.Sensor]:Z,[q.Button]:Z,[q.Hub]:za,[q.Cover]:Ta,[q.Valve]:Z,[q.Humidifier]:Z,[q.WaterHeater]:Z,[q.Container]:Ca,[q.Lock]:Z,[q.Fan]:Z,[q.Thermostat]:Z,[q.Climate]:Z,[q.MediaPlayer]:Z,[q.Control]:Z,[q.AlarmPanel]:Z,[q.EventEmitter]:La,[q.Notifier]:Ea,[q.Script]:Z,[q.Automation]:Z,[q.Presence]:Z,[q.Update]:Z,[q.Vacuum]:Z,[q.LawnMower]:Z,[q.Weather]:Z,[q.Image]:Z,[q.PetFeeder]:Z,[q.Dishwasher]:Z};function Wa(e){return Ua[e]??Ra}function Ga(e){return d(Wa(e.deviceType),{...e})}function Ka(e){return fr(U().trpcClient,e)}e();function qa(e){let[n,a]=r(`idle`),[o,s]=r(null),c=l(null),u=l(null),d=l(null),f=l(!0),p=Ft(),m=gr(),h=wn(),g=i(()=>{if(c.current){try{c.current.close()}catch{}c.current=null}if(u.current){for(let e of u.current.getTracks())try{e.stop()}catch{}u.current=null}d.current=null},[]),_=i(async()=>{if(n===`idle`)return;a(`stopping`);let t=d.current;if(t&&e!==null)try{await Promise.race([h.mutateAsync({deviceId:e,sessionId:t}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}g(),f.current&&(a(`idle`),s(null))},[n,e,h,g]),v=i(async()=>{if(e===null||n!==`idle`&&n!==`error`)return;s(null);let t=null,r=null,i=null;try{a(`requesting-mic`),t=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),u.current=t,a(`starting`);let n=await p.mutateAsync({deviceId:e});i=n.sessionId,d.current=i,a(`connecting`),r=new RTCPeerConnection,c.current=r,r.oniceconnectionstatechange=()=>{if(!f.current)return;let e=r.iceConnectionState;e===`connected`||e===`completed`?a(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&f.current&&(s(e===`failed`?`WebRTC connection failed`:null),_())};for(let e of t.getAudioTracks())r.addTrack(e,t);await r.setRemoteDescription({type:`offer`,sdp:n.sdpOffer});let o=await r.createAnswer();await r.setLocalDescription(o);let l=r.localDescription?.sdp??o.sdp??``;await m.mutateAsync({deviceId:e,sessionId:i,sdpAnswer:l})}catch(n){let o=n instanceof Error?n.message:String(n);if(console.warn(`[intercom] start failed`,n),r)try{r.close()}catch{}if(t)for(let e of t.getTracks())try{e.stop()}catch{}if(c.current=null,u.current=null,i!==null)try{await h.mutateAsync({deviceId:e,sessionId:i})}catch{}d.current=null,f.current&&(s(o),a(`error`))}},[e,n,p,m,h,_]);return t(()=>(f.current=!0,()=>{f.current=!1;let t=d.current;if(t!==null&&e!==null&&h.mutate({deviceId:e,sessionId:t}),c.current){try{c.current.close()}catch{}c.current=null}if(u.current){for(let e of u.current.getTracks())try{e.stop()}catch{}u.current=null}d.current=null}),[e]),{state:n,error:o,start:v,stop:_,isTalking:n===`talking`}}e();var Ja=0;function Q(){return++Ja}function Ya(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Xa(e){return[``,`Commands`,` help Show this help`,` examples Show usage examples for the current scope`,` context Show every available variable + full API surface`,` clear Clear terminal (also Ctrl+L)`,``,`Shortcuts`,` Enter Execute expression`,` Arrow Up/Down Navigate command history`,` Ctrl+L Clear terminal`,``,`Try: ${{system:` sm.summary() // fleet overview`,device:` device.state.battery.value?.sleeping // sync read`,provider:` devices.map(d => d.name)`,addon:` manifest.version`}[e.type]}`,``,`Top-level objects: sm (SystemMirror), DeviceType, Math, JSON, Date, …`]}function Za(e){switch(e.type){case`device`:return[``,`── State (sync, zero round-trip) ─────────────────────────`,` device.state.battery.value`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,``,`── Actions (async, through wrapper chain) ────────────────`,` await device.snapshot.getSnapshot({})`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.switch.setState({ on: true })`,``,`── Wait for condition ───────────────────────────────────`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`── Subscribe to changes ─────────────────────────────────`,` const off = device.state.battery.subscribe(s => console.log(s))`,``,`── Quick info ───────────────────────────────────────────`,` info.name device name`,` info.addonId owning addon`,` sm.dump(deviceId) full debug dump`];case`system`:return[``,`── Lookups ──────────────────────────────────────────────`,` sm.getDeviceById(8)`,` sm.getDeviceByName('Sala da pranzo')`,` sm.getDevicesByAddon('reolink')`,` sm.getDevicesByType(DeviceType.Camera)`,``,`── Filters (typed query) ────────────────────────────────`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] })`,` sm.query({ name: /^Cam-/ })`,``,`── Cross-device ─────────────────────────────────────────`,` sm.whereState('battery', s => s.percentage < 20).length`,` sm.mapState('battery', s => s.percentage)`,` sm.countByCap('snapshot')`,``,`── Batch action ─────────────────────────────────────────`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,``,`── Listen ───────────────────────────────────────────────`,` sm.listenCap('motion', (id, s) => console.log(id, s))`,` sm.onDeviceAdded((id, info) => console.log('+', info.name))`,``,`── Diagnostics ──────────────────────────────────────────`,` sm.summary()`,` sm.dump(8)`];case`provider`:return[``,` devices.map(d => d.name)`,` await getIntegration()`,` sm.getDevicesByAddon('<this-addon-id>').length`];case`addon`:return[``,` manifest.name`,` manifest.version`,` declaration`]}}function Qa(e){let t=[``,`Scope: ${e.type}`,``];switch(e.type){case`system`:return[...t,`Primary API — sm (SystemMirror):`,` sm.getDeviceById(id) DeviceProxy | null (sync)`,` sm.getDeviceByName(name) DeviceProxy | null`,` sm.getDeviceByStableId(sid) DeviceProxy | null`,` sm.getAllDevices() readonly DeviceProxy[]`,` sm.getDeviceInfo(id) DeviceInfo | null`,` sm.summary() fleet stats`,``,`Filters — sm.query({...}):`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] }) // ALL caps required`,` sm.query({ anyCap: ['ptz', 'motion'] }) // ANY cap`,` sm.query({ name: { contains: 'sala' } }) // case-insensitive`,` sm.query({ name: /^Cam-\\d+$/ })`,` sm.query({ type: DeviceType.Camera })`,` sm.query({ parentDeviceId: 8 }) // accessories of cam 8`,` sm.query({ where: (info, dev) => dev.state.battery.value?.sleeping })`,``,`State queries:`,` sm.whereState('battery', s => s.percentage < 20)`,` sm.mapState('battery', s => s.percentage)`,` sm.findState('motion', s => s.detected)`,` sm.countByCap('snapshot')`,``,`Listeners (return unsubscribe fn):`,` sm.listen((id, cap, slice) => …) // every state change`,` sm.listenCap('motion', (id, slice) => …)`,` sm.listenDevice(8, (id, cap, slice) => …)`,` sm.onDeviceAdded((id, info) => …)`,` sm.onDeviceRemoved((id, info) => …)`,``,`Wait primitives:`,` await sm.waitForState(8, 'battery', s => !s.sleeping, 30_000)`,` await sm.waitForDevice(99, 30_000)`,``,`Batch:`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,` await sm.forEachCap('reboot', d => d.reboot.reboot({}))`,``,`Diagnostics:`,` sm.dump(8) debug dump (one device)`,` sm.dump() full fleet dump`,` sm.summary() breakdown by cap/addon/type`,``,`Legacy: deviceRegistry, addonRegistry, eventBus, devices(), addons()`];case`device`:return[...t,`Pre-bound variables:`,` device DeviceProxy for this device (sync state + async methods)`,` deviceId number`,` info DeviceInfo metadata (name, addonId, type, online, …)`,` sm SystemMirror (full cluster view)`,` rawDevice legacy IDevice instance (escape hatch)`,``,`Reactive state (sync, zero round-trip):`,` device.state.battery.value BatteryStatus | undefined`,` device.state.battery.value?.sleeping`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,` device.state.switch.value?.on`,` device.state.brightness.value?.percentage`,` device.state.doorbell.value?.lastPressedAt`,``,`Cap actions (async, through wrapper chain):`,` await device.snapshot.getSnapshot({})`,` await device.snapshot.getSnapshot({ streamId: 'high' })`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.ptz.goToPreset({ presetId: 'home' })`,` await device.switch.setState({ on: true })`,` await device.brightness.setBrightness({ percentage: 60 })`,` await device.reboot.reboot({})`,``,`Subscribe to slice changes:`,` const off = device.state.battery.subscribe(s => console.log(s))`,` // off() to unsubscribe`,``,`Wait for a state condition:`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`Diagnostics:`,` info.name device name`,` info.addonId which addon owns it`,` info.online transport health`,` sm.dump(deviceId) full debug dump (binding + state + info)`];case`provider`:return[...t,`Pre-bound variables:`,` devices Devices belonging to this provider (raw IDevice[])`,` getIntegration() Integration metadata`,``,`For typed device access use the SystemMirror:`,` await getSystemMirror()`,` sm.getDevicesByAddon('this-addon-id')`];case`addon`:return[...t,`Pre-bound variables:`,` manifest { name, version, ... }`,` declaration addon declaration`,` source addon source location`,``,`Examples:`,` manifest.name`,` manifest.version`]}}function $a({scope:e,greeting:n,className:o}){let{t:s}=X(),c=U(),[f,p]=r(()=>{let t=[];return n&&t.push({id:Q(),kind:`info`,text:n}),t.push({id:Q(),kind:`info`,text:`scope: ${Ya(e)} — type help or context for available commands`}),t}),[m,h]=r(``),[g,_]=r([]),[v,y]=r(-1),b=l(null),x=l(null);t(()=>{let e=x.current;e&&(e.scrollTop=e.scrollHeight)},[f]);let S=i(()=>{b.current?.focus()},[]),C=u({mutationFn:t=>c.trpcClient.repl.execute.mutate({code:t,scope:e}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;p(e=>[...e,{id:Q(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);p(e=>[...e,{id:Q(),kind:`error`,text:t}])}});function w(t){let n=t.trim();if(n){if(n===`clear`){p([{id:Q(),kind:`info`,text:`scope: ${Ya(e)}`}]),h(``);return}if(n===`help`){p(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...Xa(e).map(e=>({id:Q(),kind:`info`,text:e}))]),h(``);return}if(n===`context`){p(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...Qa(e).map(e=>({id:Q(),kind:`info`,text:e}))]),h(``);return}if(n===`examples`){p(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...Za(e).map(e=>({id:Q(),kind:`info`,text:e}))]),h(``);return}_(e=>[...e,n]),y(-1),p(e=>[...e,{id:Q(),kind:`input`,text:`> ${n}`}]),h(``),C.mutate(n)}}function T(t){if(t.key===`Enter`){t.preventDefault(),w(m);return}if(t.key===`ArrowUp`){if(t.preventDefault(),g.length===0)return;let e=v===-1?g.length-1:Math.max(0,v-1);y(e),h(g[e]??``);return}if(t.key===`ArrowDown`){if(t.preventDefault(),v===-1)return;let e=v+1;e>=g.length?(y(-1),h(``)):(y(e),h(g[e]??``));return}t.ctrlKey&&t.key===`l`&&(t.preventDefault(),p([{id:Q(),kind:`info`,text:`scope: ${Ya(e)}`}]))}let E={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return a(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${o??``}`,onClick:S,children:[a(`div`,{ref:x,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[f.map(e=>d(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${E[e.kind]}`,children:e.text},e.id)),C.isPending&&d(`span`,{className:`text-zinc-500 animate-pulse`,children:s(`shared.replTerminal.thinking`,`…thinking`)})]}),a(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[d(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:s(`shared.replTerminal.text`,`>`)}),d(`input`,{ref:b,value:m,onChange:e=>h(e.target.value),onKeyDown:T,disabled:C.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function eo(e,t){return e===null?null:{playbackUrl:e.url,...e.format===void 0?{}:{playbackFormat:e.format},playbackAuthToken:t,...e.label===void 0?{}:{playbackLabel:e.label}}}e();function to({deviceId:e,intercomAvailable:t=!1}){let r=U(),i=typeof window<`u`?F():``,a=Number.isFinite(e),o=Ka(a?e:null),c=Qi(a?[e]:[]),l=n(()=>{if(!a)return;let e=[];for(let t of c.rows){let n=An(t);n!==null&&e.push(n)}return e},[a,c.rows]),{streams:u,pipelineMetrics:f,createSession:p,sendAnswer:m,handleOffer:h,getIceServers:g,addIceCandidate:v,getIceCandidates:y,closeSession:b,getSessionState:x,applyDownlinkProbe:S}=Gn(r.trpcClient,a?e:null),C=_(a?e:null,{width:oo}),w=qa(a&&t?e:null),T=w.state===`requesting-mic`||w.state===`starting`||w.state===`connecting`||w.state===`stopping`,E=w.isTalking||T,D=()=>{w.state===`idle`||w.state===`error`?w.start():w.state!==`stopping`&&w.stop()},O=ue(),k=sr(),A=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,j=eo(k.request,A),M=O.length>0?d(s,{children:O.map(e=>d(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return d(St,{serverUrl:i,createSession:p,sendAnswer:m,handleOffer:h,getIceServers:g,addIceCandidate:v,getIceCandidates:y,closeSession:b,getSessionState:x,applyDownlinkProbe:S,...j===null?{}:{...j,onExitPlayback:()=>k.clear()},streams:u,pipelineMetrics:f,phase:o.phase,detections:o,...l===void 0?{}:{stationaryObjects:l},defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:C.src,...C.src?{posterUrl:C.src}:{},snapshotLoading:C.loading,onRefreshSnapshot:C.refresh,intercomAvailable:t,intercomShown:E,onIntercomToggle:D,extraOverlay:M,chromeless:!0,className:`h-full`})}function no({deviceId:e,containerDeviceId:t}){let{t:n}=X();return Number.isFinite(e)?d(`div`,{className:`flex flex-col h-full`,children:d(Dn,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):d(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:n(`device.panelContent.notLoaded`,{id:e})})}function ro({deviceId:e}){let{t}=X();if(!Number.isFinite(e))return d(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:t(`device.panelContent.notLoaded`,{id:e})});let n=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
2
+ `);return d($a,{scope:{type:`device`,deviceId:e},greeting:n,className:`h-full border-0 rounded-none`})}function io({deviceId:e}){let{t}=X();return Number.isFinite(e)?d(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:d(xn,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):d(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:t(`device.panelContent.notLoaded`,{id:e})})}function ao({deviceId:e}){let{t}=X();return Number.isFinite(e)?d(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:d(Tn,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):d(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:t(`device.panelContent.notLoaded`,{id:e})})}var oo=960;function so(e){return new Set(e.filter(e=>{let t=e.nativeAddonId?.trim()??``;return t!==``&&t!==`composer`}).map(e=>e.capName))}function co(e){return e.kind===`known`?null:e}function lo(e,t){return e.composable.kind===`known`?e.composable.value.has(t)?{kind:`present`,mode:`add`}:{kind:`absent`}:e.composable}function uo(e){if(e.deviceType!==q.Camera)return{kind:`absent`};switch(e.cameraSensors){case`pending`:return{kind:`pending`};case`unknown`:return{kind:`unknown`,reason:Y.t(`helpers.assignmentAvailability.sensorsUnchecked`)};case`absent`:return{kind:`absent`};case`present`:return{kind:`present`,mode:`add`}}}function fo(e,t){if(e===`motion`)return uo(t);let n=co(t.nativeCaps);if(n!==null)return n;let r=t.nativeCaps.kind===`known`?t.nativeCaps.value:new Set;switch(e){case`doorbell`:return r.has(`doorbell`)?{kind:`absent`}:lo(t,`doorbell`);case`battery`:return r.has(`battery`)?{kind:`present`,mode:`replace`}:lo(t,`battery`);case`consumables`:return r.has(`consumables`)?{kind:`absent`}:lo(t,`consumables`)}}function po({onAdvanced:e}){let{t}=X();return e===void 0?null:d(`button`,{type:`button`,className:`rounded text-left text-[11px] text-primary hover:underline focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary`,onClick:e,children:t(`customize.advancedLink`)})}function mo(e){if(e.status===`pending`)return{kind:`pending`};if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??Y.t(`helpers.customize.requestFailed`)};let t=e.data;if(t===void 0)return{kind:`pending`};if(t.state===`not-loaded`)return{kind:`not-loaded`,reason:t.reason};if(t.view===null)return{kind:`none`};let n=Te(t.view.block);return n===null?{kind:`unknown`,reason:Y.t(`helpers.customizationRead.notAComposition`,{id:t.view.block.id})}:{kind:`present`,view:t.view,composition:n}}function ho(e){return e.kind===`present`?e.composition:null}function go(e,t){let{hidden:n,...r}=e??{},i=t?{...r,hidden:!0}:r;return Object.keys(i).length===0?null:i}function _o(e){return typeof e.linkDeviceId==`number`}var vo=new Set(Object.values(K));function yo(e){return vo.has(e)}var bo={[q.Switch]:[K.Siren,K.Floodlight,K.Spotlight,K.PirSensor,K.Chime,K.Autotrack,K.Nightvision,K.PrivacyMask,K.BinaryHelper],[q.Light]:[K.Floodlight,K.Spotlight,K.Nightvision],[q.Siren]:[K.Siren],[q.Button]:[K.Doorbell],[q.Sensor]:[K.MotionSensor,K.ContactSensor,K.LeakSensor,K.SmokeSensor,K.COSensor,K.GasSensor,K.TamperSensor,K.VibrationSensor,K.ConnectivitySensor,K.SoundSensor,K.BinarySensor,K.TemperatureSensor,K.HumiditySensor,K.AmbientLightSensor,K.PressureSensor,K.WindSensor,K.RainSensor,K.UvSensor,K.SolarRadiationSensor,K.SoilMoistureSensor,K.PowerSensor,K.EnergySensor,K.VoltageSensor,K.CurrentSensor,K.AirQualitySensor,K.BatterySensor,K.NumericSensor,K.EnumSensor,K.DateTimeSensor,K.GenericSensor],[q.Control]:[K.NumericControl,K.SelectControl,K.TextControl,K.DateTimeControl],[q.Notifier]:[K.MobilePushNotifier,K.MessagingNotifier,K.EmailNotifier,K.GenericNotifier]};function xo(e){for(let t of Object.values(q))if(t===e)return!0;return!1}function So(e){return xo(e)?bo[e]??[]:[]}function Co(e,t){let n=So(t);return e==null||e===``||n.includes(e)?n:[...n,e]}e();function wo({device:e}){let{t}=X(),n=ne(),i=c(),[o,s]=r(null),l=()=>s(null),u={onSuccess:()=>{l(),i.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>s(e.message)},f=On(),p=Dr(),m=e.display?.hidden===!0;return a(`section`,{"aria-label":t(`customize.identity.title`),className:`${T} ${h}`,children:[a(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[d(si,{deviceId:e.id,initialName:e.name,label:t(`customize.identity.name`),layout:`stacked`,onError:s,onSaved:l,onCancel:l}),d(Wr,{deviceId:e.id,initialLocation:e.location,label:t(`customize.identity.room`),layout:`stacked`,onError:s,onSaved:l,onCancel:l}),d(Ur,{label:t(`customize.identity.hidden`),layout:`stacked`,value:d(Kt,{"aria-label":t(`deviceDisplay.hideFromLists`),checked:m,disabled:p.isPending,onChange:t=>p.mutate({deviceId:e.id,display:go(e.display,t.target.checked)},u)})}),d(Ur,{label:t(`customize.identity.role`),layout:`stacked`,value:_o(e)?d(`span`,{children:To(e.role,t(`customize.identity.noRole`),n)}):d(gt,{"aria-label":t(`customize.identity.role`),value:e.role??``,disabled:f.isPending,options:[{value:``,label:t(`customize.identity.noRole`)},...Co(e.role,e.type).map(e=>({value:e,label:To(e,t(`customize.identity.noRole`),n)}))],onChange:t=>f.mutate({deviceId:e.id,role:t.target.value===``?null:t.target.value},u)})})]}),o!==null&&d(`p`,{role:`alert`,className:`mt-2 text-xs text-danger break-words`,children:o})]})}function To(e,t,n){return e==null||e===``?t:yo(e)?yn(e,n).label:e}e();function Eo(e){return e===`pending`?`pending`:e===`error`?`failed`:`answered`}function Do({excludeDeviceIds:e,onSelect:t}){let{t:r}=X(),i=Cn({projection:`slim`}),a=i.status===`success`?i.data:null,o=n(()=>{if(a===null)return[];let t=new Set(e);return gi(a).filter(e=>!t.has(e.id))},[a,e]),s=n(()=>new Map(o.map(e=>[e.id,e])),[o]),c=n(()=>o.map(e=>({id:e.id,name:e.name,type:e.type,...e.location===null?{}:{location:e.location}})),[o]);if(i.status===`error`)return d(Kn,{title:r(`customize.picker.devicesFailed`),message:i.error?.message??``});let l=e=>{let n=s.get(e);n!==void 0&&t(n)};return d(_t,{devices:c,listState:Eo(i.status),value:[],onChange:e=>{let t=e.at(-1);t!==void 0&&l(t)},noun:`device`,emptyLabel:r(`customize.assign.none`),showAll:!0,testId:`customize-field-device-picker`})}function Oo({open:e,title:t,targetKind:n,excludeDeviceIds:i,confirmLabel:o,extra:c,extraComplete:l=!0,onConfirm:u,onClose:f}){let{t:p}=X(),[m,h]=r(null),[g,_]=r(null),v=()=>{h(null),_(null),f()};return d(rn,{open:e,onOpenChange:e=>e?void 0:v(),children:a(Hn,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":t,children:[d(br,{children:d($n,{children:t})}),d(st,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:e&&a(s,{children:[a(`section`,{"aria-label":p(`customize.assign.stepDevice`),className:`flex flex-col gap-1`,children:[d(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:p(`customize.assign.stepDevice`)}),m===null?d(Do,{excludeDeviceIds:i,onSelect:h}):a(`p`,{className:`flex items-center gap-2 text-xs text-foreground`,children:[m.name,d(J,{variant:`ghost`,size:`sm`,onClick:()=>{h(null),_(null)},children:p(`customize.assign.change`)})]})]}),m!==null&&a(`section`,{"aria-label":p(`customize.assign.stepField`),className:`flex flex-col gap-1`,children:[d(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:p(`customize.assign.stepField`)}),d(mi,{device:m,targetKind:n,selected:g===null?null:{cap:g.cap,path:g.path},onPick:_,onBack:()=>{h(null),_(null)}})]}),m!==null&&c!==void 0&&a(`section`,{"aria-label":p(`customize.assign.stepDetails`),className:`flex flex-col gap-1`,children:[d(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:p(`customize.assign.stepDetails`)}),c]})]})}),a(ur,{children:[d(J,{variant:`ghost`,onClick:v,children:p(`customize.assign.cancel`)}),d(J,{disabled:g===null||!l,onClick:()=>{g!==null&&(u(g),h(null),_(null))},children:o})]})]})})}function ko(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ao(e,t){let n=Oi(e,t);return n===void 0?{kind:`absent`}:{kind:`value`,value:n}}function jo(e,t,n){return ko(t)?Ao(t,n):e.status===`error`?{kind:`unknown`,reason:e.error?.message??Y.t(`helpers.liveValue.unreadable`)}:e.status===`pending`||e.data===void 0?{kind:`pending`}:e.data===null?{kind:`absent`}:Ao(e.data,n)}function Mo(e,t,n){let r=e?`active`:`muted`;return t.cap===`contact`&&t.path===`entryOpen`?{text:e?n.open:n.closed,tone:r}:Ge[t.cap]===t.path?{text:e?n.active:n.inactive,tone:r}:{text:String(e),tone:`normal`}}function No(e,t,n){switch(e.kind){case`pending`:return{text:`…`,tone:`muted`};case`unknown`:return{text:`?`,title:e.reason,tone:`warning`};case`absent`:return{text:`—`,tone:`muted`};case`value`:{let r=e.value;return r===null?{text:`—`,tone:`muted`}:typeof r==`boolean`?Mo(r,t,n):typeof r==`number`?{text:t.path===`percentage`?`${Math.round(r)} %`:String(r),tone:`normal`}:typeof r==`string`?{text:r,tone:`normal`}:{text:JSON.stringify(r),tone:`normal`}}}}var Po=0;function Fo(e){let t=U(),n=pt({deviceId:e?.deviceId??Po,capName:e?.cap??``},{enabled:e!==null}),r=xr(t.trpcClient,e?.deviceId??null,e?.cap??``);return e===null?{kind:`absent`}:jo({status:n.status,data:n.data,error:n.error===null||n.error===void 0?null:{message:n.error.message}},r,e.path)}var Io={muted:`text-foreground-subtle`,active:`text-success`,normal:`text-foreground`,warning:`text-warning`};function Lo({target:e}){let{t}=X(),n=Fo(e);return e===null?null:d(Ro,{display:No(n,e,{active:t(`customize.assign.value.active`),inactive:t(`customize.assign.value.inactive`),open:t(`customize.assign.value.open`),closed:t(`customize.assign.value.closed`)})})}function Ro({display:e}){return d(`span`,{className:`text-xs ${Io[e.tone]}`,title:e.title,children:e.text})}function $({name:e,detail:t,meta:n,value:r,shown:i,readout:o,problem:s,onRemove:c,removeLabel:l,busy:u=!1}){return a(`li`,{className:`${A} grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-1 sm:grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,1fr)_1.75rem]`,children:[a(`div`,{className:`min-w-0`,children:[d(`div`,{className:`text-xs text-foreground break-words`,children:e}),t!==null&&d(`div`,{className:`text-[11px] text-foreground-subtle break-words`,children:t}),s!==void 0&&d(`div`,{role:`alert`,className:`text-[11px] text-warning break-words`,children:s})]}),d(`div`,{className:`row-start-2 col-start-1 text-[11px] text-foreground-subtle empty:hidden sm:row-start-auto sm:col-start-auto sm:empty:block`,children:n}),d(`div`,{className:`row-start-3 col-start-1 empty:hidden sm:row-start-auto sm:col-start-auto sm:empty:block`,children:o===void 0?i===void 0?d(Lo,{target:r}):i!==null&&d(Ro,{display:i}):o}),d(`div`,{className:`row-start-1 col-start-2 flex justify-end sm:row-start-auto sm:col-start-auto`,children:c!==void 0&&d(Qt,{icon:B,variant:`ghost`,size:`sm`,"aria-label":l,disabled:u,onClick:c})})]})}function zo({id:e,...t}){return d(lr,{headingId:`customize-${e}`,...t})}function Bo({id:e,icon:t,title:n,headerControl:r,addLabel:i,onAdd:o,addDisabled:c=!1,notices:l,suggestion:u,children:f}){let{t:p}=X(),m=o!==void 0&&i!==void 0;return a(zo,{id:e,icon:t,title:n,actions:a(s,{children:[r,m&&!c&&u!==void 0&&u.count>0&&a(J,{variant:`ghost`,size:`sm`,onClick:u.onOpen,children:[d(I,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),p(`customize.suggest.hint`,{count:u.count,location:u.location})]}),m&&d(J,{variant:`outline`,size:`sm`,disabled:c,onClick:o,children:i})]}),children:[l!==void 0&&d(`div`,{className:`flex flex-col gap-1 px-3 pt-2 empty:hidden sm:px-4`,children:l}),d(`ul`,{className:`flex flex-col divide-y divide-border`,children:f})]})}function Vo({availability:e}){let{t}=X();return e.kind===`pending`?d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.assign.checking`)}):e.kind===`unknown`?d(`p`,{role:`alert`,className:`text-xs text-warning`,children:t(`customize.assign.unknown`,{reason:e.reason})}):null}function Ho(e,t){if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??Y.t(`helpers.customize.requestFailed`)};let n=e.data;return e.status===`pending`||n===void 0?{kind:`pending`}:{kind:`known`,value:t(n)}}function Uo(e,t){let n=an.useQueries(n=>e.map(e=>n.deviceManager.listDeviceIdsByCaps({capNames:[e]},{enabled:t})));return da(e.map((e,t)=>{let r=n[t];return{cap:e,query:r===void 0?{status:`pending`}:{status:r.status,data:r.data,error:r.error===null?null:{message:r.error.message}}}}))}e();function Wo(e,t){let n=ir(e,t);return n.kind===`resolved`?n.integration.name:null}function Go(e){let t=Cn({projection:`slim`},{enabled:e}),{data:r}=pn(void 0,{enabled:e}),i=t.error===null||t.error===void 0?null:t.error.message;return n(()=>Ho({status:t.status,data:t.data,error:i===null?null:{message:i}},e=>e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,type:e.type,location:e.location,isCamera:e.isCamera,integration:Wo(e,r),parentDeviceId:e.parentDeviceId,primaryChildEntityId:e.primaryChildEntityId??null,role:e.role??null}))),[t.status,t.data,i,r])}function Ko(e){let t=Go(e.enabled),n=Uo(He,e.enabled);return t.kind===`unknown`?t:n.kind===`unknown`?n:t.kind===`pending`||n.kind===`pending`?{kind:`pending`}:{kind:`known`,value:sa({devices:t.value,capIndex:n.value,hostId:e.hostId,excludeCameras:e.excludeCameras,assigned:e.assigned,preferredCap:e.preferredCap})}}function qo(){let{t:e}=X(),t=lt();return(n,r)=>t({title:e(`customize.assign.removeConfirm.title`),message:r?`${e(`customize.assign.removeConfirm.message`,{what:n})} ${e(`customize.assign.removeConfirm.last`)}`:e(`customize.assign.removeConfirm.message`,{what:n}),confirmLabel:e(`customize.assign.removeConfirm.confirm`),variant:`danger`})}e();function Jo(e){return e===null?null:bi(e,`replace`)?`replace`:bi(e,`add`)?`add`:null}function Yo({device:e,handle:t,availability:n,onAdvanced:i}){let{t:o}=X(),c=qo(),[l,u]=r(!1),[f,p]=r(null),m=ho(t.state),h=Ni(m,`battery`),g=Jo(h),_=g===null?null:pi(h?.fields.percentage),v=Go(_!==null);if(n.kind===`absent`)return null;let b=n.kind===`present`?n.mode:null,x=t.state.kind===`none`||t.state.kind===`present`,S=_===null||v.kind!==`known`?null:v.value.find(e=>G({addonId:e.addonId,stableId:e.stableId})===G(_.source))??null,C=_===null?``:S?.name??G(_.source),w=async e=>{let n=await t.save(e);p(n.kind===`refused`?n.reason:null)},T=async()=>{if(m===null)return;let e=li(m,`battery`);await c(o(`customize.battery.removeWhat`,{name:C}),e===null)&&await w(e)},E=b!==null&&x&&h===null&&!t.saving;return a(s,{children:[a(Bo,{id:`battery`,icon:y,title:o(`customize.battery.title`),addLabel:o(b===`replace`?`customize.battery.replace`:`customize.battery.add`),onAdd:E?()=>u(!0):void 0,notices:a(s,{children:[d(Vo,{availability:n}),_!==null&&v.kind===`unknown`&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:o(`customize.assign.devicesUnreadable`,{reason:v.reason})}),f!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:f})]}),children:[b===`replace`&&x&&d($,{name:o(`customize.battery.native`),detail:null,meta:o(h===null?`customize.assign.native`:`customize.battery.nativeReplaced`),value:h===null?{deviceId:e.id,cap:`battery`,path:`percentage`}:null,removeLabel:``}),h===null&&b===`add`&&x&&d(`li`,{className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:o(`customize.assign.none`)}),_!==null&&d($,{name:C,detail:`${_.cap}.${_.fieldPath}`,meta:o(g===`replace`?`customize.assign.replaces`:`customize.assign.adds`),value:S===null?null:{deviceId:S.id,cap:_.cap,path:_.fieldPath},problem:S===null&&v.kind===`known`?o(`customize.assign.missingKept`):void 0,onRemove:x?()=>void T():void 0,removeLabel:o(`customize.assign.removeNamed`,{name:C}),busy:t.saving}),h!==null&&_===null&&d($,{name:o(`customize.battery.otherFormula`),detail:null,meta:d(po,{onAdvanced:i}),value:{deviceId:e.id,cap:`battery`,path:`percentage`},removeLabel:``})]}),d(Oo,{open:l,title:o(b===`replace`?`customize.battery.replace`:`customize.battery.add`),targetKind:`number`,excludeDeviceIds:[e.id],confirmLabel:o(`customize.assign.add`),onConfirm:e=>{u(!1);let n=b===null?null:Ai({percentage:{source:e.ref,cap:e.cap,fieldPath:e.path,kind:e.kind},mode:b});n===null?p(o(`customize.assign.pickUnusable`)):w(fi(m,t.target,n))},onClose:()=>u(!1)})]})}var Xo=`consumables`,Zo=`items`,Qo=Ee.shape.items;function $o(e){let t=e.split(`.`).pop()??e,n=t.replace(/Level$/,``);return n===``?t:n}function es(e){let t=e.replace(/([a-z0-9])([A-Z])/g,`$1 $2`).toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)}function ts(e,t){return e.caps.filter(e=>t.has(e.cap)&&e.cap!==`consumables`).flatMap(e=>e.fields.filter(e=>e.item!==!0&&Pr(e)).map(t=>({kind:`field`,key:$o(t.path),cap:e.cap,path:t.path})))}function ns(e){switch(e.kind){case`pending`:return{kind:`pending`};case`unknown`:return{kind:`unknown`,reason:e.reason};case`absent`:return{kind:`known`,value:[]};case`value`:{if(e.value===null)return{kind:`known`,value:[]};let t=Qo.safeParse(e.value);return t.success?{kind:`known`,value:t.data.map(e=>({kind:`item`,key:e.key,item:e}))}:{kind:`unknown`,reason:t.error.message}}}}function rs(e,t,n){if(e.kind!==`known`)return e;if(t.kind!==`known`)return t;let r=ts(t.value,e.value);if(!e.value.has(`consumables`)||n===null)return{kind:`known`,value:r};let i=ns(n);return i.kind===`known`?{kind:`known`,value:[...r,...i.value]}:i}function is({deviceId:e,defaults:t}){return t.map(t=>t.kind===`field`?d(as,{deviceId:e,entry:t},`field:${t.cap}.${t.path}`):d(ss,{entry:t},`item:${t.key}`))}function as({deviceId:e,entry:t}){let{t:n}=X(),r=Fo({deviceId:e,cap:t.cap,path:t.path});return d($,{name:n(`customize.consumables.fields.${t.key}`,{defaultValue:es(t.key)}),detail:n(`customize.consumables.builtIn`),meta:n(`customize.assign.native`),value:null,readout:d(os,{value:r}),removeLabel:``})}function os({value:e}){switch(e.kind){case`pending`:return d(Ro,{display:{text:`…`,tone:`muted`}});case`unknown`:return d(Ro,{display:{text:`?`,title:e.reason,tone:`warning`}});case`absent`:return d(kn,{level:null,size:`sm`});case`value`:return d(kn,{level:In(e.value),size:`sm`})}}function ss({entry:e}){let{t}=X(),{item:n}=e,r=n.level===null?n.status===`replace`?t(`uiLibrary.consumablesPanel.replace`):void 0:`${Math.round(n.level)} %`;return d($,{name:n.label,detail:t(`customize.consumables.builtIn`),meta:t(`customize.assign.native`),value:null,readout:d(kn,{level:kr(n),label:r,size:`sm`}),removeLabel:``})}e();function cs(e,t){let n=e.source;if(n===null||t.kind!==`known`)return null;let r=G(n.source);return t.value.find(e=>G({addonId:e.addonId,stableId:e.stableId})===r)??null}function ls(e){let t=typeof e==`number`?e:typeof e==`string`?Number(e):NaN;return Number.isFinite(t)?t:null}function us({device:e,handle:t,availability:n,onAdvanced:i,defaults:o}){let{t:c}=X(),l=qo(),[u,f]=r(!1),[p,m]=r(``),[h,g]=r(`percent`),[_,v]=r(null),y=ho(t.state),b=Ni(y,`consumables`),x=vi(b),S=Go(x.some(e=>e.source!==null)),C=o.kind===`known`?o.value:[];if(n.kind===`absent`&&C.length===0&&o.kind!==`unknown`)return null;let w=t.state.kind===`none`||t.state.kind===`present`,T=n.kind===`present`&&w&&!t.saving,E=yi(p),D=x.find(e=>e.key===E)??null,k=D!==null,A=p.trim()!==``&&E===``,j=async e=>{let n=await t.save(e);v(n.kind===`refused`?n.reason:null)},M=()=>{f(!1),m(``),g(`percent`)},ee=async e=>{if(b===null||y===null)return;let n=ji(b,e.key),r=n===null?li(y,`consumables`):fi(y,t.target,n);await l(c(`customize.consumables.removeWhat`,{name:e.label}),r===null)&&await j(r)},N=a(`div`,{className:`flex flex-wrap items-end gap-2`,children:[a(`label`,{className:`flex w-full flex-col gap-1 text-[11px] text-foreground-subtle sm:w-56`,children:[c(`customize.consumables.name`),d(Jt,{"aria-label":c(`customize.consumables.name`),value:p,onChange:e=>m(e.target.value)})]}),a(`label`,{className:`flex w-full flex-col gap-1 text-[11px] text-foreground-subtle sm:w-40`,children:[c(`customize.consumables.unit`),d(gt,{"aria-label":c(`customize.consumables.unit`),value:h,options:Si.map(e=>({value:e,label:c(`customize.consumables.units.${e}`)})),onChange:e=>{let t=Si.find(t=>t===e.target.value);t!==void 0&&g(t)}})]}),k&&d(`p`,{role:`alert`,className:`basis-full text-xs text-warning`,children:c(`customize.consumables.takenBy`,{name:D.label})}),A&&d(`p`,{role:`alert`,className:`basis-full text-xs text-warning`,children:c(`customize.consumables.keyless`)})]});return a(s,{children:[a(Bo,{id:`consumables`,icon:O,title:c(`customize.consumables.title`),addLabel:c(`customize.consumables.add`),onAdd:T?()=>f(!0):void 0,notices:a(s,{children:[d(Vo,{availability:n}),S.kind===`unknown`&&x.some(e=>e.source!==null)&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:c(`customize.assign.devicesUnreadable`,{reason:S.reason})}),o.kind===`unknown`&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:c(`customize.consumables.builtInUnreadable`,{reason:o.reason})}),_!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:_})]}),children:[d(is,{deviceId:e.id,defaults:C}),x.map(e=>{let n=e.source;if(e.unit===null||n===null)return d($,{name:e.label,detail:c(`customize.consumables.otherFormula`),meta:d(po,{onAdvanced:i}),value:null,removeLabel:``},e.key);let r=cs(e,S),a=r?.name??G(n.source);return d($,{name:e.label,detail:`${c(`customize.consumables.units.${e.unit}`)} · ${a}`,meta:`${n.cap}.${n.fieldPath}`,value:r===null?null:{deviceId:r.id,cap:n.cap,path:n.fieldPath},problem:r===null&&S.kind===`known`?c(`customize.assign.missingKept`):void 0,onRemove:w?()=>void ee(e):void 0,removeLabel:c(`customize.assign.removeNamed`,{name:e.label}),busy:t.saving},e.key)}),x.length===0&&C.length===0&&o.kind===`known`&&n.kind===`present`&&w&&d(`li`,{className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:c(`customize.assign.none`)})]}),d(Oo,{open:u,title:c(`customize.consumables.pickTitle`),targetKind:`number`,excludeDeviceIds:[e.id],confirmLabel:c(`customize.assign.add`),extra:N,extraComplete:E!==``&&!k,onConfirm:e=>{let n=ls(e.value);if(n!==null&&(n<0||h===`percent`&&n>100)){M(),v(c(`customize.consumables.outOfRange`,{value:n}));return}let r=_i(b,{key:E,label:p,remaining:{source:e.ref,cap:e.cap,fieldPath:e.path,kind:e.kind},unit:h});M(),r===null?v(c(`customize.assign.pickUnusable`)):j(fi(y,t.target,r))},onClose:M})]})}function ds(e,t){if(e.kind!==`known`||typeof t!=`string`||t.length===0)return null;let n=gn(e.value,t),r=new Map(e.value.map(e=>[e.id,e])),i=new Map;for(let e of n){let t=r.get(e)?.parentDeviceId,n=t==null?void 0:r.get(t);n!==void 0&&n.type===`container`&&i.set(e,n.name)}return{location:t,ids:n,containers:i}}function fs(e,t,n){return ut(e,t?.ids??new Set,n)}function ps(e,t){return e?.containers.get(t)??null}function ms(e,t,n){return e.kind===`known`?fs(e.value,t,n).suggested.length:0}function hs(e,t){let n=[t,e.detail].filter(e=>e!==null&&e!==``);return n.length===0?null:n.join(` · `)}function gs({location:e,devices:t,action:n,onPick:r,onPickAll:i}){let{t:o}=X();if(t.length===0)return null;let s=o(`customize.suggest.heading`,{location:e});return a(`section`,{"aria-label":s,className:`flex flex-col gap-1`,children:[a(`div`,{className:`flex min-h-7 items-center gap-2`,children:[d(`h3`,{className:`${j} min-w-0 flex-1`,children:s}),i!==void 0&&t.length>1&&d(J,{variant:`ghost`,size:`sm`,onClick:i,children:o(`customize.suggest.addAll`,{count:t.length})})]}),d(`ul`,{className:`flex flex-col divide-y divide-border rounded-md border border-border`,children:t.map(e=>{let t=hs(e,e.container===null||e.name.includes(e.container)?null:o(`customize.suggest.in`,{container:e.container}));return a(`li`,{className:`${A} flex items-center gap-3`,children:[a(`div`,{className:`min-w-0 flex-1`,children:[d(`div`,{className:`text-xs text-foreground break-words`,children:e.name}),t!==null&&d(`div`,{className:`text-[11px] text-foreground-subtle break-words`,children:t})]}),d(J,{variant:`outline`,size:`sm`,"aria-label":o(n===`add`?`customize.suggest.addNamed`:`customize.suggest.useNamed`,{name:e.name}),onClick:()=>r(e.id),children:o(n===`add`?`customize.suggest.add`:`customize.suggest.use`)})]},e.id)})})]})}e();function _s(e){return e.kind===`pending`?`pending`:e.kind===`unknown`?`failed`:`answered`}function vs(e){return e.map(e=>({id:e.deviceId,name:e.name,...e.meta===null?{}:{type:e.meta},...e.detail===null?{}:{location:e.detail.includes(` · `)?e.detail.split(` · `).at(-1)??null:e.detail},...e.detail===null?{}:{detail:e.detail}}))}function ys({open:e,title:i,selection:o,candidates:s,filters:c,room:l=null,confirmLabel:u,onConfirm:f,onClose:p}){let{t:m}=X(),[h,g]=r(null),[_,v]=r([]),y=c?.find(e=>e.id===h)??c?.[0]??null,b=s.kind===`known`?s.value:[],x=s.kind===`known`?ta(s.value,``,y):[],S=fs(b,l,e=>e.deviceId).suggested,C=fs(x,l,e=>e.deviceId).others,w=n(()=>vs(C),[C]),T=_s(s),E=b.filter(e=>_.includes(e.deviceId));t(()=>{e||(v([]),g(null))},[e]);let D=()=>{v([]),g(null),p()},O=e=>{e.length!==0&&(f(e),v([]),g(null))},k=()=>O(E);return d(rn,{open:e,onOpenChange:e=>e?void 0:D(),children:a(Hn,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":i,children:[d(br,{children:d($n,{children:i})}),a(st,{className:`flex flex-col gap-2 p-2 sm:p-4`,children:[c!==void 0&&c.length>0&&d(`div`,{className:`flex flex-wrap gap-1`,role:`tablist`,"aria-label":m(`customize.assign.filtersLabel`),children:c.map(e=>d(`button`,{type:`button`,role:`tab`,"aria-selected":(y?.id??null)===e.id,className:`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${(y?.id??null)===e.id?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover`}`,onClick:()=>g(e.id),children:m(e.labelKey)},e.id))}),l!==null&&d(gs,{location:l.location,devices:S.map(e=>({id:e.deviceId,name:e.name,container:ps(l,e.deviceId),detail:e.detail})),action:`add`,onPick:e=>O(S.filter(t=>t.deviceId===e)),...o===`multi`?{onPickAll:()=>O(S)}:{}}),s.kind===`unknown`?d(`p`,{role:`alert`,className:`text-xs text-warning`,children:m(`customize.assign.unknown`,{reason:s.reason})}):w.length===0&&S.length>0?null:d(_t,{devices:w,listState:T,value:_,onChange:e=>v(o===`single`?e.length>0?[e[e.length-1]]:[]:e),noun:`device`,emptyLabel:m(`customize.assign.none`),showAll:!0,testId:`customize-device-picker`})]}),a(ur,{children:[d(J,{variant:`ghost`,onClick:D,children:m(`customize.picker.cancel`)}),d(J,{disabled:E.length===0,onClick:k,children:u(E.length)})]})]})})}function bs(e){if(e===null)return[];let t=Ci(e);return Ei(e).map(e=>{let n=G(e);return{key:n,ref:e,caps:t.filter(e=>G(e.source)===n).map(e=>e.cap)}})}function xs(e,t){let n=Ci(e);if(n.length===0)return!1;let{enabled:r,...i}=e,{enabled:a,...o}=Ne({camera:t,sources:n,enabled:!0});return Mi(i,o)}function Ss(e){return e?.enabled!==!1}function Cs(e,t,n){let r=[...e===null?[]:Ci(e),...n.flatMap(e=>qe(e.ref,e.caps))];return r.length===0?null:Ne({camera:t,sources:r,enabled:Ss(e)})}function ws(e,t,n){let r=Ci(e).filter(e=>G(e.source)!==n);return r.length===0?null:Ne({camera:t,sources:r,enabled:Ss(e)})}function Ts(e,t){return{...e,enabled:t}}e();function Es({device:e,handle:t,availability:n,onAdvanced:i}){let{t:o}=X(),c=qo(),[l,u]=r(!1),[f,p]=r(null),m=ho(t.state),h=Ni(m,`doorbell`),g=h===null||xs(h,t.target),_=g?bs(h):[],v=Go(_.length>0),y=Ko({hostId:e.id,excludeCameras:!1,assigned:new Set(_.map(e=>e.key)),preferredCap:null,enabled:l});if(n.kind===`absent`)return null;let b=t.state.kind===`none`||t.state.kind===`present`,x=b&&!t.saving,S=n.kind===`present`&&x&&g,C=async e=>{let n=e===null?m===null?null:li(m,`doorbell`):fi(m,t.target,e),r=await t.save(n);p(r.kind===`refused`?r.reason:null)},w=async(e,n)=>{if(h===null||m===null)return;let r=ws(h,t.target,e.key),i=r===null&&li(m,`doorbell`)===null;await c(o(`customize.doorbell.removeWhat`,{name:n}),i)&&await C(r)},T=e=>v.kind===`known`?v.value.find(t=>G({addonId:t.addonId,stableId:t.stableId})===e.key)??null:null;return a(s,{children:[a(Bo,{id:`doorbell`,icon:ge,title:o(`customize.doorbell.title`),headerControl:h===null?void 0:a(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground`,children:[d(Kt,{"aria-label":o(`customize.doorbell.active`),checked:h.enabled!==!1,disabled:!x,onChange:e=>void C(Ts(h,e.target.checked))}),o(`customize.doorbell.active`)]}),addLabel:o(`customize.doorbell.add`),onAdd:S?()=>u(!0):void 0,notices:a(s,{children:[d(Vo,{availability:n}),v.kind===`unknown`&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:o(`customize.assign.devicesUnreadable`,{reason:v.reason})}),f!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:f})]}),children:[_.map(e=>{let n=T(e),r=n?.name??e.key,i=na(e.caps,null),a=i===null?void 0:Ge[i];return d($,{name:r,detail:n===null?null:ia(n.integration,n.location),meta:e.caps.join(`, `),value:n!==null&&i!==null&&a!==void 0?{deviceId:n.id,cap:i,path:a}:null,problem:n===null&&v.kind===`known`?o(`customize.assign.missingKept`):void 0,onRemove:b?()=>void w(e,r):void 0,removeLabel:o(`customize.assign.removeNamed`,{name:r}),busy:t.saving},e.key)}),!g&&d($,{name:o(`customize.doorbell.otherFormula`),detail:null,meta:d(po,{onAdvanced:i}),value:null,removeLabel:``}),h===null&&n.kind===`present`&&b&&d(`li`,{className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:o(`customize.assign.none`)})]}),d(ys,{open:l,title:o(`customize.doorbell.pickTitle`),selection:`multi`,candidates:y,confirmLabel:e=>o(`customize.assign.addCount`,{count:e}),onConfirm:e=>{u(!1),C(Cs(h,t.target,e.map(e=>({ref:e.ref,caps:e.caps}))))},onClose:()=>u(!1)})]})}e();function Ds(e,t){let r=typeof e==`string`&&e.length>0,i=Go(t&&r);return n(()=>t?ds(i,e):null,[t,i,e])}e();function Os(e){return e==null?null:e.message}function ks({device:e}){let t=ne(),{t:n}=X(),i=c(),o=qo(),l=Ve.includes(e.type),[u,f]=r(!1),[p,m]=r(!1),[h,g]=r(null),_=dt({deviceId:e.id},{enabled:l}),v=ca({status:_.status,data:_.data,error:Os(_.error)===null?null:{message:Os(_.error)??``}}),y=v.kind===`present`?v.slot.slotRef:``,b=v.kind===`present`?[...aa(v.slot,v.value).map(e=>e.deviceId),...ra(v.slot,v.value)]:[],x=Ar(),S=Go(l&&v.kind===`present`&&(u||b.length>0)),C=Ds(e.location,l&&v.kind===`present`),w=un({deviceId:e.id,slotRef:y},{enabled:(u||C!==null)&&v.kind===`present`});if(!l||v.kind===`absent`)return null;if(v.kind!==`present`)return d(Bo,{id:`linked`,icon:ae,title:n(`customize.linked.title`),notices:v.kind===`pending`?d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:n(`customize.assign.checking`)}):d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:n(`customize.assign.unknown`,{reason:v.reason})}),children:null});let T=v.value,E=new Map(S.kind===`known`?S.value.map(e=>[e.id,e]):[]),D=T.trackedDeviceIds!==void 0,O=(e,t)=>{let n=E.get(e.deviceId);return{...e,name:e.name??n?.name??null,type:n?.type??null,detail:n===void 0?null:ia(n.integration,n.location),orphan:t}},k=[...aa(v.slot,T).map(e=>O(e,!1)),...ra(v.slot,T).map(e=>O({deviceId:e,name:null,health:`ok`,implied:!1,tracked:!0},!0))],A=new Set(b),j=S.kind===`unknown`?S:w.status===`error`?{kind:`unknown`,reason:Os(w.error)??n(`helpers.customize.requestFailed`)}:S.kind===`pending`||w.status===`pending`||w.data===void 0?{kind:`pending`}:{kind:`known`,value:ua(w.data.candidates,E,A)},M=async t=>{if(p){g(n(`customize.saveInFlight`));return}m(!0),g(null);try{await x.mutateAsync({deviceId:e.id,slotRef:v.slot.slotRef,value:t}),await _.refetch(),await i.invalidateQueries({queryKey:[[`deviceManager`]]})}catch(e){g(e instanceof Error?e.message:String(e))}finally{m(!1)}},ee=async e=>{await o(n(`customize.linked.removeWhat`,{name:e.name??`#${e.deviceId}`}),!1)&&await M(la(T,e.deviceId))},N=[{key:`device`,header:n(`customize.linked.device`),cell:e=>a(`div`,{className:`flex flex-col min-w-0`,children:[d(`span`,{className:`truncate text-xs text-foreground`,children:e.name??`#${e.deviceId}`}),e.detail!==null&&d(`span`,{className:`truncate text-[11px] text-foreground-subtle`,children:e.detail}),e.orphan&&d(`span`,{className:`text-[11px] text-foreground-subtle`,children:n(`customize.linked.notLinked`)}),e.health!==`ok`&&d(`span`,{role:`alert`,className:`text-[11px] text-warning`,children:n(`customize.linked.health.${e.health}`)})]})},{key:`type`,header:n(`customize.linked.type`),headerClassName:`hidden sm:table-cell`,cellClassName:`hidden sm:table-cell text-xs text-foreground-subtle`,cell:e=>e.type===null?`—`:Vt(e.type,t).label},{key:`controls`,header:n(`customize.linked.controls`),headerClassName:`hidden md:table-cell`,cellClassName:`hidden md:table-cell text-xs text-foreground-subtle`,cell:e=>e.orphan?`—`:n(`customize.linked.yes`)},...D?[{key:`tracked`,header:n(`customize.linked.tracked`),cellClassName:`text-right`,headerClassName:`text-right`,cell:e=>d(er,{checked:e.tracked,disabled:p,"aria-label":n(`customize.linked.trackFor`,{name:e.name??e.deviceId}),onCheckedChange:t=>void M(oa(T,e.deviceId,t))})}]:[],{key:`remove`,header:``,cellClassName:`text-right w-10`,cell:e=>e.implied||e.orphan?null:d(Qt,{icon:B,variant:`ghost`,size:`sm`,"aria-label":n(`customize.assign.removeNamed`,{name:e.name??e.deviceId}),disabled:p,onClick:t=>{t.stopPropagation(),ee(e)}})}];return a(s,{children:[d(Bo,{id:`linked`,icon:ae,title:n(`customize.linked.title`),addLabel:n(`customize.linked.add`),onAdd:p?void 0:()=>f(!0),...C===null?{}:{suggestion:{count:ms(j,C,e=>e.deviceId),location:C.location,onOpen:()=>f(!0)}},notices:a(s,{children:[S.kind===`unknown`&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:n(`customize.assign.devicesUnreadable`,{reason:S.reason})}),h!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:h})]}),children:a(`li`,{className:`list-none px-3 py-2 sm:px-4`,children:[k.length===0?d(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`customize.assign.none`)}):d(ht,{mode:`generic`,items:k,getKey:e=>String(e.deviceId),getSearchText:e=>[e.name??``,e.detail??``,e.type??``,String(e.deviceId)].join(` `),getFilterType:e=>e.type===null?null:Vt(e.type,t).label,columns:N,searchPlaceholder:n(`customize.assign.search`),emptyLabel:n(`customize.assign.none`)}),k.some(e=>!e.orphan)&&d(`p`,{className:`mt-2 text-[10px] text-foreground-subtle`,children:n(`customize.linked.controlsAlways`)}),D&&d(`p`,{className:`mt-0.5 text-[10px] text-foreground-subtle`,children:n(`customize.linked.trackedHint`)})]})}),d(ys,{open:u,title:n(`customize.linked.pickTitle`),selection:`multi`,candidates:j,room:C,confirmLabel:e=>n(`customize.assign.addCount`,{count:e}),onConfirm:e=>{f(!1),M($i(T,e.map(e=>e.deviceId)))},onClose:()=>f(!1)})]})}function As(e){return e===null||e.state===`unreadable`?null:e.state===`configured`?e.sensors:[]}function js(e){return{addonId:e.addonId,stableId:e.stableId,mode:e.mode}}function Ms(e){return e.length===0?null:{sensors:[...e]}}function Ns(e,t){let n=new Set(e.map(De));return Ms([...e.map(js),...t.filter(e=>!n.has(De(e))).map(e=>({...e,mode:je}))])}function Ps(e,t,n){return Ms(e.map(e=>De(e)===t?{...js(e),mode:n}:js(e)))}function Fs(e,t){return Ms(e.filter(e=>De(e)!==t).map(js))}function Is(e){return e?.state===`configured`&&e.cameraMotion!==void 0}function Ls(e){return e===null||e.state===`unreadable`?null:e.state===`configured`?e.cameraMotion??`always`:`always`}function Rs(e){return e===null||e.state===`unreadable`?!1:e.state===`not-configured`||Is(e)}function zs(e){return e?.state===`configured`&&(e.notForwarded!==void 0||e.notEnforced!==void 0)}function Bs(e,t,n){if(e!==`present`||t===null||n)return{kind:`none`};let r=t.cameraLevel;return r===void 0?{kind:`unknown`}:{kind:`level`,detected:r.detected,atMs:r.atMs}}e();var Vs=5e3;function Hs(e){return e.state===`missing`||e.state===`unreadable`?e.stableId:e.name}function Us({device:e,availability:n,sensors:i}){let{t:o}=X(),c=qo(),u=tn(),[f,p]=r(!1),[m,h]=r(null),g=l(!1),[_,v]=r(!1),[y,b]=r(!1),x=i.status,S=l(i.refetch);S.current=i.refetch,t(()=>{let e=setInterval(()=>{g.current||S.current()},Vs);return()=>clearInterval(e)},[]);let C=As(x);t(()=>{x!==null&&b(!1)},[x]);let w=i.presence===`present`&&Rs(x)&&!y?C:null,T=Go(C!==null&&C.length>0),E=Ko({hostId:e.id,excludeCameras:!0,assigned:new Set((C??[]).map(De)),preferredCap:`motion`,enabled:f});if(n.kind===`absent`)return null;let D=Is(x),O=zs(x)?`passes`:Ls(x),k=Bs(i.presence,x,y),A=k.kind===`none`?null:k.kind===`unknown`?{text:`?`,tone:`warning`,title:o(`customize.motion.cameraLevelUnknown`)}:{text:o(k.detected?`customize.assign.value.active`:`customize.assign.value.inactive`),tone:k.detected?`active`:`muted`,title:o(`customize.motion.cameraLevelOwn`,{at:new Date(k.atMs).toLocaleTimeString()})},j=_||u.isPending,M=async t=>{if(g.current){h(o(`customize.saveInFlight`));return}g.current=!0,v(!0);try{await u.mutateAsync({deviceId:e.id,config:t}),h(null),await i.refetch()===`failed`&&b(!0)}catch(e){h(e instanceof Error?e.message:String(e))}finally{g.current=!1,v(!1)}},ee=async e=>{w!==null&&await c(o(`customize.motion.removeWhat`,{name:Hs(e)}),!1)&&await M(Fs(w,De(e)))},N=e=>{if(T.kind!==`known`||!(`deviceId`in e))return null;let t=T.value.find(t=>t.id===e.deviceId);return t===void 0?null:ia(t.integration,t.location)};return a(s,{children:[a(Bo,{id:`motion`,icon:H,title:o(`customize.motion.title`),addLabel:o(`customize.motion.add`),onAdd:w!==null&&n.kind===`present`?()=>p(!0):void 0,addDisabled:j,notices:a(s,{children:[d(Vo,{availability:n}),i.presence===`pending`&&n.kind!==`pending`&&d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:o(`customize.motion.reading`)}),x?.state===`unreadable`&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:o(`customize.motion.unreadable`,{reason:x.reason})}),x?.state===`configured`&&!Rs(x)&&d(`p`,{role:`alert`,className:`text-xs text-warning`,children:o(`customize.motion.olderOrchestrator`)}),y&&d(`p`,{role:`alert`,className:`text-xs text-warning`,children:o(`customize.motion.refetchFailed`)}),x?.state===`configured`&&x.notForwarded!==void 0&&d(`p`,{role:`alert`,className:`text-xs text-warning`,children:o(`customize.motion.notForwarded.${x.notForwarded}`)}),x?.state===`configured`&&x.notEnforced!==void 0&&d(`p`,{role:`alert`,className:`text-xs text-warning`,children:o(`customize.motion.notEnforced`)}),T.kind===`unknown`&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:o(`customize.assign.devicesUnreadable`,{reason:T.reason})}),m!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:m})]}),children:[d($,{name:o(`customize.motion.camera`),detail:null,meta:O===null?o(`customize.assign.native`):`${o(`customize.motion.cameraState.${O}`)} · ${o(`customize.assign.native`)}`,value:null,shown:A,removeLabel:``}),(C??[]).map(e=>{let t=De(e),n=Hs(e),r=e.state===`ready`?na(e.caps,`motion`):null,i=r===null?void 0:Ge[r];return d($,{name:n,detail:N(e),meta:D&&w!==null?d(gt,{"aria-label":o(`customize.motion.modeFor`,{name:n}),value:e.mode,disabled:j,options:Ae.options.map(e=>({value:e,label:o(`customize.motion.mode.${e}`)})),onChange:e=>{let n=Ae.safeParse(e.target.value);n.success&&w!==null&&M(Ps(w,t,n.data))}}):o(`customize.motion.mode.${e.mode}`),value:r!==null&&i!==void 0&&`deviceId`in e?{deviceId:e.deviceId,cap:r,path:i}:null,problem:e.state===`ready`?void 0:e.reason===e.state?o(`customize.motion.state.${e.state}`):`${o(`customize.motion.state.${e.state}`)}: ${e.reason}`,onRemove:w===null?void 0:()=>void ee(e),removeLabel:o(`customize.assign.removeNamed`,{name:n}),busy:j},t)})]}),d(ys,{open:f,title:o(`customize.motion.pickTitle`),selection:`multi`,candidates:E,filters:ea,confirmLabel:e=>o(`customize.assign.addCount`,{count:e}),onConfirm:e=>{if(p(!1),w===null)return;let t=Ns(w,e.map(e=>e.ref));if(t!==null&&t.sensors.length>8){h(o(`customize.motion.tooMany`,{max:8}));return}M(t)},onClose:()=>p(!1)})]})}var Ws={"numeric-sensor":{fieldPath:`value`,unitField:`unit`},"temperature-sensor":{fieldPath:`celsius`,unitField:`unit`},"humidity-sensor":{fieldPath:`percent`,unitField:`unit`},"pressure-sensor":{fieldPath:`hpa`,unitField:`unit`},"ambient-light-sensor":{fieldPath:`lux`,unitField:`unit`}},Gs=new Set([q.Camera]);function Ks(e){return e.unitField===null?[e.fieldPath]:[e.fieldPath,e.unitField]}function qs(e,t){if(Gs.has(e))return{kind:`absent`};let n=null;for(let[e,r]of Object.entries(Ws))if(t.has(e)){n={cap:e,fieldPath:r.fieldPath,unitField:r.unitField};break}let r=null;for(let e of Be)if(t.has(e)){let t=Ge[e];if(t!==void 0){r={cap:e,fieldPath:t};break}}return n===null&&r===null?{kind:`absent`}:{kind:`present`,convert:n,invert:r}}function Js(e){return Je(e.from,e.to)?Re(e):null}function Ys(e){return Ie(e)}var Xs=/^convert\(v,\s*"[^"]*",\s*"[^"]*"\)$/;function Zs(e){return e!==void 0&&Xs.test(e.expr)}function Qs(e){return e===void 0||e.expr===`!v`||Xs.test(e.expr)?!1:e.bindings.v!==void 0}function $s(e){let t=e.expr.trim();if(t===``)return{kind:`refused`,reason:Y.t(`helpers.numericTransforms.emptyExpression`)};let n={kind:`expression`,expr:t,bindings:{v:{kind:`from`,source:e.self,cap:e.cap,fieldPath:e.fieldPath}}},r=ve({source:n,now:Date.now(),read:()=>({state:`fresh`,value:e.probe})});return r.state===`unavailable`?{kind:`refused`,reason:r.reason}:{kind:`ok`,feature:{kind:`fields`,cap:e.cap,fields:{[e.fieldPath]:n}}}}function ec(e,t,n){if(e===null)return null;let r=Ni(e,n.cap);if(r===null)return e;let i=new Set(Ks(n)),a=Object.fromEntries(Object.entries(r.fields).filter(([e])=>!i.has(e)));return Object.keys(a).length===0?li(e,n.cap):fi(e,t,{kind:`fields`,cap:n.cap,...r.enabled===void 0?{}:{enabled:r.enabled},fields:a,...r.items===void 0?{}:{items:r.items}})}e();function tc(e){if(typeof e!=`object`||!e)return;let t=Reflect.get(e,`unit`);return typeof t==`string`?t:void 0}function nc(e,t){if(typeof e!=`object`||!e)return;let n=Reflect.get(e,t);return typeof n==`number`&&Number.isFinite(n)?n:void 0}function rc(e,t){let n=Ni(e,t.cap);if(n===null)return;let r=n.fields[t.fieldPath];return r!==void 0&&r.kind===`expression`?r:void 0}function ic(e,t){let n=rc(e,t);return n===void 0||!Zs(n)?null:/^convert\(v,\s*"[^"]*",\s*"([^"]*)"\)$/.exec(n.expr)?.[1]??null}function ac(e,t){let n=rc(e,t);return n===void 0||!Qs(n)?null:n.expr}function oc(e,t,n){let r=Ni(e,t);if(r===null)return!1;let i=r.fields[n];return i!==void 0&&i.kind===`expression`&&i.expr===`!v`}function sc(e){return typeof e==`number`||typeof e==`boolean`||typeof e==`string`?String(e):e===null?`null`:JSON.stringify(e)}function cc({device:e,target:t,handle:n,facts:i}){let{t:o}=X(),s=U(),[c,l]=r(null),[u,f]=r(``),[p,m]=r(null),g=i.nativeCaps.kind===`known`?i.nativeCaps.value:null,_=g===null?null:qs(e.type,g),v=_?.kind===`present`?_.convert?.cap??``:``,y=xr(s.trpcClient,e.id,v);if(i.nativeCaps.kind===`pending`)return d(`section`,{className:`${T} ${h}`,children:d(Vo,{availability:{kind:`pending`}})});if(i.nativeCaps.kind===`unknown`)return d(`section`,{className:`${T} ${h}`,children:d(Vo,{availability:{kind:`unknown`,reason:i.nativeCaps.reason}})});if(_===null||_.kind===`absent`)return null;let b=ho(n.state),x=_.convert,S=_.invert,C=x===null?void 0:tc(y),w=C===void 0?void 0:ye(C)??C,E=w===void 0?void 0:be(w),D=x===null?null:ic(b,x),O=x===null?null:ac(b,x),k=p??O??``,A=S===null?!1:oc(b,S.cap,S.fieldPath),j=n.state.kind===`none`||n.state.kind===`present`,M=x===null?0:nc(y,x.fieldPath)??0,ee=x!==null&&k.trim()!==``?{kind:`expression`,expr:k.trim(),bindings:{v:{kind:`from`,source:t,cap:x.cap,fieldPath:x.fieldPath}}}:null,N=ee===null||x===null?null:wi(ee,new Map([[Se(t,x.cap),y===void 0?{kind:`pending`}:{kind:`value`,slice:y}]]),Date.now()),P=async e=>{let t=await n.save(e);l(t.kind===`refused`?t.reason:null)},F=async()=>{if(x===null||w===void 0||u===``)return;let e=Js({self:t,cap:x.cap,fieldPath:x.fieldPath,from:w,to:u,unitField:x.unitField});if(e===null){l(o(`customize.numericTransforms.convertRefused`));return}m(null),await P(fi(b,t,e))},te=async()=>{x!==null&&(await P(ec(b,t,x)),f(``))},I=async()=>{if(x===null)return;let e=$s({self:t,cap:x.cap,fieldPath:x.fieldPath,expr:k,probe:M});if(e.kind===`refused`){l(e.reason);return}f(``),await P(fi(b,t,e.feature))},L=async()=>{x!==null&&(await P(ec(b,t,x)),m(``))},R=async()=>{if(S===null)return;let e=Ys({self:t,cap:S.cap});if(e===null){l(o(`customize.numericTransforms.invertRefused`));return}await P(fi(b,t,e))},ne=async()=>{S===null||b===null||await P(li(b,S.cap))};return d(zo,{id:`numeric-transforms`,icon:Ze,title:o(`customize.numericTransforms.title`),testId:`numeric-transforms-card`,children:a(`div`,{className:`${h} flex flex-col gap-3`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`customize.numericTransforms.blurb`)}),c!==null&&d(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:c}),x!==null&&a(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-convert`,children:[d(`label`,{className:`text-[11px] font-medium text-foreground`,children:o(`customize.numericTransforms.publishUnit`)}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:w===void 0?o(`customize.numericTransforms.fromUnknown`):o(`customize.numericTransforms.fromUnit`,{unit:w})}),d(`div`,{className:`w-full sm:max-w-xs`,children:d(Yt,{dimension:E,value:u===``?D??``:u,onChange:e=>{f(e),e!==``&&m(``)},disabled:!j||n.saving||w===void 0,"aria-label":o(`customize.numericTransforms.toUnit`),inheritLabel:o(`customize.numericTransforms.pickUnit`),emptyReason:o(`customize.numericTransforms.fromUnknown`)})}),a(`div`,{className:`flex flex-wrap gap-2`,children:[d(J,{size:`sm`,disabled:!j||n.saving||w===void 0||u===``||u===w,onClick:()=>void F(),children:o(`customize.numericTransforms.applyConvert`)}),D!==null&&d(J,{size:`sm`,variant:`outline`,disabled:!j||n.saving,onClick:()=>void te(),children:o(`customize.numericTransforms.clearConvert`)})]})]}),x!==null&&a(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-script`,children:[d(Di,{label:o(`customize.numericTransforms.script`),value:k,bindings:[`v`],onChange:e=>{m(e),e.trim()!==``&&f(``)}}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`customize.numericTransforms.scriptBlurb`)}),N!==null&&d(`p`,{role:`status`,className:`text-[11px] font-mono text-foreground`,"data-testid":`numeric-script-preview`,children:N.kind===`value`?o(`customize.numericTransforms.preview`,{source:sc(M),result:sc(N.value)}):N.kind===`waiting`?o(`customize.numericTransforms.previewWaiting`):N.kind===`unavailable`?o(`customize.numericTransforms.previewError`,{reason:N.reason}):o(`customize.numericTransforms.previewRuntimeOnly`)}),a(`div`,{className:`flex flex-wrap gap-2`,children:[d(J,{size:`sm`,disabled:!j||n.saving||k.trim()===``,onClick:()=>void I(),children:o(`customize.numericTransforms.applyScript`)}),O!==null&&d(J,{size:`sm`,variant:`outline`,disabled:!j||n.saving,onClick:()=>void L(),children:o(`customize.numericTransforms.clearScript`)})]})]}),S!==null&&a(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-invert`,children:[d(`label`,{className:`text-[11px] font-medium text-foreground`,children:o(`customize.numericTransforms.invert`)}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`customize.numericTransforms.invertBlurb`)}),d(`div`,{className:`flex flex-wrap gap-2`,children:A?d(J,{size:`sm`,variant:`outline`,disabled:!j||n.saving,onClick:()=>void ne(),children:o(`customize.numericTransforms.clearInvert`)}):d(J,{size:`sm`,disabled:!j||n.saving,onClick:()=>void R(),children:o(`customize.numericTransforms.applyInvert`)})})]})]})})}e();function lc(e){return e instanceof Error?e.message:String(e)}function uc(e){let t=Tr({addonId:e.addonId,stableId:e.stableId}),n=jn(),i=qn(),a=pr(),o=mo({status:t.status,data:t.data,error:t.error===null||t.error===void 0?null:{message:t.error.message}}),{t:s}=X(),c=l(!1),[u,d]=r(!1),f=async e=>{let r=hi(o,e);try{switch(r.kind){case`refused`:return{kind:`refused`,reason:r.reason};case`noop`:return{kind:`saved`};case`create`:await n.mutateAsync({block:r.input});break;case`update`:await i.mutateAsync({blockId:r.blockId,expectedUpdatedAt:r.expectedUpdatedAt,block:{composition:r.composition}});break;case`delete`:await a.mutateAsync({blockId:r.blockId});break}return await t.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:lc(e)}}};return{target:e,state:o,saving:u||n.isPending||i.isPending||a.isPending,save:async e=>{if(c.current)return{kind:`refused`,reason:s(`customize.saveInFlight`)};c.current=!0,d(!0);try{return await f(e)}finally{c.current=!1,d(!1)}}}}var dc=`pipeline-orchestrator`;function fc(e){return e.status===`pending`?`pending`:e.status===`error`?`unknown`:e.data===void 0?`pending`:e.data.cameraSensors===void 0?`absent`:`present`}function pc(e,t){return e===`absent`?`absent`:fc(t)}async function mc(e){try{return(await e()).isError?`failed`:`answered`}catch{return`failed`}}function hc(e,t){let n=Yn(dc),r=Vn({deviceId:e},{enabled:t&&n!==`absent`}),i=()=>mc(r.refetch);return t?{presence:pc(n,{status:r.status,data:r.data}),status:r.data?.cameraSensors??null,refetch:i}:{presence:`absent`,status:null,refetch:i}}function gc(e,t){let n=Bn({deviceType:e.type}),r=Tt({deviceId:e.id}),i=Pt({deviceId:e.id}),a=Ho(n,e=>new Set(e.caps.map(e=>e.cap))),o=Ho(r,e=>so(e.entries)),s=Ho(i,e=>e);return{deviceType:e.type,composable:a,nativeCaps:o,wireable:s,composed:new Set((t?.features??[]).map(e=>e.cap))}}function _c(e,t,n){let r=t.kind===`known`&&t.value.has(`consumables`),i=Fo(r?{deviceId:e,cap:Xo,path:Zo}:null);return rs(t,n,r?i:null)}function vc(){return{kind:`unknown`,reason:Y.t(`helpers.fieldsTableRows.noValue`)}}function yc(e,t){let n=G(e);return t.get(n)??n}function bc(e,t,n){let r=n.nativeCaps.has(e.cap)?`replaced`:`added`,i=t.filter(t=>t.cap===e.cap&&t.origin===`composed`);if(e.cap===`doorbell`){let t=Ei(e).map(e=>yc(e,n.sourceNames)).join(` + `),a=i.find(e=>e.field===`lastPressedAt`);return[{key:`doorbell`,label:Y.t(`helpers.whatChangesRows.doorbell`),origin:{kind:r,from:t},value:a?.value??vc()}]}return e.cap===`consumables`?vi(e).map(e=>{let t=t=>ke(Oe,e.key,t),a=i.find(e=>e.field===t(`level`)||e.field===t(`remaining.value`)),o=e.source===null?``:yc(e.source.source,n.sourceNames);return{key:`consumables.${e.key}`,label:Y.t(`helpers.whatChangesRows.consumable`,{name:e.label}),origin:{kind:r,from:o},value:a?.value??vc()}}):i.map(e=>({key:e.key,label:`${e.cap}.${e.field}`,origin:{kind:r,from:e.from},value:e.value}))}function xc(e){let t=xi({composition:e.composition,nativeCaps:e.nativeCaps,state:e.state,nativeFields:new Map,snapshot:null,sourceNames:e.sourceNames});return e.composition.features.flatMap(n=>n.kind===`fields`?bc(n,t,e):[])}function Sc(e,t){if(e?.state!==`configured`||e.sensors.length===0)return null;let n=e.cameraMotion===`never`?[]:[t.camera],r=e.sensors.map(e=>t.sensor(e.state===`missing`||e.state===`unreadable`?e.stableId:e.name,e.mode));return[...n,...r].join(` + `)}var Cc=`${A} grid grid-cols-1 gap-x-3 gap-y-0.5 items-baseline sm:grid-cols-[minmax(0,1fr)_minmax(0,2fr)_minmax(0,1.5fr)]`,wc=`font-mono text-[11px] text-foreground break-words`,Tc=`text-[11px] text-foreground-subtle break-words`,Ec=`text-[11px] break-words sm:text-right`;function Dc({device:e,composition:t,state:n,nativeCaps:r,cameraSensors:i}){let{t:o}=X(),s=t!==null&&n!==null,c=Go(s),l=new Map(c.kind===`known`?c.value.map(e=>[G({addonId:e.addonId,stableId:e.stableId}),e.name]):[]),u=s&&r.kind===`known`?xc({composition:t,nativeCaps:r.value,state:n,sourceNames:l}):[],f=s&&r.kind===`known`&&u.length===0&&t.features.length>0,p=Sc(i,{camera:o(`customize.changes.motion.camera`),sensor:(e,t)=>o(`customize.changes.motion.${t}`,{name:e})}),m=s&&r.kind!==`known`;return u.length===0&&p===null&&!m&&!f?null:a(zo,{id:`changes`,icon:z,title:o(`customize.changes.title`),children:[m&&d(`p`,{role:r.kind===`unknown`?`alert`:`status`,className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:r.kind===`unknown`?o(`customize.changes.unknown`,{reason:r.reason}):o(`customize.changes.reading`)}),f&&d(`p`,{className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:o(`customize.changes.noRows`)}),a(`ul`,{className:`divide-y divide-border`,children:[u.map(e=>a(`li`,{className:Cc,children:[d(`span`,{className:wc,children:e.label}),d(`span`,{className:Tc,children:c.kind===`known`?o(`customize.changes.origin.${e.origin.kind}`,{from:e.origin.from}):o(`customize.changes.originUnread.${c.kind}`,{kind:o(`customize.changes.kind.${e.origin.kind}`),reason:c.kind===`unknown`?c.reason:``})}),d(`span`,{className:Ec,children:d(Oc,{value:e.value})})]},e.key)),p!==null&&a(`li`,{className:Cc,children:[d(`span`,{className:wc,children:o(`common.motionWord`)}),d(`span`,{className:Tc,children:p}),d(`span`,{className:Ec,children:d(Lo,{target:{deviceId:e.id,cap:`motion`,path:`detected`}})})]})]})]})}function Oc({value:e}){let{t}=X();switch(e.kind){case`value`:return a(`span`,{children:[Ti(e.value,!0),e.staleReason!==null&&a(`span`,{className:`text-warning`,children:[` `,`·`,` `,t(`customize.changes.value.stale`,{reason:e.staleReason})]})]});case`unavailable`:return d(`span`,{className:`text-warning`,children:t(`customize.changes.value.unavailable`,{reason:e.reason})});case`unknown`:return d(`span`,{className:`text-foreground-subtle`,children:t(`customize.changes.value.unknown`,{reason:e.reason})});case`off`:return d(`span`,{className:`text-foreground-subtle`,children:t(`customize.status.off`)})}}e();function kc({deviceId:e,activeSubTab:t,onSubTabChange:n}){let{t:r}=X(),i=Ct({deviceId:e}),a=i.data;return a==null?i.status===`error`?d(Kn,{title:r(`customize.deviceUnreadable`),message:i.error?.message??``,onRetry:()=>void i.refetch()}):a===null?d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.noSuchDevice`,{deviceId:e})}):d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.loadingDevice`)}):a.addonId===`composer`?d(Ac,{device:a}):d(jc,{device:a,target:{addonId:a.addonId,stableId:a.stableId},activeSubTab:t,onSubTabChange:n})}function Ac({device:e}){let{t}=X(),n=e.stableId.startsWith(`composed-`)?e.stableId.slice(we.length):null;return a(`section`,{className:`${T} ${h} flex flex-col gap-2`,children:[d(`p`,{className:`text-xs text-foreground`,children:t(`customize.composed.body`)}),n!==null&&d(Jr,{className:`text-[11px] text-primary hover:underline`,to:ni(n),children:t(`customize.composed.edit`)})]})}function jc({device:e,target:t,activeSubTab:n,onSubTabChange:r}){let i=uc(t),o=Yn(`composer`),{t:s}=X(),c=hc(e.id,e.type===q.Camera),l=gc(e,ho(i.state)),u=_c(e.id,l.nativeCaps,l.wireable),f={deviceType:e.type,composable:l.composable,nativeCaps:l.nativeCaps,cameraSensors:c.presence},p=()=>r(oi),m=i.state.kind===`none`||i.state.kind===`present`;return n===`advanced`?a(`div`,{className:`flex flex-col gap-3`,children:[d(Nc,{state:i.state}),m&&d(Mc,{device:e,target:t,handle:i,facts:l,onDone:()=>r(`main`)})]}):a(`div`,{className:`flex flex-col gap-3`,children:[d(wo,{device:e}),o===`absent`&&d(`p`,{role:`alert`,className:`text-xs text-warning`,children:s(`customize.composerAbsent`)}),i.state.kind!==`none`&&d(Nc,{state:i.state}),d(Es,{device:e,handle:i,availability:fo(`doorbell`,f),onAdvanced:p}),d(Us,{device:e,handle:i,availability:fo(`motion`,f),sensors:c}),d(Yo,{device:e,handle:i,availability:fo(`battery`,f),onAdvanced:p}),d(us,{device:e,handle:i,availability:fo(`consumables`,f),onAdvanced:p,defaults:u}),d(cc,{device:e,target:t,handle:i,facts:l}),d(ks,{device:e}),d(Dc,{device:e,composition:ho(i.state),state:i.state.kind===`present`?i.state.view.state:null,nativeCaps:l.nativeCaps,cameraSensors:c.status}),a(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[m?d(po,{onAdvanced:p}):d(`span`,{}),d(Pc,{handle:i})]})]})}function Mc({device:e,target:t,handle:n,facts:r,onDone:i}){let a=n.state.kind===`present`?n.state:null;return d(ki,{initial:a===null?ui(t):di(a.composition,``),blockId:a===null?null:a.view.block.id,deviceType:e.type,targetName:e.name,nativeCaps:r.nativeCaps,targetFields:r.wireable,onCancel:i,save:async e=>{let t=await n.save(e);return t.kind===`saved`&&i(),t}})}function Nc({state:e}){let{t}=X();switch(e.kind){case`pending`:return d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.status.pending`)});case`unknown`:return d(Kn,{title:t(`customize.status.unknownTitle`),message:e.reason});case`not-loaded`:return d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.status.notLoaded`,{reason:e.reason})});case`none`:return null;case`present`:{let n=e.view.block;return a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(cn,{variant:n.status===`running`?`success`:n.status===`failed`?`danger`:`warning`,children:t(`customize.blockStatus.${n.status}`)}),!n.enabled&&d(cn,{variant:`default`,children:t(`customize.status.off`)}),n.lastError!==void 0&&d(`span`,{className:`text-[11px] text-foreground-muted break-words`,children:n.lastError}),e.view.state.kind===`unreachable`&&d(`span`,{className:`text-[11px] text-warning`,children:t(`customize.status.composerUnreachable`,{reason:e.view.state.error})})]})}}}function Pc({handle:e}){let{t}=X(),n=lt(),[i,o]=r(null);if(e.state.kind!==`present`)return null;let s=async()=>{if(!await n({title:t(`customize.remove.title`),message:t(`customize.remove.message`),confirmLabel:t(`customize.remove.confirm`),variant:`danger`}))return;let r=await e.save(null);o(r.kind===`refused`?r.reason:null)};return a(`div`,{className:`flex flex-col items-start gap-1`,children:[d(J,{variant:`danger`,size:`sm`,disabled:e.saving,onClick:()=>void s(),children:t(`customize.remove.button`)}),i!==null&&d(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:i})]})}var Fc=`overview`;function Ic(e,t){return e.some(e=>e.id===t)?t:Fc}function Lc({deviceId:e}){let{t}=X(),n=c(),r=Number.isFinite(e),{data:i}=Ct({deviceId:e},{enabled:r}),o=typeof i?.type==`string`?i.type:`camera`;yr([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:s,isLoading:l,isError:u,error:f}=Tt({deviceId:e},{enabled:r}),{data:p}=bn({deviceType:o},{enabled:!!o}),m=Fn({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(l)return d(`div`,{className:`p-4`,children:d(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(u)return a(`div`,{className:`p-4 text-xs text-red-400`,children:[t(`device.bindingsTab.failedToLoadBindings`,`Failed to load bindings:`),` `,f instanceof Error?f.message:String(f)]});let h=new Map,g={};for(let e of p??[])g[e.capName]=e.wrappers;for(let e of s?.entries??[])h.set(e.capName,{...e,wrappers:g[e.capName]??[]});for(let e of p??[])h.has(e.capName)||h.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let _=[...h.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(_.length===0)return a(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[d(nt,{className:`h-8 w-8 opacity-40`}),d(`p`,{className:`text-xs`,children:t(`device.bindingsTab.noCapabilityProvidersApplicableTo`,`No capability providers applicable to this device yet.`)}),d(`p`,{className:`text-[10px] opacity-60`,children:t(`device.bindingsTab.nativeProvidersShowUpHere`,`Native providers show up here as soon as the owning addon registers them.`)})]});let v=_.filter(e=>e.kind!==`unbound`).length,y=[{key:`capability`,header:t(`device.bindingsTab.capability`,`Capability`),render:e=>d(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:t(`device.bindingsTab.kind`,`Kind`),render:e=>d(Rc,{kind:e.kind})},{key:`provider`,header:t(`device.bindingsTab.activeProvider`,`Active Provider`),render:e=>d(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||d(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:t(`device.bindingsTab.node`,`Node`),render:e=>e.providerNodeId?d(zc,{nodeId:e.providerNodeId}):d(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:t(`device.bindingsTab.kindNative`,`Native`),render:e=>d(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||d(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:t(`device.bindingsTab.wrapper`,`Wrapper`),render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return d(Bc,{wrappers:t.wrappers,activeWrapperId:n,disabled:m.isPending,onPick:r=>{let i=n===r;m.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}];return a(`div`,{className:`flex flex-col gap-3 p-1`,children:[d(`div`,{className:`text-[11px] text-foreground-subtle`,children:d(ei,{i18nKey:`device.bindingsTab.boundSummary`,count:_.length,values:{bound:v},components:{b:d(`span`,{className:`font-medium text-foreground`}),em:d(`em`,{})}})}),d(Jn,{columns:y,rows:_,rowKey:e=>e.capName,minWidthPx:720})]})}function Rc({kind:e}){let{t}=X();return e===`native`?a(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[d(re,{className:`h-3 w-3`}),t(`device.bindingsTab.kindNative`)]}):e===`wrapped`?a(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[d(at,{className:`h-3 w-3`}),t(`device.bindingsTab.wrapped`)]}):e===`linked`?a(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-warning/30 text-warning bg-warning/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[d(ae,{className:`h-3 w-3`}),t(`device.bindingsTab.linked`)]}):a(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[d(S,{className:`h-3 w-3`}),t(`common.unbound`)]})}function zc({nodeId:e}){return d(`span`,{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e===`hub`?`text-foreground-subtle`:`text-foreground`}`,children:e})}function Bc({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){let{t:i}=X();return e.length===0?d(`span`,{className:`text-[10px] opacity-40`,children:i(`device.bindingsTab.noneAvailable`,`none available`)}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let o=e===t;return a(`button`,{disabled:n,onClick:()=>r(e),title:o?i(`device.bindingsTab.clickToDeactivateRevertTo`,`Click to deactivate (revert to native)`):i(`device.bindingsTab.activateWrapper`,`Activate wrapper {{wrapperId}}`,{wrapperId:e}),className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${o?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[d(o?p:me,{className:`h-3 w-3`}),e]},e)})})}function Vc({deviceId:e,activeSubTab:t,onSubTabChange:n,deviceType:r,isAdmin:i}){return a(`div`,{className:`flex flex-col gap-3`,children:[Kr(r,i)&&d(mr,{deviceId:e,readOnly:!0}),d(ii,{deviceId:e,activeSubTab:t,onSubTabChange:n})]})}e();var Hc=[[`pipelineOrchestrator`,`getCameraDetectionSource`]];function Uc(e){let t=c(),n=or({deviceId:e},{refetchOnMount:`always`}),a=Xt(),[o,s]=r(null),[l,u]=r(null),d=i(async n=>{u(null),s(n);try{await a.mutateAsync({deviceId:e,source:n}),await t.invalidateQueries({queryKey:Hc})}catch(e){u(e instanceof Error?e.message:`Could not change the root detector`),await t.invalidateQueries({queryKey:Hc})}finally{s(null)}},[e,a,t]),f=n.data??null;return{view:f,isLoading:n.isLoading,source:o??f?.source??null,saving:o!==null,error:l,pick:d}}var Wc=`object-detection`;function Gc(e){return[e.addonId,...e.children.flatMap(Gc)]}function Kc(e,t){if(e===`pipeline`)return new Set;let n=qc(t,Wc);return n===void 0?new Set:new Set(e===`onboard`?[n.addonId]:Gc(n))}function qc(e,t){for(let n of e){if(n.addonId===t)return n;let e=qc(n.children,t);if(e!==void 0)return e}}function Jc(e,t){return e===`onboard`?Y.t(`helpers.detectionSourceModel.badgeCameraAi`):t===`object-detection`?Y.t(`helpers.detectionSourceModel.badgeNoRoot`):Y.t(`helpers.detectionSourceModel.badgeIdle`)}function Yc(e){switch(e){case`pipeline`:return Y.t(`helpers.detectionSourceModel.explainPipeline`);case`onboard`:return Y.t(`helpers.detectionSourceModel.explainOnboard`);case`none`:return Y.t(`helpers.detectionSourceModel.explainNone`)}}function Xc(e){switch(e){case`boxed`:return``;case`while-streaming`:return Y.t(`helpers.detectionSourceModel.geometryWhileStreaming`);case`flag-only`:return Y.t(`helpers.detectionSourceModel.geometryFlagOnly`);case`unknown`:return Y.t(`helpers.detectionSourceModel.geometryUnknown`)}}function Zc(e,t){return e===`onboard`?Y.t(`helpers.detectionSourceModel.noticeOnboard`):t===`object-detection`?Y.t(`helpers.detectionSourceModel.noticeNoRoot`):Y.t(`helpers.detectionSourceModel.noticeIdle`)}function Qc({source:e,geometry:t,saving:n,error:r,onPick:i}){let{t:o}=X(),s=t===`flag-only`,c=Xc(t);return a(`section`,{"aria-label":o(`device.detectionSourceControl.rootDetector`,`Root detector`),"aria-busy":n,className:`space-y-1.5 rounded-md border border-border bg-surface px-3 py-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1.5`,children:[d(`h3`,{className:j,children:o(`device.detectionSourceControl.rootDetector`,`Root detector`)}),d(ot,{label:o(`device.detectionSourceControl.rootDetector`,`Root detector`),value:e,onChange:t=>{!n&&t!==e&&i(t)},options:[{value:`pipeline`,label:o(`device.detectionSourceControl.thisNode`,`This node`)},{value:`onboard`,label:o(`device.detectionSourceControl.cameraOnboardAi`,`Camera onboard AI`),disabled:s&&e!==`onboard`,reason:c},{value:`none`,label:o(`device.detectionSourceControl.none`,`None`)}]}),n&&d(`span`,{className:`text-[10px] text-foreground-subtle`,children:o(`device.detectionSourceControl.saving`,`Saving…`)})]}),a(`p`,{className:he,children:[Yc(e),` `,o(`device.detectionSourceControl.oneRoot`)]}),c!==``&&d(`p`,{className:`text-[10px] text-foreground-subtle`,children:c}),r!==null&&d(`p`,{role:`alert`,className:`text-[11px] text-danger`,children:r})]})}e();var $c=new Set([`package-detection`]);function el(e){return e?.settings!==void 0&&Object.keys(e.settings).length>0?`accelerator`:`camera`}function tl(e){return e===`camera`?Y.t(`device.cameraStepInspector.modelSource.camera`):e===`node`?Y.t(`device.cameraStepInspector.modelSource.node`):Y.t(`device.cameraStepInspector.modelSource.default`)}function nl(e){let{stored:t,draft:n,below:r,boundKeys:i}=e,a=n?.modelId===void 0?t?.modelId:n.modelId??void 0,o=Fe(n?.settings??t?.settings,r,i),s={...a===void 0?{}:{modelId:a},...o===void 0?{}:{settings:o}};return Object.keys(s).length>0?s:null}function rl(e,t){return(e?.modelId??null)===(t?.modelId??null)&&Le(e?.settings??{},t?.settings??{})}function il({deviceId:e}){let{t}=X(),i=c(),l=U().trpcClient,u=Er({deviceId:e},{refetchOnMount:`always`}),f=hr({deviceId:e},{refetchOnMount:`always`}),p=ft(void 0,{refetchOnMount:`always`}),m=We(It({addonId:`pipeline-orchestrator`}).data??null);yr([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let{nodes:h}=vr(),g=n(()=>{let e=new Set((p.data??[]).map(e=>e.nodeId));return h.filter(t=>t.isOnline&&e.has(t.id)).map(e=>({id:e.id,name:e.name}))},[p.data,h]),_=g.map(e=>e.id).join(`,`),v=o({enabled:g.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`camera-step-schemas`,_],queryFn:async()=>{let e={};for(let t of g)try{e[t.id]=await l.pipelineExecutor.getSchema.query({nodeId:t.id})}catch{}return e}}),y=o({enabled:g.length>0,queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`],`camera-step`,_],queryFn:async()=>{let e={};for(let t of g)try{e[t.id]=(await l.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:t.id})).devices}catch{e[t.id]=[]}return e}}),b=()=>{i.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),i.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]})},x=Ht({onSuccess:b}),S=vt(),C=kt(),[w,T]=r(null),[E,D]=r(null),[O,k]=r(null),[A,M]=r(!1),[ee,N]=r(null),P=v.data??{},F=y.data??{},te=f.data??{},I=u.data??null,L=g.map(e=>P[e.id]).find(e=>e!==void 0)??null,R=n(()=>L?Lt(L):[],[L]),ne=n(()=>Hi(R),[R]),z=Uc(e),re=n(()=>z.source===null?new Set:Kc(z.source,R),[z.source,R]),[B,V]=r(!1),ie=n(()=>Gi(g,F,B),[g,F,B]),ae=n(()=>Gi(g,F,!0),[g,F]),oe=n(()=>Gi(g,F).length,[g,F]),se=(e,t)=>Ii(P[e.nodeId],t),H=(e,t)=>te[e.nodeId]?.[e.deviceKey]?.[t],ce=(e,t)=>Xi(F[e.nodeId]??[],e.deviceKey,t)??{},le=e=>{if($c.has(e))return{kind:`zone-driven`};let t=Ii(L,e)?.enabledByDefault??!0,n=I?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},ue=(e,t,n)=>{let r=n?.stepId===t?n:null;return{node:ce(e,t),camera:r?.camera??I?.stepSettings?.[t],accelerator:r?.perAccelerator[e.id]?.settings??H(e,t)?.settings}},de=(e,t,n)=>{let r=n?.stepId===t?n.perAccelerator[e.id]?.modelId:void 0;return r===void 0?H(e,t)?.modelId:r??void 0},fe=(e,t)=>{if(re.has(e))return{kind:`disabled`};let n=se(t,e),r=le(e),i=Wi(e),a=Li(P[t.nodeId],t,H(t,`object-detection`)?.modelId),o=ue(t,e,null),s=ze(o.node,o.camera,o.accelerator);return qi({addon:n,acc:t,gatedOn:r.kind===`gate`?r.effectiveOn:!0,model:n?Ui(n,t,{nodePin:t.device.steps?.[e]?.modelId,cameraPin:H(t,e)?.modelId}):{modelId:void 0,source:`default`},...Bi(e,s,a)&&a?{rootName:a.name}:{},...i?{clusterModelId:m[e]??i.defaultModelId}:{}})},pe=ne.map(({node:e})=>({addonId:e.addonId,name:e.addonName,fieldLabels:Ki(Ii(L,e.addonId))}));return p.isLoading||g.length>0&&(v.isLoading||y.isLoading)?d(`div`,{className:`animate-pulse p-4 text-xs text-foreground-subtle`,children:t(`device.cameraStepInspector.loadingPipeline`,`Loading pipeline…`)}):g.length===0?d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:t(`device.cameraStepInspector.noPipelineNodeIsOnline`,`No pipeline node is online.`)}):L===null?d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:t(`device.cameraStepInspector.catalogUnavailable`,`Catalog unavailable.`)}):a(`div`,{className:`space-y-2`,children:[z.view?.onboard.available===!0&&z.source!==null&&d(Qc,{source:z.source,geometry:z.view.onboard.geometry,saving:z.saving,error:z.error,onPick:e=>void z.pick(e)}),d(Fi,{tree:R,searchRows:pe,accelerators:ie,cellState:fe,stepBadge:e=>re.has(e)&&z.source!==null?d(cn,{variant:`warning`,title:Zc(z.source,e),children:Jc(z.source,e)}):d(Un,{gate:le(e)}),disabledCount:Yi(Object.fromEntries(g.map(e=>[e.id,F[e.id]??[]]))),showDisabled:B,onShowDisabledChange:V,dirty:w!==null,onDiscard:()=>T(null),summary:d(`span`,{className:he,children:t(`device.cameraStepInspector.balancedAcross`,{count:oe})}),label:t(`device.cameraStepInspector.detectionStepsOfThisCamera`,`Detection steps of this camera`),renderDetail:({stepId:n,accelerator:r,matchedField:i,closeButton:o,onEscape:c,headingRef:l})=>{let u=r??ie[0],f=u?se(u,n)??Ii(L,n):null;if(f===null||u===void 0)return d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:t(`device.cameraStepInspector.noStepSelected`,`No step selected.`)});let p=w?.stepId===n?w:null,m=At(f),h=Ye(m),g=ue(u,n,p),_=ze(g.node,g.camera,g.accelerator),v=Li(P[u.nodeId],u,H(u,`object-detection`)?.modelId),y=Ui(f,u,{nodePin:u.device.steps?.[n]?.modelId,cameraPin:de(u,n,p)}).modelId,F=ze(g.node,g.camera),te=Ue(g.accelerator,F,h),R=Wi(n),ne=le(n),B=m.find(e=>`label`in e&&e.label===i)?.key??null,V=r===null?null:`${n}|${r.id}`,oe=r===null?`camera`:E?.key===V?E.scope:el(H(r,n)),U=e=>{N(null),T(t=>e(t?.stepId===n?t:{stepId:n,perAccelerator:{}}))},fe=(e,t)=>U(n=>({...n,perAccelerator:{...n.perAccelerator,[e.id]:{...n.perAccelerator[e.id],...t}}})),pe=e=>U(t=>{let r=g.accelerator??{},i=Me(t.camera??I?.stepSettings?.[n],e,r,h),a={...t.perAccelerator};for(let r of ae){let i=t.perAccelerator[r.id]?.settings??H(r,n)?.settings;i!==void 0&&(a[r.id]={...a[r.id],settings:Ke(i,e,h)})}return{...t,camera:i,perAccelerator:a}}),W=async()=>{if(p!==null){M(!0);try{let t=I?.stepSettings?.[n];p.camera!==void 0&&!Le(p.camera,t??{})&&await C.mutateAsync({deviceId:e,addonId:n,settings:Object.keys(p.camera).length>0?{...p.camera}:null});let r=p.camera??t;for(let t of ae){let i=p.perAccelerator[t.id];if(i===void 0)continue;let a=H(t,n),o=nl({stored:a,draft:i,below:ze(ce(t,n),r),boundKeys:h});rl(o,a)||await S.mutateAsync({deviceId:e,agentNodeId:t.nodeId,deviceKey:t.deviceKey,addonId:n,patch:o})}T(null),N({kind:`saved`})}catch(e){N({kind:`error`,error:e instanceof Error?e.message:t(`device.cameraStepInspector.saveFailed`)})}finally{M(!1),b()}}},me=p===null?0:+(p.camera!==void 0&&!Le(p.camera,I?.stepSettings?.[n]??{}))+Object.values(p.perAccelerator).length,ge=e=>{let r=se(e,n)??f,i=de(e,n,p),a=e.device.steps?.[n]?.modelId,o=Ui(r,e,{nodePin:a,cameraPin:i}),c=ue(e,n,p),l=Li(P[e.nodeId],e,H(e,`object-detection`)?.modelId),u=Bi(n,ze(c.node,c.camera,c.accelerator),l),m=Ri(r,e)?u&&l?d(nn,{rootModel:l,stepModelId:o.modelId}):void 0:d(s,{children:t(`device.cameraStepInspector.noBuild`,{format:e.device.format})});return{label:e.label,format:e.device.format,modelId:o.modelId,source:o.source,sourceLabel:tl(o.source),models:Et(r.models??[],e.device.format),defaultModelId:r.defaultModelIdByFormat?.[e.device.format]??r.defaultModelId,expanded:O===e.id,onToggle:()=>k(t=>t===e.id?null:e.id),onChangeModel:t=>fe(e,{modelId:t}),...i===void 0?{}:{onReset:()=>fe(e,{modelId:null}),resetLabel:a===void 0?`Reset to hardware default`:`Reset to node pin`},...m===void 0?{}:{note:m},changed:p?.perAccelerator[e.id]?.modelId!==void 0}},_e=R===null&&m.length>0?r===null?d(`p`,{className:he,children:t(`device.cameraStepInspector.appliesToAllAcceleratorsOf`,`Applies to: all accelerators of this camera.`)}):a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`span`,{className:`text-[11px] font-medium text-foreground`,children:t(`device.cameraStepInspector.appliesTo`,`Applies to`)}),d(ot,{label:t(`device.cameraStepInspector.settingsApplyTo`,`Settings apply to`),options:[{value:`accelerator`,label:t(`device.cameraStepInspector.thisAccelerator`,`This accelerator`)},{value:`camera`,label:t(`device.cameraStepInspector.allAcceleratorsOfThisCamera`,`All accelerators of this camera`)}],value:oe,onChange:e=>V!==null&&D({key:V,scope:e})})]}):void 0;return d(Sn,{ref:l,title:r===null?t(`device.cameraStepInspector.thisCamera`,`{{name}} · this camera`,{name:f.name}):`${f.name} · ${r.label}`,subtitle:r===null?t(`device.cameraStepInspector.everyAcceleratorThisCameraRuns`,`{{slot}} · every accelerator this camera runs on`,{slot:f.slot}):`${f.slot} · ${r.device.format}`,leading:o,onEscape:c,headerActions:d(wr,{gate:ne,busy:x.isPending,onSet:t=>x.mutate({deviceId:e,addonId:n,enabled:t})}),saveBar:{dirtyCount:me,saving:A,status:ee?.kind??null,...ee?.error===void 0?{}:{error:ee.error},onSave:()=>void W(),onDiscard:()=>T(null),..._e===void 0?{}:{scope:_e}},children:a(`div`,{className:`space-y-3`,children:[re.has(n)&&z.source!==null&&d(`p`,{role:`note`,className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-1.5 text-[11px] text-warning`,children:Zc(z.source,n)}),a(`section`,{className:`space-y-2`,"aria-label":t(`device.cameraStepInspector.model`,`Model`),children:[d(`h3`,{className:j,children:t(`device.cameraStepInspector.model`,`Model`)}),R===null?r===null?d(zi,{rows:ie.map(e=>{let t=Ui(se(e,n)??f,e,{nodePin:e.device.steps?.[n]?.modelId,cameraPin:de(e,n,p)});return{id:e.id,label:e.label,modelId:t.modelId,sourceLabel:tl(t.source)}})}):d(Nt,{...ge(r)},r.id):d(Ji,{step:R,engineFormat:u.device.format,runnableModelIds:Et(f.models??[],u.device.format).map(e=>e.id)})]}),R===null&&(m.length>0||v!==void 0)&&d(`section`,{"aria-label":t(`device.cameraStepInspector.settings`,`Settings`),className:`border-t border-border/60 pt-2`,children:d(al,{addon:f,fields:m,layers:g,scope:oe,viewed:r,modelId:yt(f,y,_,v),root:v,pinned:r===null?[]:te,highlightKey:B,onChangeCamera:e=>U(t=>({...t,camera:e})),onChangeAccelerator:e=>fe(u,{settings:e}),onApplyToAll:pe,onFollowNode:()=>fe(u,{settings:te.reduce((e,t)=>Ke(e,t,h),{...g.accelerator})})})}),d(Pi,{addonId:n,highlightLabel:i})]})})}})]})}function al({addon:e,fields:t,layers:n,scope:r,viewed:i,modelId:a,root:o,pinned:s,highlightKey:c,onChangeCamera:l,onChangeAccelerator:u,onApplyToAll:f,onFollowNode:p}){let{t:m}=X();Vi(c===null?null:sn(c));let h=i!==null&&n.accelerator!==void 0;return d(Ut,{addon:e,fields:t,layers:{node:n.node,...n.camera===void 0?{}:{camera:n.camera},...h?{accelerator:n.accelerator}:{}},target:r,labels:{...i===null?{}:{accelerator:`This accelerator`},camera:`All accelerators`,node:`Node`},modelId:a,...o===void 0?{}:{rootModel:o},pinnedKeys:s,highlightKey:c,onChangeLayer:r===`camera`?l:u,...s.length>0?{headerActions:d(`button`,{type:`button`,className:oe,onClick:p,children:m(`device.cameraStepInspector.followNode`,{count:s.length})})}:{},fieldActions:(e,t)=>i!==null&&t===`accelerator`?d(`button`,{type:`button`,className:oe,onClick:()=>f(e),children:m(`device.cameraStepInspector.applyToAllAccelerators`,`Apply to all accelerators`)}):null})}function ol(e,t,n){return{id:e,get label(){return Y.t(t)},icon:n}}var sl=[ol(`object-detection`,`helpers.detectionSettingsGroups.objectDetection`,`scan-search`),ol(`tracking`,`helpers.detectionSettingsGroups.tracking`,`route`),ol(`motion`,`helpers.detectionSettingsGroups.motion`,`activity`),ol(`stationary`,`helpers.detectionSettingsGroups.stationary`,`square-parking`),ol(`zones`,`helpers.detectionSettingsGroups.zones`,`shapes`),ol(`audio`,`helpers.detectionSettingsGroups.audio`,`volume-2`),ol(`cluster`,`helpers.detectionSettingsGroups.cluster`,`server`)],cl={"pipeline-object-detection":`object-detection`,"detection-sensitivity":`object-detection`,"onboard-object-detection":`object-detection`,tracking:`tracking`,"tracking-core":`tracking`,"motion-tuning":`motion`,"stationary-objects":`stationary`,occupancy:`stationary`,zones:`zones`,"pipeline-audio":`audio`,"cluster-assignment":`cluster`,"orchestrator-live":`cluster`};function ll(e){return cl[e]??`object-detection`}e();var ul=`steps`,dl=`settings`,fl=new Set([ul,dl]);function pl(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function ml({deviceId:e,activeSubTab:t,onSubTabChange:n}){let{t:r}=X();return a(mt,{value:t&&fl.has(t)?t:ul,onValueChange:i(e=>{n?.(e)},[n]),className:`flex flex-col`,children:[a(rr,{className:`flex-shrink-0`,children:[d(ct,{value:ul,children:r(`device.detectionPipelineTab.steps`,`Steps`)}),d(ct,{value:dl,children:r(`device.detectionPipelineTab.settings`,`Settings`)})]}),d(en,{value:ul,children:d(il,{deviceId:e})}),d(en,{value:dl,children:d(ii,{deviceId:e,sectionFilter:pl,subTabGrouping:{groupOf:e=>ll(e.id),tabs:sl}})})]})}var hl=`Notifications`,gl=`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`;function _l(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:hl,on:r===null?null:i??r,available:r!==null,costWhenOff:gl}}function vl(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}e();function yl(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function bl({deviceId:e}){let{t}=X(),n=c(),o=Number.isFinite(e),[s,l]=r(null),[u,f]=r(null),p=_l({mutedDeviceIds:yl(Ir({},{enabled:o}).data),deviceId:e,pendingOn:u}),m=_n({onError:t=>{console.error(`[DeviceNotificationMute] mute write failed — reverting`,{tags:{deviceId:e},meta:{error:t instanceof Error?t.message:String(t)}}),f(null),l(t instanceof Error?t.message:String(t)),n.invalidateQueries({queryKey:[[`notificationRules`,`listDeviceMutes`]]})},onSuccess:()=>{l(null),f(null),n.invalidateQueries({queryKey:[[`notificationRules`]]})}}),h=i(()=>{let t=vl(p,e);t!==null&&(f(!t.muted),m.mutate(t))},[e,m,p]),g=p.on===null,_=p.on===!1,v=_?tt:ge;return a(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[a(`div`,{className:`border-b border-border px-4 py-2 flex items-center justify-between gap-2`,children:[d(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:t(`device.deviceNotificationMute.notifications`,`Notifications`)}),_&&d(`span`,{className:`rounded bg-warning/20 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide text-warning`,children:t(`common.muted`)})]}),a(`div`,{className:`px-4 py-3 flex items-start gap-3`,children:[a(`button`,{type:`button`,role:`switch`,"aria-label":p.label,"aria-checked":p.on===!0,disabled:!p.available||m.isPending,onClick:h,title:g?t(`device.deviceNotificationMute.notificationMuteStateUnknownThe`,`Notification mute — state unknown; the notification centre did not answer.`):_?t(`device.deviceNotificationMute.muted`,`Muted. {{costWhenOff}}`,{costWhenOff:p.costWhenOff}):t(`device.deviceNotificationMute.notifyingMutingIt`,`Notifying. Muting it: {{costWhenOff}}`,{costWhenOff:p.costWhenOff}),className:`inline-flex items-center gap-1.5 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors disabled:cursor-not-allowed ${s===null?g?`border-dashed border-border text-foreground-subtle/50`:_?`border-warning/40 text-warning hover:bg-warning/10`:`border-success/30 text-success hover:bg-success/10`:`border-danger/50 text-danger bg-danger/5`}`,children:[d(v,{className:`h-3.5 w-3.5`}),d(`span`,{children:g?t(`device.deviceNotificationMute.unknown`,`Unknown`):_?t(`device.deviceNotificationMute.muted2`,`Muted`):t(`device.deviceNotificationMute.notifying`,`Notifying`)})]}),d(`p`,{className:`flex-1 text-[11px] leading-relaxed text-foreground-subtle`,children:s===null?g?t(`device.deviceNotificationMute.theNotificationCentreDidNot`,`The notification centre did not answer, so this device’s mute state is unknown.`):p.costWhenOff:t(`device.deviceNotificationMute.writeFailed`,`Write failed: {{failure}}`,{failure:s})})]})]})}function xl(e,t){return{switchId:e,label:xe[e].label,detail:t===void 0||t.length===0?null:t}}function Sl(e){let t=new Map;for(let n of e.switches)n.deviceId===e.sourceId&&(t.has(n.switchId)||t.set(n.switchId,n));return t}function Cl(e){let t=Sl(e),n=new Set(e.sourceStillLive),r=e.sourceStillLive.map(e=>xl(e,t.get(e)?.detail)),i=[...t.values()].filter(e=>e.outcome===`not-offered`&&!n.has(e.switchId)).map(e=>xl(e.switchId,e.detail));return{inheritedId:e.sourceId,retiredId:e.targetId,swapped:e.swapped,verdict:r.length===0?`quiet`:`still-live`,stillLive:r,neverOffered:i}}e();function wl(e,t){return e.filter(e=>e.isCamera&&e.id!==t).map(e=>({id:e.id,name:e.name})).toSorted((e,t)=>e.name.localeCompare(t.name))}function Tl({deviceId:e,deviceName:t}){let{t:i}=X(),o=lt(),[s,c]=r(null),l=Cn({isCamera:!0,projection:`slim`}),u=Cr(),f=l.data!==void 0,p=n(()=>l.data===void 0?[]:wl(l.data,e),[l.data,e]),m=p.find(e=>e.id===s)??null,h=u.data===void 0?null:Cl(u.data),g=u.error===null?null:u.error.message,_=async()=>{m===null||m.id===e||await o({title:i(`deviceMigrate.confirmTitle`,`Replace “{{source}}” with “{{target}}”?`,{source:t,target:m.name}),message:i(`deviceMigrate.confirmMessage`,`“{{target}}” takes over number {{sourceId}}. That number is what every recording, event, rule, zone and home-automation export of “{{source}}” is filed under, so all of it follows the number to the new hardware and keeps working. “{{source}}” is switched off and handed number {{targetId}} in exchange. This swaps two device identities and cannot be undone from here.`,{source:t,target:m.name,sourceId:e,targetId:m.id}),confirmLabel:i(`deviceMigrate.confirmAction`,`Migrate`),variant:`danger`})&&u.mutate({sourceId:e,targetId:m.id})};return a(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[a(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[a(`div`,{className:`min-w-0`,children:[d(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:i(`deviceMigrate.title`,`Migrate to…`)}),d(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:i(`deviceMigrate.subtitle`,`Replace this camera with other hardware you have already adopted. The new camera inherits number {{deviceId}}, so recordings, rules and integrations follow it.`,{deviceId:e})})]}),a(`div`,{className:`flex shrink-0 items-center gap-2`,children:[a(`select`,{"aria-label":i(`deviceMigrate.pickerLabel`,`Replacement camera`),className:`rounded-md border border-border bg-background px-2 py-1.5 text-xs text-foreground disabled:opacity-50`,disabled:!f||p.length===0||u.isPending,value:s===null?``:String(s),onChange:e=>{let t=e.target.value;c(t===``?null:Number(t))},children:[d(`option`,{value:``,children:f?i(`deviceMigrate.pickerPlaceholder`,`Select a camera…`):i(`deviceMigrate.pickerPending`,`Reading the fleet…`)}),p.map(e=>a(`option`,{value:String(e.id),children:[e.name,` (#`,e.id,`)`]},e.id))]}),a(`button`,{type:`button`,disabled:m===null||u.isPending,onClick:()=>{_()},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[d(Ze,{className:`h-3 w-3`}),u.isPending?i(`deviceMigrate.running`,`Migrating…`):i(`deviceMigrate.action`,`Migrate`)]})]})]}),f&&p.length===0&&d(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:i(`deviceMigrate.noTargets`,`No other camera is adopted, so there is nothing to migrate to.`)}),g!==null&&d(`p`,{className:`mt-2 text-[11px] text-danger`,children:i(`deviceMigrate.failed`,`Migration failed: {{error}}`,{error:g})}),h!==null&&d(El,{report:h})]})}function El({report:e}){let{t}=X(),n=e.verdict===`quiet`;return a(`div`,{className:`mt-3 space-y-2 border-t border-border pt-3`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`deviceMigrate.swapped`,`The replacement now answers on number {{inheritedId}}; the old camera was handed number {{retiredId}}.`,{inheritedId:e.inheritedId,retiredId:e.retiredId})}),n?a(`div`,{className:`flex items-start gap-2 rounded-md border border-success/30 bg-success/5 px-3 py-2`,children:[d(se,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-success`}),d(`p`,{className:`text-[11px] leading-relaxed text-foreground`,children:t(`deviceMigrate.quiet`,`Every function on the replaced camera was switched off — the old hardware is quiet.`)})]}):a(`div`,{className:`rounded-md border border-warning/40 bg-warning/5 px-3 py-2`,children:[a(`div`,{className:`flex items-start gap-2`,children:[d(W,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),d(`p`,{className:`text-[11px] leading-relaxed text-foreground`,children:t(`deviceMigrate.stillLive`,`The replaced camera could not be reached, so these functions are STILL RUNNING on the old hardware. Nothing here failed to migrate — but until you unplug it or reach it physically, it can still produce data.`)})]}),d(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.stillLive.map(e=>a(`li`,{className:`text-[11px] text-foreground`,children:[d(`span`,{className:`font-medium`,children:e.label}),e.detail!==null&&a(`span`,{className:`text-foreground-subtle`,children:[` — `,e.detail]})]},e.switchId))})]}),e.neverOffered.length>0&&a(`div`,{className:`rounded-md border border-border px-3 py-2`,children:[a(`div`,{className:`flex items-start gap-2`,children:[d(it,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),d(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`deviceMigrate.neverOffered`,`The replaced camera never offered these, so there was nothing to switch off. They are not running.`)})]}),d(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.neverOffered.map(e=>d(`li`,{className:`text-[11px] text-foreground-subtle`,children:e.label},e.switchId))})]})]})}e();function Dl({deviceId:e}){let{t}=X(),[n,i]=r(null),o=Gt({onSuccess:e=>{i(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>i(`Re-sync failed: ${e.message}`)});return a(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[a(`div`,{className:`flex items-center justify-between gap-3`,children:[a(`div`,{children:[d(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:t(`device.resyncButton.reSync`,`Re-sync`)}),d(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:t(`device.resyncButton.reAlignThisDeviceS`,`Re-align this device's type, role, capabilities and units with its source.`)})]}),a(`button`,{type:`button`,disabled:o.isPending,onClick:()=>{i(null),o.mutate({camDeviceId:e})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[d(R,{className:`h-3 w-3 ${o.isPending?`animate-spin`:``}`}),o.isPending?t(`device.resyncButton.reSyncing`,`Re-syncing…`):t(`device.resyncButton.reSync`,`Re-sync`)]})]}),n!==null&&d(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:n})]})}function Ol(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function kl({device:e}){let{t}=X(),n=ti(),r=typeof e.id==`number`?e.id:null,i=String(e.type??``),o=i===q.Camera,s=i===q.Hub,c=e.features??[],l=c.includes(Pe.Resyncable),{data:u}=tr({deviceId:r??0},{enabled:r!==null&&o,refetchInterval:5e3}),f=u?.streams??{},p=Object.entries(f),m=c.includes(Pe.DoorbellButton),h=Zn(m?{deviceId:r??void 0,historyLimit:10}:void 0),g=h.latest?Date.now()-h.latest.timestamp<3e4:!1;return a(`div`,{className:`space-y-5`,children:[s&&r!==null&&d(Ln,{deviceId:r,onOpenChild:e=>n(`/devices/${e}`)}),l&&r!==null&&d(Dl,{deviceId:r}),o&&r!==null&&d(Tl,{deviceId:r,deviceName:String(e.name??``)}),r!==null&&d(bl,{deviceId:r}),o&&r!==null&&d(En,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:r}),m&&d(Fr,{history:h.history,latestIsFresh:g}),o&&r!==null&&d(En,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:r}),o&&p.length>0&&a(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[d(`div`,{className:`border-b border-border px-4 py-2`,children:d(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:t(`device.overviewTab.streamNetwork`,`Stream Network`)})}),d(`div`,{className:`divide-y divide-border`,children:p.map(([e,n])=>a(`div`,{className:`px-4 py-2.5`,children:[a(`div`,{className:`flex items-center gap-2 mb-2`,children:[d(ie,{className:`h-3 w-3 text-foreground-subtle`}),d(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),a(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[d(Al,{label:t(`device.overviewTab.nominal`,`Nominal`),value:Ol(n.nominalBitrateKbps??0)}),d(Al,{label:t(`device.overviewTab.observed`,`Observed`),value:Ol(n.observedBitrateKbps??0)}),d(Al,{label:t(`device.overviewTab.peak`,`Peak`),value:Ol(n.peakBitrateKbps??0)}),d(Al,{label:t(`device.overviewTab.packetLoss`,`Packet Loss`),value:`${(n.packetLossPercent??0).toFixed(2)}%`,warning:(n.packetLossPercent??0)>1})]})]},e))})]}),d(Vr,{}),r!==null&&d(zr,{deviceId:r})]})}function Al({label:e,value:t,warning:n}){return a(`div`,{children:[d(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),d(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}var jl=`history`,Ml=[{id:`overview`,labelKey:`helpers.structuralTabs.overview`,cameraOnly:!1,adminOnly:!1},{id:`config`,labelKey:`helpers.structuralTabs.config`,cameraOnly:!1,adminOnly:!1},{id:ri,labelKey:`helpers.structuralTabs.customize`,cameraOnly:!1,adminOnly:!0},{id:jl,labelKey:`helpers.structuralTabs.history`,cameraOnly:!1,adminOnly:!1},{id:`detection-pipeline`,labelKey:`helpers.structuralTabs.detectionPipeline`,cameraOnly:!0,adminOnly:!1},{id:`bindings`,labelKey:`helpers.structuralTabs.bindings`,cameraOnly:!0,adminOnly:!1}],Nl=new Set([q.Hub,q.Container]);function Pl(e,t){let n=e===q.Camera,r=e===void 0||!Nl.has(e);return Ml.filter(e=>(n||!e.cameraOnly)&&(t||!e.adminOnly)&&(r||e.id!==`history`)).map(({id:e,labelKey:t})=>({id:e,label:Y.t(t)}))}function Fl({provider:e,integrationId:t,name:n}){let r=ti(),i=t===null?`/integrations`:`/integrations/${t}`,a=n===null?`Open integrations`:`Open integration ${n}`;return d(`button`,{type:`button`,onClick:()=>r(i),className:`shrink-0 rounded-md transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-1 focus-visible:ring-primary/50`,title:a,"aria-label":a,children:d($r,{type:e,size:`lg`})})}e();var Il=[{id:`logs`,icon:le,labelKey:`common.logs`},{id:`repl`,icon:rt,labelKey:`deviceDetail.repl`},{id:`events`,icon:D,labelKey:`common.events`},{id:`state`,icon:P,labelKey:`common.state`}];function Ll(){let{t:e}=X(),t=ci(),o=Number(t.deviceId),u=Number.isFinite(o),f=ti(),p=c(),m=lt(),h=U(),{user:_}=Xr(),v=_?.isAdmin===!0,[y,x]=ai(),S=y.get(`tab`)??`overview`,C=y.get(`sub`),[w,T]=r(`logs`),D=`device-detail.left-col-width-px`,[O,k]=r(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(D),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),A=l(O);A.current=O;function j(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??O??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{k(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=A.current;if(e!==null)try{window.localStorage.setItem(D,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:M,isLoading:N,isError:P}=Ct({deviceId:o},{enabled:u,refetchInterval:5e3,retry:1}),{data:F}=Rt({deviceId:o},{enabled:u}),te=n(()=>{let e=F?.settings?.sections??[],t=F?.live?.sections??[],n=[...e,...t],r=new Set;for(let e of n)e.location===`top-tab`&&e.tab&&r.add(e.tab===`zones`?`detection-pipeline`:e.tab);return n.some(Hr)&&r.add(qr),[...r].map(e=>e===`export`?{id:e,label:Br,isAddonContrib:!0}:{id:e,label:Ce[e]?.label??e,isAddonContrib:!0})},[F]),I=M,L=String(I?.name??t.deviceId??`Device`),ne=I?.online===!0,z=ne?`online`:`offline`,re=String(I?.addonId??`rtsp`),B=I?.features??[],V=I?.type,ie=V===q.Camera,{data:ae}=Zr(u?o:0),oe=V===q.Container,se=n(()=>(ae??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[ae]),H=n(()=>oe?Dt(se,typeof I?.linkDeviceId==`number`?I.linkDeviceId:null,typeof I?.primaryChildEntityId==`string`?I.primaryChildEntityId:null)?.id??null:null,[oe,se,I?.linkDeviceId,I?.primaryChildEntityId]),{data:ce}=Rt({deviceId:H??0},{enabled:H!==null}),le=n(()=>{if(H===null)return[];let e=ce?.settings?.sections??[],t=ce?.live?.sections??[],n=new Set;for(let r of[...e,...t])r.location===`top-tab`&&r.tab&&n.add(r.tab);return[...n].map(e=>({id:e,label:Ce[e]?.label??e,isAddonContrib:!0,childDeviceId:H}))},[H,ce]),ue=typeof I?.parentDeviceId==`number`?I.parentDeviceId:null,{data:fe}=Ct({deviceId:ue??0},{enabled:ue!==null}),W=Rr(),me=I?.disabled!==!0,he=n(()=>{let e=F?.settings?.sections??[],t=F?.live?.sections??[];return Gr([...e,...t],V,v,F!==void 0)},[F,V,v]),ge=n(()=>{let e=new Set,t=[];for(let n of[...Pl(V,v),...te,...le])n.id===`config`&&!he||e.has(n.id)||(e.add(n.id),t.push(n));return t},[V,v,te,le,he]),_e=n(()=>Ic(ge,S),[ge,S]),ve=i(e=>{x(t=>{let n=new URLSearchParams(t);e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`);for(let e of Zi)n.delete(e);return n},{replace:!0})},[x]),ye=i(e=>{x(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[x]),be=(ae??[]).length>0,xe=n(()=>Il.filter(({featureGate:e})=>!e||B.includes(e)),[B]),{data:Se}=pn(void 0),we=n(()=>I?ir(I,Se):null,[I,Se]),G=we?.kind===`resolved`?we.integration:null,Te=G===null?we?.kind===`unknown`?e(`deviceDetail.loadingIntegration`):we?.kind===`orphan`?e(`deviceDetail.missingIntegration`):e(`deviceDetail.noIntegration`):G.name,Ee=G!==null&&G.addonId===re?G.name:re,De=Qn({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]}),f(G?.id?`/integrations/${G.id}`:`/integrations`)}}),Oe=hn({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=Ot({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ae=Sr(),je=Wn({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Me=B.includes(Pe.Rebootable),Ne=B.includes(Pe.BatteryOperated),Fe=jt(h.trpcClient,Ne&&u?o:null),Ie=bt(h.trpcClient,u?o:null),[Le,Re]=r(!1),ze=async()=>{if(!Le){Re(!0);try{let e=L.replace(/[^a-zA-Z0-9_.-]+/g,`_`),t=new Date().toISOString().replace(/[:.]/g,`-`);await fa(`${ee}/${String(o)}.jpg?force=1`,`${e}-${t}.jpg`)}finally{Re(!1)}}},Be=Oe.isPending||ke.isPending,{data:Ve}=Or({deviceId:o},{enabled:u&&ie,refetchInterval:1e4}),He=Ve?.agentNodeId??null,K=typeof He==`string`&&He.length>0&&!He.startsWith(`addon:`)?He:void 0,{data:Ue}=zt({deviceId:o,...K?{nodeId:K}:{}},{enabled:u&&ie,refetchInterval:3e3,retry:!1}),{data:We}=$t({deviceId:o},{enabled:u&&ie,refetchInterval:3e3,retry:!1}),Ge=We?.level?.dbfs??null;function Ke(){if(!u)return null;switch(_e){case`overview`:return d(kl,{device:I??{}});case`config`:return d(Vc,{deviceId:o,activeSubTab:C,onSubTabChange:ye,deviceType:V,isAdmin:v});case`detection-pipeline`:return d(ml,{deviceId:o,activeSubTab:C,onSubTabChange:ye});case`bindings`:return d(Lc,{deviceId:o});case jl:return d(ar,{deviceId:o,onNavigate:e=>f(e)});case ri:return d(kc,{deviceId:o,activeSubTab:C,onSubTabChange:ye});default:{let e=_e,t=te.some(t=>t.id===e),n=le.find(t=>t.id===e);if(!t&&n===void 0)return null;let r=n?.childDeviceId??o;if(e===`export`)return d(ii,{deviceId:o,sectionFilter:Hr,activeSubTab:C,onSubTabChange:ye});let i=d(ii,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:C,onSubTabChange:ye});return n!==void 0&&r!==o?d(fn,{deviceId:r,children:i}):i}}}return u?N?a(`div`,{className:`flex flex-col h-full`,children:[a(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[d(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),d(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),d(`div`,{className:`flex-1 p-6`,children:d(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):P||!M?a(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[d(`p`,{className:`text-lg font-semibold text-foreground`,children:e(`deviceDetail.deviceNotFound`,`Device not found`)}),d(`p`,{className:`text-xs`,children:d(ei,{i18nKey:`deviceDetail.noDeviceWithId`,values:{id:o},components:{code:d(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`})}})}),d(`button`,{onClick:()=>f(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:e(`deviceDetail.backToIntegrations`,`Back to Integrations`)})]}):a(`div`,{className:`absolute inset-0 flex flex-col overflow-clip`,children:[a(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[d(`div`,{className:`mb-2`,children:d(Nr,{items:[{label:e(`deviceDetail.integrations`,`Integrations`),onClick:()=>f(`/integrations`)},G===null?{label:Te}:{label:Te,onClick:()=>f(`/integrations/${G.id}`)},{label:L}]})}),a(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[G!==null&&d(Fl,{provider:G.addonId,integrationId:G.id,name:G.name}),a(`div`,{className:`min-w-0 flex-1`,children:[a(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[d(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:L}),d(dr,{status:z}),Ne&&d(dn,{status:Fe,variant:`full`}),d(jr,{status:Ie})]}),ue!==null&&fe&&a(`button`,{type:`button`,onClick:()=>f(`/devices/${ue}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:e(`deviceDetail.openParentDevice`,`Open parent device {{name}}`,{name:fe.name}),children:[d(`span`,{children:`↑`}),d(`span`,{className:`truncate`,children:String(fe.name??`Device #${ue}`)})]}),d(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:B.length>0&&d(Qr,{capabilities:B})})]}),Ue&&d(`div`,{className:`hidden lg:flex`,children:d(Rl,{metrics:Ue,dbfs:Ge})}),a(`div`,{className:`flex items-center gap-1 shrink-0`,children:[a(`button`,{onClick:async()=>{me?await m({title:e(`deviceDetail.disable`,`Disable "{{name}}"?`,{name:L}),message:e(`deviceDetail.theDeviceWillStopProcessing`,`The device will stop processing streams and events. You can re-enable it later.`),confirmLabel:e(`common.disable`,`Disable`),variant:`danger`})&&ke.mutate({deviceId:o}):Oe.mutate({deviceId:o})},disabled:Be,title:me?e(`deviceDetail.disableDevice`,`Disable device`):e(`deviceDetail.enableDevice`,`Enable device`),className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border transition-colors disabled:opacity-50 ${me?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[d(g,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden sm:inline`,children:Be?e(`deviceDetail.updating`,`Updating…`):me?e(`deviceDetail.enabled`,`Enabled`):e(`deviceDetail.disabled`,`Disabled`)})]}),d(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),ie&&a(s,{children:[d(ya,{deviceId:o}),d(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),d(xa,{deviceId:o}),d(Xn,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:e(`deviceDetail.takeSnapshot`,`Take snapshot`),description:e(`deviceDetail.fetchAFreshFrameAnd`,`Fetch a fresh frame and download it.`),icon:E,disabled:Le,onClick:()=>{ze()}},{id:`reboot`,label:e(`deviceDetail.rebootDevice`,`Reboot device`),description:e(`deviceDetail.cameraGoesOfflineFor30`,`Camera goes offline for ~30 seconds.`),icon:pe,hidden:!Me,disabled:Ae.isPending,danger:!0,onClick:async()=>{await m({title:e(`deviceDetail.reboot`,`Reboot "{{name}}"?`,{name:L}),message:e(`deviceDetail.theCameraWillGoOffline`,`The camera will go offline for around 30 seconds while the firmware reboots.`),confirmLabel:e(`deviceDetail.reboot2`,`Reboot`),variant:`danger`})&&Ae.mutate({deviceId:o})}},{id:`restart-addon`,label:e(`deviceDetail.restartAddon`,`Restart addon`),description:e(`deviceDetail.bouncesEveryDeviceServedBy`,`Bounces every device served by {{servingAddonLabel}}.`,{servingAddonLabel:Ee}),icon:R,disabled:je.isPending,danger:!0,onClick:async()=>{await m({title:e(`deviceDetail.restart`,`Restart "{{servingAddonLabel}}"?`,{servingAddonLabel:Ee}),message:e(`deviceDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device served by it (not just "{{name}}"). Streams will reconnect automatically.`,{name:L}),confirmLabel:e(`deviceDetail.restart2`,`Restart`),variant:`danger`})&&je.mutate({addonId:re})}},{id:`delete`,label:e(`deviceDetail.deleteDevice`,`Delete device`),description:e(`deviceDetail.removeTheDeviceAndAll`,`Remove the device and all its settings.`),icon:b,separatorBefore:!0,disabled:De.isPending,danger:!0,onClick:async()=>{await m({title:e(`deviceDetail.delete`,`Delete "{{name}}"?`,{name:L}),message:e(`deviceDetail.thisWillRemoveTheDevice`,`This will remove the device and all its settings. This action cannot be undone.`),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&De.mutate({deviceId:o})}}]})]})]})]}),d(fn,{deviceId:o,device:I??void 0,children:d(zn,{children:d(Nn,{children:d(de,{children:d(Rn,{children:a(`main`,{className:W?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[a(`div`,{className:W?`flex flex-col bg-surface`:`${O===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!W&&O!==null?{width:`${String(O)}px`}:void 0,children:[d(`div`,{className:ie?`flex-shrink-0 border-b border-border-subtle bg-black`:W?`flex-shrink-0 border-b border-border-subtle bg-surface`:`max-h-[55%] shrink-0 overflow-y-auto border-b border-border-subtle bg-surface`,children:ie?d(to,{deviceId:o,intercomAvailable:B.includes(Pe.TwoWayAudio)}):d(Ga,{deviceId:o,deviceName:L,deviceType:V??`unknown`,provider:re,isOnline:ne,features:B})}),a(`div`,{className:W?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[d(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:d(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:xe.map(({id:t,labelKey:n,icon:r})=>{let i=w===t;return a(`button`,{onClick:()=>T(t),title:e(n),className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${i?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[d(r,{className:`h-3 w-3`}),e(n)]},t)})})}),a(`div`,{className:W?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[w===`logs`&&d(no,{deviceId:o,containerDeviceId:V===`container`?o:void 0}),w===`repl`&&d(ro,{deviceId:o}),w===`events`&&d(io,{deviceId:o}),w===`state`&&d(ao,{deviceId:o})]})]})]}),!W&&d(`div`,{role:`separator`,"aria-orientation":`vertical`,title:e(`deviceDetail.dragToResize`,`Drag to resize`),onMouseDown:j,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:d(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),a(`div`,{className:W?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[d(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:d(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:ge.map(e=>{let t=_e===e.id;return a(`button`,{onClick:()=>ve(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&d(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),a(`div`,{className:W?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[_e===`overview`&&be&&d(Sa,{parentDeviceId:o}),Ke()]})]})]})})})})})})]}):a(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[d(`p`,{className:`text-lg font-semibold text-foreground`,children:e(`deviceDetail.invalidDeviceId`,`Invalid device id`)}),d(`p`,{className:`text-xs`,children:d(ei,{i18nKey:`deviceDetail.invalidSegment`,values:{segment:t.deviceId},components:{code:d(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`})}})}),d(`button`,{onClick:()=>f(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:e(`deviceDetail.backToIntegrations`,`Back to Integrations`)})]})}function Rl({metrics:e,dbfs:t}){let n=ne(),{t:r}=X(),i=Mn(e.phase??`idle`,n);return a(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[a(`div`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`h-1.5 w-1.5 rounded-full ${i.dotClass}`}),d(`span`,{className:`text-[10px] font-medium ${i.textColor}`,children:i.label})]}),d(`div`,{className:`h-3 w-px bg-border`}),a(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[d(H,{className:`h-3 w-3`}),d(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),d(`span`,{children:r(`common.fpsWord`)})]}),a(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[d(te,{className:`h-3 w-3`}),d(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),d(`span`,{children:`ms`})]}),a(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:r(`deviceDetail.currentAudioLevelDbfs`,`Current audio level (dBFS)`),children:[d(k,{className:`h-3 w-3`}),d(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),d(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&a(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{Ll as DeviceDetailPage};