"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const util = require("util");
const os = require("os");
const constants = require("../../constants");
const helpers_1 = require("../helpers");
class MicroTemplateService {
    constructor($injector, $testInitializationService) {
        this.$injector = $injector;
        this.$testInitializationService = $testInitializationService;
        this.dynamicCallRegex = new RegExp(util.format("(%s)", this.$injector.dynamicCallRegex.source), "g");
    }
    parseContent(data, options) {
        return __awaiter(this, void 0, void 0, function* () {
            const localVariables = this.getLocalVariables(options);
            const compiledTemplate = _.template(data.replace(this.dynamicCallRegex, "this.$injector.getDynamicCallData(\"$1\")"));
            return yield compiledTemplate.apply(this, [localVariables]);
        });
    }
    isPlatform(...args) {
        const platform = os.platform().toLowerCase();
        return _.some(args, arg => arg.toLowerCase() === platform);
    }
    getLocalVariables(options) {
        const isHtml = options.isHtml;
        const localVariables = {
            constants
        };
        localVariables["isLinux"] = isHtml || this.isPlatform("linux");
        localVariables["isWindows"] = isHtml || this.isPlatform("win32");
        localVariables["isMacOS"] = isHtml || this.isPlatform("darwin");
        localVariables["isConsole"] = !isHtml;
        localVariables["isHtml"] = isHtml;
        localVariables["formatListOfNames"] = helpers_1.formatListOfNames;
        localVariables["getUnitTestingFrameworkNames"] = this.$testInitializationService.getFrameworkNames;
        localVariables["isJekyll"] = false;
        return localVariables;
    }
}
exports.MicroTemplateService = MicroTemplateService;
$injector.register("microTemplateService", MicroTemplateService);
