jQuery(document).ready(function ($) {

    /* Header Search toggle
   --------------------------------------------- */
    $('.header-search .search-toggle').click(function () {
        $(this).siblings('.header-search-wrap').fadeIn().removeClass('inactive').addClass('sactive');
        $('.header-search-wrap form .search-field').focus();
    });

    $('.header-search .close').click(function () {
        $(this).parents('.header-search-wrap').fadeOut().removeClass('sactive').addClass('inactive');
    });

    $('.header-search-wrap').keyup(function (e) {
        if (e.key == 'Escape') {
            $('.header-search .header-search-wrap').fadeOut().removeClass('sactive').addClass('inactive');
        }
    });
    $('.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();
    });

    /* Desktop Navigation
    --------------------------------------------- */
    $('.menu-item-has-children >a').after('<button class="submenu-toggle-btn"><i class="fas fa-caret-down"></i></button>');
    $('.submenu-toggle-btn').on('click', function () {
        $(this).siblings('.sub-menu').stop().slideToggle();
        $(this).toggleClass('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'
        });
    });

    /* Mobile Navigation
    --------------------------------------------- */

    var adminbarHeight = $('#wpadminbar').outerHeight();
    if (adminbarHeight) {
        $('.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(0,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)");
    });

    /* secondary Navigation
    --------------------------------------------- */
    $('.site-header .secondary-nav .toggle-btn').on('click', function () {
        $('.site-header .secondary-nav > div').addClass('menu-active');
        if ($('#wpadminbar').length) {
            $('.site-header .secondary-nav > div').css("top", adminbarHeight);

        }
    });
    $(' .secondary-nav .close-btn').on('click', function () {
        $('.site-header .secondary-nav > div').removeClass('menu-active');
    });

    /*  Navigation Accessiblity
    --------------------------------------------- */
    $(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');
        }
    });

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

    /*  Scroll 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);
    });

    /* sticky widget
    --------------------------------------------- */
    $(window).on('resize load', function () {
        var adminbarHeight = $('#wpadminbar').outerHeight();
        $(window).on('scroll', function (event) {

            if ($('#wpadminbar').length) {
                $('.widget-area .widget:last-child').css('top', adminbarHeight);
            } else {
                $('.widget-area .widget:last-child').css('top', 0);
            }

        });

    });

    var slider_auto, slider_loop, rtl;

    if (feminine_lifestyle_blog_data.auto == '1') {
        slider_auto = true;
    } else {
        slider_auto = false;
    }

    if (feminine_lifestyle_blog_data.loop == '1') {
        slider_loop = true;
    } else {
        slider_loop = false;
    }

    if (feminine_lifestyle_blog_data.rtl == '1') {
        rtl = true;
    } else {
        rtl = false;
    }

    //Banner slider js
    $('.site-banner.style-one .item-wrap').owlCarousel({
        items: 1,
        autoplay: slider_auto,
        loop: slider_loop,
        nav: true,
        dots: false,
        autoplaySpeed: 800,
        autoplayTimeout: feminine_lifestyle_blog_data.speed,
        rtl: rtl,
        responsive: {
            0: {
                margin: 10,
                stagePadding: 20,
            },
            768: {
                margin: 10,
                stagePadding: 80,
            },
            1025: {
                margin: 40,
                stagePadding: 150,
            },
            1200: {
                margin: 60,
                stagePadding: 200,
            },
            1367: {
                margin: 80,
                stagePadding: 300,
            },
            1501: {
                margin: 110,
                stagePadding: 342,
            }
        }
    });

    if ($('.single-post .site-main .article-meta').length) {
        $('.single-post .site-main article').addClass('has-article-meta');
    }

    //alignfull js
    $(window).on('load resize', function () {
        var metaWidth;
        if ($(window).width() > 1024) {
            metaWidth = $('.single .site-main .article-meta').outerWidth() + 50;
        } else {
            metaWidth = $('.single .site-main .article-meta').outerWidth() + 30;
        }
        var gbWindowWidth = $(window).width();
        var gbContainerWidth = $('.feminine-lifestyle-blog-has-blocks .site-content > .container').width();
        var gbContentWidth;
        if ($('.single-post .site-main .article-meta').length) {
            if ($(window).width() > 767) {
                gbContentWidth = $('.feminine-lifestyle-blog-has-blocks .site-main .entry-content').width() - metaWidth;
            } else {
                gbContentWidth = $('.feminine-lifestyle-blog-has-blocks .site-main .entry-content').width();
            }
            $('.feminine-lifestyle-blog-has-blocks.full-width .wp-block-cover-image .wp-block-cover__inner-container, .feminine-lifestyle-blog-has-blocks.full-width .wp-block-cover .wp-block-cover__inner-container, .feminine-lifestyle-blog-has-blocks.full-width-centered .wp-block-cover-image .wp-block-cover__inner-container, .feminine-lifestyle-blog-has-blocks.full-width-centered .wp-block-cover .wp-block-cover__inner-container').css('padding-left', metaWidth);
        } else {
            gbContentWidth = $('.feminine-lifestyle-blog-has-blocks .site-main .entry-content').width();
        }
        var gbMarginFull = (parseInt(gbContentWidth) - parseInt(gbWindowWidth)) / 2;
        var gbMarginFull2 = (parseInt(gbContentWidth) - parseInt(gbContainerWidth)) / 2;
        var gbMarginCenter = (parseInt(gbContentWidth) - parseInt(gbWindowWidth)) / 2;
        $(".feminine-lifestyle-blog-has-blocks.full-width .site-main .entry-content .alignfull").css({ "max-width": gbWindowWidth, "width": gbWindowWidth, "margin-left": gbMarginFull });
        $(".feminine-lifestyle-blog-has-blocks.full-width-centered .site-main .entry-content .alignfull").css({ "max-width": gbWindowWidth, "width": gbWindowWidth, "margin-left": gbMarginCenter });
        $(".feminine-lifestyle-blog-has-blocks.full-width-centered .site-main .entry-content .alignwide").css({ "max-width": gbContainerWidth, "width": gbContainerWidth, "margin-left": gbMarginFull2 });
    });

});