import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import FormControl from "@material-ui/core/FormControl";
import FormLabel from "@material-ui/core/FormLabel";
import TextField from "@material-ui/core/TextField";
import ToggleButton from "@material-ui/lab/ToggleButton";
import ToggleButtonGroup from "@material-ui/lab/ToggleButtonGroup";
import { List, ListItem, ListItemText, ListItemSecondaryAction, IconButton, Button } from "@material-ui/core";
import RemoveIcon from "@material-ui/icons/Remove";
import React from "react";
import { BaseDataControl } from "./BaseDataControl";
import { StringDataDefinition } from "../../Common/Data/Definitions/StringDataDefinition";
class XButtonGroupEditUI extends React.Component {
    render() {
        return (_jsxs(_Fragment, { children: [_jsx(TextField, { label: "Content Text", value: this.props.editMe.label, onChange: (event) => {
                        this.props.editMe.label = event.target.value;
                        this.props.editMe.controlUpdate();
                    } }, void 0),
                _jsx(TextField, { label: "Value Name", value: this.props.editMe.valueName, onChange: (event) => {
                        this.props.editMe.valueName = event.target.value;
                        this.props.editMe.controlUpdate();
                    } }, void 0),
                _jsx(List, Object.assign({ style: { width: "100%" } }, { children: this.props.editMe.list.map((s, idx) => (_jsxs(ListItem, { children: [_jsx(ListItemText, { children: _jsx(TextField, { label: "Button Label", value: s, size: "small", onChange: (event) => {
                                        this.props.editMe.list[idx] = event.target.value;
                                        this.props.editMe.controlUpdate();
                                    } }, idx) }, void 0),
                            _jsx(ListItemSecondaryAction, { children: _jsx(IconButton, Object.assign({ color: "secondary", size: "small", onClick: () => {
                                        this.props.editMe.list.splice(idx, 1);
                                        this.props.editMe.controlUpdate();
                                    } }, { children: _jsx(RemoveIcon, {}, void 0) }), void 0) }, void 0)] }, void 0))) }), void 0),
                _jsxs(Button, Object.assign({ color: "primary", onClick: () => {
                        this.props.editMe.list.push("");
                        this.props.editMe.controlUpdate();
                    } }, { children: [" ", "Add Button", " "] }), void 0)] }, void 0));
    }
}
export class XButtonGroup extends BaseDataControl {
    constructor() {
        super(...arguments);
        this.label = "buttonGroupLabel";
        this.valueName = "buttonGroupValue";
        this.list = [];
        this.handleChange = (event, newValue) => {
            if (this.valueName) {
                this.setFormDataValue(this.valueName, newValue);
            }
        };
    }
    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(ToggleButtonGroup, Object.assign({ exclusive: true, color: "primary", "aria-label": "contained primary button group", onChange: this.handleChange, value: this.valueName ? this.getFormDataValue(this.valueName) : "", "data-testid": this.valueName }, { children: items.map((item, index) => (_jsx(ToggleButton, Object.assign({ color: "primary", value: item, "aria-label": item }, { children: item }), index))) }), void 0)] }), void 0));
    }
    renderEditUI() {
        return _jsx(XButtonGroupEditUI, { editMe: this }, void 0);
    }
    getAddedData() {
        if (!this.valueName)
            return;
        let def = new StringDataDefinition();
        def.name = this.valueName;
        return def;
    }
}
//# sourceMappingURL=XButtonGroup.js.map