{% load helpers %}

<tr class="devicebay">
    {% if perms.dcim.change_devicebay or perms.dcim.delete_devicebay %}
        <td class="pk">
            <input name="pk" type="checkbox" value="{{ devicebay.pk }}" />
        </td>
    {% endif %}

    {# Name #}
    <td>
        <i class="fa fa-fw fa-{% if devicebay.installed_device %}dot-circle-o{% else %}circle-o{% endif %}"></i>
        <a href="{{ devicebay.get_absolute_url }}">{{ devicebay.name }}</a>
    </td>

    {# Status #}
    <td>
        {% if devicebay.installed_device %}
            <span class="label label-{{ devicebay.installed_device.get_status_class }}">
                {{ devicebay.installed_device.get_status_display }}
            </span>
        {% else %}
            <span class="label label-default">Vacant</span>
        {% endif %}
    </td>

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

    {# Installed device #}
    {% if devicebay.installed_device %}
        <td>
            <a href="{% url 'dcim:device' pk=devicebay.installed_device.pk %}">{{ devicebay.installed_device }}</a>
        </td>
        <td>
            <span>{{ devicebay.installed_device.device_type.display_name }}</span>
        </td>
    {% else %}
        <td colspan="2"></td>
    {% endif %}

    <td class="text-right noprint">
        {% if perms.dcim.change_devicebay %}
            {% if devicebay.installed_device %}
                <a href="{% url 'dcim:devicebay_depopulate' pk=devicebay.pk %}" class="btn btn-danger btn-xs">
                    <i class="glyphicon glyphicon-remove" aria-hidden="true" title="Remove device"></i>
                </a>
            {% else %}
                <a href="{% url 'dcim:devicebay_populate' pk=devicebay.pk %}" class="btn btn-success btn-xs">
                    <i class="glyphicon glyphicon-plus" aria-hidden="true" title="Install device"></i>
                </a>
            {% endif %}
            <a href="{% url 'dcim:devicebay_edit' pk=devicebay.pk %}" class="btn btn-info btn-xs">
                <i class="glyphicon glyphicon-pencil" aria-hidden="true" title="Edit device bay"></i>
            </a>
        {% endif %}
        {% if perms.dcim.delete_devicebay %}
            {% if devicebay.installed_device %}
                <button class="btn btn-danger btn-xs" disabled="disabled">
                    <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
                </button>
            {% else %}
                <a href="{% url 'dcim:devicebay_delete' pk=devicebay.pk %}?return_url={{ device.get_absolute_url }}" class="btn btn-danger btn-xs">
                    <i class="glyphicon glyphicon-trash" aria-hidden="true" title="Delete device bay"></i>
                </a>
            {% endif %}
        {% endif %}
    </td>
</tr>
