"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HasUndoPM = void 0;
exports.makeHasUndoPM = makeHasUndoPM;
const core_1 = require("@vived/core");
const UndoRedoEntity_1 = require("../Entities/UndoRedoEntity");
class HasUndoPM extends core_1.AppObjectPM {
}
exports.HasUndoPM = HasUndoPM;
HasUndoPM.type = "HasUndoPM";
HasUndoPM.get = (appObjects) => (0, core_1.getSingletonComponent)(HasUndoPM.type, appObjects);
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_1.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