/*
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 * as tslib_1 from "tslib";
import { Base, runOn, typeCast, markType } from "./type";
import { AsyncDataSourcePageRequest } from "./AsyncDataSourcePageRequest";
import { WeakReference } from "./WeakReference";
import { IDataSourceExecutionContext_$type } from "./IDataSourceExecutionContext";
import { LinkedList$1 } from "./LinkedList$1";
import { List$1 } from "./List$1";
var AsyncVirtualDataSourceProviderWorker = /** @class */ (function (_super) {
    tslib_1.__extends(AsyncVirtualDataSourceProviderWorker, _super);
    function AsyncVirtualDataSourceProviderWorker(a) {
        var _this = _super.call(this) || this;
        _this.q = new LinkedList$1(AsyncDataSourcePageRequest.$);
        _this.o = new List$1(AsyncDataSourcePageRequest.$, 0);
        _this.ab = {};
        _this.h = true;
        _this.t = 0;
        _this.s = 0;
        _this.u = 0;
        _this.c = null;
        _this.r = -1;
        _this.ap = null;
        _this.ao = null;
        _this.g = false;
        _this.m = false;
        _this.f = false;
        _this.h = true;
        _this.t = a.c;
        _this.s = _this.t;
        _this.u = a.d;
        _this.ap = new WeakReference(a.a);
        _this.ao = new WeakReference(a.b);
        return _this;
    }
    Object.defineProperty(AsyncVirtualDataSourceProviderWorker.prototype, "p", {
        get: function () {
            return this.o;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AsyncVirtualDataSourceProviderWorker.prototype, "a", {
        get: function () {
            if (this.ap == null) {
                return null;
            }
            return this.ap.c;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AsyncVirtualDataSourceProviderWorker.prototype, "b", {
        get: function () {
            if (this.ao == null) {
                return null;
            }
            return this.ao.c;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AsyncVirtualDataSourceProviderWorker.prototype, "w", {
        get: function () {
            return this.s;
        },
        set: function (a) {
            this.s = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AsyncVirtualDataSourceProviderWorker.prototype, "v", {
        get: function () {
            return this.r;
        },
        set: function (a) {
            this.r = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AsyncVirtualDataSourceProviderWorker.prototype, "d", {
        get: function () {
            return this.c;
        },
        set: function (a) {
            this.c = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AsyncVirtualDataSourceProviderWorker.prototype, "n", {
        get: function () {
            return this.g;
        },
        set: function (a) {
            this.g = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AsyncVirtualDataSourceProviderWorker.prototype, "l", {
        get: function () {
            return this.h;
        },
        set: function (a) {
            this.h = a;
        },
        enumerable: true,
        configurable: true
    });
    AsyncVirtualDataSourceProviderWorker.prototype.i = function (a, b) {
        return this.j(a, b, 200);
    };
    AsyncVirtualDataSourceProviderWorker.prototype.j = function (a, b, c) {
        if (this.m) {
            return false;
        }
        if (b == 2) {
            this.q.e(new AsyncDataSourcePageRequest(a, c));
        }
        else {
            this.q.f(new AsyncDataSourcePageRequest(a, c));
        }
        return true;
    };
    AsyncVirtualDataSourceProviderWorker.prototype.ak = function (a) {
        var b = null;
        var c = this.q.c;
        while (c != null) {
            var d = c.c;
            if (d.g == a) {
                b = c;
                break;
            }
            c = c.a;
        }
        if (b != null) {
            this.q.h(b);
        }
    };
    AsyncVirtualDataSourceProviderWorker.prototype.ai = function () {
        this.q.g();
    };
    AsyncVirtualDataSourceProviderWorker.prototype.an = function () {
        this.ap = null;
        this.ao = null;
        this.m = true;
        this.h = false;
    };
    AsyncVirtualDataSourceProviderWorker.prototype.af = function () {
    };
    AsyncVirtualDataSourceProviderWorker.prototype.e = function () {
        return null;
    };
    AsyncVirtualDataSourceProviderWorker.prototype.ae = function (a) {
    };
    AsyncVirtualDataSourceProviderWorker.prototype.aj = function (a, b) {
    };
    AsyncVirtualDataSourceProviderWorker.prototype.ad = function (a, b) {
    };
    AsyncVirtualDataSourceProviderWorker.prototype.am = function () {
        for (var a = 0; a < this.o.count; a++) {
            if (!this.o.item(a).b.a.isRunning && !this.o.item(a).d && !this.o.item(a).b.a.isCompleted && !this.o.item(a).b.a.isCancelled) {
                this.o.item(a).b.a.isRunning = true;
                this.o.item(a).b.a.run();
                break;
            }
        }
    };
    AsyncVirtualDataSourceProviderWorker.prototype.x = function (a) {
        this.am();
        for (var b = 0; b < a.length; b++) {
            if (a[b].d || a[b].b.a.isCompleted || a[b].b.a.isCancelled) {
                return b;
            }
        }
        return -1;
    };
    AsyncVirtualDataSourceProviderWorker.prototype.ac = function () {
        if (!this.f) {
            this.f = true;
            this.af();
        }
        {
            var a = null;
            var b = null;
            var c = this.o.count;
            if (this.q.c != null && c < 2) {
                var d = this.q.c;
                this.q.i();
                this.ag(d.c, d.c.h);
                c = this.o.count;
            }
            if (c > 0) {
                a = new Array(c);
                for (var e = 0; e < c; e++) {
                    a[e] = this.o.item(e);
                }
                b = this.e();
                this.ae(b);
            }
            if (a != null && a.length > 0) {
                var f = this.x(a);
                if (!this.h) {
                    return;
                }
                if (f >= 0) {
                    var g = a[f];
                    this.ad(b, f);
                    this.o.remove(g);
                    this.aj(b, f);
                    this.ah(g.b, g.h, g.g, b);
                }
            }
            else {
            }
            if (!this.h) {
                return;
            }
            if (this.h) {
                window.setTimeout(runOn(this, this.ac), 100);
            }
        }
    };
    AsyncVirtualDataSourceProviderWorker.prototype.ag = function (a, b) {
    };
    AsyncVirtualDataSourceProviderWorker.prototype.ah = function (a, b, c, d) {
    };
    AsyncVirtualDataSourceProviderWorker.prototype.al = function (a, b) {
        var _this = this;
        var c = b * 2;
        if (b > 20000) {
            this.ak(a);
        }
        if (this.ao == null) {
            this.an();
            return;
        }
        var d = typeCast(IDataSourceExecutionContext_$type, this.ao.c);
        if (d == null) {
            this.an();
            return;
        }
        d.executeDelayed(function () { return _this.j(a, 0, c); }, b);
    };
    AsyncVirtualDataSourceProviderWorker.prototype.k = function (a) {
        if (this.r < 0) {
            return false;
        }
        if ((this.r - (a * this.s)) < this.s) {
            return true;
        }
        return false;
    };
    AsyncVirtualDataSourceProviderWorker.$t = markType(AsyncVirtualDataSourceProviderWorker, 'AsyncVirtualDataSourceProviderWorker');
    return AsyncVirtualDataSourceProviderWorker;
}(Base));
export { AsyncVirtualDataSourceProviderWorker };
//# sourceMappingURL=AsyncVirtualDataSourceProviderWorker.js.map