import React from 'react';
import { Modal, Button, message } from 'antd';

export default function ModalButton(props) {
  const {
    method = 'confirm',
    title = '',
    content = '',
    modalConfigs = {},
    onClick,
    onCancel,
    // 未选数据弹出提示
    beforeCheck = '',
    okText = '确认',
    cancelText = '取消',
    ...btnProps
  } = props || {}

  const handleClick = e => {
    if (!!beforeCheck) { message.info(beforeCheck); return }
    Modal[method]({
      title,
      content,
      okText,
      cancelText,
      ...modalConfigs,
      onOk() {
        // eslint-disable-next-line no-unused-expressions
        onClick && onClick(e);
      },
      onCancel() {
        // eslint-disable-next-line no-unused-expressions
        onCancel && onCancel();
      },
    })
  }

  return <Button {...btnProps} onClick={handleClick}>{props.children}</Button>
}
