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