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