/*
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, markType } from "igniteui-react-core/ES5/type";
import { IAnchoredCategorySeriesInteractionManager_$type } from "./IAnchoredCategorySeriesInteractionManager";
import { Rect } from "igniteui-react-core/ES5/Rect";
import { ScalerParams } from "./ScalerParams";
import { truncate, intDivide, isNaN_ } from "igniteui-react-core/ES5/number";
import { stringIsNullOrEmpty } from "igniteui-react-core/ES5/string";
/**
 * @hidden
 */
var AnchoredCategorySeriesInteractionManager = /** @class */ (function (_super) {
    tslib_1.__extends(AnchoredCategorySeriesInteractionManager, _super);
    function AnchoredCategorySeriesInteractionManager() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    AnchoredCategorySeriesInteractionManager.prototype.c$b = function (a, b, c, d, e, f, g, h) {
        if (!g) {
            return h(b);
        }
        if (e == null || e.cc || f == null || d == null || isNaN_(b.x) || isNaN_(b.y)) {
            return h(b);
        }
        if (c <= 1) {
            return h(b);
        }
        var i = truncate(Math.round(a.d8(b)));
        if (i < 0 || i >= a.bz.count) {
            return h(b);
        }
        var j = intDivide(i, c);
        var k = c * j;
        var l = Math.min(k + c, d.count - 1);
        var m = a.lj(a.bi);
        var n = new ScalerParams(0, a.bs.m4, a.bs.m3, f.b8, a.bs.mu);
        var o = m.top;
        var p = m.bottom;
        var q = o + (p - o) * b.y;
        var r = f.dw(q, n);
        var s = 1.7976931348623157E+308;
        var t = k;
        for (var u = k; u <= l; u++) {
            var v = Math.abs(d.item(u) - r);
            if (v < s) {
                s = v;
                t = u;
            }
        }
        return a.bz.item(t);
    };
    AnchoredCategorySeriesInteractionManager.prototype.c$a = function (a, b, c, d, e, f) {
        var g = a.bi.bs;
        g = g.copy();
        var h = a.bi.br;
        var i = new Rect(0, 0, 0, 1, 1);
        var j = !g.isEmpty && !h.isEmpty && a.bz != null ? a.bz.indexOf(f) : -1;
        var k = a.ll(a.bi);
        var l = new ScalerParams(0, i, i, c.b8, k);
        var m = new ScalerParams(0, i, i, d.b8, k);
        m.b = a.ee();
        var n = c != null ? c.dt(j, l) : NaN;
        n += e;
        var o = d != null && b != null && j < b.count ? d.dt(b.item(j), m) : NaN;
        if (!isNaN_(n)) {
            if (n < g.left + 0.1 * g.width) {
                n = n + 0.4 * g.width;
                g.x = n - 0.5 * g.width;
            }
            if (n > g.right - 0.1 * g.width) {
                n = n - 0.4 * g.width;
                g.x = n - 0.5 * g.width;
            }
        }
        if (!isNaN_(o)) {
            if (o < g.top + 0.1 * g.height) {
                o = o + 0.4 * g.height;
                g.y = o - 0.5 * g.height;
            }
            if (o > g.bottom - 0.1 * g.height) {
                o = o - 0.4 * g.height;
                g.y = o - 0.5 * g.height;
            }
        }
        if (a.bn != null) {
            a.bn.ap(a.bs, g, true);
        }
        return j >= 0;
    };
    AnchoredCategorySeriesInteractionManager.prototype.c$c = function (a, b) {
        var c = "<div class='ui-chart-default-tooltip-content'>";
        var d = null;
        d = a.ap();
        if (d.b5) {
            var e = d;
            c += "<span>${item." + e.dateTimeMemberPath + "}</span><br/>";
        }
        else if (d != null && d.e2 != null) {
            c += "<span>${item." + d.e2 + "}</span><br/>";
        }
        c += "<span";
        var f = a.a0.a$q(a);
        if (!stringIsNullOrEmpty(f)) {
            c += " style='color:" + f + "'";
        }
        c += ">${series.title}: </span><span class='ui-priority-primary'>" + "${item." + b + "}</span></div>";
        return c;
    };
    AnchoredCategorySeriesInteractionManager.prototype.c$d = function (a, b, c, d, e, f, g, h) {
        if (c == null || d == null) {
            return Rect.empty;
        }
        var i = a.k9(b);
        var j = a.bi.bs;
        var k = a.bi.br;
        var l = a.getEffectiveViewport1(a.bi);
        var m = new ScalerParams(0, j, k, d.b8, l);
        m.b = a.ee();
        var n = a.aj(a.ap(), e.f, f, g, b, true);
        if (n == null) {
            return Rect.empty;
        }
        var o = n[0];
        var p = n[1];
        var q = Math.abs(i.x - o[0]);
        var r = Math.abs(i.x - p[0]);
        var s = d.dt(d.j7, m);
        var t = c.jk(j, k, l);
        if (q < r) {
            var u = o[0] - 0.5 * t;
            var v = h(o);
            var w = s;
            return new Rect(0, u, Math.min(v, w), t, Math.max(v, w) - Math.min(v, w));
        }
        else {
            var x = p[0] - 0.5 * t;
            var y = h(p);
            var z = s;
            return new Rect(0, x, Math.min(y, z), t, Math.max(y, z) - Math.min(y, z));
        }
    };
    AnchoredCategorySeriesInteractionManager.$t = markType(AnchoredCategorySeriesInteractionManager, 'AnchoredCategorySeriesInteractionManager', Base.$, [IAnchoredCategorySeriesInteractionManager_$type]);
    return AnchoredCategorySeriesInteractionManager;
}(Base));
export { AnchoredCategorySeriesInteractionManager };
