import { CheckboxProps } from '@mui/material'
import { ReactNode } from 'react'
import { Controller } from 'react-hook-form'
import { SingleCheckbox } from '../Input'

interface Props extends CheckboxProps {
  label?: ReactNode
  name: string
  control: any
}

export default function FormSingleCheckbox({
  name,
  control,
  label,
  onChange,
  checked,
  ...rest
}: Props) {
  return (
    <Controller
      name={name}
      control={control}
      render={({ field, fieldState: { error } }) => (
        <SingleCheckbox
          checked={checked ?? field.value}
          onChange={onChange ?? field.onChange}
          label={label}
          {...rest}
        />
      )}
    />
  )
}
