/*
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 { __extends } 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 */ (function (_super) {
    __extends(SectionMap, _super);
    function SectionMap() {
        var _this = _super.call(this) || this;
        _this.a = new SectionData();
        _this.h = new SectionDataStartIndexComparer();
        _this.i = new SectionDataUndisplacedStartIndexComparer();
        _this.o = new List$1(SectionData.$, 0);
        _this.k = new SectionSearchData();
        _this.j = new SectionSearchData();
        return _this;
    }
    Object.defineProperty(SectionMap.prototype, "p", {
        get: function () {
            return this.o;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(SectionMap.prototype, "q", {
        get: function () {
            return this.o._inner[this.o.count - 1].l + 1;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(SectionMap.prototype, "n", {
        get: function () {
            return this.p.count > 0;
        },
        enumerable: true,
        configurable: true
    });
    SectionMap.prototype.l = function (a, b, c) {
        if (a >= 0 && a < this.o.count) {
            var d = this.o._inner[a];
            if (b >= d.n && b <= d.l) {
                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.m = function (a, b, c) {
        if (a >= 0 && a < this.o.count) {
            var d = this.o._inner[a];
            if (b >= d.j && b <= d.i) {
                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.d = function (a) {
        return this.e(a, this.h, this.k);
    };
    SectionMap.prototype.e = 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].n && a <= c.a[c.c].l) {
                return c.a[c.c];
            }
            for (var e = 0; e < c.a.length; e++) {
                if (c.a[e] != null) {
                    if (a >= c.a[e].n && a <= c.a[e].l) {
                        c.c = e;
                        return c.a[c.c];
                    }
                }
            }
            var f = c.b[c.c] + 1;
            if (this.l(f, a, c)) {
                return c.a[c.c];
            }
            f = c.b[c.c] - 1;
            if (this.l(f, a, c)) {
                return c.a[c.c];
            }
        }
        this.a.n = a;
        var g = this.o.g(this.a, b);
        if (g < 0) {
            g = ~g;
            g--;
        }
        if (this.l(g, a, c)) {
            return c.a[c.c];
        }
        if (this.l(g + 1, a, c)) {
            return c.a[c.c];
        }
        if (this.l(g - 1, a, c)) {
            return c.a[c.c];
        }
        return null;
    };
    SectionMap.prototype.g = 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.j && a <= e.i) {
                return e;
            }
            for (var f = 0; f < c.a.length; f++) {
                if (c.a[f] != null) {
                    if (a >= c.a[f].j && a <= c.a[f].i) {
                        c.c = f;
                        return c.a[c.c];
                    }
                }
            }
            var g = c.b[c.c] + 1;
            if (this.m(g, a, c)) {
                return c.a[c.c];
            }
            g = c.b[c.c] - 1;
            if (this.m(g, a, c)) {
                return c.a[c.c];
            }
        }
        this.a.n = a;
        var h = this.o.g(this.a, b);
        if (h < 0) {
            h = ~h;
            h--;
        }
        if (this.m(h, a, c)) {
            return c.a[c.c];
        }
        if (this.m(h + 1, a, c)) {
            return c.a[c.c];
        }
        if (this.m(h - 1, a, c)) {
            return c.a[c.c];
        }
        return null;
    };
    SectionMap.prototype.r = function () {
        this.o.clear();
        this.k.a = null;
        this.j.a = null;
    };
    SectionMap.prototype.x = function (a, b, c) {
        for (var d = a.m + 1; d < this.o.count; d++) {
            var e = this.o._inner[d];
            e.g += c;
            e.n += b;
            e.l += b;
        }
    };
    SectionMap.prototype.w = function (a, b, c) {
        for (var d = a.m; d < this.o.count; d++) {
            var e = this.o._inner[d];
            e.g += c;
            e.n += b;
            e.l += b;
            e.m = d;
        }
    };
    SectionMap.prototype.t = function (a) {
        if (this.o.count == 0) {
            return;
        }
        var b = this.o._inner[this.o.count - 1];
        b.l = a;
    };
    SectionMap.prototype.aa = function (a, b, c, d, e, f) {
        var g = new SectionData();
        g.n = a;
        g.c = d;
        g.m = this.o.count;
        if (this.o.count > 0) {
            g.g = this.o._inner[this.o.count - 1].g;
        }
        var h = new Array(d.length);
        for (var i = 0; i < h.length; i++) {
            h[i] = b.getItemProperty(c, d[i]);
        }
        g.d = h;
        g.o(e, f);
        g.e = new Array(b.summaryDescriptions.k.count);
        this.o.add(g);
    };
    SectionMap.prototype.y = function (a, b, c) {
        for (var d = a.m + 1; d < this.o.count; d++) {
            this.o._inner[d].m = d;
            this.o._inner[d].g += c;
            this.o._inner[d].n += b;
            this.o._inner[d].l += b;
        }
    };
    SectionMap.prototype.v = function (a, b) {
        this.o.insert(a, b);
    };
    SectionMap.prototype.z = function (a) {
        if (this.k != null) {
            var b = this.k;
            SectionMap.s(a, b);
        }
        if (this.j != null) {
            var c = this.j;
            SectionMap.s(a, c);
        }
        this.o.removeAt(a);
    };
    SectionMap.s = 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].m == a) {
                        b.a[c] = null;
                    }
                }
            }
        }
    };
    SectionMap.prototype.c = function () {
        return this.o._inner[this.o.count - 1];
    };
    SectionMap.prototype.b = function () {
        return this.o._inner[0];
    };
    SectionMap.prototype.u = function () {
        this.o._inner[this.o.count - 1].g++;
    };
    SectionMap.prototype.f = function (a) {
        return this.g(a, this.i, this.j);
    };
    SectionMap.$t = markType(SectionMap, 'SectionMap');
    return SectionMap;
}(Base));
export { SectionMap };
