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