{% load helpers %}
{% load i18n %}
<tr id="row-cable-{{ row.cable.pk }}">
    <td>
        <a href="{{ row.cable.get_absolute_url }}">{{ row.cable }}</a>
    </td>
    <td>
        {% if row.fiber_cable %}
            <a href="{{ row.fiber_cable.get_absolute_url }}">{{ row.fiber_cable.fiber_cable_type }}</a>
        {% else %}
            <span class="text-muted">&mdash;</span>
        {% endif %}
    </td>
    <td>
        {% if row.gland_entry and row.gland_entry.entrance_label %}
            {{ row.gland_entry.entrance_label }}
        {% else %}
            <span class="text-muted">&mdash;</span>
        {% endif %}
    </td>
    <td>
        {% if row.strand_info %}
            {{ row.strand_info.linked }}/{{ row.strand_info.total }}
        {% else %}
            <span class="text-muted">&mdash;</span>
        {% endif %}
    </td>
    <td>
        {% if not row.fiber_cable %}
            {% if perms.netbox_fms.add_fibercable %}
            <button type="button" class="btn btn-sm btn-success"
                    hx-get="{% url 'plugins:netbox_fms:fiber_overview_link_topology' pk=device.pk %}"
                    hx-vals='{"cable_id": "{{ row.cable.pk }}"}'
                    hx-target="#htmx-modal-content" hx-swap="innerHTML"
                    data-bs-toggle="modal" data-bs-target="#htmx-modal">
                <i class="mdi mdi-link-variant"></i> {% trans "Link Topology" %}
            </button>
            {% endif %}
        {% elif row.strand_info and row.strand_info.linked == row.strand_info.total and row.strand_info.total > 0 %}
            <span class="text-success"><i class="mdi mdi-check-circle"></i></span>
        {% elif row.strand_info and row.strand_info.linked < row.strand_info.total %}
            <span class="text-warning" title="{% trans 'Partially linked' %}">
                <i class="mdi mdi-alert-circle-outline"></i> {{ row.strand_info.linked }}/{{ row.strand_info.total }}
            </span>
        {% endif %}
        {% if row.fiber_cable %}
            {% if perms.netbox_fms.add_closurecableentry or perms.netbox_fms.change_closurecableentry %}
            <button type="button" class="btn btn-sm btn-outline-secondary ms-1"
                    hx-get="{% url 'plugins:netbox_fms:fiber_overview_update_gland' pk=device.pk %}"
                    hx-vals='{"fiber_cable_id": "{{ row.fiber_cable.pk }}", "cable_id": "{{ row.cable.pk }}"}'
                    hx-target="#htmx-modal-content" hx-swap="innerHTML"
                    data-bs-toggle="modal" data-bs-target="#htmx-modal">
                <i class="mdi mdi-pencil"></i>
            </button>
            {% endif %}
        {% endif %}
    </td>
</tr>
