/*
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 { 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
 */
export let CanvasGestureDOMEventProxy = /*@__PURE__*/ (() => {
    class CanvasGestureDOMEventProxy extends BaseDOMEventProxy {
        constructor(a, b, c) {
            super();
            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));
            let d = this.cy;
            d.holdEnding = delegateCombine(d.holdEnding, runOn(this, this.de));
            let e = this.cy;
            e.holdStarting = delegateCombine(e.holdStarting, runOn(this, this.df));
            let f = this.cy;
            f.zoomStarting = delegateCombine(f.zoomStarting, runOn(this, this.dm));
            let g = this.cy;
            g.zoomEnding = delegateCombine(g.zoomEnding, runOn(this, this.dl));
            let h = this.cy;
            h.panStarting = delegateCombine(h.panStarting, runOn(this, this.dk));
            let i = this.cy;
            i.panEnding = delegateCombine(i.panEnding, runOn(this, this.dj));
            let j = this.cy;
            j.manipulationStarting = delegateCombine(j.manipulationStarting, runOn(this, this.di));
            let k = this.cy;
            k.manipulationChanging = delegateCombine(k.manipulationChanging, runOn(this, this.dg));
            let l = this.cy;
            l.manipulationEnding = delegateCombine(l.manipulationEnding, runOn(this, this.dh));
            let m = this.cy;
            m.doubleTapped = delegateCombine(m.doubleTapped, runOn(this, this.dd));
            let n = this.cy;
            n.flingStarting = delegateCombine(n.flingStarting, runOn(this, this.c0));
            this.al = (o) => 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 = (q) => true;
        }
        d() {
            let a = new CanvasGestureDOMEventProxy(this.bx, this.bw, this.bq);
            a.aa = this.aa;
            a.al = this.al;
            return a;
        }
        c0(a, b) {
            return this.ad({ $type: Point_$type, x: b.a, y: b.b }, b.h, b.i);
        }
        dd(a, b) {
            this.av({ $type: Point_$type, x: b.a, y: b.b });
        }
        get_aj() {
            return true;
        }
        dh(a, b) {
            if (this.cy.n == 0) {
                this.az({ $type: Point_$type, x: b.a, y: b.b }, b.d);
                this.ck();
            }
        }
        dg(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 });
            }
        }
        di(a, b) {
        }
        dj(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 });
            }
        }
        dk(a, b) {
            this.ay({ $type: Point_$type, x: b.a, y: b.b });
        }
        dl(a, b) {
            this.a8({ $type: Point_$type, x: b.a, y: b.b }, b.d, b.e, b.c);
        }
        dm(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);
        }
        df(a, b) {
            this.cz = true;
            this.a0({ $type: Point_$type, x: b.a, y: b.b });
        }
        de(a, b) {
            if (this.cy.n == 0) {
                this.as({ $type: Point_$type, x: b.a, y: b.b }, true);
            }
        }
        static c2() {
            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;
        }
        dn(a, b, c) {
        }
        ap(a, b) {
            let c = a;
            if (!this.bw.supportsDOMEvents()) {
                return;
            }
            let d = this.dc + b;
            let 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) {
                let source_ = this.bx.getNativeElement();
                BaseDOMEventProxy.cm(source_);
                let 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)));
            }
        }
        du(e_) {
            let a = this.bl(e_);
            let 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_);
            }
        }
        dp(e_) {
            let a = this.bl(e_);
        }
        dq(e_) {
            let a = this.bl(e_);
            let b = this.c5.indexOf((e_.originalEvent.pointerId));
            if (b >= 0) {
                this.c5.removeAt(b);
                this.c6.removeAt(b);
                this.b1 = this.c5.count;
            }
        }
        dr(e_) {
            let 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)) {
                let 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_);
            }
        }
        ds(e_) {
            let a = this.bl(e_);
            BaseDOMEventProxy.cl(e_);
            this.cp(e_);
            this.cr(e_);
            let 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)) {
                let 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_);
            }
        }
        dt(e_) {
            let a = this.bl(e_);
            if (a) {
            }
            else {
                this.cb(e_);
            }
        }
        dx(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_));
            }
        }
        c8(e_) {
            let a = BaseDOMEventProxy.cx(this.bx);
            let b = this.bf;
            let c = 0;
            let d = 0;
            if (Rect.l_op_Inequality(b, null)) {
                c = b.left;
                d = b.top;
            }
            this.c7.clear();
            if (BaseDOMEventProxy.br) {
                let e = this.c5.count;
                for (let j_ = 0; j_ < e; j_++) {
                    let f = this.c5._inner[j_];
                    let g = this.c6._inner[j_];
                    let h = g.x;
                    let i = g.y;
                    let j = new TouchPointInfo(1);
                    j.a = (h - a.left) - b.left;
                    j.b = (i - a.top) - b.top;
                    this.c7.add(j);
                }
            }
            else {
                let k = (e_.originalEvent.targetTouches.length);
                for (let j_ = 0; j_ < k; j_++) {
                    let l = (e_.originalEvent.targetTouches[j_].pageX);
                    let m = (e_.originalEvent.targetTouches[j_].pageY);
                    let n = new TouchPointInfo(1);
                    n.a = (l - a.left) - c;
                    n.b = (m - a.top) - d;
                    this.c7.add(n);
                }
            }
            return this.c7;
        }
        dw(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));
            }
        }
        c3() {
            let 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);
        }
        dv(a) {
            this.bm = false;
            this.cp(a);
            this.cr(a);
            if (this.bp) {
                this.bp = false;
                this.b6();
            }
            let b = this.cy.n;
            let 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);
            }
            let 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);
            }
        }
        dy(a) {
            if (this.c4.containsKey(a)) {
                let b = this.c4.item(a);
                this.c4.removeItem(a);
                for (let c = 0; c < b.count; c++) {
                    b._inner[c]();
                }
                b.clear();
            }
        }
        bb(a, b) {
            let c = a;
            let d = this.dc + b;
            this.dy(d);
        }
        aq() {
            if (this.bx == null) {
                return;
            }
            this.dy(this.dc);
            this.bx = null;
        }
        static register() {
            TypeRegistrar.register("CanvasGestureDOMEventProxy", CanvasGestureDOMEventProxy.$);
        }
    }
    CanvasGestureDOMEventProxy.$t = /*@__PURE__*/ markType(CanvasGestureDOMEventProxy, 'CanvasGestureDOMEventProxy', BaseDOMEventProxy.$);
    CanvasGestureDOMEventProxy.da = 0;
    return CanvasGestureDOMEventProxy;
})();
//# sourceMappingURL=CanvasGestureDOMEventProxy.js.map
