import { AppObjectUC, getSingletonComponent, } from "@vived/core";
import { dispatchStateChange } from "../../Dispatcher/UC/DispatchStateChangeUC";
import { ShowMarkdownEditorUC, } from "../../Dispatcher/UC/ShowMarkdownEditorUC";
import { BaseAppState } from "../Entity/BaseAppState";
import { UndoRedoEditSlideText } from "./UndoRedoEditSlideText";
export class EditSlideTextUC extends AppObjectUC {
}
EditSlideTextUC.type = "EditSlideTextUC";
EditSlideTextUC.get = (appObjects) => getSingletonComponent(EditSlideTextUC.type, appObjects);
export 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;
            dispatchStateChange(this.appObjects);
            new UndoRedoEditSlideText(prevText, this.appObjects);
        };
        this.editSlideText = () => {
            if (!this.baseApp) {
                this.warn("Unable to find AppState");
                return;
            }
            const showMDUC = 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.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