{% load i18n static admin_tools_menu_tags cache %}
{% if menu.children %}
  <script type="text/javascript" src="{% static 'jnt_admin_tools/js/utils.js' %}"></script>
  <script type="text/javascript" charset="utf-8">

    // Load js files syncronously and conditionally
    const menuJsFiles = [
      {
        src: '{% static "admin/js/vendor/jquery/jquery.min.js" %}',
        test: function () {
          return typeof (jQuery) == 'undefined';
        }
      },
      {
        src: '{% static "jnt_admin_tools/js/json.min.js" %}',
        test: function () {
          return typeof (JSON.stringify) == 'undefined';
        }
      },
      {
        src: '{% static "jnt_admin_tools/js/menu.js" %}',
        test: function () {
          return true;
        }
      }{% for js in menu.Media.js %},
        {
          src: '{% static js %}',
          test: function () {
            return true;
          }
        }{% endfor %}
    ];

    loadScripts(menuJsFiles, function () {
      jQuery(function ($) {
        {% if has_bookmark_item %}
          process_bookmarks(
            "{{ request.get_full_path }}",
            "{{ title|capfirst }}",
            "{% trans 'Please enter a name for the bookmark' %}"
          );
        {% endif %}
      });
    });

  </script>
  {% if has_bookmark_item %}
    {% if bookmark %}
      {% include "jnt_admin_tools/menu/remove_bookmark_form.html" %}
    {% else %}
      {% include "jnt_admin_tools/menu/add_bookmark_form.html" %}
    {% endif %}
  {% endif %}
  <ul id="navigation-menu">
    {% for item in menu.children %}
      {% if item.cache_enabled and item.cache_key %}
        {% cache item.cache_timeout navigation_menu item.cache_key %}
          {% admin_tools_render_menu_item item forloop.counter %}
        {% endcache %}
      {% else %}
        {% admin_tools_render_menu_item item forloop.counter %}
      {% endif %}
    {% endfor %}
  </ul>
{% endif %}
