import { __assign } from "tslib";
import * as React from "react";
import { warnOnce } from "@intelligentgraphics/ig.utilities";
import { Compat } from "@intelligentgraphics/igd.productdata";
export var SessionContext = React.createContext(undefined);
SessionContext.displayName = "SessionContext";
var createSessionContext = function (contextValue) {
    if (contextValue === undefined) {
        return {
            session: Compat.session,
        };
    }
    return contextValue;
};
export var createWithSessionContext = function () { return function (component) { return function (props) {
    var contextValue = React.useContext(SessionContext);
    var sessionContext = createSessionContext(contextValue);
    if (sessionContext.session === undefined && props.session === undefined) {
        warnOnce("No session could be found. Please provide a session through either one of these methods:\n- add it directly as a prop to the target component\n- add a SessionContext.Provider above the component in the react tree\n- initialize productdata's Compat module with a session");
    }
    return React.createElement(component, __assign(__assign({}, sessionContext), props));
}; }; };
export var withSessionContext = createWithSessionContext();
export var useSessionContext = function () {
    var contextValue = React.useContext(SessionContext);
    var sessionContext = createSessionContext(contextValue);
    if (sessionContext.session === undefined) {
        warnOnce("No session could be found. Please provide a session through either one of these methods:\n- add a SessionContext.Provider above the component in the react tree\n- initialize productdata's Compat module with a session");
    }
    return sessionContext;
};
