import Swal from "sweetalert2";
import type { SweetAlertIcon } from "sweetalert2";
function showAlert({
  t,
  title,
  text = "",
  confirmBtnText,
  showCancelButton = true,
  imageUrl,
  type = "warning",
  action,
}: {
  t: any;
  title: string;
  text?: string;
  confirmBtnText?: string;
  showCancelButton?: boolean;
  imageUrl?: string;
  type?: SweetAlertIcon;
  action?: any;
}): Promise<string | null> {
  return new Promise((resolve) => {
    Swal.fire({
      title: title,
      text: text,
      icon: type,
      showCancelButton: showCancelButton,
      showCloseButton: true, // Show close button
      imageUrl: imageUrl,
      confirmButtonText: confirmBtnText || t("BUTTONS.confirm"),
      cancelButtonText: t("BUTTONS.noKeepMe"),
      customClass: {
        popup: "custom-popup-class",
        title: "custom-title-class",
      },
      padding: "1rem",
    }).then((result) => {
      if (result.isConfirmed) {
        if (action) action(); // ✅ Execute action if confirmed
        resolve("confirmed"); // ✅ No value to return, resolve with "confirmed"
      } else {
        resolve(null); // ✅ Cancelled case
      }
    });
  });
}

export default showAlert;
