/*
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, Number_$type, fromEnum, markType } from "igniteui-react-core/ES2015/type";
import { List$1 } from "igniteui-react-core/ES2015/List$1";
import { Dictionary$2 } from "igniteui-react-core/ES2015/Dictionary$2";
import { MarkerManagerBucket } from "./MarkerManagerBucket";
import { ArrayExtension } from "igniteui-react-core/ES2015/ArrayExtension";
import { truncate, isNaN_ } from "igniteui-react-core/ES2015/number";
export class MarkerManagerBase extends Base {
    constructor(a, b, c, d, e) {
        super();
        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;
    }
    d(a, b) {
        let c = new List$1(Number_$type, 0);
        let d = new List$1(Number_$type, 0);
        for (let e of fromEnum(b)) {
            if (a.item(e).e.count > 0) {
                c.add(e);
            }
            else {
                d.add(e);
            }
        }
        let f = new List$1(Number_$type, 0);
        f.o(c);
        f.o(d);
        return f;
    }
    k(a, b, c, d) {
        while (a > 0) {
            if (a < c.count) {
                if (!MarkerManagerBase.b) {
                    let e = c;
                    ArrayExtension.shuffle$1(Number_$type, e);
                }
                c = this.d(b, c);
                let f = a;
                for (let g = 0; g < f; g++) {
                    let h = g;
                    let i = b.item(c._inner[h]);
                    let j;
                    let k = ((() => { let l = i.f(j); j = l.p0; return l.ret; })());
                    d.add(k);
                    a--;
                    if (i.a) {
                        b.removeItem(c._inner[h]);
                    }
                }
            }
            else {
                for (let l of fromEnum(c)) {
                    let m = b.item(l);
                    let n;
                    let o = ((() => { let p = m.f(n); n = p.p0; return p.ret; })());
                    d.add(o);
                    a--;
                    if (m.a) {
                        b.removeItem(l);
                    }
                }
                c = new List$1(Number_$type, 1, b.keys);
            }
        }
    }
    i(a, b, c, d) {
        let e = b.left;
        let f = b.right;
        let g = b.top;
        let h = b.bottom;
        if (!a.isEmpty && !b.isEmpty) {
            for (let i = 0; i < c.count; ++i) {
                let j = c.item(i).x;
                if (isNaN_(j)) {
                    continue;
                }
                let k = c.item(i).y;
                if (isNaN_(k)) {
                    continue;
                }
                if (j < e || j > f) {
                    continue;
                }
                if (k < g || k > h) {
                    continue;
                }
                d.add(i);
            }
        }
    }
    c(a, b, c, d) {
        let e = new Array(d.count);
        for (let f of fromEnum(this.e())) {
            if (f != -1) {
                e[f] = true;
            }
        }
        let g = truncate(Math.floor(a.width / c));
        let h = new Dictionary$2(Number_$type, MarkerManagerBucket.$, 0);
        for (let i of fromEnum(b)) {
            let j = d.item(i).x;
            let k = d.item(i).y;
            let l = truncate(Math.floor(k / c));
            let m = truncate(Math.floor(j / c));
            let n = (l * g) + m;
            let o;
            if (!((() => { let 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);
            }
        }
        return h;
    }
}
MarkerManagerBase.b = false;
MarkerManagerBase.$t = markType(MarkerManagerBase, 'MarkerManagerBase');
