import{slicedToArray as o,defineProperty as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as i,jsxs as r}from"react/jsx-runtime";import t,{useMemo as a,cloneElement as l}from"react";import d from"react-dom";import n from"classnames";import{useA11yDialog as s}from"./a11yDialog.js";import c from"../ModalContent/ModalContent.js";import m from"../ModalHeader/ModalHeader.js";import u from"./useBodyScrollLock.js";import f from"./useShowHideModal.js";import{validateTitleProp as g,isModalHeader as v,isModalContent as p,isModalFooter as h,ModalBackgroundColor as j}from"./ModalHelper.js";import{NOOP as b}from"../../utils/function-utils.js";import y from"./Modal.module.scss.js";var C=function(C){var M,H=C.classNames,N=void 0===H?{container:"",overlay:"",modal:"",header:""}:H,B=C.id,D=C.show,k=C.title,A=void 0===k?"":k,O=C.description,L=void 0===O?"":O,P=C.onClose,w=void 0===P?b:P,x=C.alertDialog,E=void 0!==x&&x,I=C.children,S=C.triggerElement,T=C.backgroundColor,W=void 0===T?"light":T,_=C.hideCloseButton,G=void 0!==_&&_,K=C.closeButtonAriaLabel,R=void 0===K?"close":K,q=C.modalWidth,z=C.modalHeight,F=C.className,J=a((function(){return I?t.Children.toArray(I):[]}),[I]);g(A,J);var Q=s({id:B,alertDialog:E}),U=o(Q,2),V=U[0],X=U[1];u({instance:V});var Y=f({instance:V,show:D,triggerElement:S,onClose:w,alertDialog:E}).closeDialogIfNeeded,Z=a((function(){var o=X.title.id,e=J.find(v);return e?l(e,{id:o,closeModal:w}):i(m,{title:A,description:L,closeModal:w,id:o,hideCloseButton:G,closeButtonAriaLabel:R})}),[X.title,J,A,L,w,G,R]),$=a((function(){return J.find(p)||i(c,{children:J.filter((function(o){return!v(o)&&!h(o)}))})}),[J]),oo=a((function(){return J.find(h)||null}),[J]),eo=d.createPortal(i("div",Object.assign({className:F},{children:r("div",Object.assign({},X.container,{className:n(y.container,N.container),"data-testid":"l3-dialog-container"},{children:[i("div",{onClick:Y,className:n(y.overlay,N.overlay),"data-testid":"l3-modal-overlay"}),i("div",Object.assign({},X.dialog,{className:n(y.dialog,N.modal,z,q,(M={},e(M,y.light,W===j.LIGHT),e(M,y.dark,W===j.DARK),e(M,"modalWidth",q),e(M,"modalHeight",z),M))},{children:r("div",Object.assign({className:F},{children:[Z,$,oo]}))}))]}))})),document.body);return d.createPortal(eo,document.body)};Object.assign(C,{backgroundColor:j});var M=C;export{M as default};
