/*
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, IEnumerable_$type, fromEnum, typeCast, Date_$type, Boolean_$type, Array_$type, runOn, Number_$type, String_$type, Delegate_$type, markType } from "./type";
import { TypeDescriptionContext } from "./TypeDescriptionContext";
import { TypeDescriptionCleanups } from "./TypeDescriptionCleanups";
import { Dictionary$2 } from "./Dictionary$2";
import { Description } from "./Description";
import { DescriptionTreeNode } from "./DescriptionTreeNode";
import { Queue$1 } from "./Queue$1";
import { DescriptionTreeAction } from "./DescriptionTreeAction";
import { DescriptionRef } from "./DescriptionRef";
import { List$1 } from "./List$1";
import { TypeDescriptionPropretyTransforms } from "./TypeDescriptionPropretyTransforms";
import { DescriptionSerializerBuilder } from "./DescriptionSerializerBuilder";
import { DescriptionSerializer } from "./DescriptionSerializer";
import { DataSourceLocalDataProvider } from "./DataSourceLocalDataProvider";
import { JsonDictionaryParser } from "./JsonDictionaryParser";
import { DescriptionTreeBuilder } from "./DescriptionTreeBuilder";
import { JsonDictionaryObject } from "./JsonDictionaryObject";
import { JsonDictionaryValue } from "./JsonDictionaryValue";
import { JsonDictionaryArray } from "./JsonDictionaryArray";
import { TypeDescriptionMetadata } from "./TypeDescriptionMetadata";
import { DescriptionTreeReconciler } from "./DescriptionTreeReconciler";
import { HashSet$1 } from "./HashSet$1";
import { Tuple$2 } from "./Tuple$2";
import { NotImplementedException } from "./NotImplementedException";
import { ComponentRendererAdapter } from "./ComponentRendererAdapter";
import { stringIsNullOrEmpty, stringStartsWith, stringEndsWith } from "./string";
/**
 * @hidden
 */
