"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
var Node_1 = require("./Node");
var Text_1 = require("./Text");
var ParentNode = /** @class */ (function (_super) {
    __extends(ParentNode, _super);
    function ParentNode() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Object.defineProperty(ParentNode.prototype, "children", {
        get: function () {
            return this.childNodes.filter(function (n) { return n.nodeType === 1; });
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ParentNode.prototype, "firstElementChild", {
        get: function () {
            var children = this.children;
            if (children.length === 0)
                return undefined;
            return children[0];
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ParentNode.prototype, "lastElementChild", {
        get: function () {
            var children = this.children;
            if (children.length === 0)
                return undefined;
            return children[children.length - 1];
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ParentNode.prototype, "childElementCount", {
        get: function () {
            return this.children.length;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ParentNode.prototype, "textContent", {
        get: function () {
            return this.childNodes.map(function (node) { return node.textContent; }).join("");
        },
        set: function (text) {
            var textNode = new Text_1.Text(text);
            textNode.parentNode = this;
            this.childNodes.splice(0, this.childNodes.length, textNode);
        },
        enumerable: true,
        configurable: true
    });
    ParentNode.prototype.getElementById = function (id) {
        var children = this.children;
        for (var i = 0; i < children.length; i++) {
            if (children[i].id === id)
                return children[i];
            var el = children[i].getElementById(id);
            if (el)
                return el;
        }
        return undefined;
    };
    ParentNode.prototype.getElementsByClassName = function (className) {
        var classList = className.split(/[ ]+/g);
        var elements = [];
        var children = this.children;
        for (var i = 0; i < children.length; i++) {
            var childClassList = children[i].className.split(/[ ]+/g);
            a: {
                for (var i_1 = 0; i_1 < classList.length; i_1++) {
                    if (childClassList.indexOf(classList[i_1]) === -1)
                        break a;
                }
                elements.push(children[i]);
            }
            elements = elements.concat(children[i].getElementsByClassName(className));
        }
        return elements;
    };
    ParentNode.prototype.getElementsByTagName = function (tagName) {
        var elements = [];
        var children = this.children;
        for (var i = 0; i < children.length; i++) {
            if (tagName === '*' || children[i].tagName === tagName) {
                elements.push(children[i]);
            }
            elements = elements.concat(children[i].getElementsByTagName(tagName));
        }
        return elements;
    };
    return ParentNode;
}(Node_1.Node));
exports.ParentNode = ParentNode;
//# sourceMappingURL=ParentNode.js.map