$(document).ready(function() {

    $('.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('')
        }
    });
    $('.visitor_request_button').click(async function (e) {
        e.preventDefault();

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

        let form = $('.visitor_request_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) {
            $('.visitorRequestAjaxError').removeClass('d-none').slideDown().html(response.errors);
            $('.visitorRequestAjaxSuccess').addClass('d-none');
        }
        if (response.message) {
            $('.visitorRequestAjaxSuccess').removeClass('d-none').slideDown().html(response.message);
            $('.visitorRequestAjaxError').addClass('d-none');
            $('.visitor_request_form input, textarea').val('')
        }
    });

    /* ----------------------------------------------------------------
                    [ file-upload ]
    -----------------------------------------------------------------*/

    $(".file-upload").on("change", ".file-upload-field", function() {
        $(this).parent(".file-upload-wrapper").attr("data-text", $(this).val().replace(/.*(\/|\\)/, ''));
    });

    var wind = $(window);

    wow = new WOW({
        boxClass: 'wow',
        animateClass: 'animated',
        offset: 200,
        mobile: false,
        live: false
    });
    wow.init();


    // ----------------- scroll navbar ------------------
    wind.on("scroll", function() {

        var bodyScroll = wind.scrollTop(),
            navbar = $(".menu")

        if (bodyScroll > 200) {

            navbar.addClass("fixed");

        } else {

            navbar.removeClass("fixed");
        }
    });


    // ---------- to top -----------
    $('.to-top').click(function() {
        $('html, body').animate({
            scrollTop: 0
        }, 1000);
        return false;
    });


    // -------------- nav-toggle ------------
    $('.nav-toggle').click(function() {
        $('.navbar .custom-navbar .nav-list').toggleClass('show');
        $(this).toggleClass('active');
        $('.navbar .custom-navbar .overlay').toggleClass('show');
    })
    $('.navbar .custom-navbar .overlay').click(function() {
        $(this).removeClass('show');
        $('.navbar .custom-navbar .nav-list').removeClass('show');
        $('.nav-toggle').removeClass('active');
    })

});


// ------------ swiper sliders -----------
$(document).ready(function() {
    // ------------ head slider -----------
    var swiper = new Swiper('.swiper-head', {
        speed: 800,
        pagination: false,
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
        mousewheel: false,
        keyboard: true,
        autoplay: {
            delay: 6000,
        },
        loop: true,
    });
});

// === window When Loading === //

$(window).on("load", function() {

    var wind = $(window);

    $(".loader").delay(6000).fadeOut(1000);

});
