{% import "macros.html" as macros with context %}
<!DOCTYPE html>
<html lang="{{ get_locale()|string|replace('_', '-') }}">
  <head>
    {% block head %}
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="csrf_token" content="{{ csrf_token() }}">
    <title>{% block title %}{{ site_name }}{{ (': ' ~ title)|safe if title }}{% endblock %}</title>
    <link href="{{ static_file(filename='css/evesrp.css') }}" rel="stylesheet">
    <link rel="shortcut icon" href="{{ static_file(filename='favicon.ico') }}">
    {% endblock head %}
  </head>
  <body>
    {% block body %}
    <div class="modal" id="copyModal" tabindex="1" role="dialog" aria-hidden="true">
      <div class="modal-dialog modal-sm">
        <div class="modal-content">
          <div class="modal-body">
            {# TRANS: A quick message shown to someone when they need to press a key combo to copy text. #}
            <p id="keyComboMessage">{{ gettext("Press %(key_combo)s to Copy.", key_combo="Ctrl-C") }}</p>
          </div>
        </div>
      </div>
    </div>
    <nav class="navbar navbar-default navbar-static-top" role="navigation">
      <div class="container">
        <!-- Navbar "Brand and the collapse/expand toggle -->
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#eve-srp-navbar-collapse">
            {# TRANS: This is only for screen-readers (for blind users) #}
            <span class="sr-only">{% trans %}Toggle Navigation{% endtrans %}</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="{{ url_for('index') }}">{{ site_name }}</a>
        </div><!-- .navbar-header -->
        <!-- The actual navigation things -->
        <div class="collapse navbar-collapse" id="eve-srp-navbar-collapse">
          {% block collapsed_navitems %}
          <ul class="nav navbar-nav" id="left-nav">
            {% block navitems %}
            {% if current_user.is_authenticated %}
            {% if current_user.has_permission((PermissionType.review, PermissionType.audit)) %}
            {# TRANS: This is in the navigation bar at the top, and is a link to a list of request that are waiting to be evaluated. #}
            {{ macros.navbar_button(gettext('Pending'), 'requests.list_pending_requests', request_count(PermissionType.review), id='badge-pending')|indent(12)|safe }}
            {% endif %}
            {% if current_user.has_permission(PermissionType.pay) %}
            {# TRANS: This is in the navigation bar at the top, and is a link to a list of requests ready to pay out. #}
            {{ macros.navbar_button(gettext('Pay Outs'), 'requests.list_approved_requests', request_count(PermissionType.pay), id='badge-payouts')|indent(12)|safe }}
            {% endif %}
            {% if current_user.has_permission(PermissionType.elevated) %}
            {# TRANS: This is in the navigation bar at the top, and is a link to a list of request that have been either rejected or been paid. #}
            {{ macros.navbar_button(gettext('Completed'), 'requests.list_completed_requests')|indent(12)|safe }}
            {% endif %}
            {% endif %}
            {% endblock navitems %}
          </ul>
          <ul class="nav navbar-nav navbar-right" id="right-nav">
            {% block navitems_right %}
            {% if current_user.is_anonymous %}
            {# TRANS: This is a link in the navigation bar. It goes to the login page. #}
            {{ macros.navbar_button(gettext('Log In'), 'login.login')|indent(12)|safe }}
            {% else %}
            {% if current_user.has_permission(PermissionType.submit) %}
            {# TRANS: This is a link in the navigation bar to the page for submitting a request. #}
            {{ macros.navbar_button(gettext('Submit'), 'requests.submit_request')|indent(12)|safe }}
            {% endif %}
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                {% with personal_count = request_count(PermissionType.submit) %}
                <span class="caret"></span> {{ current_user.name }} <span class="badge hidden-sm" id="badge-personal">
                  {%- if personal_count != 0 -%}
                  {{ personal_count|numberfmt }}
                  {%- endif -%}
                </span>
                {% endwith %}

              </a>
              <ul class="dropdown-menu">
                {# TRANS: This is a link in the navigation bar, linking to all of the requests the current user has ever made. #}
                {{ macros.navbar_button(gettext('Requests'), 'requests.personal_requests', request_count(PermissionType.submit))|indent(16)|safe }}
                {# TRANS: This is a link in the navigation bar to the page for managing the app's external API keys (not API keys from CCP, but those from within the app). #}
                {{ macros.navbar_button(gettext('API Keys'), 'login.api_keys')|indent(16)|safe }}
                {# TRANS: This is a link in the navigation bar to a page listing the permissions a user has in different reimbursement divisions. #}
                {{ macros.navbar_button(gettext('Permissions'), 'divisions.permissions')|indent(16)|safe }}
                <li class="divider"></li>
                {# TRANS: The link in the navigation bar at the top for logging out of the app. #}
                {{ macros.navbar_button(gettext('Log Out'), 'login.logout')|indent(16)|safe }}
              </ul>
            </li>
            {% endif %}
            {% endblock navitems_right %}
          </ul>
          {% endblock collapsed_navitems %}
        </div>
      </div>
    </nav>
    <div id="content" class="container">
      {% with messages = get_flashed_messages(with_categories=true) %}
      {% if messages %}
      {% for category, message in messages %}
      {% if category == 'message' %}{% set alert_class = 'alert-success' %}
      {% elif category == 'warning' %}{% set alert_class = 'alert-warning' %}
      {% elif category == 'error' %}{% set alert_class = 'alert-danger' %}
      {% else %}
      {# catches 'info', the final recommended flash category #}
      {% set alert_class = 'alert-info' %}
      {% endif %}
      <div class="alert {{ alert_class }} alert-dismissable fade in">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        {{ message }}
      </div>
      {% endfor %}
      {% endif %}
      {% endwith %}
      {% block content %}
      <p>Placeholder content here</p>
      {% endblock content %}
    </div>
    {% block stats %}
    <footer id="stats">
      <p class="text-muted text-center"><small>
        EVE-SRP v{{ app_version }} &bull;
        {# TRANS: This is a link to the Github project for the app. It's where people can contribute code to the project. #}
        <a href="https://github.com/paxswill/evesrp">{{ gettext('Github Project') }}</a> &bull;
        {% if 'dev' in app_version %}
        <a href="https://eve-srp.readthedocs.org/en/latest/users.html">
        {% else %}
        <a href="{{ "https://eve-srp.readthedocs.org/en/v" ~ app_version ~ "/users.html" }}">
        {% endif %}
        {# TRANS: This is a link to the manual for the app. #}
        {{ gettext('Help') }}
        </a>
      </small></p>
      {% if locales()|list|length > 1 %}
      <form method="GET" class="text-muted text-center">
        <small>
          <input id="lang" type="hidden" name="lang" value="">
          {% for locale in locales() %}
          {% if get_locale() == locale %}
          <strong>{{ locale.display_name }}</strong>
          {% else %}
          <a class="langSelect" data-lang="{{ locale|string }}" href="#">{{ locale.display_name }}</a>
          {% endif %}
          {% if not loop.last %}
          &bull;
          {% endif %}
          {% endfor %}
        </small>
      </form>
      {% else %}
      <!-- No locales -->
      {% endif %}
      {% if current_user.admin %}
      <p class="text-muted text-center">
        <small>
          {# TRANS: This is a specialized line of text that is only visible to administrators. It shows the how many of database queries were executed to make this page, and how long they took (in milliseconds). #}
          {{ gettext('%(queries)d queries in %(time).3f ms', queries=g.DB_STATS.total_queries, time=(g.DB_STATS.total_time * 1000)) }}
        </small>
      </p>
      {% endif %}
    </footer>
    {% endblock stats %}
    {% endblock body %}
    {% block scripts %}
    {% if config['SENTRY_DSN_PUBLIC'] %}
    <script type="text/javascript" src="https://cdn.ravenjs.com/3.0.2/raven.min.js"></script>
    <script type="text/javascript">
      Raven.config("{{ config['SENTRY_DSN_PUBLIC'] }}", {
        release: "{{ app_version }}",
      }).install();
      {% if current_user.is_authenticated %}
      Raven.setUserContext({
        name: "{{ current_user.name }}",
        id: {{ current_user.id }},
        authmethod: "{{ current_user.authmethod }}"
      });
      {% endif %}
    </script>
    {% endif %}
    <!-- scriptRoot is the root of this application, wherever it it -->
    <script type="text/javascript">scriptRoot = {{ request.script_root|tojson }};</script>
    <script type="text/javascript" src="{{ static_file('js/formatters.min.js') }}"></script>
    <script type="text/javascript" src="{{ static_file('js/evesrp.min.js') }}"></script>
    {% endblock scripts %}
  </body>
</html>
