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

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

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

{% block extra_controls %}
  {% if perms.dcim.change_devicetype %}
    <div class="dropdown">
      <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={% url 'dcim:devicetype_consoleports' pk=object.pk %}">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={% url 'dcim:devicetype_consoleserverports' pk=object.pk %}">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={% url 'dcim:devicetype_powerports' pk=object.pk %}">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={% url 'dcim:devicetype_poweroutlets' pk=object.pk %}">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={% url 'dcim:devicetype_interfaces' pk=object.pk %}">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={% url 'dcim:devicetype_frontports' pk=object.pk %}">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={% url 'dcim:devicetype_rearports' pk=object.pk %}">Rear Ports</a></li>
        {% endif %}
        {% if perms.dcim.add_modulebaytemplate %}
          <li><a class="dropdown-item" href="{% url 'dcim:modulebaytemplate_add' %}?device_type={{ object.pk }}&return_url={% url 'dcim:devicetype_modulebays' pk=object.pk %}">Module Bays</a></li>
        {% endif %}
        {% if perms.dcim.add_devicebaytemplate %}
          <li><a class="dropdown-item" href="{% url 'dcim:devicebaytemplate_add' %}?device_type={{ object.pk }}&return_url={% url 'dcim:devicetype_devicebays' pk=object.pk %}">Device Bays</a></li>
        {% endif %}
        {% if perms.dcim.add_inventoryitemtemplate %}
          <li><a class="dropdown-item" href="{% url 'dcim:inventoryitemtemplate_add' %}?device_type={{ object.pk }}&return_url={% url 'dcim:devicetype_inventoryitems' pk=object.pk %}">Inventory Items</a></li>
        {% endif %}
      </ul>
    </div>
  {% endif %}
{% endblock %}

{% block extra_tabs %}
    {% with tab_name='device-bay-templates' devicebay_count=object.devicebaytemplates.count %}
        {% if active_tab == tab_name or devicebay_count %}
            <li role="presentation" class="nav-item">
                <a class="nav-link {% if active_tab == tab_name %} active{% endif %}" href="{% url 'dcim:devicetype_devicebays' pk=object.pk %}">Device Bays {% badge devicebay_count %}</a>
            </li>
        {% endif %}
    {% endwith %}

    {% with tab_name='module-bay-templates' modulebay_count=object.modulebaytemplates.count %}
        {% if active_tab == tab_name or modulebay_count %}
            <li role="presentation" class="nav-item">
                <a class="nav-link {% if active_tab == tab_name %} active{% endif %}" href="{% url 'dcim:devicetype_modulebays' pk=object.pk %}">Module Bays {% badge modulebay_count %}</a>
            </li>
        {% endif %}
    {% endwith %}

    {% with tab_name='interface-templates' interface_count=object.interfacetemplates.count %}
        {% if active_tab == tab_name or interface_count %}
            <li role="presentation" class="nav-item">
                <a class="nav-link {% if active_tab == tab_name %} active{% endif %}" href="{% url 'dcim:devicetype_interfaces' pk=object.pk %}">Interfaces {% badge interface_count %}</a>
            </li>
        {% endif %}
    {% endwith %}

    {% with tab_name='front-port-templates' frontport_count=object.frontporttemplates.count %}
        {% if active_tab == tab_name or frontport_count %}
            <li role="presentation" class="nav-item">
                <a class="nav-link {% if active_tab == tab_name %} active{% endif %}" href="{% url 'dcim:devicetype_frontports' pk=object.pk %}">Front Ports {% badge frontport_count %}</a>
            </li>
        {% endif %}
    {% endwith %}

    {% with tab_name='rear-port-templates' rearport_count=object.rearporttemplates.count %}
        {% if active_tab == tab_name or rearport_count %}
            <li role="presentation" class="nav-item">
                <a class="nav-link {% if active_tab == tab_name %} active{% endif %}" href="{% url 'dcim:devicetype_rearports' pk=object.pk %}">Rear Ports {% badge rearport_count %}</a>
            </li>
        {% endif %}
    {% endwith %}

    {% with tab_name='console-port-templates' consoleport_count=object.consoleporttemplates.count %}
        {% if active_tab == tab_name or consoleport_count %}
            <li role="presentation" class="nav-item">
                <a class="nav-link {% if active_tab == tab_name %} active{% endif %}" href="{% url 'dcim:devicetype_consoleports' pk=object.pk %}">Console Ports {% badge consoleport_count %}</a>
            </li>
        {% endif %}
    {% endwith %}

    {% with tab_name='console-server-port-templates' consoleserverport_count=object.consoleserverporttemplates.count %}
        {% if active_tab == tab_name or consoleserverport_count %}
            <li role="presentation" class="nav-item">
                <a class="nav-link {% if active_tab == tab_name %} active{% endif %}" href="{% url 'dcim:devicetype_consoleserverports' pk=object.pk %}">Console Server Ports {% badge consoleserverport_count %}</a>
            </li>
        {% endif %}
    {% endwith %}

    {% with tab_name='power-port-templates' powerport_count=object.powerporttemplates.count %}
        {% if active_tab == tab_name or powerport_count %}
            <li role="presentation" class="nav-item">
                <a class="nav-link {% if active_tab == tab_name %} active{% endif %}" href="{% url 'dcim:devicetype_powerports' pk=object.pk %}">Power Ports {% badge powerport_count %}</a>
            </li>
        {% endif %}
    {% endwith %}

    {% with tab_name='power-outlet-templates' poweroutlet_count=object.poweroutlettemplates.count %}
        {% if active_tab == tab_name or poweroutlet_count %}
            <li role="presentation" class="nav-item">
                <a class="nav-link {% if active_tab == tab_name %} active{% endif %}" href="{% url 'dcim:devicetype_poweroutlets' pk=object.pk %}">Power Outlets {% badge poweroutlet_count %}</a>
            </li>
        {% endif %}
    {% endwith %}

    {% with tab_name='inventory-item-templates' inventoryitem_count=object.inventoryitemtemplates.count %}
        {% if active_tab == tab_name or inventoryitem_count %}
            <li role="presentation" class="nav-item">
                <a class="nav-link {% if active_tab == tab_name %} active{% endif %}" href="{% url 'dcim:devicetype_inventoryitems' pk=object.pk %}">Inventory Items {% badge inventoryitem_count %}</a>
            </li>
        {% endif %}
    {% endwith %}
{% endblock %}
