{% load helpers i18n %}
{% if object.mark_connected %}
  <div>
    <span class="text-success"><i class="mdi mdi-check-bold"></i></span>
    <span class="text-muted">{% trans "Marked as connected" %}</span>
  </div>
{% elif object.cable %}
  <div>
    <a class="d-block d-md-inline" href="{{ object.cable.get_absolute_url }}">{{ object.cable }}</a> {% trans "to" %}
    {% for peer in object.link_peers %}
      {% if peer.device %}
        {{ peer.device|linkify }}<br/>
      {% elif peer.circuit %}
        {{ peer.circuit|linkify }}<br/>
      {% endif %}
      {{ peer|linkify }}{% if not forloop.last %},{% endif %}
    {% endfor %}
  </div>
  <div class="mt-1">
    <a href="{% url 'circuits:circuittermination_trace' pk=object.pk %}" class="btn btn-sm btn-primary" title="{% trans "Trace" %}">
      <i class="mdi mdi-transit-connection-variant" aria-hidden="true"></i> {% trans "Trace" %}
    </a>
    {% if perms.dcim.change_cable %}
      <a href="{% url 'dcim:cable_edit' pk=object.cable.pk %}?return_url={{ object.circuit.get_absolute_url }}" title="{% trans "Edit cable" %}" class="btn btn-sm btn-warning">
        <i class="mdi mdi-ethernet-cable" aria-hidden="true"></i> {% trans "Edit" %}
      </a>
    {% endif %}
    {% if perms.dcim.delete_cable %}
      <a href="{% url 'dcim:cable_delete' pk=object.cable.pk %}?return_url={{ object.circuit.get_absolute_url }}" title="{% trans "Remove cable" %}" class="btn btn-sm btn-danger">
        <i class="mdi mdi-ethernet-cable-off" aria-hidden="true"></i> {% trans "Disconnect" %}
      </a>
    {% endif %}
  </div>
{% elif perms.dcim.add_cable %}
  <div class="dropdown">
    <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
      <span class="mdi mdi-ethernet-cable" aria-hidden="true"></span> {% trans "Connect" %}
    </button>
    <ul class="dropdown-menu">
      <li><a class="dropdown-item" href="{% url 'dcim:cable_add' %}?a_terminations_type=circuits.circuittermination&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=circuits.circuittermination&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=circuits.circuittermination&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=circuits.circuittermination&a_terminations={{ object.pk }}&b_terminations_type=circuits.circuittermination&return_url={{ object.get_absolute_url }}">{% trans "Circuit Termination" %}</a></li>
    </ul>
  </div>
{% else %}
  {{ ''|placeholder }}
{% endif %}
