{% extends 'generic/object.html' %}
{% load buttons %}
{% load helpers %}
{% load plugins %}

{% block title %}{{ object.manufacturer }} {{ object.model }}{% endblock %}

{% block breadcrumbs %}
  <li class="breadcrumb-item"><a href="{% url 'dcim:devicetype_list' %}">Device Types</a></li>
  <li class="breadcrumb-item"><a href="{% url 'dcim:devicetype_list' %}?manufacturer_id={{ object.manufacturer.pk }}">{{ object.manufacturer }}</a></li>
  <li class="breadcrumb-item">{{ object.model }}</li>
{% endblock %}

{% block controls %}
  {% if perms.dcim.change_devicetype %}
    <div class="dropdown m-1">
      <button type="button" class="btn btn-primary btn-sm dropdown-toggle"data-bs-toggle="dropdown" aria-expanded="false">
        <i class="mdi mdi-plus-thick" aria-hidden="true"></i> Add Components
      </button>
      <ul class="dropdown-menu">
        {% if perms.dcim.add_consoleporttemplate %}
          <li><a class="dropdown-item" href="{% url 'dcim:consoleporttemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_consoleports">Console Ports</a></li>
        {% endif %}
        {% if perms.dcim.add_consoleserverporttemplate %}
          <li><a class="dropdown-item" href="{% url 'dcim:consoleserverporttemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_consoleserverports">Console Server Ports</a></li>
        {% endif %}
        {% if perms.dcim.add_powerporttemplate %}
          <li><a class="dropdown-item" href="{% url 'dcim:powerporttemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_powerports">Power Ports</a></li>
        {% endif %}
        {% if perms.dcim.add_poweroutlettemplate %}
          <li><a class="dropdown-item" href="{% url 'dcim:poweroutlettemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_poweroutlets">Power Outlets</a></li>
        {% endif %}
        {% if perms.dcim.add_interfacetemplate %}
          <li><a class="dropdown-item" href="{% url 'dcim:interfacetemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_interfaces">Interfaces</a></li>
        {% endif %}
        {% if perms.dcim.add_frontporttemplate %}
          <li><a class="dropdown-item" href="{% url 'dcim:frontporttemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_frontports">Front Ports</a></li>
        {% endif %}
        {% if perms.dcim.add_rearporttemplate %}
          <li><a class="dropdown-item" href="{% url 'dcim:rearporttemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_rearports">Rear Ports</a></li>
        {% endif %}
        {% if perms.dcim.add_devicebaytemplate %}
          <li><a class="dropdown-item" href="{% url 'dcim:devicebaytemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_devicebays">Device Bays</a></li>
        {% endif %}
      </ul>
    </div>
  {% endif %}
  {% if perms.dcim.add_devicetype %}
    {% clone_button object %}
  {% endif %}
  {% if perms.dcim.change_devicetype %}
    {% edit_button object %}
  {% endif %}
  {% if perms.dcim.delete_devicetype %}
    {% delete_button object %}
  {% endif %}
{% endblock %}

