import{k as e}from"./utils-BakkG8Vx.js";import{I as t,_t as n,pt as r}from"./content_renderer-CoENEE63.js";import{n as i,s as a}from"./options-CDt8ZGCW.js";async function o(t,r,o,s){if(![`notes`,`attachments`].includes(t))throw Error(`Unrecognized import entity type '${t}'.`);if(o.length===0)return;let c=e.randomString(10),l=0;for(let e of o){l++;let u=new FormData;u.append(`upload`,e),u.append(`taskId`,c),u.append(`last`,l===o.length?`true`:`false`);for(let e in s)u.append(e,s[e]);await $.ajax({url:`${window.glob.baseApiUrl}notes/${r}/${t}-import`,headers:await i.getHeaders(),data:u,dataType:`json`,type:`POST`,timeout:3600*1e3,error:function(e){n.showError(a(`import.failed`,{message:e.responseText}))},contentType:!1,processData:!1})}}function s(e,t){return{id:e,title:a(`import.import-status`),message:t,icon:`plus`}}r.subscribeToMessages(async e=>{if(!(!(`taskType`in e)||e.taskType!==`importNotes`)){if(e.type===`taskError`)n.closePersistent(e.taskId),n.showError(e.message);else if(e.type===`taskProgressCount`)n.showPersistent(s(e.taskId,a(`import.in-progress`,{progress:e.progressCount})));else if(e.type===`taskSucceeded`){let r=s(e.taskId,a(`import.successful`));r.timeout=5e3,n.showPersistent(r),e.result.importedNoteId&&await t.tabManager.getActiveContext()?.setNote(e.result.importedNoteId)}}}),r.subscribeToMessages(async e=>{if(!(!(`taskType`in e)||e.taskType!==`importAttachments`)){if(e.type===`taskError`)n.closePersistent(e.taskId),n.showError(e.message);else if(e.type===`taskProgressCount`)n.showPersistent(s(e.taskId,a(`import.in-progress`,{progress:e.progressCount})));else if(e.type===`taskSucceeded`){let r=s(e.taskId,a(`import.successful`));r.timeout=5e3,n.showPersistent(r),e.result.parentNoteId&&await t.tabManager.getActiveContext()?.setNote(e.result.importedNoteId,{viewScope:{viewMode:`attachments`}})}}});var c={uploadFiles:o};export{o as n,c as t};