/*
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, 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
 */
export let CategorySeriesInteractionManager = /*@__PURE__*/ (() => {
    class CategorySeriesInteractionManager extends Base {
        b$c(a, b) {
            let c = a.bs.bv;
            let d = a.bs.bu;
            let e = a.aq();
            let f = a.getEffectiveViewport1(a.bs);
            let g = a.ny(a.bs);
            let h = -1;
            if (e != null && !c.isEmpty && !d.isEmpty) {
                let i = new ScalerParams(0, c, d, e.ca, f);
                let j = e.d2(g.left, i);
                let k = e.d2(g.right, i);
                let l = (b.x - c.left) / c.width;
                let m = j + (l * (k - j));
                if (e.categoryMode != 0) {
                    m -= 0.5;
                }
                h = m;
            }
            return h;
        }
        b$f(a, b) {
            let 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;
        }
        b$d(a, b) {
            let c = a.bs.bv;
            let d = a.bs.bu;
            let e = a.getEffectiveViewport1(a.bs);
            if (c.isEmpty || d.isEmpty) {
                return -1;
            }
            if (isNaN_(b.x)) {
                return -1;
            }
            let f = a.aq();
            if (f == null) {
                return -1;
            }
            let g = typeCast(ISortingAxis_$type, f);
            let h = a.ny(a.bs);
            let i = new ScalerParams(0, c, d, f.ca, e);
            let j = 0;
            if (f.cd) {
                let k = (b.x - c.left) / c.width;
                let l = k * h.width + h.left;
                j = f.d2(l, i);
            }
            else {
                let m = f.d2(h.left, i);
                let n = f.d2(h.right, i);
                let o = (b.x - c.left) / c.width;
                j = m + ((n - m) * o);
            }
            let p = g.i$f(j);
            return p;
        }
        b$e(a, b, c) {
            let d = a.bs.bu;
            let e = a.bs.bv;
            let f = a.aq();
            let g = 0;
            if (f.ch) {
                let h = (c.y - e.top) / e.height;
                g = h * d.height + d.top;
            }
            else {
                let i = (c.x - e.left) / e.width;
                g = i * d.width + d.left;
            }
            if (f.ca) {
                let j = b.count;
                let k = 0;
                for (k = j - 1; k >= 0; k--) {
                    let l = b._inner[k];
                    let 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 {
                let n = b.count;
                let o = 0;
                for (o = 0; o < n; o++) {
                    let p = b._inner[o];
                    let 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;
            }
        }
        b$a(a, b, c, d, e, f, g, h) {
            if (a.cd == null) {
                return null;
            }
            if (e == 0) {
                return null;
            }
            let i = a.cd.count;
            let j = a.aq();
            let k = -1;
            let l = -1;
            if (j.cf) {
                let m = this.b$e(a, b, g);
                k = m;
                l = m;
            }
            else {
                let 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;
            }
            let o = new HighlightingInfo();
            o.b = a;
            o.h = k;
            o.g = l;
            return o;
        }
        b$b(a, b, c, d, e, f, g, h) {
            if (a.cd == null) {
                return null;
            }
            if (d == 0) {
                return null;
            }
            let i = a.cd.count;
            let j = a.aq();
            let k = -1;
            let l = -1;
            let m = -1;
            if (j.cf) {
                let n = this.b$e(a, e, g);
                m = n;
                k = n;
                l = n;
            }
            else {
                let 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;
            }
            let p = b;
            let q = p.count;
            if (p == null) {
                return null;
            }
            if (q == 0) {
                return null;
            }
            for (let r = 0; r < q; r++) {
                if (p._inner[r].al == m) {
                    let s = new HighlightingInfo();
                    s.b = a;
                    s.h = p._inner[r].al;
                    s.g = p._inner[r].al;
                    s.e = true;
                    return s;
                }
            }
            let t = a.no(g);
            let u = p._inner[0].al;
            if (a.isVertical) {
                let v = e._inner[p._inner[0].al][0];
                let w = (t.y - v) * (t.y - v);
                let x;
                for (let 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 {
                let z = e._inner[p._inner[0].al][0];
                let aa = (t.x - z) * (t.x - z);
                let ab;
                for (let 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;
                    }
                }
            }
            let 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 = /*@__PURE__*/ markType(CategorySeriesInteractionManager, 'CategorySeriesInteractionManager', Base.$, [ICategorySeriesInteractionManager_$type]);
    return CategorySeriesInteractionManager;
})();
//# sourceMappingURL=CategorySeriesInteractionManager.js.map
