/*
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-angular-core";
import { ISeriesViewerInteractionManager_$type } from "./ISeriesViewerInteractionManager";
import { HighlightingManager } from "./HighlightingManager";
import { SeriesViewerScrollbarManager } from "./SeriesViewerScrollbarManager";
import { Rect } from "igniteui-angular-core";
import { TileZoomManager } from "./TileZoomManager";
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
 */
var SeriesViewerInteractionManager = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(SeriesViewerInteractionManager, _super);
    function SeriesViewerInteractionManager() {
        var _this = _super.call(this) || this;
        _this.t = 0;
        _this.u = 0;
        _this.ai = null;
        _this.q = 0;
        _this.r = 0;
        _this.p = 0;
        _this.s = 0;
        _this.i = false;
        _this.aj = null;
        _this.al = null;
        _this.j = false;
        _this.l = false;
        _this.f = null;
        _this.b = null;
        _this.e = null;
        _this.ak = null;
        _this.am = null;
        _this.d = null;
        _this.a = null;
        _this.h = false;
        _this.ak = Rect.empty;
        _this.aj = Rect.empty;
        return _this;
    }
    Object.defineProperty(SeriesViewerInteractionManager.prototype, "f$b", {
        get: function () {
            if (this.b == null) {
                this.b = new HighlightingManager();
            }
            return this.b;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(SeriesViewerInteractionManager.prototype, "f$c", {
        get: function () {
            if (this.e == null) {
                this.e = new SeriesViewerScrollbarManager();
            }
            return this.e;
        },
        enumerable: false,
        configurable: true
    });
    SeriesViewerInteractionManager.prototype.f$ao = function (a, b) {
        var c = null;
        var d = null;
        var e = null;
        e = a.cq.e();
        var f;
        var g = ((function () { var h = a.cq.f(b, false, f, false); f = h.p2; return h.ret; })());
        if (g != e) {
            if (e.a6.a$c) {
                e.a6.a$z(e, b, null, null, false);
            }
        }
        c = f;
        if (a != null) {
            a.od(b);
        }
        if (g != null && !g.a6.a$c) {
            g.a6.a$y(g, b, c, d, false);
        }
    };
    SeriesViewerInteractionManager.prototype.f$a = function (a) {
        if (a.at != 0) {
            return a.at;
        }
        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.la(function (g) {
                    if (g.bo == 2) {
                        c = true;
                    }
                    if (g.bo == 1) {
                        d = true;
                    }
                    return true;
                });
            }
            else {
                if (f.bo == 2) {
                    c = true;
                }
                if (f.bo == 1) {
                    d = true;
                }
            }
        }
        if (d) {
            b = 1;
        }
        if (c) {
            b = 2;
        }
        if (c && d) {
            b = 3;
        }
        return b;
    };
    SeriesViewerInteractionManager.prototype.f$an = function (a) {
        var b = a.r6;
        var c = b;
        var d = a.cq;
        var e = a.dl();
        var f = a.dp;
        var g = a.ez;
        var h = a.e7;
        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.lg(c);
        }
        a.lp(c);
        var k = a.ch == 0 && !a.d7 && (a.dv || f) && !g && !h;
        var l = a.su;
        if (k && !isNaN_(b.x) && !l.isEmpty) {
            var m = l.width * (b.x - a.sf.left) / a.sf.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.sf.top) / a.sf.height;
            d.eh(l.left, l.top + n, l.right, l.top + n);
            d.d9();
        }
        else {
            d.cg();
        }
    };
    SeriesViewerInteractionManager.prototype.f$ag = function (a) {
        switch (a.ch) {
            case 0:
                a.cq.d5();
                this.f$an(a);
                a.cq.cd();
                break;
            case 1:
                a.cq.d7();
                a.cq.ck();
                this.f$an(a);
                a.cq.cc();
                break;
            case 2:
                a.cq.d7();
                a.cq.ck();
                this.f$an(a);
                a.cq.ce();
                break;
        }
    };
    SeriesViewerInteractionManager.prototype.f$q = function (a, b) {
        if (b.x >= 0 && b.y >= 0 && b.x <= a.su.width && b.y <= a.su.height) {
            this.ae(a, b);
        }
        else {
            a.lc();
        }
    };
    SeriesViewerInteractionManager.prototype.ae = function (a, b) {
        var e_1, _a;
        var c = a.cq;
        var d = a.su;
        if (a.d8 || a.d7) {
            return;
        }
        if (a.dp && a.dv) {
            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.la(function (g) {
                            if (g._visibility == 0) {
                                g.mo(b, runOn(c, c.bm));
                            }
                            return true;
                        });
                    }
                    else {
                        if (f._visibility == 0) {
                            f.mo(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.ad = function (a, b) {
        if (a.dv || a.d5) {
            a.dp = true;
            a.m9();
            this.aj = new Rect(0, b.x, b.y, 0, 0);
            this.al = new Rect(0, b.x, b.y, 0, 0);
            a.ch = 0;
            a.k3(a.r9(b));
        }
    };
    SeriesViewerInteractionManager.prototype.f$ae = function (a, b) {
        this.ad(a, b);
        this.ae(a, b);
        this.f$an(a);
    };
    SeriesViewerInteractionManager.prototype.f$r = function (a, b, c) {
        if (!a.dp) {
            this.ag(a, b, c);
        }
    };
    SeriesViewerInteractionManager.prototype.f$p = function (a, b) {
        this.ak = Rect.empty;
        a.lc();
    };
    SeriesViewerInteractionManager.prototype.f$al = function (a) {
        if (this.j) {
            this.f$c.onScrollbarDragCancel();
            this.j = false;
        }
        var b = a.cq;
        this.s = 1;
        this.ac(a);
        a.ch = 0;
        this.i = true;
        a.ez = true;
        a.na();
    };
    SeriesViewerInteractionManager.prototype.ac = function (a) {
        var b = a.cq;
        a.dp = false;
        b.cj();
        b.cf();
        b.ch();
        a.k3({ $type: Point_$type, x: NaN, y: NaN });
        b.cg();
        b.cl();
        b.ck();
    };
    SeriesViewerInteractionManager.prototype.f$ad = function (a, b) {
        this.f$al(a);
    };
    SeriesViewerInteractionManager.prototype.f$am = function (a, b, c, d, e) {
        this.t = b.x;
        this.u = b.y;
        this.q = c;
        this.r = d;
        this.p = e;
        this.ai = a.sf;
        this.f$al(a);
    };
    SeriesViewerInteractionManager.prototype.f$ac = function (a, b) {
        var c = a.cq;
        c.cg();
        c.cl();
        if (c.av) {
            this.y(a, b);
        }
        else {
            this.aa(a, b);
            this.s = b;
        }
    };
    SeriesViewerInteractionManager.prototype.f$ai = function (a, b, c, d, e) {
        var f = a.cq;
        f.cg();
        f.cl();
        this.q = this.q * c;
        this.r = this.r * d;
        this.p = this.p * e;
        if (a.ee) {
            this.q = this.p;
            this.r = this.p;
        }
        var g = a.sf;
        var h = a.su;
        var i = b.x - this.t;
        var j = b.y - this.u;
        this.t = b.x;
        this.u = b.y;
        var k = g.width;
        var l = g.height;
        var m = this.ai.width / this.q;
        var n = this.ai.height / this.r;
        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.ot(g, true);
    };
    SeriesViewerInteractionManager.prototype.f$z = function (a, b) {
        this.aj = new Rect(0, b.x, b.y, 0, 0);
        this.al = new Rect(0, b.x, b.y, 0, 0);
    };
    SeriesViewerInteractionManager.prototype.z = function (a, b, c) {
        var d = a.sf.width;
        var e = a.sf.height;
        var f = a.sf.left + d / 2;
        var g = a.sf.top + e / 2;
        d = d / b;
        e = e / b;
        var h = f - d / 2;
        var i = g - e / 2;
        a.ot(new Rect(0, h, i, d, e), true);
    };
    SeriesViewerInteractionManager.prototype.f$ab = function (a, b) {
        var c = a.cq;
        if (c.av) {
            this.y(a, b);
        }
        else {
            this.aa(a, b);
        }
        this.aj = Rect.empty;
        a.ez = false;
    };
    SeriesViewerInteractionManager.prototype.f$s = function (a, b) {
        a.ez = false;
        this.aj = Rect.empty;
        a.lc();
    };
    SeriesViewerInteractionManager.prototype.f$y = function (a, b) {
        a.kz();
    };
    SeriesViewerInteractionManager.prototype.f$ah = function (a, b, c, d, e) {
        a.ez = false;
        this.aj = Rect.empty;
        a.lc();
    };
    SeriesViewerInteractionManager.prototype.y = function (a, b) {
        var c = a.sv;
        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.ot(g, true);
    };
    SeriesViewerInteractionManager.prototype.aa = function (a, b) {
        var c = a.su;
        var d = a.sv;
        var e = b - this.s;
        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.ot(j, true);
        }
    };
    SeriesViewerInteractionManager.prototype.f$n = function (a, b, c) {
        if (!a.ez) {
            this.i = false;
        }
        var d = false;
        if (a.dq) {
            if (this.f$c.shouldHandleInteraction(b, c)) {
                this.j = true;
                d = true;
                this.ac(a);
                a.cq.dr();
                return;
            }
        }
        this.ag(a, b, c);
        a.mt(b, c);
    };
    SeriesViewerInteractionManager.prototype.ag = function (a, b, c) {
        var d;
        var e = a.cq;
        var f = a.cf(c);
        if (e.ez == 0) {
            switch (f) {
                case 1:
                    d = a.el() ? f : 0;
                    break;
                default:
                    d = f;
                    break;
            }
        }
        else {
            if (e.ez == a.rf) {
                d = 1;
            }
            else if (e.ez == a.rg) {
                d = 2;
            }
            else {
                d = 0;
            }
        }
        switch (d) {
            case 1:
            case 2:
                a.cq.ca();
                a.cq.dr();
                break;
        }
        a.ch = d;
        switch (a.ch) {
            case 1:
                a.k3({ $type: Point_$type, x: NaN, y: NaN });
                this.aj = new Rect(0, b.x, b.y, 0, 0);
                this.al = new Rect(0, b.x, b.y, 0, 0);
                this.ak = new Rect(0, b.x, b.y, 0, 0);
                e.d8();
                e.eg(this.aj);
                a.nf(Rect.empty, true);
                break;
            case 2:
                this.aj = new Rect(0, b.x, b.y, 0, 0);
                this.ak = new Rect(0, b.x, b.y, 0, 0);
                break;
        }
        this.am = a.sf;
        a.sw = a.sf;
    };
    SeriesViewerInteractionManager.prototype.f$ak = function (a) {
        a.oe();
        a.cq.dl();
    };
    SeriesViewerInteractionManager.prototype.f$aj = function (a) {
        a.k7();
        a.cq.dk();
    };
    SeriesViewerInteractionManager.prototype.f$ap = function (a) {
        if (a.dk && !this.l) {
            this.l = true;
            this.af(a);
        }
    };
    SeriesViewerInteractionManager.prototype.f$k = function (a) {
        if (this.l) {
            this.ab(a);
            this.l = false;
        }
    };
    SeriesViewerInteractionManager.prototype.f$h = function (a) {
        if (this.f == null) {
            return;
        }
        this.g.ab();
    };
    Object.defineProperty(SeriesViewerInteractionManager.prototype, "g", {
        get: function () {
            return this.f;
        },
        enumerable: false,
        configurable: true
    });
    SeriesViewerInteractionManager.prototype.af = function (a) {
        if (this.f == null) {
            this.f = new TileZoomManager(a, true, a.hb);
            this.f.h = !a.e0;
        }
        a.d4 = true;
        a.ne();
        this.f.al();
        a.cq.br();
        a.cq.bs();
    };
    SeriesViewerInteractionManager.prototype.ab = function (a) {
        if (this.f == null) {
            return;
        }
        a.d4 = false;
        a.cq.dg();
        this.f.ah();
        a.ny();
        a.cq.by();
    };
    SeriesViewerInteractionManager.prototype.f$j = function (a) {
        a.k1();
        a.n0();
    };
    SeriesViewerInteractionManager.prototype.n = function (a) {
        return a.ch == 2;
    };
    SeriesViewerInteractionManager.prototype.o = function (a, b) {
        return a.b7 == 1 || b || a.dk;
    };
    SeriesViewerInteractionManager.prototype.m = function (a) {
        return a.ch == 1;
    };
    SeriesViewerInteractionManager.prototype.f$m = function (a, b, c) {
        var d = a.cq;
        if (this.j) {
            a.a6.onScrollbarDrag(b, c);
            return;
        }
        if (this.aj.isEmpty && c) {
            this.ag(a, b, c);
        }
        var e = 2;
        if (c) {
            e = 10;
        }
        var f = false;
        var g = new Rect(2, { $type: Point_$type, x: this.aj.x, y: this.aj.y }, b);
        var h = new Rect(0, 0, 0, 0, 0);
        if (!this.ak.isEmpty) {
            h = new Rect(2, { $type: Point_$type, x: this.ak.x, y: this.ak.y }, b);
        }
        if (h.width > e && h.height > e) {
            f = true;
        }
        if (!a.ez) {
            if (f) {
                this.i = false;
            }
        }
        if (!a.ez && (a.dp || !c)) {
            a.k3(a.r9(b));
        }
        if (this.m(a)) {
            if (f) {
                var i = a.st(g);
                a.nf(i, true);
            }
            else {
                a.nf(Rect.empty, true);
            }
            a.l2();
            d.eg(g);
        }
        var j = a.su;
        var k = a.sf;
        if (this.n(a)) {
            var l = j;
            var m = k.left + k.width * (this.aj.x - b.x) / l.width;
            var n = k.top + k.height * (this.aj.y - b.y) / l.height;
            var o = new Rect(0, m, n, k.width, k.height);
            if (this.o(a, c)) {
                if (h.width != 0 || h.height != 0) {
                    a.na();
                }
                a.nf(Rect.empty, true);
                var p = a.sf;
                a.ot(o, true);
                var q = a.sf;
                if (p.equals1(q) && a.cq.k.ac) {
                    a.cq.k.au();
                }
                this.aj = new Rect(3, b, new Size(1, 0, 0));
                this.al = new Rect(3, b, new Size(1, 0, 0));
            }
            else {
                a.nf(o, true);
            }
        }
        this.al = new Rect(3, b, new Size(1, 0, 0));
        d.bu(b);
    };
    SeriesViewerInteractionManager.prototype.f$l = function (a, b, c, d) {
        var e = a.cq;
        var f = 2;
        if (c) {
            f = 10;
        }
        var g = a.su;
        var h = a.sf;
        if (!d) {
            if (this.j) {
                this.f$c.onScrollbarDragComplete(b, c);
                this.j = false;
                e.bw();
                return;
            }
        }
        if (!this.i) {
            var i = false;
            var j = new Rect(2, { $type: Point_$type, x: this.aj.x, y: this.aj.y }, b);
            if (j.width > f && j.height > f) {
                i = true;
            }
            if (a.ch == 1) {
                a.l1();
                e.cf();
                if (i) {
                    a.ot(a.st(j), true);
                }
            }
            if (a.ch == 2) {
                var k = g;
                var l = h.left + h.width * (this.aj.x - b.x) / k.width;
                var m = h.top + h.height * (this.aj.y - b.y) / k.height;
                a.ot(new Rect(0, l, m, h.width, h.height), true);
            }
        }
        var n = false;
        var o = new Rect(2, { $type: Point_$type, x: this.ak.x, y: this.ak.y }, b);
        if (o.width > f || o.height > f) {
            n = true;
        }
        if (n) {
            a.e7 = true;
        }
        a.ch = 0;
        a.nf(Rect.empty, true);
        e.bw();
        a.e7 = false;
        e.cg();
        e.cl();
        if (c) {
            e.ck();
            e.cg();
            e.cl();
            e.ch();
        }
        a.lc();
        a.m9();
        a.mu(b, c, d);
    };
    SeriesViewerInteractionManager.prototype.f$af = function (a) {
        if (this.g != null) {
            this.g.h = !a.e0;
        }
    };
    SeriesViewerInteractionManager.prototype.f$e = function (a, b) {
        var c = a.cq;
        var d = a.sf;
        if (a.ch == 2 && b == 8) {
            c.bt();
            a.ch = 0;
            a.m9();
            a.nf(Rect.empty, true);
            if (a.b7 == 1) {
                a.ot(this.am, true);
            }
            return true;
        }
        if (a.ch == 1 && b == 8) {
            c.bt();
            a.ch = 0;
            a.m9();
            c.cf();
            a.nf(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:
                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:
                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 15:
                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:
                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.ot(e, true);
        }
        return f;
    };
    SeriesViewerInteractionManager.prototype.f$f = function (a, b, c) {
        var d = a.cq;
        var e = a.sf;
        var f = e.left + e.width * b.x / a.su.width;
        var g = e.top + e.height * b.y / a.su.height;
        var h = 1 - MathUtil.c(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.na();
        this.x(a, 1000);
        a.ot(new Rect(0, i, l, k - i, j - l), true);
        return a.el();
    };
    SeriesViewerInteractionManager.prototype.x = function (a, b) {
        a.cq.bz(b);
    };
    SeriesViewerInteractionManager.prototype.f$o = function (a, b) {
        var c = a.sf;
        var d = c.left + c.width * b.x / a.su.width;
        var e = c.top + c.height * b.y / a.su.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.ot(new Rect(0, g, j, i - g, h - j), true);
    };
    SeriesViewerInteractionManager.prototype.f$i = function (a) {
        this.g.ac();
    };
    SeriesViewerInteractionManager.prototype.f$d = function (a, b, c, d, e, f, g) {
        var e_2, _a;
        var h = true;
        var i = false;
        var j = false;
        var k = a;
        if (k.as == 1) {
            h = false;
            i = true;
        }
        if (k.as == 3 || k.as == 4) {
            i = true;
        }
        if (k.as == 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.f4 != 1) {
                o = truncate(Math.round(d.x * a.f4));
                p = truncate(Math.round(d.y * a.f4));
            }
            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.el) {
                        continue;
                    }
                    if (t_1) {
                        break;
                    }
                    if (v.isStacked) {
                        v.la(function (w) {
                            if (w.ho == n) {
                                r = w;
                                s = u_1;
                                t_1 = true;
                                return false;
                            }
                            return true;
                        });
                    }
                    else if (v.ho == n) {
                        r = v;
                        s = u_1;
                        break;
                    }
                    u_1++;
                }
            }
            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;
                }
            }
        }
        var w = null;
        if (i) {
            var x = false;
            for (var y = b.count - 1; y >= 0; y--) {
                var z = b._inner[y];
                if (!z.el) {
                    continue;
                }
                var aa = z.b0;
                if (!z.e9(aa.bu, aa.bv, aa)) {
                    continue;
                }
                if (!x && y < s && h && !j) {
                    if (r != null) {
                        w = r;
                        x = true;
                        break;
                    }
                }
                if (z != null && z.bo == 1) {
                    if (z.ev(d, g)) {
                        w = z;
                        break;
                    }
                }
            }
            if (h && !x) {
                if (r != null) {
                    w = r;
                    x = true;
                }
            }
        }
        else {
            w = r;
        }
        if (w != null) {
            var ab = w.at({ $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$g = function (a, b) {
        if (PointUtil.equals(b, null)) {
            return false;
        }
        var c = b.x;
        var d = b.y;
        if (this.j) {
            return true;
        }
        if (c >= a.su.left && d >= a.su.top && c <= a.su.left + a.su.width && d <= a.su.top + a.su.height) {
            var e = a.cj;
            if (e != null && e.viewShouldInteract(b)) {
                return false;
            }
            return true;
        }
        return false;
    };
    SeriesViewerInteractionManager.prototype.c = function (a) {
        if (a != null) {
            return a.bf();
        }
        else {
            return null;
        }
    };
    SeriesViewerInteractionManager.prototype.f$w = function (a, b, c, d, e, f) {
        var _this = this;
        if (!f && a.dj) {
            this.ah(a, false);
        }
        var g = new MouseEventArgs();
        g.position = d;
        if (a.ch == 2 || a.ch == 1 || a.ez || (a.cj != null && a.cj.isPinching)) {
            if (this.d != null) {
                this.d.a6.a$z(this.d, g.position, this.a, g, f);
                this.d = null;
            }
            return;
        }
        var h = null;
        var i = ((function () { var j = _this.f$d(a, b, c, d, !e, h, f); h = j.p5; return j.ret; })());
        this.a = h;
        var j = this.c(i);
        if (i != null) {
            var k = false;
            var l = false;
            if (this.d != i) {
                l = true;
            }
            if (this.d == null || l) {
                k = true;
            }
            if (k) {
                if (l) {
                    if (this.d != null) {
                        j = this.c(this.d);
                        this.d.a6.a$z(this.d, g.position, h, g, f);
                        if (j != null) {
                            j.a6.a$z(j, g.position, h, g, f);
                        }
                    }
                }
                this.d = i;
                i.lv(g.position, h, g, f);
                if (j != null) {
                    j.lv(g.position, h, g, f);
                }
            }
            else {
                this.d = i;
                i.a6.a$ab(i, g.position, h, g, f);
                if (j != null) {
                    j.a6.a$ab(j, g.position, h, g, f);
                }
            }
        }
        else {
            if (this.d != null) {
                j = this.c(this.d);
                this.d.a6.a$z(this.d, g.position, h, g, f);
                if (j != null) {
                    j.a6.a$z(j, g.position, h, g, f);
                }
                this.d = null;
            }
            for (var m = 0; m < a.series.count; m++) {
                var n = a.series._inner[m];
                if (n.a6.a$b) {
                    j = this.c(n);
                    n.a6.a$z(n, g.position, n.a6.a$p, g, f);
                    if (j != null) {
                        j.a6.a$z(j, g.position, n.a6.a$p, g, f);
                    }
                }
            }
        }
    };
    SeriesViewerInteractionManager.prototype.f$v = function (a, b) {
        if (this.d != null) {
            var c = this.c(this.d);
            var d = new MouseEventArgs();
            d.position = b;
            this.d.a6.a$z(this.d, d.position, null, d, false);
            if (c != null) {
                c.a6.a$z(c, d.position, null, d, false);
            }
            this.d = null;
        }
        a.mo(b, a.ch != 0 || a.eq);
    };
    SeriesViewerInteractionManager.prototype.f$u = function (a, b, c) {
        if (this.d != null) {
            var d = new MouseButtonEventArgs();
            d.position = c;
            if (b.al) {
                this.d.a6.a$ac(this.d, d.position, this.a, d);
            }
            else {
                this.d.a6.a$w(this.d, d.position, this.a, d);
            }
        }
    };
    SeriesViewerInteractionManager.prototype.f$x = function (a, b, c) {
        var d;
        var e = (this.d != null) ? this.d : ((function () { var f = a.cq.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.a6.a$ad(e, f.position, this.a, f);
            }
            else {
                e.a6.a$aa(e, f.position, this.a, f);
            }
        }
    };
    SeriesViewerInteractionManager.prototype.f$t = function (a, b, c) {
        if (!c && a.es) {
            this.ah(a, false);
        }
        if (c && !a.es) {
            this.ah(a, true);
        }
        a.l6(b, c);
    };
    SeriesViewerInteractionManager.prototype.ah = function (a, b) {
        if (a != null) {
            if (!this.k) {
                a.dj = b;
            }
        }
    };
    SeriesViewerInteractionManager.prototype.f$aa = function (a, b) {
        this.h = true;
    };
    Object.defineProperty(SeriesViewerInteractionManager.prototype, "k", {
        get: function () {
            return this.h;
        },
        enumerable: false,
        configurable: true
    });
    SeriesViewerInteractionManager.$t = markType(SeriesViewerInteractionManager, 'SeriesViewerInteractionManager', Base.$, [ISeriesViewerInteractionManager_$type]);
    return SeriesViewerInteractionManager;
}(Base));
export { SeriesViewerInteractionManager };
