"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RichTextEditorFormControl = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const RichTextEditor_1 = require("../../../CommonUI/RichTextEditor");
const PropertyEditorText_1 = require("../../../CommonUI/PropertyEditing/PropertyEditorText");
const CommonStyled_1 = require("./CommonStyled");
const TextEntryFormControl_1 = require("../TextEntryFormControl");
const StringDataDefinition_1 = require("@appglue/common/dist/Common/Data/Definitions/StringDataDefinition");
const DataUtilities_1 = require("@appglue/common/dist/Common/DataUtilities");
class RichTextEditorFormControl extends TextEntryFormControl_1.TextEntryFormControl {
    exportFileName = "output";
    __type = "Rich Text Edit";
    render() {
        const issueData = this.getFormContext().getControlContext(this).getRuntimeIssueData();
        const issueText = issueData?.text || "";
        return ((0, jsx_runtime_1.jsxs)("div", { style: {
                width: this.fullWidth ? "100%" : `${this.width || 200}px`,
            }, children: [this.label && (0, jsx_runtime_1.jsx)(CommonStyled_1.StyledInputLabel, { children: this.label }), (0, jsx_runtime_1.jsx)(RichTextEditor_1.RichTextEditor, { value: this.valueName && this.getFormDataValue(this.valueName), updateCallback: (val) => this.valueName && val !== "" && this.setFormDataValue(this.valueName, val), placeholder: this.placeholderText || "Label", exportFileName: this.exportFileName, ref: this.ref }), (issueText || this.hintText) && ((0, jsx_runtime_1.jsx)(CommonStyled_1.StyledFormHelperText, { error: Boolean(issueText), "data-testid": "issueOrHintText", children: issueText ? issueText : this.hintText }))] }));
    }
    getAddedData() {
        if (!this.valueName)
            return;
        let dd = new StringDataDefinition_1.StringDataDefinition();
        dd.name = this.valueName;
        return dd;
    }
    renderEditUI() {
        return (0, jsx_runtime_1.jsx)(XRichTextEditorUI, { editMe: this });
    }
    getStorageData() {
        let retData = super.getStorageData();
        retData = DataUtilities_1.DataUtilities.addStorageData(this, retData, "exportFileName", "__type");
        return retData;
    }
    setStorageData(data) {
        super.setStorageData(data);
        DataUtilities_1.DataUtilities.setStorageData(this, data, "exportFileName", "__type");
    }
}
exports.RichTextEditorFormControl = RichTextEditorFormControl;
function XRichTextEditorUI(props) {
    return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [props.editMe.renderBaseDataControlEditor(["requiredOnAllOutcomes"]), props.editMe.renderTextControlBasePropertyEditor(), (0, jsx_runtime_1.jsx)(PropertyEditorText_1.PropertyEditorText, { editObject: props.editMe, label: "Export File Name", propertyName: "exportFileName", updateCallback: props.editMe.controlUpdate })] }));
}
//# sourceMappingURL=RichTextEditorFormControl.js.map