@camstack/addon-admin-ui 1.2.437 → 1.2.439
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-C3Ltt0yX.js → AddonAssetIcon-BDSwFXgm.js} +1 -1
- package/dist/assets/{Addons-CkBmnKjV.js → Addons-BNdKgh4A.js} +1 -1
- package/dist/assets/{AdminPage-B7Z1OWO3.js → AdminPage-CgbWYJ_a.js} +1 -1
- package/dist/assets/{AdminSectionedPage-USP4OV_Y.js → AdminSectionedPage-Cx5lBMEy.js} +1 -1
- package/dist/assets/{AiProfiles-QWD8PlMr.js → AiProfiles-Bcw_Zupz.js} +1 -1
- package/dist/assets/{BrokerForm-BxmxiIRw.js → BrokerForm-vhYWxL3G.js} +1 -1
- package/dist/assets/{Build-CXn4HT3p.js → Build-DU8TYYdP.js} +1 -1
- package/dist/assets/{Calendars-DN9ln21d.js → Calendars-nXT3Wrbf.js} +1 -1
- package/dist/assets/{Cluster-tgWdVHND.js → Cluster-i581brrb.js} +1 -1
- package/dist/assets/{ClusterStepModel-BizBdfIU.js → ClusterStepModel-COT7-UPr.js} +1 -1
- package/dist/assets/{CompositionEditor-GiDCG4Aj.js → CompositionEditor-ChpgaVIC.js} +1 -1
- package/dist/assets/{CompositionEditorPage-wfYMLlvy.js → CompositionEditorPage-ChGD20-A.js} +1 -1
- package/dist/assets/{Data-CmT5GPx9.js → Data-NVQyqefj.js} +1 -1
- package/dist/assets/{DeviceDetail-moNYFDGE.js → DeviceDetail-UQPY3O77.js} +1 -1
- package/dist/assets/{DeviceDoActionFields-C1LG9nW0.js → DeviceDoActionFields-B1mTzp5D.js} +1 -1
- package/dist/assets/{Devices-837Dt931.js → Devices-DNkljEPT.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-Crrh_6YT.js → EmbedPlayerPage-BPwqAqDS.js} +1 -1
- package/dist/assets/{Identity-CNNb8wrU.js → Identity-SFG32MYD.js} +1 -1
- package/dist/assets/{IntegrationDetail-BER_0Zaz.js → IntegrationDetail-DOpZe3Ca.js} +1 -1
- package/dist/assets/{IntegrationHub-BEu0isNR.js → IntegrationHub-DbxSPB_Z.js} +1 -1
- package/dist/assets/{Integrations-CuZucOyR.js → Integrations--ssC4t1F.js} +1 -1
- package/dist/assets/{Integrations-Sjh868gF.js → Integrations-6eDOiK1G.js} +1 -1
- package/dist/assets/{Library-B4Nw3n28.js → Library-Bi_LuV1_.js} +1 -1
- package/dist/assets/{Locations-B7dC2DyF.js → Locations-Cg0m1b4l.js} +1 -1
- package/dist/assets/{Logs-4XWMmfpD.js → Logs-DQzkH4DL.js} +1 -1
- package/dist/assets/{MaskShapeCanvas-Bwqusno0.js → MaskShapeCanvas-B01TLLz0.js} +1 -1
- package/dist/assets/{MotionZonesSettings-CZbGV_dv.js → MotionZonesSettings-Ccp-7wRO.js} +1 -1
- package/dist/assets/{MyAccess-TAG05L5N.js → MyAccess-d8Soqp8x.js} +1 -1
- package/dist/assets/{Network-ReY1qUoQ.js → Network-DUXIj2Zk.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-DIKEaj5p.js → NodeAddonsSettingsPanel-BfK00QUN.js} +1 -1
- package/dist/assets/{Notifications-CqTEfaZ_.js → Notifications-M4WZNbHV.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-CTKUYU5o.js → PrivacyMaskSettings-BnmGNc7h.js} +1 -1
- package/dist/assets/{Recordings-EMQC9iqz.js → Recordings-DalG2LLq.js} +1 -1
- package/dist/assets/{ScanNetworkModal-DK98Sjd4.js → ScanNetworkModal-BuYymusi.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-CG4pADlP.js → SceneMonitorEditor-COIi86yu.js} +1 -1
- package/dist/assets/{SessionsList-B1Ni2lo_.js → SessionsList-CoUCGhgk.js} +1 -1
- package/dist/assets/{Showroom-BKLoHB4Z.js → Showroom-B-HvuRyq.js} +1 -1
- package/dist/assets/{System-DEOHPmr3.js → System-D1S9FZIN.js} +1 -1
- package/dist/assets/{Terminal-dVu7TTAE.js → Terminal-VExSxhFn.js} +1 -1
- package/dist/assets/{Viewer-B9mEIKqz.js → Viewer-CNtlq-6t.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BX43JXOX.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-B5lRPMSE.js} +1 -1
- package/dist/assets/{addon-icons-context-BjcmJD_J.js → addon-icons-context-O3QiZWCa.js} +1 -1
- package/dist/assets/{archive-Bcg0gLgY.js → archive-NnMWQRLb.js} +1 -1
- package/dist/assets/{authed-media-Cf82_ejX.js → authed-media-B64j5Vsu.js} +1 -1
- package/dist/assets/{bell-off-BnByNJjy.js → bell-off-DR6rLD11.js} +1 -1
- package/dist/assets/{board-model-D8m2YmcS.js → board-model-CUEDqTvL.js} +1 -1
- package/dist/assets/{boxes-V2c7jrxe.js → boxes-B64NRkVe.js} +1 -1
- package/dist/assets/circle-slash-CEYz4tuU.js +1 -0
- package/dist/assets/client-Ca-96r9I.js +358 -0
- package/dist/assets/{cloud-upload-aziKggfg.js → cloud-upload-Ck1AcqSa.js} +1 -1
- package/dist/assets/crop-C-IooyeF.js +1 -0
- package/dist/assets/{device-integration-icon-3UfBj_i6.js → device-integration-icon-CdWFmoUD.js} +1 -1
- package/dist/assets/device-picker-model-Dep-E57-.js +1 -0
- package/dist/assets/dist-BSOkO07t.js +1 -0
- package/dist/assets/dist-vJSNSRqs.js +358 -0
- package/dist/assets/{eraser-CsYhDDbY.js → eraser-CHm7ildU.js} +1 -1
- package/dist/assets/{hard-drive-download-CWqd_JKb.js → hard-drive-download-DVmQAuw3.js} +1 -1
- package/dist/assets/{history-DOf9zSG-.js → history-2q2gbNuR.js} +1 -1
- package/dist/assets/{hostInit-BCqJwB4Y.js → hostInit-BJE3f_CH.js} +1 -1
- package/dist/assets/i18n-ATfMbes1.js +1 -0
- package/dist/assets/{icons-BrAHwVJD.js → icons-DQaWDMUW.js} +1 -1
- package/dist/assets/index-CIQcOfrF.js +4 -0
- package/dist/assets/{key-D0VHbthb.js → key-N9xPL69Y.js} +1 -1
- package/dist/assets/{key-round-CasJ848Z.js → key-round-DetnHyGS.js} +1 -1
- package/dist/assets/{layers-CFb4zoU6.js → layers-DdcQNtFW.js} +1 -1
- package/dist/assets/{linked-devices-model-DbkbB7KM.js → linked-devices-model-Ca0JeX-b.js} +1 -1
- package/dist/assets/{list-ordered-B14sQnH2.js → list-ordered-CG0tknH1.js} +1 -1
- package/dist/assets/{location-owned-usage-C21QUrwl.js → location-owned-usage-CPVIHMbS.js} +1 -1
- package/dist/assets/{log-in-UZRiT8Rq.js → log-in-eXylJY9j.js} +1 -1
- package/dist/assets/{memory-stick-l6hXPEuG.js → memory-stick-DASwwt0F.js} +1 -1
- package/dist/assets/{message-square-plus-C3grB9GT.js → message-square-plus-DqkHZSG8.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-5e54ea5d.js → mf-entry-bootstrap-0-3bcba670.js} +2 -2
- package/dist/assets/{mic-off-wol-RBiS.js → mic-off-Dn3D8U5T.js} +1 -1
- package/dist/assets/{monitor-off-BUehkWHc.js → monitor-off-BFFE28-j.js} +1 -1
- package/dist/assets/{monitor-smartphone-CCDiXDn-.js → monitor-smartphone-Df6JhoUF.js} +1 -1
- package/dist/assets/mount-Dep-E57-.js +1 -0
- package/dist/assets/{notification-schedule-field-DiZ-TJBp.js → notification-schedule-field-DX8l1Z0c.js} +1 -1
- package/dist/assets/{player-overlays-Db_o1Zm2.js → player-overlays-CikRdqm6.js} +1 -1
- package/dist/assets/{recycle-BVxTT0po.js → recycle-CeQJmMoH.js} +1 -1
- package/dist/assets/remoteEntry-B_6E82lR.js +1 -0
- package/dist/assets/{scan-eye-C5EKCLMY.js → scan-eye-uX_isL7a.js} +1 -1
- package/dist/assets/{scissors-DjP6Unuk.js → scissors-Bi6HP2Jp.js} +1 -1
- package/dist/assets/{search-x-gjRI7PKB.js → search-x-CScyd-pU.js} +1 -1
- package/dist/assets/{send-CV6GWVOX.js → send-D2QbbJQk.js} +1 -1
- package/dist/assets/{settings-2--KyzHb5N.js → settings-2-CkjM7VHr.js} +1 -1
- package/dist/assets/{speaker-CnmwOCLp.js → speaker-C3Z3o0NO.js} +1 -1
- package/dist/assets/src-Bt0KiIin.js +67 -0
- package/dist/assets/{timer-reset-nORqwwje.js → timer-reset-C_TvCMnb.js} +1 -1
- package/dist/assets/{ungroup-BQTGGbbf.js → ungroup-IELE1M3H.js} +1 -1
- package/dist/assets/{unlink-669jprEf.js → unlink-CLHtJAsY.js} +1 -1
- package/dist/assets/{usb-BT4hzhxS.js → usb-DncvObAi.js} +1 -1
- package/dist/assets/{use-scenes-feed-DCExYbbk.js → use-scenes-feed-BgX1JX4l.js} +1 -1
- package/dist/assets/{use-stationary-objects-DPwgtmOw.js → use-stationary-objects-BzSycd9M.js} +1 -1
- package/dist/assets/useEventInvalidation-Dep-E57-.js +1 -0
- package/dist/assets/{useNodeUrlSelection-ibxCoFYh.js → useNodeUrlSelection-D3zWAXku.js} +1 -1
- package/dist/assets/user-round-BCHxFTod.js +1 -0
- package/dist/assets/{user-x-Drhirj9Y.js → user-x-B-NhZXl-.js} +1 -1
- package/dist/assets/{video-Dzs93Xor.js → video-IXUGebu2.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DVRZb8h3.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-5Br3X_S3.js} +2 -2
- package/dist/index.html +10 -10
- package/dist/server/addon.js +83 -3
- package/package.json +1 -1
- package/dist/assets/circle-slash-B_FzZotu.js +0 -1
- package/dist/assets/client-CUuI767h.js +0 -358
- package/dist/assets/crop-DzZyuK_f.js +0 -1
- package/dist/assets/device-picker-model-DJj6igTj.js +0 -1
- package/dist/assets/dist-DsAwO6-i.js +0 -358
- package/dist/assets/dist-t-gGaOd0.js +0 -1
- package/dist/assets/i18n-RHwbGLC0.js +0 -1
- package/dist/assets/index-CeO2wVZi.js +0 -4
- package/dist/assets/mount-DJj6igTj.js +0 -1
- package/dist/assets/remoteEntry-DSZ__m0a.js +0 -1
- package/dist/assets/src-CL0G8g2V.js +0 -67
- package/dist/assets/useEventInvalidation-DJj6igTj.js +0 -1
- package/dist/assets/user-round-NWWWc7PC.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{$ as e,B as t,J as n,K as r,L as i,S as a,b as o,q as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{D as l,O as u,V as d,oa as f,ot as p}from"./player-overlays-Db_o1Zm2.js";import{Cr as m,Dr as h,Er as g,Mr as _,Or as v,Rr as y,Tr as b,an as x,br as S,cn as C,gr as w,jr as T,ln as ee,on as te,sn as ne,vn as E,wr as re,xr as ie,yr as ae,zr as oe}from"./client-CUuI767h.js";import{Bi as se,Bn as D,Pi as ce,Un as O,_a as le,_u as ue,cr as de,er as fe,hu as pe,qa as me,ru as he,s as ge,va as k}from"./src-CL0G8g2V.js";import{t as A}from"./i18n-RHwbGLC0.js";import{t as j}from"./useTranslation-D3Is_4B6.js";e();function _e(e){return{target:{kind:`new`,type:e},name:``,features:[]}}function ve(e){return{target:{kind:`existing`,device:e},name:``,features:[]}}function M(e,t){return{target:e.target,name:t,features:e.features.flatMap(e=>e.kind===`fields`?[e]:[])}}function N(e,t,n){return{...e,features:e.features.map(e=>e.cap===t?n(e):e)}}function P(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>e!==t))}function ye(e,t){switch(t.type){case`set-new-type`:return e.target.kind===`new`?{...e,target:{...e.target,type:t.deviceType}}:e;case`set-new-role`:{if(e.target.kind!==`new`)return e;let{role:n,...r}=e.target;return{...e,target:t.role===null?r:{...r,role:t.role}}}case`set-name`:return{...e,name:t.name};case`add-feature`:return e.features.some(e=>e.cap===t.cap)?e:{...e,features:[...e.features,{kind:`fields`,cap:t.cap,fields:{}}]};case`remove-feature`:return{...e,features:e.features.filter(e=>e.cap!==t.cap)};case`set-field`:return N(e,t.cap,e=>({...e,fields:{...e.fields,[t.path]:t.source}}));case`clear-field`:return N(e,t.cap,e=>({...e,fields:P(e.fields,t.path)}));case`remove-binding`:return N(e,t.cap,e=>{let n=e.fields[t.path];return n?.kind===`expression`?{...e,fields:{...e.fields,[t.path]:{...n,bindings:P(n.bindings,t.bindingName)}}}:e});case`copy-feature`:return N(e,t.cap,e=>({...e,fields:{...e.fields,...Object.fromEntries(t.paths.map(e=>[e,{kind:`from`,source:t.from,cap:t.sourceCap,fieldPath:e}]))}}))}}function be(e){let t=ie.safeParse({target:e.target,features:e.features});return t.success?{ok:!0,composition:t.data}:{ok:!1,problems:t.error.issues.map(e=>`${e.path.join(`.`)||`composition`}: ${e.message}`)}}function xe(e,t){return JSON.stringify(e)!==JSON.stringify(t)}function Se(e){for(let t=1;;t++){let n=`s${t}`;if(!e.includes(n))return n}}var Ce=[`room`,`converted-sensor`,`derived-binary`],F={addonId:`provider-homeassistant`,stableId:`sensor.template_source`};function we(){return M(C({temperatureSources:te,motionSources:x,occupancyWindowMs:ne}),`Room`)}function Te(){return M({target:{kind:`new`,type:_.Sensor},features:[{kind:`fields`,cap:`numeric-sensor`,fields:{value:{kind:`expression`,expr:`convert(v, "°C", "°F")`,bindings:{v:{kind:`from`,source:F,cap:`numeric-sensor`,fieldPath:`value`}}},unit:{kind:`expression`,expr:`"°F"`,bindings:{}},lastFetchedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Converted sensor`)}function Ee(){return M({target:{kind:`new`,type:_.Sensor},features:[{kind:`fields`,cap:`binary`,fields:{on:{kind:`expression`,expr:`v > 20`,bindings:{v:{kind:`from`,source:F,cap:`temperature-sensor`,fieldPath:`celsius`}}},lastChangedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Derived binary`)}function De(e){switch(e){case`room`:return we();case`converted-sensor`:return Te();case`derived-binary`:return Ee()}}function Oe(e,t){return typeof t==`number`&&Number.isFinite(t)&&t>0?{kind:`device`,path:`/devices/${t}`}:{kind:`editor`,path:`/build/compositions/${encodeURIComponent(e)}`}}var I=`rounded-lg border border-border bg-surface p-4`,ke=I;function Ae(e){return{addonId:e.addonId,stableId:e.stableId}}function L(e){return new Map(e.map(e=>[h(Ae(e)),e]))}function je(e,t,n){let r=e?.features??[],i=r.findIndex(e=>e.cap===n.cap);return{target:e?.target??{kind:`existing`,device:t},features:i===-1?[...r,n]:r.map((e,t)=>t===i?n:e)}}function Me(e,t){let n=e.features.filter(e=>e.cap!==t);return n.length===0?null:{target:e.target,features:n}}function Ne(e,t){let n=e?.features.find(e=>e.cap===t);return n!==void 0&&n.kind===`fields`?n:null}function R(e){return Array.isArray(e)?e.map(R):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,R(t)]))}function z(e){return JSON.stringify(R(e))}function Pe(e,t){return z(e)===z(t)}function B(e,t){return z(e)===z(t)}function Fe(e,t){switch(e.kind){case`pending`:return{kind:`refused`,reason:A.t(`helpers.customizationSave.notReadYet`)};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}:z(t)===z(e.composition)?{kind:`noop`}:{kind:`update`,blockId:n,expectedUpdatedAt:e.view.block.updatedAt,composition:t}}}}function V(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 H(e){return{kind:`expression`,expr:e,bindings:{}}}function U(e){let t=V(`number`,e.percentage);return t===null?null:{kind:`fields`,cap:`battery`,fields:e.mode===`replace`?{percentage:t}:{percentage:t,charging:H(`"unknown"`),sleeping:H(`false`),lastUpdated:H(`now`)}}}var Ie=[`percent`,...E.options];function W(e,t){return t===`percent`?{level:e}:{"remaining.value":e,"remaining.unit":H(JSON.stringify(t))}}function Le(e,t){let n=V(`number`,t.remaining);if(n===null||!S.test(t.key)||t.label.trim()===``)return null;let r={label:t.label.trim(),fields:W(n,t.unit)};return{kind:`fields`,cap:`consumables`,...e?.enabled===void 0?{}:{enabled:e.enabled},fields:e?.fields??{lastChangedAt:H(`now`),lastFetchedAt:H(`now`)},items:{...e?.items,[t.key]:r}}}function Re(e){if(e.level!==void 0)return`percent`;let t=e[`remaining.unit`];if(t===void 0||t.kind!==`expression`)return null;try{let e=E.safeParse(JSON.parse(t.expr));return e.success?e.data:null}catch{return null}}function ze(e){return Object.entries(e?.items??{}).map(([e,t])=>{let n=Re(t.fields),r=G(t.fields.level??t.fields[`remaining.value`]),i=r===null?null:V(`number`,r);return n!==null&&i!==null&&Pe(W(i,n),t.fields)?{key:e,label:t.label,unit:n,source:r}:{key:e,label:t.label,unit:null,source:null}})}function Be(e,t){let n=Object.fromEntries(Object.entries(e.items??{}).filter(([e])=>e!==t));return Object.keys(n).length===0?null:{...e,items:n}}function Ve(e){return e.toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,48)}function He(e){let t=e.fields.lastPressedAt;if(t===void 0||t.kind!==`expression`)return[];let n=Object.entries(t.bindings).filter(([e])=>e.startsWith(`active`)).flatMap(([,e])=>e.kind===`from`?[e.source]:[]);return[...new Map(n.map(e=>[h(e),e])).values()]}function Ue(e){let t=e.fields.lastPressedAt;if(t===void 0||t.kind!==`expression`)return[];let n=t.bindings;return Object.entries(n).flatMap(([e,t])=>{if(!e.startsWith(`active`)||t.kind!==`from`)return[];let r=n[`changed${e.slice(6)}`];return r===void 0||r.kind!==`from`?[]:[{source:t.source,cap:t.cap,activeField:t.fieldPath,changedAtField:r.fieldPath}]})}function G(e){if(e===void 0)return null;if(e.kind===`from`){let{kind:t,...n}=e;return{...n,kind:`number`}}if(e.kind!==`expression`||e.expr!==`number(x)`)return null;let t=e.bindings.x;if(t===void 0||t.kind!==`from`||Object.keys(e.bindings).length!==1)return null;let{kind:n,...r}=t;return{...r,kind:`string`}}function We(e,t){let n=G(e.fields.percentage);if(n===null)return!1;let r=U({percentage:n,mode:t}),{enabled:i,...a}=e;return r!==null&&B(a,r)}function K(e){return e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,location:e.location,type:e.type}))}function Ge(e,t,n){let r=t.trim().toLowerCase();return r===``?[]:e.filter(e=>!n.includes(e.id)&&[e.name,e.stableId,e.location??``].some(e=>e.toLowerCase().includes(r))).toSorted((e,t)=>e.name.localeCompare(t.name)).slice(0,20)}function q(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n||Array.isArray(n))return;n=Object.getOwnPropertyDescriptor(n,e)?.value}return n}function Ke(e,t,n,r){return r===null?{kind:`from`,source:e,cap:t,fieldPath:n.path}:V(r,{source:e,cap:t,fieldPath:n.path,kind:n.kind})}function qe(e,t,n,r){let i={addonId:e.addonId,stableId:e.stableId};return t.caps.flatMap(e=>e.fields.filter(e=>e.item!==!0).map(t=>({cap:e.cap,path:t.path,kind:t.kind,value:n===null?void 0:q(n[e.cap],t.path),source:Ke(i,e.cap,t,r)})))}function J(e,t){return t?e===void 0?`—`:e===null?`null`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e):`…`}var Je=[];function Y({title:e,targetKind:t,excludeDeviceIds:r=Je,onPick:i,onCancel:o}){let{t:s}=j(),[f,p]=n(null);return a(`aside`,{"aria-label":e,className:`${u} ${l} flex flex-col gap-2`,children:[c(`h3`,{className:d,children:e}),f===null?c(Ye,{excludeDeviceIds:r,onSelect:p}):c(X,{device:f,targetKind:t,onPick:i,onBack:()=>p(null)}),c(`div`,{children:c(O,{variant:`ghost`,size:`sm`,onClick:o,children:s(`customize.picker.cancel`)})})]})}function Ye({excludeDeviceIds:e,onSelect:t}){let{t:r}=j(),[i,s]=n(``),l=k({projection:`slim`});return a(o,{children:[a(`label`,{className:`flex flex-col gap-1 text-[11px] text-foreground-subtle`,children:[r(`customize.picker.search`),c(he,{type:`search`,"aria-label":r(`customize.picker.search`),value:i,onChange:e=>s(e.target.value)})]}),l.status===`pending`&&c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:r(`customize.picker.loadingDevices`)}),l.status===`error`&&c(D,{title:r(`customize.picker.devicesFailed`),message:l.error?.message??``}),l.status===`success`&&c(`ul`,{className:`flex flex-col gap-1`,children:Ge(K(l.data),i,e).map(e=>c(`li`,{children:a(`button`,{type:`button`,className:`text-left text-[11px] hover:underline`,onClick:()=>t(e),children:[e.name,` `,a(`span`,{className:`text-foreground-subtle`,children:[`· `,e.stableId]})]})},e.id))})]})}function X({device:e,targetKind:t,selected:n,onPick:r,onBack:i}){let{t:o}=j(),s=le({deviceId:e.id}),l=me({deviceId:e.id});if(s.status===`pending`)return c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:o(`customize.picker.loadingFields`)});if(s.status===`error`)return c(D,{title:o(`customize.picker.fieldsFailed`),message:s.error?.message??``});let u=qe(e,s.data,l.status===`success`?l.data:null,t),d=u.filter(e=>e.source===null).length,f={addonId:e.addonId,stableId:e.stableId};return a(`div`,{className:`flex flex-col gap-1`,children:[a(`button`,{type:`button`,className:`text-left text-[11px] text-primary`,onClick:i,children:[`← `,e.name]}),l.status===`error`&&c(`p`,{role:`alert`,className:`text-[10px] text-warning`,children:o(`customize.picker.valuesFailed`,{reason:l.error?.message??``})}),c(`ul`,{role:`listbox`,"aria-label":o(`customize.picker.fields`),className:`flex flex-col gap-1`,children:u.map(t=>{let i=t.source;if(i===null)return null;let o=()=>r({device:e,ref:f,cap:t.cap,path:t.path,kind:t.kind,source:i,value:t.value});return a(`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:[a(`span`,{className:`font-mono`,children:[t.cap,`.`,t.path]}),c(`span`,{children:J(t.value,l.status===`success`)})]},`${t.cap}.${t.path}`)})}),d>0&&t!==null&&c(`p`,{className:`text-[10px] text-foreground-subtle`,children:o(`customize.picker.hidden`,{count:d,kind:o(`customize.kinds.${t}`)})})]})}var Xe=`integration`;function Z(e,t){switch(e.kind){case`from`:{let n=h(e.source);return`${t.get(n)??n} · ${e.cap}.${e.fieldPath}`}case`expression`:return e.expr;case`code`:return`code`}}function Ze(e,t){if(e.kind===`unreachable`)return{kind:`unknown`,reason:e.error};if(e.state===null)return{kind:`unknown`,reason:A.t(`helpers.fieldsTableRows.composerNotReported`)};let n=e.state.fields.find(t);return n===void 0?{kind:`unknown`,reason:A.t(`helpers.fieldsTableRows.noValue`)}:n.state===`unavailable`?{kind:`unavailable`,reason:n.reason??A.t(`common.unavailable`)}:{kind:`value`,value:n.value,staleReason:n.state===`stale`?n.reason??A.t(`common.stale`):null}}function Q(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?Ze(e.input.state,r):{kind:`off`}}}function Qe(e){let t=e.feature.cap;return Object.entries(e.feature.fields).map(([n,r])=>Q(e,n,r,e=>e.cap===t&&e.path===n&&e.item===void 0))}function $e(e){let t=e.feature.cap;return Object.entries(e.feature.items??{}).flatMap(([n,r])=>Object.entries(r.fields).map(([r,i])=>Q(e,re(ae,n,r),i,e=>e.cap===t&&e.path===r&&e.item?.arrayPath===`items`&&e.item.key===n)))}function et(e,t,n){if(e===null)return{kind:`unknown`,reason:A.t(`helpers.fieldsTableRows.stateUnreadable`)};let r=q(e[t],n),i=r===void 0?void 0:y(r);return i===void 0?{kind:`unknown`,reason:A.t(`helpers.fieldsTableRows.notReported`)}:{kind:`value`,value:i,staleReason:null}}function tt(e){if(e.mode!==`replace`)return[];let t=e.feature.cap,n=new Set(Object.keys(e.feature.fields));return(e.input.nativeFields.get(t)??[]).filter(e=>!n.has(e)).map(n=>({key:`${t}.${n}`,cap:t,field:n,origin:`native`,mode:e.mode,from:Xe,value:et(e.input.snapshot,t,n)}))}function nt(e){return e.composition.features.flatMap(t=>{if(t.kind!==`fields`)return[];let n={feature:t,mode:e.nativeCaps.has(t.cap)?`replace`:`add`,enabled:m(t),input:e};return[...Qe(n),...$e(n),...tt(n)]})}var rt={min:`min(a, b, …)`,max:`max(a, b, …)`,abs:`abs(x)`,floor:`floor(x)`,ceil:`ceil(x)`,sqrt:`sqrt(x)`,round:`round(x, digits?)`,pow:`pow(x, y)`,clamp:`clamp(x, lo, hi)`,avg:`avg(a, b, …)`,sum:`sum(a, b, …)`,coalesce:`coalesce(a, b, …)`,age:`age(now, ts)`,convert:`convert(x, "from", "to")`,any:`any(a, b, …)`,all:`all(a, b, …)`,within:`within(ts, ms)`,number:`number(x)`,latest:`latest(ts, …)`,rose:`rose(level, changedAt, debounceMs?)`,count:`count(x)`},it=/[A-Za-z_][A-Za-z0-9_]*$/;function at(e,t,n){let r=it.exec(e.slice(0,t))?.[0]??``;if(r===``)return[];let i=n.filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`binding`,label:e,insert:e,hintKey:null})),a=`now`.startsWith(r)?[{kind:`now`,label:`now`,insert:`now`,hintKey:`compositionEditor.now`}]:[],o=[...oe].filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`builtin`,label:rt[e]??e,insert:`${e}(`,hintKey:`compositionEditor.builtins.${e}`}));return[...i,...a,...o].slice(0,8)}function ot(e,t,n){let r=t-(it.exec(e.slice(0,t))?.[0]??``).length;return{text:`${e.slice(0,r)}${n.insert}${e.slice(t)}`,cursor:r+n.insert.length}}e();function st({label:e,value:t,bindings:r,onChange:i}){let{t:o}=j(),l=s(null),[u,d]=n(t.length),f=at(t,u,r);return a(`div`,{className:`flex flex-col gap-1`,children:[a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[e,c(`input`,{ref:l,className:`font-mono px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`,value:t,onChange:e=>{i(e.target.value),d(e.target.selectionStart??e.target.value.length)},onSelect:e=>d(e.currentTarget.selectionStart??t.length)})]}),f.length>0&&c(`ul`,{role:`listbox`,"aria-label":o(`compositionEditor.suggestions`),className:`rounded border border-border bg-surface text-[11px]`,children:f.map(e=>a(`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=ot(t,u,e);i(n.text),d(n.cursor),l.current?.focus()},children:[c(`span`,{className:`font-mono`,children:e.label}),e.hintKey!==null&&c(`span`,{className:`text-foreground-subtle`,children:o(e.hintKey)})]},`${e.kind}:${e.label}`))})]})}function ct(e,t,n){if(e.kind===`code`)return{kind:`unavailable`,reason:A.t(`helpers.fieldPreview.codeFields`)};if(e.kind===`expression`&&(w(e.expr,`rose`)||w(e.expr,`count`)))return{kind:`runtime-only`};let r=v(e).filter(e=>t.get(g(e.source,e.cap))?.kind!==`value`).map(b);if(r.length>0)return{kind:`waiting`,missing:r};let i=ee({source:e,now:n,read:e=>{let n=t.get(g(e.source,e.cap)),r=n?.kind===`value`?q(n.slice,e.fieldPath):void 0,i=r===void 0?void 0:y(r);return i===void 0?{state:`unavailable`,reason:A.t(`helpers.fieldPreview.notReported`,{path:`${e.cap}.${e.fieldPath}`}),fatal:!1}:{state:`fresh`,value:i}}});return i.state===`unavailable`?{kind:`unavailable`,reason:i.reason}:{kind:`value`,value:i.value,stale:i.reason}}e();function lt({sliceKey:e,deviceId:n,capName:r,onReading:i}){let a=ge(p().trpcClient,n,r);return t(()=>{i(e,a===void 0?{kind:`pending`}:{kind:`value`,slice:a})},[e,a,i]),null}function ut(e,t){return[...new Map(v(e).map(e=>[g(e.source,e.cap),e]))].map(([e,n])=>({key:e,read:n,device:t.get(h(n.source))}))}function dt({source:e}){let{t}=j(),r=k({projection:`slim`}),[o,s]=n(new Map),l=i((e,t)=>{s(n=>new Map([...n,[e,t]]))},[]),u=ut(e,L(r.status===`success`?K(r.data):[])),d=r.status===`success`?u.filter(e=>e.device===void 0).map(e=>h(e.read.source)):[];return a(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[u.map(e=>e.device===void 0?null:c(lt,{sliceKey:e.key,deviceId:e.device.id,capName:e.read.cap,onReading:l},e.key)),c(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.label`)}),r.status===`error`?c(`span`,{className:`text-warning`,children:t(`compositionEditor.preview.devicesFailed`,{reason:r.error?.message??``})}):d.length>0?c(`span`,{className:`text-warning`,children:t(`compositionEditor.preview.unknownDevice`,{sources:d.join(`, `)})}):c(ft,{preview:ct(e,o,Date.now())})]})}function ft({preview:e}){let{t}=j();switch(e.kind){case`value`:return a(`strong`,{children:[`→ `,J(e.value,!0),e.stale===null?``:` (${e.stale})`]});case`unavailable`:return c(`span`,{className:`text-warning`,children:e.reason});case`waiting`:return c(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.waiting`,{sources:e.missing.join(`, `)})});case`runtime-only`:return c(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.runtimeOnly`)})}}e();function pt({path:e,kind:t,required:r,source:i,onSet:s,onClear:l,onRemoveBinding:u,sourceNames:d}){let{t:f}=j(),[p,m]=n(`idle`),h=i?.kind===`expression`?i:null;return a(`div`,{className:`flex flex-col gap-1 rounded border border-border p-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[c(`span`,{className:`font-mono text-[11px]`,children:e}),a(`span`,{className:`text-[10px] text-foreground-subtle`,children:[f(`customize.kinds.${t}`),r?` · ${f(`compositionEditor.required`)}`:``]}),c(O,{size:`sm`,variant:`outline`,onClick:()=>m(`take`),children:f(`compositionEditor.takeFrom`)}),c(O,{size:`sm`,variant:`outline`,"aria-pressed":h!==null,onClick:()=>s(h??{kind:`expression`,expr:`null`,bindings:{}}),children:f(`compositionEditor.formula`)}),i!==void 0&&c(O,{size:`sm`,variant:`ghost`,onClick:l,children:f(`compositionEditor.clear`)})]}),i?.kind===`from`&&c(`span`,{className:`text-[11px]`,children:Z(i,d)}),h!==null&&a(o,{children:[c(st,{label:f(`compositionEditor.formulaFor`,{path:e}),value:h.expr,bindings:Object.keys(h.bindings),onChange:e=>s({...h,expr:e})}),c(`ul`,{className:`text-[11px] flex flex-col gap-0.5`,children:Object.entries(h.bindings).map(([e,t])=>a(`li`,{className:`flex flex-wrap items-center gap-2`,children:[c(`span`,{className:`font-mono`,children:e}),c(`span`,{children:t.kind===`from`?Z(t,d):JSON.stringify(t.value)}),c(O,{size:`sm`,variant:`ghost`,"aria-label":f(`compositionEditor.removeBinding`,{name:e}),onClick:()=>u(e),children:`×`})]},e))}),c(O,{size:`sm`,variant:`ghost`,onClick:()=>m(`add-binding`),children:f(`compositionEditor.addSource`)})]}),p!==`idle`&&c(Y,{title:f(p===`take`?`compositionEditor.takeFrom`:`compositionEditor.addSource`),targetKind:p===`take`?t:null,onCancel:()=>m(`idle`),onPick:e=>{if(p===`take`)s(e.source);else if(h!==null){let t=Se(Object.keys(h.bindings));s({...h,bindings:{...h.bindings,[t]:{kind:`from`,source:e.ref,cap:e.cap,fieldPath:e.path}}})}m(`idle`)}}),i!==void 0&&c(dt,{source:i})]})}e();function mt(e){return e===null||e.kind===`known`?null:e}function ht({draft:e,deviceType:t,nativeCaps:r,targetFields:i,dispatch:s}){let{t:l}=j(),u=ce({deviceType:t}),d=k({projection:`slim`}),f=new Map([...L(d.status===`success`?K(d.data):[])].map(([e,t])=>[e,t.name])),[p,m]=n(null),h=mt(r)??mt(i),g=r?.kind===`known`?r.value:new Set,_=new Set(e.features.map(e=>e.cap)),v=u.status===`success`?u.data.caps.filter(e=>!_.has(e.cap)&&!g.has(e.cap)):[],y=[...g].filter(e=>!_.has(e)),b=e=>g.has(e)?((i?.kind===`known`?i.value.caps.find(t=>t.cap===e):void 0)?.fields??[]).filter(e=>e.item!==!0&&!e.path.includes(`.`)).map(e=>({path:e.path,kind:e.kind,required:!1})):((u.status===`success`?u.data.caps.find(t=>t.cap===e):void 0)?.fields??[]).map(e=>({path:e.path,kind:e.kind,required:e.required}));return h===null?a(o,{children:[a(`section`,{"aria-labelledby":`editor-features`,className:`${I} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),u.status===`pending`&&c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.checking`)}),u.status===`error`&&c(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.unknown`,{reason:u.error?.message??``})}),a(`div`,{className:`flex flex-wrap gap-1`,children:[e.features.map(e=>a(`span`,{className:`flex items-center gap-1 rounded border border-border px-1.5 text-[11px]`,children:[e.cap,c(de,{variant:g.has(e.cap)?`default`:`info`,children:g.has(e.cap)?l(`compositionEditor.replaces`):l(`compositionEditor.added`)}),c(`button`,{type:`button`,"aria-label":l(`compositionEditor.removeFeature`,{cap:e.cap}),onClick:()=>s({type:`remove-feature`,cap:e.cap}),children:`×`})]},e.cap)),v.map(e=>a(O,{size:`sm`,variant:`outline`,onClick:()=>s({type:`add-feature`,cap:e.cap}),children:[`+ `,e.cap]},e.cap)),y.map(e=>c(O,{size:`sm`,variant:`ghost`,onClick:()=>s({type:`add-feature`,cap:e}),children:l(`compositionEditor.replaceIn`,{cap:e})},e))]})]}),e.features.map(e=>a(`section`,{"aria-label":l(`compositionEditor.steps.fieldsOf`,{cap:e.cap}),className:`${I} flex flex-col gap-2`,children:[a(`div`,{className:`flex items-center justify-between`,children:[c(`h2`,{className:`text-sm font-semibold`,children:l(`compositionEditor.steps.fieldsOf`,{cap:e.cap})}),c(O,{size:`sm`,variant:`outline`,onClick:()=>m(e.cap),children:l(`compositionEditor.copyFeature`)})]}),p===e.cap&&c(Y,{title:l(`compositionEditor.copyFeature`),targetKind:null,onCancel:()=>m(null),onPick:t=>{s({type:`copy-feature`,cap:e.cap,from:t.ref,sourceCap:t.cap,paths:b(e.cap).map(e=>e.path)}),m(null)}}),b(e.cap).map(t=>c(pt,{path:t.path,kind:t.kind,required:t.required,source:e.fields[t.path],onSet:n=>s({type:`set-field`,cap:e.cap,path:t.path,source:n}),onClear:()=>s({type:`clear-field`,cap:e.cap,path:t.path}),onRemoveBinding:n=>s({type:`remove-binding`,cap:e.cap,path:t.path,bindingName:n}),sourceNames:f},t.path))]},e.cap))]}):a(`section`,{"aria-labelledby":`editor-features`,className:`${I} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:h.kind===`unknown`?h.reason:l(`compositionEditor.reading`)})]})}var $=`px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`;function gt({draft:e,targetName:t,dispatch:n}){let r=f(),{t:i}=j(),o=e.target;return a(`section`,{"aria-labelledby":`editor-target`,className:`${I} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-target`,className:`text-sm font-semibold`,children:i(`compositionEditor.steps.target`)}),o.kind===`existing`?c(`p`,{className:`text-[11px]`,children:i(`compositionEditor.existingTarget`,{name:t??`${o.device.addonId}/${o.device.stableId}`})}):a(`div`,{className:`grid grid-cols-3 gap-2`,children:[a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[i(`compositionEditor.targetType`),c(`select`,{className:$,value:o.type,onChange:e=>{let t=Object.values(_).find(t=>t===e.target.value);t!==void 0&&n({type:`set-new-type`,deviceType:t})},children:Object.values(_).map(e=>c(`option`,{value:e,children:ue(e,r).label},e))})]}),a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[i(`customize.identity.role`),a(`select`,{className:$,value:o.role??``,onChange:e=>n({type:`set-new-role`,role:Object.values(T).find(t=>t===e.target.value)??null}),children:[c(`option`,{value:``,children:i(`customize.identity.noRole`)}),Object.values(T).map(e=>c(`option`,{value:e,children:pe(e,r).label},e))]})]}),a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[i(`compositionEditor.name`),c(`input`,{className:$,value:e.name,onChange:e=>n({type:`set-name`,name:e.target.value})})]})]})]})}e();function _t({draft:e,blockId:r,saving:i,onSave:o,onCancel:s}){let{t:l}=j(),u=se(),d=be(e),f=d.ok?JSON.stringify(d.composition):``,[p,m]=n({key:``,state:{kind:`checking`}});t(()=>{if(!d.ok)return;let e=d.composition,t=setTimeout(()=>{u.mutateAsync({composition:e,...r===null?{}:{blockId:r}}).then(e=>m({key:f,state:e.ok?{kind:`ok`}:{kind:`refused`,problems:e.problems}})).catch(e=>m({key:f,state:{kind:`unknown`,reason:e instanceof Error?e.message:String(e)}}))},500);return()=>clearTimeout(t)},[f,r]);let h=d.ok?p.key===f?p.state:{kind:`checking`}:{kind:`invalid-draft`,problems:d.problems};return a(`section`,{"aria-labelledby":`editor-verify`,className:`${I} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-verify`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.verify`)}),h.kind===`checking`&&c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.verify.checking`)}),h.kind===`ok`&&c(`p`,{className:`text-[11px] text-success`,children:l(`compositionEditor.verify.ok`)}),h.kind===`unknown`&&c(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.verify.unknown`,{reason:h.reason})}),(h.kind===`invalid-draft`||h.kind===`refused`)&&c(`ul`,{role:`alert`,className:`flex flex-col gap-1 text-[11px] text-danger`,children:h.kind===`invalid-draft`?h.problems.map(e=>c(`li`,{children:e},e)):h.problems.map(e=>a(`li`,{children:[c(`span`,{className:`font-mono`,children:e.path}),` — `,e.message]},`${e.path}:${e.code}`))}),a(`div`,{className:`flex gap-2`,children:[c(O,{variant:`ghost`,onClick:s,children:l(`compositionEditor.cancel`)}),c(O,{disabled:h.kind!==`ok`||i||!d.ok,onClick:()=>d.ok&&o(d.composition),children:l(`compositionEditor.save`)})]})]})}e();function vt({initial:e,blockId:t,deviceType:r,targetName:i=null,nativeCaps:a,targetFields:o,save:s,onCancel:l,showTemplates:u=!1}){let[d,f]=n(e),p=`${d.name}:${d.features.map(e=>e.cap).join(`,`)}:${d.target.kind===`new`?d.target.type:`existing`}`;return c(yt,{seed:d,blockId:t,deviceType:r,targetName:i,nativeCaps:a,targetFields:o,showTemplates:u,onApplyTemplate:e=>{f(De(e))},save:s,onCancel:l},p)}function yt({seed:e,blockId:t,deviceType:i,targetName:o,nativeCaps:s,targetFields:l,showTemplates:u,onApplyTemplate:d,save:f,onCancel:p}){let{t:m}=j(),h=fe(),[g,_]=r(ye,e),[v,y]=n(!1),[b,x]=n(null),S=async t=>{xe(e,g)&&!await h({title:m(`compositionEditor.templates.confirmTitle`),message:m(`compositionEditor.templates.confirmMessage`),confirmLabel:m(`compositionEditor.templates.confirmApply`),variant:`danger`})||d(t)},C=g.target.kind===`new`?g.target.type:i,w=async e=>{y(!0);let t=await f(e,g.name);y(!1),x(t.kind===`refused`?t.reason:null)};return a(`div`,{className:`flex flex-col gap-4`,children:[u&&g.target.kind===`new`&&a(`div`,{className:`rounded-lg border border-border bg-surface p-4 flex flex-wrap gap-2`,"data-testid":`composition-templates`,children:[c(`span`,{className:`text-[11px] text-foreground-subtle self-center`,children:m(`compositionEditor.templates.label`)}),Ce.map(e=>c(O,{size:`sm`,variant:`outline`,onClick:()=>void S(e),children:m(`compositionEditor.templates.${e}`)},e))]}),c(gt,{draft:g,targetName:o,dispatch:_}),c(ht,{draft:g,deviceType:C,nativeCaps:s,targetFields:l,dispatch:_}),c(_t,{draft:g,blockId:t,saving:v,onSave:e=>void w(e),onCancel:p}),b!==null&&c(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:b})]})}export{Me as C,ve as D,M as E,_e as O,je as S,Oe as T,G as _,X as a,Fe as b,K as c,Le as d,ze as f,Ve as g,We as h,nt as i,Ie as l,Ue as m,ct as n,J as o,He as p,st as r,q as s,vt as t,U as u,Be as v,ke as w,B as x,Ne as y};
|
|
1
|
+
import{$ as e,B as t,J as n,K as r,L as i,S as a,b as o,q as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{D as l,O as u,V as d,oa as f,ot as p}from"./player-overlays-CikRdqm6.js";import{Cr as m,Dr as h,Er as g,Mr as _,Or as v,Rr as y,Tr as b,an as x,br as S,cn as C,gr as w,jr as T,ln as ee,on as te,sn as ne,vn as E,wr as re,xr as ie,yr as ae,zr as oe}from"./client-Ca-96r9I.js";import{Bi as se,Bn as D,Pi as ce,Un as O,_a as le,_u as ue,cr as de,er as fe,hu as pe,qa as me,ru as he,s as ge,va as k}from"./src-Bt0KiIin.js";import{t as A}from"./i18n-ATfMbes1.js";import{t as j}from"./useTranslation-D3Is_4B6.js";e();function _e(e){return{target:{kind:`new`,type:e},name:``,features:[]}}function ve(e){return{target:{kind:`existing`,device:e},name:``,features:[]}}function M(e,t){return{target:e.target,name:t,features:e.features.flatMap(e=>e.kind===`fields`?[e]:[])}}function N(e,t,n){return{...e,features:e.features.map(e=>e.cap===t?n(e):e)}}function P(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>e!==t))}function ye(e,t){switch(t.type){case`set-new-type`:return e.target.kind===`new`?{...e,target:{...e.target,type:t.deviceType}}:e;case`set-new-role`:{if(e.target.kind!==`new`)return e;let{role:n,...r}=e.target;return{...e,target:t.role===null?r:{...r,role:t.role}}}case`set-name`:return{...e,name:t.name};case`add-feature`:return e.features.some(e=>e.cap===t.cap)?e:{...e,features:[...e.features,{kind:`fields`,cap:t.cap,fields:{}}]};case`remove-feature`:return{...e,features:e.features.filter(e=>e.cap!==t.cap)};case`set-field`:return N(e,t.cap,e=>({...e,fields:{...e.fields,[t.path]:t.source}}));case`clear-field`:return N(e,t.cap,e=>({...e,fields:P(e.fields,t.path)}));case`remove-binding`:return N(e,t.cap,e=>{let n=e.fields[t.path];return n?.kind===`expression`?{...e,fields:{...e.fields,[t.path]:{...n,bindings:P(n.bindings,t.bindingName)}}}:e});case`copy-feature`:return N(e,t.cap,e=>({...e,fields:{...e.fields,...Object.fromEntries(t.paths.map(e=>[e,{kind:`from`,source:t.from,cap:t.sourceCap,fieldPath:e}]))}}))}}function be(e){let t=ie.safeParse({target:e.target,features:e.features});return t.success?{ok:!0,composition:t.data}:{ok:!1,problems:t.error.issues.map(e=>`${e.path.join(`.`)||`composition`}: ${e.message}`)}}function xe(e,t){return JSON.stringify(e)!==JSON.stringify(t)}function Se(e){for(let t=1;;t++){let n=`s${t}`;if(!e.includes(n))return n}}var Ce=[`room`,`converted-sensor`,`derived-binary`],F={addonId:`provider-homeassistant`,stableId:`sensor.template_source`};function we(){return M(C({temperatureSources:te,motionSources:x,occupancyWindowMs:ne}),`Room`)}function Te(){return M({target:{kind:`new`,type:_.Sensor},features:[{kind:`fields`,cap:`numeric-sensor`,fields:{value:{kind:`expression`,expr:`convert(v, "°C", "°F")`,bindings:{v:{kind:`from`,source:F,cap:`numeric-sensor`,fieldPath:`value`}}},unit:{kind:`expression`,expr:`"°F"`,bindings:{}},lastFetchedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Converted sensor`)}function Ee(){return M({target:{kind:`new`,type:_.Sensor},features:[{kind:`fields`,cap:`binary`,fields:{on:{kind:`expression`,expr:`v > 20`,bindings:{v:{kind:`from`,source:F,cap:`temperature-sensor`,fieldPath:`celsius`}}},lastChangedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Derived binary`)}function De(e){switch(e){case`room`:return we();case`converted-sensor`:return Te();case`derived-binary`:return Ee()}}function Oe(e,t){return typeof t==`number`&&Number.isFinite(t)&&t>0?{kind:`device`,path:`/devices/${t}`}:{kind:`editor`,path:`/build/compositions/${encodeURIComponent(e)}`}}var I=`rounded-lg border border-border bg-surface p-4`,ke=I;function Ae(e){return{addonId:e.addonId,stableId:e.stableId}}function L(e){return new Map(e.map(e=>[h(Ae(e)),e]))}function je(e,t,n){let r=e?.features??[],i=r.findIndex(e=>e.cap===n.cap);return{target:e?.target??{kind:`existing`,device:t},features:i===-1?[...r,n]:r.map((e,t)=>t===i?n:e)}}function Me(e,t){let n=e.features.filter(e=>e.cap!==t);return n.length===0?null:{target:e.target,features:n}}function Ne(e,t){let n=e?.features.find(e=>e.cap===t);return n!==void 0&&n.kind===`fields`?n:null}function R(e){return Array.isArray(e)?e.map(R):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,R(t)]))}function z(e){return JSON.stringify(R(e))}function Pe(e,t){return z(e)===z(t)}function B(e,t){return z(e)===z(t)}function Fe(e,t){switch(e.kind){case`pending`:return{kind:`refused`,reason:A.t(`helpers.customizationSave.notReadYet`)};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}:z(t)===z(e.composition)?{kind:`noop`}:{kind:`update`,blockId:n,expectedUpdatedAt:e.view.block.updatedAt,composition:t}}}}function V(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 H(e){return{kind:`expression`,expr:e,bindings:{}}}function U(e){let t=V(`number`,e.percentage);return t===null?null:{kind:`fields`,cap:`battery`,fields:e.mode===`replace`?{percentage:t}:{percentage:t,charging:H(`"unknown"`),sleeping:H(`false`),lastUpdated:H(`now`)}}}var Ie=[`percent`,...E.options];function W(e,t){return t===`percent`?{level:e}:{"remaining.value":e,"remaining.unit":H(JSON.stringify(t))}}function Le(e,t){let n=V(`number`,t.remaining);if(n===null||!S.test(t.key)||t.label.trim()===``)return null;let r={label:t.label.trim(),fields:W(n,t.unit)};return{kind:`fields`,cap:`consumables`,...e?.enabled===void 0?{}:{enabled:e.enabled},fields:e?.fields??{lastChangedAt:H(`now`),lastFetchedAt:H(`now`)},items:{...e?.items,[t.key]:r}}}function Re(e){if(e.level!==void 0)return`percent`;let t=e[`remaining.unit`];if(t===void 0||t.kind!==`expression`)return null;try{let e=E.safeParse(JSON.parse(t.expr));return e.success?e.data:null}catch{return null}}function ze(e){return Object.entries(e?.items??{}).map(([e,t])=>{let n=Re(t.fields),r=G(t.fields.level??t.fields[`remaining.value`]),i=r===null?null:V(`number`,r);return n!==null&&i!==null&&Pe(W(i,n),t.fields)?{key:e,label:t.label,unit:n,source:r}:{key:e,label:t.label,unit:null,source:null}})}function Be(e,t){let n=Object.fromEntries(Object.entries(e.items??{}).filter(([e])=>e!==t));return Object.keys(n).length===0?null:{...e,items:n}}function Ve(e){return e.toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,48)}function He(e){let t=e.fields.lastPressedAt;if(t===void 0||t.kind!==`expression`)return[];let n=Object.entries(t.bindings).filter(([e])=>e.startsWith(`active`)).flatMap(([,e])=>e.kind===`from`?[e.source]:[]);return[...new Map(n.map(e=>[h(e),e])).values()]}function Ue(e){let t=e.fields.lastPressedAt;if(t===void 0||t.kind!==`expression`)return[];let n=t.bindings;return Object.entries(n).flatMap(([e,t])=>{if(!e.startsWith(`active`)||t.kind!==`from`)return[];let r=n[`changed${e.slice(6)}`];return r===void 0||r.kind!==`from`?[]:[{source:t.source,cap:t.cap,activeField:t.fieldPath,changedAtField:r.fieldPath}]})}function G(e){if(e===void 0)return null;if(e.kind===`from`){let{kind:t,...n}=e;return{...n,kind:`number`}}if(e.kind!==`expression`||e.expr!==`number(x)`)return null;let t=e.bindings.x;if(t===void 0||t.kind!==`from`||Object.keys(e.bindings).length!==1)return null;let{kind:n,...r}=t;return{...r,kind:`string`}}function We(e,t){let n=G(e.fields.percentage);if(n===null)return!1;let r=U({percentage:n,mode:t}),{enabled:i,...a}=e;return r!==null&&B(a,r)}function K(e){return e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,location:e.location,type:e.type}))}function Ge(e,t,n){let r=t.trim().toLowerCase();return r===``?[]:e.filter(e=>!n.includes(e.id)&&[e.name,e.stableId,e.location??``].some(e=>e.toLowerCase().includes(r))).toSorted((e,t)=>e.name.localeCompare(t.name)).slice(0,20)}function q(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n||Array.isArray(n))return;n=Object.getOwnPropertyDescriptor(n,e)?.value}return n}function Ke(e,t,n,r){return r===null?{kind:`from`,source:e,cap:t,fieldPath:n.path}:V(r,{source:e,cap:t,fieldPath:n.path,kind:n.kind})}function qe(e,t,n,r){let i={addonId:e.addonId,stableId:e.stableId};return t.caps.flatMap(e=>e.fields.filter(e=>e.item!==!0).map(t=>({cap:e.cap,path:t.path,kind:t.kind,value:n===null?void 0:q(n[e.cap],t.path),source:Ke(i,e.cap,t,r)})))}function J(e,t){return t?e===void 0?`—`:e===null?`null`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e):`…`}var Je=[];function Y({title:e,targetKind:t,excludeDeviceIds:r=Je,onPick:i,onCancel:o}){let{t:s}=j(),[f,p]=n(null);return a(`aside`,{"aria-label":e,className:`${u} ${l} flex flex-col gap-2`,children:[c(`h3`,{className:d,children:e}),f===null?c(Ye,{excludeDeviceIds:r,onSelect:p}):c(X,{device:f,targetKind:t,onPick:i,onBack:()=>p(null)}),c(`div`,{children:c(O,{variant:`ghost`,size:`sm`,onClick:o,children:s(`customize.picker.cancel`)})})]})}function Ye({excludeDeviceIds:e,onSelect:t}){let{t:r}=j(),[i,s]=n(``),l=k({projection:`slim`});return a(o,{children:[a(`label`,{className:`flex flex-col gap-1 text-[11px] text-foreground-subtle`,children:[r(`customize.picker.search`),c(he,{type:`search`,"aria-label":r(`customize.picker.search`),value:i,onChange:e=>s(e.target.value)})]}),l.status===`pending`&&c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:r(`customize.picker.loadingDevices`)}),l.status===`error`&&c(D,{title:r(`customize.picker.devicesFailed`),message:l.error?.message??``}),l.status===`success`&&c(`ul`,{className:`flex flex-col gap-1`,children:Ge(K(l.data),i,e).map(e=>c(`li`,{children:a(`button`,{type:`button`,className:`text-left text-[11px] hover:underline`,onClick:()=>t(e),children:[e.name,` `,a(`span`,{className:`text-foreground-subtle`,children:[`· `,e.stableId]})]})},e.id))})]})}function X({device:e,targetKind:t,selected:n,onPick:r,onBack:i}){let{t:o}=j(),s=le({deviceId:e.id}),l=me({deviceId:e.id});if(s.status===`pending`)return c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:o(`customize.picker.loadingFields`)});if(s.status===`error`)return c(D,{title:o(`customize.picker.fieldsFailed`),message:s.error?.message??``});let u=qe(e,s.data,l.status===`success`?l.data:null,t),d=u.filter(e=>e.source===null).length,f={addonId:e.addonId,stableId:e.stableId};return a(`div`,{className:`flex flex-col gap-1`,children:[a(`button`,{type:`button`,className:`text-left text-[11px] text-primary`,onClick:i,children:[`← `,e.name]}),l.status===`error`&&c(`p`,{role:`alert`,className:`text-[10px] text-warning`,children:o(`customize.picker.valuesFailed`,{reason:l.error?.message??``})}),c(`ul`,{role:`listbox`,"aria-label":o(`customize.picker.fields`),className:`flex flex-col gap-1`,children:u.map(t=>{let i=t.source;if(i===null)return null;let o=()=>r({device:e,ref:f,cap:t.cap,path:t.path,kind:t.kind,source:i,value:t.value});return a(`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:[a(`span`,{className:`font-mono`,children:[t.cap,`.`,t.path]}),c(`span`,{children:J(t.value,l.status===`success`)})]},`${t.cap}.${t.path}`)})}),d>0&&t!==null&&c(`p`,{className:`text-[10px] text-foreground-subtle`,children:o(`customize.picker.hidden`,{count:d,kind:o(`customize.kinds.${t}`)})})]})}var Xe=`integration`;function Z(e,t){switch(e.kind){case`from`:{let n=h(e.source);return`${t.get(n)??n} · ${e.cap}.${e.fieldPath}`}case`expression`:return e.expr;case`code`:return`code`}}function Ze(e,t){if(e.kind===`unreachable`)return{kind:`unknown`,reason:e.error};if(e.state===null)return{kind:`unknown`,reason:A.t(`helpers.fieldsTableRows.composerNotReported`)};let n=e.state.fields.find(t);return n===void 0?{kind:`unknown`,reason:A.t(`helpers.fieldsTableRows.noValue`)}:n.state===`unavailable`?{kind:`unavailable`,reason:n.reason??A.t(`common.unavailable`)}:{kind:`value`,value:n.value,staleReason:n.state===`stale`?n.reason??A.t(`common.stale`):null}}function Q(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?Ze(e.input.state,r):{kind:`off`}}}function Qe(e){let t=e.feature.cap;return Object.entries(e.feature.fields).map(([n,r])=>Q(e,n,r,e=>e.cap===t&&e.path===n&&e.item===void 0))}function $e(e){let t=e.feature.cap;return Object.entries(e.feature.items??{}).flatMap(([n,r])=>Object.entries(r.fields).map(([r,i])=>Q(e,re(ae,n,r),i,e=>e.cap===t&&e.path===r&&e.item?.arrayPath===`items`&&e.item.key===n)))}function et(e,t,n){if(e===null)return{kind:`unknown`,reason:A.t(`helpers.fieldsTableRows.stateUnreadable`)};let r=q(e[t],n),i=r===void 0?void 0:y(r);return i===void 0?{kind:`unknown`,reason:A.t(`helpers.fieldsTableRows.notReported`)}:{kind:`value`,value:i,staleReason:null}}function tt(e){if(e.mode!==`replace`)return[];let t=e.feature.cap,n=new Set(Object.keys(e.feature.fields));return(e.input.nativeFields.get(t)??[]).filter(e=>!n.has(e)).map(n=>({key:`${t}.${n}`,cap:t,field:n,origin:`native`,mode:e.mode,from:Xe,value:et(e.input.snapshot,t,n)}))}function nt(e){return e.composition.features.flatMap(t=>{if(t.kind!==`fields`)return[];let n={feature:t,mode:e.nativeCaps.has(t.cap)?`replace`:`add`,enabled:m(t),input:e};return[...Qe(n),...$e(n),...tt(n)]})}var rt={min:`min(a, b, …)`,max:`max(a, b, …)`,abs:`abs(x)`,floor:`floor(x)`,ceil:`ceil(x)`,sqrt:`sqrt(x)`,round:`round(x, digits?)`,pow:`pow(x, y)`,clamp:`clamp(x, lo, hi)`,avg:`avg(a, b, …)`,sum:`sum(a, b, …)`,coalesce:`coalesce(a, b, …)`,age:`age(now, ts)`,convert:`convert(x, "from", "to")`,any:`any(a, b, …)`,all:`all(a, b, …)`,within:`within(ts, ms)`,number:`number(x)`,latest:`latest(ts, …)`,rose:`rose(level, changedAt, debounceMs?)`,count:`count(x)`},it=/[A-Za-z_][A-Za-z0-9_]*$/;function at(e,t,n){let r=it.exec(e.slice(0,t))?.[0]??``;if(r===``)return[];let i=n.filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`binding`,label:e,insert:e,hintKey:null})),a=`now`.startsWith(r)?[{kind:`now`,label:`now`,insert:`now`,hintKey:`compositionEditor.now`}]:[],o=[...oe].filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`builtin`,label:rt[e]??e,insert:`${e}(`,hintKey:`compositionEditor.builtins.${e}`}));return[...i,...a,...o].slice(0,8)}function ot(e,t,n){let r=t-(it.exec(e.slice(0,t))?.[0]??``).length;return{text:`${e.slice(0,r)}${n.insert}${e.slice(t)}`,cursor:r+n.insert.length}}e();function st({label:e,value:t,bindings:r,onChange:i}){let{t:o}=j(),l=s(null),[u,d]=n(t.length),f=at(t,u,r);return a(`div`,{className:`flex flex-col gap-1`,children:[a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[e,c(`input`,{ref:l,className:`font-mono px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`,value:t,onChange:e=>{i(e.target.value),d(e.target.selectionStart??e.target.value.length)},onSelect:e=>d(e.currentTarget.selectionStart??t.length)})]}),f.length>0&&c(`ul`,{role:`listbox`,"aria-label":o(`compositionEditor.suggestions`),className:`rounded border border-border bg-surface text-[11px]`,children:f.map(e=>a(`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=ot(t,u,e);i(n.text),d(n.cursor),l.current?.focus()},children:[c(`span`,{className:`font-mono`,children:e.label}),e.hintKey!==null&&c(`span`,{className:`text-foreground-subtle`,children:o(e.hintKey)})]},`${e.kind}:${e.label}`))})]})}function ct(e,t,n){if(e.kind===`code`)return{kind:`unavailable`,reason:A.t(`helpers.fieldPreview.codeFields`)};if(e.kind===`expression`&&(w(e.expr,`rose`)||w(e.expr,`count`)))return{kind:`runtime-only`};let r=v(e).filter(e=>t.get(g(e.source,e.cap))?.kind!==`value`).map(b);if(r.length>0)return{kind:`waiting`,missing:r};let i=ee({source:e,now:n,read:e=>{let n=t.get(g(e.source,e.cap)),r=n?.kind===`value`?q(n.slice,e.fieldPath):void 0,i=r===void 0?void 0:y(r);return i===void 0?{state:`unavailable`,reason:A.t(`helpers.fieldPreview.notReported`,{path:`${e.cap}.${e.fieldPath}`}),fatal:!1}:{state:`fresh`,value:i}}});return i.state===`unavailable`?{kind:`unavailable`,reason:i.reason}:{kind:`value`,value:i.value,stale:i.reason}}e();function lt({sliceKey:e,deviceId:n,capName:r,onReading:i}){let a=ge(p().trpcClient,n,r);return t(()=>{i(e,a===void 0?{kind:`pending`}:{kind:`value`,slice:a})},[e,a,i]),null}function ut(e,t){return[...new Map(v(e).map(e=>[g(e.source,e.cap),e]))].map(([e,n])=>({key:e,read:n,device:t.get(h(n.source))}))}function dt({source:e}){let{t}=j(),r=k({projection:`slim`}),[o,s]=n(new Map),l=i((e,t)=>{s(n=>new Map([...n,[e,t]]))},[]),u=ut(e,L(r.status===`success`?K(r.data):[])),d=r.status===`success`?u.filter(e=>e.device===void 0).map(e=>h(e.read.source)):[];return a(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[u.map(e=>e.device===void 0?null:c(lt,{sliceKey:e.key,deviceId:e.device.id,capName:e.read.cap,onReading:l},e.key)),c(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.label`)}),r.status===`error`?c(`span`,{className:`text-warning`,children:t(`compositionEditor.preview.devicesFailed`,{reason:r.error?.message??``})}):d.length>0?c(`span`,{className:`text-warning`,children:t(`compositionEditor.preview.unknownDevice`,{sources:d.join(`, `)})}):c(ft,{preview:ct(e,o,Date.now())})]})}function ft({preview:e}){let{t}=j();switch(e.kind){case`value`:return a(`strong`,{children:[`→ `,J(e.value,!0),e.stale===null?``:` (${e.stale})`]});case`unavailable`:return c(`span`,{className:`text-warning`,children:e.reason});case`waiting`:return c(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.waiting`,{sources:e.missing.join(`, `)})});case`runtime-only`:return c(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.runtimeOnly`)})}}e();function pt({path:e,kind:t,required:r,source:i,onSet:s,onClear:l,onRemoveBinding:u,sourceNames:d}){let{t:f}=j(),[p,m]=n(`idle`),h=i?.kind===`expression`?i:null;return a(`div`,{className:`flex flex-col gap-1 rounded border border-border p-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[c(`span`,{className:`font-mono text-[11px]`,children:e}),a(`span`,{className:`text-[10px] text-foreground-subtle`,children:[f(`customize.kinds.${t}`),r?` · ${f(`compositionEditor.required`)}`:``]}),c(O,{size:`sm`,variant:`outline`,onClick:()=>m(`take`),children:f(`compositionEditor.takeFrom`)}),c(O,{size:`sm`,variant:`outline`,"aria-pressed":h!==null,onClick:()=>s(h??{kind:`expression`,expr:`null`,bindings:{}}),children:f(`compositionEditor.formula`)}),i!==void 0&&c(O,{size:`sm`,variant:`ghost`,onClick:l,children:f(`compositionEditor.clear`)})]}),i?.kind===`from`&&c(`span`,{className:`text-[11px]`,children:Z(i,d)}),h!==null&&a(o,{children:[c(st,{label:f(`compositionEditor.formulaFor`,{path:e}),value:h.expr,bindings:Object.keys(h.bindings),onChange:e=>s({...h,expr:e})}),c(`ul`,{className:`text-[11px] flex flex-col gap-0.5`,children:Object.entries(h.bindings).map(([e,t])=>a(`li`,{className:`flex flex-wrap items-center gap-2`,children:[c(`span`,{className:`font-mono`,children:e}),c(`span`,{children:t.kind===`from`?Z(t,d):JSON.stringify(t.value)}),c(O,{size:`sm`,variant:`ghost`,"aria-label":f(`compositionEditor.removeBinding`,{name:e}),onClick:()=>u(e),children:`×`})]},e))}),c(O,{size:`sm`,variant:`ghost`,onClick:()=>m(`add-binding`),children:f(`compositionEditor.addSource`)})]}),p!==`idle`&&c(Y,{title:f(p===`take`?`compositionEditor.takeFrom`:`compositionEditor.addSource`),targetKind:p===`take`?t:null,onCancel:()=>m(`idle`),onPick:e=>{if(p===`take`)s(e.source);else if(h!==null){let t=Se(Object.keys(h.bindings));s({...h,bindings:{...h.bindings,[t]:{kind:`from`,source:e.ref,cap:e.cap,fieldPath:e.path}}})}m(`idle`)}}),i!==void 0&&c(dt,{source:i})]})}e();function mt(e){return e===null||e.kind===`known`?null:e}function ht({draft:e,deviceType:t,nativeCaps:r,targetFields:i,dispatch:s}){let{t:l}=j(),u=ce({deviceType:t}),d=k({projection:`slim`}),f=new Map([...L(d.status===`success`?K(d.data):[])].map(([e,t])=>[e,t.name])),[p,m]=n(null),h=mt(r)??mt(i),g=r?.kind===`known`?r.value:new Set,_=new Set(e.features.map(e=>e.cap)),v=u.status===`success`?u.data.caps.filter(e=>!_.has(e.cap)&&!g.has(e.cap)):[],y=[...g].filter(e=>!_.has(e)),b=e=>g.has(e)?((i?.kind===`known`?i.value.caps.find(t=>t.cap===e):void 0)?.fields??[]).filter(e=>e.item!==!0&&!e.path.includes(`.`)).map(e=>({path:e.path,kind:e.kind,required:!1})):((u.status===`success`?u.data.caps.find(t=>t.cap===e):void 0)?.fields??[]).map(e=>({path:e.path,kind:e.kind,required:e.required}));return h===null?a(o,{children:[a(`section`,{"aria-labelledby":`editor-features`,className:`${I} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),u.status===`pending`&&c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.checking`)}),u.status===`error`&&c(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.unknown`,{reason:u.error?.message??``})}),a(`div`,{className:`flex flex-wrap gap-1`,children:[e.features.map(e=>a(`span`,{className:`flex items-center gap-1 rounded border border-border px-1.5 text-[11px]`,children:[e.cap,c(de,{variant:g.has(e.cap)?`default`:`info`,children:g.has(e.cap)?l(`compositionEditor.replaces`):l(`compositionEditor.added`)}),c(`button`,{type:`button`,"aria-label":l(`compositionEditor.removeFeature`,{cap:e.cap}),onClick:()=>s({type:`remove-feature`,cap:e.cap}),children:`×`})]},e.cap)),v.map(e=>a(O,{size:`sm`,variant:`outline`,onClick:()=>s({type:`add-feature`,cap:e.cap}),children:[`+ `,e.cap]},e.cap)),y.map(e=>c(O,{size:`sm`,variant:`ghost`,onClick:()=>s({type:`add-feature`,cap:e}),children:l(`compositionEditor.replaceIn`,{cap:e})},e))]})]}),e.features.map(e=>a(`section`,{"aria-label":l(`compositionEditor.steps.fieldsOf`,{cap:e.cap}),className:`${I} flex flex-col gap-2`,children:[a(`div`,{className:`flex items-center justify-between`,children:[c(`h2`,{className:`text-sm font-semibold`,children:l(`compositionEditor.steps.fieldsOf`,{cap:e.cap})}),c(O,{size:`sm`,variant:`outline`,onClick:()=>m(e.cap),children:l(`compositionEditor.copyFeature`)})]}),p===e.cap&&c(Y,{title:l(`compositionEditor.copyFeature`),targetKind:null,onCancel:()=>m(null),onPick:t=>{s({type:`copy-feature`,cap:e.cap,from:t.ref,sourceCap:t.cap,paths:b(e.cap).map(e=>e.path)}),m(null)}}),b(e.cap).map(t=>c(pt,{path:t.path,kind:t.kind,required:t.required,source:e.fields[t.path],onSet:n=>s({type:`set-field`,cap:e.cap,path:t.path,source:n}),onClear:()=>s({type:`clear-field`,cap:e.cap,path:t.path}),onRemoveBinding:n=>s({type:`remove-binding`,cap:e.cap,path:t.path,bindingName:n}),sourceNames:f},t.path))]},e.cap))]}):a(`section`,{"aria-labelledby":`editor-features`,className:`${I} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:h.kind===`unknown`?h.reason:l(`compositionEditor.reading`)})]})}var $=`px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`;function gt({draft:e,targetName:t,dispatch:n}){let r=f(),{t:i}=j(),o=e.target;return a(`section`,{"aria-labelledby":`editor-target`,className:`${I} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-target`,className:`text-sm font-semibold`,children:i(`compositionEditor.steps.target`)}),o.kind===`existing`?c(`p`,{className:`text-[11px]`,children:i(`compositionEditor.existingTarget`,{name:t??`${o.device.addonId}/${o.device.stableId}`})}):a(`div`,{className:`grid grid-cols-3 gap-2`,children:[a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[i(`compositionEditor.targetType`),c(`select`,{className:$,value:o.type,onChange:e=>{let t=Object.values(_).find(t=>t===e.target.value);t!==void 0&&n({type:`set-new-type`,deviceType:t})},children:Object.values(_).map(e=>c(`option`,{value:e,children:ue(e,r).label},e))})]}),a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[i(`customize.identity.role`),a(`select`,{className:$,value:o.role??``,onChange:e=>n({type:`set-new-role`,role:Object.values(T).find(t=>t===e.target.value)??null}),children:[c(`option`,{value:``,children:i(`customize.identity.noRole`)}),Object.values(T).map(e=>c(`option`,{value:e,children:pe(e,r).label},e))]})]}),a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[i(`compositionEditor.name`),c(`input`,{className:$,value:e.name,onChange:e=>n({type:`set-name`,name:e.target.value})})]})]})]})}e();function _t({draft:e,blockId:r,saving:i,onSave:o,onCancel:s}){let{t:l}=j(),u=se(),d=be(e),f=d.ok?JSON.stringify(d.composition):``,[p,m]=n({key:``,state:{kind:`checking`}});t(()=>{if(!d.ok)return;let e=d.composition,t=setTimeout(()=>{u.mutateAsync({composition:e,...r===null?{}:{blockId:r}}).then(e=>m({key:f,state:e.ok?{kind:`ok`}:{kind:`refused`,problems:e.problems}})).catch(e=>m({key:f,state:{kind:`unknown`,reason:e instanceof Error?e.message:String(e)}}))},500);return()=>clearTimeout(t)},[f,r]);let h=d.ok?p.key===f?p.state:{kind:`checking`}:{kind:`invalid-draft`,problems:d.problems};return a(`section`,{"aria-labelledby":`editor-verify`,className:`${I} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-verify`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.verify`)}),h.kind===`checking`&&c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.verify.checking`)}),h.kind===`ok`&&c(`p`,{className:`text-[11px] text-success`,children:l(`compositionEditor.verify.ok`)}),h.kind===`unknown`&&c(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.verify.unknown`,{reason:h.reason})}),(h.kind===`invalid-draft`||h.kind===`refused`)&&c(`ul`,{role:`alert`,className:`flex flex-col gap-1 text-[11px] text-danger`,children:h.kind===`invalid-draft`?h.problems.map(e=>c(`li`,{children:e},e)):h.problems.map(e=>a(`li`,{children:[c(`span`,{className:`font-mono`,children:e.path}),` — `,e.message]},`${e.path}:${e.code}`))}),a(`div`,{className:`flex gap-2`,children:[c(O,{variant:`ghost`,onClick:s,children:l(`compositionEditor.cancel`)}),c(O,{disabled:h.kind!==`ok`||i||!d.ok,onClick:()=>d.ok&&o(d.composition),children:l(`compositionEditor.save`)})]})]})}e();function vt({initial:e,blockId:t,deviceType:r,targetName:i=null,nativeCaps:a,targetFields:o,save:s,onCancel:l,showTemplates:u=!1}){let[d,f]=n(e),p=`${d.name}:${d.features.map(e=>e.cap).join(`,`)}:${d.target.kind===`new`?d.target.type:`existing`}`;return c(yt,{seed:d,blockId:t,deviceType:r,targetName:i,nativeCaps:a,targetFields:o,showTemplates:u,onApplyTemplate:e=>{f(De(e))},save:s,onCancel:l},p)}function yt({seed:e,blockId:t,deviceType:i,targetName:o,nativeCaps:s,targetFields:l,showTemplates:u,onApplyTemplate:d,save:f,onCancel:p}){let{t:m}=j(),h=fe(),[g,_]=r(ye,e),[v,y]=n(!1),[b,x]=n(null),S=async t=>{xe(e,g)&&!await h({title:m(`compositionEditor.templates.confirmTitle`),message:m(`compositionEditor.templates.confirmMessage`),confirmLabel:m(`compositionEditor.templates.confirmApply`),variant:`danger`})||d(t)},C=g.target.kind===`new`?g.target.type:i,w=async e=>{y(!0);let t=await f(e,g.name);y(!1),x(t.kind===`refused`?t.reason:null)};return a(`div`,{className:`flex flex-col gap-4`,children:[u&&g.target.kind===`new`&&a(`div`,{className:`rounded-lg border border-border bg-surface p-4 flex flex-wrap gap-2`,"data-testid":`composition-templates`,children:[c(`span`,{className:`text-[11px] text-foreground-subtle self-center`,children:m(`compositionEditor.templates.label`)}),Ce.map(e=>c(O,{size:`sm`,variant:`outline`,onClick:()=>void S(e),children:m(`compositionEditor.templates.${e}`)},e))]}),c(gt,{draft:g,targetName:o,dispatch:_}),c(ht,{draft:g,deviceType:C,nativeCaps:s,targetFields:l,dispatch:_}),c(_t,{draft:g,blockId:t,saving:v,onSave:e=>void w(e),onCancel:p}),b!==null&&c(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:b})]})}export{Me as C,ve as D,M as E,_e as O,je as S,Oe as T,G as _,X as a,Fe as b,K as c,Le as d,ze as f,Ve as g,We as h,nt as i,Ie as l,Ue as m,ct as n,J as o,He as p,st as r,q as s,vt as t,U as u,Be as v,ke as w,B as x,Ne as y};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{S as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Mr as n,pr as r}from"./client-
|
|
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-CEHpkaJP.js";import{Mr as n,pr as r}from"./client-Ca-96r9I.js";import{t as i}from"./boxes-B64NRkVe.js";import{Bn as a,Mi as o,Oi as s,zi as c}from"./src-Bt0KiIin.js";import{t as l}from"./useTranslation-D3Is_4B6.js";import{$ as u,Z as d,et as f,g as p,x as m}from"./index-CIQcOfrF.js";import{E as h,O as g,T as _,t as v,w as y}from"./CompositionEditor-ChpgaVIC.js";import{t as b}from"./AdminPage-CgbWYJ_a.js";var x=`new`;function S(e){return e instanceof Error?e.message:String(e)}function C(e){let t=e.trim();return t===``?{}:{name:t}}function w(){let{blockId:w}=f(),{t:T}=l(),E=u(),D=s(),O=c(),k=w===void 0||w===x,A=o({blockId:w??``},{enabled:!k}),j=()=>{E(p)},M=e=>t(b,{icon:i,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(n.Sensor),blockId:null,deviceType:n.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(a,{title:T(`compositionEditor.loadFailed`),message:A.error.message})));if(A.data.state===`not-loaded`)return M(N(t(`p`,{role:`status`,children:T(`customize.status.notLoaded`,{reason:A.data.reason})})));let P=A.data.view;if(P===null)return M(N(t(`p`,{children:T(`compositionEditor.notFound`,{blockId:w})})));let F=r(P.block);if(F===null)return M(N(t(`p`,{children:T(`compositionEditor.notComposition`)})));if(F.target.kind===`existing`){let e=P.state.kind===`answered`?P.state.state?.deviceId??null:null;return M(N(e===null?t(`p`,{children:T(`compositionEditor.customizationUnknownDevice`)}):t(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,2 +1,2 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,L as i,S as a,b as o,o as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{An as l,D as u,Fn as d,It as f,Ji as p,Jr as m,Nt as h,Q as g,Wi as _,Wr as v,Yi as y,Zr as b,ai as x,fn as S,ir as C,kn as w,or as T,pi as E,rr as D,si as O,vn as k,xi as A,yi as j}from"./player-overlays-
|
|
1
|
+
import{$ as e,B as t,G as n,J as r,L as i,S as a,b as o,o as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{An as l,D as u,Fn as d,It as f,Ji as p,Jr as m,Nt as h,Q as g,Wi as _,Wr as v,Yi as y,Zr as b,ai as x,fn as S,ir as C,kn as w,or as T,pi as E,rr as D,si as O,vn as k,xi as A,yi as j}from"./player-overlays-CikRdqm6.js";import{n as M,t as N}from"./cloud-upload-Ck1AcqSa.js";import{t as P}from"./circle-slash-CEYz4tuU.js";import{t as F}from"./hard-drive-download-DVmQAuw3.js";import{$r as I,An as ee,B as L,Bn as R,F as te,Gc as z,H as ne,I as re,Ir as ie,J as B,Kc as ae,Kt as oe,Mn as se,Nc as ce,Nn as le,On as ue,Pn as de,Ql as fe,Qr as pe,Un as V,V as me,Vn as he,Wc as ge,ai as _e,ci as ve,cn as ye,cr as be,di as xe,ei as Se,er as H,fi as Ce,ii as we,iu as U,kn as Te,li as Ee,ni as De,oi as Oe,ol as ke,pi as Ae,qc as je,qt as Me,ra as Ne,ri as Pe,ru as Fe,si as Ie,ti as Le,ui as Re}from"./src-Bt0KiIin.js";import{t as W}from"./i18n-ATfMbes1.js";import{t as G}from"./useTranslation-D3Is_4B6.js";import"./mount-Dep-E57-.js";import{X as ze,w as Be}from"./index-CIQcOfrF.js";import{t as Ve}from"./AdminSectionedPage-Cx5lBMEy.js";import{t as He}from"./AdminPage-CgbWYJ_a.js";import{n as Ue}from"./authed-media-B64j5Vsu.js";import{t as K}from"./format-size-DIxKXxtj.js";import{a as We,c as Ge,l as Ke,n as qe,o as Je,s as Ye,t as Xe,u as Ze}from"./location-owned-usage-CPVIHMbS.js";e();function Qe(e){return Object.entries(e).map(([e,t])=>`${e} ${t}`).join(` · `)}function $e(e){return e.reduce((e,t)=>e+Object.values(t.stores).reduce((e,t)=>e+t,0),0)}function et(){let{t:e}=G(),t=H(),n=Ne(),[i,s]=r(null),[l,u]=r(null),d=async e=>{u(null);try{s(await n.mutateAsync({confirm:e}))}catch(e){u(e instanceof Error?e.message:String(e))}},p=async()=>{i===null||i.status!==`dry-run`||await t({title:e(`systemPage.deletedDevices.confirmTitle`,`Delete the data of deleted devices?`),message:i.devices.map(e=>`#${e.deviceId}: ${Qe(e.stores)}`).join(`
|
|
2
2
|
`),confirmLabel:e(`systemPage.deletedDevices.confirmLabel`,`Delete`),variant:`danger`})&&await d(!0)},m=[{key:`device`,header:e(`systemPage.deletedDevices.device`,`Device`),render:e=>`#${e.deviceId}`},{key:`stores`,header:e(`systemPage.deletedDevices.stores`,`Data held`),nowrap:!1,render:e=>Qe(e.stores)}];return a(`div`,{className:`space-y-4`,"data-testid":`deleted-devices-data`,children:[c(`p`,{className:`text-sm text-muted-foreground`,children:e(`systemPage.deletedDevices.intro`,`Data that still belongs to devices that were deleted before deletions were recorded: footage, events, history and per-addon settings. Scanning deletes nothing; deleting asks first and shows what goes.`)}),a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[a(V,{variant:`outline`,onClick:()=>void d(!1),disabled:n.isPending,"data-testid":`deleted-devices-scan`,children:[n.isPending?c(T,{className:`mr-2 h-4 w-4 animate-spin`}):c(S,{className:`mr-2 h-4 w-4`}),e(`systemPage.deletedDevices.scan`,`Scan`)]}),i?.status===`dry-run`&&i.devices.length>0?a(V,{variant:`danger`,onClick:()=>void p(),disabled:n.isPending,"data-testid":`deleted-devices-delete`,children:[c(f,{className:`mr-2 h-4 w-4`}),e(`systemPage.deletedDevices.delete`,`Delete the data of {{count}} devices…`,{count:i.devices.length})]}):null]}),l===null?null:c(`p`,{className:`text-sm text-danger`,children:l}),i?.status===`skipped`?c(`p`,{className:`text-sm text-warning`,"data-testid":`deleted-devices-skipped`,children:e(`systemPage.deletedDevices.skipped`,`Nothing was listed or deleted: the device list could not be trusted ({{reason}}). Try again.`,{reason:i.reason??``})}):null,i!==null&&i.status!==`skipped`?a(o,{children:[c(`p`,{className:`text-sm`,"data-testid":`deleted-devices-summary`,children:i.status===`cleaned`?e(`systemPage.deletedDevices.cleaned`,`Deleted {{rows}} items of {{count}} devices.`,{rows:$e(i.devices),count:i.devices.length}):e(`systemPage.deletedDevices.found`,`{{count}} deleted devices still hold {{rows}} items.`,{rows:$e(i.devices),count:i.devices.length})}),c(oe,{columns:m,rows:i.devices,rowKey:e=>e.deviceId,emptyMessage:e(`systemPage.deletedDevices.none`,`No data belongs to a deleted device.`)}),i.unreachable.length>0?c(`p`,{className:`text-xs text-muted-foreground`,children:e(`systemPage.deletedDevices.unreachable`,`Not asked (unreachable): {{names}}`,{names:i.unreachable.join(`, `)})}):null]}):null]})}e();function tt(){let{t:e}=G(),r=s(),i=H(),{data:o,isLoading:l,isError:u}=je({}),d=ae(),f=n(()=>d.data??[],[d.data]),{data:p}=ce({},{refetchOnWindowFocus:!1}),m=n(()=>Xe(o??[],p?.locations),[o,p?.locations]),{data:h}=z({},{refetchOnWindowFocus:!1}),g=n(()=>We(h),[h]),{state:_,openNew:v,openEdit:y,close:b}=L(),[x,S]=me(`type`),C=()=>{S(null),b()},w=e=>{S(e),v()},T=e=>{S(null),y(e.id)},E=o??[],D=_.mode===`edit`?E.find(e=>e.id===_.id)??null:null;t(()=>{_.mode===`new`&&(x===null||x===``)&&(S(null),b())},[_.mode,x,b,S]),t(()=>{_.mode===`edit`&&!l&&D===null&&(S(null),b())},[_.mode,l,D,b,S]),t(()=>{_.mode===`closed`&&x!==null&&S(null)},[_.mode,x,S]);let O=ge({onSuccess:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),k=ke({onSuccess:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),A=async(t,n)=>{Ke(n)&&!await i({title:e(`system.storage.disable`,`Disable "{{displayName}}"?`,{displayName:t.displayName}),message:e(`system.storage.nothingIsDeletedSetThe`,`{{consequence}} Nothing is deleted — set the location back to Read-only or Active to bring its footage back.`,{consequence:Ge(n).consequence}),confirmLabel:e(`common.disable`,`Disable`),variant:`danger`})||k.mutate(Ye(t,{mode:n}))},j=async t=>{if(await i({title:e(`system.storage.deleteLocation`,`Delete location "{{displayName}}"?`,{displayName:t.displayName}),message:e(`system.storage.thisRemovesTheLocationRecord`,`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`}))try{await O.mutateAsync({id:t.id}),_.mode===`edit`&&_.id===t.id&&C()}catch(n){await i({title:e(`system.storage.deleteAnyway`,`Delete anyway?`),message:e(`system.storage.forcingNote`,{error:n instanceof Error?n.message:String(n)}),confirmLabel:e(`system.storage.forceDelete`,`Force delete`),variant:`danger`})&&O.mutate({id:t.id,force:!0},{onSuccess:()=>{_.mode===`edit`&&_.id===t.id&&C()}})}},M=n(()=>{let e=new Map;for(let t of o??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[o]),N=l||d.isLoading,P=u||d.isError,F=_.mode===`new`&&x!==null&&x!==``,I=_.mode===`edit`&&D!==null;return a(He,{embedded:!0,children:[N&&c(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:e(`system.storage.loadingLocations`,`Loading locations…`)}),P&&c(`div`,{className:`text-xs text-danger`,children:e(`system.storage.failedToLoadStorageLocations`,`Failed to load storage locations.`)}),!N&&!P&&a(`div`,{className:`space-y-3`,children:[f.length===0&&c(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:e(`system.storage.noStorageLocationsDeclaredBy`,`No storage locations declared by any installed addon.`)}),f.map(e=>c(qe,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:M.get(e.id)??[],onAdd:w,onEdit:T,onDelete:e=>{j(e)},ownedBytesById:m,drainById:g,onSetMode:(e,t)=>{A(e,t)}},e.id))]}),F&&x!==null&&c(Ze,{initialType:x,onClose:C,onCreated:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),C()}}),I&&D!==null&&c(Je,{location:D,onClose:C,onSaved:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),C()}})]})}var nt={settings:{labelKey:`helpers.backupDatabases.settings.label`,descriptionKey:`helpers.backupDatabases.settings.description`},events:{labelKey:`helpers.backupDatabases.events.label`,descriptionKey:`helpers.backupDatabases.events.description`},history:{labelKey:`helpers.backupDatabases.history.label`,descriptionKey:`helpers.backupDatabases.history.description`}},rt=Object.keys(nt),q=[`settings`];function it(){return W.t(`helpers.backupDatabases.notCreated`)}function J(e){return W.t(nt[e].labelKey)}function at(e){return W.t(nt[e].descriptionKey)}function Y(e){let t=new Set(e);return rt.filter(e=>t.has(e))}function X(e){return e!==void 0&&e.length>0?Y(e):q}function ot(e){return Y(e)}function st(e,t){return t===void 0||!t.answered?`unknown`:t.databases.includes(e)?`present`:`absent`}function ct(e,t,n){return st(e,t)===`absent`&&!n.has(e)}function lt(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function ut(e){return!e.includes(`settings`)}function dt(e){return{databases:[...ot(e)]}}function ft(e,t){return e!==void 0&&e.length>0?Y(e):t!==void 0&&t.length>0?Y(t.map(e=>e.databaseId??`settings`)):q}function Z({databases:e}){let{t}=G();return a(`span`,{className:`flex flex-wrap items-center gap-1`,"data-testid":`backup-database-badges`,children:[e.map(e=>c(be,{variant:e===`settings`?`primary`:`info`,style:`fill`,size:`sm`,children:J(e)},e)),ut(e)&&c(be,{variant:`warning`,style:`fill`,size:`sm`,children:t(`backup.backupDatabaseBadges.snapshotsOnly`,`Snapshots only`)})]})}e();var pt=[[`backup`,`listDestinations`]],mt=[`backup`,`listArchives`];function ht({destinationId:e,restoreSupported:t,onOpenRestoreWizard:o}){let{t:l}=G(),u=s(),d=H(),{data:p,isLoading:m,isError:h}=we({destinationId:e}),g=p??[],_=I({onSuccess:()=>{u.invalidateQueries({queryKey:[[...mt]]}),u.invalidateQueries({queryKey:pt})}}),y=i(async t=>{await d({title:l(`backup.archiveList.deleteThisArchive`,`Delete this archive?`),message:l(`backup.archiveList.permanentlyDeletesAndFrees`,`Permanently deletes "{{value1}}" and frees {{value2}}.`,{value1:t.label??t.id,value2:K(t.sizeBytes)}),confirmLabel:l(`common.delete`,`Delete`),variant:`danger`})&&_.mutate({destinationId:e,backupId:t.id})},[d,e,_,l]),[b,x]=r(null),S=i(async t=>{x(t.id);try{let n=await Ue(gt(e,t.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${t.label??t.id}.tar.gz${t.encryption===void 0?``:`.csbk`}`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{x(null)}},[e]),C=n(()=>[...g].toSorted((e,t)=>t.createdAt-e.createdAt),[g]);return m?c(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:l(`backup.archiveList.loadingArchives`,`Loading archives…`)}):h?c(`div`,{className:`text-xs text-danger py-2`,children:l(`backup.archiveList.failedToReadManifestFor`,`Failed to read manifest for this destination`)}):C.length===0?c(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:l(`backup.archiveList.noArchivesAtThisDestination`,`No archives at this destination yet.`)}):c(oe,{columns:[{key:`when`,header:l(`backup.archiveList.when`,`When`),sortValue:e=>e.createdAt,render:e=>c(`span`,{className:`tabular-nums`,children:_t(e.createdAt)})},{key:`label`,header:l(`backup.archiveList.label`,`Label`),sortValue:e=>e.label??null,render:e=>a(`span`,{className:`inline-flex items-center gap-1`,children:[e.encryption!==void 0&&c(D,{className:`h-3 w-3 text-success`,"aria-label":l(`backup.archiveList.encryptedRestoreNeedsBackupKey`,`encrypted — restore needs backup key {{keyId}}`,{keyId:e.encryption.keyId})}),e.label??c(`span`,{className:`text-foreground-subtle italic`,children:`—`})]})},{key:`databases`,header:l(`backup.archiveList.databases`,`Databases`),nowrap:!1,notSortableReason:`Database badges`,render:e=>c(Z,{databases:X(e.databases)})},{key:`includes`,header:l(`backup.archiveList.files`,`Files`),nowrap:!1,notSortableReason:`Location list`,render:e=>e.locations.length>0?c(`span`,{className:`text-foreground-subtle`,children:e.locations.join(`, `)}):c(`span`,{className:`text-foreground-subtle italic`,children:l(`common.none`)})},{key:`size`,header:l(`backup.archiveList.size`,`Size`),align:`right`,sortValue:e=>e.sizeBytes,render:e=>c(`span`,{className:`tabular-nums`,children:K(e.sizeBytes)})},{key:`actions`,header:``,align:`right`,notSortableReason:`Actions`,render:n=>a(`span`,{className:`flex items-center justify-end gap-1`,children:[a(V,{variant:`ghost`,size:`sm`,onClick:()=>{S(n)},disabled:b===n.id,title:l(`backup.archiveList.downloadArchive`,`Download archive`),children:[b===n.id?c(T,{className:`h-3 w-3 animate-spin`}):c(v,{className:`h-3 w-3`}),l(`backup.archiveList.download`,`Download`)]}),t&&o&&a(V,{variant:`ghost`,size:`sm`,onClick:()=>o({destinationId:e,archiveId:n.id}),title:l(`backup.archiveList.restoreFromThisArchive`,`Restore from this archive`),children:[c(k,{className:`h-3 w-3`}),l(`backup.archiveList.restore`,`Restore`)]}),c(U,{variant:`ghost`,size:`sm`,icon:f,"aria-label":l(`backup.archiveList.delete`,`Delete {{value1}}`,{value1:n.label??n.id}),disabled:_.isPending,onClick:()=>{y(n)}})]})}],rows:C,rowKey:e=>e.id,minWidthPx:760,emptyMessage:l(`backup.archiveList.noArchivesAtThisDestination`,`No archives at this destination yet.`)})}function gt(e,t){return g(`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}function _t(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}e();var vt=[[`backup`,`listSchedules`]];function yt({onEdit:e,onOpenRestoreWizard:t}){let{t:o}=G(),{data:s,isLoading:l,isError:u,error:d,refetch:f}=ve(),p=s??[],m=Oe().data??[],h=n(()=>{let e=new Map;for(let t of m)e.set(t.id,t);return e},[m]),[g,_]=r(null),v=i(e=>{_(t=>t===e?null:e)},[]),y=g===null?null:p.find(e=>e.id===g)??null,b=n(()=>bt({destById:h,expandedId:g,onToggleExpand:v,onEdit:e}),[h,g,v,e]);return l?a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle animate-pulse`,children:[c(T,{className:`h-3.5 w-3.5 animate-spin`}),o(`backup.backupEntriesTable.loadingBackupEntries`,`Loading backup entries…`)]}):u?c(R,{title:o(`backup.backupEntriesTable.failedToLoadBackupEntries`,`Failed to load backup entries`),message:d instanceof Error?d.message:o(`backup.backupEntriesTable.unknownError`,`Unknown error`),onRetry:()=>void f()}):p.length===0?c(he,{icon:M,title:o(`backup.backupEntriesTable.noBackupEntriesYet`,`No backup entries yet`),description:o(`backup.backupEntriesTable.createOneToScheduleBackups`,`Create one to schedule backups across one or more storage locations.`)}):a(`div`,{className:`space-y-2`,children:[c(oe,{columns:b,rows:p,rowKey:e=>e.id,minWidthPx:980,maxBodyHeight:Me,emptyMessage:o(`backup.backupEntriesTable.noBackupEntriesYet`,`No backup entries yet`),onRowClick:t=>e(t)}),y!==null&&c(Dt,{row:y,destById:h,...t?{onOpenRestoreWizard:t}:{}})]})}function bt(e){return[{key:`expand`,header:``,width:`w-8`,nowrap:!0,notSortableReason:`Expand control`,render:t=>{let n=e.expandedId===t.id;return c(U,{variant:`ghost`,size:`sm`,icon:n?A:j,"aria-label":n?W.t(`backup.backupEntriesTable.hideArchives`,`Hide archives`):W.t(`backup.backupEntriesTable.showArchives`,`Show archives`),"aria-expanded":n,onClick:n=>{n.stopPropagation(),e.onToggleExpand(t.id)}})}},{key:`entry`,header:W.t(`backup.backupEntriesTable.entry`,`Entry`),sortValue:e=>e.label,render:e=>a(`span`,{className:`flex min-w-0 flex-col`,children:[c(`span`,{className:`truncate font-medium text-foreground`,children:e.label||W.t(`backup.backupEntriesTable.unnamed`,`(unnamed)`)}),e.lastRunAt!==void 0&&c(`span`,{className:`text-[10px] text-foreground-subtle`,children:W.t(`backup.backupEntriesTable.lastRun`,{when:new Date(e.lastRunAt).toLocaleString()})})]})},{key:`enabled`,header:W.t(`backup.backupEntriesTable.enabled`,`Enabled`),width:`w-20`,nowrap:!0,sortValue:e=>+!!e.enabled,render:e=>c(`span`,{onClick:e=>e.stopPropagation(),children:c(wt,{row:e})})},{key:`databases`,header:W.t(`backup.backupEntriesTable.backsUp`,`Backs up`),nowrap:!1,notSortableReason:`Database badges`,render:e=>c(Z,{databases:X(e.databases)})},{key:`locations`,header:W.t(`backup.backupEntriesTable.locations`,`Locations`),nowrap:!1,notSortableReason:`Location chips`,render:t=>c(xt,{row:t,destById:e.destById})},{key:`retention`,header:W.t(`backup.backupEntriesTable.retention`,`Retention`),width:`w-24`,nowrap:!0,sortValue:e=>e.retentionCount,render:e=>c(`span`,{onClick:e=>e.stopPropagation(),children:c(Tt,{row:e})})},{key:`schedule`,header:W.t(`backup.backupEntriesTable.schedule`,`Schedule`),width:`w-48`,nowrap:!0,sortValue:e=>e.cron,render:e=>c(St,{row:e})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:t=>c(`span`,{onClick:e=>e.stopPropagation(),children:c(Et,{row:t,onEdit:()=>e.onEdit(t)})})}]}function xt({row:e,destById:t}){let{t:n}=G();return e.locationIds.length===0?c(`span`,{className:`text-[11px] italic text-danger`,children:n(`backup.backupEntriesTable.noLocations`,`No locations`)}):c(`span`,{className:`flex flex-wrap gap-1`,children:e.locationIds.map(e=>c(`span`,{className:`inline-flex items-center rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-foreground`,title:e,children:t.get(e)?.displayName??e},e))})}function St({row:e}){let{t}=G(),n=e.cron.trim().length>0;return a(`span`,{className:`flex flex-col items-start gap-0.5`,children:[a(`span`,{className:`inline-flex items-center gap-1`,children:[c(M,{className:`h-3 w-3 text-foreground-subtle`}),c(`span`,{className:`font-mono text-[11px] text-foreground`,children:n?e.cron:t(`backup.backupEntriesTable.manual`,`Manual`)})]}),n&&e.nextRunAt!==void 0&&c(`span`,{className:`text-[10px] text-foreground-subtle`,children:W.t(`common.nextRun`,{when:new Date(e.nextRunAt).toLocaleString()})})]})}function Ct(e){return n(()=>({id:e.id,label:e.label,cron:e.cron,locationIds:[...e.locationIds],retentionCount:e.retentionCount,...e.dataSources?{dataSources:[...e.dataSources]}:{},...e.databases?{databases:[...e.databases]}:{}}),[e])}function wt({row:e}){let{t}=G(),n=s(),r=Ae({onSuccess:()=>{n.invalidateQueries({queryKey:vt})}}),i=Ct(e);return c(`label`,{className:`inline-flex cursor-pointer items-center`,children:c(`input`,{type:`checkbox`,className:`accent-primary`,checked:e.enabled,disabled:r.isPending,onChange:e=>r.mutate({...i,enabled:e.target.checked}),"aria-label":t(`backup.backupEntriesTable.enable`,`Enable {{value1}}`,{value1:e.label||e.id})})})}function Tt({row:e}){let{t:n}=G(),i=s(),a=Ae({onSuccess:()=>{i.invalidateQueries({queryKey:vt})}}),o=Ct(e),[l,u]=r(String(e.retentionCount));return t(()=>{u(String(e.retentionCount))},[e.retentionCount]),c(Fe,{type:`number`,min:1,max:1e3,value:l,disabled:a.isPending,onChange:e=>u(e.target.value),onBlur:()=>{let t=Number.parseInt(l,10);if(Number.isNaN(t)||t<1){u(String(e.retentionCount));return}t!==e.retentionCount&&a.mutate({...o,enabled:e.enabled,retentionCount:t})},onKeyDown:t=>{t.key===`Enter`&&t.target.blur(),t.key===`Escape`&&u(String(e.retentionCount))},className:`w-16`,"aria-label":n(`backup.backupEntriesTable.retentionFor`,`Retention for {{value1}}`,{value1:e.label||e.id})})}function Et({row:e,onEdit:t}){let{t:n}=G(),r=s(),i=H(),o=Se({onSuccess:()=>{r.invalidateQueries({queryKey:vt})}}),u=Ce({onMutate:()=>{r.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{r.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),r.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),r.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})}}),p=()=>{e.locationIds.length!==0&&u.mutate({destinations:[...e.locationIds],...e.dataSources&&e.dataSources.length>0?{locations:[...e.dataSources]}:{},label:e.label,retentionCount:e.retentionCount,databases:[...X(e.databases)]})},m=async()=>{await i({title:n(`backup.backupEntriesTable.deleteBackupEntry`,`Delete backup entry?`),message:n(`backup.backupEntriesTable.willStopRunningExistingArchives`,`"{{value1}}" will stop running. Existing archives are kept.`,{value1:e.label||e.id}),confirmLabel:n(`common.delete`,`Delete`),variant:`warning`})&&o.mutate({id:e.id})};return a(`span`,{className:`flex items-center justify-end gap-1.5`,children:[a(V,{size:`sm`,type:`button`,onClick:p,disabled:u.isPending||e.locationIds.length===0,title:n(`backup.backupEntriesTable.runThisEntryNow`,`Run this entry now`),children:[u.isPending?c(T,{className:`h-3 w-3 animate-spin`}):c(l,{className:`h-3 w-3`}),n(`backup.backupEntriesTable.runNow`,`Run now`)]}),c(U,{variant:`ghost`,size:`sm`,icon:d,"aria-label":n(`backup.backupEntriesTable.edit`,`Edit {{value1}}`,{value1:e.label||e.id}),onClick:t}),c(U,{variant:`ghost`,size:`sm`,icon:f,"aria-label":n(`backup.backupEntriesTable.delete`,`Delete {{value1}}`,{value1:e.label||e.id}),disabled:o.isPending,onClick:()=>{m()}})]})}function Dt({row:e,destById:t,onOpenRestoreWizard:n}){let{t:r}=G();return a(`div`,{className:`space-y-4 rounded-lg border border-border bg-background/30 px-4 py-3`,children:[c(`p`,{className:`text-[11px] font-medium text-foreground-subtle`,children:r(`backup.backupEntriesTable.archivesFor`,{name:e.label||e.id})}),e.locationIds.length===0&&c(`p`,{className:`text-xs italic text-foreground-subtle`,children:r(`backup.backupEntriesTable.thisEntryHasNoLocations`,`This entry has no locations selected.`)}),e.locationIds.map(e=>a(`div`,{className:`space-y-1.5`,children:[c(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:t.get(e)?.displayName??e}),c(ht,{destinationId:e,restoreSupported:t.get(e)?.restoreSupported??!0,...n?{onOpenRestoreWizard:n}:{}})]},e))]})}function Ot({selected:e,onChange:t,disabled:n=!1,testId:r=`backup-databases`}){let{t:i}=G(),o=_e().data,s=e.size>0&&ut(Y(e)),l=e.size===0?`Pick at least one.`:s?`Snapshots only: configuration and files are not part of this backup.`:null;return c(B,{label:i(`backup.backupDatabasePicker.whatToBackUp`,`What to back up`),required:!0,...l===null?{}:{description:l},children:c(`div`,{className:`divide-y divide-border rounded border border-border bg-background`,"data-testid":r,children:rt.map(s=>{let l=st(s,o),u=n||ct(s,o,e);return a(`label`,{className:`flex items-start gap-2 px-3 py-2 text-xs ${u?`opacity-60`:`cursor-pointer hover:bg-primary/5`}`,children:[c(ye,{checked:e.has(s),disabled:u,onChange:()=>t(lt(e,s)),"data-testid":`${r}-${s}`}),a(`span`,{className:`min-w-0 flex-1`,children:[a(`span`,{className:`flex flex-wrap items-center gap-1.5 text-foreground`,children:[J(s),l===`absent`&&c(be,{variant:`neutral`,size:`sm`,children:i(`backup.backupDatabasePicker.notCreatedYet`,`Not created yet`)})]}),c(`span`,{className:`block text-[11px] text-foreground-subtle`,children:l===`absent`?it():at(s)})]})]},s)})})})}e();function kt({onClose:e}){let{t}=G(),n=s(),[i,o]=r(new Set(q)),u=Ce({onMutate:()=>{n.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{n.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),n.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),n.invalidateQueries({queryKey:[[`backup`,`listRuns`]]}),e()}});return c(ue,{open:!0,onOpenChange:t=>!t&&e(),children:a(ee,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(le,{children:[c(de,{children:t(`backup.backupNowDialog.backUpNow`,`Back up now`)}),c(`p`,{className:`text-xs text-foreground-subtle`,children:t(`backup.backupNowDialog.runsOnceAndWritesThe`,`Runs once and writes the archive to every enabled backup location.`)})]}),c(Te,{children:a(`div`,{className:`p-4`,children:[c(Ot,{selected:i,onChange:o,disabled:u.isPending,testId:`backup-now-databases`}),u.error&&c(`p`,{role:`alert`,className:`pt-2 text-xs text-danger`,children:u.error.message})]})}),a(se,{children:[c(V,{variant:`outline`,size:`sm`,onClick:e,children:t(`common.cancel`,`Cancel`)}),a(V,{size:`sm`,onClick:()=>{i.size!==0&&u.mutate(dt(i))},disabled:i.size===0||u.isPending,"data-testid":`backup-now-run`,children:[u.isPending?c(T,{className:`h-3.5 w-3.5 animate-spin`}):c(l,{className:`h-3.5 w-3.5`}),t(`backup.backupNowDialog.backUpNow`,`Back up now`)]})]})]})})}e();function At(e){return e===null?`—`:new Date(e).toLocaleString()}function jt(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 Mt({revealed:e,onDone:t}){let{t:n}=G(),[i,o]=r(!1),[s,l]=r(!1);return c(ue,{open:!0,onOpenChange:e=>!e&&i&&t(),children:a(ee,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`border-danger/40`,"aria-labelledby":`backup-key-title`,children:[c(le,{children:c(de,{id:`backup-key-title`,children:n(`backup.encryptionCard.yourKey`,{keyId:e.keyId})})}),a(Te,{className:`space-y-3`,children:[a(`p`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 p-2 text-xs text-foreground`,children:[c(h,{className:`mt-0.5 h-4 w-4 shrink-0 text-danger`}),c(`span`,{children:n(`backup.backupEncryptionCard.thisKeyIsShownOnly`,`This key is shown only once. CamStack does not keep it — not the hub, not its database, not its backups. Without it, an encrypted backup cannot be restored by anyone, including you. Store it in a password manager or print it, away from this server.`)})]}),c(`div`,{className:`break-all rounded-md border border-border bg-background p-2 font-mono text-xs text-foreground select-all`,children:e.secretKey}),a(`div`,{className:`flex flex-wrap gap-2`,children:[a(V,{size:`sm`,variant:`outline`,onClick:()=>{navigator.clipboard?.writeText(e.secretKey).then(()=>l(!0))},children:[c(b,{className:`mr-1 h-3.5 w-3.5`}),s?n(`backup.backupEncryptionCard.copied`,`Copied`):n(`common.copy`,`Copy`)]}),a(V,{size:`sm`,variant:`outline`,onClick:()=>jt(e),children:[c(v,{className:`mr-1 h-3.5 w-3.5`}),n(`backup.backupEncryptionCard.downloadAsFile`,`Download as file`)]})]}),a(`label`,{className:`flex items-center gap-2 text-xs text-foreground`,children:[c(`input`,{type:`checkbox`,checked:i,onChange:e=>o(e.target.checked),className:`accent-primary`}),n(`backup.backupEncryptionCard.iHaveStoredThisKey`,`I have stored this key somewhere safe, off this server.`)]})]}),c(se,{children:c(V,{size:`sm`,disabled:!i,onClick:t,children:n(`backup.backupEncryptionCard.iHaveStoredIt`,`I have stored it`)})})]})})}function Nt(){let{t:e}=G(),t=De(),n=xe(),i=Le(),s=H(),[l,u]=r(null),[d,f]=r(null),p=t.data?.enabled??!1,m=t.data?.active??null,h=(t.data?.keys??[]).filter(e=>e.retiredAt!==null),g=async()=>{if(await s({title:p?e(`backup.backupEncryptionCard.replaceTheBackupKey`,`Replace the backup key`):e(`backup.backupEncryptionCard.encryptBackups`,`Encrypt backups`),message:p?e(`backup.backupEncryptionCard.aNewKeyIsGenerated`,`A new key is generated and shown once; new backups are encrypted to it. Older backups keep needing the key they were made with — keep that one too.`):e(`backup.backupEncryptionCard.aBackupKeyIsGenerated`,`A backup key is generated and shown once. Every new backup is encrypted to it, and restoring one will ask for it. Existing backups stay as they are.`),confirmLabel:p?e(`backup.backupEncryptionCard.generateANewKey`,`Generate a new key`):e(`backup.backupEncryptionCard.generateTheKey`,`Generate the key`),variant:`warning`})){f(null);try{let e=await n.mutateAsync({});u({keyId:e.keyId,secretKey:e.secretKey})}catch(e){f(e instanceof Error?e.message:String(e))}}},_=async()=>{if(await s({title:e(`backup.backupEncryptionCard.turnBackupEncryptionOff`,`Turn backup encryption off`),message:e(`backup.backupEncryptionCard.newBackupsWillBeWritten`,`New backups will be written unencrypted. Existing encrypted backups still need their key to be restored.`),confirmLabel:e(`backup.backupEncryptionCard.turnOff`,`Turn off`),variant:`danger`})){f(null);try{await i.mutateAsync({}),t.refetch()}catch(e){f(e instanceof Error?e.message:String(e))}}};return a(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-4`,children:[a(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[a(`div`,{className:`flex items-center gap-2`,children:[p?c(D,{className:`h-4 w-4 text-success`}):c(C,{className:`h-4 w-4 text-foreground-subtle`}),c(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`backup.backupEncryptionCard.encryption`,`Encryption`)}),c(`span`,{className:`text-xs text-foreground-subtle`,children:p&&m!==null?e(`backup.backupEncryptionCard.onKeySince`,`On — key {{keyId}}, since {{value2}}`,{keyId:m.keyId,value2:At(m.createdAt)}):e(`backup.backupEncryptionCard.offBackupsAreNotEncrypted`,`Off — backups are not encrypted`)})]}),c(`div`,{className:`flex gap-2`,children:p?a(o,{children:[c(V,{size:`sm`,variant:`outline`,disabled:n.isPending,onClick:()=>void g(),children:e(`backup.backupEncryptionCard.replaceKey`,`Replace key`)}),c(V,{size:`sm`,variant:`outline`,disabled:i.isPending,onClick:()=>void _(),children:e(`backup.backupEncryptionCard.turnOff`,`Turn off`)})]}):c(V,{size:`sm`,disabled:n.isPending,onClick:()=>void g(),children:e(`backup.backupEncryptionCard.enableEncryption`,`Enable encryption`)})})]}),c(`p`,{className:`text-xs text-foreground-subtle`,children:e(`backup.backupEncryptionCard.archivesAreEncryptedOnThis`,`Archives are encrypted on this server before they reach any destination. The server keeps only a public key, so it can encrypt scheduled backups but cannot decrypt them — only your backup key can. Covers the database snapshot, config.yaml, addon data (HomeKit pairing, Matter fabric, Tailscale state) and TLS.`)}),h.length>0&&a(`div`,{className:`text-xs`,children:[c(`p`,{className:`text-foreground-subtle`,children:e(`backup.backupEncryptionCard.olderKeysBackupsMadeWith`,`Older keys (backups made with them still need them):`)}),c(`ul`,{className:`font-mono text-foreground`,children:h.map(e=>a(`li`,{children:[e.keyId,` · `,At(e.createdAt),` → `,At(e.retiredAt)]},e.keyId))})]}),d!==null&&c(`p`,{className:`text-xs text-danger`,children:d}),l!==null&&c(Mt,{revealed:l,onDone:()=>{u(null),t.refetch()}})]})}e();var Pt=[{id:`manual`,labelKey:`backup.cronEditor.presetManual`,cron:``},{id:`hourly`,labelKey:`backup.cronEditor.presetHourly`,cron:`0 * * * *`,descriptionKey:`backup.cronEditor.presetHourlyDesc`},{id:`every-3h`,labelKey:`backup.cronEditor.preset3h`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,labelKey:`backup.cronEditor.preset6h`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,labelKey:`backup.cronEditor.presetDaily`,cron:`0 3 * * *`,descriptionKey:`backup.cronEditor.presetDailyDesc`},{id:`weekly-sun`,labelKey:`backup.cronEditor.presetWeekly`,cron:`0 3 * * 0`,descriptionKey:`backup.cronEditor.presetWeeklyDesc`}];function Ft(e){let t=e.trim();for(let e of Pt)if(e.cron===t)return e.id;return`custom`}function It({value:e,onChange:n,previewCount:i=5,disabled:o=!1}){let{t:s}=G(),l=Ft(e),[u,d]=r(l===`custom`);t(()=>{l!==`custom`&&d(!1)},[l]);let f=zt(e,250),p=Ee({cron:f,count:i},{enabled:f.trim().length>0}),m=p.data??null,h=e=>{d(!1),n(e.cron)},g=u||l===`custom`;return a(`div`,{className:`space-y-3`,children:[a(`div`,{className:`space-y-1`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:s(`backup.cronEditor.schedulePreset`,`Schedule preset`)}),a(`div`,{className:`flex flex-wrap gap-1.5`,children:[Pt.map(e=>c(`button`,{type:`button`,onClick:()=>h(e),disabled:o,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!u&&l===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.descriptionKey===void 0?e.description??s(e.labelKey):s(e.descriptionKey),children:s(e.labelKey)},e.id)),c(`button`,{type:`button`,onClick:()=>{d(!0),e.trim().length===0&&n(`0 3 * * *`)},disabled:o,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(g?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:s(`backup.cronEditor.custom`,`Custom…`)})]})]}),g&&a(`div`,{className:`space-y-1`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:s(`backup.cronEditor.cronExpression5FieldPosix`,`Cron expression (5-field POSIX)`)}),c(`input`,{type:`text`,value:e,onChange:e=>n(e.target.value),disabled:o,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),a(`p`,{className:`text-[10px] text-foreground-subtle`,children:[s(`backup.cronEditor.format`,`Format:`),` `,c(ze,{i18nKey:`backup.cronEditor.formatLine`,components:{code:c(`span`,{className:`font-mono`})}})]})]}),c(Lt,{cron:f,preview:m,loading:p.isFetching})]})}function Lt({cron:e,preview:t,loading:n}){let{t:r}=G();return n&&t===null?a(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[c(T,{className:`h-3 w-3 animate-spin`}),r(`backup.cronEditor.validating`,`Validating…`)]}):t===null?null:t.ok?t.nextRuns.length===0?c(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:r(`backup.cronEditor.noFutureRunsMatchThis`,`No future runs match this expression.`)}):a(`div`,{className:`space-y-1`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:r(`backup.cronEditor.nextRuns`,`Next runs`)}),c(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>a(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[c(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),c(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:Rt(e)})]},`${e}-${t}`))})]}):c(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??r(`backup.cronEditor.invalidCronExpression`,`Invalid cron expression`)})}function Rt(e){let t=e-Date.now();if(t<=0)return W.t(`helpers.relativeTime.now`);let n=Math.floor(t/1e3);if(n<60)return W.t(`helpers.relativeTime.inSeconds`,{count:n});let r=Math.floor(n/60);if(r<60)return W.t(`helpers.relativeTime.inMinutes`,{count:r});let i=Math.floor(r/60);if(i<24)return W.t(`helpers.relativeTime.inHours`,{count:i});let a=Math.floor(i/24);return W.t(`helpers.relativeTime.inDays`,{count:a})}function zt(e,i){let[a,o]=r(e),s=n(()=>e,[e]);return t(()=>{let e=setTimeout(()=>o(s),i);return()=>clearTimeout(e)},[s,i]),a}e();var Bt=[[`backup`,`listSchedules`]];function Vt({entry:e,onClose:t,onSaved:i}){let{t:o}=G(),l=s(),u=Oe(),d=u.data??[],[f,p]=r(e?.label??``),[m,h]=r(e?.cron??`0 3 * * *`),[g,_]=r(e?.enabled??!0),[v,y]=r(String(e?.retentionCount??7)),[b,x]=r(new Set(e?.locationIds??[])),[S,C]=r(new Set(e===null?q:X(e.databases))),w=Ae({onSuccess:()=>{l.invalidateQueries({queryKey:Bt}),i()}}),E=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},D=Number.parseInt(v,10),O=n(()=>f.trim().length>0&&b.size>0&&S.size>0&&!Number.isNaN(D)&&D>=1&&D<=1e3,[f,b,S,D]),k=()=>{O&&w.mutate({...e?{id:e.id}:{},label:f.trim(),cron:m.trim(),enabled:g,locationIds:Array.from(b),retentionCount:D,databases:[...ot(S)]})},A=w.error instanceof Error?w.error.message:null;return c(ne,{open:!0,onClose:t,title:e?o(`backup.backupEntryModal.editBackupEntry`,`Edit backup entry`):o(`backup.backupEntryModal.newBackupEntry`,`New backup entry`),icon:M,error:A,width:`lg`,testId:`backup-entry-form`,footer:a(V,{size:`sm`,type:`button`,onClick:k,disabled:!O||w.isPending,children:[w.isPending?c(T,{className:`h-3.5 w-3.5 animate-spin`}):null,e?o(`common.save`,`Save`):o(`backup.backupEntryModal.createEntry`,`Create entry`)]}),children:a(`div`,{className:`space-y-4`,children:[c(B,{label:o(`backup.backupEntryModal.name`,`Name`),required:!0,children:c(Fe,{value:f,onChange:e=>p(e.target.value),placeholder:o(`backup.backupEntryModal.nightlyOffsite`,`Nightly offsite`),autoFocus:!0,"data-testid":`backup-entry-name`})}),a(B,{label:o(`backup.backupEntryModal.locationsSelected`,`Locations ({{value1}} selected)`,{value1:String(b.size)}),required:!0,children:[u.isLoading&&a(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[c(T,{className:`h-3.5 w-3.5 animate-spin`}),o(`backup.backupEntryModal.loadingLocations`,`Loading locations…`)]}),!u.isLoading&&d.length===0&&c(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:o(`backup.backupEntryModal.noBackupsStorageLocationsConfigured`,"No `backups` storage locations configured. Add one in Settings → Storage first.")}),d.length>0&&c(`div`,{className:`max-h-52 divide-y divide-border overflow-y-auto rounded border border-border bg-background`,children:d.map(e=>a(`label`,{className:`flex cursor-pointer items-center justify-between px-3 py-2 text-xs hover:bg-primary/5`,children:[a(`div`,{className:`flex items-center gap-2`,children:[c(`input`,{type:`checkbox`,checked:b.has(e.id),onChange:()=>E(e.id),className:`accent-primary`}),c(`span`,{className:`text-foreground`,children:e.displayName})]}),a(`div`,{className:`flex items-center gap-1.5`,children:[c(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e.kind}),c(`span`,{className:`font-mono text-[10px] text-foreground-subtle`,children:e.id})]})]},e.id))})]}),c(Ot,{selected:S,onChange:C,disabled:w.isPending,testId:`backup-entry-databases`}),a(`div`,{className:`grid grid-cols-2 gap-3`,children:[c(B,{label:o(`backup.backupEntryModal.retentionArchivesKept`,`Retention (archives kept)`),required:!0,children:c(Fe,{type:`number`,min:1,max:1e3,value:v,onChange:e=>y(e.target.value),"data-testid":`backup-entry-retention`})}),c(B,{label:o(`backup.backupEntryModal.enabled`,`Enabled`),description:o(`backup.backupEntryModal.runOnScheduleWhenChecked`,`Run on schedule when checked.`),children:a(`label`,{className:`inline-flex cursor-pointer items-center gap-2 py-1.5 text-xs text-foreground`,children:[c(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`accent-primary`,"data-testid":`backup-entry-enabled`}),c(`span`,{children:o(`backup.backupEntryModal.runOnSchedule`,`Run on schedule`)})]})})]}),c(B,{label:o(`backup.backupEntryModal.schedule`,`Schedule`),children:c(It,{value:m,onChange:h,disabled:w.isPending})})]})})}e();var Ht=2e3,Ut=5e3;function Q(e){return e.state===`queued`||e.state===`running`}function Wt(e){if(e.state===`queued`)return{title:W.t(`backup.backupRunsPanel.cancelQueuedBackupRun`,`Cancel queued backup run?`),message:W.t(`backup.backupRunsPanel.thisRunHasNotStarted`,`This run has not started. Cancelling removes it from the queue — nothing has been written, nothing is deleted.`),confirmLabel:W.t(`backup.backupRunsPanel.cancelRun`,`Cancel run`),variant:`warning`};let t=e.completedDestinationIds.length,n=t>0?`${t===1?`The 1 destination`:`The ${t} destinations`} that already completed KEEP${t===1?`S`:``} the archive.`:`No destination has completed yet, so nothing will be kept.`;return{title:W.t(`backup.backupRunsPanel.stopThisBackupRun`,`Stop this backup run?`),message:W.t(`backup.backupRunsPanel.theHalfWrittenStagingArchive`,`The half-written staging archive is deleted and the destination currently uploading discards its partial copy. {{keptSentence}}`,{keptSentence:n}),confirmLabel:W.t(`backup.backupRunsPanel.stopRun`,`Stop run`),variant:`danger`}}function Gt(){let e=H(),[t,n]=r(null),a=Ie(void 0,{refetchInterval:e=>(e.state.data??[]).some(Q)?Ht:Ut}),o=pe({onSettled:()=>{n(null),a.refetch()}}),s=i(async t=>{await e(Wt(t))&&(n(t.id),o.mutate({runId:t.id}))},[e,o]);return c(Kt,{queryState:a.isError?`error`:a.data===void 0?`pending`:`ready`,runs:a.data??[],cancelingId:t,onCancelRequest:e=>{s(e)},now:Date.now()})}function Kt({queryState:e,runs:t,cancelingId:n,onCancelRequest:r,now:i}){let{t:o}=G(),s=e===`ready`&&t.some(Q),l=t.filter(e=>e.state===`running`),u=t.filter(e=>e.state===`queued`),d=t.filter(e=>!Q(e)),f=[...l,...u,...d];return a(`section`,{className:`rounded-lg border border-border bg-surface`,children:[a(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border`,children:[c(`h2`,{className:`text-xs font-semibold text-foreground`,children:o(`backup.backupRunsPanel.runs`,`Runs`)}),s&&a(`span`,{className:`inline-flex items-center gap-1 text-[10px] font-medium text-primary`,title:o(`backup.backupRunsPanel.aBackupRunIsIn`,`A backup run is in progress`),children:[c(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary animate-pulse`}),o(`backup.runsPanel.live`)]}),c(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:o(`backup.backupRunsPanel.oneRunExecutesAtA`,`One run executes at a time — queued runs wait in line.`)})]}),e===`pending`&&c(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle animate-pulse`,children:o(`backup.backupRunsPanel.checkingForBackupRuns`,`Checking for backup runs…`)}),e===`error`&&c(`div`,{className:`px-3 py-2.5 text-xs text-danger`,children:o(`backup.backupRunsPanel.couldNotReadBackupRuns`,`Could not read backup runs — the orchestrator did not answer.`)}),e===`ready`&&t.length===0&&c(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle italic`,children:o(`backup.backupRunsPanel.noBackupRunsYetRuns`,`No backup runs yet. Runs appear here the moment one starts — manual or scheduled.`)}),e===`ready`&&t.length>0&&c(`div`,{className:`overflow-x-auto`,children:a(`table`,{className:`w-full text-xs min-w-[720px]`,children:[c(`thead`,{children:a(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.run`,`Run`)}),c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.state`,`State`)}),c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.progress`,`Progress`)}),c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.destinations`,`Destinations`)}),c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.timing`,`Timing`)}),c(`th`,{className:`text-right px-3 py-1.5 font-medium w-28`,children:o(`backup.backupRunsPanel.actions`,`Actions`)})]})}),c(`tbody`,{children:f.map(e=>c(qt,{run:e,canceling:n===e.id,onCancelRequest:r,now:i},e.id))})]})})]})}function qt({run:e,canceling:t,onCancelRequest:n,now:r}){let{t:i}=G(),o=Q(e);return a(`tr`,{className:`border-t border-border hover:bg-primary/5 align-top`,children:[a(`td`,{className:`px-3 py-2`,children:[c(`div`,{className:`text-foreground`,children:e.label??c(`span`,{className:`text-foreground-subtle italic`,children:i(`backup.runsPanel.manual`)})}),c(`div`,{className:`text-[10px] text-foreground-subtle font-mono`,title:e.id,children:e.id.slice(0,8)})]}),a(`td`,{className:`px-3 py-2`,children:[c(Jt,{run:e}),e.state===`failed`&&e.error!==void 0&&c(`div`,{className:`mt-1 text-[10px] text-danger max-w-56 truncate`,title:e.error,children:e.error})]}),c(`td`,{className:`px-3 py-2`,children:c(Yt,{run:e})}),c(`td`,{className:`px-3 py-2`,children:c(Xt,{run:e})}),c(`td`,{className:`px-3 py-2 text-foreground-subtle tabular-nums`,children:c(Zt,{run:e,now:r})}),c(`td`,{className:`px-3 py-2`,children:c(`div`,{className:`flex justify-end`,children:o&&a(`button`,{onClick:()=>n(e),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:e.state===`queued`?i(`backup.backupRunsPanel.removeThisRunFromThe`,`Remove this run from the queue before it starts`):i(`backup.backupRunsPanel.stopThisRunTheHalf`,`Stop this run — the half-written archive is discarded`),children:[t?c(T,{className:`h-3 w-3 animate-spin`}):c(_,{className:`h-3 w-3`}),e.state===`queued`?i(`common.cancel`,`Cancel`):i(`backup.backupRunsPanel.stop`,`Stop`)]})})})]})}function Jt({run:e}){let{t}=G();switch(e.state){case`queued`:return a(`span`,{className:`inline-flex items-center gap-1 rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:[c(x,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.queued`,`Queued`)]});case`running`:return a(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`,children:[c(T,{className:`h-3 w-3 animate-spin`}),e.phase===`uploading`?t(`backup.backupRunsPanel.uploading`,`Uploading`):t(`backup.backupRunsPanel.buildingArchive`,`Building archive`)]});case`succeeded`:return a(`span`,{className:`inline-flex items-center gap-1 rounded bg-success/10 px-1.5 py-0.5 text-[10px] font-medium text-success`,children:[c(E,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.succeeded`,`Succeeded`)]});case`failed`:return a(`span`,{className:`inline-flex items-center gap-1 rounded bg-danger/10 px-1.5 py-0.5 text-[10px] font-medium text-danger`,children:[c(O,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.failed`,`Failed`)]});case`cancelled`:return a(`span`,{className:`inline-flex items-center gap-1 rounded bg-amber-500/10 px-1.5 py-0.5 text-[10px] font-medium text-amber-700 dark:text-amber-300`,title:t(`backup.backupRunsPanel.stoppedBeforeCompletingEveryDestination`,`Stopped before completing every destination — not a success`),children:[c(P,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.stopped`,`Stopped`)]})}}function Yt({run:e}){let{t}=G();if(e.state===`queued`)return c(`span`,{className:`text-foreground-subtle`,children:e.queuePosition===void 0?c(`span`,{className:`italic`,children:t(`backup.backupRunsPanel.waitingItsTurn`,`waiting its turn`)}):a(`span`,{className:`inline-flex items-center gap-1`,children:[c(`span`,{className:e.queuePosition===1?`rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`:`rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium`,children:Qt(e.queuePosition)}),t(`backup.backupRunsPanel.inLine`,`in line`)]})});if(e.state===`running`&&e.phase===`building`)return a(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[c(F,{className:`h-3 w-3 text-primary`}),c(`span`,{className:`tabular-nums font-medium animate-pulse`,children:K(e.stagedBytes)}),c(`span`,{className:`text-foreground-subtle`,children:t(`backup.backupRunsPanel.stagedSoFar`,`staged so far`)})]});if(e.state===`running`){let n=e.archiveSizeBytes;return a(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[c(N,{className:`h-3 w-3 text-primary`}),a(`span`,{className:`tabular-nums font-medium`,children:[K(e.uploadedBytes),n===void 0?``:` / ${K(n)}`]}),c(`span`,{className:`text-foreground-subtle`,children:t(`backup.backupRunsPanel.toCurrentDestination`,`to current destination`)})]})}let n=e.archiveSizeBytes??(e.stagedBytes>0?e.stagedBytes:void 0);return n===void 0?c(`span`,{className:`text-foreground-subtle italic`,children:`—`}):c(`span`,{className:`tabular-nums text-foreground`,children:t(`backup.runsPanel.archiveSize`,{size:K(n)})})}function Xt({run:e}){let{t}=G(),n=e.destinationIds.length,r=e.completedDestinationIds.length,i=e.failedDestinationIds.length;return n===0?c(`span`,{className:`text-foreground-subtle italic`,children:t(`backup.backupRunsPanel.notResolvedYet`,`not resolved yet`)}):a(`div`,{className:`flex flex-col gap-0.5`,children:[c(`span`,{className:`text-foreground-subtle`,title:e.destinationIds.join(`, `),children:t(`backup.runsPanel.targets`,{count:n})}),a(`span`,{className:`inline-flex items-center gap-2 text-[10px]`,children:[r>0&&c(`span`,{className:`text-success`,title:t(`backup.backupRunsPanel.keptTheirArchive`,`Kept their archive: {{value1}}`,{value1:e.completedDestinationIds.join(`, `)}),children:t(`backup.runsPanel.completed`,{count:r})}),i>0&&c(`span`,{className:`text-danger`,title:t(`backup.backupRunsPanel.failed2`,`Failed: {{value1}}`,{value1:e.failedDestinationIds.join(`, `)}),children:t(`backup.runsPanel.failedCount`,{count:i})})]})]})}function Zt({run:e,now:t}){let{t:n}=G();return e.state===`queued`?c(`span`,{children:n(`backup.runsPanel.queuedAgo`,{elapsed:$t(t-e.requestedAt)})}):e.startedAt===void 0?c(`span`,{children:`—`}):e.finishedAt===void 0?c(`span`,{children:n(`backup.runsPanel.runningFor`,{elapsed:$t(t-e.startedAt)})}):a(`div`,{className:`flex flex-col gap-0.5`,children:[c(`span`,{children:en(e.finishedAt)}),c(`span`,{className:`text-[10px]`,children:n(`backup.runsPanel.took`,{elapsed:$t(e.finishedAt-e.startedAt)})})]})}function Qt(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 $t(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 en(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}e();var tn=[[`backup`,`list`]];function nn({initialDestinationId:e,initialArchiveId:i,onClose:o,onScheduled:l}){let{t:u}=G(),d=s(),[f,m]=r(e&&i?2:1),[h,g]=r(e),[_,v]=r(i),[b,x]=r(new Set),[S,C]=r(``),{data:w}=Oe(),E=w??[],{data:D,isLoading:O}=we({destinationId:h??``},{enabled:!!h}),A=D??[];t(()=>{if(h!==void 0)return;let e=E.filter(e=>e.restoreSupported);e.length===1&&g(e[0].id)},[h,E]);let{data:j}=Pe({destinationId:h??``,backupId:_??``},{enabled:!!h&&!!_}),M=n(()=>j?.locations??[],[j]);t(()=>{M.length!==0&&x(e=>e.size===0?new Set(M):e)},[M]);let N=Re({onSuccess:()=>{d.invalidateQueries({queryKey:tn}),l(),o()}}),P=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},F=A.find(e=>e.id===_),I=F?.encryption!==void 0,L=ft(F?.databases,j?.sqliteSnapshots),R=ut(L),te=!!h&&!!_,z=R||b.size>0,ne=te&&z&&!N.isPending&&(!I||S.trim().length>0),re=()=>{!h||!_||N.mutate({destinationId:h,backupId:_,...R?{}:{locations:[...b]},...I?{backupSecretKey:S.trim()}:{}})};return c(ue,{open:!0,onOpenChange:e=>!e&&o(),children:a(ee,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(le,{children:[c(de,{children:u(`backup.restoreWizard.restoreBackup`,`Restore Backup`)}),c(`p`,{className:`text-xs text-foreground-subtle`,children:u(`backup.restoreWizard.stepOf`,{step:f,name:f===1?u(`backup.restoreWizard.pickSource`,`pick source`):f===2?u(`backup.restoreWizard.pickLocations`,`pick locations`):u(`backup.restoreWizard.confirmStep`)})})]}),a(Te,{children:[f===1&&c(rn,{destinations:E,destinationId:h,onPickDestination:e=>{g(e),v(void 0),x(new Set)},archives:A,archivesLoading:O,archiveId:_,onPickArchive:v}),f===2&&c(an,{locations:M,picked:b,onToggle:P,databases:L,snapshotsOnly:R}),f===3&&c(on,{destinationName:E.find(e=>e.id===h)?.displayName??h??``,archive:F,picked:[...b],databases:L,snapshotsOnly:R}),f===3&&F?.encryption!==void 0&&c(sn,{keyId:F.encryption.keyId,value:S,onChange:C}),f===3&&N.error&&c(`p`,{role:`alert`,className:`px-4 pb-2 text-xs text-danger`,children:N.error.message})]}),a(se,{className:`justify-between`,children:[c(`div`,{children:f>1&&a(V,{variant:`outline`,size:`sm`,onClick:()=>m(e=>e===3?2:1),children:[c(y,{className:`h-3 w-3`}),u(`common.back`,`Back`)]})}),a(`div`,{className:`flex items-center gap-2`,children:[c(V,{variant:`outline`,size:`sm`,onClick:o,children:u(`common.cancel`,`Cancel`)}),f<3?a(V,{size:`sm`,disabled:f===1&&!te||f===2&&!z,onClick:()=>m(e=>e===1?2:3),children:[u(`common.next`,`Next`),c(p,{className:`h-3 w-3`})]}):a(V,{size:`sm`,onClick:re,disabled:!ne,children:[N.isPending?c(T,{className:`h-3.5 w-3.5 animate-spin`}):c(k,{className:`h-3.5 w-3.5`}),u(`backup.restoreWizard.scheduleRestore`,`Schedule Restore`)]})]})]})]})})}function rn({destinations:e,destinationId:t,onPickDestination:n,archives:r,archivesLoading:i,archiveId:o,onPickArchive:s}){let{t:l}=G(),u=e.filter(e=>e.restoreSupported);return a(`div`,{className:`p-4 space-y-3`,children:[a(`div`,{className:`space-y-1.5`,children:[c(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:l(`backup.restoreWizard.destination`,`Destination`)}),c(fe,{value:t??``,onChange:e=>n(e.target.value),options:[{value:``,label:l(`backup.restoreWizard.selectDestination`,`Select destination…`)},...u.map(e=>({value:e.id,label:`${e.displayName} (${e.kind})`}))]})]}),a(`div`,{className:`space-y-1.5`,children:[c(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:l(`backup.restoreWizard.archive`,`Archive`)}),!t&&c(`div`,{className:`text-xs text-foreground-subtle italic`,children:l(`backup.restoreWizard.pickADestinationFirst`,`Pick a destination first.`)}),t&&i&&c(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:l(`backup.restoreWizard.readingArchives`,`Reading archives…`)}),t&&!i&&r.length===0&&c(`div`,{className:`text-xs text-foreground-subtle italic`,children:l(`backup.restoreWizard.noArchivesAvailableAtThis`,`No archives available at this destination.`)}),t&&r.length>0&&c(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:r.map(e=>{let t=o===e.id;return a(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[a(`div`,{className:`flex items-center gap-2`,children:[c(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>s(e.id),className:`accent-primary`}),a(`div`,{children:[a(`div`,{className:`flex items-center gap-1 font-medium text-foreground`,children:[e.encryption!==void 0&&c(D,{className:`h-3 w-3 text-success`,"aria-label":l(`backup.restoreWizard.encryptedKey`,`encrypted (key {{keyId}})`,{keyId:e.encryption.keyId})}),e.label??e.id]}),c(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()}),c(`div`,{className:`pt-1`,children:c(Z,{databases:ft(e.databases,void 0)})})]})]}),c(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:K(e.sizeBytes)})]},e.id)})})]})]})}function an({locations:e,picked:t,onToggle:n,databases:r,snapshotsOnly:i}){let{t:o}=G();return i?a(`div`,{className:`space-y-3 p-4`,children:[a(`div`,{className:`space-y-1.5`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:o(`backup.restoreWizard.databasesInThisArchive`,`Databases in this archive`)}),c(Z,{databases:r})]}),c(`div`,{className:`rounded border border-info/30 bg-info/10 px-3 py-2 text-[11px] text-info`,children:o(`backup.restoreWizard.snapshotsOnlyRestoringThisArchive`,`Snapshots only: restoring this archive replaces just these databases. It does NOT touch configuration, addons, addon data or certificates.`)})]}):e.length===0?c(`div`,{className:`p-4`,children:c(`div`,{className:`text-xs text-foreground-subtle`,children:o(`backup.restoreWizard.loadingArchiveManifestIfThis`,`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`)})}):a(`div`,{className:`p-4 space-y-3`,children:[a(`div`,{className:`space-y-1.5`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:o(`backup.restoreWizard.databasesInThisArchive`,`Databases in this archive`)}),c(Z,{databases:r})]}),c(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-[11px] text-warning`,children:o(`backup.restoreWizard.selectedEntriesWillOverwriteLive`,`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`)}),a(`div`,{className:`space-y-1.5`,children:[c(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:o(`common.apply`,`Apply`)}),c(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>a(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[c(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>n(e),className:`accent-primary`}),c(`span`,{className:`font-mono text-foreground`,children:e}),c(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:ln(e)})]},e))})]})]})}function on({destinationName:e,archive:t,picked:n,databases:r,snapshotsOnly:i}){let{t:o}=G();return a(`div`,{className:`p-4 space-y-3 text-xs`,children:[c(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-warning`,children:o(`backup.restoreWizard.restoreIsAppliedAtNext`,`Restore is applied at next server boot. Active connections will drop when you restart.`)}),a(`dl`,{className:`space-y-1.5`,children:[c($,{term:`Destination`,value:e}),c($,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&c($,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${K(t.sizeBytes)}`}),c($,{term:`Databases`,value:r.map(e=>J(e)).join(`, `)}),c($,{term:`Locations`,value:i?`none (configuration is not touched)`:n.length>0?n.join(`, `):`— (full archive)`})]})]})}function sn({keyId:e,value:t,onChange:n}){let{t:r}=G();return a(`div`,{className:`space-y-1.5 px-4 pb-3`,children:[c(`label`,{htmlFor:`restore-backup-key`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:r(`backup.restoreWizard.backupKey`,`Backup key`)}),c(`input`,{id:`restore-backup-key`,type:`password`,autoComplete:`off`,spellCheck:!1,value:t,onChange:e=>n(e.target.value),placeholder:r(`backup.restoreWizard.camstackBackupSecretV1`,`camstack-backup-secret-v1:…`),className:`w-full rounded border border-border bg-background px-2 py-1.5 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),c(`p`,{className:`text-[11px] text-foreground-subtle`,children:c(ze,{i18nKey:`backup.restoreWizard.encryptedTo`,values:{keyId:e},components:{mono:c(`span`,{className:`font-mono`})}})})]})}function $({term:e,value:t}){return a(`div`,{className:`flex justify-between gap-3`,children:[c(`dt`,{className:`text-foreground-subtle`,children:e}),c(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var cn={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function ln(e){return cn[e]??``}e();function un(){let{t:e}=G(),n=H(),i=ie(),{state:o,openNew:s,openEdit:u,close:d}=L({editKey:`edit`,newKey:`new`}),f=ve(),p=f.data??[],[m,h]=r(null),[g,_]=r(!1),[v,y]=r(!1),[b,x]=r(!1),S=o.mode===`edit`?p.find(e=>e.id===o.id)??null:null;t(()=>{o.mode===`edit`&&!f.isLoading&&S===null&&d()},[o.mode,f.isLoading,S,d]);let C=o.mode===`new`||o.mode===`edit`&&S!==null,E=async()=>{await n({title:e(`system.backup.restartServerNow`,`Restart server now?`),message:e(`system.backup.activeConnectionsWillDropAnd`,`Active connections will drop and the apply-backup hook will run before boot.`),confirmLabel:e(`system.backup.restart`,`Restart`),variant:`warning`})&&i.mutate({confirm:!0})};return a(He,{embedded:!0,children:[a(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,"data-testid":`backup-actions`,children:[a(V,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>x(!0),"data-testid":`backup-now`,children:[c(l,{className:`h-3.5 w-3.5`}),e(`system.backup.backUpNow`,`Back up now`)]}),a(V,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>_(!0),children:[c(k,{className:`h-3.5 w-3.5`}),e(`system.backup.restore`,`Restore…`)]}),a(V,{size:`sm`,type:`button`,onClick:s,"data-testid":`backup-new-entry`,children:[c(w,{className:`h-3.5 w-3.5`}),e(`system.backup.newEntry`,`New entry`)]})]}),v&&c(`div`,{className:`rounded-lg border border-warning/30 bg-warning/10 px-3 py-2.5 text-xs text-warning`,children:a(`div`,{className:`flex items-center justify-between gap-3`,children:[a(`div`,{className:`flex items-center gap-2`,children:[c(k,{className:`h-3.5 w-3.5`}),c(`span`,{children:e(`system.backup.restoreScheduledRestartTheServer`,`Restore scheduled. Restart the server to apply.`)})]}),a(V,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>{E()},disabled:i.isPending,children:[i.isPending?c(T,{className:`h-3.5 w-3.5 animate-spin`}):c(k,{className:`h-3.5 w-3.5`}),e(`system.backup.restartNow`,`Restart Now`)]})]})}),c(Nt,{}),c(Gt,{}),c(yt,{onEdit:e=>u(e.id),onOpenRestoreWizard:e=>h(e)}),C&&c(Vt,{entry:S,onClose:d,onSaved:d}),b&&c(kt,{onClose:()=>x(!1)}),(m||g)&&c(nn,{...m?{initialDestinationId:m.destinationId,initialArchiveId:m.archiveId}:{},onClose:()=>{h(null),_(!1)},onScheduled:()=>y(!0)})]})}function dn(){let{t:e}=G();return a(`div`,{className:u,children:[c(`p`,{className:`mb-3 text-xs text-foreground-muted`,children:e(`systemPage.data.entriesIntro`,`Operator-created rows stored as record entry kinds. Password fields come from each kind schema.`)}),c(re,{})]})}function fn(){let{t:e}=G();return a(`div`,{className:u,children:[c(`p`,{className:`mb-3 text-xs text-foreground-muted`,children:e(`systemPage.data.recordsIntro`,`Every declared record kind on this hub. Secret fields are redacted in row previews.`)}),c(te,{})]})}function pn(){let{t:e}=G(),t=Be(`/system/data`,{t:e,isAdmin:!0})??{icon:m,title:e(`system.data`,`Data`)};return c(Ve,{icon:t.icon,title:t.title,defaultSection:`storage`,sectionsLabel:`${t.title} sections`,sections:[{id:`storage`,label:e(`systemPage.data.storage`,`Storage`),content:c(tt,{})},{id:`entries`,label:e(`systemPage.data.entries`,`Entries`),content:c(dn,{})},{id:`records`,label:e(`systemPage.data.records`,`Records`),content:c(fn,{})},{id:`backup`,label:e(`systemPage.data.backup`,`Backup`),content:c(un,{})},{id:`deleted-devices`,label:e(`systemPage.data.deletedDevices`,`Deleted devices`),content:c(et,{})}]})}export{pn as DataPage};
|