const hamburger = document.querySelector('#toggle-btn');

hamburger.addEventListener('click', function () {
    document.querySelector('#sidebar').classList.toggle('expand');
});

document.getElementById('logoutLink').addEventListener('click', function (event) {
    event.preventDefault();

    $.ajax({
        url: 'database/model/usuarios.php',
        type: 'POST',
        data: { action: 'logout' },
        success: function (response) {
            let result = JSON.parse(response);
            if (result.status === 'success') {
                Swal.fire({
                    icon: 'success',
                    title: result.message,
                    showConfirmButton: false,
                    timer: 1500
                }).then(() => {
                    window.location.href = 'index.php';
                });
            } else {
                Swal.fire({
                    icon: 'error',
                    title: 'Error',
                    text: result.message
                });
            }
        },
        error: function (xhr, status, error) {
            console.error("AJAX error:", status, error);
            Swal.fire({
                icon: 'error',
                title: 'Error',
                text: 'An error occurred while trying to log out'
            });
        }
    });
});