$('.login_button').click(async function (e) {
    e.preventDefault();
    let form = $('.login_form'),
        data = new FormData(form[0]),
        url = form.attr('action'),
        method = form.attr('method');

    const response=await ajax({
        url,
        data,
        dataType: 'json',
        method,
        contentType: false,
        processData: false,
    });

    if (response.errors) {
        toasterError(response.errors);
    }
    if (response.url) {
        window.location.reload();
    }
});

$('.comment_button').click(async function (e) {
    e.preventDefault();
    let data = new FormData(),
        url = productEvaluateRoute,
        method = 'post';

    data.append('evaluate', $('.comment_form input[name="evaluate"]:checked').val());
    data.append('comment', $('.comment_form textarea[name="comment"]').val());
    data.append('product_id', product_id);

    const response=await ajax({
        url,
        data,
        dataType: 'json',
        method,
        contentType: false,
        processData: false,
    });

    if (response.errors) {
        toasterError(response.errors);
    }
    if (response.message) {
        $('.reviewModal').modal('hide');
        toasterSuccess(response.message);
        setTimeout(function () {
            window.location.reload();
        }, 200);
    }
});

$(".qt-plus").click(function() {
    $(this).parent().children(".qt").html(parseInt($(this).parent().children(".qt").html()) + 1);
});

$(".qt-minus").click(function() {

    child = $(this).parent().children(".qt");

    if (parseInt(child.html()) > 1) {
        child.html(parseInt(child.html()) - 1);
    }

    $(this).parent().children(".full-price").addClass("minused");

});


$('#togglePassword').click(function () {
    let password = $('#password'),
        type = password.attr('type') === 'password' ? 'text' : 'password';
    password.attr('type', type);
    $(this).toggleClass('fa-eye-slash');
});

