import { ElMessageBox, ElMessage } from 'element-plus'

/**
 * 删除确认弹窗
 * @param name 要删除的名称
 * @param onConfirm 确认回调
 */
export const confirmDelete = (name: string, onConfirm: () => void | Promise<void>) => {
  ElMessageBox.confirm(`确定要删除"${name}"吗？`, '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(async () => {
    await onConfirm()
    ElMessage.success('删除成功')
  }).catch(() => {})
}

/**
 * 批量删除确认弹窗
 * @param count 要删除的数量
 * @param onConfirm 确认回调
 */
export const confirmBatchDelete = (count: number, onConfirm: () => void | Promise<void>) => {
  ElMessageBox.confirm(`确定要删除选中的 ${count} 条数据吗？`, '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(async () => {
    await onConfirm()
    ElMessage.success('删除成功')
  }).catch(() => {})
}

/**
 * 通用确认弹窗
 * @param message 提示信息
 * @param onConfirm 确认回调
 * @param title 标题
 */
export const confirm = (
  message: string, 
  onConfirm: () => void | Promise<void>,
  title = '提示'
) => {
  ElMessageBox.confirm(message, title, {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(async () => {
    await onConfirm()
  }).catch(() => {})
}
