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