import ConfigProvider from '../config-provider';
import React, { Component } from 'react';
import hoistNonReactStatics from 'hoist-non-react-statics';
import { SplitButton as NextSplitButton } from '@alifd/next';
import { SplitButtonProps as NextSplitButtonProps } from '@alifd/next/types/split-button';

interface SplitButtonProps extends Omit<NextSplitButtonProps, 'size'> {
  size?: 'large' | 'medium' | 'small' | 'xs';
}

class SplitButton extends Component<SplitButtonProps> {
  static Item = NextSplitButton.Item;
  static Divider = NextSplitButton.Divider;
  static Group = NextSplitButton.Group;

  render() {
    const { size = 'medium', ...otherProps } = this.props;
    let { type } = this.props;

    // @不喜：连在一起效果不好
    if (type === 'primary') {
      type = 'secondary';
    }

    return (
      <NextSplitButton
        {...otherProps}
        size={size as 'large' | 'medium' | 'small'}
        type={type}
      />
    );
  }
}

hoistNonReactStatics(SplitButton, NextSplitButton);

export default ConfigProvider.config(SplitButton);
