{% extends "allianceauth/base.html" %}
{% load bootstrap %}
{% load static %}
{% load i18n %}

{% block page_title %}{% translate "HR Application Management" %}{% endblock page_title %}
{% block extra_css %}{% endblock extra_css %}

{% block content %}
    <div class="col-lg-12">
        {% if perms.auth.human_resources %}
            <h1 class="page-header text-center">{% translate "Application Search Results" %}
                <div class="text-right">
                    <!-- Button trigger modal -->
                    <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#myModal">
                        {% translate "Search Applications" %}
                    </button>
                </div>
            </h1>
            <div class="container-fluid">
                <table class="table table-bordered">
                    <tr>
                        <th class="text-center">{% translate "Application ID" %}</th>
                        <th class="text-center">{% translate "Username" %}</th>
                        <th class="text-center">{% translate "Main Character" %}</th>
                        <th class="text-center">{% translate "Corporation" %}</th>
                        <th class="text-center">{% translate "Status" %}</th>
                        <th class="text-center">{% translate "Actions" %}</th>
                    </tr>
                    {% for app in applications %}
                        <tr>
                            <td class="text-center">{{ app.id }}</td>
                            <td class="text-center">{{ app.user }}</td>
                            <td class="text-center">{{ app.main_character }}</td>
                            <td class="text-center">{{ app.form.corp }}</td>
                            <td class="text-center">
                                {% if app.approved == None %}
                                    <div class="label label-warning">{% translate "Pending" %}</div>
                                {% elif  app.approved == True %}
                                    <div class="label label-success">{% translate "Approved" %}</div>
                                {% else %}
                                    <div class="label label-danger">{% translate "Rejected" %}</div>
                                {% endif %}
                            </td>
                            <td class="text-center">
                                <a href="{% url 'hrapplications:view' app.id %}" class="btn btn-primary">
                                    <span class="glyphicon glyphicon-eye-open"></span>
                                </a>
                            </td>
                        </tr>
                    {% endfor %}
                </table>
            </div>
        {% endif %}
    </div>

    {% if perms.auth.human_resources %}
        <!-- Modal -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">{% translate "Close" %}</span></button>
                        <h4 class="modal-title" id="myModalLabel">{% translate "Application Search" %}</h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-signin" role="form" action={% url 'hrapplications:search' %} method="POST">
                            {% csrf_token %}
                            {{ search_form|bootstrap }}
                            <br/>
                            <button class="btn btn-lg btn-primary btn-block" type="submit">{% translate "Search" %}</button>
                        </form>
                    </div>
                    <div class="modal-footer">
                    </div>
                </div>
            </div>
        </div>
    {% endif %}
{% endblock content %}
