'use client'

import Swal from 'sweetalert2'

type ShowConfirmAlertProps = {
  title?: string
  text?: string
  confirmButtonText?: string
  denyButtonText?: string
  cancelButtonText?: string
  showDenyButton?: boolean
  showCancelButton?: boolean
  icon?: 'success' | 'error' | 'warning' | 'info' | 'question'
  onConfirm?: () => void
  onDeny?: () => void
  onCancel?: () => void
}

export const SweetAlertCustom = async ({
  title = 'هل أنت متأكد؟',
  text = '',
  confirmButtonText = 'تأكيد',
  denyButtonText = 'رفض',
  cancelButtonText = 'إلغاء',
  showDenyButton = true,
  showCancelButton = true,
  icon = 'question',
  onConfirm,
  onDeny,
  onCancel
}: ShowConfirmAlertProps): Promise<{ isConfirmed: boolean; isDismissed: boolean }> => {
  const result = await Swal.fire({
    title,
    text,
    icon,
    showDenyButton,
    showCancelButton,
    confirmButtonText,
    denyButtonText,
    cancelButtonText
  })

  return {
    isConfirmed: result.isConfirmed,
    isDismissed: result.isDismissed || false
  }
}
