$('#LoginForm').submit(function (e) {
    e.preventDefault();

    let formData = new FormData(this);
    formData.append('action', 'login');

    $.ajax({
        url: "database/model/usuarios.php",
        type: "POST",
        data: formData,
        processData: false,
        contentType: false,
        success: function (response) {
            try {
                let result = JSON.parse(response);
                Swal.fire({
                    icon: result.status,
                    title: result.message,
                    showConfirmButton: false,
                    timer: 1500
                }).then(() => {
                    if (result.status == 'success') {
                        setTimeout(() => {
                            window.location.href = 'dashboard.php';
                        }, 1500);
                    }
                });
            } catch (error) {
                console.log(error);
            }
        },
        error: function (error) {
            console.log(error);
            Swal.fire({
                icon: 'error',
                title: 'Error al iniciar sesión',
                showConfirmButton: false,
                timer: 1500
            });
        }
    });
});
