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

import { type FormRangePickerProps } from './types';
import RangeDatePicker from '.';

const FormRangeDatePicker = ({
  name,
  inputProps,
  rules,
}: FormRangePickerProps) => {
  return (
    <Controller
      render={({ field: { ref, onBlur, ...field }, fieldState: { error } }) => (
        <RangeDatePicker
          value={field.value || [null, null]}
          onChange={field.onChange}
          {...inputProps}
          error={!!error}
          errorText={error?.message}
        />
      )}
      name={name}
      rules={rules}
    />
  );
};

export type { FormRangePickerProps };

export default FormRangeDatePicker;
