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

import { type FormInputTimeProps } from './types';
import InputTime from '.';

const FormInputTime = ({ name, inputProps, rules }: FormInputTimeProps) => {
  return (
    <Controller
      name={name}
      rules={rules}
      render={({ field: { ref, ...field }, fieldState: { error } }) => (
        <InputTime
          {...field}
          {...inputProps}
          inputRef={ref}
          error={inputProps.error || !!error}
          errorText={
            inputProps.hideErrorText
              ? ''
              : error?.message || inputProps.errorText
          }
        />
      )}
    />
  );
};

export default FormInputTime;
