"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MicroTemplateService = void 0;
const util = require("util");
const os = require("os");
const constants = require("../../constants");
const yok_1 = require("../yok");
const _ = require("lodash");
class MicroTemplateService {
    constructor($injector) {
        this.$injector = $injector;
        this.dynamicCallRegex = new RegExp(util.format("(%s)", this.$injector.dynamicCallRegex.source), "g");
    }
    async parseContent(data, options) {
        const localVariables = this.getLocalVariables(options);
        const compiledTemplate = _.template(data.replace(this.dynamicCallRegex, 'this.$injector.getDynamicCallData("$1")'));
        return await 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["isJekyll"] = false;
        return localVariables;
    }
}
exports.MicroTemplateService = MicroTemplateService;
yok_1.injector.register("microTemplateService", MicroTemplateService);
