/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import * as tslib_1 from "tslib";
import { Base, Type, typeCastObjTo$t, markType } from "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { IgnoreChildrenMarker } from "./IgnoreChildrenMarker";
/**
 * @hidden
 */
var ContextStack = /** @class */ (function (_super) {
    tslib_1.__extends(ContextStack, _super);
    function ContextStack() {
        var _this = _super.call(this) || this;
        _this.d = null;
        _this.b = false;
        _this.d = new List$1(Base.$, 0);
        return _this;
    }
    ContextStack.prototype.i = function (a) {
        while (this.e > a) {
            this.h();
        }
    };
    ContextStack.prototype.j = function (a, b) {
        while (this.e > a && this.f != b) {
            this.h();
        }
    };
    ContextStack.prototype.a = function ($t) {
        var a = $t;
        var b = a == Base.$;
        for (var c = this.d.count - 1; c >= 0; c--) {
            var d = this.d._inner[c];
            if (d == null) {
                if (b) {
                    return Type.getDefaultValue($t);
                }
                continue;
            }
            if (a.isInstanceOfType(d)) {
                return typeCastObjTo$t($t, d);
            }
        }
        return Type.getDefaultValue($t);
    };
    ContextStack.prototype.m = function (a, b) {
        var c = this.d.k(a);
        if (c < 0) {
            return;
        }
        this.d._inner[c] = b;
    };
    ContextStack.prototype.h = function () {
        var a = this.f;
        this.d.removeAt(this.d.count - 1);
        if (this.b && Base.referenceEquals(a, IgnoreChildrenMarker.a)) {
            this.b = this.a(IgnoreChildrenMarker.$) != null;
        }
        return a;
    };
    ContextStack.prototype.k = function (a) {
        this.d.add1(a);
        if (this.b == false && Base.referenceEquals(a, IgnoreChildrenMarker.a)) {
            this.b = true;
        }
    };
    ContextStack.prototype.g = function (a) {
        for (var b = this.d.count - 1; b >= 0; b--) {
            var c = this.d._inner[b];
            if (c == null) {
                continue;
            }
            if (a(c)) {
                return c;
            }
        }
        return null;
    };
    ContextStack.prototype.l = function (a) {
        if (this.d == null || this.d.count == 0) {
            return;
        }
        for (var b = this.d.count - 1; b >= 0; b -= 1) {
            var c = this.d._inner[b];
            if (Base.referenceEquals(a, c)) {
                this.d.removeAt(b);
                break;
            }
        }
    };
    Object.defineProperty(ContextStack.prototype, "e", {
        get: function () {
            return this.d.count;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ContextStack.prototype, "f", {
        get: function () {
            if (this.d.count == 0) {
                return null;
            }
            return this.d._inner[this.d.count - 1];
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ContextStack.prototype, "c", {
        get: function () {
            return this.b;
        },
        enumerable: true,
        configurable: true
    });
    ContextStack.$t = markType(ContextStack, 'ContextStack');
    return ContextStack;
}(Base));
export { ContextStack };
//# sourceMappingURL=ContextStack.js.map