/*
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 { __extends, __values } from "tslib";
import { Base, IEnumerable_$type, fromEnum, typeCast, Date_$type, Boolean_$type, Array_$type, runOn, Number_$type, Delegate_$type, String_$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 { List$1 } from "./List$1";
import { DescriptionRef } from "./DescriptionRef";
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 { DescriptionRefTargetInfo } from "./DescriptionRefTargetInfo";
import { NotImplementedException } from "./NotImplementedException";
import { ComponentRendererAdapter } from "./ComponentRendererAdapter";
import { stringIsNullOrEmpty, stringStartsWith, stringEndsWith } from "./string";
/**
 * @hidden
 */
var ComponentRenderer = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(ComponentRenderer, _super);
    function ComponentRenderer() {
        var _this = _super.call(this) || this;
        _this._adapter = null;
        _this._context = null;
        _this._isProceedOnErrorEnabled = false;
        _this.i = null;
        _this.j = null;
        _this.av = new Dictionary$2(Base.$, Description.$, 0);
        _this.aw = new Dictionary$2(Base.$, Boolean_$type, 0);
        _this.ax = new Dictionary$2(Base.$, Boolean_$type, 0);
        _this.au = new Dictionary$2(Base.$, Boolean_$type, 0);
        _this.as = new Dictionary$2(Base.$, DescriptionTreeNode.$, 0);
        _this.a0 = new Dictionary$2(Base.$, ContainerState.$, 0);
        _this.ay = new Dictionary$2(Base.$, Queue$1.$.specialize(Queue$1.$.specialize(DescriptionTreeAction.$)), 0);
        _this.at = new Dictionary$2(Base.$, List$1.$.specialize(Delegate_$type), 0);
        _this.ar = new Dictionary$2(Base.$, Boolean_$type, 0);
        _this.az = new Dictionary$2(String_$type, DescriptionRef.$, 0);
        _this.a1 = new Dictionary$2(String_$type, Base.$, 0);
        _this.a3 = new Dictionary$2(String_$type, Base.$, 0);
        _this.a7 = new List$1(Delegate_$type, 0);
        _this.a2 = new Dictionary$2(String_$type, List$1.$.specialize(Delegate_$type), 0);
        _this.a5 = new List$1(Delegate_$type, 0);
        _this.a6 = new List$1(Delegate_$type, 0);
        _this._shouldNamespaceSystemRefValues = false;
        var a = _this.h();
        _this.adapter = a;
        var adapter_ = _this.adapter;
        var b = (adapter_._platform);
        if (b == "Igc") {
            ComponentRenderer.platform = 4;
        }
        else if (b == "Igr") {
            ComponentRenderer.platform = 2;
        }
        _this.context = new TypeDescriptionContext(_this.adapter, ComponentRenderer.platform);
        _this.i = new TypeDescriptionPropretyTransforms();
        _this.j = new TypeDescriptionCleanups();
        return _this;
    }
    Object.defineProperty(ComponentRenderer, "defaultInstance", {
        get: function () {
            return ComponentRenderer._defaultInstance;
        },
        set: function (a) {
            ComponentRenderer._defaultInstance = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(ComponentRenderer.prototype, "adapter", {
        get: function () {
            return this._adapter;
        },
        set: function (a) {
            this._adapter = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(ComponentRenderer.prototype, "context", {
        get: function () {
            return this._context;
        },
        set: function (a) {
            this._context = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(ComponentRenderer.prototype, "isProceedOnErrorEnabled", {
        get: function () {
            return this._isProceedOnErrorEnabled;
        },
        set: function (a) {
            this._isProceedOnErrorEnabled = a;
        },
        enumerable: false,
        configurable: true
    });
    ComponentRenderer.prototype.h = 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 = __values(fromEnum(this.as.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.as.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.a3.count > 0) {
            b.e(",");
        }
        b.f("");
        if (this.a3.count > 0) {
            d = true;
            b.f("refs: {");
            b.i();
            try {
                for (var _e = __values(fromEnum(this.a3.keys)), _f = _e.next(); !_f.done; _f = _e.next()) {
                    var i = _f.value;
                    if (!this.n(i, this.a3.item(i))) {
                        continue;
                    }
                    if (d) {
                        d = false;
                    }
                    else {
                        b.f(",");
                    }
                    this.df(b, i, this.a3.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.df = function (a, b, c) {
        a.e("\"" + b + "\": ");
        this.dg(a, c);
    };
    ComponentRenderer.prototype.dg = function (a, b) {
        if (this.w(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.t(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.de(a, c, d);
                }
                a.f("");
                a.h();
                a.e("]");
            }
            else {
                var e = [b];
                var f = new DataSourceLocalDataProvider();
                f.dataSource = e;
                this.de(a, f, 0);
            }
        }
    };
    ComponentRenderer.prototype.w = 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.t = function (a) {
        if (typeCast(Array_$type, a) !== null) {
            return true;
        }
        if (typeCast(IEnumerable_$type, a) !== null) {
            return true;
        }
        return false;
    };
    ComponentRenderer.prototype.de = 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.dg(a, g);
                    break;
            }
        }
        a.h();
        a.f("}");
    };
    ComponentRenderer.prototype.n = 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.a0.item(b);
        if (h.c("Type")) {
            var j = h.a("Type").b;
            return this.bt(j, h, b, i, true, -1, null);
        }
        else {
            return this.bs(typeCast(JsonDictionaryObject.$, d));
        }
    };
    ComponentRenderer.prototype.loadJson = function (a, b) {
        this.cr(a, b, null, false, false, false);
    };
    ComponentRenderer.prototype.loadJsonOverlay = function (a, b, c) {
        this.cr(a, b, c, true, false, true);
    };
    ComponentRenderer.prototype.loadJsonDelta = function (a, b, c) {
        this.cr(a, b, null, true, c, false);
    };
    ComponentRenderer.prototype.ao = function () {
        return false;
    };
    ComponentRenderer.prototype.cr = 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.ao();
        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.a9();
                        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.a4.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.db(w.result, r, d, true, false);
                                var y = c(p);
                                var z = this.a4.item(r);
                                this.cn(this.as.item(r), y, z, r);
                            }
                        }
                        this.db(u.result, r, d, e, false);
                    }
                }
            }
            if (k.g("refs") && j != null) {
                var aa = k.item("refs");
                var ab = this.ae(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.bs(ag);
                            this.provideRefValue(j, af, ak);
                        }
                    }
                }
            }
            if (k.g("modules") && j != null) {
                var al = k.item("modules");
                this.ab(al);
            }
            if (k.g("strings") && j != null) {
                var am = k.item("strings");
                this.ai(am);
            }
            if (k.g("onInit") && j != null) {
                var an = k.item("onInit");
                this.ac(an);
            }
            if (k.g("onViewInit") && j != null) {
                var ao = k.item("onViewInit");
                this.ad(ao);
            }
        }
    };
    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.bs(f);
            this.provideRefValue(a, d, j);
        }
    };
    ComponentRenderer.prototype.a9 = function () {
        return null;
    };
    ComponentRenderer.prototype.ae = function (a) {
        return false;
    };
    ComponentRenderer.prototype.ab = function (a) {
        return false;
    };
    ComponentRenderer.prototype.ai = function (a) {
        return false;
    };
    ComponentRenderer.prototype.ac = function (a) {
        return false;
    };
    ComponentRenderer.prototype.ad = function (a) {
        return false;
    };
    ComponentRenderer.prototype.b6 = function (a, b, c) {
        var d = a;
        if (c != null) {
            d = c.j(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.cn = function (a, b, c, d) {
        var e_3, _a;
        if (!c.b(b)) {
            c.k(d, this.as.item(d).g, b, this.as.item(d), runOn(this, this.cx), -1);
        }
        try {
            for (var _b = __values(fromEnum(a.f())), _c = _b.next(); !_c.done; _c = _b.next()) {
                var e = _c.value;
                this.co(this.b6(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.co = 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.adapter.getPropertyValue(c, a);
            if (!d.b(h) && !d.a(g.g)) {
                d.k(e, g.g, h, g, runOn(this, this.cx), f);
            }
            try {
                for (var _b = __values(fromEnum(g.f())), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var i = _c.value;
                    this.co(a + "." + this.b6(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.adapter.getPropertyValue(c, a);
            k_1 = 0;
            this.adapter.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.cx), f);
                    }
                    try {
                        for (var _b = __values(fromEnum(s.f())), _c = _b.next(); !_c.done; _c = _b.next()) {
                            var t = _c.value;
                            _this.co(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.ca(a);
                this.adapter.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.cx), f);
                        }
                        try {
                            for (var _b = __values(fromEnum(t.f())), _c = _b.next(); !_c.done; _c = _b.next()) {
                                var u = _c.value;
                                _this.co(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.ca = 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.b8(d);
        if (c != null) {
            return c + "." + d;
        }
        return d;
    };
    ComponentRenderer.prototype.b8 = 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.bs(a.items[c]);
            b[c] = d;
        }
        return b;
    };
    ComponentRenderer.prototype.bs = 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.bs(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, "a4", {
        get: function () {
            return this.a0;
        },
        enumerable: false,
        configurable: true
    });
    ComponentRenderer.prototype.cleanup = function (a, b) {
        this.db(null, a, false, false, b);
    };
    ComponentRenderer.prototype.render = function (a, b) {
        this.db(a, b, false, false, false);
    };
    ComponentRenderer.prototype.db = function (a, b, c, d, e) {
        var _this = this;
        if (!this.a0.containsKey(b)) {
            this.a0.item(b, new ContainerState());
            this.a0.item(b).i = b;
        }
        this.av.item(b, a);
        this.aw.item(b, c);
        this.ax.item(b, d);
        this.au.item(b, e);
        this.ct(b, function () { return _this.c9(b); });
    };
    ComponentRenderer.prototype.ct = function (a, b) {
        this.adapter.onUIThread(a, b);
    };
    ComponentRenderer.prototype.c9 = function (a) {
        var e_7, _a, e_8, _b, e_9, _c, e_10, _d;
        var _this = this;
        if (this.av.containsKey(a)) {
            var b = this.aw.containsKey(a) ? this.aw.item(a) : false;
            var c = this.ax.containsKey(a) ? this.ax.item(a) : false;
            var d = this.av.item(a);
            this.av.removeItem(a);
            var e = DescriptionTreeBuilder.createTree(this.context, d);
            var f = null;
            if (this.as.containsKey(a)) {
                f = this.as.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.a0.containsKey(a)) {
                    this.a0.addItem(a, ((function () {
                        var $ret = new ContainerState();
                        $ret.i = a;
                        return $ret;
                    })()));
                }
                var j_2 = this.a0.item(a);
                if (i.a.count > 0) {
                    try {
                        for (var _e = __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.cl(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 = __values(fromEnum(i.c)), _h = _g.next(); !_h.done; _h = _g.next()) {
                            var m = _h.value;
                            var n = this.by(a, j_2, m);
                            var o = this.adapter.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.cx), 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 = __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.as.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.by(a, j_2, v);
                        var ac = this_1.adapter.getPropertyValue(ab, v.j);
                        if (ac != null) {
                            var ad_1 = 0;
                            this_1.adapter.forPropertyValueItem(ab, v.j, function (ae) {
                                if (x.containsKey(_this.adapter.getPropertyValue(ae, "Name").toString())) {
                                    if (!j_2.b(ae)) {
                                        var af = x.item(_this.adapter.getPropertyValue(ae, "Name").toString());
                                        if (typeCast(DescriptionTreeNode.$, af) !== null) {
                                            var ag = af.g;
                                            j_2.k(a, ag, ae, af, runOn(_this, _this.cx), v.c.g);
                                        }
                                    }
                                }
                                ad_1++;
                            });
                        }
                    };
                    var this_1 = this;
                    try {
                        for (var _l = __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.as.item(a, e);
            }
            if (!c) {
                this.da(a, g);
            }
            if (this.au.item(a)) {
                this.c7(a);
                if (this.a0.containsKey(a)) {
                    this.a0.removeItem(a);
                }
            }
        }
    };
    ComponentRenderer.prototype.provideRefValue = function (a, b, c) {
        var _this = this;
        this.ct(a, function () {
            if (!_this.a0.containsKey(a)) {
                _this.a0.addItem(a, ((function () {
                    var $ret = new ContainerState();
                    $ret.i = a;
                    return $ret;
                })()));
            }
            var d = _this.a0.item(a);
            _this.cx(a, b, c, true);
        });
    };
    ComponentRenderer.prototype.removeRefValue = function (a, b) {
        var _this = this;
        this.ct(a, function () {
            if (!_this.a0.containsKey(a)) {
                _this.a0.addItem(a, ((function () {
                    var $ret = new ContainerState();
                    $ret.i = a;
                    return $ret;
                })()));
            }
            var c = _this.a0.item(a);
            _this.removeRefValueCore(a, b, true);
        });
    };
    ComponentRenderer.prototype.c7 = function (a) {
        var e_11, _a;
        var b = this.a0.item(a);
        var c = new List$1(String_$type, 0);
        try {
            for (var _b = __values(fromEnum(this.az.keys)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var d = _c.value;
                if (this.az.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.a3.containsKey(c._inner[e]));
            this.shouldNamespaceSystemRefValues = f;
        }
    };
    ComponentRenderer.prototype.clearRefValues = function (a) {
        var _this = this;
        this.ct(a, function () {
            if (!_this.a0.containsKey(a)) {
                _this.a0.addItem(a, ((function () {
                    var $ret = new ContainerState();
                    $ret.i = a;
                    return $ret;
                })()));
            }
            var b = _this.a0.item(a);
            _this.clearUserRefValues();
        });
    };
    ComponentRenderer.prototype.u = function (a) {
        if (this.ar.containsKey(a) && this.ar.item(a)) {
            return false;
        }
        if (this.ay.containsKey(a) && this.ay.item(a).count > 0) {
            return false;
        }
        return true;
    };
    ComponentRenderer.prototype.queueForIdle = function (a, b) {
        var _this = this;
        this.ct(a, function () {
            if (_this.u(a)) {
                b();
            }
            else {
                if (!_this.at.containsKey(a)) {
                    _this.at.item(a, new List$1(Delegate_$type, 0));
                }
                _this.at.item(a).add(b);
            }
        });
    };
    ComponentRenderer.prototype.tryFlushIdleActions = function (a) {
        if (this.u(a)) {
            if (this.at.containsKey(a)) {
                var b = new List$1(Delegate_$type, 1, this.at.item(a));
                this.at.item(a).clear();
                for (var c = 0; c < b.count; c++) {
                    b._inner[c]();
                }
            }
        }
    };
    ComponentRenderer.prototype.da = function (a, b) {
        var c = this.a0.item(a);
        this.cu(a, c, b);
    };
    ComponentRenderer.prototype.dd = function (a, b) {
        if (this.isProceedOnErrorEnabled) {
            try {
                this.cm(a, b, true);
            }
            catch (c) {
                this.ar.item(a, false);
            }
        }
        else {
            this.cm(a, b, true);
        }
    };
    ComponentRenderer.prototype.dj = function (a, b) {
        if (this.isProceedOnErrorEnabled) {
            try {
                this.cm(a, b, false);
            }
            catch (c) {
                this.ar.item(a, false);
            }
        }
        else {
            this.cm(a, b, false);
        }
    };
    ComponentRenderer.prototype.cm = function (a, b, c) {
        if (!c) {
            if (this.ar.containsKey(a) && this.ar.item(a)) {
                return;
            }
        }
        this.ar.item(a, true);
        var d = true;
        while (d && this.ay.item(a).count > 0) {
            while (this.ay.item(a).count > 0 && this.ay.item(a).c().count < 1) {
                this.ay.item(a).b();
            }
            if (this.ay.item(a).count < 1) {
                break;
            }
            var e = this.ay.item(a).c();
            while (e.count > 0) {
                var f = e.b();
                d = this.y(a, b, f);
                if (!d) {
                    break;
                }
            }
        }
        if (d) {
            this.ar.item(a, false);
        }
        if (this.u(a)) {
            this.tryFlushIdleActions(a);
        }
    };
    ComponentRenderer.prototype.cu = 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.ay.containsKey(a)) {
            this.ay.addItem(a, new Queue$1(Queue$1.$.specialize(DescriptionTreeAction.$)));
        }
        this.ay.item(a).g(d);
        this.dj(a, b);
    };
    ComponentRenderer.prototype.cv = function (a, b, c) {
        for (var d = 0; d < c.count; d++) {
            this.y(a, b, c._inner[d]);
        }
    };
    ComponentRenderer.prototype.y = function (a, b, c) {
        switch (c.a) {
            case 5: return this.z(a, b, c);
            case 2: return this.aa(a, b, c);
            case 4: return this.af(a, b, c);
            case 3: return this.ag(a, b, c);
            case 1: return this.ah(a, b, c);
            case 0: return this.aj(a, b, c);
        }
        return true;
    };
    ComponentRenderer.prototype.aj = function (a, b, c) {
        var d = this.by(a, b, c);
        this.aq(a, b, c, d);
        return true;
    };
    ComponentRenderer.prototype.aq = function (a, b, c, d) {
        var e = this.bv(c, a, b);
        e = this.i.transform(ComponentRenderer.platform, e, c);
        var f = false;
        if (this.a7 != null && this.a7.count > 0) {
            for (var g = 0; g < this.a7.count; g++) {
                var h = this.a7._inner[g];
                var i = this.b7(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.an(a, b, c.i(ComponentRenderer.platform), c.d, e, d);
        }
        else {
            this.dh(a, b, c.i(ComponentRenderer.platform), c.d, e, c.h, d);
        }
        return true;
    };
    ComponentRenderer.prototype.b7 = function (a, b) {
        var c = b.c;
        var d = "";
        if (c != this.as.item(a)) {
            var e = this.b5(a, c);
            d = e;
        }
        if (d.length > 0) {
            d += ".";
        }
        d += b.j;
        return d;
    };
    ComponentRenderer.prototype.b5 = function (a, b) {
        if (b == null) {
            return "";
        }
        var c = this.cb("", this.as.item(a), b);
        if (c.c) {
            return c.d;
        }
        return "";
    };
    ComponentRenderer.prototype.cb = 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.cb(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.cb(l, k, c);
                            if (m.c) {
                                return m;
                            }
                        }
                    }
                }
            }
        }
        return new Tuple$2(Boolean_$type, String_$type, false, a);
    };
    ComponentRenderer.prototype.an = function (a, b, c, d, e, f) {
        var e_12, _a;
        if (this.a2.containsKey(c)) {
            try {
                for (var _b = __values(fromEnum(this.a2.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.adapter.setOrUpdateCollectionOnTarget(a, c, d, this.context, f, e);
        return true;
    };
    ComponentRenderer.prototype.bv = function (a, b, c) {
        if (a.d == null) {
            return a.g;
        }
        switch (a.d.knownType) {
            case 10: return this.bb(a, b, c);
            case 7: return this.bc(a);
            case 4: return this.bd(a);
            case 6: return this.be(a);
            case 9: return this.bb(a, b, c);
            case 5: return this.bf(a);
            case 16: return this.bg(a);
            case 20: return this.bz(a, c);
            case 22: return this.b2(a, c);
            case 15: return null;
            case 3: return this.bh(a);
            case 19: return this.b0(a, c);
            case 8: return this.bj(a, b, c);
            case 13: return null;
            case 18: return this.b1(a, c);
            case 1: return this.bk(a);
            case 11: return this.bl(a);
            case 14: return this.bm(a);
            case 12: return this.bn(a);
            case 2: return this.bo(a);
            case 21: return this.bp(a);
            case 17: return this.bq(a, b, c);
            case 0: return null;
        }
        return null;
    };
    ComponentRenderer.prototype.bq = function (a, b, c) {
        var d = this.br(a.g, a, b, c);
        return d;
    };
    ComponentRenderer.prototype.br = 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.br(e[g], b, c, d);
                f[g] = h;
            }
            a = f;
        }
        if (typeCast(DescriptionTreeNode.$, a) !== null) {
            var i = a;
            if (i.i == "EmbeddedRef") {
                return this.bt(i.i, a, c, d, false, b.c.g, b.d);
            }
        }
        return a;
    };
    ComponentRenderer.prototype.bp = function (a) {
        return a.g;
    };
    ComponentRenderer.prototype.bo = function (a) {
        return a.g != null ? a.g.toString() : null;
    };
    ComponentRenderer.prototype.bn = function (a) {
        var b = a.g;
        var width_ = b.width;
        var height_ = b.height;
        var c = { width: width_, height: height_ };
        return c;
    };
    ComponentRenderer.prototype.bm = 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.bl = function (a) {
        var b = a.g;
        var x_ = b.x;
        var y_ = b.y;
        var c = { x: x_, y: y_ };
        return c;
    };
    ComponentRenderer.prototype.bk = 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.e = function (a, b) {
        if (this.az.containsKey(a)) {
            var c = this.az.item(a);
            return c;
        }
        var d = new DescriptionRef(a);
        this.az.addItem(a, d);
        return d;
    };
    ComponentRenderer.prototype.b1 = function (a, b) {
        return a.g == null ? null : this.e(a.g, b);
    };
    ComponentRenderer.prototype.bj = 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.bt(d, a.g, b, c, false, a.c.g, a.d);
        return f;
    };
    ComponentRenderer.prototype.b0 = function (a, b) {
        return a.g == null ? null : this.e(a.g, b);
    };
    ComponentRenderer.prototype.bh = function (a) {
        if (typeof a.g === 'string') {
            var v_ = a.g;
            a.g = new Date(v_);
        }
        return a.g;
    };
    ComponentRenderer.prototype.bz = function (a, b) {
        return a.g == null ? null : this.e(a.g, b);
    };
    ComponentRenderer.prototype.b2 = function (a, b) {
        return a.g == null ? null : this.e(a.g, b);
    };
    ComponentRenderer.prototype.b4 = function (a) {
        return a;
    };
    ComponentRenderer.prototype.bg = 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.b4(b[d]);
        }
        return c;
    };
    ComponentRenderer.prototype.bf = function (a) {
        return this.b4(a.g);
    };
    ComponentRenderer.prototype.be = 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.b3(b[d]);
        }
        return c;
    };
    ComponentRenderer.prototype.b3 = function (a) {
        return a;
    };
    ComponentRenderer.prototype.bd = function (a) {
        return this.b3(a.g);
    };
    ComponentRenderer.prototype.bc = function (a) {
        return a.g;
    };
    ComponentRenderer.prototype.addTargetPropertyUpdatingListener = function (a) {
        this.a7.add(a);
    };
    ComponentRenderer.prototype.removeTargetPropertyUpdatingListener = function (a) {
        this.a7.remove(a);
    };
    ComponentRenderer.prototype.addPropertyUpdatingListener = function (a, b) {
        if (!this.a2.containsKey(a)) {
            this.a2.addItem(a, new List$1(Delegate_$type, 0));
        }
        this.a2.item(a).add(b);
    };
    ComponentRenderer.prototype.addReferenceLookupListener = function (a) {
        this.a5.add(a);
    };
    ComponentRenderer.prototype.removeReferenceLookupListener = function (a) {
        this.a5.remove(a);
    };
    ComponentRenderer.prototype.removePropertyUpdatingListener = function (a, b) {
        if (this.a2.containsKey(a)) {
            this.a2.item(a).remove(b);
            if (this.a2.item(a).count == 0) {
                this.a2.removeItem(a);
            }
        }
    };
    ComponentRenderer.prototype.addNamespaceLookupListener = function (a) {
        this.a6.add(a);
    };
    ComponentRenderer.prototype.removeNamespaceLookupListener = function (a) {
        this.a6.remove(a);
    };
    ComponentRenderer.prototype.bb = 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.bt(h, d[g], b, c, false, a.c.g, a.d);
            e.add1(j);
        }
        return e.toArray();
    };
    ComponentRenderer.prototype.dh = 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.q(f)) {
                    var j = this.f(f);
                    if (Base.equalsStatic(j, e)) {
                        i = true;
                    }
                    else {
                        j.j(a, g, c);
                    }
                }
            }
            if (this.r(e)) {
                var k = e;
                if (k.e != null && k.e.length > 0 && this.a1.containsKey(k.e)) {
                    k.a = true;
                }
                e = this.bx(e);
                this.di(g, c, d, e, f, k);
            }
            else {
                this.adapter.onPendingRef(g, c, d, e);
            }
            var l = null;
            l = function (m, n) {
                var o = m;
                if (o.e != null && o.e.length > 0 && _this.a1.containsKey(o.e)) {
                    o.a = true;
                }
                var p = _this.bx(m);
                _this.di(g, c, d, p, f, o);
            };
            if (!i) {
                h.g(a, g, c, l);
            }
            return;
        }
        this.di(g, c, d, e, f, null);
    };
    ComponentRenderer.prototype.hasUserRef = function (a) {
        return this.a3.containsKey(a);
    };
    Object.defineProperty(ComponentRenderer.prototype, "shouldNamespaceSystemRefValues", {
        get: function () {
            return this._shouldNamespaceSystemRefValues;
        },
        set: function (a) {
            this._shouldNamespaceSystemRefValues = a;
        },
        enumerable: false,
        configurable: true
    });
    ComponentRenderer.prototype.cx = function (a, b, c, d) {
        var e = null;
        if (d) {
            if (this.a3.containsKey(b)) {
                e = this.a3.item(b);
            }
            this.a3.item(b, c);
        }
        else {
            if (this.shouldNamespaceSystemRefValues) {
                var f = "";
                if (this.a6 != null && this.a6.count > 0) {
                    for (var g = 0; g < this.a6.count; g++) {
                        f = this.a6._inner[g](a);
                    }
                }
                if (!stringIsNullOrEmpty(f)) {
                    b = f + "/" + b;
                }
            }
            if (this.a1.containsKey(b)) {
                e = this.a1.item(b);
            }
            this.a1.item(b, c);
            if (this.az.containsKey(b)) {
                this.az.item(b).a = true;
            }
        }
        if (this.az.containsKey(b)) {
            this.az.item(b).f(e, c);
        }
    };
    ComponentRenderer.prototype.removeRefValueCore = function (a, b, c) {
        var d = null;
        if (c) {
            if (this.a3.containsKey(b)) {
                d = this.a3.item(b);
            }
            this.a3.removeItem(b);
        }
        else {
            if (this.shouldNamespaceSystemRefValues) {
                var e = "";
                if (this.a6 != null && this.a6.count > 0) {
                    for (var f = 0; f < this.a6.count; f++) {
                        e = this.a6._inner[f](a);
                    }
                }
                if (!stringIsNullOrEmpty(e)) {
                    b = e + "/" + b;
                }
            }
            if (this.a1.containsKey(b)) {
                d = this.a1.item(b);
            }
            this.a1.removeItem(b);
        }
        if (this.az.containsKey(b)) {
            this.az.item(b).f(d, this.bx(this.az.item(b)));
            if (this.az.item(b).c <= 0) {
                this.az.item(b).h();
                this.az.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 = __values(fromEnum(this.a3.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 = __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.r = function (a) {
        return this.a3.containsKey(a.e) || this.a1.containsKey(a.e);
    };
    ComponentRenderer.prototype.bx = function (a) {
        if (this.a3.containsKey(a.e)) {
            return this.a3.item(a.e);
        }
        if (this.a1.containsKey(a.e)) {
            return this.a1.item(a.e);
        }
        return null;
    };
    ComponentRenderer.prototype.q = function (a) {
        return this.az.containsKey(a);
    };
    ComponentRenderer.prototype.f = function (a) {
        return this.az.item(a);
    };
    ComponentRenderer.prototype.getMissingRefs = function () {
        var e_15, _a;
        var a = new List$1(String_$type, 0);
        try {
            for (var _b = __values(fromEnum(this.az.keys)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var b = _c.value;
                if (!this.r(this.az.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.getRefChangeInfos = function (a) {
        var e_16, _a;
        var b = new List$1(DescriptionRefTargetInfo.$, 0);
        if (this.az.containsKey(a)) {
            var _loop_2 = function (c) {
                b.add(((function () {
                    var $ret = new DescriptionRefTargetInfo();
                    $ret.container = c.b;
                    $ret.propertyName = c.d;
                    $ret.target = c.c;
                    return $ret;
                })()));
            };
            try {
                for (var _b = __values(fromEnum(this.az.item(a).b)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var c = _c.value;
                    _loop_2(c);
                }
            }
            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;
                }
            }
        }
        return b.toArray();
    };
    ComponentRenderer.prototype.by = function (a, b, c) {
        return b.j(c.c.g);
    };
    ComponentRenderer.prototype.ah = function (a, b, c) {
        var d = this.by(a, b, c);
        this.am(a, b, c, d);
        return true;
    };
    ComponentRenderer.prototype.am = function (a, b, c, d) {
        this.adapter.resetPropertyOnTarget(a, c.i(ComponentRenderer.platform), c.d, d);
        return true;
    };
    ComponentRenderer.prototype.ag = function (a, b, c) {
        if (c.c == null) {
            return this.al(a, b, c);
        }
        else {
            var d = this.by(a, b, c);
            this.dc(a, b, c, d);
        }
        return true;
    };
    ComponentRenderer.prototype.dc = 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.bt(f, c.g, a, b, false, c.c.g, c.d);
        this.adapter.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.cl(a, i, b);
                }
            }
        }
    };
    ComponentRenderer.prototype.al = function (a, b, c) {
        var _this = this;
        var d = this.adapter.getRootObject(a);
        if (d != null) {
            this.cl(a, d, b);
        }
        if (!(typeCast(DescriptionTreeNode.$, c.g) !== null)) {
            throw new NotImplementedException(0);
        }
        var e = c.g;
        var f = false;
        this.adapter.replaceRootItem(a, e.i, this.context, function (g) {
            var h = _this.adapter.getRootObject(a);
            b.k(a, e.g, h, e, runOn(_this, _this.cx), -1);
            var i = _this.a8(e);
            _this.cv(a, b, i);
            f = true;
            if (g) {
                _this.dd(a, b);
            }
        });
        return f;
    };
    ComponentRenderer.prototype.cl = function (a, b, c) {
        var e_17, _a;
        var d = this.ba(a, b, c);
        try {
            for (var _b = __values(fromEnum(this.az.values)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var e = _c.value;
                e.i(b);
            }
        }
        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;
            }
        }
        if (d != -1) {
            c.l(this, a, d, runOn(this, this.removeRefValueCore));
        }
        this.j.b(ComponentRenderer.platform, b);
    };
    ComponentRenderer.prototype.ba = function (a, b, c) {
        return c.h(b);
    };
    ComponentRenderer.prototype.af = function (a, b, c) {
        if (c.c == null) {
            return this.ak(a, b, c);
        }
        else {
            var d = this.by(a, b, c);
            this.c0(a, b, c, d);
        }
        return true;
    };
    ComponentRenderer.prototype.c0 = function (a, b, c, d) {
        var e = c.i(ComponentRenderer.platform);
        this.adapter.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.cl(a, g, b);
                }
            }
        }
    };
    ComponentRenderer.prototype.ak = function (a, b, c) {
        var _this = this;
        var d = this.adapter.getRootObject(a);
        if (d != null) {
            this.cl(a, d, b);
        }
        var e = false;
        this.adapter.removeRootItem(a, this.context, function (f) {
            e = true;
            if (f) {
                _this.dd(a, b);
            }
        });
        return e;
    };
    ComponentRenderer.prototype.aa = function (a, b, c) {
        if (c.c == null) {
            return this.m(a, b, c);
        }
        else {
            var d = this.by(a, b, c);
            this.cc(a, b, c, d);
        }
        return true;
    };
    ComponentRenderer.prototype.m = 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.adapter.replaceRootItem(a, d.i, this.context, function (f) {
            var g = _this.adapter.getRootObject(a);
            b.k(a, d.g, g, d, runOn(_this, _this.cx), -1);
            var h = _this.a8(d);
            _this.cv(a, b, h);
            e = true;
            if (f) {
                _this.dd(a, b);
            }
        });
        return e;
    };
    ComponentRenderer.prototype.cc = 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.bt(f, c.g, a, b, false, c.c.g, c.d);
        this.adapter.addItemToCollection(e, c.d, d, c.e, h);
    };
    ComponentRenderer.prototype.bt = function (a, b, c, d, e, f, g) {
        if (this.v(a)) {
            return b;
        }
        var h = null;
        if (b != null && typeCast(DescriptionTreeNode.$, b) !== null) {
            var i = b;
            if (i.c("Name")) {
                var j = i.a("Name").b;
                if (!stringIsNullOrEmpty(j)) {
                    if (this.shouldNamespaceSystemRefValues) {
                        var k = "";
                        if (this.a6 != null && this.a6.count > 0) {
                            for (var l = 0; l < this.a6.count; l++) {
                                k = this.a6._inner[l](c);
                            }
                        }
                        if (!stringIsNullOrEmpty(k)) {
                            j = k + "/" + j;
                        }
                    }
                    if (this.a1.containsKey(j)) {
                        var m = this.a1.item(j);
                        h = m;
                    }
                }
            }
            if (h == null) {
                h = this.context.u(a, c);
            }
        }
        else if (b != null) {
            h = this.context.u(a, c);
        }
        if (b == null) {
            return h;
        }
        if (typeCast(DescriptionTreeNode.$, b) !== null) {
            var n = b;
            if (n.i == "EmbeddedRef") {
                var o = "uuid";
                var p = null;
                for (var q = 0; q < n.f().count; q++) {
                    if (n.f()._inner[q].c == "RefType") {
                        o = n.f()._inner[q].b;
                    }
                    if (n.f()._inner[q].c == "Value") {
                        p = n.f()._inner[q].b;
                    }
                }
                if (p != null) {
                    for (var r = 0; r < this.a5.count; r++) {
                        var s = this.a5._inner[r](c, o, p);
                        if (s != null) {
                            return s;
                        }
                    }
                    return null;
                }
            }
            else {
                d.k(c, n.g, h, n, runOn(this, this.cx), f);
                var t = this.a8(n);
                this.cv(c, d, t);
                if (e) {
                    d.l(this, c, n.g, runOn(this, this.removeRefValueCore));
                }
            }
        }
        var u = (a == "object" || a == "Object");
        if (!u && typeof b === 'string' && a.toLowerCase() != "string") {
            return this.bi(a, b, g);
        }
        if (u) {
            return b;
        }
        return h;
    };
    ComponentRenderer.prototype.v = 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.bi = function (a, b, c) {
        return this.context.q(a, b, c);
    };
    ComponentRenderer.prototype.a8 = 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;
            if (e.d != null && e.d.mustBeFirst) {
                c.insert(0, e);
            }
            else {
                c.add(e);
            }
        }
        return c;
    };
    ComponentRenderer.prototype.z = function (a, b, c) {
        if (c.c == null) {
            return this.p(a, b, c);
        }
        else {
            var d = this.by(a, b, c);
            this.ci(a, b, c, d);
        }
        return true;
    };
    ComponentRenderer.prototype.ci = function (a, b, c, d) {
        var e = c.i(ComponentRenderer.platform);
        this.adapter.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.cl(a, j, b);
                        }
                    }
                }
            }
        }
    };
    ComponentRenderer.prototype.di = function (a, b, c, d, e, f) {
        var e_18, _a;
        if (this.a2.containsKey(b)) {
            try {
                for (var _b = __values(fromEnum(this.a2.item(b))), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var g = _c.value;
                    g(b, a, d);
                }
            }
            catch (e_18_1) {
                e_18 = { error: e_18_1 };
            }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return))
                        _a.call(_b);
                }
                finally {
                    if (e_18)
                        throw e_18.error;
                }
            }
        }
        this.adapter.setPropertyValue(a, b, c, d, e, f);
    };
    ComponentRenderer.prototype.bw = function (a, b) {
        return this.adapter.getPropertyValue(a, b);
    };
    ComponentRenderer.prototype.p = function (a, b, c) {
        return this.o(a, b);
    };
    ComponentRenderer.prototype.o = function (a, b) {
        var _this = this;
        var c = this.adapter.getRootObject(a);
        if (c != null) {
            this.cl(a, c, b);
        }
        var d = false;
        this.adapter.clearContainer(a, this.context, function (e) {
            d = true;
            if (e) {
                _this.dd(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) {
    __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.cl(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 };
