(function ($) {
    'use strict';
    $(document).ready(function () {

        /*Scroll to Top*/
        $(window).on("scroll", function () {
            if ($(this).scrollTop() >= 50) {
                $('#return-to-top').fadeIn(200);
            } else {
                $('#return-to-top').fadeOut(200);
            }
        });
        $('#return-to-top').click(function () {
            $('body,html').animate({
                scrollTop: 0
            }, 500);
        });

        /*====================================
          slick nav
      ======================================*/
      var logo_path = jQuery('.mobile-menu').data('logo');
      var logo_link = jQuery('.mobile-menu').data('link');
      var logo_type = jQuery('.mobile-menu').data('type');
      let logo;
      if (logo_type === 'text') {
        logo = '<a href="' + logo_link + '"><h1 class="site-title">'+logo_path+'</h1></a>';
      }else {
        logo = '<a href="' + logo_link + '"><img src="' + logo_path + '" class="img-fluid" alt="logo"></a>';;
      }

      jQuery('.navbar-nav').slicknav({
          appendTo: '.mobile-menu',
          removeClasses: true,
          label: '',
  
          closedSymbol: '<i class="fa fa-angle-right"><i/>',
          openedSymbol: '<i class="fa fa-angle-down"><i/>',
          brand: logo
      });

      jQuery(document).ready(function() {
          jQuery(".slicknav_nav").accessibleDropDown();
      });

      jQuery.fn.accessibleDropDown = function () {
        var el = jQuery(this);

        /* Make dropdown menus keyboard accessible */

          jQuery("a", el).focus(function() {
              jQuery(this).parents("li").addClass("force-show");
          }).blur(function() {
              jQuery(this).parents("li").removeClass("force-show");
          });
      }

      function wheelify_toggle_icon_burger() {

        const list = document.querySelectorAll(".slicknav_nav li a");

            // get first element to be focused inside modal
            const firstFocusableElement = document.getElementById('slicknav_btn');

            // get last element to be focused inside modal
            const last = list[list.length - 1];
            const lastFocusableElement = last;

            document.addEventListener('keydown', function (e) {
                let isTabPressed = e.key === 'Tab' || e.keyCode === 9;

                if (!isTabPressed) {
                    return;
                }

                // if shift key pressed for shift + tab combination
                if (e.shiftKey) {
                    if (document.activeElement === firstFocusableElement) {
                        lastFocusableElement.focus();
                        e.preventDefault();
                    }
                } else {
                    if (document.activeElement === lastFocusableElement) {
                        firstFocusableElement.focus();
                        e.preventDefault();
                    }
                }
            });
    }


    wheelify_toggle_icon_burger();

       
    });
})(jQuery);