"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.ManagedComponent = void 0;
const ste_events_1 = require("ste-events");
const Utilities_1 = require("../core/Utilities");
class ManagedComponent {
    _data;
    _parent;
    id;
    _onPropertyChanged = new ste_events_1.EventDispatcher();
    get onPropertyChanged() {
        return this._onPropertyChanged.asEvent();
    }
    constructor(parent, id, data) {
        this._parent = parent;
        this._data = data;
        this.id = id;
    }
    getData() {
        return this._data;
    }
    getBaseValue() {
        return this._data;
    }
    setData(newData) {
        if (Utilities_1.default.isUsableAsObjectKey(this.id)) {
            this._parent[this.id] = newData;
        }
        this._data = newData;
    }
    setBaseValue(value) {
        this._parent[this.id] = value;
        this._data = value;
    }
    getProperty(id) {
        if (!this._data) {
            return undefined;
        }
        return this._data[id];
    }
    setProperty(propertyId, value) {
        if (typeof this._data === "string") {
            if (this.id === "minecraft:geometry") {
                this._data = {
                    identifier: this._data,
                };
            }
            else {
                this._data = {
                    value: this._data,
                };
            }
        }
        if (this._data && typeof this._data !== "string" && Utilities_1.default.isUsableAsObjectKey(propertyId)) {
            this._data[propertyId] = value;
        }
    }
}
exports.ManagedComponent = ManagedComponent;

//# sourceMappingURL=../maps/minecraft/ManagedComponent.js.map
