/*
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 } from "tslib";
import { Base, runOn, delegateCombine, Point_$type, markType, PointUtil } from "igniteui-react-core";
import { ISeriesViewerScrollbarManager_$type } from "./ISeriesViewerScrollbarManager";
import { Rect } from "igniteui-react-core";
import { Rectangle } from "igniteui-react-core";
import { DeviceUtils } from "igniteui-react-core";
import { BrushUtil } from "igniteui-react-core";
import { truncate, isNaN_ } from "igniteui-react-core";
import { dateNow } from "igniteui-react-core";
import { timeSpanFromMilliseconds, timeSpanTotalMilliseconds } from "igniteui-react-core";
/**
 * @hidden
 */
var SeriesViewerScrollbarManager = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(SeriesViewerScrollbarManager, _super);
    function SeriesViewerScrollbarManager() {
        var _this = _super.call(this) || this;
        _this.i = false;
        _this.l = true;
        _this._executionContext = null;
        _this._animator = null;
        _this._owner = null;
        _this.b = 0;
        _this.c = 0;
        _this.a = 0;
        _this.d = 0;
        _this.y = SeriesViewerScrollbarManager.aw;
        _this.at = SeriesViewerScrollbarManager.a8;
        _this.ab = SeriesViewerScrollbarManager.ax;
        _this.ag = SeriesViewerScrollbarManager.a1;
        _this.af = SeriesViewerScrollbarManager.a0;
        _this.h = true;
        _this.ao = SeriesViewerScrollbarManager.a4;
        _this.x = SeriesViewerScrollbarManager.av;
        _this.ak = SeriesViewerScrollbarManager.a2;
        _this.as = SeriesViewerScrollbarManager.a7;
        _this.ar = SeriesViewerScrollbarManager.a6;
        _this.n = true;
        _this.bl = SeriesViewerScrollbarManager.bp;
        _this.bn = SeriesViewerScrollbarManager.br;
        _this.bm = SeriesViewerScrollbarManager.bq;
        _this.bo = SeriesViewerScrollbarManager.bs;
        _this.ap = SeriesViewerScrollbarManager.a5;
        _this.ad = SeriesViewerScrollbarManager.az;
        _this.an = SeriesViewerScrollbarManager.a3;
        _this.aa = SeriesViewerScrollbarManager.ay;
        _this.bw = Rect.empty;
        _this.bz = Rect.empty;
        _this.ai = 0;
        _this.au = 0;
        _this.aq = 0;
        _this.aj = 0;
        _this.al = 0;
        _this.z = 0;
        _this.ac = 0;
        _this.ah = 0;
        _this.am = 0;
        _this.ae = 0;
        _this.g = false;
        _this.b2 = new Rectangle();
        _this.m = false;
        _this.b3 = new Rectangle();
        _this.bx = null;
        _this.by = null;
        _this.t = new Date();
        _this.f = false;
        _this.a9 = 1000;
        _this.e = false;
        _this.w = 0;
        _this.u = 0;
        _this.bv = PointUtil.create();
        _this.j = false;
        _this.k = false;
        _this.bt = { $type: Point_$type, x: NaN, y: NaN };
        _this.v = 10;
        _this.bu = null;
        _this.w = 1;
        _this.b = 0;
        _this.c = 0;
        _this.a = 1;
        _this.d = 2;
        return _this;
    }
    Object.defineProperty(SeriesViewerScrollbarManager.prototype, "o", {
        get: function () {
            return this.i;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(SeriesViewerScrollbarManager.prototype, "executionContext", {
        get: function () {
            return this._executionContext;
        },
        set: function (a) {
            this._executionContext = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(SeriesViewerScrollbarManager.prototype, "animator", {
        get: function () {
            return this._animator;
        },
        set: function (a) {
            this._animator = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(SeriesViewerScrollbarManager.prototype, "owner", {
        get: function () {
            return this._owner;
        },
        set: function (a) {
            this._owner = a;
        },
        enumerable: false,
        configurable: true
    });
    SeriesViewerScrollbarManager.prototype.onHorizontalScrollbarModeChanged = function (a) {
        var b = this.b;
        this.b = a;
        switch (a) {
            case 0:
                if (b != 0) {
                    this.be();
                }
                this.i = false;
                break;
            case 1:
                this.i = true;
                break;
            case 2:
                this.i = true;
                break;
            case 3:
                this.i = true;
                break;
        }
    };
    SeriesViewerScrollbarManager.prototype.onVerticalScrollbarModeChanged = function (a) {
        var b = this.c;
        this.c = a;
        switch (a) {
            case 0:
                if (b != 0) {
                    this.bf();
                }
                this.i = false;
                break;
            case 1:
                this.i = true;
                break;
            case 2:
                this.i = true;
                break;
            case 3:
                this.i = true;
                break;
        }
    };
    SeriesViewerScrollbarManager.prototype.bf = function () {
        this.b3._visibility = 1;
    };
    SeriesViewerScrollbarManager.prototype.be = function () {
        this.b2._visibility = 1;
    };
    SeriesViewerScrollbarManager.prototype.updateScrollbars = function (a, b, c, d, e) {
        if (c.isEmpty || e.isEmpty) {
            this.be();
            this.bf();
            return;
        }
        if (b.equals1(c) && d.equals1(e)) {
            return;
        }
        if (!b.equals1(c)) {
            this.bd();
        }
        this.bj(a, c, e);
        {
            this.bc();
        }
    };
    SeriesViewerScrollbarManager.prototype.bd = function () {
        if (!this.l) {
            this.w = 0;
        }
        if (this.animator.f()) {
            this.animator.w();
        }
        this.t = dateNow();
    };
    SeriesViewerScrollbarManager.prototype.updateBarDimensions = function (a, b, c, d, e, f, g, h, i, j, k, l, m) {
        var n = false;
        var o = isNaN_(b) ? SeriesViewerScrollbarManager.aw : b;
        var p = isNaN_(c) ? SeriesViewerScrollbarManager.av : c;
        var q = isNaN_(d) ? SeriesViewerScrollbarManager.ax : d;
        var r = isNaN_(f) ? SeriesViewerScrollbarManager.a1 : f;
        var s = isNaN_(g) ? SeriesViewerScrollbarManager.a0 : g;
        var t = e;
        var u = isNaN_(h) ? SeriesViewerScrollbarManager.a8 : h;
        var v = isNaN_(i) ? SeriesViewerScrollbarManager.a2 : i;
        var w = isNaN_(j) ? SeriesViewerScrollbarManager.a4 : j;
        var x = isNaN_(l) ? SeriesViewerScrollbarManager.a7 : l;
        var y = isNaN_(m) ? SeriesViewerScrollbarManager.a6 : m;
        var z = k;
        if (o != this.y) {
            this.y = o;
            n = true;
        }
        if (p != this.x) {
            this.x = p;
            n = true;
        }
        if (q != this.ab) {
            this.ab = q;
            n = true;
        }
        if (r != this.ag) {
            this.ag = r;
            n = true;
        }
        if (s != this.af) {
            this.af = s;
            n = true;
        }
        if (t != this.h) {
            this.h = t;
            n = true;
        }
        if (u != this.at) {
            this.at = u;
            n = true;
        }
        if (v != this.ak) {
            this.ak = v;
            n = true;
        }
        if (w != this.ao) {
            this.ao = w;
            n = true;
        }
        if (x != this.as) {
            this.as = x;
            n = true;
        }
        if (y != this.ar) {
            this.ar = y;
            n = true;
        }
        if (z != this.n) {
            this.n = z;
            n = true;
        }
        if (n) {
            this.bj(a, this.bw, this.bz);
        }
    };
    SeriesViewerScrollbarManager.prototype.updateBarAppearance = function (a, b, c, d, e, f, g, h, i) {
        var j = false;
        var k = b == null ? SeriesViewerScrollbarManager.bp : b;
        var l = d == null ? SeriesViewerScrollbarManager.bq : d;
        var m = c == null ? SeriesViewerScrollbarManager.br : c;
        var n = e == null ? SeriesViewerScrollbarManager.bs : e;
        var o = isNaN_(f) ? SeriesViewerScrollbarManager.az : f;
        var p = isNaN_(g) ? SeriesViewerScrollbarManager.a5 : g;
        if (k != this.bl) {
            this.bl = k;
            j = true;
        }
        if (m != this.bn) {
            this.bn = m;
            j = true;
        }
        if (l != this.bm) {
            this.bm = l;
            j = true;
        }
        if (n != this.bo) {
            this.bo = n;
            j = true;
        }
        if (p != this.ap) {
            this.ap = p;
            j = true;
        }
        if (p != this.ap) {
            this.ap = p;
            j = true;
        }
        if (j) {
            this.bj(a, this.bw, this.bz);
        }
    };
    SeriesViewerScrollbarManager.prototype.updateVerticalScrollbarPosition = function (a) {
        switch (a) {
            case 0:
            case 2:
                this.d = 2;
                break;
            case 1:
                this.d = 1;
                break;
        }
        this.bj(this.owner, this.bw, this.bz);
    };
    SeriesViewerScrollbarManager.prototype.updateHorizontalScrollbarPosition = function (a) {
        switch (a) {
            case 0:
            case 1:
                this.a = 1;
                break;
            case 2:
                this.a = 2;
                break;
        }
        this.bj(this.owner, this.bw, this.bz);
    };
    SeriesViewerScrollbarManager.prototype.bj = function (a, b, c) {
        if (!b.isEmpty && (b.width < 1 || b.height < 1)) {
            this.l = false;
        }
        this.bw = b;
        this.bz = c;
        if (b.isEmpty || c.isEmpty) {
            this.be();
            this.bf();
            return;
        }
        var d = c;
        var e = c;
        d = this.b0(a, d);
        if (d.isEmpty) {
            this.be();
            this.bf();
            return;
        }
        this.bx = d;
        e = this.b1(a, e);
        if (e.isEmpty) {
            this.be();
            this.bf();
            return;
        }
        this.by = e;
        var f = b.top * e.height + e.top;
        var g = b.bottom * e.height + e.top;
        var h = b.left * d.width + d.left;
        var i = b.right * d.width + d.left;
        var j = g - f;
        var k = i - h;
        var l = Math.max(j, this.ak * 2);
        var m = Math.max(k, this.x * 2);
        var n = 0;
        var o = 0;
        if (m > k) {
            n = (m - k) / 2;
            h -= n;
            i += n;
            k = m;
        }
        this.ai = n;
        if (l > j) {
            o = (l - j) / 2;
            f -= o;
            g += o;
            j = l;
        }
        this.au = o;
        this.aq = f;
        this.aj = g;
        this.al = j;
        this.z = h;
        this.ac = i;
        this.ah = k;
        if (this.d == 2) {
            this.am = e.right - (this.at + this.ao);
        }
        else {
            this.am = e.left + (this.ao);
        }
        if (this.a == 1) {
            this.ae = d.bottom - (this.y + this.ab);
        }
        else {
            this.ae = d.top + (this.ab);
        }
        this.bk(a);
    };
    SeriesViewerScrollbarManager.prototype.b0 = function (a, b) {
        var c = 0;
        var d = 0;
        if (this.h) {
            switch (this.a) {
                case 1:
                case 2:
                    if (this.c != 0) {
                        if (this.d == 2) {
                            d = this.at + this.ao + 1;
                        }
                        if (this.d == 1) {
                            c = this.at + this.ao + 1;
                        }
                    }
                    break;
            }
        }
        var e = b.width - (c + d);
        if (e <= 0) {
            return Rect.empty;
        }
        return new Rect(0, b.left + c, b.top, e, b.height);
    };
    SeriesViewerScrollbarManager.prototype.b1 = function (a, b) {
        var c = 0;
        var d = 0;
        if (this.n) {
            switch (this.d) {
                case 1:
                case 2:
                    if (this.b != 0) {
                        if (this.a == 1) {
                            d = this.y + this.ab + 1;
                        }
                        if (this.a == 2) {
                            c = this.y + this.ab + 1;
                        }
                    }
                    break;
            }
        }
        var e = b.height - (c + d);
        if (e <= 0) {
            return Rect.empty;
        }
        return new Rect(0, b.left, b.top + c, b.width, e);
    };
    SeriesViewerScrollbarManager.prototype.bk = function (a) {
        if (a == null) {
            return;
        }
        var b = 1;
        var c = 1;
        if (this.b == 1 || this.bw.width == 1) {
            b = this.aa - (this.aa * this.w);
        }
        else {
            b = this.aa;
        }
        if (this.c == 1 || this.bw.height == 1) {
            c = this.an - (this.an * this.w);
        }
        else {
            c = this.an;
        }
        var d = this.ae;
        var e = this.y;
        if (this.b == 2) {
            if (this.w != 0) {
                if (this.a == 1) {
                    d = this.ae + ((this.y + this.ab) - 3) * this.w;
                    e = this.y - (this.y - 3) * this.w;
                }
                if (this.a == 2) {
                    d = this.ae;
                    e = this.y - (this.y - 3) * this.w;
                }
            }
        }
        var f = this.am;
        var g = this.at;
        if (this.c == 2) {
            if (this.w != 0) {
                if (this.d == 2) {
                    f = this.am + ((this.at + this.ao) - 3) * this.w;
                    g = this.at - (this.at - 3) * this.w;
                }
                if (this.d == 1) {
                    f = this.am;
                    g = this.at - (this.at - 3) * this.w;
                }
            }
        }
        var h = this.b2;
        h._visibility = this.b != 0 ? 0 : 1;
        h.width = this.ah;
        h.height = e;
        h.ad = this.ad;
        h._fill = this.bl;
        h._stroke = this.bm;
        h.ap = this.x;
        h.aq = this.x;
        h._opacity = b;
        var i = this.b3;
        i._visibility = this.c != 0 ? 0 : 1;
        i.width = g;
        i.height = this.al;
        i.ad = this.ap;
        i._fill = this.bn;
        i._stroke = this.bo;
        i.ap = this.ak;
        i.aq = this.ak;
        i._opacity = c;
        h.n = this.z;
        h.o = d;
        i.n = f;
        i.o = this.aq;
        if (!this.g) {
            this.g = true;
            a.c9.b6(h);
        }
        if (!this.m) {
            this.m = true;
            a.c9.b9(i);
        }
        a.c9.b8();
    };
    SeriesViewerScrollbarManager.prototype.bc = function () {
        if (!this.f) {
            this.f = true;
            this.executionContext.executeDelayed(runOn(this, this.bb), this.a9);
        }
    };
    SeriesViewerScrollbarManager.prototype.bb = function () {
        if ((+(dateNow()) - +(this.t)) > timeSpanFromMilliseconds(300)) {
            this.f = false;
            this.bi();
        }
        else {
            this.executionContext.executeDelayed(runOn(this, this.bb), truncate(timeSpanTotalMilliseconds((+(dateNow()) - +(this.t)))));
        }
    };
    SeriesViewerScrollbarManager.prototype.bi = function () {
        if (this.r(this.bt) || this.s(this.bt)) {
            return;
        }
        if (!this.e) {
            this.e = true;
            var a = this.animator;
            a.propertyChanged = delegateCombine(a.propertyChanged, runOn(this, this.ba));
        }
        if (this.w != 1) {
            this.u = this.w;
            this.animator.w();
            this.animator.v();
        }
    };
    SeriesViewerScrollbarManager.prototype.ba = function (a, b) {
        this.w = (1 - this.u) * this.animator.o;
        this.bk(this.owner);
    };
    SeriesViewerScrollbarManager.prototype.shouldHandleInteraction = function (a, b) {
        var c = { $type: Point_$type, x: a.x + this.bz.left, y: a.y + this.bz.top };
        if (this.b != 0) {
            if (this.p(c, b)) {
                this.j = true;
                this.k = true;
                this.bv = { $type: Point_$type, x: c.x, y: c.y };
                this.bu = { $type: Point_$type, x: c.x, y: c.y };
                return true;
            }
        }
        if (this.c != 0) {
            if (this.q(c, b)) {
                this.j = true;
                this.k = false;
                this.bv = { $type: Point_$type, x: c.x, y: c.y };
                this.bu = { $type: Point_$type, x: c.x, y: c.y };
                return true;
            }
        }
        return false;
    };
    SeriesViewerScrollbarManager.prototype.onCrosshairMoved = function (a) {
        this.bt = { $type: Point_$type, x: a.x, y: a.y };
        if (this.r(a) || this.s(a)) {
            this.bd();
            this.bk(this.owner);
        }
        else {
            this.bc();
        }
    };
    SeriesViewerScrollbarManager.prototype.q = function (a, b) {
        if (this.c == 0) {
            return false;
        }
        var c = this.v;
        if (!b) {
            c = 0;
        }
        var d = Math.abs(a.x - this.am) < c || Math.abs(a.y - (this.am + this.at)) < c || (a.x >= this.am && a.x <= (this.am + this.at));
        var e = Math.abs(a.y - this.aq) < c || Math.abs(a.y - (this.aq + this.al)) < c || (a.y >= this.aq && a.y <= (this.aq + this.al));
        return d && e;
    };
    SeriesViewerScrollbarManager.prototype.p = function (a, b) {
        if (this.b == 0) {
            return false;
        }
        var c = this.v;
        if (!b) {
            c = 0;
        }
        var d = Math.abs(a.x - this.z) < c || Math.abs(a.y - (this.z + this.ah)) < c || (a.x >= this.z && a.x <= (this.z + this.ah));
        var e = Math.abs(a.y - this.ae) < c || Math.abs(a.y - (this.ae + this.y)) < c || (a.y >= this.ae && a.y <= (this.ae + this.y));
        return e && d;
    };
    SeriesViewerScrollbarManager.prototype.s = function (a) {
        if (this.c == 0) {
            return false;
        }
        var b = Math.abs(a.x - this.am) < this.v || Math.abs(a.y - (this.am + this.at)) < this.v || (a.x >= this.am && a.x <= (this.am + this.at));
        return b;
    };
    SeriesViewerScrollbarManager.prototype.r = function (a) {
        if (this.b == 0) {
            return false;
        }
        var b = Math.abs(a.y - this.ae) < this.v || Math.abs(a.y - (this.ae + this.y)) < this.v || (a.y >= this.ae && a.y <= (this.ae + this.y));
        return b;
    };
    SeriesViewerScrollbarManager.prototype.onScrollbarDrag = function (a, b) {
        var c = { $type: Point_$type, x: a.x + this.bz.left, y: a.y + this.bz.top };
        var d = c.x - this.bu.x;
        var e = c.y - this.bu.y;
        this.bu = { $type: Point_$type, x: c.x, y: c.y };
        if (this.k) {
            this.bg(d);
        }
        else {
            this.bh(e);
        }
    };
    SeriesViewerScrollbarManager.prototype.bh = function (a) {
        var b = this.by;
        var c = this.au * 2;
        var d = b.height - c;
        var e = a / d;
        var f = this.owner.v4;
        var g = new Rect(0, f.left, f.top + e, f.width, f.height);
        this.owner.wk = g;
    };
    SeriesViewerScrollbarManager.prototype.bg = function (a) {
        var b = this.bx;
        var c = this.ai * 2;
        var d = b.width - c;
        var e = a / d;
        var f = this.owner.v4;
        var g = new Rect(0, f.left + e, f.top, f.width, f.height);
        this.owner.wk = g;
    };
    SeriesViewerScrollbarManager.prototype.onScrollbarDragComplete = function (a, b) {
        this.j = false;
    };
    SeriesViewerScrollbarManager.prototype.onScrollbarDragCancel = function () {
        this.j = false;
    };
    SeriesViewerScrollbarManager.$t = markType(SeriesViewerScrollbarManager, 'SeriesViewerScrollbarManager', Base.$, [ISeriesViewerScrollbarManager_$type]);
    SeriesViewerScrollbarManager.aw = DeviceUtils.g(8);
    SeriesViewerScrollbarManager.a8 = DeviceUtils.g(8);
    SeriesViewerScrollbarManager.ax = DeviceUtils.g(1);
    SeriesViewerScrollbarManager.a1 = DeviceUtils.g(0);
    SeriesViewerScrollbarManager.a0 = DeviceUtils.g(0);
    SeriesViewerScrollbarManager.a4 = DeviceUtils.g(1);
    SeriesViewerScrollbarManager.av = DeviceUtils.g(4);
    SeriesViewerScrollbarManager.a2 = DeviceUtils.g(4);
    SeriesViewerScrollbarManager.a7 = DeviceUtils.g(0);
    SeriesViewerScrollbarManager.a6 = DeviceUtils.g(0);
    SeriesViewerScrollbarManager.bp = BrushUtil.h(255, 120, 120, 120);
    SeriesViewerScrollbarManager.br = BrushUtil.h(255, 120, 120, 120);
    SeriesViewerScrollbarManager.bq = BrushUtil.h(255, 120, 120, 120);
    SeriesViewerScrollbarManager.bs = BrushUtil.h(255, 120, 120, 120);
    SeriesViewerScrollbarManager.a5 = DeviceUtils.g(1);
    SeriesViewerScrollbarManager.az = DeviceUtils.g(1);
    SeriesViewerScrollbarManager.a3 = DeviceUtils.g(0.9);
    SeriesViewerScrollbarManager.ay = DeviceUtils.g(0.9);
    return SeriesViewerScrollbarManager;
}(Base));
export { SeriesViewerScrollbarManager };
