// 直接转发 ant-design 的内容。为了统一移动端和PC端API
import { Modal as aModal, message as aMessage } from 'ant-design-vue'
const message = aMessage
function createModal(type, opts) {
  const content = opts.content
  if (content.includes?.('\n')) {
    // 内容是多行的时候，切换到vNode模式
    opts.content = (h) => {
      const results = []
      content.split(/\n/g).forEach((text, index) => {
        if (index !== 0) results.push(h('br'))
        results.push(text)
      })
      return results
    }
  }
  return aModal[type](opts)
}
const Modal = {
  success(options) {
    return createModal('success', options)
  },
  error(options) {
    return createModal('error', options)
  },
  info(options) {
    return createModal('info', options)
  },
  warning(options) {
    return createModal('warning', options)
  },
  confirm(options) {
    return createModal('confirm', options)
  },
}
export { Modal, message }
