// ******** Banner Slider ******** //
$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});

new Swiper('#bannerSlider', {
      autoplay: {
          delay: 4000,
       }, //enable auto height
      fadeEffect: { crossFade: true },
      speed: 3000,
      effect: "fade",
      spaceBetween: 20,
      pagination: {
        el: '.swiper-pagination',
        clickable: true,
      },
      navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
      },
    });
    // $("#bannerSlider").hover(function() {
    //     (this).swiper.autoplay.stop();
    // }, function() {
    //     (this).swiper.autoplay.start();
    // });
// ******** Professor Slider ******** //
new Swiper('#professorSlider', {
    freeMode: true,
    speed:2000,
    autoplay: {
        delay: 3000,
    },
    loop:true,
    spaceBetween: 5,
    pagination: {
        el: ".swiper-pagination",
        dynamicBullets: true,
    },
});
// ******** Single Project Slider ******** //
new Swiper('#collageSlider', {
    freeMode: true,
    speed:2000,
    autoplay: {
        delay: 3000,
    },
    loop:true,
    spaceBetween: 5,
    // pagination: {
    //     el: ".swiper-pagination",
    //     dynamicBullets: true,
    // },
    navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
    },
    breakpoints: {
        320: {
            slidesPerView: 2,
            spaceBetween: 20,
        },
        481: {
            slidesPerView: 2,
            spaceBetween: 20,
        },
        768: {
            slidesPerView: 3,
            spaceBetween: 30,
        },
        1024: {
            slidesPerView: 6,
            spaceBetween: 30,
        },
    }
});
// ******** Banner Slider ******** //
new Swiper('#projectdownSlider', {
    autoplay: {
        delay: 3000,
    }, //enable auto height
    spaceBetween: 20,
    pagination: {
        el: '.swiper-pagination',
        clickable: true,
    },
    // navigation: {
    //     nextEl: '.swiper-button-next',
    //     prevEl: '.swiper-button-prev',
    // },
});
// *******Work With Slider ******** //
    new Swiper('#MasterPlanSlider', {
        autoplay: {
            delay: 3000,
        },
        preventClicks: true,
        preventClicksPropagation: true ,
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
        breakpoints: {
            320: {
                slidesPerView: 1,
                spaceBetween: 20,
            },
            481: {
                slidesPerView: 2,
                spaceBetween: 20,
            },
            768: {
                slidesPerView: 2,
                spaceBetween: 30,
            },
            1024: {
                slidesPerView: 2,
                spaceBetween: 30,
            },
        }
    });

// *******More Projects Slider ******** //
new Swiper('#moreProjectSlider', {
    autoplay: {
        delay: 5000,
    },
    preventClicks: true,
    navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
    },
    breakpoints: {
        320: {
            slidesPerView: 1,
            spaceBetween: 20,
        },
        768: {
            slidesPerView: 2,
            spaceBetween: 10,
        },
        1024: {
            slidesPerView: 3,
            spaceBetween: 10,
        },
    }
});

// *******Accredited Slider ******** //
new Swiper('#accredited_slider', {
    autoplay: {
        delay: 4000,
    },
    pagination: {
        el: '.swiper-pagination',
        clickable: true,
    },
    preventClicks: true,
    preventClicksPropagation: true ,
    navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
    },
    breakpoints: {
        320: {
            slidesPerView: 2,
            spaceBetween: 10,
        },
        768: {
            slidesPerView: 5,
            spaceBetween: 10,
        },
        1024: {
            slidesPerView: 6,
            spaceBetween: 20,
        },
    }
});

// ******** NAVBAR CLICKING ******** //
    var pathname = window.location.pathname;
    function ShowSection(url, position,id){
        if(pathname != '/'){
            window.location.href = "/"+url;
        }else{
            var nav_bar_data = (".navOnclick a");
            for(var i=0;i<nav_bar_data.length;i++){
                $("a#navbar"+i).removeClass("active");
            }
            $("a#navbar"+id).addClass("active");

            $('html,body').animate({scrollTop: $(url).offset().top-position}, 'slow');
        }
        closeNavigation();
    }

// ******** ONCLICK NAVBAR CLOSING ******** //
    function closeNavigation() {
          // document.querySelector(".siteNavigation").style.display = "none";
        var siteNavi = document.querySelector('.siteNavigation');
        var menuTogg = document.querySelector('.toggle');

        siteNavi.classList.toggle('active');
        menuTogg.classList.toggle('active');
        };

