$(document).ready(function() {

    $('.contact_us_button').click(async function (e) {
        e.preventDefault();

        let interval = setInterval(function () {
            $('.ajaxError, .ajaxSuccess').slideUp(400);
            clearInterval(interval)
        }, 3000);

        let form = $('.contact_us_form'),
            data = new FormData(form[0]),
            url = form.attr('action'),
            method = form.attr('method');

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

        if (response.errors) {
            $('.ajaxError').removeClass('d-none').slideDown().html(response.errors);
            $('.ajaxSuccess').addClass('d-none');
        }
        if (response.message) {
            $('.ajaxSuccess').removeClass('d-none').slideDown().html(response.message);
            $('.ajaxError').addClass('d-none');
            $('.contact_us_form input, textarea').val('')
        }
    });
    $('.newsletter_button').click(async function (e) {
        e.preventDefault();

        let interval = setInterval(function () {
            $('.newsletterAjaxError, .newsletterAjaxSuccess').slideUp(400);
            clearInterval(interval)
        }, 3000);

        let  email = $('.newsletter_email');

        let data = {email: email.val()},
            form = $('.newsletter_form'),
            url = form.attr('action'),
            method = form.attr('method');

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

        if (response.errors) {
            $('.newsletterAjaxError').removeClass('d-none').slideDown().html(response.errors);
            $('.newsletterAjaxSuccess').addClass('d-none');
        }
        if (response.message) {
            $('.newsletterAjaxSuccess').removeClass('d-none').slideDown().html(response.message);
            $('.newsletterAjaxError').addClass('d-none');
            email.val('')
        }
    });

    $('.courses_search_button').click(function () {
        if ($('input[type="search"]').val() === ''){
            $('input[type="search"]').addClass('is-invalid bg-warning');
            return false
        }
    });

    $('input[type="search"]').focus(function () {
       $(this).removeClass('is-invalid bg-warning')
    });

    $(".fancybox").fancybox();
});
/*Loading page */
$(window).on("load", function(){
    $(".loading-page")
    .fadeOut(2000 , function(){
        $("body").css("overflow" , "auto");
        $("this").fadeOut(1500 , function(){
            $(this).remove();
        });
    });
});
$(document).ready(function () {
    //animation icon toggler of navbar
    $(`.navbar-toggler`).click(function() {
        $(`.navbar-toggler`).toggleClass(`active`);
    });
    //Wow intit
    wow = new WOW({
        boxClass: 'wow',
        animateClass: 'animated',
        offset: 200,
        mobile: true,
        live: false
    });
    wow.init();
    //smooth_scroll
    smoothScroll.init();
    var amountScrolled = 300;
    $(window).scroll(function () {
        if ($(window).scrollTop() > amountScrolled) {
            $('#scroll-btn').fadeIn('slow');
        } else {
            $('#scroll-btn').fadeOut('slow');
        }
    });
    $('#scroll-btn').click(function () {
        $('html, body').animate({
            scrollTop: 0
        }, 1000);
        return false;
    });
    //fancybox
    $("[data-fancybox]").fancybox({
        selector: '[data-fancybox="images"]',
        loop: true
    });
    //tooltip
    $(function () {
        $('[data-toggle="tooltip"]').tooltip();
    });
});
//Owl carousel
$('.header-carousel').owlCarousel({
    rtl:true,
    margin:20,
    items:1,
    loop:true,
    nav:true,
    dots:false,
    mouseDrag:true,
    touchDrag:true,
})
$('.about-carousel').owlCarousel({
    rtl:true,
    margin:20,
    responsive:{
        0:{
            items:1,
            loop:true,
            nav:false,
            dots:true,
            mouseDrag:true,
            touchDrag:true

        },
        600:{
            items:2,
            loop:true,
            nav:false,
            dots:true,
            mouseDrag:true,
            touchDrag:true
        },
        1000:{
            items:3,
            loop:false,
            nav:false,
            dots:false,
            mouseDrag:false,
            touchDrag:false,
        }
    }
})
$('.quotes-carousel').owlCarousel({
    rtl:true,
    margin:20,
    items:1,
    loop:true,
    nav:false,
    dots:true,
    mouseDrag:true,
    touchDrag:true,
})
$('.team-carousel').owlCarousel({
    rtl:true,
    margin:20,
    loop:true,
    nav:false,
    dots: true,
    mouseDrag:true,
    touchDrag:true,
    responsive:{
        0:{
            items:1,


        },
        600:{
            items:2,
        },
        1000:{
            items:4,

        }
    }
})
$('.contact-carousel').owlCarousel({
    rtl:true,
    margin:20,
    responsive:{
        0:{
            items:1,
            loop:true,
            nav:false,
            dots: true,
            mouseDrag:true,
            touchDrag:true

        },
        600:{
            items:3,
            loop:true,
            nav:false,
            dots: true,
            mouseDrag:true,
            touchDrag:true
        },
        1000:{
            items:4,
            loop:false,
            nav:false,
            dots:false,
            mouseDrag:false,
            touchDrag:false,
        }
    }
})
$('.course-carousel').owlCarousel({
    rtl:true,
    margin:20,
    items:1,
    loop:true,
    nav:true,
    dots:false,
    mouseDrag:true,
    touchDrag:true,
})
$('.blog-carousel').owlCarousel({
    rtl:true,
    margin:20,
    items:1,
    loop:true,
    nav:true,
    dots:false,
    mouseDrag:true,
    touchDrag:true,
})
//edit profile informations
// function fullname(){
//     document.getElementById('fullname').disabled = false;
//     document.getElementById('fullname').style.backgroundColor = "transparent";
//     document.getElementById('fullname').style.color = "#3D84C6";
//     document.getElementById('fullname').style.border = "1px solid #3D84C6";
// }
// function mail(){
//     document.getElementById('mail').disabled = false;
//     document.getElementById('mail').style.backgroundColor = "transparent";
//     document.getElementById('mail').style.color = "#435598";
//     document.getElementById('mail').style.border = "1px solid #3D84C6";
// }
// function country(){
//     document.getElementById('country').disabled = false;
//     document.getElementById('country').style.backgroundColor = "transparent";
//     document.getElementById('country').style.color = "#3D84C6";
//     document.getElementById('country').style.border = "1px solid #3D84C6";
// }
// function city(){
//     document.getElementById('city').disabled = false;
//     document.getElementById('city').style.backgroundColor = "transparent";
//     document.getElementById('city').style.color = "#3D84C6";
//     document.getElementById('city').style.border = "1px solid #3D84C6";
// }
// function address(){
//     document.getElementById('address').disabled = false;
//     document.getElementById('address').style.backgroundColor = "transparent";
//     document.getElementById('address').style.color = "#3D84C6";
//     document.getElementById('address').style.border = "1px solid #3D84C6";
// }
// function phone(){
//     document.getElementById('phone').disabled = false;
//     document.getElementById('phone').style.backgroundColor = "transparent";
//     document.getElementById('phone').style.color = "#3D84C6";
//     document.getElementById('phone').style.border = "1px solid #3D84C6";
// }
// function bankName(){
//     document.getElementById('bankName').disabled = false;
//     document.getElementById('bankName').style.backgroundColor = "transparent";
//     document.getElementById('bankName').style.color = "#3D84C6";
//     document.getElementById('bankName').style.border = "1px solid #3D84C6";
// }
// function accNum(){
//     document.getElementById('accNum').disabled = false;
//     document.getElementById('accNum').style.backgroundColor = "transparent";
//     document.getElementById('accNum').style.color = "#3D84C6";
//     document.getElementById('accNum').style.border = "1px solid #3D84C6";
// }
// function iban(){
//     document.getElementById('iban').disabled = false;
//     document.getElementById('iban').style.backgroundColor = "transparent";
//     document.getElementById('iban').style.color = "#3D84C6";
//     document.getElementById('iban').style.border = "1px solid #3D84C6";
// }
// function cardholder(){
//     document.getElementById('cardholder').disabled = false;
//     document.getElementById('cardholder').style.backgroundColor = "transparent";
//     document.getElementById('cardholder').style.color = "#3D84C6";
//     document.getElementById('cardholder').style.border = "1px solid #3D84C6";
// }
// Grid & List view
function showList(e) {
    var $gridCont = $('.grid-container');
    e.preventDefault();
    $gridCont.hasClass('list-view') ? $gridCont.removeClass('list-view') : $gridCont.addClass('list-view');
    $('.btn-grid').removeClass('active');
    $('.btn-list').addClass('active');
}
function gridList(e) {
    var $gridCont = $('.grid-container')
    e.preventDefault();
    $gridCont.removeClass('list-view');
    $('.btn-list').removeClass('active');
    $('.btn-grid').addClass('active');
}
$(document).on('click', '.btn-grid', gridList);
$(document).on('click', '.btn-list', showList);


//Owl carousel
// $('.owl-carousel').owlCarousel({
//     rtl:true,
//     margin:20,
//     responsive:{
//         0:{
//             items:1,
//             loop:true,
//             nav:true,
//             mouseDrag:true,
//             touchDrag:true

//         },
//         600:{
//             items:2,
//             loop:true,
//             nav:true,
//             mouseDrag:true,
//             touchDrag:true
//         },
//         1000:{
//             items:3,
//             loop:false,
//             nav:false,
//             mouseDrag:false,
//             touchDrag:false,
//         }
//     }
// })
