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

{% block extra_breadcrumbs %}
    {% for ancestor in object.ancestors %}
        <li>{{ ancestor|hyperlinked_object:"name"}}</li>
    {% endfor %}
{% endblock %}

{% block buttons %}
        {% plugin_buttons object %}
        {% if perms.dcim.add_location %}
            {% clone_button object %}
        {% endif %}
        {% if perms.dcim.change_location %}
            {% edit_button object key="pk" %}
        {% endif %}
        {% if perms.dcim.delete_location %}
            {% delete_button object key="pk" %}
        {% endif %}
{% endblock buttons %}

{% block content_left_page %}
    <div class="panel panel-default">
        <div class="panel-heading">
            <strong>Location</strong>
        </div>
        <table class="table table-hover panel-body attr-table">
            <tr>
                <td>Location Type</td>
                <td>{{ object.location_type|hyperlinked_object:"name" }}</td>
            </tr>
            <tr>
                <td>Status</td>
                <td>
                    {{ object.status| hyperlinked_object_with_color }}
                </td>
            </tr>
            <tr>
                <td>Hierarchy</td>
                <td>
                    {% include 'dcim/inc/location_hierarchy.html' with location=object %}
                </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>Facility</td>
                <td>{{ object.facility|placeholder }}</td>
            </tr>
            <tr>
                <td>AS Number</td>
                <td>{{ object.asn|placeholder }}</td>
            </tr>
            <tr>
                <td>Time Zone</td>
                 <td>
                    {% if object.time_zone %}
                        {{ object.time_zone }} (UTC {{ object.time_zone|tzoffset }})<br />
                        <small class="text-muted">Local time: {% timezone object.time_zone %}{% now "SHORT_DATETIME_FORMAT" %}{% endtimezone %}</small>
                    {% else %}
                        <span class="text-muted">&mdash;</span>
                    {% endif %}
                </td>
            </tr>
            <tr>
                <td>Description</td>
                <td>{{ object.description|placeholder }}</td>
            </tr>
            <tr>
                <td>Children</td>
                <td>
                    {% if object.location_type.children.all %}
                        <a href="{% url 'dcim:location_list' %}?parent={{ object.pk }}">{{ children_table.rows|length }}</a>
                    {% else %}
                        {{ None|placeholder }}
                    {% endif %}
                </td>
            </tr>
        </table>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading">
            <strong>Contact Info</strong>
        </div>
        <table class="table table-hover panel-body attr-table">
            <tr>
                <td>Physical Address</td>
                <td>
                    {% if object.physical_address %}
                        <div class="pull-right noprint">
                            <a href="https://maps.google.com/?q={{ object.physical_address|urlencode }}" target="_blank" class="btn btn-primary btn-xs">
                                <i class="mdi mdi-map-marker"></i> Map it
                            </a>
                        </div>
                        <span>{{ object.physical_address|linebreaksbr }}</span>
                    {% else %}
                        <span class="text-muted">&mdash;</span>
                    {% endif %}
                </td>
            </tr>
            <tr>
                <td>Shipping Address</td>
                <td>{{ object.shipping_address|linebreaksbr|placeholder }}</td>
            </tr>
            <tr>
                <td>GPS Coordinates</td>
                <td>
                    {% if object.latitude and object.longitude %}
                        <div class="pull-right noprint">
                            <a href="https://maps.google.com/?q={{ object.latitude }},{{ object.longitude }}" target="_blank" class="btn btn-primary btn-xs">
                                <i class="mdi mdi-map-marker"></i> Map it
                            </a>
                        </div>
                        <span>{{ object.latitude }}, {{ object.longitude }}</span>
                    {% else %}
                        <span class="text-muted">&mdash;</span>
                    {% endif %}
                </td>
            </tr>
            <tr>
                <td>Contact Name</td>
                <td>{{ object.contact_name|placeholder }}</td>
            </tr>
            <tr>
                <td>Contact Phone</td>
                <td>
                    {% if object.contact_phone %}
                        <a href="tel:{{ object.contact_phone }}">{{ object.contact_phone }}</a>
                    {% else %}
                        <span class="text-muted">&mdash;</span>
                    {% endif %}
                </td>
            </tr>
            <tr>
                <td>Contact E-Mail</td>
                <td>
                    {% if object.contact_email %}
                        <a href="mailto:{{ object.contact_email }}">{{ object.contact_email }}</a>
                    {% else %}
                        <span class="text-muted">&mdash;</span>
                    {% endif %}
                </td>
            </tr>
        </table>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading">
            <strong>Comments</strong>
        </div>
        <div class="panel-body rendered-markdown">
            {% if object.comments %}
                {{ object.comments|render_markdown }}
            {% else %}
                <span class="text-muted">None</span>
            {% endif %}
        </div>
    </div>
{% endblock content_left_page %}

