{% load helpers %}

<tr class="poweroutlet{% if po.cable %} {{ po.cable.get_status_class }}{% endif %}">

    {# Checkbox #}
    {% if perms.dcim.change_poweroutlet or perms.dcim.delete_poweroutlet %}
        <td class="pk">
            <input name="pk" type="checkbox" value="{{ po.pk }}" />
        </td>
    {% endif %}

    {# Name #}
    <td>
        <i class="fa fa-fw fa-bolt"></i> {{ po }}
    </td>

    {# Type #}
    <td>
        {{ po.get_type_display }}
    </td>

    {# Input/leg #}
    <td>
        {% if po.power_port %}
            {{ po.power_port }}{% if po.feed_leg %} / {{ po.get_feed_leg_display }}{% endif %}
        {% elif po.feed_leg %}
            {{ po.get_feed_leg_display }}
        {% else %}
            <span class="text-warning">None</span>
        {% endif %}
    </td>

    {# Description #}
    <td>
        {{ po.description|placeholder }}
    </td>

    {# Cable #}
    <td class="text-nowrap">
        {% if po.cable %}
            <a href="{{ po.cable.get_absolute_url }}">{{ po.cable }}</a>
            <a href="{% url 'dcim:poweroutlet_trace' pk=po.pk %}" class="btn btn-primary btn-xs" title="Trace">
                <i class="fa fa-share-alt" aria-hidden="true"></i>
            </a>
        {% else %}
            <span class="text-muted">&mdash;</span>
        {% endif %}
    </td>

    {# Connection #}
    {% if po.connected_endpoint %}
        {% with pp=po.connected_endpoint %}
            <td>
                <a href="{% url 'dcim:device' pk=pp.device.pk %}">{{ pp.device }}</a>
            </td>
            <td>
                {{ pp }}
            </td>
            <td>
                {% if pp.allocated_draw %}
                    {{ pp.allocated_draw }}W{% if pp.maximum_draw %} ({{ pp.maximum_draw }}W max){% endif %}
                {% elif pp.maximum_draw %}
                    {{ pp.maximum_draw }}W
                {% endif %}
            </td>
        {% endwith %}
    {% else %}
        <td colspan="3">
            <span class="text-muted">Not connected</span>
        </td>
    {% endif %}

    {# Actions #}
    <td class="text-right noprint">
        {% if po.cable %}
            {% include 'dcim/inc/cable_toggle_buttons.html' with cable=po.cable %}
        {% elif perms.dcim.add_cable %}
            <a href="{% url 'dcim:poweroutlet_connect' termination_a_id=po.pk termination_b_type='power-port' %}?return_url={{ device.get_absolute_url }}" title="Connect" class="btn btn-success btn-xs">
                <i class="glyphicon glyphicon-resize-small" aria-hidden="true"></i>
            </a>
        {% endif %}
        {% if perms.dcim.change_poweroutlet %}
            <a href="{% url 'dcim:poweroutlet_edit' pk=po.pk %}" title="Edit outlet" class="btn btn-info btn-xs">
                <i class="glyphicon glyphicon-pencil" aria-hidden="true"></i>
            </a>
        {% endif %}
        {% if perms.dcim.delete_poweroutlet %}
            {% if po.connected_endpoint %}
                <button class="btn btn-danger btn-xs" disabled="disabled">
                    <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
                </button>
            {% else %}
                <a href="{% url 'dcim:poweroutlet_delete' pk=po.pk %}?return_url={{ device.get_absolute_url }}" title="Delete outlet" class="btn btn-danger btn-xs">
                    <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
                </a>
            {% endif %}
        {% endif %}
    </td>
</tr>
