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