"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnabledStatePM = void 0;
exports.makeEnabledStatePM = makeEnabledStatePM;
const core_1 = require("@vived/core");
const EnablementEntity_1 = require("../Entities/EnablementEntity");
class EnabledStatePM extends core_1.AppObjectPM {
    static get(appObjID, appObjects) {
        const appObj = appObjects.get(appObjID);
        if (appObj === undefined) {
            return undefined;
        }
        return appObj.getComponent(EnabledStatePM.type);
    }
}
exports.EnabledStatePM = EnabledStatePM;
EnabledStatePM.type = "EnabledStatePM";
function makeEnabledStatePM(appObject) {
    return new EnabledStatePMImp(appObject);
}
class EnabledStatePMImp extends EnabledStatePM {
    get entity() {
        return this.getCachedLocalComponent(EnablementEntity_1.EnablementEntity.type);
    }
    vmsAreEqual(a, b) {
        return a === b;
    }
    constructor(appObject) {
        super(appObject, EnabledStatePM.type);
        this.onEntityChange = () => {
            if (!this.entity)
                return;
            this.doUpdateView(this.entity.enabled);
        };
        this.dispose = () => {
            super.dispose();
            this.entity?.removeChangeObserver(this.onEntityChange);
            this.entity?.removeChangeObserver(this.dispose);
        };
        this.entity?.addChangeObserver(this.onEntityChange);
        this.entity?.addOnDisposeObserver(this.dispose);
        this.onEntityChange();
    }
}
//# sourceMappingURL=EnabledStatePM.js.map