"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Parser = void 0;
var Parser = /** @class */ (function () {
    function Parser(html_jsons) {
        this.HTML_TEXT = "";
        this.html_jsons = html_jsons;
    }
    Parser.prototype.parse = function () {
        /**
         * STEPS
         * 1. CREATE STARTING TAG AND SET ATTRIBUTES/STYLES TO THE TAG
         * 2. RECURSE THE FUNCTION
         * 3. CLOSE TAG
         */
        for (var _i = 0, _a = this.html_jsons; _i < _a.length; _i++) {
            var html_json = _a[_i];
            if (html_json) {
                var resultantTag = this.parseNode(html_json);
                this.HTML_TEXT += resultantTag;
            }
        }
        return this.HTML_TEXT;
    };
    Parser.prototype.parseNode = function (html_json) {
        var front_part = this.processStartTag(html_json);
        if (html_json.children && html_json.children.length > 0) {
            for (var _i = 0, _a = html_json.children; _i < _a.length; _i++) {
                var tag = _a[_i];
                front_part += this.parseNode(tag);
            }
        }
        var end_part = this.processEndTag(html_json);
        return front_part + end_part;
    };
    Parser.prototype.processStartTag = function (tag) {
        var tag_array = [];
        tag_array.push("<" + tag.tag);
        if (tag.css)
            tag_array.push("style=\"" + tag.css + "\"");
        this.checkIfTagSelfEnding(tag.tag) ? tag_array.push(" />") : tag_array.push(" >");
        tag.value ? tag_array.push(tag.value) : tag_array.push(" \n");
        return tag_array.join(" ");
    };
    Parser.prototype.processEndTag = function (tag) {
        var end_tag = "";
        if (!this.checkIfTagSelfEnding(tag.tag)) {
            end_tag = "</" + tag.tag + "> \n";
        }
        return end_tag;
    };
    Parser.prototype.checkIfTagSelfEnding = function (tag) {
        var self_ending_tags = ["img"];
        if (self_ending_tags.includes(tag))
            return true;
        else
            return false;
    };
    return Parser;
}());
exports.Parser = Parser;
//# sourceMappingURL=parser.js.map