import { BaseSelectProps } from '@mui/material'
import { Controller } from 'react-hook-form'
import ExamGroupSelector from '../ExamGroupSelector'

type ExamGroupSelectorProps = {
  control: any
  name: string
  label: string
  required?: boolean
  multiple?: boolean
  allowAll?: boolean
  filters?: { courseId: number; examType: string }
  onChange?: (value: any) => void
} & BaseSelectProps
export default function FormExamGroupSelector(props: ExamGroupSelectorProps) {
  const {
    name,
    required = false,
    control,
    label,
    multiple = false,
    allowAll = true,
    onChange,
    value,
    filters,
  } = props

  return (
    <Controller
      name={name}
      control={control}
      render={({ field, fieldState: { error } }) => (
        <ExamGroupSelector
          label={label}
          name={name}
          onChange={onChange ?? field.onChange}
          value={value ?? field?.value}
          allowAll={allowAll}
          filters={filters}
          required={required}
          error={!!error}
          helperText={error?.message}
          {...props}
        />
      )}
    />
  )
}
