/*
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";
var CanvasGestureDOMEventProxy = /** @class */ (function (_super) {
    tslib_1.__extends(CanvasGestureDOMEventProxy, _super);
    function CanvasGestureDOMEventProxy(a, b, c) {
        var _this = _super.call(this) || this;
        _this.c6 = 0;
        _this.c7 = "";
        _this.ct = null;
        _this.c4 = null;
        _this.cz = new Dictionary$2(String_$type, List$1.$.specialize(Delegate_$type), 0);
        _this.dv = null;
        _this.cu = false;
        _this.c0 = new List$1(Number_$type, 0);
        _this.c1 = new List$1(Point_$type, 0);
        _this.c2 = new List$1(TouchPointInfo.$, 0);
        _this.bm = c;
        _this.br = b;
        _this.ct = new TouchGestureRecognizer(new DOMExecutionContext(b));
        var d = _this.ct;
        d.holdEnding = delegateCombine(d.holdEnding, runOn(_this, _this.c9));
        var e = _this.ct;
        e.holdStarting = delegateCombine(e.holdStarting, runOn(_this, _this.da));
        var f = _this.ct;
        f.zoomStarting = delegateCombine(f.zoomStarting, runOn(_this, _this.dh));
        var g = _this.ct;
        g.zoomEnding = delegateCombine(g.zoomEnding, runOn(_this, _this.dg));
        var h = _this.ct;
        h.panStarting = delegateCombine(h.panStarting, runOn(_this, _this.df));
        var i = _this.ct;
        i.panEnding = delegateCombine(i.panEnding, runOn(_this, _this.de));
        var j = _this.ct;
        j.manipulationStarting = delegateCombine(j.manipulationStarting, runOn(_this, _this.dd));
        var k = _this.ct;
        k.manipulationChanging = delegateCombine(k.manipulationChanging, runOn(_this, _this.db));
        var l = _this.ct;
        l.manipulationEnding = delegateCombine(l.manipulationEnding, runOn(_this, _this.dc));
        var m = _this.ct;
        m.doubleTapped = delegateCombine(m.doubleTapped, runOn(_this, _this.c8));
        var n = _this.ct;
        n.flingStarting = delegateCombine(n.flingStarting, runOn(_this, _this.cv));
        _this.aj = function (o) { return true; };
        _this.z = true;
        CanvasGestureDOMEventProxy.c5++;
        _this.c6 = CanvasGestureDOMEventProxy.c5;
        _this.c7 = ".DOMProxy" + _this.c6.toString();
        _this.a9 = 0;
        _this.bs = a;
        BaseDOMEventProxy.bj = false;
        try {
            BaseDOMEventProxy.bj = (window.navigator.msPointerEnabled && MSGesture !== undefined);
        }
        catch (o) {
        }
        BaseDOMEventProxy.bk = false;
        try {
            BaseDOMEventProxy.bk = (window.PointerEvent || window.navigator.pointerEnabled);
        }
        catch (p) {
        }
        if (BaseDOMEventProxy.bj || BaseDOMEventProxy.bk) {
            _this.z = false;
        }
        BaseDOMEventProxy.b0 = _this.bz();
        BaseDOMEventProxy.bx = _this.by();
        _this.am(_this.bs, "");
        _this.ai = function (q) { return true; };
        return _this;
    }
    CanvasGestureDOMEventProxy.prototype.d = function () {
        var a = new CanvasGestureDOMEventProxy(this.bs, this.br, this.bm);
        a.z = this.z;
        a.aj = this.aj;
        return a;
    };
    CanvasGestureDOMEventProxy.prototype.cv = function (a, b) {
        return this.ac({ $type: Point_$type, x: b.a, y: b.b }, b.h, b.i);
    };
    CanvasGestureDOMEventProxy.prototype.c8 = function (a, b) {
        this.as({ $type: Point_$type, x: b.a, y: b.b });
    };
    CanvasGestureDOMEventProxy.prototype.get_ah = function () {
        return true;
    };
    Object.defineProperty(CanvasGestureDOMEventProxy.prototype, "ah", {
        get: function () {
            return this.get_ah();
        },
        enumerable: true,
        configurable: true
    });
    CanvasGestureDOMEventProxy.prototype.dc = function (a, b) {
        if (this.ct.n == 0) {
            this.aw({ $type: Point_$type, x: b.a, y: b.b }, b.d);
            this.cf();
        }
    };
    CanvasGestureDOMEventProxy.prototype.db = function (a, b) {
        if (this.ct.n == 2) {
            this.a3({ $type: Point_$type, x: b.a, y: b.b }, b.d);
            this.a6({ $type: Point_$type, x: b.a, y: b.b }, b.d, b.e, b.c);
        }
        if (this.ct.n == 1 || this.ct.n == 5) {
            this.aq({ $type: Point_$type, x: b.a, y: b.b }, true);
            this.au({ $type: Point_$type, x: b.a, y: b.b });
        }
    };
    CanvasGestureDOMEventProxy.prototype.dd = function (a, b) {
    };
    CanvasGestureDOMEventProxy.prototype.de = function (a, b) {
        this.cu = false;
        if (this.ct.n == 0) {
            this.ap({ $type: Point_$type, x: b.a, y: b.b }, true);
            this.at({ $type: Point_$type, x: b.a, y: b.b });
        }
    };
    CanvasGestureDOMEventProxy.prototype.df = function (a, b) {
        this.av({ $type: Point_$type, x: b.a, y: b.b });
    };
    CanvasGestureDOMEventProxy.prototype.dg = function (a, b) {
        this.a5({ $type: Point_$type, x: b.a, y: b.b }, b.d, b.e, b.c);
    };
    CanvasGestureDOMEventProxy.prototype.dh = function (a, b) {
        this.a4({ $type: Point_$type, x: b.a, y: b.b }, 1);
        this.a7({ $type: Point_$type, x: b.a, y: b.b }, 1, 1, 1);
    };
    CanvasGestureDOMEventProxy.prototype.da = function (a, b) {
        this.cu = true;
        this.ax({ $type: Point_$type, x: b.a, y: b.b });
    };
    CanvasGestureDOMEventProxy.prototype.c9 = function (a, b) {
        if (this.ct.n == 0) {
            this.ap({ $type: Point_$type, x: b.a, y: b.b }, true);
        }
    };
    CanvasGestureDOMEventProxy.cx = function () {
        BaseDOMEventProxy.bj = false;
        try {
            BaseDOMEventProxy.bj = (window.navigator.msPointerEnabled && MSGesture !== undefined);
        }
        catch (a) {
        }
        BaseDOMEventProxy.bk = false;
        try {
            BaseDOMEventProxy.bk = (window.PointerEvent || window.navigator.pointerEnabled);
        }
        catch (b) {
        }
        return BaseDOMEventProxy.bj || BaseDOMEventProxy.bk;
    };
    CanvasGestureDOMEventProxy.prototype.di = function (a, b, c) {
    };
    CanvasGestureDOMEventProxy.prototype.am = function (a, b) {
        var c = a;
        if (!this.br.supportsDOMEvents()) {
            return;
        }
        var d = this.c7 + b;
        var e = new List$1(Delegate_$type, 0);
        this.cz.addItem(d, e);
        this.di(a, b, e);
        if (!BaseDOMEventProxy.bj && !BaseDOMEventProxy.bk) {
            e.add(c.listen("mousemove", runOn(this, this.b7)));
            e.add(c.listen("mouseleave", runOn(this, this.b6)));
            e.add(c.listen("mousedown", runOn(this, this.b5)));
            e.add(c.listen("mouseup", runOn(this, this.b9)));
            e.add(this.br.globalListen("window", "mouseup", runOn(this, this.cn)));
        }
        e.add(c.listen("keydown", runOn(this, this.b2)));
        e.add(c.listen("keyup", runOn(this, this.b4)));
        if (BaseDOMEventProxy.bj || BaseDOMEventProxy.bk) {
            var source_ = this.bs.getNativeElement();
            BaseDOMEventProxy.ch(source_);
            var f = this.bs.getNativeElement();
            if (BaseDOMEventProxy.bk) {
                e.add(c.listen("pointerdown", runOn(this, this.dl)));
                e.add(c.listen("pointerup", runOn(this, this.dp)));
                e.add(c.listen("pointercancel", runOn(this, this.dk)));
                e.add(c.listen("pointermove", runOn(this, this.dm)));
                e.add(c.listen("pointerout", runOn(this, this.dn)));
                e.add(c.listen("lostpointercapture", runOn(this, this.dj)));
            }
            else {
                e.add(c.listen("MSPointerDown", runOn(this, this.dl)));
                e.add(c.listen("MSPointerUp", runOn(this, this.dp)));
                e.add(c.listen("MSPointerCancel", runOn(this, this.dk)));
                e.add(c.listen("MSPointerMove", runOn(this, this.dm)));
                e.add(c.listen("MSPointerOut", runOn(this, this.dn)));
                e.add(c.listen("MSLostPointerCapture", runOn(this, this.dj)));
            }
        }
        if (this.bm) {
            e.add(c.listen("wheel", runOn(this, this.ca)));
        }
        else {
            e.add(c.listen("DOMMouseScroll", runOn(this, this.b8)));
            e.add(c.listen("mousewheel", runOn(this, this.b8)));
        }
        e.add(c.listen("touchstart", runOn(this, this.ds)));
        e.add(c.listen("touchmove", runOn(this, this.dr)));
        e.add(c.listen("touchend", runOn(this, this.dq)));
    };
    CanvasGestureDOMEventProxy.prototype.dp = function (e_) {
        var a = this.cw(e_);
        var b = this.c0.indexOf((e_.originalEvent.pointerId));
        if (b >= 0) {
            this.c0.removeAt(b);
            this.c1.removeAt(b);
            this.bw = this.c0.count;
        }
        if (a) {
            this.dq(e_);
        }
        else {
            this.b9(e_);
        }
    };
    CanvasGestureDOMEventProxy.prototype.dj = function (e_) {
        var a = this.cw(e_);
    };
    CanvasGestureDOMEventProxy.prototype.dk = function (e_) {
        var a = this.cw(e_);
        var b = this.c0.indexOf((e_.originalEvent.pointerId));
        if (b >= 0) {
            this.c0.removeAt(b);
            this.c1.removeAt(b);
            this.bw = this.c0.count;
        }
    };
    CanvasGestureDOMEventProxy.prototype.dl = function (e_) {
        var a = this.cw(e_);
        BaseDOMEventProxy.cg(e_);
        this.c0.add((e_.originalEvent.pointerId));
        this.c1.add({ $type: Point_$type, x: e_.pageX, y: e_.pageY });
        this.bw = this.c0.count;
        if (a) {
            this.cm(e_);
        }
        else {
            this.cl(e_);
        }
        this.ck(e_);
        if (this.aa(this.cr, a, false)) {
            var eventSource_ = this.bs.getNativeElement();
            if (BaseDOMEventProxy.bk) {
                eventSource_.setPointerCapture(e_.originalEvent.pointerId);
            }
            else {
                eventSource_.msSetPointerCapture(e_.originalEvent.pointerId);
            }
        }
        if (a) {
            this.ds(e_);
        }
        else {
            this.b5(e_);
        }
    };
    CanvasGestureDOMEventProxy.prototype.cw = function (e_) {
        var pointerEvent_ = e_.originalEvent;
        var a = false;
        if (BaseDOMEventProxy.bk) {
            a = (pointerEvent_.pointerType == 'touch');
        }
        else {
            a = (pointerEvent_.pointerType == pointerEvent_.MSPOINTER_TYPE_TOUCH);
        }
        return a;
    };
    CanvasGestureDOMEventProxy.prototype.dm = function (e_) {
        var a = this.cw(e_);
        BaseDOMEventProxy.cg(e_);
        var b = this.c0.indexOf((e_.originalEvent.pointerId));
        if (b >= 0) {
            this.c1._inner[b] = { $type: Point_$type, x: e_.pageX, y: e_.pageY };
        }
        if (a) {
            this.dr(e_);
        }
        else {
            this.b7(e_);
        }
    };
    CanvasGestureDOMEventProxy.prototype.dn = function (e_) {
        var a = this.cw(e_);
        if (a) {
        }
        else {
            this.b6(e_);
        }
    };
    CanvasGestureDOMEventProxy.prototype.ds = function (e_) {
        this.bi = true;
        this.ck(e_);
        this.cm(e_);
        this.dv = this.cq;
        if (this.aa(this.cr, true, false)) {
            if (!this.z || this.bw > 1) {
                if (this.bl) {
                    this.bl = false;
                    this.b1();
                }
                this.ci(e_);
            }
            else {
                this.bl = true;
                this.cu = false;
            }
            this.a1(this.cr, false, true);
            this.ay(this.cr);
            this.ar(this.cq, true);
            this.ct.a6(this.c3(e_));
        }
    };
    CanvasGestureDOMEventProxy.prototype.c3 = function (e_) {
        var a = BaseDOMEventProxy.cs(this.bs);
        var b = this.bc;
        this.c2.clear();
        if (BaseDOMEventProxy.bj || BaseDOMEventProxy.bk) {
            var c = this.c0.count;
            for (var j_ = 0; j_ < c; j_++) {
                var d = this.c0._inner[j_];
                var e = this.c1._inner[j_];
                var f = e.x;
                var g = e.y;
                var h = new TouchPointInfo(1);
                h.a = (f - a.left) - b.left;
                h.b = (g - a.top) - b.top;
                this.c2.add(h);
            }
        }
        else {
            var i = (e_.originalEvent.targetTouches.length);
            for (var j_ = 0; j_ < i; j_++) {
                var j = (e_.originalEvent.targetTouches[j_].pageX);
                var k = (e_.originalEvent.targetTouches[j_].pageY);
                var l = new TouchPointInfo(1);
                l.a = (j - a.left) - b.left;
                l.b = (k - a.top) - b.top;
                this.c2.add(l);
            }
        }
        return this.c2;
    };
    CanvasGestureDOMEventProxy.prototype.dr = function (a) {
        this.bi = true;
        this.ck(a);
        this.cm(a);
        if (this.bl) {
            if ((this.aa(this.cr, true, false) && this.cy()) || this.cu == true || this.ct.n == 2) {
                this.bl = false;
                this.b1();
            }
        }
        if ((this.cu || this.ct.n == 2 || this.aa(this.cr, true, false)) && !this.bl) {
            this.cu = true;
            this.ci(a);
            this.ct.a6(this.c3(a));
        }
    };
    CanvasGestureDOMEventProxy.prototype.cy = function () {
        var a = { $type: Point_$type, x: this.dv.x - this.cq.x, y: this.dv.y - this.cq.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.aj(a);
    };
    CanvasGestureDOMEventProxy.prototype.dq = function (a) {
        this.bi = false;
        this.ck(a);
        this.cm(a);
        if (this.bl) {
            this.bl = false;
            this.b1();
        }
        var b = this.ct.n;
        var c = this.aa(this.cr, true, false) || b != 0;
        if (this.ct.n != 2 && this.ct.n != 5) {
            this.a1(this.cr, false, true);
            this.a2(this.cr);
        }
        var d = this.ct.n == 2;
        if (d) {
            c = true;
            this.ap({ $type: Point_$type, x: this.ct.as, y: this.ct.at }, true);
        }
        this.ct.a6(this.c3(a));
        if (this.ct.n == 0) {
            this.cf();
        }
        if (!d && this.ct.n == 0) {
            this.ap({ $type: Point_$type, x: this.ct.as, y: this.ct.at }, true);
        }
        if (this.ct.n != 0) {
            c = true;
        }
        if (c) {
            this.ci(a);
        }
    };
    CanvasGestureDOMEventProxy.prototype.dt = function (a) {
        if (this.cz.containsKey(a)) {
            var b = this.cz.item(a);
            this.cz.removeItem(a);
            for (var c = 0; c < b.count; c++) {
                b._inner[c]();
            }
            b.clear();
        }
    };
    CanvasGestureDOMEventProxy.prototype.a8 = function (a, b) {
        var c = a;
        var d = this.c7 + b;
        this.dt(d);
    };
    CanvasGestureDOMEventProxy.prototype.an = function () {
        if (this.bs == null) {
            return;
        }
        this.dt(this.c7);
        this.bs = null;
    };
    CanvasGestureDOMEventProxy.register = function () {
        TypeRegistrar.register("CanvasGestureDOMEventProxy", CanvasGestureDOMEventProxy.$);
    };
    CanvasGestureDOMEventProxy.c5 = 0;
    CanvasGestureDOMEventProxy.$t = markType(CanvasGestureDOMEventProxy, 'CanvasGestureDOMEventProxy', BaseDOMEventProxy.$);
    return CanvasGestureDOMEventProxy;
}(BaseDOMEventProxy));
export { CanvasGestureDOMEventProxy };
/*<BeginStatics Name="Infragistics.Controls.CanvasGestureDOMEventProxy" />*/
/*<EndStatics Name="Infragistics.Controls.CanvasGestureDOMEventProxy" />*/
//# sourceMappingURL=CanvasGestureDOMEventProxy.js.map