import { __awaiter } from "tslib";
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
import * as React from "react";
const globalListeners = new Set();
export const FormSubmitHookContext = React.createContext({
    listeners: globalListeners,
    addListener: (listener) => globalListeners.add(listener),
    removeListener: (listener) => globalListeners.delete(listener),
    triggerSubmitHooks: (row) => __awaiter(void 0, void 0, void 0, function* () { return Promise.all([...globalListeners.values()].map((listener) => listener(row))); }),
});
export const FormSubmitHookProvider = (props) => {
    const listeners = React.useMemo(() => new Set(), []);
    const contextValue = React.useMemo(() => ({
        listeners,
        addListener: (listener) => listeners.add(listener),
        removeListener: (listener) => listeners.delete(listener),
        triggerSubmitHooks: (row) => __awaiter(void 0, void 0, void 0, function* () { return Promise.all([...listeners.values()].map((listener) => listener(row))); }),
    }), [listeners]);
    return (_jsx(FormSubmitHookContext.Provider, Object.assign({ value: contextValue }, { children: props.children })));
};
//# sourceMappingURL=FormSubmitHook.js.map