{% block content_right_page %}
    <div class="panel panel-default">
        <div class="panel-heading">
            <strong>Stats</strong>
        </div>
        <div class="panel-body">
            <div class="col-md-4 text-center">
                <h2><a href="{% url 'dcim:rack_list' %}?location={{ object.pk }}" class="btn {% if stats.rack_count %}btn-primary{% else %}btn-default{% endif %} btn-lg">{{ stats.rack_count }}</a></h2>
                <p>Racks</p>
            </div>
            <div class="col-md-4 text-center">
                <h2><a href="{% url 'dcim:device_list' %}?location={{ object.pk }}" class="btn {% if stats.device_count %}btn-primary{% else %}btn-default{% endif %} btn-lg">{{ stats.device_count }}</a></h2>
                <p>Devices</p>
            </div>
            <div class="col-md-4 text-center">
                <h2><a href="{% url 'ipam:prefix_list' %}?location={{ object.pk }}" class="btn {% if stats.prefix_count %}btn-primary{% else %}btn-default{% endif %} btn-lg">{{ stats.prefix_count }}</a></h2>
                <p>Prefixes</p>
            </div>
            <div class="col-md-4 text-center">
                <h2><a href="{% url 'ipam:vlan_list' %}?location={{ object.pk }}" class="btn {% if stats.vlan_count %}btn-primary{% else %}btn-default{% endif %} btn-lg">{{ stats.vlan_count }}</a></h2>
                <p>VLANs</p>
            </div>
            <div class="col-md-4 text-center">
                <h2><a href="{% url 'circuits:circuit_list' %}?location={{ object.pk }}" class="btn {% if stats.circuit_count %}btn-primary{% else %}btn-default{% endif %} btn-lg">{{ stats.circuit_count }}</a></h2>
                <p>Circuits</p>
            </div>
            <div class="col-md-4 text-center">
                <h2><a href="{% url 'virtualization:virtualmachine_list' %}?location={{ object.pk }}" class="btn {% if stats.vm_count %}btn-primary{% else %}btn-default{% endif %} btn-lg">{{ stats.vm_count }}</a></h2>
                <p>Virtual Machines</p>
            </div>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading">
            <strong>Rack Groups</strong>
        </div>
        <table class="table table-hover panel-body">
            {% for rg in rack_groups %}
                <tr>
                    <td style="padding-left: {{ rg.tree_depth }}8px"><i class="mdi mdi-folder-open"></i> <a href="{{ rg.get_absolute_url }}">{{ rg }}</a></td>
                    <td>{{ rg.rack_count }}</td>
                    <td class="text-right noprint">
                        <a href="{% url 'dcim:rack_elevation_list' %}?rack_group={{ rg.pk }}" class="btn btn-xs btn-primary" title="View elevations">
                            <i class="mdi mdi-server"></i>
                        </a>
                    </td>
                </tr>
            {% endfor %}
            <tr>
                <td><i class="mdi mdi-folder-open"></i> All racks</td>
                <td>{{ stats.rack_count }}</td>
                <td class="text-right noprint">
                    <a href="{% url 'dcim:rack_elevation_list' %}?location={{ object.pk }}" class="btn btn-xs btn-primary" title="View elevations">
                        <i class="mdi mdi-server"></i>
                    </a>
                </td>
            </tr>
        </table>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading">
            <strong>Images</strong>
        </div>
        {% include 'inc/image_attachments.html' with images=object.images.all %}
        {% if perms.extras.add_imageattachment %}
            <div class="panel-footer text-right noprint">
                <a href="{% url 'dcim:location_add_image' object_id=object.pk %}" class="btn btn-primary btn-xs">
                    <span class="mdi mdi-plus-thick" aria-hidden="true"></span>
                    Attach an image
                </a>
            </div>
        {% endif %}
    </div>
{% endblock content_right_page %}

{% block content_full_width_page %}
    {% if object.location_type.children.all %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Children</strong>
            </div>
            {% include 'inc/table.html' with table=children_table %}
            {% if perms.dcim.add_location %}
                <div class="panel-footer text-right noprint">
                    <a href="{% url 'dcim:location_add' %}?parent={{ object.pk }}" class="btn btn-xs btn-primary">
                        <span class="mdi mdi-plus-thick" aria-hidden="true"></span> Add child
                    </a>
                </div>
            {% endif %}
        </div>
        {% include 'inc/paginator.html' with paginator=children_table.paginator page=children_table.page %}
    {% endif %}
{% endblock content_full_width_page %}
