import {m,l,e,f}from'./chunk-INQUC7PY.mjs';function y(t){return !t||t.length===0?"":t.map(l=>{let s=l;return s?.content?s.content.map(e=>e.content?.map(n=>n.text||"").join("")||"").join(""):""}).join(`
`)}function p(t){let l=t.getEditorRef();if(l){let e=l.getDocument();if(e?.package?.document)return e.package.document}return t.getDocument()?.package?.document??null}function O(t,l$1="AI"){function s(e){return e??l$1}return {getContentAsText(e$1){let n=p(t);return n?f(e(n,e$1)):""},getContent(e$1){let n=p(t);return n?e(n,e$1):[]},getComments(e){let n=p(t);if(!n)return [];let r=m(n,e);if(r.length>0)return r;let i=t.getComments();if(i.length===0)return [];let a=new Map,g=[];for(let o of i)if(o.parentId){let u=a.get(o.parentId);u?u.push(o):a.set(o.parentId,[o]);}else g.push(o);let m$1=[];for(let o of g){if(e?.author&&o.author!==e.author||e?.done!==void 0&&(o.done??false)!==e.done)continue;let u=a.get(o.id)??[];m$1.push({id:o.id,author:o.author,date:o.date??null,text:y(o.content),anchoredText:"",paragraphIndex:-1,replies:u.map(c=>({id:c.id,author:c.author,date:c.date??null,text:y(c.content)})),done:o.done??false});}return m$1},getChanges(e){let n=p(t);return n?l(n,e):[]},findText(e,n){return t.findInDocument(e,n)},getSelection(){return t.getSelectionInfo()},addComment(e){return t.addComment({paraId:e.paraId,text:e.text,author:s(e.author),search:e.search})},replyTo(e,n){return t.replyToComment(e,n.text,s(n.author))},resolveComment(e){t.resolveComment(e);},proposeChange(e){return t.proposeChange({paraId:e.paraId,search:e.search,replaceWith:e.replaceWith,author:s(e.author)})},applyFormatting(e){return t.applyFormatting({paraId:e.paraId,search:e.search,marks:e.marks})},setParagraphStyle(e){return t.setParagraphStyle({paraId:e.paraId,styleId:e.styleId})},insertBreak(e){return t.insertBreak({paraId:e.paraId,type:e.type})},getPage(e){return t.getPageContent(e)},getPages(e){let n=t.getTotalPages(),r=Math.max(1,Math.min(e.from,n)),i=Math.max(r,Math.min(e.to,n)),a=[];for(let g=r;g<=i;g++){let m=t.getPageContent(g);m&&a.push(m);}return a},getTotalPages(){return t.getTotalPages()},getCurrentPage(){return t.getCurrentPage()},scrollTo(e,n){return t.scrollToParaId(e,n)},onContentChange(e){return t.onContentChange(()=>{let n=p(t),r=n?m(n):[],i=n?l(n):[];try{e({commentCount:r.length,changeCount:i.length,comments:r,changes:i});}catch(a){console.error("onContentChange listener threw:",a);}})},onSelectionChange(e){return t.onSelectionChange(()=>{try{e(t.getSelectionInfo());}catch(n){console.error("onSelectionChange listener threw:",n);}})}}}export{O as a};