import * as React from "react";
import { store, createStore } from "../store";
import { Provider, createDispatchHook, createSelectorHook } from "react-redux";
import { useState, useEffect } from "react";
import { FEAGlobals } from "../../common/Globals";
import { useFloatingFocus } from "../hooks/useFloatingFocus";
export { createStore };
export const reduxContext = React.createContext(null);
/** Strongly typed version of useDispatch from react-redux.
 * https://react-redux.js.org/api/hooks#usedispatch */
export const useDispatch = createDispatchHook(reduxContext);
/** Strongly typed version of useSelector from react-redux.
 * https://react-redux.js.org/api/hooks#useselector */
export const useSelector = createSelectorHook(reduxContext);
export const FinsembleProvider = (props) => {
    const [ready, setReady] = useState(false);
    if (props.floatingFocus !== false)
        useFloatingFocus();
    useEffect(() => {
        var _a;
        if (ready)
            return;
        const release = () => {
            setReady(true);
        };
        // We need to check to make sure FSBL exists because this code may run in a preload, before
        // FSBL has been injected, in which case we need to wait on the window listener
        window.FSBL && ((_a = FEAGlobals.FSBL) === null || _a === void 0 ? void 0 : _a.addEventListener)
            ? FEAGlobals.FSBL.addEventListener("onReady", release)
            : window.addEventListener("FEAGlobals.FSBLReady", release);
    }, [ready]);
    return ready ? (React.createElement(Provider, { context: reduxContext, store: props.store || store }, props.children)) : null;
};
//# sourceMappingURL=FinsembleProvider.js.map