{% extends "base.html" %}
{% load kegweblib %}

{% block title %}Drinker Details: {{ drinker.username }} | {{ block.super }}{% endblock %}
{% block pagetitle %}Drinker Details: {{ drinker.username }}{% endblock %}

{% block content %}
<div class="row">
  <div class="span4">
    {% mugshot_box drinker %}
    <BR>
    <a href="{% url 'kb-drinker-sessions' drinker.username %}"
      class="btn btn-info" style="width:90%">See All Drinker Sessions</a>
    <BR><BR><BR>
  </div>

  <div class="span8">
    <ul class="nav nav-tabs" id="drinkerDetails">
      <li><a href="#1" data-toggle="tab">Summary</a></li>
      <li><a href="#2" data-toggle="tab">Charts</a></li>
      {% if chunk %}
      <li><a href="#3" data-toggle="tab">Last Session</a></li>
      {% endif %}
      {% if largest_session %}
      <li><a href="#4" data-toggle="tab">Largest Session</a></li>
      {% endif %}
    </ul>

    <div class="tab-content">
      <div class="tab-pane" id="1">
        <table class="table table-condensed table-striped">
          {% if stats %}
           <tr>
              <th>Total Volume</th>
              <td> {% volume stats.total_volume_ml %}</td>
           </tr>

           <tr>
              <th>Total Pours</th>
              <td>{{ stats.total_pours }}</td>
           </tr>

           <tr>
             <th>Total Sessions</td>
             <td>{{ stats.sessions_count }}</td>
           </tr>

           {% if stats.total_pours %}
           <tr>
              <th>Average Pour</th>
              <td>{% volume stats.average_volume_ml %}</td>
           </tr>

           <tr>
              <th>Largest Pour</th>
              <td>{% volume stats.greatest_volume_ml %}</td>
           </tr>
           {% endif %}
           {% endif %}

           <tr>
              <th>Member Since</th>
              <td>
                {{ drinker.date_joined|date:"l, F j Y" }}<br>
                <i>({% timeago drinker.date_joined %})</i>
              </td>
           </tr>

           {% with drinker.drinks.latest as last_drink %}
           {% if last_drink %}
           <tr>
              <th>Last Drink</th>
              <td>
                {{ last_drink.time|date:"l, F j Y" }}<br>
                <i>({% timeago last_drink.time%})</i>
              </td>
           </tr>
           {% endif %}
           {% endwith %}

        </table>
      </div> <!-- tab-pane -->

      <div class="tab-pane" id="2">
        {% if not stats.total_pours %}
        Looks like {{ drinker }} has never poured a drink. Boo!
        {% else %}
        <table class="table table-condensed">
          <tr>
            {% if kbsite.volume_display_units == 'metric' %}
              <th>total liters, by day of week</th>
            {% else %}
              <th>total pints, by day of week</th>
            {% endif %}
            <td>{% chart sessions_by_weekday stats 350 100 %}</td>
          </tr>

          <tr>
            {% if kbsite.volume_display_units == 'metric' %}
              <th>all sessions, by liter per session</th>
            {% else %}
              <th>all sessions, by pints per session</th>
            {% endif %}
            <td>{% chart sessions_by_volume stats 350 100 %}</td>
          </tr>
        </table>
        {% endif %}
      </div>

      {% if chunk %}
      <div class="tab-pane" id="3">

        {% with chunk.session as session %}
          {% include "kegweb/keg-session.html" %}
        {% endwith %}

      </div>
      {% endif %}

      {% if largest_session %}
      <div class="tab-pane" id="4">

          {% with largest_session as session %}
            {% include "kegweb/keg-session.html" %}
          {% endwith %}

      </div>
      {% endif %}

    </div> <!-- tab-content -->
  </div>
</div> <!-- row -->

{% endblock %}


{% block kb-extrajs %}
<script type="text/javascript">
$(document).ready(function () {
  $('#drinkerDetails a:first').tab('show');
});
</script>
{% endblock %}
