import{o as e}from"./rolldown-runtime.DAXXjFlN.js";import{r as t}from"./emotion-is-prop-valid.esm.CygBv61C.js";var n=e(t(),1);function r({isOpen:e,onClose:t,floatingSetFn:r,referenceSetFn:i,excludeSelectors:a,restoreFocusFn:o,closeOnTab:s=!1}){let c=(0,n.useRef)(null),l=(0,n.useRef)(null),u=(0,n.useRef)(a);(0,n.useEffect)(()=>{u.current=a},[a]);let d=(0,n.useCallback)(e=>{c.current=e,r(e)},[r]),f=(0,n.useCallback)(e=>{l.current=e,i?.(e)},[i]);return(0,n.useEffect)(()=>{if(!e)return;let n=e=>{let n=e.target;c.current?.contains(n)||l.current?.contains(n)||u.current?.some(e=>n.closest(e))||t()},r=e=>{let n=e.key===`Escape`,r=s&&e.key===`Tab`;!n&&!r||(n&&(e.stopPropagation(),e.preventDefault()),t(),n&&o?.())};return document.addEventListener(`pointerdown`,n,!0),document.addEventListener(`keydown`,r,!0),()=>{document.removeEventListener(`pointerdown`,n,!0),document.removeEventListener(`keydown`,r,!0)}},[e,t,s,o]),{panelRef:c,setFloatingRef:d,referenceRef:l,setReferenceRef:f}}export{r as t};