"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var l=require("../../_virtual/jsx-runtime.js"),i=require("react"),q=require("react-dom"),R=require("../../hooks/useKeyPress.js"),h=require("../../hooks/useTrappedFocus.js"),x=require("../../utils/index.js"),j=require("./components/bottomSheetContent/index.js"),b=require("./styles.js");function P({bottomSheetRoot:f,isOpened:e,shouldCloseOnEsc:o,shouldCloseOnOverlayClick:a,onClose:d,allowBackgroundInteractions:t,bodyRef:E,...v}){const r=i.useRef(null),c=i.useRef(x.getComponentRoot(f)),m=x.getId(v.id);h.useTrappedFocus(r);const y=R.useKeyPress("Escape",c);return i.useEffect(()=>{o&&!t&&e&&y&&d()},[y]),i.useEffect(()=>{const u=n=>n.target===r.current&&d(),s=()=>{var n;return(n=r.current)==null?void 0:n.removeEventListener("click",u)};return r.current&&(a&&!t?r.current.addEventListener("click",u):s()),s},[e,a,t]),i.useEffect(()=>{var u;return e&&(document.body.style.overflow="hidden",(u=c.current)==null||u.setAttribute("aria-hidden","true")),()=>{var s;document.body.style.overflow="auto",(s=c.current)==null||s.removeAttribute("aria-hidden")}},[e]),e?q.createPortal(l.jsxRuntimeExports.jsx(b.Overlay,{ref:r,isOpened:e,allowBackgroundInteractions:t,"data-testid":`${v["data-testid"]}-bottom-sheet-overlay`,id:m("overlay"),children:l.jsxRuntimeExports.jsx(j.BottomSheetContent,{...v,bottomSheetRoot:f,isOpened:e,shouldCloseOnEsc:o&&!t,shouldCloseOnOverlayClick:a&&!t,onClose:d,bodyRef:E,id:m("content")})}),c.current):null}exports.BottomSheet=P;
