{% extends 'generic/object_detail.html' %}
{% load helpers %}

{% block breadcrumbs %}
    <li><a href="{% url 'ipam:namespace_list' %}">Namespaces</a></li>
    <li>{{ object.namespace | hyperlinked_object }}</li>
    <li><a href="{% url list_url %}?namespace={{ object.namespace.pk }}">{{ verbose_name_plural|bettertitle }}</a></li>
    {% block extra_breadcrumbs %}{% endblock extra_breadcrumbs %}
    <li>{{ object|hyperlinked_object }}</li>
{% endblock breadcrumbs %}

{% block extra_buttons %}
        {% if perms.ipam.add_prefix and active_tab == 'prefixes' and first_available_prefix %}
        <a href="{% url 'ipam:prefix_add' %}?prefix={{ first_available_prefix }}&namespace={{ object.namespace.pk }}&location={{ object.location.pk }}&tenant_group={{ object.tenant.tenant_group.pk }}&tenant={{ object.tenant.pk }}" class="btn btn-success">
                <i class="mdi mdi-plus-thick" aria-hidden="true"></i> Add Child Prefix
            </a>
        {% endif %}
        {% if perms.ipam.add_ipaddress and active_tab == 'ip-addresses' and first_available_ip %}
            <a href="{% url 'ipam:ipaddress_add' %}?address={{ first_available_ip }}&namespace={{ object.namespace.pk }}&tenant_group={{ object.tenant.tenant_group.pk }}&tenant={{ object.tenant.pk }}" class="btn btn-success">
                <span class="mdi mdi-plus-thick" aria-hidden="true"></span>
                Add an IP Address
            </a>
        {% endif %}
{% endblock extra_buttons %}

{% block panel_buttons %}
    {% include 'ipam/inc/toggle_available.html' %}
{% endblock panel_buttons %}

{% block extra_nav_tabs %}
        <li role="presentation"{% if active_tab == 'prefixes' %} class="active"{% endif %}>
            <a href="{% url 'ipam:prefix_prefixes' pk=object.pk %}">Child Prefixes <span class="badge">{{ object.descendants_count }}</span></a>
        </li>
        {% if perms.ipam.view_ipaddress %}
            <li role="presentation"{% if active_tab == 'ip-addresses' %} class="active"{% endif %}>
                <a href="{% url 'ipam:prefix_ipaddresses' pk=object.pk %}">IP Addresses <span class="badge">{{ object.get_child_ips.count }}</span></a>
            </li>
        {% endif %}
{% endblock extra_nav_tabs %}

{% block content_left_page %}
            <div class="panel panel-default">
                <div class="panel-heading">
                    <strong>Prefix</strong>
                </div>
                <table class="table table-hover panel-body attr-table">
                    <tr>
                        <td>Namespace</td>
                        <td>{{ object.namespace|hyperlinked_object }}</td>
                    </tr>
                    <tr>
                        <td>IP Version</td>
                        <td>IPv{{ object.ip_version }}</td>
                    </tr>
                    <tr>
                        <td>Status</td>
                        <td>
                            {{ object.status| hyperlinked_object_with_color }}
                        </td>
                    </tr>
                    <tr>
                        <td>Role</td>
                        <td>{{ object.role | hyperlinked_object_with_color }}</td>
                    </tr>
                    <tr>
                        <td>Type</td>
                        <td>
                            {{ object.get_type_display }}
                        </td>
                    </tr>
                    <tr>
                        <td>Tenant</td>
                        <td>
                            {% if object.tenant and object.tenant.tenant_group %}
                                {{ object.tenant.tenant_group|hyperlinked_object }} /
                            {% endif %}
                            {{ object.tenant|hyperlinked_object }}
                        </td>
                    </tr>
                    <tr>
                        <td>Location</td>
                        <td>{% include 'dcim/inc/location_hierarchy.html' with location=object.location %}</td>
                    </tr>
                    <tr>
                        <td>VLAN</td>
                        <td>
                            {% if object.vlan and object.vlan.vlan_group %}
                                {{ object.vlan.vlan_group|hyperlinked_object }} /
                            {% endif %}
                            {{ object.vlan|hyperlinked_object }}
                        </td>
                    </tr>
                    <tr>
                        <td>RIR</td>
                        <td>{{ object.rir|hyperlinked_object }}</td>
                    </tr>
                    <tr>
                        <td>Date Allocated</td>
                        <td>{{ object.date_allocated|placeholder }}</td>
                    </tr>
                    <tr>
                        <td>Description</td>
                        <td>{{ object.description|placeholder }}</td>
                    </tr>
                    <tr>
                        <td>Utilization</td>
                        <td>{% utilization_graph object.get_utilization %}</td>
                    </tr>
                </table>
            </div>
{% endblock content_left_page %}

{% block content_right_page %}
            {% include 'panel_table.html' with table=parent_prefix_table heading='Parent Prefixes' panel_class='default' %}
            {% include "utilities/obj_table.html" with table=vrf_table table_template="panel_table.html" heading="Assigned VRFs" disable_pagination=False %}
{% endblock content_right_page %}
