"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 ACCEPTED_COLOR_TYPE = [
    'primary',
    'secondary',
    'tertiary',
    'success',
    'warning',
    'danger',
    'dark',
    'medium',
    'light'
];
function default_1(_options) {
    return schematics_1.chain([
        angular_utility_1.toPromiseRule(async (tree, _context) => {
            let project = lib_1.loadProject(tree, _context);
            let appTheme = project.appConfigBuilder.appTheme;
            if (_options.theme) {
                appTheme.initTheme(_options.theme);
            }
            else if (_options.fromImage) {
                await appTheme.fromImage(_options.fromImage);
            }
            else {
                let color;
                for (color of ACCEPTED_COLOR_TYPE) {
                    if (_options[color]) {
                        _context.logger.info(`Setting color ${color}`);
                        appTheme.setColor(color, _options[color]);
                    }
                }
            }
            project.save();
        }),
        (tree, _context) => {
            let path = 'src/theme';
            let project = lib_1.loadProject(tree, _context);
            let appTheme = project.appConfigBuilder.appTheme;
            let colors = appTheme.colors;
            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).padStart(6, "0")}`;
                    },
                    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