/*
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 { __extends, __values } from "tslib";
import { Base, Point_$type, runOn, fromEnum, markType, PointUtil } from "igniteui-react-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-react-core";
import { TileZoomManager } from "./TileZoomManager";
import { ChartSelection } from "./ChartSelection";
import { Size } from "igniteui-react-core";
import { MathUtil } from "igniteui-react-core";
import { MouseEventArgs } from "igniteui-react-core";
import { MouseButtonEventArgs } from "igniteui-react-core";
import { truncate, intDivide, isNaN_ } from "igniteui-react-core";
/**
 * @hidden
 */
var SeriesViewerInteractionManager = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(SeriesViewerInteractionManager, _super);
    function SeriesViewerInteractionManager() {
        var _this = _super.call(this) || this;
        _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;
        return _this;
    }
    Object.defineProperty(SeriesViewerInteractionManager.prototype, "f$e", {
        get: function () {
            if (this.e == null) {
                this.e = new SeriesHighlightingManager();
            }
            return this.e;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(SeriesViewerInteractionManager.prototype, "f$f", {
        get: function () {
            if (this.f == null) {
                this.f = new SeriesSelectionHighlightingManager();
            }
            return this.f;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(SeriesViewerInteractionManager.prototype, "f$d", {
        get: function () {
            if (this.d == null) {
                this.d = new SeriesFocusHighlightingManager();
            }
            return this.d;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(SeriesViewerInteractionManager.prototype, "f$b", {
        get: function () {
            if (this.g == null) {
                this.g = new SeriesViewerScrollbarManager();
            }
            return this.g;
        },
        enumerable: false,
        configurable: true
    });
    SeriesViewerInteractionManager.prototype.f$j = function (a, b, c) {
        var d = a.db;
        if (a.bn != null) {
            a = a.bn;
        }
        if (a.bk != null) {
            a = a.bk;
        }
        var e = ((function () {
            var $ret = new ChartSelection();
            $ret.item = b;
            $ret.series = a;
            return $ret;
        })());
        var f = a.db.selectedSeriesItems;
        if (f.contains(e)) {
            return;
        }
        a.db.selectedSeriesItems.add(e);
    };
    SeriesViewerInteractionManager.prototype.f$aq = function (a, b, c) {
        var d = a.db;
        if (a.bn != null) {
            a = a.bn;
        }
        if (a.bk != null) {
            a = a.bk;
        }
        var e = ((function () {
            var $ret = new ChartSelection();
            $ret.item = b;
            $ret.series = a;
            return $ret;
        })());
        var f = a.db.selectedSeriesItems;
        if (!f.contains(e)) {
            return;
        }
        a.db.selectedSeriesItems.remove(e);
    };
    SeriesViewerInteractionManager.prototype.f$as = function (a, b) {
        var c = null;
        var d = null;
        var e = null;
        e = a.c9.e();
        var f;
        var g = ((function () { var 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);
        }
    };
    SeriesViewerInteractionManager.prototype.f$a = function (a) {
        if (a.av != 0) {
            return a.av;
        }
        var b = 1;
        var c = false;
        var d = false;
        for (var e = 0; e < a.series.count; e++) {
            var f = a.series._inner[e];
            if (f.isStacked) {
                f.p1(function (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;
    };
    SeriesViewerInteractionManager.prototype.f$ar = function (a) {
        var b = a.vv;
        var c = b;
        var d = a.c9;
        var e = a.ei();
        var f = a.el;
        var g = a.fy;
        var 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 (var i = 0; i < a.series.count; i++) {
            var j = a.series._inner[i];
            j.qa(c);
        }
        a.oa(c);
        var k = a.c0 == 0 && !a.e4 && (a.er || f) && !g && !h;
        var l = a.wj;
        if (k && !isNaN_(b.x) && !l.isEmpty) {
            var 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) {
            var 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();
        }
    };
    SeriesViewerInteractionManager.prototype.f$aj = function (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;
        }
    };
    SeriesViewerInteractionManager.prototype.f$t = function (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();
        }
    };
    SeriesViewerInteractionManager.prototype.ak = function (a, b) {
        var e_1, _a;
        var c = a.c9;
        var d = a.wj;
        if (a.e5 || a.e4) {
            return;
        }
        if (a.el && a.er) {
            var e = d.height > d.width;
            c.bv(e);
            try {
                for (var _b = __values(fromEnum(a.series)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var f = _c.value;
                    if (f.isStacked) {
                        f.p1(function (g) {
                            if (g._visibility == 0) {
                                g.r3(b, runOn(c, c.bm));
                            }
                            if (g.eg) {
                                g.pz(function (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(function (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));
                        }
                    }
                }
            }
            catch (e_1_1) {
                e_1 = { error: e_1_1 };
            }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return))
                        _a.call(_b);
                }
                finally {
                    if (e_1)
                        throw e_1.error;
                }
            }
            c.ea();
        }
    };
    SeriesViewerInteractionManager.prototype.aj = function (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));
        }
    };
    SeriesViewerInteractionManager.prototype.f$ah = function (a, b) {
        this.aj(a, b);
        this.ak(a, b);
        this.f$ar(a);
    };
    SeriesViewerInteractionManager.prototype.f$u = function (a, b, c) {
        if (!a.el) {
            this.am(a, b, c);
        }
    };
    SeriesViewerInteractionManager.prototype.f$s = function (a, b) {
        this.aq = Rect.empty;
        a.nw();
    };
    SeriesViewerInteractionManager.prototype.f$ao = function (a) {
        if (this.l) {
            this.f$b.onScrollbarDragCancel();
            this.l = false;
        }
        var b = a.c9;
        this.u = 1;
        this.ae(a);
        a.c0 = 0;
        this.k = true;
        a.fy = true;
        a.qa(true);
    };
    SeriesViewerInteractionManager.prototype.ae = function (a) {
        var 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();
    };
    SeriesViewerInteractionManager.prototype.f$ag = function (a, b) {
        this.f$ao(a);
    };
    SeriesViewerInteractionManager.prototype.f$ap = function (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);
    };
    SeriesViewerInteractionManager.prototype.f$af = function (a, b) {
        var c = a.c9;
        c.cg();
        c.cl();
        if (c.av) {
            this.aa(a, b);
        }
        else {
            this.ac(a, b);
            this.u = b;
        }
    };
    SeriesViewerInteractionManager.prototype.f$al = function (a, b, c, d, e) {
        var 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;
        }
        var g = a.v4;
        var h = a.wj;
        var i = b.x - this.v;
        var j = b.y - this.w;
        this.v = b.x;
        this.w = b.y;
        var k = g.width;
        var l = g.height;
        var m = this.ao.width / this.s;
        var n = this.ao.height / this.t;
        if (m > 1) {
            m = 1;
        }
        if (n > 1) {
            n = 1;
        }
        var o = { $type: Point_$type, x: b.x, y: b.y };
        var 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 };
        var q = new Rect(0, g.left, g.top, m, n);
        var 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 };
        var s = (r.x - o.x) - i;
        var t = (r.y - o.y) - j;
        var u = s / h.width * q.width;
        var 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);
    };
    SeriesViewerInteractionManager.prototype.f$ac = function (a, b) {
        this.ap = new Rect(0, b.x, b.y, 0, 0);
        this.ar = new Rect(0, b.x, b.y, 0, 0);
    };
    SeriesViewerInteractionManager.prototype.ab = function (a, b, c) {
        var d = a.v4.width;
        var e = a.v4.height;
        var f = a.v4.left + d / 2;
        var g = a.v4.top + e / 2;
        d = d / b;
        e = e / b;
        var h = f - d / 2;
        var i = g - e / 2;
        a.rx(new Rect(0, h, i, d, e), true);
    };
    SeriesViewerInteractionManager.prototype.f$ae = function (a, b) {
        var c = a.c9;
        if (c.av) {
            this.aa(a, b);
        }
        else {
            this.ac(a, b);
        }
        this.ap = Rect.empty;
        a.fy = false;
    };
    SeriesViewerInteractionManager.prototype.f$v = function (a, b) {
        a.fy = false;
        this.ap = Rect.empty;
        a.nw();
    };
    SeriesViewerInteractionManager.prototype.f$ab = function (a, b) {
        a.na();
    };
    SeriesViewerInteractionManager.prototype.f$ak = function (a, b, c, d, e) {
        a.fy = false;
        this.ap = Rect.empty;
        a.nw();
    };
    SeriesViewerInteractionManager.prototype.aa = function (a, b) {
        var c = a.wk;
        var d = 1 / b;
        var e = { $type: Point_$type, x: c.x + c.width / 2, y: c.y + c.height / 2 };
        var f = { $type: Point_$type, x: c.x - e.x, y: c.y - e.y };
        var g = new Rect(0, f.x * d + e.x, f.y * d + e.y, c.width * d, c.height * d);
        a.rx(g, true);
    };
    SeriesViewerInteractionManager.prototype.ac = function (a, b) {
        var c = a.wj;
        var d = a.wk;
        var e = b - this.u;
        if (e != 0) {
            var f = 0.03;
            var g = e < 0 ? 1 + f : 1 - f;
            var h = { $type: Point_$type, x: d.x + d.width / 2, y: d.y + d.height / 2 };
            var i = { $type: Point_$type, x: d.x - h.x, y: d.y - h.y };
            var j = new Rect(0, i.x * g + h.x, i.y * g + h.y, d.width * g, d.height * g);
            a.rx(j, true);
        }
    };
    SeriesViewerInteractionManager.prototype.f$q = function (a, b, c) {
        if (!a.fy) {
            this.k = false;
        }
        var 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);
    };
    SeriesViewerInteractionManager.prototype.am = function (a, b, c) {
        var d;
        var e = a.c9;
        if (a.cx != 0) {
            d = a.cx;
        }
        else if (e.ez == 0) {
            var 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;
    };
    SeriesViewerInteractionManager.prototype.f$an = function (a) {
        a.ri();
        a.c9.dl();
    };
    SeriesViewerInteractionManager.prototype.f$am = function (a) {
        a.nl();
        a.c9.dk();
    };
    SeriesViewerInteractionManager.prototype.f$at = function (a) {
        if (a.eh && !this.n) {
            this.n = true;
            this.al(a);
        }
    };
    SeriesViewerInteractionManager.prototype.f$n = function (a) {
        if (this.n) {
            this.ad(a);
            this.n = false;
        }
    };
    SeriesViewerInteractionManager.prototype.f$k = function (a) {
        if (this.h == null) {
            return;
        }
        this.i.ab();
    };
    Object.defineProperty(SeriesViewerInteractionManager.prototype, "i", {
        get: function () {
            return this.h;
        },
        enumerable: false,
        configurable: true
    });
    SeriesViewerInteractionManager.prototype.al = function (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();
    };
    SeriesViewerInteractionManager.prototype.ad = function (a) {
        if (this.h == null) {
            return;
        }
        a.e1 = false;
        a.c9.dg();
        this.h.ah();
        a.q0();
        a.c9.by();
    };
    SeriesViewerInteractionManager.prototype.f$m = function (a) {
        a.nf();
        a.q2();
    };
    SeriesViewerInteractionManager.prototype.p = function (a) {
        return a.c0 == 2;
    };
    SeriesViewerInteractionManager.prototype.q = function (a, b) {
        return a.cp == 1 || b || a.eh;
    };
    SeriesViewerInteractionManager.prototype.o = function (a) {
        return a.c0 == 1;
    };
    SeriesViewerInteractionManager.prototype.f$p = function (a, b, c) {
        var d = a.c9;
        if (this.l) {
            a.bc.onScrollbarDrag(b, c);
            return;
        }
        if (this.ap.isEmpty && c) {
            this.am(a, b, c);
        }
        var e = 2;
        if (c) {
            e = 10;
        }
        var f = false;
        var g = false;
        var h = new Rect(2, { $type: Point_$type, x: this.ap.x, y: this.ap.y }, b);
        var 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) {
                var 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) {
                var k = a.wi(h);
                a.qf(k, true);
            }
            else {
                a.qf(Rect.empty, true);
            }
            a.op(g);
            d.eg(h);
        }
        var l = a.wj;
        var m = a.v4;
        if (this.p(a)) {
            var n = l;
            var o = m.left + m.width * (this.ap.x - b.x) / n.width;
            var p = m.top + m.height * (this.ap.y - b.y) / n.height;
            var 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);
                var r = a.v4;
                a.rx(q, true);
                var 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);
    };
    SeriesViewerInteractionManager.prototype.f$o = function (a, b, c, d) {
        var e = a.c9;
        var f = 2;
        if (c) {
            f = 10;
        }
        var g = a.wj;
        var h = a.v4;
        if (!d) {
            if (this.l) {
                this.f$b.onScrollbarDragComplete(b, c);
                this.l = false;
                e.bw();
                return;
            }
        }
        if (!this.k) {
            var i = false;
            var 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) {
                var k = g;
                var l = h.left + h.width * (this.ap.x - b.x) / k.width;
                var m = h.top + h.height * (this.ap.y - b.y) / k.height;
                a.rx(new Rect(0, l, m, h.width, h.height), true);
            }
        }
        var n = false;
        var 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);
    };
    SeriesViewerInteractionManager.prototype.f$ai = function (a) {
        if (this.i != null) {
            this.i.h = !a.fz;
        }
    };
    SeriesViewerInteractionManager.prototype.f$g = function (a, b) {
        var e_2, _a;
        var c = a.c9;
        var 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;
        }
        var e = Rect.empty;
        var 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;
                    try {
                        for (var _b = __values(fromEnum(a.focusedSeriesItems)), _c = _b.next(); !_c.done; _c = _b.next()) {
                            var g = _c.value;
                            a.pt(g.series, g.item);
                        }
                    }
                    catch (e_2_1) {
                        e_2 = { error: e_2_1 };
                    }
                    finally {
                        try {
                            if (_c && !_c.done && (_a = _b.return))
                                _a.call(_b);
                        }
                        finally {
                            if (e_2)
                                throw e_2.error;
                        }
                    }
                }
                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;
    };
    SeriesViewerInteractionManager.prototype.ai = function (a) {
        var b = null;
        if (a.focusedSeriesItems.count > 0) {
            b = a.focusedSeriesItems._inner[0];
        }
        var 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) {
                var d = ((function () {
                    var $ret = new ChartSelection();
                    $ret.series = c;
                    $ret.item = c.dn.item(0);
                    return $ret;
                })());
                a.focusedSeriesItems.clear();
                a.focusedSeriesItems.add(d);
                return;
            }
            var e_3 = c.dn.indexOf(b.item);
            if (e_3 == -1) {
                return;
            }
            e_3++;
            if (e_3 > c.dn.count - 1) {
                return;
            }
            var f = ((function () {
                var $ret = new ChartSelection();
                $ret.series = c;
                $ret.item = c.dn.item(e_3);
                return $ret;
            })());
            a.focusedSeriesItems.clear();
            a.focusedSeriesItems.add(f);
        }
    };
    SeriesViewerInteractionManager.prototype.af = function (a) {
        var b = null;
        if (a.focusedSeriesItems.count > 0) {
            b = a.focusedSeriesItems._inner[0];
        }
        var 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) {
                var d = ((function () {
                    var $ret = new ChartSelection();
                    $ret.series = c;
                    $ret.item = c.dn.item(0);
                    return $ret;
                })());
                a.focusedSeriesItems.clear();
                a.focusedSeriesItems.add(d);
                return;
            }
            var e_4 = c.dn.indexOf(b.item);
            if (e_4 == -1) {
                return;
            }
            e_4--;
            if (e_4 < 0) {
                return;
            }
            var f = ((function () {
                var $ret = new ChartSelection();
                $ret.series = c;
                $ret.item = c.dn.item(e_4);
                return $ret;
            })());
            a.focusedSeriesItems.clear();
            a.focusedSeriesItems.add(f);
        }
    };
    SeriesViewerInteractionManager.prototype.ah = function (a) {
        var b = null;
        if (a.focusedSeriesItems.count > 0) {
            b = a.focusedSeriesItems._inner[0];
        }
        var 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) {
            var d = a.series.indexOf(c);
            if (d == -1) {
                return;
            }
            var e_5 = 0;
            if (b != null && b.item != null && c.dn != null) {
                e_5 = c.dn.indexOf(b.item);
                if (e_5 == -1) {
                    e_5 = 0;
                }
            }
            d--;
            if (d < 0) {
                return;
            }
            c = a.series._inner[d];
            if (c.dn == null) {
                var f = ((function () {
                    var $ret = new ChartSelection();
                    $ret.series = c;
                    $ret.item = null;
                    return $ret;
                })());
                a.focusedSeriesItems.clear();
                a.focusedSeriesItems.add(f);
                return;
            }
            if (e_5 > c.dn.count - 1) {
                e_5 = 0;
            }
            var g = ((function () {
                var $ret = new ChartSelection();
                $ret.series = c;
                $ret.item = c.dn.item(e_5);
                return $ret;
            })());
            a.focusedSeriesItems.clear();
            a.focusedSeriesItems.add(g);
        }
    };
    SeriesViewerInteractionManager.prototype.ag = function (a) {
        var b = null;
        if (a.focusedSeriesItems.count > 0) {
            b = a.focusedSeriesItems._inner[0];
        }
        var 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) {
            var d = a.series.indexOf(c);
            if (d == -1) {
                return;
            }
            var e_6 = 0;
            if (b != null && b.item != null && c.dn != null) {
                e_6 = c.dn.indexOf(b.item);
                if (e_6 == -1) {
                    e_6 = 0;
                }
            }
            d++;
            if (d > a.series.count - 1) {
                return;
            }
            c = a.series._inner[d];
            if (c.dn == null) {
                var f = ((function () {
                    var $ret = new ChartSelection();
                    $ret.series = c;
                    $ret.item = null;
                    return $ret;
                })());
                a.focusedSeriesItems.clear();
                a.focusedSeriesItems.add(f);
                return;
            }
            if (e_6 > c.dn.count - 1) {
                e_6 = 0;
            }
            var g = ((function () {
                var $ret = new ChartSelection();
                $ret.series = c;
                $ret.item = c.dn.item(e_6);
                return $ret;
            })());
            a.focusedSeriesItems.clear();
            a.focusedSeriesItems.add(g);
        }
    };
    SeriesViewerInteractionManager.prototype.f$h = function (a, b, c) {
        var d = a.c9;
        var e = a.v4;
        var f = e.left + e.width * b.x / a.wj.width;
        var g = e.top + e.height * b.y / a.wj.height;
        var h = 1 - MathUtil.d(c, -0.5, 0.5);
        var i = Math.max(0, f - h * (f - e.left));
        var j = Math.min(1, g + h * (e.bottom - g));
        var k = Math.min(1, f + h * (e.right - f));
        var 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();
    };
    SeriesViewerInteractionManager.prototype.z = function (a, b) {
        a.c9.bz(b);
    };
    SeriesViewerInteractionManager.prototype.f$r = function (a, b) {
        var c = a.v4;
        var d = c.left + c.width * b.x / a.wj.width;
        var e = c.top + c.height * b.y / a.wj.height;
        var f = 0.7;
        var g = Math.max(0, d - f * (d - c.left));
        var h = Math.min(1, e + f * (c.bottom - e));
        var i = Math.min(1, d + f * (c.right - d));
        var j = Math.max(0, e - f * (e - c.top));
        a.rx(new Rect(0, g, j, i - g, h - j), true);
    };
    SeriesViewerInteractionManager.prototype.f$l = function (a) {
        this.i.ac();
    };
    SeriesViewerInteractionManager.prototype.f$c = function (a, b, c, d, e, f, g) {
        var e_7, _a;
        var h = true;
        var i = false;
        var j = false;
        var 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;
        }
        var l = truncate(Math.round(d.x));
        var m = truncate(Math.round(d.y));
        f = null;
        var n = -1;
        if (h && c != null) {
            var o = l;
            var p = m;
            if (a.hi != 1) {
                o = truncate(Math.round(d.x * a.hi));
                p = truncate(Math.round(d.y * a.hi));
            }
            var 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) {
                var num2_ = q[2];
                if (num2_ % 4 != 0) {
                    num2_ = num2_ + (4 - (num2_ % 4));
                }
                var num1_ = q[1];
                if (num1_ % 4 != 0) {
                    num1_ = num1_ + (4 - (num1_ % 4));
                }
                var num0_ = q[0];
                if (num0_ % 4 != 0) {
                    num0_ = num0_ + (4 - (num0_ % 4));
                }
                var 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--;
            }
        }
        var r = null;
        var s = -1;
        if (n >= 0) {
            var t_1 = false;
            var u_1 = 0;
            try {
                for (var _b = __values(fromEnum(b)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var v = _c.value;
                    if (!v.f8) {
                        continue;
                    }
                    if (t_1) {
                        break;
                    }
                    if (v.isStacked) {
                        v.p1(function (w) {
                            if (w.kg == n) {
                                r = w;
                                s = u_1;
                                t_1 = true;
                                return false;
                            }
                            return true;
                        });
                    }
                    else if (v.kg == n) {
                        r = v;
                        s = u_1;
                        break;
                    }
                    u_1++;
                }
            }
            catch (e_7_1) {
                e_7 = { error: e_7_1 };
            }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return))
                        _a.call(_b);
                }
                finally {
                    if (e_7)
                        throw e_7.error;
                }
            }
        }
        var w = null;
        if (i) {
            var x = false;
            for (var y = b.count - 1; y >= 0; y--) {
                var z = b._inner[y];
                if (!z.f8) {
                    continue;
                }
                var 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) {
            var 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
        };
    };
    SeriesViewerInteractionManager.prototype.f$i = function (a, b) {
        if (PointUtil.equals(b, null)) {
            return false;
        }
        var c = b.x;
        var 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) {
            var e = a.c2;
            if (e != null && e.viewShouldInteract(b)) {
                return false;
            }
            return true;
        }
        return false;
    };
    SeriesViewerInteractionManager.prototype.b = function (a) {
        if (a != null) {
            return a.bp();
        }
        else {
            return null;
        }
    };
    SeriesViewerInteractionManager.prototype.f$z = function (a, b, c, d, e, f) {
        var _this = this;
        if (!f && a.eg) {
            this.an(a, false);
        }
        var 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;
        }
        var h = null;
        var i = ((function () { var j = _this.f$c(a, b, c, d, !e, h, f); h = j.p5; return j.ret; })());
        this.a = h;
        var j = this.b(i);
        if (i != null) {
            var k = false;
            var 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 (var m = 0; m < a.series.count; m++) {
                var 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);
                    }
                }
            }
        }
    };
    SeriesViewerInteractionManager.prototype.f$y = function (a, b) {
        if (this.c != null) {
            var c = this.b(this.c);
            var 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);
    };
    SeriesViewerInteractionManager.prototype.f$x = function (a, b, c) {
        if (this.c != null) {
            var 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);
            }
        }
    };
    SeriesViewerInteractionManager.prototype.f$aa = function (a, b, c) {
        var d;
        var e = (this.c != null) ? this.c : ((function () { var f = a.c9.f(c, false, d, false); d = f.p2; return f.ret; })());
        if (e != null) {
            var 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);
            }
        }
    };
    SeriesViewerInteractionManager.prototype.f$w = function (a, b, c) {
        if (!c && a.fr) {
            this.an(a, false);
        }
        if (c && !a.fr) {
            this.an(a, true);
        }
        a.ot(b, c);
    };
    SeriesViewerInteractionManager.prototype.an = function (a, b) {
        if (a != null) {
            if (!this.m) {
                a.eg = b;
            }
        }
    };
    SeriesViewerInteractionManager.prototype.f$ad = function (a, b) {
        this.j = true;
    };
    Object.defineProperty(SeriesViewerInteractionManager.prototype, "m", {
        get: function () {
            return this.j;
        },
        enumerable: false,
        configurable: true
    });
    SeriesViewerInteractionManager.$t = markType(SeriesViewerInteractionManager, 'SeriesViewerInteractionManager', Base.$, [ISeriesViewerInteractionManager_$type]);
    return SeriesViewerInteractionManager;
}(Base));
export { SeriesViewerInteractionManager };
