import Vue from 'vue';
import { MessageBox, Notification, Message } from 'element-ui';
import { i18n } from '@/utils/i18ns'
import vxeTable from 'vxe-table';

export default {
  success: (msg, config = { duration: 3000 }, callback = Function) => {
    config = Object.assign({ message: msg }, {
      iconStatus: 'fa fa-check-circle',
      duration: 3000,
      status: 'success',
      id: 'unique1'
    }, config);
    vxeTable.modal.message(config).then(() => {
      if (callback) callback();
    });
  },
  info: (msg, config = { duration: 3000 }, callback = Function) => {
    config = Object.assign({ message: msg }, {
      iconStatus: 'fa fa-info-circle',
      duration: 3000,
      status: 'info',
      id: 'unique1'
    }, config);
    vxeTable.modal.message(config).then(() => {
      if (callback) callback();
    });
  },
  warning: (msg, config = { duration: 3000 }, callback = Function) => {
    config = Object.assign({ message: msg }, {
      iconStatus: 'fa fa-warning',
      duration: 3000,
      status: 'warning',
      id: 'unique1'
    }, config);
    vxeTable.modal.message(config).then(() => {
      if (callback) callback();
    });
  },
  error: (msg, config = { duration: 3000 }, callback = Function) => {
    config = Object.assign({ message: msg }, {
      iconStatus: 'fa fa-times',
      duration: 3000,
      status: 'error',
      id: 'unique1'
    }, config);
    vxeTable.modal.message(config).then(() => {
      if (callback) callback();
    });
  },
  confirm: (msg, callback) => {
    const title = i18n.tc("common.button.tip.title");
    MessageBox.confirm(msg, title, {
      closeOnPressEscape: false,
      closeOnClickModal: false,
      showClose: false,
      confirmButtonText: i18n.t('common.button.sureBtn'),
      cancelButtonText: i18n.t('common.button.cancel'),
      type: 'warning'
    }).then(() => {
      if (callback) {
        callback();
      }
    })
  },
  alert: function (message, callback) {
    const msg = i18n.t('common.tipMessage.title')
    MessageBox.alert(message, msg, {
      confirmButtonText: i18n.t('common.button.sureBtn'),
      closeOnPressEscape: false,
      closeOnClickModal: false,
      showClose: false,
      iconClass: 'el-icon-info',
      callback: (action) => {
        if (callback) {
          callback(action)
        }
      }
    }).then(() => {
      alert('1')
    })
  },
  notify: function (options) {
    const defaultConfig = {
      title: 'HTML 片段',
      type: 'info',
      iconClass: 'el-icon-info',
      position: 'top-right', // top-right/top-left/bottom-right/bottom-left
      dangerouslyUseHTMLString: true,
      message: '<strong>这是 <i>HTML</i> 片段</strong>'
    }
    const config = Object.assign({}, defaultConfig, options)
    Notification.info(config)
  }
}
