"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var ig_utilities_1 = require("@intelligentgraphics/ig.utilities");
var igd_productdata_1 = require("@intelligentgraphics/igd.productdata");
exports.SessionContext = React.createContext(undefined);
exports.SessionContext.displayName = "SessionContext";
var createSessionContext = function (contextValue) {
    if (contextValue === undefined) {
        return {
            session: igd_productdata_1.Compat.session,
        };
    }
    return contextValue;
};
exports.createWithSessionContext = function () { return function (component) { return function (props) {
    var contextValue = React.useContext(exports.SessionContext);
    var sessionContext = createSessionContext(contextValue);
    if (sessionContext.session === undefined && props.session === undefined) {
        ig_utilities_1.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, tslib_1.__assign(tslib_1.__assign({}, sessionContext), props));
}; }; };
exports.withSessionContext = exports.createWithSessionContext();
exports.useSessionContext = function () {
    var contextValue = React.useContext(exports.SessionContext);
    var sessionContext = createSessionContext(contextValue);
    if (sessionContext.session === undefined) {
        ig_utilities_1.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;
};