var ComponentRenderer = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(ComponentRenderer, _super);
    function ComponentRenderer() {
        var _this = _super.call(this) || this;
        _this.f = null;
        _this._context = null;
        _this._isProceedOnErrorEnabled = false;
        _this.h = null;
        _this.i = null;
        _this.aq = new Dictionary$2(Base.$, Description.$, 0);
        _this.ar = new Dictionary$2(Base.$, Boolean_$type, 0);
        _this.as = new Dictionary$2(Base.$, Boolean_$type, 0);
        _this.ap = new Dictionary$2(Base.$, Boolean_$type, 0);
        _this.ao = new Dictionary$2(Base.$, DescriptionTreeNode.$, 0);
        _this.av = new Dictionary$2(Base.$, ContainerState.$, 0);
        _this.at = new Dictionary$2(Base.$, Queue$1.$.specialize(Queue$1.$.specialize(DescriptionTreeAction.$)), 0);
        _this.an = new Dictionary$2(Base.$, Boolean_$type, 0);
        _this.au = new Dictionary$2(String_$type, DescriptionRef.$, 0);
        _this.aw = new Dictionary$2(String_$type, Base.$, 0);
        _this.ay = new Dictionary$2(String_$type, Base.$, 0);
        _this.a2 = new List$1(Delegate_$type, 0);
        _this.ax = new Dictionary$2(String_$type, List$1.$.specialize(Delegate_$type), 0);
        _this.a0 = new List$1(Delegate_$type, 0);
        _this.a1 = new List$1(Delegate_$type, 0);
        _this._shouldNamespaceSystemRefValues = false;
        var a = _this.g();
        _this.f = a;
        var adapter_ = _this.f;
        var b = (adapter_._platform);
        if (b == "Igc") {
            ComponentRenderer.platform = 4;
        }
        else if (b == "Igr") {
            ComponentRenderer.platform = 2;
        }
        _this.context = new TypeDescriptionContext(_this.f, ComponentRenderer.platform);
        _this.h = new TypeDescriptionPropretyTransforms();
        _this.i = new TypeDescriptionCleanups();
        return _this;
    }
    Object.defineProperty(ComponentRenderer, "defaultInstance", {
        get: function () {
            return ComponentRenderer._defaultInstance;
        },
        set: function (a) {
            ComponentRenderer._defaultInstance = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ComponentRenderer.prototype, "context", {
        get: function () {
            return this._context;
        },
        set: function (a) {
            this._context = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ComponentRenderer.prototype, "isProceedOnErrorEnabled", {
        get: function () {
            return this._isProceedOnErrorEnabled;
        },
        set: function (a) {
            this._isProceedOnErrorEnabled = a;
        },
        enumerable: true,
        configurable: true
    });
    ComponentRenderer.prototype.g = function () {
        return (new ComponentRendererAdapter());
    };
    ComponentRenderer.prototype.toJson = function (a) {
        var e_1, _a, e_2, _b;
        var b = new DescriptionSerializerBuilder();
        var c = new DescriptionSerializer();
        b.f("{");
        b.i();
        b.f("\"descriptions\": {");
        b.i();
        var d = true;
        try {
            for (var _c = tslib_1.__values(fromEnum(this.ao.keys)), _d = _c.next(); !_d.done; _d = _c.next()) {
                var e = _d.value;
                if (d) {
                    d = false;
                }
                else {
                    b.f(",");
                }
                var f = e;
                var g = this.ao.item(e);
                var h = "root";
                h = a(f);
                if (stringIsNullOrEmpty(h)) {
                    h = "root";
                }
                b.e("\"" + h + "\"");
                b.e(": ");
                c.t(this.context, g, b);
            }
        }
        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;
            }
        }
        b.f("");
        b.h();
        b.e("}");
        if (this.ay.count > 0) {
            b.e(",");
        }
        b.f("");
        if (this.ay.count > 0) {
            d = true;
            b.f("refs: {");
            b.i();
            try {
                for (var _e = tslib_1.__values(fromEnum(this.ay.keys)), _f = _e.next(); !_f.done; _f = _e.next()) {
                    var i = _f.value;
                    if (!this.m(i, this.ay.item(i))) {
                        continue;
                    }
                    if (d) {
                        d = false;
                    }
                    else {
                        b.f(",");
                    }
                    this.c8(b, i, this.ay.item(i));
                }
            }
            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;
                }
            }
            b.f("");
            b.h();
            b.f("}");
        }
        b.h();
        b.f("}");
        return b.toString();
    };
    ComponentRenderer.prototype.c8 = function (a, b, c) {
        a.e("\"" + b + "\": ");
        this.c9(a, c);
    };
    ComponentRenderer.prototype.c9 = function (a, b) {
        if (this.u(b)) {
            if (typeof b === 'string') {
                a.e(b == null ? "null" : "\"" + b.toString() + "\"");
            }
            else if (typeof b === 'number') {
                a.e(b == null ? "null" : b.toString());
            }
            else if (typeof b === 'number') {
                a.e(b == null ? "null" : b.toString());
            }
            else if (typeof b === 'number') {
                a.e(b == null ? "null" : b.toString());
            }
            else if (typeof b === 'number') {
                a.e(b == null ? "null" : b.toString());
            }
            else if (typeof b === 'number') {
                a.e(b == null ? "null" : b.toString());
            }
            else if (typeof b === 'number') {
                a.e(b == null ? "null" : b.toString());
            }
            else if (typeof b === 'number') {
                a.e(b == null ? "null" : b.toString());
            }
            else if (typeCast(Date_$type, b) !== null) {
                var v_ = b;
                a.e("\"" + (v_.toJSON()) + "\"");
            }
            else if (typeCast(Boolean_$type, b) !== null) {
                a.e(b == null ? "null" : b.toString().toLowerCase());
            }
            else {
                a.e("null");
            }
        }
        else {
            if (b == null) {
                a.e("null");
                return;
            }
            if (this.s(b)) {
                a.f("[");
                a.i();
                var c = new DataSourceLocalDataProvider();
                c.dataSource = b;
                for (var d = 0; d < c.actualCount; d++) {
                    if (d > 0) {
                        a.f(",");
                    }
                    this.c7(a, c, d);
                }
                a.f("");
                a.h();
                a.e("]");
            }
            else {
                var e = [b];
                var f = new DataSourceLocalDataProvider();
                f.dataSource = e;
                this.c7(a, f, 0);
            }
        }
    };
    ComponentRenderer.prototype.u = function (a) {
        if (typeof a === 'string') {
            return true;
        }
        if (typeof a === 'number' || typeof a === 'number' || typeof a === 'number' || typeof a === 'number' || typeof a === 'number' || typeof a === 'number' || typeof a === 'number') {
            return true;
        }
        if (typeCast(Date_$type, a) !== null) {
            return true;
        }
        if (typeCast(Boolean_$type, a) !== null) {
            return true;
        }
        return false;
    };
    ComponentRenderer.prototype.s = function (a) {
        if (typeCast(Array_$type, a) !== null) {
            return true;
        }
        if (typeCast(IEnumerable_$type, a) !== null) {
            return true;
        }
        return false;
    };
    ComponentRenderer.prototype.c7 = function (a, b, c) {
        a.f("{");
        a.i();
        var d = b.actualSchema;
        for (var e = 0; e < d.propertyNames.length; e++) {
            if (e > 0) {
                a.f(",");
            }
            var f = d.propertyNames[e];
            if (stringStartsWith(f, "[")) {
                f = f.substr(1, f.length - 2);
            }
            a.e("\"" + f + "\"");
            a.e(": ");
            var g = b.getItemValue(b.getItemAtIndex(c), d.propertyNames[e]);
            switch (d.propertyTypes[e]) {
                case 0:
                    a.e(g == null ? "null" : "\"" + g.toString() + "\"");
                    break;
                case 2:
                    a.e(g == null ? "null" : "\"" + g.toString() + "\"");
                    break;
                case 10:
                case 6:
                case 5:
                case 1:
                case 3:
                case 4:
                case 7:
                    a.e(g == null ? "null" : g.toString());
                    break;
                case 8:
                    var v_ = g;
                    a.e("\"" + (v_.toJSON()) + "\"");
                    break;
                case 11:
                    this.c9(a, g);
                    break;
            }
        }
        a.h();
        a.f("}");
    };
    ComponentRenderer.prototype.m = function (a, b) {
        if (b == null) {
            return true;
        }
        var v_ = b;
        if ((typeof v_ === 'function')) {
            return false;
        }
        return true;
    };
    ComponentRenderer.prototype.createObjectFromJson = function (a, b) {
        var c = new JsonDictionaryParser();
        var d = c.parse(a);
        var e = new DescriptionSerializer();
        var f = false;
        var g = e.d(this.context, d, f, null, false);
        if (g.result == null) {
            return null;
        }
        var h = DescriptionTreeBuilder.createTree(this.context, g.result);
        var i = this.av.item(b);
        if (h.c("Type")) {
            var j = h.a("Type").b;
            return this.bo(j, h, b, i, true, -1);
        }
        else {
            return this.bn(typeCast(JsonDictionaryObject.$, d));
        }
    };
    ComponentRenderer.prototype.loadJson = function (a, b) {
        this.cl(a, b, null, false, false, false);
    };
    ComponentRenderer.prototype.loadJsonOverlay = function (a, b, c) {
        this.cl(a, b, c, true, false, true);
    };
    ComponentRenderer.prototype.loadJsonDelta = function (a, b, c) {
        this.cl(a, b, null, true, c, false);
    };
    ComponentRenderer.prototype.ak = function () {
        return false;
    };
    ComponentRenderer.prototype.cl = function (a, b, c, d, e, f) {
        var g = new JsonDictionaryParser();
        var h = g.parse(a);
        var i = new DescriptionSerializer();
        i.h = this.isProceedOnErrorEnabled;
        i.g = this.ak();
        var j = null;
        if (typeCast(JsonDictionaryObject.$, h) !== null) {
            var k = h;
            if (k.g("descriptions")) {
                var l = k.item("descriptions");
                if (typeCast(JsonDictionaryObject.$, l) !== null) {
                    var m = l;
                    var n = m.e();
                    for (var o = 0; o < n.length; o++) {
                        var p = n[o];
                        var q = m.item(p);
                        var r = b(p);
                        if (r == null) {
                            continue;
                        }
                        j = r;
                        var s = false;
                        var t = this.a4();
                        if (t != null) {
                            s = true;
                        }
                        var u = null;
                        if (this.isProceedOnErrorEnabled) {
                            try {
                                u = i.d(this.context, q, s, t, false);
                            }
                            catch (v) {
                                return;
                            }
                        }
                        else {
                            u = i.d(this.context, q, s, t, false);
                        }
                        if (u.result == null) {
                            continue;
                        }
                        if (f) {
                            if (!this.az.containsKey(r)) {
                                var w = null;
                                if (this.isProceedOnErrorEnabled) {
                                    try {
                                        w = i.d(this.context, q, s, t, true);
                                    }
                                    catch (x) {
                                        return;
                                    }
                                }
                                else {
                                    w = i.d(this.context, q, s, t, true);
                                }
                                this.c4(w.result, r, d, true, false);
                                var y = c(p);
                                var z = this.az.item(r);
                                this.ch(this.ao.item(r), y, z, r);
                            }
                        }
                        this.c4(u.result, r, d, e, false);
                    }
                }
            }
            if (k.g("refs") && j != null) {
                var aa = k.item("refs");
                var ab = this.aa(aa);
                if (!ab && typeCast(JsonDictionaryObject.$, aa) !== null) {
                    var ac = aa;
                    var ad = ac.e();
                    for (var ae = 0; ae < ad.length; ae++) {
                        var af = ad[ae];
                        var ag = ac.item(af);
                        if (typeCast(JsonDictionaryValue.$, ag) !== null) {
                            var ah = ag;
                            this.provideRefValue(j, af, ah.value);
                        }
                        else if (typeCast(JsonDictionaryArray.$, ag) !== null) {
                            var ai = ag;
                            var aj = this.a(ai);
                            this.provideRefValue(j, af, aj);
                        }
                        else {
                            var ak = this.bn(ag);
                            this.provideRefValue(j, af, ak);
                        }
                    }
                }
            }
            if (k.g("modules") && j != null) {
                var al = k.item("modules");
                this.z(al);
            }
            if (k.g("strings") && j != null) {
                var am = k.item("strings");
                this.ae(am);
            }
        }
    };
    ComponentRenderer.prototype.provideRefValueFromJson = function (a, b, c) {
        var d = b;
        var e = new JsonDictionaryParser();
        var f = e.parse(c);
        if (typeCast(JsonDictionaryValue.$, f) !== null) {
            var g = f;
            this.provideRefValue(a, d, g.value);
        }
        else if (typeCast(JsonDictionaryArray.$, f) !== null) {
            var h = f;
            var i = this.a(h);
            this.provideRefValue(a, d, i);
        }
        else {
            var j = this.bn(f);
            this.provideRefValue(a, d, j);
        }
    };
    ComponentRenderer.prototype.a4 = function () {
        return null;
    };
    ComponentRenderer.prototype.aa = function (a) {
        return false;
    };
    ComponentRenderer.prototype.z = function (a) {
        return false;
    };
    ComponentRenderer.prototype.ae = function (a) {
        return false;
    };
    ComponentRenderer.prototype.b0 = function (a, b, c) {
        var d = a;
        if (c != null) {
            d = c.g(b);
        }
        else {
            if (TypeDescriptionMetadata.shouldCamelize(b)) {
                d = TypeDescriptionMetadata.camelize(d);
            }
        }
        if (stringEndsWith(d, "Ref")) {
            d = d.substr(0, d.length - ("Ref").length);
        }
        return d;
    };
    ComponentRenderer.prototype.ch = function (a, b, c, d) {
        var e_3, _a;
        if (!c.b(b)) {
            c.k(d, this.ao.item(d).g, b, this.ao.item(d), runOn(this, this.cr), -1);
        }
        try {
            for (var _b = tslib_1.__values(fromEnum(a.f())), _c = _b.next(); !_c.done; _c = _b.next()) {
                var e = _c.value;
                this.ci(this.b0(e.c, ComponentRenderer.platform, e.a), e.b, b, c, d, a.g);
            }
        }
        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;
            }
        }
    };
    ComponentRenderer.prototype.ci = function (a, b, c, d, e, f) {
        var e_4, _a;
        var _this = this;
        if (typeCast(DescriptionTreeNode.$, b) !== null) {
            var g = b;
            var h = this.f.getPropertyValue(c, a);
            if (!d.b(h) && !d.a(g.g)) {
                d.k(e, g.g, h, g, runOn(this, this.cr), f);
            }
            try {
                for (var _b = tslib_1.__values(fromEnum(g.f())), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var i = _c.value;
                    this.ci(a + "." + this.b0(i.c, ComponentRenderer.platform, i.a), i.b, c, d, e, g.g);
                }
            }
            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;
                }
            }
        }
        if (typeCast(Array_$type, b) !== null) {
            var j_1 = new Dictionary$2(Number_$type, DescriptionTreeNode.$, 0);
            var k_1 = 0;
            var l = b.length;
            var o = b;
            for (var n = 0; n < o.length; n++) {
                var m = o[n];
                if (typeCast(DescriptionTreeNode.$, m) !== null) {
                    var p = m;
                    j_1.item(k_1, p);
                }
                k_1++;
            }
            var q = this.f.getPropertyValue(c, a);
            k_1 = 0;
            this.f.forPropertyValueItem(c, a, function (r) {
                var e_5, _a;
                if (j_1.containsKey(k_1)) {
                    var s = j_1.item(k_1);
                    if (!d.b(r) && !d.a(s.g)) {
                        d.k(e, s.g, r, s, runOn(_this, _this.cr), f);
                    }
                    try {
                        for (var _b = tslib_1.__values(fromEnum(s.f())), _c = _b.next(); !_c.done; _c = _b.next()) {
                            var t = _c.value;
                            _this.ci(a + "." + t.c, t.b, c, d, e, s.g);
                        }
                    }
                    catch (e_5_1) {
                        e_5 = { error: e_5_1 };
                    }
                    finally {
                        try {
                            if (_c && !_c.done && (_a = _b.return))
                                _a.call(_b);
                        }
                        finally {
                            if (e_5)
                                throw e_5.error;
                        }
                    }
                }
                k_1++;
            });
            if (l > 0 && k_1 == 0) {
                var r_1 = this.b4(a);
                this.f.forPropertyValueItem(c, r_1, function (s) {
                    var e_6, _a;
                    if (j_1.containsKey(k_1)) {
                        var t = j_1.item(k_1);
                        if (!d.b(s) && !d.a(t.g)) {
                            d.k(e, t.g, s, t, runOn(_this, _this.cr), f);
                        }
                        try {
                            for (var _b = tslib_1.__values(fromEnum(t.f())), _c = _b.next(); !_c.done; _c = _b.next()) {
                                var u = _c.value;
                                _this.ci(r_1 + "." + u.c, u.b, c, d, e, t.g);
                            }
                        }
                        catch (e_6_1) {
                            e_6 = { error: e_6_1 };
                        }
                        finally {
                            try {
                                if (_c && !_c.done && (_a = _b.return))
                                    _a.call(_b);
                            }
                            finally {
                                if (e_6)
                                    throw e_6.error;
                            }
                        }
                    }
                    k_1++;
                });
            }
        }
    };
    ComponentRenderer.prototype.b4 = function (a) {
        var b = a.lastIndexOf('.');
        var c = null;
        var d = a;
        if (b > 0) {
            c = a.substr(0, b);
            d = a.substr(b + 1);
        }
        d = "actual" + this.b2(d);
        if (c != null) {
            return c + "." + d;
        }
        return d;
    };
    ComponentRenderer.prototype.b2 = function (a) {
        return a.substr(0, 1).toUpperCase() + a.substr(1);
    };
    ComponentRenderer.prototype.a = function (a) {
        var b = new Array(a.items.length);
        for (var c = 0; c < a.items.length; c++) {
            var d = this.bn(a.items[c]);
            b[c] = d;
        }
        return b;
    };
    ComponentRenderer.prototype.bn = function (a) {
        if (a == null) {
            return null;
        }
        var b = {};
        var dict_ = b;
        var c = a.e();
        for (var d = 0; d < c.length; d++) {
            var key_ = c[d];
            if (typeCast(JsonDictionaryObject.$, a.item(key_)) !== null) {
                var val_ = this.bn(a.item(key_));
                dict_[key_] = val_;
            }
            else if (typeCast(JsonDictionaryArray.$, a.item(key_)) !== null) {
                var val_ = this.a(a.item(key_));
                dict_[key_] = val_;
            }
            else {
                var val_ = a.item(key_).value;
                dict_[key_] = val_;
            }
        }
        return dict_;
    };
    Object.defineProperty(ComponentRenderer.prototype, "az", {
        get: function () {
            return this.av;
        },
        enumerable: true,
        configurable: true
    });
    ComponentRenderer.prototype.cleanup = function (a, b) {
        this.c4(null, a, false, false, b);
    };
    ComponentRenderer.prototype.render = function (a, b) {
        this.c4(a, b, false, false, false);
    };
    ComponentRenderer.prototype.c4 = function (a, b, c, d, e) {
        var _this = this;
        if (!this.av.containsKey(b)) {
            this.av.item(b, new ContainerState());
            this.av.item(b).i = b;
        }
        this.aq.item(b, a);
        this.ar.item(b, c);
        this.as.item(b, d);
        this.ap.item(b, e);
        this.cn(b, function () { return _this.c2(b); });
    };
    ComponentRenderer.prototype.cn = function (a, b) {
        this.f.onUIThread(a, b);
    };
    ComponentRenderer.prototype.c2 = function (a) {
        var e_7, _a, e_8, _b, e_9, _c, e_10, _d;
        var _this = this;
        if (this.aq.containsKey(a)) {
            var b = this.ar.containsKey(a) ? this.ar.item(a) : false;
            var c = this.as.containsKey(a) ? this.as.item(a) : false;
            var d = this.aq.item(a);
            this.aq.removeItem(a);
            var e = DescriptionTreeBuilder.createTree(this.context, d);
            var f = null;
            if (this.ao.containsKey(a)) {
                f = this.ao.item(a);
            }
            var g = DescriptionTreeReconciler.c(f, e, b);
            if (!c && b) {
                e = f.b();
                DescriptionTreeReconciler.a(f, g);
                var h = f;
                f = e;
                e = h;
                g = DescriptionTreeReconciler.c(f, e, false);
            }
            if (c) {
                var i = DescriptionTreeReconciler.a(f, g);
                if (!this.av.containsKey(a)) {
                    this.av.addItem(a, ((function () {
                        var $ret = new ContainerState();
                        $ret.i = a;
                        return $ret;
                    })()));
                }
                var j_2 = this.av.item(a);
                if (i.a.count > 0) {
                    try {
                        for (var _e = tslib_1.__values(fromEnum(i.a)), _f = _e.next(); !_f.done; _f = _e.next()) {
                            var k = _f.value;
                            if (j_2.a(k)) {
                                var l = j_2.j(k);
                                this.cf(a, l, j_2);
                            }
                        }
                    }
                    catch (e_7_1) {
                        e_7 = { error: e_7_1 };
                    }
                    finally {
                        try {
                            if (_f && !_f.done && (_a = _e.return))
                                _a.call(_e);
                        }
                        finally {
                            if (e_7)
                                throw e_7.error;
                        }
                    }
                }
                if (i.c.count > 0) {
                    try {
                        for (var _g = tslib_1.__values(fromEnum(i.c)), _h = _g.next(); !_h.done; _h = _g.next()) {
                            var m = _h.value;
                            var n = this.bt(a, j_2, m);
                            var o = this.f.getPropertyValue(n, m.j);
                            if (o != null) {
                                if (!j_2.b(o)) {
                                    var p = m.g;
                                    if (typeCast(DescriptionTreeNode.$, p) !== null) {
                                        var q = p.g;
                                        j_2.k(a, q, o, p, runOn(this, this.cr), m.c.g);
                                    }
                                }
                            }
                        }
                    }
                    catch (e_8_1) {
                        e_8 = { error: e_8_1 };
                    }
                    finally {
                        try {
                            if (_h && !_h.done && (_b = _g.return))
                                _b.call(_g);
                        }
                        finally {
                            if (e_8)
                                throw e_8.error;
                        }
                    }
                }
                if (i.d.count > 0) {
                    try {
                        for (var _j = tslib_1.__values(fromEnum(i.d)), _k = _j.next(); !_k.done; _k = _j.next()) {
                            var r = _k.value;
                            var s = r.g;
                            if (s != null) {
                                if (!j_2.b(s)) {
                                    var t = r.g;
                                    if (typeCast(DescriptionTreeNode.$, t) !== null) {
                                        var u = t.g;
                                        this.ao.item(a, t);
                                    }
                                }
                            }
                        }
                    }
                    catch (e_9_1) {
                        e_9 = { error: e_9_1 };
                    }
                    finally {
                        try {
                            if (_k && !_k.done && (_c = _j.return))
                                _c.call(_j);
                        }
                        finally {
                            if (e_9)
                                throw e_9.error;
                        }
                    }
                }
                if (i.b.count > 0) {
                    var _loop_1 = function (v) {
                        var w = v.c.a(v.j).b;
                        if (w == null) {
                            return "continue";
                        }
                        var x = new Dictionary$2(String_$type, DescriptionTreeNode.$, 0);
                        for (var y = 0; y < w.length; y++) {
                            var z = w[y];
                            if (typeCast(DescriptionTreeNode.$, z) !== null) {
                                var aa = z;
                                if (aa.c("Name")) {
                                    x.item(aa.a("Name").b, aa);
                                }
                            }
                        }
                        if (x.count == 0) {
                            return "continue";
                        }
                        var ab = this_1.bt(a, j_2, v);
                        var ac = this_1.f.getPropertyValue(ab, v.j);
                        if (ac != null) {
                            var ad_1 = 0;
                            this_1.f.forPropertyValueItem(ab, v.j, function (ae) {
                                if (x.containsKey(_this.f.getPropertyValue(ae, "Name").toString())) {
                                    if (!j_2.b(ae)) {
                                        var af = x.item(_this.f.getPropertyValue(ae, "Name").toString());
                                        if (typeCast(DescriptionTreeNode.$, af) !== null) {
                                            var ag = af.g;
                                            j_2.k(a, ag, ae, af, runOn(_this, _this.cr), v.c.g);
                                        }
                                    }
                                }
                                ad_1++;
                            });
                        }
                    };
                    var this_1 = this;
                    try {
                        for (var _l = tslib_1.__values(fromEnum(i.b)), _m = _l.next(); !_m.done; _m = _l.next()) {
                            var v = _m.value;
                            _loop_1(v);
                        }
                    }
                    catch (e_10_1) {
                        e_10 = { error: e_10_1 };
                    }
                    finally {
                        try {
                            if (_m && !_m.done && (_d = _l.return))
                                _d.call(_l);
                        }
                        finally {
                            if (e_10)
                                throw e_10.error;
                        }
                    }
                }
            }
            else {
                this.ao.item(a, e);
            }
            if (!c) {
                this.c3(a, g);
            }
            if (this.ap.item(a)) {
                this.c0(a);
                if (this.av.containsKey(a)) {
                    this.av.removeItem(a);
                }
            }
        }
    };
    ComponentRenderer.prototype.provideRefValue = function (a, b, c) {
        var _this = this;
        this.cn(a, function () {
            if (!_this.av.containsKey(a)) {
                _this.av.addItem(a, ((function () {
                    var $ret = new ContainerState();
                    $ret.i = a;
                    return $ret;
                })()));
            }
            var d = _this.av.item(a);
            _this.cr(a, b, c, true);
        });
    };
    ComponentRenderer.prototype.removeRefValue = function (a, b) {
        var _this = this;
        this.cn(a, function () {
            if (!_this.av.containsKey(a)) {
                _this.av.addItem(a, ((function () {
                    var $ret = new ContainerState();
                    $ret.i = a;
                    return $ret;
                })()));
            }
            var c = _this.av.item(a);
            _this.removeRefValueCore(a, b, true);
        });
    };
    ComponentRenderer.prototype.c0 = function (a) {
        var e_11, _a;
        var b = this.av.item(a);
        var c = new List$1(String_$type, 0);
        try {
            for (var _b = tslib_1.__values(fromEnum(this.au.keys)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var d = _c.value;
                if (this.au.item(d).c == 0) {
                    c.add(d);
                }
            }
        }
        catch (e_11_1) {
            e_11 = { error: e_11_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_11)
                    throw e_11.error;
            }
        }
        for (var e = 0; e < c.count; e++) {
            var f = this.shouldNamespaceSystemRefValues;
            this.shouldNamespaceSystemRefValues = false;
            this.removeRefValueCore(a, c._inner[e], this.ay.containsKey(c._inner[e]));
            this.shouldNamespaceSystemRefValues = f;
        }
    };
    ComponentRenderer.prototype.clearRefValues = function (a) {
        var _this = this;
        this.cn(a, function () {
            if (!_this.av.containsKey(a)) {
                _this.av.addItem(a, ((function () {
                    var $ret = new ContainerState();
                    $ret.i = a;
                    return $ret;
                })()));
            }
            var b = _this.av.item(a);
            _this.clearUserRefValues();
        });
    };
    ComponentRenderer.prototype.c3 = function (a, b) {
        var c = this.av.item(a);
        this.co(a, c, b);
    };
    ComponentRenderer.prototype.c6 = function (a, b) {
        if (this.isProceedOnErrorEnabled) {
            try {
                this.cg(a, b, true);
            }
            catch (c) {
                this.an.item(a, false);
            }
        }
        else {
            this.cg(a, b, true);
        }
    };
    ComponentRenderer.prototype.dc = function (a, b) {
        if (this.isProceedOnErrorEnabled) {
            try {
                this.cg(a, b, false);
            }
            catch (c) {
                this.an.item(a, false);
            }
        }
        else {
            this.cg(a, b, false);
        }
    };
    ComponentRenderer.prototype.cg = function (a, b, c) {
        if (!c) {
            if (this.an.containsKey(a) && this.an.item(a)) {
                return;
            }
        }
        this.an.item(a, true);
        var d = true;
        while (d && this.at.item(a).count > 0) {
            while (this.at.item(a).count > 0 && this.at.item(a).c().count < 1) {
                this.at.item(a).b();
            }
            if (this.at.item(a).count < 1) {
                break;
            }
            var e = this.at.item(a).c();
            while (e.count > 0) {
                var f = e.b();
                d = this.w(a, b, f);
                if (!d) {
                    break;
                }
            }
        }
        if (d) {
            this.an.item(a, false);
        }
    };
    ComponentRenderer.prototype.co = function (a, b, c) {
        var d = new Queue$1(DescriptionTreeAction.$);
        for (var e = 0; e < c.count; e++) {
            d.g(c._inner[e]);
        }
        if (!this.at.containsKey(a)) {
            this.at.addItem(a, new Queue$1(Queue$1.$.specialize(DescriptionTreeAction.$)));
        }
        this.at.item(a).g(d);
        this.dc(a, b);
    };
    ComponentRenderer.prototype.cp = function (a, b, c) {
        for (var d = 0; d < c.count; d++) {
            this.w(a, b, c._inner[d]);
        }
    };
    ComponentRenderer.prototype.w = function (a, b, c) {
        switch (c.a) {
            case 5: return this.x(a, b, c);
            case 2: return this.y(a, b, c);
            case 4: return this.ab(a, b, c);
            case 3: return this.ac(a, b, c);
            case 1: return this.ad(a, b, c);
            case 0: return this.af(a, b, c);
        }
        return true;
    };
    ComponentRenderer.prototype.af = function (a, b, c) {
        var d = this.bt(a, b, c);
        this.am(a, b, c, d);
        return true;
    };
    ComponentRenderer.prototype.am = function (a, b, c, d) {
        var e = this.bq(c, a, b);
        e = this.h.transform(ComponentRenderer.platform, e, c);
        var f = false;
        if (this.a2 != null && this.a2.count > 0) {
            for (var g = 0; g < this.a2.count; g++) {
                var h = this.a2._inner[g];
                var i = this.b1(a, c);
                if (h(i, d, e)) {
                    f = true;
                }
            }
        }
        if (c.j == "Type" || c.j == "type") {
            f = true;
        }
        if (f) {
            return true;
        }
        if (c.d != null && c.d.knownType == 9) {
            this.aj(a, b, c.i(ComponentRenderer.platform), c.d, e, d);
        }
        else {
            this.da(a, b, c.i(ComponentRenderer.platform), c.d, e, c.h, d);
        }
        return true;
    };
    ComponentRenderer.prototype.b1 = function (a, b) {
        var c = b.c;
        var d = "";
        if (c != this.ao.item(a)) {
            var e = this.bz(a, c);
            d = e;
        }
        if (d.length > 0) {
            d += ".";
        }
        d += b.j;
        return d;
    };
    ComponentRenderer.prototype.bz = function (a, b) {
        if (b == null) {
            return "";
        }
        var c = this.b5("", this.ao.item(a), b);
        if (c.c) {
            return c.d;
        }
        return "";
    };
    ComponentRenderer.prototype.b5 = function (a, b, c) {
        if (b == c) {
            return new Tuple$2(Boolean_$type, String_$type, true, a);
        }
        if (a.length > 0) {
            a += ".";
        }
        var d = b.f();
        for (var e = 0; e < d.count; e++) {
            var f = d._inner[e];
            if (typeCast(DescriptionTreeNode.$, f.b) !== null) {
                if (f.b.g == c.g) {
                    a += f.c;
                    return new Tuple$2(Boolean_$type, String_$type, true, a);
                }
                else {
                    var g = a + f.c;
                    var h = this.b5(g, f.b, c);
                    if (h.c) {
                        return h;
                    }
                }
            }
            if (f.a != null && f.a.knownType == 9) {
                var i = f.b;
                for (var j = 0; j < i.length; j++) {
                    if (typeCast(DescriptionTreeNode.$, i[j]) !== null) {
                        var k = i[j];
                        if (k.g == c.g) {
                            a += f.c + "[" + j + "]";
                            return new Tuple$2(Boolean_$type, String_$type, true, a);
                        }
                        else {
                            var l = a + f.c + "[" + j + "]";
                            var m = this.b5(l, k, c);
                            if (m.c) {
                                return m;
                            }
                        }
                    }
                }
            }
        }
        return new Tuple$2(Boolean_$type, String_$type, false, a);
    };
    ComponentRenderer.prototype.aj = function (a, b, c, d, e, f) {
        var e_12, _a;
        if (this.ax.containsKey(c)) {
            try {
                for (var _b = tslib_1.__values(fromEnum(this.ax.item(c))), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var g = _c.value;
                    g(c, f, e);
                }
            }
            catch (e_12_1) {
                e_12 = { error: e_12_1 };
            }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return))
                        _a.call(_b);
                }
                finally {
                    if (e_12)
                        throw e_12.error;
                }
            }
        }
        this.f.setOrUpdateCollectionOnTarget(a, c, d, this.context, f, e);
        return true;
    };
    ComponentRenderer.prototype.bq = function (a, b, c) {
        if (a.d == null) {
            return a.g;
        }
        switch (a.d.knownType) {
            case 10: return this.a6(a, b, c);
            case 7: return this.a7(a);
            case 4: return this.a8(a);
            case 6: return this.a9(a);
            case 9: return this.a6(a, b, c);
            case 5: return this.ba(a);
            case 16: return this.bb(a);
            case 20: return this.bu(a, c);
            case 15: return null;
            case 3: return this.bc(a);
            case 19: return this.bv(a, c);
            case 8: return this.be(a, b, c);
            case 13: return null;
            case 18: return this.bw(a, c);
            case 1: return this.bf(a);
            case 11: return this.bg(a);
            case 14: return this.bh(a);
            case 12: return this.bi(a);
            case 2: return this.bj(a);
            case 21: return this.bk(a);
            case 17: return this.bl(a, b, c);
            case 0: return null;
        }
        return null;
    };
    ComponentRenderer.prototype.bl = function (a, b, c) {
        var d = this.bm(a.g, a, b, c);
        return d;
    };
    ComponentRenderer.prototype.bm = function (a, b, c, d) {
        if (typeof a === 'string') {
            if (stringStartsWith(a, "@d:")) {
                var v_ = a.substr(3);
                a = new Date(v_);
            }
        }
        if (typeCast(Array_$type, a) !== null) {
            var e = a;
            var f = new Array(e.length);
            for (var g = 0; g < e.length; g++) {
                var h = this.bm(e[g], b, c, d);
                f[g] = h;
            }
            a = f;
        }
        if (typeCast(DescriptionTreeNode.$, a) !== null) {
            var i = a;
            if (i.i == "EmbeddedRef") {
                return this.bo(i.i, a, c, d, false, b.c.g);
            }
        }
        return a;
    };
    ComponentRenderer.prototype.bk = function (a) {
        return a.g;
    };
    ComponentRenderer.prototype.bj = function (a) {
        return a.g != null ? a.g.toString() : null;
    };
    ComponentRenderer.prototype.bi = function (a) {
        var b = a.g;
        var width_ = b.width;
        var height_ = b.height;
        var c = { width: width_, height: height_ };
        return c;
    };
    ComponentRenderer.prototype.bh = function (a) {
        var b = a.g;
        var top_ = b.top;
        var left_ = b.left;
        var width_ = b.width;
        var height_ = b.height;
        var c = { left: left_, top: top_, width: width_, height: height_ };
        return c;
    };
    ComponentRenderer.prototype.bg = function (a) {
        var b = a.g;
        var x_ = b.x;
        var y_ = b.y;
        var c = { x: x_, y: y_ };
        return c;
    };
    ComponentRenderer.prototype.bf = function (a) {
        if (a.g == null) {
            if (a.d != null && (a.d.specificType == "double" || a.d.specificType == "float")) {
                return NaN;
            }
            return 0;
        }
        return a.g;
    };
    ComponentRenderer.prototype.d = function (a, b) {
        if (this.au.containsKey(a)) {
            var c = this.au.item(a);
            return c;
        }
        var d = new DescriptionRef(a);
        this.au.addItem(a, d);
        return d;
    };
    ComponentRenderer.prototype.bw = function (a, b) {
        return a.g == null ? null : this.d(a.g, b);
    };
    ComponentRenderer.prototype.be = function (a, b, c) {
        var d = a.d.specificType;
        if (d == null) {
            d = a.d.specificExternalType;
        }
        if (typeCast(DescriptionTreeNode.$, a.g) !== null) {
            var e = a.g;
            if (e.c("Type")) {
                d = e.a("Type").b;
            }
        }
        var f = this.bo(d, a.g, b, c, false, a.c.g);
        return f;
    };
    ComponentRenderer.prototype.bv = function (a, b) {
        return a.g == null ? null : this.d(a.g, b);
    };
    ComponentRenderer.prototype.bc = function (a) {
        if (typeof a.g === 'string') {
            var v_ = a.g;
            a.g = new Date(v_);
        }
        return a.g;
    };
    ComponentRenderer.prototype.bu = function (a, b) {
        return a.g == null ? null : this.d(a.g, b);
    };
    ComponentRenderer.prototype.by = function (a) {
        return a;
    };
    ComponentRenderer.prototype.bb = function (a) {
        var b = a.g;
        if (b == null) {
            return null;
        }
        var c = new Array(b.length);
        for (var d = 0; d < b.length; d++) {
            c[d] = this.by(b[d]);
        }
        return c;
    };
    ComponentRenderer.prototype.ba = function (a) {
        return this.by(a.g);
    };
    ComponentRenderer.prototype.a9 = function (a) {
        var b = a.g;
        if (b == null) {
            return null;
        }
        var c = new Array(b.length);
        for (var d = 0; d < b.length; d++) {
            c[d] = this.bx(b[d]);
        }
        return c;
    };
    ComponentRenderer.prototype.bx = function (a) {
        return a;
    };
    ComponentRenderer.prototype.a8 = function (a) {
        return this.bx(a.g);
    };
    ComponentRenderer.prototype.a7 = function (a) {
        return a.g;
    };
    ComponentRenderer.prototype.addTargetPropertyUpdatingListener = function (a) {
        this.a2.add(a);
    };
    ComponentRenderer.prototype.removeTargetPropertyUpdatingListener = function (a) {
        this.a2.remove(a);
    };
    ComponentRenderer.prototype.addPropertyUpdatingListener = function (a, b) {
        if (!this.ax.containsKey(a)) {
            this.ax.addItem(a, new List$1(Delegate_$type, 0));
        }
        this.ax.item(a).add(b);
    };
    ComponentRenderer.prototype.addReferenceLookupListener = function (a) {
        this.a0.add(a);
    };
    ComponentRenderer.prototype.removeReferenceLookupListener = function (a) {
        this.a0.remove(a);
    };
    ComponentRenderer.prototype.removePropertyUpdatingListener = function (a, b) {
        if (this.ax.containsKey(a)) {
            this.ax.item(a).remove(b);
            if (this.ax.item(a).count == 0) {
                this.ax.removeItem(a);
            }
        }
    };
    ComponentRenderer.prototype.addNamespaceLookupListener = function (a) {
        this.a1.add(a);
    };
    ComponentRenderer.prototype.removeNamespaceLookupListener = function (a) {
        this.a1.remove(a);
    };
    ComponentRenderer.prototype.a6 = function (a, b, c) {
        if (a.g == null) {
            return null;
        }
        var d = a.g;
        var e = new List$1(Base.$, 0);
        var f = a.d.specificType;
        if (f == null) {
            f = a.d.specificExternalType;
        }
        if (a.d.knownType == 9) {
            f = a.d.collectionElementType;
            if (f == null) {
                f = a.d.specificExternalType;
            }
        }
        for (var g = 0; g < d.length; g++) {
            var h = f;
            if (typeCast(DescriptionTreeNode.$, d[g]) !== null) {
                var i = d[g];
                if (i.c("Type")) {
                    h = i.a("Type").b;
                }
            }
            var j = this.bo(h, d[g], b, c, false, a.c.g);
            e.add1(j);
        }
        return e.toArray();
    };
    ComponentRenderer.prototype.da = function (a, b, c, d, e, f, g) {
        var _this = this;
        if (typeCast(DescriptionRef.$, e) !== null) {
            var h = e;
            var i = false;
            if (f != null && typeof f === 'string') {
                if (this.p(f)) {
                    var j = this.e(f);
                    if (Base.equalsStatic(j, e)) {
                        i = true;
                    }
                    else {
                        j.j(a, g, c);
                    }
                }
            }
            if (this.q(e)) {
                var k = e;
                if (k.e != null && k.e.length > 0 && this.aw.containsKey(k.e)) {
                    k.a = true;
                }
                e = this.bs(e);
                this.db(g, c, d, e, f, k);
            }
            else {
                this.f.onPendingRef(g, c, d, e);
            }
            var l = null;
            l = function (m, n) {
                var o = m;
                if (o.e != null && o.e.length > 0 && _this.aw.containsKey(o.e)) {
                    o.a = true;
                }
                var p = _this.bs(m);
                _this.db(g, c, d, p, f, o);
            };
            if (!i) {
                h.g(a, g, c, l);
            }
            return;
        }
        this.db(g, c, d, e, f, null);
    };
    ComponentRenderer.prototype.hasUserRef = function (a) {
        return this.ay.containsKey(a);
    };
    Object.defineProperty(ComponentRenderer.prototype, "shouldNamespaceSystemRefValues", {
        get: function () {
            return this._shouldNamespaceSystemRefValues;
        },
        set: function (a) {
            this._shouldNamespaceSystemRefValues = a;
        },
        enumerable: true,
        configurable: true
    });
    ComponentRenderer.prototype.cr = function (a, b, c, d) {
        var e = null;
        if (d) {
            if (this.ay.containsKey(b)) {
                e = this.ay.item(b);
            }
            this.ay.item(b, c);
        }
        else {
            if (this.shouldNamespaceSystemRefValues) {
                var f = "";
                if (this.a1 != null && this.a1.count > 0) {
                    for (var g = 0; g < this.a1.count; g++) {
                        f = this.a1._inner[g](a);
                    }
                }
                if (!stringIsNullOrEmpty(f)) {
                    b = f + "/" + b;
                }
            }
            if (this.aw.containsKey(b)) {
                e = this.aw.item(b);
            }
            this.aw.item(b, c);
            if (this.au.containsKey(b)) {
                this.au.item(b).a = true;
            }
        }
        if (this.au.containsKey(b)) {
            this.au.item(b).f(e, c);
        }
    };
    ComponentRenderer.prototype.removeRefValueCore = function (a, b, c) {
        var d = null;
        if (c) {
            if (this.ay.containsKey(b)) {
                d = this.ay.item(b);
            }
            this.ay.removeItem(b);
        }
        else {
            if (this.shouldNamespaceSystemRefValues) {
                var e = "";
                if (this.a1 != null && this.a1.count > 0) {
                    for (var f = 0; f < this.a1.count; f++) {
                        e = this.a1._inner[f](a);
                    }
                }
                if (!stringIsNullOrEmpty(e)) {
                    b = e + "/" + b;
                }
            }
            if (this.aw.containsKey(b)) {
                d = this.aw.item(b);
            }
            this.aw.removeItem(b);
        }
        if (this.au.containsKey(b)) {
            this.au.item(b).f(d, this.bs(this.au.item(b)));
            if (this.au.item(b).c <= 0) {
                this.au.item(b).h();
                this.au.removeItem(b);
            }
        }
    };
    ComponentRenderer.prototype.clearUserRefValues = function () {
        var e_13, _a, e_14, _b;
        var a = new List$1(String_$type, 0);
        try {
            for (var _c = tslib_1.__values(fromEnum(this.ay.keys)), _d = _c.next(); !_d.done; _d = _c.next()) {
                var b = _d.value;
                a.add(b);
            }
        }
        catch (e_13_1) {
            e_13 = { error: e_13_1 };
        }
        finally {
            try {
                if (_d && !_d.done && (_a = _c.return))
                    _a.call(_c);
            }
            finally {
                if (e_13)
                    throw e_13.error;
            }
        }
        try {
            for (var _e = tslib_1.__values(fromEnum(a)), _f = _e.next(); !_f.done; _f = _e.next()) {
                var c = _f.value;
                this.removeRefValueCore(null, c, true);
            }
        }
        catch (e_14_1) {
            e_14 = { error: e_14_1 };
        }
        finally {
            try {
                if (_f && !_f.done && (_b = _e.return))
                    _b.call(_e);
            }
            finally {
                if (e_14)
                    throw e_14.error;
            }
        }
    };
    ComponentRenderer.prototype.q = function (a) {
        return this.ay.containsKey(a.e) || this.aw.containsKey(a.e);
    };
    ComponentRenderer.prototype.bs = function (a) {
        if (this.ay.containsKey(a.e)) {
            return this.ay.item(a.e);
        }
        if (this.aw.containsKey(a.e)) {
            return this.aw.item(a.e);
        }
        return null;
    };
    ComponentRenderer.prototype.p = function (a) {
        return this.au.containsKey(a);
    };
    ComponentRenderer.prototype.e = function (a) {
        return this.au.item(a);
    };
    ComponentRenderer.prototype.getMissingRefs = function () {
        var e_15, _a;
        var a = new List$1(String_$type, 0);
        try {
            for (var _b = tslib_1.__values(fromEnum(this.au.keys)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var b = _c.value;
                if (!this.q(this.au.item(b))) {
                    a.add(b);
                }
            }
        }
        catch (e_15_1) {
            e_15 = { error: e_15_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_15)
                    throw e_15.error;
            }
        }
        return a.toArray();
    };
    ComponentRenderer.prototype.bt = function (a, b, c) {
        return b.j(c.c.g);
    };
    ComponentRenderer.prototype.ad = function (a, b, c) {
        var d = this.bt(a, b, c);
        this.ai(a, b, c, d);
        return true;
    };
    ComponentRenderer.prototype.ai = function (a, b, c, d) {
        this.f.resetPropertyOnTarget(a, c.i(ComponentRenderer.platform), c.d, d);
        return true;
    };
    ComponentRenderer.prototype.ac = function (a, b, c) {
        if (c.c == null) {
            return this.ah(a, b, c);
        }
        else {
            var d = this.bt(a, b, c);
            this.c5(a, b, c, d);
        }
        return true;
    };
    ComponentRenderer.prototype.c5 = function (a, b, c, d) {
        var e = c.i(ComponentRenderer.platform);
        var f = c.d.collectionElementType;
        if (f == null) {
            f = c.d.specificExternalType;
        }
        var g = this.bo(f, c.g, a, b, false, c.c.g);
        this.f.replaceItemInCollection(e, c.d, d, c.e, g);
        if (c.h != null && typeCast(DescriptionTreeNode.$, c.h) !== null) {
            var h = c.h.g;
            if (h >= 0) {
                var i = b.j(h);
                if (i != null) {
                    this.cf(a, i, b);
                }
            }
        }
    };
    ComponentRenderer.prototype.ah = function (a, b, c) {
        var _this = this;
        var d = this.f.getRootObject(a);
        if (d != null) {
            this.cf(a, d, b);
        }
        if (!(typeCast(DescriptionTreeNode.$, c.g) !== null)) {
            throw new NotImplementedException(0);
        }
        var e = c.g;
        var f = false;
        this.f.replaceRootItem(a, e.i, this.context, function (g) {
            var h = _this.f.getRootObject(a);
            b.k(a, e.g, h, e, runOn(_this, _this.cr), -1);
            var i = _this.a3(e);
            _this.cp(a, b, i);
            f = true;
            if (g) {
                _this.c6(a, b);
            }
        });
        return f;
    };
    ComponentRenderer.prototype.cf = function (a, b, c) {
        var e_16, _a;
        var d = this.a5(a, b, c);
        try {
            for (var _b = tslib_1.__values(fromEnum(this.au.values)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var e = _c.value;
                e.i(b);
            }
        }
        catch (e_16_1) {
            e_16 = { error: e_16_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_16)
                    throw e_16.error;
            }
        }
        if (d != -1) {
            c.l(this, a, d, runOn(this, this.removeRefValueCore));
        }
        this.i.b(ComponentRenderer.platform, b);
    };
    ComponentRenderer.prototype.a5 = function (a, b, c) {
        return c.h(b);
    };
    ComponentRenderer.prototype.ab = function (a, b, c) {
        if (c.c == null) {
            return this.ag(a, b, c);
        }
        else {
            var d = this.bt(a, b, c);
            this.ct(a, b, c, d);
        }
        return true;
    };
    ComponentRenderer.prototype.ct = function (a, b, c, d) {
        var e = c.i(ComponentRenderer.platform);
        this.f.removeItemFromCollection(e, c.d, d, c.f);
        if (c.h != null && typeCast(DescriptionTreeNode.$, c.h) !== null) {
            var f = c.h.g;
            if (f >= 0) {
                var g = b.j(f);
                if (g != null) {
                    this.cf(a, g, b);
                }
            }
        }
    };
    ComponentRenderer.prototype.ag = function (a, b, c) {
        var _this = this;
        var d = this.f.getRootObject(a);
        if (d != null) {
            this.cf(a, d, b);
        }
        var e = false;
        this.f.removeRootItem(a, this.context, function (f) {
            e = true;
            if (f) {
                _this.c6(a, b);
            }
        });
        return e;
    };
    ComponentRenderer.prototype.y = function (a, b, c) {
        if (c.c == null) {
            return this.l(a, b, c);
        }
        else {
            var d = this.bt(a, b, c);
            this.b6(a, b, c, d);
        }
        return true;
    };
    ComponentRenderer.prototype.l = function (a, b, c) {
        var _this = this;
        if (!(typeCast(DescriptionTreeNode.$, c.g) !== null)) {
            throw new NotImplementedException(0);
        }
        var d = c.g;
        var e = false;
        this.f.replaceRootItem(a, d.i, this.context, function (f) {
            var g = _this.f.getRootObject(a);
            b.k(a, d.g, g, d, runOn(_this, _this.cr), -1);
            var h = _this.a3(d);
            _this.cp(a, b, h);
            e = true;
            if (f) {
                _this.c6(a, b);
            }
        });
        return e;
    };
    ComponentRenderer.prototype.b6 = function (a, b, c, d) {
        var e = c.i(ComponentRenderer.platform);
        var f = c.d.collectionElementType;
        if (typeCast(DescriptionTreeNode.$, c.g) !== null) {
            var g = c.g;
            if (g.c("Type")) {
                f = g.a("Type").b;
            }
        }
        if (f == null) {
            f = c.d.specificExternalType;
        }
        var h = this.bo(f, c.g, a, b, false, c.c.g);
        this.f.addItemToCollection(e, c.d, d, c.e, h);
    };
    ComponentRenderer.prototype.bo = function (a, b, c, d, e, f) {
        if (this.t(a)) {
            return b;
        }
        var g = null;
        if (b != null && typeCast(DescriptionTreeNode.$, b) !== null) {
            var h = b;
            if (h.c("Name")) {
                var i = h.a("Name").b;
                if (!stringIsNullOrEmpty(i)) {
                    if (this.shouldNamespaceSystemRefValues) {
                        var j = "";
                        if (this.a1 != null && this.a1.count > 0) {
                            for (var k = 0; k < this.a1.count; k++) {
                                j = this.a1._inner[k](c);
                            }
                        }
                        if (!stringIsNullOrEmpty(j)) {
                            i = j + "/" + i;
                        }
                    }
                    if (this.aw.containsKey(i)) {
                        var l = this.aw.item(i);
                        g = l;
                    }
                }
            }
            if (g == null) {
                g = this.context.p(a, c);
            }
        }
        else if (b != null) {
            g = this.context.p(a, c);
        }
        if (b == null) {
            return g;
        }
        if (typeCast(DescriptionTreeNode.$, b) !== null) {
            var m = b;
            if (m.i == "EmbeddedRef") {
                var n = "uuid";
                var o = null;
                for (var p = 0; p < m.f().count; p++) {
                    if (m.f()._inner[p].c == "RefType") {
                        n = m.f()._inner[p].b;
                    }
                    if (m.f()._inner[p].c == "Value") {
                        o = m.f()._inner[p].b;
                    }
                }
                if (o != null) {
                    for (var q = 0; q < this.a0.count; q++) {
                        var r = this.a0._inner[q](c, n, o);
                        if (r != null) {
                            return r;
                        }
                    }
                    return null;
                }
            }
            else {
                d.k(c, m.g, g, m, runOn(this, this.cr), f);
                var s = this.a3(m);
                this.cp(c, d, s);
                if (e) {
                    d.l(this, c, m.g, runOn(this, this.removeRefValueCore));
                }
            }
        }
        var t = (a == "object" || a == "Object");
        if (!t && typeof b === 'string' && a.toLowerCase() != "string") {
            return this.bd(a, b);
        }
        if (t) {
            return b;
        }
        return g;
    };
    ComponentRenderer.prototype.t = function (a) {
        return a == "int" || a == "Int32" || a == "short" || a == "Int16" || a == "double" || a == "Double" || a == "float" || a == "Float" || a == "Single" || a == "single" || a == "DateTime" || a == "decimal" || a == "Decimal" || a == "long" || a == "Int64" || a == "byte" || a == "bool" || a == "string" || a == "String";
    };
    ComponentRenderer.prototype.bd = function (a, b) {
        return this.context.l(a, b);
    };
    ComponentRenderer.prototype.a3 = function (a) {
        var b = a.f();
        var c = new List$1(DescriptionTreeAction.$, 0);
        for (var d = 0; d < b.count; d++) {
            var e = new DescriptionTreeAction();
            e.a = 0;
            e.j = b._inner[d].c;
            e.d = b._inner[d].a;
            e.c = a;
            e.b = a;
            e.g = b._inner[d].b;
            c.add(e);
        }
        return c;
    };
    ComponentRenderer.prototype.x = function (a, b, c) {
        if (c.c == null) {
            return this.o(a, b, c);
        }
        else {
            var d = this.bt(a, b, c);
            this.cc(a, b, c, d);
        }
        return true;
    };
    ComponentRenderer.prototype.cc = function (a, b, c, d) {
        var e = c.i(ComponentRenderer.platform);
        this.f.clearCollection(d, e, c.d);
        if (c.h != null && typeCast(Array_$type, c.h) !== null) {
            var f = c.h;
            for (var g = 0; g < f.length; g++) {
                var h = f[g];
                if (h != null && typeCast(DescriptionTreeNode.$, h) !== null) {
                    var i = h.g;
                    if (i >= 0) {
                        var j = b.j(i);
                        if (j != null) {
                            this.cf(a, j, b);
                        }
                    }
                }
            }
        }
    };
    ComponentRenderer.prototype.db = function (a, b, c, d, e, f) {
        var e_17, _a;
        if (this.ax.containsKey(b)) {
            try {
                for (var _b = tslib_1.__values(fromEnum(this.ax.item(b))), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var g = _c.value;
                    g(b, a, d);
                }
            }
            catch (e_17_1) {
                e_17 = { error: e_17_1 };
            }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return))
                        _a.call(_b);
                }
                finally {
                    if (e_17)
                        throw e_17.error;
                }
            }
        }
        this.f.setPropertyValue(a, b, c, d, e, f);
    };
    ComponentRenderer.prototype.br = function (a, b) {
        return this.f.getPropertyValue(a, b);
    };
    ComponentRenderer.prototype.o = function (a, b, c) {
        return this.n(a, b);
    };
    ComponentRenderer.prototype.n = function (a, b) {
        var _this = this;
        var c = this.f.getRootObject(a);
        if (c != null) {
            this.cf(a, c, b);
        }
        var d = false;
        this.f.clearContainer(a, this.context, function (e) {
            d = true;
            if (e) {
                _this.c6(a, b);
            }
        });
        return d;
    };
    ComponentRenderer.$t = markType(ComponentRenderer, 'ComponentRenderer');
    ComponentRenderer._defaultInstance = null;
    ComponentRenderer.platform = 3;
    return ComponentRenderer;
}(Base));
export { ComponentRenderer };
/**
 * @hidden
 */
