import{slicedToArray as e,defineProperty as t}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import o,{forwardRef as r,useRef as a,useState as i,useCallback as s,useMemo as n}from"react";import l from"classnames";import{RemoveScroll as m}from"react-remove-scroll";import c from"react-focus-lock";import{AnimatePresence as d,motion as u}from"framer-motion";import{getTestId as f}from"../../../tests/testIds.js";import{ComponentDefaultTestId as p,ComponentVibeId as v}from"../../../tests/constants.js";import y from"./Modal.module.scss.js";import E from"../ModalTopActions/ModalTopActions.js";import{getStyle as b}from"../../../helpers/typesciptCssModulesHelper.js";import{camelCase as j}from"es-toolkit";import{ModalProvider as A}from"../context/ModalContext.js";import{keyCodes as T}from"../../../constants/keyCodes.js";import"../../../constants/sizes.js";import{modalAnimationFullViewVariants as h,modalAnimationAnchorPopVariants as x,modalAnimationCenterPopVariants as M,modalAnimationOverlayVariants as L}from"../utils/animationVariants.js";import{createPortal as k}from"react-dom";import F from"../hooks/usePortalTarget/usePortalTarget.js";import P from"../hooks/useFocusEscapeTargets/useFocusEscapeTargets.js";import g from"../../LayerProvider/LayerProvider.js";import w from"../../../hooks/useMergeRef.js";var C=c.default||c,I=r((function(r,c){var I=r.id,N=r.show,z=r.size,D=void 0===z?"medium":z,H=r.renderHeaderAction,_=r.closeButtonTheme,B=r.closeButtonAriaLabel,O=r.onClose,R=void 0===O?function(){}:O,V=r.autoFocus,X=void 0===V||V,K=r.allowFocusEscapeTo,S=r.onFocusAttempt,Y=r.anchorElementRef,q=r.alertModal,G=r.container,J=void 0===G?document.body:G,Q=r.children,U=r.style,W=r.zIndex,Z=r.className,$=r["data-testid"],ee=r["aria-labelledby"],te=r["aria-describedby"],oe=F(J),re=a(null),ae=w(c,re),ie=a(null),se=i(),ne=e(se,2),le=ne[0],me=ne[1],ce=i(),de=e(ce,2),ue=de[0],fe=de[1],pe=s((function(e){ee||me(e)}),[ee]),ve=s((function(e){te||fe(e)}),[te]),ye=n((function(){return{modalId:I,setTitleId:pe,setDescriptionId:ve,autoFocus:X}}),[I,pe,ve,X]),Ee=s((function(e){N&&!q&&R(e)}),[N,q,R]),be=s((function(e){e.key===T.ESCAPE&&N&&!q&&R(e)}),[q,R,N]),je="full-view"===D?h:(null==Y?void 0:Y.current)?x:M,Ae=W?{"--monday-modal-z-index":W}:{},Te=P(K),he=s((function(e){if(S){var t=S(e);return!0===t||t instanceof HTMLElement&&(t.focus(),!1)}return!Te(e)}),[S,Te]);return o.createElement(d,null,N&&o.createElement(g,{layerRef:ie},o.createElement(A,{value:ye},k(o.createElement(C,{returnFocus:!0,autoFocus:X,whiteList:he},o.createElement("div",{ref:ie,className:y.container,style:Ae},o.createElement(u.div,{variants:L,initial:"initial",animate:"enter",exit:"exit","data-testid":f(p.MODAL_NEXT_OVERLAY,I),className:y.overlay,onClick:Ee,"aria-hidden":!0}),o.createElement(m,{forwardProps:!0,ref:ae},o.createElement(u.div,{variants:je,initial:"exit",animate:"enter",exit:"exit",custom:Y,className:l(y.modal,b(y,j("size-"+D)),t({},y.withHeaderAction,!!H),Z),id:I,"data-testid":$||f(p.MODAL_NEXT,I),"data-vibe":v.MODAL,role:"dialog","aria-modal":!0,"aria-labelledby":ee||le,"aria-describedby":te||ue,style:U,onKeyDown:be,tabIndex:-1},Q,o.createElement(E,{renderAction:H,theme:_,closeButtonAriaLabel:B,onClose:R}))))),oe))))}));export{I as default};
//# sourceMappingURL=Modal.js.map
