@camstack/addon-admin-ui 1.2.447 → 1.2.448

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-YlaeLmP_.js} +1 -1
  2. package/dist/assets/Addons-D0RNa7cq.js +4 -0
  3. package/dist/assets/{AdminPage-CTKQzYSK.js → AdminPage-Y0f_vb0G.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-DB1wuvwM.js → AdminSectionedPage-CvrbRm6V.js} +1 -1
  5. package/dist/assets/AiProfiles-CSfexEul.js +3 -0
  6. package/dist/assets/{BrokerForm-DgJKJJ9V.js → BrokerForm-D3VJOkFb.js} +1 -1
  7. package/dist/assets/Build-DqFGOChc.js +40 -0
  8. package/dist/assets/Calendars-BDpDvL0Q.js +1 -0
  9. package/dist/assets/{Cluster-CUFJA8Yh.js → Cluster-CTGHGuyd.js} +1 -1
  10. package/dist/assets/{ClusterStepModel-G54nm4iG.js → ClusterStepModel-DnRSJW9o.js} +1 -1
  11. package/dist/assets/CompositionEditor-D_p_gdiC.js +1 -0
  12. package/dist/assets/{CompositionEditorPage-DqCZgEdJ.js → CompositionEditorPage-B6Blr6a5.js} +1 -1
  13. package/dist/assets/Data-Cn6tMPDf.js +2 -0
  14. package/dist/assets/DeviceDetail-D_Vyvh2M.js +2 -0
  15. package/dist/assets/{DeviceDoActionFields-CU_AKA1W.js → DeviceDoActionFields-DtRDOGnl.js} +1 -1
  16. package/dist/assets/{Devices-CdmAtZP1.js → Devices-BqbXuY4u.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-OyxmU511.js → EmbedPlayerPage-DYNkVSGX.js} +1 -1
  18. package/dist/assets/History-4K69b4zC.js +1 -0
  19. package/dist/assets/Identity-BuytRDu0.js +1 -0
  20. package/dist/assets/IntegrationDetail-B9PHPBT2.js +1 -0
  21. package/dist/assets/IntegrationHub-CATt3sSb.js +1 -0
  22. package/dist/assets/Integrations-6bieSjRq.js +1 -0
  23. package/dist/assets/Integrations-6cJP9_gE.js +1 -0
  24. package/dist/assets/Library-BPUNgYx9.js +1 -0
  25. package/dist/assets/Locations-0VOpTZRT.js +3 -0
  26. package/dist/assets/{Logs-CaO5TsuY.js → Logs-hq9A8gPf.js} +1 -1
  27. package/dist/assets/{MaskShapeCanvas-CnazBudR.js → MaskShapeCanvas-DaES9o_d.js} +1 -1
  28. package/dist/assets/{MotionZonesSettings-BcEiYvgb.js → MotionZonesSettings-BB1OPY-Z.js} +1 -1
  29. package/dist/assets/MyAccess-BwHAEcsT.js +2 -0
  30. package/dist/assets/{Network-BNthoi6m.js → Network-CELjk0fc.js} +1 -1
  31. package/dist/assets/{NodeAddonsSettingsPanel-CpONFsu0.js → NodeAddonsSettingsPanel-C5TYpzdG.js} +1 -1
  32. package/dist/assets/Notifications-C_tBdjVZ.js +1 -0
  33. package/dist/assets/{PrivacyMaskSettings-B89MVHxL.js → PrivacyMaskSettings-dl0SaDLU.js} +1 -1
  34. package/dist/assets/Recordings-BebI9rhV.js +1 -0
  35. package/dist/assets/{ScanNetworkModal-B9n2JdTA.js → ScanNetworkModal-DpScPCmx.js} +1 -1
  36. package/dist/assets/{SceneMonitorEditor-Bmn_UcYs.js → SceneMonitorEditor-D_JR8OEY.js} +1 -1
  37. package/dist/assets/SessionsList-KUtPcHl3.js +2 -0
  38. package/dist/assets/{Showroom-BaHMWO3G.js → Showroom-BxILBL8f.js} +1 -1
  39. package/dist/assets/System-oJXxolQh.js +1 -0
  40. package/dist/assets/{Terminal-TaTeiXX0.js → Terminal-Cf5lX56U.js} +3 -3
  41. package/dist/assets/{Viewer-DXjhAdbS.js → Viewer-CDsUYSir.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-CC77R0_e.js} +1 -1
  43. package/dist/assets/{addon-icons-context-0MDrwtIo.js → addon-icons-context-F-l6JxP6.js} +1 -1
  44. package/dist/assets/{archive-C3J7kPmp.js → archive-gt6xpkGA.js} +1 -1
  45. package/dist/assets/{authed-media-dGvmAGIm.js → authed-media-BKSVGA1M.js} +1 -1
  46. package/dist/assets/{bell-off-Df5MKmnk.js → bell-off-DkFzAVbQ.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-DD515hf_.js} +1 -1
  49. package/dist/assets/circle-slash-Dvu6elI8.js +1 -0
  50. package/dist/assets/client-Dv9yZvWI.js +358 -0
  51. package/dist/assets/{cloud-upload-I7yc63rr.js → cloud-upload-DRbR_RgV.js} +1 -1
  52. package/dist/assets/crop-NbQapATy.js +1 -0
  53. package/dist/assets/{device-integration-icon-C_jsalSP.js → device-integration-icon-BrsSuZkc.js} +1 -1
  54. package/dist/assets/device-picker-model-B9RFllo3.js +1 -0
  55. package/dist/assets/{dist-BOKrykX2.js → dist-CtaM7tdj.js} +1 -1
  56. package/dist/assets/dist-eeXLB_WF.js +358 -0
  57. package/dist/assets/{eraser-WGJr5dAG.js → eraser-CYGvrt-o.js} +1 -1
  58. package/dist/assets/{hard-drive-download-BqS2ahXp.js → hard-drive-download-RpoYwcJW.js} +1 -1
  59. package/dist/assets/{hostInit-Cn05saXf.js → hostInit-SPnLNFAH.js} +1 -1
  60. package/dist/assets/i18n-DBncQ6jl.js +1 -0
  61. package/dist/assets/{icons-BgfaaZCZ.js → icons-Ctu1Y05s.js} +1 -1
  62. package/dist/assets/{index-2_qB4G1l.js → index-CXOYQeji.js} +3 -3
  63. package/dist/assets/{key-D741QkPA.js → key-BYpSoaTE.js} +1 -1
  64. package/dist/assets/{key-round-_blTK3l4.js → key-round-CUnNZTAz.js} +1 -1
  65. package/dist/assets/{layers-CBNWlTsd.js → layers-DlmuW7b-.js} +1 -1
  66. package/dist/assets/{linked-devices-model-Csh4WaVK.js → linked-devices-model-BEA1lr2Y.js} +1 -1
  67. package/dist/assets/{list-ordered-BTh8rts2.js → list-ordered-CoANKD7e.js} +1 -1
  68. package/dist/assets/{location-owned-usage-Dqp8xgaw.js → location-owned-usage-BOD2xEtr.js} +1 -1
  69. package/dist/assets/{log-in-Fh5saGuL.js → log-in-Ch8A1qlw.js} +1 -1
  70. package/dist/assets/{memory-stick-2qy4HWOo.js → memory-stick-Bsklsl2s.js} +1 -1
  71. package/dist/assets/{message-square-plus-D70FuCBB.js → message-square-plus-C5arEPSf.js} +1 -1
  72. package/dist/assets/{mf-entry-bootstrap-0-1defdd87.js → mf-entry-bootstrap-0-cf438d0a.js} +2 -2
  73. package/dist/assets/{mic-off-MTwAUBdb.js → mic-off-D9VVE1hf.js} +1 -1
  74. package/dist/assets/{monitor-off-Dn82QkPx.js → monitor-off-BCaF7zDl.js} +1 -1
  75. package/dist/assets/{monitor-smartphone-K0Y4ODGq.js → monitor-smartphone-B1lc4syi.js} +1 -1
  76. package/dist/assets/mount-B9RFllo3.js +1 -0
  77. package/dist/assets/notification-schedule-field-w-B_hHnB.js +1 -0
  78. package/dist/assets/{player-overlays-DyNPyo_W.js → player-overlays-DxE-ZGs_.js} +1 -1
  79. package/dist/assets/{recycle-DO1B1SCp.js → recycle-vSXkN2mG.js} +1 -1
  80. package/dist/assets/remoteEntry-S5WkZciN.js +1 -0
  81. package/dist/assets/{scan-eye-DSsbXKWH.js → scan-eye-BrgwL9sQ.js} +1 -1
  82. package/dist/assets/{scissors-CGMgxeDq.js → scissors-BKN5a41L.js} +1 -1
  83. package/dist/assets/{search-x-CUa_1rys.js → search-x-BFtEEQ7u.js} +1 -1
  84. package/dist/assets/{send-CKZO6JbT.js → send-DUwpyQRD.js} +1 -1
  85. package/dist/assets/{settings-2-Dee5_Dd_.js → settings-2-Cy16RU0G.js} +1 -1
  86. package/dist/assets/{speaker-CGMtKx0N.js → speaker-0YT_wAR4.js} +1 -1
  87. package/dist/assets/src-BXyxUvfL.js +67 -0
  88. package/dist/assets/{timer-reset-Dg8WnmrV.js → timer-reset-BXot0J3z.js} +1 -1
  89. package/dist/assets/{ungroup-DqYydoru.js → ungroup-CaZBfFGG.js} +1 -1
  90. package/dist/assets/{unlink-XIrgZrQf.js → unlink-sHJt-6l3.js} +1 -1
  91. package/dist/assets/{usb-33G087e5.js → usb-DhSYhQLg.js} +1 -1
  92. package/dist/assets/{use-scenes-feed-DsXuB27l.js → use-scenes-feed-gpHOmo_k.js} +1 -1
  93. package/dist/assets/{use-stationary-objects-D_FqXLHG.js → use-stationary-objects-1xlyjyv9.js} +1 -1
  94. package/dist/assets/useEventInvalidation-B9RFllo3.js +1 -0
  95. package/dist/assets/{useNodeUrlSelection-DWli8jTd.js → useNodeUrlSelection-Bn1gQlh_.js} +1 -1
  96. package/dist/assets/user-round-BN8VNM_n.js +1 -0
  97. package/dist/assets/{user-x-ODLis0Xn.js → user-x-BjgNc3OJ.js} +1 -1
  98. package/dist/assets/{video-BtFmM3eg.js → video-Ds3z1Mgy.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_-DpZo3iGZ.js} +2 -2
  100. package/dist/index.html +10 -10
  101. package/dist/server/addon.js +10 -16
  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
