{% 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:moduletype_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' %}?module_type={{ object.pk }}&return_url={% url 'dcim:moduletype_consoleports' pk=object.pk %}">Console Ports</a></li>
        {% endif %}
        {% if perms.dcim.add_consoleserverporttemplate %}
          <li><a class="dropdown-item" href="{% url 'dcim:consoleserverporttemplate_add' %}?module_type={{ object.pk }}&return_url={% url 'dcim:moduletype_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' %}?module_type={{ object.pk }}&return_url={% url 'dcim:moduletype_powerports' pk=object.pk %}">Power Ports</a></li>
        {% endif %}
        {% if perms.dcim.add_poweroutlettemplate %}
          <li><a class="dropdown-item" href="{% url 'dcim:poweroutlettemplate_add' %}?module_type={{ object.pk }}&return_url={% url 'dcim:moduletype_poweroutlets' pk=object.pk %}">Power Outlets</a></li>
        {% endif %}
        {% if perms.dcim.add_interfacetemplate %}
          <li><a class="dropdown-item" href="{% url 'dcim:interfacetemplate_add' %}?module_type={{ object.pk }}&return_url={% url 'dcim:moduletype_interfaces' pk=object.pk %}">Interfaces</a></li>
        {% endif %}
        {% if perms.dcim.add_frontporttemplate %}
          <li><a class="dropdown-item" href="{% url 'dcim:frontporttemplate_add' %}?module_type={{ object.pk }}&return_url={% url 'dcim:moduletype_frontports' pk=object.pk %}">Front Ports</a></li>
        {% endif %}
        {% if perms.dcim.add_rearporttemplate %}
          <li><a class="dropdown-item" href="{% url 'dcim:rearporttemplate_add' %}?module_type={{ object.pk }}&return_url={% url 'dcim:moduletype_rearports' pk=object.pk %}">Rear Ports</a></li>
        {% endif %}
      </ul>
    </div>
  {% endif %}
{% endblock %}

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

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

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

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

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

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

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