/*
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 { BaseDataSource } from "./BaseDataSource";
import { IPageCandidatesSink_$type } from "./IPageCandidatesSink";
import { PagePredictionEngine } from "./PagePredictionEngine";
import { LRUCache$2 } from "./LRUCache$2";
import { Base, runOn, Array_$type, Number_$type, typeCast, fromEnum, typeGetValue, String_$type, Boolean_$type, markType } from "./type";
import { IDataSourcePage_$type } from "./IDataSourcePage";
import { Dictionary$2 } from "./Dictionary$2";
import { SectionMap } from "./SectionMap";
import { DataSourceExecutionContext } from "./DataSourceExecutionContext";
import { SectionData } from "./SectionData";
import { List$1 } from "./List$1";
import { DataSourceSpecialRow } from "./DataSourceSpecialRow";
import { DataSourcePropertiesComparer } from "./DataSourcePropertiesComparer";
import { truncate, intDivide } from "./number";
/**
 * @hidden
 */
export let VirtualDataSource = /*@__PURE__*/ (() => {
    class VirtualDataSource extends BaseDataSource {
        constructor() {
            super();
            this.cg = null;
            this.cx = false;
            this.dj = 0;
            this.cr = null;
            this.ck = null;
            this.cj = null;
            this.di = 50;
            this.dh = 200;
            this.actualPageSizePopulated = false;
            this.c3 = 50;
            this.cv = false;
            this.co = null;
            this.cu = new LRUCache$2(Base.$, IDataSourcePage_$type, 0, 200);
            this.c1 = new Dictionary$2(Base.$, Array_$type, 0);
            this.c2 = new Dictionary$2(Number_$type, Number_$type, 0);
            this.cw = false;
            this.ce = null;
            this.ch = null;
            this.ct = new SectionMap();
            this.cf = null;
            this.db = -1;
            this.c4 = -1;
            this.dd = -1;
            this.c6 = -1;
            this.de = -1;
            this.c7 = -1;
            this.dc = -1;
            this.c5 = -1;
            this.dg = -1;
            this.df = -1;
            this.c9 = -1;
            this.c8 = -1;
            this.da = -1;
            this.c0 = new Dictionary$2(String_$type, Boolean_$type, 0);
            this.cr = new PagePredictionEngine();
            this.cr.e = this;
            this.cr.ag = this.actualPageSize;
            this.cr.f = this.ct;
            this.executionContext = new DataSourceExecutionContext();
            this.cr.b = this.executionContext;
        }
        get_isSectionCollapsable() {
            if (!this.isSectionContentVisible) {
                return true;
            }
            return super.get_isSectionCollapsable();
        }
        set_isSectionCollapsable(a) {
            super.set_isSectionCollapsable(a);
        }
        get_isSectionExpandedDefault() {
            if (!this.isSectionContentVisible) {
                return false;
            }
            if (this.isSectionCollapsable) {
                return super.get_isSectionExpandedDefault();
            }
            return true;
        }
        set_isSectionExpandedDefault(a) {
            super.set_isSectionExpandedDefault(a);
        }
        get_actualBaseDataProvider() {
            return this.actualDataProvider;
        }
        get actualBaseDataProvider() {
            return this.get_actualBaseDataProvider();
        }
        get dataProvider() {
            return this.ck;
        }
        set dataProvider(a) {
            let b = this.ck;
            this.ck = a;
            if (b != this.ck) {
                this.onPropertyUpdated("DataProvider", b, this.ck);
            }
        }
        get actualDataProvider() {
            if (this.cj == null) {
                this.actualDataProvider = this.resolveDataProvider();
            }
            return this.cj;
        }
        set actualDataProvider(a) {
            let b = this.cj;
            this.cj = a;
            if (b != this.cj) {
                this.onPropertyUpdated("ActualDataProvider", b, this.cj);
            }
        }
        get pageSizeRequested() {
            return this.di;
        }
        set pageSizeRequested(a) {
            let b = this.di;
            this.di = a;
            if (b != this.di) {
                this.onPropertyUpdated("PageSizeRequested", b, this.di);
            }
        }
        resetCache() {
            if (this.cp != null) {
                this.cp.resetCache();
            }
            this.resetCacheOverride();
        }
        resetCacheOverride() {
            this.cu.i();
        }
        get maxCachedPages() {
            return this.dh;
        }
        set maxCachedPages(a) {
            let b = this.dh;
            this.dh = a;
            if (b != this.dh) {
                this.onPropertyUpdated("MaxCachedPages", b, this.dh);
            }
        }
        get actualPageSize() {
            return this.c3;
        }
        set actualPageSize(a) {
            let b = this.c3;
            this.c3 = a;
            if (b != this.c3) {
                this.onPropertyUpdated("ActualPageSize", b, this.c3);
            }
        }
        get_isSortingSupported() {
            if (this.externalDataSource != null && !this.cv) {
                this.cv = true;
                let a = this.externalDataSource.isSortingSupportedOverride;
                this.cv = false;
                return a;
            }
            return false;
        }
        get_isFilteringSupported() {
            if (this.externalDataSource != null && !this.cv) {
                this.cv = true;
                let a = this.externalDataSource.isFilteringSupportedOverride;
                this.cv = false;
                return a;
            }
            return false;
        }
        get_isGroupingSupported() {
            if (this.externalDataSource != null && !this.cv) {
                this.cv = true;
                let a = this.externalDataSource.isGroupingSupportedOverride;
                this.cv = false;
                return a;
            }
            return false;
        }
        get cp() {
            return this.co;
        }
        set cp(a) {
            this.co = a;
            this.actualDataProvider = this.resolveDataProvider();
        }
        resolveDataProvider() {
            if (this.cp == null) {
                return null;
            }
            return this.cp.resolveDataProvider();
        }
        propertyUpdatedOverride(a, b, c) {
            super.propertyUpdatedOverride(a, b, c);
            switch (a) {
                case "DataProvider":
                    this.actualDataProvider = this.dataProvider;
                    this.queueAutoRefresh();
                    break;
                case "ExecutionContext":
                    this.cr.b = this.executionContext;
                    break;
                case "ActualDataProvider":
                    this.actualDataProvider.pageSizeRequested = this.pageSizeRequested;
                    this.actualDataProvider.pageLoaded = runOn(this, this.d0);
                    this.queueAutoRefresh();
                    break;
                case "PageSizeRequested":
                    this.actualPageSize = this.pageSizeRequested;
                    if (this.actualDataProvider != null) {
                        this.actualDataProvider.pageSizeRequested = this.pageSizeRequested;
                    }
                    this.queueAutoRefresh();
                    break;
                case "ActualPageSize":
                    this.cr.ag = this.actualPageSize;
                    this.queueAutoRefresh();
                    break;
                case "FirstVisibleIndexRequested":
                    this.cr.aa = this.firstVisibleIndexRequested;
                    break;
                case "LastVisibleIndexRequested":
                    this.cr.ae = this.lastVisibleIndexRequested;
                    break;
                case "ActualCount":
                    if (this.actualDataProvider != null && !this.ct.q) {
                        this.cr.ab = this.actualDataProvider.actualCount;
                    }
                    else {
                        this.cr.ab = this.actualCount;
                    }
                    this.queueAutoRefresh();
                    break;
                case "MaxCachedPages":
                    this.cu.h = this.maxCachedPages;
                    break;
            }
        }
        dm(a) {
            if (this.aj && this.ct.q) {
                let b = this.cs(a);
                if (b == null) {
                    b = this.ct.d();
                }
                return a - b.u;
            }
            return a;
        }
        d0(a, b, c) {
            let d = this.executionContext;
            if (d != null) {
                d.execute(() => this.d6(a, b, c));
            }
            else {
                this.d6(a, b, c);
            }
        }
        d6(a, b, c) {
            if (a == null) {
                b = this.resolveFullCount(b);
                if (this.actualCount != b) {
                    this.actualCount = b;
                }
                return;
            }
            if (c != this.actualPageSize && !this.actualPageSizePopulated) {
                this.actualPageSize = c;
            }
            this.actualPageSizePopulated = true;
            let d = a.pageIndex();
            this.d1(d);
            this.cu.item(d, a);
            let e = a.schema();
            if (e != null) {
                this.actualSchema = e;
            }
            let f = a.getSummaryInformation();
            if (this.ch == null && f != null) {
                this.ch = f;
                for (let g = 0; g < this.summaryDescriptions.k.count; g++) {
                    this.ch[g].summaryIndex = g;
                }
                let h = SectionData.s(this.ch);
                this.dj = h.count;
            }
            let i = a.getGroupInformation();
            if (this.ce == null && i != null) {
                this.ce = i;
                this.d5();
                this.cx = false;
            }
            b = this.resolveFullCount(b);
            if (this.actualCount != b) {
                this.actualCount = b;
            }
            this.d4(a);
        }
        resolveFullCount(a) {
            if (this.ce != null) {
                return this.ct.u + this.dj;
            }
            return a + this.dj;
        }
        d5() {
            let a = 0;
            let b = 0;
            let c = 0;
            if (this.shouldEmitSectionHeaders) {
                switch (this.sectionHeaderDisplayMode) {
                    case 0:
                        c++;
                        break;
                    case 1:
                        c += this.groupDescriptions.k.count;
                        break;
                }
            }
            if (this.shouldEmitSectionFooters) {
                c++;
            }
            let d = this.shouldEmitSectionHeaders;
            let e = this.shouldEmitSectionFooters;
            for (let f = 0; f < this.ce.length; f++) {
                let g = new SectionData();
                if (d) {
                    switch (this.sectionHeaderDisplayMode) {
                        case 0:
                            b++;
                            break;
                        case 1:
                            b += this.groupDescriptions.k.count;
                            break;
                    }
                }
                let h = this.ce[f].endIndex - this.ce[f].startIndex;
                g.af = a;
                g.ae = f;
                g.d = [h + 1];
                g.ad = a + h;
                g.ad += c;
                g.u = b;
                g.e = this.ce[f].groupKeyProperties;
                g.f = this.ce[f].groupKeyValues;
                g.ai(this.sectionHeaderDisplayMode, this.isSectionExpandedDefault);
                if (e) {
                    g.v = g.c.length;
                }
                let i = 0;
                g.i = this.ce[f].summaryResults;
                if (g.i != null) {
                    for (let j = 0; j < g.i.length; j++) {
                        g.i[j].summaryIndex = j;
                    }
                    i = SectionData.s(g.i).count;
                }
                if (this.includeSummaryRowsInSection) {
                    if (this.isSectionSummaryRowsAtBottom) {
                        g.ag = i;
                    }
                    else {
                        g.ah = i;
                        g.u += i;
                    }
                    b += i;
                    g.ad += i;
                }
                if (e) {
                    b++;
                }
                for (let k = 0; k < g.c.length; k++) {
                    let l = this.dw(g, k);
                    g.a[k] = l;
                    if (this.c0.containsKey(l)) {
                        g.c[k] = this.c0.item(l);
                    }
                    else {
                        g.c[k] = this.isSectionExpandedDefault;
                    }
                    if (!g.c[k]) {
                        let m = g.c.length - 1 - k;
                        g.ad -= m;
                        b -= m;
                        if (e) {
                            b--;
                            g.v--;
                        }
                        k += m;
                    }
                }
                if (!g.q) {
                    g.ad -= g.d[0] + i;
                    b -= g.d[0] + i;
                }
                a = g.ad + 1;
                this.ct.t.add(g);
            }
        }
        d4(a) {
            if (this.updateNotifier != null) {
                let b = a.pageIndex() * this.actualPageSize;
                if (this.actualDataProvider != null) {
                    if (b > this.actualDataProvider.actualCount) {
                        return;
                    }
                }
                let c = this.dl(b);
                let d = this.dl(b + a.count() - 1);
                if (c > 0 && this.getRowType(c - 1) == 1) {
                    c--;
                }
                if (this.actualCount == 0 && a.count() == 0) {
                    this.onClearItems();
                }
                else {
                    this.updateNotifier.rangeActualized(c, d);
                }
            }
        }
        dl(a) {
            if (this.aj && this.ct.q) {
                let b = this.ct.g(a);
                if (b == null) {
                    b = this.ct.d();
                }
                if (!b.q) {
                    return b.af;
                }
                return a + b.u;
            }
            return a;
        }
        d2(a) {
            a();
        }
        get_isVirtual() {
            return true;
        }
        isPlaceholderItem(a) {
            let b = this.ci(a);
            let c = b[0];
            if (!this.cu.d(c)) {
                if (b[1] == -1) {
                    return false;
                }
                return true;
            }
            return false;
        }
        getItemAtIndex(a) {
            if (a >= this.actualCount - this.dj) {
                return this.dr(a);
            }
            let b = this.ci(a);
            let c = b[0];
            if (!this.cu.d(c)) {
                if (b[1] == -1) {
                    return this.dr(a);
                }
                return null;
            }
            let d = this.cu.item(c);
            let e = b[1];
            if (e == -1) {
                return this.dr(a);
            }
            return d.getItemAtIndex(e);
        }
        dr(a) {
            if (a >= this.actualCount - this.dj) {
                let b = new DataSourceSpecialRow();
                b.rowType = 4;
                b.level = 0;
                let c = a - (this.actualCount - this.dj);
                let d = SectionData.s(this.ch);
                let e = new Array(d._inner[c].count);
                d._inner[c].values.copyTo(e, 0);
                b.summaryResults = e;
                return b;
            }
            let f = this.cs(a);
            if (f != null) {
                let g = f.k(a);
                if (g == 1 || g == 2) {
                    let h = new DataSourceSpecialRow();
                    h.rowType = g;
                    h.summaryResults = f.i;
                    for (let i = 0; i < this.groupDescriptions.k.count; i++) {
                        h.setSectionValue(this.groupDescriptions.k.item(i).propertyName, f.f[i]);
                        h.setValue(this.groupDescriptions.k.item(i).propertyName, f.f[i]);
                    }
                    h.level = g == 1 ? a - f.af : (f.v - 1) - (a - (f.ad - f.v + 1));
                    return h;
                }
                else if (g == 5) {
                    let j = new DataSourceSpecialRow();
                    j.rowType = 5;
                    j.level = f.c.length;
                    let k = f.y(a);
                    let l = SectionData.s(f.i);
                    let m = new Array(l._inner[k].count);
                    l._inner[k].values.copyTo(m, 0);
                    j.summaryResults = m;
                    return j;
                }
            }
            return null;
        }
        ci(a) {
            if (this.aj && this.ct.q) {
                let b = false;
                let c = this.cs(a);
                if (c == null) {
                    c = this.ct.d();
                    if (this.ch.length > 0 && a > c.ad) {
                        b = true;
                    }
                }
                let d = c.af;
                if (a >= d && a < d + c.c.length && this.shouldEmitSectionHeaders) {
                    b = true;
                }
                if (a - (d + c.c.length - 1) <= c.aa + c.ah) {
                    b = true;
                }
                if (this.shouldEmitSectionFooters) {
                    if (a <= c.ad && a >= c.ad - c.c.length - c.ag) {
                        b = true;
                    }
                }
                else if (c.ag > 0) {
                    if (a > c.ad - c.ag && a <= c.ad) {
                        b = true;
                    }
                }
                let e = a - c.u;
                let f = truncate(Math.floor(e / this.actualPageSize));
                let g = e % this.actualPageSize;
                if (b) {
                    g = -1;
                }
                let h = new Array(2);
                h[0] = f;
                h[1] = g;
                return h;
            }
            else {
                let i = truncate(Math.floor(a / this.actualPageSize));
                let j = a % this.actualPageSize;
                let k = new Array(2);
                k[0] = i;
                k[1] = j;
                return k;
            }
        }
        cs(a) {
            return this.ct.e(a);
        }
        getItemPropertyAtIndex(a, b) {
            if (a > (this.actualCount - 1) - this.dj) {
                return this.ds(a, b);
            }
            let c = this.ci(a);
            let d = c[0];
            if (!this.cu.d(d)) {
                if (c[1] == -1) {
                    return this.ds(a, b);
                }
                return null;
            }
            let e = this.cu.item(d);
            let f = c[1];
            if (f == -1) {
                return this.ds(a, b);
            }
            return e.getItemValueAtIndex(f, b);
        }
        ds(a, b) {
            let c = this.dr(a);
            if (typeCast(DataSourceSpecialRow.$, c) !== null) {
                return c.getValue(b);
            }
            return null;
        }
        d3(a) {
            if (!this.c2.containsKey(a)) {
                this.c2.addItem(a, 1);
            }
            else {
                this.c2.item(a, this.c2.item(a) + 1);
            }
        }
        d1(a) {
            if (this.c2.containsKey(a)) {
                this.c2.item(a, this.c2.item(a) - 1);
                if (this.c2.item(a) <= 0) {
                    this.c2.removeItem(a);
                    if (this.actualDataProvider != null) {
                        this.actualDataProvider.removePageRequest(a);
                    }
                }
            }
        }
        addCandidate(a, b) {
            let c = false;
            if (!this.c1.containsKey(a)) {
                let d = new List$1(Number_$type, 0);
                let e = this.transformPage(a);
                for (let f = 0; f < e.length; f++) {
                    let g = e[f];
                    if (!this.cu.d(g)) {
                        d.add(g);
                        this.d3(g);
                        let h = this.c2.item(g);
                        if (h == 1 && this.actualDataProvider != null) {
                            this.actualDataProvider.addPageRequest(g, b);
                        }
                        c = true;
                    }
                }
                if (d.count > 0) {
                    this.c1.addItem(a, d.toArray());
                }
            }
            return c;
        }
        removeCandidate(a) {
            if (this.c1.containsKey(a)) {
                for (let b = 0; b < this.c1.item(a).length; b++) {
                    let c = this.c1.item(a)[b];
                    this.d1(c);
                }
                this.c1.removeItem(a);
            }
        }
        transformPage(a) {
            let b = [a];
            if (this.aj && this.ct.q) {
                let c = a * this.actualPageSize;
                let d = c + this.actualPageSize - 1;
                let e = this.cs(c);
                let f = new List$1(Number_$type, 0);
                for (let g = c; g <= d; g++) {
                    if (e == null) {
                        break;
                    }
                    if (g > e.ad) {
                        if (e.ae < this.ct.t.count - 1) {
                            e = this.ct.t._inner[e.ae + 1];
                        }
                        else {
                            break;
                        }
                    }
                    if (!e.q || (g >= e.af && g <= e.af + (e.c.length - 1) + e.aa)) {
                        continue;
                    }
                    let h = g - e.u;
                    let i = intDivide(h, this.actualPageSize);
                    if (!f.contains(i)) {
                        f.add(i);
                    }
                }
                b = f.toArray();
            }
            return b;
        }
        getUnrealizedCount() {
            let a = this.cu.g * this.actualPageSize;
            let b = this.actualCount - a;
            return b;
        }
        onSetItemOverride(a, b, c) {
            super.onSetItemOverride(a, b, c);
            let d = this.ci(a);
            let e = d[0];
            if (this.cu.d(e)) {
                this.cu.j(e);
            }
        }
        refreshInternalOverride() {
            super.refreshInternalOverride();
            this.actualPageSizePopulated = false;
            let a = this.actualCount != 0;
            this.cw = true;
            if (!this.cx) {
                this.resetCache();
                if (a) {
                    this.onClearItems();
                }
                this.ce = null;
                this.ch = null;
                this.dj = 0;
                this.ct.v();
            }
            else {
                this.cx = false;
                if (a) {
                    this.onClearItems();
                }
            }
            this.d7();
            this.cr.au();
            this.cw = false;
        }
        d7() {
            if (this.actualDataProvider != null) {
                for (let a of fromEnum(this.c1.values)) {
                    for (let c = 0; c < a.length; c++) {
                        let b = a[c];
                        this.actualDataProvider.addPageRequest(b, 1);
                    }
                }
            }
        }
        onClearItemsOverride() {
            super.onClearItemsOverride();
            if (!this.cw) {
                this.queueAutoRefresh();
            }
        }
        onInsertItemOverride(a, b) {
            super.onInsertItemOverride(a, b);
            this.queueAutoRefresh();
        }
        onRemoveItemOverride(a, b) {
            super.onRemoveItemOverride(a, b);
            this.queueAutoRefresh();
        }
        get_isItemIndexLookupSupported() {
            return true;
        }
        get_isKeyIndexLookupSupported() {
            return true;
        }
        indexOfItem(a) {
            let b = this.cu.b;
            let c = b.o;
            let d = b.q;
            let e = d.count;
            let f = b.p;
            for (let g = 0; g < e; g++) {
                if (f._inner[g]) {
                    continue;
                }
                let h = d._inner[g].b;
                let i = h.count();
                for (let j = 0; j < i; j++) {
                    if (this.cz(h.getItemAtIndex(j), a)) {
                        let k = typeGetValue(c._inner[g]);
                        let l = k * this.actualPageSize;
                        return l + j;
                    }
                }
            }
            if (this.actualDataProvider != null && this.actualDataProvider.isItemIndexLookupSupported) {
                return this.actualDataProvider.indexOfItem(a);
            }
            return -1;
        }
        cz(a, b) {
            if (a == null && b == null) {
                return true;
            }
            if (a == null || b == null) {
                return false;
            }
            return Base.equalsStatic(a, b);
        }
        indexOfKey(a) {
            let b = this.actualPrimaryKey;
            if (b == null || b.length < 1 || this.actualBaseDataProvider == null) {
                return -1;
            }
            this.ensureComparables(this.actualSchema);
            let c = this.cq();
            if (this.aj && this.shouldEmitSectionHeaders && !this.isSectionContentVisible && this.isSectionHeaderNormalRow) {
                if (this.ct.t.count > 0) {
                    for (let d = 0; d < this.ct.t.count; d++) {
                        let e = this.ct.t._inner[d];
                        let f = new DataSourceSpecialRow();
                        for (let g = 0; g < e.e.length; g++) {
                            let h = e.e[g];
                            let i = e.f[g];
                            f.setSectionValue(h, i);
                        }
                        if (c.i(f, a) == 0) {
                            return d;
                        }
                    }
                }
            }
            let j = this.cu.b;
            let k = j.o;
            let l = j.q;
            let m = l.count;
            let n = j.p;
            for (let o = 0; o < m; o++) {
                if (n._inner[o]) {
                    continue;
                }
                let p = l._inner[o].b;
                let q = p.count();
                for (let r = 0; r < q; r++) {
                    if (c.i(p.getItemAtIndex(r), a) == 0) {
                        let s = typeGetValue(k._inner[o]);
                        let t = s * this.actualPageSize;
                        return t + r;
                    }
                }
            }
            if (this.actualDataProvider != null && this.actualDataProvider.isKeyIndexLookupSupported) {
                return this.actualDataProvider.indexOfKey(a);
            }
            return -1;
        }
        cq() {
            let a = new Array(this.actualPrimaryKey.length);
            for (let b = 0; b < a.length; b++) {
                a[b] = 0;
            }
            return new DataSourcePropertiesComparer(this.actualPrimaryKey, a, this.cg, this);
        }
        getStickyRowPriority(a) {
            let b = this.getRowType(a);
            switch (b) {
                case 1: return 100 - this.getRowLevel(a);
                case 2: return 99 - this.getRowLevel(a);
                case 3:
                case 5: return 2;
                case 4: return 3;
            }
            return 1;
        }
        unpinRow(a) {
            super.unpinRow(a);
        }
        pinRow(a) {
            super.pinRow(a);
        }
        isRowPinned(a) {
            return super.isRowPinned(a);
        }
        getStickyRowsInRange(a, b) {
            if ((this.groupDescriptions == null || this.groupDescriptions.k.count == 0) && (this.summaryDescriptions == null || this.summaryDescriptions.k.count == 0)) {
                return null;
            }
            let c = this.cs(a);
            let d = this.cs(b);
            if (this.ct.t.count > 0) {
                if (this.ct.t.count == 1) {
                    c = this.ct.t._inner[0];
                    d = this.ct.t._inner[0];
                }
                else {
                    c = this.ct.e(a);
                    d = this.ct.e(b);
                    if (b >= this.actualCount - this.dj) {
                        d = this.ct.d();
                    }
                }
            }
            else if (this.dj > 0) {
                let e = new List$1(Number_$type, 0);
                for (let f = this.actualCount - this.dj; f < this.actualCount; f++) {
                    e.add(f);
                }
                return e.toArray();
            }
            if (c == null || d == null) {
                return null;
            }
            if (c.ae == this.db && c.aa == this.dd && c.af == this.de && c.ad == this.dc && c.ah == this.dg && c.ag == this.df && d.ae == this.c4 && d.aa == this.c6 && d.af == this.c7 && d.ad == this.c5 && d.ah == this.c9 && d.ag == this.c8 && this.dj == this.da) {
                return this.cf;
            }
            this.db = c.ae;
            this.c4 = d.ae;
            this.dd = c.aa;
            this.c6 = d.aa;
            this.de = c.af;
            this.c7 = d.af;
            this.dc = c.ad;
            this.c5 = d.ad;
            this.c9 = d.ah;
            this.c8 = d.ag;
            this.dg = c.ah;
            this.df = c.ag;
            this.da = this.dj;
            let g = new List$1(Number_$type, 0);
            for (let h = c.ae; h <= d.ae; h++) {
                let i = this.ct.t._inner[h];
                let j = i.c.length;
                if (this.shouldEmitSectionHeaders && this.aj) {
                    for (let k = 0; k < i.c.length; k++) {
                        g.add(i.af + k);
                        if (!i.c[k]) {
                            break;
                        }
                    }
                }
                if (i.q) {
                    for (let l = 0; l < i.ah; l++) {
                        g.add(i.af + l + j);
                    }
                    if (this.shouldEmitShiftedRows) {
                        for (let m = 0; m < i.aa; m++) {
                            g.add(i.af + m + j);
                        }
                    }
                    for (let n = i.ag - 1; n >= 0; n--) {
                        if (this.shouldEmitSectionFooters) {
                            g.add(i.ad - j - n);
                        }
                        else {
                            g.add(i.ad - n);
                        }
                    }
                }
                if (this.shouldEmitSectionFooters && this.aj) {
                    for (let o = i.c.length - 1; o >= 0; o--) {
                        if (!i.c[o]) {
                            break;
                        }
                        g.add(i.ad - o);
                    }
                }
            }
            for (let p = this.actualCount - this.dj; p < this.actualCount; p++) {
                g.add(p);
            }
            this.cf = g.toArray();
            return this.cf;
        }
        isExclusivelySticky(a) {
            return this.getRowType(a) == 1 || this.getRowType(a) == 2;
        }
        getRowType(a) {
            if (a < 0) {
                return 0;
            }
            let b = this.getItemAtIndex(a);
            let item_ = b;
            if ((item_ != null && item_.$$isSpecialRow !== undefined)) {
                let c = b.rowType;
                if (this.isSectionHeaderNormalRow && c == 1) {
                    return 0;
                }
                return c;
            }
            return 0;
        }
        getIsRowExpandedAtIndex(a) {
            let b = this.ct.e(a);
            if (b == null) {
                b = this.ct.d();
            }
            for (let c = 0; c < b.c.length; c++) {
                if (a == b.af + c) {
                    return b.c[c];
                }
            }
            return super.getIsRowExpandedAtIndex(a);
        }
        setIsRowExpandedAtIndex(a, b) {
            let c = this.ct.e(a);
            if (c == null) {
                c = this.ct.d();
            }
            for (let d = 0; d < c.c.length; d++) {
                if (a == c.af + d) {
                    let e = false;
                    let f = c.a[d];
                    if (this.c0.containsKey(f) && this.c0.item(f) != b) {
                        let g = this.c0.item(f);
                        if (b == this.isSectionExpandedDefault) {
                            this.c0.removeItem(f);
                        }
                        else {
                            this.c0.item(f, b);
                        }
                        e = true;
                        this.onRowExpansionChanged(a, g, b);
                    }
                    else if (b != this.isSectionExpandedDefault) {
                        this.c0.addItem(f, b);
                        e = true;
                        this.onRowExpansionChanged(a, this.isSectionExpandedDefault, b);
                    }
                    if (e) {
                        this.ct.v();
                        this.d5();
                        this.cx = true;
                        if (this.actualCount != this.ct.u) {
                            this.actualCount = this.ct.u + this.dj;
                        }
                        else {
                            this.queueAutoRefresh();
                        }
                    }
                    break;
                }
            }
        }
        getRowLevel(a) {
            if (a < 0) {
                return 0;
            }
            let b = this.getItemAtIndex(a);
            let item_ = b;
            if ((item_ != null && item_.$$isSpecialRow !== undefined)) {
                return b.level;
            }
            if (this.isGroupingSupported) {
                if (this.sectionHeaderDisplayMode == 1) {
                    return this.groupDescriptions.k.count;
                }
                else if (this.groupDescriptions.k.count > 0) {
                    return 1;
                }
            }
            return 0;
        }
        getRootSummaryRowCount() {
            return this.dj;
        }
        dv(a) {
            let b = "";
            for (let c = 0; c < a.e.length; c++) {
                b += a.e[c] + ":" + a.f[c];
            }
            return b;
        }
        dw(a, b) {
            if (this.sectionHeaderDisplayMode == 0) {
                return this.dv(a);
            }
            let c = "";
            for (let d = 0; d < a.e.length; d++) {
                c += a.e[d] + ":" + a.f[d] + ":";
            }
            c += b;
            return c;
        }
        getRootSummaryResults() {
            return this.ch;
        }
        getSectionSummaryResults(a) {
            if (this.ct.q && a >= 0 && a < this.ct.t.count) {
                if (this.ct.t._inner[a].i != null) {
                    let b = new Array(1);
                    b[0] = this.ct.t._inner[a].i;
                    return b;
                }
            }
            return null;
        }
        clone() {
            return null;
        }
        cloneProperties(a) {
            super.cloneProperties(a);
            let b = typeCast(VirtualDataSource.$, a);
            if (b != null) {
                b.pageSizeRequested = this.pageSizeRequested;
                b.maxCachedPages = this.maxCachedPages;
            }
        }
    }
    VirtualDataSource.$t = /*@__PURE__*/ markType(VirtualDataSource, 'VirtualDataSource', BaseDataSource.$, [IPageCandidatesSink_$type]);
    return VirtualDataSource;
})();
//# sourceMappingURL=VirtualDataSource.js.map
