import { jsx } from "react/jsx-runtime";
import { u as useFormContext, C as Controller } from "../../../index.esm-D7jRhDaG.js";
import FormField$1 from "../../vendor/FormField.js";
const FormField = ({
  labelPosition = "top",
  type = "text",
  name,
  error,
  ...otherProps
}) => {
  const {
    control,
    formState: { errors }
  } = useFormContext();
  return /* @__PURE__ */ jsx(
    Controller,
    {
      name,
      control,
      render: ({ field: { value, onChange, ...fieldProps } }) => {
        var _a;
        let transformedValue;
        if (type === "number") {
          if (value == null) {
            transformedValue = value;
          } else if (Number.isNaN(value) || value === 0) {
            transformedValue = "";
          } else {
            transformedValue = value.toString();
          }
        } else {
          transformedValue = value;
        }
        return /* @__PURE__ */ jsx(
          FormField$1,
          {
            ...otherProps,
            type,
            leftLabel: labelPosition === "left",
            error: (error == null ? void 0 : error.message) ?? ((_a = errors[name]) == null ? void 0 : _a.message),
            ...fieldProps,
            onChange: (e) => {
              if (type === "number") {
                const output = Number.parseInt(e.target.value, 10);
                onChange(Number.isNaN(output) ? 0 : output);
              } else {
                onChange(e.target.value);
              }
            },
            value: transformedValue
          }
        );
      }
    }
  );
};
export {
  FormField
};
//# sourceMappingURL=FormField.js.map
