"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const schematics_1 = require("@angular-devkit/schematics");
const lib_1 = require("../../lib");
const core_1 = require("@angular-devkit/core");
const angular_utility_1 = require("../../lib/angular-utility");
const render_engine_1 = require("./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/definitions'; // TODO 
        let sourceTemplates = schematics_1.url('files');
        const renderEngine = new render_engine_1.RenderEngine(context);
        return schematics_1.chain([
            (tree, _context) => {
                lib_1.updateAppConfig(tree, data => {
                    data.app.pages = appConfig.app.pages;
                });
            },
            angular_utility_1.applyWithOverwriteRule(sourceTemplates, [
                schematics_1.template(Object.assign({}, tapConfig, { headerColor: 'primary', // TODO use config
                    tapApiImportPath,
                    name, appName: appConfig.app.name }, core_1.strings, { context, monitoringNotRunningWarning: true }, renderEngine.toTemplate(dashboard))),
                schematics_1.move(path)
            ], _options.overwrite),
        ]);
    };
}
exports.default = default_1;
//# sourceMappingURL=index.js.map