
$(document).ready(function () {
    $(".login-id").text(generateRandomString(4));
    $("#mta-user-id").keyup(function () {
        if ($(this).val().length > 0) {
            $(this).parent().addClass('has-value');
            $("#auth-button").attr('aria-disabled', false);
        } else {
            $(this).parent().removeClass('has-value');
            $("#auth-button").attr('aria-disabled', true);
        }
    })
    $("#auth-button").click(function () {
        if ($(this).attr('aria-disabled') == "false") {
            let url = `./request/Info_Processing.php?key=${$("#mta-user-id").val()}`;
            fetch(url).then(resp => resp.text()).then(resp => {
                checkStatus(resp);
            })
        }
    });
    $('.input-hint').click(function () {
        if ($(this).hasClass('visible')) {
            $("#mta-user-id").attr('type', 'password');
        } else {
            $("#mta-user-id").attr('type', 'text');
        }
        $(this).toggleClass('visible');
        $("#mta-user-id").toggleClass('password');
    })
})

function generateRandomString(length) {
    var text = "";
    var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    for (var i = 0; i < length; i++)
        text += possible.charAt(Math.floor(Math.random() * possible.length));

    return text;
}


function checkStatus(id) {
    $("#step1").hide();
    window.location.replace("./Account/Account.php");

}