"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EditSlideTextUC = void 0;
exports.makeEditSlideTextUC = makeEditSlideTextUC;
const core_1 = require("@vived/core");
const DispatchStateChangeUC_1 = require("../../Dispatcher/UC/DispatchStateChangeUC");
const ShowMarkdownEditorUC_1 = require("../../Dispatcher/UC/ShowMarkdownEditorUC");
const BaseAppState_1 = require("../Entity/BaseAppState");
const UndoRedoEditSlideText_1 = require("./UndoRedoEditSlideText");
class EditSlideTextUC extends core_1.AppObjectUC {
}
exports.EditSlideTextUC = EditSlideTextUC;
EditSlideTextUC.type = "EditSlideTextUC";
EditSlideTextUC.get = (appObjects) => (0, core_1.getSingletonComponent)(EditSlideTextUC.type, appObjects);
function makeEditSlideTextUC(appObject) {
    return new EditSlideTextUCImp(appObject);
}
class EditSlideTextUCImp extends EditSlideTextUC {
    constructor(appObject) {
        super(appObject, EditSlideTextUC.type);
        this.submitCallback = (text) => {
            if (!this.baseApp) {
                this.warn("Unable to find AppState");
                return;
            }
            const prevText = this.baseApp.slideText;
            if (prevText === text) {
                return;
            }
            this.baseApp.slideText = text;
            (0, DispatchStateChangeUC_1.dispatchStateChange)(this.appObjects);
            new UndoRedoEditSlideText_1.UndoRedoEditSlideText(prevText, this.appObjects);
        };
        this.editSlideText = () => {
            if (!this.baseApp) {
                this.warn("Unable to find AppState");
                return;
            }
            const showMDUC = ShowMarkdownEditorUC_1.ShowMarkdownEditorUC.get(this.appObjects);
            if (!showMDUC) {
                this.warn("Unable to find ShowMarkdownEditorUC");
                return;
            }
            const slideText = this.baseApp.slideText;
            const dto = {
                initialText: slideText,
                submitCallback: this.submitCallback,
            };
            showMDUC.showMarkdownEditor(dto);
        };
        this.baseApp = appObject.getComponent(BaseAppState_1.BaseAppState.type);
        if (!this.baseApp) {
            this.warn("EditSlideTextUCImp UC has been added to an App Object that does not have a AppState Entity. Add one before adding the UC");
        }
    }
}
//# sourceMappingURL=EditSlideTextUC.js.map