import {LANGUAGE_ENGLISH, LANGUAGE_LOCALSTORAGE} from "./constantCollection";

var InfoTip = {

  //成功提示
  successTip: function(vue, success, addition) {
    var additionString = (typeof addition == "undefined")?'':addition;
    var language = window.localStorage.getItem(LANGUAGE_LOCALSTORAGE);
    if(language === LANGUAGE_ENGLISH){
      additionString += " ";
    }
    vue.$message({
      type: 'success',
      message: additionString + success.message,
      duration: 10000,
      showClose: true,
    })
  },

  //错误提示
  errorTip: function(vue, error) {
    vue.$alert(error.code+':'+error.message, vue.$t('common.tip'), {
      confirmButtonText: vue.$t('common.ok'),
      type: 'error'
    })
  },

  //警告提示
  warningTip:function (vue, warn, addition) {
    var additionString = (typeof addition == "undefined")?'':addition;
    var language = window.localStorage.getItem(LANGUAGE_LOCALSTORAGE);
    if(language === LANGUAGE_ENGLISH){
      additionString += " ";
    }
    vue.$alert(additionString + warn.message, vue.$t('common.tip'), {
      confirmButtonText: vue.$t('common.ok'),
      type: 'warning',
      callback: action => {
        document.querySelector('input').focus()
      }
    })
  },

  //警告提示
  warningTip_login:function (vue, warn, addition) {
    var additionString = (typeof addition == "undefined")?'':addition;
    var language = window.localStorage.getItem(LANGUAGE_LOCALSTORAGE);
    if(language === LANGUAGE_ENGLISH){
      additionString += " ";
    }
    vue.$alert(additionString + warn.message, vue.$t('common.tip'), {
      confirmButtonText: vue.$t('common.ok'),
      type: 'warning',
      callback: action => {
        document.querySelector('button').focus()
      }
    })
  },

  //警告提示
  warningTip_alarm:function (vue, warn, addition) {
    var additionString = (typeof addition == "undefined")?'':addition;
    var language = window.localStorage.getItem(LANGUAGE_LOCALSTORAGE);
    if(language === LANGUAGE_ENGLISH){
      additionString += " ";
    }
    vue.$alert(additionString + warn.message, vue.$t('common.tip'), {
      confirmButtonText: vue.$t('common.ok'),
      type: 'warning',
    })
  },

  //删除确认提示
  conformTip:function (vue, deleteWarn){
    return vue.$confirm(deleteWarn.message, vue.$t('common.tip'), {
      confirmButtonText: vue.$t('common.ok'),
      cancelButtonText: vue.$t('common.cancel'),
      type: 'warning'
    })
  },

  // 消息提示
  messageTip:function (vue, message, callback = ()=>{},addition) {
    var additionString = (typeof addition == "undefined")?'':addition;
    var language = window.localStorage.getItem(LANGUAGE_LOCALSTORAGE);
    if(language === LANGUAGE_ENGLISH){
      additionString += " ";
    }
    vue.$alert(additionString + message.message, vue.$t('common.tip'), {
      confirmButtonText: vue.$t('common.ok'),
      type: 'info',
      callback: () => {
        callback();
      }
    })
  },
}

export default InfoTip
