import s,{useRef as a,useMemo as m}from"react";import{Hidden as M,Features as d}from'../internal/hidden.js';import{useEvent as H}from'./use-event.js';import{useOwnerDocument as E}from'./use-owner.js';function j({defaultContainers:t=[],portals:r,mainTreeNodeRef:u}={}){var c;let o=a((c=u==null?void 0:u.current)!=null?c:null),l=E(o),f=H(()=>{var i;let n=[];for(let e of t)e!==null&&(e instanceof HTMLElement?n.push(e):"current"in e&&e.current instanceof HTMLElement&&n.push(e.current));if(r!=null&&r.current)for(let e of r.current)n.push(e);for(let e of(i=l==null?void 0:l.querySelectorAll("html > *, body > *"))!=null?i:[])e!==document.body&&e!==document.head&&e instanceof HTMLElement&&e.id!=="headlessui-portal-root"&&(e.contains(o.current)||n.some(T=>e.contains(T))||n.push(e));return n});return{resolveContainers:f,contains:H(n=>f().some(i=>i.contains(n))),mainTreeNodeRef:o,MainTreeNode:m(()=>function(){return u!=null?null:s.createElement(M,{features:d.Hidden,ref:o})},[o,u])}}function y(){let t=a(null);return{mainTreeNodeRef:t,MainTreeNode:m(()=>function(){return s.createElement(M,{features:d.Hidden,ref:t})},[t])}}export{y as useMainTreeNode,j as useRootContainers};
