@camstack/addon-admin-ui 1.2.473 → 1.2.474
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-DmwaRNVP.js → AddonAssetIcon-DNTjc2uq.js} +1 -1
- package/dist/assets/Addons-CPaW6tLw.js +4 -0
- package/dist/assets/{AdminPage-B-1YjUaD.js → AdminPage-B4QlIiKh.js} +1 -1
- package/dist/assets/{AdminSectionedPage-DCas2jUy.js → AdminSectionedPage-BIoU14zn.js} +1 -1
- package/dist/assets/AiProfiles-FpbSg3kP.js +3 -0
- package/dist/assets/{BrokerForm-x5UJk9ci.js → BrokerForm-CU4X3nL7.js} +1 -1
- package/dist/assets/Build-C2qKCizt.js +40 -0
- package/dist/assets/Calendars-BRTmlFIt.js +1 -0
- package/dist/assets/{Cluster-DaFXU71S.js → Cluster-BvxOiIZ7.js} +1 -1
- package/dist/assets/CompositionCreateForm-DCUy3waQ.js +1 -0
- package/dist/assets/{CompositionEditorPage-B_ERZESY.js → CompositionEditorPage-syg6YTJF.js} +1 -1
- package/dist/assets/Data-VG64mGmK.js +2 -0
- package/dist/assets/DeviceDetail-tZevLHDV.js +2 -0
- package/dist/assets/{DeviceDoActionFields-BETAvCYe.js → DeviceDoActionFields-BmEM1vFn.js} +1 -1
- package/dist/assets/{Devices-C1DTPVnZ.js → Devices-B-b5cUYn.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-Bw6TIHbX.js → EmbedPlayerPage-CI3OOtRg.js} +1 -1
- package/dist/assets/HelperWizard-4637ctxc.js +2 -0
- package/dist/assets/History-BJcol9mz.js +1 -0
- package/dist/assets/Identity-CjEfAbi1.js +1 -0
- package/dist/assets/IntegrationDetail-DLncDXox.js +1 -0
- package/dist/assets/{IntegrationHub-DahW4X5K.js → IntegrationHub-B1soAFk9.js} +1 -1
- package/dist/assets/Integrations-DtQc1eDp.js +1 -0
- package/dist/assets/Integrations-xxkUIJ67.js +1 -0
- package/dist/assets/{Library-gaMbp-Fr.js → Library-DbHcY62a.js} +1 -1
- package/dist/assets/Locations-CfYQkG2R.js +3 -0
- package/dist/assets/{Logs-CtH4NMql.js → Logs-CMYLVX21.js} +1 -1
- package/dist/assets/{MaskShapeCanvas-Byp9XgNC.js → MaskShapeCanvas-BnMDm4ev.js} +1 -1
- package/dist/assets/{MotionZonesSettings-C35beRsS.js → MotionZonesSettings-DKqDt4OB.js} +1 -1
- package/dist/assets/{MyAccess-Dj5hcaLN.js → MyAccess-CjUd-G8J.js} +1 -1
- package/dist/assets/{Network-D-v-cA54.js → Network-Dudx2Fcg.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-CW_M8Xge.js → NodeAddonsSettingsPanel-9_q0f4bE.js} +1 -1
- package/dist/assets/Notifications-DE5Wtais.js +1 -0
- package/dist/assets/{Pipeline-C85hColk.js → Pipeline-r8TFI-Fa.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-SPaH91xV.js → PrivacyMaskSettings-DZ2mewnu.js} +1 -1
- package/dist/assets/Recordings-BrpMcrZw.js +1 -0
- package/dist/assets/{ScanNetworkModal-ClvLQ-ol.js → ScanNetworkModal-DhahS87x.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-BvqnlZ2i.js → SceneMonitorEditor-CH7F9rZo.js} +1 -1
- package/dist/assets/SessionsList-BbD9LSdf.js +2 -0
- package/dist/assets/{Showroom-jPZcBd6K.js → Showroom-BX1LrKmF.js} +1 -1
- package/dist/assets/{System-B5Ny1ozj.js → System-CvErxLx3.js} +1 -1
- package/dist/assets/{Terminal-DYLSrpsL.js → Terminal-COEKXIAj.js} +3 -3
- package/dist/assets/{Viewer-GqkHpMmf.js → Viewer-BW9JCbu_.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BlUFdak1.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-B4AOEb1R.js} +1 -1
- package/dist/assets/{addon-icons-context-BUi2hqSA.js → addon-icons-context-Bus8wGvh.js} +1 -1
- package/dist/assets/{archive-Bs9ToeWK.js → archive-BTmhmQQp.js} +1 -1
- package/dist/assets/{assignment-candidates-e6s6JtrJ.js → assignment-candidates-C4DL_rSh.js} +1 -1
- package/dist/assets/{authed-media-BWhmwHt2.js → authed-media-C8FW8mvx.js} +1 -1
- package/dist/assets/{bell-off-CosUv2Rj.js → bell-off-DsAerV0u.js} +1 -1
- package/dist/assets/{board-model-BtdRuNBI.js → board-model-CnpzmN9f.js} +1 -1
- package/dist/assets/{boxes-CA7Sh4JV.js → boxes-DT6bkxUA.js} +1 -1
- package/dist/assets/circle-slash-BFwh1Zbg.js +1 -0
- package/dist/assets/{client-DIBstlq5.js → client-BbPYrWg7.js} +14 -14
- package/dist/assets/{cloud-upload-olZ1M2tJ.js → cloud-upload-iGrXLaxX.js} +1 -1
- package/dist/assets/crop-FX76GBoF.js +1 -0
- package/dist/assets/{device-integration-icon-656UPgnE.js → device-integration-icon-XVdZ9pIS.js} +1 -1
- package/dist/assets/device-picker-model-B5MjkWnS.js +1 -0
- package/dist/assets/{dist-G4Cxki3p.js → dist-Bd_kB5yG.js} +1 -1
- package/dist/assets/{eraser-CABcfjb2.js → eraser-L4lKjV-e.js} +1 -1
- package/dist/assets/{format-BYDOzxSv.js → format-BTMQLjGl.js} +1 -1
- package/dist/assets/{hard-drive-download-ClcxzAVo.js → hard-drive-download-cfcxCkzE.js} +1 -1
- package/dist/assets/{hostInit-DXWqqcl-.js → hostInit-BBq0iCeL.js} +1 -1
- package/dist/assets/{i18n-D3CF2V_j.js → i18n-BO6gCPcC.js} +1 -1
- package/dist/assets/{icons-BmpL14Dq.js → icons-Cv_Dcjty.js} +1 -1
- package/dist/assets/{index-Cskol4XA.js → index-C8XwyZGE.js} +3 -3
- package/dist/assets/{key-CURebvKJ.js → key-e3_N15fG.js} +1 -1
- package/dist/assets/{key-round-BTmR8Ca5.js → key-round-x0Ig1rd2.js} +1 -1
- package/dist/assets/{layers-BCzFIxnd.js → layers-T4HoHbdn.js} +1 -1
- package/dist/assets/{linked-devices-model-Uzvgx-iv.js → linked-devices-model-CObOrxIk.js} +1 -1
- package/dist/assets/{list-ordered-BpmnL-Ze.js → list-ordered-I4dBVzRf.js} +1 -1
- package/dist/assets/{location-owned-usage-ChLz8liX.js → location-owned-usage-D17U3uzz.js} +1 -1
- package/dist/assets/{log-in-hW2oGppQ.js → log-in-B1D0wNrs.js} +1 -1
- package/dist/assets/{memory-stick-DJEnjf6G.js → memory-stick-DYS3v1CU.js} +1 -1
- package/dist/assets/{message-square-plus-CZ2oQ3Vr.js → message-square-plus-D64e2l9L.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-0c9682e8.js → mf-entry-bootstrap-0-c6a36508.js} +2 -2
- package/dist/assets/{mic-off-KFKpp3gz.js → mic-off-hTqpFTxe.js} +1 -1
- package/dist/assets/{monitor-off-Cn5TAK6N.js → monitor-off-Bj-JQM7b.js} +1 -1
- package/dist/assets/{monitor-smartphone-Jvu4UJGi.js → monitor-smartphone-CyTSF3mW.js} +1 -1
- package/dist/assets/mount-B5MjkWnS.js +1 -0
- package/dist/assets/{player-overlays-B_ZfVBiA.js → player-overlays-CvKnZb5M.js} +1 -1
- package/dist/assets/{recycle-BDm5DJUQ.js → recycle-BLx8Nd-6.js} +1 -1
- package/dist/assets/remoteEntry-DBUvkI6n.js +1 -0
- package/dist/assets/{scan-eye-C7MTwcP4.js → scan-eye-CrOhuNWQ.js} +1 -1
- package/dist/assets/{scissors-BQnPBcjw.js → scissors-C6HYvaxr.js} +1 -1
- package/dist/assets/{search-x-DEyDFvNT.js → search-x-C8eiZDQW.js} +1 -1
- package/dist/assets/{send-B3qo7thK.js → send-CNzJmniJ.js} +1 -1
- package/dist/assets/{settings-2-C0X8oPpn.js → settings-2-Ccb0AMXU.js} +1 -1
- package/dist/assets/{speaker-pcRBhz9y.js → speaker-BsE4hqmg.js} +1 -1
- package/dist/assets/src-DKc14e9G.js +67 -0
- package/dist/assets/step-inspector-model-BeIQx3rW.js +1 -0
- package/dist/assets/{timer-reset-CCky8ePa.js → timer-reset-Tun-zcxs.js} +1 -1
- package/dist/assets/{ungroup-iaoDNnXe.js → ungroup-BdxY8QDj.js} +1 -1
- package/dist/assets/{unlink-8OutaYJL.js → unlink-BVODHZoC.js} +1 -1
- package/dist/assets/{usb-DL2I9kcC.js → usb-i2JzfEjl.js} +1 -1
- package/dist/assets/{use-scenes-feed-4lpCQaI1.js → use-scenes-feed-CUQxwk-v.js} +1 -1
- package/dist/assets/{use-stationary-objects-P_tT9TQq.js → use-stationary-objects-Cqmb4Ymg.js} +1 -1
- package/dist/assets/useEventInvalidation-B5MjkWnS.js +1 -0
- package/dist/assets/{useNodeUrlSelection-CiraZrDp.js → useNodeUrlSelection-rnUQLTfb.js} +1 -1
- package/dist/assets/user-round-BkFCDGbj.js +1 -0
- package/dist/assets/{user-x-DYn__Nok.js → user-x-CIq05NC_.js} +1 -1
- package/dist/assets/{video-BcVXMTle.js → video-CJw8Jnle.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CXWzeD1i.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BWKP-Fxc.js} +2 -2
- package/dist/index.html +9 -9
- package/dist/server/addon.js +1 -1
- package/package.json +1 -1
- package/dist/assets/Addons-Ch5dCeth.js +0 -4
- package/dist/assets/AiProfiles-ChvfjsXv.js +0 -3
- package/dist/assets/Build-CUVwS9XA.js +0 -40
- package/dist/assets/Calendars-BMLzvBb6.js +0 -1
- package/dist/assets/CompositionCreateForm-BxelZLtf.js +0 -1
- package/dist/assets/Data-CMHfgMXt.js +0 -2
- package/dist/assets/DeviceDetail-CAtDRoZZ.js +0 -2
- package/dist/assets/History-BXTYUTxj.js +0 -1
- package/dist/assets/Identity-DTOixhZS.js +0 -1
- package/dist/assets/IntegrationDetail-CnINeomo.js +0 -1
- package/dist/assets/Integrations-Dex6zRMx.js +0 -1
- package/dist/assets/Integrations-HN2iCOqd.js +0 -1
- package/dist/assets/Locations-haT1EJbm.js +0 -3
- package/dist/assets/Notifications-r5w4Ne2O.js +0 -1
- package/dist/assets/Recordings-ZYwRaSrC.js +0 -1
- package/dist/assets/SessionsList-BCDysQfs.js +0 -2
- package/dist/assets/circle-slash-0Ca1BMK0.js +0 -1
- package/dist/assets/crop-BZM3UFyT.js +0 -1
- package/dist/assets/device-picker-model-yjEyEWyS.js +0 -1
- package/dist/assets/event-targets-CHOtaC2B.js +0 -2
- package/dist/assets/mount-yjEyEWyS.js +0 -1
- package/dist/assets/remoteEntry-7WZh94sn.js +0 -1
- package/dist/assets/src-BVr0SnD-.js +0 -67
- package/dist/assets/step-inspector-model-DjRSZkVO.js +0 -1
- package/dist/assets/useEventInvalidation-yjEyEWyS.js +0 -1
- package/dist/assets/user-round-4ZziAKb6.js +0 -1
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,L as i,S as a,b as o,o as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{An as l,D as u,Fn as d,Gi as f,It as p,Jr as m,Nt as h,Q as g,Wr as _,Xi as v,Yi as y,Zr as b,ai as x,fn as S,ir as C,kn as w,or as T,pi as E,rr as D,si as O,vn as k,xi as A,yi as j}from"./player-overlays-B_ZfVBiA.js";import{n as M,t as N}from"./cloud-upload-olZ1M2tJ.js";import{t as P}from"./circle-slash-0Ca1BMK0.js";import{t as F}from"./hard-drive-download-ClcxzAVo.js";import{$i as I,Al as L,Bn as R,Cn as ee,Ei as te,Er as ne,Gi as re,Gu as ie,Hi as ae,Hl as oe,Hr as z,Ja as se,Ji as ce,Ki as le,Qi as ue,Rn as de,Sn as fe,Tr as pe,Ui as me,Ul as he,Un as ge,Vl as _e,Vn as ve,Wi as ye,Wl as be,Wr as B,Xi as xe,Xu as Se,Yi as Ce,Zi as we,Zu as V,_r as Te,ct as Ee,dr as De,ea as Oe,fr as ke,ft as Ae,gr as je,hr as Me,mt as Ne,na as Pe,pr as Fe,pt as Ie,qi as Le,ra as Re,ru as ze,ta as Be,xt as H}from"./src-BVr0SnD-.js";import{t as U}from"./i18n-D3CF2V_j.js";import{t as W}from"./useTranslation-D3Is_4B6.js";import"./mount-yjEyEWyS.js";import{dr as Ve,lr as He,mr as Ue,x as We}from"./index-Cskol4XA.js";import{t as Ge}from"./AdminSectionedPage-DCas2jUy.js";import{t as Ke}from"./AdminPage-B-1YjUaD.js";import{n as qe}from"./authed-media-BWhmwHt2.js";import{t as G}from"./format-size-DIxKXxtj.js";import{a as Je,c as Ye,l as Xe,n as Ze,o as Qe,s as $e,t as et,u as tt}from"./location-owned-usage-ChLz8liX.js";e();function nt(){let{t:e}=W(),r=s(),i=z(),{data:o,isLoading:l,isError:u}=be({}),d=he(),f=n(()=>d.data??[],[d.data]),{data:p}=L({},{refetchOnWindowFocus:!1}),m=n(()=>et(o??[],p?.locations),[o,p?.locations]),{data:h}=oe({},{refetchOnWindowFocus:!1}),g=n(()=>Je(h),[h]),{state:_,openNew:v,openEdit:y,close:b}=Ae(),[x,S]=Ie(`type`),C=()=>{S(null),b()},w=e=>{S(e),v()},T=e=>{S(null),y(e.id)},E=o??[],D=_.mode===`edit`?E.find(e=>e.id===_.id)??null:null;t(()=>{_.mode===`new`&&(x===null||x===``)&&(S(null),b())},[_.mode,x,b,S]),t(()=>{_.mode===`edit`&&!l&&D===null&&(S(null),b())},[_.mode,l,D,b,S]),t(()=>{_.mode===`closed`&&x!==null&&S(null)},[_.mode,x,S]);let O=_e({onSuccess:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),k=ze({onSuccess:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),A=async(t,n)=>{Xe(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:Ye(n).consequence}),confirmLabel:e(`common.disable`,`Disable`),variant:`danger`})||k.mutate($e(t,{mode:n}))},j=async t=>{if(await i({title:e(`system.storage.deleteLocation`,`Delete location "{{displayName}}"?`,{displayName:t.displayName}),message:e(`system.storage.thisRemovesTheLocationRecord`,`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`}))try{await O.mutateAsync({id:t.id}),_.mode===`edit`&&_.id===t.id&&C()}catch(n){await i({title:e(`system.storage.deleteAnyway`,`Delete anyway?`),message:e(`system.storage.forcingNote`,{error:n instanceof Error?n.message:String(n)}),confirmLabel:e(`system.storage.forceDelete`,`Force delete`),variant:`danger`})&&O.mutate({id:t.id,force:!0},{onSuccess:()=>{_.mode===`edit`&&_.id===t.id&&C()}})}},M=n(()=>{let e=new Map;for(let t of o??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[o]),N=l||d.isLoading,P=u||d.isError,F=_.mode===`new`&&x!==null&&x!==``,I=_.mode===`edit`&&D!==null;return a(Ke,{embedded:!0,children:[N&&c(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:e(`system.storage.loadingLocations`,`Loading locations…`)}),P&&c(`div`,{className:`text-xs text-danger`,children:e(`system.storage.failedToLoadStorageLocations`,`Failed to load storage locations.`)}),!N&&!P&&a(`div`,{className:`space-y-3`,children:[f.length===0&&c(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:e(`system.storage.noStorageLocationsDeclaredBy`,`No storage locations declared by any installed addon.`)}),f.map(e=>c(Ze,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:M.get(e.id)??[],onAdd:w,onEdit:T,onDelete:e=>{j(e)},ownedBytesById:m,drainById:g,onSetMode:(e,t)=>{A(e,t)}},e.id))]}),F&&x!==null&&c(tt,{initialType:x,onClose:C,onCreated:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),C()}}),I&&D!==null&&c(Qe,{location:D,onClose:C,onSaved:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),C()}})]})}var K={settings:{labelKey:`helpers.backupDatabases.settings.label`,descriptionKey:`helpers.backupDatabases.settings.description`,shortKey:`helpers.backupDatabases.settings.short`},events:{labelKey:`helpers.backupDatabases.events.label`,descriptionKey:`helpers.backupDatabases.events.description`,shortKey:`helpers.backupDatabases.events.short`},history:{labelKey:`helpers.backupDatabases.history.label`,descriptionKey:`helpers.backupDatabases.history.description`,shortKey:`helpers.backupDatabases.history.short`}},rt=Object.keys(K),q=[`settings`];function it(){return U.t(`helpers.backupDatabases.notCreated`)}function at(e){return U.t(K[e].labelKey)}function ot(e){return U.t(K[e].shortKey)}function st(e){return U.t(K[e].descriptionKey)}function J(e){let t=new Set(e);return rt.filter(e=>t.has(e))}function Y(e){return e!==void 0&&e.length>0?J(e):q}function ct(e){return J(e)}function lt(e,t){return t===void 0||!t.answered?`unknown`:t.databases.includes(e)?`present`:`absent`}function ut(e,t,n){return lt(e,t)===`absent`&&!n.has(e)}function dt(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function ft(e){return!e.includes(`settings`)}function pt(e){return{databases:[...ct(e)]}}function mt(e,t){return e!==void 0&&e.length>0?J(e):t!==void 0&&t.length>0?J(t.map(e=>e.databaseId??`settings`)):q}function X({databases:e}){return c(`span`,{className:`text-xs font-medium uppercase tracking-wide text-foreground-muted`,"data-testid":`backup-database-badges`,children:e.map(e=>ot(e)).join(` · `)})}e();var ht=[[`backup`,`listDestinations`]],gt=[`backup`,`listArchives`];function _t({destinationId:e,restoreSupported:t,onOpenRestoreWizard:o}){let{t:l}=W(),u=s(),d=z(),{data:f,isLoading:m,isError:h}=ce({destinationId:e}),g=f??[],v=me({onSuccess:()=>{u.invalidateQueries({queryKey:[[...gt]]}),u.invalidateQueries({queryKey:ht})}}),y=i(async t=>{await d({title:l(`backup.archiveList.deleteThisArchive`,`Delete this archive?`),message:l(`backup.archiveList.permanentlyDeletesAndFrees`,`Permanently deletes "{{value1}}" and frees {{value2}}.`,{value1:t.label??t.id,value2:G(t.sizeBytes)}),confirmLabel:l(`common.delete`,`Delete`),variant:`danger`})&&v.mutate({destinationId:e,backupId:t.id})},[d,e,v,l]),[b,x]=r(null),S=i(async t=>{x(t.id);try{let n=await qe(vt(e,t.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${t.label??t.id}.tar.gz${t.encryption===void 0?``:`.csbk`}`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{x(null)}},[e]),C=n(()=>[...g].toSorted((e,t)=>t.createdAt-e.createdAt),[g]);return m?c(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:l(`backup.archiveList.loadingArchives`,`Loading archives…`)}):h?c(`div`,{className:`text-xs text-danger py-2`,children:l(`backup.archiveList.failedToReadManifestFor`,`Failed to read manifest for this destination`)}):C.length===0?c(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:l(`backup.archiveList.noArchivesAtThisDestination`,`No archives at this destination yet.`)}):c(fe,{columns:[{key:`when`,header:l(`backup.archiveList.when`,`When`),sortValue:e=>e.createdAt,render:e=>c(`span`,{className:`tabular-nums`,children:yt(e.createdAt)})},{key:`label`,header:l(`backup.archiveList.label`,`Label`),sortValue:e=>e.label??null,render:e=>a(`span`,{className:`inline-flex items-center gap-1`,children:[e.encryption!==void 0&&c(D,{className:`h-3 w-3 text-success`,"aria-label":l(`backup.archiveList.encryptedRestoreNeedsBackupKey`,`encrypted — restore needs backup key {{keyId}}`,{keyId:e.encryption.keyId})}),e.label??c(`span`,{className:`text-foreground-subtle italic`,children:`—`})]})},{key:`databases`,header:l(`backup.archiveList.databases`,`Databases`),nowrap:!1,notSortableReason:`Database badges`,render:e=>c(X,{databases:Y(e.databases)})},{key:`includes`,header:l(`backup.archiveList.files`,`Files`),nowrap:!1,notSortableReason:`Location list`,render:e=>e.locations.length>0?c(`span`,{className:`text-foreground-subtle`,children:e.locations.join(`, `)}):c(`span`,{className:`text-foreground-subtle italic`,children:l(`common.none`)})},{key:`size`,header:l(`backup.archiveList.size`,`Size`),align:`right`,sortValue:e=>e.sizeBytes,render:e=>c(`span`,{className:`tabular-nums`,children:G(e.sizeBytes)})},{key:`actions`,header:``,align:`right`,notSortableReason:`Actions`,render:n=>a(`span`,{className:`flex items-center justify-end gap-1`,children:[a(B,{variant:`ghost`,size:`sm`,onClick:()=>{S(n)},disabled:b===n.id,title:l(`backup.archiveList.downloadArchive`,`Download archive`),children:[b===n.id?c(T,{className:`h-3 w-3 animate-spin`}):c(_,{className:`h-3 w-3`}),l(`backup.archiveList.download`,`Download`)]}),t&&o&&a(B,{variant:`ghost`,size:`sm`,onClick:()=>o({destinationId:e,archiveId:n.id}),title:l(`backup.archiveList.restoreFromThisArchive`,`Restore from this archive`),children:[c(k,{className:`h-3 w-3`}),l(`backup.archiveList.restore`,`Restore`)]}),c(V,{variant:`ghost`,size:`sm`,icon:p,"aria-label":l(`backup.archiveList.delete`,`Delete {{value1}}`,{value1:n.label??n.id}),disabled:v.isPending,onClick:()=>{y(n)}})]})}],rows:C,rowKey:e=>e.id,minWidthPx:760,emptyMessage:l(`backup.archiveList.noArchivesAtThisDestination`,`No archives at this destination yet.`)})}function vt(e,t){return g(`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}function yt(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}e();var Z=[[`backup`,`listSchedules`]];function bt({onEdit:e,onOpenRestoreWizard:t}){let{t:o}=W(),{data:s,isLoading:l,isError:u,error:d,refetch:f}=ue(),p=s??[],m=xe().data??[],h=n(()=>{let e=new Map;for(let t of m)e.set(t.id,t);return e},[m]),[g,_]=r(null),v=i(e=>{_(t=>t===e?null:e)},[]),y=n(()=>xt({destById:h,expandedId:g,onToggleExpand:v,onEdit:e}),[h,g,v,e]);return l?a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle animate-pulse`,children:[c(T,{className:`h-3.5 w-3.5 animate-spin`}),o(`backup.backupEntriesTable.loadingBackupEntries`,`Loading backup entries…`)]}):u?c(pe,{title:o(`backup.backupEntriesTable.failedToLoadBackupEntries`,`Failed to load backup entries`),message:d instanceof Error?d.message:o(`backup.backupEntriesTable.unknownError`,`Unknown error`),onRetry:()=>void f()}):p.length===0?c(ne,{icon:M,title:o(`backup.backupEntriesTable.noBackupEntriesYet`,`No backup entries yet`),description:o(`backup.backupEntriesTable.createOneToScheduleBackups`,`Create one to schedule backups across one or more storage locations.`)}):c(fe,{columns:y,rows:p,rowKey:e=>e.id,minWidthPx:980,maxBodyHeight:ee,emptyMessage:o(`backup.backupEntriesTable.noBackupEntriesYet`,`No backup entries yet`),onRowClick:t=>e(t),isExpanded:e=>e.id===g,renderExpanded:e=>c(Ot,{row:e,destById:h,...t?{onOpenRestoreWizard:t}:{}})})}function xt(e){return[{key:`expand`,header:``,width:`w-8`,nowrap:!0,notSortableReason:`Expand control`,render:t=>{let n=e.expandedId===t.id;return c(V,{variant:`ghost`,size:`sm`,icon:n?A:j,"aria-label":n?U.t(`backup.backupEntriesTable.hideArchives`,`Hide archives`):U.t(`backup.backupEntriesTable.showArchives`,`Show archives`),"aria-expanded":n,onClick:n=>{n.stopPropagation(),e.onToggleExpand(t.id)}})}},{key:`entry`,header:U.t(`backup.backupEntriesTable.entry`,`Entry`),sortValue:e=>e.label,render:e=>a(`span`,{className:`flex min-w-0 flex-col`,children:[c(`span`,{className:`truncate font-medium text-foreground`,children:e.label||U.t(`backup.backupEntriesTable.unnamed`,`(unnamed)`)}),e.lastRunAt!==void 0&&c(`span`,{className:`text-[10px] text-foreground-subtle`,children:U.t(`backup.backupEntriesTable.lastRun`,{when:new Date(e.lastRunAt).toLocaleString()})})]})},{key:`enabled`,header:U.t(`backup.backupEntriesTable.enabled`,`Enabled`),width:`w-20`,nowrap:!0,sortValue:e=>+!!e.enabled,render:e=>c(`span`,{onClick:e=>e.stopPropagation(),children:c(Tt,{row:e})})},{key:`databases`,header:U.t(`backup.backupEntriesTable.backsUp`,`Backs up`),nowrap:!1,notSortableReason:`Database badges`,render:e=>c(X,{databases:Y(e.databases)})},{key:`locations`,header:U.t(`backup.backupEntriesTable.locations`,`Locations`),nowrap:!1,notSortableReason:`Location chips`,render:t=>c(St,{row:t,destById:e.destById})},{key:`retention`,header:U.t(`backup.backupEntriesTable.retention`,`Retention`),width:`w-24`,nowrap:!0,sortValue:e=>e.retentionCount,render:e=>c(`span`,{onClick:e=>e.stopPropagation(),children:c(Et,{row:e})})},{key:`schedule`,header:U.t(`backup.backupEntriesTable.schedule`,`Schedule`),width:`w-48`,nowrap:!0,sortValue:e=>e.cron,render:e=>c(Ct,{row:e})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:t=>c(`span`,{onClick:e=>e.stopPropagation(),children:c(Dt,{row:t,onEdit:()=>e.onEdit(t)})})}]}function St({row:e,destById:t}){let{t:n}=W();return e.locationIds.length===0?c(`span`,{className:`text-[11px] italic text-danger`,children:n(`backup.backupEntriesTable.noLocations`,`No locations`)}):c(`span`,{className:`flex flex-wrap gap-1`,children:e.locationIds.map(e=>c(`span`,{className:`inline-flex items-center rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-foreground`,title:e,children:t.get(e)?.displayName??e},e))})}function Ct({row:e}){let{t}=W(),n=e.cron.trim().length>0;return a(`span`,{className:`flex flex-col items-start gap-0.5`,children:[a(`span`,{className:`inline-flex items-center gap-1`,children:[c(M,{className:`h-3 w-3 text-foreground-subtle`}),c(`span`,{className:`font-mono text-[11px] text-foreground`,children:n?e.cron:t(`backup.backupEntriesTable.manual`,`Manual`)})]}),n&&e.nextRunAt!==void 0&&c(`span`,{className:`text-[10px] text-foreground-subtle`,children:U.t(`common.nextRun`,{when:new Date(e.nextRunAt).toLocaleString()})})]})}function wt(e){return n(()=>({id:e.id,label:e.label,cron:e.cron,locationIds:[...e.locationIds],retentionCount:e.retentionCount,...e.dataSources?{dataSources:[...e.dataSources]}:{},...e.databases?{databases:[...e.databases]}:{}}),[e])}function Tt({row:e}){let{t}=W(),n=s(),r=Re({onSuccess:()=>{n.invalidateQueries({queryKey:Z})}}),i=wt(e);return c(`label`,{className:`inline-flex cursor-pointer items-center`,children:c(`input`,{type:`checkbox`,className:`accent-primary`,checked:e.enabled,disabled:r.isPending,onChange:e=>r.mutate({...i,enabled:e.target.checked}),"aria-label":t(`backup.backupEntriesTable.enable`,`Enable {{value1}}`,{value1:e.label||e.id})})})}function Et({row:e}){let{t:n}=W(),i=s(),a=Re({onSuccess:()=>{i.invalidateQueries({queryKey:Z})}}),o=wt(e),[l,u]=r(String(e.retentionCount));return t(()=>{u(String(e.retentionCount))},[e.retentionCount]),c(Se,{type:`number`,min:1,max:1e3,value:l,disabled:a.isPending,onChange:e=>u(e.target.value),onBlur:()=>{let t=Number.parseInt(l,10);if(Number.isNaN(t)||t<1){u(String(e.retentionCount));return}t!==e.retentionCount&&a.mutate({...o,enabled:e.enabled,retentionCount:t})},onKeyDown:t=>{t.key===`Enter`&&t.target.blur(),t.key===`Escape`&&u(String(e.retentionCount))},className:`w-16`,"aria-label":n(`backup.backupEntriesTable.retentionFor`,`Retention for {{value1}}`,{value1:e.label||e.id})})}function Dt({row:e,onEdit:t}){let{t:n}=W(),r=s(),i=z(),o=ye({onSuccess:()=>{r.invalidateQueries({queryKey:Z})}}),u=Pe({onMutate:()=>{r.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{r.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),r.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),r.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})}}),f=()=>{e.locationIds.length!==0&&u.mutate({destinations:[...e.locationIds],...e.dataSources&&e.dataSources.length>0?{locations:[...e.dataSources]}:{},label:e.label,retentionCount:e.retentionCount,databases:[...Y(e.databases)]})},m=async()=>{await i({title:n(`backup.backupEntriesTable.deleteBackupEntry`,`Delete backup entry?`),message:n(`backup.backupEntriesTable.willStopRunningExistingArchives`,`"{{value1}}" will stop running. Existing archives are kept.`,{value1:e.label||e.id}),confirmLabel:n(`common.delete`,`Delete`),variant:`warning`})&&o.mutate({id:e.id})};return a(`span`,{className:`flex items-center justify-end gap-1.5`,children:[a(B,{size:`sm`,type:`button`,onClick:f,disabled:u.isPending||e.locationIds.length===0,title:n(`backup.backupEntriesTable.runThisEntryNow`,`Run this entry now`),children:[u.isPending?c(T,{className:`h-3 w-3 animate-spin`}):c(l,{className:`h-3 w-3`}),n(`backup.backupEntriesTable.runNow`,`Run now`)]}),c(V,{variant:`ghost`,size:`sm`,icon:d,"aria-label":n(`backup.backupEntriesTable.edit`,`Edit {{value1}}`,{value1:e.label||e.id}),onClick:t}),c(V,{variant:`ghost`,size:`sm`,icon:p,"aria-label":n(`backup.backupEntriesTable.delete`,`Delete {{value1}}`,{value1:e.label||e.id}),disabled:o.isPending,onClick:()=>{m()}})]})}function Ot({row:e,destById:t,onOpenRestoreWizard:n}){let{t:r}=W();return a(`div`,{className:`space-y-4 rounded-lg border border-border bg-background/30 px-4 py-3`,children:[c(`p`,{className:`text-[11px] font-medium text-foreground-subtle`,children:r(`backup.backupEntriesTable.archivesFor`,{name:e.label||e.id})}),e.locationIds.length===0&&c(`p`,{className:`text-xs italic text-foreground-subtle`,children:r(`backup.backupEntriesTable.thisEntryHasNoLocations`,`This entry has no locations selected.`)}),e.locationIds.map(e=>a(`div`,{className:`space-y-1.5`,children:[c(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:t.get(e)?.displayName??e}),c(_t,{destinationId:e,restoreSupported:t.get(e)?.restoreSupported??!0,...n?{onOpenRestoreWizard:n}:{}})]},e))]})}function kt({selected:e,onChange:t,disabled:n=!1,testId:r=`backup-databases`}){let{t:i}=W(),o=Ce().data,s=e.size>0&&ft(J(e)),l=e.size===0?`Pick at least one.`:s?`Snapshots only: configuration and files are not part of this backup.`:null;return c(H,{label:i(`backup.backupDatabasePicker.whatToBackUp`,`What to back up`),required:!0,...l===null?{}:{description:l},children:c(`div`,{className:`divide-y divide-border rounded border border-border bg-background`,"data-testid":r,children:rt.map(i=>{let s=lt(i,o),l=n||ut(i,o,e);return a(`label`,{className:`flex items-start gap-2 px-3 py-2 text-xs ${l?`opacity-60`:`cursor-pointer hover:bg-primary/5`}`,children:[c(ge,{checked:e.has(i),disabled:l,onChange:()=>t(dt(e,i)),"data-testid":`${r}-${i}`}),a(`span`,{className:`min-w-0 flex-1`,children:[c(`span`,{className:`flex flex-wrap items-center gap-1.5 text-foreground`,children:at(i)}),c(`span`,{className:`block text-[11px] text-foreground-subtle`,children:s===`absent`?it():st(i)})]})]},i)})})})}e();function At({onClose:e}){let{t}=W(),n=s(),[i,o]=r(new Set(q)),u=Pe({onMutate:()=>{n.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{n.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),n.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),n.invalidateQueries({queryKey:[[`backup`,`listRuns`]]}),e()}});return c(De,{open:!0,onOpenChange:t=>!t&&e(),children:a(Fe,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(je,{children:[c(Te,{children:t(`backup.backupNowDialog.backUpNow`,`Back up now`)}),c(`p`,{className:`text-xs text-foreground-subtle`,children:t(`backup.backupNowDialog.runsOnceAndWritesThe`,`Runs once and writes the archive to every enabled backup location.`)})]}),c(ke,{children:a(`div`,{className:`p-4`,children:[c(kt,{selected:i,onChange:o,disabled:u.isPending,testId:`backup-now-databases`}),u.error&&c(`p`,{role:`alert`,className:`pt-2 text-xs text-danger`,children:u.error.message})]})}),a(Me,{children:[c(B,{variant:`outline`,size:`sm`,onClick:e,children:t(`common.cancel`,`Cancel`)}),a(B,{size:`sm`,onClick:()=>{i.size!==0&&u.mutate(pt(i))},disabled:i.size===0||u.isPending,"data-testid":`backup-now-run`,children:[u.isPending?c(T,{className:`h-3.5 w-3.5 animate-spin`}):c(l,{className:`h-3.5 w-3.5`}),t(`backup.backupNowDialog.backUpNow`,`Back up now`)]})]})]})})}e();function jt(e){return e===null?`—`:new Date(e).toLocaleString()}function Mt(e){let t=new Blob([`${e.secretKey}\n`],{type:`text/plain`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`camstack-backup-key-${e.keyId}.txt`,r.click(),URL.revokeObjectURL(n)}function Nt({revealed:e,onDone:t}){let{t:n}=W(),[i,o]=r(!1),[s,l]=r(!1);return c(De,{open:!0,onOpenChange:e=>!e&&i&&t(),children:a(Fe,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`border-danger/40`,"aria-labelledby":`backup-key-title`,children:[c(je,{children:c(Te,{id:`backup-key-title`,children:n(`backup.encryptionCard.yourKey`,{keyId:e.keyId})})}),a(ke,{className:`space-y-3`,children:[a(`p`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 p-2 text-xs text-foreground`,children:[c(h,{className:`mt-0.5 h-4 w-4 shrink-0 text-danger`}),c(`span`,{children:n(`backup.backupEncryptionCard.thisKeyIsShownOnly`,`This key is shown only once. CamStack does not keep it — not the hub, not its database, not its backups. Without it, an encrypted backup cannot be restored by anyone, including you. Store it in a password manager or print it, away from this server.`)})]}),c(`div`,{className:`break-all rounded-md border border-border bg-background p-2 font-mono text-xs text-foreground select-all`,children:e.secretKey}),a(`div`,{className:`flex flex-wrap gap-2`,children:[a(B,{size:`sm`,variant:`outline`,onClick:()=>{navigator.clipboard?.writeText(e.secretKey).then(()=>l(!0))},children:[c(b,{className:`mr-1 h-3.5 w-3.5`}),s?n(`backup.backupEncryptionCard.copied`,`Copied`):n(`common.copy`,`Copy`)]}),a(B,{size:`sm`,variant:`outline`,onClick:()=>Mt(e),children:[c(_,{className:`mr-1 h-3.5 w-3.5`}),n(`backup.backupEncryptionCard.downloadAsFile`,`Download as file`)]})]}),a(`label`,{className:`flex items-center gap-2 text-xs text-foreground`,children:[c(`input`,{type:`checkbox`,checked:i,onChange:e=>o(e.target.checked),className:`accent-primary`}),n(`backup.backupEncryptionCard.iHaveStoredThisKey`,`I have stored this key somewhere safe, off this server.`)]})]}),c(Me,{children:c(B,{size:`sm`,disabled:!i,onClick:t,children:n(`backup.backupEncryptionCard.iHaveStoredIt`,`I have stored it`)})})]})})}function Pt(){let{t:e}=W(),t=le(),n=Be(),i=re(),s=z(),[l,u]=r(null),[d,f]=r(null),p=t.data?.enabled??!1,m=t.data?.active??null,h=(t.data?.keys??[]).filter(e=>e.retiredAt!==null),g=async()=>{if(await s({title:p?e(`backup.backupEncryptionCard.replaceTheBackupKey`,`Replace the backup key`):e(`backup.backupEncryptionCard.encryptBackups`,`Encrypt backups`),message:p?e(`backup.backupEncryptionCard.aNewKeyIsGenerated`,`A new key is generated and shown once; new backups are encrypted to it. Older backups keep needing the key they were made with — keep that one too.`):e(`backup.backupEncryptionCard.aBackupKeyIsGenerated`,`A backup key is generated and shown once. Every new backup is encrypted to it, and restoring one will ask for it. Existing backups stay as they are.`),confirmLabel:p?e(`backup.backupEncryptionCard.generateANewKey`,`Generate a new key`):e(`backup.backupEncryptionCard.generateTheKey`,`Generate the key`),variant:`warning`})){f(null);try{let e=await n.mutateAsync({});u({keyId:e.keyId,secretKey:e.secretKey})}catch(e){f(e instanceof Error?e.message:String(e))}}},_=async()=>{if(await s({title:e(`backup.backupEncryptionCard.turnBackupEncryptionOff`,`Turn backup encryption off`),message:e(`backup.backupEncryptionCard.newBackupsWillBeWritten`,`New backups will be written unencrypted. Existing encrypted backups still need their key to be restored.`),confirmLabel:e(`backup.backupEncryptionCard.turnOff`,`Turn off`),variant:`danger`})){f(null);try{await i.mutateAsync({}),t.refetch()}catch(e){f(e instanceof Error?e.message:String(e))}}};return a(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-4`,children:[a(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[a(`div`,{className:`flex items-center gap-2`,children:[p?c(D,{className:`h-4 w-4 text-success`}):c(C,{className:`h-4 w-4 text-foreground-subtle`}),c(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`backup.backupEncryptionCard.encryption`,`Encryption`)}),c(`span`,{className:`text-xs text-foreground-subtle`,children:p&&m!==null?e(`backup.backupEncryptionCard.onKeySince`,`On — key {{keyId}}, since {{value2}}`,{keyId:m.keyId,value2:jt(m.createdAt)}):e(`backup.backupEncryptionCard.offBackupsAreNotEncrypted`,`Off — backups are not encrypted`)})]}),c(`div`,{className:`flex gap-2`,children:p?a(o,{children:[c(B,{size:`sm`,variant:`outline`,disabled:n.isPending,onClick:()=>void g(),children:e(`backup.backupEncryptionCard.replaceKey`,`Replace key`)}),c(B,{size:`sm`,variant:`outline`,disabled:i.isPending,onClick:()=>void _(),children:e(`backup.backupEncryptionCard.turnOff`,`Turn off`)})]}):c(B,{size:`sm`,disabled:n.isPending,onClick:()=>void g(),children:e(`backup.backupEncryptionCard.enableEncryption`,`Enable encryption`)})})]}),c(`p`,{className:`text-xs text-foreground-subtle`,children:e(`backup.backupEncryptionCard.archivesAreEncryptedOnThis`,`Archives are encrypted on this server before they reach any destination. The server keeps only a public key, so it can encrypt scheduled backups but cannot decrypt them — only your backup key can. Covers the database snapshot, config.yaml, addon data (HomeKit pairing, Matter fabric, Tailscale state) and TLS.`)}),h.length>0&&a(`div`,{className:`text-xs`,children:[c(`p`,{className:`text-foreground-subtle`,children:e(`backup.backupEncryptionCard.olderKeysBackupsMadeWith`,`Older keys (backups made with them still need them):`)}),c(`ul`,{className:`font-mono text-foreground`,children:h.map(e=>a(`li`,{children:[e.keyId,` · `,jt(e.createdAt),` → `,jt(e.retiredAt)]},e.keyId))})]}),d!==null&&c(`p`,{className:`text-xs text-danger`,children:d}),l!==null&&c(Nt,{revealed:l,onDone:()=>{u(null),t.refetch()}})]})}e();var Ft=[{id:`manual`,labelKey:`backup.cronEditor.presetManual`,cron:``},{id:`hourly`,labelKey:`backup.cronEditor.presetHourly`,cron:`0 * * * *`,descriptionKey:`backup.cronEditor.presetHourlyDesc`},{id:`every-3h`,labelKey:`backup.cronEditor.preset3h`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,labelKey:`backup.cronEditor.preset6h`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,labelKey:`backup.cronEditor.presetDaily`,cron:`0 3 * * *`,descriptionKey:`backup.cronEditor.presetDailyDesc`},{id:`weekly-sun`,labelKey:`backup.cronEditor.presetWeekly`,cron:`0 3 * * 0`,descriptionKey:`backup.cronEditor.presetWeeklyDesc`}];function It(e){let t=e.trim();for(let e of Ft)if(e.cron===t)return e.id;return`custom`}function Lt({value:e,onChange:n,previewCount:i=5,disabled:o=!1}){let{t:s}=W(),l=It(e),[u,d]=r(l===`custom`);t(()=>{l!==`custom`&&d(!1)},[l]);let f=Bt(e,250),p=I({cron:f,count:i},{enabled:f.trim().length>0}),m=p.data??null,h=e=>{d(!1),n(e.cron)},g=u||l===`custom`;return a(`div`,{className:`space-y-3`,children:[a(`div`,{className:`space-y-1`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:s(`backup.cronEditor.schedulePreset`,`Schedule preset`)}),a(`div`,{className:`flex flex-wrap gap-1.5`,children:[Ft.map(e=>c(`button`,{type:`button`,onClick:()=>h(e),disabled:o,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!u&&l===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.descriptionKey===void 0?e.description??s(e.labelKey):s(e.descriptionKey),children:s(e.labelKey)},e.id)),c(`button`,{type:`button`,onClick:()=>{d(!0),e.trim().length===0&&n(`0 3 * * *`)},disabled:o,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(g?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:s(`backup.cronEditor.custom`,`Custom…`)})]})]}),g&&a(`div`,{className:`space-y-1`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:s(`backup.cronEditor.cronExpression5FieldPosix`,`Cron expression (5-field POSIX)`)}),c(`input`,{type:`text`,value:e,onChange:e=>n(e.target.value),disabled:o,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),a(`p`,{className:`text-[10px] text-foreground-subtle`,children:[s(`backup.cronEditor.format`,`Format:`),` `,c(He,{i18nKey:`backup.cronEditor.formatLine`,components:{code:c(`span`,{className:`font-mono`})}})]})]}),c(Rt,{cron:f,preview:m,loading:p.isFetching})]})}function Rt({cron:e,preview:t,loading:n}){let{t:r}=W();return n&&t===null?a(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[c(T,{className:`h-3 w-3 animate-spin`}),r(`backup.cronEditor.validating`,`Validating…`)]}):t===null?null:t.ok?t.nextRuns.length===0?c(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:r(`backup.cronEditor.noFutureRunsMatchThis`,`No future runs match this expression.`)}):a(`div`,{className:`space-y-1`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:r(`backup.cronEditor.nextRuns`,`Next runs`)}),c(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>a(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[c(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),c(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:zt(e)})]},`${e}-${t}`))})]}):c(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??r(`backup.cronEditor.invalidCronExpression`,`Invalid cron expression`)})}function zt(e){let t=e-Date.now();if(t<=0)return U.t(`helpers.relativeTime.now`);let n=Math.floor(t/1e3);if(n<60)return U.t(`helpers.relativeTime.inSeconds`,{count:n});let r=Math.floor(n/60);if(r<60)return U.t(`helpers.relativeTime.inMinutes`,{count:r});let i=Math.floor(r/60);if(i<24)return U.t(`helpers.relativeTime.inHours`,{count:i});let a=Math.floor(i/24);return U.t(`helpers.relativeTime.inDays`,{count:a})}function Bt(e,i){let[a,o]=r(e),s=n(()=>e,[e]);return t(()=>{let e=setTimeout(()=>o(s),i);return()=>clearTimeout(e)},[s,i]),a}e();var Vt=[[`backup`,`listSchedules`]];function Ht({entry:e,onClose:t,onSaved:i}){let{t:o}=W(),l=s(),u=xe(),d=u.data??[],[f,p]=r(e?.label??``),[m,h]=r(e?.cron??`0 3 * * *`),[g,_]=r(e?.enabled??!0),[v,y]=r(String(e?.retentionCount??7)),[b,x]=r(new Set(e?.locationIds??[])),[S,C]=r(new Set(e===null?q:Y(e.databases))),w=Re({onSuccess:()=>{l.invalidateQueries({queryKey:Vt}),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=n(()=>f.trim().length>0&&b.size>0&&S.size>0&&!Number.isNaN(D)&&D>=1&&D<=1e3,[f,b,S,D]),k=()=>{O&&w.mutate({...e?{id:e.id}:{},label:f.trim(),cron:m.trim(),enabled:g,locationIds:Array.from(b),retentionCount:D,databases:[...ct(S)]})},A=w.error instanceof Error?w.error.message:null;return c(Ne,{open:!0,onClose:t,title:e?o(`backup.backupEntryModal.editBackupEntry`,`Edit backup entry`):o(`backup.backupEntryModal.newBackupEntry`,`New backup entry`),icon:M,error:A,width:`lg`,testId:`backup-entry-form`,footer:a(B,{size:`sm`,type:`button`,onClick:k,disabled:!O||w.isPending,children:[w.isPending?c(T,{className:`h-3.5 w-3.5 animate-spin`}):null,e?o(`common.save`,`Save`):o(`backup.backupEntryModal.createEntry`,`Create entry`)]}),children:a(`div`,{className:`space-y-4`,children:[c(H,{label:o(`backup.backupEntryModal.name`,`Name`),required:!0,children:c(Se,{value:f,onChange:e=>p(e.target.value),placeholder:o(`backup.backupEntryModal.nightlyOffsite`,`Nightly offsite`),autoFocus:!0,"data-testid":`backup-entry-name`})}),a(H,{label:o(`backup.backupEntryModal.locationsSelected`,`Locations ({{value1}} selected)`,{value1:String(b.size)}),required:!0,children:[u.isLoading&&a(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[c(T,{className:`h-3.5 w-3.5 animate-spin`}),o(`backup.backupEntryModal.loadingLocations`,`Loading locations…`)]}),!u.isLoading&&d.length===0&&c(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:o(`backup.backupEntryModal.noBackupsStorageLocationsConfigured`,"No `backups` storage locations configured. Add one in Settings → Storage first.")}),d.length>0&&c(`div`,{className:`max-h-52 divide-y divide-border overflow-y-auto rounded border border-border bg-background`,children:d.map(e=>a(`label`,{className:`flex cursor-pointer items-center justify-between px-3 py-2 text-xs hover:bg-primary/5`,children:[a(`div`,{className:`flex items-center gap-2`,children:[c(`input`,{type:`checkbox`,checked:b.has(e.id),onChange:()=>E(e.id),className:`accent-primary`}),c(`span`,{className:`text-foreground`,children:e.displayName})]}),a(`div`,{className:`flex items-center gap-1.5`,children:[c(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e.kind}),c(`span`,{className:`font-mono text-[10px] text-foreground-subtle`,children:e.id})]})]},e.id))})]}),c(kt,{selected:S,onChange:C,disabled:w.isPending,testId:`backup-entry-databases`}),a(`div`,{className:`grid grid-cols-2 gap-3`,children:[c(H,{label:o(`backup.backupEntryModal.retentionArchivesKept`,`Retention (archives kept)`),required:!0,children:c(Se,{type:`number`,min:1,max:1e3,value:v,onChange:e=>y(e.target.value),"data-testid":`backup-entry-retention`})}),c(H,{label:o(`backup.backupEntryModal.enabled`,`Enabled`),description:o(`backup.backupEntryModal.runOnScheduleWhenChecked`,`Run on schedule when checked.`),children:a(`label`,{className:`inline-flex cursor-pointer items-center gap-2 py-1.5 text-xs text-foreground`,children:[c(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`accent-primary`,"data-testid":`backup-entry-enabled`}),c(`span`,{children:o(`backup.backupEntryModal.runOnSchedule`,`Run on schedule`)})]})})]}),c(H,{label:o(`backup.backupEntryModal.schedule`,`Schedule`),children:c(Lt,{value:m,onChange:h,disabled:w.isPending})})]})})}e();var Ut=2e3,Wt=5e3;function Q(e){return e.state===`queued`||e.state===`running`}function Gt(e){if(e.state===`queued`)return{title:U.t(`backup.backupRunsPanel.cancelQueuedBackupRun`,`Cancel queued backup run?`),message:U.t(`backup.backupRunsPanel.thisRunHasNotStarted`,`This run has not started. Cancelling removes it from the queue — nothing has been written, nothing is deleted.`),confirmLabel:U.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:U.t(`backup.backupRunsPanel.stopThisBackupRun`,`Stop this backup run?`),message:U.t(`backup.backupRunsPanel.theHalfWrittenStagingArchive`,`The half-written staging archive is deleted and the destination currently uploading discards its partial copy. {{keptSentence}}`,{keptSentence:n}),confirmLabel:U.t(`backup.backupRunsPanel.stopRun`,`Stop run`),variant:`danger`}}function Kt(){let e=z(),[t,n]=r(null),a=we(void 0,{refetchInterval:e=>(e.state.data??[]).some(Q)?Ut:Wt}),o=ae({onSettled:()=>{n(null),a.refetch()}}),s=i(async t=>{await e(Gt(t))&&(n(t.id),o.mutate({runId:t.id}))},[e,o]);return c(qt,{queryState:a.isError?`error`:a.data===void 0?`pending`:`ready`,runs:a.data??[],cancelingId:t,onCancelRequest:e=>{s(e)},now:Date.now()})}function qt({queryState:e,runs:t,cancelingId:n,onCancelRequest:r,now:i}){let{t:o}=W(),s=e===`ready`&&t.some(Q),l=t.filter(e=>e.state===`running`),u=t.filter(e=>e.state===`queued`),d=t.filter(e=>!Q(e)),f=[...l,...u,...d];return a(`section`,{className:`rounded-lg border border-border bg-surface`,children:[a(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border`,children:[c(`h2`,{className:`text-xs font-semibold text-foreground`,children:o(`backup.backupRunsPanel.runs`,`Runs`)}),s&&a(`span`,{className:`inline-flex items-center gap-1 text-[10px] font-medium text-primary`,title:o(`backup.backupRunsPanel.aBackupRunIsIn`,`A backup run is in progress`),children:[c(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary animate-pulse`}),o(`backup.runsPanel.live`)]}),c(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:o(`backup.backupRunsPanel.oneRunExecutesAtA`,`One run executes at a time — queued runs wait in line.`)})]}),e===`pending`&&c(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle animate-pulse`,children:o(`backup.backupRunsPanel.checkingForBackupRuns`,`Checking for backup runs…`)}),e===`error`&&c(`div`,{className:`px-3 py-2.5 text-xs text-danger`,children:o(`backup.backupRunsPanel.couldNotReadBackupRuns`,`Could not read backup runs — the orchestrator did not answer.`)}),e===`ready`&&t.length===0&&c(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle italic`,children:o(`backup.backupRunsPanel.noBackupRunsYetRuns`,`No backup runs yet. Runs appear here the moment one starts — manual or scheduled.`)}),e===`ready`&&t.length>0&&c(`div`,{className:`overflow-x-auto`,children:a(`table`,{className:`w-full text-xs min-w-[720px]`,children:[c(`thead`,{children:a(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.run`,`Run`)}),c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.state`,`State`)}),c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.progress`,`Progress`)}),c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.destinations`,`Destinations`)}),c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.timing`,`Timing`)}),c(`th`,{className:`text-right px-3 py-1.5 font-medium w-28`,children:o(`backup.backupRunsPanel.actions`,`Actions`)})]})}),c(`tbody`,{children:f.map(e=>c(Jt,{run:e,canceling:n===e.id,onCancelRequest:r,now:i},e.id))})]})})]})}function Jt({run:e,canceling:t,onCancelRequest:n,now:r}){let{t:i}=W(),o=Q(e);return a(`tr`,{className:`border-t border-border hover:bg-primary/5 align-top`,children:[c(`td`,{className:`px-3 py-2`,children:c(`div`,{className:`text-foreground`,title:e.id,children:e.label??c(`span`,{className:`text-foreground-subtle italic`,children:i(`backup.runsPanel.manual`)})})}),a(`td`,{className:`px-3 py-2`,children:[c(Yt,{run:e}),e.state===`failed`&&e.error!==void 0&&c(`div`,{className:`mt-1 text-[10px] text-danger max-w-56 truncate`,title:e.error,children:e.error})]}),c(`td`,{className:`px-3 py-2`,children:c(Xt,{run:e})}),c(`td`,{className:`px-3 py-2`,children:c(Zt,{run:e})}),c(`td`,{className:`px-3 py-2 text-foreground-subtle tabular-nums`,children:c(Qt,{run:e,now:r})}),c(`td`,{className:`px-3 py-2`,children:c(`div`,{className:`flex justify-end`,children:o&&a(`button`,{onClick:()=>n(e),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:e.state===`queued`?i(`backup.backupRunsPanel.removeThisRunFromThe`,`Remove this run from the queue before it starts`):i(`backup.backupRunsPanel.stopThisRunTheHalf`,`Stop this run — the half-written archive is discarded`),children:[t?c(T,{className:`h-3 w-3 animate-spin`}):c(f,{className:`h-3 w-3`}),e.state===`queued`?i(`common.cancel`,`Cancel`):i(`backup.backupRunsPanel.stop`,`Stop`)]})})})]})}function Yt({run:e}){let{t}=W();switch(e.state){case`queued`:return a(`span`,{className:`inline-flex items-center gap-1 rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:[c(x,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.queued`,`Queued`)]});case`running`:return a(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`,children:[c(T,{className:`h-3 w-3 animate-spin`}),e.phase===`uploading`?t(`backup.backupRunsPanel.uploading`,`Uploading`):t(`backup.backupRunsPanel.buildingArchive`,`Building archive`)]});case`succeeded`:return a(`span`,{className:`inline-flex items-center gap-1 rounded bg-success/10 px-1.5 py-0.5 text-[10px] font-medium text-success`,children:[c(E,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.succeeded`,`Succeeded`)]});case`failed`:return a(`span`,{className:`inline-flex items-center gap-1 rounded bg-danger/10 px-1.5 py-0.5 text-[10px] font-medium text-danger`,children:[c(O,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.failed`,`Failed`)]});case`cancelled`:return a(`span`,{className:`inline-flex items-center gap-1 rounded bg-amber-500/10 px-1.5 py-0.5 text-[10px] font-medium text-amber-700 dark:text-amber-300`,title:t(`backup.backupRunsPanel.stoppedBeforeCompletingEveryDestination`,`Stopped before completing every destination — not a success`),children:[c(P,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.stopped`,`Stopped`)]})}}function Xt({run:e}){let{t}=W();if(e.state===`queued`)return c(`span`,{className:`text-foreground-subtle`,children:e.queuePosition===void 0?c(`span`,{className:`italic`,children:t(`backup.backupRunsPanel.waitingItsTurn`,`waiting its turn`)}):a(`span`,{className:`inline-flex items-center gap-1`,children:[c(`span`,{className:e.queuePosition===1?`rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`:`rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium`,children:$t(e.queuePosition)}),t(`backup.backupRunsPanel.inLine`,`in line`)]})});if(e.state===`running`&&e.phase===`building`)return a(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[c(F,{className:`h-3 w-3 text-primary`}),c(`span`,{className:`tabular-nums font-medium animate-pulse`,children:G(e.stagedBytes)}),c(`span`,{className:`text-foreground-subtle`,children:t(`backup.backupRunsPanel.stagedSoFar`,`staged so far`)})]});if(e.state===`running`){let n=e.archiveSizeBytes;return a(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[c(N,{className:`h-3 w-3 text-primary`}),a(`span`,{className:`tabular-nums font-medium`,children:[G(e.uploadedBytes),n===void 0?``:` / ${G(n)}`]}),c(`span`,{className:`text-foreground-subtle`,children:t(`backup.backupRunsPanel.toCurrentDestination`,`to current destination`)})]})}let n=e.archiveSizeBytes??(e.stagedBytes>0?e.stagedBytes:void 0);return n===void 0?c(`span`,{className:`text-foreground-subtle italic`,children:`—`}):c(`span`,{className:`tabular-nums text-foreground`,children:t(`backup.runsPanel.archiveSize`,{size:G(n)})})}function Zt({run:e}){let{t}=W(),n=e.destinationIds.length,r=e.completedDestinationIds.length,i=e.failedDestinationIds.length;return n===0?c(`span`,{className:`text-foreground-subtle italic`,children:t(`backup.backupRunsPanel.notResolvedYet`,`not resolved yet`)}):a(`div`,{className:`flex flex-col gap-0.5`,children:[c(`span`,{className:`text-foreground-subtle`,title:e.destinationIds.join(`, `),children:t(`backup.runsPanel.targets`,{count:n})}),a(`span`,{className:`inline-flex items-center gap-2 text-[10px]`,children:[r>0&&c(`span`,{className:`text-success`,title:t(`backup.backupRunsPanel.keptTheirArchive`,`Kept their archive: {{value1}}`,{value1:e.completedDestinationIds.join(`, `)}),children:t(`backup.runsPanel.completed`,{count:r})}),i>0&&c(`span`,{className:`text-danger`,title:t(`backup.backupRunsPanel.failed2`,`Failed: {{value1}}`,{value1:e.failedDestinationIds.join(`, `)}),children:t(`backup.runsPanel.failedCount`,{count:i})})]})]})}function Qt({run:e,now:t}){let{t:n}=W();return e.state===`queued`?c(`span`,{children:n(`backup.runsPanel.queuedAgo`,{elapsed:en(t-e.requestedAt)})}):e.startedAt===void 0?c(`span`,{children:`—`}):e.finishedAt===void 0?c(`span`,{children:n(`backup.runsPanel.runningFor`,{elapsed:en(t-e.startedAt)})}):a(`div`,{className:`flex flex-col gap-0.5`,children:[c(`span`,{children:tn(e.finishedAt)}),c(`span`,{className:`text-[10px]`,children:n(`backup.runsPanel.took`,{elapsed:en(e.finishedAt-e.startedAt)})})]})}function $t(e){if(e<=1)return`next`;let t=e%100;if(t>=11&&t<=13)return`${e}th`;switch(e%10){case 1:return`${e}st`;case 2:return`${e}nd`;case 3:return`${e}rd`;default:return`${e}th`}}function en(e){let t=Math.max(0,Math.floor(e/1e3));if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m ${String(t%60).padStart(2,`0`)}s`:`${Math.floor(n/60)}h ${String(n%60).padStart(2,`0`)}m`}function tn(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}e();var nn=[[`backup`,`list`]];function rn({initialDestinationId:e,initialArchiveId:i,onClose:o,onScheduled:l}){let{t:u}=W(),d=s(),[f,p]=r(e&&i?2:1),[m,h]=r(e),[g,_]=r(i),[b,x]=r(new Set),[S,C]=r(``),{data:w}=xe(),E=w??[],{data:D,isLoading:O}=ce({destinationId:m??``},{enabled:!!m}),A=D??[];t(()=>{if(m!==void 0)return;let e=E.filter(e=>e.restoreSupported);e.length===1&&h(e[0].id)},[m,E]);let{data:j}=Le({destinationId:m??``,backupId:g??``},{enabled:!!m&&!!g}),M=n(()=>j?.locations??[],[j]);t(()=>{M.length!==0&&x(e=>e.size===0?new Set(M):e)},[M]);let N=Oe({onSuccess:()=>{d.invalidateQueries({queryKey:nn}),l(),o()}}),P=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},F=A.find(e=>e.id===g),I=F?.encryption!==void 0,L=mt(F?.databases,j?.sqliteSnapshots),R=ft(L),ee=!!m&&!!g,te=R||b.size>0,ne=ee&&te&&!N.isPending&&(!I||S.trim().length>0),re=()=>{!m||!g||N.mutate({destinationId:m,backupId:g,...R?{}:{locations:[...b]},...I?{backupSecretKey:S.trim()}:{}})};return c(De,{open:!0,onOpenChange:e=>!e&&o(),children:a(Fe,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(je,{children:[c(Te,{children:u(`backup.restoreWizard.restoreBackup`,`Restore Backup`)}),c(`p`,{className:`text-xs text-foreground-subtle`,children:u(`backup.restoreWizard.stepOf`,{step:f,name:f===1?u(`backup.restoreWizard.pickSource`,`pick source`):f===2?u(`backup.restoreWizard.pickLocations`,`pick locations`):u(`backup.restoreWizard.confirmStep`)})})]}),a(ke,{children:[f===1&&c(an,{destinations:E,destinationId:m,onPickDestination:e=>{h(e),_(void 0),x(new Set)},archives:A,archivesLoading:O,archiveId:g,onPickArchive:_}),f===2&&c(on,{locations:M,picked:b,onToggle:P,databases:L,snapshotsOnly:R}),f===3&&c(sn,{destinationName:E.find(e=>e.id===m)?.displayName??m??``,archive:F,picked:[...b],databases:L,snapshotsOnly:R}),f===3&&F?.encryption!==void 0&&c(cn,{keyId:F.encryption.keyId,value:S,onChange:C}),f===3&&N.error&&c(`p`,{role:`alert`,className:`px-4 pb-2 text-xs text-danger`,children:N.error.message})]}),a(Me,{className:`justify-between`,children:[c(`div`,{children:f>1&&a(B,{variant:`outline`,size:`sm`,onClick:()=>p(e=>e===3?2:1),children:[c(v,{className:`h-3 w-3`}),u(`common.back`,`Back`)]})}),a(`div`,{className:`flex items-center gap-2`,children:[c(B,{variant:`outline`,size:`sm`,onClick:o,children:u(`common.cancel`,`Cancel`)}),f<3?a(B,{size:`sm`,disabled:f===1&&!ee||f===2&&!te,onClick:()=>p(e=>e===1?2:3),children:[u(`common.next`,`Next`),c(y,{className:`h-3 w-3`})]}):a(B,{size:`sm`,onClick:re,disabled:!ne,children:[N.isPending?c(T,{className:`h-3.5 w-3.5 animate-spin`}):c(k,{className:`h-3.5 w-3.5`}),u(`backup.restoreWizard.scheduleRestore`,`Schedule Restore`)]})]})]})]})})}function an({destinations:e,destinationId:t,onPickDestination:n,archives:r,archivesLoading:i,archiveId:o,onPickArchive:s}){let{t:l}=W(),u=e.filter(e=>e.restoreSupported);return a(`div`,{className:`p-4 space-y-3`,children:[a(`div`,{className:`space-y-1.5`,children:[c(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:l(`backup.restoreWizard.destination`,`Destination`)}),c(ie,{value:t??``,onChange:e=>n(e.target.value),options:[{value:``,label:l(`backup.restoreWizard.selectDestination`,`Select destination…`)},...u.map(e=>({value:e.id,label:`${e.displayName} (${e.kind})`}))]})]}),a(`div`,{className:`space-y-1.5`,children:[c(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:l(`backup.restoreWizard.archive`,`Archive`)}),!t&&c(`div`,{className:`text-xs text-foreground-subtle italic`,children:l(`backup.restoreWizard.pickADestinationFirst`,`Pick a destination first.`)}),t&&i&&c(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:l(`backup.restoreWizard.readingArchives`,`Reading archives…`)}),t&&!i&&r.length===0&&c(`div`,{className:`text-xs text-foreground-subtle italic`,children:l(`backup.restoreWizard.noArchivesAvailableAtThis`,`No archives available at this destination.`)}),t&&r.length>0&&c(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:r.map(e=>{let t=o===e.id;return a(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[a(`div`,{className:`flex items-center gap-2`,children:[c(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>s(e.id),className:`accent-primary`}),a(`div`,{children:[a(`div`,{className:`flex items-center gap-1 font-medium text-foreground`,children:[e.encryption!==void 0&&c(D,{className:`h-3 w-3 text-success`,"aria-label":l(`backup.restoreWizard.encryptedKey`,`encrypted (key {{keyId}})`,{keyId:e.encryption.keyId})}),e.label??e.id]}),c(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()}),c(`div`,{className:`pt-1`,children:c(X,{databases:mt(e.databases,void 0)})})]})]}),c(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:G(e.sizeBytes)})]},e.id)})})]})]})}function on({locations:e,picked:t,onToggle:n,databases:r,snapshotsOnly:i}){let{t:o}=W();return i?a(`div`,{className:`space-y-3 p-4`,children:[a(`div`,{className:`space-y-1.5`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:o(`backup.restoreWizard.databasesInThisArchive`,`Databases in this archive`)}),c(X,{databases:r})]}),c(`div`,{className:`rounded border border-info/30 bg-info/10 px-3 py-2 text-[11px] text-info`,children:o(`backup.restoreWizard.snapshotsOnlyRestoringThisArchive`,`Snapshots only: restoring this archive replaces just these databases. It does NOT touch configuration, addons, addon data or certificates.`)})]}):e.length===0?c(`div`,{className:`p-4`,children:c(`div`,{className:`text-xs text-foreground-subtle`,children:o(`backup.restoreWizard.loadingArchiveManifestIfThis`,`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`)})}):a(`div`,{className:`p-4 space-y-3`,children:[a(`div`,{className:`space-y-1.5`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:o(`backup.restoreWizard.databasesInThisArchive`,`Databases in this archive`)}),c(X,{databases:r})]}),c(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-[11px] text-warning`,children:o(`backup.restoreWizard.selectedEntriesWillOverwriteLive`,`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`)}),a(`div`,{className:`space-y-1.5`,children:[c(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:o(`common.apply`,`Apply`)}),c(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>a(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[c(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>n(e),className:`accent-primary`}),c(`span`,{className:`font-mono text-foreground`,children:e}),c(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:un(e)})]},e))})]})]})}function sn({destinationName:e,archive:t,picked:n,databases:r,snapshotsOnly:i}){let{t:o}=W();return a(`div`,{className:`p-4 space-y-3 text-xs`,children:[c(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-warning`,children:o(`backup.restoreWizard.restoreIsAppliedAtNext`,`Restore is applied at next server boot. Active connections will drop when you restart.`)}),a(`dl`,{className:`space-y-1.5`,children:[c($,{term:`Destination`,value:e}),c($,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&c($,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${G(t.sizeBytes)}`}),a(`div`,{className:`flex justify-between gap-3`,children:[c(`dt`,{className:`text-foreground-subtle`,children:o(`backup.restoreWizard.databases`,`Databases`)}),c(`dd`,{className:`text-right`,children:c(X,{databases:r})})]}),c($,{term:`Locations`,value:i?`none (configuration is not touched)`:n.length>0?n.join(`, `):`— (full archive)`})]})]})}function cn({keyId:e,value:t,onChange:n}){let{t:r}=W();return a(`div`,{className:`space-y-1.5 px-4 pb-3`,children:[c(`label`,{htmlFor:`restore-backup-key`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:r(`backup.restoreWizard.backupKey`,`Backup key`)}),c(`input`,{id:`restore-backup-key`,type:`password`,autoComplete:`off`,spellCheck:!1,value:t,onChange:e=>n(e.target.value),placeholder:r(`backup.restoreWizard.camstackBackupSecretV1`,`camstack-backup-secret-v1:…`),className:`w-full rounded border border-border bg-background px-2 py-1.5 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),c(`p`,{className:`text-[11px] text-foreground-subtle`,children:c(He,{i18nKey:`backup.restoreWizard.encryptedTo`,values:{keyId:e},components:{mono:c(`span`,{className:`font-mono`})}})})]})}function $({term:e,value:t}){return a(`div`,{className:`flex justify-between gap-3`,children:[c(`dt`,{className:`text-foreground-subtle`,children:e}),c(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var ln={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function un(e){return ln[e]??``}e();function dn(){let{t:e}=W(),n=z(),i=te(),{state:o,openNew:s,openEdit:u,close:d}=Ae({editKey:`edit`,newKey:`new`}),f=ue(),p=f.data??[],[m,h]=r(null),[g,_]=r(!1),[v,y]=r(!1),[b,x]=r(!1),S=o.mode===`edit`?p.find(e=>e.id===o.id)??null:null;t(()=>{o.mode===`edit`&&!f.isLoading&&S===null&&d()},[o.mode,f.isLoading,S,d]);let C=o.mode===`new`||o.mode===`edit`&&S!==null,E=async()=>{await n({title:e(`system.backup.restartServerNow`,`Restart server now?`),message:e(`system.backup.activeConnectionsWillDropAnd`,`Active connections will drop and the apply-backup hook will run before boot.`),confirmLabel:e(`system.backup.restart`,`Restart`),variant:`warning`})&&i.mutate({confirm:!0})};return a(Ke,{embedded:!0,children:[a(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,"data-testid":`backup-actions`,children:[a(B,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>x(!0),"data-testid":`backup-now`,children:[c(l,{className:`h-3.5 w-3.5`}),e(`system.backup.backUpNow`,`Back up now`)]}),a(B,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>_(!0),children:[c(k,{className:`h-3.5 w-3.5`}),e(`system.backup.restore`,`Restore…`)]}),a(B,{size:`sm`,type:`button`,onClick:s,"data-testid":`backup-new-entry`,children:[c(w,{className:`h-3.5 w-3.5`}),e(`system.backup.newEntry`,`New entry`)]})]}),v&&c(`div`,{className:`rounded-lg border border-warning/30 bg-warning/10 px-3 py-2.5 text-xs text-warning`,children:a(`div`,{className:`flex items-center justify-between gap-3`,children:[a(`div`,{className:`flex items-center gap-2`,children:[c(k,{className:`h-3.5 w-3.5`}),c(`span`,{children:e(`system.backup.restoreScheduledRestartTheServer`,`Restore scheduled. Restart the server to apply.`)})]}),a(B,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>{E()},disabled:i.isPending,children:[i.isPending?c(T,{className:`h-3.5 w-3.5 animate-spin`}):c(k,{className:`h-3.5 w-3.5`}),e(`system.backup.restartNow`,`Restart Now`)]})]})}),c(Pt,{}),c(Kt,{}),c(bt,{onEdit:e=>u(e.id),onOpenRestoreWizard:e=>h(e)}),C&&c(Ht,{entry:S,onClose:d,onSaved:d}),b&&c(At,{onClose:()=>x(!1)}),(m||g)&&c(rn,{...m?{initialDestinationId:m.destinationId,initialArchiveId:m.archiveId}:{},onClose:()=>{h(null),_(!1)},onScheduled:()=>y(!0)})]})}e();function fn(e){return Object.entries(e).map(([e,t])=>`${e} ${t}`).join(` · `)}function pn(e){return e.reduce((e,t)=>e+Object.values(t.stores).reduce((e,t)=>e+t,0),0)}function mn(){let{t:e}=W(),t=z(),n=se(),[i,s]=r(null),[l,u]=r(null),d=async e=>{u(null);try{s(await n.mutateAsync({confirm:e}))}catch(e){u(e instanceof Error?e.message:String(e))}},f=async()=>{i===null||i.status!==`dry-run`||await t({title:e(`systemPage.deletedDevices.confirmTitle`,`Delete the data of deleted devices?`),message:i.devices.map(e=>`#${e.deviceId}: ${fn(e.stores)}`).join(`
|
|
2
|
-
`),confirmLabel:e(`systemPage.deletedDevices.confirmLabel`,`Delete`),variant:`danger`})&&await d(!0)},m=[{key:`device`,header:e(`systemPage.deletedDevices.device`,`Device`),render:e=>`#${e.deviceId}`},{key:`stores`,header:e(`systemPage.deletedDevices.stores`,`Data held`),nowrap:!1,render:e=>fn(e.stores)}];return a(`div`,{className:`space-y-4`,"data-testid":`deleted-devices-data`,children:[c(`p`,{className:`text-sm text-foreground-muted`,children:e(`systemPage.deletedDevices.intro`,`Data that still belongs to devices that were deleted before deletions were recorded: footage, events, history and per-addon settings. Scanning deletes nothing; deleting asks first and shows what goes.`)}),a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[a(B,{variant:`outline`,onClick:()=>void d(!1),disabled:n.isPending,"data-testid":`deleted-devices-scan`,children:[n.isPending?c(T,{className:`mr-2 h-4 w-4 animate-spin`}):c(S,{className:`mr-2 h-4 w-4`}),e(`systemPage.deletedDevices.scan`,`Scan`)]}),i?.status===`dry-run`&&i.devices.length>0?a(B,{variant:`danger`,onClick:()=>void f(),disabled:n.isPending,"data-testid":`deleted-devices-delete`,children:[c(p,{className:`mr-2 h-4 w-4`}),e(`systemPage.deletedDevices.delete`,`Delete the data of {{count}} devices…`,{count:i.devices.length})]}):null]}),l===null?null:c(`p`,{className:`text-sm text-danger`,children:l}),i?.status===`skipped`?c(`p`,{className:`text-sm text-warning`,"data-testid":`deleted-devices-skipped`,children:e(`systemPage.deletedDevices.skipped`,`Nothing was listed or deleted: the device list could not be trusted ({{reason}}). Try again.`,{reason:i.reason??``})}):null,i!==null&&i.status!==`skipped`?a(o,{children:[c(`p`,{className:`text-sm`,"data-testid":`deleted-devices-summary`,children:i.status===`cleaned`?e(`systemPage.deletedDevices.cleaned`,`Deleted {{rows}} items of {{count}} devices.`,{rows:pn(i.devices),count:i.devices.length}):e(`systemPage.deletedDevices.found`,`{{count}} deleted devices still hold {{rows}} items.`,{rows:pn(i.devices),count:i.devices.length})}),c(fe,{columns:m,rows:i.devices,rowKey:e=>e.deviceId,emptyMessage:e(`systemPage.deletedDevices.none`,`No data belongs to a deleted device.`)}),i.unreachable.length>0?c(`p`,{className:`text-xs text-foreground-muted`,children:e(`systemPage.deletedDevices.unreachable`,`Not asked (unreachable): {{names}}`,{names:i.unreachable.join(`, `)})}):null]}):null]})}var hn=`view`,gn=`kinds`,_n=`deleted-devices`;function vn(){let{t:e}=W(),[t,n]=Ue(),r=t.get(`view`)===`deleted-devices`?_n:gn;return a(`div`,{className:u,children:[a(`div`,{className:`mb-3 space-y-2`,children:[c(de,{appearance:`pills`,value:r,onValueChange:e=>{n(t=>{let n=new URLSearchParams(t);return e===`kinds`?n.delete(hn):n.set(hn,e),n},{replace:!0})},children:a(R,{className:`flex flex-wrap gap-1`,children:[c(ve,{value:gn,children:e(`systemPage.data.viewKinds`,`Record kinds`)}),c(ve,{value:_n,children:e(`systemPage.data.viewDeletedDevices`,`Deleted devices`)})]})}),r===`kinds`?c(`p`,{className:`text-xs text-foreground-muted`,children:e(`systemPage.data.recordsUnifiedIntro`,`Every declared record kind on this hub. Entry kinds can be added, edited and deleted; the rest are read-only. Secret fields are redacted.`)}):null]}),c(r===`kinds`?Ee:mn,{})]})}var yn={entries:null,"deleted-devices":`deleted-devices`};function bn(){let{t:e}=W(),t=We(`/system/data`,{t:e,isAdmin:!0})??{icon:m,title:e(`system.data`,`Data`)},[n]=Ue(),r=yn[n.get(`tab`)??``];if(r!==void 0){let e=new URLSearchParams(n);return e.set(`tab`,`records`),r!==null&&e.set(`view`,r),c(Ve,{replace:!0,to:{search:e.toString()}})}return c(Ge,{icon:t.icon,title:t.title,defaultSection:`storage`,sectionsLabel:`${t.title} sections`,sections:[{id:`storage`,label:e(`systemPage.data.storage`,`Storage`),content:c(nt,{})},{id:`records`,label:e(`systemPage.data.records`,`Records`),content:c(vn,{}),ownedParams:[`view`,`recordsOwner`,`recordsKind`,`entryNew`,`entryEdit`]},{id:`backup`,label:e(`systemPage.data.backup`,`Backup`),content:c(dn,{})}]})}export{bn as DataPage};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,L as i,S as a,a as o,b as s,o as c,q as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Br as f,Cr as p,D as m,Di as h,En as g,G as _,Gn as v,It as y,J as b,Jn as x,Jr as S,K as C,Kn as w,Li as T,O as E,Ri as D,Si as O,St as k,T as A,V as j,W as ee,Xn as te,Xr as M,Z as ne,Zt as re,_t as N,bn as ie,dn as ae,dt as P,en as F,ht as oe,li as se,lr as I,or as L,ot as R,pi as z,pn as B,q as ce,r as le,sa as ue,t as de,ta as fe,tr as pe,vn as me,xn as V,yn as H,z as he,zn as ge,zr as _e}from"./player-overlays-B_ZfVBiA.js";import{$r as ve,Di as ye,Fn as U,Fr as be,Gt as xe,Hr as Se,In as Ce,Jt as we,Kt as Te,Nn as Ee,Oi as W,Pn as De,Ti as Oe,Wn as G,Xt as ke,Yt as Ae,d as je,da as Me,ki as K,oi as Ne,pi as Pe,qt as Fe,sa as Ie,ua as Le}from"./client-DIBstlq5.js";import{t as Re}from"./archive-Bs9ToeWK.js";import{i as ze,n as Be,r as Ve,t as He}from"./scan-eye-C7MTwcP4.js";import{t as Ue}from"./bell-off-CosUv2Rj.js";import{t as We}from"./boxes-CA7Sh4JV.js";import{n as Ge}from"./video-BcVXMTle.js";import{t as Ke}from"./circle-slash-0Ca1BMK0.js";import{t as qe}from"./layers-BCzFIxnd.js";import{$ as Je,$c as Ye,$r as Xe,$t as Ze,$u as Qe,Ac as $e,An as et,Bn as tt,Bt as nt,Ca as rt,Ct as it,Dl as at,Dr as ot,F as st,Fa as ct,Fo as lt,Ft as ut,Gt as dt,Gu as ft,Hn as pt,Hr as mt,Ia as ht,Jn as gt,Jt as _t,Ka as vt,L as yt,Lr as bt,Lt as xt,Ma as St,Mc as Ct,Mn as wt,Nn as Tt,No as Et,Nt as Dt,Pa as Ot,Pc as kt,Pt as At,Qt as jt,Qu as Mt,Rc as Nt,Rn as Pt,Rt as Ft,Sa as It,Sc as Lt,Sn as Rt,Sr as zt,St as Bt,Ti as Vt,Tn as Ht,Tr as Ut,Uc as Wt,Un as Gt,Ut as Kt,Vi as qt,Vn as Jt,Vt as Yt,Wr as q,Wt as Xt,X as Zt,Xa as Qt,Xt as $t,Y as en,Ys as tn,Yt as nn,Zr as J,Zu as rn,_r as an,a as on,ac as sn,ad as cn,ao as ln,at as un,c as dn,cd as fn,cn as pn,co as mn,dd as hn,dr as gn,ds as _n,ed as vn,ei as yn,el as bn,en as xn,et as Sn,fl as Cn,fr as wn,fs as Tn,go as En,gr as Dn,hr as On,i as kn,it as An,ja as jn,jc as Mn,jn as Nn,jt as Pn,ka as Fn,kt as In,l as Ln,lo as Rn,nl as zn,no as Bn,nt as Vn,o as Hn,od as Un,oi as Wn,oo as Gn,po as Kn,pr as qn,ps as Jn,qn as Yn,qt as Xn,r as Zn,rc as Qn,rd as $n,rl as er,rt as tr,so as nr,ss as rr,td as ir,tl as ar,to as or,ud as sr,uo as cr,ur as lr,va as ur,vn as dr,vr as fr,wa as pr,xr as mr,ya as hr,yo as gr,yr as _r,yt as vr,zn as yr,zo as br}from"./src-BVr0SnD-.js";import{t as Y}from"./i18n-D3CF2V_j.js";import{t as X}from"./useTranslation-D3Is_4B6.js";import"./mount-yjEyEWyS.js";import{$n as xr,A as Sr,D as Cr,E as wr,O as Tr,cr as Er,er as Dr,fr as Or,ir as kr,j as Ar,k as jr,lr as Mr,mr as Nr,nr as Pr,or as Z,p as Fr,pr as Ir,rr as Lr,sr as Rr,tr as zr,ur as Br}from"./index-Cskol4XA.js";import{A as Vr,D as Hr,E as Ur,O as Wr,S as Gr,T as Kr,_ as qr,a as Jr,b as Yr,c as Xr,d as Zr,f as Qr,g as $r,h as ei,i as ti,k as ni,l as ri,m as ii,n as ai,o as oi,p as si,r as ci,s as li,t as ui,u as di,v as fi,w as pi,x as mi,y as hi}from"./event-targets-CHOtaC2B.js";import{r as gi,t as _i}from"./assignment-candidates-e6s6JtrJ.js";import{_ as vi,b as yi,i as bi,m as xi,o as Si,t as Ci}from"./step-inspector-model-DjRSZkVO.js";import"./useEventInvalidation-yjEyEWyS.js";import{t as wi}from"./use-stationary-objects-P_tT9TQq.js";import{n as Ti,t as Ei}from"./format-BYDOzxSv.js";import{a as Di,i as Oi,n as ki,o as Ai,r as ji,s as Mi,t as Ni}from"./linked-devices-model-Uzvgx-iv.js";import{t as Pi}from"./authed-media-BWhmwHt2.js";e();function Fi(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 Ii(e){if(typeof e!=`object`||!e)return null;let t=e.switches;if(!Array.isArray(t))return null;let n=t.map(Fi).filter(e=>e!==null);return n.length===0?null:n}var Li=[[/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 Ri(e){for(let[t,n]of Li)if(t.test(e))return n;return`generic`}function zi(e){let t=e.filter(e=>e.on===!1).map(e=>e.id),n=e.filter(e=>e.on===null).map(e=>e.id),r=t=>t.map(t=>e.find(e=>e.id===t)?.label??t).join(`, `),i=[];return t.length>0&&i.push(Y.t(`helpers.cameraSwitchRows.off`,{list:r(t)})),n.length>0&&i.push(Y.t(`helpers.cameraSwitchRows.unknown`,{list:r(n)})),{offIds:t,unknownIds:n,summary:i.length===0?Y.t(`helpers.cameraSwitchRows.allOn`):i.join(` · `)}}var Bi={stream:V,detection:He,privacy:_e,microphone:te,speaker:k,listening:Be,archive:Re,recording:Ve,notifications:T,generic:F};function Vi({deviceId:e}){let{t}=X(),n=c(),o=Number.isFinite(e),[s,l]=r(null),[u,f]=r(!1),p=kt({deviceId:e},{enabled:o});Zn([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let m=Ii(p.data),h=er({onError:(t,r)=>{console.error(`[CameraFunctionSwitches] switch write failed — reverting`,{tags:{deviceId:e},meta:{switchId:r.switchId,error:t instanceof Error?t.message:String(t)}}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSwitches`]]}),l({id:r.switchId,message:t instanceof Error?t.message:String(t)})},onSuccess:()=>{l(null),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),n.invalidateQueries({queryKey:[[`deviceManager`]]}),n.invalidateQueries({queryKey:[[`recording`]]})}}),g=i(t=>{!t.available||t.on===null||h.mutate({deviceId:e,switchId:t.id,enabled:!t.on})},[e,h]);if(m===null)return null;let _=zi(m),v=e=>s?.id===e.id?s.message:null;return a(Qe,{open:u,onOpenChange:f,children:[a(ir,{"aria-label":t(`device.cameraFunctionSwitches.cameraFunctions`,`Camera functions`),title:_.summary,className:`inline-flex items-center gap-1 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors ${s===null?_.offIds.length>0?`border-warning/40 text-warning hover:bg-warning/10`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`:`border-danger/50 text-danger bg-danger/5`}`,children:[d(F,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden lg:inline`,children:t(`device.cameraFunctionSwitches.functions`,`Functions`)}),_.offIds.length>0&&d(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:t(`device.cameraFunctionSwitches.offCount`,{count:_.offIds.length})})]}),a(vn,{align:`end`,className:`min-w-[240px] max-h-[60vh] overflow-y-auto p-1`,children:[d(`div`,{className:`px-2 py-1 text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t(`device.cameraFunctionSwitches.cameraFunctions`,`Camera functions`)}),d(`ul`,{className:`space-y-0.5`,children:m.map(e=>d(`li`,{children:d(Hi,{row:e,failure:v(e),onToggle:()=>g(e)})},e.id))})]})]})}function Hi({row:e,failure:t,onToggle:n}){let{t:r}=X(),i=Bi[Ri(e.label)],o=e.on===null,s=e.on===!1,c=t===null?o?e.unavailableReason??`The source that owns this did not answer.`:e.costWhenOff:`Write failed: ${t}`,l=t===null?o?e.unavailableReason??`unknown`:null:`write failed`;return a(`button`,{type:`button`,role:`switch`,"aria-label":e.label,"aria-checked":e.on===!0,disabled:!e.available,onClick:n,title:c,className:`flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-[12px] text-foreground transition-colors hover:bg-surface-hover disabled:opacity-40 disabled:cursor-not-allowed`,children:[d(i,{className:`h-3.5 w-3.5 shrink-0 ${t===null?o?`text-foreground-subtle/50`:s?`text-warning`:`text-success`:`text-danger`}`}),a(`span`,{className:`flex-1 min-w-0 truncate`,children:[e.label,l!==null&&a(`span`,{className:`ml-1 text-[10px] text-foreground-subtle`,children:[`· `,l]})]}),d(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[9px] font-semibold uppercase tracking-wide ${o?`bg-surface-hover text-foreground-subtle/60`:s?`bg-warning/20 text-warning`:`bg-success/20 text-success`}`,children:o?`—`:r(s?`common.off`:`common.on`)})]})}function Ui({deviceId:e}){let t=nt(R().trpcClient,e);return t===null?null:a(`a`,{href:t.url,target:`_blank`,rel:`noopener noreferrer`,title:`${t.label} — ${t.host}`,className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[d(f,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden sm:inline`,children:t.label})]})}function Wi({parentDeviceId:e}){let{t}=X(),n=Or(),r=R(),{data:i,isLoading:o,isError:s}=kr(e),{data:c}=ln({deviceId:e},{enabled:Number.isFinite(e)});if(o)return d(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:d(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(s)return d(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:d(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let l=(i??[]).filter(e=>e.display?.hidden!==!0);if(l.length===0)return null;let u=ut(c?.stableId??``,l,c?.childLayout),f=u.ungrouped,p=e=>n(`/devices/${String(e)}`),m=c?.name??``,h=(e,t)=>d(Dt,{trpc:r.trpcClient,device:{...t,name:Yt(t,m)},variant:`minimal`,onNavigate:p},e),g=f.some(e=>!!e.role),_=f.some(e=>!e.role),v=g&&!_?t(`device.accessories`,{defaultValue:`Accessories`}):!g&&_?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),y=f.length>0?a(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[d(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:v}),d(`div`,{className:`space-y-1`,children:f.map(e=>h(e.id,e))})]}):null,b=u.disabledSection===void 0?null:d(At,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:u.disabledSection.children.length,defaultOpen:!1,children:d(`div`,{className:`opacity-60 space-y-1`,children:u.disabledSection.children.map(e=>h(e.id,e))})},u.disabledSection.title);if(u.sections.length===0)return b===null?y:a(`div`,{className:`space-y-2`,children:[y,b]});let x=_&&!g;return a(`div`,{className:`space-y-2`,children:[x?y:null,u.sections.map(e=>d(At,{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 Gi({deviceId:e}){let t=R(),{data:n,isLoading:r}=Lr(e),{data:i,isLoading:a}=kr(e),o=r||a,s=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),c=typeof n?.linkDeviceId==`number`?n.linkDeviceId:null,l=typeof n?.primaryChildEntityId==`string`?n.primaryChildEntityId:null;return o?d(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):d(`div`,{className:`flex h-full w-full flex-col`,children:d(Kt,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}e();function Ki({dev:e,busy:t,setBusy:n}){let{t:i}=X(),o=e?.motionTrigger,s=b(e?.state.motionTrigger),[c,l]=r(!1);if(!o)return null;let u=s?.enabled===!0,f=s!==void 0,p=async()=>{if(t||!f)return;let e=!u;n(!0),l(!0);try{await o.setMotionTrigger({enabled:e})}finally{n(!1),l(!1)}},m=c?u?`Disabling…`:`Enabling…`:f?u?`On motion: on`:`On motion: off`:`On motion: …`;return a(`button`,{type:`button`,onClick:()=>{p()},disabled:t||!f,title:f?u?i(`hero.motionTriggerToggle.disableTriggerOnMotion`,`Disable trigger on motion`):i(`hero.motionTriggerToggle.enableTriggerOnMotion`,`Enable trigger on motion`):i(`hero.motionTriggerToggle.awaitingState`,`Awaiting state…`),"aria-pressed":u,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${u?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[d(fe,{className:`h-3 w-3`}),d(`span`,{children:m})]})}e();function Q({deviceId:e,deviceType:t,features:n}){let i=R(),o=Xn(t)?.HeroCard??_t,s=C(i.trpcClient,e),c=b(s?.state.deviceStatus),[l,u]=r(!1),f=c!==void 0&&c.online===!1,p=f?c.lastChangedAt:null;return a(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[f?d(`div`,{className:`flex justify-center`,children:d(dt,{lastChangedAt:p})}):null,d(o,{trpc:i.trpcClient,deviceId:e,features:n}),d(`div`,{className:`flex justify-center`,children:d(Ki,{dev:s,busy:l,setBusy:u})})]})}function qi({deviceId:e,features:t}){return d(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:d(nn,{trpc:R().trpcClient,deviceId:e,features:t})})}function Ji({deviceId:e,features:t}){return d(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:d(_t,{trpc:R().trpcClient,deviceId:e,features:t})})}function Yi(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function Xi(e){if(!e)return null;let t=Yi(e.data);return t===null?e.eventType:Y.t(`helpers.eventEmitterFormat.buttonHeadline`,{channel:String(t),eventType:e.eventType})}var Zi=1e3,Qi=60*Zi,$i=60*Qi,ea=24*$i;function ta(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<Zi?Y.t(`helpers.relativeTime.justNow`):n<Qi?Y.t(`helpers.relativeTime.secondsAgo`,{count:Math.floor(n/Zi)}):n<$i?Y.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(n/Qi)}):n<ea?Y.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(n/$i)}):Y.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(n/ea)})}e();var na=1500,ra=15e3,ia=1e3;function aa({deviceId:e}){let{t:n}=X(),i=C(R().trpcClient,e)?.state.eventEmitter,o=b(i);t(()=>{if(!i)return;i.refresh();let e=setInterval(()=>{i.refresh()},ra);return()=>{clearInterval(e)}},[i]);let s=o?.lastEvent??null,c=s?.seq??null,u=l(null),[f,m]=r(!1);t(()=>{if(c===null)return;let e=u.current;if(u.current=c,e===null||e===c)return;m(!0);let t=setTimeout(()=>{m(!1)},na);return()=>{clearTimeout(t)}},[c]);let[h,g]=r(()=>Date.now());t(()=>{let e=setInterval(()=>{g(Date.now())},ia);return()=>{clearInterval(e)}},[]);let _=Xi(s),y=o?.eventTypes??[],x=o?.eventCountSinceStart??0,S=o!==void 0,w=Yi(s?.data);return a(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[d(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(f),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${f?`border-primary bg-primary/20 text-primary shadow-lg shadow-primary/30 scale-105`:`border-border bg-surface text-foreground-subtle`}`,"aria-live":`polite`,title:_??n(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`),children:d(f?v:p,{className:`h-10 w-10`})}),a(`div`,{className:`text-center`,children:[w!==null&&d(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:n(`hero.eventEmitterHero.button`,`Button {{value1}}`,{value1:String(w)})}),d(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${_?`text-foreground`:`text-foreground-subtle`}`,children:_??(S?n(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`):n(`hero.eventEmitterHero.awaitingState`,`Awaiting state…`))}),d(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:s?ta(s.timestamp,h):n(`hero.eventEmitterHero.waitingForTheFirstEvent`,`Waiting for the first event`)})]}),y.length>0&&d(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:y.map(e=>d(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===s?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:n(`hero.eventEmitterHero.sinceStart`,{count:x})})]})}function oa({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){let{t:o}=X();return a(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[d(Rr,{type:n,size:`lg`}),a(`div`,{children:[d(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),d(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),a(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[d(un,{status:r?`online`:`offline`}),i.length>0&&d(Er,{capabilities:i})]}),d(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:o(`hero.genericHero.noLiveViewForThis`,`No live view for this device type. Use the Config tab or the shortcut row to interact.`)})]})}e();function sa({deviceId:e}){let{t}=X(),r=c(),i=jn({deviceId:e},{refetchInterval:1e4,retry:!1}),o=St({onSuccess:()=>{r.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),r.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),s=n(()=>ca(i.data??[]),[i.data]);return a(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[a(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[d(la,{label:t(`hero.hubHero.discovered`,`Discovered`),value:s.total,icon:d(ge,{className:`h-3.5 w-3.5`})}),d(la,{label:t(`hero.hubHero.adopted`,`Adopted`),value:s.adopted,accent:`success`}),d(la,{label:t(`hero.hubHero.available`,`Available`),value:s.available,accent:s.available>0?`primary`:void 0}),a(`button`,{type:`button`,onClick:()=>{o.mutateAsync({deviceId:e}).catch(()=>{})},disabled:o.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[o.isPending?d(L,{className:`h-3.5 w-3.5 animate-spin`}):d(ie,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden sm:inline`,children:t(`hero.hubHero.discover`,`Discover`)})]})]}),a(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[d(ua,{icon:d(oe,{className:`h-3 w-3 text-emerald-500`}),label:t(`hero.hubHero.online`,`{{online}} online`,{online:s.online})}),d(ua,{icon:d(w,{className:`h-3 w-3 text-amber-500`}),label:t(`hero.hubHero.sleeping`,`{{sleeping}} sleeping`,{sleeping:s.sleeping})}),d(ua,{icon:d(N,{className:`h-3 w-3 text-destructive`}),label:t(`hero.hubHero.offline`,`{{offline}} offline`,{offline:s.offline})}),s.unknown>0?d(ua,{icon:d(se,{className:`h-3 w-3 text-foreground-subtle`}),label:t(`hero.hubHero.unknown`,`{{unknown}} unknown`,{unknown:s.unknown})}):null]})]})}function ca(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 la({label:e,value:t,icon:n,accent:r}){return a(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${r===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:r===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[a(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,d(`span`,{className:`truncate`,children:e})]}),d(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function ua({icon:e,label:t}){return a(`span`,{className:`inline-flex items-center gap-1`,children:[e,d(`span`,{children:t})]})}var da={[K.Switch]:Q,[K.Siren]:Q,[K.Light]:Q,[K.Sensor]:Q,[K.Button]:Q,[K.Hub]:sa,[K.Cover]:qi,[K.Valve]:Q,[K.Humidifier]:Q,[K.WaterHeater]:Q,[K.Container]:Gi,[K.Lock]:Q,[K.Fan]:Q,[K.Thermostat]:Q,[K.Climate]:Q,[K.MediaPlayer]:Q,[K.Control]:Q,[K.AlarmPanel]:Q,[K.EventEmitter]:aa,[K.Notifier]:Ji,[K.Script]:Q,[K.Automation]:Q,[K.Presence]:Q,[K.Update]:Q,[K.Vacuum]:Q,[K.LawnMower]:Q,[K.Weather]:Q,[K.Image]:Q,[K.PetFeeder]:Q,[K.Dishwasher]:Q};function fa(e){return da[e]??oa}function pa({deviceId:e}){let t=ce(R().trpcClient,e,e=>e.runningState);return d(wt,{running:t===void 0||t.running===null?null:t.running,since:t?.since??null,phase:t?.phase??null,className:`px-3 pt-2 sm:px-4`})}function ma(e){let t=fa(e.deviceType);return a(s,{children:[d(pa,{deviceId:e.deviceId}),d(t,{...e})]})}function ha({deviceId:e,widgets:t}){return t.length===0?null:d(`div`,{className:`flex flex-col gap-3 px-3 pb-3 sm:px-4 sm:pb-4`,"data-testid":`device-hero-widgets`,children:t.map(t=>{let n=d(lr,{widgetId:t.widgetId,deviceId:t.deviceId});return d(`div`,{children:t.deviceId===e?n:d(bt,{deviceId:t.deviceId,children:n})},t.widgetId)})})}function ga(e){return e.sections.filter(e=>e.location===`hero`).flatMap(t=>t.fields.flatMap(n=>{if(typeof n!=`object`||!n)return[];let r=Reflect.get(n,`type`),i=Reflect.get(n,`widgetId`);return r!==`widget`||typeof i!=`string`||i.length===0?[]:[{widgetId:i,deviceId:e.deviceId,order:t.order??0}]}))}function _a(e){let t=ga(e),n=new Set(t.map(e=>e.widgetId)),r=e.child===void 0?[]:ga(e.child),i=[...t,...r.filter(e=>!n.has(e.widgetId))],a=new Set;return i.filter(e=>a.has(e.widgetId)?!1:(a.add(e.widgetId),!0)).sort((e,t)=>e.order-t.order)}function va(e){return Hn(R().trpcClient,e)}e();function ya(e){let[n,a]=r(`idle`),[o,s]=r(null),c=l(null),u=l(null),d=l(null),f=l(!0),p=Tn(),m=_n(),h=Jn(),g=i(()=>{if(c.current){try{c.current.close()}catch{}c.current=null}if(u.current){for(let e of u.current.getTracks())try{e.stop()}catch{}u.current=null}d.current=null},[]),_=i(async()=>{if(n===`idle`)return;a(`stopping`);let t=d.current;if(t&&e!==null)try{await Promise.race([h.mutateAsync({deviceId:e,sessionId:t}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}g(),f.current&&(a(`idle`),s(null))},[n,e,h,g]),v=i(async()=>{if(e===null||n!==`idle`&&n!==`error`)return;s(null);let t=null,r=null,i=null;try{a(`requesting-mic`),t=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),u.current=t,a(`starting`);let n=await p.mutateAsync({deviceId:e});i=n.sessionId,d.current=i,a(`connecting`),r=new RTCPeerConnection,c.current=r,r.oniceconnectionstatechange=()=>{if(!f.current)return;let e=r.iceConnectionState;e===`connected`||e===`completed`?a(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&f.current&&(s(e===`failed`?`WebRTC connection failed`:null),_())};for(let e of t.getAudioTracks())r.addTrack(e,t);await r.setRemoteDescription({type:`offer`,sdp:n.sdpOffer});let o=await r.createAnswer();await r.setLocalDescription(o);let l=r.localDescription?.sdp??o.sdp??``;await m.mutateAsync({deviceId:e,sessionId:i,sdpAnswer:l})}catch(n){let o=n instanceof Error?n.message:String(n);if(console.warn(`[intercom] start failed`,n),r)try{r.close()}catch{}if(t)for(let e of t.getTracks())try{e.stop()}catch{}if(c.current=null,u.current=null,i!==null)try{await h.mutateAsync({deviceId:e,sessionId:i})}catch{}d.current=null,f.current&&(s(o),a(`error`))}},[e,n,p,m,h,_]);return t(()=>(f.current=!0,()=>{f.current=!1;let t=d.current;if(t!==null&&e!==null&&h.mutate({deviceId:e,sessionId:t}),c.current){try{c.current.close()}catch{}c.current=null}if(u.current){for(let e of u.current.getTracks())try{e.stop()}catch{}u.current=null}d.current=null}),[e]),{state:n,error:o,start:v,stop:_,isTalking:n===`talking`}}e();var ba=0;function $(){return++ba}function xa(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Sa(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 Ca(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 wa(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 Ta({scope:e,greeting:n,className:o}){let{t:s}=X(),c=R(),[f,p]=r(()=>{let t=[];return n&&t.push({id:$(),kind:`info`,text:n}),t.push({id:$(),kind:`info`,text:`scope: ${xa(e)} — type help or context for available commands`}),t}),[m,h]=r(``),[g,_]=r([]),[v,y]=r(-1),b=l(null),x=l(null);t(()=>{let e=x.current;e&&(e.scrollTop=e.scrollHeight)},[f]);let S=i(()=>{b.current?.focus()},[]),C=u({mutationFn:t=>c.trpcClient.repl.execute.mutate({code:t,scope:e}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;p(e=>[...e,{id:$(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);p(e=>[...e,{id:$(),kind:`error`,text:t}])}});function w(t){let n=t.trim();if(n){if(n===`clear`){p([{id:$(),kind:`info`,text:`scope: ${xa(e)}`}]),h(``);return}if(n===`help`){p(t=>[...t,{id:$(),kind:`input`,text:`> ${n}`},...Sa(e).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}if(n===`context`){p(t=>[...t,{id:$(),kind:`input`,text:`> ${n}`},...wa(e).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}if(n===`examples`){p(t=>[...t,{id:$(),kind:`input`,text:`> ${n}`},...Ca(e).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}_(e=>[...e,n]),y(-1),p(e=>[...e,{id:$(),kind:`input`,text:`> ${n}`}]),h(``),C.mutate(n)}}function T(t){if(t.key===`Enter`){t.preventDefault(),w(m);return}if(t.key===`ArrowUp`){if(t.preventDefault(),g.length===0)return;let e=v===-1?g.length-1:Math.max(0,v-1);y(e),h(g[e]??``);return}if(t.key===`ArrowDown`){if(t.preventDefault(),v===-1)return;let e=v+1;e>=g.length?(y(-1),h(``)):(y(e),h(g[e]??``));return}t.ctrlKey&&t.key===`l`&&(t.preventDefault(),p([{id:$(),kind:`info`,text:`scope: ${xa(e)}`}]))}let E={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return a(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${o??``}`,onClick:S,children:[a(`div`,{ref:x,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[f.map(e=>d(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${E[e.kind]}`,children:e.text},e.id)),C.isPending&&d(`span`,{className:`text-zinc-500 animate-pulse`,children:s(`shared.replTerminal.thinking`,`…thinking`)})]}),a(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[d(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:s(`shared.replTerminal.text`,`>`)}),d(`input`,{ref:b,value:m,onChange:e=>h(e.target.value),onKeyDown:T,disabled:C.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function Ea(e,t){return e===null?null:{playbackUrl:e.url,...e.format===void 0?{}:{playbackFormat:e.format},playbackAuthToken:t,...e.label===void 0?{}:{playbackLabel:e.label}}}e();function Da({deviceId:e,intercomAvailable:t=!1}){let r=R(),i=typeof window<`u`?ne():``,a=Number.isFinite(e),o=va(a?e:null),c=wi(a?[e]:[]),l=n(()=>{if(!a)return;let e=[];for(let t of c.rows){let n=on(t);n!==null&&e.push(n)}return e},[a,c.rows]),{streams:u,pipelineMetrics:f,createSession:p,sendAnswer:m,handleOffer:h,getIceServers:g,addIceCandidate:v,getIceCandidates:y,closeSession:b,getSessionState:x,applyDownlinkProbe:S}=dr(r.trpcClient,a?e:null),C=_(a?e:null,{width:Ma}),w=ya(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=le(),k=zt(),A=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,j=Ea(k.request,A),ee=O.length>0?d(s,{children:O.map(e=>d(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return d(en,{serverUrl:i,createSession:p,sendAnswer:m,handleOffer:h,getIceServers:g,addIceCandidate:v,getIceCandidates:y,closeSession:b,getSessionState:x,applyDownlinkProbe:S,...j===null?{}:{...j,onExitPlayback:()=>k.clear()},streams:u,pipelineMetrics:f,phase:o.phase,detections:o,...l===void 0?{}:{stationaryObjects:l},defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:C.src,...C.src?{posterUrl:C.src}:{},snapshotLoading:C.loading,onRefreshSnapshot:C.refresh,intercomAvailable:t,intercomShown:E,onIntercomToggle:D,extraOverlay:ee,chromeless:!0,className:`h-full`})}function Oa({deviceId:e,containerDeviceId:t}){let{t:n}=X();return Number.isFinite(e)?d(`div`,{className:`flex flex-col h-full`,children:d(xn,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):d(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:n(`device.panelContent.notLoaded`,{id:e})})}function ka({deviceId:e}){let{t}=X();if(!Number.isFinite(e))return d(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:t(`device.panelContent.notLoaded`,{id:e})});let n=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
|
|
2
|
-
`);return d(Ta,{scope:{type:`device`,deviceId:e},greeting:n,className:`h-full border-0 rounded-none`})}function Aa({deviceId:e}){let{t}=X();return Number.isFinite(e)?d(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:d(Ze,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):d(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:t(`device.panelContent.notLoaded`,{id:e})})}function ja({deviceId:e}){let{t}=X();return Number.isFinite(e)?d(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:d(jt,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):d(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:t(`device.panelContent.notLoaded`,{id:e})})}var Ma=960;function Na({initialName:e,label:t=`Name`,layout:n=`inline`,bound:r}){return d(Z,{label:t,layout:n,value:d(`input`,{type:`text`,value:r.value,"aria-label":t,placeholder:e,onChange:e=>r.onChange(e.target.value),className:`flex-1 min-w-0 w-full px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`})})}e();function Pa({label:e=`Location`,layout:t=`inline`,bound:r}){let{t:i}=X(),{data:o}=Kn(),s=o??[],c=r.value.trim().toLowerCase(),l=n(()=>c.length===0?[]:s.filter(e=>e.toLowerCase()!==c&&e.toLowerCase().includes(c)),[s,c]);return d(Z,{label:e,layout:t,value:a(`div`,{className:`relative`,children:[d(`input`,{type:`text`,value:r.value,"aria-label":e,onChange:e=>r.onChange(e.target.value),placeholder:i(`shared.locationRow.roomAreaOrLeaveEmpty`,`Room / area (or leave empty to clear)`),className:`flex-1 min-w-0 w-full px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),l.length>0&&d(`div`,{className:`absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md`,children:l.map(e=>a(`button`,{type:`button`,onClick:()=>r.onChange(e),className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[d(pe,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),d(`span`,{className:`truncate`,children:e})]},e))})]})})}var Fa=`w-full min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary disabled:opacity-50 disabled:cursor-not-allowed`,Ia=0,La=10;function Ra(e){if(e.trim()===``)return``;let t=Number.parseInt(e,10);return Number.isFinite(t)?String(t<Ia?Ia:t>La?La:t):``}function za({value:e,onChange:t,disabled:n=!1,placeholder:r,className:i,id:a,"aria-label":o}){return d(`input`,{type:`number`,min:Ia,max:La,step:1,id:a,className:i??Fa,"aria-label":o,placeholder:r,value:e,onChange:e=>{t(Ra(e.target.value))},disabled:n})}function Ba({deviceName:e,value:t,inheritedIcon:n,inheritedLabel:r,disabled:i,onChange:o}){let{t:s}=X(),c={trigger:s(`deviceDisplay.pickIcon`,{name:e}),panel:s(`deviceDisplay.iconFor`,{name:e}),searchPlaceholder:s(`deviceDisplay.iconSearchPlaceholder`),clear:r,noMatches:s(`deviceDisplay.iconNoMatches`)};return a(`div`,{className:`flex items-center gap-2`,children:[d(Mt,{value:t===``?null:t,onPick:e=>o(e??``),categoryLabel:e=>s(`deviceDisplay.iconCategory.${e}`,{defaultValue:Se(e)}),fallbackGlyph:n,labels:c,disabled:i}),d(`span`,{className:`text-[11px] text-foreground-subtle`,children:t===``?r:t})]})}var Va=`w-full min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary disabled:opacity-50`;function Ha(e){if(e.trim()===``)return;let t=Number.parseInt(e,10);return Number.isFinite(t)?t:void 0}function Ua({device:e,role:t,display:n,onChange:r}){let i=ue();Un();let{t:o}=X(),l=c(),u=t===null?void 0:$t[t],f=u?.kind===`numeric`,p=t!==null||e.parentDeviceId!==null&&e.parentDeviceId!==void 0,m=e.sourceInfo?.quantity,h=u?.kind===`numeric`?u.quantity??(m!==void 0&&m!==`device`?m:void 0):void 0,g=h===void 0?void 0:Ie(h),_=g===void 0?void 0:G(g),{data:v}=nr({},{staleTime:6e4,enabled:t!==null}),y=Et({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),b=()=>{if(t===null)return;let e=Ha(n.precision),r={...n.icon===``?{}:{icon:n.icon},...n.unit===``?{}:{unit:n.unit},...e===void 0?{}:{precision:e}};y.mutate({defaults:{...v?.defaults,[t]:r}})},x=t===null?void 0:v?.defaults?.[t]?.icon,S=x===void 0?void 0:cn(x),C=t===null?sr(e.type,i):fn(t,i),w={icon:S??C.icon,label:S===void 0?C.label:String(x)},T=t===null&&e.type===K.Container?o(`deviceDisplay.inheritedContainer`):S===void 0?o(`deviceDisplay.inherited`,{name:w.label}):o(`deviceDisplay.inheritedRoleDefault`,{icon:w.label,role:C.label}),E=t===null?``:fn(t,i).label;return a(`div`,{className:`mt-3 divide-y divide-border border-t border-border`,children:[d(Z,{label:o(`deviceDisplay.icon`),value:d(Ba,{deviceName:e.name,value:n.icon,inheritedIcon:w.icon,inheritedLabel:T,disabled:!1,onChange:e=>r({icon:e})})}),p&&d(Z,{label:o(`deviceDisplay.label`),value:d(`input`,{type:`text`,className:Va,"aria-label":o(`deviceDisplay.label`),placeholder:t===null?e.name:E,value:n.label,onChange:e=>r({label:e.target.value})})}),f&&a(s,{children:[d(Z,{label:o(`deviceDisplay.unit`),value:d(st,{dimension:_,value:n.unit,onChange:e=>r({unit:e}),disabled:!1,"aria-label":o(`deviceDisplay.unit`),inheritLabel:o(`deviceDisplay.unitSource`,{unit:g===void 0?``:` (${g})`}),emptyReason:o(`deviceDisplay.unitSource`,{unit:``})})}),d(Z,{label:o(`deviceDisplay.precision`),value:d(za,{"aria-label":o(`deviceDisplay.precision`),placeholder:o(`deviceDisplay.precisionInherit`),value:n.precision,onChange:e=>r({precision:e}),disabled:!1})})]}),t!==null&&d(`div`,{className:`px-3 sm:px-4 py-2`,children:d(q,{type:`button`,variant:`outline`,size:`sm`,onClick:b,disabled:y.isPending,title:o(`deviceDisplay.setRoleDefaultTitle`,{role:E}),children:o(`deviceDisplay.setRoleDefault`,{role:E})})})]})}function Wa(e){return typeof e.linkDeviceId==`number`}var Ga=new Set(Object.values(W));function Ka(e){return Ga.has(e)}var qa={[K.Switch]:[W.Siren,W.Floodlight,W.Spotlight,W.PirSensor,W.Chime,W.Autotrack,W.Nightvision,W.PrivacyMask,W.BinaryHelper],[K.Light]:[W.Floodlight,W.Spotlight,W.Nightvision],[K.Siren]:[W.Siren],[K.Button]:[W.Doorbell],[K.Sensor]:[W.MotionSensor,W.ContactSensor,W.LeakSensor,W.SmokeSensor,W.COSensor,W.GasSensor,W.TamperSensor,W.VibrationSensor,W.ConnectivitySensor,W.SoundSensor,W.BinarySensor,W.TemperatureSensor,W.HumiditySensor,W.AmbientLightSensor,W.PressureSensor,W.WindSensor,W.RainSensor,W.UvSensor,W.SolarRadiationSensor,W.SoilMoistureSensor,W.PowerSensor,W.EnergySensor,W.VoltageSensor,W.CurrentSensor,W.AirQualitySensor,W.BatterySensor,W.NumericSensor,W.EnumSensor,W.DateTimeSensor,W.GenericSensor],[K.Control]:[W.NumericControl,W.SelectControl,W.TextControl,W.DateTimeControl],[K.Notifier]:[W.MobilePushNotifier,W.MessagingNotifier,W.EmailNotifier,W.GenericNotifier]};function Ja(e){for(let t of Object.values(K))if(t===e)return!0;return!1}function Ya(e){return Ja(e)?qa[e]??[]:[]}function Xa(e,t){let n=Ya(t);return e==null||e===``||n.includes(e)?n:[...n,e]}function Za({device:e}){let{t}=X(),n=ue(),r=zr(),i=r?.identity??null,o=i?.name??e.name,s=i?.location??e.location??``,c=i?.role??e.role??null,l=i?.display.hidden??e.display?.hidden===!0,u=r!==null&&i!==null;return a(`section`,{"aria-label":t(`customize.identity.title`),className:`${E} ${m}`,children:[a(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[u?d(Na,{deviceId:e.id,initialName:o,label:t(`customize.identity.name`),layout:`stacked`,bound:{value:o,onChange:r.setIdentityName}}):d(Z,{label:t(`customize.identity.name`),layout:`stacked`,value:o}),u?d(Pa,{deviceId:e.id,initialLocation:s,label:t(`customize.identity.room`),layout:`stacked`,bound:{value:s,onChange:r.setIdentityLocation}}):d(Z,{label:t(`customize.identity.room`),layout:`stacked`,value:s===``?t(`common.unset`):s}),d(Z,{label:t(`customize.identity.type`),layout:`stacked`,value:e.type}),d(Z,{label:t(`customize.identity.hidden`),layout:`stacked`,value:d(Gt,{"aria-label":t(`deviceDisplay.hideFromLists`),checked:l,disabled:!u,onChange:e=>r?.setIdentityDisplay({hidden:e.target.checked})})}),d(Z,{label:t(`customize.identity.role`),layout:`stacked`,value:Wa(e)||!u?d(`span`,{children:Qa(c,t(`customize.identity.noRole`),n)}):d(ft,{"aria-label":t(`customize.identity.role`),value:c??``,options:[{value:``,label:t(`customize.identity.noRole`)},...Xa(c,e.type).map(e=>({value:e,label:Qa(e,t(`customize.identity.noRole`),n)}))],onChange:e=>r.setIdentityRole(e.target.value===``?null:e.target.value)})})]}),i!==null&&r!==null&&d(Ua,{device:e,role:c,display:i.display,onChange:r.setIdentityDisplay})]})}function Qa(e,t,n){return e==null||e===``?t:Ka(e)?fn(e,n).label:e}function $a(e){let t=De({draft:{kind:`pulse`,cap:e.cap,targetId:e.targetId,enabled:e.enabled,debounceMs:e.debounceMs,...e.edges===void 0?{}:{edges:[...e.edges]},sources:e.sources.map(e=>({addonId:e.addonId,stableId:e.stableId,cap:e.cap,fieldPath:e.fieldPath}))},device:e.device,changedAtFields:e.sources.map(e=>e.changedAtField)});return t.ok?t.value:null}function eo(e){let t=U({draft:{kind:`span`,cap:e.cap,targetId:e.targetId,timeoutMs:e.timeoutMs,...e.cooldownMs===void 0?{}:{cooldownMs:e.cooldownMs},sources:e.sources.map(e=>({addonId:e.addonId,stableId:e.stableId,cap:e.cap,fieldPath:e.fieldPath,mode:e.mode}))},device:e.device});return t.ok?t.value:null}function to(e,t){return{deviceId:e,config:t.config}}function no(e,t){return{deviceId:e,patch:{motionCooldownMs:t}}}async function ro(e,t,n,r){await n(to(e,t)),await r(no(e,t.timeoutMs))}e();function io(e){let{t}=X(),n=e.mode===`change`?t(`customize.scalar.changeTitle`,{title:e.title}):t(`customize.scalar.addTitle`,{title:e.title});return d(gn,{open:e.open,onOpenChange:t=>!t&&e.onClose(),children:a(qn,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":n,children:[d(Dn,{children:d(an,{children:n})}),e.open?d(ao,{...e}):null]})})}function ao(e){let{t}=X(),[n,i]=r(()=>oo(e.sources)),[o,c]=r(null),[l,u]=r(e.edge),[f,p]=r(e.debounceMs/1e3),m=so(n),h=m.length===0?null:$a({cap:e.cap,targetId:e.targetId,device:e.target,enabled:e.enabled,debounceMs:Math.round(f*1e3),edges:[l],sources:m}),g=m[0]??null,_=br({deviceId:n[0]?.deviceId??0}),v=lo(_.status===`success`?_.data:void 0,g),y=Ae(Fe,v,Math.round(f*1e3));return a(s,{children:[a(wn,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:[d(`p`,{className:`text-[11px] text-foreground-muted`,children:t(`customize.event.pulseBody`)}),d(ei,{kind:`event`,shape:`pulse`,enabled:e.open,hostId:e.host.id,devicePickerTestId:`event-pulse-picker`,destination:{cap:e.cap,targetId:e.targetId,title:e.title},device:o,picked:n,onDeviceChange:c,onPickedChange:i,edges:e.edges,edge:l,onEdgeChange:u,debounceSec:f,onDebounceSecChange:p,sourceModes:[],timeoutSec:0,onTimeoutSecChange:()=>void 0,cooldownSec:null,onCooldownSecChange:()=>void 0}),d(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:t(co(v,y.lastPressedAt))})]}),a(On,{className:`flex flex-wrap gap-2`,children:[d(q,{variant:`ghost`,onClick:e.onClose,children:t(`customize.scalar.cancel`)}),d(q,{"data-testid":`event-save`,disabled:!e.canSave||h===null,onClick:()=>{h!==null&&e.onSave(h)},children:t(`customize.scalar.save`)})]})]})}function oo(e){return e.map(e=>({deviceId:0,addonId:e.addonId,stableId:e.stableId,cap:e.cap,fieldPath:e.fieldPath,deviceName:e.stableId,changedAtField:e.changedAtField}))}function so(e){return e.map(e=>({addonId:e.addonId,stableId:e.stableId,cap:e.cap,fieldPath:e.fieldPath,changedAtField:e.changedAtField??Oe[e.cap]??`lastChangedAt`}))}function co(e,t){return e.kind===`unread`?`customize.event.previewWaiting`:e.active&&t===null?`customize.event.previewAlreadyOn`:t===null?`customize.event.previewQuiet`:`customize.event.previewCounted`}function lo(e,t){if(e===void 0||t===null)return{kind:`unread`};let n=e[t.cap],r=n===void 0?void 0:qr(n,t.fieldPath),i=Oe[t.cap]??t.changedAtField,a=n===void 0?void 0:qr(n,i);return typeof r==`boolean`?{kind:`level`,active:r,changedAt:typeof a==`number`&&Number.isFinite(a)?a:null}:{kind:`unread`}}function uo(e,t,n){if(e===`pending`)return{kind:`pending`,seconds:null};if(e===`unknown`||e==null)return{kind:`unknown`,seconds:null};if(!e)return{kind:`quiet`,seconds:null};let r=fo(t,n);return r===null?{kind:`unknown`,seconds:null}:{kind:`active`,seconds:r}}function fo(e,t){if(e==null||!Number.isFinite(e)||e<Ei)return null;let n=Math.floor((t-e)/1e3);return n<0?0:n}function po(e,t){if(e===`pending`)return{kind:`pending`,lastPressedAt:null,pressCount:null};if(e===`unknown`)return{kind:`unknown`,lastPressedAt:null,pressCount:null};let n=typeof e==`number`&&Number.isFinite(e)&&e>=Ei?e:null,r=typeof t==`number`&&Number.isFinite(t)&&t>=0?t:null;return n===null?{kind:`none`,lastPressedAt:null,pressCount:r}:{kind:`ring`,lastPressedAt:n,pressCount:r}}e();function mo({device:e,handle:t,availability:n,cap:i,title:o,view:c}){let{t:l,i18n:u}=X(),f=fi(),[p,m]=r(!1),[h,g]=r(null),_=Ur(t.state),v=hi(_,i),y=go(t,v),b=y.kind===`known`&&y.value!==null?Ee({feature:y.value,device:t.target,cap:i,targetId:c.id,timestampPath:c.timestampPath,counterPath:c.counterPath}):null,x=b!==null,S=Wr(x),C=b?.draft.sources[0]??null,w=C===null||S.kind!==`known`?null:S.value.find(e=>Pe({addonId:e.addonId,stableId:e.stableId})===Pe(C))??null,T=_o(x,S.kind,w!==null),E=xe({cap:i,targetId:c.id,device:t.target,timestampPath:c.timestampPath,counterPath:c.counterPath,apply:c.apply,stored:y,sourcePresence:T,sourceUnknownReason:S.kind===`unknown`?S.reason:null}),O=t.state.kind===`none`||t.state.kind===`present`;if(n.kind===`absent`||!c.deviceTypes.includes(e.type))return null;let k=async e=>{let n=await t.save(e);g(n.kind===`refused`?n.reason:null)},A=vo(b),j=b?.draft.edges?.[0],ee=j!==void 0&&c.edges.includes(j)?j:c.defaultEdge,te=C===null?``:Kr(C.cap,C.fieldPath,u.language),M=y.kind===`known`&&y.value===null,ne=!x&&y.kind===`known`&&y.value!==null;return a(s,{children:[d(Vr,{id:i,icon:D,title:o,testId:`event-card-${i}`,actions:a(s,{children:[v!==null&&a(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground`,children:[d(Gt,{"aria-label":l(`customize.doorbell.active`),checked:v.enabled!==!1,disabled:!O||t.saving,onChange:e=>{k(mi(_,t.target,{...v,enabled:e.target.checked}))}}),l(`customize.doorbell.active`)]}),d(J,{children:l(ui(E.text,E.status.state))})]}),children:d(`div`,{className:`flex flex-col gap-2 px-3 py-2 sm:px-4`,children:n.kind===`pending`||n.kind===`present`&&!O?d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:l(`customize.event.checking`)}):n.kind===`unknown`?d(Ut,{title:l(`customize.scalar.unreadable`),message:n.reason}):a(s,{children:[x&&C!==null&&d(`p`,{className:`text-xs text-foreground`,children:l(`customize.scalar.override`,{name:w?.name??C.stableId,field:te})}),x&&d(ho,{deviceId:e.id,cap:i,timestampPath:c.timestampPath,counterPath:c.counterPath,startedAt:t.state.kind===`present`?t.state.view.block.createdAt:null}),ne&&v!==null&&a(`p`,{className:`text-xs text-foreground flex flex-wrap items-center gap-1`,children:[l(`customize.doorbell.otherFormula`),d(di,{handle:t,cap:i,fieldPath:c.counterPath})]}),M&&d(`p`,{className:`text-xs text-foreground-subtle`,children:l(`customize.scalar.noOverride`)}),h!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:h}),a(`div`,{className:`flex flex-wrap gap-2`,children:[x&&d(q,{variant:`outline`,size:`sm`,disabled:t.saving,onClick:()=>m(!0),children:l(`customize.scalar.change`)}),x&&d(q,{variant:`ghost`,size:`sm`,disabled:t.saving,onClick:()=>{if(_===null)return;let t=Gr(_,i);f(l(`customize.doorbell.removeWhat`,{name:w?.name??e.name}),t===null).then(e=>{e&&k(t)})},children:l(`customize.scalar.remove`)}),M&&d(q,{variant:`outline`,size:`sm`,"data-testid":`event-add-${i}`,disabled:t.saving,onClick:()=>m(!0),children:l(`customize.scalar.add`)})]})]})})}),d(io,{open:p,mode:x?`change`:`add`,title:o,cap:i,targetId:c.id,host:e,target:t.target,enabled:v?.enabled!==!1,debounceMs:b?.draft.debounceMs??c.debounceMs,edges:c.edges,edge:ee,sources:A,canSave:O&&!t.saving,onClose:()=>m(!1),onSave:e=>{m(!1),k(mi(_,t.target,e))}})]})}function ho({deviceId:e,cap:t,timestampPath:n,counterPath:r,startedAt:i}){let{t:o}=X(),s=$r({deviceId:e,cap:t,path:n}),c=$r({deviceId:e,cap:t,path:r}),l=po(s.kind===`pending`?`pending`:s.kind!==`value`||typeof s.value!=`number`?`unknown`:s.value,c.kind===`value`&&typeof c.value==`number`?c.value:null);return l.kind===`pending`?d(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:o(`customize.event.checking`)}):l.kind===`unknown`?d(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:o(`customize.event.doorbellLast.unknown`)}):l.kind===`none`?a(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:[o(`customize.event.doorbellLast.none`,{when:i===null?``:Ti(i)}),l.pressCount===null?``:` · ${o(`customize.event.doorbellCount`,{count:l.pressCount})}`]}):a(`p`,{role:`status`,className:`text-[11px] text-foreground`,children:[o(`customize.event.doorbellLast.ring`,{when:Ti(l.lastPressedAt)}),l.pressCount===null?``:` · ${o(`customize.event.doorbellCount`,{count:l.pressCount})}`]})}function go(e,t){return e.state.kind===`pending`?{kind:`pending`}:e.state.kind===`unknown`||e.state.kind===`not-loaded`?{kind:`unknown`,reason:e.state.reason}:{kind:`known`,value:t}}function _o(e,t,n){return e?t===`pending`?`pending`:t===`unknown`?`unknown`:n?`present`:`absent`:`present`}function vo(e){return e===null?[]:e.draft.sources.map((t,n)=>({addonId:t.addonId,stableId:t.stableId,cap:t.cap,fieldPath:t.fieldPath,changedAtField:e.changedAtFields[n]??``}))}e();function yo(e){let{t}=X(),n=e.mode===`change`?t(`customize.scalar.changeTitle`,{title:e.title}):t(`customize.scalar.addTitle`,{title:e.title});return d(gn,{open:e.open,onOpenChange:t=>!t&&e.onClose(),children:a(qn,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":n,children:[d(Dn,{children:d(an,{children:n})}),e.open?d(bo,{...e}):null]})})}function bo(e){let{t}=X(),[n,i]=r(()=>xo(e.sources)),[o,c]=r(null),[l,u]=r(e.timeoutMs/1e3),[f,p]=r((e.cooldownMs??0)/1e3),m=So(n),h=eo({cap:e.cap,targetId:e.targetId,device:e.target,timeoutMs:Math.round(l*1e3),cooldownMs:e.cooldownMs===null?void 0:Math.round(f*1e3),sources:m}),g=n[0];return a(s,{children:[a(wn,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:[d(`p`,{className:`text-[11px] text-foreground-muted`,children:t(`customize.event.spanBody`)}),d(ei,{kind:`event`,shape:`span`,enabled:e.open,hostId:e.host.id,devicePickerTestId:`event-span-picker`,destination:{cap:e.cap,targetId:e.targetId,title:e.title},device:o,picked:n,onDeviceChange:c,onPickedChange:t=>i(t.filter(t=>!(t.addonId===e.host.addonId&&t.stableId===e.host.stableId))),edges:[],edge:`rising`,onEdgeChange:()=>void 0,debounceSec:0,onDebounceSecChange:()=>void 0,sourceModes:e.sourceModes,timeoutSec:l,onTimeoutSecChange:u,cooldownSec:e.cooldownMs===null?null:f,onCooldownSecChange:p}),g!==void 0&&d(Co,{deviceId:g.deviceId,cap:g.cap,fieldPath:g.fieldPath,timeoutMs:Math.round(l*1e3)})]}),a(On,{className:`flex flex-wrap gap-2`,children:[d(q,{variant:`ghost`,onClick:e.onClose,children:t(`customize.scalar.cancel`)}),d(q,{"data-testid":`event-save`,disabled:!e.canSave||h===null,onClick:()=>{h!==null&&e.onSave(h)},children:t(`customize.scalar.save`)})]})]})}function xo(e){return e.map(e=>({deviceId:0,addonId:e.addonId,stableId:e.stableId,cap:e.cap,fieldPath:e.fieldPath,deviceName:e.label.length>0?e.label:e.stableId,mode:e.mode}))}function So(e){return e.map(e=>({addonId:e.addonId,stableId:e.stableId,cap:e.cap,fieldPath:e.fieldPath,mode:e.mode??`in-addition`,label:e.deviceName}))}function Co({deviceId:e,cap:t,fieldPath:n,timeoutMs:r}){let{t:i}=X(),a=$r({deviceId:e,cap:t,path:n}),o=a.kind===`value`&&typeof a.value==`boolean`?{kind:`level`,active:a.value,changedAt:null}:{kind:`unread`};return d(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:i(wo(o,ke(we,o,{timeoutMs:r,cooldownMs:0,nowMs:Date.now()}).open))})}function wo(e,t){return e.kind===`unread`?`customize.event.previewWaiting`:t?`customize.event.previewMotionOn`:e.active?`customize.event.previewSensorOn`:`customize.event.previewMotionOff`}e();function To({device:e,availability:t,cap:n,title:i,view:o,sensors:c}){let{t:u}=X(),f=bn(),p=Lt(),m=Wn({addonId:`pipeline-orchestrator`,deviceId:e.id,nodeId:`hub`}),[h,g]=r(!1),[_,v]=r(null),y=l(!1),[b,x]=r(!1),S=Do(c),C=Te(o.id,S),w=ko(vi(m.data).motionCooldownMs,o.timeoutMs);if(t.kind===`absent`||!o.deviceTypes.includes(e.type))return null;let T=b||f.isPending||p.isPending,E=C.writable&&!T&&t.kind===`present`,D=async t=>{if(!C.writable||y.current){v(u(`customize.saveInFlight`));return}y.current=!0,x(!0);try{await ro(e.id,t,async e=>{await f.mutateAsync({deviceId:e.deviceId,config:e.config===null?null:{sensors:e.config.sensors.map(e=>({addonId:e.addonId,stableId:e.stableId,mode:e.mode}))}})},async e=>{let t={motionCooldownMs:e.patch.motionCooldownMs};await p.mutateAsync({deviceId:e.deviceId,patch:t})}),v(null),await c.refetch()===`failed`&&v(u(`customize.motion.refetchFailed`))}catch(e){v(e instanceof Error?e.message:String(e))}finally{y.current=!1,x(!1)}},O=C.rows.map(e=>({addonId:e.addonId,stableId:e.stableId,cap:`binary`,fieldPath:`on`,mode:e.mode,label:e.name}));return a(s,{children:[d(Vr,{id:n,icon:fe,title:i,testId:`event-card-${n}`,actions:d(J,{children:u(ui(C.text,C.status.state))}),children:d(`div`,{className:`flex flex-col gap-2 px-3 py-2 sm:px-4`,children:t.kind===`pending`||S.kind===`pending`?d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:u(`customize.motion.reading`)}):t.kind===`unknown`||S.kind===`unknown`?d(Ut,{title:u(`customize.motion.unreadable`,{reason:Oo(S)}),message:S.kind===`unknown`?S.reason??``:``}):a(s,{children:[d(Eo,{deviceId:e.id}),C.rows.length===0?d(`p`,{className:`text-xs text-foreground-subtle`,children:u(`customize.scalar.noOverride`)}):d(`ul`,{className:`flex flex-col gap-1`,children:C.rows.map(e=>a(`li`,{className:`text-xs text-foreground`,children:[e.name,e.reason===null?``:` — ${u(`customize.motion.state.${e.state}`)}`]},e.key))}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:u(`customize.event.timeoutSeconds`,{seconds:w/1e3})}),_!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:_}),d(`div`,{className:`flex flex-wrap gap-2`,children:d(q,{variant:`outline`,size:`sm`,"data-testid":`event-add-${n}`,disabled:!E,onClick:()=>g(!0),children:C.rows.length===0?u(`customize.scalar.add`):u(`customize.scalar.change`)})})]})})}),d(yo,{open:h,mode:C.rows.length===0?`add`:`change`,title:i,cap:n,targetId:o.id,host:e,target:{addonId:e.addonId,stableId:e.stableId},timeoutMs:w,cooldownMs:o.cooldownMs,sourceModes:o.sourceModes,sources:O,canSave:E,onClose:()=>g(!1),onSave:e=>{g(!1),D(e)}})]})}function Eo({deviceId:e}){let{t}=X(),n=$r({deviceId:e,cap:`motion`,path:`detected`}),r=$r({deviceId:e,cap:`motion`,path:`lastDetectedAt`}),i=uo(n.kind===`pending`?`pending`:n.kind!==`value`||typeof n.value!=`boolean`?`unknown`:n.value,r.kind===`value`&&typeof r.value==`number`?r.value:null,Date.now());return d(`p`,{role:`status`,className:`text-xs text-foreground`,children:t(i.kind===`active`?`customize.event.motionNow.active`:`customize.event.motionNow.${i.kind}`,i.seconds===null?void 0:{seconds:i.seconds})})}function Do(e){return e.presence===`pending`?{kind:`pending`}:e.status===null?{kind:`unknown`,reason:null}:{kind:`known`,value:e.status}}function Oo(e){return e.kind===`unknown`?e.reason??``:e.kind===`known`&&e.value.state===`unreadable`?e.value.reason:``}function ko(e,t){return e!==null&&Number.isFinite(e)?e:t}var Ao=Ce;function jo(e,t){let n=Ao[e];return n===void 0?null:n.targets.find(e=>e.id===t)??null}function Mo({device:e,handle:t,facts:n,sensors:r}){let{t:i}=X();return d(s,{children:ai().map(a=>{let o=a.pulse??a.span;if(o===null||!o.deviceTypes.includes(e.type))return null;let s=jo(a.cap,o.id);if(s===null)return null;let c=i(a.pulse===null?`customize.motion.title`:`customize.doorbell.title`),l=Zr(si(a.cap,s),n);return a.pulse===null?a.span===null?null:d(To,{device:e,availability:l,cap:a.cap,title:c,view:a.span,sensors:r},a.cap):d(mo,{device:e,handle:t,availability:l,cap:a.cap,title:c,view:a.pulse},a.cap)})})}function No({id:e,icon:t,title:n,headerControl:r,addLabel:i,onAdd:o,addDisabled:c=!1,notices:l,suggestion:u,children:f}){let{t:p}=X(),m=o!==void 0&&i!==void 0;return a(Vr,{id:e,icon:t,title:n,actions:a(s,{children:[r,m&&!c&&u!==void 0&&u.count>0&&a(q,{variant:`ghost`,size:`sm`,onClick:u.onOpen,children:[d(re,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),p(`customize.suggest.hint`,{count:u.count,location:u.location})]}),m&&d(q,{variant:`outline`,size:`sm`,disabled:c,onClick:o,children:i})]}),children:[l!==void 0&&d(`div`,{className:`flex flex-col gap-1 px-3 pt-2 empty:hidden sm:px-4`,children:l}),d(`ul`,{className:`flex flex-col divide-y divide-border`,children:f})]})}function Po(e,t){if(e.kind!==`known`||typeof t!=`string`||t.length===0)return null;let n=yn(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 Fo(e,t,n){return Xe(e,t?.ids??new Set,n)}function Io(e,t){return e?.containers.get(t)??null}function Lo(e,t,n){return e.kind===`known`?Fo(e.value,t,n).suggested.length:0}function Ro(e,t){let n=[t,e.detail].filter(e=>e!==null&&e!==``);return n.length===0?null:n.join(` · `)}function zo({location:e,devices:t,action:n,onPick:r,onPickAll:i}){let{t:o}=X();if(t.length===0)return null;let s=o(`customize.suggest.heading`,{location:e});return a(`section`,{"aria-label":s,className:`flex flex-col gap-1`,children:[a(`div`,{className:`flex min-h-7 items-center gap-2`,children:[d(`h3`,{className:`${j} min-w-0 flex-1`,children:s}),i!==void 0&&t.length>1&&d(q,{variant:`ghost`,size:`sm`,onClick:i,children:o(`customize.suggest.addAll`,{count:t.length})})]}),d(`ul`,{className:`flex flex-col divide-y divide-border rounded-md border border-border`,children:t.map(e=>{let t=Ro(e,e.container===null||e.name.includes(e.container)?null:o(`customize.suggest.in`,{container:e.container}));return a(`li`,{className:`${A} flex items-center gap-3`,children:[a(`div`,{className:`min-w-0 flex-1`,children:[d(`div`,{className:`text-xs text-foreground break-words`,children:e.name}),t!==null&&d(`div`,{className:`text-[11px] text-foreground-subtle break-words`,children:t})]}),d(q,{variant:`outline`,size:`sm`,"aria-label":o(n===`add`?`customize.suggest.addNamed`:`customize.suggest.useNamed`,{name:e.name}),onClick:()=>r(e.id),children:o(n===`add`?`customize.suggest.add`:`customize.suggest.use`)})]},e.id)})})]})}e();function Bo(e){return e.kind===`pending`?`pending`:e.kind===`unknown`?`failed`:`answered`}function Vo(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 Ho({open:e,title:i,selection:o,candidates:s,filters:c,room:l=null,confirmLabel:u,onConfirm:f,onClose:p}){let{t:m}=X(),[h,g]=r(null),[_,v]=r([]),y=c?.find(e=>e.id===h)??c?.[0]??null,b=s.kind===`known`?s.value:[],x=s.kind===`known`?gi(s.value,``,y):[],S=Fo(b,l,e=>e.deviceId).suggested,C=Fo(x,l,e=>e.deviceId).others,w=n(()=>Vo(C),[C]),T=Bo(s),E=b.filter(e=>_.includes(e.deviceId));t(()=>{e||(v([]),g(null))},[e]);let D=()=>{v([]),g(null),p()},O=e=>{e.length!==0&&(f(e),v([]),g(null))},k=()=>O(E);return d(gn,{open:e,onOpenChange:e=>e?void 0:D(),children:a(qn,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":i,children:[d(Dn,{children:d(an,{children:i})}),a(wn,{className:`flex flex-col gap-2 p-2 sm:p-4`,children:[c!==void 0&&c.length>0&&d(`div`,{className:`flex flex-wrap gap-1`,role:`tablist`,"aria-label":m(`customize.assign.filtersLabel`),children:c.map(e=>d(`button`,{type:`button`,role:`tab`,"aria-selected":(y?.id??null)===e.id,className:`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${(y?.id??null)===e.id?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover`}`,onClick:()=>g(e.id),children:m(e.labelKey)},e.id))}),l!==null&&d(zo,{location:l.location,devices:S.map(e=>({id:e.deviceId,name:e.name,container:Io(l,e.deviceId),detail:e.detail})),action:`add`,onPick:e=>O(S.filter(t=>t.deviceId===e)),...o===`multi`?{onPickAll:()=>O(S)}:{}}),s.kind===`unknown`?d(`p`,{role:`alert`,className:`text-xs text-warning`,children:m(`customize.assign.unknown`,{reason:s.reason})}):w.length===0&&S.length>0?null:d(yt,{devices:w,listState:T,value:_,onChange:e=>v(o===`single`?e.length>0?[e[e.length-1]]:[]:e),noun:`device`,emptyLabel:m(`customize.assign.none`),showAll:!0,testId:`customize-device-picker`})]}),a(On,{children:[d(q,{variant:`ghost`,onClick:D,children:m(`customize.picker.cancel`)}),d(q,{disabled:E.length===0,onClick:k,children:u(E.length)})]})]})})}e();function Uo(e,t){let r=typeof e==`string`&&e.length>0,i=Wr(t&&r);return n(()=>t?Po(i,e):null,[t,i,e])}e();function Wo(e){return e==null?null:e.message}function Go({device:e}){let t=ue(),{t:n}=X(),i=c(),o=fi(),l=be.includes(e.type),[u,f]=r(!1),[p,m]=r(!1),[h,g]=r(null),_=ct({deviceId:e.id},{enabled:l}),v=ji({status:_.status,data:_.data,error:Wo(_.error)===null?null:{message:Wo(_.error)??``}}),y=v.kind===`present`?v.slot.slotRef:``,b=v.kind===`present`?[...ki(v.slot,v.value).map(e=>e.deviceId),...Oi(v.slot,v.value)]:[],x=ht(),S=Wr(l&&v.kind===`present`&&(u||b.length>0)),C=Uo(e.location,l&&v.kind===`present`),w=Ot({deviceId:e.id,slotRef:y},{enabled:(u||C!==null)&&v.kind===`present`});if(!l||v.kind===`absent`)return null;if(v.kind!==`present`)return d(No,{id:`linked`,icon:I,title:n(`customize.linked.title`),notices:v.kind===`pending`?d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:n(`customize.assign.checking`)}):d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:n(`customize.assign.unknown`,{reason:v.reason})}),children:null});let T=v.value,E=new Map(S.kind===`known`?S.value.map(e=>[e.id,e]):[]),D=T.trackedDeviceIds!==void 0,O=(e,t)=>{let n=E.get(e.deviceId);return{...e,name:e.name??n?.name??null,type:n?.type??null,detail:n===void 0?null:_i(n.integration,n.location),orphan:t}},k=[...ki(v.slot,T).map(e=>O(e,!1)),...Oi(v.slot,T).map(e=>O({deviceId:e,name:null,health:`ok`,implied:!1,tracked:!0},!0))],A=new Set(b),j=S.kind===`unknown`?S:w.status===`error`?{kind:`unknown`,reason:Wo(w.error)??n(`helpers.customize.requestFailed`)}:S.kind===`pending`||w.status===`pending`||w.data===void 0?{kind:`pending`}:{kind:`known`,value:Ni(w.data.candidates,E,A)},ee=async t=>{if(p){g(n(`customize.saveInFlight`));return}m(!0),g(null);try{await x.mutateAsync({deviceId:e.id,slotRef:v.slot.slotRef,value:t}),await _.refetch(),await i.invalidateQueries({queryKey:[[`deviceManager`]]})}catch(e){g(e instanceof Error?e.message:String(e))}finally{m(!1)}},te=async e=>{await o(n(`customize.linked.removeWhat`,{name:e.name??`#${e.deviceId}`}),!1)&&await ee(Mi(T,e.deviceId))},M=[{key:`device`,header:n(`customize.linked.device`),cell:e=>a(`div`,{className:`flex flex-col min-w-0`,children:[d(`span`,{className:`truncate text-xs text-foreground`,children:e.name??`#${e.deviceId}`}),e.detail!==null&&d(`span`,{className:`truncate text-[11px] text-foreground-subtle`,children:e.detail}),e.orphan&&d(`span`,{className:`text-[11px] text-foreground-subtle`,children:n(`customize.linked.notLinked`)}),e.health!==`ok`&&d(`span`,{role:`alert`,className:`text-[11px] text-warning`,children:n(`customize.linked.health.${e.health}`)})]})},{key:`type`,header:n(`customize.linked.type`),headerClassName:`hidden sm:table-cell`,cellClassName:`hidden sm:table-cell text-xs text-foreground-subtle`,cell:e=>e.type===null?`—`:sr(e.type,t).label},{key:`controls`,header:n(`customize.linked.controls`),headerClassName:`hidden md:table-cell`,cellClassName:`hidden md:table-cell text-xs text-foreground-subtle`,cell:e=>e.orphan?`—`:n(`customize.linked.yes`)},...D?[{key:`tracked`,header:n(`customize.linked.tracked`),cellClassName:`text-right`,headerClassName:`text-right`,cell:e=>d(pt,{checked:e.tracked,disabled:p,"aria-label":n(`customize.linked.trackFor`,{name:e.name??e.deviceId}),onCheckedChange:t=>void ee(Ai(T,e.deviceId,t))})}]:[],{key:`remove`,header:``,cellClassName:`text-right w-10`,cell:e=>e.implied||e.orphan?null:d(rn,{icon:P,variant:`ghost`,size:`sm`,"aria-label":n(`customize.assign.removeNamed`,{name:e.name??e.deviceId}),disabled:p,onClick:t=>{t.stopPropagation(),te(e)}})}];return a(s,{children:[d(No,{id:`linked`,icon:I,title:n(`customize.linked.title`),addLabel:n(`customize.linked.add`),onAdd:p?void 0:()=>f(!0),...C===null?{}:{suggestion:{count:Lo(j,C,e=>e.deviceId),location:C.location,onOpen:()=>f(!0)}},notices:a(s,{children:[S.kind===`unknown`&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:n(`customize.assign.devicesUnreadable`,{reason:S.reason})}),h!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:h})]}),children:a(`li`,{className:`list-none px-3 py-2 sm:px-4`,children:[k.length===0?d(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`customize.assign.none`)}):d(In,{mode:`generic`,items:k,getKey:e=>String(e.deviceId),getSearchText:e=>[e.name??``,e.detail??``,e.type??``,String(e.deviceId)].join(` `),getFilterType:e=>e.type===null?null:sr(e.type,t).label,columns:M,searchPlaceholder:n(`customize.assign.search`),emptyLabel:n(`customize.assign.none`)}),k.some(e=>!e.orphan)&&d(`p`,{className:`mt-2 text-[10px] text-foreground-subtle`,children:n(`customize.linked.controlsAlways`)}),D&&d(`p`,{className:`mt-0.5 text-[10px] text-foreground-subtle`,children:n(`customize.linked.trackedHint`)})]})}),d(Ho,{open:u,title:n(`customize.linked.pickTitle`),selection:`multi`,candidates:j,room:C,confirmLabel:e=>n(`customize.assign.addCount`,{count:e}),onConfirm:e=>{f(!1),ee(Di(T,e.map(e=>e.deviceId)))},onClose:()=>f(!1)})]})}e();function Ko(e){return e instanceof Error?e.message:String(e)}function qo(e){let t=rt({addonId:e.addonId,stableId:e.stableId}),n=ur(),i=Fn(),a=hr(),o=Hr({status:t.status,data:t.data,error:t.error===null||t.error===void 0?null:{message:t.error.message}}),{t:s}=X(),c=l(!1),[u,d]=r(!1),f=async e=>{let r=Yr(o,e);try{switch(r.kind){case`refused`:return{kind:`refused`,reason:r.reason};case`noop`:return{kind:`saved`};case`create`:await n.mutateAsync({block:r.input});break;case`update`:await i.mutateAsync({blockId:r.blockId,expectedUpdatedAt:r.expectedUpdatedAt,block:{composition:r.composition}});break;case`delete`:await a.mutateAsync({blockId:r.blockId});break}return await t.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:Ko(e)}}};return{target:e,state:o,saving:u||n.isPending||i.isPending||a.isPending,save:async e=>{if(c.current)return{kind:`refused`,reason:s(`customize.saveInFlight`)};c.current=!0,d(!0);try{return await f(e)}finally{c.current=!1,d(!1)}}}}var Jo=`pipeline-orchestrator`;function Yo(e){return e.status===`pending`?`pending`:e.status===`error`?`unknown`:e.data===void 0?`pending`:e.data.cameraSensors===void 0?`absent`:`present`}function Xo(e,t){return e===`absent`?`absent`:Yo(t)}async function Zo(e){try{return(await e()).isError?`failed`:`answered`}catch{return`failed`}}function Qo(e,t){let n=ot(Jo),r=Ct({deviceId:e},{enabled:t&&n!==`absent`}),i=()=>Zo(r.refetch);return t?{presence:Xo(n,{status:r.status,data:r.data}),status:r.data?.cameraSensors??null,refetch:i}:{presence:`absent`,status:null,refetch:i}}function $o(e,t){let n=pr({deviceType:e.type}),r=Bn({deviceId:e.id}),i=mn({deviceId:e.id}),a=ni(n,e=>new Set(e.caps.map(e=>e.cap))),o=ni(r,e=>Qr(e.entries)),s=ni(i,e=>e);return{deviceType:e.type,composable:a,nativeCaps:o,wireable:s,composed:new Set((t?.features??[]).map(e=>e.cap))}}function es(e,t,n){let r=t.kind===`known`&&t.value.has(`consumables`),i=$r(r?{deviceId:e,cap:Jr,path:oi}:null);return li(t,n,r?i:null)}e();function ts({device:e}){let{t}=X(),r=e.stableId.startsWith(`composed-`)?e.stableId.slice(Ne.length):null,i=It({blockId:r??``},{enabled:r!==null}),o=Fn(),s=n(()=>{let e=new Set;for(let{cap:t}of ri())e.add(t);for(let{cap:t}of ti())e.add(t);for(let{cap:t}of ai())e.add(t);return e},[]);if(r===null)return d(`p`,{className:`text-xs text-foreground-subtle`,children:t(`customize.composed.missingBlock`)});if(i.status===`pending`)return d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.loadingDevice`)});if(i.status===`error`)return d(Ut,{title:t(`customize.composed.loadFailed`),message:i.error.message,onRetry:()=>void i.refetch()});if(i.data.state===`not-loaded`)return d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.status.notLoaded`,{reason:i.data.reason})});let c=i.data.view;if(c===null)return d(`p`,{className:`text-xs text-foreground-subtle`,children:t(`customize.composed.notFound`)});let l=ve(c.block);if(l===null)return d(`p`,{className:`text-xs text-foreground-subtle`,children:t(`compositionEditor.notComposition`)});let u={target:{addonId:e.addonId,stableId:e.stableId},state:{kind:`present`,view:c,composition:l},saving:o.isPending,save:async e=>{if(e===null)return{kind:`refused`,reason:t(`customize.composed.noDelete`)};try{return await o.mutateAsync({blockId:c.block.id,expectedUpdatedAt:c.block.updatedAt,block:{composition:e}}),await i.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:e instanceof Error?e.message:String(e)}}}};return a(`div`,{className:`flex flex-col gap-3`,children:[d(Za,{device:e}),pi(l)===`incomplete`&&d(J,{variant:`warning`,children:t(`customize.blockStatus.incomplete`)}),d(ii,{device:e,handle:u,skipCaps:s})]})}e();function ns({deviceId:e}){let{t}=X(),n=ln({deviceId:e}),r=n.data;if(r==null)return n.status===`error`?d(Ut,{title:t(`customize.deviceUnreadable`),message:n.error?.message??``,onRetry:()=>void n.refetch()}):r===null?d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.noSuchDevice`,{deviceId:e})}):d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.loadingDevice`)});let i=r.addonId===`composer`?d(ts,{device:r}):d(rs,{device:r,target:{addonId:r.addonId,stableId:r.stableId}});return d(Dr,{deviceId:r.id,seed:{name:r.name,location:r.location??``,role:r.role??null,display:r.display},children:i})}function rs({device:e,target:t}){let r=qo(t),i=ot(`composer`),{t:o}=X(),s=Qo(e.id,e.type===K.Camera),c=$o(e,Ur(r.state)),l=es(e.id,c.nativeCaps,c.wireable),u={deviceType:e.type,composable:c.composable,nativeCaps:c.nativeCaps,cameraSensors:s.presence},f=n(()=>{let e=new Set;for(let{cap:t}of ri())e.add(t);for(let{cap:t}of ti())e.add(t);for(let{cap:t}of ai())e.add(t);return e},[]);return a(`div`,{className:`flex flex-col gap-3`,children:[d(Za,{device:e}),i===`absent`&&d(`p`,{role:`alert`,className:`text-xs text-warning`,children:o(`customize.composerAbsent`)}),r.state.kind!==`none`&&d(is,{state:r.state}),d(Mo,{device:e,handle:r,facts:u,sensors:s}),d(Xr,{device:e,handle:r,facts:u}),d(ci,{device:e,handle:r,facts:u,defaults:l}),d(ii,{device:e,handle:r,skipCaps:f}),d(Go,{device:e})]})}function is({state:e}){let{t}=X();switch(e.kind){case`pending`:return d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.status.pending`)});case`unknown`:return d(Ut,{title:t(`customize.status.unknownTitle`),message:e.reason});case`not-loaded`:return d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.status.notLoaded`,{reason:e.reason})});case`none`:return null;case`present`:{let n=e.view.block;return a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(J,{variant:n.status===`running`?`success`:n.status===`failed`?`danger`:`warning`,children:t(`customize.blockStatus.${n.status}`)}),!n.enabled&&d(J,{variant:`default`,children:t(`customize.status.off`)}),n.lastError!==void 0&&d(`span`,{className:`text-[11px] text-foreground-muted break-words`,children:n.lastError}),e.view.state.kind===`unreachable`&&d(`span`,{className:`text-[11px] text-warning`,children:t(`customize.status.composerUnreachable`,{reason:e.view.state.error})})]})}}}var as=`overview`;function os(e,t){return e.some(e=>e.id===t)?t:as}function ss({deviceId:e}){let{t}=X(),n=c(),r=Number.isFinite(e),{data:i}=ln({deviceId:e},{enabled:r}),o=typeof i?.type==`string`?i.type:`camera`;Zn([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:s,isLoading:l,isError:u,error:f}=Bn({deviceId:e},{enabled:r}),{data:p}=cr({deviceType:o},{enabled:!!o}),m=lt({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(l)return d(`div`,{className:`p-4`,children:d(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(u)return a(`div`,{className:`p-4 text-xs text-red-400`,children:[t(`device.bindingsTab.failedToLoadBindings`,`Failed to load bindings:`),` `,f instanceof Error?f.message:String(f)]});let h=new Map,g={};for(let e of p??[])g[e.capName]=e.wrappers;for(let e of s?.entries??[])h.set(e.capName,{...e,wrappers:g[e.capName]??[]});for(let e of p??[])h.has(e.capName)||h.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let _=[...h.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(_.length===0)return a(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[d(We,{className:`h-8 w-8 opacity-40`}),d(`p`,{className:`text-xs`,children:t(`device.bindingsTab.noCapabilityProvidersApplicableTo`,`No capability providers applicable to this device yet.`)}),d(`p`,{className:`text-[10px] opacity-60`,children:t(`device.bindingsTab.nativeProvidersShowUpHere`,`Native providers show up here as soon as the owning addon registers them.`)})]});let v=_.filter(e=>e.kind!==`unbound`).length,y=[{key:`capability`,header:t(`device.bindingsTab.capability`,`Capability`),render:e=>d(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:t(`device.bindingsTab.kind`,`Kind`),render:e=>d(cs,{kind:e.kind})},{key:`provider`,header:t(`device.bindingsTab.activeProvider`,`Active Provider`),render:e=>d(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||d(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:t(`device.bindingsTab.node`,`Node`),render:e=>e.providerNodeId?d(ls,{nodeId:e.providerNodeId}):d(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:t(`device.bindingsTab.kindNative`,`Native`),render:e=>d(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||d(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:t(`device.bindingsTab.wrapper`,`Wrapper`),render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return d(us,{wrappers:t.wrappers,activeWrapperId:n,disabled:m.isPending,onPick:r=>{let i=n===r;m.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}];return a(`div`,{className:`flex flex-col gap-3 p-1`,children:[d(`div`,{className:`text-[11px] text-foreground-subtle`,children:d(Mr,{i18nKey:`device.bindingsTab.boundSummary`,count:_.length,values:{bound:v},components:{b:d(`span`,{className:`font-medium text-foreground`}),em:d(`em`,{})}})}),d(Rt,{columns:y,rows:_,rowKey:e=>e.capName,minWidthPx:720})]})}function cs({kind:e}){let{t}=X();return e===`native`?a(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[d(ae,{className:`h-3 w-3`}),t(`device.bindingsTab.kindNative`)]}):e===`wrapped`?a(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[d(qe,{className:`h-3 w-3`}),t(`device.bindingsTab.wrapped`)]}):e===`linked`?a(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-warning/30 text-warning bg-warning/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[d(I,{className:`h-3 w-3`}),t(`device.bindingsTab.linked`)]}):a(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[d(x,{className:`h-3 w-3`}),t(`common.unbound`)]})}function ls({nodeId:e}){return d(`span`,{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e===`hub`?`text-foreground-subtle`:`text-foreground`}`,children:e})}function us({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){let{t:i}=X();return e.length===0?d(`span`,{className:`text-[10px] opacity-40`,children:i(`device.bindingsTab.noneAvailable`,`none available`)}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let o=e===t;return a(`button`,{disabled:n,onClick:()=>r(e),title:o?i(`device.bindingsTab.clickToDeactivateRevertTo`,`Click to deactivate (revert to native)`):i(`device.bindingsTab.activateWrapper`,`Activate wrapper {{wrapperId}}`,{wrapperId:e}),className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${o?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[d(o?O:H,{className:`h-3 w-3`}),e]},e)})})}function ds({deviceId:e,activeSubTab:t,onSubTabChange:n,deviceType:r,isAdmin:i}){return a(`div`,{className:`flex flex-col gap-3`,children:[Tr(r,i)&&d(_r,{deviceId:e,readOnly:!0}),d(wr,{deviceId:e,activeSubTab:t,onSubTabChange:n})]})}e();var fs=[[`pipelineOrchestrator`,`getCameraDetectionSource`]];function ps(e){let t=c(),n=$e({deviceId:e},{refetchOnMount:`always`}),a=Ye(),[o,s]=r(null),[l,u]=r(null),d=i(async n=>{u(null),s(n);try{await a.mutateAsync({deviceId:e,source:n}),await t.invalidateQueries({queryKey:fs})}catch(e){u(e instanceof Error?e.message:`Could not change the root detector`),await t.invalidateQueries({queryKey:fs})}finally{s(null)}},[e,a,t]),f=n.data??null;return{view:f,isLoading:n.isLoading,source:o??f?.source??null,saving:o!==null,error:l,pick:d}}var ms=`object-detection`;function hs(e){return[e.addonId,...e.children.flatMap(hs)]}function gs(e,t){if(e===`pipeline`)return new Set;let n=_s(t,ms);return n===void 0?new Set:new Set(e===`onboard`?[n.addonId]:hs(n))}function _s(e,t){for(let n of e){if(n.addonId===t)return n;let e=_s(n.children,t);if(e!==void 0)return e}}function vs(e,t){return e===`onboard`?Y.t(`helpers.detectionSourceModel.badgeCameraAi`):t===`object-detection`?Y.t(`helpers.detectionSourceModel.badgeNoRoot`):Y.t(`helpers.detectionSourceModel.badgeIdle`)}function ys(e){switch(e){case`pipeline`:return Y.t(`helpers.detectionSourceModel.explainPipeline`);case`onboard`:return Y.t(`helpers.detectionSourceModel.explainOnboard`);case`none`:return Y.t(`helpers.detectionSourceModel.explainNone`)}}function bs(e){switch(e){case`boxed`:return``;case`while-streaming`:return Y.t(`helpers.detectionSourceModel.geometryWhileStreaming`);case`flag-only`:return Y.t(`helpers.detectionSourceModel.geometryFlagOnly`);case`unknown`:return Y.t(`helpers.detectionSourceModel.geometryUnknown`)}}function xs(e,t){return e===`onboard`?Y.t(`helpers.detectionSourceModel.noticeOnboard`):t===`object-detection`?Y.t(`helpers.detectionSourceModel.noticeNoRoot`):Y.t(`helpers.detectionSourceModel.noticeIdle`)}var Ss=[`pl-2`,`pl-6`,`pl-10`,`pl-14`],Cs={detector:`success`,cropper:`info`,classifier:`primary`,refiner:`warning`,"audio-classifier":`neutral`};function ws(e){return Ss[Math.min(e,Ss.length-1)]??`pl-2`}function Ts(e){return e.zoneDriven?{kind:`zone-driven`}:{kind:`gate`,effectiveOn:e.ownOn,defaultOn:e.defaultOn,explicit:e.choice!==`auto`}}function Es(e,t,n){return e.kind===`parent`?n:vs(e.source,t)}function Ds({inputs:e,outputs:t}){return e.length===0&&t.length===0?null:a(`span`,{className:`inline-flex flex-wrap items-center gap-1`,children:[e.map(e=>d(J,{size:`sm`,variant:`info`,children:e},`in-${e}`)),e.length>0&&t.length>0&&d(`span`,{className:`text-[10px] text-foreground-subtle`,"aria-hidden":!0,children:`→`}),t.map(e=>d(J,{size:`sm`,variant:`success`,children:e},`out-${e}`))]})}function Os({rows:e,label:t,selectedId:n,busy:r,onOpen:i,onSet:o}){let{t:s}=X(),c=e=>{switch(e){case`detector`:return s(`device.cameraStepInspector.kindDetector`,`detector`);case`cropper`:return s(`device.cameraStepInspector.kindCropper`,`cropper`);case`classifier`:return s(`device.cameraStepInspector.kindClassifier`,`classifier`);case`refiner`:return s(`device.cameraStepInspector.kindRefiner`,`refiner`);case`audio-classifier`:return s(`device.cameraStepInspector.kindAudio`,`audio`)}},l=s(`device.cameraStepInspector.offBecauseParent`,`Off because its parent is off`);return d(`ul`,{"aria-label":t,className:`divide-y divide-border rounded-md border border-border`,children:e.map(e=>{let t=e.stepId===n,s=e.blocked===null?null:Es(e.blocked,e.stepId,l);return a(`li`,{"data-step":e.stepId,"data-runs":e.runs?`yes`:`no`,className:`flex flex-wrap items-center gap-x-2 gap-y-1.5 py-2 pr-2 ${ws(e.depth)} ${t?`bg-primary/10`:e.runs?``:`bg-muted/40`}`,children:[a(`button`,{type:`button`,"aria-expanded":t,onClick:()=>i(e.stepId),className:`flex min-w-0 flex-1 flex-wrap items-center gap-x-2 gap-y-1 text-left`,children:[d(`span`,{className:`text-sm font-medium ${e.runs?`text-foreground`:`text-foreground-muted`}`,children:e.name}),d(J,{size:`sm`,variant:Cs[e.kind],children:c(e.kind)}),d(Ds,{inputs:e.inputs,outputs:e.outputs}),s!==null&&d(`span`,{className:`text-[11px] text-warning`,children:s})]}),d(An,{gate:Ts(e),busy:r,onSet:t=>o(e.stepId,t)})]},e.stepId)})})}function ks(e,t){let n=e?.[t];return n===void 0?`auto`:n?`on`:`off`}function As(e,t){return e===`auto`?t:e===`on`}function js(e,t,n){return e!==`onboard`&&e!==`none`||!n.has(t)?null:{kind:`source`,source:e}}function Ms(e,t,n,r,i){let a=e.zoneDrivenIds??new Set;return t.flatMap(t=>{let o=a.has(t.addonId),s=ks(e.toggles,t.addonId),c=e.defaults[t.addonId]??!0,l=o||As(s,c),u=r===null?js(e.source,t.addonId,i):{kind:`parent`,ancestorId:r.stepId},d={stepId:t.addonId,name:t.addonName,kind:t.slot,depth:n,inputs:t.inputClasses,outputs:t.outputClasses,choice:s,defaultOn:c,ownOn:l,runs:u===null&&l,blocked:u,zoneDriven:o},f=l?r:{stepId:t.addonId};return[d,...Ms(e,t.children,n+1,f,i)]})}function Ns(e){let t=e.source===null?new Set:gs(e.source,e.tree);return Ms(e,e.tree,0,null,t)}function Ps({source:e,geometry:t,saving:n,error:r,onPick:i}){let{t:o}=X(),s=t===`flag-only`,c=bs(t);return a(`section`,{"aria-label":o(`device.detectionSourceControl.rootDetector`,`Root detector`),"aria-busy":n,className:`space-y-1.5 rounded-md border border-border bg-surface px-3 py-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1.5`,children:[d(`h3`,{className:j,children:o(`device.detectionSourceControl.rootDetector`,`Root detector`)}),d(tr,{label:o(`device.detectionSourceControl.rootDetector`,`Root detector`),value:e,onChange:t=>{!n&&t!==e&&i(t)},options:[{value:`pipeline`,label:o(`device.detectionSourceControl.thisNode`,`This node`)},{value:`onboard`,label:o(`device.detectionSourceControl.cameraOnboardAi`,`Camera onboard AI`),disabled:s&&e!==`onboard`,reason:c},{value:`none`,label:o(`device.detectionSourceControl.none`,`None`)}]}),n&&d(`span`,{className:`text-[10px] text-foreground-subtle`,children:o(`device.detectionSourceControl.saving`,`Saving…`)})]}),a(`p`,{className:he,children:[ys(e),` `,o(`device.detectionSourceControl.oneRoot`)]}),c!==``&&d(`p`,{className:`text-[10px] text-foreground-subtle`,children:c}),r!==null&&d(`p`,{role:`alert`,className:`text-[11px] text-danger`,children:r})]})}e();var Fs=new Set([`package-detection`]),Is=`/system/pipeline?view=nodes`;function Ls(e){return Object.fromEntries(e.slots.flatMap(e=>e.addons.map(e=>[e.id,e.enabledByDefault??!0])))}function Rs({deviceId:e}){let{t}=X(),s=mt(),u=$n(),f=c(),p=R().trpcClient,m=l(null),h=l(null),g=Mn({deviceId:e},{refetchOnMount:`always`}),_=Wt(void 0,{refetchOnMount:`always`});Zn([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let{nodes:v}=hn(),y=n(()=>{let e=new Set((_.data??[]).map(e=>e.nodeId));return v.filter(t=>t.isOnline&&e.has(t.id)).map(e=>({id:e.id,name:e.name}))},[_.data,v]),b=y.map(e=>e.id).join(`,`),x=o({enabled:y.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`camera-step-schemas`,b],queryFn:async()=>{let e={};for(let t of y)try{e[t.id]=await p.pipelineExecutor.getSchema.query({nodeId:t.id})}catch{}return e}}),S=i(()=>{f.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]})},[f]),C=zn({onSuccess:S}),w=ar(),[T,E]=r(null),[D,O]=r(!1),[k,A]=r(null),j=ps(e),ee=x.data??{},te=g.data??null,M=y.map(e=>ee[e.id]).find(e=>e!==void 0)??null,ne=n(()=>M?Zt(M):[],[M]),re=n(()=>M===null?[]:Ns({tree:ne,toggles:te?.stepToggles,defaults:Ls(M),source:j.source,zoneDrivenIds:Fs}),[ne,M,te?.stepToggles,j.source]),{selection:N,open:ie,close:ae}=xi(n(()=>re.map(e=>e.stepId),[re]),[]),F=y[0]?.id,oe=i(async e=>{if(T!==null){if(!await s({title:t(`stepInspector.stepMatrixFrame.discardUnsavedChanges`,`Discard unsaved changes?`),message:t(`stepInspector.stepMatrixFrame.thisStepHasChangesThat`,`This step has changes that are not saved yet.`),confirmLabel:t(`stepInspector.stepMatrixFrame.discard`,`Discard`),variant:`danger`}))return;E(null)}e()},[s,T,t]),se=e=>{e!==N.stepId&&oe(()=>ie({stepId:e}))},I=()=>{oe(()=>ae())};if(_.isLoading||y.length>0&&x.isLoading)return d(`div`,{className:`animate-pulse p-4 text-xs text-foreground-subtle`,children:t(`device.cameraStepInspector.loadingPipeline`,`Loading pipeline…`)});if(y.length===0)return d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:t(`device.cameraStepInspector.noPipelineNodeIsOnline`,`No pipeline node is online.`)});if(M===null)return d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:t(`device.cameraStepInspector.catalogUnavailable`,`Catalog unavailable.`)});let L=e=>_.data?.find(e=>e.nodeId===F)?.settings.stepSettings?.[e]??{},z=re.find(e=>e.stepId===N.stepId)??null,B=z===null?null:bi(M,z.stepId),ce=u?d(Sn,{onClick:I}):d(rn,{icon:P,variant:`ghost`,size:`sm`,"aria-label":t(`common.close`,`Close`),onClick:I});return a(`div`,{ref:m,className:`space-y-2`,children:[j.view?.onboard.available===!0&&j.source!==null&&d(Ps,{source:j.source,geometry:j.view.onboard.geometry,saving:j.saving,error:j.error,onPick:e=>void j.pick(e)}),d(`p`,{className:he,children:d(Mr,{i18nKey:`device.cameraStepInspector.modelsChosenByAccelerators`,components:{nodes:d(Br,{to:Is,className:`font-medium text-primary hover:underline`})}})}),N.staleStepId!==null&&d(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-1.5 text-[11px] text-warning`,children:t(`stepInspector.stepMatrixFrame.staleStep`,{id:N.staleStepId})}),d(Os,{rows:re,label:t(`device.cameraStepInspector.detectionStepsOfThisCamera`,`Detection steps of this camera`),selectedId:N.stepId,busy:C.isPending,onOpen:se,onSet:(t,n)=>C.mutate({deviceId:e,addonId:t,enabled:n})}),d(Vn,{open:z!==null&&B!==null,anchor:m,onClose:I,label:t(`stepInspector.stepMatrixFrame.stepSettings`,`Step settings`),children:z!==null&&B!==null&&d(zs,{addon:B,nodeBag:L(z.stepId),storedCamera:te?.stepSettings?.[z.stepId],draft:T?.stepId===z.stepId?T:null,saving:D,status:k,notice:z.blocked?.kind===`source`?xs(z.blocked.source,z.stepId):null,closeButton:ce,onEscape:I,headingRef:e=>{h.current=e},onDraft:e=>{A(null),E({stepId:z.stepId,camera:e})},onDiscard:()=>E(null),onSave:async n=>{O(!0);try{await w.mutateAsync({deviceId:e,addonId:z.stepId,settings:Object.keys(n).length>0?{...n}:null}),E(null),A({kind:`saved`})}catch(e){A({kind:`error`,error:e instanceof Error?e.message:t(`device.cameraStepInspector.saveFailed`)})}finally{O(!1),S()}}})})]})}function zs({addon:e,nodeBag:t,storedCamera:n,draft:r,saving:i,status:o,notice:s,closeButton:c,onEscape:l,headingRef:u,onDraft:f,onDiscard:p,onSave:m}){let{t:h}=X(),g=Yn(e),_=Ci(g),v=Si(g),y=r?.camera??n,b=r!==null&&!je(r.camera,n??{});return d(Je,{ref:u,title:h(`device.cameraStepInspector.thisCamera`,`{{name}} · this camera`,{name:e.name}),subtitle:e.slot,leading:c,onEscape:l,..._.length>0?{saveBar:{dirtyCount:+!!b,saving:i,status:o?.kind??null,...o?.error===void 0?{}:{error:o.error},onSave:()=>void m(r?.camera??n??{}),onDiscard:p,scope:d(`p`,{className:he,children:h(`device.cameraStepInspector.appliesToAllAcceleratorsOf`,`Applies to: all accelerators of this camera.`)})}}:{},children:a(`div`,{className:`space-y-3`,children:[s!==null&&d(`p`,{role:`note`,className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-1.5 text-[11px] text-warning`,children:s}),_.length>0?d(Bs,{addon:e,fields:_,nodeBag:t,cameraBag:y,onChange:f}):d(`p`,{className:he,children:h(`device.cameraStepInspector.noCameraSettings`,`This step has no settings on this camera.`)}),v&&d(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`accelerator-only-thresholds`,children:h(`device.cameraStepInspector.thresholdsAreTheAccelerators`,`Confidence thresholds belong to the model, so they are set on the accelerator that runs it (Pipeline → Nodes), not per camera.`)})]})})}function Bs({addon:e,fields:t,nodeBag:n,cameraBag:r,onChange:i}){let{t:a}=X();return d(gt,{addon:e,fields:t,layers:{node:n,...r===void 0?{}:{camera:r}},target:`camera`,labels:{camera:a(`device.cameraStepInspector.layerCamera`,`This camera`),node:a(`device.cameraStepInspector.layerNode`,`Node`)},modelId:e.defaultModelId,onChangeLayer:i})}function Vs(e,t,n){return{id:e,get label(){return Y.t(t)},icon:n}}var Hs=[Vs(`object-detection`,`helpers.detectionSettingsGroups.objectDetection`,`scan-search`),Vs(`tracking`,`helpers.detectionSettingsGroups.tracking`,`route`),Vs(`motion`,`helpers.detectionSettingsGroups.motion`,`activity`),Vs(`stationary`,`helpers.detectionSettingsGroups.stationary`,`square-parking`),Vs(`zones`,`helpers.detectionSettingsGroups.zones`,`shapes`),Vs(`audio`,`helpers.detectionSettingsGroups.audio`,`volume-2`),Vs(`cluster`,`helpers.detectionSettingsGroups.cluster`,`server`)],Us={"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 Ws(e){return Us[e]??`object-detection`}e();var Gs=`steps`,Ks=`settings`,qs=new Set([Gs,Ks]);function Js(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function Ys({deviceId:e,activeSubTab:t,onSubTabChange:n}){let{t:r}=X();return a(Pt,{value:t&&qs.has(t)?t:Gs,onValueChange:i(e=>{n?.(e)},[n]),className:`flex flex-col`,children:[a(tt,{className:`flex-shrink-0`,children:[d(Jt,{value:Gs,children:r(`device.detectionPipelineTab.steps`,`Steps`)}),d(Jt,{value:Ks,children:r(`device.detectionPipelineTab.settings`,`Settings`)})]}),d(yr,{value:Gs,children:d(Rs,{deviceId:e})}),d(yr,{value:Ks,children:d(wr,{deviceId:e,sectionFilter:Js,subTabGrouping:{groupOf:e=>Ws(e.id),tabs:Hs}})})]})}var Xs=`Notifications`,Zs={i18nKey:`device.deviceNotificationMute.cameraCostWhenOff`,text:`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`},Qs={i18nKey:`device.deviceNotificationMute.deviceCostWhenOff`,text:`This device never notifies — no rule, no target, no alarm.`};function $s(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:Xs,on:r===null?null:i??r,available:r!==null,costWhenOff:e.isCamera?Zs:Qs}}function ec(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}e();function tc(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function nc({deviceId:e,isCamera:t}){let{t:n}=X(),o=c(),s=Number.isFinite(e),[l,u]=r(null),[f,p]=r(null),m=$s({mutedDeviceIds:tc(Qn({},{enabled:s}).data),deviceId:e,isCamera:t,pendingOn:f}),h=n(m.costWhenOff.i18nKey,m.costWhenOff.text),g=sn({onError:t=>{console.error(`[DeviceNotificationMute] mute write failed — reverting`,{tags:{deviceId:e},meta:{error:t instanceof Error?t.message:String(t)}}),p(null),u(t instanceof Error?t.message:String(t)),o.invalidateQueries({queryKey:[[`notificationRules`,`listDeviceMutes`]]})},onSuccess:()=>{u(null),p(null),o.invalidateQueries({queryKey:[[`notificationRules`]]})}}),_=i(()=>{let t=ec(m,e);t!==null&&(p(!t.muted),g.mutate(t))},[e,g,m]),v=m.on===null,y=m.on===!1,b=y?Ue:D;return a(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[a(`div`,{className:`border-b border-border px-4 py-2 flex items-center justify-between gap-2`,children:[d(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:n(`device.deviceNotificationMute.notifications`,`Notifications`)}),y&&d(`span`,{className:`rounded bg-warning/20 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide text-warning`,children:n(`common.muted`)})]}),a(`div`,{className:`px-4 py-3 flex items-start gap-3`,children:[a(`button`,{type:`button`,role:`switch`,"aria-label":m.label,"aria-checked":m.on===!0,disabled:!m.available||g.isPending,onClick:_,title:v?n(`device.deviceNotificationMute.notificationMuteStateUnknownThe`,`Notification mute — state unknown; the notification centre did not answer.`):y?n(`device.deviceNotificationMute.muted`,`Muted. {{costWhenOff}}`,{costWhenOff:h}):n(`device.deviceNotificationMute.notifyingMutingIt`,`Notifying. Muting it: {{costWhenOff}}`,{costWhenOff:h}),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 ${l===null?v?`border-dashed border-border text-foreground-subtle/50`:y?`border-warning/40 text-warning hover:bg-warning/10`:`border-success/30 text-success hover:bg-success/10`:`border-danger/50 text-danger bg-danger/5`}`,children:[d(b,{className:`h-3.5 w-3.5`}),d(`span`,{children:v?n(`device.deviceNotificationMute.unknown`,`Unknown`):y?n(`device.deviceNotificationMute.muted2`,`Muted`):n(`device.deviceNotificationMute.notifying`,`Notifying`)})]}),d(`p`,{className:`flex-1 text-[11px] leading-relaxed text-foreground-subtle`,children:l===null?v?n(`device.deviceNotificationMute.theNotificationCentreDidNot`,`The notification centre did not answer, so this device’s mute state is unknown.`):h:n(`device.deviceNotificationMute.writeFailed`,`Write failed: {{failure}}`,{failure:l})})]})]})}function rc(e,t){return{switchId:e,label:Le[e].label,detail:t===void 0||t.length===0?null:t}}function ic(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 ac(e){let t=ic(e),n=new Set(e.sourceStillLive),r=e.sourceStillLive.map(e=>rc(e,t.get(e)?.detail)),i=[...t.values()].filter(e=>e.outcome===`not-offered`&&!n.has(e.switchId)).map(e=>rc(e.switchId,e.detail));return{inheritedId:e.sourceId,retiredId:e.targetId,swapped:e.swapped,verdict:r.length===0?`quiet`:`still-live`,stillLive:r,neverOffered:i}}e();function oc(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 sc({deviceId:e,deviceName:t}){let{t:i}=X(),o=mt(),[s,c]=r(null),l=Rn({isCamera:!0,projection:`slim`}),u=En(),f=l.data!==void 0,p=n(()=>l.data===void 0?[]:oc(l.data,e),[l.data,e]),m=p.find(e=>e.id===s)??null,h=u.data===void 0?null:ac(u.data),g=u.error===null?null:u.error.message,_=async()=>{m===null||m.id===e||await o({title:i(`deviceMigrate.confirmTitle`,`Replace “{{source}}” with “{{target}}”?`,{source:t,target:m.name}),message:i(`deviceMigrate.confirmMessage`,`“{{target}}” takes over number {{sourceId}}. That number is what every recording, event, rule, zone and home-automation export of “{{source}}” is filed under, so all of it follows the number to the new hardware and keeps working. “{{source}}” is switched off and handed number {{targetId}} in exchange. This swaps two device identities and cannot be undone from here.`,{source:t,target:m.name,sourceId:e,targetId:m.id}),confirmLabel:i(`deviceMigrate.confirmAction`,`Migrate`),variant:`danger`})&&u.mutate({sourceId:e,targetId:m.id})};return a(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[a(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[a(`div`,{className:`min-w-0`,children:[d(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:i(`deviceMigrate.title`,`Migrate to…`)}),d(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:i(`deviceMigrate.subtitle`,`Replace this camera with other hardware you have already adopted. The new camera inherits number {{deviceId}}, so recordings, rules and integrations follow it.`,{deviceId:e})})]}),a(`div`,{className:`flex shrink-0 items-center gap-2`,children:[a(`select`,{"aria-label":i(`deviceMigrate.pickerLabel`,`Replacement camera`),className:`rounded-md border border-border bg-background px-2 py-1.5 text-xs text-foreground disabled:opacity-50`,disabled:!f||p.length===0||u.isPending,value:s===null?``:String(s),onChange:e=>{let t=e.target.value;c(t===``?null:Number(t))},children:[d(`option`,{value:``,children:f?i(`deviceMigrate.pickerPlaceholder`,`Select a camera…`):i(`deviceMigrate.pickerPending`,`Reading the fleet…`)}),p.map(e=>a(`option`,{value:String(e.id),children:[e.name,` (#`,e.id,`)`]},e.id))]}),a(`button`,{type:`button`,disabled:m===null||u.isPending,onClick:()=>{_()},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[d(ze,{className:`h-3 w-3`}),u.isPending?i(`deviceMigrate.running`,`Migrating…`):i(`deviceMigrate.action`,`Migrate`)]})]})]}),f&&p.length===0&&d(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:i(`deviceMigrate.noTargets`,`No other camera is adopted, so there is nothing to migrate to.`)}),g!==null&&d(`p`,{className:`mt-2 text-[11px] text-danger`,children:i(`deviceMigrate.failed`,`Migration failed: {{error}}`,{error:g})}),h!==null&&d(cc,{report:h})]})}function cc({report:e}){let{t}=X(),n=e.verdict===`quiet`;return a(`div`,{className:`mt-3 space-y-2 border-t border-border pt-3`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`deviceMigrate.swapped`,`The replacement now answers on number {{inheritedId}}; the old camera was handed number {{retiredId}}.`,{inheritedId:e.inheritedId,retiredId:e.retiredId})}),n?a(`div`,{className:`flex items-start gap-2 rounded-md border border-success/30 bg-success/5 px-3 py-2`,children:[d(z,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-success`}),d(`p`,{className:`text-[11px] leading-relaxed text-foreground`,children:t(`deviceMigrate.quiet`,`Every function on the replaced camera was switched off — the old hardware is quiet.`)})]}):a(`div`,{className:`rounded-md border border-warning/40 bg-warning/5 px-3 py-2`,children:[a(`div`,{className:`flex items-start gap-2`,children:[d(V,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),d(`p`,{className:`text-[11px] leading-relaxed text-foreground`,children:t(`deviceMigrate.stillLive`,`The replaced camera could not be reached, so these functions are STILL RUNNING on the old hardware. Nothing here failed to migrate — but until you unplug it or reach it physically, it can still produce data.`)})]}),d(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.stillLive.map(e=>a(`li`,{className:`text-[11px] text-foreground`,children:[d(`span`,{className:`font-medium`,children:e.label}),e.detail!==null&&a(`span`,{className:`text-foreground-subtle`,children:[` — `,e.detail]})]},e.switchId))})]}),e.neverOffered.length>0&&a(`div`,{className:`rounded-md border border-border px-3 py-2`,children:[a(`div`,{className:`flex items-start gap-2`,children:[d(Ke,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),d(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`deviceMigrate.neverOffered`,`The replaced camera never offered these, so there was nothing to switch off. They are not running.`)})]}),d(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.neverOffered.map(e=>d(`li`,{className:`text-[11px] text-foreground-subtle`,children:e.label},e.switchId))})]})]})}e();function lc({deviceId:e}){let{t}=X(),[n,i]=r(null),o=vt({onSuccess:e=>{i(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>i(`Re-sync failed: ${e.message}`)});return a(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[a(`div`,{className:`flex items-center justify-between gap-3`,children:[a(`div`,{children:[d(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:t(`device.resyncButton.reSync`,`Re-sync`)}),d(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:t(`device.resyncButton.reAlignThisDeviceS`,`Re-align this device's type, role, capabilities and units with its source.`)})]}),a(`button`,{type:`button`,disabled:o.isPending,onClick:()=>{i(null),o.mutate({camDeviceId:e})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[d(ie,{className:`h-3 w-3 ${o.isPending?`animate-spin`:``}`}),o.isPending?t(`device.resyncButton.reSyncing`,`Re-syncing…`):t(`device.resyncButton.reSync`,`Re-sync`)]})]}),n!==null&&d(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:n})]})}function uc(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function dc({device:e}){let{t}=X(),n=Or(),r=typeof e.id==`number`?e.id:null,i=String(e.type??``),o=i===K.Camera,s=i===K.Hub,c=e.features??[],l=c.includes(ye.Resyncable),{data:u}=tn({deviceId:r??0},{enabled:r!==null&&o,refetchInterval:5e3}),f=u?.streams??{},p=Object.entries(f),m=c.includes(ye.DoorbellButton),h=kn(m?{deviceId:r??void 0,historyLimit:10}:void 0),g=h.latest?Date.now()-h.latest.timestamp<3e4:!1;return a(`div`,{className:`space-y-5`,children:[s&&r!==null&&d(it,{deviceId:r,onOpenChild:e=>n(`/devices/${e}`)}),l&&r!==null&&d(lc,{deviceId:r}),o&&r!==null&&d(sc,{deviceId:r,deviceName:String(e.name??``)}),r!==null&&d(nc,{deviceId:r,isCamera:o}),o&&r!==null&&d(lr,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:r}),m&&d(Bt,{history:h.history,latestIsFresh:g}),o&&r!==null&&d(lr,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:r}),o&&p.length>0&&a(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[d(`div`,{className:`border-b border-border px-4 py-2`,children:d(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:t(`device.overviewTab.streamNetwork`,`Stream Network`)})}),d(`div`,{className:`divide-y divide-border`,children:p.map(([e,n])=>a(`div`,{className:`px-4 py-2.5`,children:[a(`div`,{className:`flex items-center gap-2 mb-2`,children:[d(oe,{className:`h-3 w-3 text-foreground-subtle`}),d(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),a(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[d(fc,{label:t(`device.overviewTab.nominal`,`Nominal`),value:uc(n.nominalBitrateKbps??0)}),d(fc,{label:t(`device.overviewTab.observed`,`Observed`),value:uc(n.observedBitrateKbps??0)}),d(fc,{label:t(`device.overviewTab.peak`,`Peak`),value:uc(n.peakBitrateKbps??0)}),d(fc,{label:t(`device.overviewTab.packetLoss`,`Packet Loss`),value:`${(n.packetLossPercent??0).toFixed(2)}%`,warning:(n.packetLossPercent??0)>1})]})]},e))})]}),d(Pr,{})]})}function fc({label:e,value:t,warning:n}){return a(`div`,{children:[d(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),d(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}var pc=`history`,mc=[{id:`overview`,labelKey:`helpers.structuralTabs.overview`,cameraOnly:!1,adminOnly:!1},{id:`config`,labelKey:`helpers.structuralTabs.config`,cameraOnly:!1,adminOnly:!1},{id:Fr,labelKey:`helpers.structuralTabs.customize`,cameraOnly:!1,adminOnly:!0},{id:pc,labelKey:`helpers.structuralTabs.history`,cameraOnly:!1,adminOnly:!1},{id:`detection-pipeline`,labelKey:`helpers.structuralTabs.detectionPipeline`,cameraOnly:!0,adminOnly:!1},{id:`bindings`,labelKey:`helpers.structuralTabs.bindings`,cameraOnly:!0,adminOnly:!1}],hc=new Set([K.Hub,K.Container]);function gc(e,t){let n=e===K.Camera,r=e===void 0||!hc.has(e);return mc.filter(e=>(n||!e.cameraOnly)&&(t||!e.adminOnly)&&(r||e.id!==`history`)).map(({id:e,labelKey:t})=>({id:e,label:Y.t(t)}))}function _c({provider:e,integrationId:t,name:n}){let r=Or(),i=t===null?`/integrations`:`/integrations/${t}`,a=n===null?`Open integrations`:`Open integration ${n}`;return d(`button`,{type:`button`,onClick:()=>r(i),className:`shrink-0 rounded-md transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-1 focus-visible:ring-primary/50`,title:a,"aria-label":a,children:d(Rr,{type:e,size:`lg`})})}e();var vc=[{id:`logs`,icon:B,labelKey:`common.logs`},{id:`repl`,icon:Ge,labelKey:`deviceDetail.repl`},{id:`events`,icon:T,labelKey:`common.events`},{id:`state`,icon:S,labelKey:`common.state`}];function yc(){let{t:e}=X(),t=ue(),o=Ir(),u=Number(o.deviceId),f=Number.isFinite(u),p=Or(),m=c(),_=mt(),v=R(),{user:b}=xr(),x=b?.isAdmin===!0,[S,C]=Nr(),w=S.get(`tab`)??`overview`,T=S.get(`sub`),[E,D]=r(`logs`),O=`device-detail.left-col-width-px`,[k,A]=r(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(O),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),j=l(k);j.current=k;function te(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??k??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{A(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=j.current;if(e!==null)try{window.localStorage.setItem(O,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:M,isLoading:ne,isError:re}=ln({deviceId:u},{enabled:f,refetchInterval:5e3,retry:1}),{data:N}=Gn({deviceId:u},{enabled:f}),ae=n(()=>{let e=N?.settings?.sections??[],t=N?.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(Ar)&&r.add(jr),[...r].map(e=>e===`export`?{id:e,label:Sr,isAddonContrib:!0}:{id:e,label:Me[e]?.label??e,isAddonContrib:!0})},[N]),P=M,F=String(P?.name??o.deviceId??`Device`),oe=P?.online===!0,se=oe?`online`:`offline`,I=String(P?.addonId??`rtsp`),L=P?.features??[],z=P?.type,B=z===K.Camera,{data:le}=kr(f?u:0),fe=z===K.Container,pe=n(()=>(le??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[le]),V=n(()=>fe?Xt(pe,typeof P?.linkDeviceId==`number`?P.linkDeviceId:null,typeof P?.primaryChildEntityId==`string`?P.primaryChildEntityId:null)?.id??null:null,[fe,pe,P?.linkDeviceId,P?.primaryChildEntityId]),{data:H}=Gn({deviceId:V??0},{enabled:V!==null}),he=n(()=>{if(V===null)return[];let e=H?.settings?.sections??[],t=H?.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:Me[e]?.label??e,isAddonContrib:!0,childDeviceId:V}))},[V,H]),ge=n(()=>_a({sections:[...N?.settings?.sections??[],...N?.live?.sections??[]],deviceId:u,...V===null?{}:{child:{sections:[...H?.settings?.sections??[],...H?.live?.sections??[]],deviceId:V}}}),[N,H,u,V]),_e=typeof P?.parentDeviceId==`number`?P.parentDeviceId:null,{data:ve}=ln({deviceId:_e??0},{enabled:_e!==null}),U=$n(),be=P?.disabled!==!0,xe=n(()=>{let e=N?.settings?.sections??[],t=N?.live?.sections??[];return Cr([...e,...t],z,x,N!==void 0)},[N,z,x]),Se=n(()=>{let e=new Set,t=[];for(let n of[...gc(z,x),...ae,...he])n.id===`config`&&!xe||e.has(n.id)||(e.add(n.id),t.push(n));return t},[z,x,ae,he,xe]),Ce=n(()=>os(Se,w),[Se,w]),we=i(e=>{C(t=>{let n=new URLSearchParams(t);e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`);for(let e of yi)n.delete(e);return n},{replace:!0})},[C]),Te=i(e=>{C(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[C]),Ee=(le??[]).length>0,W=n(()=>vc.filter(({featureGate:e})=>!e||L.includes(e)),[L]),{data:De}=rr(void 0),Oe=n(()=>P?Pn(P,De):null,[P,De]),G=Oe?.kind===`resolved`?Oe.integration:null,ke=G===null?Oe?.kind===`unknown`?e(`deviceDetail.loadingIntegration`):Oe?.kind===`orphan`?e(`deviceDetail.missingIntegration`):e(`deviceDetail.noIntegration`):G.name,Ae=G!==null&&G.addonId===I?G.name:I,je=gr({onSuccess:()=>{m.invalidateQueries({queryKey:[[`deviceManager`]]}),p(G?.id?`/integrations/${G.id}`:`/integrations`)}}),Ne=or({onSuccess:()=>{m.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Pe=Qt({onSuccess:()=>{m.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=at(),Ie=Vt({onSuccess:()=>{m.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=L.includes(ye.Rebootable),Re=L.includes(ye.BatteryOperated),ze=Ft(v.trpcClient,Re&&f?u:null),Be=xt(v.trpcClient,f?u:null),Ve=ce(v.trpcClient,f?u:null,e=>e.runningState),He=Ve===void 0||Ve.running===null?null:Ve.running,Ue=sr(z??`unknown`,t).icon,[We,Ge]=r(!1),Ke=async()=>{if(!We){Ge(!0);try{let e=F.replace(/[^a-zA-Z0-9_.-]+/g,`_`),t=new Date().toISOString().replace(/[:.]/g,`-`);await Pi(`${ee}/${String(u)}.jpg?force=1`,`${e}-${t}.jpg`)}finally{Ge(!1)}}},qe=Ne.isPending||Pe.isPending,{data:Je}=Nt({deviceId:u},{enabled:f&&B,refetchInterval:1e4}),Ye=Je?.agentNodeId??null,Xe=typeof Ye==`string`&&Ye.length>0&&!Ye.startsWith(`addon:`)?Ye:void 0,{data:Ze}=Cn({deviceId:u,...Xe?{nodeId:Xe}:{}},{enabled:f&&B,refetchInterval:3e3,retry:!1}),{data:Qe}=qt({deviceId:u},{enabled:f&&B,refetchInterval:3e3,retry:!1}),$e=Qe?.level?.dbfs??null;function tt(){if(!f)return null;switch(Ce){case`overview`:return d(dc,{device:P??{}});case`config`:return d(ds,{deviceId:u,activeSubTab:T,onSubTabChange:Te,deviceType:z,isAdmin:x});case`detection-pipeline`:return d(Ys,{deviceId:u,activeSubTab:T,onSubTabChange:Te});case`bindings`:return d(ss,{deviceId:u});case pc:return d(Ln,{deviceId:u,onNavigate:e=>p(e)});case Fr:return d(ns,{deviceId:u});default:{let e=Ce,t=ae.some(t=>t.id===e),n=he.find(t=>t.id===e);if(!t&&n===void 0)return null;let r=n?.childDeviceId??u;if(e===`export`)return d(wr,{deviceId:u,sectionFilter:Ar,activeSubTab:T,onSubTabChange:Te});let i=d(wr,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:T,onSubTabChange:Te});return n!==void 0&&r!==u?d(bt,{deviceId:r,children:i}):i}}}return f?ne?a(`div`,{className:`flex flex-col h-full`,children:[a(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[d(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),d(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),d(`div`,{className:`flex-1 p-6`,children:d(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):re||!M?a(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[d(`p`,{className:`text-lg font-semibold text-foreground`,children:e(`deviceDetail.deviceNotFound`,`Device not found`)}),d(`p`,{className:`text-xs`,children:d(Mr,{i18nKey:`deviceDetail.noDeviceWithId`,values:{id:u},components:{code:d(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`})}})}),d(`button`,{onClick:()=>p(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:e(`deviceDetail.backToIntegrations`,`Back to Integrations`)})]}):a(`div`,{className:`absolute inset-0 flex flex-col overflow-clip`,children:[a(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[d(`div`,{className:`mb-2`,children:d(Ht,{items:[{label:e(`deviceDetail.integrations`,`Integrations`),onClick:()=>p(`/integrations`)},G===null?{label:ke}:{label:ke,onClick:()=>p(`/integrations/${G.id}`)},{label:F}]})}),a(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[G!==null&&d(_c,{provider:G.addonId,integrationId:G.id,name:G.name}),d(Nn,{running:He,children:d(Ue,{className:`h-5 w-5 text-foreground-subtle shrink-0`,"aria-hidden":!0})}),a(`div`,{className:`min-w-0 flex-1`,children:[a(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[d(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:F}),d(un,{status:se}),Re&&d(Tt,{status:ze,variant:`full`}),d(et,{status:Be})]}),_e!==null&&ve&&a(`button`,{type:`button`,onClick:()=>p(`/devices/${_e}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:e(`deviceDetail.openParentDevice`,`Open parent device {{name}}`,{name:ve.name}),children:[d(`span`,{children:`↑`}),d(`span`,{className:`truncate`,children:String(ve.name??`Device #${_e}`)})]}),d(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:L.length>0&&d(Er,{capabilities:L})})]}),Ze&&d(`div`,{className:`hidden lg:flex`,children:d(bc,{metrics:Ze,dbfs:$e})}),a(`div`,{className:`flex items-center gap-1 shrink-0`,children:[a(`button`,{onClick:async()=>{be?await _({title:e(`deviceDetail.disable`,`Disable "{{name}}"?`,{name:F}),message:e(`deviceDetail.theDeviceWillStopProcessing`,`The device will stop processing streams and events. You can re-enable it later.`),confirmLabel:e(`common.disable`,`Disable`),variant:`danger`})&&Pe.mutate({deviceId:u}):Ne.mutate({deviceId:u})},disabled:qe,title:be?e(`deviceDetail.disableDevice`,`Disable device`):e(`deviceDetail.enableDevice`,`Enable device`),className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border transition-colors disabled:opacity-50 ${be?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[d(g,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden sm:inline`,children:qe?e(`deviceDetail.updating`,`Updating…`):be?e(`deviceDetail.enabled`,`Enabled`):e(`deviceDetail.disabled`,`Disabled`)})]}),d(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),B&&a(s,{children:[d(Vi,{deviceId:u}),d(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),d(Ui,{deviceId:u}),d(vr,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:e(`deviceDetail.takeSnapshot`,`Take snapshot`),description:e(`deviceDetail.fetchAFreshFrameAnd`,`Fetch a fresh frame and download it.`),icon:h,disabled:We,onClick:()=>{Ke()}},{id:`reboot`,label:e(`deviceDetail.rebootDevice`,`Reboot device`),description:e(`deviceDetail.cameraGoesOfflineFor30`,`Camera goes offline for ~30 seconds.`),icon:me,hidden:!Le,disabled:Fe.isPending,danger:!0,onClick:async()=>{await _({title:e(`deviceDetail.reboot`,`Reboot "{{name}}"?`,{name:F}),message:e(`deviceDetail.theCameraWillGoOffline`,`The camera will go offline for around 30 seconds while the firmware reboots.`),confirmLabel:e(`deviceDetail.reboot2`,`Reboot`),variant:`danger`})&&Fe.mutate({deviceId:u})}},{id:`restart-addon`,label:e(`deviceDetail.restartAddon`,`Restart addon`),description:e(`deviceDetail.bouncesEveryDeviceServedBy`,`Bounces every device served by {{servingAddonLabel}}.`,{servingAddonLabel:Ae}),icon:ie,disabled:Ie.isPending,danger:!0,onClick:async()=>{await _({title:e(`deviceDetail.restart`,`Restart "{{servingAddonLabel}}"?`,{servingAddonLabel:Ae}),message:e(`deviceDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device served by it (not just "{{name}}"). Streams will reconnect automatically.`,{name:F}),confirmLabel:e(`deviceDetail.restart2`,`Restart`),variant:`danger`})&&Ie.mutate({addonId:I})}},{id:`delete`,label:e(`deviceDetail.deleteDevice`,`Delete device`),description:e(`deviceDetail.removeTheDeviceAndAll`,`Remove the device and all its settings.`),icon:y,separatorBefore:!0,disabled:je.isPending,danger:!0,onClick:async()=>{await _({title:e(`deviceDetail.delete`,`Delete "{{name}}"?`,{name:F}),message:e(`deviceDetail.thisWillRemoveTheDevice`,`This will remove the device and all its settings. This action cannot be undone.`),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&je.mutate({deviceId:u})}}]})]})]})]}),d(bt,{deviceId:u,device:P??void 0,children:d(mr,{children:d(fr,{children:d(de,{children:d(dn,{children:a(`main`,{className:U?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[a(`div`,{className:U?`flex flex-col bg-surface`:`${k===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-y-auto`,style:!U&&k!==null?{width:`${String(k)}px`}:void 0,children:[d(`div`,{className:B?`flex-shrink-0 border-b border-border-subtle bg-black`:U?`flex-shrink-0 border-b border-border-subtle bg-surface`:`shrink-0 border-b border-border-subtle bg-surface`,children:B?d(Da,{deviceId:u,intercomAvailable:L.includes(ye.TwoWayAudio)}):a(`div`,{children:[d(ma,{deviceId:u,deviceName:F,deviceType:z??`unknown`,provider:I,isOnline:oe,features:L}),d(ha,{deviceId:u,widgets:ge})]})}),B&&ge.length>0&&d(`div`,{className:`flex-shrink-0 border-b border-border-subtle bg-surface pt-3 sm:pt-4`,children:d(ha,{deviceId:u,widgets:ge})}),a(`div`,{className:U?`flex flex-col border-b border-border`:`flex-1 min-h-64 flex flex-col overflow-hidden`,children:[d(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:d(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:W.map(({id:t,labelKey:n,icon:r})=>{let i=E===t;return a(`button`,{onClick:()=>D(t),title:e(n),className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${i?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[d(r,{className:`h-3 w-3`}),e(n)]},t)})})}),a(`div`,{className:U?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[E===`logs`&&d(Oa,{deviceId:u,containerDeviceId:z===`container`?u:void 0}),E===`repl`&&d(ka,{deviceId:u}),E===`events`&&d(Aa,{deviceId:u}),E===`state`&&d(ja,{deviceId:u})]})]})]}),!U&&d(`div`,{role:`separator`,"aria-orientation":`vertical`,title:e(`deviceDetail.dragToResize`,`Drag to resize`),onMouseDown:te,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:d(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),a(`div`,{className:U?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[d(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:d(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:Se.map(e=>{let t=Ce===e.id;return a(`button`,{onClick:()=>we(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&d(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),a(`div`,{className:U?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[Ce===`overview`&&Ee&&d(Wi,{parentDeviceId:u}),tt()]})]})]})})})})})})]}):a(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[d(`p`,{className:`text-lg font-semibold text-foreground`,children:e(`deviceDetail.invalidDeviceId`,`Invalid device id`)}),d(`p`,{className:`text-xs`,children:d(Mr,{i18nKey:`deviceDetail.invalidSegment`,values:{segment:o.deviceId},components:{code:d(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`})}})}),d(`button`,{onClick:()=>p(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:e(`deviceDetail.backToIntegrations`,`Back to Integrations`)})]})}function bc({metrics:e,dbfs:t}){let n=ue(),{t:r}=X(),i=pn(e.phase??`idle`,n);return a(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[a(`div`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`h-1.5 w-1.5 rounded-full ${i.dotClass}`}),d(`span`,{className:`text-[10px] font-medium ${i.textColor}`,children:i.label})]}),d(`div`,{className:`h-3 w-px bg-border`}),a(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[d(fe,{className:`h-3 w-3`}),d(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),d(`span`,{children:r(`common.fpsWord`)})]}),a(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[d(M,{className:`h-3 w-3`}),d(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),d(`span`,{children:`ms`})]}),a(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:r(`deviceDetail.currentAudioLevelDbfs`,`Current audio level (dBFS)`),children:[d(k,{className:`h-3 w-3`}),d(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),d(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&a(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{yc as DeviceDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$ as e,G as t,J as n,S as r,b as i,i as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Ci as s,It as c,bn as l,dt as u,hn as d,or as f,ot as p,sa as m,yr as h}from"./player-overlays-B_ZfVBiA.js";import{ki as g,or as _}from"./client-DIBstlq5.js";import{A as v,C as y,Cn as b,Cr as x,D as S,Dr as C,E as w,Er as T,Hr as E,La as D,M as O,N as k,O as A,Or as j,P as M,Ra as N,S as ee,Sn as P,Tr as F,Ur as te,Wl as ne,Wr as I,Zr as L,_ as re,_r as ie,b as R,bn as z,d as ae,dd as oe,dr as se,f as ce,fn as le,fr as ue,gr as de,h as fe,hr as pe,j as me,k as he,lo as B,m as ge,pn as _e,pr as ve,u as ye,v as be,w as xe,x as V}from"./src-BVr0SnD-.js";import{t as H}from"./useTranslation-D3Is_4B6.js";import{mr as Se}from"./index-Cskol4XA.js";import{t as Ce}from"./AdminPage-B-1YjUaD.js";e();function U(e,t){return e.scope===``?e.displayName:`${e.displayName} · ${t?.(e)??e.scope}`}function we(e,t,n){let r=[];for(let{device:t,series:i}of e)for(let e of i){let i={subject:{kind:`device`,deviceId:t.id},key:e.key,scope:e.scope};r.push({id:V(i),ref:i,info:e,subjectName:t.name,location:t.location??``,nodeId:``,metric:U(e,n)})}for(let{node:e,series:i}of t)for(let t of i){let i={subject:{kind:`node`,nodeId:e.id},key:t.key,scope:t.scope};r.push({id:V(i),ref:i,info:t,subjectName:e.name,location:``,nodeId:e.id,metric:U(t,n)})}return r}function Te(e){return[e.subjectName,e.location,e.metric,e.info.key,e.info.unit??``,e.nodeId].join(` `)}var Ee=[`energy`,`temperatures`,`nodes`,`storage`],De=new Set([`cap:temperature-sensor.celsius`,`cap:climate-control.currentTemp`]),W=[`addon:metrics-native/node-cpu-percent`,`addon:metrics-native/node-memory-percent`],Oe=`addon:storage-orchestrator/location-used-percent`;function ke(e,t){let n=(e,n)=>{let r=t.filter(e);return R((n?[...r].sort(n):r).map(e=>e.ref))};switch(e){case`energy`:return n(e=>e.ref.subject.kind===`device`&&e.info.key===`derived:energy.kwh`);case`temperatures`:return n(e=>e.ref.subject.kind===`device`&&De.has(e.info.key)&&e.info.scope===``,(e,t)=>e.location.localeCompare(t.location)||e.subjectName.localeCompare(t.subjectName));case`nodes`:return n(e=>e.ref.subject.kind===`node`&&W.includes(e.info.key)&&e.info.scope===``,(e,t)=>W.indexOf(e.info.key)-W.indexOf(t.info.key)||e.subjectName.localeCompare(t.subjectName));case`storage`:return n(e=>e.ref.subject.kind===`node`&&e.info.key===Oe)}}function Ae(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=[],a=[],o=[];for(let t of R(e)){let e=n.get(V(t));if(e===void 0){o.push(t);continue}e.info.key===`derived:energy.kwh`?a.push(e):e.info.kind===`boolean`||e.info.kind===`enum`?i.push(e):r.push(e)}return{lines:r,states:i,energy:a,missing:o}}function G(e){return e.subject.kind===`device`?{deviceId:e.subject.deviceId,key:e.key,scope:e.scope}:{forNodeId:e.subject.nodeId,key:e.key,scope:e.scope}}var K=`history-page`;function q(e){return`${e.subjectName} · ${e.metric}`}function je({part:e,window:n}){let{t:i}=H(),a=m(),c=t(()=>[...e.lines,...e.states,...e.energy],[e]),l=ge(t(()=>c.map(e=>G(e.ref)),[c]),n,!1),u=e=>l.status===`ok`?l.data.current.get(ce(G(e.ref))):void 0,d=e=>{let t=u(e);return t?.ok?t.result:void 0};if(c.length===0)return o(T,{icon:s,title:i(`history.page.emptyTitle`,`Pick series to compare`),description:i(`history.page.emptyHint`,`Choose up to 24 series on the left, or start from a panel above.`)});if(l.status===`error`)return o(F,{title:i(`history.page.readFailed`,`History could not be read`),message:l.error});let f=l.status===`pending`,p=c.map(e=>({c:e,e:u(e)})).filter(e=>e.e?.ok===!1),h=e.lines.map((e,t)=>{let r=d(e),i=S(e.info,r,n.from);return{id:e.id,label:q(e),unit:e.info.unit,colorIndex:t,points:i.points,gapMs:i.gapMs,interpolation:i.held&&r?.resolution===`raw`?`step`:`linear`}}),g=e.states.map((e,t)=>{let r=A(e.info,d(e),n.from,n.to),i=xe(e.info.key,a);return{id:e.id,label:q(e),kind:e.info.kind===`boolean`?`boolean`:`enum`,colorIndex:e.info.kind===`boolean`?t:0,states:r.states,segments:r.segments,totals:r.totals,stateLabel:e.info.kind===`boolean`?e=>e===`true`?i.on:i.off:void 0}}),_=e.energy.map(e=>({c:e,...w(d(e))})),v=_[0]?.bucketMs??36e5,y=[...new Set(_.flatMap(e=>e.buckets.map(e=>e.t)))].sort((e,t)=>e-t).map(e=>({t:e,values:_.map(t=>t.buckets.find(t=>t.t===e)?.values[0]??null)}));return r(`div`,{className:`space-y-5 min-w-0`,children:[p.length>0&&o(F,{title:i(`history.page.someFailed`,`Some series could not be read`),message:p.map(e=>`${q(e.c)}: ${e.e.error}`).join(` · `)}),h.length>0&&o(M,{title:i(`history.page.lines`,`Measurements`),series:h,range:n,height:260,syncKey:K,pending:f}),_.length>0&&o(x,{title:i(`history.page.energy`,`Energy`),layers:_.map((e,t)=>({id:e.c.id,label:e.c.subjectName,colorIndex:t})),buckets:y,bucketMs:v,range:n,unit:`kWh`,showTotal:!0,height:160,syncKey:K,pending:f}),g.length>0&&o(k,{title:g.length===1?g[0]?.label??``:i(`history.page.states`,`States`),rows:g,range:n,syncKey:K,pending:f})]})}function Me(e,t){let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}async function Ne(e,t){let n=[];for(let r of Me(e,50))try{let{results:e}=await t(r),i=new Map(e.map(e=>[e.seriesId,e]));for(let e of r)n.push(i.get(e)??{seriesId:e,ok:!1,reason:`not-found`})}catch(e){let t=e instanceof Error?e.message:String(e);for(let e of r)n.push({seriesId:e,ok:!1,reason:`request-failed`,message:t})}return n}function J(e){return e.raw+e[`5m`]+e[`1h`]+e[`1d`]}function Pe(e){return e.reduce((e,t)=>t.ok?{...e,deleted:e.deleted+1,points:e.points+J(t.deleted)}:{...e,refused:e.refused+1},{deleted:0,refused:0,points:0})}function Fe(e,t){let n=new Map(e.map(e=>[e.seriesId,e]));return t.flatMap(e=>{let t=n.get(e.seriesId);return t===void 0?[]:[{series:t,outcome:e}]})}var Y=e=>new Date(e).toLocaleDateString(void 0,{dateStyle:`short`});function X(e,t,n){let r=t.get(e.deviceId);return r===void 0?e.reason===`device-gone`?n(`history.orphans.deviceRemoved`,`#{{id}} (removed)`,{id:e.deviceId}):n(`history.orphans.deviceId`,`#{{id}}`,{id:e.deviceId}):r}function Z(e){let t=e.displayName??e.key;return e.scope===``?t:`${t} · ${e.scope}`}function Q(e,t,n){return{key:`series`,header:n(`history.orphans.colSeries`,`Series`),render:i=>{let a=e(i);return r(`div`,{className:`min-w-0 max-w-[16rem]`,children:[o(`div`,{className:`truncate text-foreground`,title:a.key,children:Z(a)}),o(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:X(a,t,n)})]})},sortValue:r=>`${X(e(r),t,n)} ${Z(e(r))}`}}var Ie=[`raw`,`5m`,`1h`,`1d`];function Le(e,t){return e===`raw`?t(`history.orphans.colRaw`,`Raw points`):e===`5m`?t(`history.orphans.col5m`,`5 min`):e===`1h`?t(`history.orphans.col1h`,`1 h`):t(`history.orphans.col1d`,`1 day`)}function Re(e,t){return[Q(e=>e,e,t),{key:`reason`,header:t(`history.orphans.colReason`,`Reason`),render:e=>r(`div`,{className:`flex flex-col items-start gap-0.5`,children:[o(L,{variant:e.reason===`device-gone`?`warning`:`neutral`,className:`text-[10px]`,children:e.reason===`device-gone`?t(`history.orphans.deviceGone`,`Device removed`):t(`history.orphans.undeclared`,`No longer declared`)}),e.missingSince!==null&&o(`span`,{className:`text-[10px] text-foreground-subtle`,children:t(`history.orphans.since`,`since {{date}}`,{date:Y(e.missingSince)})})]}),sortValue:e=>e.reason},{key:`span`,header:t(`history.orphans.colSpan`,`Recorded`),render:e=>r(`span`,{className:`tabular-nums text-foreground-muted`,children:[Y(e.firstTs),` → `,Y(e.lastTs)]}),sortValue:e=>e.lastTs},...Ie.map(e=>({key:`rows-${e}`,header:Le(e,t),align:`right`,render:t=>o(`span`,{className:`tabular-nums text-foreground-muted`,children:t.rows[e].toLocaleString()}),sortValue:t=>t.rows[e]}))]}function ze(e,t){if(e.ok)return o(L,{variant:`success`,className:`text-[10px]`,children:t(`history.orphans.deleted`,{count:J(e.deleted),points:J(e.deleted).toLocaleString(),defaultValue_one:`Deleted · {{points}} point`,defaultValue_other:`Deleted · {{points}} points`})});let n=e.reason===`request-failed`?t(`history.orphans.requestFailed`,`Not sent: {{message}}`,{message:e.message}):e.reason===`not-orphan`?t(`history.orphans.refusedNotOrphan`,`Kept: no longer orphan`):e.reason===`not-found`?t(`history.orphans.refusedNotFound`,`Already gone`):t(`history.orphans.refusedFailed`,`The hub could not delete it`);return o(L,{variant:e.reason===`not-found`?`neutral`:`warning`,className:`text-[10px]`,children:n})}function Be(e,t){return[Q(e=>e.series,e,t),{key:`result`,header:t(`history.orphans.colResult`,`Result`),render:e=>ze(e.outcome,t),sortValue:e=>+!e.outcome.ok}]}e();function Ve({open:e,onClose:i,list:a,deviceNames:s,onDelete:u,onRefresh:d,refreshing:p}){let{t:m}=H(),h=E(),[g,_]=n(new Set),[v,y]=n(!1),[x,S]=n([]),C=t(()=>Re(s,m),[s,m]),w=t(()=>Be(s,m),[s,m]),T=t(()=>new Set(a.series.map(e=>String(e.seriesId))),[a.series]),D=[...g].filter(e=>T.has(e)).map(Number),O=Pe(x.map(e=>e.outcome)),k=async()=>{if(await h({title:m(`history.orphans.confirmTitle`,{count:D.length,defaultValue_one:`Delete {{count}} series`,defaultValue_other:`Delete {{count}} series`}),message:m(`history.orphans.confirmMessage`,`Every recorded point of these series is removed from the hub. This cannot be undone.`),confirmLabel:m(`history.orphans.confirmLabel`,`Delete`),variant:`danger`})){y(!0);try{let e=await Ne(D,u);S(Fe(a.series,e)),_(new Set)}finally{y(!1),d()}}};return o(se,{open:e,onOpenChange:e=>!e&&i(),children:r(ve,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`orphan-series-dialog`,children:[o(de,{children:o(ie,{children:m(`history.orphans.title`,`Series no longer linked to a device`)})}),r(ue,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-muted`,children:m(`history.orphans.intro`,`Nothing records into these series any more: their device was removed, or no capability declares them now. Select the ones to delete.`)}),a.truncated&&r(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`orphan-truncated`,children:[o(`p`,{className:`text-xs text-warning`,children:m(`history.orphans.truncated`,`More series are unlinked than are listed here. Delete these, then load the rest.`)}),r(I,{size:`sm`,variant:`outline`,onClick:d,disabled:p,children:[o(l,{className:`h-3 w-3`,"aria-hidden":!0}),m(`history.orphans.loadAgain`,`Load again`)]})]}),x.length>0&&r(`div`,{className:`space-y-2`,"data-testid":`orphan-outcomes`,children:[o(`p`,{className:`text-xs text-foreground`,"aria-live":`polite`,children:m(`history.orphans.summary`,{count:O.deleted,refused:O.refused,points:O.points.toLocaleString(),defaultValue_one:`{{count}} series deleted ({{points}} points), {{refused}} kept.`,defaultValue_other:`{{count}} series deleted ({{points}} points), {{refused}} kept.`})}),o(P,{columns:w,rows:x,rowKey:e=>String(e.series.seriesId),minWidthPx:420,maxBodyHeight:`max-h-[60vh]`,emptyMessage:``})]}),o(P,{columns:C,rows:a.series,rowKey:e=>String(e.seriesId),minWidthPx:760,maxBodyHeight:b,defaultSort:{columnKey:`series`,dir:`asc`},emptyMessage:m(`history.orphans.empty`,`Every series is linked to a device.`),selection:{selected:g,onChange:_,rowLabel:e=>`${Z(e)} — ${X(e,s,m)}`,pageLabel:m(`history.orphans.selectAll`,`Select every listed series`)}})]}),r(pe,{children:[o(`span`,{className:`mr-auto text-[11px] tabular-nums text-foreground`,"aria-live":`polite`,children:m(`history.orphans.selected`,{count:D.length,defaultValue_one:`{{count}} selected`,defaultValue_other:`{{count}} selected`})}),o(I,{variant:`ghost`,size:`sm`,onClick:i,children:m(`history.orphans.close`,`Close`)}),r(I,{variant:`danger`,size:`sm`,disabled:D.length===0||v,onClick:()=>void k(),children:[v?o(f,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):o(c,{className:`h-3 w-3`,"aria-hidden":!0}),m(`history.orphans.deleteSelected`,`Delete selected`)]})]})]})})}e();var He=5*6e4;function Ue({enabled:e}){let{t:a}=H(),[s,c]=n(!1),l=N({},{enabled:e,staleTime:He}),u=B({projection:`slim`},{enabled:e}),d=D(),f=t(()=>new Map((u.data??[]).map(e=>[e.id,e.name])),[u.data]),p=e=>d.mutateAsync({seriesIds:[...e]});if(!e||l.status===`pending`)return null;if(l.status===`error`)return o(F,{variant:`warning`,title:a(`history.orphans.checkFailedTitle`,`Could not check for unlinked series`),message:l.error.message,onRetry:()=>void l.refetch()});let m=l.data;if(m.series.length===0&&!s)return null;let h=m.series.length;return r(i,{children:[h>0&&o(F,{variant:`warning`,message:m.truncated?a(`history.orphans.noticeMore`,{count:h,defaultValue_one:`More than {{count}} series are no longer linked to a device.`,defaultValue_other:`More than {{count}} series are no longer linked to a device.`}):a(`history.orphans.notice`,{count:h,defaultValue_one:`{{count}} series is no longer linked to a device.`,defaultValue_other:`{{count}} series are no longer linked to a device.`}),action:o(I,{size:`sm`,variant:`outline`,onClick:()=>c(!0),children:a(`history.orphans.review`,`Review`)})}),o(Ve,{open:s,onClose:()=>c(!1),list:m,deviceNames:f,onDelete:p,onRefresh:()=>void l.refetch(),refreshing:l.isFetching})]})}e();var We=`device`,Ge=`node`;function Ke({catalog:e,selected:n,onChange:i,loading:a}){let{t:s}=H(),c=le(e,{searchText:e=>[Te(e)],facetGroups:[{id:`subject`,value:e=>e.ref.subject.kind===`device`?We:Ge},{id:`room`,value:e=>e.location},{id:`unit`,value:e=>e.info.unit??``}]}),l=t(()=>[{key:`metric`,header:s(`history.picker.series`,`Series`),render:e=>r(`div`,{className:`min-w-0`,children:[o(`div`,{className:`truncate text-foreground`,children:e.metric}),o(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.location===``?e.subjectName:`${e.subjectName} · ${e.location}`})]}),sortValue:e=>`${e.subjectName} ${e.metric}`},{key:`unit`,header:s(`history.picker.unit`,`Unit`),render:e=>o(`span`,{className:`text-foreground-muted`,children:e.info.unit??`—`}),sortValue:e=>e.info.unit??``}],[s]),u=n.size>=24;return r(`div`,{className:`space-y-2 min-w-0`,children:[o(_e,{state:c.state,facets:[],groups:[{...c.groups.find(e=>e.id===`subject`)??{id:`subject`,facets:[],selected:[]},label:s(`history.picker.subject`,`Source`),facetLabel:e=>e===We?s(`history.picker.devices`,`Devices`):s(`history.picker.nodes`,`Nodes`)},{...c.groups.find(e=>e.id===`room`)??{id:`room`,facets:[],selected:[]},label:s(`history.picker.room`,`Room`),facetLabel:e=>e===``?s(`history.picker.noRoom`,`No room`):e},{...c.groups.find(e=>e.id===`unit`)??{id:`unit`,facets:[],selected:[]},label:s(`history.picker.metricType`,`Unit`),facetLabel:e=>e===``?s(`history.picker.noUnit`,`States & counts`):e}],labels:{searchPlaceholder:s(`history.picker.search`,`Search device, room, metric or node…`),searchLabel:s(`history.picker.searchLabel`,`Search series`),facetsLabel:s(`history.picker.facets`,`Filters`),clearLabel:s(`history.picker.clear`,`Clear`)},onSearch:c.setSearch,onToggleFacet:c.toggleFacet,onToggleGroupFacet:c.toggleGroupFacet,onClear:c.clear}),o(`p`,{className:`text-[10px] text-foreground-subtle`,"aria-live":`polite`,children:s(`history.picker.count`,`{{count}} of {{max}} selected`,{count:n.size,max:24})}),o(P,{columns:l,rows:c.rows,rowKey:e=>e.id,maxBodyHeight:b,pageSize:50,defaultSort:{columnKey:`metric`,dir:`asc`},emptyMessage:a?s(`history.picker.loading`,`Reading the series of every device…`):c.active?s(`history.picker.emptyFiltered`,`No series match these filters.`):s(`history.picker.empty`,`Nothing is recorded yet.`),selection:{selected:n,onChange:e=>{let t=[...e].filter(e=>n.has(e)),r=[...e].filter(e=>!n.has(e));i(new Set([...t,...r].slice(0,24)))},isSelectable:e=>n.has(e.id)||!u,rowLabel:e=>`${e.subjectName} · ${e.metric}`,pageLabel:s(`history.picker.selectPage`,`Select every series on this page`)}})]})}e();var qe=new Set([g.Hub,g.Container]),$=5*6e4;function Je(){let{t:e}=H(),n=C(`device-history`),[i,a]=Se(),c=t(()=>R(i.getAll(`s`).flatMap(e=>{let t=re(e);return t===null?[]:[t]})),[i]),l=i.get(`window`),f=me(l)?l:`7d`,p=he(i.get(`range`)),m=(e,t,n)=>{let r=new URLSearchParams;for(let t of R(e))r.append(`s`,be(t));t!==`7d`&&r.set(`window`,t);let o=n===void 0?i.get(`range`):n;t===`custom`&&o&&r.set(`range`,o),a(r,{replace:!0})},g=Ye(n===`present`),_=O(f,Date.now(),p),b=O(f,ae(Date.now(),_.to-_.from),p),x=t(()=>Ae(c,g.candidates),[c,g.candidates]),S=t(()=>new Set(c.map(V)),[c]),w=ye(),D=te(),k=E(),A=async()=>{let t=await D({title:e(`history.page.saveTitle`,`Save as panel`),label:e(`history.page.saveName`,`Panel name`),confirmLabel:e(`history.page.save`,`Save`)});t===null||t.trim()===``||await w.update(e=>ee(e,{id:`panel-${Date.now().toString(36)}`,name:t.trim().slice(0,80),window:f,selection:[...c]}))},M=async(t,n)=>{await k({title:e(`history.page.deleteTitle`,`Delete panel`),message:e(`history.page.deleteMessage`,`The panel "{{name}}" is removed from your account.`,{name:n}),confirmLabel:e(`history.page.delete`,`Delete`),variant:`danger`})&&await w.update(e=>y(e,t))},N=t=>t===`energy`?e(`history.panels.energy`,`Total energy`):t===`temperatures`?e(`history.panels.temperatures`,`Temperatures by room`):t===`nodes`?e(`history.panels.nodes`,`Cluster nodes`):e(`history.panels.storage`,`Storage locations`);return o(Ce,{icon:s,title:e(`history.page.title`,`History`),subtitle:e(`history.page.subtitle`,`What devices, nodes and storage recorded over time, side by side.`),actions:n===`present`?r(I,{size:`sm`,variant:`outline`,onClick:()=>void A(),disabled:c.length===0||!w.writable,children:[o(d,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),e(`history.page.saveTitle`,`Save as panel`)]}):void 0,children:n===`pending`?o(j,{className:`h-64 w-full`}):n===`unknown`?o(F,{title:e(`history.page.presenceUnknownTitle`,`Could not reach the hub`),message:e(`history.page.presenceUnknown`,`The hub did not say whether device history is installed. Try again in a moment.`)}):n===`absent`?o(T,{icon:h,title:e(`history.page.absentTitle`,`Device history is not running on this hub`),description:e(`history.page.absent`,`Nothing is recorded until the device-history system addon is enabled.`)}):r(`div`,{className:`space-y-3 sm:space-y-4`,children:[o(Ue,{enabled:n===`present`}),r(`div`,{className:`flex flex-wrap items-center gap-2`,role:`group`,"aria-label":e(`history.page.panels`,`Panels`),children:[Ee.map(e=>o(I,{size:`sm`,variant:`outline`,disabled:g.status!==`ok`,onClick:()=>m(ke(e,g.candidates),f),children:N(e)},e)),w.value.panels.map(t=>r(`span`,{className:`inline-flex items-center`,children:[o(I,{size:`sm`,variant:`secondary`,onClick:()=>m(t.selection,t.window,null),children:t.name}),o(I,{size:`sm`,variant:`ghost`,"aria-label":e(`history.page.deleteNamed`,`Delete panel {{name}}`,{name:t.name}),onClick:()=>void M(t.id,t.name),disabled:!w.writable,children:o(u,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]},t.id))]}),r(`div`,{className:`grid grid-cols-1 gap-3 sm:gap-4 xl:grid-cols-5`,children:[o(`div`,{className:`min-w-0 xl:col-span-2`,children:o(z,{headingId:`history-picker`,title:e(`history.picker.title`,`Series`),children:o(`div`,{className:`p-2 sm:p-3`,children:g.status===`error`?o(F,{message:g.error}):o(Ke,{catalog:g.candidates,loading:g.status===`pending`,selected:S,onChange:e=>{let t=c.filter(t=>e.has(V(t))),n=g.candidates.filter(t=>e.has(t.id)&&!S.has(t.id)).map(e=>e.ref);m([...t,...n],f)}})})})}),o(`div`,{className:`min-w-0 xl:col-span-3`,children:o(z,{headingId:`history-overlay`,title:e(`history.page.overlay`,`Overlay`),actions:c.length>0?o(I,{size:`sm`,variant:`ghost`,onClick:()=>m([],f),children:e(`history.page.clear`,`Clear`)}):void 0,children:r(`div`,{className:`p-2 sm:p-3 space-y-3 min-w-0`,children:[o(fe,{value:f,onChange:e=>m(c,e),custom:p,onCustomChange:e=>m(c,`custom`,v(e))}),g.status===`pending`&&c.length>0?o(j,{className:`h-64 w-full`}):o(je,{part:x,window:b}),x.missing.length>0&&g.status===`ok`&&o(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`history.page.missing`,{count:x.missing.length,defaultValue_one:`{{count}} selected series is no longer recorded.`,defaultValue_other:`{{count}} selected series are no longer recorded.`})})]})})})]})]})})}function Ye(e){let{t:n}=H(),r=n(`history.picker.wholeFrame`,`Whole frame`),i=p().trpcClient,o=B({projection:`slim`},{enabled:e}),{nodes:s}=oe(),c=t(()=>(o.data??[]).filter(e=>!qe.has(String(e.type))),[o.data]),l=a({queries:c.map(t=>({queryKey:[`device-history`,`listSeries`,t.id],queryFn:()=>i.deviceHistory.listSeries.query({deviceId:t.id}),enabled:e,staleTime:$}))}),u=a({queries:s.map(t=>({queryKey:[`device-history`,`listNodeSeries`,t.id],queryFn:()=>i.deviceHistory.listNodeSeries.query({forNodeId:t.id}),enabled:e,staleTime:$}))}),d=ne({},{enabled:e,staleTime:$}),f=t(()=>new Map((d?.data??[]).map(e=>[e.id,e.displayName])),[d?.data]),m=l.map(e=>e.data),h=u.map(e=>e.data),g=t(()=>we(c.flatMap((e,t)=>{let n=m[t];return n===void 0?[]:[{device:{id:e.id,name:e.name,location:e.location??null},series:n}]}),s.flatMap((e,t)=>{let n=h[t];return n===void 0?[]:[{node:{id:e.id,name:e.name},series:n}]}),e=>{if(e.key!==`addon:pipeline-analytics/occupancy`)return f.get(e.scope)??e.scope;let{zoneId:t,className:n}=_(e.scope),i=t===``?r:t;return n===void 0?i:`${i} · ${n}`}),[c,s,f,[...l,...u].map(e=>e.dataUpdatedAt).join(`,`),r]);return o.status===`error`?{status:`error`,error:o.error.message,candidates:[]}:{status:o.status===`pending`||l.some(e=>e.isPending)||u.some(e=>e.isPending)?`pending`:`ok`,error:``,candidates:g}}export{Je as HistoryPage};
|