import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import RadioGroup from "@material-ui/core/RadioGroup";
import FormControl from "@material-ui/core/FormControl";
import FormLabel from "@material-ui/core/FormLabel";
import React from "react";
import { BaseDataControl } from "./BaseDataControl";
import { StringDataDefinition } from "../../Common/Data/Definitions/StringDataDefinition";
import { StyledFormControlLabel } from "../../CommonUI/Components/FormControlLabel";
import { StyledRadio } from "../../CommonUI/Components/Radio";
import { PropertyEditorTextList } from "../../CommonUI/PropertyEditing/PropertyEditorTextList";
import { PropertyEditorSelect } from "../../CommonUI/PropertyEditing/PropertyEditorSelect";
export var IRadioStyleType;
(function (IRadioStyleType) {
    IRadioStyleType["CHECKBOX"] = "checkbox";
    IRadioStyleType["RADIO"] = "radio";
})(IRadioStyleType || (IRadioStyleType = {}));
class XRadioGroupEditUI extends React.Component {
    render() {
        return (_jsxs(_Fragment, { children: [this.props.editMe.renderBaseDataControlEditor(), _jsx(PropertyEditorTextList, { editObject: this.props.editMe, propertyName: "list", updateCallback: this.props.editMe.controlUpdate, label: "List" }, void 0),
                _jsx(PropertyEditorSelect, { editObject: this.props.editMe, propertyName: "styleType", updateCallback: this.props.editMe.controlUpdate, label: "Style Type", options: [IRadioStyleType.RADIO, IRadioStyleType.CHECKBOX] }, void 0)] }, void 0));
    }
}
export class XRadioGroup extends BaseDataControl {
    constructor() {
        super(...arguments);
        this.list = [];
        this.styleType = IRadioStyleType.RADIO;
        this.handleChange = (event) => {
            if (this.valueName) {
                this.setFormDataValue(this.valueName, event.currentTarget.value);
            }
        };
    }
    render() {
        let items = this.list;
        if (!items || items.length === 0) {
            items = ["needs configuration", "please setup"];
        }
        return (_jsxs(FormControl, Object.assign({ component: "fieldset" }, { children: [_jsx(FormLabel, Object.assign({ component: "legend" }, { children: this.label }), void 0),
                _jsx(RadioGroup, Object.assign({ "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) => (_jsx(StyledFormControlLabel, { value: item, control: _jsx(StyledRadio, { color: "primary", type: this.styleType }, void 0), label: item }, index))) }), void 0)] }), void 0));
    }
    renderEditUI() {
        return _jsx(XRadioGroupEditUI, { editMe: this }, void 0);
    }
    getAddedData() {
        if (!this.valueName)
            return;
        let def = new StringDataDefinition();
        def.name = this.valueName;
        return def;
    }
}
//# sourceMappingURL=XRadioGroup.js.map