"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const iso_libs_1 = require("../libs/iso-libs");
// this must be imported to allow async-functions within an AWS lambda environment
// see: https://github.com/babel/babel/issues/5085
require("@babel/polyfill");
const react_dom_1 = require("react-dom");
const routed_app_1 = require("./routed-app");
const types_1 = __importDefault(require("../types"));
const loader_1 = require("../libs/loader");
const datalayer_integration_1 = require("./datalayer-integration");
/**
 *
 * this module must not import anything that does not exist in web-mode, e.g. fs
 *
 * Creates the main Client WebApp. The `./src/client/index.tsx` module exports the result of calling this function
 * This serves as Entry-Point specified in the [[webpackConfigClient]]
 *
 * This function takes the data that is generated from the server endpoint
 */
const createClientWebApp = () => {
    var basename = iso_libs_1.getBasename(); /*
    if (typeof window != 'undefined' && window.__BASENAME__) {
        basename = window.__BASENAME__;

        // we do not delete the basename here, because we may need it at different places
        //delete window.__BASENAME__;
    }*/
    // load the IsomorphicComponent
    // we must load it directly from the module here, to enable the aliad of the config_file_path
    const isoConfig = loader_1.loadConfigurationFromModule(require('__CONFIG_FILE_PATH__'), loader_1.INFRASTRUCTURE_MODES.RUNTIME);
    // let's extract it from the root configuration
    const webApp = loader_1.extractObject(isoConfig, types_1.default.INFRASTRUCTURE_TYPE_CLIENT, __ISOMORPHIC_ID__);
    // when we have a datalayer, we can hydrate the state!
    const fHydrate = webApp.dataLayerId !== undefined ? (node) => datalayer_integration_1.hydrateFromDataLayer(node, loader_1.extractObject(isoConfig, types_1.default.INFRASTRUCTURE_TYPE_COMPONENT, webApp.dataLayerId)) : (node) => {
        console.log("this is the dummy data layer hydration");
        return node;
    };
    react_dom_1.hydrate(fHydrate(routed_app_1.createClientApp(webApp.routes, webApp.redirects, basename)), document.getElementById('root'));
};
// this module MUST NOT export anything else. Because it would also load the default, which would be executed right away
exports.default = createClientWebApp();
//# sourceMappingURL=client.js.map