import{a as e,d as t,m as n,s as r}from"./hooks.module-5xe-uC6c.js";import{F as i,t as a}from"./content_renderer-CoENEE63.js";import{t as o}from"./jsxRuntime.module--xb8gfv5.js";import{n as s,t as c}from"./utils-O3ZSar8Y.js";t();function l({note:t,noteIds:l,onReady:m,onProgressChanged:h}){let g=s(t,l),[_,v]=r({});return e(()=>{let e=new Set;i.getNotes(g).then(async n=>{let r=await t.getSubtreeNoteIds(!0),i=[],o=[];async function s(t,n){if(u(t)){let r=(await a.getRenderedContent(t,{trim:!1,noChildrenList:!0})).$renderedContent[0];d(r,t.title),f(r,n),e.add(t.noteId),o.push({note:t,contentEl:r})}else i.push(t.noteId);if(h&&h(o.length/r.length),t.hasChildren()){let e=await c(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 o)p(t,e);v({notesWithContent:o,data:{type:`collection`,ignoredNoteIds:i}})})},[g]),n(()=>{m&&_?.data&&m(_.data)},[_,m]),o(`div`,{class:`note-list list-print-view`,children:o(`div`,{class:`note-list-container use-tn-links`,children:[o(`h1`,{children:t.title}),_.notesWithContent?.map(({note:e,contentEl:t})=>o(`section`,{id:`note-${e.noteId}`,class:`note`,dangerouslySetInnerHTML:{__html:t.innerHTML}}))]})})}function u(e){return!(!e.isContentAvailable()||e.type===`file`)}function d(e,t){let n=document.createElement(`h1`);n.textContent=t,e.prepend(n)}function f(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 p(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{l as ListPrintView};