( function( window, document ) {
  function gym_coach_keepFocusInMenu() {
    document.addEventListener( 'keydown', function( e ) {
      const gym_coach_nav = document.querySelector( '.sidenav' );
      if ( ! gym_coach_nav || ! gym_coach_nav.classList.contains( 'open' ) ) {
        return;
      }
      const elements = [...gym_coach_nav.querySelectorAll( 'input, a, button' )],
        gym_coach_lastEl = elements[ elements.length - 1 ],
        gym_coach_firstEl = elements[0],
        gym_coach_activeEl = document.activeElement,
        tabKey = e.keyCode === 9,
        shiftKey = e.shiftKey;
      if ( ! shiftKey && tabKey && gym_coach_lastEl === gym_coach_activeEl ) {
        e.preventDefault();
        gym_coach_firstEl.focus();
      }
      if ( shiftKey && tabKey && gym_coach_firstEl === gym_coach_activeEl ) {
        e.preventDefault();
        gym_coach_lastEl.focus();
      }
    } );
  }
  gym_coach_keepFocusInMenu();
} )( window, document );