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

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

{% block content %}
    <div class="col-lg-12">
        <h1 class="page-header text-center">{% trans "Personal Applications" %}
            <div class="text-right">
                {% if create %}
                    <a href="{% url 'hrapplications:create_view' %}">
                        <button type="button" class="btn btn-success">{% trans "Create Application" %}</button>
                    </a>
                {% else %}
                    <button type="button" class="btn btn-success" disabled>{% trans "Create Application" %}</button>
                {% endif %}
            </div>
        </h1>
        {% if personal_apps %}
            <div class="panel panel-default">
                <table class="table table-condensed">
                    <tr>
                        <th class="text-center">{% trans "Username" %}</th>
                        <th class="text-center">{% trans "Corporation" %}
                        <th class="text-center">{% trans "Status" %}</th>
                        <th class="text-center">{% trans "Actions" %}</th>
                    </tr>
                    {% for personal_app in personal_apps %}
                        <tr>
                            <td class="text-center">{{ personal_app.user.username }}</td>
                            <td class="text-center">{{ personal_app.form.corp.corporation_name }}</td>
                            <td class="text-center">
                                {% if personal_app.approved == None %}
                                    <div class="label label-warning">{% trans "Pending" %}</div>
                                {% elif  personal_app.approved == True %}
                                    <div class="label label-success">{% trans "Approved" %}</div>
                                {% else %}
                                    <div class="label label-danger">{% trans "Rejected" %}</div>
                                {% endif %}
                            </td>
                            <td class="text-center">
                                <a href="{% url 'hrapplications:personal_view' personal_app.id %}"
                                   class="btn btn-primary">
                                    <span class="glyphicon glyphicon-eye-open"></span>
                                </a>

                                {% if personal_app.approved == None %}
                                    <a href="{% url 'hrapplications:personal_removal' personal_app.id %}"
                                       class="btn btn-danger">
                                        <span class="glyphicon glyphicon-remove"></span>
                                    </a>
                                {% endif %}
                            </td>
                        </tr>
                    {% endfor %}
                </table>
            </div>
        {% endif %}
        {% if perms.auth.human_resources %}
            <h1 class="page-header text-center">{% trans "Application Management" %}
                <div class="text-right">
                    <!-- Button trigger modal -->
                    <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#myModal">
                        {% trans "Search Applications" %}
                    </button>
                </div>
            </h1>
            <ul class="nav nav-tabs">
                <li class="active"><a data-toggle="tab" href="#pending">{% trans "Pending" %}</a></li>
                <li><a data-toggle="tab" href="#reviewed">{% trans "Reviewed" %}</a></li>
            </ul>
            <div class="tab-content">
                <div id="pending" class="tab-pane fade in active panel panel-default">
                    <div class="panel-body">
                        {% if applications %}
                            <table class="table">
                                <tr>
                                    <th class="text-center">{% trans "Date" %}</th>
                                    <th class="text-center">{% trans "Username" %}</th>
                                    <th class="text-center">{% trans "Main Character" %}</th>
                                    <th class="text-center">{% trans "Corporation" %}</th>
                                    <th class="text-center">{% trans "Status" %}</th>
                                    <th class="text-center">{% trans "Actions" %}</th>
                                </tr>
                                {% for app in applications %}
                                    <tr>
                                        <td class="text-center">{{ app.created }}</td>
                                        <td class="text-center">{{ app.user.username }}</td>
                                        <td class="text-center">{{ app.main_character }}</td>
                                        <td class="text-center">{{ app.form.corp.corporation_name }}</td>
                                        <td class="text-center">
                                            {% if app.approved == None %}
                                                {% if app.reviewer_str %}
                                                    <div class="label label-info">{% trans "Reviewer:" %} {{ app.reviewer_str }}</div>
                                                {% else %}
                                                    <div class="label label-warning">{% trans "Pending" %}</div>
                                                {% endif %}
                                            {% elif  app.approved == True %}
                                                <div class="label label-success">{% trans "Approved" %}</div>
                                            {% else %}
                                                <div class="label label-danger">{% trans "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>
                        {% else %}
                            <div class="alert alert-warning text-center">{% trans "No pending applications." %}</div>
                        {% endif %}
                    </div>
                </div>
                <div id="reviewed" class="tab-pane fade panel panel-default">
                    <div class="panel-body">
                        {% if finished_applications %}
                            <table class="table">
                                <tr>
                                    <th class="text-center">{% trans "Date" %}</th>
                                    <th class="text-center">{% trans "Username" %}</th>
                                    <th class="text-center">{% trans "Main Character" %}</th>
                                    <th class="text-center">{% trans "Corporation" %}</th>
                                    <th class="text-center">{% trans "Status" %}</th>
                                    <th class="text-center">{% trans "Actions" %}</th>
                                </tr>
                                {% for app in finished_applications %}
                                    <tr>
                                        <td class="text-center">{{ app.created }}</td>
                                        <td class="text-center">{{ app.user.username }}</td>
                                        <td class="text-center">{{ app.main_character }}</td>
                                        <td class="text-center">{{ app.form.corp.corporation_name }}</td>
                                        <td class="text-center">
                                            {% if app.approved == None %}
                                                {% if app.reviewer_str %}
                                                    <div class="label label-info">{% trans "Reviewer:" %} {{ app.reviewer_str }}</div>
                                                {% else %}
                                                    <div class="label label-warning">{% trans "Pending" %}</div>
                                                {% endif %}
                                            {% elif  app.approved == True %}
                                                <div class="label label-success">{% trans "Approved" %}</div>
                                            {% else %}
                                                <div class="label label-danger">{% trans "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>
                                            {% if perms.hrapplications.delete_application %}
                                                <a href="{% url 'hrapplications:remove' app.id %}"
                                                    class="btn btn-danger">
                                                    <span class="glyphicon glyphicon-remove"></span>
                                                </a>
                                            {% endif %}
                                        </td>
                                    </tr>
                                {% endfor %}
                            </table>
                        {% else %}
                            <div class="alert alert-warning text-center">{% trans "No reviewed applications." %}</div>
                        {% endif %}
                    </div>
                </div>
            </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">{% trans "Close" %}</span></button>
                        <h4 class="modal-title" id="myModalLabel">{% trans "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">{% trans "Search" %}</button>
                        </form>
                    </div>
                    <div class="modal-footer">
                    </div>
                </div>
            </div>
        </div>
    {% endif %}
{% endblock content %}
