/*
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, Number_$type, fromEnum, markType } from "igniteui-react-core/ES5/type";
import { List$1 } from "igniteui-react-core/ES5/List$1";
import { Dictionary$2 } from "igniteui-react-core/ES5/Dictionary$2";
import { MarkerManagerBucket } from "./MarkerManagerBucket";
import { ArrayExtension } from "igniteui-react-core/ES5/ArrayExtension";
import { truncate, isNaN_ } from "igniteui-react-core/ES5/number";
var MarkerManagerBase = /** @class */ (function (_super) {
    tslib_1.__extends(MarkerManagerBase, _super);
    function MarkerManagerBase(a, b, c, d, e) {
        var _this = _super.call(this) || this;
        _this.f = null;
        _this.h = null;
        _this.a = null;
        _this.g = null;
        _this.e = null;
        _this.h = a;
        _this.g = b;
        _this.a = c;
        _this.f = d;
        _this.e = e;
        return _this;
    }
    MarkerManagerBase.prototype.d = function (a, b) {
        var c = new List$1(Number_$type, 0);
        var d = new List$1(Number_$type, 0);
        try {
            for (var _a = tslib_1.__values(fromEnum(b)), _b = _a.next(); !_b.done; _b = _a.next()) {
                var e = _b.value;
                if (a.item(e).e.count > 0) {
                    c.add(e);
                }
                else {
                    d.add(e);
                }
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
            }
            finally { if (e_1) throw e_1.error; }
        }
        var f = new List$1(Number_$type, 0);
        f.o(c);
        f.o(d);
        return f;
        var e_1, _c;
    };
    MarkerManagerBase.prototype.k = function (a, b, c, d) {
        while (a > 0) {
            if (a < c.count) {
                if (!MarkerManagerBase.b) {
                    var e = c;
                    ArrayExtension.shuffle$1(Number_$type, e);
                }
                c = this.d(b, c);
                var f = a;
                var _loop_1 = function (g) {
                    var h = g;
                    var i = b.item(c._inner[h]);
                    var j;
                    var k = ((function () { var l = i.f(j); j = l.p0; return l.ret; })());
                    d.add(k);
                    a--;
                    if (i.a) {
                        b.removeItem(c._inner[h]);
                    }
                };
                for (var g = 0; g < f; g++) {
                    _loop_1(g);
                }
            }
            else {
                var _loop_2 = function (l) {
                    var m = b.item(l);
                    var n;
                    var o = ((function () { var p = m.f(n); n = p.p0; return p.ret; })());
                    d.add(o);
                    a--;
                    if (m.a) {
                        b.removeItem(l);
                    }
                };
                try {
                    for (var _a = tslib_1.__values(fromEnum(c)), _b = _a.next(); !_b.done; _b = _a.next()) {
                        var l = _b.value;
                        _loop_2(l);
                    }
                }
                catch (e_2_1) { e_2 = { error: e_2_1 }; }
                finally {
                    try {
                        if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
                    }
                    finally { if (e_2) throw e_2.error; }
                }
                c = new List$1(Number_$type, 1, b.keys);
            }
        }
        var e_2, _c;
    };
    MarkerManagerBase.prototype.i = function (a, b, c, d) {
        var e = b.left;
        var f = b.right;
        var g = b.top;
        var h = b.bottom;
        if (!a.isEmpty && !b.isEmpty) {
            for (var i = 0; i < c.count; ++i) {
                var j = c.item(i).x;
                if (isNaN_(j)) {
                    continue;
                }
                var k = c.item(i).y;
                if (isNaN_(k)) {
                    continue;
                }
                if (j < e || j > f) {
                    continue;
                }
                if (k < g || k > h) {
                    continue;
                }
                d.add(i);
            }
        }
    };
    MarkerManagerBase.prototype.c = function (a, b, c, d) {
        var e = new Array(d.count);
        try {
            for (var _a = tslib_1.__values(fromEnum(this.e())), _b = _a.next(); !_b.done; _b = _a.next()) {
                var f = _b.value;
                if (f != -1) {
                    e[f] = true;
                }
            }
        }
        catch (e_3_1) { e_3 = { error: e_3_1 }; }
        finally {
            try {
                if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
            }
            finally { if (e_3) throw e_3.error; }
        }
        var g = truncate(Math.floor(a.width / c));
        var h = new Dictionary$2(Number_$type, MarkerManagerBucket.$, 0);
        var _loop_3 = function (i) {
            var j = d.item(i).x;
            var k = d.item(i).y;
            var l = truncate(Math.floor(k / c));
            var m = truncate(Math.floor(j / c));
            var n = (l * g) + m;
            var o;
            if (!((function () { var p = h.tryGetValue(n, o); o = p.p1; return p.ret; })())) {
                o = new MarkerManagerBucket();
                h.addItem(n, o);
            }
            if (e[i]) {
                o.e.add(i);
            }
            else {
                o.d.add(i);
            }
        };
        try {
            for (var _d = tslib_1.__values(fromEnum(b)), _e = _d.next(); !_e.done; _e = _d.next()) {
                var i = _e.value;
                _loop_3(i);
            }
        }
        catch (e_4_1) { e_4 = { error: e_4_1 }; }
        finally {
            try {
                if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
            }
            finally { if (e_4) throw e_4.error; }
        }
        return h;
        var e_3, _c, e_4, _f;
    };
    MarkerManagerBase.b = false;
    MarkerManagerBase.$t = markType(MarkerManagerBase, 'MarkerManagerBase');
    return MarkerManagerBase;
}(Base));
export { MarkerManagerBase };
