
// --------------------------
// User Login
// --------------------------

// password toggle
function passwordViewToggle(){
    var passwordInput = $('#id_password')[0];
    if (passwordInput.type == 'text'){
        passwordInput.type = 'password'
        $('.p-t-st').removeClass('bi-eye'); $('.p-t-st').addClass('bi-eye-slash'); 
    }
    else{
        passwordInput.type = 'text';
        $('.p-t-st').removeClass('bi-eye-slash'); $('.p-t-st').addClass('bi-eye');
    }
}

$(document).ready(function(){
    $('#loginForm').on('submit', function(e){
        e.preventDefault();
        sBtn = $('#loginForm').find('button')[0];
        $(sBtn).hide();
        $('.lpb').show();
        setTimeout(()=>{
            loginUser()
        }, 1500)
    });
})


// set timer to resend Code
function setTimer(){
    setInterval(()=>{
        $('.gc-txt').html('Resend in ' + period+'s');
        $('.gc-txt').attr('onclick', '');
        if (period < 1){
            $('.gc-txt').html('Resend Code');
            $('.gc-txt').attr('onclick', 'getLoginVerificationCode()');
            $('.gc-txt').removeClass('grey-color-3');
            $('.gc-txt').addClass('primary-color');
            clearInterval(setTimer);
        }
        period -= 1;
    }, 1000)
}

// Toggle Trust Device
function trustDevice(e){
    if (e.classList.contains('checked')){
      $(e).removeClass('fa-check-square primary-color checked');
      $(e).addClass('fa-square-o black-text');
      $('#trustDeviceInp').val('false');
    }
    else{
      $(e).removeClass('fa-square-o black-text');
      $(e).addClass('fa-check-square primary-color checked');
      $('#trustDeviceInp').val('true');
    }
}

// ------/
$('#code-input').on('input', ()=>{$('.lc-err-msg').hide()})
// ------/

