import{r as e}from"./index-B-YXshIJ.js";const C=t=>{const r=e.useRef(t);return e.useEffect(()=>{r.current=t},[t]),r.current},g=({isOpen:t,onClosed:r,onOpenStart:o,onCloseStart:l})=>{const s=e.useRef(null),[n,i]=e.useState("closed"),f=C(t),[m,p]=e.useState(!1);e.useEffect(()=>{if(!(n==="closed"&&t))return;p(!0);const a=setTimeout(()=>{const u=s.current;u&&(u.showModal(),o(u),document.body.style.overflow="hidden",i("open"))},0);return()=>clearTimeout(a)},[n,t,o,f]);const c=e.useCallback(()=>{const a=s.current;if(!a)return;i("closing"),l(a);const u=()=>{const d=s.current;d&&(document.body.style.overflow="auto",i("closed"),d.close(),r(),d.removeEventListener("transitionend",u),p(!1))};s.current.addEventListener("transitionend",u,{once:!0})},[l,r]);e.useEffect(()=>{n==="open"&&!t&&c()},[n,t,f,c]);const b=e.useCallback(a=>{a.target===s.current&&c()},[c]),k=e.useCallback(a=>{a.preventDefault(),c()},[c]);return{dialogProps:{ref:s,onClick:b,onCancel:k},mountDialog:m}},v=t=>({...g({...t,onOpenStart:o=>{o.classList.add("backdrop:opacity-25"),o.classList.remove("backdrop:opacity-0"),t.onOpenStart(o)},onCloseStart:o=>{o.classList.add("backdrop:opacity-0"),o.classList.remove("backdrop:opacity-25"),t.onCloseStart(o)}}),dialogClassName:"backdrop:bg-theme-backdrop backdrop:opacity-0 backdrop:transition-opacity backdrop:duration-200"}),S=t=>()=>{const[r,o]=e.useState(!1),l=e.useCallback(()=>{o(!0)},[]),s=e.useCallback(()=>{o(!1)},[]),n=e.useMemo(()=>({close:s,isOpen:r,onClosed:s}),[s,r]);return[t,n,l,r,s]};export{S as c,v as u};
