import{d as e,f as t,l as n,p as r,s as i,t as a}from"./hooks.module-BrXTvcfS.js";import{G as o,xt as s}from"./content_renderer-DOj8g78V.js";import{a as c,n as l}from"./PopupEditor-jIUhnaOn.js";import{t as u}from"./jsxRuntime.module-Cao1NCKs.js";import{n as d,r as f}from"./react_utils-Bz0ffU2Y.js";import{J as p,S as m,s as h}from"./hooks-ClTXKdUl.js";import{t as g}from"./Modal-hBkTa-Ee.js";import{t as _}from"./NoteDetail-k1cc0ILw.js";import{t as v}from"./note_tree-CRaGDxoW.js";e();function y(){let[e,m]=i(!1),[v,y]=i(!1),x=r(f),[S,C]=i(()=>new s(`_tree-popup`)),w=a(null);return p(`openInTreePopup`,async({noteIdOrPath:e,hoistedNoteId:t})=>{let n=new s(`_tree-popup`,t);y(Array.from(document.querySelectorAll(`.modal.show`)).some(e=>e!==w.current)),await n.setNote(e,{keepActiveDialog:!0}),n.triggerEvent=(e,t)=>x?.handleEventInChildren(e,t),C(n),m(!0)}),n(()=>{document.body.classList.toggle(`tree-popup-open`,e),document.body.classList.toggle(`tree-popup-stacked`,e&&v)},[e,v]),n(()=>{if(!e||!v)return;let t=document.querySelectorAll(`.modal-backdrop`),n=t[t.length-1];if(n)return n.classList.add(`tree-popup-backdrop`),()=>n.classList.remove(`tree-popup-backdrop`)},[e,v]),h(w,t((e,t)=>{e.split(`/`).includes(S.hoistedNoteId)?S.setNote(e,{viewScope:t,keepActiveDialog:!0}):o.triggerCommand(`openInPopup`,{noteIdOrPath:e})},[S])),u(d.Provider,{value:S,children:u(g,{modalRef:w,title:u(l,{}),hideSidebarHeader:!0,className:`tree-popup-editor-dialog`,size:`xl`,sidebar:u(b,{noteContext:S}),show:e,onShown:()=>x?.handleEvent(`focusOnDetail`,{ntxId:S.ntxId}),onHidden:()=>m(!1),scrollable:!0,stackable:!0,children:[u(c,{}),u(_,{})]})})}function b({noteContext:e}){let[t]=m(()=>new v,{noteContext:e});return u(`div`,{className:`tree-popup-sidebar`,children:t})}export{y as default};