{% extends '_base.html' %}
{% load static from staticfiles %}
{% load helpers %}

{% block content %}
<div class="row">
    <div class="col-sm-8 col-md-9">
        <ol class="breadcrumb">
            <li><a href="{% url 'circuits:provider_list' %}">Providers</a></li>
            <li>{{ provider }}</li>
        </ol>
    </div>
    <div class="col-sm-4 col-md-3">
        <form action="{% url 'circuits:provider_list' %}" method="get">
            <div class="input-group">
                <input type="text" name="q" class="form-control" />
                <span class="input-group-btn">
                    <button type="submit" class="btn btn-primary">
                        <span class="fa fa-search" aria-hidden="true"></span>
                    </button>
                </span>
            </div>
        </form>
    </div>
</div>
<div class="pull-right">
    {% if show_graphs %}
        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#graphs_modal" data-obj="{{ provider.name }}" data-url="{% url 'circuits-api:provider-graphs' pk=provider.pk %}" title="Show graphs">
            <i class="fa fa-signal" aria-hidden="true"></i>
            Graphs
        </button>
    {% endif %}
    {% if perms.circuits.change_provider %}
		<a href="{% url 'circuits:provider_edit' slug=provider.slug %}" class="btn btn-warning">
			<span class="fa fa-pencil" aria-hidden="true"></span>
			Edit this provider
		</a>
    {% endif %}
    {% if perms.circuits.delete_provider %}
		<a href="{% url 'circuits:provider_delete' slug=provider.slug %}" class="btn btn-danger">
			<span class="fa fa-trash" aria-hidden="true"></span>
			Delete this provider
		</a>
    {% endif %}
</div>
<h1>{% block title %}{{ provider }}{% endblock %}</h1>
{% include 'inc/created_updated.html' with obj=provider %}
<div class="row">
	<div class="col-md-4">
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Provider</strong>
            </div>
            <table class="table table-hover panel-body attr-table">
                <tr>
                    <td>ASN</td>
                    <td>
                        {% if provider.asn %}
                            {{ provider.asn }}
                        {% else %}
                            <span class="text-muted">N/A</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Account</td>
                    <td>
                        {% if provider.account %}
                            {{ provider.account }}
                        {% else %}
                            <span class="text-muted">N/A</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Customer Portal</td>
                    <td>
                        {% if provider.portal_url %}
                            <a href="{{ provider.portal_url }}">{{ provider.portal_url }}</a>
                        {% else %}
                            <span class="text-muted">N/A</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>NOC Contact</td>
                    <td>
                        {% if provider.noc_contact %}
                            {{ provider.noc_contact|linebreaksbr }}
                        {% else %}
                            <span class="text-muted">N/A</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Admin Contact</td>
                    <td>
                        {% if provider.admin_contact %}
                            {{ provider.admin_contact|linebreaksbr }}
                        {% else %}
                            <span class="text-muted">N/A</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Circuits</td>
                    <td>
                        <a href="{% url 'circuits:circuit_list' %}?provider={{ provider.slug }}">{{ provider.circuits.count }}</a>
                    </td>
                </tr>
            </table>
        </div>
        {% with provider.get_custom_fields as custom_fields %}
            {% include 'inc/custom_fields_panel.html' %}
        {% endwith %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Comments</strong>
            </div>
            <div class="panel-body">
                {% if provider.comments %}
                    {{ provider.comments|gfm }}
                {% else %}
                    <span class="text-muted">None</span>
                {% endif %}
            </div>
        </div>
	</div>
	<div class="col-md-8">
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Circuits</strong>
            </div>
            <table class="table table-hover panel-body">
                <tr>
                    <th>Circuit ID</th>
                    <th>Type</th>
                    <th>Tenant</th>
                    <th>A Side</th>
                    <th>Z Side</th>
                    <th>Description</th>
                </tr>
                {% for c in circuits %}
                    <tr>
                        <td>
                            <a href="{% url 'circuits:circuit' pk=c.pk %}">{{ c.cid }}</a>
                        </td>
                        <td>
                            <a href="{% url 'circuits:circuit_list' %}?type={{ c.type.slug }}">{{ c.type }}</a>
                        </td>
                        <td>
                            {% if c.tenant %}
                                <a href="{% url 'tenancy:tenant' slug=c.tenant.slug %}">{{ c.tenant }}</a>
                            {% else %}
                                <span class="text-muted">&mdash;</span>
                            {% endif %}
                        </td>
                        <td>
                            {% if c.termination_a %}
                                <a href="{% url 'dcim:site' slug=c.termination_a.site.slug %}">{{ c.termination_a.site }}</a>
                            {% else %}
                                <span class="text-muted">&mdash;</span>
                            {% endif %}
                        </td>
                        <td>
                            {% if c.termination_z %}
                                <a href="{% url 'dcim:site' slug=c.termination_z.site.slug %}">{{ c.termination_z.site }}</a>
                            {% else %}
                                <span class="text-muted">&mdash;</span>
                            {% endif %}
                        </td>
                        <td>
                            {% if c.description %}
                                {{ c.description }}
                            {% else %}
                                <span class="text-muted">&mdash;</span>
                            {% endif %}
                        </td>
                    </tr>
                {% empty %}
                    <tr>
                        <td colspan="6" class="text-muted">None</td>
                    </tr>
                {% endfor %}
            </table>
            {% if perms.circuits.add_circuit %}
                <div class="panel-footer text-right">
                    <a href="{% url 'circuits:circuit_add' %}?provider={{ provider.pk }}" class="btn btn-xs btn-primary">
                        <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add circuit
                    </a>
                </div>
            {% endif %}
        </div>
    </div>
</div>
{% include 'inc/graphs_modal.html' %}
{% endblock %}

{% block javascript %}
<script src="{% static 'js/graphs.js' %}?v{{ settings.VERSION }}"></script>
{% endblock %}
