"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const React = __importStar(require("react"));
// create empty context as default
const RequestContext = React.createContext({});
/**
 * This HOC attaches the req sent to the server down to the Components - on server side only, of course!
 *
 * see hocs with context: https://itnext.io/combining-hocs-with-the-new-reacts-context-api-9d3617dccf0b
 *
 * When using the req: either check whether it is undefined or whether we run on the server -->
 * how to check whether running on server or in browser: https://www.npmjs.com/package/exenv
 */
const AttachRequest = (props) => {
    //console.log("attached request: " , props.request);
    return React.createElement(RequestContext.Provider, { value: props.request }, props.children);
};
/**
 * Pass the information on whether the user `isLoggedIn` as prop to the component
 * @param Component
 * @returns {function(any): any}
 */
function withRequest(Component) {
    return function WrapperComponent(props) {
        return (React.createElement(RequestContext.Consumer, null, value => {
            //console.log("with request: ", value);
            return React.createElement(Component, Object.assign({}, props, { request: value }));
        }));
    };
}
exports.withRequest = withRequest;
exports.default = AttachRequest;
//# sourceMappingURL=attach-request.js.map