{% extends "base.html" %}
{% load i18n static wger_extras django_bootstrap_breadcrumbs %}


{#             #}
{# Breadcrumbs #}
{#             #}
{% block breadcrumbs %}
    {{ block.super }}

    {% breadcrumb day.training day.training %}
    {% breadcrumb "Weight log" "manager:log:log" day.training_id %}
    {% breadcrumb "New weight log" "manager:log:log" day.training_id %}
{% endblock %}


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


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


{#         #}
{# Content #}
{#         #}
{% 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="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>
                        <td>{% trans "Amount" %}</td>
                        <td>{% trans "Unit" %}</td>
                        <td>{% trans "Weight" %}</td>
                        <td>{% trans "Unit" %}</td>
                    </tr>
                    {% for form in value.forms %}
                    <tr>
                        <td>
                            <div {% if form.reps.errors %}class="has-error"{% endif %}>
                                {{ form.reps|form_field_add_css:'form-control narrow-input' }}
                                <span class="help-block">
                                    {% for error in form.reps.errors %}
                                        <p>{% trans error %}</p>
                                    {% endfor %}
                                </span>
                            </div>
                        </td>
                        <td>
                            <div {% if form.repetition_unit.errors %}class="has-error"{% endif %}>
                                {{ form.repetition_unit|form_field_add_css:'form-control narrow-input' }}
                                <span class="help-block">
                                    {% for error in form.repetition_unit.errors %}
                                        <p>{% trans error %}</p>
                                    {% endfor %}
                                </span>
                            </div>
                        </td>
                        <td>
                            <div {% if form.weight.errors %}class="has-error"{% endif %}>
                            {{ form.weight|form_field_add_css:'form-control narrow-input' }}
                            <span class="help-block">
                                {% for error in form.weight.errors %}
                                    <p>{% trans error %}</p>
                                {% endfor %}
                            </span>
                            </div>
                        </td>
                        <td>
                            <div {% if form.weight_unit.errors %}class="has-error"{% endif %}>
                                {{ form.weight_unit|form_field_add_css:'form-control narrow-input' }}
                                <span class="help-block">
                                    {% for error in form.weight_unit.errors %}
                                        <p>{% trans error %}</p>
                                    {% endfor %}
                                </span>
                            </div>
                        </td>
                    </tr>
                    {% endfor %}

                    </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 %}


{#          #}
{# Side bar #}
{#          #}
{% 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>
{% endblock %}
