import{r as e}from"./chunk-QTnfLwEv.js";import{n as t}from"./index-7yDgay5u.js";import{o as n,t as r}from"./file-asset-object-store-Bvk_AjCv.js";import{i,o as a,t as o}from"./jsx-runtime-DHSfUA5-.js";import{s}from"./test.id-DxQrYxPk.js";import{d as c,o as l,u}from"./route-CPr17rXr.js";import{t as d}from"./HeaderLayoutPage-CDZOzzod.js";import{t as f}from"./useTopTips-B9oW_JMO.js";import{t as p}from"./useLoadingToast-BBb6RyKX.js";import{n as m,t as h}from"./FormPage-B0BqbKo9.js";import{t as g}from"./useForm-YVjhCM4e.js";var _=e(a(),1),v=o();function y(){let e=b(u().state),a=c(),o=p(),y=f(),[S,w]=(0,_.useState)(!1),T=g({initialValues:e?.uploadConfig??r(),requiredMessage:e=>t(`settings.sync.s3.required`,`{0} is required.`,e.label),fields:[{name:`endpoint`,label:`Endpoint`,testId:s.endpointInput,placeholder:`https://s3.ap-southeast-2.amazonaws.com`,required:!0},{name:`region`,label:`Region`,testId:s.regionInput,placeholder:`ap-southeast-2`,required:!0},{name:`bucket`,label:`Bucket`,testId:s.bucketInput,placeholder:`my-vault`,required:!0},{name:`accessKeyId`,label:`Access Key ID`,testId:s.accessKeyIdInput,placeholder:`AKIA...`,required:!0},{name:`secretAccessKey`,label:`Secret Access Key`,testId:s.secretAccessKeyInput,type:`password`,placeholder:`********`,required:!0},{name:`prefix`,label:`Prefix`,testId:s.prefixInput,placeholder:`chat-diary`},{name:`forcePathStyle`,label:t(`settings.sync.s3.forcePathStyle`,`Force path style`),testId:s.forcePathStyle,type:`checkbox`}]}),E=e?.mode;if(!x(E)||e?.channel!==`s3`)return(0,v.jsx)(l,{to:`/`,replace:!0});let D=async()=>{if(S||!T.verify())return;let e=o();w(!0);let r=await n(T.values).finally(()=>{e.dispose(),w(!1)});if(!r.ok){y({message:t(`settings.sync.s3.testFailed`,`Connection test failed: {0}`,r.error),testId:s.status});return}a(E===`auto`?`/startup/setup/key/init`:`/startup/setup/key/restore`,{state:{mode:E,channel:`s3`,uploadConfig:T.values,recoveryKey:E===`auto`?C():void 0}})};return(0,v.jsx)(d,{rootClassName:i.Page.SurfaceRoot,contentClassName:i.S3SettingsPage.SetupContent,pageTestId:s.page,contentTestId:s.setupContent,header:{tone:`surface`,showBack:!0,right:{type:`steps`,total:2,current:1}},children:(0,v.jsx)(h,{title:t(`settings.sync.s3.title`,`Configure S3 storage`),description:t(`settings.sync.s3.desc`,`Data is encrypted on this device before syncing to your S3 storage.`),testId:s.s3Card,actions:[{label:S?t(`settings.sync.s3.testingShort`,`Connecting...`):t(`common.next`,`Next`),testId:s.primaryAction,disabled:S,onClick:()=>void D()}],children:(0,v.jsx)(m,{title:t(`settings.sync.storage`,`Storage`),items:T.fields})})})}function b(e){if(!e||typeof e!=`object`||Array.isArray(e))return;let t=e;if(x(t.mode)&&t.channel===`s3`)return{mode:t.mode,channel:`s3`,uploadConfig:S(t.uploadConfig)?t.uploadConfig:void 0}}function x(e){return e===`auto`||e===`import`}function S(e){return!!e&&typeof e==`object`&&e.provider===`s3`}function C(){let e=new Uint8Array(16);return crypto.getRandomValues(e),Array.from(e,e=>`ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789`[e%57]).join(``).replace(/(.{4})/g,`$1-`).replace(/-$/,``)}export{y as StartupSetupSyncS3Page};
//# sourceMappingURL=s3-bj0t3qCO.js.map