/*
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, fromEnum, String_$type, markType } from "./type";
import { CodeGeneratingCodeWriter } from "./CodeGeneratingCodeWriter";
import { CodeGeneratingImportManager } from "./CodeGeneratingImportManager";
import { CodeGeneratingComponentRendererDataEmitterPropertyType } from "./CodeGeneratingComponentRendererDataEmitterPropertyType";
import { JsonDictionaryValue } from "./JsonDictionaryValue";
import { HashSet$1 } from "./HashSet$1";
import { JsonDictionaryObject } from "./JsonDictionaryObject";
import { JsonDictionaryArray } from "./JsonDictionaryArray";
import { List$1 } from "./List$1";
import { CodeGeneratingComponentRendererDataEmitterItemType } from "./CodeGeneratingComponentRendererDataEmitterItemType";
import { JsonDictionaryParser } from "./JsonDictionaryParser";
/**
 * @hidden
 */
export let CodeGeneratingComponentRendererDataEmitter = /*@__PURE__*/ (() => {
    class CodeGeneratingComponentRendererDataEmitter extends Base {
        get p() {
            return this.o;
        }
        get n() {
            return this.m;
        }
        v(a, b = false) {
            return a;
        }
        u(a) {
            return a;
        }
        constructor(a, b) {
            super();
            this.o = null;
            this.m = null;
            this.e = null;
            this.d = null;
            this.i = ((() => {
                let $ret = new CodeGeneratingImportManager();
                $ret.packageOverride = "./SampleData";
                return $ret;
            })());
            this.j = new CodeGeneratingImportManager();
            this.c = null;
            this.o = a;
            this.m = b;
            this.e = new CodeGeneratingCodeWriter(this.o);
            this.d = new CodeGeneratingCodeWriter(this.o);
            this.c = new CodeGeneratingCodeWriter(this.o);
        }
        get h() {
            return this.e;
        }
        get g() {
            return this.d;
        }
        get k() {
            return this.i;
        }
        get l() {
            return this.j;
        }
        set l(a) {
            this.j = a;
        }
        get f() {
            return this.c;
        }
        set f(a) {
            this.c = a;
        }
        t(a, b) {
            return null;
        }
        get_s() {
            return "";
        }
        get s() {
            return this.get_s();
        }
        aa(a) {
            if (a != null) {
                let b = a;
                let c = b.e();
                for (let d = 0; d < c.length; d++) {
                    let e = c[d];
                    let f = b.item(e);
                    if (typeCast(JsonDictionaryValue.$, f) !== null) {
                        let g = f;
                        this.ag(e, g);
                    }
                    else if (typeCast(JsonDictionaryArray.$, f) !== null) {
                        let h = f;
                        this.ae(e, h, this.h, this.k);
                        this.af(e, 0, null);
                    }
                    else {
                        let i = f;
                        let j = this.a(i);
                        let k = this.b(i);
                        let l = this.r(this.v(e, true), this.v(e), j, k);
                        for (let m of fromEnum(l)) {
                            this.ab(m, this.h, this.k);
                        }
                        this.ah(e, j, k, i);
                    }
                }
            }
            let n = new HashSet$1(String_$type, 0);
            for (let o = 0; o < this.m.t.count; o++) {
                let p = this.m.t._inner[o];
                if (p.a != null && p.c == null) {
                    if (this.o.library != null && this.o.library.hasItem(p.a.e)) {
                        if (n.contains(p.a.e)) {
                            continue;
                        }
                        n.add_1(p.a.e);
                        let q = this.o.library.getItem(p.a.e);
                        if (q.type == 0) {
                            let r = new CodeGeneratingCodeWriter(this.o);
                            let s = new CodeGeneratingImportManager();
                            let t = q.name;
                            let u = q.getContentForPlatform(this.m.platform);
                            if (u.isJson) {
                                let v = q.getConfigForPlatform(this.m.platform);
                                let w = 0;
                                if (v != null) {
                                    w = v.location;
                                }
                                switch (w) {
                                    case 0:
                                        let x = new JsonDictionaryParser();
                                        let y = x.parse(u.content);
                                        this.ad(r);
                                        this.ae(t, y, r, s);
                                        this.ac(r);
                                        this.af(t, w, u);
                                        break;
                                    case 2:
                                        this.af(t, w, u);
                                        break;
                                    case 1:
                                        this.af(t, w, u);
                                        let z = u.content;
                                        this.y(t, s);
                                        r.j(z);
                                        break;
                                }
                            }
                            else {
                                let aa = u.content;
                                this.x(t, s);
                                r.j(aa);
                                this.af(t, 0, u);
                            }
                            this.z(t, s);
                            this.m.addContainerNewFileResult(t + this.s, r.toString());
                        }
                    }
                }
            }
            this.m.addContainerResult("vmProperties", this.g.toString());
            this.m.addImportResult("vmImports", this.k);
            this.m.addImportResult("vmLibraryImports", this.l);
            this.m.addContainerResult("vmLibraryProjectFiles", this.f.toString());
            this.m.addContainerResult("vmData", this.h.toString());
        }
        ac(a) {
        }
        ad(a) {
        }
        z(a, b) {
        }
        x(a, b) {
        }
        y(a, b) {
        }
        ah(a, b, c, d) {
        }
        af(a, b, c) {
        }
        ag(a, b) {
        }
        ae(a, b, c, d) {
            if (typeCast(JsonDictionaryArray.$, b) !== null) {
                let e = b;
                if (e.items != null && e.items.length > 0) {
                    let f = this.q(e.items);
                    if (f != null) {
                        let g = this.a(f);
                        let h = this.b(f);
                        if (g != null) {
                            this.aj(a, g, h, c, d);
                            for (let i = 0; i < e.items.length; i++) {
                                this.w(a, g, h, e.items[i], i, c);
                            }
                            this.ai(a, g, h, c);
                        }
                    }
                }
            }
        }
        ai(a, b, c, d) {
        }
        ab(a, b, c) {
        }
        r(a, b, c, d) {
            let e = new List$1(CodeGeneratingComponentRendererDataEmitterItemType.$, 0);
            let f = new CodeGeneratingComponentRendererDataEmitterItemType();
            f.d = a;
            f.c = b;
            f.a = c;
            f.b = d;
            e.add(f);
            for (let g = 0; g < c.length; g++) {
                let h = c[g];
                let i = d[g];
                if (i.f) {
                    let j = this.r(this.v(a) + "_" + h, b, i.a, i.b);
                    e.o(j);
                }
                else if (i.d) {
                    let k = this.r(this.v(a) + "_" + h + "Item", b, i.a, i.b);
                    e.o(k);
                }
            }
            return e;
        }
        w(a, b, c, d, e, f) {
        }
        aj(a, b, c, d, e) {
        }
        b(a) {
            let b = new List$1(CodeGeneratingComponentRendererDataEmitterPropertyType.$, 0);
            if (typeCast(JsonDictionaryObject.$, a) !== null) {
                let c = a;
                let d = c.e();
                for (let f = 0; f < d.length; f++) {
                    let e = d[f];
                    let g = c.item(e);
                    let h = new CodeGeneratingComponentRendererDataEmitterPropertyType();
                    if (typeCast(JsonDictionaryObject.$, g) !== null) {
                        h.f = true;
                        let i = this.a(g);
                        let j = this.b(g);
                        h.a = i;
                        h.b = j;
                    }
                    else if (typeCast(JsonDictionaryArray.$, g) !== null) {
                        h.d = true;
                        let k = g;
                        if (k.items != null && k.items.length > 0) {
                            let l = this.q(k.items);
                            let m = this.a(l);
                            let n = this.b(l);
                            h.a = m;
                            h.b = n;
                        }
                    }
                    else {
                        let o = g;
                        h.c = o.e;
                    }
                    b.add(h);
                }
                return b.toArray();
            }
            return null;
        }
        a(a) {
            if (typeCast(JsonDictionaryObject.$, a) !== null) {
                let b = a;
                return b.e();
            }
            return null;
        }
        q(a) {
            for (let b = 0; b < a.length; b++) {
                if (a[b] != null) {
                    let c = this.b(a[b]);
                    if (c == null) {
                        continue;
                    }
                    let d = true;
                    for (let e = 0; e < c.length; e++) {
                        if (!c[e].e()) {
                            d = false;
                        }
                    }
                    if (!d) {
                        continue;
                    }
                    return a[b];
                }
            }
            return null;
        }
    }
    CodeGeneratingComponentRendererDataEmitter.$t = /*@__PURE__*/ markType(CodeGeneratingComponentRendererDataEmitter, 'CodeGeneratingComponentRendererDataEmitter');
    return CodeGeneratingComponentRendererDataEmitter;
})();
