//intialization plugins
$(document).ready(function () {
    //animation icon toggler of navbar
    $(`.nav_toggler`).click(function() {
        $(this).toggleClass(`active`);
        $('#menu_box').toggleClass(`active`);
    });
    // navbar-fixed-top
    $(function () {
        $(document).scroll(function () {
            var $nav = $(".provider_pg_nav");
            $nav.toggleClass('scrolled', $(this).scrollTop() > $nav.height());
        });
    });
    // categ_card
    $(`.categ_card`).click(function() {
        $('.categ_card').removeClass(`active`);
        $(this).toggleClass(`active`);
    });
    // // categ_card
    // $(`#menuToggler`).click(function() {
    // });

    $(`#dropdownSearchButton`).click(function() {
        $('#dropdownSearch').toggleClass(`active`);
    });

    // Search Container 
    $('#searchToggler').on('click', function () {
        $('.search-wrapper').addClass('active');
        $('body').addClass('overflow_hidden');
    });
    $('#dismissSearch, .search-wrapper .overlay').on('click', function () {
        $('.search-wrapper').removeClass('active');
        $('body').removeClass('overflow_hidden');
    });

    //Wow intit
    wow = new WOW({
        boxClass: 'wow',
        animateClass: 'animated',
        offset: 200,
        mobile: true,
        live: false
    });
    wow.init();
    //fancybox
    $("[data-fancybox]").fancybox({
        selector: '[data-fancybox="images"]',
        // loop: true
    });
    /*Loading page */
    // $(window).on("load", function(){
    //     $(".loading-page")
    //     .fadeOut(2000 , function(){
    //         $("body").css("overflow" , "auto");
    //         $("this").fadeOut(1500 , function(){
    //             $(this).remove();
    //         });
    //     });
    // });  

    //editButton
    $(`.profile_pg  #editButton`).click(function() {
        $(`.profile_pg .prof_tab .data_box`).hide();
        $(`.profile_pg .prof_tab .editData_box`).css("display", "block");
        
    });
});

//Swiper 
var swiper = new Swiper('.restaurants_sec .categ_swiper', {
    // loop: true,
    speed: 900,
    slidesPerView: 2,
    spaceBetween: 10,
    allowTouchMove: false,
    preventClicks: false,
    // centeredSlides: true,
    // autoplay: {
    //     delay: 2500,
    // },
    navigation: {
        nextEl: '.restaurants_sec .swiper-button-next',
        prevEl: '.restaurants_sec .swiper-button-prev',
    },
    pagination: {
        el: '.restaurants_sec .swiper-pagination',
        clickable: true
    },
    breakpoints: {
        640: {
            slidesPerView: 3,
            spaceBetween: 20,
        },
        768: {
            slidesPerView: 4,
            spaceBetween: 20,
        },
        1024: {
            slidesPerView: 7,
            spaceBetween: 20,
            allowTouchMove: false,
            preventClicks: false
        },
    }
});

var swiper = new Swiper('.restaurants_card .resCard_swiper', {
    // loop: true,
    speed: 900,
    slidesPerView: 1,
    spaceBetween: 10,
    observer: true,
    observeParents: true,
    autoplay: {
        delay: 2500,
    },
    navigation: {
        nextEl: '.restaurants_card .swiper-button-next',
        prevEl: '.restaurants_card .swiper-button-prev',
    },
    pagination: {
        el: '.restaurants_card .swiper-pagination',
        clickable: true
    },
});

var swiper = new Swiper('.eventsModal .resCard_swiper', {
    // loop: true,
    speed: 900,
    slidesPerView: 1,
    spaceBetween: 10,
    observer: true,
    observeParents: true,
    autoplay: {
        delay: 3000,
    },
    navigation: {
        nextEl: '.eventsModal .swiper-button-next',
        prevEl: '.eventsModal .swiper-button-prev',
    },
    pagination: {
        el: '.eventsModal .swiper-pagination',
        clickable: true
    },
});

var swiper = new Swiper('.imgs_tab .restuSwiper', {
    // loop: true,
    speed: 900,
    slidesPerView: 1,
    spaceBetween: 10,
    observer: true,
    observeParents: true,
    // centeredSlides: true,
    // autoplay: {
    //     delay: 2500,
    // },
    navigation: {
        nextEl: '.imgs_tab .swiper-button-next',
        prevEl: '.imgs_tab .swiper-button-prev',
    },
    pagination: {
        el: '.imgs_tab .swiper-pagination',
        clickable: true
    },
    breakpoints: {
        768: {
            slidesPerView: 2,
            spaceBetween: 20,
        },
        1024: {
            slidesPerView: 2,
            spaceBetween: 20,
        },
    }
});

