/*
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 } from "tslib";
import { Base, typeCast, markType } from "igniteui-react-core";
import { ICategorySeriesInteractionManager_$type } from "./ICategorySeriesInteractionManager";
import { ScalerParams } from "./ScalerParams";
import { ISortingAxis_$type } from "./ISortingAxis";
import { HighlightingInfo } from "igniteui-react-core";
import { truncate, intDivide, isNaN_ } from "igniteui-react-core";
/**
 * @hidden
 */
var CategorySeriesInteractionManager = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(CategorySeriesInteractionManager, _super);
    function CategorySeriesInteractionManager() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    CategorySeriesInteractionManager.prototype.b$c = function (a, b) {
        var c = a.cv.by;
        var d = a.cv.bx;
        var e = a.a0();
        var f = a.getEffectiveViewport1(a.cv);
        var g = a.wh(a.cv);
        var h = -1;
        if (e != null && !c.isEmpty && !d.isEmpty) {
            var i = new ScalerParams(0, c, d, e.ch, f);
            var j = e.eo(g.left, i);
            var k = e.eo(g.right, i);
            var l = (b.x - c.left) / c.width;
            var m = j + (l * (k - j));
            if (e.categoryMode != 0) {
                m -= 0.5;
            }
            h = m;
        }
        return h;
    };
    CategorySeriesInteractionManager.prototype.b$f = function (a, b) {
        var c = 0;
        if (a.fs) {
            c = a.j5(b);
            if (c == -1) {
                return null;
            }
        }
        else if (b.x == 1 && a.dn != null) {
            c = a.dn.count - 1;
        }
        else {
            c = a.j3(b);
        }
        return c >= 0 && a.dn != null && c < a.dn.count ? a.dn.item(c) : null;
    };
    CategorySeriesInteractionManager.prototype.b$d = function (a, b) {
        var c = a.cv.by;
        var d = a.cv.bx;
        var e = a.getEffectiveViewport1(a.cv);
        if (c.isEmpty || d.isEmpty) {
            return -1;
        }
        if (isNaN_(b.x)) {
            return -1;
        }
        var f = a.a0();
        if (f == null) {
            return -1;
        }
        var g = typeCast(ISortingAxis_$type, f);
        var h = a.wh(a.cv);
        var i = new ScalerParams(0, c, d, f.ch, e);
        var j = 0;
        if (f.cl) {
            var k = (b.x - c.left) / c.width;
            var l = k * h.width + h.left;
            j = f.eo(l, i);
        }
        else {
            var m = f.eo(h.left, i);
            var n = f.eo(h.right, i);
            var o = (b.x - c.left) / c.width;
            j = m + ((n - m) * o);
        }
        var p = g.i$f(j);
        return p;
    };
    CategorySeriesInteractionManager.prototype.b$e = function (a, b, c) {
        var d = a.cv.bx;
        var e = a.cv.by;
        var f = a.a0();
        var g = 0;
        if (f.cp) {
            var h = (c.y - e.top) / e.height;
            g = h * d.height + d.top;
        }
        else {
            var i = (c.x - e.left) / e.width;
            g = i * d.width + d.left;
        }
        if (f.ch) {
            var j = b.count;
            var k = 0;
            for (k = j - 1; k >= 0; k--) {
                var l = b._inner[k];
                var m = null;
                if (k > 0) {
                    m = b._inner[k - 1];
                }
                if (l[0] <= g && m == null || m[0] >= g) {
                    if (m != null) {
                        if (Math.abs(l[0] - g) < Math.abs(m[0] - g)) {
                            return k;
                        }
                        else {
                            return k - 1;
                        }
                    }
                    else {
                        return k;
                    }
                }
            }
            return k;
        }
        else {
            var n = b.count;
            var o = 0;
            for (o = 0; o < n; o++) {
                var p = b._inner[o];
                var q = null;
                if (o < n - 1) {
                    q = b._inner[o + 1];
                }
                if (p[0] <= g && q == null || q[0] >= g) {
                    if (q != null) {
                        if (Math.abs(p[0] - g) < Math.abs(q[0] - g)) {
                            return o;
                        }
                        else {
                            return o + 1;
                        }
                    }
                    else {
                        return o;
                    }
                }
            }
            return o;
        }
    };
    CategorySeriesInteractionManager.prototype.b$a = function (a, b, c, d, e, f, g, h, i) {
        if (a.dn == null) {
            return null;
        }
        if (f == 0) {
            return null;
        }
        var j = a.dn.count;
        var k = a.a0();
        var l = -1;
        var m = -1;
        if (k.cn) {
            var n = this.b$e(a, b, h);
            if (c != null && n >= 0 && n < c.count) {
                n = truncate(Math.round(c._inner[n]));
            }
            l = n;
            m = n;
        }
        else {
            var o = a.j3(h);
            l = truncate(Math.floor((intDivide(o, f)))) * f;
            m = l + (f - 1);
        }
        if (i != null && i.g == l && i.f == m) {
            return i;
        }
        var p = new HighlightingInfo();
        p.i = a;
        p.g = l;
        p.f = m;
        return p;
    };
    CategorySeriesInteractionManager.prototype.b$b = function (a, b, c, d, e, f, g, h) {
        if (a.dn == null) {
            return null;
        }
        if (d == 0) {
            return null;
        }
        if (e == null || e.count == 0) {
            return null;
        }
        var i = a.dn.count;
        var j = a.a0();
        var k = -1;
        var l = -1;
        var m = -1;
        var n = -1;
        if (j.cn) {
            n = this.b$e(a, e, g);
            m = n;
            k = n;
            l = n;
        }
        else {
            var o = a.j3(g);
            m = o;
            n = truncate(Math.floor((intDivide(o, d)))) - c;
            k = n;
            l = n;
        }
        if (h != null && h.g == k && h.f == l) {
            return h;
        }
        var p = b;
        var q = p.count;
        if (p == null) {
            return null;
        }
        if (q == 0) {
            return null;
        }
        for (var r = 0; r < q; r++) {
            if (p._inner[r].al == n || p._inner[r].ak == m) {
                var s = new HighlightingInfo();
                s.i = a;
                s.g = p._inner[r].ak;
                s.f = p._inner[r].ak;
                if (h != null && h.g == s.g && h.f == s.f) {
                    return h;
                }
                s.d = true;
                return s;
            }
        }
        var t = a.v5(g);
        var u = p._inner[0].ak;
        if (a.isVertical) {
            var v = e._inner[p._inner[0].al][0];
            var w = (t.y - v) * (t.y - v);
            var x = void 0;
            for (var y = 0; y < q; y++) {
                v = e._inner[p._inner[y].al][0];
                x = (t.y - v) * (t.y - v);
                if (x <= w) {
                    w = x;
                    u = p._inner[y].ak;
                }
            }
        }
        else {
            var z = e._inner[p._inner[0].al][0];
            var aa = (t.x - z) * (t.x - z);
            var ab = void 0;
            for (var ac = 0; ac < q; ac++) {
                z = e._inner[p._inner[ac].al][0];
                ab = (t.x - z) * (t.x - z);
                if (ab <= aa) {
                    aa = ab;
                    u = p._inner[ac].ak;
                }
            }
        }
        var ad = new HighlightingInfo();
        ad.i = a;
        ad.d = true;
        ad.g = u;
        ad.f = ad.g;
        if (h != null && h.g == ad.g && h.f == ad.f) {
            return h;
        }
        return ad;
    };
    CategorySeriesInteractionManager.$t = markType(CategorySeriesInteractionManager, 'CategorySeriesInteractionManager', Base.$, [ICategorySeriesInteractionManager_$type]);
    return CategorySeriesInteractionManager;
}(Base));
export { CategorySeriesInteractionManager };
