// Common SweetAlert functions
const Toast = Swal.mixin({
    toast: true,
    position: 'center',
    showConfirmButton: false,
    timer: 3000,
    timerProgressBar: true
});

// Success message
function showSuccess(message) {
    Toast.fire({
        icon: 'success',
        title: message
    });
}

// Error message
function showError(message) {
    Toast.fire({
        icon: 'error',
        title: message
    });
}

// Warning message
function showWarning(message) {
    Toast.fire({
        icon: 'warning',
        title: message
    });
}

// Info message
function showInfo(message) {
    Toast.fire({
        icon: 'info',
        title: message
    });
}

// Confirmation dialog
function confirmDelete(message = 'Are you sure you want to delete this item?') {
    return Swal.fire({
        title: 'Are you sure?',
        text: message,
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes, delete it!'
    });
}

// Success with redirect
function showSuccessAndRedirect(message, redirectUrl) {
    Swal.fire({
        icon: 'success',
        title: 'Success!',
        text: message,
        showConfirmButton: false,
        timer: 1500
    }).then(() => {
        window.location.href = redirectUrl;
    });
}

// Error with redirect
function showErrorAndRedirect(message, redirectUrl) {
    Swal.fire({
        icon: 'error',
        title: 'Error!',
        text: message,
        showConfirmButton: false,
        timer: 1500
    }).then(() => {
        window.location.href = redirectUrl;
    });
}