var swiper = new Swiper('.events_tab .events_swiper', {
    // loop: true,
    speed: 900,
    slidesPerView: 1,
    spaceBetween: 10,
    observer: true,
    observeParents: true,
    // centeredSlides: true,
    // autoplay: {
    //     delay: 2500,
    // },
    navigation: {
        nextEl: '.events_tab .swiper-button-next',
        prevEl: '.events_tab .swiper-button-prev',
    },
    pagination: {
        el: '.events_tab .swiper-pagination',
        clickable: true
    },
    breakpoints: {
        768: {
            slidesPerView: 2,
            spaceBetween: 20,
        },
        1024: {
            slidesPerView: 3,
            spaceBetween: 20,
        },
    }
});

var swiper = new Swiper('.products_tab .products_swiper', {
    // loop: true,
    speed: 900,
    slidesPerView: 1,
    spaceBetween: 10,
    observer: true,
    observeParents: true,
    // centeredSlides: true,
    // autoplay: {
    //     delay: 2500,
    // },
    navigation: {
        nextEl: '.products_tab .swiper-button-next',
        prevEl: '.products_tab .swiper-button-prev',
    },
    pagination: {
        el: '.products_tab .swiper-pagination',
        clickable: true
    },
    breakpoints: {
        768: {
            slidesPerView: 2,
            spaceBetween: 20,
        },
        1024: {
            slidesPerView: 3,
            spaceBetween: 20,
        },
    }
});

var swiper = new Swiper('.rates_tab .rates_swiper', {
    // loop: true,
    speed: 900,
    slidesPerView: 1,
    spaceBetween: 10,
    observer: true,
    observeParents: true,
    // centeredSlides: true,
    // autoplay: {
    //     delay: 2500,
    // },
    navigation: {
        nextEl: '.rates_tab .swiper-button-next',
        prevEl: '.rates_tab .swiper-button-prev',
    },
    pagination: {
        el: '.rates_tab .swiper-pagination',
        clickable: true
    },
    breakpoints: {
        768: {
            slidesPerView: 2,
            spaceBetween: 20,
        },
    }
});

// ------------ imagePreview -----------
$(document).ready(function() {
    function readURL(input) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            reader.onload = function(e) {
                $('#imagePreview').css('background-image', 'url(' + e.target.result + ')');
                $('#imagePreview').hide();
                $('#imagePreview').fadeIn(650);
            }
            reader.readAsDataURL(input.files[0]);
        }
    }
    $("#imageUpload").change(function() {
        readURL(this);
    });
});


$(document).ready(function() {
    document.getElementById('pro-image').addEventListener('change', readImage, false);
    
    $( ".preview-images-zone" ).sortable();
    
    $(document).on('click', '.image-cancel', function() {
        let no = $(this).data('no');
        $(".preview-image.preview-show-"+no).remove();
    });
});

//Dark Mode 
// if(localStorage.darkMode=="true") {
//     document.body.classList.toggle('dark_mode');
//     document.getElementById("chk").checked=true;
// }
// else {
//     document.body.classList.toggle('light_mode');
// }
// document.getElementById("chk").addEventListener('change', () => {
//     document.body.classList.toggle('dark_mode');
//     document.body.classList.toggle('light_mode');
//     localStorage.darkMode=(localStorage.darkMode=="true")?"false":"true";
// });

// var swiper = new Swiper(' .swiper-container', {
//     // loop: true,
//     speed: 900,
//     slidesPerView: 1,
//     spaceBetween: 15,
//     // autoplay: {
//     //     delay: 2500,
//     // },
//     //In Tabs
//     // observer: true,
//     // observeParents: true,
//     navigation: {
//         nextEl: '.swiper-button-next',
//         prevEl: '.swiper-button-prev',
//     },
//     pagination: {
//         el: '.swiper-pagination',
//         clickable: true
//     },
//     breakpoints: {
//         640: {
//             slidesPerView: 2,
//             spaceBetween: 20,
//         },
//         768: {
//             slidesPerView: 3,
//             spaceBetween: 20,
//         },
//         1024: {
//             slidesPerView: 5,
//             spaceBetween: 20,
//             // Prevent swiper in lg screens
//             // allowTouchMove: false,
//             // preventClicks: false
//         },
//     }
// });

