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