/*
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 { Base, typeCast, Array_$type, String_$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 { RemovedShiftedRowInfo } from "./RemovedShiftedRowInfo";
/**
 * @hidden
 */
export class RearrangedListView extends Base {
    constructor(a) {
        super();
        this.h = null;
        this.an = null;
        this.p = new SectionMap();
        this.a = null;
        this.i = null;
        this.aj = null;
        this.ai = null;
        this.k = null;
        this.q = null;
        this.g = null;
        this.s = null;
        this.t = null;
        this.u = null;
        this.aa = false;
        this.e = 0;
        this.ae = false;
        this.ad = false;
        this.af = false;
        this.v = false;
        this.am = new List$1(Array_$type, 0);
        this.ah = new Dictionary$2(String_$type, Boolean_$type, 0);
        this.h = a;
    }
    get ap() {
        return this.an;
    }
    n(a) {
        return this.p.d(a);
    }
    get j() {
        return this.i;
    }
    set j(a) {
        this.i = a;
    }
    get al() {
        return this.aj;
    }
    set al(a) {
        this.aj = a;
    }
    get ak() {
        return this.ai;
    }
    set ak(a) {
        this.ai = a;
    }
    get l() {
        return this.k;
    }
    set l(a) {
        this.k = a;
    }
    get r() {
        return this.q;
    }
    set r(a) {
        this.q = a;
    }
    get f() {
        return this.e;
    }
    set f(a) {
        this.e = a;
    }
    get ab() {
        if (this.g.isSectionCollapsable) {
            return this.g.isSectionExpandedDefault;
        }
        return true;
    }
    be() {
        if (this.an == this.h || this.an == null) {
            this.an = new List$1(Base.$, 0);
        }
        this.an.clear();
        if (!this.g.isSectionCollapsable) {
            this.ah.clear();
        }
        if (this.h == null) {
            return;
        }
        let a = this.h.actualCount;
        this.a3(null);
        let b = this.u.k.count > 0 && this.f != 2 && this.f != 3;
        if (this.k == null) {
            for (let c = 0; c < a; c++) {
                let d = this.h.getItemAtIndex(c);
                this.an.add1(d);
                if (b) {
                    this.a2(null, d);
                }
            }
        }
        else {
            for (let e = 0; e < a; e++) {
                let f = this.h.getItemAtIndex(e);
                if (this.k(f)) {
                    this.an.add1(f);
                    if (b) {
                        this.a2(null, f);
                    }
                }
            }
        }
        this.a5(null);
        if (this.aj != null) {
            this.an.z(this.aj);
        }
        this.v = false;
        this.p.r();
        if (this.s != null && this.s.k.count > 0) {
            this.v = true;
            this.a9();
        }
        else {
            this.p.p.add(((() => {
                let $ret = new SectionData();
                $ret.m = 0;
                $ret.c = null;
                $ret.d = null;
                $ret.n = 0;
                $ret.l = this.an.count;
                $ret.b = new Array(0);
                return $ret;
            })()));
        }
        let g = this.j;
        let h = new List$1(Base.$, 0);
        if (this.am.count > 0 && this.af) {
            if (!this.v) {
                let i = this.p.p._inner[0];
                for (let j = 0; j < this.am.count; j++) {
                    let k = this.g.indexOfKey(this.am._inner[j]);
                    if (k != -1) {
                        this.ax(i, this.an._inner[k], j);
                    }
                }
            }
            else {
                for (let l = 0; l < this.am.count; l++) {
                    let m = this.g.indexOfKey(this.am._inner[l]);
                    if (m != -1) {
                        let n = this.p.d(m);
                        this.ax(n, this.an._inner[m], l);
                    }
                }
            }
        }
        if (this.r != null) {
            this.r.notifyClearItems();
        }
    }
    at(a, b, c) {
        let d = a.n + a.h;
        if (this.ae) {
            d += a.b.length;
        }
        this.av(d, b);
        a.h++;
        a.l++;
        a.g++;
        if (c) {
            this.p.x(a, 1, 1);
        }
        return d;
    }
    au(a, b, c) {
        if (this.ae) {
            b += a.b.length;
        }
        this.av(b, c);
        a.h++;
        a.l++;
        a.g++;
        this.p.x(a, 1, 1);
        return b;
    }
    av(a, b) {
        let c = new DataSourceSpecialRow();
        c.rowType = 3;
        c.targetRow = b;
        this.an.insert1(a, c);
        return a + 1;
    }
    aw(a, b) {
        let c = -1;
        for (let d = 0; d < this.am.count; d++) {
            if (this.j.i(b, this.am._inner[d]) == 0) {
                c = d;
                break;
            }
        }
        return this.ax(a, b, c);
    }
    ax(a, b, c) {
        let d = -1;
        if (c != -1) {
            let e = a.n;
            let f = e + a.h;
            let g = false;
            for (let h = e; h < f; h++) {
                let i = this.ae ? h + 1 : h;
                let j = typeCast(DataSourceSpecialRow.$, this.an._inner[i]);
                if (this.aj != null) {
                    let k = this.aj.compare(b, j.targetRow);
                    if (k == 0 || k < 0) {
                        d = this.au(a, h, b);
                        g = true;
                        break;
                    }
                }
                else {
                    let l = -1;
                    for (let m = 0; m < this.am.count; m++) {
                        if (this.j.i(j.targetRow, this.am._inner[m]) == 0) {
                            l = m;
                            break;
                        }
                    }
                    if (l > c) {
                        d = this.au(a, h, b);
                        g = true;
                        break;
                    }
                }
            }
            if (!g) {
                d = this.at(a, b, true);
                g = true;
            }
        }
        return d;
    }
    get ao() {
        return this.p.p;
    }
    a9() {
        if (this.an.count == 0) {
            return;
        }
        let a = this.b();
        let b = this.c();
        let c = null;
        let d = null;
        for (let e = 0; e < this.an.count; e++) {
            let f = this.an._inner[e];
            if (f == null) {
                continue;
            }
            if (c == null) {
                this.bj(e, f, b);
                let g = this.p.p._inner[this.p.p.count - 1];
                let h = this.as(g, e, a, b);
                e += h;
                if (this.ae && !g.f) {
                    this.an.removeAt(e);
                    e--;
                }
                g.k++;
                d = f;
                this.a3(g);
                this.a2(g, f);
            }
            else {
                if (this.ak.compare(c, f) != 0) {
                    let i = this.p.p._inner[this.p.p.count - 1];
                    e += this.ar(e, d, a, b);
                    this.a4(e - 1, d, a);
                    this.a5(i);
                    this.bj(e, f, b);
                    let j = this.p.p._inner[this.p.p.count - 1];
                    e += this.as(j, e, a, b);
                    if (this.ae && !j.f) {
                        this.an.removeAt(e);
                        e--;
                    }
                    j.k++;
                    d = f;
                    this.a3(j);
                    this.a2(j, f);
                }
                else {
                    let k = this.p.p._inner[this.p.p.count - 1];
                    if (this.ae && !k.f) {
                        this.an.removeAt(e);
                        e--;
                    }
                    k.k++;
                    this.a2(k, f);
                }
            }
            if (e == this.an.count - 1) {
                let l = this.p.p._inner[this.p.p.count - 1];
                e += this.ar(e + 1, d, a, b);
                this.a4(e, d, a);
                this.a5(l);
                l.k++;
            }
            c = f;
        }
    }
    z(a) {
        if (!this.g.isSectionCollapsable) {
            return true;
        }
        return this.ah.containsKey(a) ? this.ah.item(a) : this.ab;
    }
    as(a, b, c, d) {
        let e = 0;
        if (this.ae) {
            let f = this.an._inner[b];
            if (this.g.sectionHeaderDisplayMode == 0) {
                this.a7(b, 0, f, c, d);
                this.p.u();
                e++;
                if (a != null) {
                    let g = this.ay(a);
                    a.a[0] = g;
                    a.b[0] = this.z(g);
                }
            }
            else if (this.g.sectionHeaderDisplayMode == 1) {
                for (let h = 0; h < d.length; h++) {
                    e++;
                    this.a7(b + h, h, f, c, [d[h]]);
                    this.p.u();
                    if (a != null) {
                        let i = this.az(a, h);
                        a.a[h] = i;
                        a.b[h] = this.z(i);
                        if (!a.b[h]) {
                            break;
                        }
                    }
                    else if (!this.ab) {
                        break;
                    }
                }
            }
        }
        return e;
    }
    ar(a, b, c, d) {
        let e = 0;
        if (this.ad) {
            if (this.g.sectionHeaderDisplayMode == 0) {
                this.a6(a, 0, b, c, d);
                e++;
            }
            else if (this.g.sectionHeaderDisplayMode == 1) {
                for (let f = d.length - 1; f >= 0; f--) {
                    if (this.p.p._inner[this.p.p.count - 1].b[f]) {
                        this.a6(a, f, b, c, [d[f]]);
                        a++;
                        e++;
                    }
                }
            }
        }
        return e;
    }
    b() {
        let a = new Array(this.s.k.count + this.t.k.count);
        let b = 0;
        for (let c = 0; c < this.s.k.count; c++) {
            a[b] = this.s.k.item(c).propertyName;
            b++;
        }
        for (let d = 0; d < this.t.k.count; d++) {
            a[b] = this.t.k.item(d).propertyName;
            b++;
        }
        return a;
    }
    c() {
        let a = new Array(this.s.k.count);
        let b = 0;
        for (let c = 0; c < this.s.k.count; c++) {
            a[b] = this.s.k.item(c).propertyName;
            b++;
        }
        return a;
    }
    a4(a, b, c) {
        this.p.t(a);
    }
    bi(a) {
        this.am = new List$1(Array_$type, 0);
        for (let b = 0; b < a.count; b++) {
            this.am.add(a._inner[b]);
        }
    }
    bj(a, b, c) {
        this.p.aa(a, this.g, b, c, this.g.sectionHeaderDisplayMode, this.ab);
    }
    a6(a, b, c, d, e) {
        let f = new DataSourceSpecialRow();
        f.level = b;
        for (let g = 0; g < d.length; g++) {
            f.setValue(d[g], this.g.getItemProperty(c, d[g]));
            if (g < e.length) {
                f.setSectionValue(e[g], this.g.getItemProperty(c, e[g]));
            }
        }
        f.rowType = 2;
        this.an.insert1(a, f);
    }
    a7(a, b, c, d, e) {
        let f = new DataSourceSpecialRow();
        f.level = b;
        for (let g = 0; g < d.length; g++) {
            f.setValue(d[g], this.g.getItemProperty(c, d[g]));
            if (g < e.length) {
                f.setSectionValue(e[g], this.g.getItemProperty(c, e[g]));
            }
        }
        f.rowType = 1;
        f.summaryResults = new Array(this.u.k.count);
        this.an.insert1(a, f);
    }
    ba() {
        this.an.clear();
        if (this.r != null) {
            this.r.notifyClearItems();
        }
    }
    notifySetItem(a, b, c) {
        if (this.aj != null) {
            this.bf(b);
            this.a0(c);
        }
        else {
            this.bg(a, b);
            this.a1(a, c);
        }
        this.bo(a, b, c);
    }
    a1(a, b) {
        if (!this.ag(b)) {
            return;
        }
        let c = this.aq(a);
        this.bb(c, b);
    }
    bb(a, b) {
        this.a8(a, b);
        this.bl(a, b);
        this.bm(a, b);
    }
    a8(a, b) {
        if (this.v) {
            let c = this.p.d(a);
            if (c == null) {
                c = this.p.c();
            }
            if (c.n == a) {
                if (!this.w(c, b, this.an._inner[a])) {
                    c = this.p.d(a - 1);
                    if (c == null) {
                        c = this.p.b();
                        c.n++;
                    }
                }
                else {
                    let d = this.ae ? 1 : 0;
                    a += d + c.h;
                }
            }
            if (!c.f) {
                return;
            }
            c.l++;
            this.p.x(c, 1, 0);
        }
        this.an.insert1(a, b);
        if (this.r != null) {
            this.r.notifyInsertItem(a, b);
        }
    }
    bl(a, b) {
        let c = null;
        if (this.v) {
            c = this.p.d(a);
        }
        else {
            c = this.p.p._inner[0];
        }
        if (c == null) {
            if (this.v && a == 0) {
                c = this.p.b();
            }
            else {
                c = this.p.c();
            }
        }
        if (this.w(c, b, this.an._inner[c.n])) {
            c.k++;
            if (this.af && c.f) {
                let d = this.aw(c, b);
                if (d != -1 && this.r != null) {
                    this.r.notifyInsertItem(d, this.an._inner[d]);
                }
            }
        }
        else {
            let e = this.p.d(a - 1);
            if (e != null && this.w(e, b, this.an._inner[e.n])) {
                e.k++;
                if (this.af && e.f) {
                    let f = this.aw(e, b);
                    if (f != -1 && this.r != null) {
                        this.r.notifyInsertItem(f, this.an._inner[f]);
                    }
                }
            }
            else {
                let g = false;
                if (a <= c.n) {
                    g = true;
                }
                let h = 0;
                let i = null;
                let j = null;
                let k = this.b();
                let l = this.c();
                let m = new SectionData();
                m.n = a;
                m.l = a;
                m.c = l;
                m.d = this.d(l, b);
                m.m = g ? c.m : c.m + 1;
                m.o(this.g.sectionHeaderDisplayMode, this.ab);
                this.p.v(m.m, m);
                if (this.ae) {
                    let n = this.as(m, a, k, l);
                    m.l += n;
                    h += n;
                    i = this.an._inner[a];
                    c.l--;
                }
                if (m.f) {
                    if (this.af) {
                        for (let o = 0; o < this.am.count; o++) {
                            if (this.j.i(b, this.am._inner[o]) == 0) {
                                this.at(m, b, false);
                                h++;
                                break;
                            }
                        }
                    }
                    m.k++;
                }
                else {
                    this.an.removeAt(a + h);
                    m.l--;
                    h--;
                }
                if (this.ad) {
                    let p = this.ar(a + (h - 1), b, k, l);
                    if (p > 1) {
                        m.l += p;
                    }
                    h += p;
                    j = this.an._inner[a + (h - 1)];
                }
                this.p.y(m, h, h);
                if (this.r != null) {
                    if (i != null) {
                        this.r.notifyInsertItem(a, i);
                    }
                    if (j != null) {
                        this.r.notifyInsertItem(a + (h - 1), j);
                    }
                }
            }
        }
    }
    w(a, b, c) {
        if (this.s.k.count == 0) {
            return true;
        }
        if (this.ak.compare(b, c) == 0) {
            return true;
        }
        return false;
    }
    d(a, b) {
        let c = new Array(a.length);
        for (let d = 0; d < c.length; d++) {
            c[d] = this.g.getItemProperty(b, a[d]);
        }
        return c;
    }
    ac(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);
    }
    aq(a) {
        if (this.s.k.count == 0 && this.am.count == 0 && this.k == null && this.h.actualCount == this.an.count) {
            return a;
        }
        let b = 0;
        let c = 0;
        let d = this.an.count;
        while (b < a && c < d) {
            while (c < d) {
                let e = this.an._inner[c];
                let f = false;
                let viewItem_ = e;
                if ((viewItem_.$$isSpecialRow !== undefined)) {
                    f = true;
                }
                if (!f) {
                    break;
                }
                c++;
            }
            let g = this.h.getItemAtIndex(b);
            if (this.ac(g, this.an._inner[c])) {
                c++;
                b++;
            }
            else {
                b++;
            }
        }
        return c;
    }
    bg(a, b) {
        let c = this.aq(a);
        if (c < this.an.count) {
            if (this.ac(b, this.an._inner[c])) {
                this.bc(c, b);
            }
        }
    }
    bc(a, b) {
        this.an.removeAt(a);
        if (this.r != null) {
            this.r.notifyRemoveItem(a, b);
        }
        let c = this.o(a, b);
        this.bn(a, b, c);
    }
    o(a, b) {
        let c = null;
        if (this.v) {
            c = this.p.d(a);
        }
        else {
            c = this.p.p._inner[0];
        }
        if (c != null) {
            c.k--;
            if (c.f) {
                c.l--;
                this.p.x(c, -1, 0);
                if (this.af) {
                    for (let d = 0; d < c.h; d++) {
                        let e = 0;
                        if (this.ae) {
                            e = 1;
                        }
                        let f = this.an._inner[c.n + d + e];
                        let g = null;
                        let item_ = f;
                        if ((item_ != null && item_.$$isSpecialRow !== undefined)) {
                            g = f;
                        }
                        if (g != null) {
                            if (g.targetRow == b) {
                                this.an.removeAt(c.n + d + e);
                                c.l--;
                                c.h--;
                                c.g--;
                                this.p.x(c, -1, -1);
                                if (this.r != null) {
                                    this.r.notifyRemoveItem(c.n + d + e, g);
                                }
                            }
                        }
                    }
                }
            }
            if (this.v && c.k <= 0 && this.x(c)) {
                let h = 0;
                let i = null;
                let j = null;
                if (this.ae) {
                    i = this.an._inner[c.n];
                    for (let k = 0; k < c.b.length; k++) {
                        this.an.removeAt(c.n);
                        h++;
                        if (!c.b[k]) {
                            break;
                        }
                    }
                }
                if (this.ad) {
                    j = this.an._inner[c.l];
                    for (let l = 0; l < c.b.length; l++) {
                        if (!c.b[l]) {
                            break;
                        }
                        this.an.removeAt(c.l);
                        h++;
                        c.l--;
                    }
                }
                this.p.z(c.m);
                this.p.w(c, -h, -h);
                if (this.r != null) {
                    if (i != null) {
                        this.r.notifyRemoveItem(c.n, i);
                    }
                    if (j != null) {
                        this.r.notifyRemoveItem(c.l, j);
                    }
                }
                c = null;
            }
        }
        return c;
    }
    x(a) {
        let b = (a.l - a.n) + 1;
        if (b > a.b.length + 1) {
            return false;
        }
        for (let c = a.n; c <= a.l; c++) {
            if (this.g.getRowType(c) == 0) {
                return false;
            }
        }
        return true;
    }
    a0(a) {
        if (this.ag(a)) {
            let b = this.an.g(a, this.aj);
            if (b < 0) {
                b = ~b;
            }
            this.bb(b, a);
        }
    }
    bd(a) {
        this.am.add(a);
        let b = this.g.indexOfKey(a);
        let c = this.g.getItemAtIndex(b);
        if (b == -1) {
            return;
        }
        if (this.af) {
            let d = this.p.d(b);
            let e = this.aw(d, this.an._inner[b]);
            if (this.r != null) {
                this.r.notifyInsertItem(e, this.an._inner[e]);
            }
        }
    }
    bk(a) {
        if (this.am.remove(a)) {
            let b = this.g.indexOfKey(a);
            let c = this.g.getItemAtIndex(b);
            if (b == -1) {
                return;
            }
            let d = this.p.d(b);
            let e = d.n;
            if (this.ae) {
                e += d.b.length;
            }
            if (this.af) {
                let f = this.m(e, this.an._inner[b], d.h, this.b());
                if (f != null) {
                    d.l--;
                    d.h--;
                    d.g--;
                    this.p.x(d, -1, -1);
                    if (this.r != null) {
                        this.r.notifyRemoveItem(f.a, f.item);
                    }
                }
            }
        }
    }
    m(a, b, c, d) {
        for (let e = a + (c - 1); e >= a; e--) {
            if (typeCast(DataSourceSpecialRow.$, this.an._inner[e]) !== null) {
                let f = this.an._inner[e];
                if (f.rowType == 3) {
                    let g = f.targetRow;
                    if (g == b) {
                        this.an.removeAt(e);
                        return ((() => {
                            let $ret = new RemovedShiftedRowInfo();
                            $ret.item = f;
                            $ret.a = e;
                            return $ret;
                        })());
                    }
                }
            }
        }
        return null;
    }
    bf(a) {
        let b = this.an.g(a, this.aj);
        if (b < 0) {
            b = ~b;
        }
        if (b >= 0) {
            let c = this.an.count;
            let d = 0;
            while (d < c) {
                let e = b - d;
                let f = b + d;
                if (e < 0 && f > c - 1) {
                    break;
                }
                if (e >= 0 && e < c) {
                    if (this.an._inner[e] != null && Base.equalsStatic(this.an._inner[e], a)) {
                        b = e;
                        break;
                    }
                }
                if (f < c) {
                    if (this.an._inner[f] != null && Base.equalsStatic(this.an._inner[f], a)) {
                        b = f;
                        break;
                    }
                }
                d++;
            }
            if (b < 0 || b > c - 1) {
                return;
            }
            let g = this.an._inner[b];
            if (g == null && a == null) {
                this.an.removeAt(b);
                this.q.notifyRemoveItem(b, a);
                let h = this.o(b, a);
                this.bn(b, a, h);
                return;
            }
            if (g == null) {
                return;
            }
            if (Base.equalsStatic(g, a)) {
                this.an.removeAt(b);
                this.q.notifyRemoveItem(b, a);
                let i = this.o(b, a);
                this.bn(b, a, i);
            }
            else {
                this.o(b, a);
            }
        }
        else {
            let j = this.an.count;
            for (let k = 0; k < j; k++) {
                let l = this.an._inner[k];
                if (l == null && a == null) {
                    this.an.removeAt(k);
                    break;
                }
                if (l == null) {
                    continue;
                }
                if (Base.equalsStatic(l, a)) {
                    this.an.removeAt(k);
                    this.q.notifyRemoveItem(k, a);
                    let m = this.o(k, a);
                    this.bn(k, a, m);
                    break;
                }
            }
        }
    }
    ag(a) {
        if (this.k == null) {
            return true;
        }
        return this.k(a);
    }
    notifyClearItems() {
    }
    notifyInsertItem(a, b) {
        if (this.aj != null) {
            this.a0(b);
        }
        else {
            this.a1(a, b);
        }
    }
    notifyRemoveItem(a, b) {
        if (this.aj != null) {
            this.bf(b);
        }
        else {
            this.bg(a, b);
        }
    }
    bh(a, b) {
        let c = this.p.d(a);
        if (c == null) {
            c = this.p.c();
        }
        for (let d = 0; d < c.b.length; d++) {
            if (a == c.n + d) {
                let e = c.a[d];
                if (this.ah.containsKey(e) && this.ah.item(e) != b) {
                    if (b == this.ab) {
                        this.ah.removeItem(e);
                    }
                    else {
                        this.ah.item(e, b);
                    }
                    this.g.queueAutoRefresh();
                }
                else if (b != this.ab) {
                    this.ah.addItem(e, b);
                    this.g.queueAutoRefresh();
                }
            }
        }
    }
    y(a) {
        let b = this.p.d(a);
        if (b == null) {
            b = this.p.c();
        }
        for (let c = 0; c < b.b.length; c++) {
            if (a == b.n + c) {
                return b.b[c];
            }
        }
        return true;
    }
    ay(a) {
        let b = "";
        for (let c = 0; c < a.c.length; c++) {
            b += a.c[c] + ":" + a.d[c];
        }
        return b;
    }
    az(a, b) {
        if (this.g.sectionHeaderDisplayMode == 0) {
            return this.ay(a);
        }
        let c = "";
        for (let d = 0; d < a.c.length; d++) {
            c += a.c[d] + ":" + a.d[d] + ":";
        }
        c += b;
        return c;
    }
    a3(a) {
        if (this.f == 3 || (a != null && this.f == 1) || (a == null && this.f == 2)) {
            return;
        }
        if (a == null && (this.a == null || this.a.length != this.u.k.count)) {
            this.a = new Array(this.u.k.count);
        }
        for (let b = 0; b < this.u.k.count; b++) {
            let c = this.u.k.item(b);
            c.calculator.beginCalculation(this.g, c.propertyName);
        }
    }
    a5(a) {
        if (this.f == 3 || (a != null && this.f == 1) || (a == null && this.f == 2)) {
            return;
        }
        for (let b = 0; b < this.u.k.count; b++) {
            let c = this.u.k.item(b);
            let d = c.calculator.endCalculation();
            if (a != null) {
                a.e[b] = d;
                if (this.g.sectionHeaderDisplayMode == 1) {
                    for (let e = 0; e < a.b.length; e++) {
                        let f = this.an._inner[a.n + e];
                        if (f != null) {
                            f.summaryResults[b] = d;
                        }
                        if (!a.b[e]) {
                            break;
                        }
                    }
                }
                else {
                    let g = this.an._inner[a.n];
                    if (g != null) {
                        g.summaryResults[b] = d;
                    }
                }
            }
            else {
                this.a[b] = d;
            }
        }
    }
    a2(a, b) {
        if (this.f == 3 || (a != null && this.f == 1) || (a == null && this.f == 2)) {
            return;
        }
        if (b != null) {
            for (let c = 0; c < this.u.k.count; c++) {
                let d = this.u.k.item(c);
                d.calculator.aggregate(b);
            }
        }
    }
    bm(a, b) {
        let c = this.n(a);
        if (c == null) {
            c = this.p.c();
        }
        let d = typeCast(DataSourceSpecialRow.$, this.an._inner[c.n]);
        let e = false;
        for (let f = 0; f < this.u.k.count; f++) {
            let g = this.u.k.item(f);
            this.a[f] = g.calculator.itemAdded(b, this.a[f], this.g.actualCount);
            c.e[f] = g.calculator.itemAdded(b, c.e[f], c.k);
            if (d != null) {
                d.summaryResults[f] = c.e[f];
            }
            if (g.calculator.isSummaryDirty) {
                e = true;
            }
        }
        if (e) {
            this.g.queueAutoRefresh();
        }
    }
    bn(a, b, c) {
        let d = null;
        if (c != null) {
            d = typeCast(DataSourceSpecialRow.$, this.an._inner[c.n]);
        }
        let e = false;
        for (let f = 0; f < this.u.k.count; f++) {
            let g = this.u.k.item(f);
            this.a[f] = g.calculator.itemRemoved(b, this.a[f], this.g.actualCount);
            if (c != null) {
                c.e[f] = g.calculator.itemRemoved(b, c.e[f], c.k);
                if (d != null) {
                    d.summaryResults[f] = c.e[f];
                }
            }
            if (g.calculator.isSummaryDirty) {
                e = true;
            }
        }
        if (e) {
            this.g.queueAutoRefresh();
        }
    }
    bo(a, b, c) {
        let d = this.n(a);
        if (d == null) {
            d = this.p.c();
        }
        let e = typeCast(DataSourceSpecialRow.$, this.an._inner[d.n]);
        let f = false;
        for (let g = 0; g < this.u.k.count; g++) {
            let h = this.u.k.item(g);
            this.a[g] = h.calculator.itemChanged(c, b, this.a[g], this.g.actualCount);
            d.e[g] = h.calculator.itemChanged(c, b, d.e[g], d.k);
            if (e != null) {
                e.summaryResults[g] = d.e[g];
            }
            if (h.calculator.isSummaryDirty) {
                f = true;
            }
        }
        if (f) {
            this.g.queueAutoRefresh();
        }
    }
}
RearrangedListView.$t = markType(RearrangedListView, 'RearrangedListView', Base.$, [ISupportsDataChangeNotifications_$type]);
