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

import { type FormCheckboxProps } from './types';
import Checkbox from '.';

const FormCheckbox = ({ name, checkBoxProps, rules }: FormCheckboxProps) => {
  return (
    <Controller
      render={({ field: { value, ref, ...field }, fieldState: { error } }) => (
        <Checkbox
          checked={Boolean(value)}
          {...field}
          {...checkBoxProps}
          inputRef={ref}
          error={!!error}
        />
      )}
      name={name}
      rules={rules}
    />
  );
};

export type { FormCheckboxProps };

export default FormCheckbox;
