import React, { useEffect } from "react";
export const coordsAreInside = ({ clientX, clientY }, { left, top, right, bottom }) => {
    if (clientX < left || clientY < top)
        return false;
    if (clientX > right || clientY > bottom)
        return false;
    return true;
};
export function getCloseHandler(modalRef, header, onBeforeClose) {
    if (header && header.closeButton === false)
        return undefined;
    if (onBeforeClose) {
        return () => { var _a; return onBeforeClose() !== false && ((_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.close()); };
    }
    return () => { var _a; return (_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.close(); };
}
function useIsModalOpen(modalRef) {
    const [isOpen, setIsOpen] = React.useState(false);
    useEffect(() => {
        if (!modalRef) {
            return;
        }
        setIsOpen(modalRef.open); // eslint-disable-line react-hooks/set-state-in-effect
        const observer = new MutationObserver(() => {
            setIsOpen(modalRef.open);
        });
        observer.observe(modalRef, {
            attributes: true,
            attributeFilter: ["open"],
        });
        return () => {
            observer.disconnect();
        };
    }, [modalRef]);
    return isOpen;
}
export { useIsModalOpen };
//# sourceMappingURL=ModalUtils.js.map