/*
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 { GridCellBase } from "./GridCellBase";
import { DataSourceSchemaPropertyType_$type } from "igniteui-webcomponents-core";
import { enumGetBox, runOn, delegateCombine, delegateRemove, markType } from "igniteui-webcomponents-core";
import { EditorType_$type } from "./EditorType";
import { Popup } from "igniteui-webcomponents-layouts";
import { TextEditorView } from "./TextEditorView";
import { NumericEditorView } from "./NumericEditorView";
import { DateEditorView } from "./DateEditorView";
import { ComboEditorView } from "./ComboEditorView";
import { Rect } from "igniteui-webcomponents-core";
import { stringIsNullOrWhiteSpace } from "igniteui-webcomponents-core";
/**
 * @hidden
 */
var EditorCell = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(EditorCell, _super);
    function EditorCell(a) {
        var _this = _super.call(this, a) || this;
        _this.cg = null;
        _this.cn = null;
        _this.cm = null;
        _this.cf = null;
        _this.ce = null;
        _this.c1 = null;
        _this.c2 = null;
        _this.c3 = null;
        _this.co = null;
        _this.cr = false;
        _this.cu = false;
        _this.cs = false;
        _this.ca = 0;
        _this.c5 = null;
        _this.cp = null;
        _this.cc = 1;
        _this.c4 = null;
        _this.c8 = null;
        _this.b8 = null;
        _this.ct = true;
        _this.cw = false;
        _this.cx = false;
        _this.cv = false;
        _this.z.setAttribute("tabindex", "-1");
        _this.z.setStyleProperty("outline", "none");
        _this.z.setStyleProperty("display", "flex");
        _this.z.setStyleProperty("align-items", "center");
        _this.z.listen("focusout", runOn(_this, _this.dv));
        _this.z.listen("focusin", runOn(_this, _this.dt));
        return _this;
    }
    Object.defineProperty(EditorCell.prototype, "cb", {
        get: function () {
            return this.ca;
        },
        set: function (a) {
            var b = this.ca;
            this.ca = a;
            if (b != this.ca) {
                this.bh("DataType", enumGetBox(DataSourceSchemaPropertyType_$type, b), enumGetBox(DataSourceSchemaPropertyType_$type, this.ca));
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(EditorCell.prototype, "c7", {
        get: function () {
            return this.c5;
        },
        set: function (a) {
            var b = this.c5;
            this.c5 = a;
            if (b != this.c5) {
                this.bh("Value", b, this.c5);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(EditorCell.prototype, "cq", {
        get: function () {
            return this.cp;
        },
        set: function (a) {
            var b = this.cp;
            this.cp = a;
            if (b != this.cp) {
                this.bh("FontInfo", b, this.cp);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(EditorCell.prototype, "cd", {
        get: function () {
            return this.cc;
        },
        set: function (a) {
            var b = this.cc;
            this.cc = a;
            if (b != this.cc) {
                this.bh("EditorType", enumGetBox(EditorType_$type, b), enumGetBox(EditorType_$type, this.cc));
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(EditorCell.prototype, "c6", {
        get: function () {
            return this.c4;
        },
        set: function (a) {
            var b = this.c4;
            this.c4 = a;
            if (b != this.c4) {
                this.bh("ComboItemsSource", b, this.c4);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(EditorCell.prototype, "da", {
        get: function () {
            return this.c8;
        },
        set: function (a) {
            var b = this.c8;
            this.c8 = a;
            if (b != this.c8) {
                this.bh("ComboTextField", b, this.c8);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(EditorCell.prototype, "b9", {
        get: function () {
            return this.b8;
        },
        set: function (a) {
            var b = this.b8;
            this.b8 = a;
            if (b != this.b8) {
                this.bh("ComboValueField", b, this.b8);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(EditorCell.prototype, "c0", {
        get: function () {
            return this.ct;
        },
        set: function (a) {
            var b = this.ct;
            this.ct = a;
            if (b != this.ct) {
                this.bh("IsHidden", b, this.ct);
            }
        },
        enumerable: true,
        configurable: true
    });
    EditorCell.prototype.cl = function (a) {
        if (this.c1 == null) {
            this.c1 = this.w.createElement("div");
            var b = this.w.getSubRenderer(this.c1);
            this.co = new Popup();
            this.co.provideRenderer(b);
            this.c3 = this.w.createElement("div");
            this.c3.setStyleProperty("background-color", "rgba(0,0,0,0.7)");
            this.c3.setStyleProperty("color", "#fff");
            this.c3.setStyleProperty("padding", "5px");
            this.c3.setStyleProperty("outline", "none");
            this.c3.setAttribute("tabindex", "-1");
            this.c2 = this.w.createElement("div");
            this.c2.setStyleProperty("white-space", "pre");
            if (this.cq != null) {
                this.c2.setStyleProperty("font", this.cq.fontString);
            }
            this.c3.append(this.c2);
            this.co.appendPopupContent(this.c3);
        }
        var c = null;
        switch (a) {
            case 1:
                c = this.ck();
                break;
            case 2:
                c = this.cj();
                break;
            case 3:
                c = this.ci();
                break;
            case 4:
                c = this.ch();
                break;
        }
        return c;
    };
    EditorCell.prototype.ck = function () {
        if (this.cn != null) {
            this.dn();
            this.ds();
            return this.cn;
        }
        this.cn = new TextEditorView(this.w, this.d.getTheme(), this.b);
        this.cn.setFont(this.cq);
        return this.cn;
    };
    EditorCell.prototype.cj = function () {
        if (this.cm != null) {
            this.dn();
            this.ds();
            return this.cm;
        }
        this.cm = new NumericEditorView(this.w, this.d.getTheme(), this.b);
        this.cm.setFont(this.cq);
        return this.cm;
    };
    EditorCell.prototype.ci = function () {
        if (this.cf != null) {
            this.dn();
            this.ds();
            return this.cf;
        }
        this.cf = new DateEditorView(this.w, this.d.getTheme(), this.b);
        this.cf.setFont(this.cq);
        return this.cf;
    };
    EditorCell.prototype.ch = function () {
        if (this.ce != null) {
            this.dm();
            this.dn();
            this.ds();
            return this.ce;
        }
        this.ce = new ComboEditorView(this.w, this.d.getTheme(), this.b);
        this.ce.setFont(this.cq);
        this.ce.w = this.c6;
        this.ce.z = this.da;
        this.ce.q = this.b9;
        return this.ce;
    };
    EditorCell.prototype.du = function (a, b) {
        if (b.g != b.d || b.h != b.e) {
            if (this.ce != null) {
                this.ce.ac();
            }
            this.dk();
        }
    };
    EditorCell.prototype.di = function () {
        if (!this.cs) {
            if (this.cg != null) {
                this.cg.attachEvents();
                var a = this.cg;
                a.valueProvided = delegateCombine(a.valueProvided, runOn(this, this.dz));
                var b = this.cg;
                b.lostFocus = delegateCombine(b.lostFocus, runOn(this, this.dq));
                var c = this.cg;
                c.gotFocus = delegateCombine(c.gotFocus, runOn(this, this.dp));
                var d = this.cg;
                d.userTyping = delegateCombine(d.userTyping, runOn(this, this.dx));
                this.cs = true;
            }
        }
    };
    EditorCell.prototype.dj = function () {
        if (this.cs) {
            if (this.cg != null) {
                this.cg.detachEvents();
                var a = this.cg;
                a.valueProvided = delegateRemove(a.valueProvided, runOn(this, this.dz));
                var b = this.cg;
                b.lostFocus = delegateRemove(b.lostFocus, runOn(this, this.dq));
                var c = this.cg;
                c.gotFocus = delegateRemove(c.gotFocus, runOn(this, this.dp));
                var d = this.cg;
                d.userTyping = delegateRemove(d.userTyping, runOn(this, this.dx));
                this.cs = false;
            }
        }
    };
    EditorCell.prototype.dw = function (a) {
        this.cw = false;
        this.cx = false;
        this.cv = false;
        if (!a) {
            this.cx = true;
            this.cg.onTargetChanged();
        }
    };
    EditorCell.prototype.dy = function () {
        if (this.cg != null) {
            this.cg.value = this.c7;
        }
    };
    EditorCell.prototype.dn = function () {
    };
    EditorCell.prototype.dr = function () {
        this.cr = true;
        this.dj();
        this.z.removeChildren();
        if (this.cg != null) {
            this.cg.cleanUp();
        }
        this.cg = this.cl(this.cd);
        this.z.append(this.cg.container);
        this.di();
        if (!this.c0 && this.cg != null) {
            this.cg.onEditStarted();
        }
        this.cr = false;
    };
    EditorCell.prototype.dm = function () {
        if (this.ce != null) {
            this.ce.w = this.c6;
            this.ce.z = this.da;
            this.ce.q = this.b9;
        }
    };
    EditorCell.prototype.ds = function () {
        if (this.cq != null) {
            if (this.cn != null) {
                this.cn.setFont(this.cq);
            }
            if (this.cm != null) {
                this.cm.setFont(this.cq);
            }
            if (this.cf != null) {
                this.cf.setFont(this.cq);
            }
            if (this.ce != null) {
                this.ce.setFont(this.cq);
            }
            this.c2.setStyleProperty("font", this.cq.fontString);
        }
    };
    EditorCell.prototype.dl = function () {
        this.cu = false;
        if (this.cg != null) {
            if (!this.c0) {
                this.cg.onEditStarted();
            }
            else {
                this.cg.onEditEnded();
            }
        }
    };
    EditorCell.prototype.d0 = function (a, b, c, d, e) {
        if (!stringIsNullOrWhiteSpace(a)) {
            this.c2.setRawText(a);
            this.co.ar();
            this.d1();
        }
    };
    EditorCell.prototype.d1 = function () {
        var rect_ = this.z.getNativeElement().getBoundingClientRect();
        var a = new Rect(4);
        a.left = (rect_.left + window.pageXOffset);
        a.top = (rect_.top + window.pageYOffset);
        a.right = (rect_.right + window.pageXOffset);
        a.bottom = (rect_.bottom + window.pageYOffset);
        this.co.showRelativeToExclusionRect(a, 1, 0);
    };
    EditorCell.prototype.dk = function () {
        if (this.co.t) {
            this.co.ao();
        }
    };
    EditorCell.prototype.bg = function () {
        if (this.cg == null) {
            this.dr();
            this.d.setViewportChangedHandler(runOn(this, this.du));
        }
    };
    EditorCell.prototype.a6 = function () {
        if (this.cg != null) {
            this.cg.focus();
        }
    };
    EditorCell.prototype.bh = function (a, b, c) {
        _super.prototype.bh.call(this, a, b, c);
        switch (a) {
            case "EditorType":
                this.dr();
                break;
            case "ComboItemsSource":
            case "ComboTextField":
            case "ComboValueField":
                this.dm();
                break;
            case "DataType":
                this.dn();
                break;
            case "Value":
                this.dy();
                break;
            case "FontInfo":
                this.ds();
                break;
            case "IsHidden":
                this.dl();
                break;
        }
    };
    EditorCell.prototype.dz = function (a, b, c) {
        if (a == this.cg) {
            if (!c) {
                this.b.updateCellEditValue(b);
            }
        }
    };
    EditorCell.prototype.dx = function (a) {
        if (a == this.cg) {
            this.b.startEditMode();
        }
    };
    EditorCell.prototype.cz = function (a) {
        if (a != null && this.co != null && this.co.t) {
            var b = this.c3.getNativeElement();
            return b.contains(a);
        }
        return false;
    };
    EditorCell.prototype.cy = function (a) {
        if (a != null) {
            var b = this.z.getNativeElement();
            return b.contains(a);
        }
        return false;
    };
    EditorCell.prototype.dv = function (a) {
        var _this = this;
        if (!this.cr) {
            var b = (a.originalEvent.relatedTarget);
            if (this.cv && !this.cy(b) && !this.cz(b)) {
                this.b.editorCellLostFocus();
                this.dk();
            }
            var c = this.w.rootWrapper.getNativeElement();
            if (c.contains(b)) {
                window.setTimeout(function () {
                    var d = document.activeElement.nodeName;
                    if (d == "INPUT" || d == "SELECT" || d == "TEXTAREA" || d == "BUTTON" || d == "OPTION") {
                        return;
                    }
                    if (_this.b.isEditRefocusDesired && _this.cg != null) {
                        _this.cg.focus();
                    }
                }, 0);
            }
        }
    };
    EditorCell.prototype.dt = function (a) {
        if (this.cw && !this.co.t) {
            this.d1();
        }
    };
    EditorCell.prototype.dq = function (a) {
        this.cv = true;
    };
    EditorCell.prototype.dp = function (a) {
        this.cv = false;
    };
    EditorCell.prototype.onContactStarted = function (a, b) {
        a.stopPropagation();
    };
    EditorCell.prototype.onContactCompleted = function (a, b) {
        a.stopPropagation();
    };
    EditorCell.prototype.onDoubleClick = function (a) {
        a.stopPropagation();
    };
    EditorCell.$t = markType(EditorCell, 'EditorCell', GridCellBase.$);
    return EditorCell;
}(GridCellBase));
export { EditorCell };
//# sourceMappingURL=EditorCell.js.map
