/*
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, markType } from "./type";
import { List$1 } from "./List$1";
import { SectionData } from "./SectionData";
import { SectionDataStartIndexComparer } from "./SectionDataStartIndexComparer";
import { SectionDataUndisplacedStartIndexComparer } from "./SectionDataUndisplacedStartIndexComparer";
import { SectionSearchData } from "./SectionSearchData";
/**
 * @hidden
 */
var SectionMap = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(SectionMap, _super);
    function SectionMap() {
        var _this = _super.call(this) || this;
        _this.a = new SectionData();
        _this.j = new SectionDataStartIndexComparer();
        _this.k = new SectionDataUndisplacedStartIndexComparer();
        _this.s = new List$1(SectionData.$, 0);
        _this.m = new SectionSearchData();
        _this.l = new SectionSearchData();
        return _this;
    }
    Object.defineProperty(SectionMap.prototype, "t", {
        get: function () {
            return this.s;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(SectionMap.prototype, "u", {
        get: function () {
            return this.s._inner[this.s.count - 1].ad + 1;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(SectionMap.prototype, "q", {
        get: function () {
            return this.t.count > 0;
        },
        enumerable: true,
        configurable: true
    });
    SectionMap.prototype.n = function (a, b, c) {
        if (a >= 0 && a < this.s.count) {
            var d = this.s._inner[a];
            if (b >= d.af && b <= d.ad) {
                c.c++;
                if (c.c >= c.a.length) {
                    c.c = 0;
                }
                c.b[c.c] = a;
                c.a[c.c] = d;
                return true;
            }
        }
        return false;
    };
    SectionMap.prototype.o = function (a, b, c) {
        if (a >= 0 && a < this.s.count) {
            var d = this.s._inner[a];
            if (b >= d.ac && b <= d.ab) {
                c.c++;
                if (c.c >= c.a.length) {
                    c.c = 0;
                }
                c.b[c.c] = a;
                c.a[c.c] = d;
                return true;
            }
        }
        return false;
    };
    SectionMap.prototype.e = function (a) {
        return this.f(a, this.j, this.m);
    };
    SectionMap.prototype.f = function (a, b, c) {
        if (c.a == null) {
            c.a = new Array(5);
            c.b = new Array(5);
            for (var d = 0; d < c.a.length; d++) {
                c.a[d] = null;
                c.b[d] = -1;
            }
        }
        if (c.a[c.c] != null) {
            if (a >= c.a[c.c].af && a <= c.a[c.c].ad) {
                return c.a[c.c];
            }
            for (var e = 0; e < c.a.length; e++) {
                if (c.a[e] != null) {
                    if (a >= c.a[e].af && a <= c.a[e].ad) {
                        c.c = e;
                        return c.a[c.c];
                    }
                }
            }
            var f = c.b[c.c] + 1;
            if (this.n(f, a, c)) {
                return c.a[c.c];
            }
            f = c.b[c.c] - 1;
            if (this.n(f, a, c)) {
                return c.a[c.c];
            }
        }
        this.a.af = a;
        var g = this.s.g(this.a, b);
        if (g < 0) {
            g = ~g;
            g--;
        }
        if (this.n(g, a, c)) {
            return c.a[c.c];
        }
        if (this.n(g + 1, a, c)) {
            return c.a[c.c];
        }
        if (this.n(g - 1, a, c)) {
            return c.a[c.c];
        }
        return null;
    };
    SectionMap.prototype.h = function (a, b, c) {
        if (c.a == null) {
            c.a = new Array(5);
            c.b = new Array(5);
            for (var d = 0; d < c.a.length; d++) {
                c.a[d] = null;
                c.b[d] = -1;
            }
        }
        if (c.a[c.c] != null) {
            var e = c.a[c.c];
            if (a >= e.ac && a <= e.ab) {
                return e;
            }
            for (var f = 0; f < c.a.length; f++) {
                if (c.a[f] != null) {
                    if (a >= c.a[f].ac && a <= c.a[f].ab) {
                        c.c = f;
                        return c.a[c.c];
                    }
                }
            }
            var g = c.b[c.c] + 1;
            if (this.o(g, a, c)) {
                return c.a[c.c];
            }
            g = c.b[c.c] - 1;
            if (this.o(g, a, c)) {
                return c.a[c.c];
            }
        }
        this.a.af = a;
        var h = this.s.g(this.a, b);
        if (h < 0) {
            h = ~h;
            h--;
        }
        if (this.o(h, a, c)) {
            return c.a[c.c];
        }
        if (this.o(h + 1, a, c)) {
            return c.a[c.c];
        }
        if (this.o(h - 1, a, c)) {
            return c.a[c.c];
        }
        return null;
    };
    SectionMap.prototype.v = function () {
        this.s.clear();
        this.m.a = null;
        this.l.a = null;
    };
    SectionMap.prototype.ac = function (a, b, c) {
        for (var d = a.ae + 1; d < this.s.count; d++) {
            var e = this.s._inner[d];
            e.u += c;
            e.af += b;
            e.ad += b;
            for (var f = 0; f < e.h.length; f++) {
                if (e.h[f] != -1) {
                    e.h[f] += b;
                }
            }
        }
    };
    SectionMap.prototype.ab = function (a, b, c) {
        for (var d = a.ae; d < this.s.count; d++) {
            var e = this.s._inner[d];
            e.u += c;
            e.af += b;
            e.ad += b;
            e.ae = d;
            for (var f = 0; f < e.h.length; f++) {
                if (e.h[f] != -1) {
                    e.h[f] += b;
                }
            }
        }
    };
    SectionMap.prototype.x = function (a) {
        if (this.s.count == 0) {
            return;
        }
        var b = this.s._inner[this.s.count - 1];
        b.ad = a;
    };
    SectionMap.prototype.i = function (a, b, c, d, e, f) {
        var g = this.b(b, c, d, e, f);
        g.af = a;
        g.ae = this.s.count;
        if (this.s.count > 0) {
            g.u = this.s._inner[this.s.count - 1].u;
        }
        this.s.add(g);
        return g;
    };
    SectionMap.prototype.b = function (a, b, c, d, e) {
        var f = new SectionData();
        f.e = c;
        f.d = new Array(c.length);
        var g = new Array(c.length);
        for (var h = 0; h < g.length; h++) {
            f.d[h] = 0;
            g[h] = a.getItemProperty(b, c[h]);
        }
        f.f = g;
        f.ai(d, e);
        var i = d == 1 ? c.length : 1;
        f.b = new Array(i);
        f.h = new Array(i);
        f.j = new Array(i);
        for (var j = 0; j < i; j++) {
            f.h[j] = -1;
            f.j[j] = new Array(a.summaryDescriptions.k.count);
        }
        f.g = new Array(c.length);
        return f;
    };
    SectionMap.prototype.ad = function (a, b, c) {
        for (var d = a.ae + 1; d < this.s.count; d++) {
            this.s._inner[d].ae = d;
            this.s._inner[d].u += c;
            this.s._inner[d].af += b;
            this.s._inner[d].ad += b;
            for (var e = 0; e < this.s._inner[d].h.length; e++) {
                if (this.s._inner[d].h[e] != -1) {
                    this.s._inner[d].h[e] += b;
                }
            }
        }
    };
    SectionMap.prototype.aa = function (a, b) {
        this.s.insert(a, b);
    };
    SectionMap.prototype.ae = function (a) {
        if (this.m != null) {
            var b = this.m;
            SectionMap.w(a, b);
        }
        if (this.l != null) {
            var c = this.l;
            SectionMap.w(a, c);
        }
        this.s._inner[a].p = true;
        this.s.removeAt(a);
    };
    SectionMap.w = function (a, b) {
        if (b.a != null) {
            for (var c = 0; c < b.a.length; c++) {
                if (b.a[c] != null) {
                    if (b.a[c].ae == a) {
                        b.a[c] = null;
                    }
                }
            }
        }
    };
    SectionMap.prototype.d = function () {
        return this.s._inner[this.s.count - 1];
    };
    SectionMap.prototype.c = function () {
        return this.s._inner[0];
    };
    SectionMap.prototype.y = function () {
        this.s._inner[this.s.count - 1].u++;
    };
    SectionMap.prototype.g = function (a) {
        return this.h(a, this.k, this.l);
    };
    SectionMap.prototype.p = function (a) {
        for (var b = 0; b < this.t.count; b++) {
            if (b == a.ae) {
                continue;
            }
            if (this.t._inner[b].z == a.ae) {
                return true;
            }
        }
        return false;
    };
    SectionMap.prototype.z = function (a, b) {
        if (a.e == null) {
            a.d[0] += b;
            return;
        }
        if (a.z == -1) {
            for (var c = 0; c < a.e.length; c++) {
                a.d[c] += b;
            }
        }
        else {
            var d = a.x();
            for (var e = a.x(); e < a.e.length; e++) {
                a.d[e] += b;
            }
            var f = a.z;
            while (f >= 0) {
                var g = this.t._inner[f];
                var h = g.x();
                g.d[h] += b;
                f = g.z;
            }
        }
    };
    SectionMap.prototype.af = function (a, b) {
        for (var c = 0; c < a.ae; c++) {
            var d = this.s._inner[c];
            for (var e = 0; e < a.e.length; e++) {
                if (d.a[e] != null && (d.f[e] == a.f[e] || Base.equalsStatic(d.f[e], a.f[e]))) {
                    a.z = c;
                    a.a[e] = null;
                }
            }
        }
    };
    SectionMap.prototype.r = function (a) {
        var b = a.x();
        if (b == 0) {
            return true;
        }
        var c = this.s._inner[a.z];
        for (var d = b - 1; d >= 0; d--) {
            if (!c.c[d]) {
                return false;
            }
        }
        return this.r(c);
    };
    SectionMap.$t = markType(SectionMap, 'SectionMap');
    return SectionMap;
}(Base));
export { SectionMap };
//# sourceMappingURL=SectionMap.js.map
