import { Message, Notification } from 'element-ui'
import language from '@/lang'
import router from '@/router'
export function hasTranslation(text) {
const hasKey = language.te('notifications.' + text)
if (hasKey) {
const translatedText = language.t('notifications.' + text)
return translatedText
}
return text
}
/**
*
* @param {string} type, required
* @param {string} title, required
* @param {object} message
* @param {string} summary
* @param {string} name
* @param {array} logs
*/
export function showNotification({ type, title, message, summary, name, logs = [] }) {
title = hasTranslation(title)
if (message) {
message = hasTranslation(message)
}
// For summary
if (summary) {
if (message) {
message = `${message}
${summary}`
} else {
message = summary
}
}
// For logs
if (logs && logs.length) {
logs.forEach(logResult => {
if (logResult) {
message = `${message}
${logResult.log}`
}
})
}
if (name) {
message = name + message
}
return Notification({
title,
message: `