
$(document).ready(function () {
    let passwordVisibilityIcon = $('span#password-visibility');
    let passwordField = $('input#password');

    mp.trigger('CEF:Login_RequestPlayerName');

    passwordVisibilityIcon.mouseenter(togglePasswordVisibility);
    passwordVisibilityIcon.mouseleave(togglePasswordVisibility);

    function togglePasswordVisibility() {
        if (passwordVisibilityIcon.hasClass('hidden')) {
            passwordVisibilityIcon.removeClass('hidden');
            passwordField.attr("type", "text");
        } else {
            passwordVisibilityIcon.addClass('hidden');
            passwordField.attr("type", "password");
        }
    }

    $('form.login').submit(function (e) {
        e.preventDefault();
        mp.trigger("CEF:Login_LoginRequest", passwordField.val())
    });

    $('form.register').submit(function (e) {
        e.preventDefault();
        mp.trigger("CEF:Login_RegisterRequest", passwordField.val())
    });
});

function setPlayerName(name) {
    $('span#name').html(name);
}

function showError(error) {
    var errorText = $("#alert");
    errorText.removeClass("hidden");
    errorText.text(error);
}

function disableLightMode() {
    $("body").removeClass("light");
}