import { alertController } from "@ionic/vue";

interface ConfirmationDialogOptions {
  header?: string;
  message: string;
  confirmText?: string;
  cancelText?: string;
  confirmColor?: string;
  cancelColor?: string;
}

export const useConfirmationDialog = () => {
  const confirm = async ({
    header = "Confirmation",
    message,
    confirmText = "Oui",
    cancelText = "Non",
    confirmColor = "primary",
    cancelColor = "medium",
  }: ConfirmationDialogOptions): Promise<boolean> => {
    const alert = await alertController.create({
      header,
      message,
      buttons: [
        {
          text: cancelText,
          role: "cancel",
          cssClass: `!text-secondary`,
        },
        {
          text: confirmText,
          role: "confirm",
          cssClass: `!text-secondary`,
        },
      ],
    });

    await alert.present();
    const result = await alert.onDidDismiss();
    return result.role === "confirm";
  };

  return {
    confirm,
  };
};
