"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const schematics_1 = require("@angular-devkit/schematics");
const lib_1 = require("../../lib");
const angular_utility_1 = require("../../lib/angular-utility");
const app_page_render_engine_1 = require("../app-page-render-engine");
function default_1(_options) {
    return (tree, context) => {
        let project = lib_1.loadProject(tree, context);
        let tapConfig = project.tapConfig;
        let appConfig = project.appConfigSchema;
        let profileName = _options.profile || 'anonymous';
        let monitoringPage = project.appConfigBuilder.monitoringPage();
        const componentName = _options.name || `${monitoringPage.projectPath}/${profileName}-dashboard`;
        const { name, path } = lib_1.getAngularProjectPath(componentName, tree, _options);
        let dashboard = project.appConfigBuilder.getOrCreateDashboard(profileName, _options);
        let tapApiImportPath = 'tap-api';
        let sourceTemplates = schematics_1.url(app_page_render_engine_1.PageRenderEngine.getTemplatePath('MonitoringDashboardPage'));
        const renderEngine = new app_page_render_engine_1.PageContentRenderEngine(context);
        return schematics_1.chain([
            (tree, _context) => {
                lib_1.updateAppConfig(tree, data => {
                    data.app.pages = appConfig.app.pages;
                    return data;
                });
            },
            angular_utility_1.applyWithOverwriteRule(sourceTemplates, [
                schematics_1.template(Object.assign(Object.assign(Object.assign({}, tapConfig), { headerColor: 'primary', // TODO use config
                    tapApiImportPath,
                    name, appName: appConfig.app.name, context, monitoringNotRunningWarning: true, page: dashboard }), renderEngine.toTemplate(dashboard))),
                schematics_1.move(path)
            ], {
                overwrite: _options.overwrite,
                format: true
            }),
        ]);
    };
}
exports.default = default_1;
//# sourceMappingURL=index.js.map