var ContainerState = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(ContainerState, _super);
    function ContainerState() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.i = null;
        _this.e = new Dictionary$2(Number_$type, Base.$, 0);
        _this.f = new Dictionary$2(Base.$, Number_$type, 0);
        _this.d = new Dictionary$2(Number_$type, String_$type, 0);
        _this.g = new Dictionary$2(Number_$type, HashSet$1.$.specialize(Number_$type), 0);
        _this.c = new Dictionary$2(Number_$type, List$1.$.specialize(Number_$type), 0);
        return _this;
    }
    ContainerState.prototype.k = function (a, b, c, d, e, f) {
        if (d.c("Name")) {
            this.d.item(b, d.a("Name").b);
            e(a, this.d.item(b), c, false);
        }
        this.e.item(b, c);
        this.f.item(c, b);
        if (!this.g.containsKey(b)) {
            this.g.item(b, new HashSet$1(Number_$type, 0));
        }
        this.g.item(b).add_1(f);
        if (f >= 0) {
            if (!this.c.containsKey(f)) {
                this.c.item(f, new List$1(Number_$type, 0));
            }
            this.c.item(f).add(b);
        }
    };
    ContainerState.prototype.a = function (a) {
        return this.e.containsKey(a);
    };
    ContainerState.prototype.b = function (a) {
        return this.f.containsKey(a);
    };
    ContainerState.prototype.j = function (a) {
        return this.e.item(a);
    };
    ContainerState.prototype.l = function (a, b, c, d) {
        if (this.c.containsKey(c)) {
            var e = this.c.item(c);
            for (var f = 0; f < e.count; f++) {
                if (!this.g.containsKey(e._inner[f]) || this.g.item(e._inner[f]).count < 1 || (this.g.item(e._inner[f]).count == 1 && this.g.item(e._inner[f]).contains(c))) {
                    if (this.e.containsKey(e._inner[f])) {
                        a.cf(b, this.e.item(e._inner[f]), this);
                    }
                }
            }
            this.c.removeItem(c);
        }
        var g = this.e.item(c);
        this.f.removeItem(g);
        this.e.removeItem(c);
        if (this.g.containsKey(c)) {
            this.g.removeItem(c);
        }
        if (this.d.containsKey(c)) {
            var h = this.d.item(c);
            this.d.removeItem(c);
            d(b, h, false);
        }
    };
    ContainerState.prototype.h = function (a) {
        if (this.f.containsKey(a)) {
            return this.f.item(a);
        }
        return -1;
    };
    ContainerState.$t = markType(ContainerState, 'ContainerState');
    return ContainerState;
}(Base));
export { ContainerState };
