/*
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, markType, INotifyPropertyChanged_$type, PropertyChangedEventArgs, runOn, delegateCombine, typeCast, delegateRemove, fromEn, enumGetBox, fromEnum, Number_$type } from "igniteui-webcomponents-core";
import { RenderingContext } from "igniteui-webcomponents-core";
import { FontInfo } from "igniteui-webcomponents-core";
import { CanvasViewRenderer } from "igniteui-webcomponents-core";
import { Size } from "igniteui-webcomponents-core";
import { NativeUI } from "igniteui-webcomponents-core";
import { FontUtil } from "igniteui-webcomponents-core";
import { List$1 } from "igniteui-webcomponents-core";
import { SRProvider } from "igniteui-webcomponents-core";
import { PropertyEditorPropertyDescriptionCollection } from "./PropertyEditorPropertyDescriptionCollection";
import { InputGroupDisplayType_$type } from "igniteui-webcomponents-inputs";
import { BaseControlTheme_$type } from "igniteui-webcomponents-core";
import { ControlDisplayDensity_$type } from "igniteui-webcomponents-core";
import { Dictionary$2 } from "igniteui-webcomponents-core";
import { Column } from "./Column";
import { FilterFactory } from "igniteui-webcomponents-core";
import { PropertyEditorPropertyDescription } from "./PropertyEditorPropertyDescription";
import { HorizontalPropertyEditorDataSource } from "./HorizontalPropertyEditorDataSource";
import { PropertyEditorDataSource } from "./PropertyEditorDataSource";
import { TextColumn } from "./TextColumn";
import { TemplateColumn } from "./TemplateColumn";
import { Thickness } from "igniteui-webcomponents-core";
import { ColumnWidth } from "./ColumnWidth";
import { PropertyEditorValueType_$type } from "./PropertyEditorValueType";
import { DropDownDataListItem } from "./DropDownDataListItem";
import { PropertyEditorTreeTransformer } from "./PropertyEditorTreeTransformer";
import { BrushUtil } from "igniteui-webcomponents-core";
import { truncate } from "igniteui-webcomponents-core";
/**
 * @hidden
 */
var PropertyEditorView = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(PropertyEditorView, _super);
    function PropertyEditorView() {
        var _this = _super.call(this) || this;
        _this.o = null;
        _this.n = null;
        _this.b = null;
        _this.j = null;
        _this.m = null;
        _this.f = null;
        _this.l = null;
        _this.c = ((function () {
            var $ret = new FontInfo();
            $ret.n = "Verdana";
            $ret.d = 13;
            $ret.q = "Normal";
            $ret.s = "Normal";
            $ret.o = "Normal";
            return $ret;
        })());
        _this.ad = new Size();
        _this.d = null;
        _this._gridExternal = null;
        _this.a = null;
        _this.g = false;
        _this.k = null;
        return _this;
    }
    PropertyEditorView.prototype.y = function () {
    };
    PropertyEditorView.prototype.w = function (a) {
        var _this = this;
        if (a == null) {
            this.j = null;
            return;
        }
        this.j = a;
        this.m = this.j.createElement("canvas");
        this.f = new RenderingContext(new CanvasViewRenderer(), this.j.get2DCanvasContext(this.m));
        this.l = this.j.createElement("div");
        this.ab();
        this.j.getPortal(this.j.rootWrapper, "DataGrid", function (b) {
            _this._gridExternal = b.componentRef;
            _this.a = (_this._gridExternal.i);
            _this._gridExternal.height = '100%';
            _this.b.c9(_this.a, null);
            _this.aa();
        }, false);
        var b = Math.round(a.rootWrapper.width());
        var c = Math.round(a.rootWrapper.height());
        this.j.rootWrapper.setStyleProperty("position", "relative");
    };
    PropertyEditorView.prototype.ab = function () {
    };
    PropertyEditorView.prototype.aa = function () {
        if (this.j != null) {
        }
    };
    PropertyEditorView.prototype.v = function () {
        var a = this.j.rootWrapper.width();
        var b = this.j.rootWrapper.height();
        this.ad = new Size(1, a, b);
        if (this.b.l != null) {
            this.b.du();
        }
    };
    PropertyEditorView.prototype.ac = function () {
        var a = this.j;
        if (null == a) {
            return;
        }
        var b = a.rootWrapper;
        if (null != b) {
            NativeUI.n(b, this.b.d1);
            NativeUI.j(b, this.b.dx);
        }
    };
    PropertyEditorView.prototype.e = function () {
        return this.c;
    };
    PropertyEditorView.prototype.x = function () {
    };
    PropertyEditorView.prototype.z = function () {
    };
    PropertyEditorView.prototype.u = function () {
        var a = this.b.d2();
        if (a.height > 0) {
            this.j.rootWrapper.setStyleProperty("min-height", a.height + "px");
        }
    };
    PropertyEditorView.prototype.h = function () {
        return this.ad.width;
    };
    PropertyEditorView.prototype.i = function (a) {
        this.d = this.b.ae();
        return FontUtil.measureStringWidth(a, this.d, this.f);
    };
    PropertyEditorView.prototype.s = function (a, b) {
        var _this = this;
        var cnt_ = a.content;
        var c = cnt_.element.getChildCount() > 0 ? cnt_.element.getChildAt(0) : null;
        var d = false;
        if (c == null) {
            this.j.getPortal(cnt_.element, "InputGroup", function (e) {
                var contenti_ = cnt_.element.getChildCount() > 0 ? cnt_.element.getChildAt(0) : null;
                d = true;
                var inputExternal_ = e.componentRef;
                var inputInternal_ = (inputExternal_.i);
                var f = inputInternal_.view.s;
                cnt_.__int = inputInternal_;
                inputExternal_.width = '100%';
                inputExternal_.height = '100%';
                inputExternal_.style.lineHeight = '0';
                _this.j.getPortal(f, "Input", function (g) {
                    var iExternal_ = g.componentRef;
                    var iInternal_ = (iExternal_.i);
                    inputInternal_.inputs.add(iInternal_);
                    b(inputInternal_, d);
                }, false);
            }, false);
        }
        else {
            var content_ = c;
            var impl_ = cnt_.__int;
            b(impl_, d);
        }
    };
    PropertyEditorView.prototype.r = function (a, b) {
        var cnt_ = a.content;
        var c = cnt_.element.getChildCount() > 0 ? cnt_.element.getChildAt(0) : null;
        var d = false;
        if (c == null) {
            this.j.getPortal(cnt_.element, "MultiColumnComboBox", function (e) {
                var contenti_ = cnt_.element.getChildCount() > 0 ? cnt_.element.getChildAt(0) : null;
                d = true;
                var inputExternal_ = e.componentRef;
                var inputInternal_ = (inputExternal_.i);
                cnt_.__int = inputInternal_;
                inputExternal_.width = '100%';
                inputExternal_.height = '100%';
                inputExternal_.style.lineHeight = '0';
                b(inputInternal_, d);
            }, false);
        }
        else {
            var content_ = c;
            var impl_ = cnt_.__int;
            b(impl_, d);
        }
    };
    PropertyEditorView.prototype.q = function (a, b) {
        var cnt_ = a.content;
        var c = cnt_.element.getChildCount() > 0 ? cnt_.element.getChildAt(0) : null;
        var d = false;
        if (c == null) {
            this.j.getPortal(cnt_.element, "Checkbox", function (e) {
                var contenti_ = cnt_.element.getChildCount() > 0 ? cnt_.element.getChildAt(0) : null;
                d = true;
                var inputExternal_ = e.componentRef;
                var inputInternal_ = (inputExternal_.i);
                cnt_.__int = inputInternal_;
                inputExternal_.width = '100%';
                inputExternal_.height = '100%';
                inputExternal_.style.lineHeight = '0';
                b(inputInternal_, d);
            }, false);
        }
        else {
            var content_ = c;
            var impl_ = cnt_.__int;
            b(impl_, d);
        }
    };
    PropertyEditorView.prototype.t = function (a, b) {
        if (this.k == null) {
            this.k = this.j.createElement("div");
        }
        b(this.k.getNativeElement());
    };
    PropertyEditorView.$t = markType(PropertyEditorView, 'PropertyEditorView');
    return PropertyEditorView;
}(Base));
export { PropertyEditorView };
/**
 * @hidden
 */
