"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RadioGroupFormControl = exports.IRadioStyleType = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const RadioGroup_1 = tslib_1.__importDefault(require("@material-ui/core/RadioGroup"));
const FormControl_1 = tslib_1.__importDefault(require("@material-ui/core/FormControl"));
const FormLabel_1 = tslib_1.__importDefault(require("@material-ui/core/FormLabel"));
const react_1 = tslib_1.__importDefault(require("react"));
const DataFormControl_1 = require("../DataFormControl");
const StringDataDefinition_1 = require("@appglue/common/dist/Common/Data/Definitions/StringDataDefinition");
const UIFormControlLabel_1 = require("../../../CommonUI/BuildlingBlocks/UIFormControlLabel");
const UIRadioButton_1 = require("../../../CommonUI/BuildlingBlocks/UIRadioButton");
const PropertyEditorTextList_1 = require("../../../CommonUI/PropertyEditing/PropertyEditorTextList");
const PropertyEditorSelect_1 = require("../../../CommonUI/PropertyEditing/PropertyEditorSelect");
const DataUtilities_1 = require("@appglue/common/dist/Common/DataUtilities");
var IRadioStyleType;
(function (IRadioStyleType) {
    IRadioStyleType["CHECKBOX"] = "checkbox";
    IRadioStyleType["RADIO"] = "radio";
})(IRadioStyleType = exports.IRadioStyleType || (exports.IRadioStyleType = {}));
class XRadioGroupEditUI extends react_1.default.Component {
    render() {
        return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [this.props.editMe.renderBaseDataControlEditor(), (0, jsx_runtime_1.jsx)(PropertyEditorTextList_1.PropertyEditorTextList, { editObject: this.props.editMe, propertyName: "list", updateCallback: this.props.editMe.controlUpdate, label: "List" }), (0, jsx_runtime_1.jsx)(PropertyEditorSelect_1.PropertyEditorSelect, { editObject: this.props.editMe, propertyName: "styleType", updateCallback: this.props.editMe.controlUpdate, label: "Style Type", options: [IRadioStyleType.RADIO, IRadioStyleType.CHECKBOX] })] }));
    }
}
class RadioGroupFormControl extends DataFormControl_1.DataFormControl {
    __type = "Radio Group";
    list = [];
    styleType = IRadioStyleType.RADIO;
    render() {
        let items = this.list;
        if (!items || items.length === 0) {
            items = ["needs configuration", "please setup"];
        }
        return ((0, jsx_runtime_1.jsxs)(FormControl_1.default, { component: "fieldset", children: [(0, jsx_runtime_1.jsx)(FormLabel_1.default, { component: "legend", children: this.label }), (0, jsx_runtime_1.jsx)(RadioGroup_1.default, { "aria-label": "gender", name: this.valueName, value: this.valueName ? this.getFormDataValue(this.valueName) : String, onChange: this.handleChange, "data-testid": this.valueName, children: items.map((item, index) => ((0, jsx_runtime_1.jsx)(UIFormControlLabel_1.UIFormControlLabel, { value: item, control: (0, jsx_runtime_1.jsx)(UIRadioButton_1.UIRadioButton, { color: "primary", type: this.styleType }), label: item }, index))) })] }));
    }
    renderEditUI() {
        return (0, jsx_runtime_1.jsx)(XRadioGroupEditUI, { editMe: this });
    }
    getAddedData() {
        if (!this.valueName)
            return;
        let def = new StringDataDefinition_1.StringDataDefinition();
        def.name = this.valueName;
        return def;
    }
    getStorageData() {
        let retData = super.getStorageData();
        retData = DataUtilities_1.DataUtilities.addStorageData(this, retData, "__type", "list", "styleType");
        return retData;
    }
    setStorageData(data) {
        super.setStorageData(data);
        DataUtilities_1.DataUtilities.setStorageData(this, data, "__type", "list", "styleType");
    }
    handleChange = (event) => {
        if (this.valueName) {
            this.setFormDataValue(this.valueName, event.currentTarget.value);
        }
    };
}
exports.RadioGroupFormControl = RadioGroupFormControl;
//# sourceMappingURL=RadioGroupFormControl.js.map