import { AppObjectUC } from "@vived/core";
import { DispatchStateChangeUC } from "../../Dispatcher";
import { QuestionAnswerEntity } from "../Entities/QuestionAnswerEntity";
import { SetAnswerTextUndoRedo } from "./SetAnswerTextUndoRedo";
export class SetAnswerTextUC extends AppObjectUC {
}
SetAnswerTextUC.type = "SetAnswerTextUC";
export 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;
        DispatchStateChangeUC.get(this.appObject.appObjectRepo)?.doDispatch();
        new SetAnswerTextUndoRedo(previousText, this.answer.id, this.appObject.appObjectRepo);
    }
    constructor(appObject) {
        super(appObject, SetAnswerTextUC.type);
        this.answer = appObject.getComponent(QuestionAnswerEntity.type);
        if (!this.answer) {
            this.warn("SetAnswerTextUC has been added to an app object that does not have QuestionAnswerEntity");
        }
    }
}
//# sourceMappingURL=SetAnswerTextUC.js.map