{% 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="ym-form"
      style="overflow-x: auto;"
      data-ajax="false">
{% csrf_token %}
{{formset.management_form}}

{% if session_form.non_field_errors %}
<div class="form-error">
    {% for error in session_form.non_field_errors %}
        <p class="form-error-message">{% trans error %}</p>
    {% endfor %}
</div>
{% endif %}

<table class="workout-log-table">
{% yaml_form_field dateform.date %}

{% for field in session_form %}
    {% if field.name == 'impression' %}
        {% yaml_form_field field "ym-fbox-select" %}
    {% else %}
        {% yaml_form_field field %}
    {% endif %}
{% endfor %}
</table>

<h3>{% trans "Exercises" %}</h3>
{% for key, value in exercises.items %}
    <p>{{value.obj.name}}</p>

    <table class="workout-log-table">
    <tr>
        {% for form in value.forms %}
        <td class="narrow-input">
            <div {% if form.weight.errors %}class="form-error"{% endif %}>
            {{form.reps}}
            </div>
            <div {% if form.weight.errors %}class="form-error"{% endif %}>
                 <span class="ym-message">{% trans "Reps" %}</span>
             </div>
        </td>
        <td>
            <div {% if form.weight.errors %}class="form-error"{% endif %}>
            {{form.weight}}
            </div>

            <div {% if form.weight.errors %}class="form-error"{% endif %}>
                 <span class="ym-message">kg.</span>
             </div>
        </td>
        {% endfor %}
    </tr>
    </table>
{% empty %}
    <p>
        {% trans "Add exercises to this training day before adding a log." %}
        <a href="{% url 'workout-view' day.training.id %}">{% trans "Back to workout" %}</a>
    </p>
{% endfor %}
</table>


<p>
        <a href="{% url 'core:index' %}"
               data-role="button"
               data-rel="back"
               data-mini="true">{% trans "Cancel" %}</a>
        <input type="submit" value="{% trans 'Save' %}" id="form-save">
    </td>
</p>
</form>

{% endblock %}


{% block sidebar %}
<h3>{% trans "Info" %}</h3>
<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>

<h3>{% trans "Options" %}</h3>
<p>
<a href="{% url 'workout-view' day.training.id %}"
   data-role="button">
    <img src="{% static 'images/icons/list.svg' %}"
         width="32"
         height="32"
         alt="{% trans 'Back to workout' %}">
    {% trans "Back to workout" %}
</a>
</p>
{% endblock %}
