"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SetAnswerTextUC = void 0;
exports.makeSetAnswerTextUC = makeSetAnswerTextUC;
const core_1 = require("@vived/core");
const Dispatcher_1 = require("../../Dispatcher");
const QuestionAnswerEntity_1 = require("../Entities/QuestionAnswerEntity");
const SetAnswerTextUndoRedo_1 = require("./SetAnswerTextUndoRedo");
class SetAnswerTextUC extends core_1.AppObjectUC {
}
exports.SetAnswerTextUC = SetAnswerTextUC;
SetAnswerTextUC.type = "SetAnswerTextUC";
function makeSetAnswerTextUC(appObject) {
    return new SetAnswerTextUCImp(appObject);
}
class SetAnswerTextUCImp extends SetAnswerTextUC {
    setText(text) {
        if (!this.answer)
            return;
        if (this.answer.text === text)
            return;
        const previousText = this.answer.text;
        this.answer.text = text;
        Dispatcher_1.DispatchStateChangeUC.get(this.appObject.appObjectRepo)?.doDispatch();
        new SetAnswerTextUndoRedo_1.SetAnswerTextUndoRedo(previousText, this.answer.id, this.appObject.appObjectRepo);
    }
    constructor(appObject) {
        super(appObject, SetAnswerTextUC.type);
        this.answer = appObject.getComponent(QuestionAnswerEntity_1.QuestionAnswerEntity.type);
        if (!this.answer) {
            this.warn("SetAnswerTextUC has been added to an app object that does not have QuestionAnswerEntity");
        }
    }
}
//# sourceMappingURL=SetAnswerTextUC.js.map