"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PropertyEditorFloat = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const core_1 = require("@material-ui/core");
const react_1 = require("react");
const PropertyEditorFloat = (props) => {
    const propvalue = Reflect.get(props.editObject, props.propertyName);
    const [value, setValue] = (0, react_1.useState)((propvalue || 0).toString());
    const onBlur = () => {
        try {
            let val = parseFloat(value);
            if (props.decimal) {
                val = parseFloat(value.toFixed(props.decimal));
            }
            Reflect.set(props.editObject, props.propertyName, val);
            props.updateCallback();
        }
        catch { }
    };
    (0, react_1.useEffect)(() => {
        if (propvalue) {
            setValue(propvalue.toString());
        }
    }, [propvalue]);
    const onChange = (event) => {
        setValue(event.target.value);
    };
    return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [props.label && ((0, jsx_runtime_1.jsx)(core_1.TextField, { variant: "outlined", value: value, "data-testid": "property-editor-float", type: "number", label: props.label, onChange: onChange, onBlur: onBlur, helperText: props.hint })), !props.label && (0, jsx_runtime_1.jsx)(core_1.Input, { value: value, type: "number", onChange: onChange, onBlur: onBlur })] }));
};
exports.PropertyEditorFloat = PropertyEditorFloat;
//# sourceMappingURL=PropertyEditorFloat.js.map