import{a as e,d as t,l as n,s as r}from"./hooks.module-BrXTvcfS.js";import{H as i,_t as a,t as o}from"./content_renderer-DOj8g78V.js";import{t as s}from"./jsxRuntime.module-Cao1NCKs.js";import{n as c,t as l}from"./utils-BRIMzZXt.js";t();function u({note:t,noteIds:u,onReady:h,onProgressChanged:g}){let _=c(t,u),[v,y]=r({});return e(()=>{let e=new Set;i.getNotes(_).then(async n=>{let r=await t.getSubtreeNoteIds(!0),i=[],a=[];async function s(t,n){if(d(t)){let r=(await o.getRenderedContent(t,{trim:!1,noChildrenList:!0,expandNestedIncludes:!0,mediaEnvironment:`native`})).$renderedContent[0];f(r,t.title),p(r,n),e.add(t.noteId),a.push({note:t,contentEl:r})}else i.push(t.noteId);if(g&&g(a.length/r.length),t.hasChildren()){let e=await l(t);for(let t of e)await s(t,n+1)}}for(let e of n)await s(e,1);for(let{contentEl:t}of a)m(t,e);y({notesWithContent:a,data:{type:`collection`,ignoredNoteIds:i}})})},[_]),n(()=>{h&&v?.data&&h(v.data)},[v,h]),s(`div`,{class:`note-list list-print-view`,children:s(`div`,{class:`note-list-container use-tn-links`,children:[s(`h1`,{children:t.title}),v.notesWithContent?.map(({note:e,contentEl:t})=>s(`section`,{id:`note-${e.noteId}`,class:`note`,dangerouslySetInnerHTML:{__html:a(t.innerHTML)}}))]})})}function d(e){return!(!e.isContentAvailable()||e.type===`file`)}function f(e,t){let n=document.createElement(`h1`);n.textContent=t,e.prepend(n)}function p(e,t){let n=e.querySelectorAll(`h1, h2, h3, h4, h5, h6`);for(let e of n){let n=parseInt(e.tagName.substring(1),10),r=Math.min(n+t,6),i=document.createElement(`h${r}`);i.innerHTML=e.innerHTML,e.replaceWith(i)}}function m(e,t){let n=e.querySelectorAll(`a`);for(let e of n){let n=e.getAttribute(`href`);if(n&&n.startsWith(`#root/`)){let r=n.split(`/`).at(-1);if(r&&t.has(r))e.setAttribute(`href`,`#note-${r}`);else{let t=document.createElement(`span`);t.innerHTML=e.innerHTML,e.replaceWith(t)}}}}export{u as ListPrintView};