import { jsx as _jsx } from "react/jsx-runtime";
import clsx from "clsx";
import React, { useState } from "react";
import { Styles } from "@vertesia/ui/core";
const Input = React.forwardRef(({ object, type = 'text', onChange, ...props }, ref) => {
    const [actualValue, setValue] = useState(object.value != null ? String(object.value) : '');
    const [booleanValue, setBooleanValue] = useState(object.schema.isBoolean && object.value === true);
    if (props.className) {
        props.className = clsx(Styles.INPUT, props.className);
    }
    else {
        props.className = Styles.INPUT;
    }
    const _onChange = (ev) => {
        if (props.disabled)
            return;
        setValue(ev.target.value);
        if (object.schema.isBoolean) {
            object.value = ev.target.checked;
            setBooleanValue(object.value);
        }
        else {
            object.value = ev.target.value;
        }
        onChange && onChange(ev);
    };
    if (type === 'textarea') {
        return (_jsx("textarea", { ref: ref, ...props, value: actualValue, onChange: _onChange }));
    }
    else if (type === 'checkbox') {
        return (_jsx("input", { ref: ref, ...props, type: "checkbox", checked: booleanValue, onChange: _onChange, className: "form-check-input" }));
    }
    else {
        return (_jsx("input", { ref: ref, ...props, type: type, value: actualValue, onChange: _onChange }));
    }
});
export { Input };
//# sourceMappingURL=inputs.js.map