import ConfigProvider from '../config-provider';
import React, { Component } from 'react';
import cls from 'classnames';
import { Switch as NextSwitch } from '@alifd/next';
import { SwitchProps as NextSwitchProps } from '@alifd/next/types/switch';
import { omitProps } from '../utils/object';

interface SwitchProps extends Omit<NextSwitchProps, 'size'> {
  size?: 'xs' | 'small' | 'medium';
}

class Switch extends Component<SwitchProps> {

  render() {
    const { prefix = 'next-', className, size, ...otherProps } = this.props;
    if (size === 'xs') {
      return (
        <NextSwitch
          {...omitProps(otherProps, [ 'size' ])}
          prefix={prefix}
          className={cls(
            className, {
              [`${prefix}xs`]: size === 'xs',
            },
          )}
        />
      );
    }
    return (
      <NextSwitch
        {...this.props}
        size={size as 'medium' | 'small'}
        prefix={prefix}
        className={cls(
          className, {
          },
        )}
      />
    );
  }
}
export default ConfigProvider.config(Switch);
