/*
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, String_$type, Delegate_$type, runOn, markType } from "./type";
import { TypeDescriptionContext } from "./TypeDescriptionContext";
import { TypeDescriptionPropretyTransforms } from "./TypeDescriptionPropretyTransforms";
import { TypeDescriptionCleanups } from "./TypeDescriptionCleanups";
import { Dictionary$2 } from "./Dictionary$2";
import { Description } from "./Description";
import { DescriptionTreeNode } from "./DescriptionTreeNode";
import { ContainerState } from "./ContainerState";
import { Queue$1 } from "./Queue$1";
import { DescriptionTreeAction } from "./DescriptionTreeAction";
import { DescriptionRef } from "./DescriptionRef";
import { List$1 } from "./List$1";
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 { DescriptionTreeReconciler } from "./DescriptionTreeReconciler";
import { NotImplementedException } from "./NotImplementedException";
import { ComponentRendererAdapter } from "./ComponentRendererAdapter";
import { stringIsNullOrEmpty, stringStartsWith } from "./string";
/**
 * @hidden
 */
var ComponentRenderer = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(ComponentRenderer, _super);
    function ComponentRenderer() {
        var _this = _super.call(this) || this;
        _this.d = null;
        _this._context = null;
        _this.i = null;
        _this.f = null;
        _this.ai = new Dictionary$2(Base.$, Description.$, 0);
        _this.aj = new Dictionary$2(Base.$, Boolean_$type, 0);
        _this.ak = new Dictionary$2(Base.$, Boolean_$type, 0);
        _this.ah = new Dictionary$2(Base.$, DescriptionTreeNode.$, 0);
        _this.an = new Dictionary$2(Base.$, ContainerState.$, 0);
        _this.al = new Dictionary$2(Base.$, Queue$1.$.specialize(Queue$1.$.specialize(DescriptionTreeAction.$)), 0);
        _this.ag = new Dictionary$2(Base.$, Boolean_$type, 0);
        _this.am = new Dictionary$2(String_$type, DescriptionRef.$, 0);
        _this.ao = new Dictionary$2(String_$type, Base.$, 0);
        _this.aq = new Dictionary$2(String_$type, Base.$, 0);
        _this.ap = new Dictionary$2(String_$type, List$1.$.specialize(Delegate_$type), 0);
        _this.ar = new List$1(Delegate_$type, 0);
        _this.as = new List$1(Delegate_$type, 0);
        _this._shouldNamespaceSystemRefValues = false;
        var a = _this.e();
        _this.d = a;
        _this.context = new TypeDescriptionContext(a, ComponentRenderer.platform);
        _this.i = new TypeDescriptionPropretyTransforms();
        _this.f = new TypeDescriptionCleanups();
        return _this;
    }
    Object.defineProperty(ComponentRenderer.prototype, "context", {
        get: function () {
            return this._context;
        },
        set: function (a) {
            this._context = a;
        },
        enumerable: true,
        configurable: true
    });
    ComponentRenderer.prototype.e = 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.ah.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.ah.item(e);
                var h = "root";
                h = a(f);
                if (stringIsNullOrEmpty(h)) {
                    h = "root";
                }
                b.e("\"" + h + "\"");
                b.e(": ");
                c.o(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.aq.count > 0) {
            b.e(",");
        }
        b.f("");
        if (this.aq.count > 0) {
            d = true;
            b.f("refs: {");
            b.i();
            try {
                for (var _e = tslib_1.__values(fromEnum(this.aq.keys)), _f = _e.next(); !_f.done; _f = _e.next()) {
                    var i = _f.value;
                    if (!this.k(i, this.aq.item(i))) {
                        continue;
                    }
                    if (d) {
                        d = false;
                    }
                    else {
                        b.f(",");
                    }
                    this.ch(b, i, this.aq.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.ch = function (a, b, c) {
        a.e("\"" + b + "\": ");
        this.ci(a, c);
    };
    ComponentRenderer.prototype.ci = function (a, b) {
        if (this.s(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.q(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.cg(a, c, d);
                }
                a.f("");
                a.h();
                a.e("]");
            }
            else {
                var e = [b];
                var f = new DataSourceLocalDataProvider();
                f.dataSource = e;
                this.cg(a, f, 0);
            }
        }
    };
    ComponentRenderer.prototype.s = 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.q = function (a) {
        if (typeCast(Array_$type, a) !== null) {
            return true;
        }
        if (typeCast(IEnumerable_$type, a) !== null) {
            return true;
        }
        return false;
    };
    ComponentRenderer.prototype.cg = 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.ci(a, g);
                    break;
            }
        }
        a.h();
        a.f("}");
    };
    ComponentRenderer.prototype.k = 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);
        if (g.result == null) {
            return null;
        }
        var h = DescriptionTreeBuilder.createTree(this.context, g.result);
        var i = this.an.item(b);
        if (h.b("Type")) {
            var j = h.a("Type").b;
            return this.bc(j, h, b, i);
        }
        else {
            return this.bb(typeCast(JsonDictionaryObject.$, d));
        }
    };
    ComponentRenderer.prototype.loadJson = function (a, b) {
        this.bz(a, b, false, false);
    };
    ComponentRenderer.prototype.loadJsonDelta = function (a, b, c) {
        this.bz(a, b, true, c);
    };
    ComponentRenderer.prototype.bz = function (a, b, c, d) {
        var e = new JsonDictionaryParser();
        var f = e.parse(a);
        var g = new DescriptionSerializer();
        var h = null;
        if (typeCast(JsonDictionaryObject.$, f) !== null) {
            var i = f;
            if (i.c("descriptions")) {
                var j = i.item("descriptions");
                if (typeCast(JsonDictionaryObject.$, j) !== null) {
                    var k = j;
                    var l = k.a();
                    for (var m = 0; m < l.length; m++) {
                        var n = l[m];
                        var o = k.item(n);
                        var p = b(n);
                        if (p == null) {
                            continue;
                        }
                        h = p;
                        var q = false;
                        var r = g.d(this.context, o, q);
                        if (r.result == null) {
                            continue;
                        }
                        this.cd(r.result, p, c, d);
                    }
                }
            }
            if (i.c("refs") && h != null) {
                var s = i.item("refs");
                if (typeCast(JsonDictionaryObject.$, s) !== null) {
                    var t = s;
                    var u = t.a();
                    for (var v = 0; v < u.length; v++) {
                        var w = u[v];
                        var x = t.item(w);
                        if (typeCast(JsonDictionaryValue.$, x) !== null) {
                            var y = x;
                            this.provideRefValue(h, w, y.value);
                        }
                        else if (typeCast(JsonDictionaryArray.$, x) !== null) {
                            var z = x;
                            var aa = this.a(z);
                            this.provideRefValue(h, w, aa);
                        }
                        else {
                            var ab = this.bb(x);
                            this.provideRefValue(h, w, ab);
                        }
                    }
                }
            }
        }
    };
    ComponentRenderer.prototype.a = function (a) {
        var b = new Array(a.items.length);
        for (var c = 0; c < a.items.length; c++) {
            var d = this.bb(a.items[c]);
            b[c] = d;
        }
        return b;
    };
    ComponentRenderer.prototype.bb = function (a) {
        if (a == null) {
            return null;
        }
        var b = {};
        var dict_ = b;
        var c = a.a();
        for (var d = 0; d < c.length; d++) {
            var key_ = c[d];
            if (typeCast(JsonDictionaryObject.$, a.item(key_)) !== null) {
                var val_ = this.bb(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_;
    };
    ComponentRenderer.prototype.render = function (a, b) {
        this.cd(a, b, false, false);
    };
    ComponentRenderer.prototype.cd = function (a, b, c, d) {
        var _this = this;
        if (!this.an.containsKey(b)) {
            this.an.item(b, new ContainerState());
            this.an.item(b).e = b;
        }
        this.ai.item(b, a);
        this.aj.item(b, c);
        this.ak.item(b, d);
        this.b0(b, function () { return _this.cb(b); });
    };
    ComponentRenderer.prototype.b0 = function (a, b) {
        this.d.onUIThread(a, b);
    };
    ComponentRenderer.prototype.cb = function (a) {
        if (this.ai.containsKey(a)) {
            var b = this.aj.containsKey(a) ? this.aj.item(a) : false;
            var c = this.ak.containsKey(a) ? this.ak.item(a) : false;
            var d = this.ai.item(a);
            this.ai.removeItem(a);
            var e = DescriptionTreeBuilder.createTree(this.context, d);
            var f = null;
            if (this.ah.containsKey(a)) {
                f = this.ah.item(a);
            }
            var g = DescriptionTreeReconciler.b(f, e, b);
            if (b) {
                DescriptionTreeReconciler.f(f, g);
            }
            else {
                this.ah.item(a, e);
            }
            if (!c) {
                this.cc(a, g);
            }
        }
    };
    ComponentRenderer.prototype.provideRefValue = function (a, b, c) {
        var _this = this;
        this.b0(a, function () {
            if (!_this.an.containsKey(a)) {
                _this.an.addItem(a, ((function () {
                    var $ret = new ContainerState();
                    $ret.e = a;
                    return $ret;
                })()));
            }
            var d = _this.an.item(a);
            _this.b4(a, b, c, true);
        });
    };
    ComponentRenderer.prototype.removeRefValue = function (a, b) {
        var _this = this;
        this.b0(a, function () {
            if (!_this.an.containsKey(a)) {
                _this.an.addItem(a, ((function () {
                    var $ret = new ContainerState();
                    $ret.e = a;
                    return $ret;
                })()));
            }
            var c = _this.an.item(a);
            _this.removeRefValueCore(a, b, true);
        });
    };
    ComponentRenderer.prototype.clearRefValues = function (a) {
        var _this = this;
        this.b0(a, function () {
            if (!_this.an.containsKey(a)) {
                _this.an.addItem(a, ((function () {
                    var $ret = new ContainerState();
                    $ret.e = a;
                    return $ret;
                })()));
            }
            var b = _this.an.item(a);
            _this.clearUserRefValues();
        });
    };
    ComponentRenderer.prototype.cc = function (a, b) {
        var c = this.an.item(a);
        this.b1(a, c, b);
    };
    ComponentRenderer.prototype.cf = function (a, b) {
        this.bw(a, b, true);
    };
    ComponentRenderer.prototype.cl = function (a, b) {
        this.bw(a, b, false);
    };
    ComponentRenderer.prototype.bw = function (a, b, c) {
        if (!c) {
            if (this.ag.containsKey(a) && this.ag.item(a)) {
                return;
            }
        }
        this.ag.item(a, true);
        var d = true;
        while (d && this.al.item(a).count > 0) {
            while (this.al.item(a).count > 0 && this.al.item(a).c().count < 1) {
                this.al.item(a).b();
            }
            if (this.al.item(a).count < 1) {
                break;
            }
            var e = this.al.item(a).c();
            while (e.count > 0) {
                var f = e.b();
                d = this.t(a, b, f);
                if (!d) {
                    break;
                }
            }
        }
        if (d) {
            this.ag.item(a, false);
        }
    };
    ComponentRenderer.prototype.b1 = 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.al.containsKey(a)) {
            this.al.addItem(a, new Queue$1(Queue$1.$.specialize(DescriptionTreeAction.$)));
        }
        this.al.item(a).g(d);
        this.cl(a, b);
    };
    ComponentRenderer.prototype.b2 = function (a, b, c) {
        for (var d = 0; d < c.count; d++) {
            this.t(a, b, c._inner[d]);
        }
    };
    ComponentRenderer.prototype.t = function (a, b, c) {
        switch (c.a) {
            case 5: return this.u(a, b, c);
            case 2: return this.v(a, b, c);
            case 4: return this.w(a, b, c);
            case 3: return this.x(a, b, c);
            case 1: return this.y(a, b, c);
            case 0: return this.z(a, b, c);
        }
        return true;
    };
    ComponentRenderer.prototype.z = function (a, b, c) {
        var d = this.bh(a, b, c);
        this.af(a, b, c, d);
        return true;
    };
    ComponentRenderer.prototype.af = function (a, b, c, d) {
        var e = this.be(c, a, b);
        e = this.i.b(ComponentRenderer.platform, e, c);
        if (c.c != null && c.c.knownType == 9) {
            this.ad(a, b, c.h(ComponentRenderer.platform), c.c, e, d);
        }
        else {
            this.cj(a, b, c.h(ComponentRenderer.platform), e, c.g, d);
        }
        return true;
    };
    ComponentRenderer.prototype.ad = function (a, b, c, d, e, f) {
        var e_3, _a;
        if (this.ap.containsKey(c)) {
            try {
                for (var _b = tslib_1.__values(fromEnum(this.ap.item(c))), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var g = _c.value;
                    g(c, f, e);
                }
            }
            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;
                }
            }
        }
        this.d.setOrUpdateCollectionOnTarget(a, c, d, this.context, f, e);
        return true;
    };
    ComponentRenderer.prototype.be = function (a, b, c) {
        if (a.c == null) {
            return a.f;
        }
        switch (a.c.knownType) {
            case 10: return this.av(a, b, c);
            case 7: return this.aw(a);
            case 4: return this.ax(a);
            case 6: return this.ay(a);
            case 9: return this.av(a, b, c);
            case 5: return this.az(a);
            case 16: return this.a0(a);
            case 20: return this.bi(a, c);
            case 15: return null;
            case 3: return this.a1(a);
            case 19: return this.bj(a, c);
            case 8: return this.a3(a, b, c);
            case 13: return null;
            case 18: return this.bk(a, c);
            case 1: return this.a4(a);
            case 11: return this.a5(a);
            case 14: return this.a6(a);
            case 12: return this.a7(a);
            case 2: return this.a8(a);
            case 21: return this.a9(a);
            case 17: return this.ba(a, b, c);
            case 0: return null;
        }
        return null;
    };
    ComponentRenderer.prototype.ba = function (a, b, c) {
        if (typeCast(DescriptionTreeNode.$, a.f) !== null) {
            var d = a.f;
            if (d.h == "EmbeddedRef") {
                return this.bc(d.h, a.f, b, c);
            }
        }
        return a.f;
    };
    ComponentRenderer.prototype.a9 = function (a) {
        return a.f;
    };
    ComponentRenderer.prototype.a8 = function (a) {
        return a.f != null ? a.f.toString() : null;
    };
    ComponentRenderer.prototype.a7 = function (a) {
        var b = a.f;
        var width_ = b.width;
        var height_ = b.height;
        var c = { width: width_, height: height_ };
        return c;
    };
    ComponentRenderer.prototype.a6 = function (a) {
        var b = a.f;
        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.a5 = function (a) {
        var b = a.f;
        var x_ = b.x;
        var y_ = b.y;
        var c = { x: x_, y: y_ };
        return c;
    };
    ComponentRenderer.prototype.a4 = function (a) {
        if (a.f == null) {
            if (a.c != null && (a.c.specificType == "double" || a.c.specificType == "float")) {
                return NaN;
            }
            return 0;
        }
        return a.f;
    };
    ComponentRenderer.prototype.b = function (a) {
        if (this.am.containsKey(a)) {
            var b = this.am.item(a);
            return b;
        }
        var c = new DescriptionRef(a);
        this.am.addItem(a, c);
        return c;
    };
    ComponentRenderer.prototype.bk = function (a, b) {
        return a.f == null ? null : this.b(a.f);
    };
    ComponentRenderer.prototype.a3 = function (a, b, c) {
        var d = a.c.specificType;
        if (d == null) {
            d = a.c.specificExternalType;
        }
        if (typeCast(DescriptionTreeNode.$, a.f) !== null) {
            var e = a.f;
            if (e.b("Type")) {
                d = e.a("Type").b;
            }
        }
        var f = this.bc(d, a.f, b, c);
        return f;
    };
    ComponentRenderer.prototype.bj = function (a, b) {
        return a.f == null ? null : this.b(a.f);
    };
    ComponentRenderer.prototype.a1 = function (a) {
        return a.f;
    };
    ComponentRenderer.prototype.bi = function (a, b) {
        return a.f == null ? null : this.b(a.f);
    };
    ComponentRenderer.prototype.bm = function (a) {
        return a;
    };
    ComponentRenderer.prototype.a0 = function (a) {
        var b = a.f;
        if (b == null) {
            return null;
        }
        var c = new Array(b.length);
        for (var d = 0; d < b.length; d++) {
            c[d] = this.bm(b[d]);
        }
        return c;
    };
    ComponentRenderer.prototype.az = function (a) {
        return this.bm(a.f);
    };
    ComponentRenderer.prototype.ay = function (a) {
        var b = a.f;
        if (b == null) {
            return null;
        }
        var c = new Array(b.length);
        for (var d = 0; d < b.length; d++) {
            c[d] = this.bl(b[d]);
        }
        return c;
    };
    ComponentRenderer.prototype.bl = function (a) {
        return a;
    };
    ComponentRenderer.prototype.ax = function (a) {
        return this.bl(a.f);
    };
    ComponentRenderer.prototype.aw = function (a) {
        return a.f;
    };
    ComponentRenderer.prototype.addPropertyUpdatingListener = function (a, b) {
        if (!this.ap.containsKey(a)) {
            this.ap.addItem(a, new List$1(Delegate_$type, 0));
        }
        this.ap.item(a).add(b);
    };
    ComponentRenderer.prototype.addReferenceLookupListener = function (a) {
        this.ar.add(a);
    };
    ComponentRenderer.prototype.removePropertyUpdatingListener = function (a, b) {
        if (this.ap.containsKey(a)) {
            this.ap.item(a).remove(b);
            if (this.ap.item(a).count == 0) {
                this.ap.removeItem(a);
            }
        }
    };
    ComponentRenderer.prototype.addNamespaceLookupListener = function (a) {
        this.as.add(a);
    };
    ComponentRenderer.prototype.removeNamespaceLookupListener = function (a) {
        this.as.remove(a);
    };
    ComponentRenderer.prototype.av = function (a, b, c) {
        if (a.f == null) {
            return null;
        }
        var d = a.f;
        var e = new List$1(Base.$, 0);
        var f = a.c.specificType;
        if (f == null) {
            f = a.c.specificExternalType;
        }
        if (a.c.knownType == 9) {
            f = a.c.collectionElementType;
            if (f == null) {
                f = a.c.specificExternalType;
            }
        }
        for (var g = 0; g < d.length; g++) {
            var h = f;
            if (typeCast(DescriptionTreeNode.$, d[g]) !== null) {
                var i = d[g];
                if (i.b("Type")) {
                    h = i.a("Type").b;
                }
            }
            var j = this.bc(h, d[g], b, c);
            e.add1(j);
        }
        return e.toArray();
    };
    ComponentRenderer.prototype.cj = function (a, b, c, d, e, f) {
        var _this = this;
        if (typeCast(DescriptionRef.$, d) !== null) {
            var g = d;
            var h = false;
            if (e != null && typeof e === 'string') {
                if (this.n(e)) {
                    var i = this.c(e);
                    if (Base.equalsStatic(i, d)) {
                        h = true;
                    }
                    else {
                        i.i(f, c);
                    }
                }
            }
            if (this.o(d)) {
                d = this.bg(d);
                this.ck(f, c, d, e);
            }
            var j = null;
            j = function (k, l) {
                var m = _this.bg(k);
                _this.ck(f, c, m, e);
            };
            if (!h) {
                g.f(f, c, j);
            }
            return;
        }
        this.ck(f, c, d, e);
    };
    ComponentRenderer.prototype.hasUserRef = function (a) {
        return this.aq.containsKey(a);
    };
    Object.defineProperty(ComponentRenderer.prototype, "shouldNamespaceSystemRefValues", {
        get: function () {
            return this._shouldNamespaceSystemRefValues;
        },
        set: function (a) {
            this._shouldNamespaceSystemRefValues = a;
        },
        enumerable: true,
        configurable: true
    });
    ComponentRenderer.prototype.b4 = function (a, b, c, d) {
        var e = null;
        if (d) {
            if (this.aq.containsKey(b)) {
                e = this.aq.item(b);
            }
            this.aq.item(b, c);
        }
        else {
            if (this.shouldNamespaceSystemRefValues) {
                var f = "";
                if (this.as != null && this.as.count > 0) {
                    for (var g = 0; g < this.as.count; g++) {
                        f = this.as._inner[g](a);
                    }
                }
                if (!stringIsNullOrEmpty(f)) {
                    b = f + "/" + b;
                }
            }
            if (this.ao.containsKey(b)) {
                e = this.ao.item(b);
            }
            this.ao.item(b, c);
        }
        if (this.am.containsKey(b)) {
            this.am.item(b).e(e, c);
        }
    };
    ComponentRenderer.prototype.removeRefValueCore = function (a, b, c) {
        var d = null;
        if (c) {
            if (this.aq.containsKey(b)) {
                d = this.aq.item(b);
            }
            this.aq.removeItem(b);
        }
        else {
            if (this.shouldNamespaceSystemRefValues) {
                var e = "";
                if (this.as != null && this.as.count > 0) {
                    for (var f = 0; f < this.as.count; f++) {
                        e = this.as._inner[f](a);
                    }
                }
                if (!stringIsNullOrEmpty(e)) {
                    b = e + "/" + b;
                }
            }
            if (this.ao.containsKey(b)) {
                d = this.ao.item(b);
            }
            this.ao.removeItem(b);
        }
        if (this.am.containsKey(b)) {
            this.am.item(b).e(d, this.bg(this.am.item(b)));
            if (this.am.item(b).b <= 0) {
                this.am.item(b).g();
                this.am.removeItem(b);
            }
        }
    };
    ComponentRenderer.prototype.clearUserRefValues = function () {
        var e_4, _a, e_5, _b;
        var a = new List$1(String_$type, 0);
        try {
            for (var _c = tslib_1.__values(fromEnum(this.aq.keys)), _d = _c.next(); !_d.done; _d = _c.next()) {
                var b = _d.value;
                a.add(b);
            }
        }
        catch (e_4_1) {
            e_4 = { error: e_4_1 };
        }
        finally {
            try {
                if (_d && !_d.done && (_a = _c.return))
                    _a.call(_c);
            }
            finally {
                if (e_4)
                    throw e_4.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_5_1) {
            e_5 = { error: e_5_1 };
        }
        finally {
            try {
                if (_f && !_f.done && (_b = _e.return))
                    _b.call(_e);
            }
            finally {
                if (e_5)
                    throw e_5.error;
            }
        }
    };
    ComponentRenderer.prototype.o = function (a) {
        return this.aq.containsKey(a.d) || this.ao.containsKey(a.d);
    };
    ComponentRenderer.prototype.bg = function (a) {
        if (this.aq.containsKey(a.d)) {
            return this.aq.item(a.d);
        }
        if (this.ao.containsKey(a.d)) {
            return this.ao.item(a.d);
        }
        return null;
    };
    ComponentRenderer.prototype.n = function (a) {
        return this.am.containsKey(a);
    };
    ComponentRenderer.prototype.c = function (a) {
        return this.am.item(a);
    };
    ComponentRenderer.prototype.bh = function (a, b, c) {
        return b.f(c.b.f);
    };
    ComponentRenderer.prototype.y = function (a, b, c) {
        var d = this.bh(a, b, c);
        this.ac(a, b, c, d);
        return true;
    };
    ComponentRenderer.prototype.ac = function (a, b, c, d) {
        this.d.resetPropertyOnTarget(a, c.h(ComponentRenderer.platform), c.c, d);
        return true;
    };
    ComponentRenderer.prototype.x = function (a, b, c) {
        if (c.b == null) {
            return this.ab(a, b, c);
        }
        else {
            var d = this.bh(a, b, c);
            this.ce(a, b, c, d);
        }
        return true;
    };
    ComponentRenderer.prototype.ce = function (a, b, c, d) {
        var e = c.h(ComponentRenderer.platform);
        var f = this.bc(c.c.collectionElementType, c.f, a, b);
        this.d.replaceItemInCollection(e, c.c, d, c.d, f);
        if (c.g != null && typeCast(DescriptionTreeNode.$, c.g) !== null) {
            var g = c.g.f;
            if (g >= 0) {
                var h = b.f(g);
                if (h != null) {
                    this.bv(a, h, b);
                }
            }
        }
    };
    ComponentRenderer.prototype.ab = function (a, b, c) {
        var _this = this;
        var d = this.d.getRootObject(a);
        if (d != null) {
            this.bv(a, d, b);
        }
        if (!(typeCast(DescriptionTreeNode.$, c.f) !== null)) {
            throw new NotImplementedException(0);
        }
        var e = c.f;
        var f = false;
        this.d.replaceRootItem(a, e.h, this.context, function (g) {
            var h = _this.d.getRootObject(a);
            b.g(a, e.f, h, e, runOn(_this, _this.b4));
            var i = _this.at(e);
            _this.b2(a, b, i);
            f = true;
            if (g) {
                _this.cf(a, b);
            }
        });
        return f;
    };
    ComponentRenderer.prototype.bv = function (a, b, c) {
        var e_6, _a;
        var d = this.au(a, b, c);
        try {
            for (var _b = tslib_1.__values(fromEnum(this.am.values)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var e = _c.value;
                e.h(b);
            }
        }
        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;
            }
        }
        if (d != -1) {
            c.h(a, d, runOn(this, this.removeRefValueCore));
        }
        this.f.b(ComponentRenderer.platform, b);
    };
    ComponentRenderer.prototype.au = function (a, b, c) {
        return c.d(b);
    };
    ComponentRenderer.prototype.w = function (a, b, c) {
        if (c.b == null) {
            return this.aa(a, b, c);
        }
        else {
            var d = this.bh(a, b, c);
            this.b5(a, b, c, d);
        }
        return true;
    };
    ComponentRenderer.prototype.b5 = function (a, b, c, d) {
        var e = c.h(ComponentRenderer.platform);
        this.d.removeItemFromCollection(e, c.c, d, c.e);
        if (c.g != null && typeCast(DescriptionTreeNode.$, c.g) !== null) {
            var f = c.g.f;
            if (f >= 0) {
                var g = b.f(f);
                if (g != null) {
                    this.bv(a, g, b);
                }
            }
        }
    };
    ComponentRenderer.prototype.aa = function (a, b, c) {
        var _this = this;
        var d = this.d.getRootObject(a);
        if (d != null) {
            this.bv(a, d, b);
        }
        var e = false;
        this.d.removeRootItem(a, this.context, function (f) {
            e = true;
            if (f) {
                _this.cf(a, b);
            }
        });
        return e;
    };
    ComponentRenderer.prototype.v = function (a, b, c) {
        if (c.b == null) {
            return this.j(a, b, c);
        }
        else {
            var d = this.bh(a, b, c);
            this.bo(a, b, c, d);
        }
        return true;
    };
    ComponentRenderer.prototype.j = function (a, b, c) {
        var _this = this;
        if (!(typeCast(DescriptionTreeNode.$, c.f) !== null)) {
            throw new NotImplementedException(0);
        }
        var d = c.f;
        var e = false;
        this.d.replaceRootItem(a, d.h, this.context, function (f) {
            var g = _this.d.getRootObject(a);
            b.g(a, d.f, g, d, runOn(_this, _this.b4));
            var h = _this.at(d);
            _this.b2(a, b, h);
            e = true;
            if (f) {
                _this.cf(a, b);
            }
        });
        return e;
    };
    ComponentRenderer.prototype.bo = function (a, b, c, d) {
        var e = c.h(ComponentRenderer.platform);
        var f = c.c.collectionElementType;
        if (typeCast(DescriptionTreeNode.$, c.f) !== null) {
            var g = c.f;
            if (g.b("Type")) {
                f = g.a("Type").b;
            }
        }
        var h = this.bc(f, c.f, a, b);
        this.d.addItemToCollection(e, c.c, d, c.d, h);
    };
    ComponentRenderer.prototype.bc = function (a, b, c, d) {
        if (this.r(a)) {
            return b;
        }
        var e = null;
        if (b != null && typeCast(DescriptionTreeNode.$, b) !== null) {
            var f = b;
            if (f.b("Name")) {
                var g = f.a("Name").b;
                if (!stringIsNullOrEmpty(g)) {
                    if (this.shouldNamespaceSystemRefValues) {
                        var h = "";
                        if (this.as != null && this.as.count > 0) {
                            for (var i = 0; i < this.as.count; i++) {
                                h = this.as._inner[i](c);
                            }
                        }
                        if (!stringIsNullOrEmpty(h)) {
                            g = h + "/" + g;
                        }
                    }
                    if (this.ao.containsKey(g)) {
                        var j = this.ao.item(g);
                        e = j;
                    }
                }
            }
            if (e == null) {
                e = this.context.j(a, c);
            }
        }
        else {
            e = this.context.j(a, c);
        }
        if (b == null) {
            return e;
        }
        if (typeCast(DescriptionTreeNode.$, b) !== null) {
            var k = b;
            if (k.h == "EmbeddedRef") {
                var l = "uuid";
                var m = null;
                for (var n = 0; n < k.e().count; n++) {
                    if (k.e()._inner[n].c == "RefType") {
                        l = k.e()._inner[n].b;
                    }
                    if (k.e()._inner[n].c == "Value") {
                        m = k.e()._inner[n].b;
                    }
                }
                if (m != null) {
                    for (var o = 0; o < this.ar.count; o++) {
                        var p = this.ar._inner[o](c, l, m);
                        if (p != null) {
                            return p;
                        }
                    }
                    return null;
                }
            }
            else {
                d.g(c, k.f, e, k, runOn(this, this.b4));
                var q = this.at(k);
                this.b2(c, d, q);
            }
        }
        if (typeof b === 'string' && a.toLowerCase() != "string") {
            return this.a2(a, b);
        }
        if (a == "object" || a == "Object") {
            return b;
        }
        return e;
    };
    ComponentRenderer.prototype.r = 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.a2 = function (a, b) {
        return this.context.f(a, b);
    };
    ComponentRenderer.prototype.at = function (a) {
        var b = a.e();
        var c = new List$1(DescriptionTreeAction.$, 0);
        for (var d = 0; d < b.count; d++) {
            var e = new DescriptionTreeAction();
            e.a = 0;
            e.i = b._inner[d].c;
            e.c = b._inner[d].a;
            e.b = a;
            e.f = b._inner[d].b;
            c.add(e);
        }
        return c;
    };
    ComponentRenderer.prototype.u = function (a, b, c) {
        if (c.b == null) {
            return this.m(a, b, c);
        }
        else {
            var d = this.bh(a, b, c);
            this.bs(a, b, c, d);
        }
        return true;
    };
    ComponentRenderer.prototype.bs = function (a, b, c, d) {
        var e = c.h(ComponentRenderer.platform);
        this.d.clearCollection(d, e, c.c);
        if (c.g != null && typeCast(Array_$type, c.g) !== null) {
            var f = c.g;
            for (var g = 0; g < f.length; g++) {
                var h = f[g];
                if (h != null && typeCast(DescriptionTreeNode.$, h) !== null) {
                    var i = h.f;
                    if (i >= 0) {
                        var j = b.f(i);
                        if (j != null) {
                            this.bv(a, j, b);
                        }
                    }
                }
            }
        }
    };
    ComponentRenderer.prototype.ck = function (a, b, c, d) {
        var e_7, _a;
        if (this.ap.containsKey(b)) {
            try {
                for (var _b = tslib_1.__values(fromEnum(this.ap.item(b))), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var e = _c.value;
                    e(b, a, c);
                }
            }
            catch (e_7_1) {
                e_7 = { error: e_7_1 };
            }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return))
                        _a.call(_b);
                }
                finally {
                    if (e_7)
                        throw e_7.error;
                }
            }
        }
        this.d.setPropertyValue(a, b, c, d);
    };
    ComponentRenderer.prototype.bf = function (a, b) {
        return this.d.getPropertyValue(a, b);
    };
    ComponentRenderer.prototype.m = function (a, b, c) {
        return this.l(a, b);
    };
    ComponentRenderer.prototype.l = function (a, b) {
        var _this = this;
        var c = this.d.getRootObject(a);
        if (c != null) {
            this.bv(a, c, b);
        }
        var d = false;
        this.d.clearContainer(a, this.context, function (e) {
            d = true;
            if (e) {
                _this.cf(a, b);
            }
        });
        return d;
    };
    ComponentRenderer.$t = markType(ComponentRenderer, 'ComponentRenderer');
    ComponentRenderer.platform = 3;
    return ComponentRenderer;
}(Base));
export { ComponentRenderer };
//# sourceMappingURL=ComponentRenderer.js.map
