import { AtButton } from 'taro-ui';
import Taro, { FC } from '@tarojs/taro';
import { ButtonProps } from '../../../@types/button';

const ButtonTypes = ['error', 'warning'];
const isButtonType = (x: any) => ButtonTypes.includes(x);

const Button: FC<ButtonProps> = props => {
  const { className, loading, customtype = '' } = props;

  let cn = className;

  if (customtype && isButtonType(customtype)) {
    cn = className ? `${className} ${customtype}` : `${customtype}`;
  }
  //  拦截按钮单击事件，遇到异步方法传入并触发事件时自动进入loading状态

  return (
    <AtButton {...props} loading={loading} onClick={props.onClick} className={cn}>
      {props.children}
    </AtButton>
  );
};

export default Button;
