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

import { type FormInputSelectProps } from './types';
import InputSelect from '.';

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

export type { FormInputSelectProps };

export default FormInputSelect;
