{% import "bootstrap5/utils.html" as utils %}

<!doctype html>
<html lang="en">
<head>
  {% block head %}
  <title>{% block title %}{% endblock title %} - {{ admin_gui_title }}</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  {% if favicon %}
  <link rel="icon" href="{{favicon}}">
  {% endif %}


  <!-- Styles -->
  {{ bootstrap.load_css() }}
  <link href="{{ url_for('static', filename='css/application.css') }}" rel="stylesheet">
  {% block styles %}{% endblock %}

  <!-- Scripts -->
  {{ bootstrap.load_js() }}
  <script src="https://code.jquery.com/jquery-3.7.1.min.js"
    integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo="
    crossorigin="anonymous">
  </script>

  <!-- Idle autologout -->
  <script type="text/javascript">
    var idleTimer = null;
    if({{ config['IDLE_TIMEOUT'] }} > 0) {
      function idleAutologout() {
          location.href = "{{ url_for('logout') }}";
      }
      function resetIdleTimer() {
          clearTimeout(idleTimer);
          idleTimer = setTimeout(idleAutologout, {{ config['IDLE_TIMEOUT'] }} * 1000);
      }
      window.addEventListener('keydown', resetIdleTimer, {passive: true});
      window.addEventListener('mousedown', resetIdleTimer, {passive: true});
      window.addEventListener('wheel', resetIdleTimer, {passive: true});
      idleTimer = setTimeout(idleAutologout, {{ config['IDLE_TIMEOUT'] }} * 1000);
    }
  </script>

  <!-- Add spinning icon to buttons with btn-spin-on-click class -->
  <script type="text/javascript">
    $(function() {
      $('.btn-spin-on-click').click(function(e) {
        $(this).prop('disabled', true);
        $(this).html(`{{ utils.render_icon("arrow-repeat") }} ` + $(this).data('spinning-msg'));

        if ($(this).prop('type') == 'submit') {
          // submit form
          e.preventDefault();
          var form = $(this).closest('form').submit();
        }
      });
    });
  </script>

  {% endblock %}
</head>
<body>
  <!-- Navigation bar -->
  {% block navbar %}
    <nav class="navbar navbar-expand-sm bg-light">
      <div class="container">
        <ul class="navbar-nav">
          <li class="nav-item">
            <a class="nav-link" href="{{ url_for('home') }}">{{ i18n('interface.main.home_title') }}</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="{{ url_for('users') }}">{{ i18n('interface.users.title') }}</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="{{ url_for('groups') }}">{{ i18n('interface.groups.title') }}</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="{{ url_for('roles') }}">{{ i18n('interface.roles.title') }}</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="{{ url_for('resources') }}">{{ i18n('interface.resources.title') }}</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="{{ url_for('permissions') }}">{{ i18n('interface.permissions.title') }}</a>
          </li>
          {% for plugin in config['PLUGINS'] %}
              <li class="nav-item">
                <a class="nav-link" href="{{ url_for(plugin.id) }}">{{ plugin.name }}</a>
              </li>
          {% endfor %}
          {% if config['QWC_GROUP_REGISTRATION_ENABLED'] %}
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" href="#" id="reg_dropdown" data-bs-toggle="dropdown" aria-expanded="false">{{ i18n('interface.main.registration_title') }}</a>
              <ul class="dropdown-menu" aria-labelledby="reg_dropdown">
                <li class="nav-item"><a class="nav-link" href="{{ url_for('registrable_groups') }}">{{ i18n('interface.registrable_groups.title') }}</a></li>
                <li class="nav-item"><a class="nav-link" href="{{ url_for('registration_requests') }}">{{ i18n('interface.registration_requests.registration_requests') }}</a></li>
              </ul>
            </li>
          {% endif %}
          <li class="nav-item">
            <a class="nav-link" href="{{ url_for('logout') }}">{{ i18n('interface.main.logout') }}</a>
          </li>
        </ul>
      </div>
    </nav>
  {% endblock %}

  <!-- Page content -->
  {% block content %}
    <div class="container pb-4 pt-4">
      {{ utils.render_messages() }}

      {% block container %}
      {% endblock %}
    </div>
  {% endblock %}

  <!-- Extra scripts from derived templates -->
  {% block scripts %}
  {% endblock %}
</body>
</html>
