import { ElMessage,ElMessageBox } from "element-plus"
export function showMessage(option) {
    ElMessage({
        ...option
    })
}
export {
    ElMessageBox as MyElMessageBox
}

export function elAlert(content,name='系统提示') {
    ElMessageBox.alert(content,name,{
        type:"warning",
        confirmButtonText: "确定",
    })
}
export function showConfirm(delFun,...params) {
    ElMessageBox.confirm(...params)
        .then(() => {
            delFun && delFun()
            // showMessage({
            //   type: 'success',
            //   message: '删除成功!'
            //  });
        })
        .catch(() => {
            showMessage({
                type: "info",
                message: "已取消"
            })
        })
}

export function handleMes(
    res,
    successFun,
    failCallback,
    successMessage,
    failMessage
) {
    let isTrue = Boolean(res.msg[0].success + "" === 'true')

    showMessage({
        message: isTrue
            ? successMessage || res.msg[0].error  || res.message
            : failMessage || res.msg[0].error || res.message,
        type: isTrue ? "success" : "error"
    })
    isTrue && successFun && successFun()
    !isTrue && failCallback && failCallback()
}