{% extends 'generic/object.html' %}
{% load buttons %}
{% load static %}
{% load helpers %}
{% load plugins %}
{% load i18n %}

{% block breadcrumbs %}
  {{ block.super }}
  <li class="breadcrumb-item"><a href="{% url 'dcim:powerfeed_list' %}?site_id={{ object.power_panel.site.pk }}">{{ object.power_panel.site }}</a></li>
  <li class="breadcrumb-item"><a href="{% url 'dcim:powerfeed_list' %}?power_panel_id={{ object.power_panel.pk }}">{{ object.power_panel }}</a></li>
  {% if object.rack %}
    <li class="breadcrumb-item"><a href="{% url 'dcim:powerfeed_list' %}?rack_id={{ object.rack.pk }}">{{ object.rack }}</a></li>
  {% endif %}
{% endblock %}

{% block content %}
<div class="row">
	<div class="col col-12 col-md-6">
        <div class="card">
            <h2 class="card-header">{% trans "Power Feed" %}</h2>
            <table class="table table-hover attr-table">
                <tr>
                    <th scope="row">{% trans "Power Panel" %}</th>
                    <td>{{ object.power_panel|linkify }}</td>
                </tr>
                <tr>
                    <th scope="row">{% trans "Rack" %}</th>
                    <td>{{ object.rack|linkify|placeholder }}</td>
                </tr>
                <tr>
                    <th scope="row">{% trans "Type" %}</th>
                    <td>{% badge object.get_type_display bg_color=object.get_type_color %}</td>
                </tr>
                <tr>
                    <th scope="row">{% trans "Status" %}</th>
                    <td>{% badge object.get_status_display bg_color=object.get_status_color %}</td>
                </tr>
                <tr>
                    <th scope="row">{% trans "Description" %}</th>
                    <td>{{ object.description|placeholder }}</td>
                </tr>
                <tr>
                    <th scope="row">{% trans "Tenant" %}</th>
                    <td>
                        {% if object.tenant.group %}
                          {{ object.tenant.group|linkify }} /
                        {% endif %}
                        {{ object.tenant|linkify|placeholder }}
                    </td>
                </tr>
                <tr>
                    <th scope="row">{% trans "Connected Device" %}</th>
                    <td>
                        {% if object.connected_endpoints %}
                            {{ object.connected_endpoints.0.device|linkify }} ({{ object.connected_endpoints.0|linkify:"name" }})
                        {% else %}
                            {{ ''|placeholder }}
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <th scope="row">{% trans "Utilization (Allocated" %})</th>
                    {% with utilization=object.connected_endpoints.0.get_power_draw %}
                        {% if utilization %}
                            <td>
                                {{ utilization.allocated }}{% trans "VA" %} / {{ object.available_power }}{% trans "VA" %}
                                {% if object.available_power > 0 %}
                                    {% utilization_graph utilization.allocated|percentage:object.available_power %}
                                {% endif %}
                            </td>
                        {% else %}
                            <td>{{ ''|placeholder }}</td>
                        {% endif %}
                    {% endwith %}
                </tr>
            </table>
        </div>
        <div class="card">
            <h2 class="card-header">{% trans "Electrical Characteristics" %}</h2>
            <table class="table table-hover attr-table">
                <tr>
                    <th scope="row">{% trans "Supply" %}</th>
                    <td>{{ object.get_supply_display }}</td>
                </tr>
                <tr>
                    <th scope="row">{% trans "Voltage" %}</th>
                    <td>{{ object.voltage }}{% trans "V" context "Abbreviation for volts" %}</td>
                </tr>
                <tr>
                    <th scope="row">{% trans "Amperage" %}</th>
                    <td>{{ object.amperage }}{% trans "A" context "Abbreviation for amperes" %}</td>
                </tr>
                <tr>
                    <th scope="row">{% trans "Phase" %}</th>
                    <td>{{ object.get_phase_display }}</td>
                </tr>
                <tr>
                    <th scope="row">{% trans "Max Utilization" %}</th>
                    <td>{{ object.max_utilization }}%</td>
                </tr>
            </table>
        </div>
        {% include 'inc/panels/custom_fields.html' %}
        {% include 'inc/panels/tags.html' %}
        {% plugin_left_page object %}
    </div>
    <div class="col col-12 col-md-6">
      <div class="card">
        <h2 class="card-header">{% trans "Connection" %}</h2>
        {% if object.mark_connected %}
          <div class="card-body">
            <span class="text-success"><i class="mdi mdi-check-bold"></i></span>
            {% trans "Marked as connected" %}
          </div>
        {% elif object.cable %}
          {% include 'dcim/inc/connection_endpoints.html' with trace_url='dcim:powerfeed_trace' %}
        {% else %}
          <div class="card-body text-muted">
            {% trans "Not connected" %}
            {% if perms.dcim.add_cable %}
              <a href="{% url 'dcim:cable_add' %}?a_terminations_type=dcim.powerfeed&a_terminations={{ object.pk }}&b_terminations_type=dcim.powerport&return_url={{ object.get_absolute_url }}" class="btn btn-primary float-end">
                <i class="mdi mdi-ethernet-cable" aria-hidden="true"></i> {% trans "Connect" %}
              </a>
            {% endif %}
          </div>
        {% endif %}
      </div>
      {% include 'inc/panels/comments.html' %}
      {% plugin_right_page object %}
    </div>
</div>
<div class="row">
    <div class="col col-md-12">
        {% plugin_full_width_page object %}
    </div>
</div>
{% endblock %}
