import{r as e}from"./chunk-QTnfLwEv.js";import{n as t}from"./index-7yDgay5u.js";import{i as n,o as r,t as i}from"./jsx-runtime-DHSfUA5-.js";import{P as a,R as o,s}from"./test.id-DxQrYxPk.js";import{r as c}from"./attachment-encryption-DTWbJYgF.js";import{n as l}from"./fileAssetService-gA4Q8V3n.js";import{t as u}from"./check-DqMliDjm.js";import{t as d}from"./copy-D1nqEVm3.js";import{o as f,u as p}from"./route-CPr17rXr.js";import{t as m}from"./useSuccessToast-CW8oLO3e.js";import{t as h}from"./reloadAppRoot-u7euyiyi.js";import{t as g}from"./HeaderLayoutPage-CDZOzzod.js";import{t as _}from"./useLoadingToast-BBb6RyKX.js";import{n as v,t as y}from"./FormPage-B0BqbKo9.js";var b=e(r(),1),x=i();function S(){let e=a(l),r=a(o),i=_(),S=m(),w=C(p().state),[T,E]=(0,b.useState)(!1),[D,O]=(0,b.useState)(!1),[k,A]=(0,b.useState)(!1),j=w?.uploadConfig,M=w?.recoveryKey,N=w?.channel;if(w?.mode!==`auto`||!N||!j||!M)return(0,x.jsx)(f,{to:`/`,replace:!0});let P=async()=>{try{await r.writeToClipboard(M),E(!0),S({message:t(`common.copied`,`Copied`),onDone:()=>E(!1)})}catch{E(!1)}},F=async()=>{if(k||!D)return;let t=i();A(!0);try{let t=await c(M);await e.saveSyncConfig({...j,recoveryKey:M,recoveryKeyHash:t}),h()}finally{t.dispose(),A(!1)}};return(0,x.jsx)(g,{rootClassName:n.Page.SurfaceRoot,contentClassName:n.S3SettingsPage.SetupContent,pageTestId:s.page,contentTestId:s.setupContent,header:{tone:`surface`,showBack:!0,right:{type:`steps`,total:2,current:2}},children:(0,x.jsx)(y,{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:s.keyCard,check:{label:t(`settings.sync.key.backedUp`,`I have safely backed up this recovery key`),checked:D,testId:s.backedUp,onChange:O},actions:[{label:k?t(`settings.sync.s3.testingShort`,`Connecting...`):t(`common.done`,`Done`),testId:s.primaryAction,disabled:k||!D,onClick:()=>void F()}],children:(0,x.jsx)(v,{title:t(`settings.sync.key.generated`,`New recovery key`),children:(0,x.jsxs)(`div`,{className:n.RecoveryKey.Row,"data-test-id":s.generatedKey,children:[(0,x.jsx)(`code`,{className:n.S3SettingsPage.GeneratedKeyCode,children:M}),(0,x.jsx)(`button`,{type:`button`,className:n.Button.Icon,"aria-label":t(`common.copy`,`Copy`),onClick:()=>void P(),children:T?(0,x.jsx)(u,{size:18}):(0,x.jsx)(d,{size:18})})]})})})})}function C(e){if(!e||typeof e!=`object`||Array.isArray(e))return;let t=e;if(t.mode===`auto`&&!(t.channel!==`s3`&&t.channel!==`webdav`)&&w(t.uploadConfig)&&!(typeof t.recoveryKey!=`string`||!t.recoveryKey))return{mode:`auto`,channel:t.channel,uploadConfig:t.uploadConfig,recoveryKey:t.recoveryKey}}function w(e){if(!e||typeof e!=`object`)return!1;let t=e.provider;return t===`s3`||t===`webdav`}export{S as StartupSetupKeyInitPage};
//# sourceMappingURL=init-CSbD8GzV.js.map