/*
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 { BaseDOMEventProxy } from "./BaseDOMEventProxy";
import { TypeRegistrar, runOn, delegateCombine, Point_$type, String_$type, Delegate_$type, Number_$type, markType } from "./type";
import { Dictionary$2 } from "./Dictionary$2";
import { List$1 } from "./List$1";
import { TouchPointInfo } from "./TouchPointInfo";
import { DOMExecutionContext } from "./DOMExecutionContext";
import { TouchGestureRecognizer } from "./TouchGestureRecognizer";
import { Rect } from "./Rect";
/**
 * @hidden
 */
var CanvasGestureDOMEventProxy = /** @class */ (function (_super) {
    __extends(CanvasGestureDOMEventProxy, _super);
    function CanvasGestureDOMEventProxy(a, b, c) {
        var _this = _super.call(this) || this;
        _this.db = 0;
        _this.dc = "";
        _this.cy = null;
        _this.c9 = null;
        _this.c4 = new Dictionary$2(String_$type, List$1.$.specialize(Delegate_$type), 0);
        _this.d0 = null;
        _this.cz = false;
        _this.c5 = new List$1(Number_$type, 0);
        _this.c6 = new List$1(Point_$type, 0);
        _this.c1 = false;
        _this.c7 = new List$1(TouchPointInfo.$, 0);
        _this.bq = c;
        _this.bw = b;
        _this.cy = new TouchGestureRecognizer(new DOMExecutionContext(b));
        var d = _this.cy;
        d.holdEnding = delegateCombine(d.holdEnding, runOn(_this, _this.de));
        var e = _this.cy;
        e.holdStarting = delegateCombine(e.holdStarting, runOn(_this, _this.df));
        var f = _this.cy;
        f.zoomStarting = delegateCombine(f.zoomStarting, runOn(_this, _this.dm));
        var g = _this.cy;
        g.zoomEnding = delegateCombine(g.zoomEnding, runOn(_this, _this.dl));
        var h = _this.cy;
        h.panStarting = delegateCombine(h.panStarting, runOn(_this, _this.dk));
        var i = _this.cy;
        i.panEnding = delegateCombine(i.panEnding, runOn(_this, _this.dj));
        var j = _this.cy;
        j.manipulationStarting = delegateCombine(j.manipulationStarting, runOn(_this, _this.di));
        var k = _this.cy;
        k.manipulationChanging = delegateCombine(k.manipulationChanging, runOn(_this, _this.dg));
        var l = _this.cy;
        l.manipulationEnding = delegateCombine(l.manipulationEnding, runOn(_this, _this.dh));
        var m = _this.cy;
        m.doubleTapped = delegateCombine(m.doubleTapped, runOn(_this, _this.dd));
        var n = _this.cy;
        n.flingStarting = delegateCombine(n.flingStarting, runOn(_this, _this.c0));
        _this.al = function (o) { return true; };
        _this.aa = true;
        CanvasGestureDOMEventProxy.da++;
        _this.db = CanvasGestureDOMEventProxy.da;
        _this.dc = ".DOMProxy" + _this.db.toString();
        _this.bc = 0;
        _this.bx = a;
        BaseDOMEventProxy.bn = false;
        try {
            BaseDOMEventProxy.bn = (window.navigator.msPointerEnabled && MSGesture !== undefined);
        }
        catch (o) {
        }
        BaseDOMEventProxy.bo = false;
        try {
            BaseDOMEventProxy.bo = (window.PointerEvent || window.navigator.pointerEnabled);
        }
        catch (p) {
        }
        if (BaseDOMEventProxy.br) {
            _this.aa = false;
        }
        BaseDOMEventProxy.b5 = _this.b4();
        BaseDOMEventProxy.b2 = _this.b3();
        _this.ap(_this.bx, "");
        _this.ak = function (q) { return true; };
        return _this;
    }
    CanvasGestureDOMEventProxy.prototype.d = function () {
        var a = new CanvasGestureDOMEventProxy(this.bx, this.bw, this.bq);
        a.aa = this.aa;
        a.al = this.al;
        return a;
    };
    CanvasGestureDOMEventProxy.prototype.c0 = function (a, b) {
        return this.ad({ $type: Point_$type, x: b.a, y: b.b }, b.h, b.i);
    };
    CanvasGestureDOMEventProxy.prototype.dd = function (a, b) {
        this.av({ $type: Point_$type, x: b.a, y: b.b });
    };
    CanvasGestureDOMEventProxy.prototype.get_aj = function () {
        return true;
    };
    CanvasGestureDOMEventProxy.prototype.dh = function (a, b) {
        if (this.cy.n == 0) {
            this.az({ $type: Point_$type, x: b.a, y: b.b }, b.d);
            this.ck();
        }
    };
    CanvasGestureDOMEventProxy.prototype.dg = function (a, b) {
        if (this.cy.n == 2) {
            this.a6({ $type: Point_$type, x: b.a, y: b.b }, b.d);
            this.a9({ $type: Point_$type, x: b.a, y: b.b }, b.d, b.e, b.c);
        }
        if (this.cy.n == 1 || this.cy.n == 5) {
            this.at({ $type: Point_$type, x: b.a, y: b.b }, true);
            this.ax({ $type: Point_$type, x: b.a, y: b.b });
        }
    };
    CanvasGestureDOMEventProxy.prototype.di = function (a, b) {
    };
    CanvasGestureDOMEventProxy.prototype.dj = function (a, b) {
        this.cz = false;
        if (this.cy.n == 0) {
            this.as({ $type: Point_$type, x: b.a, y: b.b }, true);
            this.aw({ $type: Point_$type, x: b.a, y: b.b });
        }
    };
    CanvasGestureDOMEventProxy.prototype.dk = function (a, b) {
        this.ay({ $type: Point_$type, x: b.a, y: b.b });
    };
    CanvasGestureDOMEventProxy.prototype.dl = function (a, b) {
        this.a8({ $type: Point_$type, x: b.a, y: b.b }, b.d, b.e, b.c);
    };
    CanvasGestureDOMEventProxy.prototype.dm = function (a, b) {
        this.a7({ $type: Point_$type, x: b.a, y: b.b }, 1);
        this.ba({ $type: Point_$type, x: b.a, y: b.b }, 1, 1, 1);
    };
    CanvasGestureDOMEventProxy.prototype.df = function (a, b) {
        this.cz = true;
        this.a0({ $type: Point_$type, x: b.a, y: b.b });
    };
    CanvasGestureDOMEventProxy.prototype.de = function (a, b) {
        if (this.cy.n == 0) {
            this.as({ $type: Point_$type, x: b.a, y: b.b }, true);
        }
    };
    CanvasGestureDOMEventProxy.c2 = function () {
        BaseDOMEventProxy.bn = false;
        try {
            BaseDOMEventProxy.bn = (window.navigator.msPointerEnabled && MSGesture !== undefined);
        }
        catch (a) {
        }
        BaseDOMEventProxy.bo = false;
        try {
            BaseDOMEventProxy.bo = (window.PointerEvent || window.navigator.pointerEnabled);
        }
        catch (b) {
        }
        return BaseDOMEventProxy.br;
    };
    CanvasGestureDOMEventProxy.prototype.dn = function (a, b, c) {
    };
    CanvasGestureDOMEventProxy.prototype.ap = function (a, b) {
        var c = a;
        if (!this.bw.supportsDOMEvents()) {
            return;
        }
        var d = this.dc + b;
        var e = new List$1(Delegate_$type, 0);
        this.c4.addItem(d, e);
        this.dn(a, b, e);
        if (!BaseDOMEventProxy.br) {
            e.add(c.listen("mousemove", runOn(this, this.cc)));
            e.add(c.listen("mouseleave", runOn(this, this.cb)));
            e.add(c.listen("mousedown", runOn(this, this.ca)));
            e.add(c.listen("mouseup", runOn(this, this.ce)));
            e.add(this.bw.globalListen("window", "mouseup", runOn(this, this.cs)));
        }
        e.add(c.listen("keydown", runOn(this, this.b7)));
        e.add(c.listen("keyup", runOn(this, this.b9)));
        if (BaseDOMEventProxy.br) {
            var source_ = this.bx.getNativeElement();
            BaseDOMEventProxy.cm(source_);
            var f = this.bx.getNativeElement();
            if (BaseDOMEventProxy.bo) {
                e.add(c.listen("pointerdown", runOn(this, this.dr)));
                e.add(c.listen("pointerup", runOn(this, this.du)));
                e.add(c.listen("pointercancel", runOn(this, this.dq)));
                e.add(c.listen("pointermove", runOn(this, this.ds)));
                e.add(c.listen("pointerleave", runOn(this, this.dt)));
                e.add(c.listen("lostpointercapture", runOn(this, this.dp)));
            }
            else {
                e.add(c.listen("MSPointerDown", runOn(this, this.dr)));
                e.add(c.listen("MSPointerUp", runOn(this, this.du)));
                e.add(c.listen("MSPointerCancel", runOn(this, this.dq)));
                e.add(c.listen("MSPointerMove", runOn(this, this.ds)));
                e.add(c.listen("MSPointerLeave", runOn(this, this.dt)));
                e.add(c.listen("MSLostPointerCapture", runOn(this, this.dp)));
            }
        }
        else {
            e.add(c.listen("touchstart", runOn(this, this.dx)));
            e.add(c.listen("touchmove", runOn(this, this.dw)));
            e.add(c.listen("touchend", runOn(this, this.dv)));
        }
        if (this.bq) {
            e.add(c.listen("wheel", runOn(this, this.cf)));
        }
        else {
            e.add(c.listen("DOMMouseScroll", runOn(this, this.cd)));
            e.add(c.listen("mousewheel", runOn(this, this.cd)));
        }
    };
    CanvasGestureDOMEventProxy.prototype.du = function (e_) {
        var a = this.bl(e_);
        var b = this.c5.indexOf((e_.originalEvent.pointerId));
        if (b >= 0) {
            this.c5.removeAt(b);
            this.c6.removeAt(b);
            this.b1 = this.c5.count;
        }
        if (a) {
            this.dv(e_);
        }
        else {
            this.ce(e_);
        }
    };
    CanvasGestureDOMEventProxy.prototype.dp = function (e_) {
        var a = this.bl(e_);
    };
    CanvasGestureDOMEventProxy.prototype.dq = function (e_) {
        var a = this.bl(e_);
        var b = this.c5.indexOf((e_.originalEvent.pointerId));
        if (b >= 0) {
            this.c5.removeAt(b);
            this.c6.removeAt(b);
            this.b1 = this.c5.count;
        }
    };
    CanvasGestureDOMEventProxy.prototype.dr = function (e_) {
        var a = this.bl(e_);
        BaseDOMEventProxy.cl(e_);
        this.c5.add((e_.originalEvent.pointerId));
        this.c6.add({ $type: Point_$type, x: e_.pageX, y: e_.pageY });
        this.b1 = this.c5.count;
        if (a) {
            this.cr(e_);
        }
        else {
            this.cq(e_);
        }
        this.cp(e_);
        if (!this.c1 && this.ab(this.cw, a, false)) {
            var eventSource_ = this.bx.getNativeElement();
            if (BaseDOMEventProxy.bo) {
                eventSource_.setPointerCapture(e_.originalEvent.pointerId);
            }
            else {
                eventSource_.msSetPointerCapture(e_.originalEvent.pointerId);
            }
        }
        if (a) {
            this.dx(e_);
        }
        else {
            this.ca(e_);
        }
    };
    CanvasGestureDOMEventProxy.prototype.ds = function (e_) {
        var a = this.bl(e_);
        BaseDOMEventProxy.cl(e_);
        this.cp(e_);
        this.cr(e_);
        var b = this.c5.indexOf((e_.originalEvent.pointerId));
        if (b >= 0) {
            this.c6._inner[b] = { $type: Point_$type, x: e_.pageX, y: e_.pageY };
        }
        if (this.c1 && this.ab(this.cw, a, false)) {
            var eventSource_ = this.bx.getNativeElement();
            if (BaseDOMEventProxy.bo) {
                eventSource_.setPointerCapture(e_.originalEvent.pointerId);
            }
            else {
                eventSource_.msSetPointerCapture(e_.originalEvent.pointerId);
            }
        }
        if (a) {
            this.dw(e_);
        }
        else {
            this.cc(e_);
        }
    };
    CanvasGestureDOMEventProxy.prototype.dt = function (e_) {
        var a = this.bl(e_);
        if (a) {
        }
        else {
            this.cb(e_);
        }
    };
    CanvasGestureDOMEventProxy.prototype.dx = function (e_) {
        this.bm = true;
        this.cp(e_);
        this.cr(e_);
        this.d0 = this.cv;
        if (this.ab(this.cw, true, false)) {
            if (!this.aa || this.b1 > 1) {
                if (this.bp) {
                    this.bp = false;
                    this.b6();
                }
                this.cn(e_);
            }
            else {
                this.bp = true;
                this.cz = false;
            }
            this.a4(this.cw, false, true);
            this.a1(this.cw);
            this.au(this.cv, true);
            this.cy.a6(this.c8(e_));
        }
    };
    CanvasGestureDOMEventProxy.prototype.c8 = function (e_) {
        var a = BaseDOMEventProxy.cx(this.bx);
        var b = this.bf;
        var c = 0;
        var d = 0;
        if (Rect.l_op_Inequality(b, null)) {
            c = b.left;
            d = b.top;
        }
        this.c7.clear();
        if (BaseDOMEventProxy.br) {
            var e = this.c5.count;
            for (var j_ = 0; j_ < e; j_++) {
                var f = this.c5._inner[j_];
                var g = this.c6._inner[j_];
                var h = g.x;
                var i = g.y;
                var j = new TouchPointInfo(1);
                j.a = (h - a.left) - b.left;
                j.b = (i - a.top) - b.top;
                this.c7.add(j);
            }
        }
        else {
            var k = (e_.originalEvent.targetTouches.length);
            for (var j_ = 0; j_ < k; j_++) {
                var l = (e_.originalEvent.targetTouches[j_].pageX);
                var m = (e_.originalEvent.targetTouches[j_].pageY);
                var n = new TouchPointInfo(1);
                n.a = (l - a.left) - c;
                n.b = (m - a.top) - d;
                this.c7.add(n);
            }
        }
        return this.c7;
    };
    CanvasGestureDOMEventProxy.prototype.dw = function (a) {
        this.bm = true;
        this.cp(a);
        this.cr(a);
        if (this.bp) {
            if ((this.ab(this.cw, true, false) && this.c3()) || this.cz == true || this.cy.n == 2) {
                this.bp = false;
                this.b6();
            }
        }
        if ((this.cz || this.cy.n == 2 || this.ab(this.cw, true, false)) && !this.bp) {
            this.cz = true;
            this.cn(a);
            this.cy.a6(this.c8(a));
        }
    };
    CanvasGestureDOMEventProxy.prototype.c3 = function () {
        var a = { $type: Point_$type, x: this.d0.x - this.cv.x, y: this.d0.y - this.cv.y };
        if (Math.abs(a.x) > Math.abs(a.y)) {
            a.y = 0;
        }
        if (Math.abs(a.y) > Math.abs(a.x)) {
            a.x = 0;
        }
        return this.al(a);
    };
    CanvasGestureDOMEventProxy.prototype.dv = function (a) {
        this.bm = false;
        this.cp(a);
        this.cr(a);
        if (this.bp) {
            this.bp = false;
            this.b6();
        }
        var b = this.cy.n;
        var c = this.ab(this.cw, true, false) || b != 0;
        if (this.cy.n != 2 && this.cy.n != 5) {
            this.a4(this.cw, false, true);
            this.a5(this.cw);
        }
        var d = this.cy.n == 2;
        if (d) {
            c = true;
            this.as({ $type: Point_$type, x: this.cy.as, y: this.cy.at }, true);
        }
        this.cy.a6(this.c8(a));
        if (this.cy.n == 0) {
            this.ck();
        }
        if (!d && this.cy.n == 0) {
            this.as({ $type: Point_$type, x: this.cy.as, y: this.cy.at }, true);
        }
        if (this.cy.n != 0) {
            c = true;
        }
        if (c) {
            this.cn(a);
        }
    };
    CanvasGestureDOMEventProxy.prototype.dy = function (a) {
        if (this.c4.containsKey(a)) {
            var b = this.c4.item(a);
            this.c4.removeItem(a);
            for (var c = 0; c < b.count; c++) {
                b._inner[c]();
            }
            b.clear();
        }
    };
    CanvasGestureDOMEventProxy.prototype.bb = function (a, b) {
        var c = a;
        var d = this.dc + b;
        this.dy(d);
    };
    CanvasGestureDOMEventProxy.prototype.aq = function () {
        if (this.bx == null) {
            return;
        }
        this.dy(this.dc);
        this.bx = null;
    };
    CanvasGestureDOMEventProxy.register = function () {
        TypeRegistrar.register("CanvasGestureDOMEventProxy", CanvasGestureDOMEventProxy.$);
    };
    CanvasGestureDOMEventProxy.$t = markType(CanvasGestureDOMEventProxy, 'CanvasGestureDOMEventProxy', BaseDOMEventProxy.$);
    CanvasGestureDOMEventProxy.da = 0;
    return CanvasGestureDOMEventProxy;
}(BaseDOMEventProxy));
export { CanvasGestureDOMEventProxy };
