"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 schematics_1.chain([
        (tree, context) => {
            let project = lib_1.loadProject(tree, context);
            let page;
            const renderEngine = new app_page_render_engine_1.PageContentRenderEngine(context);
            switch (_options.type) {
                case 'AboutPage':
                    page = project.appConfigBuilder.about(_options.name);
                    project.appConfigBuilder.addMenuForPage(page);
                    break;
                case 'ProtocolConfigurationPage':
                    page = project.appConfigBuilder.protocolConfigurationPage(_options.name);
                    project.appConfigBuilder.addDefaultPageMenu(page);
                    break;
                case 'TapInfoPage':
                    page = project.appConfigBuilder.infoPage(_options.name);
                    project.appConfigBuilder.addDefaultPageMenu(page);
                    break;
                case 'TapConfigPage':
                    page = project.appConfigBuilder.tapConfigPage(_options.name);
                    project.appConfigBuilder.addDefaultPageMenu(page);
                    break;
                case 'NotFoundPage':
                    page = project.appConfigBuilder.notFoundPage(_options.name);
                    break;
                case 'TapDevicePage':
                    page = project.appConfigBuilder.tapDevicePage(_options.name);
                    break;
                case 'TapLoginPage':
                    page = project.appConfigBuilder.tapLoginPage(_options.name);
                    break;
                case 'MonitoringPage':
                    return schematics_1.schematic('page-monitoring', _options);
                case 'MonitoringDashboardPage':
                    // TODO already done by MonitoringPage...
                    // return schematic('page-monitoring', _options);
                    return;
                case 'TapConnectionPage':
                    return schematics_1.schematic('page-tap-connection', _options);
                default:
                    throw new schematics_1.SchematicsException(`Unknown page type: "${_options.type}"`);
            }
            if (page.enabled) {
                let relativePath = page.projectPath;
                const { name, path } = lib_1.getAngularProjectPath(relativePath, tree, _options);
                project.save();
                let sourceTemplates = schematics_1.url(`files/${page.type}`);
                return angular_utility_1.applyWithOverwriteRule(sourceTemplates, [
                    schematics_1.template(Object.assign(Object.assign(Object.assign({ name,
                        page }, page), project.toTemplate()), renderEngine.toTemplate(page))),
                    schematics_1.move(path)
                ], {
                    overwrite: _options.overwrite,
                    format: true
                });
            }
        },
        schematics_1.schematic('app-routing', {}),
        schematics_1.schematic('app-menu', {})
    ]);
}
exports.default = default_1;
//# sourceMappingURL=index.js.map