import{r as e}from"./chunk-QTnfLwEv.js";import{n as t}from"./index-7yDgay5u.js";import{i as n}from"./file-asset-object-store-Bvk_AjCv.js";import{i as r,o as i,t as a}from"./jsx-runtime-DHSfUA5-.js";import{P as o,R as s,s as c}from"./test.id-DxQrYxPk.js";import{r as l}from"./attachment-encryption-DTWbJYgF.js";import{t as u}from"./diaryService-CNt2_Lb5.js";import{n as d}from"./fileAssetService-gA4Q8V3n.js";import{a as f}from"./appPreferences-BKR9KWGS.js";import{o as p,u as m}from"./route-CPr17rXr.js";import{t as h}from"./reloadAppRoot-u7euyiyi.js";import{t as g}from"./HeaderLayoutPage-CDZOzzod.js";import{t as _}from"./useTopTips-B9oW_JMO.js";import{t as v}from"./useLoadingToast-BBb6RyKX.js";import{n as y,t as b}from"./FormPage-B0BqbKo9.js";import{t as x}from"./useForm-YVjhCM4e.js";var S=e(i(),1),C=a();function w(){let e=o(d),i=o(u),a=o(s),w=v(),E=_(),D=T(m().state),[O,k]=(0,S.useState)(!1),A=x({fields:[{name:`recoveryKey`,label:t(`settings.sync.key.importLabel`,`Recovery key`),testId:c.previousKeyInput,type:`password`,placeholder:`k7Qx-9mWp-...`}]}),j=D?.uploadConfig,M=D?.channel,N=A.values.recoveryKey;if(D?.mode!==`import`||!M||!j)return(0,C.jsx)(p,{to:`/`,replace:!0});let P=async()=>{let r=N.trim();if(O)return;if(!r){let e=t(`settings.sync.key.empty`,`Paste the recovery key first.`);A.setError(`recoveryKey`,e);return}A.clearErrors();let o=w();k(!0);let s=await n(j,r,a).finally(()=>{o.dispose(),k(!1)});if(!s.ok||!s.snapshot){E({message:t(`settings.sync.importFailed`,`Could not connect to the existing sync. Check the storage settings and recovery key, then try again.`),testId:c.status});return}let u=await l(r),d={...j,recoveryKey:r,recoveryKeyHash:u},p=await e.saveSyncConfig(d);if(p){let e=await f(`persistent`,p);e&&await i.initializeStorageScopeFromSnapshot(e,s.snapshot)}h()};return(0,C.jsx)(g,{rootClassName:r.Page.SurfaceRoot,contentClassName:r.S3SettingsPage.SetupContent,pageTestId:c.page,contentTestId:c.setupContent,header:{tone:`surface`,showBack:!0,right:{type:`steps`,total:2,current:2}},children:(0,C.jsx)(b,{title:t(`settings.sync.key.title`,`Set recovery key`),description:t(`settings.sync.key.desc`,`This recovery key encrypts databases and attachments synced to cloud storage. Local data is not encrypted.`),testId:c.keyCard,actions:[{label:O?t(`settings.sync.s3.testingShort`,`Connecting...`):t(`common.done`,`Done`),testId:c.primaryAction,disabled:O,onClick:()=>void P()}],children:(0,C.jsx)(y,{items:A.fields})})})}function T(e){if(!e||typeof e!=`object`||Array.isArray(e))return;let t=e;if(t.mode===`import`&&!(t.channel!==`s3`&&t.channel!==`webdav`)&&E(t.uploadConfig))return{mode:`import`,channel:t.channel,uploadConfig:t.uploadConfig}}function E(e){if(!e||typeof e!=`object`)return!1;let t=e.provider;return t===`s3`||t===`webdav`}export{w as StartupSetupKeyRestorePage};
//# sourceMappingURL=restore-C_o9aex5.js.map