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