"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HasRedoPM = void 0;
exports.makeHasRedoPM = makeHasRedoPM;
const core_1 = require("@vived/core");
const UndoRedoEntity_1 = require("../Entities/UndoRedoEntity");
class HasRedoPM extends core_1.AppObjectPM {
}
exports.HasRedoPM = HasRedoPM;
HasRedoPM.type = "HasRedoPM";
HasRedoPM.get = (appObjects) => (0, core_1.getSingletonComponent)(HasRedoPM.type, appObjects);
function makeHasRedoPM(appObject) {
    return new HasRedoPMImp(appObject);
}
class HasRedoPMImp extends HasRedoPM {
    vmsAreEqual(a, b) {
        return a === b;
    }
    constructor(appObject) {
        super(appObject, HasRedoPM.type);
        this.dispose = () => {
            super.dispose();
            this.undoRedoEntity?.removeChangeObserver(this.onEntityChange);
        };
        this.onEntityChange = () => {
            if (!this.undoRedoEntity)
                return;
            this.doUpdateView(this.undoRedoEntity.hasRedo);
        };
        this.undoRedoEntity = appObject.getComponent(UndoRedoEntity_1.UndoRedoEntity.type);
        if (this.undoRedoEntity) {
            this.undoRedoEntity.addChangeObserver(this.onEntityChange);
            this.onEntityChange();
        }
        else {
            this.warn("HasRedoPM has been added to an app object that does not have UndoRedoEntity");
        }
    }
}
//# sourceMappingURL=HasRedoPM.js.map