{% extends "ui/panels/_base.html" %}
{% load helpers i18n %}

{% block panel_content %}
  <table class="table table-hover">
    <thead>
      <tr>
        <th>{% trans "Input" %}</th>
        <th>{% trans "Outlets" %}</th>
        <th>{% trans "Allocated" %}</th>
        <th>{% trans "Available" %}</th>
        <th>{% trans "Utilization" %}</th>
      </tr>
    </thead>
    {% for powerport in object.powerports.all %}
      {% with utilization=powerport.get_power_draw powerfeed=powerport.connected_endpoints.0 %}
        <tr>
          <td>{{ powerport }}</td>
          <td>{{ utilization.outlet_count }}</td>
          <td>{{ utilization.allocated }}{% trans "VA" %}</td>
          {% if powerfeed.available_power %}
            <td>{{ powerfeed.available_power }}{% trans "VA" %}</td>
            <td>{% utilization_graph utilization.allocated|percentage:powerfeed.available_power %}</td>
          {% else %}
            <td class="text-muted">&mdash;</td>
            <td class="text-muted">&mdash;</td>
          {% endif %}
        </tr>
        {% for leg in utilization.legs %}
          <tr>
            <td style="padding-left: 20px">
              {% trans "Leg" context "Leg of a power feed" %} {{ leg.name }}
            </td>
            <td>{{ leg.outlet_count }}</td>
            <td>{{ leg.allocated }}</td>
            {% if powerfeed.available_power %}
              {% with phase_available=powerfeed.available_power|divide:3 %}
                <td>{{ phase_available }}{% trans "VA" %}</td>
                <td>{% utilization_graph leg.allocated|percentage:phase_available %}</td>
              {% endwith %}
            {% else %}
              <td class="text-muted">&mdash;</td>
              <td class="text-muted">&mdash;</td>
            {% endif %}
          </tr>
        {% endfor %}
      {% endwith %}
    {% endfor %}
  </table>
{% endblock panel_content %}
