/*
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, Point_$type, Array_$type, toNullable, String_$type, fromEnum, markType } from "igniteui-react-core";
import { ISeriesInteractionManager_$type } from "./ISeriesInteractionManager";
import { HighlightingInfo } from "igniteui-react-core";
import { Dictionary$2 } from "igniteui-react-core";
import { List$1 } from "igniteui-react-core";
import { SeriesView } from "./SeriesView";
import { ScalerParams } from "./ScalerParams";
import { GeometryUtil } from "igniteui-react-core";
import { PolygonUtil } from "igniteui-react-core";
import { RectUtil } from "igniteui-react-core";
import { BrushUtil } from "igniteui-react-core";
import { Color } from "igniteui-react-core";
import { truncate, isNaN_ } from "igniteui-react-core";
import { boxArray$1 } from "igniteui-react-core";
import { stringIsNullOrEmpty } from "igniteui-react-core";
/**
 * @hidden
 */
export let SeriesInteractionManager = /*@__PURE__*/ (() => {
    class SeriesInteractionManager extends Base {
        constructor() {
            super(...arguments);
            this.a = null;
            this.b = null;
            this.o = new Dictionary$2(Base.$, List$1.$.specialize(HighlightingInfo.$), 0);
            this.n = new Dictionary$2(Base.$, List$1.$.specialize(HighlightingInfo.$), 0);
            this.c = false;
            this.p = null;
            this.a$s = null;
            this.a$e = false;
            this.k = false;
            this.d = false;
            this.e = false;
            this.f = true;
            this.g = false;
            this._toolTipObject = null;
            this.v = null;
            this.ac = null;
            this.u = null;
            this.l = false;
            this.m = new Dictionary$2(String_$type, SeriesView.$, 0);
        }
        a$m(a, b, c, d, e, f, g, h) {
            if (d == null) {
                return Number.POSITIVE_INFINITY;
            }
            if (c < 0 || c > g - 1) {
                return Number.POSITIVE_INFINITY;
            }
            let i;
            let j = NaN;
            let k = NaN;
            let l = NaN;
            let m = NaN;
            if (d.cn) {
                let n = d;
                i = h(b);
                let o = truncate(Math.floor(i));
                let p = truncate(Math.ceil(i));
                m = i - o;
                if (o >= 0 && o < g) {
                    let q = n.i$d(n.i$b._inner[o]);
                    j = d.ek(q, e) + f;
                }
                else {
                    j = NaN;
                }
                if (p >= 0 && p < g) {
                    let r = n.i$d(n.i$b._inner[p]);
                    k = d.ek(r, e) + f;
                }
                else {
                    k = NaN;
                }
                if (isNaN_(j) && !isNaN_(k)) {
                    j = k;
                }
                if (isNaN_(k) && !isNaN_(j)) {
                    k = j;
                }
                if (c >= 0 && c < g) {
                    let s = n.i$d(n.i$b._inner[c]);
                    l = d.ek(s, e) + f;
                }
            }
            else {
                i = a.ip(b);
                let t = truncate(Math.floor(i));
                let u = truncate(Math.ceil(i));
                m = i - t;
                if (t >= 0 && t < g) {
                    j = d.ek(t, e) + f;
                }
                else {
                    j = NaN;
                }
                if (u > g - 1 && a.fr) {
                    u = 0;
                }
                if (u >= 0 && u < g) {
                    k = d.ek(u, e) + f;
                }
                else {
                    k = NaN;
                }
                if (isNaN_(j) && !isNaN_(k)) {
                    j = k;
                }
                if (isNaN_(k) && !isNaN_(j)) {
                    k = j;
                }
                if (c >= 0 && c < g) {
                    l = d.ek(c, e) + f;
                }
            }
            let v = j + m * (k - j);
            return Math.abs(l - v);
        }
        a$o(a, b, c, d, e, f, g, h, i) {
            let j = NaN;
            if (d >= 0 && d < c.count) {
                j = c.item(d);
            }
            let k = NaN;
            if (e >= 0 && e < c.count) {
                k = c.item(e);
            }
            if (g == 0) {
                return k;
            }
            if (f == c.count - 1) {
                return j;
            }
            if (isNaN_(k) && h != 0 && b <= 0.5 && !i) {
                return j;
            }
            if (isNaN_(j) && h != 0 && b >= 0.5 && !i) {
                return k;
            }
            return j * (1 - b) + k * b;
        }
        a$b(a, b, c, d, e, f, g) {
            if (b == null) {
                return null;
            }
            let h = -1;
            let i = -1;
            let j = this.a$a(a, b, c, d, e, f, g);
            if (b.b9) {
                c = this.q(c);
            }
            if (j == null) {
                return null;
            }
            h = j[0];
            i = j[1];
            if (h < 0) {
                h = 0;
            }
            if (h > c.count - 1) {
                h = c.count - 1;
            }
            if (i < 0) {
                i = 0;
            }
            if (i > c.count - 1) {
                i = c.count - 1;
            }
            if (h < 0 || i < 0) {
                return null;
            }
            let k = c._inner[h];
            let l = c._inner[i];
            let m = new Array(2);
            m[0] = k;
            m[1] = l;
            return m;
        }
        a$a(a, b, c, d, e, f, g) {
            if (b == null) {
                return null;
            }
            let h = -1;
            let i = -1;
            if (b.cn || b.cl) {
                let j = a.v1(f);
                let k = -1;
                let l = b.ch;
                let m = a.ct.bx.right * 2;
                if (b.b9) {
                    let n = b.d4(f);
                    j = { $type: Point_$type, x: n, y: 0 };
                    c = this.q(c);
                }
                k = SeriesInteractionManager.t(c, j, l, m);
                if (k < 0) {
                    k = ~k;
                    k--;
                }
                if (k < 0) {
                    k = 0;
                }
                if (k > c.count - 1) {
                    k = c.count - 1;
                }
                let o = k;
                let p = k + 1;
                if (p > c.count - 1) {
                    p = c.count - 1;
                }
                h = o;
                i = p;
            }
            else {
                let q = a.j8(f, g);
                let r = a.j6(f, g);
                let s = truncate(Math.floor(q / d));
                let t = truncate(Math.floor(r / d));
                h = s - e;
                i = t - e;
                if (i == h) {
                    i++;
                }
            }
            return [h, i];
        }
        q(a) {
            let b = NaN;
            let c = -1;
            for (let d = 0; d < a.count; d++) {
                let e = a._inner[d];
                if (isNaN_(b)) {
                    b = e[0];
                }
                else {
                    let f = e[0];
                    if (f < b) {
                        c = d;
                        break;
                    }
                }
            }
            if (c == -1) {
                return a;
            }
            let g = new List$1(Array_$type, 0);
            for (let h = c; h < a.count; h++) {
                g.add(a._inner[h]);
            }
            for (let i = 0; i < c; i++) {
                g.add(a._inner[i]);
            }
            return g;
        }
        static t(a, b, c, d) {
            let e = 0;
            let f = a.count - 1;
            while (e <= f) {
                let g = (e + ((f - e) >> 1));
                let h;
                let i = a.item(g);
                if (c) {
                    h = (d - b.x) < (d - i[0]) ? -1 : ((d - b.x) > (d - i[0]) ? 1 : 0);
                }
                else {
                    h = b.x < i[0] ? -1 : (b.x > i[0] ? 1 : 0);
                }
                if (h < 0) {
                    f = g - 1;
                }
                else if (h > 0) {
                    e = g + 1;
                }
                else {
                    return g;
                }
            }
            return ~e;
        }
        a$r(a, b, c, d, e, f) {
            if (d == null) {
                return -1;
            }
            let g = d.cn;
            let h = a.hb;
            let i = null;
            if (g) {
                i = d;
            }
            let j = -1;
            let k = -1;
            let l = -1;
            if (g) {
                j = e(b);
                if (isNaN_(j)) {
                    return -1;
                }
                k = truncate(Math.floor(j));
                l = truncate(Math.ceil(j));
            }
            else {
                j = a.ip(b);
                if (isNaN_(j)) {
                    return -1;
                }
                k = truncate(Math.floor(j));
                l = truncate(Math.ceil(j));
            }
            if (f == null) {
                return -1;
            }
            if (k < 0 || k > f.count - 1) {
                return -1;
            }
            if (!c) {
                return k;
            }
            let m = NaN;
            if (g && !h) {
                if (k < i.i$b.count && i.i$b._inner[k] < f.count) {
                    m = f.item(i.i$b._inner[k]);
                }
            }
            else {
                m = f.item(k);
            }
            while (isNaN_(m)) {
                k--;
                if (k < 0 || k > f.count - 1) {
                    return -1;
                }
                if (g && !h) {
                    m = f.item(i.i$b._inner[k]);
                }
                else {
                    m = f.item(k);
                }
            }
            return k;
        }
        a$p(a, b, c, d, e, f, g, h, i) {
            if (b == null) {
                return NaN;
            }
            let j = a.hb;
            let k = a.j9(c, i, d, g, b);
            let l = a.j7(c, i, d, g, b);
            let m = a.im(c, k, d, e, f);
            let n = a.im(c, l, d, e, f);
            let o = k;
            let p = l;
            let q = d.cn;
            if (q && !j) {
                let r = d;
                if (k >= 0 && k < r.i$b.count) {
                    k = r.i$b._inner[k];
                }
                if (l >= 0 && k < r.i$b.count) {
                    l = r.i$b._inner[l];
                }
            }
            let s = m / (n + m);
            if (m == 0) {
                s = 0;
            }
            if (n == 0) {
                s = 1;
            }
            if (!h) {
                if (n <= m) {
                    if (l >= 0 && l < b.count) {
                        return b.item(l);
                    }
                }
                else {
                    if (k >= 0 && k < b.count) {
                        return b.item(k);
                    }
                }
                return NaN;
            }
            return a.it(s, b, k, l, o, p, f, q);
        }
        a$f(a, b, c) {
            let d = a.ak(b);
            let e = a.aj(b);
            if (d == null) {
                return false;
            }
            for (let f = 0; f < d.length; f++) {
                let g = d[f];
                if (g == null || g.length != 2) {
                    continue;
                }
                if (GeometryUtil.c(b, g[0], g[1], a.ic / 2 + a.is(c))) {
                    return true;
                }
                if (e != null && f < e.length) {
                    let h = e[f];
                    if (h == null || h.length != 2) {
                        continue;
                    }
                    if (GeometryUtil.c(b, h[0], h[1], a.ic / 2 + a.is(c))) {
                        return true;
                    }
                    if (GeometryUtil.c(b, g[0], h[0], a.ic / 2 + a.is(c))) {
                        return true;
                    }
                    if (GeometryUtil.c(b, g[1], h[1], a.ic / 2 + a.is(c))) {
                        return true;
                    }
                    let i = new Array(5);
                    i[0] = h[0];
                    i[1] = h[1];
                    i[2] = g[1];
                    i[3] = g[0];
                    i[4] = h[0];
                    if (PolygonUtil.b(boxArray$1(i), b)) {
                        return true;
                    }
                }
            }
            return false;
        }
        a$g(a, b, c, d) {
            if (d == null) {
                return false;
            }
            for (let e = 0; e < d.c.count; e++) {
                let f = d.c._inner[e];
                for (let g = 0; g < f._segments.count; g++) {
                    let h = f._segments._inner[g];
                    if (GeometryUtil.d(b, f._startPoint, h._points, a.is(c))) {
                        return true;
                    }
                }
            }
            return false;
        }
        a$h(a, b, c) {
            if (c == null) {
                return false;
            }
            if (c.c.count > 0) {
                let d = c.c._inner[0];
                if (d._segments.count > 0) {
                    let e = d._segments._inner[0];
                    if (PolygonUtil.b(e._points, b)) {
                        return true;
                    }
                }
            }
            return false;
        }
        a$q(a, b, c, d, e, f) {
            let g = a.hb;
            let h = d.cn;
            let i = null;
            if (h) {
                i = d;
            }
            let j = -1;
            let k = -1;
            let l = -1;
            if (h) {
                j = e(b);
                if (isNaN_(j)) {
                    return -1;
                }
                k = truncate(Math.floor(j));
                l = truncate(Math.ceil(j));
            }
            else {
                j = a.ip(b);
                if (isNaN_(j)) {
                    return -1;
                }
                k = truncate(Math.floor(j));
                l = truncate(Math.ceil(j));
            }
            if (f == null) {
                return -1;
            }
            if (l < 0 || l > f.count - 1) {
                if (a.fr) {
                    if (l > f.count - 1) {
                        return 0;
                    }
                }
                return -1;
            }
            if (!c) {
                return l;
            }
            let m = NaN;
            if (h && !g) {
                if (l < i.i$b.count && i.i$b._inner[l] < f.count) {
                    m = f.item(i.i$b._inner[l]);
                }
            }
            else {
                m = f.item(l);
            }
            while (isNaN_(m)) {
                l++;
                if (l < 0 || l > f.count - 1) {
                    return -1;
                }
                if (h && !g) {
                    m = f.item(i.i$b._inner[l]);
                }
                else {
                    m = f.item(l);
                }
            }
            return l;
        }
        a$n(a, b, c) {
            let d = a.ct.by;
            let e = a.ct.bx;
            if (d.isEmpty || e.isEmpty || c == null) {
                return -1;
            }
            let f = a.getEffectiveViewport1(a.ct);
            let g = null;
            if (c.cn) {
                g = c;
            }
            let h = new ScalerParams(0, d, e, c.ch, f);
            if (a.c9 == null) {
                return -1;
            }
            h.c = a.getEffectiveViewport1(a.ct);
            let i = a.wd(a.ct);
            let j = 0;
            if (c.cp) {
                let k = c.en(i.top, h);
                let l = c.en(i.bottom, h);
                let m = (b.y - d.top) / d.height;
                j = k + ((l - k) * m);
            }
            else {
                if (c.cc) {
                    let n = c.en(i.left, h);
                    let o = c.en(i.right, h);
                    let p = (b.x - d.left) / d.width;
                    j = n + ((o - n) * p);
                }
                else {
                    let q = a.v1(b);
                    j = c.en(q.x, h);
                }
            }
            if (c.ce) {
            }
            let r = g.i$c(j);
            return r;
        }
        a$i(a, b, c) {
            let d = a.wi(b);
            if (d.isEmpty) {
                return false;
            }
            let e = RectUtil.r(d, a.is(c));
            return e.containsPoint(b);
        }
        a$au(a, b, c, d, e, f, g, h, i, j) {
            if (f == null || g == null || a.ct == null || a.ct.by.isEmpty || a.ct.bx.isEmpty) {
                return { $type: Point_$type, x: NaN, y: NaN };
            }
            let k = a.getEffectiveViewport1(a.ct);
            let l = new ScalerParams(0, a.ct.by, a.ct.bx, f.ch, k);
            if (f.cp) {
                l.b = a.iw();
            }
            l.c = a.getEffectiveViewport1(a.ct);
            let m = a.ct;
            let n = a.wd(m);
            let o;
            if (g.cp) {
                o = b.y;
                o = n.top + n.height * (o - m.by.top) / m.by.height;
            }
            else {
                o = b.x;
                o = n.left + n.width * (o - m.by.left) / m.by.width;
            }
            if (!c && g != null) {
                let p;
                let q;
                if (i != null) {
                    p = i(b, d);
                }
                else {
                    p = a.j8(b, d);
                }
                if (j != null) {
                    q = j(b, d);
                }
                else {
                    q = a.j6(b, d);
                }
                if (p == -1 && q == -1) {
                    return { $type: Point_$type, x: NaN, y: NaN };
                }
                let r = new ScalerParams(0, m.by, m.bx, g.ch, k);
                r.c = a.c9.vp;
                let s = a.im(b, p, g, r, e);
                let t = a.im(b, q, g, r, e);
                let u = q;
                let v = p;
                if (g.cn) {
                    let w = g;
                    if (u >= 0 && u < w.i$b.count) {
                        u = w.i$d(w.i$b._inner[truncate(u)]);
                    }
                    if (v >= 0 && v < w.i$b.count) {
                        v = w.i$d(w.i$b._inner[truncate(v)]);
                    }
                }
                if ((t + s) != 0) {
                    let x = t / (s + t);
                    if (Math.abs(x - 0.5) < 1E-07) {
                        t = s;
                    }
                }
                if (t <= s) {
                    o = g.ek(u, r) + e;
                }
                else {
                    o = g.ek(v, r) + e;
                }
            }
            else {
                if (g.cb && !g.ce && g.categoryMode != 0) {
                    let y = 0.5 * g.getCategorySize(m.by, m.bx, a.getEffectiveViewport1(m));
                    if (a.isVertical) {
                        y = y * -1;
                    }
                    if (g.ch) {
                        y = y * -1;
                    }
                    o -= y;
                    o += e;
                }
            }
            let z;
            if (h != null) {
                z = h(b, c, d);
            }
            else {
                z = a.i3(b, c, d);
            }
            let aa = f.ek(z, l);
            if (g.cp) {
                return { $type: Point_$type, x: aa, y: o };
            }
            else {
                return { $type: Point_$type, x: o, y: aa };
            }
        }
        a$y() {
            this.a = null;
            this.b = null;
        }
        get a$d() {
            return this.o.count > 0;
        }
        a$x(a, b, c) {
            if (!this.o.containsKey(b)) {
                let d = new List$1(HighlightingInfo.$, 0);
                let e = new HighlightingInfo();
                e.d = true;
                e.i = a;
                e.g = c;
                e.f = c;
                e.b = false;
                d.add(e);
                e = new HighlightingInfo();
                e.d = false;
                e.i = a;
                e.g = c;
                e.f = c;
                e.b = false;
                d.add(e);
                this.o.item(b, d);
                a.c9.dk.startHighlight(d._inner[0]);
                a.c9.dk.startHighlight(d._inner[1]);
                if (a.gc) {
                    a.pr();
                }
                this.y(a);
            }
        }
        a$v(a) {
            if (!this.c) {
                this.c = true;
                let b = new List$1(HighlightingInfo.$, 0);
                let c = new HighlightingInfo();
                c.d = true;
                c.i = a;
                c.c = true;
                c.g = 0;
                c.f = a.dl.count - 1;
                c.b = false;
                b.add(c);
                c = new HighlightingInfo();
                c.d = false;
                c.i = a;
                c.c = true;
                c.g = 0;
                c.f = a.dl.count - 1;
                c.b = false;
                b.add(c);
                this.p = b;
                a.c9.dk.startHighlight(b._inner[0]);
                a.c9.dk.startHighlight(b._inner[1]);
                if (a.gc) {
                    a.pr();
                }
                this.y(a);
            }
        }
        a$ao(a) {
            if (this.c) {
                this.c = false;
                let b = this.p;
                this.p = null;
                a.c9.dk.endHighlight(b._inner[0]);
                a.c9.dk.endHighlight(b._inner[1]);
                if (a.gc) {
                    a.pr();
                }
                this.y(a);
            }
        }
        a$an(a, b, c) {
            if (this.o.containsKey(b)) {
                let d = this.o.item(b);
                this.o.removeItem(b);
                a.c9.dk.endHighlight(d._inner[0]);
                a.c9.dk.endHighlight(d._inner[1]);
                if (a.gc) {
                    a.pr();
                }
                this.y(a);
            }
        }
        a$w(a, b, c) {
            if (!this.n.containsKey(b)) {
                let d = new List$1(HighlightingInfo.$, 0);
                let e = new HighlightingInfo();
                e.d = true;
                e.i = a;
                e.g = c;
                e.f = c;
                e.b = false;
                d.add(e);
                e = new HighlightingInfo();
                e.d = false;
                e.i = a;
                e.g = c;
                e.f = c;
                e.b = false;
                d.add(e);
                this.n.item(b, d);
                a.c9.di.startHighlight(d._inner[0]);
                a.c9.di.startHighlight(d._inner[1]);
                if (a.gc) {
                    a.pr();
                }
                this.x(a);
            }
        }
        a$am(a, b, c) {
            if (this.n.containsKey(b)) {
                let d = this.n.item(b);
                this.n.removeItem(b);
                a.c9.di.endHighlight(d._inner[0]);
                a.c9.di.endHighlight(d._inner[1]);
                if (a.gc) {
                    a.pr();
                }
                this.x(a);
            }
        }
        a$ab(a, b, c, d, e, f, g, h, i) {
            if (d) {
                return;
            }
            if (a.c9.fj() && !f) {
                return;
            }
            if (a.bv == 1) {
                return;
            }
            if (a.c9 == null) {
                return;
            }
            let j = a.c9.bv;
            let k = j == 2 || j == 3 || j == 4;
            let l = j == 2 || j == 4;
            if (!g) {
                if (k) {
                    e = false;
                }
            }
            if ((a.eb && a.eh) || g) {
                l = false;
            }
            if (j == 2) {
                h = false;
            }
            if (j == 3) {
                h = true;
            }
            let m = null;
            let n = null;
            let o = a.c9.dj;
            let p = a.c9.da;
            let q = (f && g) || (f && !k) || i || (l && !h);
            let r = !q && (g || e || (k && !l) || (k && l && h));
            let s = (f && (!k || g)) || i || (!a.eh && k && l && !h);
            let t = !s && (e || (k && a.eh) || (!a.eh && k && !l) || (!a.eh && k && l && h));
            if (q && this.a != null) {
                m = this.a;
            }
            else {
                m = a.de(b, c, g);
                if (this.a != null && this.a != m) {
                    if (a.c9 != null) {
                        o.endHighlight(this.a);
                    }
                }
                this.a = m;
            }
            if (a.hasMarkers) {
                if (s && this.b != null) {
                    n = this.b;
                }
                else {
                    n = a.df(b, c, g);
                    if (this.b != null && this.b != n) {
                        o.endHighlight(this.b);
                    }
                    this.b = n;
                }
            }
            if (q) {
                o.endHighlight(m);
            }
            else {
                if (r) {
                    if (m != null && m.c) {
                        m.b = g || !k;
                    }
                    o.startHighlight(m);
                }
            }
            if (s) {
                if (n != null) {
                    o.endHighlight(n);
                }
            }
            else {
                if (t) {
                    if (n != null) {
                        o.startHighlight(n);
                    }
                }
            }
            this.w(a);
        }
        w(a) {
            if (a.c9 != null) {
                let b = a.c9.da;
                if (!b.f() && b.r > 0) {
                    b.v();
                }
                if (b.r == 0) {
                    let c = a.c9.f8(1);
                    while (c) {
                        c = a.c9.f8(0);
                        c = a.c9.f8(1);
                    }
                }
            }
        }
        y(a) {
            if (a.c9 != null) {
                let b = a.c9.dc;
                if (!b.f() && b.r > 0) {
                    b.v();
                }
                if (b.r == 0) {
                    let c = a.c9.f9(1);
                    while (c) {
                        c = a.c9.f9(0);
                        c = a.c9.f9(1);
                    }
                }
            }
        }
        x(a) {
            if (a.c9 != null) {
                let b = a.c9.c9;
                if (!b.f() && b.r > 0) {
                    b.v();
                }
                if (b.r == 0) {
                    let c = a.c9.f7(1);
                    while (c) {
                        c = a.c9.f7(0);
                        c = a.c9.f7(1);
                    }
                }
            }
        }
        a$k(a, b, c, d, e, f, g, h, i, j, k, l, m) {
            if (a.bv != 5 && a.bv != 4 && a.cn != 3 && a.cm != 3) {
                return e;
            }
            else if (a.bv == 5 || a.bv == 4 || a.cn == 3 || a.cm == 3) {
                let n = 0;
                let o = 0;
                let p = 0;
                if (b != null) {
                    n = b.e;
                }
                if (c != null) {
                    o = c.e;
                }
                if (d != null) {
                    p = d.e;
                }
                if (n > 1) {
                    n = 1;
                }
                if (o > 1) {
                    o = 1;
                }
                if (p > 1) {
                    p = 1;
                }
                if (f > 1) {
                    f = 1;
                }
                if (g > 1) {
                    g = 1;
                }
                if (h > 1) {
                    h = 1;
                }
                if (i > 1) {
                    i = 1;
                }
                if (j > 1) {
                    j = 1;
                }
                if (k > 1) {
                    k = 1;
                }
                let q = Math.max(f, g);
                let r = Math.max(h, i);
                let s = Math.max(j, k);
                if (a.bv != 4 && a.bv != 5) {
                    q = 0;
                    n = 0;
                }
                if (a.cn != 3) {
                    r = 0;
                    o = 0;
                }
                if (a.cm != 3) {
                    s = 0;
                    p = 0;
                }
                let t = Math.max(q, Math.max(r, s));
                n = n - t;
                o = o - t;
                p = p - t;
                let u = Math.max(n, Math.max(o, p));
                e = l + (1 + u) * (1 - l);
                return e;
            }
            else {
                return e;
            }
        }
        a$at(a, b, c, d, e, f, g, h, i, j, k, l) {
            if (l && (a.cn == 7 || a.cm == 7 || a.cn == 8 || a.cm == 8 || a.cn == 5 || a.cm == 5 || a.cn == 6 || a.cm == 6)) {
                let m = 0;
                let n = 0;
                let o = 0;
                if (c != null) {
                    n = c.e;
                }
                if (d != null) {
                    o = d.e;
                }
                if (a.cn != 7 && a.cn != 8 && a.cn != 5 && a.cn != 6) {
                    n = 0;
                }
                if (a.cm != 7 && a.cm != 8 && a.cm != 5 && a.cm != 6) {
                    o = 0;
                }
                let p = a.vd;
                if (this.j(a.cn, l)) {
                    p = a.vb;
                }
                if (this.j(a.cm, l)) {
                    p = a.vb;
                }
                let q = Math.max(m, Math.max(o, n));
                k = this.ab(a, k, p, q);
            }
            if (!l && (a.cn == 10 || a.cm == 9 || a.cn == 9 || a.cm == 10)) {
                let r = 0;
                let s = 0;
                let t = 0;
                if (c != null) {
                    s = c.e;
                }
                if (d != null) {
                    t = d.e;
                }
                if (a.cn != 10 && a.cn != 9) {
                    s = 0;
                }
                if (a.cm != 10 && a.cm != 9) {
                    t = 0;
                }
                let u = a.vd;
                if (this.j(a.cn, l)) {
                    u = a.vb;
                }
                if (this.j(a.cm, l)) {
                    u = a.vb;
                }
                let v = Math.max(r, Math.max(t, s));
                k = this.ab(a, k, u, v);
            }
            if ((a.cn == 4 || a.cm == 4)) {
                let w = 0;
                let x = 0;
                let y = 0;
                if (b != null) {
                    w = b.e;
                }
                if (c != null) {
                    x = c.e;
                }
                if (d != null) {
                    y = d.e;
                }
                if (w > 1) {
                    w = 1;
                }
                if (x > 1) {
                    x = 1;
                }
                if (y > 1) {
                    y = 1;
                }
                if (e > 1) {
                    e = 1;
                }
                if (f > 1) {
                    f = 1;
                }
                if (g > 1) {
                    g = 1;
                }
                if (h > 1) {
                    h = 1;
                }
                if (i > 1) {
                    i = 1;
                }
                if (j > 1) {
                    j = 1;
                }
                let z = Math.max(e, f);
                let aa = Math.max(g, h);
                let ab = Math.max(i, j);
                {
                    z = 0;
                    w = 0;
                }
                if (a.cn != 4) {
                    aa = 0;
                    x = 0;
                }
                if (a.cm != 4) {
                    ab = 0;
                    y = 0;
                }
                let ac = Math.max(z, Math.max(aa, ab));
                w = w - ac;
                x = x - ac;
                y = y - ac;
                let ad = Math.max(w, Math.max(x, y));
                ad = Math.abs(ad);
                let ae = BrushUtil.t(k);
                k = this.ab(a, k, ae, ad);
            }
            if (a.bv == 3 || a.bv == 2 || a.cn == 2 || a.cm == 2) {
                let af = 0;
                let ag = 0;
                let ah = 0;
                if (b != null) {
                    af = b.e;
                }
                if (c != null) {
                    ag = c.e;
                }
                if (d != null) {
                    ah = d.e;
                }
                if (a.bv != 3 && a.bv != 2) {
                    af = 0;
                }
                if (a.cn != 2) {
                    ag = 0;
                }
                if (a.cm != 2) {
                    ah = 0;
                }
                let ai = Math.max(af, Math.max(ah, ag));
                ai = ai * 0.5;
                k = this.aa(k, ai);
            }
            return k;
        }
        j(a, b) {
            if (b) {
                return a == 6 || a == 5;
            }
            return a == 9;
        }
        a$l(a, b, c, d, e) {
            if (a.cn == 7 || a.cm == 7 || a.cn == 5 || a.cm == 5 || a.cm == 11 || a.cn == 11) {
                let f = 0;
                let g = 0;
                let h = 0;
                if (c != null) {
                    g = c.e;
                }
                if (d != null) {
                    h = d.e;
                }
                if (a.cn != 7 && a.cn != 5 && a.cn != 11) {
                    g = 0;
                }
                if (a.cm != 7 && a.cm != 5 && a.cm != 11) {
                    h = 0;
                }
                let i = Math.max(f, Math.max(h, g));
                let j = e * 4;
                if (j == 0) {
                    j = 4;
                }
                e = e + i * (j - e);
            }
            return e;
        }
        aa(a, b) {
            if (a == null) {
                return a;
            }
            if (b == 0) {
                return a;
            }
            return BrushUtil.m(a, b);
        }
        ab(a, b, c, d) {
            if (a != null && a.actualLayers != null && a.actualLayers.count > 0) {
                c = a.vu(c);
            }
            let e = BrushUtil.l(b, d, c, 0);
            return e;
        }
        a$ae(a, b, c, d, e) {
            let f = a.ct;
            f.ao();
            this.a$e = true;
            let g = a.kv(c, b);
            this.a$s = g;
            if (!e && a.c9 != null && !a.a0.c) {
                this.z(a, b, g, d);
            }
            this.d = false;
            if (a.gf && g == null) {
                this.d = true;
            }
            if (a.c9 != null && !this.d) {
                if (a.gf) {
                    this.e = true;
                }
                this.a$ab(a, g, a.wb(b), e, true, false, false, a == a.c9.bq, false);
                a.c9.ph(a, g, d, b);
            }
        }
        a$ar(a, b) {
            let c = null;
            let d = null;
            let e;
            let f = ((() => { let g = a.c9.c8.f(b, false, e, false); e = g.p2; return g.ret; })());
            if (f != a) {
                if (this.a$e) {
                    this.a$af(a, b, null, null, false);
                }
                if (a.c9 != null) {
                    a.c9.q3(b);
                }
                return;
            }
            c = e;
            if (a.c9 != null) {
                a.c9.q3(b);
            }
            if (!this.a$e) {
                this.a$ae(a, b, c, d, false);
            }
            this.a$ah(a, b, c, d, false);
        }
        a$ah(a, b, c, d, e) {
            this.a$e = true;
            let f = a.kv(c, b);
            if (!e) {
                this.z(a, b, f, d);
            }
            if (f != null) {
                this.a$s = f;
            }
            if (a.c9 != null && f != null && this.d) {
                this.d = false;
                this.e = true;
                this.a$ab(a, f, a.wb(b), e, true, false, false, a == a.c9.bq, false);
                a.c9.ph(a, f, d, b);
            }
            if (a.c9 != null && (!a.gf || f != null) && !this.d) {
                this.a$ab(a, f, a.wb(b), e, true, false, false, a == a.c9.bq, false);
                a.c9.pl(a, f, d, b);
            }
            if (f == null && !this.d && a.gf) {
                this.a$ab(a, f, a.wb(b), e, false, true, false, a == a.c9.bq, false);
                a.c9.pi(a, this.a$s, d, b);
                this.e = false;
                this.d = true;
            }
        }
        a$af(a, b, c, d, e) {
            a.ct.ap();
            this.a$e = false;
            let f = this.a$s;
            a.ct.ar();
            if (a.c9 != null && (this.e || !a.gf)) {
                this.e = false;
                this.d = false;
                this.a$ab(a, f, a.wb(b), e, false, true, false, a == a.c9.bq, false);
                a.c9.pi(a, f, d, b);
            }
        }
        a$ac(a, b, c, d) {
            this.k = true;
            if (a.c9 != null) {
                a.c9.pj(a, a.kv(c, b), d, b);
            }
        }
        a$ag(a, b, c, d) {
            this.k = false;
            if (a.c9 != null) {
                a.c9.pk(a, a.kv(c, b), d, b);
            }
        }
        a$ad(a, b, c, d) {
            if (a.ct.s) {
                return;
            }
            if (this.k) {
                this.a$ag(a, b, c, d);
            }
            if (this.a$e) {
                this.a$af(a, b, c, d, false);
            }
        }
        a$ai(a, b, c, d) {
            if (a.c9 != null) {
                a.c9.pm(a, a.kv(c, b), d, b);
            }
        }
        a$aj(a, b, c, d) {
            if (a.c9 != null) {
                a.c9.pn(a, a.kv(c, b), d, b);
            }
        }
        get h() {
            return this.d;
        }
        set h(a) {
            this.d = a;
        }
        get a$c() {
            return this.e;
        }
        set a$c(a) {
            this.e = a;
        }
        z(a, b, c, d) {
            let e = false;
            if (a.c9 != null) {
                e = a.c9.e2;
            }
            if (e) {
                return;
            }
            if (a.c9 == null || a.c9.er) {
                return;
            }
            this.l = true;
            this.ac = b;
            this.u = c;
            a.ct.d.item = c;
            a.ct.d.itemLabel = a.kn(c);
            let f = a.c9.ve();
            let pos_ = { $type: Point_$type, x: b.x + 15 + f.x, y: b.y + 15 + f.y };
            let context_ = a.ct.d;
            let g = false;
            if (this._toolTipObject != null) {
                g = (this._toolTipObject._inPointer);
                this._toolTipObject._inPointer = false;
            }
            if (this._toolTipObject != null) {
                if (this.g || g) {
                    this.g = false;
                    this._toolTipObject.remove();
                    this._toolTipObject.setStyleProperty("position", "absolute");
                    this._toolTipObject.addClass(a.c9.l2);
                    a.c9.mv(this._toolTipObject);
                    this._toolTipObject.hide();
                }
                if (this.f) {
                    a.c9.mv(this._toolTipObject);
                    this.f = false;
                }
                context_.hideOthers = true;
                if ((this._toolTipObject.updateToolTip && !this._toolTipObject.updateToolTip(context_))) {
                    this.a$aa(a);
                }
                let h = window.pageXOffset;
                let i = window.pageYOffset;
                let j = document.documentElement.clientWidth;
                let k = document.documentElement.clientHeight;
                let l = this._toolTipObject.outerWidthWithMargin();
                let m = this._toolTipObject.outerHeightWithMargin();
                let n = pos_.x;
                let o = pos_.y;
                let p = 5;
                let q = 30;
                if (l + n - h + p > j) {
                    pos_.x -= q;
                    pos_.x -= l;
                }
                if (m + o - i + p > k) {
                    pos_.y -= q;
                    pos_.y -= m;
                }
                this._toolTipObject.setOffset(pos_.x, pos_.y);
            }
        }
        a$aq(a, b, c) {
            this.l = true;
            let d = { $type: Point_$type, x: b.x + a.ct.bx.left, y: b.y + a.ct.bx.top };
            let e = a.kv(null, d);
            if (a.ct.d != null) {
                a.ct.d.series = a;
                a.ct.d.item = e;
            }
            let tooltip_ = this._toolTipObject;
            let context_ = a.ct.d;
            let f = false;
            if (this._toolTipObject != null) {
                f = (this._toolTipObject._inPointer);
                this._toolTipObject._inPointer = false;
            }
            if (context_ != null) {
                context_.hideOthers = false;
            }
            if ((!this.g || f) && tooltip_ != null) {
                this.g = true;
                tooltip_.remove();
                tooltip_.setStyleProperty("position", "relative");
                tooltip_.setStyleProperty("top", "");
                tooltip_.setStyleProperty("left", "");
                tooltip_.removeClass(a.c9.l2);
            }
            if (this._toolTipObject != null) {
                if (tooltip_.updateToolTip) {
                    tooltip_.updateToolTip(context_);
                }
                ;
            }
            if (tooltip_ != null) {
                c(tooltip_);
            }
        }
        a$t(a) {
            let b = "<div class='ui-chart-default-tooltip-content'><span";
            let c = this.a$u(a);
            if (!stringIsNullOrEmpty(c)) {
                b += " style='color:" + c + "'";
            }
            b += ">" + a.title + "</span></div>";
            return b;
        }
        i(a, b) {
            let c = a != null && Color.e(toNullable(Color.$, a.color), toNullable(Color.$, null));
            c = c && a.color.l > 0;
            c = c && Color.d(a.color, b);
            return !c;
        }
        a$u(a) {
            let b = new Color();
            let c = a != null && a.c9 != null && a.c9.c8 != null && a.c9.c8.j != null ? a.c9.c8.j.ae : null;
            c.startCSSQuery();
            b.colorString = c.getCssDefaultPropertyValue("ui-chart-pointer-tooltip", "background-color");
            c.endCSSQuery();
            if (!this.i(a.u7, b)) {
                return a.u7._fill;
            }
            if (!this.i(a.u3, b)) {
                return a.u3._fill;
            }
            return null;
        }
        a$aa(a) {
            if (this._toolTipObject != null && this.l) {
                this.l = false;
                let context_ = a.ct.d;
                if (this._toolTipObject.hideToolTip) {
                    this._toolTipObject.hideToolTip(context_);
                }
                ;
            }
        }
        a$as(a, b) {
            let c = this._toolTipObject;
            this.v = null;
            this._toolTipObject = null;
            if (typeof b === 'string') {
                this.v = b;
            }
            else {
                this._toolTipObject = b;
                if (this._toolTipObject != null) {
                    this._toolTipObject.setStyleProperty("position", "absolute");
                    this._toolTipObject.setStyleProperty("top", "0px");
                    this._toolTipObject.setStyleProperty("left", "0px");
                    this._toolTipObject.setStyleProperty("z-index", "10000");
                    this._toolTipObject.setStyleProperty("pointer-events", "none");
                    let d = a.u7 != null && Color.e(toNullable(Color.$, a.u7.color), toNullable(Color.$, null)) && a.u7.color.l > 0;
                    if (d) {
                        this._toolTipObject.setStyleProperty("border-color", a.u7._fill);
                    }
                }
                else {
                    if (!this.f && c != null) {
                        a.c9.qs(c);
                        this.f = true;
                    }
                }
            }
        }
        a$ap(a) {
        }
        get a$j() {
            return this.m;
        }
        a$z(a, b, c, d, e) {
            let f;
            if (!((() => { let g = this.m.tryGetValue(d, f); f = g.p1; return g.ret; })())) {
                f = a.cr();
                f.q = true;
                f.p = true;
                if (a.c9 != null) {
                    f.a = a.c9.ak;
                    a.c9.ak.o(f);
                }
                f.au();
                f.ad = d;
                this.m.item(d, f);
            }
            f.v = e;
            f.bx = b;
            f.bw = c;
        }
        a$al(a, b, c) {
            let d;
            let e = c;
            if (e == null) {
                e = a.c9;
            }
            if (((() => { let f = this.m.tryGetValue(b, d); d = f.p1; return f.ret; })())) {
                if (e != null) {
                    d.a = null;
                    e.ak.u(d);
                }
                this.m.removeItem(b);
            }
        }
        a$ak(a, b) {
            let c = new List$1(String_$type, 0);
            for (let d of fromEnum(this.m.keys)) {
                c.add(d);
            }
            for (let e = 0; e < c.count; e++) {
                this.a$al(a, c._inner[e], b);
            }
        }
    }
    SeriesInteractionManager.$t = /*@__PURE__*/ markType(SeriesInteractionManager, 'SeriesInteractionManager', Base.$, [ISeriesInteractionManager_$type]);
    return SeriesInteractionManager;
})();
