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

type FacultySelectorProps = {
  control: any
  name: string
  label: string
  required?: boolean
  multiple?: boolean
  allowAll?: boolean
  filters?: {
    departmentId: number | string
    isSearch: boolean
    isActive: boolean
    type: string
  }
  onChange?: (value: any) => void
  api?: string
} & BaseSelectProps
export default function FormFacultySelector(props: FacultySelectorProps) {
  const {
    name,
    required = false,
    control,
    label,
    multiple = false,
    allowAll = true,
    onChange,
    value,
    filters,
    api,
  } = props

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