@@ -1 +0,0 @@
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-DyNPyo_W.js";import{Cn as m,Dr as h,Fr as g,Ir as _,Mr as v,Nr as y,Or as b,Pr as x,Ur as S,Wr as C,Xr as w,Yr as T,dn as ee,fn as te,jr as ne,kr as re,mn as ie,pn as ae,un as oe,wr as E}from"./client-CRCWO8cg.js";import{Bu as se,Er as ce,Ga as D,Hu as le,Ou as ue,Pr as de,Wa as fe,bo as pe,fr as O,hr as k,pa as me,s as he,sa as ge}from"./src-_mtQMfPm.js";import{t as A}from"./i18n-DzruZdmx.js";import{t as j}from"./useTranslation-D3Is_4B6.js";e();function _e(e){return{target:{kind:`new`,type:e},name:``,features:[]}}function ve(e){return{target:{kind:`existing`,device:e},name:``,features:[]}}function M(e,t){return{target:e.target,name:t,features:e.features.flatMap(e=>e.kind===`fields`?[e]:[])}}function N(e,t,n){return{...e,features:e.features.map(e=>e.cap===t?n(e):e)}}function P(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>e!==t))}function ye(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 N(e,t.cap,e=>({...e,fields:{...e.fields,[t.path]:t.source}}));case`clear-field`:return N(e,t.cap,e=>({...e,fields:P(e.fields,t.path)}));case`remove-binding`:return N(e,t.cap,e=>{let n=e.fields[t.path];return n?.kind===`expression`?{...e,fields:{...e.fields,[t.path]:{...n,bindings:P(n.bindings,t.bindingName)}}}:e});case`copy-feature`:return N(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 be(e){let t=re.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 xe(e,t){return JSON.stringify(e)!==JSON.stringify(t)}function Se(e){for(let t=1;;t++){let n=`s${t}`;if(!e.includes(n))return n}}var Ce=[`room`,`converted-sensor`,`derived-binary`],F={addonId:`provider-homeassistant`,stableId:`sensor.template_source`};function we(){return M(ae({temperatureSources:ee,motionSources:oe,occupancyWindowMs:te}),`Room`)}function Te(){return M({target:{kind:`new`,type:w.Sensor},features:[{kind:`fields`,cap:`numeric-sensor`,fields:{value:{kind:`expression`,expr:`convert(v, "°C", "°F")`,bindings:{v:{kind:`from`,source:F,cap:`numeric-sensor`,fieldPath:`value`}}},unit:{kind:`expression`,expr:`"°F"`,bindings:{}},lastFetchedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Converted sensor`)}function Ee(){return M({target:{kind:`new`,type:w.Sensor},features:[{kind:`fields`,cap:`binary`,fields:{on:{kind:`expression`,expr:`v > 20`,bindings:{v:{kind:`from`,source:F,cap:`temperature-sensor`,fieldPath:`celsius`}}},lastChangedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Derived binary`)}function De(e){switch(e){case`room`:return we();case`converted-sensor`:return Te();case`derived-binary`:return Ee()}}function Oe(e,t){return typeof t==`number`&&Number.isFinite(t)&&t>0?{kind:`device`,path:`/devices/${t}`}:{kind:`editor`,path:`/build/compositions/${encodeURIComponent(e)}`}}var I=`rounded-lg border border-border bg-surface p-4`,ke=I;function Ae(e){return{addonId:e.addonId,stableId:e.stableId}}function L(e){return new Map(e.map(e=>[g(Ae(e)),e]))}function je(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 Me(e,t){let n=e.features.filter(e=>e.cap!==t);return n.length===0?null:{target:e.target,features:n}}function Ne(e,t){let n=e?.features.find(e=>e.cap===t);return n!==void 0&&n.kind===`fields`?n:null}function R(e){return Array.isArray(e)?e.map(R):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,R(t)]))}function z(e){return JSON.stringify(R(e))}function Pe(e,t){return z(e)===z(t)}function B(e,t){return z(e)===z(t)}function Fe(e,t){switch(e.kind){case`pending`:return{kind:`refused`,reason:A.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}:z(t)===z(e.composition)?{kind:`noop`}:{kind:`update`,blockId:n,expectedUpdatedAt:e.view.block.updatedAt,composition:t}}}}function V(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 H(e){return{kind:`expression`,expr:e,bindings:{}}}function U(e){let t=V(`number`,e.percentage);return t===null?null:{kind:`fields`,cap:`battery`,fields:e.mode===`replace`?{percentage:t}:{percentage:t,charging:H(`"unknown"`),sleeping:H(`false`),lastUpdated:H(`now`)}}}var Ie=[`percent`,...m.options];function W(e,t){return t===`percent`?{level:e}:{"remaining.value":e,"remaining.unit":H(JSON.stringify(t))}}function Le(e,t){let n=V(`number`,t.remaining);if(n===null||!b.test(t.key)||t.label.trim()===``)return null;let r={label:t.label.trim(),fields:W(n,t.unit)};return{kind:`fields`,cap:`consumables`,...e?.enabled===void 0?{}:{enabled:e.enabled},fields:e?.fields??{lastChangedAt:H(`now`),lastFetchedAt:H(`now`)},items:{...e?.items,[t.key]:r}}}function Re(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=m.safeParse(JSON.parse(t.expr));return e.success?e.data:null}catch{return null}}function ze(e){return Object.entries(e?.items??{}).map(([e,t])=>{let n=Re(t.fields),r=G(t.fields.level??t.fields[`remaining.value`]),i=r===null?null:V(`number`,r);return n!==null&&i!==null&&Pe(W(i,n),t.fields)?{key:e,label:t.label,unit:n,source:r}:{key:e,label:t.label,unit:null,source:null}})}function Be(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 Ve(e){return e.toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,48)}function He(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=>[g(e),e])).values()]}function Ue(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 G(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 We(e,t){let n=G(e.fields.percentage);if(n===null)return!1;let r=U({percentage:n,mode:t}),{enabled:i,...a}=e;return r!==null&&B(a,r)}function K(e){return e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,location:e.location,type:e.type}))}function Ge(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 q(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 Ke(e,t,n,r){return r===null?{kind:`from`,source:e,cap:t,fieldPath:n.path}:V(r,{source:e,cap:t,fieldPath:n.path,kind:n.kind})}function qe(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:q(n[e.cap],t.path),source:Ke(i,e.cap,t,r)})))}function J(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 Je=[];function Y({title:e,targetKind:t,excludeDeviceIds:r=Je,onPick:i,onCancel:o}){let{t:s}=j(),[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(Ye,{excludeDeviceIds:r,onSelect:p}):c(X,{device:f,targetKind:t,onPick:i,onBack:()=>p(null)}),c(`div`,{children:c(k,{variant:`ghost`,size:`sm`,onClick:o,children:s(`customize.picker.cancel`)})})]})}function Ye({excludeDeviceIds:e,onSelect:t}){let{t:r}=j(),[i,s]=n(``),l=D({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(ue,{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(O,{title:r(`customize.picker.devicesFailed`),message:l.error?.message??``}),l.status===`success`&&c(`ul`,{className:`flex flex-col gap-1`,children:Ge(K(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 X({device:e,targetKind:t,selected:n,onPick:r,onBack:i}){let{t:o}=j(),s=fe({deviceId:e.id}),l=pe({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(O,{title:o(`customize.picker.fieldsFailed`),message:s.error?.message??``});let u=qe(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:J(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 Xe=`integration`;function Z(e,t){switch(e.kind){case`from`:{let n=g(e.source);return`${t.get(n)??n} · ${e.cap}.${e.fieldPath}`}case`expression`:return e.expr;case`code`:return`code`}}function Ze(e,t){if(e.kind===`unreachable`)return{kind:`unknown`,reason:e.error};if(e.state===null)return{kind:`unknown`,reason:A.t(`helpers.fieldsTableRows.composerNotReported`)};let n=e.state.fields.find(t);return n===void 0?{kind:`unknown`,reason:A.t(`helpers.fieldsTableRows.noValue`)}:n.state===`unavailable`?{kind:`unavailable`,reason:n.reason??A.t(`common.unavailable`)}:{kind:`value`,value:n.value,staleReason:n.state===`stale`?n.reason??A.t(`common.stale`):null}}function Q(e,t,n,r){return{key:`${e.feature.cap}.${t}`,cap:e.feature.cap,field:t,origin:`composed`,mode:e.mode,from:Z(n,e.input.sourceNames),value:e.enabled?Ze(e.input.state,r):{kind:`off`}}}function Qe(e){let t=e.feature.cap;return Object.entries(e.feature.fields).map(([n,r])=>Q(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])=>Q(e,v(h,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:A.t(`helpers.fieldsTableRows.stateUnreadable`)};let r=q(e[t],n),i=r===void 0?void 0:S(r);return i===void 0?{kind:`unknown`,reason:A.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:Xe,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:ne(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=[...C].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}=j(),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:A.t(`helpers.fieldPreview.codeFields`)};if(e.kind===`expression`&&(E(e.expr,`rose`)||E(e.expr,`count`)))return{kind:`runtime-only`};let r=_(e).filter(e=>t.get(x(e.source,e.cap))?.kind!==`value`).map(y);if(r.length>0)return{kind:`waiting`,missing:r};let i=ie({source:e,now:n,read:e=>{let n=t.get(x(e.source,e.cap)),r=n?.kind===`value`?q(n.slice,e.fieldPath):void 0,i=r===void 0?void 0:S(r);return i===void 0?{state:`unavailable`,reason:A.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=he(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(_(e).map(e=>[x(e.source,e.cap),e]))].map(([e,n])=>({key:e,read:n,device:t.get(g(n.source))}))}function dt({source:e}){let{t}=j(),r=D({projection:`slim`}),[o,s]=n(new Map),l=i((e,t)=>{s(n=>new Map([...n,[e,t]]))},[]),u=ut(e,L(r.status===`success`?K(r.data):[])),d=r.status===`success`?u.filter(e=>e.device===void 0).map(e=>g(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}=j();switch(e.kind){case`value`:return a(`strong`,{children:[`→ `,J(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}=j(),[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(k,{size:`sm`,variant:`outline`,onClick:()=>m(`take`),children:f(`compositionEditor.takeFrom`)}),c(k,{size:`sm`,variant:`outline`,"aria-pressed":h!==null,onClick:()=>s(h??{kind:`expression`,expr:`null`,bindings:{}}),children:f(`compositionEditor.formula`)}),i!==void 0&&c(k,{size:`sm`,variant:`ghost`,onClick:l,children:f(`compositionEditor.clear`)})]}),i?.kind===`from`&&c(`span`,{className:`text-[11px]`,children:Z(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`?Z(t,d):JSON.stringify(t.value)}),c(k,{size:`sm`,variant:`ghost`,"aria-label":f(`compositionEditor.removeBinding`,{name:e}),onClick:()=>u(e),children:`×`})]},e))}),c(k,{size:`sm`,variant:`ghost`,onClick:()=>m(`add-binding`),children:f(`compositionEditor.addSource`)})]}),p!==`idle`&&c(Y,{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=Se(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}=j(),u=ge({deviceType:t}),d=D({projection:`slim`}),f=new Map([...L(d.status===`success`?K(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:`${I} 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(de,{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(k,{size:`sm`,variant:`outline`,onClick:()=>s({type:`add-feature`,cap:e.cap}),children:[`+ `,e.cap]},e.cap)),y.map(e=>c(k,{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:`${I} 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(k,{size:`sm`,variant:`outline`,onClick:()=>m(e.cap),children:l(`compositionEditor.copyFeature`)})]}),p===e.cap&&c(Y,{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:`${I} 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}=j(),o=e.target;return a(`section`,{"aria-labelledby":`editor-target`,className:`${I} 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(w).find(t=>t===e.target.value);t!==void 0&&n({type:`set-new-type`,deviceType:t})},children:Object.values(w).map(e=>c(`option`,{value:e,children:le(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(T).find(t=>t===e.target.value)??null}),children:[c(`option`,{value:``,children:i(`customize.identity.noRole`)}),Object.values(T).map(e=>c(`option`,{value:e,children:se(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}=j(),u=me(),d=be(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:`${I} 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(k,{variant:`ghost`,onClick:s,children:l(`compositionEditor.cancel`)}),c(k,{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(De(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}=j(),h=ce(),[g,_]=r(ye,e),[v,y]=n(!1),[b,x]=n(null),S=async t=>{xe(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`)}),Ce.map(e=>c(k,{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{Me as C,ve as D,M as E,_e as O,je as S,Oe as T,G as _,X as a,Fe as b,K as c,Le as d,ze as f,Ve as g,We as h,nt as i,Ie as l,Ue as m,ct as n,J as o,He as p,st as r,q as s,vt as t,U as u,Be as v,ke as w,B as x,Ne as y};
@@ -1,2 +0,0 @@
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-DyNPyo_W.js";import{n as M,t as N}from"./cloud-upload-I7yc63rr.js";import{t as P}from"./circle-slash-BTU53Q69.js";import{t as F}from"./hard-drive-download-BqS2ahXp.js";import{$n as I,Aa as ee,Ai as te,An as L,Bi as R,Cu as ne,Di as re,Dn as ie,Ei as ae,Er as z,Fi as oe,Ii as se,Li as ce,Mi as le,Mn as ue,Ni as de,Nl as fe,Oi as pe,Ou as me,Pi as he,Qn as ge,Ri as _e,Ti as ve,_l as ye,_n as be,at as xe,bl as Se,dt as Ce,er as B,fr as we,gn as Te,hr as V,ir as Ee,ji as De,ki as Oe,kn as ke,ku as H,li as Ae,lt as je,nr as Me,ol as Ne,pr as Pe,rr as Fe,ut as Ie,vl as Le,vt as U,yl as Re,zi as ze}from"./src-_mtQMfPm.js";import{t as W}from"./i18n-DzruZdmx.js";import{t as G}from"./useTranslation-D3Is_4B6.js";import"./mount-B0uThmDr.js";import{$ as Be,T as Ve,Z as He,nt as Ue}from"./index-2_qB4G1l.js";import{t as We}from"./AdminSectionedPage-DB1wuvwM.js";import{t as Ge}from"./AdminPage-CTKQzYSK.js";import{n as Ke}from"./authed-media-dGvmAGIm.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-Dqp8xgaw.js";e();function tt(){let{t:e}=G(),r=s(),i=z(),{data:o,isLoading:l,isError:u}=Se({}),d=Re(),f=n(()=>d.data??[],[d.data]),{data:p}=Ne({},{refetchOnWindowFocus:!1}),m=n(()=>$e(o??[],p?.locations),[o,p?.locations]),{data:h}=Le({},{refetchOnWindowFocus:!1}),g=n(()=>qe(h),[h]),{state:_,openNew:v,openEdit:y,close:b}=je(),[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=ye({onSuccess:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),k=fe({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=z(),{data:m,isLoading:h,isError:g}=De({destinationId:e}),_=m??[],v=ae({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(V,{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(V,{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(H,{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}=oe(),p=s??[],m=de().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(Pe,{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(H,{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=R({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=R({onSuccess:()=>{i.invalidateQueries({queryKey:yt})}}),o=wt(e),[l,u]=r(String(e.retentionCount));return t(()=>{u(String(e.retentionCount))},[e.retentionCount]),c(me,{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=z(),o=re({onSuccess:()=>{r.invalidateQueries({queryKey:yt})}}),u=ze({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(V,{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(H,{variant:`ghost`,size:`sm`,icon:d,"aria-label":n(`backup.backupEntriesTable.edit`,`Edit {{value1}}`,{value1:e.label||e.id}),onClick:t}),c(H,{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=le().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(ue,{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=ze({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(ge,{open:!0,onOpenChange:t=>!t&&e(),children:a(B,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(Fe,{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(Me,{children:[c(V,{variant:`outline`,size:`sm`,onClick:e,children:t(`common.cancel`,`Cancel`)}),a(V,{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(ge,{open:!0,onOpenChange:e=>!e&&i&&t(),children:a(B,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`border-danger/40`,"aria-labelledby":`backup-key-title`,children:[c(Fe,{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(V,{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(V,{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(Me,{children:c(V,{size:`sm`,disabled:!i,onClick:t,children:n(`backup.backupEncryptionCard.iHaveStoredIt`,`I have stored it`)})})]})})}function Pt(){let{t:e}=G(),t=Oe(),n=_e(),i=pe(),s=z(),[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(V,{size:`sm`,variant:`outline`,disabled:n.isPending,onClick:()=>void g(),children:e(`backup.backupEncryptionCard.replaceKey`,`Replace key`)}),c(V,{size:`sm`,variant:`outline`,disabled:i.isPending,onClick:()=>void _(),children:e(`backup.backupEncryptionCard.turnOff`,`Turn off`)})]}):c(V,{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=se({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=de(),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=R({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(Ce,{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(V,{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(me,{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(me,{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=z(),[t,n]=r(null),a=he(void 0,{refetchInterval:e=>(e.state.data??[]).some(Q)?Ut:Wt}),o=ve({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}=de(),T=w??[],{data:E,isLoading:D}=De({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}=te({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=ce({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),ne=!!m&&!!g,re=R||v.size>0,ie=ne&&re&&!N.isPending&&(!ee||S.trim().length>0),ae=()=>{!m||!g||N.mutate({destinationId:m,backupId:g,...R?{}:{locations:[...v]},...ee?{backupSecretKey:S.trim()}:{}})};return c(ge,{open:!0,onOpenChange:e=>!e&&o(),children:a(B,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(Fe,{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(Me,{className:`justify-between`,children:[c(`div`,{children:f>1&&a(V,{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(V,{variant:`outline`,size:`sm`,onClick:o,children:u(`common.cancel`,`Cancel`)}),f<3?a(V,{size:`sm`,disabled:f===1&&!ne||f===2&&!re,onClick:()=>p(e=>e===1?2:3),children:[u(`common.next`,`Next`),c(y,{className:`h-3 w-3`})]}):a(V,{size:`sm`,onClick:ae,disabled:!ie,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(ne,{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=z(),i=Ae(),{state:o,openNew:s,openEdit:u,close:d}=je({editKey:`edit`,newKey:`new`}),f=oe(),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(V,{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(V,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>_(!0),children:[c(j,{className:`h-3.5 w-3.5`}),e(`system.backup.restore`,`Restore…`)]}),a(V,{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(V,{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=z(),n=ee(),[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(V,{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(V,{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(ie,{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};
@@ -1,2 +0,0 @@
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-DyNPyo_W.js";import{Bn as ve,Dr as ye,Fr as G,Gr as be,In as xe,Jr as Se,Kr as Ce,Mr as K,Pr as we,Ti as Te,Tr as Ee,Vn as De,Xr as q,Yr as J,_ as Oe,_n as ke,an as Ae,cn as je,d as Me,gr as Ne,h as Pe,hn as Fe,ln as Ie,m as Le,mn as Re,on as ze,p as Be,rr as Ve,sn as He,v as Ue,wi as We,x as Ge,xr as Ke,zn as qe}from"./client-CRCWO8cg.js";import{t as Je}from"./archive-C3J7kPmp.js";import{i as Ye,n as Xe,r as Ze,t as Qe}from"./scan-eye-DSsbXKWH.js";import{t as $e}from"./bell-off-Df5MKmnk.js";import{t as et}from"./boxes-B4UVG1kT.js";import{n as tt}from"./video-BtFmM3eg.js";import{t as nt}from"./circle-slash-BTU53Q69.js";import{t as rt}from"./layers-CBNWlTsd.js";import{$ as it,$n as at,Ac as ot,An as st,Bu as ct,Cu as lt,Dn as ut,Ds as dt,Dt as ft,Er as pt,F as mt,Fn as ht,Fs as gt,Ft as _t,Fu as vt,G as yt,Ga as bt,Go as xt,Gt as St,Ha as Ct,Hc as wt,Hn as Tt,Ht as Et,Hu as Dt,In as Ot,Ir as kt,It as At,J as jt,Ju as Mt,K as Nt,Ka as Pt,Kt as Ft,La as It,Ln as Lt,Lr as Rt,Ls as zt,Ma as Bt,Mc as Vt,Mn as Ht,Mt as Ut,Mu as Wt,N as Gt,Nc as Kt,Nt as qt,Nu as Jt,Oa as Yt,On as Xt,Ou as Zt,Pc as Qt,Pn as $t,Pr as en,Qn as tn,Ra as nn,Rn as rn,Rt as an,Tn as on,Uo as sn,Ut as cn,Uu as ln,Va as un,Vt as dn,Wa as fn,Wo as pn,Wr as mn,Xt as hn,Y as gn,Yt as _n,Za as vn,Zn as yn,Zt as bn,a as xn,ac as Sn,an as Cn,ar as wn,ba as Tn,bt as En,c as Dn,ci as On,cr as kn,eo as An,er as jn,et as Mn,fa as Nn,fn as Pn,fr as Fn,ga as In,gn as Ln,go as Rn,gr as zn,gt as Bn,ha as Vn,hr as Y,i as Hn,ir as Un,jc as Wn,jn as Gn,jt as Kn,ju as qn,kc as Jn,kn as Yn,kt as Xn,ku as Zn,l as Qn,lc as $n,lr as er,mc as tr,mn as nr,na as rr,nr as ir,nt as ar,o as or,oa as sr,oc as cr,oo as lr,or as ur,po as dr,qt as fr,r as pr,rl as mr,rr as hr,s as gr,sa as _r,sc as vr,ta as yr,tt as br,uc as xr,va as Sr,wi as Cr,wn as wr,xr as Tr,ya as Er,yc as Dr,yn as Or,yo as kr,yt as Ar,zo as jr,zt as Mr}from"./src-_mtQMfPm.js";import{t as X}from"./i18n-DzruZdmx.js";import{t as Z}from"./useTranslation-D3Is_4B6.js";import"./mount-B0uThmDr.js";import{A as Nr,F as Pr,H as Fr,I as Ir,J as Lr,K as Rr,M as zr,N as Br,P as Vr,Q as Hr,U as Ur,V as Wr,W as Gr,X as Kr,Y as qr,Z as Jr,et as Yr,g as Xr,h as Zr,j as Qr,nt as $r,p as ei,q as ti,tt as ni}from"./index-2_qB4G1l.js";import{C as ri,D as ii,E as ai,S as oi,_ as si,a as ci,b as li,c as ui,d as di,f as fi,g as pi,h as mi,i as hi,l as gi,m as _i,n as vi,o as yi,p as bi,r as xi,s as Si,t as Ci,u as wi,v as Ti,x as Ei,y as Di}from"./CompositionEditor-ZIvK82Sw.js";import{_ as Oi,a as ki,c as Ai,d as ji,f as Mi,g as Ni,h as Pi,i as Fi,l as Ii,m as Li,n as Ri,o as zi,p as Bi,s as Vi,t as Hi,u as Ui,v as Wi,y as Gi}from"./ClusterStepModel-G54nm4iG.js";import"./useEventInvalidation-B0uThmDr.js";import{t as Ki}from"./use-stationary-objects-D_FqXLHG.js";import{a as qi,c as Ji,d as Yi,f as Xi,i as Zi,l as Qi,n as $i,o as ea,p as ta,r as na,s as ra,t as ia,u as aa}from"./linked-devices-model-Csh4WaVK.js";import{t as oa}from"./authed-media-dGvmAGIm.js";e();function sa(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 ca(e){if(typeof e!=`object`||!e)return null;let t=e.switches;if(!Array.isArray(t))return null;let n=t.map(sa).filter(e=>e!==null);return n.length===0?null:n}var la=[[/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 ua(e){for(let[t,n]of la)if(t.test(e))return n;return`generic`}function da(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(X.t(`helpers.cameraSwitchRows.off`,{list:r(t)})),n.length>0&&i.push(X.t(`helpers.cameraSwitchRows.unknown`,{list:r(n)})),{offIds:t,unknownIds:n,summary:i.length===0?X.t(`helpers.cameraSwitchRows.allOn`):i.join(` · `)}}var fa={stream:W,detection:Qe,privacy:f,microphone:N,speaker:k,listening:Xe,archive:Je,recording:Ze,notifications:D,generic:V};function pa({deviceId:e}){let{t}=Z(),n=c(),o=Number.isFinite(e),[s,l]=r(null),[u,f]=r(!1),p=xr({deviceId:e},{enabled:o});pr([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let m=ca(p.data),h=Qt({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 _=da(m),v=e=>s?.id===e.id?s.message:null;return a(qn,{open:u,onOpenChange:f,children:[a(Jt,{"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(Wt,{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(ma,{row:e,failure:v(e),onToggle:()=>g(e)})},e.id))})]})]})}function ma({row:e,failure:t,onToggle:n}){let{t:r}=Z(),i=fa[ua(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 ha({deviceId:e}){let t=an(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 ga({parentDeviceId:e}){let{t}=Z(),n=Yr(),r=U(),{data:i,isLoading:o,isError:s}=Gr(e),{data:c}=un({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=qt(c?.stableId??``,l,c?.childLayout),f=u.ungrouped,p=e=>n(`/devices/${String(e)}`),m=c?.name??``,h=(e,t)=>d(Kn,{trpc:r.trpcClient,device:{...t,name:Mr(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(Ut,{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(Ut,{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 _a({deviceId:e}){let t=U(),{data:n,isLoading:r}=Ur(e),{data:i,isLoading:a}=Gr(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(dn,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}e();function va({dev:e,busy:t,setBusy:n}){let{t:i}=Z(),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 Q({deviceId:e,deviceType:t,features:n}){let i=U(),o=St(t)?.HeroCard??Ft,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(cn,{lastChangedAt:p})}):null,d(o,{trpc:i.trpcClient,deviceId:e,features:n}),d(`div`,{className:`flex justify-center`,children:d(va,{dev:s,busy:l,setBusy:u})})]})}function ya({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(fr,{trpc:U().trpcClient,deviceId:e,features:t})})}function ba({deviceId:e,features:t}){return d(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:d(Ft,{trpc:U().trpcClient,deviceId:e,features:t})})}function xa(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function Sa(e){if(!e)return null;let t=xa(e.data);return t===null?e.eventType:X.t(`helpers.eventEmitterFormat.buttonHeadline`,{channel:String(t),eventType:e.eventType})}var Ca=1e3,wa=60*Ca,Ta=60*wa,Ea=24*Ta;function Da(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<Ca?X.t(`helpers.relativeTime.justNow`):n<wa?X.t(`helpers.relativeTime.secondsAgo`,{count:Math.floor(n/Ca)}):n<Ta?X.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(n/wa)}):n<Ea?X.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(n/Ta)}):X.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(n/Ea)})}e();var Oa=1500,ka=15e3,Aa=1e3;function ja({deviceId:e}){let{t:n}=Z(),i=C(U().trpcClient,e)?.state.eventEmitter,o=x(i);t(()=>{if(!i)return;i.refresh();let e=setInterval(()=>{i.refresh()},ka);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)},Oa);return()=>{clearTimeout(t)}},[c]);let[h,g]=r(()=>Date.now());t(()=>{let e=setInterval(()=>{g(Date.now())},Aa);return()=>{clearInterval(e)}},[]);let _=Sa(s),y=o?.eventTypes??[],b=o?.eventCountSinceStart??0,S=o!==void 0,w=xa(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?Da(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 Ma({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){let{t:o}=Z();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(qr,{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(ar,{status:r?`online`:`offline`}),i.length>0&&d(Kr,{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 Na({deviceId:e}){let{t}=Z(),r=c(),i=Vn({deviceId:e},{refetchInterval:1e4,retry:!1}),o=In({onSuccess:()=>{r.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),r.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),s=n(()=>Pa(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(Fa,{label:t(`hero.hubHero.discovered`,`Discovered`),value:s.total,icon:d(_e,{className:`h-3.5 w-3.5`})}),d(Fa,{label:t(`hero.hubHero.adopted`,`Adopted`),value:s.adopted,accent:`success`}),d(Fa,{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(Ia,{icon:d(ie,{className:`h-3 w-3 text-emerald-500`}),label:t(`hero.hubHero.online`,`{{online}} online`,{online:s.online})}),d(Ia,{icon:d(w,{className:`h-3 w-3 text-amber-500`}),label:t(`hero.hubHero.sleeping`,`{{sleeping}} sleeping`,{sleeping:s.sleeping})}),d(Ia,{icon:d(L,{className:`h-3 w-3 text-destructive`}),label:t(`hero.hubHero.offline`,`{{offline}} offline`,{offline:s.offline})}),s.unknown>0?d(Ia,{icon:d(fe,{className:`h-3 w-3 text-foreground-subtle`}),label:t(`hero.hubHero.unknown`,`{{unknown}} unknown`,{unknown:s.unknown})}):null]})]})}function Pa(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 Fa({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 Ia({icon:e,label:t}){return a(`span`,{className:`inline-flex items-center gap-1`,children:[e,d(`span`,{children:t})]})}var La={[q.Switch]:Q,[q.Siren]:Q,[q.Light]:Q,[q.Sensor]:Q,[q.Button]:Q,[q.Hub]:Na,[q.Cover]:ya,[q.Valve]:Q,[q.Humidifier]:Q,[q.WaterHeater]:Q,[q.Container]:_a,[q.Lock]:Q,[q.Fan]:Q,[q.Thermostat]:Q,[q.Climate]:Q,[q.MediaPlayer]:Q,[q.Control]:Q,[q.AlarmPanel]:Q,[q.EventEmitter]:ja,[q.Notifier]:ba,[q.Script]:Q,[q.Automation]:Q,[q.Presence]:Q,[q.Update]:Q,[q.Vacuum]:Q,[q.LawnMower]:Q,[q.Weather]:Q,[q.Image]:Q,[q.PetFeeder]:Q,[q.Dishwasher]:Q};function Ra(e){return La[e]??Ma}function za(e){return d(Ra(e.deviceType),{...e})}function Ba(e){return or(U().trpcClient,e)}e();function Va(e){let[n,a]=r(`idle`),[o,s]=r(null),c=l(null),u=l(null),d=l(null),f=l(!0),p=pn(),m=sn(),h=xt(),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 Ha=0;function $(){return++Ha}function Ua(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Wa(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 Ga(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 Ka(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 qa({scope:e,greeting:n,className:o}){let{t:s}=Z(),c=U(),[f,p]=r(()=>{let t=[];return n&&t.push({id:$(),kind:`info`,text:n}),t.push({id:$(),kind:`info`,text:`scope: ${Ua(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:$(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);p(e=>[...e,{id:$(),kind:`error`,text:t}])}});function w(t){let n=t.trim();if(n){if(n===`clear`){p([{id:$(),kind:`info`,text:`scope: ${Ua(e)}`}]),h(``);return}if(n===`help`){p(t=>[...t,{id:$(),kind:`input`,text:`> ${n}`},...Wa(e).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}if(n===`context`){p(t=>[...t,{id:$(),kind:`input`,text:`> ${n}`},...Ka(e).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}if(n===`examples`){p(t=>[...t,{id:$(),kind:`input`,text:`> ${n}`},...Ga(e).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}_(e=>[...e,n]),y(-1),p(e=>[...e,{id:$(),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:$(),kind:`info`,text:`scope: ${Ua(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 Ja(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 Ya({deviceId:e,intercomAvailable:t=!1}){let r=U(),i=typeof window<`u`?F():``,a=Number.isFinite(e),o=Ba(a?e:null),c=Ki(a?[e]:[]),l=n(()=>{if(!a)return;let e=[];for(let t of c.rows){let n=xn(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}=Pn(r.trpcClient,a?e:null),C=_(a?e:null,{width:eo}),w=Va(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=er(),A=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,j=Ja(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(yt,{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 Xa({deviceId:e,containerDeviceId:t}){let{t:n}=Z();return Number.isFinite(e)?d(`div`,{className:`flex flex-col h-full`,children:d(bn,{...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 Za({deviceId:e}){let{t}=Z();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(qa,{scope:{type:`device`,deviceId:e},greeting:n,className:`h-full border-0 rounded-none`})}function Qa({deviceId:e}){let{t}=Z();return Number.isFinite(e)?d(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:d(hn,{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 $a({deviceId:e}){let{t}=Z();return Number.isFinite(e)?d(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:d(_n,{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 eo=960;function to(e){return new Set(e.filter(e=>{let t=e.nativeAddonId?.trim()??``;return t!==``&&t!==`composer`}).map(e=>e.capName))}function no(e){return e.kind===`known`?null:e}function ro(e,t){return e.composable.kind===`known`?e.composable.value.has(t)?{kind:`present`,mode:`add`}:{kind:`absent`}:e.composable}function io(e){if(e.deviceType!==q.Camera)return{kind:`absent`};switch(e.cameraSensors){case`pending`:return{kind:`pending`};case`unknown`:return{kind:`unknown`,reason:X.t(`helpers.assignmentAvailability.sensorsUnchecked`)};case`absent`:return{kind:`absent`};case`present`:return{kind:`present`,mode:`add`}}}function ao(e,t){if(e===`motion`)return io(t);let n=no(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`}:ro(t,`doorbell`);case`battery`:return r.has(`battery`)?{kind:`present`,mode:`replace`}:ro(t,`battery`);case`consumables`:return r.has(`consumables`)?{kind:`absent`}:ro(t,`consumables`)}}function oo({onAdvanced:e}){let{t}=Z();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 so(e){if(e.status===`pending`)return{kind:`pending`};if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??X.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=Ke(t.view.block);return n===null?{kind:`unknown`,reason:X.t(`helpers.customizationRead.notAComposition`,{id:t.view.block.id})}:{kind:`present`,view:t.view,composition:n}}function co(e){return e.kind===`present`?e.composition:null}function lo(e,t){let{hidden:n,...r}=e??{},i=t?{...r,hidden:!0}:r;return Object.keys(i).length===0?null:i}function uo(e){return typeof e.linkDeviceId==`number`}var fo=new Set(Object.values(J));function po(e){return fo.has(e)}var mo={[q.Switch]:[J.Siren,J.Floodlight,J.Spotlight,J.PirSensor,J.Chime,J.Autotrack,J.Nightvision,J.PrivacyMask,J.BinaryHelper],[q.Light]:[J.Floodlight,J.Spotlight,J.Nightvision],[q.Siren]:[J.Siren],[q.Button]:[J.Doorbell],[q.Sensor]:[J.MotionSensor,J.ContactSensor,J.LeakSensor,J.SmokeSensor,J.COSensor,J.GasSensor,J.TamperSensor,J.VibrationSensor,J.ConnectivitySensor,J.SoundSensor,J.BinarySensor,J.TemperatureSensor,J.HumiditySensor,J.AmbientLightSensor,J.PressureSensor,J.WindSensor,J.RainSensor,J.UvSensor,J.SolarRadiationSensor,J.SoilMoistureSensor,J.PowerSensor,J.EnergySensor,J.VoltageSensor,J.CurrentSensor,J.AirQualitySensor,J.BatterySensor,J.NumericSensor,J.EnumSensor,J.DateTimeSensor,J.GenericSensor],[q.Control]:[J.NumericControl,J.SelectControl,J.TextControl,J.DateTimeControl],[q.Notifier]:[J.MobilePushNotifier,J.MessagingNotifier,J.EmailNotifier,J.GenericNotifier]};function ho(e){for(let t of Object.values(q))if(t===e)return!0;return!1}function go(e){return ho(e)?mo[e]??[]:[]}function _o(e,t){let n=go(t);return e==null||e===``||n.includes(e)?n:[...n,e]}e();function vo({device:e}){let{t}=Z(),n=ne(),i=c(),[o,s]=r(null),l=()=>s(null),u={onSuccess:()=>{l(),i.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>s(e.message)},f=dr(),p=lr(),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(ti,{deviceId:e.id,initialName:e.name,label:t(`customize.identity.name`),layout:`stacked`,onError:s,onSaved:l,onCancel:l}),d(Rr,{deviceId:e.id,initialLocation:e.location,label:t(`customize.identity.room`),layout:`stacked`,onError:s,onSaved:l,onCancel:l}),d(Lr,{label:t(`customize.identity.hidden`),layout:`stacked`,value:d(Ht,{"aria-label":t(`deviceDisplay.hideFromLists`),checked:m,disabled:p.isPending,onChange:t=>p.mutate({deviceId:e.id,display:lo(e.display,t.target.checked)},u)})}),d(Lr,{label:t(`customize.identity.role`),layout:`stacked`,value:uo(e)?d(`span`,{children:yo(e.role,t(`customize.identity.noRole`),n)}):d(lt,{"aria-label":t(`customize.identity.role`),value:e.role??``,disabled:f.isPending,options:[{value:``,label:t(`customize.identity.noRole`)},..._o(e.role,e.type).map(e=>({value:e,label:yo(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 yo(e,t,n){return e==null||e===``?t:po(e)?ct(e,n).label:e}e();function bo(e){return e===`pending`?`pending`:e===`error`?`failed`:`answered`}function xo({excludeDeviceIds:e,onSelect:t}){let{t:r}=Z(),i=bt({projection:`slim`}),a=i.status===`success`?i.data:null,o=n(()=>{if(a===null)return[];let t=new Set(e);return ui(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(Fn,{title:r(`customize.picker.devicesFailed`),message:i.error?.message??``});let l=e=>{let n=s.get(e);n!==void 0&&t(n)};return d(mt,{devices:c,listState:bo(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 So({open:e,title:t,targetKind:n,excludeDeviceIds:i,confirmLabel:o,extra:c,extraComplete:l=!0,onConfirm:u,onClose:f}){let{t:p}=Z(),[m,h]=r(null),[g,_]=r(null),v=()=>{h(null),_(null),f()};return d(tn,{open:e,onOpenChange:e=>e?void 0:v(),children:a(jn,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":t,children:[d(hr,{children:d(Un,{children:t})}),d(at,{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(xo,{excludeDeviceIds:i,onSelect:h}):a(`p`,{className:`flex items-center gap-2 text-xs text-foreground`,children:[m.name,d(Y,{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(ci,{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(ir,{children:[d(Y,{variant:`ghost`,onClick:v,children:p(`customize.assign.cancel`)}),d(Y,{disabled:g===null||!l,onClick:()=>{g!==null&&(u(g),h(null),_(null))},children:o})]})]})})}function Co(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function wo(e,t){let n=Si(e,t);return n===void 0?{kind:`absent`}:{kind:`value`,value:n}}function To(e,t,n){return Co(t)?wo(t,n):e.status===`error`?{kind:`unknown`,reason:e.error?.message??X.t(`helpers.liveValue.unreadable`)}:e.status===`pending`||e.data===void 0?{kind:`pending`}:e.data===null?{kind:`absent`}:wo(e.data,n)}function Eo(e,t,n){let r=e?`active`:`muted`;return t.cap===`contact`&&t.path===`entryOpen`?{text:e?n.open:n.closed,tone:r}:Ce[t.cap]===t.path?{text:e?n.active:n.inactive,tone:r}:{text:String(e),tone:`normal`}}function Do(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`?Eo(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 Oo=0;function ko(e){let t=U(),n=kr({deviceId:e?.deviceId??Oo,capName:e?.cap??``},{enabled:e!==null}),r=gr(t.trpcClient,e?.deviceId??null,e?.cap??``);return e===null?{kind:`absent`}:To({status:n.status,data:n.data,error:n.error===null||n.error===void 0?null:{message:n.error.message}},r,e.path)}var Ao={muted:`text-foreground-subtle`,active:`text-success`,normal:`text-foreground`,warning:`text-warning`};function jo({target:e}){let{t}=Z(),n=ko(e);return e===null?null:d(Mo,{display:Do(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 Mo({display:e}){return d(`span`,{className:`text-xs ${Ao[e.tone]}`,title:e.title,children:e.text})}function No({name:e,detail:t,meta:n,value:r,shown:i,problem:o,onRemove:s,removeLabel:c,busy:l=!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}),o!==void 0&&d(`div`,{role:`alert`,className:`text-[11px] text-warning break-words`,children:o})]}),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:i===void 0?d(jo,{target:r}):i!==null&&d(Mo,{display:i})}),d(`div`,{className:`row-start-1 col-start-2 flex justify-end sm:row-start-auto sm:col-start-auto`,children:s!==void 0&&d(Zn,{icon:B,variant:`ghost`,size:`sm`,"aria-label":c,disabled:l,onClick:s})})]})}function Po({id:e,...t}){return d(nr,{headingId:`customize-${e}`,...t})}function Fo({id:e,icon:t,title:n,headerControl:r,addLabel:i,onAdd:o,addDisabled:c=!1,notices:l,suggestion:u,children:f}){let{t:p}=Z(),m=o!==void 0&&i!==void 0;return a(Po,{id:e,icon:t,title:n,actions:a(s,{children:[r,m&&!c&&u!==void 0&&u.count>0&&a(Y,{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(Y,{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 Io({availability:e}){let{t}=Z();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 Lo(e,t){if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??X.t(`helpers.customize.requestFailed`)};let n=e.data;return e.status===`pending`||n===void 0?{kind:`pending`}:{kind:`known`,value:t(n)}}function Ro(e,t){let n=Mt.useQueries(n=>e.map(e=>n.deviceManager.listDeviceIdsByCaps({capNames:[e]},{enabled:t})));return aa(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 zo(e,t){let n=Xn(e,t);return n.kind===`resolved`?n.integration.name:null}function Bo(e){let t=bt({projection:`slim`},{enabled:e}),{data:r}=jr(void 0,{enabled:e}),i=t.error===null||t.error===void 0?null:t.error.message;return n(()=>Lo({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:zo(e,r),parentDeviceId:e.parentDeviceId,primaryChildEntityId:e.primaryChildEntityId??null,role:e.role??null}))),[t.status,t.data,i,r])}function Vo(e){let t=Bo(e.enabled),n=Ro(be,e.enabled);return t.kind===`unknown`?t:n.kind===`unknown`?n:t.kind===`pending`||n.kind===`pending`?{kind:`pending`}:{kind:`known`,value:ta({devices:t.value,capIndex:n.value,hostId:e.hostId,excludeCameras:e.excludeCameras,assigned:e.assigned,preferredCap:e.preferredCap})}}function Ho(){let{t:e}=Z(),t=pt();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 Uo(e){return e===null?null:mi(e,`replace`)?`replace`:mi(e,`add`)?`add`:null}function Wo({device:e,handle:t,availability:n,onAdvanced:i}){let{t:o}=Z(),c=Ho(),[l,u]=r(!1),[f,p]=r(null),m=co(t.state),h=Di(m,`battery`),g=Uo(h),_=g===null?null:si(h?.fields.percentage),v=Bo(_!==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=ri(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(Fo,{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(Io,{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(No,{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(No,{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(No,{name:o(`customize.battery.otherFormula`),detail:null,meta:d(oo,{onAdvanced:i}),value:{deviceId:e.id,cap:`battery`,path:`percentage`},removeLabel:``})]}),d(So,{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:wi({percentage:{source:e.ref,cap:e.cap,fieldPath:e.path,kind:e.kind},mode:b});n===null?p(o(`customize.assign.pickUnusable`)):w(oi(m,t.target,n))},onClose:()=>u(!1)})]})}e();function Go(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 Ko(e){let t=typeof e==`number`?e:typeof e==`string`?Number(e):NaN;return Number.isFinite(t)?t:null}function qo({device:e,handle:t,availability:n,onAdvanced:i}){let{t:o}=Z(),c=Ho(),[l,u]=r(!1),[f,p]=r(``),[m,h]=r(`percent`),[g,_]=r(null),v=co(t.state),y=Di(v,`consumables`),b=fi(y),x=Bo(b.some(e=>e.source!==null));if(n.kind===`absent`)return null;let S=t.state.kind===`none`||t.state.kind===`present`,C=n.kind===`present`&&S&&!t.saving,w=pi(f),T=b.find(e=>e.key===w)??null,E=T!==null,D=f.trim()!==``&&w===``,k=async e=>{let n=await t.save(e);_(n.kind===`refused`?n.reason:null)},A=()=>{u(!1),p(``),h(`percent`)},j=async e=>{if(y===null||v===null)return;let n=Ti(y,e.key),r=n===null?ri(v,`consumables`):oi(v,t.target,n);await c(o(`customize.consumables.removeWhat`,{name:e.label}),r===null)&&await k(r)},M=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:[o(`customize.consumables.name`),d(Zt,{"aria-label":o(`customize.consumables.name`),value:f,onChange:e=>p(e.target.value)})]}),a(`label`,{className:`flex w-full flex-col gap-1 text-[11px] text-foreground-subtle sm:w-40`,children:[o(`customize.consumables.unit`),d(lt,{"aria-label":o(`customize.consumables.unit`),value:m,options:gi.map(e=>({value:e,label:o(`customize.consumables.units.${e}`)})),onChange:e=>{let t=gi.find(t=>t===e.target.value);t!==void 0&&h(t)}})]}),E&&d(`p`,{role:`alert`,className:`basis-full text-xs text-warning`,children:o(`customize.consumables.takenBy`,{name:T.label})}),D&&d(`p`,{role:`alert`,className:`basis-full text-xs text-warning`,children:o(`customize.consumables.keyless`)})]});return a(s,{children:[a(Fo,{id:`consumables`,icon:O,title:o(`customize.consumables.title`),addLabel:o(`customize.consumables.add`),onAdd:C?()=>u(!0):void 0,notices:a(s,{children:[d(Io,{availability:n}),x.kind===`unknown`&&b.some(e=>e.source!==null)&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:o(`customize.assign.devicesUnreadable`,{reason:x.reason})}),g!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:g})]}),children:[b.map(e=>{let n=e.source;if(e.unit===null||n===null)return d(No,{name:e.label,detail:o(`customize.consumables.otherFormula`),meta:d(oo,{onAdvanced:i}),value:null,removeLabel:``},e.key);let r=Go(e,x),a=r?.name??G(n.source);return d(No,{name:e.label,detail:`${o(`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&&x.kind===`known`?o(`customize.assign.missingKept`):void 0,onRemove:S?()=>void j(e):void 0,removeLabel:o(`customize.assign.removeNamed`,{name:e.label}),busy:t.saving},e.key)}),b.length===0&&n.kind===`present`&&S&&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(So,{open:l,title:o(`customize.consumables.pickTitle`),targetKind:`number`,excludeDeviceIds:[e.id],confirmLabel:o(`customize.assign.add`),extra:M,extraComplete:w!==``&&!E,onConfirm:e=>{let n=Ko(e.value);if(n!==null&&(n<0||m===`percent`&&n>100)){A(),_(o(`customize.consumables.outOfRange`,{value:n}));return}let r=di(y,{key:w,label:f,remaining:{source:e.ref,cap:e.cap,fieldPath:e.path,kind:e.kind},unit:m});A(),r===null?_(o(`customize.assign.pickUnusable`)):k(oi(v,t.target,r))},onClose:A})]})}function Jo(e,t){if(e.kind!==`known`||typeof t!=`string`||t.length===0)return null;let n=Rt(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 Yo(e,t,n){return kt(e,t?.ids??new Set,n)}function Xo(e,t){return e?.containers.get(t)??null}function Zo(e,t,n){return e.kind===`known`?Yo(e.value,t,n).suggested.length:0}function Qo(e,t){let n=[t,e.detail].filter(e=>e!==null&&e!==``);return n.length===0?null:n.join(` · `)}function $o({location:e,devices:t,action:n,onPick:r,onPickAll:i}){let{t:o}=Z();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(Y,{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=Qo(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(Y,{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 es(e){return e.kind===`pending`?`pending`:e.kind===`unknown`?`failed`:`answered`}function ts(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 ns({open:e,title:i,selection:o,candidates:s,filters:c,room:l=null,confirmLabel:u,onConfirm:f,onClose:p}){let{t:m}=Z(),[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`?Yi(s.value,``,y):[],S=Yo(b,l,e=>e.deviceId).suggested,C=Yo(x,l,e=>e.deviceId).others,w=n(()=>ts(C),[C]),T=es(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(tn,{open:e,onOpenChange:e=>e?void 0:D(),children:a(jn,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":i,children:[d(hr,{children:d(Un,{children:i})}),a(at,{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($o,{location:l.location,devices:S.map(e=>({id:e.deviceId,name:e.name,container:Xo(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(mt,{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(ir,{children:[d(Y,{variant:`ghost`,onClick:D,children:m(`customize.picker.cancel`)}),d(Y,{disabled:E.length===0,onClick:k,children:u(E.length)})]})]})})}function rs(e){if(e===null)return[];let t=_i(e);return bi(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 is(e,t){let n=_i(e);if(n.length===0)return!1;let{enabled:r,...i}=e,{enabled:a,...o}=je({camera:t,sources:n,enabled:!0});return Ei(i,o)}function as(e){return e?.enabled!==!1}function os(e,t,n){let r=[...e===null?[]:_i(e),...n.flatMap(e=>Ie(e.ref,e.caps))];return r.length===0?null:je({camera:t,sources:r,enabled:as(e)})}function ss(e,t,n){let r=_i(e).filter(e=>G(e.source)!==n);return r.length===0?null:je({camera:t,sources:r,enabled:as(e)})}function cs(e,t){return{...e,enabled:t}}e();function ls({device:e,handle:t,availability:n,onAdvanced:i}){let{t:o}=Z(),c=Ho(),[l,u]=r(!1),[f,p]=r(null),m=co(t.state),h=Di(m,`doorbell`),g=h===null||is(h,t.target),_=g?rs(h):[],v=Bo(_.length>0),y=Vo({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:ri(m,`doorbell`):oi(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=ss(h,t.target,e.key),i=r===null&&ri(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(Fo,{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(Ht,{"aria-label":o(`customize.doorbell.active`),checked:h.enabled!==!1,disabled:!x,onChange:e=>void C(cs(h,e.target.checked))}),o(`customize.doorbell.active`)]}),addLabel:o(`customize.doorbell.add`),onAdd:S?()=>u(!0):void 0,notices:a(s,{children:[d(Io,{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=Xi(e.caps,null),a=i===null?void 0:Ce[i];return d(No,{name:r,detail:n===null?null:Qi(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(No,{name:o(`customize.doorbell.otherFormula`),detail:null,meta:d(oo,{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(ns,{open:l,title:o(`customize.doorbell.pickTitle`),selection:`multi`,candidates:y,confirmLabel:e=>o(`customize.assign.addCount`,{count:e}),onConfirm:e=>{u(!1),C(os(h,t.target,e.map(e=>({ref:e.ref,caps:e.caps}))))},onClose:()=>u(!1)})]})}e();function us(e,t){let r=typeof e==`string`&&e.length>0,i=Bo(t&&r);return n(()=>t?Jo(i,e):null,[t,i,e])}e();function ds(e){return e==null?null:e.message}function fs({device:e}){let t=ne(),{t:n}=Z(),i=c(),o=Ho(),l=Ve.includes(e.type),[u,f]=r(!1),[p,m]=r(!1),[h,g]=r(null),_=Er({deviceId:e.id},{enabled:l}),v=na({status:_.status,data:_.data,error:ds(_.error)===null?null:{message:ds(_.error)??``}}),y=v.kind===`present`?v.slot.slotRef:``,b=v.kind===`present`?[...$i(v.slot,v.value).map(e=>e.deviceId),...Zi(v.slot,v.value)]:[],x=Tn(),S=Bo(l&&v.kind===`present`&&(u||b.length>0)),C=us(e.location,l&&v.kind===`present`),w=Sr({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(Fo,{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:Qi(n.integration,n.location),orphan:t}},k=[...$i(v.slot,T).map(e=>O(e,!1)),...Zi(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:ds(w.error)??n(`helpers.customize.requestFailed`)}:S.kind===`pending`||w.status===`pending`||w.data===void 0?{kind:`pending`}:{kind:`known`,value:ia(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(ra(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?`—`:Dt(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(Gn,{checked:e.tracked,disabled:p,"aria-label":n(`customize.linked.trackFor`,{name:e.name??e.deviceId}),onCheckedChange:t=>void M(ea(T,e.deviceId,t))})}]:[],{key:`remove`,header:``,cellClassName:`text-right w-10`,cell:e=>e.implied||e.orphan?null:d(Zn,{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(Fo,{id:`linked`,icon:ae,title:n(`customize.linked.title`),addLabel:n(`customize.linked.add`),onAdd:p?void 0:()=>f(!0),...C===null?{}:{suggestion:{count:Zo(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(ft,{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:Dt(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(ns,{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(qi(T,e.map(e=>e.deviceId)))},onClose:()=>f(!1)})]})}function ps(e){return e===null||e.state===`unreadable`?null:e.state===`configured`?e.sensors:[]}function ms(e){return{addonId:e.addonId,stableId:e.stableId,mode:e.mode}}function hs(e){return e.length===0?null:{sensors:[...e]}}function gs(e,t){let n=new Set(e.map(De));return hs([...e.map(ms),...t.filter(e=>!n.has(De(e))).map(e=>({...e,mode:ve}))])}function _s(e,t,n){return hs(e.map(e=>De(e)===t?{...ms(e),mode:n}:ms(e)))}function vs(e,t){return hs(e.filter(e=>De(e)!==t).map(ms))}function ys(e){return e?.state===`configured`&&e.cameraMotion!==void 0}function bs(e){return e===null||e.state===`unreadable`?null:e.state===`configured`?e.cameraMotion??`always`:`always`}function xs(e){return e===null||e.state===`unreadable`?!1:e.state===`not-configured`||ys(e)}function Ss(e){return e?.state===`configured`&&(e.notForwarded!==void 0||e.notEnforced!==void 0)}function Cs(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 ws=5e3;function Ts(e){return e.state===`missing`||e.state===`unreadable`?e.stableId:e.name}function Es({device:e,availability:n,sensors:i}){let{t:o}=Z(),c=Ho(),u=ot(),[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()},ws);return()=>clearInterval(e)},[]);let C=ps(x);t(()=>{x!==null&&b(!1)},[x]);let w=i.presence===`present`&&xs(x)&&!y?C:null,T=Bo(C!==null&&C.length>0),E=Vo({hostId:e.id,excludeCameras:!0,assigned:new Set((C??[]).map(De)),preferredCap:`motion`,enabled:f});if(n.kind===`absent`)return null;let D=ys(x),O=Ss(x)?`passes`:bs(x),k=Cs(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:Ts(e)}),!1)&&await M(vs(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:Qi(t.integration,t.location)};return a(s,{children:[a(Fo,{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(Io,{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`&&!xs(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(No,{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=Ts(e),r=e.state===`ready`?Xi(e.caps,`motion`):null,i=r===null?void 0:Ce[r];return d(No,{name:n,detail:N(e),meta:D&&w!==null?d(lt,{"aria-label":o(`customize.motion.modeFor`,{name:n}),value:e.mode,disabled:j,options:qe.options.map(e=>({value:e,label:o(`customize.motion.mode.${e}`)})),onChange:e=>{let n=qe.safeParse(e.target.value);n.success&&w!==null&&M(_s(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(ns,{open:f,title:o(`customize.motion.pickTitle`),selection:`multi`,candidates:E,filters:Ji,confirmLabel:e=>o(`customize.assign.addCount`,{count:e}),onConfirm:e=>{if(p(!1),w===null)return;let t=gs(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 Ds={"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`}},Os=new Set([q.Camera]);function ks(e){return e.unitField===null?[e.fieldPath]:[e.fieldPath,e.unitField]}function As(e,t){if(Os.has(e))return{kind:`absent`};let n=null;for(let[e,r]of Object.entries(Ds))if(t.has(e)){n={cap:e,fieldPath:r.fieldPath,unitField:r.unitField};break}let r=null;for(let e of Ae)if(t.has(e)){let t=Ce[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 Fe(e.from,e.to)?ze(e):null}function Ms(e){return He(e)}var Ns=/^convert\(v,\s*"[^"]*",\s*"[^"]*"\)$/;function Ps(e){return e!==void 0&&Ns.test(e.expr)}function Fs(e){return e===void 0||e.expr===`!v`||Ns.test(e.expr)?!1:e.bindings.v!==void 0}function Is(e){let t=e.expr.trim();if(t===``)return{kind:`refused`,reason:X.t(`helpers.numericTransforms.emptyExpression`)};let n={kind:`expression`,expr:t,bindings:{v:{kind:`from`,source:e.self,cap:e.cap,fieldPath:e.fieldPath}}},r=Re({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 Ls(e,t,n){if(e===null)return null;let r=Di(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?ri(e,n.cap):oi(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 Rs(e){if(typeof e!=`object`||!e)return;let t=Reflect.get(e,`unit`);return typeof t==`string`?t:void 0}function zs(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 Bs(e,t){let n=Di(e,t.cap);if(n===null)return;let r=n.fields[t.fieldPath];return r!==void 0&&r.kind===`expression`?r:void 0}function Vs(e,t){let n=Bs(e,t);return n===void 0||!Ps(n)?null:/^convert\(v,\s*"[^"]*",\s*"([^"]*)"\)$/.exec(n.expr)?.[1]??null}function Hs(e,t){let n=Bs(e,t);return n===void 0||!Fs(n)?null:n.expr}function Us(e,t,n){let r=Di(e,t);if(r===null)return!1;let i=r.fields[n];return i!==void 0&&i.kind===`expression`&&i.expr===`!v`}function Ws(e){return typeof e==`number`||typeof e==`boolean`||typeof e==`string`?String(e):e===null?`null`:JSON.stringify(e)}function Gs({device:e,target:t,handle:n,facts:i}){let{t:o}=Z(),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:As(e.type,g),v=_?.kind===`present`?_.convert?.cap??``:``,y=gr(s.trpcClient,e.id,v);if(i.nativeCaps.kind===`pending`)return d(`section`,{className:`${T} ${h}`,children:d(Io,{availability:{kind:`pending`}})});if(i.nativeCaps.kind===`unknown`)return d(`section`,{className:`${T} ${h}`,children:d(Io,{availability:{kind:`unknown`,reason:i.nativeCaps.reason}})});if(_===null||_.kind===`absent`)return null;let b=co(n.state),x=_.convert,S=_.invert,C=x===null?void 0:Rs(y),w=C===void 0?void 0:Ne(C)??C,E=w===void 0?void 0:ke(w),D=x===null?null:Vs(b,x),O=x===null?null:Hs(b,x),k=p??O??``,A=S===null?!1:Us(b,S.cap,S.fieldPath),j=n.state.kind===`none`||n.state.kind===`present`,M=x===null?0:zs(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:vi(ee,new Map([[we(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(oi(b,t,e))},te=async()=>{x!==null&&(await P(Ls(b,t,x)),f(``))},I=async()=>{if(x===null)return;let e=Is({self:t,cap:x.cap,fieldPath:x.fieldPath,expr:k,probe:M});if(e.kind===`refused`){l(e.reason);return}f(``),await P(oi(b,t,e.feature))},L=async()=>{x!==null&&(await P(Ls(b,t,x)),m(``))},R=async()=>{if(S===null)return;let e=Ms({self:t,cap:S.cap});if(e===null){l(o(`customize.numericTransforms.invertRefused`));return}await P(oi(b,t,e))},ne=async()=>{S===null||b===null||await P(ri(b,S.cap))};return d(Po,{id:`numeric-transforms`,icon:Ye,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(Gt,{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(Y,{size:`sm`,disabled:!j||n.saving||w===void 0||u===``||u===w,onClick:()=>void F(),children:o(`customize.numericTransforms.applyConvert`)}),D!==null&&d(Y,{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(xi,{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:Ws(M),result:Ws(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(Y,{size:`sm`,disabled:!j||n.saving||k.trim()===``,onClick:()=>void I(),children:o(`customize.numericTransforms.applyScript`)}),O!==null&&d(Y,{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(Y,{size:`sm`,variant:`outline`,disabled:!j||n.saving,onClick:()=>void ne(),children:o(`customize.numericTransforms.clearInvert`)}):d(Y,{size:`sm`,disabled:!j||n.saving,onClick:()=>void R(),children:o(`customize.numericTransforms.applyInvert`)})})]})]})})}e();function Ks(e){return e instanceof Error?e.message:String(e)}function qs(e){let t=sr({addonId:e.addonId,stableId:e.stableId}),n=yr(),i=Nn(),a=rr(),o=so({status:t.status,data:t.data,error:t.error===null||t.error===void 0?null:{message:t.error.message}}),{t:s}=Z(),c=l(!1),[u,d]=r(!1),f=async e=>{let r=li(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:Ks(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 Js=`pipeline-orchestrator`;function Ys(e){return e.status===`pending`?`pending`:e.status===`error`?`unknown`:e.data===void 0?`pending`:e.data.cameraSensors===void 0?`absent`:`present`}function Xs(e,t){return e===`absent`?`absent`:Ys(t)}async function Zs(e){try{return(await e()).isError?`failed`:`answered`}catch{return`failed`}}function Qs(e,t){let n=zn(Js),r=vr({deviceId:e},{enabled:t&&n!==`absent`}),i=()=>Zs(r.refetch);return t?{presence:Xs(n,{status:r.status,data:r.data}),status:r.data?.cameraSensors??null,refetch:i}:{presence:`absent`,status:null,refetch:i}}function $s(e,t){let n=_r({deviceType:e.type}),r=nn({deviceId:e.id}),i=fn({deviceId:e.id}),a=Lo(n,e=>new Set(e.caps.map(e=>e.cap))),o=Lo(r,e=>to(e.entries)),s=Lo(i,e=>e);return{deviceType:e.type,composable:a,nativeCaps:o,wireable:s,composed:new Set((t?.features??[]).map(e=>e.cap))}}function ec(){return{kind:`unknown`,reason:X.t(`helpers.fieldsTableRows.noValue`)}}function tc(e,t){let n=G(e);return t.get(n)??n}function nc(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=bi(e).map(e=>tc(e,n.sourceNames)).join(` + `),a=i.find(e=>e.field===`lastPressedAt`);return[{key:`doorbell`,label:X.t(`helpers.whatChangesRows.doorbell`),origin:{kind:r,from:t},value:a?.value??ec()}]}return e.cap===`consumables`?fi(e).map(e=>{let t=t=>K(ye,e.key,t),a=i.find(e=>e.field===t(`level`)||e.field===t(`remaining.value`)),o=e.source===null?``:tc(e.source.source,n.sourceNames);return{key:`consumables.${e.key}`,label:X.t(`helpers.whatChangesRows.consumable`,{name:e.label}),origin:{kind:r,from:o},value:a?.value??ec()}}):i.map(e=>({key:e.key,label:`${e.cap}.${e.field}`,origin:{kind:r,from:e.from},value:e.value}))}function rc(e){let t=hi({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`?nc(n,t,e):[])}function ic(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 ac=`${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)]`,oc=`font-mono text-[11px] text-foreground break-words`,sc=`text-[11px] text-foreground-subtle break-words`,cc=`text-[11px] break-words sm:text-right`;function lc({device:e,composition:t,state:n,nativeCaps:r,cameraSensors:i}){let{t:o}=Z(),s=t!==null&&n!==null,c=Bo(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`?rc({composition:t,nativeCaps:r.value,state:n,sourceNames:l}):[],f=s&&r.kind===`known`&&u.length===0&&t.features.length>0,p=ic(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(Po,{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:ac,children:[d(`span`,{className:oc,children:e.label}),d(`span`,{className:sc,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:cc,children:d(uc,{value:e.value})})]},e.key)),p!==null&&a(`li`,{className:ac,children:[d(`span`,{className:oc,children:o(`common.motionWord`)}),d(`span`,{className:sc,children:p}),d(`span`,{className:cc,children:d(jo,{target:{deviceId:e.id,cap:`motion`,path:`detected`}})})]})]})]})}function uc({value:e}){let{t}=Z();switch(e.kind){case`value`:return a(`span`,{children:[yi(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 dc({deviceId:e,activeSubTab:t,onSubTabChange:n}){let{t:r}=Z(),i=un({deviceId:e}),a=i.data;return a==null?i.status===`error`?d(Fn,{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(fc,{device:a}):d(pc,{device:a,target:{addonId:a.addonId,stableId:a.stableId},activeSubTab:t,onSubTabChange:n})}function fc({device:e}){let{t}=Z(),n=e.stableId.startsWith(`composed-`)?e.stableId.slice(Ee.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(Hr,{className:`text-[11px] text-primary hover:underline`,to:Xr(n),children:t(`customize.composed.edit`)})]})}function pc({device:e,target:t,activeSubTab:n,onSubTabChange:r}){let i=qs(t),o=zn(`composer`),{t:s}=Z(),c=Qs(e.id,e.type===q.Camera),l=$s(e,co(i.state)),u={deviceType:e.type,composable:l.composable,nativeCaps:l.nativeCaps,cameraSensors:c.presence},f=()=>r(ei),p=i.state.kind===`none`||i.state.kind===`present`;return n===`advanced`?a(`div`,{className:`flex flex-col gap-3`,children:[d(hc,{state:i.state}),p&&d(mc,{device:e,target:t,handle:i,facts:l,onDone:()=>r(`main`)})]}):a(`div`,{className:`flex flex-col gap-3`,children:[d(vo,{device:e}),o===`absent`&&d(`p`,{role:`alert`,className:`text-xs text-warning`,children:s(`customize.composerAbsent`)}),i.state.kind!==`none`&&d(hc,{state:i.state}),d(ls,{device:e,handle:i,availability:ao(`doorbell`,u),onAdvanced:f}),d(Es,{device:e,handle:i,availability:ao(`motion`,u),sensors:c}),d(Wo,{device:e,handle:i,availability:ao(`battery`,u),onAdvanced:f}),d(qo,{device:e,handle:i,availability:ao(`consumables`,u),onAdvanced:f}),d(Gs,{device:e,target:t,handle:i,facts:l}),d(fs,{device:e}),d(lc,{device:e,composition:co(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:[p?d(oo,{onAdvanced:f}):d(`span`,{}),d(gc,{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(Ci,{initial:a===null?ii(t):ai(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 hc({state:e}){let{t}=Z();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(Fn,{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(en,{variant:n.status===`running`?`success`:n.status===`failed`?`danger`:`warning`,children:t(`customize.blockStatus.${n.status}`)}),!n.enabled&&d(en,{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 gc({handle:e}){let{t}=Z(),n=pt(),[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(Y,{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 _c=`overview`;function vc(e,t){return e.some(e=>e.id===t)?t:_c}function yc({deviceId:e}){let{t}=Z(),n=c(),r=Number.isFinite(e),{data:i}=un({deviceId:e},{enabled:r}),o=typeof i?.type==`string`?i.type:`camera`;pr([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:s,isLoading:l,isError:u,error:f}=nn({deviceId:e},{enabled:r}),{data:p}=Pt({deviceType:o},{enabled:!!o}),m=Rn({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(et,{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(bc,{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(xc,{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(Sc,{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(Jr,{i18nKey:`device.bindingsTab.boundSummary`,count:_.length,values:{bound:v},components:{b:d(`span`,{className:`font-medium text-foreground`}),em:d(`em`,{})}})}),d(Ln,{columns:y,rows:_,rowKey:e=>e.capName,minWidthPx:720})]})}function bc({kind:e}){let{t}=Z();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(rt,{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 xc({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 Sc({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){let{t:i}=Z();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 Cc({deviceId:e,activeSubTab:t,onSubTabChange:n,deviceType:r,isAdmin:i}){return a(`div`,{className:`flex flex-col gap-3`,children:[Br(r,i)&&d(ur,{deviceId:e,readOnly:!0}),d(Qr,{deviceId:e,activeSubTab:t,onSubTabChange:n})]})}e();var wc=[[`pipelineOrchestrator`,`getCameraDetectionSource`]];function Tc(e){let t=c(),n=Sn({deviceId:e},{refetchOnMount:`always`}),a=Jn(),[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:wc})}catch(e){u(e instanceof Error?e.message:`Could not change the root detector`),await t.invalidateQueries({queryKey:wc})}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 Ec=`object-detection`;function Dc(e){return[e.addonId,...e.children.flatMap(Dc)]}function Oc(e,t){if(e===`pipeline`)return new Set;let n=kc(t,Ec);return n===void 0?new Set:new Set(e===`onboard`?[n.addonId]:Dc(n))}function kc(e,t){for(let n of e){if(n.addonId===t)return n;let e=kc(n.children,t);if(e!==void 0)return e}}function Ac(e,t){return e===`onboard`?X.t(`helpers.detectionSourceModel.badgeCameraAi`):t===`object-detection`?X.t(`helpers.detectionSourceModel.badgeNoRoot`):X.t(`helpers.detectionSourceModel.badgeIdle`)}function jc(e){switch(e){case`pipeline`:return X.t(`helpers.detectionSourceModel.explainPipeline`);case`onboard`:return X.t(`helpers.detectionSourceModel.explainOnboard`);case`none`:return X.t(`helpers.detectionSourceModel.explainNone`)}}function Mc(e){switch(e){case`boxed`:return``;case`while-streaming`:return X.t(`helpers.detectionSourceModel.geometryWhileStreaming`);case`flag-only`:return X.t(`helpers.detectionSourceModel.geometryFlagOnly`);case`unknown`:return X.t(`helpers.detectionSourceModel.geometryUnknown`)}}function Nc(e,t){return e===`onboard`?X.t(`helpers.detectionSourceModel.noticeOnboard`):t===`object-detection`?X.t(`helpers.detectionSourceModel.noticeNoRoot`):X.t(`helpers.detectionSourceModel.noticeIdle`)}function Pc({source:e,geometry:t,saving:n,error:r,onPick:i}){let{t:o}=Z(),s=t===`flag-only`,c=Mc(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(it,{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:[jc(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 Fc=new Set([`package-detection`]);function Ic(e){return e?.settings!==void 0&&Object.keys(e.settings).length>0?`accelerator`:`camera`}function Lc(e){return e===`camera`?X.t(`device.cameraStepInspector.modelSource.camera`):e===`node`?X.t(`device.cameraStepInspector.modelSource.node`):X.t(`device.cameraStepInspector.modelSource.default`)}function Rc(e){let{stored:t,draft:n,below:r,boundKeys:i}=e,a=n?.modelId===void 0?t?.modelId:n.modelId??void 0,o=Me(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 zc(e,t){return(e?.modelId??null)===(t?.modelId??null)&&Pe(e?.settings??{},t?.settings??{})}function Bc({deviceId:e}){let{t}=Z(),i=c(),l=U().trpcClient,u=cr({deviceId:e},{refetchOnMount:`always`}),f=$n({deviceId:e},{refetchOnMount:`always`}),p=Dr(void 0,{refetchOnMount:`always`}),m=xe(mn({addonId:`pipeline-orchestrator`}).data??null);pr([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let{nodes:h}=ln(),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=Kt({onSuccess:b}),S=Wn(),C=Vt(),[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?Nt(L):[],[L]),ne=n(()=>Ii(R),[R]),z=Tc(e),re=n(()=>z.source===null?new Set:Oc(z.source,R),[z.source,R]),[B,V]=r(!1),ie=n(()=>zi(g,F,B),[g,F,B]),ae=n(()=>zi(g,F,!0),[g,F]),oe=n(()=>zi(g,F).length,[g,F]),se=(e,t)=>Ai(P[e.nodeId],t),H=(e,t)=>te[e.nodeId]?.[e.deviceKey]?.[t],ce=(e,t)=>Wi(F[e.nodeId]??[],e.deviceKey,t)??{},le=e=>{if(Fc.has(e))return{kind:`zone-driven`};let t=Ai(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=Ri(e),a=ji(P[t.nodeId],t,H(t,`object-detection`)?.modelId),o=ue(t,e,null),s=Le(o.node,o.camera,o.accelerator);return Vi({addon:n,acc:t,gatedOn:r.kind===`gate`?r.effectiveOn:!0,model:n?Li(n,t,{nodePin:t.device.steps?.[e]?.modelId,cameraPin:H(t,e)?.modelId}):{modelId:void 0,source:`default`},...Pi(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:Bi(Ai(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(Pc,{source:z.source,geometry:z.view.onboard.geometry,saving:z.saving,error:z.error,onPick:e=>void z.pick(e)}),d(ki,{tree:R,searchRows:pe,accelerators:ie,cellState:fe,stepBadge:e=>re.has(e)&&z.source!==null?d(en,{variant:`warning`,title:Nc(z.source,e),children:Ac(z.source,e)}):d(Mn,{gate:le(e)}),disabledCount:Ui(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)??Ai(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=Ot(f),h=Ge(m),g=ue(u,n,p),_=Le(g.node,g.camera,g.accelerator),v=ji(P[u.nodeId],u,H(u,`object-detection`)?.modelId),y=Li(f,u,{nodePin:u.device.steps?.[n]?.modelId,cameraPin:de(u,n,p)}).modelId,F=Le(g.node,g.camera),te=Be(g.accelerator,F,h),R=Ri(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:Ic(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=Oe(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:Ue(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&&!Pe(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=Rc({stored:a,draft:i,below:Le(ce(t,n),r),boundKeys:h});zc(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&&!Pe(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=Li(r,e,{nodePin:a,cameraPin:i}),c=ue(e,n,p),l=ji(P[e.nodeId],e,H(e,`object-detection`)?.modelId),u=Pi(n,Le(c.node,c.camera,c.accelerator),l),m=Mi(r,e)?u&&l?d($t,{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:Lc(o.source),models:Tt(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(it,{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(gn,{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(br,{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:Nc(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(Ni,{rows:ie.map(e=>{let t=Li(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:Lc(t.source)}})}):d(jt,{...ge(r)},r.id):d(Hi,{step:R,engineFormat:u.device.format,runnableModelIds:Tt(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(Vc,{addon:f,fields:m,layers:g,scope:oe,viewed:r,modelId:ht(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)=>Ue(e,t,h),{...g.accelerator})})})}),d(Oi,{addonId:n,highlightLabel:i})]})})}})]})}function Vc({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}=Z();Fi(c===null?null:rn(c));let h=i!==null&&n.accelerator!==void 0;return d(Lt,{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 Hc(e,t,n){return{id:e,get label(){return X.t(t)},icon:n}}var Uc=[Hc(`object-detection`,`helpers.detectionSettingsGroups.objectDetection`,`scan-search`),Hc(`tracking`,`helpers.detectionSettingsGroups.tracking`,`route`),Hc(`motion`,`helpers.detectionSettingsGroups.motion`,`activity`),Hc(`stationary`,`helpers.detectionSettingsGroups.stationary`,`square-parking`),Hc(`zones`,`helpers.detectionSettingsGroups.zones`,`shapes`),Hc(`audio`,`helpers.detectionSettingsGroups.audio`,`volume-2`),Hc(`cluster`,`helpers.detectionSettingsGroups.cluster`,`server`)],Wc={"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 Gc(e){return Wc[e]??`object-detection`}e();var Kc=`steps`,qc=`settings`,Jc=new Set([Kc,qc]);function Yc(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function Xc({deviceId:e,activeSubTab:t,onSubTabChange:n}){let{t:r}=Z();return a(ut,{value:t&&Jc.has(t)?t:Kc,onValueChange:i(e=>{n?.(e)},[n]),className:`flex flex-col`,children:[a(Yn,{className:`flex-shrink-0`,children:[d(st,{value:Kc,children:r(`device.detectionPipelineTab.steps`,`Steps`)}),d(st,{value:qc,children:r(`device.detectionPipelineTab.settings`,`Settings`)})]}),d(Xt,{value:Kc,children:d(Bc,{deviceId:e})}),d(Xt,{value:qc,children:d(Qr,{deviceId:e,sectionFilter:Yc,subTabGrouping:{groupOf:e=>Gc(e.id),tabs:Uc}})})]})}var Zc=`Notifications`,Qc=`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`;function $c(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:Zc,on:r===null?null:i??r,available:r!==null,costWhenOff:Qc}}function el(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}e();function tl(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function nl({deviceId:e}){let{t}=Z(),n=c(),o=Number.isFinite(e),[s,l]=r(null),[u,f]=r(null),p=$c({mutedDeviceIds:tl(gt({},{enabled:o}).data),deviceId:e,pendingOn:u}),m=zt({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=el(p,e);t!==null&&(f(!t.muted),m.mutate(t))},[e,m,p]),g=p.on===null,_=p.on===!1,v=_?$e: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 rl(e,t){return{switchId:e,label:We[e].label,detail:t===void 0||t.length===0?null:t}}function il(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 al(e){let t=il(e),n=new Set(e.sourceStillLive),r=e.sourceStillLive.map(e=>rl(e,t.get(e)?.detail)),i=[...t.values()].filter(e=>e.outcome===`not-offered`&&!n.has(e.switchId)).map(e=>rl(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 ol(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 sl({deviceId:e,deviceName:t}){let{t:i}=Z(),o=pt(),[s,c]=r(null),l=bt({isCamera:!0,projection:`slim`}),u=vn(),f=l.data!==void 0,p=n(()=>l.data===void 0?[]:ol(l.data,e),[l.data,e]),m=p.find(e=>e.id===s)??null,h=u.data===void 0?null:al(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(Ye,{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(cl,{report:h})]})}function cl({report:e}){let{t}=Z(),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(nt,{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 ll({deviceId:e}){let{t}=Z(),[n,i]=r(null),o=Yt({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 ul(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function dl({device:e}){let{t}=Z(),n=Yr(),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(Se.Resyncable),{data:u}=dt({deviceId:r??0},{enabled:r!==null&&o,refetchInterval:5e3}),f=u?.streams??{},p=Object.entries(f),m=c.includes(Se.DoorbellButton),h=Hn(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(En,{deviceId:r,onOpenChild:e=>n(`/devices/${e}`)}),l&&r!==null&&d(ll,{deviceId:r}),o&&r!==null&&d(sl,{deviceId:r,deviceName:String(e.name??``)}),r!==null&&d(nl,{deviceId:r}),o&&r!==null&&d(yn,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:r}),m&&d(Ar,{history:h.history,latestIsFresh:g}),o&&r!==null&&d(yn,{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(fl,{label:t(`device.overviewTab.nominal`,`Nominal`),value:ul(n.nominalBitrateKbps??0)}),d(fl,{label:t(`device.overviewTab.observed`,`Observed`),value:ul(n.observedBitrateKbps??0)}),d(fl,{label:t(`device.overviewTab.peak`,`Peak`),value:ul(n.peakBitrateKbps??0)}),d(fl,{label:t(`device.overviewTab.packetLoss`,`Packet Loss`),value:`${(n.packetLossPercent??0).toFixed(2)}%`,warning:(n.packetLossPercent??0)>1})]})]},e))})]}),d(Fr,{}),r!==null&&d(Nr,{deviceId:r})]})}function fl({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 pl=`history`,ml=[{id:`overview`,labelKey:`helpers.structuralTabs.overview`,cameraOnly:!1,adminOnly:!1},{id:`config`,labelKey:`helpers.structuralTabs.config`,cameraOnly:!1,adminOnly:!1},{id:Zr,labelKey:`helpers.structuralTabs.customize`,cameraOnly:!1,adminOnly:!0},{id:pl,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}],hl=new Set([q.Hub,q.Container]);function gl(e,t){let n=e===q.Camera,r=e===void 0||!hl.has(e);return ml.filter(e=>(n||!e.cameraOnly)&&(t||!e.adminOnly)&&(r||e.id!==`history`)).map(({id:e,labelKey:t})=>({id:e,label:X.t(t)}))}function _l({provider:e,integrationId:t,name:n}){let r=Yr(),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(qr,{type:e,size:`lg`})})}e();var vl=[{id:`logs`,icon:le,labelKey:`common.logs`},{id:`repl`,icon:tt,labelKey:`deviceDetail.repl`},{id:`events`,icon:D,labelKey:`common.events`},{id:`state`,icon:P,labelKey:`common.state`}];function yl(){let{t:e}=Z(),t=ni(),o=Number(t.deviceId),u=Number.isFinite(o),f=Yr(),p=c(),m=pt(),h=U(),{user:_}=Wr(),v=_?.isAdmin===!0,[y,x]=$r(),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}=un({deviceId:o},{enabled:u,refetchInterval:5e3,retry:1}),{data:F}=Ct({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(Ir)&&r.add(Vr),[...r].map(e=>e===`export`?{id:e,label:Pr,isAddonContrib:!0}:{id:e,label:Te[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}=Gr(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?Et(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}=Ct({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:Te[e]?.label??e,isAddonContrib:!0,childDeviceId:H}))},[H,ce]),ue=typeof I?.parentDeviceId==`number`?I.parentDeviceId:null,{data:fe}=un({deviceId:ue??0},{enabled:ue!==null}),W=vt(),me=I?.disabled!==!0,he=n(()=>{let e=F?.settings?.sections??[],t=F?.live?.sections??[];return zr([...e,...t],V,v,F!==void 0)},[F,V,v]),ge=n(()=>{let e=new Set,t=[];for(let n of[...gl(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(()=>vc(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 Gi)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]),G=(ae??[]).length>0,be=n(()=>vl.filter(({featureGate:e})=>!e||B.includes(e)),[B]),{data:xe}=jr(void 0),Ce=n(()=>I?Xn(I,xe):null,[I,xe]),K=Ce?.kind===`resolved`?Ce.integration:null,we=K===null?Ce?.kind===`unknown`?e(`deviceDetail.loadingIntegration`):Ce?.kind===`orphan`?e(`deviceDetail.missingIntegration`):e(`deviceDetail.noIntegration`):K.name,Ee=K!==null&&K.addonId===re?K.name:re,De=An({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]}),f(K?.id?`/integrations/${K.id}`:`/integrations`)}}),J=It({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Oe=Bt({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=mr(),Ae=On({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),je=B.includes(Se.Rebootable),Me=B.includes(Se.BatteryOperated),Ne=At(h.trpcClient,Me&&u?o:null),Pe=_t(h.trpcClient,u?o:null),[Fe,Ie]=r(!1),Le=async()=>{if(!Fe){Ie(!0);try{let e=L.replace(/[^a-zA-Z0-9_.-]+/g,`_`),t=new Date().toISOString().replace(/[:.]/g,`-`);await oa(`${ee}/${String(o)}.jpg?force=1`,`${e}-${t}.jpg`)}finally{Ie(!1)}}},Re=J.isPending||Oe.isPending,{data:ze}=tr({deviceId:o},{enabled:u&&ie,refetchInterval:1e4}),Be=ze?.agentNodeId??null,Ve=typeof Be==`string`&&Be.length>0&&!Be.startsWith(`addon:`)?Be:void 0,{data:He}=wt({deviceId:o,...Ve?{nodeId:Ve}:{}},{enabled:u&&ie,refetchInterval:3e3,retry:!1}),{data:Ue}=Cr({deviceId:o},{enabled:u&&ie,refetchInterval:3e3,retry:!1}),We=Ue?.level?.dbfs??null;function Ge(){if(!u)return null;switch(_e){case`overview`:return d(dl,{device:I??{}});case`config`:return d(Cc,{deviceId:o,activeSubTab:C,onSubTabChange:ye,deviceType:V,isAdmin:v});case`detection-pipeline`:return d(Xc,{deviceId:o,activeSubTab:C,onSubTabChange:ye});case`bindings`:return d(yc,{deviceId:o});case pl:return d(Qn,{deviceId:o,onNavigate:e=>f(e)});case Zr:return d(dc,{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(Qr,{deviceId:o,sectionFilter:Ir,activeSubTab:C,onSubTabChange:ye});let i=d(Qr,{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(Tr,{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(Jr,{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(Or,{items:[{label:e(`deviceDetail.integrations`,`Integrations`),onClick:()=>f(`/integrations`)},K===null?{label:we}:{label:we,onClick:()=>f(`/integrations/${K.id}`)},{label:L}]})}),a(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[K!==null&&d(_l,{provider:K.addonId,integrationId:K.id,name:K.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(ar,{status:z}),Me&&d(on,{status:Ne,variant:`full`}),d(wr,{status:Pe})]}),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(Kr,{capabilities:B})})]}),He&&d(`div`,{className:`hidden lg:flex`,children:d(bl,{metrics:He,dbfs:We})}),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`})&&Oe.mutate({deviceId:o}):J.mutate({deviceId:o})},disabled:Re,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:Re?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(pa,{deviceId:o}),d(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),d(ha,{deviceId:o}),d(Bn,{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:Fe,onClick:()=>{Le()}},{id:`reboot`,label:e(`deviceDetail.rebootDevice`,`Reboot device`),description:e(`deviceDetail.cameraGoesOfflineFor30`,`Camera goes offline for ~30 seconds.`),icon:pe,hidden:!je,disabled:ke.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`})&&ke.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:Ae.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`})&&Ae.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(Tr,{deviceId:o,device:I??void 0,children:d(kn,{children:d(wn,{children:d(de,{children:d(Dn,{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(Ya,{deviceId:o,intercomAvailable:B.includes(Se.TwoWayAudio)}):d(za,{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:be.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(Xa,{deviceId:o,containerDeviceId:V===`container`?o:void 0}),w===`repl`&&d(Za,{deviceId:o}),w===`events`&&d(Qa,{deviceId:o}),w===`state`&&d($a,{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`&&G&&d(ga,{parentDeviceId:o}),Ge()]})]})]})})})})})})]}):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(Jr,{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 bl({metrics:e,dbfs:t}){let n=ne(),{t:r}=Z(),i=Cn(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{yl as DeviceDetailPage};