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