import { useQuasar } from 'quasar';
import AppNotificationDialog from 'src/components/dialogs/AppNotificationDialog.vue';

export function useRequestConfirmation() {
  const { dialog, screen } = useQuasar();
  const cancelButton = (label = 'Descartar', onCancel?: () => void) => ({
    label,
    fn: onCancel || (() => {}),
  });

  function requestConfirmation(data: { title?: string; message: string; action: () => void; onCancel?: () => void } = { title: 'Confirmación', message: '', action: () => {} }) {
    const { title, message, action, onCancel } = data;
    dialog({
      component: AppNotificationDialog,
      componentProps: {
        data: {
          title,
          message,
          actions: [
            cancelButton(undefined, onCancel),
            {
              label: 'Confirmar',
              fn: action,
            },
          ][screen.lt.md ? 'reverse' : 'slice'](),
        },
      },
    });
  }

  return { requestConfirmation };
}
