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

{% block title %}{{ object.name|default:object }}{% endblock %}

{% block breadcrumbs %}
  <li><a href="{% url 'plugins:netbox_optics:opticalconnection_list' %}">Optical Connections</a></li>
  <li>{{ object.name }}</li>
{% endblock %}

{% block buttons %}
  {% if perms.netbox_optics.change_opticalconnection %}
    <a href="{% url 'plugins:netbox_optics:opticalconnection_edit' pk=object.pk %}" class="btn btn-warning">
      <span class="mdi mdi-pencil" aria-hidden="true"></span> Edit
    </a>
  {% endif %}
  {% if perms.netbox_optics.delete_opticalconnection %}
    <a href="{% url 'plugins:netbox_optics:opticalconnection_delete' pk=object.pk %}?return_url={% if 'opticalspan' in request.META.HTTP_REFERER %}{{ object.span.get_absolute_url }}{% else %}{% url 'plugins:netbox_optics:opticalconnection_list' %}{% endif %}" class="btn btn-danger">
      <span class="mdi mdi-trash-can-outline" aria-hidden="true"></span> Delete
    </a>
  {% endif %}
{% endblock %}

{% block content %}
<div class="row">
    <div class="col-md-12">
        <div class="row">
            <div class="col-md-6">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <strong>Optical Connection</strong>
                    </div>
                    <table class="table table-hover panel-body attr-table">
                        <tr>
                            <td>Name</td>
                            <td>{{ object.name }}</td>
                        </tr>
                        <tr>
                            <td>Optical Span</td>
                            <td><a href="{% url 'plugins:netbox_optics:opticalspan' pk=object.span.pk %}">{{ object.span }}</a></td>
                        </tr>
                        <tr>
                            <td>Wavelength</td>
                            <td><a href="{% url 'plugins:netbox_optics:opticalgridwavelength' pk=object.wavelength.pk %}">{{ object.wavelength.value }} nm</a></td>
                        </tr>
                        <tr>
                            <td>Grid Spacing</td>
                            <td><a href="{% url 'plugins:netbox_optics:opticalgrid' pk=object.span.grid.pk %}">{{ object.span.grid.spacing }} GHz</a></td>
                        </tr>
                        <tr>
                            <td>Mux A</td>
                            <td>
                                {% if object.span.mux_a %}
                                    <a href="{% url 'dcim:device' pk=object.span.mux_a.pk %}">{{ object.span.mux_a }}</a>
                                {% else %}
                                    <span class="text-muted">None</span>
                                {% endif %}
                            </td>
                        </tr>
                        <tr>
                            <td>Mux Z</td>
                            <td>
                                {% if object.span.mux_z %}
                                    <a href="{% url 'dcim:device' pk=object.span.mux_z.pk %}">{{ object.span.mux_z }}</a>
                                {% else %}
                                    <span class="text-muted">None</span>
                                {% endif %}
                            </td>
                        </tr>
                        <tr>
                            <td>Transmit Power</td>
                            <td>{{ object.tx_power }} dBm</td>
                        </tr>
                        <tr>
                            <td>Description</td>
                            <td>{{ object.description|default:"<span class='text-muted'>None</span>" }}</td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="col-md-6">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <strong>Connection Endpoints</strong>
                    </div>
                    <table class="table table-hover panel-body attr-table">
                        <tr>
                            <td>Device A</td>
                            <td>
                                <a href="{% url 'dcim:device' pk=object.interface_a.device.pk %}">{{ object.interface_a.device }}</a>
                                /
                                <a href="{% url 'dcim:interface' pk=object.interface_a.pk %}">{{ object.interface_a }}</a>
                            </td>
                        </tr>
                        <tr>
                            <td>Device Z</td>
                            <td>
                                <a href="{% url 'dcim:device' pk=object.interface_z.device.pk %}">{{ object.interface_z.device }}</a>
                                /
                                <a href="{% url 'dcim:interface' pk=object.interface_z.pk %}">{{ object.interface_z }}</a>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
