/*
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 { __extends, __values } from "tslib";
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
 */
var VirtualDataSource = /** @class */ (function (_super) {
    __extends(VirtualDataSource, _super);
    function VirtualDataSource() {
        var _this = _super.call(this) || this;
        _this.b6 = null;
        _this.cn = false;
        _this.ch = null;
        _this.ca = null;
        _this.b9 = null;
        _this.c3 = 50;
        _this.c2 = 200;
        _this.actualPageSizePopulated = false;
        _this.ct = 50;
        _this.cl = false;
        _this.ce = null;
        _this.ck = new LRUCache$2(Base.$, IDataSourcePage_$type, 0, 200);
        _this.cr = new Dictionary$2(Base.$, Array_$type, 0);
        _this.cs = new Dictionary$2(Number_$type, Number_$type, 0);
        _this.cm = false;
        _this.b4 = null;
        _this.b7 = null;
        _this.cj = new SectionMap();
        _this.b5 = null;
        _this.cy = -1;
        _this.cu = -1;
        _this.c0 = -1;
        _this.cw = -1;
        _this.c1 = -1;
        _this.cx = -1;
        _this.cz = -1;
        _this.cv = -1;
        _this.cq = new Dictionary$2(String_$type, Boolean_$type, 0);
        _this.ch = new PagePredictionEngine();
        _this.ch.e = _this;
        _this.ch.ag = _this.actualPageSize;
        _this.ch.f = _this.cj;
        _this.executionContext = new DataSourceExecutionContext();
        _this.ch.b = _this.executionContext;
        return _this;
    }
    VirtualDataSource.prototype.get_actualBaseDataProvider = function () {
        return this.actualDataProvider;
    };
    Object.defineProperty(VirtualDataSource.prototype, "actualBaseDataProvider", {
        get: function () {
            return this.get_actualBaseDataProvider();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(VirtualDataSource.prototype, "dataProvider", {
        get: function () {
            return this.ca;
        },
        set: function (a) {
            var b = this.ca;
            this.ca = a;
            if (b != this.ca) {
                this.onPropertyUpdated("DataProvider", b, this.ca);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(VirtualDataSource.prototype, "actualDataProvider", {
        get: function () {
            if (this.b9 == null) {
                this.actualDataProvider = this.resolveDataProvider();
            }
            return this.b9;
        },
        set: function (a) {
            var b = this.b9;
            this.b9 = a;
            if (b != this.b9) {
                this.onPropertyUpdated("ActualDataProvider", b, this.b9);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(VirtualDataSource.prototype, "pageSizeRequested", {
        get: function () {
            return this.c3;
        },
        set: function (a) {
            var b = this.c3;
            this.c3 = a;
            if (b != this.c3) {
                this.onPropertyUpdated("PageSizeRequested", b, this.c3);
            }
        },
        enumerable: true,
        configurable: true
    });
    VirtualDataSource.prototype.resetCache = function () {
        if (this.cf != null) {
            this.cf.resetCache();
        }
        this.resetCacheOverride();
    };
    VirtualDataSource.prototype.resetCacheOverride = function () {
        this.ck.i();
    };
    Object.defineProperty(VirtualDataSource.prototype, "maxCachedPages", {
        get: function () {
            return this.c2;
        },
        set: function (a) {
            var b = this.c2;
            this.c2 = a;
            if (b != this.c2) {
                this.onPropertyUpdated("MaxCachedPages", b, this.c2);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(VirtualDataSource.prototype, "actualPageSize", {
        get: function () {
            return this.ct;
        },
        set: function (a) {
            var b = this.ct;
            this.ct = a;
            if (b != this.ct) {
                this.onPropertyUpdated("ActualPageSize", b, this.ct);
            }
        },
        enumerable: true,
        configurable: true
    });
    VirtualDataSource.prototype.get_isSortingSupported = function () {
        if (this.o != null && !this.cl) {
            this.cl = true;
            var a = this.o.isSortingSupportedOverride;
            this.cl = false;
            return a;
        }
        return false;
    };
    VirtualDataSource.prototype.get_isFilteringSupported = function () {
        if (this.o != null && !this.cl) {
            this.cl = true;
            var a = this.o.isFilteringSupportedOverride;
            this.cl = false;
            return a;
        }
        return false;
    };
    VirtualDataSource.prototype.get_isGroupingSupported = function () {
        if (this.o != null && !this.cl) {
            this.cl = true;
            var a = this.o.isGroupingSupportedOverride;
            this.cl = false;
            return a;
        }
        return false;
    };
    Object.defineProperty(VirtualDataSource.prototype, "cf", {
        get: function () {
            return this.ce;
        },
        set: function (a) {
            this.ce = a;
            this.actualDataProvider = this.resolveDataProvider();
        },
        enumerable: true,
        configurable: true
    });
    VirtualDataSource.prototype.resolveDataProvider = function () {
        if (this.cf == null) {
            return null;
        }
        return this.cf.resolveDataProvider();
    };
    VirtualDataSource.prototype.propertyUpdatedOverride = function (a, b, c) {
        _super.prototype.propertyUpdatedOverride.call(this, a, b, c);
        switch (a) {
            case "DataProvider":
                this.actualDataProvider = this.dataProvider;
                this.queueAutoRefresh();
                break;
            case "ExecutionContext":
                this.ch.b = this.executionContext;
                break;
            case "ActualDataProvider":
                this.actualDataProvider.pageSizeRequested = this.pageSizeRequested;
                this.actualDataProvider.pageLoaded = runOn(this, this.dj);
                this.queueAutoRefresh();
                break;
            case "PageSizeRequested":
                this.actualPageSize = this.pageSizeRequested;
                if (this.actualDataProvider != null) {
                    this.actualDataProvider.pageSizeRequested = this.pageSizeRequested;
                }
                this.queueAutoRefresh();
                break;
            case "ActualPageSize":
                this.ch.ag = this.actualPageSize;
                this.queueAutoRefresh();
                break;
            case "FirstVisibleIndexRequested":
                this.ch.aa = this.firstVisibleIndexRequested;
                break;
            case "LastVisibleIndexRequested":
                this.ch.ae = this.lastVisibleIndexRequested;
                break;
            case "ActualCount":
                if (this.actualDataProvider != null && !this.cj.n) {
                    this.ch.ab = this.actualDataProvider.actualCount;
                }
                else {
                    this.ch.ab = this.actualCount;
                }
                this.queueAutoRefresh();
                break;
            case "MaxCachedPages":
                this.ck.h = this.maxCachedPages;
                break;
        }
    };
    VirtualDataSource.prototype.c6 = function (a) {
        if (this.af && this.cj.n) {
            var b = this.ci(a);
            if (b == null) {
                b = this.cj.c();
            }
            return a - b.g;
        }
        return a;
    };
    VirtualDataSource.prototype.dj = function (a, b, c) {
        var _this = this;
        var d = this.executionContext;
        if (d != null) {
            d.execute(function () { return _this.dq(a, b, c); });
        }
        else {
            this.dq(a, b, c);
        }
    };
    VirtualDataSource.prototype.dq = function (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;
        var d = a.pageIndex();
        this.dk(d);
        this.ck.item(d, a);
        var e = a.schema();
        if (e != null) {
            this.actualSchema = e;
        }
        var f = a.getSummaryInformation();
        if (this.b7 == null && f != null) {
            this.b7 = f;
        }
        var g = a.getGroupInformation();
        if (this.b4 == null && g != null) {
            this.b4 = g;
            this.dp();
            this.cn = false;
        }
        b = this.resolveFullCount(b);
        if (this.actualCount != b) {
            this.actualCount = b;
        }
        this.dn(a);
    };
    VirtualDataSource.prototype.resolveFullCount = function (a) {
        if (this.b4 != null) {
            return this.cj.q;
        }
        return a;
    };
    VirtualDataSource.prototype.dp = function () {
        var a = 0;
        var b = 0;
        var c = 0;
        if (this.shouldEmitSectionHeaders) {
            switch (this.sectionHeaderDisplayMode) {
                case 0:
                    c++;
                    break;
                case 1:
                    c += this.groupDescriptions.k.count;
                    break;
            }
        }
        if (this.shouldEmitSectionFooters) {
            c++;
        }
        var d = this.shouldEmitSectionHeaders;
        var e = this.shouldEmitSectionFooters;
        for (var f = 0; f < this.b4.length; f++) {
            var g = new SectionData();
            if (d) {
                switch (this.sectionHeaderDisplayMode) {
                    case 0:
                        b++;
                        break;
                    case 1:
                        b += this.groupDescriptions.k.count;
                        break;
                }
            }
            var h = this.b4[f].endIndex - this.b4[f].startIndex;
            g.n = a;
            g.m = f;
            g.k = h + 1;
            g.l = a + h;
            g.l += c;
            g.g = b;
            g.c = this.b4[f].groupKeyProperties;
            g.d = this.b4[f].groupKeyValues;
            g.o(this.sectionHeaderDisplayMode, this.isSectionExpandedDefault);
            g.e = this.b4[f].summaryResults;
            if (e) {
                b++;
            }
            for (var i = 0; i < g.b.length; i++) {
                var j = this.df(g, i);
                g.a[i] = j;
                if (this.cq.containsKey(j)) {
                    g.b[i] = this.cq.item(j);
                }
                else {
                    g.b[i] = this.isSectionExpandedDefault;
                }
                if (!g.b[i]) {
                    var k = g.b.length - 1 - i;
                    g.l -= k;
                    b -= k;
                    if (e) {
                        b--;
                    }
                    i += k;
                }
            }
            if (!g.f) {
                g.l -= g.k;
                b -= g.k;
            }
            a = g.l + 1;
            this.cj.p.add(g);
        }
    };
    VirtualDataSource.prototype.dn = function (a) {
        if (this.updateNotifier != null) {
            var b = a.pageIndex() * this.actualPageSize;
            if (this.actualDataProvider != null) {
                if (b > this.actualDataProvider.actualCount) {
                    return;
                }
            }
            var c = this.c5(b);
            var d = this.c5(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);
            }
        }
    };
    VirtualDataSource.prototype.c5 = function (a) {
        if (this.af && this.cj.n) {
            var b = this.cj.f(a);
            if (b == null) {
                b = this.cj.c();
            }
            if (!b.f) {
                return b.n;
            }
            return a + b.g;
        }
        return a;
    };
    VirtualDataSource.prototype.dl = function (a) {
        a();
    };
    VirtualDataSource.prototype.get_isVirtual = function () {
        return true;
    };
    VirtualDataSource.prototype.isPlaceholderItem = function (a) {
        var b = this.b8(a);
        var c = b[0];
        if (!this.ck.d(c)) {
            return true;
        }
        return false;
    };
    VirtualDataSource.prototype.getItemAtIndex = function (a) {
        var b = this.b8(a);
        var c = b[0];
        if (!this.ck.d(c)) {
            if (b[1] == -1) {
                return this.da(a);
            }
            return null;
        }
        var d = this.ck.item(c);
        var e = b[1];
        if (e == -1) {
            return this.da(a);
        }
        return d.getItemAtIndex(e);
    };
    VirtualDataSource.prototype.da = function (a) {
        var b = this.ci(a);
        if (a >= b.n && a < b.n + b.b.length) {
            var c = a - b.n;
            var d = new DataSourceSpecialRow();
            d.rowType = 1;
            d.level = c;
            d.summaryResults = b.e;
            if (this.sectionHeaderDisplayMode == 0) {
                for (var e = 0; e < this.groupDescriptions.k.count; e++) {
                    d.setSectionValue(this.groupDescriptions.k.item(e).propertyName, b.d[e]);
                }
            }
            else {
                d.setSectionValue(this.groupDescriptions.k.item(c).propertyName, b.d[c]);
            }
            return d;
        }
        if (a == b.l) {
            var f = new DataSourceSpecialRow();
            f.rowType = 2;
            for (var g = 0; g < this.groupDescriptions.k.count; g++) {
                f.setSectionValue(this.groupDescriptions.k.item(g).propertyName, b.d[g]);
            }
            return f;
        }
        return null;
    };
    VirtualDataSource.prototype.b8 = function (a) {
        if (this.af && this.cj.n) {
            var b = this.ci(a);
            if (b == null) {
                b = this.cj.c();
            }
            var c = b.n;
            var d = false;
            if (a >= c && a < c + b.b.length && this.shouldEmitSectionHeaders) {
                d = true;
            }
            if (a - (c + b.b.length - 1) <= b.h) {
                d = true;
            }
            var e = a - b.g;
            var f = truncate(Math.floor(e / this.actualPageSize));
            var g = e % this.actualPageSize;
            if (d) {
                g = -1;
            }
            var h = new Array(2);
            h[0] = f;
            h[1] = g;
            return h;
        }
        else {
            var i = truncate(Math.floor(a / this.actualPageSize));
            var j = a % this.actualPageSize;
            var k = new Array(2);
            k[0] = i;
            k[1] = j;
            return k;
        }
    };
    VirtualDataSource.prototype.ci = function (a) {
        return this.cj.d(a);
    };
    VirtualDataSource.prototype.getItemPropertyAtIndex = function (a, b) {
        var c = this.b8(a);
        var d = c[0];
        if (!this.ck.d(d)) {
            if (c[1] == -1) {
                return this.db(a, b);
            }
            return null;
        }
        var e = this.ck.item(d);
        var f = c[1];
        if (f == -1) {
            return this.db(a, b);
        }
        return e.getItemValueAtIndex(f, b);
    };
    VirtualDataSource.prototype.db = function (a, b) {
        var c = this.da(a);
        if (typeCast(DataSourceSpecialRow.$, c) !== null) {
            return c.getValue(b);
        }
        return null;
    };
    VirtualDataSource.prototype.dm = function (a) {
        if (!this.cs.containsKey(a)) {
            this.cs.addItem(a, 1);
        }
        else {
            this.cs.item(a, this.cs.item(a) + 1);
        }
    };
    VirtualDataSource.prototype.dk = function (a) {
        if (this.cs.containsKey(a)) {
            this.cs.item(a, this.cs.item(a) - 1);
            if (this.cs.item(a) <= 0) {
                this.cs.removeItem(a);
                if (this.actualDataProvider != null) {
                    this.actualDataProvider.removePageRequest(a);
                }
            }
        }
    };
    VirtualDataSource.prototype.addCandidate = function (a, b) {
        var c = false;
        if (!this.cr.containsKey(a)) {
            var d = new List$1(Number_$type, 0);
            var e = this.transformPage(a);
            for (var f = 0; f < e.length; f++) {
                var g = e[f];
                if (!this.ck.d(g)) {
                    d.add(g);
                    this.dm(g);
                    var h = this.cs.item(g);
                    if (h == 1 && this.actualDataProvider != null) {
                        this.actualDataProvider.addPageRequest(g, b);
                    }
                    c = true;
                }
            }
            if (d.count > 0) {
                this.cr.addItem(a, d.toArray());
            }
        }
        return c;
    };
    VirtualDataSource.prototype.removeCandidate = function (a) {
        if (this.cr.containsKey(a)) {
            for (var b = 0; b < this.cr.item(a).length; b++) {
                var c = this.cr.item(a)[b];
                this.dk(c);
            }
            this.cr.removeItem(a);
        }
    };
    VirtualDataSource.prototype.transformPage = function (a) {
        var b = [a];
        if (this.af && this.cj.n) {
            var c = a * this.actualPageSize;
            var d = c + this.actualPageSize - 1;
            var e = this.ci(c);
            var f = new List$1(Number_$type, 0);
            for (var g = c; g <= d; g++) {
                if (e == null) {
                    break;
                }
                if (g > e.l) {
                    if (e.m < this.cj.p.count - 1) {
                        e = this.cj.p._inner[e.m + 1];
                    }
                    else {
                        break;
                    }
                }
                if (!e.f || (g >= e.n && g <= e.n + (e.b.length - 1) + e.h)) {
                    continue;
                }
                var h = g - e.g;
                var i = intDivide(h, this.actualPageSize);
                if (!f.contains(i)) {
                    f.add(i);
                }
            }
            b = f.toArray();
        }
        return b;
    };
    VirtualDataSource.prototype.getUnrealizedCount = function () {
        var a = this.ck.g * this.actualPageSize;
        var b = this.actualCount - a;
        return b;
    };
    VirtualDataSource.prototype.onSetItemOverride = function (a, b, c) {
        _super.prototype.onSetItemOverride.call(this, a, b, c);
        var d = this.b8(a);
        var e = d[0];
        if (this.ck.d(e)) {
            this.ck.j(e);
        }
    };
    VirtualDataSource.prototype.refreshInternalOverride = function () {
        _super.prototype.refreshInternalOverride.call(this);
        this.actualPageSizePopulated = false;
        var a = this.actualCount != 0;
        this.cm = true;
        if (!this.cn) {
            this.resetCache();
            if (a) {
                this.onClearItems();
            }
            this.b4 = null;
            this.cj.r();
        }
        else {
            this.cn = false;
            if (a) {
                this.onClearItems();
            }
        }
        this.dr();
        this.ch.au();
        this.cm = false;
    };
    VirtualDataSource.prototype.dr = function () {
        var e_1, _a;
        if (this.actualDataProvider != null) {
            try {
                for (var _b = __values(fromEnum(this.cr.values)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var a = _c.value;
                    for (var c = 0; c < a.length; c++) {
                        var b = a[c];
                        this.actualDataProvider.addPageRequest(b, 1);
                    }
                }
            }
            catch (e_1_1) { e_1 = { error: e_1_1 }; }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                }
                finally { if (e_1) throw e_1.error; }
            }
        }
    };
    VirtualDataSource.prototype.onClearItemsOverride = function () {
        _super.prototype.onClearItemsOverride.call(this);
        if (!this.cm) {
            this.queueAutoRefresh();
        }
    };
    VirtualDataSource.prototype.onInsertItemOverride = function (a, b) {
        _super.prototype.onInsertItemOverride.call(this, a, b);
        this.queueAutoRefresh();
    };
    VirtualDataSource.prototype.onRemoveItemOverride = function (a, b) {
        _super.prototype.onRemoveItemOverride.call(this, a, b);
        this.queueAutoRefresh();
    };
    VirtualDataSource.prototype.get_isItemIndexLookupSupported = function () {
        return true;
    };
    VirtualDataSource.prototype.get_isKeyIndexLookupSupported = function () {
        return true;
    };
    VirtualDataSource.prototype.indexOfItem = function (a) {
        var b = this.ck.b;
        var c = b.o;
        var d = b.q;
        var e = d.count;
        var f = b.p;
        for (var g = 0; g < e; g++) {
            if (f._inner[g]) {
                continue;
            }
            var h = d._inner[g].b;
            var i = h.count();
            for (var j = 0; j < i; j++) {
                if (this.cp(h.getItemAtIndex(j), a)) {
                    var k = typeGetValue(c._inner[g]);
                    var l = k * this.actualPageSize;
                    return l + j;
                }
            }
        }
        if (this.actualDataProvider != null && this.actualDataProvider.isItemIndexLookupSupported) {
            return this.actualDataProvider.indexOfItem(a);
        }
        return -1;
    };
    VirtualDataSource.prototype.cp = function (a, b) {
        if (a == null && b == null) {
            return true;
        }
        if (a == null || b == null) {
            return false;
        }
        return Base.equalsStatic(a, b);
    };
    VirtualDataSource.prototype.indexOfKey = function (a) {
        var b = this.actualPrimaryKey;
        if (b == null || b.length < 1 || this.actualBaseDataProvider == null) {
            return -1;
        }
        this.ensureComparables(this.actualSchema);
        var c = this.cg();
        var d = this.ck.b;
        var e = d.o;
        var f = d.q;
        var g = f.count;
        var h = d.p;
        for (var i = 0; i < g; i++) {
            if (h._inner[i]) {
                continue;
            }
            var j = f._inner[i].b;
            var k = j.count();
            for (var l = 0; l < k; l++) {
                if (c.i(j.getItemAtIndex(l), a) == 0) {
                    var m = typeGetValue(e._inner[i]);
                    var n = m * this.actualPageSize;
                    return n + l;
                }
            }
        }
        if (this.actualDataProvider != null && this.actualDataProvider.isKeyIndexLookupSupported) {
            return this.actualDataProvider.indexOfKey(a);
        }
        return -1;
    };
    VirtualDataSource.prototype.cg = function () {
        var a = new Array(this.actualPrimaryKey.length);
        for (var b = 0; b < a.length; b++) {
            a[b] = 0;
        }
        return new DataSourcePropertiesComparer(this.actualPrimaryKey, a, this.b6, this);
    };
    VirtualDataSource.prototype.getStickyRowPriority = function (a) {
        if (this.getRowType(a) == 1 || this.getRowType(a) == 2) {
            return 100 - this.getRowLevel(a);
        }
        else if (this.getRowType(a) == 3) {
            return 2;
        }
        return 1;
    };
    VirtualDataSource.prototype.unpinRow = function (a) {
        _super.prototype.unpinRow.call(this, a);
    };
    VirtualDataSource.prototype.pinRow = function (a) {
        _super.prototype.pinRow.call(this, a);
    };
    VirtualDataSource.prototype.isRowPinned = function (a) {
        return _super.prototype.isRowPinned.call(this, a);
    };
    VirtualDataSource.prototype.getStickyRowsInRange = function (a, b) {
        if (this.groupDescriptions == null || this.groupDescriptions.k.count == 0) {
            return null;
        }
        var c = this.ci(a);
        var d = this.ci(b);
        if (c == null || d == null) {
            return null;
        }
        if (c.m == this.cy && c.h == this.c0 && c.n == this.c1 && c.l == this.cz && d.m == this.cu && d.h == this.cw && d.n == this.cx && d.l == this.cv) {
            return this.b5;
        }
        this.cy = c.m;
        this.cu = d.m;
        this.c0 = c.h;
        this.cw = d.h;
        this.c1 = c.n;
        this.cx = d.n;
        this.cz = c.l;
        this.cv = d.l;
        var e = new List$1(Number_$type, 0);
        for (var f = c.m; f <= d.m; f++) {
            var g = this.cj.p._inner[f];
            if (this.shouldEmitSectionHeaders && this.af) {
                for (var h = 0; h < g.b.length; h++) {
                    e.add(g.n + h);
                    if (!g.b[h]) {
                        break;
                    }
                }
            }
            if (this.shouldEmitShiftedRows) {
                var i = g.b.length;
                for (var j = 0; j < g.h; j++) {
                    e.add(g.n + j + i);
                }
            }
            if (this.shouldEmitSectionFooters && this.af) {
                for (var k = g.b.length - 1; k >= 0; k--) {
                    if (!g.b[k]) {
                        break;
                    }
                    e.add(g.l - k);
                }
            }
        }
        this.b5 = e.toArray();
        return this.b5;
    };
    VirtualDataSource.prototype.isExclusivelySticky = function (a) {
        return this.getRowType(a) == 1 || this.getRowType(a) == 2;
    };
    VirtualDataSource.prototype.getRowType = function (a) {
        if (a < 0) {
            return 0;
        }
        var b = this.getItemAtIndex(a);
        var item_ = b;
        if ((item_ != null && item_.$$isSpecialRow !== undefined)) {
            return b.rowType;
        }
        return 0;
    };
    VirtualDataSource.prototype.getIsRowExpandedAtIndex = function (a) {
        var b = this.cj.d(a);
        if (b == null) {
            b = this.cj.c();
        }
        for (var c = 0; c < b.b.length; c++) {
            if (a == b.n + c) {
                return b.b[c];
            }
        }
        return _super.prototype.getIsRowExpandedAtIndex.call(this, a);
    };
    VirtualDataSource.prototype.setIsRowExpandedAtIndex = function (a, b) {
        var c = this.cj.d(a);
        if (c == null) {
            c = this.cj.c();
        }
        for (var d = 0; d < c.b.length; d++) {
            if (a == c.n + d) {
                var e = false;
                var f = c.a[d];
                if (this.cq.containsKey(f) && this.cq.item(f) != b) {
                    if (b == this.isSectionExpandedDefault) {
                        this.cq.removeItem(f);
                    }
                    else {
                        this.cq.item(f, b);
                    }
                    e = true;
                }
                else if (b != this.isSectionExpandedDefault) {
                    this.cq.addItem(f, b);
                    e = true;
                }
                if (e) {
                    this.cj.r();
                    this.dp();
                    this.cn = true;
                    this.actualCount = this.cj.q;
                }
                break;
            }
        }
    };
    VirtualDataSource.prototype.getRowLevel = function (a) {
        if (a < 0) {
            return 0;
        }
        var b = this.getItemAtIndex(a);
        var item_ = b;
        if ((item_ != null && item_.$$isSpecialRow !== undefined)) {
            return b.level;
        }
        return 0;
    };
    VirtualDataSource.prototype.de = function (a) {
        var b = "";
        for (var c = 0; c < a.c.length; c++) {
            b += a.c[c] + ":" + a.d[c];
        }
        return b;
    };
    VirtualDataSource.prototype.df = function (a, b) {
        if (this.sectionHeaderDisplayMode == 0) {
            return this.de(a);
        }
        var c = "";
        for (var d = 0; d < a.c.length; d++) {
            c += a.c[d] + ":" + a.d[d] + ":";
        }
        c += b;
        return c;
    };
    VirtualDataSource.$t = markType(VirtualDataSource, 'VirtualDataSource', BaseDataSource.$, [IPageCandidatesSink_$type]);
    return VirtualDataSource;
}(BaseDataSource));
export { VirtualDataSource };
