/*
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, String_$type, Number_$type, typeCast, Array_$type, Boolean_$type, markType } from "./type";
import { ISupportsDataChangeNotifications_$type } from "./ISupportsDataChangeNotifications";
import { List$1 } from "./List$1";
import { SectionData } from "./SectionData";
import { SectionMap } from "./SectionMap";
import { Dictionary$2 } from "./Dictionary$2";
import { DataSourceSpecialRow } from "./DataSourceSpecialRow";
import { SummaryGroup } from "./SummaryGroup";
import { RemovedShiftedRowInfo } from "./RemovedShiftedRowInfo";
import { dateNow } from "./date";
/**
 * @hidden
 */
var RearrangedListView = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(RearrangedListView, _super);
    function RearrangedListView(a) {
        var _this = _super.call(this) || this;
        _this.n = null;
        _this.a4 = null;
        _this.z = new SectionMap();
        _this.e = null;
        _this.a = null;
        _this.b = null;
        _this.c = null;
        _this.d = null;
        _this.a8 = 0;
        _this.a7 = 0;
        _this.am = false;
        _this.as = false;
        _this.o = null;
        _this.a0 = null;
        _this.az = null;
        _this.s = null;
        _this.aa = null;
        _this.ac = null;
        _this.m = null;
        _this.ae = null;
        _this.af = null;
        _this.ag = null;
        _this.ap = false;
        _this.k = 0;
        _this.j = 0;
        _this.av = false;
        _this.au = false;
        _this.aw = false;
        _this.ah = false;
        _this.a3 = new List$1(Array_$type, 0);
        _this.ay = new Dictionary$2(String_$type, Boolean_$type, 0);
        _this.n = a;
        return _this;
    }
    Object.defineProperty(RearrangedListView.prototype, "bk", {
        get: function () {
            return this.a7;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RearrangedListView.prototype, "i", {
        get: function () {
            return this.e;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RearrangedListView.prototype, "a6", {
        get: function () {
            return this.a4;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RearrangedListView.prototype, "aq", {
        get: function () {
            if (!this.m.isSectionContentVisible) {
                return true;
            }
            return this.m.isSectionCollapsable;
        },
        enumerable: true,
        configurable: true
    });
    RearrangedListView.prototype.w = function (a) {
        return this.z.e(a);
    };
    RearrangedListView.prototype.v = function () {
        return this.z.d();
    };
    Object.defineProperty(RearrangedListView.prototype, "p", {
        get: function () {
            return this.o;
        },
        set: function (a) {
            this.o = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RearrangedListView.prototype, "a2", {
        get: function () {
            return this.a0;
        },
        set: function (a) {
            this.a0 = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RearrangedListView.prototype, "a1", {
        get: function () {
            return this.az;
        },
        set: function (a) {
            this.az = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RearrangedListView.prototype, "t", {
        get: function () {
            return this.s;
        },
        set: function (a) {
            this.s = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RearrangedListView.prototype, "ab", {
        get: function () {
            return this.aa;
        },
        set: function (a) {
            this.aa = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RearrangedListView.prototype, "ad", {
        get: function () {
            return this.ac;
        },
        set: function (a) {
            this.ac = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RearrangedListView.prototype, "l", {
        get: function () {
            return this.k;
        },
        set: function (a) {
            this.k = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RearrangedListView.prototype, "ar", {
        get: function () {
            if (!this.m.isSectionContentVisible) {
                return false;
            }
            if (this.aq) {
                return this.m.isSectionExpandedDefault;
            }
            return true;
        },
        enumerable: true,
        configurable: true
    });
    RearrangedListView.prototype.b6 = function () {
        var _this = this;
        if (this.a4 == this.n || this.a4 == null) {
            this.a4 = new List$1(Base.$, 0);
        }
        this.a4.clear();
        if (!this.aq) {
            this.ay.clear();
        }
        if (this.n == null) {
            return;
        }
        var a = this.n.actualCount;
        this.a7 = 0;
        this.a8 = this.ba();
        this.br(null);
        var b = this.ag.k.count > 0 && this.l != 2 && this.l != 3;
        if (this.s == null) {
            for (var c = 0; c < a; c++) {
                var d = this.n.getItemAtIndex(c);
                this.a4.add1(d);
                if (b) {
                    this.bq(null, d);
                }
            }
        }
        else {
            for (var e = 0; e < a; e++) {
                var f = this.n.getItemAtIndex(e);
                if (this.s(f)) {
                    this.a4.add1(f);
                    if (b) {
                        this.bq(null, f);
                    }
                }
            }
        }
        this.bu(null);
        if (this.a0 != null) {
            this.a4.z(this.a0);
        }
        this.ah = false;
        this.z.v();
        if (this.ae != null && this.ae.k.count > 0) {
            this.ah = true;
            this.b1();
        }
        else {
            this.z.t.add(((function () {
                var $ret = new SectionData();
                $ret.ae = 0;
                $ret.e = null;
                $ret.f = null;
                $ret.af = 0;
                $ret.ad = _this.a4.count;
                $ret.c = new Array(0);
                $ret.d = new Array(1);
                return $ret;
            })()));
        }
        if (b) {
            this.bw(this.e);
        }
        var g = this.p;
        var h = new List$1(Base.$, 0);
        if (this.a3.count > 0 && this.aw) {
            if (!this.ah) {
                var i = this.z.t._inner[0];
                for (var j = 0; j < this.a3.count; j++) {
                    var k = this.m.indexOfKey(this.a3._inner[j]);
                    if (k != -1) {
                        this.bj(i, this.a4._inner[k], j);
                    }
                }
            }
            else {
                for (var l = 0; l < this.a3.count; l++) {
                    var m = this.m.indexOfKey(this.a3._inner[l]);
                    if (m != -1) {
                        var n = this.z.e(m);
                        this.bj(n, this.a4._inner[m], l);
                    }
                }
            }
        }
        if (this.ab != null) {
            this.ab.notifyClearItems();
        }
    };
    RearrangedListView.prototype.bl = function (a, b) {
        var c = null;
        if (a.q) {
            if (b) {
                var d = a.af + a.w() + a.ah + a.aa;
                c = this.a4._inner[d];
            }
            else {
                var e = a.ad - a.v - a.ag;
                c = this.a4._inner[e];
            }
        }
        return c;
    };
    Object.defineProperty(RearrangedListView.prototype, "a5", {
        get: function () {
            return this.z.t;
        },
        enumerable: true,
        configurable: true
    });
    RearrangedListView.prototype.b1 = function () {
        if (this.a4.count == 0) {
            return;
        }
        var a = dateNow();
        var b = this.f();
        var c = this.g();
        var d = this.j == 1 ? c.length : 1;
        if (this.b == null || this.b.length != c.length) {
            this.a = new Array(d);
            this.b = new Array(d);
        }
        this.c = new Array(d);
        for (var e = 0; e < d; e++) {
            this.c[e] = new Array(this.ag.k.count);
        }
        var f = this.l == 3 || this.l == 1;
        var g = new List$1(Base.$, 0);
        var h = null;
        var i = null;
        if (this.m.isSectionContentVisible || !this.av) {
            for (var j = 0; j < this.a4.count; j++) {
                var k = this.a4._inner[j];
                if (k == null) {
                    continue;
                }
                if (h == null) {
                    var l = this.x(j, k, c);
                    j += this.bc(l, j, b, c, true);
                    this.bs(l, true, f);
                    this.z.z(l, 1);
                    this.bq(l, k);
                    i = k;
                }
                else {
                    if (this.a1.compare(h, k) != 0) {
                        var m = this.z.t._inner[this.z.t.count - 1];
                        if (m.r) {
                            j += this.bb(j, i, b, c);
                        }
                        this.bt(j - 1, i, b);
                        var n = this.x(j, k, c);
                        this.bs(n, false, f);
                        var o = this.bc(n, j, b, c, true);
                        j += o;
                        n.r = this.z.r(n);
                        this.z.z(n, 1);
                        this.bq(n, k);
                        i = k;
                    }
                    else {
                        var p = this.z.t._inner[this.z.t.count - 1];
                        this.z.z(p, 1);
                        this.bq(p, k);
                    }
                }
                if (j == this.a4.count - 1) {
                    var q = this.z.t._inner[this.z.t.count - 1];
                    if (q.r) {
                        j += this.bb(j + 1, i, b, c);
                    }
                    this.bt(j, i, b);
                }
                h = k;
            }
            if (!f) {
                if (this.j == 1) {
                    for (var r = 0; r < c.length; r++) {
                        for (var s = 0; s < this.ag.k.count; s++) {
                            this.b[r].j[r][s] = this.c[r][s].endCalculation();
                            this.b[r].j[r][s].summaryIndex = s;
                        }
                        for (var t = 0; t < this.b[r].h.length; t++) {
                            if (this.b[r].h[t] == -1) {
                                this.b[r].h[t] = this.z.t._inner[this.z.t.count - 1].ad + 1;
                            }
                        }
                    }
                }
                else {
                    for (var u = 0; u < this.ag.k.count; u++) {
                        this.b[0].j[0][u] = this.c[0][u].endCalculation();
                        this.b[0].j[0][u].summaryIndex = u;
                    }
                    this.b[0].h[0] = this.z.t._inner[this.z.t.count - 1].ad + 1;
                }
            }
            this.bx();
            for (var v = 0; v < this.z.t.count; v++) {
                var w = this.z.t._inner[v];
                if (this.av) {
                    if (!w.r) {
                        var x = w.ad - w.af + 1;
                        this.a4.v(w.af, x);
                        this.z.ae(w.ae);
                        this.z.ab(w, -x, -x);
                        v--;
                    }
                    else if (!w.q) {
                        var y = 0;
                        for (var z = 0; z < w.c.length; z++) {
                            y = w.b[z];
                            if (!w.c[z]) {
                                break;
                            }
                        }
                        var aa = w.af + y + 1;
                        var ab = w.d[w.d.length - 1];
                        this.a4.v(aa, ab);
                        w.ad -= ab;
                        this.z.ac(w, -ab, -ab);
                    }
                }
            }
        }
        else {
            for (var ac = 0; ac < this.a4.count; ac++) {
                var ad = this.a4._inner[ac];
                if (ad == null) {
                    continue;
                }
                if (h == null) {
                    var ae = this.x(ac, ad, c);
                    this.bd(g, ae, ad, b, c, true);
                    this.bs(ae, true, f);
                    this.z.z(ae, 1);
                    this.bq(ae, ad);
                    i = ad;
                }
                else {
                    if (this.a1.compare(h, ad) != 0) {
                        var af = this.z.t._inner[this.z.t.count - 1];
                        this.bt(g.count - 1, i, b);
                        var ag = this.x(ac, ad, c);
                        this.bs(ag, false, f);
                        this.bd(g, ag, ad, b, c, true);
                        ag.r = this.z.r(ag);
                        this.z.z(ag, 1);
                        this.bq(ag, ad);
                        i = ad;
                    }
                    else {
                        var ah = this.z.t._inner[this.z.t.count - 1];
                        this.z.z(ah, 1);
                        this.bq(ah, ad);
                    }
                }
                if (ac == this.a4.count - 1) {
                    var ai = this.z.t._inner[this.z.t.count - 1];
                    this.bt(ac, i, b);
                }
                h = ad;
            }
            this.a4 = g;
        }
        for (var aj = 0; aj < this.b.length; aj++) {
            this.a[aj] = null;
            this.b[aj] = null;
        }
        this.c = null;
        var ak = dateNow();
    };
    RearrangedListView.prototype.bs = function (a, b, c) {
        if (b) {
            for (var d = 0; d < this.b.length; d++) {
                this.b[d] = a;
                if (!c) {
                    for (var e = 0; e < this.ag.k.count; e++) {
                        var f = this.ag.k.item(e);
                        this.c[d][e] = f.d();
                        this.c[d][e].beginCalculation(this.m, f.propertyName);
                    }
                }
            }
        }
        if (this.j == 1) {
            var g = false;
            var h = a.e.length;
            for (var i = 0; i < h; i++) {
                if (g) {
                    if (!c) {
                        for (var j = 0; j < this.ag.k.count; j++) {
                            this.b[i].j[i][j] = this.c[i][j].endCalculation();
                            this.b[i].j[i][j].summaryIndex = j;
                            this.c[i][j].beginCalculation(this.m, this.ag.k.item(j).propertyName);
                        }
                        this.b[i].h[i] = a.af;
                    }
                    this.b[i] = a;
                    continue;
                }
                var k = false;
                if (this.b[i].f[i] == null) {
                    k = a.f[i] != null;
                }
                else {
                    k = !Base.equalsStatic(this.b[i].f[i], a.f[i]);
                }
                if (k) {
                    if (!c) {
                        for (var l = 0; l < this.ag.k.count; l++) {
                            this.b[i].j[i][l] = this.c[i][l].endCalculation();
                            this.b[i].j[i][l].summaryIndex = l;
                            this.c[i][l].beginCalculation(this.m, this.ag.k.item(l).propertyName);
                        }
                        this.b[i].h[i] = a.af;
                    }
                    this.b[i] = a;
                    if (i - 1 > -1) {
                        var m = i - 1;
                        while (m >= 0 && this.b[m].p) {
                            m = m - 1;
                        }
                        a.z = this.b[m].ae;
                    }
                    g = true;
                }
            }
        }
        else {
            var n = false;
            for (var o = 0; o < a.e.length; o++) {
                if (this.b[0].f[o] == null) {
                    if (this.b[0].f[o] != a.f[o]) {
                        n = true;
                        break;
                    }
                    continue;
                }
                if (!Base.equalsStatic(this.b[0].f[o], a.f[o])) {
                    n = true;
                    break;
                }
            }
            if (n) {
                if (!c) {
                    for (var p = 0; p < this.ag.k.count; p++) {
                        this.b[0].j[0][p] = this.c[0][p].endCalculation();
                        this.b[0].j[0][p].summaryIndex = p;
                        this.c[0][p].beginCalculation(this.m, this.ag.k.item(p).propertyName);
                    }
                    this.b[0].h[0] = a.af;
                }
                this.b[0] = a;
            }
        }
    };
    RearrangedListView.prototype.ba = function () {
        var a = 0;
        var b = new Dictionary$2(String_$type, Number_$type, 0);
        for (var c = 0; c < this.ag.k.count; c++) {
            var d = this.ag.k.item(c).propertyName;
            if (!b.containsKey(d)) {
                b.addItem(d, 1);
            }
            else {
                b.item(d, b.item(d) + 1);
            }
            if (b.item(d) > a) {
                a = b.item(d);
            }
        }
        return a;
    };
    RearrangedListView.prototype.bd = function (a, b, c, d, e, f) {
        var g = 0;
        if (this.av) {
            if (this.m.sectionHeaderDisplayMode == 0) {
                if (this.an(a, 0, c, d, e, f)) {
                    this.z.y();
                    g++;
                    if (b != null) {
                        var h = this.bm(b);
                        b.a[0] = h;
                        b.c[0] = this.al(h);
                        b.b[0] = (a.count - 1) - b.af;
                    }
                }
            }
            else if (this.m.sectionHeaderDisplayMode == 1) {
                for (var i = 0, j = 0; i < e.length; i++) {
                    var k = a.count + j;
                    if (this.an(a, i, c, d, [e[i]], f)) {
                        g++;
                        this.z.y();
                        if (b != null) {
                            var l = this.bn(b, i);
                            b.a[i] = l;
                            b.c[i] = this.al(l);
                            b.b[i] = k - b.af;
                            if (!b.c[i]) {
                                break;
                            }
                        }
                        else if (!this.ar) {
                            break;
                        }
                        j++;
                    }
                }
            }
        }
        return g;
    };
    RearrangedListView.prototype.bc = function (a, b, c, d, e) {
        var f = 0;
        if (this.av) {
            var g = this.a4._inner[b];
            if (this.m.sectionHeaderDisplayMode == 0) {
                if (this.ao(b, 0, g, c, d, e)) {
                    this.z.y();
                    f++;
                    if (a != null) {
                        var h = this.bm(a);
                        a.a[0] = h;
                        a.c[0] = this.al(h);
                        a.b[0] = b - a.af;
                    }
                }
            }
            else if (this.m.sectionHeaderDisplayMode == 1) {
                for (var i = 0, j = 0; i < d.length; i++) {
                    var k = b + j;
                    if (this.ao(k, i, g, c, [d[i]], e)) {
                        f++;
                        this.z.y();
                        if (a != null) {
                            var l = this.bn(a, i);
                            a.a[i] = l;
                            a.c[i] = this.al(l);
                            a.b[i] = k - a.af;
                            if (!a.c[i]) {
                                break;
                            }
                        }
                        else if (!this.ar) {
                            break;
                        }
                        j++;
                    }
                }
            }
        }
        return f;
    };
    RearrangedListView.prototype.ao = function (a, b, c, d, e, f) {
        var g = new DataSourceSpecialRow();
        g.level = b;
        for (var h = 0; h < d.length; h++) {
            g.setValue(d[h], this.m.getItemProperty(c, d[h]));
            if (h < e.length) {
                g.setSectionValue(e[h], this.m.getItemProperty(c, e[h]));
            }
        }
        g.rowType = 1;
        g.summaryResults = new Array(this.ag.k.count);
        if (f && this.a != null) {
            if (this.a[b] != null) {
                if (this.a[b].isHeaderSame(g)) {
                    return false;
                }
                else {
                    this.a[b] = g;
                    for (var i = b + 1; i < this.a.length; i++) {
                        this.a[i] = null;
                    }
                }
            }
            else {
                this.a[b] = g;
            }
        }
        this.a4.insert1(a, g);
        return true;
    };
    RearrangedListView.prototype.an = function (a, b, c, d, e, f) {
        var g = new DataSourceSpecialRow();
        g.level = b;
        for (var h = 0; h < d.length; h++) {
            g.setValue(d[h], this.m.getItemProperty(c, d[h]));
            if (h < e.length) {
                g.setSectionValue(e[h], this.m.getItemProperty(c, e[h]));
            }
        }
        g.rowType = 1;
        g.summaryResults = new Array(this.ag.k.count);
        if (f && this.a != null) {
            if (this.a[b] != null) {
                if (this.a[b].isHeaderSame(g)) {
                    return false;
                }
                else {
                    this.a[b] = g;
                    for (var i = b + 1; i < this.a.length; i++) {
                        this.a[i] = null;
                    }
                }
            }
            else {
                this.a[b] = g;
            }
        }
        a.add1(g);
        return true;
    };
    RearrangedListView.prototype.bb = function (a, b, c, d) {
        var e = 0;
        if (this.au) {
            if (this.m.sectionHeaderDisplayMode == 0) {
                this.bv(a, 0, b, c, d);
                e++;
            }
            else if (this.m.sectionHeaderDisplayMode == 1) {
                for (var f = d.length - 1; f >= 0; f--) {
                    if (this.z.t._inner[this.z.t.count - 1].c[f]) {
                        this.bv(a, f, b, c, [d[f]]);
                        a++;
                        e++;
                    }
                }
            }
        }
        return e;
    };
    RearrangedListView.prototype.bv = function (a, b, c, d, e) {
        var f = new DataSourceSpecialRow();
        f.level = b;
        for (var g = 0; g < d.length; g++) {
            f.setValue(d[g], this.m.getItemProperty(c, d[g]));
            if (g < e.length) {
                f.setSectionValue(e[g], this.m.getItemProperty(c, e[g]));
            }
        }
        f.rowType = 2;
        this.a4.insert1(a, f);
    };
    RearrangedListView.prototype.q = function (a, b, c) {
        var d = this.r(b, 0, c, 5);
        if (this.as) {
            a.ag++;
        }
        else {
            a.ah++;
        }
        a.ad++;
        this.z.ac(a, 1, 1);
        return d;
    };
    RearrangedListView.prototype.r = function (a, b, c, d) {
        var e = ((function () {
            var $ret = new DataSourceSpecialRow();
            $ret.level = b;
            $ret.rowType = d;
            $ret.summaryResults = c;
            return $ret;
        })());
        this.a4.insert1(a, e);
        return e;
    };
    RearrangedListView.prototype.bf = function (a, b, c) {
        var d = a.w();
        var e = a.af + a.ah + a.aa;
        if (this.av) {
            e += d;
        }
        this.bh(e, a.c.length, b);
        a.aa++;
        a.ad++;
        a.u++;
        if (c) {
            this.z.ac(a, 1, 1);
        }
        return e;
    };
    RearrangedListView.prototype.bg = function (a, b, c) {
        var d = a.w();
        if (this.av) {
            b += d;
        }
        this.bh(b, a.c.length, c);
        a.aa++;
        a.ad++;
        a.u++;
        this.z.ac(a, 1, 1);
        return b;
    };
    RearrangedListView.prototype.bh = function (a, b, c) {
        var d = new DataSourceSpecialRow();
        d.rowType = 3;
        d.targetRow = c;
        d.level = b;
        this.a4.insert1(a, d);
        return a + 1;
    };
    RearrangedListView.prototype.bi = function (a, b) {
        var c = -1;
        for (var d = 0; d < this.a3.count; d++) {
            if (this.p.i(b, this.a3._inner[d]) == 0) {
                c = d;
                break;
            }
        }
        return this.bj(a, b, c);
    };
    RearrangedListView.prototype.bj = function (a, b, c) {
        var d = -1;
        if (c != -1) {
            var e = a.af;
            var f = e + a.aa;
            var g = false;
            for (var h = e; h < f; h++) {
                var i = this.av ? h + 1 : h;
                var j = typeCast(DataSourceSpecialRow.$, this.a4._inner[i]);
                if (j.targetRow != null) {
                    if (this.a0 != null) {
                        var k = this.a0.compare(b, j.targetRow);
                        if (k == 0 || k < 0) {
                            d = this.bg(a, h, b);
                            g = true;
                            break;
                        }
                    }
                    else {
                        var l = -1;
                        for (var m = 0; m < this.a3.count; m++) {
                            if (this.p.i(j.targetRow, this.a3._inner[m]) == 0) {
                                l = m;
                                break;
                            }
                        }
                        if (l > c) {
                            d = this.bg(a, h, b);
                            g = true;
                            break;
                        }
                    }
                }
            }
            if (!g) {
                d = this.bf(a, b, true);
                g = true;
            }
        }
        return d;
    };
    RearrangedListView.prototype.bw = function (a) {
        var b = SectionData.s(a);
        this.a7 = b.count;
        for (var c = 0; c < b.count; c++) {
            var d = new Array(b._inner[c].count);
            b._inner[c].values.copyTo(d, 0);
            this.r(this.a4.count, 0, d, 4);
        }
    };
    RearrangedListView.prototype.bx = function () {
        if (this.l == 0 || this.l == 2) {
            for (var a = 0; a < this.z.t.count; a++) {
                var b = this.z.t._inner[a];
                if (this.am) {
                    if (this.as) {
                        this.by(b, false);
                    }
                    else {
                        this.bz(b, false);
                    }
                }
                else {
                    for (var c = 0; c < b.j.length; c++) {
                        var d = this.a4._inner[b.af + b.b[c]];
                        if (d != null) {
                            d.summaryResults = b.j[c];
                        }
                        if (!b.c[c]) {
                            break;
                        }
                    }
                }
            }
        }
    };
    RearrangedListView.prototype.bz = function (a, b) {
        var c = 0;
        var d = this.bl(a, !this.as);
        for (var e = 0; e < a.j.length; e++) {
            if (a.a[e] == null || !a.c[e]) {
                continue;
            }
            var f = SectionData.s(a.j[e]);
            if (this.av) {
                c += 1;
            }
            a.g[e] = new SummaryGroup();
            a.g[e].a = new Array(this.a8);
            for (var g = 0; g < f.count; g++) {
                var h = new Array(f._inner[g].count);
                f._inner[g].values.copyTo(h, 0);
                var i = a.af + c + g;
                var j = this.r(i, e + 1, h, 5);
                a.ak(j, g);
                for (var k = e + 1; k < a.b.length; k++) {
                    a.b[k]++;
                }
                a.ad++;
                a.ah++;
                this.z.ad(a, 1, 1);
                if (d != null) {
                    var l = this.f();
                    for (var m = 0; m < l.length; m++) {
                        j.setValue(l[m], this.m.getItemProperty(d, l[m]));
                    }
                }
                if (b && this.ab != null) {
                    this.ab.notifyInsertItem(i, j);
                }
            }
            c += f.count;
        }
    };
    RearrangedListView.prototype.be = function (a, b, c) {
        var d = a.h[b];
        var e = SectionData.s(a.j[b]);
        for (var f = 0; f < e.count; f++) {
            var g = new Array(e._inner[f].count);
            e._inner[f].values.copyTo(g, 0);
            var h = this.z.e(d - 1);
            var i = this.r(d + f, b + 1, g, 5);
            a.ak(i, f);
            h.ad++;
            h.ag++;
            this.z.ac(h, 1, 1);
            var j = null;
            var k = 0;
            for (var l = d + f - 1; l >= 0; l--) {
                var m = this.m.getRowType(l);
                if (m == 0 || m == 1) {
                    j = this.a4._inner[l];
                    k = m;
                    break;
                }
            }
            if (j != null) {
                var n = this.f();
                if (k == 1) {
                    var o = typeCast(DataSourceSpecialRow.$, j);
                    for (var p = 0; p < n.length; p++) {
                        i.setValue(n[p], o.getValue(n[p]));
                    }
                }
                else {
                    for (var q = 0; q < n.length; q++) {
                        i.setValue(n[q], this.m.getItemProperty(j, n[q]));
                    }
                }
            }
            if (c && this.ab != null) {
                this.ab.notifyInsertItem(d + f, i);
            }
        }
        return e.count;
    };
    RearrangedListView.prototype.by = function (a, b) {
        for (var c = 0; c < a.j.length; c++) {
            if (!a.c[c]) {
                break;
            }
            if (a.h[c] == -1) {
                continue;
            }
            a.g[c] = new SummaryGroup();
            a.g[c].a = new Array(this.a8);
            var d = this.be(a, c, b);
        }
    };
    RearrangedListView.prototype.f = function () {
        var a = new Array(this.ae.k.count + this.af.k.count);
        var b = 0;
        for (var c = 0; c < this.ae.k.count; c++) {
            a[b] = this.ae.k.item(c).propertyName;
            b++;
        }
        for (var d = 0; d < this.af.k.count; d++) {
            a[b] = this.af.k.item(d).propertyName;
            b++;
        }
        return a;
    };
    RearrangedListView.prototype.g = function () {
        var a = new Array(this.ae.k.count);
        var b = 0;
        for (var c = 0; c < this.ae.k.count; c++) {
            a[b] = this.ae.k.item(c).propertyName;
            b++;
        }
        return a;
    };
    RearrangedListView.prototype.bt = function (a, b, c) {
        this.z.x(a);
    };
    RearrangedListView.prototype.x = function (a, b, c) {
        return this.z.i(a, this.m, b, c, this.m.sectionHeaderDisplayMode, this.ar);
    };
    RearrangedListView.prototype.cb = function (a) {
        this.a3 = new List$1(Array_$type, 0);
        for (var b = 0; b < a.count; b++) {
            this.a3.add(a._inner[b]);
        }
    };
    RearrangedListView.prototype.b2 = function () {
        this.a4.clear();
        if (this.ab != null) {
            this.ab.notifyClearItems();
        }
    };
    RearrangedListView.prototype.notifySetItem = function (a, b, c) {
        if (this.a0 != null) {
            this.b8(b);
            this.bo(c);
        }
        else {
            this.b9(a, b);
            this.bp(a, c);
        }
    };
    RearrangedListView.prototype.bp = function (a, b) {
        if (!this.ax(b)) {
            return;
        }
        var c = this.a9(a);
        this.b3(c, b);
    };
    RearrangedListView.prototype.b3 = function (a, b) {
        this.b0(a, b);
        this.ce(a, b);
        this.cj(a, b);
    };
    RearrangedListView.prototype.b0 = function (a, b) {
        if (this.ah) {
            var c = this.z.e(a);
            if (c == null) {
                c = this.z.d();
            }
            var d = c.w();
            var e = true;
            if (a >= c.af && a <= c.af + (d - 1) + c.ah + c.aa) {
                if (!this.ai(c, b, this.a4._inner[c.af])) {
                    c = this.z.e(c.af - 1);
                    if (c == null) {
                        c = this.z.c();
                        c.af++;
                    }
                    e = false;
                }
                else {
                    a = c.af + d + c.ah + c.aa;
                }
            }
            if (e && !c.q) {
                return;
            }
            c.ad++;
            this.z.ac(c, 1, 0);
            if (this.ai(c, b, this.a4._inner[c.af])) {
                if (!c.q) {
                    c.ad--;
                    this.z.ac(c, -1, 0);
                    return;
                }
                if (a >= c.ad - c.v - c.ag && a <= c.ad) {
                    a = c.ad - c.v - c.ag;
                }
            }
        }
        this.a4.insert1(a, b);
        if (this.ab != null) {
            this.ab.notifyInsertItem(a, b);
        }
    };
    RearrangedListView.prototype.ce = function (a, b) {
        var c = null;
        if (this.ah) {
            c = this.z.e(a);
        }
        else {
            c = this.z.t._inner[0];
        }
        if (c == null) {
            if (this.ah && a == 0) {
                c = this.z.c();
            }
            else {
                c = this.z.d();
            }
        }
        if (this.ai(c, b, this.a4._inner[c.af])) {
            this.z.z(c, 1);
            if (this.aw && c.q) {
                var d = this.bi(c, b);
                if (d != -1 && this.ab != null) {
                    this.ab.notifyInsertItem(d, this.a4._inner[d]);
                }
            }
        }
        else {
            var e = this.z.e(a - 1);
            if (e != null && this.ai(e, b, this.a4._inner[e.af])) {
                this.z.z(e, 1);
                if (this.aw && e.q) {
                    var f = this.bi(e, b);
                    if (f != -1 && this.ab != null) {
                        this.ab.notifyInsertItem(f, this.a4._inner[f]);
                    }
                }
            }
            else {
                var g = false;
                if (a <= c.af) {
                    g = true;
                }
                var h = 0;
                var i = null;
                var j = null;
                var k = this.f();
                var l = this.g();
                var m = this.z.b(this.m, b, l, this.j, this.ar);
                m.af = a;
                m.ad = a;
                m.ae = g ? c.ae : c.ae + 1;
                this.z.af(m, g);
                for (var n = 0; n < c.f.length; n++) {
                    if (Base.equalsStatic(c.f[n], m.f[n]) && !c.c[n]) {
                        this.z.z(c, 1);
                        return;
                    }
                }
                this.z.aa(m.ae, m);
                if (this.av) {
                    var o = this.bc(m, a, k, l, false);
                    m.ad += o;
                    h += o;
                    i = this.a4._inner[a];
                    if (!g) {
                        c.ad--;
                    }
                }
                if (m.q) {
                    if (this.aw) {
                        for (var p = 0; p < this.a3.count; p++) {
                            if (this.p.i(b, this.a3._inner[p]) == 0) {
                                this.bf(m, b, false);
                                h++;
                                break;
                            }
                        }
                    }
                }
                else {
                    this.a4.removeAt(a + h);
                    m.ad--;
                    h--;
                }
                if (this.au) {
                    var q = this.bb(a + (h - 1), b, k, l);
                    if (q > 1) {
                        m.ad += q;
                    }
                    h += q;
                    j = this.a4._inner[a + (h - 1)];
                }
                this.z.ad(m, h, h);
                this.b7(m);
                if (m.q) {
                    this.z.z(m, 1);
                }
                if (this.ab != null) {
                    if (i != null) {
                        this.ab.notifyInsertItem(a, i);
                    }
                    if (j != null) {
                        this.ab.notifyInsertItem(a + (h - 1), j);
                    }
                }
            }
        }
    };
    RearrangedListView.prototype.cl = function (a) {
        var b = this.a4.indexOf1(a);
        if (b >= 0) {
            var c = this.a4._inner[b - 1];
            var d = typeCast(DataSourceSpecialRow.$, c);
            var e = this.f();
            for (var f = 0; f < e.length; f++) {
                if (d == null) {
                    a.setValue(e[f], this.m.getItemProperty(c, e[f]));
                }
                else {
                    a.setValue(e[f], d.getValue(e[f]));
                }
            }
        }
    };
    RearrangedListView.prototype.b7 = function (a) {
        var b = false;
        var c = false;
        if (a.ae > 0) {
            var d = this.z.t._inner[a.ae - 1];
            var e = 0;
            for (var f = 0, g = 0; f < a.e.length; f++, g++) {
                if (!b && Base.equalsStatic(d.f[f], a.f[f])) {
                    this.a4.removeAt(a.af + g);
                    a.ad--;
                    this.z.ac(a, -1, -1);
                    if (this.am && (this.l == 2 || this.l == 0)) {
                        for (var h = 0; h < this.a8; h++) {
                            var i = typeCast(DataSourceSpecialRow.$, this.a4._inner[a.af - 1]);
                            if (i != null && i.rowType == 5 && i.level == f + 1) {
                                this.a4.removeAt(a.af - 1);
                                d.ad--;
                                this.z.ac(d, -1, -1);
                                this.a4.insert1(a.ad + 1, i);
                                e++;
                                this.cl(i);
                            }
                        }
                    }
                    a.a[f] = null;
                    a.b[f] = 0;
                    a.c[f] = true;
                    if (d.a[f] != null) {
                        a.z = d.ae;
                    }
                    g--;
                    c = true;
                }
                else {
                    b = true;
                    a.b[f] = g;
                    if (e > 0) {
                        a.ad += e;
                        this.z.ac(a, e, e);
                        a.h[f] = a.ad - (e - 1);
                    }
                    else {
                        a.h[f] = a.ad + 1;
                    }
                }
            }
            if (a.z == -1 && c) {
                a.z = d.z;
            }
        }
        if (a.ae < this.z.t.count - 1) {
            b = false;
            c = false;
            var j = this.z.t._inner[a.ae + 1];
            for (var k = 0, l = 0; k < a.e.length; k++, l++) {
                if (!b && Base.equalsStatic(j.f[k], a.f[k])) {
                    if (j.a[k] != null) {
                        this.a4.removeAt(j.af + l);
                        j.ad--;
                        this.z.ac(j, -1, -1);
                        a.al(k, -1);
                        a.j[k] = j.j[k];
                        a.d[k] = j.d[k];
                        if (this.am && (this.l == 2 || this.l == 0)) {
                            var m = j.g[k].a[0];
                            var n = this.a4.indexOf1(m);
                            a.h[k] = n;
                            var o = this.z.e(n);
                            var p = j.g[k].a.length;
                            for (var q = 0; q < p; q++) {
                                j.g[k].a[q] = null;
                                this.a4.removeAt(n);
                                o.ad--;
                                if (this.as) {
                                    o.ag--;
                                }
                                else {
                                    o.ah--;
                                }
                            }
                            this.z.ac(o, -p, -p);
                            a.al(k, -p);
                        }
                        j.h[k] = -1;
                        j.d[k] = 0;
                        j.j[k] = null;
                        j.g[k] = null;
                        j.a[k] = null;
                        j.b[k] = 0;
                        j.c[k] = true;
                        c = true;
                    }
                    l--;
                }
                else {
                    b = true;
                    j.b[k] = l;
                    if (a.a[k] != null && a.h[k] == -1) {
                        a.h[k] = a.ad + 1;
                    }
                }
            }
        }
    };
    RearrangedListView.prototype.ai = function (a, b, c) {
        if (this.ae.k.count == 0) {
            return true;
        }
        if (this.a1.compare(b, c) == 0) {
            return true;
        }
        return false;
    };
    RearrangedListView.prototype.h = function (a, b) {
        var c = new Array(a.length);
        for (var d = 0; d < c.length; d++) {
            c[d] = this.m.getItemProperty(b, a[d]);
        }
        return c;
    };
    RearrangedListView.prototype.at = function (a, b) {
        if (a == null && b == null) {
            return true;
        }
        if (a == null && b != null) {
            return false;
        }
        if (a != null && b == null) {
            return false;
        }
        return Base.equalsStatic(a, b);
    };
    RearrangedListView.prototype.a9 = function (a) {
        if (this.ae.k.count == 0 && this.a3.count == 0 && this.s == null && this.n.actualCount == this.a4.count) {
            return a;
        }
        var b = 0;
        var c = 0;
        var d = this.a4.count;
        while (b < a && c < d) {
            while (c < d) {
                var e = this.a4._inner[c];
                var f = false;
                var viewItem_ = e;
                if ((viewItem_.$$isSpecialRow !== undefined)) {
                    f = true;
                }
                if (!f) {
                    break;
                }
                c++;
            }
            var g = this.n.getItemAtIndex(b);
            if (this.at(g, this.a4._inner[c])) {
                c++;
                b++;
            }
            else {
                b++;
            }
        }
        return c;
    };
    RearrangedListView.prototype.b9 = function (a, b) {
        var c = this.a9(a);
        if (c < this.a4.count) {
            if (this.at(b, this.a4._inner[c])) {
                this.b4(c, b);
            }
        }
    };
    RearrangedListView.prototype.b4 = function (a, b) {
        this.a4.removeAt(a);
        if (this.ab != null) {
            this.ab.notifyRemoveItem(a, b);
        }
        var c = this.y(a, b);
        this.ck(a, b, c);
    };
    RearrangedListView.prototype.y = function (a, b) {
        var c = null;
        if (this.ah) {
            c = this.z.e(a);
        }
        else {
            c = this.z.t._inner[0];
        }
        if (c != null) {
            this.z.z(c, -1);
            if (c.q) {
                c.ad--;
                this.z.ac(c, -1, 0);
                if (this.aw) {
                    for (var d = 0; d < c.aa; d++) {
                        var e = 0;
                        if (this.av) {
                            e = 1;
                        }
                        e += c.ah;
                        var f = this.a4._inner[c.af + d + e];
                        var g = null;
                        var item_ = f;
                        if ((item_ != null && item_.$$isSpecialRow !== undefined)) {
                            g = f;
                        }
                        if (g != null) {
                            if (g.targetRow == b) {
                                this.a4.removeAt(c.af + d + e);
                                c.ad--;
                                c.aa--;
                                c.u--;
                                this.z.ac(c, -1, -1);
                                if (this.ab != null) {
                                    this.ab.notifyRemoveItem(c.af + d + e, g);
                                }
                            }
                        }
                    }
                }
            }
            if (this.ah && !c.n() && this.aj(c)) {
                var h = 0;
                if (this.z.p(c)) {
                    var i = c.x();
                    var j = i;
                    var k = this.ae.k.count;
                    var l = this.g();
                    var m = this.z.t._inner[c.ae + 1];
                    for (var n = 0; n < c.f.length; n++) {
                        if (!Base.equalsStatic(c.f[n], m.f[n])) {
                            j = n;
                            break;
                        }
                    }
                    if (this.av) {
                        if (c.c[j - 1]) {
                            for (var o = j; o < k; o++) {
                                if (c.g[o] != null) {
                                    for (var p = 0; p < c.g[o].a.length; p++) {
                                        var q = c.g[o].a[p];
                                        if (q != null) {
                                            var r = this.a4.indexOf1(q);
                                            if (r >= 0) {
                                                this.a4.removeAt(r);
                                                c.ad--;
                                                h++;
                                                if (this.ab != null) {
                                                    this.ab.notifyRemoveItem(r, q);
                                                }
                                                if (!this.as) {
                                                    for (var s = o + 1; s < c.b.length; s++) {
                                                        c.b[s]--;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                var t = c.af + c.b[o];
                                var u = typeCast(DataSourceSpecialRow.$, this.a4._inner[t]);
                                if (u != null && u.rowType == 1) {
                                    c.a[o] = null;
                                    this.a4.removeAt(t);
                                    c.ad--;
                                    h++;
                                    if (this.ab != null) {
                                        this.ab.notifyRemoveItem(t, u);
                                    }
                                    for (var v = o + 1; v < c.b.length; v++) {
                                        c.b[v]--;
                                    }
                                }
                                if (!c.c[o]) {
                                    break;
                                }
                            }
                        }
                    }
                    c.l = m;
                    for (var w = 0; w < j; w++) {
                        if (this.am && !this.as && (this.l == 2 || this.l == 0)) {
                            m.af -= this.av ? this.a8 + 1 : this.a8;
                        }
                        else if (this.av) {
                            m.af--;
                        }
                    }
                    m.d[i] = c.d[i];
                    m.a[i] = c.a[i];
                    m.c[i] = c.c[i];
                    m.z = c.z;
                    for (var x = i; x < k; x++) {
                        m.g[x] = c.g[x];
                    }
                    m.b[i] = c.b[i];
                    for (var y = i, z = c.b[i]; y < k; y++) {
                        m.b[y] = z;
                        if (this.av) {
                            z++;
                        }
                        if (!this.as) {
                            if (m.g[y] != null) {
                                z += m.g[y].a.length;
                            }
                        }
                        var aa = m.af - h + m.b[y];
                        var ab = typeCast(DataSourceSpecialRow.$, this.a4._inner[aa]);
                        if (ab != null && ab.rowType == 1) {
                            for (var ac = 0; ac < m.f.length; ac++) {
                                ab.setValue(m.e[ac], m.f[ac]);
                            }
                        }
                    }
                }
                else {
                    if (this.av) {
                        for (var ad = c.af; ad <= c.ad; ad++) {
                            var ae = typeCast(DataSourceSpecialRow.$, this.a4._inner[ad]);
                            if (ae != null && ae.rowType == 1) {
                                this.a4.removeAt(ad);
                                c.ad--;
                                h++;
                                ad--;
                                if (this.ab != null) {
                                    this.ab.notifyRemoveItem(ad, ae);
                                }
                            }
                        }
                    }
                    for (var af = 0; af < c.g.length; af++) {
                        if (c.g[af] == null) {
                            continue;
                        }
                        for (var ag = 0; ag < c.g[af].a.length; ag++) {
                            var ah = c.g[af].a[ag];
                            if (ah != null) {
                                var ai = this.a4.indexOf1(ah);
                                this.a4.removeAt(ai);
                                c.ad--;
                                h++;
                                if (this.ab != null) {
                                    this.ab.notifyRemoveItem(ai, ah);
                                }
                            }
                        }
                    }
                    if (c.z >= 0) {
                        var aj = c.ad - c.af + 1;
                        if (aj > 0) {
                            var ak = this.a4._inner[c.af - 1];
                            var al = typeCast(DataSourceSpecialRow.$, ak);
                            var am = this.f();
                            for (var an = 0; an < aj; an++) {
                                var ao = c.af + an;
                                var ap = typeCast(DataSourceSpecialRow.$, this.a4._inner[ao]);
                                if (ap != null) {
                                    for (var aq = 0; aq < am.length; aq++) {
                                        if (al == null) {
                                            ap.setValue(am[aq], this.m.getItemProperty(ak, am[aq]));
                                        }
                                        else {
                                            ap.setValue(am[aq], al.getValue(am[aq]));
                                        }
                                    }
                                }
                            }
                            var ar = this.z.t._inner[c.ae - 1];
                            ar.ad += aj;
                        }
                    }
                }
                if (this.au) {
                    for (var as = 0; as < c.a.length; as++) {
                        if (!c.c[as]) {
                            break;
                        }
                        if (c.a[as] != null) {
                            var at = this.a4._inner[c.ad];
                            this.a4.removeAt(c.ad);
                            if (this.ab != null) {
                                this.ab.notifyRemoveItem(c.ad, at);
                            }
                            h++;
                            c.ad--;
                        }
                    }
                }
                this.z.ae(c.ae);
                this.z.ab(c, -h, -h);
                c.p = true;
            }
        }
        return c;
    };
    RearrangedListView.prototype.aj = function (a) {
        for (var b = a.af; b <= a.ad; b++) {
            if (this.m.getRowType(b) == 0) {
                return false;
            }
        }
        return true;
    };
    RearrangedListView.prototype.bo = function (a) {
        if (this.ax(a)) {
            var b = this.a4.g(a, this.a0);
            if (b < 0) {
                b = ~b;
            }
            this.b3(b, a);
        }
    };
    RearrangedListView.prototype.b5 = function (a) {
        this.a3.add(a);
        var b = this.m.indexOfKey(a);
        var c = this.m.getItemAtIndex(b);
        if (b == -1) {
            return;
        }
        if (this.aw) {
            var d = this.z.e(b);
            var e = this.bi(d, this.a4._inner[b]);
            if (this.ab != null) {
                this.ab.notifyInsertItem(e, this.a4._inner[e]);
            }
        }
    };
    RearrangedListView.prototype.cc = function (a) {
        if (this.a3.remove(a)) {
            var b = this.m.indexOfKey(a);
            var c = this.m.getItemAtIndex(b);
            if (b == -1) {
                return;
            }
            var d = this.z.e(b);
            var e = d.af;
            if (this.av) {
                e += d.w();
            }
            if (this.aw) {
                var f = this.u(e, this.a4._inner[b], d.aa, this.f());
                if (f != null) {
                    d.ad--;
                    d.aa--;
                    d.u--;
                    this.z.ac(d, -1, -1);
                    if (this.ab != null) {
                        this.ab.notifyRemoveItem(f.a, f.item);
                    }
                }
            }
        }
    };
    RearrangedListView.prototype.u = function (a, b, c, d) {
        var _loop_1 = function (e) {
            if (typeCast(DataSourceSpecialRow.$, this_1.a4._inner[e]) !== null) {
                var f_1 = this_1.a4._inner[e];
                if (f_1.rowType == 3) {
                    var g = f_1.targetRow;
                    if (g == b) {
                        this_1.a4.removeAt(e);
                        return { value: ((function () {
                                var $ret = new RemovedShiftedRowInfo();
                                $ret.item = f_1;
                                $ret.a = e;
                                return $ret;
                            })()) };
                    }
                }
            }
        };
        var this_1 = this;
        for (var e = a + (c - 1); e >= a; e--) {
            var state_1 = _loop_1(e);
            if (typeof state_1 === "object")
                return state_1.value;
        }
        return null;
    };
    RearrangedListView.prototype.b8 = function (a) {
        var b = this.a4.g(a, this.a0);
        if (b < 0) {
            b = ~b;
        }
        if (b >= 0) {
            var c = this.a4.count;
            var d = 0;
            while (d < c) {
                var e = b - d;
                var f = b + d;
                if (e < 0 && f > c - 1) {
                    break;
                }
                if (e >= 0 && e < c) {
                    if (this.a4._inner[e] != null && Base.equalsStatic(this.a4._inner[e], a)) {
                        b = e;
                        break;
                    }
                }
                if (f < c) {
                    if (this.a4._inner[f] != null && Base.equalsStatic(this.a4._inner[f], a)) {
                        b = f;
                        break;
                    }
                }
                d++;
            }
            if (b < 0 || b > c - 1) {
                return;
            }
            var g = this.a4._inner[b];
            if (g == null && a == null) {
                this.a4.removeAt(b);
                this.aa.notifyRemoveItem(b, a);
                var h = this.y(b, a);
                this.ci(b, a, false, h);
                return;
            }
            if (g == null) {
                return;
            }
            if (Base.equalsStatic(g, a)) {
                this.a4.removeAt(b);
                this.aa.notifyRemoveItem(b, a);
                var i = this.y(b, a);
                this.ci(b, a, false, i);
            }
            else {
                if (b - 1 >= 0) {
                    var j = this.z.e(b - 1);
                    if (j != null && !j.q) {
                        b = b - 1;
                    }
                }
                this.y(b, a);
            }
        }
        else {
            var k = this.a4.count;
            for (var l = 0; l < k; l++) {
                var m = this.a4._inner[l];
                if (m == null && a == null) {
                    this.a4.removeAt(l);
                    break;
                }
                if (m == null) {
                    continue;
                }
                if (Base.equalsStatic(m, a)) {
                    this.a4.removeAt(l);
                    this.aa.notifyRemoveItem(l, a);
                    var n = this.y(l, a);
                    this.ck(l, a, n);
                    break;
                }
            }
        }
    };
    RearrangedListView.prototype.ax = function (a) {
        if (this.s == null) {
            return true;
        }
        return this.s(a);
    };
    RearrangedListView.prototype.notifyClearItems = function () {
    };
    RearrangedListView.prototype.notifyInsertItem = function (a, b) {
        if (this.a0 != null) {
            this.bo(b);
        }
        else {
            this.bp(a, b);
        }
    };
    RearrangedListView.prototype.notifyRemoveItem = function (a, b) {
        if (this.a0 != null) {
            this.b8(b);
        }
        else {
            this.b9(a, b);
        }
    };
    RearrangedListView.prototype.ca = function (a, b) {
        var c = this.z.e(a);
        if (c == null) {
            c = this.z.d();
        }
        for (var d = 0, e = 0; d < c.a.length; d++) {
            if (c.a[d] != null) {
                if (a == c.af + c.b[d]) {
                    var f = c.a[d];
                    if (this.ay.containsKey(f)) {
                        if (this.ay.item(f) != b) {
                            var g = this.ay.item(f);
                            if (b == this.ar) {
                                this.ay.removeItem(f);
                            }
                            else {
                                this.ay.item(f, b);
                            }
                            this.m.queueAutoRefresh();
                            if (this.ad != null) {
                                this.ad.notifyRowExpansionChanged(a, g, b);
                            }
                        }
                    }
                    else if (b != this.ar) {
                        this.ay.addItem(f, b);
                        this.m.queueAutoRefresh();
                        if (this.ad != null) {
                            this.ad.notifyRowExpansionChanged(a, this.ar, b);
                        }
                    }
                }
                e++;
            }
        }
    };
    RearrangedListView.prototype.ak = function (a) {
        var b = this.z.e(a);
        if (b == null) {
            b = this.z.d();
        }
        for (var c = 0, d = 0; c < b.a.length; c++) {
            if (b.a[c] != null) {
                if (a == b.af + b.b[c]) {
                    return b.c[c];
                }
                d++;
            }
        }
        return true;
    };
    RearrangedListView.prototype.al = function (a) {
        if (!this.aq) {
            return true;
        }
        return this.ay.containsKey(a) ? this.ay.item(a) : this.ar;
    };
    RearrangedListView.prototype.bm = function (a) {
        var b = "";
        for (var c = 0; c < a.e.length; c++) {
            b += a.e[c] + ":" + a.f[c];
        }
        return b;
    };
    RearrangedListView.prototype.bn = function (a, b) {
        if (this.m.sectionHeaderDisplayMode == 0) {
            return this.bm(a);
        }
        var c = "";
        for (var d = 0; d < b + 1; d++) {
            c += a.e[d] + ":" + a.f[d] + ":";
        }
        return c;
    };
    RearrangedListView.prototype.br = function (a) {
        if (this.l == 3 || (a != null && this.l == 1) || (a == null && this.l == 2)) {
            return;
        }
        if (a == null && (this.e == null || this.e.length != this.ag.k.count)) {
            this.e = new Array(this.ag.k.count);
        }
        if (a != null) {
            var b = a.w();
            for (var c = b - 1; c >= 0; c--) {
                for (var d = 0; d < this.ag.k.count; d++) {
                    var e = this.ag.k.item(d);
                    this.c[c][d].beginCalculation(this.m, e.propertyName);
                }
            }
        }
        else {
            if (this.d == null || this.d.length != this.ag.k.count) {
                this.d = new Array(this.ag.k.count);
            }
            for (var f = 0; f < this.ag.k.count; f++) {
                var g = this.ag.k.item(f);
                if (this.d[f] == null || this.d[f].operand != g.operand) {
                    this.d[f] = g.d();
                }
                this.d[f].beginCalculation(this.m, g.propertyName);
            }
        }
    };
    RearrangedListView.prototype.bu = function (a) {
        if (this.l == 3 || (a != null && this.l == 1) || (a == null && this.l == 2)) {
            return;
        }
        if (a != null) {
            var b = a.w();
            for (var c = b - 1; c >= 0; c--) {
                var d = this.a4._inner[a.af + c];
                for (var e = 0; e < this.ag.k.count; e++) {
                    var f = this.ag.k.item(e);
                    var g = this.c[c][e].endCalculation();
                    g.summaryIndex = e;
                    if (d != null) {
                        d.summaryResults[c] = g;
                    }
                }
            }
        }
        else {
            for (var h = 0; h < this.ag.k.count; h++) {
                var i = this.d[h].endCalculation();
                i.summaryIndex = h;
                this.e[h] = i;
            }
        }
    };
    RearrangedListView.prototype.bq = function (a, b) {
        if (this.l == 3 || (a != null && this.l == 1) || (a == null && this.l == 2)) {
            return;
        }
        if (b != null) {
            if (a != null) {
                for (var c = 0; c < this.c.length; c++) {
                    if (this.c[c] != null) {
                        for (var d = 0; d < this.c[c].length; d++) {
                            if (this.c[c][d] != null) {
                                this.c[c][d].aggregate(b);
                            }
                        }
                    }
                }
            }
            else {
                for (var e = 0; e < this.ag.k.count; e++) {
                    this.d[e].aggregate(b);
                }
            }
        }
    };
    RearrangedListView.prototype.cg = function (a, b, c, d, e) {
        var f = a.j[d][e];
        var g = b.itemAdded(c, f, a.d[d]);
        a.an(d, e, g);
        if (this.av) {
            if (a.a[d] != null) {
                var h = typeCast(DataSourceSpecialRow.$, this.a4._inner[a.af + a.b[d]]);
                if (h != null) {
                    h.summaryResults[e] = a.j[d][e];
                }
            }
        }
    };
    RearrangedListView.prototype.cf = function (a, b, c, d, e, f) {
        var g = a.j[d][e];
        var h = a.d[d];
        var i = f ? b.itemAdded(c, g, h) : b.itemRemoved(c, g, h);
        a.an(d, e, i);
        if (this.av) {
            if (!a.p && a.a[d] != null) {
                var j = typeCast(DataSourceSpecialRow.$, this.a4._inner[a.af + a.b[d]]);
                if (j != null) {
                    j.summaryResults[e] = a.j[d][e];
                }
            }
        }
    };
    RearrangedListView.prototype.ci = function (a, b, c, d) {
        if (this.ag.k.count == 0) {
            return;
        }
        if (d == null) {
            d = this.w(a);
            if (d == null) {
                d = this.z.d();
            }
        }
        var e = false;
        var f = false;
        var g = false;
        for (var h = 0; h < this.ag.k.count; h++) {
            var i = this.ag.k.item(h);
            if (this.l == 0 || this.l == 1) {
                var j = null;
                if (c) {
                    j = this.d[h].itemAdded(b, this.e[h], this.n.actualCount);
                }
                else {
                    j = this.d[h].itemRemoved(b, this.e[h], this.n.actualCount);
                }
                j.summaryIndex = h;
                this.e[h] = j;
                if (this.d[h].isSummaryDirty) {
                    e = true;
                }
                else {
                    f = true;
                }
            }
            if (this.l == 0 || this.l == 2) {
                if (d != null && d.j != null) {
                    var k = i.d();
                    k.dataSource = this.m;
                    k.propertyName = i.propertyName;
                    k.propertyType = this.m.resolveSchemaPropertyType(i.propertyName);
                    var l = this.g();
                    var m = d.x();
                    for (var n = m; n < l.length; n++) {
                        this.cf(d, k, b, n, h, c);
                        if (k.isSummaryDirty) {
                            e = true;
                        }
                        g = true;
                    }
                    var o = d.z;
                    while (o != -1) {
                        var p = this.z.t._inner[o];
                        var q = p.x();
                        for (var r = q; r < m; r++) {
                            this.cf(p, k, b, r, h, c);
                            if (k.isSummaryDirty) {
                                e = true;
                            }
                        }
                        o = p.z;
                        m = m - 1;
                    }
                }
            }
        }
        if (e) {
            this.m.queueAutoRefresh();
        }
        else {
            if (f) {
                var s = SectionData.s(this.e);
                this.cd(s);
            }
            if (g) {
                this.ch(d, null);
                var t = d.z;
                while (t != -1) {
                    var u = this.z.t._inner[t];
                    this.ch(u, null);
                    t = u.z;
                }
            }
        }
    };
    RearrangedListView.prototype.cj = function (a, b) {
        if (this.ag.k.count == 0) {
            return;
        }
        var c = this.w(a);
        if (c == null) {
            c = this.z.d();
        }
        var d = null;
        if (c != null) {
            d = typeCast(DataSourceSpecialRow.$, this.a4._inner[c.af]);
        }
        var e = false;
        var f = false;
        var g = false;
        for (var h = 0; h < this.ag.k.count; h++) {
            var i = this.ag.k.item(h);
            if (this.l == 0 || this.l == 1) {
                var j = this.d[h].itemAdded(b, this.e[h], this.n.actualCount);
                j.summaryIndex = h;
                this.e[h] = j;
                if (this.d[h].isSummaryDirty) {
                    e = true;
                }
                else {
                    f = true;
                }
            }
            if (this.l == 0 || this.l == 2) {
                if (c != null && c.j != null) {
                    var k = i.d();
                    k.dataSource = this.m;
                    k.propertyName = i.propertyName;
                    k.propertyType = this.m.resolveSchemaPropertyType(i.propertyName);
                    var l = this.g();
                    var m = c.x();
                    for (var n = m; n < l.length; n++) {
                        this.cg(c, k, b, n, h);
                        if (k.isSummaryDirty) {
                            e = true;
                        }
                        g = true;
                    }
                    var o = c.z;
                    while (o != -1) {
                        var p = this.z.t._inner[o];
                        var q = p.x();
                        for (var r = q; r < m; r++) {
                            this.cg(p, k, b, r, h);
                            if (k.isSummaryDirty) {
                                e = true;
                            }
                        }
                        o = p.z;
                        m = m - 1;
                    }
                }
            }
        }
        if (e) {
            this.m.queueAutoRefresh();
        }
        else {
            if (f) {
                var s = SectionData.s(this.e);
                this.cd(s);
            }
            if (g) {
                this.ch(c, null);
                var t = c.z;
                while (t != -1) {
                    var u = this.z.t._inner[t];
                    this.ch(u, null);
                    t = u.z;
                }
            }
        }
    };
    RearrangedListView.prototype.ck = function (a, b, c) {
        if (this.ag.k.count == 0) {
            return;
        }
        var d = null;
        if (c != null) {
            d = typeCast(DataSourceSpecialRow.$, this.a4._inner[c.af]);
        }
        var e = false;
        var f = false;
        var g = false;
        for (var h = 0; h < this.ag.k.count; h++) {
            var i = this.ag.k.item(h);
            if (this.l == 0 || this.l == 1) {
                var j = this.d[h].itemRemoved(b, this.e[h], this.m.actualCount);
                j.summaryIndex = h;
                this.e[h] = j;
                if (this.d[h].isSummaryDirty) {
                    e = true;
                }
                else {
                    f = true;
                }
            }
            if (this.l == 0 || this.l == 2) {
                if (c != null && c.j != null) {
                    var k = i.d();
                    k.dataSource = this.m;
                    k.propertyName = i.propertyName;
                    k.propertyType = this.m.resolveSchemaPropertyType(i.propertyName);
                    var l = this.g();
                    var m = c.x();
                    for (var n = m; n < l.length; n++) {
                        this.cf(c, k, b, n, h, false);
                        if (k.isSummaryDirty) {
                            e = true;
                        }
                        g = true;
                    }
                    var o = c.z;
                    while (o != -1) {
                        var p = this.z.t._inner[o];
                        var q = p.x();
                        for (var r = q; r < m; r++) {
                            this.cf(p, k, b, r, h, false);
                            if (k.isSummaryDirty) {
                                e = true;
                            }
                        }
                        o = p.z;
                        m = m - 1;
                    }
                }
            }
        }
        if (e) {
            this.m.queueAutoRefresh();
        }
        else {
            if (f) {
                var s = SectionData.s(this.e);
                this.cd(s);
            }
            if (g) {
                this.ch(c, null);
                var t = c.z;
                while (t != -1) {
                    var u = this.z.t._inner[t];
                    this.ch(u, null);
                    t = u.z;
                }
            }
        }
    };
    RearrangedListView.prototype.ch = function (a, b) {
        var _this = this;
        if (this.l == 2 || this.l == 0) {
            if (this.am) {
                if (!a.p && !a.o()) {
                    if (this.as) {
                        this.by(a, true);
                    }
                    else {
                        this.bz(a, true);
                    }
                }
                else {
                    a.am(function (c) {
                        if (_this.ab != null) {
                            var d = _this.a4.indexOf1(c);
                            _this.ab.notifySetItem(d, c, c);
                        }
                    });
                }
            }
            else {
                for (var c = 0; c < a.j.length; c++) {
                    var d = a.af + a.b[c];
                    var e = this.a4._inner[d];
                    if (e != null) {
                        e.summaryResults = a.j[c];
                        if (this.ab != null) {
                            this.ab.notifySetItem(d, e, e);
                        }
                    }
                }
            }
        }
    };
    RearrangedListView.prototype.cd = function (a) {
        for (var b = 0; b < a.count; b++) {
            var c = new Array(a._inner[b].count);
            a._inner[b].values.copyTo(c, 0);
            var d = this.a4.count - a.count + b;
            var e = typeCast(DataSourceSpecialRow.$, this.a4._inner[d]);
            e.summaryResults = c;
            if (this.ab != null) {
                this.ab.notifySetItem(d, e, e);
            }
        }
    };
    RearrangedListView.$t = markType(RearrangedListView, 'RearrangedListView', Base.$, [ISupportsDataChangeNotifications_$type]);
    return RearrangedListView;
}(Base));
export { RearrangedListView };
//# sourceMappingURL=RearrangedListView.js.map
