import { AppObjectPM } from "@vived/core";
import { EnablementEntity } from "../Entities/EnablementEntity";
export class EnabledStatePM extends AppObjectPM {
    static get(appObjID, appObjects) {
        const appObj = appObjects.get(appObjID);
        if (appObj === undefined) {
            return undefined;
        }
        return appObj.getComponent(EnabledStatePM.type);
    }
}
EnabledStatePM.type = "EnabledStatePM";
export function makeEnabledStatePM(appObject) {
    return new EnabledStatePMImp(appObject);
}
class EnabledStatePMImp extends EnabledStatePM {
    get entity() {
        return this.getCachedLocalComponent(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