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

{% load humanize %}

{% block page_title %}{% trans "Srp Management" %}{% endblock page_title %}
{% block extra_css %}{% endblock extra_css %}

{% block content %}
    <div class="col-lg-12">
        <div class="row">
            <h1 class="page-header text-center">{% trans "SRP Management" %}
                <div class="text-right">
                    {% if perms.auth.srp_management %}
                        <a href="{% url 'srp:all' %}" class="btn btn-primary">
                            {% trans "View All" %}
                        </a>
                    {% endif %}
                    {% if perms.srp.add_srpfleetmain or perms.auth.srp_management %}
                        <a href="{% url 'srp:add' %}" class="btn btn-success">
                            {% trans "Add SRP Fleet" %}
                        </a>
                    {% endif %}
                </div>
            </h1>
            <div class="alert alert-info" role="alert">
                <div class="text-right">
                    <b>{% trans "Total ISK Cost:" %} {{ totalcost | intcomma }}</b>
                </div>
            </div>
            {% if srpfleets %}
                <div class="table-responsive">
                    <table class="table">
                        <tr>
                            <th class="text-center">{% trans "Fleet Name" %}</th>
                            <th class="text-center">{% trans "Fleet Time" %}</th>
                            <th class="text-center">{% trans "Fleet Doctrine" %}</th>
                            <th class="text-center">{% trans "Fleet Commander" %}</th>
                            <th class="text-center">{% trans "Fleet AAR" %}</th>
                            <th class="text-center">{% trans "Fleet SRP Code" %}</th>
                            <th class="text-center">{% trans "Fleet ISK Cost" %}</th>
                            <th class="text-center">{% trans "SRP Status" %}</th>
                            <th class="text-center">{% trans "Pending Requests" %}</th>
                            <th width="100px" class="text-center">{% trans "Actions" %}</th>
                        </tr>
                        {% for srpfleet in srpfleets %}
                            <tr>
                                <td class="text-center">
                                    <div class="label label-info">
                                        {{ srpfleet.fleet_name }}
                                    </div>
                                </td>
                                <td class="text-center">{{ srpfleet.fleet_time | date:"Y-m-d H:i" }}</td>
                                <td class="text-center">{{ srpfleet.fleet_doctrine }}</td>
                                <td class="text-center">
                                    <div class="label label-success">
                                        {{ srpfleet.fleet_commander.character_name }}
                                    </div>
                                </td>
                                <td class="text-center">
                                    {%  if srpfleet.fleet_srp_aar_link %}
                                        <a href="{{ srpfleet.fleet_srp_aar_link }}" target="_blank" class="label label-primary">{% trans 'Link' %}</a>
                                    {%  endif %}
                                </td>
                                <td class="text-center">
                                    {% if srpfleet.fleet_srp_code %}
                                        <a class="label label-warning" href="{% url 'srp:request' srpfleet.fleet_srp_code %}">{{ srpfleet.fleet_srp_code }}</a>
                                    {% else %}
                                        <div class="label label-danger">
                                            {% trans "Disabled" %}
                                        </div>
                                    {% endif %}
                                </td>
                                <td class="text-center">ISK: {{ srpfleet.total_cost | intcomma }}</td>

                                <td class="text-center">
                                    {% if srpfleet.fleet_srp_status == "" %}
                                        <div class="label label-warning">
                                            {% trans "Pending" %}
                                        </div>
                                    {% else %}
                                        <div class="label label-success">
                                            {% trans "Completed" %}
                                        </div>
                                    {% endif %}
                                </td>
                                <td class="text-center">
                                    <div class="label label-warning">{{ srpfleet.pending_requests }}</div>
                                </td>
                                <td class="text-center">

                                    <a href="{% url 'srp:fleet' srpfleet.id %}" class="btn btn-primary" title="View">
                                        <span class="glyphicon glyphicon-eye-open"></span>
                                    </a>

                                    {% if perms.auth.srp_management %}
                                        <a href="{% url 'srp:edit' srpfleet.id %}" class="btn btn-info" title="Edit">
                                            <span class="glyphicon glyphicon-pencil"></span>
                                        </a>

                                        <a href="{% url 'srp:remove' srpfleet.id %}" onclick="return confirm('{% trans "Are you sure you want to delete this SRP code and its contents?" %}')" class="btn btn-danger" title="Remove">
                                            <span class="glyphicon glyphicon-trash"></span>
                                        </a>
                                        {% if srpfleet.fleet_srp_code %}
                                            <a href="{% url 'srp:disable' srpfleet.id %}" class="btn btn-warning" title="Disable">
                                                <span class="glyphicon glyphicon-remove-sign"></span>
                                            </a>
                                        {% else %}
                                            <a href="{% url 'srp:enable' srpfleet.id %}" class="btn btn-success" title="Enable">
                                                <span class="glyphicon glyphicon-ok-sign"></span>
                                            </a>
                                        {% endif %}

                                    {% endif %}
                                </td>
                            </tr>
                        {% endfor %}
                    </table>
                </div>
            {% else %}
                <div class="alert alert-warning text-center">
                    {% trans "No SRP fleets created." %}
                </div>
            {% endif %}
        </div>
    </div>

{% endblock content %}
