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

import { type FormTimePickerProps } from './types';
import TimePicker from '.';

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

export default FormTimePicker;
