import React, { createContext, useState } from 'react';
import { I18nextProvider } from 'react-i18next';
import { i18nInstance } from 'src/config/i18n';
export const ModalContext = createContext({});
export const ModalProvider = ({ children, openerElement, openerEvent, onClose = () => undefined, }) => {
    const [isOpen, setIsOpen] = useState(false);
    const openModal = () => {
        setIsOpen(true);
    };
    const closeModal = () => {
        onClose();
        setIsOpen(false);
    };
    const toggleModal = () => {
        setIsOpen(!isOpen);
    };
    if (openerElement && openerEvent)
        openerElement.addEventListener(openerEvent, openModal);
    return (React.createElement(ModalContext.Provider, { value: {
            isOpen,
            openModal,
            closeModal,
            toggleModal,
        } },
        React.createElement(I18nextProvider, { i18n: i18nInstance }, isOpen ? children : null)));
};
//# sourceMappingURL=Context.js.map