/*
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, 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
 */
var CodeGeneratingComponentRendererDataEmitter = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(CodeGeneratingComponentRendererDataEmitter, _super);
    function CodeGeneratingComponentRendererDataEmitter(a, b) {
        var _this = _super.call(this) || this;
        _this.o = null;
        _this.m = null;
        _this.e = null;
        _this.d = null;
        _this.i = ((function () {
            var $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);
        return _this;
    }
    Object.defineProperty(CodeGeneratingComponentRendererDataEmitter.prototype, "p", {
        get: function () {
            return this.o;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CodeGeneratingComponentRendererDataEmitter.prototype, "n", {
        get: function () {
            return this.m;
        },
        enumerable: true,
        configurable: true
    });
    CodeGeneratingComponentRendererDataEmitter.prototype.v = function (a, b) {
        if (b === void 0) {
            b = false;
        }
        return a;
    };
    CodeGeneratingComponentRendererDataEmitter.prototype.u = function (a) {
        return a;
    };
    Object.defineProperty(CodeGeneratingComponentRendererDataEmitter.prototype, "h", {
        get: function () {
            return this.e;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CodeGeneratingComponentRendererDataEmitter.prototype, "g", {
        get: function () {
            return this.d;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CodeGeneratingComponentRendererDataEmitter.prototype, "k", {
        get: function () {
            return this.i;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CodeGeneratingComponentRendererDataEmitter.prototype, "l", {
        get: function () {
            return this.j;
        },
        set: function (a) {
            this.j = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CodeGeneratingComponentRendererDataEmitter.prototype, "f", {
        get: function () {
            return this.c;
        },
        set: function (a) {
            this.c = a;
        },
        enumerable: true,
        configurable: true
    });
    CodeGeneratingComponentRendererDataEmitter.prototype.t = function (a, b) {
        return null;
    };
    CodeGeneratingComponentRendererDataEmitter.prototype.get_s = function () {
        return "";
    };
    Object.defineProperty(CodeGeneratingComponentRendererDataEmitter.prototype, "s", {
        get: function () {
            return this.get_s();
        },
        enumerable: true,
        configurable: true
    });
    CodeGeneratingComponentRendererDataEmitter.prototype.aa = function (a) {
        var e_1, _a;
        if (a != null) {
            var b = a;
            var c = b.e();
            for (var d = 0; d < c.length; d++) {
                var e = c[d];
                var f = b.item(e);
                if (typeCast(JsonDictionaryValue.$, f) !== null) {
                    var g = f;
                    this.ag(e, g);
                }
                else if (typeCast(JsonDictionaryArray.$, f) !== null) {
                    var h = f;
                    this.ae(e, h, this.h, this.k);
                    this.af(e, 0, null);
                }
                else {
                    var i = f;
                    var j = this.a(i);
                    var k = this.b(i);
                    var l = this.r(this.v(e, true), this.v(e), j, k);
                    try {
                        for (var _b = (e_1 = void 0, tslib_1.__values(fromEnum(l))), _c = _b.next(); !_c.done; _c = _b.next()) {
                            var m = _c.value;
                            this.ab(m, this.h, this.k);
                        }
                    }
                    catch (e_1_1) {
                        e_1 = { error: e_1_1 };
                    }
                    finally {
                        try {
                            if (_c && !_c.done && (_a = _b.return))
                                _a.call(_b);
                        }
                        finally {
                            if (e_1)
                                throw e_1.error;
                        }
                    }
                    this.ah(e, j, k, i);
                }
            }
        }
        var n = new HashSet$1(String_$type, 0);
        for (var o = 0; o < this.m.t.count; o++) {
            var 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);
                    var q = this.o.library.getItem(p.a.e);
                    if (q.type == 0) {
                        var r = new CodeGeneratingCodeWriter(this.o);
                        var s = new CodeGeneratingImportManager();
                        var t = q.name;
                        var u = q.getContentForPlatform(this.m.platform);
                        if (u.isJson) {
                            var v = q.getConfigForPlatform(this.m.platform);
                            var w = 0;
                            if (v != null) {
                                w = v.location;
                            }
                            switch (w) {
                                case 0:
                                    var x = new JsonDictionaryParser();
                                    var 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);
                                    var z = u.content;
                                    this.y(t, s);
                                    r.j(z);
                                    break;
                            }
                        }
                        else {
                            var 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());
    };
    CodeGeneratingComponentRendererDataEmitter.prototype.ac = function (a) {
    };
    CodeGeneratingComponentRendererDataEmitter.prototype.ad = function (a) {
    };
    CodeGeneratingComponentRendererDataEmitter.prototype.z = function (a, b) {
    };
    CodeGeneratingComponentRendererDataEmitter.prototype.x = function (a, b) {
    };
    CodeGeneratingComponentRendererDataEmitter.prototype.y = function (a, b) {
    };
    CodeGeneratingComponentRendererDataEmitter.prototype.ah = function (a, b, c, d) {
    };
    CodeGeneratingComponentRendererDataEmitter.prototype.af = function (a, b, c) {
    };
    CodeGeneratingComponentRendererDataEmitter.prototype.ag = function (a, b) {
    };
    CodeGeneratingComponentRendererDataEmitter.prototype.ae = function (a, b, c, d) {
        if (typeCast(JsonDictionaryArray.$, b) !== null) {
            var e = b;
            if (e.items != null && e.items.length > 0) {
                var f = this.q(e.items);
                if (f != null) {
                    var g = this.a(f);
                    var h = this.b(f);
                    if (g != null) {
                        this.aj(a, g, h, c, d);
                        for (var i = 0; i < e.items.length; i++) {
                            this.w(a, g, h, e.items[i], i, c);
                        }
                        this.ai(a, g, h, c);
                    }
                }
            }
        }
    };
    CodeGeneratingComponentRendererDataEmitter.prototype.ai = function (a, b, c, d) {
    };
    CodeGeneratingComponentRendererDataEmitter.prototype.ab = function (a, b, c) {
    };
    CodeGeneratingComponentRendererDataEmitter.prototype.r = function (a, b, c, d) {
        var e = new List$1(CodeGeneratingComponentRendererDataEmitterItemType.$, 0);
        var f = new CodeGeneratingComponentRendererDataEmitterItemType();
        f.d = a;
        f.c = b;
        f.a = c;
        f.b = d;
        e.add(f);
        for (var g = 0; g < c.length; g++) {
            var h = c[g];
            var i = d[g];
            if (i.f) {
                var j = this.r(this.v(a) + "_" + h, b, i.a, i.b);
                e.o(j);
            }
            else if (i.d) {
                var k = this.r(this.v(a) + "_" + h + "Item", b, i.a, i.b);
                e.o(k);
            }
        }
        return e;
    };
    CodeGeneratingComponentRendererDataEmitter.prototype.w = function (a, b, c, d, e, f) {
    };
    CodeGeneratingComponentRendererDataEmitter.prototype.aj = function (a, b, c, d, e) {
    };
    CodeGeneratingComponentRendererDataEmitter.prototype.b = function (a) {
        var b = new List$1(CodeGeneratingComponentRendererDataEmitterPropertyType.$, 0);
        if (typeCast(JsonDictionaryObject.$, a) !== null) {
            var c = a;
            var d = c.e();
            for (var f = 0; f < d.length; f++) {
                var e = d[f];
                var g = c.item(e);
                var h = new CodeGeneratingComponentRendererDataEmitterPropertyType();
                if (typeCast(JsonDictionaryObject.$, g) !== null) {
                    h.f = true;
                    var i = this.a(g);
                    var j = this.b(g);
                    h.a = i;
                    h.b = j;
                }
                else if (typeCast(JsonDictionaryArray.$, g) !== null) {
                    h.d = true;
                    var k = g;
                    if (k.items != null && k.items.length > 0) {
                        var l = this.q(k.items);
                        var m = this.a(l);
                        var n = this.b(l);
                        h.a = m;
                        h.b = n;
                    }
                }
                else {
                    var o = g;
                    h.c = o.e;
                }
                b.add(h);
            }
            return b.toArray();
        }
        return null;
    };
    CodeGeneratingComponentRendererDataEmitter.prototype.a = function (a) {
        if (typeCast(JsonDictionaryObject.$, a) !== null) {
            var b = a;
            return b.e();
        }
        return null;
    };
    CodeGeneratingComponentRendererDataEmitter.prototype.q = function (a) {
        for (var b = 0; b < a.length; b++) {
            if (a[b] != null) {
                var c = this.b(a[b]);
                if (c == null) {
                    continue;
                }
                var d = true;
                for (var e = 0; e < c.length; e++) {
                    if (!c[e].e()) {
                        d = false;
                    }
                }
                if (!d) {
                    continue;
                }
                return a[b];
            }
        }
        return null;
    };
    CodeGeneratingComponentRendererDataEmitter.$t = markType(CodeGeneratingComponentRendererDataEmitter, 'CodeGeneratingComponentRendererDataEmitter');
    return CodeGeneratingComponentRendererDataEmitter;
}(Base));
export { CodeGeneratingComponentRendererDataEmitter };
