/*
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 { 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
 */
export let EditorCell = /*@__PURE__*/ (() => {
    class EditorCell extends GridCellBase {
        constructor(a) {
            super(a);
            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));
        }
        get cb() {
            return this.ca;
        }
        set cb(a) {
            let b = this.ca;
            this.ca = a;
            if (b != this.ca) {
                this.bh("DataType", enumGetBox(DataSourceSchemaPropertyType_$type, b), enumGetBox(DataSourceSchemaPropertyType_$type, this.ca));
            }
        }
        get c7() {
            return this.c5;
        }
        set c7(a) {
            let b = this.c5;
            this.c5 = a;
            if (b != this.c5) {
                this.bh("Value", b, this.c5);
            }
        }
        get cq() {
            return this.cp;
        }
        set cq(a) {
            let b = this.cp;
            this.cp = a;
            if (b != this.cp) {
                this.bh("FontInfo", b, this.cp);
            }
        }
        get cd() {
            return this.cc;
        }
        set cd(a) {
            let b = this.cc;
            this.cc = a;
            if (b != this.cc) {
                this.bh("EditorType", enumGetBox(EditorType_$type, b), enumGetBox(EditorType_$type, this.cc));
            }
        }
        get c6() {
            return this.c4;
        }
        set c6(a) {
            let b = this.c4;
            this.c4 = a;
            if (b != this.c4) {
                this.bh("ComboItemsSource", b, this.c4);
            }
        }
        get da() {
            return this.c8;
        }
        set da(a) {
            let b = this.c8;
            this.c8 = a;
            if (b != this.c8) {
                this.bh("ComboTextField", b, this.c8);
            }
        }
        get b9() {
            return this.b8;
        }
        set b9(a) {
            let b = this.b8;
            this.b8 = a;
            if (b != this.b8) {
                this.bh("ComboValueField", b, this.b8);
            }
        }
        get c0() {
            return this.ct;
        }
        set c0(a) {
            let b = this.ct;
            this.ct = a;
            if (b != this.ct) {
                this.bh("IsHidden", b, this.ct);
            }
        }
        cl(a) {
            if (this.c1 == null) {
                this.c1 = this.w.createElement("div");
                let 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);
            }
            let 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;
        }
        ck() {
            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;
        }
        cj() {
            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;
        }
        ci() {
            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;
        }
        ch() {
            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;
        }
        du(a, b) {
            if (b.g != b.d || b.h != b.e) {
                if (this.ce != null) {
                    this.ce.ac();
                }
                this.dk();
            }
        }
        di() {
            if (!this.cs) {
                if (this.cg != null) {
                    this.cg.attachEvents();
                    let a = this.cg;
                    a.valueProvided = delegateCombine(a.valueProvided, runOn(this, this.dz));
                    let b = this.cg;
                    b.lostFocus = delegateCombine(b.lostFocus, runOn(this, this.dq));
                    let c = this.cg;
                    c.gotFocus = delegateCombine(c.gotFocus, runOn(this, this.dp));
                    let d = this.cg;
                    d.userTyping = delegateCombine(d.userTyping, runOn(this, this.dx));
                    this.cs = true;
                }
            }
        }
        dj() {
            if (this.cs) {
                if (this.cg != null) {
                    this.cg.detachEvents();
                    let a = this.cg;
                    a.valueProvided = delegateRemove(a.valueProvided, runOn(this, this.dz));
                    let b = this.cg;
                    b.lostFocus = delegateRemove(b.lostFocus, runOn(this, this.dq));
                    let c = this.cg;
                    c.gotFocus = delegateRemove(c.gotFocus, runOn(this, this.dp));
                    let d = this.cg;
                    d.userTyping = delegateRemove(d.userTyping, runOn(this, this.dx));
                    this.cs = false;
                }
            }
        }
        dw(a) {
            this.cw = false;
            this.cx = false;
            this.cv = false;
            if (!a) {
                this.cx = true;
                this.cg.onTargetChanged();
            }
        }
        dy() {
            if (this.cg != null) {
                this.cg.value = this.c7;
            }
        }
        dn() {
        }
        dr() {
            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;
        }
        dm() {
            if (this.ce != null) {
                this.ce.w = this.c6;
                this.ce.z = this.da;
                this.ce.q = this.b9;
            }
        }
        ds() {
            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);
            }
        }
        dl() {
            this.cu = false;
            if (this.cg != null) {
                if (!this.c0) {
                    this.cg.onEditStarted();
                }
                else {
                    this.cg.onEditEnded();
                }
            }
        }
        d0(a, b, c, d, e) {
            if (!stringIsNullOrWhiteSpace(a)) {
                this.c2.setRawText(a);
                this.co.ar();
                this.d1();
            }
        }
        d1() {
            let rect_ = this.z.getNativeElement().getBoundingClientRect();
            let 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);
        }
        dk() {
            if (this.co.t) {
                this.co.ao();
            }
        }
        bg() {
            if (this.cg == null) {
                this.dr();
                this.d.setViewportChangedHandler(runOn(this, this.du));
            }
        }
        a6() {
            if (this.cg != null) {
                this.cg.focus();
            }
        }
        bh(a, b, c) {
            super.bh(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;
            }
        }
        dz(a, b, c) {
            if (a == this.cg) {
                if (!c) {
                    this.b.updateCellEditValue(b);
                }
            }
        }
        dx(a) {
            if (a == this.cg) {
                this.b.startEditMode();
            }
        }
        cz(a) {
            if (a != null && this.co != null && this.co.t) {
                let b = this.c3.getNativeElement();
                return b.contains(a);
            }
            return false;
        }
        cy(a) {
            if (a != null) {
                let b = this.z.getNativeElement();
                return b.contains(a);
            }
            return false;
        }
        dv(a) {
            if (!this.cr) {
                let b = (a.originalEvent.relatedTarget);
                if (this.cv && !this.cy(b) && !this.cz(b)) {
                    this.b.editorCellLostFocus();
                    this.dk();
                }
                let c = this.w.rootWrapper.getNativeElement();
                if (c.contains(b)) {
                    window.setTimeout(() => {
                        let 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);
                }
            }
        }
        dt(a) {
            if (this.cw && !this.co.t) {
                this.d1();
            }
        }
        dq(a) {
            this.cv = true;
        }
        dp(a) {
            this.cv = false;
        }
        onContactStarted(a, b) {
            a.stopPropagation();
        }
        onContactCompleted(a, b) {
            a.stopPropagation();
        }
        onDoubleClick(a) {
            a.stopPropagation();
        }
    }
    EditorCell.$t = /*@__PURE__*/ markType(EditorCell, 'EditorCell', GridCellBase.$);
    return EditorCell;
})();
//# sourceMappingURL=EditorCell.js.map
