import { Controller } from 'react-hook-form';

import { type FormInputOtpProps } from './types';
import InputOtp from '.';

const FormInputOtp = ({ name, rules, inputOtpProps }: FormInputOtpProps) => {
  return (
    <Controller
      render={({
        fieldState: { error, invalid },
        field: { ref: _ref, ...fieldMethods },
      }) => (
        <InputOtp
          {...fieldMethods}
          {...inputOtpProps}
          error={invalid}
          helperText={error?.message}
        />
      )}
      name={name}
      rules={rules}
    />
  );
};

export type { FormInputOtpProps };

export default FormInputOtp;
