/*
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 { BaseEditorView } from "./BaseEditorView";
import { runOn, delegateCombine, delegateRemove, typeCast, markType } from "igniteui-webcomponents-core";
import { IDataSource_$type } from "igniteui-webcomponents-core";
import { stringIsNullOrWhiteSpace } from "igniteui-webcomponents-core";
/**
 * @hidden
 */
var ComboEditorView = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(ComboEditorView, _super);
    function ComboEditorView(a, b, c) {
        var _this = _super.call(this, a, c) || this;
        _this.s = null;
        _this.r = null;
        _this.u = null;
        _this.v = null;
        _this.x = null;
        _this.p = null;
        _this.t = false;
        _this.container = a.createElement("div");
        _this.container.setRawStyleProperty("margin-top", "-10px");
        _this.container.setRawStyleProperty("height", "38px");
        _this.container.setRawStyleProperty("width", "100%");
        a.getPortal(_this.container, "MultiColumnComboBox", function (d) {
            _this.r = d.componentRef;
            _this.u = _this.r.i;
            _this.r.height = "100%";
            _this.r.density = 3;
            _this.r.baseTheme = b;
            _this.r.labelVisible = false;
            _this.r.columnHeadersVisible = false;
            _this.r.rowSeparatorsVisible = false;
            _this.af();
            _this.o();
            if (_this.s != null) {
                _this.r.textStyle = _this.s.fontString;
            }
            _this.attachEvents();
        }, false);
        return _this;
    }
    Object.defineProperty(ComboEditorView.prototype, "w", {
        get: function () {
            return this.v;
        },
        set: function (a) {
            var b = this.v;
            this.v = a;
            if (b != this.v) {
                this.n("DataSource", b, this.v);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ComboEditorView.prototype, "z", {
        get: function () {
            return this.x;
        },
        set: function (a) {
            var b = this.x;
            this.x = a;
            if (b != this.x) {
                this.n("TextField", b, this.x);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ComboEditorView.prototype, "q", {
        get: function () {
            return this.p;
        },
        set: function (a) {
            var b = this.p;
            this.p = a;
            if (b != this.p) {
                this.n("ValueField", b, this.p);
            }
        },
        enumerable: true,
        configurable: true
    });
    ComboEditorView.prototype.setFont = function (a) {
        this.s = a;
        if (this.r != null && this.s != null) {
            this.r.textStyle = this.s.fontString;
        }
    };
    ComboEditorView.prototype.attachEvents = function () {
        if (this.r != null) {
            var a = this.r;
            a.valueChanged = delegateCombine(a.valueChanged, runOn(this, this.onComboValueChanged));
            var b = this.r;
            b.textChanged = delegateCombine(b.textChanged, runOn(this, this.onComboTextChanged));
            var c = this.r;
            c.gotFocus = delegateCombine(c.gotFocus, runOn(this, this.onComboGotFocus));
            var d = this.r;
            d.lostFocus = delegateCombine(d.lostFocus, runOn(this, this.onComboLostFocus));
            var e = this.r;
            e.keyDown = delegateCombine(e.keyDown, runOn(this, this.onInputKeyDown));
            var f = this.r;
            f.changing = delegateCombine(f.changing, runOn(this, this.onInputChanging));
        }
    };
    ComboEditorView.prototype.detachEvents = function () {
        if (this.r != null) {
            var a = this.r;
            a.valueChanged = delegateRemove(a.valueChanged, runOn(this, this.onComboValueChanged));
            var b = this.r;
            b.textChanged = delegateRemove(b.textChanged, runOn(this, this.onComboTextChanged));
            var c = this.r;
            c.gotFocus = delegateRemove(c.gotFocus, runOn(this, this.onComboGotFocus));
            var d = this.r;
            d.lostFocus = delegateRemove(d.lostFocus, runOn(this, this.onComboLostFocus));
            var e = this.r;
            e.keyDown = delegateRemove(e.keyDown, runOn(this, this.onInputKeyDown));
            var f = this.r;
            f.changing = delegateRemove(f.changing, runOn(this, this.onInputChanging));
        }
    };
    ComboEditorView.prototype.onTargetChanged = function () {
        if (this.r != null) {
            this.t = true;
            if (this.r.value == null && this.r.text != "") {
                this.r.text = "";
            }
            this.focus();
            this.t = false;
        }
    };
    ComboEditorView.prototype.onEditStarted = function () {
        _super.prototype.onEditStarted.call(this);
        var a = this.container.getNativeElement();
        this.r.defaultColumnWidth = (a.clientWidth - 2).toString();
        if (!this.a.isEditRefocusDesired) {
            this.focus();
        }
    };
    ComboEditorView.prototype.onEditEnded = function () {
        _super.prototype.onEditEnded.call(this);
        if (this.a.isEditRefocusDesired) {
            var a = this.e.rootWrapper.getNativeElement();
            if (a == document.activeElement || a.contains(document.activeElement)) {
                this.focus();
            }
        }
    };
    ComboEditorView.prototype.l = function () {
        if (this.r != null) {
            this.u.focus(true);
            this.r.select();
        }
    };
    ComboEditorView.prototype.ac = function () {
        if (this.r != null) {
            this.r.closeUp();
        }
    };
    ComboEditorView.prototype.n = function (a, b, c) {
        _super.prototype.n.call(this, a, b, c);
        switch (a) {
            case "DataSource":
            case "TextField":
            case "ValueField":
                this.af();
                break;
        }
    };
    ComboEditorView.prototype.o = function () {
        this.t = true;
        if (this.r != null) {
            if (this.value == null) {
                this.r.text = " ";
            }
            this.r.value = this.value;
            this.l();
        }
        this.t = false;
    };
    ComboEditorView.prototype.af = function () {
        if (this.r != null) {
            this.detachEvents();
            this.r.dataSource = this.w;
            this.r.textField = this.z;
            this.r.valueField = this.q;
            if (this.z != null) {
                this.r.fields = [this.z];
            }
            else if (this.q != null && this.q.length > 0) {
                this.r.fields = [this.q[0]];
            }
            else {
                var a = typeCast(IDataSource_$type, this.w);
                if (a != null && a.actualSchema != null) {
                    this.r.fields = [a.actualSchema.propertyNames[0]];
                }
                else {
                    var b = (Array.isArray(this.w));
                    if (b) {
                        var c = (Object.keys(this.w[0]));
                        if (c.length > 0) {
                            this.r.fields = [c[0]];
                        }
                    }
                }
            }
            this.attachEvents();
        }
    };
    ComboEditorView.prototype.onComboValueChanged = function (a, b) {
        this.aj();
    };
    ComboEditorView.prototype.onComboTextChanged = function (a, b) {
        this.aj();
    };
    ComboEditorView.prototype.aj = function () {
        if (this.t) {
            return;
        }
        if (this.r.value != null) {
            this.k(this.r.value, false);
        }
        else if (this.r.value == null && stringIsNullOrWhiteSpace(this.r.text)) {
            this.k(null, false);
        }
        else {
            this.k(this.value, false);
        }
    };
    ComboEditorView.prototype.onInputChanging = function (a, b) {
        this.j();
    };
    ComboEditorView.prototype.onComboLostFocus = function (a) {
        this.i();
    };
    ComboEditorView.prototype.onComboGotFocus = function (a) {
        this.h();
    };
    ComboEditorView.$t = markType(ComboEditorView, 'ComboEditorView', BaseEditorView.$);
    return ComboEditorView;
}(BaseEditorView));
export { ComboEditorView };
//# sourceMappingURL=ComboEditorView.js.map
