jQuery(function($) {
    "use strict";

    // Scroll to top functionality
    $(window).on('scroll', function() {
        if ($(this).scrollTop() >= 50) {
            $('#return-to-top').fadeIn(200);
        } else {
            $('#return-to-top').fadeOut(200);
        }
    });

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

    // Side navigation toggle
    $('.gb_toggle').on('click', function() {
        home_interior_decor_Keyboard_loop($('.side_gb_nav'));
    });

    // Preloader fade out
    setTimeout(function() {
        $(".loader").fadeOut("slow");
    }, 1000);

    // Sticky menu
    $(window).on('scroll', function() {
        var data_sticky = $('.menubar').data('sticky');
        if (data_sticky === true) {
            if ($(this).scrollTop() > 1) {
                $('.menubar').addClass("stick_head");
            } else {
                $('.menubar').removeClass("stick_head");
            }
        }
    });

    // Slider
  $(document).ready(function() {
    $('#slider .owl-carousel').owlCarousel({
      loop: false,
      margin: 0,
      nav: true,
      dots: true,
      navText: ['<i class="fas fa-arrow-left"></i>','<i class="fas fa-arrow-right"></i>'],
      rtl: false,
      items: 1,
      autoplay: false,
      autoplayTimeout: 3000,
      autoplayHoverPause: true,
    });
  });
});

// Mobile responsive menu
function home_interior_decor_menu_open_nav() {
    jQuery(".sidenav").addClass('open');
}

function home_interior_decor_menu_close_nav() {
    jQuery(".sidenav").removeClass('open');
}

// Dropdown category
jQuery(document).ready(function() {
    jQuery(".category-dropdown").hide();

    jQuery("button.category-btn").on('click', function() {
        jQuery(".category-dropdown").toggle();
    });

    // Handle focus using Tab and Shift+Tab
    jQuery(".category-btn, .category-dropdown").on("keydown", function(e) {
        var dropdownItems = jQuery(".category-dropdown").find("a"); // Assuming dropdown items are represented by <a> tags

        if (e.key === "Tab") { // Handle Tab key
            if (!e.shiftKey && document.activeElement === dropdownItems.last()[0]) {
                e.preventDefault();
                jQuery(".category-btn").focus();
            } else if (e.shiftKey && document.activeElement === dropdownItems.first()[0]) {
                e.preventDefault();
                jQuery(".category-btn").focus();
            }
        }
    });
});

// product category
jQuery('document').ready(function(){
  var owl = jQuery('#product_cat_slider .owl-carousel');
    owl.owlCarousel({
    margin:20,
    nav: true,
    navText: ['<i class="fas fa-arrow-left"></i>','<i class="fas fa-arrow-right"></i>'],
    autoplay : false,
    lazyLoad: false,
    autoplayTimeout: 3000,
    loop: true,
    dots:true,
    responsive: {
      0: {
        items: 1
      },
      600: {
        items: 3
      },
      1000: {
        items: 6
      }
    },
    autoplayHoverPause : true,
    mouseDrag: true
  });
});