{% extends 'generic/object.html' %}
{% load helpers %}
{% load i18n %}

{% block content %}
<div class="row mb-3">
    <div class="col col-md-12">
        <div class="card">
            <h5 class="card-header">{% trans "Apply Splice Plan" %}: {{ object.name }}</h5>
            <div class="card-body">
                <p>{% trans "Review the changes below before applying." %}</p>

                {% if diff %}
                {% for tray_id, tray_diff in diff.items %}
                <h6>{% trans "Tray" %} #{{ tray_id }}</h6>
                <table class="table table-sm">
                    <thead>
                        <tr>
                            <th>{% trans "Action" %}</th>
                            <th>{% trans "Fiber A" %}</th>
                            <th>{% trans "Fiber B" %}</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for pair in tray_diff.add %}
                        <tr class="table-success">
                            <td><span class="badge text-bg-success">{% trans "Add" %}</span></td>
                            <td>{{ pair.0 }}</td>
                            <td>{{ pair.1 }}</td>
                        </tr>
                        {% endfor %}
                        {% for pair in tray_diff.remove %}
                        <tr class="table-danger">
                            <td><span class="badge text-bg-danger">{% trans "Remove" %}</span></td>
                            <td>{{ pair.0 }}</td>
                            <td>{{ pair.1 }}</td>
                        </tr>
                        {% endfor %}
                        {% for pair in tray_diff.unchanged %}
                        <tr class="table-secondary">
                            <td><span class="badge text-bg-secondary">{% trans "Unchanged" %}</span></td>
                            <td>{{ pair.0 }}</td>
                            <td>{{ pair.1 }}</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
                {% endfor %}
                {% else %}
                <p class="text-muted">{% trans "No changes to apply." %}</p>
                {% endif %}

                <form method="post" action="{% url 'plugins:netbox_fms:spliceplan_apply' pk=object.pk %}">
                    {% csrf_token %}
                    <button type="submit" class="btn btn-success">
                        <i class="mdi mdi-check-circle"></i> {% trans "Apply Changes" %}
                    </button>
                    <a href="{{ object.get_absolute_url }}" class="btn btn-secondary">{% trans "Cancel" %}</a>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}