{% block content %}
    <div class="row">
        <div class="col col-md-6">
            <div class="card">
                <h5 class="card-header">
                    Chassis
                </h5>
                <div class="card-body">
                    <table class="table table-hover attr-table">
                        <tr>
                            <td>Manufacturer</td>
                            <td><a href="{{ object.manufacturer.get_absolute_url }}">{{ object.manufacturer }}</a></td>
                        </tr>
                        <tr>
                            <td>Model Name</td>
                            <td>
                                {{ object.model }}<br/>
                                <small class="text-muted">{{ object.slug }}</small>
                            </td>
                        </tr>
                        <tr>
                            <td>Part Number</td>
                            <td>{{ object.part_number|placeholder }}</td>
                        </tr>
                        <tr>
                            <td>Height (U)</td>
                            <td>{{ object.u_height }}</td>
                        </tr>
                        <tr>
                            <td>Full Depth</td>
                            <td>
                                {% if object.is_full_depth %}
                                    <i class="mdi mdi-check-bold text-success" title="Yes"></i>
                                {% else %}
                                    <i class="mdi mdi-close-thick text-danger" title="No"></i>
                                {% endif %}
                            </td>
                        </tr>
                        <tr>
                            <td>Parent/Child</td>
                            <td>
                                {{ object.get_subdevice_role_display|placeholder }}
                            </td>
                        </tr>
                        <tr>
                            <td>Front Image</td>
                            <td>
                                {% if object.front_image %}
                                    <a href="{{ object.front_image.url }}">
                                        <img src="{{ object.front_image.url }}" alt="{{ object.front_image.name }}" class="img-responsive" />
                                    </a>
                                {% else %}
                                    <span class="text-muted">&mdash;</span>
                                {% endif %}
                            </td>
                        </tr>
                        <tr>
                            <td>Rear Image</td>
                            <td>
                                {% if object.rear_image %}
                                    <a href="{{ object.rear_image.url }}">
                                        <img src="{{ object.rear_image.url }}" alt="{{ object.rear_image.name }}" class="img-responsive" />
                                    </a>
                                {% else %}
                                    <span class="text-muted">&mdash;</span>
                                {% endif %}
                            </td>
                        </tr>
                        <tr>
                            <td>Instances</td>
                            <td><a href="{% url 'dcim:device_list' %}?device_type_id={{ object.pk }}">{{ instance_count }}</a></td>
                        </tr>
                    </table>
                </div>
            </div>
            {% plugin_left_page object %}
        </div>
        <div class="col col-md-6">
            {% include 'inc/custom_fields_panel.html' %}
            {% include 'extras/inc/tags_panel.html' with tags=object.tags.all url='dcim:devicetype_list' %}
            <div class="card">
                <h5 class="card-header">
                    Comments
                </h5>
                <div class="card-body rendered-markdown">
                    {% if object.comments %}
                        {{ object.comments|render_markdown }}
                    {% else %}
                        <span class="text-muted">None</span>
                    {% endif %}
                </div>
            </div>
            {% plugin_right_page object %}
        </div>
    </div>
    <div class="row">
        <div class="col col-md-12">
            {% plugin_full_width_page object %}
        </div>
    </div>
    <div class="row my-3">
        <div class="col col-md-12">
            <ul class="nav nav-tabs" role="tablist">
                <li class="nav-item" role="presentation">
                    <button class="nav-link active" data-bs-target="#interfaces" role="tab" data-bs-toggle="tab">
                        Interfaces {% badge interface_table.rows|length %}
                    </button>
                </li>
                <li class="nav-item" role="presentation">
                    <button class="nav-link" data-bs-target="#frontports" role="tab" data-bs-toggle="tab">
                        Front Ports {% badge front_port_table.rows|length %}
                    </button>
                </li>
                <li class="nav-item" role="presentation">
                    <button class="nav-link" data-bs-target="#rearports" role="tab" data-bs-toggle="tab">
                        Rear Ports {% badge rear_port_table.rows|length %}
                    </button>
                </li>
                <li class="nav-item" role="presentation">
                    <button class="nav-link" data-bs-target="#consoleports" role="tab" data-bs-toggle="tab">
                        Console Ports {% badge consoleport_table.rows|length %}
                    </button>
                </li>
                <li class="nav-item" role="presentation">
                    <button class="nav-link" data-bs-target="#consoleserverports" role="tab" data-bs-toggle="tab">
                        Console Server Ports {% badge consoleserverport_table.rows|length %}
                    </button>
                </li>
                <li class="nav-item" role="presentation">
                    <button class="nav-link" data-bs-target="#powerports" role="tab" data-bs-toggle="tab">
                        Power Ports {% badge powerport_table.rows|length %}
                    </button>
                </li>
                <li class="nav-item" role="presentation">
                    <button class="nav-link" data-bs-target="#poweroutlets" role="tab" data-bs-toggle="tab">
                        Power Outlets {% badge poweroutlet_table.rows|length %}
                    </button>
                </li>
                <li class="nav-item" role="presentation">
                    <button class="nav-link" data-bs-target="#devicebays" role="tab" data-bs-toggle="tab">
                        Device Bays {% badge devicebay_table.rows|length %}
                    </button>
                </li>
            </ul>
            <div class="tab-content my-3">
                <div role="tabpanel" class="tab-pane active" id="interfaces">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=interface_table title='Interfaces' tab='interfaces' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="frontports">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=front_port_table title='Front Ports' tab='frontports' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="rearports">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=rear_port_table title='Rear Ports' tab='rearports' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="consoleports">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=consoleport_table title='Console Ports' tab='consoleports' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="consoleserverports">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=consoleserverport_table title='Console Server Ports' tab='consoleserverports' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="powerports">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=powerport_table title='Power Ports' tab='powerports' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="poweroutlets">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=poweroutlet_table title='Power Outlets' tab='poweroutlets' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="devicebays">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=devicebay_table title='Device Bays' tab='devicebays' %}
                </div>
            </div>
        </div>
    </div>
{% endblock %}
