{% extends "allianceauth/base-bs5.html" %}

{% load i18n %}
{% load humanize %}

{% block page_title %}
    {% translate "SRP Management" %}
{% endblock page_title %}

{% block header_nav_brand %}
    {% translate "Ship Replacement Program" %}
{% endblock header_nav_brand %}

{% block header_nav_collapse_left %}
    {% if perms.auth.srp_management %}
        <li class="nav-item">
            <a class="nav-link" href="{% url 'srp:all' %}">
                {% translate "View All" %}
            </a>
        </li>
    {% endif %}
{% endblock header_nav_collapse_left %}
{% block header_nav_collapse_right %}
    {% if perms.srp.add_srpfleetmain or perms.auth.srp_management %}
        {% translate "Add SRP Fleet" as nav_item_title %}
        {% url "srp:add" as nav_item_link %}
        {% include "framework/header/nav-collapse-button.html" with btn_modifier="success" url=nav_item_link title=nav_item_title fa_icon="fa-solid fa-plus" icon_on_mobile=True %}
    {% endif %}
{% endblock header_nav_collapse_right %}
{% block content %}
    <div>
        <div class="alert alert-info" role="alert">
            <div class="text-end">
                <b>{% translate "Total ISK Cost:" %} {{ totalcost | intcomma }}</b>
            </div>
        </div>

        {% if srpfleets %}
            <div class="table-responsive">
                <table class="table">
                    <tr>
                        <th>{% translate "Fleet Name" %}</th>
                        <th>{% translate "Fleet Time" %}</th>
                        <th>{% translate "Fleet Doctrine" %}</th>
                        <th>{% translate "Fleet Commander" %}</th>
                        <th>{% translate "Fleet AAR" %}</th>
                        <th>{% translate "Fleet SRP Code" %}</th>
                        <th>{% translate "Fleet ISK Cost" %}</th>
                        <th>{% translate "SRP Status" %}</th>
                        <th>{% translate "Pending Requests" %}</th>
                        <th style="width: 110px;">{% translate "Actions" %}</th>
                    </tr>

                    {% for srpfleet in srpfleets %}
                        <tr>
                            <td>
                                {{ srpfleet.fleet_name }}
                            </td>
                            <td>{{ srpfleet.fleet_time | date:"Y-m-d H:i" }}</td>
                            <td>{{ srpfleet.fleet_doctrine }}</td>
                            <td>
                                <div class="badge text-bg-success">
                                    {{ srpfleet.fleet_commander.character_name }}
                                </div>
                            </td>
                            <td>
                                {% if srpfleet.fleet_srp_aar_link %}
                                    <a href="{{ srpfleet.fleet_srp_aar_link }}" target="_blank" class="badge text-bg-primary">{% translate "Link" %}</a>
                                {% endif %}
                            </td>
                            <td>
                                {% if srpfleet.fleet_srp_code %}
                                    <a class="badge text-bg-warning" href="{% url 'srp:request' srpfleet.fleet_srp_code %}">{{ srpfleet.fleet_srp_code }}</a>
                                {% else %}
                                    <div class="badge text-bg-danger">
                                        {% translate "Disabled" %}
                                    </div>
                                {% endif %}
                            </td>
                            <td class="text-end">{{ srpfleet.total_cost | intcomma }} ISK</td>

                            <td>
                                {% if srpfleet.fleet_srp_status == "" %}
                                    <div class="badge text-bg-warning">
                                        {% translate "Pending" %}
                                    </div>
                                {% else %}
                                    <div class="badge text-bg-success">
                                        {% translate "Completed" %}
                                    </div>
                                {% endif %}
                            </td>
                            <td>
                                <div class="badge text-bg-warning">{{ srpfleet.pending_requests }}</div>
                            </td>
                            <td class="text-end text-nowrap">
                                <a href="{% url 'srp:fleet' srpfleet.id %}" class="btn btn-primary btn-sm m-1" title="View">
                                    <i class="fa-solid fa-eye"></i>
                                </a>

                                {% if perms.auth.srp_management %}
                                    <a href="{% url 'srp:edit' srpfleet.id %}" class="btn btn-info btn-sm m-1" title="Edit">
                                        <i class="fa-solid fa-pen-to-square fa-fw"></i>
                                    </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 btn-sm m-1" title="Remove">
                                        <i class="fa-solid fa-trash-can fa-fw"></i>
                                    </a>

                                    {% if srpfleet.fleet_srp_code %}
                                        <a href="{% url 'srp:disable' srpfleet.id %}" class="btn btn-warning btn-sm m-1" title="Disable">
                                            <i class="fa-solid fa-ban fa-fw"></i>
                                        </a>
                                    {% else %}
                                        <a href="{% url 'srp:enable' srpfleet.id %}" class="btn btn-success btn-sm m-1" title="Enable">
                                            <i class="fa-solid fa-check fa-fw"></i>
                                        </a>
                                    {% endif %}
                                {% endif %}
                            </td>
                        </tr>
                    {% endfor %}
                </table>
            </div>
        {% else %}
            <div class="alert alert-warning text-center">
                {% translate "No SRP fleets created." %}
            </div>
        {% endif %}
    </div>
{% endblock content %}
