import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import React from "react";
import FormControlLabel from '@material-ui/core/FormControlLabel';
import Switch from '@material-ui/core/Switch';
import { BaseDataControl } from "./BaseDataControl";
import { BooleanDataDefinition } from "../../Common/Data/Definitions/BooleanDataDefinition";
import { PropertyEditorBoolean } from "../../CommonUI/PropertyEditing/PropertyEditorBoolean";
class XSwitchEditUI extends React.Component {
    render() {
        return (_jsxs(_Fragment, { children: [this.props.editMe.renderBaseDataControlEditor(['requiredOnAllOutcomes']), _jsx(PropertyEditorBoolean, { editObject: this.props.editMe, propertyName: 'defaultValue', label: "Default Value", updateCallback: this.props.editMe.controlUpdate }, void 0)] }, void 0));
    }
}
export class XSwitch extends BaseDataControl {
    constructor() {
        super(...arguments);
        this.defaultValue = false;
        this.handleChange = (event) => {
            if (this.valueName) {
                this.setFormDataValue(this.valueName, event.currentTarget.checked);
            }
        };
        this.getValue = () => {
            if (this.valueName) {
                let value = this.getFormDataValue(this.valueName);
                if (typeof value === 'undefined' || value === null) {
                    return this.defaultValue;
                }
                return value;
            }
            return this.defaultValue;
        };
    }
    render() {
        return (_jsx(FormControlLabel, { control: _jsx(Switch, { checked: this.getValue(), onChange: this.handleChange, name: this.valueName, color: "primary", "data-testid": this.valueName, inputRef: this.ref }, void 0), label: this.label }, void 0));
    }
    renderEditUI() {
        return _jsx(XSwitchEditUI, { editMe: this }, void 0);
    }
    getAddedData() {
        if (!this.valueName)
            return;
        let def = new BooleanDataDefinition();
        def.name = this.valueName;
        return def;
    }
}
//# sourceMappingURL=XSwitch.js.map