@camstack/addon-admin-ui 1.2.425 → 1.2.427
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-CYCgFnh-.js → AddonAssetIcon-BgXfFdy2.js} +1 -1
- package/dist/assets/Addons-BTWw53aT.js +4 -0
- package/dist/assets/{AdminPage-250c5IIz.js → AdminPage-C0Zxs_ot.js} +1 -1
- package/dist/assets/{AdminSectionedPage-Bx9l4jGV.js → AdminSectionedPage-D2kYQhvu.js} +1 -1
- package/dist/assets/{AiProfiles-CUuAciGa.js → AiProfiles-Ca7zuVMp.js} +1 -1
- package/dist/assets/{BrokerForm-nkI-Qcl_.js → BrokerForm-6-BwPs-g.js} +1 -1
- package/dist/assets/Build-BsduavcU.js +40 -0
- package/dist/assets/{Calendars-B5LzurzV.js → Calendars-DVTk_2iT.js} +1 -1
- package/dist/assets/Cluster-BPJ4maiI.js +1 -0
- package/dist/assets/{ClusterStepModel-RbVpM7O6.js → ClusterStepModel-CjuZ-oml.js} +1 -1
- package/dist/assets/CompositionEditor-DJcmWU2U.js +1 -0
- package/dist/assets/{CompositionEditorPage-Dwc53zIU.js → CompositionEditorPage-CDyW_Buu.js} +1 -1
- package/dist/assets/{Data-w3RkRs0J.js → Data-CLLvqZwG.js} +1 -1
- package/dist/assets/{DeviceDetail-De_43vZZ.js → DeviceDetail-BKw1gufS.js} +2 -2
- package/dist/assets/{DeviceDoActionFields-GnzcNn1m.js → DeviceDoActionFields-R-ZYIdMv.js} +1 -1
- package/dist/assets/{Devices-CPzgp4KM.js → Devices-CHeb_BTk.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-f4jubzvX.js → EmbedPlayerPage-B4y0Q0wO.js} +1 -1
- package/dist/assets/{Identity-CAsJZhy-.js → Identity-NOlTR-3q.js} +1 -1
- package/dist/assets/{IntegrationDetail-DVzyFVQi.js → IntegrationDetail-CcZkPlbN.js} +1 -1
- package/dist/assets/IntegrationHub-CuW7-WRy.js +1 -0
- package/dist/assets/{Integrations-DYJZbIJb.js → Integrations-ACdx4iPR.js} +1 -1
- package/dist/assets/Integrations-DjnhmLye.js +1 -0
- package/dist/assets/{Library-CuaDA83A.js → Library-B3iyoKdK.js} +1 -1
- package/dist/assets/Locations-Cs1VwmXB.js +3 -0
- package/dist/assets/Logs-BMc6WXCH.js +1 -0
- package/dist/assets/{MotionZonesSettings-sQ16MBx7.js → MotionZonesSettings-DjvGw8j4.js} +1 -1
- package/dist/assets/MyAccess-BfUfTXrv.js +2 -0
- package/dist/assets/{Network-gdhbKSd3.js → Network-F2lAIcbT.js} +1 -1
- package/dist/assets/NodeAddonsSettingsPanel-D3ux_JIo.js +1 -0
- package/dist/assets/Notifications-Cp3qo_EC.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-ck5SNB0S.js → PrivacyMaskSettings-IK6ytyM8.js} +1 -1
- package/dist/assets/{Recordings-C_wXXKNm.js → Recordings-D91q74Ga.js} +1 -1
- package/dist/assets/{ScanNetworkModal-DL_B-AVn.js → ScanNetworkModal-DjU-xM4X.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-8CpDpVOM.js → SceneMonitorEditor-V_pHxg3U.js} +1 -1
- package/dist/assets/{SessionsList-DZBaHZJv.js → SessionsList-DQ7kj8fX.js} +1 -1
- package/dist/assets/{Showroom-CaiMghAf.js → Showroom-Cw-6ZdvC.js} +1 -1
- package/dist/assets/System-DLLa4weE.js +1 -0
- package/dist/assets/{Terminal-C6_w6IRM.js → Terminal-D-YHBrHK.js} +1 -1
- package/dist/assets/{Viewer-ClJ6Xfm_.js → Viewer-BmXiweP2.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DUcH4sBh.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-wt87pCBz.js} +1 -1
- package/dist/assets/{addon-icons-context-_Q-TMhpS.js → addon-icons-context-CvwUgMRr.js} +1 -1
- package/dist/assets/{archive-5Mi3cn4y.js → archive-Bwv0mNo-.js} +1 -1
- package/dist/assets/{authed-media-CIBSu5eS.js → authed-media-0TPg9TTZ.js} +1 -1
- package/dist/assets/{bell-off-O6w2Rfx2.js → bell-off-D2KzCQW2.js} +1 -1
- package/dist/assets/{boxes-gwiYF6bh.js → boxes-BXQUMgws.js} +1 -1
- package/dist/assets/circle-slash-DpUtlEnB.js +1 -0
- package/dist/assets/client-CjyKfSu1.js +358 -0
- package/dist/assets/{cloud-upload-BkkCpA1A.js → cloud-upload-BsULjxPu.js} +1 -1
- package/dist/assets/crop-BtQBZ9jm.js +1 -0
- package/dist/assets/{device-integration-icon-CPrOtTLY.js → device-integration-icon-CCoHGEQZ.js} +1 -1
- package/dist/assets/device-picker-model-1Z6p3UkP.js +1 -0
- package/dist/assets/{dist-CJ-8B9yY.js → dist-DQtBl_2T.js} +1 -1
- package/dist/assets/dist-DWoekMi0.js +358 -0
- package/dist/assets/{eraser-TGwVVn87.js → eraser-DB7_WMyf.js} +1 -1
- package/dist/assets/{file-up-BGAdeddG.js → file-up-DuqaeMYR.js} +1 -1
- package/dist/assets/{hard-drive-download-srWFcoIp.js → hard-drive-download-CKj8xKOz.js} +1 -1
- package/dist/assets/{history-BuUr8Pf8.js → history-V8RQKQAb.js} +1 -1
- package/dist/assets/{hostInit-DWnakaq9.js → hostInit-CdxLRG1l.js} +1 -1
- package/dist/assets/{icons-DrL-Fdok.js → icons-CEMmjIEL.js} +1 -1
- package/dist/assets/{index-D7FGxQMl.js → index-D66JvELZ.js} +3 -3
- package/dist/assets/{key-B0MTvYot.js → key-Bj5-ZBrb.js} +1 -1
- package/dist/assets/{key-round-Cl-qLeAZ.js → key-round-B2I1YisX.js} +1 -1
- package/dist/assets/{layers-Df1aeR99.js → layers-BARFkXZ5.js} +1 -1
- package/dist/assets/{list-ordered-BzkisKLy.js → list-ordered-9lF0Gp3K.js} +1 -1
- package/dist/assets/{location-owned-usage-CVdW20Z2.js → location-owned-usage-CNXQ-Obv.js} +1 -1
- package/dist/assets/{log-in-xkUb0jne.js → log-in-CjtrIfG3.js} +1 -1
- package/dist/assets/{memory-stick-C4-nNgvT.js → memory-stick-B26_SbtH.js} +1 -1
- package/dist/assets/{message-square-plus-B2M8qlsN.js → message-square-plus-COMrVZEZ.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-cd3d1253.js → mf-entry-bootstrap-0-ec37d41a.js} +2 -2
- package/dist/assets/{mic-off-C-BZDmBY.js → mic-off-DBIqFVjg.js} +1 -1
- package/dist/assets/{monitor-off-DeEjoNtE.js → monitor-off-CTQMySOs.js} +1 -1
- package/dist/assets/{monitor-smartphone-DmzFXiIW.js → monitor-smartphone-iBd_3nPv.js} +1 -1
- package/dist/assets/mount-1Z6p3UkP.js +1 -0
- package/dist/assets/{notification-schedule-field-BDMeSniX.js → notification-schedule-field-D8dd67dT.js} +1 -1
- package/dist/assets/{octagon-alert-AbeyZo0w.js → octagon-alert-DMjnTemh.js} +1 -1
- package/dist/assets/{player-overlays-DEJGWVeQ.js → player-overlays-DWMIy1MJ.js} +1 -1
- package/dist/assets/{recycle-Cg5L5URL.js → recycle-BCVF0r6Y.js} +1 -1
- package/dist/assets/remoteEntry-RwWzzVu_.js +1 -0
- package/dist/assets/{scan-eye-QKQlUjSj.js → scan-eye-DRXP3PgB.js} +1 -1
- package/dist/assets/{scissors-CixnGpmu.js → scissors-DUFtPb9T.js} +1 -1
- package/dist/assets/{search-x-Cjg-NClW.js → search-x-B3nve3vV.js} +1 -1
- package/dist/assets/{send-C_JQVC2l.js → send-P2KlabIu.js} +1 -1
- package/dist/assets/{settings-2-0Dzmg5ID.js → settings-2-reEhyiKz.js} +1 -1
- package/dist/assets/{speaker-D_GGxoIS.js → speaker-DSNMuvS8.js} +1 -1
- package/dist/assets/{src-CVCI1YgT.js → src-BLkInT8U.js} +8 -8
- package/dist/assets/{timer-reset-DbjUS-e3.js → timer-reset-CsRTbSzh.js} +1 -1
- package/dist/assets/{ungroup-Bn_PEJ2F.js → ungroup-BLeVa8__.js} +1 -1
- package/dist/assets/{unlink-C2XiU97D.js → unlink-DeNvF8r-.js} +1 -1
- package/dist/assets/{usb-Yb2y3179.js → usb-CFseVsQJ.js} +1 -1
- package/dist/assets/{use-scenes-feed-Bg10fjvd.js → use-scenes-feed-C8frh3hQ.js} +1 -1
- package/dist/assets/{use-stationary-objects-BE7lNV-s.js → use-stationary-objects-DNayAuMq.js} +1 -1
- package/dist/assets/useEventInvalidation-1Z6p3UkP.js +1 -0
- package/dist/assets/{useNodeUrlSelection-DVvZOo0G.js → useNodeUrlSelection-BsLRiUy8.js} +1 -1
- package/dist/assets/user-round-BB0VDRnJ.js +1 -0
- package/dist/assets/{user-x-HpPBhUXj.js → user-x-CpaZ5HO0.js} +1 -1
- package/dist/assets/{video-47m9GMk0.js → video--MLJeLNU.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BHVW3f4G.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-1Do_dc2z.js} +2 -2
- package/dist/index.html +9 -9
- package/dist/server/addon.js +34 -5
- package/package.json +1 -1
- package/dist/assets/Addons-BrNO-gNV.js +0 -4
- package/dist/assets/Build-BKUHKW99.js +0 -40
- package/dist/assets/Cluster-BRfEOot0.js +0 -1
- package/dist/assets/CompositionEditor-paHohkHN.js +0 -1
- package/dist/assets/IntegrationHub-Bufk1Dn6.js +0 -1
- package/dist/assets/Integrations-CrWX5s2l.js +0 -1
- package/dist/assets/Locations-DC7Mbk0N.js +0 -3
- package/dist/assets/Logs-B3gxHPJx.js +0 -1
- package/dist/assets/MyAccess-Dk-eK9Ik.js +0 -2
- package/dist/assets/NodeAddonsSettingsPanel-Dh4z-QGr.js +0 -1
- package/dist/assets/Notifications-CP3XZDYw.js +0 -1
- package/dist/assets/System-DBkSQMrh.js +0 -1
- package/dist/assets/circle-slash-LeaAcO0Z.js +0 -1
- package/dist/assets/client-Cm-sr0wc.js +0 -358
- package/dist/assets/crop-CSoFpLsd.js +0 -1
- package/dist/assets/device-picker-model-DSRwVBTr.js +0 -1
- package/dist/assets/dist-DH3WcYkO.js +0 -358
- package/dist/assets/mount-DSRwVBTr.js +0 -1
- package/dist/assets/remoteEntry-Cdw06LwW.js +0 -1
- package/dist/assets/useEventInvalidation-DSRwVBTr.js +0 -1
- package/dist/assets/user-round-Bn5beI9W.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{G as e,I as t,K as n,Q as r,S as i,b as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{D as l,O as u,V as d,ot as f}from"./player-overlays-DWMIy1MJ.js";import{Ar as p,Cr as m,Dr as h,Er as g,Lr as _,Rr as v,Sr as y,Tr as b,_n as x,an as S,br as C,cn as w,hr as T,jr as E,ln as ee,on as te,sn as ne,vr as re,wr as ie,yr as ae}from"./client-CjyKfSu1.js";import{Bn as D,Li as oe,Ln as O,Ua as se,Xl as ce,Zn as le,ar as ue,cu as de,ji as fe,ma as k,pa as pe,s as me,uu as he}from"./src-BLkInT8U.js";import{t as A}from"./useTranslation-Bc5yH9V9.js";r();function ge(e){return{target:{kind:`new`,type:e},name:``,features:[]}}function _e(e){return{target:{kind:`existing`,device:e},name:``,features:[]}}function j(e,t){return{target:e.target,name:t,features:e.features.flatMap(e=>e.kind===`fields`?[e]:[])}}function M(e,t,n){return{...e,features:e.features.map(e=>e.cap===t?n(e):e)}}function N(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>e!==t))}function ve(e,t){switch(t.type){case`set-new-type`:return e.target.kind===`new`?{...e,target:{...e.target,type:t.deviceType}}:e;case`set-new-role`:{if(e.target.kind!==`new`)return e;let{role:n,...r}=e.target;return{...e,target:t.role===null?r:{...r,role:t.role}}}case`set-name`:return{...e,name:t.name};case`add-feature`:return e.features.some(e=>e.cap===t.cap)?e:{...e,features:[...e.features,{kind:`fields`,cap:t.cap,fields:{}}]};case`remove-feature`:return{...e,features:e.features.filter(e=>e.cap!==t.cap)};case`set-field`:return M(e,t.cap,e=>({...e,fields:{...e.fields,[t.path]:t.source}}));case`clear-field`:return M(e,t.cap,e=>({...e,fields:N(e.fields,t.path)}));case`remove-binding`:return M(e,t.cap,e=>{let n=e.fields[t.path];return n?.kind===`expression`?{...e,fields:{...e.fields,[t.path]:{...n,bindings:N(n.bindings,t.bindingName)}}}:e});case`copy-feature`:return M(e,t.cap,e=>({...e,fields:{...e.fields,...Object.fromEntries(t.paths.map(e=>[e,{kind:`from`,source:t.from,cap:t.sourceCap,fieldPath:e}]))}}))}}function ye(e){let t=C.safeParse({target:e.target,features:e.features});return t.success?{ok:!0,composition:t.data}:{ok:!1,problems:t.error.issues.map(e=>`${e.path.join(`.`)||`composition`}: ${e.message}`)}}function be(e,t){return JSON.stringify(e)!==JSON.stringify(t)}function xe(e){for(let t=1;;t++){let n=`s${t}`;if(!e.includes(n))return n}}var Se=[`room`,`converted-sensor`,`derived-binary`],P={addonId:`provider-homeassistant`,stableId:`sensor.template_source`};function Ce(){return j(w({temperatureSources:te,motionSources:S,occupancyWindowMs:ne}),`Room`)}function we(){return j({target:{kind:`new`,type:E.Sensor},features:[{kind:`fields`,cap:`numeric-sensor`,fields:{value:{kind:`expression`,expr:`convert(v, "°C", "°F")`,bindings:{v:{kind:`from`,source:P,cap:`numeric-sensor`,fieldPath:`value`}}},unit:{kind:`expression`,expr:`"°F"`,bindings:{}},lastFetchedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Converted sensor`)}function Te(){return j({target:{kind:`new`,type:E.Sensor},features:[{kind:`fields`,cap:`binary`,fields:{on:{kind:`expression`,expr:`v > 20`,bindings:{v:{kind:`from`,source:P,cap:`temperature-sensor`,fieldPath:`celsius`}}},lastChangedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Derived binary`)}function Ee(e){switch(e){case`room`:return Ce();case`converted-sensor`:return we();case`derived-binary`:return Te()}}function De(e,t){return typeof t==`number`&&Number.isFinite(t)&&t>0?{kind:`device`,path:`/devices/${t}`}:{kind:`editor`,path:`/build/compositions/${encodeURIComponent(e)}`}}var F=`rounded-lg border border-border bg-surface p-4`,Oe=F;function ke(e){return{addonId:e.addonId,stableId:e.stableId}}function I(e){return new Map(e.map(e=>[g(ke(e)),e]))}function Ae(e,t,n){let r=e?.features??[],i=r.findIndex(e=>e.cap===n.cap);return{target:e?.target??{kind:`existing`,device:t},features:i===-1?[...r,n]:r.map((e,t)=>t===i?n:e)}}function je(e,t){let n=e.features.filter(e=>e.cap!==t);return n.length===0?null:{target:e.target,features:n}}function Me(e,t){let n=e?.features.find(e=>e.cap===t);return n!==void 0&&n.kind===`fields`?n:null}function L(e){return Array.isArray(e)?e.map(L):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,L(t)]))}function R(e){return JSON.stringify(L(e))}function Ne(e,t){return R(e)===R(t)}function z(e,t){return R(e)===R(t)}function Pe(e,t){switch(e.kind){case`pending`:return{kind:`refused`,reason:`the customization has not been read yet — try again`};case`unknown`:return{kind:`refused`,reason:`the customization could not be read: ${e.reason}`};case`not-loaded`:return{kind:`refused`,reason:`the customizations are not loaded yet: ${e.reason}`};case`none`:return t===null?{kind:`noop`}:{kind:`create`,input:{enabled:!0,composition:t}};case`present`:{let n=e.view.block.id;return t===null?{kind:`delete`,blockId:n}:R(t)===R(e.composition)?{kind:`noop`}:{kind:`update`,blockId:n,expectedUpdatedAt:e.view.block.updatedAt,composition:t}}}}function B(e,t){let n=e===`enum`?`string`:e,r=t.kind===`enum`?`string`:t.kind,i={source:t.source,cap:t.cap,fieldPath:t.fieldPath};return r===n?{kind:`from`,...i}:n===`number`&&r===`string`?{kind:`expression`,expr:`number(x)`,bindings:{x:{kind:`from`,...i}}}:null}function V(e){return{kind:`expression`,expr:e,bindings:{}}}function H(e){let t=B(`number`,e.percentage);return t===null?null:{kind:`fields`,cap:`battery`,fields:e.mode===`replace`?{percentage:t}:{percentage:t,charging:V(`"unknown"`),sleeping:V(`false`),lastUpdated:V(`now`)}}}var Fe=[`percent`,...x.options];function U(e,t){return t===`percent`?{level:e}:{"remaining.value":e,"remaining.unit":V(JSON.stringify(t))}}function Ie(e,t){let n=B(`number`,t.remaining);if(n===null||!ae.test(t.key)||t.label.trim()===``)return null;let r={label:t.label.trim(),fields:U(n,t.unit)};return{kind:`fields`,cap:`consumables`,...e?.enabled===void 0?{}:{enabled:e.enabled},fields:e?.fields??{lastChangedAt:V(`now`),lastFetchedAt:V(`now`)},items:{...e?.items,[t.key]:r}}}function Le(e){if(e.level!==void 0)return`percent`;let t=e[`remaining.unit`];if(t===void 0||t.kind!==`expression`)return null;try{let e=x.safeParse(JSON.parse(t.expr));return e.success?e.data:null}catch{return null}}function Re(e){return Object.entries(e?.items??{}).map(([e,t])=>{let n=Le(t.fields),r=W(t.fields.level??t.fields[`remaining.value`]),i=r===null?null:B(`number`,r);return n!==null&&i!==null&&Ne(U(i,n),t.fields)?{key:e,label:t.label,unit:n,source:r}:{key:e,label:t.label,unit:null,source:null}})}function ze(e,t){let n=Object.fromEntries(Object.entries(e.items??{}).filter(([e])=>e!==t));return Object.keys(n).length===0?null:{...e,items:n}}function Be(e){return e.toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,48)}function Ve(e){let t=e.fields.lastPressedAt;if(t===void 0||t.kind!==`expression`)return[];let n=Object.entries(t.bindings).filter(([e])=>e.startsWith(`active`)).flatMap(([,e])=>e.kind===`from`?[e.source]:[]);return[...new Map(n.map(e=>[g(e),e])).values()]}function He(e){let t=e.fields.lastPressedAt;if(t===void 0||t.kind!==`expression`)return[];let n=t.bindings;return Object.entries(n).flatMap(([e,t])=>{if(!e.startsWith(`active`)||t.kind!==`from`)return[];let r=n[`changed${e.slice(6)}`];return r===void 0||r.kind!==`from`?[]:[{source:t.source,cap:t.cap,activeField:t.fieldPath,changedAtField:r.fieldPath}]})}function W(e){if(e===void 0)return null;if(e.kind===`from`){let{kind:t,...n}=e;return{...n,kind:`number`}}if(e.kind!==`expression`||e.expr!==`number(x)`)return null;let t=e.bindings.x;if(t===void 0||t.kind!==`from`||Object.keys(e.bindings).length!==1)return null;let{kind:n,...r}=t;return{...r,kind:`string`}}function Ue(e,t){let n=W(e.fields.percentage);if(n===null)return!1;let r=H({percentage:n,mode:t}),{enabled:i,...a}=e;return r!==null&&z(a,r)}function G(e){return e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,location:e.location,type:e.type}))}function We(e,t,n){let r=t.trim().toLowerCase();return r===``?[]:e.filter(e=>!n.includes(e.id)&&[e.name,e.stableId,e.location??``].some(e=>e.toLowerCase().includes(r))).toSorted((e,t)=>e.name.localeCompare(t.name)).slice(0,20)}function K(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n||Array.isArray(n))return;n=Object.getOwnPropertyDescriptor(n,e)?.value}return n}function Ge(e,t,n,r){return r===null?{kind:`from`,source:e,cap:t,fieldPath:n.path}:B(r,{source:e,cap:t,fieldPath:n.path,kind:n.kind})}function Ke(e,t,n,r){let i={addonId:e.addonId,stableId:e.stableId};return t.caps.flatMap(e=>e.fields.filter(e=>e.item!==!0).map(t=>({cap:e.cap,path:t.path,kind:t.kind,value:n===null?void 0:K(n[e.cap],t.path),source:Ge(i,e.cap,t,r)})))}function q(e,t){return t?e===void 0?`—`:e===null?`null`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e):`…`}var qe=[];function J({title:e,targetKind:t,excludeDeviceIds:n=qe,onPick:r,onCancel:a}){let{t:c}=A(),[f,p]=o(null);return i(`aside`,{"aria-label":e,className:`${u} ${l} flex flex-col gap-2`,children:[s(`h3`,{className:d,children:e}),f===null?s(Je,{excludeDeviceIds:n,onSelect:p}):s(Y,{device:f,targetKind:t,onPick:r,onBack:()=>p(null)}),s(`div`,{children:s(D,{variant:`ghost`,size:`sm`,onClick:a,children:c(`customize.picker.cancel`)})})]})}function Je({excludeDeviceIds:e,onSelect:t}){let{t:n}=A(),[r,c]=o(``),l=k({projection:`slim`});return i(a,{children:[i(`label`,{className:`flex flex-col gap-1 text-[11px] text-foreground-subtle`,children:[n(`customize.picker.search`),s(ce,{type:`search`,"aria-label":n(`customize.picker.search`),value:r,onChange:e=>c(e.target.value)})]}),l.status===`pending`&&s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:n(`customize.picker.loadingDevices`)}),l.status===`error`&&s(O,{title:n(`customize.picker.devicesFailed`),message:l.error?.message??``}),l.status===`success`&&s(`ul`,{className:`flex flex-col gap-1`,children:We(G(l.data),r,e).map(e=>s(`li`,{children:i(`button`,{type:`button`,className:`text-left text-[11px] hover:underline`,onClick:()=>t(e),children:[e.name,` `,i(`span`,{className:`text-foreground-subtle`,children:[`· `,e.stableId]})]})},e.id))})]})}function Y({device:e,targetKind:t,selected:n,onPick:r,onBack:a}){let{t:o}=A(),c=pe({deviceId:e.id}),l=se({deviceId:e.id});if(c.status===`pending`)return s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:o(`customize.picker.loadingFields`)});if(c.status===`error`)return s(O,{title:o(`customize.picker.fieldsFailed`),message:c.error?.message??``});let u=Ke(e,c.data,l.status===`success`?l.data:null,t),d=u.filter(e=>e.source===null).length,f={addonId:e.addonId,stableId:e.stableId};return i(`div`,{className:`flex flex-col gap-1`,children:[i(`button`,{type:`button`,className:`text-left text-[11px] text-primary`,onClick:a,children:[`← `,e.name]}),l.status===`error`&&s(`p`,{role:`alert`,className:`text-[10px] text-warning`,children:o(`customize.picker.valuesFailed`,{reason:l.error?.message??``})}),s(`ul`,{role:`listbox`,"aria-label":o(`customize.picker.fields`),className:`flex flex-col gap-1`,children:u.map(t=>{let a=t.source;if(a===null)return null;let o=()=>r({device:e,ref:f,cap:t.cap,path:t.path,kind:t.kind,source:a,value:t.value});return i(`li`,{role:`option`,"aria-selected":n?.cap===t.cap&&n.path===t.path,tabIndex:0,className:`flex justify-between gap-2 text-[11px] cursor-pointer hover:bg-surface-hover rounded px-1`,onClick:o,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&o()},children:[i(`span`,{className:`font-mono`,children:[t.cap,`.`,t.path]}),s(`span`,{children:q(t.value,l.status===`success`)})]},`${t.cap}.${t.path}`)})}),d>0&&t!==null&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:o(`customize.picker.hidden`,{count:d,kind:o(`customize.kinds.${t}`)})})]})}var Ye=`integration`;function X(e,t){switch(e.kind){case`from`:{let n=g(e.source);return`${t.get(n)??n} · ${e.cap}.${e.fieldPath}`}case`expression`:return e.expr;case`code`:return`code`}}function Xe(e,t){if(e.kind===`unreachable`)return{kind:`unknown`,reason:e.error};if(e.state===null)return{kind:`unknown`,reason:`the composer has not reported this customization yet`};let n=e.state.fields.find(t);return n===void 0?{kind:`unknown`,reason:`the composer reports no value for this field`}:n.state===`unavailable`?{kind:`unavailable`,reason:n.reason??`unavailable`}:{kind:`value`,value:n.value,staleReason:n.state===`stale`?n.reason??`stale`:null}}function Ze(e,t,n,r){return{key:`${e.feature.cap}.${t}`,cap:e.feature.cap,field:t,origin:`composed`,mode:e.mode,from:X(n,e.input.sourceNames),value:e.enabled?Xe(e.input.state,r):{kind:`off`}}}function Qe(e){let t=e.feature.cap;return Object.entries(e.feature.fields).map(([n,r])=>Ze(e,n,r,e=>e.cap===t&&e.path===n&&e.item===void 0))}function $e(e){let t=e.feature.cap;return Object.entries(e.feature.items??{}).flatMap(([n,r])=>Object.entries(r.fields).map(([r,i])=>Ze(e,m(re,n,r),i,e=>e.cap===t&&e.path===r&&e.item?.arrayPath===`items`&&e.item.key===n)))}function et(e,t,n){if(e===null)return{kind:`unknown`,reason:`the device state could not be read`};let r=K(e[t],n),i=r===void 0?void 0:_(r);return i===void 0?{kind:`unknown`,reason:`not reported`}:{kind:`value`,value:i,staleReason:null}}function tt(e){if(e.mode!==`replace`)return[];let t=e.feature.cap,n=new Set(Object.keys(e.feature.fields));return(e.input.nativeFields.get(t)??[]).filter(e=>!n.has(e)).map(n=>({key:`${t}.${n}`,cap:t,field:n,origin:`native`,mode:e.mode,from:Ye,value:et(e.input.snapshot,t,n)}))}function nt(e){return e.composition.features.flatMap(t=>{if(t.kind!==`fields`)return[];let n={feature:t,mode:e.nativeCaps.has(t.cap)?`replace`:`add`,enabled:y(t),input:e};return[...Qe(n),...$e(n),...tt(n)]})}var rt={min:`min(a, b, …)`,max:`max(a, b, …)`,abs:`abs(x)`,floor:`floor(x)`,ceil:`ceil(x)`,sqrt:`sqrt(x)`,round:`round(x, digits?)`,pow:`pow(x, y)`,clamp:`clamp(x, lo, hi)`,avg:`avg(a, b, …)`,sum:`sum(a, b, …)`,coalesce:`coalesce(a, b, …)`,age:`age(now, ts)`,convert:`convert(x, "from", "to")`,any:`any(a, b, …)`,all:`all(a, b, …)`,within:`within(ts, ms)`,number:`number(x)`,latest:`latest(ts, …)`,rose:`rose(level, changedAt, debounceMs?)`,count:`count(x)`},Z=/[A-Za-z_][A-Za-z0-9_]*$/;function it(e,t,n){let r=Z.exec(e.slice(0,t))?.[0]??``;if(r===``)return[];let i=n.filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`binding`,label:e,insert:e,hintKey:null})),a=`now`.startsWith(r)?[{kind:`now`,label:`now`,insert:`now`,hintKey:`compositionEditor.now`}]:[],o=[...v].filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`builtin`,label:rt[e]??e,insert:`${e}(`,hintKey:`compositionEditor.builtins.${e}`}));return[...i,...a,...o].slice(0,8)}function at(e,t,n){let r=t-(Z.exec(e.slice(0,t))?.[0]??``).length;return{text:`${e.slice(0,r)}${n.insert}${e.slice(t)}`,cursor:r+n.insert.length}}r();function ot({label:e,value:t,bindings:r,onChange:a}){let{t:c}=A(),l=n(null),[u,d]=o(t.length),f=it(t,u,r);return i(`div`,{className:`flex flex-col gap-1`,children:[i(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[e,s(`input`,{ref:l,className:`font-mono px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`,value:t,onChange:e=>{a(e.target.value),d(e.target.selectionStart??e.target.value.length)},onSelect:e=>d(e.currentTarget.selectionStart??t.length)})]}),f.length>0&&s(`ul`,{role:`listbox`,"aria-label":c(`compositionEditor.suggestions`),className:`rounded border border-border bg-surface text-[11px]`,children:f.map(e=>i(`li`,{role:`option`,"aria-selected":!1,tabIndex:0,className:`flex justify-between gap-2 px-1 cursor-pointer hover:bg-surface-hover`,onClick:()=>{let n=at(t,u,e);a(n.text),d(n.cursor),l.current?.focus()},children:[s(`span`,{className:`font-mono`,children:e.label}),e.hintKey!==null&&s(`span`,{className:`text-foreground-subtle`,children:c(e.hintKey)})]},`${e.kind}:${e.label}`))})]})}function st(e,t,n){if(e.kind===`code`)return{kind:`unavailable`,reason:`code fields arrive in slice 4`};if(e.kind===`expression`&&(T(e.expr,`rose`)||T(e.expr,`count`)))return{kind:`runtime-only`};let r=h(e).filter(e=>t.get(b(e.source,e.cap))?.kind!==`value`).map(ie);if(r.length>0)return{kind:`waiting`,missing:r};let i=ee({source:e,now:n,read:e=>{let n=t.get(b(e.source,e.cap)),r=n?.kind===`value`?K(n.slice,e.fieldPath):void 0,i=r===void 0?void 0:_(r);return i===void 0?{state:`unavailable`,reason:`${e.cap}.${e.fieldPath} is not reported`,fatal:!1}:{state:`fresh`,value:i}}});return i.state===`unavailable`?{kind:`unavailable`,reason:i.reason}:{kind:`value`,value:i.value,stale:i.reason}}r();function ct({sliceKey:e,deviceId:t,capName:n,onReading:r}){let i=me(f().trpcClient,t,n);return c(()=>{r(e,i===void 0?{kind:`pending`}:{kind:`value`,slice:i})},[e,i,r]),null}function lt(e,t){return[...new Map(h(e).map(e=>[b(e.source,e.cap),e]))].map(([e,n])=>({key:e,read:n,device:t.get(g(n.source))}))}function ut({source:e}){let{t:n}=A(),r=k({projection:`slim`}),[a,c]=o(new Map),l=t((e,t)=>{c(n=>new Map([...n,[e,t]]))},[]),u=lt(e,I(r.status===`success`?G(r.data):[])),d=r.status===`success`?u.filter(e=>e.device===void 0).map(e=>g(e.read.source)):[];return i(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[u.map(e=>e.device===void 0?null:s(ct,{sliceKey:e.key,deviceId:e.device.id,capName:e.read.cap,onReading:l},e.key)),s(`span`,{className:`text-foreground-subtle`,children:n(`compositionEditor.preview.label`)}),r.status===`error`?s(`span`,{className:`text-warning`,children:n(`compositionEditor.preview.devicesFailed`,{reason:r.error?.message??``})}):d.length>0?s(`span`,{className:`text-warning`,children:n(`compositionEditor.preview.unknownDevice`,{sources:d.join(`, `)})}):s(dt,{preview:st(e,a,Date.now())})]})}function dt({preview:e}){let{t}=A();switch(e.kind){case`value`:return i(`strong`,{children:[`→ `,q(e.value,!0),e.stale===null?``:` (${e.stale})`]});case`unavailable`:return s(`span`,{className:`text-warning`,children:e.reason});case`waiting`:return s(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.waiting`,{sources:e.missing.join(`, `)})});case`runtime-only`:return s(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.runtimeOnly`)})}}r();function ft({path:e,kind:t,required:n,source:r,onSet:c,onClear:l,onRemoveBinding:u,sourceNames:d}){let{t:f}=A(),[p,m]=o(`idle`),h=r?.kind===`expression`?r:null;return i(`div`,{className:`flex flex-col gap-1 rounded border border-border p-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[s(`span`,{className:`font-mono text-[11px]`,children:e}),i(`span`,{className:`text-[10px] text-foreground-subtle`,children:[f(`customize.kinds.${t}`),n?` · ${f(`compositionEditor.required`)}`:``]}),s(D,{size:`sm`,variant:`outline`,onClick:()=>m(`take`),children:f(`compositionEditor.takeFrom`)}),s(D,{size:`sm`,variant:`outline`,"aria-pressed":h!==null,onClick:()=>c(h??{kind:`expression`,expr:`null`,bindings:{}}),children:f(`compositionEditor.formula`)}),r!==void 0&&s(D,{size:`sm`,variant:`ghost`,onClick:l,children:f(`compositionEditor.clear`)})]}),r?.kind===`from`&&s(`span`,{className:`text-[11px]`,children:X(r,d)}),h!==null&&i(a,{children:[s(ot,{label:f(`compositionEditor.formulaFor`,{path:e}),value:h.expr,bindings:Object.keys(h.bindings),onChange:e=>c({...h,expr:e})}),s(`ul`,{className:`text-[11px] flex flex-col gap-0.5`,children:Object.entries(h.bindings).map(([e,t])=>i(`li`,{className:`flex flex-wrap items-center gap-2`,children:[s(`span`,{className:`font-mono`,children:e}),s(`span`,{children:t.kind===`from`?X(t,d):JSON.stringify(t.value)}),s(D,{size:`sm`,variant:`ghost`,"aria-label":f(`compositionEditor.removeBinding`,{name:e}),onClick:()=>u(e),children:`×`})]},e))}),s(D,{size:`sm`,variant:`ghost`,onClick:()=>m(`add-binding`),children:f(`compositionEditor.addSource`)})]}),p!==`idle`&&s(J,{title:f(p===`take`?`compositionEditor.takeFrom`:`compositionEditor.addSource`),targetKind:p===`take`?t:null,onCancel:()=>m(`idle`),onPick:e=>{if(p===`take`)c(e.source);else if(h!==null){let t=xe(Object.keys(h.bindings));c({...h,bindings:{...h.bindings,[t]:{kind:`from`,source:e.ref,cap:e.cap,fieldPath:e.path}}})}m(`idle`)}}),r!==void 0&&s(ut,{source:r})]})}r();function Q(e){return e===null||e.kind===`known`?null:e}function pt({draft:e,deviceType:t,nativeCaps:n,targetFields:r,dispatch:c}){let{t:l}=A(),u=fe({deviceType:t}),d=k({projection:`slim`}),f=new Map([...I(d.status===`success`?G(d.data):[])].map(([e,t])=>[e,t.name])),[p,m]=o(null),h=Q(n)??Q(r),g=n?.kind===`known`?n.value:new Set,_=new Set(e.features.map(e=>e.cap)),v=u.status===`success`?u.data.caps.filter(e=>!_.has(e.cap)&&!g.has(e.cap)):[],y=[...g].filter(e=>!_.has(e)),b=e=>g.has(e)?((r?.kind===`known`?r.value.caps.find(t=>t.cap===e):void 0)?.fields??[]).filter(e=>e.item!==!0&&!e.path.includes(`.`)).map(e=>({path:e.path,kind:e.kind,required:!1})):((u.status===`success`?u.data.caps.find(t=>t.cap===e):void 0)?.fields??[]).map(e=>({path:e.path,kind:e.kind,required:e.required}));return h===null?i(a,{children:[i(`section`,{"aria-labelledby":`editor-features`,className:`${F} flex flex-col gap-2`,children:[s(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),u.status===`pending`&&s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.checking`)}),u.status===`error`&&s(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.unknown`,{reason:u.error?.message??``})}),i(`div`,{className:`flex flex-wrap gap-1`,children:[e.features.map(e=>i(`span`,{className:`flex items-center gap-1 rounded border border-border px-1.5 text-[11px]`,children:[e.cap,s(ue,{variant:g.has(e.cap)?`default`:`info`,children:g.has(e.cap)?l(`compositionEditor.replaces`):l(`compositionEditor.added`)}),s(`button`,{type:`button`,"aria-label":l(`compositionEditor.removeFeature`,{cap:e.cap}),onClick:()=>c({type:`remove-feature`,cap:e.cap}),children:`×`})]},e.cap)),v.map(e=>i(D,{size:`sm`,variant:`outline`,onClick:()=>c({type:`add-feature`,cap:e.cap}),children:[`+ `,e.cap]},e.cap)),y.map(e=>s(D,{size:`sm`,variant:`ghost`,onClick:()=>c({type:`add-feature`,cap:e}),children:l(`compositionEditor.replaceIn`,{cap:e})},e))]})]}),e.features.map(e=>i(`section`,{"aria-label":l(`compositionEditor.steps.fieldsOf`,{cap:e.cap}),className:`${F} flex flex-col gap-2`,children:[i(`div`,{className:`flex items-center justify-between`,children:[s(`h2`,{className:`text-sm font-semibold`,children:l(`compositionEditor.steps.fieldsOf`,{cap:e.cap})}),s(D,{size:`sm`,variant:`outline`,onClick:()=>m(e.cap),children:l(`compositionEditor.copyFeature`)})]}),p===e.cap&&s(J,{title:l(`compositionEditor.copyFeature`),targetKind:null,onCancel:()=>m(null),onPick:t=>{c({type:`copy-feature`,cap:e.cap,from:t.ref,sourceCap:t.cap,paths:b(e.cap).map(e=>e.path)}),m(null)}}),b(e.cap).map(t=>s(ft,{path:t.path,kind:t.kind,required:t.required,source:e.fields[t.path],onSet:n=>c({type:`set-field`,cap:e.cap,path:t.path,source:n}),onClear:()=>c({type:`clear-field`,cap:e.cap,path:t.path}),onRemoveBinding:n=>c({type:`remove-binding`,cap:e.cap,path:t.path,bindingName:n}),sourceNames:f},t.path))]},e.cap))]}):i(`section`,{"aria-labelledby":`editor-features`,className:`${F} flex flex-col gap-2`,children:[s(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:h.kind===`unknown`?h.reason:l(`compositionEditor.reading`)})]})}var $=`px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`;function mt({draft:e,targetName:t,dispatch:n}){let{t:r}=A(),a=e.target;return i(`section`,{"aria-labelledby":`editor-target`,className:`${F} flex flex-col gap-2`,children:[s(`h2`,{id:`editor-target`,className:`text-sm font-semibold`,children:r(`compositionEditor.steps.target`)}),a.kind===`existing`?s(`p`,{className:`text-[11px]`,children:r(`compositionEditor.existingTarget`,{name:t??`${a.device.addonId}/${a.device.stableId}`})}):i(`div`,{className:`grid grid-cols-3 gap-2`,children:[i(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[r(`compositionEditor.targetType`),s(`select`,{className:$,value:a.type,onChange:e=>{let t=Object.values(E).find(t=>t===e.target.value);t!==void 0&&n({type:`set-new-type`,deviceType:t})},children:Object.values(E).map(e=>s(`option`,{value:e,children:he(e).label},e))})]}),i(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[r(`customize.identity.role`),i(`select`,{className:$,value:a.role??``,onChange:e=>n({type:`set-new-role`,role:Object.values(p).find(t=>t===e.target.value)??null}),children:[s(`option`,{value:``,children:r(`customize.identity.noRole`)}),Object.values(p).map(e=>s(`option`,{value:e,children:de(e).label},e))]})]}),i(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[r(`compositionEditor.name`),s(`input`,{className:$,value:e.name,onChange:e=>n({type:`set-name`,name:e.target.value})})]})]})]})}r();function ht({draft:e,blockId:t,saving:n,onSave:r,onCancel:a}){let{t:l}=A(),u=oe(),d=ye(e),f=d.ok?JSON.stringify(d.composition):``,[p,m]=o({key:``,state:{kind:`checking`}});c(()=>{if(!d.ok)return;let e=d.composition,n=setTimeout(()=>{u.mutateAsync({composition:e,...t===null?{}:{blockId:t}}).then(e=>m({key:f,state:e.ok?{kind:`ok`}:{kind:`refused`,problems:e.problems}})).catch(e=>m({key:f,state:{kind:`unknown`,reason:e instanceof Error?e.message:String(e)}}))},500);return()=>clearTimeout(n)},[f,t]);let h=d.ok?p.key===f?p.state:{kind:`checking`}:{kind:`invalid-draft`,problems:d.problems};return i(`section`,{"aria-labelledby":`editor-verify`,className:`${F} flex flex-col gap-2`,children:[s(`h2`,{id:`editor-verify`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.verify`)}),h.kind===`checking`&&s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.verify.checking`)}),h.kind===`ok`&&s(`p`,{className:`text-[11px] text-success`,children:l(`compositionEditor.verify.ok`)}),h.kind===`unknown`&&s(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.verify.unknown`,{reason:h.reason})}),(h.kind===`invalid-draft`||h.kind===`refused`)&&s(`ul`,{role:`alert`,className:`flex flex-col gap-1 text-[11px] text-danger`,children:h.kind===`invalid-draft`?h.problems.map(e=>s(`li`,{children:e},e)):h.problems.map(e=>i(`li`,{children:[s(`span`,{className:`font-mono`,children:e.path}),` — `,e.message]},`${e.path}:${e.code}`))}),i(`div`,{className:`flex gap-2`,children:[s(D,{variant:`ghost`,onClick:a,children:l(`compositionEditor.cancel`)}),s(D,{disabled:h.kind!==`ok`||n||!d.ok,onClick:()=>d.ok&&r(d.composition),children:l(`compositionEditor.save`)})]})]})}r();function gt({initial:e,blockId:t,deviceType:n,targetName:r=null,nativeCaps:i,targetFields:a,save:c,onCancel:l,showTemplates:u=!1}){let[d,f]=o(e),p=`${d.name}:${d.features.map(e=>e.cap).join(`,`)}:${d.target.kind===`new`?d.target.type:`existing`}`;return s(_t,{seed:d,blockId:t,deviceType:n,targetName:r,nativeCaps:i,targetFields:a,showTemplates:u,onApplyTemplate:e=>{f(Ee(e))},save:c,onCancel:l},p)}function _t({seed:t,blockId:n,deviceType:r,targetName:a,nativeCaps:c,targetFields:l,showTemplates:u,onApplyTemplate:d,save:f,onCancel:p}){let{t:m}=A(),h=le(),[g,_]=e(ve,t),[v,y]=o(!1),[b,x]=o(null),S=async e=>{be(t,g)&&!await h({title:m(`compositionEditor.templates.confirmTitle`),message:m(`compositionEditor.templates.confirmMessage`),confirmLabel:m(`compositionEditor.templates.confirmApply`),variant:`danger`})||d(e)},C=g.target.kind===`new`?g.target.type:r,w=async e=>{y(!0);let t=await f(e,g.name);y(!1),x(t.kind===`refused`?t.reason:null)};return i(`div`,{className:`flex flex-col gap-4`,children:[u&&g.target.kind===`new`&&i(`div`,{className:`rounded-lg border border-border bg-surface p-4 flex flex-wrap gap-2`,"data-testid":`composition-templates`,children:[s(`span`,{className:`text-[11px] text-foreground-subtle self-center`,children:m(`compositionEditor.templates.label`)}),Se.map(e=>s(D,{size:`sm`,variant:`outline`,onClick:()=>void S(e),children:m(`compositionEditor.templates.${e}`)},e))]}),s(mt,{draft:g,targetName:a,dispatch:_}),s(pt,{draft:g,deviceType:C,nativeCaps:c,targetFields:l,dispatch:_}),s(ht,{draft:g,blockId:n,saving:v,onSave:e=>void w(e),onCancel:p}),b!==null&&s(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:b})]})}export{je as C,_e as D,j as E,ge as O,Ae as S,De as T,W as _,Y as a,Pe as b,G as c,Ie as d,Re as f,Be as g,Ue as h,nt as i,Fe as l,He as m,st as n,q as o,Ve as p,ot as r,K as s,gt as t,H as u,ze as v,Oe as w,z as x,Me as y};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{S as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{t as n}from"./boxes-
|
|
1
|
+
import{S as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{t as n}from"./boxes-BXQUMgws.js";import{fr as r,jr as i}from"./client-CjyKfSu1.js";import{Ii as a,Ln as o,Ti as s,ki as c}from"./src-BLkInT8U.js";import{t as l}from"./useTranslation-Bc5yH9V9.js";import{X as u,Y as d,b as f,h as p,q as m}from"./index-D66JvELZ.js";import{E as h,O as g,T as _,t as v,w as y}from"./CompositionEditor-DJcmWU2U.js";import{t as b}from"./AdminPage-C0Zxs_ot.js";var x=`new`;function S(e){return e instanceof Error?e.message:String(e)}function C(e){let t=e.trim();return t===``?{}:{name:t}}function w(){let{blockId:w}=u(),{t:T}=l(),E=d(),D=s(),O=a(),k=w===void 0||w===x,A=c({blockId:w??``},{enabled:!k}),j=()=>{E(p)},M=e=>t(b,{icon:n,title:T(`compositionEditor.pageTitle`),children:e}),N=e=>t(`section`,{className:`${y} flex flex-col gap-2`,children:e});if(k)return M(t(v,{initial:g(i.Sensor),blockId:null,deviceType:i.Sensor,nativeCaps:null,targetFields:null,showTemplates:!0,onCancel:j,save:async(e,t)=>{try{let{block:n}=await D.mutateAsync({block:{...C(t),enabled:!0,composition:e}});return E(_(n.id,null).path,{replace:!0}),{kind:`saved`}}catch(e){return{kind:`refused`,reason:S(e)}}}}));if(A.status===`pending`)return M(N(t(`p`,{role:`status`,children:T(`compositionEditor.loading`)})));if(A.status===`error`)return M(N(t(o,{title:T(`compositionEditor.loadFailed`),message:A.error.message})));if(A.data.state===`not-loaded`)return M(N(t(`p`,{role:`status`,children:T(`customize.status.notLoaded`,{reason:A.data.reason})})));let P=A.data.view;if(P===null)return M(N(t(`p`,{children:T(`compositionEditor.notFound`,{blockId:w})})));let F=r(P.block);if(F===null)return M(N(t(`p`,{children:T(`compositionEditor.notComposition`)})));if(F.target.kind===`existing`){let e=P.state.kind===`answered`?P.state.state?.deviceId??null:null;return M(N(e===null?t(`p`,{children:T(`compositionEditor.customizationUnknownDevice`)}):t(m,{className:`text-primary`,to:f(e),children:T(`compositionEditor.openOnDevice`)})))}let I=P.state.kind===`answered`?P.state.state?.deviceId??null:null,L=I===null?null:_(P.block.id,I);return M(e(`div`,{className:`flex flex-col gap-3`,children:[L!==null&&L.kind===`device`&&t(m,{className:`text-sm text-primary`,to:L.path,"data-testid":`open-composed-device`,children:T(`compositionEditor.openComposedDevice`,{id:I})}),t(v,{initial:h(F,P.block.name),blockId:P.block.id,deviceType:F.target.type,nativeCaps:null,targetFields:null,onCancel:j,save:async(e,t)=>{try{return await O.mutateAsync({blockId:P.block.id,expectedUpdatedAt:P.block.updatedAt,block:{...C(t),composition:e}}),await A.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:S(e)}}}},`${P.block.id}@${P.block.updatedAt}`)]}))}export{w as CompositionEditorPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Hi as l,Hr as u,It as d,Ki as f,Kr as p,Nt as m,On as h,Pn as g,Q as _,Yr as v,_i as y,_n as b,ai as x,ar as S,di as C,kn as w,nr as T,qi as E,ri as D,rr as O,yi as k}from"./player-overlays-DEJGWVeQ.js";import{n as A,t as j}from"./cloud-upload-BkkCpA1A.js";import{t as M}from"./circle-slash-LeaAcO0Z.js";import{t as N}from"./hard-drive-download-srWFcoIp.js";import{$r as P,An as F,Bc as ee,Bn as I,Dc as L,Dn as te,En as ne,G as R,Gl as z,Ht as B,L as re,Ln as ie,Nr as ae,Qr as oe,R as se,Rc as ce,Rn as le,Tn as ue,Ut as de,Vc as fe,Xl as pe,Xr as me,Yr as he,Zl as V,Zn as H,Zr as ge,ai as _e,an as ve,ar as U,ci as ye,ei as be,el as xe,ii as Se,jn as W,kn as G,li as Ce,ni as we,oi as Te,ri as K,si as Ee,ti as De,ui as Oe,z as ke,zc as Ae}from"./src-CVCI1YgT.js";import{t as je}from"./useTranslation-Bc5yH9V9.js";import"./mount-DSRwVBTr.js";import{C as Me}from"./index-D7FGxQMl.js";import{t as Ne}from"./AdminSectionedPage-Bx9l4jGV.js";import{t as Pe}from"./AdminPage-250c5IIz.js";import{n as Fe}from"./authed-media-CIBSu5eS.js";import{t as q}from"./format-size-DIxKXxtj.js";import{a as Ie,c as Le,l as Re,n as ze,o as Be,s as Ve,t as He,u as Ue}from"./location-owned-usage-CVdW20Z2.js";t();function We(){let e=a(),t=H(),{data:i,isLoading:o,isError:l}=fe({}),u=ee(),d=r(()=>u.data??[],[u.data]),{data:f}=L({},{refetchOnWindowFocus:!1}),p=r(()=>He(i??[],f?.locations),[i,f?.locations]),{data:m}=Ae({},{refetchOnWindowFocus:!1}),h=r(()=>Ie(m),[m]),{state:g,openNew:_,openEdit:v,close:y}=re(),[b,x]=se(`type`),S=()=>{x(null),y()},C=e=>{x(e),_()},w=e=>{x(null),v(e.id)},T=i??[],E=g.mode===`edit`?T.find(e=>e.id===g.id)??null:null;c(()=>{g.mode===`new`&&(b===null||b===``)&&(x(null),y())},[g.mode,b,y,x]),c(()=>{g.mode===`edit`&&!o&&E===null&&(x(null),y())},[g.mode,o,E,y,x]),c(()=>{g.mode===`closed`&&b!==null&&x(null)},[g.mode,b,x]);let D=ce({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),O=xe({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),k=async(e,n)=>{Re(n)&&!await t({title:`Disable "${e.displayName}"?`,message:`${Le(n).consequence}\n\nNothing is deleted — set the location back to Read-only or Active to bring its footage back.`,confirmLabel:`Disable`,variant:`danger`})||O.mutate(Ve(e,{mode:n}))},A=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 D.mutateAsync({id:e.id}),g.mode===`edit`&&g.id===e.id&&S()}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`})&&D.mutate({id:e.id,force:!0},{onSuccess:()=>{g.mode===`edit`&&g.id===e.id&&S()}})}},j=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]),M=o||u.isLoading,N=l||u.isError,P=g.mode===`new`&&b!==null&&b!==``,F=g.mode===`edit`&&E!==null;return n(Pe,{embedded:!0,children:[M&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),N&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!M&&!N&&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(ze,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:j.get(e.id)??[],onAdd:C,onEdit:w,onDelete:e=>{A(e)},ownedBytesById:p,drainById:h,onSetMode:(e,t)=>{k(e,t)}},e.id))]}),P&&b!==null&&s(Ue,{initialType:b,onClose:S,onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),S()}}),F&&E!==null&&s(Be,{location:E,onClose:S,onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),S()}})]})}var Ge={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.`}},Ke=Object.keys(Ge),J=[`settings`],qe=`Created when this feature is enabled`;function Je(e){return Ge[e].label}function Ye(e){return Ge[e].description}function Y(e){let t=new Set(e);return Ke.filter(e=>t.has(e))}function X(e){return e!==void 0&&e.length>0?Y(e):J}function Xe(e){return Y(e)}function Ze(e,t){return t===void 0||!t.answered?`unknown`:t.databases.includes(e)?`present`:`absent`}function Qe(e,t,n){return Ze(e,t)===`absent`&&!n.has(e)}function $e(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function et(e){return!e.includes(`settings`)}function tt(e){return{databases:[...Xe(e)]}}function nt(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(U,{variant:e===`settings`?`primary`:`info`,style:`fill`,size:`sm`,children:Je(e)},e)),et(e)&&s(U,{variant:`warning`,style:`fill`,size:`sm`,children:`Snapshots only`})]})}t();var rt=[[`backup`,`listDestinations`]],it=[`backup`,`listArchives`];function at({destinationId:t,restoreSupported:i,onOpenRestoreWizard:c}){let l=a(),f=H(),{data:p,isLoading:m,isError:h}=De({destinationId:t}),g=p??[],_=me({onSuccess:()=>{l.invalidateQueries({queryKey:[[...it]]}),l.invalidateQueries({queryKey:rt})}}),v=e(async e=>{await f({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})},[f,t,_]),[y,x]=o(null),C=e(async e=>{x(e.id);try{let n=await Fe(ot(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(()=>[...g].toSorted((e,t)=>t.createdAt-e.createdAt),[g]);return m?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):h?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(B,{columns:[{key:`when`,header:`When`,sortValue:e=>e.createdAt,render:e=>s(`span`,{className:`tabular-nums`,children:st(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(T,{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(I,{variant:`ghost`,size:`sm`,onClick:()=>{C(e)},disabled:y===e.id,title:`Download archive`,children:[y===e.id?s(S,{className:`h-3 w-3 animate-spin`}):s(u,{className:`h-3 w-3`}),`Download`]}),i&&c&&n(I,{variant:`ghost`,size:`sm`,onClick:()=>c({destinationId:t,archiveId:e.id}),title:`Restore from this archive`,children:[s(b,{className:`h-3 w-3`}),`Restore`]}),s(V,{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 ot(e,t){return _(`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}function st(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}t();var ct=[[`backup`,`listSchedules`]];function lt({onEdit:t,onOpenRestoreWizard:i}){let{data:a,isLoading:c,isError:l,error:u,refetch:d}=_e(),f=a??[],p=K().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(()=>ut({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(S,{className:`h-3.5 w-3.5 animate-spin`}),`Loading backup entries…`]}):l?s(ie,{title:`Failed to load backup entries`,message:u instanceof Error?u.message:`Unknown error`,onRetry:()=>void d()}):f.length===0?s(le,{icon:A,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(B,{columns:y,rows:f,rowKey:e=>e.id,minWidthPx:980,maxBodyHeight:de,mobileMode:`cards`,emptyMessage:`No backup entries yet`,onRowClick:e=>t(e)}),v!==null&&s(_t,{row:v,destById:m,...i?{onOpenRestoreWizard:i}:{}})]})}function ut(e){return[{key:`expand`,header:``,width:`w-8`,nowrap:!0,notSortableReason:`Expand control`,render:t=>{let n=e.expandedId===t.id;return s(V,{variant:`ghost`,size:`sm`,icon:n?k:y,"aria-label":n?`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(mt,{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(dt,{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(ht,{row:e})})},{key:`schedule`,header:`Schedule`,width:`w-48`,nowrap:!0,sortValue:e=>e.cron,render:e=>s(ft,{row:e})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:t=>s(`span`,{onClick:e=>e.stopPropagation(),children:s(gt,{row:t,onEdit:()=>e.onEdit(t)})})}]}function dt({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 ft({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(A,{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 pt(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 mt({row:e}){let t=a(),n=Oe({onSuccess:()=>{t.invalidateQueries({queryKey:ct})}}),r=pt(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 ht({row:e}){let t=a(),n=Oe({onSuccess:()=>{t.invalidateQueries({queryKey:ct})}}),r=pt(e),[i,l]=o(String(e.retentionCount));return c(()=>{l(String(e.retentionCount))},[e.retentionCount]),s(pe,{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 gt({row:e,onEdit:t}){let r=a(),i=H(),o=ge({onSuccess:()=>{r.invalidateQueries({queryKey:ct})}}),c=Ce({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(I,{size:`sm`,type:`button`,onClick:l,disabled:c.isPending||e.locationIds.length===0,title:`Run this entry now`,children:[c.isPending?s(S,{className:`h-3 w-3 animate-spin`}):s(w,{className:`h-3 w-3`}),`Run now`]}),s(V,{variant:`ghost`,size:`sm`,icon:g,"aria-label":`Edit ${e.label||e.id}`,onClick:t}),s(V,{variant:`ghost`,size:`sm`,icon:d,"aria-label":`Delete ${e.label||e.id}`,disabled:o.isPending,onClick:()=>{u()}})]})}function _t({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(at,{destinationId:e,restoreSupported:t.get(e)?.restoreSupported??!0,...r?{onOpenRestoreWizard:r}:{}})]},e))]})}function vt({selected:e,onChange:t,disabled:r=!1,testId:i=`backup-databases`}){let a=we().data,o=e.size>0&&et(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(R,{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:Ke.map(o=>{let c=Ze(o,a),l=r||Qe(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(ve,{checked:e.has(o),disabled:l,onChange:()=>t($e(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:[Je(o),c===`absent`&&s(U,{variant:`neutral`,size:`sm`,children:`Not created yet`})]}),s(`span`,{className:`block text-[11px] text-foreground-subtle`,children:c===`absent`?qe:Ye(o)})]})]},o)})})})}t();function yt({onClose:e}){let t=a(),[r,i]=o(new Set(J)),c=Ce({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(ue,{open:!0,onOpenChange:t=>!t&&e(),children:n(te,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[n(F,{children:[s(W,{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(ne,{children:n(`div`,{className:`p-4`,children:[s(vt,{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(G,{children:[s(I,{variant:`outline`,size:`sm`,onClick:e,children:`Cancel`}),n(I,{size:`sm`,onClick:()=>{r.size!==0&&c.mutate(tt(r))},disabled:r.size===0||c.isPending,"data-testid":`backup-now-run`,children:[c.isPending?s(S,{className:`h-3.5 w-3.5 animate-spin`}):s(w,{className:`h-3.5 w-3.5`}),`Back up now`]})]})]})})}t();function bt(e){return e===null?`—`:new Date(e).toLocaleString()}function xt(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 St({revealed:e,onDone:t}){let[r,i]=o(!1),[a,c]=o(!1);return s(ue,{open:!0,onOpenChange:e=>!e&&r&&t(),children:n(te,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`border-danger/40`,"aria-labelledby":`backup-key-title`,children:[s(F,{children:n(W,{id:`backup-key-title`,children:[`Your backup key (`,e.keyId,`)`]})}),n(ne,{className:`space-y-3`,children:[n(`p`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 p-2 text-xs text-foreground`,children:[s(m,{className:`mt-0.5 h-4 w-4 shrink-0 text-danger`}),s(`span`,{children:`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(I,{size:`sm`,variant:`outline`,onClick:()=>{navigator.clipboard?.writeText(e.secretKey).then(()=>c(!0))},children:[s(v,{className:`mr-1 h-3.5 w-3.5`}),a?`Copied`:`Copy`]}),n(I,{size:`sm`,variant:`outline`,onClick:()=>xt(e),children:[s(u,{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(G,{children:s(I,{size:`sm`,disabled:!r,onClick:t,children:`I have stored it`})})]})})}function Ct(){let e=P(),t=ye(),r=oe(),a=H(),[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))}}},g=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(T,{className:`h-4 w-4 text-success`}):s(O,{className:`h-4 w-4 text-foreground-subtle`}),s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Encryption`}),s(`span`,{className:`text-xs text-foreground-subtle`,children:f&&p!==null?`On — key ${p.keyId}, since ${bt(p.createdAt)}`:`Off — backups are not encrypted`})]}),s(`div`,{className:`flex gap-2`,children:f?n(i,{children:[s(I,{size:`sm`,variant:`outline`,disabled:t.isPending,onClick:()=>void h(),children:`Replace key`}),s(I,{size:`sm`,variant:`outline`,disabled:r.isPending,onClick:()=>void g(),children:`Turn off`})]}):s(I,{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,` · `,bt(e.createdAt),` → `,bt(e.retiredAt)]},e.keyId))})]}),u!==null&&s(`p`,{className:`text-xs text-danger`,children:u}),c!==null&&s(St,{revealed:c,onDone:()=>{l(null),e.refetch()}})]})}t();var wt=[{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 Tt(e){let t=e.trim();for(let e of wt)if(e.cron===t)return e.id;return`custom`}function Et({value:e,onChange:t,previewCount:r=5,disabled:i=!1}){let a=Tt(e),[l,u]=o(a===`custom`);c(()=>{a!==`custom`&&u(!1)},[a]);let d=kt(e,250),f=Te({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:[wt.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(Dt,{cron:d,preview:p,loading:f.isFetching})]})}function Dt({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(S,{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:Ot(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 Ot(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 kt(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 At=[[`backup`,`listSchedules`]];function jt({entry:e,onClose:t,onSaved:i}){let c=a(),l=K(),u=l.data??[],[d,f]=o(e?.label??``),[p,m]=o(e?.cron??`0 3 * * *`),[h,g]=o(e?.enabled??!0),[_,v]=o(String(e?.retentionCount??7)),[y,b]=o(new Set(e?.locationIds??[])),[x,C]=o(new Set(e===null?J:X(e.databases))),w=Oe({onSuccess:()=>{c.invalidateQueries({queryKey:At}),i()}}),T=e=>{b(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},E=Number.parseInt(_,10),D=r(()=>d.trim().length>0&&y.size>0&&x.size>0&&!Number.isNaN(E)&&E>=1&&E<=1e3,[d,y,x,E]),O=()=>{D&&w.mutate({...e?{id:e.id}:{},label:d.trim(),cron:p.trim(),enabled:h,locationIds:Array.from(y),retentionCount:E,databases:[...Xe(x)]})},k=w.error instanceof Error?w.error.message:null;return s(ke,{open:!0,onClose:t,title:e?`Edit backup entry`:`New backup entry`,icon:A,error:k,width:`lg`,testId:`backup-entry-form`,footer:n(I,{size:`sm`,type:`button`,onClick:O,disabled:!D||w.isPending,children:[w.isPending?s(S,{className:`h-3.5 w-3.5 animate-spin`}):null,e?`Save`:`Create entry`]}),children:n(`div`,{className:`space-y-4`,children:[s(R,{label:`Name`,required:!0,children:s(pe,{value:d,onChange:e=>f(e.target.value),placeholder:`Nightly offsite`,autoFocus:!0,"data-testid":`backup-entry-name`})}),n(R,{label:`Locations (${String(y.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(S,{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:y.has(e.id),onChange:()=>T(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(vt,{selected:x,onChange:C,disabled:w.isPending,testId:`backup-entry-databases`}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[s(R,{label:`Retention (archives kept)`,required:!0,children:s(pe,{type:`number`,min:1,max:1e3,value:_,onChange:e=>v(e.target.value),"data-testid":`backup-entry-retention`})}),s(R,{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(R,{label:`Schedule`,children:s(Et,{value:p,onChange:m,disabled:w.isPending})})]})})}t();var Mt=2e3,Nt=5e3;function Q(e){return e.state===`queued`||e.state===`running`}function Pt(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 Ft(){let t=H(),[n,r]=o(null),i=Se(void 0,{refetchInterval:e=>(e.state.data??[]).some(Q)?Mt:Nt}),a=he({onSettled:()=>{r(null),i.refetch()}}),c=e(async e=>{await t(Pt(e))&&(r(e.id),a.mutate({runId:e.id}))},[t,a]);return s(It,{queryState:i.isError?`error`:i.data===void 0?`pending`:`ready`,runs:i.data??[],cancelingId:n,onCancelRequest:e=>{c(e)},now:Date.now()})}function It({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(Lt,{run:e,canceling:r===e.id,onCancelRequest:i,now:a},e.id))})]})})]})}function Lt({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(Rt,{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(zt,{run:e})}),s(`td`,{className:`px-3 py-2`,children:s(Bt,{run:e})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle tabular-nums`,children:s(Vt,{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(S,{className:`h-3 w-3 animate-spin`}):s(l,{className:`h-3 w-3`}),e.state===`queued`?`Cancel`:`Stop`]})})})]})}function Rt({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(D,{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(S,{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(C,{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(x,{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(M,{className:`h-3 w-3`}),`Stopped`]})}}function zt({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:Ht(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(N,{className:`h-3 w-3 text-primary`}),s(`span`,{className:`tabular-nums font-medium animate-pulse`,children:q(e.stagedBytes)}),s(`span`,{className:`text-foreground-subtle`,children:`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(j,{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 Bt({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 Vt({run:e,now:t}){return e.state===`queued`?n(`span`,{children:[`queued `,Ut(t-e.requestedAt),` ago`]}):e.startedAt===void 0?s(`span`,{children:`—`}):e.finishedAt===void 0?n(`span`,{children:[`running for `,Ut(t-e.startedAt)]}):n(`div`,{className:`flex flex-col gap-0.5`,children:[s(`span`,{children:Wt(e.finishedAt)}),n(`span`,{className:`text-[10px]`,children:[`took `,Ut(e.finishedAt-e.startedAt)]})]})}function Ht(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 Ut(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 Wt(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}t();var Gt=[[`backup`,`list`]];function Kt({initialDestinationId:e,initialArchiveId:t,onClose:i,onScheduled:l}){let u=a(),[d,p]=o(e&&t?2:1),[m,h]=o(e),[g,_]=o(t),[v,y]=o(new Set),[x,C]=o(``),{data:w}=K(),T=w??[],{data:D,isLoading:O}=De({destinationId:m??``},{enabled:!!m}),k=D??[];c(()=>{if(m!==void 0)return;let e=T.filter(e=>e.restoreSupported);e.length===1&&h(e[0].id)},[m,T]);let{data:A}=be({destinationId:m??``,backupId:g??``},{enabled:!!m&&!!g}),j=r(()=>A?.locations??[],[A]);c(()=>{j.length!==0&&y(e=>e.size===0?new Set(j):e)},[j]);let M=Ee({onSuccess:()=>{u.invalidateQueries({queryKey:Gt}),l(),i()}}),N=e=>{y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},P=k.find(e=>e.id===g),ee=P?.encryption!==void 0,L=nt(P?.databases,A?.sqliteSnapshots),R=et(L),z=!!m&&!!g,B=R||v.size>0,re=z&&B&&!M.isPending&&(!ee||x.trim().length>0),ie=()=>{!m||!g||M.mutate({destinationId:m,backupId:g,...R?{}:{locations:[...v]},...ee?{backupSecretKey:x.trim()}:{}})};return s(ue,{open:!0,onOpenChange:e=>!e&&i(),children:n(te,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[n(F,{children:[s(W,{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(ne,{children:[d===1&&s(qt,{destinations:T,destinationId:m,onPickDestination:e=>{h(e),_(void 0),y(new Set)},archives:k,archivesLoading:O,archiveId:g,onPickArchive:_}),d===2&&s(Jt,{locations:j,picked:v,onToggle:N,databases:L,snapshotsOnly:R}),d===3&&s(Yt,{destinationName:T.find(e=>e.id===m)?.displayName??m??``,archive:P,picked:[...v],databases:L,snapshotsOnly:R}),d===3&&P?.encryption!==void 0&&s(Xt,{keyId:P.encryption.keyId,value:x,onChange:C}),d===3&&M.error&&s(`p`,{role:`alert`,className:`px-4 pb-2 text-xs text-danger`,children:M.error.message})]}),n(G,{className:`justify-between`,children:[s(`div`,{children:d>1&&n(I,{variant:`outline`,size:`sm`,onClick:()=>p(e=>e===3?2:1),children:[s(E,{className:`h-3 w-3`}),`Back`]})}),n(`div`,{className:`flex items-center gap-2`,children:[s(I,{variant:`outline`,size:`sm`,onClick:i,children:`Cancel`}),d<3?n(I,{size:`sm`,disabled:d===1&&!z||d===2&&!B,onClick:()=>p(e=>e===1?2:3),children:[`Next`,s(f,{className:`h-3 w-3`})]}):n(I,{size:`sm`,onClick:ie,disabled:!re,children:[M.isPending?s(S,{className:`h-3.5 w-3.5 animate-spin`}):s(b,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function qt({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(z,{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(T,{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:nt(e.databases,void 0)})})]})]}),s(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:q(e.sizeBytes)})]},e.id)})})]})]})}function Jt({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:Qt(e)})]},e))})]})]})}function Yt({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=>Je(e)).join(`, `)}),s($,{term:`Locations`,value:a?`none (configuration is not touched)`:r.length>0?r.join(`, `):`— (full archive)`})]})]})}function Xt({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 Zt={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function Qt(e){return Zt[e]??``}t();function $t(){let e=H(),t=ae(),{state:r,openNew:i,openEdit:a,close:l}=re({editKey:`edit`,newKey:`new`}),u=_e(),d=u.data??[],[f,p]=o(null),[m,g]=o(!1),[_,v]=o(!1),[y,x]=o(!1),C=r.mode===`edit`?d.find(e=>e.id===r.id)??null:null;c(()=>{r.mode===`edit`&&!u.isLoading&&C===null&&l()},[r.mode,u.isLoading,C,l]);let T=r.mode===`new`||r.mode===`edit`&&C!==null,E=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(Pe,{embedded:!0,children:[n(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,"data-testid":`backup-actions`,children:[n(I,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>x(!0),"data-testid":`backup-now`,children:[s(w,{className:`h-3.5 w-3.5`}),`Back up now`]}),n(I,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>g(!0),children:[s(b,{className:`h-3.5 w-3.5`}),`Restore…`]}),n(I,{size:`sm`,type:`button`,onClick:i,"data-testid":`backup-new-entry`,children:[s(h,{className:`h-3.5 w-3.5`}),`New entry`]})]}),_&&s(`div`,{className:`rounded-lg border border-warning/30 bg-warning/10 px-3 py-2.5 text-xs text-warning`,children:n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(b,{className:`h-3.5 w-3.5`}),s(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),n(I,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>{E()},disabled:t.isPending,children:[t.isPending?s(S,{className:`h-3.5 w-3.5 animate-spin`}):s(b,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),s(Ct,{}),s(Ft,{}),s(lt,{onEdit:e=>a(e.id),onOpenRestoreWizard:e=>p(e)}),T&&s(jt,{entry:C,onClose:l,onSaved:l}),y&&s(yt,{onClose:()=>x(!1)}),(f||m)&&s(Kt,{...f?{initialDestinationId:f.destinationId,initialArchiveId:f.archiveId}:{},onClose:()=>{p(null),g(!1)},onScheduled:()=>v(!0)})]})}function en(){let{t:e}=je(),t=Me(`/system/data`,{t:e,isAdmin:!0})??{icon:p,title:e(`system.data`,`Data`)};return s(Ne,{icon:t.icon,title:t.title,defaultSection:`storage`,sectionsLabel:`${t.title} sections`,sections:[{id:`storage`,label:`Storage`,content:s(We,{})},{id:`backup`,label:`Backup`,content:s($t,{})}]})}export{en as DataPage};
|
|
1
|
+
import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Hi as l,Hr as u,It as d,Ki as f,Kr as p,Nt as m,On as h,Pn as g,Q as _,Yr as v,_i as y,_n as b,ai as x,ar as S,di as C,kn as w,nr as T,qi as E,ri as D,rr as O,yi as k}from"./player-overlays-DWMIy1MJ.js";import{n as A,t as j}from"./cloud-upload-BsULjxPu.js";import{t as M}from"./circle-slash-DpUtlEnB.js";import{t as N}from"./hard-drive-download-CKj8xKOz.js";import{$r as P,An as F,Bc as ee,Bn as I,Dc as L,Dn as te,En as ne,G as R,Gl as z,Ht as B,L as re,Ln as ie,Nr as ae,Qr as oe,R as se,Rc as ce,Rn as le,Tn as ue,Ut as de,Vc as fe,Xl as pe,Xr as me,Yr as he,Zl as V,Zn as H,Zr as ge,ai as _e,an as ve,ar as U,ci as ye,ei as be,el as xe,ii as Se,jn as W,kn as G,li as Ce,ni as we,oi as Te,ri as K,si as Ee,ti as De,ui as Oe,z as ke,zc as Ae}from"./src-BLkInT8U.js";import{t as je}from"./useTranslation-Bc5yH9V9.js";import"./mount-1Z6p3UkP.js";import{S as Me}from"./index-D66JvELZ.js";import{t as Ne}from"./AdminSectionedPage-D2kYQhvu.js";import{t as Pe}from"./AdminPage-C0Zxs_ot.js";import{n as Fe}from"./authed-media-0TPg9TTZ.js";import{t as q}from"./format-size-DIxKXxtj.js";import{a as Ie,c as Le,l as Re,n as ze,o as Be,s as Ve,t as He,u as Ue}from"./location-owned-usage-CNXQ-Obv.js";t();function We(){let e=a(),t=H(),{data:i,isLoading:o,isError:l}=fe({}),u=ee(),d=r(()=>u.data??[],[u.data]),{data:f}=L({},{refetchOnWindowFocus:!1}),p=r(()=>He(i??[],f?.locations),[i,f?.locations]),{data:m}=Ae({},{refetchOnWindowFocus:!1}),h=r(()=>Ie(m),[m]),{state:g,openNew:_,openEdit:v,close:y}=re(),[b,x]=se(`type`),S=()=>{x(null),y()},C=e=>{x(e),_()},w=e=>{x(null),v(e.id)},T=i??[],E=g.mode===`edit`?T.find(e=>e.id===g.id)??null:null;c(()=>{g.mode===`new`&&(b===null||b===``)&&(x(null),y())},[g.mode,b,y,x]),c(()=>{g.mode===`edit`&&!o&&E===null&&(x(null),y())},[g.mode,o,E,y,x]),c(()=>{g.mode===`closed`&&b!==null&&x(null)},[g.mode,b,x]);let D=ce({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),O=xe({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),k=async(e,n)=>{Re(n)&&!await t({title:`Disable "${e.displayName}"?`,message:`${Le(n).consequence}\n\nNothing is deleted — set the location back to Read-only or Active to bring its footage back.`,confirmLabel:`Disable`,variant:`danger`})||O.mutate(Ve(e,{mode:n}))},A=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 D.mutateAsync({id:e.id}),g.mode===`edit`&&g.id===e.id&&S()}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`})&&D.mutate({id:e.id,force:!0},{onSuccess:()=>{g.mode===`edit`&&g.id===e.id&&S()}})}},j=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]),M=o||u.isLoading,N=l||u.isError,P=g.mode===`new`&&b!==null&&b!==``,F=g.mode===`edit`&&E!==null;return n(Pe,{embedded:!0,children:[M&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),N&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!M&&!N&&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(ze,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:j.get(e.id)??[],onAdd:C,onEdit:w,onDelete:e=>{A(e)},ownedBytesById:p,drainById:h,onSetMode:(e,t)=>{k(e,t)}},e.id))]}),P&&b!==null&&s(Ue,{initialType:b,onClose:S,onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),S()}}),F&&E!==null&&s(Be,{location:E,onClose:S,onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),S()}})]})}var Ge={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.`}},Ke=Object.keys(Ge),J=[`settings`],qe=`Created when this feature is enabled`;function Je(e){return Ge[e].label}function Ye(e){return Ge[e].description}function Y(e){let t=new Set(e);return Ke.filter(e=>t.has(e))}function X(e){return e!==void 0&&e.length>0?Y(e):J}function Xe(e){return Y(e)}function Ze(e,t){return t===void 0||!t.answered?`unknown`:t.databases.includes(e)?`present`:`absent`}function Qe(e,t,n){return Ze(e,t)===`absent`&&!n.has(e)}function $e(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function et(e){return!e.includes(`settings`)}function tt(e){return{databases:[...Xe(e)]}}function nt(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(U,{variant:e===`settings`?`primary`:`info`,style:`fill`,size:`sm`,children:Je(e)},e)),et(e)&&s(U,{variant:`warning`,style:`fill`,size:`sm`,children:`Snapshots only`})]})}t();var rt=[[`backup`,`listDestinations`]],it=[`backup`,`listArchives`];function at({destinationId:t,restoreSupported:i,onOpenRestoreWizard:c}){let l=a(),f=H(),{data:p,isLoading:m,isError:h}=De({destinationId:t}),g=p??[],_=me({onSuccess:()=>{l.invalidateQueries({queryKey:[[...it]]}),l.invalidateQueries({queryKey:rt})}}),v=e(async e=>{await f({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})},[f,t,_]),[y,x]=o(null),C=e(async e=>{x(e.id);try{let n=await Fe(ot(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(()=>[...g].toSorted((e,t)=>t.createdAt-e.createdAt),[g]);return m?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):h?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(B,{columns:[{key:`when`,header:`When`,sortValue:e=>e.createdAt,render:e=>s(`span`,{className:`tabular-nums`,children:st(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(T,{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(I,{variant:`ghost`,size:`sm`,onClick:()=>{C(e)},disabled:y===e.id,title:`Download archive`,children:[y===e.id?s(S,{className:`h-3 w-3 animate-spin`}):s(u,{className:`h-3 w-3`}),`Download`]}),i&&c&&n(I,{variant:`ghost`,size:`sm`,onClick:()=>c({destinationId:t,archiveId:e.id}),title:`Restore from this archive`,children:[s(b,{className:`h-3 w-3`}),`Restore`]}),s(V,{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 ot(e,t){return _(`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}function st(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}t();var ct=[[`backup`,`listSchedules`]];function lt({onEdit:t,onOpenRestoreWizard:i}){let{data:a,isLoading:c,isError:l,error:u,refetch:d}=_e(),f=a??[],p=K().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(()=>ut({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(S,{className:`h-3.5 w-3.5 animate-spin`}),`Loading backup entries…`]}):l?s(ie,{title:`Failed to load backup entries`,message:u instanceof Error?u.message:`Unknown error`,onRetry:()=>void d()}):f.length===0?s(le,{icon:A,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(B,{columns:y,rows:f,rowKey:e=>e.id,minWidthPx:980,maxBodyHeight:de,mobileMode:`cards`,emptyMessage:`No backup entries yet`,onRowClick:e=>t(e)}),v!==null&&s(_t,{row:v,destById:m,...i?{onOpenRestoreWizard:i}:{}})]})}function ut(e){return[{key:`expand`,header:``,width:`w-8`,nowrap:!0,notSortableReason:`Expand control`,render:t=>{let n=e.expandedId===t.id;return s(V,{variant:`ghost`,size:`sm`,icon:n?k:y,"aria-label":n?`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(mt,{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(dt,{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(ht,{row:e})})},{key:`schedule`,header:`Schedule`,width:`w-48`,nowrap:!0,sortValue:e=>e.cron,render:e=>s(ft,{row:e})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:t=>s(`span`,{onClick:e=>e.stopPropagation(),children:s(gt,{row:t,onEdit:()=>e.onEdit(t)})})}]}function dt({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 ft({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(A,{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 pt(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 mt({row:e}){let t=a(),n=Oe({onSuccess:()=>{t.invalidateQueries({queryKey:ct})}}),r=pt(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 ht({row:e}){let t=a(),n=Oe({onSuccess:()=>{t.invalidateQueries({queryKey:ct})}}),r=pt(e),[i,l]=o(String(e.retentionCount));return c(()=>{l(String(e.retentionCount))},[e.retentionCount]),s(pe,{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 gt({row:e,onEdit:t}){let r=a(),i=H(),o=ge({onSuccess:()=>{r.invalidateQueries({queryKey:ct})}}),c=Ce({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(I,{size:`sm`,type:`button`,onClick:l,disabled:c.isPending||e.locationIds.length===0,title:`Run this entry now`,children:[c.isPending?s(S,{className:`h-3 w-3 animate-spin`}):s(w,{className:`h-3 w-3`}),`Run now`]}),s(V,{variant:`ghost`,size:`sm`,icon:g,"aria-label":`Edit ${e.label||e.id}`,onClick:t}),s(V,{variant:`ghost`,size:`sm`,icon:d,"aria-label":`Delete ${e.label||e.id}`,disabled:o.isPending,onClick:()=>{u()}})]})}function _t({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(at,{destinationId:e,restoreSupported:t.get(e)?.restoreSupported??!0,...r?{onOpenRestoreWizard:r}:{}})]},e))]})}function vt({selected:e,onChange:t,disabled:r=!1,testId:i=`backup-databases`}){let a=we().data,o=e.size>0&&et(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(R,{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:Ke.map(o=>{let c=Ze(o,a),l=r||Qe(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(ve,{checked:e.has(o),disabled:l,onChange:()=>t($e(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:[Je(o),c===`absent`&&s(U,{variant:`neutral`,size:`sm`,children:`Not created yet`})]}),s(`span`,{className:`block text-[11px] text-foreground-subtle`,children:c===`absent`?qe:Ye(o)})]})]},o)})})})}t();function yt({onClose:e}){let t=a(),[r,i]=o(new Set(J)),c=Ce({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(ue,{open:!0,onOpenChange:t=>!t&&e(),children:n(te,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[n(F,{children:[s(W,{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(ne,{children:n(`div`,{className:`p-4`,children:[s(vt,{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(G,{children:[s(I,{variant:`outline`,size:`sm`,onClick:e,children:`Cancel`}),n(I,{size:`sm`,onClick:()=>{r.size!==0&&c.mutate(tt(r))},disabled:r.size===0||c.isPending,"data-testid":`backup-now-run`,children:[c.isPending?s(S,{className:`h-3.5 w-3.5 animate-spin`}):s(w,{className:`h-3.5 w-3.5`}),`Back up now`]})]})]})})}t();function bt(e){return e===null?`—`:new Date(e).toLocaleString()}function xt(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 St({revealed:e,onDone:t}){let[r,i]=o(!1),[a,c]=o(!1);return s(ue,{open:!0,onOpenChange:e=>!e&&r&&t(),children:n(te,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`border-danger/40`,"aria-labelledby":`backup-key-title`,children:[s(F,{children:n(W,{id:`backup-key-title`,children:[`Your backup key (`,e.keyId,`)`]})}),n(ne,{className:`space-y-3`,children:[n(`p`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 p-2 text-xs text-foreground`,children:[s(m,{className:`mt-0.5 h-4 w-4 shrink-0 text-danger`}),s(`span`,{children:`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(I,{size:`sm`,variant:`outline`,onClick:()=>{navigator.clipboard?.writeText(e.secretKey).then(()=>c(!0))},children:[s(v,{className:`mr-1 h-3.5 w-3.5`}),a?`Copied`:`Copy`]}),n(I,{size:`sm`,variant:`outline`,onClick:()=>xt(e),children:[s(u,{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(G,{children:s(I,{size:`sm`,disabled:!r,onClick:t,children:`I have stored it`})})]})})}function Ct(){let e=P(),t=ye(),r=oe(),a=H(),[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))}}},g=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(T,{className:`h-4 w-4 text-success`}):s(O,{className:`h-4 w-4 text-foreground-subtle`}),s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Encryption`}),s(`span`,{className:`text-xs text-foreground-subtle`,children:f&&p!==null?`On — key ${p.keyId}, since ${bt(p.createdAt)}`:`Off — backups are not encrypted`})]}),s(`div`,{className:`flex gap-2`,children:f?n(i,{children:[s(I,{size:`sm`,variant:`outline`,disabled:t.isPending,onClick:()=>void h(),children:`Replace key`}),s(I,{size:`sm`,variant:`outline`,disabled:r.isPending,onClick:()=>void g(),children:`Turn off`})]}):s(I,{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,` · `,bt(e.createdAt),` → `,bt(e.retiredAt)]},e.keyId))})]}),u!==null&&s(`p`,{className:`text-xs text-danger`,children:u}),c!==null&&s(St,{revealed:c,onDone:()=>{l(null),e.refetch()}})]})}t();var wt=[{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 Tt(e){let t=e.trim();for(let e of wt)if(e.cron===t)return e.id;return`custom`}function Et({value:e,onChange:t,previewCount:r=5,disabled:i=!1}){let a=Tt(e),[l,u]=o(a===`custom`);c(()=>{a!==`custom`&&u(!1)},[a]);let d=kt(e,250),f=Te({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:[wt.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(Dt,{cron:d,preview:p,loading:f.isFetching})]})}function Dt({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(S,{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:Ot(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 Ot(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 kt(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 At=[[`backup`,`listSchedules`]];function jt({entry:e,onClose:t,onSaved:i}){let c=a(),l=K(),u=l.data??[],[d,f]=o(e?.label??``),[p,m]=o(e?.cron??`0 3 * * *`),[h,g]=o(e?.enabled??!0),[_,v]=o(String(e?.retentionCount??7)),[y,b]=o(new Set(e?.locationIds??[])),[x,C]=o(new Set(e===null?J:X(e.databases))),w=Oe({onSuccess:()=>{c.invalidateQueries({queryKey:At}),i()}}),T=e=>{b(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},E=Number.parseInt(_,10),D=r(()=>d.trim().length>0&&y.size>0&&x.size>0&&!Number.isNaN(E)&&E>=1&&E<=1e3,[d,y,x,E]),O=()=>{D&&w.mutate({...e?{id:e.id}:{},label:d.trim(),cron:p.trim(),enabled:h,locationIds:Array.from(y),retentionCount:E,databases:[...Xe(x)]})},k=w.error instanceof Error?w.error.message:null;return s(ke,{open:!0,onClose:t,title:e?`Edit backup entry`:`New backup entry`,icon:A,error:k,width:`lg`,testId:`backup-entry-form`,footer:n(I,{size:`sm`,type:`button`,onClick:O,disabled:!D||w.isPending,children:[w.isPending?s(S,{className:`h-3.5 w-3.5 animate-spin`}):null,e?`Save`:`Create entry`]}),children:n(`div`,{className:`space-y-4`,children:[s(R,{label:`Name`,required:!0,children:s(pe,{value:d,onChange:e=>f(e.target.value),placeholder:`Nightly offsite`,autoFocus:!0,"data-testid":`backup-entry-name`})}),n(R,{label:`Locations (${String(y.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(S,{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:y.has(e.id),onChange:()=>T(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(vt,{selected:x,onChange:C,disabled:w.isPending,testId:`backup-entry-databases`}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[s(R,{label:`Retention (archives kept)`,required:!0,children:s(pe,{type:`number`,min:1,max:1e3,value:_,onChange:e=>v(e.target.value),"data-testid":`backup-entry-retention`})}),s(R,{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(R,{label:`Schedule`,children:s(Et,{value:p,onChange:m,disabled:w.isPending})})]})})}t();var Mt=2e3,Nt=5e3;function Q(e){return e.state===`queued`||e.state===`running`}function Pt(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 Ft(){let t=H(),[n,r]=o(null),i=Se(void 0,{refetchInterval:e=>(e.state.data??[]).some(Q)?Mt:Nt}),a=he({onSettled:()=>{r(null),i.refetch()}}),c=e(async e=>{await t(Pt(e))&&(r(e.id),a.mutate({runId:e.id}))},[t,a]);return s(It,{queryState:i.isError?`error`:i.data===void 0?`pending`:`ready`,runs:i.data??[],cancelingId:n,onCancelRequest:e=>{c(e)},now:Date.now()})}function It({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(Lt,{run:e,canceling:r===e.id,onCancelRequest:i,now:a},e.id))})]})})]})}function Lt({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(Rt,{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(zt,{run:e})}),s(`td`,{className:`px-3 py-2`,children:s(Bt,{run:e})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle tabular-nums`,children:s(Vt,{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(S,{className:`h-3 w-3 animate-spin`}):s(l,{className:`h-3 w-3`}),e.state===`queued`?`Cancel`:`Stop`]})})})]})}function Rt({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(D,{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(S,{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(C,{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(x,{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(M,{className:`h-3 w-3`}),`Stopped`]})}}function zt({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:Ht(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(N,{className:`h-3 w-3 text-primary`}),s(`span`,{className:`tabular-nums font-medium animate-pulse`,children:q(e.stagedBytes)}),s(`span`,{className:`text-foreground-subtle`,children:`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(j,{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 Bt({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 Vt({run:e,now:t}){return e.state===`queued`?n(`span`,{children:[`queued `,Ut(t-e.requestedAt),` ago`]}):e.startedAt===void 0?s(`span`,{children:`—`}):e.finishedAt===void 0?n(`span`,{children:[`running for `,Ut(t-e.startedAt)]}):n(`div`,{className:`flex flex-col gap-0.5`,children:[s(`span`,{children:Wt(e.finishedAt)}),n(`span`,{className:`text-[10px]`,children:[`took `,Ut(e.finishedAt-e.startedAt)]})]})}function Ht(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 Ut(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 Wt(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}t();var Gt=[[`backup`,`list`]];function Kt({initialDestinationId:e,initialArchiveId:t,onClose:i,onScheduled:l}){let u=a(),[d,p]=o(e&&t?2:1),[m,h]=o(e),[g,_]=o(t),[v,y]=o(new Set),[x,C]=o(``),{data:w}=K(),T=w??[],{data:D,isLoading:O}=De({destinationId:m??``},{enabled:!!m}),k=D??[];c(()=>{if(m!==void 0)return;let e=T.filter(e=>e.restoreSupported);e.length===1&&h(e[0].id)},[m,T]);let{data:A}=be({destinationId:m??``,backupId:g??``},{enabled:!!m&&!!g}),j=r(()=>A?.locations??[],[A]);c(()=>{j.length!==0&&y(e=>e.size===0?new Set(j):e)},[j]);let M=Ee({onSuccess:()=>{u.invalidateQueries({queryKey:Gt}),l(),i()}}),N=e=>{y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},P=k.find(e=>e.id===g),ee=P?.encryption!==void 0,L=nt(P?.databases,A?.sqliteSnapshots),R=et(L),z=!!m&&!!g,B=R||v.size>0,re=z&&B&&!M.isPending&&(!ee||x.trim().length>0),ie=()=>{!m||!g||M.mutate({destinationId:m,backupId:g,...R?{}:{locations:[...v]},...ee?{backupSecretKey:x.trim()}:{}})};return s(ue,{open:!0,onOpenChange:e=>!e&&i(),children:n(te,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[n(F,{children:[s(W,{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(ne,{children:[d===1&&s(qt,{destinations:T,destinationId:m,onPickDestination:e=>{h(e),_(void 0),y(new Set)},archives:k,archivesLoading:O,archiveId:g,onPickArchive:_}),d===2&&s(Jt,{locations:j,picked:v,onToggle:N,databases:L,snapshotsOnly:R}),d===3&&s(Yt,{destinationName:T.find(e=>e.id===m)?.displayName??m??``,archive:P,picked:[...v],databases:L,snapshotsOnly:R}),d===3&&P?.encryption!==void 0&&s(Xt,{keyId:P.encryption.keyId,value:x,onChange:C}),d===3&&M.error&&s(`p`,{role:`alert`,className:`px-4 pb-2 text-xs text-danger`,children:M.error.message})]}),n(G,{className:`justify-between`,children:[s(`div`,{children:d>1&&n(I,{variant:`outline`,size:`sm`,onClick:()=>p(e=>e===3?2:1),children:[s(E,{className:`h-3 w-3`}),`Back`]})}),n(`div`,{className:`flex items-center gap-2`,children:[s(I,{variant:`outline`,size:`sm`,onClick:i,children:`Cancel`}),d<3?n(I,{size:`sm`,disabled:d===1&&!z||d===2&&!B,onClick:()=>p(e=>e===1?2:3),children:[`Next`,s(f,{className:`h-3 w-3`})]}):n(I,{size:`sm`,onClick:ie,disabled:!re,children:[M.isPending?s(S,{className:`h-3.5 w-3.5 animate-spin`}):s(b,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function qt({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(z,{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(T,{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:nt(e.databases,void 0)})})]})]}),s(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:q(e.sizeBytes)})]},e.id)})})]})]})}function Jt({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:Qt(e)})]},e))})]})]})}function Yt({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=>Je(e)).join(`, `)}),s($,{term:`Locations`,value:a?`none (configuration is not touched)`:r.length>0?r.join(`, `):`— (full archive)`})]})]})}function Xt({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 Zt={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function Qt(e){return Zt[e]??``}t();function $t(){let e=H(),t=ae(),{state:r,openNew:i,openEdit:a,close:l}=re({editKey:`edit`,newKey:`new`}),u=_e(),d=u.data??[],[f,p]=o(null),[m,g]=o(!1),[_,v]=o(!1),[y,x]=o(!1),C=r.mode===`edit`?d.find(e=>e.id===r.id)??null:null;c(()=>{r.mode===`edit`&&!u.isLoading&&C===null&&l()},[r.mode,u.isLoading,C,l]);let T=r.mode===`new`||r.mode===`edit`&&C!==null,E=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(Pe,{embedded:!0,children:[n(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,"data-testid":`backup-actions`,children:[n(I,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>x(!0),"data-testid":`backup-now`,children:[s(w,{className:`h-3.5 w-3.5`}),`Back up now`]}),n(I,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>g(!0),children:[s(b,{className:`h-3.5 w-3.5`}),`Restore…`]}),n(I,{size:`sm`,type:`button`,onClick:i,"data-testid":`backup-new-entry`,children:[s(h,{className:`h-3.5 w-3.5`}),`New entry`]})]}),_&&s(`div`,{className:`rounded-lg border border-warning/30 bg-warning/10 px-3 py-2.5 text-xs text-warning`,children:n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(b,{className:`h-3.5 w-3.5`}),s(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),n(I,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>{E()},disabled:t.isPending,children:[t.isPending?s(S,{className:`h-3.5 w-3.5 animate-spin`}):s(b,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),s(Ct,{}),s(Ft,{}),s(lt,{onEdit:e=>a(e.id),onOpenRestoreWizard:e=>p(e)}),T&&s(jt,{entry:C,onClose:l,onSaved:l}),y&&s(yt,{onClose:()=>x(!1)}),(f||m)&&s(Kt,{...f?{initialDestinationId:f.destinationId,initialArchiveId:f.archiveId}:{},onClose:()=>{p(null),g(!1)},onScheduled:()=>v(!0)})]})}function en(){let{t:e}=je(),t=Me(`/system/data`,{t:e,isAdmin:!0})??{icon:p,title:e(`system.data`,`Data`)};return s(Ne,{icon:t.icon,title:t.title,defaultSection:`storage`,sectionsLabel:`${t.title} sections`,sections:[{id:`storage`,label:`Storage`,content:s(We,{})},{id:`backup`,label:`Backup`,content:s($t,{})}]})}export{en as DataPage};
|