/*
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, Delegate_$type, runOn, Number_$type, String_$type, EnumUtil, typeGetValue, markType } from "./type";
import { TypeDescriptionContext } from "./TypeDescriptionContext";
import { TypeDescriptionCleanups } from "./TypeDescriptionCleanups";
import { Dictionary$2 } from "./Dictionary$2";
import { List$1 } from "./List$1";
import { Description } from "./Description";
import { DescriptionTreeNode } from "./DescriptionTreeNode";
import { Queue$1 } from "./Queue$1";
import { DescriptionTreeAction } from "./DescriptionTreeAction";
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 { GlobalAnimationState } from "./GlobalAnimationState";
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._allowNullForRemove = false;
            this.be = new List$1(Delegate_$type, 0);
            this.a1 = new Dictionary$2(Base.$, Description.$, 0);
            this.a2 = new Dictionary$2(Base.$, Boolean_$type, 0);
            this.a3 = new Dictionary$2(Base.$, Boolean_$type, 0);
            this.a0 = new Dictionary$2(Base.$, Boolean_$type, 0);
            this.ay = new Dictionary$2(Base.$, String_$type, 0);
            this.az = new Dictionary$2(Base.$, Number_$type, 0);
            this.aw = new Dictionary$2(Base.$, DescriptionTreeNode.$, 0);
            this.a7 = new Dictionary$2(Base.$, ContainerState.$, 0);
            this.a4 = new Dictionary$2(Base.$, Queue$1.$.specialize(Queue$1.$.specialize(DescriptionTreeAction.$)), 0);
            this.ax = new Dictionary$2(Base.$, List$1.$.specialize(Delegate_$type), 0);
            this.av = new Dictionary$2(Base.$, Boolean_$type, 0);
            this.a6 = new Dictionary$2(String_$type, DescriptionRef.$, 0);
            this.a8 = new Dictionary$2(String_$type, Base.$, 0);
            this.ba = new Dictionary$2(String_$type, Base.$, 0);
            this.a5 = new Dictionary$2(Base.$, String_$type, 0);
            this.bl = null;
            this.bg = new List$1(Delegate_$type, 0);
            this.a9 = new Dictionary$2(String_$type, List$1.$.specialize(Delegate_$type), 0);
            this.bd = new List$1(Delegate_$type, 0);
            this.bf = new List$1(Delegate_$type, 0);
            this.bc = null;
            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.aw.keys)) {
                if (d) {
                    d = false;
                }
                else {
                    b.f(",");
                }
                let f = e;
                let g = this.aw.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.ba.count > 0) {
                b.e(",");
            }
            b.f("");
            if (this.ba.count > 0) {
                d = true;
                b.f("refs: {");
                b.i();
                for (let i of fromEnum(this.ba.keys)) {
                    if (!this.q(i, this.ba.item(i))) {
                        continue;
                    }
                    if (d) {
                        d = false;
                    }
                    else {
                        b.f(",");
                    }
                    this.eg(b, i, this.ba.item(i));
                }
                b.f("");
                b.h();
                b.f("}");
            }
            b.h();
            b.f("}");
            return b.toString();
        }
        eg(a, b, c) {
            a.e("\"" + b + "\": ");
            this.eh(a, c);
        }
        eh(a, b) {
            if (this.z(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.w(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.ef(a, c, d);
                    }
                    a.f("");
                    a.h();
                    a.e("]");
                }
                else {
                    let e = [b];
                    let f = new DataSourceLocalDataProvider();
                    f.dataSource = e;
                    this.ef(a, f, 0);
                }
            }
        }
        z(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;
        }
        w(a) {
            if (typeCast(Array_$type, a) !== null) {
                return true;
            }
            if (typeCast(IEnumerable_$type, a) !== null) {
                return true;
            }
            return false;
        }
        ef(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.eh(a, g);
                        break;
                }
            }
            a.h();
            a.f("}");
        }
        q(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.a7.item(b);
            if (h.c("Type")) {
                let j = h.a("Type").b;
                return this.b6(j, h, b, i, true, -1, null);
            }
            else {
                return this.b5(typeCast(JsonDictionaryObject.$, d));
            }
        }
        loadJson(a, b) {
            this.dm(a, b, null, false, false, false);
        }
        loadJsonOverlay(a, b, c) {
            this.dm(a, b, c, true, false, true);
        }
        loadJsonDelta(a, b, c) {
            this.dm(a, b, null, true, c, false);
        }
        get preserveKeyOrder() {
            return this._preserveKeyOrder;
        }
        set preserveKeyOrder(a) {
            this._preserveKeyOrder = a;
        }
        as() {
            return false;
        }
        dp(a) {
        }
        get allowNullForRemove() {
            return this._allowNullForRemove;
        }
        set allowNullForRemove(a) {
            this._allowNullForRemove = a;
        }
        dm(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.as();
            let j = null;
            if (typeCast(JsonDictionaryObject.$, h) !== null) {
                let k = h;
                if (k.g("skipAlterDataCasing")) {
                    let l = k.item("skipAlterDataCasing");
                    if (l.value) {
                        this.dp(true);
                    }
                }
                else {
                    this.dp(false);
                }
                let m = null;
                if (k.g("animationIdleRef") || k.g("hasAnimations")) {
                    m = "AnimationIdleHandler";
                    if (k.g("animationIdleRef")) {
                        m = k.item("animationIdleRef").value;
                    }
                }
                let n = 0;
                if (k.g("animationIdleTimeout")) {
                    n = truncate(k.item("animationIdleTimeout").value);
                }
                if (k.g("descriptions")) {
                    let o = k.item("descriptions");
                    if (typeCast(JsonDictionaryObject.$, o) !== null) {
                        let p = o;
                        let q = p.e();
                        for (let r = 0; r < q.length; r++) {
                            let s = q[r];
                            let t = p.item(s);
                            let u = b(s);
                            if (u == null) {
                                continue;
                            }
                            j = u;
                            let v = false;
                            let w = this.bj();
                            if (w != null) {
                                v = true;
                            }
                            let x = null;
                            if (this.isProceedOnErrorEnabled) {
                                try {
                                    x = i.d(this.context, t, v, w, false);
                                }
                                catch (y) {
                                    return;
                                }
                            }
                            else {
                                x = i.d(this.context, t, v, w, false);
                            }
                            if (x.result == null && !this.allowNullForRemove) {
                                continue;
                            }
                            if (f) {
                                if (!this.bb.containsKey(u)) {
                                    let z = null;
                                    if (this.isProceedOnErrorEnabled) {
                                        try {
                                            z = i.d(this.context, t, v, w, true);
                                        }
                                        catch (aa) {
                                            return;
                                        }
                                    }
                                    else {
                                        z = i.d(this.context, t, v, w, true);
                                    }
                                    this.ea(z.result, u, d, true, false, m, n);
                                    m = null;
                                    let ab = c(s);
                                    let ac = this.bb.item(u);
                                    this.dg(this.aw.item(u), ab, ac, u);
                                }
                            }
                            this.ea(x.result, u, d, e, false, m, n);
                            m = null;
                        }
                    }
                }
                if (k.g("refs") && j != null) {
                    let ad = k.item("refs");
                    let ae = this.ai(ad);
                    if (!ae && typeCast(JsonDictionaryObject.$, ad) !== null) {
                        let af = ad;
                        let ag = af.e();
                        for (let ah = 0; ah < ag.length; ah++) {
                            let ai = ag[ah];
                            let aj = af.item(ai);
                            if (typeCast(JsonDictionaryValue.$, aj) !== null) {
                                let ak = aj;
                                this.provideRefValue(j, ai, ak.value);
                            }
                            else if (typeCast(JsonDictionaryArray.$, aj) !== null) {
                                let al = aj;
                                let am = this.a(al);
                                this.provideRefValue(j, ai, am);
                            }
                            else {
                                let an = this.b5(aj);
                                this.provideRefValue(j, ai, an);
                            }
                        }
                    }
                }
                if (k.g("modules") && j != null) {
                    let ao = k.item("modules");
                    this.af(ao);
                }
                if (k.g("strings") && j != null) {
                    let ap = k.item("strings");
                    this.am(ap);
                }
                if (k.g("onInit") && j != null) {
                    let aq = k.item("onInit");
                    this.ag(aq);
                }
                if (k.g("onViewInit") && j != null) {
                    let ar = k.item("onViewInit");
                    this.ah(ar);
                }
            }
        }
        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.b5(f);
                this.provideRefValue(a, d, j);
            }
        }
        addMemberPathTransformer(a) {
            this.be.add(a);
        }
        removeMemberPathTransformer(a) {
            this.be.remove(a);
        }
        bj() {
            if (this.be.count > 0) {
                return (a) => {
                    let b = a;
                    for (let c = 0; c < this.be.count; c++) {
                        b = this.be._inner[c](b);
                    }
                    return b;
                };
            }
            return null;
        }
        ai(a) {
            return false;
        }
        af(a) {
            return false;
        }
        am(a) {
            return false;
        }
        ag(a) {
            return false;
        }
        ah(a) {
            return false;
        }
        cw(a, b, c) {
            let d = a;
            if (c != null) {
                d = c.k(b);
            }
            else {
                if (TypeDescriptionMetadata.shouldCamelize(b)) {
                    d = TypeDescriptionMetadata.camelize(d);
                }
            }
            if (stringEndsWith(d, "Ref")) {
                d = d.substr(0, d.length - ("Ref").length);
            }
            return d;
        }
        dg(a, b, c, d) {
            if (!c.b(b)) {
                c.k(d, this.aw.item(d).g, b, this.aw.item(d), runOn(this, this.du), -1);
            }
            for (let e of fromEnum(a.f())) {
                this.dh(this.cw(e.c, ComponentRenderer.platform, e.a), e.b, b, c, d, a.g);
            }
        }
        dh(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.du), f);
                }
                for (let i of fromEnum(g.f())) {
                    this.dh(a + "." + this.cw(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.du), f);
                        }
                        for (let t of fromEnum(s.f())) {
                            this.dh(a + "." + t.c, t.b, c, d, e, s.g);
                        }
                    }
                    k++;
                });
                if (l > 0 && k == 0) {
                    let r = this.c1(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.du), f);
                            }
                            for (let u of fromEnum(t.f())) {
                                this.dh(r + "." + u.c, u.b, c, d, e, t.g);
                            }
                        }
                        k++;
                    });
                }
            }
        }
        c1(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.cy(d);
            if (c != null) {
                return c + "." + d;
            }
            return d;
        }
        cy(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.b5(a.items[c]);
                b[c] = d;
            }
            return b;
        }
        b5(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.b5(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 bb() {
            return this.a7;
        }
        cleanup(a, b) {
            this.bl = a;
            this.ea(null, a, false, false, b, null, 0);
        }
        render(a, b) {
            this.ea(a, b, false, false, false, null, 0);
        }
        ea(a, b, c, d, e, f, g) {
            if (!this.a7.containsKey(b)) {
                this.a7.item(b, new ContainerState());
                this.a7.item(b).i = b;
            }
            this.a1.item(b, a);
            this.a2.item(b, c);
            this.a3.item(b, d);
            this.a0.item(b, e);
            this.ay.item(b, f);
            this.az.item(b, g);
            this.dq(b, () => this.d8(b));
        }
        dq(a, b) {
            this.adapter.onUIThread(a, b);
        }
        d8(a) {
            if (this.a1.containsKey(a)) {
                let b = this.a2.containsKey(a) ? this.a2.item(a) : false;
                let c = this.a3.containsKey(a) ? this.a3.item(a) : false;
                let d = this.a1.item(a);
                let e = this.ay.containsKey(a) ? this.ay.item(a) : null;
                let f = this.az.containsKey(a) ? this.az.item(a) : 0;
                this.a1.removeItem(a);
                let g = DescriptionTreeBuilder.createTreeWithOptions(this.context, d, this.preserveKeyOrder);
                let h = null;
                if (this.aw.containsKey(a)) {
                    h = this.aw.item(a);
                }
                let i = DescriptionTreeReconciler.c(h, g, b);
                if (!c && b) {
                    g = h.b();
                    DescriptionTreeReconciler.a(h, i);
                    let j = h;
                    h = g;
                    g = j;
                    i = DescriptionTreeReconciler.c(h, g, false);
                }
                if (c) {
                    let k = DescriptionTreeReconciler.a(h, i);
                    if (!this.a7.containsKey(a)) {
                        this.a7.addItem(a, ((() => {
                            let $ret = new ContainerState();
                            $ret.i = a;
                            return $ret;
                        })()));
                    }
                    let l = this.a7.item(a);
                    if (k.a.count > 0) {
                        for (let m of fromEnum(k.a)) {
                            if (l.a(m)) {
                                let n = l.j(m);
                                this.de(a, n, l);
                            }
                        }
                    }
                    if (k.c.count > 0) {
                        for (let o of fromEnum(k.c)) {
                            let p = this.cc(a, l, o);
                            let q = this.adapter.getPropertyValue(p, o.j);
                            if (q != null) {
                                if (!l.b(q)) {
                                    let r = o.g;
                                    if (typeCast(DescriptionTreeNode.$, r) !== null) {
                                        let s = r.g;
                                        l.k(a, s, q, r, runOn(this, this.du), o.c.g);
                                    }
                                }
                            }
                        }
                    }
                    if (k.d.count > 0) {
                        for (let t of fromEnum(k.d)) {
                            let u = t.g;
                            if (u != null) {
                                if (!l.b(u)) {
                                    let v = t.g;
                                    if (typeCast(DescriptionTreeNode.$, v) !== null) {
                                        let w = v.g;
                                        this.aw.item(a, v);
                                    }
                                }
                            }
                        }
                    }
                    if (k.b.count > 0) {
                        for (let x of fromEnum(k.b)) {
                            let y = x.c.a(x.j).b;
                            if (y == null) {
                                continue;
                            }
                            let z = new Dictionary$2(String_$type, DescriptionTreeNode.$, 0);
                            for (let aa = 0; aa < y.length; aa++) {
                                let ab = y[aa];
                                if (typeCast(DescriptionTreeNode.$, ab) !== null) {
                                    let ac = ab;
                                    if (ac.c("Name")) {
                                        z.item(ac.a("Name").b, ac);
                                    }
                                }
                            }
                            if (z.count == 0) {
                                continue;
                            }
                            let ad = this.cc(a, l, x);
                            let ae = this.adapter.getPropertyValue(ad, x.j);
                            if (ae != null) {
                                let af = 0;
                                this.adapter.forPropertyValueItem(ad, x.j, (ag) => {
                                    if (z.containsKey(this.adapter.getPropertyValue(ag, "Name").toString())) {
                                        if (!l.b(ag)) {
                                            let ah = z.item(this.adapter.getPropertyValue(ag, "Name").toString());
                                            if (typeCast(DescriptionTreeNode.$, ah) !== null) {
                                                let ai = ah.g;
                                                l.k(a, ai, ag, ah, runOn(this, this.du), x.c.g);
                                            }
                                        }
                                    }
                                    af++;
                                });
                            }
                        }
                    }
                }
                else {
                    this.aw.item(a, g);
                }
                if (!c) {
                    if (e != null && this.v(e)) {
                        let ag = this.ba.item(e);
                        if (ag != null) {
                            let ah = GlobalAnimationState.d.i();
                            if (f > 0) {
                                GlobalAnimationState.d.n((ai) => ag(ai), ah, f);
                            }
                            else {
                                GlobalAnimationState.d.m(() => ag(false), ah);
                            }
                        }
                    }
                    this.d9(a, i);
                }
                if (this.a0.item(a)) {
                    this.d6(a);
                    if (this.a7.containsKey(a)) {
                        this.a7.removeItem(a);
                    }
                }
            }
            if (this.bl != null) {
                if (this.a1.containsKey(this.bl)) {
                    this.a1.removeItem(this.bl);
                }
                if (this.a2.containsKey(this.bl)) {
                    this.a2.removeItem(this.bl);
                }
                if (this.a3.containsKey(this.bl)) {
                    this.a3.removeItem(this.bl);
                }
                if (this.a0.containsKey(this.bl)) {
                    this.a0.removeItem(this.bl);
                }
                if (this.aw.containsKey(this.bl)) {
                    this.aw.removeItem(this.bl);
                }
                if (this.a4.containsKey(this.bl)) {
                    this.a4.removeItem(this.bl);
                }
                if (this.ax.containsKey(this.bl)) {
                    this.ax.removeItem(this.bl);
                }
                if (this.av.containsKey(this.bl)) {
                    this.av.removeItem(this.bl);
                }
                if (this.az.containsKey(this.bl)) {
                    this.az.removeItem(this.bl);
                }
                if (this.ay.containsKey(this.bl)) {
                    this.ay.removeItem(this.bl);
                }
                this.bl = null;
            }
        }
        getTargetValue(a, b, c) {
            let d = this.context.getMetadata(a, this.cy(b));
            let e = d.k(ComponentRenderer.platform);
            return this.adapter.getPropertyValue(c, e);
        }
        setTargetValue(a, b, c, d, e) {
            let f = this.context.getMetadata(a, this.cy(b));
            let g = f.k(ComponentRenderer.platform);
            this.adapter.setPropertyValue(c, g, f, d, e, null);
        }
        executeMethod(a, b, c) {
            let d = new JsonDictionaryParser();
            let e = d.parse(b);
            if (!this.a7.containsKey(a)) {
                this.a7.item(a, new ContainerState());
                this.a7.item(a).i = a;
            }
            let f = this.a7.item(a);
            let g = new DescriptionSerializer();
            g.h = this.isProceedOnErrorEnabled;
            g.g = this.as();
            let h = this.aw.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.cu(m, "targetRef");
                }
                let n = null;
                if (m.g("methodName")) {
                    n = this.cu(m, "methodName");
                }
                if (l != null) {
                    if (this.a8.containsKey(l)) {
                        i = this.a8.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.ce(a, r.g);
                        }
                        else {
                            s = this.b9(r, a, f);
                        }
                        if (r.d.knownType == 8 && r.d.specificType == "string") {
                            s = this.bu(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.cz(w, t);
                    c(x);
                });
            }
        }
        ce(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.bd.count; f++) {
                        let g = this.bd._inner[f](a, c, d);
                        if (g != null) {
                            return g;
                        }
                    }
                    if (c == "name") {
                        let h = d;
                        if (this.a8.containsKey(h)) {
                            return this.a8.item(h);
                        }
                        if (this.ba.containsKey(h)) {
                            return this.ba.item(h);
                        }
                    }
                    return null;
                }
            }
            return null;
        }
        static bi(a) {
            if (typeCast(Date_$type, a) !== null) {
                return a.getTime();
            }
            if (a == null) {
                return 0;
            }
            return a;
        }
        cz(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.bi(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.cf(a);
                        return $ret;
                    })()));
                    break;
                case 5:
                    c.item("result", ((() => {
                        let $ret = new JsonDictionaryValue();
                        $ret.e = 2;
                        $ret.value = this.ch(a);
                        return $ret;
                    })()));
                    break;
                case 6:
                    c.item("result", ((() => {
                        let $ret = new JsonDictionaryValue();
                        $ret.e = 2;
                        $ret.value = this.cg(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.ck(a);
                        return $ret;
                    })()));
                    break;
                case 12:
                    c.item("result", this.cm(a));
                    break;
                case 13: break;
                case 14:
                    c.item("result", ((() => {
                        let $ret = new JsonDictionaryValue();
                        $ret.e = 2;
                        $ret.value = this.cl(a);
                        return $ret;
                    })()));
                    break;
                case 15: break;
                case 16:
                    c.item("result", ((() => {
                        let $ret = new JsonDictionaryValue();
                        $ret.e = 2;
                        $ret.value = this.ci(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.cn(a);
                        return $ret;
                    })()));
                    break;
                case 22: break;
                case 23:
                    c.item("result", ((() => {
                        let $ret = new JsonDictionaryValue();
                        $ret.e = 2;
                        $ret.value = this.cj(a);
                        return $ret;
                    })()));
                    break;
            }
            return c.b();
        }
        cj(a) {
            return this.adapter.serializeDoubleCollection(a);
        }
        cn(a) {
            return this.adapter.serializeTimespan(a);
        }
        ci(a) {
            return this.adapter.serializeColorCollection(a);
        }
        cl(a) {
            return this.adapter.serializeRect(a);
        }
        cm(a) {
            return this.adapter.serializeSize(a);
        }
        ck(a) {
            return this.adapter.serializePoint(a);
        }
        cg(a) {
            return this.adapter.serializeBrushCollection(a);
        }
        ch(a) {
            return this.adapter.serializeColor(a);
        }
        cf(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.cu(b, "knownType");
            let h = EnumUtil.tryParse$1(TypeDescriptionWellKnownType_$type, g, true, f);
            f = h.p2;
            e.knownType = f;
            e.specificExternalType = this.cu(b, "specificExternalType");
            e.specificType = this.cu(b, "specificType");
            e.collectionElementType = this.cu(b, "collectionElementType");
            d.d = e;
            let i = null;
            i = this.b8(e, b, c);
            d.g = i;
            return d;
        }
        cu(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;
        }
        b8(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.b4(a.knownType, a.specificType, a.specificExternalType, a.collectionElementType, e, c);
                }
            }
            return null;
        }
        b4(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.dj(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.b4(q, r, s, t, w, f);
                        p[v] = x;
                    }
                }
                return p;
            }
            else if (typeCast(JsonDictionaryValue.$, e) !== null) {
                return e.value;
            }
            return e;
        }
        dj(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
            };
        }
        resolveRefValue(a, b, c) {
            this.dq(a, () => {
                if (!this.a7.containsKey(a)) {
                    this.a7.addItem(a, ((() => {
                        let $ret = new ContainerState();
                        $ret.i = a;
                        return $ret;
                    })()));
                }
                let d = this.a7.item(a);
                if (!this.hasRef(b)) {
                    if (this.a8.containsKey(b)) {
                        c(this.a8.item(b));
                        return;
                    }
                    if (!this.x(a)) {
                        this.queueForIdle(a, () => this.resolveRefValue(a, b, c));
                        return;
                    }
                    c(null);
                    return;
                }
                let e = this.f(b);
                let f = this.cb(e);
                c(f);
            });
        }
        resolveRefName(a, b, c) {
            this.dq(a, () => {
                if (!this.a7.containsKey(a)) {
                    this.a7.addItem(a, ((() => {
                        let $ret = new ContainerState();
                        $ret.i = a;
                        return $ret;
                    })()));
                }
                let d = this.a7.item(a);
                if (b != null && this.a5.containsKey(b)) {
                    c(this.a5.item(b));
                    return;
                }
                c(null);
            });
        }
        provideRefValue(a, b, c) {
            this.dq(a, () => {
                if (!this.a7.containsKey(a)) {
                    this.a7.addItem(a, ((() => {
                        let $ret = new ContainerState();
                        $ret.i = a;
                        return $ret;
                    })()));
                }
                let d = this.a7.item(a);
                this.du(a, b, c, true);
            });
        }
        removeRefValue(a, b) {
            this.dq(a, () => {
                if (!this.a7.containsKey(a)) {
                    this.a7.addItem(a, ((() => {
                        let $ret = new ContainerState();
                        $ret.i = a;
                        return $ret;
                    })()));
                }
                let c = this.a7.item(a);
                this.removeRefValueCore(a, b, true);
            });
        }
        d6(a) {
            let b = this.a7.item(a);
            let c = new List$1(String_$type, 0);
            for (let d of fromEnum(this.a6.keys)) {
                if (this.a6.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.ba.containsKey(c._inner[e]));
                this.shouldNamespaceSystemRefValues = f;
                if (this.bc != null && this.bc.count > 0) {
                    for (let g = 0; g < this.bc.count; g++) {
                        this.bc._inner[g](a, c._inner[e]);
                    }
                }
            }
        }
        clearRefValues(a) {
            this.dq(a, () => {
                if (!this.a7.containsKey(a)) {
                    this.a7.addItem(a, ((() => {
                        let $ret = new ContainerState();
                        $ret.i = a;
                        return $ret;
                    })()));
                }
                let b = this.a7.item(a);
                this.clearUserRefValues();
            });
        }
        x(a) {
            if (this.av.containsKey(a) && this.av.item(a)) {
                return false;
            }
            if (this.a4.containsKey(a) && this.a4.item(a).count > 0) {
                return false;
            }
            return true;
        }
        queueForIdle(a, b) {
            this.dq(a, () => {
                if (this.x(a)) {
                    b();
                }
                else {
                    if (!this.ax.containsKey(a)) {
                        this.ax.item(a, new List$1(Delegate_$type, 0));
                    }
                    this.ax.item(a).add(b);
                }
            });
        }
        tryFlushIdleActions(a) {
            if (this.x(a)) {
                if (this.ax.containsKey(a)) {
                    let b = new List$1(Delegate_$type, 1, this.ax.item(a));
                    this.ax.item(a).clear();
                    for (let c = 0; c < b.count; c++) {
                        b._inner[c]();
                    }
                }
            }
        }
        d9(a, b) {
            let c = this.a7.item(a);
            this.dr(a, c, b);
        }
        ee(a, b) {
            if (this.isProceedOnErrorEnabled) {
                try {
                    this.df(a, b, true);
                }
                catch (c) {
                    this.av.item(a, false);
                }
            }
            else {
                this.df(a, b, true);
            }
        }
        el(a, b) {
            if (this.isProceedOnErrorEnabled) {
                try {
                    this.df(a, b, false);
                }
                catch (c) {
                    this.av.item(a, false);
                }
            }
            else {
                this.df(a, b, false);
            }
        }
        df(a, b, c) {
            if (!c) {
                if (this.av.containsKey(a) && this.av.item(a)) {
                    return;
                }
            }
            this.av.item(a, true);
            let d = true;
            while (d && this.a4.item(a).count > 0) {
                while (this.a4.item(a).count > 0 && this.a4.item(a).c().count < 1) {
                    this.a4.item(a).b();
                }
                if (this.a4.item(a).count < 1) {
                    break;
                }
                let e = this.a4.item(a).c();
                while (e.count > 0) {
                    let f = e.b();
                    d = this.ac(a, b, f);
                    if (!d) {
                        break;
                    }
                }
            }
            if (d) {
                this.av.item(a, false);
            }
            if (this.x(a)) {
                this.tryFlushIdleActions(a);
            }
        }
        dr(a, b, c) {
            let d = new Queue$1(DescriptionTreeAction.$);
            for (let e = 0; e < c.count; e++) {
                d.g(c._inner[e]);
            }
            if (!this.a4.containsKey(a)) {
                this.a4.addItem(a, new Queue$1(Queue$1.$.specialize(DescriptionTreeAction.$)));
            }
            this.a4.item(a).g(d);
            this.el(a, b);
        }
        ds(a, b, c) {
            for (let d = 0; d < c.count; d++) {
                this.ac(a, b, c._inner[d]);
            }
        }
        ac(a, b, c) {
            switch (c.a) {
                case 5: return this.ad(a, b, c);
                case 2: return this.ae(a, b, c);
                case 4: return this.aj(a, b, c);
                case 3: return this.ak(a, b, c);
                case 1: return this.al(a, b, c);
                case 0: return this.an(a, b, c);
            }
            return true;
        }
        an(a, b, c) {
            let d = this.cc(a, b, c);
            this.au(a, b, c, d);
            return true;
        }
        au(a, b, c, d) {
            let e = this.b9(c, a, b);
            e = this.j.transform(ComponentRenderer.platform, e, c);
            let f = false;
            if (this.bg != null && this.bg.count > 0) {
                for (let g = 0; g < this.bg.count; g++) {
                    let h = this.bg._inner[g];
                    let i = this.cx(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.ar(a, b, c.i(ComponentRenderer.platform), c.d, e, d);
            }
            else {
                this.ei(a, b, c.i(ComponentRenderer.platform), c.d, e, c.h, d);
            }
            return true;
        }
        cx(a, b) {
            let c = b.c;
            let d = "";
            if (c != this.aw.item(a)) {
                let e = this.cv(a, c);
                d = e;
            }
            if (d.length > 0) {
                d += ".";
            }
            d += b.j;
            return d;
        }
        cv(a, b) {
            if (b == null) {
                return "";
            }
            let c = this.c2("", this.aw.item(a), b);
            if (c.c) {
                return c.d;
            }
            return "";
        }
        c2(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.c2(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.c2(l, k, c);
                                if (m.c) {
                                    return m;
                                }
                            }
                        }
                    }
                }
            }
            return new Tuple$2(Boolean_$type, String_$type, false, a);
        }
        ar(a, b, c, d, e, f) {
            if (this.a9.containsKey(c)) {
                for (let g of fromEnum(this.a9.item(c))) {
                    g(c, f, e);
                }
            }
            this.adapter.setOrUpdateCollectionOnTarget(a, c, d, this.context, f, e);
            return true;
        }
        b9(a, b, c) {
            if (a.d == null) {
                return a.g;
            }
            switch (a.d.knownType) {
                case 10: return this.bm(a, b, c);
                case 7: return this.bn(a);
                case 4: return this.bo(a);
                case 6: return this.bp(a);
                case 23: return this.bt(a);
                case 9: return this.bm(a, b, c);
                case 5: return this.bq(a);
                case 16: return this.br(a);
                case 20: return this.co(a, c);
                case 22: return this.cr(a, c);
                case 15: return null;
                case 3: return this.bs(a);
                case 19: return this.cp(a, c);
                case 8: return this.bv(a, b, c);
                case 13: return null;
                case 18: return this.cq(a, c);
                case 1: return this.bw(a);
                case 11: return this.bx(a);
                case 14: return this.by(a);
                case 12: return this.bz(a);
                case 2: return this.b0(a);
                case 21: return this.b1(a);
                case 17: return this.b2(a, b, c);
                case 0: return null;
            }
            return null;
        }
        b2(a, b, c) {
            let d = this.b3(a.g, a, b, c);
            return d;
        }
        b3(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.b3(e[g], b, c, d);
                    f[g] = h;
                }
                a = f;
            }
            if (typeCast(DescriptionTreeNode.$, a) !== null) {
                let i = a;
                if (i.i == "EmbeddedRef") {
                    return this.b6(i.i, a, c, d, false, b.c.g, b.d);
                }
            }
            return a;
        }
        b1(a) {
            return a.g;
        }
        b0(a) {
            return a.g != null ? a.g.toString() : null;
        }
        bz(a) {
            let b = a.g;
            let width_ = b.width;
            let height_ = b.height;
            let c = { width: width_, height: height_ };
            return c;
        }
        by(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;
        }
        bx(a) {
            let b = a.g;
            let x_ = b.x;
            let y_ = b.y;
            let c = { x: x_, y: y_ };
            return c;
        }
        bw(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) {
            if (this.a6.containsKey(a)) {
                let b = this.a6.item(a);
                return b;
            }
            let c = new DescriptionRef(a);
            this.a6.addItem(a, c);
            return c;
        }
        cq(a, b) {
            return a.g == null ? null : this.e(a.g);
        }
        bv(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.b6(d, a.g, b, c, false, a.c.g, a.d);
            return f;
        }
        cp(a, b) {
            return a.g == null ? null : this.e(a.g);
        }
        bs(a) {
            if (typeof a.g === 'string') {
                let v_ = a.g;
                a.g = new Date(v_);
            }
            return a.g;
        }
        co(a, b) {
            return a.g == null ? null : this.e(a.g);
        }
        cr(a, b) {
            return a.g == null ? null : this.e(a.g);
        }
        ct(a) {
            return a;
        }
        br(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.ct(b[d]);
            }
            return c;
        }
        bq(a) {
            return this.ct(a.g);
        }
        bp(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.cs(b[d]);
            }
            return c;
        }
        bt(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;
        }
        cs(a) {
            return a;
        }
        bo(a) {
            return this.cs(a.g);
        }
        bn(a) {
            return a.g;
        }
        addTargetPropertyUpdatingListener(a) {
            this.bg.add(a);
        }
        removeTargetPropertyUpdatingListener(a) {
            this.bg.remove(a);
        }
        addPropertyUpdatingListener(a, b) {
            if (!this.a9.containsKey(a)) {
                this.a9.addItem(a, new List$1(Delegate_$type, 0));
            }
            this.a9.item(a).add(b);
        }
        addReferenceLookupListener(a) {
            this.bd.add(a);
        }
        removeReferenceLookupListener(a) {
            this.bd.remove(a);
        }
        removePropertyUpdatingListener(a, b) {
            if (this.a9.containsKey(a)) {
                this.a9.item(a).remove(b);
                if (this.a9.item(a).count == 0) {
                    this.a9.removeItem(a);
                }
            }
        }
        addNamespaceLookupListener(a) {
            this.bf.add(a);
        }
        removeNamespaceLookupListener(a) {
            this.bf.remove(a);
        }
        addCleanupListener(a) {
            if (this.bc == null) {
                this.bc = new List$1(Delegate_$type, 0);
            }
            this.bc.add(a);
        }
        removeCleanupListener(a) {
            if (this.bc != null) {
                this.bc.remove(a);
            }
        }
        bm(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.b6(h, d[g], b, c, false, a.c.g, a.d);
                e.add1(j);
            }
            return e.toArray();
        }
        ei(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.hasRef(f)) {
                        let j = this.f(f);
                        if (Base.equalsStatic(j, e)) {
                            i = true;
                        }
                        else {
                            j.j(a, g, c);
                        }
                    }
                }
                if (this.u(e)) {
                    let k = e;
                    if (k.e != null && k.e.length > 0 && this.a8.containsKey(k.e)) {
                        k.a = true;
                    }
                    e = this.cb(e);
                    this.ej(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.a8.containsKey(o.e)) {
                        o.a = true;
                    }
                    let p = this.cb(m);
                    this.ej(g, c, d, p, n.b, o);
                };
                if (!i) {
                    h.g(a, g, c, l);
                }
                return;
            }
            this.ej(g, c, d, e, f, null);
        }
        v(a) {
            return this.ba.containsKey(a);
        }
        get shouldNamespaceSystemRefValues() {
            return this._shouldNamespaceSystemRefValues;
        }
        set shouldNamespaceSystemRefValues(a) {
            this._shouldNamespaceSystemRefValues = a;
        }
        du(a, b, c, d) {
            let e = null;
            if (d) {
                if (this.ba.containsKey(b)) {
                    e = this.ba.item(b);
                }
                this.ba.item(b, c);
                if (c != null) {
                    this.a5.item(c, b);
                }
            }
            else {
                if (this.shouldNamespaceSystemRefValues) {
                    let f = "";
                    if (this.bf != null && this.bf.count > 0) {
                        for (let g = 0; g < this.bf.count; g++) {
                            f = this.bf._inner[g](a);
                        }
                    }
                    if (!stringIsNullOrEmpty(f)) {
                        b = f + "/" + b;
                    }
                }
                if (this.a8.containsKey(b)) {
                    e = this.a8.item(b);
                }
                this.a8.item(b, c);
                if (c != null) {
                    this.a5.item(c, b);
                }
                if (this.a6.containsKey(b)) {
                    this.a6.item(b).a = true;
                }
            }
            if (this.a6.containsKey(b)) {
                this.a6.item(b).f(e, c);
            }
        }
        removeRefValueCore(a, b, c) {
            let d = null;
            if (c) {
                if (this.ba.containsKey(b)) {
                    d = this.ba.item(b);
                }
                this.ba.removeItem(b);
                if (d != null && this.a5.containsKey(d)) {
                    this.a5.removeItem(d);
                }
            }
            else {
                if (this.shouldNamespaceSystemRefValues) {
                    let e = "";
                    if (this.bf != null && this.bf.count > 0) {
                        for (let f = 0; f < this.bf.count; f++) {
                            e = this.bf._inner[f](a);
                        }
                    }
                    if (!stringIsNullOrEmpty(e)) {
                        b = e + "/" + b;
                    }
                }
                if (this.a8.containsKey(b)) {
                    d = this.a8.item(b);
                }
                this.a8.removeItem(b);
                if (d != null && this.a5.containsKey(d)) {
                    this.a5.removeItem(d);
                }
            }
            if (this.a6.containsKey(b)) {
                this.a6.item(b).f(d, this.cb(this.a6.item(b)));
                if (this.a6.item(b).c <= 0) {
                    this.a6.item(b).h();
                    this.a6.removeItem(b);
                }
            }
        }
        clearUserRefValues() {
            let a = new List$1(String_$type, 0);
            for (let b of fromEnum(this.ba.keys)) {
                a.add(b);
            }
            for (let c of fromEnum(a)) {
                this.removeRefValueCore(null, c, true);
            }
        }
        u(a) {
            return this.ba.containsKey(a.e) || this.a8.containsKey(a.e);
        }
        cb(a) {
            if (this.ba.containsKey(a.e)) {
                return this.ba.item(a.e);
            }
            if (this.a8.containsKey(a.e)) {
                return this.a8.item(a.e);
            }
            return null;
        }
        hasRef(a) {
            return this.a6.containsKey(a);
        }
        f(a) {
            return this.a6.item(a);
        }
        getMissingRefs() {
            let a = new List$1(String_$type, 0);
            for (let b of fromEnum(this.a6.keys)) {
                if (!this.u(this.a6.item(b))) {
                    a.add(b);
                }
            }
            return a.toArray();
        }
        getRefChangeInfos(a) {
            let b = new List$1(DescriptionRefTargetInfo.$, 0);
            if (this.a6.containsKey(a)) {
                for (let c of fromEnum(this.a6.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();
        }
        cc(a, b, c) {
            return b.j(c.c.g);
        }
        al(a, b, c) {
            let d = this.cc(a, b, c);
            this.aq(a, b, c, d);
            return true;
        }
        aq(a, b, c, d) {
            this.adapter.resetPropertyOnTarget(a, c.i(ComponentRenderer.platform), c.d, d);
            return true;
        }
        ak(a, b, c) {
            if (c.c == null) {
                return this.ap(a, b, c);
            }
            else {
                let d = this.cc(a, b, c);
                this.eb(a, b, c, d);
            }
            return true;
        }
        eb(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.b6(f, c.g, a, b, false, c.c.g, c.d);
            this.adapter.replaceItemInCollection(e, c.d, d, c.e, h);
            if (c.h != null && typeCast(DescriptionTreeNode.$, c.h) !== null) {
                let i = c.h.g;
                if (i >= 0) {
                    let j = b.j(i);
                    if (j != null) {
                        this.de(a, j, b);
                    }
                }
            }
        }
        ap(a, b, c) {
            let d = this.adapter.getRootObject(a);
            if (d != null) {
                this.de(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.du), -1);
                let i = this.bh(e);
                this.ds(a, b, i);
                f = true;
                if (g) {
                    this.ee(a, b);
                }
            });
            return f;
        }
        de(a, b, c) {
            let d = this.bk(a, b, c);
            for (let e of fromEnum(this.a6.values)) {
                e.i(b);
            }
            if (d != -1) {
                c.l(this, a, d, runOn(this, this.removeRefValueCore));
            }
            this.k.b(ComponentRenderer.platform, b);
        }
        bk(a, b, c) {
            return c.h(b);
        }
        aj(a, b, c) {
            if (c.c == null) {
                return this.ao(a, b, c);
            }
            else {
                let d = this.cc(a, b, c);
                this.dy(a, b, c, d);
            }
            return true;
        }
        dy(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.de(a, g, b);
                    }
                }
            }
        }
        ao(a, b, c) {
            let d = this.adapter.getRootObject(a);
            if (d != null) {
                this.de(a, d, b);
            }
            let e = false;
            this.adapter.removeRootItem(a, this.context, (f) => {
                e = true;
                if (f) {
                    this.ee(a, b);
                }
            });
            return e;
        }
        ae(a, b, c) {
            if (c.c == null) {
                return this.n(a, b, c);
            }
            else {
                let d = this.cc(a, b, c);
                this.c4(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.du), -1);
                let h = this.bh(d);
                this.ds(a, b, h);
                e = true;
                if (f) {
                    this.ee(a, b);
                }
            });
            return e;
        }
        c4(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.b6(f, c.g, a, b, false, c.c.g, c.d);
            this.adapter.addItemToCollection(e, c.d, d, c.e, h);
        }
        b6(a, b, c, d, e, f, g) {
            if (this.y(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.bf != null && this.bf.count > 0) {
                                for (let l = 0; l < this.bf.count; l++) {
                                    k = this.bf._inner[l](c);
                                }
                            }
                            if (!stringIsNullOrEmpty(k)) {
                                j = k + "/" + j;
                            }
                        }
                        if (this.a8.containsKey(j)) {
                            let m = this.a8.item(j);
                            h = m;
                        }
                    }
                }
                if (h == null) {
                    h = this.context.y(a, c, j);
                }
            }
            else if (b != null) {
                h = this.context.y(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.bd.count; r++) {
                            let s = this.bd._inner[r](c, o, p);
                            if (s != null) {
                                return s;
                            }
                        }
                        if (o == "name") {
                            let t = p;
                            if (this.a8.containsKey(t)) {
                                return this.a8.item(t);
                            }
                        }
                        return null;
                    }
                }
                else {
                    if (!this.a7.containsKey(c)) {
                        this.a7.addItem(c, ((() => {
                            let $ret = new ContainerState();
                            $ret.i = c;
                            return $ret;
                        })()));
                        d = this.a7.item(c);
                    }
                    d.k(c, n.g, h, n, runOn(this, this.du), f);
                    let u = this.bh(n);
                    this.ds(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.bu(a, b, g);
            }
            if (v) {
                return b;
            }
            return h;
        }
        y(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";
        }
        bu(a, b, c) {
            return this.context.t(a, b, c, this.o());
        }
        o() {
            return true;
        }
        bh(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;
        }
        ad(a, b, c) {
            if (c.c == null) {
                return this.s(a, b, c);
            }
            else {
                let d = this.cc(a, b, c);
                this.db(a, b, c, d);
            }
            return true;
        }
        db(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.de(a, j, b);
                            }
                        }
                    }
                }
            }
        }
        ej(a, b, c, d, e, f) {
            if (this.a9.containsKey(b)) {
                for (let g of fromEnum(this.a9.item(b))) {
                    g(b, a, d);
                }
            }
            this.adapter.setPropertyValue(a, b, c, d, e, f);
        }
        ca(a, b) {
            return this.adapter.getPropertyValue(a, b);
        }
        s(a, b, c) {
            return this.r(a, b);
        }
        r(a, b) {
            let c = this.adapter.getRootObject(a);
            if (c != null) {
                this.de(a, c, b);
            }
            let d = false;
            this.adapter.clearContainer(a, this.context, (e) => {
                d = true;
                if (e) {
                    this.ee(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.de(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;
})();
