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

{% load humanize %}

{% block page_title %}{% translate "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">{% translate "SRP Management" %}
                <div class="text-right">
                    {% if perms.auth.srp_management %}
                        <a href="{% url 'srp:all' %}" class="btn btn-primary">
                            {% translate "View All" %}
                        </a>
                    {% endif %}
                    {% if perms.srp.add_srpfleetmain or perms.auth.srp_management %}
                        <a href="{% url 'srp:add' %}" class="btn btn-success">
                            {% translate "Add SRP Fleet" %}
                        </a>
                    {% endif %}
                </div>
            </h1>
            <div class="alert alert-info" role="alert">
                <div class="text-right">
                    <b>{% translate "Total ISK Cost:" %} {{ totalcost | intcomma }}</b>
                </div>
            </div>
            {% if srpfleets %}
                <div class="table-responsive">
                    <table class="table">
                        <tr>
                            <th class="text-center">{% translate "Fleet Name" %}</th>
                            <th class="text-center">{% translate "Fleet Time" %}</th>
                            <th class="text-center">{% translate "Fleet Doctrine" %}</th>
                            <th class="text-center">{% translate "Fleet Commander" %}</th>
                            <th class="text-center">{% translate "Fleet AAR" %}</th>
                            <th class="text-center">{% translate "Fleet SRP Code" %}</th>
                            <th class="text-center">{% translate "Fleet ISK Cost" %}</th>
                            <th class="text-center">{% translate "SRP Status" %}</th>
                            <th class="text-center">{% translate "Pending Requests" %}</th>
                            <th width="100px" class="text-center">{% translate "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">{% translate '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">
                                            {% translate "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">
                                            {% translate "Pending" %}
                                        </div>
                                    {% else %}
                                        <div class="label label-success">
                                            {% translate "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('{% translate "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">
                    {% translate "No SRP fleets created." %}
                </div>
            {% endif %}
        </div>
    </div>

{% endblock content %}