var PropertyEditor = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(PropertyEditor, _super);
    function PropertyEditor() {
        var _this = _super.call(this) || this;
        _this.s = null;
        _this.l = null;
        _this.ab = null;
        _this.d = null;
        _this.ah = false;
        _this.c = null;
        _this.x = null;
        _this.y = null;
        _this.ai = false;
        _this.af = null;
        _this.propertyChanged = null;
        _this.al = false;
        _this.o = null;
        _this.p = new PropertyEditorPropertyDescriptionCollection();
        _this.bq = null;
        _this.z = 3;
        _this.bg = -1;
        _this.ac = null;
        _this.t = 1;
        _this.v = 2;
        _this.bo = null;
        _this.ap = new Dictionary$2(Column.$, Number_$type, 0);
        _this.h = null;
        _this.i = null;
        _this.f = null;
        _this.bm = null;
        _this.bp = null;
        _this.aj = false;
        _this.ak = false;
        _this.dv = PropertyEditor.dy;
        _this.dw = PropertyEditor.dz;
        _this.bk = 0;
        _this.bh = -1;
        _this.m = null;
        _this.d = new FilterFactory();
        var a = new PropertyEditorView();
        a.b = _this;
        var b = _this.properties;
        b.collectionChanged = delegateCombine(b.collectionChanged, runOn(_this, _this.dn));
        _this.s = a;
        _this.s.y();
        return _this;
    }
    Object.defineProperty(PropertyEditor.prototype, "e", {
        get: function () {
            if (this.l == null) {
                return null;
            }
            return this.l.actualDataSource;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(PropertyEditor.prototype, "ag", {
        get: function () {
            if (this.af == null) {
                this.af = new SRProvider(this.s.j);
                this.af.cb("DataGrid");
            }
            return this.af;
        },
        enumerable: true,
        configurable: true
    });
    PropertyEditor.prototype.dn = function (a, b) {
        var e_1, _a, e_2, _b;
        if (b.oldItems != null) {
            try {
                for (var _c = tslib_1.__values(fromEn(b.oldItems)), _d = _c.next(); !_d.done; _d = _c.next()) {
                    var c = _d.value;
                    if (typeCast(INotifyPropertyChanged_$type, c) !== null) {
                        var d = c;
                        d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.dc));
                    }
                }
            }
            catch (e_1_1) {
                e_1 = { error: e_1_1 };
            }
            finally {
                try {
                    if (_d && !_d.done && (_a = _c.return))
                        _a.call(_c);
                }
                finally {
                    if (e_1)
                        throw e_1.error;
                }
            }
        }
        if (b.newItems != null) {
            try {
                for (var _e = tslib_1.__values(fromEn(b.newItems)), _f = _e.next(); !_f.done; _f = _e.next()) {
                    var e = _f.value;
                    if (typeCast(INotifyPropertyChanged_$type, e) !== null) {
                        var f = e;
                        f.propertyChanged = delegateCombine(f.propertyChanged, runOn(this, this.dc));
                    }
                }
            }
            catch (e_2_1) {
                e_2 = { error: e_2_1 };
            }
            finally {
                try {
                    if (_f && !_f.done && (_b = _e.return))
                        _b.call(_e);
                }
                finally {
                    if (e_2)
                        throw e_2.error;
                }
            }
        }
        this.ao();
        if (this.properties.count > 0 && this.actualProperties != this.properties) {
            this.actualProperties = this.properties;
        }
        if (this.l != null) {
            this.l.rg();
        }
    };
    PropertyEditor.prototype.dc = function (a, b) {
        if (!this.al) {
            this.ao();
            if (this.l != null) {
                this.du();
            }
        }
    };
    PropertyEditor.prototype.notifySizeChanged = function () {
        this.s.v();
    };
    PropertyEditor.prototype.c9 = function (a, b) {
        this.l = a;
        if (null != this.l) {
            this.l.lt = 0;
            this.l.l3 = 0;
            this.l.hc = false;
            this.l.cm = 0;
            this.l.cg = 0;
            var c = this.l;
            c.cellClicked = delegateCombine(c.cellClicked, runOn(this, this.c8));
            if (this.actualProperties != null) {
                this.l.itemsSource = this.actualProperties;
                this.ce();
            }
            if (this.actualProperties != null) {
                this.du();
            }
        }
    };
    PropertyEditor.prototype.destroy = function () {
        if (this.l != null) {
            var a = this.l;
            a.cellClicked = delegateRemove(a.cellClicked, runOn(this, this.c8));
        }
        if (this.x != null) {
            var b = this.x;
            b.change = delegateRemove(b.change, runOn(this, this.db));
        }
        this.provideContainer(null);
    };
    PropertyEditor.prototype.provideContainer = function (a) {
        this.s.w(a);
    };
    PropertyEditor.prototype.c8 = function (a, b) {
    };
    PropertyEditor.prototype.dj = function (a) {
    };
    Object.defineProperty(PropertyEditor.prototype, "actualProperties", {
        get: function () {
            return this.o;
        },
        set: function (a) {
            var b = this.o;
            this.o = a;
            if (b != this.o) {
                this.dk("ActualProperties", b, this.o);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(PropertyEditor.prototype, "properties", {
        get: function () {
            return this.p;
        },
        set: function (a) {
            var b = this.p;
            this.p = a;
            if (b != this.p) {
                this.dk("Properties", b, this.p);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(PropertyEditor.prototype, "b2", {
        get: function () {
            return this.bq;
        },
        set: function (a) {
            var b = this.bq;
            this.bq = a;
            if (b != this.bq) {
                this.dk("FilterPlaceholderText", b, this.bq);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(PropertyEditor.prototype, "aa", {
        get: function () {
            return this.z;
        },
        set: function (a) {
            var b = this.z;
            this.z = a;
            if (b != this.z) {
                this.dk("SearchInputType", enumGetBox(InputGroupDisplayType_$type, b), enumGetBox(InputGroupDisplayType_$type, this.z));
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(PropertyEditor.prototype, "bl", {
        get: function () {
            return this.bg;
        },
        set: function (a) {
            var b = this.bg;
            this.bg = a;
            if (b != this.bg) {
                this.dk("RowHeight", b, this.bg);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(PropertyEditor.prototype, "ad", {
        get: function () {
            return this.ac;
        },
        set: function (a) {
            var b = this.ac;
            this.ac = a;
            if (b != this.ac) {
                this.dk("CellTextStyle", b, this.ac);
            }
        },
        enumerable: true,
        configurable: true
    });
    PropertyEditor.prototype.ae = function () {
        if (this.ad == null) {
            return this.s.e();
        }
        return this.ad;
    };
    Object.defineProperty(PropertyEditor.prototype, "u", {
        get: function () {
            return this.t;
        },
        set: function (a) {
            var b = this.t;
            this.t = a;
            if (b != this.t) {
                this.dk("BaseTheme", enumGetBox(BaseControlTheme_$type, b), enumGetBox(BaseControlTheme_$type, this.t));
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(PropertyEditor.prototype, "w", {
        get: function () {
            return this.v;
        },
        set: function (a) {
            var b = this.v;
            this.v = a;
            if (b != this.v) {
                this.dk("Density", enumGetBox(ControlDisplayDensity_$type, b), enumGetBox(ControlDisplayDensity_$type, this.v));
            }
        },
        enumerable: true,
        configurable: true
    });
    PropertyEditor.prototype.dk = function (a, b, c) {
        if (this.propertyChanged != null) {
            this.propertyChanged(this, new PropertyChangedEventArgs(a));
        }
        this.dp(a, b, c);
    };
    PropertyEditor.prototype.dp = function (a, b, c) {
        switch (a) {
            case "DescriptionType":
                if (this.b0 == null) {
                    if (this.properties == null) {
                        this.actualProperties = null;
                    }
                }
                if (this.b0 != null) {
                    if (this.m == null) {
                        this.m = new PropertyEditorDataSource();
                    }
                    this.m.l = this.b0;
                }
                if (this.properties == null || this.properties.count == 0) {
                    if (this.m.g != null) {
                        this.actualProperties = this.m.g;
                    }
                }
                else {
                    if (this.properties != null && this.properties.count > 0) {
                        this.ao();
                    }
                }
                break;
            case "ComponentRenderer":
                if (this.g == null) {
                    this.j = this.k;
                }
                else {
                    this.j = this.g.context;
                }
                break;
            case "Target": break;
            case "Context":
                if (this.g == null) {
                    this.j = c;
                }
                break;
            case "ActualContext":
                if (this.j == null) {
                    if (this.properties == null) {
                        this.actualProperties = null;
                    }
                }
                if (this.j != null) {
                    if (this.m == null) {
                        this.m = new PropertyEditorDataSource();
                    }
                    this.m.b = this.j;
                }
                if (this.properties == null || this.properties.count == 0) {
                    if (this.m.g != null) {
                        this.actualProperties = this.m.g;
                    }
                }
                else {
                    if (this.properties != null && this.properties.count > 0) {
                        this.ao();
                    }
                }
                break;
            case "Properties":
                this.actualProperties = this.properties;
                break;
            case "IsWrappingEnabled":
                this.du();
                break;
            case "IsHorizontal":
                if (this.am) {
                    if (this.actualProperties != null && !(typeCast(HorizontalPropertyEditorDataSource.$, this.actualProperties) !== null)) {
                        this.actualProperties = new HorizontalPropertyEditorDataSource(this.actualProperties);
                    }
                }
                else {
                    if (typeCast(HorizontalPropertyEditorDataSource.$, this.actualProperties) !== null) {
                        var d = this.actualProperties;
                        this.actualProperties = d.ae;
                    }
                }
                break;
            case "ActualProperties":
                if (this.am) {
                    if (this.actualProperties != null && !(typeCast(HorizontalPropertyEditorDataSource.$, this.actualProperties) !== null)) {
                        this.actualProperties = new HorizontalPropertyEditorDataSource(this.actualProperties);
                    }
                }
                else {
                    if (typeCast(HorizontalPropertyEditorDataSource.$, this.actualProperties) !== null) {
                        var e = this.actualProperties;
                        this.actualProperties = e.ae;
                    }
                }
                if (this.l != null) {
                    if (c != null) {
                        this.l.a8.m();
                        this.l.b5.m();
                        this.l.v.clear();
                        this.l.b8.m();
                    }
                    if (this.l.actualDataSource != null) {
                        var f = this.l.actualDataSource;
                        f.schemaChanged = delegateRemove(f.schemaChanged, runOn(this, this.dm));
                    }
                    var g = this.l.itemsSource != this.actualProperties;
                    var h = this.actualProperties;
                    h = this.actualProperties.toArray();
                    this.l.itemsSource = h;
                    this.ce();
                    if (this.l.actualDataSource != null) {
                        var i = this.l.actualDataSource;
                        i.schemaChanged = delegateCombine(i.schemaChanged, runOn(this, this.dm));
                    }
                    if (g) {
                        this.du();
                    }
                }
                break;
            case "FilterPlaceholderText":
                if (this.x != null) {
                    this.x.b8 = this.b2;
                }
                break;
            case "SearchInputType":
                if (this.y != null) {
                    this.y.k = this.aa;
                }
                break;
            case "RowHeight":
                if (this.l != null) {
                    this.l.l1 = this.bl;
                }
                break;
            case "CellTextStyle":
                if (this.l != null) {
                    this.l.fu = this.ad;
                }
                break;
            case "BackgroundColor":
            case "TextColor":
                var j = this.l;
                if (null != j) {
                    j.v4 = this.d1;
                    j.v2 = this.dx;
                }
                this.s.ac();
                break;
            case "BaseTheme":
                this.dt();
                break;
            case "Density":
                this.ds();
                break;
        }
    };
    PropertyEditor.prototype.ao = function () {
        var e_3, _a;
        var a = this.al;
        this.al = true;
        var b = false;
        try {
            for (var _b = tslib_1.__values(fromEnum(this.properties)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var c = _c.value;
                var d = c.y;
                if (this.m != null) {
                    var e = this.m.d(d, false);
                    if (e != null) {
                        if (c.m(e)) {
                            b = true;
                        }
                    }
                }
            }
        }
        catch (e_3_1) {
            e_3 = { error: e_3_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_3)
                    throw e_3.error;
            }
        }
        if (b) {
            this.du();
        }
        else if (this.l != null) {
            this.l.rg();
        }
        this.al = a;
        return b;
    };
    PropertyEditor.prototype.ds = function () {
        if (this.l != null) {
            this.l.fl = this.w;
        }
        if (this.y != null) {
            this.y.h = this.w;
        }
        this.s.x();
    };
    PropertyEditor.prototype.dt = function () {
        if (this.y != null) {
            this.y.d = this.u;
        }
        this.s.z();
    };
    PropertyEditor.prototype.dm = function (a, b) {
        this.ai = true;
        this.ce();
        this.ai = false;
    };
    PropertyEditor.prototype.du = function () {
        this.ap.clear();
        this.l.actualColumns.clear();
        this.l.h5 = false;
        this.l.l1 = this.bl == -1 ? 38 : this.bl;
        this.l.v2 = this.dx;
        this.l.v3 = this.dx;
        this.l.fl = this.w;
        this.l.w8 = new Thickness(0, 0);
        if (this.ad != null) {
            this.l.fu = this.ad;
        }
        if (this.am) {
            this.cg();
        }
        else {
            var a = new TextColumn();
            a.h4 = "PropertyPath";
            a.dataBinding = delegateCombine(a.dataBinding, runOn(this, this.dd));
            this.l.columns.add(a);
            var b = new TemplateColumn();
            b.h4 = "ValueType";
            b.dataBinding = delegateCombine(b.dataBinding, runOn(this, this.cl));
            b.cellStyleKeyRequested = delegateCombine(b.cellStyleKeyRequested, runOn(this, this.cj));
            b.cellUpdating = delegateCombine(b.cellUpdating, runOn(this, this.ck));
            this.l.columns.add(b);
        }
    };
    PropertyEditor.prototype.cg = function () {
        if (this.actualProperties == null) {
            return;
        }
        var a = this.actualProperties.ae;
        var b = a.count;
        var c = new List$1(Column.$, 0);
        var d = this.bi(a, b, c, 0x7FFFFFFF);
        for (var e = 0; e < c.count; e++) {
            this.l.columns.add(c._inner[e]);
        }
        this.bk = d;
        var f = this.actualProperties;
        var g = f.count;
        f.clear();
        for (var h = 0; h < this.bk; h++) {
            f.add(new PropertyEditorPropertyDescription());
        }
        if (f.count != g) {
            var i = f.toArray();
            this.l.itemsSource = i;
            this.s.u();
        }
    };
    PropertyEditor.prototype.d2 = function () {
        if (this.am && this.l != null && this.l.itemsSource != null) {
            var a = this.l.k8;
            var b = this.l.itemsSource;
            return new Size(1, 0, b.count * a);
        }
        else {
            return new Size(1, 0, 0);
        }
    };
    PropertyEditor.prototype.bi = function (a, b, c, d) {
        var e = 0;
        var f = 0;
        var g = 0;
        var h = this.s.h();
        h -= 5;
        if (!this.an) {
            h = 1.7976931348623157E+308;
        }
        var i = 0;
        var j = h;
        var _loop_1 = function (k) {
            var l = a.item(k);
            var m = this_1.a7(l);
            var n = this_1.a3(l);
            if ((i + m + n > h && g > 0) || g >= d) {
                d = Math.max(Math.min(d, g), 2);
                f++;
                var o = h - i;
                if (o < j) {
                    j = o;
                }
                i = 0;
                g = 0;
            }
            var p = this_1.b5(l);
            if (c.count <= g) {
                var q = new TextColumn();
                q.width = ((function () {
                    var $ret = new ColumnWidth();
                    $ret.c = false;
                    $ret.f = m;
                    return $ret;
                })());
                q.dataBinding = delegateCombine(q.dataBinding, runOn(this_1, this_1.dd));
                q.il = "PropertyName_" + k;
                q.h4 = "PropertyName";
                c.add(q);
                this_1.ap.item(q, c.count - 1);
                g++;
            }
            else {
                var r = c._inner[g];
                if (m > r.width.f) {
                    var s = m - r.width.f;
                    r.width = ((function () {
                        var $ret = new ColumnWidth();
                        $ret.c = false;
                        $ret.f = m;
                        return $ret;
                    })());
                    if (s > j) {
                        this_1.dr(h, c);
                        if (c.count == 0) {
                            return { value: 0 };
                        }
                        return { value: this_1.bi(a, b, c, c.count) };
                    }
                    else {
                        j -= s;
                        g++;
                    }
                }
                else {
                    m = r.width.f;
                    g++;
                }
            }
            if (c.count <= g) {
                var t = new TemplateColumn();
                t.il = "ValueType_" + k;
                t.h4 = "ValueType";
                t.dataBinding = delegateCombine(t.dataBinding, runOn(this_1, this_1.cl));
                t.width = ((function () {
                    var $ret = new ColumnWidth();
                    $ret.c = false;
                    $ret.f = n;
                    return $ret;
                })());
                t.cellStyleKeyRequested = delegateCombine(t.cellStyleKeyRequested, runOn(this_1, this_1.cj));
                t.cellUpdating = delegateCombine(t.cellUpdating, runOn(this_1, this_1.ck));
                c.add(t);
                this_1.ap.item(t, c.count - 1);
                g++;
            }
            else {
                var u = c._inner[g];
                if (n > u.width.f) {
                    var v = n - u.width.f;
                    u.width = ((function () {
                        var $ret = new ColumnWidth();
                        $ret.c = false;
                        $ret.f = n;
                        return $ret;
                    })());
                    if (v > j) {
                        this_1.dr(h, c);
                        if (c.count == 0) {
                            return { value: 0 };
                        }
                        return { value: this_1.bi(a, b, c, c.count) };
                    }
                    else {
                        j -= v;
                        g++;
                    }
                }
                else {
                    n = u.width.f;
                    g++;
                }
            }
            i += m + n;
        };
        var this_1 = this;
        for (var k = 0; k < b; k++) {
            var state_1 = _loop_1(k);
            if (typeof state_1 === "object")
                return state_1.value;
        }
        return f + 1;
    };
    PropertyEditor.prototype.dr = function (a, b) {
        var e_4, _a;
        var c = 0;
        try {
            for (var _b = tslib_1.__values(fromEnum(b)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var d = _c.value;
                c += d.width.f;
            }
        }
        catch (e_4_1) {
            e_4 = { error: e_4_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_4)
                    throw e_4.error;
            }
        }
        while (c > a) {
            if (b.count < 1) {
                return;
            }
            if (typeCast(TemplateColumn.$, b._inner[b.count - 1]) !== null) {
                c -= b._inner[b.count - 1].width.f;
                c -= b._inner[b.count - 2].width.f;
                b.removeAt(b.count - 1);
                b.removeAt(b.count - 1);
            }
            else {
                c -= b._inner[b.count - 1].width.f;
                b.removeAt(b.count - 1);
            }
        }
    };
    PropertyEditor.prototype.cl = function (a, b) {
        var c = a;
        var d = this.n(c, b.cellInfo.ej, b.rowObject);
        b.resolvedValue = enumGetBox(PropertyEditorValueType_$type, d != null ? d.k : 0);
    };
    PropertyEditor.prototype.dd = function (a, b) {
        var c = a;
        var d = this.n(c, b.cellInfo.ej, b.rowObject);
        if (d == null) {
            b.resolvedValue = null;
            return;
        }
        b.resolvedValue = d.w != null ? d.w : d.y;
    };
    PropertyEditor.prototype.a3 = function (a) {
        switch (a.k) {
            case 10: return this.aq(a);
            case 7: return this.ar(a);
            case 4: return this.at(a);
            case 6: return this.as(a);
            case 9: return this.aw(a);
            case 5: return this.ay(a);
            case 14: return this.ax(a);
            case 18: return this.az(a);
            case 3: return this.a0(a);
            case 15: return this.a4(a);
            case 17: return this.a5(a);
            case 16: return this.a8(a);
            case 1: return this.a9(a);
            case 11: return this.ba(a);
            case 13: return this.bb(a);
            case 12: return this.bc(a);
            case 2: return this.bd(a);
            case 8: return this.be(a);
            case 19: return this.bf(a);
            case 0: return this.a6(a);
        }
        return 100;
    };
    PropertyEditor.prototype.bf = function (a) {
        return this.a6(a);
    };
    PropertyEditor.prototype.a6 = function (a) {
        return 250;
    };
    PropertyEditor.prototype.au = function (a) {
        return 100;
    };
    PropertyEditor.prototype.be = function (a) {
        return this.au(a);
    };
    PropertyEditor.prototype.bd = function (a) {
        return this.a6(a);
    };
    PropertyEditor.prototype.bc = function (a) {
        return this.a6(a);
    };
    PropertyEditor.prototype.bb = function (a) {
        return this.a6(a);
    };
    PropertyEditor.prototype.ba = function (a) {
        return this.a6(a);
    };
    PropertyEditor.prototype.a9 = function (a) {
        return this.a6(a);
    };
    PropertyEditor.prototype.a8 = function (a) {
        return this.au(a);
    };
    PropertyEditor.prototype.a5 = function (a) {
        return this.au(a);
    };
    PropertyEditor.prototype.a4 = function (a) {
        return this.a2(a);
    };
    PropertyEditor.prototype.a2 = function (a) {
        return this.a6(a);
    };
    PropertyEditor.prototype.a0 = function (a) {
        return this.a1(a);
    };
    PropertyEditor.prototype.a1 = function (a) {
        return this.a6(a);
    };
    PropertyEditor.prototype.az = function (a) {
        return this.au(a);
    };
    PropertyEditor.prototype.ax = function (a) {
        return this.au(a);
    };
    PropertyEditor.prototype.ay = function (a) {
        return this.a6(a);
    };
    PropertyEditor.prototype.aw = function (a) {
        return this.au(a);
    };
    PropertyEditor.prototype.as = function (a) {
        return this.au(a);
    };
    PropertyEditor.prototype.at = function (a) {
        return this.a6(a);
    };
    PropertyEditor.prototype.ar = function (a) {
        return this.av(a);
    };
    PropertyEditor.prototype.av = function (a) {
        return 50;
    };
    PropertyEditor.prototype.aq = function (a) {
        return this.au(a);
    };
    PropertyEditor.prototype.a7 = function (a) {
        return this.s.i(this.b5(a)) + 30;
    };
    PropertyEditor.prototype.b5 = function (a) {
        return a.w != null ? a.w : a.y;
    };
    PropertyEditor.prototype.ck = function (a, b) {
        var c = a;
        var d = this.n(c, b.cellInfo.ej, b.cellInfo.gq);
        var e = d != null ? d.k : 0;
        switch (e) {
            case 10:
                this.cm(c, b);
                break;
            case 7:
                this.cn(c, b);
                break;
            case 4:
                this.cp(c, b);
                break;
            case 6:
                this.co(c, b);
                break;
            case 9:
                this.cq(c, b);
                break;
            case 5:
                this.cs(c, b);
                break;
            case 14:
                this.cr(c, b);
                break;
            case 18:
                this.ct(c, b);
                break;
            case 3:
                this.cu(c, b);
                break;
            case 15:
                this.cx(c, b);
                break;
            case 17:
                this.cy(c, b);
                break;
            case 16:
                this.c0(c, b);
                break;
            case 1:
                this.c1(c, b);
                break;
            case 11:
                this.c2(c, b);
                break;
            case 13:
                this.c3(c, b);
                break;
            case 12:
                this.c4(c, b);
                break;
            case 2:
                this.c5(c, b);
                break;
            case 8:
                this.c6(c, b);
                break;
            case 19:
                this.c7(c, b);
                break;
            case 0: break;
        }
    };
    PropertyEditor.prototype.c7 = function (a, b) {
        this.cz(a, b);
    };
    PropertyEditor.prototype.c6 = function (a, b) {
    };
    PropertyEditor.prototype.c5 = function (a, b) {
        this.cz(a, b);
    };
    PropertyEditor.prototype.c4 = function (a, b) {
        this.cz(a, b);
    };
    PropertyEditor.prototype.c3 = function (a, b) {
        this.cz(a, b);
    };
    PropertyEditor.prototype.c2 = function (a, b) {
        this.cz(a, b);
    };
    PropertyEditor.prototype.c1 = function (a, b) {
        this.cz(a, b);
    };
    PropertyEditor.prototype.cz = function (a, b) {
        var _this = this;
        this.s.s(b, function (c, d) {
            if (c.k != 2) {
                c.k = 2;
            }
            if (c.h != 3) {
                c.h = 3;
            }
            var e = _this.n(a, b.cellInfo.ej, b.cellInfo.gq);
            var f = c.inputs._inner[0];
            f.bb = e;
            f.cg = e.q;
            if (d) {
                f.changing = delegateCombine(f.changing, runOn(_this, _this.da));
            }
        });
    };
    PropertyEditor.prototype.cw = function (a, b) {
        var _this = this;
        this.s.r(b, function (c, d) {
            if (c.density != 3) {
                c.density = 3;
            }
            var e = _this.n(a, b.cellInfo.ej, b.cellInfo.gq);
            if (c.c0 != e) {
                if (!d) {
                    c.valueChanged = delegateRemove(c.valueChanged, runOn(_this, _this.ch));
                }
                c.c0 = e;
                c.c1 = null;
                c.itemsSource = _this.b(_this.a(e));
                if (e.q != c.c1) {
                    c.c1 = e.q;
                }
                if (!d) {
                    c.valueChanged = delegateCombine(c.valueChanged, runOn(_this, _this.ch));
                }
            }
            else {
                if (e.q != c.c1) {
                    c.c1 = e.q;
                }
            }
            if (d) {
                c.valueChanged = delegateCombine(c.valueChanged, runOn(_this, _this.ch));
                c.hd = BrushUtil.g(255, 255, 255, 255);
                c.g = ["Name"];
                c.columnHeadersVisible = false;
                c.defaultColumnWidth = ((function () {
                    var $ret = new ColumnWidth();
                    $ret.c = false;
                    $ret.f = _this.a3(e);
                    return $ret;
                })());
                c.fe = "Name";
            }
        });
    };
    PropertyEditor.prototype.b = function (a) {
        var b = new List$1(DropDownDataListItem.$, 0);
        var _loop_2 = function (c) {
            b.add(((function () {
                var $ret = new DropDownDataListItem();
                $ret.Name = a[c];
                $ret.Value = a[c];
                return $ret;
            })()));
        };
        for (var c = 0; c < a.length; c++) {
            _loop_2(c);
        }
        return b.toArray();
    };
    PropertyEditor.prototype.a = function (a) {
        return a.c;
    };
    PropertyEditor.prototype.ch = function (a, b) {
        var c = a;
        var d = c.c0;
        this.al = true;
        d.q = c.c1;
        this.al = false;
        this.dl(d);
    };
    PropertyEditor.prototype.da = function (a, b) {
        var c = a;
        var d = c.bb;
        this.al = true;
        d.q = c.cg;
        this.al = false;
        this.dl(d);
    };
    PropertyEditor.prototype.dl = function (a) {
        var _this = this;
        if (this.bn != null && this.g != null) {
            var b = this.bo == null;
            this.bo = this.b4();
            if (b) {
                this.s.t(this.bn, function (c) { return _this.g.loadJsonOverlay(_this.bo, function (d) { return c; }, function (d) { return _this.bn; }); });
            }
            else {
                this.s.t(this.bn, function (c) { return _this.g.loadJsonDelta(_this.bo, function (d) { return c; }, false); });
            }
        }
    };
    PropertyEditor.prototype.b4 = function () {
        if (this.actualProperties == null) {
            return null;
        }
        var a = this.actualProperties;
        if (typeCast(HorizontalPropertyEditorDataSource.$, a) !== null) {
            a = a.ae;
        }
        var b = new PropertyEditorTreeTransformer(this.j, this.b0);
        this.cv(a, "", b, this.b0);
        return b.g();
    };
    PropertyEditor.prototype.cv = function (a, b, c, d) {
        for (var e = 0; e < a.count; e++) {
            var f = a._inner[e];
            if (f.i != null) {
                for (var g = 0; g < f.i.count; g++) {
                    var h = f.i._inner[g];
                    var i = b + f.y + "[" + g + "]";
                    this.cv(h.a, i, c, h.b);
                }
            }
            else if (f.g != null) {
                var j = b + f.y;
                this.cv(f.g.a, j, c, f.g.b);
            }
            else {
                c.h(b + f.y, f.q, d);
            }
        }
    };
    PropertyEditor.prototype.c0 = function (a, b) {
    };
    PropertyEditor.prototype.cy = function (a, b) {
    };
    PropertyEditor.prototype.cx = function (a, b) {
        this.cw(a, b);
    };
    PropertyEditor.prototype.cu = function (a, b) {
    };
    PropertyEditor.prototype.ct = function (a, b) {
    };
    PropertyEditor.prototype.cr = function (a, b) {
    };
    PropertyEditor.prototype.cs = function (a, b) {
        this.cz(a, b);
    };
    PropertyEditor.prototype.cq = function (a, b) {
    };
    PropertyEditor.prototype.co = function (a, b) {
    };
    PropertyEditor.prototype.cp = function (a, b) {
        this.cz(a, b);
    };
    PropertyEditor.prototype.cn = function (a, b) {
        var _this = this;
        this.s.q(b, function (c, d) {
            if (!c.t) {
                c.t = true;
            }
            var e = _this.n(a, b.cellInfo.ej, b.cellInfo.gq);
            var f = e.q;
            if (f == null) {
                f = false;
            }
            var g = f;
            c.checked = g;
            c.a5 = e;
            if (d) {
                c.change = delegateCombine(c.change, runOn(_this, _this.cf));
            }
        });
    };
    PropertyEditor.prototype.n = function (a, b, c) {
        if (this.am) {
            var d = this.actualProperties.ae;
            var e = d;
            var f = truncate((this.l.actualColumns.count / 2));
            var g = b * f;
            var h = this.bj(a);
            h = truncate(Math.floor(h / 2)) + g;
            if (h > e.count - 1) {
                return null;
            }
            return e.item(h);
        }
        else {
            return c;
        }
    };
    PropertyEditor.prototype.bj = function (a) {
        return this.ap.item(a);
    };
    PropertyEditor.prototype.cf = function (a, b) {
        var c = a;
        var d = c.a5;
        this.al = true;
        d.q = c.checked;
        this.al = false;
        this.dl(d);
    };
    PropertyEditor.prototype.cm = function (a, b) {
    };
    PropertyEditor.prototype.cj = function (a, b) {
        var c = a;
        var d = b;
        if (!this.am) {
            d = this.actualProperties._inner[b.rowNumber];
        }
        var e = this.n(c, b.rowNumber, d);
        var f = e != null ? e.k : 0;
        b.styleKey = "editortype_" + enumGetBox(PropertyEditorValueType_$type, f);
    };
    PropertyEditor.prototype.db = function (a, b) {
        var c = b.value.toLowerCase();
        this.dj(c);
    };
    PropertyEditor.prototype.dh = function (a, b, c) {
        if (this.l != null) {
            this.l.rm(a, b, c);
        }
    };
    PropertyEditor.prototype.de = function () {
        if (this.l != null) {
            this.l.rg();
        }
    };
    PropertyEditor.prototype.df = function (a, b) {
        if (this.l != null) {
            this.l.ri(a, b);
        }
        ;
    };
    PropertyEditor.prototype.dg = function (a, b) {
        if (this.l != null) {
            this.l.rj(a, b);
        }
        ;
    };
    Object.defineProperty(PropertyEditor.prototype, "j", {
        get: function () {
            return this.h;
        },
        set: function (a) {
            var b = this.h;
            this.h = a;
            this.dk("ActualContext", b, this.h);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(PropertyEditor.prototype, "k", {
        get: function () {
            return this.i;
        },
        set: function (a) {
            var b = this.i;
            this.i = a;
            this.dk("Context", b, this.i);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(PropertyEditor.prototype, "g", {
        get: function () {
            return this.f;
        },
        set: function (a) {
            var b = this.f;
            this.f = a;
            this.dk("ComponentRenderer", b, this.f);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(PropertyEditor.prototype, "bn", {
        get: function () {
            return this.bm;
        },
        set: function (a) {
            var b = this.bm;
            this.bm = a;
            this.dk("Target", b, this.bm);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(PropertyEditor.prototype, "b0", {
        get: function () {
            return this.bp;
        },
        set: function (a) {
            var b = this.bp;
            this.bp = a;
            this.dk("DescriptionType", b, this.bp);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(PropertyEditor.prototype, "am", {
        get: function () {
            return this.aj;
        },
        set: function (a) {
            var b = this.aj;
            this.aj = a;
            this.dk("IsHorizontal", b, this.aj);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(PropertyEditor.prototype, "an", {
        get: function () {
            return this.ak;
        },
        set: function (a) {
            var b = this.ak;
            this.ak = a;
            this.dk("IsWrappingEnabled", b, this.ak);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(PropertyEditor.prototype, "dx", {
        get: function () {
            return this.dv;
        },
        set: function (a) {
            var b = this.dv;
            this.dv = a;
            if (b != this.dv) {
                this.dk("BackgroundColor", b, a);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(PropertyEditor.prototype, "d1", {
        get: function () {
            return this.dw;
        },
        set: function (a) {
            var b = this.dw;
            this.dw = a;
            if (b != this.dw) {
                this.dk("TextColor", b, a);
            }
        },
        enumerable: true,
        configurable: true
    });
    PropertyEditor.prototype.ce = function () {
        var a = this.l.actualDataSource;
        if (null != a) {
            if (null == a.actualSchema) {
                this.bh = -1;
                return;
            }
            var b = a.actualCount;
            this.bh = b;
        }
        else {
            this.bh = -1;
        }
    };
    PropertyEditor.$t = markType(PropertyEditor, 'PropertyEditor', Base.$, [INotifyPropertyChanged_$type]);
    PropertyEditor.d0 = BrushUtil.g(255, 24, 29, 31);
    PropertyEditor.cb = "M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z";
    PropertyEditor.dy = BrushUtil.g(255, 248, 248, 248);
    PropertyEditor.dz = BrushUtil.g(255, 24, 29, 31);
    return PropertyEditor;
}(Base));
export { PropertyEditor };
//# sourceMappingURL=PropertyEditorView_combined.js.map
