/*
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, runOn, fromEnum, markType, PointUtil } from "igniteui-angular-core";
import { ISeriesViewerInteractionManager_$type } from "./ISeriesViewerInteractionManager";
import { SeriesHighlightingManager } from "./SeriesHighlightingManager";
import { SeriesSelectionHighlightingManager } from "./SeriesSelectionHighlightingManager";
import { SeriesFocusHighlightingManager } from "./SeriesFocusHighlightingManager";
import { SeriesViewerScrollbarManager } from "./SeriesViewerScrollbarManager";
import { Rect } from "igniteui-angular-core";
import { TileZoomManager } from "./TileZoomManager";
import { ChartSelection } from "./ChartSelection";
import { Size } from "igniteui-angular-core";
import { MathUtil } from "igniteui-angular-core";
import { MouseEventArgs } from "igniteui-angular-core";
import { MouseButtonEventArgs } from "igniteui-angular-core";
import { truncate, intDivide, isNaN_ } from "igniteui-angular-core";
/**
 * @hidden
 */
export let SeriesViewerInteractionManager = /*@__PURE__*/ (() => {
    class SeriesViewerInteractionManager extends Base {
        constructor() {
            super();
            this.v = 0;
            this.w = 0;
            this.ao = null;
            this.s = 0;
            this.t = 0;
            this.r = 0;
            this.u = 0;
            this.k = false;
            this.ap = null;
            this.ar = null;
            this.l = false;
            this.n = false;
            this.h = null;
            this.e = null;
            this.f = null;
            this.d = null;
            this.g = null;
            this.aq = null;
            this.as = null;
            this.c = null;
            this.a = null;
            this.j = false;
            this.aq = Rect.empty;
            this.ap = Rect.empty;
        }
        get f$e() {
            if (this.e == null) {
                this.e = new SeriesHighlightingManager();
            }
            return this.e;
        }
        get f$f() {
            if (this.f == null) {
                this.f = new SeriesSelectionHighlightingManager();
            }
            return this.f;
        }
        get f$d() {
            if (this.d == null) {
                this.d = new SeriesFocusHighlightingManager();
            }
            return this.d;
        }
        get f$b() {
            if (this.g == null) {
                this.g = new SeriesViewerScrollbarManager();
            }
            return this.g;
        }
        f$j(a, b, c) {
            let d = a.db;
            if (a.bn != null) {
                a = a.bn;
            }
            if (a.bk != null) {
                a = a.bk;
            }
            let e = ((() => {
                let $ret = new ChartSelection();
                $ret.item = b;
                $ret.series = a;
                return $ret;
            })());
            let f = a.db.selectedSeriesItems;
            if (f.contains(e)) {
                return;
            }
            a.db.selectedSeriesItems.add(e);
        }
        f$aq(a, b, c) {
            let d = a.db;
            if (a.bn != null) {
                a = a.bn;
            }
            if (a.bk != null) {
                a = a.bk;
            }
            let e = ((() => {
                let $ret = new ChartSelection();
                $ret.item = b;
                $ret.series = a;
                return $ret;
            })());
            let f = a.db.selectedSeriesItems;
            if (!f.contains(e)) {
                return;
            }
            a.db.selectedSeriesItems.remove(e);
        }
        f$as(a, b) {
            let c = null;
            let d = null;
            let e = null;
            e = a.c9.e();
            let f;
            let g = ((() => { let h = a.c9.f(b, false, f, false); f = h.p2; return h.ret; })());
            if (g != e) {
                if (e != null && e.ba.a$e) {
                    e.ba.a$af(e, b, null, null, false);
                }
            }
            c = f;
            if (a != null) {
                a.rh(b);
            }
            if (g != null && !g.ba.a$e) {
                g.ba.a$ae(g, b, c, d, false);
            }
        }
        f$a(a) {
            if (a.av != 0) {
                return a.av;
            }
            let b = 1;
            let c = false;
            let d = false;
            for (let e = 0; e < a.series.count; e++) {
                let f = a.series._inner[e];
                if (f.isStacked) {
                    f.p1((g) => {
                        if (g.b1 == 2) {
                            c = true;
                        }
                        if (g.b1 == 1) {
                            d = true;
                        }
                        return true;
                    });
                }
                else {
                    if (f.b1 == 2) {
                        c = true;
                    }
                    if (f.b1 == 1) {
                        d = true;
                    }
                }
            }
            if (d) {
                b = 1;
            }
            if (c) {
                b = 2;
            }
            if (c && d) {
                b = 3;
            }
            return b;
        }
        f$ar(a) {
            let b = a.vv;
            let c = b;
            let d = a.c9;
            let e = a.ei();
            let f = a.el;
            let g = a.fy;
            let h = a.ga;
            if (!e) {
                c = { $type: Point_$type, x: NaN, y: NaN };
            }
            if (c.x < 0 || c.x > 1 || c.y < 0 || c.y > 1) {
                c = { $type: Point_$type, x: NaN, y: NaN };
            }
            for (let i = 0; i < a.series.count; i++) {
                let j = a.series._inner[i];
                j.qa(c);
            }
            a.oa(c);
            let k = a.c0 == 0 && !a.e4 && (a.er || f) && !g && !h;
            let l = a.wj;
            if (k && !isNaN_(b.x) && !l.isEmpty) {
                let m = l.width * (b.x - a.v4.left) / a.v4.width;
                d.eo(l.left + m, l.top, l.left + m, l.bottom);
                d.ed();
                d.ei(m);
            }
            else {
                d.cl();
            }
            if (k && !isNaN_(b.y) && !l.isEmpty) {
                let n = l.height * (b.y - a.v4.top) / a.v4.height;
                d.eh(l.left, l.top + n, l.right, l.top + n);
                d.d9();
            }
            else {
                d.cg();
            }
        }
        f$aj(a) {
            switch (a.c0) {
                case 0:
                    a.c9.d5();
                    this.f$ar(a);
                    a.c9.cd();
                    break;
                case 1:
                    a.c9.d7();
                    a.c9.ck();
                    this.f$ar(a);
                    a.c9.cc();
                    break;
                case 2:
                    a.c9.d7();
                    a.c9.ck();
                    this.f$ar(a);
                    a.c9.ce();
                    break;
            }
        }
        f$t(a, b) {
            if (b.x >= 0 && b.y >= 0 && b.x <= a.wj.width && b.y <= a.wj.height) {
                this.ak(a, b);
            }
            else {
                a.nw();
            }
        }
        ak(a, b) {
            let c = a.c9;
            let d = a.wj;
            if (a.e5 || a.e4) {
                return;
            }
            if (a.el && a.er) {
                let e = d.height > d.width;
                c.bv(e);
                for (let f of fromEnum(a.series)) {
                    if (f.isStacked) {
                        f.p1((g) => {
                            if (g._visibility == 0) {
                                g.r3(b, runOn(c, c.bm));
                            }
                            if (g.eg) {
                                g.pz((h) => {
                                    if (h._visibility == 0) {
                                        h.r3(b, runOn(c, c.bm));
                                    }
                                    return true;
                                });
                            }
                            return true;
                        });
                    }
                    else if (f.eg) {
                        if (f._visibility == 0) {
                            if (f._visibility == 0) {
                                f.r3(b, runOn(c, c.bm));
                            }
                        }
                        f.pz((g) => {
                            if (g._visibility == 0) {
                                g.r3(b, runOn(c, c.bm));
                            }
                            return true;
                        });
                    }
                    else {
                        if (f._visibility == 0) {
                            f.r3(b, runOn(c, c.bm));
                        }
                    }
                }
                c.ea();
            }
        }
        aj(a, b) {
            if (a.er || a.e2) {
                a.el = true;
                a.p9();
                this.ap = new Rect(0, b.x, b.y, 0, 0);
                this.ar = new Rect(0, b.x, b.y, 0, 0);
                a.c0 = 0;
                a.nh(a.vy(b));
            }
        }
        f$ah(a, b) {
            this.aj(a, b);
            this.ak(a, b);
            this.f$ar(a);
        }
        f$u(a, b, c) {
            if (!a.el) {
                this.am(a, b, c);
            }
        }
        f$s(a, b) {
            this.aq = Rect.empty;
            a.nw();
        }
        f$ao(a) {
            if (this.l) {
                this.f$b.onScrollbarDragCancel();
                this.l = false;
            }
            let b = a.c9;
            this.u = 1;
            this.ae(a);
            a.c0 = 0;
            this.k = true;
            a.fy = true;
            a.qa(true);
        }
        ae(a) {
            let b = a.c9;
            a.el = false;
            b.cj();
            b.cf();
            b.ch();
            a.nh({ $type: Point_$type, x: NaN, y: NaN });
            b.cg();
            b.cl();
            b.ck();
        }
        f$ag(a, b) {
            this.f$ao(a);
        }
        f$ap(a, b, c, d, e) {
            this.v = b.x;
            this.w = b.y;
            this.s = c;
            this.t = d;
            this.r = e;
            this.ao = a.v4;
            this.f$ao(a);
        }
        f$af(a, b) {
            let c = a.c9;
            c.cg();
            c.cl();
            if (c.av) {
                this.aa(a, b);
            }
            else {
                this.ac(a, b);
                this.u = b;
            }
        }
        f$al(a, b, c, d, e) {
            let f = a.c9;
            f.cg();
            f.cl();
            this.s = this.s * c;
            this.t = this.t * d;
            this.r = this.r * e;
            if (a.fb) {
                this.s = this.r;
                this.t = this.r;
            }
            let g = a.v4;
            let h = a.wj;
            let i = b.x - this.v;
            let j = b.y - this.w;
            this.v = b.x;
            this.w = b.y;
            let k = g.width;
            let l = g.height;
            let m = this.ao.width / this.s;
            let n = this.ao.height / this.t;
            if (m > 1) {
                m = 1;
            }
            if (n > 1) {
                n = 1;
            }
            let o = { $type: Point_$type, x: b.x, y: b.y };
            let p = { $type: Point_$type, x: (o.x - h.left) / h.width * g.width + g.left, y: (o.y - h.top) / h.height * g.height + g.top };
            let q = new Rect(0, g.left, g.top, m, n);
            let r = { $type: Point_$type, x: (p.x - q.left) / q.width * h.width + h.left, y: (p.y - q.top) / q.height * h.height + h.top };
            let s = (r.x - o.x) - i;
            let t = (r.y - o.y) - j;
            let u = s / h.width * q.width;
            let v = t / h.height * q.height;
            q = new Rect(0, q.left + u, q.top + v, q.width, q.height);
            g = q;
            a.rx(g, true);
        }
        f$ac(a, b) {
            this.ap = new Rect(0, b.x, b.y, 0, 0);
            this.ar = new Rect(0, b.x, b.y, 0, 0);
        }
        ab(a, b, c) {
            let d = a.v4.width;
            let e = a.v4.height;
            let f = a.v4.left + d / 2;
            let g = a.v4.top + e / 2;
            d = d / b;
            e = e / b;
            let h = f - d / 2;
            let i = g - e / 2;
            a.rx(new Rect(0, h, i, d, e), true);
        }
        f$ae(a, b) {
            let c = a.c9;
            if (c.av) {
                this.aa(a, b);
            }
            else {
                this.ac(a, b);
            }
            this.ap = Rect.empty;
            a.fy = false;
        }
        f$v(a, b) {
            a.fy = false;
            this.ap = Rect.empty;
            a.nw();
        }
        f$ab(a, b) {
            a.na();
        }
        f$ak(a, b, c, d, e) {
            a.fy = false;
            this.ap = Rect.empty;
            a.nw();
        }
        aa(a, b) {
            let c = a.wk;
            let d = 1 / b;
            let e = { $type: Point_$type, x: c.x + c.width / 2, y: c.y + c.height / 2 };
            let f = { $type: Point_$type, x: c.x - e.x, y: c.y - e.y };
            let g = new Rect(0, f.x * d + e.x, f.y * d + e.y, c.width * d, c.height * d);
            a.rx(g, true);
        }
        ac(a, b) {
            let c = a.wj;
            let d = a.wk;
            let e = b - this.u;
            if (e != 0) {
                let f = 0.03;
                let g = e < 0 ? 1 + f : 1 - f;
                let h = { $type: Point_$type, x: d.x + d.width / 2, y: d.y + d.height / 2 };
                let i = { $type: Point_$type, x: d.x - h.x, y: d.y - h.y };
                let j = new Rect(0, i.x * g + h.x, i.y * g + h.y, d.width * g, d.height * g);
                a.rx(j, true);
            }
        }
        f$q(a, b, c) {
            if (!a.fy) {
                this.k = false;
            }
            let d = false;
            if (a.em) {
                if (this.f$b.shouldHandleInteraction(b, c)) {
                    this.l = true;
                    d = true;
                    this.ae(a);
                    a.c9.dr();
                    return;
                }
            }
            this.am(a, b, c);
            a.pn(b, c);
        }
        am(a, b, c) {
            let d;
            let e = a.c9;
            if (a.cx != 0) {
                d = a.cx;
            }
            else if (e.ez == 0) {
                let f = a.cy(c);
                switch (f) {
                    case 1:
                        d = a.fk() ? f : 0;
                        break;
                    default:
                        d = f;
                        break;
                }
            }
            else {
                if (e.ez == a.u1) {
                    d = 1;
                }
                else if (e.ez == a.u2) {
                    d = 2;
                }
                else if (e.ez == a.u3) {
                    d = 3;
                }
                else {
                    d = 0;
                }
            }
            switch (d) {
                case 1:
                case 2:
                case 3:
                    a.c9.ca();
                    a.c9.dr();
                    break;
            }
            a.c0 = d;
            switch (a.c0) {
                case 1:
                    this.ap = new Rect(0, b.x, b.y, 0, 0);
                    this.ar = new Rect(0, b.x, b.y, 0, 0);
                    this.aq = new Rect(0, b.x, b.y, 0, 0);
                    e.d8();
                    e.eg(this.ap);
                    a.qf(Rect.empty, true);
                    break;
                case 2:
                    this.ap = new Rect(0, b.x, b.y, 0, 0);
                    this.aq = new Rect(0, b.x, b.y, 0, 0);
                    break;
                case 3:
                    this.ap = new Rect(0, b.x, b.y, 0, 0);
                    this.ar = new Rect(0, b.x, b.y, 0, 0);
                    this.aq = new Rect(0, b.x, b.y, 0, 0);
                    e.d8();
                    e.eg(this.ap);
                    a.qf(Rect.empty, true);
                    break;
            }
            this.as = a.v4;
            a.wl = a.v4;
        }
        f$an(a) {
            a.ri();
            a.c9.dl();
        }
        f$am(a) {
            a.nl();
            a.c9.dk();
        }
        f$at(a) {
            if (a.eh && !this.n) {
                this.n = true;
                this.al(a);
            }
        }
        f$n(a) {
            if (this.n) {
                this.ad(a);
                this.n = false;
            }
        }
        f$k(a) {
            if (this.h == null) {
                return;
            }
            this.i.ab();
        }
        get i() {
            return this.h;
        }
        al(a) {
            if (this.h == null) {
                this.h = new TileZoomManager(a, true, a.i1);
                this.h.h = !a.fz;
            }
            a.e1 = true;
            a.qe();
            this.h.al();
            a.c9.br();
            a.c9.bs();
        }
        ad(a) {
            if (this.h == null) {
                return;
            }
            a.e1 = false;
            a.c9.dg();
            this.h.ah();
            a.q0();
            a.c9.by();
        }
        f$m(a) {
            a.nf();
            a.q2();
        }
        p(a) {
            return a.c0 == 2;
        }
        q(a, b) {
            return a.cp == 1 || b || a.eh;
        }
        o(a) {
            return a.c0 == 1;
        }
        f$p(a, b, c) {
            let d = a.c9;
            if (this.l) {
                a.bc.onScrollbarDrag(b, c);
                return;
            }
            if (this.ap.isEmpty && c) {
                this.am(a, b, c);
            }
            let e = 2;
            if (c) {
                e = 10;
            }
            let f = false;
            let g = false;
            let h = new Rect(2, { $type: Point_$type, x: this.ap.x, y: this.ap.y }, b);
            let i = new Rect(0, 0, 0, 0, 0);
            if (!this.aq.isEmpty) {
                i = new Rect(2, { $type: Point_$type, x: this.aq.x, y: this.aq.y }, b);
            }
            if (i.width > e || i.height > e) {
                g = true;
            }
            if (i.width > e && i.height > e) {
                f = true;
            }
            if (!a.fy) {
                if (f) {
                    this.k = false;
                }
            }
            if (!a.fy && (a.el || !c)) {
                a.nh(a.vy(b));
            }
            if (a.c0 == 3) {
                if (f) {
                    let j = a.wi(h);
                    a.qf(j, true);
                }
                else {
                    a.qf(Rect.empty, true);
                }
                a.on(g);
                d.eg(h);
            }
            if (this.o(a)) {
                if (f) {
                    let k = a.wi(h);
                    a.qf(k, true);
                }
                else {
                    a.qf(Rect.empty, true);
                }
                a.op(g);
                d.eg(h);
            }
            let l = a.wj;
            let m = a.v4;
            if (this.p(a)) {
                let n = l;
                let o = m.left + m.width * (this.ap.x - b.x) / n.width;
                let p = m.top + m.height * (this.ap.y - b.y) / n.height;
                let q = new Rect(0, o, p, m.width, m.height);
                if (this.q(a, c)) {
                    if (i.width != 0 || i.height != 0) {
                        a.qa(g);
                    }
                    a.qf(Rect.empty, true);
                    let r = a.v4;
                    a.rx(q, true);
                    let s = a.v4;
                    if (r.equals1(s) && a.c9.k.ac) {
                        a.c9.k.au();
                    }
                    this.ap = new Rect(3, b, new Size(1, 0, 0));
                    this.ar = new Rect(3, b, new Size(1, 0, 0));
                }
                else {
                    a.qf(q, true);
                }
            }
            this.ar = new Rect(3, b, new Size(1, 0, 0));
            d.bu(b);
        }
        f$o(a, b, c, d) {
            let e = a.c9;
            let f = 2;
            if (c) {
                f = 10;
            }
            let g = a.wj;
            let h = a.v4;
            if (!d) {
                if (this.l) {
                    this.f$b.onScrollbarDragComplete(b, c);
                    this.l = false;
                    e.bw();
                    return;
                }
            }
            if (!this.k) {
                let i = false;
                let j = new Rect(2, { $type: Point_$type, x: this.ap.x, y: this.ap.y }, b);
                if (j.width > f && j.height > f) {
                    i = true;
                }
                if (a.c0 == 3 && i) {
                    a.om();
                    a.m6(j);
                    e.cf();
                }
                if (a.c0 == 1) {
                    a.oo();
                    e.cf();
                    if (i) {
                        a.rx(a.wi(j), true);
                    }
                }
                if (a.c0 == 2) {
                    let k = g;
                    let l = h.left + h.width * (this.ap.x - b.x) / k.width;
                    let m = h.top + h.height * (this.ap.y - b.y) / k.height;
                    a.rx(new Rect(0, l, m, h.width, h.height), true);
                }
            }
            let n = false;
            let o = new Rect(2, { $type: Point_$type, x: this.aq.x, y: this.aq.y }, b);
            if (o.width > f || o.height > f) {
                n = true;
            }
            if (n) {
                a.ga = true;
            }
            a.c0 = 0;
            a.qf(Rect.empty, true);
            e.bw();
            a.ga = false;
            e.cg();
            e.cl();
            if (c) {
                e.ck();
                e.cg();
                e.cl();
                e.ch();
            }
            a.nw();
            a.p9();
            a.po(b, c, d);
        }
        f$ai(a) {
            if (this.i != null) {
                this.i.h = !a.fz;
            }
        }
        f$g(a, b) {
            let c = a.c9;
            let d = a.v4;
            if (a.c0 == 2 && b == 8) {
                c.bt();
                a.c0 = 0;
                a.p9();
                a.qf(Rect.empty, true);
                if (a.cp == 1) {
                    a.rx(this.as, true);
                }
                return true;
            }
            if (a.c0 == 1 && b == 8) {
                c.bt();
                a.c0 = 0;
                a.p9();
                c.cf();
                a.qf(Rect.empty, true);
                return true;
            }
            let e = Rect.empty;
            let f = false;
            switch (b) {
                case 13:
                    f = true;
                    e = new Rect(0, 0, 0, 1, 1);
                    break;
                case 11:
                    f = true;
                    e = new Rect(0, d.left - 0.1 * d.width, d.top - 0.1 * d.height, 1.2 * d.width, 1.2 * d.height);
                    break;
                case 10:
                    f = true;
                    e = new Rect(0, d.left + 0.1 * d.width, d.top + 0.1 * d.height, 0.8 * d.width, 0.8 * d.height);
                    break;
                case 14:
                    if (c.ez == 2) {
                        f = true;
                        this.af(a);
                    }
                    else {
                        f = true;
                        e = new Rect(0, d.left - 0.1 * d.width, d.top, d.width, d.height);
                        e.x = e.x - Math.min(e.left, 0);
                    }
                    break;
                case 16:
                    if (c.ez == 2) {
                        f = true;
                        this.ai(a);
                    }
                    else {
                        f = true;
                        e = new Rect(0, d.left + 0.1 * d.width, d.top, d.width, d.height);
                        e.x = e.x - Math.max(e.right - 1, 0);
                    }
                    break;
                case 9:
                    if (a.focusedSeriesItems.count > 0) {
                        f = true;
                        for (let g of fromEnum(a.focusedSeriesItems)) {
                            a.pt(g.series, g.item);
                        }
                    }
                    break;
                case 15:
                    if (c.ez == 2) {
                        f = true;
                        this.ah(a);
                    }
                    else {
                        f = true;
                        e = new Rect(0, d.left, d.top - 0.1 * d.height, d.width, d.height);
                        e.y = e.y - Math.min(e.top, 0);
                    }
                    break;
                case 17:
                    if (c.ez == 2) {
                        f = true;
                        this.ag(a);
                    }
                    else {
                        f = true;
                        e = new Rect(0, d.left, d.top + 0.1 * d.height, d.width, d.height);
                        e.y = e.y - Math.max(e.bottom - 1, 0);
                    }
                    break;
            }
            if (!e.isEmpty && Rect.l_op_Inequality(e, d)) {
                a.rx(e, true);
            }
            return f;
        }
        ai(a) {
            let b = null;
            if (a.focusedSeriesItems.count > 0) {
                b = a.focusedSeriesItems._inner[0];
            }
            let c = null;
            if (b != null) {
                c = b.series;
            }
            if (c == null) {
                if (a.series.count == 0) {
                    return;
                }
                c = a.series._inner[0];
            }
            if (c != null && c.dn != null) {
                if (b == null) {
                    let d = ((() => {
                        let $ret = new ChartSelection();
                        $ret.series = c;
                        $ret.item = c.dn.item(0);
                        return $ret;
                    })());
                    a.focusedSeriesItems.clear();
                    a.focusedSeriesItems.add(d);
                    return;
                }
                let e = c.dn.indexOf(b.item);
                if (e == -1) {
                    return;
                }
                e++;
                if (e > c.dn.count - 1) {
                    return;
                }
                let f = ((() => {
                    let $ret = new ChartSelection();
                    $ret.series = c;
                    $ret.item = c.dn.item(e);
                    return $ret;
                })());
                a.focusedSeriesItems.clear();
                a.focusedSeriesItems.add(f);
            }
        }
        af(a) {
            let b = null;
            if (a.focusedSeriesItems.count > 0) {
                b = a.focusedSeriesItems._inner[0];
            }
            let c = null;
            if (b != null) {
                c = b.series;
            }
            if (c == null) {
                if (a.series.count == 0) {
                    return;
                }
                c = a.series._inner[0];
            }
            if (c != null && c.dn != null) {
                if (b == null) {
                    let d = ((() => {
                        let $ret = new ChartSelection();
                        $ret.series = c;
                        $ret.item = c.dn.item(0);
                        return $ret;
                    })());
                    a.focusedSeriesItems.clear();
                    a.focusedSeriesItems.add(d);
                    return;
                }
                let e = c.dn.indexOf(b.item);
                if (e == -1) {
                    return;
                }
                e--;
                if (e < 0) {
                    return;
                }
                let f = ((() => {
                    let $ret = new ChartSelection();
                    $ret.series = c;
                    $ret.item = c.dn.item(e);
                    return $ret;
                })());
                a.focusedSeriesItems.clear();
                a.focusedSeriesItems.add(f);
            }
        }
        ah(a) {
            let b = null;
            if (a.focusedSeriesItems.count > 0) {
                b = a.focusedSeriesItems._inner[0];
            }
            let c = null;
            if (b != null) {
                c = b.series;
            }
            if (c == null) {
                if (a.series.count == 0) {
                    return;
                }
                c = a.series._inner[0];
            }
            if (c != null) {
                let d = a.series.indexOf(c);
                if (d == -1) {
                    return;
                }
                let e = 0;
                if (b != null && b.item != null && c.dn != null) {
                    e = c.dn.indexOf(b.item);
                    if (e == -1) {
                        e = 0;
                    }
                }
                d--;
                if (d < 0) {
                    return;
                }
                c = a.series._inner[d];
                if (c.dn == null) {
                    let f = ((() => {
                        let $ret = new ChartSelection();
                        $ret.series = c;
                        $ret.item = null;
                        return $ret;
                    })());
                    a.focusedSeriesItems.clear();
                    a.focusedSeriesItems.add(f);
                    return;
                }
                if (e > c.dn.count - 1) {
                    e = 0;
                }
                let g = ((() => {
                    let $ret = new ChartSelection();
                    $ret.series = c;
                    $ret.item = c.dn.item(e);
                    return $ret;
                })());
                a.focusedSeriesItems.clear();
                a.focusedSeriesItems.add(g);
            }
        }
        ag(a) {
            let b = null;
            if (a.focusedSeriesItems.count > 0) {
                b = a.focusedSeriesItems._inner[0];
            }
            let c = null;
            if (b != null) {
                c = b.series;
            }
            if (c == null) {
                if (a.series.count == 0) {
                    return;
                }
                c = a.series._inner[0];
            }
            if (c != null) {
                let d = a.series.indexOf(c);
                if (d == -1) {
                    return;
                }
                let e = 0;
                if (b != null && b.item != null && c.dn != null) {
                    e = c.dn.indexOf(b.item);
                    if (e == -1) {
                        e = 0;
                    }
                }
                d++;
                if (d > a.series.count - 1) {
                    return;
                }
                c = a.series._inner[d];
                if (c.dn == null) {
                    let f = ((() => {
                        let $ret = new ChartSelection();
                        $ret.series = c;
                        $ret.item = null;
                        return $ret;
                    })());
                    a.focusedSeriesItems.clear();
                    a.focusedSeriesItems.add(f);
                    return;
                }
                if (e > c.dn.count - 1) {
                    e = 0;
                }
                let g = ((() => {
                    let $ret = new ChartSelection();
                    $ret.series = c;
                    $ret.item = c.dn.item(e);
                    return $ret;
                })());
                a.focusedSeriesItems.clear();
                a.focusedSeriesItems.add(g);
            }
        }
        f$h(a, b, c) {
            let d = a.c9;
            let e = a.v4;
            let f = e.left + e.width * b.x / a.wj.width;
            let g = e.top + e.height * b.y / a.wj.height;
            let h = 1 - MathUtil.d(c, -0.5, 0.5);
            let i = Math.max(0, f - h * (f - e.left));
            let j = Math.min(1, g + h * (e.bottom - g));
            let k = Math.min(1, f + h * (e.right - f));
            let l = Math.max(0, g - h * (g - e.top));
            a.qa(true);
            this.z(a, 1000);
            a.rx(new Rect(0, i, l, k - i, j - l), true);
            return a.fk();
        }
        z(a, b) {
            a.c9.bz(b);
        }
        f$r(a, b) {
            let c = a.v4;
            let d = c.left + c.width * b.x / a.wj.width;
            let e = c.top + c.height * b.y / a.wj.height;
            let f = 0.7;
            let g = Math.max(0, d - f * (d - c.left));
            let h = Math.min(1, e + f * (c.bottom - e));
            let i = Math.min(1, d + f * (c.right - d));
            let j = Math.max(0, e - f * (e - c.top));
            a.rx(new Rect(0, g, j, i - g, h - j), true);
        }
        f$l(a) {
            this.i.ac();
        }
        f$c(a, b, c, d, e, f, g) {
            let h = true;
            let i = false;
            let j = false;
            let k = a;
            if (k.au == 1) {
                h = false;
                i = true;
            }
            if (k.au == 3 || k.au == 4) {
                i = true;
            }
            if (k.au == 4) {
                j = true;
            }
            let l = truncate(Math.round(d.x));
            let m = truncate(Math.round(d.y));
            f = null;
            let n = -1;
            if (h && c != null) {
                let o = l;
                let p = m;
                if (a.hi != 1) {
                    o = truncate(Math.round(d.x * a.hi));
                    p = truncate(Math.round(d.y * a.hi));
                }
                let q = c.a(o, p);
                if (q == null || q.length == 0) {
                    f = null;
                    return {
                        ret: null,
                        p5: f
                    };
                }
                if ((q[0] > 0 || q[1] > 0 || q[2] > 0) && q[3] == 255) {
                    let num2_ = q[2];
                    if (num2_ % 4 != 0) {
                        num2_ = num2_ + (4 - (num2_ % 4));
                    }
                    let num1_ = q[1];
                    if (num1_ % 4 != 0) {
                        num1_ = num1_ + (4 - (num1_ % 4));
                    }
                    let num0_ = q[0];
                    if (num0_ % 4 != 0) {
                        num0_ = num0_ + (4 - (num0_ % 4));
                    }
                    let num_ = 0;
                    num_ = (num2_ >> 2);
                    num_ = (num_ << 6);
                    num_ = (num_ | (num1_ >> 2));
                    num_ = (num_ << 6);
                    num_ = (num_ | (num0_ >> 2));
                    n = truncate(Math.floor((intDivide(num_, 1000))));
                    n--;
                }
            }
            let r = null;
            let s = -1;
            if (n >= 0) {
                let t = false;
                let u = 0;
                for (let v of fromEnum(b)) {
                    if (!v.f8) {
                        continue;
                    }
                    if (t) {
                        break;
                    }
                    if (v.isStacked) {
                        v.p1((w) => {
                            if (w.kg == n) {
                                r = w;
                                s = u;
                                t = true;
                                return false;
                            }
                            return true;
                        });
                    }
                    else if (v.kg == n) {
                        r = v;
                        s = u;
                        break;
                    }
                    u++;
                }
            }
            let w = null;
            if (i) {
                let x = false;
                for (let y = b.count - 1; y >= 0; y--) {
                    let z = b._inner[y];
                    if (!z.f8) {
                        continue;
                    }
                    let aa = z.cv;
                    if (!z.he(aa.bx, aa.by, aa)) {
                        continue;
                    }
                    if (!x && y < s && h && !j) {
                        if (r != null) {
                            w = r;
                            x = true;
                            break;
                        }
                    }
                    if (z != null && z.b1 == 1) {
                        if (z.gw(d, g)) {
                            w = z;
                            break;
                        }
                    }
                }
                if (h && !x) {
                    if (r != null) {
                        w = r;
                        x = true;
                    }
                }
            }
            else {
                w = r;
            }
            if (w != null) {
                let ab = w.a2({ $type: Point_$type, x: l, y: m }, g);
                if (ab != null) {
                    f = ab;
                }
                return {
                    ret: w,
                    p5: f
                };
            }
            return {
                ret: null,
                p5: f
            };
        }
        f$i(a, b) {
            if (PointUtil.equals(b, null)) {
                return false;
            }
            let c = b.x;
            let d = b.y;
            if (this.l) {
                return true;
            }
            if (c >= a.wj.left && d >= a.wj.top && c <= a.wj.left + a.wj.width && d <= a.wj.top + a.wj.height) {
                let e = a.c2;
                if (e != null && e.viewShouldInteract(b)) {
                    return false;
                }
                return true;
            }
            return false;
        }
        b(a) {
            if (a != null) {
                return a.bp();
            }
            else {
                return null;
            }
        }
        f$z(a, b, c, d, e, f) {
            if (!f && a.eg) {
                this.an(a, false);
            }
            let g = new MouseEventArgs();
            g.position = d;
            if (a.c0 == 2 || a.c0 == 1 || a.fy || (a.c2 != null && a.c2.isPinching)) {
                if (this.c != null) {
                    this.c.ba.a$af(this.c, g.position, this.a, g, f);
                    this.c = null;
                }
                return;
            }
            let h = null;
            let i = ((() => { let j = this.f$c(a, b, c, d, !e, h, f); h = j.p5; return j.ret; })());
            this.a = h;
            let j = this.b(i);
            if (i != null) {
                let k = false;
                let l = false;
                if (this.c != i) {
                    l = true;
                }
                if (this.c == null || l) {
                    k = true;
                }
                if (k) {
                    if (l) {
                        if (this.c != null) {
                            j = this.b(this.c);
                            this.c.ba.a$af(this.c, g.position, h, g, f);
                            if (j != null) {
                                j.ba.a$af(j, g.position, h, g, f);
                            }
                        }
                    }
                    this.c = i;
                    j = this.b(this.c);
                    i.qs(g.position, h, g, f);
                    if (j != null) {
                        j.qs(g.position, h, g, f);
                    }
                }
                else {
                    this.c = i;
                    j = this.b(this.c);
                    i.ba.a$ah(i, g.position, h, g, f);
                    if (j != null) {
                        j.ba.a$ah(j, g.position, h, g, f);
                    }
                }
            }
            else {
                if (this.c != null) {
                    j = this.b(this.c);
                    this.c.ba.a$af(this.c, g.position, h, g, f);
                    if (j != null) {
                        j.ba.a$af(j, g.position, h, g, f);
                    }
                    this.c = null;
                }
                for (let m = 0; m < a.series.count; m++) {
                    let n = a.series._inner[m];
                    if (n.ba.a$c) {
                        j = this.b(n);
                        n.ba.a$af(n, g.position, n.ba.a$s, g, f);
                        if (j != null) {
                            j.ba.a$af(j, g.position, n.ba.a$s, g, f);
                        }
                    }
                }
            }
        }
        f$y(a, b) {
            if (this.c != null) {
                let c = this.b(this.c);
                let d = new MouseEventArgs();
                d.position = b;
                this.c.ba.a$af(this.c, d.position, null, d, false);
                if (c != null) {
                    c.ba.a$af(c, d.position, null, d, false);
                }
                this.c = null;
            }
            a.pi(b, a.c0 != 0 || a.fp);
        }
        f$x(a, b, c) {
            if (this.c != null) {
                let d = new MouseButtonEventArgs();
                d.position = c;
                if (b.al) {
                    this.c.ba.a$ai(this.c, d.position, this.a, d);
                }
                else {
                    this.c.ba.a$ac(this.c, d.position, this.a, d);
                }
            }
        }
        f$aa(a, b, c) {
            let d;
            let e = (this.c != null) ? this.c : ((() => { let f = a.c9.f(c, false, d, false); d = f.p2; return f.ret; })());
            if (e != null) {
                let f = new MouseButtonEventArgs();
                f.position = c;
                if (b.al) {
                    e.ba.a$aj(e, f.position, this.a, f);
                }
                else {
                    e.ba.a$ag(e, f.position, this.a, f);
                }
            }
        }
        f$w(a, b, c) {
            if (!c && a.fr) {
                this.an(a, false);
            }
            if (c && !a.fr) {
                this.an(a, true);
            }
            a.ot(b, c);
        }
        an(a, b) {
            if (a != null) {
                if (!this.m) {
                    a.eg = b;
                }
            }
        }
        f$ad(a, b) {
            this.j = true;
        }
        get m() {
            return this.j;
        }
    }
    SeriesViewerInteractionManager.$t = markType(SeriesViewerInteractionManager, 'SeriesViewerInteractionManager', Base.$, [ISeriesViewerInteractionManager_$type]);
    return SeriesViewerInteractionManager;
})();
