import { getSingletonComponent } from "@vived/core";
import { AppObjectUC } from "@vived/core";
import { AppDispatcher } from "../Entities/AppDispatcher";
export class ShowMarkdownEditorUC extends AppObjectUC {
    constructor() {
        super(...arguments);
        this.requestType = "SHOW_MARKDOWN_EDITOR";
    }
}
ShowMarkdownEditorUC.type = "ShowMarkdownEditorUC";
ShowMarkdownEditorUC.get = (appObjects) => getSingletonComponent(ShowMarkdownEditorUC.type, appObjects);
export 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.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