@camstack/addon-admin-ui 1.2.427 → 1.2.428
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.
- package/dist/assets/{AddonAssetIcon-BgXfFdy2.js → AddonAssetIcon-Cs_blBpK.js} +1 -1
- package/dist/assets/Addons-2xWF73cR.js +4 -0
- package/dist/assets/{AdminPage-C0Zxs_ot.js → AdminPage-DuuyDIsY.js} +1 -1
- package/dist/assets/{AdminSectionedPage-D2kYQhvu.js → AdminSectionedPage-C3VHg80L.js} +1 -1
- package/dist/assets/AiProfiles-DmHcVlS2.js +3 -0
- package/dist/assets/BrokerForm-Dqhjsi3Y.js +1 -0
- package/dist/assets/Build-CBYP1fT5.js +40 -0
- package/dist/assets/Calendars-C926x7b_.js +1 -0
- package/dist/assets/Cluster-OZlA14uV.js +1 -0
- package/dist/assets/ClusterStepModel-DHbwIGAW.js +1 -0
- package/dist/assets/CompositionEditor-vP3JcV2R.js +1 -0
- package/dist/assets/{CompositionEditorPage-CDyW_Buu.js → CompositionEditorPage-Acq7iapA.js} +1 -1
- package/dist/assets/Data-7BoejvKA.js +1 -0
- package/dist/assets/DeviceDetail-ByM0856T.js +2 -0
- package/dist/assets/DeviceDoActionFields-BDJsvRNX.js +1 -0
- package/dist/assets/{Devices-CHeb_BTk.js → Devices-PIrWjfhq.js} +1 -1
- package/dist/assets/EmbedPlayerPage-RXOmf2F3.js +1 -0
- package/dist/assets/Identity-C-tztwfa.js +1 -0
- package/dist/assets/IntegrationDetail-DugB7cv6.js +1 -0
- package/dist/assets/IntegrationHub-BePMbmC5.js +1 -0
- package/dist/assets/Integrations-Dj3nT9ZT.js +1 -0
- package/dist/assets/Integrations-OH5z-t03.js +1 -0
- package/dist/assets/Library-DDNti2te.js +1 -0
- package/dist/assets/Locations-OL9_NoSi.js +3 -0
- package/dist/assets/Logs-DIeXeCqI.js +1 -0
- package/dist/assets/{MotionZonesSettings-DjvGw8j4.js → MotionZonesSettings-CfTOerul.js} +1 -1
- package/dist/assets/MyAccess-iJP3JQIS.js +2 -0
- package/dist/assets/Network-DYssxNiN.js +1 -0
- package/dist/assets/NodeAddonsSettingsPanel-mmtEgDbu.js +1 -0
- package/dist/assets/Notifications-DEcxFWp3.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-IK6ytyM8.js → PrivacyMaskSettings-CJUKFEIs.js} +1 -1
- package/dist/assets/Recordings-lygSYEJj.js +1 -0
- package/dist/assets/ScanNetworkModal-C2oJlLfj.js +1 -0
- package/dist/assets/{SceneMonitorEditor-V_pHxg3U.js → SceneMonitorEditor-D1S-D2V9.js} +1 -1
- package/dist/assets/SessionsList-CIN4GdSm.js +2 -0
- package/dist/assets/{Showroom-Cw-6ZdvC.js → Showroom-W2yJvb8s.js} +1 -1
- package/dist/assets/System-ChWpOOqN.js +1 -0
- package/dist/assets/{Terminal-D-YHBrHK.js → Terminal-CrFum1tE.js} +5 -5
- package/dist/assets/{Viewer-BmXiweP2.js → Viewer-YBzeS3RA.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-wt87pCBz.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CE2IIKhe.js} +1 -1
- package/dist/assets/{addon-icons-context-CvwUgMRr.js → addon-icons-context-D6glxUQF.js} +1 -1
- package/dist/assets/{archive-Bwv0mNo-.js → archive-kvflMCgL.js} +1 -1
- package/dist/assets/{authed-media-0TPg9TTZ.js → authed-media-CSlndmzS.js} +1 -1
- package/dist/assets/{bell-off-D2KzCQW2.js → bell-off-BYnwGeiH.js} +1 -1
- package/dist/assets/{boxes-BXQUMgws.js → boxes-Dx4USyB3.js} +1 -1
- package/dist/assets/circle-slash-D5mo-8G0.js +1 -0
- package/dist/assets/client-CMlUvfoK.js +358 -0
- package/dist/assets/{cloud-upload-BsULjxPu.js → cloud-upload-82x5w5u8.js} +1 -1
- package/dist/assets/crop-Dev61hIh.js +1 -0
- package/dist/assets/{device-integration-icon-CCoHGEQZ.js → device-integration-icon-bTnWrYe0.js} +1 -1
- package/dist/assets/device-picker-model-DlnG_8P7.js +1 -0
- package/dist/assets/{dist-DQtBl_2T.js → dist--5X8Gy0U.js} +1 -1
- package/dist/assets/{dist-DWoekMi0.js → dist-Dod19ois.js} +13 -13
- package/dist/assets/{eraser-DB7_WMyf.js → eraser-B8Awx5Sj.js} +1 -1
- package/dist/assets/{file-up-DuqaeMYR.js → file-up-LqDVgVVa.js} +1 -1
- package/dist/assets/{hard-drive-download-CKj8xKOz.js → hard-drive-download-C24D80x2.js} +1 -1
- package/dist/assets/{history-V8RQKQAb.js → history-DZsORyBG.js} +1 -1
- package/dist/assets/{hostInit-CdxLRG1l.js → hostInit-D2EmEDvv.js} +1 -1
- package/dist/assets/i18n-vggiB6gm.js +1 -0
- package/dist/assets/{icons-CEMmjIEL.js → icons-D5RaCH1q.js} +1 -1
- package/dist/assets/index-BgQGn3LX.js +4 -0
- package/dist/assets/index-BndCgmxf.css +2 -0
- package/dist/assets/{key-Bj5-ZBrb.js → key-DLwSBrPM.js} +1 -1
- package/dist/assets/{key-round-B2I1YisX.js → key-round-CYflkUyd.js} +1 -1
- package/dist/assets/{layers-BARFkXZ5.js → layers-C1wzFfr1.js} +1 -1
- package/dist/assets/linked-devices-model-CCTQ_gka.js +1 -0
- package/dist/assets/{list-ordered-9lF0Gp3K.js → list-ordered-CFeS9o_w.js} +1 -1
- package/dist/assets/location-owned-usage-DSLiI6RY.js +1 -0
- package/dist/assets/{log-in-CjtrIfG3.js → log-in-Be_RcxDr.js} +1 -1
- package/dist/assets/{memory-stick-B26_SbtH.js → memory-stick-4BwYEagi.js} +1 -1
- package/dist/assets/{message-square-plus-COMrVZEZ.js → message-square-plus-D7BNG3h7.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-ec37d41a.js → mf-entry-bootstrap-0-9df0d08c.js} +2 -2
- package/dist/assets/{mic-off-DBIqFVjg.js → mic-off-e162Bcfu.js} +1 -1
- package/dist/assets/{monitor-off-CTQMySOs.js → monitor-off-CARYfHC4.js} +1 -1
- package/dist/assets/{monitor-smartphone-iBd_3nPv.js → monitor-smartphone-lsNgnRRZ.js} +1 -1
- package/dist/assets/mount-DlnG_8P7.js +1 -0
- package/dist/assets/notification-schedule-field-DWpT_5Vh.js +1 -0
- package/dist/assets/{octagon-alert-DMjnTemh.js → octagon-alert-h80nyWRM.js} +1 -1
- package/dist/assets/{player-overlays-DWMIy1MJ.js → player-overlays-Cda8wso6.js} +1 -1
- package/dist/assets/{recycle-BCVF0r6Y.js → recycle-0MLWppmT.js} +1 -1
- package/dist/assets/remoteEntry-V_83-NrI.js +1 -0
- package/dist/assets/{scan-eye-DRXP3PgB.js → scan-eye-DVK8MF3K.js} +1 -1
- package/dist/assets/{scissors-DUFtPb9T.js → scissors-Cz3GoeOd.js} +1 -1
- package/dist/assets/{search-x-B3nve3vV.js → search-x-i_A-Upbe.js} +1 -1
- package/dist/assets/{send-P2KlabIu.js → send-B5VKcNUH.js} +1 -1
- package/dist/assets/{settings-2-reEhyiKz.js → settings-2-ZQsYJ0Zb.js} +1 -1
- package/dist/assets/{speaker-DSNMuvS8.js → speaker-Cl8DZGk_.js} +1 -1
- package/dist/assets/{src-BLkInT8U.js → src-eoSUZcV-.js} +8 -8
- package/dist/assets/{timer-reset-CsRTbSzh.js → timer-reset-A5ofAkBW.js} +1 -1
- package/dist/assets/{ungroup-BLeVa8__.js → ungroup-t0yDnzVf.js} +1 -1
- package/dist/assets/{unlink-DeNvF8r-.js → unlink-C1ZpCxl3.js} +1 -1
- package/dist/assets/{usb-CFseVsQJ.js → usb-DmUPajSy.js} +1 -1
- package/dist/assets/{use-scenes-feed-C8frh3hQ.js → use-scenes-feed-BQlYhRMq.js} +1 -1
- package/dist/assets/{use-stationary-objects-DNayAuMq.js → use-stationary-objects-BWM4vE0E.js} +1 -1
- package/dist/assets/useEventInvalidation-DlnG_8P7.js +1 -0
- package/dist/assets/{useNodeUrlSelection-BsLRiUy8.js → useNodeUrlSelection-CTxv9Em7.js} +1 -1
- package/dist/assets/user-round-BTaID248.js +1 -0
- package/dist/assets/{user-x-CpaZ5HO0.js → user-x-DRcPeM9C.js} +1 -1
- package/dist/assets/{video--MLJeLNU.js → video-tLHyNE3q.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-1Do_dc2z.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DOOXjnRq.js} +2 -2
- package/dist/index.html +11 -10
- package/dist/server/addon.js +27 -3
- package/package.json +1 -1
- package/dist/assets/Addons-BTWw53aT.js +0 -4
- package/dist/assets/AiProfiles-Ca7zuVMp.js +0 -3
- package/dist/assets/BrokerForm-6-BwPs-g.js +0 -1
- package/dist/assets/Build-BsduavcU.js +0 -40
- package/dist/assets/Calendars-DVTk_2iT.js +0 -1
- package/dist/assets/Cluster-BPJ4maiI.js +0 -1
- package/dist/assets/ClusterStepModel-CjuZ-oml.js +0 -1
- package/dist/assets/CompositionEditor-DJcmWU2U.js +0 -1
- package/dist/assets/Data-CLLvqZwG.js +0 -1
- package/dist/assets/DeviceDetail-BKw1gufS.js +0 -2
- package/dist/assets/DeviceDoActionFields-R-ZYIdMv.js +0 -1
- package/dist/assets/EmbedPlayerPage-B4y0Q0wO.js +0 -1
- package/dist/assets/Identity-NOlTR-3q.js +0 -1
- package/dist/assets/IntegrationDetail-CcZkPlbN.js +0 -1
- package/dist/assets/IntegrationHub-CuW7-WRy.js +0 -1
- package/dist/assets/Integrations-ACdx4iPR.js +0 -1
- package/dist/assets/Integrations-DjnhmLye.js +0 -1
- package/dist/assets/Library-B3iyoKdK.js +0 -1
- package/dist/assets/Locations-Cs1VwmXB.js +0 -3
- package/dist/assets/Logs-BMc6WXCH.js +0 -1
- package/dist/assets/MyAccess-BfUfTXrv.js +0 -2
- package/dist/assets/Network-F2lAIcbT.js +0 -1
- package/dist/assets/NodeAddonsSettingsPanel-D3ux_JIo.js +0 -1
- package/dist/assets/Notifications-Cp3qo_EC.js +0 -1
- package/dist/assets/Recordings-D91q74Ga.js +0 -1
- package/dist/assets/ScanNetworkModal-DjU-xM4X.js +0 -1
- package/dist/assets/SessionsList-DQ7kj8fX.js +0 -2
- package/dist/assets/System-DLLa4weE.js +0 -1
- package/dist/assets/circle-slash-DpUtlEnB.js +0 -1
- package/dist/assets/client-CjyKfSu1.js +0 -358
- package/dist/assets/crop-BtQBZ9jm.js +0 -1
- package/dist/assets/device-picker-model-1Z6p3UkP.js +0 -1
- package/dist/assets/index-D66JvELZ.js +0 -4
- package/dist/assets/index-dmZ34NAY.css +0 -2
- package/dist/assets/location-owned-usage-CNXQ-Obv.js +0 -1
- package/dist/assets/mount-1Z6p3UkP.js +0 -1
- package/dist/assets/notification-schedule-field-D8dd67dT.js +0 -1
- package/dist/assets/remoteEntry-RwWzzVu_.js +0 -1
- package/dist/assets/useEventInvalidation-1Z6p3UkP.js +0 -1
- package/dist/assets/user-round-BB0VDRnJ.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{G as e,I as t,K as n,Q as r,S as i,b as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{D as l,O as u,V as d,ot as f}from"./player-overlays-Cda8wso6.js";import{Cr as p,Dr as m,Er as h,Mr as g,Or as _,Rr as v,Tr as y,an as b,br as x,cn as S,gr as C,jr as w,ln as ee,on as te,sn as ne,vn as T,wr as re,xr as ie,yr as ae,zr as oe}from"./client-CMlUvfoK.js";import{Bn as E,Li as se,Ln as D,Ua as ce,Zl as le,Zn as ue,ar as de,du as fe,ji as pe,lu as me,ma as O,pa as he,s as ge}from"./src-eoSUZcV-.js";import{t as k}from"./useTranslation-Bc5yH9V9.js";r();function _e(e){return{target:{kind:`new`,type:e},name:``,features:[]}}function ve(e){return{target:{kind:`existing`,device:e},name:``,features:[]}}function A(e,t){return{target:e.target,name:t,features:e.features.flatMap(e=>e.kind===`fields`?[e]:[])}}function j(e,t,n){return{...e,features:e.features.map(e=>e.cap===t?n(e):e)}}function M(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 j(e,t.cap,e=>({...e,fields:{...e.fields,[t.path]:t.source}}));case`clear-field`:return j(e,t.cap,e=>({...e,fields:M(e.fields,t.path)}));case`remove-binding`:return j(e,t.cap,e=>{let n=e.fields[t.path];return n?.kind===`expression`?{...e,fields:{...e.fields,[t.path]:{...n,bindings:M(n.bindings,t.bindingName)}}}:e});case`copy-feature`:return j(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=ie.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`],N={addonId:`provider-homeassistant`,stableId:`sensor.template_source`};function we(){return A(S({temperatureSources:te,motionSources:b,occupancyWindowMs:ne}),`Room`)}function Te(){return A({target:{kind:`new`,type:g.Sensor},features:[{kind:`fields`,cap:`numeric-sensor`,fields:{value:{kind:`expression`,expr:`convert(v, "°C", "°F")`,bindings:{v:{kind:`from`,source:N,cap:`numeric-sensor`,fieldPath:`value`}}},unit:{kind:`expression`,expr:`"°F"`,bindings:{}},lastFetchedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Converted sensor`)}function Ee(){return A({target:{kind:`new`,type:g.Sensor},features:[{kind:`fields`,cap:`binary`,fields:{on:{kind:`expression`,expr:`v > 20`,bindings:{v:{kind:`from`,source:N,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 P=`rounded-lg border border-border bg-surface p-4`,ke=P;function Ae(e){return{addonId:e.addonId,stableId:e.stableId}}function F(e){return new Map(e.map(e=>[m(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 I(e){return Array.isArray(e)?e.map(I):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,I(t)]))}function L(e){return JSON.stringify(I(e))}function Pe(e,t){return L(e)===L(t)}function R(e,t){return L(e)===L(t)}function Fe(e,t){switch(e.kind){case`pending`:return{kind:`refused`,reason:`the customization has not been read yet — try again`};case`unknown`:return{kind:`refused`,reason:`the customization could not be read: ${e.reason}`};case`not-loaded`:return{kind:`refused`,reason:`the customizations are not loaded yet: ${e.reason}`};case`none`:return t===null?{kind:`noop`}:{kind:`create`,input:{enabled:!0,composition:t}};case`present`:{let n=e.view.block.id;return t===null?{kind:`delete`,blockId:n}:L(t)===L(e.composition)?{kind:`noop`}:{kind:`update`,blockId:n,expectedUpdatedAt:e.view.block.updatedAt,composition:t}}}}function z(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 B(e){return{kind:`expression`,expr:e,bindings:{}}}function V(e){let t=z(`number`,e.percentage);return t===null?null:{kind:`fields`,cap:`battery`,fields:e.mode===`replace`?{percentage:t}:{percentage:t,charging:B(`"unknown"`),sleeping:B(`false`),lastUpdated:B(`now`)}}}var Ie=[`percent`,...T.options];function H(e,t){return t===`percent`?{level:e}:{"remaining.value":e,"remaining.unit":B(JSON.stringify(t))}}function Le(e,t){let n=z(`number`,t.remaining);if(n===null||!x.test(t.key)||t.label.trim()===``)return null;let r={label:t.label.trim(),fields:H(n,t.unit)};return{kind:`fields`,cap:`consumables`,...e?.enabled===void 0?{}:{enabled:e.enabled},fields:e?.fields??{lastChangedAt:B(`now`),lastFetchedAt:B(`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=T.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=U(t.fields.level??t.fields[`remaining.value`]),i=r===null?null:z(`number`,r);return n!==null&&i!==null&&Pe(H(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=>[m(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 U(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=U(e.fields.percentage);if(n===null)return!1;let r=V({percentage:n,mode:t}),{enabled:i,...a}=e;return r!==null&&R(a,r)}function W(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 G(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}:z(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:G(n[e.cap],t.path),source:Ke(i,e.cap,t,r)})))}function K(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 q({title:e,targetKind:t,excludeDeviceIds:n=Je,onPick:r,onCancel:a}){let{t:c}=k(),[f,p]=o(null);return i(`aside`,{"aria-label":e,className:`${u} ${l} flex flex-col gap-2`,children:[s(`h3`,{className:d,children:e}),f===null?s(Ye,{excludeDeviceIds:n,onSelect:p}):s(J,{device:f,targetKind:t,onPick:r,onBack:()=>p(null)}),s(`div`,{children:s(E,{variant:`ghost`,size:`sm`,onClick:a,children:c(`customize.picker.cancel`)})})]})}function Ye({excludeDeviceIds:e,onSelect:t}){let{t:n}=k(),[r,c]=o(``),l=O({projection:`slim`});return i(a,{children:[i(`label`,{className:`flex flex-col gap-1 text-[11px] text-foreground-subtle`,children:[n(`customize.picker.search`),s(le,{type:`search`,"aria-label":n(`customize.picker.search`),value:r,onChange:e=>c(e.target.value)})]}),l.status===`pending`&&s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:n(`customize.picker.loadingDevices`)}),l.status===`error`&&s(D,{title:n(`customize.picker.devicesFailed`),message:l.error?.message??``}),l.status===`success`&&s(`ul`,{className:`flex flex-col gap-1`,children:Ge(W(l.data),r,e).map(e=>s(`li`,{children:i(`button`,{type:`button`,className:`text-left text-[11px] hover:underline`,onClick:()=>t(e),children:[e.name,` `,i(`span`,{className:`text-foreground-subtle`,children:[`· `,e.stableId]})]})},e.id))})]})}function J({device:e,targetKind:t,selected:n,onPick:r,onBack:a}){let{t:o}=k(),c=he({deviceId:e.id}),l=ce({deviceId:e.id});if(c.status===`pending`)return s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:o(`customize.picker.loadingFields`)});if(c.status===`error`)return s(D,{title:o(`customize.picker.fieldsFailed`),message:c.error?.message??``});let u=qe(e,c.data,l.status===`success`?l.data:null,t),d=u.filter(e=>e.source===null).length,f={addonId:e.addonId,stableId:e.stableId};return i(`div`,{className:`flex flex-col gap-1`,children:[i(`button`,{type:`button`,className:`text-left text-[11px] text-primary`,onClick:a,children:[`← `,e.name]}),l.status===`error`&&s(`p`,{role:`alert`,className:`text-[10px] text-warning`,children:o(`customize.picker.valuesFailed`,{reason:l.error?.message??``})}),s(`ul`,{role:`listbox`,"aria-label":o(`customize.picker.fields`),className:`flex flex-col gap-1`,children:u.map(t=>{let a=t.source;if(a===null)return null;let o=()=>r({device:e,ref:f,cap:t.cap,path:t.path,kind:t.kind,source:a,value:t.value});return i(`li`,{role:`option`,"aria-selected":n?.cap===t.cap&&n.path===t.path,tabIndex:0,className:`flex justify-between gap-2 text-[11px] cursor-pointer hover:bg-surface-hover rounded px-1`,onClick:o,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&o()},children:[i(`span`,{className:`font-mono`,children:[t.cap,`.`,t.path]}),s(`span`,{children:K(t.value,l.status===`success`)})]},`${t.cap}.${t.path}`)})}),d>0&&t!==null&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:o(`customize.picker.hidden`,{count:d,kind:o(`customize.kinds.${t}`)})})]})}var Xe=`integration`;function Y(e,t){switch(e.kind){case`from`:{let n=m(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:`the composer has not reported this customization yet`};let n=e.state.fields.find(t);return n===void 0?{kind:`unknown`,reason:`the composer reports no value for this field`}:n.state===`unavailable`?{kind:`unavailable`,reason:n.reason??`unavailable`}:{kind:`value`,value:n.value,staleReason:n.state===`stale`?n.reason??`stale`:null}}function X(e,t,n,r){return{key:`${e.feature.cap}.${t}`,cap:e.feature.cap,field:t,origin:`composed`,mode:e.mode,from:Y(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])=>X(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])=>X(e,re(ae,n,r),i,e=>e.cap===t&&e.path===r&&e.item?.arrayPath===`items`&&e.item.key===n)))}function et(e,t,n){if(e===null)return{kind:`unknown`,reason:`the device state could not be read`};let r=G(e[t],n),i=r===void 0?void 0:v(r);return i===void 0?{kind:`unknown`,reason:`not reported`}:{kind:`value`,value:i,staleReason:null}}function tt(e){if(e.mode!==`replace`)return[];let t=e.feature.cap,n=new Set(Object.keys(e.feature.fields));return(e.input.nativeFields.get(t)??[]).filter(e=>!n.has(e)).map(n=>({key:`${t}.${n}`,cap:t,field:n,origin:`native`,mode:e.mode,from: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:p(t),input:e};return[...Qe(n),...$e(n),...tt(n)]})}var rt={min:`min(a, b, …)`,max:`max(a, b, …)`,abs:`abs(x)`,floor:`floor(x)`,ceil:`ceil(x)`,sqrt:`sqrt(x)`,round:`round(x, digits?)`,pow:`pow(x, y)`,clamp:`clamp(x, lo, hi)`,avg:`avg(a, b, …)`,sum:`sum(a, b, …)`,coalesce:`coalesce(a, b, …)`,age:`age(now, ts)`,convert:`convert(x, "from", "to")`,any:`any(a, b, …)`,all:`all(a, b, …)`,within:`within(ts, ms)`,number:`number(x)`,latest:`latest(ts, …)`,rose:`rose(level, changedAt, debounceMs?)`,count:`count(x)`},Z=/[A-Za-z_][A-Za-z0-9_]*$/;function it(e,t,n){let r=Z.exec(e.slice(0,t))?.[0]??``;if(r===``)return[];let i=n.filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`binding`,label:e,insert:e,hintKey:null})),a=`now`.startsWith(r)?[{kind:`now`,label:`now`,insert:`now`,hintKey:`compositionEditor.now`}]:[],o=[...oe].filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`builtin`,label:rt[e]??e,insert:`${e}(`,hintKey:`compositionEditor.builtins.${e}`}));return[...i,...a,...o].slice(0,8)}function at(e,t,n){let r=t-(Z.exec(e.slice(0,t))?.[0]??``).length;return{text:`${e.slice(0,r)}${n.insert}${e.slice(t)}`,cursor:r+n.insert.length}}r();function ot({label:e,value:t,bindings:r,onChange:a}){let{t:c}=k(),l=n(null),[u,d]=o(t.length),f=it(t,u,r);return i(`div`,{className:`flex flex-col gap-1`,children:[i(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[e,s(`input`,{ref:l,className:`font-mono px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`,value:t,onChange:e=>{a(e.target.value),d(e.target.selectionStart??e.target.value.length)},onSelect:e=>d(e.currentTarget.selectionStart??t.length)})]}),f.length>0&&s(`ul`,{role:`listbox`,"aria-label":c(`compositionEditor.suggestions`),className:`rounded border border-border bg-surface text-[11px]`,children:f.map(e=>i(`li`,{role:`option`,"aria-selected":!1,tabIndex:0,className:`flex justify-between gap-2 px-1 cursor-pointer hover:bg-surface-hover`,onClick:()=>{let n=at(t,u,e);a(n.text),d(n.cursor),l.current?.focus()},children:[s(`span`,{className:`font-mono`,children:e.label}),e.hintKey!==null&&s(`span`,{className:`text-foreground-subtle`,children:c(e.hintKey)})]},`${e.kind}:${e.label}`))})]})}function st(e,t,n){if(e.kind===`code`)return{kind:`unavailable`,reason:`code fields arrive in slice 4`};if(e.kind===`expression`&&(C(e.expr,`rose`)||C(e.expr,`count`)))return{kind:`runtime-only`};let r=_(e).filter(e=>t.get(h(e.source,e.cap))?.kind!==`value`).map(y);if(r.length>0)return{kind:`waiting`,missing:r};let i=ee({source:e,now:n,read:e=>{let n=t.get(h(e.source,e.cap)),r=n?.kind===`value`?G(n.slice,e.fieldPath):void 0,i=r===void 0?void 0:v(r);return i===void 0?{state:`unavailable`,reason:`${e.cap}.${e.fieldPath} is not reported`,fatal:!1}:{state:`fresh`,value:i}}});return i.state===`unavailable`?{kind:`unavailable`,reason:i.reason}:{kind:`value`,value:i.value,stale:i.reason}}r();function ct({sliceKey:e,deviceId:t,capName:n,onReading:r}){let i=ge(f().trpcClient,t,n);return c(()=>{r(e,i===void 0?{kind:`pending`}:{kind:`value`,slice:i})},[e,i,r]),null}function lt(e,t){return[...new Map(_(e).map(e=>[h(e.source,e.cap),e]))].map(([e,n])=>({key:e,read:n,device:t.get(m(n.source))}))}function ut({source:e}){let{t:n}=k(),r=O({projection:`slim`}),[a,c]=o(new Map),l=t((e,t)=>{c(n=>new Map([...n,[e,t]]))},[]),u=lt(e,F(r.status===`success`?W(r.data):[])),d=r.status===`success`?u.filter(e=>e.device===void 0).map(e=>m(e.read.source)):[];return i(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[u.map(e=>e.device===void 0?null:s(ct,{sliceKey:e.key,deviceId:e.device.id,capName:e.read.cap,onReading:l},e.key)),s(`span`,{className:`text-foreground-subtle`,children:n(`compositionEditor.preview.label`)}),r.status===`error`?s(`span`,{className:`text-warning`,children:n(`compositionEditor.preview.devicesFailed`,{reason:r.error?.message??``})}):d.length>0?s(`span`,{className:`text-warning`,children:n(`compositionEditor.preview.unknownDevice`,{sources:d.join(`, `)})}):s(dt,{preview:st(e,a,Date.now())})]})}function dt({preview:e}){let{t}=k();switch(e.kind){case`value`:return i(`strong`,{children:[`→ `,K(e.value,!0),e.stale===null?``:` (${e.stale})`]});case`unavailable`:return s(`span`,{className:`text-warning`,children:e.reason});case`waiting`:return s(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.waiting`,{sources:e.missing.join(`, `)})});case`runtime-only`:return s(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.runtimeOnly`)})}}r();function ft({path:e,kind:t,required:n,source:r,onSet:c,onClear:l,onRemoveBinding:u,sourceNames:d}){let{t:f}=k(),[p,m]=o(`idle`),h=r?.kind===`expression`?r:null;return i(`div`,{className:`flex flex-col gap-1 rounded border border-border p-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[s(`span`,{className:`font-mono text-[11px]`,children:e}),i(`span`,{className:`text-[10px] text-foreground-subtle`,children:[f(`customize.kinds.${t}`),n?` · ${f(`compositionEditor.required`)}`:``]}),s(E,{size:`sm`,variant:`outline`,onClick:()=>m(`take`),children:f(`compositionEditor.takeFrom`)}),s(E,{size:`sm`,variant:`outline`,"aria-pressed":h!==null,onClick:()=>c(h??{kind:`expression`,expr:`null`,bindings:{}}),children:f(`compositionEditor.formula`)}),r!==void 0&&s(E,{size:`sm`,variant:`ghost`,onClick:l,children:f(`compositionEditor.clear`)})]}),r?.kind===`from`&&s(`span`,{className:`text-[11px]`,children:Y(r,d)}),h!==null&&i(a,{children:[s(ot,{label:f(`compositionEditor.formulaFor`,{path:e}),value:h.expr,bindings:Object.keys(h.bindings),onChange:e=>c({...h,expr:e})}),s(`ul`,{className:`text-[11px] flex flex-col gap-0.5`,children:Object.entries(h.bindings).map(([e,t])=>i(`li`,{className:`flex flex-wrap items-center gap-2`,children:[s(`span`,{className:`font-mono`,children:e}),s(`span`,{children:t.kind===`from`?Y(t,d):JSON.stringify(t.value)}),s(E,{size:`sm`,variant:`ghost`,"aria-label":f(`compositionEditor.removeBinding`,{name:e}),onClick:()=>u(e),children:`×`})]},e))}),s(E,{size:`sm`,variant:`ghost`,onClick:()=>m(`add-binding`),children:f(`compositionEditor.addSource`)})]}),p!==`idle`&&s(q,{title:f(p===`take`?`compositionEditor.takeFrom`:`compositionEditor.addSource`),targetKind:p===`take`?t:null,onCancel:()=>m(`idle`),onPick:e=>{if(p===`take`)c(e.source);else if(h!==null){let t=Se(Object.keys(h.bindings));c({...h,bindings:{...h.bindings,[t]:{kind:`from`,source:e.ref,cap:e.cap,fieldPath:e.path}}})}m(`idle`)}}),r!==void 0&&s(ut,{source:r})]})}r();function Q(e){return e===null||e.kind===`known`?null:e}function pt({draft:e,deviceType:t,nativeCaps:n,targetFields:r,dispatch:c}){let{t:l}=k(),u=pe({deviceType:t}),d=O({projection:`slim`}),f=new Map([...F(d.status===`success`?W(d.data):[])].map(([e,t])=>[e,t.name])),[p,m]=o(null),h=Q(n)??Q(r),g=n?.kind===`known`?n.value:new Set,_=new Set(e.features.map(e=>e.cap)),v=u.status===`success`?u.data.caps.filter(e=>!_.has(e.cap)&&!g.has(e.cap)):[],y=[...g].filter(e=>!_.has(e)),b=e=>g.has(e)?((r?.kind===`known`?r.value.caps.find(t=>t.cap===e):void 0)?.fields??[]).filter(e=>e.item!==!0&&!e.path.includes(`.`)).map(e=>({path:e.path,kind:e.kind,required:!1})):((u.status===`success`?u.data.caps.find(t=>t.cap===e):void 0)?.fields??[]).map(e=>({path:e.path,kind:e.kind,required:e.required}));return h===null?i(a,{children:[i(`section`,{"aria-labelledby":`editor-features`,className:`${P} flex flex-col gap-2`,children:[s(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),u.status===`pending`&&s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.checking`)}),u.status===`error`&&s(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.unknown`,{reason:u.error?.message??``})}),i(`div`,{className:`flex flex-wrap gap-1`,children:[e.features.map(e=>i(`span`,{className:`flex items-center gap-1 rounded border border-border px-1.5 text-[11px]`,children:[e.cap,s(de,{variant:g.has(e.cap)?`default`:`info`,children:g.has(e.cap)?l(`compositionEditor.replaces`):l(`compositionEditor.added`)}),s(`button`,{type:`button`,"aria-label":l(`compositionEditor.removeFeature`,{cap:e.cap}),onClick:()=>c({type:`remove-feature`,cap:e.cap}),children:`×`})]},e.cap)),v.map(e=>i(E,{size:`sm`,variant:`outline`,onClick:()=>c({type:`add-feature`,cap:e.cap}),children:[`+ `,e.cap]},e.cap)),y.map(e=>s(E,{size:`sm`,variant:`ghost`,onClick:()=>c({type:`add-feature`,cap:e}),children:l(`compositionEditor.replaceIn`,{cap:e})},e))]})]}),e.features.map(e=>i(`section`,{"aria-label":l(`compositionEditor.steps.fieldsOf`,{cap:e.cap}),className:`${P} flex flex-col gap-2`,children:[i(`div`,{className:`flex items-center justify-between`,children:[s(`h2`,{className:`text-sm font-semibold`,children:l(`compositionEditor.steps.fieldsOf`,{cap:e.cap})}),s(E,{size:`sm`,variant:`outline`,onClick:()=>m(e.cap),children:l(`compositionEditor.copyFeature`)})]}),p===e.cap&&s(q,{title:l(`compositionEditor.copyFeature`),targetKind:null,onCancel:()=>m(null),onPick:t=>{c({type:`copy-feature`,cap:e.cap,from:t.ref,sourceCap:t.cap,paths:b(e.cap).map(e=>e.path)}),m(null)}}),b(e.cap).map(t=>s(ft,{path:t.path,kind:t.kind,required:t.required,source:e.fields[t.path],onSet:n=>c({type:`set-field`,cap:e.cap,path:t.path,source:n}),onClear:()=>c({type:`clear-field`,cap:e.cap,path:t.path}),onRemoveBinding:n=>c({type:`remove-binding`,cap:e.cap,path:t.path,bindingName:n}),sourceNames:f},t.path))]},e.cap))]}):i(`section`,{"aria-labelledby":`editor-features`,className:`${P} flex flex-col gap-2`,children:[s(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:h.kind===`unknown`?h.reason:l(`compositionEditor.reading`)})]})}var $=`px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`;function mt({draft:e,targetName:t,dispatch:n}){let{t:r}=k(),a=e.target;return i(`section`,{"aria-labelledby":`editor-target`,className:`${P} flex flex-col gap-2`,children:[s(`h2`,{id:`editor-target`,className:`text-sm font-semibold`,children:r(`compositionEditor.steps.target`)}),a.kind===`existing`?s(`p`,{className:`text-[11px]`,children:r(`compositionEditor.existingTarget`,{name:t??`${a.device.addonId}/${a.device.stableId}`})}):i(`div`,{className:`grid grid-cols-3 gap-2`,children:[i(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[r(`compositionEditor.targetType`),s(`select`,{className:$,value:a.type,onChange:e=>{let t=Object.values(g).find(t=>t===e.target.value);t!==void 0&&n({type:`set-new-type`,deviceType:t})},children:Object.values(g).map(e=>s(`option`,{value:e,children:fe(e).label},e))})]}),i(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[r(`customize.identity.role`),i(`select`,{className:$,value:a.role??``,onChange:e=>n({type:`set-new-role`,role:Object.values(w).find(t=>t===e.target.value)??null}),children:[s(`option`,{value:``,children:r(`customize.identity.noRole`)}),Object.values(w).map(e=>s(`option`,{value:e,children:me(e).label},e))]})]}),i(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[r(`compositionEditor.name`),s(`input`,{className:$,value:e.name,onChange:e=>n({type:`set-name`,name:e.target.value})})]})]})]})}r();function ht({draft:e,blockId:t,saving:n,onSave:r,onCancel:a}){let{t:l}=k(),u=se(),d=be(e),f=d.ok?JSON.stringify(d.composition):``,[p,m]=o({key:``,state:{kind:`checking`}});c(()=>{if(!d.ok)return;let e=d.composition,n=setTimeout(()=>{u.mutateAsync({composition:e,...t===null?{}:{blockId:t}}).then(e=>m({key:f,state:e.ok?{kind:`ok`}:{kind:`refused`,problems:e.problems}})).catch(e=>m({key:f,state:{kind:`unknown`,reason:e instanceof Error?e.message:String(e)}}))},500);return()=>clearTimeout(n)},[f,t]);let h=d.ok?p.key===f?p.state:{kind:`checking`}:{kind:`invalid-draft`,problems:d.problems};return i(`section`,{"aria-labelledby":`editor-verify`,className:`${P} flex flex-col gap-2`,children:[s(`h2`,{id:`editor-verify`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.verify`)}),h.kind===`checking`&&s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.verify.checking`)}),h.kind===`ok`&&s(`p`,{className:`text-[11px] text-success`,children:l(`compositionEditor.verify.ok`)}),h.kind===`unknown`&&s(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.verify.unknown`,{reason:h.reason})}),(h.kind===`invalid-draft`||h.kind===`refused`)&&s(`ul`,{role:`alert`,className:`flex flex-col gap-1 text-[11px] text-danger`,children:h.kind===`invalid-draft`?h.problems.map(e=>s(`li`,{children:e},e)):h.problems.map(e=>i(`li`,{children:[s(`span`,{className:`font-mono`,children:e.path}),` — `,e.message]},`${e.path}:${e.code}`))}),i(`div`,{className:`flex gap-2`,children:[s(E,{variant:`ghost`,onClick:a,children:l(`compositionEditor.cancel`)}),s(E,{disabled:h.kind!==`ok`||n||!d.ok,onClick:()=>d.ok&&r(d.composition),children:l(`compositionEditor.save`)})]})]})}r();function gt({initial:e,blockId:t,deviceType:n,targetName:r=null,nativeCaps:i,targetFields:a,save:c,onCancel:l,showTemplates:u=!1}){let[d,f]=o(e),p=`${d.name}:${d.features.map(e=>e.cap).join(`,`)}:${d.target.kind===`new`?d.target.type:`existing`}`;return s(_t,{seed:d,blockId:t,deviceType:n,targetName:r,nativeCaps:i,targetFields:a,showTemplates:u,onApplyTemplate:e=>{f(De(e))},save:c,onCancel:l},p)}function _t({seed:t,blockId:n,deviceType:r,targetName:a,nativeCaps:c,targetFields:l,showTemplates:u,onApplyTemplate:d,save:f,onCancel:p}){let{t:m}=k(),h=ue(),[g,_]=e(ye,t),[v,y]=o(!1),[b,x]=o(null),S=async e=>{xe(t,g)&&!await h({title:m(`compositionEditor.templates.confirmTitle`),message:m(`compositionEditor.templates.confirmMessage`),confirmLabel:m(`compositionEditor.templates.confirmApply`),variant:`danger`})||d(e)},C=g.target.kind===`new`?g.target.type:r,w=async e=>{y(!0);let t=await f(e,g.name);y(!1),x(t.kind===`refused`?t.reason:null)};return i(`div`,{className:`flex flex-col gap-4`,children:[u&&g.target.kind===`new`&&i(`div`,{className:`rounded-lg border border-border bg-surface p-4 flex flex-wrap gap-2`,"data-testid":`composition-templates`,children:[s(`span`,{className:`text-[11px] text-foreground-subtle self-center`,children:m(`compositionEditor.templates.label`)}),Ce.map(e=>s(E,{size:`sm`,variant:`outline`,onClick:()=>void S(e),children:m(`compositionEditor.templates.${e}`)},e))]}),s(mt,{draft:g,targetName:a,dispatch:_}),s(pt,{draft:g,deviceType:C,nativeCaps:c,targetFields:l,dispatch:_}),s(ht,{draft:g,blockId:n,saving:v,onSave:e=>void w(e),onCancel:p}),b!==null&&s(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:b})]})}export{Me as C,ve as D,A as E,_e as O,je as S,Oe as T,U as _,J as a,Fe as b,W as c,Le as d,ze as f,Ve as g,We as h,nt as i,Ie as l,Ue as m,st as n,K as o,He as p,ot as r,G as s,gt as t,V as u,Be as v,ke as w,R as x,Ne as y};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{S as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{t as n}from"./boxes-
|
|
1
|
+
import{S as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{t as n}from"./boxes-Dx4USyB3.js";import{Mr as r,pr as i}from"./client-CMlUvfoK.js";import{Ii as a,Ln as o,Ti as s,ki as c}from"./src-eoSUZcV-.js";import{t as l}from"./useTranslation-Bc5yH9V9.js";import{J as u,X as d,Z as f,b as p,h as m}from"./index-BgQGn3LX.js";import{E as h,O as g,T as _,t as v,w as y}from"./CompositionEditor-vP3JcV2R.js";import{t as b}from"./AdminPage-DuuyDIsY.js";var x=`new`;function S(e){return e instanceof Error?e.message:String(e)}function C(e){let t=e.trim();return t===``?{}:{name:t}}function w(){let{blockId:w}=f(),{t:T}=l(),E=d(),D=s(),O=a(),k=w===void 0||w===x,A=c({blockId:w??``},{enabled:!k}),j=()=>{E(m)},M=e=>t(b,{icon:n,title:T(`compositionEditor.pageTitle`),children:e}),N=e=>t(`section`,{className:`${y} flex flex-col gap-2`,children:e});if(k)return M(t(v,{initial:g(r.Sensor),blockId:null,deviceType:r.Sensor,nativeCaps:null,targetFields:null,showTemplates:!0,onCancel:j,save:async(e,t)=>{try{let{block:n}=await D.mutateAsync({block:{...C(t),enabled:!0,composition:e}});return E(_(n.id,null).path,{replace:!0}),{kind:`saved`}}catch(e){return{kind:`refused`,reason:S(e)}}}}));if(A.status===`pending`)return M(N(t(`p`,{role:`status`,children:T(`compositionEditor.loading`)})));if(A.status===`error`)return M(N(t(o,{title:T(`compositionEditor.loadFailed`),message:A.error.message})));if(A.data.state===`not-loaded`)return M(N(t(`p`,{role:`status`,children:T(`customize.status.notLoaded`,{reason:A.data.reason})})));let P=A.data.view;if(P===null)return M(N(t(`p`,{children:T(`compositionEditor.notFound`,{blockId:w})})));let F=i(P.block);if(F===null)return M(N(t(`p`,{children:T(`compositionEditor.notComposition`)})));if(F.target.kind===`existing`){let e=P.state.kind===`answered`?P.state.state?.deviceId??null:null;return M(N(e===null?t(`p`,{children:T(`compositionEditor.customizationUnknownDevice`)}):t(u,{className:`text-primary`,to:p(e),children:T(`compositionEditor.openOnDevice`)})))}let I=P.state.kind===`answered`?P.state.state?.deviceId??null:null,L=I===null?null:_(P.block.id,I);return M(e(`div`,{className:`flex flex-col gap-3`,children:[L!==null&&L.kind===`device`&&t(u,{className:`text-sm text-primary`,to:L.path,"data-testid":`open-composed-device`,children:T(`compositionEditor.openComposedDevice`,{id:I})}),t(v,{initial:h(F,P.block.name),blockId:P.block.id,deviceType:F.target.type,nativeCaps:null,targetFields:null,onCancel:j,save:async(e,t)=>{try{return await O.mutateAsync({blockId:P.block.id,expectedUpdatedAt:P.block.updatedAt,block:{...C(t),composition:e}}),await A.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:S(e)}}}},`${P.block.id}@${P.block.updatedAt}`)]}))}export{w as CompositionEditorPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Hi as l,Hr as u,It as d,Ki as f,Kr as p,Nt as m,On as h,Pn as g,Q as _,Yr as v,_i as y,_n as b,ai as x,ar as S,di as C,kn as w,nr as T,qi as E,ri as D,rr as O,yi as k}from"./player-overlays-Cda8wso6.js";import{n as A,t as j}from"./cloud-upload-82x5w5u8.js";import{t as M}from"./circle-slash-D5mo-8G0.js";import{t as N}from"./hard-drive-download-C24D80x2.js";import{$r as P,An as F,Bc as I,Bn as L,Dc as ee,Dn as te,En as ne,G as R,Ht as z,Kl as re,L as B,Ln as ie,Nr as ae,Ql as V,Qr as oe,R as se,Rc as ce,Rn as le,Tn as H,Ut as ue,Vc as de,Xr as fe,Yr as pe,Zl as me,Zn as U,Zr as he,ai as ge,an as _e,ar as ve,ci as ye,ei as be,el as xe,ii as Se,jn as Ce,kn as W,li as we,ni as Te,oi as Ee,ri as De,si as Oe,ti as ke,ui as Ae,z as je,zc as Me}from"./src-eoSUZcV-.js";import{t as G}from"./i18n-vggiB6gm.js";import{t as K}from"./useTranslation-Bc5yH9V9.js";import"./mount-DlnG_8P7.js";import{C as Ne}from"./index-BgQGn3LX.js";import{t as Pe}from"./AdminSectionedPage-C3VHg80L.js";import{t as Fe}from"./AdminPage-DuuyDIsY.js";import{n as Ie}from"./authed-media-CSlndmzS.js";import{t as q}from"./format-size-DIxKXxtj.js";import{a as Le,c as Re,l as ze,n as Be,o as Ve,s as He,t as Ue,u as We}from"./location-owned-usage-DSLiI6RY.js";t();function Ge(){let{t:e}=K(),t=a(),i=U(),{data:o,isLoading:l,isError:u}=de({}),d=I(),f=r(()=>d.data??[],[d.data]),{data:p}=ee({},{refetchOnWindowFocus:!1}),m=r(()=>Ue(o??[],p?.locations),[o,p?.locations]),{data:h}=Me({},{refetchOnWindowFocus:!1}),g=r(()=>Le(h),[h]),{state:_,openNew:v,openEdit:y,close:b}=B(),[x,S]=se(`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;c(()=>{_.mode===`new`&&(x===null||x===``)&&(S(null),b())},[_.mode,x,b,S]),c(()=>{_.mode===`edit`&&!l&&D===null&&(S(null),b())},[_.mode,l,D,b,S]),c(()=>{_.mode===`closed`&&x!==null&&S(null)},[_.mode,x,S]);let O=ce({onSuccess:()=>{t.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),k=xe({onSuccess:()=>{t.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),A=async(t,n)=>{ze(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:Re(n).consequence}),confirmLabel:e(`common.disable`,`Disable`),variant:`danger`})||k.mutate(He(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:`${n instanceof Error?n.message:String(n)}\n\nForcing the delete removes the record only. Anything still on that location becomes unreachable — index rows naming it stop resolving, and playback of those segments goes silently black rather than erroring.`,confirmLabel:e(`system.storage.forceDelete`,`Force delete`),variant:`danger`})&&O.mutate({id:t.id,force:!0},{onSuccess:()=>{_.mode===`edit`&&_.id===t.id&&C()}})}},M=r(()=>{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!==``,L=_.mode===`edit`&&D!==null;return n(Fe,{embedded:!0,children:[N&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:e(`system.storage.loadingLocations`,`Loading locations…`)}),P&&s(`div`,{className:`text-xs text-danger`,children:e(`system.storage.failedToLoadStorageLocations`,`Failed to load storage locations.`)}),!N&&!P&&n(`div`,{className:`space-y-3`,children:[f.length===0&&s(`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=>s(Be,{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&&s(We,{initialType:x,onClose:C,onCreated:()=>{t.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),C()}}),L&&D!==null&&s(Ve,{location:D,onClose:C,onSaved:()=>{t.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),C()}})]})}var Ke={settings:{label:`Configuration & files`,description:`Configuration database, addons, addon data and certificates. Nightly.`},events:{label:`Events & detections`,description:`Tracks, detections and notification history. Statistical: weekly is enough.`},history:{label:`History (statistics)`,description:`Long-term statistics and ledgers. Statistical: weekly is enough.`}},qe=Object.keys(Ke),J=[`settings`],Je=`Created when this feature is enabled`;function Ye(e){return Ke[e].label}function Xe(e){return Ke[e].description}function Y(e){let t=new Set(e);return qe.filter(e=>t.has(e))}function X(e){return e!==void 0&&e.length>0?Y(e):J}function Ze(e){return Y(e)}function Qe(e,t){return t===void 0||!t.answered?`unknown`:t.databases.includes(e)?`present`:`absent`}function $e(e,t,n){return Qe(e,t)===`absent`&&!n.has(e)}function et(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function tt(e){return!e.includes(`settings`)}function nt(e){return{databases:[...Ze(e)]}}function rt(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}){let{t}=K();return n(`span`,{className:`flex flex-wrap items-center gap-1`,"data-testid":`backup-database-badges`,children:[e.map(e=>s(ve,{variant:e===`settings`?`primary`:`info`,style:`fill`,size:`sm`,children:Ye(e)},e)),tt(e)&&s(ve,{variant:`warning`,style:`fill`,size:`sm`,children:t(`backup.backupDatabaseBadges.snapshotsOnly`,`Snapshots only`)})]})}t();var it=[[`backup`,`listDestinations`]],at=[`backup`,`listArchives`];function ot({destinationId:t,restoreSupported:i,onOpenRestoreWizard:c}){let{t:l}=K(),f=a(),p=U(),{data:m,isLoading:h,isError:g}=ke({destinationId:t}),_=m??[],v=fe({onSuccess:()=>{f.invalidateQueries({queryKey:[[...at]]}),f.invalidateQueries({queryKey:it})}}),y=e(async e=>{await p({title:l(`backup.archiveList.deleteThisArchive`,`Delete this archive?`),message:l(`backup.archiveList.permanentlyDeletesAndFrees`,`Permanently deletes "{{value1}}" and frees {{value2}}.`,{value1:e.label??e.id,value2:q(e.sizeBytes)}),confirmLabel:l(`common.delete`,`Delete`),variant:`danger`})&&v.mutate({destinationId:t,backupId:e.id})},[p,t,v,l]),[x,C]=o(null),w=e(async e=>{C(e.id);try{let n=await Ie(st(t,e.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.label??e.id}.tar.gz${e.encryption===void 0?``:`.csbk`}`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{C(null)}},[t]),E=r(()=>[..._].toSorted((e,t)=>t.createdAt-e.createdAt),[_]);return h?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:l(`backup.archiveList.loadingArchives`,`Loading archives…`)}):g?s(`div`,{className:`text-xs text-danger py-2`,children:l(`backup.archiveList.failedToReadManifestFor`,`Failed to read manifest for this destination`)}):E.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:l(`backup.archiveList.noArchivesAtThisDestination`,`No archives at this destination yet.`)}):s(z,{columns:[{key:`when`,header:l(`backup.archiveList.when`,`When`),sortValue:e=>e.createdAt,render:e=>s(`span`,{className:`tabular-nums`,children:ct(e.createdAt)})},{key:`label`,header:l(`backup.archiveList.label`,`Label`),sortValue:e=>e.label??null,render:e=>n(`span`,{className:`inline-flex items-center gap-1`,children:[e.encryption!==void 0&&s(T,{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??s(`span`,{className:`text-foreground-subtle italic`,children:`—`})]})},{key:`databases`,header:l(`backup.archiveList.databases`,`Databases`),nowrap:!1,notSortableReason:`Database badges`,render:e=>s(Z,{databases:X(e.databases)})},{key:`includes`,header:l(`backup.archiveList.files`,`Files`),nowrap:!1,notSortableReason:`Location list`,render:e=>e.locations.length>0?s(`span`,{className:`text-foreground-subtle`,children:e.locations.join(`, `)}):s(`span`,{className:`text-foreground-subtle italic`,children:`none`})},{key:`size`,header:l(`backup.archiveList.size`,`Size`),align:`right`,sortValue:e=>e.sizeBytes,render:e=>s(`span`,{className:`tabular-nums`,children:q(e.sizeBytes)})},{key:`actions`,header:``,align:`right`,notSortableReason:`Actions`,render:e=>n(`span`,{className:`flex items-center justify-end gap-1`,children:[n(L,{variant:`ghost`,size:`sm`,onClick:()=>{w(e)},disabled:x===e.id,title:l(`backup.archiveList.downloadArchive`,`Download archive`),children:[x===e.id?s(S,{className:`h-3 w-3 animate-spin`}):s(u,{className:`h-3 w-3`}),l(`backup.archiveList.download`,`Download`)]}),i&&c&&n(L,{variant:`ghost`,size:`sm`,onClick:()=>c({destinationId:t,archiveId:e.id}),title:l(`backup.archiveList.restoreFromThisArchive`,`Restore from this archive`),children:[s(b,{className:`h-3 w-3`}),l(`backup.archiveList.restore`,`Restore`)]}),s(V,{variant:`ghost`,size:`sm`,icon:d,"aria-label":l(`backup.archiveList.delete`,`Delete {{value1}}`,{value1:e.label??e.id}),disabled:v.isPending,onClick:()=>{y(e)}})]})}],rows:E,rowKey:e=>e.id,minWidthPx:760,mobileMode:`cards`,emptyMessage:l(`backup.archiveList.noArchivesAtThisDestination`,`No archives at this destination yet.`)})}function st(e,t){return _(`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}function ct(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}t();var lt=[[`backup`,`listSchedules`]];function ut({onEdit:t,onOpenRestoreWizard:i}){let{t:a}=K(),{data:c,isLoading:l,isError:u,error:d,refetch:f}=ge(),p=c??[],m=De().data??[],h=r(()=>{let e=new Map;for(let t of m)e.set(t.id,t);return e},[m]),[g,_]=o(null),v=e(e=>{_(t=>t===e?null:e)},[]),y=g===null?null:p.find(e=>e.id===g)??null,b=r(()=>dt({destById:h,expandedId:g,onToggleExpand:v,onEdit:t}),[h,g,v,t]);return l?n(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle animate-pulse`,children:[s(S,{className:`h-3.5 w-3.5 animate-spin`}),a(`backup.backupEntriesTable.loadingBackupEntries`,`Loading backup entries…`)]}):u?s(ie,{title:a(`backup.backupEntriesTable.failedToLoadBackupEntries`,`Failed to load backup entries`),message:d instanceof Error?d.message:a(`backup.backupEntriesTable.unknownError`,`Unknown error`),onRetry:()=>void f()}):p.length===0?s(le,{icon:A,title:a(`backup.backupEntriesTable.noBackupEntriesYet`,`No backup entries yet`),description:a(`backup.backupEntriesTable.createOneToScheduleBackups`,`Create one to schedule backups across one or more storage locations.`)}):n(`div`,{className:`space-y-2`,children:[s(z,{columns:b,rows:p,rowKey:e=>e.id,minWidthPx:980,maxBodyHeight:ue,mobileMode:`cards`,emptyMessage:a(`backup.backupEntriesTable.noBackupEntriesYet`,`No backup entries yet`),onRowClick:e=>t(e)}),y!==null&&s(vt,{row:y,destById:h,...i?{onOpenRestoreWizard:i}:{}})]})}function dt(e){return[{key:`expand`,header:``,width:`w-8`,nowrap:!0,notSortableReason:`Expand control`,render:t=>{let n=e.expandedId===t.id;return s(V,{variant:`ghost`,size:`sm`,icon:n?k:y,"aria-label":n?G.t(`backup.backupEntriesTable.hideArchives`,`Hide archives`):G.t(`backup.backupEntriesTable.showArchives`,`Show archives`),"aria-expanded":n,onClick:n=>{n.stopPropagation(),e.onToggleExpand(t.id)}})}},{key:`entry`,header:G.t(`backup.backupEntriesTable.entry`,`Entry`),sortValue:e=>e.label,render:e=>n(`span`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate font-medium text-foreground`,children:e.label||G.t(`backup.backupEntriesTable.unnamed`,`(unnamed)`)}),e.lastRunAt!==void 0&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`last run `,new Date(e.lastRunAt).toLocaleString()]})]})},{key:`enabled`,header:G.t(`backup.backupEntriesTable.enabled`,`Enabled`),width:`w-20`,nowrap:!0,sortValue:e=>+!!e.enabled,render:e=>s(`span`,{onClick:e=>e.stopPropagation(),children:s(ht,{row:e})})},{key:`databases`,header:G.t(`backup.backupEntriesTable.backsUp`,`Backs up`),nowrap:!1,notSortableReason:`Database badges`,render:e=>s(Z,{databases:X(e.databases)})},{key:`locations`,header:G.t(`backup.backupEntriesTable.locations`,`Locations`),nowrap:!1,notSortableReason:`Location chips`,render:t=>s(ft,{row:t,destById:e.destById})},{key:`retention`,header:G.t(`backup.backupEntriesTable.retention`,`Retention`),width:`w-24`,nowrap:!0,sortValue:e=>e.retentionCount,render:e=>s(`span`,{onClick:e=>e.stopPropagation(),children:s(gt,{row:e})})},{key:`schedule`,header:G.t(`backup.backupEntriesTable.schedule`,`Schedule`),width:`w-48`,nowrap:!0,sortValue:e=>e.cron,render:e=>s(pt,{row:e})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:t=>s(`span`,{onClick:e=>e.stopPropagation(),children:s(_t,{row:t,onEdit:()=>e.onEdit(t)})})}]}function ft({row:e,destById:t}){let{t:n}=K();return e.locationIds.length===0?s(`span`,{className:`text-[11px] italic text-danger`,children:n(`backup.backupEntriesTable.noLocations`,`No locations`)}):s(`span`,{className:`flex flex-wrap gap-1`,children:e.locationIds.map(e=>s(`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 pt({row:e}){let{t}=K(),r=e.cron.trim().length>0;return n(`span`,{className:`flex flex-col items-start gap-0.5`,children:[n(`span`,{className:`inline-flex items-center gap-1`,children:[s(A,{className:`h-3 w-3 text-foreground-subtle`}),s(`span`,{className:`font-mono text-[11px] text-foreground`,children:r?e.cron:t(`backup.backupEntriesTable.manual`,`Manual`)})]}),r&&e.nextRunAt!==void 0&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`next `,new Date(e.nextRunAt).toLocaleString()]})]})}function mt(e){return r(()=>({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 ht({row:e}){let{t}=K(),n=a(),r=Ae({onSuccess:()=>{n.invalidateQueries({queryKey:lt})}}),i=mt(e);return s(`label`,{className:`inline-flex cursor-pointer items-center`,children:s(`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 gt({row:e}){let{t}=K(),n=a(),r=Ae({onSuccess:()=>{n.invalidateQueries({queryKey:lt})}}),i=mt(e),[l,u]=o(String(e.retentionCount));return c(()=>{u(String(e.retentionCount))},[e.retentionCount]),s(me,{type:`number`,min:1,max:1e3,value:l,disabled:r.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&&r.mutate({...i,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":t(`backup.backupEntriesTable.retentionFor`,`Retention for {{value1}}`,{value1:e.label||e.id})})}function _t({row:e,onEdit:t}){let{t:r}=K(),i=a(),o=U(),c=he({onSuccess:()=>{i.invalidateQueries({queryKey:lt})}}),l=we({onMutate:()=>{i.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{i.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),i.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),i.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})}}),u=()=>{e.locationIds.length!==0&&l.mutate({destinations:[...e.locationIds],...e.dataSources&&e.dataSources.length>0?{locations:[...e.dataSources]}:{},label:e.label,retentionCount:e.retentionCount,databases:[...X(e.databases)]})},f=async()=>{await o({title:r(`backup.backupEntriesTable.deleteBackupEntry`,`Delete backup entry?`),message:r(`backup.backupEntriesTable.willStopRunningExistingArchives`,`"{{value1}}" will stop running. Existing archives are kept.`,{value1:e.label||e.id}),confirmLabel:r(`common.delete`,`Delete`),variant:`warning`})&&c.mutate({id:e.id})};return n(`span`,{className:`flex items-center justify-end gap-1.5`,children:[n(L,{size:`sm`,type:`button`,onClick:u,disabled:l.isPending||e.locationIds.length===0,title:r(`backup.backupEntriesTable.runThisEntryNow`,`Run this entry now`),children:[l.isPending?s(S,{className:`h-3 w-3 animate-spin`}):s(w,{className:`h-3 w-3`}),r(`backup.backupEntriesTable.runNow`,`Run now`)]}),s(V,{variant:`ghost`,size:`sm`,icon:g,"aria-label":r(`backup.backupEntriesTable.edit`,`Edit {{value1}}`,{value1:e.label||e.id}),onClick:t}),s(V,{variant:`ghost`,size:`sm`,icon:d,"aria-label":r(`backup.backupEntriesTable.delete`,`Delete {{value1}}`,{value1:e.label||e.id}),disabled:c.isPending,onClick:()=>{f()}})]})}function vt({row:e,destById:t,onOpenRestoreWizard:r}){let{t:i}=K();return n(`div`,{className:`space-y-4 rounded-lg border border-border bg-background/30 px-4 py-3`,children:[n(`p`,{className:`text-[11px] font-medium text-foreground-subtle`,children:[`Archives for `,e.label||e.id]}),e.locationIds.length===0&&s(`p`,{className:`text-xs italic text-foreground-subtle`,children:i(`backup.backupEntriesTable.thisEntryHasNoLocations`,`This entry has no locations selected.`)}),e.locationIds.map(e=>n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:t.get(e)?.displayName??e}),s(ot,{destinationId:e,restoreSupported:t.get(e)?.restoreSupported??!0,...r?{onOpenRestoreWizard:r}:{}})]},e))]})}function yt({selected:e,onChange:t,disabled:r=!1,testId:i=`backup-databases`}){let{t:a}=K(),o=Te().data,c=e.size>0&&tt(Y(e)),l=e.size===0?`Pick at least one.`:c?`Snapshots only: configuration and files are not part of this backup.`:null;return s(R,{label:a(`backup.backupDatabasePicker.whatToBackUp`,`What to back up`),required:!0,...l===null?{}:{description:l},children:s(`div`,{className:`divide-y divide-border rounded border border-border bg-background`,"data-testid":i,children:qe.map(c=>{let l=Qe(c,o),u=r||$e(c,o,e);return n(`label`,{className:`flex items-start gap-2 px-3 py-2 text-xs ${u?`opacity-60`:`cursor-pointer hover:bg-primary/5`}`,children:[s(_e,{checked:e.has(c),disabled:u,onChange:()=>t(et(e,c)),"data-testid":`${i}-${c}`}),n(`span`,{className:`min-w-0 flex-1`,children:[n(`span`,{className:`flex flex-wrap items-center gap-1.5 text-foreground`,children:[Ye(c),l===`absent`&&s(ve,{variant:`neutral`,size:`sm`,children:a(`backup.backupDatabasePicker.notCreatedYet`,`Not created yet`)})]}),s(`span`,{className:`block text-[11px] text-foreground-subtle`,children:l===`absent`?Je:Xe(c)})]})]},c)})})})}t();function bt({onClose:e}){let{t}=K(),r=a(),[i,c]=o(new Set(J)),l=we({onMutate:()=>{r.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{r.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),r.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),r.invalidateQueries({queryKey:[[`backup`,`listRuns`]]}),e()}});return s(H,{open:!0,onOpenChange:t=>!t&&e(),children:n(te,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[n(F,{children:[s(Ce,{children:t(`backup.backupNowDialog.backUpNow`,`Back up now`)}),s(`p`,{className:`text-xs text-foreground-subtle`,children:t(`backup.backupNowDialog.runsOnceAndWritesThe`,`Runs once and writes the archive to every enabled backup location.`)})]}),s(ne,{children:n(`div`,{className:`p-4`,children:[s(yt,{selected:i,onChange:c,disabled:l.isPending,testId:`backup-now-databases`}),l.error&&s(`p`,{role:`alert`,className:`pt-2 text-xs text-danger`,children:l.error.message})]})}),n(W,{children:[s(L,{variant:`outline`,size:`sm`,onClick:e,children:t(`common.cancel`,`Cancel`)}),n(L,{size:`sm`,onClick:()=>{i.size!==0&&l.mutate(nt(i))},disabled:i.size===0||l.isPending,"data-testid":`backup-now-run`,children:[l.isPending?s(S,{className:`h-3.5 w-3.5 animate-spin`}):s(w,{className:`h-3.5 w-3.5`}),t(`backup.backupNowDialog.backUpNow`,`Back up now`)]})]})]})})}t();function xt(e){return e===null?`—`:new Date(e).toLocaleString()}function St(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 Ct({revealed:e,onDone:t}){let{t:r}=K(),[i,a]=o(!1),[c,l]=o(!1);return s(H,{open:!0,onOpenChange:e=>!e&&i&&t(),children:n(te,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`border-danger/40`,"aria-labelledby":`backup-key-title`,children:[s(F,{children:n(Ce,{id:`backup-key-title`,children:[`Your backup key (`,e.keyId,`)`]})}),n(ne,{className:`space-y-3`,children:[n(`p`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 p-2 text-xs text-foreground`,children:[s(m,{className:`mt-0.5 h-4 w-4 shrink-0 text-danger`}),s(`span`,{children:r(`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.`)})]}),s(`div`,{className:`break-all rounded-md border border-border bg-background p-2 font-mono text-xs text-foreground select-all`,children:e.secretKey}),n(`div`,{className:`flex flex-wrap gap-2`,children:[n(L,{size:`sm`,variant:`outline`,onClick:()=>{navigator.clipboard?.writeText(e.secretKey).then(()=>l(!0))},children:[s(v,{className:`mr-1 h-3.5 w-3.5`}),c?r(`backup.backupEncryptionCard.copied`,`Copied`):r(`common.copy`,`Copy`)]}),n(L,{size:`sm`,variant:`outline`,onClick:()=>St(e),children:[s(u,{className:`mr-1 h-3.5 w-3.5`}),r(`backup.backupEncryptionCard.downloadAsFile`,`Download as file`)]})]}),n(`label`,{className:`flex items-center gap-2 text-xs text-foreground`,children:[s(`input`,{type:`checkbox`,checked:i,onChange:e=>a(e.target.checked),className:`accent-primary`}),r(`backup.backupEncryptionCard.iHaveStoredThisKey`,`I have stored this key somewhere safe, off this server.`)]})]}),s(W,{children:s(L,{size:`sm`,disabled:!i,onClick:t,children:r(`backup.backupEncryptionCard.iHaveStoredIt`,`I have stored it`)})})]})})}function wt(){let{t:e}=K(),t=P(),r=ye(),a=oe(),c=U(),[l,u]=o(null),[d,f]=o(null),p=t.data?.enabled??!1,m=t.data?.active??null,h=(t.data?.keys??[]).filter(e=>e.retiredAt!==null),g=async()=>{if(await c({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 r.mutateAsync({});u({keyId:e.keyId,secretKey:e.secretKey})}catch(e){f(e instanceof Error?e.message:String(e))}}},_=async()=>{if(await c({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 a.mutateAsync({}),t.refetch()}catch(e){f(e instanceof Error?e.message:String(e))}}};return n(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-4`,children:[n(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[n(`div`,{className:`flex items-center gap-2`,children:[p?s(T,{className:`h-4 w-4 text-success`}):s(O,{className:`h-4 w-4 text-foreground-subtle`}),s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`backup.backupEncryptionCard.encryption`,`Encryption`)}),s(`span`,{className:`text-xs text-foreground-subtle`,children:p&&m!==null?e(`backup.backupEncryptionCard.onKeySince`,`On — key {{keyId}}, since {{value2}}`,{keyId:m.keyId,value2:xt(m.createdAt)}):e(`backup.backupEncryptionCard.offBackupsAreNotEncrypted`,`Off — backups are not encrypted`)})]}),s(`div`,{className:`flex gap-2`,children:p?n(i,{children:[s(L,{size:`sm`,variant:`outline`,disabled:r.isPending,onClick:()=>void g(),children:e(`backup.backupEncryptionCard.replaceKey`,`Replace key`)}),s(L,{size:`sm`,variant:`outline`,disabled:a.isPending,onClick:()=>void _(),children:e(`backup.backupEncryptionCard.turnOff`,`Turn off`)})]}):s(L,{size:`sm`,disabled:r.isPending,onClick:()=>void g(),children:e(`backup.backupEncryptionCard.enableEncryption`,`Enable encryption`)})})]}),s(`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&&n(`div`,{className:`text-xs`,children:[s(`p`,{className:`text-foreground-subtle`,children:e(`backup.backupEncryptionCard.olderKeysBackupsMadeWith`,`Older keys (backups made with them still need them):`)}),s(`ul`,{className:`font-mono text-foreground`,children:h.map(e=>n(`li`,{children:[e.keyId,` · `,xt(e.createdAt),` → `,xt(e.retiredAt)]},e.keyId))})]}),d!==null&&s(`p`,{className:`text-xs text-danger`,children:d}),l!==null&&s(Ct,{revealed:l,onDone:()=>{u(null),t.refetch()}})]})}t();var Tt=[{id:`manual`,label:`Manual only`,cron:``},{id:`hourly`,label:`Every hour`,cron:`0 * * * *`,description:`On the hour`},{id:`every-3h`,label:`Every 3 hours`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,label:`Every 6 hours`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,label:`Daily at 03:00`,cron:`0 3 * * *`,description:`Every night at 3 AM`},{id:`weekly-sun`,label:`Weekly Sunday 03:00`,cron:`0 3 * * 0`,description:`Sunday morning at 3 AM`}];function Et(e){let t=e.trim();for(let e of Tt)if(e.cron===t)return e.id;return`custom`}function Dt({value:e,onChange:t,previewCount:r=5,disabled:i=!1}){let{t:a}=K(),l=Et(e),[u,d]=o(l===`custom`);c(()=>{l!==`custom`&&d(!1)},[l]);let f=At(e,250),p=Ee({cron:f,count:r},{enabled:f.trim().length>0}),m=p.data??null,h=e=>{d(!1),t(e.cron)},g=u||l===`custom`;return n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:a(`backup.cronEditor.schedulePreset`,`Schedule preset`)}),n(`div`,{className:`flex flex-wrap gap-1.5`,children:[Tt.map(e=>s(`button`,{type:`button`,onClick:()=>h(e),disabled:i,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.description??e.label,children:e.label},e.id)),s(`button`,{type:`button`,onClick:()=>{d(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:i,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:a(`backup.cronEditor.custom`,`Custom…`)})]})]}),g&&n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:a(`backup.cronEditor.cronExpression5FieldPosix`,`Cron expression (5-field POSIX)`)}),s(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:i,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`}),n(`p`,{className:`text-[10px] text-foreground-subtle`,children:[a(`backup.cronEditor.format`,`Format:`),` `,s(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),s(Ot,{cron:f,preview:m,loading:p.isFetching})]})}function Ot({cron:e,preview:t,loading:r}){let{t:i}=K();return r&&t===null?n(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[s(S,{className:`h-3 w-3 animate-spin`}),i(`backup.cronEditor.validating`,`Validating…`)]}):t===null?null:t.ok?t.nextRuns.length===0?s(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:i(`backup.cronEditor.noFutureRunsMatchThis`,`No future runs match this expression.`)}):n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:i(`backup.cronEditor.nextRuns`,`Next runs`)}),s(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>n(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[s(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),s(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:kt(e)})]},`${e}-${t}`))})]}):s(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??i(`backup.cronEditor.invalidCronExpression`,`Invalid cron expression`)})}function kt(e){let t=e-Date.now();if(t<=0)return`now`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function At(e,t){let[n,i]=o(e),a=r(()=>e,[e]);return c(()=>{let e=setTimeout(()=>i(a),t);return()=>clearTimeout(e)},[a,t]),n}t();var jt=[[`backup`,`listSchedules`]];function Mt({entry:e,onClose:t,onSaved:i}){let{t:c}=K(),l=a(),u=De(),d=u.data??[],[f,p]=o(e?.label??``),[m,h]=o(e?.cron??`0 3 * * *`),[g,_]=o(e?.enabled??!0),[v,y]=o(String(e?.retentionCount??7)),[b,x]=o(new Set(e?.locationIds??[])),[C,w]=o(new Set(e===null?J:X(e.databases))),T=Ae({onSuccess:()=>{l.invalidateQueries({queryKey:jt}),i()}}),E=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},D=Number.parseInt(v,10),O=r(()=>f.trim().length>0&&b.size>0&&C.size>0&&!Number.isNaN(D)&&D>=1&&D<=1e3,[f,b,C,D]),k=()=>{O&&T.mutate({...e?{id:e.id}:{},label:f.trim(),cron:m.trim(),enabled:g,locationIds:Array.from(b),retentionCount:D,databases:[...Ze(C)]})},j=T.error instanceof Error?T.error.message:null;return s(je,{open:!0,onClose:t,title:e?c(`backup.backupEntryModal.editBackupEntry`,`Edit backup entry`):c(`backup.backupEntryModal.newBackupEntry`,`New backup entry`),icon:A,error:j,width:`lg`,testId:`backup-entry-form`,footer:n(L,{size:`sm`,type:`button`,onClick:k,disabled:!O||T.isPending,children:[T.isPending?s(S,{className:`h-3.5 w-3.5 animate-spin`}):null,e?c(`common.save`,`Save`):c(`backup.backupEntryModal.createEntry`,`Create entry`)]}),children:n(`div`,{className:`space-y-4`,children:[s(R,{label:c(`backup.backupEntryModal.name`,`Name`),required:!0,children:s(me,{value:f,onChange:e=>p(e.target.value),placeholder:c(`backup.backupEntryModal.nightlyOffsite`,`Nightly offsite`),autoFocus:!0,"data-testid":`backup-entry-name`})}),n(R,{label:c(`backup.backupEntryModal.locationsSelected`,`Locations ({{value1}} selected)`,{value1:String(b.size)}),required:!0,children:[u.isLoading&&n(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[s(S,{className:`h-3.5 w-3.5 animate-spin`}),c(`backup.backupEntryModal.loadingLocations`,`Loading locations…`)]}),!u.isLoading&&d.length===0&&s(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:c(`backup.backupEntryModal.noBackupsStorageLocationsConfigured`,"No `backups` storage locations configured. Add one in Settings → Storage first.")}),d.length>0&&s(`div`,{className:`max-h-52 divide-y divide-border overflow-y-auto rounded border border-border bg-background`,children:d.map(e=>n(`label`,{className:`flex cursor-pointer items-center justify-between px-3 py-2 text-xs hover:bg-primary/5`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`checkbox`,checked:b.has(e.id),onChange:()=>E(e.id),className:`accent-primary`}),s(`span`,{className:`text-foreground`,children:e.displayName})]}),n(`div`,{className:`flex items-center gap-1.5`,children:[s(`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}),s(`span`,{className:`font-mono text-[10px] text-foreground-subtle`,children:e.id})]})]},e.id))})]}),s(yt,{selected:C,onChange:w,disabled:T.isPending,testId:`backup-entry-databases`}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[s(R,{label:c(`backup.backupEntryModal.retentionArchivesKept`,`Retention (archives kept)`),required:!0,children:s(me,{type:`number`,min:1,max:1e3,value:v,onChange:e=>y(e.target.value),"data-testid":`backup-entry-retention`})}),s(R,{label:c(`backup.backupEntryModal.enabled`,`Enabled`),description:c(`backup.backupEntryModal.runOnScheduleWhenChecked`,`Run on schedule when checked.`),children:n(`label`,{className:`inline-flex cursor-pointer items-center gap-2 py-1.5 text-xs text-foreground`,children:[s(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`accent-primary`,"data-testid":`backup-entry-enabled`}),s(`span`,{children:c(`backup.backupEntryModal.runOnSchedule`,`Run on schedule`)})]})})]}),s(R,{label:c(`backup.backupEntryModal.schedule`,`Schedule`),children:s(Dt,{value:m,onChange:h,disabled:T.isPending})})]})})}t();var Nt=2e3,Pt=5e3;function Q(e){return e.state===`queued`||e.state===`running`}function Ft(e){if(e.state===`queued`)return{title:G.t(`backup.backupRunsPanel.cancelQueuedBackupRun`,`Cancel queued backup run?`),message:G.t(`backup.backupRunsPanel.thisRunHasNotStarted`,`This run has not started. Cancelling removes it from the queue — nothing has been written, nothing is deleted.`),confirmLabel:G.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:G.t(`backup.backupRunsPanel.stopThisBackupRun`,`Stop this backup run?`),message:G.t(`backup.backupRunsPanel.theHalfWrittenStagingArchive`,`The half-written staging archive is deleted and the destination currently uploading discards its partial copy. {{keptSentence}}`,{keptSentence:n}),confirmLabel:G.t(`backup.backupRunsPanel.stopRun`,`Stop run`),variant:`danger`}}function It(){let t=U(),[n,r]=o(null),i=Se(void 0,{refetchInterval:e=>(e.state.data??[]).some(Q)?Nt:Pt}),a=pe({onSettled:()=>{r(null),i.refetch()}}),c=e(async e=>{await t(Ft(e))&&(r(e.id),a.mutate({runId:e.id}))},[t,a]);return s(Lt,{queryState:i.isError?`error`:i.data===void 0?`pending`:`ready`,runs:i.data??[],cancelingId:n,onCancelRequest:e=>{c(e)},now:Date.now()})}function Lt({queryState:e,runs:t,cancelingId:r,onCancelRequest:i,now:a}){let{t:o}=K(),c=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 n(`section`,{className:`rounded-lg border border-border bg-surface`,children:[n(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border`,children:[s(`h2`,{className:`text-xs font-semibold text-foreground`,children:o(`backup.backupRunsPanel.runs`,`Runs`)}),c&&n(`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:[s(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary animate-pulse`}),`live`]}),s(`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`&&s(`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`&&s(`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&&s(`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&&s(`div`,{className:`overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[720px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.run`,`Run`)}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.state`,`State`)}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.progress`,`Progress`)}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.destinations`,`Destinations`)}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.timing`,`Timing`)}),s(`th`,{className:`text-right px-3 py-1.5 font-medium w-28`,children:o(`backup.backupRunsPanel.actions`,`Actions`)})]})}),s(`tbody`,{children:f.map(e=>s(Rt,{run:e,canceling:r===e.id,onCancelRequest:i,now:a},e.id))})]})})]})}function Rt({run:e,canceling:t,onCancelRequest:r,now:i}){let{t:a}=K(),o=Q(e);return n(`tr`,{className:`border-t border-border hover:bg-primary/5 align-top`,children:[n(`td`,{className:`px-3 py-2`,children:[s(`div`,{className:`text-foreground`,children:e.label??s(`span`,{className:`text-foreground-subtle italic`,children:`manual`})}),s(`div`,{className:`text-[10px] text-foreground-subtle font-mono`,title:e.id,children:e.id.slice(0,8)})]}),n(`td`,{className:`px-3 py-2`,children:[s(zt,{run:e}),e.state===`failed`&&e.error!==void 0&&s(`div`,{className:`mt-1 text-[10px] text-danger max-w-56 truncate`,title:e.error,children:e.error})]}),s(`td`,{className:`px-3 py-2`,children:s(Bt,{run:e})}),s(`td`,{className:`px-3 py-2`,children:s(Vt,{run:e})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle tabular-nums`,children:s(Ht,{run:e,now:i})}),s(`td`,{className:`px-3 py-2`,children:s(`div`,{className:`flex justify-end`,children:o&&n(`button`,{onClick:()=>r(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`?a(`backup.backupRunsPanel.removeThisRunFromThe`,`Remove this run from the queue before it starts`):a(`backup.backupRunsPanel.stopThisRunTheHalf`,`Stop this run — the half-written archive is discarded`),children:[t?s(S,{className:`h-3 w-3 animate-spin`}):s(l,{className:`h-3 w-3`}),e.state===`queued`?a(`common.cancel`,`Cancel`):a(`backup.backupRunsPanel.stop`,`Stop`)]})})})]})}function zt({run:e}){let{t}=K();switch(e.state){case`queued`:return n(`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:[s(D,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.queued`,`Queued`)]});case`running`:return n(`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:[s(S,{className:`h-3 w-3 animate-spin`}),e.phase===`uploading`?t(`backup.backupRunsPanel.uploading`,`Uploading`):t(`backup.backupRunsPanel.buildingArchive`,`Building archive`)]});case`succeeded`:return n(`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:[s(C,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.succeeded`,`Succeeded`)]});case`failed`:return n(`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:[s(x,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.failed`,`Failed`)]});case`cancelled`:return n(`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:[s(M,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.stopped`,`Stopped`)]})}}function Bt({run:e}){let{t}=K();if(e.state===`queued`)return s(`span`,{className:`text-foreground-subtle`,children:e.queuePosition===void 0?s(`span`,{className:`italic`,children:t(`backup.backupRunsPanel.waitingItsTurn`,`waiting its turn`)}):n(`span`,{className:`inline-flex items-center gap-1`,children:[s(`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:Ut(e.queuePosition)}),t(`backup.backupRunsPanel.inLine`,`in line`)]})});if(e.state===`running`&&e.phase===`building`)return n(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[s(N,{className:`h-3 w-3 text-primary`}),s(`span`,{className:`tabular-nums font-medium animate-pulse`,children:q(e.stagedBytes)}),s(`span`,{className:`text-foreground-subtle`,children:t(`backup.backupRunsPanel.stagedSoFar`,`staged so far`)})]});if(e.state===`running`){let r=e.archiveSizeBytes;return n(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[s(j,{className:`h-3 w-3 text-primary`}),n(`span`,{className:`tabular-nums font-medium`,children:[q(e.uploadedBytes),r===void 0?``:` / ${q(r)}`]}),s(`span`,{className:`text-foreground-subtle`,children:t(`backup.backupRunsPanel.toCurrentDestination`,`to current destination`)})]})}let r=e.archiveSizeBytes??(e.stagedBytes>0?e.stagedBytes:void 0);return r===void 0?s(`span`,{className:`text-foreground-subtle italic`,children:`—`}):n(`span`,{className:`tabular-nums text-foreground`,children:[q(r),` archive`]})}function Vt({run:e}){let{t}=K(),r=e.destinationIds.length,i=e.completedDestinationIds.length,a=e.failedDestinationIds.length;return r===0?s(`span`,{className:`text-foreground-subtle italic`,children:t(`backup.backupRunsPanel.notResolvedYet`,`not resolved yet`)}):n(`div`,{className:`flex flex-col gap-0.5`,children:[n(`span`,{className:`text-foreground-subtle`,title:e.destinationIds.join(`, `),children:[r,` target`,r===1?``:`s`]}),n(`span`,{className:`inline-flex items-center gap-2 text-[10px]`,children:[i>0&&n(`span`,{className:`text-success`,title:t(`backup.backupRunsPanel.keptTheirArchive`,`Kept their archive: {{value1}}`,{value1:e.completedDestinationIds.join(`, `)}),children:[`✓ `,i,` completed`]}),a>0&&n(`span`,{className:`text-danger`,title:t(`backup.backupRunsPanel.failed2`,`Failed: {{value1}}`,{value1:e.failedDestinationIds.join(`, `)}),children:[`✗ `,a,` failed`]})]})]})}function Ht({run:e,now:t}){return e.state===`queued`?n(`span`,{children:[`queued `,Wt(t-e.requestedAt),` ago`]}):e.startedAt===void 0?s(`span`,{children:`—`}):e.finishedAt===void 0?n(`span`,{children:[`running for `,Wt(t-e.startedAt)]}):n(`div`,{className:`flex flex-col gap-0.5`,children:[s(`span`,{children:Gt(e.finishedAt)}),n(`span`,{className:`text-[10px]`,children:[`took `,Wt(e.finishedAt-e.startedAt)]})]})}function Ut(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 Wt(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 Gt(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}t();var Kt=[[`backup`,`list`]];function qt({initialDestinationId:e,initialArchiveId:t,onClose:i,onScheduled:l}){let{t:u}=K(),d=a(),[p,m]=o(e&&t?2:1),[h,g]=o(e),[_,v]=o(t),[y,x]=o(new Set),[C,w]=o(``),{data:T}=De(),D=T??[],{data:O,isLoading:k}=ke({destinationId:h??``},{enabled:!!h}),A=O??[];c(()=>{if(h!==void 0)return;let e=D.filter(e=>e.restoreSupported);e.length===1&&g(e[0].id)},[h,D]);let{data:j}=be({destinationId:h??``,backupId:_??``},{enabled:!!h&&!!_}),M=r(()=>j?.locations??[],[j]);c(()=>{M.length!==0&&x(e=>e.size===0?new Set(M):e)},[M]);let N=Oe({onSuccess:()=>{d.invalidateQueries({queryKey:Kt}),l(),i()}}),P=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},I=A.find(e=>e.id===_),ee=I?.encryption!==void 0,R=rt(I?.databases,j?.sqliteSnapshots),z=tt(R),re=!!h&&!!_,B=z||y.size>0,ie=re&&B&&!N.isPending&&(!ee||C.trim().length>0),ae=()=>{!h||!_||N.mutate({destinationId:h,backupId:_,...z?{}:{locations:[...y]},...ee?{backupSecretKey:C.trim()}:{}})};return s(H,{open:!0,onOpenChange:e=>!e&&i(),children:n(te,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[n(F,{children:[s(Ce,{children:u(`backup.restoreWizard.restoreBackup`,`Restore Backup`)}),n(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,p,` of 3 —`,` `,p===1?u(`backup.restoreWizard.pickSource`,`pick source`):p===2?u(`backup.restoreWizard.pickLocations`,`pick locations`):`confirm`]})]}),n(ne,{children:[p===1&&s(Jt,{destinations:D,destinationId:h,onPickDestination:e=>{g(e),v(void 0),x(new Set)},archives:A,archivesLoading:k,archiveId:_,onPickArchive:v}),p===2&&s(Yt,{locations:M,picked:y,onToggle:P,databases:R,snapshotsOnly:z}),p===3&&s(Xt,{destinationName:D.find(e=>e.id===h)?.displayName??h??``,archive:I,picked:[...y],databases:R,snapshotsOnly:z}),p===3&&I?.encryption!==void 0&&s(Zt,{keyId:I.encryption.keyId,value:C,onChange:w}),p===3&&N.error&&s(`p`,{role:`alert`,className:`px-4 pb-2 text-xs text-danger`,children:N.error.message})]}),n(W,{className:`justify-between`,children:[s(`div`,{children:p>1&&n(L,{variant:`outline`,size:`sm`,onClick:()=>m(e=>e===3?2:1),children:[s(E,{className:`h-3 w-3`}),u(`common.back`,`Back`)]})}),n(`div`,{className:`flex items-center gap-2`,children:[s(L,{variant:`outline`,size:`sm`,onClick:i,children:u(`common.cancel`,`Cancel`)}),p<3?n(L,{size:`sm`,disabled:p===1&&!re||p===2&&!B,onClick:()=>m(e=>e===1?2:3),children:[u(`common.next`,`Next`),s(f,{className:`h-3 w-3`})]}):n(L,{size:`sm`,onClick:ae,disabled:!ie,children:[N.isPending?s(S,{className:`h-3.5 w-3.5 animate-spin`}):s(b,{className:`h-3.5 w-3.5`}),u(`backup.restoreWizard.scheduleRestore`,`Schedule Restore`)]})]})]})]})})}function Jt({destinations:e,destinationId:t,onPickDestination:r,archives:i,archivesLoading:a,archiveId:o,onPickArchive:c}){let{t:l}=K(),u=e.filter(e=>e.restoreSupported);return n(`div`,{className:`p-4 space-y-3`,children:[n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:l(`backup.restoreWizard.destination`,`Destination`)}),s(re,{value:t??``,onChange:e=>r(e.target.value),options:[{value:``,label:l(`backup.restoreWizard.selectDestination`,`Select destination…`)},...u.map(e=>({value:e.id,label:`${e.displayName} (${e.kind})`}))]})]}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:l(`backup.restoreWizard.archive`,`Archive`)}),!t&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:l(`backup.restoreWizard.pickADestinationFirst`,`Pick a destination first.`)}),t&&a&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:l(`backup.restoreWizard.readingArchives`,`Reading archives…`)}),t&&!a&&i.length===0&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:l(`backup.restoreWizard.noArchivesAvailableAtThis`,`No archives available at this destination.`)}),t&&i.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:i.map(e=>{let t=o===e.id;return n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>c(e.id),className:`accent-primary`}),n(`div`,{children:[n(`div`,{className:`flex items-center gap-1 font-medium text-foreground`,children:[e.encryption!==void 0&&s(T,{className:`h-3 w-3 text-success`,"aria-label":l(`backup.restoreWizard.encryptedKey`,`encrypted (key {{keyId}})`,{keyId:e.encryption.keyId})}),e.label??e.id]}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()}),s(`div`,{className:`pt-1`,children:s(Z,{databases:rt(e.databases,void 0)})})]})]}),s(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:q(e.sizeBytes)})]},e.id)})})]})]})}function Yt({locations:e,picked:t,onToggle:r,databases:i,snapshotsOnly:a}){let{t:o}=K();return a?n(`div`,{className:`space-y-3 p-4`,children:[n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:o(`backup.restoreWizard.databasesInThisArchive`,`Databases in this archive`)}),s(Z,{databases:i})]}),s(`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?s(`div`,{className:`p-4`,children:s(`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.`)})}):n(`div`,{className:`p-4 space-y-3`,children:[n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:o(`backup.restoreWizard.databasesInThisArchive`,`Databases in this archive`)}),s(Z,{databases:i})]}),s(`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.`)}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:o(`common.apply`,`Apply`)}),s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>n(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>r(e),className:`accent-primary`}),s(`span`,{className:`font-mono text-foreground`,children:e}),s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:$t(e)})]},e))})]})]})}function Xt({destinationName:e,archive:t,picked:r,databases:i,snapshotsOnly:a}){let{t:o}=K();return n(`div`,{className:`p-4 space-y-3 text-xs`,children:[s(`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.`)}),n(`dl`,{className:`space-y-1.5`,children:[s($,{term:`Destination`,value:e}),s($,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&s($,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${q(t.sizeBytes)}`}),s($,{term:`Databases`,value:i.map(e=>Ye(e)).join(`, `)}),s($,{term:`Locations`,value:a?`none (configuration is not touched)`:r.length>0?r.join(`, `):`— (full archive)`})]})]})}function Zt({keyId:e,value:t,onChange:r}){let{t:i}=K();return n(`div`,{className:`space-y-1.5 px-4 pb-3`,children:[s(`label`,{htmlFor:`restore-backup-key`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:i(`backup.restoreWizard.backupKey`,`Backup key`)}),s(`input`,{id:`restore-backup-key`,type:`password`,autoComplete:`off`,spellCheck:!1,value:t,onChange:e=>r(e.target.value),placeholder:i(`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`}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`This archive is encrypted to backup key `,s(`span`,{className:`font-mono`,children:e}),`. Paste the secret key shown when that key was created. It is used to decrypt the archive on this server and is not stored.`]})]})}function $({term:e,value:t}){return n(`div`,{className:`flex justify-between gap-3`,children:[s(`dt`,{className:`text-foreground-subtle`,children:e}),s(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Qt={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function $t(e){return Qt[e]??``}t();function en(){let{t:e}=K(),t=U(),r=ae(),{state:i,openNew:a,openEdit:l,close:u}=B({editKey:`edit`,newKey:`new`}),d=ge(),f=d.data??[],[p,m]=o(null),[g,_]=o(!1),[v,y]=o(!1),[x,C]=o(!1),T=i.mode===`edit`?f.find(e=>e.id===i.id)??null:null;c(()=>{i.mode===`edit`&&!d.isLoading&&T===null&&u()},[i.mode,d.isLoading,T,u]);let E=i.mode===`new`||i.mode===`edit`&&T!==null,D=async()=>{await t({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`})&&r.mutate({confirm:!0})};return n(Fe,{embedded:!0,children:[n(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,"data-testid":`backup-actions`,children:[n(L,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>C(!0),"data-testid":`backup-now`,children:[s(w,{className:`h-3.5 w-3.5`}),e(`system.backup.backUpNow`,`Back up now`)]}),n(L,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>_(!0),children:[s(b,{className:`h-3.5 w-3.5`}),e(`system.backup.restore`,`Restore…`)]}),n(L,{size:`sm`,type:`button`,onClick:a,"data-testid":`backup-new-entry`,children:[s(h,{className:`h-3.5 w-3.5`}),e(`system.backup.newEntry`,`New entry`)]})]}),v&&s(`div`,{className:`rounded-lg border border-warning/30 bg-warning/10 px-3 py-2.5 text-xs text-warning`,children:n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(b,{className:`h-3.5 w-3.5`}),s(`span`,{children:e(`system.backup.restoreScheduledRestartTheServer`,`Restore scheduled. Restart the server to apply.`)})]}),n(L,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>{D()},disabled:r.isPending,children:[r.isPending?s(S,{className:`h-3.5 w-3.5 animate-spin`}):s(b,{className:`h-3.5 w-3.5`}),e(`system.backup.restartNow`,`Restart Now`)]})]})}),s(wt,{}),s(It,{}),s(ut,{onEdit:e=>l(e.id),onOpenRestoreWizard:e=>m(e)}),E&&s(Mt,{entry:T,onClose:u,onSaved:u}),x&&s(bt,{onClose:()=>C(!1)}),(p||g)&&s(qt,{...p?{initialDestinationId:p.destinationId,initialArchiveId:p.archiveId}:{},onClose:()=>{m(null),_(!1)},onScheduled:()=>y(!0)})]})}function tn(){let{t:e}=K(),t=Ne(`/system/data`,{t:e,isAdmin:!0})??{icon:p,title:e(`system.data`,`Data`)};return s(Pe,{icon:t.icon,title:t.title,defaultSection:`storage`,sectionsLabel:`${t.title} sections`,sections:[{id:`storage`,label:e(`systemPage.data.storage`,`Storage`),content:s(Ge,{})},{id:`backup`,label:e(`systemPage.data.backup`,`Backup`),content:s(en,{})}]})}export{tn as DataPage};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,W as i,a,b as o,o as s,q as c,t as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{$t as f,D as p,Fi as m,G as h,Gn as g,It as _,J as v,Jr as y,K as b,Kr as x,Ln as S,Lr as C,O as w,Pi as T,Qi as E,Ri as D,Rn as O,Rr as k,St as A,T as j,Tn as M,V as ee,W as N,Wn as P,Xt as F,Yn as I,Z as L,_n as te,_t as R,ar as ne,bi as z,bn as B,br as V,cr as re,di as ie,dt as ae,fn as oe,ht as H,m as U,ot as W,qn as se,r as ce,si as le,sr as G,t as ue,un as de,vn as fe,wi as pe,yn as me,z as he}from"./player-overlays-Cda8wso6.js";import{t as ge}from"./archive-kvflMCgL.js";import{i as _e,n as ve,r as ye,t as be}from"./scan-eye-DVK8MF3K.js";import{t as xe}from"./bell-off-BYnwGeiH.js";import{t as Se}from"./boxes-Dx4USyB3.js";import{n as K}from"./video-tLHyNE3q.js";import{t as Ce}from"./circle-slash-D5mo-8G0.js";import{t as we}from"./layers-C1wzFfr1.js";import{An as Te,Ar as Ee,Br as De,Dr as q,Er as Oe,Fn as ke,Mr as J,Nn as Ae,Pn as je,Vr as Me,Xn as Ne,_ as Pe,_i as Fe,_r as Ie,b as Le,en as Re,f as ze,fn as Be,g as Ve,gi as He,in as Ue,jr as Y,ln as We,lr as Ge,m as Ke,nn as qe,p as Je,pr as Ye,rn as Xe,tn as Ze,u as Qe,un as $e,wr as et,yr as tt}from"./client-CMlUvfoK.js";import{$s as nt,A as rt,Ai as it,An as at,Bi as ot,Bn as X,Ca as st,Ct as ct,Dn as lt,Ds as ut,Ei as dt,En as ft,Fn as pt,Ha as mt,Hi as ht,Ht as gt,Ia as _t,Ii as vt,In as yt,Is as bt,Jr as xt,K as St,Kl as Ct,Kn as wt,Kt as Tt,Ln as Et,M as Dt,Mn as Ot,Mr as kt,Ms as At,Mt as jt,Nn as Mt,Os as Nt,Qi as Pt,Ql as Ft,Qs as It,Qt as Lt,S as Rt,T as zt,Tc as Bt,Ti as Vt,Tn as Ht,Tt as Ut,Ui as Wt,Vn as Gt,Vs as Kt,Vt as qt,W as Jt,Wi as Yt,Yo as Xt,Zl as Zt,Zn as Qt,Zs as $t,Zt as en,_t as tn,_u as nn,a as rn,an,ar as on,as as sn,at as cn,ba as ln,bt as un,c as dn,cn as fn,co as pn,ct as mn,d as hn,da as gn,dn as _n,dt as vn,du as yn,ec as bn,en as xn,et as Sn,eu as Cn,fo as wn,ft as Tn,fu as En,gt as Dn,ha as On,hn as kn,ht as An,i as jn,in as Mn,it as Nn,iu as Pn,j as Fn,ji as In,jn as Ln,js as Rn,k as zn,ka as Bn,kn as Vn,ks as Hn,l as Un,ln as Wn,lt as Gn,lu as Kn,ma as qn,mo as Jn,mr as Yn,nc as Xn,nn as Zn,nt as Qn,nu as $n,o as er,oa as tr,or as nr,ot as rr,pa as ir,po as ar,q as or,r as sr,rn as cr,rs as lr,s as ur,sa as dr,sn as fr,sr as pr,ta as mr,tc as hr,tn as gr,tu as _r,ua as vr,uc as yr,un as br,w as xr,wn as Sr,wt as Cr,x as wr,xt as Tr,yt as Er,za as Dr,zi as Or,zt as kr}from"./src-eoSUZcV-.js";import{t as Z}from"./useTranslation-Bc5yH9V9.js";import"./mount-DlnG_8P7.js";import{A as Ar,B as jr,D as Mr,G as Nr,J as Pr,K as Fr,M as Ir,N as Lr,O as Rr,Q as zr,R as Br,U as Vr,V as Hr,W as Ur,X as Wr,Z as Gr,g as Kr,j as qr,k as Jr,q as Yr,v as Xr,y as Zr,z as Qr}from"./index-BgQGn3LX.js";import{C as $r,D as ei,E as ti,S as ni,_ as ri,a as ii,b as ai,c as oi,d as si,f as ci,g as li,h as ui,i as di,l as fi,m as pi,n as mi,o as hi,p as gi,r as _i,s as vi,t as yi,u as bi,v as xi,x as Si,y as Ci}from"./CompositionEditor-vP3JcV2R.js";import{_ as wi,a as Ti,c as Ei,d as Di,f as Oi,g as ki,h as Ai,i as ji,l as Mi,m as Ni,n as Pi,o as Fi,p as Ii,s as Li,t as Ri,u as zi,v as Bi,y as Vi}from"./ClusterStepModel-DHbwIGAW.js";import"./useEventInvalidation-DlnG_8P7.js";import{t as Hi}from"./use-stationary-objects-BWM4vE0E.js";import{a as Ui,c as Wi,d as Gi,f as Ki,i as qi,l as Ji,n as Yi,o as Xi,p as Zi,r as Qi,s as $i,t as ea,u as ta}from"./linked-devices-model-CCTQ_gka.js";import{t as na}from"./authed-media-CSlndmzS.js";n();function ra(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 ia(e){if(typeof e!=`object`||!e)return null;let t=e.switches;if(!Array.isArray(t))return null;let n=t.map(ra).filter(e=>e!==null);return n.length===0?null:n}var aa=[[/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 oa(e){for(let[t,n]of aa)if(t.test(e))return n;return`generic`}function sa(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(`Off: ${r(t)}`),n.length>0&&i.push(`Unknown: ${r(n)}`),{offIds:t,unknownIds:n,summary:i.length===0?`All camera functions on`:i.join(` · `)}}var ca={stream:B,detection:be,privacy:C,microphone:I,speaker:A,listening:ve,archive:ge,recording:ye,notifications:T,generic:f};function la({deviceId:t}){let{t:n}=Z(),i=s(),a=Number.isFinite(t),[o,l]=c(null),[d,p]=c(!1),m=At({deviceId:t},{enabled:a});sr([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let h=ia(m.data),g=Xn({onError:(e,n)=>{console.error(`[CameraFunctionSwitches] switch write failed — reverting`,{tags:{deviceId:t},meta:{switchId:n.switchId,error:e instanceof Error?e.message:String(e)}}),i.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSwitches`]]}),l({id:n.switchId,message:e instanceof Error?e.message:String(e)})},onSuccess:()=>{l(null),i.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),i.invalidateQueries({queryKey:[[`deviceManager`]]}),i.invalidateQueries({queryKey:[[`recording`]]})}}),_=e(e=>{!e.available||e.on===null||g.mutate({deviceId:t,switchId:e.id,enabled:!e.on})},[t,g]);if(h===null)return null;let v=sa(h),y=e=>o?.id===e.id?o.message:null;return r(Cn,{open:d,onOpenChange:p,children:[r($n,{"aria-label":n(`device.cameraFunctionSwitches.cameraFunctions`,`Camera functions`),title:v.summary,className:`inline-flex items-center gap-1 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors ${o===null?v.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:[u(f,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden lg:inline`,children:n(`device.cameraFunctionSwitches.functions`,`Functions`)}),v.offIds.length>0&&r(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:[v.offIds.length,` off`]})]}),r(_r,{align:`end`,className:`min-w-[240px] max-h-[60vh] overflow-y-auto p-1`,children:[u(`div`,{className:`px-2 py-1 text-[10px] uppercase tracking-wider text-foreground-subtle`,children:n(`device.cameraFunctionSwitches.cameraFunctions`,`Camera functions`)}),u(`ul`,{className:`space-y-0.5`,children:h.map(e=>u(`li`,{children:u(ua,{row:e,failure:y(e),onToggle:()=>_(e)})},e.id))})]})]})}function ua({row:e,failure:t,onToggle:n}){let i=ca[oa(e.label)],a=e.on===null,o=e.on===!1,s=t===null?a?e.unavailableReason??`The source that owns this did not answer.`:e.costWhenOff:`Write failed: ${t}`,c=t===null?a?e.unavailableReason??`unknown`:null:`write failed`;return r(`button`,{type:`button`,role:`switch`,"aria-label":e.label,"aria-checked":e.on===!0,disabled:!e.available,onClick:n,title:s,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:[u(i,{className:`h-3.5 w-3.5 shrink-0 ${t===null?a?`text-foreground-subtle/50`:o?`text-warning`:`text-success`:`text-danger`}`}),r(`span`,{className:`flex-1 min-w-0 truncate`,children:[e.label,c!==null&&r(`span`,{className:`ml-1 text-[10px] text-foreground-subtle`,children:[`· `,c]})]}),u(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[9px] font-semibold uppercase tracking-wide ${a?`bg-surface-hover text-foreground-subtle/60`:o?`bg-warning/20 text-warning`:`bg-success/20 text-success`}`,children:a?`—`:o?`off`:`on`})]})}function da({deviceId:e}){let t=vn(W().trpcClient,e);return t===null?null:r(`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:[u(k,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:t.label})]})}function fa({parentDeviceId:e}){let{t}=Z(),n=Wr(),i=W(),{data:a,isLoading:o,isError:s}=Hr(e),{data:c}=vr({deviceId:e},{enabled:Number.isFinite(e)});if(o)return u(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(s)return u(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let l=(a??[]).filter(e=>e.display?.hidden!==!0);if(l.length===0)return null;let d=rr(c?.stableId??``,l,c?.childLayout),f=d.ungrouped,p=e=>n(`/devices/${String(e)}`),m=c?.name??``,h=(e,t)=>u(Nn,{trpc:i.trpcClient,device:{...t,name:Tn(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?r(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[u(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:v}),u(`div`,{className:`space-y-1`,children:f.map(e=>h(e.id,e))})]}):null,b=d.disabledSection===void 0?null:u(cn,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:d.disabledSection.children.length,defaultOpen:!1,children:u(`div`,{className:`opacity-60 space-y-1`,children:d.disabledSection.children.map(e=>h(e.id,e))})},d.disabledSection.title);if(d.sections.length===0)return b===null?y:r(`div`,{className:`space-y-2`,children:[y,b]});let x=_&&!g;return r(`div`,{className:`space-y-2`,children:[x?y:null,d.sections.map(e=>u(cn,{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 pa({deviceId:e}){let t=W(),{data:n,isLoading:r}=jr(e),{data:i,isLoading:a}=Hr(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?u(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):u(`div`,{className:`flex h-full w-full flex-col`,children:u(An,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}n();function ma({dev:e,busy:t,setBusy:n}){let{t:i}=Z(),a=e?.motionTrigger,o=v(e?.state.motionTrigger),[s,l]=c(!1);if(!a)return null;let d=o?.enabled===!0,f=o!==void 0,p=async()=>{if(t||!f)return;let e=!d;n(!0),l(!0);try{await a.setMotionTrigger({enabled:e})}finally{n(!1),l(!1)}},m=s?d?`Disabling…`:`Enabling…`:f?d?`On motion: on`:`On motion: off`:`On motion: …`;return r(`button`,{type:`button`,onClick:()=>{p()},disabled:t||!f,title:f?d?i(`hero.motionTriggerToggle.disableTriggerOnMotion`,`Disable trigger on motion`):i(`hero.motionTriggerToggle.enableTriggerOnMotion`,`Enable trigger on motion`):i(`hero.motionTriggerToggle.awaitingState`,`Awaiting state…`),"aria-pressed":d,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 ${d?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[u(E,{className:`h-3 w-3`}),u(`span`,{children:m})]})}n();function Q({deviceId:e,deviceType:t,features:n}){let i=W(),a=Er(t)?.HeroCard??un,o=b(i.trpcClient,e),s=v(o?.state.deviceStatus),[l,d]=c(!1),f=s!==void 0&&s.online===!1,p=f?s.lastChangedAt:null;return r(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[f?u(`div`,{className:`flex justify-center`,children:u(tn,{lastChangedAt:p})}):null,u(a,{trpc:i.trpcClient,deviceId:e,features:n}),u(`div`,{className:`flex justify-center`,children:u(ma,{dev:o,busy:l,setBusy:d})})]})}function ha({deviceId:e,features:t}){return u(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:u(Tr,{trpc:W().trpcClient,deviceId:e,features:t})})}function ga({deviceId:e,features:t}){return u(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:u(un,{trpc:W().trpcClient,deviceId:e,features:t})})}function _a(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function va(e){if(!e)return null;let t=_a(e.data);return t===null?e.eventType:`Button ${String(t)} · ${e.eventType}`}var ya=1e3,ba=60*ya,xa=60*ba,Sa=24*xa;function Ca(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<ya?`just now`:n<ba?`${String(Math.floor(n/ya))}s ago`:n<xa?`${String(Math.floor(n/ba))}m ago`:n<Sa?`${String(Math.floor(n/xa))}h ago`:`${String(Math.floor(n/Sa))}d ago`}n();var wa=1500,Ta=15e3,Ea=1e3;function Da({deviceId:e}){let{t:n}=Z(),i=b(W().trpcClient,e)?.state.eventEmitter,a=v(i);d(()=>{if(!i)return;i.refresh();let e=setInterval(()=>{i.refresh()},Ta);return()=>{clearInterval(e)}},[i]);let o=a?.lastEvent??null,s=o?.seq??null,l=t(null),[f,p]=c(!1);d(()=>{if(s===null)return;let e=l.current;if(l.current=s,e===null||e===s)return;p(!0);let t=setTimeout(()=>{p(!1)},wa);return()=>{clearTimeout(t)}},[s]);let[m,h]=c(()=>Date.now());d(()=>{let e=setInterval(()=>{h(Date.now())},Ea);return()=>{clearInterval(e)}},[]);let g=va(o),_=a?.eventTypes??[],y=a?.eventCountSinceStart??0,x=a!==void 0,S=_a(o?.data);return r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[u(`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:g??n(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`),children:u(f?P:V,{className:`h-10 w-10`})}),r(`div`,{className:`text-center`,children:[S!==null&&u(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:n(`hero.eventEmitterHero.button`,`Button {{value1}}`,{value1:String(S)})}),u(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${g?`text-foreground`:`text-foreground-subtle`}`,children:g??(x?n(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`):n(`hero.eventEmitterHero.awaitingState`,`Awaiting state…`))}),u(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:o?Ca(o.timestamp,m):n(`hero.eventEmitterHero.waitingForTheFirstEvent`,`Waiting for the first event`)})]}),_.length>0&&u(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:_.map(e=>u(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===o?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),u(`div`,{className:`text-[10px] text-foreground-subtle`,children:`${String(y)} ${y===1?`event`:`events`} since start`})]})}function Oa({deviceName:e,deviceType:t,provider:n,isOnline:i,features:a}){let{t:o}=Z();return r(`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:[u(Fr,{type:n,size:`lg`}),r(`div`,{children:[u(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),u(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),r(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[u(Dt,{status:i?`online`:`offline`}),a.length>0&&u(Yr,{capabilities:a})]}),u(`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.`)})]})}n();function ka({deviceId:e}){let{t}=Z(),n=s(),a=Or({deviceId:e},{refetchInterval:1e4,retry:!1}),o=ot({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),n.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),c=i(()=>Aa(a.data??[]),[a.data]);return r(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[r(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[u(ja,{label:t(`hero.hubHero.discovered`,`Discovered`),value:c.total,icon:u(O,{className:`h-3.5 w-3.5`})}),u(ja,{label:t(`hero.hubHero.adopted`,`Adopted`),value:c.adopted,accent:`success`}),u(ja,{label:t(`hero.hubHero.available`,`Available`),value:c.available,accent:c.available>0?`primary`:void 0}),r(`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?u(ne,{className:`h-3.5 w-3.5 animate-spin`}):u(me,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:t(`hero.hubHero.discover`,`Discover`)})]})]}),r(`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:[u(Ma,{icon:u(H,{className:`h-3 w-3 text-emerald-500`}),label:t(`hero.hubHero.online`,`{{online}} online`,{online:c.online})}),u(Ma,{icon:u(g,{className:`h-3 w-3 text-amber-500`}),label:t(`hero.hubHero.sleeping`,`{{sleeping}} sleeping`,{sleeping:c.sleeping})}),u(Ma,{icon:u(R,{className:`h-3 w-3 text-destructive`}),label:t(`hero.hubHero.offline`,`{{offline}} offline`,{offline:c.offline})}),c.unknown>0?u(Ma,{icon:u(le,{className:`h-3 w-3 text-foreground-subtle`}),label:t(`hero.hubHero.unknown`,`{{unknown}} unknown`,{unknown:c.unknown})}):null]})]})}function Aa(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 ja({label:e,value:t,icon:n,accent:i}){return r(`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 ${i===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:i===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[r(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,u(`span`,{className:`truncate`,children:e})]}),u(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function Ma({icon:e,label:t}){return r(`span`,{className:`inline-flex items-center gap-1`,children:[e,u(`span`,{children:t})]})}var Na={[J.Switch]:Q,[J.Siren]:Q,[J.Light]:Q,[J.Sensor]:Q,[J.Button]:Q,[J.Hub]:ka,[J.Cover]:ha,[J.Valve]:Q,[J.Humidifier]:Q,[J.WaterHeater]:Q,[J.Container]:pa,[J.Lock]:Q,[J.Fan]:Q,[J.Thermostat]:Q,[J.Climate]:Q,[J.MediaPlayer]:Q,[J.Control]:Q,[J.AlarmPanel]:Q,[J.EventEmitter]:Da,[J.Notifier]:ga,[J.Script]:Q,[J.Automation]:Q,[J.Presence]:Q,[J.Update]:Q,[J.Vacuum]:Q,[J.LawnMower]:Q,[J.Weather]:Q,[J.Image]:Q,[J.PetFeeder]:Q};function Pa(e){return Na[e]??Oa}function Fa(e){return u(Pa(e.deviceType),{...e})}function Ia(e){return er(W().trpcClient,e)}n();function La(n){let[r,i]=c(`idle`),[a,o]=c(null),s=t(null),l=t(null),u=t(null),f=t(!0),p=ar(),m=wn(),h=Jn(),g=e(()=>{if(s.current){try{s.current.close()}catch{}s.current=null}if(l.current){for(let e of l.current.getTracks())try{e.stop()}catch{}l.current=null}u.current=null},[]),_=e(async()=>{if(r===`idle`)return;i(`stopping`);let e=u.current;if(e&&n!==null)try{await Promise.race([h.mutateAsync({deviceId:n,sessionId:e}),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&&(i(`idle`),o(null))},[r,n,h,g]),v=e(async()=>{if(n===null||r!==`idle`&&r!==`error`)return;o(null);let e=null,t=null,a=null;try{i(`requesting-mic`),e=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),l.current=e,i(`starting`);let r=await p.mutateAsync({deviceId:n});a=r.sessionId,u.current=a,i(`connecting`),t=new RTCPeerConnection,s.current=t,t.oniceconnectionstatechange=()=>{if(!f.current)return;let e=t.iceConnectionState;e===`connected`||e===`completed`?i(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&f.current&&(o(e===`failed`?`WebRTC connection failed`:null),_())};for(let n of e.getAudioTracks())t.addTrack(n,e);await t.setRemoteDescription({type:`offer`,sdp:r.sdpOffer});let c=await t.createAnswer();await t.setLocalDescription(c);let d=t.localDescription?.sdp??c.sdp??``;await m.mutateAsync({deviceId:n,sessionId:a,sdpAnswer:d})}catch(r){let c=r instanceof Error?r.message:String(r);if(console.warn(`[intercom] start failed`,r),t)try{t.close()}catch{}if(e)for(let t of e.getTracks())try{t.stop()}catch{}if(s.current=null,l.current=null,a!==null)try{await h.mutateAsync({deviceId:n,sessionId:a})}catch{}u.current=null,f.current&&(o(c),i(`error`))}},[n,r,p,m,h,_]);return d(()=>(f.current=!0,()=>{f.current=!1;let e=u.current;if(e!==null&&n!==null&&h.mutate({deviceId:n,sessionId:e}),s.current){try{s.current.close()}catch{}s.current=null}if(l.current){for(let e of l.current.getTracks())try{e.stop()}catch{}l.current=null}u.current=null}),[n]),{state:r,error:a,start:v,stop:_,isTalking:r===`talking`}}n();var Ra=0;function $(){return++Ra}function za(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Ba(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 Va(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 Ha(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 Ua({scope:n,greeting:i,className:a}){let{t:o}=Z(),s=W(),[f,p]=c(()=>{let e=[];return i&&e.push({id:$(),kind:`info`,text:i}),e.push({id:$(),kind:`info`,text:`scope: ${za(n)} — type help or context for available commands`}),e}),[m,h]=c(``),[g,_]=c([]),[v,y]=c(-1),b=t(null),x=t(null);d(()=>{let e=x.current;e&&(e.scrollTop=e.scrollHeight)},[f]);let S=e(()=>{b.current?.focus()},[]),C=l({mutationFn:e=>s.trpcClient.repl.execute.mutate({code:e,scope:n}),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(e){let t=e.trim();if(t){if(t===`clear`){p([{id:$(),kind:`info`,text:`scope: ${za(n)}`}]),h(``);return}if(t===`help`){p(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`},...Ba(n).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}if(t===`context`){p(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`},...Ha(n).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}if(t===`examples`){p(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`},...Va(n).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}_(e=>[...e,t]),y(-1),p(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`}]),h(``),C.mutate(t)}}function T(e){if(e.key===`Enter`){e.preventDefault(),w(m);return}if(e.key===`ArrowUp`){if(e.preventDefault(),g.length===0)return;let t=v===-1?g.length-1:Math.max(0,v-1);y(t),h(g[t]??``);return}if(e.key===`ArrowDown`){if(e.preventDefault(),v===-1)return;let t=v+1;t>=g.length?(y(-1),h(``)):(y(t),h(g[t]??``));return}e.ctrlKey&&e.key===`l`&&(e.preventDefault(),p([{id:$(),kind:`info`,text:`scope: ${za(n)}`}]))}let E={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return r(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${a??``}`,onClick:S,children:[r(`div`,{ref:x,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[f.map(e=>u(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${E[e.kind]}`,children:e.text},e.id)),C.isPending&&u(`span`,{className:`text-zinc-500 animate-pulse`,children:o(`shared.replTerminal.thinking`,`…thinking`)})]}),r(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[u(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:o(`shared.replTerminal.text`,`>`)}),u(`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 Wa(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}}}n();function Ga({deviceId:e,intercomAvailable:t=!1}){let n=W(),r=typeof window<`u`?L():``,a=Number.isFinite(e),s=Ia(a?e:null),c=Hi(a?[e]:[]),l=i(()=>{if(!a)return;let e=[];for(let t of c.rows){let n=rn(t);n!==null&&e.push(n)}return e},[a,c.rows]),{streams:d,pipelineMetrics:f,createSession:p,sendAnswer:m,handleOffer:g,getIceServers:_,addIceCandidate:v,getIceCandidates:y,closeSession:b,getSessionState:x,applyDownlinkProbe:S}=kr(n.trpcClient,a?e:null),C=h(a?e:null,{width:Xa}),w=La(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=ce(),k=yt(),A=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,j=Wa(k.request,A),M=O.length>0?u(o,{children:O.map(e=>u(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return u(wr,{serverUrl:r,createSession:p,sendAnswer:m,handleOffer:g,getIceServers:_,addIceCandidate:v,getIceCandidates:y,closeSession:b,getSessionState:x,applyDownlinkProbe:S,...j===null?{}:{...j,onExitPlayback:()=>k.clear()},streams:d,pipelineMetrics:f,phase:s.phase,detections:s,...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 Ka({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full`,children:u(Ut,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function qa({deviceId:e}){if(!Number.isFinite(e))return r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let t=[`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 u(Ua,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function Ja({deviceId:e}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:u(Cr,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Ya({deviceId:e}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:u(ct,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}var Xa=960;function Za(e){return new Set(e.filter(e=>{let t=e.nativeAddonId?.trim()??``;return t!==``&&t!==`composer`}).map(e=>e.capName))}function Qa(e){return e.kind===`known`?null:e}function $a(e,t){return e.composable.kind===`known`?e.composable.value.has(t)?{kind:`present`,mode:`add`}:{kind:`absent`}:e.composable}function eo(e){if(e.deviceType!==J.Camera)return{kind:`absent`};switch(e.cameraSensors){case`pending`:return{kind:`pending`};case`unknown`:return{kind:`unknown`,reason:`camera sensors could not be checked`};case`absent`:return{kind:`absent`};case`present`:return{kind:`present`,mode:`add`}}}function to(e,t){if(e===`motion`)return eo(t);let n=Qa(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`}:$a(t,`doorbell`);case`battery`:return r.has(`battery`)?{kind:`present`,mode:`replace`}:$a(t,`battery`);case`consumables`:return r.has(`consumables`)?{kind:`absent`}:$a(t,`consumables`)}}function no({onAdvanced:e}){let{t}=Z();return e===void 0?null:u(`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 ro(e){if(e.status===`pending`)return{kind:`pending`};if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??`the request failed`};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=Ye(t.view.block);return n===null?{kind:`unknown`,reason:`block ${t.view.block.id} is not a composition`}:{kind:`present`,view:t.view,composition:n}}function io(e){return e.kind===`present`?e.composition:null}function ao(e,t){let{hidden:n,...r}=e??{},i=t?{...r,hidden:!0}:r;return Object.keys(i).length===0?null:i}function oo(e){return typeof e.linkDeviceId==`number`}var so=new Set(Object.values(Y));function co(e){return so.has(e)}var lo={[J.Switch]:[Y.Siren,Y.Floodlight,Y.Spotlight,Y.PirSensor,Y.Chime,Y.Autotrack,Y.Nightvision,Y.PrivacyMask,Y.BinaryHelper],[J.Light]:[Y.Floodlight,Y.Spotlight,Y.Nightvision],[J.Siren]:[Y.Siren],[J.Button]:[Y.Doorbell],[J.Sensor]:[Y.MotionSensor,Y.ContactSensor,Y.LeakSensor,Y.SmokeSensor,Y.COSensor,Y.GasSensor,Y.TamperSensor,Y.VibrationSensor,Y.ConnectivitySensor,Y.SoundSensor,Y.BinarySensor,Y.TemperatureSensor,Y.HumiditySensor,Y.AmbientLightSensor,Y.PressureSensor,Y.WindSensor,Y.RainSensor,Y.UvSensor,Y.SolarRadiationSensor,Y.SoilMoistureSensor,Y.PowerSensor,Y.EnergySensor,Y.VoltageSensor,Y.CurrentSensor,Y.AirQualitySensor,Y.BatterySensor,Y.NumericSensor,Y.EnumSensor,Y.DateTimeSensor,Y.GenericSensor],[J.Control]:[Y.NumericControl,Y.SelectControl,Y.TextControl,Y.DateTimeControl],[J.Notifier]:[Y.MobilePushNotifier,Y.MessagingNotifier,Y.EmailNotifier,Y.GenericNotifier]};function uo(e){for(let t of Object.values(J))if(t===e)return!0;return!1}function fo(e){return uo(e)?lo[e]??[]:[]}function po(e,t){let n=fo(t);return e==null||e===``||n.includes(e)?n:[...n,e]}n();function mo({device:e}){let{t}=Z(),n=s(),[i,a]=c(null),o=()=>a(null),l={onSuccess:()=>{o(),n.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>a(e.message)},d=_t(),f=Bn(),m=e.display?.hidden===!0;return r(`section`,{"aria-label":t(`customize.identity.title`),className:`${w} ${p}`,children:[r(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[u(Ur,{deviceId:e.id,initialName:e.name,label:t(`customize.identity.name`),layout:`stacked`,onError:a,onSaved:o,onCancel:o}),u(Vr,{deviceId:e.id,initialLocation:e.location,label:t(`customize.identity.room`),layout:`stacked`,onError:a,onSaved:o,onCancel:o}),u(Nr,{label:t(`customize.identity.hidden`),layout:`stacked`,value:u(an,{"aria-label":t(`deviceDisplay.hideFromLists`),checked:m,disabled:f.isPending,onChange:t=>f.mutate({deviceId:e.id,display:ao(e.display,t.target.checked)},l)})}),u(Nr,{label:t(`customize.identity.role`),layout:`stacked`,value:oo(e)?u(`span`,{children:ho(e.role,t(`customize.identity.noRole`))}):u(Ct,{"aria-label":t(`customize.identity.role`),value:e.role??``,disabled:d.isPending,options:[{value:``,label:t(`customize.identity.noRole`)},...po(e.role,e.type).map(e=>({value:e,label:ho(e,t(`customize.identity.noRole`))}))],onChange:t=>d.mutate({deviceId:e.id,role:t.target.value===``?null:t.target.value},l)})})]}),i!==null&&u(`p`,{role:`alert`,className:`mt-2 text-xs text-danger break-words`,children:i})]})}function ho(e,t){return e==null||e===``?t:co(e)?Kn(e).label:e}n();function go(e){return e===`pending`?`pending`:e===`error`?`failed`:`answered`}function _o({excludeDeviceIds:e,onSelect:t}){let{t:n}=Z(),r=qn({projection:`slim`}),a=r.status===`success`?r.data:null,o=i(()=>{if(a===null)return[];let t=new Set(e);return oi(a).filter(e=>!t.has(e.id))},[a,e]),s=i(()=>new Map(o.map(e=>[e.id,e])),[o]),c=i(()=>o.map(e=>({id:e.id,name:e.name,type:e.type,...e.location===null?{}:{location:e.location}})),[o]);if(r.status===`error`)return u(Et,{title:n(`customize.picker.devicesFailed`),message:r.error?.message??``});let l=e=>{let n=s.get(e);n!==void 0&&t(n)};return u(hn,{devices:c,listState:go(r.status),value:[],onChange:e=>{let t=e.at(-1);t!==void 0&&l(t)},noun:`device`,emptyLabel:n(`customize.assign.none`),showAll:!0,testId:`customize-field-device-picker`})}function vo({open:e,title:t,targetKind:n,excludeDeviceIds:i,confirmLabel:a,extra:s,extraComplete:l=!0,onConfirm:d,onClose:f}){let{t:p}=Z(),[m,h]=c(null),[g,_]=c(null),v=()=>{h(null),_(null),f()};return u(Ht,{open:e,onOpenChange:e=>e?void 0:v(),children:r(lt,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":t,children:[u(at,{children:u(Ln,{children:t})}),u(ft,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:e&&r(o,{children:[r(`section`,{"aria-label":p(`customize.assign.stepDevice`),className:`flex flex-col gap-1`,children:[u(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:p(`customize.assign.stepDevice`)}),m===null?u(_o,{excludeDeviceIds:i,onSelect:h}):r(`p`,{className:`flex items-center gap-2 text-xs text-foreground`,children:[m.name,u(X,{variant:`ghost`,size:`sm`,onClick:()=>{h(null),_(null)},children:p(`customize.assign.change`)})]})]}),m!==null&&r(`section`,{"aria-label":p(`customize.assign.stepField`),className:`flex flex-col gap-1`,children:[u(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:p(`customize.assign.stepField`)}),u(ii,{device:m,targetKind:n,selected:g===null?null:{cap:g.cap,path:g.path},onPick:_,onBack:()=>{h(null),_(null)}})]}),m!==null&&s!==void 0&&r(`section`,{"aria-label":p(`customize.assign.stepDetails`),className:`flex flex-col gap-1`,children:[u(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:p(`customize.assign.stepDetails`)}),s]})]})}),r(Vn,{children:[u(X,{variant:`ghost`,onClick:v,children:p(`customize.assign.cancel`)}),u(X,{disabled:g===null||!l,onClick:()=>{g!==null&&(d(g),h(null),_(null))},children:a})]})]})})}function yo(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function bo(e,t){let n=vi(e,t);return n===void 0?{kind:`absent`}:{kind:`value`,value:n}}function xo(e,t,n){return yo(t)?bo(t,n):e.status===`error`?{kind:`unknown`,reason:e.error?.message??`the value could not be read`}:e.status===`pending`||e.data===void 0?{kind:`pending`}:e.data===null?{kind:`absent`}:bo(e.data,n)}function So(e,t,n){let r=e?`active`:`muted`;return t.cap===`contact`&&t.path===`entryOpen`?{text:e?n.open:n.closed,tone:r}:Me[t.cap]===t.path?{text:e?n.active:n.inactive,tone:r}:{text:String(e),tone:`normal`}}function Co(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`?So(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 wo=0;function To(e){let t=W(),n=mt({deviceId:e?.deviceId??wo,capName:e?.cap??``},{enabled:e!==null}),r=ur(t.trpcClient,e?.deviceId??null,e?.cap??``);return e===null?{kind:`absent`}:xo({status:n.status,data:n.data,error:n.error===null||n.error===void 0?null:{message:n.error.message}},r,e.path)}var Eo={muted:`text-foreground-subtle`,active:`text-success`,normal:`text-foreground`,warning:`text-warning`};function Do({target:e}){let{t}=Z(),n=To(e);return e===null?null:u(Oo,{display:Co(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 Oo({display:e}){return u(`span`,{className:`text-xs ${Eo[e.tone]}`,title:e.title,children:e.text})}function ko({name:e,detail:t,meta:n,value:i,shown:a,problem:o,onRemove:s,removeLabel:c,busy:l=!1}){return r(`li`,{className:`${j} 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:[r(`div`,{className:`min-w-0`,children:[u(`div`,{className:`text-xs text-foreground break-words`,children:e}),t!==null&&u(`div`,{className:`text-[11px] text-foreground-subtle break-words`,children:t}),o!==void 0&&u(`div`,{role:`alert`,className:`text-[11px] text-warning break-words`,children:o})]}),u(`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}),u(`div`,{className:`row-start-3 col-start-1 empty:hidden sm:row-start-auto sm:col-start-auto sm:empty:block`,children:a===void 0?u(Do,{target:i}):a!==null&&u(Oo,{display:a})}),u(`div`,{className:`row-start-1 col-start-2 flex justify-end sm:row-start-auto sm:col-start-auto`,children:s!==void 0&&u(Ft,{icon:ae,variant:`ghost`,size:`sm`,"aria-label":c,disabled:l,onClick:s})})]})}function Ao({id:e,...t}){return u(qt,{headingId:`customize-${e}`,...t})}function jo({id:e,icon:t,title:n,headerControl:i,addLabel:a,onAdd:s,addDisabled:c=!1,notices:l,suggestion:d,children:f}){let{t:p}=Z(),m=s!==void 0&&a!==void 0;return r(Ao,{id:e,icon:t,title:n,actions:r(o,{children:[i,m&&!c&&d!==void 0&&d.count>0&&r(X,{variant:`ghost`,size:`sm`,onClick:d.onOpen,children:[u(F,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),p(`customize.suggest.hint`,{count:d.count,location:d.location})]}),m&&u(X,{variant:`outline`,size:`sm`,disabled:c,onClick:s,children:a})]}),children:[l!==void 0&&u(`div`,{className:`flex flex-col gap-1 px-3 pt-2 empty:hidden sm:px-4`,children:l}),u(`ul`,{className:`flex flex-col divide-y divide-border`,children:f})]})}function Mo({availability:e}){let{t}=Z();return e.kind===`pending`?u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.assign.checking`)}):e.kind===`unknown`?u(`p`,{role:`alert`,className:`text-xs text-warning`,children:t(`customize.assign.unknown`,{reason:e.reason})}):null}function No(e,t){if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??`the request failed`};let n=e.data;return e.status===`pending`||n===void 0?{kind:`pending`}:{kind:`known`,value:t(n)}}function Po(e,t){let n=nn.useQueries(n=>e.map(e=>n.deviceManager.listDeviceIdsByCaps({capNames:[e]},{enabled:t})));return ta(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}}}}))}n();function Fo(e,t){let n=Qn(e,t);return n.kind===`resolved`?n.integration.name:null}function Io(e){let t=qn({projection:`slim`},{enabled:e}),{data:n}=pn(void 0,{enabled:e}),r=t.error===null||t.error===void 0?null:t.error.message;return i(()=>No({status:t.status,data:t.data,error:r===null?null:{message:r}},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:Fo(e,n),parentDeviceId:e.parentDeviceId,primaryChildEntityId:e.primaryChildEntityId??null,role:e.role??null}))),[t.status,t.data,r,n])}function Lo(e){let t=Io(e.enabled),n=Po(De,e.enabled);return t.kind===`unknown`?t:n.kind===`unknown`?n:t.kind===`pending`||n.kind===`pending`?{kind:`pending`}:{kind:`known`,value:Zi({devices:t.value,capIndex:n.value,hostId:e.hostId,excludeCameras:e.excludeCameras,assigned:e.assigned,preferredCap:e.preferredCap})}}function Ro(){let{t:e}=Z(),t=Qt();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`})}n();function zo(e){return e===null?null:ui(e,`replace`)?`replace`:ui(e,`add`)?`add`:null}function Bo({device:e,handle:t,availability:n,onAdvanced:i}){let{t:a}=Z(),s=Ro(),[l,d]=c(!1),[f,p]=c(null),m=io(t.state),h=Ci(m,`battery`),g=zo(h),_=g===null?null:ri(h?.fields.percentage),v=Io(_!==null);if(n.kind===`absent`)return null;let y=n.kind===`present`?n.mode:null,b=t.state.kind===`none`||t.state.kind===`present`,x=_===null||v.kind!==`known`?null:v.value.find(e=>q({addonId:e.addonId,stableId:e.stableId})===q(_.source))??null,S=_===null?``:x?.name??q(_.source),C=async e=>{let n=await t.save(e);p(n.kind===`refused`?n.reason:null)},w=async()=>{if(m===null)return;let e=$r(m,`battery`);await s(a(`customize.battery.removeWhat`,{name:S}),e===null)&&await C(e)},T=y!==null&&b&&h===null&&!t.saving;return r(o,{children:[r(jo,{id:`battery`,icon:D,title:a(`customize.battery.title`),addLabel:a(y===`replace`?`customize.battery.replace`:`customize.battery.add`),onAdd:T?()=>d(!0):void 0,notices:r(o,{children:[u(Mo,{availability:n}),_!==null&&v.kind===`unknown`&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.assign.devicesUnreadable`,{reason:v.reason})}),f!==null&&u(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:f})]}),children:[y===`replace`&&b&&u(ko,{name:a(`customize.battery.native`),detail:null,meta:a(h===null?`customize.assign.native`:`customize.battery.nativeReplaced`),value:h===null?{deviceId:e.id,cap:`battery`,path:`percentage`}:null,removeLabel:``}),h===null&&y===`add`&&b&&u(`li`,{className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:a(`customize.assign.none`)}),_!==null&&u(ko,{name:S,detail:`${_.cap}.${_.fieldPath}`,meta:a(g===`replace`?`customize.assign.replaces`:`customize.assign.adds`),value:x===null?null:{deviceId:x.id,cap:_.cap,path:_.fieldPath},problem:x===null&&v.kind===`known`?a(`customize.assign.missingKept`):void 0,onRemove:b?()=>void w():void 0,removeLabel:a(`customize.assign.removeNamed`,{name:S}),busy:t.saving}),h!==null&&_===null&&u(ko,{name:a(`customize.battery.otherFormula`),detail:null,meta:u(no,{onAdvanced:i}),value:{deviceId:e.id,cap:`battery`,path:`percentage`},removeLabel:``})]}),u(vo,{open:l,title:a(y===`replace`?`customize.battery.replace`:`customize.battery.add`),targetKind:`number`,excludeDeviceIds:[e.id],confirmLabel:a(`customize.assign.add`),onConfirm:e=>{d(!1);let n=y===null?null:bi({percentage:{source:e.ref,cap:e.cap,fieldPath:e.path,kind:e.kind},mode:y});n===null?p(a(`customize.assign.pickUnusable`)):C(ni(m,t.target,n))},onClose:()=>d(!1)})]})}n();function Vo(e,t){let n=e.source;if(n===null||t.kind!==`known`)return null;let r=q(n.source);return t.value.find(e=>q({addonId:e.addonId,stableId:e.stableId})===r)??null}function Ho(e){let t=typeof e==`number`?e:typeof e==`string`?Number(e):NaN;return Number.isFinite(t)?t:null}function Uo({device:e,handle:t,availability:n,onAdvanced:i}){let{t:a}=Z(),s=Ro(),[l,d]=c(!1),[f,p]=c(``),[m,h]=c(`percent`),[g,_]=c(null),v=io(t.state),y=Ci(v,`consumables`),b=ci(y),x=Io(b.some(e=>e.source!==null));if(n.kind===`absent`)return null;let C=t.state.kind===`none`||t.state.kind===`present`,w=n.kind===`present`&&C&&!t.saving,T=li(f),E=b.find(e=>e.key===T)??null,D=E!==null,O=f.trim()!==``&&T===``,k=async e=>{let n=await t.save(e);_(n.kind===`refused`?n.reason:null)},A=()=>{d(!1),p(``),h(`percent`)},j=async e=>{if(y===null||v===null)return;let n=xi(y,e.key),r=n===null?$r(v,`consumables`):ni(v,t.target,n);await s(a(`customize.consumables.removeWhat`,{name:e.label}),r===null)&&await k(r)},M=r(`div`,{className:`flex flex-wrap items-end gap-2`,children:[r(`label`,{className:`flex w-full flex-col gap-1 text-[11px] text-foreground-subtle sm:w-56`,children:[a(`customize.consumables.name`),u(Zt,{"aria-label":a(`customize.consumables.name`),value:f,onChange:e=>p(e.target.value)})]}),r(`label`,{className:`flex w-full flex-col gap-1 text-[11px] text-foreground-subtle sm:w-40`,children:[a(`customize.consumables.unit`),u(Ct,{"aria-label":a(`customize.consumables.unit`),value:m,options:fi.map(e=>({value:e,label:a(`customize.consumables.units.${e}`)})),onChange:e=>{let t=fi.find(t=>t===e.target.value);t!==void 0&&h(t)}})]}),D&&u(`p`,{role:`alert`,className:`basis-full text-xs text-warning`,children:a(`customize.consumables.takenBy`,{name:E.label})}),O&&u(`p`,{role:`alert`,className:`basis-full text-xs text-warning`,children:a(`customize.consumables.keyless`)})]});return r(o,{children:[r(jo,{id:`consumables`,icon:S,title:a(`customize.consumables.title`),addLabel:a(`customize.consumables.add`),onAdd:w?()=>d(!0):void 0,notices:r(o,{children:[u(Mo,{availability:n}),x.kind===`unknown`&&b.some(e=>e.source!==null)&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.assign.devicesUnreadable`,{reason:x.reason})}),g!==null&&u(`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 u(ko,{name:e.label,detail:a(`customize.consumables.otherFormula`),meta:u(no,{onAdvanced:i}),value:null,removeLabel:``},e.key);let r=Vo(e,x),o=r?.name??q(n.source);return u(ko,{name:e.label,detail:`${a(`customize.consumables.units.${e.unit}`)} · ${o}`,meta:`${n.cap}.${n.fieldPath}`,value:r===null?null:{deviceId:r.id,cap:n.cap,path:n.fieldPath},problem:r===null&&x.kind===`known`?a(`customize.assign.missingKept`):void 0,onRemove:C?()=>void j(e):void 0,removeLabel:a(`customize.assign.removeNamed`,{name:e.label}),busy:t.saving},e.key)}),b.length===0&&n.kind===`present`&&C&&u(`li`,{className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:a(`customize.assign.none`)})]}),u(vo,{open:l,title:a(`customize.consumables.pickTitle`),targetKind:`number`,excludeDeviceIds:[e.id],confirmLabel:a(`customize.assign.add`),extra:M,extraComplete:T!==``&&!D,onConfirm:e=>{let n=Ho(e.value);if(n!==null&&(n<0||m===`percent`&&n>100)){A(),_(a(`customize.consumables.outOfRange`,{value:n}));return}let r=si(y,{key:T,label:f,remaining:{source:e.ref,cap:e.cap,fieldPath:e.path,kind:e.kind},unit:m});A(),r===null?_(a(`customize.assign.pickUnusable`)):k(ni(v,t.target,r))},onClose:A})]})}function Wo(e,t){if(e.kind!==`known`||typeof t!=`string`||t.length===0)return null;let n=pr(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 Go(e,t,n){return nr(e,t?.ids??new Set,n)}function Ko(e,t){return e?.containers.get(t)??null}function qo(e,t,n){return e.kind===`known`?Go(e.value,t,n).suggested.length:0}function Jo(e,t){let n=[t,e.detail].filter(e=>e!==null&&e!==``);return n.length===0?null:n.join(` · `)}function Yo({location:e,devices:t,action:n,onPick:i,onPickAll:a}){let{t:o}=Z();if(t.length===0)return null;let s=o(`customize.suggest.heading`,{location:e});return r(`section`,{"aria-label":s,className:`flex flex-col gap-1`,children:[r(`div`,{className:`flex min-h-7 items-center gap-2`,children:[u(`h3`,{className:`${ee} min-w-0 flex-1`,children:s}),a!==void 0&&t.length>1&&u(X,{variant:`ghost`,size:`sm`,onClick:a,children:o(`customize.suggest.addAll`,{count:t.length})})]}),u(`ul`,{className:`flex flex-col divide-y divide-border rounded-md border border-border`,children:t.map(e=>{let t=Jo(e,e.container===null||e.name.includes(e.container)?null:o(`customize.suggest.in`,{container:e.container}));return r(`li`,{className:`${j} flex items-center gap-3`,children:[r(`div`,{className:`min-w-0 flex-1`,children:[u(`div`,{className:`text-xs text-foreground break-words`,children:e.name}),t!==null&&u(`div`,{className:`text-[11px] text-foreground-subtle break-words`,children:t})]}),u(X,{variant:`outline`,size:`sm`,"aria-label":o(n===`add`?`customize.suggest.addNamed`:`customize.suggest.useNamed`,{name:e.name}),onClick:()=>i(e.id),children:o(n===`add`?`customize.suggest.add`:`customize.suggest.use`)})]},e.id)})})]})}n();function Xo(e){return e.kind===`pending`?`pending`:e.kind===`unknown`?`failed`:`answered`}function Zo(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 Qo({open:e,title:t,selection:n,candidates:a,filters:o,room:s=null,confirmLabel:l,onConfirm:f,onClose:p}){let{t:m}=Z(),[h,g]=c(null),[_,v]=c([]),y=o?.find(e=>e.id===h)??o?.[0]??null,b=a.kind===`known`?a.value:[],x=a.kind===`known`?Gi(a.value,``,y):[],S=Go(b,s,e=>e.deviceId).suggested,C=Go(x,s,e=>e.deviceId).others,w=i(()=>Zo(C),[C]),T=Xo(a),E=b.filter(e=>_.includes(e.deviceId));d(()=>{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 u(Ht,{open:e,onOpenChange:e=>e?void 0:D(),children:r(lt,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":t,children:[u(at,{children:u(Ln,{children:t})}),r(ft,{className:`flex flex-col gap-2 p-2 sm:p-4`,children:[o!==void 0&&o.length>0&&u(`div`,{className:`flex flex-wrap gap-1`,role:`tablist`,"aria-label":m(`customize.assign.filtersLabel`),children:o.map(e=>u(`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))}),s!==null&&u(Yo,{location:s.location,devices:S.map(e=>({id:e.deviceId,name:e.name,container:Ko(s,e.deviceId),detail:e.detail})),action:`add`,onPick:e=>O(S.filter(t=>t.deviceId===e)),...n===`multi`?{onPickAll:()=>O(S)}:{}}),a.kind===`unknown`?u(`p`,{role:`alert`,className:`text-xs text-warning`,children:m(`customize.assign.unknown`,{reason:a.reason})}):w.length===0&&S.length>0?null:u(hn,{devices:w,listState:T,value:_,onChange:e=>v(n===`single`?e.length>0?[e[e.length-1]]:[]:e),noun:`device`,emptyLabel:m(`customize.assign.none`),showAll:!0,testId:`customize-device-picker`})]}),r(Vn,{children:[u(X,{variant:`ghost`,onClick:D,children:m(`customize.picker.cancel`)}),u(X,{disabled:E.length===0,onClick:k,children:l(E.length)})]})]})})}function $o(e){if(e===null)return[];let t=pi(e);return gi(e).map(e=>{let n=q(e);return{key:n,ref:e,caps:t.filter(e=>q(e.source)===n).map(e=>e.cap)}})}function es(e,t){let n=pi(e);if(n.length===0)return!1;let{enabled:r,...i}=e,{enabled:a,...o}=Xe({camera:t,sources:n,enabled:!0});return Si(i,o)}function ts(e){return e?.enabled!==!1}function ns(e,t,n){let r=[...e===null?[]:pi(e),...n.flatMap(e=>Ue(e.ref,e.caps))];return r.length===0?null:Xe({camera:t,sources:r,enabled:ts(e)})}function rs(e,t,n){let r=pi(e).filter(e=>q(e.source)!==n);return r.length===0?null:Xe({camera:t,sources:r,enabled:ts(e)})}function is(e,t){return{...e,enabled:t}}n();function as({device:e,handle:t,availability:n,onAdvanced:i}){let{t:a}=Z(),s=Ro(),[l,d]=c(!1),[f,p]=c(null),h=io(t.state),g=Ci(h,`doorbell`),_=g===null||es(g,t.target),v=_?$o(g):[],y=Io(v.length>0),b=Lo({hostId:e.id,excludeCameras:!1,assigned:new Set(v.map(e=>e.key)),preferredCap:null,enabled:l});if(n.kind===`absent`)return null;let x=t.state.kind===`none`||t.state.kind===`present`,S=x&&!t.saving,C=n.kind===`present`&&S&&_,w=async e=>{let n=e===null?h===null?null:$r(h,`doorbell`):ni(h,t.target,e),r=await t.save(n);p(r.kind===`refused`?r.reason:null)},T=async(e,n)=>{if(g===null||h===null)return;let r=rs(g,t.target,e.key),i=r===null&&$r(h,`doorbell`)===null;await s(a(`customize.doorbell.removeWhat`,{name:n}),i)&&await w(r)},E=e=>y.kind===`known`?y.value.find(t=>q({addonId:t.addonId,stableId:t.stableId})===e.key)??null:null;return r(o,{children:[r(jo,{id:`doorbell`,icon:m,title:a(`customize.doorbell.title`),headerControl:g===null?void 0:r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground`,children:[u(an,{"aria-label":a(`customize.doorbell.active`),checked:g.enabled!==!1,disabled:!S,onChange:e=>void w(is(g,e.target.checked))}),a(`customize.doorbell.active`)]}),addLabel:a(`customize.doorbell.add`),onAdd:C?()=>d(!0):void 0,notices:r(o,{children:[u(Mo,{availability:n}),y.kind===`unknown`&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.assign.devicesUnreadable`,{reason:y.reason})}),f!==null&&u(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:f})]}),children:[v.map(e=>{let n=E(e),r=n?.name??e.key,i=Ki(e.caps,null),o=i===null?void 0:Me[i];return u(ko,{name:r,detail:n===null?null:Ji(n.integration,n.location),meta:e.caps.join(`, `),value:n!==null&&i!==null&&o!==void 0?{deviceId:n.id,cap:i,path:o}:null,problem:n===null&&y.kind===`known`?a(`customize.assign.missingKept`):void 0,onRemove:x?()=>void T(e,r):void 0,removeLabel:a(`customize.assign.removeNamed`,{name:r}),busy:t.saving},e.key)}),!_&&u(ko,{name:a(`customize.doorbell.otherFormula`),detail:null,meta:u(no,{onAdvanced:i}),value:null,removeLabel:``}),g===null&&n.kind===`present`&&x&&u(`li`,{className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:a(`customize.assign.none`)})]}),u(Qo,{open:l,title:a(`customize.doorbell.pickTitle`),selection:`multi`,candidates:b,confirmLabel:e=>a(`customize.assign.addCount`,{count:e}),onConfirm:e=>{d(!1),w(ns(g,t.target,e.map(e=>({ref:e.ref,caps:e.caps}))))},onClose:()=>d(!1)})]})}n();function os(e,t){let n=typeof e==`string`&&e.length>0,r=Io(t&&n);return i(()=>t?Wo(r,e):null,[t,r,e])}n();function ss(e){return e==null?null:e.message}function cs({device:e}){let{t}=Z(),n=s(),i=Ro(),a=Ne.includes(e.type),[l,d]=c(!1),[f,p]=c(!1),[m,h]=c(null),g=Wt({deviceId:e.id},{enabled:a}),_=Qi({status:g.status,data:g.data,error:ss(g.error)===null?null:{message:ss(g.error)??``}}),v=_.kind===`present`?_.slot.slotRef:``,y=_.kind===`present`?[...Yi(_.slot,_.value).map(e=>e.deviceId),...qi(_.slot,_.value)]:[],b=Yt(),x=Io(a&&_.kind===`present`&&(l||y.length>0)),S=os(e.location,a&&_.kind===`present`),C=ht({deviceId:e.id,slotRef:v},{enabled:(l||S!==null)&&_.kind===`present`});if(!a||_.kind===`absent`)return null;if(_.kind!==`present`)return u(jo,{id:`linked`,icon:re,title:t(`customize.linked.title`),notices:_.kind===`pending`?u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.assign.checking`)}):u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:t(`customize.assign.unknown`,{reason:_.reason})}),children:null});let w=_.value,T=new Map(x.kind===`known`?x.value.map(e=>[e.id,e]):[]),E=w.trackedDeviceIds!==void 0,D=(e,t)=>{let n=T.get(e.deviceId);return{...e,name:e.name??n?.name??null,type:n?.type??null,detail:n===void 0?null:Ji(n.integration,n.location),orphan:t}},O=[...Yi(_.slot,w).map(e=>D(e,!1)),...qi(_.slot,w).map(e=>D({deviceId:e,name:null,health:`ok`,implied:!1,tracked:!0},!0))],k=new Set(y),A=x.kind===`unknown`?x:C.status===`error`?{kind:`unknown`,reason:ss(C.error)??`the request failed`}:x.kind===`pending`||C.status===`pending`||C.data===void 0?{kind:`pending`}:{kind:`known`,value:ea(C.data.candidates,T,k)},j=async r=>{if(f){h(t(`customize.saveInFlight`));return}p(!0),h(null);try{await b.mutateAsync({deviceId:e.id,slotRef:_.slot.slotRef,value:r}),await g.refetch(),await n.invalidateQueries({queryKey:[[`deviceManager`]]})}catch(e){h(e instanceof Error?e.message:String(e))}finally{p(!1)}},M=async e=>{await i(t(`customize.linked.removeWhat`,{name:e.name??`#${e.deviceId}`}),!1)&&await j($i(w,e.deviceId))},ee=[{key:`device`,header:t(`customize.linked.device`),cell:e=>r(`div`,{className:`flex flex-col min-w-0`,children:[u(`span`,{className:`truncate text-xs text-foreground`,children:e.name??`#${e.deviceId}`}),e.detail!==null&&u(`span`,{className:`truncate text-[11px] text-foreground-subtle`,children:e.detail}),e.orphan&&u(`span`,{className:`text-[11px] text-foreground-subtle`,children:t(`customize.linked.notLinked`)}),e.health!==`ok`&&u(`span`,{role:`alert`,className:`text-[11px] text-warning`,children:t(`customize.linked.health.${e.health}`)})]})},{key:`type`,header:t(`customize.linked.type`),headerClassName:`hidden sm:table-cell`,cellClassName:`hidden sm:table-cell text-xs text-foreground-subtle`,cell:e=>e.type===null?`—`:yn(e.type).label},{key:`controls`,header:t(`customize.linked.controls`),headerClassName:`hidden md:table-cell`,cellClassName:`hidden md:table-cell text-xs text-foreground-subtle`,cell:e=>e.orphan?`—`:t(`customize.linked.yes`)},...E?[{key:`tracked`,header:t(`customize.linked.tracked`),cellClassName:`text-right`,headerClassName:`text-right`,cell:e=>u(Mn,{checked:e.tracked,disabled:f,"aria-label":t(`customize.linked.trackFor`,{name:e.name??e.deviceId}),onCheckedChange:t=>void j(Xi(w,e.deviceId,t))})}]:[],{key:`remove`,header:``,cellClassName:`text-right w-10`,cell:e=>e.implied||e.orphan?null:u(Ft,{icon:ae,variant:`ghost`,size:`sm`,"aria-label":t(`customize.assign.removeNamed`,{name:e.name??e.deviceId}),disabled:f,onClick:t=>{t.stopPropagation(),M(e)}})}];return r(o,{children:[u(jo,{id:`linked`,icon:re,title:t(`customize.linked.title`),addLabel:t(`customize.linked.add`),onAdd:f?void 0:()=>d(!0),...S===null?{}:{suggestion:{count:qo(A,S,e=>e.deviceId),location:S.location,onOpen:()=>d(!0)}},notices:r(o,{children:[x.kind===`unknown`&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:t(`customize.assign.devicesUnreadable`,{reason:x.reason})}),m!==null&&u(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:m})]}),children:r(`li`,{className:`list-none px-3 py-2 sm:px-4`,children:[O.length===0?u(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`customize.assign.none`)}):u(Sn,{mode:`generic`,items:O,getKey:e=>String(e.deviceId),getSearchText:e=>[e.name??``,e.detail??``,e.type??``,String(e.deviceId)].join(` `),getFilterType:e=>e.type===null?null:yn(e.type).label,columns:ee,searchPlaceholder:t(`customize.assign.search`),emptyLabel:t(`customize.assign.none`)}),O.some(e=>!e.orphan)&&u(`p`,{className:`mt-2 text-[10px] text-foreground-subtle`,children:t(`customize.linked.controlsAlways`)}),E&&u(`p`,{className:`mt-0.5 text-[10px] text-foreground-subtle`,children:t(`customize.linked.trackedHint`)})]})}),u(Qo,{open:l,title:t(`customize.linked.pickTitle`),selection:`multi`,candidates:A,room:S,confirmLabel:e=>t(`customize.assign.addCount`,{count:e}),onConfirm:e=>{d(!1),j(Ui(w,e.map(e=>e.deviceId)))},onClose:()=>d(!1)})]})}function ls(e){return e===null||e.state===`unreadable`?null:e.state===`configured`?e.sensors:[]}function us(e){return{addonId:e.addonId,stableId:e.stableId,mode:e.mode}}function ds(e){return e.length===0?null:{sensors:[...e]}}function fs(e,t){let n=new Set(e.map(ke));return ds([...e.map(us),...t.filter(e=>!n.has(ke(e))).map(e=>({...e,mode:je}))])}function ps(e,t,n){return ds(e.map(e=>ke(e)===t?{...us(e),mode:n}:us(e)))}function ms(e,t){return ds(e.filter(e=>ke(e)!==t).map(us))}function hs(e){return e?.state===`configured`&&e.cameraMotion!==void 0}function gs(e){return e===null||e.state===`unreadable`?null:e.state===`configured`?e.cameraMotion??`always`:`always`}function _s(e){return e===null||e.state===`unreadable`?!1:e.state===`not-configured`||hs(e)}function vs(e){return e?.state===`configured`&&(e.notForwarded!==void 0||e.notEnforced!==void 0)}function ys(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}}n();var bs=5e3;function xs(e){return e.state===`missing`||e.state===`unreadable`?e.stableId:e.name}function Ss({device:e,availability:n,sensors:i}){let{t:a}=Z(),s=Ro(),l=It(),[f,p]=c(!1),[m,h]=c(null),g=t(!1),[_,v]=c(!1),[y,b]=c(!1),x=i.status,S=t(i.refetch);S.current=i.refetch,d(()=>{let e=setInterval(()=>{g.current||S.current()},bs);return()=>clearInterval(e)},[]);let C=ls(x);d(()=>{x!==null&&b(!1)},[x]);let w=i.presence===`present`&&_s(x)&&!y?C:null,T=Io(C!==null&&C.length>0),D=Lo({hostId:e.id,excludeCameras:!0,assigned:new Set((C??[]).map(ke)),preferredCap:`motion`,enabled:f});if(n.kind===`absent`)return null;let O=hs(x),k=vs(x)?`passes`:gs(x),A=ys(i.presence,x,y),j=A.kind===`none`?null:A.kind===`unknown`?{text:`?`,tone:`warning`,title:a(`customize.motion.cameraLevelUnknown`)}:{text:a(A.detected?`customize.assign.value.active`:`customize.assign.value.inactive`),tone:A.detected?`active`:`muted`,title:a(`customize.motion.cameraLevelOwn`,{at:new Date(A.atMs).toLocaleTimeString()})},M=_||l.isPending,ee=async t=>{if(g.current){h(a(`customize.saveInFlight`));return}g.current=!0,v(!0);try{await l.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)}},N=async e=>{w!==null&&await s(a(`customize.motion.removeWhat`,{name:xs(e)}),!1)&&await ee(ms(w,ke(e)))},P=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:Ji(t.integration,t.location)};return r(o,{children:[r(jo,{id:`motion`,icon:E,title:a(`customize.motion.title`),addLabel:a(`customize.motion.add`),onAdd:w!==null&&n.kind===`present`?()=>p(!0):void 0,addDisabled:M,notices:r(o,{children:[u(Mo,{availability:n}),i.presence===`pending`&&n.kind!==`pending`&&u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:a(`customize.motion.reading`)}),x?.state===`unreadable`&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.motion.unreadable`,{reason:x.reason})}),x?.state===`configured`&&!_s(x)&&u(`p`,{role:`alert`,className:`text-xs text-warning`,children:a(`customize.motion.olderOrchestrator`)}),y&&u(`p`,{role:`alert`,className:`text-xs text-warning`,children:a(`customize.motion.refetchFailed`)}),x?.state===`configured`&&x.notForwarded!==void 0&&u(`p`,{role:`alert`,className:`text-xs text-warning`,children:a(`customize.motion.notForwarded.${x.notForwarded}`)}),x?.state===`configured`&&x.notEnforced!==void 0&&u(`p`,{role:`alert`,className:`text-xs text-warning`,children:a(`customize.motion.notEnforced`)}),T.kind===`unknown`&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.assign.devicesUnreadable`,{reason:T.reason})}),m!==null&&u(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:m})]}),children:[u(ko,{name:a(`customize.motion.camera`),detail:null,meta:k===null?a(`customize.assign.native`):`${a(`customize.motion.cameraState.${k}`)} · ${a(`customize.assign.native`)}`,value:null,shown:j,removeLabel:``}),(C??[]).map(e=>{let t=ke(e),n=xs(e),r=e.state===`ready`?Ki(e.caps,`motion`):null,i=r===null?void 0:Me[r];return u(ko,{name:n,detail:P(e),meta:O&&w!==null?u(Ct,{"aria-label":a(`customize.motion.modeFor`,{name:n}),value:e.mode,disabled:M,options:Ae.options.map(e=>({value:e,label:a(`customize.motion.mode.${e}`)})),onChange:e=>{let n=Ae.safeParse(e.target.value);n.success&&w!==null&&ee(ps(w,t,n.data))}}):a(`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?a(`customize.motion.state.${e.state}`):`${a(`customize.motion.state.${e.state}`)}: ${e.reason}`,onRemove:w===null?void 0:()=>void N(e),removeLabel:a(`customize.assign.removeNamed`,{name:n}),busy:M},t)})]}),u(Qo,{open:f,title:a(`customize.motion.pickTitle`),selection:`multi`,candidates:D,filters:Wi,confirmLabel:e=>a(`customize.assign.addCount`,{count:e}),onConfirm:e=>{if(p(!1),w===null)return;let t=fs(w,e.map(e=>e.ref));if(t!==null&&t.sensors.length>8){h(a(`customize.motion.tooMany`,{max:8}));return}ee(t)},onClose:()=>p(!1)})]})}var Cs={"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`}},ws=new Set([J.Camera]);function Ts(e){return e.unitField===null?[e.fieldPath]:[e.fieldPath,e.unitField]}function Es(e,t){if(ws.has(e))return{kind:`absent`};let n=null;for(let[e,r]of Object.entries(Cs))if(t.has(e)){n={cap:e,fieldPath:r.fieldPath,unitField:r.unitField};break}let r=null;for(let e of Re)if(t.has(e)){let t=Me[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 Ds(e){return $e(e.from,e.to)?Ze(e):null}function Os(e){return qe(e)}var ks=/^convert\(v,\s*"[^"]*",\s*"[^"]*"\)$/;function As(e){return e!==void 0&&ks.test(e.expr)}function js(e){return e===void 0||e.expr===`!v`||ks.test(e.expr)?!1:e.bindings.v!==void 0}function Ms(e){let t=e.expr.trim();if(t===``)return{kind:`refused`,reason:`expression is empty`};let n={kind:`expression`,expr:t,bindings:{v:{kind:`from`,source:e.self,cap:e.cap,fieldPath:e.fieldPath}}},r=We({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 Ns(e,t,n){if(e===null)return null;let r=Ci(e,n.cap);if(r===null)return e;let i=new Set(Ts(n)),a=Object.fromEntries(Object.entries(r.fields).filter(([e])=>!i.has(e)));return Object.keys(a).length===0?$r(e,n.cap):ni(e,t,{kind:`fields`,cap:n.cap,...r.enabled===void 0?{}:{enabled:r.enabled},fields:a,...r.items===void 0?{}:{items:r.items}})}n();function Ps(e){if(typeof e!=`object`||!e)return;let t=Reflect.get(e,`unit`);return typeof t==`string`?t:void 0}function Fs(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 Is(e,t){let n=Ci(e,t.cap);if(n===null)return;let r=n.fields[t.fieldPath];return r!==void 0&&r.kind===`expression`?r:void 0}function Ls(e,t){let n=Is(e,t);return n===void 0||!As(n)?null:/^convert\(v,\s*"[^"]*",\s*"([^"]*)"\)$/.exec(n.expr)?.[1]??null}function Rs(e,t){let n=Is(e,t);return n===void 0||!js(n)?null:n.expr}function zs(e,t,n){let r=Ci(e,t);if(r===null)return!1;let i=r.fields[n];return i!==void 0&&i.kind===`expression`&&i.expr===`!v`}function Bs(e){return typeof e==`number`||typeof e==`boolean`||typeof e==`string`?String(e):e===null?`null`:JSON.stringify(e)}function Vs({device:e,target:t,handle:n,facts:i}){let{t:a}=Z(),o=W(),[s,l]=c(null),[d,f]=c(``),[m,h]=c(null),g=i.nativeCaps.kind===`known`?i.nativeCaps.value:null,_=g===null?null:Es(e.type,g),v=_?.kind===`present`?_.convert?.cap??``:``,y=ur(o.trpcClient,e.id,v);if(i.nativeCaps.kind===`pending`)return u(`section`,{className:`${w} ${p}`,children:u(Mo,{availability:{kind:`pending`}})});if(i.nativeCaps.kind===`unknown`)return u(`section`,{className:`${w} ${p}`,children:u(Mo,{availability:{kind:`unknown`,reason:i.nativeCaps.reason}})});if(_===null||_.kind===`absent`)return null;let b=io(n.state),x=_.convert,S=_.invert,C=x===null?void 0:Ps(y),T=C===void 0?void 0:Ge(C)??C,E=T===void 0?void 0:Be(T),D=x===null?null:Ls(b,x),O=x===null?null:Rs(b,x),k=m??O??``,A=S===null?!1:zs(b,S.cap,S.fieldPath),j=n.state.kind===`none`||n.state.kind===`present`,M=x===null?0:Fs(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:mi(ee,new Map([[Oe(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||T===void 0||d===``)return;let e=Ds({self:t,cap:x.cap,fieldPath:x.fieldPath,from:T,to:d,unitField:x.unitField});if(e===null){l(a(`customize.numericTransforms.convertRefused`));return}h(null),await P(ni(b,t,e))},I=async()=>{x!==null&&(await P(Ns(b,t,x)),f(``))},L=async()=>{if(x===null)return;let e=Ms({self:t,cap:x.cap,fieldPath:x.fieldPath,expr:k,probe:M});if(e.kind===`refused`){l(e.reason);return}f(``),await P(ni(b,t,e.feature))},te=async()=>{x!==null&&(await P(Ns(b,t,x)),h(``))},R=async()=>{if(S===null)return;let e=Os({self:t,cap:S.cap});if(e===null){l(a(`customize.numericTransforms.invertRefused`));return}await P(ni(b,t,e))},ne=async()=>{S===null||b===null||await P($r(b,S.cap))};return u(Ao,{id:`numeric-transforms`,icon:_e,title:a(`customize.numericTransforms.title`),testId:`numeric-transforms-card`,children:r(`div`,{className:`${p} flex flex-col gap-3`,children:[u(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`customize.numericTransforms.blurb`)}),s!==null&&u(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:s}),x!==null&&r(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-convert`,children:[u(`label`,{className:`text-[11px] font-medium text-foreground`,children:a(`customize.numericTransforms.publishUnit`)}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:T===void 0?a(`customize.numericTransforms.fromUnknown`):a(`customize.numericTransforms.fromUnit`,{unit:T})}),u(`div`,{className:`w-full sm:max-w-xs`,children:u(Un,{dimension:E,value:d===``?D??``:d,onChange:e=>{f(e),e!==``&&h(``)},disabled:!j||n.saving||T===void 0,"aria-label":a(`customize.numericTransforms.toUnit`),inheritLabel:a(`customize.numericTransforms.pickUnit`),emptyReason:a(`customize.numericTransforms.fromUnknown`)})}),r(`div`,{className:`flex flex-wrap gap-2`,children:[u(X,{size:`sm`,disabled:!j||n.saving||T===void 0||d===``||d===T,onClick:()=>void F(),children:a(`customize.numericTransforms.applyConvert`)}),D!==null&&u(X,{size:`sm`,variant:`outline`,disabled:!j||n.saving,onClick:()=>void I(),children:a(`customize.numericTransforms.clearConvert`)})]})]}),x!==null&&r(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-script`,children:[u(_i,{label:a(`customize.numericTransforms.script`),value:k,bindings:[`v`],onChange:e=>{h(e),e.trim()!==``&&f(``)}}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`customize.numericTransforms.scriptBlurb`)}),N!==null&&u(`p`,{role:`status`,className:`text-[11px] font-mono text-foreground`,"data-testid":`numeric-script-preview`,children:N.kind===`value`?a(`customize.numericTransforms.preview`,{source:Bs(M),result:Bs(N.value)}):N.kind===`waiting`?a(`customize.numericTransforms.previewWaiting`):N.kind===`unavailable`?a(`customize.numericTransforms.previewError`,{reason:N.reason}):a(`customize.numericTransforms.previewRuntimeOnly`)}),r(`div`,{className:`flex flex-wrap gap-2`,children:[u(X,{size:`sm`,disabled:!j||n.saving||k.trim()===``,onClick:()=>void L(),children:a(`customize.numericTransforms.applyScript`)}),O!==null&&u(X,{size:`sm`,variant:`outline`,disabled:!j||n.saving,onClick:()=>void te(),children:a(`customize.numericTransforms.clearScript`)})]})]}),S!==null&&r(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-invert`,children:[u(`label`,{className:`text-[11px] font-medium text-foreground`,children:a(`customize.numericTransforms.invert`)}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`customize.numericTransforms.invertBlurb`)}),u(`div`,{className:`flex flex-wrap gap-2`,children:A?u(X,{size:`sm`,variant:`outline`,disabled:!j||n.saving,onClick:()=>void ne(),children:a(`customize.numericTransforms.clearInvert`)}):u(X,{size:`sm`,disabled:!j||n.saving,onClick:()=>void R(),children:a(`customize.numericTransforms.applyInvert`)})})]})]})})}n();function Hs(e){return e instanceof Error?e.message:String(e)}function Us(e){let n=it({addonId:e.addonId,stableId:e.stableId}),r=Vt(),i=vt(),a=dt(),o=ro({status:n.status,data:n.data,error:n.error===null||n.error===void 0?null:{message:n.error.message}}),{t:s}=Z(),l=t(!1),[u,d]=c(!1),f=async e=>{let t=ai(o,e);try{switch(t.kind){case`refused`:return{kind:`refused`,reason:t.reason};case`noop`:return{kind:`saved`};case`create`:await r.mutateAsync({block:t.input});break;case`update`:await i.mutateAsync({blockId:t.blockId,expectedUpdatedAt:t.expectedUpdatedAt,block:{composition:t.composition}});break;case`delete`:await a.mutateAsync({blockId:t.blockId});break}return await n.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:Hs(e)}}};return{target:e,state:o,saving:u||r.isPending||i.isPending||a.isPending,save:async e=>{if(l.current)return{kind:`refused`,reason:s(`customize.saveInFlight`)};l.current=!0,d(!0);try{return await f(e)}finally{l.current=!1,d(!1)}}}}var Ws=`pipeline-orchestrator`;function Gs(e){return e.status===`pending`?`pending`:e.status===`error`?`unknown`:e.data===void 0?`pending`:e.data.cameraSensors===void 0?`absent`:`present`}function Ks(e,t){return e===`absent`?`absent`:Gs(t)}async function qs(e){try{return(await e()).isError?`failed`:`answered`}catch{return`failed`}}function Js(e,t){let n=Gt(Ws),r=Hn({deviceId:e},{enabled:t&&n!==`absent`}),i=()=>qs(r.refetch);return t?{presence:Ks(n,{status:r.status,data:r.data}),status:r.data?.cameraSensors??null,refetch:i}:{presence:`absent`,status:null,refetch:i}}function Ys(e,t){let n=In({deviceType:e.type}),r=dr({deviceId:e.id}),i=ir({deviceId:e.id}),a=No(n,e=>new Set(e.caps.map(e=>e.cap))),o=No(r,e=>Za(e.entries)),s=No(i,e=>e);return{deviceType:e.type,composable:a,nativeCaps:o,wireable:s,composed:new Set((t?.features??[]).map(e=>e.cap))}}var Xs={kind:`unknown`,reason:`the composer reports no value for this field`};function Zs(e,t){let n=q(e);return t.get(n)??n}function Qs(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=gi(e).map(e=>Zs(e,n.sourceNames)).join(` + `),a=i.find(e=>e.field===`lastPressedAt`);return[{key:`doorbell`,label:`doorbell`,origin:{kind:r,from:t},value:a?.value??Xs}]}return e.cap===`consumables`?ci(e).map(e=>{let t=t=>et(tt,e.key,t),a=i.find(e=>e.field===t(`level`)||e.field===t(`remaining.value`)),o=e.source===null?``:Zs(e.source.source,n.sourceNames);return{key:`consumables.${e.key}`,label:`consumables · ${e.label}`,origin:{kind:r,from:o},value:a?.value??Xs}}):i.map(e=>({key:e.key,label:`${e.cap}.${e.field}`,origin:{kind:r,from:e.from},value:e.value}))}function $s(e){let t=di({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`?Qs(n,t,e):[])}function ec(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 tc=`${j} 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)]`,nc=`font-mono text-[11px] text-foreground break-words`,rc=`text-[11px] text-foreground-subtle break-words`,ic=`text-[11px] break-words sm:text-right`;function ac({device:e,composition:t,state:n,nativeCaps:i,cameraSensors:a}){let{t:o}=Z(),s=t!==null&&n!==null,c=Io(s),l=new Map(c.kind===`known`?c.value.map(e=>[q({addonId:e.addonId,stableId:e.stableId}),e.name]):[]),d=s&&i.kind===`known`?$s({composition:t,nativeCaps:i.value,state:n,sourceNames:l}):[],f=s&&i.kind===`known`&&d.length===0&&t.features.length>0,p=ec(a,{camera:o(`customize.changes.motion.camera`),sensor:(e,t)=>o(`customize.changes.motion.${t}`,{name:e})}),m=s&&i.kind!==`known`;return d.length===0&&p===null&&!m&&!f?null:r(Ao,{id:`changes`,icon:G,title:o(`customize.changes.title`),children:[m&&u(`p`,{role:i.kind===`unknown`?`alert`:`status`,className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:i.kind===`unknown`?o(`customize.changes.unknown`,{reason:i.reason}):o(`customize.changes.reading`)}),f&&u(`p`,{className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:o(`customize.changes.noRows`)}),r(`ul`,{className:`divide-y divide-border`,children:[d.map(e=>r(`li`,{className:tc,children:[u(`span`,{className:nc,children:e.label}),u(`span`,{className:rc,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:``})}),u(`span`,{className:ic,children:u(oc,{value:e.value})})]},e.key)),p!==null&&r(`li`,{className:tc,children:[u(`span`,{className:nc,children:`motion`}),u(`span`,{className:rc,children:p}),u(`span`,{className:ic,children:u(Do,{target:{deviceId:e.id,cap:`motion`,path:`detected`}})})]})]})]})}function oc({value:e}){let{t}=Z();switch(e.kind){case`value`:return r(`span`,{children:[hi(e.value,!0),e.staleReason!==null&&r(`span`,{className:`text-warning`,children:[` `,`·`,` `,t(`customize.changes.value.stale`,{reason:e.staleReason})]})]});case`unavailable`:return u(`span`,{className:`text-warning`,children:t(`customize.changes.value.unavailable`,{reason:e.reason})});case`unknown`:return u(`span`,{className:`text-foreground-subtle`,children:t(`customize.changes.value.unknown`,{reason:e.reason})});case`off`:return u(`span`,{className:`text-foreground-subtle`,children:t(`customize.status.off`)})}}n();function sc({deviceId:e,activeSubTab:t,onSubTabChange:n}){let{t:r}=Z(),i=vr({deviceId:e}),a=i.data;return a==null?i.status===`error`?u(Et,{title:r(`customize.deviceUnreadable`),message:i.error?.message??``,onRetry:()=>void i.refetch()}):a===null?u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.noSuchDevice`,{deviceId:e})}):u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.loadingDevice`)}):a.addonId===`composer`?u(cc,{device:a}):u(lc,{device:a,target:{addonId:a.addonId,stableId:a.stableId},activeSubTab:t,onSubTabChange:n})}function cc({device:e}){let{t}=Z(),n=e.stableId.startsWith(`composed-`)?e.stableId.slice(Ie.length):null;return r(`section`,{className:`${w} ${p} flex flex-col gap-2`,children:[u(`p`,{className:`text-xs text-foreground`,children:t(`customize.composed.body`)}),n!==null&&u(Pr,{className:`text-[11px] text-primary hover:underline`,to:Zr(n),children:t(`customize.composed.edit`)})]})}function lc({device:e,target:t,activeSubTab:n,onSubTabChange:i}){let a=Us(t),o=Gt(`composer`),{t:s}=Z(),c=Js(e.id,e.type===J.Camera),l=Ys(e,io(a.state)),d={deviceType:e.type,composable:l.composable,nativeCaps:l.nativeCaps,cameraSensors:c.presence},f=()=>i(Kr),p=a.state.kind===`none`||a.state.kind===`present`;return n===`advanced`?r(`div`,{className:`flex flex-col gap-3`,children:[u(dc,{state:a.state}),p&&u(uc,{device:e,target:t,handle:a,facts:l,onDone:()=>i(`main`)})]}):r(`div`,{className:`flex flex-col gap-3`,children:[u(mo,{device:e}),o===`absent`&&u(`p`,{role:`alert`,className:`text-xs text-warning`,children:s(`customize.composerAbsent`)}),a.state.kind!==`none`&&u(dc,{state:a.state}),u(as,{device:e,handle:a,availability:to(`doorbell`,d),onAdvanced:f}),u(Ss,{device:e,handle:a,availability:to(`motion`,d),sensors:c}),u(Bo,{device:e,handle:a,availability:to(`battery`,d),onAdvanced:f}),u(Uo,{device:e,handle:a,availability:to(`consumables`,d),onAdvanced:f}),u(Vs,{device:e,target:t,handle:a,facts:l}),u(cs,{device:e}),u(ac,{device:e,composition:io(a.state),state:a.state.kind===`present`?a.state.view.state:null,nativeCaps:l.nativeCaps,cameraSensors:c.status}),r(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[p?u(no,{onAdvanced:f}):u(`span`,{}),u(fc,{handle:a})]})]})}function uc({device:e,target:t,handle:n,facts:r,onDone:i}){let a=n.state.kind===`present`?n.state:null;return u(yi,{initial:a===null?ei(t):ti(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 dc({state:e}){let{t}=Z();switch(e.kind){case`pending`:return u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.status.pending`)});case`unknown`:return u(Et,{title:t(`customize.status.unknownTitle`),message:e.reason});case`not-loaded`:return u(`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 r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[u(on,{variant:n.status===`running`?`success`:n.status===`failed`?`danger`:`warning`,children:t(`customize.blockStatus.${n.status}`)}),!n.enabled&&u(on,{variant:`default`,children:t(`customize.status.off`)}),n.lastError!==void 0&&u(`span`,{className:`text-[11px] text-foreground-muted break-words`,children:n.lastError}),e.view.state.kind===`unreachable`&&u(`span`,{className:`text-[11px] text-warning`,children:t(`customize.status.composerUnreachable`,{reason:e.view.state.error})})]})}}}function fc({handle:e}){let{t}=Z(),n=Qt(),[i,a]=c(null);if(e.state.kind!==`present`)return null;let o=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);a(r.kind===`refused`?r.reason:null)};return r(`div`,{className:`flex flex-col items-start gap-1`,children:[u(X,{variant:`danger`,size:`sm`,disabled:e.saving,onClick:()=>void o(),children:t(`customize.remove.button`)}),i!==null&&u(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:i})]})}var pc=`overview`;function mc(e,t){return e.some(e=>e.id===t)?t:pc}function hc({deviceId:e}){let{t}=Z(),n=s(),i=Number.isFinite(e),{data:a}=vr({deviceId:e},{enabled:i}),o=typeof a?.type==`string`?a.type:`camera`;sr([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:c,isLoading:l,isError:d,error:f}=dr({deviceId:e},{enabled:i}),{data:p}=On({deviceType:o},{enabled:!!o}),m=Dr({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(l)return u(`div`,{className:`p-4`,children:u(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(d)return r(`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 c?.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 r(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[u(Se,{className:`h-8 w-8 opacity-40`}),u(`p`,{className:`text-xs`,children:t(`device.bindingsTab.noCapabilityProvidersApplicableTo`,`No capability providers applicable to this device yet.`)}),u(`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=>u(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:t(`device.bindingsTab.kind`,`Kind`),render:e=>u(gc,{kind:e.kind})},{key:`provider`,header:t(`device.bindingsTab.activeProvider`,`Active Provider`),render:e=>u(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||u(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:t(`device.bindingsTab.node`,`Node`),render:e=>e.providerNodeId?u(_c,{nodeId:e.providerNodeId}):u(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:t(`device.bindingsTab.native`,`Native`),render:e=>u(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||u(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:t(`device.bindingsTab.wrapper`,`Wrapper`),render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return u(vc,{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 r(`div`,{className:`flex flex-col gap-3 p-1`,children:[r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-foreground`,children:v}),` of `,_.length,` capabilit`,_.length===1?`y`:`ies`,` bound — rows marked `,u(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),u(gt,{columns:y,rows:_,rowKey:e=>e.capName,minWidthPx:720})]})}function gc({kind:e}){return e===`native`?r(`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:[u(de,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?r(`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:[u(we,{className:`h-3 w-3`}),`wrapped`]}):e===`linked`?r(`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:[u(re,{className:`h-3 w-3`}),`linked`]}):r(`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:[u(se,{className:`h-3 w-3`}),`unbound`]})}function _c({nodeId:e}){return u(`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 vc({wrappers:e,activeWrapperId:t,disabled:n,onPick:i}){let{t:a}=Z();return e.length===0?u(`span`,{className:`text-[10px] opacity-40`,children:a(`device.bindingsTab.noneAvailable`,`none available`)}):u(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let o=e===t;return r(`button`,{disabled:n,onClick:()=>i(e),title:o?a(`device.bindingsTab.clickToDeactivateRevertTo`,`Click to deactivate (revert to native)`):a(`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:[u(o?z:fe,{className:`h-3 w-3`}),e]},e)})})}function yc({deviceId:e,activeSubTab:t,onSubTabChange:n,deviceType:i,isAdmin:a}){return r(`div`,{className:`flex flex-col gap-3`,children:[Ar(i,a)&&u(Mt,{deviceId:e,readOnly:!0}),u(Rr,{deviceId:e,activeSubTab:t,onSubTabChange:n})]})}n();var bc=[[`pipelineOrchestrator`,`getCameraDetectionSource`]];function xc(t){let n=s(),r=ut({deviceId:t},{refetchOnMount:`always`}),i=$t(),[a,o]=c(null),[l,u]=c(null),d=e(async e=>{u(null),o(e);try{await i.mutateAsync({deviceId:t,source:e}),await n.invalidateQueries({queryKey:bc})}catch(e){u(e instanceof Error?e.message:`Could not change the root detector`),await n.invalidateQueries({queryKey:bc})}finally{o(null)}},[t,i,n]),f=r.data??null;return{view:f,isLoading:r.isLoading,source:a??f?.source??null,saving:a!==null,error:l,pick:d}}var Sc=`object-detection`;function Cc(e){return[e.addonId,...e.children.flatMap(Cc)]}function wc(e,t){if(e===`pipeline`)return new Set;let n=Tc(t,Sc);return n===void 0?new Set:new Set(e===`onboard`?[n.addonId]:Cc(n))}function Tc(e,t){for(let n of e){if(n.addonId===t)return n;let e=Tc(n.children,t);if(e!==void 0)return e}}function Ec(e,t){return e===`onboard`?`Camera AI`:t===`object-detection`?`No root`:`Idle`}function Dc(e){switch(e){case`pipeline`:return`This node detects: the root step runs on decoded frames and every step below it applies.`;case`onboard`:return`The camera detects: its own boxes replace the root step, so the accelerator is not asked. The steps below it still run on crops from this node's frames.`;case`none`:return`No root detector: nothing is detected on this camera, so every video step below the root is idle.`}}function Oc(e){switch(e){case`boxed`:return``;case`while-streaming`:return`Its boxes ride the stream that is already open, so they exist only while the camera is awake; between wake-ups it reports nothing.`;case`flag-only`:return`Its onboard AI reports a class with no bounding box, so it cannot be the root detector.`;case`unknown`:return`This camera has not said whether its detections carry a bounding box; without one it cannot be the root detector.`}}function kc(e,t){return e===`onboard`?`Not running here: this camera's own detector is the root, so this node's root step is never asked. These settings apply again if you switch the root detector back to this node.`:t===`object-detection`?`Not running here: this camera has no root detector.`:`Idle: this camera has no root detector, so there is nothing for this step to work on.`}function Ac({source:e,geometry:t,saving:n,error:i,onPick:a}){let{t:o}=Z(),s=t===`flag-only`,c=Oc(t);return r(`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:[r(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1.5`,children:[u(`h3`,{className:ee,children:o(`device.detectionSourceControl.rootDetector`,`Root detector`)}),u(zn,{label:o(`device.detectionSourceControl.rootDetector`,`Root detector`),value:e,onChange:t=>{!n&&t!==e&&a(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&&u(`span`,{className:`text-[10px] text-foreground-subtle`,children:o(`device.detectionSourceControl.saving`,`Saving…`)})]}),r(`p`,{className:he,children:[Dc(e),` A camera runs one root detector at a time.`]}),c!==``&&u(`p`,{className:`text-[10px] text-foreground-subtle`,children:c}),i!==null&&u(`p`,{role:`alert`,className:`text-[11px] text-danger`,children:i})]})}n();var jc=new Set([`package-detection`]);function Mc(e){return e?.settings!==void 0&&Object.keys(e.settings).length>0?`accelerator`:`camera`}function Nc(e){return e===`camera`?`this camera`:e===`node`?`node pin`:`hardware default`}function Pc(e){let{stored:t,draft:n,below:r,boundKeys:i}=e,a=n?.modelId===void 0?t?.modelId:n.modelId??void 0,o=Qe(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 Fc(e,t){return(e?.modelId??null)===(t?.modelId??null)&&Ke(e?.settings??{},t?.settings??{})}function Ic({deviceId:e}){let{t}=Z(),n=s(),l=W().trpcClient,d=Nt({deviceId:e},{refetchOnMount:`always`}),f=Rn({deviceId:e},{refetchOnMount:`always`}),p=Kt(void 0,{refetchOnMount:`always`}),m=Te(Yn({addonId:`pipeline-orchestrator`}).data??null);sr([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let{nodes:h}=En(),g=i(()=>{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=a({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=a({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=()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]})},x=hr({onSuccess:b}),S=nt(),C=bn(),[w,T]=c(null),[E,D]=c(null),[O,k]=c(null),[A,j]=c(!1),[M,N]=c(null),P=v.data??{},F=y.data??{},I=f.data??{},L=d.data??null,te=g.map(e=>P[e.id]).find(e=>e!==void 0)??null,R=i(()=>te?Rt(te):[],[te]),ne=i(()=>Mi(R),[R]),z=xc(e),B=i(()=>z.source===null?new Set:wc(z.source,R),[z.source,R]),[V,re]=c(!1),ie=i(()=>Fi(g,F,V),[g,F,V]),ae=i(()=>Fi(g,F,!0),[g,F]),oe=i(()=>Fi(g,F).length,[g,F]),H=(e,t)=>Ei(P[e.nodeId],t),U=(e,t)=>I[e.nodeId]?.[e.deviceKey]?.[t],se=(e,t)=>Bi(F[e.nodeId]??[],e.deviceKey,t)??{},ce=e=>{if(jc.has(e))return{kind:`zone-driven`};let t=Ei(te,e)?.enabledByDefault??!0,n=L?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},le=(e,t,n)=>{let r=n?.stepId===t?n:null;return{node:se(e,t),camera:r?.camera??L?.stepSettings?.[t],accelerator:r?.perAccelerator[e.id]?.settings??U(e,t)?.settings}},G=(e,t,n)=>{let r=n?.stepId===t?n.perAccelerator[e.id]?.modelId:void 0;return r===void 0?U(e,t)?.modelId:r??void 0},ue=(e,t)=>{if(B.has(e))return{kind:`disabled`};let n=H(t,e),r=ce(e),i=Pi(e),a=Di(P[t.nodeId],t,U(t,`object-detection`)?.modelId),o=le(t,e,null),s=Je(o.node,o.camera,o.accelerator);return Li({addon:n,acc:t,gatedOn:r.kind===`gate`?r.effectiveOn:!0,model:n?Ni(n,t,{nodePin:t.device.steps?.[e]?.modelId,cameraPin:U(t,e)?.modelId}):{modelId:void 0,source:`default`},...Ai(e,s,a)&&a?{rootName:a.name}:{},...i?{clusterModelId:m[e]??i.defaultModelId}:{}})},de=ne.map(({node:e})=>({addonId:e.addonId,name:e.addonName,fieldLabels:Ii(Ei(te,e.addonId))}));return p.isLoading||g.length>0&&(v.isLoading||y.isLoading)?u(`div`,{className:`animate-pulse p-4 text-xs text-foreground-subtle`,children:t(`device.cameraStepInspector.loadingPipeline`,`Loading pipeline…`)}):g.length===0?u(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:t(`device.cameraStepInspector.noPipelineNodeIsOnline`,`No pipeline node is online.`)}):te===null?u(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:t(`device.cameraStepInspector.catalogUnavailable`,`Catalog unavailable.`)}):r(`div`,{className:`space-y-2`,children:[z.view?.onboard.available===!0&&z.source!==null&&u(Ac,{source:z.source,geometry:z.view.onboard.geometry,saving:z.saving,error:z.error,onPick:e=>void z.pick(e)}),u(Ti,{tree:R,searchRows:de,accelerators:ie,cellState:ue,stepBadge:e=>B.has(e)&&z.source!==null?u(on,{variant:`warning`,title:kc(z.source,e),children:Ec(z.source,e)}):u(rt,{gate:ce(e)}),disabledCount:zi(Object.fromEntries(g.map(e=>[e.id,F[e.id]??[]]))),showDisabled:V,onShowDisabledChange:re,dirty:w!==null,onDiscard:()=>T(null),summary:r(`span`,{className:he,children:[`This camera is balanced across `,oe,` accelerator`,oe===1?``:`s`,` at every session start · ovr = this camera overrides the node`]}),label:t(`device.cameraStepInspector.detectionStepsOfThisCamera`,`Detection steps of this camera`),renderDetail:({stepId:n,accelerator:i,matchedField:a,closeButton:s,onEscape:c,headingRef:l})=>{let d=i??ie[0],f=d?H(d,n)??Ei(te,n):null;if(f===null||d===void 0)return u(`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=Wn(f),h=Le(m),g=le(d,n,p),_=Je(g.node,g.camera,g.accelerator),v=Di(P[d.nodeId],d,U(d,`object-detection`)?.modelId),y=Ni(f,d,{nodePin:d.device.steps?.[n]?.modelId,cameraPin:G(d,n,p)}).modelId,F=Je(g.node,g.camera),I=ze(g.accelerator,F,h),R=Pi(n),ne=ce(n),V=m.find(e=>`label`in e&&e.label===a)?.key??null,re=i===null?null:`${n}|${i.id}`,oe=i===null?`camera`:E?.key===re?E.scope:Mc(U(i,n)),W=e=>{N(null),T(t=>e(t?.stepId===n?t:{stepId:n,perAccelerator:{}}))},ue=(e,t)=>W(n=>({...n,perAccelerator:{...n.perAccelerator,[e.id]:{...n.perAccelerator[e.id],...t}}})),de=e=>W(t=>{let r=g.accelerator??{},i=Ve(t.camera??L?.stepSettings?.[n],e,r,h),a={...t.perAccelerator};for(let r of ae){let i=t.perAccelerator[r.id]?.settings??U(r,n)?.settings;i!==void 0&&(a[r.id]={...a[r.id],settings:Pe(i,e,h)})}return{...t,camera:i,perAccelerator:a}}),fe=async()=>{if(p!==null){j(!0);try{let t=L?.stepSettings?.[n];p.camera!==void 0&&!Ke(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=U(t,n),o=Pc({stored:a,draft:i,below:Je(se(t,n),r),boundKeys:h});Fc(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:`Save failed`})}finally{j(!1),b()}}},pe=p===null?0:+(p.camera!==void 0&&!Ke(p.camera,L?.stepSettings?.[n]??{}))+Object.values(p.perAccelerator).length,me=e=>{let t=H(e,n)??f,i=G(e,n,p),a=e.device.steps?.[n]?.modelId,s=Ni(t,e,{nodePin:a,cameraPin:i}),c=le(e,n,p),l=Di(P[e.nodeId],e,U(e,`object-detection`)?.modelId),d=Ai(n,Je(c.node,c.camera,c.accelerator),l),m=Oi(t,e)?d&&l?u(fr,{rootModel:l,stepModelId:s.modelId}):void 0:r(o,{children:[`No `,e.device.format,` build of this step — it does not run on this accelerator.`]});return{label:e.label,format:e.device.format,modelId:s.modelId,source:s.source,sourceLabel:Nc(s.source),models:kn(t.models??[],e.device.format),defaultModelId:t.defaultModelIdByFormat?.[e.device.format]??t.defaultModelId,expanded:O===e.id,onToggle:()=>k(t=>t===e.id?null:e.id),onChangeModel:t=>ue(e,{modelId:t}),...i===void 0?{}:{onReset:()=>ue(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}},ge=R===null&&m.length>0?i===null?u(`p`,{className:he,children:t(`device.cameraStepInspector.appliesToAllAcceleratorsOf`,`Applies to: all accelerators of this camera.`)}):r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[u(`span`,{className:`text-[11px] font-medium text-foreground`,children:t(`device.cameraStepInspector.appliesTo`,`Applies to`)}),u(zn,{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=>re!==null&&D({key:re,scope:e})})]}):void 0;return u(zt,{ref:l,title:i===null?t(`device.cameraStepInspector.thisCamera`,`{{name}} · this camera`,{name:f.name}):`${f.name} · ${i.label}`,subtitle:i===null?t(`device.cameraStepInspector.everyAcceleratorThisCameraRuns`,`{{slot}} · every accelerator this camera runs on`,{slot:f.slot}):`${f.slot} · ${i.device.format}`,leading:s,onEscape:c,headerActions:u(Fn,{gate:ne,busy:x.isPending,onSet:t=>x.mutate({deviceId:e,addonId:n,enabled:t})}),saveBar:{dirtyCount:pe,saving:A,status:M?.kind??null,...M?.error===void 0?{}:{error:M.error},onSave:()=>void fe(),onDiscard:()=>T(null),...ge===void 0?{}:{scope:ge}},children:r(`div`,{className:`space-y-3`,children:[B.has(n)&&z.source!==null&&u(`p`,{role:`note`,className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-1.5 text-[11px] text-warning`,children:kc(z.source,n)}),r(`section`,{className:`space-y-2`,"aria-label":t(`device.cameraStepInspector.model`,`Model`),children:[u(`h3`,{className:ee,children:t(`device.cameraStepInspector.model`,`Model`)}),R===null?i===null?u(ki,{rows:ie.map(e=>{let t=Ni(H(e,n)??f,e,{nodePin:e.device.steps?.[n]?.modelId,cameraPin:G(e,n,p)});return{id:e.id,label:e.label,modelId:t.modelId,sourceLabel:Nc(t.source)}})}):u(xr,{...me(i)},i.id):u(Ri,{step:R,engineFormat:d.device.format,runnableModelIds:kn(f.models??[],d.device.format).map(e=>e.id)})]}),R===null&&(m.length>0||v!==void 0)&&u(`section`,{"aria-label":t(`device.cameraStepInspector.settings`,`Settings`),className:`border-t border-border/60 pt-2`,children:u(Lc,{addon:f,fields:m,layers:g,scope:oe,viewed:i,modelId:fn(f,y,_,v),root:v,pinned:i===null?[]:I,highlightKey:V,onChangeCamera:e=>W(t=>({...t,camera:e})),onChangeAccelerator:e=>ue(d,{settings:e}),onApplyToAll:de,onFollowNode:()=>ue(d,{settings:I.reduce((e,t)=>Pe(e,t,h),{...g.accelerator})})})}),u(wi,{addonId:n,highlightLabel:a})]})})}})]})}function Lc({addon:e,fields:t,layers:n,scope:i,viewed:a,modelId:o,root:s,pinned:c,highlightKey:l,onChangeCamera:d,onChangeAccelerator:f,onApplyToAll:p,onFollowNode:m}){let{t:h}=Z();ji(l===null?null:_n(l));let g=a!==null&&n.accelerator!==void 0;return u(br,{addon:e,fields:t,layers:{node:n.node,...n.camera===void 0?{}:{camera:n.camera},...g?{accelerator:n.accelerator}:{}},target:i,labels:{...a===null?{}:{accelerator:`This accelerator`},camera:`All accelerators`,node:`Node`},modelId:o,...s===void 0?{}:{rootModel:s},pinnedKeys:c,highlightKey:l,onChangeLayer:i===`camera`?d:f,...c.length>0?{headerActions:r(`button`,{type:`button`,className:U,onClick:m,children:[`Follow the node for `,c.length,` pinned field`,c.length===1?``:`s`]})}:{},fieldActions:(e,t)=>a!==null&&t===`accelerator`?u(`button`,{type:`button`,className:U,onClick:()=>p(e),children:h(`device.cameraStepInspector.applyToAllAccelerators`,`Apply to all accelerators`)}):null})}var Rc=[{id:`object-detection`,label:`Object detection`,icon:`scan-search`},{id:`tracking`,label:`Tracking`,icon:`route`},{id:`motion`,label:`Motion`,icon:`activity`},{id:`stationary`,label:`Stationary`,icon:`square-parking`},{id:`zones`,label:`Zones`,icon:`shapes`},{id:`audio`,label:`Audio`,icon:`volume-2`},{id:`cluster`,label:`Cluster`,icon:`server`}],zc={"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 Bc(e){return zc[e]??`object-detection`}n();var Vc=`steps`,Hc=`settings`,Uc=new Set([Vc,Hc]);function Wc(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function Gc({deviceId:t,activeSubTab:n,onSubTabChange:i}){let{t:a}=Z();return r(xn,{value:n&&Uc.has(n)?n:Vc,onValueChange:e(e=>{i?.(e)},[i]),className:`flex flex-col`,children:[r(Zn,{className:`flex-shrink-0`,children:[u(cr,{value:Vc,children:a(`device.detectionPipelineTab.steps`,`Steps`)}),u(cr,{value:Hc,children:a(`device.detectionPipelineTab.settings`,`Settings`)})]}),u(gr,{value:Vc,children:u(Ic,{deviceId:t})}),u(gr,{value:Hc,children:u(Rr,{deviceId:t,sectionFilter:Wc,subTabGrouping:{groupOf:e=>Bc(e.id),tabs:Rc}})})]})}var Kc=`Notifications`,qc=`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`;function Jc(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:Kc,on:r===null?null:i??r,available:r!==null,costWhenOff:qc}}function Yc(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}n();function Xc(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function Zc({deviceId:t}){let{t:n}=Z(),i=s(),a=Number.isFinite(t),[o,l]=c(null),[d,f]=c(null),p=Jc({mutedDeviceIds:Xc(lr({},{enabled:a}).data),deviceId:t,pendingOn:d}),h=sn({onError:e=>{console.error(`[DeviceNotificationMute] mute write failed — reverting`,{tags:{deviceId:t},meta:{error:e instanceof Error?e.message:String(e)}}),f(null),l(e instanceof Error?e.message:String(e)),i.invalidateQueries({queryKey:[[`notificationRules`,`listDeviceMutes`]]})},onSuccess:()=>{l(null),f(null),i.invalidateQueries({queryKey:[[`notificationRules`]]})}}),g=e(()=>{let e=Yc(p,t);e!==null&&(f(!e.muted),h.mutate(e))},[t,h,p]),_=p.on===null,v=p.on===!1,y=v?xe:m;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`border-b border-border px-4 py-2 flex items-center justify-between gap-2`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:n(`device.deviceNotificationMute.notifications`,`Notifications`)}),v&&u(`span`,{className:`rounded bg-warning/20 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide text-warning`,children:`muted`})]}),r(`div`,{className:`px-4 py-3 flex items-start gap-3`,children:[r(`button`,{type:`button`,role:`switch`,"aria-label":p.label,"aria-checked":p.on===!0,disabled:!p.available||h.isPending,onClick:g,title:_?n(`device.deviceNotificationMute.notificationMuteStateUnknownThe`,`Notification mute — state unknown; the notification centre did not answer.`):v?n(`device.deviceNotificationMute.muted`,`Muted. {{costWhenOff}}`,{costWhenOff:p.costWhenOff}):n(`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 ${o===null?_?`border-dashed border-border text-foreground-subtle/50`:v?`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:[u(y,{className:`h-3.5 w-3.5`}),u(`span`,{children:_?n(`device.deviceNotificationMute.unknown`,`Unknown`):v?n(`device.deviceNotificationMute.muted2`,`Muted`):n(`device.deviceNotificationMute.notifying`,`Notifying`)})]}),u(`p`,{className:`flex-1 text-[11px] leading-relaxed text-foreground-subtle`,children:o===null?_?n(`device.deviceNotificationMute.theNotificationCentreDidNot`,`The notification centre did not answer, so this device’s mute state is unknown.`):p.costWhenOff:n(`device.deviceNotificationMute.writeFailed`,`Write failed: {{failure}}`,{failure:o})})]})]})}function Qc(e,t){return{switchId:e,label:He[e].label,detail:t===void 0||t.length===0?null:t}}function $c(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 el(e){let t=$c(e),n=new Set(e.sourceStillLive),r=e.sourceStillLive.map(e=>Qc(e,t.get(e)?.detail)),i=[...t.values()].filter(e=>e.outcome===`not-offered`&&!n.has(e.switchId)).map(e=>Qc(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}}n();function tl(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 nl({deviceId:e,deviceName:t}){let{t:n}=Z(),a=Qt(),[o,s]=c(null),l=qn({isCamera:!0,projection:`slim`}),d=ln(),f=l.data!==void 0,p=i(()=>l.data===void 0?[]:tl(l.data,e),[l.data,e]),m=p.find(e=>e.id===o)??null,h=d.data===void 0?null:el(d.data),g=d.error===null?null:d.error.message,_=async()=>{m===null||m.id===e||await a({title:n(`deviceMigrate.confirmTitle`,`Replace “{{source}}” with “{{target}}”?`,{source:t,target:m.name}),message:n(`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:n(`deviceMigrate.confirmAction`,`Migrate`),variant:`danger`})&&d.mutate({sourceId:e,targetId:m.id})};return r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`min-w-0`,children:[u(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:n(`deviceMigrate.title`,`Migrate to…`)}),u(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:n(`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})})]}),r(`div`,{className:`flex shrink-0 items-center gap-2`,children:[r(`select`,{"aria-label":n(`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||d.isPending,value:o===null?``:String(o),onChange:e=>{let t=e.target.value;s(t===``?null:Number(t))},children:[u(`option`,{value:``,children:f?n(`deviceMigrate.pickerPlaceholder`,`Select a camera…`):n(`deviceMigrate.pickerPending`,`Reading the fleet…`)}),p.map(e=>r(`option`,{value:String(e.id),children:[e.name,` (#`,e.id,`)`]},e.id))]}),r(`button`,{type:`button`,disabled:m===null||d.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:[u(_e,{className:`h-3 w-3`}),d.isPending?n(`deviceMigrate.running`,`Migrating…`):n(`deviceMigrate.action`,`Migrate`)]})]})]}),f&&p.length===0&&u(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:n(`deviceMigrate.noTargets`,`No other camera is adopted, so there is nothing to migrate to.`)}),g!==null&&u(`p`,{className:`mt-2 text-[11px] text-danger`,children:n(`deviceMigrate.failed`,`Migration failed: {{error}}`,{error:g})}),h!==null&&u(rl,{report:h})]})}function rl({report:e}){let{t}=Z(),n=e.verdict===`quiet`;return r(`div`,{className:`mt-3 space-y-2 border-t border-border pt-3`,children:[u(`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?r(`div`,{className:`flex items-start gap-2 rounded-md border border-success/30 bg-success/5 px-3 py-2`,children:[u(ie,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-success`}),u(`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.`)})]}):r(`div`,{className:`rounded-md border border-warning/40 bg-warning/5 px-3 py-2`,children:[r(`div`,{className:`flex items-start gap-2`,children:[u(B,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),u(`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.`)})]}),u(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.stillLive.map(e=>r(`li`,{className:`text-[11px] text-foreground`,children:[u(`span`,{className:`font-medium`,children:e.label}),e.detail!==null&&r(`span`,{className:`text-foreground-subtle`,children:[` — `,e.detail]})]},e.switchId))})]}),e.neverOffered.length>0&&r(`div`,{className:`rounded-md border border-border px-3 py-2`,children:[r(`div`,{className:`flex items-start gap-2`,children:[u(Ce,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),u(`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.`)})]}),u(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.neverOffered.map(e=>u(`li`,{className:`text-[11px] text-foreground-subtle`,children:e.label},e.switchId))})]})]})}n();function il({deviceId:e}){let{t}=Z(),[n,i]=c(null),a=Pt({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 r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[r(`div`,{className:`flex items-center justify-between gap-3`,children:[r(`div`,{children:[u(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:t(`device.resyncButton.reSync`,`Re-sync`)}),u(`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.`)})]}),r(`button`,{type:`button`,disabled:a.isPending,onClick:()=>{i(null),a.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:[u(me,{className:`h-3 w-3 ${a.isPending?`animate-spin`:``}`}),a.isPending?t(`device.resyncButton.reSyncing`,`Re-syncing…`):t(`device.resyncButton.reSync`,`Re-sync`)]})]}),n!==null&&u(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:n})]})}function al(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function ol({device:e}){let{t}=Z(),n=Wr(),i=typeof e.id==`number`?e.id:null,a=String(e.type??``),o=a===J.Camera,s=a===J.Hub,c=e.features??[],l=c.includes(Ee.Resyncable),{data:d}=Xt({deviceId:i??0},{enabled:i!==null&&o,refetchInterval:5e3}),f=d?.streams??{},p=Object.entries(f),m=c.includes(Ee.DoorbellButton),h=jn(m?{deviceId:i??void 0,historyLimit:10}:void 0),g=h.latest?Date.now()-h.latest.timestamp<3e4:!1;return r(`div`,{className:`space-y-5`,children:[s&&i!==null&&u(or,{deviceId:i,onOpenChild:e=>n(`/devices/${e}`)}),l&&i!==null&&u(il,{deviceId:i}),o&&i!==null&&u(nl,{deviceId:i,deviceName:String(e.name??``)}),i!==null&&u(Zc,{deviceId:i}),o&&i!==null&&u(Sr,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:i}),m&&u(St,{history:h.history,latestIsFresh:g}),o&&i!==null&&u(Sr,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:i}),o&&p.length>0&&r(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[u(`div`,{className:`border-b border-border px-4 py-2`,children:u(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:t(`device.overviewTab.streamNetwork`,`Stream Network`)})}),u(`div`,{className:`divide-y divide-border`,children:p.map(([e,n])=>r(`div`,{className:`px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 mb-2`,children:[u(H,{className:`h-3 w-3 text-foreground-subtle`}),u(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),r(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[u(sl,{label:t(`device.overviewTab.nominal`,`Nominal`),value:al(n.nominalBitrateKbps??0)}),u(sl,{label:t(`device.overviewTab.observed`,`Observed`),value:al(n.observedBitrateKbps??0)}),u(sl,{label:t(`device.overviewTab.peak`,`Peak`),value:al(n.peakBitrateKbps??0)}),u(sl,{label:t(`device.overviewTab.packetLoss`,`Packet Loss`),value:`${(n.packetLossPercent??0).toFixed(2)}%`,warning:(n.packetLossPercent??0)>1})]})]},e))})]}),u(Qr,{}),i!==null&&u(Mr,{deviceId:i})]})}function sl({label:e,value:t,warning:n}){return r(`div`,{children:[u(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),u(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}var cl=[{id:`overview`,label:`Overview`,cameraOnly:!1,adminOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1,adminOnly:!1},{id:Xr,label:`Customize`,cameraOnly:!1,adminOnly:!0},{id:`detection-pipeline`,label:`Detection pipeline`,cameraOnly:!0,adminOnly:!1},{id:`bindings`,label:`Bindings`,cameraOnly:!0,adminOnly:!1}];function ll(e,t){let n=e===J.Camera;return cl.filter(e=>(n||!e.cameraOnly)&&(t||!e.adminOnly)).map(({id:e,label:t})=>({id:e,label:t}))}function ul({provider:e,integrationId:t,name:n}){let r=Wr(),i=t===null?`/integrations`:`/integrations/${t}`,a=n===null?`Open integrations`:`Open integration ${n}`;return u(`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:u(Fr,{type:e,size:`lg`})})}n();var dl=[{id:`logs`,icon:oe,label:`Logs`},{id:`repl`,icon:K,label:`REPL`},{id:`events`,icon:T,label:`Events`},{id:`state`,icon:x,label:`State`}];function fl(){let{t:n}=Z(),a=Gr(),l=Number(a.deviceId),d=Number.isFinite(l),f=Wr(),p=s(),m=Qt(),h=W(),{user:g}=Br(),v=g?.isAdmin===!0,[y,b]=zr(),x=y.get(`tab`)??`overview`,S=y.get(`sub`),[C,w]=c(`logs`),T=`device-detail.left-col-width-px`,[E,D]=c(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(T),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),O=t(E);O.current=E;function k(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??E??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{D(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=O.current;if(e!==null)try{window.localStorage.setItem(T,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:A,isLoading:j,isError:ee}=vr({deviceId:l},{enabled:d,refetchInterval:5e3,retry:1}),{data:P}=gn({deviceId:l},{enabled:d}),F=i(()=>{let e=P?.settings?.sections??[],t=P?.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(Lr)&&r.add(qr),[...r].map(e=>e===`export`?{id:e,label:Ir,isAddonContrib:!0}:{id:e,label:Fe[e]?.label??e,isAddonContrib:!0})},[P]),I=A,L=String(I?.name??a.deviceId??`Device`),R=I?.online===!0,ne=R?`online`:`offline`,z=String(I?.addonId??`rtsp`),B=I?.features??[],V=I?.type,re=V===J.Camera,{data:ie}=Hr(d?l:0),ae=V===J.Container,oe=i(()=>(ie??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[ie]),H=i(()=>ae?Dn(oe,typeof I?.linkDeviceId==`number`?I.linkDeviceId:null,typeof I?.primaryChildEntityId==`string`?I.primaryChildEntityId:null)?.id??null:null,[ae,oe,I?.linkDeviceId,I?.primaryChildEntityId]),{data:U}=gn({deviceId:H??0},{enabled:H!==null}),se=i(()=>{if(H===null)return[];let e=U?.settings?.sections??[],t=U?.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:Fe[e]?.label??e,isAddonContrib:!0,childDeviceId:H}))},[H,U]),ce=typeof I?.parentDeviceId==`number`?I.parentDeviceId:null,{data:le}=vr({deviceId:ce??0},{enabled:ce!==null}),G=Pn(),de=I?.disabled!==!0,fe=i(()=>{let e=P?.settings?.sections??[],t=P?.live?.sections??[];return Jr([...e,...t],V,v,P!==void 0)},[P,V,v]),he=i(()=>{let e=new Set,t=[];for(let n of[...ll(V,v),...F,...se])n.id===`config`&&!fe||e.has(n.id)||(e.add(n.id),t.push(n));return t},[V,v,F,se,fe]),ge=i(()=>mc(he,x),[he,x]),_e=e(e=>{b(t=>{let n=new URLSearchParams(t);e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`);for(let e of Vi)n.delete(e);return n},{replace:!0})},[b]),ve=e(e=>{b(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[b]),ye=(ie??[]).length>0,be=i(()=>dl.filter(({featureGate:e})=>!e||B.includes(e)),[B]),{data:xe}=pn(void 0),Se=i(()=>I?Qn(I,xe):null,[I,xe]),K=Se?.kind===`resolved`?Se.integration:null,Ce=K===null?Se?.kind===`unknown`?`Loading integration…`:Se?.kind===`orphan`?`Missing integration`:`No integration`:K.name,we=K!==null&&K.addonId===z?K.name:z,Te=st({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]}),f(K?.id?`/integrations/${K.id}`:`/integrations`)}}),De=tr({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),q=mr({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Oe=Bt(),ke=kt({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ae=B.includes(Ee.Rebootable),je=B.includes(Ee.BatteryOperated),Me=Gn(h.trpcClient,je&&d?l:null),Ne=mn(h.trpcClient,d?l:null),[Pe,Ie]=c(!1),Le=async()=>{if(!Pe){Ie(!0);try{let e=L.replace(/[^a-zA-Z0-9_.-]+/g,`_`),t=new Date().toISOString().replace(/[:.]/g,`-`);await na(`${N}/${String(l)}.jpg?force=1`,`${e}-${t}.jpg`)}finally{Ie(!1)}}},Re=De.isPending||q.isPending,{data:ze}=bt({deviceId:l},{enabled:d,refetchInterval:1e4}),Be=ze?.agentNodeId??null,Ve=typeof Be==`string`&&Be.length>0&&!Be.startsWith(`addon:`)?Be:void 0,{data:He}=yr({deviceId:l,...Ve?{nodeId:Ve}:{}},{enabled:d,refetchInterval:3e3,retry:!1}),{data:Ue}=xt({deviceId:l},{enabled:d,refetchInterval:3e3,retry:!1}),Y=Ue?.level?.dbfs??null;function We(){if(!d)return null;switch(ge){case`overview`:return u(ol,{device:I??{}});case`config`:return u(yc,{deviceId:l,activeSubTab:S,onSubTabChange:ve,deviceType:V,isAdmin:v});case`detection-pipeline`:return u(Gc,{deviceId:l,activeSubTab:S,onSubTabChange:ve});case`bindings`:return u(hc,{deviceId:l});case Xr:return u(sc,{deviceId:l,activeSubTab:S,onSubTabChange:ve});default:{let e=ge,t=F.some(t=>t.id===e),n=se.find(t=>t.id===e);if(!t&&n===void 0)return null;let r=n?.childDeviceId??l;if(e===`export`)return u(Rr,{deviceId:l,sectionFilter:Lr,activeSubTab:S,onSubTabChange:ve});let i=u(Rr,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:S,onSubTabChange:ve});return n!==void 0&&r!==l?u(wt,{deviceId:r,children:i}):i}}}return d?j?r(`div`,{className:`flex flex-col h-full`,children:[r(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[u(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),u(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),u(`div`,{className:`flex-1 p-6`,children:u(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):ee||!A?r(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[u(`p`,{className:`text-lg font-semibold text-foreground`,children:n(`deviceDetail.deviceNotFound`,`Device not found`)}),r(`p`,{className:`text-xs`,children:[`No device with ID`,` `,r(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,l]})]}),u(`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:n(`deviceDetail.backToIntegrations`,`Back to Integrations`)})]}):r(`div`,{className:`absolute inset-0 flex flex-col overflow-clip`,children:[r(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[u(`div`,{className:`mb-2`,children:u(Tt,{items:[{label:n(`deviceDetail.integrations`,`Integrations`),onClick:()=>f(`/integrations`)},K===null?{label:Ce}:{label:Ce,onClick:()=>f(`/integrations/${K.id}`)},{label:L}]})}),r(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[K!==null&&u(ul,{provider:K.addonId,integrationId:K.id,name:K.name}),r(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:L}),u(Dt,{status:ne}),je&&u(Lt,{status:Me,variant:`full`}),u(en,{status:Ne})]}),ce!==null&&le&&r(`button`,{type:`button`,onClick:()=>f(`/devices/${ce}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:n(`deviceDetail.openParentDevice`,`Open parent device {{name}}`,{name:le.name}),children:[u(`span`,{children:`↑`}),u(`span`,{className:`truncate`,children:String(le.name??`Device #${ce}`)})]}),u(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:B.length>0&&u(Yr,{capabilities:B})})]}),He&&u(`div`,{className:`hidden lg:flex`,children:u(pl,{metrics:He,dbfs:Y})}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[r(`button`,{onClick:async()=>{de?await m({title:n(`deviceDetail.disable`,`Disable "{{name}}"?`,{name:L}),message:n(`deviceDetail.theDeviceWillStopProcessing`,`The device will stop processing streams and events. You can re-enable it later.`),confirmLabel:n(`common.disable`,`Disable`),variant:`danger`})&&q.mutate({deviceId:l}):De.mutate({deviceId:l})},disabled:Re,title:de?n(`deviceDetail.disableDevice`,`Disable device`):n(`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 ${de?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[u(M,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:Re?n(`deviceDetail.updating`,`Updating…`):de?n(`deviceDetail.enabled`,`Enabled`):n(`deviceDetail.disabled`,`Disabled`)})]}),u(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),re&&r(o,{children:[u(la,{deviceId:l}),u(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),u(da,{deviceId:l}),u(Jt,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:n(`deviceDetail.takeSnapshot`,`Take snapshot`),description:n(`deviceDetail.fetchAFreshFrameAnd`,`Fetch a fresh frame and download it.`),icon:pe,disabled:Pe,onClick:()=>{Le()}},{id:`reboot`,label:n(`deviceDetail.rebootDevice`,`Reboot device`),description:n(`deviceDetail.cameraGoesOfflineFor30`,`Camera goes offline for ~30 seconds.`),icon:te,hidden:!Ae,disabled:Oe.isPending,danger:!0,onClick:async()=>{await m({title:n(`deviceDetail.reboot`,`Reboot "{{name}}"?`,{name:L}),message:n(`deviceDetail.theCameraWillGoOffline`,`The camera will go offline for around 30 seconds while the firmware reboots.`),confirmLabel:n(`deviceDetail.reboot2`,`Reboot`),variant:`danger`})&&Oe.mutate({deviceId:l})}},{id:`restart-addon`,label:n(`deviceDetail.restartAddon`,`Restart addon`),description:n(`deviceDetail.bouncesEveryDeviceServedBy`,`Bounces every device served by {{servingAddonLabel}}.`,{servingAddonLabel:we}),icon:me,disabled:ke.isPending,danger:!0,onClick:async()=>{await m({title:n(`deviceDetail.restart`,`Restart "{{servingAddonLabel}}"?`,{servingAddonLabel:we}),message:n(`deviceDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device served by it (not just "{{name}}"). Streams will reconnect automatically.`,{name:L}),confirmLabel:n(`deviceDetail.restart2`,`Restart`),variant:`danger`})&&ke.mutate({addonId:z})}},{id:`delete`,label:n(`deviceDetail.deleteDevice`,`Delete device`),description:n(`deviceDetail.removeTheDeviceAndAll`,`Remove the device and all its settings.`),icon:_,separatorBefore:!0,disabled:Te.isPending,danger:!0,onClick:async()=>{await m({title:n(`deviceDetail.delete`,`Delete "{{name}}"?`,{name:L}),message:n(`deviceDetail.thisWillRemoveTheDevice`,`This will remove the device and all its settings. This action cannot be undone.`),confirmLabel:n(`common.delete`,`Delete`),variant:`danger`})&&Te.mutate({deviceId:l})}}]})]})]})]}),u(wt,{deviceId:l,device:I??void 0,children:u(pt,{children:u(Ot,{children:u(ue,{children:u(dn,{children:r(`main`,{className:G?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[r(`div`,{className:G?`flex flex-col bg-surface`:`${E===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!G&&E!==null?{width:`${String(E)}px`}:void 0,children:[u(`div`,{className:re?`flex-shrink-0 border-b border-border-subtle bg-black`:G?`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:re?u(Ga,{deviceId:l,intercomAvailable:B.includes(Ee.TwoWayAudio)}):u(Fa,{deviceId:l,deviceName:L,deviceType:V??`unknown`,provider:z,isOnline:R,features:B})}),r(`div`,{className:G?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[u(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:u(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:be.map(({id:e,label:t,icon:n})=>r(`button`,{onClick:()=>w(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${C===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[u(n,{className:`h-3 w-3`}),t]},e))})}),r(`div`,{className:G?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[C===`logs`&&u(Ka,{deviceId:l,containerDeviceId:V===`container`?l:void 0}),C===`repl`&&u(qa,{deviceId:l}),C===`events`&&u(Ja,{deviceId:l}),C===`state`&&u(Ya,{deviceId:l})]})]})]}),!G&&u(`div`,{role:`separator`,"aria-orientation":`vertical`,title:n(`deviceDetail.dragToResize`,`Drag to resize`),onMouseDown:k,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:u(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),r(`div`,{className:G?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[u(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:u(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:he.map(e=>{let t=ge===e.id;return r(`button`,{onClick:()=>_e(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&&u(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),r(`div`,{className:G?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[ge===`overview`&&ye&&u(fa,{parentDeviceId:l}),We()]})]})]})})})})})})]}):r(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[u(`p`,{className:`text-lg font-semibold text-foreground`,children:n(`deviceDetail.invalidDeviceId`,`Invalid device id`)}),r(`p`,{className:`text-xs`,children:[`The URL segment`,` `,u(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:a.deviceId}),` `,n(`deviceDetail.isNotANumber`,`is not a number.`)]}),u(`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:n(`deviceDetail.backToIntegrations`,`Back to Integrations`)})]})}function pl({metrics:e,dbfs:t}){let{t:n}=Z(),i=jt(e.phase??`idle`);return r(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[r(`div`,{className:`flex items-center gap-1.5`,children:[u(`span`,{className:`h-1.5 w-1.5 rounded-full ${i.dotClass}`}),u(`span`,{className:`text-[10px] font-medium ${i.textColor}`,children:i.label})]}),u(`div`,{className:`h-3 w-px bg-border`}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[u(E,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),u(`span`,{children:`fps`})]}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[u(y,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),u(`span`,{children:`ms`})]}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:n(`deviceDetail.currentAudioLevelDbfs`,`Current audio level (dBFS)`),children:[u(A,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),u(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&r(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{fl as DeviceDetailPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Q as e,S as t,W as n,a as r,x as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{ot as a}from"./player-overlays-Cda8wso6.js";import{Bt as o,Gt as s,Ht as c,Kt as l,Ut as u,Vt as d,Wt as f,zt as p}from"./client-CMlUvfoK.js";import{d as m}from"./src-eoSUZcV-.js";import{t as h}from"./useTranslation-Bc5yH9V9.js";import"./notification-schedule-field-DWpT_5Vh.js";e();var g=6e4;function _(e){let t=a();return r({queryKey:[`device-do-action`,`bound-caps`,e],enabled:e>0,staleTime:g,queryFn:async()=>{let n=await t.trpcClient.deviceManager.getBindings.query({deviceId:e});return[...new Set(n.entries.map(e=>e.capName))].sort((e,t)=>e.localeCompare(t))}})}function v(e){let t=a(),n=[...new Set(e.filter(e=>e>0))].sort((e,t)=>e-t);return r({queryKey:[`device-do-action`,`bound-caps-batch`,n],enabled:n.length>0,staleTime:g,queryFn:async()=>{let e=await t.trpcClient.deviceManager.getBindingsBatch.query({deviceIds:n}),r=new Map;for(let t of e)r.set(t.deviceId,[...new Set(t.entries.map(e=>e.capName))].sort((e,t)=>e.localeCompare(t)));return r}})}var y=`mt-1 w-full rounded border border-border bg-background px-2 py-1 text-xs`,b=`block text-[11px] font-medium text-foreground`,x=`deviceId`;function S(e,t){return t.length===0?0:t.length===1?t[0]:t.find(t=>!e.includes(t))??t[t.length-1]}function C(e,t,n){if(t.length===0)return[];if(t.length===1)return t;let r=t.find(t=>!e.includes(t));if(r===void 0)return t;let i=n(r);if(i===void 0)return[r];let a=e[0]??t.find(e=>e!==r);if(a===void 0)return[r];let o=n(a);return o===void 0||!l(o,i)?[r]:t.filter(e=>{let t=n(e);return t!==void 0&&l(o,t)})}function w(e){return e.length===0?0:e.length===1?e[0]:[...e]}function T(e){return typeof e==`number`?e>0?[e]:[]:Array.isArray(e)?e.filter(e=>e>0):[]}function E(e,t){return{deviceId:e,cap:t.cap,method:t.method,...t.args===void 0?{}:{args:{...t.args}}}}function D(e,t){return`Custom: ${e}.${t}`}function O({value:e,onChange:r,devices:a,listState:g,fleet:O,allowTriggerDevice:k=!1,allowMultiSameFamily:A=!1,testId:j=`device-do-action`}){let{t:M}=h(),N=typeof e.deviceId!=`number`&&!Array.isArray(e.deviceId),P=T(e.deviceId),F=n(()=>a.filter(e=>f(String(e.type??``))),[a]),I=n(()=>{let e=new Map;for(let t of F)t.type!==void 0&&t.type!==null&&e.set(t.id,String(t.type));return e},[F]),L=n(()=>{if(!A||P.length===0)return F;let e=I.get(P[0]);return e===void 0?F:F.filter(t=>{if(P.includes(t.id))return!0;let n=t.type!==void 0&&t.type!==null?String(t.type):void 0;return n!==void 0&&l(e,n)})},[A,P,F,I]),R=_(!A&&P.length===1?P[0]:0),z=v(A?P:[]),B=n(()=>N?c():P.length===0?[]:A?z.isLoading&&z.data===void 0?[]:d(P.map(e=>({boundCaps:z.data?.get(e),deviceType:I.get(e)}))):R.data===void 0&&R.isLoading?[]:o({boundCaps:R.data,deviceType:I.get(P[0])}),[N,P,A,z.data,z.isLoading,R.data,R.isLoading,I]),V=u(e.cap,e.method,e.args),H=s(e.cap,e.method,e.args),U=e.cap!==``&&e.method!==``&&H===null&&(N||P.length>0),W=A?z.isLoading:R.isLoading,G=A?z.isError:R.isError,K=t=>{if(t.startsWith(`custom:`))return;let n=p.find(e=>e.id===t);n!==void 0&&r(E(N?e.deviceId:P.length>0?w(P):F[0]?.id??0,n))};return t(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,"data-testid":j,children:[k&&t(`div`,{className:`w-full max-w-xs`,children:[i(`label`,{className:b,children:M(`deviceDoAction.deviceDoActionFields.target`,`Target`)}),t(`select`,{className:y,"data-testid":`${j}-target`,value:N?`trigger`:`device`,onChange:e=>{if(e.target.value===`trigger`){r({deviceId:{$var:x},cap:``,method:``});return}r({deviceId:F[0]?.id??0,cap:``,method:``})},children:[i(`option`,{value:`device`,children:M(`deviceDoAction.deviceDoActionFields.specificDevice`,`Specific device`)}),i(`option`,{value:`trigger`,children:M(`deviceDoAction.deviceDoActionFields.theDeviceThatTriggeredThis`,`The device that triggered this run`)})]})]}),!N&&t(`div`,{"data-testid":`${j}-device`,children:[t(`label`,{className:b,children:[`Device`,A?`s`:``]}),i(m,{devices:L,listState:g,...O===void 0?{}:{fleet:O},value:[...P],onChange:e=>{r({deviceId:w(A?C(P,e,e=>I.get(e)):(()=>{let t=S(P,e);return t>0?[t]:[]})()),cap:``,method:``})},emptyLabel:A?`No devices selected`:`No device selected`,noun:`device`,testId:`${j}-device-picker`}),A&&P.length>1&&i(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:M(`deviceDoAction.deviceDoActionFields.sameFamilyOnlyTheAction`,`Same family only — the action runs on each selected device.`)})]}),t(`div`,{className:`w-full max-w-sm`,children:[i(`label`,{className:b,children:M(`deviceDoAction.deviceDoActionFields.action`,`Action`)}),t(`select`,{className:y,"data-testid":`${j}-action`,value:V===`custom:${e.cap}.${e.method}`?V:H?.id??``,disabled:!N&&(P.length===0||W),onChange:e=>K(e.target.value),children:[i(`option`,{value:``,children:!N&&P.length===0?M(`deviceDoAction.deviceDoActionFields.pickADeviceFirst`,`Pick a device first`):W?M(`deviceDoAction.deviceDoActionFields.loadingActions`,`Loading actions…`):B.length===0?M(`deviceDoAction.deviceDoActionFields.noActionsForThisDevice`,`No actions for this device`):M(`deviceDoAction.deviceDoActionFields.selectAnAction`,`Select an action…`)}),U&&i(`option`,{value:V,children:D(e.cap,e.method)}),B.map(e=>i(`option`,{value:e.id,children:e.label},e.id))]}),G&&i(`p`,{className:`mt-1 text-[11px] text-warning`,children:M(`deviceDoAction.deviceDoActionFields.couldNotReadThisDevice`,`Could not read this device’s capabilities.`)})]}),H?.openArgs!==void 0&&H.openArgs.length>0&&i(`div`,{className:`flex flex-col gap-2`,children:H.openArgs.map(n=>{let a=e.args?.[n.key],o=typeof a==`string`||typeof a==`number`?String(a):``;return t(`div`,{className:`w-full max-w-sm`,children:[i(`label`,{className:b,htmlFor:`${j}-${n.key}`,children:n.label}),i(`input`,{id:`${j}-${n.key}`,className:y,"data-testid":`${j}-${n.key}`,type:n.kind===`number`?`number`:`text`,value:o,onChange:t=>{let i=t.target.value,a=e.args===void 0?{}:{...e.args};if(i===``)delete a[n.key];else if(n.kind===`number`){let e=Number(i);Number.isNaN(e)?delete a[n.key]:a[n.key]=e}else a[n.key]=i;r(Object.keys(a).length>0?{...e,args:a}:{deviceId:e.deviceId,cap:e.cap,method:e.method})}})]},n.key)})})]})}export{O as t};
|