import { AppObjectUC } from "@vived/core";
import { BaseAppState } from "../../BaseApp/Entity/BaseAppState";
import { ToolRepository, ToolState } from "../../Tools/Entities";
import { UndoRedoEntity } from "../Entities";
export class UndoRedoToolStatesHook extends AppObjectUC {
    get baseApp() {
        return this.getCachedSingleton(BaseAppState.type);
    }
    get undoRedo() {
        return this.getCachedSingleton(UndoRedoEntity.type);
    }
    get toolRepo() {
        return this.getCachedSingleton(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
                        ? ToolState.ENABLED
                        : ToolState.DISABLED;
                }
                else {
                    redoTool.state = ToolState.HIDDEN;
                }
            }
            if (undoTool) {
                if (this.baseApp.isAuthoring) {
                    undoTool.state = this.undoRedo.hasUndo
                        ? ToolState.ENABLED
                        : ToolState.DISABLED;
                }
                else {
                    undoTool.state = ToolState.HIDDEN;
                }
            }
        };
        this.undoRedo?.addChangeObserver(this.onUndoRedoChange);
        this.baseApp?.addChangeObserver(this.onUndoRedoChange);
        this.onUndoRedoChange();
    }
}
UndoRedoToolStatesHook.type = "UndoRedoToolStatesHook";
//# sourceMappingURL=UndoRedoButtonStatesHook.js.map