// ******** NAVBAR OPEN / CLOSE ******** //
    const menuToggle = document.querySelector('.toggle');
    const siteNavigation = document.querySelector('.siteNavigation');
    menuToggle.onclick = function(){
        menuToggle.classList.toggle('active');
        siteNavigation.classList.toggle('active');
    }

// ******** Moblie Navbar Clicking ******** //
    function ShowMobSection(url,position){
        if(pathname != '/'){
            window.location.href = "/"+url;
        }else{
            $('html,body').animate({scrollTop: $(url).offset().top-position}, 'slow');
        }
        closeNav();
    }

// ******** Mob View Fixed Header ******** //
$(window).scroll(function(){
      var mob_sticky = $('#mob-header'),
          scroll = $(window).scrollTop();
      if (scroll >= 20) mob_sticky.addClass('mob_sticky');
      else mob_sticky.removeClass('mob_sticky');
    });


// ******** Mobile Navigation ******** //
    function getDirection() {
      var windowWidth = window.innerWidth;
      var direction = window.innerWidth <= 760 ? 'vertical' : 'horizontal';
      return direction;
    }
    function openNav() {
      document.getElementById("mySidenav").style.width = "250px";
    }

    function closeNav() {
      document.getElementById("mySidenav").style.width = "0";
    };


function getCity(){
    var country = $('#country').val();
    var url = window.location.origin+'/getCity/'+country;
   console.log(country);
    $.ajax({
        url: url,
        type: 'GET',
        // data: {country: country},
    })
        .done(function (data) {
            $('select[name="city_id"]').empty();
            $('select[name="city_id"]').append('<option>---Select City---</option>');
            $.each(data,function(key,value){
                // console.log(value);
                $('select[name="city_id"]').append('<option value="'+value['id']+'">'+value['title']+'</option>');
            });
        })
        .fail(function () {
            alert('Somthing Went Wrong!');
        })
        .always(function () {
            $('tbody').removeClass('table-loader');
        });
}
// ******** Sticky Header ******** //
    window.addEventListener('scroll', function(){
        var header = document.querySelector('header');
        header.classList.toggle('sticky', window.scrollY > 0);
    });

    // ******** Preloader ******** //
    // window.addEventListener('load', () => {
    //     const preloader = document.querySelector(".preloader");
    //     preloader.classList.add("preload-finish")
    // });
// ******** CONTACT SUBMIT ******** //
function contactSubmit() {
    var first_name = $('#first_name').val();
    var email = $('#email').val();
    var phone = $('#phone').val();
    var message = $('#message').val();
    var url = window.location.origin+'/saveContactSubdmit';

    if(first_name && phone) {
        $.ajax({
            url: url,
            type: 'GET',
            data: {
                first_name: first_name,
                email: email,
                phone: phone,
                message: message},
        })
            .done(function (data) {
                console.log(data);
                if (data == 'true') {
                    $('#contact__register').empty();
                    $('#contact__register').addClass('text-green-500 text-center w-9/12 bg-green-100 py-4 mx-auto mb-6 text-xl');
                    $('#contact__register').append('Thank You For showing your Interest to Us!');
                    $('#first_name').val(null);
                    $('#first_name_error').empty();
                    $('#email').val(null);
                    $('#email_error').empty();
                    $('#phone').val(null);
                    $('#phone_error').empty();
                    $('#message').val(null);
                }
            })
            .fail(function () {
                $('#contact__register').empty();
                $('#contact__register').addClass('text-red-500 text-center w-9/12 bg-red-100 py-4 mx-auto mb-6 text-xl');
                $('#contact__register').append('Somthing Went Wrong!');
            })

            .always(function () {
                $('tbody').removeClass('table-loader');
            });
    } else {
        if (first_name == "") {
            $('#first_name_error').empty();
            $('#first_name_error').addClass('invalid-feedback text-red-500 font-light text-sm ');
            $('#first_name_error').append('Name is Required!');
        }
        if (IsEmail(email)==false) {
            if(email != ""){
                $('#email_error').empty();
                $('#email_error').addClass('invalid-feedback text-red-500 font-light text-sm ');
                $('#email_error').append('Invalid Email Address!');
            }
        }
        if (phone == "") {
            $('#phone_error').empty();
            $('#phone_error').addClass('invalid-feedback text-red-500 font-light text-sm ');
            $('#phone_error').append('Contact Field is Required!');
        }

    }
};
function IsEmail(email) {
    var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if(!regex.test(email)) {
        return false;
    }else{
        return true;
    }
}
