"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const types_1 = __importDefault(require("../types"));
const middleware_component_1 = require("../middleware/middleware-component");
const webapp_component_1 = require("../webapp/webapp-component");
const libs_1 = require("../libs");
const iso_plugin_1 = require("./iso-plugin");
const webapp_plugin_1 = require("../webapp/webapp-plugin");
const environment_plugin_1 = require("../environment/environment-plugin");
const datalayer_plugin_1 = require("../datalayer/datalayer-plugin");
const identity_plugin_1 = require("../identity/identity-plugin");
const authentication_plugin_1 = require("../authentication/authentication-plugin");
const datalayer_component_1 = require("../datalayer/datalayer-component");
const service_plugin_1 = require("../service/service-plugin");
const service_component_1 = require("../service/service-component");
exports.ISOMORPHIC_INSTANCE_TYPE = "IsomorphicComponent";
/**
 * The IsomorphicApp is an infrastructure and must implement [[IInfrastructure]]
 *
 * @param props
 */
exports.default = (props) => {
    //console.log ("isomorphic: ",props );
    const infProps = {
        // allows to identify this component as Infrastructure
        infrastructureType: types_1.default.INFRASTRUCTURE_TYPE_CONFIGURATION,
        instanceId: props.stackName,
        instanceType: exports.ISOMORPHIC_INSTANCE_TYPE,
        // only load plugins during compilation
        createPlugins: (configPath, stage, parserMode) => props.infrastructureMode === "COMPILATION" ? [
            // be able to process IsomorphicApps (as top-level-node)
            iso_plugin_1.IsoPlugin({
                parserMode: parserMode,
                buildPath: props.buildPath,
                configFilePath: configPath
            }),
            datalayer_plugin_1.DataLayerPlugin({
                buildPath: props.buildPath,
                configFilePath: configPath,
            }),
            // isomorphic apps can have webapps (i.e. clients!)
            webapp_plugin_1.WebAppPlugin({
                parserMode: parserMode,
                buildPath: props.buildPath,
                configFilePath: configPath,
                assetsPath: props.assetsPath
            }),
            service_plugin_1.ServicePlugin({}),
            // isomorphic apps can have different environments
            environment_plugin_1.EnvironmentPlugin({
                stage: stage,
                parserMode: parserMode
            }),
            identity_plugin_1.IdentityPlugin({}),
            authentication_plugin_1.AuthenticationPlugin({})
        ] : []
    };
    const isoProps = {
        middlewares: libs_1.findComponentRecursively(props.children, middleware_component_1.isMiddleware),
        webApps: libs_1.findComponentRecursively(props.children, webapp_component_1.isWebApp),
        services: libs_1.findComponentRecursively(props.children, service_component_1.isService),
        dataLayerId: libs_1.findComponentRecursively(props.children, datalayer_component_1.isDataLayer).reduce((res, dl) => res ? res : dl.id, undefined)
    };
    //console.log("webapps: ", isoProps.webApps)
    return Object.assign(props, infProps, isoProps);
};
function isIsomorphicApp(component) {
    return component !== undefined &&
        component.instanceType === exports.ISOMORPHIC_INSTANCE_TYPE;
}
exports.isIsomorphicApp = isIsomorphicApp;
//# sourceMappingURL=iso-component.js.map