/*
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, typeCast, markType } from "igniteui-react-core";
import { ICategorySeriesInteractionManager_$type } from "./ICategorySeriesInteractionManager";
import { ScalerParams } from "./ScalerParams";
import { ISortingAxis_$type } from "./ISortingAxis";
import { HighlightingInfo } from "./HighlightingInfo";
import { intDivide, truncate, isNaN_ } from "igniteui-react-core";
/**
 * @hidden
 */
var CategorySeriesInteractionManager = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(CategorySeriesInteractionManager, _super);
    function CategorySeriesInteractionManager() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    CategorySeriesInteractionManager.prototype.b$c = function (a, b) {
        var c = a.bs.bv;
        var d = a.bs.bu;
        var e = a.aq();
        var f = a.getEffectiveViewport1(a.bs);
        var g = a.ny(a.bs);
        var h = -1;
        if (e != null && !c.isEmpty && !d.isEmpty) {
            var i = new ScalerParams(0, c, d, e.ca, f);
            var j = e.d2(g.left, i);
            var k = e.d2(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.dg) {
            c = a.gb(b);
            if (c == -1) {
                return null;
            }
        }
        else if (b.x == 1 && a.cd != null) {
            c = a.cd.count - 1;
        }
        else {
            c = a.f9(b);
        }
        return c >= 0 && a.cd != null && c < a.cd.count ? a.cd.item(c) : null;
    };
    CategorySeriesInteractionManager.prototype.b$d = function (a, b) {
        var c = a.bs.bv;
        var d = a.bs.bu;
        var e = a.getEffectiveViewport1(a.bs);
        if (c.isEmpty || d.isEmpty) {
            return -1;
        }
        if (isNaN_(b.x)) {
            return -1;
        }
        var f = a.aq();
        if (f == null) {
            return -1;
        }
        var g = typeCast(ISortingAxis_$type, f);
        var h = a.ny(a.bs);
        var i = new ScalerParams(0, c, d, f.ca, e);
        var j = 0;
        if (f.cd) {
            var k = (b.x - c.left) / c.width;
            var l = k * h.width + h.left;
            j = f.d2(l, i);
        }
        else {
            var m = f.d2(h.left, i);
            var n = f.d2(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.bs.bu;
        var e = a.bs.bv;
        var f = a.aq();
        var g = 0;
        if (f.ch) {
            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.ca) {
            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) {
        if (a.cd == null) {
            return null;
        }
        if (e == 0) {
            return null;
        }
        var i = a.cd.count;
        var j = a.aq();
        var k = -1;
        var l = -1;
        if (j.cf) {
            var m = this.b$e(a, b, g);
            k = m;
            l = m;
        }
        else {
            var n = a.f9(g);
            k = truncate(Math.floor((intDivide(n, e)))) * e;
            l = k + (e - 1);
        }
        if (h != null && h.h == k && h.g == l) {
            return h;
        }
        var o = new HighlightingInfo();
        o.b = a;
        o.h = k;
        o.g = l;
        return o;
    };
    CategorySeriesInteractionManager.prototype.b$b = function (a, b, c, d, e, f, g, h) {
        if (a.cd == null) {
            return null;
        }
        if (d == 0) {
            return null;
        }
        var i = a.cd.count;
        var j = a.aq();
        var k = -1;
        var l = -1;
        var m = -1;
        if (j.cf) {
            var n = this.b$e(a, e, g);
            m = n;
            k = n;
            l = n;
        }
        else {
            var o = a.f9(g);
            m = truncate(Math.floor((intDivide(o, d)))) - c;
            k = m;
            l = m;
        }
        if (h != null && h.h == k && h.g == 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 == m) {
                var s = new HighlightingInfo();
                s.b = a;
                s.h = p._inner[r].al;
                s.g = p._inner[r].al;
                s.e = true;
                return s;
            }
        }
        var t = a.no(g);
        var u = p._inner[0].al;
        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].al;
                }
            }
        }
        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].al;
                }
            }
        }
        var ad = new HighlightingInfo();
        ad.b = a;
        ad.e = true;
        ad.h = u;
        ad.g = ad.h;
        if (h != null && h.h == ad.h && h.g == ad.g) {
            return h;
        }
        return ad;
    };
    CategorySeriesInteractionManager.$t = markType(CategorySeriesInteractionManager, 'CategorySeriesInteractionManager', Base.$, [ICategorySeriesInteractionManager_$type]);
    return CategorySeriesInteractionManager;
}(Base));
export { CategorySeriesInteractionManager };
//# sourceMappingURL=CategorySeriesInteractionManager.js.map
