/*
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 { 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
 */
export let PropertyEditorTreeTransformer = /*@__PURE__*/ (() => {
    class PropertyEditorTreeTransformer extends Base {
        constructor(a, b) {
            super();
            this.a = new DescriptionTreeNode();
            this.b = null;
            this.b = a;
            this.a = new DescriptionTreeNode();
            this.a.h = b;
            let c = new JsonDictionaryObject();
        }
        h(a, b, c) {
            if (a == null) {
                return;
            }
            this.c(a, b, this.a, c, null);
        }
        c(a, b, c, d, e) {
            if (a == null) {
                return null;
            }
            let f = stringSplit(a, ['.', '['], 0);
            let g = f[0];
            let h = f.length > 1;
            let i = false;
            let j = null;
            if (stringContains(g, "]")) {
                i = true;
                g = stringReplace(g, "]", "");
                if (stringContains(g, "as")) {
                    let k = g.indexOf("as");
                    let l = g.substr(0, k).trim();
                    j = g.substr(k + 2).trim();
                    d = j;
                    g = l;
                }
            }
            let m = null;
            if (!i) {
                m = this.b.d(d, g);
            }
            else {
                m = e;
            }
            if (h) {
                if (i) {
                    let n = c.b;
                    let o = parseInt(stringReplace(stringReplace(g, "[", ""), "]", ""));
                    if (n == null || n.length <= o) {
                        let p = new List$1(Base.$, 0);
                        for (let q = 0; q <= o; q++) {
                            if (n != null && q < n.length) {
                                let r = n[q];
                                if (typeCast(DescriptionTreeNode.$, r) !== null && q == o) {
                                    r.h = j;
                                }
                                p.add1(r);
                            }
                            else {
                                let s = this.d(e, true, j);
                                if (s != null) {
                                    p.add1(s);
                                }
                            }
                        }
                        n = p.toArray();
                        let t = n[o];
                        let u = new List$1(String_$type, 1, f);
                        u.removeAt(0);
                        let v = m.collectionElementType;
                        if (j != null) {
                            v = j;
                        }
                        let w = this.c(stringJoin(".", ...u.toArray()), b, t, v, m);
                        if (w != null) {
                            n[o] = w;
                        }
                        c.b = n;
                    }
                }
                else {
                    let x = c;
                    if (!x.b(g)) {
                        x.n(g, this.d(m, false, null), m);
                    }
                    let y = x.a(g);
                    let z = new List$1(String_$type, 1, f);
                    z.removeAt(0);
                    let aa = this.c(stringJoin(".", ...z.toArray()), b, y, m.specificExternalType, m);
                    if (aa != null) {
                        x.n(g, aa, m);
                    }
                }
            }
            else {
                let ab = c;
                ab.n(g, this.e(b, m), m);
            }
            return null;
        }
        f(a) {
            if (a == null) {
                return null;
            }
            if (a.length < 1) {
                return "";
            }
            return a.substr(0, 1).toLowerCase() + a.substr(1);
        }
        e(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;
        }
        d(a, b, c) {
            if (!b && (a.knownType == 10 || a.knownType == 9)) {
                return new Array(0);
            }
            else {
                let d = new DescriptionTreeNode();
                if (c != null) {
                    d.h = c;
                }
                else {
                    d.h = a.specificExternalType != null ? a.specificExternalType : a.specificType;
                }
                return d;
            }
        }
        g() {
            let a = new DescriptionSerializerBuilder();
            let b = new DescriptionSerializer();
            let 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 = /*@__PURE__*/ markType(PropertyEditorTreeTransformer, 'PropertyEditorTreeTransformer');
    return PropertyEditorTreeTransformer;
})();
//# sourceMappingURL=PropertyEditorTreeTransformer.js.map
