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

import { type FormDatePickerProps } from './types';
import DatePicker from '.';

const FormDatePicker = ({ name, inputProps, rules }: FormDatePickerProps) => {
  return (
    <Controller
      render={({ field: { ref, onBlur, ...field }, fieldState: { error } }) => (
        <DatePicker
          {...field}
          {...inputProps}
          inputRef={ref}
          error={!!error}
          errorText={error?.message}
        />
      )}
      name={name}
      rules={rules}
    />
  );
};

export type { FormDatePickerProps };

export default FormDatePicker;
