{% extends "page-twocol.html" %}
{% load kegweblib %}

{% block title %}Keg {{ keg.id }} | {{ block.super }}{% endblock %}
{% block pagetitle %}Keg {{ keg.id }}{% endblock %}

{% block sidebar %}
  <div class="well">
  {% include "kegweb/keg-image.html" %}

  {% with keg.next as next %} {% with keg.previous as previous %}
  {% if next or previous %}
  <div style="font-size: 0.8em; text-align:center; margin-bottom:16px;">
    {% if previous %}
      <a href="{% url "kb-keg" previous.id %}">&laquo; previous keg</a>
    {% endif %}
    {% if next and previous %}
    &mdash;
    {% endif %}
    {% if next %}
      <a href="{% url "kb-keg" next.id %}">next keg &raquo;</a>
    {% endif %}
  </div>
  {% endif %}
  {% endwith %} {% endwith %}
  </div>
{% endblock sidebar %}


{% block col-1 %}
<h2>
  {{keg.type.name}}
  {% if keg.type.brewer %}
  <small>{{keg.type.brewer}}</small>
  {% endif %}
</h2>

{% include "kegweb/basic-badges.html" %}

<table class="table table-hover">
  <tbody>
    <tr>
      <th>Status</th>
      <td>
        {% ifequal keg.status "online" %}
        Keg is <b>online</b>, and is {{ keg.keg_age.days }}
        day{{keg.keg_age.days|pluralize}} old.
        <span class="muted">
        {% if keg.is_empty %}
          (<i>empty</i>)
        {% else %}
          ({{ keg.percent_full|floatformat:2 }}% full</i>)
        {% endif %}
        </span>
        {% else %}
        Keg is <b>offline</b>; it lasted {{ keg.keg_age.days }}
        day{{keg.keg_age.days|pluralize}}.
        {% endifequal %}
      </td>
    </tr>

    {% include "kegweb/basic-stats.html" %}

    {% with keg.current_tap as tap %}
    {% if tap and tap.temperature_sensor %}
    <tr>
      <th>Temperature</th>
      <td>
        {{ tap.Temperature.TempC|floatformat:1}}&deg;C / 
        {{ tap.Temperature.TempF|floatformat:1}}&deg;F<br/>
        {% chart sensor tap.temperature_sensor 340 60 %}
      </td>
    </tr>
    {% endif %}
    {% endwith %}

    {% if keg.spilled_volume > 0 %}
    <tr>
      <th>Total Spilled/Lost</th>
      <td>{% volume keg.spilled_volume %}</td>
    </tr>
    {% endif %}

  </tbody>
</table>

{% if keg.description %}
<blockquote>
  <p>{{ keg.description}}</p>
</blockquote>
{% endif %}
<hr/>

{% if sessions %}
{% for session in sessions %}
  {% include "kegweb/keg-session.html" %}
{% endfor %}
{% endif %}

{% endblock col-1 %}

{% block col-2 %}
<div class="row">
    <h2>Top Drinkers</h2>
    {% chart users_by_volume stats 280 220 %}<br/>
    {% with keg.TopDrinkers as ranked_drinkers %}
      {% include "kegweb/drinker-rank.html" %}
    {% endwith %}
</div>

{% endblock col-2 %}

