"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var c=require("../../_virtual/jsx-runtime.js"),i=require("react"),h=require("react-dom"),T=require("../../hooks/useKeyPress.js"),o=require("../../utils/index.js"),y=require("./styles.js");require("../IconButton/styles.js");require("../Spinner/styles.js");require("../Button/index.js");var A=require("./components/DialogContent.js"),F=require("../../hooks/useTrappedFocus.js");function H(e){return e&&e.__esModule?e:{default:e}}var K=H(h);function L({children:e,className:q,isOpen:r=!1,modalRoot:x,onClose:s=o.noop,shouldCloseOnEsc:E=!0,shouldCloseOnOverlayClick:l=!0,pinnedFooter:R=!0,size:j="medium",position:b="center",action:k,variant:f="wide",hideCloseIcon:P=!1,title:_,primaryAction:D,dismissAction:M,stackedActionButtons:w=!1,isLoading:I=!1,...n}){const t=i.useRef(null);F.useTrappedFocus(t);const v=o.getId(n["data-testid"]),m=o.getId(n["data-trackid"]),a=i.useRef(o.getComponentRoot(x)),p=T.useKeyPress("Escape",a);return i.useEffect(()=>{E&&r&&p&&s()},[p]),i.useEffect(()=>{const u=d=>d.target===t.current&&s(),g=()=>{var d;return(d=t.current)==null?void 0:d.removeEventListener("click",u)};return t.current&&(l?t.current.addEventListener("click",u):g()),g},[r,l]),i.useEffect(()=>(r&&(document.body.style.overflow="hidden",a.current&&a.current.setAttribute("aria-hidden","true")),()=>{document.body.style.overflow="auto",a.current&&a.current.removeAttribute("aria-hidden")}),[r]),r?K.default.createPortal(c.jsxRuntimeExports.jsx(y.Overlay,{className:q,ref:t,isOpen:r,"data-testid":v("overlay"),"data-trackid":m("overlay"),"aria-label":n["aria-label"],children:c.jsxRuntimeExports.jsx(y.Dialog,{onClick:u=>{u.stopPropagation(),u.nativeEvent.stopImmediatePropagation()},role:"dialog","data-testid":v("dialog-wrapper"),"data-trackid":m("dialog-wrapper"),size:j,position:b,variant:f,children:c.jsxRuntimeExports.jsx(A.DialogContent,{onClose:s,pinnedFooter:R,action:k,variant:f,hideCloseIcon:P,title:_,primaryAction:D,dismissAction:M,stackedActionButtons:w,isLoading:I,...n,children:e})})}),a.current):null}exports.Modal=L;
