import { AppObjectPM, getSingletonComponent, } from "@vived/core";
import { UndoRedoEntity } from "../Entities/UndoRedoEntity";
export class HasUndoPM extends AppObjectPM {
}
HasUndoPM.type = "HasUndoPM";
HasUndoPM.get = (appObjects) => getSingletonComponent(HasUndoPM.type, appObjects);
export function makeHasUndoPM(appObject) {
    return new HasUndoPMImp(appObject);
}
class HasUndoPMImp extends HasUndoPM {
    vmsAreEqual(a, b) {
        return a === b;
    }
    constructor(appObject) {
        super(appObject, HasUndoPM.type);
        this.dispose = () => {
            super.dispose();
            this.undoRedoEntity?.removeChangeObserver(this.onEntityChange);
        };
        this.onEntityChange = () => {
            if (!this.undoRedoEntity)
                return;
            this.doUpdateView(this.undoRedoEntity.hasUndo);
        };
        this.undoRedoEntity = appObject.getComponent(UndoRedoEntity.type);
        if (this.undoRedoEntity) {
            this.undoRedoEntity.addChangeObserver(this.onEntityChange);
            this.onEntityChange();
        }
        else {
            this.warn("HasUndoPM has been added to an app object that does not have UndoRedoEntity");
        }
    }
}
//# sourceMappingURL=HasUndoPM.js.map