{% extends '_base.html' %}
{% load render_table from django_tables2 %}

{% block title %}{{ ipaddress }}{% endblock %}

{% block content %}
<div class="row">
    <div class="col-md-9">
        <ol class="breadcrumb">
            {% for p in parent_prefixes %}
                <li><a href="{% url 'ipam:prefix' pk=p.pk %}">{{ p }}</a></li>
            {% empty %}
                <li><a href="{% url 'ipam:ipaddress_list' %}">IP Addresses</a></li>
            {% endfor %}
            <li>{{ ipaddress.address.ip }}</li>
        </ol>
    </div>
    <div class="col-md-3">
        <form action="{% url 'ipam:ipaddress_list' %}" method="get">
            <div class="input-group">
                <input type="text" name="q" class="form-control" placeholder="IP address" />
                <span class="input-group-btn">
                    <button type="submit" class="btn btn-primary">
                        <span class="glyphicon glyphicon-search" aria-hidden="true"></span>
                    </button>
                </span>
            </div>
        </form>
    </div>
</div>
<div class="pull-right">
    {% if perms.ipam.change_ipaddress %}
        <a href="{% url 'ipam:ipaddress_edit' pk=ipaddress.pk %}" class="btn btn-warning">
            <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
            Edit this IP
        </a>
    {% endif %}
    {% if perms.ipam.delete_ipaddress %}
        <a href="{% url 'ipam:ipaddress_delete' pk=ipaddress.pk %}" class="btn btn-danger">
            <span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
            Delete this IP
        </a>
    {% endif %}
</div>
<h1>{{ ipaddress }}</h1>
<div class="row">
	<div class="col-md-6">
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>IP Address</strong>
            </div>
            <table class="table table-hover panel-body">
                <tr>
                    <td>Family</td>
                    <td>{{ ipaddress.get_family_display }}</td>
                </tr>
                <tr>
                    <td>VRF</td>
                    <td>
                        {% if ipaddress.vrf %}
                            <a href="{% url 'ipam:vrf' pk=ipaddress.vrf.pk %}">{{ ipaddress.vrf }}</a> ({{ ipaddress.vrf.rd }})
                        {% else %}
                            <span>Global</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Description</td>
                    <td>
                        {% if ipaddress.description  %}
                            <span>{{ ipaddress.description }}</span>
                        {% else %}
                            <span class="text-muted">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Assignment</td>
                    <td>
                        {% if ipaddress.interface %}
                            <span><a href="{% url 'dcim:device' pk=ipaddress.interface.device.pk %}">{{ ipaddress.interface.device }}</a> ({{ ipaddress.interface }})</span>
                        {% else %}
                            <span class="text-muted">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>NAT (inside)</td>
                    <td>
                        {% if ipaddress.nat_inside %}
                            <a href="{% url 'ipam:ipaddress' pk=ipaddress.nat_inside.pk %}">{{ ipaddress.nat_inside }}</a>
                            {% if ipaddress.nat_inside.interface %}
                                (<a href="{% url 'dcim:device' pk=ipaddress.nat_inside.interface.device.pk %}">{{ ipaddress.nat_inside.interface.device }}</a>)
                            {% endif %}
                        {% else %}
                            <span class="text-muted">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>NAT (outside)</td>
                    <td>
                        {% if ipaddress.nat_outside %}
                            <a href="{% url 'ipam:ipaddress' pk=ipaddress.nat_outside.pk %}">{{ ipaddress.nat_outside }}</a>
                        {% else %}
                            <span class="text-muted">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Created</td>
                    <td>{{ ipaddress.created }}</td>
                </tr>
                <tr>
                    <td>Last Updated</td>
                    <td>{{ ipaddress.last_updated }}</td>
                </tr>
            </table>
        </div>
	</div>
	<div class="col-md-6">
        {% with heading='Parent Prefixes' %}
            {% render_table parent_prefixes_table 'panel_table.html' %}
        {% endwith %}
        {% if duplicate_ips_table.rows %}
            {% with heading='Duplicate IP Addresses' panel_class='danger' %}
                {% render_table duplicate_ips_table 'panel_table.html' %}
            {% endwith %}
        {% endif %}
        {% with heading='Related IP Addresses' %}
            {% render_table related_ips_table 'panel_table.html' %}
        {% endwith %}
	</div>
</div>
{% endblock %}
