"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SwitchFormControl = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = tslib_1.__importDefault(require("react"));
const DataFormControl_1 = require("../DataFormControl");
const BooleanDataDefinition_1 = require("@appglue/common/dist/Common/Data/Definitions/BooleanDataDefinition");
const PropertyEditorBoolean_1 = require("../../../CommonUI/PropertyEditing/PropertyEditorBoolean");
const DataUtilities_1 = require("@appglue/common/dist/Common/DataUtilities");
const UISwitch_1 = require("../../../CommonUI/BuildlingBlocks/UISwitch");
const material_1 = require("@mui/material");
const UILabel_1 = require("../../../CommonUI/BuildlingBlocks/UILabel");
class XSwitchEditUI extends react_1.default.Component {
    render() {
        return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [this.props.editMe.renderBaseDataControlEditor(["requiredOnAllOutcomes"]), (0, jsx_runtime_1.jsx)(PropertyEditorBoolean_1.PropertyEditorBoolean, { editObject: this.props.editMe, propertyName: "defaultValue", label: "Default Value", updateCallback: this.props.editMe.controlUpdate })] }));
    }
}
class SwitchFormControl extends DataFormControl_1.DataFormControl {
    __type = "Switch";
    defaultValue = false;
    render() {
        return ((0, jsx_runtime_1.jsxs)(material_1.Box, { display: "flex", alignItems: "center", children: [(0, jsx_runtime_1.jsx)(UILabel_1.UILabel, { paddingRight: "10px", children: this.label }), (0, jsx_runtime_1.jsx)(UISwitch_1.UISwitch, { checked: this.getValue(), onSet: this.handleChange, "data-testid": this.valueName })] }));
    }
    renderEditUI() {
        return (0, jsx_runtime_1.jsx)(XSwitchEditUI, { editMe: this });
    }
    getAddedData() {
        if (!this.valueName)
            return;
        let def = new BooleanDataDefinition_1.BooleanDataDefinition();
        def.name = this.valueName;
        return def;
    }
    getStorageData() {
        let retData = super.getStorageData();
        retData = DataUtilities_1.DataUtilities.addStorageData(this, retData, "__type", "defaultValue");
        return retData;
    }
    setStorageData(data) {
        super.setStorageData(data);
        DataUtilities_1.DataUtilities.setStorageData(this, data, "__type", "defaultValue");
    }
    handleChange = (newValue) => {
        if (this.valueName) {
            this.setFormDataValue(this.valueName, newValue);
        }
    };
    getValue = () => {
        if (this.valueName) {
            let value = this.getFormDataValue(this.valueName);
            if (typeof value === "undefined" || value === null) {
                return this.defaultValue;
            }
            return value;
        }
        return this.defaultValue;
    };
}
exports.SwitchFormControl = SwitchFormControl;
//# sourceMappingURL=SwitchFormControl.js.map