import ConfigProvider from '../config-provider';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import cls from 'classnames';
import { CommonThemeProps } from '../types';
import { CascaderSelect as NextCascaderSelect } from '@alifd/next';
import { CascaderSelectProps as NextCascaderSelectProps } from '@alifd/next/types/cascader-select';
import { SelectProps as NextSelectProps } from '@alifd/next/types/select';
import { getTheme } from '../utils/getTheme';
import { omitProps } from '../utils/object';


interface CascaderSelectProps extends Omit<NextCascaderSelectProps, 'size'>, CommonThemeProps, Pick<NextSelectProps, 'name'>{
  size?: 'large' | 'medium' | 'small' | 'xs';
}
class CascaderSelect extends Component<CascaderSelectProps> {

  // contextTypes
  static contextTypes = {
    theme: PropTypes.string,
  };

  render() {
    const { prefix = 'next-', popupClassName, className, size, ...otherProps } = this.props;

    const theme = getTheme(this.context, this.props);

    if (size === 'xs') {
      return (
        <NextCascaderSelect
          {...omitProps(otherProps, [ 'size' ])}
          // @ts-ignore
          adjustTagSize
          className={cls(className, {
            [`${prefix}grey`]: theme === 'grey',
            [`${prefix}xs`]: size === 'xs',
            [`${prefix}white`]: theme === 'white',

          })}
          popupClassName={
            cls(popupClassName, {
              [`${prefix}grey`]: theme === 'grey',
              [`${prefix}white`]: theme === 'white',
            })
          }
        />
      );
    }
    return (

      <NextCascaderSelect
        {...otherProps}
        // @ts-ignore
        adjustTagSize
        prefix={prefix}
        size={size}
        className={cls(className, {
          [`${prefix}grey`]: theme === 'grey',
          [`${prefix}white`]: theme === 'white',

        })}
        popupClassName={
          cls(popupClassName, {
            [`${prefix}grey`]: theme === 'grey',
            [`${prefix}white`]: theme === 'white',
          })
        }
      />
    );
  }
}

export default ConfigProvider.config(CascaderSelect);
