import{slicedToArray as e,defineProperty as t}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import o,{forwardRef as r,useRef as a,useState as s,useCallback as i,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 E from"./Modal.module.scss.js";import y from"../ModalTopActions/ModalTopActions.js";import{getStyle as b}from"../../../helpers/typesciptCssModulesHelper.js";import{camelCase as A}from"es-toolkit";import{ModalProvider as j}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 k}from"../utils/animationVariants.js";import{createPortal as C}from"react-dom";import F from"../hooks/usePortalTarget/usePortalTarget.js";import L from"../hooks/useFocusEscapeTargets/useFocusEscapeTargets.js";import{LayerProvider as g}from"@vibe/layer/mockedClassNames";import w from"../../../hooks/useMergeRef.js";var N=c.default||c,I=r((function(r,c){var I=r.id,P=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),se=a(null),ie=s(),ne=e(ie,2),le=ne[0],me=ne[1],ce=s(),de=e(ce,2),ue=de[0],fe=de[1],pe=i((function(e){ee||me(e)}),[ee]),ve=i((function(e){te||fe(e)}),[te]),Ee=n((function(){return{modalId:I,setTitleId:pe,setDescriptionId:ve,autoFocus:X}}),[I,pe,ve,X]),ye=i((function(e){P&&!q&&R(e)}),[P,q,R]),be=i((function(e){e.key===T.ESCAPE&&P&&!q&&R(e)}),[q,R,P]),Ae="full-view"===D?h:(null==Y?void 0:Y.current)?x:M,je=W?{"--monday-modal-z-index":W}:{},Te=L(K),he=i((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,P&&o.createElement(g,{layerRef:se},o.createElement(j,{value:Ee},C(o.createElement(N,{returnFocus:!0,autoFocus:X,whiteList:he},o.createElement("div",{ref:se,className:E.container,style:je},o.createElement(u.div,{variants:k,initial:"initial",animate:"enter",exit:"exit","data-testid":f(p.MODAL_NEXT_OVERLAY,I),className:E.overlay,onClick:ye,"aria-hidden":!0}),o.createElement(m,{forwardProps:!0,ref:ae},o.createElement(u.div,{variants:Ae,initial:"exit",animate:"enter",exit:"exit",custom:Y,className:l(E.modal,b(E,A("size-"+D)),t({},E.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(y,{renderAction:H,theme:_,closeButtonAriaLabel:B,onClose:R}))))),oe))))}));export{I as default};
//# sourceMappingURL=Modal.js.map
