/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { Base, IEnumerable_$type, fromEnum, typeCast, Date_$type, Boolean_$type, Array_$type, runOn, Number_$type, Delegate_$type, String_$type, EnumUtil, typeGetValue, 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 { TypeDescriptionWellKnownType_$type } from "./TypeDescriptionWellKnownType";
import { Tuple$2 } from "./Tuple$2";
import { DescriptionRefTargetInfo } from "./DescriptionRefTargetInfo";
import { NotImplementedException } from "./NotImplementedException";
import { truncate } from "./number";
import { ComponentRendererAdapter } from "./ComponentRendererAdapter";
import { stringIsNullOrEmpty, stringStartsWith, stringEndsWith } from "./string";
/**
 * @hidden
 */
export let ComponentRenderer = /*@__PURE__*/ (() => {
    class ComponentRenderer extends Base {
        static get defaultInstance() {
            return ComponentRenderer._defaultInstance;
        }
        static set defaultInstance(a) {
            ComponentRenderer._defaultInstance = a;
        }
        get adapter() {
            return this._adapter;
        }
        set adapter(a) {
            this._adapter = a;
        }
        get context() {
            return this._context;
        }
        set context(a) {
            this._context = a;
        }
        get isProceedOnErrorEnabled() {
            return this._isProceedOnErrorEnabled;
        }
        set isProceedOnErrorEnabled(a) {
            this._isProceedOnErrorEnabled = a;
        }
        constructor() {
            super();
            this._adapter = null;
            this._context = null;
            this._isProceedOnErrorEnabled = false;
            this.j = null;
            this.k = null;
            this._preserveKeyOrder = false;
            this.ay = new Dictionary$2(Base.$, Description.$, 0);
            this.az = new Dictionary$2(Base.$, Boolean_$type, 0);
            this.a0 = new Dictionary$2(Base.$, Boolean_$type, 0);
            this.ax = new Dictionary$2(Base.$, Boolean_$type, 0);
            this.av = new Dictionary$2(Base.$, DescriptionTreeNode.$, 0);
            this.a3 = new Dictionary$2(Base.$, ContainerState.$, 0);
            this.a1 = new Dictionary$2(Base.$, Queue$1.$.specialize(Queue$1.$.specialize(DescriptionTreeAction.$)), 0);
            this.aw = new Dictionary$2(Base.$, List$1.$.specialize(Delegate_$type), 0);
            this.au = new Dictionary$2(Base.$, Boolean_$type, 0);
            this.a2 = new Dictionary$2(String_$type, DescriptionRef.$, 0);
            this.a4 = new Dictionary$2(String_$type, Base.$, 0);
            this.a6 = new Dictionary$2(String_$type, Base.$, 0);
            this.ba = new List$1(Delegate_$type, 0);
            this.a5 = new Dictionary$2(String_$type, List$1.$.specialize(Delegate_$type), 0);
            this.a8 = new List$1(Delegate_$type, 0);
            this.a9 = new List$1(Delegate_$type, 0);
            this._shouldNamespaceSystemRefValues = false;
            let a = this.i();
            this.adapter = a;
            let adapter_ = this.adapter;
            let 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.j = new TypeDescriptionPropretyTransforms();
            this.k = new TypeDescriptionCleanups();
        }
        i() {
            return (new ComponentRendererAdapter());
        }
        toJson(a) {
            let b = new DescriptionSerializerBuilder();
            let c = new DescriptionSerializer();
            b.f("{");
            b.i();
            b.f("\"descriptions\": {");
            b.i();
            let d = true;
            for (let e of fromEnum(this.av.keys)) {
                if (d) {
                    d = false;
                }
                else {
                    b.f(",");
                }
                let f = e;
                let g = this.av.item(e);
                let h = "root";
                h = a(f);
                if (stringIsNullOrEmpty(h)) {
                    h = "root";
                }
                b.e("\"" + h + "\"");
                b.e(": ");
                c.t(this.context, g, b);
            }
            b.f("");
            b.h();
            b.e("}");
            if (this.a6.count > 0) {
                b.e(",");
            }
            b.f("");
            if (this.a6.count > 0) {
                d = true;
                b.f("refs: {");
                b.i();
                for (let i of fromEnum(this.a6.keys)) {
                    if (!this.p(i, this.a6.item(i))) {
                        continue;
                    }
                    if (d) {
                        d = false;
                    }
                    else {
                        b.f(",");
                    }
                    this.d2(b, i, this.a6.item(i));
                }
                b.f("");
                b.h();
                b.f("}");
            }
            b.h();
            b.f("}");
            return b.toString();
        }
        d2(a, b, c) {
            a.e("\"" + b + "\": ");
            this.d3(a, c);
        }
        d3(a, b) {
            if (this.y(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) {
                    let 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.v(b)) {
                    a.f("[");
                    a.i();
                    let c = new DataSourceLocalDataProvider();
                    c.dataSource = b;
                    for (let d = 0; d < c.actualCount; d++) {
                        if (d > 0) {
                            a.f(",");
                        }
                        this.d1(a, c, d);
                    }
                    a.f("");
                    a.h();
                    a.e("]");
                }
                else {
                    let e = [b];
                    let f = new DataSourceLocalDataProvider();
                    f.dataSource = e;
                    this.d1(a, f, 0);
                }
            }
        }
        y(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;
        }
        v(a) {
            if (typeCast(Array_$type, a) !== null) {
                return true;
            }
            if (typeCast(IEnumerable_$type, a) !== null) {
                return true;
            }
            return false;
        }
        d1(a, b, c) {
            a.f("{");
            a.i();
            let d = b.actualSchema;
            for (let e = 0; e < d.propertyNames.length; e++) {
                if (e > 0) {
                    a.f(",");
                }
                let f = d.propertyNames[e];
                if (stringStartsWith(f, "[")) {
                    f = f.substr(1, f.length - 2);
                }
                a.e("\"" + f + "\"");
                a.e(": ");
                let 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:
                        let v_ = g;
                        a.e("\"" + (v_.toJSON()) + "\"");
                        break;
                    case 11:
                        this.d3(a, g);
                        break;
                }
            }
            a.h();
            a.f("}");
        }
        p(a, b) {
            if (b == null) {
                return true;
            }
            let v_ = b;
            if ((typeof v_ === 'function')) {
                return false;
            }
            return true;
        }
        createObjectFromJson(a, b) {
            let c = new JsonDictionaryParser();
            let d = c.parse(a);
            let e = new DescriptionSerializer();
            let f = false;
            let g = e.d(this.context, d, f, null, false);
            if (g.result == null) {
                return null;
            }
            let h = DescriptionTreeBuilder.createTree(this.context, g.result);
            let i = this.a3.item(b);
            if (h.c("Type")) {
                let j = h.a("Type").b;
                return this.bz(j, h, b, i, true, -1, null);
            }
            else {
                return this.by(typeCast(JsonDictionaryObject.$, d));
            }
        }
        loadJson(a, b) {
            this.dc(a, b, null, false, false, false);
        }
        loadJsonOverlay(a, b, c) {
            this.dc(a, b, c, true, false, true);
        }
        loadJsonDelta(a, b, c) {
            this.dc(a, b, null, true, c, false);
        }
        get preserveKeyOrder() {
            return this._preserveKeyOrder;
        }
        set preserveKeyOrder(a) {
            this._preserveKeyOrder = a;
        }
        ar() {
            return false;
        }
        de(a) {
        }
        dc(a, b, c, d, e, f) {
            let g = new JsonDictionaryParser();
            let h = g.parse(a);
            let i = new DescriptionSerializer();
            i.h = this.isProceedOnErrorEnabled;
            i.g = this.ar();
            let j = null;
            if (typeCast(JsonDictionaryObject.$, h) !== null) {
                let k = h;
                if (k.g("skipAlterDataCasing")) {
                    let l = k.item("skipAlterDataCasing");
                    if (l.value) {
                        this.de(true);
                    }
                }
                else {
                    this.de(false);
                }
                if (k.g("descriptions")) {
                    let m = k.item("descriptions");
                    if (typeCast(JsonDictionaryObject.$, m) !== null) {
                        let n = m;
                        let o = n.e();
                        for (let p = 0; p < o.length; p++) {
                            let q = o[p];
                            let r = n.item(q);
                            let s = b(q);
                            if (s == null) {
                                continue;
                            }
                            j = s;
                            let t = false;
                            let u = this.bd();
                            if (u != null) {
                                t = true;
                            }
                            let v = null;
                            if (this.isProceedOnErrorEnabled) {
                                try {
                                    v = i.d(this.context, r, t, u, false);
                                }
                                catch (w) {
                                    return;
                                }
                            }
                            else {
                                v = i.d(this.context, r, t, u, false);
                            }
                            if (v.result == null) {
                                continue;
                            }
                            if (f) {
                                if (!this.a7.containsKey(s)) {
                                    let x = null;
                                    if (this.isProceedOnErrorEnabled) {
                                        try {
                                            x = i.d(this.context, r, t, u, true);
                                        }
                                        catch (y) {
                                            return;
                                        }
                                    }
                                    else {
                                        x = i.d(this.context, r, t, u, true);
                                    }
                                    this.dy(x.result, s, d, true, false);
                                    let z = c(q);
                                    let aa = this.a7.item(s);
                                    this.c6(this.av.item(s), z, aa, s);
                                }
                            }
                            this.dy(v.result, s, d, e, false);
                        }
                    }
                }
                if (k.g("refs") && j != null) {
                    let ab = k.item("refs");
                    let ac = this.ah(ab);
                    if (!ac && typeCast(JsonDictionaryObject.$, ab) !== null) {
                        let ad = ab;
                        let ae = ad.e();
                        for (let af = 0; af < ae.length; af++) {
                            let ag = ae[af];
                            let ah = ad.item(ag);
                            if (typeCast(JsonDictionaryValue.$, ah) !== null) {
                                let ai = ah;
                                this.provideRefValue(j, ag, ai.value);
                            }
                            else if (typeCast(JsonDictionaryArray.$, ah) !== null) {
                                let aj = ah;
                                let ak = this.a(aj);
                                this.provideRefValue(j, ag, ak);
                            }
                            else {
                                let al = this.by(ah);
                                this.provideRefValue(j, ag, al);
                            }
                        }
                    }
                }
                if (k.g("modules") && j != null) {
                    let am = k.item("modules");
                    this.ae(am);
                }
                if (k.g("strings") && j != null) {
                    let an = k.item("strings");
                    this.al(an);
                }
                if (k.g("onInit") && j != null) {
                    let ao = k.item("onInit");
                    this.af(ao);
                }
                if (k.g("onViewInit") && j != null) {
                    let ap = k.item("onViewInit");
                    this.ag(ap);
                }
            }
        }
        provideRefValueFromJson(a, b, c) {
            let d = b;
            let e = new JsonDictionaryParser();
            let f = e.parse(c);
            if (typeCast(JsonDictionaryValue.$, f) !== null) {
                let g = f;
                this.provideRefValue(a, d, g.value);
            }
            else if (typeCast(JsonDictionaryArray.$, f) !== null) {
                let h = f;
                let i = this.a(h);
                this.provideRefValue(a, d, i);
            }
            else {
                let j = this.by(f);
                this.provideRefValue(a, d, j);
            }
        }
        bd() {
            return null;
        }
        ah(a) {
            return false;
        }
        ae(a) {
            return false;
        }
        al(a) {
            return false;
        }
        af(a) {
            return false;
        }
        ag(a) {
            return false;
        }
        co(a, b, c) {
            let 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;
        }
        c6(a, b, c, d) {
            if (!c.b(b)) {
                c.k(d, this.av.item(d).g, b, this.av.item(d), runOn(this, this.dj), -1);
            }
            for (let e of fromEnum(a.f())) {
                this.c7(this.co(e.c, ComponentRenderer.platform, e.a), e.b, b, c, d, a.g);
            }
        }
        c7(a, b, c, d, e, f) {
            if (typeCast(DescriptionTreeNode.$, b) !== null) {
                let g = b;
                let h = this.adapter.getPropertyValue(c, a);
                if (!d.b(h) && !d.a(g.g)) {
                    d.k(e, g.g, h, g, runOn(this, this.dj), f);
                }
                for (let i of fromEnum(g.f())) {
                    this.c7(a + "." + this.co(i.c, ComponentRenderer.platform, i.a), i.b, c, d, e, g.g);
                }
            }
            if (typeCast(Array_$type, b) !== null) {
                let j = new Dictionary$2(Number_$type, DescriptionTreeNode.$, 0);
                let k = 0;
                let l = b.length;
                let o = b;
                for (let n = 0; n < o.length; n++) {
                    let m = o[n];
                    if (typeCast(DescriptionTreeNode.$, m) !== null) {
                        let p = m;
                        j.item(k, p);
                    }
                    k++;
                }
                let q = this.adapter.getPropertyValue(c, a);
                k = 0;
                this.adapter.forPropertyValueItem(c, a, (r) => {
                    if (j.containsKey(k)) {
                        let s = j.item(k);
                        if (!d.b(r) && !d.a(s.g)) {
                            d.k(e, s.g, r, s, runOn(this, this.dj), f);
                        }
                        for (let t of fromEnum(s.f())) {
                            this.c7(a + "." + t.c, t.b, c, d, e, s.g);
                        }
                    }
                    k++;
                });
                if (l > 0 && k == 0) {
                    let r = this.ct(a);
                    this.adapter.forPropertyValueItem(c, r, (s) => {
                        if (j.containsKey(k)) {
                            let t = j.item(k);
                            if (!d.b(s) && !d.a(t.g)) {
                                d.k(e, t.g, s, t, runOn(this, this.dj), f);
                            }
                            for (let u of fromEnum(t.f())) {
                                this.c7(r + "." + u.c, u.b, c, d, e, t.g);
                            }
                        }
                        k++;
                    });
                }
            }
        }
        ct(a) {
            let b = a.lastIndexOf('.');
            let c = null;
            let d = a;
            if (b > 0) {
                c = a.substr(0, b);
                d = a.substr(b + 1);
            }
            d = "actual" + this.cq(d);
            if (c != null) {
                return c + "." + d;
            }
            return d;
        }
        cq(a) {
            return a.substr(0, 1).toUpperCase() + a.substr(1);
        }
        a(a) {
            let b = new Array(a.items.length);
            for (let c = 0; c < a.items.length; c++) {
                let d = this.by(a.items[c]);
                b[c] = d;
            }
            return b;
        }
        by(a) {
            if (a == null) {
                return null;
            }
            let b = {};
            let dict_ = b;
            let c = a.e();
            for (let d = 0; d < c.length; d++) {
                let key_ = c[d];
                if (typeCast(JsonDictionaryObject.$, a.item(key_)) !== null) {
                    let val_ = this.by(a.item(key_));
                    dict_[key_] = val_;
                }
                else if (typeCast(JsonDictionaryArray.$, a.item(key_)) !== null) {
                    let val_ = this.a(a.item(key_));
                    dict_[key_] = val_;
                }
                else {
                    let val_ = a.item(key_).value;
                    dict_[key_] = val_;
                }
            }
            return dict_;
        }
        get a7() {
            return this.a3;
        }
        cleanup(a, b) {
            this.dy(null, a, false, false, b);
        }
        render(a, b) {
            this.dy(a, b, false, false, false);
        }
        dy(a, b, c, d, e) {
            if (!this.a3.containsKey(b)) {
                this.a3.item(b, new ContainerState());
                this.a3.item(b).i = b;
            }
            this.ay.item(b, a);
            this.az.item(b, c);
            this.a0.item(b, d);
            this.ax.item(b, e);
            this.df(b, () => this.dw(b));
        }
        df(a, b) {
            this.adapter.onUIThread(a, b);
        }
        dw(a) {
            if (this.ay.containsKey(a)) {
                let b = this.az.containsKey(a) ? this.az.item(a) : false;
                let c = this.a0.containsKey(a) ? this.a0.item(a) : false;
                let d = this.ay.item(a);
                this.ay.removeItem(a);
                let e = DescriptionTreeBuilder.createTreeWithOptions(this.context, d, this.preserveKeyOrder);
                let f = null;
                if (this.av.containsKey(a)) {
                    f = this.av.item(a);
                }
                let g = DescriptionTreeReconciler.c(f, e, b);
                if (!c && b) {
                    e = f.b();
                    DescriptionTreeReconciler.a(f, g);
                    let h = f;
                    f = e;
                    e = h;
                    g = DescriptionTreeReconciler.c(f, e, false);
                }
                if (c) {
                    let i = DescriptionTreeReconciler.a(f, g);
                    if (!this.a3.containsKey(a)) {
                        this.a3.addItem(a, ((() => {
                            let $ret = new ContainerState();
                            $ret.i = a;
                            return $ret;
                        })()));
                    }
                    let j = this.a3.item(a);
                    if (i.a.count > 0) {
                        for (let k of fromEnum(i.a)) {
                            if (j.a(k)) {
                                let l = j.j(k);
                                this.c4(a, l, j);
                            }
                        }
                    }
                    if (i.c.count > 0) {
                        for (let m of fromEnum(i.c)) {
                            let n = this.b5(a, j, m);
                            let o = this.adapter.getPropertyValue(n, m.j);
                            if (o != null) {
                                if (!j.b(o)) {
                                    let p = m.g;
                                    if (typeCast(DescriptionTreeNode.$, p) !== null) {
                                        let q = p.g;
                                        j.k(a, q, o, p, runOn(this, this.dj), m.c.g);
                                    }
                                }
                            }
                        }
                    }
                    if (i.d.count > 0) {
                        for (let r of fromEnum(i.d)) {
                            let s = r.g;
                            if (s != null) {
                                if (!j.b(s)) {
                                    let t = r.g;
                                    if (typeCast(DescriptionTreeNode.$, t) !== null) {
                                        let u = t.g;
                                        this.av.item(a, t);
                                    }
                                }
                            }
                        }
                    }
                    if (i.b.count > 0) {
                        for (let v of fromEnum(i.b)) {
                            let w = v.c.a(v.j).b;
                            if (w == null) {
                                continue;
                            }
                            let x = new Dictionary$2(String_$type, DescriptionTreeNode.$, 0);
                            for (let y = 0; y < w.length; y++) {
                                let z = w[y];
                                if (typeCast(DescriptionTreeNode.$, z) !== null) {
                                    let aa = z;
                                    if (aa.c("Name")) {
                                        x.item(aa.a("Name").b, aa);
                                    }
                                }
                            }
                            if (x.count == 0) {
                                continue;
                            }
                            let ab = this.b5(a, j, v);
                            let ac = this.adapter.getPropertyValue(ab, v.j);
                            if (ac != null) {
                                let ad = 0;
                                this.adapter.forPropertyValueItem(ab, v.j, (ae) => {
                                    if (x.containsKey(this.adapter.getPropertyValue(ae, "Name").toString())) {
                                        if (!j.b(ae)) {
                                            let af = x.item(this.adapter.getPropertyValue(ae, "Name").toString());
                                            if (typeCast(DescriptionTreeNode.$, af) !== null) {
                                                let ag = af.g;
                                                j.k(a, ag, ae, af, runOn(this, this.dj), v.c.g);
                                            }
                                        }
                                    }
                                    ad++;
                                });
                            }
                        }
                    }
                }
                else {
                    this.av.item(a, e);
                }
                if (!c) {
                    this.dx(a, g);
                }
                if (this.ax.item(a)) {
                    this.du(a);
                    if (this.a3.containsKey(a)) {
                        this.a3.removeItem(a);
                    }
                }
            }
        }
        executeMethod(a, b, c) {
            let d = new JsonDictionaryParser();
            let e = d.parse(b);
            if (!this.a3.containsKey(a)) {
                this.a3.item(a, new ContainerState());
                this.a3.item(a).i = a;
            }
            let f = this.a3.item(a);
            let g = new DescriptionSerializer();
            g.h = this.isProceedOnErrorEnabled;
            g.g = this.ar();
            let h = this.av.item(a);
            let i = null;
            let j = new List$1(Base.$, 0);
            let k = new List$1(TypeDescriptionMetadata.$, 0);
            if (typeCast(JsonDictionaryObject.$, e) !== null) {
                let l = null;
                let m = e;
                if (m.g("targetRef")) {
                    l = this.cm(m, "targetRef");
                }
                let n = null;
                if (m.g("methodName")) {
                    n = this.cm(m, "methodName");
                }
                if (l != null) {
                    if (this.a4.containsKey(l)) {
                        i = this.a4.item(l);
                    }
                }
                else {
                    i = f.j(h.g);
                }
                if (m.g("args")) {
                    let o = m.item("args");
                    for (let p = 0; p < o.items.length; p++) {
                        let q = o.items[p];
                        let r = this.g(h, q, g);
                        let s = null;
                        if (typeCast(DescriptionTreeNode.$, r.g) !== null && r.g.i == "EmbeddedRef") {
                            s = this.b6(a, r.g);
                        }
                        else {
                            s = this.b2(r, a, f);
                        }
                        if (r.d.knownType == 8 && r.d.specificType == "string") {
                            s = this.bn(r.d.specificExternalType, s, r.d);
                        }
                        j.add1(s);
                        k.add(r.d);
                    }
                }
                let t = null;
                if (m.g("return")) {
                    let u = m.item("return");
                    let v = this.g(h, u, g);
                    t = v.d;
                }
                this.adapter.executeMethod(i, n, j.toArray(), k.toArray(), (w) => {
                    let x = this.cr(w, t);
                    c(x);
                });
            }
        }
        b6(a, b) {
            if (b.i == "EmbeddedRef") {
                let c = "uuid";
                let d = null;
                for (let e = 0; e < b.f().count; e++) {
                    if (b.f()._inner[e].c == "RefType") {
                        c = b.f()._inner[e].b;
                    }
                    if (b.f()._inner[e].c == "Value") {
                        d = b.f()._inner[e].b;
                    }
                }
                if (d != null) {
                    for (let f = 0; f < this.a8.count; f++) {
                        let g = this.a8._inner[f](a, c, d);
                        if (g != null) {
                            return g;
                        }
                    }
                    if (c == "name") {
                        let h = d;
                        if (this.a4.containsKey(h)) {
                            return this.a4.item(h);
                        }
                        if (this.a6.containsKey(h)) {
                            return this.a6.item(h);
                        }
                    }
                    return null;
                }
            }
            return null;
        }
        static bc(a) {
            if (typeCast(Date_$type, a) !== null) {
                return a.getTime();
            }
            if (a == null) {
                return 0;
            }
            return a;
        }
        cr(a, b) {
            let c = new JsonDictionaryObject();
            c.item("knownType", ((() => {
                let $ret = new JsonDictionaryValue();
                $ret.e = 2;
                $ret.value = EnumUtil.getName(TypeDescriptionWellKnownType_$type, b.knownType);
                return $ret;
            })()));
            if (b.specificType != null) {
                c.item("specificType", ((() => {
                    let $ret = new JsonDictionaryValue();
                    $ret.e = 2;
                    $ret.value = b.specificType;
                    return $ret;
                })()));
            }
            if (b.specificExternalType != null) {
                c.item("specificExternalType", ((() => {
                    let $ret = new JsonDictionaryValue();
                    $ret.e = 2;
                    $ret.value = b.specificExternalType;
                    return $ret;
                })()));
            }
            if (b.collectionElementType != null) {
                c.item("collectionElementType", ((() => {
                    let $ret = new JsonDictionaryValue();
                    $ret.e = 2;
                    $ret.value = b.collectionElementType;
                    return $ret;
                })()));
            }
            switch (b.knownType) {
                case 0: break;
                case 1:
                    c.item("result", ((() => {
                        let $ret = new JsonDictionaryValue();
                        $ret.e = 0;
                        $ret.value = ComponentRenderer.bc(a);
                        return $ret;
                    })()));
                    break;
                case 2:
                    c.item("result", ((() => {
                        let $ret = new JsonDictionaryValue();
                        $ret.e = 2;
                        $ret.value = a != null ? a.toString() : null;
                        return $ret;
                    })()));
                    break;
                case 3:
                    c.item("result", ((() => {
                        let $ret = new JsonDictionaryValue();
                        $ret.e = 2;
                        $ret.value = a != null ? a.toString() : null;
                        return $ret;
                    })()));
                    break;
                case 4:
                    c.item("result", ((() => {
                        let $ret = new JsonDictionaryValue();
                        $ret.e = 2;
                        $ret.value = this.b7(a);
                        return $ret;
                    })()));
                    break;
                case 5:
                    c.item("result", ((() => {
                        let $ret = new JsonDictionaryValue();
                        $ret.e = 2;
                        $ret.value = this.b9(a);
                        return $ret;
                    })()));
                    break;
                case 6:
                    c.item("result", ((() => {
                        let $ret = new JsonDictionaryValue();
                        $ret.e = 2;
                        $ret.value = this.b8(a);
                        return $ret;
                    })()));
                    break;
                case 7:
                    c.item("result", ((() => {
                        let $ret = new JsonDictionaryValue();
                        $ret.e = 1;
                        $ret.value = a;
                        return $ret;
                    })()));
                    break;
                case 8: break;
                case 9: break;
                case 10: break;
                case 11:
                    c.item("result", ((() => {
                        let $ret = new JsonDictionaryValue();
                        $ret.e = 2;
                        $ret.value = this.cc(a);
                        return $ret;
                    })()));
                    break;
                case 12:
                    c.item("result", ((() => {
                        let $ret = new JsonDictionaryValue();
                        $ret.e = 2;
                        $ret.value = this.ce(a);
                        return $ret;
                    })()));
                    break;
                case 13: break;
                case 14:
                    c.item("result", ((() => {
                        let $ret = new JsonDictionaryValue();
                        $ret.e = 2;
                        $ret.value = this.cd(a);
                        return $ret;
                    })()));
                    break;
                case 15: break;
                case 16:
                    c.item("result", ((() => {
                        let $ret = new JsonDictionaryValue();
                        $ret.e = 2;
                        $ret.value = this.ca(a);
                        return $ret;
                    })()));
                    break;
                case 17: break;
                case 18: break;
                case 19: break;
                case 20: break;
                case 21:
                    c.item("result", ((() => {
                        let $ret = new JsonDictionaryValue();
                        $ret.e = 2;
                        $ret.value = this.cf(a);
                        return $ret;
                    })()));
                    break;
                case 22: break;
                case 23:
                    c.item("result", ((() => {
                        let $ret = new JsonDictionaryValue();
                        $ret.e = 2;
                        $ret.value = this.cb(a);
                        return $ret;
                    })()));
                    break;
            }
            return c.b();
        }
        cb(a) {
            return this.adapter.serializeDoubleCollection(a);
        }
        cf(a) {
            return this.adapter.serializeTimespan(a);
        }
        ca(a) {
            return this.adapter.serializeColorCollection(a);
        }
        cd(a) {
            return this.adapter.serializeRect(a);
        }
        ce(a) {
            return this.adapter.serializeSize(a);
        }
        cc(a) {
            return this.adapter.serializePoint(a);
        }
        b8(a) {
            return this.adapter.serializeBrushCollection(a);
        }
        b9(a) {
            return this.adapter.serializeColor(a);
        }
        b7(a) {
            return this.adapter.serializeBrush(a);
        }
        g(a, b, c) {
            let d = new DescriptionTreeAction();
            d.a = 0;
            d.c = a;
            d.j = "*argument";
            let e = new TypeDescriptionMetadata();
            e.propertyName = "*argument";
            let f;
            let g = this.cm(b, "knownType");
            let h = EnumUtil.tryParse$1(TypeDescriptionWellKnownType_$type, g, true, f);
            f = h.p2;
            e.knownType = f;
            e.specificExternalType = this.cm(b, "specificExternalType");
            e.specificType = this.cm(b, "specificType");
            e.collectionElementType = this.cm(b, "collectionElementType");
            d.d = e;
            let i = null;
            i = this.b1(e, b, c);
            d.g = i;
            return d;
        }
        cm(a, b) {
            if (typeCast(JsonDictionaryObject.$, a) !== null) {
                let c = a;
                if (c.g(b)) {
                    return c.item(b).value != null ? c.item(b).value.toString() : null;
                }
            }
            return null;
        }
        b1(a, b, c) {
            if (typeCast(JsonDictionaryObject.$, b) !== null) {
                let d = b;
                if (d.g("value")) {
                    let e = (d.item("value")) != null ? (d.item("value")) : null;
                    return this.bx(a.knownType, a.specificType, a.specificExternalType, a.collectionElementType, e, c);
                }
            }
            return null;
        }
        bx(a, b, c, d, e, f) {
            if (typeCast(JsonDictionaryObject.$, e) !== null) {
                let g = e;
                if (g.g("type") || g.g("refType")) {
                    let h = f.c(this.context, g.b());
                    if (h != null) {
                        let i = h.result;
                        if (i == null) {
                            return null;
                        }
                        return DescriptionTreeBuilder.createTreeWithOptions(this.context, i, this.preserveKeyOrder);
                    }
                    return null;
                }
                else if (a == 11) {
                    let j = DescriptionSerializer.k(this.context, g);
                    return DescriptionTreeBuilder.createTreeWithOptions(this.context, j, this.preserveKeyOrder);
                }
                else if (a == 14) {
                    let k = DescriptionSerializer.k(this.context, g);
                    return DescriptionTreeBuilder.createTreeWithOptions(this.context, k, this.preserveKeyOrder);
                }
                else if (a == 12) {
                    let l = DescriptionSerializer.k(this.context, g);
                    return DescriptionTreeBuilder.createTreeWithOptions(this.context, l, this.preserveKeyOrder);
                }
            }
            else if (typeCast(JsonDictionaryArray.$, e) !== null) {
                let m = e;
                let n = "string";
                let o = false;
                if (a == 10) {
                    n = c;
                }
                if (a == 9) {
                    o = true;
                    n = d;
                }
                let p = new Array(m.items.length);
                let q;
                let r;
                let s;
                let t;
                let u = this.c9(o, n, b, c, q, r, s, t);
                q = u.p4;
                r = u.p5;
                s = u.p6;
                t = u.p7;
                if (m.items != null) {
                    for (let v = 0; v < m.items.length; v++) {
                        let w = m.items[v];
                        let x = this.bx(q, r, s, t, w, f);
                    }
                }
            }
            else if (typeCast(JsonDictionaryValue.$, e) !== null) {
                return e.value;
            }
            return e;
        }
        c9(a, b, c, d, e, f, g, h) {
            if (a) {
                e = 8;
                f = b;
                g = null;
                h = null;
                return {
                    p4: e,
                    p5: f,
                    p6: g,
                    p7: h
                };
            }
            let i = c;
            if (d != null) {
                i = d;
            }
            h = null;
            switch (d) {
                case "string":
                    if (c != null && c != "string") {
                        e = 8;
                        f = "string";
                        g = d;
                    }
                    else {
                        e = 2;
                        f = null;
                        g = null;
                    }
                    return {
                        p4: e,
                        p5: f,
                        p6: g,
                        p7: h
                    };
                case "double":
                    e = 1;
                    f = "double";
                    g = "double";
                    return {
                        p4: e,
                        p5: f,
                        p6: g,
                        p7: h
                    };
                case "int":
                    e = 1;
                    f = "double";
                    g = "double";
                    return {
                        p4: e,
                        p5: f,
                        p6: g,
                        p7: h
                    };
                case "long":
                    e = 1;
                    f = "double";
                    g = "double";
                    return {
                        p4: e,
                        p5: f,
                        p6: g,
                        p7: h
                    };
                case "bool":
                    e = 1;
                    f = "double";
                    g = "double";
                    return {
                        p4: e,
                        p5: f,
                        p6: g,
                        p7: h
                    };
            }
            e = 8;
            f = c;
            g = d;
            return {
                p4: e,
                p5: f,
                p6: g,
                p7: h
            };
        }
        provideRefValue(a, b, c) {
            this.df(a, () => {
                if (!this.a3.containsKey(a)) {
                    this.a3.addItem(a, ((() => {
                        let $ret = new ContainerState();
                        $ret.i = a;
                        return $ret;
                    })()));
                }
                let d = this.a3.item(a);
                this.dj(a, b, c, true);
            });
        }
        removeRefValue(a, b) {
            this.df(a, () => {
                if (!this.a3.containsKey(a)) {
                    this.a3.addItem(a, ((() => {
                        let $ret = new ContainerState();
                        $ret.i = a;
                        return $ret;
                    })()));
                }
                let c = this.a3.item(a);
                this.removeRefValueCore(a, b, true);
            });
        }
        du(a) {
            let b = this.a3.item(a);
            let c = new List$1(String_$type, 0);
            for (let d of fromEnum(this.a2.keys)) {
                if (this.a2.item(d).c == 0) {
                    c.add(d);
                }
            }
            for (let e = 0; e < c.count; e++) {
                let f = this.shouldNamespaceSystemRefValues;
                this.shouldNamespaceSystemRefValues = false;
                this.removeRefValueCore(a, c._inner[e], this.a6.containsKey(c._inner[e]));
                this.shouldNamespaceSystemRefValues = f;
            }
        }
        clearRefValues(a) {
            this.df(a, () => {
                if (!this.a3.containsKey(a)) {
                    this.a3.addItem(a, ((() => {
                        let $ret = new ContainerState();
                        $ret.i = a;
                        return $ret;
                    })()));
                }
                let b = this.a3.item(a);
                this.clearUserRefValues();
            });
        }
        w(a) {
            if (this.au.containsKey(a) && this.au.item(a)) {
                return false;
            }
            if (this.a1.containsKey(a) && this.a1.item(a).count > 0) {
                return false;
            }
            return true;
        }
        queueForIdle(a, b) {
            this.df(a, () => {
                if (this.w(a)) {
                    b();
                }
                else {
                    if (!this.aw.containsKey(a)) {
                        this.aw.item(a, new List$1(Delegate_$type, 0));
                    }
                    this.aw.item(a).add(b);
                }
            });
        }
        tryFlushIdleActions(a) {
            if (this.w(a)) {
                if (this.aw.containsKey(a)) {
                    let b = new List$1(Delegate_$type, 1, this.aw.item(a));
                    this.aw.item(a).clear();
                    for (let c = 0; c < b.count; c++) {
                        b._inner[c]();
                    }
                }
            }
        }
        dx(a, b) {
            let c = this.a3.item(a);
            this.dg(a, c, b);
        }
        d0(a, b) {
            if (this.isProceedOnErrorEnabled) {
                try {
                    this.c5(a, b, true);
                }
                catch (c) {
                    this.au.item(a, false);
                }
            }
            else {
                this.c5(a, b, true);
            }
        }
        d6(a, b) {
            if (this.isProceedOnErrorEnabled) {
                try {
                    this.c5(a, b, false);
                }
                catch (c) {
                    this.au.item(a, false);
                }
            }
            else {
                this.c5(a, b, false);
            }
        }
        c5(a, b, c) {
            if (!c) {
                if (this.au.containsKey(a) && this.au.item(a)) {
                    return;
                }
            }
            this.au.item(a, true);
            let d = true;
            while (d && this.a1.item(a).count > 0) {
                while (this.a1.item(a).count > 0 && this.a1.item(a).c().count < 1) {
                    this.a1.item(a).b();
                }
                if (this.a1.item(a).count < 1) {
                    break;
                }
                let e = this.a1.item(a).c();
                while (e.count > 0) {
                    let f = e.b();
                    d = this.ab(a, b, f);
                    if (!d) {
                        break;
                    }
                }
            }
            if (d) {
                this.au.item(a, false);
            }
            if (this.w(a)) {
                this.tryFlushIdleActions(a);
            }
        }
        dg(a, b, c) {
            let d = new Queue$1(DescriptionTreeAction.$);
            for (let e = 0; e < c.count; e++) {
                d.g(c._inner[e]);
            }
            if (!this.a1.containsKey(a)) {
                this.a1.addItem(a, new Queue$1(Queue$1.$.specialize(DescriptionTreeAction.$)));
            }
            this.a1.item(a).g(d);
            this.d6(a, b);
        }
        dh(a, b, c) {
            for (let d = 0; d < c.count; d++) {
                this.ab(a, b, c._inner[d]);
            }
        }
        ab(a, b, c) {
            switch (c.a) {
                case 5: return this.ac(a, b, c);
                case 2: return this.ad(a, b, c);
                case 4: return this.ai(a, b, c);
                case 3: return this.aj(a, b, c);
                case 1: return this.ak(a, b, c);
                case 0: return this.am(a, b, c);
            }
            return true;
        }
        am(a, b, c) {
            let d = this.b5(a, b, c);
            this.at(a, b, c, d);
            return true;
        }
        at(a, b, c, d) {
            let e = this.b2(c, a, b);
            e = this.j.transform(ComponentRenderer.platform, e, c);
            let f = false;
            if (this.ba != null && this.ba.count > 0) {
                for (let g = 0; g < this.ba.count; g++) {
                    let h = this.ba._inner[g];
                    let i = this.cp(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.aq(a, b, c.i(ComponentRenderer.platform), c.d, e, d);
            }
            else {
                this.d4(a, b, c.i(ComponentRenderer.platform), c.d, e, c.h, d);
            }
            return true;
        }
        cp(a, b) {
            let c = b.c;
            let d = "";
            if (c != this.av.item(a)) {
                let e = this.cn(a, c);
                d = e;
            }
            if (d.length > 0) {
                d += ".";
            }
            d += b.j;
            return d;
        }
        cn(a, b) {
            if (b == null) {
                return "";
            }
            let c = this.cu("", this.av.item(a), b);
            if (c.c) {
                return c.d;
            }
            return "";
        }
        cu(a, b, c) {
            if (b == c) {
                return new Tuple$2(Boolean_$type, String_$type, true, a);
            }
            if (a.length > 0) {
                a += ".";
            }
            let d = b.f();
            for (let e = 0; e < d.count; e++) {
                let 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 {
                        let g = a + f.c;
                        let h = this.cu(g, f.b, c);
                        if (h.c) {
                            return h;
                        }
                    }
                }
                if (f.a != null && f.a.knownType == 9) {
                    let i = f.b;
                    for (let j = 0; j < i.length; j++) {
                        if (typeCast(DescriptionTreeNode.$, i[j]) !== null) {
                            let k = i[j];
                            if (k.g == c.g) {
                                a += f.c + "[" + j + "]";
                                return new Tuple$2(Boolean_$type, String_$type, true, a);
                            }
                            else {
                                let l = a + f.c + "[" + j + "]";
                                let m = this.cu(l, k, c);
                                if (m.c) {
                                    return m;
                                }
                            }
                        }
                    }
                }
            }
            return new Tuple$2(Boolean_$type, String_$type, false, a);
        }
        aq(a, b, c, d, e, f) {
            if (this.a5.containsKey(c)) {
                for (let g of fromEnum(this.a5.item(c))) {
                    g(c, f, e);
                }
            }
            this.adapter.setOrUpdateCollectionOnTarget(a, c, d, this.context, f, e);
            return true;
        }
        b2(a, b, c) {
            if (a.d == null) {
                return a.g;
            }
            switch (a.d.knownType) {
                case 10: return this.bf(a, b, c);
                case 7: return this.bg(a);
                case 4: return this.bh(a);
                case 6: return this.bi(a);
                case 23: return this.bm(a);
                case 9: return this.bf(a, b, c);
                case 5: return this.bj(a);
                case 16: return this.bk(a);
                case 20: return this.cg(a, c);
                case 22: return this.cj(a, c);
                case 15: return null;
                case 3: return this.bl(a);
                case 19: return this.ch(a, c);
                case 8: return this.bo(a, b, c);
                case 13: return null;
                case 18: return this.ci(a, c);
                case 1: return this.bp(a);
                case 11: return this.bq(a);
                case 14: return this.br(a);
                case 12: return this.bs(a);
                case 2: return this.bt(a);
                case 21: return this.bu(a);
                case 17: return this.bv(a, b, c);
                case 0: return null;
            }
            return null;
        }
        bv(a, b, c) {
            let d = this.bw(a.g, a, b, c);
            return d;
        }
        bw(a, b, c, d) {
            if (typeof a === 'string') {
                if (stringStartsWith(a, "@d:")) {
                    let v_ = a.substr(3);
                    a = new Date(v_);
                }
            }
            if (typeCast(Array_$type, a) !== null) {
                let e = a;
                let f = new Array(e.length);
                for (let g = 0; g < e.length; g++) {
                    let h = this.bw(e[g], b, c, d);
                    f[g] = h;
                }
                a = f;
            }
            if (typeCast(DescriptionTreeNode.$, a) !== null) {
                let i = a;
                if (i.i == "EmbeddedRef") {
                    return this.bz(i.i, a, c, d, false, b.c.g, b.d);
                }
            }
            return a;
        }
        bu(a) {
            return a.g;
        }
        bt(a) {
            return a.g != null ? a.g.toString() : null;
        }
        bs(a) {
            let b = a.g;
            let width_ = b.width;
            let height_ = b.height;
            let c = { width: width_, height: height_ };
            return c;
        }
        br(a) {
            let b = a.g;
            let top_ = b.top;
            let left_ = b.left;
            let width_ = b.width;
            let height_ = b.height;
            let c = { left: left_, top: top_, width: width_, height: height_ };
            return c;
        }
        bq(a) {
            let b = a.g;
            let x_ = b.x;
            let y_ = b.y;
            let c = { x: x_, y: y_ };
            return c;
        }
        bp(a) {
            if (a.g == null) {
                if (a.d != null && ((a.d.specificType == "double" || a.d.specificType == "float") || (a.d.specificExternalType == "double" || a.d.specificExternalType == "float"))) {
                    return NaN;
                }
                return 0;
            }
            let b = a.g;
            if (typeof b === 'number') {
                b = typeGetValue(b);
            }
            if (a.d != null && a.d.specificExternalType != null) {
                switch (a.d.specificExternalType) {
                    case "int":
                        b = truncate(b);
                        break;
                    case "float":
                        b = b;
                        break;
                    case "short":
                        b = truncate(b);
                        break;
                    case "long":
                        b = truncate(b);
                        break;
                }
            }
            return b;
        }
        e(a, b) {
            if (this.a2.containsKey(a)) {
                let c = this.a2.item(a);
                return c;
            }
            let d = new DescriptionRef(a);
            this.a2.addItem(a, d);
            return d;
        }
        ci(a, b) {
            return a.g == null ? null : this.e(a.g, b);
        }
        bo(a, b, c) {
            let d = a.d.specificType;
            if (d == null) {
                d = a.d.specificExternalType;
            }
            if (typeCast(DescriptionTreeNode.$, a.g) !== null) {
                let e = a.g;
                if (e.c("Type")) {
                    d = e.a("Type").b;
                }
            }
            let f = this.bz(d, a.g, b, c, false, a.c.g, a.d);
            return f;
        }
        ch(a, b) {
            return a.g == null ? null : this.e(a.g, b);
        }
        bl(a) {
            if (typeof a.g === 'string') {
                let v_ = a.g;
                a.g = new Date(v_);
            }
            return a.g;
        }
        cg(a, b) {
            return a.g == null ? null : this.e(a.g, b);
        }
        cj(a, b) {
            return a.g == null ? null : this.e(a.g, b);
        }
        cl(a) {
            return a;
        }
        bk(a) {
            let b = a.g;
            if (b == null) {
                return null;
            }
            let c = new Array(b.length);
            for (let d = 0; d < b.length; d++) {
                c[d] = this.cl(b[d]);
            }
            return c;
        }
        bj(a) {
            return this.cl(a.g);
        }
        bi(a) {
            let b = a.g;
            if (b == null) {
                return null;
            }
            let c = new Array(b.length);
            for (let d = 0; d < b.length; d++) {
                c[d] = this.ck(b[d]);
            }
            return c;
        }
        bm(a) {
            let b = a.g;
            if (b == null) {
                return null;
            }
            let c = new Array(b.length);
            for (let d = 0; d < b.length; d++) {
                c[d] = b[d];
            }
            return c;
        }
        ck(a) {
            return a;
        }
        bh(a) {
            return this.ck(a.g);
        }
        bg(a) {
            return a.g;
        }
        addTargetPropertyUpdatingListener(a) {
            this.ba.add(a);
        }
        removeTargetPropertyUpdatingListener(a) {
            this.ba.remove(a);
        }
        addPropertyUpdatingListener(a, b) {
            if (!this.a5.containsKey(a)) {
                this.a5.addItem(a, new List$1(Delegate_$type, 0));
            }
            this.a5.item(a).add(b);
        }
        addReferenceLookupListener(a) {
            this.a8.add(a);
        }
        removeReferenceLookupListener(a) {
            this.a8.remove(a);
        }
        removePropertyUpdatingListener(a, b) {
            if (this.a5.containsKey(a)) {
                this.a5.item(a).remove(b);
                if (this.a5.item(a).count == 0) {
                    this.a5.removeItem(a);
                }
            }
        }
        addNamespaceLookupListener(a) {
            this.a9.add(a);
        }
        removeNamespaceLookupListener(a) {
            this.a9.remove(a);
        }
        bf(a, b, c) {
            if (a.g == null) {
                return null;
            }
            let d = a.g;
            let e = new List$1(Base.$, 0);
            let 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 (let g = 0; g < d.length; g++) {
                let h = f;
                if (typeCast(DescriptionTreeNode.$, d[g]) !== null) {
                    let i = d[g];
                    if (i.c("Type")) {
                        h = i.a("Type").b;
                    }
                }
                let j = this.bz(h, d[g], b, c, false, a.c.g, a.d);
                e.add1(j);
            }
            return e.toArray();
        }
        d4(a, b, c, d, e, f, g) {
            if (typeCast(DescriptionRef.$, e) !== null) {
                let h = e;
                let i = false;
                if (f != null && typeof f === 'string') {
                    if (this.s(f)) {
                        let j = this.f(f);
                        if (Base.equalsStatic(j, e)) {
                            i = true;
                        }
                        else {
                            j.j(a, g, c);
                        }
                    }
                }
                if (this.t(e)) {
                    let k = e;
                    if (k.e != null && k.e.length > 0 && this.a4.containsKey(k.e)) {
                        k.a = true;
                    }
                    e = this.b4(e);
                    this.d5(g, c, d, e, f, k);
                }
                else {
                    this.adapter.onPendingRef(g, c, d, e);
                }
                let l = null;
                l = (m, n) => {
                    let o = m;
                    if (o.e != null && o.e.length > 0 && this.a4.containsKey(o.e)) {
                        o.a = true;
                    }
                    let p = this.b4(m);
                    this.d5(g, c, d, p, f, o);
                };
                if (!i) {
                    h.g(a, g, c, l);
                }
                return;
            }
            this.d5(g, c, d, e, f, null);
        }
        hasUserRef(a) {
            return this.a6.containsKey(a);
        }
        get shouldNamespaceSystemRefValues() {
            return this._shouldNamespaceSystemRefValues;
        }
        set shouldNamespaceSystemRefValues(a) {
            this._shouldNamespaceSystemRefValues = a;
        }
        dj(a, b, c, d) {
            let e = null;
            if (d) {
                if (this.a6.containsKey(b)) {
                    e = this.a6.item(b);
                }
                this.a6.item(b, c);
            }
            else {
                if (this.shouldNamespaceSystemRefValues) {
                    let f = "";
                    if (this.a9 != null && this.a9.count > 0) {
                        for (let g = 0; g < this.a9.count; g++) {
                            f = this.a9._inner[g](a);
                        }
                    }
                    if (!stringIsNullOrEmpty(f)) {
                        b = f + "/" + b;
                    }
                }
                if (this.a4.containsKey(b)) {
                    e = this.a4.item(b);
                }
                this.a4.item(b, c);
                if (this.a2.containsKey(b)) {
                    this.a2.item(b).a = true;
                }
            }
            if (this.a2.containsKey(b)) {
                this.a2.item(b).f(e, c);
            }
        }
        removeRefValueCore(a, b, c) {
            let d = null;
            if (c) {
                if (this.a6.containsKey(b)) {
                    d = this.a6.item(b);
                }
                this.a6.removeItem(b);
            }
            else {
                if (this.shouldNamespaceSystemRefValues) {
                    let e = "";
                    if (this.a9 != null && this.a9.count > 0) {
                        for (let f = 0; f < this.a9.count; f++) {
                            e = this.a9._inner[f](a);
                        }
                    }
                    if (!stringIsNullOrEmpty(e)) {
                        b = e + "/" + b;
                    }
                }
                if (this.a4.containsKey(b)) {
                    d = this.a4.item(b);
                }
                this.a4.removeItem(b);
            }
            if (this.a2.containsKey(b)) {
                this.a2.item(b).f(d, this.b4(this.a2.item(b)));
                if (this.a2.item(b).c <= 0) {
                    this.a2.item(b).h();
                    this.a2.removeItem(b);
                }
            }
        }
        clearUserRefValues() {
            let a = new List$1(String_$type, 0);
            for (let b of fromEnum(this.a6.keys)) {
                a.add(b);
            }
            for (let c of fromEnum(a)) {
                this.removeRefValueCore(null, c, true);
            }
        }
        t(a) {
            return this.a6.containsKey(a.e) || this.a4.containsKey(a.e);
        }
        b4(a) {
            if (this.a6.containsKey(a.e)) {
                return this.a6.item(a.e);
            }
            if (this.a4.containsKey(a.e)) {
                return this.a4.item(a.e);
            }
            return null;
        }
        s(a) {
            return this.a2.containsKey(a);
        }
        f(a) {
            return this.a2.item(a);
        }
        getMissingRefs() {
            let a = new List$1(String_$type, 0);
            for (let b of fromEnum(this.a2.keys)) {
                if (!this.t(this.a2.item(b))) {
                    a.add(b);
                }
            }
            return a.toArray();
        }
        getRefChangeInfos(a) {
            let b = new List$1(DescriptionRefTargetInfo.$, 0);
            if (this.a2.containsKey(a)) {
                for (let c of fromEnum(this.a2.item(a).b)) {
                    b.add(((() => {
                        let $ret = new DescriptionRefTargetInfo();
                        $ret.container = c.b;
                        $ret.propertyName = c.d;
                        $ret.target = c.c;
                        return $ret;
                    })()));
                }
            }
            return b.toArray();
        }
        b5(a, b, c) {
            return b.j(c.c.g);
        }
        ak(a, b, c) {
            let d = this.b5(a, b, c);
            this.ap(a, b, c, d);
            return true;
        }
        ap(a, b, c, d) {
            this.adapter.resetPropertyOnTarget(a, c.i(ComponentRenderer.platform), c.d, d);
            return true;
        }
        aj(a, b, c) {
            if (c.c == null) {
                return this.ao(a, b, c);
            }
            else {
                let d = this.b5(a, b, c);
                this.dz(a, b, c, d);
            }
            return true;
        }
        dz(a, b, c, d) {
            let e = c.i(ComponentRenderer.platform);
            let f = c.d.collectionElementType;
            if (f == null) {
                f = c.d.specificExternalType;
            }
            let g = this.bz(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) {
                let h = c.h.g;
                if (h >= 0) {
                    let i = b.j(h);
                    if (i != null) {
                        this.c4(a, i, b);
                    }
                }
            }
        }
        ao(a, b, c) {
            let d = this.adapter.getRootObject(a);
            if (d != null) {
                this.c4(a, d, b);
            }
            if (!(typeCast(DescriptionTreeNode.$, c.g) !== null)) {
                throw new NotImplementedException(0);
            }
            let e = c.g;
            let f = false;
            this.adapter.replaceRootItem(a, e.i, this.context, (g) => {
                let h = this.adapter.getRootObject(a);
                b.k(a, e.g, h, e, runOn(this, this.dj), -1);
                let i = this.bb(e);
                this.dh(a, b, i);
                f = true;
                if (g) {
                    this.d0(a, b);
                }
            });
            return f;
        }
        c4(a, b, c) {
            let d = this.be(a, b, c);
            for (let e of fromEnum(this.a2.values)) {
                e.i(b);
            }
            if (d != -1) {
                c.l(this, a, d, runOn(this, this.removeRefValueCore));
            }
            this.k.b(ComponentRenderer.platform, b);
        }
        be(a, b, c) {
            return c.h(b);
        }
        ai(a, b, c) {
            if (c.c == null) {
                return this.an(a, b, c);
            }
            else {
                let d = this.b5(a, b, c);
                this.dm(a, b, c, d);
            }
            return true;
        }
        dm(a, b, c, d) {
            let e = c.i(ComponentRenderer.platform);
            this.adapter.removeItemFromCollection(e, c.d, d, c.f);
            if (c.h != null && typeCast(DescriptionTreeNode.$, c.h) !== null) {
                let f = c.h.g;
                if (f >= 0) {
                    let g = b.j(f);
                    if (g != null) {
                        this.c4(a, g, b);
                    }
                }
            }
        }
        an(a, b, c) {
            let d = this.adapter.getRootObject(a);
            if (d != null) {
                this.c4(a, d, b);
            }
            let e = false;
            this.adapter.removeRootItem(a, this.context, (f) => {
                e = true;
                if (f) {
                    this.d0(a, b);
                }
            });
            return e;
        }
        ad(a, b, c) {
            if (c.c == null) {
                return this.n(a, b, c);
            }
            else {
                let d = this.b5(a, b, c);
                this.cv(a, b, c, d);
            }
            return true;
        }
        n(a, b, c) {
            if (!(typeCast(DescriptionTreeNode.$, c.g) !== null)) {
                throw new NotImplementedException(0);
            }
            let d = c.g;
            let e = false;
            this.adapter.replaceRootItem(a, d.i, this.context, (f) => {
                let g = this.adapter.getRootObject(a);
                b.k(a, d.g, g, d, runOn(this, this.dj), -1);
                let h = this.bb(d);
                this.dh(a, b, h);
                e = true;
                if (f) {
                    this.d0(a, b);
                }
            });
            return e;
        }
        cv(a, b, c, d) {
            let e = c.i(ComponentRenderer.platform);
            let f = c.d.collectionElementType;
            if (typeCast(DescriptionTreeNode.$, c.g) !== null) {
                let g = c.g;
                if (g.c("Type")) {
                    f = g.a("Type").b;
                }
            }
            if (f == null) {
                f = c.d.specificExternalType;
            }
            let h = this.bz(f, c.g, a, b, false, c.c.g, c.d);
            this.adapter.addItemToCollection(e, c.d, d, c.e, h);
        }
        bz(a, b, c, d, e, f, g) {
            if (this.x(a)) {
                return b;
            }
            let h = null;
            if (b != null && typeCast(DescriptionTreeNode.$, b) !== null) {
                let i = b;
                let j = null;
                if (i.c("Name")) {
                    j = i.a("Name").b;
                    if (!stringIsNullOrEmpty(j)) {
                        if (this.shouldNamespaceSystemRefValues) {
                            let k = "";
                            if (this.a9 != null && this.a9.count > 0) {
                                for (let l = 0; l < this.a9.count; l++) {
                                    k = this.a9._inner[l](c);
                                }
                            }
                            if (!stringIsNullOrEmpty(k)) {
                                j = k + "/" + j;
                            }
                        }
                        if (this.a4.containsKey(j)) {
                            let m = this.a4.item(j);
                            h = m;
                        }
                    }
                }
                if (h == null) {
                    h = this.context.x(a, c, j);
                }
            }
            else if (b != null) {
                h = this.context.x(a, c, null);
            }
            if (b == null) {
                return h;
            }
            if (typeCast(DescriptionTreeNode.$, b) !== null) {
                let n = b;
                if (n.i == "EmbeddedRef") {
                    let o = "uuid";
                    let p = null;
                    for (let 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 (let r = 0; r < this.a8.count; r++) {
                            let s = this.a8._inner[r](c, o, p);
                            if (s != null) {
                                return s;
                            }
                        }
                        if (o == "name") {
                            let t = p;
                            if (this.a4.containsKey(t)) {
                                return this.a4.item(t);
                            }
                        }
                        return null;
                    }
                }
                else {
                    d.k(c, n.g, h, n, runOn(this, this.dj), f);
                    let u = this.bb(n);
                    this.dh(c, d, u);
                    if (e) {
                        d.l(this, c, n.g, runOn(this, this.removeRefValueCore));
                    }
                }
            }
            let v = (a == "object" || a == "Object");
            let w = v && typeof b === 'string' && stringStartsWith(b.toString(), "[") && stringEndsWith(b.toString(), "]");
            if (w) {
                let newVal_ = b;
                let x = JSON.parse(newVal_);
                return x;
            }
            if (!v && typeof b === 'string' && a.toLowerCase() != "string") {
                return this.bn(a, b, g);
            }
            if (v) {
                return b;
            }
            return h;
        }
        x(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";
        }
        bn(a, b, c) {
            return this.context.s(a, b, c, this.o());
        }
        o() {
            return true;
        }
        bb(a) {
            let b = a.f();
            let c = new List$1(DescriptionTreeAction.$, 0);
            for (let d = 0; d < b.count; d++) {
                let 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;
        }
        ac(a, b, c) {
            if (c.c == null) {
                return this.r(a, b, c);
            }
            else {
                let d = this.b5(a, b, c);
                this.c1(a, b, c, d);
            }
            return true;
        }
        c1(a, b, c, d) {
            let e = c.i(ComponentRenderer.platform);
            this.adapter.clearCollection(d, e, c.d);
            if (c.h != null && typeCast(Array_$type, c.h) !== null) {
                let f = c.h;
                for (let g = 0; g < f.length; g++) {
                    let h = f[g];
                    if (h != null && typeCast(DescriptionTreeNode.$, h) !== null) {
                        let i = h.g;
                        if (i >= 0) {
                            let j = b.j(i);
                            if (j != null) {
                                this.c4(a, j, b);
                            }
                        }
                    }
                }
            }
        }
        d5(a, b, c, d, e, f) {
            if (this.a5.containsKey(b)) {
                for (let g of fromEnum(this.a5.item(b))) {
                    g(b, a, d);
                }
            }
            this.adapter.setPropertyValue(a, b, c, d, e, f);
        }
        b3(a, b) {
            return this.adapter.getPropertyValue(a, b);
        }
        r(a, b, c) {
            return this.q(a, b);
        }
        q(a, b) {
            let c = this.adapter.getRootObject(a);
            if (c != null) {
                this.c4(a, c, b);
            }
            let d = false;
            this.adapter.clearContainer(a, this.context, (e) => {
                d = true;
                if (e) {
                    this.d0(a, b);
                }
            });
            return d;
        }
    }
    ComponentRenderer.$t = /*@__PURE__*/ markType(ComponentRenderer, 'ComponentRenderer');
    ComponentRenderer._defaultInstance = null;
    ComponentRenderer.platform = 3;
    return ComponentRenderer;
})();
/**
 * @hidden
 */
export let ContainerState = /*@__PURE__*/ (() => {
    class ContainerState extends Base {
        constructor() {
            super(...arguments);
            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);
        }
        k(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);
            }
        }
        a(a) {
            return this.e.containsKey(a);
        }
        b(a) {
            return this.f.containsKey(a);
        }
        j(a) {
            return this.e.item(a);
        }
        l(a, b, c, d) {
            if (this.c.containsKey(c)) {
                let e = this.c.item(c);
                for (let 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.c4(b, this.e.item(e._inner[f]), this);
                        }
                    }
                }
                this.c.removeItem(c);
            }
            let 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)) {
                let h = this.d.item(c);
                this.d.removeItem(c);
                d(b, h, false);
            }
        }
        h(a) {
            if (this.f.containsKey(a)) {
                return this.f.item(a);
            }
            return -1;
        }
    }
    ContainerState.$t = /*@__PURE__*/ markType(ContainerState, 'ContainerState');
    return ContainerState;
})();
