{% load helpers %}

<div class="card">
    <h5 class="card-header d-flex justify-content-between align-items-center">
        RIR Networks
        {% if show_sync_button and aggregate_pk %}
        <form method="post" action="{% url 'plugins:netbox_rir_manager:aggregate_sync' aggregate_pk %}" class="d-inline">
            {% csrf_token %}
            <button type="submit" class="btn btn-sm btn-info" title="Sync this aggregate from ARIN">
                <i class="mdi mdi-sync"></i> Sync from ARIN
            </button>
        </form>
        {% elif show_sync_button and prefix_pk %}
        <form method="post" action="{% url 'plugins:netbox_rir_manager:prefix_sync' prefix_pk %}" class="d-inline">
            {% csrf_token %}
            <button type="submit" class="btn btn-sm btn-info" title="Sync this prefix from ARIN">
                <i class="mdi mdi-sync"></i> Sync from ARIN
            </button>
        </form>
        {% endif %}
    </h5>
    {% if rir_networks %}
    <table class="table table-hover attr-table">
        <thead>
            <tr>
                <th>Handle</th>
                <th>Net Name</th>
                <th>Organization</th>
                <th>Last Synced</th>
            </tr>
        </thead>
        <tbody>
            {% for net in rir_networks %}
            <tr>
                <td><a href="{{ net.get_absolute_url }}">{{ net.handle }}</a></td>
                <td>{{ net.net_name }}</td>
                <td>
                    {% if net.organization %}
                        <a href="{{ net.organization.get_absolute_url }}">{{ net.organization.handle }}</a>
                    {% else %}
                        {{ ''|placeholder }}
                    {% endif %}
                </td>
                <td>{{ net.last_synced|placeholder }}</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
    {% else %}
    <div class="card-body text-muted">
        No RIR networks linked.{% if show_sync_button %} Click "Sync from ARIN" to fetch.{% endif %}
    </div>
    {% endif %}
</div>
