{% import "macros.html" as macros with context %}
<!DOCTYPE html>
<html lang="en">
  <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 }}{% endblock %}</title>
    <link href="{{ url_for('static', filename='css/custom.css') }}" rel="stylesheet">
    <!-- Bootstrap -->
    <link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="stylesheet">
    <!-- Bootstrap-tokenfield -->
    <link href="{{ url_for('static', filename='css/bootstrap-tokenfield.min.css') }}" rel="stylesheet">
    <link href="{{ url_for('static', filename='css/tokenfield-typeahead.min.css') }}" rel="stylesheet">
    {% endblock head %}
  </head>
  <body>
    {% block body %}
    <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">
            <span class="sr-only">Toggle Navigation</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">
            {% block navitems %}
            {% if current_user.is_authenticated() %}
            {% if current_user.has_permission(PermissionType.review) %}
            {{ macros.navbar_button('Pending', 'requests.list_pending_requests', request_count(PermissionType.review))|indent(12)|safe }}
            {% endif %}
            {% if current_user.has_permission(PermissionType.pay) %}
            {{ macros.navbar_button('Pay Outs', 'requests.list_approved_requests', request_count(PermissionType.pay))|indent(12)|safe }}
            {% endif %}
            {% if current_user.has_permission(PermissionType.pay) or current_user.has_permission(PermissionType.review) %}
            {{ macros.navbar_button('Completed', 'requests.list_completed_requests')|indent(12)|safe }}
            {% endif %}
            {% endif %}
            {% endblock navitems %}
          </ul>
          <ul class="nav navbar-nav navbar-right">
            {% block navitems_right %}
            {% if current_user.is_anonymous() %}
            {{ macros.navbar_button('Log In', 'login.login')|indent(12)|safe }}
            {% else %}
            {% if current_user.has_permission(PermissionType.submit) %}
            {{ macros.navbar_button('Submit', 'requests.submit_request')|indent(12)|safe }}
            {% endif %}
            {{ macros.navbar_button('Personal', 'requests.personal_requests', request_count(PermissionType.submit))|indent(12)|safe }}
            {% if current_user.admin or current_user.has_permission(PermissionType.admin) %}
            {{ macros.navbar_button('Admin', 'divisions.list_divisions')|indent(12)|safe }}
            {% endif %}
            {{ macros.navbar_button('Log Out', 'login.logout')|indent(12)|safe }}
            {% 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;
        <a href="https://github.com/paxswill/evesrp">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 %}
          Help
        </a>
      </small></p>
      {% if current_user.admin %}
      <p class="text-muted text-center"><small>{{ g.DB_STATS.total_queries }} queries in {{ (g.DB_STATS.total_time * 1000)|round(3)}} ms</small></p>
      {% endif %}
    </footer>
    {% endblock stats %}
    {% endblock body %}
    {% block scripts %}
    <!-- Jquery from CDNJS. Need to use 1.x to support the IGB -->
    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.js"></script>
    <!-- $SCRIPT_ROOT is the root of this application, wherever it it -->
    <script type="text/javascript">
      $SCRIPT_ROOT = {{ request.script_root|tojson }};
    </script>
    <script type="text/javascript" src="{{ url_for('static', filename='js/evesrp.min.js') }}"></script>
    {% endblock scripts %}
  </body>
</html>
