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

{% block content %}
<div class="row">
    <div class="col col-md-6">
        <div class="card">
            <h5 class="card-header">SCION Link Assignment</h5>
            <div class="card-body">
                <table class="table table-hover attr-table">
                    <tr>
                        <th scope="row">ISD-AS</th>
                        <td><a href="{% url 'plugins:netbox_scion:isdas' object.isd_as.pk %}">{{ object.isd_as }}</a></td>
                    </tr>
                    <tr>
                        <th scope="row">Core Node</th>
                        <td>{{ object.core }}</td>
                    </tr>
                    <tr>
                        <th scope="row">Interface ID</th>
                        <td>{{ object.interface_id }}</td>
                    </tr>
                    <tr>
                        <th scope="row">Relationship</th>
                        <td>
                            {% if object.relationship == 'CORE' %}
                                <span class="badge" style="background-color:#4f46e5;color:#fff;font-weight:500;">Core</span>
                            {% elif object.relationship == 'CHILD' %}
                                <span class="badge" style="background-color:#14b8a6;color:#fff;font-weight:500;">Child</span>
                            {% elif object.relationship == 'PARENT' %}
                                <span class="badge" style="background-color:#3b82f6;color:#fff;font-weight:500;">Parent</span>
                            {% else %}
                                {{ object.get_relationship_display }}
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Status</th>
                        <td>
                            {% if object.status == 'ACTIVE' %}
                                <span class="badge" style="background-color:#28a745;color:#fff;font-weight:500;">Active</span>
                            {% elif object.status == 'RESERVED' %}
                                <span class="badge" style="background-color:#ffc107;color:#000;font-weight:500;">Reserved</span>
                            {% elif object.status == 'PLANNED' %}
                                <span class="badge" style="background-color:#6c757d;color:#fff;font-weight:500;">Planned</span>
                            {% else %}
                                {{ object.get_status_display }}
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Peer Name</th>
                        <td>{{ object.peer_name }}</td>
                    </tr>
                    <tr>
                        <th scope="row">Peer</th>
                        <td>{{ object.peer }}</td>
                    </tr>
                    <tr>
                        <th scope="row">Local Underlay</th>
                        <td>
                            {% if object.local_underlay %}{{ object.local_underlay }}{% else %}<span class="text-muted">—</span>{% endif %}
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Peer Underlay</th>
                        <td>
                            {% if object.peer_underlay %}{{ object.peer_underlay }}{% else %}<span class="text-muted">—</span>{% endif %}
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Ticket</th>
                        <td>
                            {% if object.ticket %}
                                {% with url=object.get_ticket_url %}
                                    {% if url %}
                                        <a href="{{ url }}" target="_blank" rel="noopener noreferrer">{{ object.ticket }}</a>
                                    {% else %}
                                        {{ object.ticket }}
                                    {% endif %}
                                {% endwith %}
                            {% else %}
                                <span class="text-muted">Not specified</span>
                            {% endif %}
                        </td>
                    </tr>
                    {% if object.description %}
                    <tr>
                        <th scope="row">Description</th>
                        <td>{{ object.description|linebreaksbr }}</td>
                    </tr>
                    {% endif %}
                </table>
            </div>
        </div>
        {% include 'inc/panels/custom_fields.html' %}
        {% include 'inc/panels/tags.html' %}
        {% include 'inc/panels/comments.html' %}
    </div>
    <div class="col col-md-6">
        <div class="card">
            <h5 class="card-header">Related Information</h5>
            <div class="card-body">
                <table class="table table-hover">
                    <tr>
                        <th scope="row">Organization</th>
                        <td>
                            {% if object.isd_as.organization %}
                                <a href="{% url 'plugins:netbox_scion:organization' object.isd_as.organization.pk %}">{{ object.isd_as.organization }}</a>
                            {% else %}
                                —
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">ISD-AS</th>
                        <td><a href="{% url 'plugins:netbox_scion:isdas' object.isd_as.pk %}">{{ object.isd_as.isd_as }}</a></td>
                    </tr>
                    {% if object.isd_as.appliances %}
                    <tr>
                        <th scope="row">Available Appliances</th>
                        <td>
                            {% for appliance in object.isd_as.appliances %}
                                <span class="badge badge-secondary{% if appliance == object.core %} badge-primary{% endif %}">{{ appliance }}</span>
                            {% endfor %}
                        </td>
                    </tr>
                    {% endif %}
                </table>
            </div>
        </div>
    </div>
</div>
{% endblock %}
