{% extends '_base.html' %}

{% block title %}{{ prefix }}{% endblock %}

{% block content %}
{% include 'ipam/inc/prefix_header.html' with active_tab='prefix' %}
<div class="row">
	<div class="col-md-5">
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Prefix</strong>
            </div>
            <table class="table table-hover panel-body attr-table">
                <tr>
                    <td>Family</td>
                    <td>{{ prefix.get_family_display }}</td>
                </tr>
                <tr>
                    <td>VRF</td>
                    <td>
                        {% if prefix.vrf %}
                            <a href="{% url 'ipam:vrf' pk=prefix.vrf.pk %}">{{ prefix.vrf }}</a> ({{ prefix.vrf.rd }})
                        {% else %}
                            <span>Global</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Tenant</td>
                    <td>
                        {% if prefix.tenant %}
                            {% if prefix.tenant.group %}
                                <a href="{{ prefix.tenant.group.get_absolute_url }}">{{ prefix.tenant.group.name }}</a>
                                <i class="fa fa-angle-right"></i>
                            {% endif %}
                            <a href="{{ prefix.tenant.get_absolute_url }}">{{ prefix.tenant }}</a>
                        {% elif prefix.vrf.tenant %}
                            {% if prefix.vrf.tenant.group %}
                                <a href="{{ prefix.vrf.tenant.group.get_absolute_url }}">{{ prefix.vrf.tenant.group.name }}</a>
                                <i class="fa fa-angle-right"></i>
                            {% endif %}
                            <a href="{{ prefix.vrf.tenant.get_absolute_url }}">{{ prefix.vrf.tenant }}</a>
                            <label class="label label-info">Inherited</label>
                        {% else %}
                            <span class="text-muted">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Aggregate</td>
                    <td>
                        {% if aggregate %}
                            <a href="{% url 'ipam:aggregate' pk=aggregate.pk %}">{{ aggregate.prefix }}</a> ({{ aggregate.rir }})
                        {% else %}
                            <span class="text-warning">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Site</td>
                    <td>
                        {% if prefix.site %}
                            {% if prefix.site.region %}
                                <a href="{{ prefix.site.region.get_absolute_url }}">{{ prefix.site.region }}</a>
                                <i class="fa fa-angle-right"></i>
                            {% endif %}
                            <a href="{% url 'dcim:site' slug=prefix.site.slug %}">{{ prefix.site }}</a>
                        {% else %}
                            <span class="text-muted">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>VLAN</td>
                    <td>
                        {% if prefix.vlan %}
                            {% if prefix.vlan.group %}
                                <a href="{{ prefix.vlan.group.get_absolute_url }}">{{ prefix.vlan.group.name }}</a>
                                <i class="fa fa-angle-right"></i>
                            {% endif %}
                            <a href="{% url 'ipam:vlan' pk=prefix.vlan.pk %}">{{ prefix.vlan.display_name }}</a>
                        {% else %}
                            <span class="text-muted">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Status</td>
                    <td>
                        <span class="label label-{{ prefix.get_status_class }}">{{ prefix.get_status_display }}</span>
                    </td>
                </tr>
                <tr>
                    <td>Role</td>
                    <td>
                        {% if prefix.role %}
                            <a href="{% url 'ipam:prefix_list' %}?role={{ prefix.role.slug }}">{{ prefix.role }}</a>
                        {% else %}
                            <span class="text-muted">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Is a pool</td>
                    <td>
                        {% if prefix.is_pool %}
                            <i class="glyphicon glyphicon-ok text-success" title="Yes"></i>
                        {% else %}
                            <i class="glyphicon glyphicon-remove text-danger" title="No"></i>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Description</td>
                    <td>
                        {% if prefix.description %}
                            <span>{{ prefix.description }}</span>
                        {% else %}
                            <span class="text-muted">N/A</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Utilization</td>
                    <td><a href="{% url 'ipam:prefix_ipaddresses' pk=prefix.pk %}">{{ ipaddress_count }} IP addresses</a> ({{ prefix.get_utilization }}%)</td>
                </tr>
            </table>
        </div>
        {% with prefix.get_custom_fields as custom_fields %}
            {% include 'inc/custom_fields_panel.html' %}
        {% endwith %}
        <br />
	</div>
	<div class="col-md-7">
        {% if duplicate_prefix_table.rows %}
            {% include 'panel_table.html' with table=duplicate_prefix_table heading='Duplicate Prefixes' panel_class='danger' %}
        {% endif %}
        {% include 'panel_table.html' with table=parent_prefix_table heading='Parent Prefixes' %}
	</div>
</div>
<div class="row">
	<div class="col-md-12">
        {% if child_prefix_table.rows %}
            {% include 'utilities/obj_table.html' with table=child_prefix_table table_template='panel_table.html' heading='Child Prefixes' parent=prefix bulk_edit_url='ipam:prefix_bulk_edit' bulk_delete_url='ipam:prefix_bulk_delete' %}
        {% elif prefix.new_subnet %}
            <a href="{% url 'ipam:prefix_add' %}?prefix={{ prefix.new_subnet }}{% if prefix.vrf %}&vrf={{ prefix.vrf.pk }}{% endif %}{% if prefix.site %}&site={{ prefix.site.pk }}{% endif %}" class="btn btn-success">
                <i class="fa fa-plus" aria-hidden="true"></i> Add Child Prefix
            </a>
        {% endif %}
    </div>
</div>
{% endblock %}
