import{hideOthers as o}from"../../../../aria-hidden/dist/es2015/index.js";import{useRef as r,useCallback as n,useState as e,useEffect as t}from"react";import{useModalManager as a,manager as i}from"./modal-manager.js";import{useIds as l}from"../../../hooks/dist/esm/use-id.js";import{mergeRefs as s}from"../../../react-utils/dist/esm/refs.js";import{callAllHandlers as d}from"../../../utils/dist/esm/function.js";function u(){return(u=Object.assign||function(o){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(o[e]=n[e])}return o}).apply(this,arguments)}function c(o){var{isOpen:t,onClose:c,id:f,closeOnOverlayClick:m=!0,closeOnEsc:v=!0,useInert:g=!0,onOverlayClick:y,onEsc:k}=o,h=r(null),b=r(null),[C,O,j]=l(f,"chakra-modal","chakra-modal--header","chakra-modal--body");p(h,t&&g),a(h,t);var D=r(null),P=n((o=>{D.current=o.target}),[]),w=n((o=>{"Escape"===o.key&&(o.stopPropagation(),v&&(null==c||c()),null==k||k())}),[v,c,k]),[M,I]=e(!1),[x,E]=e(!1),K=n((function(o,r){return void 0===o&&(o={}),void 0===r&&(r=null),u({role:"dialog"},o,{ref:s(r,h),id:C,tabIndex:-1,"aria-modal":!0,"aria-labelledby":M?O:void 0,"aria-describedby":x?j:void 0,onClick:d(o.onClick,(o=>o.stopPropagation()))})}),[j,x,C,O,M]),R=n((o=>{o.stopPropagation(),D.current===o.target&&i.isTopModal(h)&&(m&&(null==c||c()),null==y||y())}),[c,m,y]),B=n((function(o,r){return void 0===o&&(o={}),void 0===r&&(r=null),u({},o,{ref:s(r,b),onClick:d(o.onClick,R),onKeyDown:d(o.onKeyDown,w),onMouseDown:d(o.onMouseDown,P)})}),[w,P,R]);return{isOpen:t,onClose:c,headerId:O,bodyId:j,setBodyMounted:E,setHeaderMounted:I,dialogRef:h,overlayRef:b,getDialogProps:K,getDialogContainerProps:B}}function p(r,n){t((()=>{if(r.current){var e=null;return n&&r.current&&(e=o(r.current)),()=>{n&&(null==e||e())}}}),[n,r])}export{p as useAriaHidden,c as useModal};
//# sourceMappingURL=use-modal.js.map
