"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InlineTextEditFormControl = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const TextEntryFormControl_1 = require("../TextEntryFormControl");
const InlineTextEdit_1 = require("../../../CommonUI/InlineTextEdit");
const PropertyEditorText_1 = require("../../../CommonUI/PropertyEditing/PropertyEditorText");
const PropertyEditorSelect_1 = require("../../../CommonUI/PropertyEditing/PropertyEditorSelect");
const PropertyEditorBoolean_1 = require("../../../CommonUI/PropertyEditing/PropertyEditorBoolean");
const PropertyEditorInteger_1 = require("../../../CommonUI/PropertyEditing/PropertyEditorInteger");
const core_1 = require("@material-ui/core");
const CommonStyled_1 = require("./CommonStyled");
const StringDataDefinition_1 = require("@appglue/common/dist/Common/Data/Definitions/StringDataDefinition");
const DataUtilities_1 = require("@appglue/common/dist/Common/DataUtilities");
class InlineTextEditFormControl extends TextEntryFormControl_1.TextEntryFormControl {
    __type = "Inline Text Edit";
    type = "h6";
    focusControl() {
        this.ref.current && this.ref.current.click();
    }
    render() {
        const issueData = this.getFormContext().getControlContext(this).getRuntimeIssueData();
        const issueText = issueData?.text || "";
        const customWidth = this.fullWidth ? "100%" : this.width ? `${this.width}px` : "300px";
        return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(InlineTextEdit_1.InlineTextEdit, { text: this.valueName && this.getFormDataValue(this.valueName), onEdit: (val) => this.valueName && val !== "" && this.setFormDataValue(this.valueName, val), placeholder: this.placeholderText || "Label", variant: this.type, fullWidth: this.fullWidth, width: customWidth, multiLine: false, 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)(XInlineTextEditUI, { editMe: this });
    }
    getStorageData() {
        let retData = super.getStorageData();
        retData = DataUtilities_1.DataUtilities.addStorageData(this, retData, "__type", "type");
        return retData;
    }
    setStorageData(data) {
        super.setStorageData(data);
        DataUtilities_1.DataUtilities.setStorageData(this, data, "__type", "type");
    }
}
exports.InlineTextEditFormControl = InlineTextEditFormControl;
function XInlineTextEditUI(props) {
    const options = [
        "h1",
        "h2",
        "h3",
        "h4",
        "h5",
        "h6",
        "subtitle1",
        "subtitle2",
        "body1",
        "caption",
        "button",
        "overline",
    ];
    return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(PropertyEditorSelect_1.PropertyEditorSelect, { label: "Select Tag", propertyName: "type", editObject: props.editMe, updateCallback: props.editMe.controlUpdate, options: options }), props.editMe.renderBaseDataControlEditor(["label"]), (0, jsx_runtime_1.jsx)(PropertyEditorText_1.PropertyEditorText, { label: "Placeholder Text", propertyName: "placeholderText", editObject: props.editMe, updateCallback: props.editMe.controlUpdate }), (0, jsx_runtime_1.jsx)(PropertyEditorText_1.PropertyEditorText, { label: "Hint Text", propertyName: "hintText", editObject: props.editMe, updateCallback: props.editMe.controlUpdate }), (0, jsx_runtime_1.jsx)(PropertyEditorBoolean_1.PropertyEditorBoolean, { label: "Full Width", updateCallback: props.editMe.controlUpdate, propertyName: "fullWidth", editObject: props.editMe }), (0, jsx_runtime_1.jsx)(core_1.Collapse, { in: !props.editMe.fullWidth, children: (0, jsx_runtime_1.jsx)(PropertyEditorInteger_1.PropertyEditorInteger, { label: "Width", updateCallback: props.editMe.controlUpdate, propertyName: "width", editObject: props.editMe }) })] }));
}
//# sourceMappingURL=InlineTextEditFormControl.js.map