{% extends "kegadmin/base.html" %}
{% load kegweblib %}
{% load crispy_forms_tags %}

{% block title %}Kegbot Admin: Edit Tap: {{ tap.name }} | {{ block.super }}{% endblock %}
{% block pagetitle %}Kegbot Admin: Edit Tap: {{ tap.name }}{% endblock %}

{% block kegadmin-main %}
<ul class="nav nav-tabs" id="tapDetails">
    {% if not current_keg %}
    <li><a href="#1" data-toggle="tab">Create New Keg</a></li>
      {% if available_kegs %}
      <li><a href="#2" data-toggle="tab">Attach Untapped Keg</a></li>
      {% endif %}
    {% else %}
    <li><a href="#3" data-toggle="tab">Current Keg</a></li>
    <li><a href="#4" data-toggle="tab">Add Drink</a></li>
    <li><a href="#5" data-toggle="tab">Add Spill</a></li>
    {% endif %}
    <li><a href="#6" data-toggle="tab">Tap Settings</a></li>
    <li><a href="#7" data-toggle="tab">Delete Tap</a></li>
</ul>

<div class="tab-content">
  {% if not current_keg %}
  <div class="tab-pane" id="1">
    {% crispy activate_keg_form %}
  </div>

  {% if available_kegs %}
  <div class="tab-pane" id="2">
    <form action="" class="user-select" method="POST">{% csrf_token %}
      <input type="hidden" name="tap_id" value="{{tap.id}}">
      <select name="keg_id" class="span6">
        {% for keg in available_kegs %}
          <option value="{{keg.id}}">{{keg}}</option>
        {% endfor %}
      </select>
      <button class="btn btn-primary" style="margin-top:-10px;" name="submit_keg_choice" type="submit">
        Activate Keg
      </button>
    </form>
  </div>
  {% endif %}

  {% else %}
  <div class="tab-pane" id="3">
    <table class="table table-striped table-hover">
    <tr>
      <th>Keg</th>
      <td><a href="{% url 'kegadmin-edit-keg' current_keg.id %}">{{ current_keg }}</a></td>
    </tr>
    <tr>
      <th>Tapped</th>
      <td>{{ current_keg.start_time }}</td>
    </tr>
    <tr>
      <th>Volume</th>
      <td>{% volume current_keg.remaining_volume_ml %} remaining ({{ current_keg.percent_full|floatformat:2 }}% full)</td>
    </tr>
    </table>
    {% crispy end_keg_form %}
  </div>

  <div class="tab-pane" id="4">
    <div class="alert alert-info">
      Manually record a drink using the form below.
      You may leave the <em>username</em> field blank to
      add an anonymous pour.
    </div>

    <form action="" class="user-select" method="POST">{% csrf_token %}
    <div class="input-prepend input-append">
    {% if metric_volumes %}
      <input type="hidden" name="units" value="mL">
      <input class="span4" type="text" name="volume" placeholder="123">
      <span class="add-on">mL</span>
    {% else %}
      <input type="hidden" name="units" value="oz">
      <input class="span4" type="text" name="volume" placeholder="1.23">
      <span class="add-on">oz</span>
    {% endif %}
      <input class="span4" type="text" name="username" placeholder="username">
    <button class="btn btn-info" name="submit_record_drink" type="submit">
      <i class="icon-plus-sign icon-white"></i> Record
    </button>
    </div>
    </form>
  </div>

  <div class="tab-pane" id="5">
    <div class="alert alert-info">
      Manually record a spill using the form below. Spills are
      <em>not</em> attributed to any user and are <em>not</em> saved as an event.
      You may also update the keg's total spilled volume on the
      <a href="{% url 'kegadmin-edit-keg' current_keg.id %}">keg admin page</a>.
    </div>

    <form action="" class="user-select" method="POST">{% csrf_token %}
    <div class="input-prepend input-append">
    {% if metric_volumes %}
      <input type="hidden" name="units" value="mL">
      <input class="span4" type="text" name="volume" placeholder="123">
      <span class="add-on">mL</span>
    {% else %}
      <input type="hidden" name="units" value="oz">
      <input class="span4" type="text" name="volume" placeholder="1.23">
      <span class="add-on">oz</span>
    {% endif %}
    <button class="btn btn-info" name="submit_record_spill" type="submit">
      <i class="icon-plus-sign icon-white"></i> Record
    </button>
    </div>
    </form>
  </div>
  {% endif %}

  <div class="tab-pane" id="6">
  {% crispy tap_settings_form %}
  </div>

  <div class="tab-pane" id="7">
    <div class="alert alert-danger">
      If you delete a tap with a keg currently attached, the keg
      will be taken offline and marked as finished.
    </div>
    {% crispy delete_tap_form %}
  </div>
</div>

{% endblock %}

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