import { ErrorMessage as RHFErrorMessage } from '@hookform/error-message'

import { Error } from './Error'

import type { ErrorMessageProps } from './errorMessage'

export function ErrorMessage<T>({
  errors,
  name,
  messageLabel,
}: ErrorMessageProps<T>) {
  return (
    <RHFErrorMessage
      errors={errors}
      name={name}
      render={({ message }) => <Error>{messageLabel ?? message}</Error>}
    />
  )
}
