/*
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, markType } from "igniteui-react-core";
import { IAnchoredCategorySeriesInteractionManager_$type } from "./IAnchoredCategorySeriesInteractionManager";
import { Rect } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { truncate, intDivide, isNaN_ } from "igniteui-react-core";
import { stringIsNullOrEmpty } from "igniteui-react-core";
/**
 * @hidden
 */
export let AnchoredCategorySeriesInteractionManager = /*@__PURE__*/ (() => {
    class AnchoredCategorySeriesInteractionManager extends Base {
        c$b(a, b, c, d, e, f, g, h) {
            if (!g) {
                return h(b);
            }
            if (e == null || e.cf || f == null || d == null || isNaN_(b.x) || isNaN_(b.y)) {
                return h(b);
            }
            if (c <= 1) {
                return h(b);
            }
            let i = truncate(Math.round(a.e4(b)));
            if (i < 0 || i >= a.cd.count) {
                return h(b);
            }
            let j = intDivide(i, c);
            let k = c * j;
            let l = Math.min(k + c, d.count - 1);
            let m = a.ny(a.bs);
            let n = new ScalerParams(0, a.b6.o8, a.b6.o7, f.ca, a.b6.ow);
            let o = m.top;
            let p = m.bottom;
            let q = o + (p - o) * b.y;
            let r = f.d2(q, n);
            let s = 1.7976931348623157E+308;
            let t = k;
            for (let u = k; u <= l; u++) {
                let v = Math.abs(d.item(u) - r);
                if (v < s) {
                    s = v;
                    t = u;
                }
            }
            return a.cd.item(t);
        }
        c$a(a, b, c, d, e, f) {
            let g = a.bs.bv;
            g = g.copy();
            let h = a.bs.bu;
            let i = new Rect(0, 0, 0, 1, 1);
            let j = !g.isEmpty && !h.isEmpty && a.cd != null ? a.cd.indexOf(f) : -1;
            let k = a.n0(a.bs);
            let l = new ScalerParams(0, i, i, c.ca, k);
            let m = new ScalerParams(0, i, i, d.ca, k);
            m.b = a.fa();
            let n = c != null ? c.dz(j, l) : NaN;
            n += e;
            let o = d != null && b != null && j < b.count ? d.dz(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.b1 != null) {
                a.b1.ap(a.b6, g, true);
            }
            return j >= 0;
        }
        c$c(a, b) {
            let c = "<div class='ui-chart-default-tooltip-content'>";
            let d = null;
            d = a.aq();
            if (d.b7) {
                let e = d;
                c += "<span>${item." + e.dateTimeMemberPath + "}</span><br/>";
            }
            else if (d != null && d.fa != null) {
                c += "<span>${item." + d.fa.toString() + "}</span><br/>";
            }
            c += "<span";
            let f = a.a3.a$r(a);
            if (!stringIsNullOrEmpty(f)) {
                c += " style='color:" + f + "'";
            }
            c += ">${series.title}: </span><span class='ui-priority-primary'>" + "${item." + b + "}</span></div>";
            return c;
        }
        c$d(a, b, c, d, e, f, g, h) {
            if (c == null || d == null) {
                return Rect.empty;
            }
            let i = a.no(b);
            let j = a.bs.bv;
            let k = a.bs.bu;
            let l = a.getEffectiveViewport1(a.bs);
            let m = new ScalerParams(0, j, k, d.ca, l);
            m.b = a.fa();
            let n = a.aj(a.aq(), e.f, f, g, b, true);
            if (n == null) {
                return Rect.empty;
            }
            let o = n[0];
            let p = n[1];
            let q = Math.abs(i.x - o[0]);
            let r = Math.abs(i.x - p[0]);
            let s = d.dz(d.kn, m);
            let t = c.j0(j, k, l);
            if (q < r) {
                let u = o[0] - 0.5 * t;
                let v = h(o);
                let w = s;
                return new Rect(0, u, Math.min(v, w), t, Math.max(v, w) - Math.min(v, w));
            }
            else {
                let x = p[0] - 0.5 * t;
                let y = h(p);
                let z = s;
                return new Rect(0, x, Math.min(y, z), t, Math.max(y, z) - Math.min(y, z));
            }
        }
    }
    AnchoredCategorySeriesInteractionManager.$t = /*@__PURE__*/ markType(AnchoredCategorySeriesInteractionManager, 'AnchoredCategorySeriesInteractionManager', Base.$, [IAnchoredCategorySeriesInteractionManager_$type]);
    return AnchoredCategorySeriesInteractionManager;
})();
//# sourceMappingURL=AnchoredCategorySeriesInteractionManager.js.map
