/*
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 * as tslib_1 from "tslib";
import { Base, runOn, delegateCombine, markType, INotifyPropertyChanged_$type, PropertyChangedEventArgs, Point_$type } from "./type";
import { CanvasGestureDOMEventProxy } from "./CanvasGestureDOMEventProxy";
import { Brush } from "./Brush";
import { Rect } from "./Rect";
import { truncate } from "./number";
import { ScrollerScrollingEventArgs } from "./ScrollerScrollingEventArgs";
var ScrollerView = /** @class */ (function (_super) {
    tslib_1.__extends(ScrollerView, _super);
    function ScrollerView(a) {
        var _this = _super.call(this) || this;
        _this.b = null;
        _this.w = null;
        _this.aa = null;
        _this.v = null;
        _this.a = null;
        _this.z = null;
        _this.x = null;
        _this.y = null;
        _this.ab = null;
        _this.d = false;
        _this.c = null;
        _this.h = false;
        _this.g = false;
        _this.r = 0;
        _this.o = 0;
        _this.s = -1;
        _this.p = -1;
        _this.f = false;
        _this.e = false;
        _this.q = 0;
        _this.n = 0;
        _this.b = a;
        return _this;
    }
    ScrollerView.prototype.aw = function () {
        return ((function () {
            var $ret = new Brush();
            $ret.fill = "#666666";
            return $ret;
        })());
    };
    ScrollerView.prototype.ap = function (a) {
        if (a == null) {
            if (this.w != null) {
                this.w = null;
            }
            if (this.a != null) {
                this.a.ai = null;
                this.a.an();
            }
            return;
        }
        this.w = a;
        var b = Math.round(this.w.rootWrapper.width());
        var c = Math.round(this.w.rootWrapper.height());
        this.z = this.w.rootWrapper;
        this.z.setStyleProperty("position", "relative");
        this.aa = this.w.createElement("div");
        this.aa.setStyleProperty("position", "relative");
        this.aa.setStyleProperty("width", "100%");
        this.aa.setStyleProperty("height", "100%");
        this.aa.setStyleProperty("overflow", "hidden");
        this.z.append(this.aa);
        this.y = this.w.createElement("div");
        this.y.setStyleProperty("position", "absolute");
        this.y.setStyleProperty("height", this.b.scrollbarSpan + "px");
        this.y.setStyleProperty("width", this.b.minScrollbarSize + "px");
        this.y.setStyleProperty("background-color", this.b.scrollbarBrush._fill);
        this.y.setStyleProperty("display", "none");
        this.y.setStyleProperty("border-radius", "5px");
        this.y.setStyleProperty("z-index", "10000");
        this.y.setStyleProperty("bottom", c + "px");
        this.z.append(this.y);
        this.ab = this.w.createElement("div");
        this.ab.setStyleProperty("position", "absolute");
        this.ab.setStyleProperty("width", this.b.scrollbarSpan + "px");
        this.ab.setStyleProperty("height", this.b.minScrollbarSize + "px");
        this.ab.setStyleProperty("background-color", this.b.scrollbarBrush._fill);
        this.ab.setStyleProperty("display", "none");
        this.ab.setStyleProperty("border-radius", "5px");
        this.ab.setStyleProperty("z-index", "10000");
        this.ab.setStyleProperty("right", "0px");
        this.z.append(this.ab);
        this.v = this.aa.getNativeElement();
        this.a = new CanvasGestureDOMEventProxy(this.w.rootWrapper, this.w, true);
        var d = this.a;
        d.onMouseWheel = delegateCombine(d.onMouseWheel, runOn(this, this.j));
        var e = this.a;
        e.onDragStarted = delegateCombine(e.onDragStarted, runOn(this, this.ai));
        var f = this.a;
        f.onDragDelta = delegateCombine(f.onDragDelta, runOn(this, this.ah));
        var g = this.a;
        g.onDragCompleted = delegateCombine(g.onDragCompleted, runOn(this, this.ag));
        var h = this.a;
        h.onFlingStarted = delegateCombine(h.onFlingStarted, runOn(this, this.i));
        var i = this.a;
        i.onContactStarted = delegateCombine(i.onContactStarted, runOn(this, this.af));
        var j = this.a;
        j.onContactMoved = delegateCombine(j.onContactMoved, runOn(this, this.ae));
        var k = this.a;
        k.onContactCompleted = delegateCombine(k.onContactCompleted, runOn(this, this.ad));
        this.a.z = true;
        this.a.ak = runOn(this, this.m);
        this.b.aw(b, c);
    };
    ScrollerView.prototype.m = function (a, b, c) {
        if (this.e || this.f) {
            return true;
        }
        if (c || b) {
            return true;
        }
        if (this.k(a, b)) {
            return true;
        }
        if (this.l(a, b)) {
            return true;
        }
        return false;
    };
    ScrollerView.prototype.ad = function (a, b) {
        this.e = false;
        this.f = false;
    };
    ScrollerView.prototype.ae = function (a, b) {
        if (this.f) {
            var c = a.y - this.q;
            this.q = a.y;
            this.b.av(c);
        }
        else if (this.e) {
            var d = a.x - this.n;
            this.n = a.x;
            this.b.at(d);
        }
    };
    ScrollerView.prototype.af = function (a, b) {
        this.d = false;
        this.ac();
        var c = this.l(a, b);
        var d = this.k(a, b);
        if (c) {
            this.f = true;
            this.q = a.y;
        }
        else if (d) {
            this.e = true;
            this.n = a.x;
        }
    };
    ScrollerView.prototype.k = function (a, b) {
        if (!this.g) {
            return false;
        }
        if (a.y >= this.b.viewportHeight - this.b.scrollbarSpan && a.y <= this.b.viewportHeight && a.x >= this.p - this.o / 2 && a.x <= this.p + this.o / 2) {
            return true;
        }
        return false;
    };
    ScrollerView.prototype.l = function (a, b) {
        if (!this.h) {
            return false;
        }
        if (a.x >= this.b.viewportWidth - this.b.scrollbarSpan && a.x <= this.b.viewportWidth && a.y >= this.s - this.r / 2 && a.y <= this.s + this.r / 2) {
            return true;
        }
        return false;
    };
    ScrollerView.prototype.i = function (a, b, c) {
        this.d = true;
        return true;
    };
    ScrollerView.prototype.an = function (a) {
        this.a.bc = new Rect(0, 0, 0, this.b.viewportWidth, this.b.viewportHeight);
    };
    ScrollerView.prototype.ao = function (a) {
        this.a.bc = new Rect(0, 0, 0, this.b.viewportWidth, this.b.viewportHeight);
    };
    ScrollerView.prototype.al = function (a) {
        if (this.x != null) {
            this.x.setStyleProperty("height", a + "px");
        }
    };
    ScrollerView.prototype.am = function (a) {
        if (this.x != null) {
            this.x.setStyleProperty("width", a + "px");
        }
    };
    ScrollerView.prototype.ac = function () {
    };
    ScrollerView.prototype.ag = function (a) {
        if (this.e || this.f) {
            return;
        }
        this.d = false;
        this.b.aq(a);
    };
    ScrollerView.prototype.ah = function (a) {
        if (this.e || this.f) {
            return;
        }
        this.b.ar(a);
    };
    ScrollerView.prototype.au = function (a) {
        this.v.scrollTop = truncate(a);
    };
    ScrollerView.prototype.ai = function (a) {
        if (this.e || this.f) {
            return;
        }
        this.d = false;
        this.b.as(a);
    };
    ScrollerView.prototype.t = function () {
        return this.v.scrollLeft;
    };
    ScrollerView.prototype.u = function () {
        return this.v.scrollTop;
    };
    ScrollerView.prototype.j = function (a, b) {
        this.d = false;
        this.ac();
        return this.b.l(a, b);
    };
    ScrollerView.prototype.at = function (a) {
        this.v.scrollLeft = truncate(a);
    };
    ScrollerView.prototype.aq = function (a) {
        this.x = a;
        this.aa.append(this.x);
    };
    ScrollerView.prototype.ar = function (a) {
        if (this.w == null) {
            return;
        }
        if (this.c == null) {
            this.c = this.w.getRequestAnimationFrame();
        }
        if (this.d) {
            a();
        }
        else {
            this.c(function () { return a(); });
        }
    };
    ScrollerView.prototype.ak = function () {
        if (this.h) {
            this.h = false;
            this.ab.setStyleProperty("display", "none");
        }
    };
    ScrollerView.prototype.aj = function () {
        if (this.g) {
            this.g = false;
            this.y.setStyleProperty("display", "none");
        }
    };
    ScrollerView.prototype.av = function (a, b) {
        var c = false;
        if (!this.h) {
            c = true;
            this.h = true;
            this.ab.setStyleProperty("display", "block");
        }
        if (a != this.s || c) {
            this.s = a;
            if (this.h) {
                this.ab.setRawYPosition(a - b / 2);
            }
        }
        if (b != this.r || c) {
            this.r = b;
            if (this.h) {
                this.ab.setRawSize(this.b.scrollbarSpan, b);
            }
        }
    };
    ScrollerView.prototype.as = function (a, b) {
        var c = false;
        if (!this.g) {
            c = true;
            this.g = true;
            this.y.setStyleProperty("display", "block");
        }
        if (a != this.p || c) {
            this.p = a;
            if (this.g) {
                this.y.setRawXPosition(a - b / 2);
            }
        }
        if (b != this.o || c) {
            this.o = b;
            if (this.g) {
                this.y.setRawSize(b, this.b.scrollbarSpan);
            }
        }
    };
    ScrollerView.$t = markType(ScrollerView, 'ScrollerView');
    return ScrollerView;
}(Base));
export { ScrollerView };
var Scroller = /** @class */ (function (_super) {
    tslib_1.__extends(Scroller, _super);
    function Scroller() {
        var _this = _super.call(this) || this;
        _this.n = 0;
        _this.o = 20;
        _this.r = 8;
        _this.u = 0;
        _this.a6 = null;
        _this.m = 0;
        _this.w = 0;
        _this.v = 0;
        _this.t = 0;
        _this.s = 0;
        _this.b = null;
        _this.h = true;
        _this.j = false;
        _this.g = false;
        _this.e = false;
        _this.f = false;
        _this.a8 = null;
        _this.d = false;
        _this.propertyChanged = null;
        _this.onScrolling = null;
        _this.p = 0;
        _this.q = 0;
        _this.i = false;
        _this.a6 = _this.view.aw();
        return _this;
    }
    Object.defineProperty(Scroller.prototype, "contentWidth", {
        get: function () {
            return this.n;
        },
        set: function (a) {
            var b = this.n;
            this.n = a;
            if (b != this.n) {
                this.au("ContentWidth", b, this.n);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "minScrollbarSize", {
        get: function () {
            return this.o;
        },
        set: function (a) {
            var b = this.o;
            this.o = a;
            if (b != this.o) {
                this.au("MinScrollbarSize", b, this.o);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "scrollbarSpan", {
        get: function () {
            return this.r;
        },
        set: function (a) {
            var b = this.r;
            this.r = a;
            if (b != this.r) {
                this.au("ScrollbarSpan", b, this.r);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "verticalTrackStartInset", {
        get: function () {
            return this.u;
        },
        set: function (a) {
            var b = this.u;
            this.u = a;
            if (b != this.u) {
                this.au("VerticalTrackStartInset", b, this.u);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "scrollbarBrush", {
        get: function () {
            return this.a6;
        },
        set: function (a) {
            var b = this.a6;
            this.a6 = a;
            if (b != this.a6) {
                this.au("ScrollbarBrush", b, this.a6);
            }
        },
        enumerable: true,
        configurable: true
    });
    Scroller.prototype.au = function (a, b, c) {
        if (this.propertyChanged != null) {
            this.propertyChanged(this, new PropertyChangedEventArgs(a));
        }
        this.ax(a, b, c);
    };
    Scroller.prototype.ax = function (a, b, c) {
        switch (a) {
            case "ContentWidth":
                this.view.am(this.contentWidth);
                this.a3();
                break;
            case "ContentHeight":
                this.view.al(this.contentHeight);
                this.a5();
                break;
            case "ScrollTop":
                this.view.au(this.scrollTop);
                break;
            case "ScrollLeft":
                this.view.at(this.scrollLeft);
                break;
            case "ViewportWidth":
                this.view.ao(this.viewportWidth);
                break;
            case "ViewportHeight":
                this.view.an(this.viewportHeight);
                break;
            case "ScrollbarBrush":
            case "ScrollbarSpan":
            case "MinScrollbarSize":
            case "VerticalTrackStartInset":
                this.a5();
                this.a3();
                break;
        }
    };
    Object.defineProperty(Scroller.prototype, "contentHeight", {
        get: function () {
            return this.m;
        },
        set: function (a) {
            var b = this.m;
            this.m = a;
            if (b != this.m) {
                this.au("ContentHeight", b, this.m);
            }
        },
        enumerable: true,
        configurable: true
    });
    Scroller.prototype.av = function (a) {
        var b = this.verticalTrackStartInset + (this.minScrollbarSize / 2);
        var c = this.viewportHeight - (this.minScrollbarSize / 2);
        var d = a / (c - b);
        var e = d * (this.contentHeight - this.viewportHeight);
        this.a1(0, e);
    };
    Scroller.prototype.at = function (a) {
        var b = 0 + (this.minScrollbarSize / 2);
        var c = this.viewportWidth - (this.minScrollbarSize / 2);
        var d = a / (c - b);
        var e = d * (this.contentWidth - this.viewportWidth);
        this.a1(e, 0);
    };
    Scroller.prototype.aw = function (a, b) {
        this.w = a;
        this.v = b;
    };
    Object.defineProperty(Scroller.prototype, "viewportWidth", {
        get: function () {
            return this.w;
        },
        set: function (a) {
            var b = this.w;
            this.w = a;
            if (b != this.w) {
                this.au("ViewportWidth", b, this.w);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "viewportHeight", {
        get: function () {
            return this.v;
        },
        set: function (a) {
            var b = this.v;
            this.v = a;
            if (b != this.v) {
                this.au("ViewportHeight", b, this.v);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "scrollTop", {
        get: function () {
            return this.t;
        },
        set: function (a) {
            var b = this.t;
            this.t = a;
            if (b != this.t) {
                this.au("ScrollTop", b, this.t);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "scrollLeft", {
        get: function () {
            return this.s;
        },
        set: function (a) {
            var b = this.s;
            this.s = a;
            if (b != this.s) {
                this.au("ScrollLeft", b, this.s);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "view", {
        get: function () {
            if (this.b == null) {
                this.b = new ScrollerView(this);
            }
            return this.b;
        },
        enumerable: true,
        configurable: true
    });
    Scroller.prototype.provideContainer = function (a) {
        this.view.ap(a);
        this.t = this.view.u();
        this.s = this.view.t();
        this.a3();
        this.a5();
    };
    Scroller.prototype.provideContent = function (a) {
        this.view.aq(a);
    };
    Scroller.prototype.l = function (a, b) {
        this.f = false;
        this.e = false;
        this.g = false;
        this.view.ac();
        this.a1(0, b);
        return true;
    };
    Object.defineProperty(Scroller.prototype, "lockScrollDirection", {
        get: function () {
            return this.h;
        },
        set: function (a) {
            this.h = true;
        },
        enumerable: true,
        configurable: true
    });
    Scroller.prototype.as = function (a) {
        this.g = false;
        this.e = false;
        this.f = false;
        this.d = true;
        this.a8 = { $type: Point_$type, x: a.x, y: a.y };
    };
    Scroller.prototype.ar = function (a) {
        if (this.d) {
            var b = a.y - this.a8.y;
            var c = a.x - this.a8.x;
            if (this.lockScrollDirection && !this.f) {
                this.f = true;
                if (b > 0 || c > 0) {
                    if (b > c) {
                        this.g = true;
                    }
                    else {
                        this.g = true;
                    }
                }
            }
            this.a8 = { $type: Point_$type, x: a.x, y: a.y };
            this.a1(-c, -b);
        }
    };
    Scroller.prototype.a1 = function (a, b) {
        this.p += a;
        this.q += b;
        this.a0();
    };
    Scroller.prototype.a0 = function () {
        if (this.i) {
            return;
        }
        this.i = true;
        this.view.ar(runOn(this, this.a2));
    };
    Scroller.prototype.a2 = function () {
        this.i = false;
        var a = this.p;
        var b = this.q;
        this.p = 0;
        this.q = 0;
        if (this.f) {
            if (this.g) {
                a = 0;
            }
            if (this.e) {
                b = 0;
            }
        }
        var c = Math.round(this.scrollTop + b);
        var d = Math.round(this.scrollLeft + a);
        if (c < 0) {
            c = 0;
            this.view.ac();
        }
        if (d < 0) {
            d = 0;
            this.view.ac();
        }
        if (c + this.viewportHeight > this.contentHeight) {
            c = this.contentHeight - this.viewportHeight;
            if (c < 0) {
                c = 0;
            }
            this.view.ac();
        }
        if (d + this.viewportWidth > this.contentWidth) {
            d = this.contentWidth - this.viewportWidth;
            if (d < 0) {
                d = 0;
            }
            this.view.ac();
        }
        b = c - this.scrollTop;
        a = d - this.scrollLeft;
        if (b != 0 || a != 0) {
            this.j = true;
            this.scrollTop = c;
            this.scrollLeft = d;
            this.a5();
            this.a3();
            this.j = false;
            if (this.onScrolling != null) {
                this.onScrolling(this, ((function () {
                    var $ret = new ScrollerScrollingEventArgs();
                    $ret.deltaX = a;
                    $ret.deltaY = b;
                    return $ret;
                })()));
            }
        }
    };
    Scroller.prototype.a5 = function () {
        this.a4(this.contentHeight, this.viewportHeight, this.scrollTop, true);
    };
    Scroller.prototype.a3 = function () {
        this.a4(this.contentWidth, this.viewportWidth, this.scrollLeft, false);
    };
    Scroller.prototype.a4 = function (a, b, c, d) {
        var e = Math.round((b / a) * b);
        if (e < this.minScrollbarSize) {
            e = this.minScrollbarSize;
        }
        if (e >= b) {
            if (d) {
                this.view.ak();
            }
            else {
                this.view.aj();
            }
            return;
        }
        var f = d ? this.verticalTrackStartInset : 0;
        var g = f + (e / 2);
        var h = b - (e / 2);
        var i = c / (a - b);
        var j = Math.round(g + (h - g) * i);
        if (d) {
            this.view.av(j, e);
        }
        else {
            this.view.as(j, e);
        }
    };
    Scroller.prototype.aq = function (a) {
        this.f = false;
        this.e = false;
        this.g = false;
        this.d = false;
    };
    Scroller.$t = markType(Scroller, 'Scroller', Base.$, [INotifyPropertyChanged_$type]);
    return Scroller;
}(Base));
export { Scroller };
//# sourceMappingURL=ScrollerView_combined.js.map