/*
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, typeCast, String_$type, markType } from "igniteui-webcomponents-core";
import { DescriptionTreeNode } from "igniteui-webcomponents-core";
import { JsonDictionaryObject } from "igniteui-webcomponents-core";
import { List$1 } from "igniteui-webcomponents-core";
import { DescriptionSerializerBuilder } from "igniteui-webcomponents-core";
import { DescriptionSerializer } from "igniteui-webcomponents-core";
import { stringSplit } from "igniteui-webcomponents-core";
import { stringContains, stringReplace, stringJoin } from "igniteui-webcomponents-core";
/**
 * @hidden
 */
var PropertyEditorTreeTransformer = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(PropertyEditorTreeTransformer, _super);
    function PropertyEditorTreeTransformer(a, b) {
        var _this = _super.call(this) || this;
        _this.a = new DescriptionTreeNode();
        _this.b = null;
        _this.b = a;
        _this.a = new DescriptionTreeNode();
        _this.a.h = b;
        var c = new JsonDictionaryObject();
        return _this;
    }
    PropertyEditorTreeTransformer.prototype.h = function (a, b, c) {
        if (a == null) {
            return;
        }
        this.c(a, b, this.a, c, null);
    };
    PropertyEditorTreeTransformer.prototype.c = function (a, b, c, d, e) {
        if (a == null) {
            return null;
        }
        var f = stringSplit(a, ['.', '['], 0);
        var g = f[0];
        var h = f.length > 1;
        var i = false;
        var j = null;
        if (stringContains(g, "]")) {
            i = true;
            g = stringReplace(g, "]", "");
            if (stringContains(g, "as")) {
                var k = g.indexOf("as");
                var l = g.substr(0, k).trim();
                j = g.substr(k + 2).trim();
                d = j;
                g = l;
            }
        }
        var m = null;
        if (!i) {
            m = this.b.d(d, g);
        }
        else {
            m = e;
        }
        if (h) {
            if (i) {
                var n = c.b;
                var o = parseInt(stringReplace(stringReplace(g, "[", ""), "]", ""));
                if (n == null || n.length <= o) {
                    var p = new List$1(Base.$, 0);
                    for (var q = 0; q <= o; q++) {
                        if (n != null && q < n.length) {
                            var r = n[q];
                            if (typeCast(DescriptionTreeNode.$, r) !== null && q == o) {
                                r.h = j;
                            }
                            p.add1(r);
                        }
                        else {
                            var s = this.d(e, true, j);
                            if (s != null) {
                                p.add1(s);
                            }
                        }
                    }
                    n = p.toArray();
                    var t = n[o];
                    var u = new List$1(String_$type, 1, f);
                    u.removeAt(0);
                    var v = m.collectionElementType;
                    if (j != null) {
                        v = j;
                    }
                    var w = this.c(stringJoin.apply(void 0, tslib_1.__spread(["."], u.toArray())), b, t, v, m);
                    if (w != null) {
                        n[o] = w;
                    }
                    c.b = n;
                }
            }
            else {
                var x = c;
                if (!x.b(g)) {
                    x.n(g, this.d(m, false, null), m);
                }
                var y = x.a(g);
                var z = new List$1(String_$type, 1, f);
                z.removeAt(0);
                var aa = this.c(stringJoin.apply(void 0, tslib_1.__spread(["."], z.toArray())), b, y, m.specificExternalType, m);
                if (aa != null) {
                    x.n(g, aa, m);
                }
            }
        }
        else {
            var ab = c;
            ab.n(g, this.e(b, m), m);
        }
        return null;
    };
    PropertyEditorTreeTransformer.prototype.f = function (a) {
        if (a == null) {
            return null;
        }
        if (a.length < 1) {
            return "";
        }
        return a.substr(0, 1).toLowerCase() + a.substr(1);
    };
    PropertyEditorTreeTransformer.prototype.e = function (a, b) {
        if (a == null) {
            return null;
        }
        if (b == null) {
            return null;
        }
        switch (b.knownType) {
            case 10: return a;
            case 7: return a;
            case 4: return a.toString();
            case 6: return a;
            case 9: return a;
            case 5: return a.toString();
            case 16: return a;
            case 20: return a;
            case 15: return a;
            case 3: return a;
            case 19: return a;
            case 8: return a;
            case 13: return a;
            case 18: return a;
            case 1: return a;
            case 11: return a;
            case 14: return a;
            case 12: return a;
            case 2: return a;
            case 21: return a;
            case 17: return a;
            case 0: return a;
        }
        return null;
    };
    PropertyEditorTreeTransformer.prototype.d = function (a, b, c) {
        if (!b && (a.knownType == 10 || a.knownType == 9)) {
            return new Array(0);
        }
        else {
            var d = new DescriptionTreeNode();
            if (c != null) {
                d.h = c;
            }
            else {
                d.h = a.specificExternalType != null ? a.specificExternalType : a.specificType;
            }
            return d;
        }
    };
    PropertyEditorTreeTransformer.prototype.g = function () {
        var a = new DescriptionSerializerBuilder();
        var b = new DescriptionSerializer();
        var c = "root";
        a.f("{");
        a.i();
        a.f("\"descriptions\": {");
        a.i();
        a.e("\"" + c + "\"");
        a.e(": ");
        b.q(this.b, this.a, a);
        a.f("");
        a.h();
        a.e("}");
        a.h();
        a.f("}");
        return a.toString();
    };
    PropertyEditorTreeTransformer.$t = markType(PropertyEditorTreeTransformer, 'PropertyEditorTreeTransformer');
    return PropertyEditorTreeTransformer;
}(Base));
export { PropertyEditorTreeTransformer };
//# sourceMappingURL=PropertyEditorTreeTransformer.js.map
