{% extends "fitcheck/base.html" %}

{% load i18n %}

{% block fitcheck_content %}
    <div class="fc-toolbar">
        <div class="fc-eyebrow">
            {% translate "Fitting standards live independently - assign them to doctrines from each doctrine's page." %}
        </div>
        <div class="ms-auto d-flex gap-2">
            <a class="btn btn-warning btn-sm" href="{% url 'fitcheck:stale_recheck_page' %}">
                <i class="fa-solid fa-rotate"></i> {% translate "Recheck Stale Submissions" %}
            </a>
            <a class="btn btn-primary btn-sm" href="{% url 'fitcheck:standard_import' %}">
                <i class="fa-solid fa-file-import"></i> {% translate "New Fitting (EFT Import)" %}
            </a>
        </div>
    </div>

    <div class="fc-finding-section fc-sec-LOW">
        <div class="fc-finding-section-head">
            <i class="fa-solid fa-screwdriver-wrench"></i>
            <span class="ms-1">{% translate "Fitting standards" %}</span>
        </div>
        <div class="card-body p-0">
            <table class="table table-hover align-middle mb-0 fc-table-fixed">
                <colgroup>
                    <col style="width: 18%"><col style="width: 12%"><col style="width: 20%"><col style="width: 12%"><col style="width: 6%"><col style="width: 9%"><col style="width: 9%"><col style="width: 5%"><col style="width: 9%">
                </colgroup>
                <thead>
                    <tr>
                        <th>{% translate "Fitting" %}</th>
                        <th>{% translate "Hull" %}</th>
                        <th>{% translate "Doctrines" %}</th>
                        <th>{% translate "Policy" %}</th>
                        <th>{% translate "Version" %}</th>
                        <th>{% translate "Created" %}</th>
                        <th>{% translate "Updated" %}</th>
                        <th>{% translate "Active" %}</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    {% for fit in fits %}
                        <tr>
                            <td>
                                <img class="fc-module-icon" width="28" height="28" alt=""
                                     src="https://images.evetech.net/types/{{ fit.ship_type_id }}/icon?size=32">
                                <a href="{% url 'fitcheck:fit_detail' fit.pk %}"><strong>{{ fit.name }}</strong></a>
                            </td>
                            <td class="text-muted">{{ fit.ship_type.name }}</td>
                            <td>
                                {% for doctrine in fit.doctrines.all %}
                                    <a class="fc-chip me-1" href="{% url 'fitcheck:doctrine_detail' doctrine.pk %}">{{ doctrine.name }}</a>
                                {% empty %}
                                    <span class="text-muted small">{% translate "standalone" %}</span>
                                {% endfor %}
                            </td>
                            <td class="small text-muted">
                                {% if fit.compliance_policy %}
                                    <i class="fa-solid fa-scale-balanced me-1"></i>{{ fit.compliance_policy.name }}
                                {% else %}
                                    {{ fit.get_default_policy_display }}
                                {% endif %}
                            </td>
                            <td>{% translate "Fit" %} v{{ fit.version }}</td>
                            <td class="small text-muted text-nowrap">{{ fit.created_at|date:"Y-m-d" }}</td>
                            <td class="small text-muted text-nowrap">
                                {% with updated=fit.bom_updated_at|default:fit.updated_at %}{{ updated|date:"Y-m-d" }}{% endwith %}
                            </td>
                            <td>
                                {% if fit.is_active %}
                                    <i class="fa-solid fa-check text-success"></i>
                                {% else %}
                                    <i class="fa-solid fa-xmark text-danger"></i>
                                {% endif %}
                            </td>
                            <td class="text-end text-nowrap">
                                <a class="btn btn-sm btn-warning" title="{% translate 'Module policies and exceptions' %}"
                                   href="{% url 'fitcheck:manage_fit_items' fit.pk %}">
                                    <i class="fa-solid fa-sliders"></i>
                                </a>
                                <a class="btn btn-sm btn-warning" title="{% translate 'Settings' %}"
                                   href="{% url 'fitcheck:manage_fit_settings' fit.pk %}">
                                    <i class="fa-solid fa-gear"></i>
                                </a>
                                <form class="d-inline" method="post" action="{% url 'fitcheck:fit_delete' fit.pk %}"
                                      onsubmit="return confirm('{% translate "Delete this fitting and all its submissions?" %}')">
                                    {% csrf_token %}
                                    <button class="btn btn-sm btn-danger" type="submit" title="{% translate 'Delete' %}">
                                        <i class="fa-solid fa-trash"></i>
                                    </button>
                                </form>
                            </td>
                        </tr>
                    {% empty %}
                        <tr>
                            <td colspan="9" class="p-4 text-center text-muted">
                                {% translate "No fitting standards yet - import one from EFT." %}
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
{% endblock %}
