@camstack/addon-admin-ui 1.2.416 → 1.2.418
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-C62yJZFm.js +1 -0
- package/dist/assets/Addons-VQS109cZ.js +4 -0
- package/dist/assets/{AdminPage-D7-0jWFU.js → AdminPage-BEqLIsOo.js} +1 -1
- package/dist/assets/{AdminSectionedPage-BjXLUVSX.js → AdminSectionedPage-CP474cGo.js} +1 -1
- package/dist/assets/AiProfiles-u256UZct.js +3 -0
- package/dist/assets/BrokerForm-DUkw19ji.js +1 -0
- package/dist/assets/Build-Brgeliww.js +40 -0
- package/dist/assets/Calendars-BMPzJO5T.js +1 -0
- package/dist/assets/Cluster-BP84zI8m.js +1 -0
- package/dist/assets/ClusterStepModel-DSV_DDrS.js +1 -0
- package/dist/assets/CompositionEditor-DCgWv0b9.js +1 -0
- package/dist/assets/{CompositionEditorPage-vkJd3OvE.js → CompositionEditorPage-DQRfGqD9.js} +1 -1
- package/dist/assets/Data-TTszkqiw.js +1 -0
- package/dist/assets/DeviceDetail-CPVXc0Fg.js +2 -0
- package/dist/assets/{DeviceDoActionFields-Dk1xuFsm.js → DeviceDoActionFields-BlMeNa6S.js} +1 -1
- package/dist/assets/{Devices-DxlUNGRf.js → Devices-Ba_o53OS.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-uOxIyvPM.js → EmbedPlayerPage-DyvatXBm.js} +1 -1
- package/dist/assets/Identity-Bi5h3d3K.js +1 -0
- package/dist/assets/IntegrationDetail-vZ_Lj86F.js +1 -0
- package/dist/assets/IntegrationHub-COkGQeyK.js +1 -0
- package/dist/assets/Integrations-CxF_Vsv7.js +1 -0
- package/dist/assets/Integrations-D9x4MZdn.js +1 -0
- package/dist/assets/Library-DyV2ZDM-.js +1 -0
- package/dist/assets/Locations-CKf9yfhF.js +3 -0
- package/dist/assets/Logs-0kTIclt1.js +1 -0
- package/dist/assets/{MotionZonesSettings-DE-apmof.js → MotionZonesSettings-DXSMGb_y.js} +1 -1
- package/dist/assets/MyAccess-CwmClt12.js +2 -0
- package/dist/assets/Network-DGIx_W_h.js +1 -0
- package/dist/assets/NodeAddonsSettingsPanel-C_CcgSpF.js +1 -0
- package/dist/assets/Notifications-GsY_0ici.js +1 -0
- package/dist/assets/PrivacyMaskSettings-C_Lloo6m.js +1 -0
- package/dist/assets/Recordings-DwSSrKQD.js +1 -0
- package/dist/assets/{ScanNetworkModal-BFlsOjii.js → ScanNetworkModal-Dq_ea9P_.js} +1 -1
- package/dist/assets/SceneMonitorEditor-C_Ar3-bY.js +1 -0
- package/dist/assets/SessionsList-DvSyxvxt.js +2 -0
- package/dist/assets/{Showroom-eoafVoyx.js → Showroom-BA-v1np-.js} +1 -1
- package/dist/assets/System-CwL0iIg6.js +1 -0
- package/dist/assets/{Terminal-fTiFwYAg.js → Terminal-D6KTXuAz.js} +5 -5
- package/dist/assets/Viewer-DkQKIrd8.js +1 -0
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DlDQHv4o.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CCPefcbR.js} +1 -1
- package/dist/assets/addon-icons-context-DjDIqnLX.js +1 -0
- package/dist/assets/{archive-BDsI1Dbp.js → archive-CPl948Xw.js} +1 -1
- package/dist/assets/{authed-media-j0JPywRs.js → authed-media-BUdhZkQX.js} +1 -1
- package/dist/assets/bell-off-KhA1gUdX.js +1 -0
- package/dist/assets/{boxes-BM0v3X80.js → boxes-BJT46V9Z.js} +1 -1
- package/dist/assets/circle-slash-BLuQVjBj.js +1 -0
- package/dist/assets/client-BuR_k4TQ.js +357 -0
- package/dist/assets/cloud-upload-ssmNKdHW.js +1 -0
- package/dist/assets/crop-CZqa0EdU.js +1 -0
- package/dist/assets/{device-integration-icon-ocs6ggTN.js → device-integration-icon-DFhPmm5v.js} +1 -1
- package/dist/assets/device-picker-model-DP3NSKXl.js +1 -0
- package/dist/assets/{dist-Cy4r_xUn.js → dist-CCZlk2eE.js} +1 -1
- package/dist/assets/dist-CtWVWsbl.js +357 -0
- package/dist/assets/eraser-DRyBUKNh.js +1 -0
- package/dist/assets/file-up-wQjYsgvp.js +1 -0
- package/dist/assets/format-size-DIxKXxtj.js +1 -0
- package/dist/assets/hard-drive-download-HQYBHoiD.js +1 -0
- package/dist/assets/{history-B74VMQT0.js → history-oLd0L9rZ.js} +1 -1
- package/dist/assets/{hostInit-DCunyfRZ.js → hostInit-D90L9qfj.js} +1 -1
- package/dist/assets/icons-DuIMQjz-.js +1 -0
- package/dist/assets/index-BilrpIGQ.js +4 -0
- package/dist/assets/{index-BXWF5H1x.css → index-Q7OTRxZX.css} +1 -1
- package/dist/assets/key-DzVMR4fY.js +1 -0
- package/dist/assets/key-round-D1FkABXg.js +1 -0
- package/dist/assets/{layers-a5eCLI1t.js → layers-DoFyMFF3.js} +1 -1
- package/dist/assets/list-ordered-6N9kB8SV.js +1 -0
- package/dist/assets/location-owned-usage-CbWvLYTm.js +1 -0
- package/dist/assets/{log-in-BQ5RonNw.js → log-in-DMf-S1KW.js} +1 -1
- package/dist/assets/memory-stick-DSGFkyDx.js +1 -0
- package/dist/assets/message-square-plus-M4i6DeFo.js +1 -0
- package/dist/assets/{mf-entry-bootstrap-0-6c18451d.js → mf-entry-bootstrap-0-e96294f3.js} +2 -2
- package/dist/assets/mic-off-Bz-qzGUm.js +1 -0
- package/dist/assets/monitor-off-CeMF_Mpo.js +1 -0
- package/dist/assets/{monitor-smartphone-8wpzhXiA.js → monitor-smartphone-Xhzlx_89.js} +1 -1
- package/dist/assets/mount-DP3NSKXl.js +1 -0
- package/dist/assets/notification-schedule-field-BEC_PxdH.js +1 -0
- package/dist/assets/{octagon-alert-DafO864y.js → octagon-alert-Drdzfe0m.js} +1 -1
- package/dist/assets/player-overlays-CT0Sya8x.js +1 -0
- package/dist/assets/recycle-oKcI9-Qf.js +1 -0
- package/dist/assets/remoteEntry-D6CE2qGW.js +1 -0
- package/dist/assets/scan-eye-PgVPskUP.js +1 -0
- package/dist/assets/scissors-CmocAATr.js +1 -0
- package/dist/assets/search-x-DBBZ90V1.js +1 -0
- package/dist/assets/{send-Df6yf9Ke.js → send-DrOGIOSA.js} +1 -1
- package/dist/assets/{settings-2-D2Z3I7_I.js → settings-2-YgshzBDH.js} +1 -1
- package/dist/assets/speaker-5mQMtqrA.js +1 -0
- package/dist/assets/src-BN3mx6i3.js +67 -0
- package/dist/assets/timer-reset-7vZp4A1n.js +1 -0
- package/dist/assets/ungroup-Cj812Fu5.js +1 -0
- package/dist/assets/unlink-CH_DjMZS.js +1 -0
- package/dist/assets/usb-JbE9Gq0u.js +1 -0
- package/dist/assets/{use-scenes-feed-CGEpLzQ4.js → use-scenes-feed-rhcS_kPu.js} +1 -1
- package/dist/assets/{use-stationary-objects-CvNiN6bl.js → use-stationary-objects-HzWVsNGW.js} +1 -1
- package/dist/assets/useEventInvalidation-DP3NSKXl.js +1 -0
- package/dist/assets/useNodeUrlSelection-DF6nhFoG.js +1 -0
- package/dist/assets/user-round-t6VEn5sR.js +1 -0
- package/dist/assets/user-x-Bwwio4kh.js +1 -0
- package/dist/assets/video-tqpr2hW0.js +1 -0
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-D4d5vHMt.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-TrZv_3YK.js} +2 -2
- package/dist/index.html +10 -8
- package/dist/server/addon.js +19890 -1346
- package/package.json +1 -1
- package/dist/assets/AddonAssetIcon-BiM7X6ce.js +0 -1
- package/dist/assets/Addons-DAUd3f9C.js +0 -4
- package/dist/assets/AiProfiles-ConI-m3c.js +0 -3
- package/dist/assets/BrokerForm-dcVdlnbQ.js +0 -1
- package/dist/assets/Build-Bc6T4YxX.js +0 -40
- package/dist/assets/Calendars-Bj42p1jV.js +0 -1
- package/dist/assets/Cluster-Ccbe42xK.js +0 -1
- package/dist/assets/ClusterStepModel-BW7HnI0Q.js +0 -1
- package/dist/assets/CompositionEditor-CAtKL9zi.js +0 -1
- package/dist/assets/Data-DVK-DtHQ.js +0 -1
- package/dist/assets/DeviceDetail-DrozyhRY.js +0 -2
- package/dist/assets/Identity-C15dtEig.js +0 -1
- package/dist/assets/IntegrationDetail-rRrB-tuL.js +0 -1
- package/dist/assets/IntegrationHub-U7lxyXCr.js +0 -1
- package/dist/assets/Integrations-BZ7UFBbo.js +0 -1
- package/dist/assets/Integrations-brAq5y-N.js +0 -1
- package/dist/assets/Library-Bg1lGdr_.js +0 -1
- package/dist/assets/Locations-DvSBfgkn.js +0 -3
- package/dist/assets/Logs-h2dxr2Jn.js +0 -1
- package/dist/assets/MyAccess-BvLVb25u.js +0 -2
- package/dist/assets/Network-DXnh0Cgl.js +0 -1
- package/dist/assets/NodeAddonsSettingsPanel-BMHbbtN-.js +0 -1
- package/dist/assets/Notifications-CEOX2_pI.js +0 -1
- package/dist/assets/PrivacyMaskSettings-CnoZ54U0.js +0 -1
- package/dist/assets/Recordings-Dg5I6bJ0.js +0 -1
- package/dist/assets/SceneMonitorEditor-DPHlWKEI.js +0 -1
- package/dist/assets/SessionsList-DyXYeA2E.js +0 -2
- package/dist/assets/System-BZFr7IgC.js +0 -1
- package/dist/assets/Viewer-Ch-uricZ.js +0 -1
- package/dist/assets/circle-slash-C0s73mTj.js +0 -1
- package/dist/assets/client-Da5ic7fF.js +0 -357
- package/dist/assets/crop-D4-5yeFX.js +0 -1
- package/dist/assets/device-picker-model-dhif7MNn.js +0 -1
- package/dist/assets/dist-7PxzCqSO.js +0 -357
- package/dist/assets/format-size-BqCoWUse.js +0 -1
- package/dist/assets/index-Bi6aHCQm.js +0 -4
- package/dist/assets/location-owned-usage-DDGnGfYC.js +0 -1
- package/dist/assets/mount-dhif7MNn.js +0 -1
- package/dist/assets/notification-schedule-field-Caj6sqLM.js +0 -1
- package/dist/assets/player-overlays-4f4KZjKK.js +0 -1
- package/dist/assets/remoteEntry-CsX_cuFO.js +0 -1
- package/dist/assets/src-DHEqfaFh.js +0 -67
- package/dist/assets/useEventInvalidation-dhif7MNn.js +0 -1
- package/dist/assets/useNodeUrlSelection-DOFQZmcd.js +0 -1
- package/dist/assets/user-round-g5vQShKE.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Q as l,_t as u,ct as d,gt as f,yt as p}from"./player-overlays-4f4KZjKK.js";import{Af as m,An as h,Dd as g,Fn as _,G as v,Gc as y,Gn as b,Hn as x,Ht as S,In as C,Kc as w,L as T,Mc as E,Mf as D,Mn as O,Mu as k,Nf as A,Od as j,Pn as M,Qd as N,R as P,Rr as F,Uc as I,Un as ee,Ut as L,Wc as te,Xl as R,_d as z,af as B,ai as ne,al as re,ci as ie,di as ae,ef as oe,ei as se,fi as ce,hd as le,hi as V,ii as ue,jn as de,kd as H,li as fe,md as pe,mi as me,nf as he,ni as ge,nr as U,nu as W,of as _e,oi as ve,pi as ye,ri as be,sd as G,si as xe,ti as Se,tu as K,uf as Ce,ui as we,un as Te,ur as Ee,z as De}from"./src-DHEqfaFh.js";import{t as Oe}from"./circle-slash-C0s73mTj.js";import{a as ke,c as Ae,l as je,n as Me,o as Ne,s as Pe,t as Fe,u as Ie}from"./location-owned-usage-DDGnGfYC.js";import{n as Le,t as q}from"./format-size-BqCoWUse.js";import{t as Re}from"./useTranslation-Bc5yH9V9.js";import"./mount-dhif7MNn.js";import{C as ze}from"./index-Bi6aHCQm.js";import{t as Be}from"./AdminSectionedPage-BjXLUVSX.js";import{t as Ve}from"./AdminPage-D7-0jWFU.js";import{n as He}from"./authed-media-j0JPywRs.js";var Ue=p(`calendar-clock`,[[`path`,{d:`M16 14v2.2l1.6 1`,key:`fo4ql5`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]),We=p(`cloud-upload`,[[`path`,{d:`M12 13v8`,key:`1l5pq0`}],[`path`,{d:`M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242`,key:`1pljnt`}],[`path`,{d:`m8 17 4-4 4 4`,key:`1quai1`}]]);t();function Ge(){let e=a(),t=U(),{data:i,isLoading:o,isError:l}=w({}),u=y(),d=r(()=>u.data??[],[u.data]),{data:f}=E({},{refetchOnWindowFocus:!1}),p=r(()=>Fe(i??[],f?.locations),[i,f?.locations]),{data:m}=te({},{refetchOnWindowFocus:!1}),h=r(()=>ke(m),[m]),{state:g,openNew:_,openEdit:v,close:b}=T(),[x,S]=P(`type`),C=()=>{S(null),b()},D=e=>{S(e),_()},O=e=>{S(null),v(e.id)},k=i??[],A=g.mode===`edit`?k.find(e=>e.id===g.id)??null:null;c(()=>{g.mode===`new`&&(x===null||x===``)&&(S(null),b())},[g.mode,x,b,S]),c(()=>{g.mode===`edit`&&!o&&A===null&&(S(null),b())},[g.mode,o,A,b,S]),c(()=>{g.mode===`closed`&&x!==null&&S(null)},[g.mode,x,S]);let j=I({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),M=re({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),N=async(e,n)=>{je(n)&&!await t({title:`Disable "${e.displayName}"?`,message:`${Ae(n).consequence}\n\nNothing is deleted — set the location back to Read-only or Active to bring its footage back.`,confirmLabel:`Disable`,variant:`danger`})||M.mutate(Pe(e,{mode:n}))},F=async e=>{if(await t({title:`Delete location "${e.displayName}"?`,message:`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`,confirmLabel:`Delete`,variant:`danger`}))try{await j.mutateAsync({id:e.id}),g.mode===`edit`&&g.id===e.id&&C()}catch(n){await t({title:`Delete anyway?`,message:`${n instanceof Error?n.message:String(n)}\n\nForcing the delete removes the record only. Anything still on that location becomes unreachable — index rows naming it stop resolving, and playback of those segments goes silently black rather than erroring.`,confirmLabel:`Force delete`,variant:`danger`})&&j.mutate({id:e.id,force:!0},{onSuccess:()=>{g.mode===`edit`&&g.id===e.id&&C()}})}},ee=r(()=>{let e=new Map;for(let t of i??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[i]),L=o||u.isLoading,R=l||u.isError,z=g.mode===`new`&&x!==null&&x!==``,B=g.mode===`edit`&&A!==null;return n(Ve,{embedded:!0,children:[L&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),R&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!L&&!R&&n(`div`,{className:`space-y-3`,children:[d.length===0&&s(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:`No storage locations declared by any installed addon.`}),d.map(e=>s(Me,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:ee.get(e.id)??[],onAdd:D,onEdit:O,onDelete:e=>{F(e)},ownedBytesById:p,drainById:h,onSetMode:(e,t)=>{N(e,t)}},e.id))]}),z&&x!==null&&s(Ie,{initialType:x,onClose:C,onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),C()}}),B&&A!==null&&s(Ne,{location:A,onClose:C,onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),C()}})]})}var Ke={settings:{label:`Configuration & files`,description:`Configuration database, addons, addon data and certificates. Nightly.`},events:{label:`Events & detections`,description:`Tracks, detections and notification history. Statistical: weekly is enough.`},history:{label:`History (statistics)`,description:`Long-term statistics and ledgers. Statistical: weekly is enough.`}},qe=Object.keys(Ke),J=[`settings`],Je=`Created when this feature is enabled`;function Ye(e){return Ke[e].label}function Xe(e){return Ke[e].description}function Y(e){let t=new Set(e);return qe.filter(e=>t.has(e))}function X(e){return e!==void 0&&e.length>0?Y(e):J}function Ze(e){return Y(e)}function Qe(e,t){return t===void 0||!t.answered?`unknown`:t.databases.includes(e)?`present`:`absent`}function $e(e,t,n){return Qe(e,t)===`absent`&&!n.has(e)}function et(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function tt(e){return!e.includes(`settings`)}function nt(e){return{databases:[...Ze(e)]}}function rt(e,t){return e!==void 0&&e.length>0?Y(e):t!==void 0&&t.length>0?Y(t.map(e=>e.databaseId??`settings`)):J}function Z({databases:e}){return n(`span`,{className:`flex flex-wrap items-center gap-1`,"data-testid":`backup-database-badges`,children:[e.map(e=>s(Ee,{variant:e===`settings`?`primary`:`info`,style:`fill`,size:`sm`,children:Ye(e)},e)),tt(e)&&s(Ee,{variant:`warning`,style:`fill`,size:`sm`,children:`Snapshots only`})]})}t();var it=[[`backup`,`listDestinations`]],at=[`backup`,`listArchives`];function ot({destinationId:t,restoreSupported:i,onOpenRestoreWizard:c}){let l=a(),u=U(),{data:f,isLoading:p,isError:m}=ve({destinationId:t}),h=f??[],_=Se({onSuccess:()=>{l.invalidateQueries({queryKey:[[...at]]}),l.invalidateQueries({queryKey:it})}}),v=e(async e=>{await u({title:`Delete this archive?`,message:`Permanently deletes "${e.label??e.id}" and frees ${q(e.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&_.mutate({destinationId:t,backupId:e.id})},[u,t,_]),[y,x]=o(null),C=e(async e=>{x(e.id);try{let n=await He(st(t,e.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.label??e.id}.tar.gz${e.encryption===void 0?``:`.csbk`}`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{x(null)}},[t]),w=r(()=>[...h].toSorted((e,t)=>t.createdAt-e.createdAt),[h]);return p?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):m?s(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):w.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):s(S,{columns:[{key:`when`,header:`When`,sortValue:e=>e.createdAt,render:e=>s(`span`,{className:`tabular-nums`,children:ct(e.createdAt)})},{key:`label`,header:`Label`,sortValue:e=>e.label??null,render:e=>n(`span`,{className:`inline-flex items-center gap-1`,children:[e.encryption!==void 0&&s(g,{className:`h-3 w-3 text-success`,"aria-label":`encrypted — restore needs backup key ${e.encryption.keyId}`}),e.label??s(`span`,{className:`text-foreground-subtle italic`,children:`—`})]})},{key:`databases`,header:`Databases`,nowrap:!1,notSortableReason:`Database badges`,render:e=>s(Z,{databases:X(e.databases)})},{key:`includes`,header:`Files`,nowrap:!1,notSortableReason:`Location list`,render:e=>e.locations.length>0?s(`span`,{className:`text-foreground-subtle`,children:e.locations.join(`, `)}):s(`span`,{className:`text-foreground-subtle italic`,children:`none`})},{key:`size`,header:`Size`,align:`right`,sortValue:e=>e.sizeBytes,render:e=>s(`span`,{className:`tabular-nums`,children:q(e.sizeBytes)})},{key:`actions`,header:``,align:`right`,notSortableReason:`Actions`,render:e=>n(`span`,{className:`flex items-center justify-end gap-1`,children:[n(b,{variant:`ghost`,size:`sm`,onClick:()=>{C(e)},disabled:y===e.id,title:`Download archive`,children:[y===e.id?s(H,{className:`h-3 w-3 animate-spin`}):s(N,{className:`h-3 w-3`}),`Download`]}),i&&c&&n(b,{variant:`ghost`,size:`sm`,onClick:()=>c({destinationId:t,archiveId:e.id}),title:`Restore from this archive`,children:[s(G,{className:`h-3 w-3`}),`Restore`]}),s(W,{variant:`ghost`,size:`sm`,icon:d,"aria-label":`Delete ${e.label??e.id}`,disabled:_.isPending,onClick:()=>{v(e)}})]})}],rows:w,rowKey:e=>e.id,minWidthPx:760,mobileMode:`cards`,emptyMessage:`No archives at this destination yet.`})}function st(e,t){return l(`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}function ct(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}t();var lt=[[`backup`,`listSchedules`]];function ut({onEdit:t,onOpenRestoreWizard:i}){let{data:a,isLoading:c,isError:l,error:u,refetch:d}=we(),f=a??[],p=ie().data??[],m=r(()=>{let e=new Map;for(let t of p)e.set(t.id,t);return e},[p]),[h,g]=o(null),_=e(e=>{g(t=>t===e?null:e)},[]),v=h===null?null:f.find(e=>e.id===h)??null,y=r(()=>dt({destById:m,expandedId:h,onToggleExpand:_,onEdit:t}),[m,h,_,t]);return c?n(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle animate-pulse`,children:[s(H,{className:`h-3.5 w-3.5 animate-spin`}),`Loading backup entries…`]}):l?s(x,{title:`Failed to load backup entries`,message:u instanceof Error?u.message:`Unknown error`,onRetry:()=>void d()}):f.length===0?s(ee,{icon:Ue,title:`No backup entries yet`,description:`Create one to schedule backups across one or more storage locations.`}):n(`div`,{className:`space-y-2`,children:[s(S,{columns:y,rows:f,rowKey:e=>e.id,minWidthPx:980,maxBodyHeight:L,mobileMode:`cards`,emptyMessage:`No backup entries yet`,onRowClick:e=>t(e)}),v!==null&&s(vt,{row:v,destById:m,...i?{onOpenRestoreWizard:i}:{}})]})}function dt(e){return[{key:`expand`,header:``,width:`w-8`,nowrap:!0,notSortableReason:`Expand control`,render:t=>{let n=e.expandedId===t.id;return s(W,{variant:`ghost`,size:`sm`,icon:n?u:f,"aria-label":n?`Hide archives`:`Show archives`,"aria-expanded":n,onClick:n=>{n.stopPropagation(),e.onToggleExpand(t.id)}})}},{key:`entry`,header:`Entry`,sortValue:e=>e.label,render:e=>n(`span`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate font-medium text-foreground`,children:e.label||`(unnamed)`}),e.lastRunAt!==void 0&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`last run `,new Date(e.lastRunAt).toLocaleString()]})]})},{key:`enabled`,header:`Enabled`,width:`w-20`,nowrap:!0,sortValue:e=>+!!e.enabled,render:e=>s(`span`,{onClick:e=>e.stopPropagation(),children:s(ht,{row:e})})},{key:`databases`,header:`Backs up`,nowrap:!1,notSortableReason:`Database badges`,render:e=>s(Z,{databases:X(e.databases)})},{key:`locations`,header:`Locations`,nowrap:!1,notSortableReason:`Location chips`,render:t=>s(ft,{row:t,destById:e.destById})},{key:`retention`,header:`Retention`,width:`w-24`,nowrap:!0,sortValue:e=>e.retentionCount,render:e=>s(`span`,{onClick:e=>e.stopPropagation(),children:s(gt,{row:e})})},{key:`schedule`,header:`Schedule`,width:`w-48`,nowrap:!0,sortValue:e=>e.cron,render:e=>s(pt,{row:e})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:t=>s(`span`,{onClick:e=>e.stopPropagation(),children:s(_t,{row:t,onEdit:()=>e.onEdit(t)})})}]}function ft({row:e,destById:t}){return e.locationIds.length===0?s(`span`,{className:`text-[11px] italic text-danger`,children:`No locations`}):s(`span`,{className:`flex flex-wrap gap-1`,children:e.locationIds.map(e=>s(`span`,{className:`inline-flex items-center rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-foreground`,title:e,children:t.get(e)?.displayName??e},e))})}function pt({row:e}){let t=e.cron.trim().length>0;return n(`span`,{className:`flex flex-col items-start gap-0.5`,children:[n(`span`,{className:`inline-flex items-center gap-1`,children:[s(Ue,{className:`h-3 w-3 text-foreground-subtle`}),s(`span`,{className:`font-mono text-[11px] text-foreground`,children:t?e.cron:`Manual`})]}),t&&e.nextRunAt!==void 0&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`next `,new Date(e.nextRunAt).toLocaleString()]})]})}function mt(e){return r(()=>({id:e.id,label:e.label,cron:e.cron,locationIds:[...e.locationIds],retentionCount:e.retentionCount,...e.dataSources?{dataSources:[...e.dataSources]}:{},...e.databases?{databases:[...e.databases]}:{}}),[e])}function ht({row:e}){let t=a(),n=V({onSuccess:()=>{t.invalidateQueries({queryKey:lt})}}),r=mt(e);return s(`label`,{className:`inline-flex cursor-pointer items-center`,children:s(`input`,{type:`checkbox`,className:`accent-primary`,checked:e.enabled,disabled:n.isPending,onChange:e=>n.mutate({...r,enabled:e.target.checked}),"aria-label":`Enable ${e.label||e.id}`})})}function gt({row:e}){let t=a(),n=V({onSuccess:()=>{t.invalidateQueries({queryKey:lt})}}),r=mt(e),[i,l]=o(String(e.retentionCount));return c(()=>{l(String(e.retentionCount))},[e.retentionCount]),s(K,{type:`number`,min:1,max:1e3,value:i,disabled:n.isPending,onChange:e=>l(e.target.value),onBlur:()=>{let t=Number.parseInt(i,10);if(Number.isNaN(t)||t<1){l(String(e.retentionCount));return}t!==e.retentionCount&&n.mutate({...r,enabled:e.enabled,retentionCount:t})},onKeyDown:t=>{t.key===`Enter`&&t.target.blur(),t.key===`Escape`&&l(String(e.retentionCount))},className:`w-16`,"aria-label":`Retention for ${e.label||e.id}`})}function _t({row:e,onEdit:t}){let r=a(),i=U(),o=ge({onSuccess:()=>{r.invalidateQueries({queryKey:lt})}}),c=me({onMutate:()=>{r.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{r.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),r.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),r.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})}}),l=()=>{e.locationIds.length!==0&&c.mutate({destinations:[...e.locationIds],...e.dataSources&&e.dataSources.length>0?{locations:[...e.dataSources]}:{},label:e.label,retentionCount:e.retentionCount,databases:[...X(e.databases)]})},u=async()=>{await i({title:`Delete backup entry?`,message:`"${e.label||e.id}" will stop running. Existing archives are kept.`,confirmLabel:`Delete`,variant:`warning`})&&o.mutate({id:e.id})};return n(`span`,{className:`flex items-center justify-end gap-1.5`,children:[n(b,{size:`sm`,type:`button`,onClick:l,disabled:c.isPending||e.locationIds.length===0,title:`Run this entry now`,children:[c.isPending?s(H,{className:`h-3 w-3 animate-spin`}):s(le,{className:`h-3 w-3`}),`Run now`]}),s(W,{variant:`ghost`,size:`sm`,icon:z,"aria-label":`Edit ${e.label||e.id}`,onClick:t}),s(W,{variant:`ghost`,size:`sm`,icon:d,"aria-label":`Delete ${e.label||e.id}`,disabled:o.isPending,onClick:()=>{u()}})]})}function vt({row:e,destById:t,onOpenRestoreWizard:r}){return n(`div`,{className:`space-y-4 rounded-lg border border-border bg-background/30 px-4 py-3`,children:[n(`p`,{className:`text-[11px] font-medium text-foreground-subtle`,children:[`Archives for `,e.label||e.id]}),e.locationIds.length===0&&s(`p`,{className:`text-xs italic text-foreground-subtle`,children:`This entry has no locations selected.`}),e.locationIds.map(e=>n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:t.get(e)?.displayName??e}),s(ot,{destinationId:e,restoreSupported:t.get(e)?.restoreSupported??!0,...r?{onOpenRestoreWizard:r}:{}})]},e))]})}function yt({selected:e,onChange:t,disabled:r=!1,testId:i=`backup-databases`}){let a=xe().data,o=e.size>0&&tt(Y(e)),c=e.size===0?`Pick at least one.`:o?`Snapshots only: configuration and files are not part of this backup.`:null;return s(v,{label:`What to back up`,required:!0,...c===null?{}:{description:c},children:s(`div`,{className:`divide-y divide-border rounded border border-border bg-background`,"data-testid":i,children:qe.map(o=>{let c=Qe(o,a),l=r||$e(o,a,e);return n(`label`,{className:`flex items-start gap-2 px-3 py-2 text-xs ${l?`opacity-60`:`cursor-pointer hover:bg-primary/5`}`,children:[s(Te,{checked:e.has(o),disabled:l,onChange:()=>t(et(e,o)),"data-testid":`${i}-${o}`}),n(`span`,{className:`min-w-0 flex-1`,children:[n(`span`,{className:`flex flex-wrap items-center gap-1.5 text-foreground`,children:[Ye(o),c===`absent`&&s(Ee,{variant:`neutral`,size:`sm`,children:`Not created yet`})]}),s(`span`,{className:`block text-[11px] text-foreground-subtle`,children:c===`absent`?Je:Xe(o)})]})]},o)})})})}t();function bt({onClose:e}){let t=a(),[r,i]=o(new Set(J)),c=me({onMutate:()=>{t.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{t.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),t.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),t.invalidateQueries({queryKey:[[`backup`,`listRuns`]]}),e()}});return s(h,{open:!0,onOpenChange:t=>!t&&e(),children:n(O,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[n(_,{children:[s(C,{children:`Back up now`}),s(`p`,{className:`text-xs text-foreground-subtle`,children:`Runs once and writes the archive to every enabled backup location.`})]}),s(de,{children:n(`div`,{className:`p-4`,children:[s(yt,{selected:r,onChange:i,disabled:c.isPending,testId:`backup-now-databases`}),c.error&&s(`p`,{role:`alert`,className:`pt-2 text-xs text-danger`,children:c.error.message})]})}),n(M,{children:[s(b,{variant:`outline`,size:`sm`,onClick:e,children:`Cancel`}),n(b,{size:`sm`,onClick:()=>{r.size!==0&&c.mutate(nt(r))},disabled:r.size===0||c.isPending,"data-testid":`backup-now-run`,children:[c.isPending?s(H,{className:`h-3.5 w-3.5 animate-spin`}):s(le,{className:`h-3.5 w-3.5`}),`Back up now`]})]})]})})}t();function xt(e){return e===null?`—`:new Date(e).toLocaleString()}function St(e){let t=new Blob([`${e.secretKey}\n`],{type:`text/plain`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`camstack-backup-key-${e.keyId}.txt`,r.click(),URL.revokeObjectURL(n)}function Ct({revealed:e,onDone:t}){let[r,i]=o(!1),[a,c]=o(!1);return s(h,{open:!0,onOpenChange:e=>!e&&r&&t(),children:n(O,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`border-danger/40`,"aria-labelledby":`backup-key-title`,children:[s(_,{children:n(C,{id:`backup-key-title`,children:[`Your backup key (`,e.keyId,`)`]})}),n(de,{className:`space-y-3`,children:[n(`p`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 p-2 text-xs text-foreground`,children:[s(k,{className:`mt-0.5 h-4 w-4 shrink-0 text-danger`}),s(`span`,{children:`This key is shown only once. CamStack does not keep it — not the hub, not its database, not its backups. Without it, an encrypted backup cannot be restored by anyone, including you. Store it in a password manager or print it, away from this server.`})]}),s(`div`,{className:`break-all rounded-md border border-border bg-background p-2 font-mono text-xs text-foreground select-all`,children:e.secretKey}),n(`div`,{className:`flex flex-wrap gap-2`,children:[n(b,{size:`sm`,variant:`outline`,onClick:()=>{navigator.clipboard?.writeText(e.secretKey).then(()=>c(!0))},children:[s(he,{className:`mr-1 h-3.5 w-3.5`}),a?`Copied`:`Copy`]}),n(b,{size:`sm`,variant:`outline`,onClick:()=>St(e),children:[s(N,{className:`mr-1 h-3.5 w-3.5`}),`Download as file`]})]}),n(`label`,{className:`flex items-center gap-2 text-xs text-foreground`,children:[s(`input`,{type:`checkbox`,checked:r,onChange:e=>i(e.target.checked),className:`accent-primary`}),`I have stored this key somewhere safe, off this server.`]})]}),s(M,{children:s(b,{size:`sm`,disabled:!r,onClick:t,children:`I have stored it`})})]})})}function wt(){let e=ue(),t=ye(),r=be(),a=U(),[c,l]=o(null),[u,d]=o(null),f=e.data?.enabled??!1,p=e.data?.active??null,m=(e.data?.keys??[]).filter(e=>e.retiredAt!==null),h=async()=>{if(await a({title:f?`Replace the backup key`:`Encrypt backups`,message:f?`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.`:`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:f?`Generate a new key`:`Generate the key`,variant:`warning`})){d(null);try{let e=await t.mutateAsync({});l({keyId:e.keyId,secretKey:e.secretKey})}catch(e){d(e instanceof Error?e.message:String(e))}}},_=async()=>{if(await a({title:`Turn backup encryption off`,message:`New backups will be written unencrypted. Existing encrypted backups still need their key to be restored.`,confirmLabel:`Turn off`,variant:`danger`})){d(null);try{await r.mutateAsync({}),e.refetch()}catch(e){d(e instanceof Error?e.message:String(e))}}};return n(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-4`,children:[n(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[n(`div`,{className:`flex items-center gap-2`,children:[f?s(g,{className:`h-4 w-4 text-success`}):s(j,{className:`h-4 w-4 text-foreground-subtle`}),s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Encryption`}),s(`span`,{className:`text-xs text-foreground-subtle`,children:f&&p!==null?`On — key ${p.keyId}, since ${xt(p.createdAt)}`:`Off — backups are not encrypted`})]}),s(`div`,{className:`flex gap-2`,children:f?n(i,{children:[s(b,{size:`sm`,variant:`outline`,disabled:t.isPending,onClick:()=>void h(),children:`Replace key`}),s(b,{size:`sm`,variant:`outline`,disabled:r.isPending,onClick:()=>void _(),children:`Turn off`})]}):s(b,{size:`sm`,disabled:t.isPending,onClick:()=>void h(),children:`Enable encryption`})})]}),s(`p`,{className:`text-xs text-foreground-subtle`,children:`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.`}),m.length>0&&n(`div`,{className:`text-xs`,children:[s(`p`,{className:`text-foreground-subtle`,children:`Older keys (backups made with them still need them):`}),s(`ul`,{className:`font-mono text-foreground`,children:m.map(e=>n(`li`,{children:[e.keyId,` · `,xt(e.createdAt),` → `,xt(e.retiredAt)]},e.keyId))})]}),u!==null&&s(`p`,{className:`text-xs text-danger`,children:u}),c!==null&&s(Ct,{revealed:c,onDone:()=>{l(null),e.refetch()}})]})}t();var Tt=[{id:`manual`,label:`Manual only`,cron:``},{id:`hourly`,label:`Every hour`,cron:`0 * * * *`,description:`On the hour`},{id:`every-3h`,label:`Every 3 hours`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,label:`Every 6 hours`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,label:`Daily at 03:00`,cron:`0 3 * * *`,description:`Every night at 3 AM`},{id:`weekly-sun`,label:`Weekly Sunday 03:00`,cron:`0 3 * * 0`,description:`Sunday morning at 3 AM`}];function Et(e){let t=e.trim();for(let e of Tt)if(e.cron===t)return e.id;return`custom`}function Dt({value:e,onChange:t,previewCount:r=5,disabled:i=!1}){let a=Et(e),[l,u]=o(a===`custom`);c(()=>{a!==`custom`&&u(!1)},[a]);let d=At(e,250),f=ae({cron:d,count:r},{enabled:d.trim().length>0}),p=f.data??null,m=e=>{u(!1),t(e.cron)},h=l||a===`custom`;return n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),n(`div`,{className:`flex flex-wrap gap-1.5`,children:[Tt.map(e=>s(`button`,{type:`button`,onClick:()=>m(e),disabled:i,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!l&&a===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.description??e.label,children:e.label},e.id)),s(`button`,{type:`button`,onClick:()=>{u(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:i,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(h?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),h&&n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),s(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:i,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),n(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,s(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),s(Ot,{cron:d,preview:p,loading:f.isFetching})]})}function Ot({cron:e,preview:t,loading:r}){return r&&t===null?n(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[s(H,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?s(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:`No future runs match this expression.`}):n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),s(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>n(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[s(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),s(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:kt(e)})]},`${e}-${t}`))})]}):s(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??`Invalid cron expression`})}function kt(e){let t=e-Date.now();if(t<=0)return`now`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function At(e,t){let[n,i]=o(e),a=r(()=>e,[e]);return c(()=>{let e=setTimeout(()=>i(a),t);return()=>clearTimeout(e)},[a,t]),n}t();var jt=[[`backup`,`listSchedules`]];function Mt({entry:e,onClose:t,onSaved:i}){let c=a(),l=ie(),u=l.data??[],[d,f]=o(e?.label??``),[p,m]=o(e?.cron??`0 3 * * *`),[h,g]=o(e?.enabled??!0),[_,y]=o(String(e?.retentionCount??7)),[x,S]=o(new Set(e?.locationIds??[])),[C,w]=o(new Set(e===null?J:X(e.databases))),T=V({onSuccess:()=>{c.invalidateQueries({queryKey:jt}),i()}}),E=e=>{S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},D=Number.parseInt(_,10),O=r(()=>d.trim().length>0&&x.size>0&&C.size>0&&!Number.isNaN(D)&&D>=1&&D<=1e3,[d,x,C,D]),k=()=>{O&&T.mutate({...e?{id:e.id}:{},label:d.trim(),cron:p.trim(),enabled:h,locationIds:Array.from(x),retentionCount:D,databases:[...Ze(C)]})},A=T.error instanceof Error?T.error.message:null;return s(De,{open:!0,onClose:t,title:e?`Edit backup entry`:`New backup entry`,icon:Ue,error:A,width:`lg`,testId:`backup-entry-form`,footer:n(b,{size:`sm`,type:`button`,onClick:k,disabled:!O||T.isPending,children:[T.isPending?s(H,{className:`h-3.5 w-3.5 animate-spin`}):null,e?`Save`:`Create entry`]}),children:n(`div`,{className:`space-y-4`,children:[s(v,{label:`Name`,required:!0,children:s(K,{value:d,onChange:e=>f(e.target.value),placeholder:`Nightly offsite`,autoFocus:!0,"data-testid":`backup-entry-name`})}),n(v,{label:`Locations (${String(x.size)} selected)`,required:!0,children:[l.isLoading&&n(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[s(H,{className:`h-3.5 w-3.5 animate-spin`}),`Loading locations…`]}),!l.isLoading&&u.length===0&&s(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:"No `backups` storage locations configured. Add one in Settings → Storage first."}),u.length>0&&s(`div`,{className:`max-h-52 divide-y divide-border overflow-y-auto rounded border border-border bg-background`,children:u.map(e=>n(`label`,{className:`flex cursor-pointer items-center justify-between px-3 py-2 text-xs hover:bg-primary/5`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`checkbox`,checked:x.has(e.id),onChange:()=>E(e.id),className:`accent-primary`}),s(`span`,{className:`text-foreground`,children:e.displayName})]}),n(`div`,{className:`flex items-center gap-1.5`,children:[s(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e.kind}),s(`span`,{className:`font-mono text-[10px] text-foreground-subtle`,children:e.id})]})]},e.id))})]}),s(yt,{selected:C,onChange:w,disabled:T.isPending,testId:`backup-entry-databases`}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[s(v,{label:`Retention (archives kept)`,required:!0,children:s(K,{type:`number`,min:1,max:1e3,value:_,onChange:e=>y(e.target.value),"data-testid":`backup-entry-retention`})}),s(v,{label:`Enabled`,description:`Run on schedule when checked.`,children:n(`label`,{className:`inline-flex cursor-pointer items-center gap-2 py-1.5 text-xs text-foreground`,children:[s(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),className:`accent-primary`,"data-testid":`backup-entry-enabled`}),s(`span`,{children:`Run on schedule`})]})})]}),s(v,{label:`Schedule`,children:s(Dt,{value:p,onChange:m,disabled:T.isPending})})]})})}t();var Nt=2e3,Pt=5e3;function Q(e){return e.state===`queued`||e.state===`running`}function Ft(e){if(e.state===`queued`)return{title:`Cancel queued backup run?`,message:`This run has not started. Cancelling removes it from the queue — nothing has been written, nothing is deleted.`,confirmLabel:`Cancel run`,variant:`warning`};let t=e.completedDestinationIds.length;return{title:`Stop this backup run?`,message:`The half-written staging archive is deleted and the destination currently uploading discards its partial copy. ${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.`}`,confirmLabel:`Stop run`,variant:`danger`}}function It(){let t=U(),[n,r]=o(null),i=fe(void 0,{refetchInterval:e=>(e.state.data??[]).some(Q)?Nt:Pt}),a=se({onSettled:()=>{r(null),i.refetch()}}),c=e(async e=>{await t(Ft(e))&&(r(e.id),a.mutate({runId:e.id}))},[t,a]);return s(Lt,{queryState:i.isError?`error`:i.data===void 0?`pending`:`ready`,runs:i.data??[],cancelingId:n,onCancelRequest:e=>{c(e)},now:Date.now()})}function Lt({queryState:e,runs:t,cancelingId:r,onCancelRequest:i,now:a}){let o=e===`ready`&&t.some(Q),c=t.filter(e=>e.state===`running`),l=t.filter(e=>e.state===`queued`),u=t.filter(e=>!Q(e)),d=[...c,...l,...u];return n(`section`,{className:`rounded-lg border border-border bg-surface`,children:[n(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border`,children:[s(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Runs`}),o&&n(`span`,{className:`inline-flex items-center gap-1 text-[10px] font-medium text-primary`,title:`A backup run is in progress`,children:[s(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary animate-pulse`}),`live`]}),s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:`One run executes at a time — queued runs wait in line.`})]}),e===`pending`&&s(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle animate-pulse`,children:`Checking for backup runs…`}),e===`error`&&s(`div`,{className:`px-3 py-2.5 text-xs text-danger`,children:`Could not read backup runs — the orchestrator did not answer.`}),e===`ready`&&t.length===0&&s(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle italic`,children:`No backup runs yet. Runs appear here the moment one starts — manual or scheduled.`}),e===`ready`&&t.length>0&&s(`div`,{className:`overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[720px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Run`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`State`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Progress`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Destinations`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Timing`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium w-28`,children:`Actions`})]})}),s(`tbody`,{children:d.map(e=>s(Rt,{run:e,canceling:r===e.id,onCancelRequest:i,now:a},e.id))})]})})]})}function Rt({run:e,canceling:t,onCancelRequest:r,now:i}){let a=Q(e);return n(`tr`,{className:`border-t border-border hover:bg-primary/5 align-top`,children:[n(`td`,{className:`px-3 py-2`,children:[s(`div`,{className:`text-foreground`,children:e.label??s(`span`,{className:`text-foreground-subtle italic`,children:`manual`})}),s(`div`,{className:`text-[10px] text-foreground-subtle font-mono`,title:e.id,children:e.id.slice(0,8)})]}),n(`td`,{className:`px-3 py-2`,children:[s(zt,{run:e}),e.state===`failed`&&e.error!==void 0&&s(`div`,{className:`mt-1 text-[10px] text-danger max-w-56 truncate`,title:e.error,children:e.error})]}),s(`td`,{className:`px-3 py-2`,children:s(Bt,{run:e})}),s(`td`,{className:`px-3 py-2`,children:s(Vt,{run:e})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle tabular-nums`,children:s(Ht,{run:e,now:i})}),s(`td`,{className:`px-3 py-2`,children:s(`div`,{className:`flex justify-end`,children:a&&n(`button`,{onClick:()=>r(e),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:e.state===`queued`?`Remove this run from the queue before it starts`:`Stop this run — the half-written archive is discarded`,children:[t?s(H,{className:`h-3 w-3 animate-spin`}):s(m,{className:`h-3 w-3`}),e.state===`queued`?`Cancel`:`Stop`]})})})]})}function zt({run:e}){switch(e.state){case`queued`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:[s(B,{className:`h-3 w-3`}),`Queued`]});case`running`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`,children:[s(H,{className:`h-3 w-3 animate-spin`}),e.phase===`uploading`?`Uploading`:`Building archive`]});case`succeeded`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-success/10 px-1.5 py-0.5 text-[10px] font-medium text-success`,children:[s(Ce,{className:`h-3 w-3`}),`Succeeded`]});case`failed`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-danger/10 px-1.5 py-0.5 text-[10px] font-medium text-danger`,children:[s(_e,{className:`h-3 w-3`}),`Failed`]});case`cancelled`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-amber-500/10 px-1.5 py-0.5 text-[10px] font-medium text-amber-700 dark:text-amber-300`,title:`Stopped before completing every destination — not a success`,children:[s(Oe,{className:`h-3 w-3`}),`Stopped`]})}}function Bt({run:e}){if(e.state===`queued`)return s(`span`,{className:`text-foreground-subtle`,children:e.queuePosition===void 0?s(`span`,{className:`italic`,children:`waiting its turn`}):n(`span`,{className:`inline-flex items-center gap-1`,children:[s(`span`,{className:e.queuePosition===1?`rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`:`rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium`,children:Ut(e.queuePosition)}),`in line`]})});if(e.state===`running`&&e.phase===`building`)return n(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[s(Le,{className:`h-3 w-3 text-primary`}),s(`span`,{className:`tabular-nums font-medium animate-pulse`,children:q(e.stagedBytes)}),s(`span`,{className:`text-foreground-subtle`,children:`staged so far`})]});if(e.state===`running`){let t=e.archiveSizeBytes;return n(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[s(We,{className:`h-3 w-3 text-primary`}),n(`span`,{className:`tabular-nums font-medium`,children:[q(e.uploadedBytes),t===void 0?``:` / ${q(t)}`]}),s(`span`,{className:`text-foreground-subtle`,children:`to current destination`})]})}let t=e.archiveSizeBytes??(e.stagedBytes>0?e.stagedBytes:void 0);return t===void 0?s(`span`,{className:`text-foreground-subtle italic`,children:`—`}):n(`span`,{className:`tabular-nums text-foreground`,children:[q(t),` archive`]})}function Vt({run:e}){let t=e.destinationIds.length,r=e.completedDestinationIds.length,i=e.failedDestinationIds.length;return t===0?s(`span`,{className:`text-foreground-subtle italic`,children:`not resolved yet`}):n(`div`,{className:`flex flex-col gap-0.5`,children:[n(`span`,{className:`text-foreground-subtle`,title:e.destinationIds.join(`, `),children:[t,` target`,t===1?``:`s`]}),n(`span`,{className:`inline-flex items-center gap-2 text-[10px]`,children:[r>0&&n(`span`,{className:`text-success`,title:`Kept their archive: ${e.completedDestinationIds.join(`, `)}`,children:[`✓ `,r,` completed`]}),i>0&&n(`span`,{className:`text-danger`,title:`Failed: ${e.failedDestinationIds.join(`, `)}`,children:[`✗ `,i,` failed`]})]})]})}function Ht({run:e,now:t}){return e.state===`queued`?n(`span`,{children:[`queued `,Wt(t-e.requestedAt),` ago`]}):e.startedAt===void 0?s(`span`,{children:`—`}):e.finishedAt===void 0?n(`span`,{children:[`running for `,Wt(t-e.startedAt)]}):n(`div`,{className:`flex flex-col gap-0.5`,children:[s(`span`,{children:Gt(e.finishedAt)}),n(`span`,{className:`text-[10px]`,children:[`took `,Wt(e.finishedAt-e.startedAt)]})]})}function Ut(e){if(e<=1)return`next`;let t=e%100;if(t>=11&&t<=13)return`${e}th`;switch(e%10){case 1:return`${e}st`;case 2:return`${e}nd`;case 3:return`${e}rd`;default:return`${e}th`}}function Wt(e){let t=Math.max(0,Math.floor(e/1e3));if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m ${String(t%60).padStart(2,`0`)}s`:`${Math.floor(n/60)}h ${String(n%60).padStart(2,`0`)}m`}function Gt(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}t();var Kt=[[`backup`,`list`]];function qt({initialDestinationId:e,initialArchiveId:t,onClose:i,onScheduled:l}){let u=a(),[d,f]=o(e&&t?2:1),[p,m]=o(e),[g,v]=o(t),[y,x]=o(new Set),[S,w]=o(``),{data:T}=ie(),E=T??[],{data:k,isLoading:j}=ve({destinationId:p??``},{enabled:!!p}),N=k??[];c(()=>{if(p!==void 0)return;let e=E.filter(e=>e.restoreSupported);e.length===1&&m(e[0].id)},[p,E]);let{data:P}=ne({destinationId:p??``,backupId:g??``},{enabled:!!p&&!!g}),F=r(()=>P?.locations??[],[P]);c(()=>{F.length!==0&&x(e=>e.size===0?new Set(F):e)},[F]);let I=ce({onSuccess:()=>{u.invalidateQueries({queryKey:Kt}),l(),i()}}),ee=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},L=N.find(e=>e.id===g),te=L?.encryption!==void 0,R=rt(L?.databases,P?.sqliteSnapshots),z=tt(R),B=!!p&&!!g,re=z||y.size>0,ae=B&&re&&!I.isPending&&(!te||S.trim().length>0),oe=()=>{!p||!g||I.mutate({destinationId:p,backupId:g,...z?{}:{locations:[...y]},...te?{backupSecretKey:S.trim()}:{}})};return s(h,{open:!0,onOpenChange:e=>!e&&i(),children:n(O,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[n(_,{children:[s(C,{children:`Restore Backup`}),n(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,d,` of 3 —`,` `,d===1?`pick source`:d===2?`pick locations`:`confirm`]})]}),n(de,{children:[d===1&&s(Jt,{destinations:E,destinationId:p,onPickDestination:e=>{m(e),v(void 0),x(new Set)},archives:N,archivesLoading:j,archiveId:g,onPickArchive:v}),d===2&&s(Yt,{locations:F,picked:y,onToggle:ee,databases:R,snapshotsOnly:z}),d===3&&s(Xt,{destinationName:E.find(e=>e.id===p)?.displayName??p??``,archive:L,picked:[...y],databases:R,snapshotsOnly:z}),d===3&&L?.encryption!==void 0&&s(Zt,{keyId:L.encryption.keyId,value:S,onChange:w}),d===3&&I.error&&s(`p`,{role:`alert`,className:`px-4 pb-2 text-xs text-danger`,children:I.error.message})]}),n(M,{className:`justify-between`,children:[s(`div`,{children:d>1&&n(b,{variant:`outline`,size:`sm`,onClick:()=>f(e=>e===3?2:1),children:[s(A,{className:`h-3 w-3`}),`Back`]})}),n(`div`,{className:`flex items-center gap-2`,children:[s(b,{variant:`outline`,size:`sm`,onClick:i,children:`Cancel`}),d<3?n(b,{size:`sm`,disabled:d===1&&!B||d===2&&!re,onClick:()=>f(e=>e===1?2:3),children:[`Next`,s(D,{className:`h-3 w-3`})]}):n(b,{size:`sm`,onClick:oe,disabled:!ae,children:[I.isPending?s(H,{className:`h-3.5 w-3.5 animate-spin`}):s(G,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function Jt({destinations:e,destinationId:t,onPickDestination:r,archives:i,archivesLoading:a,archiveId:o,onPickArchive:c}){let l=e.filter(e=>e.restoreSupported);return n(`div`,{className:`p-4 space-y-3`,children:[n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),s(R,{value:t??``,onChange:e=>r(e.target.value),options:[{value:``,label:`Select destination…`},...l.map(e=>({value:e.id,label:`${e.displayName} (${e.kind})`}))]})]}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&a&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!a&&i.length===0&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&i.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:i.map(e=>{let t=o===e.id;return n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>c(e.id),className:`accent-primary`}),n(`div`,{children:[n(`div`,{className:`flex items-center gap-1 font-medium text-foreground`,children:[e.encryption!==void 0&&s(g,{className:`h-3 w-3 text-success`,"aria-label":`encrypted (key ${e.encryption.keyId})`}),e.label??e.id]}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()}),s(`div`,{className:`pt-1`,children:s(Z,{databases:rt(e.databases,void 0)})})]})]}),s(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:q(e.sizeBytes)})]},e.id)})})]})]})}function Yt({locations:e,picked:t,onToggle:r,databases:i,snapshotsOnly:a}){return a?n(`div`,{className:`space-y-3 p-4`,children:[n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Databases in this archive`}),s(Z,{databases:i})]}),s(`div`,{className:`rounded border border-info/30 bg-info/10 px-3 py-2 text-[11px] text-info`,children:`Snapshots only: restoring this archive replaces just these databases. It does NOT touch configuration, addons, addon data or certificates.`})]}):e.length===0?s(`div`,{className:`p-4`,children:s(`div`,{className:`text-xs text-foreground-subtle`,children:`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`})}):n(`div`,{className:`p-4 space-y-3`,children:[n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Databases in this archive`}),s(Z,{databases:i})]}),s(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-[11px] text-warning`,children:`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>n(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>r(e),className:`accent-primary`}),s(`span`,{className:`font-mono text-foreground`,children:e}),s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:$t(e)})]},e))})]})]})}function Xt({destinationName:e,archive:t,picked:r,databases:i,snapshotsOnly:a}){return n(`div`,{className:`p-4 space-y-3 text-xs`,children:[s(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-warning`,children:`Restore is applied at next server boot. Active connections will drop when you restart.`}),n(`dl`,{className:`space-y-1.5`,children:[s($,{term:`Destination`,value:e}),s($,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&s($,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${q(t.sizeBytes)}`}),s($,{term:`Databases`,value:i.map(e=>Ye(e)).join(`, `)}),s($,{term:`Locations`,value:a?`none (configuration is not touched)`:r.length>0?r.join(`, `):`— (full archive)`})]})]})}function Zt({keyId:e,value:t,onChange:r}){return n(`div`,{className:`space-y-1.5 px-4 pb-3`,children:[s(`label`,{htmlFor:`restore-backup-key`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Backup key`}),s(`input`,{id:`restore-backup-key`,type:`password`,autoComplete:`off`,spellCheck:!1,value:t,onChange:e=>r(e.target.value),placeholder:`camstack-backup-secret-v1:…`,className:`w-full rounded border border-border bg-background px-2 py-1.5 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`This archive is encrypted to backup key `,s(`span`,{className:`font-mono`,children:e}),`. Paste the secret key shown when that key was created. It is used to decrypt the archive on this server and is not stored.`]})]})}function $({term:e,value:t}){return n(`div`,{className:`flex justify-between gap-3`,children:[s(`dt`,{className:`text-foreground-subtle`,children:e}),s(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Qt={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function $t(e){return Qt[e]??``}t();function en(){let e=U(),t=F(),{state:r,openNew:i,openEdit:a,close:l}=T({editKey:`edit`,newKey:`new`}),u=we(),d=u.data??[],[f,p]=o(null),[m,h]=o(!1),[g,_]=o(!1),[v,y]=o(!1),x=r.mode===`edit`?d.find(e=>e.id===r.id)??null:null;c(()=>{r.mode===`edit`&&!u.isLoading&&x===null&&l()},[r.mode,u.isLoading,x,l]);let S=r.mode===`new`||r.mode===`edit`&&x!==null,C=async()=>{await e({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&t.mutate({confirm:!0})};return n(Ve,{embedded:!0,children:[n(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,"data-testid":`backup-actions`,children:[n(b,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>y(!0),"data-testid":`backup-now`,children:[s(le,{className:`h-3.5 w-3.5`}),`Back up now`]}),n(b,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>h(!0),children:[s(G,{className:`h-3.5 w-3.5`}),`Restore…`]}),n(b,{size:`sm`,type:`button`,onClick:i,"data-testid":`backup-new-entry`,children:[s(pe,{className:`h-3.5 w-3.5`}),`New entry`]})]}),g&&s(`div`,{className:`rounded-lg border border-warning/30 bg-warning/10 px-3 py-2.5 text-xs text-warning`,children:n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(G,{className:`h-3.5 w-3.5`}),s(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),n(b,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>{C()},disabled:t.isPending,children:[t.isPending?s(H,{className:`h-3.5 w-3.5 animate-spin`}):s(G,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),s(wt,{}),s(It,{}),s(ut,{onEdit:e=>a(e.id),onOpenRestoreWizard:e=>p(e)}),S&&s(Mt,{entry:x,onClose:l,onSaved:l}),v&&s(bt,{onClose:()=>y(!1)}),(f||m)&&s(qt,{...f?{initialDestinationId:f.destinationId,initialArchiveId:f.archiveId}:{},onClose:()=>{p(null),h(!1)},onScheduled:()=>_(!0)})]})}function tn(){let{t:e}=Re(),t=ze(`/system/data`,{t:e,isAdmin:!0})??{icon:oe,title:e(`system.data`,`Data`)};return s(Be,{icon:t.icon,title:t.title,defaultSection:`storage`,sectionsLabel:`${t.title} sections`,sections:[{id:`storage`,label:`Storage`,content:s(Ge,{})},{id:`backup`,label:`Backup`,content:s(en,{})}]})}export{tn as DataPage};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,a,b as o,o as s,q as c,t as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{D as f,G as p,J as m,K as h,O as g,T as _,V as v,W as y,Z as b,ct as x,dt as S,ht as C,m as w,ot as T,r as E,t as D,ut as O,vt as k,yt as A,z as j}from"./player-overlays-4f4KZjKK.js";import{$r as M,A as N,Ac as ee,Ad as P,Ai as F,An as te,Bn as I,Cd as L,Cf as R,Ct as z,Df as B,Fi as ne,Fn as V,Gi as re,Gn as H,Gu as U,Hn as ie,Ht as ae,Ii as oe,In as se,Is as ce,Ji as W,K as le,Kn as G,Ks as ue,Kt as de,Ln as fe,Lr as pe,Ls as K,M as me,Mn as he,Ms as ge,Mt as _e,Ns as ve,Oa as ye,Pa as be,Pn as xe,Ps as Se,Qt as Ce,Rf as we,Rn as Te,S as Ee,T as q,Ta as De,Tf as Oe,Tt as ke,Va as Ae,Vi as je,Vn as Me,Vs as Ne,Vt as Pe,Vu as Fe,W as Ie,Wa as Le,Wi as Re,Xl as ze,Yd as Be,Yi as Ve,Zn as He,Zt as Ue,_o as We,_t as Ge,_u as Ke,a as qe,ac as Je,an as Ye,at as Xe,b as Ze,ba as Qe,bd as $e,bn as et,bt as tt,bu as nt,c as rt,cd as it,cn as at,cs as ot,ct as st,cu as ct,d as lt,da as ut,dr as dt,dt as ft,ed as pt,ef as mt,en as ht,es as gt,et as _t,fa as vt,fd as yt,fn as bt,fr as xt,ft as St,ga as Ct,gn as wt,gt as Tt,ha as Et,hc as Dt,hf as Ot,hn as kt,ht as At,hu as jt,i as Mt,ic as Nt,in as Pt,it as Ft,j as It,jd as Lt,ji as Rt,jn as zt,k as Bt,kd as Vt,kn as Ht,l as Ut,ld as Wt,ln as Gt,lt as Kt,mn as qt,nc as Jt,nd as Yt,nn as Xt,nr as Zt,nt as Qt,nu as $t,o as en,oa as tn,oc as nn,on as rn,ot as an,ou as on,pn as sn,po as cn,q as ln,qa as un,qi as dn,r as fn,ra as pn,rc as mn,rn as hn,s as gn,sc as _n,sd as vn,sf as yn,tf as bn,tn as xn,tu as Sn,uf as Cn,un as wn,ur as Tn,us as En,uu as Dn,va as On,vd as kn,vo as An,w as jn,wf as Mn,wt as Nn,wu as Pn,x as Fn,xd as In,xt as Ln,xu as Rn,y as zn,ya as Bn,yd as Vn,yo as Hn,yr as Un,yt as Wn,zd as Gn,zt as Kn}from"./src-DHEqfaFh.js";import{t as qn}from"./archive-BDsI1Dbp.js";import{t as Jn}from"./boxes-BM0v3X80.js";import{t as Yn}from"./circle-slash-C0s73mTj.js";import{_ as Xn,a as Zn,c as Qn,d as $n,f as er,g as tr,h as nr,i as rr,l as ir,m as ar,n as or,o as sr,p as cr,s as lr,t as ur,u as dr,v as fr,y as pr}from"./ClusterStepModel-BW7HnI0Q.js";import{t as mr}from"./layers-a5eCLI1t.js";import{Cr as J,Dr as Y,Er as hr,Fn as gr,In as _r,Ir as vr,Ln as yr,Lr as br,Mn as xr,Or as X,Sr,Zn as Cr,_ as wr,an as Tr,ar as Er,b as Dr,br as Or,f as kr,fi as Ar,fn as jr,g as Mr,hn as Nr,hr as Pr,in as Fr,lr as Ir,m as Lr,on as Rr,p as zr,pi as Br,pn as Vr,pr as Hr,rn as Ur,sn as Wr,u as Gr}from"./client-Da5ic7fF.js";import{t as Z}from"./useTranslation-Bc5yH9V9.js";import"./mount-dhif7MNn.js";import{$ as Kr,A as qr,B as Jr,D as Yr,G as Xr,J as Zr,K as Qr,M as $r,N as ei,O as ti,Q as ni,R as ri,U as ii,V as ai,W as oi,Y as si,Z as ci,_ as li,b as ui,et as di,j as fi,k as pi,y as mi,z as hi}from"./index-Bi6aHCQm.js";import{C as gi,D as _i,E as vi,S as yi,_ as bi,a as xi,b as Si,c as Ci,d as wi,f as Ti,g as Ei,h as Di,i as Oi,l as ki,m as Ai,n as ji,o as Mi,p as Ni,r as Pi,s as Fi,t as Ii,u as Li,v as Ri,x as zi,y as Bi}from"./CompositionEditor-CAtKL9zi.js";import"./useEventInvalidation-dhif7MNn.js";import{t as Vi}from"./use-stationary-objects-CvNiN6bl.js";import"./device-picker-model-dhif7MNn.js";import{t as Hi}from"./authed-media-j0JPywRs.js";var Ui=A(`arrow-left-right`,[[`path`,{d:`M8 3 4 7l4 4`,key:`9rb6wj`}],[`path`,{d:`M4 7h16`,key:`6tx8e3`}],[`path`,{d:`m16 21 4-4-4-4`,key:`siv7j2`}],[`path`,{d:`M20 17H4`,key:`h6l3hr`}]]),Wi=A(`disc`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]),Gi=A(`ear`,[[`path`,{d:`M6 8.5a6.5 6.5 0 1 1 13 0c0 6-6 6-6 10a3.5 3.5 0 1 1-7 0`,key:`1dfaln`}],[`path`,{d:`M15 8.5a2.5 2.5 0 0 0-5 0v1a2 2 0 1 1 0 4`,key:`1qnva7`}]]),Ki=A(`scan-eye`,[[`path`,{d:`M3 7V5a2 2 0 0 1 2-2h2`,key:`aa7l1z`}],[`path`,{d:`M17 3h2a2 2 0 0 1 2 2v2`,key:`4qcy5o`}],[`path`,{d:`M21 17v2a2 2 0 0 1-2 2h-2`,key:`6vwrx8`}],[`path`,{d:`M7 21H5a2 2 0 0 1-2-2v-2`,key:`ioqczr`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`path`,{d:`M18.944 12.33a1 1 0 0 0 0-.66 7.5 7.5 0 0 0-13.888 0 1 1 0 0 0 0 .66 7.5 7.5 0 0 0 13.888 0`,key:`11ak4c`}]]);n();function qi(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 Ji(e){if(typeof e!=`object`||!e)return null;let t=e.switches;if(!Array.isArray(t))return null;let n=t.map(qi).filter(e=>e!==null);return n.length===0?null:n}var Yi=[[/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 Xi(e){for(let[t,n]of Yi)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(`Off: ${r(t)}`),n.length>0&&i.push(`Unknown: ${r(n)}`),{offIds:t,unknownIds:n,summary:i.length===0?`All camera functions on`:i.join(` · `)}}var Qi={stream:Wt,detection:Ki,privacy:C,microphone:S,speaker:Pn,listening:Gi,archive:qn,recording:Wi,notifications:R,generic:U};function $i({deviceId:t}){let n=s(),i=Number.isFinite(t),[a,o]=c(null),[l,d]=c(!1),f=K({deviceId:t},{enabled:i});fn([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let p=Ji(f.data),m=_n({onError:(e,r)=>{console.error(`[CameraFunctionSwitches] switch write failed — reverting`,{tags:{deviceId:t},meta:{switchId:r.switchId,error:e instanceof Error?e.message:String(e)}}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSwitches`]]}),o({id:r.switchId,message:e instanceof Error?e.message:String(e)})},onSuccess:()=>{o(null),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),n.invalidateQueries({queryKey:[[`deviceManager`]]}),n.invalidateQueries({queryKey:[[`recording`]]})}}),h=e(e=>{!e.available||e.on===null||m.mutate({deviceId:t,switchId:e.id,enabled:!e.on})},[t,m]);if(p===null)return null;let g=Zi(p),_=e=>a?.id===e.id?a.message:null;return r(Pt,{open:l,onOpenChange:d,children:[r(rn,{"aria-label":`Camera functions`,title:g.summary,className:`inline-flex items-center gap-1 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors ${a===null?g.offIds.length>0?`border-warning/40 text-warning hover:bg-warning/10`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`:`border-danger/50 text-danger bg-danger/5`}`,children:[u(U,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden lg:inline`,children:`Functions`}),g.offIds.length>0&&r(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:[g.offIds.length,` off`]})]}),r(Ye,{align:`end`,className:`min-w-[240px] max-h-[60vh] overflow-y-auto p-1`,children:[u(`div`,{className:`px-2 py-1 text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Camera functions`}),u(`ul`,{className:`space-y-0.5`,children:p.map(e=>u(`li`,{children:u(ea,{row:e,failure:_(e),onToggle:()=>h(e)})},e.id))})]})]})}function ea({row:e,failure:t,onToggle:n}){let i=Qi[Xi(e.label)],a=e.on===null,o=e.on===!1,s=t===null?a?e.unavailableReason??`The source that owns this did not answer.`:e.costWhenOff:`Write failed: ${t}`,c=t===null?a?e.unavailableReason??`unknown`:null:`write failed`;return r(`button`,{type:`button`,role:`switch`,"aria-label":e.label,"aria-checked":e.on===!0,disabled:!e.available,onClick:n,title:s,className:`flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-[12px] text-foreground transition-colors hover:bg-surface-hover disabled:opacity-40 disabled:cursor-not-allowed`,children:[u(i,{className:`h-3.5 w-3.5 shrink-0 ${t===null?a?`text-foreground-subtle/50`:o?`text-warning`:`text-success`:`text-danger`}`}),r(`span`,{className:`flex-1 min-w-0 truncate`,children:[e.label,c!==null&&r(`span`,{className:`ml-1 text-[10px] text-foreground-subtle`,children:[`· `,c]})]}),u(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[9px] font-semibold uppercase tracking-wide ${a?`bg-surface-hover text-foreground-subtle/60`:o?`bg-warning/20 text-warning`:`bg-success/20 text-success`}`,children:a?`—`:o?`off`:`on`})]})}function ta({deviceId:e}){let t=ft(T().trpcClient,e);return t===null?null:r(`a`,{href:t.url,target:`_blank`,rel:`noopener noreferrer`,title:`${t.label} — ${t.host}`,className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[u(Be,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:t.label})]})}function na({parentDeviceId:e}){let{t}=Z(),n=ci(),i=T(),{data:a,isLoading:o,isError:s}=ai(e),{data:c}=Et({deviceId:e},{enabled:Number.isFinite(e)});if(o)return u(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(s)return u(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let l=(a??[]).filter(e=>e.display?.hidden!==!0);if(l.length===0)return null;let d=an(c?.stableId??``,l,c?.childLayout),f=d.ungrouped,p=e=>n(`/devices/${String(e)}`),m=c?.name??``,h=(e,t)=>u(Ft,{trpc:i.trpcClient,device:{...t,name:St(t,m)},variant:`minimal`,onNavigate:p},e),g=f.some(e=>!!e.role),_=f.some(e=>!e.role),v=g&&!_?t(`device.accessories`,{defaultValue:`Accessories`}):!g&&_?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),y=f.length>0?r(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[u(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:v}),u(`div`,{className:`space-y-1`,children:f.map(e=>h(e.id,e))})]}):null,b=d.disabledSection===void 0?null:u(Xe,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:d.disabledSection.children.length,defaultOpen:!1,children:u(`div`,{className:`opacity-60 space-y-1`,children:d.disabledSection.children.map(e=>h(e.id,e))})},d.disabledSection.title);if(d.sections.length===0)return b===null?y:r(`div`,{className:`space-y-2`,children:[y,b]});let x=_&&!g;return r(`div`,{className:`space-y-2`,children:[x?y:null,d.sections.map(e=>u(Xe,{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 ra({deviceId:e}){let t=T(),{data:n,isLoading:r}=Jr(e),{data:i,isLoading:a}=ai(e),o=r||a,s=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),c=typeof n?.linkDeviceId==`number`?n.linkDeviceId:null,l=typeof n?.primaryChildEntityId==`string`?n.primaryChildEntityId:null;return o?u(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):u(`div`,{className:`flex h-full w-full flex-col`,children:u(At,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}n();function ia({dev:e,busy:t,setBusy:n}){let i=e?.motionTrigger,a=m(e?.state.motionTrigger),[o,s]=c(!1);if(!i)return null;let l=a?.enabled===!0,d=a!==void 0,f=async()=>{if(t||!d)return;let e=!l;n(!0),s(!0);try{await i.setMotionTrigger({enabled:e})}finally{n(!1),s(!1)}};return r(`button`,{type:`button`,onClick:()=>{f()},disabled:t||!d,title:d?l?`Disable trigger on motion`:`Enable trigger on motion`:`Awaiting state…`,"aria-pressed":l,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 ${l?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[u(we,{className:`h-3 w-3`}),u(`span`,{children:o?l?`Disabling…`:`Enabling…`:d?l?`On motion: on`:`On motion: off`:`On motion: …`})]})}n();function Q({deviceId:e,deviceType:t,features:n}){let i=T(),a=Wn(t)?.HeroCard??tt,o=h(i.trpcClient,e),s=m(o?.state.deviceStatus),[l,d]=c(!1),f=s!==void 0&&s.online===!1,p=f?s.lastChangedAt:null;return r(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[f?u(`div`,{className:`flex justify-center`,children:u(Ge,{lastChangedAt:p})}):null,u(a,{trpc:i.trpcClient,deviceId:e,features:n}),u(`div`,{className:`flex justify-center`,children:u(ia,{dev:o,busy:l,setBusy:d})})]})}function aa({deviceId:e,features:t}){return u(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:u(Ln,{trpc:T().trpcClient,deviceId:e,features:t})})}function oa({deviceId:e,features:t}){return u(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:u(tt,{trpc:T().trpcClient,deviceId:e,features:t})})}function sa(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function ca(e){if(!e)return null;let t=sa(e.data);return t===null?e.eventType:`Button ${String(t)} · ${e.eventType}`}var la=1e3,ua=60*la,da=60*ua,fa=24*da;function pa(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<la?`just now`:n<ua?`${String(Math.floor(n/la))}s ago`:n<da?`${String(Math.floor(n/ua))}m ago`:n<fa?`${String(Math.floor(n/da))}h ago`:`${String(Math.floor(n/fa))}d ago`}n();var ma=1500,ha=15e3,ga=1e3;function _a({deviceId:e}){let n=h(T().trpcClient,e)?.state.eventEmitter,i=m(n);d(()=>{if(!n)return;n.refresh();let e=setInterval(()=>{n.refresh()},ha);return()=>{clearInterval(e)}},[n]);let a=i?.lastEvent??null,o=a?.seq??null,s=t(null),[l,f]=c(!1);d(()=>{if(o===null)return;let e=s.current;if(s.current=o,e===null||e===o)return;f(!0);let t=setTimeout(()=>{f(!1)},ma);return()=>{clearTimeout(t)}},[o]);let[p,g]=c(()=>Date.now());d(()=>{let e=setInterval(()=>{g(Date.now())},ga);return()=>{clearInterval(e)}},[]);let _=ca(a),v=i?.eventTypes??[],y=i?.eventCountSinceStart??0,b=i!==void 0,x=sa(a?.data);return r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[u(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(l),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${l?`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:_??`No press recorded`,children:u(l?$e:Gn,{className:`h-10 w-10`})}),r(`div`,{className:`text-center`,children:[x!==null&&u(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:`Button ${String(x)}`}),u(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${_?`text-foreground`:`text-foreground-subtle`}`,children:_??(b?`No press recorded`:`Awaiting state…`)}),u(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:a?pa(a.timestamp,p):`Waiting for the first event`})]}),v.length>0&&u(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:v.map(e=>u(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===a?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),u(`div`,{className:`text-[10px] text-foreground-subtle`,children:`${String(y)} ${y===1?`event`:`events`} since start`})]})}function va({deviceName:e,deviceType:t,provider:n,isOnline:i,features:a}){return r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[u(Qr,{type:n,size:`lg`}),r(`div`,{children:[u(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),u(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),r(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[u(me,{status:i?`online`:`offline`}),a.length>0&&u(Zr,{capabilities:a})]}),u(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:`No live view for this device type. Use the Config tab or the shortcut row to interact.`})]})}n();function ya({deviceId:e}){let t=s(),n=Re({deviceId:e},{refetchInterval:1e4,retry:!1}),a=re({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),o=i(()=>ba(n.data??[]),[n.data]);return r(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[r(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[u(xa,{label:`Discovered`,value:o.total,icon:u(Vn,{className:`h-3.5 w-3.5`})}),u(xa,{label:`Adopted`,value:o.adopted,accent:`success`}),u(xa,{label:`Available`,value:o.available,accent:o.available>0?`primary`:void 0}),r(`button`,{type:`button`,onClick:()=>{a.mutateAsync({deviceId:e}).catch(()=>{})},disabled:a.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:[a.isPending?u(Vt,{className:`h-3.5 w-3.5 animate-spin`}):u(it,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[u(Sa,{icon:u(nt,{className:`h-3 w-3 text-emerald-500`}),label:`${o.online} online`}),u(Sa,{icon:u(In,{className:`h-3 w-3 text-amber-500`}),label:`${o.sleeping} sleeping`}),u(Sa,{icon:u(Rn,{className:`h-3 w-3 text-destructive`}),label:`${o.offline} offline`}),o.unknown>0?u(Sa,{icon:u(yn,{className:`h-3 w-3 text-foreground-subtle`}),label:`${o.unknown} unknown`}):null]})]})}function ba(e){let t={total:e.length,adopted:0,available:0,online:0,sleeping:0,offline:0,unknown:0};for(let n of e)n.alreadyAdopted?t.adopted+=1:t.available+=1,t[n.status]+=1;return t}function xa({label:e,value:t,icon:n,accent:i}){return r(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${i===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:i===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[r(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,u(`span`,{className:`truncate`,children:e})]}),u(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function Sa({icon:e,label:t}){return r(`span`,{className:`inline-flex items-center gap-1`,children:[e,u(`span`,{children:t})]})}var Ca={[X.Switch]:Q,[X.Siren]:Q,[X.Light]:Q,[X.Sensor]:Q,[X.Button]:Q,[X.Hub]:ya,[X.Cover]:aa,[X.Valve]:Q,[X.Humidifier]:Q,[X.WaterHeater]:Q,[X.Container]:ra,[X.Lock]:Q,[X.Fan]:Q,[X.Thermostat]:Q,[X.Climate]:Q,[X.MediaPlayer]:Q,[X.Control]:Q,[X.AlarmPanel]:Q,[X.EventEmitter]:_a,[X.Notifier]:oa,[X.Script]:Q,[X.Automation]:Q,[X.Presence]:Q,[X.Update]:Q,[X.Vacuum]:Q,[X.LawnMower]:Q,[X.Weather]:Q,[X.Image]:Q,[X.PetFeeder]:Q};function wa(e){return Ca[e]??va}function Ta(e){return u(wa(e.deviceType),{...e})}function Ea(e){return en(T().trpcClient,e)}n();function Da(n){let[r,i]=c(`idle`),[a,o]=c(null),s=t(null),l=t(null),u=t(null),f=t(!0),p=An(),m=We(),h=Hn(),g=e(()=>{if(s.current){try{s.current.close()}catch{}s.current=null}if(l.current){for(let e of l.current.getTracks())try{e.stop()}catch{}l.current=null}u.current=null},[]),_=e(async()=>{if(r===`idle`)return;i(`stopping`);let e=u.current;if(e&&n!==null)try{await Promise.race([h.mutateAsync({deviceId:n,sessionId:e}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}g(),f.current&&(i(`idle`),o(null))},[r,n,h,g]),v=e(async()=>{if(n===null||r!==`idle`&&r!==`error`)return;o(null);let e=null,t=null,a=null;try{i(`requesting-mic`),e=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),l.current=e,i(`starting`);let r=await p.mutateAsync({deviceId:n});a=r.sessionId,u.current=a,i(`connecting`),t=new RTCPeerConnection,s.current=t,t.oniceconnectionstatechange=()=>{if(!f.current)return;let e=t.iceConnectionState;e===`connected`||e===`completed`?i(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&f.current&&(o(e===`failed`?`WebRTC connection failed`:null),_())};for(let n of e.getAudioTracks())t.addTrack(n,e);await t.setRemoteDescription({type:`offer`,sdp:r.sdpOffer});let c=await t.createAnswer();await t.setLocalDescription(c);let d=t.localDescription?.sdp??c.sdp??``;await m.mutateAsync({deviceId:n,sessionId:a,sdpAnswer:d})}catch(r){let c=r instanceof Error?r.message:String(r);if(console.warn(`[intercom] start failed`,r),t)try{t.close()}catch{}if(e)for(let t of e.getTracks())try{t.stop()}catch{}if(s.current=null,l.current=null,a!==null)try{await h.mutateAsync({deviceId:n,sessionId:a})}catch{}u.current=null,f.current&&(o(c),i(`error`))}},[n,r,p,m,h,_]);return d(()=>(f.current=!0,()=>{f.current=!1;let e=u.current;if(e!==null&&n!==null&&h.mutate({deviceId:n,sessionId:e}),s.current){try{s.current.close()}catch{}s.current=null}if(l.current){for(let e of l.current.getTracks())try{e.stop()}catch{}l.current=null}u.current=null}),[n]),{state:r,error:a,start:v,stop:_,isTalking:r===`talking`}}n();var Oa=0;function $(){return++Oa}function ka(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Aa(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 ja(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 Ma(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 Na({scope:n,greeting:i,className:a}){let o=T(),[s,f]=c(()=>{let e=[];return i&&e.push({id:$(),kind:`info`,text:i}),e.push({id:$(),kind:`info`,text:`scope: ${ka(n)} — type help or context for available commands`}),e}),[p,m]=c(``),[h,g]=c([]),[_,v]=c(-1),y=t(null),b=t(null);d(()=>{let e=b.current;e&&(e.scrollTop=e.scrollHeight)},[s]);let x=e(()=>{y.current?.focus()},[]),S=l({mutationFn:e=>o.trpcClient.repl.execute.mutate({code:e,scope:n}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;f(e=>[...e,{id:$(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);f(e=>[...e,{id:$(),kind:`error`,text:t}])}});function C(e){let t=e.trim();if(t){if(t===`clear`){f([{id:$(),kind:`info`,text:`scope: ${ka(n)}`}]),m(``);return}if(t===`help`){f(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`},...Aa(n).map(e=>({id:$(),kind:`info`,text:e}))]),m(``);return}if(t===`context`){f(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`},...Ma(n).map(e=>({id:$(),kind:`info`,text:e}))]),m(``);return}if(t===`examples`){f(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`},...ja(n).map(e=>({id:$(),kind:`info`,text:e}))]),m(``);return}g(e=>[...e,t]),v(-1),f(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`}]),m(``),S.mutate(t)}}function w(e){if(e.key===`Enter`){e.preventDefault(),C(p);return}if(e.key===`ArrowUp`){if(e.preventDefault(),h.length===0)return;let t=_===-1?h.length-1:Math.max(0,_-1);v(t),m(h[t]??``);return}if(e.key===`ArrowDown`){if(e.preventDefault(),_===-1)return;let t=_+1;t>=h.length?(v(-1),m(``)):(v(t),m(h[t]??``));return}e.ctrlKey&&e.key===`l`&&(e.preventDefault(),f([{id:$(),kind:`info`,text:`scope: ${ka(n)}`}]))}let E={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return r(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${a??``}`,onClick:x,children:[r(`div`,{ref:b,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[s.map(e=>u(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${E[e.kind]}`,children:e.text},e.id)),S.isPending&&u(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),r(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[u(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),u(`input`,{ref:y,value:p,onChange:e=>m(e.target.value),onKeyDown:w,disabled:S.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 Pa(e,t){return e===null?null:{playbackUrl:e.url,...e.format===void 0?{}:{playbackFormat:e.format},playbackAuthToken:t,...e.label===void 0?{}:{playbackLabel:e.label}}}n();function Fa({deviceId:e,intercomAvailable:t=!1}){let n=T(),r=typeof window<`u`?b():``,a=Number.isFinite(e),s=Ea(a?e:null),c=Vi(a?[e]:[]),l=i(()=>{if(!a)return;let e=[];for(let t of c.rows){let n=qe(t);n!==null&&e.push(n)}return e},[a,c.rows]),{streams:d,pipelineMetrics:f,createSession:m,sendAnswer:h,handleOffer:g,getIceServers:_,addIceCandidate:v,getIceCandidates:y,closeSession:x,getSessionState:S,applyDownlinkProbe:C}=Kn(n.trpcClient,a?e:null),w=p(a?e:null,{width:Ba}),D=Da(a&&t?e:null),O=D.state===`requesting-mic`||D.state===`starting`||D.state===`connecting`||D.state===`stopping`,k=D.isTalking||O,A=()=>{D.state===`idle`||D.state===`error`?D.start():D.state!==`stopping`&&D.stop()},j=E(),M=Me(),N=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,ee=Pa(M.request,N),P=j.length>0?u(o,{children:j.map(e=>u(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return u(Fn,{serverUrl:r,createSession:m,sendAnswer:h,handleOffer:g,getIceServers:_,addIceCandidate:v,getIceCandidates:y,closeSession:x,getSessionState:S,applyDownlinkProbe:C,...ee===null?{}:{...ee,onExitPlayback:()=>M.clear()},streams:d,pipelineMetrics:f,phase:s.phase,detections:s,...l===void 0?{}:{stationaryObjects:l},defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:w.src,...w.src?{posterUrl:w.src}:{},snapshotLoading:w.loading,onRefreshSnapshot:w.refresh,intercomAvailable:t,intercomShown:k,onIntercomToggle:A,extraOverlay:P,chromeless:!0,className:`h-full`})}function Ia({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full`,children:u(ke,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function La({deviceId:e}){if(!Number.isFinite(e))return r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let t=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
|
|
2
|
-
`);return u(Na,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function Ra({deviceId:e}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:u(Nn,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function za({deviceId:e}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:u(z,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}var Ba=960;function Va(e){return new Set(e.filter(e=>{let t=e.nativeAddonId?.trim()??``;return t!==``&&t!==`composer`}).map(e=>e.capName))}function Ha(e){return e.kind===`known`?null:e}function Ua(e,t){return e.composable.kind===`known`?e.composable.value.has(t)?{kind:`present`,mode:`add`}:{kind:`absent`}:e.composable}function Wa(e){if(e.deviceType!==X.Camera)return{kind:`absent`};switch(e.cameraSensors){case`pending`:return{kind:`pending`};case`unknown`:return{kind:`unknown`,reason:`camera sensors could not be checked`};case`absent`:return{kind:`absent`};case`present`:return{kind:`present`,mode:`add`}}}function Ga(e,t){if(e===`motion`)return Wa(t);let n=Ha(t.nativeCaps);if(n!==null)return n;let r=t.nativeCaps.kind===`known`?t.nativeCaps.value:new Set;switch(e){case`doorbell`:return r.has(`doorbell`)?{kind:`absent`}:Ua(t,`doorbell`);case`battery`:return r.has(`battery`)?{kind:`present`,mode:`replace`}:Ua(t,`battery`);case`consumables`:return r.has(`consumables`)?{kind:`absent`}:Ua(t,`consumables`)}}function Ka({onAdvanced:e}){let{t}=Z();return e===void 0?null:u(`button`,{type:`button`,className:`rounded text-left text-[11px] text-primary hover:underline focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary`,onClick:e,children:t(`customize.advancedLink`)})}function qa(e){if(e.status===`pending`)return{kind:`pending`};if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??`the request failed`};let t=e.data;if(t===void 0)return{kind:`pending`};if(t.state===`not-loaded`)return{kind:`not-loaded`,reason:t.reason};if(t.view===null)return{kind:`none`};let n=Ir(t.view.block);return n===null?{kind:`unknown`,reason:`block ${t.view.block.id} is not a composition`}:{kind:`present`,view:t.view,composition:n}}function Ja(e){return e.kind===`present`?e.composition:null}function Ya(e,t){let{hidden:n,...r}=e??{},i=t?{...r,hidden:!0}:r;return Object.keys(i).length===0?null:i}function Xa(e){return typeof e.linkDeviceId==`number`}var Za=new Set(Object.values(Y));function Qa(e){return Za.has(e)}var $a={[X.Switch]:[Y.Siren,Y.Floodlight,Y.Spotlight,Y.PirSensor,Y.Chime,Y.Autotrack,Y.Nightvision,Y.PrivacyMask,Y.BinaryHelper],[X.Light]:[Y.Floodlight,Y.Spotlight,Y.Nightvision],[X.Siren]:[Y.Siren],[X.Button]:[Y.Doorbell],[X.Sensor]:[Y.MotionSensor,Y.ContactSensor,Y.LeakSensor,Y.SmokeSensor,Y.COSensor,Y.GasSensor,Y.TamperSensor,Y.VibrationSensor,Y.ConnectivitySensor,Y.SoundSensor,Y.BinarySensor,Y.TemperatureSensor,Y.HumiditySensor,Y.AmbientLightSensor,Y.PressureSensor,Y.WindSensor,Y.RainSensor,Y.UvSensor,Y.SolarRadiationSensor,Y.SoilMoistureSensor,Y.PowerSensor,Y.EnergySensor,Y.VoltageSensor,Y.CurrentSensor,Y.AirQualitySensor,Y.BatterySensor,Y.NumericSensor,Y.EnumSensor,Y.DateTimeSensor,Y.GenericSensor],[X.Control]:[Y.NumericControl,Y.SelectControl,Y.TextControl,Y.DateTimeControl],[X.Notifier]:[Y.MobilePushNotifier,Y.MessagingNotifier,Y.EmailNotifier,Y.GenericNotifier]};function eo(e){for(let t of Object.values(X))if(t===e)return!0;return!1}function to(e){return eo(e)?$a[e]??[]:[]}function no(e,t){let n=to(t);return e==null||e===``||n.includes(e)?n:[...n,e]}n();function ro({device:e}){let{t}=Z(),n=s(),[i,a]=c(null),o=()=>a(null),l={onSuccess:()=>{o(),n.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>a(e.message)},d=Ae(),p=be(),m=e.display?.hidden===!0;return r(`section`,{"aria-label":t(`customize.identity.title`),className:`${g} ${f}`,children:[r(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[u(oi,{deviceId:e.id,initialName:e.name,label:t(`customize.identity.name`),layout:`stacked`,onError:a,onSaved:o,onCancel:o}),u(ii,{deviceId:e.id,initialLocation:e.location,label:t(`customize.identity.room`),layout:`stacked`,onError:a,onSaved:o,onCancel:o}),u(Xr,{label:t(`customize.identity.hidden`),layout:`stacked`,value:u(wn,{"aria-label":t(`deviceDisplay.hideFromLists`),checked:m,disabled:p.isPending,onChange:t=>p.mutate({deviceId:e.id,display:Ya(e.display,t.target.checked)},l)})}),u(Xr,{label:t(`customize.identity.role`),layout:`stacked`,value:Xa(e)?u(`span`,{children:io(e.role,t(`customize.identity.noRole`))}):u(ze,{"aria-label":t(`customize.identity.role`),value:e.role??``,disabled:d.isPending,options:[{value:``,label:t(`customize.identity.noRole`)},...no(e.role,e.type).map(e=>({value:e,label:io(e,t(`customize.identity.noRole`))}))],onChange:t=>d.mutate({deviceId:e.id,role:t.target.value===``?null:t.target.value},l)})})]}),i!==null&&u(`p`,{role:`alert`,className:`mt-2 text-xs text-danger break-words`,children:i})]})}function io(e,t){return e==null||e===``?t:Qa(e)?on(e).label:e}function ao(e,t){if(e.kind!==`known`||typeof t!=`string`||t.length===0)return null;let n=xt(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 oo(e,t,n){return dt(e,t?.ids??new Set,n)}function so(e,t){return e?.containers.get(t)??null}function co(e,t){return e===null||t.length===0?e:{...e,ids:new Set([...e.ids].filter(e=>!t.includes(e)))}}function lo(e,t,n){return e.kind===`known`?oo(e.value,t,n).suggested.length:0}function uo(e,t){let n=[t,e.detail].filter(e=>e!==null&&e!==``);return n.length===0?null:n.join(` · `)}function fo({location:e,devices:t,action:n,onPick:i,onPickAll:a}){let{t:o}=Z();if(t.length===0)return null;let s=o(`customize.suggest.heading`,{location:e});return r(`section`,{"aria-label":s,className:`flex flex-col gap-1`,children:[r(`div`,{className:`flex min-h-7 items-center gap-2`,children:[u(`h3`,{className:`${v} min-w-0 flex-1`,children:s}),a!==void 0&&t.length>1&&u(H,{variant:`ghost`,size:`sm`,onClick:a,children:o(`customize.suggest.addAll`,{count:t.length})})]}),u(`ul`,{className:`flex flex-col divide-y divide-border rounded-md border border-border`,children:t.map(e=>{let t=uo(e,e.container===null||e.name.includes(e.container)?null:o(`customize.suggest.in`,{container:e.container}));return r(`li`,{className:`${_} flex items-center gap-3`,children:[r(`div`,{className:`min-w-0 flex-1`,children:[u(`div`,{className:`text-xs text-foreground break-words`,children:e.name}),t!==null&&u(`div`,{className:`text-[11px] text-foreground-subtle break-words`,children:t})]}),u(H,{variant:`outline`,size:`sm`,"aria-label":o(n===`add`?`customize.suggest.addNamed`:`customize.suggest.useNamed`,{name:e.name}),onClick:()=>i(e.id),children:o(n===`add`?`customize.suggest.add`:`customize.suggest.use`)})]},e.id)})})]})}n();function po(e){return e===`pending`?`pending`:e===`error`?`failed`:`answered`}function mo({excludeDeviceIds:e,room:t,onSelect:n}){let{t:a}=Z(),s=Bn({projection:`slim`}),c=s.status===`success`?s.data:null,l=i(()=>{if(c===null)return[];let t=new Set(e);return Ci(c).filter(e=>!t.has(e.id))},[c,e]),d=i(()=>new Map(l.map(e=>[e.id,e])),[l]),f=i(()=>oo(l,t,e=>e.id),[l,t]),p=i(()=>f.others.map(e=>({id:e.id,name:e.name,type:e.type,...e.location===null?{}:{location:e.location}})),[f.others]);if(s.status===`error`)return u(ie,{title:a(`customize.picker.devicesFailed`),message:s.error?.message??``});let m=e=>{let t=d.get(e);t!==void 0&&n(t)};return r(o,{children:[t!==null&&u(fo,{location:t.location,devices:f.suggested.map(e=>({id:e.id,name:e.name,container:so(t,e.id),detail:e.type})),action:`use`,onPick:m}),p.length===0&&f.suggested.length>0?null:u(lt,{devices:p,listState:po(s.status),value:[],onChange:e=>{let t=e.at(-1);t!==void 0&&m(t)},noun:`device`,emptyLabel:a(`customize.assign.none`),showAll:!0,testId:`customize-field-device-picker`})]})}function ho({open:e,title:t,targetKind:n,excludeDeviceIds:i,room:a=null,confirmLabel:s,extra:l,extraComplete:d=!0,onConfirm:f,onClose:p}){let{t:m}=Z(),[h,g]=c(null),[_,v]=c(null),y=()=>{g(null),v(null),p()};return u(te,{open:e,onOpenChange:e=>e?void 0:y(),children:r(he,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":t,children:[u(V,{children:u(se,{children:t})}),u(zt,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:e&&r(o,{children:[r(`section`,{"aria-label":m(`customize.assign.stepDevice`),className:`flex flex-col gap-1`,children:[u(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:m(`customize.assign.stepDevice`)}),h===null?u(mo,{excludeDeviceIds:i,room:a,onSelect:g}):r(`p`,{className:`flex items-center gap-2 text-xs text-foreground`,children:[h.name,u(H,{variant:`ghost`,size:`sm`,onClick:()=>{g(null),v(null)},children:m(`customize.assign.change`)})]})]}),h!==null&&r(`section`,{"aria-label":m(`customize.assign.stepField`),className:`flex flex-col gap-1`,children:[u(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:m(`customize.assign.stepField`)}),u(xi,{device:h,targetKind:n,selected:_===null?null:{cap:_.cap,path:_.path},onPick:v,onBack:()=>{g(null),v(null)}})]}),h!==null&&l!==void 0&&r(`section`,{"aria-label":m(`customize.assign.stepDetails`),className:`flex flex-col gap-1`,children:[u(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:m(`customize.assign.stepDetails`)}),l]})]})}),r(xe,{children:[u(H,{variant:`ghost`,onClick:y,children:m(`customize.assign.cancel`)}),u(H,{disabled:_===null||!d,onClick:()=>{_!==null&&(f(_),g(null),v(null))},children:s})]})]})})}function go(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function _o(e,t){let n=Fi(e,t);return n===void 0?{kind:`absent`}:{kind:`value`,value:n}}function vo(e,t,n){return go(t)?_o(t,n):e.status===`error`?{kind:`unknown`,reason:e.error?.message??`the value could not be read`}:e.status===`pending`||e.data===void 0?{kind:`pending`}:e.data===null?{kind:`absent`}:_o(e.data,n)}function yo(e,t,n){let r=e?`active`:`muted`;return t.cap===`contact`&&t.path===`entryOpen`?{text:e?n.open:n.closed,tone:r}:br[t.cap]===t.path?{text:e?n.active:n.inactive,tone:r}:{text:String(e),tone:`normal`}}function bo(e,t,n){switch(e.kind){case`pending`:return{text:`…`,tone:`muted`};case`unknown`:return{text:`?`,title:e.reason,tone:`warning`};case`absent`:return{text:`—`,tone:`muted`};case`value`:{let r=e.value;return r===null?{text:`—`,tone:`muted`}:typeof r==`boolean`?yo(r,t,n):typeof r==`number`?{text:t.path===`percentage`?`${Math.round(r)} %`:String(r),tone:`normal`}:typeof r==`string`?{text:r,tone:`normal`}:{text:JSON.stringify(r),tone:`normal`}}}}var xo=0;function So(e){let t=T(),n=un({deviceId:e?.deviceId??xo,capName:e?.cap??``},{enabled:e!==null}),r=gn(t.trpcClient,e?.deviceId??null,e?.cap??``);return e===null?{kind:`absent`}:vo({status:n.status,data:n.data,error:n.error===null||n.error===void 0?null:{message:n.error.message}},r,e.path)}var Co={muted:`text-foreground-subtle`,active:`text-success`,normal:`text-foreground`,warning:`text-warning`};function wo({target:e}){let{t}=Z(),n=So(e);return e===null?null:u(To,{display:bo(n,e,{active:t(`customize.assign.value.active`),inactive:t(`customize.assign.value.inactive`),open:t(`customize.assign.value.open`),closed:t(`customize.assign.value.closed`)})})}function To({display:e}){return u(`span`,{className:`text-xs ${Co[e.tone]}`,title:e.title,children:e.text})}function Eo({name:e,detail:t,meta:n,value:i,shown:a,problem:o,onRemove:s,removeLabel:c,busy:l=!1}){return r(`li`,{className:`${_} grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-1 sm:grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,1fr)_1.75rem]`,children:[r(`div`,{className:`min-w-0`,children:[u(`div`,{className:`text-xs text-foreground break-words`,children:e}),t!==null&&u(`div`,{className:`text-[11px] text-foreground-subtle break-words`,children:t}),o!==void 0&&u(`div`,{role:`alert`,className:`text-[11px] text-warning break-words`,children:o})]}),u(`div`,{className:`row-start-2 col-start-1 text-[11px] text-foreground-subtle empty:hidden sm:row-start-auto sm:col-start-auto sm:empty:block`,children:n}),u(`div`,{className:`row-start-3 col-start-1 empty:hidden sm:row-start-auto sm:col-start-auto sm:empty:block`,children:a===void 0?u(wo,{target:i}):a!==null&&u(To,{display:a})}),u(`div`,{className:`row-start-1 col-start-2 flex justify-end sm:row-start-auto sm:col-start-auto`,children:s!==void 0&&u($t,{icon:Ke,variant:`ghost`,size:`sm`,"aria-label":c,disabled:l,onClick:s})})]})}function Do({id:e,...t}){return u(Pe,{headingId:`customize-${e}`,...t})}function Oo({id:e,icon:t,title:n,headerControl:i,addLabel:a,onAdd:s,addDisabled:c=!1,notices:l,suggestion:d,children:f}){let{t:p}=Z(),m=s!==void 0&&a!==void 0;return r(Do,{id:e,icon:t,title:n,actions:r(o,{children:[i,m&&!c&&d!==void 0&&d.count>0&&r(H,{variant:`ghost`,size:`sm`,onClick:d.onOpen,children:[u(Fe,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),p(`customize.suggest.hint`,{count:d.count,location:d.location})]}),m&&u(H,{variant:`outline`,size:`sm`,disabled:c,onClick:s,children:a})]}),children:[l!==void 0&&u(`div`,{className:`flex flex-col gap-1 px-3 pt-2 empty:hidden sm:px-4`,children:l}),u(`ul`,{className:`flex flex-col divide-y divide-border`,children:f})]})}function ko({availability:e}){let{t}=Z();return e.kind===`pending`?u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.assign.checking`)}):e.kind===`unknown`?u(`p`,{role:`alert`,className:`text-xs text-warning`,children:t(`customize.assign.unknown`,{reason:e.reason})}):null}function Ao(e,t){if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??`the request failed`};let n=e.data;return e.status===`pending`||n===void 0?{kind:`pending`}:{kind:`known`,value:t(n)}}var jo=[{id:`motion`,labelKey:`customize.assign.filters.motion`,caps:[`motion`]},{id:`contact`,labelKey:`customize.assign.filters.contact`,caps:[`contact`]},{id:`all`,labelKey:`customize.assign.filters.all`,caps:vr}];function Mo(e,t){return t!==null&&e.includes(t)?t:vr.find(t=>e.includes(t))??null}function No(e,t){let n=[e,t].filter(e=>e!==null&&e!==``);return n.length===0?null:n.join(` · `)}function Po(e,t){if(e.id===t.hostId||e.type===X.Container||t.excludeCameras&&e.isCamera)return!1;let n=J({addonId:e.addonId,stableId:e.stableId});return!t.assigned.has(n)}function Fo(e){return e.devices.flatMap(t=>{if(!Po(t,e))return[];let n=e.capIndex.get(t.id)??[],r=Mo(n,e.preferredCap);if(r===null)return[];let i=br[r];return[{deviceId:t.id,ref:{addonId:t.addonId,stableId:t.stableId},name:t.name,detail:No(t.integration,t.location),meta:r,caps:n,value:i===void 0?null:{deviceId:t.id,cap:r,path:i}}]}).toSorted((e,t)=>e.name.localeCompare(t.name))}function Io(e,t,n){let r=zn(t);return e.filter(e=>{if(n!==null&&!e.caps.some(e=>n.caps.includes(e)))return!1;if(r.length===0)return!0;let t=Ze({id:e.deviceId,name:e.name,...e.detail===null?{}:{detail:e.detail},...e.meta===null?{}:{type:e.meta}});return r.every(e=>t.includes(e))})}function Lo(e){let t=e.find(e=>e.query.status===`error`);if(t!==void 0)return{kind:`unknown`,reason:t.query.error?.message??`the request failed`};if(e.some(e=>e.query.status!==`success`||e.query.data===void 0))return{kind:`pending`};let n=new Map;for(let t of e)for(let e of t.query.data??[])n.set(e,[...n.get(e)??[],t.cap]);return{kind:`known`,value:n}}function Ro(e,t){let n=jt.useQueries(n=>e.map(e=>n.deviceManager.listDeviceIdsByCaps({capNames:[e]},{enabled:t})));return Lo(e.map((e,t)=>{let r=n[t];return{cap:e,query:r===void 0?{status:`pending`}:{status:r.status,data:r.data,error:r.error===null?null:{message:r.error.message}}}}))}n();function zo(e,t){let n=Qt(e,t);return n.kind===`resolved`?n.integration.name:null}function Bo(e){let t=Bn({projection:`slim`},{enabled:e}),{data:n}=cn(void 0,{enabled:e}),r=t.error===null||t.error===void 0?null:t.error.message;return i(()=>Ao({status:t.status,data:t.data,error:r===null?null:{message:r}},e=>e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,type:e.type,location:e.location,isCamera:e.isCamera,integration:zo(e,n),parentDeviceId:e.parentDeviceId,primaryChildEntityId:e.primaryChildEntityId??null,role:e.role??null}))),[t.status,t.data,r,n])}function Vo(e){let t=Bo(e.enabled),n=Ro(vr,e.enabled);return t.kind===`unknown`?t:n.kind===`unknown`?n:t.kind===`pending`||n.kind===`pending`?{kind:`pending`}:{kind:`known`,value:Fo({devices:t.value,capIndex:n.value,hostId:e.hostId,excludeCameras:e.excludeCameras,assigned:e.assigned,preferredCap:e.preferredCap})}}n();function Ho(e,t){let n=typeof e==`string`&&e.length>0,r=Bo(t&&n);return i(()=>t?ao(r,e):null,[t,r,e])}function Uo(){let{t:e}=Z(),t=Zt();return(n,r)=>t({title:e(`customize.assign.removeConfirm.title`),message:r?`${e(`customize.assign.removeConfirm.message`,{what:n})} ${e(`customize.assign.removeConfirm.last`)}`:e(`customize.assign.removeConfirm.message`,{what:n}),confirmLabel:e(`customize.assign.removeConfirm.confirm`),variant:`danger`})}n();function Wo(e){return e===null?null:Di(e,`replace`)?`replace`:Di(e,`add`)?`add`:null}function Go({device:e,handle:t,availability:n,onAdvanced:i}){let{t:a}=Z(),s=Uo(),[l,d]=c(!1),[f,p]=c(null),m=Ja(t.state),h=Bi(m,`battery`),g=Wo(h),_=g===null?null:bi(h?.fields.percentage),v=Bo(_!==null),y=co(Ho(e.location,n.kind===`present`&&h===null),[e.id]);if(n.kind===`absent`)return null;let b=n.kind===`present`?n.mode:null,x=t.state.kind===`none`||t.state.kind===`present`,S=_===null||v.kind!==`known`?null:v.value.find(e=>J({addonId:e.addonId,stableId:e.stableId})===J(_.source))??null,C=_===null?``:S?.name??J(_.source),w=async e=>{let n=await t.save(e);p(n.kind===`refused`?n.reason:null)},T=async()=>{if(m===null)return;let e=gi(m,`battery`);await s(a(`customize.battery.removeWhat`,{name:C}),e===null)&&await w(e)},E=b!==null&&x&&h===null&&!t.saving;return r(o,{children:[r(Oo,{id:`battery`,icon:B,title:a(`customize.battery.title`),addLabel:a(b===`replace`?`customize.battery.replace`:`customize.battery.add`),onAdd:E?()=>d(!0):void 0,...y===null?{}:{suggestion:{count:y.ids.size,location:y.location,onOpen:()=>d(!0)}},notices:r(o,{children:[u(ko,{availability:n}),_!==null&&v.kind===`unknown`&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.assign.devicesUnreadable`,{reason:v.reason})}),f!==null&&u(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:f})]}),children:[b===`replace`&&x&&u(Eo,{name:a(`customize.battery.native`),detail:null,meta:a(h===null?`customize.assign.native`:`customize.battery.nativeReplaced`),value:h===null?{deviceId:e.id,cap:`battery`,path:`percentage`}:null,removeLabel:``}),h===null&&b===`add`&&x&&u(`li`,{className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:a(`customize.assign.none`)}),_!==null&&u(Eo,{name:C,detail:`${_.cap}.${_.fieldPath}`,meta:a(g===`replace`?`customize.assign.replaces`:`customize.assign.adds`),value:S===null?null:{deviceId:S.id,cap:_.cap,path:_.fieldPath},problem:S===null&&v.kind===`known`?a(`customize.assign.missingKept`):void 0,onRemove:x?()=>void T():void 0,removeLabel:a(`customize.assign.removeNamed`,{name:C}),busy:t.saving}),h!==null&&_===null&&u(Eo,{name:a(`customize.battery.otherFormula`),detail:null,meta:u(Ka,{onAdvanced:i}),value:{deviceId:e.id,cap:`battery`,path:`percentage`},removeLabel:``})]}),u(ho,{open:l,title:a(b===`replace`?`customize.battery.replace`:`customize.battery.add`),targetKind:`number`,excludeDeviceIds:[e.id],room:y,confirmLabel:a(`customize.assign.add`),onConfirm:e=>{d(!1);let n=b===null?null:Li({percentage:{source:e.ref,cap:e.cap,fieldPath:e.path,kind:e.kind},mode:b});n===null?p(a(`customize.assign.pickUnusable`)):w(yi(m,t.target,n))},onClose:()=>d(!1)})]})}n();function Ko(e,t){let n=e.source;if(n===null||t.kind!==`known`)return null;let r=J(n.source);return t.value.find(e=>J({addonId:e.addonId,stableId:e.stableId})===r)??null}function qo(e){let t=typeof e==`number`?e:typeof e==`string`?Number(e):NaN;return Number.isFinite(t)?t:null}function Jo({device:e,handle:t,availability:n,onAdvanced:i}){let{t:a}=Z(),s=Uo(),[l,d]=c(!1),[f,p]=c(``),[m,h]=c(`percent`),[g,_]=c(null),v=Ja(t.state),y=Bi(v,`consumables`),b=Ti(y),x=Bo(b.some(e=>e.source!==null)),S=b.flatMap(e=>{let t=Ko(e,x);return t===null?[]:[t.id]}),C=co(Ho(e.location,n.kind===`present`),[e.id,...S]);if(n.kind===`absent`)return null;let w=t.state.kind===`none`||t.state.kind===`present`,T=n.kind===`present`&&w&&!t.saving,E=Ei(f),D=b.find(e=>e.key===E)??null,O=D!==null,k=f.trim()!==``&&E===``,A=async e=>{let n=await t.save(e);_(n.kind===`refused`?n.reason:null)},j=()=>{d(!1),p(``),h(`percent`)},M=async e=>{if(y===null||v===null)return;let n=Ri(y,e.key),r=n===null?gi(v,`consumables`):yi(v,t.target,n);await s(a(`customize.consumables.removeWhat`,{name:e.label}),r===null)&&await A(r)},N=r(`div`,{className:`flex flex-wrap items-end gap-2`,children:[r(`label`,{className:`flex w-full flex-col gap-1 text-[11px] text-foreground-subtle sm:w-56`,children:[a(`customize.consumables.name`),u(Sn,{"aria-label":a(`customize.consumables.name`),value:f,onChange:e=>p(e.target.value)})]}),r(`label`,{className:`flex w-full flex-col gap-1 text-[11px] text-foreground-subtle sm:w-40`,children:[a(`customize.consumables.unit`),u(ze,{"aria-label":a(`customize.consumables.unit`),value:m,options:ki.map(e=>({value:e,label:a(`customize.consumables.units.${e}`)})),onChange:e=>{let t=ki.find(t=>t===e.target.value);t!==void 0&&h(t)}})]}),O&&u(`p`,{role:`alert`,className:`basis-full text-xs text-warning`,children:a(`customize.consumables.takenBy`,{name:D.label})}),k&&u(`p`,{role:`alert`,className:`basis-full text-xs text-warning`,children:a(`customize.consumables.keyless`)})]});return r(o,{children:[r(Oo,{id:`consumables`,icon:kn,title:a(`customize.consumables.title`),addLabel:a(`customize.consumables.add`),onAdd:T?()=>d(!0):void 0,...C===null?{}:{suggestion:{count:C.ids.size,location:C.location,onOpen:()=>d(!0)}},notices:r(o,{children:[u(ko,{availability:n}),x.kind===`unknown`&&b.some(e=>e.source!==null)&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.assign.devicesUnreadable`,{reason:x.reason})}),g!==null&&u(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:g})]}),children:[b.map(e=>{let n=e.source;if(e.unit===null||n===null)return u(Eo,{name:e.label,detail:a(`customize.consumables.otherFormula`),meta:u(Ka,{onAdvanced:i}),value:null,removeLabel:``},e.key);let r=Ko(e,x),o=r?.name??J(n.source);return u(Eo,{name:e.label,detail:`${a(`customize.consumables.units.${e.unit}`)} · ${o}`,meta:`${n.cap}.${n.fieldPath}`,value:r===null?null:{deviceId:r.id,cap:n.cap,path:n.fieldPath},problem:r===null&&x.kind===`known`?a(`customize.assign.missingKept`):void 0,onRemove:w?()=>void M(e):void 0,removeLabel:a(`customize.assign.removeNamed`,{name:e.label}),busy:t.saving},e.key)}),b.length===0&&n.kind===`present`&&w&&u(`li`,{className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:a(`customize.assign.none`)})]}),u(ho,{open:l,title:a(`customize.consumables.pickTitle`),targetKind:`number`,excludeDeviceIds:[e.id],room:C,confirmLabel:a(`customize.assign.add`),extra:N,extraComplete:E!==``&&!O,onConfirm:e=>{let n=qo(e.value);if(n!==null&&(n<0||m===`percent`&&n>100)){j(),_(a(`customize.consumables.outOfRange`,{value:n}));return}let r=wi(y,{key:E,label:f,remaining:{source:e.ref,cap:e.cap,fieldPath:e.path,kind:e.kind},unit:m});j(),r===null?_(a(`customize.assign.pickUnusable`)):A(yi(v,t.target,r))},onClose:j})]})}n();function Yo(e){return e.kind===`pending`?`pending`:e.kind===`unknown`?`failed`:`answered`}function Xo(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 Zo({open:e,title:t,selection:n,candidates:a,filters:o,room:s=null,confirmLabel:l,onConfirm:f,onClose:p}){let{t:m}=Z(),[h,g]=c(null),[_,v]=c([]),y=o?.find(e=>e.id===h)??o?.[0]??null,b=a.kind===`known`?a.value:[],x=a.kind===`known`?Io(a.value,``,y):[],S=oo(b,s,e=>e.deviceId).suggested,C=oo(x,s,e=>e.deviceId).others,w=i(()=>Xo(C),[C]),T=Yo(a),E=b.filter(e=>_.includes(e.deviceId));d(()=>{e||(v([]),g(null))},[e]);let D=()=>{v([]),g(null),p()},O=e=>{e.length!==0&&(f(e),v([]),g(null))},k=()=>O(E);return u(te,{open:e,onOpenChange:e=>e?void 0:D(),children:r(he,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":t,children:[u(V,{children:u(se,{children:t})}),r(zt,{className:`flex flex-col gap-2 p-2 sm:p-4`,children:[o!==void 0&&o.length>0&&u(`div`,{className:`flex flex-wrap gap-1`,role:`tablist`,"aria-label":m(`customize.assign.filtersLabel`),children:o.map(e=>u(`button`,{type:`button`,role:`tab`,"aria-selected":(y?.id??null)===e.id,className:`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${(y?.id??null)===e.id?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover`}`,onClick:()=>g(e.id),children:m(e.labelKey)},e.id))}),s!==null&&u(fo,{location:s.location,devices:S.map(e=>({id:e.deviceId,name:e.name,container:so(s,e.deviceId),detail:e.detail})),action:`add`,onPick:e=>O(S.filter(t=>t.deviceId===e)),...n===`multi`?{onPickAll:()=>O(S)}:{}}),a.kind===`unknown`?u(`p`,{role:`alert`,className:`text-xs text-warning`,children:m(`customize.assign.unknown`,{reason:a.reason})}):w.length===0&&S.length>0?null:u(lt,{devices:w,listState:T,value:_,onChange:e=>v(n===`single`?e.length>0?[e[e.length-1]]:[]:e),noun:`device`,emptyLabel:m(`customize.assign.none`),showAll:!0,testId:`customize-device-picker`})]}),r(xe,{children:[u(H,{variant:`ghost`,onClick:D,children:m(`customize.picker.cancel`)}),u(H,{disabled:E.length===0,onClick:k,children:l(E.length)})]})]})})}function Qo(e){if(e===null)return[];let t=Ai(e);return Ni(e).map(e=>{let n=J(e);return{key:n,ref:e,caps:t.filter(e=>J(e.source)===n).map(e=>e.cap)}})}function $o(e,t){let n=Ai(e);if(n.length===0)return!1;let{enabled:r,...i}=e,{enabled:a,...o}=Rr({camera:t,sources:n,enabled:!0});return zi(i,o)}function es(e){return e?.enabled!==!1}function ts(e,t,n){let r=[...e===null?[]:Ai(e),...n.flatMap(e=>Wr(e.ref,e.caps))];return r.length===0?null:Rr({camera:t,sources:r,enabled:es(e)})}function ns(e,t,n){let r=Ai(e).filter(e=>J(e.source)!==n);return r.length===0?null:Rr({camera:t,sources:r,enabled:es(e)})}function rs(e,t){return{...e,enabled:t}}n();function is({device:e,handle:t,availability:n,onAdvanced:i}){let{t:a}=Z(),s=Uo(),[l,d]=c(!1),[f,p]=c(null),m=Ja(t.state),h=Bi(m,`doorbell`),g=h===null||$o(h,t.target),_=g?Qo(h):[],v=Bo(_.length>0),y=n.kind===`present`&&g,b=Ho(e.location,y),x=Vo({hostId:e.id,excludeCameras:!1,assigned:new Set(_.map(e=>e.key)),preferredCap:null,enabled:l||b!==null});if(n.kind===`absent`)return null;let S=t.state.kind===`none`||t.state.kind===`present`,C=S&&!t.saving,w=n.kind===`present`&&C&&g,T=async e=>{let n=e===null?m===null?null:gi(m,`doorbell`):yi(m,t.target,e),r=await t.save(n);p(r.kind===`refused`?r.reason:null)},E=async(e,n)=>{if(h===null||m===null)return;let r=ns(h,t.target,e.key),i=r===null&&gi(m,`doorbell`)===null;await s(a(`customize.doorbell.removeWhat`,{name:n}),i)&&await T(r)},D=e=>v.kind===`known`?v.value.find(t=>J({addonId:t.addonId,stableId:t.stableId})===e.key)??null:null;return r(o,{children:[r(Oo,{id:`doorbell`,icon:Mn,title:a(`customize.doorbell.title`),headerControl:h===null?void 0:r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground`,children:[u(wn,{"aria-label":a(`customize.doorbell.active`),checked:h.enabled!==!1,disabled:!C,onChange:e=>void T(rs(h,e.target.checked))}),a(`customize.doorbell.active`)]}),addLabel:a(`customize.doorbell.add`),onAdd:w?()=>d(!0):void 0,...b===null?{}:{suggestion:{count:lo(x,b,e=>e.deviceId),location:b.location,onOpen:()=>d(!0)}},notices:r(o,{children:[u(ko,{availability:n}),v.kind===`unknown`&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.assign.devicesUnreadable`,{reason:v.reason})}),f!==null&&u(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:f})]}),children:[_.map(e=>{let n=D(e),r=n?.name??e.key,i=Mo(e.caps,null),o=i===null?void 0:br[i];return u(Eo,{name:r,detail:n===null?null:No(n.integration,n.location),meta:e.caps.join(`, `),value:n!==null&&i!==null&&o!==void 0?{deviceId:n.id,cap:i,path:o}:null,problem:n===null&&v.kind===`known`?a(`customize.assign.missingKept`):void 0,onRemove:S?()=>void E(e,r):void 0,removeLabel:a(`customize.assign.removeNamed`,{name:r}),busy:t.saving},e.key)}),!g&&u(Eo,{name:a(`customize.doorbell.otherFormula`),detail:null,meta:u(Ka,{onAdvanced:i}),value:null,removeLabel:``}),h===null&&n.kind===`present`&&S&&u(`li`,{className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:a(`customize.assign.none`)})]}),u(Zo,{open:l,title:a(`customize.doorbell.pickTitle`),selection:`multi`,candidates:x,room:b,confirmLabel:e=>a(`customize.assign.addCount`,{count:e}),onConfirm:e=>{d(!1),T(ts(h,t.target,e.map(e=>({ref:e.ref,caps:e.caps}))))},onClose:()=>d(!1)})]})}function as(e){return e.slot===`linked-devices`}function os(e){if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??`the request failed`};if(e.status===`pending`||e.data===void 0)return{kind:`pending`};for(let t of e.data)if(t.state===`ok`&&t.slot===`linked-devices`&&as(t.value))return{kind:`present`,slot:t,value:t.value};let t=e.data.find(e=>e.state===`unreachable`);return t!==void 0&&t.state===`unreachable`?{kind:`unknown`,reason:t.reason}:{kind:`absent`}}function ss(e,t){let n=t.trackedDeviceIds??[],r=e=>t=>({deviceId:t.deviceId,name:t.name,health:t.health,implied:e,tracked:n.includes(t.deviceId)});return[...e.sources.map(r(!1)),...(e.impliedSources??[]).map(r(!0))]}function cs(e,t){let n=new Set([...e.sources,...e.impliedSources??[]].map(e=>e.deviceId));return(t.trackedDeviceIds??[]).filter(e=>!n.has(e))}function ls(e,t){return{...e,deviceIds:[...e.deviceIds,...t.filter(t=>!e.deviceIds.includes(t))]}}function us(e,t){return{...e,deviceIds:e.deviceIds.filter(e=>e!==t),...e.trackedDeviceIds===void 0?{}:{trackedDeviceIds:e.trackedDeviceIds.filter(e=>e!==t)}}}function ds(e,t,n){let r=e.trackedDeviceIds??[],i=n?[...r.filter(e=>e!==t),t]:r.filter(e=>e!==t);return{...e,trackedDeviceIds:i}}function fs(e,t,n){return e.flatMap(e=>{let r=t.get(e.deviceId);return n.has(e.deviceId)||r===void 0?[]:[{deviceId:e.deviceId,ref:{addonId:r.addonId,stableId:r.stableId},name:e.parentName===null?e.name:`${e.parentName} · ${e.name}`,detail:No(r.integration,e.location),meta:e.type,caps:[],value:null}]})}n();function ps(e){return e==null?null:e.message}function ms({device:e}){let{t}=Z(),n=s(),i=Uo(),a=Cr.includes(e.type),[l,d]=c(!1),[f,p]=c(!1),[m,h]=c(null),g=W({deviceId:e.id},{enabled:a}),_=os({status:g.status,data:g.data,error:ps(g.error)===null?null:{message:ps(g.error)??``}}),v=_.kind===`present`?_.slot.slotRef:``,y=_.kind===`present`?[...ss(_.slot,_.value).map(e=>e.deviceId),...cs(_.slot,_.value)]:[],b=Ve(),x=Bo(a&&_.kind===`present`&&(l||y.length>0)),S=Ho(e.location,a&&_.kind===`present`),C=dn({deviceId:e.id,slotRef:v},{enabled:(l||S!==null)&&_.kind===`present`});if(!a||_.kind===`absent`)return null;if(_.kind!==`present`)return u(Oo,{id:`linked`,icon:Lt,title:t(`customize.linked.title`),notices:_.kind===`pending`?u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.assign.checking`)}):u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:t(`customize.assign.unknown`,{reason:_.reason})}),children:null});let w=_.value,T=new Map(x.kind===`known`?x.value.map(e=>[e.id,e]):[]),E=w.trackedDeviceIds!==void 0,D=(e,t)=>{let n=T.get(e.deviceId);return{...e,name:e.name??n?.name??null,type:n?.type??null,detail:n===void 0?null:No(n.integration,n.location),orphan:t}},O=[...ss(_.slot,w).map(e=>D(e,!1)),...cs(_.slot,w).map(e=>D({deviceId:e,name:null,health:`ok`,implied:!1,tracked:!0},!0))],k=new Set(y),A=x.kind===`unknown`?x:C.status===`error`?{kind:`unknown`,reason:ps(C.error)??`the request failed`}:x.kind===`pending`||C.status===`pending`||C.data===void 0?{kind:`pending`}:{kind:`known`,value:fs(C.data.candidates,T,k)},j=async r=>{if(f){h(t(`customize.saveInFlight`));return}p(!0),h(null);try{await b.mutateAsync({deviceId:e.id,slotRef:_.slot.slotRef,value:r}),await g.refetch(),await n.invalidateQueries({queryKey:[[`deviceManager`]]})}catch(e){h(e instanceof Error?e.message:String(e))}finally{p(!1)}},M=async e=>{await i(t(`customize.linked.removeWhat`,{name:e.name??`#${e.deviceId}`}),!1)&&await j(us(w,e.deviceId))},N=[{key:`device`,header:t(`customize.linked.device`),cell:e=>r(`div`,{className:`flex flex-col min-w-0`,children:[u(`span`,{className:`truncate text-xs text-foreground`,children:e.name??`#${e.deviceId}`}),e.detail!==null&&u(`span`,{className:`truncate text-[11px] text-foreground-subtle`,children:e.detail}),e.orphan&&u(`span`,{className:`text-[11px] text-foreground-subtle`,children:t(`customize.linked.notLinked`)}),e.health!==`ok`&&u(`span`,{role:`alert`,className:`text-[11px] text-warning`,children:t(`customize.linked.health.${e.health}`)})]})},{key:`type`,header:t(`customize.linked.type`),headerClassName:`hidden sm:table-cell`,cellClassName:`hidden sm:table-cell text-xs text-foreground-subtle`,cell:e=>e.type===null?`—`:ct(e.type).label},{key:`controls`,header:t(`customize.linked.controls`),headerClassName:`hidden md:table-cell`,cellClassName:`hidden md:table-cell text-xs text-foreground-subtle`,cell:e=>e.orphan?`—`:t(`customize.linked.yes`)},...E?[{key:`tracked`,header:t(`customize.linked.tracked`),cellClassName:`text-right`,headerClassName:`text-right`,cell:e=>u(Gt,{checked:e.tracked,disabled:f,"aria-label":t(`customize.linked.trackFor`,{name:e.name??e.deviceId}),onCheckedChange:t=>void j(ds(w,e.deviceId,t))})}]:[],{key:`remove`,header:``,cellClassName:`text-right w-10`,cell:e=>e.implied||e.orphan?null:u($t,{icon:Ke,variant:`ghost`,size:`sm`,"aria-label":t(`customize.assign.removeNamed`,{name:e.name??e.deviceId}),disabled:f,onClick:t=>{t.stopPropagation(),M(e)}})}];return r(o,{children:[u(Oo,{id:`linked`,icon:Lt,title:t(`customize.linked.title`),addLabel:t(`customize.linked.add`),onAdd:f?void 0:()=>d(!0),...S===null?{}:{suggestion:{count:lo(A,S,e=>e.deviceId),location:S.location,onOpen:()=>d(!0)}},notices:r(o,{children:[x.kind===`unknown`&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:t(`customize.assign.devicesUnreadable`,{reason:x.reason})}),m!==null&&u(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:m})]}),children:r(`li`,{className:`list-none px-3 py-2 sm:px-4`,children:[O.length===0?u(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`customize.assign.none`)}):u(_t,{mode:`generic`,items:O,getKey:e=>String(e.deviceId),getSearchText:e=>[e.name??``,e.detail??``,e.type??``,String(e.deviceId)].join(` `),getFilterType:e=>e.type===null?null:ct(e.type).label,columns:N,searchPlaceholder:t(`customize.assign.search`),emptyLabel:t(`customize.assign.none`)}),O.some(e=>!e.orphan)&&u(`p`,{className:`mt-2 text-[10px] text-foreground-subtle`,children:t(`customize.linked.controlsAlways`)}),E&&u(`p`,{className:`mt-0.5 text-[10px] text-foreground-subtle`,children:t(`customize.linked.trackedHint`)})]})}),u(Zo,{open:l,title:t(`customize.linked.pickTitle`),selection:`multi`,candidates:A,room:S,confirmLabel:e=>t(`customize.assign.addCount`,{count:e}),onConfirm:e=>{d(!1),j(ls(w,e.map(e=>e.deviceId)))},onClose:()=>d(!1)})]})}function hs(e){return e===null||e.state===`unreadable`?null:e.state===`configured`?e.sensors:[]}function gs(e){return{addonId:e.addonId,stableId:e.stableId,mode:e.mode}}function _s(e){return e.length===0?null:{sensors:[...e]}}function vs(e,t){let n=new Set(e.map(yr));return _s([...e.map(gs),...t.filter(e=>!n.has(yr(e))).map(e=>({...e,mode:_r}))])}function ys(e,t,n){return _s(e.map(e=>yr(e)===t?{...gs(e),mode:n}:gs(e)))}function bs(e,t){return _s(e.filter(e=>yr(e)!==t).map(gs))}function xs(e){return e?.state===`configured`&&e.cameraMotion!==void 0}function Ss(e){return e===null||e.state===`unreadable`?null:e.state===`configured`?e.cameraMotion??`always`:`always`}function Cs(e){return e===null||e.state===`unreadable`?!1:e.state===`not-configured`||xs(e)}function ws(e){return e?.state===`configured`&&(e.notForwarded!==void 0||e.notEnforced!==void 0)}function Ts(e,t,n){if(e!==`present`||t===null||n)return{kind:`none`};let r=t.cameraLevel;return r===void 0?{kind:`unknown`}:{kind:`level`,detected:r.detected,atMs:r.atMs}}n();var Es=5e3;function Ds(e){return e.state===`missing`||e.state===`unreadable`?e.stableId:e.name}function Os({device:e,availability:n,sensors:i}){let{t:a}=Z(),s=Uo(),l=mn(),[f,p]=c(!1),[m,h]=c(null),g=t(!1),[_,v]=c(!1),[y,b]=c(!1),x=i.status,S=t(i.refetch);S.current=i.refetch,d(()=>{let e=setInterval(()=>{g.current||S.current()},Es);return()=>clearInterval(e)},[]);let C=hs(x);d(()=>{x!==null&&b(!1)},[x]);let w=i.presence===`present`&&Cs(x)&&!y?C:null,T=Bo(C!==null&&C.length>0),E=Ho(e.location,w!==null&&n.kind===`present`),D=Vo({hostId:e.id,excludeCameras:!0,assigned:new Set((C??[]).map(yr)),preferredCap:`motion`,enabled:f||E!==null});if(n.kind===`absent`)return null;let O=xs(x),k=ws(x)?`passes`:Ss(x),A=Ts(i.presence,x,y),j=A.kind===`none`?null:A.kind===`unknown`?{text:`?`,tone:`warning`,title:a(`customize.motion.cameraLevelUnknown`)}:{text:a(A.detected?`customize.assign.value.active`:`customize.assign.value.inactive`),tone:A.detected?`active`:`muted`,title:a(`customize.motion.cameraLevelOwn`,{at:new Date(A.atMs).toLocaleTimeString()})},M=_||l.isPending,N=async t=>{if(g.current){h(a(`customize.saveInFlight`));return}g.current=!0,v(!0);try{await l.mutateAsync({deviceId:e.id,config:t}),h(null),await i.refetch()===`failed`&&b(!0)}catch(e){h(e instanceof Error?e.message:String(e))}finally{g.current=!1,v(!1)}},ee=async e=>{w!==null&&await s(a(`customize.motion.removeWhat`,{name:Ds(e)}),!1)&&await N(bs(w,yr(e)))},P=e=>{if(T.kind!==`known`||!(`deviceId`in e))return null;let t=T.value.find(t=>t.id===e.deviceId);return t===void 0?null:No(t.integration,t.location)};return r(o,{children:[r(Oo,{id:`motion`,icon:we,title:a(`customize.motion.title`),addLabel:a(`customize.motion.add`),onAdd:w!==null&&n.kind===`present`?()=>p(!0):void 0,addDisabled:M,...E===null?{}:{suggestion:{count:lo(D,E,e=>e.deviceId),location:E.location,onOpen:()=>p(!0)}},notices:r(o,{children:[u(ko,{availability:n}),i.presence===`pending`&&n.kind!==`pending`&&u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:a(`customize.motion.reading`)}),x?.state===`unreadable`&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.motion.unreadable`,{reason:x.reason})}),x?.state===`configured`&&!Cs(x)&&u(`p`,{role:`alert`,className:`text-xs text-warning`,children:a(`customize.motion.olderOrchestrator`)}),y&&u(`p`,{role:`alert`,className:`text-xs text-warning`,children:a(`customize.motion.refetchFailed`)}),x?.state===`configured`&&x.notForwarded!==void 0&&u(`p`,{role:`alert`,className:`text-xs text-warning`,children:a(`customize.motion.notForwarded.${x.notForwarded}`)}),x?.state===`configured`&&x.notEnforced!==void 0&&u(`p`,{role:`alert`,className:`text-xs text-warning`,children:a(`customize.motion.notEnforced`)}),T.kind===`unknown`&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.assign.devicesUnreadable`,{reason:T.reason})}),m!==null&&u(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:m})]}),children:[u(Eo,{name:a(`customize.motion.camera`),detail:null,meta:k===null?a(`customize.assign.native`):`${a(`customize.motion.cameraState.${k}`)} · ${a(`customize.assign.native`)}`,value:null,shown:j,removeLabel:``}),(C??[]).map(e=>{let t=yr(e),n=Ds(e),r=e.state===`ready`?Mo(e.caps,`motion`):null,i=r===null?void 0:br[r];return u(Eo,{name:n,detail:P(e),meta:O&&w!==null?u(ze,{"aria-label":a(`customize.motion.modeFor`,{name:n}),value:e.mode,disabled:M,options:gr.options.map(e=>({value:e,label:a(`customize.motion.mode.${e}`)})),onChange:e=>{let n=gr.safeParse(e.target.value);n.success&&w!==null&&N(ys(w,t,n.data))}}):a(`customize.motion.mode.${e.mode}`),value:r!==null&&i!==void 0&&`deviceId`in e?{deviceId:e.deviceId,cap:r,path:i}:null,problem:e.state===`ready`?void 0:e.reason===e.state?a(`customize.motion.state.${e.state}`):`${a(`customize.motion.state.${e.state}`)}: ${e.reason}`,onRemove:w===null?void 0:()=>void ee(e),removeLabel:a(`customize.assign.removeNamed`,{name:n}),busy:M},t)})]}),u(Zo,{open:f,title:a(`customize.motion.pickTitle`),selection:`multi`,candidates:D,room:E,filters:jo,confirmLabel:e=>a(`customize.assign.addCount`,{count:e}),onConfirm:e=>{if(p(!1),w===null)return;let t=vs(w,e.map(e=>e.ref));if(t!==null&&t.sensors.length>8){h(a(`customize.motion.tooMany`,{max:8}));return}N(t)},onClose:()=>p(!1)})]})}var ks={"numeric-sensor":{fieldPath:`value`,unitField:`unit`},"temperature-sensor":{fieldPath:`celsius`,unitField:`unit`},"humidity-sensor":{fieldPath:`percent`,unitField:`unit`},"pressure-sensor":{fieldPath:`hpa`,unitField:`unit`},"ambient-light-sensor":{fieldPath:`lux`,unitField:`unit`}},As=new Set([X.Camera]);function js(e){return e.unitField===null?[e.fieldPath]:[e.fieldPath,e.unitField]}function Ms(e,t){if(As.has(e))return{kind:`absent`};let n=null;for(let[e,r]of Object.entries(ks))if(t.has(e)){n={cap:e,fieldPath:r.fieldPath,unitField:r.unitField};break}let r=null;for(let e of Ur)if(t.has(e)){let t=br[e];if(t!==void 0){r={cap:e,fieldPath:t};break}}return n===null&&r===null?{kind:`absent`}:{kind:`present`,convert:n,invert:r}}function Ns(e){return Vr(e.from,e.to)?Fr(e):null}function Ps(e){return Tr(e)}var Fs=/^convert\(v,\s*"[^"]*",\s*"[^"]*"\)$/;function Is(e){return e!==void 0&&Fs.test(e.expr)}function Ls(e){return e===void 0||e.expr===`!v`||Fs.test(e.expr)?!1:e.bindings.v!==void 0}function Rs(e){let t=e.expr.trim();if(t===``)return{kind:`refused`,reason:`expression is empty`};let n={kind:`expression`,expr:t,bindings:{v:{kind:`from`,source:e.self,cap:e.cap,fieldPath:e.fieldPath}}},r=jr({source:n,now:Date.now(),read:()=>({state:`fresh`,value:e.probe})});return r.state===`unavailable`?{kind:`refused`,reason:r.reason}:{kind:`ok`,feature:{kind:`fields`,cap:e.cap,fields:{[e.fieldPath]:n}}}}function zs(e,t,n){if(e===null)return null;let r=Bi(e,n.cap);if(r===null)return e;let i=new Set(js(n)),a=Object.fromEntries(Object.entries(r.fields).filter(([e])=>!i.has(e)));return Object.keys(a).length===0?gi(e,n.cap):yi(e,t,{kind:`fields`,cap:n.cap,...r.enabled===void 0?{}:{enabled:r.enabled},fields:a,...r.items===void 0?{}:{items:r.items}})}n();function Bs(e){if(typeof e!=`object`||!e)return;let t=Reflect.get(e,`unit`);return typeof t==`string`?t:void 0}function Vs(e,t){if(typeof e!=`object`||!e)return;let n=Reflect.get(e,t);return typeof n==`number`&&Number.isFinite(n)?n:void 0}function Hs(e,t){let n=Bi(e,t.cap);if(n===null)return;let r=n.fields[t.fieldPath];return r!==void 0&&r.kind===`expression`?r:void 0}function Us(e,t){let n=Hs(e,t);return n===void 0||!Is(n)?null:/^convert\(v,\s*"[^"]*",\s*"([^"]*)"\)$/.exec(n.expr)?.[1]??null}function Ws(e,t){let n=Hs(e,t);return n===void 0||!Ls(n)?null:n.expr}function Gs(e,t,n){let r=Bi(e,t);if(r===null)return!1;let i=r.fields[n];return i!==void 0&&i.kind===`expression`&&i.expr===`!v`}function Ks(e){return typeof e==`number`||typeof e==`boolean`||typeof e==`string`?String(e):e===null?`null`:JSON.stringify(e)}function qs({device:e,target:t,handle:n,facts:i}){let{t:a}=Z(),o=T(),[s,l]=c(null),[d,p]=c(``),[m,h]=c(null),_=i.nativeCaps.kind===`known`?i.nativeCaps.value:null,v=_===null?null:Ms(e.type,_),y=v?.kind===`present`?v.convert?.cap??``:``,b=gn(o.trpcClient,e.id,y);if(i.nativeCaps.kind===`pending`)return u(`section`,{className:`${g} ${f}`,children:u(ko,{availability:{kind:`pending`}})});if(i.nativeCaps.kind===`unknown`)return u(`section`,{className:`${g} ${f}`,children:u(ko,{availability:{kind:`unknown`,reason:i.nativeCaps.reason}})});if(v===null||v.kind===`absent`)return null;let x=Ja(n.state),S=v.convert,C=v.invert,w=S===null?void 0:Bs(b),E=w===void 0?void 0:Er(w)??w,D=E===void 0?void 0:Nr(E),O=S===null?null:Us(x,S),k=S===null?null:Ws(x,S),A=m??k??``,j=C===null?!1:Gs(x,C.cap,C.fieldPath),M=n.state.kind===`none`||n.state.kind===`present`,N=S===null?0:Vs(b,S.fieldPath)??0,ee=S!==null&&A.trim()!==``?{kind:`expression`,expr:A.trim(),bindings:{v:{kind:`from`,source:t,cap:S.cap,fieldPath:S.fieldPath}}}:null,P=ee===null||S===null?null:ji(ee,new Map([[Sr(t,S.cap),b===void 0?{kind:`pending`}:{kind:`value`,slice:b}]]),Date.now()),F=async e=>{let t=await n.save(e);l(t.kind===`refused`?t.reason:null)},te=async()=>{if(S===null||E===void 0||d===``)return;let e=Ns({self:t,cap:S.cap,fieldPath:S.fieldPath,from:E,to:d,unitField:S.unitField});if(e===null){l(a(`customize.numericTransforms.convertRefused`));return}h(null),await F(yi(x,t,e))},I=async()=>{S!==null&&(await F(zs(x,t,S)),p(``))},L=async()=>{if(S===null)return;let e=Rs({self:t,cap:S.cap,fieldPath:S.fieldPath,expr:A,probe:N});if(e.kind===`refused`){l(e.reason);return}p(``),await F(yi(x,t,e.feature))},R=async()=>{S!==null&&(await F(zs(x,t,S)),h(``))},z=async()=>{if(C===null)return;let e=Ps({self:t,cap:C.cap});if(e===null){l(a(`customize.numericTransforms.invertRefused`));return}await F(yi(x,t,e))},B=async()=>{C===null||x===null||await F(gi(x,C.cap))};return u(Do,{id:`numeric-transforms`,icon:Ui,title:a(`customize.numericTransforms.title`),testId:`numeric-transforms-card`,children:r(`div`,{className:`${f} flex flex-col gap-3`,children:[u(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`customize.numericTransforms.blurb`)}),s!==null&&u(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:s}),S!==null&&r(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-convert`,children:[u(`label`,{className:`text-[11px] font-medium text-foreground`,children:a(`customize.numericTransforms.publishUnit`)}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:E===void 0?a(`customize.numericTransforms.fromUnknown`):a(`customize.numericTransforms.fromUnit`,{unit:E})}),u(`div`,{className:`w-full sm:max-w-xs`,children:u(Ut,{dimension:D,value:d===``?O??``:d,onChange:e=>{p(e),e!==``&&h(``)},disabled:!M||n.saving||E===void 0,"aria-label":a(`customize.numericTransforms.toUnit`),inheritLabel:a(`customize.numericTransforms.pickUnit`),emptyReason:a(`customize.numericTransforms.fromUnknown`)})}),r(`div`,{className:`flex flex-wrap gap-2`,children:[u(H,{size:`sm`,disabled:!M||n.saving||E===void 0||d===``||d===E,onClick:()=>void te(),children:a(`customize.numericTransforms.applyConvert`)}),O!==null&&u(H,{size:`sm`,variant:`outline`,disabled:!M||n.saving,onClick:()=>void I(),children:a(`customize.numericTransforms.clearConvert`)})]})]}),S!==null&&r(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-script`,children:[u(Pi,{label:a(`customize.numericTransforms.script`),value:A,bindings:[`v`],onChange:e=>{h(e),e.trim()!==``&&p(``)}}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`customize.numericTransforms.scriptBlurb`)}),P!==null&&u(`p`,{role:`status`,className:`text-[11px] font-mono text-foreground`,"data-testid":`numeric-script-preview`,children:P.kind===`value`?a(`customize.numericTransforms.preview`,{source:Ks(N),result:Ks(P.value)}):P.kind===`waiting`?a(`customize.numericTransforms.previewWaiting`):P.kind===`unavailable`?a(`customize.numericTransforms.previewError`,{reason:P.reason}):a(`customize.numericTransforms.previewRuntimeOnly`)}),r(`div`,{className:`flex flex-wrap gap-2`,children:[u(H,{size:`sm`,disabled:!M||n.saving||A.trim()===``,onClick:()=>void L(),children:a(`customize.numericTransforms.applyScript`)}),k!==null&&u(H,{size:`sm`,variant:`outline`,disabled:!M||n.saving,onClick:()=>void R(),children:a(`customize.numericTransforms.clearScript`)})]})]}),C!==null&&r(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-invert`,children:[u(`label`,{className:`text-[11px] font-medium text-foreground`,children:a(`customize.numericTransforms.invert`)}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`customize.numericTransforms.invertBlurb`)}),u(`div`,{className:`flex flex-wrap gap-2`,children:j?u(H,{size:`sm`,variant:`outline`,disabled:!M||n.saving,onClick:()=>void B(),children:a(`customize.numericTransforms.clearInvert`)}):u(H,{size:`sm`,disabled:!M||n.saving,onClick:()=>void z(),children:a(`customize.numericTransforms.applyInvert`)})})]})]})})}n();function Js(e){return e instanceof Error?e.message:String(e)}function Ys(e){let n=ne({addonId:e.addonId,stableId:e.stableId}),r=F(),i=je(),a=Rt(),o=qa({status:n.status,data:n.data,error:n.error===null||n.error===void 0?null:{message:n.error.message}}),{t:s}=Z(),l=t(!1),[u,d]=c(!1),f=async e=>{let t=Si(o,e);try{switch(t.kind){case`refused`:return{kind:`refused`,reason:t.reason};case`noop`:return{kind:`saved`};case`create`:await r.mutateAsync({block:t.input});break;case`update`:await i.mutateAsync({blockId:t.blockId,expectedUpdatedAt:t.expectedUpdatedAt,block:{composition:t.composition}});break;case`delete`:await a.mutateAsync({blockId:t.blockId});break}return await n.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:Js(e)}}};return{target:e,state:o,saving:u||r.isPending||i.isPending||a.isPending,save:async e=>{if(l.current)return{kind:`refused`,reason:s(`customize.saveInFlight`)};l.current=!0,d(!0);try{return await f(e)}finally{l.current=!1,d(!1)}}}}var Xs=`pipeline-orchestrator`;function Zs(e){return e.status===`pending`?`pending`:e.status===`error`?`unknown`:e.data===void 0?`pending`:e.data.cameraSensors===void 0?`absent`:`present`}function Qs(e,t){return e===`absent`?`absent`:Zs(t)}async function $s(e){try{return(await e()).isError?`failed`:`answered`}catch{return`failed`}}function ec(e,t){let n=G(Xs),r=Se({deviceId:e},{enabled:t&&n!==`absent`}),i=()=>$s(r.refetch);return t?{presence:Qs(n,{status:r.status,data:r.data}),status:r.data?.cameraSensors??null,refetch:i}:{presence:`absent`,status:null,refetch:i}}function tc(e,t){let n=oe({deviceType:e.type}),r=vt({deviceId:e.id}),i=On({deviceId:e.id}),a=Ao(n,e=>new Set(e.caps.map(e=>e.cap))),o=Ao(r,e=>Va(e.entries)),s=Ao(i,e=>e);return{deviceType:e.type,composable:a,nativeCaps:o,wireable:s,composed:new Set((t?.features??[]).map(e=>e.cap))}}var nc={kind:`unknown`,reason:`the composer reports no value for this field`};function rc(e,t){let n=J(e);return t.get(n)??n}function ic(e,t,n){let r=n.nativeCaps.has(e.cap)?`replaced`:`added`,i=t.filter(t=>t.cap===e.cap&&t.origin===`composed`);if(e.cap===`doorbell`){let t=Ni(e).map(e=>rc(e,n.sourceNames)).join(` + `),a=i.find(e=>e.field===`lastPressedAt`);return[{key:`doorbell`,label:`doorbell`,origin:{kind:r,from:t},value:a?.value??nc}]}return e.cap===`consumables`?Ti(e).map(e=>{let t=t=>Or(Pr,e.key,t),a=i.find(e=>e.field===t(`level`)||e.field===t(`remaining.value`)),o=e.source===null?``:rc(e.source.source,n.sourceNames);return{key:`consumables.${e.key}`,label:`consumables · ${e.label}`,origin:{kind:r,from:o},value:a?.value??nc}}):i.map(e=>({key:e.key,label:`${e.cap}.${e.field}`,origin:{kind:r,from:e.from},value:e.value}))}function ac(e){let t=Oi({composition:e.composition,nativeCaps:e.nativeCaps,state:e.state,nativeFields:new Map,snapshot:null,sourceNames:e.sourceNames});return e.composition.features.flatMap(n=>n.kind===`fields`?ic(n,t,e):[])}function oc(e,t){if(e?.state!==`configured`||e.sensors.length===0)return null;let n=e.cameraMotion===`never`?[]:[t.camera],r=e.sensors.map(e=>t.sensor(e.state===`missing`||e.state===`unreadable`?e.stableId:e.name,e.mode));return[...n,...r].join(` + `)}var sc=`${_} grid grid-cols-1 gap-x-3 gap-y-0.5 items-baseline sm:grid-cols-[minmax(0,1fr)_minmax(0,2fr)_minmax(0,1.5fr)]`,cc=`font-mono text-[11px] text-foreground break-words`,lc=`text-[11px] text-foreground-subtle break-words`,uc=`text-[11px] break-words sm:text-right`;function dc({device:e,composition:t,state:n,nativeCaps:i,cameraSensors:a}){let{t:o}=Z(),s=t!==null&&n!==null,c=Bo(s),l=new Map(c.kind===`known`?c.value.map(e=>[J({addonId:e.addonId,stableId:e.stableId}),e.name]):[]),d=s&&i.kind===`known`?ac({composition:t,nativeCaps:i.value,state:n,sourceNames:l}):[],f=s&&i.kind===`known`&&d.length===0&&t.features.length>0,p=oc(a,{camera:o(`customize.changes.motion.camera`),sensor:(e,t)=>o(`customize.changes.motion.${t}`,{name:e})}),m=s&&i.kind!==`known`;return d.length===0&&p===null&&!m&&!f?null:r(Do,{id:`changes`,icon:P,title:o(`customize.changes.title`),children:[m&&u(`p`,{role:i.kind===`unknown`?`alert`:`status`,className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:i.kind===`unknown`?o(`customize.changes.unknown`,{reason:i.reason}):o(`customize.changes.reading`)}),f&&u(`p`,{className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:o(`customize.changes.noRows`)}),r(`ul`,{className:`divide-y divide-border`,children:[d.map(e=>r(`li`,{className:sc,children:[u(`span`,{className:cc,children:e.label}),u(`span`,{className:lc,children:c.kind===`known`?o(`customize.changes.origin.${e.origin.kind}`,{from:e.origin.from}):o(`customize.changes.originUnread.${c.kind}`,{kind:o(`customize.changes.kind.${e.origin.kind}`),reason:c.kind===`unknown`?c.reason:``})}),u(`span`,{className:uc,children:u(fc,{value:e.value})})]},e.key)),p!==null&&r(`li`,{className:sc,children:[u(`span`,{className:cc,children:`motion`}),u(`span`,{className:lc,children:p}),u(`span`,{className:uc,children:u(wo,{target:{deviceId:e.id,cap:`motion`,path:`detected`}})})]})]})]})}function fc({value:e}){let{t}=Z();switch(e.kind){case`value`:return r(`span`,{children:[Mi(e.value,!0),e.staleReason!==null&&r(`span`,{className:`text-warning`,children:[` `,`·`,` `,t(`customize.changes.value.stale`,{reason:e.staleReason})]})]});case`unavailable`:return u(`span`,{className:`text-warning`,children:t(`customize.changes.value.unavailable`,{reason:e.reason})});case`unknown`:return u(`span`,{className:`text-foreground-subtle`,children:t(`customize.changes.value.unknown`,{reason:e.reason})});case`off`:return u(`span`,{className:`text-foreground-subtle`,children:t(`customize.status.off`)})}}n();function pc({deviceId:e,activeSubTab:t,onSubTabChange:n}){let{t:r}=Z(),i=Et({deviceId:e}),a=i.data;return a==null?i.status===`error`?u(ie,{title:r(`customize.deviceUnreadable`),message:i.error?.message??``,onRetry:()=>void i.refetch()}):a===null?u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.noSuchDevice`,{deviceId:e})}):u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.loadingDevice`)}):a.addonId===`composer`?u(mc,{device:a}):u(hc,{device:a,target:{addonId:a.addonId,stableId:a.stableId},activeSubTab:t,onSubTabChange:n})}function mc({device:e}){let{t}=Z(),n=e.stableId.startsWith(`composed-`)?e.stableId.slice(Hr.length):null;return r(`section`,{className:`${g} ${f} flex flex-col gap-2`,children:[u(`p`,{className:`text-xs text-foreground`,children:t(`customize.composed.body`)}),n!==null&&u(si,{className:`text-[11px] text-primary hover:underline`,to:ui(n),children:t(`customize.composed.edit`)})]})}function hc({device:e,target:t,activeSubTab:n,onSubTabChange:i}){let a=Ys(t),o=G(`composer`),{t:s}=Z(),c=ec(e.id,e.type===X.Camera),l=tc(e,Ja(a.state)),d={deviceType:e.type,composable:l.composable,nativeCaps:l.nativeCaps,cameraSensors:c.presence},f=()=>i(li),p=a.state.kind===`none`||a.state.kind===`present`;return n===`advanced`?r(`div`,{className:`flex flex-col gap-3`,children:[u(_c,{state:a.state}),p&&u(gc,{device:e,target:t,handle:a,facts:l,onDone:()=>i(`main`)})]}):r(`div`,{className:`flex flex-col gap-3`,children:[u(ro,{device:e}),o===`absent`&&u(`p`,{role:`alert`,className:`text-xs text-warning`,children:s(`customize.composerAbsent`)}),a.state.kind!==`none`&&u(_c,{state:a.state}),u(is,{device:e,handle:a,availability:Ga(`doorbell`,d),onAdvanced:f}),u(Os,{device:e,handle:a,availability:Ga(`motion`,d),sensors:c}),u(Go,{device:e,handle:a,availability:Ga(`battery`,d),onAdvanced:f}),u(Jo,{device:e,handle:a,availability:Ga(`consumables`,d),onAdvanced:f}),u(qs,{device:e,target:t,handle:a,facts:l}),u(ms,{device:e}),u(dc,{device:e,composition:Ja(a.state),state:a.state.kind===`present`?a.state.view.state:null,nativeCaps:l.nativeCaps,cameraSensors:c.status}),r(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[p?u(Ka,{onAdvanced:f}):u(`span`,{}),u(vc,{handle:a})]})]})}function gc({device:e,target:t,handle:n,facts:r,onDone:i}){let a=n.state.kind===`present`?n.state:null;return u(Ii,{initial:a===null?_i(t):vi(a.composition,``),blockId:a===null?null:a.view.block.id,deviceType:e.type,targetName:e.name,nativeCaps:r.nativeCaps,targetFields:r.wireable,onCancel:i,save:async e=>{let t=await n.save(e);return t.kind===`saved`&&i(),t}})}function _c({state:e}){let{t}=Z();switch(e.kind){case`pending`:return u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.status.pending`)});case`unknown`:return u(ie,{title:t(`customize.status.unknownTitle`),message:e.reason});case`not-loaded`:return u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.status.notLoaded`,{reason:e.reason})});case`none`:return null;case`present`:{let n=e.view.block;return r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[u(Tn,{variant:n.status===`running`?`success`:n.status===`failed`?`danger`:`warning`,children:t(`customize.blockStatus.${n.status}`)}),!n.enabled&&u(Tn,{variant:`default`,children:t(`customize.status.off`)}),n.lastError!==void 0&&u(`span`,{className:`text-[11px] text-foreground-muted break-words`,children:n.lastError}),e.view.state.kind===`unreachable`&&u(`span`,{className:`text-[11px] text-warning`,children:t(`customize.status.composerUnreachable`,{reason:e.view.state.error})})]})}}}function vc({handle:e}){let{t}=Z(),n=Zt(),[i,a]=c(null);if(e.state.kind!==`present`)return null;let o=async()=>{if(!await n({title:t(`customize.remove.title`),message:t(`customize.remove.message`),confirmLabel:t(`customize.remove.confirm`),variant:`danger`}))return;let r=await e.save(null);a(r.kind===`refused`?r.reason:null)};return r(`div`,{className:`flex flex-col items-start gap-1`,children:[u(H,{variant:`danger`,size:`sm`,disabled:e.saving,onClick:()=>void o(),children:t(`customize.remove.button`)}),i!==null&&u(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:i})]})}var yc=`overview`;function bc(e,t){return e.some(e=>e.id===t)?t:yc}function xc({deviceId:e}){let t=s(),n=Number.isFinite(e),{data:i}=Et({deviceId:e},{enabled:n}),a=typeof i?.type==`string`?i.type:`camera`;fn([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:o,isLoading:c,isError:l,error:d}=vt({deviceId:e},{enabled:n}),{data:f}=Qe({deviceType:a},{enabled:!!a}),p=Le({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(c)return u(`div`,{className:`p-4`,children:u(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(l)return r(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,d instanceof Error?d.message:String(d)]});let m=new Map,h={};for(let e of f??[])h[e.capName]=e.wrappers;for(let e of o?.entries??[])m.set(e.capName,{...e,wrappers:h[e.capName]??[]});for(let e of f??[])m.has(e.capName)||m.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let g=[...m.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(g.length===0)return r(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[u(Jn,{className:`h-8 w-8 opacity-40`}),u(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),u(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let _=g.filter(e=>e.kind!==`unbound`).length;return r(`div`,{className:`flex flex-col gap-3 p-1`,children:[r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-foreground`,children:_}),` of `,g.length,` capabilit`,g.length===1?`y`:`ies`,` bound — rows marked `,u(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),u(ae,{columns:[{key:`capability`,header:`Capability`,render:e=>u(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>u(Sc,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>u(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||u(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?u(Cc,{nodeId:e.providerNodeId}):u(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>u(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||u(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return u(wc,{wrappers:t.wrappers,activeWrapperId:n,disabled:p.isPending,onPick:r=>{let i=n===r;p.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:g,rowKey:e=>e.capName,minWidthPx:720})]})}function Sc({kind:e}){return e===`native`?r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(pt,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(mr,{className:`h-3 w-3`}),`wrapped`]}):e===`linked`?r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-warning/30 text-warning bg-warning/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(Lt,{className:`h-3 w-3`}),`linked`]}):r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(L,{className:`h-3 w-3`}),`unbound`]})}function Cc({nodeId:e}){return u(`span`,{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e===`hub`?`text-foreground-subtle`:`text-foreground`}`,children:e})}function wc({wrappers:e,activeWrapperId:t,disabled:n,onPick:i}){return e.length===0?u(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):u(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let a=e===t;return r(`button`,{disabled:n,onClick:()=>i(e),title:a?`Click to deactivate (revert to native)`:`Activate wrapper ${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 ${a?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[u(a?Ot:O,{className:`h-3 w-3`}),e]},e)})})}function Tc({deviceId:e,activeSubTab:t,onSubTabChange:n,deviceType:i,isAdmin:a}){return r(`div`,{className:`flex flex-col gap-3`,children:[qr(i,a)&&u(Te,{deviceId:e,readOnly:!0}),u(ti,{deviceId:e,activeSubTab:t,onSubTabChange:n})]})}n();var Ec=[[`pipelineOrchestrator`,`getCameraDetectionSource`]];function Dc(t){let n=s(),r=ge({deviceId:t},{refetchOnMount:`always`}),i=Jt(),[a,o]=c(null),[l,u]=c(null),d=e(async e=>{u(null),o(e);try{await i.mutateAsync({deviceId:t,source:e}),await n.invalidateQueries({queryKey:Ec})}catch(e){u(e instanceof Error?e.message:`Could not change the root detector`),await n.invalidateQueries({queryKey:Ec})}finally{o(null)}},[t,i,n]),f=r.data??null;return{view:f,isLoading:r.isLoading,source:a??f?.source??null,saving:a!==null,error:l,pick:d}}var Oc=`object-detection`;function kc(e){return[e.addonId,...e.children.flatMap(kc)]}function Ac(e,t){if(e===`pipeline`)return new Set;let n=jc(t,Oc);return n===void 0?new Set:new Set(e===`onboard`?[n.addonId]:kc(n))}function jc(e,t){for(let n of e){if(n.addonId===t)return n;let e=jc(n.children,t);if(e!==void 0)return e}}function Mc(e,t){return e===`onboard`?`Camera AI`:t===`object-detection`?`No root`:`Idle`}function Nc(e){switch(e){case`pipeline`:return`This node detects: the root step runs on decoded frames and every step below it applies.`;case`onboard`:return`The camera detects: its own boxes replace the root step, so the accelerator is not asked. The steps below it still run on crops from this node's frames.`;case`none`:return`No root detector: nothing is detected on this camera, so every video step below the root is idle.`}}function Pc(e){switch(e){case`boxed`:return``;case`while-streaming`:return`Its boxes ride the stream that is already open, so they exist only while the camera is awake; between wake-ups it reports nothing.`;case`flag-only`:return`Its onboard AI reports a class with no bounding box, so it cannot be the root detector.`;case`unknown`:return`This camera has not said whether its detections carry a bounding box; without one it cannot be the root detector.`}}function Fc(e,t){return e===`onboard`?`Not running here: this camera's own detector is the root, so this node's root step is never asked. These settings apply again if you switch the root detector back to this node.`:t===`object-detection`?`Not running here: this camera has no root detector.`:`Idle: this camera has no root detector, so there is nothing for this step to work on.`}function Ic({source:e,geometry:t,saving:n,error:i,onPick:a}){let o=t===`flag-only`,s=Pc(t);return r(`section`,{"aria-label":`Root detector`,"aria-busy":n,className:`space-y-1.5 rounded-md border border-border bg-surface px-3 py-2`,children:[r(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1.5`,children:[u(`h3`,{className:v,children:`Root detector`}),u(Bt,{label:`Root detector`,value:e,onChange:t=>{!n&&t!==e&&a(t)},options:[{value:`pipeline`,label:`This node`},{value:`onboard`,label:`Camera onboard AI`,disabled:o&&e!==`onboard`,reason:s},{value:`none`,label:`None`}]}),n&&u(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Saving…`})]}),r(`p`,{className:j,children:[Nc(e),` A camera runs one root detector at a time.`]}),s!==``&&u(`p`,{className:`text-[10px] text-foreground-subtle`,children:s}),i!==null&&u(`p`,{role:`alert`,className:`text-[11px] text-danger`,children:i})]})}n();var Lc=new Set([`package-detection`]);function Rc(e){return e?.settings!==void 0&&Object.keys(e.settings).length>0?`accelerator`:`camera`}function zc(e){return e===`camera`?`this camera`:e===`node`?`node pin`:`hardware default`}function Bc(e){let{stored:t,draft:n,below:r,boundKeys:i}=e,a=n?.modelId===void 0?t?.modelId:n.modelId??void 0,o=Gr(n?.settings??t?.settings,r,i),s={...a===void 0?{}:{modelId:a},...o===void 0?{}:{settings:o}};return Object.keys(s).length>0?s:null}function Vc(e,t){return(e?.modelId??null)===(t?.modelId??null)&&Lr(e?.settings??{},t?.settings??{})}function Hc({deviceId:e}){let t=s(),n=T().trpcClient,l=ve({deviceId:e},{refetchOnMount:`always`}),d=ce({deviceId:e},{refetchOnMount:`always`}),f=ue(void 0,{refetchOnMount:`always`}),p=xr(Un({addonId:`pipeline-orchestrator`}).data??null);fn([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let{nodes:m}=Dn(),h=i(()=>{let e=new Set((f.data??[]).map(e=>e.nodeId));return m.filter(t=>t.isOnline&&e.has(t.id)).map(e=>({id:e.id,name:e.name}))},[f.data,m]),g=h.map(e=>e.id).join(`,`),_=a({enabled:h.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`camera-step-schemas`,g],queryFn:async()=>{let e={};for(let t of h)try{e[t.id]=await n.pipelineExecutor.getSchema.query({nodeId:t.id})}catch{}return e}}),y=a({enabled:h.length>0,queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`],`camera-step`,g],queryFn:async()=>{let e={};for(let t of h)try{e[t.id]=(await n.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:t.id})).devices}catch{e[t.id]=[]}return e}}),b=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]})},x=nn({onSuccess:b}),S=Nt(),C=Je(),[w,E]=c(null),[D,O]=c(null),[k,A]=c(null),[M,ee]=c(!1),[P,F]=c(null),te=_.data??{},I=y.data??{},L=d.data??{},R=l.data??null,z=h.map(e=>te[e.id]).find(e=>e!==void 0)??null,B=i(()=>z?Ee(z):[],[z]),ne=i(()=>ir(B),[B]),V=Dc(e),re=i(()=>V.source===null?new Set:Ac(V.source,B),[V.source,B]),[H,U]=c(!1),ie=i(()=>sr(h,I,H),[h,I,H]),ae=i(()=>sr(h,I,!0),[h,I]),oe=i(()=>sr(h,I).length,[h,I]),se=(e,t)=>Qn(te[e.nodeId],t),W=(e,t)=>L[e.nodeId]?.[e.deviceKey]?.[t],le=(e,t)=>fr(I[e.nodeId]??[],e.deviceKey,t)??{},G=e=>{if(Lc.has(e))return{kind:`zone-driven`};let t=Qn(z,e)?.enabledByDefault??!0,n=R?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},de=(e,t,n)=>{let r=n?.stepId===t?n:null;return{node:le(e,t),camera:r?.camera??R?.stepSettings?.[t],accelerator:r?.perAccelerator[e.id]?.settings??W(e,t)?.settings}},fe=(e,t,n)=>{let r=n?.stepId===t?n.perAccelerator[e.id]?.modelId:void 0;return r===void 0?W(e,t)?.modelId:r??void 0},pe=(e,t)=>{if(re.has(e))return{kind:`disabled`};let n=se(t,e),r=G(e),i=or(e),a=$n(te[t.nodeId],t,W(t,`object-detection`)?.modelId),o=de(t,e,null),s=zr(o.node,o.camera,o.accelerator);return lr({addon:n,acc:t,gatedOn:r.kind===`gate`?r.effectiveOn:!0,model:n?ar(n,t,{nodePin:t.device.steps?.[e]?.modelId,cameraPin:W(t,e)?.modelId}):{modelId:void 0,source:`default`},...nr(e,s,a)&&a?{rootName:a.name}:{},...i?{clusterModelId:p[e]??i.defaultModelId}:{}})},K=ne.map(({node:e})=>({addonId:e.addonId,name:e.addonName,fieldLabels:cr(Qn(z,e.addonId))}));return f.isLoading||h.length>0&&(_.isLoading||y.isLoading)?u(`div`,{className:`animate-pulse p-4 text-xs text-foreground-subtle`,children:`Loading pipeline…`}):h.length===0?u(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No pipeline node is online.`}):z===null?u(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`Catalog unavailable.`}):r(`div`,{className:`space-y-2`,children:[V.view?.onboard.available===!0&&V.source!==null&&u(Ic,{source:V.source,geometry:V.view.onboard.geometry,saving:V.saving,error:V.error,onPick:e=>void V.pick(e)}),u(Zn,{tree:B,searchRows:K,accelerators:ie,cellState:pe,stepBadge:e=>re.has(e)&&V.source!==null?u(Tn,{variant:`warning`,title:Fc(V.source,e),children:Mc(V.source,e)}):u(N,{gate:G(e)}),disabledCount:dr(Object.fromEntries(h.map(e=>[e.id,I[e.id]??[]]))),showDisabled:H,onShowDisabledChange:U,dirty:w!==null,onDiscard:()=>E(null),summary:r(`span`,{className:j,children:[`This camera is balanced across `,oe,` accelerator`,oe===1?``:`s`,` at every session start · ovr = this camera overrides the node`]}),label:`Detection steps of this camera`,renderDetail:({stepId:t,accelerator:n,matchedField:i,closeButton:a,onEscape:s,headingRef:c})=>{let l=n??ie[0],d=l?se(l,t)??Qn(z,t):null;if(d===null||l===void 0)return u(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No step selected.`});let f=w?.stepId===t?w:null,p=qt(d),m=Dr(p),h=de(l,t,f),g=zr(h.node,h.camera,h.accelerator),_=$n(te[l.nodeId],l,W(l,`object-detection`)?.modelId),y=ar(d,l,{nodePin:l.device.steps?.[t]?.modelId,cameraPin:fe(l,t,f)}).modelId,T=zr(h.node,h.camera),N=kr(h.accelerator,T,m),I=or(t),L=G(t),B=p.find(e=>`label`in e&&e.label===i)?.key??null,ne=n===null?null:`${t}|${n.id}`,H=n===null?`camera`:D?.key===ne?D.scope:Rc(W(n,t)),U=e=>{F(null),E(n=>e(n?.stepId===t?n:{stepId:t,perAccelerator:{}}))},oe=(e,t)=>U(n=>({...n,perAccelerator:{...n.perAccelerator,[e.id]:{...n.perAccelerator[e.id],...t}}})),ce=e=>U(n=>{let r=h.accelerator??{},i=Mr(n.camera??R?.stepSettings?.[t],e,r,m),a={...n.perAccelerator};for(let r of ae){let i=n.perAccelerator[r.id]?.settings??W(r,t)?.settings;i!==void 0&&(a[r.id]={...a[r.id],settings:wr(i,e,m)})}return{...n,camera:i,perAccelerator:a}}),ue=async()=>{if(f!==null){ee(!0);try{let n=R?.stepSettings?.[t];f.camera!==void 0&&!Lr(f.camera,n??{})&&await C.mutateAsync({deviceId:e,addonId:t,settings:Object.keys(f.camera).length>0?{...f.camera}:null});let r=f.camera??n;for(let n of ae){let i=f.perAccelerator[n.id];if(i===void 0)continue;let a=W(n,t),o=Bc({stored:a,draft:i,below:zr(le(n,t),r),boundKeys:m});Vc(o,a)||await S.mutateAsync({deviceId:e,agentNodeId:n.nodeId,deviceKey:n.deviceKey,addonId:t,patch:o})}E(null),F({kind:`saved`})}catch(e){F({kind:`error`,error:e instanceof Error?e.message:`Save failed`})}finally{ee(!1),b()}}},pe=f===null?0:+(f.camera!==void 0&&!Lr(f.camera,R?.stepSettings?.[t]??{}))+Object.values(f.perAccelerator).length,K=e=>{let n=se(e,t)??d,i=fe(e,t,f),a=e.device.steps?.[t]?.modelId,s=ar(n,e,{nodePin:a,cameraPin:i}),c=de(e,t,f),l=$n(te[e.nodeId],e,W(e,`object-detection`)?.modelId),p=nr(t,zr(c.node,c.camera,c.accelerator),l),m=er(n,e)?p&&l?u(bt,{rootModel:l,stepModelId:s.modelId}):void 0:r(o,{children:[`No `,e.device.format,` build of this step — it does not run on this accelerator.`]});return{label:e.label,format:e.device.format,modelId:s.modelId,source:s.source,sourceLabel:zc(s.source),models:et(n.models??[],e.device.format),defaultModelId:n.defaultModelIdByFormat?.[e.device.format]??n.defaultModelId,expanded:k===e.id,onToggle:()=>A(t=>t===e.id?null:e.id),onChangeModel:t=>oe(e,{modelId:t}),...i===void 0?{}:{onReset:()=>oe(e,{modelId:null}),resetLabel:a===void 0?`Reset to hardware default`:`Reset to node pin`},...m===void 0?{}:{note:m},changed:f?.perAccelerator[e.id]?.modelId!==void 0}},me=I===null&&p.length>0?n===null?u(`p`,{className:j,children:`Applies to: all accelerators of this camera.`}):r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[u(`span`,{className:`text-[11px] font-medium text-foreground`,children:`Applies to`}),u(Bt,{label:`Settings apply to`,options:[{value:`accelerator`,label:`This accelerator`},{value:`camera`,label:`All accelerators of this camera`}],value:H,onChange:e=>ne!==null&&O({key:ne,scope:e})})]}):void 0;return u(q,{ref:c,title:n===null?`${d.name} · this camera`:`${d.name} · ${n.label}`,subtitle:n===null?`${d.slot} · every accelerator this camera runs on`:`${d.slot} · ${n.device.format}`,leading:a,onEscape:s,headerActions:u(It,{gate:L,busy:x.isPending,onSet:n=>x.mutate({deviceId:e,addonId:t,enabled:n})}),saveBar:{dirtyCount:pe,saving:M,status:P?.kind??null,...P?.error===void 0?{}:{error:P.error},onSave:()=>void ue(),onDiscard:()=>E(null),...me===void 0?{}:{scope:me}},children:r(`div`,{className:`space-y-3`,children:[re.has(t)&&V.source!==null&&u(`p`,{role:`note`,className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-1.5 text-[11px] text-warning`,children:Fc(V.source,t)}),r(`section`,{className:`space-y-2`,"aria-label":`Model`,children:[u(`h3`,{className:v,children:`Model`}),I===null?n===null?u(tr,{rows:ie.map(e=>{let n=ar(se(e,t)??d,e,{nodePin:e.device.steps?.[t]?.modelId,cameraPin:fe(e,t,f)});return{id:e.id,label:e.label,modelId:n.modelId,sourceLabel:zc(n.source)}})}):u(jn,{...K(n)},n.id):u(ur,{step:I,engineFormat:l.device.format,runnableModelIds:et(d.models??[],l.device.format).map(e=>e.id)})]}),I===null&&(p.length>0||_!==void 0)&&u(`section`,{"aria-label":`Settings`,className:`border-t border-border/60 pt-2`,children:u(Uc,{addon:d,fields:p,layers:h,scope:H,viewed:n,modelId:sn(d,y,g,_),root:_,pinned:n===null?[]:N,highlightKey:B,onChangeCamera:e=>U(t=>({...t,camera:e})),onChangeAccelerator:e=>oe(l,{settings:e}),onApplyToAll:ce,onFollowNode:()=>oe(l,{settings:N.reduce((e,t)=>wr(e,t,m),{...h.accelerator})})})}),u(Xn,{addonId:t,highlightLabel:i})]})})}})]})}function Uc({addon:e,fields:t,layers:n,scope:i,viewed:a,modelId:o,root:s,pinned:c,highlightKey:l,onChangeCamera:d,onChangeAccelerator:f,onApplyToAll:p,onFollowNode:m}){rr(l===null?null:wt(l));let h=a!==null&&n.accelerator!==void 0;return u(kt,{addon:e,fields:t,layers:{node:n.node,...n.camera===void 0?{}:{camera:n.camera},...h?{accelerator:n.accelerator}:{}},target:i,labels:{...a===null?{}:{accelerator:`This accelerator`},camera:`All accelerators`,node:`Node`},modelId:o,...s===void 0?{}:{rootModel:s},pinnedKeys:c,highlightKey:l,onChangeLayer:i===`camera`?d:f,...c.length>0?{headerActions:r(`button`,{type:`button`,className:w,onClick:m,children:[`Follow the node for `,c.length,` pinned field`,c.length===1?``:`s`]})}:{},fieldActions:(e,t)=>a!==null&&t===`accelerator`?u(`button`,{type:`button`,className:w,onClick:()=>p(e),children:`Apply to all accelerators`}):null})}var Wc=[{id:`object-detection`,label:`Object detection`,icon:`scan-search`},{id:`tracking`,label:`Tracking`,icon:`route`},{id:`motion`,label:`Motion`,icon:`activity`},{id:`stationary`,label:`Stationary`,icon:`square-parking`},{id:`zones`,label:`Zones`,icon:`shapes`},{id:`audio`,label:`Audio`,icon:`volume-2`},{id:`cluster`,label:`Cluster`,icon:`server`}],Gc={"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 Kc(e){return Gc[e]??`object-detection`}n();var qc=`steps`,Jc=`settings`,Yc=new Set([qc,Jc]);function Xc(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function Zc({deviceId:t,activeSubTab:n,onSubTabChange:i}){return r(ht,{value:n&&Yc.has(n)?n:qc,onValueChange:e(e=>{i?.(e)},[i]),className:`flex flex-col`,children:[r(Xt,{className:`flex-shrink-0`,children:[u(hn,{value:qc,children:`Steps`}),u(hn,{value:Jc,children:`Settings`})]}),u(xn,{value:qc,children:u(Hc,{deviceId:t})}),u(xn,{value:Jc,children:u(ti,{deviceId:t,sectionFilter:Xc,subTabGrouping:{groupOf:e=>Kc(e.id),tabs:Wc}})})]})}var Qc=`Notifications`,$c=`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`;function el(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:Qc,on:r===null?null:i??r,available:r!==null,costWhenOff:$c}}function tl(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}n();function nl(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function rl({deviceId:t}){let n=s(),i=Number.isFinite(t),[a,o]=c(null),[l,d]=c(null),f=el({mutedDeviceIds:nl(ot({},{enabled:i}).data),deviceId:t,pendingOn:l}),p=En({onError:e=>{console.error(`[DeviceNotificationMute] mute write failed — reverting`,{tags:{deviceId:t},meta:{error:e instanceof Error?e.message:String(e)}}),d(null),o(e instanceof Error?e.message:String(e)),n.invalidateQueries({queryKey:[[`notificationRules`,`listDeviceMutes`]]})},onSuccess:()=>{o(null),d(null),n.invalidateQueries({queryKey:[[`notificationRules`]]})}}),m=e(()=>{let e=tl(f,t);e!==null&&(d(!e.muted),p.mutate(e))},[t,p,f]),h=f.on===null,g=f.on===!1,_=g?Oe:Mn;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`border-b border-border px-4 py-2 flex items-center justify-between gap-2`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Notifications`}),g&&u(`span`,{className:`rounded bg-warning/20 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide text-warning`,children:`muted`})]}),r(`div`,{className:`px-4 py-3 flex items-start gap-3`,children:[r(`button`,{type:`button`,role:`switch`,"aria-label":f.label,"aria-checked":f.on===!0,disabled:!f.available||p.isPending,onClick:m,title:h?`Notification mute — state unknown; the notification centre did not answer.`:g?`Muted. ${f.costWhenOff}`:`Notifying. Muting it: ${f.costWhenOff}`,className:`inline-flex items-center gap-1.5 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors disabled:cursor-not-allowed ${a===null?h?`border-dashed border-border text-foreground-subtle/50`:g?`border-warning/40 text-warning hover:bg-warning/10`:`border-success/30 text-success hover:bg-success/10`:`border-danger/50 text-danger bg-danger/5`}`,children:[u(_,{className:`h-3.5 w-3.5`}),u(`span`,{children:h?`Unknown`:g?`Muted`:`Notifying`})]}),u(`p`,{className:`flex-1 text-[11px] leading-relaxed text-foreground-subtle`,children:a===null?h?`The notification centre did not answer, so this device’s mute state is unknown.`:f.costWhenOff:`Write failed: ${a}`})]})]})}function il(e,t){return{switchId:e,label:Ar[e].label,detail:t===void 0||t.length===0?null:t}}function al(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 ol(e){let t=al(e),n=new Set(e.sourceStillLive),r=e.sourceStillLive.map(e=>il(e,t.get(e)?.detail)),i=[...t.values()].filter(e=>e.outcome===`not-offered`&&!n.has(e.switchId)).map(e=>il(e.switchId,e.detail));return{inheritedId:e.sourceId,retiredId:e.targetId,swapped:e.swapped,verdict:r.length===0?`quiet`:`still-live`,stillLive:r,neverOffered:i}}n();function sl(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 cl({deviceId:e,deviceName:t}){let{t:n}=Z(),a=Zt(),[o,s]=c(null),l=Bn({isCamera:!0,projection:`slim`}),d=De(),f=l.data!==void 0,p=i(()=>l.data===void 0?[]:sl(l.data,e),[l.data,e]),m=p.find(e=>e.id===o)??null,h=d.data===void 0?null:ol(d.data),g=d.error===null?null:d.error.message,_=async()=>{m===null||m.id===e||await a({title:n(`deviceMigrate.confirmTitle`,`Replace “{{source}}” with “{{target}}”?`,{source:t,target:m.name}),message:n(`deviceMigrate.confirmMessage`,`“{{target}}” takes over number {{sourceId}}. That number is what every recording, event, rule, zone and home-automation export of “{{source}}” is filed under, so all of it follows the number to the new hardware and keeps working. “{{source}}” is switched off and handed number {{targetId}} in exchange. This swaps two device identities and cannot be undone from here.`,{source:t,target:m.name,sourceId:e,targetId:m.id}),confirmLabel:n(`deviceMigrate.confirmAction`,`Migrate`),variant:`danger`})&&d.mutate({sourceId:e,targetId:m.id})};return r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`min-w-0`,children:[u(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:n(`deviceMigrate.title`,`Migrate to…`)}),u(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:n(`deviceMigrate.subtitle`,`Replace this camera with other hardware you have already adopted. The new camera inherits number {{deviceId}}, so recordings, rules and integrations follow it.`,{deviceId:e})})]}),r(`div`,{className:`flex shrink-0 items-center gap-2`,children:[r(`select`,{"aria-label":n(`deviceMigrate.pickerLabel`,`Replacement camera`),className:`rounded-md border border-border bg-background px-2 py-1.5 text-xs text-foreground disabled:opacity-50`,disabled:!f||p.length===0||d.isPending,value:o===null?``:String(o),onChange:e=>{let t=e.target.value;s(t===``?null:Number(t))},children:[u(`option`,{value:``,children:f?n(`deviceMigrate.pickerPlaceholder`,`Select a camera…`):n(`deviceMigrate.pickerPending`,`Reading the fleet…`)}),p.map(e=>r(`option`,{value:String(e.id),children:[e.name,` (#`,e.id,`)`]},e.id))]}),r(`button`,{type:`button`,disabled:m===null||d.isPending,onClick:()=>{_()},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[u(Ui,{className:`h-3 w-3`}),d.isPending?n(`deviceMigrate.running`,`Migrating…`):n(`deviceMigrate.action`,`Migrate`)]})]})]}),f&&p.length===0&&u(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:n(`deviceMigrate.noTargets`,`No other camera is adopted, so there is nothing to migrate to.`)}),g!==null&&u(`p`,{className:`mt-2 text-[11px] text-danger`,children:n(`deviceMigrate.failed`,`Migration failed: {{error}}`,{error:g})}),h!==null&&u(ll,{report:h})]})}function ll({report:e}){let{t}=Z(),n=e.verdict===`quiet`;return r(`div`,{className:`mt-3 space-y-2 border-t border-border pt-3`,children:[u(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`deviceMigrate.swapped`,`The replacement now answers on number {{inheritedId}}; the old camera was handed number {{retiredId}}.`,{inheritedId:e.inheritedId,retiredId:e.retiredId})}),n?r(`div`,{className:`flex items-start gap-2 rounded-md border border-success/30 bg-success/5 px-3 py-2`,children:[u(Cn,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-success`}),u(`p`,{className:`text-[11px] leading-relaxed text-foreground`,children:t(`deviceMigrate.quiet`,`Every function on the replaced camera was switched off — the old hardware is quiet.`)})]}):r(`div`,{className:`rounded-md border border-warning/40 bg-warning/5 px-3 py-2`,children:[r(`div`,{className:`flex items-start gap-2`,children:[u(Wt,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),u(`p`,{className:`text-[11px] leading-relaxed text-foreground`,children:t(`deviceMigrate.stillLive`,`The replaced camera could not be reached, so these functions are STILL RUNNING on the old hardware. Nothing here failed to migrate — but until you unplug it or reach it physically, it can still produce data.`)})]}),u(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.stillLive.map(e=>r(`li`,{className:`text-[11px] text-foreground`,children:[u(`span`,{className:`font-medium`,children:e.label}),e.detail!==null&&r(`span`,{className:`text-foreground-subtle`,children:[` — `,e.detail]})]},e.switchId))})]}),e.neverOffered.length>0&&r(`div`,{className:`rounded-md border border-border px-3 py-2`,children:[r(`div`,{className:`flex items-start gap-2`,children:[u(Yn,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),u(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`deviceMigrate.neverOffered`,`The replaced camera never offered these, so there was nothing to switch off. They are not running.`)})]}),u(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.neverOffered.map(e=>u(`li`,{className:`text-[11px] text-foreground-subtle`,children:e.label},e.switchId))})]})]})}n();function ul({deviceId:e}){let[t,n]=c(null),i=pn({onSuccess:e=>{n(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>n(`Re-sync failed: ${e.message}`)});return r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[r(`div`,{className:`flex items-center justify-between gap-3`,children:[r(`div`,{children:[u(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),u(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),r(`button`,{type:`button`,disabled:i.isPending,onClick:()=>{n(null),i.mutate({camDeviceId:e})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[u(it,{className:`h-3 w-3 ${i.isPending?`animate-spin`:``}`}),i.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&u(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}function dl(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function fl({device:e}){let t=ci(),n=typeof e.id==`number`?e.id:null,i=String(e.type??``),a=i===X.Camera,o=i===X.Hub,s=e.features??[],c=s.includes(hr.Resyncable),{data:l}=gt({deviceId:n??0},{enabled:n!==null&&a,refetchInterval:5e3}),d=l?.streams??{},f=Object.entries(d),p=s.includes(hr.DoorbellButton),m=Mt(p?{deviceId:n??void 0,historyLimit:10}:void 0),h=m.latest?Date.now()-m.latest.timestamp<3e4:!1;return r(`div`,{className:`space-y-5`,children:[o&&n!==null&&u(ln,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),c&&n!==null&&u(ul,{deviceId:n}),a&&n!==null&&u(cl,{deviceId:n,deviceName:String(e.name??``)}),n!==null&&u(rl,{deviceId:n}),a&&n!==null&&u(Ht,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),p&&u(le,{history:m.history,latestIsFresh:h}),a&&n!==null&&u(Ht,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),a&&f.length>0&&r(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[u(`div`,{className:`border-b border-border px-4 py-2`,children:u(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),u(`div`,{className:`divide-y divide-border`,children:f.map(([e,t])=>r(`div`,{className:`px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 mb-2`,children:[u(nt,{className:`h-3 w-3 text-foreground-subtle`}),u(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),r(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[u(pl,{label:`Nominal`,value:dl(t.nominalBitrateKbps??0)}),u(pl,{label:`Observed`,value:dl(t.observedBitrateKbps??0)}),u(pl,{label:`Peak`,value:dl(t.peakBitrateKbps??0)}),u(pl,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),u(hi,{}),n!==null&&u(Yr,{deviceId:n})]})}function pl({label:e,value:t,warning:n}){return r(`div`,{children:[u(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),u(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}var ml=[{id:`overview`,label:`Overview`,cameraOnly:!1,adminOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1,adminOnly:!1},{id:mi,label:`Customize`,cameraOnly:!1,adminOnly:!0},{id:`detection-pipeline`,label:`Detection pipeline`,cameraOnly:!0,adminOnly:!1},{id:`bindings`,label:`Bindings`,cameraOnly:!0,adminOnly:!1}];function hl(e,t){let n=e===X.Camera;return ml.filter(e=>(n||!e.cameraOnly)&&(t||!e.adminOnly)).map(({id:e,label:t})=>({id:e,label:t}))}function gl({provider:e,integrationId:t,name:n}){let r=ci(),i=t===null?`/integrations`:`/integrations/${t}`,a=n===null?`Open integrations`:`Open integration ${n}`;return u(`button`,{type:`button`,onClick:()=>r(i),className:`shrink-0 rounded-md transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-1 focus-visible:ring-primary/50`,title:a,"aria-label":a,children:u(Qr,{type:e,size:`lg`})})}n();var _l=[{id:`logs`,icon:Yt,label:`Logs`},{id:`repl`,icon:di,label:`REPL`},{id:`events`,icon:R,label:`Events`},{id:`state`,icon:mt,label:`State`}];function vl(){let n=ni(),a=Number(n.deviceId),l=Number.isFinite(a),d=ci(),f=s(),p=Zt(),m=T(),{user:h}=ri(),g=h?.isAdmin===!0,[_,v]=Kr(),b=_.get(`tab`)??`overview`,S=_.get(`sub`),[C,w]=c(`logs`),E=`device-detail.left-col-width-px`,[O,A]=c(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(E),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),j=t(O);j.current=O;function N(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??O??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{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(E,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:P,isLoading:F,isError:te}=Et({deviceId:a},{enabled:l,refetchInterval:5e3,retry:1}),{data:L}=Ct({deviceId:a},{enabled:l}),R=i(()=>{let e=L?.settings?.sections??[],t=L?.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(ei)&&r.add(fi),[...r].map(e=>e===`export`?{id:e,label:$r,isAddonContrib:!0}:{id:e,label:Br[e]?.label??e,isAddonContrib:!0})},[L]),z=P,B=String(z?.name??n.deviceId??`Device`),ne=z?.online===!0,V=ne?`online`:`offline`,re=String(z?.addonId??`rtsp`),H=z?.features??[],U=z?.type,ie=U===X.Camera,{data:ae}=ai(l?a:0),oe=U===X.Container,se=i(()=>(ae??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[ae]),ce=i(()=>oe?Tt(se,typeof z?.linkDeviceId==`number`?z.linkDeviceId:null,typeof z?.primaryChildEntityId==`string`?z.primaryChildEntityId:null)?.id??null:null,[oe,se,z?.linkDeviceId,z?.primaryChildEntityId]),{data:W}=Ct({deviceId:ce??0},{enabled:ce!==null}),le=i(()=>{if(ce===null)return[];let e=W?.settings?.sections??[],t=W?.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:Br[e]?.label??e,isAddonContrib:!0,childDeviceId:ce}))},[ce,W]),G=typeof z?.parentDeviceId==`number`?z.parentDeviceId:null,{data:ue}=Et({deviceId:G??0},{enabled:G!==null}),K=at(),he=z?.disabled!==!0,ge=i(()=>{let e=L?.settings?.sections??[],t=L?.live?.sections??[];return pi([...e,...t],U,g,L!==void 0)},[L,U,g]),_e=i(()=>{let e=new Set,t=[];for(let n of[...hl(U,g),...R,...le])n.id===`config`&&!ge||e.has(n.id)||(e.add(n.id),t.push(n));return t},[U,g,R,le,ge]),ve=i(()=>bc(_e,b),[_e,b]),be=e(e=>{v(t=>{let n=new URLSearchParams(t);e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`);for(let e of pr)n.delete(e);return n},{replace:!0})},[v]),xe=e(e=>{v(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[v]),Se=(ae??[]).length>0,we=i(()=>_l.filter(({featureGate:e})=>!e||H.includes(e)),[H]),{data:Te}=cn(void 0),Ee=i(()=>z?Qt(z,Te):null,[z,Te]),q=Ee?.kind===`resolved`?Ee.integration:null,De=q===null?Ee?.kind===`unknown`?`Loading integration…`:Ee?.kind===`orphan`?`Missing integration`:`No integration`:q.name,Oe=q!==null&&q.addonId===re?q.name:re,ke=ye({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]}),d(q?.id?`/integrations/${q.id}`:`/integrations`)}}),Ae=ut({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),je=tn({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Me=ee(),Pe=pe({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=H.includes(hr.Rebootable),Le=H.includes(hr.BatteryOperated),Re=Kt(m.trpcClient,Le&&l?a:null),ze=st(m.trpcClient,l?a:null),[Be,Ve]=c(!1),We=async()=>{if(!Be){Ve(!0);try{let e=B.replace(/[^a-zA-Z0-9_.-]+/g,`_`),t=new Date().toISOString().replace(/[:.]/g,`-`);await Hi(`${y}/${String(a)}.jpg?force=1`,`${e}-${t}.jpg`)}finally{Ve(!1)}}},Ge=Ae.isPending||je.isPending,{data:Ke}=Ne({deviceId:a},{enabled:l,refetchInterval:1e4}),qe=Ke?.agentNodeId??null,Je=typeof qe==`string`&&qe.length>0&&!qe.startsWith(`addon:`)?qe:void 0,{data:Ye}=Dt({deviceId:a,...Je?{nodeId:Je}:{}},{enabled:l,refetchInterval:3e3,retry:!1}),{data:Xe}=M({deviceId:a},{enabled:l,refetchInterval:3e3,retry:!1}),Ze=Xe?.level?.dbfs??null;function Qe(){if(!l)return null;switch(ve){case`overview`:return u(fl,{device:z??{}});case`config`:return u(Tc,{deviceId:a,activeSubTab:S,onSubTabChange:xe,deviceType:U,isAdmin:g});case`detection-pipeline`:return u(Zc,{deviceId:a,activeSubTab:S,onSubTabChange:xe});case`bindings`:return u(xc,{deviceId:a});case mi:return u(pc,{deviceId:a,activeSubTab:S,onSubTabChange:xe});default:{let e=ve,t=R.some(t=>t.id===e),n=le.find(t=>t.id===e);if(!t&&n===void 0)return null;let r=n?.childDeviceId??a;if(e===`export`)return u(ti,{deviceId:a,sectionFilter:ei,activeSubTab:S,onSubTabChange:xe});let i=u(ti,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:S,onSubTabChange:xe});return n!==void 0&&r!==a?u(He,{deviceId:r,children:i}):i}}}return l?F?r(`div`,{className:`flex flex-col h-full`,children:[r(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[u(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),u(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),u(`div`,{className:`flex-1 p-6`,children:u(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):te||!P?r(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[u(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),r(`p`,{className:`text-xs`,children:[`No device with ID`,` `,r(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,a]})]}),u(`button`,{onClick:()=>d(`/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:`Back to Integrations`})]}):r(`div`,{className:`absolute inset-0 flex flex-col overflow-clip`,children:[r(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[u(`div`,{className:`mb-2`,children:u(de,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},q===null?{label:De}:{label:De,onClick:()=>d(`/integrations/${q.id}`)},{label:B}]})}),r(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[q!==null&&u(gl,{provider:q.addonId,integrationId:q.id,name:q.name}),r(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:B}),u(me,{status:V}),Le&&u(Ce,{status:Re,variant:`full`}),u(Ue,{status:ze})]}),G!==null&&ue&&r(`button`,{type:`button`,onClick:()=>d(`/devices/${G}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${ue.name}`,children:[u(`span`,{children:`↑`}),u(`span`,{className:`truncate`,children:String(ue.name??`Device #${G}`)})]}),u(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:H.length>0&&u(Zr,{capabilities:H})})]}),Ye&&u(`div`,{className:`hidden lg:flex`,children:u(yl,{metrics:Ye,dbfs:Ze})}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[r(`button`,{onClick:async()=>{he?await p({title:`Disable "${B}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&je.mutate({deviceId:a}):Ae.mutate({deviceId:a})},disabled:Ge,title:he?`Disable device`:`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 ${he?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[u(yt,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:Ge?`Updating…`:he?`Enabled`:`Disabled`})]}),u(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),ie&&r(o,{children:[u($i,{deviceId:a}),u(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),u(ta,{deviceId:a}),u(Ie,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:k,disabled:Be,onClick:()=>{We()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:vn,hidden:!Fe,disabled:Me.isPending,danger:!0,onClick:async()=>{await p({title:`Reboot "${B}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Me.mutate({deviceId:a})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${Oe}.`,icon:it,disabled:Pe.isPending,danger:!0,onClick:async()=>{await p({title:`Restart "${Oe}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${B}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&Pe.mutate({addonId:re})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:x,separatorBefore:!0,disabled:ke.isPending,danger:!0,onClick:async()=>{await p({title:`Delete "${B}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&ke.mutate({deviceId:a})}}]})]})]})]}),u(He,{deviceId:a,device:z??void 0,children:u(I,{children:u(fe,{children:u(D,{children:u(rt,{children:r(`main`,{className:K?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[r(`div`,{className:K?`flex flex-col bg-surface`:`${O===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!K&&O!==null?{width:`${String(O)}px`}:void 0,children:[u(`div`,{className:ie?`flex-shrink-0 border-b border-border-subtle bg-black`:K?`flex-shrink-0 border-b border-border-subtle bg-surface`:`max-h-[55%] shrink-0 overflow-y-auto border-b border-border-subtle bg-surface`,children:ie?u(Fa,{deviceId:a,intercomAvailable:H.includes(hr.TwoWayAudio)}):u(Ta,{deviceId:a,deviceName:B,deviceType:U??`unknown`,provider:re,isOnline:ne,features:H})}),r(`div`,{className:K?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[u(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:u(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:we.map(({id:e,label:t,icon:n})=>r(`button`,{onClick:()=>w(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${C===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[u(n,{className:`h-3 w-3`}),t]},e))})}),r(`div`,{className:K?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[C===`logs`&&u(Ia,{deviceId:a,containerDeviceId:U===`container`?a:void 0}),C===`repl`&&u(La,{deviceId:a}),C===`events`&&u(Ra,{deviceId:a}),C===`state`&&u(za,{deviceId:a})]})]})]}),!K&&u(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:N,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:u(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),r(`div`,{className:K?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[u(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:u(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:_e.map(e=>{let t=ve===e.id;return r(`button`,{onClick:()=>be(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&u(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),r(`div`,{className:K?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[ve===`overview`&&Se&&u(na,{parentDeviceId:a}),Qe()]})]})]})})})})})})]}):r(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[u(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),r(`p`,{className:`text-xs`,children:[`The URL segment`,` `,u(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:n.deviceId}),` `,`is not a number.`]}),u(`button`,{onClick:()=>d(`/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:`Back to Integrations`})]})}function yl({metrics:e,dbfs:t}){let n=_e(e.phase??`idle`);return r(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[r(`div`,{className:`flex items-center gap-1.5`,children:[u(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),u(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),u(`div`,{className:`h-3 w-px bg-border`}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[u(we,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),u(`span`,{children:`fps`})]}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[u(bn,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),u(`span`,{children:`ms`})]}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[u(Pn,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),u(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&r(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{vl as DeviceDetailPage};
|