{% extends "ui/panels/_base.html" %}
{% load helpers i18n %}

{% block panel_content %}
  {% if object.mark_connected %}
    <div class="card-body">
      <span class="text-success"><i class="mdi mdi-check-bold"></i></span>
      {% trans "Marked as connected" %}
    </div>
  {% elif object.cable %}
    <table class="table table-hover attr-table">
      <tr>
        <th scope="row">{% trans "Cable" %}</th>
        <td>
          {{ object.cable|linkify }}
          <a href="{% url 'dcim:interface_trace' pk=object.pk %}" class="btn btn-sm btn-primary" title="{% trans "Trace" %}">
            <i class="mdi mdi-transit-connection-variant" aria-hidden="true"></i>
          </a>
        </td>
      </tr>
      <tr>
        <th scope="row">{% trans "Path status" %}</th>
        <td>
          {% if object.path.is_complete and object.path.is_active %}
            <span class="badge text-bg-success">{% trans "Reachable" %}</span>
          {% else %}
            <span class="badge text-bg-danger">{% trans "Not Reachable" %}</span>
          {% endif %}
        </td>
      </tr>
      <tr>
        <th scope="row">{% trans "Path endpoints" %}</th>
        <td>
          {% for endpoint in object.connected_endpoints %}
            {% if endpoint.parent_object %}
              {{ endpoint.parent_object|linkify }}
              <i class="mdi mdi-chevron-right"></i>
            {% endif %}
            {{ endpoint|linkify }}
            {% if not forloop.last %}<br />{% endif %}
          {% empty %}
            {{ ''|placeholder }}
          {% endfor %}
        </td>
      </tr>
    </table>
  {% elif object.wireless_link %}
    <table class="table table-hover attr-table">
      <tr>
        <th scope="row">{% trans "Wireless Link" %}</th>
        <td>
          {{ object.wireless_link|linkify }}
          <a href="{% url 'dcim:interface_trace' pk=object.pk %}" class="btn btn-sm btn-primary" title="{% trans "Trace" %}">
            <i class="mdi mdi-transit-connection-variant" aria-hidden="true"></i>
          </a>
        </td>
      </tr>
      {% with peer_interface=object.link_peers.0 %}
        <tr>
          <th scope="row">{% trans "Device" %}</th>
          <td>{{ peer_interface.device|linkify }}</td>
        </tr>
        <tr>
          <th scope="row">{% trans "Name" %}</th>
          <td>{{ peer_interface|linkify }}</td>
        </tr>
        <tr>
          <th scope="row">{% trans "Type" %}</th>
          <td>{{ peer_interface.get_type_display }}</td>
        </tr>
      {% endwith %}
    </table>
  {% else %}
    <div class="card-body text-muted">
      {% trans "Not Connected" %}
      {% if object.is_wired and perms.dcim.add_cable %}
        <div class="dropdown float-end">
          <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
            <span class="mdi mdi-ethernet-cable" aria-hidden="true"></span> {% trans "Connect" %}
          </button>
          <ul class="dropdown-menu dropdown-menu-end">
            <li>
              <a class="dropdown-item" href="{% url 'dcim:cable_add' %}?a_terminations_type=dcim.interface&a_terminations={{ object.pk }}&b_terminations_type=dcim.interface&return_url={{ object.get_absolute_url }}">{% trans "Interface" %}</a>
            </li>
            <li>
              <a class="dropdown-item" href="{% url 'dcim:cable_add' %}?a_terminations_type=dcim.interface&a_terminations={{ object.pk }}&b_terminations_type=dcim.frontport&return_url={{ object.get_absolute_url }}">{% trans "Front Port" %}</a>
            </li>
            <li>
              <a class="dropdown-item" href="{% url 'dcim:cable_add' %}?a_terminations_type=dcim.interface&a_terminations={{ object.pk }}&b_terminations_type=dcim.rearport&return_url={{ object.get_absolute_url }}">{% trans "Rear Port" %}</a>
            </li>
            <li>
              <a class="dropdown-item" href="{% url 'dcim:cable_add' %}?a_terminations_type=dcim.interface&a_terminations={{ object.pk }}&b_terminations_type=circuits.circuittermination&return_url={{ object.get_absolute_url }}">{% trans "Circuit Termination" %}</a>
            </li>
          </ul>
        </div>
      {% elif object.is_wireless and perms.wireless.add_wirelesslink %}
        <div class="dropdown float-end">
          <a href="{% url 'wireless:wirelesslink_add' %}?interface_a={{ object.pk }}&return_url={{ object.get_absolute_url }}" class="btn btn-primary">
            <span class="mdi mdi-wifi-plus" aria-hidden="true"></span> {% trans "Connect" %}
          </a>
        </div>
      {% endif %}
    </div>
  {% endif %}
{% endblock panel_content %}
