import{r as e}from"./chunk-QTnfLwEv.js";import{n as t}from"./index-7yDgay5u.js";import{n,o as r}from"./file-asset-object-store-Bvk_AjCv.js";import{i,o as a,t as o}from"./jsx-runtime-DHSfUA5-.js";import{P as s,R as c,s as l}from"./test.id-DxQrYxPk.js";import{d as u,o as d,u as f}from"./route-CPr17rXr.js";import{t as p}from"./HeaderLayoutPage-CDZOzzod.js";import{t as m}from"./useTopTips-B9oW_JMO.js";import{t as h}from"./useLoadingToast-BBb6RyKX.js";import{n as g,t as _}from"./FormPage-B0BqbKo9.js";import{t as v}from"./useForm-YVjhCM4e.js";var y=e(a(),1),b=o();function x(){let e=S(f().state),a=u(),o=h(),x=m(),w=s(c),[E,D]=(0,y.useState)(!1),O=v({initialValues:e?.uploadConfig??n(),requiredMessage:e=>t(`settings.sync.s3.required`,`{0} is required.`,e.label),fields:[{name:`url`,label:`WebDAV URL`,testId:l.webdavUrlInput,placeholder:`https://dav.example.com/dav/files/me`,required:!0},{name:`username`,label:`Username`,testId:l.webdavUsernameInput,placeholder:`username`},{name:`password`,label:t(`settings.sync.webdav.password`,`Password or app password`),testId:l.webdavPasswordInput,type:`password`,placeholder:`********`},{name:`prefix`,label:`Prefix`,testId:l.webdavPrefixInput,placeholder:`chat-diary`}]}),k=e?.mode;if(!C(k)||e?.channel!==`webdav`)return(0,b.jsx)(d,{to:`/`,replace:!0});let A=async()=>{if(E||!O.verify())return;let e=o();D(!0);let n=await r(O.values,w).finally(()=>{e.dispose(),D(!1)});if(!n.ok){x({message:t(`settings.sync.s3.testFailed`,`Connection test failed: {0}`,n.error),testId:l.status});return}a(k===`auto`?`/startup/setup/key/init`:`/startup/setup/key/restore`,{state:{mode:k,channel:`webdav`,uploadConfig:O.values,recoveryKey:k===`auto`?T():void 0}})};return(0,b.jsx)(p,{rootClassName:i.Page.SurfaceRoot,contentClassName:i.S3SettingsPage.SetupContent,pageTestId:l.page,contentTestId:l.setupContent,header:{tone:`surface`,showBack:!0,right:{type:`steps`,total:2,current:1}},children:(0,b.jsx)(_,{title:t(`settings.sync.webdav.title`,`Configure WebDAV storage`),description:t(`settings.sync.webdav.desc`,`Data is encrypted on this device before syncing to your WebDAV storage.`),testId:l.webdavCard,actions:[{label:E?t(`settings.sync.s3.testingShort`,`Connecting...`):t(`common.next`,`Next`),testId:l.primaryAction,disabled:E,onClick:()=>void A()}],children:(0,b.jsx)(g,{title:t(`settings.sync.storage`,`Storage`),items:O.fields})})})}function S(e){if(!e||typeof e!=`object`||Array.isArray(e))return;let t=e;if(C(t.mode)&&t.channel===`webdav`)return{mode:t.mode,channel:`webdav`,uploadConfig:w(t.uploadConfig)?t.uploadConfig:void 0}}function C(e){return e===`auto`||e===`import`}function w(e){return!!e&&typeof e==`object`&&e.provider===`webdav`}function T(){let e=new Uint8Array(16);return crypto.getRandomValues(e),Array.from(e,e=>`ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789`[e%57]).join(``).replace(/(.{4})/g,`$1-`).replace(/-$/,``)}export{x as StartupSetupSyncWebdavPage};
//# sourceMappingURL=webdav-Di8KH0kQ.js.map