{% extends "layout.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% from "bootstrap/pagination.html" import render_pagination %}

{% block content %}

<div class="container-fluid">
    {% if current_user.main_character and (current_user.has_role("recruiter") or current_user.has_role("admin") or current_user.has_role("reviewer")) %}
        <h1 class="page-header text-center">Application Queue</h1>
        <div class="row">
            <div class="col-sm-6">
                {{ search_form.hidden_tag() }}
                {{ wtf.quick_form(search_form) }}
                <br>
            </div>
            <div class="col-sm-6">
                <a class="btn btn-danger" href="{{ url_for('recruit.application_queue', page=1, filter=0) }}">
                    Current Queue
                </a>
                <a class="btn btn-danger" href="{{ url_for('recruit.application_queue', page=1, filter=1) }}">
                    All Apps
                </a>
                <a class="btn btn-danger" href="{{ url_for('recruit.application_queue', page=1, filter=2) }}">
                    My Apps
                </a>
                <br>
                {% if recruiter_queue.pages > 1 %}
                    {{ render_pagination(recruiter_queue) }}
                {% endif %}
            </div>
        </div>
        <div class="table-responsive">
            <table class="table table-bordered table-striped table-hover">
                <thead>
                    <tr>
                        <th class="text-center">ID</th>
                        <th class="text-center">Main <div class="alert-warning" role="alert">Alt App</div></th>
                        {#<th class="text-center">Characters</th>#}
                        <th class="text-center">Created</th>
                        <th class="text-center">Last Update Time</th>
                        <th class="text-center">Status</th>
                        <th class="text-center">Comments</th>
                        <th class="text-center">Actions</th>
                    </tr>
                </thead>
                <tbody>
                {% for queue in recruiter_queue.items %}
                    <tr>
                        <td data-title="ID" class="text-center">{{ queue.id }}</td>
                        <td data-title="Main" class="text-center">
                            {% if queue.alt_application %}
                                <div class="alert-warning" role="alert">{{ queue.main_character_name }}</div>
                            {% else %}
                                {{ queue.main_character_name }}
                            {% endif %}
                        </td>
                        {#<td data-title="Character" class="text-center">{{ queue.characters[0].character_name}}{% if queue.characters|length > 1 %}, ...{% endif %}</td>  Could be useful but table is getting cramped #}
                        <td data-title="Created" class="text-center">{{ queue.created_time.strftime('%Y/%m/%d') }}</td>
                        <td data-title="Last Update Time" class="text-center">{{ queue.last_update_time.strftime('%Y/%m/%d %H:%M:%S') }}</td>
                        <td data-title="Status" class="text-center">
                            {% if queue.approved_denied == "New" %}
                                <div class="alert-warning" role="alert">New</div>

                            {% elif queue.approved_denied == "Approved" %}
                                <div class="alert-success" role="alert">Approved</div>

                            {% elif queue.approved_denied == "Rejected" %}
                                <div class="alert-danger" role="alert">Rejected</div>

                            {% elif queue.approved_denied == "Undecided" %}
                                <div class="alert-info" role="alert">In Progress</div>

                            {% elif queue.approved_denied == "Awaiting Response" %}
                                <div class="alert-info" role="alert">Awaiting Response</div>

                            {% elif queue.approved_denied == "Needs Director Review" %}
                                <div class="alert-danger" role="alert">Needs Director Review</div>

                            {% elif queue.approved_denied == "Role Stasis" %}
                                <div class="alert-info" role="alert">Role Stasis</div>

                            {% elif queue.approved_denied == "Closed" %}
                                <div class="alert-danger" role="alert">Closed</div>

                            {% elif queue.approved_denied == "Needs Processing" %}
                                <div class="alert-warning" role="alert">Needs Processing</div>

                            {% elif queue.approved_denied == "Missing In-Game" %}
                                <div class="alert-info" role="alert">In-Game App</div>

                            {% endif %}
                        </td>
                        <td data-title="# Comments" class="text-center">{{ queue.hr_comments|length }}</td>
                        <td data-title="Actions" class="text-center">
                            <a class="btn btn-primary" href="{{ url_for('recruit.application_view', application_id=queue.id) }}">
                                <span class="glyphicon glyphicon-eye-open"></span>
                            </a>
                            {% if queue.training %}
                                <a class="btn btn-success btn-ok" href="{{ url_for('recruit.application_interact', application_id=queue.id, action='training') }}">
                                    <span class="glyphicon glyphicon-education"></span>
                                </a>
                            {% else %}
                                <a class="btn btn-danger btn-ok" href="{{ url_for('recruit.application_interact', application_id=queue.id, action='training') }}">
                                    <span class="glyphicon glyphicon-education"></span>
                                </a>
                            {% endif %}
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    {% else %}
        <div class="alert alert-danger" role="alert">No primary character set, Please set a primary character</div>
    {% endif %}
</div>

{% endblock %}
