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

{% block extra_breadcrumbs %}
                <li>{{ object.power_panel.location|hyperlinked_object }}</li>
                <li>{{ object.power_panel|hyperlinked_object }}</li>
                {% if object.rack %}
                    <li>{{ object.rack|hyperlinked_object }}</li>
                {% endif %}
{% endblock extra_breadcrumbs %}

{% block content_left_page %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Power Feed</strong>
            </div>
            <table class="table table-hover panel-body attr-table">
                <tr>
                    <td>Power Panel</td>
                    <td>{{ object.power_panel|hyperlinked_object }}</td>
                </tr>
                <tr>
                    <td>Rack</td>
                    <td>{{ object.rack|hyperlinked_object }}</td>
                </tr>
                <tr>
                    <td>Type</td>
                    <td>
                        <span class="label label-{{ object.get_type_class }}">{{ object.get_type_display }}</span>
                    </td>
                </tr>
                <tr>
                    <td>Status</td>
                    <td>
                        {{ object.status| hyperlinked_object_with_color }}
                    </td>
                </tr>
                <tr>
                    <td>Connected Device</td>
                    <td>
                        {% if object.connected_endpoint %}
                            {{ object.connected_endpoint.device|hyperlinked_object }}
                            ({{ object.connected_endpoint }})
                        {% else %}
                            <span class="text-muted">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Utilization (Allocated)</td>
                    {% with utilization=object.connected_endpoint.get_power_draw %}
                        {% if utilization %}
                            <td>
                                {{ utilization.allocated }}VA / {{ object.available_power }}VA
                                {% if object.available_power > 0 %}
                                    {% utilization_graph_raw_data utilization.allocated object.available_power %}
                                {% endif %}
                            </td>
                        {% else %}
                            <td class="text-muted">N/A</td>
                        {% endif %}
                    {% endwith %}
                </tr>
            </table>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Electrical Characteristics</strong>
            </div>
            <table class="table table-hover panel-body attr-table">
                <tr>
                    <td>Supply</td>
                    <td>{{ object.get_supply_display }}</td>
                </tr>
                <tr>
                    <td>Voltage</td>
                    <td>{{ object.voltage }}V</td>
                </tr>
                <tr>
                    <td>Amperage</td>
                    <td>{{ object.amperage }}A</td>
                </tr>
                <tr>
                    <td>Phase</td>
                    <td>{{ object.get_phase_display }}</td>
                </tr>
                <tr>
                    <td>Max Utilization</td>
                    <td>{{ object.max_utilization }}%</td>
                </tr>
            </table>
        </div>
{% endblock content_left_page %}

{% block content_right_page %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Connection</strong>
            </div>
            {% if object.cable %}
                <table class="table table-hover panel-body attr-table">
                    <tr>
                        <td>Cable</td>
                        <td>
                            {{ object.cable|hyperlinked_object }}
                            <a href="{% url 'dcim:powerfeed_trace' pk=object.pk %}" class="btn btn-primary btn-xs" title="Trace">
                                <i class="mdi mdi-transit-connection-variant" aria-hidden="true"></i>
                            </a>
                        </td>
                    </tr>
                    {% if object.connected_endpoint %}
                        <tr>
                            <td>Device</td>
                            <td>{{ object.connected_endpoint.device|hyperlinked_object }}</td>
                        </tr>
                        <tr>
                            <td>Power Port</td>
                            <td>{{ object.connected_endpoint|hyperlinked_object }}</td>
                        </tr>
                        <tr>
                            <td>Type</td>
                            <td>{{ object.connected_endpoint.get_type_display|placeholder }}</td>
                        </tr>
                        <tr>
                            <td>Description</td>
                            <td>{{ object.connected_endpoint.description|placeholder }}</td>
                        </tr>
                        <tr>
                            <td>Path Status</td>
                            <td>
                                {% if object.path.is_active %}
                                    <span class="label label-success">Reachable</span>
                                {% else %}
                                    <span class="label label-danger">Not Reachable</span>
                                {% endif %}
                            </td>
                        </tr>
                    {% endif %}
                </table>
            {% else %}
                <div class="panel-body text-muted">
                    {% if perms.dcim.add_cable %}
                        <a href="{% url 'dcim:powerfeed_connect' termination_a_id=object.pk termination_b_type='power-port' %}?return_url={{ object.get_absolute_url }}" class="btn btn-primary btn-sm pull-right">
                            <span class="mdi mdi-ethernet-cable" aria-hidden="true"></span> Connect
                        </a>
                    {% endif %}
                    Not connected
                </div>
            {% endif %}
        </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_right_page %}
