/**
 * @author 挽枫
 * @description 按钮主题色封装、封装的不好不要吐槽、EasyV4.17版本需求、后续按钮主题色更改可直接去更改index.less、使用时如果需要使用antd默认样式则不要传入theme参数即可
 *
 */
import { Button } from '@easyv/antd';
import { ButtonProps } from '@easyv/antd/lib/button';
import classNames from 'classnames';
import React, { ReactElement } from 'react';
import styles from './index.less';

export interface EasyButtonProps extends ButtonProps {
  theme?: 'danger' | 'primary' | 'default' | 'ghost';
}

function EasyvButton(props: EasyButtonProps): ReactElement {
  const { theme = 'default', className, type, onClick, ...otherProps } = props;
  const handleClick = (e) => {
    const target = e.currentTarget;
    target.blur();
    onClick && onClick(e);
  };
  return (
    <Button
      onClick={handleClick}
      {...otherProps}
      type={type ? type : undefined}
      className={classNames(styles.easyvButton, className, { [styles[theme!]]: type ? false : true })}>
      {props.children}
    </Button>
  );
}

export default EasyvButton;
