/*
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-angular-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-angular-core";
/**
 * @hidden
 */
var CategorySeriesInteractionManager = /** @class */ (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.bi.bs;
        var d = a.bi.br;
        var e = a.ap();
        var f = a.getEffectiveViewport1(a.bi);
        var g = a.lq(a.bi);
        var h = -1;
        if (e != null && !c.isEmpty && !d.isEmpty) {
            var i = new ScalerParams(0, c, d, e.b8, f);
            var j = e.dz(g.left, i);
            var k = e.dz(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.c1) {
            c = a.fa(b);
            if (c == -1) {
                return null;
            }
        }
        else if (b.x == 1 && a.bz != null) {
            c = a.bz.count - 1;
        }
        else {
            c = a.e8(b);
        }
        return c >= 0 && a.bz != null && c < a.bz.count ? a.bz.item(c) : null;
    };
    CategorySeriesInteractionManager.prototype.b$d = function (a, b) {
        var c = a.bi.bs;
        var d = a.bi.br;
        var e = a.getEffectiveViewport1(a.bi);
        if (c.isEmpty || d.isEmpty) {
            return -1;
        }
        if (isNaN_(b.x)) {
            return -1;
        }
        var f = a.ap();
        if (f == null) {
            return -1;
        }
        var g = typeCast(ISortingAxis_$type, f);
        var h = a.lq(a.bi);
        var i = new ScalerParams(0, c, d, f.b8, e);
        var j = 0;
        if (f.cb) {
            var k = (b.x - c.left) / c.width;
            var l = k * h.width + h.left;
            j = f.dz(l, i);
        }
        else {
            var m = f.dz(h.left, i);
            var n = f.dz(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.bi.br;
        var e = a.bi.bs;
        var f = a.ap();
        var g = 0;
        if (f.cf) {
            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.b8) {
            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) {
        var i = a.bz.count;
        var j = a.ap();
        var k = -1;
        var l = -1;
        if (j.cd) {
            var m = this.b$e(a, b, g);
            k = m;
            l = m;
        }
        else {
            var n = a.e8(g);
            k = truncate(Math.floor((intDivide(n, e)))) * e;
            l = k + (e - 1);
        }
        if (h != null && h.f == k && h.e == l) {
            return h;
        }
        var o = new HighlightingInfo();
        o.b = a;
        o.f = k;
        o.e = l;
        return o;
    };
    CategorySeriesInteractionManager.prototype.b$b = function (a, b, c, d, e, f) {
        var g = a.lg(e);
        var h = b;
        if (h == null) {
            return null;
        }
        var i = h.count;
        if (i == 0) {
            return null;
        }
        var j = h._inner[0].al;
        if (a.isVertical) {
            var k = c._inner[h._inner[0].al][0];
            var l = (g.y - k) * (g.y - k);
            var m = void 0;
            for (var n = 0; n < i; n++) {
                k = c._inner[h._inner[n].al][0];
                m = (g.y - k) * (g.y - k);
                if (m <= l) {
                    l = m;
                    j = h._inner[n].al;
                }
            }
        }
        else {
            var o = c._inner[h._inner[0].al][0];
            var p = (g.x - o) * (g.x - o);
            var q = void 0;
            for (var r = 0; r < i; r++) {
                o = c._inner[h._inner[r].al][0];
                q = (g.x - o) * (g.x - o);
                if (q <= p) {
                    p = q;
                    j = h._inner[r].al;
                }
            }
        }
        var s = new HighlightingInfo();
        s.b = a;
        s.c = true;
        s.f = j;
        s.e = s.f;
        if (f != null && f.f == s.f && f.e == s.e) {
            return f;
        }
        return s;
    };
    CategorySeriesInteractionManager.$t = markType(CategorySeriesInteractionManager, 'CategorySeriesInteractionManager', Base.$, [ICategorySeriesInteractionManager_$type]);
    return CategorySeriesInteractionManager;
}(Base));
export { CategorySeriesInteractionManager };
//# sourceMappingURL=CategorySeriesInteractionManager.js.map