import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { Controller } from "react-hook-form";
import { NumericFormat } from "react-number-format";
import { twMerge } from "tailwind-merge";
import { RWATableTextInput } from "./text-input.js";
export function RWANumberInput(props) {
    const { name, control, currency, rules, errorMessage, errorMessageClassName, numericFormatProps, value: _, onChange: __, ...inputProps } = props;
    const { allowNegative = false, decimalScale = 2, thousandSeparator = ",", fixedDecimalScale = true, } = numericFormatProps ?? {};
    const prefix = currency === "USD" ? "$" : undefined;
    const invalid = props["aria-invalid"] === "true";
    return (_jsx(Controller, { control: control, name: name, render: ({ field: { onChange, value, ref } }) => (_jsxs(_Fragment, { children: [_jsx(NumericFormat, { ...inputProps, allowNegative: allowNegative, customInput: RWATableTextInput, decimalScale: decimalScale, fixedDecimalScale: fixedDecimalScale, getInputRef: ref, onValueChange: ({ floatValue }) => onChange(floatValue), prefix: prefix, thousandSeparator: thousandSeparator, value: value }), invalid && !!errorMessage ? (_jsx("p", { className: twMerge("text-sm text-red-900", errorMessageClassName), role: "alert", children: errorMessage })) : null] })), rules: rules }));
}
//# sourceMappingURL=number-input.js.map