import { FormControl } from '@mui/material';

import CustomHelperText from '../Base/CustomHelperText';
import CustomLabel from '../Base/CustomLabel';
import CustomSelect from '../Base/CustomSelect';

import { type InputSelectProps } from './types';

const InputSelect = ({
  sx = {},
  label,
  value,
  helperText,
  errorText,
  onChange,
  placeholder,
  inputRef,
  error,
  fullWidth = true,
  options,
  disabled,
  allowClear,
  renderOption,
  success,
}: InputSelectProps) => {
  return (
    <FormControl
      sx={sx}
      error={error}
      fullWidth={fullWidth}
      disabled={disabled}
    >
      <CustomLabel label={label} />
      <CustomSelect
        value={value}
        onChange={onChange}
        renderOption={renderOption}
        inputRef={inputRef}
        placeholder={placeholder}
        options={options}
        allowClear={allowClear}
        disabled={disabled}
        success={success}
      />
      <CustomHelperText
        helperText={error ? errorText : helperText}
        value={value}
      />
    </FormControl>
  );
};

export type { InputSelectProps };

export default InputSelect;
