{% extends 'dcim/device_component.html' %}
{% load helpers %}
{% load plugins %}

{% block content %}
    <div class="row">
        <div class="col-md-6">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <strong>Interface</strong>
                </div>
                <table class="table table-hover panel-body attr-table">
                    <tr>
                        <td>Device</td>
                        <td>
                            <a href="{{ instance.device.get_absolute_url }}">{{ instance.device }}</a>
                        </td>
                    </tr>
                    <tr>
                        <td>Name</td>
                        <td>{{ instance.name }}</td>
                    </tr>
                    <tr>
                        <td>Label</td>
                        <td>{{ instance.label|placeholder }}</td>
                    </tr>
                    <tr>
                        <td>Type</td>
                        <td>{{ instance.get_type_display }}</td>
                    </tr>
                    <tr>
                        <td>Enabled</td>
                        <td>
                            {% if instance.enabled %}
                                <span class="text-success"><i class="fa fa-check"></i></span>
                            {% else %}
                                <span class="text-danger"><i class="fa fa-close"></i></span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td>LAG</td>
                        <td>
                            {% if instance.lag%}
                                <a href="{{ instance.lag.get_absolute_url }}">{{ instance.lag }}</a>
                            {% else %}
                                <span class="text-muted">None</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td>Description</td>
                        <td>{{ instance.description|placeholder }} </td>
                    </tr>
                    <tr>
                        <td>MTU</td>
                        <td>{{ instance.mtu|placeholder }}</td>
                    </tr>
                    <tr>
                        <td>MAC Address</td>
                        <td><span class="text-monospace">{{ instance.mac_address|placeholder }}</span></td>
                    </tr>
                    <tr>
                        <td>802.1Q Mode</td>
                        <td>{{ instance.get_mode_display }}</td>
                    </tr>
                </table>
            </div>
            {% include 'extras/inc/tags_panel.html' with tags=instance.tags.all %}
            {% plugin_left_page instance %}
        </div>
        <div class="col-md-6">
            {% if instance.is_connectable %}
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <strong>Connection</strong>
                    </div>
                    {% if instance.cable %}
                        <table class="table table-hover panel-body attr-table">
                            {% if connected_interface %}
                                <tr>
                                    <td>Device</td>
                                    <td>
                                        <a href="{{ connected_interface.device.get_absolute_url }}">{{ connected_interface.device }}</a>
                                    </td>
                                </tr>
                                <tr>
                                    <td>Name</td>
                                    <td>
                                        <a href="{{ connected_interface.get_absolute_url }}">{{ connected_interface.name }}</a>
                                    </td>
                                </tr>
                                <tr>
                                    <td>Type</td>
                                    <td>{{ connected_interface.get_type_display }}</td>
                                </tr>
                                <tr>
                                    <td>Enabled</td>
                                    <td>
                                        {% if connected_interface.enabled %}
                                            <span class="text-success"><i class="fa fa-check"></i></span>
                                        {% else %}
                                            <span class="text-danger"><i class="fa fa-close"></i></span>
                                        {% endif %}
                                    </td>
                                </tr>
                                <tr>
                                    <td>LAG</td>
                                    <td>
                                        {% if connected_interface.lag%}
                                            <a href="{{ connected_interface.lag.get_absolute_url }}">{{ connected_interface.lag }}</a>
                                        {% else %}
                                            <span class="text-muted">None</span>
                                        {% endif %}
                                    </td>
                                </tr>
                                <tr>
                                    <td>Description</td>
                                    <td>{{ connected_interface.description|placeholder }}</td>
                                </tr>
                                <tr>
                                    <td>MTU</td>
                                    <td>{{ connected_interface.mtu|placeholder }}</td>
                                </tr>
                                <tr>
                                    <td>MAC Address</td>
                                    <td>{{ connected_interface.mac_address|placeholder }}</td>
                                </tr>
                                <tr>
                                    <td>802.1Q Mode</td>
                                    <td>{{ connected_interface.get_mode_display }}</td>
                                </tr>
                            {% elif connected_circuittermination %}
                                {% with ct=connected_circuittermination %}
                                    <tr>
                                        <td>Provider</td>
                                        <td><a href="{{ ct.circuit.provider.get_absolute_url }}">{{ ct.circuit.provider }}</a></td>
                                    </tr>
                                    <tr>
                                        <td>Circuit</td>
                                        <td><a href="{{ ct.circuit.get_absolute_url }}">{{ ct.circuit }}</a></td>
                                    </tr>
                                    <tr>
                                        <td>Side</td>
                                        <td>{{ ct.term_side }}</td>
                                    </tr>
                                {% endwith %}
                            {% endif %}
                            <tr>
                                <td>Cable</td>
                                <td>
                                    <a href="{{ instance.cable.get_absolute_url }}">{{ instance.cable }}</a>
                                    <a href="{% url 'dcim:interface_trace' pk=instance.pk %}" class="btn btn-primary btn-xs" title="Trace">
                                        <i class="fa fa-share-alt" aria-hidden="true"></i>
                                    </a>
                                </td>
                            </tr>
                            <tr>
                                <td>Connection Status</td>
                                <td>
                                    {% if instance.connection_status %}
                                        <span class="label label-success">{{ instance.get_connection_status_display }}</span>
                                    {% else %}
                                        <span class="label label-info">{{ instance.get_connection_status_display }}</span>
                                    {% endif %}
                                </td>
                            </tr>
                        </table>
                    {% else %}
                        <div class="panel-body text-muted">
                            Not connected
                        </div>
                    {% endif %}
                </div>
            {% endif %}
            {% if instance.is_lag %}
                <div class="panel panel-default">
                    <div class="panel-heading"><strong>LAG Members</strong></div>
                    <table class="table table-hover table-headings panel-body">
                        <thead>
                            <tr>
                                <th>Parent</th>
                                <th>Interface</th>
                                <th>Type</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for member in instance.member_interfaces.all %}
                                <tr>
                                    <td>
                                        <a href="{{ member.device.get_absolute_url }}">{{ member.device }}</a>
                                    </td>
                                    <td>
                                        <a href="{{ member.get_absolute_url }}">{{ member }}</a>
                                    </td>
                                    <td>
                                        {{ member.get_type_display }}
                                    </td>
                                </tr>
                            {% empty %}
                                <tr>
                                    <td colspan="3" class="text-muted">No member interfaces</td>
                                </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            {% endif %}
            {% plugin_right_page instance %}
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            {% include 'panel_table.html' with table=ipaddress_table heading="IP Addresses" %}
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            {% include 'panel_table.html' with table=vlan_table heading="VLANs" %}
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            {% plugin_full_width_page instance %}
        </div>
    </div>
{% endblock %}
