import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { TextField, Input } from "@material-ui/core";
import { useState, useEffect } from "react";
export const PropertyEditorFloat = (props) => {
    const propvalue = Reflect.get(props.editObject, props.propertyName);
    const [value, setValue] = 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 (_a) { }
    };
    useEffect(() => {
        if (propvalue) {
            setValue(propvalue.toString());
        }
    }, [propvalue]);
    const onChange = (event) => {
        setValue(event.target.value);
    };
    return (_jsxs(_Fragment, { children: [props.label && (_jsx(TextField, { variant: "outlined", value: value, "data-testid": "property-editor-float", type: 'number', label: props.label, onChange: onChange, onBlur: onBlur, helperText: props.hint }, void 0)),
            !props.label && (_jsx(Input, { value: value, type: "number", onChange: onChange, onBlur: onBlur }, void 0))] }, void 0));
};
//# sourceMappingURL=PropertyEditorFloat.js.map