/*
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";
export class CanvasGestureDOMEventProxy extends BaseDOMEventProxy {
    constructor(a, b, c) {
        super();
        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));
        let d = this.ct;
        d.holdEnding = delegateCombine(d.holdEnding, runOn(this, this.c9));
        let e = this.ct;
        e.holdStarting = delegateCombine(e.holdStarting, runOn(this, this.da));
        let f = this.ct;
        f.zoomStarting = delegateCombine(f.zoomStarting, runOn(this, this.dh));
        let g = this.ct;
        g.zoomEnding = delegateCombine(g.zoomEnding, runOn(this, this.dg));
        let h = this.ct;
        h.panStarting = delegateCombine(h.panStarting, runOn(this, this.df));
        let i = this.ct;
        i.panEnding = delegateCombine(i.panEnding, runOn(this, this.de));
        let j = this.ct;
        j.manipulationStarting = delegateCombine(j.manipulationStarting, runOn(this, this.dd));
        let k = this.ct;
        k.manipulationChanging = delegateCombine(k.manipulationChanging, runOn(this, this.db));
        let l = this.ct;
        l.manipulationEnding = delegateCombine(l.manipulationEnding, runOn(this, this.dc));
        let m = this.ct;
        m.doubleTapped = delegateCombine(m.doubleTapped, runOn(this, this.c8));
        let n = this.ct;
        n.flingStarting = delegateCombine(n.flingStarting, runOn(this, this.cv));
        this.aj = (o) => 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 = (q) => true;
    }
    d() {
        let a = new CanvasGestureDOMEventProxy(this.bs, this.br, this.bm);
        a.z = this.z;
        a.aj = this.aj;
        return a;
    }
    cv(a, b) {
        return this.ac({ $type: Point_$type, x: b.a, y: b.b }, b.h, b.i);
    }
    c8(a, b) {
        this.as({ $type: Point_$type, x: b.a, y: b.b });
    }
    get_ah() {
        return true;
    }
    get ah() {
        return this.get_ah();
    }
    dc(a, b) {
        if (this.ct.n == 0) {
            this.aw({ $type: Point_$type, x: b.a, y: b.b }, b.d);
            this.cf();
        }
    }
    db(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 });
        }
    }
    dd(a, b) {
    }
    de(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 });
        }
    }
    df(a, b) {
        this.av({ $type: Point_$type, x: b.a, y: b.b });
    }
    dg(a, b) {
        this.a5({ $type: Point_$type, x: b.a, y: b.b }, b.d, b.e, b.c);
    }
    dh(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);
    }
    da(a, b) {
        this.cu = true;
        this.ax({ $type: Point_$type, x: b.a, y: b.b });
    }
    c9(a, b) {
        if (this.ct.n == 0) {
            this.ap({ $type: Point_$type, x: b.a, y: b.b }, true);
        }
    }
    static cx() {
        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;
    }
    di(a, b, c) {
    }
    am(a, b) {
        let c = a;
        if (!this.br.supportsDOMEvents()) {
            return;
        }
        let d = this.c7 + b;
        let 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) {
            let source_ = this.bs.getNativeElement();
            BaseDOMEventProxy.ch(source_);
            let 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)));
    }
    dp(e_) {
        let a = this.cw(e_);
        let 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_);
        }
    }
    dj(e_) {
        let a = this.cw(e_);
    }
    dk(e_) {
        let a = this.cw(e_);
        let b = this.c0.indexOf((e_.originalEvent.pointerId));
        if (b >= 0) {
            this.c0.removeAt(b);
            this.c1.removeAt(b);
            this.bw = this.c0.count;
        }
    }
    dl(e_) {
        let 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)) {
            let 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_);
        }
    }
    cw(e_) {
        let pointerEvent_ = e_.originalEvent;
        let a = false;
        if (BaseDOMEventProxy.bk) {
            a = (pointerEvent_.pointerType == 'touch');
        }
        else {
            a = (pointerEvent_.pointerType == pointerEvent_.MSPOINTER_TYPE_TOUCH);
        }
        return a;
    }
    dm(e_) {
        let a = this.cw(e_);
        BaseDOMEventProxy.cg(e_);
        let 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_);
        }
    }
    dn(e_) {
        let a = this.cw(e_);
        if (a) {
        }
        else {
            this.b6(e_);
        }
    }
    ds(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_));
        }
    }
    c3(e_) {
        let a = BaseDOMEventProxy.cs(this.bs);
        let b = this.bc;
        this.c2.clear();
        if (BaseDOMEventProxy.bj || BaseDOMEventProxy.bk) {
            let c = this.c0.count;
            for (let j_ = 0; j_ < c; j_++) {
                let d = this.c0._inner[j_];
                let e = this.c1._inner[j_];
                let f = e.x;
                let g = e.y;
                let h = new TouchPointInfo(1);
                h.a = (f - a.left) - b.left;
                h.b = (g - a.top) - b.top;
                this.c2.add(h);
            }
        }
        else {
            let i = (e_.originalEvent.targetTouches.length);
            for (let j_ = 0; j_ < i; j_++) {
                let j = (e_.originalEvent.targetTouches[j_].pageX);
                let k = (e_.originalEvent.targetTouches[j_].pageY);
                let 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;
    }
    dr(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));
        }
    }
    cy() {
        let 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);
    }
    dq(a) {
        this.bi = false;
        this.ck(a);
        this.cm(a);
        if (this.bl) {
            this.bl = false;
            this.b1();
        }
        let b = this.ct.n;
        let 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);
        }
        let 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);
        }
    }
    dt(a) {
        if (this.cz.containsKey(a)) {
            let b = this.cz.item(a);
            this.cz.removeItem(a);
            for (let c = 0; c < b.count; c++) {
                b._inner[c]();
            }
            b.clear();
        }
    }
    a8(a, b) {
        let c = a;
        let d = this.c7 + b;
        this.dt(d);
    }
    an() {
        if (this.bs == null) {
            return;
        }
        this.dt(this.c7);
        this.bs = null;
    }
    static register() {
        TypeRegistrar.register("CanvasGestureDOMEventProxy", CanvasGestureDOMEventProxy.$);
    }
}
CanvasGestureDOMEventProxy.c5 = 0;
CanvasGestureDOMEventProxy.$t = markType(CanvasGestureDOMEventProxy, 'CanvasGestureDOMEventProxy', BaseDOMEventProxy.$);
/*<BeginStatics Name="Infragistics.Controls.CanvasGestureDOMEventProxy" />*/
/*<EndStatics Name="Infragistics.Controls.CanvasGestureDOMEventProxy" />*/
//# sourceMappingURL=CanvasGestureDOMEventProxy.js.map