"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InlineRichTextEditorFormControl = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const InlineRichTextEdit_1 = require("../../../CommonUI/InlineRichTextEdit");
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 PropertyEditorBoolean_1 = require("../../../CommonUI/PropertyEditing/PropertyEditorBoolean");
const DataUtilities_1 = require("@appglue/common/dist/Common/DataUtilities");
class InlineRichTextEditorFormControl extends TextEntryFormControl_1.TextEntryFormControl {
    __type = "Inline Rich Text Edit";
    showToolsOnFocus = false;
    exportFileName = "output";
    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)(InlineRichTextEdit_1.InlineRichTextEdit, { value: this.valueName && this.getFormDataValue(this.valueName), updateCallback: (val) => this.valueName && val !== "" && this.setFormDataValue(this.valueName, val), placeholder: this.placeholderText || "Label", showToolsOnFocus: this.showToolsOnFocus, 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)(XInlineRichTextEditorUI, { editMe: this });
    }
    getStorageData() {
        let retData = super.getStorageData();
        retData = DataUtilities_1.DataUtilities.addStorageData(this, retData, "__type", "showToolsOnFocus", "exportFileName");
        return retData;
    }
    setStorageData(data) {
        super.setStorageData(data);
        DataUtilities_1.DataUtilities.setStorageData(this, data, "__type", "showToolsOnFocus", "exportFileName");
    }
}
exports.InlineRichTextEditorFormControl = InlineRichTextEditorFormControl;
function XInlineRichTextEditorUI(props) {
    return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [props.editMe.renderBaseDataControlEditor(["requiredOnAllOutcomes"]), (0, jsx_runtime_1.jsx)(PropertyEditorBoolean_1.PropertyEditorBoolean, { editObject: props.editMe, label: "Show Tools On Focus", propertyName: "showToolsOnFocus", updateCallback: props.editMe.controlUpdate }), 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=InlineRichTextEditorFormControl.js.map