{% extends "base.html" %}
{% load i18n %}
{% load staticfiles %}
{% load wger_extras %}

{% block title %}{% trans "New weight log" %} – {{day.description}}{% endblock %}

{% block header %}
<script type="text/javascript">
$(document).ready(function () {
    get_workout_session();
});
</script>
{% endblock %}

{% block content %}
<form action="{{form_action}}" method="POST" class="form-horizontal">
    {% csrf_token %}
    {{formset.management_form}}

    {% render_form_errors session_form %}
    {% render_form_field dateform.date %}

    {% for field in session_form %}
        {% render_form_field field %}
    {% endfor %}


    <div style="overflow-x: auto;margin-bottom: 1em;">
    {% for set in day.set_set.select_related %}
    {% for exercise in set.exercises.select_related %}
        {% with value=exercises|get_item:exercise.id %}
        <div class="form-group workout-log-table {% if field.errors %}has-error{% endif %}">
            <div {% if field.errors %}class="has-error has-feedback"{% endif %}>
                <label class="col-md-3 control-label">
                    {{value.obj.name}}
                </label>

                <div class="col-md-9">
                    <table class="table">
                    <tr>
                    {% for form in value.forms %}
                        <td>
                            {{ form.reps|form_field_add_css:'form-control narrow-input' }}
                        </td>
                        <td>
                            {{ form.weight|form_field_add_css:'form-control narrow-input' }}
                        </td>
                    {% endfor %}
                    </tr>
                    <tr>
                    {% for form in value.forms %}
                        <td>{% trans "Reps" %}</td>
                        <td>
                            {% trans_weight_unit 'kg' user %}
                        </td>
                    {% endfor %}
                    </tr>
                    </table>
                </div>
            </div>
        </div>
        {% endwith %}
    {% endfor %}
    {% empty %}
        {% trans "Add exercises to this training day before adding a log." %}
        <br>
        <a href="{{ day.training.get_absolute_url }}">{% trans "Back to workout" %}</a>
    {% endfor %}
    </div>

    {% render_form_submit %}

</form>

{% endblock %}


{% block sidebar %}
<h4>{% trans "Info" %}</h4>
<p>{% blocktrans %}A new workout session (impression, notes, time) will
be created if there isn't already one for the selected date. If there is, it
will simply be edited. Weight entries are always added.{% endblocktrans %}</p>

<h4>{% trans "Options" %}</h4>
<p>
<a href="{{ day.training.get_absolute_url }}" {% auto_link_css flavour %}>
    <img src="{% static 'images/icons/list.svg' %}"
         width="32"
         height="32"
         alt="{% trans 'Back to workout' %}">
    {% trans "Back to workout" %}
</a>
</p>
{% endblock %}
