"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const schematics_1 = require("@angular-devkit/schematics");
const angular_utility_1 = require("../../lib/angular-utility");
const lib_1 = require("../../lib");
const ACCEPTED_COLOR_TYPE = [
    'primary',
    'secondary',
    'tertiary',
];
function default_1(_options) {
    return schematics_1.chain([
        (tree, _context) => {
            let project = lib_1.loadProject(tree, _context);
            let appTheme = project.appConfigBuilder.appTheme;
            if (_options.theme) {
                appTheme.setTheme(_options.theme);
            }
            else {
                let color;
                for (color of ACCEPTED_COLOR_TYPE) {
                    if (_options[color]) {
                        _context.logger.info(`Setting color ${color}`);
                        appTheme.setColor(color, _options[color]);
                    }
                }
            }
            let colors = appTheme.colors;
            project.save();
            console.log('App colors: ', colors);
            let path = 'src/theme';
            return angular_utility_1.applyWithOverwriteRule(schematics_1.url('files'), [
                schematics_1.template({
                    colors: colors,
                    hex: (v) => {
                        let intC = typeof v === "string" ? parseInt(v, 16) : v;
                        return `#${intC.toString(16)}`;
                    },
                    rgb: (v) => {
                        let intC = typeof v === "string" ? parseInt(v, 16) : v;
                        return `${intC >> 16 & 0xFF}, ${intC >> 8 & 0xFF}, ${intC & 0xFF}`;
                    }
                }),
                schematics_1.move(path)
            ]);
        }
    ]);
}
exports.default = default_1;
//# sourceMappingURL=index.js.map