/*
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 { 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
 */
var GridCellBase = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(GridCellBase, _super);
    function GridCellBase(a) {
        var _this = _super.call(this) || this;
        _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");
        var b = (window.navigator.msPointerEnabled && MSGesture !== undefined);
        var c = (window.PointerEvent || window.navigator.pointerEnabled);
        var 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));
        }
        return _this;
    }
    Object.defineProperty(GridCellBase.prototype, "b", {
        get: function () {
            return this.a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GridCellBase.prototype, "d", {
        get: function () {
            return this.c;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GridCellBase.prototype, "w", {
        get: function () {
            return this.v;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GridCellBase.prototype, "z", {
        get: function () {
            return this.x;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GridCellBase.prototype, "ax", {
        get: function () {
            return this.ak;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GridCellBase.prototype, "av", {
        get: function () {
            return this.ai;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GridCellBase.prototype, "aw", {
        get: function () {
            return this.aj;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GridCellBase.prototype, "ay", {
        get: function () {
            return this.an;
        },
        set: function (a) {
            var b = this.an;
            this.an = a;
            if (b != this.an) {
                this.bh("Indent", b, this.an);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GridCellBase.prototype, "o", {
        get: function () {
            return this.k;
        },
        set: function (a) {
            var b = this.k;
            this.k = a;
            if (b != this.k) {
                this.bh("IsCollapsable", b, this.k);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GridCellBase.prototype, "p", {
        get: function () {
            return this.l;
        },
        set: function (a) {
            var b = this.l;
            this.l = a;
            if (b != this.l) {
                this.bh("IsExpanded", b, this.l);
            }
        },
        enumerable: true,
        configurable: true
    });
    GridCellBase.prototype.a7 = function () {
        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) {
            var 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);
        }
    };
    GridCellBase.prototype.bn = function () {
        this.ak = 0;
        this.aj = 0;
        if (this.y != null) {
            if (this.y.parent() != null) {
                this.y.remove();
            }
        }
    };
    Object.defineProperty(GridCellBase.prototype, "n", {
        get: function () {
            return this.i;
        },
        set: function (a) {
            this.i = a;
        },
        enumerable: true,
        configurable: true
    });
    GridCellBase.prototype.get_r = function () {
        return false;
    };
    Object.defineProperty(GridCellBase.prototype, "r", {
        get: function () {
            return this.get_r();
        },
        enumerable: true,
        configurable: true
    });
    GridCellBase.prototype.bv = function (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");
    };
    GridCellBase.prototype.bq = function (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");
        }
    };
    GridCellBase.prototype.get_q = function () {
        return false;
    };
    Object.defineProperty(GridCellBase.prototype, "q", {
        get: function () {
            return this.get_q();
        },
        enumerable: true,
        configurable: true
    });
    GridCellBase.prototype.br = function (a, b) {
        if (this.al != a || this.am != b) {
            var c = this.al;
            this.al = a;
            this.am = b;
            var 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);
        }
    };
    GridCellBase.prototype.bx = function (a, b) {
        if (this.au != a) {
            var c = this.au;
            this.au = a;
            this.x.setRawStyleProperty("width", a.toString() + "px");
            this.by(this.au, this.al, c, this.al);
        }
    };
    GridCellBase.prototype.by = function (a, b, c, d) {
    };
    GridCellBase.prototype.a5 = function () {
        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);
    };
    GridCellBase.prototype.bp = function (a) {
        this.x.setRawStyleProperty("background-color", a.colorString);
    };
    GridCellBase.prototype.bu = function (a) {
        this.x.setRawStyleProperty("opacity", a.toString());
    };
    GridCellBase.prototype.b6 = function (a) {
        if (!this.r) {
            return;
        }
        this.h.i = (a * 0.20000000298023224);
    };
    GridCellBase.prototype.b4 = function (a, b, c, d) {
        if (this.h != null) {
            var e = this.u;
            var 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);
        }
    };
    GridCellBase.prototype.bf = function (a, b, c) {
    };
    GridCellBase.prototype.b5 = function (a) {
        if (!this.r) {
            return;
        }
        var 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);
        }
        var c = a.gg * 0.2;
        var d = a.e0 * 0.6;
        if (this.u >= c && this.u <= d && !this.m) {
            return;
        }
        this.m = false;
        var 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));
    };
    GridCellBase.prototype.b2 = function (a, b) {
        if (!this.r) {
            return;
        }
        this.e = a;
        this.f = b;
        this.m = true;
    };
    GridCellBase.prototype.b3 = function (a) {
        if (!this.r) {
            return;
        }
        if (a != null) {
            this.h.l = a.color;
        }
    };
    GridCellBase.prototype.bo = function (a) {
        this.a = a;
    };
    GridCellBase.prototype.bt = function (a) {
        this.c = a;
    };
    GridCellBase.prototype.bs = function (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;
        }
    };
    GridCellBase.prototype.bw = function (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;
        }
    };
    GridCellBase.prototype.s = function (a) {
        return a.isClickActionDesired;
    };
    GridCellBase.prototype.a8 = function (a) {
        this.onContactStarted(a, false);
    };
    GridCellBase.prototype.bc = function (a) {
        this.onContactCompleted(a, false);
    };
    GridCellBase.prototype.bb = function (a) {
        this.onContactMoved(a, false);
    };
    GridCellBase.prototype.ba = function (a) {
        this.be(a, false);
    };
    GridCellBase.prototype.a9 = function (a) {
        this.bd(a, false);
    };
    GridCellBase.prototype.bi = function (e_) {
        var a = (e_.originalEvent.pointerType);
        if (a == "touch") {
            this.bz(e_);
        }
        else {
            this.a8(e_);
        }
    };
    GridCellBase.prototype.bl = function (e_) {
        var a = (e_.originalEvent.pointerType);
        if (a == "touch") {
            this.b0(e_);
        }
        else {
            this.bb(e_);
        }
    };
    GridCellBase.prototype.bm = function (e_) {
        var a = (e_.originalEvent.pointerType);
        if (a == "touch") {
            this.b1(e_);
        }
        else {
            this.bc(e_);
        }
    };
    GridCellBase.prototype.bk = function (e_) {
        var a = (e_.originalEvent.pointerType);
        if (a != "touch") {
            this.ba(e_);
        }
    };
    GridCellBase.prototype.bj = function (e_) {
        var a = (e_.originalEvent.pointerType);
        if (a != "touch") {
            this.a9(e_);
        }
    };
    GridCellBase.prototype.bz = function (a) {
        this.onContactStarted(a, true);
    };
    GridCellBase.prototype.b0 = function (a) {
        this.onContactMoved(a, true);
    };
    GridCellBase.prototype.b1 = function (a) {
        this.onContactCompleted(a, true);
    };
    GridCellBase.prototype.onContactStarted = function (e_, a) {
        var b = false;
        if (this.o) {
            var 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);
            }
        }
    };
    GridCellBase.prototype.onContactMoved = function (a, b) {
        if (this.a != null) {
            var c = a.pageX;
            var 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);
            }
        }
    };
    GridCellBase.prototype.onContactCompleted = function (e_, a) {
        var _this = this;
        this.af++;
        window.setTimeout(function () { return _this.af = 0; }, 250);
        var b = false;
        if (this.o) {
            var 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)) {
                var c = e_.pageX;
                var 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;
    };
    GridCellBase.prototype.be = function (a, b) {
        if (this.a != null && this.a.isLeaveActionDesired) {
            var c = a.pageX;
            var d = a.pageY;
            this.a.mouseLeaveCell(c, d);
        }
    };
    GridCellBase.prototype.bd = function (a, b) {
        if (this.a != null && this.a.isEnterActionDesired) {
            var c = a.pageX;
            var d = a.pageY;
            this.a.mouseEnterCell(c, d);
        }
    };
    GridCellBase.prototype.onDoubleClick = function (a) {
    };
    GridCellBase.prototype.bh = function (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;
        }
    };
    GridCellBase.prototype.bg = function () {
    };
    GridCellBase.prototype.a6 = function () {
        this.x.focus(true);
    };
    GridCellBase.$t = markType(GridCellBase, 'GridCellBase', Base.$, [INativeCell_$type]);
    GridCellBase.az = new Random(0);
    GridCellBase.as = 10;
    GridCellBase.ag = 3;
    return GridCellBase;
}(Base));
export { GridCellBase };
//# sourceMappingURL=GridCellBase.js.map
