import{slicedToArray as e,defineProperty as t}from"../../../_virtual/_rollupPluginBabelHelpers.js";import o,{useMemo as r,useCallback as i,cloneElement as l}from"react";import a from"react-dom";import n from"classnames";import{useA11yDialog as s}from"./a11yDialog.js";import d from"./LegacyModalContent/LegacyModalContent.js";import m from"./LegacyModalHeader/LegacyModalHeader.js";import c from"./useBodyScrollLock.js";import u from"./useShowHideModal.js";import{ModalWidth as f,validateTitleProp as p,isModalHeader as v,isModalContent as y,isModalFooter as g}from"./ModalHelper.js";import{NOOP as j}from"../../utils/function-utils.js";import{withStaticPropsWithoutForwardRef as h}from"../../types/withStaticProps.js";import"../../utils/colors-vars-map.js";import{getTestId as L}from"../../tests/testIds.js";import{ComponentDefaultTestId as M}from"../../tests/constants.js";import w from"./LegacyModal.module.scss.js";import{isClient as E}from"../../utils/ssr-utils.js";import C from"../../../components/layer/dist/LayerProvider/LayerProvider.js";var A=h((function(f){var h=f.classNames,A=void 0===h?{container:"",overlay:"",modal:""}:h,b=f.id,D=f.show,O=f.title,P=void 0===O?"":O,H=f.description,S=void 0===H?"":H,B=f.onClose,N=void 0===B?j:B,x=f.alertDialog,_=void 0!==x&&x,k=f.children,z=f.triggerElement,I=f.width,R=void 0===I?"default":I,T=f.closeButtonAriaLabel,V=void 0===T?"Close":T,Y=f.contentSpacing,$=void 0!==Y&&Y,q=f.zIndex,F=void 0===q?1e4:q,G=f.unmountOnClose,J=void 0===G||G,K=f["data-testid"],Q=r((function(){return k?o.Children.toArray(k):[]}),[k]);p(P,Q);var U=s({id:b,alertDialog:_}),W=e(U,2),X=W[0],Z=W[1],ee=i((function(){_||null==N||N()}),[_,N]);c({instance:X});var te=u({instance:X,show:D,triggerElement:z,onClose:N,alertDialog:_}).shouldShow,oe=r((function(){var e=Z.title.id,t=Q.find(v);return t?l(t,{id:e,closeModal:N}):o.createElement(m,{title:P,description:S,closeModal:N,id:e,closeButtonAriaLabel:V})}),[Z.title,Q,P,S,N,V]),re=r((function(){return Q.find(y)||o.createElement(d,null,Q.filter((function(e){return!v(e)&&!g(e)})))}),[Q]),ie=r((function(){return Q.find(g)||null}),[Q]),le="default"!==R&&"full-width"!==R,ae=o.createElement(C,{layerRef:{current:null==X?void 0:X.$el}},o.createElement("div",Object.assign({},Z.container,{className:n(w.container,A.container),"data-testid":K||L(M.MODAL,b),style:{"--monday-modal-z-index":F}}),o.createElement("div",{onClick:ee,className:n(w.overlay,A.overlay),"data-testid":M.MODAL_OVERLAY}),o.createElement("div",Object.assign({},Z.dialog,{className:n(w.dialog,A.modal,t(t(t({},w.default,"default"===R),w.full,"full-width"===R),w.spacing,$)),style:{width:le?R:null}}),oe,re,ie)));return J&&!te?null:E()?a.createPortal(ae,document.body):null}),{width:f});export{A as default};
//# sourceMappingURL=LegacyModal.js.map
