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

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

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

const DatePicker = ({
  sx = {},
  label,
  value,
  helperText,
  errorText,
  onChange,
  inputRef,
  error,
  fullWidth = true,
  disabled = false,
  enableClear = false,
  size = 'medium',
  slotProps,
  ...props
}: DatePickerProps) => {
  return (
    <FormControl
      sx={sx}
      error={error}
      fullWidth={fullWidth}
      disabled={disabled}
    >
      <CustomLabel label={label} />
      <CustomDatePicker
        size={size}
        value={value}
        onChange={onChange}
        inputRef={inputRef}
        disabled={disabled}
        error={error}
        enableClear={enableClear}
        slotProps={slotProps}
        {...props}
      />
      {size !== 'small' && (
        <CustomHelperText helperText={error ? errorText : helperText} />
      )}
    </FormControl>
  );
};

export type { DatePickerProps };

export default DatePicker;
