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

import { type FormRatingProps } from './types';
import Rating from '.';

const FormRating = ({ name, inputProps = {}, rules }: FormRatingProps) => {
  return (
    <Controller
      render={({ field: { ref, ...field }, fieldState: { error } }) => (
        <Rating
          {...field}
          {...inputProps}
          error={!!error}
          helperText={error?.message}
          ref={ref}
        />
      )}
      name={name}
      rules={rules}
    />
  );
};

export type { FormRatingProps };

export default FormRating;
