@camstack/addon-admin-ui 1.2.384 → 1.2.385
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-Cji8o_ed.js → AddonAssetIcon-DZP7aCIx.js} +1 -1
- package/dist/assets/{AddonIntegrationBody-BmKTeANU.js → AddonIntegrationBody-xiE0jNlG.js} +1 -1
- package/dist/assets/{Addons-ThKEp7qj.js → Addons-o9wXCzXq.js} +1 -1
- package/dist/assets/{AdminPage-CypZrzwh.js → AdminPage-nt88IVlh.js} +1 -1
- package/dist/assets/{AdminSectionedPage-fCCbEY4X.js → AdminSectionedPage-3qgyliDm.js} +1 -1
- package/dist/assets/{AiProfiles-CLVNwOGK.js → AiProfiles-C-v-FTYp.js} +1 -1
- package/dist/assets/{BrokerForm-BvQ3y656.js → BrokerForm-D9wTdix8.js} +1 -1
- package/dist/assets/{Build-B3h-pYA9.js → Build-BYFpn2jN.js} +1 -1
- package/dist/assets/{Calendars-Bt-vx65e.js → Calendars-DgJBMVwv.js} +1 -1
- package/dist/assets/{Cluster-DP5LVyPi.js → Cluster-J3-XI9B3.js} +1 -1
- package/dist/assets/{ClusterStepModel-B7AJgRHr.js → ClusterStepModel-DRkAJoa2.js} +1 -1
- package/dist/assets/{CompositionEditor-DhY-4ig2.js → CompositionEditor-BaNYPdLs.js} +1 -1
- package/dist/assets/{CompositionEditorPage-CDcglFdz.js → CompositionEditorPage-CUJU_QFY.js} +1 -1
- package/dist/assets/{Data-4x3E7gZ7.js → Data-CbqwI0zY.js} +1 -1
- package/dist/assets/{DeviceDetail-Bh7jp487.js → DeviceDetail-DtEfXYLF.js} +1 -1
- package/dist/assets/{DeviceDoActionFields-DNK6VlKf.js → DeviceDoActionFields-DuMMgBVZ.js} +1 -1
- package/dist/assets/{Devices-qg2IXMUv.js → Devices-TSR3gTOn.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-CXJOZURH.js → EmbedPlayerPage-lCq58AFh.js} +1 -1
- package/dist/assets/{Identity-YuZ4ULlb.js → Identity-O8LMCBYv.js} +1 -1
- package/dist/assets/{IntegrationDetail-hS-gjMQ6.js → IntegrationDetail-6nNR9kpf.js} +1 -1
- package/dist/assets/{Integrations-C5sI1fLe.js → Integrations-CAd8A-tv.js} +1 -1
- package/dist/assets/{Integrations-DzIX9NpZ.js → Integrations-DvpD7RyK.js} +1 -1
- package/dist/assets/{Library-N1UWKUkC.js → Library-Ds2Govgr.js} +1 -1
- package/dist/assets/{Locations-B0O6LF8O.js → Locations-D65BwYps.js} +1 -1
- package/dist/assets/{Logs-DSddtVEp.js → Logs-CIGfshGa.js} +1 -1
- package/dist/assets/{MyAccess--Kv6GTI2.js → MyAccess-lToZhhaj.js} +1 -1
- package/dist/assets/{Network-gGXOhRpC.js → Network-lmrVIJ3v.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-43RW_xq3.js → NodeAddonsSettingsPanel-DfcsJEKU.js} +1 -1
- package/dist/assets/Notifications-gwTr1o7v.js +1 -0
- package/dist/assets/{Recordings-CBDQ-KJI.js → Recordings-DxXvWh8j.js} +1 -1
- package/dist/assets/{ScanNetworkModal-Bi2lsUik.js → ScanNetworkModal-DdhwJ8rk.js} +1 -1
- package/dist/assets/{SessionsList-Cxu4MVva.js → SessionsList-B-PmiTxK.js} +1 -1
- package/dist/assets/{Showroom-BmaHcBRm.js → Showroom-CniZRhgD.js} +1 -1
- package/dist/assets/{System-BctLt6rx.js → System-CWO8MTm2.js} +1 -1
- package/dist/assets/{Terminal-CE_BJxwo.js → Terminal-RPUG_ky9.js} +1 -1
- package/dist/assets/{Viewer-2M0ylOw3.js → Viewer-C-Lhu6RI.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BgPIzpZC.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-B5q478Vj.js} +1 -1
- package/dist/assets/{authed-media-DmJCnyAU.js → authed-media-CmNMcsPz.js} +1 -1
- package/dist/assets/{device-integration-icon-CWBzge9m.js → device-integration-icon-Ccvq5_Th.js} +1 -1
- package/dist/assets/device-picker-model-BizCkD6A.js +1 -0
- package/dist/assets/{hostInit-CyEtnNFN.js → hostInit-YoM4TDWI.js} +1 -1
- package/dist/assets/{index-CacciakK.js → index-D_3-GXGK.js} +3 -3
- package/dist/assets/{location-owned-usage-BopLei43.js → location-owned-usage-B7AdEDxo.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-ca028e4c.js → mf-entry-bootstrap-0-a6175f54.js} +2 -2
- package/dist/assets/mount-BizCkD6A.js +1 -0
- package/dist/assets/{notification-schedule-field-K1sNMmx4.js → notification-schedule-field-BV1PkSYj.js} +1 -1
- package/dist/assets/remoteEntry-vnA9K0Ej.js +1 -0
- package/dist/assets/{src-CoX6DWRw.js → src-M02zmBCw.js} +1 -1
- package/dist/assets/{use-scenes-feed-D9DWklxj.js → use-scenes-feed-ENVwf1Sb.js} +1 -1
- package/dist/assets/{use-stationary-objects-CRAk6z8Y.js → use-stationary-objects-DOuMHvDD.js} +1 -1
- package/dist/assets/useEventInvalidation-BizCkD6A.js +1 -0
- package/dist/assets/{useNodeUrlSelection-Dvo2rCQJ.js → useNodeUrlSelection-CJbI9vHl.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BWZVzJfl.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BkngZkyx.js} +2 -2
- package/dist/index.html +5 -5
- package/dist/server/addon.js +1 -1
- package/package.json +1 -1
- package/dist/assets/Notifications-BXHj1O5F.js +0 -1
- package/dist/assets/device-picker-model-CdxP7UkM.js +0 -1
- package/dist/assets/mount-CdxP7UkM.js +0 -1
- package/dist/assets/remoteEntry-HJa-d3BT.js +0 -1
- package/dist/assets/useEventInvalidation-CdxP7UkM.js +0 -1
|
@@ -1 +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-Gj8o_n4X.js";import{Fi as p,Gn as m,Hn as h,Vi as g,Zl as _,_a as v,iu as y,nr as b,nu as x,qa as S,s as C,ur as w,va as T}from"./src-CoX6DWRw.js";import{Er as E,Mr as D,Nr as ee,Sr as O,Tr as k,_r as te,bn as A,br as j,cn as ne,dn as re,fn as ie,hr as ae,ln as oe,mr as se,pr as ce,un as le,ur as M,vr as ue,xr as N,yr as de}from"./client-tKRKHAfe.js";import{t as P}from"./useTranslation-Bc5yH9V9.js";r();function fe(e){return{target:{kind:`new`,type:e},name:``,features:[]}}function pe(e){return{target:{kind:`existing`,device:e},name:``,features:[]}}function F(e,t){return{target:e.target,name:t,features:e.features.flatMap(e=>e.kind===`fields`?[e]:[])}}function I(e,t,n){return{...e,features:e.features.map(e=>e.cap===t?n(e):e)}}function L(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>e!==t))}function me(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 I(e,t.cap,e=>({...e,fields:{...e.fields,[t.path]:t.source}}));case`clear-field`:return I(e,t.cap,e=>({...e,fields:L(e.fields,t.path)}));case`remove-binding`:return I(e,t.cap,e=>{let n=e.fields[t.path];return n?.kind===`expression`?{...e,fields:{...e.fields,[t.path]:{...n,bindings:L(n.bindings,t.bindingName)}}}:e});case`copy-feature`:return I(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 he(e){let t=ae.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 ge(e,t){return JSON.stringify(e)!==JSON.stringify(t)}function _e(e){for(let t=1;;t++){let n=`s${t}`;if(!e.includes(n))return n}}var ve=[`room`,`converted-sensor`,`derived-binary`],R={addonId:`provider-homeassistant`,stableId:`sensor.template_source`};function ye(){return F(re({temperatureSources:oe,motionSources:ne,occupancyWindowMs:le}),`Room`)}function be(){return F({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:R,cap:`numeric-sensor`,fieldPath:`value`}}},unit:{kind:`expression`,expr:`"°F"`,bindings:{}},lastFetchedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Converted sensor`)}function xe(){return F({target:{kind:`new`,type:E.Sensor},features:[{kind:`fields`,cap:`binary`,fields:{on:{kind:`expression`,expr:`v > 20`,bindings:{v:{kind:`from`,source:R,cap:`temperature-sensor`,fieldPath:`celsius`}}},lastChangedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Derived binary`)}function Se(e){switch(e){case`room`:return ye();case`converted-sensor`:return be();case`derived-binary`:return xe()}}function Ce(e,t){return typeof t==`number`&&Number.isFinite(t)&&t>0?{kind:`device`,path:`/devices/${t}`}:{kind:`editor`,path:`/build/compositions/${encodeURIComponent(e)}`}}var z=`rounded-lg border border-border bg-surface p-4`,we=z;function Te(e){return{addonId:e.addonId,stableId:e.stableId}}function B(e){return new Map(e.map(e=>[N(Te(e)),e]))}function Ee(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 De(e,t){let n=e.features.filter(e=>e.cap!==t);return n.length===0?null:{target:e.target,features:n}}function Oe(e,t){let n=e?.features.find(e=>e.cap===t);return n!==void 0&&n.kind===`fields`?n:null}function V(e){return Array.isArray(e)?e.map(V):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,V(t)]))}function H(e){return JSON.stringify(V(e))}function ke(e,t){return H(e)===H(t)}function U(e,t){return H(e)===H(t)}function Ae(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}:H(t)===H(e.composition)?{kind:`noop`}:{kind:`update`,blockId:n,expectedUpdatedAt:e.view.block.updatedAt,composition:t}}}}function W(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 G(e){return{kind:`expression`,expr:e,bindings:{}}}function K(e){let t=W(`number`,e.percentage);return t===null?null:{kind:`fields`,cap:`battery`,fields:e.mode===`replace`?{percentage:t}:{percentage:t,charging:G(`"unknown"`),sleeping:G(`false`),lastUpdated:G(`now`)}}}var je=[`percent`,...A.options];function Me(e,t){return t===`percent`?{level:e}:{"remaining.value":e,"remaining.unit":G(JSON.stringify(t))}}function Ne(e,t){let n=W(`number`,t.remaining);if(n===null||!se.test(t.key)||t.label.trim()===``)return null;let r={label:t.label.trim(),fields:Me(n,t.unit)};return{kind:`fields`,cap:`consumables`,...e?.enabled===void 0?{}:{enabled:e.enabled},fields:e?.fields??{lastChangedAt:G(`now`),lastFetchedAt:G(`now`)},items:{...e?.items,[t.key]:r}}}function Pe(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=A.safeParse(JSON.parse(t.expr));return e.success?e.data:null}catch{return null}}function Fe(e){return Object.entries(e?.items??{}).map(([e,t])=>{let n=Pe(t.fields),r=q(t.fields.level??t.fields[`remaining.value`]),i=r===null?null:W(`number`,r);return n!==null&&i!==null&&ke(Me(i,n),t.fields)?{key:e,label:t.label,unit:n,source:r}:{key:e,label:t.label,unit:null,source:null}})}function Ie(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 Le(e){return e.toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,48)}function Re(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=>[N(e),e])).values()]}function ze(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 q(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 Be(e,t){let n=q(e.fields.percentage);if(n===null)return!1;let r=K({percentage:n,mode:t}),{enabled:i,...a}=e;return r!==null&&U(a,r)}function J(e){return e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,location:e.location,type:e.type}))}function Ve(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 Y(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 He(e,t,n,r){return r===null?{kind:`from`,source:e,cap:t,fieldPath:n.path}:W(r,{source:e,cap:t,fieldPath:n.path,kind:n.kind})}function Ue(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:Y(n[e.cap],t.path),source:He(i,e.cap,t,r)})))}function X(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 We=[];function Ge({title:e,targetKind:t,excludeDeviceIds:n=We,onPick:r,onCancel:a}){let{t:c}=P(),[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(Ke,{excludeDeviceIds:n,onSelect:p}):s(qe,{device:f,targetKind:t,onPick:r,onBack:()=>p(null)}),s(`div`,{children:s(m,{variant:`ghost`,size:`sm`,onClick:a,children:c(`customize.picker.cancel`)})})]})}function Ke({excludeDeviceIds:e,onSelect:t}){let{t:n}=P(),[r,c]=o(``),l=T({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(_,{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(h,{title:n(`customize.picker.devicesFailed`),message:l.error?.message??``}),l.status===`success`&&s(`ul`,{className:`flex flex-col gap-1`,children:Ve(J(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 qe({device:e,targetKind:t,selected:n,onPick:r,onBack:a}){let{t:o}=P(),c=v({deviceId:e.id}),l=S({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(h,{title:o(`customize.picker.fieldsFailed`),message:c.error?.message??``});let u=Ue(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:X(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 Je=`integration`;function Z(e,t){switch(e.kind){case`from`:{let n=N(e.source);return`${t.get(n)??n} · ${e.cap}.${e.fieldPath}`}case`expression`:return e.expr;case`code`:return`code`}}function Ye(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 Xe(e,t,n,r){return{key:`${e.feature.cap}.${t}`,cap:e.feature.cap,field:t,origin:`composed`,mode:e.mode,from:Z(n,e.input.sourceNames),value:e.enabled?Ye(e.input.state,r):{kind:`off`}}}function Ze(e){let t=e.feature.cap;return Object.entries(e.feature.fields).map(([n,r])=>Xe(e,n,r,e=>e.cap===t&&e.path===n&&e.item===void 0))}function Qe(e){let t=e.feature.cap;return Object.entries(e.feature.items??{}).flatMap(([n,r])=>Object.entries(r.fields).map(([r,i])=>Xe(e,ue(ce,n,r),i,e=>e.cap===t&&e.path===r&&e.item?.arrayPath===`items`&&e.item.key===n)))}function $e(e,t,n){if(e===null)return{kind:`unknown`,reason:`the device state could not be read`};let r=Y(e[t],n),i=r===void 0?void 0:D(r);return i===void 0?{kind:`unknown`,reason:`not reported`}:{kind:`value`,value:i,staleReason:null}}function et(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:Je,value:$e(e.input.snapshot,t,n)}))}function tt(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:te(t),input:e};return[...Ze(n),...Qe(n),...et(n)]})}var nt={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)`},Q=/[A-Za-z_][A-Za-z0-9_]*$/;function rt(e,t,n){let r=Q.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=[...ee].filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`builtin`,label:nt[e]??e,insert:`${e}(`,hintKey:`compositionEditor.builtins.${e}`}));return[...i,...a,...o].slice(0,8)}function it(e,t,n){let r=t-(Q.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 at({label:e,value:t,bindings:r,onChange:a}){let{t:c}=P(),l=n(null),[u,d]=o(t.length),f=rt(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=it(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 ot(e,t,n){if(e.kind===`code`)return{kind:`unavailable`,reason:`code fields arrive in slice 4`};if(e.kind===`expression`&&(M(e.expr,`rose`)||M(e.expr,`count`)))return{kind:`runtime-only`};let r=O(e).filter(e=>t.get(j(e.source,e.cap))?.kind!==`value`).map(de);if(r.length>0)return{kind:`waiting`,missing:r};let i=ie({source:e,now:n,read:e=>{let n=t.get(j(e.source,e.cap)),r=n?.kind===`value`?Y(n.slice,e.fieldPath):void 0,i=r===void 0?void 0:D(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 st({sliceKey:e,deviceId:t,capName:n,onReading:r}){let i=C(f().trpcClient,t,n);return c(()=>{r(e,i===void 0?{kind:`pending`}:{kind:`value`,slice:i})},[e,i,r]),null}function ct(e,t){return[...new Map(O(e).map(e=>[j(e.source,e.cap),e]))].map(([e,n])=>({key:e,read:n,device:t.get(N(n.source))}))}function lt({source:e}){let{t:n}=P(),r=T({projection:`slim`}),[a,c]=o(new Map),l=t((e,t)=>{c(n=>new Map([...n,[e,t]]))},[]),u=ct(e,B(r.status===`success`?J(r.data):[])),d=r.status===`success`?u.filter(e=>e.device===void 0).map(e=>N(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(st,{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(ut,{preview:ot(e,a,Date.now())})]})}function ut({preview:e}){let{t}=P();switch(e.kind){case`value`:return i(`strong`,{children:[`→ `,X(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 dt({path:e,kind:t,required:n,source:r,onSet:c,onClear:l,onRemoveBinding:u,sourceNames:d}){let{t:f}=P(),[p,h]=o(`idle`),g=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(m,{size:`sm`,variant:`outline`,onClick:()=>h(`take`),children:f(`compositionEditor.takeFrom`)}),s(m,{size:`sm`,variant:`outline`,"aria-pressed":g!==null,onClick:()=>c(g??{kind:`expression`,expr:`null`,bindings:{}}),children:f(`compositionEditor.formula`)}),r!==void 0&&s(m,{size:`sm`,variant:`ghost`,onClick:l,children:f(`compositionEditor.clear`)})]}),r?.kind===`from`&&s(`span`,{className:`text-[11px]`,children:Z(r,d)}),g!==null&&i(a,{children:[s(at,{label:f(`compositionEditor.formulaFor`,{path:e}),value:g.expr,bindings:Object.keys(g.bindings),onChange:e=>c({...g,expr:e})}),s(`ul`,{className:`text-[11px] flex flex-col gap-0.5`,children:Object.entries(g.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`?Z(t,d):JSON.stringify(t.value)}),s(m,{size:`sm`,variant:`ghost`,"aria-label":f(`compositionEditor.removeBinding`,{name:e}),onClick:()=>u(e),children:`×`})]},e))}),s(m,{size:`sm`,variant:`ghost`,onClick:()=>h(`add-binding`),children:f(`compositionEditor.addSource`)})]}),p!==`idle`&&s(Ge,{title:f(p===`take`?`compositionEditor.takeFrom`:`compositionEditor.addSource`),targetKind:p===`take`?t:null,onCancel:()=>h(`idle`),onPick:e=>{if(p===`take`)c(e.source);else if(g!==null){let t=_e(Object.keys(g.bindings));c({...g,bindings:{...g.bindings,[t]:{kind:`from`,source:e.ref,cap:e.cap,fieldPath:e.path}}})}h(`idle`)}}),r!==void 0&&s(lt,{source:r})]})}r();function ft(e){return e===null||e.kind===`known`?null:e}function pt({draft:e,deviceType:t,nativeCaps:n,targetFields:r,dispatch:c}){let{t:l}=P(),u=p({deviceType:t}),d=T({projection:`slim`}),f=new Map([...B(d.status===`success`?J(d.data):[])].map(([e,t])=>[e,t.name])),[h,g]=o(null),_=ft(n)??ft(r),v=n?.kind===`known`?n.value:new Set,y=new Set(e.features.map(e=>e.cap)),b=u.status===`success`?u.data.caps.filter(e=>!y.has(e.cap)&&!v.has(e.cap)):[],x=[...v].filter(e=>!y.has(e)),S=e=>v.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 _===null?i(a,{children:[i(`section`,{"aria-labelledby":`editor-features`,className:`${z} 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(w,{variant:v.has(e.cap)?`default`:`info`,children:v.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)),b.map(e=>i(m,{size:`sm`,variant:`outline`,onClick:()=>c({type:`add-feature`,cap:e.cap}),children:[`+ `,e.cap]},e.cap)),x.map(e=>s(m,{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:`${z} 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(m,{size:`sm`,variant:`outline`,onClick:()=>g(e.cap),children:l(`compositionEditor.copyFeature`)})]}),h===e.cap&&s(Ge,{title:l(`compositionEditor.copyFeature`),targetKind:null,onCancel:()=>g(null),onPick:t=>{c({type:`copy-feature`,cap:e.cap,from:t.ref,sourceCap:t.cap,paths:S(e.cap).map(e=>e.path)}),g(null)}}),S(e.cap).map(t=>s(dt,{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:`${z} 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:_.kind===`unknown`?_.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}=P(),a=e.target;return i(`section`,{"aria-labelledby":`editor-target`,className:`${z} 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:y(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(k).find(t=>t===e.target.value)??null}),children:[s(`option`,{value:``,children:r(`customize.identity.noRole`)}),Object.values(k).map(e=>s(`option`,{value:e,children:x(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}=P(),u=g(),d=he(e),f=d.ok?JSON.stringify(d.composition):``,[p,h]=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=>h({key:f,state:e.ok?{kind:`ok`}:{kind:`refused`,problems:e.problems}})).catch(e=>h({key:f,state:{kind:`unknown`,reason:e instanceof Error?e.message:String(e)}}))},500);return()=>clearTimeout(n)},[f,t]);let _=d.ok?p.key===f?p.state:{kind:`checking`}:{kind:`invalid-draft`,problems:d.problems};return i(`section`,{"aria-labelledby":`editor-verify`,className:`${z} flex flex-col gap-2`,children:[s(`h2`,{id:`editor-verify`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.verify`)}),_.kind===`checking`&&s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.verify.checking`)}),_.kind===`ok`&&s(`p`,{className:`text-[11px] text-success`,children:l(`compositionEditor.verify.ok`)}),_.kind===`unknown`&&s(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.verify.unknown`,{reason:_.reason})}),(_.kind===`invalid-draft`||_.kind===`refused`)&&s(`ul`,{role:`alert`,className:`flex flex-col gap-1 text-[11px] text-danger`,children:_.kind===`invalid-draft`?_.problems.map(e=>s(`li`,{children:e},e)):_.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(m,{variant:`ghost`,onClick:a,children:l(`compositionEditor.cancel`)}),s(m,{disabled:_.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(Se(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:h}=P(),g=b(),[_,v]=e(me,t),[y,x]=o(!1),[S,C]=o(null),w=async e=>{ge(t,_)&&!await g({title:h(`compositionEditor.templates.confirmTitle`),message:h(`compositionEditor.templates.confirmMessage`),confirmLabel:h(`compositionEditor.templates.confirmApply`),variant:`danger`})||d(e)},T=_.target.kind===`new`?_.target.type:r,E=async e=>{x(!0);let t=await f(e,_.name);x(!1),C(t.kind===`refused`?t.reason:null)};return i(`div`,{className:`flex flex-col gap-4`,children:[u&&_.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:h(`compositionEditor.templates.label`)}),ve.map(e=>s(m,{size:`sm`,variant:`outline`,onClick:()=>void w(e),children:h(`compositionEditor.templates.${e}`)},e))]}),s(mt,{draft:_,targetName:a,dispatch:v}),s(pt,{draft:_,deviceType:T,nativeCaps:c,targetFields:l,dispatch:v}),s(ht,{draft:_,blockId:n,saving:y,onSave:e=>void E(e),onCancel:p}),S!==null&&s(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:S})]})}export{De as C,pe as D,F as E,fe as O,Ee as S,Ce as T,q as _,qe as a,Ae as b,J as c,Ne as d,Fe as f,Le as g,Be as h,tt as i,je as l,ze as m,ot as n,X as o,Re as p,at as r,Y as s,gt as t,K as u,Ie as v,we as w,U as x,Oe as y};
|
|
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-Gj8o_n4X.js";import{Fi as p,Gn as m,Hn as h,Vi as g,Zl as _,_a as v,iu as y,nr as b,nu as x,qa as S,s as C,ur as w,va as T}from"./src-M02zmBCw.js";import{Er as E,Mr as D,Nr as ee,Sr as O,Tr as k,_r as te,bn as A,br as j,cn as ne,dn as re,fn as ie,hr as ae,ln as oe,mr as se,pr as ce,un as le,ur as M,vr as ue,xr as N,yr as de}from"./client-tKRKHAfe.js";import{t as P}from"./useTranslation-Bc5yH9V9.js";r();function fe(e){return{target:{kind:`new`,type:e},name:``,features:[]}}function pe(e){return{target:{kind:`existing`,device:e},name:``,features:[]}}function F(e,t){return{target:e.target,name:t,features:e.features.flatMap(e=>e.kind===`fields`?[e]:[])}}function I(e,t,n){return{...e,features:e.features.map(e=>e.cap===t?n(e):e)}}function L(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>e!==t))}function me(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 I(e,t.cap,e=>({...e,fields:{...e.fields,[t.path]:t.source}}));case`clear-field`:return I(e,t.cap,e=>({...e,fields:L(e.fields,t.path)}));case`remove-binding`:return I(e,t.cap,e=>{let n=e.fields[t.path];return n?.kind===`expression`?{...e,fields:{...e.fields,[t.path]:{...n,bindings:L(n.bindings,t.bindingName)}}}:e});case`copy-feature`:return I(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 he(e){let t=ae.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 ge(e,t){return JSON.stringify(e)!==JSON.stringify(t)}function _e(e){for(let t=1;;t++){let n=`s${t}`;if(!e.includes(n))return n}}var ve=[`room`,`converted-sensor`,`derived-binary`],R={addonId:`provider-homeassistant`,stableId:`sensor.template_source`};function ye(){return F(re({temperatureSources:oe,motionSources:ne,occupancyWindowMs:le}),`Room`)}function be(){return F({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:R,cap:`numeric-sensor`,fieldPath:`value`}}},unit:{kind:`expression`,expr:`"°F"`,bindings:{}},lastFetchedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Converted sensor`)}function xe(){return F({target:{kind:`new`,type:E.Sensor},features:[{kind:`fields`,cap:`binary`,fields:{on:{kind:`expression`,expr:`v > 20`,bindings:{v:{kind:`from`,source:R,cap:`temperature-sensor`,fieldPath:`celsius`}}},lastChangedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Derived binary`)}function Se(e){switch(e){case`room`:return ye();case`converted-sensor`:return be();case`derived-binary`:return xe()}}function Ce(e,t){return typeof t==`number`&&Number.isFinite(t)&&t>0?{kind:`device`,path:`/devices/${t}`}:{kind:`editor`,path:`/build/compositions/${encodeURIComponent(e)}`}}var z=`rounded-lg border border-border bg-surface p-4`,we=z;function Te(e){return{addonId:e.addonId,stableId:e.stableId}}function B(e){return new Map(e.map(e=>[N(Te(e)),e]))}function Ee(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 De(e,t){let n=e.features.filter(e=>e.cap!==t);return n.length===0?null:{target:e.target,features:n}}function Oe(e,t){let n=e?.features.find(e=>e.cap===t);return n!==void 0&&n.kind===`fields`?n:null}function V(e){return Array.isArray(e)?e.map(V):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,V(t)]))}function H(e){return JSON.stringify(V(e))}function ke(e,t){return H(e)===H(t)}function U(e,t){return H(e)===H(t)}function Ae(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}:H(t)===H(e.composition)?{kind:`noop`}:{kind:`update`,blockId:n,expectedUpdatedAt:e.view.block.updatedAt,composition:t}}}}function W(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 G(e){return{kind:`expression`,expr:e,bindings:{}}}function K(e){let t=W(`number`,e.percentage);return t===null?null:{kind:`fields`,cap:`battery`,fields:e.mode===`replace`?{percentage:t}:{percentage:t,charging:G(`"unknown"`),sleeping:G(`false`),lastUpdated:G(`now`)}}}var je=[`percent`,...A.options];function Me(e,t){return t===`percent`?{level:e}:{"remaining.value":e,"remaining.unit":G(JSON.stringify(t))}}function Ne(e,t){let n=W(`number`,t.remaining);if(n===null||!se.test(t.key)||t.label.trim()===``)return null;let r={label:t.label.trim(),fields:Me(n,t.unit)};return{kind:`fields`,cap:`consumables`,...e?.enabled===void 0?{}:{enabled:e.enabled},fields:e?.fields??{lastChangedAt:G(`now`),lastFetchedAt:G(`now`)},items:{...e?.items,[t.key]:r}}}function Pe(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=A.safeParse(JSON.parse(t.expr));return e.success?e.data:null}catch{return null}}function Fe(e){return Object.entries(e?.items??{}).map(([e,t])=>{let n=Pe(t.fields),r=q(t.fields.level??t.fields[`remaining.value`]),i=r===null?null:W(`number`,r);return n!==null&&i!==null&&ke(Me(i,n),t.fields)?{key:e,label:t.label,unit:n,source:r}:{key:e,label:t.label,unit:null,source:null}})}function Ie(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 Le(e){return e.toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,48)}function Re(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=>[N(e),e])).values()]}function ze(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 q(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 Be(e,t){let n=q(e.fields.percentage);if(n===null)return!1;let r=K({percentage:n,mode:t}),{enabled:i,...a}=e;return r!==null&&U(a,r)}function J(e){return e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,location:e.location,type:e.type}))}function Ve(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 Y(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 He(e,t,n,r){return r===null?{kind:`from`,source:e,cap:t,fieldPath:n.path}:W(r,{source:e,cap:t,fieldPath:n.path,kind:n.kind})}function Ue(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:Y(n[e.cap],t.path),source:He(i,e.cap,t,r)})))}function X(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 We=[];function Ge({title:e,targetKind:t,excludeDeviceIds:n=We,onPick:r,onCancel:a}){let{t:c}=P(),[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(Ke,{excludeDeviceIds:n,onSelect:p}):s(qe,{device:f,targetKind:t,onPick:r,onBack:()=>p(null)}),s(`div`,{children:s(m,{variant:`ghost`,size:`sm`,onClick:a,children:c(`customize.picker.cancel`)})})]})}function Ke({excludeDeviceIds:e,onSelect:t}){let{t:n}=P(),[r,c]=o(``),l=T({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(_,{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(h,{title:n(`customize.picker.devicesFailed`),message:l.error?.message??``}),l.status===`success`&&s(`ul`,{className:`flex flex-col gap-1`,children:Ve(J(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 qe({device:e,targetKind:t,selected:n,onPick:r,onBack:a}){let{t:o}=P(),c=v({deviceId:e.id}),l=S({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(h,{title:o(`customize.picker.fieldsFailed`),message:c.error?.message??``});let u=Ue(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:X(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 Je=`integration`;function Z(e,t){switch(e.kind){case`from`:{let n=N(e.source);return`${t.get(n)??n} · ${e.cap}.${e.fieldPath}`}case`expression`:return e.expr;case`code`:return`code`}}function Ye(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 Xe(e,t,n,r){return{key:`${e.feature.cap}.${t}`,cap:e.feature.cap,field:t,origin:`composed`,mode:e.mode,from:Z(n,e.input.sourceNames),value:e.enabled?Ye(e.input.state,r):{kind:`off`}}}function Ze(e){let t=e.feature.cap;return Object.entries(e.feature.fields).map(([n,r])=>Xe(e,n,r,e=>e.cap===t&&e.path===n&&e.item===void 0))}function Qe(e){let t=e.feature.cap;return Object.entries(e.feature.items??{}).flatMap(([n,r])=>Object.entries(r.fields).map(([r,i])=>Xe(e,ue(ce,n,r),i,e=>e.cap===t&&e.path===r&&e.item?.arrayPath===`items`&&e.item.key===n)))}function $e(e,t,n){if(e===null)return{kind:`unknown`,reason:`the device state could not be read`};let r=Y(e[t],n),i=r===void 0?void 0:D(r);return i===void 0?{kind:`unknown`,reason:`not reported`}:{kind:`value`,value:i,staleReason:null}}function et(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:Je,value:$e(e.input.snapshot,t,n)}))}function tt(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:te(t),input:e};return[...Ze(n),...Qe(n),...et(n)]})}var nt={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)`},Q=/[A-Za-z_][A-Za-z0-9_]*$/;function rt(e,t,n){let r=Q.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=[...ee].filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`builtin`,label:nt[e]??e,insert:`${e}(`,hintKey:`compositionEditor.builtins.${e}`}));return[...i,...a,...o].slice(0,8)}function it(e,t,n){let r=t-(Q.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 at({label:e,value:t,bindings:r,onChange:a}){let{t:c}=P(),l=n(null),[u,d]=o(t.length),f=rt(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=it(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 ot(e,t,n){if(e.kind===`code`)return{kind:`unavailable`,reason:`code fields arrive in slice 4`};if(e.kind===`expression`&&(M(e.expr,`rose`)||M(e.expr,`count`)))return{kind:`runtime-only`};let r=O(e).filter(e=>t.get(j(e.source,e.cap))?.kind!==`value`).map(de);if(r.length>0)return{kind:`waiting`,missing:r};let i=ie({source:e,now:n,read:e=>{let n=t.get(j(e.source,e.cap)),r=n?.kind===`value`?Y(n.slice,e.fieldPath):void 0,i=r===void 0?void 0:D(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 st({sliceKey:e,deviceId:t,capName:n,onReading:r}){let i=C(f().trpcClient,t,n);return c(()=>{r(e,i===void 0?{kind:`pending`}:{kind:`value`,slice:i})},[e,i,r]),null}function ct(e,t){return[...new Map(O(e).map(e=>[j(e.source,e.cap),e]))].map(([e,n])=>({key:e,read:n,device:t.get(N(n.source))}))}function lt({source:e}){let{t:n}=P(),r=T({projection:`slim`}),[a,c]=o(new Map),l=t((e,t)=>{c(n=>new Map([...n,[e,t]]))},[]),u=ct(e,B(r.status===`success`?J(r.data):[])),d=r.status===`success`?u.filter(e=>e.device===void 0).map(e=>N(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(st,{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(ut,{preview:ot(e,a,Date.now())})]})}function ut({preview:e}){let{t}=P();switch(e.kind){case`value`:return i(`strong`,{children:[`→ `,X(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 dt({path:e,kind:t,required:n,source:r,onSet:c,onClear:l,onRemoveBinding:u,sourceNames:d}){let{t:f}=P(),[p,h]=o(`idle`),g=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(m,{size:`sm`,variant:`outline`,onClick:()=>h(`take`),children:f(`compositionEditor.takeFrom`)}),s(m,{size:`sm`,variant:`outline`,"aria-pressed":g!==null,onClick:()=>c(g??{kind:`expression`,expr:`null`,bindings:{}}),children:f(`compositionEditor.formula`)}),r!==void 0&&s(m,{size:`sm`,variant:`ghost`,onClick:l,children:f(`compositionEditor.clear`)})]}),r?.kind===`from`&&s(`span`,{className:`text-[11px]`,children:Z(r,d)}),g!==null&&i(a,{children:[s(at,{label:f(`compositionEditor.formulaFor`,{path:e}),value:g.expr,bindings:Object.keys(g.bindings),onChange:e=>c({...g,expr:e})}),s(`ul`,{className:`text-[11px] flex flex-col gap-0.5`,children:Object.entries(g.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`?Z(t,d):JSON.stringify(t.value)}),s(m,{size:`sm`,variant:`ghost`,"aria-label":f(`compositionEditor.removeBinding`,{name:e}),onClick:()=>u(e),children:`×`})]},e))}),s(m,{size:`sm`,variant:`ghost`,onClick:()=>h(`add-binding`),children:f(`compositionEditor.addSource`)})]}),p!==`idle`&&s(Ge,{title:f(p===`take`?`compositionEditor.takeFrom`:`compositionEditor.addSource`),targetKind:p===`take`?t:null,onCancel:()=>h(`idle`),onPick:e=>{if(p===`take`)c(e.source);else if(g!==null){let t=_e(Object.keys(g.bindings));c({...g,bindings:{...g.bindings,[t]:{kind:`from`,source:e.ref,cap:e.cap,fieldPath:e.path}}})}h(`idle`)}}),r!==void 0&&s(lt,{source:r})]})}r();function ft(e){return e===null||e.kind===`known`?null:e}function pt({draft:e,deviceType:t,nativeCaps:n,targetFields:r,dispatch:c}){let{t:l}=P(),u=p({deviceType:t}),d=T({projection:`slim`}),f=new Map([...B(d.status===`success`?J(d.data):[])].map(([e,t])=>[e,t.name])),[h,g]=o(null),_=ft(n)??ft(r),v=n?.kind===`known`?n.value:new Set,y=new Set(e.features.map(e=>e.cap)),b=u.status===`success`?u.data.caps.filter(e=>!y.has(e.cap)&&!v.has(e.cap)):[],x=[...v].filter(e=>!y.has(e)),S=e=>v.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 _===null?i(a,{children:[i(`section`,{"aria-labelledby":`editor-features`,className:`${z} 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(w,{variant:v.has(e.cap)?`default`:`info`,children:v.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)),b.map(e=>i(m,{size:`sm`,variant:`outline`,onClick:()=>c({type:`add-feature`,cap:e.cap}),children:[`+ `,e.cap]},e.cap)),x.map(e=>s(m,{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:`${z} 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(m,{size:`sm`,variant:`outline`,onClick:()=>g(e.cap),children:l(`compositionEditor.copyFeature`)})]}),h===e.cap&&s(Ge,{title:l(`compositionEditor.copyFeature`),targetKind:null,onCancel:()=>g(null),onPick:t=>{c({type:`copy-feature`,cap:e.cap,from:t.ref,sourceCap:t.cap,paths:S(e.cap).map(e=>e.path)}),g(null)}}),S(e.cap).map(t=>s(dt,{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:`${z} 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:_.kind===`unknown`?_.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}=P(),a=e.target;return i(`section`,{"aria-labelledby":`editor-target`,className:`${z} 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:y(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(k).find(t=>t===e.target.value)??null}),children:[s(`option`,{value:``,children:r(`customize.identity.noRole`)}),Object.values(k).map(e=>s(`option`,{value:e,children:x(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}=P(),u=g(),d=he(e),f=d.ok?JSON.stringify(d.composition):``,[p,h]=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=>h({key:f,state:e.ok?{kind:`ok`}:{kind:`refused`,problems:e.problems}})).catch(e=>h({key:f,state:{kind:`unknown`,reason:e instanceof Error?e.message:String(e)}}))},500);return()=>clearTimeout(n)},[f,t]);let _=d.ok?p.key===f?p.state:{kind:`checking`}:{kind:`invalid-draft`,problems:d.problems};return i(`section`,{"aria-labelledby":`editor-verify`,className:`${z} flex flex-col gap-2`,children:[s(`h2`,{id:`editor-verify`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.verify`)}),_.kind===`checking`&&s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.verify.checking`)}),_.kind===`ok`&&s(`p`,{className:`text-[11px] text-success`,children:l(`compositionEditor.verify.ok`)}),_.kind===`unknown`&&s(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.verify.unknown`,{reason:_.reason})}),(_.kind===`invalid-draft`||_.kind===`refused`)&&s(`ul`,{role:`alert`,className:`flex flex-col gap-1 text-[11px] text-danger`,children:_.kind===`invalid-draft`?_.problems.map(e=>s(`li`,{children:e},e)):_.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(m,{variant:`ghost`,onClick:a,children:l(`compositionEditor.cancel`)}),s(m,{disabled:_.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(Se(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:h}=P(),g=b(),[_,v]=e(me,t),[y,x]=o(!1),[S,C]=o(null),w=async e=>{ge(t,_)&&!await g({title:h(`compositionEditor.templates.confirmTitle`),message:h(`compositionEditor.templates.confirmMessage`),confirmLabel:h(`compositionEditor.templates.confirmApply`),variant:`danger`})||d(e)},T=_.target.kind===`new`?_.target.type:r,E=async e=>{x(!0);let t=await f(e,_.name);x(!1),C(t.kind===`refused`?t.reason:null)};return i(`div`,{className:`flex flex-col gap-4`,children:[u&&_.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:h(`compositionEditor.templates.label`)}),ve.map(e=>s(m,{size:`sm`,variant:`outline`,onClick:()=>void w(e),children:h(`compositionEditor.templates.${e}`)},e))]}),s(mt,{draft:_,targetName:a,dispatch:v}),s(pt,{draft:_,deviceType:T,nativeCaps:c,targetFields:l,dispatch:v}),s(ht,{draft:_,blockId:n,saving:y,onSave:e=>void E(e),onCancel:p}),S!==null&&s(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:S})]})}export{De as C,pe as D,F as E,fe as O,Ee as S,Ce as T,q as _,qe as a,Ae as b,J as c,Ne as d,Fe as f,Le as g,Be as h,tt as i,je as l,ze as m,ot as n,X as o,Re as p,at as r,Y as s,gt as t,K as u,Ie as v,we as w,U as x,Oe 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{Bi as n,Hn as r,Ni as i,ki as a}from"./src-
|
|
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{Bi as n,Hn as r,Ni as i,ki as a}from"./src-M02zmBCw.js";import{t as o}from"./boxes-N_8REhrI.js";import{Er as s,sr as c}from"./client-tKRKHAfe.js";import{t as l}from"./useTranslation-Bc5yH9V9.js";import{Q as u,Y as d,Z as f,g as p,x as m}from"./index-D_3-GXGK.js";import{E as h,O as g,T as _,t as v,w as y}from"./CompositionEditor-BaNYPdLs.js";import{t as b}from"./AdminPage-nt88IVlh.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=f(),D=a(),O=n(),k=w===void 0||w===x,A=i({blockId:w??``},{enabled:!k}),j=()=>{E(p)},M=e=>t(b,{icon:o,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(s.Sensor),blockId:null,deviceType:s.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(r,{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=c(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(d,{className:`text-primary`,to:m(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(d,{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{Q as l,_t as u,ct as d,gt as f,yt as p}from"./player-overlays-Gj8o_n4X.js";import{An as m,Bc as h,Cd as g,Ef as _,Fn as v,G as y,Gn as b,Hc as x,Hn as S,Ht as C,In as w,Jd as T,L as E,Mn as D,Of as O,Ou as k,Pn as A,Qd as j,Ql as M,R as N,Rr as P,Td as F,Uc as I,Un as L,Ut as R,Vc as z,Xd as B,Zl as V,ai as ee,ci as H,dd as te,di as ne,ei as re,fi as ie,ii as ae,jn as oe,kc as se,kf as ce,li as le,mi as U,nf as ue,ni as de,nl as fe,nr as W,of as pe,oi as me,pd as he,pi as ge,rd as G,ri as _e,si as K,tf as ve,ti as ye,ud as be,ui as xe,wd as Se,z as Ce}from"./src-CoX6DWRw.js";import{t as we}from"./circle-slash-BzeOqvpP.js";import{a as Te,c as Ee,l as De,n as Oe,o as ke,s as Ae,t as je,u as Me}from"./location-owned-usage-BopLei43.js";import{n as Ne,t as q}from"./format-size-BuyX1HQn.js";import{t as Pe}from"./useTranslation-Bc5yH9V9.js";import"./mount-CdxP7UkM.js";import{C as Fe}from"./index-CacciakK.js";import{t as Ie}from"./AdminSectionedPage-fCCbEY4X.js";import{t as Le}from"./AdminPage-CypZrzwh.js";import{n as Re}from"./authed-media-DmJCnyAU.js";var J=p(`calendar-clock`,[[`path`,{d:`M16 14v2.2l1.6 1`,key:`fo4ql5`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]),ze=p(`cloud-upload`,[[`path`,{d:`M12 13v8`,key:`1l5pq0`}],[`path`,{d:`M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242`,key:`1pljnt`}],[`path`,{d:`m8 17 4-4 4 4`,key:`1quai1`}]]);t();function Be(){let e=a(),t=W(),{data:i,isLoading:o,isError:l}=I({}),u=x(),d=r(()=>u.data??[],[u.data]),{data:f}=se({},{refetchOnWindowFocus:!1}),p=r(()=>je(i??[],f?.locations),[i,f?.locations]),{data:m}=z({},{refetchOnWindowFocus:!1}),g=r(()=>Te(m),[m]),{state:_,openNew:v,openEdit:y,close:b}=E(),[S,C]=N(`type`),w=()=>{C(null),b()},T=e=>{C(e),v()},D=e=>{C(null),y(e.id)},O=i??[],k=_.mode===`edit`?O.find(e=>e.id===_.id)??null:null;c(()=>{_.mode===`new`&&(S===null||S===``)&&(C(null),b())},[_.mode,S,b,C]),c(()=>{_.mode===`edit`&&!o&&k===null&&(C(null),b())},[_.mode,o,k,b,C]),c(()=>{_.mode===`closed`&&S!==null&&C(null)},[_.mode,S,C]);let A=h({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),j=fe({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),M=async(e,n)=>{De(n)&&!await t({title:`Disable "${e.displayName}"?`,message:`${Ee(n).consequence}\n\nNothing is deleted — set the location back to Read-only or Active to bring its footage back.`,confirmLabel:`Disable`,variant:`danger`})||j.mutate(Ae(e,{mode:n}))},P=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 A.mutateAsync({id:e.id}),_.mode===`edit`&&_.id===e.id&&w()}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`})&&A.mutate({id:e.id,force:!0},{onSuccess:()=>{_.mode===`edit`&&_.id===e.id&&w()}})}},F=r(()=>{let e=new Map;for(let t of i??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[i]),L=o||u.isLoading,R=l||u.isError,B=_.mode===`new`&&S!==null&&S!==``,V=_.mode===`edit`&&k!==null;return n(Le,{embedded:!0,children:[L&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),R&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!L&&!R&&n(`div`,{className:`space-y-3`,children:[d.length===0&&s(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:`No storage locations declared by any installed addon.`}),d.map(e=>s(Oe,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:F.get(e.id)??[],onAdd:T,onEdit:D,onDelete:e=>{P(e)},ownedBytesById:p,drainById:g,onSetMode:(e,t)=>{M(e,t)}},e.id))]}),B&&S!==null&&s(Me,{initialType:S,onClose:w,onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),w()}}),V&&k!==null&&s(ke,{location:k,onClose:w,onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),w()}})]})}t();var Ve=[[`backup`,`listDestinations`]],He=[`backup`,`listArchives`];function Ue({destinationId:t,restoreSupported:i,onOpenRestoreWizard:c}){let l=a(),u=W(),{data:f,isLoading:p,isError:m}=me({destinationId:t}),h=f??[],_=ye({onSuccess:()=>{l.invalidateQueries({queryKey:[[...He]]}),l.invalidateQueries({queryKey:Ve})}}),v=e(async e=>{await u({title:`Delete this archive?`,message:`Permanently deletes "${e.label??e.id}" and frees ${q(e.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&_.mutate({destinationId:t,backupId:e.id})},[u,t,_]),[y,b]=o(null),x=e(async e=>{b(e.id);try{let n=await Re(We(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{b(null)}},[t]),S=r(()=>[...h].toSorted((e,t)=>t.createdAt-e.createdAt),[h]);return p?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):m?s(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):S.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):s(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[640px]`,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:`When`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),s(`tbody`,{children:S.map(e=>n(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:Ge(e.createdAt)}),s(`td`,{className:`px-3 py-1.5 text-foreground`,children:n(`span`,{className:`inline-flex items-center gap-1`,children:[e.encryption!==void 0&&s(g,{className:`h-3 w-3 text-success`,"aria-label":`encrypted — restore needs backup key ${e.encryption.keyId}`}),e.label??s(`span`,{className:`text-foreground-subtle italic`,children:`—`})]})}),s(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:e.locations.join(`, `)}),s(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:q(e.sizeBytes)}),s(`td`,{className:`px-3 py-1.5`,children:n(`div`,{className:`flex items-center justify-end gap-1`,children:[n(`button`,{onClick:()=>{x(e)},disabled:y===e.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 disabled:opacity-50`,title:`Download archive`,children:[y===e.id?s(F,{className:`h-3 w-3 animate-spin`}):s(T,{className:`h-3 w-3`}),`Download`]}),i&&c&&n(`button`,{onClick:()=>c({destinationId:t,archiveId:e.id}),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-primary hover:bg-primary/10`,title:`Restore from this archive`,children:[s(G,{className:`h-3 w-3`}),`Restore`]}),s(`button`,{onClick:()=>{v(e)},disabled:_.isPending,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:`Delete archive`,children:_.isPending?s(F,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`})})]})})]},e.id))})]})})}function We(e,t){return l(`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}function Ge(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}t();var Y=[[`backup`,`listSchedules`]];function Ke({onEdit:t,onOpenRestoreWizard:i}){let{data:a,isLoading:c,isError:l,error:u,refetch:d}=le(),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(()=>qe({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(F,{className:`h-3.5 w-3.5 animate-spin`}),`Loading backup entries…`]}):l?s(S,{title:`Failed to load backup entries`,message:u instanceof Error?u.message:`Unknown error`,onRetry:()=>void d()}):f.length===0?s(L,{icon:J,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(C,{columns:y,rows:f,rowKey:e=>e.id,minWidthPx:820,maxBodyHeight:R,mobileMode:`scroll`,emptyMessage:`No backup entries yet`,onRowClick:e=>t(e)}),v!==null&&s(et,{row:v,destById:m,...i?{onOpenRestoreWizard:i}:{}})]})}function qe(e){return[{key:`expand`,header:``,width:`w-8`,nowrap:!0,notSortableReason:`Expand control`,render:t=>{let n=e.expandedId===t.id;return s(M,{variant:`ghost`,size:`sm`,icon:n?u:f,"aria-label":n?`Hide archives`:`Show archives`,"aria-expanded":n,onClick:n=>{n.stopPropagation(),e.onToggleExpand(t.id)}})}},{key:`entry`,header:`Entry`,sortValue:e=>e.label,render:e=>n(`span`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate font-medium text-foreground`,children:e.label||`(unnamed)`}),e.lastRunAt!==void 0&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`last run `,new Date(e.lastRunAt).toLocaleString()]})]})},{key:`enabled`,header:`Enabled`,width:`w-20`,nowrap:!0,sortValue:e=>+!!e.enabled,render:e=>s(`span`,{onClick:e=>e.stopPropagation(),children:s(Ze,{row:e})})},{key:`locations`,header:`Locations`,nowrap:!1,notSortableReason:`Location chips`,render:t=>s(Je,{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(Qe,{row:e})})},{key:`schedule`,header:`Schedule`,width:`w-48`,nowrap:!0,sortValue:e=>e.cron,render:e=>s(Ye,{row:e})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:t=>s(`span`,{onClick:e=>e.stopPropagation(),children:s($e,{row:t,onEdit:()=>e.onEdit(t)})})}]}function Je({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 Ye({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(J,{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 Xe(e){return r(()=>({id:e.id,label:e.label,cron:e.cron,locationIds:[...e.locationIds],retentionCount:e.retentionCount,...e.dataSources?{dataSources:[...e.dataSources]}:{}}),[e])}function Ze({row:e}){let t=a(),n=U({onSuccess:()=>{t.invalidateQueries({queryKey:Y})}}),r=Xe(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 Qe({row:e}){let t=a(),n=U({onSuccess:()=>{t.invalidateQueries({queryKey:Y})}}),r=Xe(e),[i,l]=o(String(e.retentionCount));return c(()=>{l(String(e.retentionCount))},[e.retentionCount]),s(V,{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 $e({row:e,onEdit:t}){let r=a(),i=W(),o=de({onSuccess:()=>{r.invalidateQueries({queryKey:Y})}}),c=ge({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})},u=async()=>{await i({title:`Delete backup entry?`,message:`"${e.label||e.id}" will stop running. Existing archives are kept.`,confirmLabel:`Delete`,variant:`warning`})&&o.mutate({id:e.id})};return n(`span`,{className:`flex items-center justify-end gap-1.5`,children:[n(b,{size:`sm`,type:`button`,onClick:l,disabled:c.isPending||e.locationIds.length===0,title:`Run this entry now`,children:[c.isPending?s(F,{className:`h-3 w-3 animate-spin`}):s(te,{className:`h-3 w-3`}),`Run now`]}),s(M,{variant:`ghost`,size:`sm`,icon:he,"aria-label":`Edit ${e.label||e.id}`,onClick:t}),s(M,{variant:`ghost`,size:`sm`,icon:d,"aria-label":`Delete ${e.label||e.id}`,disabled:o.isPending,onClick:()=>{u()}})]})}function et({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(Ue,{destinationId:e,restoreSupported:t.get(e)?.restoreSupported??!0,...r?{onOpenRestoreWizard:r}:{}})]},e))]})}t();function X(e){return e===null?`—`:new Date(e).toLocaleString()}function tt(e){let t=new Blob([`${e.secretKey}\n`],{type:`text/plain`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`camstack-backup-key-${e.keyId}.txt`,r.click(),URL.revokeObjectURL(n)}function nt({revealed:e,onDone:t}){let[r,i]=o(!1),[a,c]=o(!1);return s(m,{open:!0,onOpenChange:e=>!e&&r&&t(),children:n(D,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`border-danger/40`,"aria-labelledby":`backup-key-title`,children:[s(v,{children:n(w,{id:`backup-key-title`,children:[`Your backup key (`,e.keyId,`)`]})}),n(oe,{className:`space-y-3`,children:[n(`p`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 p-2 text-xs text-foreground`,children:[s(k,{className:`mt-0.5 h-4 w-4 shrink-0 text-danger`}),s(`span`,{children:`This key is shown only once. CamStack does not keep it — not the hub, not its database, not its backups. Without it, an encrypted backup cannot be restored by anyone, including you. Store it in a password manager or print it, away from this server.`})]}),s(`div`,{className:`break-all rounded-md border border-border bg-background p-2 font-mono text-xs text-foreground select-all`,children:e.secretKey}),n(`div`,{className:`flex flex-wrap gap-2`,children:[n(b,{size:`sm`,variant:`outline`,onClick:()=>{navigator.clipboard?.writeText(e.secretKey).then(()=>c(!0))},children:[s(j,{className:`mr-1 h-3.5 w-3.5`}),a?`Copied`:`Copy`]}),n(b,{size:`sm`,variant:`outline`,onClick:()=>tt(e),children:[s(T,{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(A,{children:s(b,{size:`sm`,disabled:!r,onClick:t,children:`I have stored it`})})]})})}function rt(){let e=ae(),t=ie(),r=_e(),a=W(),[c,l]=o(null),[u,d]=o(null),f=e.data?.enabled??!1,p=e.data?.active??null,m=(e.data?.keys??[]).filter(e=>e.retiredAt!==null),h=async()=>{if(await a({title:f?`Replace the backup key`:`Encrypt backups`,message:f?`A new key is generated and shown once; new backups are encrypted to it. Older backups keep needing the key they were made with — keep that one too.`:`A backup key is generated and shown once. Every new backup is encrypted to it, and restoring one will ask for it. Existing backups stay as they are.`,confirmLabel:f?`Generate a new key`:`Generate the key`,variant:`warning`})){d(null);try{let e=await t.mutateAsync({});l({keyId:e.keyId,secretKey:e.secretKey})}catch(e){d(e instanceof Error?e.message:String(e))}}},_=async()=>{if(await a({title:`Turn backup encryption off`,message:`New backups will be written unencrypted. Existing encrypted backups still need their key to be restored.`,confirmLabel:`Turn off`,variant:`danger`})){d(null);try{await r.mutateAsync({}),e.refetch()}catch(e){d(e instanceof Error?e.message:String(e))}}};return n(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-4`,children:[n(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[n(`div`,{className:`flex items-center gap-2`,children:[f?s(g,{className:`h-4 w-4 text-success`}):s(Se,{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 ${X(p.createdAt)}`:`Off — backups are not encrypted`})]}),s(`div`,{className:`flex gap-2`,children:f?n(i,{children:[s(b,{size:`sm`,variant:`outline`,disabled:t.isPending,onClick:()=>void h(),children:`Replace key`}),s(b,{size:`sm`,variant:`outline`,disabled:r.isPending,onClick:()=>void _(),children:`Turn off`})]}):s(b,{size:`sm`,disabled:t.isPending,onClick:()=>void h(),children:`Enable encryption`})})]}),s(`p`,{className:`text-xs text-foreground-subtle`,children:`Archives are encrypted on this server before they reach any destination. The server keeps only a public key, so it can encrypt scheduled backups but cannot decrypt them — only your backup key can. Covers the database snapshot, config.yaml, addon data (HomeKit pairing, Matter fabric, Tailscale state) and TLS.`}),m.length>0&&n(`div`,{className:`text-xs`,children:[s(`p`,{className:`text-foreground-subtle`,children:`Older keys (backups made with them still need them):`}),s(`ul`,{className:`font-mono text-foreground`,children:m.map(e=>n(`li`,{children:[e.keyId,` · `,X(e.createdAt),` → `,X(e.retiredAt)]},e.keyId))})]}),u!==null&&s(`p`,{className:`text-xs text-danger`,children:u}),c!==null&&s(nt,{revealed:c,onDone:()=>{l(null),e.refetch()}})]})}t();var it=[{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 at(e){let t=e.trim();for(let e of it)if(e.cron===t)return e.id;return`custom`}function ot({value:e,onChange:t,previewCount:r=5,disabled:i=!1}){let a=at(e),[l,u]=o(a===`custom`);c(()=>{a!==`custom`&&u(!1)},[a]);let d=lt(e,250),f=xe({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:[it.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(st,{cron:d,preview:p,loading:f.isFetching})]})}function st({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(F,{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:ct(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 ct(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 lt(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 ut=[[`backup`,`listSchedules`]];function dt({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)),[x,S]=o(new Set(e?.locationIds??[])),C=U({onSuccess:()=>{c.invalidateQueries({queryKey:ut}),i()}}),w=e=>{S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},T=Number.parseInt(_,10),E=r(()=>d.trim().length>0&&x.size>0&&!Number.isNaN(T)&&T>=1&&T<=1e3,[d,x,T]),D=()=>{E&&C.mutate({...e?{id:e.id}:{},label:d.trim(),cron:p.trim(),enabled:h,locationIds:Array.from(x),retentionCount:T})},O=C.error instanceof Error?C.error.message:null;return s(Ce,{open:!0,onClose:t,title:e?`Edit backup entry`:`New backup entry`,icon:J,error:O,width:`lg`,testId:`backup-entry-form`,footer:n(b,{size:`sm`,type:`button`,onClick:D,disabled:!E||C.isPending,children:[C.isPending?s(F,{className:`h-3.5 w-3.5 animate-spin`}):null,e?`Save`:`Create entry`]}),children:n(`div`,{className:`space-y-4`,children:[s(y,{label:`Name`,required:!0,children:s(V,{value:d,onChange:e=>f(e.target.value),placeholder:`Nightly offsite`,autoFocus:!0,"data-testid":`backup-entry-name`})}),n(y,{label:`Locations (${String(x.size)} selected)`,required:!0,children:[l.isLoading&&n(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[s(F,{className:`h-3.5 w-3.5 animate-spin`}),`Loading locations…`]}),!l.isLoading&&u.length===0&&s(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:"No `backups` storage locations configured. Add one in Settings → Storage first."}),u.length>0&&s(`div`,{className:`max-h-52 divide-y divide-border overflow-y-auto rounded border border-border bg-background`,children:u.map(e=>n(`label`,{className:`flex cursor-pointer items-center justify-between px-3 py-2 text-xs hover:bg-primary/5`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`checkbox`,checked:x.has(e.id),onChange:()=>w(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))})]}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[s(y,{label:`Retention (archives kept)`,required:!0,children:s(V,{type:`number`,min:1,max:1e3,value:_,onChange:e=>v(e.target.value),"data-testid":`backup-entry-retention`})}),s(y,{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(y,{label:`Schedule`,children:s(ot,{value:p,onChange:m,disabled:C.isPending})})]})})}t();var ft=2e3,pt=5e3;function Z(e){return e.state===`queued`||e.state===`running`}function mt(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 ht(){let t=W(),[n,r]=o(null),i=H(void 0,{refetchInterval:e=>(e.state.data??[]).some(Z)?ft:pt}),a=re({onSettled:()=>{r(null),i.refetch()}}),c=e(async e=>{await t(mt(e))&&(r(e.id),a.mutate({runId:e.id}))},[t,a]);return s(gt,{queryState:i.isError?`error`:i.data===void 0?`pending`:`ready`,runs:i.data??[],cancelingId:n,onCancelRequest:e=>{c(e)},now:Date.now()})}function gt({queryState:e,runs:t,cancelingId:r,onCancelRequest:i,now:a}){let o=e===`ready`&&t.some(Z),c=t.filter(e=>e.state===`running`),l=t.filter(e=>e.state===`queued`),u=t.filter(e=>!Z(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(_t,{run:e,canceling:r===e.id,onCancelRequest:i,now:a},e.id))})]})})]})}function _t({run:e,canceling:t,onCancelRequest:r,now:i}){let a=Z(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(vt,{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(yt,{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(xt,{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(F,{className:`h-3 w-3 animate-spin`}):s(_,{className:`h-3 w-3`}),e.state===`queued`?`Cancel`:`Stop`]})})})]})}function vt({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(ve,{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(F,{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(pe,{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(ue,{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(we,{className:`h-3 w-3`}),`Stopped`]})}}function yt({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:St(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(Ne,{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(ze,{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 xt({run:e,now:t}){return e.state===`queued`?n(`span`,{children:[`queued `,Q(t-e.requestedAt),` ago`]}):e.startedAt===void 0?s(`span`,{children:`—`}):e.finishedAt===void 0?n(`span`,{children:[`running for `,Q(t-e.startedAt)]}):n(`div`,{className:`flex flex-col gap-0.5`,children:[s(`span`,{children:Ct(e.finishedAt)}),n(`span`,{className:`text-[10px]`,children:[`took `,Q(e.finishedAt-e.startedAt)]})]})}function St(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 Q(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 Ct(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}t();var wt=[[`backup`,`list`]];function Tt({initialDestinationId:e,initialArchiveId:t,onClose:i,onScheduled:l}){let u=a(),[d,f]=o(e&&t?2:1),[p,h]=o(e),[g,_]=o(t),[y,x]=o(new Set),[S,C]=o(``),{data:T}=K(),E=T??[],{data:k,isLoading:j}=me({destinationId:p??``},{enabled:!!p}),M=k??[];c(()=>{if(p!==void 0)return;let e=E.filter(e=>e.restoreSupported);e.length===1&&h(e[0].id)},[p,E]);let{data:N}=ee({destinationId:p??``,backupId:g??``},{enabled:!!p&&!!g}),P=r(()=>N?.locations??[],[N]);c(()=>{P.length!==0&&x(e=>e.size===0?new Set(P):e)},[P]);let I=ne({onSuccess:()=>{u.invalidateQueries({queryKey:wt}),l(),i()}}),L=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},R=M.find(e=>e.id===g),z=R?.encryption!==void 0,B=!!p&&!!g,V=y.size>0,H=B&&V&&!I.isPending&&(!z||S.trim().length>0),te=()=>{!p||!g||I.mutate({destinationId:p,backupId:g,locations:[...y],...z?{backupSecretKey:S.trim()}:{}})};return s(m,{open:!0,onOpenChange:e=>!e&&i(),children:n(D,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[n(v,{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(oe,{children:[d===1&&s(Et,{destinations:E,destinationId:p,onPickDestination:e=>{h(e),_(void 0),x(new Set)},archives:M,archivesLoading:j,archiveId:g,onPickArchive:_}),d===2&&s(Dt,{locations:P,picked:y,onToggle:L}),d===3&&s(Ot,{destinationName:E.find(e=>e.id===p)?.displayName??p??``,archive:R,picked:[...y]}),d===3&&R?.encryption!==void 0&&s(kt,{keyId:R.encryption.keyId,value:S,onChange:C}),d===3&&I.error&&s(`p`,{role:`alert`,className:`px-4 pb-2 text-xs text-danger`,children:I.error.message})]}),n(A,{className:`justify-between`,children:[s(`div`,{children:d>1&&n(b,{variant:`outline`,size:`sm`,onClick:()=>f(e=>e===3?2:1),children:[s(ce,{className:`h-3 w-3`}),`Back`]})}),n(`div`,{className:`flex items-center gap-2`,children:[s(b,{variant:`outline`,size:`sm`,onClick:i,children:`Cancel`}),d<3?n(b,{size:`sm`,disabled:d===1&&!B||d===2&&!V,onClick:()=>f(e=>e===1?2:3),children:[`Next`,s(O,{className:`h-3 w-3`})]}):n(b,{size:`sm`,onClick:te,disabled:!H,children:[I.isPending?s(F,{className:`h-3.5 w-3.5 animate-spin`}):s(G,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function Et({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`}),n(`select`,{value:t??``,onChange:e=>r(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:[s(`option`,{value:``,disabled:!0,children:`Select destination…`}),l.map(e=>n(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&a&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!a&&i.length===0&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&i.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:i.map(e=>{let t=o===e.id;return n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>c(e.id),className:`accent-primary`}),n(`div`,{children:[n(`div`,{className:`flex items-center gap-1 font-medium text-foreground`,children:[e.encryption!==void 0&&s(g,{className:`h-3 w-3 text-success`,"aria-label":`encrypted (key ${e.encryption.keyId})`}),e.label??e.id]}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),s(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:q(e.sizeBytes)})]},e.id)})})]})]})}function Dt({locations:e,picked:t,onToggle:r}){return 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:[s(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,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:jt(e)})]},e))})]})]})}function Ot({destinationName:e,archive:t,picked:r}){return n(`div`,{className:`p-4 space-y-3 text-xs`,children:[s(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-300`,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:`Locations`,value:r.length>0?r.join(`, `):`— (full archive)`})]})]})}function kt({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 At={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function jt(e){return At[e]??``}t();function Mt(){let e=W(),t=P(),{state:r,openNew:a,openEdit:l,close:u}=E({editKey:`edit`,newKey:`new`}),d=le(),f=d.data??[],[p,m]=o(null),[h,g]=o(!1),[_,v]=o(!1),y=r.mode===`edit`?f.find(e=>e.id===r.id)??null:null;c(()=>{r.mode===`edit`&&!d.isLoading&&y===null&&u()},[r.mode,d.isLoading,y,u]);let x=r.mode===`new`||r.mode===`edit`&&y!==null,S=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(Le,{embedded:!0,actions:n(i,{children:[n(b,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>g(!0),children:[s(G,{className:`h-3.5 w-3.5`}),`Restore…`]}),n(b,{size:`sm`,type:`button`,onClick:a,"data-testid":`backup-new-entry`,children:[s(be,{className:`h-3.5 w-3.5`}),`New entry`]})]}),children:[_&&s(`div`,{className:`rounded-lg border border-warning/30 bg-warning/10 px-3 py-2.5 text-xs text-warning`,children:n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(G,{className:`h-3.5 w-3.5`}),s(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),n(b,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>{S()},disabled:t.isPending,children:[t.isPending?s(F,{className:`h-3.5 w-3.5 animate-spin`}):s(G,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),s(rt,{}),s(ht,{}),s(Ke,{onEdit:e=>l(e.id),onOpenRestoreWizard:e=>m(e)}),x&&s(dt,{entry:y,onClose:u,onSaved:u}),(p||h)&&s(Tt,{...p?{initialDestinationId:p.destinationId,initialArchiveId:p.archiveId}:{},onClose:()=>{m(null),g(!1)},onScheduled:()=>v(!0)})]})}function Nt(){let{t:e}=Pe(),t=Fe(`/system/data`,{t:e,isAdmin:!0})??{icon:B,title:e(`system.data`,`Data`)};return s(Ie,{icon:t.icon,title:t.title,defaultSection:`storage`,sectionsLabel:`${t.title} sections`,sections:[{id:`storage`,label:`Storage`,content:s(Be,{})},{id:`backup`,label:`Backup`,content:s(Mt,{})}]})}export{Nt 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{Q as l,_t as u,ct as d,gt as f,yt as p}from"./player-overlays-Gj8o_n4X.js";import{An as m,Bc as h,Cd as g,Ef as _,Fn as v,G as y,Gn as b,Hc as x,Hn as S,Ht as C,In as w,Jd as T,L as E,Mn as D,Of as O,Ou as k,Pn as A,Qd as j,Ql as M,R as N,Rr as P,Td as F,Uc as I,Un as L,Ut as R,Vc as z,Xd as B,Zl as V,ai as ee,ci as H,dd as te,di as ne,ei as re,fi as ie,ii as ae,jn as oe,kc as se,kf as ce,li as le,mi as U,nf as ue,ni as de,nl as fe,nr as W,of as pe,oi as me,pd as he,pi as ge,rd as G,ri as _e,si as K,tf as ve,ti as ye,ud as be,ui as xe,wd as Se,z as Ce}from"./src-M02zmBCw.js";import{t as we}from"./circle-slash-BzeOqvpP.js";import{a as Te,c as Ee,l as De,n as Oe,o as ke,s as Ae,t as je,u as Me}from"./location-owned-usage-B7AdEDxo.js";import{n as Ne,t as q}from"./format-size-BuyX1HQn.js";import{t as Pe}from"./useTranslation-Bc5yH9V9.js";import"./mount-BizCkD6A.js";import{C as Fe}from"./index-D_3-GXGK.js";import{t as Ie}from"./AdminSectionedPage-3qgyliDm.js";import{t as Le}from"./AdminPage-nt88IVlh.js";import{n as Re}from"./authed-media-CmNMcsPz.js";var J=p(`calendar-clock`,[[`path`,{d:`M16 14v2.2l1.6 1`,key:`fo4ql5`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]),ze=p(`cloud-upload`,[[`path`,{d:`M12 13v8`,key:`1l5pq0`}],[`path`,{d:`M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242`,key:`1pljnt`}],[`path`,{d:`m8 17 4-4 4 4`,key:`1quai1`}]]);t();function Be(){let e=a(),t=W(),{data:i,isLoading:o,isError:l}=I({}),u=x(),d=r(()=>u.data??[],[u.data]),{data:f}=se({},{refetchOnWindowFocus:!1}),p=r(()=>je(i??[],f?.locations),[i,f?.locations]),{data:m}=z({},{refetchOnWindowFocus:!1}),g=r(()=>Te(m),[m]),{state:_,openNew:v,openEdit:y,close:b}=E(),[S,C]=N(`type`),w=()=>{C(null),b()},T=e=>{C(e),v()},D=e=>{C(null),y(e.id)},O=i??[],k=_.mode===`edit`?O.find(e=>e.id===_.id)??null:null;c(()=>{_.mode===`new`&&(S===null||S===``)&&(C(null),b())},[_.mode,S,b,C]),c(()=>{_.mode===`edit`&&!o&&k===null&&(C(null),b())},[_.mode,o,k,b,C]),c(()=>{_.mode===`closed`&&S!==null&&C(null)},[_.mode,S,C]);let A=h({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),j=fe({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),M=async(e,n)=>{De(n)&&!await t({title:`Disable "${e.displayName}"?`,message:`${Ee(n).consequence}\n\nNothing is deleted — set the location back to Read-only or Active to bring its footage back.`,confirmLabel:`Disable`,variant:`danger`})||j.mutate(Ae(e,{mode:n}))},P=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 A.mutateAsync({id:e.id}),_.mode===`edit`&&_.id===e.id&&w()}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`})&&A.mutate({id:e.id,force:!0},{onSuccess:()=>{_.mode===`edit`&&_.id===e.id&&w()}})}},F=r(()=>{let e=new Map;for(let t of i??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[i]),L=o||u.isLoading,R=l||u.isError,B=_.mode===`new`&&S!==null&&S!==``,V=_.mode===`edit`&&k!==null;return n(Le,{embedded:!0,children:[L&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),R&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!L&&!R&&n(`div`,{className:`space-y-3`,children:[d.length===0&&s(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:`No storage locations declared by any installed addon.`}),d.map(e=>s(Oe,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:F.get(e.id)??[],onAdd:T,onEdit:D,onDelete:e=>{P(e)},ownedBytesById:p,drainById:g,onSetMode:(e,t)=>{M(e,t)}},e.id))]}),B&&S!==null&&s(Me,{initialType:S,onClose:w,onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),w()}}),V&&k!==null&&s(ke,{location:k,onClose:w,onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),w()}})]})}t();var Ve=[[`backup`,`listDestinations`]],He=[`backup`,`listArchives`];function Ue({destinationId:t,restoreSupported:i,onOpenRestoreWizard:c}){let l=a(),u=W(),{data:f,isLoading:p,isError:m}=me({destinationId:t}),h=f??[],_=ye({onSuccess:()=>{l.invalidateQueries({queryKey:[[...He]]}),l.invalidateQueries({queryKey:Ve})}}),v=e(async e=>{await u({title:`Delete this archive?`,message:`Permanently deletes "${e.label??e.id}" and frees ${q(e.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&_.mutate({destinationId:t,backupId:e.id})},[u,t,_]),[y,b]=o(null),x=e(async e=>{b(e.id);try{let n=await Re(We(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{b(null)}},[t]),S=r(()=>[...h].toSorted((e,t)=>t.createdAt-e.createdAt),[h]);return p?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):m?s(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):S.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):s(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[640px]`,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:`When`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),s(`tbody`,{children:S.map(e=>n(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:Ge(e.createdAt)}),s(`td`,{className:`px-3 py-1.5 text-foreground`,children:n(`span`,{className:`inline-flex items-center gap-1`,children:[e.encryption!==void 0&&s(g,{className:`h-3 w-3 text-success`,"aria-label":`encrypted — restore needs backup key ${e.encryption.keyId}`}),e.label??s(`span`,{className:`text-foreground-subtle italic`,children:`—`})]})}),s(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:e.locations.join(`, `)}),s(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:q(e.sizeBytes)}),s(`td`,{className:`px-3 py-1.5`,children:n(`div`,{className:`flex items-center justify-end gap-1`,children:[n(`button`,{onClick:()=>{x(e)},disabled:y===e.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 disabled:opacity-50`,title:`Download archive`,children:[y===e.id?s(F,{className:`h-3 w-3 animate-spin`}):s(T,{className:`h-3 w-3`}),`Download`]}),i&&c&&n(`button`,{onClick:()=>c({destinationId:t,archiveId:e.id}),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-primary hover:bg-primary/10`,title:`Restore from this archive`,children:[s(G,{className:`h-3 w-3`}),`Restore`]}),s(`button`,{onClick:()=>{v(e)},disabled:_.isPending,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:`Delete archive`,children:_.isPending?s(F,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`})})]})})]},e.id))})]})})}function We(e,t){return l(`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}function Ge(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}t();var Y=[[`backup`,`listSchedules`]];function Ke({onEdit:t,onOpenRestoreWizard:i}){let{data:a,isLoading:c,isError:l,error:u,refetch:d}=le(),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(()=>qe({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(F,{className:`h-3.5 w-3.5 animate-spin`}),`Loading backup entries…`]}):l?s(S,{title:`Failed to load backup entries`,message:u instanceof Error?u.message:`Unknown error`,onRetry:()=>void d()}):f.length===0?s(L,{icon:J,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(C,{columns:y,rows:f,rowKey:e=>e.id,minWidthPx:820,maxBodyHeight:R,mobileMode:`scroll`,emptyMessage:`No backup entries yet`,onRowClick:e=>t(e)}),v!==null&&s(et,{row:v,destById:m,...i?{onOpenRestoreWizard:i}:{}})]})}function qe(e){return[{key:`expand`,header:``,width:`w-8`,nowrap:!0,notSortableReason:`Expand control`,render:t=>{let n=e.expandedId===t.id;return s(M,{variant:`ghost`,size:`sm`,icon:n?u:f,"aria-label":n?`Hide archives`:`Show archives`,"aria-expanded":n,onClick:n=>{n.stopPropagation(),e.onToggleExpand(t.id)}})}},{key:`entry`,header:`Entry`,sortValue:e=>e.label,render:e=>n(`span`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate font-medium text-foreground`,children:e.label||`(unnamed)`}),e.lastRunAt!==void 0&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`last run `,new Date(e.lastRunAt).toLocaleString()]})]})},{key:`enabled`,header:`Enabled`,width:`w-20`,nowrap:!0,sortValue:e=>+!!e.enabled,render:e=>s(`span`,{onClick:e=>e.stopPropagation(),children:s(Ze,{row:e})})},{key:`locations`,header:`Locations`,nowrap:!1,notSortableReason:`Location chips`,render:t=>s(Je,{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(Qe,{row:e})})},{key:`schedule`,header:`Schedule`,width:`w-48`,nowrap:!0,sortValue:e=>e.cron,render:e=>s(Ye,{row:e})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:t=>s(`span`,{onClick:e=>e.stopPropagation(),children:s($e,{row:t,onEdit:()=>e.onEdit(t)})})}]}function Je({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 Ye({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(J,{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 Xe(e){return r(()=>({id:e.id,label:e.label,cron:e.cron,locationIds:[...e.locationIds],retentionCount:e.retentionCount,...e.dataSources?{dataSources:[...e.dataSources]}:{}}),[e])}function Ze({row:e}){let t=a(),n=U({onSuccess:()=>{t.invalidateQueries({queryKey:Y})}}),r=Xe(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 Qe({row:e}){let t=a(),n=U({onSuccess:()=>{t.invalidateQueries({queryKey:Y})}}),r=Xe(e),[i,l]=o(String(e.retentionCount));return c(()=>{l(String(e.retentionCount))},[e.retentionCount]),s(V,{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 $e({row:e,onEdit:t}){let r=a(),i=W(),o=de({onSuccess:()=>{r.invalidateQueries({queryKey:Y})}}),c=ge({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})},u=async()=>{await i({title:`Delete backup entry?`,message:`"${e.label||e.id}" will stop running. Existing archives are kept.`,confirmLabel:`Delete`,variant:`warning`})&&o.mutate({id:e.id})};return n(`span`,{className:`flex items-center justify-end gap-1.5`,children:[n(b,{size:`sm`,type:`button`,onClick:l,disabled:c.isPending||e.locationIds.length===0,title:`Run this entry now`,children:[c.isPending?s(F,{className:`h-3 w-3 animate-spin`}):s(te,{className:`h-3 w-3`}),`Run now`]}),s(M,{variant:`ghost`,size:`sm`,icon:he,"aria-label":`Edit ${e.label||e.id}`,onClick:t}),s(M,{variant:`ghost`,size:`sm`,icon:d,"aria-label":`Delete ${e.label||e.id}`,disabled:o.isPending,onClick:()=>{u()}})]})}function et({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(Ue,{destinationId:e,restoreSupported:t.get(e)?.restoreSupported??!0,...r?{onOpenRestoreWizard:r}:{}})]},e))]})}t();function X(e){return e===null?`—`:new Date(e).toLocaleString()}function tt(e){let t=new Blob([`${e.secretKey}\n`],{type:`text/plain`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`camstack-backup-key-${e.keyId}.txt`,r.click(),URL.revokeObjectURL(n)}function nt({revealed:e,onDone:t}){let[r,i]=o(!1),[a,c]=o(!1);return s(m,{open:!0,onOpenChange:e=>!e&&r&&t(),children:n(D,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`border-danger/40`,"aria-labelledby":`backup-key-title`,children:[s(v,{children:n(w,{id:`backup-key-title`,children:[`Your backup key (`,e.keyId,`)`]})}),n(oe,{className:`space-y-3`,children:[n(`p`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 p-2 text-xs text-foreground`,children:[s(k,{className:`mt-0.5 h-4 w-4 shrink-0 text-danger`}),s(`span`,{children:`This key is shown only once. CamStack does not keep it — not the hub, not its database, not its backups. Without it, an encrypted backup cannot be restored by anyone, including you. Store it in a password manager or print it, away from this server.`})]}),s(`div`,{className:`break-all rounded-md border border-border bg-background p-2 font-mono text-xs text-foreground select-all`,children:e.secretKey}),n(`div`,{className:`flex flex-wrap gap-2`,children:[n(b,{size:`sm`,variant:`outline`,onClick:()=>{navigator.clipboard?.writeText(e.secretKey).then(()=>c(!0))},children:[s(j,{className:`mr-1 h-3.5 w-3.5`}),a?`Copied`:`Copy`]}),n(b,{size:`sm`,variant:`outline`,onClick:()=>tt(e),children:[s(T,{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(A,{children:s(b,{size:`sm`,disabled:!r,onClick:t,children:`I have stored it`})})]})})}function rt(){let e=ae(),t=ie(),r=_e(),a=W(),[c,l]=o(null),[u,d]=o(null),f=e.data?.enabled??!1,p=e.data?.active??null,m=(e.data?.keys??[]).filter(e=>e.retiredAt!==null),h=async()=>{if(await a({title:f?`Replace the backup key`:`Encrypt backups`,message:f?`A new key is generated and shown once; new backups are encrypted to it. Older backups keep needing the key they were made with — keep that one too.`:`A backup key is generated and shown once. Every new backup is encrypted to it, and restoring one will ask for it. Existing backups stay as they are.`,confirmLabel:f?`Generate a new key`:`Generate the key`,variant:`warning`})){d(null);try{let e=await t.mutateAsync({});l({keyId:e.keyId,secretKey:e.secretKey})}catch(e){d(e instanceof Error?e.message:String(e))}}},_=async()=>{if(await a({title:`Turn backup encryption off`,message:`New backups will be written unencrypted. Existing encrypted backups still need their key to be restored.`,confirmLabel:`Turn off`,variant:`danger`})){d(null);try{await r.mutateAsync({}),e.refetch()}catch(e){d(e instanceof Error?e.message:String(e))}}};return n(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-4`,children:[n(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[n(`div`,{className:`flex items-center gap-2`,children:[f?s(g,{className:`h-4 w-4 text-success`}):s(Se,{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 ${X(p.createdAt)}`:`Off — backups are not encrypted`})]}),s(`div`,{className:`flex gap-2`,children:f?n(i,{children:[s(b,{size:`sm`,variant:`outline`,disabled:t.isPending,onClick:()=>void h(),children:`Replace key`}),s(b,{size:`sm`,variant:`outline`,disabled:r.isPending,onClick:()=>void _(),children:`Turn off`})]}):s(b,{size:`sm`,disabled:t.isPending,onClick:()=>void h(),children:`Enable encryption`})})]}),s(`p`,{className:`text-xs text-foreground-subtle`,children:`Archives are encrypted on this server before they reach any destination. The server keeps only a public key, so it can encrypt scheduled backups but cannot decrypt them — only your backup key can. Covers the database snapshot, config.yaml, addon data (HomeKit pairing, Matter fabric, Tailscale state) and TLS.`}),m.length>0&&n(`div`,{className:`text-xs`,children:[s(`p`,{className:`text-foreground-subtle`,children:`Older keys (backups made with them still need them):`}),s(`ul`,{className:`font-mono text-foreground`,children:m.map(e=>n(`li`,{children:[e.keyId,` · `,X(e.createdAt),` → `,X(e.retiredAt)]},e.keyId))})]}),u!==null&&s(`p`,{className:`text-xs text-danger`,children:u}),c!==null&&s(nt,{revealed:c,onDone:()=>{l(null),e.refetch()}})]})}t();var it=[{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 at(e){let t=e.trim();for(let e of it)if(e.cron===t)return e.id;return`custom`}function ot({value:e,onChange:t,previewCount:r=5,disabled:i=!1}){let a=at(e),[l,u]=o(a===`custom`);c(()=>{a!==`custom`&&u(!1)},[a]);let d=lt(e,250),f=xe({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:[it.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(st,{cron:d,preview:p,loading:f.isFetching})]})}function st({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(F,{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:ct(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 ct(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 lt(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 ut=[[`backup`,`listSchedules`]];function dt({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)),[x,S]=o(new Set(e?.locationIds??[])),C=U({onSuccess:()=>{c.invalidateQueries({queryKey:ut}),i()}}),w=e=>{S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},T=Number.parseInt(_,10),E=r(()=>d.trim().length>0&&x.size>0&&!Number.isNaN(T)&&T>=1&&T<=1e3,[d,x,T]),D=()=>{E&&C.mutate({...e?{id:e.id}:{},label:d.trim(),cron:p.trim(),enabled:h,locationIds:Array.from(x),retentionCount:T})},O=C.error instanceof Error?C.error.message:null;return s(Ce,{open:!0,onClose:t,title:e?`Edit backup entry`:`New backup entry`,icon:J,error:O,width:`lg`,testId:`backup-entry-form`,footer:n(b,{size:`sm`,type:`button`,onClick:D,disabled:!E||C.isPending,children:[C.isPending?s(F,{className:`h-3.5 w-3.5 animate-spin`}):null,e?`Save`:`Create entry`]}),children:n(`div`,{className:`space-y-4`,children:[s(y,{label:`Name`,required:!0,children:s(V,{value:d,onChange:e=>f(e.target.value),placeholder:`Nightly offsite`,autoFocus:!0,"data-testid":`backup-entry-name`})}),n(y,{label:`Locations (${String(x.size)} selected)`,required:!0,children:[l.isLoading&&n(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[s(F,{className:`h-3.5 w-3.5 animate-spin`}),`Loading locations…`]}),!l.isLoading&&u.length===0&&s(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:"No `backups` storage locations configured. Add one in Settings → Storage first."}),u.length>0&&s(`div`,{className:`max-h-52 divide-y divide-border overflow-y-auto rounded border border-border bg-background`,children:u.map(e=>n(`label`,{className:`flex cursor-pointer items-center justify-between px-3 py-2 text-xs hover:bg-primary/5`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`checkbox`,checked:x.has(e.id),onChange:()=>w(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))})]}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[s(y,{label:`Retention (archives kept)`,required:!0,children:s(V,{type:`number`,min:1,max:1e3,value:_,onChange:e=>v(e.target.value),"data-testid":`backup-entry-retention`})}),s(y,{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(y,{label:`Schedule`,children:s(ot,{value:p,onChange:m,disabled:C.isPending})})]})})}t();var ft=2e3,pt=5e3;function Z(e){return e.state===`queued`||e.state===`running`}function mt(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 ht(){let t=W(),[n,r]=o(null),i=H(void 0,{refetchInterval:e=>(e.state.data??[]).some(Z)?ft:pt}),a=re({onSettled:()=>{r(null),i.refetch()}}),c=e(async e=>{await t(mt(e))&&(r(e.id),a.mutate({runId:e.id}))},[t,a]);return s(gt,{queryState:i.isError?`error`:i.data===void 0?`pending`:`ready`,runs:i.data??[],cancelingId:n,onCancelRequest:e=>{c(e)},now:Date.now()})}function gt({queryState:e,runs:t,cancelingId:r,onCancelRequest:i,now:a}){let o=e===`ready`&&t.some(Z),c=t.filter(e=>e.state===`running`),l=t.filter(e=>e.state===`queued`),u=t.filter(e=>!Z(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(_t,{run:e,canceling:r===e.id,onCancelRequest:i,now:a},e.id))})]})})]})}function _t({run:e,canceling:t,onCancelRequest:r,now:i}){let a=Z(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(vt,{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(yt,{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(xt,{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(F,{className:`h-3 w-3 animate-spin`}):s(_,{className:`h-3 w-3`}),e.state===`queued`?`Cancel`:`Stop`]})})})]})}function vt({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(ve,{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(F,{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(pe,{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(ue,{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(we,{className:`h-3 w-3`}),`Stopped`]})}}function yt({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:St(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(Ne,{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(ze,{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 xt({run:e,now:t}){return e.state===`queued`?n(`span`,{children:[`queued `,Q(t-e.requestedAt),` ago`]}):e.startedAt===void 0?s(`span`,{children:`—`}):e.finishedAt===void 0?n(`span`,{children:[`running for `,Q(t-e.startedAt)]}):n(`div`,{className:`flex flex-col gap-0.5`,children:[s(`span`,{children:Ct(e.finishedAt)}),n(`span`,{className:`text-[10px]`,children:[`took `,Q(e.finishedAt-e.startedAt)]})]})}function St(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 Q(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 Ct(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}t();var wt=[[`backup`,`list`]];function Tt({initialDestinationId:e,initialArchiveId:t,onClose:i,onScheduled:l}){let u=a(),[d,f]=o(e&&t?2:1),[p,h]=o(e),[g,_]=o(t),[y,x]=o(new Set),[S,C]=o(``),{data:T}=K(),E=T??[],{data:k,isLoading:j}=me({destinationId:p??``},{enabled:!!p}),M=k??[];c(()=>{if(p!==void 0)return;let e=E.filter(e=>e.restoreSupported);e.length===1&&h(e[0].id)},[p,E]);let{data:N}=ee({destinationId:p??``,backupId:g??``},{enabled:!!p&&!!g}),P=r(()=>N?.locations??[],[N]);c(()=>{P.length!==0&&x(e=>e.size===0?new Set(P):e)},[P]);let I=ne({onSuccess:()=>{u.invalidateQueries({queryKey:wt}),l(),i()}}),L=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},R=M.find(e=>e.id===g),z=R?.encryption!==void 0,B=!!p&&!!g,V=y.size>0,H=B&&V&&!I.isPending&&(!z||S.trim().length>0),te=()=>{!p||!g||I.mutate({destinationId:p,backupId:g,locations:[...y],...z?{backupSecretKey:S.trim()}:{}})};return s(m,{open:!0,onOpenChange:e=>!e&&i(),children:n(D,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[n(v,{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(oe,{children:[d===1&&s(Et,{destinations:E,destinationId:p,onPickDestination:e=>{h(e),_(void 0),x(new Set)},archives:M,archivesLoading:j,archiveId:g,onPickArchive:_}),d===2&&s(Dt,{locations:P,picked:y,onToggle:L}),d===3&&s(Ot,{destinationName:E.find(e=>e.id===p)?.displayName??p??``,archive:R,picked:[...y]}),d===3&&R?.encryption!==void 0&&s(kt,{keyId:R.encryption.keyId,value:S,onChange:C}),d===3&&I.error&&s(`p`,{role:`alert`,className:`px-4 pb-2 text-xs text-danger`,children:I.error.message})]}),n(A,{className:`justify-between`,children:[s(`div`,{children:d>1&&n(b,{variant:`outline`,size:`sm`,onClick:()=>f(e=>e===3?2:1),children:[s(ce,{className:`h-3 w-3`}),`Back`]})}),n(`div`,{className:`flex items-center gap-2`,children:[s(b,{variant:`outline`,size:`sm`,onClick:i,children:`Cancel`}),d<3?n(b,{size:`sm`,disabled:d===1&&!B||d===2&&!V,onClick:()=>f(e=>e===1?2:3),children:[`Next`,s(O,{className:`h-3 w-3`})]}):n(b,{size:`sm`,onClick:te,disabled:!H,children:[I.isPending?s(F,{className:`h-3.5 w-3.5 animate-spin`}):s(G,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function Et({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`}),n(`select`,{value:t??``,onChange:e=>r(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:[s(`option`,{value:``,disabled:!0,children:`Select destination…`}),l.map(e=>n(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&a&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!a&&i.length===0&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&i.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:i.map(e=>{let t=o===e.id;return n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>c(e.id),className:`accent-primary`}),n(`div`,{children:[n(`div`,{className:`flex items-center gap-1 font-medium text-foreground`,children:[e.encryption!==void 0&&s(g,{className:`h-3 w-3 text-success`,"aria-label":`encrypted (key ${e.encryption.keyId})`}),e.label??e.id]}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),s(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:q(e.sizeBytes)})]},e.id)})})]})]})}function Dt({locations:e,picked:t,onToggle:r}){return 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:[s(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,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:jt(e)})]},e))})]})]})}function Ot({destinationName:e,archive:t,picked:r}){return n(`div`,{className:`p-4 space-y-3 text-xs`,children:[s(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-300`,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:`Locations`,value:r.length>0?r.join(`, `):`— (full archive)`})]})]})}function kt({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 At={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function jt(e){return At[e]??``}t();function Mt(){let e=W(),t=P(),{state:r,openNew:a,openEdit:l,close:u}=E({editKey:`edit`,newKey:`new`}),d=le(),f=d.data??[],[p,m]=o(null),[h,g]=o(!1),[_,v]=o(!1),y=r.mode===`edit`?f.find(e=>e.id===r.id)??null:null;c(()=>{r.mode===`edit`&&!d.isLoading&&y===null&&u()},[r.mode,d.isLoading,y,u]);let x=r.mode===`new`||r.mode===`edit`&&y!==null,S=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(Le,{embedded:!0,actions:n(i,{children:[n(b,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>g(!0),children:[s(G,{className:`h-3.5 w-3.5`}),`Restore…`]}),n(b,{size:`sm`,type:`button`,onClick:a,"data-testid":`backup-new-entry`,children:[s(be,{className:`h-3.5 w-3.5`}),`New entry`]})]}),children:[_&&s(`div`,{className:`rounded-lg border border-warning/30 bg-warning/10 px-3 py-2.5 text-xs text-warning`,children:n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(G,{className:`h-3.5 w-3.5`}),s(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),n(b,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>{S()},disabled:t.isPending,children:[t.isPending?s(F,{className:`h-3.5 w-3.5 animate-spin`}):s(G,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),s(rt,{}),s(ht,{}),s(Ke,{onEdit:e=>l(e.id),onOpenRestoreWizard:e=>m(e)}),x&&s(dt,{entry:y,onClose:u,onSaved:u}),(p||h)&&s(Tt,{...p?{initialDestinationId:p.destinationId,initialArchiveId:p.archiveId}:{},onClose:()=>{m(null),g(!1)},onScheduled:()=>v(!0)})]})}function Nt(){let{t:e}=Pe(),t=Fe(`/system/data`,{t:e,isAdmin:!0})??{icon:B,title:e(`system.data`,`Data`)};return s(Ie,{icon:t.icon,title:t.title,defaultSection:`storage`,sectionsLabel:`${t.title} sections`,sections:[{id:`storage`,label:`Storage`,content:s(Be,{})},{id:`backup`,label:`Backup`,content:s(Mt,{})}]})}export{Nt as DataPage};
|