"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SetAnswerTextUndoRedo = void 0;
const DispatchStateChangeUC_1 = require("../../Dispatcher/UC/DispatchStateChangeUC");
const UndoRedoEntity_1 = require("../../UndoRedo/Entities/UndoRedoEntity");
const Entities_1 = require("../Entities");
class SetAnswerTextUndoRedo {
    constructor(initialText, answerID, appObjects) {
        this.initialText = initialText;
        this.answerID = answerID;
        this.finalText = "";
        this.undoAction = () => {
            if (!this.questionEntity || !this.dispatchStateChange)
                return;
            if (!this.answer)
                return;
            this.answer.text = this.initialText;
            this.dispatchStateChange.doDispatch();
        };
        this.redoAction = () => {
            if (!this.questionEntity || !this.dispatchStateChange)
                return;
            if (!this.answer)
                return;
            this.answer.text = this.finalText;
            this.dispatchStateChange.doDispatch();
        };
        this.questionEntity = Entities_1.QuestionEntity.get(appObjects);
        if (!this.questionEntity) {
            appObjects.submitWarning("SetAnswerTextUndoRedo", "Unable to find QuestionEntity");
            return;
        }
        this.answer = this.questionEntity.getAnswer(this.answerID);
        if (!this.answer) {
            appObjects.submitWarning("SetAnswerTextUndoRedo", "Unable to get answer by ID");
            return;
        }
        this.finalText = this.answer.text;
        this.dispatchStateChange = DispatchStateChangeUC_1.DispatchStateChangeUC.get(appObjects);
        if (!this.dispatchStateChange) {
            appObjects.submitWarning("SetAnswerTextUndoRedo", "Unable to find DispatchStateChangeUC");
            return;
        }
        const undoRedo = UndoRedoEntity_1.UndoRedoEntity.get(appObjects);
        if (!undoRedo) {
            appObjects.submitWarning("SetAnswerTextUndoRedo", "Unable to find UndoRedoEntity");
            return;
        }
        undoRedo.submitAction(this);
    }
}
exports.SetAnswerTextUndoRedo = SetAnswerTextUndoRedo;
//# sourceMappingURL=SetAnswerTextUndoRedo.js.map