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{D as a,P as o}from"./test.id-DxQrYxPk.js";import{t as s}from"./navigationService-BNBSAd9W.js";import{_ as c}from"./selectors-DZWoTA9D.js";import{t as l}from"./useDiaryModel-BQGj9xs8.js";import{t as u}from"./HeaderLayoutPage-CDZOzzod.js";import{n as d,t as f}from"./FormPage-B0BqbKo9.js";import{t as p}from"./useForm-YVjhCM4e.js";var m=e(r(),1),h=i(),g=500*1024*1024,_=`*/*`,v=[`.mdd`,`.zip`];function y(){let e=o(s),r=l(),i=(0,m.useMemo)(()=>c(r),[r]),[v,y]=(0,m.useState)(!1),S=p({initialValues:{notebookId:i[0]?.id??``},fields:[{name:`file`,label:`Zip`,type:`file`,accept:_,maxSize:g,maxSizeMessage:()=>t(`settings.import.fileTooLarge`,`Files must be {0} MB or smaller.`,g/(1024*1024)),validate:e=>{if(b(e)&&!x(e))return t(`settings.import.minimalDiary.unsupportedFile`,`Only .mdd and .zip files are supported.`)},testId:a.file,inputTestId:a.fileInput,disabled:v},{name:`notebookId`,label:t(`settings.import.targetNotebook`,`Target notebook`),type:`option`,testId:a.existingNotebook,disabled:v,options:i.map(e=>({label:e.name,value:e.id}))}]}),C=!!S.values.file&&!v,w=S.fields[0],T=S.fields[1],E=async()=>{if(v||!S.verify())return;let t=S.values.file;if(!t)return;let n=S.values.notebookId;y(!0),e.navigate({path:`/settings/import/minimal-diary/result`,replace:!0,state:{file:t,notebookId:n}})};return(0,h.jsx)(u,{rootClassName:n.Page.SurfaceRoot,contentClassName:n.WeuiForm.PageMain,pageTestId:a.page,contentTestId:a.content,header:{showBack:!0,tone:`surface`},children:(0,h.jsxs)(f,{title:t(`settings.import.minimalDiary.title`,`Import Minimal Diary`),actions:[{label:v?t(`settings.import.importing`,`Importing`):t(`settings.import.start`,`Import`),disabled:!C,testId:a.start,onClick:()=>void E()}],children:[(0,h.jsx)(d,{title:t(`settings.import.file`,`File`),items:[w]}),(0,h.jsx)(d,{title:t(`settings.import.targetNotebook`,`Target notebook`),items:[T]})]})})}function b(e){return typeof File<`u`&&e instanceof File}function x(e){let t=e.name.toLowerCase();return v.some(e=>t.endsWith(e))}export{y as SettingsImportMinimalDiaryPage};
//# sourceMappingURL=minimal-DCxffe81.js.map