jQuery(document).ready(function($) {
    var adminbarHeight = $('#wpadminbar').outerHeight();
    var header_sticky_bar = $('.sticky-t-bar ').outerHeight();
    
    // article share 

    var entry_header = $('.single-post .site-main .post .entry-header').outerHeight();
    var page_thumnail = $('.single-post .site-main .post > .post-thumbnail').outerHeight();
    var topValue = entry_header + page_thumnail;
    if ($('.single-post.style-one,.single-post.style-two,.single-post.style-five').length) {
        console.log(0);
        if ($('.single-post .site-main .post >.post-thumbnail').length) {
            $('.single-post .site-main .post.has-meta .article-meta').css('top', topValue + 120);
            console.log(1);
        }
        else  {
             $('.single-post .site-main .post.has-meta .article-meta').css('top', entry_header + 30);
            console.log(2);
            
         }  

    }
    var slider_auto, slider_loop, rtl, testimonial_slider_auto, testimonial_slider_loop;
    
    if( wellness_coach_lite_data.auto == '1' ){
        slider_auto = true;
    }else{
        slider_auto = false;
    }
    
    if( wellness_coach_lite_data.loop == '1' ){
        slider_loop = true;
    }else{
        slider_loop = false;
    }
    
    if( wellness_coach_lite_data.rtl == '1' ){
        rtl = true;
    }else{
        rtl = false;
    }

    $('.site-banner.slider-one .banner-wrapper').owlCarousel({
        loop           : slider_loop,
        mouseDrag      : false,
        margin         : 0,
        nav            : true,
        items          : 1,
        dots           : false,
        autoplay       : slider_auto,
        navText        : '',
        rtl            : rtl,
        lazyLoad       : true,
        autoplaySpeed  : 1000,
        animateOut     : wellness_coach_lite_data.animation,
        autoplayTimeout: wellness_coach_lite_data.speed,
        responsive: {
            0: {
                nav: false,
                dots: true,
            },
            768: {
                nav: true,
                dots: false,
            }
        }
    });

    

    // feature section
    $('.feature-section .bttk-itw-holder').addClass('owl-carousel');

    // feature slider
    $('.feature-section .bttk-itw-holder').owlCarousel({
        loop: false,
        margin: 30,
        nav: true,
        dots: false,
        items: 1,
        rtl: rtl,
        responsive: {
            0: {
                items: 1,
                margin: 0,
                nav: false,
                dots: true
            },
            768: {
                items: 2,
                margin: 30,
                nav: true,
                dots: false
            },
            992: {
                items: 3,
                margin: 30,
                nav: true,
                dots: false
            }
        }
    });

    // testimonial slider
    if( wellness_coach_lite_data.testimonial_auto == '1' ){
        testimonial_slider_auto = true;
    }else{
        testimonial_slider_auto = false;
    }
    
    if( wellness_coach_lite_data.testimonial_loop == '1' ){
        testimonial_slider_loop = true;
    }else{
        testimonial_slider_loop = false;
    }

    $('.testimonial-section .testimonial-sec__content-wrapper .testimonial__inner-wrapper').owlCarousel({
        loop           : testimonial_slider_loop,
        mouseDrag      : false,
        margin         : 0,
        items          : 1,
        dots           : true,
        autoplay       : testimonial_slider_auto,
        navText        : '',
        rtl            : rtl,
        lazyLoad       : true,
        autoplaySpeed  : 1000,
        autoplayTimeout: wellness_coach_lite_data.testimonial_speed,
        responsive: {
            0: {
                nav: false,
            },
            768: {
                nav: true,
            }
        }
    });

        
        $('.menu-item-has-children > a').after('<button class="submenu-toggle-btn"><i class="fas fa-caret-down"></i></button>');
        $('.main-navigation').prepend('<button class="close-btn"></button>');
        $('.site-header:not(.style-three) .secondary-nav .menu-secondary-container').prepend('<button id="closeBttn" class="close-btn"></button>');
        $('.submenu-toggle-btn').on('click', function () {
            $(this).siblings('.sub-menu').stop().slideToggle();
            $(this).toggleClass('active');
        });
        // $('.style-three .header-main .secondary-nav .submenu-toggle-btn').on('click', function () {
        //      $(this).siblings('.sub-menu').stop();
        //      $(this).removeClass('active');
        // });

        $('.header-main .toggle-btn').on('click', function () {
            $(this).siblings('.main-navigation').animate({
                width: 'toggle'
            });
        });
        

        $('.main-navigation .close-btn').on('click', function () {
            $('.main-navigation').animate({
                width: 'toggle'
            });
        });

        $('.secondary-nav .toggle-btn, .secondary-nav .close-btn').on('click', function () {
            if ($('#wpadminbar').length) {
                $('.menu-secondary-container').animate({
                    width: 'toggle',
                    'top': adminbarHeight
                });
            }
            else{
                $('.menu-secondary-container').animate({
                    width: 'toggle' 
                });
            }

        });
        //sticky header js
        if ($('.site-header').length) {
            var stickyHeaderHeight = $('.sticky-header').outerHeight();
            if (wellness_coach_lite_data.sticky == "1") {
                $(window).on('scroll', function () {
                    var headerHeight = $('.site-header + div').offset().top;
                    if ($(window).scrollTop() > headerHeight) {
                        $('.sticky-header').addClass('is-sticky');
                        $('body').addClass('has-sticky-nav');
                        if ($('#wpadminbar').length){
                            $('.sticky-header').css('top', adminbarHeight);
                        }
                    }
                    else {
                        $(".sticky-header").removeClass("is-sticky");
                        $('body').removeClass('has-sticky-nav');
                    }
                });

                $(".widget-sticky .site-content .widget-area .widget:last-child, .single .site-main article .article-meta-inner").css(
                    "top",
                    stickyHeaderHeight + 50
                );

            }
        }

        
        
        // mobile header
        if ($('#wpadminbar').length) {
            $('.site-header .mobile-header .header-bottom-slide .header-bottom-slide-inner ').css("top", adminbarHeight);
        }
        else {
            $('.site-header .mobile-header .header-bottom-slide .header-bottom-slide-inner ').css("top", 0);
        }

        $('.sticky-header .toggle-btn,.site-header .mobile-header .toggle-btn-wrap .toggle-btn').click(function () {
            $('body').addClass('mobile-menu-active');
            $('.site-header .mobile-header .header-bottom-slide .header-bottom-slide-inner ').css("transform", "translate(0px,0)");
        });
        $('.site-header .mobile-header .header-bottom-slide .header-bottom-slide-inner .container .mobile-header-wrap > .close').click(function () {
            $('body').removeClass('mobile-menu-active');
            $('.site-header .mobile-header .header-bottom-slide .header-bottom-slide-inner ').css("transform", "translate(-100%,0)");
            $('.rtl .site-header .mobile-header .header-bottom-slide .header-bottom-slide-inner ').css("transform", "translate(100%,0)");
        });
        

        $('#site-navigation').on( 'click', function(event) {
            event.stopPropagation();
        });

    
     //Header Search form show/hide
     $('.site-header .nav-holder .form-holder').prepend('<div class="btn-close-form"><span></span></div>');

    $('.site-header .form-section').on( 'click', function(event) {
        event.stopPropagation();
    });
    $("#btn-search").on( 'click', function() {
        $(".site-header .form-holder").show("fast");
    });

    $('.btn-close-form').on( 'click', function(){
        $('.site-header .nav-holder .form-holder').hide("fast");
    });

    // accesibility
    $('.nav-menu li a, .nav-menu li .submenu-toggle-btn').on('focus', function () {
        $(this).parents('li').addClass('hover');
    }).blur(function () {
        $(this).parents('li').removeClass('hover');
    });
    

     //header search form toggle 
     $('.header-search .search-toggle').click(function() {
        $(this).siblings('.header-search-wrap').fadeIn();
        $('.header-search-wrap form .search-field').focus();
    });
  
    $('.header-search .close').click(function () {
        $(this).parents('.header-search-wrap').fadeOut();
    });
  
    $('.header-search-wrap').keyup(function(e) {
        if(e.key == 'Escape') {
          $('.header-search .header-search-wrap').fadeOut();
        }
    });
    $('.header-search .header-search-inner .search-form').click(function (e) {
        e.stopPropagation();
    });
  
    $('.header-search .header-search-inner').click(function (e) {
        $(this).parents('.header-search-wrap').fadeOut();
    });

     

     /**
      * =========================
      * article share
      * =========================
      */
    $('.single .content-area article .article-meta .post-share .post-share-title ').on('click', function () {
        $('.single.single-post .content-area .site-main > article .article-meta .post-share .social-networks').slideToggle();
    }); 
      /**
       * =========================
       * article share
       * =========================
       */
    

    //change sticky position of sticky item
    $(window).on('resize load', function () {
        var adminbarHeight = $('#wpadminbar').outerHeight();
        $(window).on('scroll', function (event) {

            if (wellness_coach_lite_data.sticky == "1") {
                $('.widget-area .widget:last-child').css('top', stickyHeaderHeight + 50);
            } else if ($('#wpadminbar').length) {
                $('.widget-area .widget:last-child').css('top', adminbarHeight);
            } else {
                $('.widget-area .widget:last-child').css('top', 0);
            }

        });

    });

    
    

    // client section
    var client_sec_title = $('.client-section .widget-title').text();
    $('.client-section .widget-title').html('<span>' + client_sec_title + '</span>');
    $('.client-section .blossom-inner-wrap').addClass('owl-carousel');
    // client slider
    jQuery('.client-section .blossom-inner-wrap').owlCarousel({
        loop                 : true,
        margin               : 0,
        nav                  : true,
        autoplay             : true,
        dots                 : false,
        autoplayTimeout      : 3000,
        rtl                  : rtl,
        responsive: {
            0: {
                items: 2,
                nav: false,
                dots: true,
            },
            768: {
                items: 3
            },
            1025: {
                items: 5
            }
        }
    });
    
    /* Portfolio Isotope Filter */
    if( $('.page-template-portfolio').length > 0 ){
        // init Isotope
        var $grid = $('.grid').imagesLoaded( function(){  
        
            $grid.isotope({
              // options
            });
            
            // filter items on button click
            $('.filter-button-group').on( 'click', 'button', function() {
              $('.filter-button-group button').removeClass('is-checked');
              $(this).addClass('is-checked');
              var filterValue = $(this).attr('data-filter');
              $grid.isotope({ filter: filterValue });
            });
        
        });
    }

    //back to top
    $(window).on( 'scroll', function () {
    if ($(this).scrollTop() > 200) {
        $('.back-to-top').addClass('active');
    } else {
        $('.back-to-top').removeClass('active');
    }
    });

    $('.back-to-top').on('click', function () {
        $('body,html').animate({
            scrollTop: 0,
        }, 600);
    });

    /**
     * =========================
     * Accessibility codes start
     * =========================
     */
    $(document).on('mousemove', 'body', function (e) {
        $(this).removeClass('keyboard-nav-on');
    });
    $(document).on('keydown', 'body', function (e) {
        if (e.which == 9) {
            $(this).addClass('keyboard-nav-on');
        }
    });
    /**
     * =========================
     * Accessibility codes end
     * =========================
     */

});