/*
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 { Base, runOn, markType, PointUtil } from "igniteui-webcomponents-core";
import { INativeCell_$type } from "./INativeCell";
import { GridExpansionIndicator } from "./GridExpansionIndicator";
import { PlaceholderView } from "./PlaceholderView";
import { Color } from "igniteui-webcomponents-core";
import { DeviceUtils } from "igniteui-webcomponents-core";
import { Random } from "igniteui-webcomponents-core";
import { intDivide, truncate, isNaN_ } from "igniteui-webcomponents-core";
/**
 * @hidden
 */
export let GridCellBase = /*@__PURE__*/ (() => {
    class GridCellBase extends Base {
        constructor(a) {
            super();
            this.a = null;
            this.c = null;
            this.v = null;
            this.x = null;
            this.y = null;
            this.g = null;
            this.ak = 0;
            this.ah = 24;
            this.aj = 0;
            this.ai = 0;
            this.an = 0;
            this.k = false;
            this.l = false;
            this.i = false;
            this.ap = 0;
            this.ar = 0;
            this.aq = 0;
            this.ao = 0;
            this.ac = 0;
            this.ae = 0;
            this.ad = 0;
            this.ab = 0;
            this.b7 = null;
            this.al = 0;
            this.au = 0;
            this.am = 0;
            this.h = null;
            this.e = 0;
            this.f = 0;
            this.u = 0;
            this.t = 0;
            this.m = false;
            this.a0 = 0;
            this.a1 = 0;
            this.aa = 0;
            this.at = -1;
            this.af = 0;
            this.j = false;
            this.v = a;
            this.x = this.v.createElement("div");
            this.x.setAttribute("tabindex", "-1");
            this.x.setRawStyleProperty("position", "absolute");
            this.x.setRawStyleProperty("overflow", "hidden");
            this.x.setRawStyleProperty("box-sizing", "border-box");
            this.x.setRawStyleProperty("outline", "none");
            let b = (window.navigator.msPointerEnabled && MSGesture !== undefined);
            let c = (window.PointerEvent || window.navigator.pointerEnabled);
            let d = (window.TouchEvent);
            if ((b || c)) {
                this.x.listen("pointerdown", runOn(this, this.bi));
                this.x.listen("pointerup", runOn(this, this.bm));
                this.x.listen("pointermove", runOn(this, this.bl));
                this.x.listen("pointerleave", runOn(this, this.bk));
                this.x.listen("pointerenter", runOn(this, this.bj));
            }
            else {
                this.x.listen("mousedown", runOn(this, this.a8));
                this.x.listen("mouseup", runOn(this, this.bc));
                this.x.listen("mousemove", runOn(this, this.bb));
                this.x.listen("mouseleave", runOn(this, this.ba));
                this.x.listen("touchstart", runOn(this, this.bz));
                this.x.listen("touchend", runOn(this, this.b1));
                this.x.listen("touchmove", runOn(this, this.b0));
            }
        }
        get b() {
            return this.a;
        }
        get d() {
            return this.c;
        }
        get w() {
            return this.v;
        }
        get z() {
            return this.x;
        }
        get ax() {
            return this.ak;
        }
        get av() {
            return this.ai;
        }
        get aw() {
            return this.aj;
        }
        get ay() {
            return this.an;
        }
        set ay(a) {
            let b = this.an;
            this.an = a;
            if (b != this.an) {
                this.bh("Indent", b, this.an);
            }
        }
        get o() {
            return this.k;
        }
        set o(a) {
            let b = this.k;
            this.k = a;
            if (b != this.k) {
                this.bh("IsCollapsable", b, this.k);
            }
        }
        get p() {
            return this.l;
        }
        set p(a) {
            let b = this.l;
            this.l = a;
            if (b != this.l) {
                this.bh("IsExpanded", b, this.l);
            }
        }
        a7() {
            this.aj = 10;
            this.ai = this.ay * 24;
            this.ak = 24;
            if (this.y == null) {
                this.y = this.v.createElement("div");
                this.y.setRawStyleProperty("display", "inline-block");
                this.y.setRawStyleProperty("vertical-align", "middle");
                this.y.setRawStyleProperty("width", this.ak + "px");
                this.y.setRawStyleProperty("height", this.ak + "px");
                this.y.setRawStyleProperty("cursor", "pointer");
                this.y.setRawStyleProperty("position", "absolute");
                this.y.setRawXPosition(this.ap + this.ai);
                this.y.setRawYPosition(intDivide(this.al, 2) - intDivide(this.ah, 2));
            }
            if (this.g == null) {
                let a = this.v.getSubRenderer(this.y);
                this.g = new GridExpansionIndicator();
                this.g.ab(a);
                this.g.y(24, 24);
            }
            if (this.y.parent() == null) {
                this.x.append(this.y);
            }
        }
        bn() {
            this.ak = 0;
            this.aj = 0;
            if (this.y != null) {
                if (this.y.parent() != null) {
                    this.y.remove();
                }
            }
        }
        get n() {
            return this.i;
        }
        set n(a) {
            this.i = a;
        }
        get_r() {
            return false;
        }
        get r() {
            return this.get_r();
        }
        bv(a, b, c, d) {
            this.ap = a;
            this.ar = b;
            this.aq = c;
            this.ao = d;
            this.x.setRawStyleProperty("padding-left", a.toString() + "px");
            this.x.setRawStyleProperty("padding-top", b.toString() + "px");
            this.x.setRawStyleProperty("padding-right", c.toString() + "px");
            this.x.setRawStyleProperty("padding-bottom", d.toString() + "px");
        }
        bq(a, b, c, d, e) {
            this.ac = b;
            this.ae = c;
            this.ad = d;
            this.ab = e;
            this.b7 = a;
            if (a == null) {
                this.x.setRawStyleProperty("border", "");
            }
            else {
                this.x.setRawStyleProperty("border-color", a._fill);
                this.x.setRawStyleProperty("border-left-width", b.toString() + "px");
                this.x.setRawStyleProperty("border-top-width", c.toString() + "px");
                this.x.setRawStyleProperty("border-right-width", d.toString() + "px");
                this.x.setRawStyleProperty("border-bottom-width", e.toString() + "px");
                this.x.setRawStyleProperty("border-style", "solid");
            }
        }
        get_q() {
            return false;
        }
        get q() {
            return this.get_q();
        }
        br(a, b) {
            if (this.al != a || this.am != b) {
                let c = this.al;
                this.al = a;
                this.am = b;
                let d = Math.max(0, this.al - this.am);
                this.x.setRawStyleProperty("height", a.toString() + "px");
                this.x.setRawStyleProperty("line-height", d.toString() + "px");
                if (this.y != null) {
                    this.y.setRawYPosition(intDivide(this.al, 2) - intDivide(this.ak, 2));
                }
                this.by(this.au, this.al, this.au, c);
            }
        }
        bx(a, b) {
            if (this.au != a) {
                let c = this.au;
                this.au = a;
                this.x.setRawStyleProperty("width", a.toString() + "px");
                this.by(this.au, this.al, c, this.al);
            }
        }
        by(a, b, c, d) {
        }
        a5() {
            if (!this.r) {
                return;
            }
            this.i = true;
            this.h = new PlaceholderView(this.v);
            this.e = 0;
            this.f = 1;
            this.h.l = Color.u(120, 120, 120, 120);
            this.h.i = 0;
            this.x.append(this.h.g);
        }
        bp(a) {
            this.x.setRawStyleProperty("background-color", a.colorString);
        }
        bu(a) {
            this.x.setRawStyleProperty("opacity", a.toString());
        }
        b6(a) {
            if (!this.r) {
                return;
            }
            this.h.i = (a * 0.20000000298023224);
        }
        b4(a, b, c, d) {
            if (this.h != null) {
                let e = this.u;
                let f = this.t;
                if (this.f == 1) {
                    b = truncate((b + (d / 2) - (f / 2)));
                }
                else if (this.f == 2) {
                    b = truncate((b + (d) - (f)));
                }
                if (this.e == 1) {
                    a = truncate((a + (c / 2) - (e / 2)));
                }
                else if (this.e == 2) {
                    a = truncate((a + (c) - (e)));
                }
                this.h.g.setRawXPosition(a);
                this.h.g.setRawYPosition(b);
            }
        }
        bf(a, b, c) {
        }
        b5(a) {
            if (!this.r) {
                return;
            }
            let b = DeviceUtils.f(12);
            if (a.af != null && !isNaN_(a.af.d)) {
                b = a.af.d;
            }
            if (this.t != b) {
                this.t = b;
                this.h.d = (b);
            }
            let c = a.gg * 0.2;
            let d = a.e0 * 0.6;
            if (this.u >= c && this.u <= d && !this.m) {
                return;
            }
            this.m = false;
            let e = (GridCellBase.az.nextDouble() * (d - c) + c);
            if (this.u != e) {
                this.u = e;
                this.h.e = e;
            }
            this.b4(this.ap + this.ai + this.ak, this.ar, this.au - (this.ap + this.aq), this.al - (this.ar + this.ao));
        }
        b2(a, b) {
            if (!this.r) {
                return;
            }
            this.e = a;
            this.f = b;
            this.m = true;
        }
        b3(a) {
            if (!this.r) {
                return;
            }
            if (a != null) {
                this.h.l = a.color;
            }
        }
        bo(a) {
            this.a = a;
        }
        bt(a) {
            this.c = a;
        }
        bs(a, b) {
            switch (b) {
                case 0:
                    this.z.setRawStyleProperty("text-align", "left");
                    break;
                case 1:
                    this.z.setRawStyleProperty("text-align", "center");
                    break;
                case 2:
                    this.z.setRawStyleProperty("text-align", "right");
                    break;
                case 3:
                    this.z.setRawStyleProperty("text-align", "center");
                    break;
            }
        }
        bw(a, b) {
            switch (b) {
                case 0:
                    a.setRawStyleProperty("vertical-align", "top");
                    break;
                case 1:
                    a.setRawStyleProperty("vertical-align", "center");
                    break;
                case 2:
                    a.setRawStyleProperty("vertical-align", "bottom");
                    break;
                case 3:
                    a.setRawStyleProperty("vertical-align", "center");
                    break;
            }
        }
        s(a) {
            return a.isClickActionDesired;
        }
        a8(a) {
            this.onContactStarted(a, false);
        }
        bc(a) {
            this.onContactCompleted(a, false);
        }
        bb(a) {
            this.onContactMoved(a, false);
        }
        ba(a) {
            this.be(a, false);
        }
        a9(a) {
            this.bd(a, false);
        }
        bi(e_) {
            let a = (e_.originalEvent.pointerType);
            if (a == "touch") {
                this.bz(e_);
            }
            else {
                this.a8(e_);
            }
        }
        bl(e_) {
            let a = (e_.originalEvent.pointerType);
            if (a == "touch") {
                this.b0(e_);
            }
            else {
                this.bb(e_);
            }
        }
        bm(e_) {
            let a = (e_.originalEvent.pointerType);
            if (a == "touch") {
                this.b1(e_);
            }
            else {
                this.bc(e_);
            }
        }
        bk(e_) {
            let a = (e_.originalEvent.pointerType);
            if (a != "touch") {
                this.ba(e_);
            }
        }
        bj(e_) {
            let a = (e_.originalEvent.pointerType);
            if (a != "touch") {
                this.a9(e_);
            }
        }
        bz(a) {
            this.onContactStarted(a, true);
        }
        b0(a) {
            this.onContactMoved(a, true);
        }
        b1(a) {
            this.onContactCompleted(a, true);
        }
        onContactStarted(e_, a) {
            let b = false;
            if (this.o) {
                let indicator_ = this.g.q();
                b = (e_.originalEvent.srcElement === indicator_ || e_.originalEvent.target === indicator_);
            }
            this.j = false;
            if (b) {
                this.j = true;
            }
            else {
                if (this.a != null && this.s(this.a)) {
                    this.a0 = e_.pageX;
                    this.a1 = e_.pageY;
                    if (this.at != e_.which) {
                        this.af = 0;
                    }
                    this.at = e_.which;
                    this.a.mouseDownCell(this.a0, this.a1);
                }
            }
        }
        onContactMoved(a, b) {
            if (this.a != null) {
                let c = a.pageX;
                let d = a.pageY;
                if (this.s(this.a)) {
                    if (this.a.isMouseDown) {
                        if (b) {
                            if (PointUtil.equals(this.a.mousePosition, null) || Math.abs(c - this.a.mousePosition.x) > GridCellBase.as || Math.abs(d - this.a.mousePosition.y) > GridCellBase.as) {
                                this.a.mouseUpCell(c, d);
                            }
                            else {
                                a.stopPropagation();
                            }
                        }
                        else {
                            if (PointUtil.equals(this.a.mousePosition, null)) {
                                this.a.mouseUpCell(c, d);
                            }
                            else if (this.at == 1) {
                                if (Math.abs(c - this.a.mousePosition.x) > GridCellBase.ag || Math.abs(d - this.a.mousePosition.y) > GridCellBase.ag) {
                                    this.a.isControlPressed = a.ctrlKey;
                                    this.a.dragStarted();
                                }
                            }
                        }
                    }
                }
                if (this.a.isHoverActionDesired) {
                    this.a.mouseIsOver(c, d);
                }
            }
        }
        onContactCompleted(e_, a) {
            this.af++;
            window.setTimeout(() => this.af = 0, 250);
            let b = false;
            if (this.o) {
                let indicator_ = this.g.q();
                b = (e_.originalEvent.srcElement === indicator_ || e_.originalEvent.target === indicator_);
            }
            if (this.j && b) {
                this.b.clickExpansionIndicator();
            }
            else {
                if (this.a != null && this.s(this.a)) {
                    let c = e_.pageX;
                    let d = e_.pageY;
                    if (PointUtil.equals(this.a.mousePosition, null) || Math.abs(c - this.a.mousePosition.x) > GridCellBase.as || Math.abs(d - this.a.mousePosition.y) > GridCellBase.as || this.a.isDrag) {
                        this.a.mouseUpCell(c, d);
                    }
                    if (this.a.isCellDown()) {
                        this.a.isControlPressed = e_.ctrlKey;
                        this.a.isShiftPressed = e_.shiftKey;
                        if (this.af > 1) {
                            switch (this.at) {
                                case 1:
                                    this.a.doubleClicked(0);
                                    break;
                                case 2:
                                    this.a.doubleClicked(1);
                                    break;
                                case 3:
                                    this.a.doubleClicked(2);
                                    break;
                                default:
                                    this.a.doubleClicked(3);
                                    break;
                            }
                        }
                        else {
                            switch (e_.which) {
                                case 1:
                                    this.a.clickCell(0);
                                    break;
                                case 2:
                                    this.a.clickCell(1);
                                    break;
                                case 3:
                                    this.a.clickCell(2);
                                    break;
                                default:
                                    this.a.clickCell(3);
                                    break;
                            }
                        }
                        this.a.mouseUpCell(e_.pageX, e_.pageY);
                    }
                }
            }
            this.j = false;
        }
        be(a, b) {
            if (this.a != null && this.a.isLeaveActionDesired) {
                let c = a.pageX;
                let d = a.pageY;
                this.a.mouseLeaveCell(c, d);
            }
        }
        bd(a, b) {
            if (this.a != null && this.a.isEnterActionDesired) {
                let c = a.pageX;
                let d = a.pageY;
                this.a.mouseEnterCell(c, d);
            }
        }
        onDoubleClick(a) {
        }
        bh(a, b, c) {
            switch (a) {
                case "Indent":
                    this.ai = this.ay * 24;
                    this.aj = this.ay > 0 ? 10 : 0;
                    if (this.y != null) {
                        this.y.setRawXPosition(this.ap + this.ai);
                        this.y.setRawYPosition(intDivide(this.al, 2) - intDivide(this.ah, 2));
                    }
                    break;
                case "IsCollapsable":
                    if (this.o) {
                        this.a7();
                    }
                    else {
                        this.bn();
                    }
                    break;
                case "IsExpanded":
                    if (this.g != null) {
                        this.g.g = this.p;
                    }
                    break;
            }
        }
        bg() {
        }
        a6() {
            this.x.focus(true);
        }
    }
    GridCellBase.$t = /*@__PURE__*/ markType(GridCellBase, 'GridCellBase', Base.$, [INativeCell_$type]);
    GridCellBase.az = /*@__PURE__*/ new Random(0);
    GridCellBase.as = 10;
    GridCellBase.ag = 3;
    return GridCellBase;
})();
//# sourceMappingURL=GridCellBase.js.map
