import { h } from 'vue'
import domView from './index.vue'

//删除提醒
export const delMessageV2 = (cbk) => {
    window?.$messageBox({
        center: true,
        message: () => h(domView, {
            type: 'delete',
            title: '确认删除提醒',
            text: '请谨慎考虑后，确认是否需要删除？',
        }),
        customClass: 'hc-message-view-box',
        showCancelButton: true,
        confirmButtonText: '确认删除',
        cancelButtonText: '取消操作',
        beforeClose: (action, instance, done) => {
            if (cbk) {
                cbk(action, instance, done)
            } else {
                done()
            }
        },
    })
}

//请求异常
export const apiErrorMessage = () => {
    setTimeout(() => {
        const doms = document.querySelector('.hc-message-view-box.warning')
        if (doms) return
        window?.$messageBox({
            center: true,
            message: () => h(domView, {
                type: 'warning',
                title: '服务器异常，请稍后重试',
                text: '服务器异常了，如有需要，请联系管理员！',
            }),
            customClass: 'hc-message-view-box warning',
            showCancelButton: false,
            confirmButtonText: '关闭',
        })
    }, 1000)
}

//请求异常
export const apiWarningMessage = () => {
    setTimeout(() => {
        const doms = document.querySelector('.hc-message-view-box.warning')
        if (doms) return
        window?.$messageBox({
            center: true,
            message: () => h(domView, {
                type: 'warning',
                title: '正在升级优化，请稍后重试',
                text: '该功能正在升级优化，请联系管理员',
            }),
            customClass: 'hc-message-view-box warning',
            showCancelButton: false,
            confirmButtonText: '关闭',
        })
    }, 1000)
}
