"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UndoRedoToolStatesHook = void 0;
const core_1 = require("@vived/core");
const BaseAppState_1 = require("../../BaseApp/Entity/BaseAppState");
const Entities_1 = require("../../Tools/Entities");
const Entities_2 = require("../Entities");
class UndoRedoToolStatesHook extends core_1.AppObjectUC {
    get baseApp() {
        return this.getCachedSingleton(BaseAppState_1.BaseAppState.type);
    }
    get undoRedo() {
        return this.getCachedSingleton(Entities_2.UndoRedoEntity.type);
    }
    get toolRepo() {
        return this.getCachedSingleton(Entities_1.ToolRepository.type);
    }
    constructor(appObject) {
        super(appObject, UndoRedoToolStatesHook.type);
        this.onUndoRedoChange = () => {
            const undoTool = this.toolRepo?.getTool("UNDO");
            const redoTool = this.toolRepo?.getTool("REDO");
            if (!this.baseApp)
                return;
            if (!this.undoRedo)
                return;
            if (redoTool) {
                if (this.baseApp.isAuthoring) {
                    redoTool.state = this.undoRedo.hasRedo
                        ? Entities_1.ToolState.ENABLED
                        : Entities_1.ToolState.DISABLED;
                }
                else {
                    redoTool.state = Entities_1.ToolState.HIDDEN;
                }
            }
            if (undoTool) {
                if (this.baseApp.isAuthoring) {
                    undoTool.state = this.undoRedo.hasUndo
                        ? Entities_1.ToolState.ENABLED
                        : Entities_1.ToolState.DISABLED;
                }
                else {
                    undoTool.state = Entities_1.ToolState.HIDDEN;
                }
            }
        };
        this.undoRedo?.addChangeObserver(this.onUndoRedoChange);
        this.baseApp?.addChangeObserver(this.onUndoRedoChange);
        this.onUndoRedoChange();
    }
}
exports.UndoRedoToolStatesHook = UndoRedoToolStatesHook;
UndoRedoToolStatesHook.type = "UndoRedoToolStatesHook";
//# sourceMappingURL=UndoRedoButtonStatesHook.js.map