"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ShowMarkdownEditorUC = void 0;
exports.makeShowMarkdownEditorUC = makeShowMarkdownEditorUC;
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const AppDispatcher_1 = require("../Entities/AppDispatcher");
class ShowMarkdownEditorUC extends core_2.AppObjectUC {
    constructor() {
        super(...arguments);
        this.requestType = "SHOW_MARKDOWN_EDITOR";
    }
}
exports.ShowMarkdownEditorUC = ShowMarkdownEditorUC;
ShowMarkdownEditorUC.type = "ShowMarkdownEditorUC";
ShowMarkdownEditorUC.get = (appObjects) => (0, core_1.getSingletonComponent)(ShowMarkdownEditorUC.type, appObjects);
function makeShowMarkdownEditorUC(appObject) {
    return new ShowMarkdownEditorUCImp(appObject);
}
class ShowMarkdownEditorUCImp extends ShowMarkdownEditorUC {
    constructor(appObject) {
        super(appObject, ShowMarkdownEditorUC.type);
        this.requestVersion = 1;
        this.showMarkdownEditor = (data) => {
            if (!this.appDispatcher)
                return;
            const payload = {
                initialText: data.initialText ?? "",
                submitCallback: data.submitCallback,
            };
            if (data.validateString) {
                payload.validateString = data.validateString;
            }
            this.appDispatcher.formRequestAndDispatch(this.requestType, this.requestVersion, payload);
        };
        this.appDispatcher = appObject.getComponent(AppDispatcher_1.AppDispatcher.type);
        if (!this.appDispatcher) {
            console.warn(`${ShowMarkdownEditorUC.type} has been added to an App Object that does not have a AppDispatcher. Add a dispatcher first`);
            this.dispose();
        }
    }
}
//# sourceMappingURL=ShowMarkdownEditorUC.js.map