var isLoggedIn = false;

function updateLoginButtonVisibility() {
    if (isLoggedIn) {
        $("#loginButton").hide();
        $("#dropdownMenuButton1").show();
    } else {
        $("#loginButton").show();
        $("#dropdownMenuButton1").hide();
    }
}

$(document).ready(function() {
    console.log("button hide");
updateLoginButtonVisibility();  
});

$("#loginForm").on('submit', function (e) {
    e.preventDefault();

    var data = {
        email_mobile: $('#username').val(),
        password: $('#password').val(),
    };

    console.log("Data before AJAX request:", JSON.stringify(data));
    $.ajax({
        type: "post",
        url: "/user-login",
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        data: JSON.stringify(data),
        success: function (response) {
            alert('login Successfully');
            console.log(response);
            isLoggedIn = true;
            updateLoginButtonVisibility();
            $("#login").modal("hide");
        },
        error: function (response) {
            alert('Invalid Credentials ' + response.responseJSON.error);
            console.log("error");
        },
    });
});







