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